@adimm/x-injection 1.2.0 → 2.0.3

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.cjs CHANGED
@@ -1,671 +1,814 @@
1
1
  "use strict";
2
2
 
3
- var e, i = Object.defineProperty, t = Object.getOwnPropertyDescriptor, n = Object.getOwnPropertyNames, o = Object.prototype.hasOwnProperty, r = (e, t) => i(e, "name", {
4
- value: t,
3
+ var e, t = Object.defineProperty, i = Object.getOwnPropertyDescriptor, o = Object.getOwnPropertyNames, r = Object.prototype.hasOwnProperty, n = (e, i) => t(e, "name", {
4
+ value: i,
5
5
  configurable: !0
6
6
  }), s = {};
7
7
 
8
- ((e, t) => {
9
- for (var n in t) i(e, n, {
10
- get: t[n],
8
+ ((e, i) => {
9
+ for (var o in i) t(e, o, {
10
+ get: i[o],
11
11
  enumerable: !0
12
12
  });
13
13
  })(s, {
14
- AppModule: () => $,
15
- GLOBAL_APP_MODULE_ID: () => d,
16
- GlobalAppModule: () => H,
17
- GlobalContainer: () => L,
18
- Inject: () => T,
19
- InjectFromBase: () => _,
20
- Injectable: () => E,
21
- InjectionError: () => x,
22
- InjectionProviderModuleDisposedError: () => q,
23
- InjectionProviderModuleError: () => F,
24
- InjectionProviderModuleGlobalMarkError: () => N,
25
- InjectionProviderModuleMissingIdentifierError: () => U,
26
- InjectionScope: () => c,
27
- MultiInject: () => w,
28
- Named: () => P,
29
- Optional: () => C,
30
- ProviderModule: () => W,
31
- ProviderModuleDefinition: () => m,
32
- ProviderModuleHelpers: () => I,
33
- ProviderTokenHelpers: () => f,
34
- Tagged: () => R,
35
- Unmanaged: () => A,
36
- bindingScopeToInjectionScope: () => l,
37
- injectionScopeToBindingScope: () => u,
38
- isClass: () => p,
39
- isClassOrFunction: () => v,
40
- isFunction: () => S,
41
- isPlainObject: () => b
42
- }), module.exports = (e = s, ((e, r, s, d) => {
43
- if (r && "object" == typeof r || "function" == typeof r) for (let a of n(r)) o.call(e, a) || a === s || i(e, a, {
44
- get: () => r[a],
45
- enumerable: !(d = t(r, a)) || d.enumerable
14
+ AppModule: () => Z,
15
+ DefinitionEventType: () => p,
16
+ Inject: () => V,
17
+ InjectFromBase: () => N,
18
+ Injectable: () => q,
19
+ InjectionError: () => I,
20
+ InjectionProviderModuleDisposedError: () => P,
21
+ InjectionProviderModuleError: () => b,
22
+ InjectionProviderModuleMissingIdentifierError: () => x,
23
+ InjectionProviderModuleMissingProviderError: () => E,
24
+ InjectionProviderModuleUnknownProviderError: () => w,
25
+ InjectionScope: () => u,
26
+ MiddlewareType: () => a,
27
+ MultiInject: () => U,
28
+ Named: () => H,
29
+ Optional: () => J,
30
+ ProviderModule: () => G,
31
+ ProviderModuleBlueprint: () => A,
32
+ ProviderModuleHelpers: () => g,
33
+ ProviderTokenHelpers: () => h,
34
+ Tagged: () => Q,
35
+ Unmanaged: () => Y,
36
+ bindingScopeToInjectionScope: () => c,
37
+ deepClone: () => k,
38
+ injectionScopeToBindingScope: () => l,
39
+ isClass: () => v,
40
+ isClassOrFunction: () => m,
41
+ isFunction: () => F,
42
+ isPlainObject: () => y
43
+ }), module.exports = (e = s, ((e, n, s, d) => {
44
+ if (n && "object" == typeof n || "function" == typeof n) for (let u of o(n)) r.call(e, u) || u === s || t(e, u, {
45
+ get: () => n[u],
46
+ enumerable: !(d = i(n, u)) || d.enumerable
46
47
  });
47
48
  return e;
48
- })(i({}, "__esModule", {
49
+ })(t({}, "__esModule", {
49
50
  value: !0
50
51
  }), e));
51
52
 
52
- var d = "GlobalAppModule", a = require("inversify"), c = function(e) {
53
+ var d = require("inversify"), u = function(e) {
53
54
  return e[e.Singleton = 0] = "Singleton", e[e.Transient = 1] = "Transient", e[e.Request = 2] = "Request",
54
55
  e;
56
+ }({}), a = function(e) {
57
+ return e[e.BeforeAddImport = 0] = "BeforeAddImport", e[e.BeforeAddProvider = 1] = "BeforeAddProvider",
58
+ e[e.BeforeGet = 2] = "BeforeGet", e[e.BeforeRemoveImport = 3] = "BeforeRemoveImport",
59
+ e[e.BeforeRemoveProvider = 4] = "BeforeRemoveProvider", e[e.BeforeRemoveExport = 5] = "BeforeRemoveExport",
60
+ e[e.OnExportAccess = 6] = "OnExportAccess", e;
61
+ }({}), p = function(e) {
62
+ return e[e.Noop = 0] = "Noop", e[e.Import = 1] = "Import", e[e.Provider = 2] = "Provider",
63
+ e[e.GetProvider = 3] = "GetProvider", e[e.Export = 4] = "Export", e[e.ExportModule = 5] = "ExportModule",
64
+ e[e.ExportProvider = 6] = "ExportProvider", e[e.ImportRemoved = 7] = "ImportRemoved",
65
+ e[e.ProviderRemoved = 8] = "ProviderRemoved", e[e.ExportRemoved = 9] = "ExportRemoved",
66
+ e[e.ExportModuleRemoved = 10] = "ExportModuleRemoved", e[e.ExportProviderRemoved = 11] = "ExportProviderRemoved",
67
+ e;
55
68
  }({});
56
69
 
57
- function u(e) {
70
+ function l(e) {
58
71
  switch (e) {
59
- case c.Singleton:
72
+ case u.Singleton:
60
73
  return "Singleton";
61
74
 
62
- case c.Transient:
75
+ case u.Transient:
63
76
  return "Transient";
64
77
 
65
- case c.Request:
78
+ case u.Request:
66
79
  return "Request";
67
80
  }
68
81
  }
69
82
 
70
- function l(e) {
83
+ function c(e) {
71
84
  switch (e) {
72
85
  case "Singleton":
73
- return c.Singleton;
86
+ return u.Singleton;
74
87
 
75
88
  case "Transient":
76
- return c.Transient;
89
+ return u.Transient;
77
90
 
78
91
  case "Request":
79
- return c.Request;
92
+ return u.Request;
80
93
  }
81
94
  }
82
95
 
83
- r(u, "injectionScopeToBindingScope"), r(l, "bindingScopeToInjectionScope");
96
+ n(l, "injectionScopeToBindingScope"), n(c, "bindingScopeToInjectionScope");
84
97
 
85
- var f, h = require("@inversifyjs/core");
98
+ var h, f = require("@inversifyjs/core");
86
99
 
87
- function p(e) {
100
+ function v(e) {
88
101
  return "function" == typeof e && Function.prototype.toString.call(e).startsWith("class ");
89
102
  }
90
103
 
91
- function v(e) {
104
+ function m(e) {
92
105
  return "function" == typeof e;
93
106
  }
94
107
 
95
- function S(e) {
96
- return "function" == typeof e && !Function.prototype.toString.call(e).startsWith("class ");
97
- }
98
-
99
- function g(e) {
108
+ function M(e) {
100
109
  return "[object Object]" === Object.prototype.toString.call(e);
101
110
  }
102
111
 
103
- function b(e) {
104
- if (!1 === g(e)) return !1;
105
- const i = e.constructor;
106
- if (void 0 === i) return !0;
107
- const t = i.prototype;
108
- return !1 !== g(t) && !1 !== t.hasOwnProperty("isPrototypeOf");
112
+ function y(e) {
113
+ if (!1 === M(e)) return !1;
114
+ const t = e.constructor;
115
+ if (void 0 === t) return !0;
116
+ const i = t.prototype;
117
+ return !1 !== M(i) && !1 !== i.hasOwnProperty("isPrototypeOf");
109
118
  }
110
119
 
111
- r(p, "isClass"), r(v, "isClassOrFunction"), r(S, "isFunction"), r(g, "isObject"),
112
- r(b, "isPlainObject"), function(e) {
113
- function i(e) {
120
+ n(v, "isClass"), n(m, "isClassOrFunction"), n(M, "isObject"), n(y, "isPlainObject"),
121
+ function(e) {
122
+ function t(e) {
114
123
  return I(e) && "useClass" in e;
115
124
  }
116
- function t(e) {
125
+ function i(e) {
117
126
  return I(e) && "useValue" in e;
118
127
  }
119
- function n(e) {
128
+ function o(e) {
120
129
  return I(e) && "useFactory" in e;
121
130
  }
122
- function o(e) {
123
- return "string" == typeof e || "symbol" == typeof e || v(e);
131
+ function r(e) {
132
+ return "string" == typeof e || "symbol" == typeof e || m(e);
124
133
  }
125
134
  function s(e) {
126
- return o(e) ? e : e.provide;
135
+ return r(e) ? e : e.provide;
127
136
  }
128
137
  function d(e) {
129
138
  return e.map((e => s(e)));
130
139
  }
131
- function a(e, i) {
132
- return p(e) ? {
133
- ...i,
134
- provide: i?.provide ?? e,
135
- useClass: i?.useClass ?? e
136
- } : S(e) ? {
137
- ...i,
138
- provide: i?.provide ?? e,
139
- useFactory: i?.useFactory ?? e
140
- } : {
141
- ...e,
142
- ...i
143
- };
140
+ function u(e) {
141
+ return "symbol" == typeof e || "string" == typeof e ? e.toString() : e.name;
144
142
  }
145
- function c(e, i) {
146
- return f(e) ?? g(e) ?? i;
143
+ function a(e) {
144
+ return u(s(e));
147
145
  }
148
- function u(e) {
146
+ function p(e, r) {
147
+ if (e === r) return !0;
148
+ return s(e) === s(r) && (t(e) && t(r) ? e.useClass === r.useClass : i(e) && i(r) ? e.useValue === r.useValue : !o(e) || !o(r) || e.useFactory === r.useFactory);
149
+ }
150
+ function l(e, t) {
151
+ return M(e) ?? g(e) ?? t;
152
+ }
153
+ function h(e) {
149
154
  if (I(e)) return e;
150
155
  }
151
- function f(e) {
152
- const i = u(e);
153
- if (i) return i.scope;
156
+ function M(e) {
157
+ const t = h(e);
158
+ if (t) return t.scope;
154
159
  }
155
160
  function g(e) {
156
- const i = s(e);
157
- if (!p(i)) return;
158
- const t = (0, h.getClassMetadata)(i)?.scope;
159
- return t ? l(t) : void 0;
161
+ const t = s(e);
162
+ if (!v(t)) return;
163
+ const i = (0, f.getClassMetadata)(t)?.scope;
164
+ return i ? c(i) : void 0;
160
165
  }
161
166
  function I(e) {
162
- return b(e) && "object" == typeof e && "provide" in e;
163
- }
164
- r(i, "isClassToken"), e.isClassToken = i, r(t, "isValueToken"), e.isValueToken = t,
165
- r(n, "isFactoryToken"), e.isFactoryToken = n, r(o, "isProviderIdentifier"), e.isProviderIdentifier = o,
166
- r(s, "toServiceIdentifier"), e.toServiceIdentifier = s, r(d, "toServiceIdentifiers"),
167
- e.toServiceIdentifiers = d, r(a, "toDependencyProviderWithOptions"), e.toDependencyProviderWithOptions = a,
168
- r(c, "getInjectionScopeByPriority"), e.getInjectionScopeByPriority = c, r(u, "tryGetProviderOptions"),
169
- e.tryGetProviderOptions = u, r(f, "tryGetScopeFromProvider"), e.tryGetScopeFromProvider = f,
170
- r(g, "tryGetDecoratorScopeFromClass"), e.tryGetDecoratorScopeFromClass = g, r(I, "hasProvideProperty");
171
- }(f || (f = {}));
172
-
173
- var I, y = new Set, m = class e {
167
+ return y(e) && "object" == typeof e && "provide" in e;
168
+ }
169
+ n(t, "isClassToken"), e.isClassToken = t, n(i, "isValueToken"), e.isValueToken = i,
170
+ n(o, "isFactoryToken"), e.isFactoryToken = o, n(r, "isProviderIdentifier"), e.isProviderIdentifier = r,
171
+ n(s, "toProviderIdentifier"), e.toProviderIdentifier = s, n(d, "toProviderIdentifiers"),
172
+ e.toProviderIdentifiers = d, n(u, "providerIdentifierToString"), e.providerIdentifierToString = u,
173
+ n(a, "providerTokenToString"), e.providerTokenToString = a, n(p, "providerTokensAreEqual"),
174
+ e.providerTokensAreEqual = p, n(l, "getInjectionScopeByPriority"), e.getInjectionScopeByPriority = l,
175
+ n(h, "tryGetProviderOptions"), e.tryGetProviderOptions = h, n(M, "tryGetScopeFromProvider"),
176
+ e.tryGetScopeFromProvider = M, n(g, "tryGetDecoratorScopeFromClass"), e.tryGetDecoratorScopeFromClass = g,
177
+ n(I, "hasProvideProperty");
178
+ }(h || (h = {}));
179
+
180
+ var g, I = class e extends Error {
174
181
  static {
175
- r(this, "ProviderModuleDefinition");
176
- }
177
- identifier;
178
- imports;
179
- providers;
180
- exports;
181
- defaultScope;
182
- isGlobal;
183
- onReady;
184
- onDispose;
185
- constructor(e) {
186
- const {identifier: i, imports: t, providers: n, exports: o, defaultScope: r, isGlobal: s, onReady: d, onDispose: a} = e;
187
- this.identifier = i, this.imports = t, this.providers = n, this.exports = o, this.defaultScope = r ?? c.Singleton,
188
- this.isGlobal = s ?? !1, this.onReady = d, this.onDispose = a, this.checkIfShouldBeAddedToTheGlobalRegister();
189
- }
190
- getDefinition() {
191
- return {
192
- identifier: this.identifier,
193
- imports: this.imports,
194
- providers: this.providers,
195
- exports: this.exports,
196
- defaultScope: this.defaultScope,
197
- isGlobal: this.isGlobal,
198
- onReady: this.onReady,
199
- onDispose: this.onDispose
200
- };
201
- }
202
- clone(i) {
203
- const t = this.getDefinition();
204
- return new e(i ? {
205
- ...t,
206
- ...i
207
- } : t);
208
- }
209
- toString() {
210
- return ("symbol" == typeof this.identifier ? this.identifier.description : this.identifier) ?? "Unknown";
211
- }
212
- checkIfShouldBeAddedToTheGlobalRegister() {
213
- this.isGlobal && y.add(this);
214
- }
215
- };
216
-
217
- function E(e) {
218
- return void 0 === e ? (0, a.injectable)() : (0, a.injectable)(u(e));
219
- }
220
-
221
- !function(e) {
222
- function i(e) {
223
- return e;
224
- }
225
- function t(e) {
226
- const {identifier: i, imports: t, providers: o, exports: r, defaultScope: s, isGlobal: d, onReady: a, onDispose: c, ...u} = e, l = u;
227
- if (n(e)) {
228
- const e = u;
229
- delete e.getDefinition, delete e.clone, delete e.toString;
230
- }
231
- return {
232
- options: {
233
- identifier: i,
234
- imports: t,
235
- providers: o,
236
- exports: r,
237
- defaultScope: s,
238
- isGlobal: d,
239
- onReady: a,
240
- onDispose: c
241
- },
242
- internalOptions: l
243
- };
244
- }
245
- function n(e) {
246
- return e instanceof m;
247
- }
248
- function o(e) {
249
- return S(e);
182
+ n(this, "InjectionError");
250
183
  }
251
- function s(e, i) {
252
- return o(i) ? i(e) : i;
253
- }
254
- r(i, "buildInternalConstructorParams"), e.buildInternalConstructorParams = i, r(t, "getOptionsOrModuleDefinitionOptions"),
255
- e.getOptionsOrModuleDefinitionOptions = t, r(n, "isModuleDefinition"), e.isModuleDefinition = n,
256
- r(o, "isLazyExport"), e.isLazyExport = o, r(s, "tryStaticOrLazyExportToStaticExport"),
257
- e.tryStaticOrLazyExportToStaticExport = s;
258
- }(I || (I = {})), r(E, "Injectable");
259
-
260
- var M = require("inversify");
261
-
262
- function T(e) {
263
- return (0, M.inject)(f.toServiceIdentifier(e));
264
- }
265
-
266
- r(T, "Inject");
267
-
268
- var k = require("inversify");
269
-
270
- function w(e) {
271
- return (0, k.multiInject)(f.toServiceIdentifier(e));
272
- }
273
-
274
- r(w, "MultiInject");
275
-
276
- var D = require("inversify");
277
-
278
- function _(e) {
279
- return (0, D.injectFromBase)(e);
280
- }
281
-
282
- r(_, "InjectFromBase");
283
-
284
- var j = require("inversify");
285
-
286
- function P(e) {
287
- return (0, j.named)(e);
288
- }
289
-
290
- r(P, "Named");
291
-
292
- var O = require("inversify");
293
-
294
- function C() {
295
- return (0, O.optional)();
296
- }
297
-
298
- r(C, "Optional");
299
-
300
- var G = require("inversify");
301
-
302
- function R(e, i) {
303
- return (0, G.tagged)(e, i);
304
- }
305
-
306
- r(R, "Tagged");
307
-
308
- var B = require("inversify");
309
-
310
- function A() {
311
- return (0, B.unmanaged)();
312
- }
313
-
314
- r(A, "Unmanaged");
315
-
316
- var x = class e extends Error {
184
+ name=e.name;
185
+ }, b = class e extends Error {
317
186
  static {
318
- r(this, "InjectionError");
187
+ n(this, "InjectionProviderModuleError");
319
188
  }
320
189
  name=e.name;
321
- }, F = class e extends Error {
190
+ constructor(e, t) {
191
+ let i = "Unknown";
192
+ try {
193
+ i = e.toString();
194
+ } catch {}
195
+ super(`{ProviderModule.${i}} => ${t}`);
196
+ }
197
+ }, w = class e extends b {
322
198
  static {
323
- r(this, "InjectionProviderModuleError");
199
+ n(this, "InjectionProviderModuleUnknownProviderError");
324
200
  }
325
201
  name=e.name;
326
- constructor(e, i) {
327
- super(`{ProviderModule.${e.toString()}} => ${i}`);
202
+ constructor(e, t) {
203
+ super(e, `The [${h.providerTokenToString(t)}] provider is of an unknown type!`);
328
204
  }
329
- }, q = class e extends F {
205
+ }, P = class e extends b {
330
206
  static {
331
- r(this, "InjectionProviderModuleDisposedError");
207
+ n(this, "InjectionProviderModuleDisposedError");
332
208
  }
333
209
  name=e.name;
334
210
  constructor(e) {
335
- super(e, "Has been disposed! You can re-initialize it by using the `_internalInit` method.");
211
+ super(e, "Has been disposed!");
336
212
  }
337
- }, U = class e extends F {
213
+ }, x = class e extends b {
338
214
  static {
339
- r(this, "InjectionProviderModuleMissingIdentifierError");
215
+ n(this, "InjectionProviderModuleMissingIdentifierError");
340
216
  }
341
217
  name=e.name;
342
218
  constructor(e) {
343
219
  super(e, "An `identifier` must be supplied!");
344
220
  }
345
- }, N = class e extends F {
221
+ }, E = class e extends b {
346
222
  static {
347
- r(this, "InjectionProviderModuleGlobalMarkError");
223
+ n(this, "InjectionProviderModuleMissingProviderError");
348
224
  }
349
225
  name=e.name;
350
- constructor(e, i) {
351
- super(e, i);
226
+ constructor(e, t) {
227
+ super(e, `The [${h.providerTokenToString(t)}] provider is not bound to this (or any imported) module container, and was not found either in the 'AppModule'!`);
352
228
  }
353
- }, L = new (require("inversify").Container)({
229
+ }, S = require("inversify"), D = new (require("inversify").Container)({
354
230
  defaultScope: "Singleton"
355
- }), z = require("inversify"), V = class {
231
+ }), C = class {
356
232
  static {
357
- r(this, "ProviderModuleUtils");
358
- }
359
- get container() {
360
- return this.moduleNaked.container;
361
- }
362
- appModule=$;
363
- module;
364
- moduleNaked;
365
- constructor(e, i) {
366
- this.module = e, this.moduleNaked = e.toNaked(), this.appModule = i.appModule?.() ?? this.appModule,
367
- this.checkIfShouldBeAddedToTheGlobalRegister();
368
- }
369
- bindToContainer(e, i) {
370
- return f.isProviderIdentifier(e) ? this.bindSelfTokenToContainer(e, i) : f.isClassToken(e) ? this.bindClassTokenToContainer(e, i) : f.isValueToken(e) ? this.bindValueTokenToContainer(e) : !!f.isFactoryToken(e) && this.bindFactoryTokenToContainer(e, i);
233
+ n(this, "ModuleContainer");
371
234
  }
372
- checkIfShouldBeAddedToTheGlobalRegister() {
373
- this.moduleNaked.isAppModule || !this.module.isGlobal || this.moduleNaked.instantiatedFromDefinition || y.add(this.module);
235
+ container;
236
+ providerModule;
237
+ constructor(e, t) {
238
+ this.providerModule = e;
239
+ const {defaultScope: i = u.Singleton} = e.options;
240
+ this.container = "AppModule" === e.id ? D : new S.Container({
241
+ parent: t ?? this.providerModule.appModuleRef.moduleContainer.container,
242
+ defaultScope: l(i)
243
+ }), this.providerModule.options.providers?.forEach((e => this.bindToContainer(e)));
244
+ }
245
+ get(e, t, i) {
246
+ const o = this.providerModule.middlewaresManager.applyMiddlewares(a.BeforeGet, this.getProvider(e, i), e, this.getProvider.bind(this));
247
+ if (o || null === o) return o;
248
+ if (!t) throw new E(this.providerModule, e);
374
249
  }
375
- bindSelfTokenToContainer(e, i) {
376
- return this.setBindingScope(e, this.container.bind(f.toServiceIdentifier(e)).toSelf(), i),
377
- this.moduleNaked.__isCurrentBound(e);
250
+ getMany(...e) {
251
+ return e.map((e => {
252
+ const t = y(e) && "provider" in e;
253
+ return this.get(t ? e.provider : e, !!t && e.isOptional, !!t && e.asList);
254
+ }));
378
255
  }
379
- bindClassTokenToContainer(e, i) {
380
- return this.setBindingOnEvent(e, this.setWhenBinding(e, this.setBindingScope(e, this.container.bind(f.toServiceIdentifier(e)).to(e.useClass), i))),
381
- this.moduleNaked.__isCurrentBound(e);
256
+ bindToContainer(e) {
257
+ const t = h.toProviderIdentifier(e), i = [ {
258
+ providerTypeMatches: h.isProviderIdentifier,
259
+ bind: n((() => this.container.bind(t).toSelf()), "bind")
260
+ }, {
261
+ providerTypeMatches: h.isClassToken,
262
+ bind: n((() => this.container.bind(t).to(e.useClass)), "bind")
263
+ }, {
264
+ providerTypeMatches: h.isValueToken,
265
+ bind: n((() => this.container.bind(t).toConstantValue(e.useValue)), "bind")
266
+ }, {
267
+ providerTypeMatches: h.isFactoryToken,
268
+ bind: n((() => this.container.bind(t).toResolvedValue((() => {
269
+ const t = e, i = this.providerModule.getMany(...t.inject ?? []);
270
+ return t.useFactory(...i);
271
+ }))), "bind")
272
+ } ], {bind: o} = i.find((({providerTypeMatches: t}) => t(e))) ?? {};
273
+ if (!o) throw new w(this.providerModule, e);
274
+ const r = h.isProviderIdentifier(e);
275
+ let s = o();
276
+ if (h.isValueToken(e) || r || (s = this.setBindingScope(e, s)), r) return;
277
+ const d = e;
278
+ d.when && s.when(d.when);
279
+ }
280
+ setBindingScope(e, t) {
281
+ switch (h.getInjectionScopeByPriority(e, this.providerModule.options.defaultScope ?? u.Singleton)) {
282
+ case u.Singleton:
283
+ return t.inSingletonScope();
284
+
285
+ case u.Transient:
286
+ return t.inTransientScope();
287
+
288
+ case u.Request:
289
+ return t.inRequestScope();
290
+ }
382
291
  }
383
- bindValueTokenToContainer(e) {
384
- return this.setBindingOnEvent(e, this.setWhenBinding(e, this.container.bind(f.toServiceIdentifier(e)).toConstantValue(e.useValue))),
385
- this.moduleNaked.__isCurrentBound(e);
292
+ dispose() {
293
+ this.providerModule = null, this.container = null;
386
294
  }
387
- bindFactoryTokenToContainer(e, i) {
388
- return this.setBindingOnEvent(e, this.setWhenBinding(e, this.setBindingScope(e, this.container.bind(f.toServiceIdentifier(e)).toResolvedValue(e.useFactory, f.toServiceIdentifiers(e.inject ?? [])), i))),
389
- this.moduleNaked.__isCurrentBound(e);
295
+ getProvider(e, t) {
296
+ const i = h.toProviderIdentifier(e);
297
+ return t ? this.container.getAll(i, {
298
+ optional: !0
299
+ }) : this.container.get(i, {
300
+ optional: !0
301
+ });
390
302
  }
391
- setBindingScope(e, i, t) {
392
- if (f.isValueToken(e)) return i;
393
- switch (f.getInjectionScopeByPriority(e, t)) {
394
- case c.Singleton:
395
- return i.inSingletonScope();
396
-
397
- case c.Transient:
398
- return i.inTransientScope();
399
-
400
- case c.Request:
401
- return i.inRequestScope();
303
+ }, R = require("inversify"), T = class {
304
+ static {
305
+ n(this, "ImportedModuleContainer");
306
+ }
307
+ get moduleDef() {
308
+ return this.providerModule.dynamicModuleDef.moduleDef;
309
+ }
310
+ importedIntoModule;
311
+ providerModule;
312
+ proxyContainer;
313
+ proxyContainerOptions;
314
+ constructor(e, t) {
315
+ this.importedIntoModule = e, this.providerModule = t, this.proxyContainer = this.buildProxyContainer();
316
+ }
317
+ dispose() {
318
+ this.importedIntoModule.moduleContainer.container.unloadSync(this.proxyContainer),
319
+ this.importedIntoModule = null, this.providerModule = null, this.proxyContainer = null,
320
+ this.proxyContainerOptions = null;
321
+ }
322
+ buildProxyContainer() {
323
+ const e = new R.ContainerModule((e => {
324
+ this.proxyContainerOptions = e, this.traverseExportGraph(((e, t) => {
325
+ this.proxyProviderIdentifier(e, t);
326
+ }), this.moduleDef.exports), this.providerModule.dynamicModuleDef.event$.subscribe((({type: e, change: t}) => {
327
+ if (e !== p.Export && e !== p.ExportRemoved) return;
328
+ if (!g.isModule(t)) return void (e === p.Export ? this.proxyProviderIdentifier(t, this.providerModule) : e === p.ExportRemoved && this.unproxyProviderIdentifier(t));
329
+ const i = t;
330
+ e === p.Export ? this.traverseExportGraph(((e, t) => {
331
+ this.proxyProviderIdentifier(e, t);
332
+ }), i.dynamicModuleDef.moduleDef.exports) : this.traverseExportGraph((e => {
333
+ this.unproxyProviderIdentifier(e);
334
+ }), i.dynamicModuleDef.moduleDef.exports);
335
+ }));
336
+ }));
337
+ return this.importedIntoModule.moduleContainer.container.loadSync(e), e;
338
+ }
339
+ proxyProviderIdentifier(e, t) {
340
+ const i = h.toProviderIdentifier(e);
341
+ if (this.proxyContainerOptions.isBound(i)) return;
342
+ const o = this.proxyContainerOptions.bind(i).toDynamicValue((() => {
343
+ if (!1 !== this.providerModule.middlewaresManager.applyMiddlewares(a.OnExportAccess, this.importedIntoModule, i)) return t.moduleContainer.container.get(i);
344
+ this.proxyContainerOptions.unbind(i);
345
+ }));
346
+ this.providerModule.moduleContainer.setBindingScope(e, o);
347
+ }
348
+ unproxyProviderIdentifier(e) {
349
+ const t = h.toProviderIdentifier(e);
350
+ this.proxyContainerOptions.isBound(t) && this.proxyContainerOptions.unbind(t);
351
+ }
352
+ traverseExportGraph(e, t) {
353
+ const i = [];
354
+ for (const o of t) {
355
+ if (o instanceof G) i.push(o); else {
356
+ if (!1 === this.providerModule.middlewaresManager.applyMiddlewares(a.OnExportAccess, this.importedIntoModule, o)) continue;
357
+ e(o, this.providerModule);
358
+ }
402
359
  }
360
+ for (const t of i) this.traverseExportGraph(e, t.dynamicModuleDef.moduleDef.exports);
403
361
  }
404
- setWhenBinding(e, i) {
405
- if (f.isProviderIdentifier(e)) return i;
406
- const t = e.when;
407
- return t ? i.when(t) : i;
408
- }
409
- setBindingOnEvent(e, i) {
410
- if (f.isProviderIdentifier(e)) return;
411
- const t = e;
412
- t.onEvent?.activation && i.onActivation(t.onEvent.activation), t.onEvent?.deactivation && i.onDeactivation(t.onEvent.deactivation);
413
- }
414
- }, W = class e {
362
+ }, B = class {
415
363
  static {
416
- r(this, "ProviderModule");
364
+ n(this, "Signal");
417
365
  }
418
- isDisposed=!1;
419
- identifier;
420
- isGlobal=!1;
421
- isAppModule;
422
- instantiatedFromDefinition;
423
- container;
424
- defaultScope;
425
- onReady;
426
- onDispose;
427
- moduleUtils;
428
- imports;
429
- providers;
430
- exports;
431
- registeredSideEffects;
366
+ value;
367
+ subscribers=new Set;
432
368
  constructor(e) {
433
- const {options: i, internalOptions: t} = I.getOptionsOrModuleDefinitionOptions(e);
434
- this.identifier = this.setIdentifier(i.identifier), this.isDisposed = t.isDisposed ?? !1,
435
- this.isAppModule = t.isAppModule ?? !1, this.instantiatedFromDefinition = t.instantiatedFromDefinition ?? !1,
436
- this.isAppModule || this._internalInit({
437
- ...i,
438
- ...t
439
- });
369
+ this.value = e;
440
370
  }
441
- get(e, i) {
442
- return this.__get(e, {
443
- optional: i ?? !1
444
- });
371
+ emit(e) {
372
+ this.value = e, this.subscribers.forEach((e => e(this.value)));
445
373
  }
446
- getMany(...e) {
447
- return e.map((e => {
448
- const i = b(e) && "provider" in e;
449
- return this.get(i ? e.provider : e, !!i && e.isOptional);
450
- }));
374
+ get() {
375
+ return this.value;
451
376
  }
452
- lazyImport(...e) {
453
- this.injectImportedModules(e);
377
+ subscribe(e, t) {
378
+ return this.subscribers.add(e), t && e(this.value), () => this.subscribers.delete(e);
454
379
  }
455
- toNaked() {
456
- return this;
380
+ dispose() {
381
+ this.subscribers = null, this.value = null;
457
382
  }
458
- async dispose() {
459
- const {before: e, after: i} = this.onDispose?.() ?? {};
460
- await (e?.(this)), await this.__unbindAll(), this.container = null, this.imports = null,
461
- this.providers = null, this.exports = null, this.registeredSideEffects = null, this.isDisposed = !0,
462
- await (i?.(this));
383
+ }, j = class {
384
+ static {
385
+ n(this, "DynamicModuleDefinition");
463
386
  }
464
- toString() {
465
- return ("symbol" == typeof this.identifier ? this.identifier.description : this.identifier) ?? "Unknown";
387
+ get moduleContainer() {
388
+ return this.providerModule.moduleContainer;
466
389
  }
467
- setIdentifier(e) {
468
- if (!e) throw new U(this);
469
- return e;
390
+ get subscribe() {
391
+ if (null === this.event$) throw new P(this.providerModule);
392
+ return this.event$.subscribe.bind(this.event$);
470
393
  }
471
- prepareContainer(e) {
472
- return this.isAppModule ? e.container?.() ?? L : e.container ? (console.warn(`[xInjection]: The '${this.toString()}' module is overwriting its container!`),
473
- e.container()) : new z.Container({
474
- parent: L,
475
- defaultScope: this.defaultScope.inversify
476
- });
394
+ moduleDef;
395
+ event$=new B({
396
+ type: p.Noop,
397
+ change: null
398
+ });
399
+ providerModule;
400
+ emittingModules=new Set;
401
+ importedModuleSubscriptions=new Map;
402
+ constructor(e) {
403
+ this.providerModule = e, this.moduleDef = {
404
+ imports: new Set,
405
+ providers: new Set,
406
+ exports: new Set
407
+ }, this.buildInitialDefinition(e.options);
408
+ }
409
+ addImport(e, t = !1) {
410
+ let i = g.tryBlueprintToModule(e);
411
+ const o = this.providerModule.middlewaresManager.applyMiddlewares(a.BeforeAddImport, i);
412
+ !1 !== o && (i = o, this.moduleDef.imports.add(i), this.createImportedModuleContainer(i),
413
+ this.subscribeToImportedModuleEvents(i), this.emitEventSafely({
414
+ type: p.Export,
415
+ change: i
416
+ }), this.emitEventSafely({
417
+ type: p.Import,
418
+ change: i
419
+ }), t && (this.moduleDef.exports.add(i), this.emitEventSafely({
420
+ type: p.ExportModule,
421
+ change: i
422
+ })));
477
423
  }
478
- injectImportedModules(i) {
479
- i && 0 !== i.length && i.forEach((i => {
480
- if ("GlobalAppModule" === i.toString()) throw new F(this, "The 'GlobalAppModule' can't be imported!");
481
- if (!this.isAppModule && i.isGlobal) return void this.moduleUtils.appModule._importWithoutSecondaryImportCheck(i);
482
- const t = I.isModuleDefinition(i) ? new e(I.buildInternalConstructorParams({
483
- ...i.getDefinition(),
484
- instantiatedFromDefinition: !0
485
- })) : i;
486
- t.exports.forEach((i => {
487
- const n = I.tryStaticOrLazyExportToStaticExport(this, i);
488
- if (!n) return;
489
- if (n instanceof e) return void this.injectImportedModules([ n ]);
490
- const o = n, s = f.toServiceIdentifier(o), d = {
491
- scope: f.getInjectionScopeByPriority(o, t.defaultScope.native),
492
- provide: s,
493
- useFactory: r((() => t.get(o)), "useFactory")
494
- };
495
- this.moduleUtils.bindToContainer(d, t.defaultScope.native), t.registerSideEffect(o, "unbind", (() => this.__unbind(d)), {
496
- registerModuleId: this.identifier
497
- }), this._onUnbind(s, (() => {
498
- const e = t.registeredSideEffects.get(s);
499
- e && (e.onUnbindEffects = e.onUnbindEffects.filter((e => e.registerModuleId !== this.identifier)));
500
- }));
501
- }));
502
- }));
424
+ async addImportLazy(e, t) {
425
+ const i = await e();
426
+ this.addImport(i, t);
427
+ }
428
+ addProvider(e, t = !1) {
429
+ const i = this.providerModule.middlewaresManager.applyMiddlewares(a.BeforeAddProvider, e);
430
+ !1 !== i && (e = i, this.moduleDef.providers.add(e), this.moduleContainer.bindToContainer(e),
431
+ this.emitEventSafely({
432
+ type: p.Provider,
433
+ change: e
434
+ }), t && (this.moduleDef.exports.add(e), this.emitEventSafely({
435
+ type: p.Export,
436
+ change: e
437
+ }), this.emitEventSafely({
438
+ type: p.ExportProvider,
439
+ change: e
440
+ })));
503
441
  }
504
- injectProviders() {
505
- this.providers.forEach((e => this.moduleUtils.bindToContainer(e, this.defaultScope.native)));
442
+ async addProviderLazy(e, t) {
443
+ const i = await e();
444
+ this.addProvider(i, t);
445
+ }
446
+ removeImport(e) {
447
+ if (!this.moduleDef.imports.has(e)) return !1;
448
+ if (!1 === this.providerModule.middlewaresManager.applyMiddlewares(a.BeforeRemoveImport, e)) return !1;
449
+ this.unsubscribeFromImportedModuleEvents(e);
450
+ return this.providerModule.importedModuleContainers.get(e).dispose(), this.providerModule.importedModuleContainers.delete(e),
451
+ this.moduleDef.imports.delete(e), this.emitEventSafely({
452
+ type: p.ImportRemoved,
453
+ change: e
454
+ }), this.removeFromExports(e), !0;
455
+ }
456
+ removeProvider(e) {
457
+ if (!this.moduleDef.providers.has(e)) return !1;
458
+ return !1 !== this.providerModule.middlewaresManager.applyMiddlewares(a.BeforeRemoveProvider, e) && (this.moduleDef.providers.delete(e),
459
+ this.moduleContainer.container.unbindSync(h.toProviderIdentifier(e)), this.emitEventSafely({
460
+ type: p.ProviderRemoved,
461
+ change: e
462
+ }), this.removeFromExports(e), !0);
463
+ }
464
+ removeFromExports(e) {
465
+ if (!this.moduleDef.exports.has(e)) return !1;
466
+ return !1 !== this.providerModule.middlewaresManager.applyMiddlewares(a.BeforeRemoveExport, e) && (this.moduleDef.exports.delete(e),
467
+ this.emitEventSafely({
468
+ type: p.ExportRemoved,
469
+ change: e
470
+ }), g.isModule(e) ? this.emitEventSafely({
471
+ type: p.ExportModuleRemoved,
472
+ change: e
473
+ }) : this.emitEventSafely({
474
+ type: p.ExportProviderRemoved,
475
+ change: e
476
+ }), !0);
477
+ }
478
+ emitEventSafely(e) {
479
+ if (!this.emittingModules.has(this.providerModule)) try {
480
+ this.emittingModules.add(this.providerModule), this.event$.emit(e);
481
+ } finally {
482
+ this.emittingModules.delete(this.providerModule);
483
+ }
506
484
  }
507
- registerSideEffect(e, i, t, n) {
508
- const o = f.toServiceIdentifier(e);
509
- this.registeredSideEffects.has(o) || this.registeredSideEffects.set(o, {
510
- onBindEffects: [],
511
- onGetEffects: [],
512
- onRebindEffects: [],
513
- onUnbindEffects: []
514
- });
515
- const r = this.registeredSideEffects.get(o);
516
- "bind" === i ? r.onBindEffects.push(t) : "get" === i ? r.onGetEffects.push({
517
- once: n.once,
518
- invoked: !1,
519
- cb: t
520
- }) : "rebind" === i ? r.onRebindEffects.push(t) : "unbind" === i && r.onUnbindEffects.push({
521
- registerModuleId: n?.registerModuleId,
522
- cb: t
523
- });
485
+ dispose() {
486
+ this.importedModuleSubscriptions = null, this.emittingModules = null, this.event$.dispose(),
487
+ this.event$ = null, this.moduleDef = null;
488
+ }
489
+ buildInitialDefinition({imports: e = [], providers: t = [], exports: i = []}) {
490
+ this.moduleDef.providers = new Set(t), i.forEach((e => {
491
+ g.isModuleOrBlueprint(e) || this.moduleDef.exports.add(e);
492
+ })), e.forEach((e => {
493
+ if (g.isModule(e) ? e.options.isGlobal : e.isGlobal) return;
494
+ const t = g.tryBlueprintToModule(e), o = i.some((e => g.isModuleOrBlueprint(e) && e.id === t.id));
495
+ this.addImport(t, o);
496
+ }));
524
497
  }
525
- invokeRegisteredSideEffects(e, i) {
526
- const t = f.toServiceIdentifier(e), n = this.registeredSideEffects.get(t);
527
- n && n[`${i}Effects`].forEach((e => {
528
- if ("function" == typeof e) return e();
529
- if ("onGet" === i) {
530
- const i = e;
531
- if (i.invoked && i.once) return;
532
- i.invoked = !0;
498
+ createImportedModuleContainer(e) {
499
+ if (e.isAppModule) throw new b(this.providerModule, "The 'AppModule' can't be imported!");
500
+ this.providerModule.importedModuleContainers.set(e, new T(this.providerModule, e));
501
+ }
502
+ subscribeToImportedModuleEvents(e) {
503
+ if (this.importedModuleSubscriptions.has(e)) return;
504
+ const t = e.dynamicModuleDef.event$.subscribe((({type: e, change: t}) => {
505
+ switch (e) {
506
+ case p.Export:
507
+ case p.ExportRemoved:
508
+ case p.ExportModule:
509
+ case p.ExportModuleRemoved:
510
+ case p.ExportProvider:
511
+ case p.ExportProviderRemoved:
512
+ this.emitEventSafely({
513
+ type: e,
514
+ change: t
515
+ });
533
516
  }
534
- e.cb();
535
517
  }));
518
+ this.importedModuleSubscriptions.set(e, t);
536
519
  }
537
- async removeRegisteredSideEffects(e) {
538
- if (!this.registeredSideEffects) return;
539
- if ("all" === e) return this.registeredSideEffects.forEach((({onUnbindEffects: e}) => e.forEach((e => e.cb())))),
540
- void this.registeredSideEffects.clear();
541
- const i = f.toServiceIdentifier(e);
542
- if (!this.registeredSideEffects.has(i)) return;
543
- const t = this.registeredSideEffects.get(i)?.onUnbindEffects ?? [];
544
- for (const e of t) await e.cb();
545
- this.registeredSideEffects.delete(i);
546
- }
547
- shouldThrowIfDisposed() {
548
- if (null === this.container) throw new q(this);
549
- }
550
- _internalInit(e) {
551
- const {options: {isGlobal: i, imports: t = [], providers: n = [], exports: o = [], defaultScope: r = c.Singleton, onReady: s, onDispose: d}, internalOptions: a} = I.getOptionsOrModuleDefinitionOptions(e);
552
- return this.isGlobal = i ?? !1, this.isDisposed = !1, this.imports = t, this.providers = n,
553
- this.exports = o, this.defaultScope = {
554
- native: r,
555
- inversify: u(r)
556
- }, this.onReady = s, this.onDispose = d, this.container = this.prepareContainer({
557
- ...a
558
- }), this.moduleUtils = new V(this, a), this.registeredSideEffects = new Map, this.injectImportedModules(this.imports),
559
- this.injectProviders(), this.onReady?.(this), this;
560
- }
561
- _onBind(e, i) {
562
- this.shouldThrowIfDisposed(), this.registerSideEffect(e, "bind", i);
563
- }
564
- _onGet(e, i, t) {
565
- if (this.shouldThrowIfDisposed(), "boolean" != typeof i) throw new F(this, `The 'once' parameter is required when using the '${this._onGet.name}' method!`);
566
- this.registerSideEffect(e, "get", t, {
567
- once: i
568
- });
569
- }
570
- _onRebind(e, i) {
571
- this.shouldThrowIfDisposed(), this.registerSideEffect(e, "rebind", i);
520
+ unsubscribeFromImportedModuleEvents(e) {
521
+ const t = this.importedModuleSubscriptions.get(e);
522
+ t && (t(), this.importedModuleSubscriptions.delete(e));
572
523
  }
573
- _onUnbind(e, i) {
574
- this.shouldThrowIfDisposed(), this.registerSideEffect(e, "unbind", i);
575
- }
576
- _overwriteContainer(e) {
577
- this.container = e();
578
- }
579
- __bind(e) {
580
- this.shouldThrowIfDisposed();
581
- const i = this.container.bind(f.toServiceIdentifier(e));
582
- return this.invokeRegisteredSideEffects(e, "onBind"), i;
524
+ }, O = class {
525
+ static {
526
+ n(this, "MiddlewaresManager");
583
527
  }
584
- __get(e, i) {
585
- return this.shouldThrowIfDisposed(), this.invokeRegisteredSideEffects(e, "onGet"),
586
- this.container.get(f.toServiceIdentifier(e), i);
528
+ middlewaresMap=new Map;
529
+ providerModule;
530
+ constructor(e) {
531
+ this.providerModule = e;
532
+ }
533
+ add(e, t) {
534
+ const i = this.middlewaresMap.get(e);
535
+ i ? i.push(t) : this.middlewaresMap.set(e, [ t ]);
536
+ }
537
+ applyMiddlewares(e, ...t) {
538
+ if (null === this.middlewaresMap) throw new P(this.providerModule);
539
+ const i = this.middlewaresMap.get(e);
540
+ switch (e) {
541
+ case a.BeforeAddImport:
542
+ case a.BeforeAddProvider:
543
+ if (!i) return t[0];
544
+ let e = t[0];
545
+ for (const t of i) {
546
+ const i = t(e);
547
+ if (!1 === i) return !1;
548
+ !0 !== i && (e = i);
549
+ }
550
+ return e;
551
+
552
+ case a.BeforeGet:
553
+ return i ? i.reduce(((e, i) => i(e, t[1], t[2])), t[0]) : t[0];
554
+
555
+ case a.BeforeRemoveImport:
556
+ case a.BeforeRemoveProvider:
557
+ case a.BeforeRemoveExport:
558
+ case a.OnExportAccess:
559
+ return !i || !i.some((e => !e(t[0], t[1])));
560
+ }
587
561
  }
588
- async __getAsync(e, i) {
589
- return this.shouldThrowIfDisposed(), this.container.getAsync(f.toServiceIdentifier(e), i);
562
+ clear() {
563
+ this.middlewaresMap.clear();
590
564
  }
591
- __getAll(e, i) {
592
- return this.shouldThrowIfDisposed(), this.container.getAll(f.toServiceIdentifier(e), i);
565
+ dispose() {
566
+ this.middlewaresMap = null;
593
567
  }
594
- async __getAllAsync(e, i) {
595
- return this.shouldThrowIfDisposed(), this.container.getAllAsync(f.toServiceIdentifier(e), i);
568
+ }, A = class e {
569
+ static {
570
+ n(this, "ProviderModuleBlueprint");
596
571
  }
597
- __isBound(e, i) {
598
- return this.shouldThrowIfDisposed(), this.container.isBound(f.toServiceIdentifier(e), i);
572
+ id;
573
+ imports;
574
+ providers;
575
+ exports;
576
+ defaultScope;
577
+ isGlobal;
578
+ onReady;
579
+ onReset;
580
+ onDispose;
581
+ blueprintOptions;
582
+ constructor(e, t) {
583
+ this.updateDefinition(e), this.blueprintOptions = {
584
+ autoImportIntoAppModuleWhenGlobal: t?.autoImportIntoAppModuleWhenGlobal ?? !0
585
+ }, this.convertToModuleAndInjectIntoAppModuleIfGlobal();
599
586
  }
600
- __isCurrentBound(e, i) {
601
- return this.shouldThrowIfDisposed(), this.container.isCurrentBound(f.toServiceIdentifier(e), i);
587
+ updateDefinition(e) {
588
+ return this.id = e.id, this.imports = e.imports, this.providers = e.providers, this.exports = e.exports,
589
+ this.defaultScope = e.defaultScope, this.isGlobal = e.isGlobal, this.onReady = e.onReady,
590
+ this.onReset = e.onReset, this.onDispose = e.onDispose, this;
602
591
  }
603
- __takeSnapshot() {
604
- this.shouldThrowIfDisposed(), this.container.snapshot();
592
+ getDefinition() {
593
+ return {
594
+ id: this.id,
595
+ imports: this.imports,
596
+ providers: this.providers,
597
+ exports: this.exports,
598
+ defaultScope: this.defaultScope,
599
+ isGlobal: this.isGlobal,
600
+ onReady: this.onReady,
601
+ onReset: this.onReset,
602
+ onDispose: this.onDispose
603
+ };
605
604
  }
606
- __restoreSnapshot() {
607
- this.shouldThrowIfDisposed(), this.container.restore();
605
+ clone() {
606
+ return new e(k(this.getDefinition()), {
607
+ ...this.blueprintOptions
608
+ });
608
609
  }
609
- async __rebind(e) {
610
- this.shouldThrowIfDisposed();
611
- const i = await this.container.rebind(f.toServiceIdentifier(e));
612
- return this.invokeRegisteredSideEffects(e, "onRebind"), i;
610
+ convertToModuleAndInjectIntoAppModuleIfGlobal() {
611
+ this.isGlobal && this.blueprintOptions?.autoImportIntoAppModuleWhenGlobal && G.APP_MODULE_REF.update.addImport(this);
613
612
  }
614
- __rebindSync(e) {
615
- this.shouldThrowIfDisposed();
616
- const i = this.container.rebindSync(f.toServiceIdentifier(e));
617
- return this.invokeRegisteredSideEffects(e, "onRebind"), i;
613
+ }, G = class e {
614
+ static {
615
+ n(this, "ProviderModule");
616
+ }
617
+ get id() {
618
+ return this.options.id;
619
+ }
620
+ get definition() {
621
+ return this.throwIfDisposed(), this.dynamicModuleDef.moduleDef;
622
+ }
623
+ get update() {
624
+ return this.throwIfDisposed(), this.dynamicModuleDef;
625
+ }
626
+ get middlewares() {
627
+ return this.throwIfDisposed(), this.middlewaresManager;
628
+ }
629
+ get isDisposed() {
630
+ return this.disposed;
631
+ }
632
+ get isAppModule() {
633
+ return "AppModule" === this.id;
634
+ }
635
+ static APP_MODULE_REF;
636
+ appModuleRef;
637
+ options;
638
+ middlewaresManager;
639
+ dynamicModuleDef;
640
+ moduleContainer;
641
+ importedModuleContainers=new Map;
642
+ disposed=!1;
643
+ constructor({appModuleRef: t = e.APP_MODULE_REF, inversify: i, ...o}) {
644
+ this.appModuleRef = t, this.options = o, this.throwIfIdIsMissing(), this.middlewaresManager = new O(this),
645
+ this.moduleContainer = new C(this, i?.parentContainer), this.dynamicModuleDef = new j(this),
646
+ !this.isAppModule && this.options.isGlobal && this.appModuleRef.update.addImport(this, !0),
647
+ this.options.onReady?.(this);
648
+ }
649
+ static create(t) {
650
+ const i = g.isBlueprint(t) ? t.getDefinition() : t;
651
+ if ("AppModule" === i.id) throw new I("The 'AppModule' id can't be used as it is already being used by the built-in 'AppModule'");
652
+ return new e(i);
653
+ }
654
+ static blueprint(e, t) {
655
+ return new A(e, t);
656
+ }
657
+ isImportingModule(e) {
658
+ return this.throwIfDisposed(), g.isModule(e) ? this.importedModuleContainers.has(e) : this.importedModuleContainers.keys().some((t => t.id === e));
659
+ }
660
+ hasProvider(e) {
661
+ this.throwIfDisposed();
662
+ const t = h.toProviderIdentifier(e);
663
+ return this.moduleContainer.container.isBound(t);
664
+ }
665
+ get(e, t, i) {
666
+ this.throwIfDisposed();
667
+ const o = this.moduleContainer.get(e, t, i);
668
+ return this.dynamicModuleDef.emitEventSafely({
669
+ type: p.GetProvider,
670
+ change: o
671
+ }), o;
618
672
  }
619
- async __unbind(e) {
620
- this.shouldThrowIfDisposed(), await this.container.unbind(f.toServiceIdentifier(e)),
621
- await this.removeRegisteredSideEffects(e);
673
+ getMany(...e) {
674
+ return this.throwIfDisposed(), this.moduleContainer.getMany(...e);
675
+ }
676
+ isExportingModule(e) {
677
+ return this.throwIfDisposed(), !!this.isImportingModule(e) && (g.isModule(e) ? this.definition.exports.has(e) : this.definition.exports.keys().some((t => g.isModule(t) && t.id === e)));
678
+ }
679
+ isExportingProvider(e) {
680
+ this.throwIfDisposed();
681
+ let t = this.definition.exports.has(e);
682
+ return !t && h.isProviderIdentifier(e) && (t = this.definition.exports.keys().some((t => !g.isModuleOrBlueprint(t) && h.toProviderIdentifier(t) === e))),
683
+ t;
684
+ }
685
+ async reset(e = !0) {
686
+ let t, i;
687
+ if (this.throwIfDisposed(), e) {
688
+ const e = this.options.onReset?.() ?? {};
689
+ t = e.before, i = e.after, await (t?.(this));
690
+ }
691
+ this.middlewaresManager.clear(), this.moduleContainer.container.unbindAll(), this.definition.imports.clear(),
692
+ this.definition.providers.clear(), this.definition.exports.clear(), this.importedModuleContainers.clear(),
693
+ e && await (i?.());
622
694
  }
623
- __unbindSync(e) {
624
- this.shouldThrowIfDisposed(), this.container.unbindSync(f.toServiceIdentifier(e)),
625
- this.removeRegisteredSideEffects(e);
695
+ async dispose() {
696
+ this.throwIfDisposed();
697
+ const {before: e, after: t} = this.options.onDispose?.() ?? {};
698
+ await (e?.(this)), await this.reset(!1), this.middlewaresManager.dispose(), this.dynamicModuleDef.dispose(),
699
+ this.importedModuleContainers.forEach((e => e.dispose())), this.moduleContainer.dispose(),
700
+ this.options = {
701
+ id: this.options.id
702
+ }, this.dynamicModuleDef = null, this.importedModuleContainers = null, this.moduleContainer = null,
703
+ this.disposed = !0, await (t?.());
626
704
  }
627
- async __unbindAll() {
628
- this.shouldThrowIfDisposed(), await this.container.unbindAll(), await this.removeRegisteredSideEffects("all");
705
+ toString() {
706
+ return this.id.toString();
629
707
  }
630
- }, H = class extends W {
631
- static {
632
- r(this, "GlobalAppModule");
633
- }
634
- _strict;
635
- nakedModule=this;
636
- isLoaded=!1;
637
- constructor() {
638
- super(I.buildInternalConstructorParams({
639
- identifier: d,
640
- isAppModule: !0
641
- }));
708
+ throwIfIdIsMissing() {
709
+ if (!this.options.id || 0 === this.options.id.toString().trim().length) throw new x(this);
642
710
  }
643
- register(e) {
644
- if (this.isLoaded) throw new x(`The '${this.toString()}' has already been registered!`);
645
- return this._strict = e._strict ?? !0, this.nakedModule._internalInit(e), this.checkIfRegisteredModulesHaveGlobalMark(this.nakedModule, this.imports),
646
- this.isLoaded = !0, this;
711
+ throwIfDisposed() {
712
+ if (this.isDisposed) throw new P(this);
647
713
  }
648
- lazyImport(...e) {
649
- this.checkIfRegisteredModulesHaveGlobalMark(this.nakedModule, e), super.lazyImport(...e);
714
+ };
715
+
716
+ function F(e) {
717
+ return "function" == typeof e && !Function.prototype.toString.call(e).startsWith("class ");
718
+ }
719
+
720
+ function k(e) {
721
+ if (null === e || "object" != typeof e) return e;
722
+ if ("function" == typeof e) return (...t) => e(...t);
723
+ if (Array.isArray(e)) return e.map((e => k(e)));
724
+ const t = {};
725
+ for (const i in e) Object.prototype.hasOwnProperty.call(e, i) && (t[i] = k(e[i]));
726
+ return t;
727
+ }
728
+
729
+ function q(e) {
730
+ return void 0 === e ? (0, d.injectable)() : (0, d.injectable)(l(e));
731
+ }
732
+
733
+ !function(e) {
734
+ function t(e) {
735
+ return e instanceof G;
650
736
  }
651
- toNaked() {
652
- return super.toNaked();
737
+ function i(e) {
738
+ return e instanceof A;
653
739
  }
654
- async dispose() {
655
- this.isLoaded = !1, await super.dispose();
740
+ function o(e) {
741
+ return t(e) || i(e);
656
742
  }
657
- _importWithoutSecondaryImportCheck(...e) {
658
- this.checkIfRegisteredModulesHaveGlobalMark(this.nakedModule, e, !0), super.lazyImport(...e);
743
+ function r(e) {
744
+ return e instanceof A ? s(e) : e;
659
745
  }
660
- checkIfRegisteredModulesHaveGlobalMark(e, i, t = !1) {
661
- this._strict && (i.forEach((i => {
662
- const n = I.tryStaticOrLazyExportToStaticExport(this, i), o = I.isModuleDefinition(n);
663
- if (n instanceof W || o) {
664
- if (n.isGlobal) return y.delete(n), void (n.exports && this.checkIfRegisteredModulesHaveGlobalMark(n, n.exports, !0));
665
- throw new N(n, t ? `Is not marked as \`global\` but has been imported into the \`AppModule\` via the \`${e.toString()}\` module!` : "Is not marked as `global` but has been imported into the `AppModule`!");
666
- }
667
- })), t || y.forEach((e => {
668
- throw new N(e, "Is marked as 'global' and has not been imported into the 'AppModule'!");
669
- })));
746
+ function s(e) {
747
+ return G.create(e.getDefinition());
670
748
  }
671
- }, $ = new H;//# sourceMappingURL=index.cjs.map
749
+ n(t, "isModule"), e.isModule = t, n(i, "isBlueprint"), e.isBlueprint = i, n(o, "isModuleOrBlueprint"),
750
+ e.isModuleOrBlueprint = o, n(r, "tryBlueprintToModule"), e.tryBlueprintToModule = r,
751
+ n(s, "blueprintToModule"), e.blueprintToModule = s;
752
+ }(g || (g = {})), n(F, "isFunction"), n(k, "deepClone"), n(q, "Injectable");
753
+
754
+ var $ = require("inversify");
755
+
756
+ function V(e) {
757
+ return (0, $.inject)(h.toProviderIdentifier(e));
758
+ }
759
+
760
+ n(V, "Inject");
761
+
762
+ var _ = require("inversify");
763
+
764
+ function U(e) {
765
+ return (0, _.multiInject)(h.toProviderIdentifier(e));
766
+ }
767
+
768
+ n(U, "MultiInject");
769
+
770
+ var L = require("inversify");
771
+
772
+ function N(e) {
773
+ return (0, L.injectFromBase)(e);
774
+ }
775
+
776
+ n(N, "InjectFromBase");
777
+
778
+ var W = require("inversify");
779
+
780
+ function H(e) {
781
+ return (0, W.named)(e);
782
+ }
783
+
784
+ n(H, "Named");
785
+
786
+ var z = require("inversify");
787
+
788
+ function J() {
789
+ return (0, z.optional)();
790
+ }
791
+
792
+ n(J, "Optional");
793
+
794
+ var K = require("inversify");
795
+
796
+ function Q(e, t) {
797
+ return (0, K.tagged)(e, t);
798
+ }
799
+
800
+ n(Q, "Tagged");
801
+
802
+ var X = require("inversify");
803
+
804
+ function Y() {
805
+ return (0, X.unmanaged)();
806
+ }
807
+
808
+ n(Y, "Unmanaged");
809
+
810
+ var Z = new G({
811
+ id: "AppModule"
812
+ });
813
+
814
+ G.APP_MODULE_REF = Z;//# sourceMappingURL=index.cjs.map