Skip to content

annotation-engine is a reusable JS library created for PrivateSky and useful to create annotations in DSL languages

Notifications You must be signed in to change notification settings

PrivateSky/annotation-engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fluent Validation

Let's start with an example:

const schema = new Schema('int unsigned default:3')
const value = schema.create()
assert.strictEqual(value, 3)

const received = -1
try {
  schema.setValue(received)
} catch (err) {
  assert.strictEqual(err.type, 'validation')
  assert.deepStrictEqual(err.details, 'unsigned')
}

or, maybe something more complicated:

const schema = new Schema({
  id: 'int unsigned default:3',
  name: 'string required min:2 max:255',
  email: 'string required email unique:checkByEmail',
})

schema.inject('checkByEmail', async => value => {
  const existent = await db.findByEmail({email:value})
  return !!existent
})

try {
  await schema.setValue({
    id: -1,
    name: 'M',
    email: '[email protected]'
  })
} catch (err) {
  assert.strictEqual(err.type, 'validation')
  assert.deepStrictEqual(err.details, { id: 'unsigned', name: 'min:2', email: 'unique' })
}

About

annotation-engine is a reusable JS library created for PrivateSky and useful to create annotations in DSL languages

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •