Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
The no-ORM for the most popular no-SQL database. Operates on vanilla JS objects, not complex models. Use the same Mongo methods you're used to from the shell, but with additional safeguards and helpers. Validate data against JSON schemas, rename fields
The no-ORM for the most popular no-SQL database. Operates on vanilla JS objects, not complex models. Use the same Mongo methods you're used to from the shell, but with additional safeguards and helpers. Validate data against JSON schemas, rename fields, convert between ObjectIds and strings, handle standardized errors, and more.
Can run commands with make
or npm run
.
npm run prepublish
: Compiles Coffeescript to Javascript, once.npm run watch
: Runs build after every change.npm run test
: Runs tests.var MongoClient = require('mongodb')
var Norm = require("norm");
MongoClient.connect("CONNECTION STRING", function(err, db) {
// handle error
collection = db.collection("COLLECTION_NAME")
var schema = {
field1: {
type: "string",
required: true
}
// etc...
};
// optional, detailed below
var options = {};
var norm = new Norm(collection, schema, options);
});
name
: Used in all error messages. (Default: The name of the collection)additionalProperties
: Whether to allow properties not in the schema. (Default: false)shardOn
: Name of the key to use as a source for the shard key. This should be a key of an Object Id value.shardKeyName
: If shardOn
is enabled, the name of the shard key. (Default: "k")shardRotation
: If shardOn
is enabled, the number of characters to rotate the shard key, for even distribution across shards. (Default: 2)validateIndexes
: If true, return an Index
error whenever a query would perform a full table scan.standardOptions
: Override default options for mongo queries. (Default: {j: true, w: 1, getLastError: 1, safe: true, multi: false, new: true}
)validatorOptions
: Override default options for is-my-json-valid. (Default: {verbose: true}
)For all methods, the following holds.
If query argument is a string, then query will be set to {_id: ObjectId(query)}
ObjectId
error will be returned if the id is invalid.If the query argument is an array, then the query will be set to {_id: {$in: query.map(ObjectId)}}
ObjectId
error will be returned if one or more id of the provided ids are invalid.Empty
will be returned if the array has no elements.{_id: ObjectId(query)}
In all other cases, the query is treated as a regular mongo query.
Operator
error if an unsupported operator is used.Pass a callback to use callback-style. Don't pass a callback, and Norm will return you a Promise. The exception to this is findStream
, which always returns a streams.
norm.find(query[, options][, cb])
norm.findStream(query[, options])
find
but returns a stream of results.norm.findOne(query[, options][, cb])
NotFound
error if no document matches querynorm.count(query[, options][, cb])
norm.create(payload[, options][, cb])
Empty
error if payload is empty.Schema
error if schema is violated.Duplicate
error if uniqueness is violated.norm.update(query, operation[, options][, cb])
$set
, $merge
, etc), it will be wrapped with $set
.{multi: true}
must be passed to update multiple documents at once.Operator
error if an unsupported operator is used.Empty
error if any part of the operation payload is empty.Schema
error if schema is violated.Duplicate
error if uniqueness is violated.findAndModify
for that, which is somewhat slower.norm.findAndModify(query, operation[, options][, cb])
.update
, but returns the resultnorm.remove(query[, options][, cb])
norm.decorate(methods, wrapper)
methods
is an array of strings, each of which should be a Norm methodNorm.READS
and Norm.WRITES
are included on the prototype. Norm.OPERATIONS
is their concatenation.methodName
is the name of the wrapped methodargs
is an array of non-cb arguments passed to the methodoperation
will perform the requested operationcb
is the final callback. Remember to pass it the error and results!For example, the following code will log all db operations:
norm.decorate(Norm.OPERATIONS, function(methodName, args, operation, cb) {
var start = Date.now();
var that = this;
operation(function(err, result) {
console.log("Collection:", that.name)
console.log("Executed:", methodName);
console.log("Arguments:", args);
console.log("Errored?", !!err)
console.log("Time:", Date.now() - start);
cb(err, result);
});
});
norm.collection
norm.errors
NotFound
, Schema
, ObjectId
, Empty
, Operator
, Sharding
, Duplicate
patternProperties
FAQs
The no-ORM for the most popular no-SQL database. Operates on vanilla JS objects, not complex models. Use the same Mongo methods you're used to from the shell, but with additional safeguards and helpers. Validate data against JSON schemas, rename fields
We found that norm demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 25 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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.