@xyo-network/bridge-module-resolver 2.47.1
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/LICENSE +165 -0
- package/README.md +13 -0
- package/dist/cjs/ModuleResolver.js +72 -0
- package/dist/cjs/ModuleResolver.js.map +1 -0
- package/dist/cjs/ProxyModule.js +41 -0
- package/dist/cjs/ProxyModule.js.map +1 -0
- package/dist/cjs/index.js +6 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/docs.json +5715 -0
- package/dist/esm/ModuleResolver.js +61 -0
- package/dist/esm/ModuleResolver.js.map +1 -0
- package/dist/esm/ProxyModule.js +32 -0
- package/dist/esm/ProxyModule.js.map +1 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/types/ModuleResolver.d.ts +21 -0
- package/dist/types/ModuleResolver.d.ts.map +1 -0
- package/dist/types/ProxyModule.d.ts +25 -0
- package/dist/types/ProxyModule.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -0
- package/package.json +59 -0
- package/src/ModuleResolver.ts +75 -0
- package/src/ProxyModule.ts +36 -0
- package/src/index.ts +2 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { AddressSchema } from '@xyo-network/address-payload-plugin';
|
|
2
|
+
import { CompositeModuleResolver } from '@xyo-network/module';
|
|
3
|
+
import compact from 'lodash/compact';
|
|
4
|
+
import flatten from 'lodash/flatten';
|
|
5
|
+
import { ProxyModule } from './ProxyModule';
|
|
6
|
+
export class BridgeModuleResolver extends CompositeModuleResolver {
|
|
7
|
+
bridge;
|
|
8
|
+
resolvedModules = {};
|
|
9
|
+
// TODO: Allow optional ctor param for supplying address for nested Nodes
|
|
10
|
+
// protected readonly address?: string,
|
|
11
|
+
constructor(bridge) {
|
|
12
|
+
super();
|
|
13
|
+
this.bridge = bridge;
|
|
14
|
+
}
|
|
15
|
+
get isModuleResolver() {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
add(_module, _name) {
|
|
19
|
+
throw new Error('Method not implemented.');
|
|
20
|
+
}
|
|
21
|
+
remove(_address) {
|
|
22
|
+
throw new Error('Method not implemented.');
|
|
23
|
+
}
|
|
24
|
+
async resolve(filter) {
|
|
25
|
+
return await Promise.all(flatten(await this.resolveRemoteModules(filter)));
|
|
26
|
+
}
|
|
27
|
+
async getRemoteAddresses() {
|
|
28
|
+
const discover = await this.bridge.targetDiscover();
|
|
29
|
+
return compact(discover.map((payload) => {
|
|
30
|
+
if (payload.schema === AddressSchema) {
|
|
31
|
+
const schemaPayload = payload;
|
|
32
|
+
return schemaPayload.address;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
resolveByAddress(targetAddress) {
|
|
40
|
+
const cached = this.resolvedModules[targetAddress];
|
|
41
|
+
if (cached)
|
|
42
|
+
return cached;
|
|
43
|
+
const mod = new ProxyModule(this.bridge, targetAddress);
|
|
44
|
+
this.resolvedModules[targetAddress] = mod;
|
|
45
|
+
return mod;
|
|
46
|
+
}
|
|
47
|
+
resolveByName(name) {
|
|
48
|
+
const cached = this.resolvedModules[name];
|
|
49
|
+
if (cached)
|
|
50
|
+
return cached;
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
async resolveRemoteModules(filter) {
|
|
54
|
+
const addresses = filter ? filter?.address : await this.getRemoteAddresses();
|
|
55
|
+
const names = filter?.name;
|
|
56
|
+
const byAddress = compact(await Promise.all(addresses?.map((address) => this.resolveByAddress(address)) ?? []));
|
|
57
|
+
const byName = compact(await Promise.all(names?.map((name) => this.resolveByName(name)) ?? []));
|
|
58
|
+
return [...byAddress, ...byName];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=ModuleResolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Modu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 +1,32 @@
|
|
|
1
|
+
import { ModuleConfigSchema } from '@xyo-network/module';
|
|
2
|
+
export class ProxyModule {
|
|
3
|
+
bridge;
|
|
4
|
+
_address;
|
|
5
|
+
constructor(bridge, _address) {
|
|
6
|
+
this.bridge = bridge;
|
|
7
|
+
this._address = _address;
|
|
8
|
+
}
|
|
9
|
+
get address() {
|
|
10
|
+
return this._address;
|
|
11
|
+
}
|
|
12
|
+
get config() {
|
|
13
|
+
return { schema: ModuleConfigSchema };
|
|
14
|
+
}
|
|
15
|
+
get queries() {
|
|
16
|
+
return this.bridge.targetQueries(this.address);
|
|
17
|
+
}
|
|
18
|
+
get resolver() {
|
|
19
|
+
return this.bridge.targetResolver;
|
|
20
|
+
}
|
|
21
|
+
async query(query, payloads) {
|
|
22
|
+
return await this.bridge.targetQuery(this.address, query, payloads);
|
|
23
|
+
}
|
|
24
|
+
async queryable(query, payloads, queryConfig) {
|
|
25
|
+
return await this.bridge.targetQueryable(this.address, query, payloads, queryConfig);
|
|
26
|
+
}
|
|
27
|
+
/* Resolves a filter from the perspective of the module, including through the parent/gateway module */
|
|
28
|
+
async resolve(filter) {
|
|
29
|
+
return await this.bridge.targetResolve(this.address, filter);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=ProxyModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProxyModule.js","sourceRoot":"","sources":["../../src/ProxyModule.ts"],"names":[],"mappings":"AACA,OAAO,EAAwB,kBAAkB,EAAyD,MAAM,qBAAqB,CAAA;AAGrI,MAAM,OAAO,WAAW;IACS;IAAyC;IAAxE,YAA+B,MAAoB,EAAqB,QAAgB;QAAzD,WAAM,GAAN,MAAM,CAAc;QAAqB,aAAQ,GAAR,QAAQ,CAAQ;IAAG,CAAC;IAE5F,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAA;IACtB,CAAC;IAED,IAAI,MAAM;QACR,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,CAAA;IACvC,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAChD,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,MAAM,CAAC,cAAc,CAAA;IACnC,CAAC;IAED,KAAK,CAAC,KAAK,CAAwD,KAAQ,EAAE,QAAuB;QAClG,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAA;IACrE,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,KAA2B,EAAE,QAAuB,EAAE,WAA0B;QAC9F,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAA;IACtF,CAAC;IAED,uGAAuG;IACvG,KAAK,CAAC,OAAO,CAAC,MAAqB;QACjC,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;IAC9D,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,eAAe,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { BridgeModule } from '@xyo-network/bridge-model';
|
|
2
|
+
import { CompositeModuleResolver } from '@xyo-network/module';
|
|
3
|
+
import { Module, ModuleFilter } from '@xyo-network/module-model';
|
|
4
|
+
import { ProxyModule } from './ProxyModule';
|
|
5
|
+
export declare class BridgeModuleResolver extends CompositeModuleResolver {
|
|
6
|
+
protected readonly bridge: BridgeModule;
|
|
7
|
+
private resolvedModules;
|
|
8
|
+
constructor(bridge: BridgeModule);
|
|
9
|
+
get isModuleResolver(): boolean;
|
|
10
|
+
add(module: Module, name?: string | undefined): this;
|
|
11
|
+
add(module: Module[], name?: string[] | undefined): this;
|
|
12
|
+
add(module: Module | Module[], name?: string | string[] | undefined): this;
|
|
13
|
+
remove(name: string | string[]): this;
|
|
14
|
+
remove(address: string | string[]): this;
|
|
15
|
+
resolve(filter?: ModuleFilter): Promise<ProxyModule[]>;
|
|
16
|
+
private getRemoteAddresses;
|
|
17
|
+
private resolveByAddress;
|
|
18
|
+
private resolveByName;
|
|
19
|
+
private resolveRemoteModules;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=ModuleResolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ModuleResolver.d.ts","sourceRoot":"","sources":["../../src/ModuleResolver.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAA;AAC7D,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAIhE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAE3C,qBAAa,oBAAqB,SAAQ,uBAAuB;IAKnD,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,YAAY;IAJnD,OAAO,CAAC,eAAe,CAAkC;gBAI1B,MAAM,EAAE,YAAY;IAInD,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,WAAW,EAAE,CAAC;YAI9C,kBAAkB;IAchC,OAAO,CAAC,gBAAgB;IAQxB,OAAO,CAAC,aAAa;YAMP,oBAAoB;CAOnC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { BridgeModule } from '@xyo-network/bridge-model';
|
|
2
|
+
import { Module, ModuleConfig, ModuleFilter, ModuleQueryResult, XyoQueryBoundWitness } from '@xyo-network/module';
|
|
3
|
+
import { XyoPayload } from '@xyo-network/payload-model';
|
|
4
|
+
export declare class ProxyModule implements Module {
|
|
5
|
+
protected readonly bridge: BridgeModule;
|
|
6
|
+
protected readonly _address: string;
|
|
7
|
+
constructor(bridge: BridgeModule, _address: string);
|
|
8
|
+
get address(): string;
|
|
9
|
+
get config(): ModuleConfig;
|
|
10
|
+
get queries(): string[];
|
|
11
|
+
get resolver(): import("@xyo-network/module").ModuleResolver<Module<import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & {
|
|
12
|
+
name?: string | undefined;
|
|
13
|
+
security?: {
|
|
14
|
+
allowAnonymous?: boolean | undefined;
|
|
15
|
+
allowed?: Record<string, (string | import("@xyo-network/module").CosigningAddressSet)[]> | undefined;
|
|
16
|
+
disallowed?: Record<string, string[]> | undefined;
|
|
17
|
+
} | undefined;
|
|
18
|
+
} & {
|
|
19
|
+
schema: string;
|
|
20
|
+
}>>;
|
|
21
|
+
query<T extends XyoQueryBoundWitness = XyoQueryBoundWitness>(query: T, payloads?: XyoPayload[]): Promise<ModuleQueryResult>;
|
|
22
|
+
queryable(query: XyoQueryBoundWitness, payloads?: XyoPayload[], queryConfig?: ModuleConfig): Promise<boolean>;
|
|
23
|
+
resolve(filter?: ModuleFilter): Promise<Module[]>;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=ProxyModule.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProxyModule.d.ts","sourceRoot":"","sources":["../../src/ProxyModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,EAAE,MAAM,EAAE,YAAY,EAAsB,YAAY,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AACrI,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA;AAEvD,qBAAa,WAAY,YAAW,MAAM;IAC5B,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,YAAY;IAAE,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM;gBAAzD,MAAM,EAAE,YAAY,EAAqB,QAAQ,EAAE,MAAM;IAExF,IAAI,OAAO,WAEV;IAED,IAAI,MAAM,IAAI,YAAY,CAEzB;IAED,IAAI,OAAO,aAEV;IAED,IAAI,QAAQ;;;;;;;;;QAEX;IAEK,KAAK,CAAC,CAAC,SAAS,oBAAoB,GAAG,oBAAoB,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,CAAC,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAI3H,SAAS,CAAC,KAAK,EAAE,oBAAoB,EAAE,QAAQ,CAAC,EAAE,UAAU,EAAE,EAAE,WAAW,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC;IAK7G,OAAO,CAAC,MAAM,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAGxD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,eAAe,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xyo-network/bridge-module-resolver",
|
|
3
|
+
"author": {
|
|
4
|
+
"email": "support@xyo.network",
|
|
5
|
+
"name": "XYO Development Team",
|
|
6
|
+
"url": "https://xyo.network"
|
|
7
|
+
},
|
|
8
|
+
"bugs": {
|
|
9
|
+
"email": "support@xyo.network",
|
|
10
|
+
"url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@xyo-network/address-payload-plugin": "^2.47.1",
|
|
14
|
+
"@xyo-network/bridge-model": "^2.47.1",
|
|
15
|
+
"@xyo-network/module": "^2.47.1",
|
|
16
|
+
"@xyo-network/module-model": "^2.47.1",
|
|
17
|
+
"@xyo-network/payload-model": "^2.47.1",
|
|
18
|
+
"lodash": "^4.17.21"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@xylabs/ts-scripts-yarn3": "^2.14.15",
|
|
22
|
+
"@xylabs/tsconfig": "^2.14.15",
|
|
23
|
+
"typescript": "^4.9.5"
|
|
24
|
+
},
|
|
25
|
+
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
26
|
+
"browser": "dist/esm/index.js",
|
|
27
|
+
"docs": "dist/docs.json",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"node": {
|
|
31
|
+
"import": "./dist/esm/index.js",
|
|
32
|
+
"require": "./dist/cjs/index.js"
|
|
33
|
+
},
|
|
34
|
+
"browser": {
|
|
35
|
+
"import": "./dist/esm/index.js",
|
|
36
|
+
"require": "./dist/cjs/index.js"
|
|
37
|
+
},
|
|
38
|
+
"default": "./dist/esm/index.js"
|
|
39
|
+
},
|
|
40
|
+
"./dist/docs.json": {
|
|
41
|
+
"default": "./dist/docs.json"
|
|
42
|
+
},
|
|
43
|
+
"./package.json": "./package.json"
|
|
44
|
+
},
|
|
45
|
+
"main": "dist/cjs/index.js",
|
|
46
|
+
"module": "dist/esm/index.js",
|
|
47
|
+
"homepage": "https://xyo.network",
|
|
48
|
+
"license": "LGPL-3.0",
|
|
49
|
+
"publishConfig": {
|
|
50
|
+
"access": "public"
|
|
51
|
+
},
|
|
52
|
+
"repository": {
|
|
53
|
+
"type": "git",
|
|
54
|
+
"url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
|
|
55
|
+
},
|
|
56
|
+
"sideEffects": false,
|
|
57
|
+
"types": "dist/types/index.d.ts",
|
|
58
|
+
"version": "2.47.1"
|
|
59
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { AddressPayload, AddressSchema } from '@xyo-network/address-payload-plugin'
|
|
2
|
+
import { BridgeModule } from '@xyo-network/bridge-model'
|
|
3
|
+
import { CompositeModuleResolver } 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 { ProxyModule } from './ProxyModule'
|
|
9
|
+
|
|
10
|
+
export class BridgeModuleResolver extends CompositeModuleResolver {
|
|
11
|
+
private resolvedModules: Record<string, ProxyModule> = {}
|
|
12
|
+
|
|
13
|
+
// TODO: Allow optional ctor param for supplying address for nested Nodes
|
|
14
|
+
// protected readonly address?: string,
|
|
15
|
+
constructor(protected readonly bridge: BridgeModule) {
|
|
16
|
+
super()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public get isModuleResolver(): boolean {
|
|
20
|
+
return true
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
add(module: Module, name?: string | undefined): this
|
|
24
|
+
add(module: Module[], name?: string[] | undefined): this
|
|
25
|
+
add(module: Module | Module[], name?: string | string[] | undefined): this
|
|
26
|
+
add(_module: unknown, _name?: unknown): this {
|
|
27
|
+
throw new Error('Method not implemented.')
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
remove(name: string | string[]): this
|
|
31
|
+
remove(address: string | string[]): this
|
|
32
|
+
remove(_address: unknown): this {
|
|
33
|
+
throw new Error('Method not implemented.')
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async resolve(filter?: ModuleFilter): Promise<ProxyModule[]> {
|
|
37
|
+
return await Promise.all(flatten(await this.resolveRemoteModules(filter)))
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
private async getRemoteAddresses() {
|
|
41
|
+
const discover = await this.bridge.targetDiscover()
|
|
42
|
+
return compact(
|
|
43
|
+
discover.map((payload) => {
|
|
44
|
+
if (payload.schema === AddressSchema) {
|
|
45
|
+
const schemaPayload = payload as AddressPayload
|
|
46
|
+
return schemaPayload.address
|
|
47
|
+
} else {
|
|
48
|
+
return null
|
|
49
|
+
}
|
|
50
|
+
}),
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
private resolveByAddress(targetAddress: string): ProxyModule | undefined {
|
|
55
|
+
const cached = this.resolvedModules[targetAddress]
|
|
56
|
+
if (cached) return cached
|
|
57
|
+
const mod = new ProxyModule(this.bridge, targetAddress)
|
|
58
|
+
this.resolvedModules[targetAddress] = mod
|
|
59
|
+
return mod
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
private resolveByName(name: string): ProxyModule | undefined {
|
|
63
|
+
const cached = this.resolvedModules[name]
|
|
64
|
+
if (cached) return cached
|
|
65
|
+
return undefined
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
private async resolveRemoteModules(filter?: ModuleFilter): Promise<ProxyModule[]> {
|
|
69
|
+
const addresses = filter ? filter?.address : await this.getRemoteAddresses()
|
|
70
|
+
const names = filter?.name
|
|
71
|
+
const byAddress = compact(await Promise.all(addresses?.map((address) => this.resolveByAddress(address)) ?? []))
|
|
72
|
+
const byName = compact(await Promise.all(names?.map((name) => this.resolveByName(name)) ?? []))
|
|
73
|
+
return [...byAddress, ...byName]
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { BridgeModule } from '@xyo-network/bridge-model'
|
|
2
|
+
import { Module, ModuleConfig, ModuleConfigSchema, ModuleFilter, ModuleQueryResult, XyoQueryBoundWitness } from '@xyo-network/module'
|
|
3
|
+
import { XyoPayload } from '@xyo-network/payload-model'
|
|
4
|
+
|
|
5
|
+
export class ProxyModule implements Module {
|
|
6
|
+
constructor(protected readonly bridge: BridgeModule, protected readonly _address: string) {}
|
|
7
|
+
|
|
8
|
+
get address() {
|
|
9
|
+
return this._address
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
get config(): ModuleConfig {
|
|
13
|
+
return { schema: ModuleConfigSchema }
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
get queries() {
|
|
17
|
+
return this.bridge.targetQueries(this.address)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
get resolver() {
|
|
21
|
+
return this.bridge.targetResolver
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async query<T extends XyoQueryBoundWitness = XyoQueryBoundWitness>(query: T, payloads?: XyoPayload[]): Promise<ModuleQueryResult> {
|
|
25
|
+
return await this.bridge.targetQuery(this.address, query, payloads)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async queryable(query: XyoQueryBoundWitness, payloads?: XyoPayload[], queryConfig?: ModuleConfig): Promise<boolean> {
|
|
29
|
+
return await this.bridge.targetQueryable(this.address, query, payloads, queryConfig)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/* Resolves a filter from the perspective of the module, including through the parent/gateway module */
|
|
33
|
+
async resolve(filter?: ModuleFilter): Promise<Module[]> {
|
|
34
|
+
return await this.bridge.targetResolve(this.address, filter)
|
|
35
|
+
}
|
|
36
|
+
}
|
package/src/index.ts
ADDED