@decaf-ts/injectable-decorators 1.16.0 → 1.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.cjs CHANGED
@@ -36,7 +36,7 @@ __exportStar(require("./utils.cjs"), exports);
36
36
  * @const VERSION
37
37
  * @memberOf module:injectable-decorators
38
38
  */
39
- exports.VERSION = "1.15.0";
39
+ exports.VERSION = "1.17.0";
40
40
  exports.PACKAGE_NAME = "@decaf-ts/injectable-decorators";
41
41
  decoration_1.Metadata.registerLibrary(exports.PACKAGE_NAME, exports.VERSION);
42
42
  //# sourceMappingURL=index.js.map
package/lib/esm/index.js CHANGED
@@ -19,7 +19,7 @@ export * from "./utils.js";
19
19
  * @const VERSION
20
20
  * @memberOf module:injectable-decorators
21
21
  */
22
- export const VERSION = "1.15.0";
22
+ export const VERSION = "1.17.0";
23
23
  export const PACKAGE_NAME = "@decaf-ts/injectable-decorators";
24
24
  Metadata.registerLibrary(PACKAGE_NAME, VERSION);
25
25
  //# sourceMappingURL=index.js.map
@@ -1,4 +1,4 @@
1
- import { Injectable, InjectablesRegistry } from "./registry.cjs";
1
+ import { Injectable, InjectablesRegistry } from "./registry.d.cts";
2
2
  /**
3
3
  * @description Central registry for managing injectable dependencies.
4
4
  * @summary Static class holding the access to the injectables functions. Provides methods for registering,
@@ -1,4 +1,4 @@
1
- import { Injectable, InjectablesRegistry } from "./registry.js";
1
+ import { Injectable, InjectablesRegistry } from "./registry.d.mts";
2
2
  /**
3
3
  * @description Central registry for managing injectable dependencies.
4
4
  * @summary Static class holding the access to the injectables functions. Provides methods for registering,
@@ -1,5 +1,5 @@
1
1
  import type { Constructor } from "@decaf-ts/decoration";
2
- import { InjectOptions } from "./decorators.cjs";
2
+ import { InjectOptions } from "./decorators.d.cts";
3
3
  declare module "@decaf-ts/decoration" {
4
4
  namespace Metadata {
5
5
  function injectables<T extends string | symbol | Constructor>(category?: T): (T extends undefined ? Constructor[] : Constructor) | undefined;
@@ -1,5 +1,5 @@
1
1
  import type { Constructor } from "@decaf-ts/decoration";
2
- import { InjectOptions } from "./decorators.js";
2
+ import { InjectOptions } from "./decorators.d.mts";
3
3
  declare module "@decaf-ts/decoration" {
4
4
  namespace Metadata {
5
5
  function injectables<T extends string | symbol | Constructor>(category?: T): (T extends undefined ? Constructor[] : Constructor) | undefined;
@@ -1,4 +1,4 @@
1
- import { InjectableConfig } from "./decorators.cjs";
1
+ import { InjectableConfig } from "./decorators.d.cts";
2
2
  /**
3
3
  * @description Constants used for reflection metadata keys in the dependency injection system.
4
4
  * @summary Injectables Reflection keys used to store and retrieve metadata about injectable classes and properties.
@@ -1,4 +1,4 @@
1
- import { InjectableConfig } from "./decorators.js";
1
+ import { InjectableConfig } from "./decorators.d.mts";
2
2
  /**
3
3
  * @description Constants used for reflection metadata keys in the dependency injection system.
4
4
  * @summary Injectables Reflection keys used to store and retrieve metadata about injectable classes and properties.
@@ -1,4 +1,4 @@
1
- import { InstanceCallback } from "./types.cjs";
1
+ import { InstanceCallback } from "./types.d.cts";
2
2
  import { Constructor } from "@decaf-ts/decoration";
3
3
  /**
4
4
  * @description Configuration options for the @injectable decorator.
@@ -1,4 +1,4 @@
1
- import { InstanceCallback } from "./types.js";
1
+ import { InstanceCallback } from "./types.d.mts";
2
2
  import { Constructor } from "@decaf-ts/decoration";
3
3
  /**
4
4
  * @description Configuration options for the @injectable decorator.
@@ -6,17 +6,17 @@
6
6
  *
7
7
  * @module injectable-decorators
8
8
  */
9
- export * from "./constants.cjs";
10
- export * from "./decorators.cjs";
11
- export * from "./Injectables.cjs";
12
- export * from "./registry.cjs";
13
- export * from "./types.cjs";
14
- export * from "./utils.cjs";
9
+ export * from "./constants.d.cts";
10
+ export * from "./decorators.d.cts";
11
+ export * from "./Injectables.d.cts";
12
+ export * from "./registry.d.cts";
13
+ export * from "./types.d.cts";
14
+ export * from "./utils.d.cts";
15
15
  /**
16
16
  * @description Current version of the injectable-decorators library.
17
17
  * @summary Defined on library build. Holds the library's current version string.
18
18
  * @const VERSION
19
19
  * @memberOf module:injectable-decorators
20
20
  */
21
- export declare const VERSION = "1.15.0";
21
+ export declare const VERSION = "1.17.0";
22
22
  export declare const PACKAGE_NAME = "@decaf-ts/injectable-decorators";
@@ -6,17 +6,17 @@
6
6
  *
7
7
  * @module injectable-decorators
8
8
  */
9
- export * from "./constants.js";
10
- export * from "./decorators.js";
11
- export * from "./Injectables.js";
12
- export * from "./registry.js";
13
- export * from "./types.js";
14
- export * from "./utils.js";
9
+ export * from "./constants.d.mts";
10
+ export * from "./decorators.d.mts";
11
+ export * from "./Injectables.d.mts";
12
+ export * from "./registry.d.mts";
13
+ export * from "./types.d.mts";
14
+ export * from "./utils.d.mts";
15
15
  /**
16
16
  * @description Current version of the injectable-decorators library.
17
17
  * @summary Defined on library build. Holds the library's current version string.
18
18
  * @const VERSION
19
19
  * @memberOf module:injectable-decorators
20
20
  */
21
- export declare const VERSION = "1.15.0";
21
+ export declare const VERSION = "1.17.0";
22
22
  export declare const PACKAGE_NAME = "@decaf-ts/injectable-decorators";
