@venizia/ignis-inversion 0.4.6 → 0.4.7-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/dist/esm/common/base-helper.d.ts +2 -0
  2. package/dist/esm/common/base-helper.js +1 -0
  3. package/dist/esm/common/base-helper.js.map +1 -1
  4. package/dist/esm/common/logger.d.ts +1 -0
  5. package/dist/esm/common/logger.js +1 -0
  6. package/dist/esm/common/logger.js.map +1 -1
  7. package/dist/esm/common/types.d.ts +13 -0
  8. package/dist/esm/common/types.js.map +1 -1
  9. package/dist/esm/common/utilities.js.map +1 -1
  10. package/dist/esm/modules/binding/binding.d.ts +1 -0
  11. package/dist/esm/modules/binding/binding.js +1 -0
  12. package/dist/esm/modules/binding/binding.js.map +1 -1
  13. package/dist/esm/modules/binding/common/constants.d.ts +5 -0
  14. package/dist/esm/modules/binding/common/constants.js +3 -0
  15. package/dist/esm/modules/binding/common/constants.js.map +1 -1
  16. package/dist/esm/modules/binding/common/types.d.ts +4 -0
  17. package/dist/esm/modules/binding/common/types.js +1 -0
  18. package/dist/esm/modules/binding/common/types.js.map +1 -1
  19. package/dist/esm/modules/container/base.d.ts +6 -1
  20. package/dist/esm/modules/container/base.js +6 -1
  21. package/dist/esm/modules/container/base.js.map +1 -1
  22. package/dist/esm/modules/container/common/types.d.ts +1 -0
  23. package/dist/esm/modules/container/common/types.js.map +1 -1
  24. package/dist/esm/modules/container/container.js.map +1 -1
  25. package/dist/esm/modules/container/verifier.d.ts +3 -0
  26. package/dist/esm/modules/container/verifier.js.map +1 -1
  27. package/dist/esm/modules/error/app-error.d.ts +4 -0
  28. package/dist/esm/modules/error/app-error.js +3 -0
  29. package/dist/esm/modules/error/app-error.js.map +1 -1
  30. package/dist/esm/modules/error/common/types.d.ts +4 -0
  31. package/dist/esm/modules/error/common/types.js.map +1 -1
  32. package/dist/esm/modules/error/definition.d.ts +2 -0
  33. package/dist/esm/modules/error/definition.js +1 -0
  34. package/dist/esm/modules/error/definition.js.map +1 -1
  35. package/dist/esm/modules/error/message-code.d.ts +1 -0
  36. package/dist/esm/modules/error/message-code.js +1 -0
  37. package/dist/esm/modules/error/message-code.js.map +1 -1
  38. package/dist/esm/modules/error/message-template.js.map +1 -1
  39. package/dist/esm/modules/metadata/common/constants.d.ts +1 -0
  40. package/dist/esm/modules/metadata/common/constants.js +1 -0
  41. package/dist/esm/modules/metadata/common/constants.js.map +1 -1
  42. package/dist/esm/modules/metadata/injectors.js.map +1 -1
  43. package/dist/esm/modules/registry/common/types.d.ts +2 -0
  44. package/dist/esm/modules/registry/common/types.js.map +1 -1
  45. package/dist/esm/modules/registry/registry.d.ts +1 -0
  46. package/dist/esm/modules/registry/registry.js +1 -0
  47. package/dist/esm/modules/registry/registry.js.map +1 -1
  48. package/package.json +3 -3
  49. package/dist/esm/common/base-helper.d.ts.map +0 -1
  50. package/dist/esm/common/index.d.ts.map +0 -1
  51. package/dist/esm/common/logger.d.ts.map +0 -1
  52. package/dist/esm/common/types.d.ts.map +0 -1
  53. package/dist/esm/common/utilities.d.ts.map +0 -1
  54. package/dist/esm/index.d.ts.map +0 -1
  55. package/dist/esm/modules/binding/binding.d.ts.map +0 -1
  56. package/dist/esm/modules/binding/common/constants.d.ts.map +0 -1
  57. package/dist/esm/modules/binding/common/index.d.ts.map +0 -1
  58. package/dist/esm/modules/binding/common/types.d.ts.map +0 -1
  59. package/dist/esm/modules/binding/index.d.ts.map +0 -1
  60. package/dist/esm/modules/container/abstract.d.ts.map +0 -1
  61. package/dist/esm/modules/container/base.d.ts.map +0 -1
  62. package/dist/esm/modules/container/common/index.d.ts.map +0 -1
  63. package/dist/esm/modules/container/common/types.d.ts.map +0 -1
  64. package/dist/esm/modules/container/container.d.ts.map +0 -1
  65. package/dist/esm/modules/container/index.d.ts.map +0 -1
  66. package/dist/esm/modules/container/verifier.d.ts.map +0 -1
  67. package/dist/esm/modules/error/app-error.d.ts.map +0 -1
  68. package/dist/esm/modules/error/common/constants.d.ts.map +0 -1
  69. package/dist/esm/modules/error/common/index.d.ts.map +0 -1
  70. package/dist/esm/modules/error/common/types.d.ts.map +0 -1
  71. package/dist/esm/modules/error/definition.d.ts.map +0 -1
  72. package/dist/esm/modules/error/index.d.ts.map +0 -1
  73. package/dist/esm/modules/error/message-code.d.ts.map +0 -1
  74. package/dist/esm/modules/error/message-template.d.ts.map +0 -1
  75. package/dist/esm/modules/index.d.ts.map +0 -1
  76. package/dist/esm/modules/metadata/common/constants.d.ts.map +0 -1
  77. package/dist/esm/modules/metadata/common/index.d.ts.map +0 -1
  78. package/dist/esm/modules/metadata/index.d.ts.map +0 -1
  79. package/dist/esm/modules/metadata/injectors.d.ts.map +0 -1
  80. package/dist/esm/modules/registry/common/index.d.ts.map +0 -1
  81. package/dist/esm/modules/registry/common/types.d.ts.map +0 -1
  82. package/dist/esm/modules/registry/index.d.ts.map +0 -1
  83. package/dist/esm/modules/registry/registry.d.ts.map +0 -1
