@venizia/ignis-inversion 0.4.7-0 → 0.4.7-2
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/dist/esm/common/base-helper.d.ts +2 -0
- package/dist/esm/common/base-helper.js +1 -0
- package/dist/esm/common/base-helper.js.map +1 -1
- package/dist/esm/common/logger.d.ts +1 -0
- package/dist/esm/common/logger.js +1 -0
- package/dist/esm/common/logger.js.map +1 -1
- package/dist/esm/common/types.d.ts +13 -0
- package/dist/esm/common/types.js.map +1 -1
- package/dist/esm/modules/binding/binding.d.ts +1 -0
- package/dist/esm/modules/binding/binding.js +1 -0
- package/dist/esm/modules/binding/binding.js.map +1 -1
- package/dist/esm/modules/binding/common/constants.d.ts +5 -0
- package/dist/esm/modules/binding/common/constants.js +3 -0
- package/dist/esm/modules/binding/common/constants.js.map +1 -1
- package/dist/esm/modules/binding/common/types.d.ts +4 -0
- package/dist/esm/modules/binding/common/types.js +1 -0
- package/dist/esm/modules/binding/common/types.js.map +1 -1
- package/dist/esm/modules/container/base.d.ts +6 -1
- package/dist/esm/modules/container/base.js +6 -1
- package/dist/esm/modules/container/base.js.map +1 -1
- package/dist/esm/modules/container/common/types.d.ts +1 -0
- package/dist/esm/modules/container/common/types.js.map +1 -1
- package/dist/esm/modules/container/verifier.d.ts +3 -0
- package/dist/esm/modules/container/verifier.js.map +1 -1
- package/dist/esm/modules/error/app-error.d.ts +4 -0
- package/dist/esm/modules/error/app-error.js +3 -0
- package/dist/esm/modules/error/app-error.js.map +1 -1
- package/dist/esm/modules/error/common/types.d.ts +4 -0
- package/dist/esm/modules/error/common/types.js.map +1 -1
- package/dist/esm/modules/error/definition.d.ts +2 -0
- package/dist/esm/modules/error/definition.js +1 -0
- package/dist/esm/modules/error/definition.js.map +1 -1
- package/dist/esm/modules/error/message-code.d.ts +1 -0
- package/dist/esm/modules/error/message-code.js +1 -0
- package/dist/esm/modules/error/message-code.js.map +1 -1
- package/dist/esm/modules/metadata/common/constants.d.ts +1 -0
- package/dist/esm/modules/metadata/common/constants.js +1 -0
- package/dist/esm/modules/metadata/common/constants.js.map +1 -1
- package/dist/esm/modules/registry/common/types.d.ts +2 -0
- package/dist/esm/modules/registry/common/types.js.map +1 -1
- package/dist/esm/modules/registry/registry.d.ts +1 -0
- package/dist/esm/modules/registry/registry.js +1 -0
- package/dist/esm/modules/registry/registry.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-helper.js","sourceRoot":"","sources":["../../../src/common/base-helper.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,UAAU;
|
|
1
|
+
{"version":3,"file":"base-helper.js","sourceRoot":"","sources":["../../../src/common/base-helper.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,MAAM,OAAO,UAAU;IAMrB,YAAY,IAA4C;QACtD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;QAC9B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,IAAI,EAAE,CAAC;IAC1C,CAAC;CACF","sourcesContent":["/** Base for classes that carry a logging `scope` and an optional `identifier`. */\nexport class BaseHelper {\n scope: string;\n\n /** @default '' */\n identifier: string;\n\n constructor(opts: { scope: string; identifier?: string }) {\n this.scope = opts.scope ?? '';\n this.identifier = opts.identifier ?? '';\n }\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** Static console logger with `[INFO]`, `[WARN]`, `[ERROR]` and `[DEBUG]` prefixes. `debug` prints only when enabled through `enableDebug` or when the `DEBUG` environment variable is set at load time. */
|
|
1
2
|
export declare class Logger {
|
|
2
3
|
private static debugEnabled;
|
|
3
4
|
static enableDebug(opts: {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** Static console logger with `[INFO]`, `[WARN]`, `[ERROR]` and `[DEBUG]` prefixes. `debug` prints only when enabled through `enableDebug` or when the `DEBUG` environment variable is set at load time. */
|
|
1
2
|
export class Logger {
|
|
2
3
|
static { this.debugEnabled = Boolean(globalThis.process?.env?.DEBUG); }
|
|
3
4
|
static enableDebug(opts) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../src/common/logger.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,MAAM;aACF,iBAAY,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;IAEtE,MAAM,CAAC,WAAW,CAAC,IAA0B;QAC3C,MAAM,CAAC,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC;IACrC,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,OAAe,EAAE,GAAG,IAAe;QAC7C,OAAO,CAAC,GAAG,CAAC,UAAU,OAAO,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;IAC5C,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,OAAe,EAAE,GAAG,IAAe;QAC7C,OAAO,CAAC,IAAI,CAAC,UAAU,OAAO,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;IAC7C,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,OAAe,EAAE,GAAG,IAAe;QAC9C,OAAO,CAAC,KAAK,CAAC,WAAW,OAAO,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;IAC/C,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,OAAe,EAAE,GAAG,IAAe;QAC9C,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC;YACzB,OAAO;QACT,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,WAAW,OAAO,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;IAC7C,CAAC","sourcesContent":["
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../src/common/logger.ts"],"names":[],"mappings":"AAAA,4MAA4M;AAC5M,MAAM,OAAO,MAAM;aACF,iBAAY,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;IAEtE,MAAM,CAAC,WAAW,CAAC,IAA0B;QAC3C,MAAM,CAAC,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC;IACrC,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,OAAe,EAAE,GAAG,IAAe;QAC7C,OAAO,CAAC,GAAG,CAAC,UAAU,OAAO,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;IAC5C,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,OAAe,EAAE,GAAG,IAAe;QAC7C,OAAO,CAAC,IAAI,CAAC,UAAU,OAAO,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;IAC7C,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,OAAe,EAAE,GAAG,IAAe;QAC9C,OAAO,CAAC,KAAK,CAAC,WAAW,OAAO,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;IAC/C,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,OAAe,EAAE,GAAG,IAAe;QAC9C,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC;YACzB,OAAO;QACT,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,WAAW,OAAO,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;IAC7C,CAAC","sourcesContent":["/** Static console logger with `[INFO]`, `[WARN]`, `[ERROR]` and `[DEBUG]` prefixes. `debug` prints only when enabled through `enableDebug` or when the `DEBUG` environment variable is set at load time. */\nexport class Logger {\n private static debugEnabled = Boolean(globalThis.process?.env?.DEBUG);\n\n static enableDebug(opts: { enabled: boolean }) {\n Logger.debugEnabled = opts.enabled;\n }\n\n static info(message: string, ...args: unknown[]) {\n console.log(`[INFO] ${message}`, ...args);\n }\n\n static warn(message: string, ...args: unknown[]) {\n console.warn(`[WARN] ${message}`, ...args);\n }\n\n static error(message: string, ...args: unknown[]) {\n console.error(`[ERROR] ${message}`, ...args);\n }\n\n static debug(message: string, ...args: unknown[]) {\n if (!Logger.debugEnabled) {\n return;\n }\n\n console.log(`[DEBUG] ${message}`, ...args);\n }\n}\n"]}
|
|
@@ -1,21 +1,34 @@
|
|
|
1
|
+
/** A `T` that may also be `undefined` or `null`. */
|
|
1
2
|
export type TNullable<T> = T | undefined | null;
|
|
3
|
+
/** A `T` or a `Promise` of it, for APIs that accept sync and async results. */
|
|
2
4
|
export type ValueOrPromise<T> = T | Promise<T>;
|
|
5
|
+
/** Union of the property value types of `T`. */
|
|
3
6
|
export type ValueOf<T> = T[keyof T];
|
|
7
|
+
/** Alias of `any`, for places where the type is deliberately unchecked. */
|
|
4
8
|
export type AnyType = any;
|
|
9
|
+
/** A concrete class constructor taking any arguments and producing `T`. */
|
|
5
10
|
export type TConstructor<T> = new (...args: any[]) => T;
|
|
11
|
+
/** Like `TConstructor`, but also matches abstract classes. */
|
|
6
12
|
export type TAbstractConstructor<T> = abstract new (...args: any[]) => T;
|
|
13
|
+
/** A `TConstructor` that also exposes static properties of any name. */
|
|
7
14
|
export type TClass<T> = TConstructor<T> & {
|
|
8
15
|
[property: string]: any;
|
|
9
16
|
};
|
|
17
|
+
/** A function that returns `T` when called. */
|
|
10
18
|
export type TResolver<T> = (...args: any[]) => T;
|
|
19
|
+
/** A function that returns `T` or a `Promise` of `T`. */
|
|
11
20
|
export type TAsyncResolver<T> = (...args: any[]) => T | Promise<T>;
|
|
21
|
+
/** A `T` itself, or a function that returns it. */
|
|
12
22
|
export type TValueOrResolver<T> = T | TResolver<T>;
|
|
23
|
+
/** A `T` itself, or a function that returns it or a `Promise` of it. */
|
|
13
24
|
export type TValueOrAsyncResolver<T> = T | TAsyncResolver<T>;
|
|
14
25
|
/** What `@inject({ target })` names: the class, or a function returning it. The function form defers the reference to resolve time, which is how a class reached through an import cycle stays reachable. */
|
|
15
26
|
export type TInjectTarget = TValueOrResolver<TClass<AnyType>>;
|
|
16
27
|
/** `& {}` keeps the literal set but stops it widening to `string` / `number` in mutable positions; see `TConstValue` in `@venizia/ignis-helpers`. */
|
|
17
28
|
export type TConstValue<T extends TClass<any>> = Extract<ValueOf<T>, string | number> & {};
|
|
29
|
+
/** Identifier for a binding: a string or a symbol. */
|
|
18
30
|
export type TBindingKey = string | symbol;
|
|
31
|
+
/** Free-form map of tag names to values. */
|
|
19
32
|
export interface IBindingTag {
|
|
20
33
|
[name: string]: any;
|
|
21
34
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/common/types.ts"],"names":[],"mappings":"","sourcesContent":["
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/common/types.ts"],"names":[],"mappings":"","sourcesContent":["/** A `T` that may also be `undefined` or `null`. */\nexport type TNullable<T> = T | undefined | null;\n\n/** A `T` or a `Promise` of it, for APIs that accept sync and async results. */\nexport type ValueOrPromise<T> = T | Promise<T>;\n/** Union of the property value types of `T`. */\nexport type ValueOf<T> = T[keyof T];\n\n/** Alias of `any`, for places where the type is deliberately unchecked. */\nexport type AnyType = any;\n\n/** A concrete class constructor taking any arguments and producing `T`. */\nexport type TConstructor<T> = new (...args: any[]) => T;\n/** Like `TConstructor`, but also matches abstract classes. */\nexport type TAbstractConstructor<T> = abstract new (...args: any[]) => T;\n/** A `TConstructor` that also exposes static properties of any name. */\nexport type TClass<T> = TConstructor<T> & { [property: string]: any };\n\n/** A function that returns `T` when called. */\nexport type TResolver<T> = (...args: any[]) => T;\n/** A function that returns `T` or a `Promise` of `T`. */\nexport type TAsyncResolver<T> = (...args: any[]) => T | Promise<T>;\n/** A `T` itself, or a function that returns it. */\nexport type TValueOrResolver<T> = T | TResolver<T>;\n/** A `T` itself, or a function that returns it or a `Promise` of it. */\nexport type TValueOrAsyncResolver<T> = T | TAsyncResolver<T>;\n\n/** What `@inject({ target })` names: the class, or a function returning it. The function form defers the reference to resolve time, which is how a class reached through an import cycle stays reachable. */\nexport type TInjectTarget = TValueOrResolver<TClass<AnyType>>;\n\n/** `& {}` keeps the literal set but stops it widening to `string` / `number` in mutable positions; see `TConstValue` in `@venizia/ignis-helpers`. */\nexport type TConstValue<T extends TClass<any>> = Extract<ValueOf<T>, string | number> & {};\n\n/** Identifier for a binding: a string or a symbol. */\nexport type TBindingKey = string | symbol;\n\n/** Free-form map of tag names to values. */\nexport interface IBindingTag {\n [name: string]: any;\n}\n"]}
|
|
@@ -3,6 +3,7 @@ import { type TClass, type TConstValue } from '../../common/types.js';
|
|
|
3
3
|
import type { IContainer } from '../container/common/types.js';
|
|
4
4
|
import { BindingValueTypes, type TBindingScope } from './common/constants.js';
|
|
5
5
|
import { type IBinding, type TBindingProvider, type TBindingResolverValue } from './common/types.js';
|
|
6
|
+
/** One container entry under `key`, resolved to a class, a value or a provider (set with `toClass`, `toValue`, `toProvider`). Scope is transient unless `setScope` selects singleton; a key with a dot gets its first segment as a tag. */
|
|
6
7
|
export declare class Binding<T = any> extends BaseHelper implements IBinding<T> {
|
|
7
8
|
key: string;
|
|
8
9
|
private bindScope;
|
|
@@ -2,6 +2,7 @@ import { getError } from '../error/index.js';
|
|
|
2
2
|
import { BaseHelper } from '../../common/base-helper.js';
|
|
3
3
|
import { BindingScopes, BindingValueTypes } from './common/constants.js';
|
|
4
4
|
import { isClassProvider, } from './common/types.js';
|
|
5
|
+
/** One container entry under `key`, resolved to a class, a value or a provider (set with `toClass`, `toValue`, `toProvider`). Scope is transient unless `setScope` selects singleton; a key with a dot gets its first segment as a tag. */
|
|
5
6
|
export class Binding extends BaseHelper {
|
|
6
7
|
constructor(opts) {
|
|
7
8
|
super({ scope: opts.key });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"binding.js","sourceRoot":"","sources":["../../../../src/modules/binding/binding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAGlD,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAsB,MAAM,oBAAoB,CAA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G,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;gBACtD,MAAM;YACR,CAAC;YACD,OAAO,CAAC,CAAC,CAAC;gBACR,MAAM,QAAQ,CAAC;oBACb,OAAO,EAAE,8CAA8C,YAAY,EAAE;iBACtE,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAED,IAAI,IAAI,CAAC,SAAS,KAAK,aAAa,CAAC,SAAS,EAAE,CAAC;YAC/C,IAAI,CAAC,MAAM,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;QACpC,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,UAAU;QACR,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;IAC1B,CAAC;CACF","sourcesContent":["import { getError } from '../error';\nimport { BaseHelper } from '@/common/base-helper';\nimport { type TClass, type TConstValue } from '@/common/types';\nimport type { IContainer } from '../container/common/types';\nimport { BindingScopes, BindingValueTypes, type TBindingScope } from './common/constants';\nimport {\n type IBinding,\n isClassProvider,\n type TBindingProvider,\n type TBindingResolverValue,\n} from './common/types';\n\nexport class Binding<T = any> extends BaseHelper implements IBinding<T> {\n key: string;\n\n private bindScope: TBindingScope = BindingScopes.TRANSIENT;\n private tags: Set<string>;\n /** Boxed: a singleton may legitimately be `null`, `false`, `0`, `''` or `undefined`. */\n private cached?: { value: T };\n\n private resolver:\n | { type: typeof BindingValueTypes.CLASS; value: TClass<T> }\n | { type: typeof BindingValueTypes.VALUE; value: T }\n | { type: typeof BindingValueTypes.PROVIDER; value: TBindingProvider<T> };\n\n constructor(opts: { key: string }) {\n super({ scope: opts.key });\n this.tags = new Set([]);\n\n this.key = opts.key;\n\n const keyParts = this.key.split('.');\n\n if (keyParts.length > 1) {\n const [namespace] = keyParts;\n this.setTags(namespace);\n }\n }\n\n static override bind<T = any>(opts: { key: string }): Binding<T> {\n return new Binding<T>(opts);\n }\n\n toClass(value: TClass<T>): this {\n this.resolver = { type: BindingValueTypes.CLASS, value };\n\n return this;\n }\n\n toValue(value: T): this {\n this.resolver = { type: BindingValueTypes.VALUE, value };\n\n return this;\n }\n\n toProvider(value: TBindingProvider<T>): this {\n this.resolver = { type: BindingValueTypes.PROVIDER, value };\n\n return this;\n }\n\n /** The class a `toClass` binding instantiates; `undefined` for a value or a provider. */\n boundClass(): TClass<T> | undefined {\n return this.resolver.type === BindingValueTypes.CLASS ? this.resolver.value : undefined;\n }\n\n getBindingMeta(opts: { type: TConstValue<typeof BindingValueTypes> }): TBindingResolverValue<T> {\n if (this.resolver.type !== opts.type) {\n throw getError({\n message: `[getBindingMeta] Invalid resolver type, only ${this.resolver.type} is allowd | resolverType: ${this.resolver.type} | optType: ${opts.type}`,\n });\n }\n\n return this.resolver.value;\n }\n\n setScope(scope: TBindingScope): this {\n this.bindScope = scope;\n\n return this;\n }\n\n setTags(...tags: string[]): this {\n tags.forEach((t) => this.tags.add(t));\n\n return this;\n }\n\n hasTag(tag: string): boolean {\n return this.tags.has(tag);\n }\n\n getTags(): string[] {\n return Array.from(this.tags);\n }\n\n getScope(): TBindingScope {\n return this.bindScope;\n }\n\n /** True when `getValue` answers without building anything: a cached singleton or a plain value. Nothing it reads can form a cycle. */\n isSettled(): boolean {\n return (\n (this.bindScope === BindingScopes.SINGLETON && this.cached !== undefined) ||\n this.resolver.type === BindingValueTypes.VALUE\n );\n }\n\n getValue(container?: IContainer): T {\n if (this.bindScope === BindingScopes.SINGLETON && this.cached) {\n return this.cached.value;\n }\n\n let instance: T;\n\n const { type: resolverType } = this.resolver;\n\n switch (resolverType) {\n case BindingValueTypes.VALUE: {\n instance = this.resolver.value;\n break;\n }\n case BindingValueTypes.PROVIDER: {\n const provider = this.resolver.value;\n\n if (!container) {\n throw getError({\n message: `[getValue] Invalid context/container to get provider value | type: ${resolverType} | key: ${this.key}`,\n });\n }\n\n if (!isClassProvider(provider)) {\n instance = provider(container);\n break;\n }\n\n const p = container.instantiate(provider);\n instance = p.value(container);\n break;\n }\n case BindingValueTypes.CLASS: {\n if (!container) {\n throw getError({\n message: `[getValue] Invalid context/container to instantiate class | type: ${resolverType} | key: ${this.key}`,\n });\n }\n\n instance = container.instantiate(this.resolver.value);\n break;\n }\n default: {\n throw getError({\n message: `[getValue] Invalid value type | valueType: ${resolverType}`,\n });\n }\n }\n\n if (this.bindScope === BindingScopes.SINGLETON) {\n this.cached = { value: instance };\n }\n\n return instance;\n }\n\n clearCache() {\n this.cached = undefined;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"binding.js","sourceRoot":"","sources":["../../../../src/modules/binding/binding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAGlD,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAsB,MAAM,oBAAoB,CAAC;AAC1F,OAAO,EAEL,eAAe,GAGhB,MAAM,gBAAgB,CAAC;AAExB,2OAA2O;AAC3O,MAAM,OAAO,OAAiB,SAAQ,UAAU;IAa9C,YAAY,IAAqB;QAC/B,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;QAXrB,cAAS,GAAkB,aAAa,CAAC,SAAS,CAAC;QAYzD,IAAI,CAAC,IAAI,GAAG,IAAI,GAAG,CAAC,EAAE,CAAC,CAAC;QAExB,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;QAEpB,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAErC,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACxB,MAAM,CAAC,SAAS,CAAC,GAAG,QAAQ,CAAC;YAC7B,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;IAED,MAAM,CAAU,IAAI,CAAU,IAAqB;QACjD,OAAO,IAAI,OAAO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C,GAAG,EAAE;qBACjH,CAAC,CAAC;gBACL,CAAC;gBAED,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAC;oBAC/B,QAAQ,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC;oBAC/B,MAAM;gBACR,CAAC;gBAED,MAAM,CAAC,GAAG,SAAS,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;gBAC1C,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;gBAC9B,MAAM;YACR,CAAC;YACD,KAAK,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC;gBAC7B,IAAI,CAAC,SAAS,EAAE,CAAC;oBACf,MAAM,QAAQ,CAAC;wBACb,OAAO,EAAE,qEAAqE,YAAY,WAAW,IAAI,CAAC,GAAG,EAAE;qBAChH,CAAC,CAAC;gBACL,CAAC;gBAED,QAAQ,GAAG,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;gBACtD,MAAM;YACR,CAAC;YACD,OAAO,CAAC,CAAC,CAAC;gBACR,MAAM,QAAQ,CAAC;oBACb,OAAO,EAAE,8CAA8C,YAAY,EAAE;iBACtE,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAED,IAAI,IAAI,CAAC,SAAS,KAAK,aAAa,CAAC,SAAS,EAAE,CAAC;YAC/C,IAAI,CAAC,MAAM,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;QACpC,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,UAAU;QACR,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;IAC1B,CAAC;CACF","sourcesContent":["import { getError } from '../error';\nimport { BaseHelper } from '@/common/base-helper';\nimport { type TClass, type TConstValue } from '@/common/types';\nimport type { IContainer } from '../container/common/types';\nimport { BindingScopes, BindingValueTypes, type TBindingScope } from './common/constants';\nimport {\n type IBinding,\n isClassProvider,\n type TBindingProvider,\n type TBindingResolverValue,\n} from './common/types';\n\n/** One container entry under `key`, resolved to a class, a value or a provider (set with `toClass`, `toValue`, `toProvider`). Scope is transient unless `setScope` selects singleton; a key with a dot gets its first segment as a tag. */\nexport class Binding<T = any> extends BaseHelper implements IBinding<T> {\n key: string;\n\n private bindScope: TBindingScope = BindingScopes.TRANSIENT;\n private tags: Set<string>;\n /** Boxed: a singleton may legitimately be `null`, `false`, `0`, `''` or `undefined`. */\n private cached?: { value: T };\n\n private resolver:\n | { type: typeof BindingValueTypes.CLASS; value: TClass<T> }\n | { type: typeof BindingValueTypes.VALUE; value: T }\n | { type: typeof BindingValueTypes.PROVIDER; value: TBindingProvider<T> };\n\n constructor(opts: { key: string }) {\n super({ scope: opts.key });\n this.tags = new Set([]);\n\n this.key = opts.key;\n\n const keyParts = this.key.split('.');\n\n if (keyParts.length > 1) {\n const [namespace] = keyParts;\n this.setTags(namespace);\n }\n }\n\n static override bind<T = any>(opts: { key: string }): Binding<T> {\n return new Binding<T>(opts);\n }\n\n toClass(value: TClass<T>): this {\n this.resolver = { type: BindingValueTypes.CLASS, value };\n\n return this;\n }\n\n toValue(value: T): this {\n this.resolver = { type: BindingValueTypes.VALUE, value };\n\n return this;\n }\n\n toProvider(value: TBindingProvider<T>): this {\n this.resolver = { type: BindingValueTypes.PROVIDER, value };\n\n return this;\n }\n\n /** The class a `toClass` binding instantiates; `undefined` for a value or a provider. */\n boundClass(): TClass<T> | undefined {\n return this.resolver.type === BindingValueTypes.CLASS ? this.resolver.value : undefined;\n }\n\n getBindingMeta(opts: { type: TConstValue<typeof BindingValueTypes> }): TBindingResolverValue<T> {\n if (this.resolver.type !== opts.type) {\n throw getError({\n message: `[getBindingMeta] Invalid resolver type, only ${this.resolver.type} is allowd | resolverType: ${this.resolver.type} | optType: ${opts.type}`,\n });\n }\n\n return this.resolver.value;\n }\n\n setScope(scope: TBindingScope): this {\n this.bindScope = scope;\n\n return this;\n }\n\n setTags(...tags: string[]): this {\n tags.forEach((t) => this.tags.add(t));\n\n return this;\n }\n\n hasTag(tag: string): boolean {\n return this.tags.has(tag);\n }\n\n getTags(): string[] {\n return Array.from(this.tags);\n }\n\n getScope(): TBindingScope {\n return this.bindScope;\n }\n\n /** True when `getValue` answers without building anything: a cached singleton or a plain value. Nothing it reads can form a cycle. */\n isSettled(): boolean {\n return (\n (this.bindScope === BindingScopes.SINGLETON && this.cached !== undefined) ||\n this.resolver.type === BindingValueTypes.VALUE\n );\n }\n\n getValue(container?: IContainer): T {\n if (this.bindScope === BindingScopes.SINGLETON && this.cached) {\n return this.cached.value;\n }\n\n let instance: T;\n\n const { type: resolverType } = this.resolver;\n\n switch (resolverType) {\n case BindingValueTypes.VALUE: {\n instance = this.resolver.value;\n break;\n }\n case BindingValueTypes.PROVIDER: {\n const provider = this.resolver.value;\n\n if (!container) {\n throw getError({\n message: `[getValue] Invalid context/container to get provider value | type: ${resolverType} | key: ${this.key}`,\n });\n }\n\n if (!isClassProvider(provider)) {\n instance = provider(container);\n break;\n }\n\n const p = container.instantiate(provider);\n instance = p.value(container);\n break;\n }\n case BindingValueTypes.CLASS: {\n if (!container) {\n throw getError({\n message: `[getValue] Invalid context/container to instantiate class | type: ${resolverType} | key: ${this.key}`,\n });\n }\n\n instance = container.instantiate(this.resolver.value);\n break;\n }\n default: {\n throw getError({\n message: `[getValue] Invalid value type | valueType: ${resolverType}`,\n });\n }\n }\n\n if (this.bindScope === BindingScopes.SINGLETON) {\n this.cached = { value: instance };\n }\n\n return instance;\n }\n\n clearCache() {\n this.cached = undefined;\n }\n}\n"]}
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import { type TConstValue } from '../../../common/types.js';
|
|
2
|
+
/** Lifetime of a resolved binding: `SINGLETON` caches the first value, `TRANSIENT` builds a new one on each `getValue`. */
|
|
2
3
|
export declare class BindingScopes {
|
|
3
4
|
static readonly SINGLETON = "singleton";
|
|
4
5
|
static readonly TRANSIENT = "transient";
|
|
5
6
|
}
|
|
7
|
+
/** Union of the `BindingScopes` values. */
|
|
6
8
|
export type TBindingScope = TConstValue<typeof BindingScopes>;
|
|
9
|
+
/** What a binding resolves from: a class to instantiate, a plain value, or a provider. */
|
|
7
10
|
export declare class BindingValueTypes {
|
|
8
11
|
static readonly CLASS = "class";
|
|
9
12
|
static readonly VALUE = "value";
|
|
10
13
|
static readonly PROVIDER = "provider";
|
|
11
14
|
}
|
|
15
|
+
/** Union of the `BindingValueTypes` values. */
|
|
12
16
|
export type TBindingValueType = TConstValue<typeof BindingValueTypes>;
|
|
17
|
+
/** Helpers for building binding keys. */
|
|
13
18
|
export declare class BindingKeys {
|
|
14
19
|
static build(opts: {
|
|
15
20
|
namespace: string;
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { getError } from '../../error/index.js';
|
|
2
|
+
/** Lifetime of a resolved binding: `SINGLETON` caches the first value, `TRANSIENT` builds a new one on each `getValue`. */
|
|
2
3
|
export class BindingScopes {
|
|
3
4
|
static { this.SINGLETON = 'singleton'; }
|
|
4
5
|
static { this.TRANSIENT = 'transient'; }
|
|
5
6
|
}
|
|
7
|
+
/** What a binding resolves from: a class to instantiate, a plain value, or a provider. */
|
|
6
8
|
export class BindingValueTypes {
|
|
7
9
|
static { this.CLASS = 'class'; }
|
|
8
10
|
static { this.VALUE = 'value'; }
|
|
9
11
|
static { this.PROVIDER = 'provider'; }
|
|
10
12
|
}
|
|
13
|
+
/** Helpers for building binding keys. */
|
|
11
14
|
export class BindingKeys {
|
|
12
15
|
static build(opts) {
|
|
13
16
|
const { namespace, key } = opts;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../src/modules/binding/common/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAGvC,MAAM,OAAO,aAAa;aACR,cAAS,GAAG,WAAW,CAAC;aACxB,cAAS,GAAG,WAAW,CAAC;;
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../src/modules/binding/common/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAGvC,2HAA2H;AAC3H,MAAM,OAAO,aAAa;aACR,cAAS,GAAG,WAAW,CAAC;aACxB,cAAS,GAAG,WAAW,CAAC;;AAK1C,0FAA0F;AAC1F,MAAM,OAAO,iBAAiB;aACZ,UAAK,GAAG,OAAO,CAAC;aAChB,UAAK,GAAG,OAAO,CAAC;aAChB,aAAQ,GAAG,UAAU,CAAC;;AAKxC,yCAAyC;AACzC,MAAM,OAAO,WAAW;IACtB,MAAM,CAAC,KAAK,CAAC,IAAwC;QACnD,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;QAChC,MAAM,QAAQ,GAAkB,EAAE,CAAC;QAEnC,IAAI,SAAS,EAAE,CAAC;YACd,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC3B,CAAC;QAED,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,MAAM,QAAQ,CAAC;gBACb,OAAO,EAAE,oDAAoD,GAAG,EAAE;aACnE,CAAC,CAAC;QACL,CAAC;QAED,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAEnB,OAAO,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC;CACF","sourcesContent":["import { getError } from '../../error';\nimport { type TConstValue } from '@/common/types';\n\n/** Lifetime of a resolved binding: `SINGLETON` caches the first value, `TRANSIENT` builds a new one on each `getValue`. */\nexport class BindingScopes {\n static readonly SINGLETON = 'singleton';\n static readonly TRANSIENT = 'transient';\n}\n/** Union of the `BindingScopes` values. */\nexport type TBindingScope = TConstValue<typeof BindingScopes>;\n\n/** What a binding resolves from: a class to instantiate, a plain value, or a provider. */\nexport class BindingValueTypes {\n static readonly CLASS = 'class';\n static readonly VALUE = 'value';\n static readonly PROVIDER = 'provider';\n}\n/** Union of the `BindingValueTypes` values. */\nexport type TBindingValueType = TConstValue<typeof BindingValueTypes>;\n\n/** Helpers for building binding keys. */\nexport class BindingKeys {\n static build(opts: { namespace: string; key: string }) {\n const { namespace, key } = opts;\n const keyParts: Array<string> = [];\n\n if (namespace) {\n keyParts.push(namespace);\n }\n\n if (!key) {\n throw getError({\n message: `[BindingKeys][build] Invalid key to build | key: ${key}`,\n });\n }\n\n keyParts.push(key);\n\n return keyParts.join('.');\n }\n}\n"]}
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import type { IContainer } from '../../container/common/types.js';
|
|
2
2
|
import { type TClass, type TConstValue } from '../../../common/types.js';
|
|
3
3
|
import type { BindingValueTypes, TBindingScope } from './constants.js';
|
|
4
|
+
/** A value source resolved against a container; `value` runs on each resolution of the binding it backs. */
|
|
4
5
|
export interface IProvider<T> {
|
|
5
6
|
value(container: IContainer): T;
|
|
6
7
|
}
|
|
8
|
+
/** True for a function whose prototype has a `value` method, so a provider class is told apart from a plain provider function. */
|
|
7
9
|
export declare const isClassProvider: <T>(target: any) => target is TClass<IProvider<T>>;
|
|
10
|
+
/** What `toProvider` accepts: a function taking the container, or a class implementing {@link IProvider}. */
|
|
8
11
|
export type TBindingProvider<T> = (<C extends IContainer>(container: C) => T) | TClass<IProvider<T>>;
|
|
9
12
|
/** What a binding's resolver holds - a class, a plain value, or a provider. */
|
|
10
13
|
export type TBindingResolverValue<T> = TClass<T> | T | TBindingProvider<T>;
|
|
14
|
+
/** A container entry: one key bound to a class, a value or a provider, with a scope and tags. */
|
|
11
15
|
export interface IBinding<T = any> {
|
|
12
16
|
/** Normalized at construction - a symbol key arrives here as its string form. */
|
|
13
17
|
key: string;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** True for a function whose prototype has a `value` method, so a provider class is told apart from a plain provider function. */
|
|
1
2
|
export const isClassProvider = (target) => {
|
|
2
3
|
return (typeof target === 'function' && target.prototype && typeof target.prototype.value === 'function');
|
|
3
4
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/modules/binding/common/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/modules/binding/common/types.ts"],"names":[],"mappings":"AASA,kIAAkI;AAClI,MAAM,CAAC,MAAM,eAAe,GAAG,CAAI,MAAW,EAAkC,EAAE;IAChF,OAAO,CACL,OAAO,MAAM,KAAK,UAAU,IAAI,MAAM,CAAC,SAAS,IAAI,OAAO,MAAM,CAAC,SAAS,CAAC,KAAK,KAAK,UAAU,CACjG,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type { IContainer } from '../../container/common/types';\nimport { type TClass, type TConstValue } from '@/common/types';\nimport type { BindingValueTypes, TBindingScope } from './constants';\n\n/** A value source resolved against a container; `value` runs on each resolution of the binding it backs. */\nexport interface IProvider<T> {\n value(container: IContainer): T;\n}\n\n/** True for a function whose prototype has a `value` method, so a provider class is told apart from a plain provider function. */\nexport const isClassProvider = <T>(target: any): target is TClass<IProvider<T>> => {\n return (\n typeof target === 'function' && target.prototype && typeof target.prototype.value === 'function'\n );\n};\n\n/** What `toProvider` accepts: a function taking the container, or a class implementing {@link IProvider}. */\nexport type TBindingProvider<T> =\n | (<C extends IContainer>(container: C) => T)\n | TClass<IProvider<T>>;\n\n/** What a binding's resolver holds - a class, a plain value, or a provider. */\nexport type TBindingResolverValue<T> = TClass<T> | T | TBindingProvider<T>;\n\n/** A container entry: one key bound to a class, a value or a provider, with a scope and tags. */\nexport interface IBinding<T = any> {\n /** Normalized at construction - a symbol key arrives here as its string form. */\n key: string;\n\n toClass(value: TClass<T>): this;\n toValue(value: T): this;\n toProvider(value: TBindingProvider<T>): this;\n getBindingMeta(opts: { type: TConstValue<typeof BindingValueTypes> }): TBindingResolverValue<T>;\n\n setScope(scope: TBindingScope): this;\n getScope(): TBindingScope;\n setTags(...tags: string[]): this;\n hasTag(tag: string): boolean;\n getTags(): string[];\n\n getValue(container?: IContainer): T;\n clearCache(): void;\n}\n"]}
|
|
@@ -6,7 +6,12 @@ export declare abstract class BaseContainer extends AbstractContainer {
|
|
|
6
6
|
protected bindings: Map<string, Binding<any>>;
|
|
7
7
|
/** How often each bound key has been handed out since counting started. */
|
|
8
8
|
protected resolutionCounts: Map<string, number>;
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* Whether resolutions are counted. The counter sits on the hottest path in the container, and an
|
|
11
|
+
* application that never reads the report should not pay for it.
|
|
12
|
+
*
|
|
13
|
+
* @default false
|
|
14
|
+
*/
|
|
10
15
|
protected isCountingResolutions: boolean;
|
|
11
16
|
/** Whether `startResolutionCounting` has ever run. A report read without it would name every binding, which is a wrong answer rather than an empty one. */
|
|
12
17
|
protected hasStartedResolutionCounting: boolean;
|
|
@@ -12,7 +12,12 @@ export class BaseContainer extends AbstractContainer {
|
|
|
12
12
|
this.bindings = new Map();
|
|
13
13
|
/** How often each bound key has been handed out since counting started. */
|
|
14
14
|
this.resolutionCounts = new Map();
|
|
15
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* Whether resolutions are counted. The counter sits on the hottest path in the container, and an
|
|
17
|
+
* application that never reads the report should not pay for it.
|
|
18
|
+
*
|
|
19
|
+
* @default false
|
|
20
|
+
*/
|
|
16
21
|
this.isCountingResolutions = false;
|
|
17
22
|
/** Whether `startResolutionCounting` has ever run. A report read without it would name every binding, which is a wrong answer rather than an empty one. */
|
|
18
23
|
this.hasStartedResolutionCounting = false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../../src/modules/container/base.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAA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E,CAAC;QAExC,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC/B,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;gBACzB,SAAS;YACX,CAAC;YAED,IAAI,OAAO,YAAY,KAAK,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;gBACpF,SAAS;YACX,CAAC;YAED,IAAI,OAAO,YAAY,GAAG,IAAI,OAAO,CAAC,IAAI,GAAG,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;gBAC3E,SAAS;YACX,CAAC;YAED,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACnB,CAAC;QAED,OAAO,EAAE,CAAC;IACZ,CAAC;IAEQ,KAAK;QACZ,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;QAExC,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC/B,OAAO,CAAC,UAAU,EAAE,CAAC;QACvB,CAAC;IACH,CAAC;IAEQ,KAAK;QACZ,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACtB,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;QACxB,IAAI,CAAC,uBAAuB,CAAC,KAAK,EAAE,CAAC;IACvC,CAAC;CACF","sourcesContent":["import { type TBindingKey, type TClass, type TNullable } from '@/common/types';\nimport { Binding } from '../binding/binding';\nimport { BindingKeys } from '../binding/common/constants';\nimport { getError } from '../error';\nimport { metadataRegistry } from '../registry/registry';\nimport { AbstractContainer } from './abstract';\n\n/** A dependency graph nests far less than this; deeper is all but certainly a cycle, and is checked. */\nconst CYCLE_CHECK_DEPTH = 64;\n\n/** Storage half of the container, keyed by normalized binding-key strings - resolution (`instantiate`) stays abstract, it is the part an implementation swaps. */\nexport abstract class BaseContainer extends AbstractContainer {\n protected bindings = new Map<string, Binding>();\n\n /** How often each bound key has been handed out since counting started. */\n protected resolutionCounts = new Map<string, number>();\n\n /** Off by default: the counter sits on the hottest path in the container, and an application that never reads the report should not pay for it. */\n protected isCountingResolutions = false;\n\n /** Whether `startResolutionCounting` has ever run. A report read without it would name every binding, which is a wrong answer rather than an empty one. */\n protected hasStartedResolutionCounting = false;\n\n /** The string each BOUND symbol is stored under: `Symbol('x')` twice is two keys, and both print as \"Symbol(x)\". */\n protected symbolKeys = new Map<symbol, string>();\n\n /** How many symbols have been bound per description, so a new one gets its suffix in one step. */\n protected symbolDescriptionCounts = new Map<string, number>();\n\n /**\n * Nesting depth of the reads in progress. Past {@link CYCLE_CHECK_DEPTH} the keys are tracked, and\n * a key met again is a cycle: a real graph is far shallower, so the common read pays one counter.\n * Only the synchronous part is checked - a cycle through an `await` is not seen.\n */\n protected resolutionDepth = 0;\n protected resolvingKeys = new Set<string>();\n\n constructor(opts?: { scope: string }) {\n super({ scope: opts?.scope ?? BaseContainer.name });\n }\n\n override getMetadataRegistry() {\n return metadataRegistry;\n }\n\n /**\n * The string a key is stored under, or `undefined` for a symbol that was never bound - a lookup\n * never records one, so reading with throwaway symbols leaves nothing behind.\n */\n protected toKeyString(opts: {\n key: TBindingKey | { namespace: string; key: string };\n }): string | undefined {\n const { key } = opts;\n\n switch (typeof key) {\n case 'string': {\n return key;\n }\n case 'symbol': {\n return this.symbolKeys.get(key);\n }\n case 'object': {\n return BindingKeys.build(key);\n }\n default: {\n throw getError({\n message: `[getBinding] Invalid binding key type | opts: ${String(key)} | allowed: [string, symbol, { namespace: string, key: string }]`,\n });\n }\n }\n }\n\n /** A bound symbol's own string: its description, suffixed (`Symbol(x)#2`) when another symbol holds it. */\n protected bindSymbolKey(opts: { key: symbol }): string {\n const { key } = opts;\n\n const known = this.symbolKeys.get(key);\n\n if (known !== undefined) {\n return known;\n }\n\n const description = key.toString();\n const count = (this.symbolDescriptionCounts.get(description) ?? 0) + 1;\n this.symbolDescriptionCounts.set(description, count);\n\n const keyStr = count === 1 ? description : `${description}#${count}`;\n this.symbolKeys.set(key, keyStr);\n\n return keyStr;\n }\n\n override bind<T>(opts: { key: TBindingKey }): Binding<T> {\n const { key } = opts;\n const keyStr = typeof key === 'symbol' ? this.bindSymbolKey({ key }) : key;\n const binding = new Binding<T>({ key: keyStr });\n this.bindings.set(keyStr, binding as Binding);\n\n return binding;\n }\n\n override isBound(opts: { key: TBindingKey }): boolean {\n const keyStr = this.toKeyString({ key: opts.key });\n\n return keyStr !== undefined && this.bindings.has(keyStr);\n }\n\n override getBinding<T>(opts: {\n key: TBindingKey | { namespace: string; key: string };\n }): TNullable<Binding<T>> {\n const keyStr = this.toKeyString({ key: opts.key });\n\n return keyStr === undefined ? undefined : this.bindings.get(keyStr);\n }\n\n override unbind(opts: { key: TBindingKey }): boolean {\n const { key } = opts;\n const keyStr = this.toKeyString({ key });\n\n if (typeof key === 'symbol') {\n this.symbolKeys.delete(key);\n }\n\n return keyStr !== undefined && this.bindings.delete(keyStr);\n }\n\n override set<T>(opts: { binding: Binding<T> }): void {\n const { binding } = opts;\n this.bindings.set(binding.key, binding);\n }\n\n override get<T>(opts: {\n key: TBindingKey | { namespace: string; key: string };\n isOptional?: false;\n }): T;\n override get<T>(opts: {\n key: TBindingKey | { namespace: string; key: string };\n isOptional?: boolean;\n }): T | undefined;\n override get<T>(opts: {\n key: TBindingKey | { namespace: string; key: string };\n isOptional?: boolean;\n }): T | undefined {\n const { key, isOptional = false } = opts;\n\n const binding = this.getBinding<T>({ key });\n\n if (binding) {\n // Counted here and nowhere else: constructor injection, property injection, `application.get`\n // and `BindingVerifier.verify` all arrive through this one method. A miss below is not a resolution.\n if (this.isCountingResolutions) {\n this.resolutionCounts.set(binding.key, (this.resolutionCounts.get(binding.key) ?? 0) + 1);\n }\n\n // The hot path: a cached singleton or a value builds nothing, so it cannot be part of a cycle.\n if (binding.isSettled()) {\n return binding.getValue(this);\n }\n\n this.resolutionDepth++;\n const isTracked = this.resolutionDepth > CYCLE_CHECK_DEPTH;\n\n if (isTracked && this.resolvingKeys.has(binding.key)) {\n this.resolutionDepth--;\n throw getError({\n message: `Circular dependency | ${[...this.resolvingKeys, binding.key].join(' -> ')}`,\n });\n }\n\n if (isTracked) {\n this.resolvingKeys.add(binding.key);\n }\n\n try {\n return binding.getValue(this);\n } finally {\n this.resolutionDepth--;\n\n if (isTracked) {\n this.resolvingKeys.delete(binding.key);\n }\n }\n }\n\n if (!isOptional) {\n const printed = typeof key === 'object' ? BindingKeys.build(key) : String(key);\n\n throw getError({\n message: `Binding key: ${printed} is not bounded in context!`,\n extra: { unboundKey: printed },\n });\n }\n\n return undefined;\n }\n\n override gets<T extends unknown[]>(opts: {\n bindings: {\n [K in keyof T]: {\n key: TBindingKey | { namespace: string; key: string };\n isOptional?: boolean;\n };\n };\n }): { [K in keyof T]: T[K] | undefined } {\n return opts.bindings.map((opt) => this.get({ ...opt, isOptional: true })) as {\n [K in keyof T]: T[K] | undefined;\n };\n }\n\n /** Clears the counts and starts counting. Call it AFTER `initialize()`: boot resolves plenty no request ever asks for, and `bootChecks.binding.doVerify` reads every service and repository. */\n override startResolutionCounting(): void {\n this.resolutionCounts.clear();\n this.isCountingResolutions = true;\n this.hasStartedResolutionCounting = true;\n }\n\n /** Stops counting and keeps what was counted, so `get` returns to its uncounted cost. */\n override stopResolutionCounting(): void {\n this.isCountingResolutions = false;\n }\n\n /** How many times each bound key has been read since counting started. A key that was bound and never read is absent. The map is a copy. */\n override getResolutionCounts(): ReadonlyMap<string, number> {\n return new Map(this.resolutionCounts);\n }\n\n override resolve<T>(cls: TClass<T>): T {\n return this.instantiate(cls);\n }\n\n override findByTag<T = any>(opts: {\n tag: string;\n exclude?: Array<string> | Set<string>;\n }): Binding<T>[] {\n const { tag, exclude } = opts;\n\n const rs: Binding<T>[] = [];\n\n const bindings = this.bindings.values();\n\n for (const binding of bindings) {\n if (!binding.hasTag(tag)) {\n continue;\n }\n\n if (exclude instanceof Array && exclude.length > 0 && exclude.includes(binding.key)) {\n continue;\n }\n\n if (exclude instanceof Set && exclude.size > 0 && exclude.has(binding.key)) {\n continue;\n }\n\n rs.push(binding);\n }\n\n return rs;\n }\n\n override clear(): void {\n const bindings = this.bindings.values();\n\n for (const binding of bindings) {\n binding.clearCache();\n }\n }\n\n override reset(): void {\n this.bindings.clear();\n this.symbolKeys.clear();\n this.symbolDescriptionCounts.clear();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../../src/modules/container/base.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE/C,wGAAwG;AACxG,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAE7B,kKAAkK;AAClK,MAAM,OAAgB,aAAc,SAAQ,iBAAiB;IA+B3D,YAAY,IAAwB;QAClC,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,IAAI,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC;QA/B5C,aAAQ,GAAG,IAAI,GAAG,EAAmB,CAAC;QAEhD,2EAA2E;QACjE,qBAAgB,GAAG,IAAI,GAAG,EAAkB,CAAC;QAEvD;;;;;WAKG;QACO,0BAAqB,GAAG,KAAK,CAAC;QAExC,2JAA2J;QACjJ,iCAA4B,GAAG,KAAK,CAAC;QAE/C,oHAAoH;QAC1G,eAAU,GAAG,IAAI,GAAG,EAAkB,CAAC;QAEjD,kGAAkG;QACxF,4BAAuB,GAAG,IAAI,GAAG,EAAkB,CAAC;QAE9D;;;;WAIG;QACO,oBAAe,GAAG,CAAC,CA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ExC,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC/B,OAAO,CAAC,UAAU,EAAE,CAAC;QACvB,CAAC;IACH,CAAC;IAEQ,KAAK;QACZ,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACtB,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;QACxB,IAAI,CAAC,uBAAuB,CAAC,KAAK,EAAE,CAAC;IACvC,CAAC;CACF","sourcesContent":["import { type TBindingKey, type TClass, type TNullable } from '@/common/types';\nimport { Binding } from '../binding/binding';\nimport { BindingKeys } from '../binding/common/constants';\nimport { getError } from '../error';\nimport { metadataRegistry } from '../registry/registry';\nimport { AbstractContainer } from './abstract';\n\n/** A dependency graph nests far less than this; deeper is all but certainly a cycle, and is checked. */\nconst CYCLE_CHECK_DEPTH = 64;\n\n/** Storage half of the container, keyed by normalized binding-key strings - resolution (`instantiate`) stays abstract, it is the part an implementation swaps. */\nexport abstract class BaseContainer extends AbstractContainer {\n protected bindings = new Map<string, Binding>();\n\n /** How often each bound key has been handed out since counting started. */\n protected resolutionCounts = new Map<string, number>();\n\n /**\n * Whether resolutions are counted. The counter sits on the hottest path in the container, and an\n * application that never reads the report should not pay for it.\n *\n * @default false\n */\n protected isCountingResolutions = false;\n\n /** Whether `startResolutionCounting` has ever run. A report read without it would name every binding, which is a wrong answer rather than an empty one. */\n protected hasStartedResolutionCounting = false;\n\n /** The string each BOUND symbol is stored under: `Symbol('x')` twice is two keys, and both print as \"Symbol(x)\". */\n protected symbolKeys = new Map<symbol, string>();\n\n /** How many symbols have been bound per description, so a new one gets its suffix in one step. */\n protected symbolDescriptionCounts = new Map<string, number>();\n\n /**\n * Nesting depth of the reads in progress. Past {@link CYCLE_CHECK_DEPTH} the keys are tracked, and\n * a key met again is a cycle: a real graph is far shallower, so the common read pays one counter.\n * Only the synchronous part is checked - a cycle through an `await` is not seen.\n */\n protected resolutionDepth = 0;\n protected resolvingKeys = new Set<string>();\n\n constructor(opts?: { scope: string }) {\n super({ scope: opts?.scope ?? BaseContainer.name });\n }\n\n override getMetadataRegistry() {\n return metadataRegistry;\n }\n\n /**\n * The string a key is stored under, or `undefined` for a symbol that was never bound - a lookup\n * never records one, so reading with throwaway symbols leaves nothing behind.\n */\n protected toKeyString(opts: {\n key: TBindingKey | { namespace: string; key: string };\n }): string | undefined {\n const { key } = opts;\n\n switch (typeof key) {\n case 'string': {\n return key;\n }\n case 'symbol': {\n return this.symbolKeys.get(key);\n }\n case 'object': {\n return BindingKeys.build(key);\n }\n default: {\n throw getError({\n message: `[getBinding] Invalid binding key type | opts: ${String(key)} | allowed: [string, symbol, { namespace: string, key: string }]`,\n });\n }\n }\n }\n\n /** A bound symbol's own string: its description, suffixed (`Symbol(x)#2`) when another symbol holds it. */\n protected bindSymbolKey(opts: { key: symbol }): string {\n const { key } = opts;\n\n const known = this.symbolKeys.get(key);\n\n if (known !== undefined) {\n return known;\n }\n\n const description = key.toString();\n const count = (this.symbolDescriptionCounts.get(description) ?? 0) + 1;\n this.symbolDescriptionCounts.set(description, count);\n\n const keyStr = count === 1 ? description : `${description}#${count}`;\n this.symbolKeys.set(key, keyStr);\n\n return keyStr;\n }\n\n override bind<T>(opts: { key: TBindingKey }): Binding<T> {\n const { key } = opts;\n const keyStr = typeof key === 'symbol' ? this.bindSymbolKey({ key }) : key;\n const binding = new Binding<T>({ key: keyStr });\n this.bindings.set(keyStr, binding as Binding);\n\n return binding;\n }\n\n override isBound(opts: { key: TBindingKey }): boolean {\n const keyStr = this.toKeyString({ key: opts.key });\n\n return keyStr !== undefined && this.bindings.has(keyStr);\n }\n\n override getBinding<T>(opts: {\n key: TBindingKey | { namespace: string; key: string };\n }): TNullable<Binding<T>> {\n const keyStr = this.toKeyString({ key: opts.key });\n\n return keyStr === undefined ? undefined : this.bindings.get(keyStr);\n }\n\n override unbind(opts: { key: TBindingKey }): boolean {\n const { key } = opts;\n const keyStr = this.toKeyString({ key });\n\n if (typeof key === 'symbol') {\n this.symbolKeys.delete(key);\n }\n\n return keyStr !== undefined && this.bindings.delete(keyStr);\n }\n\n override set<T>(opts: { binding: Binding<T> }): void {\n const { binding } = opts;\n this.bindings.set(binding.key, binding);\n }\n\n override get<T>(opts: {\n key: TBindingKey | { namespace: string; key: string };\n isOptional?: false;\n }): T;\n override get<T>(opts: {\n key: TBindingKey | { namespace: string; key: string };\n isOptional?: boolean;\n }): T | undefined;\n override get<T>(opts: {\n key: TBindingKey | { namespace: string; key: string };\n isOptional?: boolean;\n }): T | undefined {\n const { key, isOptional = false } = opts;\n\n const binding = this.getBinding<T>({ key });\n\n if (binding) {\n // Counted here and nowhere else: constructor injection, property injection, `application.get`\n // and `BindingVerifier.verify` all arrive through this one method. A miss below is not a resolution.\n if (this.isCountingResolutions) {\n this.resolutionCounts.set(binding.key, (this.resolutionCounts.get(binding.key) ?? 0) + 1);\n }\n\n // The hot path: a cached singleton or a value builds nothing, so it cannot be part of a cycle.\n if (binding.isSettled()) {\n return binding.getValue(this);\n }\n\n this.resolutionDepth++;\n const isTracked = this.resolutionDepth > CYCLE_CHECK_DEPTH;\n\n if (isTracked && this.resolvingKeys.has(binding.key)) {\n this.resolutionDepth--;\n throw getError({\n message: `Circular dependency | ${[...this.resolvingKeys, binding.key].join(' -> ')}`,\n });\n }\n\n if (isTracked) {\n this.resolvingKeys.add(binding.key);\n }\n\n try {\n return binding.getValue(this);\n } finally {\n this.resolutionDepth--;\n\n if (isTracked) {\n this.resolvingKeys.delete(binding.key);\n }\n }\n }\n\n if (!isOptional) {\n const printed = typeof key === 'object' ? BindingKeys.build(key) : String(key);\n\n throw getError({\n message: `Binding key: ${printed} is not bounded in context!`,\n extra: { unboundKey: printed },\n });\n }\n\n return undefined;\n }\n\n override gets<T extends unknown[]>(opts: {\n bindings: {\n [K in keyof T]: {\n key: TBindingKey | { namespace: string; key: string };\n isOptional?: boolean;\n };\n };\n }): { [K in keyof T]: T[K] | undefined } {\n return opts.bindings.map((opt) => this.get({ ...opt, isOptional: true })) as {\n [K in keyof T]: T[K] | undefined;\n };\n }\n\n /** Clears the counts and starts counting. Call it AFTER `initialize()`: boot resolves plenty no request ever asks for, and `bootChecks.binding.doVerify` reads every service and repository. */\n override startResolutionCounting(): void {\n this.resolutionCounts.clear();\n this.isCountingResolutions = true;\n this.hasStartedResolutionCounting = true;\n }\n\n /** Stops counting and keeps what was counted, so `get` returns to its uncounted cost. */\n override stopResolutionCounting(): void {\n this.isCountingResolutions = false;\n }\n\n /** How many times each bound key has been read since counting started. A key that was bound and never read is absent. The map is a copy. */\n override getResolutionCounts(): ReadonlyMap<string, number> {\n return new Map(this.resolutionCounts);\n }\n\n override resolve<T>(cls: TClass<T>): T {\n return this.instantiate(cls);\n }\n\n override findByTag<T = any>(opts: {\n tag: string;\n exclude?: Array<string> | Set<string>;\n }): Binding<T>[] {\n const { tag, exclude } = opts;\n\n const rs: Binding<T>[] = [];\n\n const bindings = this.bindings.values();\n\n for (const binding of bindings) {\n if (!binding.hasTag(tag)) {\n continue;\n }\n\n if (exclude instanceof Array && exclude.length > 0 && exclude.includes(binding.key)) {\n continue;\n }\n\n if (exclude instanceof Set && exclude.size > 0 && exclude.has(binding.key)) {\n continue;\n }\n\n rs.push(binding);\n }\n\n return rs;\n }\n\n override clear(): void {\n const bindings = this.bindings.values();\n\n for (const binding of bindings) {\n binding.clearCache();\n }\n }\n\n override reset(): void {\n this.bindings.clear();\n this.symbolKeys.clear();\n this.symbolDescriptionCounts.clear();\n }\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { IBinding } from '../../binding/common/types.js';
|
|
2
2
|
import type { TBindingKey, TClass, TNullable } from '../../../common/types.js';
|
|
3
3
|
import type { MetadataRegistry } from '../../registry/registry.js';
|
|
4
|
+
/** Binds keys, resolves them and instantiates classes with their injected dependencies. */
|
|
4
5
|
export interface IContainer {
|
|
5
6
|
getMetadataRegistry(): MetadataRegistry;
|
|
6
7
|
bind<T>(opts: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/modules/container/common/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { IBinding } from '../../binding/common/types';\nimport type { TBindingKey, TClass, TNullable } from '@/common/types';\nimport type { MetadataRegistry } from '../../registry/registry';\n\nexport interface IContainer {\n getMetadataRegistry(): MetadataRegistry;\n\n bind<T>(opts: { key: TBindingKey }): IBinding<T>;\n isBound(opts: { key: TBindingKey }): boolean;\n getBinding<T>(opts: {\n key: TBindingKey | { namespace: string; key: string };\n }): TNullable<IBinding<T>>;\n unbind(opts: { key: TBindingKey }): boolean;\n set<T>(opts: { binding: IBinding<T> }): void;\n\n get<T>(opts: { key: TBindingKey | { namespace: string; key: string }; isOptional?: false }): T;\n get<T>(opts: {\n key: TBindingKey | { namespace: string; key: string };\n isOptional?: boolean;\n }): T | undefined;\n gets<T extends unknown[]>(opts: {\n bindings: {\n [K in keyof T]: {\n key: TBindingKey | { namespace: string; key: string };\n isOptional?: boolean;\n };\n };\n }): { [K in keyof T]: T[K] | undefined };\n\n resolve<T>(cls: TClass<T>): T;\n instantiate<T>(cls: TClass<T>): T;\n\n findByTag<T = any>(opts: { tag: string; exclude?: Array<string> | Set<string> }): IBinding<T>[];\n clear(): void;\n reset(): void;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/modules/container/common/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { IBinding } from '../../binding/common/types';\nimport type { TBindingKey, TClass, TNullable } from '@/common/types';\nimport type { MetadataRegistry } from '../../registry/registry';\n\n/** Binds keys, resolves them and instantiates classes with their injected dependencies. */\nexport interface IContainer {\n getMetadataRegistry(): MetadataRegistry;\n\n bind<T>(opts: { key: TBindingKey }): IBinding<T>;\n isBound(opts: { key: TBindingKey }): boolean;\n getBinding<T>(opts: {\n key: TBindingKey | { namespace: string; key: string };\n }): TNullable<IBinding<T>>;\n unbind(opts: { key: TBindingKey }): boolean;\n set<T>(opts: { binding: IBinding<T> }): void;\n\n get<T>(opts: { key: TBindingKey | { namespace: string; key: string }; isOptional?: false }): T;\n get<T>(opts: {\n key: TBindingKey | { namespace: string; key: string };\n isOptional?: boolean;\n }): T | undefined;\n gets<T extends unknown[]>(opts: {\n bindings: {\n [K in keyof T]: {\n key: TBindingKey | { namespace: string; key: string };\n isOptional?: boolean;\n };\n };\n }): { [K in keyof T]: T[K] | undefined };\n\n resolve<T>(cls: TClass<T>): T;\n instantiate<T>(cls: TClass<T>): T;\n\n findByTag<T = any>(opts: { tag: string; exclude?: Array<string> | Set<string> }): IBinding<T>[];\n clear(): void;\n reset(): void;\n}\n"]}
|
|
@@ -2,6 +2,7 @@ import type { TClass } from '../../common/types.js';
|
|
|
2
2
|
import type { IContainer } from './common/types.js';
|
|
3
3
|
/** A class (matched exactly, never by subclass), a class name, or a binding key. */
|
|
4
4
|
export type TBindingSkip = TClass<unknown> | string;
|
|
5
|
+
/** Input to `BindingVerifier`: the container and the namespaces whose bindings are resolved. */
|
|
5
6
|
export interface IVerifyBindingsOptions {
|
|
6
7
|
container: IContainer;
|
|
7
8
|
/**
|
|
@@ -13,6 +14,7 @@ export interface IVerifyBindingsOptions {
|
|
|
13
14
|
/** Bindings to leave unresolved. A skip that matches no enumerated binding is reported in `unmatchedSkips`. */
|
|
14
15
|
skip?: TBindingSkip[];
|
|
15
16
|
}
|
|
17
|
+
/** One binding that threw while being resolved, with the missing key or class when the error names one. */
|
|
16
18
|
export interface IBindingFailure {
|
|
17
19
|
/** The binding that could not resolve, that is, who needs the missing thing. */
|
|
18
20
|
key: string;
|
|
@@ -24,6 +26,7 @@ export interface IBindingFailure {
|
|
|
24
26
|
/** The thrown object, unchanged. */
|
|
25
27
|
error: unknown;
|
|
26
28
|
}
|
|
29
|
+
/** Result of verifying bindings: the keys that resolved, the failures, and the `skip` entries that matched nothing. */
|
|
27
30
|
export interface IBindingVerification {
|
|
28
31
|
/** Keys resolved, in container order, namespaces in the order given. */
|
|
29
32
|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CAAC;QACH,CAAC;QAED,MAAM,MAAM,GACV,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC;YACxB,CAAC,CAAC,IAAI,KAAK,KAAK,MAAM,CAAC,QAAQ,CAAC,MAAM,mCAAmC;YACzE,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC;QAEpB,MAAM,QAAQ,CAAC;YACb,OAAO,EAAE,GAAG,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;YACxC,KAAK,EAAE;gBACL,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,EAAE,EAAE,CAAC,CAAC;oBAClF,GAAG;oBACH,OAAO;oBACP,GAAG,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC;oBACnD,GAAG,CAAC,iBAAiB,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,iBAAiB,EAAE,CAAC;iBAClE,CAAC,CAAC;gBACH,OAAO;gBACP,cAAc,EAAE,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,eAAe,CAAC,QAAQ,CAAC;aACpE;SACF,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import type { TClass } from '@/common/types';\nimport type { IBinding } from '../binding/common/types';\nimport { getError } from '../error';\nimport type { IContainer } from './common/types';\n\n/** A class (matched exactly, never by subclass), a class name, or a binding key. */\nexport type TBindingSkip = TClass<unknown> | string;\n\nexport interface IVerifyBindingsOptions {\n container: IContainer;\n\n /**\n * A binding is in a namespace when it carries the tag `Binding` sets from the first segment of its\n * key: `services.Orders` is in `services`. Required: inversion does not know which namespaces an\n * application uses. A namespace that itself holds a dot is not supported.\n */\n namespaces: string[];\n\n /** Bindings to leave unresolved. A skip that matches no enumerated binding is reported in `unmatchedSkips`. */\n skip?: TBindingSkip[];\n}\n\nexport interface IBindingFailure {\n /** The binding that could not resolve, that is, who needs the missing thing. */\n key: string;\n message: string;\n\n /** An injected key nobody bound (`extra.unboundKey` of the container's error). */\n missingKey?: string;\n\n /** An injected class nobody registered (`extra.unregisteredClass` of the container's error). */\n unregisteredClass?: string;\n\n /** The thrown object, unchanged. */\n error: unknown;\n}\n\nexport interface IBindingVerification {\n /** Keys resolved, in container order, namespaces in the order given. */\n verified: string[];\n failures: IBindingFailure[];\n unmatchedSkips: TBindingSkip[];\n}\n\ninterface IClassBinding {\n boundClass: () => TClass<unknown> | undefined;\n}\n\n/** Resolves bindings of the given namespaces and reports what cannot resolve. */\nexport class BindingVerifier {\n private static hasBoundClass(binding: IBinding): binding is IBinding & IClassBinding {\n return 'boundClass' in binding && typeof binding.boundClass === 'function';\n }\n\n private static classOf(binding: IBinding): TClass<unknown> | undefined {\n return BindingVerifier.hasBoundClass(binding) ? binding.boundClass() : undefined;\n }\n\n private static skipName(skip: TBindingSkip): string {\n return typeof skip === 'string' ? skip : skip.name;\n }\n\n private static matchesSkip(opts: { skip: TBindingSkip; binding: IBinding }): boolean {\n const { skip, binding } = opts;\n const bound = BindingVerifier.classOf(binding);\n\n if (typeof skip === 'string') {\n return skip === binding.key || (bound !== undefined && skip === bound.name);\n }\n\n return bound === skip;\n }\n\n private static readString(opts: { source: unknown; name: string }): string | undefined {\n const { source, name } = opts;\n\n if (typeof source !== 'object' || source === null || !(name in source)) {\n return undefined;\n }\n\n const value = Reflect.get(source, name);\n\n return typeof value === 'string' ? value : undefined;\n }\n\n /** What a thrown value says about the thing it could not find; a constructor's own error says nothing. */\n private static readMissing(error: unknown): { missingKey?: string; unregisteredClass?: string } {\n const extra =\n typeof error === 'object' && error !== null ? Reflect.get(error, 'extra') : undefined;\n const missingKey = BindingVerifier.readString({ source: extra, name: 'unboundKey' });\n const unregisteredClass = BindingVerifier.readString({\n source: extra,\n name: 'unregisteredClass',\n });\n\n return {\n ...(missingKey === undefined ? {} : { missingKey }),\n ...(unregisteredClass === undefined ? {} : { unregisteredClass }),\n };\n }\n\n /**\n * Resolves every binding of the given namespaces once and reports every failure, instead of stopping\n * at the first. It changes nothing in the container. A failed binding is a result, never a throw:\n * `assertResolve` is the throwing form.\n */\n static verify(opts: IVerifyBindingsOptions): IBindingVerification {\n const { container, namespaces, skip = [] } = opts;\n\n const enumerated = new Map<string, IBinding>();\n\n for (const namespace of namespaces) {\n for (const binding of container.findByTag({ tag: namespace })) {\n if (!enumerated.has(binding.key)) {\n enumerated.set(binding.key, binding);\n }\n }\n }\n\n const matched = new Set<TBindingSkip>();\n const verified: string[] = [];\n const failures: IBindingFailure[] = [];\n\n for (const binding of enumerated.values()) {\n const skipped = skip.filter((candidate) =>\n BindingVerifier.matchesSkip({ skip: candidate, binding }),\n );\n\n for (const candidate of skipped) {\n matched.add(candidate);\n }\n\n if (skipped.length > 0) {\n continue;\n }\n\n try {\n container.get({ key: binding.key });\n verified.push(binding.key);\n } catch (error) {\n failures.push({\n key: binding.key,\n message: error instanceof Error ? error.message : String(error),\n ...BindingVerifier.readMissing(error),\n error,\n });\n }\n }\n\n return {\n verified,\n failures,\n unmatchedSkips: skip.filter((candidate) => !matched.has(candidate)),\n };\n }\n\n /**\n * `verify`, and one `ApplicationError` when a binding failed or a skip matched nothing: the\n * message lists `<key>: <message>` per failure, `extra.missing` maps each missing key or class name\n * to the bindings that needed it.\n */\n static assertResolve(opts: IVerifyBindingsOptions & { scope: string }): IBindingVerification {\n const { scope, ...rest } = opts;\n const result = BindingVerifier.verify(rest);\n\n if (result.failures.length === 0 && result.unmatchedSkips.length === 0) {\n return result;\n }\n\n const parts = [\n ...result.failures.map((failure) => `${failure.key}: ${failure.message}`),\n ...result.unmatchedSkips.map(\n (skip) => `skip matched no binding: ${BindingVerifier.skipName(skip)}`,\n ),\n ];\n\n const missing: Record<string, string[]> = {};\n\n for (const failure of result.failures) {\n const what = failure.missingKey ?? failure.unregisteredClass;\n\n if (what !== undefined) {\n missing[what] = [...(missing[what] ?? []), failure.key];\n }\n }\n\n const header =\n result.failures.length > 0\n ? `[${scope}] ${result.failures.length} binding(s) cannot be resolved | `\n : `[${scope}] `;\n\n throw getError({\n message: `${header}${parts.join(' | ')}`,\n extra: {\n failures: result.failures.map(({ key, message, missingKey, unregisteredClass }) => ({\n key,\n message,\n ...(missingKey === undefined ? {} : { missingKey }),\n ...(unregisteredClass === undefined ? {} : { unregisteredClass }),\n })),\n missing,\n unmatchedSkips: result.unmatchedSkips.map(BindingVerifier.skipName),\n },\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"verifier.js","sourceRoot":"","sources":["../../../../src/modules/container/verifier.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAiDpC,iFAAiF;AACjF,MAAM,OAAO,eAAe;IAClB,MAAM,CAAC,aAAa,CAAC,OAAiB;QAC5C,OAAO,YAAY,IAAI,OAAO,IAAI,OAAO,OAAO,CAAC,UAAU,KAAK,UAAU,CAAC;IAC7E,CAAC;IAEO,MAAM,CAAC,OAAO,CAAC,OAAiB;QACtC,OAAO,eAAe,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IACnF,CAAC;IAEO,MAAM,CAAC,QAAQ,CAAC,IAAkB;QACxC,OAAO,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;IACrD,CAAC;IAEO,MAAM,CAAC,WAAW,CAAC,IAA+C;QACxE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;QAC/B,MAAM,KAAK,GAAG,eAAe,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAE/C,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC7B,OAAO,IAAI,KAAK,OAAO,CAA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getError } from '../error';\nimport type { IContainer } from './common/types';\n\n/** A class (matched exactly, never by subclass), a class name, or a binding key. */\nexport type TBindingSkip = TClass<unknown> | string;\n\n/** Input to `BindingVerifier`: the container and the namespaces whose bindings are resolved. */\nexport interface IVerifyBindingsOptions {\n container: IContainer;\n\n /**\n * A binding is in a namespace when it carries the tag `Binding` sets from the first segment of its\n * key: `services.Orders` is in `services`. Required: inversion does not know which namespaces an\n * application uses. A namespace that itself holds a dot is not supported.\n */\n namespaces: string[];\n\n /** Bindings to leave unresolved. A skip that matches no enumerated binding is reported in `unmatchedSkips`. */\n skip?: TBindingSkip[];\n}\n\n/** One binding that threw while being resolved, with the missing key or class when the error names one. */\nexport interface IBindingFailure {\n /** The binding that could not resolve, that is, who needs the missing thing. */\n key: string;\n message: string;\n\n /** An injected key nobody bound (`extra.unboundKey` of the container's error). */\n missingKey?: string;\n\n /** An injected class nobody registered (`extra.unregisteredClass` of the container's error). */\n unregisteredClass?: string;\n\n /** The thrown object, unchanged. */\n error: unknown;\n}\n\n/** Result of verifying bindings: the keys that resolved, the failures, and the `skip` entries that matched nothing. */\nexport interface IBindingVerification {\n /** Keys resolved, in container order, namespaces in the order given. */\n verified: string[];\n failures: IBindingFailure[];\n unmatchedSkips: TBindingSkip[];\n}\n\ninterface IClassBinding {\n boundClass: () => TClass<unknown> | undefined;\n}\n\n/** Resolves bindings of the given namespaces and reports what cannot resolve. */\nexport class BindingVerifier {\n private static hasBoundClass(binding: IBinding): binding is IBinding & IClassBinding {\n return 'boundClass' in binding && typeof binding.boundClass === 'function';\n }\n\n private static classOf(binding: IBinding): TClass<unknown> | undefined {\n return BindingVerifier.hasBoundClass(binding) ? binding.boundClass() : undefined;\n }\n\n private static skipName(skip: TBindingSkip): string {\n return typeof skip === 'string' ? skip : skip.name;\n }\n\n private static matchesSkip(opts: { skip: TBindingSkip; binding: IBinding }): boolean {\n const { skip, binding } = opts;\n const bound = BindingVerifier.classOf(binding);\n\n if (typeof skip === 'string') {\n return skip === binding.key || (bound !== undefined && skip === bound.name);\n }\n\n return bound === skip;\n }\n\n private static readString(opts: { source: unknown; name: string }): string | undefined {\n const { source, name } = opts;\n\n if (typeof source !== 'object' || source === null || !(name in source)) {\n return undefined;\n }\n\n const value = Reflect.get(source, name);\n\n return typeof value === 'string' ? value : undefined;\n }\n\n /** What a thrown value says about the thing it could not find; a constructor's own error says nothing. */\n private static readMissing(error: unknown): { missingKey?: string; unregisteredClass?: string } {\n const extra =\n typeof error === 'object' && error !== null ? Reflect.get(error, 'extra') : undefined;\n const missingKey = BindingVerifier.readString({ source: extra, name: 'unboundKey' });\n const unregisteredClass = BindingVerifier.readString({\n source: extra,\n name: 'unregisteredClass',\n });\n\n return {\n ...(missingKey === undefined ? {} : { missingKey }),\n ...(unregisteredClass === undefined ? {} : { unregisteredClass }),\n };\n }\n\n /**\n * Resolves every binding of the given namespaces once and reports every failure, instead of stopping\n * at the first. It changes nothing in the container. A failed binding is a result, never a throw:\n * `assertResolve` is the throwing form.\n */\n static verify(opts: IVerifyBindingsOptions): IBindingVerification {\n const { container, namespaces, skip = [] } = opts;\n\n const enumerated = new Map<string, IBinding>();\n\n for (const namespace of namespaces) {\n for (const binding of container.findByTag({ tag: namespace })) {\n if (!enumerated.has(binding.key)) {\n enumerated.set(binding.key, binding);\n }\n }\n }\n\n const matched = new Set<TBindingSkip>();\n const verified: string[] = [];\n const failures: IBindingFailure[] = [];\n\n for (const binding of enumerated.values()) {\n const skipped = skip.filter((candidate) =>\n BindingVerifier.matchesSkip({ skip: candidate, binding }),\n );\n\n for (const candidate of skipped) {\n matched.add(candidate);\n }\n\n if (skipped.length > 0) {\n continue;\n }\n\n try {\n container.get({ key: binding.key });\n verified.push(binding.key);\n } catch (error) {\n failures.push({\n key: binding.key,\n message: error instanceof Error ? error.message : String(error),\n ...BindingVerifier.readMissing(error),\n error,\n });\n }\n }\n\n return {\n verified,\n failures,\n unmatchedSkips: skip.filter((candidate) => !matched.has(candidate)),\n };\n }\n\n /**\n * `verify`, and one `ApplicationError` when a binding failed or a skip matched nothing: the\n * message lists `<key>: <message>` per failure, `extra.missing` maps each missing key or class name\n * to the bindings that needed it.\n */\n static assertResolve(opts: IVerifyBindingsOptions & { scope: string }): IBindingVerification {\n const { scope, ...rest } = opts;\n const result = BindingVerifier.verify(rest);\n\n if (result.failures.length === 0 && result.unmatchedSkips.length === 0) {\n return result;\n }\n\n const parts = [\n ...result.failures.map((failure) => `${failure.key}: ${failure.message}`),\n ...result.unmatchedSkips.map(\n (skip) => `skip matched no binding: ${BindingVerifier.skipName(skip)}`,\n ),\n ];\n\n const missing: Record<string, string[]> = {};\n\n for (const failure of result.failures) {\n const what = failure.missingKey ?? failure.unregisteredClass;\n\n if (what !== undefined) {\n missing[what] = [...(missing[what] ?? []), failure.key];\n }\n }\n\n const header =\n result.failures.length > 0\n ? `[${scope}] ${result.failures.length} binding(s) cannot be resolved | `\n : `[${scope}] `;\n\n throw getError({\n message: `${header}${parts.join(' | ')}`,\n extra: {\n failures: result.failures.map(({ key, message, missingKey, unregisteredClass }) => ({\n key,\n message,\n ...(missingKey === undefined ? {} : { missingKey }),\n ...(unregisteredClass === undefined ? {} : { unregisteredClass }),\n })),\n missing,\n unmatchedSkips: result.unmatchedSkips.map(BindingVerifier.skipName),\n },\n });\n }\n}\n"]}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { TError, TErrorLogLevel, TErrorNormalized, TResponsedError } from './common/index.js';
|
|
2
|
+
/** The error type the framework throws; `normalized` holds the resolved text, code and args a client renders. */
|
|
2
3
|
export declare class ApplicationError extends Error {
|
|
4
|
+
/** @default 400 */
|
|
3
5
|
statusCode: number;
|
|
4
6
|
normalized: TErrorNormalized;
|
|
5
7
|
extra?: Record<string, unknown>;
|
|
@@ -16,7 +18,9 @@ export declare class ApplicationError extends Error {
|
|
|
16
18
|
error: TResponsedError;
|
|
17
19
|
}): ApplicationError;
|
|
18
20
|
}
|
|
21
|
+
/** Builds an `ApplicationError`; same as `ApplicationError.getError`. */
|
|
19
22
|
export declare const getError: (opts: TError) => ApplicationError;
|
|
23
|
+
/** Rebuilds an `ApplicationError` from the wire payload a client received; same as `ApplicationError.fromError`. */
|
|
20
24
|
export declare const fromError: (opts: {
|
|
21
25
|
error: TResponsedError;
|
|
22
26
|
}) => ApplicationError;
|
|
@@ -14,6 +14,7 @@ const KNOWN_KEYS = [
|
|
|
14
14
|
'logLevel',
|
|
15
15
|
'name',
|
|
16
16
|
];
|
|
17
|
+
/** The error type the framework throws; `normalized` holds the resolved text, code and args a client renders. */
|
|
17
18
|
export class ApplicationError extends Error {
|
|
18
19
|
constructor(opts) {
|
|
19
20
|
const { statusCode, messageArgs, cause, extra, transform, logLevel } = opts;
|
|
@@ -72,7 +73,9 @@ export class ApplicationError extends Error {
|
|
|
72
73
|
});
|
|
73
74
|
}
|
|
74
75
|
}
|
|
76
|
+
/** Builds an `ApplicationError`; same as `ApplicationError.getError`. */
|
|
75
77
|
export const getError = (opts) => ApplicationError.getError(opts);
|
|
78
|
+
/** Rebuilds an `ApplicationError` from the wire payload a client received; same as `ApplicationError.fromError`. */
|
|
76
79
|
export const fromError = (opts) => ApplicationError.fromError(opts);
|
|
77
80
|
/**
|
|
78
81
|
* An `ApplicationError` by shape - a numeric `statusCode` and a `normalized` with its `text` - so it
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-error.js","sourceRoot":"","sources":["../../../../src/modules/error/app-error.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAGrD,yDAAyD;AACzD,MAAM,UAAU,GAAG;IACjB,OAAO;IACP,SAAS;IACT,aAAa;IACb,YAAY;IACZ,aAAa;IACb,OAAO;IACP,OAAO;IACP,WAAW;IACX,UAAU;IACV,MAAM;CACE,CAAC;AAEX,MAAM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AI;QACnB,MAAM,IAAI,UAAU;QACpB,OAAO,UAAU,CAAC,IAAI,KAAK,QAAQ,CACpC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { type TNullable } from '@/common/types';\nimport { ObjectUtility } from '@/common/utilities';\nimport { MessageCode } from './message-code';\nimport { MessageTemplate } from './message-template';\nimport type { TError, TErrorLogLevel, TErrorNormalized, TResponsedError } from './common';\n\n/** Consumed keys. Everything else rides into `extra`. */\nconst KNOWN_KEYS = [\n 'error',\n 'message',\n 'messageCode',\n 'statusCode',\n 'messageArgs',\n 'cause',\n 'extra',\n 'transform',\n 'logLevel',\n 'name',\n] as const;\n\n/** The error type the framework throws; `normalized` holds the resolved text, code and args a client renders. */\nexport class ApplicationError extends Error {\n /** @default 400 */\n statusCode: number;\n normalized: TErrorNormalized;\n extra?: Record<string, unknown>;\n readonly logLevel?: TErrorLogLevel;\n\n constructor(opts: TError) {\n const { statusCode, messageArgs, cause, extra, transform, logLevel } = opts;\n\n // Index signature defeats `in` narrowing - read the discriminant and cast.\n const definition = 'error' in opts ? opts.error : undefined;\n\n const input = opts.message;\n const override = typeof input === 'string' ? { text: input } : input;\n\n // `?.message?.` has to guard BOTH: `error` reaches here from an untyped call site as anything at all, and a bare `definition?.message.text` throws on a malformed one.\n const message = override?.text ?? definition?.message?.text ?? '';\n const messageCode = MessageCode.resolve(\n override?.code ?? definition?.message?.code ?? (opts.messageCode as TNullable<string>),\n );\n const args = override?.args ?? messageArgs ?? definition?.message?.args;\n\n super(message, cause === undefined ? undefined : { cause });\n\n this.statusCode = statusCode ?? definition?.statusCode ?? 400;\n this.logLevel = logLevel;\n\n // Explicit `extra` wins over swept keys.\n const merged = {\n ...ObjectUtility.omit({ source: opts, keys: KNOWN_KEYS }),\n ...extra,\n };\n this.extra = Object.keys(merged).length > 0 ? merged : undefined;\n\n const normalized: TErrorNormalized = {\n text: message,\n code: messageCode,\n args: args ?? {},\n };\n\n this.normalized = transform\n ? transform({\n message: normalized,\n statusCode: this.statusCode,\n extra: this.extra,\n })\n : normalized;\n }\n\n /**\n * The message with its args filled in: `Only 2 left of TRA-01`. `message` itself stays the template,\n * so a log or an error tracker never prints a value outside the args it redacts by key - call this\n * where a plain reader stores or shows the text, such as a queue's failure reason.\n */\n toFilledText(): string {\n return MessageTemplate.render({ text: this.message, args: this.normalized.args }).text;\n }\n\n static getError(opts: TError) {\n return new ApplicationError(opts);\n }\n\n static fromError(opts: { error: TResponsedError }): ApplicationError {\n const { error } = opts;\n\n return this.getError({\n message: {\n text: error.normalized?.text ?? error.message ?? '',\n code: error.normalized?.code,\n args: error.normalized?.args,\n },\n statusCode: error.statusCode,\n extra: error.extra,\n ...(error.requestId === undefined ? {} : { requestId: error.requestId }),\n });\n }\n}\n\n/** Builds an `ApplicationError`; same as `ApplicationError.getError`. */\nexport const getError = (opts: TError): ApplicationError => ApplicationError.getError(opts);\n\n/** Rebuilds an `ApplicationError` from the wire payload a client received; same as `ApplicationError.fromError`. */\nexport const fromError = (opts: { error: TResponsedError }): ApplicationError =>\n ApplicationError.fromError(opts);\n\n/**\n * An `ApplicationError` by shape - a numeric `statusCode` and a `normalized` with its `text` - so it\n * holds across the CJS and ESM copies of this class, where `instanceof` does not. A plain `Error`\n * that merely carries a `statusCode` (an HTTP client's, an engine's) is not one.\n *\n * An error from a copy older than 0.2.2-0 matches but has no `toFilledText()`.\n */\nexport const isApplicationError = (error: unknown): error is ApplicationError => {\n if (!(error instanceof Error) || !('statusCode' in error) || !('normalized' in error)) {\n return false;\n }\n\n const { statusCode, normalized } = error;\n\n return (\n typeof statusCode === 'number' &&\n typeof normalized === 'object' &&\n normalized !== null &&\n 'text' in normalized &&\n typeof normalized.text === 'string'\n );\n};\n"]}
|
|
@@ -29,6 +29,7 @@ export type TErrorDefinitionMessage = Omit<TErrorMessageInput, 'code'> & {
|
|
|
29
29
|
export type TErrorMessage = string | TErrorMessageInput;
|
|
30
30
|
/** The catalogued form's override - every field optional, since the definition supplies the rest. */
|
|
31
31
|
export type TErrorMessageOverride = string | Partial<TErrorMessageInput>;
|
|
32
|
+
/** A catalogued error: a message with a required code, an HTTP status code, and an optional scope and description. */
|
|
32
33
|
export type TErrorDefinition = {
|
|
33
34
|
message: TErrorDefinitionMessage;
|
|
34
35
|
statusCode: number;
|
|
@@ -38,6 +39,7 @@ export type TErrorDefinition = {
|
|
|
38
39
|
/** Augmented per-package via declaration merging, driving `messageCode` autocomplete. */
|
|
39
40
|
export interface IErrorKeyRegistry {
|
|
40
41
|
}
|
|
42
|
+
/** A registered message code when `IErrorKeyRegistry` is augmented, otherwise any `string`. */
|
|
41
43
|
export type TErrorKey = [keyof IErrorKeyRegistry] extends [never] ? string : Extract<keyof IErrorKeyRegistry, string>;
|
|
42
44
|
/** Builds {@link TErrorNormalized} in place of the default; `message` is the default it replaces. */
|
|
43
45
|
export type TErrorNormalizeTransformFn = (opts: {
|
|
@@ -52,6 +54,7 @@ type TErrorCommon = {
|
|
|
52
54
|
cause?: unknown;
|
|
53
55
|
extra?: Record<string, unknown>;
|
|
54
56
|
transform?: TErrorNormalizeTransformFn;
|
|
57
|
+
/** @default 'error' */
|
|
55
58
|
logLevel?: TErrorLogLevel;
|
|
56
59
|
};
|
|
57
60
|
/** Catalogued form - `message` and `statusCode` override the definition's defaults; the object form is partial, so `{ message: { args } }` amends the args and keeps the definition's text and code. */
|
|
@@ -68,6 +71,7 @@ export type TErrorByField = TErrorCommon & {
|
|
|
68
71
|
error?: never;
|
|
69
72
|
[key: string]: unknown;
|
|
70
73
|
};
|
|
74
|
+
/** The input of `ApplicationError` and `getError`: a catalogued definition or free-form fields. */
|
|
71
75
|
export type TError = TErrorByDefinition | TErrorByField;
|
|
72
76
|
/** Registers a catalog's keys with {@link IErrorKeyRegistry}, via `declare module '@venizia/ignis-helpers' { interface IErrorKeyRegistry extends TRegisterErrors<typeof CategoryErrors> {} }`. */
|
|
73
77
|
export type TRegisterErrors<T extends Record<string, TErrorDefinition>> = Record<T[keyof T]['message']['code'], true>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/modules/error/common/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { TErrorScope } from '../definition';\nimport type { TErrorLogLevel } from './constants';\n\n/** Resolved message a client renders. All fields always present - no null-checks downstream. */\nexport type TErrorNormalized = {\n text: string;\n code: string;\n args: Record<string, unknown>;\n};\n\n/** Wire payload as a CLIENT receives it - the input to {@link ApplicationError.fromError}. Every field is optional on purpose: a client parses what a gateway, a proxy or an older server actually sent. */\nexport type TResponsedError = {\n message?: string;\n statusCode?: number;\n normalized?: Partial<TErrorNormalized>;\n extra?: Record<string, unknown>;\n requestId?: string;\n details?: Record<string, unknown>;\n};\n\n/** The message a CALLER supplies - only `text` is required, the rest is what {@link TErrorNormalized} resolves; every other message shape is derived from this one. */\nexport type TErrorMessageInput = {\n text: string;\n code?: TErrorKey | (string & Record<never, never>);\n args?: Record<string, unknown>;\n};\n\n/** Catalogued message - `code` required, typed `string` and not {@link TErrorKey}: catalogs DECLARE the registry keys, so typing against the registry would be self-referential. */\nexport type TErrorDefinitionMessage = Omit<TErrorMessageInput, 'code'> & { code: string };\n\n/** The free-form input: a bare string is the historical shape. */\nexport type TErrorMessage = string | TErrorMessageInput;\n\n/** The catalogued form's override - every field optional, since the definition supplies the rest. */\nexport type TErrorMessageOverride = string | Partial<TErrorMessageInput>;\n\nexport type TErrorDefinition = {\n message: TErrorDefinitionMessage;\n statusCode: number;\n category?: TErrorScope;\n description?: string;\n};\n\n/** Augmented per-package via declaration merging, driving `messageCode` autocomplete. */\nexport interface IErrorKeyRegistry {}\n\nexport type TErrorKey = [keyof IErrorKeyRegistry] extends [never]\n ? string\n : Extract<keyof IErrorKeyRegistry, string>;\n\n/** Builds {@link TErrorNormalized} in place of the default; `message` is the default it replaces. */\nexport type TErrorNormalizeTransformFn = (opts: {\n message: TErrorNormalized;\n statusCode: number;\n extra?: Record<string, unknown>;\n}) => TErrorNormalized;\n\n/** Shared by both input forms - unknown keys ride the index signature into `extra`, so a throw site can attach context the framework does not model, and so does a mistyped key. */\ntype TErrorCommon = {\n statusCode?: number;\n messageArgs?: Record<string, unknown>;\n cause?: unknown;\n extra?: Record<string, unknown>;\n transform?: TErrorNormalizeTransformFn;\n logLevel?: TErrorLogLevel
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/modules/error/common/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { TErrorScope } from '../definition';\nimport type { TErrorLogLevel } from './constants';\n\n/** Resolved message a client renders. All fields always present - no null-checks downstream. */\nexport type TErrorNormalized = {\n text: string;\n code: string;\n args: Record<string, unknown>;\n};\n\n/** Wire payload as a CLIENT receives it - the input to {@link ApplicationError.fromError}. Every field is optional on purpose: a client parses what a gateway, a proxy or an older server actually sent. */\nexport type TResponsedError = {\n message?: string;\n statusCode?: number;\n normalized?: Partial<TErrorNormalized>;\n extra?: Record<string, unknown>;\n requestId?: string;\n details?: Record<string, unknown>;\n};\n\n/** The message a CALLER supplies - only `text` is required, the rest is what {@link TErrorNormalized} resolves; every other message shape is derived from this one. */\nexport type TErrorMessageInput = {\n text: string;\n code?: TErrorKey | (string & Record<never, never>);\n args?: Record<string, unknown>;\n};\n\n/** Catalogued message - `code` required, typed `string` and not {@link TErrorKey}: catalogs DECLARE the registry keys, so typing against the registry would be self-referential. */\nexport type TErrorDefinitionMessage = Omit<TErrorMessageInput, 'code'> & { code: string };\n\n/** The free-form input: a bare string is the historical shape. */\nexport type TErrorMessage = string | TErrorMessageInput;\n\n/** The catalogued form's override - every field optional, since the definition supplies the rest. */\nexport type TErrorMessageOverride = string | Partial<TErrorMessageInput>;\n\n/** A catalogued error: a message with a required code, an HTTP status code, and an optional scope and description. */\nexport type TErrorDefinition = {\n message: TErrorDefinitionMessage;\n statusCode: number;\n category?: TErrorScope;\n description?: string;\n};\n\n/** Augmented per-package via declaration merging, driving `messageCode` autocomplete. */\nexport interface IErrorKeyRegistry {}\n\n/** A registered message code when `IErrorKeyRegistry` is augmented, otherwise any `string`. */\nexport type TErrorKey = [keyof IErrorKeyRegistry] extends [never]\n ? string\n : Extract<keyof IErrorKeyRegistry, string>;\n\n/** Builds {@link TErrorNormalized} in place of the default; `message` is the default it replaces. */\nexport type TErrorNormalizeTransformFn = (opts: {\n message: TErrorNormalized;\n statusCode: number;\n extra?: Record<string, unknown>;\n}) => TErrorNormalized;\n\n/** Shared by both input forms - unknown keys ride the index signature into `extra`, so a throw site can attach context the framework does not model, and so does a mistyped key. */\ntype TErrorCommon = {\n statusCode?: number;\n messageArgs?: Record<string, unknown>;\n cause?: unknown;\n extra?: Record<string, unknown>;\n transform?: TErrorNormalizeTransformFn;\n /** @default 'error' */\n logLevel?: TErrorLogLevel;\n};\n\n/** Catalogued form - `message` and `statusCode` override the definition's defaults; the object form is partial, so `{ message: { args } }` amends the args and keeps the definition's text and code. */\nexport type TErrorByDefinition = TErrorCommon & {\n error: TErrorDefinition;\n message?: TErrorMessageOverride;\n [key: string]: unknown;\n};\n\n/** Free-form: an invariant, a misconfiguration, a failure carrying no i18n code. `message` is the only required field - most throw sites legitimately fall back to `MessageCode.DEFAULT`. */\nexport type TErrorByField = TErrorCommon & {\n message: TErrorMessage;\n messageCode?: TErrorKey | (string & Record<never, never>);\n /** Never valid here - `error` is the catalogued form's discriminant and a CONSUMED key, so a wrapped failure passed as `error` would vanish; use `cause`. */\n error?: never;\n [key: string]: unknown;\n};\n\n/** The input of `ApplicationError` and `getError`: a catalogued definition or free-form fields. */\nexport type TError = TErrorByDefinition | TErrorByField;\n\n/** Registers a catalog's keys with {@link IErrorKeyRegistry}, via `declare module '@venizia/ignis-helpers' { interface IErrorKeyRegistry extends TRegisterErrors<typeof CategoryErrors> {} }`. */\nexport type TRegisterErrors<T extends Record<string, TErrorDefinition>> = Record<\n T[keyof T]['message']['code'],\n true\n>;\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { TConstValue } from '../../common/types.js';
|
|
2
|
+
/** Categories an error definition can belong to, set in `TErrorDefinition.category`. */
|
|
2
3
|
export declare class ErrorScopes {
|
|
3
4
|
static readonly AUTH = "auth";
|
|
4
5
|
static readonly VALIDATION = "validation";
|
|
@@ -6,5 +7,6 @@ export declare class ErrorScopes {
|
|
|
6
7
|
static readonly SYSTEM = "system";
|
|
7
8
|
static readonly INTEGRATION = "integration";
|
|
8
9
|
}
|
|
10
|
+
/** One of the `ErrorScopes` values. */
|
|
9
11
|
export type TErrorScope = TConstValue<typeof ErrorScopes>;
|
|
10
12
|
//# sourceMappingURL=definition.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definition.js","sourceRoot":"","sources":["../../../../src/modules/error/definition.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,WAAW;aACN,SAAI,GAAG,MAAM,CAAC;aACd,eAAU,GAAG,YAAY,CAAC;aAC1B,aAAQ,GAAG,UAAU,CAAC;aACtB,WAAM,GAAG,QAAQ,CAAC;aAClB,gBAAW,GAAG,aAAa,CAAC","sourcesContent":["import type { TConstValue } from '@/common/types';\n\nexport class ErrorScopes {\n static readonly AUTH = 'auth';\n static readonly VALIDATION = 'validation';\n static readonly BUSINESS = 'business';\n static readonly SYSTEM = 'system';\n static readonly INTEGRATION = 'integration';\n}\n\nexport type TErrorScope = TConstValue<typeof ErrorScopes>;\n"]}
|
|
1
|
+
{"version":3,"file":"definition.js","sourceRoot":"","sources":["../../../../src/modules/error/definition.ts"],"names":[],"mappings":"AAEA,wFAAwF;AACxF,MAAM,OAAO,WAAW;aACN,SAAI,GAAG,MAAM,CAAC;aACd,eAAU,GAAG,YAAY,CAAC;aAC1B,aAAQ,GAAG,UAAU,CAAC;aACtB,WAAM,GAAG,QAAQ,CAAC;aAClB,gBAAW,GAAG,aAAa,CAAC","sourcesContent":["import type { TConstValue } from '@/common/types';\n\n/** Categories an error definition can belong to, set in `TErrorDefinition.category`. */\nexport class ErrorScopes {\n static readonly AUTH = 'auth';\n static readonly VALIDATION = 'validation';\n static readonly BUSINESS = 'business';\n static readonly SYSTEM = 'system';\n static readonly INTEGRATION = 'integration';\n}\n\n/** One of the `ErrorScopes` values. */\nexport type TErrorScope = TConstValue<typeof ErrorScopes>;\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { TNullable } from '../../common/types.js';
|
|
2
2
|
import type { TError } from './common/index.js';
|
|
3
3
|
type TErrorFactory = (opts: TError) => Error;
|
|
4
|
+
/** Message codes: dot-separated lower snake_case segments, at least two (`namespace.reason`). */
|
|
4
5
|
export declare class MessageCode {
|
|
5
6
|
static readonly SEPARATOR = ".";
|
|
6
7
|
static readonly SEGMENT_PATTERN: RegExp;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message-code.js","sourceRoot":"","sources":["../../../../src/modules/error/message-code.ts"],"names":[],"mappings":"AAKA,MAAM,OAAO,WAAW;aACN,cAAS,GAAG,GAAG,CAAC;aAChB,oBAAe,GAAG,0BAA0B,CAAC;aAC7C,iBAAY,GAAG,CAAC,CAAC;aACjB,YAAO,GAAG,mBAAmB,CAAC;IAE9C,0FAA0F;aAC3E,iBAAY,GAAkB,CAAC,IAAI,EAAE,EAAE;IACpD,uGAAuG;IACvG,IAAI,KAAK,CAAC,OAAO,IAAI,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAE5F;;;;OAIG;IACH,MAAM,CAAC,eAAe,CAAC,IAAgC;QACrD,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC;IACnC,CAAC;IAED,6LAA6L;IAC7L,MAAM,CAAC,KAAK,CAAC,IAA8B;QACzC,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;QAEvB,IAAI,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;YACrC,MAA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C","sourcesContent":["import type { TNullable } from '@/common/types';\nimport type { TError } from './common';\n\ntype TErrorFactory = (opts: TError) => Error;\n\nexport class MessageCode {\n static readonly SEPARATOR = '.';\n static readonly SEGMENT_PATTERN = /^[a-z0-9]+(_[a-z0-9]+)*$/;\n static readonly MIN_SEGMENTS = 2;\n static readonly DEFAULT = 'core.system_error';\n\n // The one permitted raw `new Error`, used only until `src/index.ts` registers `getError`.\n private static errorFactory: TErrorFactory = (opts) =>\n // eslint-disable-next-line venizia/no-new-error -- the bootstrap factory, replaced by getError at init\n new Error(typeof opts.message === 'string' ? opts.message : JSON.stringify(opts.message));\n\n /**\n * Registered by the package entry at module init; keeps the throws identical without a\n * static import of app-error (that import was the cycle).\n * @internal Framework wiring; consumers must not replace the factory.\n */\n static useErrorFactory(opts: { factory: TErrorFactory }): void {\n this.errorFactory = opts.factory;\n }\n\n /** Builds a code from its segments, throwing on a malformed one - codes are declared at module scope, so a bad code fails the process at import instead of shipping dead into production. */\n static build(opts: { parts: Array<string> }): string {\n const { parts } = opts;\n\n if (parts.length < this.MIN_SEGMENTS) {\n throw this.errorFactory({\n messageCode: 'core.message_code.invalid_segment_count',\n message: `[MessageCode][build] A code needs at least ${this.MIN_SEGMENTS} segments (namespace + reason) | Got: ${JSON.stringify(parts)}`,\n });\n }\n\n for (const segment of parts) {\n if (!this.SEGMENT_PATTERN.test(segment)) {\n throw this.errorFactory({\n messageCode: 'core.message_code.invalid_segment_format',\n message: `[MessageCode][build] Invalid segment '${segment}' | Expected lower snake_case (a-z, 0-9, '_') | Full: ${JSON.stringify(parts)}`,\n });\n }\n }\n\n return parts.join(this.SEPARATOR).toLowerCase();\n }\n\n /** True when `code` is well-formed. Takes `unknown` because it guards codes arriving from outside - a guard that throws on the very input it exists to screen is not a guard. */\n static isValid(code: unknown): boolean {\n if (typeof code !== 'string') {\n return false;\n }\n\n const segments = code.split(this.SEPARATOR);\n\n return (\n segments.length >= this.MIN_SEGMENTS &&\n segments.every((segment) => this.SEGMENT_PATTERN.test(segment))\n );\n }\n\n /** Normalizes an absent, empty or non-string code to {@link DEFAULT}. */\n static resolve(code?: TNullable<string>): string {\n return typeof code === 'string' && code.length\n ? code.toLowerCase()\n : this.DEFAULT.toLowerCase();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"message-code.js","sourceRoot":"","sources":["../../../../src/modules/error/message-code.ts"],"names":[],"mappings":"AAKA,iGAAiG;AACjG,MAAM,OAAO,WAAW;aACN,cAAS,GAAG,GAAG,CAAC;aAChB,oBAAe,GAAG,0BAA0B,CAAC;aAC7C,iBAAY,GAAG,CAAC,CAAC;aACjB,YAAO,GAAG,mBAAmB,CAAC;IAE9C,0FAA0F;aAC3E,iBAAY,GAAkB,CAAC,IAAI,EAAE,EAAE;IACpD,uGAAuG;IACvG,IAAI,KAAK,CAAC,OAAO,IAAI,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAE5F;;;;OAIG;IACH,MAAM,CAAC,eAAe,CAAC,IAAgC;QACrD,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC;IACnC,CAAC;IAED,6LAA6L;IAC7L,MAAM,CAAC,KAAK,CAAC,IAA8B;QACzC,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;QAEvB,IAAI,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;YACrC,MAAM,IAAI,CAAC,YAAY,CAAC;gBACtB,WAAW,EAAE,yCAAyC;gBACtD,OAAO,EAAE,8CAA8C,IAAI,CAAC,YAAY,yCAAyC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE;aACzI,CAAC,CAAC;QACL,CAAC;QAED,KAAK,MAAM,OAAO,IAAI,KAAK,EAAE,CAAC;YAC5B,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;gBACxC,MAAM,IAAI,CAAC,YAAY,CAAC;oBACtB,WAAW,EAAE,0CAA0C;oBACvD,OAAO,EAAE,yCAAyC,OAAO,yDAAyD,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE;iBAC1I,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,CAAC;IAClD,CAAC;IAED,iLAAiL;IACjL,MAAM,CAAC,OAAO,CAAC,IAAa;QAC1B,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC7B,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAE5C,OAAO,CACL,QAAQ,CAAC,MAAM,IAAI,IAAI,CAAC,YAAY;YACpC,QAAQ,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAChE,CAAC;IACJ,CAAC;IAED,yEAAyE;IACzE,MAAM,CAAC,OAAO,CAAC,IAAwB;QACrC,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM;YAC5C,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE;YACpB,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;IACjC,CAAC","sourcesContent":["import type { TNullable } from '@/common/types';\nimport type { TError } from './common';\n\ntype TErrorFactory = (opts: TError) => Error;\n\n/** Message codes: dot-separated lower snake_case segments, at least two (`namespace.reason`). */\nexport class MessageCode {\n static readonly SEPARATOR = '.';\n static readonly SEGMENT_PATTERN = /^[a-z0-9]+(_[a-z0-9]+)*$/;\n static readonly MIN_SEGMENTS = 2;\n static readonly DEFAULT = 'core.system_error';\n\n // The one permitted raw `new Error`, used only until `src/index.ts` registers `getError`.\n private static errorFactory: TErrorFactory = (opts) =>\n // eslint-disable-next-line venizia/no-new-error -- the bootstrap factory, replaced by getError at init\n new Error(typeof opts.message === 'string' ? opts.message : JSON.stringify(opts.message));\n\n /**\n * Registered by the package entry at module init; keeps the throws identical without a\n * static import of app-error (that import was the cycle).\n * @internal Framework wiring; consumers must not replace the factory.\n */\n static useErrorFactory(opts: { factory: TErrorFactory }): void {\n this.errorFactory = opts.factory;\n }\n\n /** Builds a code from its segments, throwing on a malformed one - codes are declared at module scope, so a bad code fails the process at import instead of shipping dead into production. */\n static build(opts: { parts: Array<string> }): string {\n const { parts } = opts;\n\n if (parts.length < this.MIN_SEGMENTS) {\n throw this.errorFactory({\n messageCode: 'core.message_code.invalid_segment_count',\n message: `[MessageCode][build] A code needs at least ${this.MIN_SEGMENTS} segments (namespace + reason) | Got: ${JSON.stringify(parts)}`,\n });\n }\n\n for (const segment of parts) {\n if (!this.SEGMENT_PATTERN.test(segment)) {\n throw this.errorFactory({\n messageCode: 'core.message_code.invalid_segment_format',\n message: `[MessageCode][build] Invalid segment '${segment}' | Expected lower snake_case (a-z, 0-9, '_') | Full: ${JSON.stringify(parts)}`,\n });\n }\n }\n\n return parts.join(this.SEPARATOR).toLowerCase();\n }\n\n /** True when `code` is well-formed. Takes `unknown` because it guards codes arriving from outside - a guard that throws on the very input it exists to screen is not a guard. */\n static isValid(code: unknown): boolean {\n if (typeof code !== 'string') {\n return false;\n }\n\n const segments = code.split(this.SEPARATOR);\n\n return (\n segments.length >= this.MIN_SEGMENTS &&\n segments.every((segment) => this.SEGMENT_PATTERN.test(segment))\n );\n }\n\n /** Normalizes an absent, empty or non-string code to {@link DEFAULT}. */\n static resolve(code?: TNullable<string>): string {\n return typeof code === 'string' && code.length\n ? code.toLowerCase()\n : this.DEFAULT.toLowerCase();\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../src/modules/metadata/common/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,UAAU,EAAE,MAAM,CAAC,GAAG,CAAC,kBAAkB,CAAC;IAC1C,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,cAAc,CAAC;IAClC,WAAW,EAAE,MAAM,CAAC,GAAG,CAAC,mBAAmB,CAAC;CAC7C,CAAC","sourcesContent":["
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../src/modules/metadata/common/constants.ts"],"names":[],"mappings":"AAAA,8GAA8G;AAC9G,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,UAAU,EAAE,MAAM,CAAC,GAAG,CAAC,kBAAkB,CAAC;IAC1C,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,cAAc,CAAC;IAClC,WAAW,EAAE,MAAM,CAAC,GAAG,CAAC,mBAAmB,CAAC;CAC7C,CAAC","sourcesContent":["/** Symbol keys under which the decorators store reflect metadata: properties, injects and the binding key. */\nexport const MetadataKeys = {\n PROPERTIES: Symbol.for('ignis:properties'),\n INJECT: Symbol.for('ignis:inject'),\n BINDING_KEY: Symbol.for('ignis:binding-key'),\n};\n"]}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { TBindingKey, TInjectTarget } from '../../../common/types.js';
|
|
2
|
+
/** Metadata recorded for an injected property. */
|
|
2
3
|
export interface IPropertyMetadata {
|
|
3
4
|
bindingKey?: TBindingKey;
|
|
4
5
|
/** Named by class, or by a function returning it; the key is read off the class at resolve time. */
|
|
5
6
|
target?: TInjectTarget;
|
|
6
7
|
isOptional?: boolean;
|
|
7
8
|
}
|
|
9
|
+
/** Metadata recorded for an injected constructor parameter; `index` is its position. */
|
|
8
10
|
export interface IInjectMetadata {
|
|
9
11
|
key?: TBindingKey;
|
|
10
12
|
/** Named by class, or by a function returning it; the key is read off the class at resolve time. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/modules/registry/common/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { TBindingKey, TInjectTarget } from '@/common/types';\n\n// No index signature: it would let a misspelled read (`metadata.optional`) compile as `any`.\nexport interface IPropertyMetadata {\n bindingKey?: TBindingKey;\n /** Named by class, or by a function returning it; the key is read off the class at resolve time. */\n target?: TInjectTarget;\n isOptional?: boolean;\n}\n\nexport interface IInjectMetadata {\n key?: TBindingKey;\n /** Named by class, or by a function returning it; the key is read off the class at resolve time. */\n target?: TInjectTarget;\n index: number;\n isOptional?: boolean;\n}\n\n/** What `MetadataKeys.BINDING_KEY` holds. */\nexport interface IBindingKeyRecord {\n key: TBindingKey;\n isProvisional: boolean;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/modules/registry/common/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { TBindingKey, TInjectTarget } from '@/common/types';\n\n// No index signature: it would let a misspelled read (`metadata.optional`) compile as `any`.\n/** Metadata recorded for an injected property. */\nexport interface IPropertyMetadata {\n bindingKey?: TBindingKey;\n /** Named by class, or by a function returning it; the key is read off the class at resolve time. */\n target?: TInjectTarget;\n isOptional?: boolean;\n}\n\n/** Metadata recorded for an injected constructor parameter; `index` is its position. */\nexport interface IInjectMetadata {\n key?: TBindingKey;\n /** Named by class, or by a function returning it; the key is read off the class at resolve time. */\n target?: TInjectTarget;\n index: number;\n isOptional?: boolean;\n}\n\n/** What `MetadataKeys.BINDING_KEY` holds. */\nexport interface IBindingKeyRecord {\n key: TBindingKey;\n isProvisional: boolean;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../../../src/modules/registry/registry.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAE1B,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB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C,cAAc,CACnE,YAAY,CAAC,WAAW,EACxB,MAAM,CACP,CAAC;QAEF,6FAA6F;QAC7F,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,CAAC,GAAG,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,IAAI,CAAC,aAAa,EAAE,CAAC;YAC7F,MAAM,CAAC,IAAI,CACT,gFAAgF,EAC/E,MAA4B,CAAC,IAAI,EAClC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,EACtB,GAAG,CAAC,QAAQ,EAAE,CACf,CAAC;QACJ,CAAC;QAED,OAAO,CAAC,cAAc,CAAC,YAAY,CAAC,WAAW,EAAE,EAAE,GAAG,EAAE,aAAa,EAAE,EAAE,MAAM,CAAC,CAAC;IACnF,CAAC;IAED,2GAA2G;IAC3G,aAAa,CAA4B,IAAmB;QAC1D,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;QACxB,MAAM,MAAM,GAAkC,OAAO,CAAC,cAAc,CAClE,YAAY,CAAC,WAAW,EACxB,MAAM,CACP,CAAC;QAEF,OAAO,MAAM,EAAE,GAAG,CAAC;IACrB,CAAC;CACF;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,gBAAgB,EAAE,CAAC","sourcesContent":["import 'reflect-metadata';\n\nimport { BaseHelper } from '@/common/base-helper';\nimport { Logger } from '@/common/logger';\nimport { type TBindingKey, type TClass } from '@/common/types';\nimport { MetadataKeys } from '../metadata/common/constants';\nimport {\n type IBindingKeyRecord,\n type IInjectMetadata,\n type IPropertyMetadata,\n} from './common/types';\n\n/** Central metadata registry for storing and retrieving decorator metadata. */\nexport class MetadataRegistry extends BaseHelper {\n constructor() {\n super({ scope: MetadataRegistry.name });\n }\n\n define<Target extends object = object, Value = any>(opts: {\n target: Target;\n key: TBindingKey;\n value: Value;\n }): void {\n const { target, key, value } = opts;\n\n Logger.debug(\n '[define] Set metadata | target: %s | key: %s | value: %j',\n target.constructor.name,\n key.toString(),\n value,\n );\n\n Reflect.defineMetadata(key, value, target);\n }\n\n get<Target extends object = object, Value = any>(opts: {\n target: Target;\n key: TBindingKey;\n }): Value | undefined {\n const { target, key } = opts;\n\n return Reflect.getMetadata(key, target);\n }\n\n has<Target extends object = object>(opts: { target: Target; key: TBindingKey }): boolean {\n const { target, key } = opts;\n\n return Reflect.hasMetadata(key, target);\n }\n\n delete<Target extends object = object>(opts: { target: Target; key: TBindingKey }): boolean {\n const { target, key } = opts;\n\n return Reflect.deleteMetadata(key, target);\n }\n\n getKeys<Target extends object = object>(opts: { target: Target }): TBindingKey[] {\n const { target } = opts;\n\n return (\n Reflect.getMetadataKeys(target)?.filter((key) => {\n return typeof key === 'symbol' || typeof key === 'string';\n }) ?? []\n );\n }\n\n getMethodNames<T = any>(opts: { target: TClass<T> }): string[] {\n const { target } = opts;\n const prototype = target.prototype;\n const methods = Object.getOwnPropertyNames(prototype).filter(\n (name) => name !== 'constructor' && typeof prototype[name] === 'function',\n );\n\n return methods;\n }\n\n clearMetadata<T extends object = object>(opts: { target: T }): void {\n const { target } = opts;\n const keys = Reflect.getMetadataKeys(target);\n\n for (const key of keys) {\n Reflect.deleteMetadata(key, target);\n }\n }\n\n setPropertyMetadata<T extends object = object>(opts: {\n target: T;\n propertyName: string | symbol;\n metadata: IPropertyMetadata;\n }): void {\n const { target, propertyName, metadata } = opts;\n\n // Copy-on-write, as for constructor injection: the inherited map belongs to the parent class and\n // every sibling subclass reads it.\n const own: Map<string | symbol, IPropertyMetadata> | undefined = Reflect.getOwnMetadata(\n MetadataKeys.PROPERTIES,\n target.constructor,\n );\n const properties = own ?? new Map(this.getPropertiesMetadata({ target }));\n\n properties.set(propertyName, metadata);\n Reflect.defineMetadata(MetadataKeys.PROPERTIES, properties, target.constructor);\n }\n\n getPropertiesMetadata<T extends object = object>(opts: {\n target: T;\n }): Map<string | symbol, IPropertyMetadata> | undefined {\n const { target } = opts;\n\n return Reflect.getMetadata(MetadataKeys.PROPERTIES, target.constructor);\n }\n\n getPropertyMetadata<T extends object = object>(opts: {\n target: T;\n propertyName: string | symbol;\n }): IPropertyMetadata | undefined {\n const { target, propertyName } = opts;\n const properties = this.getPropertiesMetadata({ target });\n\n return properties?.get(propertyName);\n }\n\n setInjectMetadata<T extends object = object>(opts: {\n target: T;\n index: number;\n metadata: IInjectMetadata;\n }): void {\n const { target, index, metadata } = opts;\n // Copy-on-write: the inherited list belongs to the parent class and every sibling subclass reads it.\n const own: IInjectMetadata[] | undefined = Reflect.getOwnMetadata(MetadataKeys.INJECT, target);\n const injects = own ?? [...(Reflect.getMetadata(MetadataKeys.INJECT, target) ?? [])];\n injects[index] = metadata;\n Reflect.defineMetadata(MetadataKeys.INJECT, injects, target);\n }\n\n getInjectMetadata<T extends object = object>(opts: { target: T }): IInjectMetadata[] | undefined {\n const { target } = opts;\n\n return Reflect.getMetadata(MetadataKeys.INJECT, target);\n }\n\n /** `isProvisional` marks a DERIVED key; a registration replaces it silently, having seen the call-site override. */\n setBindingKey<T extends object = object>(opts: {\n target: T;\n key: TBindingKey;\n isProvisional?: boolean;\n }): void {\n const { target, key, isProvisional = false } = opts;\n const current: IBindingKeyRecord | undefined = Reflect.getOwnMetadata(\n MetadataKeys.BINDING_KEY,\n target,\n );\n\n // Two apps in one process, one class, two keys: the last registration would decide for both.\n if (current !== undefined && current.key !== key && !current.isProvisional && !isProvisional) {\n Logger.warn(\n '[setBindingKey] Rebound under a different key | target: %s | was: %s | now: %s',\n (target as { name?: string }).name,\n current.key.toString(),\n key.toString(),\n );\n }\n\n Reflect.defineMetadata(MetadataKeys.BINDING_KEY, { key, isProvisional }, target);\n }\n\n /** Own metadata only: a subclass is not registered, and the parent key would resolve the wrong binding. */\n getBindingKey<T extends object = object>(opts: { target: T }): TBindingKey | undefined {\n const { target } = opts;\n const record: IBindingKeyRecord | undefined = Reflect.getOwnMetadata(\n MetadataKeys.BINDING_KEY,\n target,\n );\n\n return record?.key;\n }\n}\n\nexport const metadataRegistry = new MetadataRegistry();\n"]}
|
|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AAM,EAAE,MAAM,CAAC,CAAC;IAC1D,CAAC;IAED,oHAAoH;IACpH,aAAa,CAA4B,IAIxC;QACC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,aAAa,GAAG,KAAK,EAAE,GAAG,IAAI,CAAC;QACpD,MAAM,OAAO,GAAkC,OAAO,CAAC,cAAc,CACnE,YAAY,CAAC,WAAW,EACxB,MAAM,CACP,CAAC;QAEF,6FAA6F;QAC7F,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,CAAC,GAAG,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,IAAI,CAAC,aAAa,EAAE,CAAC;YAC7F,MAAM,CAAC,IAAI,CACT,gFAAgF,EAC/E,MAA4B,CAAC,IAAI,EAClC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,EACtB,GAAG,CAAC,QAAQ,EAAE,CACf,CAAC;QACJ,CAAC;QAED,OAAO,CAAC,cAAc,CAAC,YAAY,CAAC,WAAW,EAAE,EAAE,GAAG,EAAE,aAAa,EAAE,EAAE,MAAM,CAAC,CAAC;IACnF,CAAC;IAED,2GAA2G;IAC3G,aAAa,CAA4B,IAAmB;QAC1D,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;QACxB,MAAM,MAAM,GAAkC,OAAO,CAAC,cAAc,CAClE,YAAY,CAAC,WAAW,EACxB,MAAM,CACP,CAAC;QAEF,OAAO,MAAM,EAAE,GAAG,CAAC;IACrB,CAAC;CACF;AAED,8CAA8C;AAC9C,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,gBAAgB,EAAE,CAAC","sourcesContent":["import 'reflect-metadata';\n\nimport { BaseHelper } from '@/common/base-helper';\nimport { Logger } from '@/common/logger';\nimport { type TBindingKey, type TClass } from '@/common/types';\nimport { MetadataKeys } from '../metadata/common/constants';\nimport {\n type IBindingKeyRecord,\n type IInjectMetadata,\n type IPropertyMetadata,\n} from './common/types';\n\n/** Central metadata registry for storing and retrieving decorator metadata. */\nexport class MetadataRegistry extends BaseHelper {\n constructor() {\n super({ scope: MetadataRegistry.name });\n }\n\n define<Target extends object = object, Value = any>(opts: {\n target: Target;\n key: TBindingKey;\n value: Value;\n }): void {\n const { target, key, value } = opts;\n\n Logger.debug(\n '[define] Set metadata | target: %s | key: %s | value: %j',\n target.constructor.name,\n key.toString(),\n value,\n );\n\n Reflect.defineMetadata(key, value, target);\n }\n\n get<Target extends object = object, Value = any>(opts: {\n target: Target;\n key: TBindingKey;\n }): Value | undefined {\n const { target, key } = opts;\n\n return Reflect.getMetadata(key, target);\n }\n\n has<Target extends object = object>(opts: { target: Target; key: TBindingKey }): boolean {\n const { target, key } = opts;\n\n return Reflect.hasMetadata(key, target);\n }\n\n delete<Target extends object = object>(opts: { target: Target; key: TBindingKey }): boolean {\n const { target, key } = opts;\n\n return Reflect.deleteMetadata(key, target);\n }\n\n getKeys<Target extends object = object>(opts: { target: Target }): TBindingKey[] {\n const { target } = opts;\n\n return (\n Reflect.getMetadataKeys(target)?.filter((key) => {\n return typeof key === 'symbol' || typeof key === 'string';\n }) ?? []\n );\n }\n\n getMethodNames<T = any>(opts: { target: TClass<T> }): string[] {\n const { target } = opts;\n const prototype = target.prototype;\n const methods = Object.getOwnPropertyNames(prototype).filter(\n (name) => name !== 'constructor' && typeof prototype[name] === 'function',\n );\n\n return methods;\n }\n\n clearMetadata<T extends object = object>(opts: { target: T }): void {\n const { target } = opts;\n const keys = Reflect.getMetadataKeys(target);\n\n for (const key of keys) {\n Reflect.deleteMetadata(key, target);\n }\n }\n\n setPropertyMetadata<T extends object = object>(opts: {\n target: T;\n propertyName: string | symbol;\n metadata: IPropertyMetadata;\n }): void {\n const { target, propertyName, metadata } = opts;\n\n // Copy-on-write, as for constructor injection: the inherited map belongs to the parent class and\n // every sibling subclass reads it.\n const own: Map<string | symbol, IPropertyMetadata> | undefined = Reflect.getOwnMetadata(\n MetadataKeys.PROPERTIES,\n target.constructor,\n );\n const properties = own ?? new Map(this.getPropertiesMetadata({ target }));\n\n properties.set(propertyName, metadata);\n Reflect.defineMetadata(MetadataKeys.PROPERTIES, properties, target.constructor);\n }\n\n getPropertiesMetadata<T extends object = object>(opts: {\n target: T;\n }): Map<string | symbol, IPropertyMetadata> | undefined {\n const { target } = opts;\n\n return Reflect.getMetadata(MetadataKeys.PROPERTIES, target.constructor);\n }\n\n getPropertyMetadata<T extends object = object>(opts: {\n target: T;\n propertyName: string | symbol;\n }): IPropertyMetadata | undefined {\n const { target, propertyName } = opts;\n const properties = this.getPropertiesMetadata({ target });\n\n return properties?.get(propertyName);\n }\n\n setInjectMetadata<T extends object = object>(opts: {\n target: T;\n index: number;\n metadata: IInjectMetadata;\n }): void {\n const { target, index, metadata } = opts;\n // Copy-on-write: the inherited list belongs to the parent class and every sibling subclass reads it.\n const own: IInjectMetadata[] | undefined = Reflect.getOwnMetadata(MetadataKeys.INJECT, target);\n const injects = own ?? [...(Reflect.getMetadata(MetadataKeys.INJECT, target) ?? [])];\n injects[index] = metadata;\n Reflect.defineMetadata(MetadataKeys.INJECT, injects, target);\n }\n\n getInjectMetadata<T extends object = object>(opts: { target: T }): IInjectMetadata[] | undefined {\n const { target } = opts;\n\n return Reflect.getMetadata(MetadataKeys.INJECT, target);\n }\n\n /** `isProvisional` marks a DERIVED key; a registration replaces it silently, having seen the call-site override. */\n setBindingKey<T extends object = object>(opts: {\n target: T;\n key: TBindingKey;\n isProvisional?: boolean;\n }): void {\n const { target, key, isProvisional = false } = opts;\n const current: IBindingKeyRecord | undefined = Reflect.getOwnMetadata(\n MetadataKeys.BINDING_KEY,\n target,\n );\n\n // Two apps in one process, one class, two keys: the last registration would decide for both.\n if (current !== undefined && current.key !== key && !current.isProvisional && !isProvisional) {\n Logger.warn(\n '[setBindingKey] Rebound under a different key | target: %s | was: %s | now: %s',\n (target as { name?: string }).name,\n current.key.toString(),\n key.toString(),\n );\n }\n\n Reflect.defineMetadata(MetadataKeys.BINDING_KEY, { key, isProvisional }, target);\n }\n\n /** Own metadata only: a subclass is not registered, and the parent key would resolve the wrong binding. */\n getBindingKey<T extends object = object>(opts: { target: T }): TBindingKey | undefined {\n const { target } = opts;\n const record: IBindingKeyRecord | undefined = Reflect.getOwnMetadata(\n MetadataKeys.BINDING_KEY,\n target,\n );\n\n return record?.key;\n }\n}\n\n/** The shared `MetadataRegistry` instance. */\nexport const metadataRegistry = new MetadataRegistry();\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@venizia/ignis-inversion",
|
|
3
|
-
"version": "0.4.7-
|
|
3
|
+
"version": "0.4.7-2",
|
|
4
4
|
"description": "A small, standalone Dependency Injection and Inversion of Control container for TypeScript. Features decorator-based constructor and property injection, fluent Binding API, singleton/transient scoping, namespace auto-tagging, Provider pattern, tag-based discovery, and reflect-metadata integration. Zero framework lock-in — works standalone or with Ignis.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"architecture",
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
},
|
|
89
89
|
"devDependencies": {
|
|
90
90
|
"@types/bun": "^1.4.3",
|
|
91
|
-
"@venizia/dev-configs": "0.4.8-
|
|
91
|
+
"@venizia/dev-configs": "0.4.8-2",
|
|
92
92
|
"eslint": "^10.13.0",
|
|
93
93
|
"oxlint": "1.89.0",
|
|
94
94
|
"oxlint-tsgolint": "7.0.2004",
|