Socket
Socket
Sign inDemoInstall

@loopback/context

Package Overview
Dependencies
10
Maintainers
7
Versions
192
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.1.1 to 3.0.0

34

CHANGELOG.md

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

# [3.0.0](https://github.com/strongloop/loopback-next/compare/@loopback/context@2.1.1...@loopback/context@3.0.0) (2020-03-05)
### chore
* remove support for Node.js v8.x ([4281d9d](https://github.com/strongloop/loopback-next/commit/4281d9df50f0715d32879e1442a90b643ec8f542))
### Features
* **context:** allow tags to be matched by a given name with any value ([7cf053e](https://github.com/strongloop/loopback-next/commit/7cf053e49f46b93033c6b7c5e80daffe8406b2af))
* **context:** remove generic parameters from `BindingFilter` type ([1ce33af](https://github.com/strongloop/loopback-next/commit/1ce33afeefc1c928085ed505adaa32cc06574a0c))
* add `tslib` as dependency ([a6e0b4c](https://github.com/strongloop/loopback-next/commit/a6e0b4ce7b862764167cefedee14c1115b25e0a4)), closes [#4676](https://github.com/strongloop/loopback-next/issues/4676)
* **context:** improve ctx.inspect() to allow classes with colliding names ([e7380fc](https://github.com/strongloop/loopback-next/commit/e7380fc467fe43fd801d8eca05e37745fc922aed))
### BREAKING CHANGES
* **context:** The type `BindingFilter` is no longer generic. Please
update your code and remove any generic arguments provided for the type.
```diff
- BindingFilter<SomeType>
+ BindingFilter
```
Signed-off-by: Miroslav Bajtoš <mbajtoss@gmail.com>
* Node.js v8.x is now end of life. Please upgrade to version
10 and above. See https://nodejs.org/en/about/releases.
## [2.1.1](https://github.com/strongloop/loopback-next/compare/@loopback/context@2.1.0...@loopback/context@2.1.1) (2020-02-06)

@@ -8,0 +42,0 @@

4

dist/binding-config.js
"use strict";
// Copyright IBM Corp. 2017,2018. All Rights Reserved.
// Copyright IBM Corp. 2019. All Rights Reserved.
// Node module: @loopback/context

@@ -16,3 +16,3 @@ // This file is licensed under the MIT License.

getConfigAsValueOrPromise(key, propertyPath, resolutionOptions) {
propertyPath = (propertyPath !== null && propertyPath !== void 0 ? propertyPath : '');
propertyPath = propertyPath !== null && propertyPath !== void 0 ? propertyPath : '';
const configKey = configBindingKeyFor(key, propertyPath);

@@ -19,0 +19,0 @@ const options = Object.assign({ optional: true }, resolutionOptions);

@@ -8,14 +8,8 @@ import { Binding, BindingTag } from './binding';

* @remarks
* TODO(semver-major): We might change this type in the future to either remove
* the `<ValueType>` or make it as type guard by asserting the matched binding
* to be typed with `<ValueType>`.
*
* **NOTE**: Originally, we allow filters to be tied with a single value type.
* Originally, we allowed filters to be tied with a single value type.
* This actually does not make much sense - the filter function is typically
* invoked on all bindings to find those ones matching the given criteria.
* Filters must be prepared to handle bindings of any value type. We learned
* about this problem after enabling TypeScript's `strictFunctionTypes` check,
* but decided to preserve `ValueType` argument for backwards compatibility.
* The `<ValueType>` represents the value type for matched bindings but it's
* not used for checking.
* about this problem after enabling TypeScript's `strictFunctionTypes` check.
* This aspect is resolved by typing the input argument as `Binding<unknown>`.
*

@@ -35,8 +29,16 @@ * Ideally, `BindingFilter` should be declared as a type guard as follows:

*
* If we described BindingFilter as a type-guard, then all filter implementations
* would have to be explicitly typed as type-guards too, which would make it
* tedious to write quick filter functions like `b => b.key.startsWith('services')`.
*
* To keep things simple and easy to use, we use `boolean` as the return type
* of a binding filter function.
*/
export declare type BindingFilter<ValueType = unknown> = (binding: Readonly<Binding<unknown>>) => boolean;
export interface BindingFilter {
(binding: Readonly<Binding<unknown>>): boolean;
}
/**
* Select binding(s) by key or a filter function
*/
export declare type BindingSelector<ValueType = unknown> = BindingAddress<ValueType> | BindingFilter<ValueType>;
export declare type BindingSelector<ValueType = unknown> = BindingAddress<ValueType> | BindingFilter;
/**

@@ -52,3 +54,3 @@ * Type guard for binding address

*/
export interface BindingTagFilter extends BindingFilter<unknown> {
export interface BindingTagFilter extends BindingFilter {
/**

@@ -67,2 +69,17 @@ * A special property on the filter function to provide access to the binding

/**
* A symbol that can be used to match binding tags by name regardless of the
* value.
*
* @example
*
* The following code matches bindings with tag `{controller: 'A'}` or
* `{controller: 'controller'}`. But if the tag name 'controller' does not
* exist for a binding, the binding will NOT be included.
*
* ```ts
* ctx.findByTag({controller: ANY_TAG_VALUE})
* ```
*/
export declare const ANY_TAG_VALUE: unique symbol;
/**
* Create a binding filter for the tag pattern

@@ -69,0 +86,0 @@ * @param tagPattern - Binding tag name, regexp, or object

"use strict";
// Copyright IBM Corp. 2019. All Rights Reserved.
// Copyright IBM Corp. 2019,2020. All Rights Reserved.
// Node module: @loopback/context

@@ -46,2 +46,17 @@ // This file is licensed under the MIT License.

/**
* A symbol that can be used to match binding tags by name regardless of the
* value.
*
* @example
*
* The following code matches bindings with tag `{controller: 'A'}` or
* `{controller: 'controller'}`. But if the tag name 'controller' does not
* exist for a binding, the binding will NOT be included.
*
* ```ts
* ctx.findByTag({controller: ANY_TAG_VALUE})
* ```
*/
exports.ANY_TAG_VALUE = Symbol.for('loopback.AnyTagValue');
/**
* Create a binding filter for the tag pattern

@@ -75,2 +90,4 @@ * @param tagPattern - Binding tag name, regexp, or object

for (const t in tagPattern) {
if (tagMap[t] === exports.ANY_TAG_VALUE)
return t in b.tagMap;
// One tag name/value does not match

@@ -86,3 +103,3 @@ if (b.tagMap[t] !== tagMap[t])

const tagFilter = filter;
tagFilter.bindingTagPattern = (regex !== null && regex !== void 0 ? regex : tagPattern);
tagFilter.bindingTagPattern = regex !== null && regex !== void 0 ? regex : tagPattern;
return tagFilter;

@@ -89,0 +106,0 @@ }

@@ -6,8 +6,6 @@ "use strict";

// License text available at https://opensource.org/licenses/MIT
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const metadata_1 = require("@loopback/metadata");
const debug_1 = __importDefault(require("debug"));
const debug_1 = tslib_1.__importDefault(require("debug"));
const binding_1 = require("./binding");

@@ -102,6 +100,6 @@ const keys_1 = require("./keys");

function bindingTemplateFor(cls) {
var _a, _b;
var _a;
const spec = getBindingMetadata(cls);
debug('class %s has binding metadata', cls.name, spec);
const templateFunctions = (_b = (_a = spec) === null || _a === void 0 ? void 0 : _a.templates, (_b !== null && _b !== void 0 ? _b : [asClassOrProvider(cls)]));
const templateFunctions = (_a = spec === null || spec === void 0 ? void 0 : spec.templates) !== null && _a !== void 0 ? _a : [asClassOrProvider(cls)];
return function applyBindingTemplatesFromMetadata(binding) {

@@ -204,13 +202,13 @@ for (const t of templateFunctions) {

return key;
let namespace = (_a = options.namespace, (_a !== null && _a !== void 0 ? _a : bindingTemplate.tagMap[keys_1.ContextTags.NAMESPACE]));
let namespace = (_a = options.namespace) !== null && _a !== void 0 ? _a : bindingTemplate.tagMap[keys_1.ContextTags.NAMESPACE];
if (!namespace) {
const namespaces = Object.assign({}, exports.DEFAULT_TYPE_NAMESPACES, options.typeNamespaceMapping);
// Derive the key from type + name
let type = (_b = options.type, (_b !== null && _b !== void 0 ? _b : bindingTemplate.tagMap[keys_1.ContextTags.TYPE]));
let type = (_b = options.type) !== null && _b !== void 0 ? _b : bindingTemplate.tagMap[keys_1.ContextTags.TYPE];
if (!type) {
type = (_c = bindingTemplate.tagNames.find(t => namespaces[t] != null), (_c !== null && _c !== void 0 ? _c : keys_1.ContextTags.CLASS));
type = (_c = bindingTemplate.tagNames.find(t => namespaces[t] != null)) !== null && _c !== void 0 ? _c : keys_1.ContextTags.CLASS;
}
namespace = getNamespace(type, namespaces);
}
const name = (_d = options.name, (_d !== null && _d !== void 0 ? _d : (bindingTemplate.tagMap[keys_1.ContextTags.NAME] || cls.name)));
const name = (_d = options.name) !== null && _d !== void 0 ? _d : (bindingTemplate.tagMap[keys_1.ContextTags.NAME] || cls.name);
key = `${namespace}.${name}`;

@@ -217,0 +215,0 @@ return key;

"use strict";
// Copyright IBM Corp. 2018. All Rights Reserved.
// Copyright IBM Corp. 2018,2019. All Rights Reserved.
// Node module: @loopback/context

@@ -4,0 +4,0 @@ // This file is licensed under the MIT License.

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

function compareByOrder(a, b, order = []) {
a = (a !== null && a !== void 0 ? a : '');
b = (b !== null && b !== void 0 ? b : '');
a = a !== null && a !== void 0 ? a : '';
b = b !== null && b !== void 0 ? b : '';
const i1 = order.indexOf(a);

@@ -55,0 +55,0 @@ const i2 = order.indexOf(b);

"use strict";
// Copyright IBM Corp. 2017,2019. All Rights Reserved.
// Copyright IBM Corp. 2017,2020. All Rights Reserved.
// Node module: @loopback/context
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const debug_1 = __importDefault(require("debug"));
const tslib_1 = require("tslib");
const debug_1 = tslib_1.__importDefault(require("debug"));
const events_1 = require("events");

@@ -138,3 +136,3 @@ const binding_key_1 = require("./binding-key");

// Default to TRANSIENT if not set
return _a = this._scope, (_a !== null && _a !== void 0 ? _a : BindingScope.TRANSIENT);
return (_a = this._scope) !== null && _a !== void 0 ? _a : BindingScope.TRANSIENT;
}

@@ -141,0 +139,0 @@ /**

"use strict";
// Copyright IBM Corp. 2019. All Rights Reserved.
// Copyright IBM Corp. 2019,2020. All Rights Reserved.
// Node module: @loopback/context

@@ -4,0 +4,0 @@ // This file is licensed under the MIT License.

"use strict";
// Copyright IBM Corp. 2020. All Rights Reserved.
// Copyright IBM Corp. 2019,2020. All Rights Reserved.
// Node module: @loopback/context
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
var __asyncValues = (this && this.__asyncValues) || function (o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const debug_1 = __importDefault(require("debug"));
const tslib_1 = require("tslib");
const debug_1 = tslib_1.__importDefault(require("debug"));
const events_1 = require("events");

@@ -193,3 +184,3 @@ const debug = debug_1.default('loopback:context:subscription');

try {
for (var events_2 = __asyncValues(events), events_2_1; events_2_1 = await events_2.next(), !events_2_1.done;) {
for (var events_2 = tslib_1.__asyncValues(events), events_2_1; events_2_1 = await events_2.next(), !events_2_1.done;) {
const { type, binding, context, observers } = events_2_1.value;

@@ -265,3 +256,3 @@ // The loop will happen asynchronously upon events

var _a;
this._observers = (_a = this._observers, (_a !== null && _a !== void 0 ? _a : new Set()));
this._observers = (_a = this._observers) !== null && _a !== void 0 ? _a : new Set();
this.setupEventHandlersIfNeeded();

@@ -268,0 +259,0 @@ this._observers.add(observer);

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

break; // One of the tags is not found
filter = (filter !== null && filter !== void 0 ? filter : binding_filter_1.filterByTag(tag));
filter = filter !== null && filter !== void 0 ? filter : binding_filter_1.filterByTag(tag);
const matched = new Set(Array.from(bindingsByTag).filter(filter));

@@ -111,3 +111,3 @@ if (!union && matched.size === 0)

if (union) {
matched.forEach(b => { var _a; return (_a = bindings) === null || _a === void 0 ? void 0 : _a.add(b); });
matched.forEach(b => bindings === null || bindings === void 0 ? void 0 : bindings.add(b));
}

@@ -114,0 +114,0 @@ else {

"use strict";
// Copyright IBM Corp. 2019. All Rights Reserved.
// Copyright IBM Corp. 2019,2020. All Rights Reserved.
// Node module: @loopback/context
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const debug_1 = __importDefault(require("debug"));
const tslib_1 = require("tslib");
const debug_1 = tslib_1.__importDefault(require("debug"));
const events_1 = require("events");

@@ -12,0 +10,0 @@ const util_1 = require("util");

@@ -406,2 +406,10 @@ /// <reference types="node" />

inspect(options?: ContextInspectOptions): JSONObject;
/**
* Inspect the context hierarchy
* @param options - Options for inspect
* @param visitedClasses - A map to keep class to name so that we can have
* different names for classes with colliding names. The situation can happen
* when two classes with the same name are bound in different modules.
*/
private _inspect;
}

@@ -408,0 +416,0 @@ /**

"use strict";
// Copyright IBM Corp. 2017,2019. All Rights Reserved.
// Copyright IBM Corp. 2017,2020. All Rights Reserved.
// Node module: @loopback/context
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const debug_1 = __importDefault(require("debug"));
const tslib_1 = require("tslib");
const debug_1 = tslib_1.__importDefault(require("debug"));
const events_1 = require("events");

@@ -66,3 +64,3 @@ const uuid_1 = require("uuid");

this._parent = _parent;
this.name = (name !== null && name !== void 0 ? name : this.generateName());
this.name = name !== null && name !== void 0 ? name : this.generateName();
this.tagIndexer = new context_tag_indexer_1.ContextTagIndexer(this);

@@ -134,3 +132,2 @@ this.subscriptionManager = new context_subscription_1.ContextSubscriptionManager(this);

add(binding) {
var _a;
const key = binding.key;

@@ -142,3 +139,3 @@ this._debug('[%s] Adding binding: %s', key);

existingBinding = this.registry.get(key);
const bindingIsLocked = (_a = existingBinding) === null || _a === void 0 ? void 0 : _a.isLocked;
const bindingIsLocked = existingBinding === null || existingBinding === void 0 ? void 0 : existingBinding.isLocked;
if (bindingIsLocked)

@@ -255,3 +252,2 @@ throw new Error(`Cannot rebind key "${key}" to a locked binding`);

unbind(key) {
var _a;
this._debug('Unbind %s', key);

@@ -263,3 +259,3 @@ key = binding_key_1.BindingKey.validate(key);

return false;
if ((_a = binding) === null || _a === void 0 ? void 0 : _a.isLocked)
if (binding === null || binding === void 0 ? void 0 : binding.isLocked)
throw new Error(`Cannot unbind key "${key}" of a locked binding`);

@@ -427,3 +423,2 @@ this.registry.delete(key);

getBinding(key, options) {
var _a;
key = binding_key_1.BindingKey.validate(key);

@@ -437,3 +432,3 @@ const binding = this.registry.get(key);

}
if ((_a = options) === null || _a === void 0 ? void 0 : _a.optional)
if (options === null || options === void 0 ? void 0 : options.optional)
return undefined;

@@ -524,6 +519,31 @@ throw new Error(`The key '${key}' is not bound to any value in context ${this.name}`);

inspect(options = {}) {
return this._inspect(options, new ClassNameMap());
}
/**
* Inspect the context hierarchy
* @param options - Options for inspect
* @param visitedClasses - A map to keep class to name so that we can have
* different names for classes with colliding names. The situation can happen
* when two classes with the same name are bound in different modules.
*/
_inspect(options, visitedClasses) {
var _a;
options = Object.assign({ includeParent: true, includeInjections: false }, options);
const bindings = {};
for (const [k, v] of this.registry) {
const ctor = (_a = v.valueConstructor) !== null && _a !== void 0 ? _a : v.providerConstructor;
let name = undefined;
if (ctor != null) {
name = visitedClasses.visit(ctor);
}
bindings[k] = v.inspect(options);
if (name != null) {
const binding = bindings[k];
if (v.valueConstructor) {
binding.valueConstructor = name;
}
else if (v.providerConstructor) {
binding.providerConstructor = name;
}
}
}

@@ -537,3 +557,3 @@ const json = {

if (this._parent) {
json.parent = this._parent.inspect(options);
json.parent = this._parent._inspect(options, visitedClasses);
}

@@ -545,2 +565,30 @@ return json;

/**
* An internal utility class to handle class name conflicts
*/
class ClassNameMap {
constructor() {
this.classes = new Map();
this.nameIndex = new Map();
}
visit(ctor) {
let name = this.classes.get(ctor);
if (name == null) {
name = ctor.name;
// Now check if the name collides with another class
let index = this.nameIndex.get(name);
if (typeof index === 'number') {
// A conflict is found, mangle the name as `ClassName #1`
this.nameIndex.set(name, ++index);
name = `${name} #${index}`;
}
else {
// The name is used for the 1st time
this.nameIndex.set(name, 0);
}
this.classes.set(ctor, name);
}
return name;
}
}
/**
* Policy to control if a binding should be created for the context

@@ -547,0 +595,0 @@ */

"use strict";
// Copyright IBM Corp. 2017,2018. All Rights Reserved.
// Copyright IBM Corp. 2017,2020. All Rights Reserved.
// Node module: @loopback/context
// This file is licensed under the MIT License.
// 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 });
__export(require("@loopback/metadata"));
__export(require("./binding"));
__export(require("./binding-config"));
__export(require("./binding-decorator"));
__export(require("./binding-filter"));
__export(require("./binding-inspector"));
__export(require("./binding-key"));
__export(require("./binding-sorter"));
__export(require("./context"));
__export(require("./context-subscription"));
__export(require("./context-view"));
__export(require("./inject"));
__export(require("./inject-config"));
__export(require("./interception-proxy"));
__export(require("./interceptor"));
__export(require("./interceptor-chain"));
__export(require("./invocation"));
__export(require("./keys"));
__export(require("./resolution-session"));
__export(require("./resolver"));
__export(require("./value-promise"));
const tslib_1 = require("tslib");
tslib_1.__exportStar(require("@loopback/metadata"), exports);
tslib_1.__exportStar(require("./binding"), exports);
tslib_1.__exportStar(require("./binding-config"), exports);
tslib_1.__exportStar(require("./binding-decorator"), exports);
tslib_1.__exportStar(require("./binding-filter"), exports);
tslib_1.__exportStar(require("./binding-inspector"), exports);
tslib_1.__exportStar(require("./binding-key"), exports);
tslib_1.__exportStar(require("./binding-sorter"), exports);
tslib_1.__exportStar(require("./context"), exports);
tslib_1.__exportStar(require("./context-subscription"), exports);
tslib_1.__exportStar(require("./context-view"), exports);
tslib_1.__exportStar(require("./inject"), exports);
tslib_1.__exportStar(require("./inject-config"), exports);
tslib_1.__exportStar(require("./interception-proxy"), exports);
tslib_1.__exportStar(require("./interceptor"), exports);
tslib_1.__exportStar(require("./interceptor-chain"), exports);
tslib_1.__exportStar(require("./invocation"), exports);
tslib_1.__exportStar(require("./keys"), exports);
tslib_1.__exportStar(require("./resolution-session"), exports);
tslib_1.__exportStar(require("./resolver"), exports);
tslib_1.__exportStar(require("./value-promise"), exports);
//# sourceMappingURL=index.js.map

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

function config(propertyPath, metadata) {
propertyPath = (propertyPath !== null && propertyPath !== void 0 ? propertyPath : '');
propertyPath = propertyPath !== null && propertyPath !== void 0 ? propertyPath : '';
if (typeof propertyPath === 'object') {

@@ -63,3 +63,3 @@ metadata = propertyPath;

config.getter = function injectConfigGetter(propertyPath, metadata) {
propertyPath = (propertyPath !== null && propertyPath !== void 0 ? propertyPath : '');
propertyPath = propertyPath !== null && propertyPath !== void 0 ? propertyPath : '';
if (typeof propertyPath === 'object') {

@@ -79,3 +79,3 @@ metadata = propertyPath;

config.view = function injectConfigView(propertyPath, metadata) {
propertyPath = (propertyPath !== null && propertyPath !== void 0 ? propertyPath : '');
propertyPath = propertyPath !== null && propertyPath !== void 0 ? propertyPath : '';
if (typeof propertyPath === 'object') {

@@ -82,0 +82,0 @@ metadata = propertyPath;

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

*/
const view: (bindingFilter: BindingFilter<unknown>, metadata?: InjectionMetadata | undefined) => (target: Object, member: string | undefined, methodDescriptorOrParameterIndex?: number | TypedPropertyDescriptor<any> | undefined) => void;
const view: (bindingFilter: BindingFilter, metadata?: InjectionMetadata | undefined) => (target: Object, member: string | undefined, methodDescriptorOrParameterIndex?: number | TypedPropertyDescriptor<any> | undefined) => void;
/**

@@ -194,0 +194,0 @@ * Inject the context object.

"use strict";
// Copyright IBM Corp. 2017,2018. All Rights Reserved.
// Copyright IBM Corp. 2017,2020. All Rights Reserved.
// Node module: @loopback/context

@@ -176,3 +176,3 @@ // This file is licensed under the MIT License.

metadata = Object.assign({ decorator: '@inject.binding' }, metadata);
return inject((bindingKey !== null && bindingKey !== void 0 ? bindingKey : ''), metadata, resolveAsBinding);
return inject(bindingKey !== null && bindingKey !== void 0 ? bindingKey : '', metadata, resolveAsBinding);
};

@@ -240,3 +240,3 @@ /**

if (targetType && targetType !== expectedType) {
expectedTypeName = (expectedTypeName !== null && expectedTypeName !== void 0 ? expectedTypeName : expectedType.name);
expectedTypeName = expectedTypeName !== null && expectedTypeName !== void 0 ? expectedTypeName : expectedType.name;
throw new Error(`The type of ${targetName} (${targetType.name}) is not ${expectedTypeName}`);

@@ -292,5 +292,4 @@ }

function findOrCreateBindingForInjection(ctx, injection, session) {
var _a;
if (injection.bindingSelector === '')
return (_a = session) === null || _a === void 0 ? void 0 : _a.currentBinding;
return session === null || session === void 0 ? void 0 : session.currentBinding;
const bindingCreation = injection.metadata &&

@@ -367,7 +366,7 @@ injection.metadata.bindingCreation;

var _a, _b;
method = (method !== null && method !== void 0 ? method : '');
method = method !== null && method !== void 0 ? method : '';
// Try to read from cache
const cache = (_a = metadata_1.MetadataInspector.getAllMethodMetadata(METHODS_KEY, target, {
ownMetadataOnly: true,
}), (_a !== null && _a !== void 0 ? _a : {}));
})) !== null && _a !== void 0 ? _a : {};
let meta = cache[method];

@@ -388,3 +387,3 @@ if (meta)

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

@@ -457,3 +456,3 @@ cache[method] = meta;

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

@@ -469,3 +468,3 @@ }

const json = {};
const ctor = (_a = binding.valueConstructor, (_a !== null && _a !== void 0 ? _a : binding.providerConstructor));
const ctor = (_a = binding.valueConstructor) !== null && _a !== void 0 ? _a : binding.providerConstructor;
if (ctor == null)

@@ -509,3 +508,3 @@ return json;

// Binding filter function
descriptor.bindingFilter = (_b = (_a = injectionInfo.bindingSelector) === null || _a === void 0 ? void 0 : _a.name, (_b !== null && _b !== void 0 ? _b : '<function>'));
descriptor.bindingFilter = (_b = (_a = injectionInfo.bindingSelector) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : '<function>';
}

@@ -512,0 +511,0 @@ // Inspect metadata

@@ -6,7 +6,5 @@ "use strict";

// License text available at https://opensource.org/licenses/MIT
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const debug_1 = __importDefault(require("debug"));
const tslib_1 = require("tslib");
const debug_1 = tslib_1.__importDefault(require("debug"));
const value_promise_1 = require("./value-promise");

@@ -13,0 +11,0 @@ const debug = debug_1.default('loopback:context:interceptor-chain');

"use strict";
// Copyright IBM Corp. 2019. All Rights Reserved.
// Copyright IBM Corp. 2019,2020. All Rights Reserved.
// Node module: @loopback/context
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const metadata_1 = require("@loopback/metadata");
const assert_1 = __importDefault(require("assert"));
const debug_1 = __importDefault(require("debug"));
const assert_1 = tslib_1.__importDefault(require("assert"));
const debug_1 = tslib_1.__importDefault(require("debug"));
const binding_decorator_1 = require("./binding-decorator");

@@ -67,3 +65,3 @@ const binding_sorter_1 = require("./binding-sorter");

optional: true,
}), (_a !== null && _a !== void 0 ? _a : []));
})) !== null && _a !== void 0 ? _a : [];
return binding_sorter_1.sortBindingsByPhase(bindings, keys_1.ContextTags.GLOBAL_INTERCEPTOR_GROUP, orderedGroups);

@@ -80,5 +78,5 @@ }

var _a, _b;
let interceptors = (_a = metadata_1.MetadataInspector.getMethodMetadata(exports.INTERCEPT_METHOD_KEY, this.target, this.methodName), (_a !== null && _a !== void 0 ? _a : []));
let interceptors = (_a = metadata_1.MetadataInspector.getMethodMetadata(exports.INTERCEPT_METHOD_KEY, this.target, this.methodName)) !== null && _a !== void 0 ? _a : [];
const targetClass = typeof this.target === 'function' ? this.target : this.target.constructor;
const classInterceptors = (_b = metadata_1.MetadataInspector.getClassMetadata(exports.INTERCEPT_CLASS_KEY, targetClass), (_b !== null && _b !== void 0 ? _b : []));
const classInterceptors = (_b = metadata_1.MetadataInspector.getClassMetadata(exports.INTERCEPT_CLASS_KEY, targetClass)) !== null && _b !== void 0 ? _b : [];
// Inserting class level interceptors before method level ones

@@ -85,0 +83,0 @@ interceptors = mergeInterceptors(classInterceptors, interceptors);

"use strict";
// Copyright IBM Corp. 2019. All Rights Reserved.
// Copyright IBM Corp. 2019,2020. All Rights Reserved.
// Node module: @loopback/context
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const metadata_1 = require("@loopback/metadata");
const assert_1 = __importDefault(require("assert"));
const debug_1 = __importDefault(require("debug"));
const assert_1 = tslib_1.__importDefault(require("assert"));
const debug_1 = tslib_1.__importDefault(require("debug"));
const context_1 = require("./context");

@@ -123,3 +121,2 @@ const interceptor_1 = require("./interceptor");

function invokeTargetMethodWithInjection(ctx, target, method, nonInjectedArgs) {
var _a;
const methodName = getTargetName(target, method);

@@ -129,3 +126,3 @@ /* istanbul ignore if */

debug('Invoking method %s', methodName);
if ((_a = nonInjectedArgs) === null || _a === void 0 ? void 0 : _a.length) {
if (nonInjectedArgs === null || nonInjectedArgs === void 0 ? void 0 : nonInjectedArgs.length) {
debug('Non-injected arguments:', nonInjectedArgs);

@@ -132,0 +129,0 @@ }

"use strict";
// Copyright IBM Corp. 2018. All Rights Reserved.
// Copyright IBM Corp. 2018,2019. All Rights Reserved.
// Node module: @loopback/context

@@ -4,0 +4,0 @@ // This file is licensed under the MIT License.

"use strict";
// Copyright IBM Corp. 2018,2019. All Rights Reserved.
// Copyright IBM Corp. 2018,2020. All Rights Reserved.
// Node module: @loopback/context
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const metadata_1 = require("@loopback/metadata");
const debug_1 = __importDefault(require("debug"));
const debug_1 = tslib_1.__importDefault(require("debug"));
const value_promise_1 = require("./value-promise");

@@ -60,3 +58,3 @@ const debugSession = debug_1.default('loopback:context:resolver:session');

static enterBinding(binding, session) {
session = (session !== null && session !== void 0 ? session : new ResolutionSession());
session = session !== null && session !== void 0 ? session : new ResolutionSession();
session.pushBinding(binding);

@@ -81,3 +79,3 @@ return session;

static enterInjection(injection, session) {
session = (session !== null && session !== void 0 ? session : new ResolutionSession());
session = session !== null && session !== void 0 ? session : new ResolutionSession();
session.pushInjection(injection);

@@ -186,3 +184,2 @@ return session;

popBinding() {
var _a;
const top = this.stack.pop();

@@ -195,3 +192,3 @@ if (!isBinding(top)) {

if (debugSession.enabled) {
debugSession('Exit binding:', (_a = binding) === null || _a === void 0 ? void 0 : _a.toJSON());
debugSession('Exit binding:', binding === null || binding === void 0 ? void 0 : binding.toJSON());
debugSession('Resolution path:', this.getResolutionPath() || '<empty>');

@@ -257,5 +254,5 @@ }

}
return (optionsOrSession !== null && optionsOrSession !== void 0 ? optionsOrSession : {});
return optionsOrSession !== null && optionsOrSession !== void 0 ? optionsOrSession : {};
}
exports.asResolutionOptions = asResolutionOptions;
//# sourceMappingURL=resolution-session.js.map

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

// License text available at https://opensource.org/licenses/MIT
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const metadata_1 = require("@loopback/metadata");
const assert_1 = __importDefault(require("assert"));
const debug_1 = __importDefault(require("debug"));
const assert_1 = tslib_1.__importDefault(require("assert"));
const debug_1 = tslib_1.__importDefault(require("debug"));
const binding_1 = require("./binding");

@@ -36,7 +34,6 @@ const binding_filter_1 = require("./binding-filter");

nonInjectedArgs) {
var _a;
/* istanbul ignore if */
if (debug.enabled) {
debug('Instantiating %s', getTargetName(ctor));
if ((_a = nonInjectedArgs) === null || _a === void 0 ? void 0 : _a.length) {
if (nonInjectedArgs === null || nonInjectedArgs === void 0 ? void 0 : nonInjectedArgs.length) {
debug('Non-injected arguments:', nonInjectedArgs);

@@ -70,4 +67,3 @@ }

function resolveContext(ctx, injection, session) {
var _a;
const currentBinding = (_a = session) === null || _a === void 0 ? void 0 : _a.currentBinding;
const currentBinding = session === null || session === void 0 ? void 0 : session.currentBinding;
if (currentBinding == null ||

@@ -149,3 +145,3 @@ currentBinding.scope !== binding_1.BindingScope.SINGLETON) {

const injectedArgs = inject_1.describeInjectedArguments(target, method);
const extraArgs = (nonInjectedArgs !== null && nonInjectedArgs !== void 0 ? nonInjectedArgs : []);
const extraArgs = nonInjectedArgs !== null && nonInjectedArgs !== void 0 ? nonInjectedArgs : [];
let argLength = metadata_1.DecoratorFactory.getNumberOfParameters(target, method);

@@ -152,0 +148,0 @@ // Please note `injectedArgs` contains `undefined` for non-injected args

"use strict";
// Copyright IBM Corp. 2018,2019. All Rights Reserved.
// Copyright IBM Corp. 2018,2020. All Rights Reserved.
// Node module: @loopback/context

@@ -4,0 +4,0 @@ // This file is licensed under the MIT License.

@@ -1,2 +0,2 @@

// Copyright IBM Corp. 2017,2018. All Rights Reserved.
// Copyright IBM Corp. 2017,2019. All Rights Reserved.
// Node module: @loopback/context

@@ -3,0 +3,0 @@ // This file is licensed under the MIT License.

@@ -1,2 +0,2 @@

// Copyright IBM Corp. 2017,2018. All Rights Reserved.
// Copyright IBM Corp. 2017,2019. All Rights Reserved.
// Node module: @loopback/context

@@ -3,0 +3,0 @@ // This file is licensed under the MIT License.

{
"name": "@loopback/context",
"version": "2.1.1",
"version": "3.0.0",
"description": "LoopBack's container for Inversion of Control",
"engines": {
"node": ">=8.9"
"node": ">=10"
},

@@ -21,15 +21,16 @@ "scripts": {

"dependencies": {
"@loopback/metadata": "^1.4.1",
"@loopback/metadata": "^2.0.0",
"debug": "^4.1.1",
"p-event": "^4.1.0",
"uuid": "^3.4.0"
"tslib": "^1.11.1",
"uuid": "^7.0.2"
},
"devDependencies": {
"@loopback/build": "^3.1.1",
"@loopback/eslint-config": "^5.0.3",
"@loopback/testlab": "^1.10.3",
"@types/bluebird": "^3.5.29",
"@loopback/build": "^4.0.0",
"@loopback/eslint-config": "^6.0.0",
"@loopback/testlab": "^2.0.0",
"@types/bluebird": "^3.5.30",
"@types/debug": "^4.1.5",
"@types/node": "^10.17.14",
"@types/uuid": "^3.4.7",
"@types/node": "^10.17.17",
"@types/uuid": "^7.0.0",
"bluebird": "^3.7.2"

@@ -59,3 +60,3 @@ },

},
"gitHead": "6eea5e428b145cafb84a998bd53979da8c8fba07"
"gitHead": "baf9c89decba06b826204cd43e58a11be05408f8"
}

@@ -1,2 +0,2 @@

// Copyright IBM Corp. 2017,2018. All Rights Reserved.
// Copyright IBM Corp. 2019. All Rights Reserved.
// Node module: @loopback/context

@@ -3,0 +3,0 @@ // This file is licensed under the MIT License.

@@ -1,2 +0,2 @@

// Copyright IBM Corp. 2019. All Rights Reserved.
// Copyright IBM Corp. 2019,2020. All Rights Reserved.
// Node module: @loopback/context

@@ -15,14 +15,8 @@ // This file is licensed under the MIT License.

* @remarks
* TODO(semver-major): We might change this type in the future to either remove
* the `<ValueType>` or make it as type guard by asserting the matched binding
* to be typed with `<ValueType>`.
*
* **NOTE**: Originally, we allow filters to be tied with a single value type.
* Originally, we allowed filters to be tied with a single value type.
* This actually does not make much sense - the filter function is typically
* invoked on all bindings to find those ones matching the given criteria.
* Filters must be prepared to handle bindings of any value type. We learned
* about this problem after enabling TypeScript's `strictFunctionTypes` check,
* but decided to preserve `ValueType` argument for backwards compatibility.
* The `<ValueType>` represents the value type for matched bindings but it's
* not used for checking.
* about this problem after enabling TypeScript's `strictFunctionTypes` check.
* This aspect is resolved by typing the input argument as `Binding<unknown>`.
*

@@ -42,6 +36,12 @@ * Ideally, `BindingFilter` should be declared as a type guard as follows:

*
* If we described BindingFilter as a type-guard, then all filter implementations
* would have to be explicitly typed as type-guards too, which would make it
* tedious to write quick filter functions like `b => b.key.startsWith('services')`.
*
* To keep things simple and easy to use, we use `boolean` as the return type
* of a binding filter function.
*/
export type BindingFilter<ValueType = unknown> = (
binding: Readonly<Binding<unknown>>,
) => boolean;
export interface BindingFilter {
(binding: Readonly<Binding<unknown>>): boolean;
}

@@ -53,3 +53,3 @@ /**

| BindingAddress<ValueType>
| BindingFilter<ValueType>;
| BindingFilter;

@@ -91,3 +91,3 @@ /**

*/
export interface BindingTagFilter extends BindingFilter<unknown> {
export interface BindingTagFilter extends BindingFilter {
/**

@@ -119,2 +119,18 @@ * A special property on the filter function to provide access to the binding

/**
* A symbol that can be used to match binding tags by name regardless of the
* value.
*
* @example
*
* The following code matches bindings with tag `{controller: 'A'}` or
* `{controller: 'controller'}`. But if the tag name 'controller' does not
* exist for a binding, the binding will NOT be included.
*
* ```ts
* ctx.findByTag({controller: ANY_TAG_VALUE})
* ```
*/
export const ANY_TAG_VALUE = Symbol.for('loopback.AnyTagValue');
/**
* Create a binding filter for the tag pattern

@@ -149,2 +165,3 @@ * @param tagPattern - Binding tag name, regexp, or object

for (const t in tagPattern) {
if (tagMap[t] === ANY_TAG_VALUE) return t in b.tagMap;
// One tag name/value does not match

@@ -151,0 +168,0 @@ if (b.tagMap[t] !== tagMap[t]) return false;

@@ -1,2 +0,2 @@

// Copyright IBM Corp. 2018. All Rights Reserved.
// Copyright IBM Corp. 2018,2019. All Rights Reserved.
// Node module: @loopback/context

@@ -3,0 +3,0 @@ // This file is licensed under the MIT License.

@@ -1,2 +0,2 @@

// Copyright IBM Corp. 2017,2019. All Rights Reserved.
// Copyright IBM Corp. 2017,2020. All Rights Reserved.
// Node module: @loopback/context

@@ -3,0 +3,0 @@ // This file is licensed under the MIT License.

@@ -1,2 +0,2 @@

// Copyright IBM Corp. 2019. All Rights Reserved.
// Copyright IBM Corp. 2019,2020. All Rights Reserved.
// Node module: @loopback/context

@@ -3,0 +3,0 @@ // This file is licensed under the MIT License.

@@ -1,2 +0,2 @@

// Copyright IBM Corp. 2020. All Rights Reserved.
// Copyright IBM Corp. 2019,2020. All Rights Reserved.
// Node module: @loopback/context

@@ -3,0 +3,0 @@ // This file is licensed under the MIT License.

@@ -1,2 +0,2 @@

// Copyright IBM Corp. 2019. All Rights Reserved.
// Copyright IBM Corp. 2019,2020. All Rights Reserved.
// Node module: @loopback/context

@@ -3,0 +3,0 @@ // This file is licensed under the MIT License.

@@ -1,2 +0,2 @@

// Copyright IBM Corp. 2017,2019. All Rights Reserved.
// Copyright IBM Corp. 2017,2020. All Rights Reserved.
// Node module: @loopback/context

@@ -37,2 +37,3 @@ // This file is licensed under the MIT License.

BoundValue,
Constructor,
getDeepProperty,

@@ -801,2 +802,16 @@ isPromiseLike,

inspect(options: ContextInspectOptions = {}): JSONObject {
return this._inspect(options, new ClassNameMap());
}
/**
* Inspect the context hierarchy
* @param options - Options for inspect
* @param visitedClasses - A map to keep class to name so that we can have
* different names for classes with colliding names. The situation can happen
* when two classes with the same name are bound in different modules.
*/
private _inspect(
options: ContextInspectOptions,
visitedClasses: ClassNameMap,
): JSONObject {
options = {

@@ -809,3 +824,16 @@ includeParent: true,

for (const [k, v] of this.registry) {
const ctor = v.valueConstructor ?? v.providerConstructor;
let name: string | undefined = undefined;
if (ctor != null) {
name = visitedClasses.visit(ctor);
}
bindings[k] = v.inspect(options);
if (name != null) {
const binding = bindings[k] as JSONObject;
if (v.valueConstructor) {
binding.valueConstructor = name;
} else if (v.providerConstructor) {
binding.providerConstructor = name;
}
}
}

@@ -818,3 +846,3 @@ const json: JSONObject = {

if (this._parent) {
json.parent = this._parent.inspect(options);
json.parent = this._parent._inspect(options, visitedClasses);
}

@@ -826,2 +854,29 @@ return json;

/**
* An internal utility class to handle class name conflicts
*/
class ClassNameMap {
private readonly classes = new Map<Constructor<unknown>, string>();
private readonly nameIndex = new Map<string, number>();
visit(ctor: Constructor<unknown>) {
let name = this.classes.get(ctor);
if (name == null) {
name = ctor.name;
// Now check if the name collides with another class
let index = this.nameIndex.get(name);
if (typeof index === 'number') {
// A conflict is found, mangle the name as `ClassName #1`
this.nameIndex.set(name, ++index);
name = `${name} #${index}`;
} else {
// The name is used for the 1st time
this.nameIndex.set(name, 0);
}
this.classes.set(ctor, name);
}
return name;
}
}
/**
* Options for context.inspect()

@@ -828,0 +883,0 @@ */

@@ -1,2 +0,2 @@

// Copyright IBM Corp. 2017,2018. All Rights Reserved.
// Copyright IBM Corp. 2017,2020. All Rights Reserved.
// Node module: @loopback/context

@@ -3,0 +3,0 @@ // This file is licensed under the MIT License.

@@ -1,2 +0,2 @@

// Copyright IBM Corp. 2017,2018. All Rights Reserved.
// Copyright IBM Corp. 2017,2020. All Rights Reserved.
// Node module: @loopback/context

@@ -3,0 +3,0 @@ // This file is licensed under the MIT License.

@@ -1,2 +0,2 @@

// Copyright IBM Corp. 2019. All Rights Reserved.
// Copyright IBM Corp. 2019,2020. All Rights Reserved.
// Node module: @loopback/context

@@ -3,0 +3,0 @@ // This file is licensed under the MIT License.

@@ -1,2 +0,2 @@

// Copyright IBM Corp. 2019. All Rights Reserved.
// Copyright IBM Corp. 2019,2020. All Rights Reserved.
// Node module: @loopback/context

@@ -3,0 +3,0 @@ // This file is licensed under the MIT License.

@@ -1,2 +0,2 @@

// Copyright IBM Corp. 2018. All Rights Reserved.
// Copyright IBM Corp. 2018,2019. All Rights Reserved.
// Node module: @loopback/context

@@ -3,0 +3,0 @@ // This file is licensed under the MIT License.

@@ -1,2 +0,2 @@

// Copyright IBM Corp. 2018,2019. All Rights Reserved.
// Copyright IBM Corp. 2018,2020. All Rights Reserved.
// Node module: @loopback/context

@@ -3,0 +3,0 @@ // This file is licensed under the MIT License.

@@ -1,2 +0,2 @@

// Copyright IBM Corp. 2018,2019. All Rights Reserved.
// Copyright IBM Corp. 2018,2020. All Rights Reserved.
// Node module: @loopback/context

@@ -3,0 +3,0 @@ // This file is licensed under the MIT License.

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

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

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc