@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
@@ -6,25 +6,181 @@ var __publicField = (obj, key, value) => {
6
6
  return value;
7
7
  };
8
8
 
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;
166
+
9
167
  // src/AsyncQueryBus/AsyncQueryBusClient.ts
10
- import { assertEx as assertEx2 } from "@xylabs/assert";
11
168
  import { delay } from "@xylabs/delay";
12
169
  import { forget } from "@xylabs/forget";
13
170
  import { clearTimeoutEx, setTimeoutEx } from "@xylabs/timer";
14
171
  import { isBoundWitnessWithMeta } from "@xyo-network/boundwitness-model";
15
172
  import { BoundWitnessDivinerQuerySchema } from "@xyo-network/diviner-boundwitness-model";
16
- import { asModuleInstance } from "@xyo-network/module-model";
17
173
  import { PayloadBuilder } from "@xyo-network/payload-builder";
174
+ import { LRUCache as LRUCache2 } from "lru-cache";
18
175
 
19
176
  // src/AsyncQueryBus/AsyncQueryBusBase.ts
20
- import { assertEx } from "@xylabs/assert";
21
- import { Base } from "@xylabs/object";
177
+ import { assertEx as assertEx2 } from "@xylabs/assert";
178
+ import { Base as Base2 } from "@xylabs/object";
22
179
  import { asArchivistInstance } from "@xyo-network/archivist-model";
23
180
  import { asDivinerInstance } from "@xyo-network/diviner-model";
24
181
  import { LRUCache } from "lru-cache";
25
- var _AsyncQueryBusBase = class _AsyncQueryBusBase extends Base {
182
+ var _AsyncQueryBusBase = class _AsyncQueryBusBase extends Base2 {
26
183
  _lastState;
27
- _queryCache;
28
184
  _targetConfigs = {};
29
185
  _targetQueries = {};
30
186
  constructor(params) {
@@ -33,19 +189,9 @@ var _AsyncQueryBusBase = class _AsyncQueryBusBase extends Base {
33
189
  get config() {
34
190
  return this.params.config;
35
191
  }
36
- get individualAddressBatchQueryLimitConfig() {
37
- return this.config.individualAddressBatchQueryLimit ?? 10;
38
- }
39
192
  get pollFrequencyConfig() {
40
- return this.config.pollFrequency ?? 1e3;
41
- }
42
- get queryCacheConfig() {
43
- const queryCacheConfig = this.config.queryCache === true ? {} : this.config.queryCache;
44
- return {
45
- max: 100,
46
- ttl: 1e3 * 60,
47
- ...queryCacheConfig
48
- };
193
+ var _a;
194
+ return ((_a = this.config) == null ? void 0 : _a.pollFrequency) ?? 1e3;
49
195
  }
50
196
  get resolver() {
51
197
  return this.params.resolver;
@@ -61,47 +207,32 @@ var _AsyncQueryBusBase = class _AsyncQueryBusBase extends Base {
61
207
  this._lastState = this._lastState ?? new LRUCache(requiredConfig);
62
208
  return this._lastState;
63
209
  }
64
- /**
65
- * A cache of queries that have been issued
66
- */
67
- get queryCache() {
68
- const config = this.queryCacheConfig;
69
- const requiredConfig = {
70
- noUpdateTTL: false,
71
- ttlAutopurge: true
72
- };
73
- this._queryCache = this._queryCache ?? new LRUCache({
74
- ...config,
75
- ...requiredConfig
76
- });
77
- return this._queryCache;
78
- }
79
210
  async queriesArchivist() {
80
- var _a;
81
- return assertEx(asArchivistInstance(await this.resolver.resolve((_a = this.config.queries) == null ? void 0 : _a.archivist)), () => {
82
- var _a2;
83
- 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}]`;
84
215
  });
85
216
  }
86
217
  async queriesDiviner() {
87
- var _a;
88
- return assertEx(asDivinerInstance(await this.resolver.resolve((_a = this.config.queries) == null ? void 0 : _a.boundWitnessDiviner)), () => {
89
- var _a2;
90
- 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}]`;
91
222
  });
92
223
  }
93
224
  async responsesArchivist() {
94
- var _a;
95
- return assertEx(asArchivistInstance(await this.resolver.resolve((_a = this.config.responses) == null ? void 0 : _a.archivist)), () => {
96
- var _a2;
97
- 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}]`;
98
229
  });
99
230
  }
100
231
  async responsesDiviner() {
101
- var _a;
102
- return assertEx(asDivinerInstance(await this.resolver.resolve((_a = this.config.responses) == null ? void 0 : _a.boundWitnessDiviner)), () => {
103
- var _a2;
104
- 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}]`;
105
236
  });
106
237
  }
107
238
  /**
@@ -143,21 +274,45 @@ var Pending = "pending";
143
274
 
144
275
  // src/AsyncQueryBus/AsyncQueryBusClient.ts
145
276
  var _AsyncQueryBusClient = class _AsyncQueryBusClient extends AsyncQueryBusBase {
277
+ _queryCache;
278
+ _pollCount = 0;
146
279
  _pollId;
147
280
  constructor(params) {
148
281
  super(params);
149
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
+ }
150
292
  get started() {
151
293
  return !!this._pollId;
152
294
  }
153
- async listeningModules() {
154
- 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({
155
- 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
156
307
  });
157
- return mods;
308
+ return this._queryCache;
309
+ }
310
+ listeningAddresses() {
311
+ var _a;
312
+ return (_a = this._queryCache) == null ? void 0 : _a.keys();
158
313
  }
159
314
  async send(address, query, payloads) {
160
- var _a, _b, _c, _d, _e, _f;
315
+ var _a, _b, _c, _d;
161
316
  (_a = this.logger) == null ? void 0 : _a.debug(`Begin issuing query to: ${address}`);
162
317
  const $meta = {
163
318
  ...query == null ? void 0 : query.$meta,
@@ -170,10 +325,6 @@ var _AsyncQueryBusClient = class _AsyncQueryBusClient extends AsyncQueryBusBase
170
325
  $meta
171
326
  });
172
327
  const queryArchivist = await this.queriesArchivist();
173
- const sourceAddress = query.addresses.at(0);
174
- if (sourceAddress && !((_b = this.config.listeningModules) == null ? void 0 : _b.includes(sourceAddress))) {
175
- (_c = this.config.listeningModules) == null ? void 0 : _c.push(sourceAddress);
176
- }
177
328
  const routedQueryHash = (
178
329
  // Trust the signed hash if it's there
179
330
  (routedQuery == null ? void 0 : routedQuery.$hash) ?? // TODO: What is the right way to find the dataHash
@@ -181,15 +332,15 @@ var _AsyncQueryBusClient = class _AsyncQueryBusClient extends AsyncQueryBusBase
181
332
  routedQuery
182
333
  ]))[0]
183
334
  );
184
- (_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}`);
185
336
  const data = payloads ? [
186
337
  routedQuery,
187
338
  ...payloads
188
339
  ] : [
189
340
  routedQuery
190
341
  ];
191
- const insertResult = await ((_e = queryArchivist.insert) == null ? void 0 : _e.call(queryArchivist, data));
192
- (_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}`);
193
344
  this.queryCache.set(routedQueryHash, Pending);
194
345
  if (!insertResult)
195
346
  throw new Error("Unable to issue query to queryArchivist");
@@ -198,52 +349,43 @@ var _AsyncQueryBusClient = class _AsyncQueryBusClient extends AsyncQueryBusBase
198
349
  (_a2 = this.logger) == null ? void 0 : _a2.debug(`Polling for response to query: ${routedQueryHash}`);
199
350
  const pollForResponse = /* @__PURE__ */ __name(async () => {
200
351
  var _a3, _b2;
201
- let response = this.queryCache.get(routedQueryHash);
202
- while (response !== void 0) {
203
- await delay(100);
204
- response = this.queryCache.get(routedQueryHash);
205
- if (response && response !== Pending) {
206
- (_a3 = this.logger) == null ? void 0 : _a3.debug(`Returning response to query: ${routedQueryHash}`);
207
- resolve(response);
208
- 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
+ }
209
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();
210
383
  }
211
- (_b2 = this.logger) == null ? void 0 : _b2.error("Timeout waiting for query response");
212
- const error = {
213
- message: "Timeout waiting for query response",
214
- query: "network.xyo.boundwitness",
215
- schema: "network.xyo.error.module",
216
- sources: [
217
- routedQueryHash
218
- ]
219
- };
220
- resolve([
221
- routedQuery,
222
- [],
223
- [
224
- await PayloadBuilder.build(error)
225
- ]
226
- ]);
227
- return;
228
384
  }, "pollForResponse");
229
385
  forget(pollForResponse());
230
386
  });
231
387
  return context;
232
388
  }
233
- start() {
234
- if (this.started) {
235
- console.warn("AsyncQueryBus starting when already started");
236
- }
237
- this.poll();
238
- }
239
- stop() {
240
- if (!this.started) {
241
- console.warn("AsyncQueryBus stopping when already stopped");
242
- }
243
- if (this._pollId)
244
- clearTimeoutEx(this._pollId);
245
- this._pollId = void 0;
246
- }
247
389
  /**
248
390
  * Runs the background divine process on a loop with a delay
249
391
  * specified by the `config.pollFrequency`
@@ -297,29 +439,49 @@ var _AsyncQueryBusClient = class _AsyncQueryBusClient extends AsyncQueryBusBase
297
439
  }
298
440
  }));
299
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
+ }
300
457
  };
301
458
  __name(_AsyncQueryBusClient, "AsyncQueryBusClient");
302
459
  var AsyncQueryBusClient = _AsyncQueryBusClient;
303
460
 
304
- // src/AsyncQueryBus/AsyncQueryBusServer.ts
461
+ // src/AsyncQueryBus/AsyncQueryBusHost.ts
305
462
  import { containsAll } from "@xylabs/array";
306
463
  import { assertEx as assertEx3 } from "@xylabs/assert";
307
464
  import { clearTimeoutEx as clearTimeoutEx2, setTimeoutEx as setTimeoutEx2 } from "@xylabs/timer";
308
465
  import { isQueryBoundWitnessWithMeta } from "@xyo-network/boundwitness-model";
309
466
  import { BoundWitnessDivinerQuerySchema as BoundWitnessDivinerQuerySchema2 } from "@xyo-network/diviner-boundwitness-model";
310
- import { asModuleInstance as asModuleInstance2 } from "@xyo-network/module-model";
467
+ import { asModuleInstance } from "@xyo-network/module-model";
311
468
  import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/payload-builder";
312
- var _AsyncQueryBusServer = class _AsyncQueryBusServer extends AsyncQueryBusBase {
469
+ var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
313
470
  _pollId;
314
471
  constructor(params) {
315
472
  super(params);
316
473
  }
474
+ get perAddressBatchQueryLimit() {
475
+ var _a;
476
+ return ((_a = this.config) == null ? void 0 : _a.perAddressBatchQueryLimit) ?? 10;
477
+ }
317
478
  get started() {
318
479
  return !!this._pollId;
319
480
  }
320
481
  async listeningModules() {
321
- 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({
322
- 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"
323
485
  });
324
486
  return mods;
325
487
  }
@@ -337,28 +499,28 @@ var _AsyncQueryBusServer = class _AsyncQueryBusServer extends AsyncQueryBusBase
337
499
  clearTimeoutEx2(this._pollId);
338
500
  this._pollId = void 0;
339
501
  }
340
- callLocalModule = async (localModule, command) => {
502
+ callLocalModule = async (localModule, query) => {
341
503
  var _a, _b, _c, _d, _e, _f;
342
504
  const localModuleName = localModule.config.name ?? localModule.address;
343
505
  const queryArchivist = await this.queriesArchivist();
344
506
  const responseArchivist = await this.responsesArchivist();
345
- const commandDestination = (_a = command.$meta) == null ? void 0 : _a.destination;
507
+ const commandDestination = (_a = query.$meta) == null ? void 0 : _a.destination;
346
508
  if (commandDestination && (commandDestination == null ? void 0 : commandDestination.includes(localModule.address))) {
347
- const queryIndex = command.payload_hashes.indexOf(command.query);
509
+ const queryIndex = query.payload_hashes.indexOf(query.query);
348
510
  if (queryIndex !== -1) {
349
- const querySchema = command.payload_schemas[queryIndex];
511
+ const querySchema = query.payload_schemas[queryIndex];
350
512
  if (localModule.queries.includes(querySchema)) {
351
- const commandPayloads = await queryArchivist.get(command.payload_hashes);
513
+ const commandPayloads = await queryArchivist.get(query.payload_hashes);
352
514
  const commandPayloadsDict = await PayloadBuilder2.toAllHashMap(commandPayloads);
353
- const commandHash = (await PayloadBuilder2.build(command)).$hash;
354
- 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)) {
355
517
  (_b = this.logger) == null ? void 0 : _b.error(`Error processing command ${commandHash} for module ${localModuleName}, missing payloads`);
356
518
  return;
357
519
  }
358
520
  try {
359
- const commandSchema = commandPayloadsDict[command.query].schema;
521
+ const commandSchema = commandPayloadsDict[query.query].schema;
360
522
  (_c = this.logger) == null ? void 0 : _c.debug(`Issuing command ${commandSchema} (${commandHash}) addressed to module: ${localModuleName}`);
361
- const response = await localModule.query(command, commandPayloads);
523
+ const response = await localModule.query(query, commandPayloads);
362
524
  const [bw, payloads, errors] = response;
363
525
  (_d = this.logger) == null ? void 0 : _d.debug(`Replying to command ${commandHash} addressed to module: ${localModuleName}`);
364
526
  const insertResult = await responseArchivist.insert([
@@ -366,11 +528,11 @@ var _AsyncQueryBusServer = class _AsyncQueryBusServer extends AsyncQueryBusBase
366
528
  ...payloads,
367
529
  ...errors
368
530
  ]);
369
- if (insertResult.length > 0) {
531
+ if (insertResult.length === 0) {
370
532
  (_e = this.logger) == null ? void 0 : _e.error(`Error replying to command ${commandHash} addressed to module: ${localModuleName}`);
371
533
  }
372
- if (command == null ? void 0 : command.timestamp) {
373
- await this.commitState(localModule.address, command.timestamp);
534
+ if (query == null ? void 0 : query.timestamp) {
535
+ await this.commitState(localModule.address, query.timestamp);
374
536
  }
375
537
  } catch (error) {
376
538
  (_f = this.logger) == null ? void 0 : _f.error(`Error processing command ${commandHash} for module ${localModuleName}: ${error}`);
@@ -383,13 +545,13 @@ var _AsyncQueryBusServer = class _AsyncQueryBusServer extends AsyncQueryBusBase
383
545
  * Finds unprocessed commands addressed to the supplied address
384
546
  * @param address The address to find commands for
385
547
  */
386
- findCommandsToAddress = async (address) => {
548
+ findQueriesToAddress = async (address) => {
387
549
  const queryBoundWitnessDiviner = await this.queriesDiviner();
388
550
  const timestamp = await this.retrieveState(address);
389
551
  const destination = [
390
552
  address
391
553
  ];
392
- const limit = this.individualAddressBatchQueryLimitConfig;
554
+ const limit = this.perAddressBatchQueryLimit;
393
555
  const divinerQuery = {
394
556
  destination,
395
557
  limit,
@@ -400,10 +562,10 @@ var _AsyncQueryBusServer = class _AsyncQueryBusServer extends AsyncQueryBusBase
400
562
  const result = await queryBoundWitnessDiviner.divine([
401
563
  divinerQuery
402
564
  ]);
403
- const commands = result.filter(isQueryBoundWitnessWithMeta);
404
- 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;
405
567
  await this.commitState(address, nextState);
406
- return commands;
568
+ return queries;
407
569
  };
408
570
  /**
409
571
  * Runs the background divine process on a loop with a delay
@@ -436,12 +598,12 @@ var _AsyncQueryBusServer = class _AsyncQueryBusServer extends AsyncQueryBusBase
436
598
  try {
437
599
  const localModuleName = localModule.config.name ?? localModule.address;
438
600
  (_a2 = this.logger) == null ? void 0 : _a2.debug(`Checking for inbound commands to ${localModuleName}`);
439
- const commands = await this.findCommandsToAddress(localModule.address);
440
- if (commands.length === 0)
601
+ const queries = await this.findQueriesToAddress(localModule.address);
602
+ if (queries.length === 0)
441
603
  return;
442
604
  (_b = this.logger) == null ? void 0 : _b.debug(`Found commands addressed to local module: ${localModuleName}`);
443
- for (const command of commands) {
444
- await this.callLocalModule(localModule, command);
605
+ for (const query of queries) {
606
+ await this.callLocalModule(localModule, query);
445
607
  }
446
608
  } catch (error) {
447
609
  (_c = this.logger) == null ? void 0 : _c.error(`Error processing commands for address ${localModule.address}: ${error}`);
@@ -449,8 +611,53 @@ var _AsyncQueryBusServer = class _AsyncQueryBusServer extends AsyncQueryBusBase
449
611
  }));
450
612
  };
451
613
  };
452
- __name(_AsyncQueryBusServer, "AsyncQueryBusServer");
453
- 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;
454
661
 
455
662
  // src/Schema.ts
456
663
  var PubSubBridgeSchema = "network.xyo.bridge.pubsub";
@@ -462,9 +669,9 @@ var PubSubBridgeConfigSchema = `${PubSubBridgeSchema}.config`;
462
669
  import { assertEx as assertEx4 } from "@xylabs/assert";
463
670
  import { AbstractBridge } from "@xyo-network/abstract-bridge";
464
671
  import { ModuleManifestPayloadSchema } from "@xyo-network/manifest-model";
465
- import { creatableModule, ModuleManifestQuerySchema } from "@xyo-network/module-model";
672
+ import { creatableModule, ModuleManifestQuerySchema as ModuleManifestQuerySchema2 } from "@xyo-network/module-model";
466
673
  import { isPayloadOfSchemaType } from "@xyo-network/payload-model";
467
- import { LRUCache as LRUCache2 } from "lru-cache";
674
+ import { LRUCache as LRUCache3 } from "lru-cache";
468
675
  function _ts_decorate(decorators, target, key, desc) {
469
676
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
470
677
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -486,10 +693,10 @@ var _PubSubBridge = class _PubSubBridge extends AbstractBridge {
486
693
  _targetConfigs = {};
487
694
  _targetQueries = {};
488
695
  _busClient;
489
- _busServer;
696
+ _busHost;
490
697
  get discoverCache() {
491
698
  const config = this.discoverCacheConfig;
492
- this._discoverCache = this._discoverCache ?? new LRUCache2({
699
+ this._discoverCache = this._discoverCache ?? new LRUCache3({
493
700
  ttlAutopurge: true,
494
701
  ...config
495
702
  });
@@ -547,7 +754,7 @@ var _PubSubBridge = class _PubSubBridge extends AbstractBridge {
547
754
  const addressToCall = address ?? this.getRootAddress();
548
755
  const queryPayload = {
549
756
  maxDepth,
550
- schema: ModuleManifestQuerySchema
757
+ schema: ModuleManifestQuerySchema2
551
758
  };
552
759
  const boundQuery = await this.bindQuery(queryPayload);
553
760
  const manifest = assertEx4(await this.targetQuery(addressToCall, boundQuery[0], boundQuery[1]), () => `Unable to resolve [${address}]`)[1];
@@ -571,32 +778,30 @@ var _PubSubBridge = class _PubSubBridge extends AbstractBridge {
571
778
  busClient() {
572
779
  if (!this._busClient) {
573
780
  this._busClient = new AsyncQueryBusClient({
574
- config: this.config,
781
+ config: this.config.client,
575
782
  logger: this.logger,
576
783
  resolver: this
577
784
  });
578
785
  }
579
786
  return this._busClient;
580
787
  }
581
- busServer() {
582
- if (!this._busServer) {
583
- this._busServer = new AsyncQueryBusServer({
584
- config: this.config,
788
+ busHost() {
789
+ if (!this._busHost) {
790
+ this._busHost = new AsyncQueryBusHost({
791
+ config: this.config.host,
585
792
  logger: this.logger,
586
793
  resolver: this
587
794
  });
588
795
  }
589
- return this._busServer;
796
+ return this._busHost;
590
797
  }
591
798
  async startHandler() {
592
799
  await Promise.resolve(this.connect());
593
- this.busServer().start();
594
- this.busClient().start();
800
+ this.busHost().start();
595
801
  return true;
596
802
  }
597
803
  stopHandler(_timeout) {
598
- this.busClient().stop();
599
- this.busServer().stop();
804
+ this.busHost().stop();
600
805
  return true;
601
806
  }
602
807
  };
@@ -609,8 +814,11 @@ PubSubBridge = _ts_decorate([
609
814
  creatableModule()
610
815
  ], PubSubBridge);
611
816
  export {
817
+ AbstractModuleProxy,
612
818
  AsyncQueryBusClient,
613
- AsyncQueryBusServer,
819
+ AsyncQueryBusHost,
820
+ AsyncQueryBusModuleHost,
821
+ AsyncQueryBusModuleProxy,
614
822
  Pending,
615
823
  PubSubBridge,
616
824
  PubSubBridgeConfigSchema,