@xyo-network/bridge-pub-sub 2.94.15 → 2.94.16
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 +4 -0
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.cts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.mts +4 -0
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.mts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.ts +4 -0
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.ts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.cts +24 -3
- package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.cts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.mts +24 -3
- package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.mts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.ts +24 -3
- package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.ts.map +1 -1
- package/dist/browser/PubSubBridge.d.cts.map +1 -1
- package/dist/browser/PubSubBridge.d.mts.map +1 -1
- package/dist/browser/PubSubBridge.d.ts.map +1 -1
- package/dist/browser/index.cjs +130 -101
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +130 -101
- package/dist/browser/index.js.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.cts +4 -0
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.cts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.mts +4 -0
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.mts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.ts +4 -0
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.ts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.cts +24 -3
- package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.cts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.mts +24 -3
- package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.mts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.ts +24 -3
- package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.ts.map +1 -1
- package/dist/node/PubSubBridge.d.cts.map +1 -1
- package/dist/node/PubSubBridge.d.mts.map +1 -1
- package/dist/node/PubSubBridge.d.ts.map +1 -1
- package/dist/node/index.cjs +134 -105
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +134 -105
- package/dist/node/index.js.map +1 -1
- package/package.json +19 -18
- package/src/AsyncQueryBus/AsyncQueryBusBase.ts +85 -72
- package/src/AsyncQueryBus/AsyncQueryBusHost.ts +29 -14
- package/src/PubSubBridge.ts +21 -20
|
@@ -4,7 +4,7 @@ import { Address } from '@xylabs/hex'
|
|
|
4
4
|
import { clearTimeoutEx, setTimeoutEx } from '@xylabs/timer'
|
|
5
5
|
import { isQueryBoundWitnessWithMeta, QueryBoundWitness } from '@xyo-network/boundwitness-model'
|
|
6
6
|
import { BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'
|
|
7
|
-
import { asModuleInstance, ModuleConfigSchema, ModuleInstance } from '@xyo-network/module-model'
|
|
7
|
+
import { asModuleInstance, ModuleConfigSchema, ModuleIdentifier, ModuleInstance } from '@xyo-network/module-model'
|
|
8
8
|
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
9
9
|
import { Schema, WithMeta } from '@xyo-network/payload-model'
|
|
10
10
|
|
|
@@ -14,6 +14,7 @@ import { AsyncQueryBusHostParams } from './model'
|
|
|
14
14
|
export interface ExposeOptions {
|
|
15
15
|
allowedQueries?: Schema[]
|
|
16
16
|
failOnAlreadyExposed?: boolean
|
|
17
|
+
required?: boolean
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
export class AsyncQueryBusHost<TParams extends AsyncQueryBusHostParams = AsyncQueryBusHostParams> extends AsyncQueryBusBase<TParams> {
|
|
@@ -37,19 +38,29 @@ export class AsyncQueryBusHost<TParams extends AsyncQueryBusHostParams = AsyncQu
|
|
|
37
38
|
return !!this._pollId
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
expose(
|
|
41
|
-
const { failOnAlreadyExposed } = options
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
async expose(id: ModuleIdentifier, options?: ExposeOptions) {
|
|
42
|
+
const { failOnAlreadyExposed, required = true } = options ?? {}
|
|
43
|
+
const module = asModuleInstance(await this.resolver.resolve(id, { maxDepth: 10 }))
|
|
44
|
+
if (!module && required) {
|
|
45
|
+
throw new Error(`Unable to resolve module to expose [${id}]`)
|
|
46
|
+
}
|
|
47
|
+
if (module) {
|
|
48
|
+
assertEx(!failOnAlreadyExposed || !this._exposedAddresses.has(module.address), () => `Address already exposed: ${id} [${module.address}]`)
|
|
49
|
+
this._exposedAddresses.add(module.address)
|
|
50
|
+
this._exposeOptions[module.address] = { ...options }
|
|
51
|
+
this.logger?.debug(`${id} exposed [${module.address}]`)
|
|
52
|
+
return module
|
|
53
|
+
}
|
|
46
54
|
}
|
|
47
55
|
|
|
48
56
|
async listeningModules(): Promise<ModuleInstance[]> {
|
|
49
57
|
const exposedModules = [...(this.config?.listeningModules ?? []), ...this.exposedAddresses.values()]
|
|
50
58
|
const mods = await Promise.all(
|
|
51
|
-
exposedModules.map(async (
|
|
52
|
-
assertEx(
|
|
59
|
+
exposedModules.map(async (exposedModule) =>
|
|
60
|
+
assertEx(
|
|
61
|
+
asModuleInstance(await this.resolver.resolve(exposedModule, { maxDepth: 10 })),
|
|
62
|
+
() => `Unable to resolve listeningModule [${exposedModule}]`,
|
|
63
|
+
),
|
|
53
64
|
),
|
|
54
65
|
)
|
|
55
66
|
return mods
|
|
@@ -70,11 +81,15 @@ export class AsyncQueryBusHost<TParams extends AsyncQueryBusHostParams = AsyncQu
|
|
|
70
81
|
this._pollId = undefined
|
|
71
82
|
}
|
|
72
83
|
|
|
73
|
-
unexpose(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
84
|
+
async unexpose(id: ModuleIdentifier, validate = true) {
|
|
85
|
+
const module = asModuleInstance(await this.resolver.resolve(id, { maxDepth: 10 }))
|
|
86
|
+
if (module) {
|
|
87
|
+
assertEx(!validate || this._exposedAddresses.has(module.address), () => `Address not exposed [${module.address}][${module.id}]`)
|
|
88
|
+
this._exposedAddresses.delete(module.address)
|
|
89
|
+
delete this._exposeOptions[module.address]
|
|
90
|
+
this.logger?.debug(`${module.address} [${module.id}] unexposed`)
|
|
91
|
+
}
|
|
92
|
+
return module
|
|
78
93
|
}
|
|
79
94
|
|
|
80
95
|
protected callLocalModule = async (localModule: ModuleInstance, query: WithMeta<QueryBoundWitness>) => {
|
package/src/PubSubBridge.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { exists } from '@xylabs/exists'
|
|
|
3
3
|
import { Address } from '@xylabs/hex'
|
|
4
4
|
import { AbstractBridge } from '@xyo-network/abstract-bridge'
|
|
5
5
|
import { BridgeExposeOptions, BridgeModule, BridgeUnexposeOptions } from '@xyo-network/bridge-model'
|
|
6
|
-
import { creatableModule,
|
|
6
|
+
import { creatableModule, ModuleIdentifier, ModuleInstance, ModuleResolverInstance } from '@xyo-network/module-model'
|
|
7
7
|
import { LRUCache } from 'lru-cache'
|
|
8
8
|
|
|
9
9
|
import { AsyncQueryBusClient, AsyncQueryBusHost } from './AsyncQueryBus'
|
|
@@ -55,16 +55,17 @@ export class PubSubBridge<TParams extends PubSubBridgeParams = PubSubBridgeParam
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
async exposeHandler(id: ModuleIdentifier, options?: BridgeExposeOptions | undefined): Promise<ModuleInstance[]> {
|
|
58
|
-
const { maxDepth = 2, direction = 'all' } = options ?? {}
|
|
59
|
-
const
|
|
58
|
+
const { maxDepth = 2, direction = 'all', required = true } = options ?? {}
|
|
59
|
+
const host = assertEx(this.busHost(), () => 'Not configured as a host')
|
|
60
|
+
const module = await host.expose(id, { required })
|
|
60
61
|
if (module) {
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return [module, ...
|
|
62
|
+
const children = maxDepth > 0 ? await module.resolve('*', { direction, maxDepth, visibility: 'public' }) : []
|
|
63
|
+
const exposedChildren = (
|
|
64
|
+
await Promise.all(children.map((child) => this.exposeHandler(child.address, { maxDepth: maxDepth - 1, required: false })))
|
|
65
|
+
)
|
|
66
|
+
.flat()
|
|
67
|
+
.filter(exists)
|
|
68
|
+
return [module, ...exposedChildren]
|
|
68
69
|
}
|
|
69
70
|
return []
|
|
70
71
|
}
|
|
@@ -80,17 +81,17 @@ export class PubSubBridge<TParams extends PubSubBridgeParams = PubSubBridgeParam
|
|
|
80
81
|
}
|
|
81
82
|
|
|
82
83
|
async unexposeHandler(id: ModuleIdentifier, options?: BridgeUnexposeOptions | undefined): Promise<ModuleInstance[]> {
|
|
83
|
-
const { maxDepth =
|
|
84
|
-
const
|
|
85
|
-
const module = await
|
|
84
|
+
const { maxDepth = 2, direction = 'all', required = true } = options ?? {}
|
|
85
|
+
const host = assertEx(this.busHost(), () => 'Not configured as a host')
|
|
86
|
+
const module = await host.unexpose(id, required)
|
|
86
87
|
if (module) {
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
return [module, ...
|
|
88
|
+
const children = maxDepth > 0 ? await module.resolve('*', { direction, maxDepth, visibility: 'public' }) : []
|
|
89
|
+
const exposedChildren = (
|
|
90
|
+
await Promise.all(children.map((child) => this.unexposeHandler(child.address, { maxDepth: maxDepth - 1, required: false })))
|
|
91
|
+
)
|
|
92
|
+
.flat()
|
|
93
|
+
.filter(exists)
|
|
94
|
+
return [module, ...exposedChildren]
|
|
94
95
|
}
|
|
95
96
|
return []
|
|
96
97
|
}
|