@xyo-network/bridge 2.46.4 → 2.47.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.
Files changed (41) hide show
  1. package/dist/cjs/AbstractBridge.js +1 -7
  2. package/dist/cjs/AbstractBridge.js.map +1 -1
  3. package/dist/cjs/BridgeWrapper.js +32 -0
  4. package/dist/cjs/BridgeWrapper.js.map +1 -1
  5. package/dist/cjs/HttpBridge.js +53 -34
  6. package/dist/cjs/HttpBridge.js.map +1 -1
  7. package/dist/cjs/HttpProxyModule.js +39 -0
  8. package/dist/cjs/HttpProxyModule.js.map +1 -0
  9. package/dist/cjs/RemoteModuleResolver.js +15 -38
  10. package/dist/cjs/RemoteModuleResolver.js.map +1 -1
  11. package/dist/docs.json +15257 -9644
  12. package/dist/esm/AbstractBridge.js +2 -7
  13. package/dist/esm/AbstractBridge.js.map +1 -1
  14. package/dist/esm/BridgeWrapper.js +23 -1
  15. package/dist/esm/BridgeWrapper.js.map +1 -1
  16. package/dist/esm/HttpBridge.js +46 -30
  17. package/dist/esm/HttpBridge.js.map +1 -1
  18. package/dist/esm/HttpProxyModule.js +32 -0
  19. package/dist/esm/HttpProxyModule.js.map +1 -0
  20. package/dist/esm/RemoteModuleResolver.js +10 -29
  21. package/dist/esm/RemoteModuleResolver.js.map +1 -1
  22. package/dist/types/AbstractBridge.d.ts +6 -2
  23. package/dist/types/AbstractBridge.d.ts.map +1 -1
  24. package/dist/types/Bridge.d.ts +8 -2
  25. package/dist/types/Bridge.d.ts.map +1 -1
  26. package/dist/types/BridgeWrapper.d.ts +29 -3
  27. package/dist/types/BridgeWrapper.d.ts.map +1 -1
  28. package/dist/types/HttpBridge.d.ts +30 -10
  29. package/dist/types/HttpBridge.d.ts.map +1 -1
  30. package/dist/types/HttpProxyModule.d.ts +25 -0
  31. package/dist/types/HttpProxyModule.d.ts.map +1 -0
  32. package/dist/types/RemoteModuleResolver.d.ts +3 -3
  33. package/dist/types/RemoteModuleResolver.d.ts.map +1 -1
  34. package/package.json +11 -11
  35. package/src/AbstractBridge.ts +22 -7
  36. package/src/Bridge.ts +10 -2
  37. package/src/BridgeWrapper.ts +49 -3
  38. package/src/HttpBridge.ts +54 -30
  39. package/src/HttpProxyModule.ts +37 -0
  40. package/src/RemoteModuleResolver.ts +13 -41
  41. package/src/spec/HttpBridge.spec.ts +6 -2
package/package.json CHANGED
@@ -11,16 +11,16 @@
11
11
  },
12
12
  "dependencies": {
13
13
  "@xylabs/assert": "^2.7.1",
14
- "@xyo-network/account": "^2.46.4",
15
- "@xyo-network/address-payload-plugin": "^2.46.4",
16
- "@xyo-network/api-models": "^2.46.4",
17
- "@xyo-network/axios": "^2.46.4",
18
- "@xyo-network/module": "^2.46.4",
19
- "@xyo-network/module-model": "^2.46.4",
20
- "@xyo-network/payload-model": "^2.46.4",
21
- "@xyo-network/payload-wrapper": "^2.46.4",
22
- "@xyo-network/promise": "^2.46.4",
23
- "@xyo-network/query-payload-plugin": "^2.46.4",
14
+ "@xyo-network/account": "^2.47.0",
15
+ "@xyo-network/address-payload-plugin": "^2.47.0",
16
+ "@xyo-network/api-models": "^2.47.0",
17
+ "@xyo-network/axios": "^2.47.0",
18
+ "@xyo-network/module": "^2.47.0",
19
+ "@xyo-network/module-model": "^2.47.0",
20
+ "@xyo-network/payload-model": "^2.47.0",
21
+ "@xyo-network/payload-wrapper": "^2.47.0",
22
+ "@xyo-network/promise": "^2.47.0",
23
+ "@xyo-network/query-payload-plugin": "^2.47.0",
24
24
  "lodash": "^4.17.21"
25
25
  },
