Socket
Socket
Sign inDemoInstall

resource-schema

Package Overview
Dependencies
Maintainers
5
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

resource-schema - npm Package Compare versions

Comparing version 0.18.0 to 0.19.0

lib/key_validator.js

7

CHANGELOG.md

@@ -0,1 +1,8 @@

# 0.19.0
## Features
- add $skip query
- add $sort query
- add $addResourceCount query
# 0.15.0

@@ -2,0 +9,0 @@

46

lib/index.js

@@ -40,2 +40,3 @@ // Generated by CoffeeScript 1.9.2

this._getResourceSelectFields = bind(this._getResourceSelectFields, this);
this._getSort = bind(this._getSort, this);
this._getLimit = bind(this._getLimit, this);

@@ -119,3 +120,3 @@ this._applyGetters = bind(this._applyGetters, this);

return function(mongoQuery) {
var limit, modelQuery;
var limit, modelQuery, skip, sort;
modelQuery = _this.Model.find(mongoQuery);

@@ -126,6 +127,19 @@ limit = _this._getLimit(req.query);

}
return modelQuery.exec();
skip = req.query.$skip;
if (skip) {
modelQuery.skip(skip);
}
sort = _this._getSort(req.query);
if (sort) {
modelQuery.sort(sort);
}
return q.all([modelQuery.exec(), _this._getResourceCount(req.query)]);
};
})(this)).then((function(_this) {
return function(models) {
return function(arg) {
var modelCount, models;
models = arg[0], modelCount = arg[1];
if (modelCount) {
res.set('x-resource-count', modelCount);
}
return _this._sendResources(models, requestContext);

@@ -665,2 +679,17 @@ };

/*
Get mongoose value to use for sorting the results.
@param [Object] query - req.query.$sort must be an array or string
@returns [String] Space separated sort string
*/
ResourceSchema.prototype._getSort = function(query) {
if (Array.isArray(query.$sort)) {
return query.$sort.join(' ');
} else if (typeof query.$sort === 'string') {
return query.$sort;
}
};
/*
Get resource fields that will be returned with this request. Reject everything

@@ -1207,4 +1236,15 @@ that not added or selected

ResourceSchema.prototype._getResourceCount = function(query) {
var d;
if (query.$addResourceCount) {
return this.Model.count();
} else {
d = q.defer();
d.resolve(void 0);
return d.promise;
}
};
return ResourceSchema;
})();

2

package.json
{
"name": "resource-schema",
"version": "0.18.0",
"version": "0.19.0",
"description": "Define schemas for RESTful resources from mongoose models, and generate middleware to GET, POST, PUT, and DELETE to those resources.",

@@ -5,0 +5,0 @@ "author": "Good Eggs <open-source@goodeggs.com>",

@@ -369,4 +369,2 @@ # Resource Schema

```
### queryParams: Object

@@ -552,4 +550,27 @@

GET /products?$limit=10
### $skip
Skip number of documents
```
GET /products?$skip=5
```
### $sort
Sort the returned documents
```
GET /products?$sort=name&$sort=-price
```
### $addResourceCount
Add total resource count to the response headers as 'x-resource-count'. Calculating number of pages.
```
GET /products?$addResourceCount=true
```
### $add

@@ -556,0 +577,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc