New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@wendellhu/redi

Package Overview
Dependencies
Maintainers
1
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wendellhu/redi - npm Package Compare versions

Comparing version 0.9.0 to 0.10.0

118

dist/redi.js

@@ -61,3 +61,3 @@ (function (global, factory) {

var __extends$5 = (undefined && undefined.__extends) || (function () {
var __extends$4 = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {

@@ -78,3 +78,3 @@ extendStatics = Object.setPrototypeOf ||

var RediError = /** @class */ (function (_super) {
__extends$5(RediError, _super);
__extends$4(RediError, _super);
function RediError(message) {

@@ -86,3 +86,3 @@ return _super.call(this, "[redi]: ".concat(message)) || this;

var __extends$4 = (undefined && undefined.__extends) || (function () {
var __extends$3 = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {

@@ -105,6 +105,8 @@ extendStatics = Object.setPrototypeOf ||

var DependencyDescriptorNotFoundError = /** @class */ (function (_super) {
__extends$4(DependencyDescriptorNotFoundError, _super);
__extends$3(DependencyDescriptorNotFoundError, _super);
function DependencyDescriptorNotFoundError(index, target) {
var _this = this;
var msg = "Could not find dependency registered on the ".concat(index + 1, " parameter of the constructor of \"").concat(prettyPrintIdentifier(target), "\".");
return _super.call(this, msg) || this;
_this = _super.call(this, msg) || this;
return _this;
}

@@ -114,6 +116,8 @@ return DependencyDescriptorNotFoundError;

var IdentifierUndefinedError = /** @class */ (function (_super) {
__extends$4(IdentifierUndefinedError, _super);
__extends$3(IdentifierUndefinedError, _super);
function IdentifierUndefinedError(target, index) {
var _this = this;
var msg = "It seems that you register \"undefined\" as dependency on the ".concat(index + 1, " parameter of \"").concat(prettyPrintIdentifier(target), "\". Please make sure that there is not cyclic dependency among your TypeScript files, or consider using \"forwardRef\".");
return _super.call(this, msg) || this;
_this = _super.call(this, msg) || this;
return _this;
}

@@ -197,3 +201,3 @@ return IdentifierUndefinedError;

var __extends$3 = (undefined && undefined.__extends) || (function () {
var __extends$2 = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {

@@ -214,6 +218,8 @@ extendStatics = Object.setPrototypeOf ||

var QuantityCheckError = /** @class */ (function (_super) {
__extends$3(QuantityCheckError, _super);
__extends$2(QuantityCheckError, _super);
function QuantityCheckError(id, quantity, actual) {
var _this = this;
var msg = "Expect \"".concat(quantity, "\" dependency items for id \"").concat(prettyPrintIdentifier(id), "\" but get ").concat(actual, ".");
return _super.call(this, msg) || this;
_this = _super.call(this, msg) || this;
return _this;
}

@@ -280,3 +286,3 @@ return QuantityCheckError;

var __extends$2 = (undefined && undefined.__extends) || (function () {
var __extends$1 = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {

@@ -300,6 +306,8 @@ extendStatics = Object.setPrototypeOf ||

var DependencyNotFoundError = /** @class */ (function (_super) {
__extends$2(DependencyNotFoundError, _super);
__extends$1(DependencyNotFoundError, _super);
function DependencyNotFoundError(id) {
var _this = this;
var msg = "Cannot find \"".concat(prettyPrintIdentifier(id), "\" registered by any injector.");
return _super.call(this, msg) || this;
_this = _super.call(this, msg) || this;
return _this;
}

@@ -594,3 +602,3 @@ return DependencyNotFoundError;

var __extends$1 = (undefined && undefined.__extends) || (function () {
var __extends = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {

@@ -633,3 +641,3 @@ extendStatics = Object.setPrototypeOf ||

var CircularDependencyError = /** @class */ (function (_super) {
__extends$1(CircularDependencyError, _super);
__extends(CircularDependencyError, _super);
function CircularDependencyError(id) {

@@ -641,3 +649,3 @@ return _super.call(this, "Detecting cyclic dependency. The last identifier is \"".concat(prettyPrintIdentifier(id), "\".")) || this;

var InjectorAlreadyDisposedError = /** @class */ (function (_super) {
__extends$1(InjectorAlreadyDisposedError, _super);
__extends(InjectorAlreadyDisposedError, _super);
function InjectorAlreadyDisposedError() {

@@ -649,3 +657,3 @@ return _super.call(this, 'Injector cannot be accessed after it was disposed.') || this;

var AsyncItemReturnAsyncItemError = /** @class */ (function (_super) {
__extends$1(AsyncItemReturnAsyncItemError, _super);
__extends(AsyncItemReturnAsyncItemError, _super);
function AsyncItemReturnAsyncItemError(id) {

@@ -657,3 +665,3 @@ return _super.call(this, "Async item \"".concat(prettyPrintIdentifier(id), "\" returns another async item.")) || this;

var GetAsyncItemFromSyncApiError = /** @class */ (function (_super) {
__extends$1(GetAsyncItemFromSyncApiError, _super);
__extends(GetAsyncItemFromSyncApiError, _super);
function GetAsyncItemFromSyncApiError(id) {

@@ -665,3 +673,3 @@ return _super.call(this, "Cannot get async item \"".concat(prettyPrintIdentifier(id), "\" from sync api.")) || this;

var AddDependencyAfterResolutionError = /** @class */ (function (_super) {
__extends$1(AddDependencyAfterResolutionError, _super);
__extends(AddDependencyAfterResolutionError, _super);
function AddDependencyAfterResolutionError(id) {

@@ -672,2 +680,9 @@ return _super.call(this, "Cannot add dependency \"".concat(prettyPrintIdentifier(id), "\" after it is already resolved.")) || this;

}(RediError));
var DeleteDependencyAfterResolutionError = /** @class */ (function (_super) {
__extends(DeleteDependencyAfterResolutionError, _super);
function DeleteDependencyAfterResolutionError(id) {
return _super.call(this, "Cannot dependency dependency \"".concat(prettyPrintIdentifier(id), "\" after it is already resolved.")) || this;
}
return DeleteDependencyAfterResolutionError;
}(RediError));
var Injector = /** @class */ (function () {

@@ -721,17 +736,25 @@ function Injector(collectionOrDependencies, parent) {

/** Replace an injection mapping for interface-based injection. */
Injector.prototype.replace = function (id, item) {
Injector.prototype.replace = function (dependency) {
this.ensureInjectorNotDisposed();
if (this.resolvedDependencyCollection.has(id)) {
throw new AddDependencyAfterResolutionError(id);
var identifier = dependency[0];
if (this.resolvedDependencyCollection.has(identifier)) {
throw new AddDependencyAfterResolutionError(identifier);
}
this.dependencyCollection.delete(id);
this.dependencyCollection.add(id, item);
this.dependencyCollection.delete(identifier);
if (dependency.length === 1) {
this.dependencyCollection.add(identifier);
}
else {
this.dependencyCollection.add(identifier, dependency[1]);
}
};
/**
* Delete a dependency and instantiated values from an injector.
* Delete a dependency from an injector.
*/
Injector.prototype.delete = function (id) {
Injector.prototype.delete = function (identifier) {
this.ensureInjectorNotDisposed();
this.dependencyCollection.delete(id);
this.resolvedDependencyCollection.delete(id);
if (this.resolvedDependencyCollection.has(identifier)) {
throw new DeleteDependencyAfterResolutionError(identifier);
}
this.dependencyCollection.delete(identifier);
};

@@ -1047,40 +1070,2 @@ Injector.prototype.get = function (id, quantityOrLookup, lookUp) {

var __extends = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var singletonDependencies = [];
var DuplicatedRegistrationError = /** @class */ (function (_super) {
__extends(DuplicatedRegistrationError, _super);
function DuplicatedRegistrationError(id, item1, item2) {
return _super.call(this, "Duplicated registration of ".concat(prettyPrintIdentifier(id), ", 1. ").concat(item1, " 2. ").concat(item2, ".")) || this;
}
return DuplicatedRegistrationError;
}(RediError));
function registerSingleton(id, item) {
var index = singletonDependencies.findIndex(function (r) { return r[0] === id; });
if (index !== -1) {
throw new DuplicatedRegistrationError(id, singletonDependencies[index][1], item);
}
singletonDependencies.push([id, item]);
}
function getSingletonDependencies() {
return singletonDependencies;
}
/* istanbul ignore next */
function TEST_ONLY_clearSingletonDependencies() {
singletonDependencies.length = 0;
}
var globalObject = (typeof globalThis !== 'undefined' && globalThis) ||

@@ -1114,3 +1099,2 @@ (typeof window !== 'undefined' && window) ||

exports.isValueDependencyItem = isValueDependencyItem;
exports.registerSingleton = registerSingleton;
exports.setDependencies = setDependencies;

@@ -1117,0 +1101,0 @@

@@ -25,4 +25,6 @@ var __extends = (this && this.__extends) || (function () {

function DependencyDescriptorNotFoundError(index, target) {
var _this = this;
var msg = "Could not find dependency registered on the ".concat(index + 1, " parameter of the constructor of \"").concat(prettyPrintIdentifier(target), "\".");
return _super.call(this, msg) || this;
_this = _super.call(this, msg) || this;
return _this;
}

@@ -34,4 +36,6 @@ return DependencyDescriptorNotFoundError;

function IdentifierUndefinedError(target, index) {
var _this = this;
var msg = "It seems that you register \"undefined\" as dependency on the ".concat(index + 1, " parameter of \"").concat(prettyPrintIdentifier(target), "\". Please make sure that there is not cyclic dependency among your TypeScript files, or consider using \"forwardRef\".");
return _super.call(this, msg) || this;
_this = _super.call(this, msg) || this;
return _this;
}

@@ -38,0 +42,0 @@ return IdentifierUndefinedError;

@@ -6,6 +6,6 @@ import { DependencyIdentifier } from './dependencyIdentifier';

import { RediError } from './error';
export type DependencyPair<T> = [DependencyIdentifier<T>, DependencyItem<T>];
export type DependencyClass<T> = [Ctor<T>];
export type Dependency<T = any> = DependencyPair<T> | DependencyClass<T>;
export type DependencyOrInstance<T = any> = Dependency<T> | [Ctor<T> | DependencyIdentifier<T>, T];
export declare type DependencyPair<T> = [DependencyIdentifier<T>, DependencyItem<T>];
export declare type DependencyClass<T> = [Ctor<T>];
export declare type Dependency<T = any> = DependencyPair<T> | DependencyClass<T>;
export declare type DependencyOrInstance<T = any> = Dependency<T> | [Ctor<T> | DependencyIdentifier<T>, T];
export declare function isBareClassDependency<T>(thing: Dependency<T>): thing is DependencyClass<T>;

@@ -12,0 +12,0 @@ export declare class DependencyNotFoundError extends RediError {

@@ -27,4 +27,6 @@ var __extends = (this && this.__extends) || (function () {

function DependencyNotFoundError(id) {
var _this = this;
var msg = "Cannot find \"".concat(prettyPrintIdentifier(id), "\" registered by any injector.");
return _super.call(this, msg) || this;
_this = _super.call(this, msg) || this;
return _this;
}

@@ -31,0 +33,0 @@ return DependencyNotFoundError;

import { Ctor } from './dependencyItem';
import { ForwardRef } from './dependencyForwardRef';
export declare const IdentifierDecoratorSymbol: unique symbol;
export type IdentifierDecorator<T> = {
export declare type IdentifierDecorator<T> = {
[IdentifierDecoratorSymbol]: true;

@@ -13,3 +13,3 @@ (...args: any[]): void;

};
export type DependencyIdentifier<T> = string | Ctor<T> | ForwardRef<T> | IdentifierDecorator<T>;
export type NormalizedDependencyIdentifier<T> = Exclude<DependencyIdentifier<T>, ForwardRef<T>>;
export declare type DependencyIdentifier<T> = string | Ctor<T> | ForwardRef<T> | IdentifierDecorator<T>;
export declare type NormalizedDependencyIdentifier<T> = Exclude<DependencyIdentifier<T>, ForwardRef<T>>;

@@ -18,4 +18,4 @@ import { DependencyIdentifier } from './dependencyIdentifier';

export declare function isClassDependencyItem<T>(thing: unknown): thing is ClassDependencyItem<T>;
export type FactoryDepModifier = typeof Self | typeof SkipSelf | typeof Optional | typeof Many | typeof WithNew;
export type FactoryDep<T> = [...FactoryDepModifier[], DependencyIdentifier<T>] | DependencyIdentifier<T>;
export declare type FactoryDepModifier = typeof Self | typeof SkipSelf | typeof Optional | typeof Many | typeof WithNew;
export declare type FactoryDep<T> = [...FactoryDepModifier[], DependencyIdentifier<T>] | DependencyIdentifier<T>;
export interface FactoryDependencyItem<T> extends DependencyItemHooks<T> {

@@ -39,4 +39,4 @@ useFactory: (...deps: any[]) => T;

export declare function isAsyncHook<T>(thing: unknown): thing is AsyncHook<T>;
export type SyncDependencyItem<T> = ClassDependencyItem<T> | FactoryDependencyItem<T> | ValueDependencyItem<T>;
export type DependencyItem<T> = SyncDependencyItem<T> | AsyncDependencyItem<T>;
export declare type SyncDependencyItem<T> = ClassDependencyItem<T> | FactoryDependencyItem<T> | ValueDependencyItem<T>;
export declare type DependencyItem<T> = SyncDependencyItem<T> | AsyncDependencyItem<T>;
export declare function prettyPrintIdentifier<T>(id: DependencyIdentifier<T>): string;

@@ -23,4 +23,6 @@ var __extends = (this && this.__extends) || (function () {

function QuantityCheckError(id, quantity, actual) {
var _this = this;
var msg = "Expect \"".concat(quantity, "\" dependency items for id \"").concat(prettyPrintIdentifier(id), "\" but get ").concat(actual, ".");
return _super.call(this, msg) || this;
_this = _super.call(this, msg) || this;
return _this;
}

@@ -27,0 +29,0 @@ return QuantityCheckError;

@@ -6,3 +6,3 @@ import { Disposable } from './dispose';

}
export type DisposableCallback = () => void;
export declare type DisposableCallback = () => void;
/**

@@ -9,0 +9,0 @@ * this run the callback when CPU is idle. Will fallback to setTimeout if

import { Dependency, DependencyOrInstance } from './dependencyCollection';
import { DependencyIdentifier } from './dependencyIdentifier';
import { AsyncHook, DependencyItem } from './dependencyItem';
import { AsyncHook } from './dependencyItem';
import { LookUp, Quantity } from './types';

@@ -19,7 +19,7 @@ export declare class Injector {

/** Replace an injection mapping for interface-based injection. */
replace<T>(id: DependencyIdentifier<T>, item: DependencyItem<T>): void;
replace<T>(dependency: Dependency<T>): void;
/**
* Delete a dependency and instantiated values from an injector.
* Delete a dependency from an injector.
*/
delete<T>(id: DependencyIdentifier<T>): void;
delete<T>(identifier: DependencyIdentifier<T>): void;
/**

@@ -26,0 +26,0 @@ * Get dependency instance(s).

@@ -81,2 +81,9 @@ var __extends = (this && this.__extends) || (function () {

}(RediError));
var DeleteDependencyAfterResolutionError = /** @class */ (function (_super) {
__extends(DeleteDependencyAfterResolutionError, _super);
function DeleteDependencyAfterResolutionError(id) {
return _super.call(this, "Cannot dependency dependency \"".concat(prettyPrintIdentifier(id), "\" after it is already resolved.")) || this;
}
return DeleteDependencyAfterResolutionError;
}(RediError));
var Injector = /** @class */ (function () {

@@ -130,17 +137,25 @@ function Injector(collectionOrDependencies, parent) {

/** Replace an injection mapping for interface-based injection. */
Injector.prototype.replace = function (id, item) {
Injector.prototype.replace = function (dependency) {
this.ensureInjectorNotDisposed();
if (this.resolvedDependencyCollection.has(id)) {
throw new AddDependencyAfterResolutionError(id);
var identifier = dependency[0];
if (this.resolvedDependencyCollection.has(identifier)) {
throw new AddDependencyAfterResolutionError(identifier);
}
this.dependencyCollection.delete(id);
this.dependencyCollection.add(id, item);
this.dependencyCollection.delete(identifier);
if (dependency.length === 1) {
this.dependencyCollection.add(identifier);
}
else {
this.dependencyCollection.add(identifier, dependency[1]);
}
};
/**
* Delete a dependency and instantiated values from an injector.
* Delete a dependency from an injector.
*/
Injector.prototype.delete = function (id) {
Injector.prototype.delete = function (identifier) {
this.ensureInjectorNotDisposed();
this.dependencyCollection.delete(id);
this.resolvedDependencyCollection.delete(id);
if (this.resolvedDependencyCollection.has(identifier)) {
throw new DeleteDependencyAfterResolutionError(identifier);
}
this.dependencyCollection.delete(identifier);
};

@@ -147,0 +162,0 @@ Injector.prototype.get = function (id, quantityOrLookup, lookUp) {

@@ -11,5 +11,4 @@ export { createIdentifier } from './decorators';

export { setDependencies } from './dependencyDeclare';
export { registerSingleton } from './dependencySingletons';
export { WithNew } from './dependencyWithNew';
export { AsyncDependencyItem, AsyncHook, ClassDependencyItem, Ctor, DependencyItem, FactoryDependencyItem, isAsyncDependencyItem, isAsyncHook, isClassDependencyItem, isCtor, isFactoryDependencyItem, isValueDependencyItem, SyncDependencyItem, ValueDependencyItem, } from './dependencyItem';
export { RediError } from './error';

@@ -8,3 +8,2 @@ export { createIdentifier } from './decorators';

export { setDependencies } from './dependencyDeclare';
export { registerSingleton } from './dependencySingletons';
export { WithNew } from './dependencyWithNew';

@@ -11,0 +10,0 @@ export { isAsyncDependencyItem, isAsyncHook, isClassDependencyItem, isCtor, isFactoryDependencyItem, isValueDependencyItem, } from './dependencyItem';

@@ -55,3 +55,3 @@ var IdentifierDecoratorSymbol = Symbol('$$IDENTIFIER_DECORATOR');

var __extends$5 = (undefined && undefined.__extends) || (function () {
var __extends$4 = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {

@@ -72,3 +72,3 @@ extendStatics = Object.setPrototypeOf ||

var RediError = /** @class */ (function (_super) {
__extends$5(RediError, _super);
__extends$4(RediError, _super);
function RediError(message) {

@@ -80,3 +80,3 @@ return _super.call(this, "[redi]: ".concat(message)) || this;

var __extends$4 = (undefined && undefined.__extends) || (function () {
var __extends$3 = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {

@@ -99,6 +99,8 @@ extendStatics = Object.setPrototypeOf ||

var DependencyDescriptorNotFoundError = /** @class */ (function (_super) {
__extends$4(DependencyDescriptorNotFoundError, _super);
__extends$3(DependencyDescriptorNotFoundError, _super);
function DependencyDescriptorNotFoundError(index, target) {
var _this = this;
var msg = "Could not find dependency registered on the ".concat(index + 1, " parameter of the constructor of \"").concat(prettyPrintIdentifier(target), "\".");
return _super.call(this, msg) || this;
_this = _super.call(this, msg) || this;
return _this;
}

@@ -108,6 +110,8 @@ return DependencyDescriptorNotFoundError;

var IdentifierUndefinedError = /** @class */ (function (_super) {
__extends$4(IdentifierUndefinedError, _super);
__extends$3(IdentifierUndefinedError, _super);
function IdentifierUndefinedError(target, index) {
var _this = this;
var msg = "It seems that you register \"undefined\" as dependency on the ".concat(index + 1, " parameter of \"").concat(prettyPrintIdentifier(target), "\". Please make sure that there is not cyclic dependency among your TypeScript files, or consider using \"forwardRef\".");
return _super.call(this, msg) || this;
_this = _super.call(this, msg) || this;
return _this;
}

@@ -191,3 +195,3 @@ return IdentifierUndefinedError;

var __extends$3 = (undefined && undefined.__extends) || (function () {
var __extends$2 = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {

@@ -208,6 +212,8 @@ extendStatics = Object.setPrototypeOf ||

var QuantityCheckError = /** @class */ (function (_super) {
__extends$3(QuantityCheckError, _super);
__extends$2(QuantityCheckError, _super);
function QuantityCheckError(id, quantity, actual) {
var _this = this;
var msg = "Expect \"".concat(quantity, "\" dependency items for id \"").concat(prettyPrintIdentifier(id), "\" but get ").concat(actual, ".");
return _super.call(this, msg) || this;
_this = _super.call(this, msg) || this;
return _this;
}

@@ -274,3 +280,3 @@ return QuantityCheckError;

var __extends$2 = (undefined && undefined.__extends) || (function () {
var __extends$1 = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {

@@ -294,6 +300,8 @@ extendStatics = Object.setPrototypeOf ||

var DependencyNotFoundError = /** @class */ (function (_super) {
__extends$2(DependencyNotFoundError, _super);
__extends$1(DependencyNotFoundError, _super);
function DependencyNotFoundError(id) {
var _this = this;
var msg = "Cannot find \"".concat(prettyPrintIdentifier(id), "\" registered by any injector.");
return _super.call(this, msg) || this;
_this = _super.call(this, msg) || this;
return _this;
}

@@ -588,3 +596,3 @@ return DependencyNotFoundError;

var __extends$1 = (undefined && undefined.__extends) || (function () {
var __extends = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {

@@ -627,3 +635,3 @@ extendStatics = Object.setPrototypeOf ||

var CircularDependencyError = /** @class */ (function (_super) {
__extends$1(CircularDependencyError, _super);
__extends(CircularDependencyError, _super);
function CircularDependencyError(id) {

@@ -635,3 +643,3 @@ return _super.call(this, "Detecting cyclic dependency. The last identifier is \"".concat(prettyPrintIdentifier(id), "\".")) || this;

var InjectorAlreadyDisposedError = /** @class */ (function (_super) {
__extends$1(InjectorAlreadyDisposedError, _super);
__extends(InjectorAlreadyDisposedError, _super);
function InjectorAlreadyDisposedError() {

@@ -643,3 +651,3 @@ return _super.call(this, 'Injector cannot be accessed after it was disposed.') || this;

var AsyncItemReturnAsyncItemError = /** @class */ (function (_super) {
__extends$1(AsyncItemReturnAsyncItemError, _super);
__extends(AsyncItemReturnAsyncItemError, _super);
function AsyncItemReturnAsyncItemError(id) {

@@ -651,3 +659,3 @@ return _super.call(this, "Async item \"".concat(prettyPrintIdentifier(id), "\" returns another async item.")) || this;

var GetAsyncItemFromSyncApiError = /** @class */ (function (_super) {
__extends$1(GetAsyncItemFromSyncApiError, _super);
__extends(GetAsyncItemFromSyncApiError, _super);
function GetAsyncItemFromSyncApiError(id) {

@@ -659,3 +667,3 @@ return _super.call(this, "Cannot get async item \"".concat(prettyPrintIdentifier(id), "\" from sync api.")) || this;

var AddDependencyAfterResolutionError = /** @class */ (function (_super) {
__extends$1(AddDependencyAfterResolutionError, _super);
__extends(AddDependencyAfterResolutionError, _super);
function AddDependencyAfterResolutionError(id) {

@@ -666,2 +674,9 @@ return _super.call(this, "Cannot add dependency \"".concat(prettyPrintIdentifier(id), "\" after it is already resolved.")) || this;

}(RediError));
var DeleteDependencyAfterResolutionError = /** @class */ (function (_super) {
__extends(DeleteDependencyAfterResolutionError, _super);
function DeleteDependencyAfterResolutionError(id) {
return _super.call(this, "Cannot dependency dependency \"".concat(prettyPrintIdentifier(id), "\" after it is already resolved.")) || this;
}
return DeleteDependencyAfterResolutionError;
}(RediError));
var Injector = /** @class */ (function () {

@@ -715,17 +730,25 @@ function Injector(collectionOrDependencies, parent) {

/** Replace an injection mapping for interface-based injection. */
Injector.prototype.replace = function (id, item) {
Injector.prototype.replace = function (dependency) {
this.ensureInjectorNotDisposed();
if (this.resolvedDependencyCollection.has(id)) {
throw new AddDependencyAfterResolutionError(id);
var identifier = dependency[0];
if (this.resolvedDependencyCollection.has(identifier)) {
throw new AddDependencyAfterResolutionError(identifier);
}
this.dependencyCollection.delete(id);
this.dependencyCollection.add(id, item);
this.dependencyCollection.delete(identifier);
if (dependency.length === 1) {
this.dependencyCollection.add(identifier);
}
else {
this.dependencyCollection.add(identifier, dependency[1]);
}
};
/**
* Delete a dependency and instantiated values from an injector.
* Delete a dependency from an injector.
*/
Injector.prototype.delete = function (id) {
Injector.prototype.delete = function (identifier) {
this.ensureInjectorNotDisposed();
this.dependencyCollection.delete(id);
this.resolvedDependencyCollection.delete(id);
if (this.resolvedDependencyCollection.has(identifier)) {
throw new DeleteDependencyAfterResolutionError(identifier);
}
this.dependencyCollection.delete(identifier);
};

@@ -1041,40 +1064,2 @@ Injector.prototype.get = function (id, quantityOrLookup, lookUp) {

var __extends = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var singletonDependencies = [];
var DuplicatedRegistrationError = /** @class */ (function (_super) {
__extends(DuplicatedRegistrationError, _super);
function DuplicatedRegistrationError(id, item1, item2) {
return _super.call(this, "Duplicated registration of ".concat(prettyPrintIdentifier(id), ", 1. ").concat(item1, " 2. ").concat(item2, ".")) || this;
}
return DuplicatedRegistrationError;
}(RediError));
function registerSingleton(id, item) {
var index = singletonDependencies.findIndex(function (r) { return r[0] === id; });
if (index !== -1) {
throw new DuplicatedRegistrationError(id, singletonDependencies[index][1], item);
}
singletonDependencies.push([id, item]);
}
function getSingletonDependencies() {
return singletonDependencies;
}
/* istanbul ignore next */
function TEST_ONLY_clearSingletonDependencies() {
singletonDependencies.length = 0;
}
var globalObject = (typeof globalThis !== 'undefined' && globalThis) ||

@@ -1092,3 +1077,3 @@ (typeof window !== 'undefined' && window) ||

export { Inject, Injector, LookUp, Many, Optional, Quantity, RediError, Self, SkipSelf, WithNew, createIdentifier, forwardRef, isAsyncDependencyItem, isAsyncHook, isClassDependencyItem, isCtor, isFactoryDependencyItem, isValueDependencyItem, registerSingleton, setDependencies };
export { Inject, Injector, LookUp, Many, Optional, Quantity, RediError, Self, SkipSelf, WithNew, createIdentifier, forwardRef, isAsyncDependencyItem, isAsyncHook, isClassDependencyItem, isCtor, isFactoryDependencyItem, isValueDependencyItem, setDependencies };
//# sourceMappingURL=redi.js.map
{
"$schema": "https://raw.githubusercontent.com/wzhudev/squirrel/master/src/schema/package.schema.json",
"name": "@wendellhu/redi",
"version": "0.9.0",
"version": "0.10.0",
"description": "A dependency library for TypeScript and JavaScript, along with a binding for React.",

@@ -6,0 +6,0 @@ "author": "Wenzhao Hu<wzhudev@outlook.com>",

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc