
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
mongoose-to-joi-translator
Advanced tools
Extracts schema from mongoose and generates an equivilent JOI schema.
This project aims at reducing the amount of work needed when validation is required for the database and another location, e.g. API. It also aims at unifying the way validation errors are handled. This is a proof of concept that works only on mongoose's validation.
Deeply nested document validation is supported, i.e. Objects within Objects, Arrays within Objects etc.
npm test
const getJoiSchema = require('mongoose-to-joi-translator');
const joiSchema = getJoiSchema(new Schema({ word: { type: String } }));
const { error, value } = Joi.validate({ word: 'hello' }, joiSchema);
const { JoiValidator } = require('generic-joi-validator');
const joiValidator = new JoiValidator();
// Use a translator to extract Joi schema from your database
const mongoose = require('mongoose');
const { Schema } = mongoose;
const getJoiSchema = require('mongoose-to-joi-translator');
joiValidator.schemata.stores = getJoiSchema(new Schema({
name: {
type: String,
required: true
},
location: new Schema({
latitude: {
type: String,
required: true
},
longitude: {
type: String,
required: true
}
})
}));
// or add your schema manually
joiValidator.schemata.stores = {
name: Joi.string().required(),
location: {
latitude: Joi.string().required(),
longitude: Joi.string().required()
}
};
// With koa
const Koa = require('koa');
const bodyParser = require('koa-bodyparser');
const Router = require('koa-router');
const router = new Router();
const app = new Koa();
app.use(bodyParser());
const koaValidator = async (ctx, next) => {
const { error, value } = joiValidator.prepare(ctx.url.substr(ctx.url.lastIndexOf('/') + 1), ctx.request.body);
ctx.assert(!error, 400, value);
ctx.state.data = value;
return next();
};
router.post(
'/stores',
koaValidator,
async (ctx, next) => {
ctx.body = ctx.state.data;
return next();
}
);
app.use(router.allowedMethods({ throw: true }));
app.use(router.routes());
app.listen(3000);
FAQs
Converts mongoose schema to Joi.
The npm package mongoose-to-joi-translator receives a total of 4 weekly downloads. As such, mongoose-to-joi-translator popularity was classified as not popular.
We found that mongoose-to-joi-translator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.