From bf3b2cefe4705ccc2384c02ecc9d8cda5d5dd724 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Mon, 27 Mar 2017 14:10:15 +0200 Subject: [PATCH] Preserve custom remoting metadata (shared methods) Allow strong-remoting dependents like loopback to define custom metadata for shared methods. --- lib/shared-method.js | 6 ++++++ test/shared-class.test.js | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/shared-method.js b/lib/shared-method.js index a3195e5c..1f8043e6 100644 --- a/lib/shared-method.js +++ b/lib/shared-method.js @@ -161,6 +161,12 @@ function SharedMethod(fn, name, sc, options) { } this.stringName = (sc ? sc.name : '') + (isStatic ? '.' : '.prototype.') + name; + + // Include any remaining metadata to support custom user-defined extensions + for (var key in options) { + if (this[key]) continue; + this[key] = options[key]; + } } function normalizeArgumentDescriptor(desc) { diff --git a/test/shared-class.test.js b/test/shared-class.test.js index e083cc5c..6c54a264 100644 --- a/test/shared-class.test.js +++ b/test/shared-class.test.js @@ -155,6 +155,16 @@ describe('SharedClass', function() { expect(sc.findMethodByName(METHOD_NAME).accessType).to.eql('READ'); }); + it('defines a remote method with arbitrary custom metadata', function() { + var sc = new SharedClass('SomeClass', SomeClass); + SomeClass.prototype.testFn = function() {}; + sc.defineMethod('testFn', { + isStatic: true, + accessScope: 'read:custom', + }); + expect(sc.findMethodByName('testFn').accessScope).to.eql('read:custom'); + }); + it('should allow a shared class to resolve dynamically defined functions', function(done) { var MyClass = function() {};