
Research
/Security News
Critical Vulnerability in NestJS Devtools: Localhost RCE via Sandbox Escape
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
node2neo-model
Advanced tools
Model support for Node2Neo. This module builds upon the node2neo family of modules. A model uses a node2neo-schema, but can be used independently if required.
NOTE: Neo4j 2.0 is required.
var db = require('node2neo')('http://localhost:7474');
var Model = require('node2neo-model');
Var schema = {
first: {type: String, required: true},
email: {type:String, required: true, index: true},
birthday: Date
}
var User = Model.model('User', schema);
User.create({first: 'Name', email: 'test@test.com'}, function(err, user){
...
})
The first step in the creation of a model is to validate that the data passed in matches the structure defined in the schema. THis reduces teh need to perform checking of input data in your code!
The structure of the create function is .create(data, options, callback); Often when creating a model you want to create a relationship to another object. You can pass in a relationship object to the optional options object.
var relationship = {
indexField: 'email',
indexValue: 'test@test.com',
nodeLabel: 'User', // this is optional, but can narrow down your matched results
type: 'FRIEND',
direction: 'to',
data: {
optional: true
}
}
User.create({first: 'Other', email: 'other@test.com'}, {relationship: relationship}, function(err, results){
// results.node = the newly created node
// results.rel = the newly created relationship
});
To update a model you need an instance of the existing model. There are three ways to update a model: findByIdAndUpdate, findOneAndUpdate or update.
User.findByIdAndUpdate(id, updates, options, callback){
// finds the model and then calls User.update with the model
});
User.findOneAndUpdate(conditions, updates, options, callback){
// finds the model and then calls User.update with the model
});
User.update(model, updates, options, callback){
});
Again the updates are validated against the schema definitions.
The options argument can be used to pass in transactions as well. Transactions let you perform multiple operations with a single atomic transaction. This is useful where you have multiple all-or-nothing statemetns that you want to run.
There are issues with the database locking if two transactions attempt to update the same node so be careful.
NOTE: You cannot create and update a model in the same transaction as the node does not exist in the database until the complete transaction has been committed.
db.beginTransaction (function (err, results) {
if (err) //handle Error
var transId = db.getTransactionId(results.commit);
User.create(data, {transaction: transId}, function(err, user){
Event.create(data, {transaction: transId}, function(err, event){
Other.update(model, updates, {transaction: transId}, function(err, other){
db.commitTransaction(transId, function (err) {
// all or nothing commit
})
})
})
})
})
To remove a node simply pass its id to the remove function. The options object can contain a force option. Removing a node in Neo4j will fail if it has any relationships. The force option deletes the node and all relationships that the node has.
When removing nodes be careful not to leave orphan nodes - remove does not cascade.
User.remove(id, {force: true}, function(err){
})
To find a node you can use the find method.
Find returns an array of nodes and includes an _id field to enable easy referencing of the node.
User.find({email: 'test@test.com'}, function(err, user){
})
// the returned format
[{
_id: 17534,
first: 'Name',
email: 'test@test.com'
}]
'''js
You can pass optional parameters to find:
- limit: limit the number of results
- skip: skip the x number of initial results
- orderBy: sort the results e.g. orderBy: [{field: 'first', desc:true, nulls:true}]
- using: define teh index to use in the lookup
#### Find One
Find returns an array of nodes. However if you know you only want one result you can use findOne. This method does not validate that there is only one result though, if there are multiple results only the first result will be returned.
```js
User.findOne({email: 'test@test.com}, function(err, user){
})
If no node is found node the returned object will be undefined:
User.findOne({email: 'test@test.com, name: 'Test'}, function(err, user){
// user === undefined
});
User.findById(id, function(err, user){
// if not a valid id user === unndefined
});
If you want to find all of the relationships from a node and the related nodes you can use the getRelationships method.
The getRelationships method takes the id of the starting node, and some optional conditions and options.
Conditions include:
The options object is the same as the find options:
User.getRelationships(208, {label: 'Cookies', types: 'Authorises'}, function(err, results){
// results is an object with nodes and rels arrays
// each node includes an _id and _nodeType variable. _nodeType includes the label of the node
// each rel includes _id, type, direction and data. Direction is 'to or 'from'. type is the relationship type, and data contains any data on the relationship.
});
##Licence MIT
FAQs
Model support for Node2neo
The npm package node2neo-model receives a total of 4 weekly downloads. As such, node2neo-model popularity was classified as not popular.
We found that node2neo-model 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
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.