Socket
Socket
Sign inDemoInstall

jest

Package Overview
Dependencies
0
Maintainers
1
Versions
354
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.22 to 0.1.30

.dbshell

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 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc