ts-ioc-container 69.2.0 → 70.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cjm/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.injectProp = exports.createHookExecutionContext = exports.createHookContextFactory = exports.HookContext = exports.toHookFn = exports.hasHooks = exports.hook = exports.getHooks = exports.ArgumentNotFoundError = exports.TypedEventDisposedError = exports.UnsupportedTokenTypeError = exports.CannonSingletonApplyTwiceError = exports.ProviderDisposedError = exports.ContainerDisposedError = exports.MethodNotImplementedError = exports.DependencyMissingKeyError = exports.ContainerNotFoundError = exports.DependencyNotFoundError = exports.ContainerError = exports.Registration = exports.onResolve = exports.appendArgsFn = exports.appendArgs = exports.decorate = exports.singleton = exports.autoResolve = exports.lazy = exports.scopeAccess = exports.scope = exports.bindTo = exports.register = exports.toRegistrationFn = exports.toProviderFn = exports.toBindToken = exports.registerPipe = exports.isProviderPipe = exports.Provider = exports.ProxyInjector = exports.SimpleInjector = exports.resolveArgs = exports.argsFn = exports.args = exports.arg = exports.inject = exports.MetadataInjector = exports.Injector = exports.EmptyContainer = exports.AutoResolveModule = exports.Container = exports.isDependencyKey = void 0;
4
4
  exports.TypedEvent = exports.getConstructorChain = exports.memoize = exports.once = exports.shallowCache = exports.debounce = exports.throttle = exports.runAtOnce = exports.runInOrder = exports.handleAsyncError = exports.handleError = exports.getMethodTags = exports.addMethodTag = exports.getMethodLabels = exports.addMethodLabel = exports.getMethodMeta = exports.addMethodMeta = exports.getParamTags = exports.addParamTag = exports.getParamLabels = exports.addParamLabel = exports.getParamMeta = exports.addParamMeta = exports.getClassTags = exports.addClassTag = exports.getClassLabels = exports.addClassLabel = exports.getClassMeta = exports.addClassMeta = exports.resolveConstructor = exports.GroupInstanceToken = exports.ConstantToken = exports.FunctionToken = exports.SingleToken = exports.ClassToken = exports.toSingleAlias = exports.SingleAliasToken = exports.toGroupAlias = exports.GroupAliasToken = exports.argToToken = exports.toMappedToken = exports.toToken = exports.forwardArgs = exports.isInjectionToken = exports.InjectionToken = exports.toTask = exports.HookCollector = exports.oncePerInstance = exports.parallel = exports.sequential = void 0;
5
- exports.Is = exports.unwrapProxy = exports.ProxyRegistry = exports.findOrFail = exports.pipe = exports.select = void 0;
5
+ exports.isSerializable = exports.Is = exports.unwrapProxy = exports.ProxyRegistry = exports.findOrFail = exports.pipe = exports.select = void 0;
6
6
  var IContainer_1 = require("./container/IContainer");
7
7
  Object.defineProperty(exports, "isDependencyKey", { enumerable: true, get: function () { return IContainer_1.isDependencyKey; } });
8
8
  var Container_1 = require("./container/Container");
