@rolster/invertly 1.1.1 → 1.3.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/cjs/index.js +241 -243
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/index.js +241 -243
- package/dist/es/index.js.map +1 -1
- package/dist/esm/decorators/index.d.ts +2 -2
- package/dist/esm/decorators/index.js +2 -2
- package/dist/esm/decorators/inject.decorator.d.ts +4 -4
- package/dist/esm/decorators/inject.decorator.js +15 -16
- package/dist/esm/decorators/inject.decorator.js.map +1 -1
- package/dist/esm/decorators/injectable.decorator.d.ts +6 -6
- package/dist/esm/decorators/injectable.decorator.js +10 -10
- package/dist/esm/factories/container.factory.d.ts +8 -9
- package/dist/esm/factories/container.factory.js +105 -111
- package/dist/esm/factories/container.factory.js.map +1 -1
- package/dist/esm/factories/index.d.ts +21 -21
- package/dist/esm/factories/index.js +32 -34
- package/dist/esm/factories/index.js.map +1 -1
- package/dist/esm/index.d.ts +6 -6
- package/dist/esm/index.js +5 -5
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/stores/context.store.d.ts +7 -7
- package/dist/esm/stores/context.store.js +14 -14
- package/dist/esm/stores/index.d.ts +5 -5
- package/dist/esm/stores/index.js +5 -5
- package/dist/esm/stores/inject.store.d.ts +7 -6
- package/dist/esm/stores/inject.store.js +13 -19
- package/dist/esm/stores/inject.store.js.map +1 -1
- package/dist/esm/stores/injectable.store.d.ts +8 -8
- package/dist/esm/stores/injectable.store.js +11 -11
- package/dist/esm/stores/locator.store.d.ts +7 -7
- package/dist/esm/stores/locator.store.js +31 -32
- package/dist/esm/stores/locator.store.js.map +1 -1
- package/dist/esm/stores/scope.store.d.ts +6 -7
- package/dist/esm/stores/scope.store.js +11 -11
- package/dist/esm/stores/scope.store.js.map +1 -1
- package/dist/esm/types/constructable.type.d.ts +1 -1
- package/dist/esm/types/constructable.type.js +1 -1
- package/dist/esm/types/context.type.d.ts +5 -5
- package/dist/esm/types/context.type.js +1 -1
- package/dist/esm/types/index.d.ts +5 -5
- package/dist/esm/types/index.js +5 -5
- package/dist/esm/types/inject.type.d.ts +9 -9
- package/dist/esm/types/inject.type.js +1 -1
- package/dist/esm/types/injectable.type.d.ts +12 -12
- package/dist/esm/types/injectable.type.js +1 -1
- package/dist/esm/types/locator.type.d.ts +8 -8
- package/dist/esm/types/locator.type.js +1 -1
- package/package.json +5 -4
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import { registerInject } from '../factories';
|
|
2
|
-
function createInject(inject) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
1
|
+
import { registerInject } from '../factories';
|
|
2
|
+
function createInject(inject) {
|
|
3
|
+
return (parent, _, index) => {
|
|
4
|
+
registerInject({ ...inject, index, parent });
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
export function Singleton(token) {
|
|
8
|
+
return createInject({ token, scopeable: false, singleton: true });
|
|
9
|
+
}
|
|
10
|
+
export function Scope(token) {
|
|
11
|
+
return createInject({ token, scopeable: true, singleton: false });
|
|
12
|
+
}
|
|
13
|
+
export function Factory(token) {
|
|
14
|
+
return createInject({ token, scopeable: false, singleton: false });
|
|
15
|
+
}
|
|
17
16
|
//# sourceMappingURL=inject.decorator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inject.decorator.js","sourceRoot":"","sources":["../../../src/decorators/inject.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAS9C,SAAS,YAAY,CAAC,
|
|
1
|
+
{"version":3,"file":"inject.decorator.js","sourceRoot":"","sources":["../../../src/decorators/inject.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAS9C,SAAS,YAAY,CAAC,MAAqB;IACzC,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE;QAC1B,cAAc,CAAC,EAAE,GAAG,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;IAC/C,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,KAAkB;IAC1C,OAAO,YAAY,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AACpE,CAAC;AAED,MAAM,UAAU,KAAK,CAAC,KAAkB;IACtC,OAAO,YAAY,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;AACpE,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,KAAkB;IACxC,OAAO,YAAY,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;AACrE,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
interface InjectableOptions {
|
|
2
|
-
scopeable?: boolean;
|
|
3
|
-
singleton?: boolean;
|
|
4
|
-
}
|
|
5
|
-
export declare function Injectable(options?: InjectableOptions): ClassDecorator;
|
|
6
|
-
export {};
|
|
1
|
+
interface InjectableOptions {
|
|
2
|
+
scopeable?: boolean;
|
|
3
|
+
singleton?: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare function Injectable(options?: InjectableOptions): ClassDecorator;
|
|
6
|
+
export {};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { registerInjectable } from '../factories';
|
|
2
|
-
export function Injectable(options) {
|
|
3
|
-
return (token) => {
|
|
4
|
-
registerInjectable({
|
|
5
|
-
scopeable: !!options?.scopeable,
|
|
6
|
-
singleton: !!options?.singleton,
|
|
7
|
-
token
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
}
|
|
1
|
+
import { registerInjectable } from '../factories';
|
|
2
|
+
export function Injectable(options) {
|
|
3
|
+
return (token) => {
|
|
4
|
+
registerInjectable({
|
|
5
|
+
scopeable: !!options?.scopeable,
|
|
6
|
+
singleton: !!options?.singleton,
|
|
7
|
+
token
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
11
|
//# sourceMappingURL=injectable.decorator.js.map
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
|
-
import { InjectOptions, InjectableOptions, InjectionOptions } from '../types';
|
|
3
|
-
export declare class
|
|
4
|
-
private readonly
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import { InjectOptions, InjectableOptions, InjectionOptions } from '../types';
|
|
3
|
+
export declare class InvertlyContainer {
|
|
4
|
+
private readonly dataCenter;
|
|
5
|
+
registerInjectable(options: InjectableOptions): void;
|
|
6
|
+
registerInject(options: InjectOptions): void;
|
|
7
|
+
createInjectable<T = any>(options: InjectionOptions<T>): T;
|
|
8
|
+
}
|
|
@@ -1,112 +1,106 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
|
-
import { Context, InjectStore, InjectableStore, ScopeStore, requestInLocator } from '../stores';
|
|
3
|
-
class
|
|
4
|
-
constructor() {
|
|
5
|
-
this.scope = new ScopeStore();
|
|
6
|
-
this.injectables = new InjectableStore();
|
|
7
|
-
this.injects = new InjectStore();
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
class
|
|
11
|
-
constructor(
|
|
12
|
-
this.
|
|
13
|
-
this.context = context;
|
|
14
|
-
this.scope = new ScopeStore();
|
|
15
|
-
}
|
|
16
|
-
build(injectable) {
|
|
17
|
-
const
|
|
18
|
-
if (!
|
|
19
|
-
throw Error(`Class ${injectable.toString()} is not found in the collection`);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return this.
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
this.
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
this.
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
this.
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const { token, context } = options;
|
|
107
|
-
const { warehouse } = this;
|
|
108
|
-
const dependency = new Dependency({ warehouse, context });
|
|
109
|
-
return dependency.build(token);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import { Context, InjectStore, InjectableStore, ScopeStore, requestInLocator } from '../stores';
|
|
3
|
+
class DataCenter {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.scope = new ScopeStore();
|
|
6
|
+
this.injectables = new InjectableStore();
|
|
7
|
+
this.injects = new InjectStore();
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
class InjectableFactory {
|
|
11
|
+
constructor(dataCenter, context) {
|
|
12
|
+
this.dataCenter = dataCenter;
|
|
13
|
+
this.context = context;
|
|
14
|
+
this.scope = new ScopeStore();
|
|
15
|
+
}
|
|
16
|
+
build(injectable) {
|
|
17
|
+
const options = this.dataCenter.injectables.request(injectable);
|
|
18
|
+
if (!options) {
|
|
19
|
+
throw Error(`Class ${injectable.toString()} is not found in the collection`);
|
|
20
|
+
}
|
|
21
|
+
return this.createInstance(options);
|
|
22
|
+
}
|
|
23
|
+
createObject(token) {
|
|
24
|
+
const Constructor = token;
|
|
25
|
+
const tokens = this.reflectTokens(Constructor);
|
|
26
|
+
const params = tokens
|
|
27
|
+
? this.createReflectArgs({ token, tokens })
|
|
28
|
+
: this.createTokenArgs(token);
|
|
29
|
+
return new Constructor(...params);
|
|
30
|
+
}
|
|
31
|
+
reflectTokens(constructable) {
|
|
32
|
+
return Reflect.getMetadata('design:paramtypes', constructable);
|
|
33
|
+
}
|
|
34
|
+
createFromScope({ token, scope }) {
|
|
35
|
+
let instance = scope.request(token);
|
|
36
|
+
if (!instance) {
|
|
37
|
+
instance = this.createObject(token);
|
|
38
|
+
scope.push(token, instance);
|
|
39
|
+
}
|
|
40
|
+
return instance;
|
|
41
|
+
}
|
|
42
|
+
createFromContainer(token) {
|
|
43
|
+
return this.createFromScope({ token, scope: this.dataCenter.scope });
|
|
44
|
+
}
|
|
45
|
+
createInstance(options) {
|
|
46
|
+
const { token, scopeable, singleton } = options;
|
|
47
|
+
if (singleton) {
|
|
48
|
+
return this.createFromContainer(token);
|
|
49
|
+
}
|
|
50
|
+
if (scopeable) {
|
|
51
|
+
return this.createFromScope({ token, scope: this.scope });
|
|
52
|
+
}
|
|
53
|
+
return this.createObject(token);
|
|
54
|
+
}
|
|
55
|
+
createFromDecorator(inject) {
|
|
56
|
+
const { token, scopeable, singleton } = inject;
|
|
57
|
+
const locator = requestInLocator(token);
|
|
58
|
+
return this.createInstance({
|
|
59
|
+
token: locator?.useClass ?? token,
|
|
60
|
+
scopeable,
|
|
61
|
+
singleton
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
createReflectArgs({ tokens, token }) {
|
|
65
|
+
const injects = this.dataCenter.injects.request(token);
|
|
66
|
+
return tokens.map((token, index) => {
|
|
67
|
+
const inject = injects[index];
|
|
68
|
+
if (inject) {
|
|
69
|
+
return this.createFromDecorator(inject);
|
|
70
|
+
}
|
|
71
|
+
const locator = requestInLocator(token);
|
|
72
|
+
if (locator) {
|
|
73
|
+
return this.createInstance({
|
|
74
|
+
...locator,
|
|
75
|
+
token: locator.useClass
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
if (token === Context) {
|
|
79
|
+
return this.context;
|
|
80
|
+
}
|
|
81
|
+
return this.createObject(token);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
createTokenArgs(token) {
|
|
85
|
+
const injects = this.dataCenter.injects.request(token);
|
|
86
|
+
return injects.reduce((objects, options) => {
|
|
87
|
+
objects[options.index] = this.createInstance({ ...options });
|
|
88
|
+
return objects;
|
|
89
|
+
}, []);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
export class InvertlyContainer {
|
|
93
|
+
constructor() {
|
|
94
|
+
this.dataCenter = new DataCenter();
|
|
95
|
+
}
|
|
96
|
+
registerInjectable(options) {
|
|
97
|
+
this.dataCenter.injectables.push(options);
|
|
98
|
+
}
|
|
99
|
+
registerInject(options) {
|
|
100
|
+
this.dataCenter.injects.push(options);
|
|
101
|
+
}
|
|
102
|
+
createInjectable(options) {
|
|
103
|
+
return new InjectableFactory(this.dataCenter, options.context).build(options.token);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
112
106
|
//# sourceMappingURL=container.factory.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"container.factory.js","sourceRoot":"","sources":["../../../src/factories/container.factory.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EACL,OAAO,EACP,WAAW,EACX,eAAe,EACf,UAAU,EACV,gBAAgB,EACjB,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"container.factory.js","sourceRoot":"","sources":["../../../src/factories/container.factory.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EACL,OAAO,EACP,WAAW,EACX,eAAe,EACf,UAAU,EACV,gBAAgB,EACjB,MAAM,WAAW,CAAC;AA6BnB,MAAM,UAAU;IAAhB;QACkB,UAAK,GAAG,IAAI,UAAU,EAAE,CAAC;QAEzB,gBAAW,GAAG,IAAI,eAAe,EAAE,CAAC;QAEpC,YAAO,GAAG,IAAI,WAAW,EAAE,CAAC;IAC9C,CAAC;CAAA;AAED,MAAM,iBAAiB;IAGrB,YACU,UAAsB,EACtB,OAAyB;QADzB,eAAU,GAAV,UAAU,CAAY;QACtB,YAAO,GAAP,OAAO,CAAkB;QAJlB,UAAK,GAAG,IAAI,UAAU,EAAE,CAAC;IAKvC,CAAC;IAEG,KAAK,CAAU,UAA8B;QAClD,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAEhE,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,KAAK,CACT,SAAS,UAAU,CAAC,QAAQ,EAAE,iCAAiC,CAChE,CAAC;QACJ,CAAC;QAED,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IACtC,CAAC;IAEO,YAAY,CAAU,KAAyB;QACrD,MAAM,WAAW,GAAG,KAAgC,CAAC;QAErD,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,C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AC,OAAO,EAAE,OAAO,EAAE,EAAE;YACzC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,cAAc,CAAC,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;YAE7D,OAAO,OAAO,CAAC;QACjB,CAAC,EAAE,EAAW,CAAC,CAAC;IAClB,CAAC;CACF;AAED,MAAM,OAAO,iBAAiB;IAA9B;QACmB,eAAU,GAAG,IAAI,UAAU,EAAE,CAAC;IAejD,CAAC;IAbQ,kBAAkB,CAAC,OAA0B;QAClD,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC5C,CAAC;IAEM,cAAc,CAAC,OAAsB;QAC1C,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACxC,CAAC;IAEM,gBAAgB,CAAU,OAA4B;QAC3D,OAAO,IAAI,iBAAiB,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,CAClE,OAAO,CAAC,KAAK,CACd,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { InjectOptions, InjectToken, InjectableOptions, InjectableToken, InjectionOptions } from '../types';
|
|
2
|
-
import {
|
|
3
|
-
interface Inject<T = any> {
|
|
4
|
-
token: InjectToken<T>;
|
|
5
|
-
index?: number;
|
|
6
|
-
scopeable?: boolean;
|
|
7
|
-
singleton?: boolean;
|
|
8
|
-
}
|
|
9
|
-
interface DependencyOptions {
|
|
10
|
-
container?:
|
|
11
|
-
injects?: Inject[];
|
|
12
|
-
scopeable?: boolean;
|
|
13
|
-
singleton?: boolean;
|
|
14
|
-
}
|
|
15
|
-
declare function createFromInvertly<T = any>(options: InjectionOptions<T>, container?:
|
|
16
|
-
export declare function invertly<T = any>(token: InjectableToken<T>, container?:
|
|
17
|
-
export declare function registerInjectable(options: InjectableOptions, container?:
|
|
18
|
-
export declare function registerInject(options: InjectOptions, container?:
|
|
19
|
-
export declare function registerDependency<T = any>(token: InjectableToken<T>, options: DependencyOptions): void;
|
|
20
|
-
export {
|
|
21
|
-
export default createFromInvertly;
|
|
1
|
+
import { InjectOptions, InjectToken, InjectableOptions, InjectableToken, InjectionOptions } from '../types';
|
|
2
|
+
import { InvertlyContainer } from './container.factory';
|
|
3
|
+
interface Inject<T = any> {
|
|
4
|
+
token: InjectToken<T>;
|
|
5
|
+
index?: number;
|
|
6
|
+
scopeable?: boolean;
|
|
7
|
+
singleton?: boolean;
|
|
8
|
+
}
|
|
9
|
+
interface DependencyOptions {
|
|
10
|
+
container?: InvertlyContainer;
|
|
11
|
+
injects?: Inject[];
|
|
12
|
+
scopeable?: boolean;
|
|
13
|
+
singleton?: boolean;
|
|
14
|
+
}
|
|
15
|
+
declare function createFromInvertly<T = any>(options: InjectionOptions<T>, container?: InvertlyContainer): T;
|
|
16
|
+
export declare function invertly<T = any>(token: InjectableToken<T>, container?: InvertlyContainer): T;
|
|
17
|
+
export declare function registerInjectable(options: InjectableOptions, container?: InvertlyContainer): void;
|
|
18
|
+
export declare function registerInject(options: InjectOptions, container?: InvertlyContainer): void;
|
|
19
|
+
export declare function registerDependency<T = any>(token: InjectableToken<T>, options: DependencyOptions): void;
|
|
20
|
+
export { InvertlyContainer } from './container.factory';
|
|
21
|
+
export default createFromInvertly;
|
|
@@ -1,35 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
const
|
|
3
|
-
function createFromInvertly(options, container) {
|
|
4
|
-
return (container
|
|
5
|
-
}
|
|
6
|
-
export function invertly(token, container) {
|
|
7
|
-
return createFromInvertly({ token }, container);
|
|
8
|
-
}
|
|
9
|
-
export function registerInjectable(options, container) {
|
|
10
|
-
(container
|
|
11
|
-
}
|
|
12
|
-
export function registerInject(options, container) {
|
|
13
|
-
(container
|
|
14
|
-
}
|
|
15
|
-
export function registerDependency(token, options) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
export { Container } from './container.factory';
|
|
34
|
-
export default createFromInvertly;
|
|
1
|
+
import { InvertlyContainer } from './container.factory';
|
|
2
|
+
const INVERTLY_CONTAINER = new InvertlyContainer();
|
|
3
|
+
function createFromInvertly(options, container) {
|
|
4
|
+
return (container ?? INVERTLY_CONTAINER).createInjectable(options);
|
|
5
|
+
}
|
|
6
|
+
export function invertly(token, container) {
|
|
7
|
+
return createFromInvertly({ token }, container);
|
|
8
|
+
}
|
|
9
|
+
export function registerInjectable(options, container) {
|
|
10
|
+
(container ?? INVERTLY_CONTAINER).registerInjectable(options);
|
|
11
|
+
}
|
|
12
|
+
export function registerInject(options, container) {
|
|
13
|
+
(container ?? INVERTLY_CONTAINER).registerInject(options);
|
|
14
|
+
}
|
|
15
|
+
export function registerDependency(token, options) {
|
|
16
|
+
registerInjectable({
|
|
17
|
+
token,
|
|
18
|
+
scopeable: options.scopeable ?? false,
|
|
19
|
+
singleton: options.singleton ?? false
|
|
20
|
+
}, options.container);
|
|
21
|
+
options.injects?.forEach((inject, indexParent) => {
|
|
22
|
+
registerInject({
|
|
23
|
+
index: inject.index ?? indexParent,
|
|
24
|
+
parent: token,
|
|
25
|
+
scopeable: inject.scopeable ?? options.scopeable ?? false,
|
|
26
|
+
singleton: inject.singleton ?? options.singleton ?? false,
|
|
27
|
+
token: inject.token
|
|
28
|
+
}, options.container);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
export { InvertlyContainer } from './container.factory';
|
|
32
|
+
export default createFromInvertly;
|
|
35
33
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/factories/index.ts"],"names":[],"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,SAAS,EAAE,MAAM,CAAC,SAAS,IAAI,OAAO,CAAC,SAAS,IAAI,KAAK;YACzD,KAAK,EAAE,MAAM,CAAC,KAAK;SACpB,EACD,OAAO,CAAC,SAAS,CAClB,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAED,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,eAAe,kBAAkB,CAAC"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import createFromInvertly from './factories';
|
|
2
|
-
export { Factory, Injectable, Scope, Singleton } from './decorators';
|
|
3
|
-
export { Container, invertly, registerDependency, registerInject, registerInjectable } from './factories';
|
|
4
|
-
export { Context, requestInLocator, pushInLocator, saveInLocator } from './stores';
|
|
5
|
-
export { Constructable, InjectableToken, InjectToken, LocatorOptions } from './types';
|
|
6
|
-
export default createFromInvertly;
|
|
1
|
+
import createFromInvertly from './factories';
|
|
2
|
+
export { Factory, Injectable, Scope, Singleton } from './decorators';
|
|
3
|
+
export { InvertlyContainer as Container, invertly, registerDependency, registerInject, registerInjectable } from './factories';
|
|
4
|
+
export { Context, requestInLocator, pushInLocator, saveInLocator } from './stores';
|
|
5
|
+
export { Constructable, InjectableToken, InjectToken, LocatorOptions } from './types';
|
|
6
|
+
export default createFromInvertly;
|
package/dist/esm/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import createFromInvertly from './factories';
|
|
2
|
-
export { Factory, Injectable, Scope, Singleton } from './decorators';
|
|
3
|
-
export { Container, invertly, registerDependency, registerInject, registerInjectable } from './factories';
|
|
4
|
-
export { Context, requestInLocator, pushInLocator, saveInLocator } from './stores';
|
|
5
|
-
export default createFromInvertly;
|
|
1
|
+
import createFromInvertly from './factories';
|
|
2
|
+
export { Factory, Injectable, Scope, Singleton } from './decorators';
|
|
3
|
+
export { InvertlyContainer as Container, invertly, registerDependency, registerInject, registerInjectable } from './factories';
|
|
4
|
+
export { Context, requestInLocator, pushInLocator, saveInLocator } from './stores';
|
|
5
|
+
export default createFromInvertly;
|
|
6
6
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,MAAM,aAAa,CAAC;AAE7C,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACrE,OAAO,EACL,SAAS,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,MAAM,aAAa,CAAC;AAE7C,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACrE,OAAO,EACL,iBAAiB,IAAI,SAAS,EAC9B,QAAQ,EACR,kBAAkB,EAClB,cAAc,EACd,kBAAkB,EACnB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,OAAO,EACP,gBAAgB,EAChB,aAAa,EACb,aAAa,EACd,MAAM,UAAU,CAAC;AAQlB,eAAe,kBAAkB,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { AbstractContext } from '../types';
|
|
2
|
-
export declare class Context<K = string> implements AbstractContext<K> {
|
|
3
|
-
private store;
|
|
4
|
-
set(key: K, value?: any): void;
|
|
5
|
-
request<T = any>(key: K): Undefined<T>;
|
|
6
|
-
has(key: K): boolean;
|
|
7
|
-
}
|
|
1
|
+
import { AbstractContext } from '../types';
|
|
2
|
+
export declare class Context<K = string> implements AbstractContext<K> {
|
|
3
|
+
private store;
|
|
4
|
+
set(key: K, value?: any): void;
|
|
5
|
+
request<T = any>(key: K): Undefined<T>;
|
|
6
|
+
has(key: K): boolean;
|
|
7
|
+
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
export class Context {
|
|
2
|
-
constructor() {
|
|
3
|
-
this.store = new Map();
|
|
4
|
-
}
|
|
5
|
-
set(key, value) {
|
|
6
|
-
this.store.set(key, value);
|
|
7
|
-
}
|
|
8
|
-
request(key) {
|
|
9
|
-
return this.store.get(key);
|
|
10
|
-
}
|
|
11
|
-
has(key) {
|
|
12
|
-
return this.store.has(key);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
1
|
+
export class Context {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.store = new Map();
|
|
4
|
+
}
|
|
5
|
+
set(key, value) {
|
|
6
|
+
this.store.set(key, value);
|
|
7
|
+
}
|
|
8
|
+
request(key) {
|
|
9
|
+
return this.store.get(key);
|
|
10
|
+
}
|
|
11
|
+
has(key) {
|
|
12
|
+
return this.store.has(key);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
15
|
//# sourceMappingURL=context.store.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from './context.store';
|
|
2
|
-
export * from './inject.store';
|
|
3
|
-
export * from './injectable.store';
|
|
4
|
-
export * from './locator.store';
|
|
5
|
-
export * from './scope.store';
|
|
1
|
+
export * from './context.store';
|
|
2
|
+
export * from './inject.store';
|
|
3
|
+
export * from './injectable.store';
|
|
4
|
+
export * from './locator.store';
|
|
5
|
+
export * from './scope.store';
|
package/dist/esm/stores/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from './context.store';
|
|
2
|
-
export * from './inject.store';
|
|
3
|
-
export * from './injectable.store';
|
|
4
|
-
export * from './locator.store';
|
|
5
|
-
export * from './scope.store';
|
|
1
|
+
export * from './context.store';
|
|
2
|
+
export * from './inject.store';
|
|
3
|
+
export * from './injectable.store';
|
|
4
|
+
export * from './locator.store';
|
|
5
|
+
export * from './scope.store';
|
|
6
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { InjectableToken, InjectOptions } from '../types';
|
|
2
|
-
export declare class InjectStore {
|
|
3
|
-
private collection;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { InjectableToken, InjectOptions } from '../types';
|
|
2
|
+
export declare class InjectStore {
|
|
3
|
+
private collection;
|
|
4
|
+
constructor();
|
|
5
|
+
push(options: InjectOptions): void;
|
|
6
|
+
request(token: InjectableToken): InjectOptions[];
|
|
7
|
+
}
|
|
@@ -1,20 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const injects = this.request(parent);
|
|
8
|
-
injects[index] = options;
|
|
9
|
-
}
|
|
10
|
-
request(token) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
const injects = [];
|
|
16
|
-
this.collection.set(token, injects);
|
|
17
|
-
return injects;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
1
|
+
import { SecureMap } from '@rolster/commons';
|
|
2
|
+
export class InjectStore {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.collection = new SecureMap(() => []);
|
|
5
|
+
}
|
|
6
|
+
push(options) {
|
|
7
|
+
const injects = this.collection.request(options.parent);
|
|
8
|
+
injects[options.index] = options;
|
|
9
|
+
}
|
|
10
|
+
request(token) {
|
|
11
|
+
return this.collection.request(token);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
20
14
|
//# sourceMappingURL=inject.store.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inject.store.js","sourceRoot":"","sources":["../../../src/stores/inject.store.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"inject.store.js","sourceRoot":"","sources":["../../../src/stores/inject.store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAG7C,MAAM,OAAO,WAAW;IAGtB;QACE,IAAI,CAAC,UAAU,GAAG,IAAI,SAAS,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;IAC5C,CAAC;IAEM,IAAI,CAAC,OAAsB;QAChC,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAExD,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC;IACnC,CAAC;IAEM,OAAO,CAAC,KAAsB;QACnC,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACxC,CAAC;CACF"}
|