Skip to content

Commit

Permalink
feat: add support for loopback 3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Kirkpatrick authored and Tom Kirkpatrick committed Jun 29, 2017
1 parent de7b8ae commit 918a00f
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 48 deletions.
5 changes: 4 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"extends": "fullcube",
"root": true
"root": true,
"rules": {
"id-match": 0
}
}
6 changes: 3 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const url = require('url')
const rabbit = require('rabbot')
const modelDef = require('./models/rabbitmq.json')

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

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

// Set up the RabbitMQ model.
const RabbitMQ = setupRabbitMQModel(app, settings)
const RabbitMQ = setupRabbitMqModel(app, settings)

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

const connection = rabbit.configurations.default.connection
const connection = _.get(rabbit, 'configurations.default.connection')
const parsedConnectionUri = url.parse(connection.uri)
const ampqStatsOptions = {
username: connection.user,
Expand Down
24 changes: 17 additions & 7 deletions lib/models/rabbitmq.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const Promise = require('bluebird')
const _ = require('lodash')
const rabbit = require('rabbot')
const loopback = require('loopback')

module.exports = function queueFn(RabbitMQ) {
/**
Expand Down Expand Up @@ -36,27 +37,36 @@ module.exports = function queueFn(RabbitMQ) {
}))
}


RabbitMQ.remoteMethod('status', {
isStatic: true,
const statusMethodSpec = {
description: 'Get an status overview of the connected rabbitmq server',
returns: {
arg: 'result',
type: 'Object',
root: true,
},
http: { path: '/status', verb: 'get' },
})
}

if (loopback.version.startsWith(2)) {
statusMethodSpec.isStatic = true
}

RabbitMQ.remoteMethod('status', statusMethodSpec)


RabbitMQ.remoteMethod('queues', {
isStatic: true,
const queuesMethodSpec = {
description: 'Get queues of connected rabbitmq server',
returns: {
arg: 'result',
type: 'Object',
root: true,
},
http: { path: '/queues', verb: 'get' },
})
}

if (loopback.version.startsWith(2)) {
queuesMethodSpec.isStatic = true
}

RabbitMQ.remoteMethod('queues', queuesMethodSpec)
}
43 changes: 20 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"test": "NODE_ENV=test nyc --reporter=lcov --reporter=text --reporter=text-summary mocha test/*test.js",
"dev": "nodemon test/fixtures/test-server/server.js --ignore db.json --ext js,json",
"lint": "eslint .",
"pretestDDD": "npm run lint",
"pretest": "npm run lint",
"test:watch": "npm run test -- -w",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
Expand All @@ -30,37 +30,34 @@
"dependencies": {
"amqp-stats": "https://github.com/fullcube/node-amqp-stats/tarball/fe86722fd278067969f03addde57ed53f0910cd8",
"amqplib": "0.5.1",
"bluebird": "3.4.7",
"debug": "2.6.6",
"bluebird": "3.5.0",
"debug": "2.6.8",
"lodash": "4.17.4",
"rabbot": "1.1.0"
},
"devDependencies": {
"chai": "3.5.0",
"chai": "4.0.2",
"compression": "1.6.2",
"condition-circle": "1.5.0",
"config": "1.24.0",
"coveralls": "2.11.15",
"dirty-chai": "1.2.2",
"eslint": "2.13.1",
"config": "1.26.1",
"coveralls": "2.13.1",
"dirty-chai": "2.0.0",
"eslint": "4.1.1",
"eslint-config-fullcube": "latest",
"eslint-config-loopback": "7.0.1",
"eslint-plugin-mocha": "4.7.0",
"loopback": "2.36.0",
"loopback-boot": "2.23.0",
"loopback-component-explorer": "2.7.0",
"loopback-component-fixtures": "1.0.2",
"loopback-datasource-juggler": "2.53.0",
"mocha": "3.3.0",
"loopback": "3.8.0",
"loopback-boot": "2.25.0",
"loopback-component-explorer": "4.2.0",
"loopback-component-fixtures": "1.1.0",
"mocha": "3.4.2",
"mocha-sinon": "2.0.0",
"nodemon": "1.11.0",
"nyc": "10.3.2",
"semantic-release": "6.3.2",
"serve-favicon": "2.3.2",
"sinon": "2.2.0",
"sinon-chai": "2.10.0",
"supertest": "3.0.0",
"supertest-as-promised": "4.0.2"
"nyc": "11.0.3",
"semantic-release": "6.3.6",
"serve-favicon": "2.4.3",
"sinon": "2.3.6",
"sinon-chai": "2.11.0",
"strong-error-handler": "2.1.0",
"supertest": "3.0.0"
},
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions test/acl.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
require('./common')

const path = require('path')
const requireUncached = require('./common').requireUncached
const json = require('./common').json
const { requireUncached } = require('./common')
const { json } = require('./common')

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

Expand Down
2 changes: 1 addition & 1 deletion test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require('mocha-sinon')()
global.chai.use(require('dirty-chai'))
global.chai.use(require('sinon-chai'))

const request = require('supertest-as-promised')
const request = require('supertest')

// Because require'ing config creates and caches a global singleton,
// We have to invalidate the cache to build new object based on the environment variables above
Expand Down
3 changes: 0 additions & 3 deletions test/fixtures/test-server-acl/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
"urlencoded": {
"extended": true,
"limit": "100kb"
},
"errorHandler": {
"disableStackTrace": false
}
},
"legacyExplorer": false
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/test-server-acl/middleware.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
"loopback#urlNotFound": {}
},
"final:after": {
"loopback#errorHandler": {}
"strong-error-handler": {}
}
}
3 changes: 0 additions & 3 deletions test/fixtures/test-server/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
"urlencoded": {
"extended": true,
"limit": "100kb"
},
"errorHandler": {
"disableStackTrace": false
}
},
"legacyExplorer": false
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/test-server/middleware.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
"loopback#urlNotFound": {}
},
"final:after": {
"loopback#errorHandler": {}
"strong-error-handler": {}
}
}
2 changes: 1 addition & 1 deletion test/initialization.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require('./common')

const path = require('path')
const requireUncached = require('./common').requireUncached
const { requireUncached } = require('./common')

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

Expand Down
2 changes: 1 addition & 1 deletion test/mixin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require('./common')

const path = require('path')
const requireUncached = require('./common').requireUncached
const { requireUncached } = require('./common')

const TEST_APP = path.join(__dirname, 'fixtures/test-server/server.js')
const DELAY = 200
Expand Down
2 changes: 1 addition & 1 deletion test/queue.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require('./common')

const path = require('path')
const requireUncached = require('./common').requireUncached
const { requireUncached } = require('./common')

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

Expand Down

0 comments on commit 918a00f

Please sign in to comment.