@@ -163,3 +163,4 @@ Object.defineProperty(exports, "ProxyRegistry", { enumerable: true, get: functio
163
163
  Object.defineProperty(exports, "unwrapProxy", { enumerable: true, get: function () { return ProxyRegistry_1.unwrapProxy; } });
164
164
  var basic_1 = require("./utils/basic");
165
165
  Object.defineProperty(exports, "Is", { enumerable: true, get: function () { return basic_1.Is; } });
166
+ Object.defineProperty(exports, "isSerializable", { enumerable: true, get: function () { return basic_1.isSerializable; } });
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Provider = void 0;
4
+ const basic_1 = require("../utils/basic");
4
5
  const CannonSingletonApplyTwiceError_1 = require("../errors/CannonSingletonApplyTwiceError");
5
6
  const ProviderDisposedError_1 = require("../errors/ProviderDisposedError");
6
7
  class Provider {
@@ -31,7 +32,7 @@ class Provider {
31
32
  if (!this.getKey) {
32
33
  return this.resolveDep(scope, options);
33
34
  }
34
- const key = this.getKey(...(options.args ?? []));
35
+ const key = (0, basic_1.toString)(this.getKey(...(options.args ?? [])));
35
36
  if (!this.cache.has(key)) {
36
37
  this.cache.set(key, this.resolveDep(scope, options));
37
38
  }
@@ -41,8 +41,8 @@ class ClassToken extends InjectionToken_1.InjectionToken {
41
41
  isLazy: true,
42
42
  });
43
43
  }
44
- getKey() {
45
- return this.target;
44
+ toString() {
45
+ return this.target.name;
46
46
  }
47
47
  }
48
48
  exports.ClassToken = ClassToken;
@@ -21,7 +21,7 @@ class ConstantToken extends InjectionToken_1.InjectionToken {
21
21
  lazy() {
22
22
  throw new MethodNotImplementedError_1.MethodNotImplementedError('not implemented');
23
23
  }
24
- getKey() {
24
+ toString() {
25
25
  throw new MethodNotImplementedError_1.MethodNotImplementedError('not implemented');
26
26
  }
27
27
  }
@@ -39,7 +39,7 @@ class FunctionToken extends InjectionToken_1.InjectionToken {
39
39
  isLazy: true,
40
40
  });
41
41
  }
42
- getKey() {
42
+ toString() {
43
43
  throw new MethodNotImplementedError_1.MethodNotImplementedError('not implemented');
44
44
  }
45
45
  }
@@ -44,8 +44,8 @@ class GroupAliasToken extends InjectionToken_1.InjectionToken {
44
44
  isLazy: true,
45
45
  });
46
46
  }
47
- getKey() {
48
- return this.token;
47
+ toString() {
48
+ return this.token.toString();
49
49
  }
50
50
  }
51
51
  exports.GroupAliasToken = GroupAliasToken;
@@ -29,7 +29,7 @@ class GroupInstanceToken extends InjectionToken_1.InjectionToken {
29
29
  resolve(c) {
30
30
  return c.getInstances(this.isCascade).filter(this.predicate);
31
31
  }
32
- getKey() {
32
+ toString() {
33
33
  throw new MethodNotImplementedError_1.MethodNotImplementedError('not implemented');
34
34
  }
35
35
  }
@@ -44,8 +44,8 @@ class SingleAliasToken extends InjectionToken_1.InjectionToken {
44
44
  isLazy: true,
45
45
  });
46
46
  }
47
- getKey() {
48
- return this.token;
47
+ toString() {
48
+ return this.token.toString();
49
49
  }
50
50
  }
51
51
  exports.SingleAliasToken = SingleAliasToken;
@@ -44,8 +44,8 @@ class SingleToken extends InjectionToken_1.InjectionToken {
44
44
  isLazy: true,
45
45
  });
46
46
  }
47
- getKey() {
48
- return this.token;
47
+ toString() {
48
+ return this.token.toString();
49
49
  }
50
50
  }
51
51
  exports.SingleToken = SingleToken;
@@ -1,9 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Is = void 0;
3
+ exports.toString = exports.Is = void 0;
4
+ exports.isSerializable = isSerializable;
4
5
  exports.Is = {
5
6
  nullish: (value) => value === undefined || value === null,
6
7
  object: (target) => target !== null && typeof target === 'object',
7
8
  instance: (target) => Object.prototype.hasOwnProperty.call(target, 'constructor'),
8
9
  constructor: (target) => typeof target === 'function' && !!target.prototype,
9
10
  };
