
Security News
/Research
Wallet-Draining npm Package Impersonates Nodemailer to Hijack Crypto Transactions
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
backbone-blueprint
Advanced tools
Creates model/collection hierarchies based on JSON schema.
Based on JSON-Schema specification, but it's slightly modified regards handling relations etc.
var addressSchema = exports.addressSchema = {
id: '/schemas/address',
title: 'Address',
type: 'object',
properties: {
street: { type: 'string' },
city: {type: 'string'},
country: {type: 'string'}
}
};
var Address = Model.extend({
type: 'address',
schema: addressSchema
});
var address = new Address({
street: '221B Baker Street ',
city: 'London',
country: 'England'
});
Relations are defined as
type: 'relation'
collection/model: ModelName
Thus relations can be either Models or Collections.
var Addresses = exports.Addresses = Collection.extend({
model: Address
});
var personSchema = exports.personSchema = {
id: '/schemas/person',
type: 'object',
properties: {
addresses : {
type: 'relation',
collection: Addresses
}
}
};
var person = new Person({
addresses: [{street: 'Baker Street', city: 'London', country: 'GB'}]
});
console.log(person.get('addresses').at(0).get('country'));
Initing a relation might need information from the main model. This is done by passing a references - options to the property. E.g.
properties: {
owner: {
type: 'relation',
model: Person,
references: {id: 'owner_id'}
}
}
will read the value of owner_id
property from the main model, and init relation automatically with it. So e.g. if a Model has {owner_id: 2}
, owner relation will be inited with:
person = new Person({id: 2})
Validation is done by jsonschema module. Validating Models can be created by extending from ValidatingModel.
var schema = {
id: '/schemas/foo',
type: 'object',
properties: {
data: {
type: 'string'
}
}
};
var Foo = ValidatingModel.extend({
type: 'foo',
schema: schema
});
var f = new Foo({data: 'a'});
var errors = f.validate();
Will give an error, since 'data' had incorrect type.
If you want to make more complex validations, that jsonschema does not support, you can extend the customValidation method, see tests for more info.
Passing option {recursive: true}
to toJSON, will also include relation in the JSON output. Sometimes it's useful to control which attributes are included in the JSON. This can be done with projection settings. E.g.
var projection = {
owner: ['id', 'title'],
removeFields: ['addresses']
};
var json = person.toJSON({recursive: true, projection: projection});
will include only 'id' & 'title' fields from the owner relation and will remove the 'addresses' relation completely from the output.
onlyFields option will whitelist the given properties, thus includes only the specified properties in the JSON output.
removeFields option will blacklist the given properties, thus removes the specified properties in the JSON output.
You can define a projection preset in the schema, e.g.
properties: {
...
},
projection: {
mini: {
onlyFields: ['city']
}
}
Then you can give projection options as
person.toJSON({recursive: true, projection: 'mini'})
A property can define convert
function which is called when attribute is set. E.g.:
properties: {
id: {
type: 'integer',
convert: function(attribute) {
return Number(attribute);
}
}, ...
This project is based on https://github.com/redpie/backbone-schema
The MIT License
FAQs
Create object hierarchies based on json schema
The npm package backbone-blueprint receives a total of 1 weekly downloads. As such, backbone-blueprint popularity was classified as not popular.
We found that backbone-blueprint demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 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
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.