@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
@@ -6,39 +6,181 @@ var __publicField = (obj, key, value) => {
6
6
  return value;
7
7
  };
8
8
 
9
- // src/Schema.ts
10
- var PubSubBridgeSchema = "network.xyo.bridge.pubsub";
11
-
12
- // src/Config.ts
13
- var PubSubBridgeConfigSchema = `${PubSubBridgeSchema}.config`;
14
-
15
- // src/PubSubBridge.ts
16
- import { assertEx as assertEx4 } from "@xylabs/assert";
17
- import { AbstractBridge } from "@xyo-network/abstract-bridge";
18
- import { ModuleManifestPayloadSchema } from "@xyo-network/manifest-model";
19
- import { creatableModule, ModuleManifestQuerySchema } from "@xyo-network/module-model";
20
- import { isPayloadOfSchemaType } from "@xyo-network/payload-model";
21
- import { LRUCache as LRUCache2 } from "lru-cache";
9
+ // src/AbstractModuleProxy/AbstractModuleProxy.ts
10
+ import { assertEx } from "@xylabs/assert";
11
+ import { compact } from "@xylabs/lodash";
12
+ import { Base } from "@xylabs/object";
13
+ import { PromiseEx } from "@xylabs/promise";
14
+ import { QueryBoundWitnessBuilder } from "@xyo-network/boundwitness-builder";
15
+ import { BoundWitnessWrapper } from "@xyo-network/boundwitness-wrapper";
16
+ import { AddressPreviousHashSchema, ModuleAddressQuerySchema, ModuleConfigSchema, ModuleDescribeQuerySchema, ModuleDiscoverQuerySchema, ModuleManifestQuerySchema } from "@xyo-network/module-model";
17
+ import { ModuleErrorSchema } from "@xyo-network/payload-model";
18
+ var _AbstractModuleProxy = class _AbstractModuleProxy extends Base {
19
+ eventData = {};
20
+ proxyParams;
21
+ constructor(params) {
22
+ super({
23
+ config: {
24
+ schema: ModuleConfigSchema
25
+ }
26
+ });
27
+ this.proxyParams = params;
28
+ }
29
+ get account() {
30
+ return this.proxyParams.account;
31
+ }
32
+ get address() {
33
+ return this.proxyParams.moduleAddress;
34
+ }
35
+ get config() {
36
+ return this.params.config;
37
+ }
38
+ get downResolver() {
39
+ throw new Error("Unsupported");
40
+ }
41
+ get id() {
42
+ return this.proxyParams.moduleAddress;
43
+ }
44
+ get queries() {
45
+ return this.proxyParams.queries;
46
+ }
47
+ get upResolver() {
48
+ throw new Error("Unsupported");
49
+ }
50
+ static hasRequiredQueries(module) {
51
+ return this.missingRequiredQueries(module).length === 0;
52
+ }
53
+ static missingRequiredQueries(module) {
54
+ const moduleQueries = module.queries;
55
+ return compact(this.requiredQueries.map((query) => {
56
+ return moduleQueries.includes(query) ? null : query;
57
+ }));
58
+ }
59
+ async addressPreviousHash() {
60
+ const queryPayload = {
61
+ schema: ModuleAddressQuerySchema
62
+ };
63
+ return assertEx((await this.sendQuery(queryPayload)).find((payload) => payload.schema === AddressPreviousHashSchema), "Result did not include correct payload");
64
+ }
65
+ clearListeners(_eventNames) {
66
+ throw new Error("Unsupported");
67
+ }
68
+ //TODO: Make ModuleDescription into real payload
69
+ async describe() {
70
+ const queryPayload = {
71
+ schema: ModuleDescribeQuerySchema
72
+ };
73
+ return (await this.sendQuery(queryPayload))[0];
74
+ }
75
+ async discover() {
76
+ const queryPayload = {
77
+ schema: ModuleDiscoverQuerySchema
78
+ };
79
+ return await this.sendQuery(queryPayload);
80
+ }
81
+ emit(_eventName, _eventArgs) {
82
+ throw new Error("Unsupported");
83
+ }
84
+ emitSerial(_eventName, _eventArgs) {
85
+ throw new Error("Unsupported");
86
+ }
87
+ listenerCount(_eventNames) {
88
+ throw new Error("Unsupported");
89
+ }
90
+ async manifest(maxDepth) {
91
+ const queryPayload = {
92
+ schema: ModuleManifestQuerySchema,
93
+ ...maxDepth === void 0 ? {} : {
94
+ maxDepth
95
+ }
96
+ };
97
+ return (await this.sendQuery(queryPayload))[0];
98
+ }
99
+ async moduleAddress() {
100
+ const queryPayload = {
101
+ schema: ModuleAddressQuerySchema
102
+ };
103
+ return await this.sendQuery(queryPayload);
104
+ }
105
+ off(_eventNames, _listener) {
106
+ throw new Error("Unsupported");
107
+ }
108
+ offAny(_listener) {
109
+ throw new Error("Unsupported");
110
+ }
111
+ on(_eventNames, _listener) {
112
+ throw new Error("Unsupported");
113
+ }
114
+ onAny(_listener) {
115
+ throw new Error("Unsupported");
116
+ }
117
+ once(_eventName, _listener) {
118
+ throw new Error("Unsupported");
119
+ }
120
+ async previousHash() {
121
+ const queryPayload = {
122
+ schema: ModuleAddressQuerySchema
123
+ };
124
+ return (await this.sendQuery(queryPayload)).pop().previousHash;
125
+ }
126
+ queryable(_query, _payloads) {
127
+ return true;
128
+ }
129
+ resolve(nameOrAddressOrFilter, _options) {
130
+ return typeof nameOrAddressOrFilter === "string" ? void 0 : [];
131
+ }
132
+ state() {
133
+ return [];
134
+ }
135
+ bindQuery(query, payloads, account = this.account) {
136
+ const promise = new PromiseEx(async (resolve) => {
137
+ const result = await this.bindQueryInternal(query, payloads, account);
138
+ resolve == null ? void 0 : resolve(result);
139
+ return result;
140
+ }, account);
141
+ return promise;
142
+ }
143
+ async bindQueryInternal(query, payloads, account = this.account) {
144
+ const builder = await new QueryBoundWitnessBuilder().payloads(payloads).query(query);
145
+ const result = await (account ? builder.witness(account) : builder).build();
146
+ return result;
147
+ }
148
+ async filterErrors(result) {
149
+ const wrapper = await BoundWitnessWrapper.wrap(result[0], result[1]);
150
+ return wrapper.payloadsBySchema(ModuleErrorSchema);
151
+ }
152
+ async sendQuery(queryPayload, payloads) {
153
+ const query = await this.bindQuery(queryPayload, payloads);
154
+ const [, resultPayloads, errors] = await this.query(query[0], query[1]);
155
+ if (errors && errors.length > 0) {
156
+ throw errors[0];
157
+ }
158
+ return resultPayloads;
159
+ }
160
+ };
161
+ __name(_AbstractModuleProxy, "AbstractModuleProxy");
162
+ __publicField(_AbstractModuleProxy, "requiredQueries", [
163
+ ModuleDiscoverQuerySchema
164
+ ]);
165
+ var AbstractModuleProxy = _AbstractModuleProxy;
22
166
 
23
167
  // src/AsyncQueryBus/AsyncQueryBusClient.ts
24
- import { assertEx as assertEx2 } from "@xylabs/assert";
25
168
  import { delay } from "@xylabs/delay";
26
169
  import { forget } from "@xylabs/forget";
27
170
  import { clearTimeoutEx, setTimeoutEx } from "@xylabs/timer";
28
171
  import { isBoundWitnessWithMeta } from "@xyo-network/boundwitness-model";
29
172
  import { BoundWitnessDivinerQuerySchema } from "@xyo-network/diviner-boundwitness-model";
30
- import { asModuleInstance } from "@xyo-network/module-model";
31
173
  import { PayloadBuilder } from "@xyo-network/payload-builder";
174
+ import { LRUCache as LRUCache2 } from "lru-cache";
32
175
 
33
176
  // src/AsyncQueryBus/AsyncQueryBusBase.ts
34
- import { assertEx } from "@xylabs/assert";
35
- import { Base } from "@xylabs/object";
177
+ import { assertEx as assertEx2 } from "@xylabs/assert";
178
+ import { Base as Base2 } from "@xylabs/object";
36
179
  import { asArchivistInstance } from "@xyo-network/archivist-model";
37
180
  import { asDivinerInstance } from "@xyo-network/diviner-model";
38
181
  import { LRUCache } from "lru-cache";
39
- var _AsyncQueryBusBase = class _AsyncQueryBusBase extends Base {
182
+ var _AsyncQueryBusBase = class _AsyncQueryBusBase extends Base2 {
40
183
  _lastState;
41
- _queryCache;
42
184
  _targetConfigs = {};
43
185
  _targetQueries = {};
44
186
  constructor(params) {
@@ -47,19 +189,9 @@ var _AsyncQueryBusBase = class _AsyncQueryBusBase extends Base {
47
189
  get config() {
48
190
  return this.params.config;
49
191
  }
50
- get individualAddressBatchQueryLimitConfig() {
51
- return this.config.individualAddressBatchQueryLimit ?? 10;
52
- }
53
192
  get pollFrequencyConfig() {
54
- return this.config.pollFrequency ?? 1e3;
55
- }
56
- get queryCacheConfig() {
57
- const queryCacheConfig = this.config.queryCache === true ? {} : this.config.queryCache;
58
- return {
59
- max: 100,
60
- ttl: 1e3 * 60,
61
- ...queryCacheConfig
62
- };
193
+ var _a;
194
+ return ((_a = this.config) == null ? void 0 : _a.pollFrequency) ?? 1e3;
63
195
  }
64
196
  get resolver() {
65
197
  return this.params.resolver;
@@ -75,47 +207,32 @@ var _AsyncQueryBusBase = class _AsyncQueryBusBase extends Base {
75
207
  this._lastState = this._lastState ?? new LRUCache(requiredConfig);
76
208
  return this._lastState;
77
209
  }
78
- /**
79
- * A cache of queries that have been issued
80
- */
81
- get queryCache() {
82
- const config = this.queryCacheConfig;
83
- const requiredConfig = {
84
- noUpdateTTL: false,
85
- ttlAutopurge: true
86
- };
87
- this._queryCache = this._queryCache ?? new LRUCache({
88
- ...config,
89
- ...requiredConfig
90
- });
91
- return this._queryCache;
92
- }
93
210
  async queriesArchivist() {
94
- var _a;
95
- return assertEx(asArchivistInstance(await this.resolver.resolve((_a = this.config.queries) == null ? void 0 : _a.archivist)), () => {
96
- var _a2;
97
- return `Unable to resolve queriesArchivist [${(_a2 = this.config.queries) == null ? void 0 : _a2.archivist}]`;
211
+ var _a, _b, _c;
212
+ return assertEx2(asArchivistInstance(await this.resolver.resolve((_c = (_b = (_a = this.config) == null ? void 0 : _a.clearingHouse) == null ? void 0 : _b.queries) == null ? void 0 : _c.archivist)), () => {
213
+ var _a2, _b2, _c2;
214
+ return `Unable to resolve queriesArchivist [${(_c2 = (_b2 = (_a2 = this.config) == null ? void 0 : _a2.clearingHouse) == null ? void 0 : _b2.queries) == null ? void 0 : _c2.archivist}]`;
98
215
  });
99
216
  }
100
217
  async queriesDiviner() {
101
- var _a;
102
- return assertEx(asDivinerInstance(await this.resolver.resolve((_a = this.config.queries) == null ? void 0 : _a.boundWitnessDiviner)), () => {
103
- var _a2;
104
- return `Unable to resolve queriesDiviner [${(_a2 = this.config.queries) == null ? void 0 : _a2.boundWitnessDiviner}]`;
218
+ var _a, _b, _c;
219
+ return assertEx2(asDivinerInstance(await this.resolver.resolve((_c = (_b = (_a = this.config) == null ? void 0 : _a.clearingHouse) == null ? void 0 : _b.queries) == null ? void 0 : _c.boundWitnessDiviner)), () => {
220
+ var _a2, _b2, _c2;
221
+ return `Unable to resolve queriesDiviner [${(_c2 = (_b2 = (_a2 = this.config) == null ? void 0 : _a2.clearingHouse) == null ? void 0 : _b2.queries) == null ? void 0 : _c2.boundWitnessDiviner}]`;
105
222
  });
106
223
  }
107
224
  async responsesArchivist() {
108
- var _a;
109
- return assertEx(asArchivistInstance(await this.resolver.resolve((_a = this.config.responses) == null ? void 0 : _a.archivist)), () => {
110
- var _a2;
111
- return `Unable to resolve responsesArchivist [${(_a2 = this.config.responses) == null ? void 0 : _a2.archivist}]`;
225
+ var _a, _b, _c;
226
+ return assertEx2(asArchivistInstance(await this.resolver.resolve((_c = (_b = (_a = this.config) == null ? void 0 : _a.clearingHouse) == null ? void 0 : _b.responses) == null ? void 0 : _c.archivist)), () => {
227
+ var _a2, _b2, _c2;
228
+ return `Unable to resolve responsesArchivist [${(_c2 = (_b2 = (_a2 = this.config) == null ? void 0 : _a2.clearingHouse) == null ? void 0 : _b2.responses) == null ? void 0 : _c2.archivist}]`;
112
229
  });
113
230
  }
114
231
  async responsesDiviner() {
115
- var _a;
116
- return assertEx(asDivinerInstance(await this.resolver.resolve((_a = this.config.responses) == null ? void 0 : _a.boundWitnessDiviner)), () => {
117
- var _a2;
118
- return `Unable to resolve responsesDiviner [${(_a2 = this.config.responses) == null ? void 0 : _a2.boundWitnessDiviner}]`;
232
+ var _a, _b, _c;
233
+ return assertEx2(asDivinerInstance(await this.resolver.resolve((_c = (_b = (_a = this.config) == null ? void 0 : _a.clearingHouse) == null ? void 0 : _b.responses) == null ? void 0 : _c.boundWitnessDiviner)), () => {
234
+ var _a2, _b2, _c2;
235
+ return `Unable to resolve responsesDiviner [${(_c2 = (_b2 = (_a2 = this.config) == null ? void 0 : _a2.clearingHouse) == null ? void 0 : _b2.responses) == null ? void 0 : _c2.boundWitnessDiviner}]`;
119
236
  });
120
237
  }
121
238
  /**
@@ -157,21 +274,45 @@ var Pending = "pending";
157
274
 
158
275
  // src/AsyncQueryBus/AsyncQueryBusClient.ts
159
276
  var _AsyncQueryBusClient = class _AsyncQueryBusClient extends AsyncQueryBusBase {
277
+ _queryCache;
278
+ _pollCount = 0;
160
279
  _pollId;
161
280
  constructor(params) {
162
281
  super(params);
163
282
  }
283
+ get queryCacheConfig() {
284
+ var _a, _b;
285
+ const queryCacheConfig = ((_a = this.config) == null ? void 0 : _a.queryCache) === true ? {} : (_b = this.config) == null ? void 0 : _b.queryCache;
286
+ return {
287
+ max: 100,
288
+ ttl: 1e3 * 60,
289
+ ...queryCacheConfig
290
+ };
291
+ }
164
292
  get started() {
165
293
  return !!this._pollId;
166
294
  }
167
- async listeningModules() {
168
- const mods = this.config.listeningModules ? await Promise.all(this.config.listeningModules.map(async (listeningModule) => assertEx2(asModuleInstance(await this.resolver.resolve(listeningModule)), () => `Unable to resolve all listeningModule [${listeningModule}]`))) : await this.resolver.resolve({
169
- direction: "all"
295
+ /**
296
+ * A cache of queries that have been issued
297
+ */
298
+ get queryCache() {
299
+ const config = this.queryCacheConfig;
300
+ const requiredConfig = {
301
+ noUpdateTTL: false,
302
+ ttlAutopurge: true
303
+ };
304
+ this._queryCache = this._queryCache ?? new LRUCache2({
305
+ ...config,
306
+ ...requiredConfig
170
307
  });
171
- return mods;
308
+ return this._queryCache;
309
+ }
310
+ listeningAddresses() {
311
+ var _a;
312
+ return (_a = this._queryCache) == null ? void 0 : _a.keys();
172
313
  }
173
314
  async send(address, query, payloads) {
174
- var _a, _b, _c, _d, _e, _f;
315
+ var _a, _b, _c, _d;
175
316
  (_a = this.logger) == null ? void 0 : _a.debug(`Begin issuing query to: ${address}`);
176
317
  const $meta = {
177
318
  ...query == null ? void 0 : query.$meta,
@@ -184,10 +325,6 @@ var _AsyncQueryBusClient = class _AsyncQueryBusClient extends AsyncQueryBusBase
184
325
  $meta
185
326
  });
186
327
  const queryArchivist = await this.queriesArchivist();
187
- const sourceAddress = query.addresses.at(0);
188
- if (sourceAddress && !((_b = this.config.listeningModules) == null ? void 0 : _b.includes(sourceAddress))) {
189
- (_c = this.config.listeningModules) == null ? void 0 : _c.push(sourceAddress);
190
- }
191
328
  const routedQueryHash = (
192
329
  // Trust the signed hash if it's there
193
330
  (routedQuery == null ? void 0 : routedQuery.$hash) ?? // TODO: What is the right way to find the dataHash
@@ -195,15 +332,15 @@ var _AsyncQueryBusClient = class _AsyncQueryBusClient extends AsyncQueryBusBase
195
332
  routedQuery
196
333
  ]))[0]
197
334
  );
198
- (_d = this.logger) == null ? void 0 : _d.debug(`Issuing query: ${routedQueryHash} to: ${address}`);
335
+ (_b = this.logger) == null ? void 0 : _b.debug(`Issuing query: ${routedQueryHash} to: ${address}`);
199
336
  const data = payloads ? [
200
337
  routedQuery,
201
338
  ...payloads
202
339
  ] : [
203
340
  routedQuery
204
341
  ];
205
- const insertResult = await ((_e = queryArchivist.insert) == null ? void 0 : _e.call(queryArchivist, data));
206
- (_f = this.logger) == null ? void 0 : _f.debug(`Issued query: ${routedQueryHash} to: ${address}`);
342
+ const insertResult = await ((_c = queryArchivist.insert) == null ? void 0 : _c.call(queryArchivist, data));
343
+ (_d = this.logger) == null ? void 0 : _d.debug(`Issued query: ${routedQueryHash} to: ${address}`);
207
344
  this.queryCache.set(routedQueryHash, Pending);
208
345
  if (!insertResult)
209
346
  throw new Error("Unable to issue query to queryArchivist");
@@ -212,52 +349,43 @@ var _AsyncQueryBusClient = class _AsyncQueryBusClient extends AsyncQueryBusBase
212
349
  (_a2 = this.logger) == null ? void 0 : _a2.debug(`Polling for response to query: ${routedQueryHash}`);
213
350
  const pollForResponse = /* @__PURE__ */ __name(async () => {
214
351
  var _a3, _b2;
215
- let response = this.queryCache.get(routedQueryHash);
216
- while (response !== void 0) {
217
- await delay(100);
218
- response = this.queryCache.get(routedQueryHash);
219
- if (response && response !== Pending) {
220
- (_a3 = this.logger) == null ? void 0 : _a3.debug(`Returning response to query: ${routedQueryHash}`);
221
- resolve(response);
222
- return;
352
+ try {
353
+ this.start();
354
+ let response = this.queryCache.get(routedQueryHash);
355
+ while (response !== void 0) {
356
+ await delay(100);
357
+ response = this.queryCache.get(routedQueryHash);
358
+ if (response && response !== Pending) {
359
+ (_a3 = this.logger) == null ? void 0 : _a3.debug(`Returning response to query: ${routedQueryHash}`);
360
+ resolve(response);
361
+ return;
362
+ }
223
363
  }
364
+ (_b2 = this.logger) == null ? void 0 : _b2.error("Timeout waiting for query response");
365
+ const error = {
366
+ message: "Timeout waiting for query response",
367
+ query: "network.xyo.boundwitness",
368
+ schema: "network.xyo.error.module",
369
+ sources: [
370
+ routedQueryHash
371
+ ]
372
+ };
373
+ resolve([
374
+ routedQuery,
375
+ [],
376
+ [
377
+ await PayloadBuilder.build(error)
378
+ ]
379
+ ]);
380
+ return;
381
+ } finally {
382
+ this.stop();
224
383
  }
225
- (_b2 = this.logger) == null ? void 0 : _b2.error("Timeout waiting for query response");
226
- const error = {
227
- message: "Timeout waiting for query response",
228
- query: "network.xyo.boundwitness",
229
- schema: "network.xyo.error.module",
230
- sources: [
231
- routedQueryHash
232
- ]
233
- };
234
- resolve([
235
- routedQuery,
236
- [],
237
- [
238
- await PayloadBuilder.build(error)
239
- ]
240
- ]);
241
- return;
242
384
  }, "pollForResponse");
243
385
  forget(pollForResponse());
244
386
  });
245
387
  return context;
246
388
  }
247
- start() {
248
- if (this.started) {
249
- console.warn("AsyncQueryBus starting when already started");
250
- }
251
- this.poll();
252
- }
253
- stop() {
254
- if (!this.started) {
255
- console.warn("AsyncQueryBus stopping when already stopped");
256
- }
257
- if (this._pollId)
258
- clearTimeoutEx(this._pollId);
259
- this._pollId = void 0;
260
- }
261
389
  /**
262
390
  * Runs the background divine process on a loop with a delay
263
391
  * specified by the `config.pollFrequency`
@@ -311,29 +439,49 @@ var _AsyncQueryBusClient = class _AsyncQueryBusClient extends AsyncQueryBusBase
311
439
  }
312
440
  }));
313
441
  };
442
+ start() {
443
+ if (this._pollCount === 0) {
444
+ this.poll();
445
+ }
446
+ this._pollCount++;
447
+ }
448
+ stop() {
449
+ this._pollCount--;
450
+ if (this._pollCount <= 0) {
451
+ if (this._pollId)
452
+ clearTimeoutEx(this._pollId);
453
+ this._pollId = void 0;
454
+ this._pollCount = 0;
455
+ }
456
+ }
314
457
  };
315
458
  __name(_AsyncQueryBusClient, "AsyncQueryBusClient");
316
459
  var AsyncQueryBusClient = _AsyncQueryBusClient;
317
460
 
318
- // src/AsyncQueryBus/AsyncQueryBusServer.ts
461
+ // src/AsyncQueryBus/AsyncQueryBusHost.ts
319
462
  import { containsAll } from "@xylabs/array";
320
463
  import { assertEx as assertEx3 } from "@xylabs/assert";
321
464
  import { clearTimeoutEx as clearTimeoutEx2, setTimeoutEx as setTimeoutEx2 } from "@xylabs/timer";
322
465
  import { isQueryBoundWitnessWithMeta } from "@xyo-network/boundwitness-model";
323
466
  import { BoundWitnessDivinerQuerySchema as BoundWitnessDivinerQuerySchema2 } from "@xyo-network/diviner-boundwitness-model";
324
- import { asModuleInstance as asModuleInstance2 } from "@xyo-network/module-model";
467
+ import { asModuleInstance } from "@xyo-network/module-model";
325
468
  import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/payload-builder";
326
- var _AsyncQueryBusServer = class _AsyncQueryBusServer extends AsyncQueryBusBase {
469
+ var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
327
470
  _pollId;
328
471
  constructor(params) {
329
472
  super(params);
330
473
  }
474
+ get perAddressBatchQueryLimit() {
475
+ var _a;
476
+ return ((_a = this.config) == null ? void 0 : _a.perAddressBatchQueryLimit) ?? 10;
477
+ }
331
478
  get started() {
332
479
  return !!this._pollId;
333
480
  }
334
481
  async listeningModules() {
335
- const mods = this.config.listeningModules ? await Promise.all(this.config.listeningModules.map(async (listeningModule) => assertEx3(asModuleInstance2(await this.resolver.resolve(listeningModule)), () => `Unable to resolve listeningModule [${listeningModule}]`))) : await this.resolver.resolve({
336
- direction: "all"
482
+ var _a;
483
+ const mods = ((_a = this.config) == null ? void 0 : _a.listeningModules) ? await Promise.all(this.config.listeningModules.map(async (listeningModule) => assertEx3(asModuleInstance(await this.resolver.resolve(listeningModule)), () => `Unable to resolve listeningModule [${listeningModule}]`))) : await this.resolver.resolve(void 0, {
484
+ direction: "down"
337
485
  });
338
486
  return mods;
339
487
  }
@@ -351,28 +499,28 @@ var _AsyncQueryBusServer = class _AsyncQueryBusServer extends AsyncQueryBusBase
351
499
  clearTimeoutEx2(this._pollId);
352
500
  this._pollId = void 0;
353
501
  }
354
- callLocalModule = async (localModule, command) => {
502
+ callLocalModule = async (localModule, query) => {
355
503
  var _a, _b, _c, _d, _e, _f;
356
504
  const localModuleName = localModule.config.name ?? localModule.address;
357
505
  const queryArchivist = await this.queriesArchivist();
358
506
  const responseArchivist = await this.responsesArchivist();
359
- const commandDestination = (_a = command.$meta) == null ? void 0 : _a.destination;
507
+ const commandDestination = (_a = query.$meta) == null ? void 0 : _a.destination;
360
508
  if (commandDestination && (commandDestination == null ? void 0 : commandDestination.includes(localModule.address))) {
361
- const queryIndex = command.payload_hashes.indexOf(command.query);
509
+ const queryIndex = query.payload_hashes.indexOf(query.query);
362
510
  if (queryIndex !== -1) {
363
- const querySchema = command.payload_schemas[queryIndex];
511
+ const querySchema = query.payload_schemas[queryIndex];
364
512
  if (localModule.queries.includes(querySchema)) {
365
- const commandPayloads = await queryArchivist.get(command.payload_hashes);
513
+ const commandPayloads = await queryArchivist.get(query.payload_hashes);
366
514
  const commandPayloadsDict = await PayloadBuilder2.toAllHashMap(commandPayloads);
367
- const commandHash = (await PayloadBuilder2.build(command)).$hash;
368
- if (!containsAll(Object.keys(commandPayloadsDict), command.payload_hashes)) {
515
+ const commandHash = (await PayloadBuilder2.build(query)).$hash;
516
+ if (!containsAll(Object.keys(commandPayloadsDict), query.payload_hashes)) {
369
517
  (_b = this.logger) == null ? void 0 : _b.error(`Error processing command ${commandHash} for module ${localModuleName}, missing payloads`);
370
518
  return;
371
519
  }
372
520
  try {
373
- const commandSchema = commandPayloadsDict[command.query].schema;
521
+ const commandSchema = commandPayloadsDict[query.query].schema;
374
522
  (_c = this.logger) == null ? void 0 : _c.debug(`Issuing command ${commandSchema} (${commandHash}) addressed to module: ${localModuleName}`);
375
- const response = await localModule.query(command, commandPayloads);
523
+ const response = await localModule.query(query, commandPayloads);
376
524
  const [bw, payloads, errors] = response;
377
525
  (_d = this.logger) == null ? void 0 : _d.debug(`Replying to command ${commandHash} addressed to module: ${localModuleName}`);
378
526
  const insertResult = await responseArchivist.insert([
@@ -380,11 +528,11 @@ var _AsyncQueryBusServer = class _AsyncQueryBusServer extends AsyncQueryBusBase
380
528
  ...payloads,
381
529
  ...errors
382
530
  ]);
383
- if (insertResult.length > 0) {
531
+ if (insertResult.length === 0) {
384
532
  (_e = this.logger) == null ? void 0 : _e.error(`Error replying to command ${commandHash} addressed to module: ${localModuleName}`);
385
533
  }
386
- if (command == null ? void 0 : command.timestamp) {
387
- await this.commitState(localModule.address, command.timestamp);
534
+ if (query == null ? void 0 : query.timestamp) {
535
+ await this.commitState(localModule.address, query.timestamp);
388
536
  }
389
537
  } catch (error) {
390
538
  (_f = this.logger) == null ? void 0 : _f.error(`Error processing command ${commandHash} for module ${localModuleName}: ${error}`);
@@ -397,13 +545,13 @@ var _AsyncQueryBusServer = class _AsyncQueryBusServer extends AsyncQueryBusBase
397
545
  * Finds unprocessed commands addressed to the supplied address
398
546
  * @param address The address to find commands for
399
547
  */
400
- findCommandsToAddress = async (address) => {
548
+ findQueriesToAddress = async (address) => {
401
549
  const queryBoundWitnessDiviner = await this.queriesDiviner();
402
550
  const timestamp = await this.retrieveState(address);
403
551
  const destination = [
404
552
  address
405
553
  ];
406
- const limit = this.individualAddressBatchQueryLimitConfig;
554
+ const limit = this.perAddressBatchQueryLimit;
407
555
  const divinerQuery = {
408
556
  destination,
409
557
  limit,
@@ -414,10 +562,10 @@ var _AsyncQueryBusServer = class _AsyncQueryBusServer extends AsyncQueryBusBase
414
562
  const result = await queryBoundWitnessDiviner.divine([
415
563
  divinerQuery
416
564
  ]);
417
- const commands = result.filter(isQueryBoundWitnessWithMeta);
418
- const nextState = Math.max(...commands.map((c) => c.timestamp ?? 0));
565
+ const queries = result.filter(isQueryBoundWitnessWithMeta);
566
+ const nextState = queries.length > 0 ? Math.max(...queries.map((c) => c.timestamp ?? 0)) + 1 : timestamp;
419
567
  await this.commitState(address, nextState);
420
- return commands;
568
+ return queries;
421
569
  };
422
570
  /**
423
571
  * Runs the background divine process on a loop with a delay
@@ -450,12 +598,12 @@ var _AsyncQueryBusServer = class _AsyncQueryBusServer extends AsyncQueryBusBase
450
598
  try {
451
599
  const localModuleName = localModule.config.name ?? localModule.address;
452
600
  (_a2 = this.logger) == null ? void 0 : _a2.debug(`Checking for inbound commands to ${localModuleName}`);
453
- const commands = await this.findCommandsToAddress(localModule.address);
454
- if (commands.length === 0)
601
+ const queries = await this.findQueriesToAddress(localModule.address);
602
+ if (queries.length === 0)
455
603
  return;
456
604
  (_b = this.logger) == null ? void 0 : _b.debug(`Found commands addressed to local module: ${localModuleName}`);
457
- for (const command of commands) {
458
- await this.callLocalModule(localModule, command);
605
+ for (const query of queries) {
606
+ await this.callLocalModule(localModule, query);
459
607
  }
460
608
  } catch (error) {
461
609
  (_c = this.logger) == null ? void 0 : _c.error(`Error processing commands for address ${localModule.address}: ${error}`);
@@ -463,10 +611,67 @@ var _AsyncQueryBusServer = class _AsyncQueryBusServer extends AsyncQueryBusBase
463
611
  }));
464
612
  };
465
613
  };
466
- __name(_AsyncQueryBusServer, "AsyncQueryBusServer");
467
- var AsyncQueryBusServer = _AsyncQueryBusServer;
614
+ __name(_AsyncQueryBusHost, "AsyncQueryBusHost");
615
+ var AsyncQueryBusHost = _AsyncQueryBusHost;
616
+
617
+ // src/AbstractModuleHost/AbstractModuleHost.ts
618
+ import { Base as Base3 } from "@xylabs/object";
619
+ var _AbstractModuleHost = class _AbstractModuleHost extends Base3 {
620
+ };
621
+ __name(_AbstractModuleHost, "AbstractModuleHost");
622
+ var AbstractModuleHost = _AbstractModuleHost;
623
+
624
+ // src/AsyncQueryBus/ModuleHost/ModuleHost.ts
625
+ var _AsyncQueryBusModuleHost = class _AsyncQueryBusModuleHost extends AbstractModuleHost {
626
+ _busHost;
627
+ constructor(params) {
628
+ super(params);
629
+ }
630
+ async start() {
631
+ var _a;
632
+ const listeningModules = this.params.config.listeningModules ?? (await this.params.module.resolve(void 0, {
633
+ direction: "down"
634
+ })).map((m) => m.address);
635
+ this._busHost = new AsyncQueryBusHost({
636
+ config: {
637
+ ...this.params.config,
638
+ listeningModules
639
+ },
640
+ logger: this.params.logger,
641
+ resolver: this.params.module
642
+ });
643
+ (_a = this._busHost) == null ? void 0 : _a.start();
644
+ }
645
+ stop() {
646
+ var _a;
647
+ (_a = this._busHost) == null ? void 0 : _a.stop();
648
+ }
649
+ };
650
+ __name(_AsyncQueryBusModuleHost, "AsyncQueryBusModuleHost");
651
+ var AsyncQueryBusModuleHost = _AsyncQueryBusModuleHost;
652
+
653
+ // src/AsyncQueryBus/ModuleProxy/ModuleProxy.ts
654
+ var _AsyncQueryBusModuleProxy = class _AsyncQueryBusModuleProxy extends AbstractModuleProxy {
655
+ async query(query, payloads) {
656
+ return await this.proxyParams.bridgeClient.send(this.address, query, payloads);
657
+ }
658
+ };
659
+ __name(_AsyncQueryBusModuleProxy, "AsyncQueryBusModuleProxy");
660
+ var AsyncQueryBusModuleProxy = _AsyncQueryBusModuleProxy;
661
+
662
+ // src/Schema.ts
663
+ var PubSubBridgeSchema = "network.xyo.bridge.pubsub";
664
+
665
+ // src/Config.ts
666
+ var PubSubBridgeConfigSchema = `${PubSubBridgeSchema}.config`;
468
667
 
469
668
  // src/PubSubBridge.ts
669
+ import { assertEx as assertEx4 } from "@xylabs/assert";
670
+ import { AbstractBridge } from "@xyo-network/abstract-bridge";
671
+ import { ModuleManifestPayloadSchema } from "@xyo-network/manifest-model";
672
+ import { creatableModule, ModuleManifestQuerySchema as ModuleManifestQuerySchema2 } from "@xyo-network/module-model";
673
+ import { isPayloadOfSchemaType } from "@xyo-network/payload-model";
674
+ import { LRUCache as LRUCache3 } from "lru-cache";
470
675
  function _ts_decorate(decorators, target, key, desc) {
471
676
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
472
677
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -488,10 +693,10 @@ var _PubSubBridge = class _PubSubBridge extends AbstractBridge {
488
693
  _targetConfigs = {};
489
694
  _targetQueries = {};
490
695
  _busClient;
491
- _busServer;
696
+ _busHost;
492
697
  get discoverCache() {
493
698
  const config = this.discoverCacheConfig;
494
- this._discoverCache = this._discoverCache ?? new LRUCache2({
699
+ this._discoverCache = this._discoverCache ?? new LRUCache3({
495
700
  ttlAutopurge: true,
496
701
  ...config
497
702
  });
@@ -549,7 +754,7 @@ var _PubSubBridge = class _PubSubBridge extends AbstractBridge {
549
754
  const addressToCall = address ?? this.getRootAddress();
550
755
  const queryPayload = {
551
756
  maxDepth,
552
- schema: ModuleManifestQuerySchema
757
+ schema: ModuleManifestQuerySchema2
553
758
  };
554
759
  const boundQuery = await this.bindQuery(queryPayload);
555
760
  const manifest = assertEx4(await this.targetQuery(addressToCall, boundQuery[0], boundQuery[1]), () => `Unable to resolve [${address}]`)[1];
@@ -573,32 +778,30 @@ var _PubSubBridge = class _PubSubBridge extends AbstractBridge {
573
778
  busClient() {
574
779
  if (!this._busClient) {
575
780
  this._busClient = new AsyncQueryBusClient({
576
- config: this.config,
781
+ config: this.config.client,
577
782
  logger: this.logger,
578
783
  resolver: this
579
784
  });
580
785
  }
581
786
  return this._busClient;
582
787
  }
583
- busServer() {
584
- if (!this._busServer) {
585
- this._busServer = new AsyncQueryBusServer({
586
- config: this.config,
788
+ busHost() {
789
+ if (!this._busHost) {
790
+ this._busHost = new AsyncQueryBusHost({
791
+ config: this.config.host,
587
792
  logger: this.logger,
588
793
  resolver: this
589
794
  });
590
795
  }
591
- return this._busServer;
796
+ return this._busHost;
592
797
  }
593
798
  async startHandler() {
594
799
  await Promise.resolve(this.connect());
595
- this.busServer().start();
596
- this.busClient().start();
800
+ this.busHost().start();
597
801
  return true;
598
802
  }
599
803
  stopHandler(_timeout) {
600
- this.busClient().stop();
601
- this.busServer().stop();
804
+ this.busHost().stop();
602
805
  return true;
603
806
  }
604
807
  };
@@ -611,6 +814,12 @@ PubSubBridge = _ts_decorate([
611
814
  creatableModule()
612
815
  ], PubSubBridge);
613
816
  export {
817
+ AbstractModuleProxy,
818
+ AsyncQueryBusClient,
819
+ AsyncQueryBusHost,
820
+ AsyncQueryBusModuleHost,
821
+ AsyncQueryBusModuleProxy,
822
+ Pending,
614
823
  PubSubBridge,
615
824
  PubSubBridgeConfigSchema,
616
825
  PubSubBridgeSchema