@xyo-network/bridge-pub-sub 2.90.23 → 2.91.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/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 +75 -38
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.cts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.mts +75 -38
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.mts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.ts +75 -38
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.ts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusClient.d.cts +16 -46
- package/dist/browser/AsyncQueryBus/AsyncQueryBusClient.d.cts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusClient.d.mts +16 -46
- package/dist/browser/AsyncQueryBus/AsyncQueryBusClient.d.mts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusClient.d.ts +16 -46
- 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 +14 -19
- package/dist/browser/PubSubBridge.d.cts.map +1 -1
- package/dist/browser/PubSubBridge.d.mts +14 -19
- package/dist/browser/PubSubBridge.d.mts.map +1 -1
- package/dist/browser/PubSubBridge.d.ts +14 -19
- package/dist/browser/PubSubBridge.d.ts.map +1 -1
- package/dist/browser/index.cjs +341 -135
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.d.cts +2 -0
- package/dist/browser/index.d.cts.map +1 -1
- package/dist/browser/index.d.mts +2 -0
- package/dist/browser/index.d.mts.map +1 -1
- package/dist/browser/index.d.ts +2 -0
- package/dist/browser/index.d.ts.map +1 -1
- package/dist/browser/index.js +343 -137
- 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 +75 -38
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.cts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.mts +75 -38
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.mts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.ts +75 -38
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.ts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusClient.d.cts +16 -46
- package/dist/node/AsyncQueryBus/AsyncQueryBusClient.d.cts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusClient.d.mts +16 -46
- package/dist/node/AsyncQueryBus/AsyncQueryBusClient.d.mts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusClient.d.ts +16 -46
- 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 +14 -19
- package/dist/node/PubSubBridge.d.cts.map +1 -1
- package/dist/node/PubSubBridge.d.mts +14 -19
- package/dist/node/PubSubBridge.d.mts.map +1 -1
- package/dist/node/PubSubBridge.d.ts +14 -19
- package/dist/node/PubSubBridge.d.ts.map +1 -1
- package/dist/node/index.cjs +367 -152
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.d.cts +2 -0
- package/dist/node/index.d.cts.map +1 -1
- package/dist/node/index.d.mts +2 -0
- package/dist/node/index.d.mts.map +1 -1
- package/dist/node/index.d.ts +2 -0
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +363 -154
- package/dist/node/index.js.map +1 -1
- package/package.json +32 -25
- 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 +19 -40
- package/src/AsyncQueryBus/AsyncQueryBusClient.ts +73 -63
- package/src/AsyncQueryBus/{AsyncQueryBusServer.ts → AsyncQueryBusHost.ts} +35 -27
- 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 +19 -20
- package/src/index.ts +2 -0
- package/dist/browser/AsyncQueryBus/AsyncQueryBusServer.d.cts +0 -74
- package/dist/browser/AsyncQueryBus/AsyncQueryBusServer.d.cts.map +0 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusServer.d.mts +0 -74
- package/dist/browser/AsyncQueryBus/AsyncQueryBusServer.d.mts.map +0 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusServer.d.ts +0 -74
- package/dist/browser/AsyncQueryBus/AsyncQueryBusServer.d.ts.map +0 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusServer.d.cts +0 -74
- package/dist/node/AsyncQueryBus/AsyncQueryBusServer.d.cts.map +0 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusServer.d.mts +0 -74
- package/dist/node/AsyncQueryBus/AsyncQueryBusServer.d.mts.map +0 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusServer.d.ts +0 -74
- package/dist/node/AsyncQueryBus/AsyncQueryBusServer.d.ts.map +0 -1
|
@@ -1,41 +1,30 @@
|
|
|
1
1
|
import { assertEx } from '@xylabs/assert'
|
|
2
|
+
import { Address } from '@xylabs/hex'
|
|
2
3
|
import { Base } from '@xylabs/object'
|
|
3
4
|
import { asArchivistInstance } from '@xyo-network/archivist-model'
|
|
4
5
|
import { BoundWitness, QueryBoundWitness } from '@xyo-network/boundwitness-model'
|
|
5
|
-
import { CacheConfig } from '@xyo-network/bridge-model'
|
|
6
6
|
import { BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload } from '@xyo-network/diviner-boundwitness-model'
|
|
7
7
|
import { asDivinerInstance, DivinerInstance } from '@xyo-network/diviner-model'
|
|
8
|
-
import { ModuleConfig
|
|
8
|
+
import { ModuleConfig } from '@xyo-network/module-model'
|
|
9
9
|
import { LRUCache } from 'lru-cache'
|
|
10
10
|
|
|
11
|
-
import { Pending } from './Config'
|
|
12
11
|
import { AsyncQueryBusParams } from './Params'
|
|
13
12
|
|
|
14
13
|
export class AsyncQueryBusBase<TParams extends AsyncQueryBusParams = AsyncQueryBusParams> extends Base<TParams> {
|
|
15
|
-
protected _lastState?: LRUCache<
|
|
16
|
-
protected
|
|
17
|
-
protected
|
|
18
|
-
protected _targetQueries: Record<string, string[]> = {}
|
|
14
|
+
protected _lastState?: LRUCache<Address, number>
|
|
15
|
+
protected _targetConfigs: Record<Address, ModuleConfig> = {}
|
|
16
|
+
protected _targetQueries: Record<Address, string[]> = {}
|
|
19
17
|
|
|
20
18
|
constructor(params: TParams) {
|
|
21
19
|
super(params)
|
|
22
20
|
}
|
|
23
21
|
|
|
24
|
-
get config() {
|
|
22
|
+
get config(): TParams['config'] {
|
|
25
23
|
return this.params.config
|
|
26
24
|
}
|
|
27
25
|
|
|
28
|
-
get individualAddressBatchQueryLimitConfig(): number {
|
|
29
|
-
return this.config.individualAddressBatchQueryLimit ?? 10
|
|
30
|
-
}
|
|
31
|
-
|
|
32
26
|
get pollFrequencyConfig(): number {
|
|
33
|
-
return this.config
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
get queryCacheConfig(): LRUCache.Options<string, Pending | ModuleQueryResult, unknown> {
|
|
37
|
-
const queryCacheConfig: CacheConfig | undefined = this.config.queryCache === true ? {} : this.config.queryCache
|
|
38
|
-
return { max: 100, ttl: 1000 * 60, ...queryCacheConfig }
|
|
27
|
+
return this.config?.pollFrequency ?? 1000
|
|
39
28
|
}
|
|
40
29
|
|
|
41
30
|
get resolver() {
|
|
@@ -45,47 +34,37 @@ export class AsyncQueryBusBase<TParams extends AsyncQueryBusParams = AsyncQueryB
|
|
|
45
34
|
/**
|
|
46
35
|
* A cache of the last offset of the Diviner process per address
|
|
47
36
|
*/
|
|
48
|
-
protected get lastState(): LRUCache<
|
|
37
|
+
protected get lastState(): LRUCache<Address, number> {
|
|
49
38
|
const requiredConfig = { max: 1000, ttl: 0 }
|
|
50
|
-
this._lastState = this._lastState ?? new LRUCache<
|
|
39
|
+
this._lastState = this._lastState ?? new LRUCache<Address, number>(requiredConfig)
|
|
51
40
|
return this._lastState
|
|
52
41
|
}
|
|
53
42
|
|
|
54
|
-
/**
|
|
55
|
-
* A cache of queries that have been issued
|
|
56
|
-
*/
|
|
57
|
-
protected get queryCache(): LRUCache<string, Pending | ModuleQueryResult> {
|
|
58
|
-
const config = this.queryCacheConfig
|
|
59
|
-
const requiredConfig = { noUpdateTTL: false, ttlAutopurge: true }
|
|
60
|
-
this._queryCache = this._queryCache ?? new LRUCache<string, Pending | ModuleQueryResult>({ ...config, ...requiredConfig })
|
|
61
|
-
return this._queryCache
|
|
62
|
-
}
|
|
63
|
-
|
|
64
43
|
async queriesArchivist() {
|
|
65
44
|
return assertEx(
|
|
66
|
-
asArchivistInstance(await this.resolver.resolve(this.config
|
|
67
|
-
() => `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}]`,
|
|
68
47
|
)
|
|
69
48
|
}
|
|
70
49
|
|
|
71
50
|
async queriesDiviner() {
|
|
72
51
|
return assertEx(
|
|
73
|
-
asDivinerInstance(await this.resolver.resolve(this.config
|
|
74
|
-
() => `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}]`,
|
|
75
54
|
) as DivinerInstance<BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, QueryBoundWitness>
|
|
76
55
|
}
|
|
77
56
|
|
|
78
57
|
async responsesArchivist() {
|
|
79
58
|
return assertEx(
|
|
80
|
-
asArchivistInstance(await this.resolver.resolve(this.config
|
|
81
|
-
() => `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}]`,
|
|
82
61
|
)
|
|
83
62
|
}
|
|
84
63
|
|
|
85
64
|
async responsesDiviner() {
|
|
86
65
|
return assertEx(
|
|
87
|
-
asDivinerInstance(await this.resolver.resolve(this.config
|
|
88
|
-
() => `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}]`,
|
|
89
68
|
) as DivinerInstance<BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitness>
|
|
90
69
|
}
|
|
91
70
|
|
|
@@ -97,7 +76,7 @@ export class AsyncQueryBusBase<TParams extends AsyncQueryBusParams = AsyncQueryB
|
|
|
97
76
|
* @param address The module address to commit the state for
|
|
98
77
|
* @param nextState The state to commit
|
|
99
78
|
*/
|
|
100
|
-
protected async commitState(address:
|
|
79
|
+
protected async commitState(address: Address, nextState: number) {
|
|
101
80
|
await Promise.resolve()
|
|
102
81
|
// TODO: Offload to Archivist/Diviner instead of in-memory
|
|
103
82
|
const lastState = this.lastState.get(address)
|
|
@@ -109,7 +88,7 @@ export class AsyncQueryBusBase<TParams extends AsyncQueryBusParams = AsyncQueryB
|
|
|
109
88
|
* Retrieves the last state of the process. Used to recover state after
|
|
110
89
|
* preemptions, reboots, etc.
|
|
111
90
|
*/
|
|
112
|
-
protected async retrieveState(address:
|
|
91
|
+
protected async retrieveState(address: Address): Promise<number> {
|
|
113
92
|
await Promise.resolve()
|
|
114
93
|
const state = this.lastState.get(address)
|
|
115
94
|
if (state === undefined) {
|
|
@@ -1,53 +1,57 @@
|
|
|
1
|
-
import { assertEx } from '@xylabs/assert'
|
|
2
1
|
import { delay } from '@xylabs/delay'
|
|
3
2
|
import { forget } from '@xylabs/forget'
|
|
3
|
+
import { Address } from '@xylabs/hex'
|
|
4
4
|
import { clearTimeoutEx, setTimeoutEx } from '@xylabs/timer'
|
|
5
5
|
import { isBoundWitnessWithMeta, QueryBoundWitness } from '@xyo-network/boundwitness-model'
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import { CacheConfig } from '@xyo-network/bridge-model'
|
|
7
|
+
import { BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'
|
|
8
|
+
import { ModuleQueryResult } from '@xyo-network/module-model'
|
|
8
9
|
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
9
10
|
import { ModuleError, Payload, PayloadWithMeta, WithMeta } from '@xyo-network/payload-model'
|
|
11
|
+
import { LRUCache } from 'lru-cache'
|
|
10
12
|
|
|
11
13
|
import { AsyncQueryBusBase } from './AsyncQueryBusBase'
|
|
12
14
|
import { Pending } from './Config'
|
|
13
|
-
import {
|
|
15
|
+
import { AsyncQueryBusClientParams } from './Params'
|
|
14
16
|
|
|
15
|
-
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
|
|
16
20
|
private _pollId?: string
|
|
17
21
|
|
|
18
22
|
constructor(params: TParams) {
|
|
19
23
|
super(params)
|
|
20
24
|
}
|
|
21
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
|
+
|
|
22
31
|
get started() {
|
|
23
32
|
return !!this._pollId
|
|
24
33
|
}
|
|
25
34
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return
|
|
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()
|
|
38
47
|
}
|
|
39
48
|
|
|
40
|
-
async send(address:
|
|
49
|
+
async send(address: Address, query: QueryBoundWitness, payloads?: Payload[] | undefined): Promise<ModuleQueryResult> {
|
|
41
50
|
this.logger?.debug(`Begin issuing query to: ${address}`)
|
|
42
51
|
const $meta = { ...query?.$meta, destination: [address] }
|
|
43
52
|
const routedQuery = await PayloadBuilder.build({ ...query, $meta })
|
|
44
53
|
const queryArchivist = await this.queriesArchivist()
|
|
45
54
|
|
|
46
|
-
const sourceAddress = query.addresses.at(0)
|
|
47
|
-
if (sourceAddress && !this.config.listeningModules?.includes(sourceAddress)) {
|
|
48
|
-
this.config.listeningModules?.push(sourceAddress)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
55
|
// TODO: Should we always re-hash to true up timestamps? We can't
|
|
52
56
|
// re-sign correctly so we would lose that information if we did and
|
|
53
57
|
// would also be replying to consumers with a different query hash than
|
|
@@ -69,53 +73,43 @@ export class AsyncQueryBusClient<TParams extends AsyncQueryBusParams = AsyncQuer
|
|
|
69
73
|
const context = new Promise<ModuleQueryResult>((resolve) => {
|
|
70
74
|
this.logger?.debug(`Polling for response to query: ${routedQueryHash}`)
|
|
71
75
|
const pollForResponse = async () => {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
//
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
+
}
|
|
84
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()
|
|
85
106
|
}
|
|
86
|
-
// If we got here waiting for a response timed out
|
|
87
|
-
this.logger?.error('Timeout waiting for query response')
|
|
88
|
-
// Resolve with error to match what a local module would do if it were to error
|
|
89
|
-
// TODO: BW Builder/Sign result as this module?
|
|
90
|
-
const error: ModuleError = {
|
|
91
|
-
message: 'Timeout waiting for query response',
|
|
92
|
-
query: 'network.xyo.boundwitness',
|
|
93
|
-
schema: 'network.xyo.error.module',
|
|
94
|
-
sources: [routedQueryHash],
|
|
95
|
-
}
|
|
96
|
-
resolve([routedQuery, [], [await PayloadBuilder.build(error)]])
|
|
97
|
-
return
|
|
98
107
|
}
|
|
99
108
|
forget(pollForResponse())
|
|
100
109
|
})
|
|
101
110
|
return context
|
|
102
111
|
}
|
|
103
112
|
|
|
104
|
-
start() {
|
|
105
|
-
if (this.started) {
|
|
106
|
-
console.warn('AsyncQueryBus starting when already started')
|
|
107
|
-
}
|
|
108
|
-
this.poll()
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
stop() {
|
|
112
|
-
if (!this.started) {
|
|
113
|
-
console.warn('AsyncQueryBus stopping when already stopped')
|
|
114
|
-
}
|
|
115
|
-
if (this._pollId) clearTimeoutEx(this._pollId)
|
|
116
|
-
this._pollId = undefined
|
|
117
|
-
}
|
|
118
|
-
|
|
119
113
|
/**
|
|
120
114
|
* Runs the background divine process on a loop with a delay
|
|
121
115
|
* specified by the `config.pollFrequency`
|
|
@@ -145,7 +139,7 @@ export class AsyncQueryBusClient<TParams extends AsyncQueryBusParams = AsyncQuer
|
|
|
145
139
|
await Promise.allSettled(
|
|
146
140
|
pendingCommands.map(async ([sourceQuery, status]) => {
|
|
147
141
|
if (status === Pending) {
|
|
148
|
-
const divinerQuery = { schema: BoundWitnessDivinerQuerySchema, sourceQuery }
|
|
142
|
+
const divinerQuery: BoundWitnessDivinerQueryPayload = { schema: BoundWitnessDivinerQuerySchema, sourceQuery }
|
|
149
143
|
const result = await responseBoundWitnessDiviner.divine([divinerQuery])
|
|
150
144
|
if (result && result.length > 0) {
|
|
151
145
|
const response = result.find(isBoundWitnessWithMeta)
|
|
@@ -160,4 +154,20 @@ export class AsyncQueryBusClient<TParams extends AsyncQueryBusParams = AsyncQuer
|
|
|
160
154
|
}),
|
|
161
155
|
)
|
|
162
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
|
+
}
|
|
163
173
|
}
|
|
@@ -1,33 +1,40 @@
|
|
|
1
1
|
import { containsAll } from '@xylabs/array'
|
|
2
2
|
import { assertEx } from '@xylabs/assert'
|
|
3
|
+
import { Address } from '@xylabs/hex'
|
|
3
4
|
import { clearTimeoutEx, setTimeoutEx } from '@xylabs/timer'
|
|
4
5
|
import { isQueryBoundWitnessWithMeta, QueryBoundWitness } from '@xyo-network/boundwitness-model'
|
|
5
6
|
import { BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'
|
|
6
7
|
import { asModuleInstance, ModuleInstance } from '@xyo-network/module-model'
|
|
7
8
|
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
9
|
+
import { WithMeta } from '@xyo-network/payload-model'
|
|
8
10
|
|
|
9
11
|
import { AsyncQueryBusBase } from './AsyncQueryBusBase'
|
|
10
|
-
import {
|
|
12
|
+
import { AsyncQueryBusHostParams } from './Params'
|
|
11
13
|
|
|
12
|
-
export class
|
|
14
|
+
export class AsyncQueryBusHost<TParams extends AsyncQueryBusHostParams = AsyncQueryBusHostParams> extends AsyncQueryBusBase<TParams> {
|
|
13
15
|
private _pollId?: string
|
|
14
16
|
|
|
15
17
|
constructor(params: TParams) {
|
|
16
18
|
super(params)
|
|
17
19
|
}
|
|
18
20
|
|
|
21
|
+
get perAddressBatchQueryLimit(): number {
|
|
22
|
+
return this.config?.perAddressBatchQueryLimit ?? 10
|
|
23
|
+
}
|
|
24
|
+
|
|
19
25
|
get started() {
|
|
20
26
|
return !!this._pollId
|
|
21
27
|
}
|
|
22
28
|
|
|
23
|
-
async listeningModules() {
|
|
24
|
-
const mods =
|
|
25
|
-
?
|
|
29
|
+
async listeningModules(): Promise<ModuleInstance[]> {
|
|
30
|
+
const mods =
|
|
31
|
+
this.config?.listeningModules ?
|
|
32
|
+
await Promise.all(
|
|
26
33
|
this.config.listeningModules.map(async (listeningModule) =>
|
|
27
34
|
assertEx(asModuleInstance(await this.resolver.resolve(listeningModule)), () => `Unable to resolve listeningModule [${listeningModule}]`),
|
|
28
35
|
),
|
|
29
36
|
)
|
|
30
|
-
: await this.resolver.resolve({ direction: '
|
|
37
|
+
: await this.resolver.resolve(undefined, { direction: 'down' })
|
|
31
38
|
return mods
|
|
32
39
|
}
|
|
33
40
|
|
|
@@ -46,46 +53,47 @@ export class AsyncQueryBusServer<TParams extends AsyncQueryBusParams = AsyncQuer
|
|
|
46
53
|
this._pollId = undefined
|
|
47
54
|
}
|
|
48
55
|
|
|
49
|
-
protected callLocalModule = async (localModule: ModuleInstance,
|
|
56
|
+
protected callLocalModule = async (localModule: ModuleInstance, query: WithMeta<QueryBoundWitness>) => {
|
|
57
|
+
//console.log(`callLocalModule: ${query.$hash}`)
|
|
50
58
|
const localModuleName = localModule.config.name ?? localModule.address
|
|
51
59
|
const queryArchivist = await this.queriesArchivist()
|
|
52
60
|
const responseArchivist = await this.responsesArchivist()
|
|
53
|
-
const commandDestination = (
|
|
61
|
+
const commandDestination = (query.$meta as { destination?: string[] })?.destination
|
|
54
62
|
if (commandDestination && commandDestination?.includes(localModule.address)) {
|
|
55
63
|
// Find the query
|
|
56
|
-
const queryIndex =
|
|
64
|
+
const queryIndex = query.payload_hashes.indexOf(query.query)
|
|
57
65
|
if (queryIndex !== -1) {
|
|
58
|
-
const querySchema =
|
|
66
|
+
const querySchema = query.payload_schemas[queryIndex]
|
|
59
67
|
// If the destination can process this type of query
|
|
60
68
|
if (localModule.queries.includes(querySchema)) {
|
|
61
69
|
// Get the associated payloads
|
|
62
|
-
const commandPayloads = await queryArchivist.get(
|
|
70
|
+
const commandPayloads = await queryArchivist.get(query.payload_hashes)
|
|
63
71
|
const commandPayloadsDict = await PayloadBuilder.toAllHashMap(commandPayloads)
|
|
64
|
-
const commandHash = (await PayloadBuilder.build(
|
|
72
|
+
const commandHash = (await PayloadBuilder.build(query)).$hash
|
|
65
73
|
// Check that we have all the arguments for the command
|
|
66
|
-
if (!containsAll(Object.keys(commandPayloadsDict),
|
|
74
|
+
if (!containsAll(Object.keys(commandPayloadsDict), query.payload_hashes)) {
|
|
67
75
|
this.logger?.error(`Error processing command ${commandHash} for module ${localModuleName}, missing payloads`)
|
|
68
76
|
return
|
|
69
77
|
}
|
|
70
78
|
try {
|
|
71
79
|
// Issue the query against module
|
|
72
|
-
const commandSchema = commandPayloadsDict[
|
|
80
|
+
const commandSchema = commandPayloadsDict[query.query].schema
|
|
73
81
|
this.logger?.debug(`Issuing command ${commandSchema} (${commandHash}) addressed to module: ${localModuleName}`)
|
|
74
|
-
const response = await localModule.query(
|
|
82
|
+
const response = await localModule.query(query, commandPayloads)
|
|
75
83
|
const [bw, payloads, errors] = response
|
|
76
84
|
this.logger?.debug(`Replying to command ${commandHash} addressed to module: ${localModuleName}`)
|
|
77
85
|
const insertResult = await responseArchivist.insert([bw, ...payloads, ...errors])
|
|
78
86
|
// NOTE: If all archivists support the contract that numPayloads inserted === numPayloads returned we can
|
|
79
87
|
// do some deeper assertions here like lenIn === lenOut, but for now this should be good enough since BWs
|
|
80
88
|
// should always be unique causing at least one insertion
|
|
81
|
-
if (insertResult.length
|
|
89
|
+
if (insertResult.length === 0) {
|
|
82
90
|
this.logger?.error(`Error replying to command ${commandHash} addressed to module: ${localModuleName}`)
|
|
83
91
|
}
|
|
84
|
-
if (
|
|
92
|
+
if (query?.timestamp) {
|
|
85
93
|
// TODO: This needs to be thought through as we can't use a distributed timestamp
|
|
86
94
|
// because of collisions. We need to ensure we are using the timestamp of the store
|
|
87
95
|
// so there's no chance of multiple commands at the same time
|
|
88
|
-
await this.commitState(localModule.address,
|
|
96
|
+
await this.commitState(localModule.address, query.timestamp)
|
|
89
97
|
}
|
|
90
98
|
} catch (error) {
|
|
91
99
|
this.logger?.error(`Error processing command ${commandHash} for module ${localModuleName}: ${error}`)
|
|
@@ -99,22 +107,22 @@ export class AsyncQueryBusServer<TParams extends AsyncQueryBusParams = AsyncQuer
|
|
|
99
107
|
* Finds unprocessed commands addressed to the supplied address
|
|
100
108
|
* @param address The address to find commands for
|
|
101
109
|
*/
|
|
102
|
-
protected
|
|
110
|
+
protected findQueriesToAddress = async (address: Address) => {
|
|
103
111
|
const queryBoundWitnessDiviner = await this.queriesDiviner()
|
|
104
112
|
// Retrieve last offset from state store
|
|
105
113
|
const timestamp = await this.retrieveState(address)
|
|
106
114
|
const destination = [address]
|
|
107
|
-
const limit = this.
|
|
115
|
+
const limit = this.perAddressBatchQueryLimit
|
|
108
116
|
// Filter for commands to us by destination address
|
|
109
117
|
const divinerQuery = { destination, limit, schema: BoundWitnessDivinerQuerySchema, sort: 'asc', timestamp }
|
|
110
118
|
const result = await queryBoundWitnessDiviner.divine([divinerQuery])
|
|
111
|
-
const
|
|
112
|
-
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
|
|
113
121
|
// TODO: This needs to be thought through as we can't use a distributed timestamp
|
|
114
122
|
// because of collisions. We need to use the timestamp of the store so there's no
|
|
115
123
|
// chance of multiple commands at the same time
|
|
116
124
|
await this.commitState(address, nextState)
|
|
117
|
-
return
|
|
125
|
+
return queries
|
|
118
126
|
}
|
|
119
127
|
|
|
120
128
|
/**
|
|
@@ -149,11 +157,11 @@ export class AsyncQueryBusServer<TParams extends AsyncQueryBusParams = AsyncQuer
|
|
|
149
157
|
try {
|
|
150
158
|
const localModuleName = localModule.config.name ?? localModule.address
|
|
151
159
|
this.logger?.debug(`Checking for inbound commands to ${localModuleName}`)
|
|
152
|
-
const
|
|
153
|
-
if (
|
|
160
|
+
const queries = await this.findQueriesToAddress(localModule.address)
|
|
161
|
+
if (queries.length === 0) return
|
|
154
162
|
this.logger?.debug(`Found commands addressed to local module: ${localModuleName}`)
|
|
155
|
-
for (const
|
|
156
|
-
await this.callLocalModule(localModule,
|
|
163
|
+
for (const query of queries) {
|
|
164
|
+
await this.callLocalModule(localModule, query)
|
|
157
165
|
}
|
|
158
166
|
} catch (error) {
|
|
159
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>
|