Socket
Socket
Sign inDemoInstall

@loopback/context

Package Overview
Dependencies
14
Maintainers
7
Versions
191
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.10.1 to 3.11.0

17

CHANGELOG.md

@@ -6,2 +6,19 @@ # Change Log

# [3.11.0](https://github.com/strongloop/loopback-next/compare/@loopback/context@3.10.1...@loopback/context@3.11.0) (2020-09-15)
### Bug Fixes
* improve handling of missing design-time type metadata ([95b6a2b](https://github.com/strongloop/loopback-next/commit/95b6a2b7ce64e614720df43b905f77a53a54e438))
### Features
* **context:** add `[@injectable](https://github.com/injectable)` as a preferred decorator for `[@bind](https://github.com/bind)` ([1f75c35](https://github.com/strongloop/loopback-next/commit/1f75c35937a4190564bdade48b0782c4364f6101))
* allow dynamic value provider classes and classes with [@inject](https://github.com/inject) to be booted ([7b85cdf](https://github.com/strongloop/loopback-next/commit/7b85cdf63730ef659a4ee799f05f02eea8a1e3e8))
## [3.10.1](https://github.com/strongloop/loopback-next/compare/@loopback/context@3.10.0...@loopback/context@3.10.1) (2020-08-27)

@@ -8,0 +25,0 @@

28

dist/binding-decorator.d.ts

@@ -8,4 +8,5 @@ import { BindingSpec } from './binding-inspector';

* ```ts
* @bind((binding) => {binding.inScope(BindingScope.SINGLETON).tag('controller')}
* @injectable((binding) => {binding.inScope(BindingScope.SINGLETON).tag('controller')}
* )
* @injectable({scope: BindingScope.SINGLETON})
* export class MyController {

@@ -18,6 +19,9 @@ * }

*/
export declare function bind(...specs: BindingSpec[]): ClassDecorator;
export declare namespace bind {
export declare function injectable(...specs: BindingSpec[]): ClassDecorator;
/**
* A namespace to host shortcuts for `@injectable`
*/
export declare namespace injectable {
/**
* `@bind.provider` to denote a provider class
* `@injectable.provider` to denote a provider class
*

@@ -28,1 +32,17 @@ * A list of binding scope/tags or template functions to configure the binding

}
/**
* `@bind` is now an alias to {@link injectable} for backward compatibility
* {@inheritDoc injectable}
*/
export declare function bind(...specs: BindingSpec[]): ClassDecorator;
/**
* Alias namespace `bind` to `injectable` for backward compatibility
*
* It should have the same members as `bind`.
*/
export declare namespace bind {
/**
* {@inheritDoc injectable.provider}
*/
const provider: typeof injectable.provider;
}

45

dist/binding-decorator.js

@@ -7,9 +7,9 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.bind = void 0;
exports.bind = exports.injectable = void 0;
const metadata_1 = require("@loopback/metadata");
const binding_inspector_1 = require("./binding-inspector");
/**
* Decorator factory for `@bind`
* Decorator factory for `@injectable`
*/
class BindDecoratorFactory extends metadata_1.ClassDecoratorFactory {
class InjectableDecoratorFactory extends metadata_1.ClassDecoratorFactory {
mergeWithInherited(inherited, target) {

@@ -47,4 +47,5 @@ if (inherited) {

* ```ts
* @bind((binding) => {binding.inScope(BindingScope.SINGLETON).tag('controller')}
* @injectable((binding) => {binding.inScope(BindingScope.SINGLETON).tag('controller')}
* )
* @injectable({scope: BindingScope.SINGLETON})
* export class MyController {

@@ -57,3 +58,3 @@ * }

*/
function bind(...specs) {
function injectable(...specs) {
const templateFunctions = specs.map(t => {

@@ -73,10 +74,13 @@ if (typeof t === 'function') {

};
const decorator = BindDecoratorFactory.createDecorator(binding_inspector_1.BINDING_METADATA_KEY, spec, { decoratorName: '@bind' });
const decorator = InjectableDecoratorFactory.createDecorator(binding_inspector_1.BINDING_METADATA_KEY, spec, { decoratorName: '@injectable' });
decorator(target);
};
}
exports.bind = bind;
(function (bind) {
exports.injectable = injectable;
/**
* A namespace to host shortcuts for `@injectable`
*/
(function (injectable) {
/**
* `@bind.provider` to denote a provider class
* `@injectable.provider` to denote a provider class
*

@@ -90,3 +94,3 @@ * A list of binding scope/tags or template functions to configure the binding

}
bind(
injectable(
// Set up the default for providers

@@ -98,4 +102,23 @@ binding_inspector_1.asProvider(target),

}
bind.provider = provider;
injectable.provider = provider;
})(injectable = exports.injectable || (exports.injectable = {}));
/**
* `@bind` is now an alias to {@link injectable} for backward compatibility
* {@inheritDoc injectable}
*/
function bind(...specs) {
return injectable(...specs);
}
exports.bind = bind;
/**
* Alias namespace `bind` to `injectable` for backward compatibility
*
* It should have the same members as `bind`.
*/
(function (bind) {
/**
* {@inheritDoc injectable.provider}
*/
bind.provider = injectable.provider;
})(bind = exports.bind || (exports.bind = {}));
//# sourceMappingURL=binding-decorator.js.map

@@ -7,3 +7,3 @@ import { MetadataAccessor } from '@loopback/metadata';

/**
* Binding metadata from `@bind`
* Binding metadata from `@injectable`
*

@@ -34,3 +34,3 @@ * @typeParam T - Value type

/**
* Specification of parameters for `@bind()`
* Specification of parameters for `@injectable()`
*/

@@ -83,3 +83,3 @@ export declare type BindingSpec<T = unknown> = BindingTemplate<T> | BindingScopeAndTags;

*
* @param cls - A class with optional `@bind`
* @param cls - A class with optional `@injectable`
*

@@ -142,6 +142,9 @@ * @typeParam T - Value type

* - `binding.toClass(cls)`: if `cls` is a plain class such as `MyController`
* - `binding.toProvider(cls)`: it `cls` is a value provider class with a
* - `binding.toProvider(cls)`: if `cls` is a value provider class with a
* prototype method `value()`
* - `binding.toDynamicValue(cls)`: if `cls` is a dynamic value provider class
* with a static method `value()`
*
* @param cls - A class. It can be either a plain class or a value provider class
* @param cls - A class. It can be either a plain class, a value provider class,
* or a dynamic value provider class
* @param options - Options to customize the binding key

@@ -148,0 +151,0 @@ *

@@ -114,3 +114,3 @@ "use strict";

*
* @param cls - A class with optional `@bind`
* @param cls - A class with optional `@injectable`
*

@@ -144,6 +144,9 @@ * @typeParam T - Value type

* - `binding.toClass(cls)`: if `cls` is a plain class such as `MyController`
* - `binding.toProvider(cls)`: it `cls` is a value provider class with a
* - `binding.toProvider(cls)`: if `cls` is a value provider class with a
* prototype method `value()`
* - `binding.toDynamicValue(cls)`: if `cls` is a dynamic value provider class
* with a static method `value()`
*
* @param cls - A class. It can be either a plain class or a value provider class
* @param cls - A class. It can be either a plain class, a value provider class,
* or a dynamic value provider class
* @param options - Options to customize the binding key

@@ -150,0 +153,0 @@ *

@@ -21,3 +21,3 @@ export declare type BindingAddress<T = unknown> = string | BindingKey<T>;

*/
static create<ValueType>(key: string, propertyPath?: string): BindingKey<ValueType>;
static create<V>(key: string, propertyPath?: string): BindingKey<V>;
private constructor();

@@ -24,0 +24,0 @@ toString(): string;

@@ -9,2 +9,3 @@ "use strict";

const unique_id_1 = require("./unique-id");
// eslint-disable-next-line @typescript-eslint/no-unused-vars
class BindingKey {

@@ -11,0 +12,0 @@ constructor(key, propertyPath) {

@@ -451,3 +451,3 @@ /// <reference types="node" />

*/
static bind<T = unknown>(key: BindingAddress<T>): Binding<T>;
static bind<V = unknown>(key: BindingAddress<V>): Binding<V>;
/**

@@ -462,3 +462,3 @@ * Create a configuration binding for the given key

*
* @typeParam T Generic type for the configuration value (not the binding to
* @typeParam V Generic type for the configuration value (not the binding to
* be configured)

@@ -468,3 +468,3 @@ *

*/
static configure<T = unknown>(key: BindingAddress): Binding<T>;
static configure<V = unknown>(key: BindingAddress): Binding<V>;
/**

@@ -471,0 +471,0 @@ * The "changed" event is emitted by methods such as `tag`, `inScope`, `to`,

@@ -630,3 +630,3 @@ "use strict";

*
* @typeParam T Generic type for the configuration value (not the binding to
* @typeParam V Generic type for the configuration value (not the binding to
* be configured)

@@ -633,0 +633,0 @@ *

@@ -116,3 +116,3 @@ /// <reference types="node" />

*/
on(eventName: 'bind', listener: <T>(event: ContextViewEvent<T>) => void): this;
on(eventName: 'bind', listener: <V>(event: ContextViewEvent<V>) => void): this;
/**

@@ -124,4 +124,4 @@ * The "unbind" event is emitted a new binding is removed from the view.

*/
on(eventName: 'unbind', listener: <T>(event: ContextViewEvent<T> & {
cachedValue?: T;
on(eventName: 'unbind', listener: <V>(event: ContextViewEvent<V> & {
cachedValue?: V;
}) => void): this;

@@ -143,3 +143,3 @@ /**

*/
on(eventName: 'refresh', listener: <T>(result: T[]) => void): this;
on(eventName: 'refresh', listener: <V>(result: V[]) => void): this;
/**

@@ -160,3 +160,3 @@ * The "close" event is emitted when the view is closed (stopped observing

*/
once(eventName: 'bind', listener: <T>(event: ContextViewEvent<T>) => void): this;
once(eventName: 'bind', listener: <V>(event: ContextViewEvent<V>) => void): this;
/**

@@ -168,4 +168,4 @@ * The "unbind" event is emitted a new binding is removed from the view.

*/
once(eventName: 'unbind', listener: <T>(event: ContextViewEvent<T> & {
cachedValue?: T;
once(eventName: 'unbind', listener: <V>(event: ContextViewEvent<V> & {
cachedValue?: V;
}) => void): this;

@@ -187,3 +187,3 @@ /**

*/
once(eventName: 'refresh', listener: <T>(result: T[]) => void): this;
once(eventName: 'refresh', listener: <V>(result: V[]) => void): this;
/**

@@ -190,0 +190,0 @@ * The "close" event is emitted when the view is closed (stopped observing

@@ -9,3 +9,3 @@ import { MetadataMap } from '@loopback/metadata';

import { ResolutionOptions, ResolutionSession } from './resolution-session';
import { BoundValue, ValueOrPromise } from './value-promise';
import { BoundValue, Constructor, ValueOrPromise } from './value-promise';
/**

@@ -233,3 +233,3 @@ * A function to provide resolution of injected values.

*/
export declare function inspectTargetType(injection: Readonly<Injection>): Function;
export declare function inspectTargetType(injection: Readonly<Injection>): Function | undefined;
/**

@@ -246,1 +246,8 @@ * Return a map of injection objects for properties

export declare function inspectInjections(binding: Readonly<Binding<unknown>>): JSONObject;
/**
* Check if the given class has `@inject` or other decorations that map to
* `@inject`.
*
* @param cls - Class with possible `@inject` decorations
*/
export declare function hasInjections(cls: Constructor<unknown>): boolean;

@@ -7,3 +7,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.inspectInjections = exports.describeInjectedProperties = exports.inspectTargetType = exports.describeInjectedArguments = exports.assertTargetType = exports.Getter = exports.inject = void 0;
exports.hasInjections = exports.inspectInjections = exports.describeInjectedProperties = exports.inspectTargetType = exports.describeInjectedArguments = exports.assertTargetType = exports.Getter = exports.inject = void 0;
const metadata_1 = require("@loopback/metadata");

@@ -14,6 +14,6 @@ const binding_1 = require("./binding");

const resolution_session_1 = require("./resolution-session");
const PARAMETERS_KEY = metadata_1.MetadataAccessor.create('inject:parameters');
const PROPERTIES_KEY = metadata_1.MetadataAccessor.create('inject:properties');
const INJECT_PARAMETERS_KEY = metadata_1.MetadataAccessor.create('inject:parameters');
const INJECT_PROPERTIES_KEY = metadata_1.MetadataAccessor.create('inject:properties');
// A key to cache described argument injections
const METHODS_KEY = metadata_1.MetadataAccessor.create('inject:methods');
const INJECT_METHODS_KEY = metadata_1.MetadataAccessor.create('inject:methods');
/**

@@ -61,3 +61,3 @@ * A decorator to annotate method arguments for automatic injection

// Please note propertyKey is `undefined` for constructor
const paramDecorator = metadata_1.ParameterDecoratorFactory.createDecorator(PARAMETERS_KEY, {
const paramDecorator = metadata_1.ParameterDecoratorFactory.createDecorator(INJECT_PARAMETERS_KEY, {
target,

@@ -86,3 +86,3 @@ member,

}
const propDecorator = metadata_1.PropertyDecoratorFactory.createDecorator(PROPERTIES_KEY, {
const propDecorator = metadata_1.PropertyDecoratorFactory.createDecorator(INJECT_PROPERTIES_KEY, {
target,

@@ -376,3 +376,3 @@ member,

// Try to read from cache
const cache = (_a = metadata_1.MetadataInspector.getAllMethodMetadata(METHODS_KEY, target, {
const cache = (_a = metadata_1.MetadataInspector.getAllMethodMetadata(INJECT_METHODS_KEY, target, {
ownMetadataOnly: true,

@@ -395,6 +395,6 @@ })) !== null && _a !== void 0 ? _a : {};

}
meta = (_b = metadata_1.MetadataInspector.getAllParameterMetadata(PARAMETERS_KEY, target, method, options)) !== null && _b !== void 0 ? _b : [];
meta = (_b = metadata_1.MetadataInspector.getAllParameterMetadata(INJECT_PARAMETERS_KEY, target, method, options)) !== null && _b !== void 0 ? _b : [];
// Cache the result
cache[method] = meta;
metadata_1.MetadataInspector.defineMetadata(METHODS_KEY, cache, target);
metadata_1.MetadataInspector.defineMetadata(INJECT_METHODS_KEY, cache, target);
return meta;

@@ -409,5 +409,6 @@ }

function inspectTargetType(injection) {
var _a;
if (typeof injection.methodDescriptorOrParameterIndex === 'number') {
const designType = metadata_1.MetadataInspector.getDesignTypeForMethod(injection.target, injection.member);
return designType.parameterTypes[injection.methodDescriptorOrParameterIndex];
return (_a = designType === null || designType === void 0 ? void 0 : designType.parameterTypes) === null || _a === void 0 ? void 0 : _a[injection.methodDescriptorOrParameterIndex];
}

@@ -462,3 +463,3 @@ return metadata_1.MetadataInspector.getDesignTypeForProperty(injection.target, injection.member);

var _a;
const metadata = (_a = metadata_1.MetadataInspector.getAllPropertyMetadata(PROPERTIES_KEY, target)) !== null && _a !== void 0 ? _a : {};
const metadata = (_a = metadata_1.MetadataInspector.getAllPropertyMetadata(INJECT_PROPERTIES_KEY, target)) !== null && _a !== void 0 ? _a : {};
return metadata;

@@ -527,2 +528,15 @@ }

}
/**
* Check if the given class has `@inject` or other decorations that map to
* `@inject`.
*
* @param cls - Class with possible `@inject` decorations
*/
function hasInjections(cls) {
return (metadata_1.MetadataInspector.getClassMetadata(INJECT_PARAMETERS_KEY, cls) != null ||
metadata_1.Reflector.getMetadata(INJECT_PARAMETERS_KEY.toString(), cls.prototype) !=
null ||
metadata_1.MetadataInspector.getAllPropertyMetadata(INJECT_PROPERTIES_KEY, cls.prototype) != null);
}
exports.hasInjections = hasInjections;
//# sourceMappingURL=inject.js.map

@@ -116,3 +116,3 @@ "use strict";

function globalInterceptor(group, ...specs) {
return binding_decorator_1.bind(asGlobalInterceptor(group), ...specs);
return binding_decorator_1.injectable(asGlobalInterceptor(group), ...specs);
}

@@ -119,0 +119,0 @@ exports.globalInterceptor = globalInterceptor;

@@ -56,3 +56,3 @@ /**

*/
export declare function resolveMap<T, V>(map: MapObject<T>, resolver: (val: T, key: string, map: MapObject<T>) => ValueOrPromise<V>): ValueOrPromise<MapObject<V>>;
export declare function resolveMap<T, V>(map: MapObject<T>, resolver: (val: T, key: string, values: MapObject<T>) => ValueOrPromise<V>): ValueOrPromise<MapObject<V>>;
/**

@@ -84,3 +84,3 @@ * Resolve entries of an array into a new array with the same indexes. If one or

*/
export declare function resolveList<T, V>(list: T[], resolver: (val: T, index: number, list: T[]) => ValueOrPromise<V>): ValueOrPromise<V[]>;
export declare function resolveList<T, V>(list: T[], resolver: (val: T, index: number, values: T[]) => ValueOrPromise<V>): ValueOrPromise<V[]>;
/**

@@ -127,4 +127,4 @@ * Try to run an action that returns a promise or a value

*
* @deprecated Use [uuid](https://www.npmjs.com/package/uuid) or
* [hyperid](https://www.npmjs.com/package/hyperid) instead.
* @deprecated Use `generateUniqueId`, [uuid](https://www.npmjs.com/package/uuid)
* or [hyperid](https://www.npmjs.com/package/hyperid) instead.
*/

@@ -131,0 +131,0 @@ export declare function uuid(): string;

@@ -264,4 +264,4 @@ "use strict";

*
* @deprecated Use [uuid](https://www.npmjs.com/package/uuid) or
* [hyperid](https://www.npmjs.com/package/hyperid) instead.
* @deprecated Use `generateUniqueId`, [uuid](https://www.npmjs.com/package/uuid)
* or [hyperid](https://www.npmjs.com/package/hyperid) instead.
*/

@@ -268,0 +268,0 @@ function uuid() {

{
"name": "@loopback/context",
"version": "3.10.1",
"version": "3.11.0",
"description": "Facilities to manage artifacts and their dependencies in your Node.js applications. The module exposes TypeScript/JavaScript APIs and decorators to register artifacts, declare dependencies, and resolve artifacts by keys. It also serves as an IoC container to support dependency injection",

@@ -26,3 +26,3 @@ "main": "dist/index.js",

"dependencies": {
"@loopback/metadata": "^2.2.6",
"@loopback/metadata": "^3.0.0",
"@types/debug": "^4.1.5",

@@ -36,7 +36,7 @@ "debug": "^4.1.1",

"devDependencies": {
"@loopback/build": "^6.2.2",
"@loopback/eslint-config": "^9.0.2",
"@loopback/testlab": "^3.2.4",
"@loopback/build": "^6.2.3",
"@loopback/eslint-config": "^10.0.0",
"@loopback/testlab": "^3.2.5",
"@types/bluebird": "^3.5.32",
"@types/node": "^10.17.28",
"@types/node": "^10.17.34",
"@types/uuid": "^8.3.0",

@@ -65,3 +65,3 @@ "bluebird": "^3.7.2"

},
"gitHead": "a3f54273814de63819e0d8bc86509f8a737800bb"
"gitHead": "2b7d2ef44be0e3c19aee3316a2776d7fff6b0051"
}

@@ -20,5 +20,7 @@ // Copyright IBM Corp. 2018,2020. All Rights Reserved.

/**
* Decorator factory for `@bind`
* Decorator factory for `@injectable`
*/
class BindDecoratorFactory extends ClassDecoratorFactory<BindingMetadata> {
class InjectableDecoratorFactory extends ClassDecoratorFactory<
BindingMetadata
> {
mergeWithInherited(inherited: BindingMetadata, target: Function) {

@@ -58,4 +60,5 @@ if (inherited) {

* ```ts
* @bind((binding) => {binding.inScope(BindingScope.SINGLETON).tag('controller')}
* @injectable((binding) => {binding.inScope(BindingScope.SINGLETON).tag('controller')}
* )
* @injectable({scope: BindingScope.SINGLETON})
* export class MyController {

@@ -68,3 +71,3 @@ * }

*/
export function bind(...specs: BindingSpec[]): ClassDecorator {
export function injectable(...specs: BindingSpec[]): ClassDecorator {
const templateFunctions = specs.map(t => {

@@ -85,6 +88,6 @@ if (typeof t === 'function') {

const decorator = BindDecoratorFactory.createDecorator(
const decorator = InjectableDecoratorFactory.createDecorator(
BINDING_METADATA_KEY,
spec,
{decoratorName: '@bind'},
{decoratorName: '@injectable'},
);

@@ -95,5 +98,8 @@ decorator(target);

export namespace bind {
/**
* A namespace to host shortcuts for `@injectable`
*/
export namespace injectable {
/**
* `@bind.provider` to denote a provider class
* `@injectable.provider` to denote a provider class
*

@@ -109,3 +115,3 @@ * A list of binding scope/tags or template functions to configure the binding

}
bind(
injectable(
// Set up the default for providers

@@ -119,1 +125,21 @@ asProvider(target),

}
/**
* `@bind` is now an alias to {@link injectable} for backward compatibility
* {@inheritDoc injectable}
*/
export function bind(...specs: BindingSpec[]): ClassDecorator {
return injectable(...specs);
}
/**
* Alias namespace `bind` to `injectable` for backward compatibility
*
* It should have the same members as `bind`.
*/
export namespace bind {
/**
* {@inheritDoc injectable.provider}
*/
export const provider = injectable.provider;
}

@@ -24,3 +24,3 @@ // Copyright IBM Corp. 2018,2020. All Rights Reserved.

/**
* Binding metadata from `@bind`
* Binding metadata from `@injectable`
*

@@ -57,3 +57,3 @@ * @typeParam T - Value type

/**
* Specification of parameters for `@bind()`
* Specification of parameters for `@injectable()`
*/

@@ -169,3 +169,3 @@ export type BindingSpec<T = unknown> = BindingTemplate<T> | BindingScopeAndTags;

*
* @param cls - A class with optional `@bind`
* @param cls - A class with optional `@injectable`
*

@@ -249,6 +249,9 @@ * @typeParam T - Value type

* - `binding.toClass(cls)`: if `cls` is a plain class such as `MyController`
* - `binding.toProvider(cls)`: it `cls` is a value provider class with a
* - `binding.toProvider(cls)`: if `cls` is a value provider class with a
* prototype method `value()`
* - `binding.toDynamicValue(cls)`: if `cls` is a dynamic value provider class
* with a static method `value()`
*
* @param cls - A class. It can be either a plain class or a value provider class
* @param cls - A class. It can be either a plain class, a value provider class,
* or a dynamic value provider class
* @param options - Options to customize the binding key

@@ -255,0 +258,0 @@ *

@@ -10,2 +10,3 @@ // Copyright IBM Corp. 2018,2020. All Rights Reserved.

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export class BindingKey<ValueType> {

@@ -29,6 +30,3 @@ static readonly PROPERTY_SEPARATOR = '#';

*/
public static create<ValueType>(
key: string,
propertyPath?: string,
): BindingKey<ValueType> {
public static create<V>(key: string, propertyPath?: string): BindingKey<V> {
// TODO(bajtos) allow chaining of propertyPaths, e.g.

@@ -39,3 +37,3 @@ // BindingKey.create('config#rest', 'port')

BindingKey.validate(key);
return new BindingKey<ValueType>(key, propertyPath);
return new BindingKey<V>(key, propertyPath);
}

@@ -42,0 +40,0 @@

@@ -858,3 +858,3 @@ // Copyright IBM Corp. 2017,2020. All Rights Reserved.

*/
static bind<T = unknown>(key: BindingAddress<T>): Binding<T> {
static bind<V = unknown>(key: BindingAddress<V>): Binding<V> {
return new Binding(key);

@@ -872,3 +872,3 @@ }

*
* @typeParam T Generic type for the configuration value (not the binding to
* @typeParam V Generic type for the configuration value (not the binding to
* be configured)

@@ -878,4 +878,4 @@ *

*/
static configure<T = unknown>(key: BindingAddress): Binding<T> {
return new Binding(BindingKey.buildKeyForConfig<T>(key)).tag({
static configure<V = unknown>(key: BindingAddress): Binding<V> {
return new Binding(BindingKey.buildKeyForConfig<V>(key)).tag({
[ContextTags.CONFIGURATION_FOR]: key.toString(),

@@ -882,0 +882,0 @@ });

@@ -254,3 +254,3 @@ // Copyright IBM Corp. 2019,2020. All Rights Reserved.

eventName: 'bind',
listener: <T>(event: ContextViewEvent<T>) => void,
listener: <V>(event: ContextViewEvent<V>) => void,
): this;

@@ -266,3 +266,3 @@

eventName: 'unbind',
listener: <T>(event: ContextViewEvent<T> & {cachedValue?: T}) => void,
listener: <V>(event: ContextViewEvent<V> & {cachedValue?: V}) => void,
): this;

@@ -287,3 +287,3 @@

// eslint-disable-next-line @typescript-eslint/unified-signatures
on(eventName: 'refresh', listener: <T>(result: T[]) => void): this;
on(eventName: 'refresh', listener: <V>(result: V[]) => void): this;

@@ -317,3 +317,3 @@ /**

eventName: 'bind',
listener: <T>(event: ContextViewEvent<T>) => void,
listener: <V>(event: ContextViewEvent<V>) => void,
): this;

@@ -329,3 +329,3 @@

eventName: 'unbind',
listener: <T>(event: ContextViewEvent<T> & {cachedValue?: T}) => void,
listener: <V>(event: ContextViewEvent<V> & {cachedValue?: V}) => void,
): this;

@@ -350,3 +350,3 @@

// eslint-disable-next-line @typescript-eslint/unified-signatures
once(eventName: 'refresh', listener: <T>(result: T[]) => void): this;
once(eventName: 'refresh', listener: <V>(result: V[]) => void): this;

@@ -353,0 +353,0 @@ /**

@@ -14,2 +14,3 @@ // Copyright IBM Corp. 2017,2020. All Rights Reserved.

PropertyDecoratorFactory,
Reflector,
} from '@loopback/metadata';

@@ -30,13 +31,16 @@ import {Binding, BindingTag} from './binding';

import {ResolutionOptions, ResolutionSession} from './resolution-session';
import {BoundValue, ValueOrPromise} from './value-promise';
import {BoundValue, Constructor, ValueOrPromise} from './value-promise';
const PARAMETERS_KEY = MetadataAccessor.create<Injection, ParameterDecorator>(
'inject:parameters',
);
const PROPERTIES_KEY = MetadataAccessor.create<Injection, PropertyDecorator>(
'inject:properties',
);
const INJECT_PARAMETERS_KEY = MetadataAccessor.create<
Injection,
ParameterDecorator
>('inject:parameters');
const INJECT_PROPERTIES_KEY = MetadataAccessor.create<
Injection,
PropertyDecorator
>('inject:properties');
// A key to cache described argument injections
const METHODS_KEY = MetadataAccessor.create<Injection, MethodDecorator>(
const INJECT_METHODS_KEY = MetadataAccessor.create<Injection, MethodDecorator>(
'inject:methods',

@@ -156,3 +160,3 @@ );

>(
PARAMETERS_KEY,
INJECT_PARAMETERS_KEY,
{

@@ -193,3 +197,3 @@ target,

>(
PROPERTIES_KEY,
INJECT_PROPERTIES_KEY,
{

@@ -581,3 +585,3 @@ target,

MetadataInspector.getAllMethodMetadata<Readonly<Injection>[]>(
METHODS_KEY,
INJECT_METHODS_KEY,
target,

@@ -604,3 +608,3 @@ {

MetadataInspector.getAllParameterMetadata<Readonly<Injection>>(
PARAMETERS_KEY,
INJECT_PARAMETERS_KEY,
target,

@@ -614,3 +618,3 @@ method,

MetadataInspector.defineMetadata<MetadataMap<Readonly<Injection>[]>>(
METHODS_KEY,
INJECT_METHODS_KEY,
cache,

@@ -633,3 +637,3 @@ target,

);
return designType.parameterTypes[
return designType?.parameterTypes?.[
injection.methodDescriptorOrParameterIndex as number

@@ -717,3 +721,3 @@ ];

MetadataInspector.getAllPropertyMetadata<Readonly<Injection>>(
PROPERTIES_KEY,
INJECT_PROPERTIES_KEY,
target,

@@ -786,1 +790,19 @@ ) ?? {};

}
/**
* Check if the given class has `@inject` or other decorations that map to
* `@inject`.
*
* @param cls - Class with possible `@inject` decorations
*/
export function hasInjections(cls: Constructor<unknown>): boolean {
return (
MetadataInspector.getClassMetadata(INJECT_PARAMETERS_KEY, cls) != null ||
Reflector.getMetadata(INJECT_PARAMETERS_KEY.toString(), cls.prototype) !=
null ||
MetadataInspector.getAllPropertyMetadata(
INJECT_PROPERTIES_KEY,
cls.prototype,
) != null
);
}

@@ -17,3 +17,3 @@ // Copyright IBM Corp. 2019,2020. All Rights Reserved.

import {Binding, BindingTemplate} from './binding';
import {bind} from './binding-decorator';
import {injectable} from './binding-decorator';
import {

@@ -163,3 +163,3 @@ BindingFromClassOptions,

export function globalInterceptor(group?: string, ...specs: BindingSpec[]) {
return bind(asGlobalInterceptor(group), ...specs);
return injectable(asGlobalInterceptor(group), ...specs);
}

@@ -166,0 +166,0 @@

@@ -97,3 +97,3 @@ // Copyright IBM Corp. 2018,2020. All Rights Reserved.

map: MapObject<T>,
resolver: (val: T, key: string, map: MapObject<T>) => ValueOrPromise<V>,
resolver: (val: T, key: string, values: MapObject<T>) => ValueOrPromise<V>,
): ValueOrPromise<MapObject<V>> {

@@ -160,3 +160,3 @@ const result: MapObject<V> = {};

list: T[],
resolver: (val: T, index: number, list: T[]) => ValueOrPromise<V>,
resolver: (val: T, index: number, values: T[]) => ValueOrPromise<V>,
): ValueOrPromise<V[]> {

@@ -307,4 +307,4 @@ const result: V[] = new Array<V>(list.length);

*
* @deprecated Use [uuid](https://www.npmjs.com/package/uuid) or
* [hyperid](https://www.npmjs.com/package/hyperid) instead.
* @deprecated Use `generateUniqueId`, [uuid](https://www.npmjs.com/package/uuid)
* or [hyperid](https://www.npmjs.com/package/hyperid) instead.
*/

@@ -311,0 +311,0 @@ export function uuid() {

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc