@kaokei/di 3.0.8 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,24 +1,22 @@
1
- var O = Object.defineProperty;
2
- var R = (e, t, n) => t in e ? O(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
- var r = (e, t, n) => R(e, typeof t != "symbol" ? t + "" : t, n);
1
+ var L = Object.defineProperty;
2
+ var j = (n, t, e) => t in n ? L(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
3
+ var r = (n, t, e) => j(n, typeof t != "symbol" ? t + "" : t, e);
4
4
  const l = {
5
- // 记录构造函数参数装饰器对应的数据的key
6
- INJECTED_PARAMS: "injected:params",
7
- // 记录实例属性装饰器对应的数据的key
5
+ // 记录实例属性装饰器对应的数据的键
8
6
  INJECTED_PROPS: "injected:props",
9
- // Inject装饰器的key
7
+ // Inject 装饰器的键
10
8
  INJECT: "inject",
11
- // Self装饰器的key
9
+ // Self 装饰器的键
12
10
  SELF: "self",
13
- // SkipSelf装饰器的key
11
+ // SkipSelf 装饰器的键
14
12
  SKIP_SELF: "skipSelf",
15
- // Optional装饰器的key
13
+ // Optional 装饰器的键
16
14
  OPTIONAL: "optional",
17
- // PostConstruct装饰器的key
15
+ // PostConstruct 装饰器的键
18
16
  POST_CONSTRUCT: "postConstruct",
19
- // PreDestroy装饰器的key
17
+ // PreDestroy 装饰器的键
20
18
  PRE_DESTROY: "preDestroy"
21
- }, p = {
19
+ }, f = {
22
20
  DEFAULT: "default",
23
21
  INITING: "initing",
24
22
  ACTIVATED: "activated"
@@ -28,89 +26,99 @@ const l = {
28
26
  ConstantValue: "ConstantValue",
29
27
  DynamicValue: "DynamicValue"
30
28
  }, C = {
31
- POST_CONSTRUCT: "Cannot apply @PostConstruct decorator multiple times in the same class.",
32
- PRE_DESTROY: "Cannot apply @PreDestroy decorator multiple times in the same class.",
33
- MISS_INJECT: "Expected a @Inject decorator to explicitly specify the token.",
34
- MISS_CONTAINER: "@LazyInject decorator cannot find the corresponding container."
35
- }, D = Symbol(), S = /* @__PURE__ */ new WeakMap();
36
- function w(e) {
37
- return typeof e == "function" && Object.getPrototypeOf(e) !== Function.prototype;
29
+ // 用于 decorator.ts createMetaDecorator —— 重复装饰器检测
30
+ POST_CONSTRUCT: "Multiple @PostConstruct decorators are not allowed in a single class.",
31
+ PRE_DESTROY: "Multiple @PreDestroy decorators are not allowed in a single class.",
32
+ // 用于 token.ts resolveToken —— 无效 token
33
+ INVALID_TOKEN: "@Inject or @LazyInject requires a valid token, but received null or undefined.",
34
+ // 用于 decorator.ts 的 defineLazyProperty —— 无效 token
35
+ LAZY_INJECT_INVALID_TOKEN: "@LazyInject requires a valid token, but received null or undefined."
36
+ };
37
+ function m(n, t) {
38
+ return Object.prototype.hasOwnProperty.call(n, t);
39
+ }
40
+ const D = Symbol("UNINITIALIZED"), A = /* @__PURE__ */ new WeakMap();
41
+ function k(n) {
42
+ return typeof n == "function" && Object.getPrototypeOf(n) !== Function.prototype;
38
43
  }
39
- function b(e, t, n) {
40
- const s = S.get(n) || {};
41
- s[e] = t, S.set(n, s);
44
+ function V(n, t, e) {
45
+ const i = A.get(e) || {};
46
+ i[n] = t, A.set(e, i);
42
47
  }
43
- function E(e, t) {
44
- return (S.get(t) || {})[e];
48
+ function P(n, t) {
49
+ return (A.get(t) || {})[n];
45
50
  }
46
- function y(e, t) {
47
- const n = E(e, t);
48
- if (!w(t))
49
- return n;
50
- const s = y(
51
- e,
51
+ function T(n, t) {
52
+ const e = P(n, t);
53
+ if (!k(t))
54
+ return e;
55
+ const i = T(
56
+ n,
52
57
  Object.getPrototypeOf(t)
53
58
  );
54
- if (s || n)
59
+ if (i || e)
55
60
  return {
56
- ...s || {},
57
- ...n || {}
61
+ ...i || {},
62
+ ...e || {}
58
63
  };
59
64
  }
60
- class J {
65
+ class G {
61
66
  constructor(t) {
62
- r(this, "_", "");
67
+ // 仅类型层面存在,无运行时开销
63
68
  r(this, "name");
64
69
  this.name = t;
65
70
  }
66
71
  }
67
72
  class B {
68
73
  constructor(t) {
69
- r(this, "callback");
70
- this.callback = t;
74
+ r(this, "_callback");
75
+ this._callback = t;
71
76
  }
72
77
  resolve() {
73
- return this.callback();
78
+ return this._callback();
74
79
  }
75
80
  }
76
- function A(e) {
77
- if (!e)
78
- throw new Error(C.MISS_INJECT);
79
- return e instanceof B ? e.resolve() : e;
81
+ function S(n) {
82
+ if (!n)
83
+ throw new Error(C.INVALID_TOKEN);
84
+ return n instanceof B ? n.resolve() : n;
80
85
  }
81
- class T extends Error {
82
- constructor(t, n) {
83
- super(), this.name = this.constructor.name, this.message = `${t}${n == null ? void 0 : n.name}`;
86
+ class g extends Error {
87
+ constructor(e, i) {
88
+ const s = (i == null ? void 0 : i.name) || "<unknown token>";
89
+ super(`${e}${s}`);
90
+ r(this, "token");
91
+ this.name = this.constructor.name, this.token = i;
84
92
  }
85
93
  }
86
- class V extends T {
94
+ class w extends g {
87
95
  constructor(t) {
88
96
  super("");
89
- const n = [];
90
- let s = t;
91
- for (; s && s.token; )
92
- n.push(s.token), s = s.parent;
93
- const i = n.reverse().map((o) => o.name).join(" --> ");
94
- this.message = `Circular dependency found: ${i}`;
97
+ const e = [];
98
+ let i = t;
99
+ for (; i && i.token; )
100
+ e.push(i.token), i = i.parent;
101
+ const s = e.reverse().map((a) => a.name || "<anonymous>").join(" --> ");
102
+ this.message = `Circular dependency found: ${s}`;
95
103
  }
96
104
  }
97
- class _ extends T {
105
+ class H extends g {
98
106
  constructor(t) {
99
107
  super("Invalid binding: ", t);
100
108
  }
101
109
  }
102
- class H extends V {
110
+ class M extends w {
103
111
  constructor(t) {
104
112
  super(t), this.name = "CircularDependencyError inside @PostConstruct";
105
113
  }
106
114
  }
107
- class j {
108
- constructor(t, n) {
115
+ const y = class y {
116
+ constructor(t, e) {
109
117
  r(this, "container");
110
118
  r(this, "context");
111
119
  r(this, "token");
112
120
  r(this, "type", d.Invalid);
113
- r(this, "status", p.DEFAULT);
121
+ r(this, "status", f.DEFAULT);
114
122
  r(this, "classValue");
115
123
  r(this, "constantValue");
116
124
  r(this, "dynamicValue");
@@ -118,7 +126,7 @@ class j {
118
126
  r(this, "postConstructResult", D);
119
127
  r(this, "onActivationHandler");
120
128
  r(this, "onDeactivationHandler");
121
- this.container = n, this.context = { container: this.container }, this.token = t;
129
+ this.container = e, this.context = { container: this.container }, this.token = t;
122
130
  }
123
131
  onActivation(t) {
124
132
  this.onActivationHandler = t;
@@ -127,8 +135,8 @@ class j {
127
135
  this.onDeactivationHandler = t;
128
136
  }
129
137
  activate(t) {
130
- const n = this.onActivationHandler ? this.onActivationHandler(this.context, t) : t;
131
- return this.container.activate(n, this.token);
138
+ const e = this.onActivationHandler ? this.onActivationHandler(this.context, t) : t;
139
+ return this.container.activate(e, this.token);
132
140
  }
133
141
  deactivate() {
134
142
  this.onDeactivationHandler && this.onDeactivationHandler(this.cache);
@@ -147,102 +155,125 @@ class j {
147
155
  }
148
156
  toService(t) {
149
157
  return this.toDynamicValue(
150
- (n) => n.container.get(t, { parent: { token: this.token } })
158
+ (e) => e.container.get(t, { parent: { token: this.token } })
151
159
  );
152
160
  }
153
161
  get(t) {
154
- if (p.INITING === this.status)
155
- throw new V(t);
156
- if (p.ACTIVATED === this.status)
162
+ if (f.INITING === this.status)
163
+ throw new w(t);
164
+ if (f.ACTIVATED === this.status)
157
165
  return this.cache;
158
- if (d.Instance === this.type)
159
- return this.resolveInstanceValue(t);
160
- if (d.ConstantValue === this.type)
161
- return this.resolveConstantValue();
162
- if (d.DynamicValue === this.type)
163
- return this.resolveDynamicValue();
164
- throw new _(this.token);
165
- }
166
- getAwaitBindings(t, n) {
167
- return n === !0 ? t : Array.isArray(n) ? t.filter((s) => n.includes(s.token)) : typeof n == "function" ? t.filter(n) : [];
168
- }
169
- postConstruct(t, n, s) {
166
+ const e = y._resolvers[this.type];
167
+ if (e)
168
+ return this[e](t);
169
+ throw new H(this.token);
170
+ }
171
+ _getAwaitBindings(t, e) {
172
+ return e === !0 ? t : Array.isArray(e) ? t.filter((i) => e.includes(i.token)) : typeof e == "function" ? t.filter(e) : [];
173
+ }
174
+ /**
175
+ * PostConstruct 生命周期处理
176
+ *
177
+ * postConstructResult 的三种状态:
178
+ * - UNINITIALIZED(Symbol):PostConstruct 尚未执行,用于循环依赖检测
179
+ * - undefined:没有使用 @PostConstruct 装饰器,或 @PostConstruct() 无参数时同步执行完毕
180
+ * - Promise<void>:@PostConstruct(value) 有参数时,等待前置服务初始化后异步执行
181
+ *
182
+ * @PostConstruct() 无参数时:同步执行,不等待任何前置服务
183
+ * @PostConstruct(value) 有参数时:等待指定的前置服务初始化完成后再执行
184
+ * - 如果前置服务初始化成功,执行当前服务的 PostConstruct 方法
185
+ * - 如果前置服务初始化失败,rejected promise 自然传播,当前服务的 PostConstruct 不执行
186
+ */
187
+ _postConstruct(t, e) {
170
188
  if (d.Instance === this.type) {
171
- const { key: i, value: o } = y(l.POST_CONSTRUCT, this.classValue) || {};
189
+ const { key: i, value: s } = T(l.POST_CONSTRUCT, this.classValue) || {};
172
190
  if (i)
173
- if (o) {
174
- const a = [...n, ...s].filter(
175
- (u) => d.Instance === (u == null ? void 0 : u.type)
176
- ), c = this.getAwaitBindings(a, o);
177
- for (const u of c)
178
- if (u && u.postConstructResult === D)
179
- throw new H({
180
- token: u.token,
191
+ if (s) {
192
+ const a = e.filter(
193
+ (c) => d.Instance === (c == null ? void 0 : c.type)
194
+ ), o = this._getAwaitBindings(a, s);
195
+ for (const c of o)
196
+ if (c && c.postConstructResult === D)
197
+ throw new M({
198
+ token: c.token,
181
199
  parent: t
182
200
  });
183
- const h = c.map((u) => u.postConstructResult);
184
- this.postConstructResult = Promise.all(h).then(
185
- () => this.execute(i)
201
+ const u = o.map((c) => c.postConstructResult);
202
+ this.postConstructResult = Promise.all(u).then(
203
+ () => this._execute(i)
186
204
  );
187
205
  } else
188
- this.postConstructResult = this.execute(i);
206
+ this.postConstructResult = this._execute(i);
189
207
  else
190
208
  this.postConstructResult = void 0;
191
209
  }
192
210
  }
193
211
  preDestroy() {
194
212
  if (d.Instance === this.type) {
195
- const { key: t } = y(l.PRE_DESTROY, this.classValue) || {};
196
- t && this.execute(t);
213
+ const { key: t } = T(l.PRE_DESTROY, this.classValue) || {};
214
+ t && this._execute(t);
197
215
  }
198
- I.map.delete(this.cache), this.container = null, this.context = null, this.classValue = null, this.constantValue = null, this.dynamicValue = null, this.cache = null, this.postConstructResult = D, this.onActivationHandler = void 0, this.onDeactivationHandler = void 0;
199
- }
200
- execute(t) {
201
- const n = this.cache[t];
202
- return n == null ? void 0 : n.call(this.cache);
203
- }
204
- resolveInstanceValue(t) {
205
- this.status = p.INITING;
206
- const n = this.classValue, [s, i] = this.getConstructorParameters(t), o = new n(...s);
207
- this.cache = this.activate(o), this.status = p.ACTIVATED, I.map.set(this.cache, this.container);
208
- const [a, c] = this.getInjectProperties(t);
209
- return Object.assign(this.cache, a), this.postConstruct(t, i, c), this.cache;
210
- }
211
- resolveConstantValue() {
212
- return this.status = p.INITING, this.cache = this.activate(this.constantValue), this.status = p.ACTIVATED, this.cache;
213
- }
214
- resolveDynamicValue() {
215
- this.status = p.INITING;
216
- const t = this.dynamicValue.call(this, this.context);
217
- return this.cache = this.activate(t), this.status = p.ACTIVATED, this.cache;
218
- }
219
- getConstructorParameters(t) {
220
- const n = E(l.INJECTED_PARAMS, this.classValue) || [], s = [], i = [];
221
- for (let o = 0; o < n.length; o++) {
222
- const a = n[o], { inject: c, ...h } = a;
223
- h.parent = t;
224
- const u = this.container.get(A(c), h);
225
- s.push(u), i.push(h.binding);
216
+ I._instanceContainerMap.delete(this.cache), this.container = null, this.context = null, this.classValue = void 0, this.constantValue = void 0, this.dynamicValue = void 0, this.cache = void 0, this.postConstructResult = D, this.onActivationHandler = void 0, this.onDeactivationHandler = void 0;
217
+ }
218
+ _execute(t) {
219
+ const e = this.cache[t];
220
+ return e == null ? void 0 : e.call(this.cache);
221
+ }
222
+ _resolveInstanceValue(t) {
223
+ this.status = f.INITING;
224
+ const e = this._createInstance();
225
+ this.cache = this.activate(e), this.status = f.ACTIVATED, this._registerInstance();
226
+ const { properties: i, bindings: s } = this._getInjectProperties(t);
227
+ return this._injectProperties(i), this._postConstruct(t, s), this.cache;
228
+ }
229
+ // 创建类的实例
230
+ _createInstance() {
231
+ const t = this.classValue;
232
+ return new t();
233
+ }
234
+ // 注册实例与容器的映射关系
235
+ _registerInstance() {
236
+ I._instanceContainerMap.set(this.cache, this.container);
237
+ }
238
+ // 将解析后的属性注入到实例上
239
+ _injectProperties(t) {
240
+ Object.assign(this.cache, t);
241
+ }
242
+ _resolveConstantValue() {
243
+ return this.status = f.INITING, this.cache = this.activate(this.constantValue), this.status = f.ACTIVATED, this.cache;
244
+ }
245
+ _resolveDynamicValue() {
246
+ this.status = f.INITING;
247
+ const t = this.dynamicValue(this.context);
248
+ return this.cache = this.activate(t), this.status = f.ACTIVATED, this.cache;
249
+ }
250
+ _getInjectProperties(t) {
251
+ const e = T(l.INJECTED_PROPS, this.classValue) || {}, i = Object.keys(e), s = /* @__PURE__ */ Object.create(null), a = [];
252
+ for (let o = 0; o < i.length; o++) {
253
+ const u = i[o], c = e[u], { inject: p, ..._ } = c;
254
+ _.parent = t;
255
+ const h = this.container.get(
256
+ S(p),
257
+ _
258
+ );
259
+ h === void 0 && c.optional || (s[u] = h), a.push(_.binding);
226
260
  }
227
- return [s, i];
228
- }
229
- getInjectProperties(t) {
230
- const n = y(l.INJECTED_PROPS, this.classValue) || {}, s = Object.keys(n), i = /* @__PURE__ */ Object.create(null), o = [];
231
- for (let a = 0; a < s.length; a++) {
232
- const c = s[a], h = n[c], { inject: u, ...f } = h;
233
- f.parent = t;
234
- const g = this.container.get(A(u), f);
235
- g === void 0 && h.optional || (i[c] = g), o.push(f.binding);
236
- }
237
- return [i, o];
261
+ return { properties: s, bindings: a };
238
262
  }
239
- }
240
- class k extends T {
263
+ };
264
+ // 类型到解析方法的静态映射表,用于替代 get 方法中的 if-else 链
265
+ r(y, "_resolvers", {
266
+ [d.Instance]: "_resolveInstanceValue",
267
+ [d.ConstantValue]: "_resolveConstantValue",
268
+ [d.DynamicValue]: "_resolveDynamicValue"
269
+ });
270
+ let b = y;
271
+ class x extends g {
241
272
  constructor(t) {
242
273
  super("No matching binding found for token: ", t);
243
274
  }
244
275
  }
245
- class x extends T {
276
+ class F extends g {
246
277
  constructor(t) {
247
278
  super("Cannot bind token multiple times: ", t);
248
279
  }
@@ -251,29 +282,33 @@ const v = class v {
251
282
  constructor() {
252
283
  r(this, "parent");
253
284
  r(this, "children");
254
- r(this, "bindings", /* @__PURE__ */ new Map());
255
- r(this, "onActivationHandler");
256
- r(this, "onDeactivationHandler");
285
+ r(this, "_bindings", /* @__PURE__ */ new Map());
286
+ r(this, "_onActivationHandler");
287
+ r(this, "_onDeactivationHandler");
288
+ }
289
+ // 查询实例所属的容器
290
+ static getContainerOf(t) {
291
+ return v._instanceContainerMap.get(t);
257
292
  }
258
293
  bind(t) {
259
- if (this.bindings.has(t))
260
- throw new x(t);
261
- const n = this.buildBinding(t);
262
- return this.bindings.set(t, n), n;
294
+ if (this._bindings.has(t))
295
+ throw new F(t);
296
+ const e = this._buildBinding(t);
297
+ return this._bindings.set(t, e), e;
263
298
  }
264
299
  unbind(t) {
265
- if (this.bindings.has(t)) {
266
- const n = this.getBinding(t);
267
- this.deactivate(n), n.deactivate(), n.preDestroy(), this.bindings.delete(t);
300
+ if (this._bindings.has(t)) {
301
+ const e = this._getBinding(t);
302
+ this.deactivate(e), e.deactivate(), e.preDestroy(), this._bindings.delete(t);
268
303
  }
269
304
  }
270
305
  unbindAll() {
271
- this.bindings.forEach((t) => {
272
- this.unbind(t.token);
273
- });
306
+ const t = Array.from(this._bindings.keys());
307
+ for (const e of t)
308
+ this.unbind(e);
274
309
  }
275
310
  isCurrentBound(t) {
276
- return this.bindings.has(t);
311
+ return this._bindings.has(t);
277
312
  }
278
313
  isBound(t) {
279
314
  return this.isCurrentBound(t) || !!this.parent && this.parent.isBound(t);
@@ -283,124 +318,177 @@ const v = class v {
283
318
  return t.parent = this, this.children || (this.children = /* @__PURE__ */ new Set()), this.children.add(t), t;
284
319
  }
285
320
  destroy() {
286
- var t, n, s;
287
- this.unbindAll(), this.bindings.clear(), (n = (t = this.parent) == null ? void 0 : t.children) == null || n.delete(this), this.parent = void 0, (s = this.children) == null || s.clear(), this.children = void 0, this.onActivationHandler = void 0, this.onDeactivationHandler = void 0;
288
- }
289
- get(t, n = {}) {
290
- const s = this.getBinding(t);
291
- if (n.skipSelf) {
292
- if (this.parent)
293
- return n.skipSelf = !1, this.parent.get(t, n);
294
- } else if (n.self || s) {
295
- if (s)
296
- return n.token = t, n.binding = s, s.get(n);
297
- } else if (this.parent)
298
- return this.parent.get(t, n);
299
- return this.checkBindingNotFoundError(t, n);
321
+ var t, e;
322
+ if (this.children) {
323
+ const i = Array.from(this.children);
324
+ for (const s of i)
325
+ s.destroy();
326
+ }
327
+ this.unbindAll(), this._bindings.clear(), (e = (t = this.parent) == null ? void 0 : t.children) == null || e.delete(this), this.parent = void 0, this.children = void 0, this._onActivationHandler = void 0, this._onDeactivationHandler = void 0;
328
+ }
329
+ get(t, e = {}) {
330
+ return e.skipSelf ? this._resolveSkipSelf(t, e) : e.self ? this._resolveSelf(t, e) : this._resolveDefault(t, e);
331
+ }
332
+ // 处理 skipSelf 选项:跳过当前容器,委托父容器解析
333
+ _resolveSkipSelf(t, e) {
334
+ return this.parent ? (e.skipSelf = !1, this.parent.get(t, e)) : this._checkBindingNotFoundError(t, e);
335
+ }
336
+ // 处理 self 选项:仅在当前容器中查找
337
+ _resolveSelf(t, e) {
338
+ const i = this._getBinding(t);
339
+ return i ? (e.token = t, e.binding = i, i.get(e)) : this._checkBindingNotFoundError(t, e);
340
+ }
341
+ // 默认解析流程:当前容器 → 父容器 → 抛错
342
+ _resolveDefault(t, e) {
343
+ const i = this._getBinding(t);
344
+ return i ? (e.token = t, e.binding = i, i.get(e)) : this.parent ? this.parent.get(t, e) : this._checkBindingNotFoundError(t, e);
300
345
  }
301
346
  onActivation(t) {
302
- this.onActivationHandler = t;
347
+ this._onActivationHandler = t;
303
348
  }
304
349
  onDeactivation(t) {
305
- this.onDeactivationHandler = t;
350
+ this._onDeactivationHandler = t;
306
351
  }
307
- activate(t, n) {
308
- return this.onActivationHandler ? this.onActivationHandler({ container: this }, t, n) : t;
352
+ activate(t, e) {
353
+ return this._onActivationHandler ? this._onActivationHandler({ container: this }, t, e) : t;
309
354
  }
310
355
  deactivate(t) {
311
- this.onDeactivationHandler && this.onDeactivationHandler(t.cache, t.token);
356
+ this._onDeactivationHandler && this._onDeactivationHandler(t.cache, t.token);
312
357
  }
313
- buildBinding(t) {
314
- return new j(t, this);
358
+ _buildBinding(t) {
359
+ return new b(t, this);
315
360
  }
316
- getBinding(t) {
317
- return this.bindings.get(t);
361
+ _getBinding(t) {
362
+ return this._bindings.get(t);
318
363
  }
319
- checkBindingNotFoundError(t, n) {
320
- if (!n.optional)
321
- throw new k(t);
364
+ _checkBindingNotFoundError(t, e) {
365
+ if (!e.optional)
366
+ throw new x(t);
322
367
  }
323
368
  };
324
- r(v, "map", /* @__PURE__ */ new WeakMap());
369
+ // 实例到容器的映射表,用于 @LazyInject 查找实例所属容器
370
+ // 仅 Instance 类型的 binding 会注册映射(_registerInstance 仅在 _resolveInstanceValue 中调用)
371
+ // toConstantValue 和 toDynamicValue 不会触发注册,原因:
372
+ // 同一对象可能通过 toConstantValue 被绑定到多个容器,WeakMap 只能保留最后一次映射,
373
+ // 会导致 @LazyInject 从错误的容器解析依赖。
374
+ // 由于 Instance 类型每次都通过 new ClassName() 创建新实例,不存在同一实例被多个容器注册的覆盖风险
375
+ r(v, "_instanceContainerMap", /* @__PURE__ */ new WeakMap());
325
376
  let I = v;
326
- function m(e, t) {
327
- return function(n) {
328
- return function(s, i, o) {
329
- const a = typeof o == "number", c = a ? s : s.constructor, h = a ? o : i, u = a ? l.INJECTED_PARAMS : l.INJECTED_PROPS, f = a ? E(u, c) || [] : y(u, c) || {}, g = f[h] || {};
330
- g[e] = n === void 0 ? t : n, f[h] = g, b(u, f, c);
377
+ class z extends g {
378
+ constructor(t, e) {
379
+ super(
380
+ `@LazyInject(${t == null ? void 0 : t.name}) in class ${e.name} requires a registered container but none was found. Token: `,
381
+ t
382
+ );
383
+ }
384
+ }
385
+ function E(n, t) {
386
+ return function(e) {
387
+ return function(i, s) {
388
+ s.addInitializer(function() {
389
+ const a = this.constructor, o = s.name, u = P(l.INJECTED_PROPS, a) || {}, c = u[o] || {};
390
+ c[n] = e === void 0 ? t : e, u[o] = c, V(l.INJECTED_PROPS, u, a);
391
+ });
331
392
  };
332
393
  };
333
394
  }
334
- function N(e, t) {
335
- return (n) => (s, i) => {
336
- if (E(e, s.constructor))
395
+ function R(n, t) {
396
+ return (e) => (i, s) => {
397
+ const a = s.name, o = s.metadata;
398
+ if (m(o, n))
337
399
  throw new Error(t);
338
- b(
339
- e,
340
- { key: i, value: n },
341
- s.constructor
342
- );
400
+ o[n] = !0, s.addInitializer(function() {
401
+ const u = this.constructor;
402
+ V(n, { key: a, value: e }, u);
403
+ });
343
404
  };
344
405
  }
345
- const U = m(l.INJECT), G = m(l.SELF, !0), Y = m(l.SKIP_SELF, !0), z = m(l.OPTIONAL, !0), K = N(
406
+ const K = E(l.INJECT), $ = E(l.SELF, !0), Z = E(l.SKIP_SELF, !0), q = E(l.OPTIONAL, !0), W = R(
346
407
  l.POST_CONSTRUCT,
347
408
  C.POST_CONSTRUCT
348
- ), $ = N(
409
+ ), Q = R(
349
410
  l.PRE_DESTROY,
350
411
  C.PRE_DESTROY
351
412
  );
352
- function P(e, t, n, s) {
353
- for (let i = e.length - 1; i >= 0; i--)
354
- e[i](t, n, s);
355
- }
356
- function W(e, t, n) {
357
- e = Array.isArray(e) ? e : [e], typeof n == "number" ? P(e, t, void 0, n) : typeof n == "string" && P(e, t.prototype, n);
358
- }
359
- function M(e, t, n, s) {
360
- function i() {
361
- const a = Symbol.for(t);
362
- if (!this.hasOwnProperty(a)) {
363
- const c = s || I.map.get(this), h = this.constructor;
364
- if (!c)
365
- throw new Error(`${C.MISS_CONTAINER} ${h.name}`);
366
- this[a] = c.get(A(n), {
367
- parent: { token: h }
368
- });
369
- }
370
- return this[a];
371
- }
372
- function o(a) {
373
- const c = Symbol.for(t);
374
- this[c] = a;
375
- }
376
- Object.defineProperty(e, t, {
413
+ function U(n, t, e, i) {
414
+ if (e == null)
415
+ throw new Error(C.LAZY_INJECT_INVALID_TOKEN);
416
+ const s = Symbol.for(t);
417
+ Object.defineProperty(n, t, {
377
418
  configurable: !0,
378
419
  enumerable: !0,
379
- get: i,
380
- set: o
420
+ get() {
421
+ if (!m(n, s)) {
422
+ const a = i || I.getContainerOf(n), o = n.constructor;
423
+ if (!a)
424
+ throw new z(S(e), o);
425
+ n[s] = a.get(S(e), {
426
+ parent: { token: o }
427
+ });
428
+ }
429
+ return n[s];
430
+ },
431
+ set(a) {
432
+ n[s] = a;
433
+ }
381
434
  });
382
435
  }
383
- function L(e, t) {
384
- return function(n, s) {
385
- M(n, s, e, t);
436
+ function J(n, t) {
437
+ return function(e, i) {
438
+ const s = i.name;
439
+ i.addInitializer(function() {
440
+ U(this, s, n, t);
441
+ });
386
442
  };
387
443
  }
388
- function q(e) {
444
+ function X(n) {
389
445
  return function(t) {
390
- return L(t, e);
446
+ return J(t, n);
447
+ };
448
+ }
449
+ const N = Symbol("decorate.metadata");
450
+ function tt(n, t, e) {
451
+ const i = Array.isArray(n) ? n : [n], s = t.prototype, a = typeof s[e] == "function", o = [];
452
+ m(t, N) || (t[N] = {});
453
+ const u = t[N], c = {
454
+ kind: a ? "method" : "field",
455
+ name: e,
456
+ static: !1,
457
+ private: !1,
458
+ addInitializer(h) {
459
+ o.push(h);
460
+ },
461
+ metadata: u
391
462
  };
463
+ let p = a ? s[e] : void 0;
464
+ for (let h = i.length - 1; h >= 0; h--) {
465
+ const O = i[h](p, c);
466
+ a && typeof O == "function" && (p = O);
467
+ }
468
+ a && p !== s[e] && (s[e] = p);
469
+ const _ = Object.create(s);
470
+ for (const h of o)
471
+ h.call(_);
392
472
  }
393
473
  export {
474
+ g as BaseError,
475
+ b as Binding,
476
+ x as BindingNotFoundError,
477
+ H as BindingNotValidError,
478
+ w as CircularDependencyError,
394
479
  I as Container,
395
- U as Inject,
396
- L as LazyInject,
480
+ z as ContainerNotFoundError,
481
+ F as DuplicateBindingError,
482
+ K as Inject,
483
+ J as LazyInject,
397
484
  B as LazyToken,
398
- z as Optional,
399
- K as PostConstruct,
400
- $ as PreDestroy,
401
- G as Self,
402
- Y as SkipSelf,
403
- J as Token,
404
- q as createLazyInject,
405
- W as decorate
485
+ q as Optional,
486
+ W as PostConstruct,
487
+ M as PostConstructError,
488
+ Q as PreDestroy,
489
+ $ as Self,
490
+ Z as SkipSelf,
491
+ G as Token,
492
+ X as createLazyInject,
493
+ tt as decorate
406
494
  };