@spinajs/di 2.0.180 → 2.0.181
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/lib/cjs/array.d.ts +10 -10
- package/lib/cjs/array.js +13 -13
- package/lib/cjs/binder.d.ts +39 -39
- package/lib/cjs/binder.js +96 -96
- package/lib/cjs/container-cache.d.ts +17 -17
- package/lib/cjs/container-cache.js +63 -63
- package/lib/cjs/container.d.ts +133 -133
- package/lib/cjs/container.js +466 -466
- package/lib/cjs/container.js.map +1 -1
- package/lib/cjs/decorators.d.ts +141 -141
- package/lib/cjs/decorators.js +303 -303
- package/lib/cjs/enums.d.ts +31 -31
- package/lib/cjs/enums.js +35 -35
- package/lib/cjs/enums.js.map +1 -1
- package/lib/cjs/exceptions.d.ts +17 -17
- package/lib/cjs/exceptions.js +25 -25
- package/lib/cjs/helpers.d.ts +35 -35
- package/lib/cjs/helpers.js +86 -86
- package/lib/cjs/index.d.ts +12 -12
- package/lib/cjs/index.js +41 -41
- package/lib/cjs/interfaces.d.ts +172 -172
- package/lib/cjs/interfaces.js +53 -53
- package/lib/cjs/registry.d.ts +14 -14
- package/lib/cjs/registry.js +80 -80
- package/lib/cjs/root.d.ts +108 -108
- package/lib/cjs/root.js +216 -217
- package/lib/cjs/root.js.map +1 -1
- package/lib/cjs/types.d.ts +13 -13
- package/lib/cjs/types.js +2 -2
- package/lib/mjs/array.d.ts +10 -10
- package/lib/mjs/array.js +9 -9
- package/lib/mjs/binder.d.ts +39 -39
- package/lib/mjs/binder.js +92 -92
- package/lib/mjs/container-cache.d.ts +17 -17
- package/lib/mjs/container-cache.js +59 -59
- package/lib/mjs/container.d.ts +133 -133
- package/lib/mjs/container.js +459 -459
- package/lib/mjs/container.js.map +1 -1
- package/lib/mjs/decorators.d.ts +141 -141
- package/lib/mjs/decorators.js +266 -266
- package/lib/mjs/enums.d.ts +31 -31
- package/lib/mjs/enums.js +32 -32
- package/lib/mjs/enums.js.map +1 -1
- package/lib/mjs/exceptions.d.ts +17 -17
- package/lib/mjs/exceptions.js +19 -19
- package/lib/mjs/helpers.d.ts +35 -35
- package/lib/mjs/helpers.js +72 -72
- package/lib/mjs/index.d.ts +12 -12
- package/lib/mjs/index.js +12 -12
- package/lib/mjs/interfaces.d.ts +172 -172
- package/lib/mjs/interfaces.js +45 -45
- package/lib/mjs/registry.d.ts +14 -14
- package/lib/mjs/registry.js +76 -76
- package/lib/mjs/root.d.ts +108 -108
- package/lib/mjs/root.js +159 -159
- package/lib/mjs/types.d.ts +13 -13
- package/lib/mjs/types.js +1 -1
- package/lib/tsconfig.cjs.tsbuildinfo +1 -1
- package/lib/tsconfig.mjs.tsbuildinfo +1 -1
- package/package.json +2 -2
package/lib/cjs/array.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Class } from './types.js';
|
|
2
|
-
declare global {
|
|
3
|
-
interface ArrayConstructor {
|
|
4
|
-
ofType<T>(type: Class<T> | string): TypedArray<T>;
|
|
5
|
-
}
|
|
6
|
-
}
|
|
7
|
-
export declare class TypedArray<R> extends Array<R> {
|
|
8
|
-
Type: Class<R> | string;
|
|
9
|
-
constructor(Type: Class<R> | string);
|
|
10
|
-
}
|
|
1
|
+
import { Class } from './types.js';
|
|
2
|
+
declare global {
|
|
3
|
+
interface ArrayConstructor {
|
|
4
|
+
ofType<T>(type: Class<T> | string): TypedArray<T>;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export declare class TypedArray<R> extends Array<R> {
|
|
8
|
+
Type: Class<R> | string;
|
|
9
|
+
constructor(Type: Class<R> | string);
|
|
10
|
+
}
|
|
11
11
|
//# sourceMappingURL=array.d.ts.map
|
package/lib/cjs/array.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TypedArray = void 0;
|
|
4
|
-
class TypedArray extends Array {
|
|
5
|
-
constructor(Type) {
|
|
6
|
-
super();
|
|
7
|
-
this.Type = Type;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
exports.TypedArray = TypedArray;
|
|
11
|
-
Array.ofType = function (type) {
|
|
12
|
-
return new TypedArray(type);
|
|
13
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypedArray = void 0;
|
|
4
|
+
class TypedArray extends Array {
|
|
5
|
+
constructor(Type) {
|
|
6
|
+
super();
|
|
7
|
+
this.Type = Type;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.TypedArray = TypedArray;
|
|
11
|
+
Array.ofType = function (type) {
|
|
12
|
+
return new TypedArray(type);
|
|
13
|
+
};
|
|
14
14
|
//# sourceMappingURL=array.js.map
|
package/lib/cjs/binder.d.ts
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import { IBind, IContainer, ResolvableObject } from './interfaces.js';
|
|
2
|
-
import { Class, Factory } from './types.js';
|
|
3
|
-
export declare class Binder<T> implements IBind {
|
|
4
|
-
private implementation;
|
|
5
|
-
private container;
|
|
6
|
-
private isFactory;
|
|
7
|
-
private isConstructor;
|
|
8
|
-
constructor(implementation: Class<T> | Factory<T> | ResolvableObject, container: IContainer);
|
|
9
|
-
as<T>(type: string | Class<T>): this;
|
|
10
|
-
/**
|
|
11
|
-
* Add plain value to container. If value exists, it overrides content in container cache
|
|
12
|
-
*
|
|
13
|
-
* @param type - name of added value
|
|
14
|
-
* @param override - if true, any value registered before is overriden by new one
|
|
15
|
-
* @returns
|
|
16
|
-
*/
|
|
17
|
-
asValue(type: string, override?: boolean): this;
|
|
18
|
-
/**
|
|
19
|
-
*
|
|
20
|
-
* Add plain value to container, value is stored in hashmap for quick access
|
|
21
|
-
* eg. we have multiple value converters and we wanc o(1) access, instead searching for
|
|
22
|
-
* converter for specific type
|
|
23
|
-
*
|
|
24
|
-
* @param type - name of added value
|
|
25
|
-
* @param key - hashmap key
|
|
26
|
-
*/
|
|
27
|
-
asMapValue(type: string, key: string): this;
|
|
28
|
-
/**
|
|
29
|
-
* Register type as itself. Usefull when we also want to register type as self instead of base class
|
|
30
|
-
* so we can retrieve just this specific instance.
|
|
31
|
-
* @returns this
|
|
32
|
-
*/
|
|
33
|
-
asSelf(): this;
|
|
34
|
-
/**
|
|
35
|
-
* Mark type as SingleInstance resolve strategy.
|
|
36
|
-
* @returns this
|
|
37
|
-
*/
|
|
38
|
-
singleInstance(): this;
|
|
39
|
-
}
|
|
1
|
+
import { IBind, IContainer, ResolvableObject } from './interfaces.js';
|
|
2
|
+
import { Class, Factory } from './types.js';
|
|
3
|
+
export declare class Binder<T> implements IBind {
|
|
4
|
+
private implementation;
|
|
5
|
+
private container;
|
|
6
|
+
private isFactory;
|
|
7
|
+
private isConstructor;
|
|
8
|
+
constructor(implementation: Class<T> | Factory<T> | ResolvableObject, container: IContainer);
|
|
9
|
+
as<T>(type: string | Class<T>): this;
|
|
10
|
+
/**
|
|
11
|
+
* Add plain value to container. If value exists, it overrides content in container cache
|
|
12
|
+
*
|
|
13
|
+
* @param type - name of added value
|
|
14
|
+
* @param override - if true, any value registered before is overriden by new one
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
asValue(type: string, override?: boolean): this;
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* Add plain value to container, value is stored in hashmap for quick access
|
|
21
|
+
* eg. we have multiple value converters and we wanc o(1) access, instead searching for
|
|
22
|
+
* converter for specific type
|
|
23
|
+
*
|
|
24
|
+
* @param type - name of added value
|
|
25
|
+
* @param key - hashmap key
|
|
26
|
+
*/
|
|
27
|
+
asMapValue(type: string, key: string): this;
|
|
28
|
+
/**
|
|
29
|
+
* Register type as itself. Usefull when we also want to register type as self instead of base class
|
|
30
|
+
* so we can retrieve just this specific instance.
|
|
31
|
+
* @returns this
|
|
32
|
+
*/
|
|
33
|
+
asSelf(): this;
|
|
34
|
+
/**
|
|
35
|
+
* Mark type as SingleInstance resolve strategy.
|
|
36
|
+
* @returns this
|
|
37
|
+
*/
|
|
38
|
+
singleInstance(): this;
|
|
39
|
+
}
|
|
40
40
|
//# sourceMappingURL=binder.d.ts.map
|
package/lib/cjs/binder.js
CHANGED
|
@@ -1,97 +1,97 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Binder = void 0;
|
|
4
|
-
const exceptions_js_1 = require("./exceptions.js");
|
|
5
|
-
const enums_js_1 = require("./enums.js");
|
|
6
|
-
const helpers_js_1 = require("./helpers.js");
|
|
7
|
-
const index_js_1 = require("./index.js");
|
|
8
|
-
class Binder {
|
|
9
|
-
constructor(implementation, container) {
|
|
10
|
-
this.implementation = implementation;
|
|
11
|
-
this.container = container;
|
|
12
|
-
this.isFactory = (0, helpers_js_1.isFactory)(implementation);
|
|
13
|
-
this.isConstructor = (0, helpers_js_1.isConstructor)(implementation);
|
|
14
|
-
}
|
|
15
|
-
as(type) {
|
|
16
|
-
this.container.Registry.register(type, this.implementation);
|
|
17
|
-
const iType = (0, helpers_js_1.getTypeName)(this.implementation);
|
|
18
|
-
const tType = (0, helpers_js_1.getTypeName)(type);
|
|
19
|
-
this.container.emit(`di.registered.${iType}`, this.implementation);
|
|
20
|
-
this.container.emit(`di.registered.${tType}`, this.implementation);
|
|
21
|
-
return this;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Add plain value to container. If value exists, it overrides content in container cache
|
|
25
|
-
*
|
|
26
|
-
* @param type - name of added value
|
|
27
|
-
* @param override - if true, any value registered before is overriden by new one
|
|
28
|
-
* @returns
|
|
29
|
-
*/
|
|
30
|
-
asValue(type, override = false) {
|
|
31
|
-
if (override) {
|
|
32
|
-
if (this.container.Cache.has(type)) {
|
|
33
|
-
this.container.Cache.remove(type);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
this.container.Cache.add(type, this.implementation);
|
|
37
|
-
const tType = (0, helpers_js_1.getTypeName)(type);
|
|
38
|
-
this.container.emit(`di.registered.${tType}`, this.implementation);
|
|
39
|
-
return this;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
*
|
|
43
|
-
* Add plain value to container, value is stored in hashmap for quick access
|
|
44
|
-
* eg. we have multiple value converters and we wanc o(1) access, instead searching for
|
|
45
|
-
* converter for specific type
|
|
46
|
-
*
|
|
47
|
-
* @param type - name of added value
|
|
48
|
-
* @param key - hashmap key
|
|
49
|
-
*/
|
|
50
|
-
asMapValue(type, key) {
|
|
51
|
-
let map = null;
|
|
52
|
-
if (this.container.Cache.has(type)) {
|
|
53
|
-
map = this.container.Cache.get(type)[0];
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
map = new Map();
|
|
57
|
-
this.container.Cache.add(type, map);
|
|
58
|
-
}
|
|
59
|
-
map.set(key, this.implementation);
|
|
60
|
-
const iType = (0, helpers_js_1.getTypeName)(this.implementation);
|
|
61
|
-
const tType = (0, helpers_js_1.getTypeName)(type);
|
|
62
|
-
this.container.emit(`di.registered.${iType}`, this.implementation);
|
|
63
|
-
this.container.emit(`di.registered.${tType}`, this.implementation);
|
|
64
|
-
return this;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Register type as itself. Usefull when we also want to register type as self instead of base class
|
|
68
|
-
* so we can retrieve just this specific instance.
|
|
69
|
-
* @returns this
|
|
70
|
-
*/
|
|
71
|
-
asSelf() {
|
|
72
|
-
if (!this.isConstructor || this.isFactory) {
|
|
73
|
-
throw new exceptions_js_1.BindException('cannot register as self non class');
|
|
74
|
-
}
|
|
75
|
-
// we can safly cast to any, we checked params earlier
|
|
76
|
-
this.container.Registry.register(this.implementation, this.implementation);
|
|
77
|
-
const iType = (0, helpers_js_1.getTypeName)(this.implementation);
|
|
78
|
-
this.container.emit(`di.registered.${iType}`, this.implementation);
|
|
79
|
-
return this;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Mark type as SingleInstance resolve strategy.
|
|
83
|
-
* @returns this
|
|
84
|
-
*/
|
|
85
|
-
singleInstance() {
|
|
86
|
-
if (this.isFactory || !this.isConstructor) {
|
|
87
|
-
throw new exceptions_js_1.BindException('Cannot bind factory function as singleton.');
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
const descriptor = index_js_1.DI.RootContainer.extractDescriptor(this.implementation);
|
|
91
|
-
descriptor.resolver = enums_js_1.ResolveType.Singleton;
|
|
92
|
-
}
|
|
93
|
-
return this;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
exports.Binder = Binder;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Binder = void 0;
|
|
4
|
+
const exceptions_js_1 = require("./exceptions.js");
|
|
5
|
+
const enums_js_1 = require("./enums.js");
|
|
6
|
+
const helpers_js_1 = require("./helpers.js");
|
|
7
|
+
const index_js_1 = require("./index.js");
|
|
8
|
+
class Binder {
|
|
9
|
+
constructor(implementation, container) {
|
|
10
|
+
this.implementation = implementation;
|
|
11
|
+
this.container = container;
|
|
12
|
+
this.isFactory = (0, helpers_js_1.isFactory)(implementation);
|
|
13
|
+
this.isConstructor = (0, helpers_js_1.isConstructor)(implementation);
|
|
14
|
+
}
|
|
15
|
+
as(type) {
|
|
16
|
+
this.container.Registry.register(type, this.implementation);
|
|
17
|
+
const iType = (0, helpers_js_1.getTypeName)(this.implementation);
|
|
18
|
+
const tType = (0, helpers_js_1.getTypeName)(type);
|
|
19
|
+
this.container.emit(`di.registered.${iType}`, this.implementation);
|
|
20
|
+
this.container.emit(`di.registered.${tType}`, this.implementation);
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Add plain value to container. If value exists, it overrides content in container cache
|
|
25
|
+
*
|
|
26
|
+
* @param type - name of added value
|
|
27
|
+
* @param override - if true, any value registered before is overriden by new one
|
|
28
|
+
* @returns
|
|
29
|
+
*/
|
|
30
|
+
asValue(type, override = false) {
|
|
31
|
+
if (override) {
|
|
32
|
+
if (this.container.Cache.has(type)) {
|
|
33
|
+
this.container.Cache.remove(type);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
this.container.Cache.add(type, this.implementation);
|
|
37
|
+
const tType = (0, helpers_js_1.getTypeName)(type);
|
|
38
|
+
this.container.emit(`di.registered.${tType}`, this.implementation);
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
*
|
|
43
|
+
* Add plain value to container, value is stored in hashmap for quick access
|
|
44
|
+
* eg. we have multiple value converters and we wanc o(1) access, instead searching for
|
|
45
|
+
* converter for specific type
|
|
46
|
+
*
|
|
47
|
+
* @param type - name of added value
|
|
48
|
+
* @param key - hashmap key
|
|
49
|
+
*/
|
|
50
|
+
asMapValue(type, key) {
|
|
51
|
+
let map = null;
|
|
52
|
+
if (this.container.Cache.has(type)) {
|
|
53
|
+
map = this.container.Cache.get(type)[0];
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
map = new Map();
|
|
57
|
+
this.container.Cache.add(type, map);
|
|
58
|
+
}
|
|
59
|
+
map.set(key, this.implementation);
|
|
60
|
+
const iType = (0, helpers_js_1.getTypeName)(this.implementation);
|
|
61
|
+
const tType = (0, helpers_js_1.getTypeName)(type);
|
|
62
|
+
this.container.emit(`di.registered.${iType}`, this.implementation);
|
|
63
|
+
this.container.emit(`di.registered.${tType}`, this.implementation);
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Register type as itself. Usefull when we also want to register type as self instead of base class
|
|
68
|
+
* so we can retrieve just this specific instance.
|
|
69
|
+
* @returns this
|
|
70
|
+
*/
|
|
71
|
+
asSelf() {
|
|
72
|
+
if (!this.isConstructor || this.isFactory) {
|
|
73
|
+
throw new exceptions_js_1.BindException('cannot register as self non class');
|
|
74
|
+
}
|
|
75
|
+
// we can safly cast to any, we checked params earlier
|
|
76
|
+
this.container.Registry.register(this.implementation, this.implementation);
|
|
77
|
+
const iType = (0, helpers_js_1.getTypeName)(this.implementation);
|
|
78
|
+
this.container.emit(`di.registered.${iType}`, this.implementation);
|
|
79
|
+
return this;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Mark type as SingleInstance resolve strategy.
|
|
83
|
+
* @returns this
|
|
84
|
+
*/
|
|
85
|
+
singleInstance() {
|
|
86
|
+
if (this.isFactory || !this.isConstructor) {
|
|
87
|
+
throw new exceptions_js_1.BindException('Cannot bind factory function as singleton.');
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
const descriptor = index_js_1.DI.RootContainer.extractDescriptor(this.implementation);
|
|
91
|
+
descriptor.resolver = enums_js_1.ResolveType.Singleton;
|
|
92
|
+
}
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.Binder = Binder;
|
|
97
97
|
//# sourceMappingURL=binder.js.map
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { TypedArray } from './array.js';
|
|
2
|
-
import { IContainer } from './interfaces.js';
|
|
3
|
-
import { Class } from './types.js';
|
|
4
|
-
export declare class ContainerCache {
|
|
5
|
-
private container;
|
|
6
|
-
private cache;
|
|
7
|
-
constructor(container: IContainer);
|
|
8
|
-
[Symbol.iterator](): Generator<{
|
|
9
|
-
key: string;
|
|
10
|
-
value: any;
|
|
11
|
-
}, void, unknown>;
|
|
12
|
-
remove(key: string | Class<any> | TypedArray<any>, parent?: boolean): void;
|
|
13
|
-
add(key: string | Class<any> | object, instance: any): void;
|
|
14
|
-
has(key: string | Class<any> | object | TypedArray<any>, parent?: boolean): boolean;
|
|
15
|
-
get(key: string | Class<any> | TypedArray<any>, parent?: boolean): any;
|
|
16
|
-
clear(): void;
|
|
17
|
-
}
|
|
1
|
+
import { TypedArray } from './array.js';
|
|
2
|
+
import { IContainer } from './interfaces.js';
|
|
3
|
+
import { Class } from './types.js';
|
|
4
|
+
export declare class ContainerCache {
|
|
5
|
+
private container;
|
|
6
|
+
private cache;
|
|
7
|
+
constructor(container: IContainer);
|
|
8
|
+
[Symbol.iterator](): Generator<{
|
|
9
|
+
key: string;
|
|
10
|
+
value: any;
|
|
11
|
+
}, void, unknown>;
|
|
12
|
+
remove(key: string | Class<any> | TypedArray<any>, parent?: boolean): void;
|
|
13
|
+
add(key: string | Class<any> | object, instance: any): void;
|
|
14
|
+
has(key: string | Class<any> | object | TypedArray<any>, parent?: boolean): boolean;
|
|
15
|
+
get(key: string | Class<any> | TypedArray<any>, parent?: boolean): any;
|
|
16
|
+
clear(): void;
|
|
17
|
+
}
|
|
18
18
|
//# sourceMappingURL=container-cache.d.ts.map
|
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ContainerCache = void 0;
|
|
4
|
-
const helpers_js_1 = require("./helpers.js");
|
|
5
|
-
class ContainerCache {
|
|
6
|
-
constructor(container) {
|
|
7
|
-
this.container = container;
|
|
8
|
-
this.cache = new Map();
|
|
9
|
-
// add to cache container
|
|
10
|
-
// so we can inject container if needed
|
|
11
|
-
this.add(container, container);
|
|
12
|
-
}
|
|
13
|
-
*[Symbol.iterator]() {
|
|
14
|
-
for (const [key, value] of this.cache) {
|
|
15
|
-
for (const v of value) {
|
|
16
|
-
yield { key, value: v };
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
remove(key, parent) {
|
|
21
|
-
if (this.has(key)) {
|
|
22
|
-
this.cache.delete((0, helpers_js_1.getTypeName)(key));
|
|
23
|
-
}
|
|
24
|
-
else if (parent && this.container.Parent) {
|
|
25
|
-
this.container.Parent.uncache(key);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
add(key, instance) {
|
|
29
|
-
const tName = (0, helpers_js_1.getTypeName)(key);
|
|
30
|
-
if (this.has(key)) {
|
|
31
|
-
if (this.cache.get(tName).indexOf(instance) === -1) {
|
|
32
|
-
this.cache.get(tName).push(instance);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
this.cache.set(tName, [instance]);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
has(key, parent) {
|
|
40
|
-
if (this.cache.has((0, helpers_js_1.getTypeName)(key))) {
|
|
41
|
-
return true;
|
|
42
|
-
}
|
|
43
|
-
if (parent && this.container.Parent) {
|
|
44
|
-
return this.container.Parent.Cache.has(key, parent);
|
|
45
|
-
}
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
get(key, parent) {
|
|
49
|
-
const tName = (0, helpers_js_1.getTypeName)(key);
|
|
50
|
-
if (this.cache.has(tName)) {
|
|
51
|
-
return this.cache.get(tName);
|
|
52
|
-
}
|
|
53
|
-
if (parent && this.container.Parent) {
|
|
54
|
-
return this.container.Parent.Cache.get(key, parent);
|
|
55
|
-
}
|
|
56
|
-
return [];
|
|
57
|
-
}
|
|
58
|
-
clear() {
|
|
59
|
-
this.cache.clear();
|
|
60
|
-
this.add(this.container, this.container);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
exports.ContainerCache = ContainerCache;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ContainerCache = void 0;
|
|
4
|
+
const helpers_js_1 = require("./helpers.js");
|
|
5
|
+
class ContainerCache {
|
|
6
|
+
constructor(container) {
|
|
7
|
+
this.container = container;
|
|
8
|
+
this.cache = new Map();
|
|
9
|
+
// add to cache container
|
|
10
|
+
// so we can inject container if needed
|
|
11
|
+
this.add(container, container);
|
|
12
|
+
}
|
|
13
|
+
*[Symbol.iterator]() {
|
|
14
|
+
for (const [key, value] of this.cache) {
|
|
15
|
+
for (const v of value) {
|
|
16
|
+
yield { key, value: v };
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
remove(key, parent) {
|
|
21
|
+
if (this.has(key)) {
|
|
22
|
+
this.cache.delete((0, helpers_js_1.getTypeName)(key));
|
|
23
|
+
}
|
|
24
|
+
else if (parent && this.container.Parent) {
|
|
25
|
+
this.container.Parent.uncache(key);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
add(key, instance) {
|
|
29
|
+
const tName = (0, helpers_js_1.getTypeName)(key);
|
|
30
|
+
if (this.has(key)) {
|
|
31
|
+
if (this.cache.get(tName).indexOf(instance) === -1) {
|
|
32
|
+
this.cache.get(tName).push(instance);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
this.cache.set(tName, [instance]);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
has(key, parent) {
|
|
40
|
+
if (this.cache.has((0, helpers_js_1.getTypeName)(key))) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
if (parent && this.container.Parent) {
|
|
44
|
+
return this.container.Parent.Cache.has(key, parent);
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
get(key, parent) {
|
|
49
|
+
const tName = (0, helpers_js_1.getTypeName)(key);
|
|
50
|
+
if (this.cache.has(tName)) {
|
|
51
|
+
return this.cache.get(tName);
|
|
52
|
+
}
|
|
53
|
+
if (parent && this.container.Parent) {
|
|
54
|
+
return this.container.Parent.Cache.get(key, parent);
|
|
55
|
+
}
|
|
56
|
+
return [];
|
|
57
|
+
}
|
|
58
|
+
clear() {
|
|
59
|
+
this.cache.clear();
|
|
60
|
+
this.add(this.container, this.container);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.ContainerCache = ContainerCache;
|
|
64
64
|
//# sourceMappingURL=container-cache.js.map
|