26
26
  "devDependencies": {
@@ -61,5 +61,5 @@
61
61
  },
62
62
  "sideEffects": false,
63
63
  "types": "dist/types/index.d.ts",
64
- "version": "2.46.4"
64
+ "version": "2.47.0"
65
65
  }
@@ -1,5 +1,16 @@
1
1
  import { Account } from '@xyo-network/account'
2
- import { AbstractModule, ModuleQueryResult, QueryBoundWitnessWrapper, XyoErrorBuilder, XyoQuery, XyoQueryBoundWitness } from '@xyo-network/module'
2
+ import {
3
+ AbstractModule,
4
+ Module,
5
+ ModuleConfig,
6
+ ModuleFilter,
7
+ ModuleQueryResult,
8
+ ModuleResolver,
9
+ QueryBoundWitnessWrapper,
10
+ XyoErrorBuilder,
11
+ XyoQuery,
12
+ XyoQueryBoundWitness,
13
+ } from '@xyo-network/module'
3
14
  import { XyoPayload } from '@xyo-network/payload-model'
4
15
  import { Promisable } from '@xyo-network/promise'
5
16
 
@@ -8,6 +19,8 @@ import { BridgeConfig } from './Config'
8
19
  import { XyoBridgeConnectQuerySchema, XyoBridgeDisconnectQuerySchema, XyoBridgeQuery } from './Queries'
9
20
 
10
21
  export abstract class AbstractBridge<TConfig extends BridgeConfig = BridgeConfig> extends AbstractModule<TConfig> implements BridgeModule {
22
+ abstract targetResolver: ModuleResolver
23
+
11
24
  override get queries(): string[] {
12
25
  return [XyoBridgeConnectQuerySchema, XyoBridgeDisconnectQuerySchema, ...super.queries]
13
26
  }
@@ -27,11 +40,7 @@ export abstract class AbstractBridge<TConfig extends BridgeConfig = BridgeConfig
27
40
  break
28
41
  }
29
42
  default:
30
- if (super.queries.includes(typedQuery.schema)) {
31
- return super.query(query, payloads)
32
- } else {
33
- return this.forward(typedQuery)
34
- }
43
+ return super.query(query, payloads)
35
44
  }
36
45
  } catch (ex) {
37
46
  const error = ex as Error
@@ -43,5 +52,11 @@ export abstract class AbstractBridge<TConfig extends BridgeConfig = BridgeConfig
43
52
  abstract connect(): Promisable<boolean>
44
53
  abstract disconnect(): Promisable<boolean>
45
54
 
46
- abstract forward(query: XyoQuery): Promise<ModuleQueryResult>
55
+ abstract targetConfig(address: string): Promisable<ModuleConfig>
56
+
57
+ abstract targetQuery(address: string, query: XyoQuery, payloads?: XyoPayload[]): Promisable<ModuleQueryResult>
58
+
59
+ abstract targetQueryable(address: string, query: XyoQueryBoundWitness, payloads?: XyoPayload[], queryConfig?: ModuleConfig): boolean
60
+
61
+ abstract targetResolve(address: string, filter?: ModuleFilter): Promisable<Module[]>
47
62
  }
package/src/Bridge.ts CHANGED
@@ -1,9 +1,17 @@
1
- import { Module } from '@xyo-network/module-model'
1
+ import { Module, ModuleConfig, ModuleFilter, ModuleQueryResult, XyoQuery, XyoQueryBoundWitness } from '@xyo-network/module-model'
2
+ import { XyoPayload } from '@xyo-network/payload-model'
2
3
  import { Promisable } from '@xyo-network/promise'
3
4
 
5
+ import { BridgeConfig } from './Config'
6
+
4
7
  export interface Bridge {
5
8
  connect: () => Promisable<boolean>
6
9
  disconnect: () => Promisable<boolean>
7
10
  }
8
11
 
