@lpgroup/yup
v1.8.3
Published
Collection of yup validation functions.
Downloads
991
Readme
@lpgroup/yup
Collection of yup validation and helper functions for projects based on feathersjs.
Install
Installation of the npm
npm install @lpgroup/yup
Example
const yup = require("@lpgroup/yup");
const schema = { key: yup.string().required() };
Hooks
/* xxx.yup.js */
const cy = require("@lpgroup/yup");
const requestSchema = {
_id: cy.uuid().required(),
alias: cy.string().required(),
name: cy.string().required(),
createdAt: cy.timestamp().defaultNull(),
changedAt: cy.timestamp().defaultNull(),
};
const dbSchema = {
added: cy.changed(),
changed: cy.changed(),
owner: cy.owner(),
};
module.exports = cy.buildValidationSchema(requestSchema, dbSchema);
module.exports.requestSchema = requestSchema;
/* xxx.service.js */
const { Xxx } = require("./xxx.class");
const hooks = require("./xxx.hooks");
const schema = require("./xxx.yup");
module.exports = (app) => {
const options = { id: "alias", schema };
app.use("/xxx", new Xxx(options, app));
const service = app.service("xxx");
service.hooks(hooks);
};
/* xxx.hooks.js */
const { validReq } = require("@lpgroup/yup");
const { validDB } = require("@lpgroup/yup");
module.exports = {
before: {
create: [validReq(), changeData(), validDB()],
update: [validReq(), changeData(), validDB()],
patch: [validReq(), changeData(), validDB()],
},
};
API
general
hooks
validReq(objSchema)
validReq(xxx);
validDB(objSchema)
validDB(xxx);
yup.array(objSchema)
const schema = { key: yup.array({ key: yup.string() }).required() };
Development
When developing this NPM your can patch yup to give better error message.
npm run patch-package
Contribute
See contribute
License
MIT - See licence