assemblerjs 0.9.7 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +220 -56
- package/dist/index.d.ts +700 -465
- package/dist/index.js +59 -1
- package/dist/index.mjs +21 -919
- package/dist/index10.js +8 -0
- package/dist/index10.mjs +4 -0
- package/dist/index11.js +27 -0
- package/dist/index11.mjs +23 -0
- package/dist/index12.js +16 -0
- package/dist/index12.mjs +12 -0
- package/dist/index13.js +94 -0
- package/dist/index13.mjs +90 -0
- package/dist/index14.js +22 -0
- package/dist/index14.mjs +18 -0
- package/dist/index15.js +22 -0
- package/dist/index15.mjs +18 -0
- package/dist/index16.js +22 -0
- package/dist/index16.mjs +18 -0
- package/dist/index17.js +22 -0
- package/dist/index17.mjs +18 -0
- package/dist/index18.js +31 -0
- package/dist/index18.mjs +26 -0
- package/dist/index19.js +31 -0
- package/dist/index19.mjs +26 -0
- package/dist/index2.js +22 -0
- package/dist/index2.mjs +17 -0
- package/dist/index20.js +31 -0
- package/dist/index20.mjs +27 -0
- package/dist/index21.js +33 -0
- package/dist/index21.mjs +25 -0
- package/dist/index22.js +53 -0
- package/dist/index22.mjs +48 -0
- package/dist/index23.js +69 -0
- package/dist/index23.mjs +65 -0
- package/dist/index24.js +37 -0
- package/dist/index24.mjs +33 -0
- package/dist/index25.js +71 -0
- package/dist/index25.mjs +67 -0
- package/dist/index26.js +37 -0
- package/dist/index26.mjs +33 -0
- package/dist/index27.js +37 -0
- package/dist/index27.mjs +33 -0
- package/dist/index28.js +46 -0
- package/dist/index28.mjs +41 -0
- package/dist/index29.js +20 -0
- package/dist/index29.mjs +14 -0
- package/dist/index3.js +20 -0
- package/dist/index3.mjs +14 -0
- package/dist/index30.js +19 -0
- package/dist/index30.mjs +13 -0
- package/dist/index31.js +100 -0
- package/dist/index31.mjs +94 -0
- package/dist/index32.js +28 -0
- package/dist/index32.mjs +24 -0
- package/dist/index33.js +34 -0
- package/dist/index33.mjs +29 -0
- package/dist/index34.js +14 -0
- package/dist/index34.mjs +10 -0
- package/dist/index35.js +54 -0
- package/dist/index35.mjs +50 -0
- package/dist/index36.js +117 -0
- package/dist/index36.mjs +113 -0
- package/dist/index37.js +19 -0
- package/dist/index37.mjs +15 -0
- package/dist/index38.js +31 -0
- package/dist/index38.mjs +27 -0
- package/dist/index39.js +55 -0
- package/dist/index39.mjs +50 -0
- package/dist/index4.js +81 -0
- package/dist/index4.mjs +77 -0
- package/dist/index5.js +94 -0
- package/dist/index5.mjs +90 -0
- package/dist/index6.js +114 -0
- package/dist/index6.mjs +110 -0
- package/dist/index7.js +9 -0
- package/dist/index7.mjs +5 -0
- package/dist/index8.js +10 -0
- package/dist/index8.mjs +6 -0
- package/dist/index9.js +8 -0
- package/dist/index9.mjs +4 -0
- package/package.json +8 -5
package/dist/index.d.ts
CHANGED
|
@@ -34,8 +34,9 @@ export declare abstract class AbstractAssemblage {
|
|
|
34
34
|
* Called when instance of class is disposed.
|
|
35
35
|
*
|
|
36
36
|
* @param { AssemblerContext } context The assembler's context.
|
|
37
|
+
* @param { Record<string, any> } configuration The configuration object.
|
|
37
38
|
*/
|
|
38
|
-
abstract onDispose?(context: AssemblerContext): void;
|
|
39
|
+
abstract onDispose?(context: AssemblerContext, configuration?: Record<string, any>): void;
|
|
39
40
|
/**
|
|
40
41
|
* Dispose the assemblage instance.
|
|
41
42
|
*/
|
|
@@ -46,10 +47,7 @@ export declare abstract class AbstractAssemblage {
|
|
|
46
47
|
abstract whenReady?(): Promise<void>;
|
|
47
48
|
}
|
|
48
49
|
|
|
49
|
-
|
|
50
|
-
* `Assembler` abstraction.
|
|
51
|
-
*/
|
|
52
|
-
export declare abstract class AbstractAssembler extends AbstractEventManager {
|
|
50
|
+
export declare abstract class AbstractAssembler extends AbstractEventManager implements InjectableResolver, ObjectProvider, TagResolver, LifecycleManager, InjectableRegistrar {
|
|
53
51
|
abstract privateContext: AssemblerContext;
|
|
54
52
|
abstract publicContext: AssemblerContext;
|
|
55
53
|
abstract size: number;
|
|
@@ -136,13 +134,14 @@ export declare class Assembler extends EventManager implements AbstractAssembler
|
|
|
136
134
|
* Build the dependencies tree from an assemblage as entry point.
|
|
137
135
|
*
|
|
138
136
|
* @param { Concrete<T> } entry An assemblage concrete class.
|
|
137
|
+
* @param { Record<string, any> } configuration Optional configuration to pass to the build process.
|
|
139
138
|
* @returns { T } An instance of `entry` marked as singleton.
|
|
140
139
|
*/
|
|
141
|
-
static build<T>(entry: Concrete<T>): T;
|
|
142
|
-
protected
|
|
143
|
-
protected
|
|
144
|
-
protected
|
|
145
|
-
|
|
140
|
+
static build<T>(entry: Concrete<T>, configuration?: Record<string, any>): T;
|
|
141
|
+
protected injectableManager: InjectableManager;
|
|
142
|
+
protected objectManager: ObjectManager;
|
|
143
|
+
protected _hookManager: HookManager;
|
|
144
|
+
get hookManager(): HookManager;
|
|
146
145
|
/**
|
|
147
146
|
* Context passed to internal classes.
|
|
148
147
|
*/
|
|
@@ -152,509 +151,745 @@ export declare class Assembler extends EventManager implements AbstractAssembler
|
|
|
152
151
|
*/
|
|
153
152
|
readonly publicContext: AssemblerContext;
|
|
154
153
|
private constructor();
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
154
|
+
dispose(): void;
|
|
155
|
+
register<T>(injection: Injection<T>, instance?: boolean): Injectable<T>;
|
|
156
|
+
use<T>(identifier: string | symbol, object: T): T;
|
|
157
|
+
prepareInitHook<T = AbstractAssemblage>(instance: T, configuration?: Record<string, any>): unknown[];
|
|
158
|
+
has<T>(identifier: Identifier<T> | string | symbol): boolean;
|
|
159
|
+
require<T>(identifier: Identifier<T> | string | symbol, configuration?: Record<string, any>): T;
|
|
160
|
+
concrete<T>(identifier: Identifier<T>): Concrete<T> | undefined;
|
|
161
|
+
tagged(...tags: string[]): unknown[];
|
|
162
|
+
addGlobal(key: string, value: any): void;
|
|
163
|
+
/**
|
|
164
|
+
* Get a global value by key.
|
|
159
165
|
*
|
|
160
|
-
*
|
|
166
|
+
* @param { string } key The key to get global value.
|
|
167
|
+
* @returns { any | undefined } The global value or `undefined` if not set.
|
|
161
168
|
*/
|
|
169
|
+
global(key: string): any | undefined;
|
|
170
|
+
/**
|
|
171
|
+
* Size of the assembler: number of registered dependencies.
|
|
172
|
+
*/
|
|
173
|
+
get size(): number;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Assembler public context that provide
|
|
178
|
+
* access to some useful `Assembler` methods.
|
|
179
|
+
*/
|
|
180
|
+
export declare interface AssemblerContext {
|
|
181
|
+
has: AbstractAssembler['has'];
|
|
182
|
+
require: AbstractAssembler['require'];
|
|
183
|
+
concrete: AbstractAssembler['concrete'];
|
|
184
|
+
tagged: AbstractAssembler['tagged'];
|
|
185
|
+
global: AbstractAssembler['global'];
|
|
186
|
+
dispose: AssemblerDispose;
|
|
187
|
+
on: AbstractAssembler['on'];
|
|
188
|
+
once: AbstractAssembler['once'];
|
|
189
|
+
off: AbstractAssembler['off'];
|
|
190
|
+
events: AbstractAssembler['channels'];
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* `Assembler` dispose method type.
|
|
195
|
+
*/
|
|
196
|
+
export declare type AssemblerDispose = AbstractAssembler['dispose'];
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Assembler private context that provide
|
|
200
|
+
* access to some `Assembler` methods
|
|
201
|
+
* used internally.
|
|
202
|
+
*/
|
|
203
|
+
declare interface AssemblerPrivateContext extends AssemblerContext {
|
|
204
|
+
register: AbstractAssembler['register'];
|
|
205
|
+
use: AbstractAssembler['use'];
|
|
206
|
+
prepareInitHook: AbstractAssembler['prepareInitHook'];
|
|
207
|
+
addGlobal: AbstractAssembler['addGlobal'];
|
|
208
|
+
emit: AbstractAssembler['emit'];
|
|
209
|
+
addChannels: AbstractAssembler['addChannels'];
|
|
210
|
+
removeChannels: AbstractAssembler['removeChannels'];
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Check at given interval if a property is defined and truthy to call an async method.
|
|
215
|
+
*
|
|
216
|
+
* @param { string } property The name of the class proprty to wait for.
|
|
217
|
+
* @param { number | undefined } interval The interval in milliseconds at which the value is checked (defaults to 25 milliseconds).
|
|
218
|
+
* @returns { Promise<void> } A promise that calls the original method when resolving.
|
|
219
|
+
*
|
|
220
|
+
* @deprecated This method is deprecated in `assemblerjs` package. Use the same method from `@assemblerjs/core` package.
|
|
221
|
+
*/
|
|
222
|
+
export declare const Await: (property: string, interval?: number) => MethodDecorator;
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Injectable binds a concrete class to an abstract class as identifier without configuration.
|
|
226
|
+
*/
|
|
227
|
+
declare type BaseInjection<T> = Tuple<[Abstract<T>, Concrete<T>]>;
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Describes a buildable object.
|
|
231
|
+
*/
|
|
232
|
+
declare interface Buildable<T> {
|
|
233
|
+
identifier: Identifier<T>;
|
|
234
|
+
concrete: Concrete<T>;
|
|
235
|
+
instance?: T;
|
|
236
|
+
configuration: Record<string, any>;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Injection binds a concrete class to itself as identifier
|
|
241
|
+
* and provides a configuration object that will be passed to context.
|
|
242
|
+
*/
|
|
243
|
+
declare type ConcreteConfiguredInjection<T> = Tuple<[
|
|
244
|
+
Concrete<T>,
|
|
245
|
+
Record<string, any>
|
|
246
|
+
]>;
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Injectable binds a conrete class to itself as identifier.
|
|
250
|
+
*/
|
|
251
|
+
declare type ConcreteInjection<T> = Tuple<[Concrete<T>]>;
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Injects the injectable's configuration object.
|
|
255
|
+
* @returns A parameter decorator
|
|
256
|
+
*/
|
|
257
|
+
export declare const Configuration: (param: void) => ParameterDecorator;
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Injectable binds a concrete class to an abstract class as identifier
|
|
261
|
+
* and provides a configuration object that will be passed to context.
|
|
262
|
+
*/
|
|
263
|
+
declare type ConfiguredInjection<T> = Tuple<[
|
|
264
|
+
Abstract<T>,
|
|
265
|
+
Concrete<T>,
|
|
266
|
+
Record<string, any>
|
|
267
|
+
]>;
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* A custom decorator that adds a function called after the original constructor
|
|
271
|
+
* and that can wrap an `Assemblage` with its own parameters decorator (e.g. @Use, @Context, ...).
|
|
272
|
+
* The decorator can be placed above or below the `Assemblage` decorator.
|
|
273
|
+
* The `definition` optional parameter allows passing a configuration object to the decorator.
|
|
274
|
+
*
|
|
275
|
+
* @template TDefinition The type of the definition/configuration object
|
|
276
|
+
* @param fn A function to execute after `super`. Do not use arrow function here if access to `this` is required.
|
|
277
|
+
* @param definition The configuration object to pass to the callback function
|
|
278
|
+
* @returns A ClassDecorator
|
|
279
|
+
*/
|
|
280
|
+
export declare const ConstructorDecorator: <TDefinition extends ObjectLiteral = ObjectLiteral>(fn?: ConstructorDecoratorCallback<any, TDefinition>, definition?: TDefinition) => <TConstructor extends new (...args: any[]) => any>(Base: TConstructor) => TConstructor;
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Type for the callback function that will be executed after the constructor.
|
|
284
|
+
* @template TInstance The type of the class instance
|
|
285
|
+
* @template TDefinition The type of the definition/configuration object
|
|
286
|
+
*/
|
|
287
|
+
export declare type ConstructorDecoratorCallback<TInstance = any, TDefinition extends ObjectLiteral = ObjectLiteral> = (this: TInstance, definition?: TDefinition) => void;
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Type for the decorator function.
|
|
291
|
+
*/
|
|
292
|
+
export declare type ConstructorDecoratorFunction = <T extends new (...args: any[]) => any>(target: T) => T;
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Injects the injectable's public context.
|
|
296
|
+
* @returns A parameter decorator
|
|
297
|
+
*/
|
|
298
|
+
export declare const Context: (param: void) => ParameterDecorator;
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Create a custom decorator that adds a function called after the original constructor
|
|
302
|
+
* and that can wrap an `Assemblage` with its own parameters decorator (e.g. @Use, @Context, ...).
|
|
303
|
+
* The decorator can be placed above or below the `Assemblage` decorator.
|
|
304
|
+
* The `definition` optional parameter allows passing a configuration object to the decorator.
|
|
305
|
+
*
|
|
306
|
+
* @template TInstance The type of the class instance (for type-safe access to `this`)
|
|
307
|
+
* @template TDefinition The type of the definition/configuration object
|
|
308
|
+
* @param fn A function to execute after `super`. Do not use arrow function here if access to `this` is required.
|
|
309
|
+
* @returns A decorator function that accepts an optional definition and returns a ClassDecorator
|
|
310
|
+
*
|
|
311
|
+
* @example
|
|
312
|
+
* ```typescript
|
|
313
|
+
* // Define your decorator with typed definition
|
|
314
|
+
* interface LoggerConfig {
|
|
315
|
+
* prefix: string;
|
|
316
|
+
* enabled: boolean;
|
|
317
|
+
* }
|
|
318
|
+
*
|
|
319
|
+
* const Logger = createConstructorDecorator<MyClass, LoggerConfig>(function(config) {
|
|
320
|
+
* // `this` is typed as MyClass
|
|
321
|
+
* this.logPrefix = config?.prefix || 'LOG';
|
|
322
|
+
* });
|
|
323
|
+
*
|
|
324
|
+
* @Logger({ prefix: 'APP', enabled: true })
|
|
325
|
+
* @Assemblage()
|
|
326
|
+
* class MyClass implements AbstractAssemblage {
|
|
327
|
+
* logPrefix?: string;
|
|
328
|
+
* }
|
|
329
|
+
* ```
|
|
330
|
+
*/
|
|
331
|
+
export declare const createConstructorDecorator: <TInstance = any, TDefinition extends ObjectLiteral = ObjectLiteral>(fn?: ConstructorDecoratorCallback<TInstance, TDefinition>) => DecoratorFactory<TDefinition>;
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Legacy decorator factory - kept for backward compatibility.
|
|
335
|
+
* @deprecated Use the new decorators from simple-decorators.ts
|
|
336
|
+
*/
|
|
337
|
+
export declare const createParamIndexDecorator: (key: string) => () => ParameterDecorator;
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Manually decorate a class to be an `Assemblage`.
|
|
341
|
+
*
|
|
342
|
+
* @param { Concrete<T> } target The class to decorate.
|
|
343
|
+
* @param { AssemblageDefinition } definition Definition of the assemblage that provides injections, etc.
|
|
344
|
+
* @returns
|
|
345
|
+
*/
|
|
346
|
+
export declare const decorateAssemblage: <T>(target: Concrete<T>, definition?: AssemblageDefinition) => Concrete<T>;
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Legacy function for backward compatibility with constructor-decorator.
|
|
350
|
+
* @param identifier The identifier of the global object to inject
|
|
351
|
+
* @param target The target class
|
|
352
|
+
* @param index The parameter index
|
|
353
|
+
*/
|
|
354
|
+
export declare const decorateGlobal: (identifier: string | symbol, target: any, index: number) => void;
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Legacy function for backward compatibility with constructor-decorator.
|
|
358
|
+
* @param identifier The identifier of the object to inject
|
|
359
|
+
* @param target The target class
|
|
360
|
+
* @param index The parameter index
|
|
361
|
+
*/
|
|
362
|
+
export declare const decorateUse: (identifier: string | symbol, target: any, index: number) => void;
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Type for a function that creates a decorator.
|
|
366
|
+
* @template TDefinition The type of the definition/configuration object
|
|
367
|
+
*/
|
|
368
|
+
export declare type DecoratorFactory<TDefinition extends ObjectLiteral = ObjectLiteral> = (definition?: TDefinition) => ConstructorDecoratorFunction;
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Handler function for custom decorator logic in constructor-decorator.
|
|
372
|
+
* @param value The value stored for this parameter (e.g., identifier for Use/Global)
|
|
373
|
+
* @param target The target class being decorated
|
|
374
|
+
* @param index The parameter index
|
|
375
|
+
*/
|
|
376
|
+
export declare type DecoratorHandler = (value: any, target: any, index: number) => void;
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Metadata about a registered decorator.
|
|
380
|
+
*/
|
|
381
|
+
declare interface DecoratorMetadata_2 {
|
|
382
|
+
name: string;
|
|
383
|
+
valueType: 'single' | 'array' | 'map';
|
|
384
|
+
handler?: DecoratorHandler;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Injects the injectable's definition object.
|
|
389
|
+
* @returns A parameter decorator
|
|
390
|
+
*/
|
|
391
|
+
export declare const Definition: (param: void) => ParameterDecorator;
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Injects the injectable's dispose function.
|
|
395
|
+
* @returns A parameter decorator
|
|
396
|
+
*/
|
|
397
|
+
export declare const Dispose: (param: void) => ParameterDecorator;
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* `EventChannel` extends `string`.
|
|
401
|
+
*/
|
|
402
|
+
export declare type EventChannel = string;
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* Describes a list of event channels as Record<EventChannel, string>
|
|
406
|
+
*/
|
|
407
|
+
export declare type EventChannelList = Record<EventChannel, string>;
|
|
408
|
+
|
|
409
|
+
export declare class EventManager implements AbstractEventManager {
|
|
410
|
+
private readonly listeners;
|
|
411
|
+
private readonly onceListeners;
|
|
412
|
+
private readonly channelCache;
|
|
413
|
+
readonly channels: Set<string>;
|
|
414
|
+
constructor(...allowedChannels: string[]);
|
|
162
415
|
dispose(): void;
|
|
416
|
+
addChannels(...channels: string[]): EventManager;
|
|
417
|
+
removeChannels(...channels: string[]): EventManager;
|
|
418
|
+
on(channel: string, callback: Listener): EventManager;
|
|
419
|
+
once(channel: string, callback: Listener): EventManager;
|
|
420
|
+
off(channel: string, callback?: Listener): EventManager;
|
|
421
|
+
emit(channel: string, ...args: any[]): EventManager;
|
|
422
|
+
private run;
|
|
423
|
+
private cleanChannel;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
export declare const getAssemblageContext: <T>(target: Concrete<T> | Function) => AssemblerContext;
|
|
427
|
+
|
|
428
|
+
export declare const getAssemblageDefinition: <T>(target: Concrete<T>) => AssemblageDefinition;
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Gets all decorated parameter indexes for registered decorators.
|
|
432
|
+
* Dynamically retrieves indexes for all decorators registered in ParameterDecoratorFactory.
|
|
433
|
+
* @param target The concrete class to inspect
|
|
434
|
+
* @returns Object with indexes for each decorator type
|
|
435
|
+
*/
|
|
436
|
+
export declare const getDecoratedParametersIndexes: <T>(target: Concrete<T>) => ParametersDecoratorsIndexes;
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Generic function to get parameter indexes for a specific decorator.
|
|
440
|
+
* @param decoratorName The name of the decorator (e.g., 'Context', 'Use', 'Global')
|
|
441
|
+
* @param concrete The concrete class to get indexes from
|
|
442
|
+
* @returns Array of parameter indexes
|
|
443
|
+
*/
|
|
444
|
+
export declare const getParameterIndexes: <T>(decoratorName: string, concrete: Concrete<T>) => number[];
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* Generic function to get parameter values for a specific decorator.
|
|
448
|
+
* @param decoratorName The name of the decorator (e.g., 'Context', 'Use', 'Global')
|
|
449
|
+
* @param concrete The concrete class to get values from
|
|
450
|
+
* @returns The stored values (type depends on decorator's valueType configuration)
|
|
451
|
+
*/
|
|
452
|
+
export declare const getParameterValues: <T, V = any>(decoratorName: string, concrete: Concrete<T>) => V;
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* Generates the reflection key for parameter index based on decorator name.
|
|
456
|
+
* Must match the format used by ParameterDecoratorFactory.
|
|
457
|
+
*/
|
|
458
|
+
export declare const getParamIndexKey: (decoratorName: string) => string;
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Generates the reflection key for parameter value based on decorator name.
|
|
462
|
+
* Must match the format used by ParameterDecoratorFactory.
|
|
463
|
+
*/
|
|
464
|
+
export declare const getParamValueKey: (decoratorName: string) => string;
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Injects a global object by its identifier.
|
|
468
|
+
* @param identifier The identifier of the global object to inject
|
|
469
|
+
* @returns A parameter decorator
|
|
470
|
+
*/
|
|
471
|
+
declare const Global_2: (param: string | symbol) => ParameterDecorator;
|
|
472
|
+
export { Global_2 as Global }
|
|
473
|
+
|
|
474
|
+
declare class HookManager {
|
|
475
|
+
static callHook: <T>(assemblage: Concrete<T> | T, name: string, context?: AssemblerContext, configuration?: Record<string, any>) => Promise<void>;
|
|
476
|
+
static callHookImmediate: <T>(assemblage: Concrete<T> | T, name: string, context?: AssemblerContext, configuration?: Record<string, any>) => void;
|
|
477
|
+
private initCache;
|
|
478
|
+
prepareInitHook<T = any>(instance: T, configuration?: Record<string, any>): unknown[];
|
|
479
|
+
callInitHooks(context: AssemblerContext): void;
|
|
480
|
+
callInitedHooks(context: AssemblerContext): void;
|
|
481
|
+
clearCache(): void;
|
|
482
|
+
getCache(): {
|
|
483
|
+
instance: any;
|
|
484
|
+
configuration?: Record<string, any>;
|
|
485
|
+
}[];
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* An identifier can be an abstract or a concrete class.
|
|
490
|
+
*/
|
|
491
|
+
export declare type Identifier<T> = Class<T>;
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* Represents an injectable assemblage that can be built into instances.
|
|
495
|
+
* Handles dependency resolution, configuration management, and lifecycle.
|
|
496
|
+
*/
|
|
497
|
+
declare class Injectable<T> implements AbstractInjectable<T> {
|
|
498
|
+
readonly privateContext: AssemblerPrivateContext;
|
|
499
|
+
readonly publicContext: AssemblerContext;
|
|
500
|
+
/** Unique identifier for this injectable. */
|
|
501
|
+
readonly identifier: Identifier<T> | string | symbol;
|
|
502
|
+
/** The concrete class to instantiate. */
|
|
503
|
+
readonly concrete: Concrete<T>;
|
|
504
|
+
/** Base configuration for this injectable. */
|
|
505
|
+
readonly configuration: Record<string, any>;
|
|
506
|
+
/** Merged configuration used during build (base + runtime). */
|
|
507
|
+
private mergedConfiguration?;
|
|
508
|
+
/** Cached definition to avoid repeated metadata lookups. */
|
|
509
|
+
private cachedDefinition?;
|
|
510
|
+
/** Cached injections to avoid repeated definition access. */
|
|
511
|
+
private cachedInjections?;
|
|
512
|
+
/** Cached objects to avoid repeated definition access. */
|
|
513
|
+
private cachedObjects?;
|
|
514
|
+
/** Cached tags to avoid repeated definition access. */
|
|
515
|
+
private cachedTags?;
|
|
516
|
+
/** Cached events to avoid repeated definition access. */
|
|
517
|
+
private cachedEvents?;
|
|
518
|
+
/** Cached globals to avoid repeated definition access. */
|
|
519
|
+
private cachedGlobals?;
|
|
520
|
+
private dependenciesIds;
|
|
521
|
+
protected singletonInstance: T | undefined;
|
|
522
|
+
private builder;
|
|
523
|
+
static of<TNew>(buildable: Buildable<TNew>, privateContext: AssemblerPrivateContext, publicContext: AssemblerContext): Injectable<TNew>;
|
|
524
|
+
private constructor();
|
|
163
525
|
/**
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
* @param { Injection<T> } injection The injection tuple to register.
|
|
167
|
-
* @param { boolean | undefined } instance Set to `true` if the injection binds an instance
|
|
168
|
-
* to an identifier (defaults to `false`).
|
|
169
|
-
* @returns { Injectable<T> } An injectable of type `T`.
|
|
526
|
+
* Dispose the injectable by deleting its singleton if exists
|
|
527
|
+
* and deleting all injectable's properties.
|
|
170
528
|
*/
|
|
171
|
-
|
|
529
|
+
dispose(): void;
|
|
172
530
|
/**
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
* @param { string | symbol } identifier The identifier to register.
|
|
176
|
-
* @param { T } object The object to use with the identifier.
|
|
177
|
-
* @returns { T } The object.
|
|
178
|
-
*
|
|
179
|
-
* @example
|
|
180
|
-
* ```typescript
|
|
181
|
-
* import express from 'express';
|
|
531
|
+
* Instantiate the assemblage.
|
|
182
532
|
*
|
|
183
|
-
* @
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
* ]
|
|
187
|
-
* });
|
|
188
|
-
* class MyAssemblage implements AbstractAssemblage {
|
|
189
|
-
* constructor(@Use('express) private express) {
|
|
190
|
-
* // Use express.
|
|
191
|
-
* }
|
|
192
|
-
* }
|
|
193
|
-
* ```
|
|
533
|
+
* @param { Record<string, any> } [configuration] Optional configuration to pass to
|
|
534
|
+
* the assemblage.
|
|
535
|
+
* @returns { T } The assemblage instance.
|
|
194
536
|
*/
|
|
195
|
-
|
|
537
|
+
build(configuration?: Record<string, any>): T;
|
|
196
538
|
/**
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
* @param
|
|
201
|
-
* @param { Record<string, any> | undefined } configuration The configuration object.
|
|
202
|
-
* @returns { unknown[] } The instances to be inited as this point.
|
|
203
|
-
*/
|
|
204
|
-
prepareInitHook<T = AbstractAssemblage>(instance: T, configuration?: Record<string, any>): unknown[];
|
|
205
|
-
/**
|
|
206
|
-
* Check if `Assembler` has given identifier registered.
|
|
207
|
-
*
|
|
208
|
-
* @param { Identifier<T> | string | symbol } identifier An abstract or concrete class,
|
|
209
|
-
* or a string or symbol as identifier.
|
|
210
|
-
* @returns { boolean } `true` if dependency has been registered.
|
|
211
|
-
*/
|
|
212
|
-
has<T>(identifier: Identifier<T> | string | symbol): boolean;
|
|
213
|
-
/**
|
|
214
|
-
* Get or instantiate an assemblage for given identifier.
|
|
215
|
-
*
|
|
216
|
-
* @param { Identifier<T> | string | symbol } identifier The identifier to get instance from.
|
|
217
|
-
* @param { Record<string, any> | undefined } configuration Optional configuration
|
|
218
|
-
* object to pass to a transient assemblage's constructor.
|
|
219
|
-
* @returns { T } An instance of Concrete<T>.
|
|
220
|
-
*/
|
|
221
|
-
require<T>(identifier: Identifier<T> | string | symbol, configuration?: Record<string, any>): T;
|
|
222
|
-
/**
|
|
223
|
-
* Return a `Concrete` class for given identifier.
|
|
224
|
-
*
|
|
225
|
-
* @param { Identifier<T> } identifier The dentifier to get concrete class from.
|
|
226
|
-
* @returns { Concrete<T> | undefined } A concrete class or `undefinedù if injectable is not set.
|
|
227
|
-
*/
|
|
228
|
-
concrete<T>(identifier: Identifier<T>): Concrete<T> | undefined;
|
|
229
|
-
/**
|
|
230
|
-
* Require dependencies by tag passed in assemblage's definition.
|
|
231
|
-
*
|
|
232
|
-
* @param { string[] } tags The tags to get dependencies.
|
|
233
|
-
* @returns { unknown[] } An array of instances for the given tags. If registered
|
|
234
|
-
* identifier is not marked as 'singleton', will resolve in a new instance.
|
|
235
|
-
*/
|
|
236
|
-
tagged(...tags: string[]): unknown[];
|
|
237
|
-
addGlobal(key: string, value: any): void;
|
|
238
|
-
/**
|
|
239
|
-
* Get a global value by key.
|
|
240
|
-
*
|
|
241
|
-
* @param { string } key The key to get global value.
|
|
242
|
-
* @returns { any | undefined } The global value or `undefined` if not set.
|
|
243
|
-
*/
|
|
244
|
-
global(key: string): any | undefined;
|
|
245
|
-
/**
|
|
246
|
-
* Size of the assembler: number of registered dependencies.
|
|
247
|
-
*/
|
|
248
|
-
get size(): number;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* Assembler public context that provide
|
|
253
|
-
* access to some useful `Assembler` methods.
|
|
254
|
-
*/
|
|
255
|
-
export declare interface AssemblerContext {
|
|
256
|
-
has: AbstractAssembler['has'];
|
|
257
|
-
require: AbstractAssembler['require'];
|
|
258
|
-
concrete: AbstractAssembler['concrete'];
|
|
259
|
-
tagged: AbstractAssembler['tagged'];
|
|
260
|
-
global: AbstractAssembler['global'];
|
|
261
|
-
dispose: AssemblerDispose;
|
|
262
|
-
on: AbstractAssembler['on'];
|
|
263
|
-
once: AbstractAssembler['once'];
|
|
264
|
-
off: AbstractAssembler['off'];
|
|
265
|
-
events: AbstractAssembler['channels'];
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* `Assembler` dispose method type.
|
|
270
|
-
*/
|
|
271
|
-
export declare type AssemblerDispose = AbstractAssembler['dispose'];
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* Assembler private context that provide
|
|
275
|
-
* access to some `Assembler` methods
|
|
276
|
-
* used internally.
|
|
277
|
-
*/
|
|
278
|
-
declare interface AssemblerPrivateContext extends AssemblerContext {
|
|
279
|
-
register: AbstractAssembler['register'];
|
|
280
|
-
use: AbstractAssembler['use'];
|
|
281
|
-
prepareInitHook: AbstractAssembler['prepareInitHook'];
|
|
282
|
-
addGlobal: AbstractAssembler['addGlobal'];
|
|
283
|
-
emit: AbstractAssembler['emit'];
|
|
284
|
-
addChannels: AbstractAssembler['addChannels'];
|
|
285
|
-
removeChannels: AbstractAssembler['removeChannels'];
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
/**
|
|
289
|
-
* Check at given interval if a property is defined and truthy to call an async method.
|
|
290
|
-
*
|
|
291
|
-
* @param { string } property The name of the class proprty to wait for.
|
|
292
|
-
* @param { number | undefined } interval The interval in milliseconds at which the value is checked (defaults to 25 milliseconds).
|
|
293
|
-
* @returns { Promise<void> } A promise that calls the original method when resolving.
|
|
294
|
-
*
|
|
295
|
-
* @deprecated This method is deprecated in `assemblerjs` package. Use the same method from `@assemblerjs/core` package.
|
|
539
|
+
* Sets the singleton instance for this injectable.
|
|
540
|
+
* Used internally by resolution strategies.
|
|
541
|
+
* @param instance The singleton instance.
|
|
542
|
+
* @param mergedConfiguration Optional merged configuration to store.
|
|
296
543
|
*/
|
|
297
|
-
|
|
298
|
-
|
|
544
|
+
setSingletonInstance(instance: T, mergedConfiguration?: Record<string, any>): void;
|
|
299
545
|
/**
|
|
300
|
-
*
|
|
546
|
+
* Metadatas passed in assemblage's definition or in its parent definition.
|
|
547
|
+
* Cached to avoid repeated reflection calls.
|
|
301
548
|
*/
|
|
302
|
-
|
|
303
|
-
|
|
549
|
+
get definition(): AssemblageDefinition;
|
|
304
550
|
/**
|
|
305
|
-
*
|
|
551
|
+
* `true` if assemblage is a singleton.
|
|
306
552
|
*/
|
|
307
|
-
|
|
308
|
-
identifier: Identifier<T>;
|
|
309
|
-
concrete: Concrete<T>;
|
|
310
|
-
instance?: T;
|
|
311
|
-
configuration: Record<string, any>;
|
|
312
|
-
}
|
|
313
|
-
|
|
553
|
+
get isSingleton(): boolean;
|
|
314
554
|
/**
|
|
315
|
-
*
|
|
316
|
-
* and provides a configuration object that will be passed to context.
|
|
555
|
+
* Injectable assemblage's dependencies passed as 'constructor' parameters.
|
|
317
556
|
*/
|
|
318
|
-
|
|
319
|
-
Concrete<T>,
|
|
320
|
-
Record<string, any>
|
|
321
|
-
]>;
|
|
322
|
-
|
|
557
|
+
get dependencies(): (Identifier<unknown> | any)[];
|
|
323
558
|
/**
|
|
324
|
-
*
|
|
559
|
+
* The singleton instance if this `Injectable` wraps a singleton assemblage.
|
|
325
560
|
*/
|
|
326
|
-
|
|
327
|
-
|
|
561
|
+
get singleton(): T | undefined;
|
|
328
562
|
/**
|
|
329
|
-
*
|
|
563
|
+
* Injectable assemblage's own injections defined in its decorator's definition.
|
|
330
564
|
*/
|
|
331
|
-
|
|
332
|
-
|
|
565
|
+
get injections(): Injection<unknown>[];
|
|
566
|
+
/**
|
|
567
|
+
* Injectable assemblage's own objects (e.g. instances) injections defined in its decorator's definition.
|
|
568
|
+
*/
|
|
569
|
+
get objects(): InstanceInjection<unknown>[];
|
|
570
|
+
/**
|
|
571
|
+
* Tags passed in assemblage's definition.
|
|
572
|
+
*/
|
|
573
|
+
get tags(): string[];
|
|
574
|
+
/**
|
|
575
|
+
* Global injections passed in assemblage's definition.
|
|
576
|
+
* These injections are available in all assemblages and can be used
|
|
577
|
+
* to provide global values, services or utilities.
|
|
578
|
+
*/
|
|
579
|
+
get globals(): Record<string, any> | undefined;
|
|
333
580
|
/**
|
|
334
|
-
*
|
|
335
|
-
* and provides a configuration object that will be passed to context.
|
|
581
|
+
* Event channels passed in assemblage's definition.
|
|
336
582
|
*/
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
583
|
+
get events(): string[];
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
declare class InjectableManager {
|
|
587
|
+
private injectables;
|
|
588
|
+
private privateContext;
|
|
589
|
+
private publicContext;
|
|
590
|
+
private singletonStrategy;
|
|
591
|
+
private transientStrategy;
|
|
592
|
+
setContexts(privateContext: AssemblerPrivateContext, publicContext: AssemblerContext): void;
|
|
593
|
+
register<T>(injection: Injection<T>, instance?: boolean): Injectable<T>;
|
|
594
|
+
has<T>(identifier: Identifier<T>): boolean;
|
|
595
|
+
require<T>(identifier: Identifier<T>, configuration?: Record<string, any>): T;
|
|
596
|
+
concrete<T>(identifier: Identifier<T>): any | undefined;
|
|
597
|
+
tagged(...tags: string[]): unknown[];
|
|
598
|
+
dispose(): void;
|
|
599
|
+
get size(): number;
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
declare interface InjectableRegistrar {
|
|
603
|
+
register<T>(injection: Injection<T>, instance?: boolean): Injectable<T>;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* `Assembler` abstraction.
|
|
608
|
+
*/
|
|
609
|
+
declare interface InjectableResolver {
|
|
610
|
+
has<T>(identifier: Identifier<T>): boolean;
|
|
611
|
+
require<T>(identifier: Identifier<T> | string | symbol, configuration?: Record<string, any>): T;
|
|
612
|
+
concrete<T>(identifier: Identifier<T>): Concrete<T> | undefined;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
/**
|
|
616
|
+
* A generic injection tuple.
|
|
617
|
+
*/
|
|
618
|
+
declare type Injection<T> = BaseInjection<T> | ConfiguredInjection<T> | ConcreteInjection<T> | ConcreteConfiguredInjection<T>;
|
|
342
619
|
|
|
620
|
+
/**
|
|
621
|
+
* Injectable binds an instance of a class to an identifier (abstract or concrete).
|
|
622
|
+
*/
|
|
623
|
+
declare type InstanceInjection<T> = Tuple<[Identifier<T> | string | symbol, T]>;
|
|
624
|
+
|
|
625
|
+
/**
|
|
626
|
+
* Check if a given class is an `Assemblage`.
|
|
627
|
+
*
|
|
628
|
+
* @param { Concrete<T> } target The class to test.
|
|
629
|
+
* @returns `true` if the class is an assemblage.
|
|
630
|
+
*/
|
|
631
|
+
export declare const isAssemblage: <T>(target: Concrete<T>) => boolean;
|
|
632
|
+
|
|
633
|
+
declare interface LifecycleManager {
|
|
634
|
+
prepareInitHook<T = AbstractAssemblage>(instance: T, configuration?: Record<string, any>): unknown[];
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
/**
|
|
638
|
+
* Describes a listener type as a function taking any number of arguments and returning `void`.
|
|
639
|
+
*/
|
|
640
|
+
export declare type Listener = (...args: any[]) => void | Promise<void>;
|
|
641
|
+
|
|
642
|
+
export declare class ListenerCollection implements AbstractListenerCollection {
|
|
643
|
+
/**
|
|
644
|
+
* Class is indexable by `EventChannel`.
|
|
645
|
+
*/
|
|
646
|
+
[key: string]: Listener[] | any;
|
|
647
|
+
/**
|
|
648
|
+
* Internal listeners `Object`.
|
|
649
|
+
*/
|
|
650
|
+
readonly collection: Record<EventChannel, Array<Listener>>;
|
|
651
|
+
constructor();
|
|
343
652
|
/**
|
|
344
|
-
*
|
|
345
|
-
* and
|
|
346
|
-
|
|
347
|
-
|
|
653
|
+
* Clean up the collection by removing all listeners and channels
|
|
654
|
+
* and deleting listeners private property.
|
|
655
|
+
*/
|
|
656
|
+
dispose(): void;
|
|
657
|
+
/**
|
|
658
|
+
* Add a listener to the collection.
|
|
348
659
|
*
|
|
349
|
-
* @param {
|
|
350
|
-
*
|
|
351
|
-
* @
|
|
352
|
-
* @returns A new decorator.
|
|
660
|
+
* @param { EventChannel } channel The channel to add the listener to.
|
|
661
|
+
* @param { Listener } listener The callback function to run when the event is emitted.
|
|
662
|
+
* @returns { ListenerCollection } This collection.
|
|
353
663
|
*/
|
|
354
|
-
|
|
355
|
-
|
|
664
|
+
add(channel: EventChannel, listener: Listener): ListenerCollection;
|
|
356
665
|
/**
|
|
357
|
-
*
|
|
666
|
+
* Add a listener to the collection.
|
|
667
|
+
*
|
|
668
|
+
* @param { Tuple<EventChannel, Listener> } tuple The channel and its listener in a tuple.
|
|
669
|
+
* @returns { ListenerCollection } This collection.
|
|
358
670
|
*/
|
|
359
|
-
|
|
360
|
-
|
|
671
|
+
add(tuple: Tuple<[EventChannel, Listener]>): ListenerCollection;
|
|
361
672
|
/**
|
|
362
|
-
*
|
|
363
|
-
*
|
|
364
|
-
* Note that it must be placed before the `Assemblage` decorator.
|
|
365
|
-
* The `definition` optional parameter allows passing a configuration object to the decorator.
|
|
673
|
+
* Removes a listener or all listeners for a given channel.
|
|
674
|
+
* If the channel or the provided listener does not exist, fails silently.
|
|
366
675
|
*
|
|
367
|
-
* @param {
|
|
368
|
-
*
|
|
369
|
-
* @returns
|
|
676
|
+
* @param { EventChannel } channel The channel the listener is listening to.
|
|
677
|
+
* @param { Listener } listener The listener to remove. If not provided, remove all listeners for given channel.
|
|
678
|
+
* @returns { ListenerCollection } This collection.
|
|
370
679
|
*/
|
|
371
|
-
|
|
372
|
-
|
|
680
|
+
remove(channel: string, listener?: Listener): ListenerCollection;
|
|
373
681
|
/**
|
|
374
|
-
*
|
|
682
|
+
* Checks if the collection includes a specific channel or listener.
|
|
375
683
|
*
|
|
376
|
-
* @param {
|
|
377
|
-
* @
|
|
378
|
-
*
|
|
684
|
+
* @param { EventChannel | Listener } value The channel or the listener to find in the collection.
|
|
685
|
+
* @returns { boolean } true if the collection includes this channel / this listener,
|
|
686
|
+
* false if not.
|
|
379
687
|
*/
|
|
380
|
-
|
|
381
|
-
|
|
688
|
+
has(value: EventChannel): boolean;
|
|
689
|
+
has(value: Listener): boolean;
|
|
382
690
|
/**
|
|
383
|
-
*
|
|
691
|
+
* Get a specific channel listeners array or a specific listener channels array.
|
|
692
|
+
*
|
|
693
|
+
* @param { EventChannel | Listener } value The channel or the listener to find in the collection.
|
|
694
|
+
* @returns { EventChannel[] | Listener[] } An array of channels or listeners.
|
|
384
695
|
*/
|
|
385
|
-
|
|
386
|
-
|
|
696
|
+
get(value: EventChannel): Listener[];
|
|
697
|
+
get(value: Listener): EventChannel[];
|
|
387
698
|
/**
|
|
388
|
-
*
|
|
699
|
+
* Clear the entire collection.
|
|
700
|
+
*
|
|
701
|
+
* @returns { ListenerCollection } This collection.
|
|
389
702
|
*/
|
|
390
|
-
|
|
391
|
-
|
|
703
|
+
clear(): ListenerCollection;
|
|
392
704
|
/**
|
|
393
|
-
*
|
|
705
|
+
* The listeners of this collection flatten in a single array.
|
|
394
706
|
*/
|
|
395
|
-
|
|
396
|
-
|
|
707
|
+
get listeners(): Listener[];
|
|
708
|
+
/**
|
|
709
|
+
* The listeners collection channels.
|
|
710
|
+
*/
|
|
711
|
+
get channels(): EventChannel[];
|
|
712
|
+
/**
|
|
713
|
+
* Returns the total listeners length.
|
|
714
|
+
*/
|
|
715
|
+
get length(): number;
|
|
397
716
|
/**
|
|
398
|
-
*
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
*
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
export declare class EventManager implements AbstractEventManager {
|
|
413
|
-
private readonly listeners;
|
|
414
|
-
private readonly onceListeners;
|
|
415
|
-
readonly channels: Set<string>;
|
|
416
|
-
constructor(...allowedChannels: string[]);
|
|
417
|
-
dispose(): void;
|
|
418
|
-
addChannels(...channels: string[]): EventManager;
|
|
419
|
-
removeChannels(...channels: string[]): EventManager;
|
|
420
|
-
on(channel: string, callback: Listener): EventManager;
|
|
421
|
-
once(channel: string, callback: Listener): EventManager;
|
|
422
|
-
off(channel: string, callback?: Listener): EventManager;
|
|
423
|
-
emit(channel: string, ...args: any[]): EventManager;
|
|
424
|
-
private run;
|
|
425
|
-
private cleanChannel;
|
|
426
|
-
}
|
|
717
|
+
* Allows iterating over listeners in specific channel with 'for... of...' loop.
|
|
718
|
+
*
|
|
719
|
+
* @returns { Listener } A listener function.
|
|
720
|
+
*
|
|
721
|
+
* @example
|
|
722
|
+
* // Iterates listeners in a specific channel.
|
|
723
|
+
* for (const listener of myListenerCollection) {
|
|
724
|
+
* // Calls the registered listener.
|
|
725
|
+
* listener();
|
|
726
|
+
* }
|
|
727
|
+
*/
|
|
728
|
+
[Symbol.iterator](): Iterator<EventChannel>;
|
|
729
|
+
}
|
|
427
730
|
|
|
428
|
-
|
|
731
|
+
export declare interface ObjectLiteral {
|
|
732
|
+
[key: string]: any;
|
|
733
|
+
}
|
|
429
734
|
|
|
430
|
-
|
|
735
|
+
declare class ObjectManager {
|
|
736
|
+
private objects;
|
|
737
|
+
private globals;
|
|
738
|
+
use<T>(identifier: string | symbol, object: T): T;
|
|
739
|
+
has(identifier: string | symbol): boolean;
|
|
740
|
+
require<T>(identifier: string | symbol): T;
|
|
741
|
+
addGlobal(key: string, value: any): void;
|
|
742
|
+
global(key: string): any | undefined;
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
declare interface ObjectProvider {
|
|
746
|
+
use<T>(identifier: string | symbol, object: T): T;
|
|
747
|
+
global(key: string): any | undefined;
|
|
748
|
+
addGlobal(key: string, value: any): void;
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
/**
|
|
752
|
+
* Marks a constructor parameter as optional.
|
|
753
|
+
* If the dependency is not available, the provided default value (or undefined) will be injected.
|
|
754
|
+
*
|
|
755
|
+
* @param defaultValue Optional default value to use when the dependency is not available.
|
|
756
|
+
* If not provided, undefined will be injected.
|
|
757
|
+
*
|
|
758
|
+
* @example
|
|
759
|
+
* // Without default value - injects undefined if not available
|
|
760
|
+
* class MyService {
|
|
761
|
+
* constructor(
|
|
762
|
+
* private logger: Logger, // Required
|
|
763
|
+
* @Optional() private cache?: Cache // Optional - undefined if not available
|
|
764
|
+
* ) {}
|
|
765
|
+
* }
|
|
766
|
+
*
|
|
767
|
+
* @example
|
|
768
|
+
* // With default value
|
|
769
|
+
* class MyService {
|
|
770
|
+
* constructor(
|
|
771
|
+
* @Optional(new ConsoleLogger()) private logger: Logger,
|
|
772
|
+
* @Optional(null) private cache: Cache | null
|
|
773
|
+
* ) {}
|
|
774
|
+
* }
|
|
775
|
+
*/
|
|
776
|
+
export declare const Optional: (param: any) => ParameterDecorator;
|
|
431
777
|
|
|
432
|
-
|
|
778
|
+
/**
|
|
779
|
+
* Configuration for creating a parameter decorator.
|
|
780
|
+
*/
|
|
781
|
+
export declare interface ParameterDecoratorConfig {
|
|
782
|
+
/** The name of the decorator (e.g., 'Logger', 'Database') */
|
|
783
|
+
name: string;
|
|
784
|
+
/** How parameter values are stored */
|
|
785
|
+
valueType?: 'single' | 'array' | 'map';
|
|
786
|
+
/** The resolver class for this decorator */
|
|
787
|
+
resolver: new () => ParameterResolver;
|
|
788
|
+
/** Optional handler for custom decoration logic (e.g., for Use/Global decorators) */
|
|
789
|
+
handler?: DecoratorHandler;
|
|
790
|
+
}
|
|
433
791
|
|
|
792
|
+
/**
|
|
793
|
+
* Factory for creating parameter decorators.
|
|
794
|
+
* Decorators are responsible for registering their own resolvers.
|
|
795
|
+
* This eliminates boilerplate code and ensures consistency across all decorators.
|
|
796
|
+
*/
|
|
797
|
+
export declare class ParameterDecoratorFactory {
|
|
798
|
+
private static registeredDecorators;
|
|
434
799
|
/**
|
|
435
|
-
*
|
|
800
|
+
* Creates a parameter decorator.
|
|
801
|
+
* Note: Resolvers must be registered separately by the decorator implementation.
|
|
802
|
+
* @param config The decorator configuration
|
|
803
|
+
* @returns A parameter decorator function
|
|
436
804
|
*/
|
|
437
|
-
|
|
438
|
-
|
|
805
|
+
static create<T>(config: ParameterDecoratorConfig): (param: T) => ParameterDecorator;
|
|
806
|
+
/**
|
|
807
|
+
* Creates the actual decorator function.
|
|
808
|
+
*/
|
|
809
|
+
private static createDecoratorFunction;
|
|
810
|
+
/**
|
|
811
|
+
* Validates that a parameter doesn't already have a decorator applied.
|
|
812
|
+
* @param target The target class
|
|
813
|
+
* @param index The parameter index
|
|
814
|
+
* @param currentParamIndex The metadata key for the current decorator being applied
|
|
815
|
+
* @throws Error if the parameter already has a decorator
|
|
816
|
+
*/
|
|
817
|
+
private static validateSingleDecoratorPerParameter;
|
|
818
|
+
/**
|
|
819
|
+
* Stores parameter data using reflection metadata.
|
|
820
|
+
*/
|
|
821
|
+
private static storeParameterData;
|
|
822
|
+
/**
|
|
823
|
+
* Creates a helper function to get parameter indexes for a decorator.
|
|
824
|
+
* @param paramIndexKey The reflection key for parameter indexes
|
|
825
|
+
* @returns A function that retrieves indexes for a concrete class
|
|
826
|
+
*/
|
|
827
|
+
static createParameterIndexGetter(paramIndexKey: string): <T>(concrete: Concrete<T>) => number[];
|
|
828
|
+
/**
|
|
829
|
+
* Creates a helper function to get parameter values for a decorator.
|
|
830
|
+
* @param paramValueKey The reflection key for parameter values
|
|
831
|
+
* @param valueType The type of value storage (currently unused but kept for future extensibility)
|
|
832
|
+
* @returns A function that retrieves values for a concrete class
|
|
833
|
+
*/
|
|
834
|
+
static createParameterValueGetter(paramValueKey: string, _valueType: 'single' | 'array' | 'map'): <T>(concrete: Concrete<T>) => any;
|
|
835
|
+
/**
|
|
836
|
+
* Gets all registered decorator names.
|
|
837
|
+
* @returns Array of registered decorator names
|
|
838
|
+
*/
|
|
839
|
+
static getRegisteredDecorators(): string[];
|
|
840
|
+
/**
|
|
841
|
+
* Checks if a decorator is registered.
|
|
842
|
+
* @param name The decorator name
|
|
843
|
+
* @returns True if registered, false otherwise
|
|
844
|
+
*/
|
|
845
|
+
static isRegistered(name: string): boolean;
|
|
846
|
+
/**
|
|
847
|
+
* Gets metadata for a registered decorator.
|
|
848
|
+
* @param name The decorator name
|
|
849
|
+
* @returns The decorator metadata or undefined if not found
|
|
850
|
+
*/
|
|
851
|
+
static getDecoratorMetadata(name: string): DecoratorMetadata_2 | undefined;
|
|
852
|
+
/**
|
|
853
|
+
* Gets the handler for a decorator if it has one.
|
|
854
|
+
* @param name The decorator name
|
|
855
|
+
* @returns The handler function or undefined
|
|
856
|
+
*/
|
|
857
|
+
static getDecoratorHandler(name: string): DecoratorHandler | undefined;
|
|
858
|
+
}
|
|
439
859
|
|
|
860
|
+
/**
|
|
861
|
+
* Interface for parameter resolvers that handle different types of injection.
|
|
862
|
+
*/
|
|
863
|
+
declare interface ParameterResolver {
|
|
440
864
|
/**
|
|
441
|
-
*
|
|
865
|
+
* Resolves a parameter value for a given index.
|
|
866
|
+
* @param index The parameter index in the constructor.
|
|
867
|
+
* @param injectable The injectable instance.
|
|
868
|
+
* @param concrete The concrete class being instantiated.
|
|
869
|
+
* @param config Optional merged configuration.
|
|
870
|
+
* @returns The resolved parameter value.
|
|
442
871
|
*/
|
|
443
|
-
|
|
872
|
+
resolve(index: number, injectable: AbstractInjectable<any>, concrete: Concrete<any>, config?: Record<string, any>): any;
|
|
873
|
+
}
|
|
444
874
|
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
* If the assemblage is a singleton, this parameter will be ignored.
|
|
467
|
-
* @returns { T } The assemblage instance.
|
|
468
|
-
*/
|
|
469
|
-
build(configuration?: Record<string, any>): T;
|
|
470
|
-
/**
|
|
471
|
-
* Injectable assemblage's dependencies passed as 'constructor' parameters.
|
|
472
|
-
*/
|
|
473
|
-
get dependencies(): (Identifier<unknown> | any)[];
|
|
474
|
-
/**
|
|
475
|
-
* Metadatas passed in assemblage's definition or in its parent definition.
|
|
476
|
-
*/
|
|
477
|
-
get definition(): AssemblageDefinition;
|
|
478
|
-
/**
|
|
479
|
-
* `true` if assemblage is a singleton.
|
|
480
|
-
*/
|
|
481
|
-
get isSingleton(): boolean;
|
|
482
|
-
/**
|
|
483
|
-
* The singleton instance if this `Injectable` wraps a singleton assemblage.
|
|
484
|
-
*/
|
|
485
|
-
get singleton(): T | undefined;
|
|
486
|
-
/**
|
|
487
|
-
* Injectable assemblage's own injections defined in its decorator's definition.
|
|
488
|
-
*/
|
|
489
|
-
get injections(): Injection<unknown>[];
|
|
490
|
-
/**
|
|
491
|
-
* Injectable assemblage's own objects (e.g. instances) injections defined in its decorator's definition.
|
|
492
|
-
*/
|
|
493
|
-
get objects(): InstanceInjection<unknown>[];
|
|
494
|
-
/**
|
|
495
|
-
* Tags passed in assemblage's definition.
|
|
496
|
-
*/
|
|
497
|
-
get tags(): string[];
|
|
498
|
-
/**
|
|
499
|
-
* Global injections passed in assemblage's definition.
|
|
500
|
-
* These injections are available in all assemblages and can be used
|
|
501
|
-
* to provide global services or utilities.
|
|
502
|
-
*/
|
|
503
|
-
get globals(): Record<string, any> | undefined;
|
|
504
|
-
/**
|
|
505
|
-
* Event channels passed in assemblage's definition.
|
|
506
|
-
*/
|
|
507
|
-
get events(): string[];
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
/**
|
|
511
|
-
* A generic injection tuple.
|
|
512
|
-
*/
|
|
513
|
-
declare type Injection<T> = BaseInjection<T> | ConfiguredInjection<T> | ConcreteInjection<T> | ConcreteConfiguredInjection<T>;
|
|
514
|
-
|
|
515
|
-
/**
|
|
516
|
-
* Injectable binds an instance of a class to an identifier (abstract or concrete).
|
|
517
|
-
*/
|
|
518
|
-
declare type InstanceInjection<T> = Tuple<[Identifier<T> | string | symbol, T]>;
|
|
519
|
-
|
|
520
|
-
/**
|
|
521
|
-
* Check if a given class is an `Assemblage`.
|
|
522
|
-
*
|
|
523
|
-
* @param { Concrete<T> } target The class to test.
|
|
524
|
-
* @returns `true` if the class is an assemblage.
|
|
525
|
-
*/
|
|
526
|
-
export declare const isAssemblage: <T>(target: Concrete<T>) => boolean;
|
|
527
|
-
|
|
528
|
-
/**
|
|
529
|
-
* Describes a listener type as a function taking any number of arguments and returning `void`.
|
|
530
|
-
*/
|
|
531
|
-
export declare type Listener = (...args: any[]) => void | Promise<void>;
|
|
532
|
-
|
|
533
|
-
export declare class ListenerCollection implements AbstractListenerCollection {
|
|
534
|
-
/**
|
|
535
|
-
* Class is indexable by `EventChannel`.
|
|
536
|
-
*/
|
|
537
|
-
[key: string]: Listener[] | any;
|
|
538
|
-
/**
|
|
539
|
-
* Internal listeners `Object`.
|
|
540
|
-
*/
|
|
541
|
-
readonly collection: Record<EventChannel, Array<Listener>>;
|
|
542
|
-
constructor();
|
|
543
|
-
/**
|
|
544
|
-
* Clean up the collection by removing all listeners and channels
|
|
545
|
-
* and deleting listeners private property.
|
|
546
|
-
*/
|
|
547
|
-
dispose(): void;
|
|
548
|
-
/**
|
|
549
|
-
* Add a listener to the collection.
|
|
550
|
-
*
|
|
551
|
-
* @param { EventChannel } channel The channel to add the listener to.
|
|
552
|
-
* @param { Listener } listener The callback function to run when the event is emitted.
|
|
553
|
-
* @returns { ListenerCollection } This collection.
|
|
554
|
-
*/
|
|
555
|
-
add(channel: EventChannel, listener: Listener): ListenerCollection;
|
|
556
|
-
/**
|
|
557
|
-
* Add a listener to the collection.
|
|
558
|
-
*
|
|
559
|
-
* @param { Tuple<EventChannel, Listener> } tuple The channel and its listener in a tuple.
|
|
560
|
-
* @returns { ListenerCollection } This collection.
|
|
561
|
-
*/
|
|
562
|
-
add(tuple: Tuple<[EventChannel, Listener]>): ListenerCollection;
|
|
563
|
-
/**
|
|
564
|
-
* Removes a listener or all listeners for a given channel.
|
|
565
|
-
* If the channel or the provided listener does not exist, fails silently.
|
|
566
|
-
*
|
|
567
|
-
* @param { EventChannel } channel The channel the listener is listening to.
|
|
568
|
-
* @param { Listener } listener The listener to remove. If not provided, remove all listeners for given channel.
|
|
569
|
-
* @returns { ListenerCollection } This collection.
|
|
570
|
-
*/
|
|
571
|
-
remove(channel: string, listener?: Listener): ListenerCollection;
|
|
572
|
-
/**
|
|
573
|
-
* Checks if the collection includes a specific channel or listener.
|
|
574
|
-
*
|
|
575
|
-
* @param { EventChannel | Listener } value The channel or the listener to find in the collection.
|
|
576
|
-
* @returns { boolean } true if the collection includes this channel / this listener,
|
|
577
|
-
* false if not.
|
|
578
|
-
*/
|
|
579
|
-
has(value: EventChannel): boolean;
|
|
580
|
-
has(value: Listener): boolean;
|
|
581
|
-
/**
|
|
582
|
-
* Get a specific channel listeners array or a specific listener channels array.
|
|
583
|
-
*
|
|
584
|
-
* @param { EventChannel | Listener } value The channel or the listener to find in the collection.
|
|
585
|
-
* @returns { EventChannel[] | Listener[] } An array of channels or listeners.
|
|
586
|
-
*/
|
|
587
|
-
get(value: EventChannel): Listener[];
|
|
588
|
-
get(value: Listener): EventChannel[];
|
|
589
|
-
/**
|
|
590
|
-
* Clear the entire collction.
|
|
591
|
-
*
|
|
592
|
-
* @returns { ListenerCollection } This collection.
|
|
593
|
-
*/
|
|
594
|
-
clear(): ListenerCollection;
|
|
595
|
-
/**
|
|
596
|
-
* The listeners of this collection flatten in a single array.
|
|
597
|
-
*/
|
|
598
|
-
get listeners(): Listener[];
|
|
599
|
-
/**
|
|
600
|
-
* The listeners collection channels.
|
|
601
|
-
*/
|
|
602
|
-
get channels(): EventChannel[];
|
|
603
|
-
/**
|
|
604
|
-
* Returns the total listeners length.
|
|
605
|
-
*/
|
|
606
|
-
get length(): number;
|
|
607
|
-
/**
|
|
608
|
-
* Allows iterating over listeners in specific channel with 'for... of...' loop.
|
|
609
|
-
*
|
|
610
|
-
* @returns { Listener } A listener function.
|
|
611
|
-
*
|
|
612
|
-
* @example
|
|
613
|
-
* // Iterates listeners in a specific channel.
|
|
614
|
-
* for (const listener of myListenerCollection) {
|
|
615
|
-
* // Calls the registered listener.
|
|
616
|
-
* listener();
|
|
617
|
-
* }
|
|
618
|
-
*/
|
|
619
|
-
[Symbol.iterator](): Iterator<EventChannel>;
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
export declare interface ObjectLiteral {
|
|
623
|
-
[key: string]: any;
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
declare interface ParametersDecoratorsIndexes {
|
|
627
|
-
Context: number[];
|
|
628
|
-
Definition: number[];
|
|
629
|
-
Configuration: number[];
|
|
630
|
-
Dispose: number[];
|
|
631
|
-
Use: number[];
|
|
632
|
-
Global: number[];
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
/**
|
|
636
|
-
* Internal `Reflect` parameters decorators' indexes in constructor.
|
|
637
|
-
*/
|
|
638
|
-
export declare enum ReflectParamIndex {
|
|
639
|
-
Context = "assembler:context.param.index",
|
|
640
|
-
Dispose = "assembler:dispose.param.index",
|
|
641
|
-
Definition = "assemblage:definition.param.index",
|
|
642
|
-
Configuration = "assemblage:configuration.param.index",
|
|
643
|
-
Use = "assemblage:use.param.index",
|
|
644
|
-
Global = "assemblage:global.param.index"
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
/**
|
|
648
|
-
* Internal `Reflect` parameters decorators' values.
|
|
649
|
-
*/
|
|
650
|
-
export declare enum ReflectParamValue {
|
|
651
|
-
UseIdentifier = "assemblage:use.param.value",
|
|
652
|
-
GlobalIdentifier = "assemblage:global.param.value"
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
/**
|
|
656
|
-
* Injects an object passed with `string` or `symbol` identifier.
|
|
657
|
-
*/
|
|
658
|
-
export declare const Use: (identifier: string | symbol) => ParameterDecorator;
|
|
659
|
-
|
|
660
|
-
export { }
|
|
875
|
+
/**
|
|
876
|
+
* Dynamic record of parameter decorator indexes.
|
|
877
|
+
* Keys are decorator names (e.g., 'Context', 'Use', 'Global', etc.)
|
|
878
|
+
* Values are arrays of parameter indexes where the decorator is applied.
|
|
879
|
+
*/
|
|
880
|
+
declare interface ParametersDecoratorsIndexes {
|
|
881
|
+
[decoratorName: string]: number[];
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
declare interface TagResolver {
|
|
885
|
+
tagged(...tags: string[]): any[];
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
/**
|
|
889
|
+
* Injects an object passed with `string` or `symbol` identifier.
|
|
890
|
+
* @param identifier The identifier of the object to inject
|
|
891
|
+
* @returns A parameter decorator
|
|
892
|
+
*/
|
|
893
|
+
export declare const Use: (param: string | symbol) => ParameterDecorator;
|
|
894
|
+
|
|
895
|
+
export { }
|