From 7401244c8f4a949180b53d8380ef3c1c4002b6fe Mon Sep 17 00:00:00 2001 From: Dean McDonnell Date: Tue, 23 Aug 2016 12:10:49 +0100 Subject: [PATCH 1/4] Initial remove --- package.json | 3 +- seneca.js | 71 +-------------------------------------------- test/seneca.test.js | 2 +- 3 files changed, 4 insertions(+), 72 deletions(-) diff --git a/package.json b/package.json index f0b32cc9..787a11e1 100644 --- a/package.json +++ b/package.json @@ -101,6 +101,7 @@ "eslint-plugin-standard": "2.x.x", "lab": "11.0.x", "seneca-entity": "1.2.x", - "seneca-error-test": "0.2.x" + "seneca-error-test": "0.2.x", + "seneca-pin": "senecajs-labs/seneca-pin" } } diff --git a/seneca.js b/seneca.js index e8aeaf68..1c2f8cf6 100644 --- a/seneca.js +++ b/seneca.js @@ -214,6 +214,7 @@ module.exports = function init (seneca_options, more_options) { // Register default plugins, unless turned off by options. if (options.default_plugins.transport) { seneca.use(require('seneca-transport')) + seneca.use(require('seneca-pin')) } // Register plugins specified in options. @@ -310,7 +311,6 @@ function make_seneca (initial_options) { // Non-API methods. root.register = Plugins.register(so, callpoint) root.depends = api_depends - root.pin = api_pin root.act_if = api_act_if root.wrap = api_wrap root.seneca = api_seneca @@ -454,75 +454,6 @@ function make_seneca (initial_options) { return exportval } - // TODO: DEPRECATE - function api_pin (pattern, pinopts) { - var thispin = this - - pattern = _.isString(pattern) ? Jsonic(pattern) : pattern - - var methodkeys = [] - for (var key in pattern) { - if (/[\*\?]/.exec(pattern[key])) { - methodkeys.push(key) - } - } - - function make_pin (pattern) { - var api = { - toString: function () { - return 'pin:' + Common.pattern(pattern) + '/' + thispin - } - } - - var calcPin = function () { - var methods = private$.actrouter.list(pattern) - - methods.forEach(function (method) { - var mpat = method.match - - var methodname = '' - for (var mkI = 0; mkI < methodkeys.length; mkI++) { - methodname += ((mkI > 0 ? '_' : '')) + mpat[methodkeys[mkI]] - } - - api[methodname] = function (args, cb) { - var si = this && this.seneca ? this : thispin - - var fullargs = _.extend({}, args, mpat) - si.act(fullargs, cb) - } - - api[methodname].pattern$ = method.match - api[methodname].name$ = methodname - }) - - if (pinopts && pinopts.include) { - for (var i = 0; i < pinopts.include.length; i++) { - var methodname = pinopts.include[i] - if (thispin[methodname]) { - api[methodname] = Common.delegate(thispin, thispin[methodname]) - } - } - } - } - - var opts = {} - _.defaults(opts, pinopts, so.pin) - - if (private$._isReady || opts.immediate) { - calcPin() - } - else { - root.once('pin', calcPin) - } - - return api - } - - return make_pin(pattern) - } - - function api_sub () { var self = this diff --git a/test/seneca.test.js b/test/seneca.test.js index 9e6bd56a..4e6de98a 100644 --- a/test/seneca.test.js +++ b/test/seneca.test.js @@ -978,7 +978,7 @@ describe('seneca', function () { // --seneca.log.all and count INs // ... | grep act | grep IN | wc -l // sensitive to changes in plugin init and internal action calls - assert.equal('{ calls: 8, done: 8, fails: 0, cache: 1 }', + assert.equal('{ calls: 9, done: 9, fails: 0, cache: 1 }', Util.inspect(stats.act)) done() }) From 9f239230062cac504d628865b079e3a0bc8b71cf Mon Sep 17 00:00:00 2001 From: Dean McDonnell Date: Tue, 23 Aug 2016 12:22:04 +0100 Subject: [PATCH 2/4] Removed pin default options --- seneca.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/seneca.js b/seneca.js index 1c2f8cf6..72218280 100644 --- a/seneca.js +++ b/seneca.js @@ -151,11 +151,6 @@ var internals = { running: false }, - pin: { - // run pin function without waiting for pin event - immediate: false - }, - // backwards compatibility settings legacy: { // use old error codes, until version 3.x From 2efe4329dffdb589a5c2d883edc63ecf60d5c116 Mon Sep 17 00:00:00 2001 From: Dean McDonnell Date: Tue, 23 Aug 2016 12:41:49 +0100 Subject: [PATCH 3/4] Removed event emits out to plugin --- seneca.js | 4 ---- test/seneca.test.js | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/seneca.js b/seneca.js index 72218280..f7b31f1f 100644 --- a/seneca.js +++ b/seneca.js @@ -1702,10 +1702,6 @@ function make_seneca (initial_options) { function action_queue_clear () { root.emit('ready') - // DEPRECATED, removed in Seneca 3.0 - root.emit('pin') - root.emit('after-pin') - var ready = root.private$.ready_list.shift() if (ready) { ready() diff --git a/test/seneca.test.js b/test/seneca.test.js index 4e6de98a..38321bea 100644 --- a/test/seneca.test.js +++ b/test/seneca.test.js @@ -653,7 +653,7 @@ describe('seneca', function () { }) it('pin', function (done) { - var si = Seneca({log: 'silent'}) + var si = Seneca({log: 'silent', pin: {immediate: false}}) var log = [] From 40f2905e055465bab477ca97a13e29eb7d39e01b Mon Sep 17 00:00:00 2001 From: Dean McDonnell Date: Tue, 23 Aug 2016 13:02:18 +0100 Subject: [PATCH 4/4] Removal of pin, - removed default loading of pin - removed associated tests (moved to seneca-pin) - removed package.json entry for seneca-pin --- package.json | 3 +- seneca.js | 1 - test/plugin.test.js | 174 -------------------------------------------- test/seneca.test.js | 97 +----------------------- 4 files changed, 2 insertions(+), 273 deletions(-) diff --git a/package.json b/package.json index 787a11e1..f0b32cc9 100644 --- a/package.json +++ b/package.json @@ -101,7 +101,6 @@ "eslint-plugin-standard": "2.x.x", "lab": "11.0.x", "seneca-entity": "1.2.x", - "seneca-error-test": "0.2.x", - "seneca-pin": "senecajs-labs/seneca-pin" + "seneca-error-test": "0.2.x" } } diff --git a/seneca.js b/seneca.js index f7b31f1f..21ea1876 100644 --- a/seneca.js +++ b/seneca.js @@ -209,7 +209,6 @@ module.exports = function init (seneca_options, more_options) { // Register default plugins, unless turned off by options. if (options.default_plugins.transport) { seneca.use(require('seneca-transport')) - seneca.use(require('seneca-pin')) } // Register plugins specified in options. diff --git a/test/plugin.test.js b/test/plugin.test.js index 03c625ba..2e3ff75a 100644 --- a/test/plugin.test.js +++ b/test/plugin.test.js @@ -379,7 +379,6 @@ describe('plugin', function () { }) }) - it('dynamic-load-sequence', function (done) { var a = [] Seneca({log: 'test', debug: {undead: true}}) @@ -444,7 +443,6 @@ describe('plugin', function () { }) }) - it('plugin options can be modified by plugins during load sequence', function (done) { var seneca = Seneca({ log: 'test', @@ -548,176 +546,4 @@ describe('plugin', function () { done() }) }) - - it('will be able to pin with multiple plugins and local immediate setting', function (done) { - var seneca = Seneca({ log: 'silent' }) - - var pluginA = function () { - this.add({ init: 'pluginA' }, function (msg, cb) { - process.nextTick(cb) - }) - - this.add({ role: 'pluginA', cmd: 'msA1' }, function (msg, cb) { - cb(null, { result: 'msA1' }) - }) - - this.add({ role: 'pluginA', cmd: 'msA2' }, function (msg, cb) { - cb(null, { result: 'msA2' }) - }) - - return { - name: 'pluginA' - } - } - - var pluginB = function () { - this.add({ init: 'pluginB' }, function (msg, cb) { - var api = this.pin({ role: 'pluginA', cmd: '*' }, { immediate: true }) - api.msA1({ msg: 'hi' }, function (err, message) { - expect(err).to.not.exist() - expect(message.result).to.equal('msa1') - }) - cb() - }) - - this.add({ cmd: 'msB1' }, function (msg, cb) { - cb(null, { result: 'msB1' }) - }) - - return { - name: 'pluginB' - } - } - - var pluginC = function () { - this.add({ init: 'pluginC' }, function (msg, cb) { - process.nextTick(cb) - }) - - this.add({ cmd: 'msC1' }, function (msg, cb) { - cb(null, { result: 'msC1' }) - }) - - return { - name: 'pluginC' - } - } - - seneca.use(pluginA) - seneca.use(pluginB) - seneca.use(pluginC) - seneca.ready(function () { - done() - }) - }) - - it('will be able to pin with multiple plugins and seneca pin immediate setting', function (done) { - var seneca = Seneca({ log: 'silent', pin: { immediate: true } }) - - var pluginA = function () { - this.add({ init: 'pluginA' }, function (msg, cb) { - process.nextTick(cb) - }) - - this.add({ role: 'pluginA', cmd: 'msA1' }, function (msg, cb) { - cb(null, { result: 'msA1' }) - }) - - this.add({ role: 'pluginA', cmd: 'msA2' }, function (msg, cb) { - cb(null, { result: 'msA2' }) - }) - - return { - name: 'pluginA' - } - } - - var pluginB = function () { - this.add({ init: 'pluginB' }, function (msg, cb) { - var api = this.pin({ role: 'pluginA', cmd: '*' }) - api.msA1({ msg: 'hi' }, function (err, message) { - expect(err).to.not.exist() - expect(message.result).to.equal('msa1') - }) - cb() - }) - - this.add({ cmd: 'msB1' }, function (msg, cb) { - cb(null, { result: 'msB1' }) - }) - - return { - name: 'pluginB' - } - } - - var pluginC = function () { - this.add({ init: 'pluginC' }, function (msg, cb) { - process.nextTick(cb) - }) - - this.add({ cmd: 'msC1' }, function (msg, cb) { - cb(null, { result: 'msC1' }) - }) - - return { - name: 'pluginC' - } - } - - seneca.use(pluginA) - seneca.use(pluginB) - seneca.use(pluginC) - seneca.ready(function () { - done() - }) - }) - - it('pinning waits for ready by default', function (done) { - var seneca = Seneca({ log: 'silent' }) - - var pluginA = function () { - this.add({ init: 'pluginA' }, function (msg, cb) { - process.nextTick(cb) - }) - - this.add({ role: 'pluginA', cmd: 'msA1' }, function (msg, cb) { - cb(null, { result: 'msA1' }) - }) - - this.add({ role: 'pluginA', cmd: 'msA2' }, function (msg, cb) { - cb(null, { result: 'msA2' }) - }) - - return { - name: 'pluginA' - } - } - - var pluginB = function () { - this.add({ init: 'pluginB' }, function (msg, cb) { - var api = this.pin({ role: 'pluginA', cmd: '*' }) - expect(api.msA1).to.not.exist() - this.once('ping', function () { - api = this.pin({ role: 'pluginA', cmd: '*' }) - expect(api.msA1).to.exist() - }) - cb() - }) - - this.add({ cmd: 'msB1' }, function (msg, cb) { - cb(null, { result: 'msB1' }) - }) - - return { - name: 'pluginB' - } - } - - seneca.use(pluginA) - seneca.use(pluginB) - seneca.ready(function () { - done() - }) - }) }) diff --git a/test/seneca.test.js b/test/seneca.test.js index 38321bea..b44eacc2 100644 --- a/test/seneca.test.js +++ b/test/seneca.test.js @@ -652,68 +652,6 @@ describe('seneca', function () { done() }) - it('pin', function (done) { - var si = Seneca({log: 'silent', pin: {immediate: false}}) - - var log = [] - - si.add({p1: 'v1', p2: 'v2a'}, function (args, cb) { - log.push('a' + args.p3) - cb(null, {p3: args.p3}) - }) - - si.add({p1: 'v1', p2: 'v2b'}, function (args, cb) { - log.push('b' + args.p3) - cb(null, {p3: args.p3}) - }) - - var api = si.pin({p1: 'v1', p2: '*'}) - - si.ready(function () { - api.v2a({p3: 'A'}, function (err, r) { - assert.equal(err, null) - assert.equal(r.p3, 'A') - }) - api.v2b({p3: 'B'}, function (err, r) { - assert.equal(err, null) - assert.equal(r.p3, 'B') - }) - - var acts = si.pinact({p1: 'v1', p2: '*'}) - assert.equal("[ { p1: 'v1', p2: 'v2a' }, { p1: 'v1', p2: 'v2b' } ]", - Util.inspect(acts)) - - done() - }) - }) - - it('pin-star', function (done) { - var si = Seneca(testopts) - - si.add('a:1,b:x', function () {}) - si.add('a:1,c:y', function () {}) - var pin_b = si.pin('a:1,b:*') - var pin_c = si.pin('a:1,c:*') - - si.ready(function () { - assert.ok(_.isFunction(pin_b.x)) - assert.equal(pin_b.y, null) - assert.ok(_.isFunction(pin_c.y)) - assert.equal(pin_c.x, null) - - assert.deepEqual([ { a: '1', b: 'x' }, { a: '1', c: 'y' } ], - si.findpins('a:1')) - - assert.deepEqual([ { a: '1', b: 'x' } ], - si.findpins('a:1,b:*')) - - assert.deepEqual([ { a: '1', c: 'y' } ], - si.findpins('a:1,c:*')) - - done() - }) - }) - it('fire-and-forget', function (done) { var si = Seneca({log: 'silent'}) si.add({a: 1}, function (args, cb) { cb(null, args.a + 1) }) @@ -978,7 +916,7 @@ describe('seneca', function () { // --seneca.log.all and count INs // ... | grep act | grep IN | wc -l // sensitive to changes in plugin init and internal action calls - assert.equal('{ calls: 9, done: 9, fails: 0, cache: 1 }', + assert.equal('{ calls: 8, done: 8, fails: 0, cache: 1 }', Util.inspect(stats.act)) done() }) @@ -1361,37 +1299,4 @@ describe('seneca', function () { done() }) }) - -/* - it('depth0-loop', function (done) { - Seneca({ log: 'silent', strict: { maxloop: 0 } }) - .add('a:1', function (msg, done) { - this.act('a:1', function (err, out) { - done(err, out) - }) - }) - .act('a:1', function (err) { - expect(err).to.exist() - expect(err.code).to.equal('act_loop') - done() - }) - }) - - it('depth3-loop', function (done) { - var count = 0 - Seneca({ log: 'silent', strict: { maxloop: 3 } }) - .add('a:1', function (msg, done) { - ++count - this.act('a:1', function (err, out) { - done(err, out) - }) - }) - .act('a:1', function (err) { - expect(err).to.exist() - expect(err.code).to.equal('act_loop') - expect(count).to.equal(4) - done() - }) - }) -*/ })