@tachybase/utils 1.3.42 → 1.3.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/client.d.ts +0 -3
- package/lib/client.js +0 -22
- package/lib/date.d.ts +1 -1
- package/lib/date.js +9 -9
- package/lib/dayjs.d.ts +1 -10
- package/lib/dayjs.js +4 -22
- package/lib/index.d.ts +2 -6
- package/lib/index.js +0 -27
- package/lib/parse-date.js +21 -11
- package/lib/parse-filter.js +4 -4
- package/package.json +1 -1
- package/lib/decorators.d.ts +0 -16
- package/lib/decorators.js +0 -94
- package/lib/typedi/container-instance.class.d.ts +0 -109
- package/lib/typedi/container-instance.class.js +0 -340
- package/lib/typedi/container-registry.class.d.ts +0 -51
- package/lib/typedi/container-registry.class.js +0 -95
- package/lib/typedi/decorators/inject-many.decorator.d.ts +0 -8
- package/lib/typedi/decorators/inject-many.decorator.js +0 -56
- package/lib/typedi/decorators/inject.decorator.d.ts +0 -9
- package/lib/typedi/decorators/inject.decorator.js +0 -56
- package/lib/typedi/decorators/service.decorator.d.ts +0 -6
- package/lib/typedi/decorators/service.decorator.js +0 -49
- package/lib/typedi/empty.const.d.ts +0 -6
- package/lib/typedi/empty.const.js +0 -27
- package/lib/typedi/error/cannot-inject-value.error.d.ts +0 -11
- package/lib/typedi/error/cannot-inject-value.error.js +0 -40
- package/lib/typedi/error/cannot-instantiate-value.error.d.ts +0 -11
- package/lib/typedi/error/cannot-instantiate-value.error.js +0 -49
- package/lib/typedi/error/service-not-found.error.d.ts +0 -11
- package/lib/typedi/error/service-not-found.error.js +0 -49
- package/lib/typedi/index.d.ts +0 -17
- package/lib/typedi/index.js +0 -49
- package/lib/typedi/interfaces/container-options.interface.d.ts +0 -45
- package/lib/typedi/interfaces/container-options.interface.js +0 -15
- package/lib/typedi/interfaces/handler.interface.d.ts +0 -27
- package/lib/typedi/interfaces/handler.interface.js +0 -15
- package/lib/typedi/interfaces/service-metadata.interface.d.ts +0 -53
- package/lib/typedi/interfaces/service-metadata.interface.js +0 -15
- package/lib/typedi/interfaces/service-options.interface.d.ts +0 -6
- package/lib/typedi/interfaces/service-options.interface.js +0 -15
- package/lib/typedi/token.class.d.ts +0 -11
- package/lib/typedi/token.class.js +0 -37
- package/lib/typedi/types/abstract-constructable.type.d.ts +0 -9
- package/lib/typedi/types/abstract-constructable.type.js +0 -15
- package/lib/typedi/types/container-identifier.type.d.ts +0 -4
- package/lib/typedi/types/container-identifier.type.js +0 -15
- package/lib/typedi/types/container-scope.type.d.ts +0 -1
- package/lib/typedi/types/container-scope.type.js +0 -15
- package/lib/typedi/types/service-identifier.type.d.ts +0 -8
- package/lib/typedi/types/service-identifier.type.js +0 -15
- package/lib/typedi/utils/resolve-to-type-wrapper.util.d.ts +0 -15
- package/lib/typedi/utils/resolve-to-type-wrapper.util.js +0 -39
- /package/lib/{typedi/types → types}/constructable.type.d.ts +0 -0
- /package/lib/{typedi/types → types}/constructable.type.js +0 -0
|
@@ -1,340 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var container_instance_class_exports = {};
|
|
20
|
-
__export(container_instance_class_exports, {
|
|
21
|
-
ContainerInstance: () => ContainerInstance
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(container_instance_class_exports);
|
|
24
|
-
var import_container_registry = require("./container-registry.class");
|
|
25
|
-
var import_empty = require("./empty.const");
|
|
26
|
-
var import_cannot_instantiate_value = require("./error/cannot-instantiate-value.error");
|
|
27
|
-
var import_service_not_found = require("./error/service-not-found.error");
|
|
28
|
-
var import_token = require("./token.class");
|
|
29
|
-
const _ContainerInstance = class _ContainerInstance {
|
|
30
|
-
constructor(id) {
|
|
31
|
-
/** Metadata for all registered services in this container. */
|
|
32
|
-
this.metadataMap = /* @__PURE__ */ new Map();
|
|
33
|
-
/**
|
|
34
|
-
* Services registered with 'multiple: true' are saved as simple services
|
|
35
|
-
* with a generated token and the mapping between the original ID and the
|
|
36
|
-
* generated one is stored here. This is handled like this to allow simplifying
|
|
37
|
-
* the inner workings of the service instance.
|
|
38
|
-
*/
|
|
39
|
-
this.multiServiceIds = /* @__PURE__ */ new Map();
|
|
40
|
-
/**
|
|
41
|
-
* All registered handlers. The @Inject() decorator uses handlers internally to mark a property for injection.
|
|
42
|
-
**/
|
|
43
|
-
this.handlers = [];
|
|
44
|
-
/**
|
|
45
|
-
* Indicates if the container has been disposed or not.
|
|
46
|
-
* Any function call should fail when called after being disposed.
|
|
47
|
-
*
|
|
48
|
-
* NOTE: Currently not in used
|
|
49
|
-
*/
|
|
50
|
-
this.disposed = false;
|
|
51
|
-
this.id = id;
|
|
52
|
-
if (id !== "default") {
|
|
53
|
-
import_container_registry.ContainerRegistry.registerContainer(this);
|
|
54
|
-
this.handlers = _ContainerInstance.default.handlers || [];
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
static get default() {
|
|
58
|
-
if (!this._default) {
|
|
59
|
-
this._default = new _ContainerInstance("default");
|
|
60
|
-
import_container_registry.ContainerRegistry.registerContainer(this._default);
|
|
61
|
-
}
|
|
62
|
-
return this._default;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Checks if the service with given name or type is registered service container.
|
|
66
|
-
* Optionally, parameters can be passed in case if instance is initialized in the container for the first time.
|
|
67
|
-
*/
|
|
68
|
-
has(identifier) {
|
|
69
|
-
this.throwIfDisposed();
|
|
70
|
-
return !!this.metadataMap.has(identifier) || !!this.multiServiceIds.has(identifier);
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Retrieves the service with given name or type from the service container.
|
|
74
|
-
* Optionally, parameters can be passed in case if instance is initialized in the container for the first time.
|
|
75
|
-
*/
|
|
76
|
-
get(identifier) {
|
|
77
|
-
this.throwIfDisposed();
|
|
78
|
-
const global = _ContainerInstance.default.metadataMap.get(identifier);
|
|
79
|
-
const local = this.metadataMap.get(identifier);
|
|
80
|
-
const metadata = (global == null ? void 0 : global.scope) === "singleton" ? global : local;
|
|
81
|
-
if (metadata && metadata.multiple === true) {
|
|
82
|
-
throw new Error(`Cannot resolve multiple values for ${identifier.toString()} service!`);
|
|
83
|
-
}
|
|
84
|
-
if (metadata) {
|
|
85
|
-
return this.getServiceValue(metadata);
|
|
86
|
-
}
|
|
87
|
-
if (global && this !== _ContainerInstance.default) {
|
|
88
|
-
const clonedService = { ...global };
|
|
89
|
-
clonedService.value = import_empty.EMPTY_VALUE;
|
|
90
|
-
this.set(clonedService);
|
|
91
|
-
const value = this.getServiceValue(clonedService);
|
|
92
|
-
this.set({ ...clonedService, value });
|
|
93
|
-
return value;
|
|
94
|
-
}
|
|
95
|
-
throw new import_service_not_found.ServiceNotFoundError(identifier);
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Gets all instances registered in the container of the given service identifier.
|
|
99
|
-
* Used when service defined with multiple: true flag.
|
|
100
|
-
*/
|
|
101
|
-
getMany(identifier) {
|
|
102
|
-
this.throwIfDisposed();
|
|
103
|
-
const globalIdMap = _ContainerInstance.default.multiServiceIds.get(identifier);
|
|
104
|
-
const localIdMap = this.multiServiceIds.get(identifier);
|
|
105
|
-
if ((globalIdMap == null ? void 0 : globalIdMap.scope) === "singleton") {
|
|
106
|
-
return globalIdMap.tokens.map((generatedId) => _ContainerInstance.default.get(generatedId));
|
|
107
|
-
}
|
|
108
|
-
if (localIdMap) {
|
|
109
|
-
return localIdMap.tokens.map((generatedId) => this.get(generatedId));
|
|
110
|
-
}
|
|
111
|
-
throw new import_service_not_found.ServiceNotFoundError(identifier);
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Sets a value for the given type or service name in the container.
|
|
115
|
-
*/
|
|
116
|
-
set(serviceOptions) {
|
|
117
|
-
this.throwIfDisposed();
|
|
118
|
-
if (serviceOptions.scope === "singleton" && _ContainerInstance.default !== this) {
|
|
119
|
-
_ContainerInstance.default.set(serviceOptions);
|
|
120
|
-
return this;
|
|
121
|
-
}
|
|
122
|
-
const newMetadata = {
|
|
123
|
-
/**
|
|
124
|
-
* Typescript cannot understand that if ID doesn't exists then type must exists based on the
|
|
125
|
-
* typing so we need to explicitly cast this to a `ServiceIdentifier`
|
|
126
|
-
*/
|
|
127
|
-
id: serviceOptions.id || serviceOptions.type,
|
|
128
|
-
type: serviceOptions.type || null,
|
|
129
|
-
factory: serviceOptions.factory,
|
|
130
|
-
value: serviceOptions.value || import_empty.EMPTY_VALUE,
|
|
131
|
-
multiple: serviceOptions.multiple || false,
|
|
132
|
-
eager: serviceOptions.eager || false,
|
|
133
|
-
scope: serviceOptions.scope || "container",
|
|
134
|
-
/** We allow overriding the above options via the received config object. */
|
|
135
|
-
...serviceOptions,
|
|
136
|
-
referencedBy: (/* @__PURE__ */ new Map()).set(this.id, this)
|
|
137
|
-
};
|
|
138
|
-
if (serviceOptions.multiple) {
|
|
139
|
-
const maskedToken = new import_token.Token(`MultiMaskToken-${newMetadata.id.toString()}`);
|
|
140
|
-
const existingMultiGroup = this.multiServiceIds.get(newMetadata.id);
|
|
141
|
-
if (existingMultiGroup) {
|
|
142
|
-
existingMultiGroup.tokens.push(maskedToken);
|
|
143
|
-
} else {
|
|
144
|
-
this.multiServiceIds.set(newMetadata.id, { scope: newMetadata.scope, tokens: [maskedToken] });
|
|
145
|
-
}
|
|
146
|
-
newMetadata.id = maskedToken;
|
|
147
|
-
newMetadata.multiple = false;
|
|
148
|
-
}
|
|
149
|
-
const existingMetadata = this.metadataMap.get(newMetadata.id);
|
|
150
|
-
if (existingMetadata) {
|
|
151
|
-
Object.assign(existingMetadata, newMetadata);
|
|
152
|
-
} else {
|
|
153
|
-
this.metadataMap.set(newMetadata.id, newMetadata);
|
|
154
|
-
}
|
|
155
|
-
if (newMetadata.eager && newMetadata.scope !== "transient") {
|
|
156
|
-
this.get(newMetadata.id);
|
|
157
|
-
}
|
|
158
|
-
return this;
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Removes services with a given service identifiers.
|
|
162
|
-
*/
|
|
163
|
-
remove(identifierOrIdentifierArray) {
|
|
164
|
-
this.throwIfDisposed();
|
|
165
|
-
if (Array.isArray(identifierOrIdentifierArray)) {
|
|
166
|
-
identifierOrIdentifierArray.forEach((id) => this.remove(id));
|
|
167
|
-
} else {
|
|
168
|
-
const serviceMetadata = this.metadataMap.get(identifierOrIdentifierArray);
|
|
169
|
-
if (serviceMetadata) {
|
|
170
|
-
this.disposeServiceInstance(serviceMetadata);
|
|
171
|
-
this.metadataMap.delete(identifierOrIdentifierArray);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
return this;
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Gets a separate container instance for the given instance id.
|
|
178
|
-
*/
|
|
179
|
-
of(containerId = "default") {
|
|
180
|
-
this.throwIfDisposed();
|
|
181
|
-
if (containerId === "default") {
|
|
182
|
-
return _ContainerInstance.default;
|
|
183
|
-
}
|
|
184
|
-
let container;
|
|
185
|
-
if (import_container_registry.ContainerRegistry.hasContainer(containerId)) {
|
|
186
|
-
container = import_container_registry.ContainerRegistry.getContainer(containerId);
|
|
187
|
-
} else {
|
|
188
|
-
container = new _ContainerInstance(containerId);
|
|
189
|
-
}
|
|
190
|
-
return container;
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Registers a new handler.
|
|
194
|
-
*/
|
|
195
|
-
registerHandler(handler) {
|
|
196
|
-
this.handlers.push(handler);
|
|
197
|
-
return this;
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* Helper method that imports given services.
|
|
201
|
-
*/
|
|
202
|
-
import(services) {
|
|
203
|
-
this.throwIfDisposed();
|
|
204
|
-
return this;
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Completely resets the container by removing all previously registered services from it.
|
|
208
|
-
*/
|
|
209
|
-
reset(options = { strategy: "resetValue" }) {
|
|
210
|
-
this.throwIfDisposed();
|
|
211
|
-
switch (options.strategy) {
|
|
212
|
-
case "resetValue":
|
|
213
|
-
this.metadataMap.forEach((service) => this.disposeServiceInstance(service));
|
|
214
|
-
break;
|
|
215
|
-
case "resetServices":
|
|
216
|
-
this.metadataMap.forEach((service) => this.disposeServiceInstance(service));
|
|
217
|
-
this.metadataMap.clear();
|
|
218
|
-
this.multiServiceIds.clear();
|
|
219
|
-
break;
|
|
220
|
-
default:
|
|
221
|
-
throw new Error("Received invalid reset strategy.");
|
|
222
|
-
}
|
|
223
|
-
return this;
|
|
224
|
-
}
|
|
225
|
-
async dispose() {
|
|
226
|
-
this.reset({ strategy: "resetServices" });
|
|
227
|
-
this.disposed = true;
|
|
228
|
-
await Promise.resolve();
|
|
229
|
-
}
|
|
230
|
-
throwIfDisposed() {
|
|
231
|
-
if (this.disposed) {
|
|
232
|
-
throw new Error("Cannot use container after it has been disposed.");
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* Gets the value belonging to passed in `ServiceMetadata` instance.
|
|
237
|
-
*
|
|
238
|
-
* - if `serviceMetadata.value` is already set it is immediately returned
|
|
239
|
-
* - otherwise the requested type is resolved to the value saved to `serviceMetadata.value` and returned
|
|
240
|
-
*/
|
|
241
|
-
getServiceValue(serviceMetadata) {
|
|
242
|
-
let value = import_empty.EMPTY_VALUE;
|
|
243
|
-
if (serviceMetadata.value !== import_empty.EMPTY_VALUE) {
|
|
244
|
-
return serviceMetadata.value;
|
|
245
|
-
}
|
|
246
|
-
if (!serviceMetadata.factory && typeof serviceMetadata.type === "undefined") {
|
|
247
|
-
throw new import_cannot_instantiate_value.CannotInstantiateValueError(serviceMetadata.id);
|
|
248
|
-
}
|
|
249
|
-
if (serviceMetadata.factory) {
|
|
250
|
-
if (serviceMetadata.factory instanceof Array) {
|
|
251
|
-
let factoryInstance;
|
|
252
|
-
try {
|
|
253
|
-
factoryInstance = this.get(serviceMetadata.factory[0]);
|
|
254
|
-
} catch (error) {
|
|
255
|
-
if (error instanceof import_service_not_found.ServiceNotFoundError) {
|
|
256
|
-
factoryInstance = new serviceMetadata.factory[0]();
|
|
257
|
-
} else {
|
|
258
|
-
throw error;
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
value = factoryInstance[serviceMetadata.factory[1]](this, serviceMetadata.id);
|
|
262
|
-
} else {
|
|
263
|
-
value = serviceMetadata.factory(this, serviceMetadata.id);
|
|
264
|
-
}
|
|
265
|
-
} else if (typeof serviceMetadata.type === "function") {
|
|
266
|
-
value = new serviceMetadata.type();
|
|
267
|
-
}
|
|
268
|
-
if (serviceMetadata.scope !== "transient" && value !== import_empty.EMPTY_VALUE) {
|
|
269
|
-
serviceMetadata.value = value;
|
|
270
|
-
}
|
|
271
|
-
if (value === import_empty.EMPTY_VALUE) {
|
|
272
|
-
throw new import_cannot_instantiate_value.CannotInstantiateValueError(serviceMetadata.id);
|
|
273
|
-
}
|
|
274
|
-
if (serviceMetadata.type) {
|
|
275
|
-
this.applyPropertyHandlers(serviceMetadata.type, value);
|
|
276
|
-
}
|
|
277
|
-
return value;
|
|
278
|
-
}
|
|
279
|
-
/**
|
|
280
|
-
* Initializes all parameter types for a given target service class.
|
|
281
|
-
*/
|
|
282
|
-
initializeParams(target, paramTypes) {
|
|
283
|
-
return paramTypes.map((paramType, index) => {
|
|
284
|
-
const paramHandler = this.handlers.find((handler) => {
|
|
285
|
-
return handler.object === target && handler.index === index;
|
|
286
|
-
}) || this.handlers.find((handler) => {
|
|
287
|
-
return handler.object === Object.getPrototypeOf(target) && handler.index === index;
|
|
288
|
-
});
|
|
289
|
-
if (paramHandler) return paramHandler.value(this);
|
|
290
|
-
if (paramType && paramType.name && !this.isPrimitiveParamType(paramType.name)) {
|
|
291
|
-
return this.get(paramType);
|
|
292
|
-
}
|
|
293
|
-
return void 0;
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* Checks if given parameter type is primitive type or not.
|
|
298
|
-
*/
|
|
299
|
-
isPrimitiveParamType(paramTypeName) {
|
|
300
|
-
return ["string", "boolean", "number", "object"].includes(paramTypeName.toLowerCase());
|
|
301
|
-
}
|
|
302
|
-
/**
|
|
303
|
-
* Applies all registered handlers on a given target class.
|
|
304
|
-
*/
|
|
305
|
-
applyPropertyHandlers(target, instance) {
|
|
306
|
-
this.handlers.forEach((handler) => {
|
|
307
|
-
if (typeof handler.index === "number") return;
|
|
308
|
-
if (handler.object !== target && !(target.prototype instanceof handler.object)) return;
|
|
309
|
-
if (handler.propertyName) {
|
|
310
|
-
instance[handler.propertyName] = handler.value(this);
|
|
311
|
-
}
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
|
-
/**
|
|
315
|
-
* Checks if the given service metadata contains a destroyable service instance and destroys it in place. If the service
|
|
316
|
-
* contains a callable function named `destroy` it is called but not awaited and the return value is ignored..
|
|
317
|
-
*
|
|
318
|
-
* @param serviceMetadata the service metadata containing the instance to destroy
|
|
319
|
-
* @param force when true the service will be always destroyed even if it's cannot be re-created
|
|
320
|
-
*/
|
|
321
|
-
disposeServiceInstance(serviceMetadata, force = false) {
|
|
322
|
-
this.throwIfDisposed();
|
|
323
|
-
const shouldResetValue = force || !!serviceMetadata.type || !!serviceMetadata.factory;
|
|
324
|
-
if (shouldResetValue) {
|
|
325
|
-
if (typeof (serviceMetadata == null ? void 0 : serviceMetadata.value)["dispose"] === "function") {
|
|
326
|
-
try {
|
|
327
|
-
serviceMetadata.value.dispose();
|
|
328
|
-
} catch (error) {
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
serviceMetadata.value = import_empty.EMPTY_VALUE;
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
};
|
|
335
|
-
__name(_ContainerInstance, "ContainerInstance");
|
|
336
|
-
let ContainerInstance = _ContainerInstance;
|
|
337
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
338
|
-
0 && (module.exports = {
|
|
339
|
-
ContainerInstance
|
|
340
|
-
});
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { ContainerInstance } from './container-instance.class';
|
|
2
|
-
import { ContainerIdentifier } from './types/container-identifier.type';
|
|
3
|
-
/**
|
|
4
|
-
* The container registry is responsible for holding the default and every
|
|
5
|
-
* created container instance for later access.
|
|
6
|
-
*
|
|
7
|
-
* _Note: This class is for internal use and it's API may break in minor or
|
|
8
|
-
* patch releases without warning._
|
|
9
|
-
*/
|
|
10
|
-
export declare class ContainerRegistry {
|
|
11
|
-
/**
|
|
12
|
-
* The list of all known container. Created containers are automatically added
|
|
13
|
-
* to this list. Two container cannot be registered with the same ID.
|
|
14
|
-
*
|
|
15
|
-
* This map doesn't contains the default container.
|
|
16
|
-
*/
|
|
17
|
-
private static readonly containerMap;
|
|
18
|
-
/**
|
|
19
|
-
* Registers the given container instance or throws an error.
|
|
20
|
-
*
|
|
21
|
-
* _Note: This function is auto-called when a Container instance is created,
|
|
22
|
-
* it doesn't need to be called manually!_
|
|
23
|
-
*
|
|
24
|
-
* @param container the container to add to the registry
|
|
25
|
-
*/
|
|
26
|
-
static registerContainer(container: ContainerInstance): void;
|
|
27
|
-
/**
|
|
28
|
-
* Returns true if a container exists with the given ID or false otherwise.
|
|
29
|
-
*
|
|
30
|
-
* @param container the ID of the container
|
|
31
|
-
*/
|
|
32
|
-
static hasContainer(id: ContainerIdentifier): boolean;
|
|
33
|
-
/**
|
|
34
|
-
* Returns the container for requested ID or throws an error if no container
|
|
35
|
-
* is registered with the given ID.
|
|
36
|
-
*
|
|
37
|
-
* @param container the ID of the container
|
|
38
|
-
*/
|
|
39
|
-
static getContainer(id: ContainerIdentifier): ContainerInstance;
|
|
40
|
-
/**
|
|
41
|
-
* Removes the given container from the registry and disposes all services
|
|
42
|
-
* registered only in this container.
|
|
43
|
-
*
|
|
44
|
-
* This function throws an error if no
|
|
45
|
-
* - container exists with the given ID
|
|
46
|
-
* - any of the registered services threw an error during it's disposal
|
|
47
|
-
*
|
|
48
|
-
* @param container the container to remove from the registry
|
|
49
|
-
*/
|
|
50
|
-
static removeContainer(container: ContainerInstance): Promise<void>;
|
|
51
|
-
}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var container_registry_class_exports = {};
|
|
20
|
-
__export(container_registry_class_exports, {
|
|
21
|
-
ContainerRegistry: () => ContainerRegistry
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(container_registry_class_exports);
|
|
24
|
-
var import_container_instance = require("./container-instance.class");
|
|
25
|
-
const _ContainerRegistry = class _ContainerRegistry {
|
|
26
|
-
/**
|
|
27
|
-
* Registers the given container instance or throws an error.
|
|
28
|
-
*
|
|
29
|
-
* _Note: This function is auto-called when a Container instance is created,
|
|
30
|
-
* it doesn't need to be called manually!_
|
|
31
|
-
*
|
|
32
|
-
* @param container the container to add to the registry
|
|
33
|
-
*/
|
|
34
|
-
static registerContainer(container) {
|
|
35
|
-
if (container instanceof import_container_instance.ContainerInstance === false) {
|
|
36
|
-
throw new Error("Only ContainerInstance instances can be registered.");
|
|
37
|
-
}
|
|
38
|
-
if (_ContainerRegistry.containerMap.has(container.id)) {
|
|
39
|
-
throw new Error("Cannot register container with same ID.");
|
|
40
|
-
}
|
|
41
|
-
_ContainerRegistry.containerMap.set(container.id, container);
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Returns true if a container exists with the given ID or false otherwise.
|
|
45
|
-
*
|
|
46
|
-
* @param container the ID of the container
|
|
47
|
-
*/
|
|
48
|
-
static hasContainer(id) {
|
|
49
|
-
return _ContainerRegistry.containerMap.has(id);
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Returns the container for requested ID or throws an error if no container
|
|
53
|
-
* is registered with the given ID.
|
|
54
|
-
*
|
|
55
|
-
* @param container the ID of the container
|
|
56
|
-
*/
|
|
57
|
-
static getContainer(id) {
|
|
58
|
-
const registeredContainer = this.containerMap.get(id);
|
|
59
|
-
if (registeredContainer === void 0) {
|
|
60
|
-
throw new Error("No container is registered with the given ID.");
|
|
61
|
-
}
|
|
62
|
-
return registeredContainer;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Removes the given container from the registry and disposes all services
|
|
66
|
-
* registered only in this container.
|
|
67
|
-
*
|
|
68
|
-
* This function throws an error if no
|
|
69
|
-
* - container exists with the given ID
|
|
70
|
-
* - any of the registered services threw an error during it's disposal
|
|
71
|
-
*
|
|
72
|
-
* @param container the container to remove from the registry
|
|
73
|
-
*/
|
|
74
|
-
static async removeContainer(container) {
|
|
75
|
-
const registeredContainer = _ContainerRegistry.containerMap.get(container.id);
|
|
76
|
-
if (registeredContainer === void 0) {
|
|
77
|
-
throw new Error("No container is registered with the given ID.");
|
|
78
|
-
}
|
|
79
|
-
_ContainerRegistry.containerMap.delete(container.id);
|
|
80
|
-
await registeredContainer.dispose();
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
__name(_ContainerRegistry, "ContainerRegistry");
|
|
84
|
-
/**
|
|
85
|
-
* The list of all known container. Created containers are automatically added
|
|
86
|
-
* to this list. Two container cannot be registered with the same ID.
|
|
87
|
-
*
|
|
88
|
-
* This map doesn't contains the default container.
|
|
89
|
-
*/
|
|
90
|
-
_ContainerRegistry.containerMap = /* @__PURE__ */ new Map();
|
|
91
|
-
let ContainerRegistry = _ContainerRegistry;
|
|
92
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
93
|
-
0 && (module.exports = {
|
|
94
|
-
ContainerRegistry
|
|
95
|
-
});
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Token } from '../token.class';
|
|
2
|
-
/**
|
|
3
|
-
* Injects a list of services into a class property or constructor parameter.
|
|
4
|
-
*/
|
|
5
|
-
export declare function InjectMany(): Function;
|
|
6
|
-
export declare function InjectMany(type?: (type?: any) => Function): Function;
|
|
7
|
-
export declare function InjectMany(serviceName?: string): Function;
|
|
8
|
-
export declare function InjectMany(token: Token<any>): Function;
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var inject_many_decorator_exports = {};
|
|
20
|
-
__export(inject_many_decorator_exports, {
|
|
21
|
-
InjectMany: () => InjectMany
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(inject_many_decorator_exports);
|
|
24
|
-
var import_container_instance = require("../container-instance.class");
|
|
25
|
-
var import_cannot_inject_value = require("../error/cannot-inject-value.error");
|
|
26
|
-
var import_resolve_to_type_wrapper = require("../utils/resolve-to-type-wrapper.util");
|
|
27
|
-
function InjectMany(typeOrIdentifier) {
|
|
28
|
-
return function(_, context) {
|
|
29
|
-
if (!context.metadata.injects) {
|
|
30
|
-
context.metadata.injects = [];
|
|
31
|
-
}
|
|
32
|
-
context.metadata.injects.push((target) => {
|
|
33
|
-
const propertyName = context.name;
|
|
34
|
-
const typeWrapper = (0, import_resolve_to_type_wrapper.resolveToTypeWrapper)(typeOrIdentifier, target, propertyName);
|
|
35
|
-
if (typeWrapper === void 0 || typeWrapper.eagerType === void 0 || typeWrapper.eagerType === Object) {
|
|
36
|
-
throw new import_cannot_inject_value.CannotInjectValueError(target, propertyName);
|
|
37
|
-
}
|
|
38
|
-
import_container_instance.ContainerInstance.default.registerHandler({
|
|
39
|
-
object: target,
|
|
40
|
-
propertyName,
|
|
41
|
-
value: /* @__PURE__ */ __name((containerInstance) => {
|
|
42
|
-
const evaluatedLazyType = typeWrapper.lazyType();
|
|
43
|
-
if (evaluatedLazyType === void 0 || evaluatedLazyType === Object) {
|
|
44
|
-
throw new import_cannot_inject_value.CannotInjectValueError(target, propertyName);
|
|
45
|
-
}
|
|
46
|
-
return containerInstance.getMany(evaluatedLazyType);
|
|
47
|
-
}, "value")
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
__name(InjectMany, "InjectMany");
|
|
53
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
54
|
-
0 && (module.exports = {
|
|
55
|
-
InjectMany
|
|
56
|
-
});
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Token } from '../token.class';
|
|
2
|
-
import { Constructable } from '../types/constructable.type';
|
|
3
|
-
/**
|
|
4
|
-
* Injects a service into a class property or constructor parameter.
|
|
5
|
-
*/
|
|
6
|
-
export declare function Inject(): Function;
|
|
7
|
-
export declare function Inject(typeFn: (type?: never) => Constructable<unknown>): Function;
|
|
8
|
-
export declare function Inject(serviceName?: string): Function;
|
|
9
|
-
export declare function Inject(token: Token<unknown>): Function;
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var inject_decorator_exports = {};
|
|
20
|
-
__export(inject_decorator_exports, {
|
|
21
|
-
Inject: () => Inject
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(inject_decorator_exports);
|
|
24
|
-
var import_container_instance = require("../container-instance.class");
|
|
25
|
-
var import_cannot_inject_value = require("../error/cannot-inject-value.error");
|
|
26
|
-
var import_resolve_to_type_wrapper = require("../utils/resolve-to-type-wrapper.util");
|
|
27
|
-
function Inject(typeOrIdentifier) {
|
|
28
|
-
return function(_, context) {
|
|
29
|
-
if (!context.metadata.injects) {
|
|
30
|
-
context.metadata.injects = [];
|
|
31
|
-
}
|
|
32
|
-
context.metadata.injects.push((target) => {
|
|
33
|
-
const propertyName = context.name;
|
|
34
|
-
const typeWrapper = (0, import_resolve_to_type_wrapper.resolveToTypeWrapper)(typeOrIdentifier, target, propertyName);
|
|
35
|
-
if (typeWrapper === void 0 || typeWrapper.eagerType === void 0 || typeWrapper.eagerType === Object) {
|
|
36
|
-
throw new import_cannot_inject_value.CannotInjectValueError(target, propertyName);
|
|
37
|
-
}
|
|
38
|
-
import_container_instance.ContainerInstance.default.registerHandler({
|
|
39
|
-
object: target,
|
|
40
|
-
propertyName,
|
|
41
|
-
value: /* @__PURE__ */ __name((containerInstance) => {
|
|
42
|
-
const evaluatedLazyType = typeWrapper.lazyType();
|
|
43
|
-
if (evaluatedLazyType === void 0 || evaluatedLazyType === Object) {
|
|
44
|
-
throw new import_cannot_inject_value.CannotInjectValueError(target, propertyName);
|
|
45
|
-
}
|
|
46
|
-
return containerInstance.get(evaluatedLazyType);
|
|
47
|
-
}, "value")
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
__name(Inject, "Inject");
|
|
53
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
54
|
-
0 && (module.exports = {
|
|
55
|
-
Inject
|
|
56
|
-
});
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { ServiceOptions } from '../interfaces/service-options.interface';
|
|
2
|
-
/**
|
|
3
|
-
* Marks class as a service that can be injected using Container.
|
|
4
|
-
*/
|
|
5
|
-
export declare function Service<T = unknown>(): Function;
|
|
6
|
-
export declare function Service<T = unknown>(options: ServiceOptions<T>): Function;
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var service_decorator_exports = {};
|
|
20
|
-
__export(service_decorator_exports, {
|
|
21
|
-
Service: () => Service
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(service_decorator_exports);
|
|
24
|
-
var import_container_instance = require("../container-instance.class");
|
|
25
|
-
var import_empty = require("../empty.const");
|
|
26
|
-
function Service(options = {}) {
|
|
27
|
-
return (target, context) => {
|
|
28
|
-
const serviceMetadata = {
|
|
29
|
-
id: options.id || target,
|
|
30
|
-
type: target,
|
|
31
|
-
factory: options.factory || void 0,
|
|
32
|
-
multiple: options.multiple || false,
|
|
33
|
-
eager: options.eager || false,
|
|
34
|
-
scope: options.scope || "container",
|
|
35
|
-
referencedBy: (/* @__PURE__ */ new Map()).set(import_container_instance.ContainerInstance.default.id, import_container_instance.ContainerInstance.default),
|
|
36
|
-
value: import_empty.EMPTY_VALUE
|
|
37
|
-
};
|
|
38
|
-
(context.metadata.injects || []).forEach((inject) => {
|
|
39
|
-
inject(target);
|
|
40
|
-
});
|
|
41
|
-
import_container_instance.ContainerInstance.default.set(serviceMetadata);
|
|
42
|
-
return target;
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
__name(Service, "Service");
|
|
46
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
-
0 && (module.exports = {
|
|
48
|
-
Service
|
|
49
|
-
});
|