@@ -1,5 +1,7 @@
1
+ /** Base for classes that carry a logging `scope` and an optional `identifier`. */
1
2
  export declare class BaseHelper {
2
3
  scope: string;
4
+ /** @default '' */
3
5
  identifier: string;
4
6
  constructor(opts: {
5
7
  scope: string;
@@ -1,3 +1,4 @@
1
+ /** Base for classes that carry a logging `scope` and an optional `identifier`. */
1
2
  export class BaseHelper {
2
3
  constructor(opts) {
3
4
  this.scope = opts.scope ?? '';
@@ -1 +1 @@
1
- {"version":3,"file":"base-helper.js","sourceRoot":"","sources":["../../../src/common/base-helper.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,UAAU;IAIrB,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":["export class BaseHelper {\n scope: string;\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
+ {"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":["export 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
+ {"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":["export type TNullable<T> = T | undefined | null;\n\nexport type ValueOrPromise<T> = T | Promise<T>;\nexport type ValueOf<T> = T[keyof T];\n\nexport type AnyType = any;\n\nexport type TConstructor<T> = new (...args: any[]) => T;\nexport type TAbstractConstructor<T> = abstract new (...args: any[]) => T;\nexport type TClass<T> = TConstructor<T> & { [property: string]: any };\n\nexport type TResolver<T> = (...args: any[]) => T;\nexport type TAsyncResolver<T> = (...args: any[]) => T | Promise<T>;\nexport type TValueOrResolver<T> = T | TResolver<T>;\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\nexport type TBindingKey = string | symbol;\n\nexport interface IBindingTag {\n [name: string]: any;\n}\n"]}
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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"utilities.js","sourceRoot":"","sources":["../../../src/common/utilities.ts"],"names":[],"mappings":"AAUA;;;GAGG;AACH,MAAM,OAAO,aAAa;IACxB;;;;;;;OAOG;IACH,MAAM,CAAC,OAAO,CAAC,IAAwB;QACrC,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;QAEvB,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YAC1C,OAAO,IAAI,CAAC;QACd,CAAC;QAED,wFAAwF;QACxF,8DAA8D;QAC9D,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;YACnF,OAAQ,KAA4B,CAAC,MAAM,KAAK,CAAC,CAAC;QACpD,CAAC;QAED,IAAI,KAAK,YAAY,GAAG,IAAI,KAAK,YAAY,GAAG,EAAE,CAAC;YACjD,OAAO,KAAK,CAAC,IAAI,KAAK,CAAC,CAAC;QA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CAAC,CAAC;IAC5E,CAAC;IAEO,MAAM,CAAC,eAAe,CAC5B,eAAyC;QAEzC,OAAO,OAAO,eAAe,KAAK,UAAU,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;IAC5E,CAAC;IAED,yGAAyG;IACzG,MAAM,CAAC,YAAY,CAAI,IAAoC;QACzD,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;QACvB,OAAO,eAAe,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;IAC7D,CAAC;IAED,+DAA+D;IAC/D,MAAM,CAAC,KAAK,CAAC,iBAAiB,CAAI,IAAyC;QACzE,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;QACvB,OAAO,eAAe,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;IAClE,CAAC;IAED,iUAAiU;IACjU,MAAM,CAAC,mBAAmB,CAAC,IAA+B;QACxD,MAAM,QAAQ,GAAG,eAAe,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;QACtE,OAAO,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;IAClD,CAAC;CACF","sourcesContent":["import type {\n AnyType,\n TAsyncResolver,\n TClass,\n TInjectTarget,\n TResolver,\n TValueOrAsyncResolver,\n TValueOrResolver,\n} from './types';\n\n/**\n * Object helpers. Hand-written rather than `lodash/isEmpty` and `lodash/omit`: this package is bundled\n * for browsers, where importing lodash for two functions costs 24 KB.\n */\nexport class ObjectUtility {\n /**\n * True for a value carrying nothing: `null`/`undefined`, an empty string, array, `Map`, `Set`, or an\n * object with no own enumerable keys. A number, boolean or function is empty too - it holds no\n * entries.\n *\n * NOT a plain `!value`: `!{}` is `false` while an empty object IS empty, so the two disagree on\n * exactly the case a swap would silently flip.\n */\n static isEmpty(opts: { value: unknown }): boolean {\n const { value } = opts;\n\n if (value === null || value === undefined) {\n return true;\n }\n\n // The types that carry a MEANINGFUL length. Duck-typing on `.length` instead would call\n // `{ length: 0 }` empty, which it is not - it has an own key.\n if (typeof value === 'string' || Array.isArray(value) || ArrayBuffer.isView(value)) {\n return (value as { length: number }).length === 0;\n }\n\n if (value instanceof Map || value instanceof Set) {\n return value.size === 0;\n }\n\n if (typeof value !== 'object') {\n return true;\n }\n\n // Own keys only: `for...in` would walk the prototype chain and call an object with an inherited\n // property non-empty.\n return Object.keys(value).length === 0;\n }\n\n /**\n * A shallow copy without `keys`. Matches lodash on the shapes we pass it - a flat key list, never a\n * nested path.\n */\n static omit<T extends object, K extends PropertyKey>(opts: {\n source: T;\n keys: readonly K[];\n }): Omit<T, Extract<K, keyof T>> {\n const { source, keys } = opts;\n const dropped = new Set<PropertyKey>(keys);\n const kept: Record<string, unknown> = {};\n\n const entries = Object.entries(source);\n for (const [key, value] of entries) {\n if (dropped.has(key)) {\n continue;\n }\n\n kept[key] = value;\n }\n\n return kept as Omit<T, Extract<K, keyof T>>;\n }\n}\n\n/** Tells a CONSTRUCTOR from a RESOLVER via source text - `prototype !== undefined` is true of every non-arrow function. Sound only on ES2020+ output (classes emit as `class`); ES5 bundling breaks it. */\nexport const isClass = <T>(target: any): target is TClass<T> => {\n if (typeof target !== 'function' || target.prototype === undefined) {\n return false;\n }\n\n return /^class[\\s{]/.test(Function.prototype.toString.call(target));\n};\n\n/** Readers for the value-or-resolver vocabulary the container branches on. */\nexport class ResolverUtility {\n /** A resolver is anything callable that is not a class - a class is a value here, never a factory. */\n private static isResolver<T>(\n valueOrResolver: TValueOrResolver<T>,\n ): valueOrResolver is TResolver<T> {\n return typeof valueOrResolver === 'function' && !isClass(valueOrResolver);\n }\n\n private static isAsyncResolver<T>(\n valueOrResolver: TValueOrAsyncResolver<T>,\n ): valueOrResolver is TAsyncResolver<T> {\n return typeof valueOrResolver === 'function' && !isClass(valueOrResolver);\n }\n\n /** Reads a value-or-resolver. A class constructor is returned as-is; only a plain function is called. */\n static resolveValue<T>(opts: { value: TValueOrResolver<T> }): T {\n const { value } = opts;\n return ResolverUtility.isResolver(value) ? value() : value;\n }\n\n /** `resolveValue` for a resolver that may answer a promise. */\n static async resolveValueAsync<T>(opts: { value: TValueOrAsyncResolver<T> }): Promise<T> {\n const { value } = opts;\n return ResolverUtility.isAsyncResolver(value) ? value() : value;\n }\n\n /** Reads what `@inject({ target })` named. The function form is called HERE, never at decoration: that is what lets a class reached through an import cycle be named at all. Answers `undefined` when the function hands back something that is not a class. The container resolves synchronously, so there is no async form. */\n static resolveInjectTarget(opts: { target: TInjectTarget }): TClass<AnyType> | undefined {\n const resolved = ResolverUtility.resolveValue({ value: opts.target });\n return isClass(resolved) ? resolved : undefined;\n }\n}\n"]}
1
+ {"version":3,"file":"utilities.js","sourceRoot":"","sources":["../../../src/common/utilities.ts"],"names":[],"mappings":"AAUA;;;GAGG;AACH,MAAM,OAAO,aAAa;IACxB;;;;;;;OAOG;IACH,MAAM,CAAC,OAAO,CAAC,IAAwB;QACrC,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;QAEvB,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YAC1C,OAAO,IAAI,CAAC;QACd,CAAC;QAED,wFAAwF;QACxF,8DAA8D;QAC9D,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;YACnF,OAAQ,KAA4B,CAAC,MAAM,KAAK,CAAC,CAAC;QACpD,CAAC;QAED,IAAI,KAAK,YAAY,GAAG,IAAI,KAAK,YAAY,GAAG,EAAE,CAAC;YACjD,OAAO,KAAK,CAAC,IAAI,KAAK,CAAC,CAAC;QAC1B,CAAC;QAED,IAAI,O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AC;IAEO,MAAM,CAAC,eAAe,CAC5B,eAAyC;QAEzC,OAAO,OAAO,eAAe,KAAK,UAAU,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;IAC5E,CAAC;IAED,yGAAyG;IACzG,MAAM,CAAC,YAAY,CAAI,IAAoC;QACzD,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;QAEvB,OAAO,eAAe,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;IAC7D,CAAC;IAED,+DAA+D;IAC/D,MAAM,CAAC,KAAK,CAAC,iBAAiB,CAAI,IAAyC;QACzE,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;QAEvB,OAAO,eAAe,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;IAClE,CAAC;IAED,iUAAiU;IACjU,MAAM,CAAC,mBAAmB,CAAC,IAA+B;QACxD,MAAM,QAAQ,GAAG,eAAe,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;QAEtE,OAAO,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;IAClD,CAAC;CACF","sourcesContent":["import type {\n AnyType,\n TAsyncResolver,\n TClass,\n TInjectTarget,\n TResolver,\n TValueOrAsyncResolver,\n TValueOrResolver,\n} from './types';\n\n/**\n * Object helpers. Hand-written rather than `lodash/isEmpty` and `lodash/omit`: this package is bundled\n * for browsers, where importing lodash for two functions costs 24 KB.\n */\nexport class ObjectUtility {\n /**\n * True for a value carrying nothing: `null`/`undefined`, an empty string, array, `Map`, `Set`, or an\n * object with no own enumerable keys. A number, boolean or function is empty too - it holds no\n * entries.\n *\n * NOT a plain `!value`: `!{}` is `false` while an empty object IS empty, so the two disagree on\n * exactly the case a swap would silently flip.\n */\n static isEmpty(opts: { value: unknown }): boolean {\n const { value } = opts;\n\n if (value === null || value === undefined) {\n return true;\n }\n\n // The types that carry a MEANINGFUL length. Duck-typing on `.length` instead would call\n // `{ length: 0 }` empty, which it is not - it has an own key.\n if (typeof value === 'string' || Array.isArray(value) || ArrayBuffer.isView(value)) {\n return (value as { length: number }).length === 0;\n }\n\n if (value instanceof Map || value instanceof Set) {\n return value.size === 0;\n }\n\n if (typeof value !== 'object') {\n return true;\n }\n\n // Own keys only: `for...in` would walk the prototype chain and call an object with an inherited\n // property non-empty.\n return Object.keys(value).length === 0;\n }\n\n /**\n * A shallow copy without `keys`. Matches lodash on the shapes we pass it - a flat key list, never a\n * nested path.\n */\n static omit<T extends object, K extends PropertyKey>(opts: {\n source: T;\n keys: readonly K[];\n }): Omit<T, Extract<K, keyof T>> {\n const { source, keys } = opts;\n const dropped = new Set<PropertyKey>(keys);\n const kept: Record<string, unknown> = {};\n\n const entries = Object.entries(source);\n\n for (const [key, value] of entries) {\n if (dropped.has(key)) {\n continue;\n }\n\n kept[key] = value;\n }\n\n return kept as Omit<T, Extract<K, keyof T>>;\n }\n}\n\n/** Tells a CONSTRUCTOR from a RESOLVER via source text - `prototype !== undefined` is true of every non-arrow function. Sound only on ES2020+ output (classes emit as `class`); ES5 bundling breaks it. */\nexport const isClass = <T>(target: any): target is TClass<T> => {\n if (typeof target !== 'function' || target.prototype === undefined) {\n return false;\n }\n\n return /^class[\\s{]/.test(Function.prototype.toString.call(target));\n};\n\n/** Readers for the value-or-resolver vocabulary the container branches on. */\nexport class ResolverUtility {\n /** A resolver is anything callable that is not a class - a class is a value here, never a factory. */\n private static isResolver<T>(\n valueOrResolver: TValueOrResolver<T>,\n ): valueOrResolver is TResolver<T> {\n return typeof valueOrResolver === 'function' && !isClass(valueOrResolver);\n }\n\n private static isAsyncResolver<T>(\n valueOrResolver: TValueOrAsyncResolver<T>,\n ): valueOrResolver is TAsyncResolver<T> {\n return typeof valueOrResolver === 'function' && !isClass(valueOrResolver);\n }\n\n /** Reads a value-or-resolver. A class constructor is returned as-is; only a plain function is called. */\n static resolveValue<T>(opts: { value: TValueOrResolver<T> }): T {\n const { value } = opts;\n\n return ResolverUtility.isResolver(value) ? value() : value;\n }\n\n /** `resolveValue` for a resolver that may answer a promise. */\n static async resolveValueAsync<T>(opts: { value: TValueOrAsyncResolver<T> }): Promise<T> {\n const { value } = opts;\n\n return ResolverUtility.isAsyncResolver(value) ? value() : value;\n }\n\n /** Reads what `@inject({ target })` named. The function form is called HERE, never at decoration: that is what lets a class reached through an import cycle be named at all. Answers `undefined` when the function hands back something that is not a class. The container resolves synchronously, so there is no async form. */\n static resolveInjectTarget(opts: { target: TInjectTarget }): TClass<AnyType> | undefined {\n const resolved = ResolverUtility.resolveValue({ value: opts.target });\n\n return isClass(resolved) ? resolved : undefined;\n }\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.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,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\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 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 return this;\n }\n\n toValue(value: T): this {\n this.resolver = { type: BindingValueTypes.VALUE, value };\n return this;\n }\n\n toProvider(value: TBindingProvider<T>): this {\n this.resolver = { type: BindingValueTypes.PROVIDER, value };\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 return this;\n }\n\n setTags(...tags: string[]): this {\n tags.forEach((t) => this.tags.add(t));\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 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,EAA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cesContent":["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;;AAI1C,MAAM,OAAO,iBAAiB;aACZ,UAAK,GAAG,OAAO,CAAC;aAChB,UAAK,GAAG,OAAO,CAAC;aAChB,aAAQ,GAAG,UAAU,CAAC;;AAIxC,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;QACnC,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;QACnB,OAAO,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC;CACF","sourcesContent":["import { getError } from '../../error';\nimport { type TConstValue } from '@/common/types';\n\nexport class BindingScopes {\n static readonly SINGLETON = 'singleton';\n static readonly TRANSIENT = 'transient';\n}\nexport type TBindingScope = TConstValue<typeof BindingScopes>;\n\nexport class BindingValueTypes {\n static readonly CLASS = 'class';\n static readonly VALUE = 'value';\n static readonly PROVIDER = 'provider';\n}\nexport type TBindingValueType = TConstValue<typeof BindingValueTypes>;\n\nexport class BindingKeys {\n static build(opts: { namespace: string; key: string }) {\n const { namespace, key } = opts;\n const keyParts: Array<string> = [];\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 return keyParts.join('.');\n }\n}\n"]}
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":"AAQA,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\nexport interface IProvider<T> {\n value(container: IContainer): T;\n}\n\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\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\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"]}
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
- /** 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. */
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
- /** 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. */
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,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE/C,wGAAwG;AACxG,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAE7B,kKAAkK;AAClK,MAAM,OAAgB,aAAc,SAAQ,iBAAiB;IA0B3D,YAAY,IAAwB;QAClC,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,IAAI,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC;QA1B5C,aAAQ,GAAG,IAAI,GAAG,EAAmB,CAAC;QAEhD,2EAA2E;QACjE,qBAAgB,GAAG,IAAI,GAAG,EAAkB,CAAC;QAEvD,mJAAmJ;QACzI,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,CAAC;QACpB,kBAAa,GAAG,IAAI,GAAG,EAAU,CAAC;IAI5C,CAAC;IAEQ,mBAAmB;QAC1B,OAAO,gBAAgB,CAAC;IAC1B,CAAC;IAED;;;OAGG;IACO,WAAW,CAAC,IAErB;QACC,MAAM,EAAE,GAA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I,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 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 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 return binding;\n }\n\n override isBound(opts: { key: TBindingKey }): boolean {\n const keyStr = this.toKeyString({ key: opts.key });\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 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 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 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 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 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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,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 /**\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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"container.js","sourceRoot":"","sources":["../../../../src/modules/container/container.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAEvC,qGAAqG;AACrG,MAAM,OAAO,SAAU,SAAQ,aAAa;IAC1C,YAAY,IAAwB;QAClC,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,IAAI,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC;IAClD,CAAC;IAED;;;;;;OAMG;IACO,iBAAiB,CAAC,IAM3B;QACC,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,U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E,GAAG,EAAE,UAAU,EAAE,CAAC,CAAC;QACnF,CAAC;QAED,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;QAElC,MAAM,gBAAgB,GAAG,QAAQ,CAAC,qBAAqB,CAAC;YACtD,MAAM,EAAE,QAAkB;SAC3B,CAAC,CAAC;QAEH,IAAI,CAAC,gBAAgB,EAAE,IAAI,EAAE,CAAC;YAC5B,OAAO,QAAQ,CAAC;QAClB,CAAC;QAED,MAAM,UAAU,GAAG,gBAAgB,CAAC,OAAO,EAAE,CAAC;QAC9C,KAAK,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,IAAI,UAAU,EAAE,CAAC;YACjD,MAAM,UAAU,GAAG,QAAQ,CAAC,UAAU,IAAI,KAAK,CAAC;YAChD,MAAM,GAAG,GAAG,IAAI,CAAC,iBAAiB,CAAC;gBACjC,GAAG,EAAE,QAAQ,CAAC,UAAU;gBACxB,MAAM,EAAE,QAAQ,CAAC,MAAM;gBACvB,UAAU;gBACV,GAAG;gBACH,EAAE,EAAE,aAAa,MAAM,CAAC,WAAW,CAAC,GAAG;aACxC,CAAC,CAAC;YAEF,QAAgB,CAAC,WAAW,CAAC;gBAC5B,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC,CAAC;QAClE,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF","sourcesContent":["import { getError } from '../error';\nimport { type AnyType, type TBindingKey, type TClass, type TInjectTarget } from '@/common/types';\nimport { ResolverUtility } from '@/common/utilities';\nimport { BaseContainer } from './base';\n\n/** Default container: constructor + property injection driven by the decorator metadata registry. */\nexport class Container extends BaseContainer {\n constructor(opts?: { scope: string }) {\n super({ scope: opts?.scope ?? Container.name });\n }\n\n /**\n * The class form reads the key the REGISTRATION recorded, so a call-site override and an imperative\n * `application.service(X)` both resolve. `@inject` takes a key or a class; metadata a framework\n * writes may carry both, and then the class wins and the key is the fallback for a class nothing\n * recorded - one bound by hand with `bind({ key }).toClass(X)`. An optional class with neither\n * resolves to `undefined`, as an optional key would.\n */\n protected resolveBindingKey(opts: {\n key?: TBindingKey;\n target?: TInjectTarget;\n isOptional?: boolean;\n cls: TClass<AnyType>;\n at: string;\n }): TBindingKey | undefined {\n const { key, target: declared, isOptional = false, cls, at } = opts;\n\n if (declared === undefined && key !== undefined) {\n return key;\n }\n\n if (declared === undefined) {\n throw getError({\n message: `[${cls.name}] ${at} has neither an @inject key nor a class`,\n });\n }\n\n const target = ResolverUtility.resolveInjectTarget({ target: declared });\n if (target === undefined) {\n throw getError({\n message: `[${cls.name}] ${at} names a function that did not return a class`,\n });\n }\n\n const recorded = this.getMetadataRegistry().getBindingKey({ target }) ?? key;\n if (recorded === undefined && isOptional) {\n return undefined;\n }\n\n if (recorded === undefined) {\n throw getError({\n message: `[${cls.name}] ${at} names '${target.name}', which is not registered as an artifact | Decorate it (@service, @repository, ...) or register it on the application before it is injected`,\n extra: { unregisteredClass: target.name },\n });\n }\n\n // A same-name class records the same derived key (a library's own copy of a class the application registers): resolving it would hand back the OTHER class without a word.\n const bound = this.getBinding({ key: recorded })?.boundClass();\n if (bound && bound !== target && !(bound.prototype instanceof target)) {\n throw getError({\n message: `[${cls.name}] ${at} names '${target.name}', but '${String(recorded)}' is bound to a different class named '${bound.name}' | Two classes share one name and so one key - rename one, re-export the registered one, or inject by key`,\n });\n }\n\n return recorded;\n }\n\n override instantiate<T>(cls: TClass<T>): T {\n const registry = this.getMetadataRegistry();\n\n const injectMetadata = registry.getInjectMetadata({\n target: cls,\n });\n\n const args: any[] = [];\n\n for (let index = 0; index < (injectMetadata?.length ?? 0); index++) {\n const meta = injectMetadata?.[index];\n\n if (!meta) {\n throw getError({\n message: `[${cls.name}] Constructor parameter ${index} has no @inject | Every parameter of a container-instantiated class must be decorated - the container cannot supply an undecorated one`,\n });\n }\n\n const isOptional = meta.isOptional ?? false;\n const key = this.resolveBindingKey({\n key: meta.key,\n target: meta.target,\n isOptional,\n cls,\n at: `Constructor parameter ${index}`,\n });\n\n args[meta.index] = key === undefined ? undefined : this.get({ key, isOptional });\n }\n\n const instance = new cls(...args);\n\n const propertyMetadata = registry.getPropertiesMetadata({\n target: instance as object,\n });\n\n if (!propertyMetadata?.size) {\n return instance;\n }\n\n const properties = propertyMetadata.entries();\n for (const [propertyKey, metadata] of properties) {\n const isOptional = metadata.isOptional ?? false;\n const key = this.resolveBindingKey({\n key: metadata.bindingKey,\n target: metadata.target,\n isOptional,\n cls,\n at: `Property '${String(propertyKey)}'`,\n });\n\n (instance as any)[propertyKey] =\n key === undefined ? undefined : this.get({ key, isOptional });\n }\n\n return instance;\n }\n}\n"]}
1
+ {"version":3,"file":"container.js","sourceRoot":"","sources":["../../../../src/modules/container/container.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAEvC,qGAAqG;AACrG,MAAM,OAAO,SAAU,SAAQ,aAAa;IAC1C,YAAY,IAAwB;QAClC,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,IAAI,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC;IAClD,CAAC;IAED;;;;;;OAMG;IACO,iBAAiB,CAAC,IAM3B;QACC,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,GAAG,KAAK,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,IAAI,CAAC;QAEpE,IAAI,QAAQ,KAAK,SAAS,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;YAChD,OAAO,GAAG,CAAC;QACb,CAAC;QAED,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;YAC3B,MAAM,QAAQ,CAAC;gBACb,O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AAE,IAAI,EAAE,CAAC;YAC5B,OAAO,QAAQ,CAAC;QAClB,CAAC;QAED,MAAM,UAAU,GAAG,gBAAgB,CAAC,OAAO,EAAE,CAAC;QAE9C,KAAK,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,IAAI,UAAU,EAAE,CAAC;YACjD,MAAM,UAAU,GAAG,QAAQ,CAAC,UAAU,IAAI,KAAK,CAAC;YAChD,MAAM,GAAG,GAAG,IAAI,CAAC,iBAAiB,CAAC;gBACjC,GAAG,EAAE,QAAQ,CAAC,UAAU;gBACxB,MAAM,EAAE,QAAQ,CAAC,MAAM;gBACvB,UAAU;gBACV,GAAG;gBACH,EAAE,EAAE,aAAa,MAAM,CAAC,WAAW,CAAC,GAAG;aACxC,CAAC,CAAC;YAEF,QAAgB,CAAC,WAAW,CAAC;gBAC5B,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC,CAAC;QAClE,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF","sourcesContent":["import { getError } from '../error';\nimport { type AnyType, type TBindingKey, type TClass, type TInjectTarget } from '@/common/types';\nimport { ResolverUtility } from '@/common/utilities';\nimport { BaseContainer } from './base';\n\n/** Default container: constructor + property injection driven by the decorator metadata registry. */\nexport class Container extends BaseContainer {\n constructor(opts?: { scope: string }) {\n super({ scope: opts?.scope ?? Container.name });\n }\n\n /**\n * The class form reads the key the REGISTRATION recorded, so a call-site override and an imperative\n * `application.service(X)` both resolve. `@inject` takes a key or a class; metadata a framework\n * writes may carry both, and then the class wins and the key is the fallback for a class nothing\n * recorded - one bound by hand with `bind({ key }).toClass(X)`. An optional class with neither\n * resolves to `undefined`, as an optional key would.\n */\n protected resolveBindingKey(opts: {\n key?: TBindingKey;\n target?: TInjectTarget;\n isOptional?: boolean;\n cls: TClass<AnyType>;\n at: string;\n }): TBindingKey | undefined {\n const { key, target: declared, isOptional = false, cls, at } = opts;\n\n if (declared === undefined && key !== undefined) {\n return key;\n }\n\n if (declared === undefined) {\n throw getError({\n message: `[${cls.name}] ${at} has neither an @inject key nor a class`,\n });\n }\n\n const target = ResolverUtility.resolveInjectTarget({ target: declared });\n\n if (target === undefined) {\n throw getError({\n message: `[${cls.name}] ${at} names a function that did not return a class`,\n });\n }\n\n const recorded = this.getMetadataRegistry().getBindingKey({ target }) ?? key;\n\n if (recorded === undefined && isOptional) {\n return undefined;\n }\n\n if (recorded === undefined) {\n throw getError({\n message: `[${cls.name}] ${at} names '${target.name}', which is not registered as an artifact | Decorate it (@service, @repository, ...) or register it on the application before it is injected`,\n extra: { unregisteredClass: target.name },\n });\n }\n\n // A same-name class records the same derived key (a library's own copy of a class the application registers): resolving it would hand back the OTHER class without a word.\n const bound = this.getBinding({ key: recorded })?.boundClass();\n\n if (bound && bound !== target && !(bound.prototype instanceof target)) {\n throw getError({\n message: `[${cls.name}] ${at} names '${target.name}', but '${String(recorded)}' is bound to a different class named '${bound.name}' | Two classes share one name and so one key - rename one, re-export the registered one, or inject by key`,\n });\n }\n\n return recorded;\n }\n\n override instantiate<T>(cls: TClass<T>): T {\n const registry = this.getMetadataRegistry();\n\n const injectMetadata = registry.getInjectMetadata({\n target: cls,\n });\n\n const args: any[] = [];\n\n for (let index = 0; index < (injectMetadata?.length ?? 0); index++) {\n const meta = injectMetadata?.[index];\n\n if (!meta) {\n throw getError({\n message: `[${cls.name}] Constructor parameter ${index} has no @inject | Every parameter of a container-instantiated class must be decorated - the container cannot supply an undecorated one`,\n });\n }\n\n const isOptional = meta.isOptional ?? false;\n const key = this.resolveBindingKey({\n key: meta.key,\n target: meta.target,\n isOptional,\n cls,\n at: `Constructor parameter ${index}`,\n });\n\n args[meta.index] = key === undefined ? undefined : this.get({ key, isOptional });\n }\n\n const instance = new cls(...args);\n\n const propertyMetadata = registry.getPropertiesMetadata({\n target: instance as object,\n });\n\n if (!propertyMetadata?.size) {\n return instance;\n }\n\n const properties = propertyMetadata.entries();\n\n for (const [propertyKey, metadata] of properties) {\n const isOptional = metadata.isOptional ?? false;\n const key = this.resolveBindingKey({\n key: metadata.bindingKey,\n target: metadata.target,\n isOptional,\n cls,\n at: `Property '${String(propertyKey)}'`,\n });\n\n (instance as any)[propertyKey] =\n key === undefined ? undefined : this.get({ key, isOptional });\n }\n\n return instance;\n }\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
  verified: string[];
@@ -1 +1 @@
1
- {"version":3,"file":"verifier.js","sourceRoot":"","sources":["../../../../src/modules/container/verifier.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AA8CpC,iFAAiF;AACjF,MAAM,OAAO,eAAe;IAClB,MAAM,CAAC,aAAa,CAAC,OAAiB;QAC5C,OAAO,YAAY,IAAI,OAAO,IAAI,OAAO,OAAO,CAAC,UAAU,KAAK,UAAU,CAAC;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BACL,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 if (typeof source !== 'object' || source === null || !(name in source)) {\n return undefined;\n }\n\n const value = Reflect.get(source, name);\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 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 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 for (const failure of result.failures) {\n const what = failure.missingKey ?? failure.unregisteredClass;\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 },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,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\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