@@ -1,4 +1,4 @@
1
- import { InjectableOptions } from "./types.cjs";
1
+ import { InjectableOptions } from "./types.d.cts";
2
2
  /**
3
3
  * @description Type representing either a class constructor or an instance.
4
4
  * @summary Defines an Injectable type that can be either a class constructor or an instance of a class.
@@ -1,4 +1,4 @@
1
- import { InjectableOptions } from "./types.js";
1
+ import { InjectableOptions } from "./types.d.mts";
2
2
  /**
3
3
  * @description Type representing either a class constructor or an instance.
4
4
  * @summary Defines an Injectable type that can be either a class constructor or an instance of a class.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decaf-ts/injectable-decorators",
3
- "version": "1.16.0",
3
+ "version": "1.18.0",
4
4
  "description": "injectable decorators extension for decorator validation",
5
5
  "type": "module",
6
6
  "exports": {
@@ -1,108 +0,0 @@
1
- import { Injectable, InjectablesRegistry } from "./registry";
2
- /**
3
- * @description Central registry for managing injectable dependencies.
4
- * @summary Static class holding the access to the injectables functions. Provides methods for registering,
5
- * retrieving, and building injectable objects.
6
- * @template T Type of the injectable object
7
- *
8
- * @class Injectables
9
- *
10
- * @example
11
- * // Define an injectable class
12
- * @injectable()
13
- * class MyService {
14
- * doSomething() {
15
- * return 'Hello World';
16
- * }
17
- * }
18
- *
19
- * // Inject the service into another class
20
- * class MyComponent {
21
- * @inject()
22
- * private service!: MyService;
23
- *
24
- * useService() {
25
- * return this.service.doSomething();
26
- * }
27
- * }
28
- *
29
- * @mermaid
30
- * sequenceDiagram
31
- * participant Client
32
- * participant Injectables
33
- * participant Registry
34
- *
35
- * Client->>Injectables: register(MyService)
36
- * Injectables->>Registry: register(MyService)
37
- * Registry-->>Injectables: void
38
- *
39
- * Client->>Injectables: get("MyService")
40
- * Injectables->>Registry: get("MyService")
41
- * Registry-->>Injectables: MyService instance
42
- * Injectables-->>Client: MyService instance
43
- */
44
- export declare class Injectables {
45
- /**
46
- * @description Holds the active registry implementation used by the Injectables facade.
47
- * @summary Internal static reference that can be swapped via setRegistry to customize how injectables are stored and retrieved.
48
- * @type {InjectablesRegistry | undefined}
49
- */
50
- private static actingInjectablesRegistry?;
51
- private constructor();
52
- /**
53
- * @description Fetches an injectable instance by its registered name.
54
- * @summary Retrieves the named {@link Injectable} from the registry. If the injectable is a singleton,
55
- * returns the existing instance. Otherwise, creates a new instance.
56
- * @template T Type of the injectable object to retrieve
57
- * @param {string} name The registered name of the injectable to retrieve
58
- * @param {any[]} args Constructor arguments to pass when instantiating the injectable
59
- * @return {Injectable<T> | undefined} The injectable instance or undefined if not found
60
- */
61
- static get<T>(name: symbol | string | {
62
- new (...args: any[]): T;
63
- }, ...args: any[]): T | undefined;
64
- /**
65
- * @description Adds a class or object to the injectable registry.
66
- * @summary Registers an injectable constructor or instance with the registry, making it available for injection.
67
- * @template T Type of the injectable object to register
68
- * @param {Injectable<T>} constructor The class constructor or object instance to register
69
- * @param {any[]} args Additional arguments for registration (category, singleton flag, etc.)
70
- * @return {void}
71
- */
72
- static register<T>(constructor: Injectable<T>, ...args: any[]): void;
73
- /**
74
- * @description Creates a new instance of an injectable class.
75
- * @summary Instantiates an injectable class using its constructor and the provided arguments.
76
- * @template T Type of the object to build
77
- * @param {symbol} name symbol referencing the injectable
78
- * @param {any[]} args Constructor arguments to pass when instantiating the injectable
79
- * @return {T} The newly created instance
80
- */
81
- static build<T>(name: symbol, ...args: any[]): T;
82
- /**
83
- * @description Replaces the current registry implementation.
84
- * @summary Sets a new {@link InjectablesRegistry} implementation, allowing for custom registry behavior.
85
- * @param {InjectablesRegistry} operationsRegistry The new implementation of Registry to use
86
- * @return {void}
87
- */
88
- static setRegistry(operationsRegistry: InjectablesRegistry): void;
89
- /**
90
- * @description Provides access to the current registry instance.
91
- * @summary Returns the current {@link InjectablesRegistry} or creates a default one if none exists.
92
- * @return {InjectablesRegistry} The current registry instance
93
- */
94
- private static getRegistry;
95
- /**
96
- * @description Clears all registered injectables.
97
- * @summary Resets the registry to a clean state by creating a new empty registry instance.
98
- * @return {void}
99
- */
100
- static reset(): void;
101
- /**
102
- * @description Removes specific injectables from the registry based on a pattern.
103
- * @summary Selectively resets the registry by removing only the injectables whose names match the provided pattern.
104
- * @param {string | RegExp} match A string or regular expression pattern to match against injectable names
105
- * @return {void}
106
- */
107
- static selectiveReset(match: string | RegExp): void;
108
- }
@@ -1,8 +0,0 @@
1
- import type { Constructor } from "@decaf-ts/decoration";
2
- import { InjectOptions } from "./decorators";
3
- declare module "@decaf-ts/decoration" {
4
- namespace Metadata {
5
- function injectables<T extends string | symbol | Constructor>(category?: T): (T extends undefined ? Constructor[] : Constructor) | undefined;
6
- function injected<T, K extends keyof T>(model: T | Constructor<T>, prop?: K): (K extends keyof T ? InjectOptions : Record<K, InjectOptions>) | undefined;
7
- }
8
- }
@@ -1,29 +0,0 @@
1
- import { InjectableConfig } from "./decorators";
2
- /**
3
- * @description Constants used for reflection metadata keys in the dependency injection system.
4
- * @summary Injectables Reflection keys used to store and retrieve metadata about injectable classes and properties.
5
- * @property {string} REFLECT Reflection injectables base key prefix for all metadata keys
6
- * @property {string} INJECTABLE Reflection key suffix for marking a class as injectable
7
- * @property {string} INJECT Reflection key suffix for marking a property for injection
8
- * @const InjectablesKeys
9
- * @memberOf module:injectable-decorators
10
- */
11
- export declare const InjectablesKeys: {
12
- REFLECT: string;
13
- INJECTABLE: string;
14
- INJECT: string;
15
- };
16
- /**
17
- * @description Default configuration applied by the @injectable decorator when none is provided.
18
- * @summary Sets sensible defaults such as singleton lifecycle for newly registered injectables.
19
- * @const DefaultInjectablesConfig
20
- * @memberOf module:injectable-decorators
21
- */
22
- export declare const DefaultInjectablesConfig: InjectableConfig;
23
- /**
24
- * @description Reflection metadata key for accessing TypeScript type information.
25
- * @summary Holds the key for retrieving the design type from TypeScript's reflection metadata.
26
- * @const TypeKey
27
- * @memberOf module:injectable-decorators
28
- */
29
- export declare const TypeKey = "design:type";
@@ -1,157 +0,0 @@
1
- import { InstanceCallback } from "./types";
2
- import { Constructor } from "@decaf-ts/decoration";
3
- /**
4
- * @description Configuration options for the @injectable decorator.
5
- * @summary Controls lifecycle (singleton vs on-demand) and an optional instance transformation callback executed post-construction.
6
- * @template T The instance type affected by the callback when provided.
7
- * @property {boolean} singleton When true, a single instance is shared (singleton). When false, instances are created on demand.
8
- * @property {InstanceCallback<T>} [callback] Optional hook to transform the instance after it is constructed.
9
- * @typedef InjectableConfig
10
- * @memberOf module:injectable-decorators
11
- */
12
- export type InjectableConfig = {
13
- singleton: boolean;
14
- callback?: InstanceCallback<any>;
15
- };
16
- export declare function injectableBaseDecorator(category?: string | Constructor | Partial<InjectableConfig>, cfg?: Partial<InjectableConfig>): (original: any) => any;
17
- /**
18
- * @description Decorator that marks a class as available for dependency injection.
19
- * @summary Defines a class as an injectable that can be retrieved from the registry.
20
- * When applied to a class, replaces its constructor with one that returns an instance.
21
- *
22
- * @return {function(any): any} A decorator function that transforms the class into an injectable.
23
- *
24
- * @function injectable
25
- */
26
- export declare function injectable(): (original: any) => any;
27
- /**
28
- * @description Decorator that marks a class as available for dependency injection.
29
- * @summary Defines a class as an injectable that can be retrieved from the registry.
30
- * When applied to a class, replaces its constructor with one that returns an instance.
31
- *
32
- * @param {string | Constructor} category Defaults to the class category. Useful when minification occurs and names are changed,
33
- * or when you want to upcast the object to a different type.
34
- *
35
- * @return {function(any): any} A decorator function that transforms the class into an injectable.
36
- *
37
- * @function injectable
38
- */
39
- export declare function injectable(category: string | Constructor): (original: any) => any;
40
- /**
41
- * @description Decorator that marks a class as available for dependency injection.
42
- * @summary Defines a class as an injectable that can be retrieved from the registry.
43
- * When applied to a class, replaces its constructor with one that returns an instance.
44
- *
45
- * @param {Partial<InjectableConfig>} cfg=DefaultInjectableConfig Allows overriding the default singleton behavior and adding a callback function.
46
- *
47
- * @return {function(any): any} A decorator function that transforms the class into an injectable.
48
- *
49
- * @function injectable
50
- */
51
- export declare function injectable(cfg: Partial<InjectableConfig>): (original: any) => any;
52
- /**
53
- * @description Decorator that marks a class as available for dependency injection.
54
- * @summary Defines a class as an injectable that can be retrieved from the registry.
55
- * When applied to a class, replaces its constructor with one that returns an instance.
56
- *
57
- * @param category Defaults to the class category. Useful when minification occurs and names are changed,
58
- * or when you want to upcast the object to a different type.
59
- * @param {Partial<InjectableConfig>} cfg=DefaultInjectableConfig Allows overriding the default singleton behavior and adding a callback function.
60
- *
61
- * @return {function(any): any} A decorator function that transforms the class into an injectable.
62
- *
63
- * @function injectable
64
- */
65
- export declare function injectable(category: string | Constructor, cfg: Partial<InjectableConfig>): (original: any) => any;
66
- /**
67
- * @description Convenience decorator to register an injectable as a singleton.
68
- * @summary Wraps {@link injectable} forcing the singleton lifecycle so only one instance is created and reused.
69
- * @param {string|Constructor} [category] Optional explicit category/symbol source; defaults to the class.
70
- * @param {Omit<InjectableConfig, "singleton">} [cfg] Additional injectable configuration excluding the singleton flag.
71
- * @return {function(any): any} A class decorator that registers the target as a singleton injectable.
72
- * @function singleton
73
- * @category Class Decorators
74
- */
75
- export declare function singleton(category?: string | Constructor, cfg?: Omit<InjectableConfig, "singleton">): (original: any) => any;
76
- /**
77
- * @description Convenience decorator to register an injectable as on-demand (non-singleton).
78
- * @summary Wraps {@link injectable} forcing new instances to be created on every injection or retrieval.
79
- * @param {string|Constructor} [category] Optional explicit category/symbol source; defaults to the class.
80
- * @param {Omit<InjectableConfig, "singleton">} [cfg] Additional injectable configuration excluding the singleton flag.
81
- * @return {function(any): any} A class decorator that registers the target as a non-singleton injectable.
82
- * @function onDemand
83
- * @category Class Decorators
84
- */
85
- export declare function onDemand(category?: string | Constructor, cfg?: Omit<InjectableConfig, "singleton">): (original: any) => any;
86
- /**
87
- * @description Function type for transforming injectable instances before they're injected.
88
- * @summary Function which transforms a cached {@link injectable} instance before it's injected into a target object.
89
- *
90
- * @param {any} injectable The injectable instance to transform
91
- * @param {any} obj The object the injectable will be injected on
92
- * @return {any} The transformed injectable instance
93
- *
94
- * @typedef {Function} InstanceTransformer
95
- * @category Decorators
96
- * @memberOf module:injectable-decorators
97
- */
98
- export type InstanceTransformer = (injectable: any, obj: any) => any;
99
- /**
100
- * @description Options for the property-level @inject decorator.
101
- * @summary Allows specifying constructor arguments and an optional transformer to be applied to the resolved instance.
102
- * @property {any[]} [args] Optional constructor arguments to use when building the injectable instance.
103
- * @property {InstanceTransformer} [transformer] Optional function to transform the instance before assignment.
104
- * @typedef InjectOptions
105
- * @memberOf module:injectable-decorators
106
- */
107
- export type InjectOptions = {
108
- args?: any[];
109
- transformer?: InstanceTransformer;
110
- };
111
- export declare function injectBaseDecorator(category?: symbol | string | Constructor | Partial<InjectOptions>, cfg?: Partial<InjectOptions>): (target: any, propertyKey?: any) => void;
112
- /**
113
- * @description Property decorator that injects a dependency into a class property.
114
- * @summary Allows for the injection of an {@link injectable} decorated dependency into a class property.
115
- * The property must be typed for the requested dependency. Only concrete classes are supported; generics are not.
116
- *
117
- * @return {function(any, any): void} A property decorator function that sets up the dependency injection.
118
- *
119
- * @function inject
120
- */
121
- export declare function inject(): (target: any, propertyKey: any) => void;
122
- /**
123
- * @description Property decorator that injects a dependency into a class property.
124
- * @summary Allows for the injection of an {@link injectable} decorated dependency into a class property.
125
- * The property must be typed for the requested dependency. Only concrete classes are supported; generics are not.
126
- *
127
- * @param {string} category Defaults to the class name derived from the property type. Useful when minification occurs
128
- * and names are changed, or when you want to upcast the object to a different type.
129
- * @return {function(any, any): void} A property decorator function that sets up the dependency injection.
130
- *
131
- * @function inject
132
- */
133
- export declare function inject(category: string | Constructor): (target: any, propertyKey: any) => void;
134
- /**
135
- * @description Property decorator that injects a dependency into a class property.
136
- * @summary Allows for the injection of an {@link injectable} decorated dependency into a class property.
137
- * The property must be typed for the requested dependency. Only concrete classes are supported; generics are not.
138
- *
139
- * @param {Partial<InjectOptions>} [cfg={}] Optional function to transform the injectable instance before it's injected, or arguments to pass the constructor when injecting onDemand
140
- * @return {function(any, any): void} A property decorator function that sets up the dependency injection.
141
- *
142
- * @function inject
143
- */
144
- export declare function inject(cfg: Partial<InjectOptions>): (target: any, propertyKey: any) => void;
145
- /**
146
- * @description Property decorator that injects a dependency into a class property.
147
- * @summary Allows for the injection of an {@link injectable} decorated dependency into a class property.
148
- * The property must be typed for the requested dependency. Only concrete classes are supported; generics are not.
149
- *
150
- * @param {string} category Defaults to the class name derived from the property type. Useful when minification occurs
151
- * and names are changed, or when you want to upcast the object to a different type.
152
- * @param {Partial<InjectOptions>} cfg={} Optional function to transform the injectable instance before it's injected, or arguments to pass the constructor when injecting onDemand
153
- * @return {function(any, any): void} A property decorator function that sets up the dependency injection.
154
- *
155
- * @function inject
156
- */
157
- export declare function inject(category: string | Constructor, cfg: Partial<InjectOptions>): (target: any, propertyKey: any) => void;
@@ -1,22 +0,0 @@
1
- /**
2
- * @description A lightweight dependency injection library for TypeScript applications.
3
- * @summary Adds a simple Injectables implementation to create singleton instances of an object
4
- * and easily inject it into other objects. Provides decorators for marking classes as injectable
5
- * and for injecting dependencies into class properties.
6
- *
7
- * @module injectable-decorators
8
- */
9
- export * from "./constants";
10
- export * from "./decorators";
11
- export * from "./Injectables";
12
- export * from "./registry";
13
- export * from "./types";
14
- export * from "./utils";
15
- /**
16
- * @description Current version of the injectable-decorators library.
17
- * @summary Defined on library build. Holds the library's current version string.
18
- * @const VERSION
19
- * @memberOf module:injectable-decorators
20
- */
21
- export declare const VERSION = "1.15.0";
22
- export declare const PACKAGE_NAME = "@decaf-ts/injectable-decorators";
@@ -1 +0,0 @@
1
- export {};
@@ -1,115 +0,0 @@
1
- import { InjectableOptions } from "./types";
2
- /**
3
- * @description Type representing either a class constructor or an instance.
4
- * @summary Defines an Injectable type that can be either a class constructor or an instance of a class.
5
- * @template T The type of the injectable object
6
- * @typedef {function(any): T | T} Injectable
7
- * @memberOf module:injectable-decorators
8
- */
9
- export type Injectable<T> = {
10
- new (...args: any[]): T;
11
- } | T;
12
- /**
13
- * @description Contract for a registry that manages injectable objects.
14
- * @summary Interface for an injectable registry that provides methods for retrieving, registering, and building injectable objects.
15
- * @template T Type parameter used in the interface methods
16
- * @interface InjectablesRegistry
17
- * @memberOf module:injectable-decorators
18
- */
19
- export interface InjectablesRegistry {
20
- /**
21
- * @description Fetches an injectable instance by its registered name.
22
- * @summary Retrieves an {@link Injectable} from the registry by name, optionally passing constructor arguments.
23
- * @template T Type of the injectable object to retrieve
24
- * @param {symbol} name The registered name of the injectable to retrieve
25
- * @param {any[]} args Constructor arguments to pass when instantiating the injectable
26
- * @return {Injectable<T> | undefined} The injectable instance or undefined if not found
27
- * @memberOf module:injectable-decorators
28
- */
29
- get<T>(name: symbol | string | {
30
- new (...args: any[]): T;
31
- }, ...args: any[]): T | undefined;
32
- /**
33
- * @description Adds a class or object to the injectable registry.
34
- * @summary Registers an injectable constructor or instance with the registry, making it available for injection.
35
- * @template T Type of the injectable object to register
36
- * @param {Injectable<T>} constructor The class constructor or object instance to register
37
- * @param options
38
- * @param {any[]} args Additional arguments for registration (category, singleton flag, etc.)
39
- * @return {void}
40
- * @memberOf module:injectable-decorators
41
- */
42
- register<T>(constructor: Injectable<T>, category: symbol | undefined, options: InjectableOptions<T>, ...args: any[]): void;
43
- /**
44
- * @description Creates a new instance of an injectable class.
45
- * @summary Instantiates an injectable class using its constructor and the provided arguments.
46
- * @template T Type of the object to build
47
- * @param {symbol} name Object containing the name of the injectable to build
48
- * @param {any[]} args Constructor arguments to pass when instantiating the injectable
49
- * @return {T} The newly created instance
50
- * @memberOf module:injectable-decorators
51
- */
52
- build<T>(name: symbol, ...args: any[]): T;
53
- }
54
- /**
55
- * @description Default implementation of the InjectablesRegistry interface.
56
- * @summary Holds the various {@link Injectable}s in a cache and provides methods to register, retrieve, and build them.
57
- * @template T Type parameter used in the class methods
58
- *
59
- * @class InjectableRegistryImp
60
- * @implements InjectablesRegistry
61
- *
62
- * @memberOf module:injectable-decorators
63
- *
64
- * @example
65
- * // Create a new registry
66
- * const registry = new InjectableRegistryImp();
67
- *
68
- * // Register a class
69
- * class MyService {
70
- * doSomething() {
71
- * return 'Hello World';
72
- * }
73
- * }
74
- * registry.register(MyService, 'MyService', true);
75
- *
76
- * // Get the instance
77
- * const service = registry.get('MyService');
78
- * service.doSomething(); // 'Hello World'
79
- *
80
- * @mermaid
81
- * sequenceDiagram
82
- * participant Client
83
- * participant Registry
84
- *
85
- * Client->>Registry: register(MyService)
86
- * Registry->>Registry: Store in cache
87
- *
88
- * Client->>Registry: get("MyService")
89
- * alt Instance exists and is singleton
90
- * Registry-->>Client: Return cached instance
91
- * else No instance or not singleton
92
- * Registry->>Registry: build(name)
93
- * Registry-->>Client: Return new instance
94
- * end
95
- */
96
- export declare class InjectableRegistryImp implements InjectablesRegistry {
97
- private cache;
98
- has<T>(name: symbol | {
99
- new (...args: any[]): T;
100
- }): boolean;
101
- /**
102
- * @inheritDoc
103
- */
104
- get<T>(name: symbol | string | {
105
- new (...args: any[]): T;
106
- }, ...args: any[]): T | undefined;
107
- /**
108
- * @inheritDoc
109
- */
110
- register<T>(obj: Injectable<T>, category: symbol | undefined, options: InjectableOptions<T>, force?: boolean): void;
111
- /**
112
- * @inheritDoc
113
- */
114
- build<T>(name: symbol, ...args: any[]): T;
115
- }
@@ -1,53 +0,0 @@
1
- import { Constructor } from "@decaf-ts/decoration";
2
- /**
3
- * @description Callback function type used to transform or initialize an instance after construction.
4
- * @summary Represents a post-construction hook that can modify or replace the created instance before it is returned to the caller.
5
- * @template T The instance type being produced and possibly transformed.
6
- * @param {T} instance The newly constructed instance.
7
- * @param {...any} args Additional arguments forwarded from the construction context.
8
- * @return {T} The instance to be stored/returned, which may be the original or a transformed instance.
9
- * @typedef InstanceCallback
10
- * @memberOf module:injectable-decorators
11
- */
12
- export type InstanceCallback<T> = (instance: T, ...args: any[]) => T;
13
- /**
14
- * @description Options controlling how an injectable should be handled by the registry.
15
- * @summary Specifies lifecycle and callback configuration for injectables, such as whether they are singletons and whether a post-build callback should run.
16
- * @template T The instance type governed by these options.
17
- * @property {boolean} singleton Indicates if the injectable should be treated as a singleton (single shared instance).
18
- * @property {InstanceCallback<T>} callback Optional callback invoked after building an instance to perform additional setup or transformation.
19
- * @typedef InjectableOptions
20
- * @memberOf module:injectable-decorators
21
- */
22
- export type InjectableOptions<T> = {
23
- singleton: boolean;
24
- callback: InstanceCallback<T>;
25
- };
26
- /**
27
- * @description Internal registry definition for a stored injectable entry.
28
- * @summary Describes how the registry caches injectable metadata, constructor, and (optionally) a built instance.
29
- * @template T The resolved instance type.
30
- * @template OPTS The options shape used for this injectable, extending {@link InjectableOptions}.
31
- * @property {OPTS} options The lifecycle/options associated with this injectable entry.
32
- * @property {*} [instance] The cached instance when applicable (e.g., singleton), otherwise undefined until built.
33
- * @property {Constructor} constructor The constructor used to create new instances.
34
- * @typedef InjectableDef
35
- * @memberOf module:injectable-decorators
36
- */
37
- export type InjectableDef<T = any, OPTS extends InjectableOptions<T> = InjectableOptions<T>> = {
38
- options: OPTS;
39
- instance?: any;
40
- constructor: Constructor<T>;
41
- };
42
- /**
43
- * @description Metadata attached to classes marked as injectable.
44
- * @summary Captures identifying information stored via reflection for later retrieval and wiring.
45
- * @property {string} class The class name of the injectable.
46
- * @property {symbol} symbol The unique symbol under which the injectable is registered.
47
- * @typedef InjectableMetadata
48
- * @memberOf module:injectable-decorators
49
- */
50
- export type InjectableMetadata = {
51
- class: string;
52
- symbol: symbol;
53
- };
@@ -1,9 +0,0 @@
1
- /**
2
- * @description Generates a fully qualified reflection metadata key.
3
- * @summary Returns the reflection key for injectables by prefixing the provided key with the base reflection key.
4
- * @param {string} key The key to be prefixed
5
- * @return {string} The fully qualified reflection key
6
- * @function getInjectKey
7
- * @memberOf module:injectable-decorators
8
- */
9
- export declare const getInjectKey: (key: string) => string;