@loopback/context
Advanced tools
Comparing version 4.0.0-alpha.22 to 4.0.0-alpha.23
@@ -6,2 +6,20 @@ # Change Log | ||
<a name="4.0.0-alpha.23"></a> | ||
# [4.0.0-alpha.23](https://github.com/strongloop/loopback-next/compare/@loopback/context@4.0.0-alpha.22...@loopback/context@4.0.0-alpha.23) (2017-12-15) | ||
### Bug Fixes | ||
* Improve test coverage for metadata inspector ([3b4b552](https://github.com/strongloop/loopback-next/commit/3b4b552)) | ||
### Features | ||
* **context:** Add decorator factories ([f517570](https://github.com/strongloop/loopback-next/commit/f517570)) | ||
* Add metadata inspector ([c683019](https://github.com/strongloop/loopback-next/commit/c683019)) | ||
* Use decorator factories ([88ebd21](https://github.com/strongloop/loopback-next/commit/88ebd21)) | ||
<a name="4.0.0-alpha.22"></a> | ||
@@ -8,0 +26,0 @@ # [4.0.0-alpha.22](https://github.com/strongloop/loopback-next/compare/@loopback/context@4.0.0-alpha.21...@loopback/context@4.0.0-alpha.22) (2017-12-11) |
@@ -5,3 +5,2 @@ export { Binding, BindingScope, BindingType, BoundValue, ValueOrPromise } from './binding'; | ||
export { inject, Setter, Getter } from './inject'; | ||
export { NamespacedReflect } from './reflect'; | ||
export { Provider } from './provider'; | ||
@@ -11,2 +10,2 @@ export { isPromise } from './is-promise'; | ||
export { describeInjectedArguments, describeInjectedProperties, Injection } from './inject'; | ||
export { Reflector } from './reflect'; | ||
export * from '@loopback/metadata'; |
@@ -6,2 +6,5 @@ "use strict"; | ||
// License text available at https://opensource.org/licenses/MIT | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -16,4 +19,2 @@ var binding_1 = require("./binding"); | ||
exports.inject = inject_1.inject; | ||
var reflect_1 = require("./reflect"); | ||
exports.NamespacedReflect = reflect_1.NamespacedReflect; | ||
var is_promise_1 = require("./is-promise"); | ||
@@ -28,4 +29,3 @@ exports.isPromise = is_promise_1.isPromise; | ||
exports.describeInjectedProperties = inject_2.describeInjectedProperties; | ||
var reflect_2 = require("./reflect"); | ||
exports.Reflector = reflect_2.Reflector; | ||
__export(require("@loopback/metadata")); | ||
//# sourceMappingURL=index.js.map |
@@ -0,1 +1,2 @@ | ||
import { MetadataMap } from '@loopback/metadata'; | ||
import { BoundValue, ValueOrPromise } from './binding'; | ||
@@ -45,3 +46,3 @@ import { Context } from './context'; | ||
*/ | ||
export declare function inject(bindingKey: string, metadata?: Object, resolve?: ResolverFunction): (target: any, propertyKey?: string | symbol | undefined, propertyDescriptorOrParameterIndex?: number | TypedPropertyDescriptor<any> | undefined) => void; | ||
export declare function inject(bindingKey: string, metadata?: Object, resolve?: ResolverFunction): (target: any, propertyKey: string | symbol, methodDescriptorOrParameterIndex?: number | TypedPropertyDescriptor<any> | undefined) => void; | ||
/** | ||
@@ -69,3 +70,3 @@ * The function injected by `@inject.getter(key)`. | ||
*/ | ||
const getter: (bindingKey: string, metadata?: Object | undefined) => (target: any, propertyKey?: string | symbol | undefined, propertyDescriptorOrParameterIndex?: number | TypedPropertyDescriptor<any> | undefined) => void; | ||
const getter: (bindingKey: string, metadata?: Object | undefined) => (target: any, propertyKey: string | symbol, methodDescriptorOrParameterIndex?: number | TypedPropertyDescriptor<any> | undefined) => void; | ||
/** | ||
@@ -84,3 +85,3 @@ * Inject a function for setting (binding) the given key to a given | ||
*/ | ||
const setter: (bindingKey: string, metadata?: Object | undefined) => (target: any, propertyKey?: string | symbol | undefined, propertyDescriptorOrParameterIndex?: number | TypedPropertyDescriptor<any> | undefined) => void; | ||
const setter: (bindingKey: string, metadata?: Object | undefined) => (target: any, propertyKey: string | symbol, methodDescriptorOrParameterIndex?: number | TypedPropertyDescriptor<any> | undefined) => void; | ||
} | ||
@@ -99,4 +100,2 @@ /** | ||
*/ | ||
export declare function describeInjectedProperties(target: any): { | ||
[p: string]: Injection; | ||
}; | ||
export declare function describeInjectedProperties(target: any): MetadataMap<Injection>; |
@@ -7,3 +7,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const reflect_1 = require("./reflect"); | ||
const metadata_1 = require("@loopback/metadata"); | ||
const PARAMETERS_KEY = 'inject:parameters'; | ||
@@ -40,15 +40,15 @@ const PROPERTIES_KEY = 'inject:properties'; | ||
// tslint:disable-next-line:no-any | ||
target, propertyKey, propertyDescriptorOrParameterIndex) { | ||
if (typeof propertyDescriptorOrParameterIndex === 'number') { | ||
target, propertyKey, methodDescriptorOrParameterIndex) { | ||
if (typeof methodDescriptorOrParameterIndex === 'number') { | ||
// The decorator is applied to a method parameter | ||
// Please note propertyKey is `undefined` for constructor | ||
const injectedArgs = reflect_1.Reflector.getOwnMetadata(PARAMETERS_KEY, target, propertyKey) || []; | ||
injectedArgs[propertyDescriptorOrParameterIndex] = { | ||
const paramDecorator = metadata_1.ParameterDecoratorFactory.createDecorator(PARAMETERS_KEY, { | ||
bindingKey, | ||
metadata, | ||
resolve, | ||
}; | ||
reflect_1.Reflector.defineMetadata(PARAMETERS_KEY, injectedArgs, target, propertyKey); | ||
}); | ||
paramDecorator(target, propertyKey, methodDescriptorOrParameterIndex); | ||
} | ||
else if (propertyKey) { | ||
// Property or method | ||
if (typeof Object.getPrototypeOf(target) === 'function') { | ||
@@ -58,9 +58,17 @@ const prop = target.name + '.' + propertyKey.toString(); | ||
} | ||
// The decorator is applied to a property | ||
const injections = reflect_1.Reflector.getOwnMetadata(PROPERTIES_KEY, target) || {}; | ||
injections[propertyKey] = { bindingKey, metadata, resolve }; | ||
reflect_1.Reflector.defineMetadata(PROPERTIES_KEY, injections, target); | ||
if (methodDescriptorOrParameterIndex) { | ||
// Method | ||
throw new Error('@inject cannot be used on a method: ' + propertyKey.toString()); | ||
} | ||
const propDecorator = metadata_1.PropertyDecoratorFactory.createDecorator(PROPERTIES_KEY, { | ||
bindingKey, | ||
metadata, | ||
resolve, | ||
}); | ||
propDecorator(target, propertyKey); | ||
} | ||
else { | ||
throw new Error('@inject can only be used on properties or method parameters.'); | ||
// It won't happen here as `@inject` is not compatible with ClassDecorator | ||
/* istanbul ignore next */ | ||
throw new Error('@inject can only be used on a property or a method parameter'); | ||
} | ||
@@ -123,8 +131,5 @@ }; | ||
target, method) { | ||
if (method) { | ||
return reflect_1.Reflector.getMetadata(PARAMETERS_KEY, target, method) || []; | ||
} | ||
else { | ||
return reflect_1.Reflector.getMetadata(PARAMETERS_KEY, target) || []; | ||
} | ||
method = method || ''; | ||
const meta = metadata_1.MetadataInspector.getAllParameterMetadata(PARAMETERS_KEY, target, method); | ||
return meta || []; | ||
} | ||
@@ -140,19 +145,3 @@ exports.describeInjectedArguments = describeInjectedArguments; | ||
target) { | ||
const metadata = {}; | ||
let obj = target; | ||
while (true) { | ||
const m = reflect_1.Reflector.getOwnMetadata(PROPERTIES_KEY, obj); | ||
if (m) { | ||
// Adding non-existent properties | ||
for (const p in m) { | ||
if (!(p in metadata)) { | ||
metadata[p] = m[p]; | ||
} | ||
} | ||
} | ||
// Recurse into the prototype chain | ||
obj = Object.getPrototypeOf(obj); | ||
if (!obj) | ||
break; | ||
} | ||
const metadata = metadata_1.MetadataInspector.getAllPropertyMetadata(PROPERTIES_KEY, target) || {}; | ||
return metadata; | ||
@@ -159,0 +148,0 @@ } |
@@ -5,3 +5,2 @@ export { Binding, BindingScope, BindingType, BoundValue, ValueOrPromise } from './binding'; | ||
export { inject, Setter, Getter } from './inject'; | ||
export { NamespacedReflect } from './reflect'; | ||
export { Provider } from './provider'; | ||
@@ -11,2 +10,2 @@ export { isPromise } from './is-promise'; | ||
export { describeInjectedArguments, describeInjectedProperties, Injection } from './inject'; | ||
export { Reflector } from './reflect'; | ||
export * from '@loopback/metadata'; |
@@ -6,2 +6,5 @@ "use strict"; | ||
// License text available at https://opensource.org/licenses/MIT | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -16,4 +19,2 @@ var binding_1 = require("./binding"); | ||
exports.inject = inject_1.inject; | ||
var reflect_1 = require("./reflect"); | ||
exports.NamespacedReflect = reflect_1.NamespacedReflect; | ||
var is_promise_1 = require("./is-promise"); | ||
@@ -28,4 +29,3 @@ exports.isPromise = is_promise_1.isPromise; | ||
exports.describeInjectedProperties = inject_2.describeInjectedProperties; | ||
var reflect_2 = require("./reflect"); | ||
exports.Reflector = reflect_2.Reflector; | ||
__export(require("@loopback/metadata")); | ||
//# sourceMappingURL=index.js.map |
@@ -0,1 +1,2 @@ | ||
import { MetadataMap } from '@loopback/metadata'; | ||
import { BoundValue, ValueOrPromise } from './binding'; | ||
@@ -45,3 +46,3 @@ import { Context } from './context'; | ||
*/ | ||
export declare function inject(bindingKey: string, metadata?: Object, resolve?: ResolverFunction): (target: any, propertyKey?: string | symbol | undefined, propertyDescriptorOrParameterIndex?: number | TypedPropertyDescriptor<any> | undefined) => void; | ||
export declare function inject(bindingKey: string, metadata?: Object, resolve?: ResolverFunction): (target: any, propertyKey: string | symbol, methodDescriptorOrParameterIndex?: number | TypedPropertyDescriptor<any> | undefined) => void; | ||
/** | ||
@@ -69,3 +70,3 @@ * The function injected by `@inject.getter(key)`. | ||
*/ | ||
const getter: (bindingKey: string, metadata?: Object | undefined) => (target: any, propertyKey?: string | symbol | undefined, propertyDescriptorOrParameterIndex?: number | TypedPropertyDescriptor<any> | undefined) => void; | ||
const getter: (bindingKey: string, metadata?: Object | undefined) => (target: any, propertyKey: string | symbol, methodDescriptorOrParameterIndex?: number | TypedPropertyDescriptor<any> | undefined) => void; | ||
/** | ||
@@ -84,3 +85,3 @@ * Inject a function for setting (binding) the given key to a given | ||
*/ | ||
const setter: (bindingKey: string, metadata?: Object | undefined) => (target: any, propertyKey?: string | symbol | undefined, propertyDescriptorOrParameterIndex?: number | TypedPropertyDescriptor<any> | undefined) => void; | ||
const setter: (bindingKey: string, metadata?: Object | undefined) => (target: any, propertyKey: string | symbol, methodDescriptorOrParameterIndex?: number | TypedPropertyDescriptor<any> | undefined) => void; | ||
} | ||
@@ -99,4 +100,2 @@ /** | ||
*/ | ||
export declare function describeInjectedProperties(target: any): { | ||
[p: string]: Injection; | ||
}; | ||
export declare function describeInjectedProperties(target: any): MetadataMap<Injection>; |
@@ -7,3 +7,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const reflect_1 = require("./reflect"); | ||
const metadata_1 = require("@loopback/metadata"); | ||
const PARAMETERS_KEY = 'inject:parameters'; | ||
@@ -40,15 +40,15 @@ const PROPERTIES_KEY = 'inject:properties'; | ||
// tslint:disable-next-line:no-any | ||
target, propertyKey, propertyDescriptorOrParameterIndex) { | ||
if (typeof propertyDescriptorOrParameterIndex === 'number') { | ||
target, propertyKey, methodDescriptorOrParameterIndex) { | ||
if (typeof methodDescriptorOrParameterIndex === 'number') { | ||
// The decorator is applied to a method parameter | ||
// Please note propertyKey is `undefined` for constructor | ||
const injectedArgs = reflect_1.Reflector.getOwnMetadata(PARAMETERS_KEY, target, propertyKey) || []; | ||
injectedArgs[propertyDescriptorOrParameterIndex] = { | ||
const paramDecorator = metadata_1.ParameterDecoratorFactory.createDecorator(PARAMETERS_KEY, { | ||
bindingKey, | ||
metadata, | ||
resolve, | ||
}; | ||
reflect_1.Reflector.defineMetadata(PARAMETERS_KEY, injectedArgs, target, propertyKey); | ||
}); | ||
paramDecorator(target, propertyKey, methodDescriptorOrParameterIndex); | ||
} | ||
else if (propertyKey) { | ||
// Property or method | ||
if (typeof Object.getPrototypeOf(target) === 'function') { | ||
@@ -58,9 +58,17 @@ const prop = target.name + '.' + propertyKey.toString(); | ||
} | ||
// The decorator is applied to a property | ||
const injections = reflect_1.Reflector.getOwnMetadata(PROPERTIES_KEY, target) || {}; | ||
injections[propertyKey] = { bindingKey, metadata, resolve }; | ||
reflect_1.Reflector.defineMetadata(PROPERTIES_KEY, injections, target); | ||
if (methodDescriptorOrParameterIndex) { | ||
// Method | ||
throw new Error('@inject cannot be used on a method: ' + propertyKey.toString()); | ||
} | ||
const propDecorator = metadata_1.PropertyDecoratorFactory.createDecorator(PROPERTIES_KEY, { | ||
bindingKey, | ||
metadata, | ||
resolve, | ||
}); | ||
propDecorator(target, propertyKey); | ||
} | ||
else { | ||
throw new Error('@inject can only be used on properties or method parameters.'); | ||
// It won't happen here as `@inject` is not compatible with ClassDecorator | ||
/* istanbul ignore next */ | ||
throw new Error('@inject can only be used on a property or a method parameter'); | ||
} | ||
@@ -123,8 +131,5 @@ }; | ||
target, method) { | ||
if (method) { | ||
return reflect_1.Reflector.getMetadata(PARAMETERS_KEY, target, method) || []; | ||
} | ||
else { | ||
return reflect_1.Reflector.getMetadata(PARAMETERS_KEY, target) || []; | ||
} | ||
method = method || ''; | ||
const meta = metadata_1.MetadataInspector.getAllParameterMetadata(PARAMETERS_KEY, target, method); | ||
return meta || []; | ||
} | ||
@@ -140,19 +145,3 @@ exports.describeInjectedArguments = describeInjectedArguments; | ||
target) { | ||
const metadata = {}; | ||
let obj = target; | ||
while (true) { | ||
const m = reflect_1.Reflector.getOwnMetadata(PROPERTIES_KEY, obj); | ||
if (m) { | ||
// Adding non-existent properties | ||
for (const p in m) { | ||
if (!(p in metadata)) { | ||
metadata[p] = m[p]; | ||
} | ||
} | ||
} | ||
// Recurse into the prototype chain | ||
obj = Object.getPrototypeOf(obj); | ||
if (!obj) | ||
break; | ||
} | ||
const metadata = metadata_1.MetadataInspector.getAllPropertyMetadata(PROPERTIES_KEY, target) || {}; | ||
return metadata; | ||
@@ -159,0 +148,0 @@ } |
{ | ||
"name": "@loopback/context", | ||
"version": "4.0.0-alpha.22", | ||
"version": "4.0.0-alpha.23", | ||
"description": "LoopBack's container for Inversion of Control", | ||
@@ -25,3 +25,3 @@ "engines": { | ||
"dependencies": { | ||
"reflect-metadata": "^0.1.10" | ||
"@loopback/metadata": "^4.0.0-alpha.2" | ||
}, | ||
@@ -28,0 +28,0 @@ "devDependencies": { |
@@ -17,3 +17,2 @@ // Copyright IBM Corp. 2017. All Rights Reserved. | ||
export {inject, Setter, Getter} from './inject'; | ||
export {NamespacedReflect} from './reflect'; | ||
export {Provider} from './provider'; | ||
@@ -29,2 +28,3 @@ export {isPromise} from './is-promise'; | ||
} from './inject'; | ||
export {Reflector} from './reflect'; | ||
export * from '@loopback/metadata'; |
@@ -6,3 +6,8 @@ // Copyright IBM Corp. 2013,2017. All Rights Reserved. | ||
import {Reflector} from './reflect'; | ||
import { | ||
MetadataInspector, | ||
ParameterDecoratorFactory, | ||
PropertyDecoratorFactory, | ||
MetadataMap, | ||
} from '@loopback/metadata'; | ||
import {BoundValue, ValueOrPromise} from './binding'; | ||
@@ -64,24 +69,21 @@ import {Context} from './context'; | ||
target: any, | ||
propertyKey?: string | symbol, | ||
propertyDescriptorOrParameterIndex?: | ||
propertyKey: string | symbol, | ||
methodDescriptorOrParameterIndex?: | ||
| TypedPropertyDescriptor<BoundValue> | ||
| number, | ||
) { | ||
if (typeof propertyDescriptorOrParameterIndex === 'number') { | ||
if (typeof methodDescriptorOrParameterIndex === 'number') { | ||
// The decorator is applied to a method parameter | ||
// Please note propertyKey is `undefined` for constructor | ||
const injectedArgs: Injection[] = | ||
Reflector.getOwnMetadata(PARAMETERS_KEY, target, propertyKey!) || []; | ||
injectedArgs[propertyDescriptorOrParameterIndex] = { | ||
bindingKey, | ||
metadata, | ||
resolve, | ||
}; | ||
Reflector.defineMetadata( | ||
const paramDecorator: ParameterDecorator = ParameterDecoratorFactory.createDecorator( | ||
PARAMETERS_KEY, | ||
injectedArgs, | ||
target, | ||
propertyKey!, | ||
{ | ||
bindingKey, | ||
metadata, | ||
resolve, | ||
}, | ||
); | ||
paramDecorator(target, propertyKey!, methodDescriptorOrParameterIndex); | ||
} else if (propertyKey) { | ||
// Property or method | ||
if (typeof Object.getPrototypeOf(target) === 'function') { | ||
@@ -93,10 +95,22 @@ const prop = target.name + '.' + propertyKey.toString(); | ||
} | ||
// The decorator is applied to a property | ||
const injections: {[p: string]: Injection} = | ||
Reflector.getOwnMetadata(PROPERTIES_KEY, target) || {}; | ||
injections[propertyKey] = {bindingKey, metadata, resolve}; | ||
Reflector.defineMetadata(PROPERTIES_KEY, injections, target); | ||
if (methodDescriptorOrParameterIndex) { | ||
// Method | ||
throw new Error( | ||
'@inject cannot be used on a method: ' + propertyKey.toString(), | ||
); | ||
} | ||
const propDecorator: PropertyDecorator = PropertyDecoratorFactory.createDecorator( | ||
PROPERTIES_KEY, | ||
{ | ||
bindingKey, | ||
metadata, | ||
resolve, | ||
}, | ||
); | ||
propDecorator(target, propertyKey!); | ||
} else { | ||
// It won't happen here as `@inject` is not compatible with ClassDecorator | ||
/* istanbul ignore next */ | ||
throw new Error( | ||
'@inject can only be used on properties or method parameters.', | ||
'@inject can only be used on a property or a method parameter', | ||
); | ||
@@ -182,7 +196,9 @@ } | ||
): Injection[] { | ||
if (method) { | ||
return Reflector.getMetadata(PARAMETERS_KEY, target, method) || []; | ||
} else { | ||
return Reflector.getMetadata(PARAMETERS_KEY, target) || []; | ||
} | ||
method = method || ''; | ||
const meta = MetadataInspector.getAllParameterMetadata<Injection>( | ||
PARAMETERS_KEY, | ||
target, | ||
method, | ||
); | ||
return meta || []; | ||
} | ||
@@ -198,20 +214,9 @@ | ||
target: any, | ||
): {[p: string]: Injection} { | ||
const metadata: {[name: string]: Injection} = {}; | ||
let obj = target; | ||
while (true) { | ||
const m = Reflector.getOwnMetadata(PROPERTIES_KEY, obj); | ||
if (m) { | ||
// Adding non-existent properties | ||
for (const p in m) { | ||
if (!(p in metadata)) { | ||
metadata[p] = m[p]; | ||
} | ||
} | ||
} | ||
// Recurse into the prototype chain | ||
obj = Object.getPrototypeOf(obj); | ||
if (!obj) break; | ||
} | ||
): MetadataMap<Injection> { | ||
const metadata = | ||
MetadataInspector.getAllPropertyMetadata<Injection>( | ||
PROPERTIES_KEY, | ||
target, | ||
) || {}; | ||
return metadata; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
678779
107
7492
+ Added@loopback/metadata@4.1.2(transitive)
+ Addeddebug@4.3.7(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedms@2.1.3(transitive)
+ Addedtslib@2.7.0(transitive)
- Removedreflect-metadata@^0.1.10