@xyo-network/bridge-pub-sub 2.92.6 → 2.92.8
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/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/AsyncQueryBusHost.d.cts +7 -2
- package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.cts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.mts +7 -2
- package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.mts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.ts +7 -2
- package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.ts.map +1 -1
- package/dist/browser/AsyncQueryBus/ModuleProxy/ModuleProxy.d.cts +1 -1
- package/dist/browser/AsyncQueryBus/ModuleProxy/ModuleProxy.d.cts.map +1 -1
- package/dist/browser/AsyncQueryBus/ModuleProxy/ModuleProxy.d.mts +1 -1
- package/dist/browser/AsyncQueryBus/ModuleProxy/ModuleProxy.d.mts.map +1 -1
- package/dist/browser/AsyncQueryBus/ModuleProxy/ModuleProxy.d.ts +1 -1
- package/dist/browser/AsyncQueryBus/ModuleProxy/ModuleProxy.d.ts.map +1 -1
- package/dist/browser/AsyncQueryBus/model/ClientConfig.d.cts +1 -1
- package/dist/browser/AsyncQueryBus/model/ClientConfig.d.mts +1 -1
- package/dist/browser/AsyncQueryBus/model/ClientConfig.d.ts +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 +10 -0
- package/dist/browser/PubSubBridgeModuleResolver.d.cts.map +1 -0
- package/dist/browser/PubSubBridgeModuleResolver.d.mts +10 -0
- package/dist/browser/PubSubBridgeModuleResolver.d.mts.map +1 -0
- package/dist/browser/PubSubBridgeModuleResolver.d.ts +10 -0
- package/dist/browser/PubSubBridgeModuleResolver.d.ts.map +1 -0
- package/dist/browser/index.cjs +56 -31
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.d.cts +1 -0
- package/dist/browser/index.d.cts.map +1 -1
- package/dist/browser/index.d.mts +1 -0
- package/dist/browser/index.d.mts.map +1 -1
- package/dist/browser/index.d.ts +1 -0
- package/dist/browser/index.d.ts.map +1 -1
- package/dist/browser/index.js +56 -31
- package/dist/browser/index.js.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/AsyncQueryBusHost.d.cts +7 -2
- package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.cts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.mts +7 -2
- package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.mts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.ts +7 -2
- package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.ts.map +1 -1
- package/dist/node/AsyncQueryBus/ModuleProxy/ModuleProxy.d.cts +1 -1
- package/dist/node/AsyncQueryBus/ModuleProxy/ModuleProxy.d.cts.map +1 -1
- package/dist/node/AsyncQueryBus/ModuleProxy/ModuleProxy.d.mts +1 -1
- package/dist/node/AsyncQueryBus/ModuleProxy/ModuleProxy.d.mts.map +1 -1
- package/dist/node/AsyncQueryBus/ModuleProxy/ModuleProxy.d.ts +1 -1
- package/dist/node/AsyncQueryBus/ModuleProxy/ModuleProxy.d.ts.map +1 -1
- package/dist/node/AsyncQueryBus/model/ClientConfig.d.cts +1 -1
- package/dist/node/AsyncQueryBus/model/ClientConfig.d.mts +1 -1
- package/dist/node/AsyncQueryBus/model/ClientConfig.d.ts +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 +10 -0
- package/dist/node/PubSubBridgeModuleResolver.d.cts.map +1 -0
- package/dist/node/PubSubBridgeModuleResolver.d.mts +10 -0
- package/dist/node/PubSubBridgeModuleResolver.d.mts.map +1 -0
- package/dist/node/PubSubBridgeModuleResolver.d.ts +10 -0
- package/dist/node/PubSubBridgeModuleResolver.d.ts.map +1 -0
- package/dist/node/index.cjs +60 -35
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.d.cts +1 -0
- package/dist/node/index.d.cts.map +1 -1
- package/dist/node/index.d.mts +1 -0
- package/dist/node/index.d.mts.map +1 -1
- package/dist/node/index.d.ts +1 -0
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +59 -35
- package/dist/node/index.js.map +1 -1
- package/package.json +24 -25
- package/src/AsyncQueryBus/AsyncQueryBusClient.ts +3 -4
- package/src/AsyncQueryBus/AsyncQueryBusHost.ts +17 -5
- package/src/AsyncQueryBus/ModuleHost/ModuleHost.ts +1 -1
- package/src/AsyncQueryBus/ModuleProxy/ModuleProxy.ts +1 -1
- package/src/AsyncQueryBus/model/ClientConfig.ts +1 -1
- package/src/PubSubBridge.ts +22 -26
- package/src/PubSubBridgeModuleResolver.ts +29 -0
- package/src/index.ts +1 -0
package/src/PubSubBridge.ts
CHANGED
|
@@ -1,22 +1,19 @@
|
|
|
1
1
|
import { assertEx } from '@xylabs/assert'
|
|
2
2
|
import { Address } from '@xylabs/hex'
|
|
3
3
|
import { AbstractBridge } from '@xyo-network/abstract-bridge'
|
|
4
|
-
import { Account } from '@xyo-network/account'
|
|
5
4
|
import { BridgeExposeOptions, BridgeModule, BridgeUnexposeOptions } from '@xyo-network/bridge-model'
|
|
6
|
-
import { creatableModule,
|
|
5
|
+
import { creatableModule, ModuleFilterOptions, ModuleIdentifier } from '@xyo-network/module-model'
|
|
7
6
|
import { LRUCache } from 'lru-cache'
|
|
8
7
|
|
|
9
|
-
import { AsyncQueryBusClient, AsyncQueryBusHost
|
|
8
|
+
import { AsyncQueryBusClient, AsyncQueryBusHost } from './AsyncQueryBus'
|
|
10
9
|
import { PubSubBridgeConfigSchema } from './Config'
|
|
11
10
|
import { PubSubBridgeParams } from './Params'
|
|
11
|
+
import { PubSubBridgeModuleResolver } from './PubSubBridgeModuleResolver'
|
|
12
12
|
|
|
13
13
|
const moduleName = 'PubSubBridge'
|
|
14
14
|
|
|
15
15
|
@creatableModule()
|
|
16
|
-
export class PubSubBridge<TParams extends PubSubBridgeParams = PubSubBridgeParams
|
|
17
|
-
extends AbstractBridge<TParams, TEventData>
|
|
18
|
-
implements BridgeModule<TParams, TEventData>
|
|
19
|
-
{
|
|
16
|
+
export class PubSubBridge<TParams extends PubSubBridgeParams = PubSubBridgeParams> extends AbstractBridge<TParams> implements BridgeModule<TParams> {
|
|
20
17
|
static override configSchemas = [PubSubBridgeConfigSchema]
|
|
21
18
|
|
|
22
19
|
protected _configRootAddress: Address = ''
|
|
@@ -27,42 +24,41 @@ export class PubSubBridge<TParams extends PubSubBridgeParams = PubSubBridgeParam
|
|
|
27
24
|
|
|
28
25
|
private _busClient?: AsyncQueryBusClient
|
|
29
26
|
private _busHost?: AsyncQueryBusHost
|
|
27
|
+
private _resolver?: PubSubBridgeModuleResolver
|
|
28
|
+
|
|
29
|
+
override get resolver() {
|
|
30
|
+
this._resolver =
|
|
31
|
+
this._resolver ??
|
|
32
|
+
new PubSubBridgeModuleResolver({
|
|
33
|
+
bridge: this,
|
|
34
|
+
busClient: assertEx(this.busClient(), () => 'busClient not configured'),
|
|
35
|
+
downResolver: this.downResolver,
|
|
36
|
+
upResolver: this.upResolver,
|
|
37
|
+
wrapperAccount: this.account,
|
|
38
|
+
})
|
|
39
|
+
return this._resolver
|
|
40
|
+
}
|
|
30
41
|
|
|
31
42
|
protected get moduleName() {
|
|
32
43
|
return `${this.config.name ?? moduleName}`
|
|
33
44
|
}
|
|
34
45
|
|
|
35
|
-
async exposeHandler(id: ModuleIdentifier, options?: BridgeExposeOptions | undefined): Promise<
|
|
46
|
+
async exposeHandler(id: ModuleIdentifier, options?: BridgeExposeOptions | undefined): Promise<Address[]> {
|
|
36
47
|
const filterOptions: ModuleFilterOptions = { direction: options?.direction }
|
|
37
48
|
const module = await super.resolve(id, filterOptions)
|
|
38
49
|
if (module) {
|
|
39
|
-
const host = assertEx(this.busHost(), 'Not configured as a host')
|
|
50
|
+
const host = assertEx(this.busHost(), () => 'Not configured as a host')
|
|
40
51
|
host.expose(module.address)
|
|
41
52
|
return [module.address]
|
|
42
53
|
}
|
|
43
54
|
return []
|
|
44
55
|
}
|
|
45
56
|
|
|
46
|
-
async
|
|
47
|
-
const idParts = id.split(':')
|
|
48
|
-
const firstPart = idParts.shift()
|
|
49
|
-
const remainderParts = idParts.join(':')
|
|
50
|
-
const account = Account.randomSync()
|
|
51
|
-
const params: AsyncQueryBusModuleProxyParams = {
|
|
52
|
-
account,
|
|
53
|
-
bridge: this,
|
|
54
|
-
busClient: assertEx(this.busClient(), 'Bus client not initialized'),
|
|
55
|
-
moduleAddress: firstPart as Address,
|
|
56
|
-
}
|
|
57
|
-
const proxy = new AsyncQueryBusModuleProxy<T>(params) as unknown as T
|
|
58
|
-
return remainderParts.length > 0 ? await proxy.resolve(remainderParts, options) : proxy
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async unexposeHandler(id: ModuleIdentifier, options?: BridgeUnexposeOptions | undefined): Promise<Lowercase<string>[]> {
|
|
57
|
+
async unexposeHandler(id: ModuleIdentifier, options?: BridgeUnexposeOptions | undefined): Promise<Address[]> {
|
|
62
58
|
const filterOptions: ModuleFilterOptions = { direction: options?.direction }
|
|
63
59
|
const module = await super.resolve(id, filterOptions)
|
|
64
60
|
if (module) {
|
|
65
|
-
const host = assertEx(this.busHost(), 'Not configured as a host')
|
|
61
|
+
const host = assertEx(this.busHost(), () => 'Not configured as a host')
|
|
66
62
|
host.unexpose(module.address)
|
|
67
63
|
return [module.address]
|
|
68
64
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Address } from '@xylabs/hex'
|
|
2
|
+
import { AbstractBridgeModuleResolver, BridgeModuleResolverOptions } from '@xyo-network/abstract-bridge'
|
|
3
|
+
import { Account } from '@xyo-network/account'
|
|
4
|
+
import { ModuleFilterOptions, ModuleIdentifier, ModuleInstance } from '@xyo-network/module-model'
|
|
5
|
+
|
|
6
|
+
import { AsyncQueryBusClient, AsyncQueryBusModuleProxy, AsyncQueryBusModuleProxyParams } from './AsyncQueryBus'
|
|
7
|
+
|
|
8
|
+
export interface PubSubBridgeModuleResolverOptions extends BridgeModuleResolverOptions {
|
|
9
|
+
busClient: AsyncQueryBusClient
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class PubSubBridgeModuleResolver<
|
|
13
|
+
T extends PubSubBridgeModuleResolverOptions = PubSubBridgeModuleResolverOptions,
|
|
14
|
+
> extends AbstractBridgeModuleResolver<T> {
|
|
15
|
+
async resolveHandler<T extends ModuleInstance = ModuleInstance>(id: ModuleIdentifier, options?: ModuleFilterOptions<T>): Promise<T | undefined> {
|
|
16
|
+
const idParts = id.split(':')
|
|
17
|
+
const firstPart = idParts.shift()
|
|
18
|
+
const remainderParts = idParts.join(':')
|
|
19
|
+
const account = Account.randomSync()
|
|
20
|
+
const params: AsyncQueryBusModuleProxyParams = {
|
|
21
|
+
account,
|
|
22
|
+
busClient: this.options.busClient,
|
|
23
|
+
host: this.options.bridge,
|
|
24
|
+
moduleAddress: firstPart as Address,
|
|
25
|
+
}
|
|
26
|
+
const proxy = new AsyncQueryBusModuleProxy<T>(params) as unknown as T
|
|
27
|
+
return remainderParts.length > 0 ? await proxy.resolve(remainderParts, options) : proxy
|
|
28
|
+
}
|
|
29
|
+
}
|