@tstdl/base 0.86.0-beta9 → 0.86.1

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.
Files changed (55) hide show
  1. package/application/application.js +0 -1
  2. package/browser/browser-context-controller.d.ts +2 -2
  3. package/browser/browser-context-controller.js +6 -7
  4. package/browser/browser-controller.js +6 -7
  5. package/core.d.ts +2 -4
  6. package/core.js +2 -9
  7. package/database/mongo/module.js +8 -8
  8. package/disposable/async-disposer.d.ts +8 -7
  9. package/disposable/async-disposer.js +49 -23
  10. package/disposable/disposable.d.ts +5 -4
  11. package/disposable/disposable.js +9 -5
  12. package/injector/injector.d.ts +5 -2
  13. package/injector/injector.js +59 -23
  14. package/injector/interfaces.d.ts +4 -3
  15. package/injector/provider.d.ts +12 -12
  16. package/injector/resolve.error.d.ts +1 -1
  17. package/injector/types.d.ts +16 -7
  18. package/logger/console/logger.js +2 -2
  19. package/module/modules/web-server.module.js +0 -2
  20. package/object-storage/object-storage-provider.d.ts +1 -1
  21. package/object-storage/s3/s3.object-storage-provider.d.ts +1 -6
  22. package/object-storage/s3/s3.object-storage-provider.js +2 -12
  23. package/object-storage/s3/s3.object-storage.js +4 -1
  24. package/package.json +7 -6
  25. package/polyfills.d.ts +159 -0
  26. package/polyfills.js +2 -0
  27. package/queue/mongo/mongo-job.repository.js +3 -4
  28. package/search-index/elastic/module.js +4 -4
  29. package/tsconfig.json +1 -1
  30. package/utils/cancellation-token.d.ts +19 -17
  31. package/utils/cancellation-token.js +20 -19
  32. package/_container/container.d.ts +0 -99
  33. package/_container/container.js +0 -443
  34. package/_container/decorators.d.ts +0 -76
  35. package/_container/decorators.js +0 -110
  36. package/_container/index.d.ts +0 -10
  37. package/_container/index.js +0 -27
  38. package/_container/interfaces.d.ts +0 -16
  39. package/_container/interfaces.js +0 -26
  40. package/_container/provider.d.ts +0 -35
  41. package/_container/provider.js +0 -60
  42. package/_container/resolve-chain.d.ts +0 -27
  43. package/_container/resolve-chain.js +0 -105
  44. package/_container/resolve.error.d.ts +0 -5
  45. package/_container/resolve.error.js +0 -36
  46. package/_container/token.d.ts +0 -18
  47. package/_container/token.js +0 -41
  48. package/_container/type-info.d.ts +0 -18
  49. package/_container/type-info.js +0 -16
  50. package/_container/types.d.ts +0 -9
  51. package/_container/types.js +0 -16
  52. package/_container/utils.d.ts +0 -3
  53. package/_container/utils.js +0 -44
  54. package/global-this.d.ts +0 -1
  55. package/global-this.js +0 -37
