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

jsonapi-server

Package Overview
Dependencies
Maintainers
6
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 4.0.0 to 4.1.0

example/handlers/autoincrementHandler.js

4

CHANGELOG.md

@@ -0,1 +1,5 @@

- 2017-11-14 - v4.1.0
- 2017-11-14 - New configuration option to disable automatic id generation.
- 2017-11-14 - Update GraphQL dependencies to latest versions.
- 2017-11-14 - Remove yarn lockfile.
- 2017-11-03 - v4.0.0

@@ -2,0 +6,0 @@ - 2017-11-03 - Return error when a response item does not validate.

@@ -100,1 +100,4 @@

If you look through the example json:api resources in the `/example/resources` folder things should become clearer.
#### generateId
By default, the server autogenerates a UUID for resources which are created without specifying an ID. To disable this behavior (for example, if the database generates an ID by auto-incrementing), set `generateId` to `false`. If the resource's ID is not a UUID, it is also necessary to specify an `id` attribute with the correct type. See `/examples/resorces/autoincrement.js` for an example of such a resource.

2

lib/graphQl/resolvers.js

@@ -104,3 +104,3 @@ 'use strict'

resolvers.generateFilterQueryFromAst = ast => {
const arrays = (ast.fieldASTs || []).map(function (fieldAST) {
const arrays = (ast.fieldNodes || []).map(function (fieldAST) {
return fieldAST.arguments || [ ]

@@ -107,0 +107,0 @@ })

@@ -36,6 +36,4 @@ 'use strict'

theirResource = _.assign(
{
id: uuid.v4(),
type: request.params.type
},
{ type: request.params.type },
(request.resourceConfig.generateId !== false) && { id: uuid.v4() },
theirs.id && { id: theirs.id },

@@ -42,0 +40,0 @@ theirs.attributes,

{
"name": "jsonapi-server",
"version": "4.0.0",
"version": "4.1.0",
"description": "A config driven NodeJS framework implementing json:api",

@@ -30,3 +30,3 @@ "keywords": [

"dependencies": {
"async": "2.5.0",
"async": "2.6.0",
"body-parser": "1.18.2",

@@ -36,5 +36,5 @@ "cookie-parser": "1.4.3",

"express": "4.16.2",
"express-graphql": "0.5.4",
"graphql": "0.7.2",
"joi": "10.6.0",
"express-graphql": "0.6.11",
"graphql": "0.11.7",
"joi": "13.0.2",
"lodash.assign": "4.2.0",

@@ -53,3 +53,3 @@ "lodash.isequal": "4.5.0",

"coveralls": "3.0.0",
"eslint": "4.10.0",
"eslint": "4.11.0",
"eslint-config-standard": "10.2.1",

@@ -60,3 +60,3 @@ "eslint-plugin-import": "2.8.0",

"eslint-plugin-standard": "3.0.1",
"jscpd": "0.6.15",
"jscpd": "0.6.17",
"lokka": "1.7.0",

@@ -66,4 +66,4 @@ "lokka-transport-http": "1.6.1",

"mocha-performance": "0.1.1",
"nyc": "11.2.1",
"swagger-tools": "0.9.11",
"nyc": "11.3.0",
"swagger-tools": "0.10.3",
"v8-profiler": "5.7.0"

@@ -70,0 +70,0 @@ },

@@ -204,2 +204,49 @@ 'use strict'

})
describe('creates a resource with non-UUID ID', () => {
let id
it('works', done => {
const data = {
method: 'post',
url: 'http://localhost:16006/rest/autoincrement',
headers: {
'Content-Type': 'application/vnd.api+json'
},
body: JSON.stringify({
'data': {
'type': 'autoincrement',
'attributes': {
'name': 'bar'
}
}
})
}
helpers.request(data, (err, res, json) => {
assert.equal(err, null)
json = helpers.validateJson(json)
assert.equal(json.data.id, '2')
assert.equal(res.headers.location, `http://localhost:16006/rest/autoincrement/${json.data.id}`)
assert.equal(res.statusCode, '201', 'Expecting 201')
assert.equal(json.data.type, 'autoincrement', 'Should be a autoincrement resource')
id = json.data.id
done()
})
})
it('new resource is retrievable', done => {
const url = `http://localhost:16006/rest/autoincrement/${id}`
helpers.request({
method: 'GET',
url
}, (err, res, json) => {
assert.equal(err, null)
json = helpers.validateJson(json)
assert.equal(res.statusCode, '200', 'Expecting 200 OK')
assert.equal(json.included.length, 0, 'Should be no included resources')
done()
})
})
})
})

@@ -206,0 +253,0 @@ })

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