@loopback/core
Advanced tools
Comparing version 2.17.0 to 2.18.0
@@ -10,4 +10,4 @@ "use strict"; | ||
const context_1 = require("@loopback/context"); | ||
const assert_1 = tslib_1.__importDefault(require("assert")); | ||
const debug_1 = tslib_1.__importDefault(require("debug")); | ||
const assert_1 = (0, tslib_1.__importDefault)(require("assert")); | ||
const debug_1 = (0, tslib_1.__importDefault)(require("debug")); | ||
const events_1 = require("events"); | ||
@@ -19,5 +19,5 @@ const component_1 = require("./component"); | ||
const service_1 = require("./service"); | ||
const debug = debug_1.default('loopback:core:application'); | ||
const debugShutdown = debug_1.default('loopback:core:application:shutdown'); | ||
const debugWarning = debug_1.default('loopback:core:application:warning'); | ||
const debug = (0, debug_1.default)('loopback:core:application'); | ||
const debugShutdown = (0, debug_1.default)('loopback:core:application:shutdown'); | ||
const debugWarning = (0, debug_1.default)('loopback:core:application:warning'); | ||
/** | ||
@@ -117,3 +117,3 @@ * A helper function to build constructor args for `Context` | ||
this.debug('Adding controller %s', nameOrOptions !== null && nameOrOptions !== void 0 ? nameOrOptions : controllerCtor.name); | ||
const binding = context_1.createBindingFromClass(controllerCtor, { | ||
const binding = (0, context_1.createBindingFromClass)(controllerCtor, { | ||
namespace: keys_1.CoreBindings.CONTROLLERS, | ||
@@ -147,3 +147,3 @@ type: keys_1.CoreTags.CONTROLLER, | ||
this.debug('Adding server %s', nameOrOptions !== null && nameOrOptions !== void 0 ? nameOrOptions : ctor.name); | ||
const binding = context_1.createBindingFromClass(ctor, { | ||
const binding = (0, context_1.createBindingFromClass)(ctor, { | ||
namespace: keys_1.CoreBindings.SERVERS, | ||
@@ -210,3 +210,3 @@ type: keys_1.CoreTags.SERVER, | ||
assertNotInProcess(op) { | ||
assert_1.default(!this._state.endsWith('ing'), `Cannot ${op} the application as it is ${this._state}.`); | ||
(0, assert_1.default)(!this._state.endsWith('ing'), `Cannot ${op} the application as it is ${this._state}.`); | ||
} | ||
@@ -219,3 +219,3 @@ /** | ||
assertInStates(op, ...states) { | ||
assert_1.default(states.includes(this._state), `Cannot ${op} the application as it is ${this._state}. Valid states are ${states}.`); | ||
(0, assert_1.default)(states.includes(this._state), `Cannot ${op} the application as it is ${this._state}. Valid states are ${states}.`); | ||
} | ||
@@ -235,3 +235,3 @@ /** | ||
async awaitState(state) { | ||
await events_1.once(this, state); | ||
await (0, events_1.once)(this, state); | ||
} | ||
@@ -273,3 +273,3 @@ /** | ||
fn.name || '<onInit>', | ||
context_1.generateUniqueId(), | ||
(0, context_1.generateUniqueId)(), | ||
].join('.'); | ||
@@ -319,3 +319,3 @@ return this.bind(key) | ||
fn.name || '<onStart>', | ||
context_1.generateUniqueId(), | ||
(0, context_1.generateUniqueId)(), | ||
].join('.'); | ||
@@ -364,3 +364,3 @@ return this.bind(key) | ||
fn.name || '<onStop>', | ||
context_1.generateUniqueId(), | ||
(0, context_1.generateUniqueId)(), | ||
].join('.'); | ||
@@ -399,3 +399,3 @@ return this.bind(key) | ||
this.debug('Adding component: %s', nameOrOptions !== null && nameOrOptions !== void 0 ? nameOrOptions : componentCtor.name); | ||
const binding = context_1.createBindingFromClass(componentCtor, { | ||
const binding = (0, context_1.createBindingFromClass)(componentCtor, { | ||
namespace: keys_1.CoreBindings.COMPONENTS, | ||
@@ -406,3 +406,3 @@ type: keys_1.CoreTags.COMPONENT, | ||
}); | ||
if (lifecycle_1.isLifeCycleObserverClass(componentCtor)) { | ||
if ((0, lifecycle_1.isLifeCycleObserverClass)(componentCtor)) { | ||
binding.apply(lifecycle_1.asLifeCycleObserver); | ||
@@ -413,3 +413,3 @@ } | ||
const instance = this.getSync(binding.key); | ||
component_1.mountComponent(this, instance); | ||
(0, component_1.mountComponent)(this, instance); | ||
return binding; | ||
@@ -433,3 +433,3 @@ } | ||
this.debug('Adding life cycle observer %s', nameOrOptions !== null && nameOrOptions !== void 0 ? nameOrOptions : ctor.name); | ||
const binding = context_1.createBindingFromClass(ctor, { | ||
const binding = (0, context_1.createBindingFromClass)(ctor, { | ||
namespace: keys_1.CoreBindings.LIFE_CYCLE_OBSERVERS, | ||
@@ -487,3 +487,3 @@ type: keys_1.CoreTags.LIFE_CYCLE_OBSERVER, | ||
const options = toOptions(nameOrOptions); | ||
const binding = service_1.createServiceBinding(cls, options); | ||
const binding = (0, service_1.createServiceBinding)(cls, options); | ||
this.add(binding); | ||
@@ -499,3 +499,3 @@ return binding; | ||
const options = toOptions(nameOrOptions); | ||
return context_1.registerInterceptor(this, interceptor, options); | ||
return (0, context_1.registerInterceptor)(this, interceptor, options); | ||
} | ||
@@ -502,0 +502,0 @@ /** |
@@ -18,3 +18,3 @@ "use strict"; | ||
for (const classKey in component.classes) { | ||
const binding = context_1.createBindingFromClass(component.classes[classKey], { | ||
const binding = (0, context_1.createBindingFromClass)(component.classes[classKey], { | ||
key: classKey, | ||
@@ -27,3 +27,3 @@ }); | ||
for (const providerKey in component.providers) { | ||
const binding = context_1.createBindingFromClass(component.providers[providerKey], { | ||
const binding = (0, context_1.createBindingFromClass)(component.providers[providerKey], { | ||
key: providerKey, | ||
@@ -30,0 +30,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
import { Binding, BindingFilter, BindingFromClassOptions, BindingSpec, BindingTemplate, Constructor, Context } from '@loopback/context'; | ||
import { Binding, BindingFilter, BindingFromClassOptions, BindingSpec, BindingTemplate, Constructor, Context, InjectionMetadata } from '@loopback/context'; | ||
/** | ||
@@ -43,4 +43,5 @@ * Decorate a class as a named extension point. If the decoration is not | ||
* extensions. | ||
* @param metadata - Optional injection metadata | ||
*/ | ||
export declare function extensions(extensionPointName?: string): (target: Object, member: string | undefined, methodDescriptorOrParameterIndex?: number | TypedPropertyDescriptor<any> | undefined) => void; | ||
export declare function extensions(extensionPointName?: string, metadata?: InjectionMetadata): (target: Object, member: string | undefined, methodDescriptorOrParameterIndex?: number | TypedPropertyDescriptor<any> | undefined) => void; | ||
export declare namespace extensions { | ||
@@ -71,4 +72,5 @@ /** | ||
* extensions. | ||
* @param metadata - Optional injection metadata | ||
*/ | ||
function view(extensionPointName?: string): (target: Object, member: string | undefined, methodDescriptorOrParameterIndex?: number | TypedPropertyDescriptor<any> | undefined) => void; | ||
function view(extensionPointName?: string, metadata?: InjectionMetadata): (target: Object, member: string | undefined, methodDescriptorOrParameterIndex?: number | TypedPropertyDescriptor<any> | undefined) => void; | ||
/** | ||
@@ -98,4 +100,5 @@ * Inject an array of resolved extension instances for the extension point. | ||
* extensions. | ||
* @param metadata - Optional injection metadata | ||
*/ | ||
function list(extensionPointName?: string): (target: Object, member: string | undefined, methodDescriptorOrParameterIndex?: number | TypedPropertyDescriptor<any> | undefined) => void; | ||
function list(extensionPointName?: string, metadata?: InjectionMetadata): (target: Object, member: string | undefined, methodDescriptorOrParameterIndex?: number | TypedPropertyDescriptor<any> | undefined) => void; | ||
} | ||
@@ -102,0 +105,0 @@ /** |
@@ -27,3 +27,3 @@ "use strict"; | ||
function extensionPoint(name, ...specs) { | ||
return context_1.injectable({ tags: { [keys_1.CoreTags.EXTENSION_POINT]: name } }, ...specs); | ||
return (0, context_1.injectable)({ tags: { [keys_1.CoreTags.EXTENSION_POINT]: name } }, ...specs); | ||
} | ||
@@ -55,8 +55,9 @@ exports.extensionPoint = extensionPoint; | ||
* extensions. | ||
* @param metadata - Optional injection metadata | ||
*/ | ||
function extensions(extensionPointName) { | ||
return context_1.inject('', { decorator: '@extensions' }, (ctx, injection, session) => { | ||
context_1.assertTargetType(injection, Function, 'Getter function'); | ||
function extensions(extensionPointName, metadata) { | ||
return (0, context_1.inject)('', { ...metadata, decorator: '@extensions' }, (ctx, injection, session) => { | ||
(0, context_1.assertTargetType)(injection, Function, 'Getter function'); | ||
const bindingFilter = filterByExtensionPoint(injection, session, extensionPointName); | ||
return context_1.createViewGetter(ctx, bindingFilter, injection.metadata.bindingComparator, session); | ||
return (0, context_1.createViewGetter)(ctx, bindingFilter, injection.metadata.bindingComparator, { ...metadata, ...(0, context_1.asResolutionOptions)(session) }); | ||
}); | ||
@@ -90,8 +91,9 @@ } | ||
* extensions. | ||
* @param metadata - Optional injection metadata | ||
*/ | ||
function view(extensionPointName) { | ||
return context_1.inject('', { decorator: '@extensions.view' }, (ctx, injection, session) => { | ||
context_1.assertTargetType(injection, context_1.ContextView); | ||
function view(extensionPointName, metadata) { | ||
return (0, context_1.inject)('', { ...metadata, decorator: '@extensions.view' }, (ctx, injection, session) => { | ||
(0, context_1.assertTargetType)(injection, context_1.ContextView); | ||
const bindingFilter = filterByExtensionPoint(injection, session, extensionPointName); | ||
return ctx.createView(bindingFilter, injection.metadata.bindingComparator); | ||
return ctx.createView(bindingFilter, injection.metadata.bindingComparator, metadata); | ||
}); | ||
@@ -124,9 +126,13 @@ } | ||
* extensions. | ||
* @param metadata - Optional injection metadata | ||
*/ | ||
function list(extensionPointName) { | ||
return context_1.inject('', { decorator: '@extensions.instances' }, (ctx, injection, session) => { | ||
context_1.assertTargetType(injection, Array); | ||
function list(extensionPointName, metadata) { | ||
return (0, context_1.inject)('', { ...metadata, decorator: '@extensions.instances' }, (ctx, injection, session) => { | ||
(0, context_1.assertTargetType)(injection, Array); | ||
const bindingFilter = filterByExtensionPoint(injection, session, extensionPointName); | ||
const viewForExtensions = new context_1.ContextView(ctx, bindingFilter, injection.metadata.bindingComparator); | ||
return viewForExtensions.resolve(session); | ||
return viewForExtensions.resolve({ | ||
...metadata, | ||
...(0, context_1.asResolutionOptions)(session), | ||
}); | ||
}); | ||
@@ -176,4 +182,4 @@ } | ||
function extensionFilter(...extensionPointNames) { | ||
return context_1.filterByTag({ | ||
[keys_1.CoreTags.EXTENSION_FOR]: context_1.includesTagValue(...extensionPointNames), | ||
return (0, context_1.filterByTag)({ | ||
[keys_1.CoreTags.EXTENSION_FOR]: (0, context_1.includesTagValue)(...extensionPointNames), | ||
}); | ||
@@ -221,3 +227,3 @@ } | ||
function addExtension(context, extensionPointName, extensionClass, options) { | ||
const binding = context_1.createBindingFromClass(extensionClass, options).apply(extensionFor(extensionPointName)); | ||
const binding = (0, context_1.createBindingFromClass)(extensionClass, options).apply(extensionFor(extensionPointName)); | ||
context.add(binding); | ||
@@ -224,0 +230,0 @@ return binding; |
@@ -20,13 +20,13 @@ "use strict"; | ||
// Re-export public Core API coming from dependencies | ||
tslib_1.__exportStar(require("@loopback/context"), exports); | ||
(0, tslib_1.__exportStar)(require("@loopback/context"), exports); | ||
// Export APIs | ||
tslib_1.__exportStar(require("./application"), exports); | ||
tslib_1.__exportStar(require("./component"), exports); | ||
tslib_1.__exportStar(require("./extension-point"), exports); | ||
tslib_1.__exportStar(require("./keys"), exports); | ||
tslib_1.__exportStar(require("./lifecycle"), exports); | ||
tslib_1.__exportStar(require("./lifecycle-registry"), exports); | ||
tslib_1.__exportStar(require("./mixin-target"), exports); | ||
tslib_1.__exportStar(require("./server"), exports); | ||
tslib_1.__exportStar(require("./service"), exports); | ||
(0, tslib_1.__exportStar)(require("./application"), exports); | ||
(0, tslib_1.__exportStar)(require("./component"), exports); | ||
(0, tslib_1.__exportStar)(require("./extension-point"), exports); | ||
(0, tslib_1.__exportStar)(require("./keys"), exports); | ||
(0, tslib_1.__exportStar)(require("./lifecycle"), exports); | ||
(0, tslib_1.__exportStar)(require("./lifecycle-registry"), exports); | ||
(0, tslib_1.__exportStar)(require("./mixin-target"), exports); | ||
(0, tslib_1.__exportStar)(require("./server"), exports); | ||
(0, tslib_1.__exportStar)(require("./service"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -68,3 +68,3 @@ "use strict"; | ||
const groupMap = new Map(); | ||
context_1.sortBindingsByPhase(bindings, keys_1.CoreTags.LIFE_CYCLE_OBSERVER_GROUP, this.options.orderedGroups); | ||
(0, context_1.sortBindingsByPhase)(bindings, keys_1.CoreTags.LIFE_CYCLE_OBSERVER_GROUP, this.options.orderedGroups); | ||
for (const binding of bindings) { | ||
@@ -117,3 +117,3 @@ const group = this.getObserverGroup(binding); | ||
// DataSource.stop() | ||
await context_1.invokeMethod(observer, event, this.context, [undefined], { | ||
await (0, context_1.invokeMethod)(observer, event, this.context, [undefined], { | ||
skipInterceptors: true, | ||
@@ -185,7 +185,7 @@ }); | ||
}; | ||
LifeCycleObserverRegistry = tslib_1.__decorate([ | ||
tslib_1.__param(0, context_1.inject.context()), | ||
tslib_1.__param(1, context_1.inject.view(lifecycle_1.lifeCycleObserverFilter)), | ||
tslib_1.__param(2, context_1.inject(keys_1.CoreBindings.LIFE_CYCLE_OBSERVER_OPTIONS, { optional: true })), | ||
tslib_1.__metadata("design:paramtypes", [context_1.Context, | ||
LifeCycleObserverRegistry = (0, tslib_1.__decorate)([ | ||
(0, tslib_1.__param)(0, context_1.inject.context()), | ||
(0, tslib_1.__param)(1, context_1.inject.view(lifecycle_1.lifeCycleObserverFilter)), | ||
(0, tslib_1.__param)(2, (0, context_1.inject)(keys_1.CoreBindings.LIFE_CYCLE_OBSERVER_OPTIONS, { optional: true })), | ||
(0, tslib_1.__metadata)("design:paramtypes", [context_1.Context, | ||
context_1.ContextView, Object]) | ||
@@ -192,0 +192,0 @@ ], LifeCycleObserverRegistry); |
@@ -42,3 +42,3 @@ "use strict"; | ||
*/ | ||
exports.lifeCycleObserverFilter = context_1.filterByTag(keys_1.CoreTags.LIFE_CYCLE_OBSERVER); | ||
exports.lifeCycleObserverFilter = (0, context_1.filterByTag)(keys_1.CoreTags.LIFE_CYCLE_OBSERVER); | ||
/** | ||
@@ -50,3 +50,3 @@ * Sugar decorator to mark a class as life cycle observer | ||
function lifeCycleObserver(group = '', ...specs) { | ||
return context_1.injectable(asLifeCycleObserver, { | ||
return (0, context_1.injectable)(asLifeCycleObserver, { | ||
tags: { | ||
@@ -53,0 +53,0 @@ [keys_1.CoreTags.LIFE_CYCLE_OBSERVER_GROUP]: group, |
@@ -42,3 +42,3 @@ "use strict"; | ||
function service(serviceInterface, metadata) { | ||
return context_1.inject('', { decorator: '@service', ...metadata }, (ctx, injection, session) => { | ||
return (0, context_1.inject)('', { decorator: '@service', ...metadata }, (ctx, injection, session) => { | ||
var _a; | ||
@@ -71,3 +71,3 @@ let serviceType = serviceInterface; | ||
: serviceType.name; | ||
return context_1.transformValueOrPromise(result, values => { | ||
return (0, context_1.transformValueOrPromise)(result, values => { | ||
if (values.length === 1) | ||
@@ -107,6 +107,6 @@ return values[0]; | ||
let name = options.name; | ||
if (!name && context_1.isProviderClass(cls)) { | ||
if (!name && (0, context_1.isProviderClass)(cls)) { | ||
// Trim `Provider` from the default service name | ||
// This is needed to keep backward compatibility | ||
const templateFn = context_1.bindingTemplateFor(cls); | ||
const templateFn = (0, context_1.bindingTemplateFor)(cls); | ||
const template = context_1.Binding.bind('template').apply(templateFn); | ||
@@ -119,5 +119,5 @@ if (template.tagMap[context_1.ContextTags.PROVIDER] && | ||
} | ||
if (!name && context_1.isDynamicValueProviderClass(cls)) { | ||
if (!name && (0, context_1.isDynamicValueProviderClass)(cls)) { | ||
// Trim `Provider` from the default service name | ||
const templateFn = context_1.bindingTemplateFor(cls); | ||
const templateFn = (0, context_1.bindingTemplateFor)(cls); | ||
const template = context_1.Binding.bind('template').apply(templateFn); | ||
@@ -130,3 +130,3 @@ if (template.tagMap[context_1.ContextTags.DYNAMIC_VALUE_PROVIDER] && | ||
} | ||
const binding = context_1.createBindingFromClass(cls, { | ||
const binding = (0, context_1.createBindingFromClass)(cls, { | ||
name, | ||
@@ -133,0 +133,0 @@ type: keys_1.CoreTags.SERVICE, |
{ | ||
"name": "@loopback/core", | ||
"description": "Define and implement core constructs such as Application and Component", | ||
"version": "2.17.0", | ||
"version": "2.18.0", | ||
"license": "MIT", | ||
@@ -38,3 +38,3 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@loopback/context": "^3.17.2", | ||
"@loopback/context": "^3.18.0", | ||
"debug": "^4.3.2", | ||
@@ -44,9 +44,9 @@ "tslib": "^2.3.1" | ||
"devDependencies": { | ||
"@loopback/build": "^7.0.1", | ||
"@loopback/eslint-config": "^11.0.1", | ||
"@loopback/testlab": "^3.4.3", | ||
"@loopback/build": "^7.0.2", | ||
"@loopback/eslint-config": "^11.0.2", | ||
"@loopback/testlab": "^3.4.4", | ||
"@types/debug": "^4.1.7", | ||
"@types/node": "^10.17.60" | ||
}, | ||
"gitHead": "1df36bb1ee2e513d9e197bd6010c4cfb296d50b8" | ||
"gitHead": "d9a29c85dbe38f12ba219d8c495cf6038bbc3590" | ||
} |
@@ -7,2 +7,3 @@ // Copyright IBM Corp. 2017,2020. All Rights Reserved. | ||
import { | ||
asResolutionOptions, | ||
assertTargetType, | ||
@@ -25,2 +26,3 @@ Binding, | ||
Injection, | ||
InjectionMetadata, | ||
ResolutionSession, | ||
@@ -74,18 +76,26 @@ } from '@loopback/context'; | ||
* extensions. | ||
* @param metadata - Optional injection metadata | ||
*/ | ||
export function extensions(extensionPointName?: string) { | ||
return inject('', {decorator: '@extensions'}, (ctx, injection, session) => { | ||
assertTargetType(injection, Function, 'Getter function'); | ||
const bindingFilter = filterByExtensionPoint( | ||
injection, | ||
session, | ||
extensionPointName, | ||
); | ||
return createViewGetter( | ||
ctx, | ||
bindingFilter, | ||
injection.metadata.bindingComparator, | ||
session, | ||
); | ||
}); | ||
export function extensions( | ||
extensionPointName?: string, | ||
metadata?: InjectionMetadata, | ||
) { | ||
return inject( | ||
'', | ||
{...metadata, decorator: '@extensions'}, | ||
(ctx, injection, session) => { | ||
assertTargetType(injection, Function, 'Getter function'); | ||
const bindingFilter = filterByExtensionPoint( | ||
injection, | ||
session, | ||
extensionPointName, | ||
); | ||
return createViewGetter( | ||
ctx, | ||
bindingFilter, | ||
injection.metadata.bindingComparator, | ||
{...metadata, ...asResolutionOptions(session)}, | ||
); | ||
}, | ||
); | ||
} | ||
@@ -118,7 +128,11 @@ | ||
* extensions. | ||
* @param metadata - Optional injection metadata | ||
*/ | ||
export function view(extensionPointName?: string) { | ||
export function view( | ||
extensionPointName?: string, | ||
metadata?: InjectionMetadata, | ||
) { | ||
return inject( | ||
'', | ||
{decorator: '@extensions.view'}, | ||
{...metadata, decorator: '@extensions.view'}, | ||
(ctx, injection, session) => { | ||
@@ -134,2 +148,3 @@ assertTargetType(injection, ContextView); | ||
injection.metadata.bindingComparator, | ||
metadata, | ||
); | ||
@@ -164,7 +179,11 @@ }, | ||
* extensions. | ||
* @param metadata - Optional injection metadata | ||
*/ | ||
export function list(extensionPointName?: string) { | ||
export function list( | ||
extensionPointName?: string, | ||
metadata?: InjectionMetadata, | ||
) { | ||
return inject( | ||
'', | ||
{decorator: '@extensions.instances'}, | ||
{...metadata, decorator: '@extensions.instances'}, | ||
(ctx, injection, session) => { | ||
@@ -182,3 +201,6 @@ assertTargetType(injection, Array); | ||
); | ||
return viewForExtensions.resolve(session); | ||
return viewForExtensions.resolve({ | ||
...metadata, | ||
...asResolutionOptions(session), | ||
}); | ||
}, | ||
@@ -185,0 +207,0 @@ ); |
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
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
179030
4189
Updated@loopback/context@^3.18.0