11
+ function isSerializable(target) {
12
+ return exports.Is.object(target) && typeof target.toString === 'function' && target.toString !== Object.prototype.toString;
13
+ }
14
+ const toString = (target) => (isSerializable(target) ? target.toString() : String(target));
15
+ exports.toString = toString;
package/esm/index.js CHANGED
@@ -51,4 +51,4 @@ export { select } from './select.js';
51
51
  export { pipe } from './utils/fp.js';
52
52
  export { findOrFail } from './utils/array.js';
53
53
  export { ProxyRegistry, unwrapProxy } from './utils/ProxyRegistry.js';
54
- export { Is } from './utils/basic.js';
54
+ export { Is, isSerializable } from './utils/basic.js';
@@ -1,3 +1,4 @@
1
+ import { toString } from '../utils/basic.js';
1
2
  import { CannonSingletonApplyTwiceError } from '../errors/CannonSingletonApplyTwiceError.js';
2
3
  import { ProviderDisposedError } from '../errors/ProviderDisposedError.js';
3
4
  export class Provider {
@@ -28,7 +29,7 @@ export class Provider {
28
29
  if (!this.getKey) {
29
30
  return this.resolveDep(scope, options);
30
31
  }
31
- const key = this.getKey(...(options.args ?? []));
32
+ const key = toString(this.getKey(...(options.args ?? [])));
32
33
  if (!this.cache.has(key)) {
33
34
  this.cache.set(key, this.resolveDep(scope, options));
34
35
  }
@@ -38,7 +38,7 @@ export class ClassToken extends InjectionToken {
38
38
  isLazy: true,
39
39
  });
40
40
  }
41
- getKey() {
42
- return this.target;
41
+ toString() {
42
+ return this.target.name;
43
43
  }
44
44
  }
@@ -18,7 +18,7 @@ export class ConstantToken extends InjectionToken {
18
18
  lazy() {
19
19
  throw new MethodNotImplementedError('not implemented');
20
20
  }
21
- getKey() {
21
+ toString() {
22
22
  throw new MethodNotImplementedError('not implemented');
23
23
  }
24
24
  }
@@ -36,7 +36,7 @@ export class FunctionToken extends InjectionToken {
36
36
  isLazy: true,
37
37
  });
38
38
  }
39
- getKey() {
39
+ toString() {
40
40
  throw new MethodNotImplementedError('not implemented');
41
41
  }
42
42
  }
@@ -41,8 +41,8 @@ export class GroupAliasToken extends InjectionToken {
41
41
  isLazy: true,
42
42
  });
43
43
  }
44
- getKey() {
45
- return this.token;
44
+ toString() {
45
+ return this.token.toString();
46
46
  }
47
47
  }
48
48
  export const toGroupAlias = (token) => new GroupAliasToken(token);
@@ -26,7 +26,7 @@ export class GroupInstanceToken extends InjectionToken {
26
26
  resolve(c) {
27
27
  return c.getInstances(this.isCascade).filter(this.predicate);
28
28
  }
29
- getKey() {
29
+ toString() {
30
30
  throw new MethodNotImplementedError('not implemented');
31
31
  }
32
32
  }
@@ -41,8 +41,8 @@ export class SingleAliasToken extends InjectionToken {
41
41
  isLazy: true,
42
42
  });
43
43
  }
44
- getKey() {
45
- return this.token;
44
+ toString() {
45
+ return this.token.toString();
46
46
  }
47
47
  }
48
48
  export const toSingleAlias = (token) => new SingleAliasToken(token);
@@ -41,7 +41,7 @@ export class SingleToken extends InjectionToken {
41
41
  isLazy: true,
42
42
  });
43
43
  }
44
- getKey() {
45
- return this.token;
44
+ toString() {
45
+ return this.token.toString();
46
46
  }
47
47
  }
@@ -4,3 +4,7 @@ export const Is = {
4
4
  instance: (target) => Object.prototype.hasOwnProperty.call(target, 'constructor'),
5
5
  constructor: (target) => typeof target === 'function' && !!target.prototype,
6
6
  };
