assemblerjs 0.3.25 → 0.4.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.
- package/README.md +1 -1
- package/dist/index.d.ts +303 -197
- package/dist/index.js +1 -1
- package/dist/index.mjs +404 -395
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
A general purpose and zero-dependency [Dependency Injection](https://en.wikipedia.org/wiki/Dependency_injection) library for node and browser.
|
|
4
4
|
|
|
5
|
-
   
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
package/dist/index.d.ts
CHANGED
|
@@ -38,13 +38,16 @@ export declare abstract class AbstractAssemblage {
|
|
|
38
38
|
abstract whenReady?(): Promise<void>;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
/**
|
|
42
|
+
* `Assembler` abstraction.
|
|
43
|
+
*/
|
|
41
44
|
export declare abstract class AbstractAssembler extends AbstractEventManager {
|
|
42
45
|
abstract privateContext: AssemblerContext;
|
|
43
46
|
abstract publicContext: AssemblerContext;
|
|
44
47
|
abstract size: number;
|
|
45
48
|
abstract register<T>(injection: Injection<T>, instance?: boolean): Injectable<T>;
|
|
46
49
|
abstract use<T>(identifier: string | Symbol, object: T): T;
|
|
47
|
-
abstract
|
|
50
|
+
abstract prepareInitHook<T = AbstractAssemblage>(instance: T): unknown[];
|
|
48
51
|
abstract has<T>(identifier: Identifier<T>): boolean;
|
|
49
52
|
abstract require<T>(identifier: Identifier<T>): T;
|
|
50
53
|
abstract tagged(...tags: string[]): any[];
|
|
@@ -62,6 +65,25 @@ export declare abstract class AbstractEventManager {
|
|
|
62
65
|
abstract emit(channel: string, ...args: any[]): AbstractEventManager;
|
|
63
66
|
}
|
|
64
67
|
|
|
68
|
+
declare abstract class AbstractInjectable<T> {
|
|
69
|
+
abstract readonly privateContext: AssemblerPrivateContext;
|
|
70
|
+
abstract readonly publicContext: AssemblerContext;
|
|
71
|
+
abstract readonly identifier: Identifier<T> | string | Symbol;
|
|
72
|
+
abstract readonly concrete: Concrete<T>;
|
|
73
|
+
abstract readonly configuration: Record<string, any>;
|
|
74
|
+
abstract dependencies: (Identifier<unknown> | any)[];
|
|
75
|
+
abstract definition: AssemblageDefinition;
|
|
76
|
+
abstract isSingleton: boolean;
|
|
77
|
+
abstract singleton: T | undefined;
|
|
78
|
+
abstract injections: Injection<unknown>[];
|
|
79
|
+
abstract objects: InstanceInjection<unknown>[];
|
|
80
|
+
abstract tags: string[];
|
|
81
|
+
abstract events: string[];
|
|
82
|
+
static of<TNew>(buildable: Buildable<TNew>, privateContext: AssemblerPrivateContext, publicContext: AssemblerContext): void;
|
|
83
|
+
abstract dispose(): void;
|
|
84
|
+
abstract build(): T;
|
|
85
|
+
}
|
|
86
|
+
|
|
65
87
|
/**
|
|
66
88
|
* Generic `Array` items.
|
|
67
89
|
*/
|
|
@@ -72,6 +94,12 @@ declare type ArrayItems<T extends Array<any>> = T extends Array<infer TItems> ?
|
|
|
72
94
|
*/
|
|
73
95
|
declare type ArrayLengthMutationKeys = 'splice' | 'push' | 'pop' | 'shift' | 'unshift' | number;
|
|
74
96
|
|
|
97
|
+
/**
|
|
98
|
+
* Mark a class as `Assemblage` and cache its definition.
|
|
99
|
+
*
|
|
100
|
+
* @param { AssemblageDefinition } definition Definition of the assemblage that provides injections, etc.
|
|
101
|
+
* @returns { ClassDecorator } The decorated class.
|
|
102
|
+
*/
|
|
75
103
|
export declare const Assemblage: (definition?: AssemblageDefinition) => ClassDecorator;
|
|
76
104
|
|
|
77
105
|
declare interface AssemblageDefinition {
|
|
@@ -83,7 +111,17 @@ declare interface AssemblageDefinition {
|
|
|
83
111
|
metadata?: Record<string, any>;
|
|
84
112
|
}
|
|
85
113
|
|
|
114
|
+
/**
|
|
115
|
+
* `assembler.js` dependency injection container and handler.
|
|
116
|
+
*/
|
|
86
117
|
export declare class Assembler extends EventManager implements AbstractAssembler {
|
|
118
|
+
/**
|
|
119
|
+
* Build the dependencies tree from an assemblage as entry point.
|
|
120
|
+
*
|
|
121
|
+
* @param { Concrete<T> } entry An assemblage concrete class.
|
|
122
|
+
* @returns { T } An instance of `entry` marked as singleton.
|
|
123
|
+
*/
|
|
124
|
+
static build<T>(entry: Concrete<T>): T;
|
|
87
125
|
protected injectables: Map<Identifier<unknown>, Injectable<unknown>>;
|
|
88
126
|
protected objects: Map<string | Symbol, unknown>;
|
|
89
127
|
private initCache;
|
|
@@ -95,14 +133,21 @@ export declare class Assembler extends EventManager implements AbstractAssembler
|
|
|
95
133
|
* Context passed to assemblages.
|
|
96
134
|
*/
|
|
97
135
|
readonly publicContext: AssemblerContext;
|
|
98
|
-
static build<T>(entry: Concrete<T>): T;
|
|
99
136
|
private constructor();
|
|
137
|
+
/**
|
|
138
|
+
* Dispose assembler and all its injectables.
|
|
139
|
+
* Note that injectables' instances will be disposed only if
|
|
140
|
+
* the are singletons.
|
|
141
|
+
*
|
|
142
|
+
* Transient instances must be disposed by the user.
|
|
143
|
+
*/
|
|
100
144
|
dispose(): void;
|
|
101
145
|
/**
|
|
102
146
|
* Recursively register an `Injection` tuple and its inner injected dependencies.
|
|
103
147
|
*
|
|
104
148
|
* @param { Injection<T> } injection The injection tuple to register.
|
|
105
|
-
* @param { boolean | undefined } instance
|
|
149
|
+
* @param { boolean | undefined } instance Set to `true` if the injection binds an instance
|
|
150
|
+
* to an identifier (defaults to `false`).
|
|
106
151
|
* @returns { Injectable<T> } An injectable of type `T`.
|
|
107
152
|
*/
|
|
108
153
|
register<T>(injection: Injection<T>, instance?: boolean): Injectable<T>;
|
|
@@ -112,238 +157,299 @@ export declare class Assembler extends EventManager implements AbstractAssembler
|
|
|
112
157
|
* @param { string | symbol } identifier The identifier to register.
|
|
113
158
|
* @param { T } object The object to use with the identifier.
|
|
114
159
|
* @returns { T } The object.
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```typescript
|
|
163
|
+
* import express from 'express';
|
|
164
|
+
*
|
|
165
|
+
* @Assemblage({
|
|
166
|
+
* use: [
|
|
167
|
+
* ['express', express]
|
|
168
|
+
* ]
|
|
169
|
+
* });
|
|
170
|
+
* class MyAssemblage implements AbstractAssemblage {
|
|
171
|
+
* constructor(@Use('express) private express) {
|
|
172
|
+
* // Use express.
|
|
173
|
+
* }
|
|
174
|
+
* }
|
|
175
|
+
* ```
|
|
115
176
|
*/
|
|
116
177
|
use<T>(identifier: string | Symbol, object: T): T;
|
|
117
|
-
prepareInit<T = AbstractAssemblage>(instance: T): unknown[];
|
|
118
178
|
/**
|
|
119
|
-
*
|
|
179
|
+
* Cache an instaance to be inited with `onInit` hook
|
|
180
|
+
* when the dependency tree will be fully resolved.
|
|
120
181
|
*
|
|
121
|
-
* @param {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
182
|
+
* @param { T = AbstractAssemblage } instance The built instance.
|
|
183
|
+
* @returns { unknown[] } The instances to be inited as this point.
|
|
184
|
+
*/
|
|
185
|
+
prepareInitHook<T = AbstractAssemblage>(instance: T): unknown[];
|
|
186
|
+
/**
|
|
187
|
+
* Check if `Assembler` has given identifier registered.
|
|
188
|
+
*
|
|
189
|
+
* @param { Identifier<T> | string | symbol } identifier An abstract or concrete class,
|
|
190
|
+
* or a string or Symbol as identifier.
|
|
191
|
+
* @returns { boolean } `true` if dependency has been registered.
|
|
192
|
+
*/
|
|
193
|
+
has<T>(identifier: Identifier<T> | string | Symbol): boolean;
|
|
194
|
+
/**
|
|
195
|
+
* Get or instantiate an assemblage for given identifier.
|
|
196
|
+
*
|
|
197
|
+
* @param { Identifier<T> | string | symbol } identifier The identifier to get instance from.
|
|
198
|
+
* @returns { T } An instance of Concrete<T>.
|
|
199
|
+
*/
|
|
200
|
+
require<T>(identifier: Identifier<T> | string | Symbol): T;
|
|
201
|
+
/**
|
|
202
|
+
* Require dependencies by tag passed in assemblage's definition.
|
|
203
|
+
*
|
|
204
|
+
* @param { string[] } tags The tags to get dependencies.
|
|
205
|
+
* @returns { unknown[] } An array of instances for the given tags. If registered
|
|
206
|
+
* identifier is not marked as 'singleton', will resolve in a new instance.
|
|
207
|
+
*/
|
|
208
|
+
tagged(...tags: string[]): unknown[];
|
|
209
|
+
/**
|
|
210
|
+
* Size of the assembler: number of registered dependencies.
|
|
211
|
+
*/
|
|
212
|
+
get size(): number;
|
|
213
|
+
}
|
|
214
|
+
|
|
126
215
|
/**
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
* @param { Identifier<T> | string | symbol } identifier The identifier to get instance from.
|
|
130
|
-
* @returns { T } An instance of Concrete<T>.
|
|
216
|
+
* Assembler public context that provide
|
|
217
|
+
* access to some useful `Assembler` methods.
|
|
131
218
|
*/
|
|
132
|
-
|
|
219
|
+
export declare interface AssemblerContext {
|
|
220
|
+
has: AbstractAssembler['has'];
|
|
221
|
+
require: AbstractAssembler['require'];
|
|
222
|
+
tagged: AbstractAssembler['tagged'];
|
|
223
|
+
on: AbstractAssembler['on'];
|
|
224
|
+
once: AbstractAssembler['once'];
|
|
225
|
+
off: AbstractAssembler['off'];
|
|
226
|
+
events: AbstractAssembler['channels'];
|
|
227
|
+
}
|
|
228
|
+
|
|
133
229
|
/**
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
* @param { string | string[] } tags The tag(s) to get dependencies.
|
|
137
|
-
* @returns { unknown[] } An array of instances for the given tags. If registered
|
|
138
|
-
* identifier is not marked as 'singleton', will resolve in a new instance.
|
|
230
|
+
* `Assembler` dispose method type.
|
|
139
231
|
*/
|
|
140
|
-
|
|
232
|
+
export declare type AssemblerDispose = AbstractAssembler['dispose'];
|
|
233
|
+
|
|
141
234
|
/**
|
|
142
|
-
*
|
|
235
|
+
* Assembler private context that provide
|
|
236
|
+
* access to some `Assembler` methods
|
|
237
|
+
* used internally.
|
|
143
238
|
*/
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
off: AbstractAssembler['off'];
|
|
154
|
-
events: AbstractAssembler['channels'];
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
export declare type AssemblerDispose = AbstractAssembler['dispose'];
|
|
239
|
+
declare interface AssemblerPrivateContext extends AssemblerContext {
|
|
240
|
+
register: AbstractAssembler['register'];
|
|
241
|
+
use: AbstractAssembler['use'];
|
|
242
|
+
dispose: AssemblerDispose;
|
|
243
|
+
prepareInitHook: AbstractAssembler['prepareInitHook'];
|
|
244
|
+
emit: AbstractAssembler['emit'];
|
|
245
|
+
addChannels: AbstractAssembler['addChannels'];
|
|
246
|
+
removeChannels: AbstractAssembler['removeChannels'];
|
|
247
|
+
}
|
|
158
248
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Recursively check if a property is defined and truthy to call an async method.
|
|
171
|
-
*
|
|
172
|
-
* @param { string } property The name of the class proprty to wait for.
|
|
173
|
-
* @param { number | undefined } interval The interval in milliseconds at which the value is checked (defaults to 25 milliseconds).
|
|
174
|
-
* @returns { Promise<void> } A promise that calls the original method when resolving.
|
|
175
|
-
*/
|
|
176
|
-
export declare const Await: (property: string, interval?: number) => MethodDecorator;
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Injectable binds a concrete class to an abstract class as identifier without configuration.
|
|
180
|
-
*/
|
|
181
|
-
declare type BaseInjection<T> = Tuple<[Abstract<T>, Concrete<T>]>;
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Describes a buildable object.
|
|
185
|
-
*/
|
|
186
|
-
declare interface Buildable<T> {
|
|
187
|
-
identifier: Identifier<T>;
|
|
188
|
-
concrete: Concrete<T>;
|
|
189
|
-
instance?: T;
|
|
190
|
-
configuration: Record<string, any>;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* A concrete (newable) class.
|
|
195
|
-
*/
|
|
196
|
-
declare interface Concrete<T> extends Function {
|
|
197
|
-
new (...args: any[]): T;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* Injection binds a concrete class to itself as identifier
|
|
202
|
-
* and provides a configuration object that will be passed to context.
|
|
203
|
-
*/
|
|
204
|
-
declare type ConcreteConfiguredInjection<T> = Tuple<[
|
|
205
|
-
Concrete<T>,
|
|
206
|
-
Record<string, any>
|
|
207
|
-
]>;
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* Injectable binds a conrete class to itself as identifier.
|
|
211
|
-
*/
|
|
212
|
-
declare type ConcreteInjection<T> = Tuple<[Concrete<T>]>;
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Injects the assemblage's configuration object.
|
|
216
|
-
*/
|
|
217
|
-
export declare const Configuration: () => ParameterDecorator;
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* Injectable binds a concrete class to an abstract class as identifier
|
|
221
|
-
* and provides a configuration object that will be passed to context.
|
|
222
|
-
*/
|
|
223
|
-
declare type ConfiguredInjection<T> = Tuple<[
|
|
224
|
-
Abstract<T>,
|
|
225
|
-
Concrete<T>,
|
|
226
|
-
Record<string, any>
|
|
227
|
-
]>;
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* Injects the Assembler's context.
|
|
231
|
-
*/
|
|
232
|
-
export declare const Context: () => ParameterDecorator;
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* Injects the assemblage's definition object.
|
|
236
|
-
*/
|
|
237
|
-
export declare const Definition: () => ParameterDecorator;
|
|
249
|
+
/**
|
|
250
|
+
* Check at given interval if a property is defined and truthy to call an async method.
|
|
251
|
+
*
|
|
252
|
+
* @param { string } property The name of the class proprty to wait for.
|
|
253
|
+
* @param { number | undefined } interval The interval in milliseconds at which the value is checked (defaults to 25 milliseconds).
|
|
254
|
+
* @returns { Promise<void> } A promise that calls the original method when resolving.
|
|
255
|
+
*/
|
|
256
|
+
export declare const Await: (property: string, interval?: number) => MethodDecorator;
|
|
238
257
|
|
|
239
|
-
/**
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
258
|
+
/**
|
|
259
|
+
* Injectable binds a concrete class to an abstract class as identifier without configuration.
|
|
260
|
+
*/
|
|
261
|
+
declare type BaseInjection<T> = Tuple<[Abstract<T>, Concrete<T>]>;
|
|
243
262
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
once(channel: string, callback: Listener): EventManager;
|
|
254
|
-
off(channel: string, callback?: Listener): EventManager;
|
|
255
|
-
emit(channel: string, ...args: any[]): EventManager;
|
|
256
|
-
private run;
|
|
257
|
-
private cleanChannel;
|
|
258
|
-
}
|
|
263
|
+
/**
|
|
264
|
+
* Describes a buildable object.
|
|
265
|
+
*/
|
|
266
|
+
declare interface Buildable<T> {
|
|
267
|
+
identifier: Identifier<T>;
|
|
268
|
+
concrete: Concrete<T>;
|
|
269
|
+
instance?: T;
|
|
270
|
+
configuration: Record<string, any>;
|
|
271
|
+
}
|
|
259
272
|
|
|
260
|
-
/**
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
declare
|
|
273
|
+
/**
|
|
274
|
+
* A concrete (newable) class.
|
|
275
|
+
*/
|
|
276
|
+
declare interface Concrete<T> extends Function {
|
|
277
|
+
new (...args: any[]): T;
|
|
278
|
+
}
|
|
264
279
|
|
|
265
|
-
declare class Injectable<T> {
|
|
266
|
-
readonly privateContext: AssemblerPrivateContext;
|
|
267
|
-
readonly publicContext: AssemblerContext;
|
|
268
|
-
readonly identifier: Identifier<T> | string | Symbol;
|
|
269
|
-
readonly concrete: Concrete<T>;
|
|
270
|
-
readonly configuration: Record<string, any>;
|
|
271
|
-
private dependenciesIds;
|
|
272
|
-
private singletonInstance;
|
|
273
|
-
static of<TNew>(buildable: Buildable<TNew>, privateContext: AssemblerPrivateContext, publicContext: AssemblerContext): Injectable<TNew>;
|
|
274
|
-
private constructor();
|
|
275
280
|
/**
|
|
276
|
-
*
|
|
277
|
-
* and
|
|
281
|
+
* Injection binds a concrete class to itself as identifier
|
|
282
|
+
* and provides a configuration object that will be passed to context.
|
|
278
283
|
*/
|
|
279
|
-
|
|
284
|
+
declare type ConcreteConfiguredInjection<T> = Tuple<[
|
|
285
|
+
Concrete<T>,
|
|
286
|
+
Record<string, any>
|
|
287
|
+
]>;
|
|
288
|
+
|
|
280
289
|
/**
|
|
281
|
-
*
|
|
282
|
-
*
|
|
283
|
-
* @returns { T } The assemblage instance.
|
|
290
|
+
* Injectable binds a conrete class to itself as identifier.
|
|
284
291
|
*/
|
|
285
|
-
|
|
292
|
+
declare type ConcreteInjection<T> = Tuple<[Concrete<T>]>;
|
|
293
|
+
|
|
286
294
|
/**
|
|
287
|
-
*
|
|
295
|
+
* Injects the assemblage's configuration object.
|
|
288
296
|
*/
|
|
289
|
-
|
|
297
|
+
export declare const Configuration: () => ParameterDecorator;
|
|
298
|
+
|
|
290
299
|
/**
|
|
291
|
-
*
|
|
300
|
+
* Injectable binds a concrete class to an abstract class as identifier
|
|
301
|
+
* and provides a configuration object that will be passed to context.
|
|
292
302
|
*/
|
|
293
|
-
|
|
303
|
+
declare type ConfiguredInjection<T> = Tuple<[
|
|
304
|
+
Abstract<T>,
|
|
305
|
+
Concrete<T>,
|
|
306
|
+
Record<string, any>
|
|
307
|
+
]>;
|
|
308
|
+
|
|
294
309
|
/**
|
|
295
|
-
*
|
|
310
|
+
* Injects the Assembler's context.
|
|
296
311
|
*/
|
|
297
|
-
|
|
312
|
+
export declare const Context: () => ParameterDecorator;
|
|
313
|
+
|
|
298
314
|
/**
|
|
299
|
-
*
|
|
315
|
+
* Injects the assemblage's definition object.
|
|
300
316
|
*/
|
|
301
|
-
|
|
317
|
+
export declare const Definition: () => ParameterDecorator;
|
|
318
|
+
|
|
302
319
|
/**
|
|
303
|
-
*
|
|
320
|
+
* Injects the Assembler's 'dispose' method.
|
|
304
321
|
*/
|
|
305
|
-
|
|
322
|
+
export declare const Dispose: () => ParameterDecorator;
|
|
323
|
+
|
|
324
|
+
export declare class EventManager implements AbstractEventManager {
|
|
325
|
+
private readonly listeners;
|
|
326
|
+
private readonly onceListeners;
|
|
327
|
+
readonly channels: Set<string>;
|
|
328
|
+
constructor(...allowedChannels: string[]);
|
|
329
|
+
dispose(): void;
|
|
330
|
+
addChannels(...channels: string[]): EventManager;
|
|
331
|
+
removeChannels(...channels: string[]): EventManager;
|
|
332
|
+
on(channel: string, callback: Listener): EventManager;
|
|
333
|
+
once(channel: string, callback: Listener): EventManager;
|
|
334
|
+
off(channel: string, callback?: Listener): EventManager;
|
|
335
|
+
emit(channel: string, ...args: any[]): EventManager;
|
|
336
|
+
private run;
|
|
337
|
+
private cleanChannel;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
export declare const getDecoratedParametersIndexes: <T>(target: Concrete<T>) => {
|
|
341
|
+
context: number[];
|
|
342
|
+
definition: number[];
|
|
343
|
+
configuration: number[];
|
|
344
|
+
dispose: number[];
|
|
345
|
+
use: number[];
|
|
346
|
+
};
|
|
347
|
+
|
|
306
348
|
/**
|
|
307
|
-
*
|
|
349
|
+
* An identifier can be an abstract or a concrete class.
|
|
308
350
|
*/
|
|
309
|
-
|
|
351
|
+
declare type Identifier<T> = Concrete<T> | Abstract<T>;
|
|
352
|
+
|
|
353
|
+
declare class Injectable<T> implements AbstractInjectable<T> {
|
|
354
|
+
readonly privateContext: AssemblerPrivateContext;
|
|
355
|
+
readonly publicContext: AssemblerContext;
|
|
356
|
+
readonly identifier: Identifier<T> | string | Symbol;
|
|
357
|
+
readonly concrete: Concrete<T>;
|
|
358
|
+
readonly configuration: Record<string, any>;
|
|
359
|
+
private dependenciesIds;
|
|
360
|
+
private singletonInstance;
|
|
361
|
+
static of<TNew>(buildable: Buildable<TNew>, privateContext: AssemblerPrivateContext, publicContext: AssemblerContext): Injectable<TNew>;
|
|
362
|
+
private constructor();
|
|
363
|
+
/**
|
|
364
|
+
* Dispose the injectable by deleting its singleton if exists
|
|
365
|
+
* and deleting all injectable's properties.
|
|
366
|
+
*/
|
|
367
|
+
dispose(): void;
|
|
368
|
+
/**
|
|
369
|
+
* Instantiate the assemblage or get its singleton instance.
|
|
370
|
+
*
|
|
371
|
+
* @returns { T } The assemblage instance.
|
|
372
|
+
*/
|
|
373
|
+
build(): T;
|
|
374
|
+
/**
|
|
375
|
+
* Injectable assemblage's dependencies passed as 'constructor' parameters.
|
|
376
|
+
*/
|
|
377
|
+
get dependencies(): (Identifier<unknown> | any)[];
|
|
378
|
+
/**
|
|
379
|
+
* Metadatas passed in assemblage's definition or in its parent definition.
|
|
380
|
+
*/
|
|
381
|
+
get definition(): AssemblageDefinition;
|
|
382
|
+
/**
|
|
383
|
+
* `true` if assemblage is a singleton.
|
|
384
|
+
*/
|
|
385
|
+
get isSingleton(): boolean;
|
|
386
|
+
/**
|
|
387
|
+
* The singleton instance if this `Injectable` wraps a singleton assemblage.
|
|
388
|
+
*/
|
|
389
|
+
get singleton(): T | undefined;
|
|
390
|
+
/**
|
|
391
|
+
* Injectable assemblage's own injections defined in its decorator's definition.
|
|
392
|
+
*/
|
|
393
|
+
get injections(): Injection<unknown>[];
|
|
394
|
+
/**
|
|
395
|
+
* Injectable assemblage's own objects (e.g. instances) injections defined in its decorator's definition.
|
|
396
|
+
*/
|
|
397
|
+
get objects(): InstanceInjection<unknown>[];
|
|
398
|
+
/**
|
|
399
|
+
* Tags passed in assemblage's definition.
|
|
400
|
+
*/
|
|
401
|
+
get tags(): string[];
|
|
402
|
+
/**
|
|
403
|
+
* Event channels passed in assemblage's definition.
|
|
404
|
+
*/
|
|
405
|
+
get events(): string[];
|
|
406
|
+
}
|
|
407
|
+
|
|
310
408
|
/**
|
|
311
|
-
*
|
|
409
|
+
* A generic injection tuple.
|
|
312
410
|
*/
|
|
313
|
-
|
|
411
|
+
declare type Injection<T> = BaseInjection<T> | ConfiguredInjection<T> | ConcreteInjection<T> | ConcreteConfiguredInjection<T>;
|
|
412
|
+
|
|
314
413
|
/**
|
|
315
|
-
*
|
|
414
|
+
* Injectable binds an instance of a class to an identifier (abstract or concrete).
|
|
316
415
|
*/
|
|
317
|
-
|
|
318
|
-
}
|
|
416
|
+
declare type InstanceInjection<T> = Tuple<[Identifier<T> | string | Symbol, T]>;
|
|
319
417
|
|
|
320
|
-
/**
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
declare type
|
|
418
|
+
/**
|
|
419
|
+
* Describes a listener type as a function taking any number of arguments and returning `void`.
|
|
420
|
+
*/
|
|
421
|
+
declare type Listener = (...args: any[]) => void | Promise<void>;
|
|
324
422
|
|
|
325
|
-
/**
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
declare
|
|
423
|
+
/**
|
|
424
|
+
* Internal `Reflect` parameters decorators' indexes in constructor.
|
|
425
|
+
*/
|
|
426
|
+
export declare enum ReflectParamIndex {
|
|
427
|
+
Context = "assembler:context.param.index",
|
|
428
|
+
Dispose = "assembler:dispose.param.index",
|
|
429
|
+
Definition = "assemblage:definition.param.index",
|
|
430
|
+
Configuration = "assemblage:configuration.param.index",
|
|
431
|
+
Use = "assemblage:use.param.index"
|
|
432
|
+
}
|
|
329
433
|
|
|
330
|
-
/**
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
declare
|
|
434
|
+
/**
|
|
435
|
+
* Internal `Reflect` parameters decorators' values.
|
|
436
|
+
*/
|
|
437
|
+
export declare enum ReflectParamValue {
|
|
438
|
+
UseIdentifier = "assemblage:use.param.value"
|
|
439
|
+
}
|
|
334
440
|
|
|
335
|
-
/**
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
declare type Tuple<T extends any[]> = Pick<T, Exclude<keyof T, ArrayLengthMutationKeys>> & {
|
|
341
|
-
|
|
342
|
-
};
|
|
441
|
+
/**
|
|
442
|
+
* An array of fixed length typed values.
|
|
443
|
+
*
|
|
444
|
+
* @see https://stackoverflow.com/a/59906630/1060921
|
|
445
|
+
*/
|
|
446
|
+
declare type Tuple<T extends any[]> = Pick<T, Exclude<keyof T, ArrayLengthMutationKeys>> & {
|
|
447
|
+
[Symbol.iterator]: () => IterableIterator<ArrayItems<T>>;
|
|
448
|
+
};
|
|
343
449
|
|
|
344
|
-
/**
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
export declare const Use: (identifier: string | Symbol) => ParameterDecorator;
|
|
450
|
+
/**
|
|
451
|
+
* Injects an object passed with `string` or `Symbol` identifier.
|
|
452
|
+
*/
|
|
453
|
+
export declare const Use: (identifier: string | Symbol) => ParameterDecorator;
|
|
348
454
|
|
|
349
|
-
export { }
|
|
455
|
+
export { }
|