@kaokei/di 2.0.8 → 3.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/README.md +27 -56
- package/dist/binding.d.cts +36 -0
- package/dist/binding.d.ts +36 -0
- package/dist/cachemap.d.cts +21 -0
- package/dist/cachemap.d.ts +21 -0
- package/dist/constants.d.cts +28 -0
- package/dist/constants.d.ts +28 -0
- package/dist/container.d.cts +29 -0
- package/dist/container.d.ts +29 -0
- package/dist/decorator.d.cts +18 -0
- package/dist/decorator.d.ts +18 -0
- package/dist/errors/BaseError.d.cts +4 -0
- package/dist/errors/BaseError.d.ts +4 -0
- package/dist/errors/BindingNotFoundError.d.cts +5 -0
- package/dist/errors/BindingNotFoundError.d.ts +5 -0
- package/dist/errors/BindingNotValidError.d.cts +5 -0
- package/dist/errors/BindingNotValidError.d.ts +5 -0
- package/dist/errors/CircularDependencyError.d.cts +5 -0
- package/dist/errors/CircularDependencyError.d.ts +5 -0
- package/dist/errors/DuplicateBindingError.d.cts +5 -0
- package/dist/errors/DuplicateBindingError.d.ts +5 -0
- package/dist/errors/PostConstructError.d.cts +5 -0
- package/dist/errors/PostConstructError.d.ts +5 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +402 -0
- package/dist/interfaces.d.cts +47 -0
- package/dist/interfaces.d.ts +47 -0
- package/dist/lazyinject.d.cts +4 -0
- package/dist/lazyinject.d.ts +4 -0
- package/dist/token.d.cts +12 -0
- package/dist/token.d.ts +12 -0
- package/package.json +38 -97
- package/dist/index.cjs.js +0 -746
- package/dist/index.cjs.js.map +0 -1
- package/dist/index.cjs.min.js +0 -11
- package/dist/index.cjs.min.js.map +0 -1
- package/dist/index.cjs.runtime.js +0 -735
- package/dist/index.cjs.runtime.js.map +0 -1
- package/dist/index.cjs.runtime.min.js +0 -11
- package/dist/index.cjs.runtime.min.js.map +0 -1
- package/dist/index.esm.js +0 -724
- package/dist/index.esm.js.map +0 -1
- package/dist/index.esm.min.js +0 -11
- package/dist/index.esm.min.js.map +0 -1
- package/dist/index.esm.runtime.js +0 -713
- package/dist/index.esm.runtime.js.map +0 -1
- package/dist/index.esm.runtime.min.js +0 -11
- package/dist/index.esm.runtime.min.js.map +0 -1
- package/dist/index.iife.js +0 -749
- package/dist/index.iife.js.map +0 -1
- package/dist/index.iife.min.js +0 -11
- package/dist/index.iife.min.js.map +0 -1
- package/dist/src/Injector.d.ts +0 -143
- package/dist/src/Injector.d.ts.map +0 -1
- package/dist/src/constants.d.ts +0 -17
- package/dist/src/constants.d.ts.map +0 -1
- package/dist/src/decorator.d.ts +0 -42
- package/dist/src/decorator.d.ts.map +0 -1
- package/dist/src/errors/CircularDependencyError.d.ts +0 -6
- package/dist/src/errors/CircularDependencyError.d.ts.map +0 -1
- package/dist/src/errors/ConstructorInjectMissTokenError.d.ts +0 -6
- package/dist/src/errors/ConstructorInjectMissTokenError.d.ts.map +0 -1
- package/dist/src/errors/InjectFailedError.d.ts +0 -6
- package/dist/src/errors/InjectFailedError.d.ts.map +0 -1
- package/dist/src/errors/PropertyInjectMissTokenError.d.ts +0 -6
- package/dist/src/errors/PropertyInjectMissTokenError.d.ts.map +0 -1
- package/dist/src/errors/ProviderNotValidError.d.ts +0 -6
- package/dist/src/errors/ProviderNotValidError.d.ts.map +0 -1
- package/dist/src/errors/TokenNotFoundError.d.ts +0 -6
- package/dist/src/errors/TokenNotFoundError.d.ts.map +0 -1
- package/dist/src/errors/index.d.ts +0 -7
- package/dist/src/errors/index.d.ts.map +0 -1
- package/dist/src/forwardRef.d.ts +0 -7
- package/dist/src/forwardRef.d.ts.map +0 -1
- package/dist/src/index.d.ts +0 -7
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/utils.d.ts +0 -4
- package/dist/src/utils.d.ts.map +0 -1
package/dist/index.js
ADDED
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
var V = Object.defineProperty;
|
|
2
|
+
var R = (e, t, n) => t in e ? V(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var a = (e, t, n) => R(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
|
+
const l = {
|
|
5
|
+
// 记录构造函数参数装饰器对应的数据的key
|
|
6
|
+
INJECTED_PARAMS: "injected:params",
|
|
7
|
+
// 记录实例属性装饰器对应的数据的key
|
|
8
|
+
INJECTED_PROPS: "injected:props",
|
|
9
|
+
// Inject装饰器的key
|
|
10
|
+
INJECT: "inject",
|
|
11
|
+
// Self装饰器的key
|
|
12
|
+
SELF: "self",
|
|
13
|
+
// SkipSelf装饰器的key
|
|
14
|
+
SKIP_SELF: "skipSelf",
|
|
15
|
+
// Optional装饰器的key
|
|
16
|
+
OPTIONAL: "optional",
|
|
17
|
+
// PostConstruct装饰器的key
|
|
18
|
+
POST_CONSTRUCT: "postConstruct",
|
|
19
|
+
// PreDestroy装饰器的key
|
|
20
|
+
PRE_DESTROY: "preDestroy"
|
|
21
|
+
}, p = {
|
|
22
|
+
DEFAULT: "default",
|
|
23
|
+
INITING: "initing",
|
|
24
|
+
ACTIVATED: "activated"
|
|
25
|
+
}, d = {
|
|
26
|
+
Invalid: "Invalid",
|
|
27
|
+
Instance: "Instance",
|
|
28
|
+
ConstantValue: "ConstantValue",
|
|
29
|
+
DynamicValue: "DynamicValue"
|
|
30
|
+
}, 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
|
+
}, S = Symbol(), v = /* @__PURE__ */ new WeakMap();
|
|
36
|
+
function w(e) {
|
|
37
|
+
return typeof e == "function" && Object.getPrototypeOf(e) !== Function.prototype;
|
|
38
|
+
}
|
|
39
|
+
function A(e, t, n) {
|
|
40
|
+
const s = v.get(n) || {};
|
|
41
|
+
s[e] = t, v.set(n, s);
|
|
42
|
+
}
|
|
43
|
+
function I(e, t) {
|
|
44
|
+
return (v.get(t) || {})[e];
|
|
45
|
+
}
|
|
46
|
+
function y(e, t) {
|
|
47
|
+
const n = I(e, t);
|
|
48
|
+
if (!w(t))
|
|
49
|
+
return n;
|
|
50
|
+
const s = y(
|
|
51
|
+
e,
|
|
52
|
+
Object.getPrototypeOf(t)
|
|
53
|
+
);
|
|
54
|
+
if (s || n)
|
|
55
|
+
return {
|
|
56
|
+
...s || {},
|
|
57
|
+
...n || {}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
class J {
|
|
61
|
+
constructor(t) {
|
|
62
|
+
a(this, "_", "");
|
|
63
|
+
a(this, "name");
|
|
64
|
+
this.name = t;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
class _ {
|
|
68
|
+
constructor(t) {
|
|
69
|
+
a(this, "callback");
|
|
70
|
+
this.callback = t;
|
|
71
|
+
}
|
|
72
|
+
resolve() {
|
|
73
|
+
return this.callback();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function D(e) {
|
|
77
|
+
if (!e)
|
|
78
|
+
throw new Error(C.MISS_INJECT);
|
|
79
|
+
return e instanceof _ ? e.resolve() : e;
|
|
80
|
+
}
|
|
81
|
+
class E extends Error {
|
|
82
|
+
constructor(t, n) {
|
|
83
|
+
super(), this.name = this.constructor.name, this.message = `${t}${n == null ? void 0 : n.name}`;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
class P extends E {
|
|
87
|
+
constructor(t) {
|
|
88
|
+
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}`;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
class B extends E {
|
|
98
|
+
constructor(t) {
|
|
99
|
+
super("Invalid binding: ", t);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
class k extends P {
|
|
103
|
+
constructor(t) {
|
|
104
|
+
super(t), this.name = "CircularDependencyError inside @PostConstruct";
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
class j {
|
|
108
|
+
constructor(t, n) {
|
|
109
|
+
a(this, "container");
|
|
110
|
+
a(this, "context");
|
|
111
|
+
a(this, "token");
|
|
112
|
+
a(this, "type", d.Invalid);
|
|
113
|
+
a(this, "status", p.DEFAULT);
|
|
114
|
+
a(this, "classValue");
|
|
115
|
+
a(this, "constantValue");
|
|
116
|
+
a(this, "dynamicValue");
|
|
117
|
+
a(this, "cache");
|
|
118
|
+
a(this, "postConstructResult", S);
|
|
119
|
+
a(this, "onActivationHandler");
|
|
120
|
+
a(this, "onDeactivationHandler");
|
|
121
|
+
this.container = n, this.context = { container: this.container }, this.token = t;
|
|
122
|
+
}
|
|
123
|
+
onActivation(t) {
|
|
124
|
+
this.onActivationHandler = t;
|
|
125
|
+
}
|
|
126
|
+
onDeactivation(t) {
|
|
127
|
+
this.onDeactivationHandler = t;
|
|
128
|
+
}
|
|
129
|
+
activate(t) {
|
|
130
|
+
const n = this.onActivationHandler ? this.onActivationHandler(this.context, t) : t;
|
|
131
|
+
return this.container.activate(n, this.token);
|
|
132
|
+
}
|
|
133
|
+
deactivate() {
|
|
134
|
+
this.onDeactivationHandler && this.onDeactivationHandler(this.cache);
|
|
135
|
+
}
|
|
136
|
+
to(t) {
|
|
137
|
+
return this.type = d.Instance, this.classValue = t, this;
|
|
138
|
+
}
|
|
139
|
+
toSelf() {
|
|
140
|
+
return this.to(this.token);
|
|
141
|
+
}
|
|
142
|
+
toConstantValue(t) {
|
|
143
|
+
return this.type = d.ConstantValue, this.constantValue = t, this;
|
|
144
|
+
}
|
|
145
|
+
toDynamicValue(t) {
|
|
146
|
+
return this.type = d.DynamicValue, this.dynamicValue = t, this;
|
|
147
|
+
}
|
|
148
|
+
toService(t) {
|
|
149
|
+
return this.toDynamicValue(
|
|
150
|
+
(n) => n.container.get(t, { parent: { token: this.token } })
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
get(t) {
|
|
154
|
+
if (p.INITING === this.status)
|
|
155
|
+
throw new P(t);
|
|
156
|
+
if (p.ACTIVATED === this.status)
|
|
157
|
+
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 B(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) {
|
|
170
|
+
if (d.Instance === this.type) {
|
|
171
|
+
const { key: i, value: o } = y(l.POST_CONSTRUCT, this.token) || {};
|
|
172
|
+
if (i)
|
|
173
|
+
if (o) {
|
|
174
|
+
const r = [...n, ...s].filter(
|
|
175
|
+
(u) => d.Instance === (u == null ? void 0 : u.type)
|
|
176
|
+
), c = this.getAwaitBindings(r, o);
|
|
177
|
+
for (const u of c)
|
|
178
|
+
if (u && u.postConstructResult === S)
|
|
179
|
+
throw new k({
|
|
180
|
+
token: u.token,
|
|
181
|
+
parent: t
|
|
182
|
+
});
|
|
183
|
+
const h = c.map((u) => u.postConstructResult);
|
|
184
|
+
this.postConstructResult = Promise.all(h).then(
|
|
185
|
+
() => this.execute(i)
|
|
186
|
+
);
|
|
187
|
+
} else
|
|
188
|
+
this.postConstructResult = this.execute(i);
|
|
189
|
+
else
|
|
190
|
+
this.postConstructResult = void 0;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
preDestroy() {
|
|
194
|
+
if (d.Instance === this.type) {
|
|
195
|
+
const { key: t } = y(l.PRE_DESTROY, this.token) || {};
|
|
196
|
+
if (t)
|
|
197
|
+
return this.execute(t);
|
|
198
|
+
}
|
|
199
|
+
this.container = null, this.context = null;
|
|
200
|
+
}
|
|
201
|
+
execute(t) {
|
|
202
|
+
const n = this.cache[t];
|
|
203
|
+
return n == null ? void 0 : n.call(this.cache);
|
|
204
|
+
}
|
|
205
|
+
resolveInstanceValue(t) {
|
|
206
|
+
this.status = p.INITING;
|
|
207
|
+
const n = this.classValue, [s, i] = this.getConstructorParameters(t), o = new n(...s);
|
|
208
|
+
this.cache = this.activate(o), this.status = p.ACTIVATED, b.set(this.cache, this.container);
|
|
209
|
+
const [r, c] = this.getInjectProperties(t);
|
|
210
|
+
return Object.assign(this.cache, r), this.postConstruct(t, i, c), this.cache;
|
|
211
|
+
}
|
|
212
|
+
resolveConstantValue() {
|
|
213
|
+
return this.status = p.INITING, this.cache = this.activate(this.constantValue), this.status = p.ACTIVATED, this.cache;
|
|
214
|
+
}
|
|
215
|
+
resolveDynamicValue() {
|
|
216
|
+
this.status = p.INITING;
|
|
217
|
+
const t = this.dynamicValue.call(this, this.context);
|
|
218
|
+
return this.cache = this.activate(t), this.status = p.ACTIVATED, this.cache;
|
|
219
|
+
}
|
|
220
|
+
getConstructorParameters(t) {
|
|
221
|
+
const n = I(l.INJECTED_PARAMS, this.classValue) || [], s = [], i = [];
|
|
222
|
+
for (let o = 0; o < n.length; o++) {
|
|
223
|
+
const r = n[o], { inject: c, ...h } = r;
|
|
224
|
+
h.parent = t;
|
|
225
|
+
const u = this.container.get(D(c), h);
|
|
226
|
+
s.push(u), i.push(h.binding);
|
|
227
|
+
}
|
|
228
|
+
return [s, i];
|
|
229
|
+
}
|
|
230
|
+
getInjectProperties(t) {
|
|
231
|
+
const n = y(l.INJECTED_PROPS, this.classValue) || {}, s = Object.keys(n), i = /* @__PURE__ */ Object.create(null), o = [];
|
|
232
|
+
for (let r = 0; r < s.length; r++) {
|
|
233
|
+
const c = s[r], h = n[c], { inject: u, ...f } = h;
|
|
234
|
+
f.parent = t;
|
|
235
|
+
const g = this.container.get(D(u), f);
|
|
236
|
+
g === void 0 && h.optional || (i[c] = g), o.push(f.binding);
|
|
237
|
+
}
|
|
238
|
+
return [i, o];
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
class M extends E {
|
|
242
|
+
constructor(t) {
|
|
243
|
+
super("No matching binding found for token: ", t);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
class x extends E {
|
|
247
|
+
constructor(t) {
|
|
248
|
+
super("Cannot bind token multiple times: ", t);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
class N {
|
|
252
|
+
constructor() {
|
|
253
|
+
a(this, "parent");
|
|
254
|
+
a(this, "bindings", /* @__PURE__ */ new Map());
|
|
255
|
+
a(this, "onActivationHandler");
|
|
256
|
+
a(this, "onDeactivationHandler");
|
|
257
|
+
}
|
|
258
|
+
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;
|
|
263
|
+
}
|
|
264
|
+
unbind(t) {
|
|
265
|
+
if (this.bindings.has(t)) {
|
|
266
|
+
const n = this.getBinding(t);
|
|
267
|
+
this.deactivate(n), n.preDestroy(), this.bindings.delete(t);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
unbindAll() {
|
|
271
|
+
this.bindings.forEach((t) => {
|
|
272
|
+
this.unbind(t.token);
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
isCurrentBound(t) {
|
|
276
|
+
return this.bindings.has(t);
|
|
277
|
+
}
|
|
278
|
+
isBound(t) {
|
|
279
|
+
return this.isCurrentBound(t) || !!this.parent && this.parent.isBound(t);
|
|
280
|
+
}
|
|
281
|
+
createChild() {
|
|
282
|
+
const t = new N();
|
|
283
|
+
return t.parent = this, t;
|
|
284
|
+
}
|
|
285
|
+
get(t, n = {}) {
|
|
286
|
+
const s = this.getBinding(t);
|
|
287
|
+
if (n.skipSelf) {
|
|
288
|
+
if (this.parent)
|
|
289
|
+
return n.skipSelf = !1, this.parent.get(t, n);
|
|
290
|
+
} else if (n.self || s) {
|
|
291
|
+
if (s)
|
|
292
|
+
return n.token = t, n.binding = s, s.get(n);
|
|
293
|
+
} else if (this.parent)
|
|
294
|
+
return this.parent.get(t, n);
|
|
295
|
+
return this.checkBindingNotFoundError(t, n);
|
|
296
|
+
}
|
|
297
|
+
onActivation(t) {
|
|
298
|
+
this.onActivationHandler = t;
|
|
299
|
+
}
|
|
300
|
+
onDeactivation(t) {
|
|
301
|
+
this.onDeactivationHandler = t;
|
|
302
|
+
}
|
|
303
|
+
activate(t, n) {
|
|
304
|
+
return this.onActivationHandler ? this.onActivationHandler({ container: this }, t, n) : t;
|
|
305
|
+
}
|
|
306
|
+
deactivate(t) {
|
|
307
|
+
this.onDeactivationHandler && this.onDeactivationHandler(t.cache, t.token), t.deactivate();
|
|
308
|
+
}
|
|
309
|
+
buildBinding(t) {
|
|
310
|
+
return new j(t, this);
|
|
311
|
+
}
|
|
312
|
+
getBinding(t) {
|
|
313
|
+
return this.bindings.get(t);
|
|
314
|
+
}
|
|
315
|
+
checkBindingNotFoundError(t, n) {
|
|
316
|
+
if (!n.optional)
|
|
317
|
+
throw new M(t);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
const b = /* @__PURE__ */ new WeakMap();
|
|
321
|
+
function T(e, t) {
|
|
322
|
+
return function(n) {
|
|
323
|
+
return function(s, i, o) {
|
|
324
|
+
const r = typeof o == "number", c = r ? s : s.constructor, h = r ? o : i, u = r ? l.INJECTED_PARAMS : l.INJECTED_PROPS, f = r ? I(u, c) || [] : y(u, c) || {}, g = f[h] || {};
|
|
325
|
+
g[e] = n === void 0 ? t : n, f[h] = g, A(u, f, c);
|
|
326
|
+
};
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
function O(e, t) {
|
|
330
|
+
return (n) => (s, i) => {
|
|
331
|
+
if (I(e, s.constructor))
|
|
332
|
+
throw new Error(t);
|
|
333
|
+
A(
|
|
334
|
+
e,
|
|
335
|
+
{ key: i, value: n },
|
|
336
|
+
s.constructor
|
|
337
|
+
);
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
const U = T(l.INJECT), G = T(l.SELF, !0), Y = T(l.SKIP_SELF, !0), z = T(l.OPTIONAL, !0), K = O(
|
|
341
|
+
l.POST_CONSTRUCT,
|
|
342
|
+
C.POST_CONSTRUCT
|
|
343
|
+
), $ = O(
|
|
344
|
+
l.PRE_DESTROY,
|
|
345
|
+
C.PRE_DESTROY
|
|
346
|
+
);
|
|
347
|
+
function m(e, t, n, s) {
|
|
348
|
+
for (let i = e.length - 1; i >= 0; i--)
|
|
349
|
+
e[i](t, n, s);
|
|
350
|
+
}
|
|
351
|
+
function W(e, t, n) {
|
|
352
|
+
e = Array.isArray(e) ? e : [e], typeof n == "number" ? m(e, t, void 0, n) : typeof n == "string" && m(e, t.prototype, n);
|
|
353
|
+
}
|
|
354
|
+
function H(e, t, n, s) {
|
|
355
|
+
function i() {
|
|
356
|
+
const r = Symbol.for(t);
|
|
357
|
+
if (!this.hasOwnProperty(r)) {
|
|
358
|
+
const c = s || b.get(this), h = this.constructor;
|
|
359
|
+
if (!c)
|
|
360
|
+
throw new Error(`${C.MISS_CONTAINER} ${h.name}`);
|
|
361
|
+
this[r] = c.get(D(n), {
|
|
362
|
+
parent: { token: h }
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
return this[r];
|
|
366
|
+
}
|
|
367
|
+
function o(r) {
|
|
368
|
+
const c = Symbol.for(t);
|
|
369
|
+
this[c] = r;
|
|
370
|
+
}
|
|
371
|
+
Object.defineProperty(e, t, {
|
|
372
|
+
configurable: !0,
|
|
373
|
+
enumerable: !0,
|
|
374
|
+
get: i,
|
|
375
|
+
set: o
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
function L(e, t) {
|
|
379
|
+
return function(n, s) {
|
|
380
|
+
H(n, s, e, t);
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
function q(e) {
|
|
384
|
+
return function(t) {
|
|
385
|
+
return L(t, e);
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
export {
|
|
389
|
+
b as CONTAINER_MAP,
|
|
390
|
+
N as Container,
|
|
391
|
+
U as Inject,
|
|
392
|
+
L as LazyInject,
|
|
393
|
+
_ as LazyToken,
|
|
394
|
+
z as Optional,
|
|
395
|
+
K as PostConstruct,
|
|
396
|
+
$ as PreDestroy,
|
|
397
|
+
G as Self,
|
|
398
|
+
Y as SkipSelf,
|
|
399
|
+
J as Token,
|
|
400
|
+
q as createLazyInject,
|
|
401
|
+
W as decorate
|
|
402
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Token, LazyToken } from './token';
|
|
2
|
+
import { Container } from './container';
|
|
3
|
+
import { Binding } from './binding';
|
|
4
|
+
import { KEYS } from './constants';
|
|
5
|
+
export type Newable<TInstance = unknown, TArgs extends unknown[] = any[]> = new (...args: TArgs) => TInstance;
|
|
6
|
+
export type InjectFunction<R extends (...args: any) => any> = (token: GenericToken) => ReturnType<R>;
|
|
7
|
+
export type CommonToken<T = unknown> = Token<T> | Newable<T>;
|
|
8
|
+
export type GenericToken<T = unknown> = Token<T> | Newable<T> | LazyToken<T>;
|
|
9
|
+
export type LazyTokenCallback<T = unknown> = () => CommonToken<T>;
|
|
10
|
+
export interface Context {
|
|
11
|
+
container: Container;
|
|
12
|
+
}
|
|
13
|
+
export type DynamicValue<T> = (ctx: Context) => T;
|
|
14
|
+
export type RecordObject = Record<string, unknown>;
|
|
15
|
+
export interface Options<T = unknown> {
|
|
16
|
+
inject?: GenericToken<T>;
|
|
17
|
+
optional?: boolean;
|
|
18
|
+
self?: boolean;
|
|
19
|
+
skipSelf?: boolean;
|
|
20
|
+
token?: CommonToken<T>;
|
|
21
|
+
binding?: Binding<T>;
|
|
22
|
+
parent?: Options<any>;
|
|
23
|
+
}
|
|
24
|
+
export type ActivationHandler<T = unknown> = (ctx: Context, input: T, token?: CommonToken<T>) => T;
|
|
25
|
+
export type DeactivationHandler<T = unknown> = (input: T, token?: CommonToken<T>) => void;
|
|
26
|
+
export type PostConstructParam = void | true | CommonToken[] | ((item: Binding, index: number, arr: Binding[]) => boolean);
|
|
27
|
+
export type META_KEY_INJECTED_PARAMS = typeof KEYS.INJECTED_PARAMS;
|
|
28
|
+
export type META_KEY_INJECTED_PROPS = typeof KEYS.INJECTED_PROPS;
|
|
29
|
+
export type META_KEY_POST_CONSTRUCT = typeof KEYS.POST_CONSTRUCT;
|
|
30
|
+
export type META_KEY_PRE_DESTROY = typeof KEYS.PRE_DESTROY;
|
|
31
|
+
export type META_KEYS = META_KEY_INJECTED_PARAMS | META_KEY_INJECTED_PROPS | META_KEY_POST_CONSTRUCT | META_KEY_PRE_DESTROY;
|
|
32
|
+
export type META_VALUE_INJECTED_PARAMS = Options[];
|
|
33
|
+
export type META_VALUE_INJECTED_PROPS = Record<string, Options>;
|
|
34
|
+
export type META_VALUE_POST_CONSTRUCT = KV<PostConstructParam>;
|
|
35
|
+
export type META_VALUE_PRE_DESTROY = KV<void>;
|
|
36
|
+
export type META_VALUES = META_VALUE_INJECTED_PARAMS | META_VALUE_INJECTED_PROPS | META_VALUE_POST_CONSTRUCT | META_VALUE_PRE_DESTROY;
|
|
37
|
+
export interface KV<T> {
|
|
38
|
+
key: string;
|
|
39
|
+
value: T;
|
|
40
|
+
}
|
|
41
|
+
export type ExtractKV<T> = T extends META_KEY_POST_CONSTRUCT ? PostConstructParam : T extends META_KEY_PRE_DESTROY ? void : never;
|
|
42
|
+
export interface CacheMapValue {
|
|
43
|
+
[KEYS.INJECTED_PARAMS]: Options[];
|
|
44
|
+
[KEYS.INJECTED_PROPS]: Record<string, Options>;
|
|
45
|
+
[KEYS.POST_CONSTRUCT]: KV<PostConstructParam>;
|
|
46
|
+
[KEYS.PRE_DESTROY]: KV<void>;
|
|
47
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Token, LazyToken } from './token';
|
|
2
|
+
import { Container } from './container';
|
|
3
|
+
import { Binding } from './binding';
|
|
4
|
+
import { KEYS } from './constants';
|
|
5
|
+
export type Newable<TInstance = unknown, TArgs extends unknown[] = any[]> = new (...args: TArgs) => TInstance;
|
|
6
|
+
export type InjectFunction<R extends (...args: any) => any> = (token: GenericToken) => ReturnType<R>;
|
|
7
|
+
export type CommonToken<T = unknown> = Token<T> | Newable<T>;
|
|
8
|
+
export type GenericToken<T = unknown> = Token<T> | Newable<T> | LazyToken<T>;
|
|
9
|
+
export type LazyTokenCallback<T = unknown> = () => CommonToken<T>;
|
|
10
|
+
export interface Context {
|
|
11
|
+
container: Container;
|
|
12
|
+
}
|
|
13
|
+
export type DynamicValue<T> = (ctx: Context) => T;
|
|
14
|
+
export type RecordObject = Record<string, unknown>;
|
|
15
|
+
export interface Options<T = unknown> {
|
|
16
|
+
inject?: GenericToken<T>;
|
|
17
|
+
optional?: boolean;
|
|
18
|
+
self?: boolean;
|
|
19
|
+
skipSelf?: boolean;
|
|
20
|
+
token?: CommonToken<T>;
|
|
21
|
+
binding?: Binding<T>;
|
|
22
|
+
parent?: Options<any>;
|
|
23
|
+
}
|
|
24
|
+
export type ActivationHandler<T = unknown> = (ctx: Context, input: T, token?: CommonToken<T>) => T;
|
|
25
|
+
export type DeactivationHandler<T = unknown> = (input: T, token?: CommonToken<T>) => void;
|
|
26
|
+
export type PostConstructParam = void | true | CommonToken[] | ((item: Binding, index: number, arr: Binding[]) => boolean);
|
|
27
|
+
export type META_KEY_INJECTED_PARAMS = typeof KEYS.INJECTED_PARAMS;
|
|
28
|
+
export type META_KEY_INJECTED_PROPS = typeof KEYS.INJECTED_PROPS;
|
|
29
|
+
export type META_KEY_POST_CONSTRUCT = typeof KEYS.POST_CONSTRUCT;
|
|
30
|
+
export type META_KEY_PRE_DESTROY = typeof KEYS.PRE_DESTROY;
|
|
31
|
+
export type META_KEYS = META_KEY_INJECTED_PARAMS | META_KEY_INJECTED_PROPS | META_KEY_POST_CONSTRUCT | META_KEY_PRE_DESTROY;
|
|
32
|
+
export type META_VALUE_INJECTED_PARAMS = Options[];
|
|
33
|
+
export type META_VALUE_INJECTED_PROPS = Record<string, Options>;
|
|
34
|
+
export type META_VALUE_POST_CONSTRUCT = KV<PostConstructParam>;
|
|
35
|
+
export type META_VALUE_PRE_DESTROY = KV<void>;
|
|
36
|
+
export type META_VALUES = META_VALUE_INJECTED_PARAMS | META_VALUE_INJECTED_PROPS | META_VALUE_POST_CONSTRUCT | META_VALUE_PRE_DESTROY;
|
|
37
|
+
export interface KV<T> {
|
|
38
|
+
key: string;
|
|
39
|
+
value: T;
|
|
40
|
+
}
|
|
41
|
+
export type ExtractKV<T> = T extends META_KEY_POST_CONSTRUCT ? PostConstructParam : T extends META_KEY_PRE_DESTROY ? void : never;
|
|
42
|
+
export interface CacheMapValue {
|
|
43
|
+
[KEYS.INJECTED_PARAMS]: Options[];
|
|
44
|
+
[KEYS.INJECTED_PROPS]: Record<string, Options>;
|
|
45
|
+
[KEYS.POST_CONSTRUCT]: KV<PostConstructParam>;
|
|
46
|
+
[KEYS.PRE_DESTROY]: KV<void>;
|
|
47
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { GenericToken } from './interfaces';
|
|
2
|
+
import { Container } from './container';
|
|
3
|
+
export declare function LazyInject<T>(token: GenericToken<T>, container?: Container): (proto: any, key: string) => void;
|
|
4
|
+
export declare function createLazyInject(container: Container): <T>(token: GenericToken<T>) => (proto: any, key: string) => void;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { GenericToken } from './interfaces';
|
|
2
|
+
import { Container } from './container';
|
|
3
|
+
export declare function LazyInject<T>(token: GenericToken<T>, container?: Container): (proto: any, key: string) => void;
|
|
4
|
+
export declare function createLazyInject(container: Container): <T>(token: GenericToken<T>) => (proto: any, key: string) => void;
|
package/dist/token.d.cts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { GenericToken, LazyTokenCallback } from './interfaces';
|
|
2
|
+
export declare class Token<T> {
|
|
3
|
+
_: T;
|
|
4
|
+
name: string;
|
|
5
|
+
constructor(name: string);
|
|
6
|
+
}
|
|
7
|
+
export declare class LazyToken<T> {
|
|
8
|
+
private callback;
|
|
9
|
+
constructor(callback: LazyTokenCallback<T>);
|
|
10
|
+
resolve(): import('./interfaces').CommonToken<T>;
|
|
11
|
+
}
|
|
12
|
+
export declare function resolveToken<T>(token?: GenericToken<T>): import('./interfaces').CommonToken<T>;
|
package/dist/token.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { GenericToken, LazyTokenCallback } from './interfaces';
|
|
2
|
+
export declare class Token<T> {
|
|
3
|
+
_: T;
|
|
4
|
+
name: string;
|
|
5
|
+
constructor(name: string);
|
|
6
|
+
}
|
|
7
|
+
export declare class LazyToken<T> {
|
|
8
|
+
private callback;
|
|
9
|
+
constructor(callback: LazyTokenCallback<T>);
|
|
10
|
+
resolve(): import('./interfaces').CommonToken<T>;
|
|
11
|
+
}
|
|
12
|
+
export declare function resolveToken<T>(token?: GenericToken<T>): import('./interfaces').CommonToken<T>;
|