@coding-blocks/jsonapi-server
Advanced tools
Comparing version 3.2.6 to 3.3.0
@@ -1,13 +0,1 @@ | ||
- 2017-10-30 - v3.2.6 | ||
- 2017-10-30 - Fix type of "filter" in GraphQL | ||
- 2017-10-26 - v3.2.5 | ||
- 2017-10-26 - remove uuid dependency | ||
- 2017-10-26 - v3.2.4 | ||
- 2017-10-26 - MemoryHandler supports autoincrement | ||
- 2017-10-26 - v3.2.3 | ||
- 2017-10-26 - Use integer autoincrement ID instead of UUID | ||
- 2017-10-26 - Forked from holidayextras to coding-blocks | ||
- 2017-10-21 - v3.2.2 | ||
- 2017-10-21 - Report coverage with Coveralls. | ||
- 2017-10-21 - Modernise script. | ||
- 2017-09-23 - v3.2.1 | ||
@@ -14,0 +2,0 @@ - 2017-09-23 - Fix packaging. |
@@ -156,9 +156,9 @@ ### Foreign Key Relations | ||
// get information about the linkage - list of ids and types | ||
self: "http://localhost:16006/rest/comments/1/relationships/author", | ||
self: "http://localhost:16006/rest/comments/6b017640-827c-4d50-8dcc-79d766abb408/relationships/author", | ||
// get full details of all linked resources | ||
related: "http://localhost:16006/rest/comments/1/author" | ||
related: "http://localhost:16006/rest/comments/6b017640-827c-4d50-8dcc-79d766abb408/author" | ||
}, | ||
data: { | ||
type: "people", | ||
id: "4" | ||
id: "ad3aa89e-9c5b-4ac9-a652-6670f9f27587" | ||
} | ||
@@ -176,5 +176,5 @@ }, | ||
// get information about the linkage - list of ids and types | ||
self: "http://localhost:16006/rest/articles/relationships/?comments=1", | ||
self: "http://localhost:16006/rest/articles/relationships/?comments=6b017640-827c-4d50-8dcc-79d766abb408", | ||
// get full details of all linked resources (perform a search against the foreign key) | ||
related: "http://localhost:16006/rest/articles/?filter[comments]=1" | ||
related: "http://localhost:16006/rest/articles/?filter[comments]=6b017640-827c-4d50-8dcc-79d766abb408" | ||
} | ||
@@ -181,0 +181,0 @@ } |
@@ -23,7 +23,7 @@ ### Creating Custom Handlers | ||
{ | ||
id: "1", | ||
id: "aab14844-97e7-401c-98c8-0bd5ec922d93", | ||
type: "photos", | ||
title: "Matrix Code", | ||
url: "http://www.example.com/foobar", | ||
photographer: { type: "people", id: "4" } | ||
photographer: { type: "people", id: "ad3aa89e-9c5b-4ac9-a652-6670f9f27587" } | ||
} | ||
@@ -102,6 +102,6 @@ ``` | ||
request.params.relationships = { | ||
user: "4" | ||
user: "ad3aa89e-9c5b-4ac9-a652-6670f9f27587" | ||
} | ||
``` | ||
translates to "Find me all of the resources whose user attribute is a link to a resource with id == 4". | ||
translates to "Find me all of the resources whose user attribute is a link to a resource with id == ad3aa89e-9c5b-4ac9-a652-6670f9f27587". | ||
@@ -108,0 +108,0 @@ #### find |
@@ -39,7 +39,7 @@ | ||
{ | ||
id: 1, | ||
id: "aab14844-97e7-401c-98c8-0bd5ec922d93", | ||
type: "photos", | ||
title: "Matrix Code", | ||
url: "http://www.example.com/foobar", | ||
photographer: { type: "people", id: "4" } | ||
photographer: { type: "people", id: "ad3aa89e-9c5b-4ac9-a652-6670f9f27587" } | ||
} | ||
@@ -49,3 +49,2 @@ ] | ||
``` | ||
The examples defined are seeded into the database/memory handler when the server starts. | ||
@@ -103,1 +102,4 @@ ### SearchParams | ||
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. |
@@ -44,3 +44,3 @@ 'use strict' | ||
{ | ||
id: 1, | ||
id: 'de305d54-75b4-431b-adb2-eb6b9e546014', | ||
type: 'articles', | ||
@@ -53,11 +53,11 @@ title: 'NodeJS Best Practices', | ||
type: 'people', | ||
id: 1, | ||
id: 'cc5cca2e-0dd8-4b95-8cfc-a11230e73116', | ||
meta: { updated: '2010-11-06' } | ||
}, | ||
tags: [ | ||
{ type: 'tags', id: 1 } | ||
{ type: 'tags', id: '7541a4de-4986-4597-81b9-cf31b6762486' } | ||
], | ||
photos: [ ], | ||
comments: [ | ||
{ type: 'comments', id: 2 } | ||
{ type: 'comments', id: '3f1a89c2-eb85-4799-a048-6735db24b7eb' } | ||
], | ||
@@ -69,3 +69,3 @@ meta: { | ||
{ | ||
id: 2, | ||
id: '1be0913c-3c25-4261-98f1-e41174025ed5', | ||
type: 'articles', | ||
@@ -76,9 +76,9 @@ title: 'Linux Rocks', | ||
views: 20, | ||
author: { type: 'people', id: 3 }, | ||
author: { type: 'people', id: 'd850ea75-4427-4f81-8595-039990aeede5' }, | ||
tags: [ | ||
{ type: 'tags', id: 2 } | ||
{ type: 'tags', id: '2a3bdea4-a889-480d-b886-104498c86f69' } | ||
], | ||
photos: [ | ||
{ type: 'photos', id: 1 }, | ||
{ type: 'photos', id: 2 } | ||
{ type: 'photos', id: 'aab14844-97e7-401c-98c8-0bd5ec922d93' }, | ||
{ type: 'photos', id: '72695cbd-e9ef-44f6-85e0-0dbc06a269e8' } | ||
], | ||
@@ -88,3 +88,3 @@ comments: [ ] | ||
{ | ||
id: 3, | ||
id: 'd850ea75-4427-4f81-8595-039990aeede5', | ||
type: 'articles', | ||
@@ -95,8 +95,8 @@ title: 'How to AWS', | ||
views: 30, | ||
author: { type: 'people', id: 2 }, | ||
author: { type: 'people', id: '32fb0105-acaa-4adb-9ec4-8b49633695e1' }, | ||
tags: [ | ||
{ type: 'tags', id: 5 } | ||
{ type: 'tags', id: '8d196606-134c-4504-a93a-0d372f78d6c5' } | ||
], | ||
photos: [ | ||
{ type: 'photos', id: 1 } | ||
{ type: 'photos', id: 'aab14844-97e7-401c-98c8-0bd5ec922d93' } | ||
], | ||
@@ -106,3 +106,3 @@ comments: [ ] | ||
{ | ||
id: 4, | ||
id: 'fa2a073f-8c64-4cbb-9158-b8f67a4ab9f5', | ||
type: 'articles', | ||
@@ -113,12 +113,12 @@ title: 'Tea for Beginners', | ||
views: 40, | ||
author: { type: 'people', id: 4 }, | ||
author: { type: 'people', id: 'ad3aa89e-9c5b-4ac9-a652-6670f9f27587' }, | ||
tags: [ | ||
{ type: 'tags', id: 3 }, | ||
{ type: 'tags', id: 1 } | ||
{ type: 'tags', id: '6ec62f6d-9f82-40c5-b4f4-279ed1765492' }, | ||
{ type: 'tags', id: '7541a4de-4986-4597-81b9-cf31b6762486' } | ||
], | ||
photos: [ | ||
{ type: 'photos', id: 3 } | ||
{ type: 'photos', id: '4a8acd65-78bb-4020-b9eb-2d058a86a2a0' } | ||
], | ||
comments: [ | ||
{ type: 'comments', id: 1 } | ||
{ type: 'comments', id: '6b017640-827c-4d50-8dcc-79d766abb408' } | ||
] | ||
@@ -125,0 +125,0 @@ } |
@@ -28,17 +28,17 @@ 'use strict' | ||
{ | ||
id: 1, | ||
id: '6b017640-827c-4d50-8dcc-79d766abb408', | ||
type: 'comments', | ||
body: 'First!', | ||
timestamp: '2017-01-02', | ||
author: { type: 'people', id: 4 } | ||
author: { type: 'people', id: 'ad3aa89e-9c5b-4ac9-a652-6670f9f27587' } | ||
}, | ||
{ | ||
id: 2, | ||
id: '3f1a89c2-eb85-4799-a048-6735db24b7eb', | ||
type: 'comments', | ||
body: 'I like XML better', | ||
timestamp: '2017-06-20', | ||
author: { type: 'people', id: 2, meta: { created: '2010-01-01' } } | ||
author: { type: 'people', id: '32fb0105-acaa-4adb-9ec4-8b49633695e1', meta: { created: '2010-01-01' } } | ||
}, | ||
{ | ||
id: 3, | ||
id: '2f716574-cef6-4238-8285-520911af86c1', | ||
type: 'comments', | ||
@@ -45,0 +45,0 @@ body: 'Wibble wibble.', |
@@ -33,3 +33,3 @@ 'use strict' | ||
{ | ||
id: 1, | ||
id: 'cc5cca2e-0dd8-4b95-8cfc-a11230e73116', | ||
type: 'people', | ||
@@ -41,3 +41,3 @@ firstname: 'Oli', | ||
{ | ||
id: 2, | ||
id: '32fb0105-acaa-4adb-9ec4-8b49633695e1', | ||
type: 'people', | ||
@@ -49,3 +49,3 @@ firstname: 'Pedro', | ||
{ | ||
id: 3, | ||
id: 'd850ea75-4427-4f81-8595-039990aeede5', | ||
type: 'people', | ||
@@ -57,3 +57,3 @@ firstname: 'Mark', | ||
{ | ||
id: 4, | ||
id: 'ad3aa89e-9c5b-4ac9-a652-6670f9f27587', | ||
type: 'people', | ||
@@ -60,0 +60,0 @@ firstname: 'Rahul', |
@@ -40,3 +40,3 @@ 'use strict' | ||
{ | ||
id: 1, | ||
id: 'aab14844-97e7-401c-98c8-0bd5ec922d93', | ||
type: 'photos', | ||
@@ -49,6 +49,6 @@ title: 'Matrix Code', | ||
tags: ['neo', 'morpheus'], | ||
photographer: { type: 'people', id: 4 } | ||
photographer: { type: 'people', id: 'ad3aa89e-9c5b-4ac9-a652-6670f9f27587' } | ||
}, | ||
{ | ||
id: 2, | ||
id: '72695cbd-e9ef-44f6-85e0-0dbc06a269e8', | ||
type: 'photos', | ||
@@ -60,6 +60,6 @@ title: 'Penguins', | ||
tags: ['galapagos', 'emperor'], | ||
photographer: { type: 'people', id: 3 } | ||
photographer: { type: 'people', id: 'd850ea75-4427-4f81-8595-039990aeede5' } | ||
}, | ||
{ | ||
id: 3, | ||
id: '4a8acd65-78bb-4020-b9eb-2d058a86a2a0', | ||
type: 'photos', | ||
@@ -71,6 +71,6 @@ title: 'Cup of Tea', | ||
tags: ['black', 'green'], | ||
photographer: { type: 'people', id: 4 } | ||
photographer: { type: 'people', id: 'ad3aa89e-9c5b-4ac9-a652-6670f9f27587' } | ||
}, | ||
{ | ||
id: 4, | ||
id: 'ed45eba1-15fe-41c7-93da-1df3dfa5289f', | ||
type: 'photos', | ||
@@ -83,3 +83,3 @@ title: 'Sunset Horizon', | ||
tags: ['orange', 'sky', 'sun'], | ||
photographer: { type: 'people', id: 1 } | ||
photographer: { type: 'people', id: 'cc5cca2e-0dd8-4b95-8cfc-a11230e73116' } | ||
} | ||
@@ -86,0 +86,0 @@ |
@@ -28,27 +28,27 @@ 'use strict' | ||
{ | ||
id: 1, | ||
id: '7541a4de-4986-4597-81b9-cf31b6762486', | ||
type: 'tags', | ||
name: 'live', | ||
parent: { type: 'tags', id: 2 } | ||
parent: { type: 'tags', id: '2a3bdea4-a889-480d-b886-104498c86f69' } | ||
}, | ||
{ | ||
id: 2, | ||
id: '2a3bdea4-a889-480d-b886-104498c86f69', | ||
type: 'tags', | ||
name: 'staging', | ||
parent: { type: 'tags', id: 3 } | ||
parent: { type: 'tags', id: '6ec62f6d-9f82-40c5-b4f4-279ed1765492' } | ||
}, | ||
{ | ||
id: 3, | ||
id: '6ec62f6d-9f82-40c5-b4f4-279ed1765492', | ||
type: 'tags', | ||
name: 'building', | ||
parent: { type: 'tags', id: 4 } | ||
parent: { type: 'tags', id: '68538177-7a62-4752-bc4e-8f971d253b42' } | ||
}, | ||
{ | ||
id: 4, | ||
id: '68538177-7a62-4752-bc4e-8f971d253b42', | ||
type: 'tags', | ||
name: 'development', | ||
parent: { type: 'tags', id: 5 } | ||
parent: { type: 'tags', id: '8d196606-134c-4504-a93a-0d372f78d6c5' } | ||
}, | ||
{ | ||
id: 5, | ||
id: '8d196606-134c-4504-a93a-0d372f78d6c5', | ||
type: 'tags', | ||
@@ -55,0 +55,0 @@ name: 'planning', |
@@ -18,20 +18,20 @@ 'use strict' | ||
{ | ||
id: 1, | ||
id: 'fbaefe1b-8b80-42c2-b17c-0c397e5b7a0b', | ||
type: 'tuples', | ||
media: [ | ||
{ type: 'articles', id: 4 }, | ||
{ type: 'photos', id: 2 } | ||
{ type: 'articles', id: 'fa2a073f-8c64-4cbb-9158-b8f67a4ab9f5' }, | ||
{ type: 'photos', id: '72695cbd-e9ef-44f6-85e0-0dbc06a269e8' } | ||
], | ||
preferred: { type: 'articles', id: 4 } | ||
preferred: { type: 'articles', id: 'fa2a073f-8c64-4cbb-9158-b8f67a4ab9f5' } | ||
}, | ||
{ | ||
id: 2, | ||
id: '53e4151d-d47d-4188-be22-2b3a290f6690', | ||
type: 'tuples', | ||
media: [ | ||
{ type: 'articles', id: 3 }, | ||
{ type: 'photos', id: 3 } | ||
{ type: 'articles', id: 'd850ea75-4427-4f81-8595-039990aeede5' }, | ||
{ type: 'photos', id: '4a8acd65-78bb-4020-b9eb-2d058a86a2a0' } | ||
], | ||
preferred: { type: 'photos', id: 2 } | ||
preferred: { type: 'photos', id: '72695cbd-e9ef-44f6-85e0-0dbc06a269e8' } | ||
} | ||
] | ||
}) |
@@ -34,5 +34,2 @@ 'use strict' | ||
} | ||
if (!isNaN(parseInt(element))) { | ||
return { operator: null, value: parseInt(element) } | ||
} | ||
return { operator: null, value: element } | ||
@@ -122,8 +119,3 @@ } | ||
if (typeof filterElement === 'string') { | ||
request.params.filter[key] = filterElement = filterElement.split(FILTER_SEPERATOR).map((i) => { | ||
if (isNaN(parseInt(i))) return i | ||
else return parseInt(i) | ||
}) | ||
} | ||
if (typeof filterElement === 'string') request.params.filter[key] = filterElement = filterElement.split(FILTER_SEPERATOR) | ||
@@ -130,0 +122,0 @@ if (!Array.isArray(filterElement) && filterElement instanceof Object) continue // skip deep filters |
@@ -13,3 +13,3 @@ 'use strict' | ||
description: 'Filter string', | ||
type: graphQl.GraphQLID | ||
type: graphQl.GraphQLString | ||
} | ||
@@ -16,0 +16,0 @@ }) |
@@ -90,3 +90,3 @@ 'use strict' | ||
args: { | ||
id: { type: new graphQl.GraphQLNonNull(graphQl.GraphQLInt) } | ||
id: { type: new graphQl.GraphQLNonNull(graphQl.GraphQLString) } | ||
}, | ||
@@ -93,0 +93,0 @@ type: allReadTypes[resource], |
@@ -84,3 +84,3 @@ 'use strict' | ||
id: { | ||
type: new graphQl.GraphQLNonNull(graphQl.GraphQLInt), | ||
type: new graphQl.GraphQLNonNull(graphQl.GraphQLString), | ||
description: 'The UUID of another resource' | ||
@@ -87,0 +87,0 @@ } |
@@ -31,3 +31,3 @@ 'use strict' | ||
id: { | ||
type: new graphQl.GraphQLNonNull(graphQl.GraphQLInt), | ||
type: new graphQl.GraphQLNonNull(graphQl.GraphQLString), | ||
description: 'The UUID of the resource' | ||
@@ -34,0 +34,0 @@ } |
@@ -10,3 +10,3 @@ 'use strict' | ||
const args = { | ||
id: { type: graphQl.GraphQLInt } | ||
id: { type: graphQl.GraphQLString } | ||
} | ||
@@ -13,0 +13,0 @@ const resourceConfig = jsonApi._resources[resource] |
@@ -96,3 +96,3 @@ 'use strict' | ||
resourceConfig.attributes = _.assign({ | ||
id: ourJoi.Joi.number().integer().required() | ||
id: ourJoi.Joi.string().required() | ||
.description('Unique resource identifier') | ||
@@ -99,0 +99,0 @@ .example('1234'), |
@@ -33,3 +33,2 @@ 'use strict' | ||
let results = [].concat(resources[request.params.type]) | ||
results = results.filter(() => true) | ||
self._sortList(request, results) | ||
@@ -48,3 +47,3 @@ const resultCount = results.length | ||
// Pull the requested resource from the in-memory store | ||
const theResource = resources[request.params.type].filter(anyResource => anyResource.id === parseInt(request.params.id)).pop() | ||
const theResource = resources[request.params.type].filter(anyResource => anyResource.id === request.params.id).pop() | ||
@@ -69,16 +68,2 @@ // If the resource doesn't exist, error | ||
MemoryStore.prototype.create = (request, newResource, callback) => { | ||
if (newResource.id == null) newResource.id = 0 | ||
if (isNaN(newResource.id)) { | ||
return callback({ // eslint-disable-line standard/no-callback-literal | ||
status: '404', | ||
code: 'ENOTFOUND', | ||
title: 'Requested resource does not exist', | ||
detail: `There is no ${request.params.type} with id ${request.params.id}` | ||
}) | ||
} | ||
if (newResource.id === 0) { | ||
newResource.id = resources[request.params.type].length + 1 | ||
} | ||
// Check to see if the ID already exists | ||
@@ -95,3 +80,3 @@ const index = MemoryStore._indexOf(resources[request.params.type], newResource) | ||
// Push the newResource into our in-memory store. | ||
resources[request.params.type][newResource.id - 1] = (newResource) | ||
resources[request.params.type].push(newResource) | ||
// Return the newly created resource | ||
@@ -98,0 +83,0 @@ return callback(null, MemoryStore._clone(newResource)) |
@@ -8,3 +8,3 @@ 'use strict' | ||
const relationType = Joi.object().keys({ | ||
id: Joi.number().integer().required(), | ||
id: Joi.string().required(), | ||
type: Joi.any().required().valid(resourceName), | ||
@@ -11,0 +11,0 @@ meta: Joi.object().optional() |
@@ -8,2 +8,3 @@ 'use strict' | ||
} | ||
const uuid = require('uuid') | ||
const helper = require('./helper.js') | ||
@@ -36,6 +37,4 @@ const router = require('../router.js') | ||
theirResource = _.assign( | ||
{ | ||
id: 0, | ||
type: request.params.type | ||
}, | ||
{ type: request.params.type }, | ||
(request.resourceConfig.generateId !== false) && { id: uuid.v4() }, | ||
theirs.id && { id: theirs.id }, | ||
@@ -42,0 +41,0 @@ theirs.attributes, |
@@ -273,3 +273,3 @@ 'use strict' | ||
required: true, | ||
type: 'number' | ||
type: 'string' | ||
}) | ||
@@ -324,3 +324,3 @@ } | ||
id: { | ||
type: 'number' | ||
type: 'string' | ||
}, | ||
@@ -327,0 +327,0 @@ meta: { |
@@ -25,3 +25,3 @@ 'use strict' | ||
'id': { | ||
type: 'number' | ||
type: 'string' | ||
}, | ||
@@ -106,3 +106,3 @@ 'type': { | ||
id: { | ||
type: 'number' | ||
type: 'string' | ||
}, | ||
@@ -109,0 +109,0 @@ meta: { |
{ | ||
"name": "@coding-blocks/jsonapi-server", | ||
"version": "3.2.6", | ||
"version": "3.3.0", | ||
"description": "A config driven NodeJS framework implementing json:api", | ||
@@ -13,23 +13,10 @@ "keywords": [ | ||
"author": "Coding Blocks <dev@codingblocks.com>", | ||
"contributors": [ | ||
"Oliver Rumbelow", | ||
"Pedro Romano", | ||
"Arnav Gupta <arnav@codingblocks.com>" | ||
], | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/coding-blocks/jsonapi-server" | ||
"url": "https://github.com/coding-blocks/jsonapi-server#old" | ||
}, | ||
"engines": { | ||
"node": ">=6" | ||
"node": ">=4.5" | ||
}, | ||
"greenkeeper": { | ||
"ignore": [ | ||
"express-graphql", | ||
"graphql", | ||
"joi", | ||
"swagger-tools" | ||
] | ||
}, | ||
"dependencies": { | ||
@@ -39,7 +26,7 @@ "async": "2.5.0", | ||
"cookie-parser": "1.4.3", | ||
"debug": "3.1.0", | ||
"express": "4.16.2", | ||
"debug": "3.0.1", | ||
"express": "4.15.4", | ||
"express-graphql": "0.5.4", | ||
"graphql": "0.7.2", | ||
"joi": "10.6.0", | ||
"joi": "11.0.3", | ||
"lodash.assign": "4.2.0", | ||
@@ -52,32 +39,44 @@ "lodash.isequal": "4.5.0", | ||
"qs": "6.5.1", | ||
"request": "2.83.0", | ||
"use-strict": "1.0.1" | ||
"request": "2.82.0", | ||
"use-strict": "1.0.1", | ||
"uuid": "3.1.0" | ||
}, | ||
"devDependencies": { | ||
"coveralls": "3.0.0", | ||
"eslint": "4.9.0", | ||
"eslint": "4.7.2", | ||
"eslint-config-standard": "10.2.1", | ||
"eslint-plugin-import": "2.8.0", | ||
"eslint-plugin-node": "5.2.0", | ||
"eslint-plugin-promise": "3.6.0", | ||
"eslint-plugin-import": "2.7.0", | ||
"eslint-plugin-node": "5.1.1", | ||
"eslint-plugin-promise": "3.5.0", | ||
"eslint-plugin-standard": "3.0.1", | ||
"istanbul": "0.4.5", | ||
"jscpd": "0.6.15", | ||
"lokka": "1.7.0", | ||
"lokka-transport-http": "1.6.1", | ||
"mocha": "4.0.1", | ||
"mocha": "3.5.3", | ||
"mocha-performance": "0.1.1", | ||
"nyc": "11.2.1", | ||
"swagger-tools": "0.9.11", | ||
"plato": "1.7.0", | ||
"swagger-tools": "0.10.1", | ||
"v8-profiler": "5.7.0" | ||
}, | ||
"scripts": { | ||
"test": "node ./node_modules/mocha/bin/mocha --require use-strict -S -R spec ./test/*.js", | ||
"start": "node example/server.js", | ||
"test": "nyc mocha", | ||
"coverage": "[ -n \"$TRAVIS\" ] && nyc report --reporter=text-lcov | coveralls || nyc report --reporter=html", | ||
"coverage": "istanbul cover ./node_modules/mocha/bin/_mocha -- -S -R spec", | ||
"complexity": "node ./node_modules/plato/bin/plato -r -d complexity lib", | ||
"performance": "node --allow-natives-syntax --harmony ./node_modules/mocha/bin/_mocha -S --reporter mocha-performance ./test/*.js", | ||
"lint": "eslint ./example ./lib ./test --quiet && echo '✔ All good!'", | ||
"lint": "node ./node_modules/eslint/bin/eslint ./example ./lib ./test --quiet && echo '✔ All good!'", | ||
"jscpd": "jscpd --blame -p ./lib/ || echo 'Finished!'", | ||
"swagger": "mocha ./swaggerValidator.js --timeout 60000", | ||
"swagger": "node ./node_modules/mocha/bin/mocha --require use-strict -S -R spec ./swaggerValidator.js --timeout 60000", | ||
"ci": "npm run jscpd && npm run lint && npm run test && npm run swagger" | ||
}, | ||
"config": { | ||
"blanket": { | ||
"pattern": ".js", | ||
"data-cover-never": [ | ||
"node_modules", | ||
"test", | ||
"example" | ||
] | ||
} | ||
} | ||
} |
@@ -1,19 +0,7 @@ | ||
[![Build Status](https://travis-ci.org/coding-blocks/jsonapi-server.svg?branch=master)](https://travis-ci.org/coding-blocks/jsonapi-server) | ||
[![Coverage Status](https://coveralls.io/repos/github/coding-blocks/jsonapi-server/badge.svg?branch=master)](https://coveralls.io/github/coding-blocks/jsonapi-server?branch=master) | ||
[![npm version](https://badge.fury.io/js/%40coding-blocks%2Fjsonapi-server.svg)](https://badge.fury.io/js/%40coding-blocks%2Fjsonapi-server) | ||
[![Dependencies Status](https://david-dm.org/coding-blocks/jsonapi-server.svg)](https://david-dm.org/coding-blocks/jsonapi-server) | ||
[![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) | ||
[![Dependencies Status](https://david-dm.org/holidayextras/jsonapi-server.svg)](https://david-dm.org/holidayextras/jsonapi-server) | ||
# jsonapi-server | ||
[![Greenkeeper badge](https://badges.greenkeeper.io/coding-blocks/jsonapi-server.svg)](https://greenkeeper.io/) | ||
**NOTE: This is a fork of holidayextra's [jsonapi-server](https://github.com/holidayextras/jsonapi-server) | ||
The difference being our fork uses integer autoincrement ids instead of UUIDs. | ||
Apart from that, it is exactly the same implementation** | ||
_**You'd want to use our version of jsonapi-store-\[\*\] plugins with this | ||
as the original versions will not be compatible with this**_ | ||
_The rest of the readme is verbatim copy of the original project_ | ||
A config driven NodeJS framework implementing [`json:api`](http://jsonapi.org/) and [`GraphQL`](http://graphql.org/). You define the resources, it provides the api. | ||
@@ -46,8 +34,8 @@ | ||
We've created `handler`s to automatically map our config over to database solutions help people get off the ground: | ||
* [jsonapi-store-memoryhandler](https://github.com/coding-blocks/jsonapi-server/blob/master/lib/MemoryHandler.js) - an in-memory data store to enable rapid prototyping. This ships as a part of `jsonapi-server` and powers the core test suite. | ||
* [jsonapi-handler-chain](https://github.com/coding-blocks/jsonapi-server/blob/master/lib/ChainHandler.js) - a handler to chain custom behaviour around an existing handler. This ships as a part of `jsonapi-server`. More info can be found [here](https://github.com/coding-blocks/jsonapi-server/blob/master/documentation/chain-handler.md) | ||
* [jsonapi-store-memoryhandler](https://github.com/holidayextras/jsonapi-server/blob/master/lib/MemoryHandler.js) - an in-memory data store to enable rapid prototyping. This ships as a part of `jsonapi-server` and powers the core test suite. | ||
* [jsonapi-handler-chain](https://github.com/holidayextras/jsonapi-server/blob/master/lib/ChainHandler.js) - a handler to chain custom behaviour around an existing handler. This ships as a part of `jsonapi-server`. More info can be found [here](https://github.com/holidayextras/jsonapi-server/blob/master/documentation/chain-handler.md) | ||
* [jsonapi-store-relationaldb](https://github.com/holidayextras/jsonapi-store-relationaldb) - using `sequelize` to support PostgreSQL, MySQL, MSSQL, MariaDB and SQLite. | ||
* [jsonapi-store-mongodb](https://github.com/holidayextras/jsonapi-store-mongodb) - for MongoDB. | ||
* [jsonapi-store-elasticsearch](https://github.com/holidayextras/jsonapi-store-elasticsearch) - for Elasticsearch. | ||
* [jsonapi-store-dynamodb](https://github.com/coding-blocks/jsonapi-server/compare/dynamodb?expand=1) - *!SIGNIFICANT WIP!* for AWS DynamoDB. | ||
* [jsonapi-store-dynamodb](https://github.com/holidayextras/jsonapi-server/compare/dynamodb?expand=1) - *!SIGNIFICANT WIP!* for AWS DynamoDB. | ||
@@ -102,3 +90,3 @@ We've also written a library to ease the consumption of a json:api compliant service, if GraphQL isn't your thing: | ||
``` | ||
$ git clone https://github.com/coding-blocks/jsonapi-server.git | ||
$ git clone https://github.com/holidayextras/jsonapi-server.git | ||
$ npm install | ||
@@ -105,0 +93,0 @@ $ npm start |
@@ -11,3 +11,3 @@ 'use strict' | ||
it('returns 200 if resource is ready', done => { | ||
const url = 'http://localhost:16006/rest/articles/1' | ||
const url = 'http://localhost:16006/rest/articles/de305d54-75b4-431b-adb2-eb6b9e546014' | ||
helpers.request({ | ||
@@ -27,3 +27,3 @@ method: 'GET', | ||
handlers.ready = false | ||
const url = 'http://localhost:16006/rest/articles/1' | ||
const url = 'http://localhost:16006/rest/articles/de305d54-75b4-431b-adb2-eb6b9e546014' | ||
helpers.request({ | ||
@@ -30,0 +30,0 @@ method: 'GET', |
@@ -31,3 +31,3 @@ 'use strict' | ||
body: JSON.stringify({ | ||
'data': { 'type': 'people', 'id': 4 } | ||
'data': { 'type': 'people', 'id': 'fa2a073f-8c64-4cbb-9158-b8f67a4ab9f5' } | ||
}) | ||
@@ -47,3 +47,3 @@ } | ||
method: 'delete', | ||
url: 'http://localhost:16006/rest/articles/4/relationships/tags', | ||
url: 'http://localhost:16006/rest/articles/fa2a073f-8c64-4cbb-9158-b8f67a4ab9f5/relationships/tags', | ||
headers: { | ||
@@ -53,3 +53,3 @@ 'Content-Type': 'application/vnd.api+json' | ||
body: JSON.stringify({ | ||
'data': { 'type': 'tags', 'id': 20 } | ||
'data': { 'type': 'tags', 'id': 'foobar' } | ||
}) | ||
@@ -69,3 +69,3 @@ } | ||
method: 'delete', | ||
url: 'http://localhost:16006/rest/articles/4/relationships/tags', | ||
url: 'http://localhost:16006/rest/articles/fa2a073f-8c64-4cbb-9158-b8f67a4ab9f5/relationships/tags', | ||
headers: { | ||
@@ -75,3 +75,3 @@ 'Content-Type': 'application/vnd.api+json' | ||
body: JSON.stringify({ | ||
'data': { 'type': 'people', 'id': 1 } | ||
'data': { 'type': 'people', 'id': '7541a4de-4986-4597-81b9-cf31b6762486' } | ||
}) | ||
@@ -92,3 +92,3 @@ } | ||
method: 'delete', | ||
url: 'http://localhost:16006/rest/articles/4/relationships/tags', | ||
url: 'http://localhost:16006/rest/articles/fa2a073f-8c64-4cbb-9158-b8f67a4ab9f5/relationships/tags', | ||
headers: { | ||
@@ -98,3 +98,3 @@ 'Content-Type': 'application/vnd.api+json' | ||
body: JSON.stringify({ | ||
'data': { 'type': 'tags', 'id': 1 } | ||
'data': { 'type': 'tags', 'id': '7541a4de-4986-4597-81b9-cf31b6762486' } | ||
}) | ||
@@ -113,3 +113,3 @@ } | ||
it('new resource has changed', done => { | ||
const url = 'http://localhost:16006/rest/articles/4/relationships/tags' | ||
const url = 'http://localhost:16006/rest/articles/fa2a073f-8c64-4cbb-9158-b8f67a4ab9f5/relationships/tags' | ||
helpers.request({ | ||
@@ -127,3 +127,3 @@ method: 'GET', | ||
'type': 'tags', | ||
'id': 3 | ||
'id': '6ec62f6d-9f82-40c5-b4f4-279ed1765492' | ||
} | ||
@@ -141,3 +141,3 @@ ]) | ||
method: 'delete', | ||
url: 'http://localhost:16006/rest/articles/4/relationships/author', | ||
url: 'http://localhost:16006/rest/articles/fa2a073f-8c64-4cbb-9158-b8f67a4ab9f5/relationships/author', | ||
headers: { | ||
@@ -147,3 +147,3 @@ 'Content-Type': 'application/vnd.api+json' | ||
body: JSON.stringify({ | ||
'data': { 'type': 'people', 'id': 4 } | ||
'data': { 'type': 'people', 'id': 'ad3aa89e-9c5b-4ac9-a652-6670f9f27587' } | ||
}) | ||
@@ -162,3 +162,3 @@ } | ||
it('new resource has changed', done => { | ||
const url = 'http://localhost:16006/rest/articles/4/relationships/author' | ||
const url = 'http://localhost:16006/rest/articles/fa2a073f-8c64-4cbb-9158-b8f67a4ab9f5/relationships/author' | ||
helpers.request({ | ||
@@ -181,3 +181,3 @@ method: 'GET', | ||
method: 'post', | ||
url: 'http://localhost:16006/rest/articles/4/relationships/author', | ||
url: 'http://localhost:16006/rest/articles/fa2a073f-8c64-4cbb-9158-b8f67a4ab9f5/relationships/author', | ||
headers: { | ||
@@ -187,3 +187,3 @@ 'Content-Type': 'application/vnd.api+json' | ||
body: JSON.stringify({ | ||
'data': { 'type': 'people', 'id': 4 } | ||
'data': { 'type': 'people', 'id': 'ad3aa89e-9c5b-4ac9-a652-6670f9f27587' } | ||
}) | ||
@@ -190,0 +190,0 @@ } |
@@ -42,3 +42,3 @@ 'use strict' | ||
method: 'delete', | ||
url: 'http://localhost:16006/rest/comments/1' | ||
url: 'http://localhost:16006/rest/comments/6b017640-827c-4d50-8dcc-79d766abb408' | ||
} | ||
@@ -57,3 +57,3 @@ request(data, (err, res, json) => { | ||
it('new resource is gone', done => { | ||
const url = 'http://localhost:16006/rest/comments/1' | ||
const url = 'http://localhost:16006/rest/comments/6b017640-827c-4d50-8dcc-79d766abb408' | ||
helpers.request({ | ||
@@ -60,0 +60,0 @@ method: 'GET', |
@@ -24,3 +24,3 @@ 'use strict' | ||
it('unknown relation should error', done => { | ||
const url = 'http://localhost:16006/rest/articles/1/foobar' | ||
const url = 'http://localhost:16006/rest/articles/de305d54-75b4-431b-adb2-eb6b9e546014/foobar' | ||
helpers.request({ | ||
@@ -39,3 +39,3 @@ method: 'GET', | ||
it('foreign relation should error', done => { | ||
const url = 'http://localhost:16006/rest/people/1/articles' | ||
const url = 'http://localhost:16006/rest/people/cc5cca2e-0dd8-4b95-8cfc-a11230e73116/articles' | ||
helpers.request({ | ||
@@ -55,3 +55,3 @@ method: 'GET', | ||
it('Lookup by id', done => { | ||
const url = 'http://localhost:16006/rest/articles/1/author' | ||
const url = 'http://localhost:16006/rest/articles/de305d54-75b4-431b-adb2-eb6b9e546014/author' | ||
helpers.request({ | ||
@@ -73,3 +73,3 @@ method: 'GET', | ||
it('with null data', done => { | ||
const url = 'http://localhost:16006/rest/comments/3/author' | ||
const url = 'http://localhost:16006/rest/comments/2f716574-cef6-4238-8285-520911af86c1/author' | ||
helpers.request({ | ||
@@ -90,3 +90,3 @@ method: 'GET', | ||
it('with fields', done => { | ||
const url = 'http://localhost:16006/rest/articles/1/author?fields[people]=email' | ||
const url = 'http://localhost:16006/rest/articles/de305d54-75b4-431b-adb2-eb6b9e546014/author?fields[people]=email' | ||
helpers.request({ | ||
@@ -109,3 +109,3 @@ method: 'GET', | ||
it('with filter', done => { | ||
const url = 'http://localhost:16006/rest/articles/1/author?filter[email]=email@example.com' | ||
const url = 'http://localhost:16006/rest/articles/de305d54-75b4-431b-adb2-eb6b9e546014/author?filter[email]=email@example.com' | ||
helpers.request({ | ||
@@ -126,3 +126,3 @@ method: 'GET', | ||
it('with includes', done => { | ||
const url = 'http://localhost:16006/rest/articles/1/author?include=articles' | ||
const url = 'http://localhost:16006/rest/articles/de305d54-75b4-431b-adb2-eb6b9e546014/author?include=articles' | ||
helpers.request({ | ||
@@ -129,0 +129,0 @@ method: 'GET', |
@@ -24,3 +24,3 @@ 'use strict' | ||
it('unknown relation should error', done => { | ||
const url = 'http://localhost:16006/rest/articles/1/relationships/foobar' | ||
const url = 'http://localhost:16006/rest/articles/de305d54-75b4-431b-adb2-eb6b9e546014/relationships/foobar' | ||
helpers.request({ | ||
@@ -39,3 +39,3 @@ method: 'GET', | ||
it('Lookup by id', done => { | ||
const url = 'http://localhost:16006/rest/articles/1/relationships/author' | ||
const url = 'http://localhost:16006/rest/articles/de305d54-75b4-431b-adb2-eb6b9e546014/relationships/author' | ||
helpers.request({ | ||
@@ -61,3 +61,3 @@ method: 'GET', | ||
assert.deepEqual(keys, [ 'type', 'id', 'meta' ], 'Relationship data blocks should have specific properties') | ||
assert.equal(typeof dataBlock.id, 'number', 'Relationship data blocks id should be string') | ||
assert.equal(typeof dataBlock.id, 'string', 'Relationship data blocks id should be string') | ||
assert.equal(typeof dataBlock.type, 'string', 'Relationship data blocks type should be string') | ||
@@ -64,0 +64,0 @@ }) |
@@ -11,3 +11,3 @@ 'use strict' | ||
it('unknown id should error', done => { | ||
const url = 'http://localhost:16006/rest/foobar/relationships?author=1' | ||
const url = 'http://localhost:16006/rest/foobar/relationships?author=cc5cca2e-0dd8-4b95-8cfc-a11230e73116' | ||
request({ | ||
@@ -26,3 +26,3 @@ method: 'GET', | ||
it('unknown relation should error', done => { | ||
const url = 'http://localhost:16006/rest/articles/relationships?title=1' | ||
const url = 'http://localhost:16006/rest/articles/relationships?title=cc5cca2e-0dd8-4b95-8cfc-a11230e73116' | ||
request({ | ||
@@ -41,3 +41,3 @@ method: 'GET', | ||
it('Lookup by id', done => { | ||
const url = 'http://localhost:16006/rest/articles/relationships?author=1' | ||
const url = 'http://localhost:16006/rest/articles/relationships?author=cc5cca2e-0dd8-4b95-8cfc-a11230e73116' | ||
request({ | ||
@@ -63,3 +63,3 @@ method: 'GET', | ||
assert.deepEqual(keys, [ 'id', 'type' ], 'Relationship data blocks should have specific properties') | ||
assert.equal(typeof dataBlock.id, 'number', 'Relationship data blocks id should be string') | ||
assert.equal(typeof dataBlock.id, 'string', 'Relationship data blocks id should be string') | ||
assert.equal(typeof dataBlock.type, 'string', 'Relationship data blocks type should be string') | ||
@@ -66,0 +66,0 @@ }) |
@@ -24,3 +24,3 @@ 'use strict' | ||
it('valid lookup', done => { | ||
const url = 'http://localhost:16006/rest/articles/1' | ||
const url = 'http://localhost:16006/rest/articles/de305d54-75b4-431b-adb2-eb6b9e546014' | ||
helpers.request({ | ||
@@ -42,3 +42,3 @@ method: 'GET', | ||
it('with fields', done => { | ||
const url = 'http://localhost:16006/rest/articles/1?fields[articles]=title' | ||
const url = 'http://localhost:16006/rest/articles/de305d54-75b4-431b-adb2-eb6b9e546014?fields[articles]=title' | ||
request({ | ||
@@ -61,3 +61,3 @@ method: 'GET', | ||
it('with filter', done => { | ||
const url = 'http://localhost:16006/rest/articles/1?filter[title]=title' | ||
const url = 'http://localhost:16006/rest/articles/de305d54-75b4-431b-adb2-eb6b9e546014?filter[title]=title' | ||
helpers.request({ | ||
@@ -79,3 +79,3 @@ method: 'GET', | ||
it('basic include', done => { | ||
const url = 'http://localhost:16006/rest/articles/1?include=author' | ||
const url = 'http://localhost:16006/rest/articles/de305d54-75b4-431b-adb2-eb6b9e546014?include=author' | ||
helpers.request({ | ||
@@ -99,3 +99,3 @@ method: 'GET', | ||
it('including over a null relation', done => { | ||
const url = 'http://localhost:16006/rest/tags/5?include=parent' | ||
const url = 'http://localhost:16006/rest/tags/8d196606-134c-4504-a93a-0d372f78d6c5?include=parent' | ||
helpers.request({ | ||
@@ -117,3 +117,3 @@ method: 'GET', | ||
it('works with a manually expanded string', done => { | ||
const url = 'http://localhost:16006/rest/tags/1?include=parent.parent.parent.parent.articles' | ||
const url = 'http://localhost:16006/rest/tags/7541a4de-4986-4597-81b9-cf31b6762486?include=parent.parent.parent.parent.articles' | ||
helpers.request({ | ||
@@ -120,0 +120,0 @@ method: 'GET', |
@@ -352,3 +352,3 @@ 'use strict' | ||
it('allows filtering by id', done => { | ||
const url = 'http://localhost:16006/rest/articles?filter[id]=2&filter[id]=1' | ||
const url = 'http://localhost:16006/rest/articles?filter[id]=1be0913c-3c25-4261-98f1-e41174025ed5&filter[id]=de305d54-75b4-431b-adb2-eb6b9e546014' | ||
helpers.request({ | ||
@@ -369,3 +369,3 @@ method: 'GET', | ||
it('allows for multiple filter values to be combined in a comma-separated list', done => { | ||
const url = 'http://localhost:16006/rest/articles?filter[tags]=3,1,2' | ||
const url = 'http://localhost:16006/rest/articles?filter[tags]=6ec62f6d-9f82-40c5-b4f4-279ed1765492,7541a4de-4986-4597-81b9-cf31b6762486,2a3bdea4-a889-480d-b886-104498c86f69' | ||
helpers.request({ | ||
@@ -386,3 +386,3 @@ method: 'GET', | ||
it('allows for a compound of comma-separated list filters', done => { | ||
const url = 'http://localhost:16006/rest/articles?filter[tags]=3,1,2&filter[id]=1,2' | ||
const url = 'http://localhost:16006/rest/articles?filter[tags]=6ec62f6d-9f82-40c5-b4f4-279ed1765492,7541a4de-4986-4597-81b9-cf31b6762486,2a3bdea4-a889-480d-b886-104498c86f69&filter[id]=de305d54-75b4-431b-adb2-eb6b9e546014,1be0913c-3c25-4261-98f1-e41174025ed5' | ||
helpers.request({ | ||
@@ -403,3 +403,3 @@ method: 'GET', | ||
it('allows deep filtering', done => { | ||
const url = 'http://localhost:16006/rest/articles?include=author&filter[author]=3&filter[author][firstname]=Mark' | ||
const url = 'http://localhost:16006/rest/articles?include=author&filter[author]=d850ea75-4427-4f81-8595-039990aeede5&filter[author][firstname]=Mark' | ||
helpers.request({ | ||
@@ -662,3 +662,3 @@ method: 'GET', | ||
it('include author.photos with multiple filters', done => { | ||
const url = 'http://localhost:16006/rest/articles?include=author.photos&filter[author]=4&filter[author]=1' | ||
const url = 'http://localhost:16006/rest/articles?include=author.photos&filter[author]=ad3aa89e-9c5b-4ac9-a652-6670f9f27587&filter[author]=cc5cca2e-0dd8-4b95-8cfc-a11230e73116' | ||
helpers.request({ | ||
@@ -709,3 +709,3 @@ method: 'GET', | ||
it('should find resources by a relation', done => { | ||
const url = 'http://localhost:16006/rest/articles/?filter[photos]=1' | ||
const url = 'http://localhost:16006/rest/articles/?filter[photos]=aab14844-97e7-401c-98c8-0bd5ec922d93' | ||
helpers.request({ | ||
@@ -725,3 +725,3 @@ method: 'GET', | ||
it('should find resources by many relations', done => { | ||
const url = 'http://localhost:16006/rest/articles/?filter[photos]=1&filter[photos]=3' | ||
const url = 'http://localhost:16006/rest/articles/?filter[photos]=aab14844-97e7-401c-98c8-0bd5ec922d93&filter[photos]=4a8acd65-78bb-4020-b9eb-2d058a86a2a0' | ||
helpers.request({ | ||
@@ -741,3 +741,3 @@ method: 'GET', | ||
it('should error with incorrectly named relations', done => { | ||
const url = 'http://localhost:16006/rest/articles/?filter[photo]=1' | ||
const url = 'http://localhost:16006/rest/articles/?filter[photo]=aab14844-97e7-401c-98c8-0bd5ec922d93' | ||
helpers.request({ | ||
@@ -760,3 +760,3 @@ method: 'GET', | ||
it('should error when querying the foreign end of a relationship', done => { | ||
const url = 'http://localhost:16006/rest/comments/?filter[article]=1' | ||
const url = 'http://localhost:16006/rest/comments/?filter[article]=aab14844-97e7-401c-98c8-0bd5ec922d93' | ||
helpers.request({ | ||
@@ -763,0 +763,0 @@ method: 'GET', |
@@ -74,3 +74,3 @@ 'use strict' | ||
describe('write operations', () => { | ||
let tagId = 10 | ||
let tagId = null | ||
@@ -80,6 +80,5 @@ it('create a tag', () => client.mutate(` | ||
createTags(tags: { | ||
id: ${tagId} | ||
name: "test1" | ||
parent: { | ||
id: 1 | ||
id: "7541a4de-4986-4597-81b9-cf31b6762486" | ||
} | ||
@@ -97,3 +96,3 @@ }) { | ||
assert.equal(result.createTags.name, 'test1') | ||
assert.equal(result.createTags.parent.id, 1) | ||
assert.equal(result.createTags.parent.id, '7541a4de-4986-4597-81b9-cf31b6762486') | ||
assert.equal(result.createTags.parent.name, 'live') | ||
@@ -106,6 +105,6 @@ tagId = result.createTags.id | ||
updateTags(tags: { | ||
id: ${tagId} | ||
id: "${tagId}" | ||
name: "test2" | ||
parent: { | ||
id: 4 | ||
id: "68538177-7a62-4752-bc4e-8f971d253b42" | ||
} | ||
@@ -127,3 +126,3 @@ }) { | ||
parent: { | ||
id: 4, | ||
id: '68538177-7a62-4752-bc4e-8f971d253b42', | ||
name: 'development' | ||
@@ -137,3 +136,3 @@ } | ||
{ | ||
deleteTags(id: ${tagId}) { | ||
deleteTags(id: "${tagId}") { | ||
name | ||
@@ -152,3 +151,3 @@ } | ||
{ | ||
tags(id: ${tagId}) { | ||
tags(id: "${tagId}") { | ||
name | ||
@@ -155,0 +154,0 @@ } |
@@ -103,3 +103,3 @@ 'use strict' | ||
assert.ok(dataBlock.id, 'Relationship block should have an id') | ||
assert.equal(typeof dataBlock.id, 'number', 'Relationship data blocks id should be number') | ||
assert.equal(typeof dataBlock.id, 'string', 'Relationship data blocks id should be string') | ||
assert.ok(dataBlock.type, 'Relationship block should have a type') | ||
@@ -106,0 +106,0 @@ assert.equal(typeof dataBlock.type, 'string', 'Relationship data blocks type should be string') |
@@ -26,3 +26,3 @@ 'use strict' | ||
method: 'patch', | ||
url: 'http://localhost:16006/rest/comments/131/relationships/author', | ||
url: 'http://localhost:16006/rest/comments/foobar/relationships/author', | ||
headers: { | ||
@@ -32,3 +32,3 @@ 'Content-Type': 'application/vnd.api+json' | ||
body: JSON.stringify({ | ||
'data': { 'type': 'people', 'id': 4 } | ||
'data': { 'type': 'people', 'id': 'ad3aa89e-9c5b-4ac9-a652-6670f9f27587' } | ||
}) | ||
@@ -48,3 +48,3 @@ } | ||
method: 'patch', | ||
url: 'http://localhost:16006/rest/comments/2/relationships/article', | ||
url: 'http://localhost:16006/rest/comments/3f1a89c2-eb85-4799-a048-6735db24b7eb/relationships/article', | ||
headers: { | ||
@@ -54,3 +54,3 @@ 'Content-Type': 'application/vnd.api+json' | ||
body: JSON.stringify({ | ||
'data': { 'type': 'articles', 'id': 1 } | ||
'data': { 'type': 'articles', 'id': 'de305d54-75b4-431b-adb2-eb6b9e546014' } | ||
}) | ||
@@ -71,3 +71,3 @@ } | ||
method: 'patch', | ||
url: 'http://localhost:16006/rest/comments/2/relationships/author', | ||
url: 'http://localhost:16006/rest/comments/3f1a89c2-eb85-4799-a048-6735db24b7eb/relationships/author', | ||
headers: { | ||
@@ -77,3 +77,3 @@ 'Content-Type': 'application/vnd.api+json' | ||
body: JSON.stringify({ | ||
'data': { 'type': 'people', 'id': 4, meta: { updated: '2012-01-01' } } | ||
'data': { 'type': 'people', 'id': 'ad3aa89e-9c5b-4ac9-a652-6670f9f27587', meta: { updated: '2012-01-01' } } | ||
}) | ||
@@ -92,3 +92,3 @@ } | ||
it('new resource has changed', done => { | ||
const url = 'http://localhost:16006/rest/comments/2/relationships/author' | ||
const url = 'http://localhost:16006/rest/comments/3f1a89c2-eb85-4799-a048-6735db24b7eb/relationships/author' | ||
helpers.request({ | ||
@@ -105,3 +105,3 @@ method: 'GET', | ||
'type': 'people', | ||
'id': 4, | ||
'id': 'ad3aa89e-9c5b-4ac9-a652-6670f9f27587', | ||
'meta': { | ||
@@ -108,0 +108,0 @@ 'updated': '2012-01-01' |
@@ -28,3 +28,3 @@ 'use strict' | ||
method: 'patch', | ||
url: 'http://localhost:16006/rest/comments/654', | ||
url: 'http://localhost:16006/rest/comments/foobar', | ||
headers: { | ||
@@ -53,3 +53,3 @@ 'Content-Type': 'application/vnd.api+json' | ||
method: 'patch', | ||
url: 'http://localhost:16006/rest/comments/2', | ||
url: 'http://localhost:16006/rest/comments/3f1a89c2-eb85-4799-a048-6735db24b7eb', | ||
headers: { | ||
@@ -78,3 +78,3 @@ 'Content-Type': 'application/vnd.api+json' | ||
method: 'patch', | ||
url: 'http://localhost:16006/rest/articles/3', | ||
url: 'http://localhost:16006/rest/articles/d850ea75-4427-4f81-8595-039990aeede5', | ||
headers: { | ||
@@ -105,3 +105,3 @@ 'Content-Type': 'application/vnd.api+json' | ||
method: 'patch', | ||
url: 'http://localhost:16006/rest/articles/3', | ||
url: 'http://localhost:16006/rest/articles/d850ea75-4427-4f81-8595-039990aeede5', | ||
headers: { | ||
@@ -132,3 +132,3 @@ 'Content-Type': 'application/vnd.api+json' | ||
method: 'patch', | ||
url: 'http://localhost:16006/rest/articles/3', | ||
url: 'http://localhost:16006/rest/articles/d850ea75-4427-4f81-8595-039990aeede5', | ||
headers: { | ||
@@ -141,3 +141,3 @@ 'Content-Type': 'application/vnd.api+json' | ||
'tags': { | ||
'data': [ { 'type': 'tags', 'id': 2 }, undefined ] | ||
'data': [ { 'type': 'tags', 'id': '2a3bdea4-a889-480d-b886-104498c86f69' }, undefined ] | ||
} | ||
@@ -161,3 +161,3 @@ } | ||
method: 'patch', | ||
url: 'http://localhost:16006/rest/articles/3', | ||
url: 'http://localhost:16006/rest/articles/d850ea75-4427-4f81-8595-039990aeede5', | ||
headers: { | ||
@@ -189,3 +189,3 @@ 'Content-Type': 'application/vnd.api+json' | ||
method: 'patch', | ||
url: 'http://localhost:16006/rest/comments/2', | ||
url: 'http://localhost:16006/rest/comments/3f1a89c2-eb85-4799-a048-6735db24b7eb', | ||
headers: { | ||
@@ -201,3 +201,3 @@ 'Content-Type': 'application/vnd.api+json' | ||
'author': { | ||
'data': { 'type': 'people', 'id': 3 } | ||
'data': { 'type': 'people', 'id': 'd850ea75-4427-4f81-8595-039990aeede5' } | ||
} | ||
@@ -222,3 +222,3 @@ }, | ||
it('new resource has changed', done => { | ||
const url = 'http://localhost:16006/rest/comments/2' | ||
const url = 'http://localhost:16006/rest/comments/3f1a89c2-eb85-4799-a048-6735db24b7eb' | ||
helpers.request({ | ||
@@ -235,3 +235,3 @@ method: 'GET', | ||
'type': 'comments', | ||
'id': 2, | ||
'id': '3f1a89c2-eb85-4799-a048-6735db24b7eb', | ||
'attributes': { | ||
@@ -242,3 +242,3 @@ 'body': 'I like XML better', | ||
'links': { | ||
'self': 'http://localhost:16006/rest/comments/2' | ||
'self': 'http://localhost:16006/rest/comments/3f1a89c2-eb85-4799-a048-6735db24b7eb' | ||
}, | ||
@@ -252,8 +252,8 @@ 'relationships': { | ||
'links': { | ||
'self': 'http://localhost:16006/rest/comments/2/relationships/author', | ||
'related': 'http://localhost:16006/rest/comments/2/author' | ||
'self': 'http://localhost:16006/rest/comments/3f1a89c2-eb85-4799-a048-6735db24b7eb/relationships/author', | ||
'related': 'http://localhost:16006/rest/comments/3f1a89c2-eb85-4799-a048-6735db24b7eb/author' | ||
}, | ||
'data': { | ||
'type': 'people', | ||
'id': 3 | ||
'id': 'd850ea75-4427-4f81-8595-039990aeede5' | ||
} | ||
@@ -270,4 +270,4 @@ }, | ||
'links': { | ||
'self': 'http://localhost:16006/rest/articles/relationships/?comments=2', | ||
'related': 'http://localhost:16006/rest/articles/?filter[comments]=2' | ||
'self': 'http://localhost:16006/rest/articles/relationships/?comments=3f1a89c2-eb85-4799-a048-6735db24b7eb', | ||
'related': 'http://localhost:16006/rest/articles/?filter[comments]=3f1a89c2-eb85-4799-a048-6735db24b7eb' | ||
} | ||
@@ -288,3 +288,3 @@ } | ||
method: 'patch', | ||
url: 'http://localhost:16006/rest/comments/2', | ||
url: 'http://localhost:16006/rest/comments/3f1a89c2-eb85-4799-a048-6735db24b7eb', | ||
headers: { | ||
@@ -320,3 +320,3 @@ 'Content-Type': 'application/vnd.api+json' | ||
it('new resource has changed', done => { | ||
const url = 'http://localhost:16006/rest/comments/2' | ||
const url = 'http://localhost:16006/rest/comments/3f1a89c2-eb85-4799-a048-6735db24b7eb' | ||
helpers.request({ | ||
@@ -333,3 +333,3 @@ method: 'GET', | ||
'type': 'comments', | ||
'id': 2, | ||
'id': '3f1a89c2-eb85-4799-a048-6735db24b7eb', | ||
'attributes': { | ||
@@ -340,3 +340,3 @@ 'body': 'I like XML better', | ||
'links': { | ||
'self': 'http://localhost:16006/rest/comments/2' | ||
'self': 'http://localhost:16006/rest/comments/3f1a89c2-eb85-4799-a048-6735db24b7eb' | ||
}, | ||
@@ -350,4 +350,4 @@ 'relationships': { | ||
'links': { | ||
'self': 'http://localhost:16006/rest/comments/2/relationships/author', | ||
'related': 'http://localhost:16006/rest/comments/2/author' | ||
'self': 'http://localhost:16006/rest/comments/3f1a89c2-eb85-4799-a048-6735db24b7eb/relationships/author', | ||
'related': 'http://localhost:16006/rest/comments/3f1a89c2-eb85-4799-a048-6735db24b7eb/author' | ||
}, | ||
@@ -365,4 +365,4 @@ 'data': null | ||
'links': { | ||
'self': 'http://localhost:16006/rest/articles/relationships/?comments=2', | ||
'related': 'http://localhost:16006/rest/articles/?filter[comments]=2' | ||
'self': 'http://localhost:16006/rest/articles/relationships/?comments=3f1a89c2-eb85-4799-a048-6735db24b7eb', | ||
'related': 'http://localhost:16006/rest/articles/?filter[comments]=3f1a89c2-eb85-4799-a048-6735db24b7eb' | ||
} | ||
@@ -369,0 +369,0 @@ } |
@@ -12,3 +12,3 @@ 'use strict' | ||
describe('creates a resource', () => { | ||
let id = 10 | ||
let id = 'e4a1a34f-151b-41ca-a0d9-21726068ba8b' | ||
@@ -15,0 +15,0 @@ it('works', done => { |
@@ -31,3 +31,3 @@ 'use strict' | ||
body: JSON.stringify({ | ||
'data': { 'type': 'people', 'id': 4 } | ||
'data': { 'type': 'people', 'id': 'ad3aa89e-9c5b-4ac9-a652-6670f9f27587' } | ||
}) | ||
@@ -47,3 +47,3 @@ } | ||
method: 'post', | ||
url: 'http://localhost:16006/rest/articles/4/relationships/comments', | ||
url: 'http://localhost:16006/rest/articles/fa2a073f-8c64-4cbb-9158-b8f67a4ab9f5/relationships/comments', | ||
headers: { | ||
@@ -53,3 +53,3 @@ 'Content-Type': 'application/vnd.api+json' | ||
body: JSON.stringify({ | ||
'data': { 'type': 'people', 'id': 1 } | ||
'data': { 'type': 'people', 'id': '6b017640-827c-4d50-8dcc-79d766abb408' } | ||
}) | ||
@@ -70,3 +70,3 @@ } | ||
method: 'post', | ||
url: 'http://localhost:16006/rest/articles/1/relationships/comments', | ||
url: 'http://localhost:16006/rest/articles/de305d54-75b4-431b-adb2-eb6b9e546014/relationships/comments', | ||
headers: { | ||
@@ -76,3 +76,3 @@ 'Content-Type': 'application/vnd.api+json' | ||
body: JSON.stringify({ | ||
'data': { 'type': 'comments', 'id': 1, meta: { 'updated': '2016-01-01' } } | ||
'data': { 'type': 'comments', 'id': '6b017640-827c-4d50-8dcc-79d766abb408', meta: { 'updated': '2016-01-01' } } | ||
}) | ||
@@ -91,3 +91,3 @@ } | ||
it('new resource has changed', done => { | ||
const url = 'http://localhost:16006/rest/articles/1/relationships/comments' | ||
const url = 'http://localhost:16006/rest/articles/de305d54-75b4-431b-adb2-eb6b9e546014/relationships/comments' | ||
helpers.request({ | ||
@@ -105,7 +105,7 @@ method: 'GET', | ||
'type': 'comments', | ||
'id': 2 | ||
'id': '3f1a89c2-eb85-4799-a048-6735db24b7eb' | ||
}, | ||
{ | ||
'type': 'comments', | ||
'id': 1, | ||
'id': '6b017640-827c-4d50-8dcc-79d766abb408', | ||
'meta': { | ||
@@ -126,3 +126,3 @@ 'updated': '2016-01-01' | ||
method: 'post', | ||
url: 'http://localhost:16006/rest/articles/4/relationships/author', | ||
url: 'http://localhost:16006/rest/articles/fa2a073f-8c64-4cbb-9158-b8f67a4ab9f5/relationships/author', | ||
headers: { | ||
@@ -132,3 +132,3 @@ 'Content-Type': 'application/vnd.api+json' | ||
body: JSON.stringify({ | ||
'data': { 'type': 'people', 'id': 1 } | ||
'data': { 'type': 'people', 'id': 'cc5cca2e-0dd8-4b95-8cfc-a11230e73116' } | ||
}) | ||
@@ -147,3 +147,3 @@ } | ||
it('new resource has changed', done => { | ||
const url = 'http://localhost:16006/rest/articles/4/relationships/author' | ||
const url = 'http://localhost:16006/rest/articles/fa2a073f-8c64-4cbb-9158-b8f67a4ab9f5/relationships/author' | ||
helpers.request({ | ||
@@ -160,3 +160,3 @@ method: 'GET', | ||
'type': 'people', | ||
'id': 1 | ||
'id': 'cc5cca2e-0dd8-4b95-8cfc-a11230e73116' | ||
}) | ||
@@ -163,0 +163,0 @@ |
@@ -164,3 +164,3 @@ 'use strict' | ||
'photographer': { | ||
'data': { 'type': 'people', 'id': 1 } | ||
'data': { 'type': 'people', 'id': 'cc5cca2e-0dd8-4b95-8cfc-a11230e73116' } | ||
} | ||
@@ -205,2 +205,49 @@ }, | ||
}) | ||
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() | ||
}) | ||
}) | ||
}) | ||
}) | ||
@@ -207,0 +254,0 @@ }) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6984
295428
18
102
+ Addeduuid@3.1.0
+ Addeddebug@2.6.83.0.1(transitive)
+ Addedexpress@4.15.4(transitive)
+ Addedfinalhandler@1.0.6(transitive)
+ Addedforwarded@0.1.2(transitive)
+ Addedfresh@0.5.0(transitive)
+ Addedipaddr.js@1.4.0(transitive)
+ Addedisemail@3.2.0(transitive)
+ Addedjoi@11.0.3(transitive)
+ Addedmime@1.3.4(transitive)
+ Addedproxy-addr@1.1.5(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqs@6.5.0(transitive)
+ Addedrequest@2.82.0(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsend@0.15.4(transitive)
+ Addedserve-static@1.12.4(transitive)
+ Addedutils-merge@1.0.0(transitive)
+ Addeduuid@3.1.0(transitive)
- Removeddebug@3.1.0(transitive)
- Removedexpress@4.16.2(transitive)
- Removedfinalhandler@1.1.0(transitive)
- Removedforwarded@0.2.0(transitive)
- Removedfresh@0.5.2(transitive)
- Removedipaddr.js@1.9.1(transitive)
- Removedisemail@2.2.1(transitive)
- Removedjoi@10.6.0(transitive)
- Removedmime@1.4.1(transitive)
- Removedproxy-addr@2.0.7(transitive)
- Removedrequest@2.83.0(transitive)
- Removedsafe-buffer@5.1.1(transitive)
- Removedsend@0.16.1(transitive)
- Removedserve-static@1.13.1(transitive)
- Removedutils-merge@1.0.1(transitive)
- Removeduuid@3.4.0(transitive)
Updateddebug@3.0.1
Updatedexpress@4.15.4
Updatedjoi@11.0.3
Updatedrequest@2.82.0