Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jsonapi-server

Package Overview
Dependencies
Maintainers
2
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonapi-server - npm Package Compare versions

Comparing version 0.6.0 to 0.7.0

lib/routes/_foreignKeySearch.js

6

CONTRIBUTING.md

@@ -40,2 +40,8 @@ ### Contributing

To see code complexity statistics:
```
npm run complexity
google-chrome ./complexity/index.html
```
If all of the above comes up good, go ahead and put in a pull request!

6

example/resources/articles.js

@@ -59,3 +59,4 @@ var jsonApi = require("../../.");

{ type: "photos", id: "72695cbd-e9ef-44f6-85e0-0dbc06a269e8" }
]
],
comments: [ ]
},

@@ -73,3 +74,4 @@ {

{ type: "photos", id: "aab14844-97e7-401c-98c8-0bd5ec922d93" }
]
],
comments: [ ]
},

@@ -76,0 +78,0 @@ {

@@ -34,3 +34,3 @@ var jsonApi = require("../../.");

lastname: "Rumbelow",
email: "oliver.rumbelow@holidayextras.com"
email: "oliver.rumbelow@example.com"
},

@@ -42,3 +42,3 @@ {

lastname: "Romano",
email: "pedro.romano@holidayextras.com"
email: "pedro.romano@example.com"
},

@@ -50,3 +50,3 @@ {

lastname: "Fermor",
email: "mark.fermor@holidayextras.com"
email: "mark.fermor@example.com"
},

@@ -58,5 +58,5 @@ {

lastname: "Patel",
email: "rahul.patel@holidayextras.com"
email: "rahul.patel@example.com"
}
]
});

@@ -22,4 +22,13 @@ "use strict";

jsonApi.onUncaughtException(function(request, error) {
var errorDetails = error.stack.split("\n");
console.error(JSON.stringify({
request: request,
error: errorDetails.shift(),
stack: errorDetails
}));
});
jsonApi.start();
server.start = jsonApi.start;
server.close = jsonApi.close;

@@ -8,3 +8,3 @@ "use strict";

var responseHelper = require("./responseHelper.js");
var handlers = require("./handlers.js");
var routes = require("./routes");
var mockHandlers = require("./mockHandlers.js");

@@ -24,3 +24,2 @@ var postProcess = require("./postProcess.js");

postProcess.using(jsonApi);
handlers.using(jsonApi);
};

@@ -85,14 +84,8 @@

jsonApi.onUncaughtException = function(errHandler) {
jsonApi._errHandler = errHandler;
};
jsonApi.start = function() {
handlers._registerForeignKeySearch();
handlers._registerSearch();
handlers._registerFind();
handlers._registerRelated();
handlers._registerRelationships();
handlers._registerCreate();
handlers._registerDelete();
handlers._registerUpdate();
handlers._registerUpdateRelation();
handlers._registerAddRelation();
handlers._registerRemoveRelation();
routes.register();
router.listen(jsonApi._apiConfig.port);

@@ -99,0 +92,0 @@ };

@@ -291,2 +291,38 @@ "use strict";

postProcess._fetchRelatedResources = function(request, mainResource, callback) {
// Fetch the other objects
var dataItems = mainResource[request.params.relation];
if (!(dataItems instanceof Array)) dataItems = [ dataItems ];
var resourcesToFetch = dataItems.map(function(dataItem) {
return "http://" + request.route.host + request.route.base + dataItem.type + "/" + dataItem.id;
});
async.map(resourcesToFetch, function(related, done) {
if (debugExternalRequests) console.log(request.params.requestId, "Rel?", related);
externalRequest.get(related, function(err, externalRes, json) {
if (debugExternalRequests) console.log(request.params.requestId, "Rel!", related);
if (err || !json) return done(null, [ ]);
try {
json = JSON.parse(json);
} catch(e) {
json = null;
}
if (externalRes.statusCode >= 400) {
return done(json.errors);
}
var data = json.data;
if (!(data instanceof Array)) data = [ data ];
return done(null, data);
});
}, function(err, otherResources) {
if (err) return callback(err);
var relatedResources = [].concat.apply([], otherResources);
return callback(null, relatedResources);
});
};
postProcess._applyFields = function(request, response, callback) {

@@ -293,0 +329,0 @@ var fields = request.params.fields;

@@ -91,2 +91,3 @@ "use strict";

relation: "primary",
// type: schemaProperty._settings.__many || schemaProperty._settings.__one,
readOnly: false

@@ -139,2 +140,4 @@ },

