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.6.5 to 0.7.0

128

dist/redi.js

@@ -502,2 +502,47 @@ (function (global, factory) {

var __extends$1 = (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 singletonFetchedLock = false;
var singletonDependencies = [];
var DuplicatedRegistrationError = /** @class */ (function (_super) {
__extends$1(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() {
if (singletonFetchedLock) {
console.warn('[redi]: Singleton dependencies has been fetched before by an other injector. ' +
'Please avoid fetching singleton dependencies twice.');
}
singletonFetchedLock = true;
return singletonDependencies;
}
/* istanbul ignore next */
function TEST_ONLY_clearSingletonDependencies() {
singletonFetchedLock = false;
singletonDependencies.length = 0;
}
/**

@@ -586,47 +631,2 @@ * this run the callback when CPU is idle. Will fallback to setTimeout if

var __extends$1 = (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 singletonFetchedLock = false;
var singletonDependencies = [];
var DuplicatedRegistrationError = /** @class */ (function (_super) {
__extends$1(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() {
if (singletonFetchedLock) {
console.warn('[redi]: Singleton dependencies has been fetched before by an other injector. ' +
'Please avoid fetching singleton dependencies twice.');
}
singletonFetchedLock = true;
return singletonDependencies;
}
/* istanbul ignore next */
function TEST_ONLY_clearSingletonDependencies() {
singletonFetchedLock = false;
singletonDependencies.length = 0;
}
var __extends = (undefined && undefined.__extends) || (function () {

@@ -679,3 +679,3 @@ var extendStatics = function (d, b) {

function InjectorAlreadyDisposedError() {
return _super.call(this, 'Injector cannot be accessed after it disposes.') || this;
return _super.call(this, 'Injector cannot be accessed after it was disposed.') || this;
}

@@ -698,2 +698,9 @@ return InjectorAlreadyDisposedError;

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

@@ -703,2 +710,3 @@ function Injector(collectionOrDependencies, parent) {

this.resolutionOngoing = 0;
/** If the injector is diposed */
this.disposed = false;

@@ -723,6 +731,7 @@ this.dependencyCollection = new DependencyCollection(collectionOrDependencies || []);

this.resolvedDependencyCollection.dispose();
this.deleteThisFromParent();
this.deleteSelfFromParent();
this.disposed = true;
};
Injector.prototype.add = function (dependency, item) {
this.ensureInjectorNotDisposed();
if (typeof item !== 'undefined' || Array.isArray(dependency)) {

@@ -733,2 +742,5 @@ if (Array.isArray(dependency)) {

}
if (this.resolvedDependencyCollection.has(dependency)) {
throw new AddDependencyAfterResolutionError(dependency);
}
if (isAsyncDependencyItem(item) ||

@@ -738,5 +750,7 @@ isClassDependencyItem(item) ||

isFactoryDependencyItem(item)) {
// Add depdendency
this.dependencyCollection.add(dependency, item);
}
else {
// Add instance
this.resolvedDependencyCollection.add(dependency, item);

@@ -746,9 +760,23 @@ }

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

@@ -786,3 +814,3 @@ this.resolvedDependencyCollection.delete(id);

/**
* get a dependency, but in async way
* Get a dependency, but in async way.
*/

@@ -1051,3 +1079,3 @@ Injector.prototype.getAsync = function (id) {

};
Injector.prototype.deleteThisFromParent = function () {
Injector.prototype.deleteSelfFromParent = function () {
if (this.parent) {

@@ -1054,0 +1082,0 @@ var index = this.parent.children.indexOf(this);

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

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

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

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

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

};
export declare type DependencyIdentifier<T> = string | Ctor<T> | ForwardRef<T> | IdentifierDecorator<T>;
export declare type NormalizedDependencyIdentifier<T> = Exclude<DependencyIdentifier<T>, ForwardRef<T>>;
export type DependencyIdentifier<T> = string | Ctor<T> | ForwardRef<T> | IdentifierDecorator<T>;
export 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 declare type FactoryDepModifier = typeof Self | typeof SkipSelf | typeof Optional | typeof Many | typeof WithNew;
export declare type FactoryDep<T> = [...FactoryDepModifier[], DependencyIdentifier<T>] | DependencyIdentifier<T>;
export type FactoryDepModifier = typeof Self | typeof SkipSelf | typeof Optional | typeof Many | typeof WithNew;
export 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 declare type SyncDependencyItem<T> = ClassDependencyItem<T> | FactoryDependencyItem<T> | ValueDependencyItem<T>;
export declare type DependencyItem<T> = SyncDependencyItem<T> | AsyncDependencyItem<T>;
export type SyncDependencyItem<T> = ClassDependencyItem<T> | FactoryDependencyItem<T> | ValueDependencyItem<T>;
export type DependencyItem<T> = SyncDependencyItem<T> | AsyncDependencyItem<T>;
export declare function prettyPrintIdentifier<T>(id: DependencyIdentifier<T>): string;

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

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

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

import { Dependency, DependencyPair } from './dependencyCollection';
import { DependencyIdentifier } from './dependencyIdentifier';
import { Ctor, DependencyItem, AsyncHook } from './dependencyItem';
import { Quantity, LookUp } from './types';
import { AsyncHook, Ctor, DependencyItem } from './dependencyItem';
import { LookUp, Quantity } from './types';
export declare class Injector {

@@ -11,2 +11,3 @@ private readonly dependencyCollection;

private resolutionOngoing;
/** If the injector is diposed */
private disposed;

@@ -16,11 +17,14 @@ constructor(collectionOrDependencies?: Dependency[], parent?: Injector);

dispose(): void;
/** Add a dependency or its instance into injector. */
add<T>(ctor: Ctor<T>): void;
add<T>(pair: DependencyPair<T>): void;
add<T>(id: DependencyIdentifier<T>, item: DependencyItem<T> | T): void;
/** Replace an injection mapping for interface-based injection. */
replace<T>(id: DependencyIdentifier<T>, item: DependencyItem<T>): void;
/**
* delete a dependency and instantiated values from an injector
* Delete a dependency and instantiated values from an injector.
*/
delete<T>(id: DependencyIdentifier<T>): void;
/**
* get a dependency
* Get dependency instance(s).
*/

@@ -35,3 +39,3 @@ get<T>(id: DependencyIdentifier<T>, lookUp?: LookUp): T;

/**
* get a dependency, but in async way
* Get a dependency, but in async way.
*/

@@ -64,3 +68,3 @@ getAsync<T>(id: DependencyIdentifier<T>): Promise<T>;

private ensureInjectorNotDisposed;
private deleteThisFromParent;
private deleteSelfFromParent;
}

@@ -39,8 +39,8 @@ var __extends = (this && this.__extends) || (function () {

import { normalizeFactoryDeps } from './dependencyDescriptor';
import { isClassDependencyItem, isFactoryDependencyItem, isValueDependencyItem, isAsyncDependencyItem, isAsyncHook, isCtor, prettyPrintIdentifier, } from './dependencyItem';
import { normalizeForwardRef } from './dependencyForwardRef';
import { IdleValue } from './idleValue';
import { isAsyncDependencyItem, isAsyncHook, isClassDependencyItem, isCtor, isFactoryDependencyItem, isValueDependencyItem, prettyPrintIdentifier, } from './dependencyItem';
import { getSingletonDependencies } from './dependencySingletons';
import { RediError } from './error';
import { Quantity, LookUp } from './types';
import { IdleValue } from './idleValue';
import { LookUp, Quantity } from './types';
var MAX_RESOLUTIONS_QUEUED = 300;

@@ -58,3 +58,3 @@ var NotInstantiatedSymbol = Symbol('$$NOT_INSTANTIATED_SYMBOL');

function InjectorAlreadyDisposedError() {
return _super.call(this, 'Injector cannot be accessed after it disposes.') || this;
return _super.call(this, 'Injector cannot be accessed after it was disposed.') || this;
}

@@ -77,2 +77,9 @@ return InjectorAlreadyDisposedError;

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

@@ -82,2 +89,3 @@ function Injector(collectionOrDependencies, parent) {

this.resolutionOngoing = 0;
/** If the injector is diposed */
this.disposed = false;

@@ -102,6 +110,7 @@ this.dependencyCollection = new DependencyCollection(collectionOrDependencies || []);

this.resolvedDependencyCollection.dispose();
this.deleteThisFromParent();
this.deleteSelfFromParent();
this.disposed = true;
};
Injector.prototype.add = function (dependency, item) {
this.ensureInjectorNotDisposed();
if (typeof item !== 'undefined' || Array.isArray(dependency)) {

@@ -112,2 +121,5 @@ if (Array.isArray(dependency)) {

}
if (this.resolvedDependencyCollection.has(dependency)) {
throw new AddDependencyAfterResolutionError(dependency);
}
if (isAsyncDependencyItem(item) ||

@@ -117,5 +129,7 @@ isClassDependencyItem(item) ||

isFactoryDependencyItem(item)) {
// Add depdendency
this.dependencyCollection.add(dependency, item);
}
else {
// Add instance
this.resolvedDependencyCollection.add(dependency, item);

@@ -125,9 +139,23 @@ }

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

@@ -165,3 +193,3 @@ this.resolvedDependencyCollection.delete(id);

/**
* get a dependency, but in async way
* Get a dependency, but in async way.
*/

@@ -430,3 +458,3 @@ Injector.prototype.getAsync = function (id) {

};
Injector.prototype.deleteThisFromParent = function () {
Injector.prototype.deleteSelfFromParent = function () {
if (this.parent) {

@@ -433,0 +461,0 @@ var index = this.parent.children.indexOf(this);

@@ -496,2 +496,47 @@ var IdentifierDecoratorSymbol = Symbol('$$IDENTIFIER_DECORATOR');

var __extends$1 = (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 singletonFetchedLock = false;
var singletonDependencies = [];
var DuplicatedRegistrationError = /** @class */ (function (_super) {
__extends$1(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() {
if (singletonFetchedLock) {
console.warn('[redi]: Singleton dependencies has been fetched before by an other injector. ' +
'Please avoid fetching singleton dependencies twice.');
}
singletonFetchedLock = true;
return singletonDependencies;
}
/* istanbul ignore next */
function TEST_ONLY_clearSingletonDependencies() {
singletonFetchedLock = false;
singletonDependencies.length = 0;
}
/**

@@ -580,47 +625,2 @@ * this run the callback when CPU is idle. Will fallback to setTimeout if

var __extends$1 = (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 singletonFetchedLock = false;
var singletonDependencies = [];
var DuplicatedRegistrationError = /** @class */ (function (_super) {
__extends$1(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() {
if (singletonFetchedLock) {
console.warn('[redi]: Singleton dependencies has been fetched before by an other injector. ' +
'Please avoid fetching singleton dependencies twice.');
}
singletonFetchedLock = true;
return singletonDependencies;
}
/* istanbul ignore next */
function TEST_ONLY_clearSingletonDependencies() {
singletonFetchedLock = false;
singletonDependencies.length = 0;
}
var __extends = (undefined && undefined.__extends) || (function () {

@@ -673,3 +673,3 @@ var extendStatics = function (d, b) {

function InjectorAlreadyDisposedError() {
return _super.call(this, 'Injector cannot be accessed after it disposes.') || this;
return _super.call(this, 'Injector cannot be accessed after it was disposed.') || this;
}

@@ -692,2 +692,9 @@ return InjectorAlreadyDisposedError;

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

@@ -697,2 +704,3 @@ function Injector(collectionOrDependencies, parent) {

this.resolutionOngoing = 0;
/** If the injector is diposed */
this.disposed = false;

@@ -717,6 +725,7 @@ this.dependencyCollection = new DependencyCollection(collectionOrDependencies || []);

this.resolvedDependencyCollection.dispose();
this.deleteThisFromParent();
this.deleteSelfFromParent();
this.disposed = true;
};
Injector.prototype.add = function (dependency, item) {
this.ensureInjectorNotDisposed();
if (typeof item !== 'undefined' || Array.isArray(dependency)) {

@@ -727,2 +736,5 @@ if (Array.isArray(dependency)) {

}
if (this.resolvedDependencyCollection.has(dependency)) {
throw new AddDependencyAfterResolutionError(dependency);
}
if (isAsyncDependencyItem(item) ||

@@ -732,5 +744,7 @@ isClassDependencyItem(item) ||

isFactoryDependencyItem(item)) {
// Add depdendency
this.dependencyCollection.add(dependency, item);
}
else {
// Add instance
this.resolvedDependencyCollection.add(dependency, item);

@@ -740,9 +754,23 @@ }

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

@@ -780,3 +808,3 @@ this.resolvedDependencyCollection.delete(id);

/**
* get a dependency, but in async way
* Get a dependency, but in async way.
*/

@@ -1045,3 +1073,3 @@ Injector.prototype.getAsync = function (id) {

};
Injector.prototype.deleteThisFromParent = function () {
Injector.prototype.deleteSelfFromParent = function () {
if (this.parent) {

@@ -1048,0 +1076,0 @@ var index = this.parent.children.indexOf(this);

{
"$schema": "https://raw.githubusercontent.com/hullis/squirrel/master/src/schema/package.schema.json",
"name": "@wendellhu/redi",
"version": "0.6.5",
"version": "0.7.0",
"description": "A dependency library for TypeScript and JavaScript, along with a binding for React.",

@@ -6,0 +6,0 @@ "exports": {

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