Socket
Socket
Sign inDemoInstall

@loopback/context

Package Overview
Dependencies
14
Maintainers
11
Versions
192
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.17.2 to 3.18.0

8

dist/binding-decorator.js

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

else {
return binding_inspector_1.asBindingTemplate(t);
return (0, binding_inspector_1.asBindingTemplate)(t);
}

@@ -69,3 +69,3 @@ });

const spec = {
templates: [binding_inspector_1.asClassOrProvider(cls), ...templateFunctions],
templates: [(0, binding_inspector_1.asClassOrProvider)(cls), ...templateFunctions],
target: cls,

@@ -89,3 +89,3 @@ };

return (target) => {
if (!binding_inspector_1.isProviderClass(target)) {
if (!(0, binding_inspector_1.isProviderClass)(target)) {
throw new Error(`Target ${target} is not a Provider`);

@@ -95,3 +95,3 @@ }

// Set up the default for providers
binding_inspector_1.asProvider(target),
(0, binding_inspector_1.asProvider)(target),
// Call other template functions

@@ -98,0 +98,0 @@ ...specs)(target);

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

const metadata_1 = require("@loopback/metadata");
const debug_1 = tslib_1.__importDefault(require("debug"));
const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
const binding_1 = require("./binding");
const keys_1 = require("./keys");
const debug = debug_1.default('loopback:context:binding-inspector');
const debug = (0, debug_1.default)('loopback:context:binding-inspector');
/**

@@ -59,3 +59,3 @@ * Metadata key for binding metadata

}
else if (binding_1.isDynamicValueProviderClass(target)) {
else if ((0, binding_1.isDynamicValueProviderClass)(target)) {
binding.toDynamicValue(target).tag(keys_1.ContextTags.DYNAMIC_VALUE_PROVIDER, {

@@ -62,0 +62,0 @@ [keys_1.ContextTags.TYPE]: keys_1.ContextTags.DYNAMIC_VALUE_PROVIDER,

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

const prefix = namespace ? `${namespace}.` : '';
const name = unique_id_1.generateUniqueId();
const name = (0, unique_id_1.generateUniqueId)();
return BindingKey.create(`${prefix}${name}`);

@@ -114,0 +114,0 @@ }

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

const tslib_1 = require("tslib");
const debug_1 = tslib_1.__importDefault(require("debug"));
const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
const events_1 = require("events");

@@ -21,3 +21,3 @@ const binding_inspector_1 = require("./binding-inspector");

const value_promise_1 = require("./value-promise");
const debug = debug_1.default('loopback:context:binding');
const debug = (0, debug_1.default)('loopback:context:binding');
/**

@@ -182,3 +182,3 @@ * Scope for binding values

function toValueFactory(provider) {
return resolutionCtx => invocation_1.invokeMethod(provider, 'value', resolutionCtx.context, [], {
return resolutionCtx => (0, invocation_1.invokeMethod)(provider, 'value', resolutionCtx.context, [], {
skipInterceptors: true,

@@ -302,3 +302,3 @@ session: resolutionCtx.options.session,

}
const options = resolution_session_1.asResolutionOptions(optionsOrSession);
const options = (0, resolution_session_1.asResolutionOptions)(optionsOrSession);
const resolutionCtx = this.getResolutionContext(ctx, options);

@@ -497,3 +497,3 @@ if (resolutionCtx == null)

to(value) {
if (value_promise_1.isPromiseLike(value)) {
if ((0, value_promise_1.isPromiseLike)(value)) {
// Promises are a construct primarily intended for flow control:

@@ -601,4 +601,4 @@ // In an algorithm with steps 1 and 2, we want to wait for the outcome

this._setValueGetter(resolutionCtx => {
const providerOrPromise = resolver_1.instantiateClass(providerClass, resolutionCtx.context, resolutionCtx.options.session);
const value = value_promise_1.transformValueOrPromise(providerOrPromise, p => p.value());
const providerOrPromise = (0, resolver_1.instantiateClass)(providerClass, resolutionCtx.context, resolutionCtx.options.session);
const value = (0, value_promise_1.transformValueOrPromise)(providerOrPromise, p => p.value());
return Binding.valueOrProxy(resolutionCtx, value);

@@ -625,3 +625,3 @@ });

this._setValueGetter(resolutionCtx => {
const value = resolver_1.instantiateClass(ctor, resolutionCtx.context, resolutionCtx.options.session);
const value = (0, resolver_1.instantiateClass)(ctor, resolutionCtx.context, resolutionCtx.options.session);
return Binding.valueOrProxy(resolutionCtx, value);

@@ -655,3 +655,3 @@ });

toInjectable(ctor) {
this.apply(binding_inspector_1.bindingTemplateFor(ctor));
this.apply((0, binding_inspector_1.bindingTemplateFor)(ctor));
return this;

@@ -743,3 +743,3 @@ }

if (options.includeInjections) {
const injections = inject_1.inspectInjections(this);
const injections = (0, inject_1.inspectInjections)(this);
if (Object.keys(injections).length)

@@ -789,6 +789,6 @@ json.injections = injections;

function createInterceptionProxyFromInstance(instOrPromise, context, session) {
return value_promise_1.transformValueOrPromise(instOrPromise, inst => {
return (0, value_promise_1.transformValueOrPromise)(instOrPromise, inst => {
if (typeof inst !== 'object' || inst == null)
return inst;
return interception_proxy_1.createProxyWithInterceptors(
return (0, interception_proxy_1.createProxyWithInterceptors)(
// Cast inst from `T` to `object`

@@ -795,0 +795,0 @@ inst, context, session);

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

const tslib_1 = require("tslib");
const debug_1 = tslib_1.__importDefault(require("debug"));
const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
const events_1 = require("events");
const p_event_1 = require("p-event");
const debug = debug_1.default('loopback:context:subscription');
const debug = (0, debug_1.default)('loopback:context:subscription');
/**

@@ -139,3 +139,3 @@ * An implementation of `Subscription` interface for context events

// Create an async iterator for the `notification` event as a queue
this.notificationQueue = p_event_1.iterator(this, 'notification', {
this.notificationQueue = (0, p_event_1.iterator)(this, 'notification', {
// Do not end the iterator if an error event is emitted on the

@@ -239,3 +239,3 @@ // subscription manager

return;
await p_event_1.multiple(this, 'observersNotified', { count, timeout });
await (0, p_event_1.multiple)(this, 'observersNotified', { count, timeout });
}

@@ -242,0 +242,0 @@ /**

@@ -101,3 +101,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 : (0, binding_filter_1.filterByTag)(tag);
const matched = new Set(Array.from(bindingsByTag).filter(filter));

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

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

import { Getter } from './inject';
import { ResolutionSession } from './resolution-session';
import { ResolutionOptions, ResolutionOptionsOrSession, ResolutionSession } from './resolution-session';
import { ValueOrPromise } from './value-promise';

@@ -43,2 +43,3 @@ /**

readonly comparator?: BindingComparator | undefined;
private resolutionOptions?;
/**

@@ -59,3 +60,3 @@ * An array of cached bindings that matches the binding filter

*/
constructor(context: Context, filter: BindingFilter, comparator?: BindingComparator | undefined);
constructor(context: Context, filter: BindingFilter, comparator?: BindingComparator | undefined, resolutionOptions?: Omit<ResolutionOptions, "session"> | undefined);
/**

@@ -99,3 +100,3 @@ * Update the cached values keyed by binding

*/
resolve(session?: ResolutionSession): ValueOrPromise<T[]>;
resolve(session?: ResolutionOptionsOrSession): ValueOrPromise<T[]>;
/**

@@ -105,11 +106,11 @@ * Get the list of resolved values. If they are not cached, it tries to find

*/
values(session?: ResolutionSession): Promise<T[]>;
values(session?: ResolutionOptionsOrSession): Promise<T[]>;
/**
* As a `Getter` function
*/
asGetter(session?: ResolutionSession): Getter<T[]>;
asGetter(session?: ResolutionOptionsOrSession): Getter<T[]>;
/**
* Get the single value
*/
singleValue(session?: ResolutionSession): Promise<T | undefined>;
singleValue(session?: ResolutionOptionsOrSession): Promise<T | undefined>;
/**

@@ -213,2 +214,2 @@ * The "bind" event is emitted when a new binding is added to the view.

*/
export declare function createViewGetter<T = unknown>(ctx: Context, bindingFilter: BindingFilter, bindingComparator?: BindingComparator, session?: ResolutionSession): Getter<T[]>;
export declare function createViewGetter<T = unknown>(ctx: Context, bindingFilter: BindingFilter, bindingComparator?: BindingComparator, session?: ResolutionOptionsOrSession): Getter<T[]>;

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

const tslib_1 = require("tslib");
const debug_1 = tslib_1.__importDefault(require("debug"));
const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
const events_1 = require("events");

@@ -15,4 +15,4 @@ const util_1 = require("util");

const value_promise_1 = require("./value-promise");
const debug = debug_1.default('loopback:context:view');
const nextTick = util_1.promisify(process.nextTick);
const debug = (0, debug_1.default)('loopback:context:view');
const nextTick = (0, util_1.promisify)(process.nextTick);
/**

@@ -41,3 +41,3 @@ * `ContextView` provides a view for a given context chain to maintain a live

*/
constructor(context, filter, comparator) {
constructor(context, filter, comparator, resolutionOptions) {
super();

@@ -47,2 +47,3 @@ this.context = context;

this.comparator = comparator;
this.resolutionOptions = resolutionOptions;
}

@@ -157,10 +158,16 @@ /**

const bindings = this.bindings;
let result = value_promise_1.resolveList(bindings, b => {
return b.getValue(this.context, resolution_session_1.ResolutionSession.fork(session));
let result = (0, value_promise_1.resolveList)(bindings, b => {
const options = {
...this.resolutionOptions,
...(0, resolution_session_1.asResolutionOptions)(session),
};
options.session = resolution_session_1.ResolutionSession.fork(options.session);
return b.getValue(this.context, options);
});
if (value_promise_1.isPromiseLike(result)) {
if ((0, value_promise_1.isPromiseLike)(result)) {
result = result.then(values => {
this.updateCachedValues(values);
this.emit('resolve', values);
return values;
const list = values.filter(v => v != null);
this.updateCachedValues(list);
this.emit('resolve', list);
return list;
});

@@ -170,4 +177,5 @@ }

// Clone the array so that the cached values won't be mutated
this.updateCachedValues(result);
this.emit('resolve', result);
const list = (result = result.filter(v => v != null));
this.updateCachedValues(list);
this.emit('resolve', list);
}

@@ -232,7 +240,8 @@ return result;

}
const view = new ContextView(ctx, bindingFilter, bindingComparator);
const options = (0, resolution_session_1.asResolutionOptions)(session);
const view = new ContextView(ctx, bindingFilter, bindingComparator, options);
view.open();
return view.asGetter(session);
return view.asGetter(options);
}
exports.createViewGetter = createViewGetter;
//# sourceMappingURL=context-view.js.map

@@ -229,4 +229,5 @@ /// <reference types="node" />

* @param comparator - A function to sort matched bindings
* @param options - Resolution options
*/
createView<T = unknown>(filter: BindingFilter, comparator?: BindingComparator): ContextView<T>;
createView<T = unknown>(filter: BindingFilter, comparator?: BindingComparator, options?: Omit<ResolutionOptions, 'session'>): ContextView<T>;
/**

@@ -233,0 +234,0 @@ * Check if a binding exists with the given key in the local context without

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

const tslib_1 = require("tslib");
const debug_1 = tslib_1.__importDefault(require("debug"));
const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
const events_1 = require("events");

@@ -72,3 +72,3 @@ const binding_1 = require("./binding");

this.subscriptionManager = new context_subscription_1.ContextSubscriptionManager(this);
this._debug = debug_1.default(this.getDebugNamespace());
this._debug = (0, debug_1.default)(this.getDebugNamespace());
}

@@ -97,3 +97,3 @@ /**

generateName() {
const id = unique_id_1.generateUniqueId();
const id = (0, unique_id_1.generateUniqueId)();
if (this.constructor === Context)

@@ -255,3 +255,3 @@ return id;

const valueOrPromise = this.getConfigAsValueOrPromise(key, propertyPath, resolutionOptions);
if (value_promise_1.isPromiseLike(valueOrPromise)) {
if ((0, value_promise_1.isPromiseLike)(valueOrPromise)) {
const prop = propertyPath ? ` property ${propertyPath}` : '';

@@ -329,5 +329,6 @@ throw new Error(`Cannot get config${prop} for ${key} synchronously: the value is a promise`);

* @param comparator - A function to sort matched bindings
* @param options - Resolution options
*/
createView(filter, comparator) {
const view = new context_view_1.ContextView(this, filter, comparator);
createView(filter, comparator, options) {
const view = new context_view_1.ContextView(this, filter, comparator, options);
view.open();

@@ -458,7 +459,7 @@ return view;

// Optimize if the binding filter is for tags
if (typeof pattern === 'function' && binding_filter_1.isBindingTagFilter(pattern)) {
if (typeof pattern === 'function' && (0, binding_filter_1.isBindingTagFilter)(pattern)) {
return this._findByTagIndex(pattern.bindingTagPattern);
}
const bindings = [];
const filter = binding_filter_1.filterByKey(pattern);
const filter = (0, binding_filter_1.filterByKey)(pattern);
for (const b of this.registry.values()) {

@@ -486,3 +487,3 @@ if (filter(b))

findByTag(tagFilter) {
return this.find(binding_filter_1.filterByTag(tagFilter));
return this.find((0, binding_filter_1.filterByTag)(tagFilter));
}

@@ -517,3 +518,3 @@ /**

const valueOrPromise = this.getValueOrPromise(keyWithPath, optionsOrSession);
if (value_promise_1.isPromiseLike(valueOrPromise)) {
if ((0, value_promise_1.isPromiseLike)(valueOrPromise)) {
throw new Error(`Cannot get ${keyWithPath} synchronously: the value is a promise`);

@@ -588,3 +589,3 @@ }

const { key, propertyPath } = binding_key_1.BindingKey.parseKeyWithPath(keyWithPath);
const options = resolution_session_1.asResolutionOptions(optionsOrSession);
const options = (0, resolution_session_1.asResolutionOptions)(optionsOrSession);
const binding = this.getBinding(key, { optional: true });

@@ -603,3 +604,3 @@ if (binding == null) {

? boundValue
: value_promise_1.transformValueOrPromise(boundValue, v => value_promise_1.getDeepProperty(v, propertyPath));
: (0, value_promise_1.transformValueOrPromise)(boundValue, v => (0, value_promise_1.getDeepProperty)(v, propertyPath));
}

@@ -606,0 +607,0 @@ /**

@@ -34,28 +34,28 @@ "use strict";

*/
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-event"), exports);
tslib_1.__exportStar(require("./context-observer"), 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("./json-types"), exports);
tslib_1.__exportStar(require("./keys"), exports);
tslib_1.__exportStar(require("./provider"), exports);
tslib_1.__exportStar(require("./resolution-session"), exports);
tslib_1.__exportStar(require("./resolver"), exports);
tslib_1.__exportStar(require("./unique-id"), exports);
tslib_1.__exportStar(require("./value-promise"), exports);
(0, tslib_1.__exportStar)(require("@loopback/metadata"), exports);
(0, tslib_1.__exportStar)(require("./binding"), exports);
(0, tslib_1.__exportStar)(require("./binding-config"), exports);
(0, tslib_1.__exportStar)(require("./binding-decorator"), exports);
(0, tslib_1.__exportStar)(require("./binding-filter"), exports);
(0, tslib_1.__exportStar)(require("./binding-inspector"), exports);
(0, tslib_1.__exportStar)(require("./binding-key"), exports);
(0, tslib_1.__exportStar)(require("./binding-sorter"), exports);
(0, tslib_1.__exportStar)(require("./context"), exports);
(0, tslib_1.__exportStar)(require("./context-event"), exports);
(0, tslib_1.__exportStar)(require("./context-observer"), exports);
(0, tslib_1.__exportStar)(require("./context-subscription"), exports);
(0, tslib_1.__exportStar)(require("./context-view"), exports);
(0, tslib_1.__exportStar)(require("./inject"), exports);
(0, tslib_1.__exportStar)(require("./inject-config"), exports);
(0, tslib_1.__exportStar)(require("./interception-proxy"), exports);
(0, tslib_1.__exportStar)(require("./interceptor"), exports);
(0, tslib_1.__exportStar)(require("./interceptor-chain"), exports);
(0, tslib_1.__exportStar)(require("./invocation"), exports);
(0, tslib_1.__exportStar)(require("./json-types"), exports);
(0, tslib_1.__exportStar)(require("./keys"), exports);
(0, tslib_1.__exportStar)(require("./provider"), exports);
(0, tslib_1.__exportStar)(require("./resolution-session"), exports);
(0, tslib_1.__exportStar)(require("./resolver"), exports);
(0, tslib_1.__exportStar)(require("./unique-id"), exports);
(0, tslib_1.__exportStar)(require("./value-promise"), exports);
//# sourceMappingURL=index.js.map

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

metadata = Object.assign({ propertyPath, decorator: '@config', optional: true }, metadata);
return inject_1.inject('', metadata, resolveFromConfig);
return (0, inject_1.inject)('', metadata, resolveFromConfig);
}

@@ -70,3 +70,3 @@ exports.config = config;

metadata = Object.assign({ propertyPath, decorator: '@config.getter', optional: true }, metadata);
return inject_1.inject('', metadata, resolveAsGetterFromConfig);
return (0, inject_1.inject)('', metadata, resolveAsGetterFromConfig);
};

@@ -86,3 +86,3 @@ /**

metadata = Object.assign({ propertyPath, decorator: '@config.view', optional: true }, metadata);
return inject_1.inject('', metadata, resolveAsViewFromConfig);
return (0, inject_1.inject)('', metadata, resolveAsViewFromConfig);
};

@@ -132,3 +132,3 @@ })(config = exports.config || (exports.config = {}));

function resolveAsGetterFromConfig(ctx, injection, session) {
inject_1.assertTargetType(injection, Function, 'Getter function');
(0, inject_1.assertTargetType)(injection, Function, 'Getter function');
const bindingKey = getTargetBindingKey(injection, session);

@@ -155,3 +155,3 @@ // We need to clone the session for the getter as it will be resolved later

function resolveAsViewFromConfig(ctx, injection, session) {
inject_1.assertTargetType(injection, context_view_1.ContextView);
(0, inject_1.assertTargetType)(injection, context_view_1.ContextView);
const bindingKey = getTargetBindingKey(injection, session);

@@ -183,5 +183,5 @@ // Return `undefined` if no current binding is present

return configValues;
return configValues.map(v => value_promise_1.getDeepProperty(v, propertyPath));
return configValues.map(v => (0, value_promise_1.getDeepProperty)(v, propertyPath));
}
}
//# sourceMappingURL=inject-config.js.map

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

*/
export interface InjectionMetadata extends ResolutionOptions {
export interface InjectionMetadata extends Omit<ResolutionOptions, 'session'> {
/**

@@ -29,0 +29,0 @@ * Name of the decorator function, such as `@inject` or `@inject.setter`.

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

metadata = Object.assign({ decorator: '@inject.getter' }, metadata);
return inject(bindingSelector, metadata, binding_filter_1.isBindingAddress(bindingSelector)
return inject(bindingSelector, metadata, (0, binding_filter_1.isBindingAddress)(bindingSelector)
? resolveAsGetter

@@ -199,3 +199,3 @@ : resolveAsGetterByFilter);

metadata = Object.assign({ decorator: '@inject.tag', tag: bindingTag }, metadata);
return inject(binding_filter_1.filterByTag(bindingTag), metadata);
return inject((0, binding_filter_1.filterByTag)(bindingTag), metadata);
};

@@ -278,3 +278,3 @@ /**

const bindingSelector = injection.bindingSelector;
if (!binding_filter_1.isBindingAddress(bindingSelector)) {
if (!(0, binding_filter_1.isBindingAddress)(bindingSelector)) {
throw new Error(`@inject.setter (${targetName}) does not allow BindingFilter.`);

@@ -294,3 +294,3 @@ }

const bindingSelector = injection.bindingSelector;
if (!binding_filter_1.isBindingAddress(bindingSelector)) {
if (!(0, binding_filter_1.isBindingAddress)(bindingSelector)) {
throw new Error(`@inject.binding (${targetName}) does not allow BindingFilter.`);

@@ -439,3 +439,3 @@ }

const bindingFilter = injection.bindingSelector;
return context_view_1.createViewGetter(ctx, bindingFilter, injection.metadata.bindingComparator, session);
return (0, context_view_1.createViewGetter)(ctx, bindingFilter, injection.metadata.bindingComparator, session);
}

@@ -502,7 +502,7 @@ /**

}
if (binding_filter_1.isBindingAddress(injectionInfo.bindingSelector)) {
if ((0, binding_filter_1.isBindingAddress)(injectionInfo.bindingSelector)) {
// Binding key
descriptor.bindingKey = injectionInfo.bindingSelector.toString();
}
else if (binding_filter_1.isBindingTagFilter(injectionInfo.bindingSelector)) {
else if ((0, binding_filter_1.isBindingTagFilter)(injectionInfo.bindingSelector)) {
// Binding tag filter

@@ -509,0 +509,0 @@ descriptor.bindingTagPattern = JSON.parse(JSON.stringify(injectionInfo.bindingSelector.bindingTagPattern));

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

var _a;
return interceptor_1.invokeMethodWithInterceptors(this.context, target, propertyName, args, {
return (0, interceptor_1.invokeMethodWithInterceptors)(this.context, target, propertyName, args, {
source: (_a = this.source) !== null && _a !== void 0 ? _a : (this.session && new ProxySource(this.session)),

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

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

const tslib_1 = require("tslib");
const debug_1 = tslib_1.__importDefault(require("debug"));
const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
const value_promise_1 = require("./value-promise");
const debug = debug_1.default('loopback:context:interceptor-chain');
const debug = (0, debug_1.default)('loopback:context:interceptor-chain');
/**

@@ -106,3 +106,3 @@ * Invocation state of an interceptor chain

const interceptorFn = this.loadInterceptor(interceptor);
return value_promise_1.transformValueOrPromise(interceptorFn, fn => {
return (0, value_promise_1.transformValueOrPromise)(interceptorFn, fn => {
/* istanbul ignore if */

@@ -109,0 +109,0 @@ if (debug.enabled) {

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

const metadata_1 = require("@loopback/metadata");
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 binding_decorator_1 = require("./binding-decorator");

@@ -21,3 +21,3 @@ const binding_inspector_1 = require("./binding-inspector");

const value_promise_1 = require("./value-promise");
const debug = debug_1.default('loopback:context:interceptor');
const debug = (0, debug_1.default)('loopback:context:interceptor');
/**

@@ -71,3 +71,3 @@ * A specialized InvocationContext for interceptors

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

@@ -119,3 +119,3 @@ /**

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

@@ -240,10 +240,10 @@ exports.globalInterceptor = globalInterceptor;

// `invokeMethodWithInterceptors`
assert_1.default(!options.skipInterceptors, 'skipInterceptors is not allowed');
(0, assert_1.default)(!options.skipInterceptors, 'skipInterceptors is not allowed');
const invocationCtx = new InterceptedInvocationContext(context, target, methodName, args, options.source);
invocationCtx.assertMethodExists();
return value_promise_1.tryWithFinally(() => {
return (0, value_promise_1.tryWithFinally)(() => {
const interceptors = invocationCtx.loadInterceptors();
const targetMethodInvoker = () => invocationCtx.invokeTargetMethod(options);
interceptors.push(targetMethodInvoker);
return interceptor_chain_1.invokeInterceptors(invocationCtx, interceptors);
return (0, interceptor_chain_1.invokeInterceptors)(invocationCtx, interceptors);
}, () => invocationCtx.close());

@@ -270,4 +270,4 @@ }

let binding;
if (binding_inspector_1.isProviderClass(interceptor)) {
binding = binding_inspector_1.createBindingFromClass(interceptor, {
if ((0, binding_inspector_1.isProviderClass)(interceptor)) {
binding = (0, binding_inspector_1.createBindingFromClass)(interceptor, {
defaultNamespace: namespace,

@@ -274,0 +274,0 @@ ...options,

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

const metadata_1 = require("@loopback/metadata");
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 context_1 = require("./context");

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

const value_promise_1 = require("./value-promise");
const debug = debug_1.default('loopback:context:invocation');
const debug = (0, debug_1.default)('loopback:context:invocation');
const getTargetName = metadata_1.DecoratorFactory.getTargetName;

@@ -73,3 +73,3 @@ /**

const targetName = getTargetName(this.target, this.methodName);
assert_1.default(false, `Method ${targetName} not found`);
(0, assert_1.default)(false, `Method ${targetName} not found`);
}

@@ -113,3 +113,3 @@ return targetWithMethods;

// Invoke the target method with interception but no injection
return interceptor_1.invokeMethodWithInterceptors(ctx, target, method, nonInjectedArgs, options);
return (0, interceptor_1.invokeMethodWithInterceptors)(ctx, target, method, nonInjectedArgs, options);
}

@@ -134,6 +134,6 @@ exports.invokeMethod = invokeMethod;

}
const argsOrPromise = resolver_1.resolveInjectedArguments(target, method, ctx, session, nonInjectedArgs);
const argsOrPromise = (0, resolver_1.resolveInjectedArguments)(target, method, ctx, session, nonInjectedArgs);
const targetWithMethods = target;
assert_1.default(typeof targetWithMethods[method] === 'function', `Method ${method} not found`);
return value_promise_1.transformValueOrPromise(argsOrPromise, args => {
(0, assert_1.default)(typeof targetWithMethods[method] === 'function', `Method ${method} not found`);
return (0, value_promise_1.transformValueOrPromise)(argsOrPromise, args => {
/* istanbul ignore if */

@@ -140,0 +140,0 @@ if (debug.enabled) {

@@ -10,5 +10,5 @@ "use strict";

const metadata_1 = require("@loopback/metadata");
const debug_1 = tslib_1.__importDefault(require("debug"));
const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
const value_promise_1 = require("./value-promise");
const debugSession = debug_1.default('loopback:context:resolver:session');
const debugSession = (0, debug_1.default)('loopback:context:resolver:session');
const getTargetName = metadata_1.DecoratorFactory.getTargetName;

@@ -63,3 +63,3 @@ /**

session.pushBinding(binding);
return value_promise_1.tryWithFinally(() => action(session), () => session.popBinding());
return (0, value_promise_1.tryWithFinally)(() => action(session), () => session.popBinding());
}

@@ -74,3 +74,3 @@ /**

session.pushInjection(injection);
return value_promise_1.tryWithFinally(() => action(session), () => session.popInjection());
return (0, value_promise_1.tryWithFinally)(() => action(session), () => session.popInjection());
}

@@ -77,0 +77,0 @@ /**

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

const metadata_1 = require("@loopback/metadata");
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 binding_filter_1 = require("./binding-filter");

@@ -17,3 +17,3 @@ const inject_1 = require("./inject");

const value_promise_1 = require("./value-promise");
const debug = debug_1.default('loopback:context:resolver');
const debug = (0, debug_1.default)('loopback:context:resolver');
const getTargetName = metadata_1.DecoratorFactory.getTargetName;

@@ -44,3 +44,3 @@ /**

const propertiesOrPromise = resolveInjectedProperties(ctor, ctx, session);
const inst = value_promise_1.transformValueOrPromise(argsOrPromise, args => {
const inst = (0, value_promise_1.transformValueOrPromise)(argsOrPromise, args => {
/* istanbul ignore if */

@@ -52,3 +52,3 @@ if (debug.enabled) {

});
return value_promise_1.transformValueOrPromise(propertiesOrPromise, props => {
return (0, value_promise_1.transformValueOrPromise)(propertiesOrPromise, props => {
/* istanbul ignore if */

@@ -58,3 +58,3 @@ if (debug.enabled) {

}
return value_promise_1.transformValueOrPromise(inst, obj => Object.assign(obj, props));
return (0, value_promise_1.transformValueOrPromise)(inst, obj => Object.assign(obj, props));
});

@@ -106,3 +106,3 @@ }

// Default to resolve the value from the context by binding key
assert_1.default(binding_filter_1.isBindingAddress(injection.bindingSelector), 'The binding selector must be an address (string or BindingKey)');
(0, assert_1.default)((0, binding_filter_1.isBindingAddress)(injection.bindingSelector), 'The binding selector must be an address (string or BindingKey)');
const key = injection.bindingSelector;

@@ -143,3 +143,3 @@ const options = {

if (method) {
assert_1.default(typeof targetWithMethods[method] === 'function', `Method ${method} not found`);
(0, assert_1.default)(typeof targetWithMethods[method] === 'function', `Method ${method} not found`);
}

@@ -150,3 +150,3 @@ // NOTE: the array may be sparse, i.e.

// [ , 'key1', , 'key2']
const injectedArgs = inject_1.describeInjectedArguments(target, method);
const injectedArgs = (0, inject_1.describeInjectedArguments)(target, method);
const extraArgs = nonInjectedArgs !== null && nonInjectedArgs !== void 0 ? nonInjectedArgs : [];

@@ -165,3 +165,3 @@ let argLength = metadata_1.DecoratorFactory.getNumberOfParameters(target, method);

let nonInjectedIndex = 0;
return value_promise_1.resolveList(new Array(argLength), (val, ix) => {
return (0, value_promise_1.resolveList)(new Array(argLength), (val, ix) => {
// The `val` argument is not used as the resolver only uses `injectedArgs`

@@ -206,4 +206,4 @@ // and `extraArgs` to return the new value

}
const injectedProperties = inject_1.describeInjectedProperties(constructor.prototype);
return value_promise_1.resolveMap(injectedProperties, injection => resolve(ctx, injection,
const injectedProperties = (0, inject_1.describeInjectedProperties)(constructor.prototype);
return (0, value_promise_1.resolveMap)(injectedProperties, injection => resolve(ctx, injection,
// Clone the session so that multiple properties can be resolved in parallel

@@ -210,0 +210,0 @@ resolution_session_1.ResolutionSession.fork(session)));

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

const tslib_1 = require("tslib");
const hyperid_1 = tslib_1.__importDefault(require("hyperid"));
const hyperid_1 = (0, tslib_1.__importDefault)(require("hyperid"));
/**

@@ -18,3 +18,3 @@ * Generate a (globally) unique identifier in a very fast way.

*/
exports.generateUniqueId = hyperid_1.default({
exports.generateUniqueId = (0, hyperid_1.default)({
fixedLength: false,

@@ -21,0 +21,0 @@ urlSafe: true,

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

function uuid() {
return uuid_1.v4();
return (0, uuid_1.v4)();
}

@@ -271,0 +271,0 @@ exports.uuid = uuid;

{
"name": "@loopback/context",
"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",
"version": "3.17.2",
"version": "3.18.0",
"keywords": [

@@ -46,3 +46,3 @@ "LoopBack",

"dependencies": {
"@loopback/metadata": "^3.3.3",
"@loopback/metadata": "^3.3.4",
"@types/debug": "^4.1.7",

@@ -56,5 +56,5 @@ "debug": "^4.3.2",

"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/bluebird": "^3.5.36",

@@ -65,3 +65,3 @@ "@types/node": "^10.17.60",

},
"gitHead": "1df36bb1ee2e513d9e197bd6010c4cfb296d50b8"
"gitHead": "d9a29c85dbe38f12ba219d8c495cf6038bbc3590"
}

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

import {Getter} from './inject';
import {ResolutionSession} from './resolution-session';
import {
asResolutionOptions,
ResolutionOptions,
ResolutionOptionsOrSession,
ResolutionSession,
} from './resolution-session';
import {isPromiseLike, resolveList, ValueOrPromise} from './value-promise';

@@ -73,2 +78,3 @@ const debug = debugFactory('loopback:context:view');

public readonly comparator?: BindingComparator,
private resolutionOptions?: Omit<ResolutionOptions, 'session'>,
) {

@@ -193,3 +199,3 @@ super();

*/
resolve(session?: ResolutionSession): ValueOrPromise<T[]> {
resolve(session?: ResolutionOptionsOrSession): ValueOrPromise<T[]> {
debug('Resolving values');

@@ -201,16 +207,23 @@ if (this._cachedValues != null) {

let result = resolveList(bindings, b => {
return b.getValue(this.context, ResolutionSession.fork(session));
const options = {
...this.resolutionOptions,
...asResolutionOptions(session),
};
options.session = ResolutionSession.fork(options.session);
return b.getValue(this.context, options);
});
if (isPromiseLike(result)) {
result = result.then(values => {
this.updateCachedValues(values);
this.emit('resolve', values);
return values;
const list = values.filter(v => v != null) as T[];
this.updateCachedValues(list);
this.emit('resolve', list);
return list;
});
} else {
// Clone the array so that the cached values won't be mutated
this.updateCachedValues(result);
this.emit('resolve', result);
const list = (result = result.filter(v => v != null) as T[]);
this.updateCachedValues(list);
this.emit('resolve', list);
}
return result;
return result as ValueOrPromise<T[]>;
}

@@ -222,3 +235,3 @@

*/
async values(session?: ResolutionSession): Promise<T[]> {
async values(session?: ResolutionOptionsOrSession): Promise<T[]> {
debug('Reading values');

@@ -236,3 +249,3 @@ // Wait for the next tick so that context event notification can be emitted

*/
asGetter(session?: ResolutionSession): Getter<T[]> {
asGetter(session?: ResolutionOptionsOrSession): Getter<T[]> {
return () => this.values(session);

@@ -244,3 +257,5 @@ }

*/
async singleValue(session?: ResolutionSession): Promise<T | undefined> {
async singleValue(
session?: ResolutionOptionsOrSession,
): Promise<T | undefined> {
const values = await this.values(session);

@@ -399,3 +414,3 @@ if (values.length === 0) return undefined;

bindingComparator?: BindingComparator,
session?: ResolutionSession,
session?: ResolutionOptionsOrSession,
): Getter<T[]>;

@@ -415,3 +430,3 @@

bindingComparatorOrSession?: BindingComparator | ResolutionSession,
session?: ResolutionSession,
session?: ResolutionOptionsOrSession,
): Getter<T[]> {

@@ -425,5 +440,11 @@ let bindingComparator: BindingComparator | undefined = undefined;

const view = new ContextView<T>(ctx, bindingFilter, bindingComparator);
const options = asResolutionOptions(session);
const view = new ContextView<T>(
ctx,
bindingFilter,
bindingComparator,
options,
);
view.open();
return view.asGetter(session);
return view.asGetter(options);
}

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

* @param comparator - A function to sort matched bindings
* @param options - Resolution options
*/

@@ -449,4 +450,5 @@ createView<T = unknown>(

comparator?: BindingComparator,
options?: Omit<ResolutionOptions, 'session'>,
) {
const view = new ContextView<T>(this, filter, comparator);
const view = new ContextView<T>(this, filter, comparator, options);
view.open();

@@ -453,0 +455,0 @@ return view;

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

*/
export interface InjectionMetadata extends ResolutionOptions {
export interface InjectionMetadata extends Omit<ResolutionOptions, 'session'> {
/**

@@ -73,0 +73,0 @@ * Name of the decorator function, such as `@inject` or `@inject.setter`.

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc