@xyo-network/bridge-pub-sub 2.91.0 → 2.91.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 +51 -15
  26. package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.cts.map +1 -1
  27. package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.mts +51 -15
  28. package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.mts.map +1 -1
  29. package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.ts +51 -15
  30. package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.ts.map +1 -1
  31. package/dist/browser/AsyncQueryBus/AsyncQueryBusClient.d.cts +14 -45
  32. package/dist/browser/AsyncQueryBus/AsyncQueryBusClient.d.cts.map +1 -1
  33. package/dist/browser/AsyncQueryBus/AsyncQueryBusClient.d.mts +14 -45
  34. package/dist/browser/AsyncQueryBus/AsyncQueryBusClient.d.mts.map +1 -1
  35. package/dist/browser/AsyncQueryBus/AsyncQueryBusClient.d.ts +14 -45
  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 +4 -10
  92. package/dist/browser/PubSubBridge.d.cts.map +1 -1
  93. package/dist/browser/PubSubBridge.d.mts +4 -10
  94. package/dist/browser/PubSubBridge.d.mts.map +1 -1
  95. package/dist/browser/PubSubBridge.d.ts +4 -10
  96. package/dist/browser/PubSubBridge.d.ts.map +1 -1
  97. package/dist/browser/index.cjs +331 -126
  98. package/dist/browser/index.cjs.map +1 -1
  99. package/dist/browser/index.d.cts +1 -0
  100. package/dist/browser/index.d.cts.map +1 -1
  101. package/dist/browser/index.d.mts +1 -0
  102. package/dist/browser/index.d.mts.map +1 -1
  103. package/dist/browser/index.d.ts +1 -0
  104. package/dist/browser/index.d.ts.map +1 -1
  105. package/dist/browser/index.js +332 -127
  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 +51 -15
  132. package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.cts.map +1 -1
  133. package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.mts +51 -15
  134. package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.mts.map +1 -1
  135. package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.ts +51 -15
  136. package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.ts.map +1 -1
  137. package/dist/node/AsyncQueryBus/AsyncQueryBusClient.d.cts +14 -45
  138. package/dist/node/AsyncQueryBus/AsyncQueryBusClient.d.cts.map +1 -1
  139. package/dist/node/AsyncQueryBus/AsyncQueryBusClient.d.mts +14 -45
  140. package/dist/node/AsyncQueryBus/AsyncQueryBusClient.d.mts.map +1 -1
  141. package/dist/node/AsyncQueryBus/AsyncQueryBusClient.d.ts +14 -45
  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 +4 -10
  198. package/dist/node/PubSubBridge.d.cts.map +1 -1
  199. package/dist/node/PubSubBridge.d.mts +4 -10
  200. package/dist/node/PubSubBridge.d.mts.map +1 -1
  201. package/dist/node/PubSubBridge.d.ts +4 -10
  202. package/dist/node/PubSubBridge.d.ts.map +1 -1
  203. package/dist/node/index.cjs +355 -144
  204. package/dist/node/index.cjs.map +1 -1
  205. package/dist/node/index.d.cts +1 -0
  206. package/dist/node/index.d.cts.map +1 -1
  207. package/dist/node/index.d.mts +1 -0
  208. package/dist/node/index.d.mts.map +1 -1
  209. package/dist/node/index.d.ts +1 -0
  210. package/dist/node/index.d.ts.map +1 -1
  211. package/dist/node/index.js +352 -144
  212. package/dist/node/index.js.map +1 -1
  213. package/package.json +30 -24
  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 +11 -33
  219. package/src/AsyncQueryBus/AsyncQueryBusClient.ts +69 -61
  220. package/src/AsyncQueryBus/{AsyncQueryBusServer.ts → AsyncQueryBusHost.ts} +32 -26
  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 +10 -12
  230. package/src/index.ts +1 -0
  231. package/dist/browser/AsyncQueryBus/AsyncQueryBusServer.d.cts +0 -75
  232. package/dist/browser/AsyncQueryBus/AsyncQueryBusServer.d.cts.map +0 -1
  233. package/dist/browser/AsyncQueryBus/AsyncQueryBusServer.d.mts +0 -75
  234. package/dist/browser/AsyncQueryBus/AsyncQueryBusServer.d.mts.map +0 -1
  235. package/dist/browser/AsyncQueryBus/AsyncQueryBusServer.d.ts +0 -75
  236. package/dist/browser/AsyncQueryBus/AsyncQueryBusServer.d.ts.map +0 -1
  237. package/dist/node/AsyncQueryBus/AsyncQueryBusServer.d.cts +0 -75
  238. package/dist/node/AsyncQueryBus/AsyncQueryBusServer.d.cts.map +0 -1
  239. package/dist/node/AsyncQueryBus/AsyncQueryBusServer.d.mts +0 -75
  240. package/dist/node/AsyncQueryBus/AsyncQueryBusServer.d.mts.map +0 -1
  241. package/dist/node/AsyncQueryBus/AsyncQueryBusServer.d.ts +0 -75
  242. package/dist/node/AsyncQueryBus/AsyncQueryBusServer.d.ts.map +0 -1
