@x-oasis/di 0.1.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 ADDED
@@ -0,0 +1,19 @@
1
+ # @x-oasis/di
2
+
3
+ ## Installation
4
+
5
+ ```bash
6
+ $ npm i @x-oasis/di
7
+ ```
8
+
9
+ ## How to use
10
+
11
+ ```typescript
12
+ import { Container, Registry, inject, injectable } from '@x-oasis/di'
13
+ ```
14
+
15
+ ## How to run test
16
+
17
+ ```bash
18
+ $ pnpm test
19
+ ```
@@ -0,0 +1,16 @@
1
+ import { Ctor, ModuleIdentifier } from './types';
2
+ import Binding from './binding/Binding';
3
+ import BindingTo from './binding/BindingTo';
4
+ import Registry from './Registry';
5
+ declare class Container {
6
+ private _bindingStore;
7
+ private _belongs;
8
+ bind(identifier: ModuleIdentifier): BindingTo;
9
+ get bindingStore(): Map<import("./types").ServiceIdentifier<unknown>, Binding>;
10
+ setBelongs(belongs: Container): void;
11
+ getBinding(identifier: ModuleIdentifier | Ctor): any;
12
+ get(identifier: ModuleIdentifier | Ctor, ...args: any[]): any;
13
+ load(registry: Registry): void;
14
+ resolve(identifier: ModuleIdentifier | Ctor, ...args: any[]): any;
15
+ }
16
+ export default Container;
@@ -0,0 +1,9 @@
1
+ import Container from './Container';
2
+ import { RegistryFactory, RegistryOptions } from './types';
3
+ declare class Registry {
4
+ private readonly registryFactory;
5
+ private readonly registryOptions;
6
+ constructor(registryFactory: RegistryFactory, registryOptions?: RegistryOptions);
7
+ load(container: Container): void;
8
+ }
9
+ export default Registry;
@@ -0,0 +1,22 @@
1
+ import Container from '../Container';
2
+ import { BindingProps, BindingType, BindingValue } from '../types';
3
+ import Scope from '../scope/Scope';
4
+ declare class Binding {
5
+ private _identifier;
6
+ private _type;
7
+ private _to;
8
+ private _value;
9
+ private _container;
10
+ private _scope;
11
+ constructor(props: BindingProps);
12
+ get container(): Container;
13
+ get to(): any;
14
+ set to(v: any);
15
+ get type(): BindingType;
16
+ set type(type: BindingType);
17
+ get value(): BindingValue;
18
+ set value(value: BindingValue);
19
+ get identifier(): import("../types").ServiceIdentifier<unknown>;
20
+ get scope(): Scope;
21
+ }
22
+ export default Binding;
@@ -0,0 +1,11 @@
1
+ import { BindingToProps, ToValueCtor, ToValueDynamicValue } from '../types';
2
+ declare class BindingTo {
3
+ private binding;
4
+ constructor(props: BindingToProps);
5
+ toSelf(): import("../scope/Scope").default;
6
+ toConstantValue(value: any): import("../scope/Scope").default;
7
+ to(value: ToValueCtor): import("../scope/Scope").default;
8
+ toDynamicValue(value: ToValueDynamicValue): import("../scope/Scope").default;
9
+ toParamsFactory(value: ToValueCtor): import("../scope/Scope").default;
10
+ }
11
+ export default BindingTo;
@@ -0,0 +1,6 @@
1
+ export declare const hasSymbol: boolean;
2
+ export declare const DEPENDENCIES: unique symbol;
3
+ export declare const IS_INJECTABLE: unique symbol;
4
+ export declare const createHiddenProperty: (target: object, prop: PropertyKey, value: any) => void;
5
+ export declare const isInjectable: (thing: any) => boolean;
6
+ export declare const createId: (str: string) => symbol;
@@ -0,0 +1,4 @@
1
+ import { ModuleIdentifier } from '../types';
2
+ export declare const DUPLICATED_INJECTABLE_DECORATOR = "Cannot apply @injectable decorator multiple times.";
3
+ export declare const INSTANTIATE_FACTORY_SERVICE: (id: ModuleIdentifier) => string;
4
+ export declare const BINDING_NOT_FOUND: (id: ModuleIdentifier, index: number) => string;
@@ -0,0 +1,2 @@
1
+ import { ModuleIdentifier, DecoratorTarget } from '../types';
2
+ export declare function inject<T>(moduleIdentifier: ModuleIdentifier): (target: DecoratorTarget<T>, propertyName: string, index?: number) => void;
@@ -0,0 +1,3 @@
1
+ import { DecoratorTarget } from '../types';
2
+ declare function injectable(): <T extends DecoratorTarget<unknown>>(target: T) => any;
3
+ export { injectable };
@@ -0,0 +1,491 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ function _defineProperties(target, props) {
6
+ for (var i = 0; i < props.length; i++) {
7
+ var descriptor = props[i];
8
+ descriptor.enumerable = descriptor.enumerable || false;
9
+ descriptor.configurable = true;
10
+ if ("value" in descriptor) descriptor.writable = true;
11
+ Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
12
+ }
13
+ }
14
+ function _createClass(Constructor, protoProps, staticProps) {
15
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
16
+ if (staticProps) _defineProperties(Constructor, staticProps);
17
+ Object.defineProperty(Constructor, "prototype", {
18
+ writable: false
19
+ });
20
+ return Constructor;
21
+ }
22
+ function _setPrototypeOf(o, p) {
23
+ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
24
+ o.__proto__ = p;
25
+ return o;
26
+ };
27
+ return _setPrototypeOf(o, p);
28
+ }
29
+ function _isNativeReflectConstruct() {
30
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
31
+ if (Reflect.construct.sham) return false;
32
+ if (typeof Proxy === "function") return true;
33
+ try {
34
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
35
+ return true;
36
+ } catch (e) {
37
+ return false;
38
+ }
39
+ }
40
+ function _construct(Parent, args, Class) {
41
+ if (_isNativeReflectConstruct()) {
42
+ _construct = Reflect.construct.bind();
43
+ } else {
44
+ _construct = function _construct(Parent, args, Class) {
45
+ var a = [null];
46
+ a.push.apply(a, args);
47
+ var Constructor = Function.bind.apply(Parent, a);
48
+ var instance = new Constructor();
49
+ if (Class) _setPrototypeOf(instance, Class.prototype);
50
+ return instance;
51
+ };
52
+ }
53
+ return _construct.apply(null, arguments);
54
+ }
55
+ function _toPrimitive(input, hint) {
56
+ if (typeof input !== "object" || input === null) return input;
57
+ var prim = input[Symbol.toPrimitive];
58
+ if (prim !== undefined) {
59
+ var res = prim.call(input, hint || "default");
60
+ if (typeof res !== "object") return res;
61
+ throw new TypeError("@@toPrimitive must return a primitive value.");
62
+ }
63
+ return (hint === "string" ? String : Number)(input);
64
+ }
65
+ function _toPropertyKey(arg) {
66
+ var key = _toPrimitive(arg, "string");
67
+ return typeof key === "symbol" ? key : String(key);
68
+ }
69
+
70
+ var BindingType;
71
+ (function (BindingType) {
72
+ BindingType["Constructor"] = "constructor";
73
+ BindingType["ConstantValue"] = "constantValue";
74
+ BindingType["Factory"] = "factory";
75
+ BindingType["ParamsFactory"] = "paramsFactory";
76
+ BindingType["DynamicValue"] = "dynamicValue";
77
+ })(BindingType || (BindingType = {}));
78
+ var BindingTo;
79
+ (function (BindingTo) {
80
+ BindingTo["Constructor"] = "constructor";
81
+ })(BindingTo || (BindingTo = {}));
82
+
83
+ var RegistryType;
84
+ (function (RegistryType) {
85
+ RegistryType["Injected"] = "injected";
86
+ RegistryType["Init"] = "init";
87
+ })(RegistryType || (RegistryType = {}));
88
+
89
+ var IScope;
90
+ (function (IScope) {
91
+ IScope["Singleton"] = "singleton";
92
+ })(IScope || (IScope = {}));
93
+
94
+ var Scope = /*#__PURE__*/function () {
95
+ function Scope() {}
96
+ var _proto = Scope.prototype;
97
+ _proto.toSingletonScope = function toSingletonScope() {
98
+ this._value = IScope.Singleton;
99
+ };
100
+ _proto.inSingletonScope = function inSingletonScope() {
101
+ return this._value === IScope.Singleton;
102
+ };
103
+ _createClass(Scope, [{
104
+ key: "value",
105
+ get: function get() {
106
+ return this._value;
107
+ },
108
+ set: function set(value) {
109
+ this._value = value;
110
+ }
111
+ }]);
112
+ return Scope;
113
+ }();
114
+
115
+ var Binding = /*#__PURE__*/function () {
116
+ function Binding(props) {
117
+ var identifier = props.identifier,
118
+ container = props.container;
119
+ this._identifier = identifier;
120
+ this._container = container;
121
+ this._scope = new Scope();
122
+ }
123
+ _createClass(Binding, [{
124
+ key: "container",
125
+ get: function get() {
126
+ return this._container;
127
+ }
128
+ }, {
129
+ key: "to",
130
+ get: function get() {
131
+ return this._to;
132
+ },
133
+ set: function set(v) {
134
+ this._to = v;
135
+ }
136
+ }, {
137
+ key: "type",
138
+ get: function get() {
139
+ return this._type;
140
+ },
141
+ set: function set(type) {
142
+ this._type = type;
143
+ }
144
+ }, {
145
+ key: "value",
146
+ get: function get() {
147
+ return this._value;
148
+ },
149
+ set: function set(value) {
150
+ this._value = value;
151
+ }
152
+ }, {
153
+ key: "identifier",
154
+ get: function get() {
155
+ return this._identifier;
156
+ }
157
+ }, {
158
+ key: "scope",
159
+ get: function get() {
160
+ return this._scope;
161
+ }
162
+ }]);
163
+ return Binding;
164
+ }();
165
+
166
+ var BindingTo$1 = /*#__PURE__*/function () {
167
+ function BindingTo(props) {
168
+ this.binding = props.binding;
169
+ }
170
+ var _proto = BindingTo.prototype;
171
+ _proto.toSelf = function toSelf() {
172
+ this.binding.type = BindingType.Constructor;
173
+ this.binding.to = this.binding.identifier;
174
+ return this.binding.scope;
175
+ };
176
+ _proto.toConstantValue = function toConstantValue(value) {
177
+ this.binding.type = BindingType.ConstantValue;
178
+ this.binding.value = value;
179
+ return this.binding.scope;
180
+ };
181
+ _proto.to = function to(value) {
182
+ this.binding.type = BindingType.Constructor;
183
+ this.binding.to = value;
184
+ return this.binding.scope;
185
+ };
186
+ _proto.toDynamicValue = function toDynamicValue(value) {
187
+ this.binding.type = BindingType.DynamicValue;
188
+ this.binding.to = value;
189
+ return this.binding.scope;
190
+ };
191
+ _proto.toParamsFactory = function toParamsFactory(value) {
192
+ var _this = this;
193
+ this.binding.type = BindingType.ParamsFactory;
194
+ this.binding.to = value;
195
+ this.binding.value = function () {
196
+ var _this$binding$contain;
197
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
198
+ args[_key] = arguments[_key];
199
+ }
200
+ return (_this$binding$contain = _this.binding.container).resolve.apply(_this$binding$contain, [value].concat(args));
201
+ };
202
+ return this.binding.scope;
203
+ };
204
+ return BindingTo;
205
+ }();
206
+
207
+ var hasSymbol = typeof Symbol !== 'undefined';
208
+ var isFunction = function isFunction(val) {
209
+ return typeof val === 'function';
210
+ };
211
+ var isObject = function isObject(val) {
212
+ return val !== null && typeof val === 'object' && !Array.isArray(val);
213
+ };
214
+ var IS_INJECTABLE = hasSymbol ? /*#__PURE__*/Symbol["for"]('__is_injectable__') : '__is_injectable__';
215
+ var createHiddenProperty = function createHiddenProperty(target, prop, value) {
216
+ Object.defineProperty(target, prop, {
217
+ value: value,
218
+ enumerable: false,
219
+ writable: true
220
+ });
221
+ };
222
+ var isInjectable = function isInjectable(thing) {
223
+ if (!isObject(thing) && !isFunction(thing)) return false;
224
+ if (thing[IS_INJECTABLE]) return true;
225
+ return false;
226
+ };
227
+ var createId = function createId(str) {
228
+ return Symbol(str);
229
+ };
230
+
231
+ var Module = /*#__PURE__*/function () {
232
+ function Module(props) {
233
+ this._constructorDeps = [];
234
+ this._propertyDeps = [];
235
+ this._target = props.target;
236
+ this._registryType = props.registryType || RegistryType.Injected;
237
+ this.addConstructorDependency = this.addConstructorDependency.bind(this);
238
+ this.addPropertyDependency = this.addPropertyDependency.bind(this);
239
+ }
240
+ var _proto = Module.prototype;
241
+ _proto.addPropertyDependency = function addPropertyDependency(id, propertyName) {
242
+ var token = {
243
+ id: id,
244
+ propertyName: propertyName
245
+ };
246
+ this._propertyDeps.push(token);
247
+ };
248
+ _proto.addConstructorDependency = function addConstructorDependency(id, index) {
249
+ var token = {
250
+ id: id,
251
+ index: index
252
+ };
253
+ this._constructorDeps.push(token);
254
+ };
255
+ _createClass(Module, [{
256
+ key: "target",
257
+ get: function get() {
258
+ return this._target;
259
+ },
260
+ set: function set(value) {
261
+ this._target = value;
262
+ }
263
+ }, {
264
+ key: "registryType",
265
+ get: function get() {
266
+ return this._registryType;
267
+ }
268
+ }, {
269
+ key: "constructorDeps",
270
+ get: function get() {
271
+ return this._constructorDeps;
272
+ }
273
+ }, {
274
+ key: "propertyDeps",
275
+ get: function get() {
276
+ return this._propertyDeps;
277
+ }
278
+ }]);
279
+ return Module;
280
+ }();
281
+
282
+ var store;
283
+ (function (store) {
284
+ store.moduleMap = /*#__PURE__*/new Map();
285
+ store.setModule = function (id, module) {
286
+ return store.moduleMap.set(id, module);
287
+ };
288
+ store.hasTargetModule = function (decoratorTarget) {
289
+ return store.moduleMap.has(decoratorTarget);
290
+ };
291
+ store.getTargetModule = function (target) {
292
+ return store.moduleMap.get(target);
293
+ };
294
+ })(store || (store = {}));
295
+ function registerModule(target, registryType) {
296
+ if (!target) return null;
297
+ var _module = new Module({
298
+ target: target,
299
+ registryType: registryType
300
+ });
301
+ store.setModule(target, _module);
302
+ return _module;
303
+ }
304
+ function ensureModule(target) {
305
+ if (!target) return null;
306
+ var targetModule = store.getTargetModule(target);
307
+ if (targetModule) return targetModule;
308
+ var _module = registerModule(target, RegistryType.Init);
309
+ createHiddenProperty(target, IS_INJECTABLE, true);
310
+ return _module;
311
+ }
312
+ function addDependencies(target, dependencyModuleIdentifier, propertyName, index) {
313
+ if (typeof index !== 'number') {
314
+ var targetModule = ensureModule(target.constructor);
315
+ targetModule.addPropertyDependency(dependencyModuleIdentifier, propertyName);
316
+ } else {
317
+ var _targetModule = ensureModule(target);
318
+ _targetModule.addConstructorDependency(dependencyModuleIdentifier, index);
319
+ }
320
+ }
321
+
322
+ var DUPLICATED_INJECTABLE_DECORATOR = 'Cannot apply @injectable decorator multiple times.';
323
+ var BINDING_NOT_FOUND = function BINDING_NOT_FOUND(id, index) {
324
+ return "[instantiate error ] " + String(id) + "(index: " + index + ") cannot find corresponding binding";
325
+ };
326
+
327
+ function instantiate(binding, container) {
328
+ try {
329
+ var ctor = binding;
330
+ if (binding instanceof Binding) {
331
+ if (binding.type === BindingType.DynamicValue) {
332
+ binding.value = binding.to({
333
+ container: container
334
+ });
335
+ return binding.value;
336
+ }
337
+ ctor = binding.to;
338
+ }
339
+ if (!isInjectable(ctor)) return new ctor();
340
+ var module = store.getTargetModule(ctor);
341
+ var constructorDeps = module.constructorDeps || [];
342
+ var args = [];
343
+ for (var idx = 0; idx < constructorDeps.length; idx++) {
344
+ var current = constructorDeps[idx];
345
+ var id = current.id,
346
+ index = current.index;
347
+ var moduleBinding = container.getBinding(id);
348
+ if (!moduleBinding) {
349
+ throw new Error(BINDING_NOT_FOUND(id, index));
350
+ }
351
+ if (moduleBinding.value != null) args[index] = moduleBinding.value;else {
352
+ args[index] = instantiate(moduleBinding, container);
353
+ if (moduleBinding.type !== BindingType.ParamsFactory) moduleBinding.value = args[index];
354
+ }
355
+ }
356
+ for (var _len = arguments.length, passingArgs = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
357
+ passingArgs[_key - 2] = arguments[_key];
358
+ }
359
+ passingArgs.forEach(function (constructorParam, index) {
360
+ return args[index] = constructorParam;
361
+ });
362
+ var instance = _construct(ctor, args);
363
+ var propertyDeps = module.propertyDeps;
364
+ for (var _idx = 0; _idx < propertyDeps.length; _idx++) {
365
+ var _current = propertyDeps[_idx];
366
+ var _id = _current.id,
367
+ propertyName = _current.propertyName;
368
+ var _moduleBinding = container.getBinding(_id);
369
+ if (!_moduleBinding) {
370
+ throw new Error(BINDING_NOT_FOUND(_id, _idx));
371
+ }
372
+ if (_moduleBinding.value != null) {
373
+ instance[propertyName] = _moduleBinding.value;
374
+ } else {
375
+ instance[propertyName] = instantiate(_moduleBinding, container);
376
+ if (_moduleBinding.type !== BindingType.ParamsFactory) _moduleBinding.value = instance[propertyName];
377
+ }
378
+ }
379
+ if (binding instanceof Binding) binding.value = instance;
380
+ return instance;
381
+ } catch (err) {
382
+ var bindingInfo = binding instanceof Binding ? {
383
+ identifier: binding.identifier,
384
+ to: binding.to
385
+ } : {
386
+ ctor: binding
387
+ };
388
+ console.error('[instantiate error ] ', binding, bindingInfo, err);
389
+ return null;
390
+ }
391
+ }
392
+
393
+ var Container = /*#__PURE__*/function () {
394
+ function Container() {
395
+ this._bindingStore = new Map();
396
+ this._belongs = null;
397
+ }
398
+ var _proto = Container.prototype;
399
+ _proto.bind = function bind(identifier) {
400
+ var binding = new Binding({
401
+ identifier: identifier,
402
+ container: this
403
+ });
404
+ this._bindingStore.set(identifier, binding);
405
+ return new BindingTo$1({
406
+ binding: binding
407
+ });
408
+ };
409
+ _proto.setBelongs = function setBelongs(belongs) {
410
+ this._belongs = belongs;
411
+ };
412
+ _proto.getBinding = function getBinding(identifier) {
413
+ var bindingStack = [];
414
+ var belongs = this;
415
+ while (belongs) {
416
+ var binding = belongs.bindingStore.get(identifier);
417
+ if (binding) bindingStack.push(binding);
418
+ belongs = belongs._belongs;
419
+ }
420
+ var lastIndex = bindingStack.length - 1;
421
+ return bindingStack[lastIndex];
422
+ };
423
+ _proto.get = function get(identifier) {
424
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
425
+ args[_key - 1] = arguments[_key];
426
+ }
427
+ return this.resolve.apply(this, [identifier].concat(args));
428
+ };
429
+ _proto.load = function load(registry) {
430
+ registry.load(this);
431
+ };
432
+ _proto.resolve = function resolve(identifier) {
433
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
434
+ args[_key2 - 1] = arguments[_key2];
435
+ }
436
+ if (isInjectable(identifier)) return instantiate.apply(void 0, [identifier, this].concat(args));
437
+ var binding = this.getBinding(identifier);
438
+ if (!binding) {
439
+ return null;
440
+ }
441
+ if (binding.value != null) {
442
+ return binding.value;
443
+ }
444
+ return instantiate.apply(void 0, [binding, this].concat(args));
445
+ };
446
+ _createClass(Container, [{
447
+ key: "bindingStore",
448
+ get: function get() {
449
+ return this._bindingStore;
450
+ }
451
+ }]);
452
+ return Container;
453
+ }();
454
+
455
+ var Registry = /*#__PURE__*/function () {
456
+ function Registry(registryFactory, registryOptions) {
457
+ this.registryFactory = registryFactory;
458
+ this.registryOptions = registryOptions || {};
459
+ }
460
+ var _proto = Registry.prototype;
461
+ _proto.load = function load(container) {
462
+ this.registryFactory(container.bind.bind(container));
463
+ };
464
+ return Registry;
465
+ }();
466
+
467
+ function inject(moduleIdentifier) {
468
+ return function (target, propertyName, index) {
469
+ addDependencies(target, moduleIdentifier, propertyName, index);
470
+ };
471
+ }
472
+
473
+ function injectable() {
474
+ return function (target) {
475
+ var module = store.getTargetModule(target);
476
+ if (module && module.registryType === RegistryType.Injected) {
477
+ throw new Error(DUPLICATED_INJECTABLE_DECORATOR);
478
+ }
479
+ if (module && module.target) return module.target;
480
+ registerModule(target, RegistryType.Injected);
481
+ createHiddenProperty(target, IS_INJECTABLE, true);
482
+ return target;
483
+ };
484
+ }
485
+
486
+ exports.Container = Container;
487
+ exports.Registry = Registry;
488
+ exports.createId = createId;
489
+ exports.inject = inject;
490
+ exports.injectable = injectable;
491
+ //# sourceMappingURL=di.cjs.development.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"di.cjs.development.js","sources":["../src/types/binding.ts","../src/types/module.ts","../src/types/scope.ts","../src/scope/Scope.ts","../src/binding/Binding.ts","../src/binding/BindingTo.ts","../src/common.ts","../src/store/Module.ts","../src/store/index.ts","../src/constants/error.ts","../src/instantiate.ts","../src/Container.ts","../src/Registry.ts","../src/decorator/inject.ts","../src/decorator/injectable.ts"],"sourcesContent":["import Container from '../Container';\nimport { ModuleIdentifier, Context } from './container';\n\nexport type Ctor<T = object> = new (...args: any[]) => T;\n\nexport enum BindingType {\n Constructor = 'constructor',\n ConstantValue = 'constantValue',\n Factory = 'factory',\n ParamsFactory = 'paramsFactory',\n DynamicValue = 'dynamicValue',\n}\n\nexport enum BindingTo {\n Constructor = 'constructor',\n}\n\nexport type BindingFactory = (ctx: Context) => Function;\n\nexport type ToValueCtor = Ctor;\nexport type ToValueBindingFactory = BindingFactory;\nexport type ToValueBindingParamsFactory = Ctor;\nexport type ToValueDynamicValue = (ctx: Context) => any;\n\nexport type ToValue =\n | ToValueCtor\n | ToValueBindingFactory\n | ToValueBindingParamsFactory;\n\nexport type BindingValue = any;\n\nexport type BindingProps = {\n container: Container;\n to?: ToValue;\n value?: BindingValue;\n type?: BindingType;\n identifier: ModuleIdentifier;\n};\n","import { ModuleIdentifier } from './container';\nimport { DecoratorTarget } from './decorator';\n\nexport type ModuleProps = {\n // id: string\n registryType?: RegistryType;\n target: DecoratorTarget;\n};\n\nexport type ModulePropertyDepToken = {\n // module: Module\n id: ModuleIdentifier;\n propertyName: string;\n};\n\nexport type ModuleConstructorDepToken = {\n // module: Module\n id: ModuleIdentifier;\n index: number;\n};\n\nexport enum RegistryType {\n Injected = 'injected',\n Init = 'init',\n}\n","export enum IScope {\n Singleton = 'singleton',\n}\n","import { IScope } from '../types';\n\nexport default class Scope {\n private _value: IScope;\n\n get value() {\n return this._value;\n }\n\n set value(value: IScope) {\n this._value = value;\n }\n\n toSingletonScope() {\n this._value = IScope.Singleton;\n }\n\n inSingletonScope() {\n return this._value === IScope.Singleton;\n }\n}\n","import Container from '../Container';\nimport {\n BindingProps,\n BindingType,\n BindingValue,\n ModuleIdentifier,\n ToValue,\n} from '../types';\nimport Scope from '../scope/Scope';\n\nclass Binding {\n private _identifier: ModuleIdentifier;\n\n private _type: BindingType;\n\n private _to: ToValue;\n\n private _value: BindingValue;\n\n private _container: Container;\n\n private _scope: Scope;\n\n constructor(props: BindingProps) {\n const { identifier, container } = props;\n this._identifier = identifier;\n this._container = container;\n this._scope = new Scope();\n }\n\n get container() {\n return this._container;\n }\n\n get to() {\n return this._to;\n }\n\n set to(v: any) {\n this._to = v;\n }\n\n get type() {\n return this._type;\n }\n\n set type(type: BindingType) {\n this._type = type;\n }\n\n get value() {\n return this._value;\n }\n\n set value(value: BindingValue) {\n this._value = value;\n }\n\n get identifier() {\n return this._identifier;\n }\n\n get scope() {\n return this._scope;\n }\n}\n\nexport default Binding;\n","import Binding from './Binding';\nimport {\n BindingToProps,\n ToValueCtor,\n ToValueDynamicValue,\n BindingType,\n} from '../types';\n\nclass BindingTo {\n private binding: Binding;\n\n constructor(props: BindingToProps) {\n this.binding = props.binding;\n }\n\n toSelf() {\n this.binding.type = BindingType.Constructor;\n this.binding.to = this.binding.identifier;\n return this.binding.scope;\n }\n\n toConstantValue(value: any) {\n this.binding.type = BindingType.ConstantValue;\n this.binding.value = value;\n return this.binding.scope;\n }\n\n to(value: ToValueCtor) {\n this.binding.type = BindingType.Constructor;\n this.binding.to = value;\n return this.binding.scope;\n }\n\n toDynamicValue(value: ToValueDynamicValue) {\n this.binding.type = BindingType.DynamicValue;\n this.binding.to = value;\n return this.binding.scope;\n }\n\n toParamsFactory(value: ToValueCtor) {\n this.binding.type = BindingType.ParamsFactory;\n this.binding.to = value;\n this.binding.value = (...args: any[]) => {\n return this.binding.container.resolve(value, ...args);\n };\n return this.binding.scope;\n }\n}\n\nexport default BindingTo;\n","export const hasSymbol = typeof Symbol !== 'undefined';\n\nconst isFunction = (val: unknown): val is Function => {\n return typeof val === 'function';\n};\n\nconst isObject = (val: unknown): val is object => {\n return val !== null && typeof val === 'object' && !Array.isArray(val);\n};\n\nexport const DEPENDENCIES: unique symbol = hasSymbol\n ? Symbol.for('__dependencies__')\n : ('__dependencies__' as any);\n\nexport const IS_INJECTABLE: unique symbol = hasSymbol\n ? Symbol.for('__is_injectable__')\n : ('__is_injectable__' as any);\n\nexport const createHiddenProperty = (\n target: object,\n prop: PropertyKey,\n value: any\n) => {\n Object.defineProperty(target, prop, {\n value,\n enumerable: false,\n writable: true,\n });\n};\n\nexport const isInjectable = (thing: any) => {\n if (!isObject(thing) && !isFunction(thing)) return false;\n if (thing[IS_INJECTABLE]) return true;\n return false;\n};\n\nexport const createId = (str: string) => Symbol(str);\n","import {\n ModuleProps,\n DecoratorTarget,\n ModulePropertyDepToken,\n ModuleConstructorDepToken,\n ModuleIdentifier,\n RegistryType,\n} from '../types';\n\nexport default class Module {\n private _constructorDeps: ModuleConstructorDepToken[] = [];\n\n private _propertyDeps: ModulePropertyDepToken[] = [];\n\n private _target: DecoratorTarget;\n\n // private readonly _id: string\n\n private readonly _registryType: RegistryType;\n\n constructor(props: ModuleProps) {\n this._target = props.target;\n // this._id = props.id\n this._registryType = props.registryType || RegistryType.Injected;\n this.addConstructorDependency = this.addConstructorDependency.bind(this);\n this.addPropertyDependency = this.addPropertyDependency.bind(this);\n }\n\n get target() {\n return this._target;\n }\n\n set target(value: DecoratorTarget) {\n this._target = value;\n }\n\n // get id() {\n // return this._id\n // }\n\n get registryType() {\n return this._registryType;\n }\n\n addPropertyDependency(id: ModuleIdentifier, propertyName: string) {\n const token = { id, propertyName };\n this._propertyDeps.push(token);\n }\n\n addConstructorDependency(id: ModuleIdentifier, index: number) {\n const token = { id, index };\n this._constructorDeps.push(token);\n }\n\n get constructorDeps() {\n return this._constructorDeps;\n }\n\n get propertyDeps() {\n return this._propertyDeps;\n }\n}\n","import Module from './Module';\nimport { DecoratorTarget, ModuleIdentifier, RegistryType } from '../types';\nimport { createHiddenProperty, IS_INJECTABLE } from '../common';\n\nexport namespace store {\n export const moduleMap = new Map<any, Module>();\n\n // export const getModule = (id: ModuleIdentifier) => moduleMap.get(id)\n export const setModule = (id: any, module: Module) =>\n moduleMap.set(id, module);\n\n export const hasTargetModule = (decoratorTarget: DecoratorTarget) => {\n return moduleMap.has(decoratorTarget);\n // const id = moduleIdentifierExtractor(decoratorTarget)\n // return moduleMap.has(id)\n };\n export const getTargetModule = (target: DecoratorTarget) => {\n return moduleMap.get(target);\n // const id = moduleIdentifierExtractor(target)\n // return getModule(id)\n };\n}\n\nexport function registerModule(\n target: DecoratorTarget,\n registryType: RegistryType\n) {\n if (!target) return null;\n // const id = moduleIdentifierExtractor(target)\n const _module = new Module({ target, registryType });\n // store.setModule(id, _module)\n store.setModule(target, _module);\n return _module;\n}\n\nexport function ensureModule(target: DecoratorTarget) {\n if (!target) return null;\n const targetModule = store.getTargetModule(target);\n if (targetModule) return targetModule;\n const _module = registerModule(target, RegistryType.Init);\n createHiddenProperty(target, IS_INJECTABLE, true);\n return _module;\n}\n\nexport function addDependencies(\n target: DecoratorTarget,\n dependencyModuleIdentifier: ModuleIdentifier,\n propertyName: string,\n index?: number\n) {\n if (typeof index !== 'number') {\n // if it's a property binding, then use target.constructor\n const targetModule = ensureModule(target.constructor as DecoratorTarget);\n targetModule.addPropertyDependency(\n dependencyModuleIdentifier,\n propertyName\n );\n } else {\n const targetModule = ensureModule(target);\n targetModule.addConstructorDependency(dependencyModuleIdentifier, index);\n }\n}\n","import { ModuleIdentifier } from '../types';\n\nexport const DUPLICATED_INJECTABLE_DECORATOR =\n 'Cannot apply @injectable decorator multiple times.';\n// @ts-ignore\nexport const INSTANTIATE_FACTORY_SERVICE = (id: ModuleIdentifier) =>\n `Cannot instantiate ${String(id)} factory service, use 'get' method instead`;\nexport const BINDING_NOT_FOUND = (id: ModuleIdentifier, index: number) =>\n // @ts-ignore\n `[instantiate error ] ${String(\n id\n )}(index: ${index}) cannot find corresponding binding`;\n","import { isInjectable } from './common';\nimport { Ctor, BindingType } from './types';\nimport { store } from './store';\nimport Container from './Container';\nimport { BINDING_NOT_FOUND } from './constants/error';\nimport Binding from './binding/Binding';\n\nexport function instantiate(\n binding: Binding | Ctor,\n container: Container,\n ...passingArgs: any[]\n): any {\n try {\n let ctor: Ctor = binding as Ctor;\n\n if (binding instanceof Binding) {\n if (binding.type === BindingType.DynamicValue) {\n binding.value = binding.to({ container });\n return binding.value;\n }\n\n ctor = binding.to;\n }\n\n if (!isInjectable(ctor)) return new ctor();\n\n const module = store.getTargetModule(ctor);\n\n const constructorDeps = module.constructorDeps || [];\n\n const args = [];\n\n for (let idx = 0; idx < constructorDeps.length; idx++) {\n const current = constructorDeps[idx];\n const { id, index } = current;\n\n const moduleBinding = container.getBinding(id);\n\n if (!moduleBinding) {\n throw new Error(BINDING_NOT_FOUND(id, index));\n }\n\n if (moduleBinding.value != null) args[index] = moduleBinding.value;\n else {\n args[index] = instantiate(moduleBinding, container);\n if (moduleBinding.type !== BindingType.ParamsFactory)\n moduleBinding.value = args[index];\n }\n }\n\n // passing params should be insert on before\n passingArgs.forEach(\n (constructorParam, index) => (args[index] = constructorParam)\n );\n\n const instance = new ctor(...args) as any;\n\n const propertyDeps = module.propertyDeps;\n\n for (let idx = 0; idx < propertyDeps.length; idx++) {\n const current = propertyDeps[idx];\n const { id, propertyName } = current;\n\n const moduleBinding = container.getBinding(id);\n\n if (!moduleBinding) {\n throw new Error(BINDING_NOT_FOUND(id, idx));\n }\n\n if (moduleBinding.value != null) {\n instance[propertyName] = moduleBinding.value;\n } else {\n instance[propertyName] = instantiate(moduleBinding, container);\n if (moduleBinding.type !== BindingType.ParamsFactory)\n moduleBinding.value = instance[propertyName];\n }\n }\n\n if (binding instanceof Binding) binding.value = instance;\n\n return instance;\n } catch (err) {\n const bindingInfo =\n binding instanceof Binding\n ? { identifier: binding.identifier, to: binding.to }\n : { ctor: binding };\n console.error('[instantiate error ] ', binding, bindingInfo, err);\n return null;\n }\n}\n","import { Ctor, ModuleIdentifier } from './types';\nimport Binding from './binding/Binding';\nimport BindingTo from './binding/BindingTo';\nimport { instantiate } from './instantiate';\nimport { isInjectable } from './common';\nimport Registry from './Registry';\n\nclass Container {\n private _bindingStore = new Map<ModuleIdentifier, Binding>();\n\n private _belongs: Container = null;\n\n bind(identifier: ModuleIdentifier) {\n const binding = new Binding({\n identifier,\n container: this,\n });\n this._bindingStore.set(identifier, binding);\n return new BindingTo({ binding });\n }\n\n get bindingStore() {\n return this._bindingStore;\n }\n\n setBelongs(belongs: Container) {\n this._belongs = belongs;\n }\n\n getBinding(identifier: ModuleIdentifier | Ctor) {\n const bindingStack = [];\n\n let belongs: Container = this;\n\n while (belongs) {\n const binding = belongs.bindingStore.get(identifier);\n if (binding) bindingStack.push(binding);\n belongs = belongs._belongs;\n }\n\n // Aim to ensure singleton, get the top most instance.\n const lastIndex = bindingStack.length - 1;\n\n return bindingStack[lastIndex];\n }\n\n get(identifier: ModuleIdentifier | Ctor, ...args: any[]) {\n return this.resolve(identifier, ...args);\n }\n\n load(registry: Registry) {\n registry.load(this);\n }\n\n /**\n *\n * @param identifier\n * @returns\n *\n * container.resolve(\"LogService\")\n * container.resolve(LogService)\n */\n resolve(identifier: ModuleIdentifier | Ctor, ...args: any[]): any {\n /** for injectable as identifier condition, currently only used by toParamsFactory */\n if (isInjectable(identifier))\n return instantiate(identifier as Ctor, this, ...args);\n const binding = this.getBinding(identifier);\n\n if (!binding) {\n return null;\n }\n\n if (binding.value != null) {\n return binding.value;\n }\n\n return instantiate(binding, this, ...args);\n }\n}\n\nexport default Container;\n","import Container from './Container';\nimport { RegistryFactory, RegistryOptions } from './types';\n\nclass Registry {\n private readonly registryFactory: RegistryFactory;\n\n private readonly registryOptions: RegistryOptions;\n\n constructor(\n registryFactory: RegistryFactory,\n registryOptions?: RegistryOptions\n ) {\n this.registryFactory = registryFactory;\n this.registryOptions = registryOptions || {};\n }\n\n load(container: Container) {\n this.registryFactory(container.bind.bind(container));\n }\n}\n\nexport default Registry;\n","import { ModuleIdentifier, DecoratorTarget } from '../types';\nimport { addDependencies } from '../store';\n\nexport function inject<T>(moduleIdentifier: ModuleIdentifier) {\n return (target: DecoratorTarget<T>, propertyName: string, index?: number) => {\n addDependencies(target, moduleIdentifier, propertyName, index);\n };\n}\n","import { IS_INJECTABLE, createHiddenProperty } from '../common';\nimport * as ERRORS_MSGS from '../constants/error';\nimport { registerModule, store } from '../store';\nimport { DecoratorTarget, RegistryType } from '../types';\n\nfunction injectable() {\n return function <T extends DecoratorTarget>(target: T) {\n const module = store.getTargetModule(target);\n\n if (module && module.registryType === RegistryType.Injected) {\n // module.target = target\n // registerModule(target, RegistryType.Injected)\n // createHiddenProperty(target, IS_INJECTABLE, true)\n // return target\n // // return module.target\n throw new Error(ERRORS_MSGS.DUPLICATED_INJECTABLE_DECORATOR);\n }\n\n if (module && module.target) return module.target as any;\n\n registerModule(target, RegistryType.Injected);\n createHiddenProperty(target, IS_INJECTABLE, true);\n\n return target;\n };\n}\n\nexport { injectable };\n"],"names":["BindingType","BindingTo","RegistryType","IScope","Scope","_proto","prototype","toSingletonScope","_value","Singleton","inSingletonScope","_createClass","key","get","set","value","Binding","props","identifier","container","_identifier","_container","_scope","_to","v","_type","type","binding","toSelf","Constructor","to","scope","toConstantValue","ConstantValue","toDynamicValue","DynamicValue","toParamsFactory","ParamsFactory","args","Array","_len","_key","arguments","_this$binding$contain","_this","resolve","apply","concat","hasSymbol","Symbol","isFunction","val","isObject","isArray","IS_INJECTABLE","createHiddenProperty","target","prop","Object","defineProperty","enumerable","writable","isInjectable","thing","createId","str","Module","_target","_registryType","registryType","Injected","addConstructorDependency","bind","addPropertyDependency","id","propertyName","token","_propertyDeps","push","index","_constructorDeps","store","Map","module","moduleMap","decoratorTarget","has","registerModule","_module","setModule","ensureModule","targetModule","getTargetModule","Init","addDependencies","dependencyModuleIdentifier","constructor","DUPLICATED_INJECTABLE_DECORATOR","BINDING_NOT_FOUND","String","instantiate","ctor","constructorDeps","idx","length","current","moduleBinding","getBinding","Error","passingArgs","forEach","constructorParam","instance","_construct","propertyDeps","err","bindingInfo","console","error","Container","_bindingStore","setBelongs","belongs","_belongs","bindingStack","bindingStore","lastIndex","load","registry","_len2","_key2","Registry","registryFactory","registryOptions","inject","moduleIdentifier","injectable","ERRORS_MSGS"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,IAAYA,WAMX;AAND,WAAYA,WAAW;EACrBA,0CAA2B;EAC3BA,8CAA+B;EAC/BA,kCAAmB;EACnBA,8CAA+B;EAC/BA,4CAA6B;AAC/B,CAAC,EANWA,WAAW,KAAXA,WAAW;AAQvB,IAAYC,SAEX;AAFD,WAAYA,SAAS;EACnBA,wCAA2B;AAC7B,CAAC,EAFWA,SAAS,KAATA,SAAS;;ACQrB,IAAYC,YAGX;AAHD,WAAYA,YAAY;EACtBA,qCAAqB;EACrBA,6BAAa;AACf,CAAC,EAHWA,YAAY,KAAZA,YAAY;;ACrBxB,IAAYC,MAEX;AAFD,WAAYA,MAAM;EAChBA,iCAAuB;AACzB,CAAC,EAFWA,MAAM,KAANA,MAAM;;ACAgB,IAEbC,KAAK;EAAA,SAAAA;EAAA,IAAAC,M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