@xyo-network/bridge-pub-sub 2.91.0 → 2.91.2
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/AbstractModuleHost/AbstractModuleHost.d.cts +11 -0
- package/dist/browser/AbstractModuleHost/AbstractModuleHost.d.cts.map +1 -0
- package/dist/browser/AbstractModuleHost/AbstractModuleHost.d.mts +11 -0
- package/dist/browser/AbstractModuleHost/AbstractModuleHost.d.mts.map +1 -0
- package/dist/browser/AbstractModuleHost/AbstractModuleHost.d.ts +11 -0
- package/dist/browser/AbstractModuleHost/AbstractModuleHost.d.ts.map +1 -0
- package/dist/browser/AbstractModuleHost/index.d.cts +2 -0
- package/dist/browser/AbstractModuleHost/index.d.cts.map +1 -0
- package/dist/browser/AbstractModuleHost/index.d.mts +2 -0
- package/dist/browser/AbstractModuleHost/index.d.mts.map +1 -0
- package/dist/browser/AbstractModuleHost/index.d.ts +2 -0
- package/dist/browser/AbstractModuleHost/index.d.ts.map +1 -0
- package/dist/browser/AbstractModuleProxy/AbstractModuleProxy.d.cts +90 -0
- package/dist/browser/AbstractModuleProxy/AbstractModuleProxy.d.cts.map +1 -0
- package/dist/browser/AbstractModuleProxy/AbstractModuleProxy.d.mts +90 -0
- package/dist/browser/AbstractModuleProxy/AbstractModuleProxy.d.mts.map +1 -0
- package/dist/browser/AbstractModuleProxy/AbstractModuleProxy.d.ts +90 -0
- package/dist/browser/AbstractModuleProxy/AbstractModuleProxy.d.ts.map +1 -0
- package/dist/browser/AbstractModuleProxy/index.d.cts +2 -0
- package/dist/browser/AbstractModuleProxy/index.d.cts.map +1 -0
- package/dist/browser/AbstractModuleProxy/index.d.mts +2 -0
- package/dist/browser/AbstractModuleProxy/index.d.mts.map +1 -0
- package/dist/browser/AbstractModuleProxy/index.d.ts +2 -0
- package/dist/browser/AbstractModuleProxy/index.d.ts.map +1 -0
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.cts +51 -15
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.cts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.mts +51 -15
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.mts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.ts +51 -15
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.ts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusClient.d.cts +14 -45
- package/dist/browser/AsyncQueryBus/AsyncQueryBusClient.d.cts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusClient.d.mts +14 -45
- package/dist/browser/AsyncQueryBus/AsyncQueryBusClient.d.mts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusClient.d.ts +14 -45
- package/dist/browser/AsyncQueryBus/AsyncQueryBusClient.d.ts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.cts +37 -0
- package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.cts.map +1 -0
- package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.mts +37 -0
- package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.mts.map +1 -0
- package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.ts +37 -0
- package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.ts.map +1 -0
- package/dist/browser/AsyncQueryBus/Config.d.cts +21 -31
- package/dist/browser/AsyncQueryBus/Config.d.cts.map +1 -1
- package/dist/browser/AsyncQueryBus/Config.d.mts +21 -31
- package/dist/browser/AsyncQueryBus/Config.d.mts.map +1 -1
- package/dist/browser/AsyncQueryBus/Config.d.ts +21 -31
- package/dist/browser/AsyncQueryBus/Config.d.ts.map +1 -1
- package/dist/browser/AsyncQueryBus/ModuleHost/ModuleHost.d.cts +12 -0
- package/dist/browser/AsyncQueryBus/ModuleHost/ModuleHost.d.cts.map +1 -0
- package/dist/browser/AsyncQueryBus/ModuleHost/ModuleHost.d.mts +12 -0
- package/dist/browser/AsyncQueryBus/ModuleHost/ModuleHost.d.mts.map +1 -0
- package/dist/browser/AsyncQueryBus/ModuleHost/ModuleHost.d.ts +12 -0
- package/dist/browser/AsyncQueryBus/ModuleHost/ModuleHost.d.ts.map +1 -0
- package/dist/browser/AsyncQueryBus/ModuleHost/index.d.cts +2 -0
- package/dist/browser/AsyncQueryBus/ModuleHost/index.d.cts.map +1 -0
- package/dist/browser/AsyncQueryBus/ModuleHost/index.d.mts +2 -0
- package/dist/browser/AsyncQueryBus/ModuleHost/index.d.mts.map +1 -0
- package/dist/browser/AsyncQueryBus/ModuleHost/index.d.ts +2 -0
- package/dist/browser/AsyncQueryBus/ModuleHost/index.d.ts.map +1 -0
- package/dist/browser/AsyncQueryBus/ModuleProxy/ModuleProxy.d.cts +12 -0
- package/dist/browser/AsyncQueryBus/ModuleProxy/ModuleProxy.d.cts.map +1 -0
- package/dist/browser/AsyncQueryBus/ModuleProxy/ModuleProxy.d.mts +12 -0
- package/dist/browser/AsyncQueryBus/ModuleProxy/ModuleProxy.d.mts.map +1 -0
- package/dist/browser/AsyncQueryBus/ModuleProxy/ModuleProxy.d.ts +12 -0
- package/dist/browser/AsyncQueryBus/ModuleProxy/ModuleProxy.d.ts.map +1 -0
- package/dist/browser/AsyncQueryBus/ModuleProxy/index.d.cts +2 -0
- package/dist/browser/AsyncQueryBus/ModuleProxy/index.d.cts.map +1 -0
- package/dist/browser/AsyncQueryBus/ModuleProxy/index.d.mts +2 -0
- package/dist/browser/AsyncQueryBus/ModuleProxy/index.d.mts.map +1 -0
- package/dist/browser/AsyncQueryBus/ModuleProxy/index.d.ts +2 -0
- package/dist/browser/AsyncQueryBus/ModuleProxy/index.d.ts.map +1 -0
- package/dist/browser/AsyncQueryBus/Params.d.cts +5 -3
- package/dist/browser/AsyncQueryBus/Params.d.cts.map +1 -1
- package/dist/browser/AsyncQueryBus/Params.d.mts +5 -3
- package/dist/browser/AsyncQueryBus/Params.d.mts.map +1 -1
- package/dist/browser/AsyncQueryBus/Params.d.ts +5 -3
- package/dist/browser/AsyncQueryBus/Params.d.ts.map +1 -1
- package/dist/browser/AsyncQueryBus/index.d.cts +3 -1
- package/dist/browser/AsyncQueryBus/index.d.cts.map +1 -1
- package/dist/browser/AsyncQueryBus/index.d.mts +3 -1
- package/dist/browser/AsyncQueryBus/index.d.mts.map +1 -1
- package/dist/browser/AsyncQueryBus/index.d.ts +3 -1
- package/dist/browser/AsyncQueryBus/index.d.ts.map +1 -1
- package/dist/browser/Config.d.cts +5 -2
- package/dist/browser/Config.d.cts.map +1 -1
- package/dist/browser/Config.d.mts +5 -2
- package/dist/browser/Config.d.mts.map +1 -1
- package/dist/browser/Config.d.ts +5 -2
- package/dist/browser/Config.d.ts.map +1 -1
- package/dist/browser/PubSubBridge.d.cts +4 -10
- package/dist/browser/PubSubBridge.d.cts.map +1 -1
- package/dist/browser/PubSubBridge.d.mts +4 -10
- package/dist/browser/PubSubBridge.d.mts.map +1 -1
- package/dist/browser/PubSubBridge.d.ts +4 -10
- package/dist/browser/PubSubBridge.d.ts.map +1 -1
- package/dist/browser/index.cjs +331 -126
- 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 +332 -127
- package/dist/browser/index.js.map +1 -1
- package/dist/node/AbstractModuleHost/AbstractModuleHost.d.cts +11 -0
- package/dist/node/AbstractModuleHost/AbstractModuleHost.d.cts.map +1 -0
- package/dist/node/AbstractModuleHost/AbstractModuleHost.d.mts +11 -0
- package/dist/node/AbstractModuleHost/AbstractModuleHost.d.mts.map +1 -0
- package/dist/node/AbstractModuleHost/AbstractModuleHost.d.ts +11 -0
- package/dist/node/AbstractModuleHost/AbstractModuleHost.d.ts.map +1 -0
- package/dist/node/AbstractModuleHost/index.d.cts +2 -0
- package/dist/node/AbstractModuleHost/index.d.cts.map +1 -0
- package/dist/node/AbstractModuleHost/index.d.mts +2 -0
- package/dist/node/AbstractModuleHost/index.d.mts.map +1 -0
- package/dist/node/AbstractModuleHost/index.d.ts +2 -0
- package/dist/node/AbstractModuleHost/index.d.ts.map +1 -0
- package/dist/node/AbstractModuleProxy/AbstractModuleProxy.d.cts +90 -0
- package/dist/node/AbstractModuleProxy/AbstractModuleProxy.d.cts.map +1 -0
- package/dist/node/AbstractModuleProxy/AbstractModuleProxy.d.mts +90 -0
- package/dist/node/AbstractModuleProxy/AbstractModuleProxy.d.mts.map +1 -0
- package/dist/node/AbstractModuleProxy/AbstractModuleProxy.d.ts +90 -0
- package/dist/node/AbstractModuleProxy/AbstractModuleProxy.d.ts.map +1 -0
- package/dist/node/AbstractModuleProxy/index.d.cts +2 -0
- package/dist/node/AbstractModuleProxy/index.d.cts.map +1 -0
- package/dist/node/AbstractModuleProxy/index.d.mts +2 -0
- package/dist/node/AbstractModuleProxy/index.d.mts.map +1 -0
- package/dist/node/AbstractModuleProxy/index.d.ts +2 -0
- package/dist/node/AbstractModuleProxy/index.d.ts.map +1 -0
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.cts +51 -15
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.cts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.mts +51 -15
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.mts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.ts +51 -15
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.ts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusClient.d.cts +14 -45
- package/dist/node/AsyncQueryBus/AsyncQueryBusClient.d.cts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusClient.d.mts +14 -45
- package/dist/node/AsyncQueryBus/AsyncQueryBusClient.d.mts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusClient.d.ts +14 -45
- package/dist/node/AsyncQueryBus/AsyncQueryBusClient.d.ts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.cts +37 -0
- package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.cts.map +1 -0
- package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.mts +37 -0
- package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.mts.map +1 -0
- package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.ts +37 -0
- package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.ts.map +1 -0
- package/dist/node/AsyncQueryBus/Config.d.cts +21 -31
- package/dist/node/AsyncQueryBus/Config.d.cts.map +1 -1
- package/dist/node/AsyncQueryBus/Config.d.mts +21 -31
- package/dist/node/AsyncQueryBus/Config.d.mts.map +1 -1
- package/dist/node/AsyncQueryBus/Config.d.ts +21 -31
- package/dist/node/AsyncQueryBus/Config.d.ts.map +1 -1
- package/dist/node/AsyncQueryBus/ModuleHost/ModuleHost.d.cts +12 -0
- package/dist/node/AsyncQueryBus/ModuleHost/ModuleHost.d.cts.map +1 -0
- package/dist/node/AsyncQueryBus/ModuleHost/ModuleHost.d.mts +12 -0
- package/dist/node/AsyncQueryBus/ModuleHost/ModuleHost.d.mts.map +1 -0
- package/dist/node/AsyncQueryBus/ModuleHost/ModuleHost.d.ts +12 -0
- package/dist/node/AsyncQueryBus/ModuleHost/ModuleHost.d.ts.map +1 -0
- package/dist/node/AsyncQueryBus/ModuleHost/index.d.cts +2 -0
- package/dist/node/AsyncQueryBus/ModuleHost/index.d.cts.map +1 -0
- package/dist/node/AsyncQueryBus/ModuleHost/index.d.mts +2 -0
- package/dist/node/AsyncQueryBus/ModuleHost/index.d.mts.map +1 -0
- package/dist/node/AsyncQueryBus/ModuleHost/index.d.ts +2 -0
- package/dist/node/AsyncQueryBus/ModuleHost/index.d.ts.map +1 -0
- package/dist/node/AsyncQueryBus/ModuleProxy/ModuleProxy.d.cts +12 -0
- package/dist/node/AsyncQueryBus/ModuleProxy/ModuleProxy.d.cts.map +1 -0
- package/dist/node/AsyncQueryBus/ModuleProxy/ModuleProxy.d.mts +12 -0
- package/dist/node/AsyncQueryBus/ModuleProxy/ModuleProxy.d.mts.map +1 -0
- package/dist/node/AsyncQueryBus/ModuleProxy/ModuleProxy.d.ts +12 -0
- package/dist/node/AsyncQueryBus/ModuleProxy/ModuleProxy.d.ts.map +1 -0
- package/dist/node/AsyncQueryBus/ModuleProxy/index.d.cts +2 -0
- package/dist/node/AsyncQueryBus/ModuleProxy/index.d.cts.map +1 -0
- package/dist/node/AsyncQueryBus/ModuleProxy/index.d.mts +2 -0
- package/dist/node/AsyncQueryBus/ModuleProxy/index.d.mts.map +1 -0
- package/dist/node/AsyncQueryBus/ModuleProxy/index.d.ts +2 -0
- package/dist/node/AsyncQueryBus/ModuleProxy/index.d.ts.map +1 -0
- package/dist/node/AsyncQueryBus/Params.d.cts +5 -3
- package/dist/node/AsyncQueryBus/Params.d.cts.map +1 -1
- package/dist/node/AsyncQueryBus/Params.d.mts +5 -3
- package/dist/node/AsyncQueryBus/Params.d.mts.map +1 -1
- package/dist/node/AsyncQueryBus/Params.d.ts +5 -3
- package/dist/node/AsyncQueryBus/Params.d.ts.map +1 -1
- package/dist/node/AsyncQueryBus/index.d.cts +3 -1
- package/dist/node/AsyncQueryBus/index.d.cts.map +1 -1
- package/dist/node/AsyncQueryBus/index.d.mts +3 -1
- package/dist/node/AsyncQueryBus/index.d.mts.map +1 -1
- package/dist/node/AsyncQueryBus/index.d.ts +3 -1
- package/dist/node/AsyncQueryBus/index.d.ts.map +1 -1
- package/dist/node/Config.d.cts +5 -2
- package/dist/node/Config.d.cts.map +1 -1
- package/dist/node/Config.d.mts +5 -2
- package/dist/node/Config.d.mts.map +1 -1
- package/dist/node/Config.d.ts +5 -2
- package/dist/node/Config.d.ts.map +1 -1
- package/dist/node/PubSubBridge.d.cts +4 -10
- package/dist/node/PubSubBridge.d.cts.map +1 -1
- package/dist/node/PubSubBridge.d.mts +4 -10
- package/dist/node/PubSubBridge.d.mts.map +1 -1
- package/dist/node/PubSubBridge.d.ts +4 -10
- package/dist/node/PubSubBridge.d.ts.map +1 -1
- package/dist/node/index.cjs +355 -144
- 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 +352 -144
- package/dist/node/index.js.map +1 -1
- package/package.json +30 -24
- package/src/AbstractModuleHost/AbstractModuleHost.ts +12 -0
- package/src/AbstractModuleHost/index.ts +1 -0
- package/src/AbstractModuleProxy/AbstractModuleProxy.ts +239 -0
- package/src/AbstractModuleProxy/index.ts +1 -0
- package/src/AsyncQueryBus/AsyncQueryBusBase.ts +11 -33
- package/src/AsyncQueryBus/AsyncQueryBusClient.ts +69 -61
- package/src/AsyncQueryBus/{AsyncQueryBusServer.ts → AsyncQueryBusHost.ts} +32 -26
- package/src/AsyncQueryBus/Config.ts +23 -33
- package/src/AsyncQueryBus/ModuleHost/ModuleHost.ts +29 -0
- package/src/AsyncQueryBus/ModuleHost/index.ts +1 -0
- package/src/AsyncQueryBus/ModuleProxy/ModuleProxy.ts +19 -0
- package/src/AsyncQueryBus/ModuleProxy/index.ts +1 -0
- package/src/AsyncQueryBus/Params.ts +6 -3
- package/src/AsyncQueryBus/index.ts +3 -1
- package/src/Config.ts +5 -2
- package/src/PubSubBridge.ts +10 -12
- package/src/index.ts +1 -0
- package/dist/browser/AsyncQueryBus/AsyncQueryBusServer.d.cts +0 -75
- package/dist/browser/AsyncQueryBus/AsyncQueryBusServer.d.cts.map +0 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusServer.d.mts +0 -75
- package/dist/browser/AsyncQueryBus/AsyncQueryBusServer.d.mts.map +0 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusServer.d.ts +0 -75
- package/dist/browser/AsyncQueryBus/AsyncQueryBusServer.d.ts.map +0 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusServer.d.cts +0 -75
- package/dist/node/AsyncQueryBus/AsyncQueryBusServer.d.cts.map +0 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusServer.d.mts +0 -75
- package/dist/node/AsyncQueryBus/AsyncQueryBusServer.d.mts.map +0 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusServer.d.ts +0 -75
- package/dist/node/AsyncQueryBus/AsyncQueryBusServer.d.ts.map +0 -1
|
@@ -3,18 +3,15 @@ import { Address } from '@xylabs/hex'
|
|
|
3
3
|
import { Base } from '@xylabs/object'
|
|
4
4
|
import { asArchivistInstance } from '@xyo-network/archivist-model'
|
|
5
5
|
import { BoundWitness, QueryBoundWitness } from '@xyo-network/boundwitness-model'
|
|
6
|
-
import { CacheConfig } from '@xyo-network/bridge-model'
|
|
7
6
|
import { BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload } from '@xyo-network/diviner-boundwitness-model'
|
|
8
7
|
import { asDivinerInstance, DivinerInstance } from '@xyo-network/diviner-model'
|
|
9
|
-
import { ModuleConfig
|
|
8
|
+
import { ModuleConfig } from '@xyo-network/module-model'
|
|
10
9
|
import { LRUCache } from 'lru-cache'
|
|
11
10
|
|
|
12
|
-
import { Pending } from './Config'
|
|
13
11
|
import { AsyncQueryBusParams } from './Params'
|
|
14
12
|
|
|
15
13
|
export class AsyncQueryBusBase<TParams extends AsyncQueryBusParams = AsyncQueryBusParams> extends Base<TParams> {
|
|
16
14
|
protected _lastState?: LRUCache<Address, number>
|
|
17
|
-
protected _queryCache?: LRUCache<Address, Pending | ModuleQueryResult>
|
|
18
15
|
protected _targetConfigs: Record<Address, ModuleConfig> = {}
|
|
19
16
|
protected _targetQueries: Record<Address, string[]> = {}
|
|
20
17
|
|
|
@@ -22,21 +19,12 @@ export class AsyncQueryBusBase<TParams extends AsyncQueryBusParams = AsyncQueryB
|
|
|
22
19
|
super(params)
|
|
23
20
|
}
|
|
24
21
|
|
|
25
|
-
get config() {
|
|
22
|
+
get config(): TParams['config'] {
|
|
26
23
|
return this.params.config
|
|
27
24
|
}
|
|
28
25
|
|
|
29
|
-
get individualAddressBatchQueryLimitConfig(): number {
|
|
30
|
-
return this.config.individualAddressBatchQueryLimit ?? 10
|
|
31
|
-
}
|
|
32
|
-
|
|
33
26
|
get pollFrequencyConfig(): number {
|
|
34
|
-
return this.config
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
get queryCacheConfig(): LRUCache.Options<Address, Pending | ModuleQueryResult, unknown> {
|
|
38
|
-
const queryCacheConfig: CacheConfig | undefined = this.config.queryCache === true ? {} : this.config.queryCache
|
|
39
|
-
return { max: 100, ttl: 1000 * 60, ...queryCacheConfig }
|
|
27
|
+
return this.config?.pollFrequency ?? 1000
|
|
40
28
|
}
|
|
41
29
|
|
|
42
30
|
get resolver() {
|
|
@@ -52,41 +40,31 @@ export class AsyncQueryBusBase<TParams extends AsyncQueryBusParams = AsyncQueryB
|
|
|
52
40
|
return this._lastState
|
|
53
41
|
}
|
|
54
42
|
|
|
55
|
-
/**
|
|
56
|
-
* A cache of queries that have been issued
|
|
57
|
-
*/
|
|
58
|
-
protected get queryCache(): LRUCache<Address, Pending | ModuleQueryResult> {
|
|
59
|
-
const config = this.queryCacheConfig
|
|
60
|
-
const requiredConfig = { noUpdateTTL: false, ttlAutopurge: true }
|
|
61
|
-
this._queryCache = this._queryCache ?? new LRUCache<Address, Pending | ModuleQueryResult>({ ...config, ...requiredConfig })
|
|
62
|
-
return this._queryCache
|
|
63
|
-
}
|
|
64
|
-
|
|
65
43
|
async queriesArchivist() {
|
|
66
44
|
return assertEx(
|
|
67
|
-
asArchivistInstance(await this.resolver.resolve(this.config
|
|
68
|
-
() => `Unable to resolve queriesArchivist [${this.config
|
|
45
|
+
asArchivistInstance(await this.resolver.resolve(this.config?.clearingHouse?.queries?.archivist)),
|
|
46
|
+
() => `Unable to resolve queriesArchivist [${this.config?.clearingHouse?.queries?.archivist}]`,
|
|
69
47
|
)
|
|
70
48
|
}
|
|
71
49
|
|
|
72
50
|
async queriesDiviner() {
|
|
73
51
|
return assertEx(
|
|
74
|
-
asDivinerInstance(await this.resolver.resolve(this.config
|
|
75
|
-
() => `Unable to resolve queriesDiviner [${this.config
|
|
52
|
+
asDivinerInstance(await this.resolver.resolve(this.config?.clearingHouse?.queries?.boundWitnessDiviner)),
|
|
53
|
+
() => `Unable to resolve queriesDiviner [${this.config?.clearingHouse?.queries?.boundWitnessDiviner}]`,
|
|
76
54
|
) as DivinerInstance<BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, QueryBoundWitness>
|
|
77
55
|
}
|
|
78
56
|
|
|
79
57
|
async responsesArchivist() {
|
|
80
58
|
return assertEx(
|
|
81
|
-
asArchivistInstance(await this.resolver.resolve(this.config
|
|
82
|
-
() => `Unable to resolve responsesArchivist [${this.config
|
|
59
|
+
asArchivistInstance(await this.resolver.resolve(this.config?.clearingHouse?.responses?.archivist)),
|
|
60
|
+
() => `Unable to resolve responsesArchivist [${this.config?.clearingHouse?.responses?.archivist}]`,
|
|
83
61
|
)
|
|
84
62
|
}
|
|
85
63
|
|
|
86
64
|
async responsesDiviner() {
|
|
87
65
|
return assertEx(
|
|
88
|
-
asDivinerInstance(await this.resolver.resolve(this.config
|
|
89
|
-
() => `Unable to resolve responsesDiviner [${this.config
|
|
66
|
+
asDivinerInstance(await this.resolver.resolve(this.config?.clearingHouse?.responses?.boundWitnessDiviner)),
|
|
67
|
+
() => `Unable to resolve responsesDiviner [${this.config?.clearingHouse?.responses?.boundWitnessDiviner}]`,
|
|
90
68
|
) as DivinerInstance<BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitness>
|
|
91
69
|
}
|
|
92
70
|
|
|
@@ -1,42 +1,49 @@
|
|
|
1
|
-
import { assertEx } from '@xylabs/assert'
|
|
2
1
|
import { delay } from '@xylabs/delay'
|
|
3
2
|
import { forget } from '@xylabs/forget'
|
|
4
3
|
import { Address } from '@xylabs/hex'
|
|
5
4
|
import { clearTimeoutEx, setTimeoutEx } from '@xylabs/timer'
|
|
6
5
|
import { isBoundWitnessWithMeta, QueryBoundWitness } from '@xyo-network/boundwitness-model'
|
|
6
|
+
import { CacheConfig } from '@xyo-network/bridge-model'
|
|
7
7
|
import { BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'
|
|
8
|
-
import {
|
|
8
|
+
import { ModuleQueryResult } from '@xyo-network/module-model'
|
|
9
9
|
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
10
10
|
import { ModuleError, Payload, PayloadWithMeta, WithMeta } from '@xyo-network/payload-model'
|
|
11
|
+
import { LRUCache } from 'lru-cache'
|
|
11
12
|
|
|
12
13
|
import { AsyncQueryBusBase } from './AsyncQueryBusBase'
|
|
13
14
|
import { Pending } from './Config'
|
|
14
|
-
import {
|
|
15
|
+
import { AsyncQueryBusClientParams } from './Params'
|
|
15
16
|
|
|
16
|
-
export class AsyncQueryBusClient<TParams extends
|
|
17
|
+
export class AsyncQueryBusClient<TParams extends AsyncQueryBusClientParams = AsyncQueryBusClientParams> extends AsyncQueryBusBase<TParams> {
|
|
18
|
+
protected _queryCache?: LRUCache<Address, Pending | ModuleQueryResult>
|
|
19
|
+
private _pollCount = 0
|
|
17
20
|
private _pollId?: string
|
|
18
21
|
|
|
19
22
|
constructor(params: TParams) {
|
|
20
23
|
super(params)
|
|
21
24
|
}
|
|
22
25
|
|
|
26
|
+
get queryCacheConfig(): LRUCache.Options<Address, Pending | ModuleQueryResult, unknown> {
|
|
27
|
+
const queryCacheConfig: CacheConfig | undefined = this.config?.queryCache === true ? {} : this.config?.queryCache
|
|
28
|
+
return { max: 100, ttl: 1000 * 60, ...queryCacheConfig }
|
|
29
|
+
}
|
|
30
|
+
|
|
23
31
|
get started() {
|
|
24
32
|
return !!this._pollId
|
|
25
33
|
}
|
|
26
34
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return mods
|
|
35
|
+
/**
|
|
36
|
+
* A cache of queries that have been issued
|
|
37
|
+
*/
|
|
38
|
+
protected get queryCache(): LRUCache<Address, Pending | ModuleQueryResult> {
|
|
39
|
+
const config = this.queryCacheConfig
|
|
40
|
+
const requiredConfig = { noUpdateTTL: false, ttlAutopurge: true }
|
|
41
|
+
this._queryCache = this._queryCache ?? new LRUCache<Address, Pending | ModuleQueryResult>({ ...config, ...requiredConfig })
|
|
42
|
+
return this._queryCache
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
listeningAddresses() {
|
|
46
|
+
return this._queryCache?.keys()
|
|
40
47
|
}
|
|
41
48
|
|
|
42
49
|
async send(address: Address, query: QueryBoundWitness, payloads?: Payload[] | undefined): Promise<ModuleQueryResult> {
|
|
@@ -45,11 +52,6 @@ export class AsyncQueryBusClient<TParams extends AsyncQueryBusParams = AsyncQuer
|
|
|
45
52
|
const routedQuery = await PayloadBuilder.build({ ...query, $meta })
|
|
46
53
|
const queryArchivist = await this.queriesArchivist()
|
|
47
54
|
|
|
48
|
-
const sourceAddress = query.addresses.at(0)
|
|
49
|
-
if (sourceAddress && !this.config.listeningModules?.includes(sourceAddress)) {
|
|
50
|
-
this.config.listeningModules?.push(sourceAddress)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
55
|
// TODO: Should we always re-hash to true up timestamps? We can't
|
|
54
56
|
// re-sign correctly so we would lose that information if we did and
|
|
55
57
|
// would also be replying to consumers with a different query hash than
|
|
@@ -71,53 +73,43 @@ export class AsyncQueryBusClient<TParams extends AsyncQueryBusParams = AsyncQuer
|
|
|
71
73
|
const context = new Promise<ModuleQueryResult>((resolve) => {
|
|
72
74
|
this.logger?.debug(`Polling for response to query: ${routedQueryHash}`)
|
|
73
75
|
const pollForResponse = async () => {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
//
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
76
|
+
try {
|
|
77
|
+
this.start()
|
|
78
|
+
let response = this.queryCache.get(routedQueryHash)
|
|
79
|
+
// Poll for response until cache key expires (response timed out)
|
|
80
|
+
while (response !== undefined) {
|
|
81
|
+
// Wait a bit
|
|
82
|
+
await delay(100)
|
|
83
|
+
// Check the status of the response
|
|
84
|
+
response = this.queryCache.get(routedQueryHash)
|
|
85
|
+
// If status is no longer pending that means we received a response
|
|
86
|
+
if (response && response !== Pending) {
|
|
87
|
+
this.logger?.debug(`Returning response to query: ${routedQueryHash}`)
|
|
88
|
+
resolve(response)
|
|
89
|
+
return
|
|
90
|
+
}
|
|
86
91
|
}
|
|
92
|
+
// If we got here waiting for a response timed out
|
|
93
|
+
this.logger?.error('Timeout waiting for query response')
|
|
94
|
+
// Resolve with error to match what a local module would do if it were to error
|
|
95
|
+
// TODO: BW Builder/Sign result as this module?
|
|
96
|
+
const error: ModuleError = {
|
|
97
|
+
message: 'Timeout waiting for query response',
|
|
98
|
+
query: 'network.xyo.boundwitness',
|
|
99
|
+
schema: 'network.xyo.error.module',
|
|
100
|
+
sources: [routedQueryHash],
|
|
101
|
+
}
|
|
102
|
+
resolve([routedQuery, [], [await PayloadBuilder.build(error)]])
|
|
103
|
+
return
|
|
104
|
+
} finally {
|
|
105
|
+
this.stop()
|
|
87
106
|
}
|
|
88
|
-
// If we got here waiting for a response timed out
|
|
89
|
-
this.logger?.error('Timeout waiting for query response')
|
|
90
|
-
// Resolve with error to match what a local module would do if it were to error
|
|
91
|
-
// TODO: BW Builder/Sign result as this module?
|
|
92
|
-
const error: ModuleError = {
|
|
93
|
-
message: 'Timeout waiting for query response',
|
|
94
|
-
query: 'network.xyo.boundwitness',
|
|
95
|
-
schema: 'network.xyo.error.module',
|
|
96
|
-
sources: [routedQueryHash],
|
|
97
|
-
}
|
|
98
|
-
resolve([routedQuery, [], [await PayloadBuilder.build(error)]])
|
|
99
|
-
return
|
|
100
107
|
}
|
|
101
108
|
forget(pollForResponse())
|
|
102
109
|
})
|
|
103
110
|
return context
|
|
104
111
|
}
|
|
105
112
|
|
|
106
|
-
start() {
|
|
107
|
-
if (this.started) {
|
|
108
|
-
console.warn('AsyncQueryBus starting when already started')
|
|
109
|
-
}
|
|
110
|
-
this.poll()
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
stop() {
|
|
114
|
-
if (!this.started) {
|
|
115
|
-
console.warn('AsyncQueryBus stopping when already stopped')
|
|
116
|
-
}
|
|
117
|
-
if (this._pollId) clearTimeoutEx(this._pollId)
|
|
118
|
-
this._pollId = undefined
|
|
119
|
-
}
|
|
120
|
-
|
|
121
113
|
/**
|
|
122
114
|
* Runs the background divine process on a loop with a delay
|
|
123
115
|
* specified by the `config.pollFrequency`
|
|
@@ -162,4 +154,20 @@ export class AsyncQueryBusClient<TParams extends AsyncQueryBusParams = AsyncQuer
|
|
|
162
154
|
}),
|
|
163
155
|
)
|
|
164
156
|
}
|
|
157
|
+
|
|
158
|
+
private start() {
|
|
159
|
+
if (this._pollCount === 0) {
|
|
160
|
+
this.poll()
|
|
161
|
+
}
|
|
162
|
+
this._pollCount++
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
private stop() {
|
|
166
|
+
this._pollCount--
|
|
167
|
+
if (this._pollCount <= 0) {
|
|
168
|
+
if (this._pollId) clearTimeoutEx(this._pollId)
|
|
169
|
+
this._pollId = undefined
|
|
170
|
+
this._pollCount = 0
|
|
171
|
+
}
|
|
172
|
+
}
|
|
165
173
|
}
|
|
@@ -6,30 +6,35 @@ import { isQueryBoundWitnessWithMeta, QueryBoundWitness } from '@xyo-network/bou
|
|
|
6
6
|
import { BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'
|
|
7
7
|
import { asModuleInstance, ModuleInstance } from '@xyo-network/module-model'
|
|
8
8
|
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
9
|
+
import { WithMeta } from '@xyo-network/payload-model'
|
|
9
10
|
|
|
10
11
|
import { AsyncQueryBusBase } from './AsyncQueryBusBase'
|
|
11
|
-
import {
|
|
12
|
+
import { AsyncQueryBusHostParams } from './Params'
|
|
12
13
|
|
|
13
|
-
export class
|
|
14
|
+
export class AsyncQueryBusHost<TParams extends AsyncQueryBusHostParams = AsyncQueryBusHostParams> extends AsyncQueryBusBase<TParams> {
|
|
14
15
|
private _pollId?: string
|
|
15
16
|
|
|
16
17
|
constructor(params: TParams) {
|
|
17
18
|
super(params)
|
|
18
19
|
}
|
|
19
20
|
|
|
21
|
+
get perAddressBatchQueryLimit(): number {
|
|
22
|
+
return this.config?.perAddressBatchQueryLimit ?? 10
|
|
23
|
+
}
|
|
24
|
+
|
|
20
25
|
get started() {
|
|
21
26
|
return !!this._pollId
|
|
22
27
|
}
|
|
23
28
|
|
|
24
|
-
async listeningModules() {
|
|
29
|
+
async listeningModules(): Promise<ModuleInstance[]> {
|
|
25
30
|
const mods =
|
|
26
|
-
this.config
|
|
31
|
+
this.config?.listeningModules ?
|
|
27
32
|
await Promise.all(
|
|
28
33
|
this.config.listeningModules.map(async (listeningModule) =>
|
|
29
34
|
assertEx(asModuleInstance(await this.resolver.resolve(listeningModule)), () => `Unable to resolve listeningModule [${listeningModule}]`),
|
|
30
35
|
),
|
|
31
36
|
)
|
|
32
|
-
: await this.resolver.resolve({ direction: '
|
|
37
|
+
: await this.resolver.resolve(undefined, { direction: 'down' })
|
|
33
38
|
return mods
|
|
34
39
|
}
|
|
35
40
|
|
|
@@ -48,46 +53,47 @@ export class AsyncQueryBusServer<TParams extends AsyncQueryBusParams = AsyncQuer
|
|
|
48
53
|
this._pollId = undefined
|
|
49
54
|
}
|
|
50
55
|
|
|
51
|
-
protected callLocalModule = async (localModule: ModuleInstance,
|
|
56
|
+
protected callLocalModule = async (localModule: ModuleInstance, query: WithMeta<QueryBoundWitness>) => {
|
|
57
|
+
//console.log(`callLocalModule: ${query.$hash}`)
|
|
52
58
|
const localModuleName = localModule.config.name ?? localModule.address
|
|
53
59
|
const queryArchivist = await this.queriesArchivist()
|
|
54
60
|
const responseArchivist = await this.responsesArchivist()
|
|
55
|
-
const commandDestination = (
|
|
61
|
+
const commandDestination = (query.$meta as { destination?: string[] })?.destination
|
|
56
62
|
if (commandDestination && commandDestination?.includes(localModule.address)) {
|
|
57
63
|
// Find the query
|
|
58
|
-
const queryIndex =
|
|
64
|
+
const queryIndex = query.payload_hashes.indexOf(query.query)
|
|
59
65
|
if (queryIndex !== -1) {
|
|
60
|
-
const querySchema =
|
|
66
|
+
const querySchema = query.payload_schemas[queryIndex]
|
|
61
67
|
// If the destination can process this type of query
|
|
62
68
|
if (localModule.queries.includes(querySchema)) {
|
|
63
69
|
// Get the associated payloads
|
|
64
|
-
const commandPayloads = await queryArchivist.get(
|
|
70
|
+
const commandPayloads = await queryArchivist.get(query.payload_hashes)
|
|
65
71
|
const commandPayloadsDict = await PayloadBuilder.toAllHashMap(commandPayloads)
|
|
66
|
-
const commandHash = (await PayloadBuilder.build(
|
|
72
|
+
const commandHash = (await PayloadBuilder.build(query)).$hash
|
|
67
73
|
// Check that we have all the arguments for the command
|
|
68
|
-
if (!containsAll(Object.keys(commandPayloadsDict),
|
|
74
|
+
if (!containsAll(Object.keys(commandPayloadsDict), query.payload_hashes)) {
|
|
69
75
|
this.logger?.error(`Error processing command ${commandHash} for module ${localModuleName}, missing payloads`)
|
|
70
76
|
return
|
|
71
77
|
}
|
|
72
78
|
try {
|
|
73
79
|
// Issue the query against module
|
|
74
|
-
const commandSchema = commandPayloadsDict[
|
|
80
|
+
const commandSchema = commandPayloadsDict[query.query].schema
|
|
75
81
|
this.logger?.debug(`Issuing command ${commandSchema} (${commandHash}) addressed to module: ${localModuleName}`)
|
|
76
|
-
const response = await localModule.query(
|
|
82
|
+
const response = await localModule.query(query, commandPayloads)
|
|
77
83
|
const [bw, payloads, errors] = response
|
|
78
84
|
this.logger?.debug(`Replying to command ${commandHash} addressed to module: ${localModuleName}`)
|
|
79
85
|
const insertResult = await responseArchivist.insert([bw, ...payloads, ...errors])
|
|
80
86
|
// NOTE: If all archivists support the contract that numPayloads inserted === numPayloads returned we can
|
|
81
87
|
// do some deeper assertions here like lenIn === lenOut, but for now this should be good enough since BWs
|
|
82
88
|
// should always be unique causing at least one insertion
|
|
83
|
-
if (insertResult.length
|
|
89
|
+
if (insertResult.length === 0) {
|
|
84
90
|
this.logger?.error(`Error replying to command ${commandHash} addressed to module: ${localModuleName}`)
|
|
85
91
|
}
|
|
86
|
-
if (
|
|
92
|
+
if (query?.timestamp) {
|
|
87
93
|
// TODO: This needs to be thought through as we can't use a distributed timestamp
|
|
88
94
|
// because of collisions. We need to ensure we are using the timestamp of the store
|
|
89
95
|
// so there's no chance of multiple commands at the same time
|
|
90
|
-
await this.commitState(localModule.address,
|
|
96
|
+
await this.commitState(localModule.address, query.timestamp)
|
|
91
97
|
}
|
|
92
98
|
} catch (error) {
|
|
93
99
|
this.logger?.error(`Error processing command ${commandHash} for module ${localModuleName}: ${error}`)
|
|
@@ -101,22 +107,22 @@ export class AsyncQueryBusServer<TParams extends AsyncQueryBusParams = AsyncQuer
|
|
|
101
107
|
* Finds unprocessed commands addressed to the supplied address
|
|
102
108
|
* @param address The address to find commands for
|
|
103
109
|
*/
|
|
104
|
-
protected
|
|
110
|
+
protected findQueriesToAddress = async (address: Address) => {
|
|
105
111
|
const queryBoundWitnessDiviner = await this.queriesDiviner()
|
|
106
112
|
// Retrieve last offset from state store
|
|
107
113
|
const timestamp = await this.retrieveState(address)
|
|
108
114
|
const destination = [address]
|
|
109
|
-
const limit = this.
|
|
115
|
+
const limit = this.perAddressBatchQueryLimit
|
|
110
116
|
// Filter for commands to us by destination address
|
|
111
117
|
const divinerQuery = { destination, limit, schema: BoundWitnessDivinerQuerySchema, sort: 'asc', timestamp }
|
|
112
118
|
const result = await queryBoundWitnessDiviner.divine([divinerQuery])
|
|
113
|
-
const
|
|
114
|
-
const nextState = Math.max(...
|
|
119
|
+
const queries = result.filter(isQueryBoundWitnessWithMeta)
|
|
120
|
+
const nextState = queries.length > 0 ? Math.max(...queries.map((c) => c.timestamp ?? 0)) + 1 : timestamp
|
|
115
121
|
// TODO: This needs to be thought through as we can't use a distributed timestamp
|
|
116
122
|
// because of collisions. We need to use the timestamp of the store so there's no
|
|
117
123
|
// chance of multiple commands at the same time
|
|
118
124
|
await this.commitState(address, nextState)
|
|
119
|
-
return
|
|
125
|
+
return queries
|
|
120
126
|
}
|
|
121
127
|
|
|
122
128
|
/**
|
|
@@ -151,11 +157,11 @@ export class AsyncQueryBusServer<TParams extends AsyncQueryBusParams = AsyncQuer
|
|
|
151
157
|
try {
|
|
152
158
|
const localModuleName = localModule.config.name ?? localModule.address
|
|
153
159
|
this.logger?.debug(`Checking for inbound commands to ${localModuleName}`)
|
|
154
|
-
const
|
|
155
|
-
if (
|
|
160
|
+
const queries = await this.findQueriesToAddress(localModule.address)
|
|
161
|
+
if (queries.length === 0) return
|
|
156
162
|
this.logger?.debug(`Found commands addressed to local module: ${localModuleName}`)
|
|
157
|
-
for (const
|
|
158
|
-
await this.callLocalModule(localModule,
|
|
163
|
+
for (const query of queries) {
|
|
164
|
+
await this.callLocalModule(localModule, query)
|
|
159
165
|
}
|
|
160
166
|
} catch (error) {
|
|
161
167
|
this.logger?.error(`Error processing commands for address ${localModule.address}: ${error}`)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CacheConfig } from '@xyo-network/bridge-model'
|
|
2
|
+
import { ModuleIdentifier } from '@xyo-network/module-model'
|
|
2
3
|
|
|
3
4
|
export const Pending = 'pending' as const
|
|
4
5
|
export type Pending = typeof Pending
|
|
@@ -6,67 +7,56 @@ export type Pending = typeof Pending
|
|
|
6
7
|
/**
|
|
7
8
|
* Configuration for searchable storage of local state
|
|
8
9
|
*/
|
|
9
|
-
export interface SearchableStorage
|
|
10
|
+
export interface SearchableStorage {
|
|
10
11
|
/**
|
|
11
12
|
* Name/Address of the archivist where intermediate communications are stored
|
|
12
13
|
*/
|
|
13
|
-
archivist:
|
|
14
|
+
archivist: ModuleIdentifier
|
|
14
15
|
/**
|
|
15
16
|
* Name/Address of the diviner where intermediate communications are filtered
|
|
16
17
|
*/
|
|
17
|
-
boundWitnessDiviner:
|
|
18
|
+
boundWitnessDiviner: ModuleIdentifier
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
* Configuration for the mutually accessible
|
|
22
|
-
* modules between the modules being connected
|
|
23
|
-
*/
|
|
24
|
-
export interface Intermediary<TArchivist = string, TDiviner = string> {
|
|
21
|
+
export interface AsyncQueryBusClearingHouseConfig {
|
|
25
22
|
/**
|
|
26
|
-
*
|
|
27
|
-
*/
|
|
28
|
-
archivist: TArchivist
|
|
29
|
-
/**
|
|
30
|
-
* Name/Address of the diviner where intermediate communications are filtered
|
|
23
|
+
* Configuration for intermediary query storage
|
|
31
24
|
*/
|
|
32
|
-
|
|
33
|
-
}
|
|
25
|
+
queries?: SearchableStorage
|
|
34
26
|
|
|
35
|
-
export interface AsyncQueryBusConfig<TArchivist = string, TDiviner = string> {
|
|
36
27
|
/**
|
|
37
|
-
*
|
|
38
|
-
* for an address
|
|
28
|
+
* Configuration for intermediary response storage
|
|
39
29
|
*/
|
|
40
|
-
|
|
30
|
+
responses?: SearchableStorage
|
|
31
|
+
}
|
|
41
32
|
|
|
42
|
-
|
|
33
|
+
export interface AsyncQueryBusBaseConfig {
|
|
34
|
+
clearingHouse?: AsyncQueryBusClearingHouseConfig
|
|
43
35
|
|
|
44
36
|
/**
|
|
45
37
|
* How often to poll for new queries/responses
|
|
46
38
|
*/
|
|
47
39
|
pollFrequency?: number
|
|
48
|
-
/**
|
|
49
|
-
* Configuration for intermediary query storage
|
|
50
|
-
*/
|
|
51
|
-
queries?: Intermediary<TArchivist, TDiviner>
|
|
52
40
|
|
|
53
41
|
/**
|
|
54
|
-
*
|
|
42
|
+
* Where the archivist should persist its internal state
|
|
55
43
|
*/
|
|
56
|
-
|
|
44
|
+
stateStore?: SearchableStorage
|
|
45
|
+
}
|
|
57
46
|
|
|
47
|
+
export interface AsyncQueryBusClientConfig extends AsyncQueryBusBaseConfig {
|
|
58
48
|
/**
|
|
59
49
|
* Configuration for intermediary response storage
|
|
60
50
|
*/
|
|
61
|
-
|
|
51
|
+
queryCache?: CacheConfig | true
|
|
52
|
+
}
|
|
62
53
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
*/
|
|
66
|
-
rootAddress?: string
|
|
54
|
+
export interface AsyncQueryBusHostConfig extends AsyncQueryBusBaseConfig {
|
|
55
|
+
listeningModules?: string[]
|
|
67
56
|
|
|
68
57
|
/**
|
|
69
|
-
*
|
|
58
|
+
* How many queries to process at once when retrieving queries
|
|
59
|
+
* for an address
|
|
70
60
|
*/
|
|
71
|
-
|
|
61
|
+
perAddressBatchQueryLimit?: number
|
|
72
62
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { AbstractModuleHost, ModuleHostParams } from '../../AbstractModuleHost'
|
|
2
|
+
import { AsyncQueryBusHost } from '../AsyncQueryBusHost'
|
|
3
|
+
import { AsyncQueryBusHostConfig } from '../Config'
|
|
4
|
+
|
|
5
|
+
export type AsyncQueryBusModuleHostParams = ModuleHostParams & {
|
|
6
|
+
config: AsyncQueryBusHostConfig
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class AsyncQueryBusModuleHost extends AbstractModuleHost<AsyncQueryBusModuleHostParams> {
|
|
10
|
+
private _busHost?: AsyncQueryBusHost
|
|
11
|
+
|
|
12
|
+
constructor(params: AsyncQueryBusModuleHostParams) {
|
|
13
|
+
super(params)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
override async start(): Promise<void> {
|
|
17
|
+
const listeningModules =
|
|
18
|
+
this.params.config.listeningModules ?? (await this.params.module.resolve(undefined, { direction: 'down' })).map((m) => m.address)
|
|
19
|
+
this._busHost = new AsyncQueryBusHost({
|
|
20
|
+
config: { ...this.params.config, listeningModules },
|
|
21
|
+
logger: this.params.logger,
|
|
22
|
+
resolver: this.params.module,
|
|
23
|
+
})
|
|
24
|
+
this._busHost?.start()
|
|
25
|
+
}
|
|
26
|
+
override stop() {
|
|
27
|
+
this._busHost?.stop()
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ModuleHost'
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { QueryBoundWitness } from '@xyo-network/boundwitness-model'
|
|
2
|
+
import { Module, ModuleInstance, ModuleQueryResult } from '@xyo-network/module-model'
|
|
3
|
+
import { Payload } from '@xyo-network/payload-model'
|
|
4
|
+
|
|
5
|
+
import { AbstractModuleProxy, ModuleProxyParams } from '../../AbstractModuleProxy'
|
|
6
|
+
import { AsyncQueryBusClient } from '../AsyncQueryBusClient'
|
|
7
|
+
|
|
8
|
+
export type AsyncQueryBusModuleProxyParams = ModuleProxyParams & {
|
|
9
|
+
bridgeClient: AsyncQueryBusClient
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class AsyncQueryBusModuleProxy<TWrappedModule extends Module = Module>
|
|
13
|
+
extends AbstractModuleProxy<AsyncQueryBusModuleProxyParams, TWrappedModule>
|
|
14
|
+
implements ModuleInstance<TWrappedModule['params'], TWrappedModule['eventData']>
|
|
15
|
+
{
|
|
16
|
+
async query<T extends QueryBoundWitness = QueryBoundWitness>(query: T, payloads?: Payload[]): Promise<ModuleQueryResult> {
|
|
17
|
+
return await this.proxyParams.bridgeClient.send(this.address, query, payloads)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ModuleProxy'
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { BaseParams } from '@xylabs/object'
|
|
2
2
|
import { ModuleResolver } from '@xyo-network/module-model'
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { AsyncQueryBusBaseConfig, AsyncQueryBusClientConfig, AsyncQueryBusHostConfig } from './Config'
|
|
5
5
|
|
|
6
|
-
export type AsyncQueryBusParams = BaseParams<{
|
|
7
|
-
config
|
|
6
|
+
export type AsyncQueryBusParams<TConfig extends AsyncQueryBusBaseConfig = AsyncQueryBusBaseConfig> = BaseParams<{
|
|
7
|
+
config?: TConfig
|
|
8
8
|
resolver: ModuleResolver
|
|
9
9
|
}>
|
|
10
|
+
|
|
11
|
+
export type AsyncQueryBusClientParams = AsyncQueryBusParams<AsyncQueryBusClientConfig>
|
|
12
|
+
export type AsyncQueryBusHostParams = AsyncQueryBusParams<AsyncQueryBusHostConfig>
|
package/src/Config.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EmptyObject } from '@xylabs/object'
|
|
2
2
|
import { BridgeConfig } from '@xyo-network/bridge-model'
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { AsyncQueryBusClientConfig, AsyncQueryBusHostConfig } from './AsyncQueryBus'
|
|
5
5
|
import { PubSubBridgeSchema } from './Schema'
|
|
6
6
|
|
|
7
7
|
export const PubSubBridgeConfigSchema = `${PubSubBridgeSchema}.config`
|
|
@@ -11,6 +11,9 @@ export type PubSubBridgeConfigSchema = typeof PubSubBridgeConfigSchema
|
|
|
11
11
|
* Configuration for the PubSubBridge
|
|
12
12
|
*/
|
|
13
13
|
export type PubSubBridgeConfig<TConfig extends EmptyObject = EmptyObject, TSchema extends string | void = void> = BridgeConfig<
|
|
14
|
-
|
|
14
|
+
{
|
|
15
|
+
client?: AsyncQueryBusClientConfig
|
|
16
|
+
host?: AsyncQueryBusHostConfig
|
|
17
|
+
} & TConfig,
|
|
15
18
|
TSchema extends string ? TSchema : PubSubBridgeConfigSchema
|
|
16
19
|
>
|