Skip to content

Commit 918a00f

Browse files
Tom KirkpatrickTom Kirkpatrick
authored andcommitted
feat: add support for loopback 3.x
1 parent de7b8ae commit 918a00f

File tree

13 files changed

+52
-48
lines changed

13 files changed

+52
-48
lines changed

.eslintrc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
22
"extends": "fullcube",
3-
"root": true
3+
"root": true,
4+
"rules": {
5+
"id-match": 0
6+
}
47
}

lib/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const url = require('url')
1111
const rabbit = require('rabbot')
1212
const modelDef = require('./models/rabbitmq.json')
1313

14-
function setupRabbitMQModel(app, settings) {
14+
function setupRabbitMqModel(app, settings) {
1515
// Assign ACLs from the component configuration.
1616
modelDef.acls = _.get(settings, 'options.acls', [])
1717

@@ -33,7 +33,7 @@ module.exports = function loopbackComponentMq(app, settings) {
3333
debug('initializing message queue component with settings: %o', settings)
3434

3535
// Set up the RabbitMQ model.
36-
const RabbitMQ = setupRabbitMQModel(app, settings)
36+
const RabbitMQ = setupRabbitMqModel(app, settings)
3737

3838
// Make the configured logger available.
3939
RabbitMQ.log = _.get(settings, 'options.log', console)
@@ -60,7 +60,7 @@ module.exports = function loopbackComponentMq(app, settings) {
6060
process.exit(1)
6161
})
6262

63-
const connection = rabbit.configurations.default.connection
63+
const connection = _.get(rabbit, 'configurations.default.connection')
6464
const parsedConnectionUri = url.parse(connection.uri)
6565
const ampqStatsOptions = {
6666
username: connection.user,

lib/models/rabbitmq.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const Promise = require('bluebird')
22
const _ = require('lodash')
33
const rabbit = require('rabbot')
4+
const loopback = require('loopback')
45

56
module.exports = function queueFn(RabbitMQ) {
67
/**
@@ -36,27 +37,36 @@ module.exports = function queueFn(RabbitMQ) {
3637
}))
3738
}
3839

39-
40-
RabbitMQ.remoteMethod('status', {
41-
isStatic: true,
40+
const statusMethodSpec = {
4241
description: 'Get an status overview of the connected rabbitmq server',
4342
returns: {
4443
arg: 'result',
4544
type: 'Object',
4645
root: true,
4746
},
4847
http: { path: '/status', verb: 'get' },
49-
})
48+
}
49+
50+
if (loopback.version.startsWith(2)) {
51+
statusMethodSpec.isStatic = true
52+
}
53+
54+
RabbitMQ.remoteMethod('status', statusMethodSpec)
5055

5156

52-
RabbitMQ.remoteMethod('queues', {
53-
isStatic: true,
57+
const queuesMethodSpec = {
5458
description: 'Get queues of connected rabbitmq server',
5559
returns: {
5660
arg: 'result',
5761
type: 'Object',
5862
root: true,
5963
},
6064
http: { path: '/queues', verb: 'get' },
61-
})
65+
}
66+
67+
if (loopback.version.startsWith(2)) {
68+
queuesMethodSpec.isStatic = true
69+
}
70+
71+
RabbitMQ.remoteMethod('queues', queuesMethodSpec)
6272
}

package.json

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"test": "NODE_ENV=test nyc --reporter=lcov --reporter=text --reporter=text-summary mocha test/*test.js",
2222
"dev": "nodemon test/fixtures/test-server/server.js --ignore db.json --ext js,json",
2323
"lint": "eslint .",
24-
"pretestDDD": "npm run lint",
24+
"pretest": "npm run lint",
2525
"test:watch": "npm run test -- -w",
2626
"coverage": "nyc report --reporter=text-lcov | coveralls",
2727
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
@@ -30,37 +30,34 @@
3030
"dependencies": {
3131
"amqp-stats": "https://github.com/fullcube/node-amqp-stats/tarball/fe86722fd278067969f03addde57ed53f0910cd8",
3232
"amqplib": "0.5.1",
33-
"bluebird": "3.4.7",
34-
"debug": "2.6.6",
33+
"bluebird": "3.5.0",
34+
"debug": "2.6.8",
3535
"lodash": "4.17.4",
3636
"rabbot": "1.1.0"
3737
},
3838
"devDependencies": {
39-
"chai": "3.5.0",
39+
"chai": "4.0.2",
4040
"compression": "1.6.2",
4141
"condition-circle": "1.5.0",
42-
"config": "1.24.0",
43-
"coveralls": "2.11.15",
44-
"dirty-chai": "1.2.2",
45-
"eslint": "2.13.1",
42+
"config": "1.26.1",
43+
"coveralls": "2.13.1",
44+
"dirty-chai": "2.0.0",
45+
"eslint": "4.1.1",
4646
"eslint-config-fullcube": "latest",
47-
"eslint-config-loopback": "7.0.1",
48-
"eslint-plugin-mocha": "4.7.0",
49-
"loopback": "2.36.0",
50-
"loopback-boot": "2.23.0",
51-
"loopback-component-explorer": "2.7.0",
52-
"loopback-component-fixtures": "1.0.2",
53-
"loopback-datasource-juggler": "2.53.0",
54-
"mocha": "3.3.0",
47+
"loopback": "3.8.0",
48+
"loopback-boot": "2.25.0",
49+
"loopback-component-explorer": "4.2.0",
50+
"loopback-component-fixtures": "1.1.0",
51+
"mocha": "3.4.2",
5552
"mocha-sinon": "2.0.0",
5653
"nodemon": "1.11.0",
57-
"nyc": "10.3.2",
58-
"semantic-release": "6.3.2",
59-
"serve-favicon": "2.3.2",
60-
"sinon": "2.2.0",
61-
"sinon-chai": "2.10.0",
62-
"supertest": "3.0.0",
63-
"supertest-as-promised": "4.0.2"
54+
"nyc": "11.0.3",
55+
"semantic-release": "6.3.6",
56+
"serve-favicon": "2.4.3",
57+
"sinon": "2.3.6",
58+
"sinon-chai": "2.11.0",
59+
"strong-error-handler": "2.1.0",
60+
"supertest": "3.0.0"
6461
},
6562
"repository": {
6663
"type": "git",

test/acl.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
require('./common')
44

55
const path = require('path')
6-
const requireUncached = require('./common').requireUncached
7-
const json = require('./common').json
6+
const { requireUncached } = require('./common')
7+
const { json } = require('./common')
88

99
const TEST_APP = path.join(__dirname, 'fixtures/test-server-acl/server.js')
1010

test/common.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require('mocha-sinon')()
1111
global.chai.use(require('dirty-chai'))
1212
global.chai.use(require('sinon-chai'))
1313

14-
const request = require('supertest-as-promised')
14+
const request = require('supertest')
1515

1616
// Because require'ing config creates and caches a global singleton,
1717
// We have to invalidate the cache to build new object based on the environment variables above

test/fixtures/test-server-acl/config.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
"urlencoded": {
1717
"extended": true,
1818
"limit": "100kb"
19-
},
20-
"errorHandler": {
21-
"disableStackTrace": false
2219
}
2320
},
2421
"legacyExplorer": false

test/fixtures/test-server-acl/middleware.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020
"loopback#urlNotFound": {}
2121
},
2222
"final:after": {
23-
"loopback#errorHandler": {}
23+
"strong-error-handler": {}
2424
}
2525
}

test/fixtures/test-server/config.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
"urlencoded": {
1717
"extended": true,
1818
"limit": "100kb"
19-
},
20-
"errorHandler": {
21-
"disableStackTrace": false
2219
}
2320
},
2421
"legacyExplorer": false

test/fixtures/test-server/middleware.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020
"loopback#urlNotFound": {}
2121
},
2222
"final:after": {
23-
"loopback#errorHandler": {}
23+
"strong-error-handler": {}
2424
}
2525
}

0 commit comments

Comments
 (0)