7
+ export function isSerializable(target) {
8
+ return Is.object(target) && typeof target.toString === 'function' && target.toString !== Object.prototype.toString;
9
+ }
10
+ export const toString = (target) => (isSerializable(target) ? target.toString() : String(target));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-ioc-container",
3
- "version": "69.2.0",
3
+ "version": "70.0.0",
4
4
  "description": "Fast, lightweight TypeScript dependency injection container with a clean API, scoped lifecycles, decorators, tokens, hooks, lazy injection, customizable providers, and no global container objects.",
5
5
  "publishConfig": {
6
6
  "access": "public",
@@ -53,4 +53,4 @@ export { select } from './select.js';
53
53
  export { pipe, type MapFn } from './utils/fp.js';
54
54
  export { findOrFail, type Predicate } from './utils/array.js';
55
55
  export { ProxyRegistry, unwrapProxy, type IProxyRegistry } from './utils/ProxyRegistry.js';
56
- export { type Branded, type constructor, type Instance, Is } from './utils/basic.js';
56
+ export { type Branded, type constructor, type Instance, type Serializable, Is, isSerializable } from './utils/basic.js';
@@ -1,5 +1,6 @@
1
1
  import { IContainer, Tagged } from '../container/IContainer.js';
2
2
  import { InjectOptions } from '../injector/IInjector.js';
3
+ import { Serializable } from '../utils/basic.js';
3
4
  export type WithLazy = {
4
5
  lazy: boolean;
5
6
  };
@@ -12,7 +13,7 @@ export type ScopeAccessOptions = {
12
13
  };
13
14
  export type ScopeAccessRule = (options: ScopeAccessOptions, prev: boolean) => boolean;
14
15
  export type ArgsFn = (l: IContainer, options?: InjectOptions) => unknown[];
15
- export type GetCacheKey = (...args: unknown[]) => string | symbol;
16
+ export type GetCacheKey = (...args: unknown[]) => string | Serializable;
16
17
  export type DecorateFn<Instance = any> = (dep: Instance, scope: IContainer) => Instance;
17
18
  export type ProviderHook = (dependency: unknown, scope: IContainer) => void;
18
19
  export interface IProvider<T = any> {
@@ -1,8 +1,8 @@
1
1
  import { IContainer } from '../container/IContainer.js';
2
2
  import { InjectionToken } from './InjectionToken.js';
3
- import { type constructor } from '../utils/basic.js';
3
+ import { type constructor, Serializable } from '../utils/basic.js';
4
4
  import { ArgsFn, ProviderOptions } from '../provider/IProvider.js';
5
- export declare class ClassToken<T = any> extends InjectionToken<T> {
5
+ export declare class ClassToken<T = any> extends InjectionToken<T> implements Serializable {
6
6
  private readonly target;
7
7
  private readonly _getArgsFn;
8
8
  private readonly _isLazy;
@@ -15,5 +15,5 @@ export declare class ClassToken<T = any> extends InjectionToken<T> {
15
15
  args(...newArgs: unknown[]): ClassToken<T>;
16
16
  argsFn(fn: (s: IContainer) => unknown[]): ClassToken<T>;
17
17
  lazy(): ClassToken<T>;
18
- getKey(): constructor<T>;
18
+ toString(): string;
19
19
  }
@@ -1,12 +1,12 @@
1
- import type { DependencyKey, IContainer } from '../container/IContainer.js';
1
+ import type { IContainer } from '../container/IContainer.js';
2
2
  import { InjectionToken } from './InjectionToken.js';
3
- import { type constructor } from '../utils/basic.js';
4
- export declare class ConstantToken<T = any> extends InjectionToken<T> {
3
+ import { Serializable } from '../utils/basic.js';
4
+ export declare class ConstantToken<T = any> extends InjectionToken<T> implements Serializable {
5
5
  private readonly token;
6
6
  constructor(token: T);
7
7
  resolve(s: IContainer): T;
8
8
  args(...deps: unknown[]): InjectionToken<T>;
9
9
  argsFn(getArgsFn: (s: IContainer) => unknown[]): InjectionToken<T>;
10
10
  lazy(): InjectionToken<T>;
11
- getKey(): DependencyKey | constructor<T>;
11
+ toString(): string;
12
12
  }
@@ -1,9 +1,9 @@
1
- import type { DependencyKey, IContainer } from '../container/IContainer.js';
1
+ import type { IContainer } from '../container/IContainer.js';
2
2
  import { InjectionToken } from './InjectionToken.js';
3
3
  import { InjectFn } from '../hooks/hook.js';
4
4
  import { ArgsFn, ProviderOptions } from '../provider/IProvider.js';
5
- import { type constructor } from '../utils/basic.js';
6
- export declare class FunctionToken<T = any> extends InjectionToken<T> {
5
+ import { Serializable } from '../utils/basic.js';
6
+ export declare class FunctionToken<T = any> extends InjectionToken<T> implements Serializable {
7
7
  private readonly fn;
8
8
  private readonly _getArgsFn;
9
9
  private readonly _isLazy;
@@ -15,5 +15,5 @@ export declare class FunctionToken<T = any> extends InjectionToken<T> {
15
15
  args(...newArgs: unknown[]): InjectionToken<T>;
16
16
  argsFn(fn: (s: IContainer) => unknown[]): InjectionToken<T>;
17
17
  lazy(): InjectionToken<T>;
18
- getKey(): DependencyKey | constructor<T>;
18
+ toString(): string;
19
19
  }
@@ -3,7 +3,8 @@ import { InjectionToken } from './InjectionToken.js';
3
3
  import { IRegistration } from '../registration/IRegistration.js';
4
4
  import { BindToken } from './BindToken.js';
5
5
  import { ArgsFn, ProviderOptions } from '../provider/IProvider.js';
6
- export declare class GroupAliasToken<T = any> extends InjectionToken<T[]> implements BindToken<T> {
6
+ import { Serializable } from '../utils/basic.js';
7
+ export declare class GroupAliasToken<T = any> extends InjectionToken<T[]> implements BindToken<T>, Serializable {
7
8
  readonly token: DependencyKey;
8
9
  private readonly _getArgsFn;
9
10
  private readonly _isLazy;
@@ -17,6 +18,6 @@ export declare class GroupAliasToken<T = any> extends InjectionToken<T[]> implem
17
18
  args(...newArgs: unknown[]): GroupAliasToken<T>;
18
19
  argsFn(fn: (s: IContainer) => unknown[]): GroupAliasToken<T>;
19
20
  lazy(): GroupAliasToken<T>;
20
- getKey(): DependencyKey;
21
+ toString(): string;
21
22
  }
22
23
  export declare const toGroupAlias: <T>(token: DependencyKey) => GroupAliasToken<T>;
@@ -1,8 +1,8 @@
1
1
  import { InjectionToken } from './InjectionToken.js';
2
- import type { DependencyKey, IContainer } from '../container/IContainer.js';
3
- import { type constructor, Instance } from '../utils/basic.js';
2
+ import type { IContainer } from '../container/IContainer.js';
3
+ import { Instance, Serializable } from '../utils/basic.js';
4
4
  export type InstancePredicate = (dep: unknown) => boolean;
5
- export declare class GroupInstanceToken extends InjectionToken<Instance[]> {
5
+ export declare class GroupInstanceToken extends InjectionToken<Instance[]> implements Serializable {
6
6
  private predicate;
7
7
  private isCascade;
8
8
  constructor(predicate: InstancePredicate);
@@ -12,5 +12,5 @@ export declare class GroupInstanceToken extends InjectionToken<Instance[]> {
12
12
  lazy(): InjectionToken<Instance[]>;
13
13
  cascade(isTrue: boolean): this;
14
14
  resolve(c: IContainer): Instance[];
15
- getKey(): DependencyKey | constructor<Instance[]>;
15
+ toString(): string;
16
16
  }
@@ -1,12 +1,10 @@
1
- import { type DependencyKey, type IContainer } from '../container/IContainer.js';
1
+ import { type IContainer } from '../container/IContainer.js';
2
2
  import { ArgsFn, ProviderOptions } from '../provider/IProvider.js';
3
- import { type constructor } from '../utils/basic.js';
4
3
  export declare const forwardArgs: ArgsFn;
5
4
  export declare abstract class InjectionToken<T = any> {
6
5
  abstract resolve(s: IContainer, options?: ProviderOptions): T;
7
6
  abstract args(...deps: unknown[]): InjectionToken<T>;
8
7
  abstract argsFn(getArgsFn: (s: IContainer) => unknown[]): InjectionToken<T>;
9
8
  abstract lazy(): InjectionToken<T>;
10
- abstract getKey(): DependencyKey | constructor<T>;
11
9
  }
12
10
  export declare function isInjectionToken(target: unknown): target is InjectionToken;
@@ -3,7 +3,8 @@ import { InjectionToken } from './InjectionToken.js';
3
3
  import { IRegistration } from '../registration/IRegistration.js';
4
4
  import { BindToken } from './BindToken.js';
5
5
  import { ArgsFn } from '../provider/IProvider.js';
6
- export declare class SingleAliasToken<T = any> extends InjectionToken<T> implements BindToken<T> {
6
+ import { Serializable } from '../utils/basic.js';
7
+ export declare class SingleAliasToken<T = any> extends InjectionToken<T> implements BindToken<T>, Serializable {
7
8
  readonly token: DependencyKey;
8
9
  private readonly _getArgsFn;
9
10
  private readonly _isLazy;
@@ -17,6 +18,6 @@ export declare class SingleAliasToken<T = any> extends InjectionToken<T> impleme
17
18
  args(...newArgs: unknown[]): SingleAliasToken<T>;
18
19
  argsFn(fn: (s: IContainer) => unknown[]): SingleAliasToken<T>;
19
20
  lazy(): SingleAliasToken<T>;
20
- getKey(): DependencyKey;
21
+ toString(): string;
21
22
  }
22
23
  export declare const toSingleAlias: <T>(token: DependencyKey) => SingleAliasToken<T>;
@@ -2,7 +2,8 @@ import { DependencyKey, IContainer } from '../container/IContainer.js';
2
2
  import { InjectionToken } from './InjectionToken.js';
3
3
  import { IRegistration } from '../registration/IRegistration.js';
4
4
  import { ArgsFn, ProviderOptions } from '../provider/IProvider.js';
5
- export declare class SingleToken<T = any> extends InjectionToken<T> {
5
+ import { Serializable } from '../utils/basic.js';
6
+ export declare class SingleToken<T = any> extends InjectionToken<T> implements Serializable {
6
7
  token: DependencyKey;
7
8
  private readonly _getArgsFn;
8
9
  private readonly _isLazy;
@@ -16,5 +17,5 @@ export declare class SingleToken<T = any> extends InjectionToken<T> {
16
17
  args(...newArgs: unknown[]): SingleToken<T>;
17
18
  argsFn(fn: (s: IContainer) => unknown[]): SingleToken<T>;
18
19
  lazy(): SingleToken<T>;
19
- getKey(): DependencyKey;
20
+ toString(): string;
20
21
  }
@@ -1,4 +1,7 @@
1
1
  export type constructor<T> = new (...args: any[]) => T;
2
+ export interface Serializable {
3
+ toString(): string;
4
+ }
2
5
  export type Branded<TBrand extends string, T> = T & {
3
6
  readonly __brand?: TBrand;
4
7
  };
@@ -9,3 +12,5 @@ export declare const Is: {
9
12
  instance: (target: unknown) => target is Instance;
10
13
  constructor: (target: unknown) => target is constructor<unknown>;
11
14
  };
15
+ export declare function isSerializable(target: unknown): target is Serializable;
16
+ export declare const toString: (target: unknown) => string;