@@ -26,8 +26,11 @@ var __publicField = (obj, key, value) => {
26
26
  // src/index.ts
27
27
  var src_exports = {};
28
28
  __export(src_exports, {
29
+ AbstractModuleProxy: () => AbstractModuleProxy,
29
30
  AsyncQueryBusClient: () => AsyncQueryBusClient,
30
- AsyncQueryBusServer: () => AsyncQueryBusServer,
31
+ AsyncQueryBusHost: () => AsyncQueryBusHost,
32
+ AsyncQueryBusModuleHost: () => AsyncQueryBusModuleHost,
33
+ AsyncQueryBusModuleProxy: () => AsyncQueryBusModuleProxy,
31
34
  Pending: () => Pending,
32
35
  PubSubBridge: () => PubSubBridge,
33
36
  PubSubBridgeConfigSchema: () => PubSubBridgeConfigSchema,
@@ -35,25 +38,181 @@ __export(src_exports, {
35
38
  });
36
39
  module.exports = __toCommonJS(src_exports);
37
40
 
41
+ // src/AbstractModuleProxy/AbstractModuleProxy.ts
42
+ var import_assert = require("@xylabs/assert");
43
+ var import_lodash = require("@xylabs/lodash");
44
+ var import_object = require("@xylabs/object");
45
+ var import_promise = require("@xylabs/promise");
46
+ var import_boundwitness_builder = require("@xyo-network/boundwitness-builder");
47
+ var import_boundwitness_wrapper = require("@xyo-network/boundwitness-wrapper");
48
+ var import_module_model = require("@xyo-network/module-model");
49
+ var import_payload_model = require("@xyo-network/payload-model");
50
+ var _AbstractModuleProxy = class _AbstractModuleProxy extends import_object.Base {
51
+ eventData = {};
52
+ proxyParams;
53
+ constructor(params) {
54
+ super({
55
+ config: {
56
+ schema: import_module_model.ModuleConfigSchema
57
+ }
58
+ });
59
+ this.proxyParams = params;
60
+ }
61
+ get account() {
62
+ return this.proxyParams.account;
63
+ }
64
+ get address() {
65
+ return this.proxyParams.moduleAddress;
66
+ }
67
+ get config() {
68
+ return this.params.config;
69
+ }
70
+ get downResolver() {
71
+ throw new Error("Unsupported");
72
+ }
73
+ get id() {
74
+ return this.proxyParams.moduleAddress;
75
+ }
76
+ get queries() {
77
+ return this.proxyParams.queries;
78
+ }
79
+ get upResolver() {
80
+ throw new Error("Unsupported");
81
+ }
82
+ static hasRequiredQueries(module2) {
83
+ return this.missingRequiredQueries(module2).length === 0;
84
+ }
85
+ static missingRequiredQueries(module2) {
86
+ const moduleQueries = module2.queries;
87
+ return (0, import_lodash.compact)(this.requiredQueries.map((query) => {
88
+ return moduleQueries.includes(query) ? null : query;
89
+ }));
90
+ }
91
+ async addressPreviousHash() {
92
+ const queryPayload = {
93
+ schema: import_module_model.ModuleAddressQuerySchema
94
+ };
95
+ return (0, import_assert.assertEx)((await this.sendQuery(queryPayload)).find((payload) => payload.schema === import_module_model.AddressPreviousHashSchema), "Result did not include correct payload");
96
+ }
97
+ clearListeners(_eventNames) {
98
+ throw new Error("Unsupported");
99
+ }
100
+ //TODO: Make ModuleDescription into real payload
101
+ async describe() {
102
+ const queryPayload = {
103
+ schema: import_module_model.ModuleDescribeQuerySchema
104
+ };
105
+ return (await this.sendQuery(queryPayload))[0];
106
+ }
107
+ async discover() {
108
+ const queryPayload = {
109
+ schema: import_module_model.ModuleDiscoverQuerySchema
110
+ };
111
+ return await this.sendQuery(queryPayload);
112
+ }
113
+ emit(_eventName, _eventArgs) {
114
+ throw new Error("Unsupported");
115
+ }
116
+ emitSerial(_eventName, _eventArgs) {
117
+ throw new Error("Unsupported");
118
+ }
119
+ listenerCount(_eventNames) {
120
+ throw new Error("Unsupported");
121
+ }
122
+ async manifest(maxDepth) {
123
+ const queryPayload = {
124
+ schema: import_module_model.ModuleManifestQuerySchema,
125
+ ...maxDepth === void 0 ? {} : {
126
+ maxDepth
127
+ }
128
+ };
129
+ return (await this.sendQuery(queryPayload))[0];
130
+ }
131
+ async moduleAddress() {
132
+ const queryPayload = {
133
+ schema: import_module_model.ModuleAddressQuerySchema
134
+ };
135
+ return await this.sendQuery(queryPayload);
136
+ }
137
+ off(_eventNames, _listener) {
138
+ throw new Error("Unsupported");
139
+ }
140
+ offAny(_listener) {
141
+ throw new Error("Unsupported");
142
+ }
143
+ on(_eventNames, _listener) {
144
+ throw new Error("Unsupported");
145
+ }
146
+ onAny(_listener) {
147
+ throw new Error("Unsupported");
148
+ }
149
+ once(_eventName, _listener) {
150
+ throw new Error("Unsupported");
151
+ }
152
+ async previousHash() {
153
+ const queryPayload = {
154
+ schema: import_module_model.ModuleAddressQuerySchema
155
+ };
156
+ return (await this.sendQuery(queryPayload)).pop().previousHash;
157
+ }
158
+ queryable(_query, _payloads) {
159
+ return true;
160
+ }
161
+ resolve(nameOrAddressOrFilter, _options) {
162
+ return typeof nameOrAddressOrFilter === "string" ? void 0 : [];
163
+ }
164
+ state() {
165
+ return [];
166
+ }
167
+ bindQuery(query, payloads, account = this.account) {
168
+ const promise = new import_promise.PromiseEx(async (resolve) => {
169
+ const result = await this.bindQueryInternal(query, payloads, account);
170
+ resolve == null ? void 0 : resolve(result);
171
+ return result;
172
+ }, account);
173
+ return promise;
174
+ }
175
+ async bindQueryInternal(query, payloads, account = this.account) {
176
+ const builder = await new import_boundwitness_builder.QueryBoundWitnessBuilder().payloads(payloads).query(query);
177
+ const result = await (account ? builder.witness(account) : builder).build();
178
+ return result;
179
+ }
180
+ async filterErrors(result) {
181
+ const wrapper = await import_boundwitness_wrapper.BoundWitnessWrapper.wrap(result[0], result[1]);
182
+ return wrapper.payloadsBySchema(import_payload_model.ModuleErrorSchema);
183
+ }
184
+ async sendQuery(queryPayload, payloads) {
185
+ const query = await this.bindQuery(queryPayload, payloads);
186
+ const [, resultPayloads, errors] = await this.query(query[0], query[1]);
187
+ if (errors && errors.length > 0) {
188
+ throw errors[0];
189
+ }
190
+ return resultPayloads;
191
+ }
192
+ };
193
+ __name(_AbstractModuleProxy, "AbstractModuleProxy");
194
+ __publicField(_AbstractModuleProxy, "requiredQueries", [
195
+ import_module_model.ModuleDiscoverQuerySchema
196
+ ]);
197
+ var AbstractModuleProxy = _AbstractModuleProxy;
198
+
38
199
  // src/AsyncQueryBus/AsyncQueryBusClient.ts
39
- var import_assert2 = require("@xylabs/assert");
40
200
  var import_delay = require("@xylabs/delay");
41
201
  var import_forget = require("@xylabs/forget");
42
202
  var import_timer = require("@xylabs/timer");
43
203
  var import_boundwitness_model = require("@xyo-network/boundwitness-model");
44
204
  var import_diviner_boundwitness_model = require("@xyo-network/diviner-boundwitness-model");
45
- var import_module_model = require("@xyo-network/module-model");
46
205
  var import_payload_builder = require("@xyo-network/payload-builder");
206
+ var import_lru_cache2 = require("lru-cache");
47
207
 
48
208
  // src/AsyncQueryBus/AsyncQueryBusBase.ts
49
- var import_assert = require("@xylabs/assert");
50
- var import_object = require("@xylabs/object");
209
+ var import_assert2 = require("@xylabs/assert");
210
+ var import_object2 = require("@xylabs/object");
51
211
  var import_archivist_model = require("@xyo-network/archivist-model");
52
212
  var import_diviner_model = require("@xyo-network/diviner-model");
53
213
  var import_lru_cache = require("lru-cache");
54
- var _AsyncQueryBusBase = class _AsyncQueryBusBase extends import_object.Base {
214
+ var _AsyncQueryBusBase = class _AsyncQueryBusBase extends import_object2.Base {
55
215
  _lastState;
56
- _queryCache;
57
216
  _targetConfigs = {};
58
217
  _targetQueries = {};
59
218
  constructor(params) {
@@ -62,19 +221,9 @@ var _AsyncQueryBusBase = class _AsyncQueryBusBase extends import_object.Base {
62
221
  get config() {
63
222
  return this.params.config;
64
223
  }
65
- get individualAddressBatchQueryLimitConfig() {
66
- return this.config.individualAddressBatchQueryLimit ?? 10;
67
- }
68
224
  get pollFrequencyConfig() {
69
- return this.config.pollFrequency ?? 1e3;
70
- }
71
- get queryCacheConfig() {
72
- const queryCacheConfig = this.config.queryCache === true ? {} : this.config.queryCache;
73
- return {
74
- max: 100,
75
- ttl: 1e3 * 60,
76
- ...queryCacheConfig
77
- };
225
+ var _a;
226
+ return ((_a = this.config) == null ? void 0 : _a.pollFrequency) ?? 1e3;
78
227
  }
79
228
  get resolver() {
80
229
  return this.params.resolver;
@@ -90,47 +239,32 @@ var _AsyncQueryBusBase = class _AsyncQueryBusBase extends import_object.Base {
90
239
  this._lastState = this._lastState ?? new import_lru_cache.LRUCache(requiredConfig);
91
240
  return this._lastState;
92
241
  }
93
- /**
94
- * A cache of queries that have been issued
95
- */
96
- get queryCache() {
97
- const config = this.queryCacheConfig;
98
- const requiredConfig = {
99
- noUpdateTTL: false,
100
- ttlAutopurge: true
101
- };
102
- this._queryCache = this._queryCache ?? new import_lru_cache.LRUCache({
103
- ...config,
104
- ...requiredConfig
105
- });
106
- return this._queryCache;
107
- }
108
242
  async queriesArchivist() {
109
- var _a;
110
- return (0, import_assert.assertEx)((0, import_archivist_model.asArchivistInstance)(await this.resolver.resolve((_a = this.config.queries) == null ? void 0 : _a.archivist)), () => {
111
- var _a2;
112
- return `Unable to resolve queriesArchivist [${(_a2 = this.config.queries) == null ? void 0 : _a2.archivist}]`;
243
+ var _a, _b, _c;
244
+ return (0, import_assert2.assertEx)((0, import_archivist_model.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)), () => {
245
+ var _a2, _b2, _c2;
246
+ 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}]`;
113
247
  });
114
248
  }
115
249
  async queriesDiviner() {
116
- var _a;
117
- return (0, import_assert.assertEx)((0, import_diviner_model.asDivinerInstance)(await this.resolver.resolve((_a = this.config.queries) == null ? void 0 : _a.boundWitnessDiviner)), () => {
118
- var _a2;
119
- return `Unable to resolve queriesDiviner [${(_a2 = this.config.queries) == null ? void 0 : _a2.boundWitnessDiviner}]`;
250
+ var _a, _b, _c;
251
+ return (0, import_assert2.assertEx)((0, import_diviner_model.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)), () => {
252
+ var _a2, _b2, _c2;
253
+ 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}]`;
120
254
  });
121
255
  }
122
256
  async responsesArchivist() {
123
- var _a;
124
- return (0, import_assert.assertEx)((0, import_archivist_model.asArchivistInstance)(await this.resolver.resolve((_a = this.config.responses) == null ? void 0 : _a.archivist)), () => {
125
- var _a2;
126
- return `Unable to resolve responsesArchivist [${(_a2 = this.config.responses) == null ? void 0 : _a2.archivist}]`;
257
+ var _a, _b, _c;
258
+ return (0, import_assert2.assertEx)((0, import_archivist_model.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)), () => {
259
+ var _a2, _b2, _c2;
260
+ 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}]`;
127
261
  });
128
262
  }
129
263
  async responsesDiviner() {
130
- var _a;
131
- return (0, import_assert.assertEx)((0, import_diviner_model.asDivinerInstance)(await this.resolver.resolve((_a = this.config.responses) == null ? void 0 : _a.boundWitnessDiviner)), () => {
132
- var _a2;
133
- return `Unable to resolve responsesDiviner [${(_a2 = this.config.responses) == null ? void 0 : _a2.boundWitnessDiviner}]`;
264
+ var _a, _b, _c;
265
+ return (0, import_assert2.assertEx)((0, import_diviner_model.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)), () => {
266
+ var _a2, _b2, _c2;
267
+ 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}]`;
134
268
  });
135
269
  }
136
270
  /**
@@ -172,21 +306,45 @@ var Pending = "pending";
172
306
 
173
307
  // src/AsyncQueryBus/AsyncQueryBusClient.ts
174
308
  var _AsyncQueryBusClient = class _AsyncQueryBusClient extends AsyncQueryBusBase {
309
+ _queryCache;
310
+ _pollCount = 0;
175
311
  _pollId;
176
312
  constructor(params) {
177
313
  super(params);
178
314
  }
315
+ get queryCacheConfig() {
316
+ var _a, _b;
317
+ const queryCacheConfig = ((_a = this.config) == null ? void 0 : _a.queryCache) === true ? {} : (_b = this.config) == null ? void 0 : _b.queryCache;
318
+ return {
319
+ max: 100,
320
+ ttl: 1e3 * 60,
321
+ ...queryCacheConfig
322
+ };
323
+ }
179
324
  get started() {
180
325
  return !!this._pollId;
181
326
  }
182
- async listeningModules() {
183
- const mods = this.config.listeningModules ? await Promise.all(this.config.listeningModules.map(async (listeningModule) => (0, import_assert2.assertEx)((0, import_module_model.asModuleInstance)(await this.resolver.resolve(listeningModule)), () => `Unable to resolve all listeningModule [${listeningModule}]`))) : await this.resolver.resolve({
184
- direction: "all"
327
+ /**
328
+ * A cache of queries that have been issued
329
+ */
330
+ get queryCache() {
331
+ const config = this.queryCacheConfig;
332
+ const requiredConfig = {
333
+ noUpdateTTL: false,
334
+ ttlAutopurge: true
335
+ };
336
+ this._queryCache = this._queryCache ?? new import_lru_cache2.LRUCache({
337
+ ...config,
338
+ ...requiredConfig
185
339
  });
186
- return mods;
340
+ return this._queryCache;
341
+ }
342
+ listeningAddresses() {
343
+ var _a;
344
+ return (_a = this._queryCache) == null ? void 0 : _a.keys();
187
345
  }
188
346
  async send(address, query, payloads) {
189
- var _a, _b, _c, _d, _e, _f;
347
+ var _a, _b, _c, _d;
190
348
  (_a = this.logger) == null ? void 0 : _a.debug(`Begin issuing query to: ${address}`);
191
349
  const $meta = {
192
350
  ...query == null ? void 0 : query.$meta,
@@ -199,10 +357,6 @@ var _AsyncQueryBusClient = class _AsyncQueryBusClient extends AsyncQueryBusBase
199
357
  $meta
200
358
  });
201
359
  const queryArchivist = await this.queriesArchivist();
202
- const sourceAddress = query.addresses.at(0);
203
- if (sourceAddress && !((_b = this.config.listeningModules) == null ? void 0 : _b.includes(sourceAddress))) {
204
- (_c = this.config.listeningModules) == null ? void 0 : _c.push(sourceAddress);
205
- }
206
360
  const routedQueryHash = (
207
361
  // Trust the signed hash if it's there
208
362
  (routedQuery == null ? void 0 : routedQuery.$hash) ?? // TODO: What is the right way to find the dataHash
@@ -210,15 +364,15 @@ var _AsyncQueryBusClient = class _AsyncQueryBusClient extends AsyncQueryBusBase
210
364
  routedQuery
211
365
  ]))[0]
212
366
  );
213
- (_d = this.logger) == null ? void 0 : _d.debug(`Issuing query: ${routedQueryHash} to: ${address}`);
367
+ (_b = this.logger) == null ? void 0 : _b.debug(`Issuing query: ${routedQueryHash} to: ${address}`);
214
368
  const data = payloads ? [
215
369
  routedQuery,
216
370
  ...payloads
217
371
  ] : [
218
372
  routedQuery
219
373
  ];
220
- const insertResult = await ((_e = queryArchivist.insert) == null ? void 0 : _e.call(queryArchivist, data));
221
- (_f = this.logger) == null ? void 0 : _f.debug(`Issued query: ${routedQueryHash} to: ${address}`);
374
+ const insertResult = await ((_c = queryArchivist.insert) == null ? void 0 : _c.call(queryArchivist, data));
375
+ (_d = this.logger) == null ? void 0 : _d.debug(`Issued query: ${routedQueryHash} to: ${address}`);
222
376
  this.queryCache.set(routedQueryHash, Pending);
223
377
  if (!insertResult)
224
378
  throw new Error("Unable to issue query to queryArchivist");
@@ -227,52 +381,43 @@ var _AsyncQueryBusClient = class _AsyncQueryBusClient extends AsyncQueryBusBase
227
381
  (_a2 = this.logger) == null ? void 0 : _a2.debug(`Polling for response to query: ${routedQueryHash}`);
228
382
  const pollForResponse = /* @__PURE__ */ __name(async () => {
229
383
  var _a3, _b2;
230
- let response = this.queryCache.get(routedQueryHash);
231
- while (response !== void 0) {
232
- await (0, import_delay.delay)(100);
233
- response = this.queryCache.get(routedQueryHash);
234
- if (response && response !== Pending) {
235
- (_a3 = this.logger) == null ? void 0 : _a3.debug(`Returning response to query: ${routedQueryHash}`);
236
- resolve(response);
237
- return;
384
+ try {
385
+ this.start();
386
+ let response = this.queryCache.get(routedQueryHash);
387
+ while (response !== void 0) {
388
+ await (0, import_delay.delay)(100);
389
+ response = this.queryCache.get(routedQueryHash);
390
+ if (response && response !== Pending) {
391
+ (_a3 = this.logger) == null ? void 0 : _a3.debug(`Returning response to query: ${routedQueryHash}`);
392
+ resolve(response);
393
+ return;
394
+ }
238
395
  }
396
+ (_b2 = this.logger) == null ? void 0 : _b2.error("Timeout waiting for query response");
397
+ const error = {
398
+ message: "Timeout waiting for query response",
399
+ query: "network.xyo.boundwitness",
400
+ schema: "network.xyo.error.module",
401
+ sources: [
402
+ routedQueryHash
403
+ ]
404
+ };
405
+ resolve([
406
+ routedQuery,
407
+ [],
408
+ [
409
+ await import_payload_builder.PayloadBuilder.build(error)
410
+ ]
411
+ ]);
412
+ return;
413
+ } finally {
414
+ this.stop();
239
415
  }
240
- (_b2 = this.logger) == null ? void 0 : _b2.error("Timeout waiting for query response");
241
- const error = {
242
- message: "Timeout waiting for query response",
243
- query: "network.xyo.boundwitness",
244
- schema: "network.xyo.error.module",
245
- sources: [
246
- routedQueryHash
247
- ]
248
- };
249
- resolve([
250
- routedQuery,
251
- [],
252
- [
253
- await import_payload_builder.PayloadBuilder.build(error)
254
- ]
255
- ]);
256
- return;
257
416
  }, "pollForResponse");
258
417
  (0, import_forget.forget)(pollForResponse());
259
418
  });
260
419
  return context;
261
420
  }
262
- start() {
263
- if (this.started) {
264
- console.warn("AsyncQueryBus starting when already started");
265
- }
266
- this.poll();
267
- }
268
- stop() {
269
- if (!this.started) {
270
- console.warn("AsyncQueryBus stopping when already stopped");
271
- }
272
- if (this._pollId)
273
- (0, import_timer.clearTimeoutEx)(this._pollId);
274
- this._pollId = void 0;
275
- }
276
421
  /**
277
422
  * Runs the background divine process on a loop with a delay
278
423
  * specified by the `config.pollFrequency`
@@ -326,11 +471,26 @@ var _AsyncQueryBusClient = class _AsyncQueryBusClient extends AsyncQueryBusBase
326
471
  }
327
472
  }));
328
473
  };
474
+ start() {
475
+ if (this._pollCount === 0) {
476
+ this.poll();
477
+ }
478
+ this._pollCount++;
479
+ }
480
+ stop() {
481
+ this._pollCount--;
482
+ if (this._pollCount <= 0) {
483
+ if (this._pollId)
484
+ (0, import_timer.clearTimeoutEx)(this._pollId);
485
+ this._pollId = void 0;
486
+ this._pollCount = 0;
487
+ }
488
+ }
329
489
  };
330
490
  __name(_AsyncQueryBusClient, "AsyncQueryBusClient");
331
491
  var AsyncQueryBusClient = _AsyncQueryBusClient;
332
492
 
333
- // src/AsyncQueryBus/AsyncQueryBusServer.ts
493
+ // src/AsyncQueryBus/AsyncQueryBusHost.ts
334
494
  var import_array = require("@xylabs/array");
335
495
  var import_assert3 = require("@xylabs/assert");
336
496
  var import_timer2 = require("@xylabs/timer");
@@ -338,17 +498,22 @@ var import_boundwitness_model2 = require("@xyo-network/boundwitness-model");
338
498
  var import_diviner_boundwitness_model2 = require("@xyo-network/diviner-boundwitness-model");
339
499
  var import_module_model2 = require("@xyo-network/module-model");
340
500
  var import_payload_builder2 = require("@xyo-network/payload-builder");
341
- var _AsyncQueryBusServer = class _AsyncQueryBusServer extends AsyncQueryBusBase {
501
+ var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
342
502
  _pollId;
343
503
  constructor(params) {
344
504
  super(params);
345
505
  }
506
+ get perAddressBatchQueryLimit() {
507
+ var _a;
508
+ return ((_a = this.config) == null ? void 0 : _a.perAddressBatchQueryLimit) ?? 10;
509
+ }
346
510
  get started() {
347
511
  return !!this._pollId;
348
512
  }
349
513
  async listeningModules() {
350
- const mods = this.config.listeningModules ? await Promise.all(this.config.listeningModules.map(async (listeningModule) => (0, import_assert3.assertEx)((0, import_module_model2.asModuleInstance)(await this.resolver.resolve(listeningModule)), () => `Unable to resolve listeningModule [${listeningModule}]`))) : await this.resolver.resolve({
351
- direction: "all"
514
+ var _a;
515
+ const mods = ((_a = this.config) == null ? void 0 : _a.listeningModules) ? await Promise.all(this.config.listeningModules.map(async (listeningModule) => (0, import_assert3.assertEx)((0, import_module_model2.asModuleInstance)(await this.resolver.resolve(listeningModule)), () => `Unable to resolve listeningModule [${listeningModule}]`))) : await this.resolver.resolve(void 0, {
516
+ direction: "down"
352
517
  });
353
518
  return mods;
354
519
  }
@@ -366,28 +531,28 @@ var _AsyncQueryBusServer = class _AsyncQueryBusServer extends AsyncQueryBusBase
366
531
  (0, import_timer2.clearTimeoutEx)(this._pollId);
367
532
  this._pollId = void 0;
368
533
  }
369
- callLocalModule = async (localModule, command) => {
534
+ callLocalModule = async (localModule, query) => {
370
535
  var _a, _b, _c, _d, _e, _f;
371
536
  const localModuleName = localModule.config.name ?? localModule.address;
372
537
  const queryArchivist = await this.queriesArchivist();
373
538
  const responseArchivist = await this.responsesArchivist();
374
- const commandDestination = (_a = command.$meta) == null ? void 0 : _a.destination;
539
+ const commandDestination = (_a = query.$meta) == null ? void 0 : _a.destination;
375
540
  if (commandDestination && (commandDestination == null ? void 0 : commandDestination.includes(localModule.address))) {
376
- const queryIndex = command.payload_hashes.indexOf(command.query);
541
+ const queryIndex = query.payload_hashes.indexOf(query.query);
377
542
  if (queryIndex !== -1) {
378
- const querySchema = command.payload_schemas[queryIndex];
543
+ const querySchema = query.payload_schemas[queryIndex];
379
544
  if (localModule.queries.includes(querySchema)) {
380
- const commandPayloads = await queryArchivist.get(command.payload_hashes);
545
+ const commandPayloads = await queryArchivist.get(query.payload_hashes);
381
546
  const commandPayloadsDict = await import_payload_builder2.PayloadBuilder.toAllHashMap(commandPayloads);
382
- const commandHash = (await import_payload_builder2.PayloadBuilder.build(command)).$hash;
383
- if (!(0, import_array.containsAll)(Object.keys(commandPayloadsDict), command.payload_hashes)) {
547
+ const commandHash = (await import_payload_builder2.PayloadBuilder.build(query)).$hash;
548
+ if (!(0, import_array.containsAll)(Object.keys(commandPayloadsDict), query.payload_hashes)) {
384
549
  (_b = this.logger) == null ? void 0 : _b.error(`Error processing command ${commandHash} for module ${localModuleName}, missing payloads`);
385
550
  return;
386
551
  }
387
552
  try {
388
- const commandSchema = commandPayloadsDict[command.query].schema;
553
+ const commandSchema = commandPayloadsDict[query.query].schema;
389
554
  (_c = this.logger) == null ? void 0 : _c.debug(`Issuing command ${commandSchema} (${commandHash}) addressed to module: ${localModuleName}`);
390
- const response = await localModule.query(command, commandPayloads);
555
+ const response = await localModule.query(query, commandPayloads);
391
556
  const [bw, payloads, errors] = response;
392
557
  (_d = this.logger) == null ? void 0 : _d.debug(`Replying to command ${commandHash} addressed to module: ${localModuleName}`);
393
558
  const insertResult = await responseArchivist.insert([
@@ -395,11 +560,11 @@ var _AsyncQueryBusServer = class _AsyncQueryBusServer extends AsyncQueryBusBase
395
560
  ...payloads,
396
561
  ...errors
397
562
  ]);
398
- if (insertResult.length > 0) {
563
+ if (insertResult.length === 0) {
399
564
  (_e = this.logger) == null ? void 0 : _e.error(`Error replying to command ${commandHash} addressed to module: ${localModuleName}`);
400
565
  }
401
- if (command == null ? void 0 : command.timestamp) {
402
- await this.commitState(localModule.address, command.timestamp);
566
+ if (query == null ? void 0 : query.timestamp) {
567
+ await this.commitState(localModule.address, query.timestamp);
403
568
  }
404
569
  } catch (error) {
405
570
  (_f = this.logger) == null ? void 0 : _f.error(`Error processing command ${commandHash} for module ${localModuleName}: ${error}`);
@@ -412,13 +577,13 @@ var _AsyncQueryBusServer = class _AsyncQueryBusServer extends AsyncQueryBusBase
412
577
  * Finds unprocessed commands addressed to the supplied address
413
578
  * @param address The address to find commands for
414
579
  */
415
- findCommandsToAddress = async (address) => {
580
+ findQueriesToAddress = async (address) => {
416
581
  const queryBoundWitnessDiviner = await this.queriesDiviner();
417
582
  const timestamp = await this.retrieveState(address);
418
583
  const destination = [
419
584
  address
420
585
  ];
421
- const limit = this.individualAddressBatchQueryLimitConfig;
586
+ const limit = this.perAddressBatchQueryLimit;
422
587
  const divinerQuery = {
423
588
  destination,
424
589
  limit,
@@ -429,10 +594,10 @@ var _AsyncQueryBusServer = class _AsyncQueryBusServer extends AsyncQueryBusBase
429
594
  const result = await queryBoundWitnessDiviner.divine([
430
595
  divinerQuery
431
596
  ]);
432
- const commands = result.filter(import_boundwitness_model2.isQueryBoundWitnessWithMeta);
433
- const nextState = Math.max(...commands.map((c) => c.timestamp ?? 0));
597
+ const queries = result.filter(import_boundwitness_model2.isQueryBoundWitnessWithMeta);
598
+ const nextState = queries.length > 0 ? Math.max(...queries.map((c) => c.timestamp ?? 0)) + 1 : timestamp;
434
599
  await this.commitState(address, nextState);
435
- return commands;
600
+ return queries;
436
601
  };
437
602
  /**
438
603
  * Runs the background divine process on a loop with a delay
@@ -465,12 +630,12 @@ var _AsyncQueryBusServer = class _AsyncQueryBusServer extends AsyncQueryBusBase
465
630
  try {
466
631
  const localModuleName = localModule.config.name ?? localModule.address;
467
632
  (_a2 = this.logger) == null ? void 0 : _a2.debug(`Checking for inbound commands to ${localModuleName}`);
468
- const commands = await this.findCommandsToAddress(localModule.address);
469
- if (commands.length === 0)
633
+ const queries = await this.findQueriesToAddress(localModule.address);
634
+ if (queries.length === 0)
470
635
  return;
471
636
  (_b = this.logger) == null ? void 0 : _b.debug(`Found commands addressed to local module: ${localModuleName}`);
472
- for (const command of commands) {
473
- await this.callLocalModule(localModule, command);
637
+ for (const query of queries) {
638
+ await this.callLocalModule(localModule, query);
474
639
  }
475
640
  } catch (error) {
476
641
  (_c = this.logger) == null ? void 0 : _c.error(`Error processing commands for address ${localModule.address}: ${error}`);
@@ -478,8 +643,53 @@ var _AsyncQueryBusServer = class _AsyncQueryBusServer extends AsyncQueryBusBase
478
643
  }));
479
644
  };
480
645
  };
481
- __name(_AsyncQueryBusServer, "AsyncQueryBusServer");
482
- var AsyncQueryBusServer = _AsyncQueryBusServer;
646
+ __name(_AsyncQueryBusHost, "AsyncQueryBusHost");
647
+ var AsyncQueryBusHost = _AsyncQueryBusHost;
648
+
649
+ // src/AbstractModuleHost/AbstractModuleHost.ts
650
+ var import_object3 = require("@xylabs/object");
651
+ var _AbstractModuleHost = class _AbstractModuleHost extends import_object3.Base {
652
+ };
653
+ __name(_AbstractModuleHost, "AbstractModuleHost");
654
+ var AbstractModuleHost = _AbstractModuleHost;
655
+
656
+ // src/AsyncQueryBus/ModuleHost/ModuleHost.ts
657
+ var _AsyncQueryBusModuleHost = class _AsyncQueryBusModuleHost extends AbstractModuleHost {
658
+ _busHost;
659
+ constructor(params) {
660
+ super(params);
661
+ }
662
+ async start() {
663
+ var _a;
664
+ const listeningModules = this.params.config.listeningModules ?? (await this.params.module.resolve(void 0, {
665
+ direction: "down"
666
+ })).map((m) => m.address);
667
+ this._busHost = new AsyncQueryBusHost({
668
+ config: {
669
+ ...this.params.config,
670
+ listeningModules
671
+ },
672
+ logger: this.params.logger,
673
+ resolver: this.params.module
674
+ });
675
+ (_a = this._busHost) == null ? void 0 : _a.start();
676
+ }
677
+ stop() {
678
+ var _a;
679
+ (_a = this._busHost) == null ? void 0 : _a.stop();
680
+ }
681
+ };
682
+ __name(_AsyncQueryBusModuleHost, "AsyncQueryBusModuleHost");
683
+ var AsyncQueryBusModuleHost = _AsyncQueryBusModuleHost;
684
+
685
+ // src/AsyncQueryBus/ModuleProxy/ModuleProxy.ts
686
+ var _AsyncQueryBusModuleProxy = class _AsyncQueryBusModuleProxy extends AbstractModuleProxy {
687
+ async query(query, payloads) {
688
+ return await this.proxyParams.bridgeClient.send(this.address, query, payloads);
689
+ }
690
+ };
691
+ __name(_AsyncQueryBusModuleProxy, "AsyncQueryBusModuleProxy");
692
+ var AsyncQueryBusModuleProxy = _AsyncQueryBusModuleProxy;
483
693
 
484
694
  // src/Schema.ts
485
695
  var PubSubBridgeSchema = "network.xyo.bridge.pubsub";
@@ -492,8 +702,8 @@ var import_assert4 = require("@xylabs/assert");
492
702
  var import_abstract_bridge = require("@xyo-network/abstract-bridge");
493
703
  var import_manifest_model = require("@xyo-network/manifest-model");
494
704
  var import_module_model3 = require("@xyo-network/module-model");
495
- var import_payload_model = require("@xyo-network/payload-model");
496
- var import_lru_cache2 = require("lru-cache");
705
+ var import_payload_model2 = require("@xyo-network/payload-model");
706
+ var import_lru_cache3 = require("lru-cache");
497
707
  function _ts_decorate(decorators, target, key, desc) {
498
708
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
499
709
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -515,10 +725,10 @@ var _PubSubBridge = class _PubSubBridge extends import_abstract_bridge.AbstractB
515
725
  _targetConfigs = {};
516
726
  _targetQueries = {};
517
727
  _busClient;
518
- _busServer;
728
+ _busHost;
519
729
  get discoverCache() {
520
730
  const config = this.discoverCacheConfig;
521
- this._discoverCache = this._discoverCache ?? new import_lru_cache2.LRUCache({
731
+ this._discoverCache = this._discoverCache ?? new import_lru_cache3.LRUCache({
522
732
  ttlAutopurge: true,
523
733
  ...config
524
734
  });
@@ -580,7 +790,7 @@ var _PubSubBridge = class _PubSubBridge extends import_abstract_bridge.AbstractB
580
790
  };
581
791
  const boundQuery = await this.bindQuery(queryPayload);
582
792
  const manifest = (0, import_assert4.assertEx)(await this.targetQuery(addressToCall, boundQuery[0], boundQuery[1]), () => `Unable to resolve [${address}]`)[1];
583
- return (0, import_assert4.assertEx)(manifest.find((0, import_payload_model.isPayloadOfSchemaType)(import_manifest_model.ModuleManifestPayloadSchema)), "Did not receive manifest");
793
+ return (0, import_assert4.assertEx)(manifest.find((0, import_payload_model2.isPayloadOfSchemaType)(import_manifest_model.ModuleManifestPayloadSchema)), "Did not receive manifest");
584
794
  }
585
795
  targetQueries(address) {
586
796
  if (!this.connected)
@@ -600,32 +810,30 @@ var _PubSubBridge = class _PubSubBridge extends import_abstract_bridge.AbstractB
600
810
  busClient() {
601
811
  if (!this._busClient) {
602
812
  this._busClient = new AsyncQueryBusClient({
603
- config: this.config,
813
+ config: this.config.client,
604
814
  logger: this.logger,
605
815
  resolver: this
606
816
  });
607
817
  }
608
818
  return this._busClient;
609
819
  }
610
- busServer() {
611
- if (!this._busServer) {
612
- this._busServer = new AsyncQueryBusServer({
613
- config: this.config,
820
+ busHost() {
821
+ if (!this._busHost) {
822
+ this._busHost = new AsyncQueryBusHost({
823
+ config: this.config.host,
614
824
  logger: this.logger,
615
825
  resolver: this
616
826
  });
617
827
  }
618
- return this._busServer;
828
+ return this._busHost;
619
829
  }
620
830
  async startHandler() {
621
831
  await Promise.resolve(this.connect());
622
- this.busServer().start();
623
- this.busClient().start();
832
+ this.busHost().start();
624
833
  return true;
625
834
  }
626
835
  stopHandler(_timeout) {
627
- this.busClient().stop();
628
- this.busServer().stop();
836
+ this.busHost().stop();
629
837
  return true;
630
838
  }
631
839
  };
@@ -639,8 +847,11 @@ PubSubBridge = _ts_decorate([
639
847
  ], PubSubBridge);
640
848
  // Annotate the CommonJS export names for ESM import in node:
641
849
  0 && (module.exports = {
850
+ AbstractModuleProxy,
642
851
  AsyncQueryBusClient,
643
- AsyncQueryBusServer,
852
+ AsyncQueryBusHost,
853
+ AsyncQueryBusModuleHost,
854
+ AsyncQueryBusModuleProxy,
644
855
  Pending,
645
856
  PubSubBridge,
646
857
  PubSubBridgeConfigSchema,