@vercube/di 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +426 -0
- package/dist/index.mjs +17 -17
- package/package.json +3 -10
- package/dist/Common/BaseDecorators.d.ts +0 -31
- package/dist/Decorators/Destroy.d.ts +0 -17
- package/dist/Decorators/Init.d.ts +0 -6
- package/dist/Decorators/Inject.d.ts +0 -7
- package/dist/Decorators/InjectOptional.d.ts +0 -7
- package/dist/Domain/Container.d.ts +0 -154
- package/dist/Domain/ContainerEvents.d.ts +0 -18
- package/dist/Domain/Engine.d.ts +0 -55
- package/dist/Types/IOCTypes.d.ts +0 -48
- package/dist/Utils/Utils.d.ts +0 -79
- package/dist/index.cjs +0 -711
- package/dist/index.d.ts +0 -8
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
//#region src/Common/BaseDecorators.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* This is base class for all property decorators used in application. Decorator class must extend this one.
|
|
4
|
+
* This class instance is created using IOC container so you can @Inject() things here.
|
|
5
|
+
*/
|
|
6
|
+
declare abstract class BaseDecorator<T = any, P = any> {
|
|
7
|
+
/** Holds options object that is passed as 2nd argument in createDecorator() factory */
|
|
8
|
+
options: T;
|
|
9
|
+
/** Holds class instance that is decorated */
|
|
10
|
+
instance: any;
|
|
11
|
+
/** Holds class prototype that is decorated */
|
|
12
|
+
prototype: P;
|
|
13
|
+
/** Holds property name that was decorated */
|
|
14
|
+
propertyName: string;
|
|
15
|
+
/** Holds property descriptor that was decorated */
|
|
16
|
+
descriptor: PropertyDescriptor;
|
|
17
|
+
/** Holds property index if decorators if for Method Property */
|
|
18
|
+
propertyIndex: number;
|
|
19
|
+
/**
|
|
20
|
+
* This method is called when decorator is created and ready to be used.
|
|
21
|
+
*/
|
|
22
|
+
created(): void;
|
|
23
|
+
/**
|
|
24
|
+
* This method is called when decorator is destroyed for cleanup tasks (like unregistering listeners, clearing timers).
|
|
25
|
+
* For standard services it is called at the end of SSR requests and for Vue components it is called when component is
|
|
26
|
+
* destroyed.
|
|
27
|
+
*/
|
|
28
|
+
destroyed(): void;
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/Domain/ContainerEvents.d.ts
|
|
32
|
+
type OnExpandedEvent = (serviceKeys: IOC.ServiceKey[]) => void;
|
|
33
|
+
/**
|
|
34
|
+
* This class allows for container to listen on various IOC events.
|
|
35
|
+
*/
|
|
36
|
+
declare class ContainerEvents {
|
|
37
|
+
private fOnExpanded;
|
|
38
|
+
/**
|
|
39
|
+
* Registers to container "onExpanded" event.
|
|
40
|
+
* @param handler event handler
|
|
41
|
+
*/
|
|
42
|
+
onExpanded(handler: OnExpandedEvent): void;
|
|
43
|
+
/**
|
|
44
|
+
* Calls on expanded event.
|
|
45
|
+
* @param serviceKeys key of service we have installed
|
|
46
|
+
*/
|
|
47
|
+
callOnExpanded(serviceKeys: IOC.ServiceKey[]): void;
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/Domain/Container.d.ts
|
|
51
|
+
/**
|
|
52
|
+
* This is new implementation of IOC Container. It mimics Inversify.js container a little bit but its
|
|
53
|
+
* simpler and (probably) more performant on larger scales.
|
|
54
|
+
*/
|
|
55
|
+
declare class Container {
|
|
56
|
+
protected fLocked: boolean;
|
|
57
|
+
protected fDefaultParams: IOC.ContainerParams;
|
|
58
|
+
protected fServices: Map<IOC.ServiceKey, IOC.ServiceDef>;
|
|
59
|
+
protected fNewQueue: Map<IOC.ServiceKey, IOC.ServiceDef>;
|
|
60
|
+
protected fSingletonInstances: Map<IOC.ServiceKey, IOC.Instance>;
|
|
61
|
+
protected fInjectMethod: IOC.InjectMethod;
|
|
62
|
+
protected fContainerEvents: ContainerEvents;
|
|
63
|
+
/**
|
|
64
|
+
* Constructor for container.
|
|
65
|
+
* @param params initial params for container
|
|
66
|
+
*/
|
|
67
|
+
constructor(params?: Partial<IOC.ContainerParams>);
|
|
68
|
+
/**
|
|
69
|
+
* Returns array of all service keys. This basically returns keys from all .bindXXX calls.
|
|
70
|
+
* @returns {Array} array of service keys
|
|
71
|
+
*/
|
|
72
|
+
get servicesKeys(): IOC.ServiceKey[];
|
|
73
|
+
/**
|
|
74
|
+
* Returns events handler.
|
|
75
|
+
*/
|
|
76
|
+
get events(): ContainerEvents;
|
|
77
|
+
/**
|
|
78
|
+
* Binds particular key to container in singleton scope. Multiple queries/injects of this
|
|
79
|
+
* service will always return the same instance.
|
|
80
|
+
*
|
|
81
|
+
* @param key key of service, preferably class or abstract class
|
|
82
|
+
* @param value implementation
|
|
83
|
+
*/
|
|
84
|
+
bind<T>(key: IOC.ServiceKey<T>, value?: IOC.ServiceValue<T>): void;
|
|
85
|
+
/**
|
|
86
|
+
* Binds particular key to container in transient scope. Every query/@Inject of this service
|
|
87
|
+
* will have totally brand-new instance of class.
|
|
88
|
+
* @param key key of service, preferably class or abstract class
|
|
89
|
+
* @param value implementation
|
|
90
|
+
*/
|
|
91
|
+
bindTransient<T>(key: IOC.ServiceKey<T>, value?: IOC.ServiceValue<T>): void;
|
|
92
|
+
/**
|
|
93
|
+
* Binds particular key class to an existing class instance. If you use this method,
|
|
94
|
+
* class wont be instantiated automatically. The common use case is to
|
|
95
|
+
* share single class instance between two or more containers.
|
|
96
|
+
*
|
|
97
|
+
* @param key key of service, preferably class or abstract class
|
|
98
|
+
* @param value instance of class to be used as resolution
|
|
99
|
+
*/
|
|
100
|
+
bindInstance<T>(key: IOC.ServiceKey<T>, value: T): void;
|
|
101
|
+
/**
|
|
102
|
+
* Binds mocked instance to a particular service ID. Its designed to be used in unit tests, where you can quickly
|
|
103
|
+
* replace real IOC implementation with a partial stub. Please note, you are responsible to provide enough data
|
|
104
|
+
* for test to pass, TypeScript wont check it.
|
|
105
|
+
*
|
|
106
|
+
* Example:
|
|
107
|
+
*
|
|
108
|
+
* container.bind(HttpServer, {
|
|
109
|
+
* listen: jest.fn(),
|
|
110
|
+
* });
|
|
111
|
+
*
|
|
112
|
+
* @param key service to be replaced
|
|
113
|
+
* @param mockInstance mock instance
|
|
114
|
+
*/
|
|
115
|
+
bindMock<T>(key: IOC.ServiceKey<T>, mockInstance: Partial<T>): void;
|
|
116
|
+
/**
|
|
117
|
+
* Returns implementation for a particular key class. This is the same as @Inject,
|
|
118
|
+
* but triggered programitically.
|
|
119
|
+
* @param key key used in .bind() function to bind key class to implementation class
|
|
120
|
+
* @returns service for identifier
|
|
121
|
+
*/
|
|
122
|
+
get<T>(key: IOC.ServiceKey<T>): T;
|
|
123
|
+
/**
|
|
124
|
+
* Returns implementation for a particular key class. This is the same as @Inject,
|
|
125
|
+
* but triggered programitically.
|
|
126
|
+
* @param key key used in .bind() function to bind key class to implementation class
|
|
127
|
+
* @returns service for identifier
|
|
128
|
+
*/
|
|
129
|
+
getOptional<T>(key: IOC.ServiceKey<T>): T | null;
|
|
130
|
+
/**
|
|
131
|
+
* Uses the container provider to register multiple things in IOC container at once.
|
|
132
|
+
* @param provider provider that will register new services into IOC container
|
|
133
|
+
*/
|
|
134
|
+
use(provider: IOC.ProviderFunc): void;
|
|
135
|
+
/**
|
|
136
|
+
* Expands container during runtime, adding new services to it.
|
|
137
|
+
* @param providers functor that is used to expand the container
|
|
138
|
+
* @param flush whether container should be flushed now or not
|
|
139
|
+
*/
|
|
140
|
+
expand(providers: IOC.ProviderFunc | IOC.ProviderFunc[], flush?: boolean): void;
|
|
141
|
+
/**
|
|
142
|
+
* Creates instance of particular class using, respecting all @Injects inside created class.
|
|
143
|
+
* @param classType type of class to instantiate
|
|
144
|
+
* @param method (optional) inject method
|
|
145
|
+
* @returns new class instance with dependencies
|
|
146
|
+
*/
|
|
147
|
+
resolve<T>(classType: IOC.Newable<T>, method?: IOC.InjectMethod): T;
|
|
148
|
+
/**
|
|
149
|
+
* Returns all IOC services registered in container.
|
|
150
|
+
* @returns array with all registered services
|
|
151
|
+
*/
|
|
152
|
+
getAllServices(): IOC.Instance[];
|
|
153
|
+
/**
|
|
154
|
+
* Unlocks the container, allowing things to be retrieved and used.
|
|
155
|
+
*/
|
|
156
|
+
unlock(): void;
|
|
157
|
+
/**
|
|
158
|
+
* Locks the container, disabling to add new services here.
|
|
159
|
+
*/
|
|
160
|
+
lock(): void;
|
|
161
|
+
/**
|
|
162
|
+
* Flushes new services queue, registering them into container.
|
|
163
|
+
*/
|
|
164
|
+
flushQueue(): void;
|
|
165
|
+
/**
|
|
166
|
+
* Internally retrieve dependency from container.
|
|
167
|
+
* @param key key to get
|
|
168
|
+
* @param parent parent (for debugging purposes)
|
|
169
|
+
* @returns queried instance
|
|
170
|
+
*/
|
|
171
|
+
protected internalGet<T>(key: IOC.ServiceKey<T>, parent?: IOC.Instance): T;
|
|
172
|
+
/**
|
|
173
|
+
* Internally retrieve dependency from container.
|
|
174
|
+
* @param key key to get
|
|
175
|
+
* @param parent parent
|
|
176
|
+
* @returns queried instance
|
|
177
|
+
*/
|
|
178
|
+
protected internalGetOptional<T>(key: IOC.ServiceKey<T>): T | null;
|
|
179
|
+
/**
|
|
180
|
+
* Internally resolves service def, turning it into class instance with deps injected.
|
|
181
|
+
* @param serviceDef service def to resolve
|
|
182
|
+
* @returns class instance
|
|
183
|
+
*/
|
|
184
|
+
protected internalResolve(serviceDef: IOC.ServiceDef): IOC.Instance;
|
|
185
|
+
/**
|
|
186
|
+
* Internally inject deps for particular class..
|
|
187
|
+
* @param instance instance to inject
|
|
188
|
+
* @param method method for injecting dependencies, either lazy or static
|
|
189
|
+
*/
|
|
190
|
+
protected internalProcessInjects(instance: IOC.Instance, method: IOC.InjectMethod): void;
|
|
191
|
+
/**
|
|
192
|
+
* Disposes a module, clearing everything allocated to it.
|
|
193
|
+
* @param def def that should be disposed
|
|
194
|
+
*/
|
|
195
|
+
protected internalDispose(def: IOC.ServiceDef): void;
|
|
196
|
+
/**
|
|
197
|
+
* Describes particular key for better error messaging.
|
|
198
|
+
* @param key service key
|
|
199
|
+
* @returns string representation of service key
|
|
200
|
+
*/
|
|
201
|
+
protected getKeyDescription(key: IOC.ServiceKey): string;
|
|
202
|
+
}
|
|
203
|
+
//#endregion
|
|
204
|
+
//#region src/Types/IOCTypes.d.ts
|
|
205
|
+
/**
|
|
206
|
+
* This module exports various types used in IOC system.
|
|
207
|
+
*/
|
|
208
|
+
declare namespace IOC {
|
|
209
|
+
/**
|
|
210
|
+
* This is a key that we use to identify service. Symbol is new way of doing it, however we
|
|
211
|
+
* also keep standard/abstract classes for backward compatability.
|
|
212
|
+
*/
|
|
213
|
+
type ServiceKey<T = unknown> = symbol | Newable<T> | Abstract<T>;
|
|
214
|
+
/**
|
|
215
|
+
* This type holds implementation that might be used in class.
|
|
216
|
+
*/
|
|
217
|
+
type ServiceValue<T = unknown> = Newable<T> | T;
|
|
218
|
+
/**
|
|
219
|
+
* This interface holds information about service in IOC container.
|
|
220
|
+
*/
|
|
221
|
+
interface ServiceDef<T = unknown> {
|
|
222
|
+
serviceKey: ServiceKey<T>;
|
|
223
|
+
serviceValue: ServiceValue<T>;
|
|
224
|
+
type: ServiceFactoryType;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* This holds type of bind we have used.
|
|
228
|
+
*/
|
|
229
|
+
enum ServiceFactoryType {
|
|
230
|
+
CLASS = "CLASS",
|
|
231
|
+
CLASS_SINGLETON = "CLASS_SINGLETON",
|
|
232
|
+
INSTANCE = "INSTANCE",
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Standard class.
|
|
236
|
+
*/
|
|
237
|
+
interface Newable<T> {
|
|
238
|
+
new (...args: unknown[]): T;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Abstract class.
|
|
242
|
+
*/
|
|
243
|
+
interface Abstract<T> {
|
|
244
|
+
prototype: T;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Service instance
|
|
248
|
+
*/
|
|
249
|
+
type Instance = any;
|
|
250
|
+
/**
|
|
251
|
+
* Helper type for "some prototype".
|
|
252
|
+
*/
|
|
253
|
+
type Prototype = any;
|
|
254
|
+
/**
|
|
255
|
+
* Container provider function.
|
|
256
|
+
*/
|
|
257
|
+
type ProviderFunc = (container: Container) => void;
|
|
258
|
+
/**
|
|
259
|
+
* Container constructor parameters
|
|
260
|
+
*/
|
|
261
|
+
interface ContainerParams {
|
|
262
|
+
createLocked: boolean;
|
|
263
|
+
injectMethod?: IOC.InjectMethod;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Method for injecting dependencies.
|
|
267
|
+
* Lazy - means dependency is resolved at the time when property is **accessed**, while
|
|
268
|
+
* Static - means dependency is resolved as soon as class is instantiated
|
|
269
|
+
*/
|
|
270
|
+
enum InjectMethod {
|
|
271
|
+
LAZY = "LAZY",
|
|
272
|
+
STATIC = "STATIC",
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* This type represents unique service identity. For now, its symbol, but we leave
|
|
276
|
+
* gate open in case we would want to replace it.
|
|
277
|
+
*/
|
|
278
|
+
type Identity = symbol;
|
|
279
|
+
/**
|
|
280
|
+
* Service map used in application configs.
|
|
281
|
+
*/
|
|
282
|
+
interface ServiceMap {
|
|
283
|
+
[key: string]: ServiceMapEntry;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Service map handler function (requirement for async to work, see SPT-5448)
|
|
287
|
+
*/
|
|
288
|
+
type ServiceMapEntry = () => ServiceMapTask | ServiceMapTask[];
|
|
289
|
+
/**
|
|
290
|
+
* Expander asynchronous task.
|
|
291
|
+
*/
|
|
292
|
+
type ServiceMapTask = Promise<{
|
|
293
|
+
default: IOC.ProviderFunc;
|
|
294
|
+
}>;
|
|
295
|
+
/**
|
|
296
|
+
* IOC dependency stack, used for debuggging
|
|
297
|
+
*/
|
|
298
|
+
type Stack = (ServiceKey | Instance)[];
|
|
299
|
+
/**
|
|
300
|
+
* Type of dependency - either standard or optional.
|
|
301
|
+
*/
|
|
302
|
+
enum DependencyType {
|
|
303
|
+
STANDARD = 0,
|
|
304
|
+
OPTIONAL = 1,
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
//#endregion
|
|
308
|
+
//#region src/Decorators/Inject.d.ts
|
|
309
|
+
/**
|
|
310
|
+
* Injects a dependency with particular key to service.
|
|
311
|
+
* @param key key to inject
|
|
312
|
+
* @returns decorator
|
|
313
|
+
*/
|
|
314
|
+
declare function Inject(key: IOC.ServiceKey): Function;
|
|
315
|
+
//#endregion
|
|
316
|
+
//#region src/Decorators/InjectOptional.d.ts
|
|
317
|
+
/**
|
|
318
|
+
* Injects a dependency with particular key to service.
|
|
319
|
+
* @param key key to inject
|
|
320
|
+
* @returns decorator
|
|
321
|
+
*/
|
|
322
|
+
declare function InjectOptional(key: IOC.ServiceKey): Function;
|
|
323
|
+
//#endregion
|
|
324
|
+
//#region src/Decorators/Init.d.ts
|
|
325
|
+
/**
|
|
326
|
+
* Decorator that automatically executes the decorated method when dependencies are injected.
|
|
327
|
+
* Use this decorator to run initialization logic for runtime-loaded container dependencies.
|
|
328
|
+
* @returns {Function} Decorator function that creates an InitDecorator instance
|
|
329
|
+
*/
|
|
330
|
+
declare function Init(): Function;
|
|
331
|
+
//#endregion
|
|
332
|
+
//#region src/Decorators/Destroy.d.ts
|
|
333
|
+
/**
|
|
334
|
+
* Decorator that automatically executes the decorated method when the service or component
|
|
335
|
+
* is destroyed. Use this decorator to run cleanup logic like unregistering event listeners
|
|
336
|
+
* or clearing timers.
|
|
337
|
+
*
|
|
338
|
+
* @example
|
|
339
|
+
* ```typescript
|
|
340
|
+
* class MyService {
|
|
341
|
+
* @Destroy()
|
|
342
|
+
* cleanup() {
|
|
343
|
+
* // Cleanup logic here
|
|
344
|
+
* }
|
|
345
|
+
* }
|
|
346
|
+
* ```
|
|
347
|
+
* @returns {Function} Decorator function that creates a DestroyDecorator instance
|
|
348
|
+
*/
|
|
349
|
+
declare function Destroy(): Function;
|
|
350
|
+
//#endregion
|
|
351
|
+
//#region src/Utils/Utils.d.ts
|
|
352
|
+
/**
|
|
353
|
+
* This function generates new service key for particular service. Providing
|
|
354
|
+
* name is mandatory because, unlike classes, those unique symbols do not infer
|
|
355
|
+
* their names from code.
|
|
356
|
+
*
|
|
357
|
+
* @param name name of the service
|
|
358
|
+
* @returns unique service identity
|
|
359
|
+
*/
|
|
360
|
+
declare function Identity(name: string): IOC.Identity;
|
|
361
|
+
/**
|
|
362
|
+
* A simple type of constructor for class "T"
|
|
363
|
+
*/
|
|
364
|
+
interface IClassType<T> {
|
|
365
|
+
new (): T;
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Holds decorator entry struct. It is saved in __decorators array for every class and holds
|
|
369
|
+
* various informations.
|
|
370
|
+
*/
|
|
371
|
+
interface IDecoratorEntry {
|
|
372
|
+
classType: any;
|
|
373
|
+
params: any;
|
|
374
|
+
target: any;
|
|
375
|
+
propertyName: string;
|
|
376
|
+
descriptor: PropertyDescriptor;
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* This is a type for every class instance that is decorated. It should contain hidden __decorators
|
|
380
|
+
* array that holds information about all decorators used in this class. It will be used later for
|
|
381
|
+
* turning those declarations for real code.
|
|
382
|
+
*/
|
|
383
|
+
interface IDecoratedPrototype {
|
|
384
|
+
__decorators?: IDecoratorEntry[];
|
|
385
|
+
__metadata?: any;
|
|
386
|
+
}
|
|
387
|
+
interface IDecoratedInstance {
|
|
388
|
+
__decoratorInstances?: BaseDecorator<any>[];
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* This function creates ES6 decorator based on class that was passed in argument.
|
|
392
|
+
*
|
|
393
|
+
* @param decoratorClass class of decorator that will be used
|
|
394
|
+
* @param params custom options object that will be availalbe in "options" property of decorator class
|
|
395
|
+
* @return ES6 decorator function
|
|
396
|
+
*/
|
|
397
|
+
declare function createDecorator<P, T extends BaseDecorator<P>>(decoratorClass: IClassType<T>, params: P): Function;
|
|
398
|
+
/**
|
|
399
|
+
* This function initializes all registered decorators on particular instance. It must be called in order
|
|
400
|
+
* for decorator code work in particular class.
|
|
401
|
+
* @param target class instance to sue
|
|
402
|
+
* @param container IOC container for context
|
|
403
|
+
*/
|
|
404
|
+
declare function initializeDecorators(target: IDecoratedInstance, container: Container): void;
|
|
405
|
+
/**
|
|
406
|
+
* This function releases all decorators applied to target instance by calling their .destroyed()
|
|
407
|
+
* method. Its used to provide a way for cleanup for decorators. @see BaseDecorator.destroy()
|
|
408
|
+
*
|
|
409
|
+
* @param target instance of class that should have decorators cleaned up
|
|
410
|
+
* @param container ioc container
|
|
411
|
+
*/
|
|
412
|
+
declare function destroyDecorators(target: IDecoratedInstance, container: Container): void;
|
|
413
|
+
/**
|
|
414
|
+
* This function is responsible for preparing IOC container to work with all decorators. It simply
|
|
415
|
+
* initializes all decorators on all services registered.
|
|
416
|
+
* @param container IOC container
|
|
417
|
+
*/
|
|
418
|
+
declare function initializeContainer(container: Container): void;
|
|
419
|
+
/**
|
|
420
|
+
* This function is responsible for preparing IOC container to work with all decorators. It simply
|
|
421
|
+
* initializes all decorators on all services registered.
|
|
422
|
+
* @param container IOC container
|
|
423
|
+
*/
|
|
424
|
+
declare function destroyContainer(container: Container): void;
|
|
425
|
+
//#endregion
|
|
426
|
+
export { BaseDecorator, Container, Destroy, IClassType, IDecoratedInstance, IDecoratedPrototype, IDecoratorEntry, IOC, Identity, Init, Inject, InjectOptional, createDecorator, destroyContainer, destroyDecorators, initializeContainer, initializeDecorators };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region
|
|
1
|
+
//#region src/Common/BaseDecorators.ts
|
|
2
2
|
/**
|
|
3
3
|
* This is base class for all property decorators used in application. Decorator class must extend this one.
|
|
4
4
|
* This class instance is created using IOC container so you can @Inject() things here.
|
|
@@ -29,7 +29,7 @@ var BaseDecorator = class {
|
|
|
29
29
|
};
|
|
30
30
|
|
|
31
31
|
//#endregion
|
|
32
|
-
//#region
|
|
32
|
+
//#region src/Types/IOCTypes.ts
|
|
33
33
|
let IOC;
|
|
34
34
|
(function(_IOC) {
|
|
35
35
|
let ServiceFactoryType = /* @__PURE__ */ function(ServiceFactoryType$1) {
|
|
@@ -54,13 +54,13 @@ let IOC;
|
|
|
54
54
|
})(IOC || (IOC = {}));
|
|
55
55
|
|
|
56
56
|
//#endregion
|
|
57
|
-
//#region
|
|
57
|
+
//#region src/Domain/Engine.ts
|
|
58
58
|
/**
|
|
59
59
|
* This map holds metadata for ALL classes in system along with their dependencies. Original idea was
|
|
60
60
|
* to store those informations in object prototype, but accessing this map is blazing fast with Map
|
|
61
61
|
* container (<1ms).
|
|
62
62
|
*/
|
|
63
|
-
const classMap = new Map();
|
|
63
|
+
const classMap = /* @__PURE__ */ new Map();
|
|
64
64
|
const ROOT_PROTO = Object.getPrototypeOf({});
|
|
65
65
|
/**
|
|
66
66
|
* This method registers @Inject() in particular class.
|
|
@@ -157,7 +157,7 @@ const IOCEngine = {
|
|
|
157
157
|
};
|
|
158
158
|
|
|
159
159
|
//#endregion
|
|
160
|
-
//#region
|
|
160
|
+
//#region src/Decorators/Inject.ts
|
|
161
161
|
/**
|
|
162
162
|
* Injects a dependency with particular key to service.
|
|
163
163
|
* @param key key to inject
|
|
@@ -170,7 +170,7 @@ function Inject(key) {
|
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
//#endregion
|
|
173
|
-
//#region
|
|
173
|
+
//#region src/Decorators/InjectOptional.ts
|
|
174
174
|
/**
|
|
175
175
|
* Injects a dependency with particular key to service.
|
|
176
176
|
* @param key key to inject
|
|
@@ -183,7 +183,7 @@ function InjectOptional(key) {
|
|
|
183
183
|
}
|
|
184
184
|
|
|
185
185
|
//#endregion
|
|
186
|
-
//#region
|
|
186
|
+
//#region src/Decorators/Init.ts
|
|
187
187
|
/**
|
|
188
188
|
* This decorator fires the decorated function as soon as decorators are injected. You
|
|
189
189
|
* can use this for initialization logic in runtime-loaded container deps.
|
|
@@ -206,7 +206,7 @@ function Init() {
|
|
|
206
206
|
}
|
|
207
207
|
|
|
208
208
|
//#endregion
|
|
209
|
-
//#region
|
|
209
|
+
//#region src/Decorators/Destroy.ts
|
|
210
210
|
/**
|
|
211
211
|
* Decorator that handles cleanup tasks when a service or component is destroyed.
|
|
212
212
|
* This decorator class extends BaseDecorator and executes the decorated method
|
|
@@ -243,7 +243,7 @@ function Destroy() {
|
|
|
243
243
|
}
|
|
244
244
|
|
|
245
245
|
//#endregion
|
|
246
|
-
//#region
|
|
246
|
+
//#region src/Domain/ContainerEvents.ts
|
|
247
247
|
/**
|
|
248
248
|
* This class allows for container to listen on various IOC events.
|
|
249
249
|
*/
|
|
@@ -266,7 +266,7 @@ var ContainerEvents = class {
|
|
|
266
266
|
};
|
|
267
267
|
|
|
268
268
|
//#endregion
|
|
269
|
-
//#region
|
|
269
|
+
//#region src/Utils/Utils.ts
|
|
270
270
|
/**
|
|
271
271
|
* This function generates new service key for particular service. Providing
|
|
272
272
|
* name is mandatory because, unlike classes, those unique symbols do not infer
|
|
@@ -302,14 +302,14 @@ function createDecorator(decoratorClass, params) {
|
|
|
302
302
|
* we must hold array of decorated instances, we realize it by holding map where key is
|
|
303
303
|
* container (for easier removal later) and value is IContainerDecoratorMetadataObject.
|
|
304
304
|
*/
|
|
305
|
-
const containerMap = new Map();
|
|
305
|
+
const containerMap = /* @__PURE__ */ new Map();
|
|
306
306
|
/**
|
|
307
307
|
* Helper function to query data from container
|
|
308
308
|
* @param container container to get metadata fro
|
|
309
309
|
* @return metadata object
|
|
310
310
|
*/
|
|
311
311
|
function getContainerMetadata(container) {
|
|
312
|
-
if (!containerMap.has(container)) containerMap.set(container, { decoratedInstances: new Map() });
|
|
312
|
+
if (!containerMap.has(container)) containerMap.set(container, { decoratedInstances: /* @__PURE__ */ new Map() });
|
|
313
313
|
return containerMap.get(container);
|
|
314
314
|
}
|
|
315
315
|
/**
|
|
@@ -369,7 +369,7 @@ function destroyContainer(container) {
|
|
|
369
369
|
}
|
|
370
370
|
|
|
371
371
|
//#endregion
|
|
372
|
-
//#region
|
|
372
|
+
//#region src/Domain/Container.ts
|
|
373
373
|
/**
|
|
374
374
|
* This is new implementation of IOC Container. It mimics Inversify.js container a little bit but its
|
|
375
375
|
* simpler and (probably) more performant on larger scales.
|
|
@@ -377,9 +377,9 @@ function destroyContainer(container) {
|
|
|
377
377
|
var Container = class Container {
|
|
378
378
|
fLocked = false;
|
|
379
379
|
fDefaultParams = { createLocked: false };
|
|
380
|
-
fServices = new Map();
|
|
381
|
-
fNewQueue = new Map();
|
|
382
|
-
fSingletonInstances = new Map();
|
|
380
|
+
fServices = /* @__PURE__ */ new Map();
|
|
381
|
+
fNewQueue = /* @__PURE__ */ new Map();
|
|
382
|
+
fSingletonInstances = /* @__PURE__ */ new Map();
|
|
383
383
|
fInjectMethod = IOC.InjectMethod.STATIC;
|
|
384
384
|
fContainerEvents = new ContainerEvents();
|
|
385
385
|
/**
|
|
@@ -634,7 +634,7 @@ var Container = class Container {
|
|
|
634
634
|
return;
|
|
635
635
|
}
|
|
636
636
|
const processQueue = [];
|
|
637
|
-
const elementSet = new Set();
|
|
637
|
+
const elementSet = /* @__PURE__ */ new Set();
|
|
638
638
|
const toProcessElements = [];
|
|
639
639
|
processQueue.push(instance);
|
|
640
640
|
toProcessElements.push(instance);
|
package/package.json
CHANGED
|
@@ -1,21 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercube/di",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "Dependencie Injection module for Vercube framework",
|
|
5
5
|
"repository": "@vercube/di",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"sideEffects": false,
|
|
8
|
-
"type": "module",
|
|
9
8
|
"exports": {
|
|
10
|
-
".":
|
|
11
|
-
"types": "./dist/index.d.ts",
|
|
12
|
-
"import": "./dist/index.mjs",
|
|
13
|
-
"require": "./dist/index.cjs"
|
|
14
|
-
}
|
|
9
|
+
".": "./dist/index.mjs"
|
|
15
10
|
},
|
|
16
|
-
"
|
|
17
|
-
"module": "./dist/index.mjs",
|
|
18
|
-
"types": "./dist/index.d.ts",
|
|
11
|
+
"types": "./dist/index.d.mts",
|
|
19
12
|
"files": [
|
|
20
13
|
"dist",
|
|
21
14
|
"README.md"
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This is base class for all property decorators used in application. Decorator class must extend this one.
|
|
3
|
-
* This class instance is created using IOC container so you can @Inject() things here.
|
|
4
|
-
*/
|
|
5
|
-
export declare abstract class BaseDecorator<
|
|
6
|
-
T = any,
|
|
7
|
-
P = any
|
|
8
|
-
> {
|
|
9
|
-
/** Holds options object that is passed as 2nd argument in createDecorator() factory */
|
|
10
|
-
options: T;
|
|
11
|
-
/** Holds class instance that is decorated */
|
|
12
|
-
instance: any;
|
|
13
|
-
/** Holds class prototype that is decorated */
|
|
14
|
-
prototype: P;
|
|
15
|
-
/** Holds property name that was decorated */
|
|
16
|
-
propertyName: string;
|
|
17
|
-
/** Holds property descriptor that was decorated */
|
|
18
|
-
descriptor: PropertyDescriptor;
|
|
19
|
-
/** Holds property index if decorators if for Method Property */
|
|
20
|
-
propertyIndex: number;
|
|
21
|
-
/**
|
|
22
|
-
* This method is called when decorator is created and ready to be used.
|
|
23
|
-
*/
|
|
24
|
-
created(): void;
|
|
25
|
-
/**
|
|
26
|
-
* This method is called when decorator is destroyed for cleanup tasks (like unregistering listeners, clearing timers).
|
|
27
|
-
* For standard services it is called at the end of SSR requests and for Vue components it is called when component is
|
|
28
|
-
* destroyed.
|
|
29
|
-
*/
|
|
30
|
-
destroyed(): void;
|
|
31
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Decorator that automatically executes the decorated method when the service or component
|
|
3
|
-
* is destroyed. Use this decorator to run cleanup logic like unregistering event listeners
|
|
4
|
-
* or clearing timers.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```typescript
|
|
8
|
-
* class MyService {
|
|
9
|
-
* @Destroy()
|
|
10
|
-
* cleanup() {
|
|
11
|
-
* // Cleanup logic here
|
|
12
|
-
* }
|
|
13
|
-
* }
|
|
14
|
-
* ```
|
|
15
|
-
* @returns {Function} Decorator function that creates a DestroyDecorator instance
|
|
16
|
-
*/
|
|
17
|
-
export declare function Destroy(): Function;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Decorator that automatically executes the decorated method when dependencies are injected.
|
|
3
|
-
* Use this decorator to run initialization logic for runtime-loaded container dependencies.
|
|
4
|
-
* @returns {Function} Decorator function that creates an InitDecorator instance
|
|
5
|
-
*/
|
|
6
|
-
export declare function Init(): Function;
|