@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.
Files changed (242) hide show
  1. package/dist/browser/AbstractModuleHost/AbstractModuleHost.d.cts +11 -0
  2. package/dist/browser/AbstractModuleHost/AbstractModuleHost.d.cts.map +1 -0
  3. package/dist/browser/AbstractModuleHost/AbstractModuleHost.d.mts +11 -0
  4. package/dist/browser/AbstractModuleHost/AbstractModuleHost.d.mts.map +1 -0
  5. package/dist/browser/AbstractModuleHost/AbstractModuleHost.d.ts +11 -0
  6. package/dist/browser/AbstractModuleHost/AbstractModuleHost.d.ts.map +1 -0
  7. package/dist/browser/AbstractModuleHost/index.d.cts +2 -0
  8. package/dist/browser/AbstractModuleHost/index.d.cts.map +1 -0
  9. package/dist/browser/AbstractModuleHost/index.d.mts +2 -0
  10. package/dist/browser/AbstractModuleHost/index.d.mts.map +1 -0
  11. package/dist/browser/AbstractModuleHost/index.d.ts +2 -0
  12. package/dist/browser/AbstractModuleHost/index.d.ts.map +1 -0
  13. package/dist/browser/AbstractModuleProxy/AbstractModuleProxy.d.cts +90 -0
  14. package/dist/browser/AbstractModuleProxy/AbstractModuleProxy.d.cts.map +1 -0
  15. package/dist/browser/AbstractModuleProxy/AbstractModuleProxy.d.mts +90 -0
  16. package/dist/browser/AbstractModuleProxy/AbstractModuleProxy.d.mts.map +1 -0
  17. package/dist/browser/AbstractModuleProxy/AbstractModuleProxy.d.ts +90 -0
  18. package/dist/browser/AbstractModuleProxy/AbstractModuleProxy.d.ts.map +1 -0
  19. package/dist/browser/AbstractModuleProxy/index.d.cts +2 -0
  20. package/dist/browser/AbstractModuleProxy/index.d.cts.map +1 -0
  21. package/dist/browser/AbstractModuleProxy/index.d.mts +2 -0
  22. package/dist/browser/AbstractModuleProxy/index.d.mts.map +1 -0
  23. package/dist/browser/AbstractModuleProxy/index.d.ts +2 -0
  24. package/dist/browser/AbstractModuleProxy/index.d.ts.map +1 -0
  25. package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.cts +75 -38
  26. package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.cts.map +1 -1
  27. package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.mts +75 -38
  28. package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.mts.map +1 -1
  29. package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.ts +75 -38
  30. package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.ts.map +1 -1
  31. package/dist/browser/AsyncQueryBus/AsyncQueryBusClient.d.cts +16 -46
  32. package/dist/browser/AsyncQueryBus/AsyncQueryBusClient.d.cts.map +1 -1
  33. package/dist/browser/AsyncQueryBus/AsyncQueryBusClient.d.mts +16 -46
  34. package/dist/browser/AsyncQueryBus/AsyncQueryBusClient.d.mts.map +1 -1
  35. package/dist/browser/AsyncQueryBus/AsyncQueryBusClient.d.ts +16 -46
  36. package/dist/browser/AsyncQueryBus/AsyncQueryBusClient.d.ts.map +1 -1
  37. package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.cts +37 -0
  38. package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.cts.map +1 -0
  39. package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.mts +37 -0
  40. package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.mts.map +1 -0
  41. package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.ts +37 -0
  42. package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.ts.map +1 -0
  43. package/dist/browser/AsyncQueryBus/Config.d.cts +21 -31
  44. package/dist/browser/AsyncQueryBus/Config.d.cts.map +1 -1
  45. package/dist/browser/AsyncQueryBus/Config.d.mts +21 -31
  46. package/dist/browser/AsyncQueryBus/Config.d.mts.map +1 -1
  47. package/dist/browser/AsyncQueryBus/Config.d.ts +21 -31
  48. package/dist/browser/AsyncQueryBus/Config.d.ts.map +1 -1
  49. package/dist/browser/AsyncQueryBus/ModuleHost/ModuleHost.d.cts +12 -0
  50. package/dist/browser/AsyncQueryBus/ModuleHost/ModuleHost.d.cts.map +1 -0
  51. package/dist/browser/AsyncQueryBus/ModuleHost/ModuleHost.d.mts +12 -0
  52. package/dist/browser/AsyncQueryBus/ModuleHost/ModuleHost.d.mts.map +1 -0
  53. package/dist/browser/AsyncQueryBus/ModuleHost/ModuleHost.d.ts +12 -0
  54. package/dist/browser/AsyncQueryBus/ModuleHost/ModuleHost.d.ts.map +1 -0
  55. package/dist/browser/AsyncQueryBus/ModuleHost/index.d.cts +2 -0
  56. package/dist/browser/AsyncQueryBus/ModuleHost/index.d.cts.map +1 -0
  57. package/dist/browser/AsyncQueryBus/ModuleHost/index.d.mts +2 -0
  58. package/dist/browser/AsyncQueryBus/ModuleHost/index.d.mts.map +1 -0
  59. package/dist/browser/AsyncQueryBus/ModuleHost/index.d.ts +2 -0
  60. package/dist/browser/AsyncQueryBus/ModuleHost/index.d.ts.map +1 -0
  61. package/dist/browser/AsyncQueryBus/ModuleProxy/ModuleProxy.d.cts +12 -0
  62. package/dist/browser/AsyncQueryBus/ModuleProxy/ModuleProxy.d.cts.map +1 -0
  63. package/dist/browser/AsyncQueryBus/ModuleProxy/ModuleProxy.d.mts +12 -0
  64. package/dist/browser/AsyncQueryBus/ModuleProxy/ModuleProxy.d.mts.map +1 -0
  65. package/dist/browser/AsyncQueryBus/ModuleProxy/ModuleProxy.d.ts +12 -0
  66. package/dist/browser/AsyncQueryBus/ModuleProxy/ModuleProxy.d.ts.map +1 -0
  67. package/dist/browser/AsyncQueryBus/ModuleProxy/index.d.cts +2 -0
  68. package/dist/browser/AsyncQueryBus/ModuleProxy/index.d.cts.map +1 -0
  69. package/dist/browser/AsyncQueryBus/ModuleProxy/index.d.mts +2 -0
  70. package/dist/browser/AsyncQueryBus/ModuleProxy/index.d.mts.map +1 -0
  71. package/dist/browser/AsyncQueryBus/ModuleProxy/index.d.ts +2 -0
  72. package/dist/browser/AsyncQueryBus/ModuleProxy/index.d.ts.map +1 -0
  73. package/dist/browser/AsyncQueryBus/Params.d.cts +5 -3
  74. package/dist/browser/AsyncQueryBus/Params.d.cts.map +1 -1
  75. package/dist/browser/AsyncQueryBus/Params.d.mts +5 -3
  76. package/dist/browser/AsyncQueryBus/Params.d.mts.map +1 -1
  77. package/dist/browser/AsyncQueryBus/Params.d.ts +5 -3
  78. package/dist/browser/AsyncQueryBus/Params.d.ts.map +1 -1
  79. package/dist/browser/AsyncQueryBus/index.d.cts +3 -1
  80. package/dist/browser/AsyncQueryBus/index.d.cts.map +1 -1
  81. package/dist/browser/AsyncQueryBus/index.d.mts +3 -1
  82. package/dist/browser/AsyncQueryBus/index.d.mts.map +1 -1
  83. package/dist/browser/AsyncQueryBus/index.d.ts +3 -1
  84. package/dist/browser/AsyncQueryBus/index.d.ts.map +1 -1
  85. package/dist/browser/Config.d.cts +5 -2
  86. package/dist/browser/Config.d.cts.map +1 -1
  87. package/dist/browser/Config.d.mts +5 -2
  88. package/dist/browser/Config.d.mts.map +1 -1
  89. package/dist/browser/Config.d.ts +5 -2
  90. package/dist/browser/Config.d.ts.map +1 -1
  91. package/dist/browser/PubSubBridge.d.cts +14 -19
  92. package/dist/browser/PubSubBridge.d.cts.map +1 -1
  93. package/dist/browser/PubSubBridge.d.mts +14 -19
  94. package/dist/browser/PubSubBridge.d.mts.map +1 -1
  95. package/dist/browser/PubSubBridge.d.ts +14 -19
  96. package/dist/browser/PubSubBridge.d.ts.map +1 -1
  97. package/dist/browser/index.cjs +341 -135
  98. package/dist/browser/index.cjs.map +1 -1
  99. package/dist/browser/index.d.cts +2 -0
  100. package/dist/browser/index.d.cts.map +1 -1
  101. package/dist/browser/index.d.mts +2 -0
  102. package/dist/browser/index.d.mts.map +1 -1
  103. package/dist/browser/index.d.ts +2 -0
  104. package/dist/browser/index.d.ts.map +1 -1
  105. package/dist/browser/index.js +343 -137
  106. package/dist/browser/index.js.map +1 -1
  107. package/dist/node/AbstractModuleHost/AbstractModuleHost.d.cts +11 -0
  108. package/dist/node/AbstractModuleHost/AbstractModuleHost.d.cts.map +1 -0
  109. package/dist/node/AbstractModuleHost/AbstractModuleHost.d.mts +11 -0
  110. package/dist/node/AbstractModuleHost/AbstractModuleHost.d.mts.map +1 -0
  111. package/dist/node/AbstractModuleHost/AbstractModuleHost.d.ts +11 -0
  112. package/dist/node/AbstractModuleHost/AbstractModuleHost.d.ts.map +1 -0
  113. package/dist/node/AbstractModuleHost/index.d.cts +2 -0
  114. package/dist/node/AbstractModuleHost/index.d.cts.map +1 -0
  115. package/dist/node/AbstractModuleHost/index.d.mts +2 -0
  116. package/dist/node/AbstractModuleHost/index.d.mts.map +1 -0
  117. package/dist/node/AbstractModuleHost/index.d.ts +2 -0
  118. package/dist/node/AbstractModuleHost/index.d.ts.map +1 -0
  119. package/dist/node/AbstractModuleProxy/AbstractModuleProxy.d.cts +90 -0
  120. package/dist/node/AbstractModuleProxy/AbstractModuleProxy.d.cts.map +1 -0
  121. package/dist/node/AbstractModuleProxy/AbstractModuleProxy.d.mts +90 -0
  122. package/dist/node/AbstractModuleProxy/AbstractModuleProxy.d.mts.map +1 -0
  123. package/dist/node/AbstractModuleProxy/AbstractModuleProxy.d.ts +90 -0
  124. package/dist/node/AbstractModuleProxy/AbstractModuleProxy.d.ts.map +1 -0
  125. package/dist/node/AbstractModuleProxy/index.d.cts +2 -0
  126. package/dist/node/AbstractModuleProxy/index.d.cts.map +1 -0
  127. package/dist/node/AbstractModuleProxy/index.d.mts +2 -0
  128. package/dist/node/AbstractModuleProxy/index.d.mts.map +1 -0
  129. package/dist/node/AbstractModuleProxy/index.d.ts +2 -0
  130. package/dist/node/AbstractModuleProxy/index.d.ts.map +1 -0
  131. package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.cts +75 -38
  132. package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.cts.map +1 -1
  133. package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.mts +75 -38
  134. package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.mts.map +1 -1
  135. package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.ts +75 -38
  136. package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.ts.map +1 -1
  137. package/dist/node/AsyncQueryBus/AsyncQueryBusClient.d.cts +16 -46
  138. package/dist/node/AsyncQueryBus/AsyncQueryBusClient.d.cts.map +1 -1
  139. package/dist/node/AsyncQueryBus/AsyncQueryBusClient.d.mts +16 -46
  140. package/dist/node/AsyncQueryBus/AsyncQueryBusClient.d.mts.map +1 -1
  141. package/dist/node/AsyncQueryBus/AsyncQueryBusClient.d.ts +16 -46
  142. package/dist/node/AsyncQueryBus/AsyncQueryBusClient.d.ts.map +1 -1
  143. package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.cts +37 -0
  144. package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.cts.map +1 -0
  145. package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.mts +37 -0
  146. package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.mts.map +1 -0
  147. package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.ts +37 -0
  148. package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.ts.map +1 -0
  149. package/dist/node/AsyncQueryBus/Config.d.cts +21 -31
  150. package/dist/node/AsyncQueryBus/Config.d.cts.map +1 -1
  151. package/dist/node/AsyncQueryBus/Config.d.mts +21 -31
  152. package/dist/node/AsyncQueryBus/Config.d.mts.map +1 -1
  153. package/dist/node/AsyncQueryBus/Config.d.ts +21 -31
  154. package/dist/node/AsyncQueryBus/Config.d.ts.map +1 -1
  155. package/dist/node/AsyncQueryBus/ModuleHost/ModuleHost.d.cts +12 -0
  156. package/dist/node/AsyncQueryBus/ModuleHost/ModuleHost.d.cts.map +1 -0
  157. package/dist/node/AsyncQueryBus/ModuleHost/ModuleHost.d.mts +12 -0
  158. package/dist/node/AsyncQueryBus/ModuleHost/ModuleHost.d.mts.map +1 -0
  159. package/dist/node/AsyncQueryBus/ModuleHost/ModuleHost.d.ts +12 -0
  160. package/dist/node/AsyncQueryBus/ModuleHost/ModuleHost.d.ts.map +1 -0
  161. package/dist/node/AsyncQueryBus/ModuleHost/index.d.cts +2 -0
  162. package/dist/node/AsyncQueryBus/ModuleHost/index.d.cts.map +1 -0
  163. package/dist/node/AsyncQueryBus/ModuleHost/index.d.mts +2 -0
  164. package/dist/node/AsyncQueryBus/ModuleHost/index.d.mts.map +1 -0
  165. package/dist/node/AsyncQueryBus/ModuleHost/index.d.ts +2 -0
  166. package/dist/node/AsyncQueryBus/ModuleHost/index.d.ts.map +1 -0
  167. package/dist/node/AsyncQueryBus/ModuleProxy/ModuleProxy.d.cts +12 -0
  168. package/dist/node/AsyncQueryBus/ModuleProxy/ModuleProxy.d.cts.map +1 -0
  169. package/dist/node/AsyncQueryBus/ModuleProxy/ModuleProxy.d.mts +12 -0
  170. package/dist/node/AsyncQueryBus/ModuleProxy/ModuleProxy.d.mts.map +1 -0
  171. package/dist/node/AsyncQueryBus/ModuleProxy/ModuleProxy.d.ts +12 -0
  172. package/dist/node/AsyncQueryBus/ModuleProxy/ModuleProxy.d.ts.map +1 -0
  173. package/dist/node/AsyncQueryBus/ModuleProxy/index.d.cts +2 -0
  174. package/dist/node/AsyncQueryBus/ModuleProxy/index.d.cts.map +1 -0
  175. package/dist/node/AsyncQueryBus/ModuleProxy/index.d.mts +2 -0
  176. package/dist/node/AsyncQueryBus/ModuleProxy/index.d.mts.map +1 -0
  177. package/dist/node/AsyncQueryBus/ModuleProxy/index.d.ts +2 -0
  178. package/dist/node/AsyncQueryBus/ModuleProxy/index.d.ts.map +1 -0
  179. package/dist/node/AsyncQueryBus/Params.d.cts +5 -3
  180. package/dist/node/AsyncQueryBus/Params.d.cts.map +1 -1
  181. package/dist/node/AsyncQueryBus/Params.d.mts +5 -3
  182. package/dist/node/AsyncQueryBus/Params.d.mts.map +1 -1
  183. package/dist/node/AsyncQueryBus/Params.d.ts +5 -3
  184. package/dist/node/AsyncQueryBus/Params.d.ts.map +1 -1
  185. package/dist/node/AsyncQueryBus/index.d.cts +3 -1
  186. package/dist/node/AsyncQueryBus/index.d.cts.map +1 -1
  187. package/dist/node/AsyncQueryBus/index.d.mts +3 -1
  188. package/dist/node/AsyncQueryBus/index.d.mts.map +1 -1
  189. package/dist/node/AsyncQueryBus/index.d.ts +3 -1
  190. package/dist/node/AsyncQueryBus/index.d.ts.map +1 -1
  191. package/dist/node/Config.d.cts +5 -2
  192. package/dist/node/Config.d.cts.map +1 -1
  193. package/dist/node/Config.d.mts +5 -2
  194. package/dist/node/Config.d.mts.map +1 -1
  195. package/dist/node/Config.d.ts +5 -2
  196. package/dist/node/Config.d.ts.map +1 -1
  197. package/dist/node/PubSubBridge.d.cts +14 -19
  198. package/dist/node/PubSubBridge.d.cts.map +1 -1
  199. package/dist/node/PubSubBridge.d.mts +14 -19
  200. package/dist/node/PubSubBridge.d.mts.map +1 -1
  201. package/dist/node/PubSubBridge.d.ts +14 -19
  202. package/dist/node/PubSubBridge.d.ts.map +1 -1
  203. package/dist/node/index.cjs +367 -152
  204. package/dist/node/index.cjs.map +1 -1
  205. package/dist/node/index.d.cts +2 -0
  206. package/dist/node/index.d.cts.map +1 -1
  207. package/dist/node/index.d.mts +2 -0
  208. package/dist/node/index.d.mts.map +1 -1
  209. package/dist/node/index.d.ts +2 -0
  210. package/dist/node/index.d.ts.map +1 -1
  211. package/dist/node/index.js +363 -154
  212. package/dist/node/index.js.map +1 -1
  213. package/package.json +32 -25
  214. package/src/AbstractModuleHost/AbstractModuleHost.ts +12 -0
  215. package/src/AbstractModuleHost/index.ts +1 -0
  216. package/src/AbstractModuleProxy/AbstractModuleProxy.ts +239 -0
  217. package/src/AbstractModuleProxy/index.ts +1 -0
  218. package/src/AsyncQueryBus/AsyncQueryBusBase.ts +19 -40
  219. package/src/AsyncQueryBus/AsyncQueryBusClient.ts +73 -63
  220. package/src/AsyncQueryBus/{AsyncQueryBusServer.ts → AsyncQueryBusHost.ts} +35 -27
  221. package/src/AsyncQueryBus/Config.ts +23 -33
  222. package/src/AsyncQueryBus/ModuleHost/ModuleHost.ts +29 -0
  223. package/src/AsyncQueryBus/ModuleHost/index.ts +1 -0
  224. package/src/AsyncQueryBus/ModuleProxy/ModuleProxy.ts +19 -0
  225. package/src/AsyncQueryBus/ModuleProxy/index.ts +1 -0
  226. package/src/AsyncQueryBus/Params.ts +6 -3
  227. package/src/AsyncQueryBus/index.ts +3 -1
  228. package/src/Config.ts +5 -2
  229. package/src/PubSubBridge.ts +19 -20
  230. package/src/index.ts +2 -0
  231. package/dist/browser/AsyncQueryBus/AsyncQueryBusServer.d.cts +0 -74
  232. package/dist/browser/AsyncQueryBus/AsyncQueryBusServer.d.cts.map +0 -1
  233. package/dist/browser/AsyncQueryBus/AsyncQueryBusServer.d.mts +0 -74
  234. package/dist/browser/AsyncQueryBus/AsyncQueryBusServer.d.mts.map +0 -1
  235. package/dist/browser/AsyncQueryBus/AsyncQueryBusServer.d.ts +0 -74
  236. package/dist/browser/AsyncQueryBus/AsyncQueryBusServer.d.ts.map +0 -1
  237. package/dist/node/AsyncQueryBus/AsyncQueryBusServer.d.cts +0 -74
  238. package/dist/node/AsyncQueryBus/AsyncQueryBusServer.d.cts.map +0 -1
  239. package/dist/node/AsyncQueryBus/AsyncQueryBusServer.d.mts +0 -74
  240. package/dist/node/AsyncQueryBus/AsyncQueryBusServer.d.mts.map +0 -1
  241. package/dist/node/AsyncQueryBus/AsyncQueryBusServer.d.ts +0 -74
  242. 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, ModuleQueryResult } from '@xyo-network/module-model'
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<string, number>
16
- protected _queryCache?: LRUCache<string, Pending | ModuleQueryResult>
17
- protected _targetConfigs: Record<string, ModuleConfig> = {}
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.pollFrequency ?? 1000
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<string, number> {
37
+ protected get lastState(): LRUCache<Address, number> {
49
38
  const requiredConfig = { max: 1000, ttl: 0 }
50
- this._lastState = this._lastState ?? new LRUCache<string, number>(requiredConfig)
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.queries?.archivist)),
67
- () => `Unable to resolve queriesArchivist [${this.config.queries?.archivist}]`,
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.queries?.boundWitnessDiviner)),
74
- () => `Unable to resolve queriesDiviner [${this.config.queries?.boundWitnessDiviner}]`,
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.responses?.archivist)),
81
- () => `Unable to resolve responsesArchivist [${this.config.responses?.archivist}]`,
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.responses?.boundWitnessDiviner)),
88
- () => `Unable to resolve responsesDiviner [${this.config.responses?.boundWitnessDiviner}]`,
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: string, nextState: number) {
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: string): Promise<number> {
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 { BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'
7
- import { asModuleInstance, ModuleQueryResult } from '@xyo-network/module-model'
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 { AsyncQueryBusParams } from './Params'
15
+ import { AsyncQueryBusClientParams } from './Params'
14
16
 
15
- export class AsyncQueryBusClient<TParams extends AsyncQueryBusParams = AsyncQueryBusParams> extends AsyncQueryBusBase<TParams> {
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
- async listeningModules() {
27
- const mods = this.config.listeningModules
28
- ? await Promise.all(
29
- this.config.listeningModules.map(async (listeningModule) =>
30
- assertEx(
31
- asModuleInstance(await this.resolver.resolve(listeningModule)),
32
- () => `Unable to resolve all listeningModule [${listeningModule}]`,
33
- ),
34
- ),
35
- )
36
- : await this.resolver.resolve({ direction: 'all' })
37
- 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()
38
47
  }
39
48
 
40
- async send(address: string, query: QueryBoundWitness, payloads?: Payload[] | undefined): Promise<ModuleQueryResult> {
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
- let response = this.queryCache.get(routedQueryHash)
73
- // Poll for response until cache key expires (response timed out)
74
- while (response !== undefined) {
75
- // Wait a bit
76
- await delay(100)
77
- // Check the status of the response
78
- response = this.queryCache.get(routedQueryHash)
79
- // If status is no longer pending that means we received a response
80
- if (response && response !== Pending) {
81
- this.logger?.debug(`Returning response to query: ${routedQueryHash}`)
82
- resolve(response)
83
- return
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 { AsyncQueryBusParams } from './Params'
12
+ import { AsyncQueryBusHostParams } from './Params'
11
13
 
12
- export class AsyncQueryBusServer<TParams extends AsyncQueryBusParams = AsyncQueryBusParams> extends AsyncQueryBusBase<TParams> {
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 = this.config.listeningModules
25
- ? await Promise.all(
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: 'all' })
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, command: QueryBoundWitness) => {
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 = (command.$meta as { destination?: string[] })?.destination
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 = command.payload_hashes.indexOf(command.query)
64
+ const queryIndex = query.payload_hashes.indexOf(query.query)
57
65
  if (queryIndex !== -1) {
58
- const querySchema = command.payload_schemas[queryIndex]
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(command.payload_hashes)
70
+ const commandPayloads = await queryArchivist.get(query.payload_hashes)
63
71
  const commandPayloadsDict = await PayloadBuilder.toAllHashMap(commandPayloads)
64
- const commandHash = (await PayloadBuilder.build(command)).$hash
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), command.payload_hashes)) {
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[command.query].schema
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(command, commandPayloads)
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 > 0) {
89
+ if (insertResult.length === 0) {
82
90
  this.logger?.error(`Error replying to command ${commandHash} addressed to module: ${localModuleName}`)
83
91
  }
84
- if (command?.timestamp) {
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, command.timestamp)
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 findCommandsToAddress = async (address: string) => {
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.individualAddressBatchQueryLimitConfig
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 commands = result.filter(isQueryBoundWitnessWithMeta)
112
- const nextState = Math.max(...commands.map((c) => c.timestamp ?? 0))
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 commands
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 commands = await this.findCommandsToAddress(localModule.address)
153
- if (commands.length === 0) return
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 command of commands) {
156
- await this.callLocalModule(localModule, command)
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<TArchivist = string, TDiviner = string> {
10
+ export interface SearchableStorage {
10
11
  /**
11
12
  * Name/Address of the archivist where intermediate communications are stored
12
13
  */
13
- archivist: TArchivist
14
+ archivist: ModuleIdentifier
14
15
  /**
15
16
  * Name/Address of the diviner where intermediate communications are filtered
16
17
  */
17
- boundWitnessDiviner: TDiviner
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
- * Name/Address of the archivist where intermediate communications are stored
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
- boundWitnessDiviner: TDiviner
33
- }
25
+ queries?: SearchableStorage
34
26
 
35
- export interface AsyncQueryBusConfig<TArchivist = string, TDiviner = string> {
36
27
  /**
37
- * How many queries to process at once when retrieving queries
38
- * for an address
28
+ * Configuration for intermediary response storage
39
29
  */
40
- individualAddressBatchQueryLimit?: number
30
+ responses?: SearchableStorage
31
+ }
41
32
 
42
- listeningModules?: string[]
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
- * Configuration for intermediary response storage
42
+ * Where the archivist should persist its internal state
55
43
  */
56
- queryCache?: CacheConfig | true
44
+ stateStore?: SearchableStorage
45
+ }
57
46
 
47
+ export interface AsyncQueryBusClientConfig extends AsyncQueryBusBaseConfig {
58
48
  /**
59
49
  * Configuration for intermediary response storage
60
50
  */
61
- responses?: Intermediary<TArchivist, TDiviner>
51
+ queryCache?: CacheConfig | true
52
+ }
62
53
 
63
- /**
64
- * The root address to connect the bridge to
65
- */
66
- rootAddress?: string
54
+ export interface AsyncQueryBusHostConfig extends AsyncQueryBusBaseConfig {
55
+ listeningModules?: string[]
67
56
 
68
57
  /**
69
- * Where the archivist should persist its internal state
58
+ * How many queries to process at once when retrieving queries
59
+ * for an address
70
60
  */
71
- stateStore?: SearchableStorage<TArchivist, TDiviner>
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 { AsyncQueryBusConfig } from './Config'
4
+ import { AsyncQueryBusBaseConfig, AsyncQueryBusClientConfig, AsyncQueryBusHostConfig } from './Config'
5
5
 
6
- export type AsyncQueryBusParams = BaseParams<{
7
- config: AsyncQueryBusConfig
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>
@@ -1,4 +1,6 @@
1
1
  export * from './AsyncQueryBusClient'
2
- export * from './AsyncQueryBusServer'
2
+ export * from './AsyncQueryBusHost'
3
3
  export * from './Config'
4
+ export * from './ModuleHost'
5
+ export * from './ModuleProxy'
4
6
  export * from './Params'