@xyo-network/bridge 2.46.2 → 2.46.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/HttpBridge.js +45 -18
- package/dist/cjs/HttpBridge.js.map +1 -1
- package/dist/cjs/HttpBridgeConfig.js +5 -0
- package/dist/cjs/HttpBridgeConfig.js.map +1 -0
- package/dist/cjs/RemoteModuleResolver.js +95 -0
- package/dist/cjs/RemoteModuleResolver.js.map +1 -0
- package/dist/docs.json +2158 -9411
- package/dist/esm/HttpBridge.js +39 -16
- package/dist/esm/HttpBridge.js.map +1 -1
- package/dist/esm/HttpBridgeConfig.js +2 -0
- package/dist/esm/HttpBridgeConfig.js.map +1 -0
- package/dist/esm/RemoteModuleResolver.js +80 -0
- package/dist/esm/RemoteModuleResolver.js.map +1 -0
- package/dist/types/Config.d.ts +1 -4
- package/dist/types/Config.d.ts.map +1 -1
- package/dist/types/HttpBridge.d.ts +20 -15
- package/dist/types/HttpBridge.d.ts.map +1 -1
- package/dist/types/HttpBridgeConfig.d.ts +10 -0
- package/dist/types/HttpBridgeConfig.d.ts.map +1 -0
- package/dist/types/RemoteModuleResolver.d.ts +21 -0
- package/dist/types/RemoteModuleResolver.d.ts.map +1 -0
- package/package.json +12 -8
- package/src/Config.ts +1 -6
- package/src/HttpBridge.ts +52 -28
- package/src/HttpBridgeConfig.ts +14 -0
- package/src/RemoteModuleResolver.ts +103 -0
- package/src/spec/HttpBridge.spec.ts +17 -21
package/dist/esm/HttpBridge.js
CHANGED
|
@@ -1,26 +1,44 @@
|
|
|
1
1
|
import { assertEx } from '@xylabs/assert';
|
|
2
2
|
import { Account } from '@xyo-network/account';
|
|
3
3
|
import { AxiosJson } from '@xyo-network/axios';
|
|
4
|
-
import { AbstractModule, QueryBoundWitnessWrapper, XyoErrorBuilder, } from '@xyo-network/module';
|
|
4
|
+
import { AbstractModule, ModuleDiscoverQuerySchema, ModuleWrapper, QueryBoundWitnessWrapper, XyoErrorBuilder, } from '@xyo-network/module';
|
|
5
|
+
import { PayloadWrapper } from '@xyo-network/payload-wrapper';
|
|
6
|
+
import { QuerySchema } from '@xyo-network/query-payload-plugin';
|
|
7
|
+
import compact from 'lodash/compact';
|
|
5
8
|
import { XyoBridgeConnectQuerySchema, XyoBridgeDisconnectQuerySchema } from './Queries';
|
|
6
|
-
|
|
9
|
+
import { RemoteModuleResolver } from './RemoteModuleResolver';
|
|
7
10
|
export class HttpBridge extends AbstractModule {
|
|
8
11
|
axios;
|
|
12
|
+
remoteQueries = [];
|
|
13
|
+
remoteResolver;
|
|
9
14
|
constructor(params) {
|
|
10
15
|
super(params);
|
|
11
|
-
this.axios = new AxiosJson(
|
|
16
|
+
this.axios = params.axios ?? new AxiosJson();
|
|
17
|
+
this.remoteResolver = new RemoteModuleResolver(this);
|
|
12
18
|
}
|
|
13
19
|
get nodeUri() {
|
|
14
20
|
return assertEx(this.config?.nodeUri, 'Missing nodeUri');
|
|
15
21
|
}
|
|
22
|
+
get queries() {
|
|
23
|
+
return [...super.queries, ...this.remoteQueries];
|
|
24
|
+
}
|
|
16
25
|
get targetAddress() {
|
|
17
26
|
return this.config?.targetAddress;
|
|
18
27
|
}
|
|
19
|
-
get targetAddressString() {
|
|
20
|
-
return this.targetAddress ?? '';
|
|
21
|
-
}
|
|
22
28
|
static async create(params) {
|
|
23
|
-
|
|
29
|
+
const result = (await super.create(params));
|
|
30
|
+
const moduleWrapper = ModuleWrapper.wrap(result);
|
|
31
|
+
const discover = await moduleWrapper.discover();
|
|
32
|
+
result.remoteQueries = compact(discover.map((payload) => {
|
|
33
|
+
if (payload.schema === QuerySchema) {
|
|
34
|
+
const schemaPayload = payload;
|
|
35
|
+
return schemaPayload.query;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
}));
|
|
41
|
+
return result;
|
|
24
42
|
}
|
|
25
43
|
connect() {
|
|
26
44
|
return true;
|
|
@@ -28,6 +46,10 @@ export class HttpBridge extends AbstractModule {
|
|
|
28
46
|
disconnect() {
|
|
29
47
|
return true;
|
|
30
48
|
}
|
|
49
|
+
async discover() {
|
|
50
|
+
const queryPayload = PayloadWrapper.parse({ schema: ModuleDiscoverQuerySchema });
|
|
51
|
+
return (await this.forward(queryPayload))[1];
|
|
52
|
+
}
|
|
31
53
|
async query(query, payloads) {
|
|
32
54
|
const wrapper = QueryBoundWitnessWrapper.parseQuery(query, payloads);
|
|
33
55
|
const typedQuery = wrapper.query.payload;
|
|
@@ -45,10 +67,10 @@ export class HttpBridge extends AbstractModule {
|
|
|
45
67
|
}
|
|
46
68
|
default:
|
|
47
69
|
if (super.queries.find((schema) => schema === typedQuery.schema)) {
|
|
48
|
-
return super.query(query, payloads);
|
|
70
|
+
return await super.query(query, payloads);
|
|
49
71
|
}
|
|
50
72
|
else {
|
|
51
|
-
return this.forward(query, payloads);
|
|
73
|
+
return await this.forward(query, payloads);
|
|
52
74
|
}
|
|
53
75
|
}
|
|
54
76
|
}
|
|
@@ -56,13 +78,16 @@ export class HttpBridge extends AbstractModule {
|
|
|
56
78
|
const error = ex;
|
|
57
79
|
resultPayloads.push(new XyoErrorBuilder([wrapper.hash], error.message).build());
|
|
58
80
|
}
|
|
59
|
-
return this.bindResult(resultPayloads, queryAccount);
|
|
81
|
+
return await this.bindResult(resultPayloads, queryAccount);
|
|
82
|
+
}
|
|
83
|
+
async resolve(filter) {
|
|
84
|
+
return [...(await super.resolve(filter)), ...(await this.remoteResolver.resolve(filter))];
|
|
60
85
|
}
|
|
61
|
-
async forward(query, payloads) {
|
|
86
|
+
async forward(query, payloads = []) {
|
|
62
87
|
try {
|
|
63
|
-
const boundQuery = this.bindQuery(query, payloads);
|
|
64
|
-
const result = await this.axios.post(`${this.nodeUri}/${this.
|
|
65
|
-
return result.data;
|
|
88
|
+
const boundQuery = await this.bindQuery(query, payloads);
|
|
89
|
+
const result = await this.axios.post(`${this.nodeUri}/address/${this.targetAddress}`, boundQuery);
|
|
90
|
+
return result.data.data;
|
|
66
91
|
}
|
|
67
92
|
catch (ex) {
|
|
68
93
|
const error = ex;
|
|
@@ -72,6 +97,4 @@ export class HttpBridge extends AbstractModule {
|
|
|
72
97
|
}
|
|
73
98
|
}
|
|
74
99
|
}
|
|
75
|
-
export class XyoHttpBridge extends HttpBridge {
|
|
76
|
-
}
|
|
77
100
|
//# sourceMappingURL=HttpBridge.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpBridge.js","sourceRoot":"","sources":["../../src/HttpBridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"HttpBridge.js","sourceRoot":"","sources":["../../src/HttpBridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAE9C,OAAO,EAAc,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC1D,OAAO,EACL,cAAc,EAEd,yBAAyB,EAKzB,aAAa,EACb,wBAAwB,EACxB,eAAe,GAGhB,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAE7D,OAAO,EAAgB,WAAW,EAAE,MAAM,mCAAmC,CAAA;AAC7E,OAAO,OAAO,MAAM,gBAAgB,CAAA;AAIpC,OAAO,EAAE,2BAA2B,EAAE,8BAA8B,EAAkB,MAAM,WAAW,CAAA;AACvG,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAM7D,MAAM,OAAO,UAAgE,SAAQ,cAAuB;IAClG,KAAK,CAAW;IAChB,aAAa,GAAa,EAAE,CAAA;IAC5B,cAAc,CAAgB;IAEtC,YAAsB,MAAoC;QACxD,KAAK,CAAC,MAAM,CA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CAAC,CAAA;IAC5D,CAAC;IAEQ,KAAK,CAAC,OAAO,CAAC,MAAqB;QAC1C,OAAO,CAAC,GAAG,CAAC,MAAM,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;IAC3F,CAAC;IAES,KAAK,CAAC,OAAO,CAAC,KAAe,EAAE,WAAyB,EAAE;QAClE,IAAI;YACF,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;YACxD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAoC,GAAG,IAAI,CAAC,OAAO,YAAY,IAAI,CAAC,aAAa,EAAE,EAAE,UAAU,CAAC,CAAA;YACpI,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAA;SACxB;QAAC,OAAO,EAAE,EAAE;YACX,MAAM,KAAK,GAAG,EAAgB,CAAA;YAC9B,OAAO,CAAC,GAAG,CAAC,iBAAiB,KAAK,CAAC,MAAM,EAAE,CAAC,CAAA;YAC5C,OAAO,CAAC,GAAG,CAAC,gBAAgB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAA;YACnE,MAAM,KAAK,CAAA;SACZ;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpBridgeConfig.js","sourceRoot":"","sources":["../../src/HttpBridgeConfig.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,MAAM,sBAAsB,GAA2B,gCAAgC,CAAA"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { assertEx } from '@xylabs/assert';
|
|
2
|
+
import { AddressSchema } from '@xyo-network/address-payload-plugin';
|
|
3
|
+
import { CompositeModuleResolver, ModuleWrapper } from '@xyo-network/module';
|
|
4
|
+
import compact from 'lodash/compact';
|
|
5
|
+
import flatten from 'lodash/flatten';
|
|
6
|
+
import { HttpBridge } from './HttpBridge';
|
|
7
|
+
import { HttpBridgeConfigSchema } from './HttpBridgeConfig';
|
|
8
|
+
export class RemoteModuleResolver extends CompositeModuleResolver {
|
|
9
|
+
bridge;
|
|
10
|
+
resolvedModules = {};
|
|
11
|
+
// TODO: Allow optional ctor param for supplying address for nested Nodes
|
|
12
|
+
// protected readonly address?: string,
|
|
13
|
+
constructor(bridge) {
|
|
14
|
+
super();
|
|
15
|
+
this.bridge = bridge;
|
|
16
|
+
}
|
|
17
|
+
get isModuleResolver() {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
add(_module, _name) {
|
|
21
|
+
throw new Error('Method not implemented.');
|
|
22
|
+
}
|
|
23
|
+
remove(_address) {
|
|
24
|
+
throw new Error('Method not implemented.');
|
|
25
|
+
}
|
|
26
|
+
async resolve(filter) {
|
|
27
|
+
const mods = await Promise.all(flatten(await this.resolveRemoteModules(filter)));
|
|
28
|
+
return this.filterLocalModules(mods, filter);
|
|
29
|
+
}
|
|
30
|
+
filterLocalModules(mods, filter) {
|
|
31
|
+
// TODO: Handle filter?.query
|
|
32
|
+
if (filter?.query)
|
|
33
|
+
throw new Error('Filtering by query not yet implemented by this resolver');
|
|
34
|
+
const config = filter?.config;
|
|
35
|
+
const filtered = config?.length ? mods.filter((mod) => config.includes(mod.config.schema)) : mods;
|
|
36
|
+
return filtered;
|
|
37
|
+
}
|
|
38
|
+
async getRemoteAddresses() {
|
|
39
|
+
const nodeWrapper = assertEx(ModuleWrapper.wrap(this.bridge), 'nodeUri can not be wrapped');
|
|
40
|
+
const discover = await nodeWrapper.discover();
|
|
41
|
+
return compact(discover.map((payload) => {
|
|
42
|
+
if (payload.schema === AddressSchema) {
|
|
43
|
+
const schemaPayload = payload;
|
|
44
|
+
return schemaPayload.address;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
}));
|
|
50
|
+
}
|
|
51
|
+
async resolveByAddress(targetAddress) {
|
|
52
|
+
const cached = this.resolvedModules[targetAddress];
|
|
53
|
+
if (cached)
|
|
54
|
+
return cached;
|
|
55
|
+
const mod = await HttpBridge.create({
|
|
56
|
+
config: { nodeUri: this.bridge.nodeUri, schema: HttpBridgeConfigSchema, targetAddress },
|
|
57
|
+
});
|
|
58
|
+
this.resolvedModules[targetAddress] = mod;
|
|
59
|
+
return mod;
|
|
60
|
+
}
|
|
61
|
+
async resolveByName(name) {
|
|
62
|
+
const cached = this.resolvedModules[name];
|
|
63
|
+
if (cached)
|
|
64
|
+
return cached;
|
|
65
|
+
const mod = await HttpBridge.create({
|
|
66
|
+
config: { name, nodeUri: this.bridge.nodeUri, schema: HttpBridgeConfigSchema },
|
|
67
|
+
});
|
|
68
|
+
this.resolvedModules[name] = mod;
|
|
69
|
+
this.resolvedModules[mod.address] = mod;
|
|
70
|
+
return mod;
|
|
71
|
+
}
|
|
72
|
+
async resolveRemoteModules(filter) {
|
|
73
|
+
const addresses = filter ? filter?.address : await this.getRemoteAddresses();
|
|
74
|
+
const names = filter?.name;
|
|
75
|
+
const byAddress = await Promise.all(addresses?.map((address) => this.resolveByAddress(address)) ?? []);
|
|
76
|
+
const byName = await Promise.all(names?.map((name) => this.resolveByName(name)) ?? []);
|
|
77
|
+
return [...byAddress, ...byName];
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=RemoteModuleResolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RemoteModuleResolver.js","sourceRoot":"","sources":["../../src/RemoteModuleResolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAkB,aAAa,EAAE,MAAM,qCAAqC,CAAA;AACnF,OAAO,EAAkB,uBAAuB,EAAE,aAAa,EAAE,MAAM,qBA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AE,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,sBAAsB,EAAE;SAC/E,CAAC,CAAA;QACF,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,GAAG,GAAG,CAAA;QAChC,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,GAAG,CAAA;QACvC,OAAO,GAAG,CAAA;IACZ,CAAC;IAEO,KAAK,CAAC,oBAAoB,CAAC,MAA2B;QAC5D,MAAM,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,kBAAkB,EAAE,CAAA;QAC5E,MAAM,KAAK,GAAG,MAAM,EAAE,IAAI,CAAA;QAC1B,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,CAAA;QACtG,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,CAAA;QACtF,OAAO,CAAC,GAAG,SAAS,EAAE,GAAG,MAAM,CAAC,CAAA;IAClC,CAAC;CACF"}
|
package/dist/types/Config.d.ts
CHANGED
|
@@ -2,8 +2,5 @@ import { ModuleConfig } from '@xyo-network/module';
|
|
|
2
2
|
import { XyoPayload } from '@xyo-network/payload-model';
|
|
3
3
|
export type XyoBridgeConfigSchema = 'network.xyo.bridge.config';
|
|
4
4
|
export declare const XyoBridgeConfigSchema: XyoBridgeConfigSchema;
|
|
5
|
-
export type BridgeConfig<TConfig extends XyoPayload = XyoPayload> = ModuleConfig<
|
|
6
|
-
nodeUri: string;
|
|
7
|
-
targetAddress?: string;
|
|
8
|
-
} & TConfig>;
|
|
5
|
+
export type BridgeConfig<TConfig extends XyoPayload = XyoPayload> = ModuleConfig<TConfig>;
|
|
9
6
|
//# sourceMappingURL=Config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/Config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA;AAEvD,MAAM,MAAM,qBAAqB,GAAG,2BAA2B,CAAA;AAC/D,eAAO,MAAM,qBAAqB,EAAE,qBAAmD,CAAA;AAEvF,MAAM,MAAM,YAAY,CAAC,OAAO,SAAS,UAAU,GAAG,UAAU,IAAI,YAAY,
|
|
1
|
+
{"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/Config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA;AAEvD,MAAM,MAAM,qBAAqB,GAAG,2BAA2B,CAAA;AAC/D,eAAO,MAAM,qBAAqB,EAAE,qBAAmD,CAAA;AAEvF,MAAM,MAAM,YAAY,CAAC,OAAO,SAAS,UAAU,GAAG,UAAU,IAAI,YAAY,CAAC,OAAO,CAAC,CAAA"}
|
|
@@ -1,31 +1,36 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AbstractModule, ModuleParams, ModuleQueryResult, XyoQuery, XyoQueryBoundWitness } from '@xyo-network/module';
|
|
1
|
+
import { AxiosJson } from '@xyo-network/axios';
|
|
2
|
+
import { AbstractModule, ModuleFilter, ModuleParams, ModuleQueryResult, XyoQuery, XyoQueryBoundWitness } from '@xyo-network/module';
|
|
3
3
|
import { XyoPayload } from '@xyo-network/payload-model';
|
|
4
4
|
import { Promisable } from '@xyo-network/promise';
|
|
5
5
|
import { BridgeModule } from './Bridge';
|
|
6
|
-
import {
|
|
7
|
-
export type HttpBridgeConfigSchema = 'network.xyo.bridge.http.config';
|
|
8
|
-
export declare const HttpBridgeConfigSchema: HttpBridgeConfigSchema;
|
|
9
|
-
export type HttpBridgeConfig = BridgeConfig<{
|
|
10
|
-
axios?: RawAxiosJsonRequestConfig;
|
|
11
|
-
headers?: AxiosRequestHeaders;
|
|
12
|
-
schema: HttpBridgeConfigSchema;
|
|
13
|
-
}>;
|
|
6
|
+
import { HttpBridgeConfig } from './HttpBridgeConfig';
|
|
14
7
|
export interface XyoHttpBridgeParams<TConfig extends HttpBridgeConfig = HttpBridgeConfig> extends ModuleParams<TConfig> {
|
|
15
|
-
axios
|
|
8
|
+
axios?: AxiosJson;
|
|
16
9
|
}
|
|
17
10
|
export declare class HttpBridge<TConfig extends HttpBridgeConfig = HttpBridgeConfig> extends AbstractModule<TConfig> implements BridgeModule {
|
|
18
11
|
private axios;
|
|
12
|
+
private remoteQueries;
|
|
13
|
+
private remoteResolver;
|
|
19
14
|
protected constructor(params: XyoHttpBridgeParams<TConfig>);
|
|
20
15
|
get nodeUri(): string;
|
|
16
|
+
get queries(): string[];
|
|
21
17
|
get targetAddress(): string | undefined;
|
|
22
|
-
|
|
23
|
-
static create(params: XyoHttpBridgeParams): Promise<XyoHttpBridge>;
|
|
18
|
+
static create(params: XyoHttpBridgeParams): Promise<HttpBridge>;
|
|
24
19
|
connect(): Promisable<boolean>;
|
|
25
20
|
disconnect(): Promisable<boolean>;
|
|
21
|
+
discover(): Promise<(import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & {
|
|
22
|
+
schema: string;
|
|
23
|
+
})[]>;
|
|
26
24
|
query<T extends XyoQueryBoundWitness = XyoQueryBoundWitness>(query: T, payloads?: XyoPayload[]): Promise<ModuleQueryResult>;
|
|
25
|
+
resolve(filter?: ModuleFilter): Promise<import("@xyo-network/module").Module<import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & {
|
|
26
|
+
name?: string | undefined;
|
|
27
|
+
security?: {
|
|
28
|
+
allowed?: Record<string, (string | import("@xyo-network/module").CosigningAddressSet)[]> | undefined;
|
|
29
|
+
disallowed?: Record<string, string[]> | undefined;
|
|
30
|
+
} | undefined;
|
|
31
|
+
} & {
|
|
32
|
+
schema: string;
|
|
33
|
+
}>[]>;
|
|
27
34
|
protected forward(query: XyoQuery, payloads?: XyoPayload[]): Promise<ModuleQueryResult>;
|
|
28
35
|
}
|
|
29
|
-
export declare class XyoHttpBridge<TConfig extends HttpBridgeConfig = HttpBridgeConfig> extends HttpBridge<TConfig> {
|
|
30
|
-
}
|
|
31
36
|
//# sourceMappingURL=HttpBridge.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpBridge.d.ts","sourceRoot":"","sources":["../../src/HttpBridge.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"HttpBridge.d.ts","sourceRoot":"","sources":["../../src/HttpBridge.ts"],"names":[],"mappings":"AAGA,OAAO,EAAc,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC1D,OAAO,EACL,cAAc,EAGd,YAAY,EACZ,YAAY,EACZ,iBAAiB,EAKjB,QAAQ,EACR,oBAAoB,EACrB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA;AAEvD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAIjD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAIrD,MAAM,WAAW,mBAAmB,CAAC,OAAO,SAAS,gBAAgB,GAAG,gBAAgB,CAAE,SAAQ,YAAY,CAAC,OAAO,CAAC;IACrH,KAAK,CAAC,EAAE,SAAS,CAAA;CAClB;AAED,qBAAa,UAAU,CAAC,OAAO,SAAS,gBAAgB,GAAG,gBAAgB,CAAE,SAAQ,cAAc,CAAC,OAAO,CAAE,YAAW,YAAY;IAClI,OAAO,CAAC,KAAK,CAAW;IACxB,OAAO,CAAC,aAAa,CAAe;IACpC,OAAO,CAAC,cAAc,CAAgB;IAEtC,SAAS,aAAa,MAAM,EAAE,mBAAmB,CAAC,OAAO,CAAC;IAM1D,IAAW,OAAO,WAEjB;IAED,IAAoB,OAAO,aAE1B;IAED,IAAW,aAAa,uBAEvB;WAEqB,MAAM,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,UAAU,CAAC;IAiB9E,OAAO,IAAI,UAAU,CAAC,OAAO,CAAC;IAI9B,UAAU,IAAI,UAAU,CAAC,OAAO,CAAC;IAIlB,QAAQ;;;IAKR,KAAK,CAAC,CAAC,SAAS,oBAAoB,GAAG,oBAAoB,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,CAAC,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC;IA6B3H,OAAO,CAAC,MAAM,CAAC,EAAE,YAAY;;;;;;;;;cAI5B,OAAO,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,GAAE,UAAU,EAAO,GAAG,OAAO,CAAC,iBAAiB,CAAC;CAYlG"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { XyoPayload } from '@xyo-network/payload-model';
|
|
2
|
+
import { BridgeConfig } from './Config';
|
|
3
|
+
export type HttpBridgeConfigSchema = 'network.xyo.bridge.http.config';
|
|
4
|
+
export declare const HttpBridgeConfigSchema: HttpBridgeConfigSchema;
|
|
5
|
+
export type HttpBridgeConfig<TConfig extends XyoPayload = XyoPayload> = BridgeConfig<{
|
|
6
|
+
nodeUri: string;
|
|
7
|
+
schema: HttpBridgeConfigSchema;
|
|
8
|
+
targetAddress?: string;
|
|
9
|
+
} & TConfig>;
|
|
10
|
+
//# sourceMappingURL=HttpBridgeConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpBridgeConfig.d.ts","sourceRoot":"","sources":["../../src/HttpBridgeConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA;AAEvD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAEvC,MAAM,MAAM,sBAAsB,GAAG,gCAAgC,CAAA;AACrE,eAAO,MAAM,sBAAsB,EAAE,sBAAyD,CAAA;AAE9F,MAAM,MAAM,gBAAgB,CAAC,OAAO,SAAS,UAAU,GAAG,UAAU,IAAI,YAAY,CAClF;IACE,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,sBAAsB,CAAA;IAC9B,aAAa,CAAC,EAAE,MAAM,CAAA;CACvB,GAAG,OAAO,CACZ,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AbstractModule, CompositeModuleResolver } from '@xyo-network/module';
|
|
2
|
+
import { Module, ModuleFilter } from '@xyo-network/module-model';
|
|
3
|
+
import { HttpBridge } from './HttpBridge';
|
|
4
|
+
export declare class RemoteModuleResolver extends CompositeModuleResolver {
|
|
5
|
+
protected readonly bridge: HttpBridge;
|
|
6
|
+
private resolvedModules;
|
|
7
|
+
constructor(bridge: HttpBridge);
|
|
8
|
+
get isModuleResolver(): boolean;
|
|
9
|
+
add(module: Module, name?: string | undefined): this;
|
|
10
|
+
add(module: Module[], name?: string[] | undefined): this;
|
|
11
|
+
add(module: Module | Module[], name?: string | string[] | undefined): this;
|
|
12
|
+
remove(name: string | string[]): this;
|
|
13
|
+
remove(address: string | string[]): this;
|
|
14
|
+
resolve(filter?: ModuleFilter): Promise<AbstractModule[]>;
|
|
15
|
+
private filterLocalModules;
|
|
16
|
+
private getRemoteAddresses;
|
|
17
|
+
private resolveByAddress;
|
|
18
|
+
private resolveByName;
|
|
19
|
+
private resolveRemoteModules;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=RemoteModuleResolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RemoteModuleResolver.d.ts","sourceRoot":"","sources":["../../src/RemoteModuleResolver.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,uBAAuB,EAAiB,MAAM,qBAAqB,CAAA;AAC5F,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAIhE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAazC,qBAAa,oBAAqB,SAAQ,uBAAuB;IAKnD,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,UAAU;IAJjD,OAAO,CAAC,eAAe,CAAiC;gBAIzB,MAAM,EAAE,UAAU;IAIjD,IAAW,gBAAgB,IAAI,OAAO,CAErC;IAED,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;IACpD,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,GAAG,IAAI;IACxD,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,GAAG,IAAI;IAK1E,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI;IACrC,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI;IAKlC,OAAO,CAAC,MAAM,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAK/D,OAAO,CAAC,kBAAkB;YAQZ,kBAAkB;YAelB,gBAAgB;YAUhB,aAAa;YAWb,oBAAoB;CAOnC"}
|
package/package.json
CHANGED
|
@@ -11,13 +11,17 @@
|
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@xylabs/assert": "^2.7.1",
|
|
14
|
-
"@xyo-network/account": "^2.46.
|
|
15
|
-
"@xyo-network/
|
|
16
|
-
"@xyo-network/
|
|
17
|
-
"@xyo-network/
|
|
18
|
-
"@xyo-network/
|
|
19
|
-
"@xyo-network/
|
|
20
|
-
"@xyo-network/
|
|
14
|
+
"@xyo-network/account": "^2.46.3",
|
|
15
|
+
"@xyo-network/address-payload-plugin": "^2.46.3",
|
|
16
|
+
"@xyo-network/api-models": "^2.46.3",
|
|
17
|
+
"@xyo-network/axios": "^2.46.3",
|
|
18
|
+
"@xyo-network/module": "^2.46.3",
|
|
19
|
+
"@xyo-network/module-model": "^2.46.3",
|
|
20
|
+
"@xyo-network/payload-model": "^2.46.3",
|
|
21
|
+
"@xyo-network/payload-wrapper": "^2.46.3",
|
|
22
|
+
"@xyo-network/promise": "^2.46.3",
|
|
23
|
+
"@xyo-network/query-payload-plugin": "^2.46.3",
|
|
24
|
+
"lodash": "^4.17.21"
|
|
21
25
|
},
|
|
22
26
|
"devDependencies": {
|
|
23
27
|
"@xylabs/ts-scripts-yarn3": "^2.14.15",
|
|
@@ -57,5 +61,5 @@
|
|
|
57
61
|
},
|
|
58
62
|
"sideEffects": false,
|
|
59
63
|
"types": "dist/types/index.d.ts",
|
|
60
|
-
"version": "2.46.
|
|
64
|
+
"version": "2.46.3"
|
|
61
65
|
}
|
package/src/Config.ts
CHANGED
|
@@ -4,9 +4,4 @@ import { XyoPayload } from '@xyo-network/payload-model'
|
|
|
4
4
|
export type XyoBridgeConfigSchema = 'network.xyo.bridge.config'
|
|
5
5
|
export const XyoBridgeConfigSchema: XyoBridgeConfigSchema = 'network.xyo.bridge.config'
|
|
6
6
|
|
|
7
|
-
export type BridgeConfig<TConfig extends XyoPayload = XyoPayload> = ModuleConfig<
|
|
8
|
-
{
|
|
9
|
-
nodeUri: string
|
|
10
|
-
targetAddress?: string
|
|
11
|
-
} & TConfig
|
|
12
|
-
>
|
|
7
|
+
export type BridgeConfig<TConfig extends XyoPayload = XyoPayload> = ModuleConfig<TConfig>
|
package/src/HttpBridge.ts
CHANGED
|
@@ -1,57 +1,74 @@
|
|
|
1
1
|
import { assertEx } from '@xylabs/assert'
|
|
2
2
|
import { Account } from '@xyo-network/account'
|
|
3
|
-
import {
|
|
3
|
+
import { XyoApiEnvelope } from '@xyo-network/api-models'
|
|
4
|
+
import { AxiosError, AxiosJson } from '@xyo-network/axios'
|
|
4
5
|
import {
|
|
5
6
|
AbstractModule,
|
|
7
|
+
ModuleDiscoverQuery,
|
|
8
|
+
ModuleDiscoverQuerySchema,
|
|
9
|
+
ModuleFilter,
|
|
6
10
|
ModuleParams,
|
|
7
11
|
ModuleQueryResult,
|
|
12
|
+
ModuleResolver,
|
|
13
|
+
ModuleWrapper,
|
|
8
14
|
QueryBoundWitnessWrapper,
|
|
9
15
|
XyoErrorBuilder,
|
|
10
16
|
XyoQuery,
|
|
11
17
|
XyoQueryBoundWitness,
|
|
12
18
|
} from '@xyo-network/module'
|
|
13
19
|
import { XyoPayload } from '@xyo-network/payload-model'
|
|
20
|
+
import { PayloadWrapper } from '@xyo-network/payload-wrapper'
|
|
14
21
|
import { Promisable } from '@xyo-network/promise'
|
|
22
|
+
import { QueryPayload, QuerySchema } from '@xyo-network/query-payload-plugin'
|
|
23
|
+
import compact from 'lodash/compact'
|
|
15
24
|
|
|
16
25
|
import { BridgeModule } from './Bridge'
|
|
17
|
-
import {
|
|
26
|
+
import { HttpBridgeConfig } from './HttpBridgeConfig'
|
|
18
27
|
import { XyoBridgeConnectQuerySchema, XyoBridgeDisconnectQuerySchema, XyoBridgeQuery } from './Queries'
|
|
19
|
-
|
|
20
|
-
export type HttpBridgeConfigSchema = 'network.xyo.bridge.http.config'
|
|
21
|
-
export const HttpBridgeConfigSchema: HttpBridgeConfigSchema = 'network.xyo.bridge.http.config'
|
|
22
|
-
|
|
23
|
-
export type HttpBridgeConfig = BridgeConfig<{
|
|
24
|
-
axios?: RawAxiosJsonRequestConfig
|
|
25
|
-
headers?: AxiosRequestHeaders
|
|
26
|
-
schema: HttpBridgeConfigSchema
|
|
27
|
-
}>
|
|
28
|
+
import { RemoteModuleResolver } from './RemoteModuleResolver'
|
|
28
29
|
|
|
29
30
|
export interface XyoHttpBridgeParams<TConfig extends HttpBridgeConfig = HttpBridgeConfig> extends ModuleParams<TConfig> {
|
|
30
|
-
axios
|
|
31
|
+
axios?: AxiosJson
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
export class HttpBridge<TConfig extends HttpBridgeConfig = HttpBridgeConfig> extends AbstractModule<TConfig> implements BridgeModule {
|
|
34
35
|
private axios: AxiosJson
|
|
36
|
+
private remoteQueries: string[] = []
|
|
37
|
+
private remoteResolver: ModuleResolver
|
|
35
38
|
|
|
36
39
|
protected constructor(params: XyoHttpBridgeParams<TConfig>) {
|
|
37
40
|
super(params)
|
|
38
|
-
this.axios = new AxiosJson(
|
|
41
|
+
this.axios = params.axios ?? new AxiosJson()
|
|
42
|
+
this.remoteResolver = new RemoteModuleResolver(this)
|
|
39
43
|
}
|
|
40
44
|
|
|
41
45
|
public get nodeUri() {
|
|
42
46
|
return assertEx(this.config?.nodeUri, 'Missing nodeUri')
|
|
43
47
|
}
|
|
44
48
|
|
|
45
|
-
public get
|
|
46
|
-
return this.
|
|
49
|
+
public override get queries() {
|
|
50
|
+
return [...super.queries, ...this.remoteQueries]
|
|
47
51
|
}
|
|
48
52
|
|
|
49
|
-
public get
|
|
50
|
-
return this.targetAddress
|
|
53
|
+
public get targetAddress() {
|
|
54
|
+
return this.config?.targetAddress
|
|
51
55
|
}
|
|
52
56
|
|
|
53
|
-
static override async create(params: XyoHttpBridgeParams): Promise<
|
|
54
|
-
|
|
57
|
+
static override async create(params: XyoHttpBridgeParams): Promise<HttpBridge> {
|
|
58
|
+
const result = (await super.create(params)) as HttpBridge
|
|
59
|
+
const moduleWrapper = ModuleWrapper.wrap(result)
|
|
60
|
+
const discover = await moduleWrapper.discover()
|
|
61
|
+
result.remoteQueries = compact(
|
|
62
|
+
discover.map((payload) => {
|
|
63
|
+
if (payload.schema === QuerySchema) {
|
|
64
|
+
const schemaPayload = payload as QueryPayload
|
|
65
|
+
return schemaPayload.query
|
|
66
|
+
} else {
|
|
67
|
+
return null
|
|
68
|
+
}
|
|
69
|
+
}),
|
|
70
|
+
)
|
|
71
|
+
return result
|
|
55
72
|
}
|
|
56
73
|
|
|
57
74
|
connect(): Promisable<boolean> {
|
|
@@ -62,6 +79,11 @@ export class HttpBridge<TConfig extends HttpBridgeConfig = HttpBridgeConfig> ext
|
|
|
62
79
|
return true
|
|
63
80
|
}
|
|
64
81
|
|
|
82
|
+
override async discover() {
|
|
83
|
+
const queryPayload = PayloadWrapper.parse<ModuleDiscoverQuery>({ schema: ModuleDiscoverQuerySchema })
|
|
84
|
+
return (await this.forward(queryPayload))[1]
|
|
85
|
+
}
|
|
86
|
+
|
|
65
87
|
override async query<T extends XyoQueryBoundWitness = XyoQueryBoundWitness>(query: T, payloads?: XyoPayload[]): Promise<ModuleQueryResult> {
|
|
66
88
|
const wrapper = QueryBoundWitnessWrapper.parseQuery<XyoBridgeQuery>(query, payloads)
|
|
67
89
|
const typedQuery = wrapper.query.payload
|
|
@@ -79,23 +101,27 @@ export class HttpBridge<TConfig extends HttpBridgeConfig = HttpBridgeConfig> ext
|
|
|
79
101
|
}
|
|
80
102
|
default:
|
|
81
103
|
if (super.queries.find((schema) => schema === typedQuery.schema)) {
|
|
82
|
-
return super.query(query, payloads)
|
|
104
|
+
return await super.query(query, payloads)
|
|
83
105
|
} else {
|
|
84
|
-
return this.forward(query, payloads)
|
|
106
|
+
return await this.forward(query, payloads)
|
|
85
107
|
}
|
|
86
108
|
}
|
|
87
109
|
} catch (ex) {
|
|
88
110
|
const error = ex as Error
|
|
89
111
|
resultPayloads.push(new XyoErrorBuilder([wrapper.hash], error.message).build())
|
|
90
112
|
}
|
|
91
|
-
return this.bindResult(resultPayloads, queryAccount)
|
|
113
|
+
return await this.bindResult(resultPayloads, queryAccount)
|
|
92
114
|
}
|
|
93
115
|
|
|
94
|
-
|
|
116
|
+
override async resolve(filter?: ModuleFilter) {
|
|
117
|
+
return [...(await super.resolve(filter)), ...(await this.remoteResolver.resolve(filter))]
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
protected async forward(query: XyoQuery, payloads: XyoPayload[] = []): Promise<ModuleQueryResult> {
|
|
95
121
|
try {
|
|
96
|
-
const boundQuery = this.bindQuery(query, payloads)
|
|
97
|
-
const result = await this.axios.post<ModuleQueryResult
|
|
98
|
-
return result.data
|
|
122
|
+
const boundQuery = await this.bindQuery(query, payloads)
|
|
123
|
+
const result = await this.axios.post<XyoApiEnvelope<ModuleQueryResult>>(`${this.nodeUri}/address/${this.targetAddress}`, boundQuery)
|
|
124
|
+
return result.data.data
|
|
99
125
|
} catch (ex) {
|
|
100
126
|
const error = ex as AxiosError
|
|
101
127
|
console.log(`Error Status: ${error.status}`)
|
|
@@ -104,5 +130,3 @@ export class HttpBridge<TConfig extends HttpBridgeConfig = HttpBridgeConfig> ext
|
|
|
104
130
|
}
|
|
105
131
|
}
|
|
106
132
|
}
|
|
107
|
-
|
|
108
|
-
export class XyoHttpBridge<TConfig extends HttpBridgeConfig = HttpBridgeConfig> extends HttpBridge<TConfig> {}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { XyoPayload } from '@xyo-network/payload-model'
|
|
2
|
+
|
|
3
|
+
import { BridgeConfig } from './Config'
|
|
4
|
+
|
|
5
|
+
export type HttpBridgeConfigSchema = 'network.xyo.bridge.http.config'
|
|
6
|
+
export const HttpBridgeConfigSchema: HttpBridgeConfigSchema = 'network.xyo.bridge.http.config'
|
|
7
|
+
|
|
8
|
+
export type HttpBridgeConfig<TConfig extends XyoPayload = XyoPayload> = BridgeConfig<
|
|
9
|
+
{
|
|
10
|
+
nodeUri: string
|
|
11
|
+
schema: HttpBridgeConfigSchema
|
|
12
|
+
targetAddress?: string
|
|
13
|
+
} & TConfig
|
|
14
|
+
>
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { assertEx } from '@xylabs/assert'
|
|
2
|
+
import { AddressPayload, AddressSchema } from '@xyo-network/address-payload-plugin'
|
|
3
|
+
import { AbstractModule, CompositeModuleResolver, ModuleWrapper } from '@xyo-network/module'
|
|
4
|
+
import { Module, ModuleFilter } from '@xyo-network/module-model'
|
|
5
|
+
import compact from 'lodash/compact'
|
|
6
|
+
import flatten from 'lodash/flatten'
|
|
7
|
+
|
|
8
|
+
import { HttpBridge } from './HttpBridge'
|
|
9
|
+
import { HttpBridgeConfigSchema } from './HttpBridgeConfig'
|
|
10
|
+
|
|
11
|
+
interface LocalModuleFilter {
|
|
12
|
+
config?: string[]
|
|
13
|
+
query?: string[][]
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface RemoteModuleFilter {
|
|
17
|
+
address?: string[]
|
|
18
|
+
name?: string[]
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class RemoteModuleResolver extends CompositeModuleResolver {
|
|
22
|
+
private resolvedModules: Record<string, HttpBridge> = {}
|
|
23
|
+
|
|
24
|
+
// TODO: Allow optional ctor param for supplying address for nested Nodes
|
|
25
|
+
// protected readonly address?: string,
|
|
26
|
+
constructor(protected readonly bridge: HttpBridge) {
|
|
27
|
+
super()
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public get isModuleResolver(): boolean {
|
|
31
|
+
return true
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
add(module: Module, name?: string | undefined): this
|
|
35
|
+
add(module: Module[], name?: string[] | undefined): this
|
|
36
|
+
add(module: Module | Module[], name?: string | string[] | undefined): this
|
|
37
|
+
add(_module: unknown, _name?: unknown): this {
|
|
38
|
+
throw new Error('Method not implemented.')
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
remove(name: string | string[]): this
|
|
42
|
+
remove(address: string | string[]): this
|
|
43
|
+
remove(_address: unknown): this {
|
|
44
|
+
throw new Error('Method not implemented.')
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async resolve(filter?: ModuleFilter): Promise<AbstractModule[]> {
|
|
48
|
+
const mods = await Promise.all(flatten(await this.resolveRemoteModules(filter)))
|
|
49
|
+
return this.filterLocalModules(mods, filter)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private filterLocalModules(mods: AbstractModule[], filter?: LocalModuleFilter): AbstractModule[] {
|
|
53
|
+
// TODO: Handle filter?.query
|
|
54
|
+
if (filter?.query) throw new Error('Filtering by query not yet implemented by this resolver')
|
|
55
|
+
const config = filter?.config
|
|
56
|
+
const filtered = config?.length ? mods.filter((mod) => config.includes(mod.config.schema)) : mods
|
|
57
|
+
return filtered
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
private async getRemoteAddresses() {
|
|
61
|
+
const nodeWrapper = assertEx(ModuleWrapper.wrap(this.bridge), 'nodeUri can not be wrapped')
|
|
62
|
+
const discover = await nodeWrapper.discover()
|
|
63
|
+
return compact(
|
|
64
|
+
discover.map((payload) => {
|
|
65
|
+
if (payload.schema === AddressSchema) {
|
|
66
|
+
const schemaPayload = payload as AddressPayload
|
|
67
|
+
return schemaPayload.address
|
|
68
|
+
} else {
|
|
69
|
+
return null
|
|
70
|
+
}
|
|
71
|
+
}),
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
private async resolveByAddress(targetAddress: string): Promise<HttpBridge> {
|
|
76
|
+
const cached = this.resolvedModules[targetAddress]
|
|
77
|
+
if (cached) return cached
|
|
78
|
+
const mod = await HttpBridge.create({
|
|
79
|
+
config: { nodeUri: this.bridge.nodeUri, schema: HttpBridgeConfigSchema, targetAddress },
|
|
80
|
+
})
|
|
81
|
+
this.resolvedModules[targetAddress] = mod
|
|
82
|
+
return mod
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
private async resolveByName(name: string): Promise<HttpBridge> {
|
|
86
|
+
const cached = this.resolvedModules[name]
|
|
87
|
+
if (cached) return cached
|
|
88
|
+
const mod = await HttpBridge.create({
|
|
89
|
+
config: { name, nodeUri: this.bridge.nodeUri, schema: HttpBridgeConfigSchema },
|
|
90
|
+
})
|
|
91
|
+
this.resolvedModules[name] = mod
|
|
92
|
+
this.resolvedModules[mod.address] = mod
|
|
93
|
+
return mod
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
private async resolveRemoteModules(filter?: RemoteModuleFilter): Promise<HttpBridge[]> {
|
|
97
|
+
const addresses = filter ? filter?.address : await this.getRemoteAddresses()
|
|
98
|
+
const names = filter?.name
|
|
99
|
+
const byAddress = await Promise.all(addresses?.map((address) => this.resolveByAddress(address)) ?? [])
|
|
100
|
+
const byName = await Promise.all(names?.map((name) => this.resolveByName(name)) ?? [])
|
|
101
|
+
return [...byAddress, ...byName]
|
|
102
|
+
}
|
|
103
|
+
}
|