2.1.0 • Published 6 years ago

mongoose-to-joi-translator v2.1.0

Weekly downloads
70
License
MIT
Repository
github
Last release
6 years ago

Mongoose-to-joi-translator Logo

mongoose-to-joi-translator

Build Status codecov dependencies Status devDependencies Status

Description

Translates Mongoose schema to Joi. You can use Joi schema to do the validation. The idea is to write database models once and validate everywhere.

Installation

npm install mongoose-to-joi-translator

Supported validations

  1. All types
    • required
    • valid (enum validation)
    • default
  2. Strings
    • min
  3. Arrays
    • items (element types)
  4. Numbers
    • min
    • max
  5. Objects
  6. Dates
  7. ObjectIDs
  8. Booleans
  9. Custom sync validators as documented here

Deeply nested document validation is supported, i.e. Objects within Objects, Arrays within Objects etc.

Testing

npm test

Usage

// Require the library
const getJoiSchema = require('mongoose-to-joi-translator');
const schema = new Schema({ word: { type: String } });
const ModelName = mongoose.model('ModelName', schema);
// Extract schema
const joiSchema = getJoiSchema(ModelName);
// Use Joi to validate
const { error, value } = Joi.validate({ word: 'hello' }, joiSchema);
2.1.0

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago