Skip to content

Commit e9c30ac

Browse files
authored
Merge branch 'master' into 285-fix-graphql-updates
2 parents b0ec6c4 + 756d55c commit e9c30ac

File tree

14 files changed

+35
-33
lines changed

14 files changed

+35
-33
lines changed

documentation/configuring.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jsonApi.setConfig({
2222
copyright: "Blah"
2323
},
2424
// Should the interactive GraphQL HTTP interface be served up?
25-
graphiql: true
25+
graphiql: true,
2626
// (optional) meta can be a function to be invoked at the end of every request
2727
meta: function(request) {
2828
return { timestamp: new Date() };

documentation/suggested-project-structure.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ jsonApi.start();
4848
The idea is to stick to having one resource per file and stick to pure config. Each file should do nothing more than define a resource. Handlers should be referenced from the `../handlers` folder, which enables us to easily abstract functionality by sharing features amongst handlers. Resource files are effectively defining your routing layer.
4949

5050
```javascript
51-
var commentHandler = require("../handlers/commentHandler.js");
51+
var photosHandler = require("../handlers/photosHandler.js");
5252

5353
jsonApi.define({
5454
resource: "photos",
55-
handlers: memoryHandler,
55+
handlers: photosHandler,
5656
attributes: {
5757
title: jsonApi.Joi.string()
5858
url: jsonApi.Joi.string().uri()

example/server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ jsonApi.setConfig({
3232

3333
jsonApi.authenticate((request, callback) => {
3434
// If a "blockMe" header is provided, block access.
35-
if (request.headers.blockme) return callback('Fail')
35+
if (request.headers.blockme) return callback(new Error('Fail'))
3636

3737
// If a "blockMe" cookie is provided, block access.
38-
if (request.cookies.blockMe) return callback('Fail')
38+
if (request.cookies.blockMe) return callback(new Error('Fail'))
3939

4040
return callback()
4141
})

lib/MemoryHandler.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ MemoryStore.prototype.find = (request, callback) => {
4747

4848
// If the resource doesn't exist, error
4949
if (!theResource) {
50-
return callback({
50+
return callback({ // eslint-disable-line standard/no-callback-literal
5151
status: '404',
5252
code: 'ENOTFOUND',
5353
title: 'Requested resource does not exist',
@@ -66,7 +66,7 @@ MemoryStore.prototype.create = (request, newResource, callback) => {
6666
// Check to see if the ID already exists
6767
const index = MemoryStore._indexOf(resources[request.params.type], newResource)
6868
if (index !== -1) {
69-
return callback({
69+
return callback({ // eslint-disable-line standard/no-callback-literal
7070
status: '403',
7171
code: 'EFORBIDDEN',
7272
title: 'Requested resource already exists',

lib/postProcessing/fields.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fields.action = (request, response, callback) => {
1111

1212
for (const resource in resourceList) {
1313
if (!jsonApi._resources[resource]) {
14-
return callback({
14+
return callback({ // eslint-disable-line standard/no-callback-literal
1515
status: '403',
1616
code: 'EFORBIDDEN',
1717
title: 'Invalid field resource',
@@ -23,7 +23,7 @@ fields.action = (request, response, callback) => {
2323

2424
for (const j of field) {
2525
if (!jsonApi._resources[resource].attributes[j]) {
26-
return callback({
26+
return callback({ // eslint-disable-line standard/no-callback-literal
2727
status: '403',
2828
code: 'EFORBIDDEN',
2929
title: 'Invalid field selection',

lib/postProcessing/sort.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ sort.action = (request, response, callback) => {
1212
}
1313

1414
if (!request.resourceConfig.attributes[attribute]) {
15-
return callback({
15+
return callback({ // eslint-disable-line standard/no-callback-literal
1616
status: '403',
1717
code: 'EFORBIDDEN',
1818
title: 'Invalid sort',

lib/router.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ router.authenticate = (request, res, callback) => {
133133
detail: err || 'You are not authorised to access this resource.'
134134
}
135135
const payload = responseHelper.generateError(request, errorWrapper)
136-
res.status(401).end(new Buffer(JSON.stringify(payload)))
136+
res.status(401).end(Buffer.from(JSON.stringify(payload)))
137137
})
138138
}
139139

@@ -199,7 +199,7 @@ router._getParams = req => {
199199
router.sendResponse = (res, payload, httpCode) => {
200200
const timeDiff = (new Date()) - res._startDate
201201
metrics.processResponse(res._request, httpCode, payload, timeDiff)
202-
res.status(httpCode).end(new Buffer(JSON.stringify(payload)))
202+
res.status(httpCode).end(Buffer.from(JSON.stringify(payload)))
203203
}
204204

205205
router.getExpressServer = () => {

lib/routes/_foreignKeySearch.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ foreignKeySearchRoute.register = () => {
3030
callback => {
3131
const foreignKeySchema = resourceConfig.attributes[foreignKey]
3232
if (!foreignKeySchema || !foreignKeySchema._settings) {
33-
return callback({
33+
return callback({ // eslint-disable-line standard/no-callback-literal
3434
status: '403',
3535
code: 'EFORBIDDEN',
3636
title: 'Invalid foreign key lookup',
3737
detail: `Relation [${foreignKey}] does not exist within ${request.params.type}`
3838
})
3939
}
4040
if (!(foreignKeySchema._settings.__one || foreignKeySchema._settings.__many)) {
41-
return callback({
41+
return callback({ // eslint-disable-line standard/no-callback-literal
4242
status: '403',
4343
code: 'EFORBIDDEN',
4444
title: 'Invalid foreign key lookup',

lib/routes/find.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ findRoute.register = () => {
3535
},
3636
(sanitisedData, callback) => {
3737
if (!sanitisedData) {
38-
return callback({
38+
return callback({ // eslint-disable-line standard/no-callback-literal
3939
status: '404',
4040
code: 'EVERSION',
4141
title: 'Resource is not valid',

lib/routes/helper.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ helper.validate = (someObject, someDefinition, callback) => {
1313
debug.validationInput(JSON.stringify(someObject))
1414
Joi.validate(someObject, someDefinition, { abortEarly: false }, (err, sanitisedObject) => {
1515
if (err) {
16-
return callback({
16+
return callback({ // eslint-disable-line standard/no-callback-literal
1717
status: '403',
1818
code: 'EFORBIDDEN',
1919
title: 'Param validation failed',
@@ -27,7 +27,7 @@ helper.validate = (someObject, someDefinition, callback) => {
2727

2828
helper.checkForBody = (request, callback) => {
2929
if (!request.params.data) {
30-
return callback({
30+
return callback({ // eslint-disable-line standard/no-callback-literal
3131
status: '403',
3232
code: 'EFORBIDDEN',
3333
title: 'Request validation failed',
@@ -36,7 +36,7 @@ helper.checkForBody = (request, callback) => {
3636
}
3737
// data can be {} or [] both of which are typeof === 'object'
3838
if (typeof request.params.data !== 'object') {
39-
return callback({
39+
return callback({ // eslint-disable-line standard/no-callback-literal
4040
status: '403',
4141
code: 'EFORBIDDEN',
4242
title: 'Request validation failed',

0 commit comments

Comments
 (0)