diff --git a/oada/libs/oada-lib-arangodb/db.js b/oada/libs/oada-lib-arangodb/db.js index 31f590e9..93203079 100644 --- a/oada/libs/oada-lib-arangodb/db.js +++ b/oada/libs/oada-lib-arangodb/db.js @@ -1,6 +1,6 @@ 'use strict'; -var Bluebird = require('bluebird'); +const Bluebird = require('bluebird'); const { Database } = require('arangojs'); const config = require('./config'); @@ -21,7 +21,7 @@ const DeadlockError = { name: 'ArangoError', errorNum: 29, }; -let query = db.query; +const query = db.query; db.query = function (...args) { let tries = 0; function tryquery() { diff --git a/oada/libs/oada-lib-arangodb/init.js b/oada/libs/oada-lib-arangodb/init.js index feffcc28..0817faf0 100644 --- a/oada/libs/oada-lib-arangodb/init.js +++ b/oada/libs/oada-lib-arangodb/init.js @@ -3,14 +3,16 @@ 'use strict'; -const config = require('./config'); +const Bluebird = require('bluebird'); const debug = require('debug'); +const equal = require('deep-equal'); + +const config = require('./config'); +const users = require('./libs/users.js'); + const trace = debug('arango:init:trace'); const error = debug('arango:init:error'); const info = debug('arango:init:info'); -const equal = require('deep-equal'); -const users = require('./libs/users.js'); -const Bluebird = require('bluebird'); // Can't use db.js's db because we're creating the actual database const db = require('arangojs')({ @@ -197,7 +199,8 @@ module.exports = { ' exists on collection ' + colname + ', and ensureDefaults is falsy, ' + - 'so we are DELETING THIS DOCUMENT FROM THE DATABASE! Before deleting, its value in the database was: ', + 'so we are DELETING THIS DOCUMENT FROM THE DATABASE! ' + + 'Before deleting, its value in the database was: ', JSON.stringify(dbdoc, false, ' ') ); return db diff --git a/oada/libs/oada-lib-arangodb/libs/authorizations.js b/oada/libs/oada-lib-arangodb/libs/authorizations.js index 74c0cdf8..56718c4c 100644 --- a/oada/libs/oada-lib-arangodb/libs/authorizations.js +++ b/oada/libs/oada-lib-arangodb/libs/authorizations.js @@ -77,7 +77,7 @@ function save(token) { t._key = t._id.replace(/^authorizations\//, ''); delete t._id; } - trace('save: Replacing/Inserting token ', t); + trace('save: Replacing/Inserting token %s', t); // overwrite will replace the given token if it already exists return authorizations .save(t, { overwrite: true }) diff --git a/oada/libs/oada-lib-arangodb/libs/changes.js b/oada/libs/oada-lib-arangodb/libs/changes.js index 282a4595..811fda85 100644 --- a/oada/libs/oada-lib-arangodb/libs/changes.js +++ b/oada/libs/oada-lib-arangodb/libs/changes.js @@ -1,11 +1,14 @@ 'use strict'; -const db = require('../db'); -const debug = require('debug'); -const trace = debug('arangodb#resources:trace'); const { aql } = require('arangojs'); const pointer = require('json-pointer'); +const debug = require('debug'); + +const db = require('../db'); const config = require('../config'); + +const trace = debug('arangodb#resources:trace'); + const changes = db.collection(config.get('arangodb:collections:changes:name')); const changeEdges = db.collection( config.get('arangodb:collections:changeEdges:name') @@ -148,7 +151,7 @@ function toChangeObj(arangoPathObj) { let body = arangoPathObj.vertices[nVertices - 1].body; let resource_id = arangoPathObj.vertices[nVertices - 1].resource_id; // return change object - trace('toChangeObj: returning change object with body ', body); + trace('toChangeObj: returning change object with body %O', body); return { resource_id, path, @@ -191,7 +194,7 @@ function putChange({ throw new Error('children must be an array.'); } let number = parseInt(rev, 10); - trace('putChange: inserting change with body ', change); + trace('putChange: inserting change with body %O', change); return db .query( aql` diff --git a/oada/libs/oada-lib-arangodb/libs/codes.js b/oada/libs/oada-lib-arangodb/libs/codes.js index a05815fe..e63a8c09 100644 --- a/oada/libs/oada-lib-arangodb/libs/codes.js +++ b/oada/libs/oada-lib-arangodb/libs/codes.js @@ -1,8 +1,9 @@ 'use strict'; +const { aql } = require('arangojs'); + const config = require('../config'); const db = require('../db'); -const { aql } = require('arangojs'); const util = require('../util'); const users = require('./users.js'); diff --git a/oada/libs/oada-lib-arangodb/libs/remoteResources.js b/oada/libs/oada-lib-arangodb/libs/remoteResources.js index 532881fd..fefa3515 100644 --- a/oada/libs/oada-lib-arangodb/libs/remoteResources.js +++ b/oada/libs/oada-lib-arangodb/libs/remoteResources.js @@ -1,11 +1,13 @@ 'use strict'; -const db = require('../db'); -const debug = require('debug'); -const trace = debug('arangodb#remoteResources:trace'); const { aql } = require('arangojs'); +const debug = require('debug'); + +const db = require('../db'); const config = require('../config'); +const trace = debug('arangodb#remoteResources:trace'); + const remoteResources = db.collection( config.get('arangodb:collections:remoteResources:name') ); @@ -31,13 +33,13 @@ function getRemoteId(id, domain) { ` ) .call('all') - .tap((rids) => trace('Found:', rids)); + .tap((rids) => trace('Found: %O', rids)); } function addRemoteId(rid, domain) { let rids = Array.isArray(rid) ? rid : [rid]; - trace('Adding remote IDs:', rids); + trace('Adding remote IDs: %O', rids); return db.query(aql` FOR rid IN ${rids} INSERT { diff --git a/oada/libs/oada-lib-arangodb/libs/resources.js b/oada/libs/oada-lib-arangodb/libs/resources.js index bf332fbf..6056943d 100755 --- a/oada/libs/oada-lib-arangodb/libs/resources.js +++ b/oada/libs/oada-lib-arangodb/libs/resources.js @@ -1,16 +1,19 @@ 'use strict'; -const db = require('../db'); -const debug = require('debug'); -const info = debug('arangodb#resources:info'); -const trace = debug('arangodb#resources:trace'); -const cloneDeep = require('clone-deep'); const Bluebird = require('bluebird'); const { aql } = require('arangojs'); +const debug = require('debug'); +const cloneDeep = require('clone-deep'); const pointer = require('json-pointer'); + +const db = require('../db'); const config = require('../config'); const util = require('../util'); const users = require('./users'); + +const info = debug('arangodb#resources:info'); +const trace = debug('arangodb#resources:trace'); + const resources = db.collection( config.get('arangodb:collections:resources:name') ); @@ -250,7 +253,7 @@ function getResourceOwnerIdRev(id) { ) .then((result) => result.next()) .then((obj) => { - trace('getResourceOwnerIdRev(' + id + '): result = ', obj); + trace('getResourceOwnerIdRev(%s): result = %O', id, obj); return obj; }) .catch( @@ -357,7 +360,7 @@ function putResource(id, obj, checkLinks = true) { return (checkLinks ? addLinks(obj) : Promise.resolve([])).then( function docUpsert(links) { info(`Upserting resource ${obj._key}`); - trace(`Upserting links: ${JSON.stringify(links, null, 2)}`); + trace('Upserting links: %O', links); // TODO: Should it check that graphNodes exist but are wrong? var q; diff --git a/oada/libs/oada-lib-arangodb/libs/users.js b/oada/libs/oada-lib-arangodb/libs/users.js index 983b92ed..e7380b6f 100644 --- a/oada/libs/oada-lib-arangodb/libs/users.js +++ b/oada/libs/oada-lib-arangodb/libs/users.js @@ -1,15 +1,18 @@ 'use strict'; -const debug = require('debug'); -const info = debug('arangodb#resources:info'); -const config = require('../config'); -const db = require('../db.js'); const { aql } = require('arangojs'); -const bcrypt = require('bcryptjs'); const Bluebird = require('bluebird'); +const debug = require('debug'); +const bcrypt = require('bcryptjs'); +const flatten = require('flat'); + +const db = require('../db.js'); +const config = require('../config'); const util = require('../util'); + +const info = debug('arangodb#resources:info'); + const users = db.collection(config.get('arangodb:collections:users:name')); -const flatten = require('flat'); /* user { @@ -112,7 +115,7 @@ function findByUsernamePassword(username, password) { function create(u) { return Bluebird.try(() => { - info('create user was called with data', u); + info('create user was called with data %O', u); if (u.password) u.password = hashPw(u.password); // Throws if username already exists return users.save(u, { returnNew: true }).then((r) => r.new || r); diff --git a/oada/libs/oada-lib-kafka/Requester.js b/oada/libs/oada-lib-kafka/Requester.js index 1622bf19..cdee677b 100644 --- a/oada/libs/oada-lib-kafka/Requester.js +++ b/oada/libs/oada-lib-kafka/Requester.js @@ -15,8 +15,9 @@ 'use strict'; -const EventEmitter = require('events'); const util = require('util'); +const EventEmitter = require('events'); + const ksuid = require('ksuid'); const Bluebird = require('bluebird'); diff --git a/oada/libs/oada-lib-kafka/Responder.js b/oada/libs/oada-lib-kafka/Responder.js index 1a598471..f69fae63 100644 --- a/oada/libs/oada-lib-kafka/Responder.js +++ b/oada/libs/oada-lib-kafka/Responder.js @@ -16,6 +16,7 @@ 'use strict'; const util = require('util'); + const ksuid = require('ksuid'); const Bluebird = require('bluebird'); diff --git a/oada/libs/oada-lib-kafka/base.js b/oada/libs/oada-lib-kafka/base.js index c518d579..81f0d047 100755 --- a/oada/libs/oada-lib-kafka/base.js +++ b/oada/libs/oada-lib-kafka/base.js @@ -16,11 +16,12 @@ 'use strict'; const process = require('process'); - const EventEmitter = require('events'); -var Promise = require('bluebird'); + +const Bluebird = require('bluebird'); const ksuid = require('ksuid'); const kf = require('node-rdkafka'); + const config = require('./config'); const info = require('debug')('@oada/lib-kafka:info'); const error = require('debug')('@oada/lib-kafka:error'); @@ -34,6 +35,7 @@ const rdkafkaOpts = Object.assign(config.get('kafka:librdkafka'), { const CONNECT = Symbol('kafka-lib-connect'); const DATA = Symbol('kafa-lib-data'); + const pollInterval = 500; const healthInterval = 5 * 60 * 1000; @@ -83,7 +85,7 @@ class Base extends EventEmitter { this.consumer.on('error', (...args) => super.emit('error', ...args)); this.producer.on('error', (...args) => super.emit('error', ...args)); this.producer.on('delivery-report', function (err, _report) { - if (err) error('!!!!!!!!!!!!!!!!!!!!!!!', err); + if (err) error('!!!!!!!!!!!!!!!!!!!!!!! %O', err); }); this.consumer.on('event.error', (...args) => @@ -93,13 +95,13 @@ class Base extends EventEmitter { super.emit('error', ...args) ); - let consumerReady = Promise.fromCallback((done) => { + const consumerReady = Bluebird.fromCallback((done) => { this.consumer.on('ready', () => { info(`${this.group}'s consumer ready`); done(); }); }); - let producerReady = Promise.fromCallback((done) => { + const producerReady = Bluebird.fromCallback((done) => { this.producer.on('ready', () => { this.producer.setPollInterval( config.get('kafka:producer:pollInterval') || pollInterval @@ -119,7 +121,7 @@ class Base extends EventEmitter { done(); }); }); - this.ready = Promise.join(consumerReady, producerReady); + this.ready = Bluebird.join(consumerReady, producerReady); super.on('error', die); } @@ -135,7 +137,7 @@ class Base extends EventEmitter { async [CONNECT]() { // Assume all messages are JSON this.consumer.on('data', ({ value, ...data }) => { - let resp = JSON.parse(value); + const resp = JSON.parse(value); super.emit(DATA, resp, data); }); @@ -143,7 +145,7 @@ class Base extends EventEmitter { this.producer.connect(); await this.ready; - let topics = Array.isArray(this.consumeTopic) + const topics = Array.isArray(this.consumeTopic) ? this.consumeTopic : [this.consumeTopic]; this.consumer.subscribe(topics); @@ -154,12 +156,12 @@ class Base extends EventEmitter { async produce({ mesg, topic, part = null }) { // Assume all messages are JSON - let payload = JSON.stringify({ + const payload = JSON.stringify({ time: Date.now(), group: this.group, ...mesg, }); - let value = Buffer.from(payload); + const value = Buffer.from(payload); await this.ready; @@ -167,14 +169,14 @@ class Base extends EventEmitter { } disconnect() { - let dcons = Promise.fromCallback((done) => { + const dcons = Bluebird.fromCallback((done) => { this.consumer.disconnect(() => done()); }); - let dprod = Promise.fromCallback((done) => { + const dprod = Bluebird.fromCallback((done) => { this.producer.disconnect(() => done()); }); - return Promise.join(dcons, dprod); + return Bluebird.join(dcons, dprod); } }