belongsTo: relatedResource,
as: schemaProperty._settings.__as,
many: !!schemaProperty._settings.__many,
readOnly: true

@@ -141,0 +144,0 @@ };

@@ -38,4 +38,4 @@ "use strict";

router.bindToServer = function(config, callback) {
app[config.verb](config.path, function(req, res) {
router.bindRoute = function(config, callback) {
app[config.verb](router._jsonApi._apiConfig.base + config.path, function(req, res) {
var request = router._getParams(req);

@@ -49,2 +49,18 @@ var resourceConfig = router._jsonApi._resources[request.params.type];

router.bind404 = function(callback) {
app.use(function(req, res) {
var request = router._getParams(req);
router._setResponseHeaders(request, res);
return callback(request, res);
});
};
router.bindErrorHandler = function(callback) {
app.use(function(error, req, res, next) {
var request = router._getParams(req);
router._setResponseHeaders(request, res);
return callback(request, res, error, next);
});
};
router._getParams = function(req) {

@@ -51,0 +67,0 @@ var urlParts = req.url.split("?");

{
"name": "jsonapi-server",
"version": "0.6.0",
"version": "0.7.0",
"description": "A fully featured NodeJS sever implementation of json:api. You provide the resources, we provide the api.",
"keywords": [
"jsonapi",
"json:api",
"jsonapi",
"api"

@@ -34,3 +34,4 @@ ],

"mocha-lcov-reporter": "0.0.2",
"coveralls": "2.11.2"
"coveralls": "2.11.2",
"plato": "1.5.0"
},

@@ -42,3 +43,4 @@ "scripts": {

"coverage": "./node_modules/mocha/bin/mocha --require blanket --reporter html-cov ./test/*.js > coverage.html",
"lint": "./node_modules/.bin/eslint ./example/*.js ./lib/*.js ./test/*.js --quiet && echo '✔ All good!'"
"complexity": "./node_modules/plato/bin/plato -r -d complexity lib",
"lint": "./node_modules/.bin/eslint ./example/*.js ./lib/* ./test/*.js --quiet && echo '✔ All good!'"
},

@@ -45,0 +47,0 @@ "config": {

[![Coverage Status](https://coveralls.io/repos/holidayextras/jsonapi-server/badge.svg?branch=master)](https://coveralls.io/r/holidayextras/jsonapi-server?branch=master)
[![Build Status](https://travis-ci.org/holidayextras/jsonapi-server.svg?branch=master)](https://travis-ci.org/holidayextras/jsonapi-server)
[![npm version](https://badge.fury.io/js/jsonapi-server.svg)](http://badge.fury.io/js/jsonapi-server)
[![Code Climate](https://codeclimate.com/github/holidayextras/jsonapi-server/badges/gpa.svg)](https://codeclimate.com/github/holidayextras/jsonapi-server)

@@ -7,3 +8,3 @@

`jsonapi-server` is a fully featured NodeJS sever implementation of `json:api`. You provide the resources, we provide the api.
`jsonapi-server` is a fully featured NodeJS server implementation of `json:api`. You provide the resources, we provide the api.

@@ -59,3 +60,3 @@ ### The tl;dr

```
http://localhost:16006/rest/
http://localhost:16006/rest/photos
```

@@ -62,0 +63,0 @@

@@ -142,3 +142,5 @@ "use strict";

"belongsTo": "articles",
"readOnly": true
"as": "comments",
"readOnly": true,
"many": false
},

@@ -145,0 +147,0 @@ "links": {

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