Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
get-it-ready
Advanced tools
Generate Joi Validation, Mongoose Model and basic API endpoint routes for hapijs
Generate Joi Validation, Mongoose Model and basic API endpoint routes for hapijs
While doing hapijs app with mongoose, there was a problem with Mongoose schemas and Joi validations; they were most of the times same. And the REST API was surely going to have few predefined routes; why not have a constructor to do all this at once.
Once constructor will bridge the problem of multiple configurations for Mongoose and Joi. And also quicky return the controller methods and Routes to easily plug into Hapijs app.
This lib can be used to generate the schema, model, necessary controllers and routes that can be directly plugged into Hapijs app.
Few restrictions:
For automatic/quick usage, the method will need all following four parameters.
joi
named key in the value objectIt returns a Collection object containing ingredients of REST which are ready to be plugged to hapijs
var Joi = require('joi');
var getItReady = require('get-it-ready');
var personDefinition = {
name: {
type: String,
required: true
},
firstName: {
type: String,
required: true,
joi: Joi.string()
},
lastName: {
type: String,
required: true,
joi: Joi.string()
},
createdOn: {
type: Date,
required: false,
default: Date.now,
joi: Joi.date()
}
};
var person = getItReady(personDefinition, 'persons', 'Person', 'person');
console.log(person.validations, person.schema, person.model, person.controller, person.routes);
See above code in action at https://runkit.com/pankaj/get-it-ready
For manual opration of this lib, the order of execution of methods is very important. The order of execution should be
separateJoiValidationObject
getSchema
getModel
Mongoose.createConnection
getControllers
getRoutes
var Joi = require('joi');
var getItReady = require('get-it-ready');
var personDefinition = {
firstName: {
type: String,
required: true,
joi: Joi.string()
},
lastName: {
type: String,
required: true,
joi: Joi.string()
},
createdOn: {
type: Date,
required: false,
default: Date.now,
joi: Joi.date()
}
};
var validations = getItReady.separateJoiValidationObject(personDefination);
var schema = getItReady.getSchema(validations.schema);
var model = getItReady.getModel(modelName, schema);
var controllers = getItReady.getControllers(model, validations);
var routes = getItReady.getRoutes(controllers, routeBaseName, singularRouteName);
console.log(validations, schema, model, controller, routes);
FAQs
Generate Joi Validation, Mongoose Model and basic API endpoint routes for hapijs
The npm package get-it-ready receives a total of 3 weekly downloads. As such, get-it-ready popularity was classified as not popular.
We found that get-it-ready demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.