@xyo-network/bridge-module-resolver 2.69.0-rc.1 → 2.69.0-rc.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/dist/cjs/ProxyModule.js +56 -24
- package/dist/cjs/ProxyModule.js.map +1 -1
- package/dist/esm/ProxyModule.js +52 -24
- package/dist/esm/ProxyModule.js.map +1 -1
- package/dist/types/ProxyModule.d.ts +3 -1
- package/dist/types/ProxyModule.d.ts.map +1 -1
- package/package.json +20 -20
- package/src/ProxyModule.ts +54 -24
package/dist/cjs/ProxyModule.js
CHANGED
|
@@ -13,6 +13,7 @@ class ProxyModule extends module_1.BaseEmitter {
|
|
|
13
13
|
super({ config: proxyParams.bridge.targetConfig(proxyParams.address) });
|
|
14
14
|
this.proxyParams = proxyParams;
|
|
15
15
|
this.upResolver = new module_1.CompositeModuleResolver();
|
|
16
|
+
this._busyCount = 0;
|
|
16
17
|
}
|
|
17
18
|
get address() {
|
|
18
19
|
return this.proxyParams.address.toLowerCase();
|
|
@@ -33,26 +34,53 @@ class ProxyModule extends module_1.BaseEmitter {
|
|
|
33
34
|
addressPreviousHash() {
|
|
34
35
|
throw Error('Not Implemented');
|
|
35
36
|
}
|
|
36
|
-
|
|
37
|
-
var _a;
|
|
37
|
+
busy(closure) {
|
|
38
38
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
39
|
+
if (this._busyCount <= 0) {
|
|
40
|
+
this._busyCount = 0;
|
|
41
|
+
const args = { busy: true, module: this };
|
|
42
|
+
yield this.emit('moduleBusy', args);
|
|
43
|
+
}
|
|
44
|
+
this._busyCount++;
|
|
45
|
+
try {
|
|
46
|
+
return yield closure();
|
|
45
47
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
finally {
|
|
49
|
+
this._busyCount--;
|
|
50
|
+
if (this._busyCount <= 0) {
|
|
51
|
+
this._busyCount = 0;
|
|
52
|
+
const args = { busy: false, module: this };
|
|
53
|
+
yield this.emit('moduleBusy', args);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
describe() {
|
|
59
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
return yield this.busy(() => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
var _a;
|
|
62
|
+
const description = {
|
|
63
|
+
address: this.address,
|
|
64
|
+
queries: this.queries,
|
|
65
|
+
};
|
|
66
|
+
if (this.config.name) {
|
|
67
|
+
description.name = this.config.name;
|
|
68
|
+
}
|
|
69
|
+
const discover = yield this.discover();
|
|
70
|
+
description.children = (0, compact_1.default)((_a = discover === null || discover === void 0 ? void 0 : discover.map((payload) => {
|
|
71
|
+
const address = payload.schema === address_payload_plugin_1.AddressSchema ? payload.address : undefined;
|
|
72
|
+
return address != this.address ? address : undefined;
|
|
73
|
+
})) !== null && _a !== void 0 ? _a : []);
|
|
74
|
+
return description;
|
|
75
|
+
}));
|
|
52
76
|
});
|
|
53
77
|
}
|
|
54
78
|
discover() {
|
|
55
|
-
return
|
|
79
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
return yield this.busy(() => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
return yield this.bridge.targetDiscover();
|
|
82
|
+
}));
|
|
83
|
+
});
|
|
56
84
|
}
|
|
57
85
|
manifest() {
|
|
58
86
|
var _a;
|
|
@@ -67,9 +95,11 @@ class ProxyModule extends module_1.BaseEmitter {
|
|
|
67
95
|
}
|
|
68
96
|
query(query, payloads) {
|
|
69
97
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
98
|
+
return yield this.busy(() => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
99
|
+
const result = (0, assert_1.assertEx)(yield this.bridge.targetQuery(this.address, query, payloads), 'Remote Query Failed');
|
|
100
|
+
yield this.emit('moduleQueried', { module: this, payloads, query, result });
|
|
101
|
+
return result;
|
|
102
|
+
}));
|
|
73
103
|
});
|
|
74
104
|
}
|
|
75
105
|
queryable(query, payloads, queryConfig) {
|
|
@@ -79,12 +109,14 @@ class ProxyModule extends module_1.BaseEmitter {
|
|
|
79
109
|
}
|
|
80
110
|
resolve(nameOrAddressOrFilter, options) {
|
|
81
111
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
112
|
+
return yield this.busy(() => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
if (typeof nameOrAddressOrFilter === 'string') {
|
|
114
|
+
return yield this.bridge.targetResolve(this.address, nameOrAddressOrFilter, options);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
return yield this.bridge.targetResolve(this.address, nameOrAddressOrFilter, options);
|
|
118
|
+
}
|
|
119
|
+
}));
|
|
88
120
|
});
|
|
89
121
|
}
|
|
90
122
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProxyModule.js","sourceRoot":"","sources":["../../src/ProxyModule.ts"],"names":[],"mappings":";;;;AAAA,2CAAyC;AACzC,gFAAmF;AAGnF,gEAA0F;AAC1F,
|
|
1
|
+
{"version":3,"file":"ProxyModule.js","sourceRoot":"","sources":["../../src/ProxyModule.ts"],"names":[],"mappings":";;;;AAAA,2CAAyC;AACzC,gFAAmF;AAGnF,gEAA0F;AAC1F,gDAa4B;AAG5B,qEAAoC;AAGvB,QAAA,uBAAuB,GAA4B,iCAAiC,CAAA;AAYjG,MAAa,WAAY,SAAQ,oBAA0C;IAKzE,YAAmB,WAA8B;QAC/C,KAAK,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,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O,EAAE,qBAAqB,EAAE,OAAO,CAAC,CAAA;iBACrF;qBAAM;oBACL,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,EAAE,qBAAqB,EAAE,OAAO,CAAC,CAAA;iBACrF;YACH,CAAC,CAAA,CAAC,CAAA;QACJ,CAAC;KAAA;CACF;AA1HD,kCA0HC"}
|
package/dist/esm/ProxyModule.js
CHANGED
|
@@ -7,6 +7,7 @@ export const ProxyModuleConfigSchema = 'network.xyo.module.proxy.config';
|
|
|
7
7
|
export class ProxyModule extends BaseEmitter {
|
|
8
8
|
proxyParams;
|
|
9
9
|
upResolver = new CompositeModuleResolver();
|
|
10
|
+
_busyCount = 0;
|
|
10
11
|
constructor(proxyParams) {
|
|
11
12
|
super({ config: proxyParams.bridge.targetConfig(proxyParams.address) });
|
|
12
13
|
this.proxyParams = proxyParams;
|
|
@@ -30,23 +31,46 @@ export class ProxyModule extends BaseEmitter {
|
|
|
30
31
|
addressPreviousHash() {
|
|
31
32
|
throw Error('Not Implemented');
|
|
32
33
|
}
|
|
33
|
-
async
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
async busy(closure) {
|
|
35
|
+
if (this._busyCount <= 0) {
|
|
36
|
+
this._busyCount = 0;
|
|
37
|
+
const args = { busy: true, module: this };
|
|
38
|
+
await this.emit('moduleBusy', args);
|
|
39
|
+
}
|
|
40
|
+
this._busyCount++;
|
|
41
|
+
try {
|
|
42
|
+
return await closure();
|
|
43
|
+
}
|
|
44
|
+
finally {
|
|
45
|
+
this._busyCount--;
|
|
46
|
+
if (this._busyCount <= 0) {
|
|
47
|
+
this._busyCount = 0;
|
|
48
|
+
const args = { busy: false, module: this };
|
|
49
|
+
await this.emit('moduleBusy', args);
|
|
50
|
+
}
|
|
40
51
|
}
|
|
41
|
-
const discover = await this.discover();
|
|
42
|
-
description.children = compact(discover?.map((payload) => {
|
|
43
|
-
const address = payload.schema === AddressSchema ? payload.address : undefined;
|
|
44
|
-
return address != this.address ? address : undefined;
|
|
45
|
-
}) ?? []);
|
|
46
|
-
return description;
|
|
47
52
|
}
|
|
48
|
-
|
|
49
|
-
return this.
|
|
53
|
+
async describe() {
|
|
54
|
+
return await this.busy(async () => {
|
|
55
|
+
const description = {
|
|
56
|
+
address: this.address,
|
|
57
|
+
queries: this.queries,
|
|
58
|
+
};
|
|
59
|
+
if (this.config.name) {
|
|
60
|
+
description.name = this.config.name;
|
|
61
|
+
}
|
|
62
|
+
const discover = await this.discover();
|
|
63
|
+
description.children = compact(discover?.map((payload) => {
|
|
64
|
+
const address = payload.schema === AddressSchema ? payload.address : undefined;
|
|
65
|
+
return address != this.address ? address : undefined;
|
|
66
|
+
}) ?? []);
|
|
67
|
+
return description;
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
async discover() {
|
|
71
|
+
return await this.busy(async () => {
|
|
72
|
+
return await this.bridge.targetDiscover();
|
|
73
|
+
});
|
|
50
74
|
}
|
|
51
75
|
manifest() {
|
|
52
76
|
const name = this.config.name ?? 'Anonymous';
|
|
@@ -59,20 +83,24 @@ export class ProxyModule extends BaseEmitter {
|
|
|
59
83
|
throw Error('Not Implemented');
|
|
60
84
|
}
|
|
61
85
|
async query(query, payloads) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
86
|
+
return await this.busy(async () => {
|
|
87
|
+
const result = assertEx(await this.bridge.targetQuery(this.address, query, payloads), 'Remote Query Failed');
|
|
88
|
+
await this.emit('moduleQueried', { module: this, payloads, query, result });
|
|
89
|
+
return result;
|
|
90
|
+
});
|
|
65
91
|
}
|
|
66
92
|
async queryable(query, payloads, queryConfig) {
|
|
67
93
|
return await this.bridge.targetQueryable(this.address, query, payloads, queryConfig);
|
|
68
94
|
}
|
|
69
95
|
async resolve(nameOrAddressOrFilter, options) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
96
|
+
return await this.busy(async () => {
|
|
97
|
+
if (typeof nameOrAddressOrFilter === 'string') {
|
|
98
|
+
return await this.bridge.targetResolve(this.address, nameOrAddressOrFilter, options);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
return await this.bridge.targetResolve(this.address, nameOrAddressOrFilter, options);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
76
104
|
}
|
|
77
105
|
}
|
|
78
106
|
//# sourceMappingURL=ProxyModule.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProxyModule.js","sourceRoot":"","sources":["../../src/ProxyModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAkB,aAAa,EAAE,MAAM,qCAAqC,CAAA;AAGnF,OAAO,EAAE,qBAAqB,EAAyB,MAAM,6BAA6B,CAAA;AAC1F,OAAO,EAEL,WAAW,EACX,uBAAuB,
|
|
1
|
+
{"version":3,"file":"ProxyModule.js","sourceRoot":"","sources":["../../src/ProxyModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAkB,aAAa,EAAE,MAAM,qCAAqC,CAAA;AAGnF,OAAO,EAAE,qBAAqB,EAAyB,MAAM,6BAA6B,CAAA;AAC1F,OAAO,EAEL,WAAW,EACX,uBAAuB,GAUxB,MAAM,qBAAqB,CAAA;AAG5B,OAAO,OAAO,MAAM,gBAAgB,CAAA;AAGpC,MAAM,CAAC,MAAM,uBAAuB,GAA4B,iCAAiC,CAAA;AAYjG,MAAM,OAAO,WAAY,SAAQ,WAA0C;IAKtD;IAJV,UAAU,GAAG,IAAI,uBAAuB,EAAE,CAAA;IAE3C,UAAU,GAAG,CAAC,CAAA;IAEtB,YAAmB,WAA8B;QAC/C,KAAK,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,YAAY,CAA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O,EAAE,qBAAqB,EAAE,OAAO,CAAC,CAAA;aACrF;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;CACF"}
|
|
@@ -16,6 +16,7 @@ export type ProxyModuleParams = ModuleParams<TProxyModuleConfig, {
|
|
|
16
16
|
export declare class ProxyModule extends BaseEmitter<ModuleParams, ModuleEventData> implements ModuleInstance<ModuleParams, ModuleEventData> {
|
|
17
17
|
proxyParams: ProxyModuleParams;
|
|
18
18
|
readonly upResolver: CompositeModuleResolver;
|
|
19
|
+
private _busyCount;
|
|
19
20
|
constructor(proxyParams: ProxyModuleParams);
|
|
20
21
|
get address(): string;
|
|
21
22
|
get bridge(): BridgeModule<import("@xyo-network/core").BaseParamsFields & {
|
|
@@ -66,8 +67,9 @@ export declare class ProxyModule extends BaseEmitter<ModuleParams, ModuleEventDa
|
|
|
66
67
|
get downResolver(): import("@xyo-network/module").ModuleResolver;
|
|
67
68
|
get queries(): string[];
|
|
68
69
|
addressPreviousHash(): Promise<AddressPreviousHashPayload>;
|
|
70
|
+
busy<R>(closure: () => Promise<R>): Promise<R>;
|
|
69
71
|
describe(): Promise<ModuleDescription>;
|
|
70
|
-
discover():
|
|
72
|
+
discover(): Promise<Payload[]>;
|
|
71
73
|
manifest(): Promisable<ModuleManifestPayload>;
|
|
72
74
|
moduleAddress(): Promise<AddressPreviousHashPayload[]>;
|
|
73
75
|
previousHash(): Promise<string | undefined>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProxyModule.d.ts","sourceRoot":"","sources":["../../src/ProxyModule.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAA;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,EAAyB,qBAAqB,EAAE,MAAM,6BAA6B,CAAA;AAC1F,OAAO,EACL,0BAA0B,EAC1B,WAAW,EACX,uBAAuB,
|
|
1
|
+
{"version":3,"file":"ProxyModule.d.ts","sour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IAAI,OAAO,CAAC,0BAA0B,CAAC;IAIpD,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC;IAmBjC,QAAQ,IAAI,OAAO,CAAC,iBAAiB,CAAC;IAuBtC,QAAQ,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAMpC,QAAQ,IAAI,UAAU,CAAC,qBAAqB,CAAC;IAK7C,aAAa,IAAI,OAAO,CAAC,0BAA0B,EAAE,CAAC;IAItD,YAAY,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAIrC,KAAK,CAAC,CAAC,SAAS,iBAAiB,GAAG,iBAAiB,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAQlH,SAAS,CAAC,KAAK,EAAE,iBAAiB,EAAE,QAAQ,CAAC,EAAE,OAAO,EAAE,EAAE,WAAW,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC;IAK7G,OAAO,CAAC,MAAM,CAAC,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IACxF,OAAO,CAAC,aAAa,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC;CAanG"}
|
package/package.json
CHANGED
|
@@ -11,25 +11,25 @@
|
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@xylabs/assert": "^2.9.3",
|
|
14
|
-
"@xyo-network/account-model": "~2.69.0-rc.
|
|
15
|
-
"@xyo-network/address-payload-plugin": "~2.69.0-rc.
|
|
16
|
-
"@xyo-network/archivist-model": "~2.69.0-rc.
|
|
17
|
-
"@xyo-network/archivist-wrapper": "~2.69.0-rc.
|
|
18
|
-
"@xyo-network/boundwitness-builder": "~2.69.0-rc.
|
|
19
|
-
"@xyo-network/bridge-model": "~2.69.0-rc.
|
|
20
|
-
"@xyo-network/diviner": "~2.69.0-rc.
|
|
21
|
-
"@xyo-network/diviner-model": "~2.69.0-rc.
|
|
22
|
-
"@xyo-network/error": "~2.69.0-rc.
|
|
23
|
-
"@xyo-network/manifest-model": "~2.69.0-rc.
|
|
24
|
-
"@xyo-network/module": "~2.69.0-rc.
|
|
25
|
-
"@xyo-network/module-model": "~2.69.0-rc.
|
|
26
|
-
"@xyo-network/node-model": "~2.69.0-rc.
|
|
27
|
-
"@xyo-network/node-wrapper": "~2.69.0-rc.
|
|
28
|
-
"@xyo-network/payload-model": "~2.69.0-rc.
|
|
29
|
-
"@xyo-network/promise": "~2.69.0-rc.
|
|
30
|
-
"@xyo-network/sentinel": "~2.69.0-rc.
|
|
31
|
-
"@xyo-network/witness-model": "~2.69.0-rc.
|
|
32
|
-
"@xyo-network/witness-wrapper": "~2.69.0-rc.
|
|
14
|
+
"@xyo-network/account-model": "~2.69.0-rc.3",
|
|
15
|
+
"@xyo-network/address-payload-plugin": "~2.69.0-rc.3",
|
|
16
|
+
"@xyo-network/archivist-model": "~2.69.0-rc.3",
|
|
17
|
+
"@xyo-network/archivist-wrapper": "~2.69.0-rc.3",
|
|
18
|
+
"@xyo-network/boundwitness-builder": "~2.69.0-rc.3",
|
|
19
|
+
"@xyo-network/bridge-model": "~2.69.0-rc.3",
|
|
20
|
+
"@xyo-network/diviner": "~2.69.0-rc.3",
|
|
21
|
+
"@xyo-network/diviner-model": "~2.69.0-rc.3",
|
|
22
|
+
"@xyo-network/error": "~2.69.0-rc.3",
|
|
23
|
+
"@xyo-network/manifest-model": "~2.69.0-rc.3",
|
|
24
|
+
"@xyo-network/module": "~2.69.0-rc.3",
|
|
25
|
+
"@xyo-network/module-model": "~2.69.0-rc.3",
|
|
26
|
+
"@xyo-network/node-model": "~2.69.0-rc.3",
|
|
27
|
+
"@xyo-network/node-wrapper": "~2.69.0-rc.3",
|
|
28
|
+
"@xyo-network/payload-model": "~2.69.0-rc.3",
|
|
29
|
+
"@xyo-network/promise": "~2.69.0-rc.3",
|
|
30
|
+
"@xyo-network/sentinel": "~2.69.0-rc.3",
|
|
31
|
+
"@xyo-network/witness-model": "~2.69.0-rc.3",
|
|
32
|
+
"@xyo-network/witness-wrapper": "~2.69.0-rc.3",
|
|
33
33
|
"lodash": "^4.17.21"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
@@ -70,6 +70,6 @@
|
|
|
70
70
|
},
|
|
71
71
|
"sideEffects": false,
|
|
72
72
|
"types": "dist/types/index.d.ts",
|
|
73
|
-
"version": "2.69.0-rc.
|
|
73
|
+
"version": "2.69.0-rc.3",
|
|
74
74
|
"stableVersion": "2.68.0"
|
|
75
75
|
}
|
package/src/ProxyModule.ts
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
AddressPreviousHashPayload,
|
|
8
8
|
BaseEmitter,
|
|
9
9
|
CompositeModuleResolver,
|
|
10
|
+
ModuleBusyEventArgs,
|
|
10
11
|
ModuleConfig,
|
|
11
12
|
ModuleDescription,
|
|
12
13
|
ModuleEventData,
|
|
@@ -36,6 +37,8 @@ export type ProxyModuleParams = ModuleParams<
|
|
|
36
37
|
export class ProxyModule extends BaseEmitter<ModuleParams, ModuleEventData> implements ModuleInstance<ModuleParams, ModuleEventData> {
|
|
37
38
|
readonly upResolver = new CompositeModuleResolver()
|
|
38
39
|
|
|
40
|
+
private _busyCount = 0
|
|
41
|
+
|
|
39
42
|
constructor(public proxyParams: ProxyModuleParams) {
|
|
40
43
|
super({ config: proxyParams.bridge.targetConfig(proxyParams.address) })
|
|
41
44
|
}
|
|
@@ -65,29 +68,52 @@ export class ProxyModule extends BaseEmitter<ModuleParams, ModuleEventData> impl
|
|
|
65
68
|
throw Error('Not Implemented')
|
|
66
69
|
}
|
|
67
70
|
|
|
68
|
-
async
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
71
|
+
async busy<R>(closure: () => Promise<R>) {
|
|
72
|
+
if (this._busyCount <= 0) {
|
|
73
|
+
this._busyCount = 0
|
|
74
|
+
const args: ModuleBusyEventArgs = { busy: true, module: this }
|
|
75
|
+
await this.emit('moduleBusy', args)
|
|
72
76
|
}
|
|
73
|
-
|
|
74
|
-
|
|
77
|
+
this._busyCount++
|
|
78
|
+
try {
|
|
79
|
+
return await closure()
|
|
80
|
+
} finally {
|
|
81
|
+
this._busyCount--
|
|
82
|
+
if (this._busyCount <= 0) {
|
|
83
|
+
this._busyCount = 0
|
|
84
|
+
const args: ModuleBusyEventArgs = { busy: false, module: this }
|
|
85
|
+
await this.emit('moduleBusy', args)
|
|
86
|
+
}
|
|
75
87
|
}
|
|
88
|
+
}
|
|
76
89
|
|
|
77
|
-
|
|
90
|
+
async describe(): Promise<ModuleDescription> {
|
|
91
|
+
return await this.busy(async () => {
|
|
92
|
+
const description: ModuleDescription = {
|
|
93
|
+
address: this.address,
|
|
94
|
+
queries: this.queries,
|
|
95
|
+
}
|
|
96
|
+
if (this.config.name) {
|
|
97
|
+
description.name = this.config.name
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const discover = await this.discover()
|
|
78
101
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
102
|
+
description.children = compact(
|
|
103
|
+
discover?.map((payload) => {
|
|
104
|
+
const address = payload.schema === AddressSchema ? (payload as AddressPayload).address : undefined
|
|
105
|
+
return address != this.address ? address : undefined
|
|
106
|
+
}) ?? [],
|
|
107
|
+
)
|
|
85
108
|
|
|
86
|
-
|
|
109
|
+
return description
|
|
110
|
+
})
|
|
87
111
|
}
|
|
88
112
|
|
|
89
|
-
discover():
|
|
90
|
-
return this.
|
|
113
|
+
async discover(): Promise<Payload[]> {
|
|
114
|
+
return await this.busy(async () => {
|
|
115
|
+
return await this.bridge.targetDiscover()
|
|
116
|
+
})
|
|
91
117
|
}
|
|
92
118
|
|
|
93
119
|
manifest(): Promisable<ModuleManifestPayload> {
|
|
@@ -104,9 +130,11 @@ export class ProxyModule extends BaseEmitter<ModuleParams, ModuleEventData> impl
|
|
|
104
130
|
}
|
|
105
131
|
|
|
106
132
|
async query<T extends QueryBoundWitness = QueryBoundWitness>(query: T, payloads?: Payload[]): Promise<ModuleQueryResult> {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
133
|
+
return await this.busy(async () => {
|
|
134
|
+
const result = assertEx(await this.bridge.targetQuery(this.address, query, payloads), 'Remote Query Failed')
|
|
135
|
+
await this.emit('moduleQueried', { module: this, payloads, query, result })
|
|
136
|
+
return result
|
|
137
|
+
})
|
|
110
138
|
}
|
|
111
139
|
|
|
112
140
|
async queryable(query: QueryBoundWitness, payloads?: Payload[], queryConfig?: ModuleConfig): Promise<boolean> {
|
|
@@ -120,10 +148,12 @@ export class ProxyModule extends BaseEmitter<ModuleParams, ModuleEventData> impl
|
|
|
120
148
|
nameOrAddressOrFilter?: ModuleFilter | string,
|
|
121
149
|
options?: ModuleFilterOptions,
|
|
122
150
|
): Promise<ModuleInstance | ModuleInstance[] | undefined> {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
151
|
+
return await this.busy(async () => {
|
|
152
|
+
if (typeof nameOrAddressOrFilter === 'string') {
|
|
153
|
+
return await this.bridge.targetResolve(this.address, nameOrAddressOrFilter, options)
|
|
154
|
+
} else {
|
|
155
|
+
return await this.bridge.targetResolve(this.address, nameOrAddressOrFilter, options)
|
|
156
|
+
}
|
|
157
|
+
})
|
|
128
158
|
}
|
|
129
159
|
}
|