mesh-ioc 2.1.0 → 2.2.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/out/main/index.d.ts +1 -0
- package/out/main/index.js +1 -0
- package/out/main/reflect.d.ts +6 -0
- package/out/main/reflect.js +55 -0
- package/out/main/types.d.ts +3 -4
- package/package.json +1 -1
- package/out/main/scope.d.ts +0 -11
- package/out/main/scope.js +0 -41
package/out/main/index.d.ts
CHANGED
package/out/main/index.js
CHANGED
|
@@ -0,0 +1,6 @@
|
|
|
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>;
|
|
@@ -0,0 +1,55 @@
|
|
|
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/types.d.ts
CHANGED
|
@@ -29,8 +29,7 @@ export interface DepMetadata {
|
|
|
29
29
|
designTypeName: string;
|
|
30
30
|
key: string;
|
|
31
31
|
}
|
|
32
|
-
export interface
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
metadata?: any;
|
|
32
|
+
export interface ServiceHandler {
|
|
33
|
+
target: any;
|
|
34
|
+
methodName: string;
|
|
36
35
|
}
|
package/package.json
CHANGED
package/out/main/scope.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { AbstractClass, Binding, ServiceConstructor, ServiceKey } from './types';
|
|
2
|
-
export declare class Scope {
|
|
3
|
-
readonly name: string;
|
|
4
|
-
bindings: Map<string, Binding<any>>;
|
|
5
|
-
constructor(name: string, bindings?: Iterable<[string, Binding<any>]>);
|
|
6
|
-
[Symbol.iterator](): Generator<[string, Binding<any>], void, undefined>;
|
|
7
|
-
service<T>(impl: ServiceConstructor<T>): this;
|
|
8
|
-
service<T>(key: AbstractClass<T> | string, impl: ServiceConstructor<T>): this;
|
|
9
|
-
constant<T>(key: ServiceKey<T>, value: T): this;
|
|
10
|
-
alias<T>(key: AbstractClass<T> | string, referenceKey: AbstractClass<T> | string): this;
|
|
11
|
-
}
|
package/out/main/scope.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Scope = void 0;
|
|
4
|
-
const errors_1 = require("./errors");
|
|
5
|
-
const util_1 = require("./util");
|
|
6
|
-
class Scope {
|
|
7
|
-
constructor(name, bindings = []) {
|
|
8
|
-
this.name = name;
|
|
9
|
-
this.bindings = new Map();
|
|
10
|
-
for (const [k, v] of bindings) {
|
|
11
|
-
this.bindings.set(k, v);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
*[Symbol.iterator]() {
|
|
15
|
-
yield* this.bindings.entries();
|
|
16
|
-
}
|
|
17
|
-
service(key, impl) {
|
|
18
|
-
const k = util_1.keyToString(key);
|
|
19
|
-
if (typeof impl === 'function') {
|
|
20
|
-
this.bindings.set(k, { type: 'service', class: impl });
|
|
21
|
-
return this;
|
|
22
|
-
}
|
|
23
|
-
else if (typeof key === 'function') {
|
|
24
|
-
this.bindings.set(k, { type: 'service', class: key });
|
|
25
|
-
return this;
|
|
26
|
-
}
|
|
27
|
-
throw new errors_1.MeshInvalidBinding(String(key));
|
|
28
|
-
}
|
|
29
|
-
constant(key, value) {
|
|
30
|
-
const k = util_1.keyToString(key);
|
|
31
|
-
this.bindings.set(k, { type: 'constant', value });
|
|
32
|
-
return this;
|
|
33
|
-
}
|
|
34
|
-
alias(key, referenceKey) {
|
|
35
|
-
const k = util_1.keyToString(key);
|
|
36
|
-
const refK = util_1.keyToString(referenceKey);
|
|
37
|
-
this.bindings.set(k, { type: 'alias', key: refK });
|
|
38
|
-
return this;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
exports.Scope = Scope;
|