9
- export interface BridgeModule extends Bridge, Module {}
12
+ export interface BridgeModule<TConfig extends BridgeConfig = BridgeConfig> extends Bridge, Module<TConfig> {
13
+ targetResolver: Module['resolver']
14
+ targetQuery(address: string, query: XyoQuery, payloads?: XyoPayload[]): Promisable<ModuleQueryResult>
15
+ targetQueryable(address: string, query: XyoQueryBoundWitness, payloads?: XyoPayload[], queryConfig?: ModuleConfig): Promisable<boolean>
16
+ targetResolve(address: string, filter?: ModuleFilter): Promisable<Module[]>
17
+ }
@@ -1,10 +1,24 @@
1
- import { ModuleWrapper } from '@xyo-network/module'
1
+ import {
2
+ ModuleConfig,
3
+ ModuleDiscoverQuery,
4
+ ModuleDiscoverQuerySchema,
5
+ ModuleFilter,
6
+ ModuleQueryResult,
7
+ ModuleWrapper,
8
+ XyoQuery,
9
+ XyoQueryBoundWitness,
10
+ } from '@xyo-network/module'
11
+ import { XyoPayload, XyoPayloads } from '@xyo-network/payload-model'
2
12
  import { PayloadWrapper } from '@xyo-network/payload-wrapper'
3
13
 
4
- import { Bridge } from './Bridge'
14
+ import { BridgeModule } from './Bridge'
5
15
  import { XyoBridgeConnectQuerySchema, XyoBridgeDisconnectQuerySchema, XyoBridgeQuery } from './Queries'
6
16
 
