jest
Advanced tools
Comparing version 0.1.22 to 0.1.30
34
api.js
var _ = require('underscore'), | ||
Class = require('sji'), | ||
Resource = require('express-resource'); | ||
Class = require('sji'); | ||
@@ -133,11 +132,26 @@ var Api = module.exports = Class.extend({ | ||
this.app.resource(resource.path, (function(methods){ | ||
_.each(['show', 'index', 'create', 'update', 'destroy', 'load'], function(name) { | ||
methods[name] = function () { | ||
return resource[name].apply(resource, arguments); | ||
}; | ||
}); | ||
return methods; | ||
})({})); | ||
this.app.get('/' + resource.path, function(req, res){ | ||
resource.index(req, res); | ||
}); | ||
this.app.get('/' + resource.path + '/:id', function(req, res){ | ||
req._id = req.params.id; | ||
resource.show(req, res); | ||
}); | ||
this.app.post('/' + resource.path, function(req, res){ | ||
req._id = req.params.id; | ||
resource.create(req, res); | ||
}); | ||
this.app.delete('/' + resource.path + '/:id', function(req, res){ | ||
req._id = req.params.id; | ||
resource.destroy(req, res); | ||
}); | ||
this.app.put('/' + resource.path + '/:id', function(req, res){ | ||
req._id = req.params.id; | ||
resource.update(req, res); | ||
}); | ||
}, | ||
@@ -144,0 +158,0 @@ //Alias for register -Backword Compability |
@@ -113,6 +113,15 @@ var _ = require('underscore'), | ||
var default_sort = query.options.sort || []; | ||
default_sort = _.filter(default_sort,function(sort) { | ||
var field = sort[0]; | ||
return _.all(sorts,function(sort_query) { | ||
return sort_query.field != field; | ||
}); | ||
}); | ||
query.options.sort = []; | ||
for (var i = 0; i < sorts.length; i++) | ||
query.sort(sorts[i].field, sorts[i].type); | ||
for (var i = 0; i < sorts.length; i++) { | ||
var sort_arg = {}; | ||
sort_arg[sorts[sorts.length-1-i].field] = sorts[sorts.length-1-i].type; | ||
query.sort(sort_arg); | ||
} | ||
@@ -119,0 +128,0 @@ for(var i=0; i<default_sort.length; i++) |
{ | ||
"name":"jest", | ||
"description":"JavaScriptational State Transfer. JS restful API layer with Mongoose based resources. Inspired by python Tastypie", | ||
"version":"0.1.22", | ||
"version":"0.1.30", | ||
"author":"Ishai Jaffe <ishai@empeeric.com>", | ||
@@ -10,3 +10,2 @@ "contributors": [ | ||
"dependencies":{ | ||
"express-resource":"", | ||
"underscore":"", | ||
@@ -13,0 +12,0 @@ "sji":"" |
Jest | ||
==== | ||
> JavaScriptational State Stasfer for node.js with easy generating resource from Mongoose ORM | ||
> JavaScriptational State Transfer for node.js with easy generating resource from Mongoose ORM | ||
@@ -10,4 +10,4 @@ #### # | ||
------------ | ||
This module provides: | ||
- Resource base class with: | ||
This module provides Resource base class with: | ||
- Authentication | ||
@@ -24,56 +24,60 @@ - Authorization | ||
-------- | ||
```js | ||
var express = require('express'), | ||
app = express.createServer(), | ||
Jest = require('jest'), | ||
mongoose = require('mongoose'), | ||
Schema = mongoose.Schema; | ||
var express = require('express') | ||
, app = express.createServer(), | ||
, mongoose = require('mongoose') | ||
, Jest = require('jest'); | ||
mongoose.connect('mongodb://localhost/app'); | ||
``` | ||
var Schema = mongoose.Schema; | ||
mongoose.connect('mongodb://localhost/app'); | ||
// create mongoose model | ||
var User = mongoose.model('user', new Schema({ | ||
username: {type: String, required: true}, | ||
email: String, | ||
password: {type: String, validate: [function(v) { return true}, 'custom validate']}, | ||
credits: {type: Number, min: 1, max: 230}, | ||
role: {type: String, 'default': 'user' ,enum: ['user', 'admin']}, | ||
date: {type:Date, 'default': Date.now}, | ||
groups: [{name:String, permissions: [{name:String, expires:Date}]}] | ||
})); | ||
```js | ||
var User = mongoose.model('user', new Schema({ | ||
username: {type: String, required: true}, | ||
email: String, | ||
password: {type: String, validate: [function(v) { return true}, 'custom validate']}, | ||
credits: {type: Number, min: 1, max: 230}, | ||
role: {type: String, 'default': 'user' ,enum: ['user', 'admin']}, | ||
date: {type:Date, 'default': Date.now}, | ||
groups: [{name:String, permissions: [{name:String, expires:Date}]}] | ||
})); | ||
``` | ||
// create mongoose resource for User model | ||
var UserResource = Jest.MongooseResource.extend({ | ||
init: function(){ | ||
// call Jest.Resource constructor | ||
// passing the Model User we created | ||
this._super(User); | ||
```js | ||
var UserResource = Jest.MongooseResource.extend({ | ||
init: function(){ | ||
// call Jest.Resource constructor | ||
// passing the Model User we created | ||
this._super(User); | ||
// use array to decide which fields will be visible by API | ||
// this.fields = ['username','credits']; | ||
// use tree object to decide recursively which fields to expose | ||
this.fields = {'username': true, 'credits': true, groups: {name: true, permissions: {name: true} }}; | ||
// use array to decide which fields will be visible by API | ||
// this.fields = ['username','credits']; | ||
// use tree object to decide recursively which fields to expose | ||
this.fields = {'username': true, 'credits': true, groups: {name: true, permissions: {name: true} }}; | ||
// use list or | ||
this.update_fields = ['email', 'password']; | ||
// use list or | ||
this.update_fields = ['email', 'password']; | ||
// specify base query for the model | ||
this.default_query = function(query){ | ||
return query.where('credits').gte(10); | ||
}; | ||
// specify base query for the model | ||
this.default_query = function(query){ | ||
return query.where('credits').gte(10); | ||
}; | ||
// specify which fields can be used to filter | ||
this.filtering = {'credits': true}; | ||
// specify which fields can be used to filter | ||
this.filtering = {'credits': true}; | ||
// which http methods are allowed | ||
this.allowed_methods = ['get', 'post', 'put']; | ||
} | ||
}) | ||
// which http methods are allowed | ||
this.allowed_methods = ['get', 'post', 'put']; | ||
} | ||
}) | ||
var api = new Jest.Api('api', app); | ||
var api = new Jest.Api('api', app); | ||
api.register('users', new UserResource()); | ||
api.register('users', new UserResource()); | ||
``` | ||
@@ -80,0 +84,0 @@ installation |
@@ -1,2 +0,2 @@ | ||
var _ = require("underscore"), | ||
var _ = require('underscore'), | ||
Class = require('sji'); | ||
@@ -3,0 +3,0 @@ |
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 2 instances in 1 package
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 3 instances in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses eval() which is a dangerous function. This prevents the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 2 instances in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 9 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
SPDX disjunction
LicenseSPDX disjunction for an artifact's license information
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Bad dependency semver
QualityPackage has dependencies with an invalid semantic version. This could be a sign of beta, low quality, or unmaintained dependencies.
Found 1 instance in 1 package
SPDX disjunction
LicenseSPDX disjunction for an artifact's license information
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found
Found 1 instance in 1 package
4435529
2
297
35155
4
94
3
80
3
249
24
- Removedexpress-resource@