mesh-ioc 2.2.3 → 3.1.3
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 +6 -2
- package/out/main/decorators/dep.d.ts +2 -1
- package/out/main/decorators/dep.js +22 -17
- package/out/main/decorators/dep.js.map +1 -0
- package/out/main/errors.js +5 -11
- package/out/main/errors.js.map +1 -0
- package/out/main/index.d.ts +4 -4
- package/out/main/index.js +5 -16
- package/out/main/index.js.map +1 -0
- package/out/main/mesh.d.ts +1 -1
- package/out/main/mesh.js +14 -17
- package/out/main/mesh.js.map +1 -0
- package/out/main/types.d.ts +9 -9
- package/out/main/types.js +2 -2
- package/out/main/types.js.map +1 -0
- package/out/main/util.d.ts +1 -1
- package/out/main/util.js +2 -5
- package/out/main/util.js.map +1 -0
- package/package.json +11 -6
- package/out/main/handlers.d.ts +0 -6
- package/out/main/handlers.js +0 -55
- package/out/main/reflect.d.ts +0 -6
- package/out/main/reflect.js +0 -55
package/README.md
CHANGED
|
@@ -6,12 +6,16 @@ Mesh IoC solves the problem of dependency management of application services. It
|
|
|
6
6
|
|
|
7
7
|
## Key features
|
|
8
8
|
|
|
9
|
+
- 🔥 Zero dependencies
|
|
9
10
|
- 👗 Very slim — about 2KB minified, few hundred bytes gzipped
|
|
11
|
+
- 💻 Works in browser
|
|
12
|
+
- 🌳 Ergonomic
|
|
13
|
+
- 🗜 Tidy and compact
|
|
14
|
+
- 🔬 Strongly typed and introspectable
|
|
10
15
|
- ⚡️ Blazing fast
|
|
11
16
|
- 🧩 Flexible and composable
|
|
12
|
-
- 🌿 Ergonomic
|
|
13
|
-
- 🐓 🥚 Tolerates circular dependencies
|
|
14
17
|
- 🕵️♀️ Provides APIs for dependency analysis
|
|
18
|
+
- 🐓 🥚 Tolerates circular dependencies
|
|
15
19
|
|
|
16
20
|
## API Cheatsheet
|
|
17
21
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
-
import { DepMetadata } from '../types';
|
|
2
|
+
import { DepMetadata } from '../types.js';
|
|
3
3
|
export declare const depMetadata: DepMetadata[];
|
|
4
4
|
export interface DepOptions {
|
|
5
5
|
key?: string;
|
|
6
|
+
cache?: boolean;
|
|
6
7
|
}
|
|
7
8
|
export declare function dep(options?: DepOptions): (target: any, propertyName: string) => void;
|
|
@@ -1,34 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const mesh_1 = require("../mesh");
|
|
7
|
-
exports.depMetadata = [];
|
|
8
|
-
function dep(options = {}) {
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import { DepInstanceNotConnected, DepKeyNotInferred } from '../errors.js';
|
|
3
|
+
import { MESH_REF } from '../mesh.js';
|
|
4
|
+
export const depMetadata = [];
|
|
5
|
+
export function dep(options = {}) {
|
|
9
6
|
return function (target, propertyName) {
|
|
10
|
-
var _a;
|
|
11
7
|
const className = target.constructor.name;
|
|
12
8
|
const designType = Reflect.getMetadata('design:type', target, propertyName);
|
|
13
|
-
const key =
|
|
9
|
+
const key = options.key ?? designType?.name;
|
|
10
|
+
const cache = options.cache ?? true;
|
|
14
11
|
if (!key) {
|
|
15
|
-
throw new
|
|
12
|
+
throw new DepKeyNotInferred(className, propertyName);
|
|
16
13
|
}
|
|
17
|
-
|
|
14
|
+
depMetadata.push({
|
|
18
15
|
class: target.constructor,
|
|
19
16
|
propertyName,
|
|
20
17
|
designTypeName: designType.name,
|
|
21
18
|
key,
|
|
22
19
|
});
|
|
23
20
|
Object.defineProperty(target, propertyName, {
|
|
21
|
+
configurable: true,
|
|
24
22
|
get() {
|
|
25
|
-
const mesh = this[
|
|
23
|
+
const mesh = this[MESH_REF];
|
|
26
24
|
if (!mesh) {
|
|
27
|
-
throw new
|
|
25
|
+
throw new DepInstanceNotConnected(className, propertyName);
|
|
28
26
|
}
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
const value = mesh.resolve(key);
|
|
28
|
+
if (cache) {
|
|
29
|
+
Object.defineProperty(this, propertyName, {
|
|
30
|
+
configurable: true,
|
|
31
|
+
value
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return value;
|
|
35
|
+
},
|
|
31
36
|
});
|
|
32
37
|
};
|
|
33
38
|
}
|
|
34
|
-
|
|
39
|
+
//# sourceMappingURL=dep.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dep.js","sourceRoot":"","sources":["../../../src/main/decorators/dep.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAE1B,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAC1E,OAAO,EAAQ,QAAQ,EAAE,MAAM,YAAY,CAAC;AAG5C,MAAM,CAAC,MAAM,WAAW,GAAkB,EAAE,CAAC;AAO7C,MAAM,UAAU,GAAG,CAAC,UAAsB,EAAE;IACxC,OAAO,UAAU,MAAW,EAAE,YAAoB;QAC9C,MAAM,SAAS,GAAG,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC;QAC1C,MAAM,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC,aAAa,EAAE,MAAM,EAAE,YAAY,CAAa,CAAC;QACxF,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,UAAU,EAAE,IAAI,CAAC;QAC5C,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,IAAI,CAAC;QACpC,IAAI,CAAC,GAAG,EAAE;YACN,MAAM,IAAI,iBAAiB,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;SACxD;QACD,WAAW,CAAC,IAAI,CAAC;YACb,KAAK,EAAE,MAAM,CAAC,WAAW;YACzB,YAAY;YACZ,cAAc,EAAE,UAAU,CAAC,IAAI;YAC/B,GAAG;SACN,CAAC,CAAC;QACH,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,YAAY,EAAE;YACxC,YAAY,EAAE,IAAI;YAClB,GAAG;gBACC,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAS,CAAC;gBACpC,IAAI,CAAC,IAAI,EAAE;oBACP,MAAM,IAAI,uBAAuB,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;iBAC9D;gBACD,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;gBAChC,IAAI,KAAK,EAAE;oBACP,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,YAAY,EAAE;wBACtC,YAAY,EAAE,IAAI;wBAClB,KAAK;qBACR,CAAC,CAAC;iBACN;gBACD,OAAO,KAAK,CAAC;YACjB,CAAC;SACJ,CAAC,CAAC;IACP,CAAC,CAAC;AACN,CAAC"}
|
package/out/main/errors.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MeshInvalidBinding = exports.MeshBindingNotFound = exports.DepInstanceNotConnected = exports.DepKeyNotInferred = void 0;
|
|
4
1
|
class BaseError extends Error {
|
|
5
2
|
constructor() {
|
|
6
3
|
super(...arguments);
|
|
7
4
|
this.name = this.constructor.name;
|
|
8
5
|
}
|
|
9
6
|
}
|
|
10
|
-
class DepKeyNotInferred extends BaseError {
|
|
7
|
+
export class DepKeyNotInferred extends BaseError {
|
|
11
8
|
constructor(className, propertyName) {
|
|
12
9
|
super(`${className}.${propertyName}: ` +
|
|
13
10
|
`@dep cannot infer the binding key (possibly due to circular dependency); ` +
|
|
@@ -16,8 +13,7 @@ class DepKeyNotInferred extends BaseError {
|
|
|
16
13
|
this.propertyName = propertyName;
|
|
17
14
|
}
|
|
18
15
|
}
|
|
19
|
-
|
|
20
|
-
class DepInstanceNotConnected extends BaseError {
|
|
16
|
+
export class DepInstanceNotConnected extends BaseError {
|
|
21
17
|
constructor(className, propertyName) {
|
|
22
18
|
super(`${className}.${propertyName}: ` +
|
|
23
19
|
`Cannot access @dep(): instance is not connected to Mesh`);
|
|
@@ -25,14 +21,12 @@ class DepInstanceNotConnected extends BaseError {
|
|
|
25
21
|
this.propertyName = propertyName;
|
|
26
22
|
}
|
|
27
23
|
}
|
|
28
|
-
|
|
29
|
-
class MeshBindingNotFound extends BaseError {
|
|
24
|
+
export class MeshBindingNotFound extends BaseError {
|
|
30
25
|
constructor(meshName, serviceKey) {
|
|
31
26
|
super(`"${serviceKey}" not found in Mesh "${meshName}"`);
|
|
32
27
|
}
|
|
33
28
|
}
|
|
34
|
-
|
|
35
|
-
class MeshInvalidBinding extends BaseError {
|
|
29
|
+
export class MeshInvalidBinding extends BaseError {
|
|
36
30
|
constructor(key) {
|
|
37
31
|
super(`Invalid binding "${key}". Valid bindings are: ` +
|
|
38
32
|
`string to constructor e.g. ("MyService", MyService) or ` +
|
|
@@ -40,4 +34,4 @@ class MeshInvalidBinding extends BaseError {
|
|
|
40
34
|
`constructor to self e.g. (MyService)`);
|
|
41
35
|
}
|
|
42
36
|
}
|
|
43
|
-
|
|
37
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/main/errors.ts"],"names":[],"mappings":"AAAA,MAAM,SAAU,SAAQ,KAAK;IAA7B;;QACa,SAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;IAC1C,CAAC;CAAA;AAED,MAAM,OAAO,iBAAkB,SAAQ,SAAS;IAC5C,YAAmB,SAAiB,EAAS,YAAoB;QAC7D,KAAK,CAAC,GAAG,SAAS,IAAI,YAAY,IAAI;YAClC,2EAA2E;YAC3E,yCAAyC,CAAC,CAAC;QAHhC,cAAS,GAAT,SAAS,CAAQ;QAAS,iBAAY,GAAZ,YAAY,CAAQ;IAIjE,CAAC;CACJ;AAED,MAAM,OAAO,uBAAwB,SAAQ,SAAS;IAClD,YAAmB,SAAiB,EAAS,YAAoB;QAC7D,KAAK,CAAC,GAAG,SAAS,IAAI,YAAY,IAAI;YAClC,yDAAyD,CAAC,CAAC;QAFhD,cAAS,GAAT,SAAS,CAAQ;QAAS,iBAAY,GAAZ,YAAY,CAAQ;IAGjE,CAAC;CACJ;AAED,MAAM,OAAO,mBAAoB,SAAQ,SAAS;IAC9C,YAAY,QAAgB,EAAE,UAAkB;QAC5C,KAAK,CAAC,IAAI,UAAU,wBAAwB,QAAQ,GAAG,CAAC,CAAC;IAC7D,CAAC;CACJ;AAED,MAAM,OAAO,kBAAmB,SAAQ,SAAS;IAC7C,YAAY,GAAW;QACnB,KAAK,CAAC,oBAAoB,GAAG,yBAAyB;YAClD,yDAAyD;YACzD,kEAAkE;YAClE,sCAAsC,CAAC,CAAC;IAChD,CAAC;CACJ"}
|
package/out/main/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './decorators/dep';
|
|
2
|
-
export * from './errors';
|
|
3
|
-
export * from './mesh';
|
|
4
|
-
export * from './types';
|
|
1
|
+
export * from './decorators/dep.js';
|
|
2
|
+
export * from './errors.js';
|
|
3
|
+
export * from './mesh.js';
|
|
4
|
+
export * from './types.js';
|
package/out/main/index.js
CHANGED
|
@@ -1,16 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
__exportStar(require("./decorators/dep"), exports);
|
|
14
|
-
__exportStar(require("./errors"), exports);
|
|
15
|
-
__exportStar(require("./mesh"), exports);
|
|
16
|
-
__exportStar(require("./types"), exports);
|
|
1
|
+
export * from './decorators/dep.js';
|
|
2
|
+
export * from './errors.js';
|
|
3
|
+
export * from './mesh.js';
|
|
4
|
+
export * from './types.js';
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/main/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC"}
|
package/out/main/mesh.d.ts
CHANGED
package/out/main/mesh.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const errors_1 = require("./errors");
|
|
5
|
-
const util_1 = require("./util");
|
|
6
|
-
exports.MESH_REF = Symbol.for('MESH_REF');
|
|
1
|
+
import { MeshBindingNotFound, MeshInvalidBinding } from './errors.js';
|
|
2
|
+
import { keyToString } from './util.js';
|
|
3
|
+
export const MESH_REF = Symbol.for('MESH_REF');
|
|
7
4
|
/**
|
|
8
5
|
* An IoC container.
|
|
9
6
|
*
|
|
@@ -15,7 +12,7 @@ exports.MESH_REF = Symbol.for('MESH_REF');
|
|
|
15
12
|
* - `constant` — an instance of a class (can be bound by using class as service name) or an arbitrary value bound by a string key
|
|
16
13
|
* - `alias` — a "redirect" mapping, useful in tests
|
|
17
14
|
*/
|
|
18
|
-
class Mesh {
|
|
15
|
+
export class Mesh {
|
|
19
16
|
constructor(name = 'default', parent = undefined) {
|
|
20
17
|
this.name = name;
|
|
21
18
|
this.parent = parent;
|
|
@@ -34,7 +31,7 @@ class Mesh {
|
|
|
34
31
|
return clone;
|
|
35
32
|
}
|
|
36
33
|
service(key, impl) {
|
|
37
|
-
const k =
|
|
34
|
+
const k = keyToString(key);
|
|
38
35
|
if (typeof impl === 'function') {
|
|
39
36
|
this.bindings.set(k, { type: 'service', class: impl });
|
|
40
37
|
return this;
|
|
@@ -43,29 +40,29 @@ class Mesh {
|
|
|
43
40
|
this.bindings.set(k, { type: 'service', class: key });
|
|
44
41
|
return this;
|
|
45
42
|
}
|
|
46
|
-
throw new
|
|
43
|
+
throw new MeshInvalidBinding(String(key));
|
|
47
44
|
}
|
|
48
45
|
constant(key, value) {
|
|
49
|
-
const k =
|
|
46
|
+
const k = keyToString(key);
|
|
50
47
|
this.bindings.set(k, { type: 'constant', value });
|
|
51
48
|
return this;
|
|
52
49
|
}
|
|
53
50
|
alias(key, referenceKey) {
|
|
54
|
-
const k =
|
|
55
|
-
const refK =
|
|
51
|
+
const k = keyToString(key);
|
|
52
|
+
const refK = keyToString(referenceKey);
|
|
56
53
|
this.bindings.set(k, { type: 'alias', key: refK });
|
|
57
54
|
return this;
|
|
58
55
|
}
|
|
59
56
|
resolve(key, recursive = true) {
|
|
60
57
|
const instance = this.tryResolve(key, recursive);
|
|
61
58
|
if (instance === undefined) {
|
|
62
|
-
const k =
|
|
63
|
-
throw new
|
|
59
|
+
const k = keyToString(key);
|
|
60
|
+
throw new MeshBindingNotFound(this.name, k);
|
|
64
61
|
}
|
|
65
62
|
return instance;
|
|
66
63
|
}
|
|
67
64
|
tryResolve(key, recursive = true) {
|
|
68
|
-
const k =
|
|
65
|
+
const k = keyToString(key);
|
|
69
66
|
let instance = this.instances.get(k);
|
|
70
67
|
if (instance) {
|
|
71
68
|
return instance;
|
|
@@ -123,11 +120,11 @@ class Mesh {
|
|
|
123
120
|
if (typeof value !== 'object') {
|
|
124
121
|
return;
|
|
125
122
|
}
|
|
126
|
-
Object.defineProperty(value,
|
|
123
|
+
Object.defineProperty(value, MESH_REF, {
|
|
127
124
|
get: () => this,
|
|
128
125
|
enumerable: false,
|
|
129
126
|
configurable: true,
|
|
130
127
|
});
|
|
131
128
|
}
|
|
132
129
|
}
|
|
133
|
-
|
|
130
|
+
//# sourceMappingURL=mesh.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mesh.js","sourceRoot":"","sources":["../../src/main/mesh.ts"],"names":[],"mappings":"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AAC,OAAO,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;gBAC7D,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;gBAClC,OAAO,IAAI,OAAO,EAAE,CAAC;aACxB;YACD,KAAK,UAAU;gBACX,OAAO,OAAO,CAAC,KAAK,CAAC;SAC5B;IACL,CAAC;IAES,eAAe,CAAI,KAAQ;QACjC,IAAI,GAAG,GAAG,KAAK,CAAC;QAChB,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,WAAW,EAAE;YACvC,GAAG,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;SACzB;QACD,IAAI,IAAI,CAAC,MAAM,EAAE;YACb,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;SAC1C;QACD,OAAO,GAAG,CAAC;IACf,CAAC;IAES,SAAS,CAAC,KAAU;QAC1B,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC3B,OAAO;SACV;QACD,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,QAAQ,EAAE;YACnC,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI;YACf,UAAU,EAAE,KAAK;YACjB,YAAY,EAAE,IAAI;SACrB,CAAC,CAAC;IACP,CAAC;CAEJ"}
|
package/out/main/types.d.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type Constructor<T> = {
|
|
2
2
|
new (...args: any[]): T;
|
|
3
3
|
};
|
|
4
|
-
export
|
|
4
|
+
export type ServiceConstructor<T> = {
|
|
5
5
|
new (): T;
|
|
6
6
|
};
|
|
7
|
-
export
|
|
7
|
+
export type AbstractClass<T> = {
|
|
8
8
|
name: string;
|
|
9
9
|
prototype: T;
|
|
10
10
|
};
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export
|
|
14
|
-
export
|
|
11
|
+
export type ServiceKey<T> = ServiceConstructor<T> | AbstractClass<T> | string;
|
|
12
|
+
export type Middleware = (instance: any) => any;
|
|
13
|
+
export type Binding<T> = ConstantBinding<T> | ServiceBinding<T> | AliasBinding;
|
|
14
|
+
export type ConstantBinding<T> = {
|
|
15
15
|
type: 'constant';
|
|
16
16
|
value: T;
|
|
17
17
|
};
|
|
18
|
-
export
|
|
18
|
+
export type ServiceBinding<T> = {
|
|
19
19
|
type: 'service';
|
|
20
20
|
class: ServiceConstructor<T>;
|
|
21
21
|
};
|
|
22
|
-
export
|
|
22
|
+
export type AliasBinding = {
|
|
23
23
|
type: 'alias';
|
|
24
24
|
key: string;
|
|
25
25
|
};
|
package/out/main/types.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export {};
|
|
2
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/main/types.ts"],"names":[],"mappings":""}
|
package/out/main/util.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ServiceKey } from './types';
|
|
1
|
+
import { ServiceKey } from './types.js';
|
|
2
2
|
export declare function keyToString<T>(key: ServiceKey<T>): string;
|
package/out/main/util.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.keyToString = void 0;
|
|
4
|
-
function keyToString(key) {
|
|
1
|
+
export function keyToString(key) {
|
|
5
2
|
return typeof key === 'string' ? key : key.name;
|
|
6
3
|
}
|
|
7
|
-
|
|
4
|
+
//# sourceMappingURL=util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/main/util.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,WAAW,CAAI,GAAkB;IAC7C,OAAO,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC;AACpD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mesh-ioc",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "3.1.3",
|
|
4
|
+
"description": "Powerful and Lightweight IoC Library",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./out/main/index.js"
|
|
9
|
+
},
|
|
5
10
|
"main": "out/main/index.js",
|
|
6
11
|
"types": "out/main/index.d.ts",
|
|
7
12
|
"files": [
|
|
@@ -9,7 +14,7 @@
|
|
|
9
14
|
],
|
|
10
15
|
"scripts": {
|
|
11
16
|
"clean": "rm -rf out *.tsbuildinfo",
|
|
12
|
-
"dev": "tsc -b -w",
|
|
17
|
+
"dev": "npm run clean && tsc -b -w",
|
|
13
18
|
"compile": "tsc -b",
|
|
14
19
|
"lint": "eslint --ext=.js,.ts,.vue --cache .",
|
|
15
20
|
"test": "NODE_ENV=test mocha",
|
|
@@ -22,7 +27,7 @@
|
|
|
22
27
|
],
|
|
23
28
|
"repository": {
|
|
24
29
|
"type": "git",
|
|
25
|
-
"url": "git+ssh://git@github.com/
|
|
30
|
+
"url": "git+ssh://git@github.com/MeshIoc/mesh-ioc.git"
|
|
26
31
|
},
|
|
27
32
|
"keywords": [
|
|
28
33
|
"ioc",
|
|
@@ -34,11 +39,11 @@
|
|
|
34
39
|
"author": "Boris Okunskiy",
|
|
35
40
|
"license": "ISC",
|
|
36
41
|
"devDependencies": {
|
|
42
|
+
"@nodescript/eslint-config": "^1.0.0",
|
|
37
43
|
"@types/mocha": "^8.2.3",
|
|
38
44
|
"@types/node": "^16.3.1",
|
|
39
|
-
"@ubio/eslint-config": "^1.1.6",
|
|
40
45
|
"chalk": "^4.1.2",
|
|
41
|
-
"eslint": "^
|
|
46
|
+
"eslint": "^8.24.0",
|
|
42
47
|
"mocha": "^9.0.2",
|
|
43
48
|
"pre-commit": "^1.2.2",
|
|
44
49
|
"reflect-metadata": "^0.1.13",
|
package/out/main/handlers.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Mesh } from './mesh.js';
|
|
2
|
-
import { ServiceHandler } from './types.js';
|
|
3
|
-
export declare const handlersMap: Map<string, ServiceHandler[]>;
|
|
4
|
-
export declare function createHandlerDecorator(name: string): () => (target: any, methodName: string) => void;
|
|
5
|
-
export declare function findHandlers(mesh: Mesh, name: string, recursive?: boolean): IterableIterator<ServiceHandler>;
|
|
6
|
-
export declare function invokeHandlers(mesh: Mesh, name: string, recursive?: boolean): Promise<void>;
|
package/out/main/handlers.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.invokeHandlers = exports.findHandlers = exports.createHandlerDecorator = exports.handlersMap = void 0;
|
|
13
|
-
exports.handlersMap = new Map();
|
|
14
|
-
function createHandlerDecorator(name) {
|
|
15
|
-
var _a;
|
|
16
|
-
const handlers = (_a = exports.handlersMap.get(name)) !== null && _a !== void 0 ? _a : [];
|
|
17
|
-
exports.handlersMap.set(name, handlers);
|
|
18
|
-
return () => {
|
|
19
|
-
return (target, methodName) => {
|
|
20
|
-
handlers.push({
|
|
21
|
-
target: target.constructor,
|
|
22
|
-
methodName,
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
exports.createHandlerDecorator = createHandlerDecorator;
|
|
28
|
-
function* findHandlers(mesh, name, recursive = true) {
|
|
29
|
-
var _a;
|
|
30
|
-
const targets = (_a = exports.handlersMap.get(name)) !== null && _a !== void 0 ? _a : [];
|
|
31
|
-
for (const [key, binding] of mesh.bindings) {
|
|
32
|
-
if (binding.type === 'service') {
|
|
33
|
-
for (const t of targets) {
|
|
34
|
-
if (t.target === binding.class || t.target.isPrototypeOf(binding.class)) {
|
|
35
|
-
yield {
|
|
36
|
-
target: mesh.resolve(key),
|
|
37
|
-
methodName: t.methodName,
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
if (recursive && mesh.parent) {
|
|
44
|
-
yield* findHandlers(mesh.parent, name, recursive);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
exports.findHandlers = findHandlers;
|
|
48
|
-
function invokeHandlers(mesh, name, recursive = false) {
|
|
49
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
-
const handlers = [...findHandlers(mesh, name, recursive)];
|
|
51
|
-
const promises = handlers.map(h => h.target[h.methodName]());
|
|
52
|
-
yield Promise.all(promises);
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
exports.invokeHandlers = invokeHandlers;
|
package/out/main/reflect.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Mesh } from './mesh.js';
|
|
2
|
-
import { ServiceHandler } from './types.js';
|
|
3
|
-
export declare const handlersMap: Map<string, ServiceHandler[]>;
|
|
4
|
-
export declare function createHandlerDecorator(name: string): () => (target: any, methodName: string) => void;
|
|
5
|
-
export declare function findHandlers(mesh: Mesh, name: string, recursive?: boolean): IterableIterator<ServiceHandler>;
|
|
6
|
-
export declare function invokeHandlers(mesh: Mesh, name: string, recursive?: boolean): Promise<void>;
|
package/out/main/reflect.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.invokeHandlers = exports.findHandlers = exports.createHandlerDecorator = exports.handlersMap = void 0;
|
|
13
|
-
exports.handlersMap = new Map();
|
|
14
|
-
function createHandlerDecorator(name) {
|
|
15
|
-
var _a;
|
|
16
|
-
const handlers = (_a = exports.handlersMap.get(name)) !== null && _a !== void 0 ? _a : [];
|
|
17
|
-
exports.handlersMap.set(name, handlers);
|
|
18
|
-
return () => {
|
|
19
|
-
return (target, methodName) => {
|
|
20
|
-
handlers.push({
|
|
21
|
-
target: target.constructor,
|
|
22
|
-
methodName,
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
exports.createHandlerDecorator = createHandlerDecorator;
|
|
28
|
-
function* findHandlers(mesh, name, recursive = true) {
|
|
29
|
-
var _a;
|
|
30
|
-
const targets = (_a = exports.handlersMap.get(name)) !== null && _a !== void 0 ? _a : [];
|
|
31
|
-
for (const [key, binding] of mesh.bindings) {
|
|
32
|
-
if (binding.type === 'service') {
|
|
33
|
-
for (const t of targets) {
|
|
34
|
-
if (t.target === binding.class || t.target.isPrototypeOf(binding.class)) {
|
|
35
|
-
yield {
|
|
36
|
-
target: mesh.resolve(key),
|
|
37
|
-
methodName: t.methodName,
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
if (recursive && mesh.parent) {
|
|
44
|
-
yield* findHandlers(mesh.parent, name, recursive);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
exports.findHandlers = findHandlers;
|
|
48
|
-
function invokeHandlers(mesh, name, recursive = false) {
|
|
49
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
-
const handlers = [...findHandlers(mesh, name, recursive)];
|
|
51
|
-
const promises = handlers.map(h => h.target[h.methodName]());
|
|
52
|
-
yield Promise.all(promises);
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
exports.invokeHandlers = invokeHandlers;
|