@@ -1,76 +0,0 @@
1
- import type { Decorator } from '../reflection/index.js';
2
- import type { Constructor, OneOrMany, Simplify, TypedOmit } from '../types.js';
3
- import type { RegistrationOptions } from './container.js';
4
- import type { Provider } from './provider.js';
5
- import type { InjectionToken } from './token.js';
6
- import type { ArgumentProvider, ForwardRefInjectionToken, Mapper } from './types.js';
7
- type InjectDecorator = Decorator<'property' | 'accessor' | 'constructorParameter'>;
8
- export type InjectableOptions<T, A> = RegistrationOptions<T> & {
9
- /** aliases (tokens) for the class. Useful for example for circular dependencies when you can't use the class itself as a token */
10
- alias?: OneOrMany<InjectionToken>;
11
- /** custom provider. Useful for example if initialization is required */
12
- provider?: Provider<T, A>;
13
- };
14
- export type InjectableOptionsWithoutLifecycle<T, A> = Simplify<TypedOmit<InjectableOptions<T, A>, 'lifecycle'>>;
15
- /**
16
- * Helper decorator to replace a class definition with an other
17
- * can be used for example to type external classes with the {@link Injectable} interface
18
- * @param constructor class to replace with
19
- */
20
- export declare function replaceClass<T>(constructor: Constructor<T>): ClassDecorator;
21
- /**
22
- * registers the class in the global container. Decorated class is not modified in any way
23
- * @param options registration options
24
- */
25
- export declare function injectable<T = any, A = any>(options?: InjectableOptions<T, A>): ClassDecorator;
26
- /**
27
- * registers the class in the global container with singleton lifecycle. Decorated class is not modified in any way
28
- * @param options registration options
29
- */
30
- export declare function singleton<T = any, A = any>(options?: InjectableOptionsWithoutLifecycle<T, A>): ClassDecorator;
31
- /**
32
- * registers the class in the global container with scoped lifecycle. Decorated class is not modified in any way
33
- * @param options registration options
34
- */
35
- export declare function scoped<T = any, A = any>(lifecycle: 'resolution', options?: InjectableOptionsWithoutLifecycle<T, A>): ClassDecorator;
36
- /**
37
- * sets the token used to resolve the parameter
38
- * @param token token used for resolving
39
- * @param argument resolve argument
40
- * @param mapperOrKey map the resolved value. If {@link PropertyKey} is provided, that property of the resolved value will be injected
41
- */
42
- export declare function inject<T, A>(token?: InjectionToken<T, A>, argument?: A, mapperOrKey?: Mapper<T> | keyof T): InjectDecorator;
43
- /**
44
- * sets the argument used for resolving the parameter
45
- * @param argument
46
- */
47
- export declare function resolveArg<T>(argument: T): InjectDecorator;
48
- /**
49
- * sets the argument provider used for resolving the parameter
50
- * @param argumentProvider
51
- */
52
- export declare function resolveArgProvider<T>(argumentProvider: ArgumentProvider<T>): InjectDecorator;
53
- /**
54
- * injects the argument used for resolving the class instead of resolving the parameter
55
- * @param argument
56
- * @param mapperOrKey map the resolved value. If {@link PropertyKey} is provided, that property of the resolved value will be injected
57
- */
58
- export declare function injectArg<T>(mapperOrKey?: Mapper<T> | keyof T): InjectDecorator;
59
- /**
60
- * sets the argument used for resolving the decorated parameter to the the argument provided for parent resolve
61
- * @param mapper map the argument (for example to select a property instead of forwarding the whole object)
62
- */
63
- export declare function forwardArg(): InjectDecorator;
64
- export declare function forwardArg<T, U>(mapper: Mapper<T, U>): InjectDecorator;
65
- /**
66
- * marks the argument as optional
67
- * @param argument
68
- */
69
- export declare function optional(): InjectDecorator;
70
- /**
71
- * resolve using ForwardRef to handle circular dependencies. Resolve logic derefs all ForwardRefs which are direct properties of resolved instances automatically
72
- * @param token token to resolve
73
- * @param argument resolve argument
74
- */
75
- export declare function forwardRef<T extends object, A>(token: ForwardRefInjectionToken<T>, argument?: A): InjectDecorator;
76
- export {};
@@ -1,110 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var decorators_exports = {};
20
- __export(decorators_exports, {
21
- forwardArg: () => forwardArg,
22
- forwardRef: () => forwardRef,
23
- inject: () => inject,
24
- injectArg: () => injectArg,
25
- injectable: () => injectable,
26
- optional: () => optional,
27
- replaceClass: () => replaceClass,
28
- resolveArg: () => resolveArg,
29
- resolveArgProvider: () => resolveArgProvider,
30
- scoped: () => scoped,
31
- singleton: () => singleton
32
- });
33
- module.exports = __toCommonJS(decorators_exports);
34
- var import_reflection = require("../reflection/index.js");
35
- var import_array = require("../utils/array/array.js");
36
- var import_type_guards = require("../utils/type-guards.js");
37
- var import_container = require("./container.js");
38
- function replaceClass(constructor) {
39
- return (0, import_reflection.createClassDecorator)({ handler: () => constructor });
40
- }
41
- function injectable(options = {}) {
42
- return (0, import_reflection.createClassDecorator)({
43
- data: { [import_container.injectMetadataSymbol]: {} },
44
- mergeData: true,
45
- handler: (data) => {
46
- const { alias: aliases, provider, ...registrationOptions } = options;
47
- const targetProvider = provider ?? { useClass: data.constructor };
48
- import_container.container.register(data.constructor, targetProvider, registrationOptions);
49
- if ((0, import_type_guards.isDefined)(aliases)) {
50
- for (const alias of (0, import_array.toArray)(aliases)) {
51
- import_container.container.register(alias, { useToken: data.constructor }, registrationOptions);
52
- }
53
- }
54
- }
55
- });
56
- }
57
- function singleton(options = {}) {
58
- return injectable({ ...options, lifecycle: "singleton" });
59
- }
60
- function scoped(lifecycle, options = {}) {
61
- return injectable({ ...options, lifecycle });
62
- }
63
- function inject(token, argument, mapperOrKey) {
64
- const injectMetadata = {};
65
- if ((0, import_type_guards.isDefined)(token)) {
66
- injectMetadata.injectToken = token;
67
- }
68
- if ((0, import_type_guards.isDefined)(argument)) {
69
- injectMetadata.resolveArgumentProvider = () => argument;
70
- }
71
- if ((0, import_type_guards.isDefined)(mapperOrKey)) {
72
- injectMetadata.mapper = (0, import_type_guards.isFunction)(mapperOrKey) ? mapperOrKey : (value) => value[mapperOrKey];
73
- }
74
- return createInjectDecorator(injectMetadata);
75
- }
76
- function resolveArg(argument) {
77
- return resolveArgProvider(() => argument);
78
- }
79
- function resolveArgProvider(argumentProvider) {
80
- return createInjectDecorator({ resolveArgumentProvider: argumentProvider });
81
- }
82
- function injectArg(mapperOrKey) {
83
- return createInjectDecorator({
84
- injectArgumentMapper: (0, import_type_guards.isFunction)(mapperOrKey) ? mapperOrKey : (0, import_type_guards.isDefined)(mapperOrKey) ? (value) => value[mapperOrKey] : (value) => value
85
- });
86
- }
87
- function forwardArg(mapper = (value) => value) {
88
- return createInjectDecorator({ forwardArgumentMapper: mapper });
89
- }
90
- function optional() {
91
- return createInjectDecorator({ optional: true });
92
- }
93
- function forwardRef(token, argument) {
94
- const injectMetadata = {
95
- forwardRefToken: token
96
- };
97
- if ((0, import_type_guards.isDefined)(argument)) {
98
- injectMetadata.resolveArgumentProvider = () => argument;
99
- }
100
- return createInjectDecorator(injectMetadata);
101
- }
102
- function createInjectDecorator(metadata) {
103
- return (0, import_reflection.createDecorator)({
104
- property: true,
105
- accessor: true,
106
- constructorParameter: true,
107
- data: { [import_container.injectMetadataSymbol]: metadata },
108
- mergeData: true
109
- });
110
- }
@@ -1,10 +0,0 @@
1
- export * from './container.js';
2
- export * from './decorators.js';
3
- export * from './interfaces.js';
4
- export * from './provider.js';
5
- export * from './resolve-chain.js';
6
- export * from './resolve.error.js';
7
- export * from './token.js';
8
- export * from './type-info.js';
9
- export * from './types.js';
10
- export * from './utils.js';
@@ -1,27 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
- var container_exports = {};
17
- module.exports = __toCommonJS(container_exports);
18
- __reExport(container_exports, require("./container.js"), module.exports);
19
- __reExport(container_exports, require("./decorators.js"), module.exports);
20
- __reExport(container_exports, require("./interfaces.js"), module.exports);
21
- __reExport(container_exports, require("./provider.js"), module.exports);
22
- __reExport(container_exports, require("./resolve-chain.js"), module.exports);
23
- __reExport(container_exports, require("./resolve.error.js"), module.exports);
24
- __reExport(container_exports, require("./token.js"), module.exports);
25
- __reExport(container_exports, require("./type-info.js"), module.exports);
26
- __reExport(container_exports, require("./types.js"), module.exports);
27
- __reExport(container_exports, require("./utils.js"), module.exports);
@@ -1,16 +0,0 @@
1
- export declare const resolveArgumentType: unique symbol;
2
- export declare const afterResolve: unique symbol;
3
- export type InjectableArgument<T, Fallback> = T extends Injectable<infer A> ? A : Fallback;
4
- export interface Injectable<T = unknown> {
5
- /**
6
- * type of resolve argument
7
- * @deprecated only used for type inference
8
- */
9
- readonly [resolveArgumentType]: T;
10
- }
11
- export interface AfterResolve {
12
- /**
13
- * called after resolve through container
14
- */
15
- [afterResolve](): void | Promise<void>;
16
- }
@@ -1,26 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var interfaces_exports = {};
20
- __export(interfaces_exports, {
21
- afterResolve: () => afterResolve,
22
- resolveArgumentType: () => resolveArgumentType
23
- });
24
- module.exports = __toCommonJS(interfaces_exports);
25
- const resolveArgumentType = Symbol("resolveArgumentType");
26
- const afterResolve = Symbol("after resolve");
@@ -1,35 +0,0 @@
1
- import type { Constructor } from '../types.js';
2
- import type { InjectableArgument } from './interfaces.js';
3
- import type { InjectionToken } from './token.js';
4
- import type { ResolveContext } from './types.js';
5
- export type Factory<T, A = any> = (argument: InjectableArgument<T, A> | undefined, context: ResolveContext) => T | Promise<T>;
6
- export type Provider<T = any, A = any> = ClassProvider<T> | ValueProvider<T> | TokenProvider<T, A> | FactoryProvider<T, A>;
7
- export type ClassProvider<T = any> = {
8
- useClass: Constructor<T>;
9
- };
10
- export type ValueProvider<T = any> = {
11
- useValue: T;
12
- };
13
- export type TokenProvider<T = any, A = any> = {
14
- useToken: InjectionToken<T, A>;
15
- useTokenProvider?: undefined;
16
- argument?: InjectableArgument<T, A>;
17
- argumentProvider?: () => InjectableArgument<T, A> | Promise<InjectableArgument<T, A>>;
18
- } | {
19
- useToken?: undefined;
20
- useTokenProvider: () => InjectionToken<T, A> | Promise<InjectionToken<T, A>>;
21
- argument?: InjectableArgument<T, A>;
22
- argumentProvider?: () => InjectableArgument<T, A> | Promise<InjectableArgument<T, A>>;
23
- };
24
- export type FactoryProvider<T = any, A = unknown> = {
25
- useFactory: Factory<T, A>;
26
- };
27
- export declare function classProvider<T>(constructor: Constructor<T>): ClassProvider<T>;
28
- export declare function valueProvider<T>(value: T): ValueProvider<T>;
29
- export declare function tokenProvider<T, A>(token: InjectionToken<T, A>, argument?: InjectableArgument<T, A>): TokenProvider<T>;
30
- export declare function factoryProvider<T, A>(factory: Factory<T, A>): FactoryProvider<T, A>;
31
- export declare function isClassProvider<T>(value: unknown): value is ClassProvider<T>;
32
- export declare function isValueProvider<T>(value: unknown): value is ValueProvider<T>;
33
- export declare function isTokenProvider<T>(value: unknown): value is TokenProvider<T>;
34
- export declare function isFactoryProvider<T, A>(value: unknown): value is FactoryProvider<T, A>;
35
- export declare function isProvider<T, A>(value: unknown): value is Provider<T, A>;
@@ -1,60 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var provider_exports = {};
20
- __export(provider_exports, {
21
- classProvider: () => classProvider,
22
- factoryProvider: () => factoryProvider,
23
- isClassProvider: () => isClassProvider,
24
- isFactoryProvider: () => isFactoryProvider,
25
- isProvider: () => isProvider,
26
- isTokenProvider: () => isTokenProvider,
27
- isValueProvider: () => isValueProvider,
28
- tokenProvider: () => tokenProvider,
29
- valueProvider: () => valueProvider
30
- });
31
- module.exports = __toCommonJS(provider_exports);
32
- var import_object = require("../utils/object/object.js");
33
- var import_type_guards = require("../utils/type-guards.js");
34
- function classProvider(constructor) {
35
- return { useClass: constructor };
36
- }
37
- function valueProvider(value) {
38
- return { useValue: value };
39
- }
40
- function tokenProvider(token, argument) {
41
- return { useToken: token, argument };
42
- }
43
- function factoryProvider(factory) {
44
- return { useFactory: factory };
45
- }
46
- function isClassProvider(value) {
47
- return (0, import_type_guards.isObject)(value) && (0, import_object.hasOwnProperty)(value, "useClass");
48
- }
49
- function isValueProvider(value) {
50
- return (0, import_type_guards.isObject)(value) && (0, import_object.hasOwnProperty)(value, "useValue");
51
- }
52
- function isTokenProvider(value) {
53
- return (0, import_type_guards.isObject)(value) && ((0, import_object.hasOwnProperty)(value, "useToken") || (0, import_object.hasOwnProperty)(value, "useTokenProvider"));
54
- }
55
- function isFactoryProvider(value) {
56
- return (0, import_type_guards.isObject)(value) && (0, import_object.hasOwnProperty)(value, "useFactory");
57
- }
58
- function isProvider(value) {
59
- return (0, import_type_guards.isObject)(value) && (isClassProvider(value) || isValueProvider(value) || isTokenProvider(value) || isFactoryProvider(value));
60
- }
@@ -1,27 +0,0 @@
1
- import type { AbstractConstructor } from '../types.js';
2
- import type { InjectionToken } from './token.js';
3
- export type ResolveChainNodeBase<Type extends string> = {
4
- type: Type;
5
- };
6
- export type ResolveChainNode = ResolveChainNodeBase<'token'> & {
7
- token: InjectionToken;
8
- } | ResolveChainNodeBase<'parameter'> & {
9
- constructor: AbstractConstructor;
10
- index: number;
11
- token: InjectionToken;
12
- } | ResolveChainNodeBase<'property'> & {
13
- constructor: AbstractConstructor;
14
- property: PropertyKey;
15
- token: InjectionToken;
16
- };
17
- export declare class ResolveChain {
18
- readonly nodes: readonly ResolveChainNode[];
19
- get length(): number;
20
- constructor(nodes?: ResolveChainNode[]);
21
- static startWith(token: InjectionToken): ResolveChain;
22
- addToken(token: InjectionToken): ResolveChain;
23
- addParameter(constructor: AbstractConstructor, index: number, token: InjectionToken): ResolveChain;
24
- addProperty(constructor: AbstractConstructor, property: PropertyKey, token: InjectionToken): ResolveChain;
25
- format(truncate?: number): string;
26
- truncate(tokenCount: number): ResolveChain;
27
- }
@@ -1,105 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var resolve_chain_exports = {};
20
- __export(resolve_chain_exports, {
21
- ResolveChain: () => ResolveChain
22
- });
23
- module.exports = __toCommonJS(resolve_chain_exports);
24
- var import_reflection = require("../reflection/index.js");
25
- var import_type_guards = require("../utils/type-guards.js");
26
- var import_token = require("./token.js");
27
- class ResolveChain {
28
- nodes;
29
- get length() {
30
- return this.nodes.length;
31
- }
32
- constructor(nodes) {
33
- this.nodes = nodes ?? [];
34
- }
35
- static startWith(token) {
36
- const chain = new ResolveChain();
37
- return chain.addToken(token);
38
- }
39
- addToken(token) {
40
- const node = { type: "token", token };
41
- return new ResolveChain([...this.nodes, node]);
42
- }
43
- addParameter(constructor, index, token) {
44
- const node = { type: "parameter", constructor, index, token };
45
- return new ResolveChain([...this.nodes, node]);
46
- }
47
- addProperty(constructor, property, token) {
48
- const node = { type: "property", constructor, property, token };
49
- return new ResolveChain([...this.nodes, node]);
50
- }
51
- format(truncate) {
52
- let chainString = "";
53
- const chain = (0, import_type_guards.isDefined)(truncate) ? this.truncate(truncate) : this;
54
- if (chain.length < this.length) {
55
- chainString += "\n [...]";
56
- }
57
- for (const node of chain.nodes) {
58
- const tokenName = (0, import_token.getTokenName)(node.token);
59
- switch (node.type) {
60
- case "token":
61
- chainString += `
62
- -> ${tokenName}`;
63
- break;
64
- case "parameter":
65
- const metadata = import_reflection.reflectionRegistry.getMetadata(node.constructor);
66
- const prefix = "_, ".repeat(node.index);
67
- const suffix = ", _".repeat((0, import_type_guards.assertDefinedPass)(metadata?.parameters, "missing parameters metadata").length - node.index - 1);
68
- chainString += `(${prefix}${tokenName}${suffix})`;
69
- break;
70
- case "property":
71
- const constructorName = (0, import_token.getTokenName)(node.constructor);
72
- const key = getPropertyKeyString(node.property);
73
- chainString += `
74
- -> ${constructorName}[${key}]: ${tokenName}`;
75
- break;
76
- default:
77
- throw new Error(`unknown chain node type ${node.type}`);
78
- }
79
- }
80
- return chainString;
81
- }
82
- truncate(tokenCount) {
83
- const truncatedChain = [];
84
- let counter = 0;
85
- for (let i = this.nodes.length - 1; i >= 0 && counter < tokenCount; i--) {
86
- const node = this.nodes[i];
87
- truncatedChain.unshift(node);
88
- if (node.type == "token") {
89
- counter++;
90
- }
91
- }
92
- return new ResolveChain(truncatedChain);
93
- }
94
- }
95
- function getPropertyKeyString(key) {
96
- switch (typeof key) {
97
- case "number":
98
- case "symbol":
99
- return key.toString();
100
- case "string":
101
- return `'${key}'`;
102
- default:
103
- throw new Error(`unsupported key type ${typeof key}`);
104
- }
105
- }
@@ -1,5 +0,0 @@
1
- import { CustomError } from '../error/custom.error.js';
2
- import type { ResolveChain } from './resolve-chain.js';
3
- export declare class ResolveError extends CustomError {
4
- constructor(message: string, chain: ResolveChain, cause?: Error);
5
- }
@@ -1,36 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var resolve_error_exports = {};
20
- __export(resolve_error_exports, {
21
- ResolveError: () => ResolveError
22
- });
23
- module.exports = __toCommonJS(resolve_error_exports);
24
- var import_custom_error = require("../error/custom.error.js");
25
- var import_type_guards = require("../utils/type-guards.js");
26
- class ResolveError extends import_custom_error.CustomError {
27
- constructor(message, chain, cause) {
28
- const causeMessage = (0, import_type_guards.isDefined)(cause) ? `
29
- cause: ${cause.message}` : "";
30
- super({
31
- message: `${message}${causeMessage}
32
- chain: ${chain.format(15)}`,
33
- cause
34
- });
35
- }
36
- }
@@ -1,18 +0,0 @@
1
- import type { AbstractConstructor, EnumerationObject } from '../types.js';
2
- declare const type: unique symbol;
3
- declare const argument: unique symbol;
4
- export type ArgumentedInjectionToken<T, A> = SimpleInjectionToken<T> & {
5
- [argument]?: A;
6
- };
7
- export type SimpleInjectionToken<T> = AbstractConstructor<T> | EnumerationObject;
8
- export type InjectionToken<T = any, A = any> = SimpleInjectionToken<T> | ArgumentedInjectionToken<T, A> | ReifyingInjectionToken<T, A>;
9
- export declare class ReifyingInjectionToken<T = any, A = any> {
10
- private readonly [type];
11
- private readonly [argument];
12
- readonly description: string;
13
- constructor(description: string);
14
- toString(): string;
15
- }
16
- export declare function injectionToken<T, A = any>(description: string): InjectionToken<T, A>;
17
- export declare function getTokenName(token: InjectionToken | undefined): string;
18
- export {};
@@ -1,41 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var token_exports = {};
20
- __export(token_exports, {
21
- ReifyingInjectionToken: () => ReifyingInjectionToken,
22
- getTokenName: () => getTokenName,
23
- injectionToken: () => injectionToken
24
- });
25
- module.exports = __toCommonJS(token_exports);
26
- var import_type_guards = require("../utils/type-guards.js");
27
- class ReifyingInjectionToken {
28
- description;
29
- constructor(description) {
30
- this.description = description;
31
- }
32
- toString() {
33
- return `InjectionToken["${this.description}"]`;
34
- }
35
- }
36
- function injectionToken(description) {
37
- return new ReifyingInjectionToken(description);
38
- }
39
- function getTokenName(token) {
40
- return (0, import_type_guards.isFunction)(token) ? token.name : (0, import_type_guards.isString)(token) ? `"${token}"` : String(token);
41
- }
@@ -1,18 +0,0 @@
1
- import type { InjectionToken } from './token.js';
2
- import type { ArgumentProvider, ForwardRefInjectionToken, Mapper } from './types.js';
3
- export type InjectMetadata = {
4
- /** token overwrite by inject decorator */
5
- injectToken?: InjectionToken;
6
- /** if defined, resolve the ForwardRefToken using ForwardRef strategy instead resolving the token */
7
- forwardRefToken?: ForwardRefInjectionToken;
8
- /** whether injection is optional if token is not registered. Set by optional decorator */
9
- optional?: boolean;
10
- /** mapper to map resolved value */
11
- mapper?: Mapper;
12
- /** provider to get resolve argument */
13
- resolveArgumentProvider?: ArgumentProvider;
14
- /** if defined, map the resolve argument and use the returned value as the value to inject */
15
- injectArgumentMapper?: Mapper;
16
- /** if defined, use the provided argument, map it and pass it to the resolution of the token */
17
- forwardArgumentMapper?: Mapper;
18
- };
@@ -1,16 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
- var type_info_exports = {};
16
- module.exports = __toCommonJS(type_info_exports);
@@ -1,9 +0,0 @@
1
- import type { AbstractConstructor } from '../types.js';
2
- import type { Container } from './container.js';
3
- import type { InjectionToken } from './token.js';
4
- export type ResolveContext = Pick<Container, 'resolve' | 'resolveAsync'> & {
5
- isAsync: boolean;
6
- };
7
- export type Mapper<T = any, U = unknown> = (value: T) => U | Promise<U>;
8
- export type ArgumentProvider<T = unknown> = (context: ResolveContext) => T | Promise<T>;
9
- export type ForwardRefInjectionToken<T = any, A = any> = Exclude<InjectionToken<T, A>, AbstractConstructor> | (() => InjectionToken<T, A>);