7
- export class BridgeWrapper extends ModuleWrapper implements Bridge {
17
+ export class BridgeWrapper extends ModuleWrapper<BridgeModule> implements BridgeModule {
18
+ public get targetResolver() {
19
+ return this.module.targetResolver
20
+ }
21
+
8
22
  async connect(uri?: string): Promise<boolean> {
9
23
  const queryPayload = PayloadWrapper.parse<XyoBridgeQuery>({ schema: XyoBridgeConnectQuerySchema, uri })
10
24
  await this.sendQuery(queryPayload)
@@ -16,4 +30,36 @@ export class BridgeWrapper extends ModuleWrapper implements Bridge {
16
30
  await this.sendQuery(queryPayload)
17
31
  return true
18
32
  }
33
+
34
+ async targetDiscover(address: string): Promise<XyoPayload[]> {
35
+ const queryPayload = PayloadWrapper.parse<ModuleDiscoverQuery>({ schema: ModuleDiscoverQuerySchema })
36
+ return await this.sendTargetQuery(address, queryPayload)
37
+ }
38
+
39
+ async targetQuery<T extends XyoQueryBoundWitness = XyoQueryBoundWitness>(
40
+ address: string,
41
+ query: T,
42
+ payloads?: XyoPayload[],
43
+ ): Promise<ModuleQueryResult> {
44
+ return await this.module.targetQuery(address, query, payloads)
45
+ }
46
+
47
+ async targetQueryable(address: string, query: XyoQueryBoundWitness, payloads?: XyoPayload[], queryConfig?: ModuleConfig): Promise<boolean> {
48
+ return await this.module.targetQueryable(address, query, payloads, queryConfig)
49
+ }
50
+
51
+ async targetResolve(address: string, filter?: ModuleFilter) {
52
+ return await this.module.targetResolve(address, filter)
53
+ }
54
+
55
+ protected async sendTargetQuery<T extends XyoQuery | PayloadWrapper<XyoQuery>>(
56
+ address: string,
57
+ queryPayload: T,
58
+ payloads?: XyoPayloads,
59
+ ): Promise<XyoPayload[]> {
60
+ const query = await this.bindQuery(queryPayload, payloads)
61
+ const result = await this.module.targetQuery(address, query[0], query[1])
62
+ this.throwErrors(query, result)
63
+ return result[1]
64
+ }
19
65
  }
package/src/HttpBridge.ts CHANGED
@@ -1,16 +1,17 @@
1
1
  import { assertEx } from '@xylabs/assert'
2
2
  import { Account } from '@xyo-network/account'
3
+ import { AddressPayload, AddressSchema } from '@xyo-network/address-payload-plugin'
3
4
  import { XyoApiEnvelope } from '@xyo-network/api-models'
4
5
  import { AxiosError, AxiosJson } from '@xyo-network/axios'
5
6
  import {
6
7
  AbstractModule,
8
+ ModuleConfig,
7
9
  ModuleDiscoverQuery,
8
10
  ModuleDiscoverQuerySchema,
9
11
  ModuleFilter,
10
12
  ModuleParams,
11
13
  ModuleQueryResult,
12
14
  ModuleResolver,
13
- ModuleWrapper,
14
15
  QueryBoundWitnessWrapper,
15
16
  XyoErrorBuilder,
16
17
  XyoQuery,
@@ -31,40 +32,37 @@ export interface XyoHttpBridgeParams<TConfig extends HttpBridgeConfig = HttpBrid
31
32
  axios?: AxiosJson
32
33
  }
33
34
 
34
- export class HttpBridge<TConfig extends HttpBridgeConfig = HttpBridgeConfig> extends AbstractModule<TConfig> implements BridgeModule {
35
+ export class HttpBridge<TConfig extends HttpBridgeConfig = HttpBridgeConfig> extends AbstractModule<TConfig> implements BridgeModule<TConfig> {
36
+ private _targetQueries: Record<string, string[]> = {}
37
+ private _targetResolver: ModuleResolver
35
38
  private axios: AxiosJson
36
- private remoteQueries: string[] = []
37
- private remoteResolver: ModuleResolver
38
39
 
39
40
  protected constructor(params: XyoHttpBridgeParams<TConfig>) {
40
41
  super(params)
41
42
  this.axios = params.axios ?? new AxiosJson()
42
- this.remoteResolver = new RemoteModuleResolver(this)
43
+ this._targetResolver = new RemoteModuleResolver(this)
43
44
  }
44
45
 
45
46
  public get nodeUri() {
46
47
  return assertEx(this.config?.nodeUri, 'Missing nodeUri')
47
48
  }
48
49
 
49
- public override get queries() {
50
- return [...super.queries, ...this.remoteQueries]
50
+ public get targetAddress() {
51
+ return assertEx(this.config?.targetAddress, 'targetAddress not set')
51
52
  }
52
53
 
53
- public get targetAddress() {
54
- return this.config?.targetAddress
54
+ public get targetResolver() {
55
+ return this._targetResolver
55
56
  }
56
57
 
57
58
  static override async create(params: XyoHttpBridgeParams): Promise<HttpBridge> {
58
59
  const result = (await super.create(params)) as HttpBridge
59
- const moduleWrapper = ModuleWrapper.wrap(result)
60
- const discover = await moduleWrapper.discover()
61
- result.remoteQueries = compact(
60
+ const discover = await result.targetDiscover(params.config.targetAddress ?? '')
61
+ await Promise.all(
62
62
  discover.map((payload) => {
63
- if (payload.schema === QuerySchema) {
64
- const schemaPayload = payload as QueryPayload
65
- return schemaPayload.query
66
- } else {
67
- return null
63
+ const addressPayload = payload as AddressPayload
64
+ if (addressPayload.schema === AddressSchema) {
65
+ return result.targetDiscover(addressPayload.address)
68
66
  }
69
67
  }),
70
68
  )
@@ -79,11 +77,6 @@ export class HttpBridge<TConfig extends HttpBridgeConfig = HttpBridgeConfig> ext
79
77
  return true
80
78
  }
81
79
 
82
- override async discover() {
83
- const queryPayload = PayloadWrapper.parse<ModuleDiscoverQuery>({ schema: ModuleDiscoverQuerySchema })
84
- return (await this.forward(queryPayload))[1]
85
- }
86
-
87
80
  override async query<T extends XyoQueryBoundWitness = XyoQueryBoundWitness>(query: T, payloads?: XyoPayload[]): Promise<ModuleQueryResult> {
88
81
  const wrapper = QueryBoundWitnessWrapper.parseQuery<XyoBridgeQuery>(query, payloads)
89
82
  const typedQuery = wrapper.query.payload
@@ -100,11 +93,7 @@ export class HttpBridge<TConfig extends HttpBridgeConfig = HttpBridgeConfig> ext
100
93
  break
101
94
  }
102
95
  default:
103
- if (super.queries.find((schema) => schema === typedQuery.schema)) {
104
- return await super.query(query, payloads)
105
- } else {
106
- return await this.forward(query, payloads)
107
- }
96
+ return await super.query(query, payloads)
108
97
  }
109
98
  } catch (ex) {
110
99
  const error = ex as Error
@@ -114,13 +103,40 @@ export class HttpBridge<TConfig extends HttpBridgeConfig = HttpBridgeConfig> ext
114
103
  }
115
104
 
116
105
  override async resolve(filter?: ModuleFilter) {
117
- return [...(await super.resolve(filter)), ...(await this.remoteResolver.resolve(filter))]
106
+ return [...(await super.resolve(filter)), ...(await this.targetResolver.resolve(filter))]
118
107
  }
119
108
 
120
- protected async forward(query: XyoQuery, payloads: XyoPayload[] = []): Promise<ModuleQueryResult> {
109
+ async targetDiscover(address: string): Promise<XyoPayload[]> {
110
+ const queryPayload = PayloadWrapper.parse<ModuleDiscoverQuery>({ schema: ModuleDiscoverQuerySchema })
111
+ const discover = assertEx(await this.targetQuery(address, queryPayload), `Unable to resolve [${address}]`)[1]
112
+
113
+ this._targetQueries[address] = compact(
114
+ discover?.map((payload) => {
115
+ if (payload.schema === QuerySchema) {
116
+ const schemaPayload = payload as QueryPayload
117
+ return schemaPayload.query
118
+ } else {
119
+ return null
120
+ }
121
+ }) ?? [],
122
+ )
123
+
124
+ return discover
125
+ }
126
+
127
+ public targetQueries(address: string): string[] {
128
+ return assertEx(this._targetQueries[address], `targetConfig not set [${address}]`)
129
+ }
130
+
131
+ async targetQuery(address: string, query: XyoQuery, payloads: XyoPayload[] = []): Promise<ModuleQueryResult> {
121
132
  try {
122
133
  const boundQuery = await this.bindQuery(query, payloads)
123
- const result = await this.axios.post<XyoApiEnvelope<ModuleQueryResult>>(`${this.nodeUri}/address/${this.targetAddress}`, boundQuery)
134
+ const path = `${this.nodeUri}/${address}`
135
+ const result = await this.axios.post<XyoApiEnvelope<ModuleQueryResult>>(path, boundQuery)
136
+ if (result.status >= 400) {
137
+ this.logger?.error(`targetQuery failed [${path}]`)
138
+ throw `targetQuery failed [${path}] [${result.status}]`
139
+ }
124
140
  return result.data.data
125
141
  } catch (ex) {
126
142
  const error = ex as AxiosError
@@ -129,4 +145,12 @@ export class HttpBridge<TConfig extends HttpBridgeConfig = HttpBridgeConfig> ext
129
145
  throw error
130
146
  }
131
147
  }
148
+
149
+ targetQueryable(_address: string, _query: XyoQueryBoundWitness, _payloads?: XyoPayload[], _queryConfig?: ModuleConfig): boolean {
150
+ throw 'targetQueryable not available'
151
+ }
152
+
153
+ async targetResolve(address: string, filter?: ModuleFilter) {
154
+ return await this.targetResolver.resolve(filter)
155
+ }
132
156
  }
@@ -0,0 +1,37 @@
1
+ import { Module, ModuleConfig, ModuleConfigSchema, ModuleFilter, ModuleQueryResult, XyoQueryBoundWitness } from '@xyo-network/module'
2
+ import { XyoPayload } from '@xyo-network/payload-model'
3
+
4
+ import { HttpBridge } from './HttpBridge'
5
+
6
+ export class HttpProxyModule implements Module {
7
+ constructor(protected readonly bridge: HttpBridge, protected readonly _address: string) {}
8
+
9
+ get address() {
10
+ return this._address
11
+ }
12
+
13
+ get config(): ModuleConfig {
14
+ return { schema: ModuleConfigSchema }
15
+ }
16
+
17
+ get queries() {
18
+ return this.bridge.targetQueries(this.address)
19
+ }
20
+
21
+ get resolver() {
22
+ return this.bridge.targetResolver
23
+ }
24
+
25
+ async query<T extends XyoQueryBoundWitness = XyoQueryBoundWitness>(query: T, payloads?: XyoPayload[]): Promise<ModuleQueryResult> {
26
+ return await this.bridge.targetQuery(this.address, query, payloads)
27
+ }
28
+
29
+ queryable(query: XyoQueryBoundWitness, payloads?: XyoPayload[], queryConfig?: ModuleConfig): boolean {
30
+ return this.bridge.targetQueryable(this.address, query, payloads, queryConfig)
31
+ }
32
+
33
+ /* Resolves a filter from the perspective of the module, including through the parent/gateway module */
34
+ async resolve(filter?: ModuleFilter): Promise<Module[]> {
35
+ return await this.bridge.targetResolve(this.address, filter)
36
+ }
37
+ }
@@ -1,25 +1,14 @@
1
- import { assertEx } from '@xylabs/assert'
2
1
  import { AddressPayload, AddressSchema } from '@xyo-network/address-payload-plugin'
3
- import { AbstractModule, CompositeModuleResolver, ModuleWrapper } from '@xyo-network/module'
2
+ import { CompositeModuleResolver } from '@xyo-network/module'
4
3
  import { Module, ModuleFilter } from '@xyo-network/module-model'
5
4
  import compact from 'lodash/compact'
6
5
  import flatten from 'lodash/flatten'
7
6
 
8
7
  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
- }
8
+ import { HttpProxyModule } from './HttpProxyModule'
20
9
 
21
10
  export class RemoteModuleResolver extends CompositeModuleResolver {
22
- private resolvedModules: Record<string, HttpBridge> = {}
11
+ private resolvedModules: Record<string, HttpProxyModule> = {}
23
12
 
24
13
  // TODO: Allow optional ctor param for supplying address for nested Nodes
25
14
  // protected readonly address?: string,
@@ -44,22 +33,12 @@ export class RemoteModuleResolver extends CompositeModuleResolver {
44
33
  throw new Error('Method not implemented.')
45
34
  }
46
35
 
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
36
+ async resolve(filter?: ModuleFilter): Promise<HttpProxyModule[]> {
37
+ return await Promise.all(flatten(await this.resolveRemoteModules(filter)))
58
38
  }
59
39
 
60
40
  private async getRemoteAddresses() {
61
- const nodeWrapper = assertEx(ModuleWrapper.wrap(this.bridge), 'nodeUri can not be wrapped')
62
- const discover = await nodeWrapper.discover()
41
+ const discover = await this.bridge.targetDiscover('')
63
42
  return compact(
64
43
  discover.map((payload) => {
65
44
  if (payload.schema === AddressSchema) {
@@ -72,32 +51,25 @@ export class RemoteModuleResolver extends CompositeModuleResolver {
72
51
  )
73
52
  }
74
53
 
75
- private async resolveByAddress(targetAddress: string): Promise<HttpBridge> {
54
+ private resolveByAddress(targetAddress: string): HttpProxyModule | undefined {
76
55
  const cached = this.resolvedModules[targetAddress]
77
56
  if (cached) return cached
78
- const mod = await HttpBridge.create({
79
- config: { nodeUri: this.bridge.nodeUri, schema: HttpBridgeConfigSchema, targetAddress },
80
- })
57
+ const mod = new HttpProxyModule(this.bridge, targetAddress)
81
58
  this.resolvedModules[targetAddress] = mod
82
59
  return mod
83
60
  }
84
61
 
85
- private async resolveByName(name: string): Promise<HttpBridge> {
62
+ private resolveByName(name: string): HttpProxyModule | undefined {
86
63
  const cached = this.resolvedModules[name]
87
64
  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
65
+ return undefined
94
66
  }
95
67
 
96
- private async resolveRemoteModules(filter?: RemoteModuleFilter): Promise<HttpBridge[]> {
68
+ private async resolveRemoteModules(filter?: ModuleFilter): Promise<HttpProxyModule[]> {
97
69
  const addresses = filter ? filter?.address : await this.getRemoteAddresses()
98
70
  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)) ?? [])
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)) ?? []))
101
73
  return [...byAddress, ...byName]
102
74
  }
103
75
  }
@@ -1,3 +1,4 @@
1
+ import { assertEx } from '@xylabs/assert'
1
2
  import { AxiosJson } from '@xyo-network/axios'
2
3
  import { NodeWrapper } from '@xyo-network/node'
3
4
 
@@ -6,12 +7,15 @@ import { HttpBridgeConfigSchema } from '../HttpBridgeConfig'
6
7
 
7
8
  test('HttpBridge', async () => {
8
9
  const nodeUri = `${process.env.API_DOMAIN}` ?? 'http://localhost:8080'
10
+ const targetAddress = ''
9
11
 
10
12
  const bridge = await HttpBridge.create({
11
13
  axios: new AxiosJson(),
12
- config: { nodeUri, schema: HttpBridgeConfigSchema, targetAddress: '5111228f724a066ac060fe2e6c8bbaae44b107d5' },
14
+ config: { nodeUri: `${nodeUri}/node`, schema: HttpBridgeConfigSchema, security: { allowAnonymous: true }, targetAddress },
13
15
  })
14
- const wrapper = NodeWrapper.wrap(bridge)
16
+ const modules = await bridge.resolve()
17
+ const rootNode = assertEx(modules[0])
18
+ const wrapper = NodeWrapper.wrap(rootNode)
15
19
  const description = await wrapper.describe()
16
20
  expect(description.children).toBeArray()
17
21
  expect(description.children?.length).toBeGreaterThan(0)