moleculer-decorators
Advanced tools
Comparing version 1.0.10 to 1.0.11
@@ -5,2 +5,3 @@ "use strict"; | ||
const blacklist = ['created', 'started', 'stopped', 'actions', 'methods', 'events']; | ||
const blacklist2 = ['metadata', 'settings', 'mixins', 'name', 'version'].concat(blacklist); | ||
const defaultServiceOptions = { | ||
@@ -37,2 +38,3 @@ constructOverride: true | ||
const proto = target.prototype; | ||
const vars = []; | ||
Object.getOwnPropertyNames(proto).forEach(function (key) { | ||
@@ -45,4 +47,22 @@ if (key === 'constructor') { | ||
base[key] = Object.getOwnPropertyDescriptor(ServiceClass, key).value; | ||
if (blacklist2.indexOf(key) === -1) { | ||
vars[key] = Object.getOwnPropertyDescriptor(ServiceClass, key).value; | ||
} | ||
} | ||
}); | ||
const bypass = Object.defineProperty, obj = {}; | ||
bypass(obj, 'created', { | ||
value: function created() { | ||
for (let key in vars) { | ||
this[key] = vars[key]; | ||
} | ||
if (!_.isNil(Object.getOwnPropertyDescriptor(proto, 'created'))) { | ||
Object.getOwnPropertyDescriptor(proto, 'created').value.call(this); | ||
} | ||
}, | ||
writable: true, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
base['created'] = obj.created; | ||
} | ||
@@ -52,4 +72,7 @@ return; | ||
const descriptor = Object.getOwnPropertyDescriptor(proto, key); | ||
if (key === 'created' || key === 'started' || key === 'stopped') { | ||
if (key === 'created' && !_options.constructOverride) { | ||
base[key] = descriptor.value; | ||
} | ||
if (key === 'started' || key === 'stopped') { | ||
base[key] = descriptor.value; | ||
return; | ||
@@ -56,0 +79,0 @@ } |
{ | ||
"name": "moleculer-decorators", | ||
"version": "1.0.10", | ||
"version": "1.0.11", | ||
"description": "decorators for moleculer", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -5,2 +5,3 @@ import { ServiceSchema, Action, ActionHandler } from 'moleculer'; | ||
const blacklist = ['created', 'started', 'stopped', 'actions', 'methods', 'events']; | ||
const blacklist2 = ['metadata', 'settings', 'mixins', 'name', 'version'].concat(blacklist); | ||
const defaultServiceOptions: Options = { | ||
@@ -55,2 +56,3 @@ constructOverride: true | ||
const proto = target.prototype; | ||
const vars = []; | ||
Object.getOwnPropertyNames(proto).forEach(function (key) { | ||
@@ -64,6 +66,32 @@ if (key === 'constructor') { | ||
base[key] = Object.getOwnPropertyDescriptor(ServiceClass, key)!.value | ||
if (blacklist2.indexOf(key) === -1) { // Needed, otherwize if the service is used as a mixin, these variables will overwrite the toplevel's | ||
vars[key] = Object.getOwnPropertyDescriptor(ServiceClass, key)!.value | ||
} | ||
} | ||
}); | ||
/* Insane hack below :D | ||
* It's needed since moleculer don't transfer all defined props in the | ||
* schema to the actual service, so we have to do it. | ||
*/ | ||
const bypass: any = Object.defineProperty, // typescript fix | ||
obj: any = {}; // placeholder | ||
bypass(obj, 'created', { | ||
value: function created() { | ||
for (let key in vars) { | ||
this[key] = vars[key]; | ||
} | ||
if (!_.isNil(Object.getOwnPropertyDescriptor(proto, 'created'))) { | ||
Object.getOwnPropertyDescriptor(proto, 'created').value.call(this); | ||
} | ||
}, | ||
writable: true, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
base['created'] = obj.created; | ||
} | ||
return; | ||
@@ -74,4 +102,8 @@ } | ||
if (key === 'created' || key === 'started' || key === 'stopped') { | ||
if (key === 'created' && !_options.constructOverride) { | ||
base[key] = descriptor.value; | ||
} | ||
if (key === 'started' || key === 'stopped') { | ||
base[key] = descriptor.value; | ||
return; | ||
@@ -78,0 +110,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
81926
369