@xyo-network/bridge-pub-sub 2.92.10 → 2.93.0-rc.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/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.cts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.mts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.ts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusClient.d.cts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusClient.d.mts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusClient.d.ts.map +1 -1
- package/dist/browser/AsyncQueryBus/ModuleProxy/ModuleProxy.d.cts +1 -0
- package/dist/browser/AsyncQueryBus/ModuleProxy/ModuleProxy.d.cts.map +1 -1
- package/dist/browser/AsyncQueryBus/ModuleProxy/ModuleProxy.d.mts +1 -0
- package/dist/browser/AsyncQueryBus/ModuleProxy/ModuleProxy.d.mts.map +1 -1
- package/dist/browser/AsyncQueryBus/ModuleProxy/ModuleProxy.d.ts +1 -0
- package/dist/browser/AsyncQueryBus/ModuleProxy/ModuleProxy.d.ts.map +1 -1
- package/dist/browser/Config.d.cts +2 -0
- package/dist/browser/Config.d.cts.map +1 -1
- package/dist/browser/Config.d.mts +2 -0
- package/dist/browser/Config.d.mts.map +1 -1
- package/dist/browser/Config.d.ts +2 -0
- package/dist/browser/Config.d.ts.map +1 -1
- package/dist/browser/PubSubBridge.d.cts +7 -5
- package/dist/browser/PubSubBridge.d.cts.map +1 -1
- package/dist/browser/PubSubBridge.d.mts +7 -5
- package/dist/browser/PubSubBridge.d.mts.map +1 -1
- package/dist/browser/PubSubBridge.d.ts +7 -5
- package/dist/browser/PubSubBridge.d.ts.map +1 -1
- package/dist/browser/PubSubBridgeModuleResolver.d.cts +2 -2
- package/dist/browser/PubSubBridgeModuleResolver.d.cts.map +1 -1
- package/dist/browser/PubSubBridgeModuleResolver.d.mts +2 -2
- package/dist/browser/PubSubBridgeModuleResolver.d.mts.map +1 -1
- package/dist/browser/PubSubBridgeModuleResolver.d.ts +2 -2
- package/dist/browser/PubSubBridgeModuleResolver.d.ts.map +1 -1
- package/dist/browser/index.cjs +75 -17
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +77 -19
- package/dist/browser/index.js.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.cts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.mts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.ts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusClient.d.cts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusClient.d.mts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusClient.d.ts.map +1 -1
- package/dist/node/AsyncQueryBus/ModuleProxy/ModuleProxy.d.cts +1 -0
- package/dist/node/AsyncQueryBus/ModuleProxy/ModuleProxy.d.cts.map +1 -1
- package/dist/node/AsyncQueryBus/ModuleProxy/ModuleProxy.d.mts +1 -0
- package/dist/node/AsyncQueryBus/ModuleProxy/ModuleProxy.d.mts.map +1 -1
- package/dist/node/AsyncQueryBus/ModuleProxy/ModuleProxy.d.ts +1 -0
- package/dist/node/AsyncQueryBus/ModuleProxy/ModuleProxy.d.ts.map +1 -1
- package/dist/node/Config.d.cts +2 -0
- package/dist/node/Config.d.cts.map +1 -1
- package/dist/node/Config.d.mts +2 -0
- package/dist/node/Config.d.mts.map +1 -1
- package/dist/node/Config.d.ts +2 -0
- package/dist/node/Config.d.ts.map +1 -1
- package/dist/node/PubSubBridge.d.cts +7 -5
- package/dist/node/PubSubBridge.d.cts.map +1 -1
- package/dist/node/PubSubBridge.d.mts +7 -5
- package/dist/node/PubSubBridge.d.mts.map +1 -1
- package/dist/node/PubSubBridge.d.ts +7 -5
- package/dist/node/PubSubBridge.d.ts.map +1 -1
- package/dist/node/PubSubBridgeModuleResolver.d.cts +2 -2
- package/dist/node/PubSubBridgeModuleResolver.d.cts.map +1 -1
- package/dist/node/PubSubBridgeModuleResolver.d.mts +2 -2
- package/dist/node/PubSubBridgeModuleResolver.d.mts.map +1 -1
- package/dist/node/PubSubBridgeModuleResolver.d.ts +2 -2
- package/dist/node/PubSubBridgeModuleResolver.d.ts.map +1 -1
- package/dist/node/index.cjs +80 -18
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +82 -20
- package/dist/node/index.js.map +1 -1
- package/package.json +28 -26
- package/src/AsyncQueryBus/AsyncQueryBusBase.ts +12 -4
- package/src/AsyncQueryBus/AsyncQueryBusClient.ts +4 -0
- package/src/AsyncQueryBus/ModuleProxy/ModuleProxy.ts +6 -0
- package/src/Config.ts +2 -0
- package/src/PubSubBridge.ts +35 -14
- package/src/PubSubBridgeModuleResolver.ts +18 -7
package/src/PubSubBridge.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { assertEx } from '@xylabs/assert'
|
|
2
|
+
import { exists } from '@xylabs/exists'
|
|
2
3
|
import { Address } from '@xylabs/hex'
|
|
3
4
|
import { AbstractBridge } from '@xyo-network/abstract-bridge'
|
|
4
5
|
import { BridgeExposeOptions, BridgeModule, BridgeUnexposeOptions } from '@xyo-network/bridge-model'
|
|
5
|
-
import { creatableModule, ModuleFilterOptions, ModuleIdentifier } from '@xyo-network/module-model'
|
|
6
|
+
import { creatableModule, ModuleFilterOptions, ModuleIdentifier, ModuleInstance } from '@xyo-network/module-model'
|
|
6
7
|
import { LRUCache } from 'lru-cache'
|
|
7
8
|
|
|
8
9
|
import { AsyncQueryBusClient, AsyncQueryBusHost } from './AsyncQueryBus'
|
|
@@ -32,8 +33,6 @@ export class PubSubBridge<TParams extends PubSubBridgeParams = PubSubBridgeParam
|
|
|
32
33
|
new PubSubBridgeModuleResolver({
|
|
33
34
|
bridge: this,
|
|
34
35
|
busClient: assertEx(this.busClient(), () => 'busClient not configured'),
|
|
35
|
-
downResolver: this.downResolver,
|
|
36
|
-
upResolver: this.upResolver,
|
|
37
36
|
wrapperAccount: this.account,
|
|
38
37
|
})
|
|
39
38
|
return this._resolver
|
|
@@ -43,24 +42,43 @@ export class PubSubBridge<TParams extends PubSubBridgeParams = PubSubBridgeParam
|
|
|
43
42
|
return `${this.config.name ?? moduleName}`
|
|
44
43
|
}
|
|
45
44
|
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
protected get roots() {
|
|
46
|
+
return assertEx(this.config.roots, () => 'roots not configured')
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async exposeHandler(id: ModuleIdentifier, options?: BridgeExposeOptions | undefined): Promise<ModuleInstance[]> {
|
|
50
|
+
const { maxDepth = 1, direction } = options ?? {}
|
|
51
|
+
const filterOptions: ModuleFilterOptions = { direction }
|
|
48
52
|
const module = await super.resolve(id, filterOptions)
|
|
49
53
|
if (module) {
|
|
50
54
|
const host = assertEx(this.busHost(), () => 'Not configured as a host')
|
|
51
55
|
host.expose(module.address)
|
|
52
|
-
|
|
56
|
+
const children = await module.resolve('*', { direction, maxDepth, visibility: 'public' })
|
|
57
|
+
for (const child of children) {
|
|
58
|
+
host.expose(child.address)
|
|
59
|
+
}
|
|
60
|
+
return [module, ...children]
|
|
53
61
|
}
|
|
54
62
|
return []
|
|
55
63
|
}
|
|
56
64
|
|
|
57
|
-
async
|
|
58
|
-
|
|
65
|
+
override async startHandler(): Promise<boolean> {
|
|
66
|
+
this.busHost()?.start()
|
|
67
|
+
return await super.startHandler()
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async unexposeHandler(id: ModuleIdentifier, options?: BridgeUnexposeOptions | undefined): Promise<ModuleInstance[]> {
|
|
71
|
+
const { maxDepth = 1, direction } = options ?? {}
|
|
72
|
+
const filterOptions: ModuleFilterOptions = { direction }
|
|
59
73
|
const module = await super.resolve(id, filterOptions)
|
|
60
74
|
if (module) {
|
|
61
75
|
const host = assertEx(this.busHost(), () => 'Not configured as a host')
|
|
62
76
|
host.unexpose(module.address)
|
|
63
|
-
|
|
77
|
+
const children = await module.resolve('*', { direction, maxDepth, visibility: 'public' })
|
|
78
|
+
for (const child of children) {
|
|
79
|
+
host.unexpose(child.address)
|
|
80
|
+
}
|
|
81
|
+
return [module, ...children]
|
|
64
82
|
}
|
|
65
83
|
return []
|
|
66
84
|
}
|
|
@@ -70,7 +88,7 @@ export class PubSubBridge<TParams extends PubSubBridgeParams = PubSubBridgeParam
|
|
|
70
88
|
this._busClient = new AsyncQueryBusClient({
|
|
71
89
|
config: this.config.client,
|
|
72
90
|
logger: this.logger,
|
|
73
|
-
resolver: this,
|
|
91
|
+
resolver: this.upResolver,
|
|
74
92
|
})
|
|
75
93
|
}
|
|
76
94
|
return this._busClient
|
|
@@ -81,15 +99,18 @@ export class PubSubBridge<TParams extends PubSubBridgeParams = PubSubBridgeParam
|
|
|
81
99
|
this._busHost = new AsyncQueryBusHost({
|
|
82
100
|
config: this.config.host,
|
|
83
101
|
logger: this.logger,
|
|
84
|
-
resolver: this,
|
|
102
|
+
resolver: this.upResolver,
|
|
85
103
|
})
|
|
86
104
|
}
|
|
87
105
|
return this._busHost
|
|
88
106
|
}
|
|
89
107
|
|
|
90
|
-
protected override
|
|
91
|
-
this.
|
|
92
|
-
|
|
108
|
+
protected override async discoverRoots(): Promise<ModuleInstance[]> {
|
|
109
|
+
const rootInstances = (await Promise.all(this.roots.map(async (root) => await this.resolver.resolve<ModuleInstance>(root)))).filter(exists)
|
|
110
|
+
for (const instance of rootInstances) {
|
|
111
|
+
this.downResolver.add(instance)
|
|
112
|
+
}
|
|
113
|
+
return rootInstances
|
|
93
114
|
}
|
|
94
115
|
|
|
95
116
|
protected override stopHandler(_timeout?: number | undefined) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { assertEx } from '@xylabs/assert'
|
|
2
|
+
import { Address, isAddress } from '@xylabs/hex'
|
|
3
|
+
import { AbstractBridgeModuleResolver, BridgeModuleResolverOptions, wrapModuleWithType } from '@xyo-network/abstract-bridge'
|
|
3
4
|
import { Account } from '@xyo-network/account'
|
|
4
5
|
import { ModuleFilterOptions, ModuleIdentifier, ModuleInstance } from '@xyo-network/module-model'
|
|
5
6
|
|
|
@@ -9,12 +10,18 @@ export interface PubSubBridgeModuleResolverOptions extends BridgeModuleResolverO
|
|
|
9
10
|
busClient: AsyncQueryBusClient
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
export class PubSubBridgeModuleResolver<
|
|
13
|
-
T extends
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
export class PubSubBridgeModuleResolver extends AbstractBridgeModuleResolver<PubSubBridgeModuleResolverOptions> {
|
|
14
|
+
override async resolveHandler<T extends ModuleInstance = ModuleInstance>(
|
|
15
|
+
id: ModuleIdentifier,
|
|
16
|
+
options?: ModuleFilterOptions<T>,
|
|
17
|
+
): Promise<T | T[] | undefined> {
|
|
18
|
+
const parentResult = await super.resolveHandler(id, options)
|
|
19
|
+
if (parentResult) {
|
|
20
|
+
return parentResult
|
|
21
|
+
}
|
|
16
22
|
const idParts = id.split(':')
|
|
17
23
|
const firstPart = idParts.shift()
|
|
24
|
+
assertEx(isAddress(firstPart), () => `Invalid module address: ${firstPart}`)
|
|
18
25
|
const remainderParts = idParts.join(':')
|
|
19
26
|
const account = Account.randomSync()
|
|
20
27
|
const params: AsyncQueryBusModuleProxyParams = {
|
|
@@ -24,6 +31,10 @@ export class PubSubBridgeModuleResolver<
|
|
|
24
31
|
moduleAddress: firstPart as Address,
|
|
25
32
|
}
|
|
26
33
|
const proxy = new AsyncQueryBusModuleProxy<T>(params) as unknown as T
|
|
27
|
-
|
|
34
|
+
await proxy.start?.()
|
|
35
|
+
const wrappedProxy = wrapModuleWithType(proxy, account) as unknown as T
|
|
36
|
+
this.add(wrappedProxy)
|
|
37
|
+
console.log('ding!')
|
|
38
|
+
return remainderParts.length > 0 ? await proxy.resolve(remainderParts, options) : wrappedProxy
|
|
28
39
|
}
|
|
29
40
|
}
|