Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
json-schema-to-mongoose
Advanced tools
A translation library between JSON Schema and Mongoose Schema. Written in TypeScript.
This project was created from the ashes of json-schema-converter
. I took away
some features and made it more single purpose and added features to the
conversion.
npm install json-schema-to-mongoose --save
/// <reference path="../node_modules/json-schema-to-mongoose/json-schema-to-mongoose.d.ts" />
import createMongooseSchema = require('./lib/json-schema')
import util = require('util')
// Or use plain javascript
// var createMongooseSchema = require('./lib/json-schema')
// var util = require('util')
// example json-schema references
var refs =
{
yep:
{
type: 'string',
pattern: '^\\d{3}$'
},
idSpec: {
type: 'object',
properties:
{
id:
{
$ref: 'yep'
}
}
}
}
// example schema to convert to mongoose schema
var schema =
{
type: 'object',
properties:
{
id:
{
$ref: 'yep'
},
address:
{
type: 'object',
properties:
{
street: {type: 'string', default: '44', pattern: '^\\d{2}$'},
houseColor: {type: 'string', default: '[Function=Date.now]', format: 'date-time'}
}
}
}
}
//Convert the schema
var mongooseSchema = createMongooseSchema(refs, schema)
//Alternative syntax, which makes it so you can convert many at one time.
// var jsonSchemas = {commonRef: ..., good: ..., schema: ..., naming: ...}
// var convert = createMongooseSchema(jsonSchemas)
// var schemaNames = ['good', 'schema', 'naming']
// var schemas = _.map(schemaNames, (name) => { return jsonSchemas[name] })
// var mongooseSchemas = _.zipObject(schemaNames, schemas.reduce((mongooseSchemas, schema) => {
// return mongooseSchemas.concat(convert(schema))
// }, []))
console.log(util.inspect(mongooseSchema, false, null))
var Schema = new mongoose.Schema(mongooseSchema)
FAQs
A library for converting json-schema to mongoose schema
The npm package json-schema-to-mongoose receives a total of 41 weekly downloads. As such, json-schema-to-mongoose popularity was classified as not popular.
We found that json-schema-to-mongoose 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.