@xyo-network/bridge-module-resolver 2.69.0-rc.2 → 2.69.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/ProxyModule.js +56 -24
- package/dist/cjs/ProxyModule.js.map +1 -1
- package/dist/docs.json +27430 -0
- 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 -21
- package/src/ProxyModule.ts +54 -24
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;IAE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AAE,qBAAqB,EAAE,OAAO,CAAC,CAAA;aACrF;iBAAM;gBACL,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,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,E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;;;;;;;;;;;;;;;gCAET;IAED,IAAI,MAAM,IAAI,YAAY,CAGzB;IAED,IAAI,YAAY,iDAEf;IAED,IAAI,OAAO,aAEV;IAED,mBAAmB,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
|
|
15
|
-
"@xyo-network/address-payload-plugin": "~2.69.0
|
|
16
|
-
"@xyo-network/archivist-model": "~2.69.0
|
|
17
|
-
"@xyo-network/archivist-wrapper": "~2.69.0
|
|
18
|
-
"@xyo-network/boundwitness-builder": "~2.69.0
|
|
19
|
-
"@xyo-network/bridge-model": "~2.69.0
|
|
20
|
-
"@xyo-network/diviner": "~2.69.0
|
|
21
|
-
"@xyo-network/diviner-model": "~2.69.0
|
|
22
|
-
"@xyo-network/error": "~2.69.0
|
|
23
|
-
"@xyo-network/manifest-model": "~2.69.0
|
|
24
|
-
"@xyo-network/module": "~2.69.0
|
|
25
|
-
"@xyo-network/module-model": "~2.69.0
|
|
26
|
-
"@xyo-network/node-model": "~2.69.0
|
|
27
|
-
"@xyo-network/node-wrapper": "~2.69.0
|
|
28
|
-
"@xyo-network/payload-model": "~2.69.0
|
|
29
|
-
"@xyo-network/promise": "~2.69.0
|
|
30
|
-
"@xyo-network/sentinel": "~2.69.0
|
|
31
|
-
"@xyo-network/witness-model": "~2.69.0
|
|
32
|
-
"@xyo-network/witness-wrapper": "~2.69.0
|
|
14
|
+
"@xyo-network/account-model": "~2.69.0",
|
|
15
|
+
"@xyo-network/address-payload-plugin": "~2.69.0",
|
|
16
|
+
"@xyo-network/archivist-model": "~2.69.0",
|
|
17
|
+
"@xyo-network/archivist-wrapper": "~2.69.0",
|
|
18
|
+
"@xyo-network/boundwitness-builder": "~2.69.0",
|
|
19
|
+
"@xyo-network/bridge-model": "~2.69.0",
|
|
20
|
+
"@xyo-network/diviner": "~2.69.0",
|
|
21
|
+
"@xyo-network/diviner-model": "~2.69.0",
|
|
22
|
+
"@xyo-network/error": "~2.69.0",
|
|
23
|
+
"@xyo-network/manifest-model": "~2.69.0",
|
|
24
|
+
"@xyo-network/module": "~2.69.0",
|
|
25
|
+
"@xyo-network/module-model": "~2.69.0",
|
|
26
|
+
"@xyo-network/node-model": "~2.69.0",
|
|
27
|
+
"@xyo-network/node-wrapper": "~2.69.0",
|
|
28
|
+
"@xyo-network/payload-model": "~2.69.0",
|
|
29
|
+
"@xyo-network/promise": "~2.69.0",
|
|
30
|
+
"@xyo-network/sentinel": "~2.69.0",
|
|
31
|
+
"@xyo-network/witness-model": "~2.69.0",
|
|
32
|
+
"@xyo-network/witness-wrapper": "~2.69.0",
|
|
33
33
|
"lodash": "^4.17.21"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
@@ -70,6 +70,5 @@
|
|
|
70
70
|
},
|
|
71
71
|
"sideEffects": false,
|
|
72
72
|
"types": "dist/types/index.d.ts",
|
|
73
|
-
"version": "2.69.0
|
|
74
|
-
"stableVersion": "2.68.0"
|
|
73
|
+
"version": "2.69.0"
|
|
75
74
|
}
|
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
|
}
|