@xyo-network/bridge-pub-sub 2.94.11 → 2.94.13

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 (55) hide show
  1. package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.cts +66 -6
  2. package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.cts.map +1 -1
  3. package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.mts +66 -6
  4. package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.mts.map +1 -1
  5. package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.ts +66 -6
  6. package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.ts.map +1 -1
  7. package/dist/browser/AsyncQueryBus/AsyncQueryBusClient.d.cts.map +1 -1
  8. package/dist/browser/AsyncQueryBus/AsyncQueryBusClient.d.mts.map +1 -1
  9. package/dist/browser/AsyncQueryBus/AsyncQueryBusClient.d.ts.map +1 -1
  10. package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.cts +1 -1
  11. package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.cts.map +1 -1
  12. package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.mts +1 -1
  13. package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.mts.map +1 -1
  14. package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.ts +1 -1
  15. package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.ts.map +1 -1
  16. package/dist/browser/PubSubBridgeModuleResolver.d.cts +3 -3
  17. package/dist/browser/PubSubBridgeModuleResolver.d.cts.map +1 -1
  18. package/dist/browser/PubSubBridgeModuleResolver.d.mts +3 -3
  19. package/dist/browser/PubSubBridgeModuleResolver.d.mts.map +1 -1
  20. package/dist/browser/PubSubBridgeModuleResolver.d.ts +3 -3
  21. package/dist/browser/PubSubBridgeModuleResolver.d.ts.map +1 -1
  22. package/dist/browser/index.cjs +135 -93
  23. package/dist/browser/index.cjs.map +1 -1
  24. package/dist/browser/index.js +135 -93
  25. package/dist/browser/index.js.map +1 -1
  26. package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.cts +66 -6
  27. package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.cts.map +1 -1
  28. package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.mts +66 -6
  29. package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.mts.map +1 -1
  30. package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.ts +66 -6
  31. package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.ts.map +1 -1
  32. package/dist/node/AsyncQueryBus/AsyncQueryBusClient.d.cts.map +1 -1
  33. package/dist/node/AsyncQueryBus/AsyncQueryBusClient.d.mts.map +1 -1
  34. package/dist/node/AsyncQueryBus/AsyncQueryBusClient.d.ts.map +1 -1
  35. package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.cts +1 -1
  36. package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.cts.map +1 -1
  37. package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.mts +1 -1
  38. package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.mts.map +1 -1
  39. package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.ts +1 -1
  40. package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.ts.map +1 -1
  41. package/dist/node/PubSubBridgeModuleResolver.d.cts +3 -3
  42. package/dist/node/PubSubBridgeModuleResolver.d.cts.map +1 -1
  43. package/dist/node/PubSubBridgeModuleResolver.d.mts +3 -3
  44. package/dist/node/PubSubBridgeModuleResolver.d.mts.map +1 -1
  45. package/dist/node/PubSubBridgeModuleResolver.d.ts +3 -3
  46. package/dist/node/PubSubBridgeModuleResolver.d.ts.map +1 -1
  47. package/dist/node/index.cjs +141 -122
  48. package/dist/node/index.cjs.map +1 -1
  49. package/dist/node/index.js +141 -122
  50. package/dist/node/index.js.map +1 -1
  51. package/package.json +18 -17
  52. package/src/AsyncQueryBus/AsyncQueryBusBase.ts +69 -40
  53. package/src/AsyncQueryBus/AsyncQueryBusClient.ts +24 -26
  54. package/src/AsyncQueryBus/AsyncQueryBusHost.ts +20 -19
  55. package/src/PubSubBridgeModuleResolver.ts +5 -5
@@ -14,7 +14,7 @@ __name(_AbstractModuleHost, "AbstractModuleHost");
14
14
  var AbstractModuleHost = _AbstractModuleHost;
15
15
 
16
16
  // src/AsyncQueryBus/AsyncQueryBusClient.ts
17
- import { assertEx as assertEx2 } from "@xylabs/assert";
17
+ import { assertEx } from "@xylabs/assert";
18
18
  import { delay } from "@xylabs/delay";
19
19
  import { forget } from "@xylabs/forget";
20
20
  import { clearTimeoutEx, setTimeoutEx } from "@xylabs/timer";
@@ -24,7 +24,6 @@ import { PayloadBuilder } from "@xyo-network/payload-builder";
24
24
  import { LRUCache as LRUCache2 } from "lru-cache";
25
25
 
26
26
  // src/AsyncQueryBus/AsyncQueryBusBase.ts
27
- import { assertEx } from "@xylabs/assert";
28
27
  import { Base as Base2, toJsonString } from "@xylabs/object";
29
28
  import { asArchivistInstance } from "@xyo-network/archivist-model";
30
29
  import { asDivinerInstance } from "@xyo-network/diviner-model";
@@ -35,13 +34,13 @@ var _AsyncQueryBusBase = class _AsyncQueryBusBase extends Base2 {
35
34
  _targetQueries = {};
36
35
  _lastQueriesArchivistAttempt;
37
36
  _lastQueriesDivinerAttempt;
38
- _lastResponseArchivistAttempt;
39
- _lastResponseDivinerAttempt;
37
+ _lastResponsesArchivistAttempt;
38
+ _lastResponsesDivinerAttempt;
40
39
  _queriesArchivist;
41
40
  _queriesDiviner;
42
- _reResolveDelay = 5e3;
43
- _responseArchivist;
44
- _responseDiviner;
41
+ _reResolveDelay = 5e4;
42
+ _responsesArchivist;
43
+ _responsesDiviner;
45
44
  constructor(params) {
46
45
  super(params);
47
46
  }
@@ -67,68 +66,88 @@ var _AsyncQueryBusBase = class _AsyncQueryBusBase extends Base2 {
67
66
  return this._lastState;
68
67
  }
69
68
  async queriesArchivist() {
70
- var _a, _b, _c;
69
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
71
70
  if (this._queriesArchivist) {
72
71
  return this._queriesArchivist;
73
72
  }
74
- if (this._lastQueriesArchivistAttempt && Date.now() - this._lastQueriesArchivistAttempt < this._reResolveDelay) {
73
+ if (Date.now() - (this._lastQueriesArchivistAttempt ?? 0) < this._reResolveDelay) {
75
74
  return;
76
75
  }
77
- const resolved = await this.resolver.resolve((_c = (_b = (_a = this.config) == null ? void 0 : _a.intersect) == null ? void 0 : _b.queries) == null ? void 0 : _c.archivist, {
78
- direction: "up"
79
- });
80
- const existingResolved = assertEx(resolved, () => {
81
- var _a2, _b2, _c2;
82
- return `Unable to resolve queriesArchivist [${(_c2 = (_b2 = (_a2 = this.config) == null ? void 0 : _a2.intersect) == null ? void 0 : _b2.queries) == null ? void 0 : _c2.archivist}]`;
83
- });
84
- const result = asArchivistInstance(existingResolved, () => {
85
- var _a2, _b2, _c2, _d;
86
- return `Unable to resolve queriesArchivist as correct type [${(_c2 = (_b2 = (_a2 = this.config) == null ? void 0 : _a2.intersect) == null ? void 0 : _b2.queries) == null ? void 0 : _c2.archivist}][${(_d = existingResolved == null ? void 0 : existingResolved.constructor) == null ? void 0 : _d.name}]: ${toJsonString(existingResolved)}`;
87
- });
88
- this._queriesArchivist = result;
89
- return result;
76
+ this._lastQueriesArchivistAttempt = Date.now();
77
+ const resolved = await this.resolver.resolve((_c = (_b = (_a = this.config) == null ? void 0 : _a.intersect) == null ? void 0 : _b.queries) == null ? void 0 : _c.archivist);
78
+ if (resolved) {
79
+ const typedResolve = asArchivistInstance(resolved);
80
+ if (typedResolve) {
81
+ return typedResolve;
82
+ } else {
83
+ (_h = this.logger) == null ? void 0 : _h.warn(`Unable to resolve queriesArchivist as correct type [${(_f = (_e = (_d = this.config) == null ? void 0 : _d.intersect) == null ? void 0 : _e.queries) == null ? void 0 : _f.archivist}][${(_g = resolved == null ? void 0 : resolved.constructor) == null ? void 0 : _g.name}]: ${toJsonString(resolved)}`);
84
+ }
85
+ } else {
86
+ (_l = this.logger) == null ? void 0 : _l.log(`Unable to resolve queriesArchivist [${(_k = (_j = (_i = this.config) == null ? void 0 : _i.intersect) == null ? void 0 : _j.queries) == null ? void 0 : _k.archivist}]`);
87
+ }
90
88
  }
91
89
  async queriesDiviner() {
92
- var _a, _b, _c;
90
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
93
91
  if (this._queriesDiviner) {
94
92
  return this._queriesDiviner;
95
93
  }
96
- if (this._lastQueriesDivinerAttempt && Date.now() - this._lastQueriesDivinerAttempt < this._reResolveDelay) {
94
+ if (Date.now() - (this._lastQueriesDivinerAttempt ?? 0) < this._reResolveDelay) {
97
95
  return;
98
96
  }
99
- this._queriesDiviner = assertEx(asDivinerInstance(await this.resolver.resolve((_c = (_b = (_a = this.config) == null ? void 0 : _a.intersect) == null ? void 0 : _b.queries) == null ? void 0 : _c.boundWitnessDiviner)), () => {
100
- var _a2, _b2, _c2;
101
- return `Unable to resolve queriesDiviner [${(_c2 = (_b2 = (_a2 = this.config) == null ? void 0 : _a2.intersect) == null ? void 0 : _b2.queries) == null ? void 0 : _c2.boundWitnessDiviner}]`;
102
- });
103
- return this._queriesDiviner;
97
+ this._lastQueriesDivinerAttempt = Date.now();
98
+ const resolved = await this.resolver.resolve((_c = (_b = (_a = this.config) == null ? void 0 : _a.intersect) == null ? void 0 : _b.queries) == null ? void 0 : _c.boundWitnessDiviner);
99
+ if (resolved) {
100
+ const typedResolve = asDivinerInstance(resolved);
101
+ if (typedResolve) {
102
+ return typedResolve;
103
+ } else {
104
+ (_h = this.logger) == null ? void 0 : _h.warn(`Unable to resolve queriesDiviner as correct type [${(_f = (_e = (_d = this.config) == null ? void 0 : _d.intersect) == null ? void 0 : _e.queries) == null ? void 0 : _f.boundWitnessDiviner}][${(_g = resolved == null ? void 0 : resolved.constructor) == null ? void 0 : _g.name}]: ${toJsonString(resolved)}`);
105
+ }
106
+ } else {
107
+ (_l = this.logger) == null ? void 0 : _l.log(`Unable to resolve queriesDiviner [${(_k = (_j = (_i = this.config) == null ? void 0 : _i.intersect) == null ? void 0 : _j.queries) == null ? void 0 : _k.boundWitnessDiviner}]`);
108
+ }
104
109
  }
105
110
  async responsesArchivist() {
106
- var _a, _b, _c;
107
- if (this._responseArchivist) {
108
- return this._responseArchivist;
111
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
112
+ if (this._responsesArchivist) {
113
+ return this._responsesArchivist;
109
114
  }
110
- if (this._lastResponseArchivistAttempt && Date.now() - this._lastResponseArchivistAttempt < this._reResolveDelay) {
115
+ if (Date.now() - (this._lastResponsesArchivistAttempt ?? 0) < this._reResolveDelay) {
111
116
  return;
112
117
  }
113
- this._responseArchivist = assertEx(asArchivistInstance(await this.resolver.resolve((_c = (_b = (_a = this.config) == null ? void 0 : _a.intersect) == null ? void 0 : _b.responses) == null ? void 0 : _c.archivist)), () => {
114
- var _a2, _b2, _c2;
115
- return `Unable to resolve responsesArchivist [${(_c2 = (_b2 = (_a2 = this.config) == null ? void 0 : _a2.intersect) == null ? void 0 : _b2.responses) == null ? void 0 : _c2.archivist}]`;
116
- });
117
- return this._responseArchivist;
118
+ this._lastResponsesArchivistAttempt = Date.now();
119
+ const resolved = await this.resolver.resolve((_c = (_b = (_a = this.config) == null ? void 0 : _a.intersect) == null ? void 0 : _b.responses) == null ? void 0 : _c.archivist);
120
+ if (resolved) {
121
+ const typedResolve = asArchivistInstance(resolved);
122
+ if (typedResolve) {
123
+ return typedResolve;
124
+ } else {
125
+ (_h = this.logger) == null ? void 0 : _h.warn(`Unable to resolve responseArchivist as correct type [${(_f = (_e = (_d = this.config) == null ? void 0 : _d.intersect) == null ? void 0 : _e.responses) == null ? void 0 : _f.archivist}][${(_g = resolved == null ? void 0 : resolved.constructor) == null ? void 0 : _g.name}]: ${toJsonString(resolved)}`);
126
+ }
127
+ } else {
128
+ (_l = this.logger) == null ? void 0 : _l.log(`Unable to resolve responseArchivist [${(_k = (_j = (_i = this.config) == null ? void 0 : _i.intersect) == null ? void 0 : _j.responses) == null ? void 0 : _k.archivist}]`);
129
+ }
118
130
  }
119
131
  async responsesDiviner() {
120
- var _a, _b, _c;
121
- if (this._responseDiviner) {
122
- return this._responseDiviner;
132
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
133
+ if (this._responsesDiviner) {
134
+ return this._responsesDiviner;
123
135
  }
124
- if (this._lastResponseDivinerAttempt && Date.now() - this._lastResponseDivinerAttempt < this._reResolveDelay) {
136
+ if (Date.now() - (this._lastResponsesDivinerAttempt ?? 0) < this._reResolveDelay) {
125
137
  return;
126
138
  }
127
- this._responseDiviner = assertEx(asDivinerInstance(await this.resolver.resolve((_c = (_b = (_a = this.config) == null ? void 0 : _a.intersect) == null ? void 0 : _b.responses) == null ? void 0 : _c.boundWitnessDiviner)), () => {
128
- var _a2, _b2, _c2;
129
- return `Unable to resolve responsesDiviner [${(_c2 = (_b2 = (_a2 = this.config) == null ? void 0 : _a2.intersect) == null ? void 0 : _b2.responses) == null ? void 0 : _c2.boundWitnessDiviner}]`;
130
- });
131
- return this._responseDiviner;
139
+ this._lastResponsesDivinerAttempt = Date.now();
140
+ const resolved = await this.resolver.resolve((_c = (_b = (_a = this.config) == null ? void 0 : _a.intersect) == null ? void 0 : _b.responses) == null ? void 0 : _c.boundWitnessDiviner);
141
+ if (resolved) {
142
+ const typedResolve = asDivinerInstance(resolved);
143
+ if (typedResolve) {
144
+ return typedResolve;
145
+ } else {
146
+ (_h = this.logger) == null ? void 0 : _h.warn(`Unable to resolve responsesDiviner as correct type [${(_f = (_e = (_d = this.config) == null ? void 0 : _d.intersect) == null ? void 0 : _e.responses) == null ? void 0 : _f.boundWitnessDiviner}][${(_g = resolved == null ? void 0 : resolved.constructor) == null ? void 0 : _g.name}]: ${toJsonString(resolved)}`);
147
+ }
148
+ } else {
149
+ (_l = this.logger) == null ? void 0 : _l.log(`Unable to resolve responsesDiviner [${(_k = (_j = (_i = this.config) == null ? void 0 : _i.intersect) == null ? void 0 : _j.responses) == null ? void 0 : _k.boundWitnessDiviner}]`);
150
+ }
132
151
  }
133
152
  /**
134
153
  * Commit the internal state of the process. This is similar
@@ -219,7 +238,7 @@ var _AsyncQueryBusClient = class _AsyncQueryBusClient extends AsyncQueryBusBase
219
238
  ...query,
220
239
  $meta
221
240
  });
222
- const queryArchivist = assertEx2(await this.queriesArchivist(), () => {
241
+ const queryArchivist = assertEx(await this.queriesArchivist(), () => {
223
242
  var _a2, _b2, _c2;
224
243
  return `Unable to contact queriesArchivist [${(_c2 = (_b2 = (_a2 = this.config) == null ? void 0 : _a2.intersect) == null ? void 0 : _b2.queries) == null ? void 0 : _c2.archivist}]`;
225
244
  });
@@ -301,41 +320,39 @@ var _AsyncQueryBusClient = class _AsyncQueryBusClient extends AsyncQueryBusBase
301
320
  * Background process for processing incoming responses to previously issued queries
302
321
  */
303
322
  processIncomingResponses = async () => {
304
- const responseArchivist = assertEx2(await this.responsesArchivist(), () => {
305
- var _a, _b, _c;
306
- return `Unable to contact the responsesArchivist [${(_c = (_b = (_a = this.config) == null ? void 0 : _a.intersect) == null ? void 0 : _b.responses) == null ? void 0 : _c.archivist}]`;
307
- });
308
- const responseBoundWitnessDiviner = assertEx2(await this.responsesDiviner(), () => {
309
- var _a, _b, _c;
310
- return `Unable to contact responsesDiviner [${(_c = (_b = (_a = this.config) == null ? void 0 : _a.intersect) == null ? void 0 : _b.responses) == null ? void 0 : _c.boundWitnessDiviner}]`;
311
- });
312
- const pendingCommands = [
313
- ...this.queryCache.entries()
314
- ].filter(([_, status]) => status === Pending);
315
- await Promise.allSettled(pendingCommands.map(async ([sourceQuery, status]) => {
316
- var _a, _b, _c;
317
- if (status === Pending) {
318
- const divinerQuery = {
319
- schema: BoundWitnessDivinerQuerySchema,
320
- sourceQuery
321
- };
322
- const result = await responseBoundWitnessDiviner.divine([
323
- divinerQuery
324
- ]);
325
- if (result && result.length > 0) {
326
- const response = result.find(isBoundWitnessWithMeta);
327
- if (response && ((_a = response == null ? void 0 : response.$meta) == null ? void 0 : _a.sourceQuery) === sourceQuery) {
328
- (_b = this.logger) == null ? void 0 : _b.debug(`Found response to query: ${sourceQuery}`);
329
- const payloads = ((_c = response.payload_hashes) == null ? void 0 : _c.length) > 0 ? await responseArchivist.get(response.payload_hashes) : [];
330
- this.queryCache.set(sourceQuery, [
331
- response,
332
- payloads,
333
- []
323
+ const responseArchivist = await this.responsesArchivist();
324
+ if (responseArchivist) {
325
+ const responseBoundWitnessDiviner = await this.responsesDiviner();
326
+ if (responseBoundWitnessDiviner) {
327
+ const pendingCommands = [
328
+ ...this.queryCache.entries()
329
+ ].filter(([_, status]) => status === Pending);
330
+ await Promise.allSettled(pendingCommands.map(async ([sourceQuery, status]) => {
331
+ var _a, _b, _c;
332
+ if (status === Pending) {
333
+ const divinerQuery = {
334
+ schema: BoundWitnessDivinerQuerySchema,
335
+ sourceQuery
336
+ };
337
+ const result = await responseBoundWitnessDiviner.divine([
338
+ divinerQuery
334
339
  ]);
340
+ if (result && result.length > 0) {
341
+ const response = result.find(isBoundWitnessWithMeta);
342
+ if (response && ((_a = response == null ? void 0 : response.$meta) == null ? void 0 : _a.sourceQuery) === sourceQuery) {
343
+ (_b = this.logger) == null ? void 0 : _b.debug(`Found response to query: ${sourceQuery}`);
344
+ const payloads = ((_c = response.payload_hashes) == null ? void 0 : _c.length) > 0 ? await responseArchivist.get(response.payload_hashes) : [];
345
+ this.queryCache.set(sourceQuery, [
346
+ response,
347
+ payloads,
348
+ []
349
+ ]);
350
+ }
351
+ }
335
352
  }
336
- }
353
+ }));
337
354
  }
338
- }));
355
+ }
339
356
  };
340
357
  start() {
341
358
  if (this._pollCount === 0) {
@@ -358,7 +375,7 @@ var AsyncQueryBusClient = _AsyncQueryBusClient;
358
375
 
359
376
  // src/AsyncQueryBus/AsyncQueryBusHost.ts
360
377
  import { containsAll } from "@xylabs/array";
361
- import { assertEx as assertEx3 } from "@xylabs/assert";
378
+ import { assertEx as assertEx2 } from "@xylabs/assert";
362
379
  import { clearTimeoutEx as clearTimeoutEx2, setTimeoutEx as setTimeoutEx2 } from "@xylabs/timer";
363
380
  import { isQueryBoundWitnessWithMeta } from "@xyo-network/boundwitness-model";
364
381
  import { BoundWitnessDivinerQuerySchema as BoundWitnessDivinerQuerySchema2 } from "@xyo-network/diviner-boundwitness-model";
@@ -384,7 +401,7 @@ var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
384
401
  expose(address, options = {}) {
385
402
  var _a;
386
403
  const { failOnAlreadyExposed } = options;
387
- assertEx3(!failOnAlreadyExposed || !this._exposedAddresses.has(address), () => `Address already exposed [${address}]`);
404
+ assertEx2(!failOnAlreadyExposed || !this._exposedAddresses.has(address), () => `Address already exposed [${address}]`);
388
405
  this._exposedAddresses.add(address);
389
406
  this._exposeOptions[address] = {
390
407
  ...options
@@ -397,7 +414,7 @@ var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
397
414
  ...((_a = this.config) == null ? void 0 : _a.listeningModules) ?? [],
398
415
  ...this.exposedAddresses.values()
399
416
  ];
400
- const mods = await Promise.all(exposedModules.map(async (listeningModule) => assertEx3(asModuleInstance(await this.resolver.resolve(listeningModule)), () => `Unable to resolve listeningModule [${listeningModule}]`)));
417
+ const mods = await Promise.all(exposedModules.map(async (listeningModule) => assertEx2(asModuleInstance(await this.resolver.resolve(listeningModule)), () => `Unable to resolve listeningModule [${listeningModule}]`)));
401
418
  return mods;
402
419
  }
403
420
  start() {
@@ -416,7 +433,7 @@ var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
416
433
  }
417
434
  unexpose(address, validate = true) {
418
435
  var _a;
419
- assertEx3(!validate || this._exposedAddresses.has(address), () => `Address not exposed [${address}]`);
436
+ assertEx2(!validate || this._exposedAddresses.has(address), () => `Address not exposed [${address}]`);
420
437
  this._exposedAddresses.delete(address);
421
438
  delete this._exposeOptions[address];
422
439
  (_a = this.logger) == null ? void 0 : _a.debug(`${address} unexposed`);
@@ -424,11 +441,11 @@ var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
424
441
  callLocalModule = async (localModule, query) => {
425
442
  var _a, _b, _c, _d, _e, _f, _g;
426
443
  const localModuleName = localModule.config.name ?? localModule.address;
427
- const queryArchivist = assertEx3(await this.queriesArchivist(), () => {
444
+ const queryArchivist = assertEx2(await this.queriesArchivist(), () => {
428
445
  var _a2, _b2, _c2;
429
446
  return `Unable to contact queriesArchivist [${(_c2 = (_b2 = (_a2 = this.config) == null ? void 0 : _a2.intersect) == null ? void 0 : _b2.queries) == null ? void 0 : _c2.archivist}]`;
430
447
  });
431
- const responsesArchivist = assertEx3(await this.responsesArchivist(), () => {
448
+ const responsesArchivist = assertEx2(await this.responsesArchivist(), () => {
432
449
  var _a2, _b2, _c2;
433
450
  return `Unable to contact responsesArchivist [${(_c2 = (_b2 = (_a2 = this.config) == null ? void 0 : _a2.intersect) == null ? void 0 : _b2.queries) == null ? void 0 : _c2.archivist}]`;
434
451
  });
@@ -478,29 +495,31 @@ var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
478
495
  * @param address The address to find commands for
479
496
  */
480
497
  findQueriesToAddress = async (address) => {
481
- const queryBoundWitnessDiviner = assertEx3(await this.queriesDiviner(), () => {
482
- var _a, _b, _c;
483
- return `Unable to resolve queriesDiviner [${(_c = (_b = (_a = this.config) == null ? void 0 : _a.intersect) == null ? void 0 : _b.queries) == null ? void 0 : _c.boundWitnessDiviner}]`;
484
- });
485
- const timestamp = await this.retrieveState(address);
486
- const destination = [
487
- address
488
- ];
489
- const limit = this.perAddressBatchQueryLimit;
490
- const divinerQuery = {
491
- destination,
492
- limit,
493
- schema: BoundWitnessDivinerQuerySchema2,
494
- sort: "asc",
495
- timestamp
496
- };
497
- const result = await queryBoundWitnessDiviner.divine([
498
- divinerQuery
499
- ]);
500
- const queries = result.filter(isQueryBoundWitnessWithMeta);
501
- const nextState = queries.length > 0 ? Math.max(...queries.map((c) => c.timestamp ?? 0)) + 1 : timestamp;
502
- await this.commitState(address, nextState);
503
- return queries;
498
+ var _a, _b, _c, _d;
499
+ const queryBoundWitnessDiviner = await this.queriesDiviner();
500
+ if (queryBoundWitnessDiviner) {
501
+ const timestamp = await this.retrieveState(address);
502
+ const destination = [
503
+ address
504
+ ];
505
+ const limit = this.perAddressBatchQueryLimit;
506
+ const divinerQuery = {
507
+ destination,
508
+ limit,
509
+ schema: BoundWitnessDivinerQuerySchema2,
510
+ sort: "asc",
511
+ timestamp
512
+ };
513
+ const result = await queryBoundWitnessDiviner.divine([
514
+ divinerQuery
515
+ ]);
516
+ const queries = result.filter(isQueryBoundWitnessWithMeta);
517
+ const nextState = queries.length > 0 ? Math.max(...queries.map((c) => c.timestamp ?? 0)) + 1 : timestamp;
518
+ await this.commitState(address, nextState);
519
+ return queries;
520
+ } else {
521
+ (_d = this.logger) == null ? void 0 : _d.warn(`Unable to resolve queryBoundWitnessDiviner [${(_c = (_b = (_a = this.config) == null ? void 0 : _a.intersect) == null ? void 0 : _b.queries) == null ? void 0 : _c.boundWitnessDiviner}]`);
522
+ }
504
523
  };
505
524
  /**
506
525
  * Runs the background divine process on a loop with a delay
@@ -533,7 +552,7 @@ var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
533
552
  try {
534
553
  const localModuleName = localModule.config.name ?? localModule.address;
535
554
  (_a2 = this.logger) == null ? void 0 : _a2.debug(`Checking for inbound queries to ${localModuleName} [${localModule.address}]`);
536
- const queries = await this.findQueriesToAddress(localModule.address);
555
+ const queries = await this.findQueriesToAddress(localModule.address) ?? [];
537
556
  if (queries.length === 0)
538
557
  return;
539
558
  (_b = this.logger) == null ? void 0 : _b.debug(`Found queries addressed to local module: ${localModuleName}`);
@@ -598,13 +617,13 @@ var PubSubBridgeSchema = "network.xyo.bridge.pubsub";
598
617
  var PubSubBridgeConfigSchema = `${PubSubBridgeSchema}.config`;
599
618
 
600
619
  // src/PubSubBridge.ts
601
- import { assertEx as assertEx5 } from "@xylabs/assert";
620
+ import { assertEx as assertEx4 } from "@xylabs/assert";
602
621
  import { exists } from "@xylabs/exists";
603
622
  import { AbstractBridge } from "@xyo-network/abstract-bridge";
604
623
  import { creatableModule } from "@xyo-network/module-model";
605
624
 
606
625
  // src/PubSubBridgeModuleResolver.ts
607
- import { assertEx as assertEx4 } from "@xylabs/assert";
626
+ import { assertEx as assertEx3 } from "@xylabs/assert";
608
627
  import { isAddress } from "@xylabs/hex";
609
628
  import { AbstractBridgeModuleResolver, wrapModuleWithType } from "@xyo-network/abstract-bridge";
610
629
  import { Account } from "@xyo-network/account";
@@ -619,16 +638,16 @@ var _PubSubBridgeModuleResolver = class _PubSubBridgeModuleResolver extends Abst
619
638
  }
620
639
  const idParts = id.split(":");
621
640
  const firstPart = idParts.shift();
622
- assertEx4(isAddress(firstPart), () => `Invalid module address: ${firstPart}`);
641
+ assertEx3(isAddress(firstPart), () => `Invalid module address: ${firstPart}`);
623
642
  const remainderParts = idParts.join(":");
624
643
  const account = Account.randomSync();
625
644
  const params = {
626
645
  account,
627
- busClient: this.options.busClient,
646
+ busClient: this.params.busClient,
628
647
  config: {
629
648
  schema: ModuleConfigSchema2
630
649
  },
631
- host: this.options.bridge,
650
+ host: this.params.bridge,
632
651
  moduleAddress: firstPart
633
652
  };
634
653
  const proxy = new AsyncQueryBusModuleProxy(params);
@@ -636,13 +655,13 @@ var _PubSubBridgeModuleResolver = class _PubSubBridgeModuleResolver extends Abst
636
655
  const state = await proxy.state();
637
656
  if (state) {
638
657
  const configSchema = (_a = state.find((payload) => payload.schema === ConfigSchema)) == null ? void 0 : _a.config;
639
- const config = assertEx4(state.find((payload) => payload.schema === configSchema), () => "Unable to locate config");
658
+ const config = assertEx3(state.find((payload) => payload.schema === configSchema), () => "Unable to locate config");
640
659
  proxy.setConfig(config);
641
660
  }
642
661
  }
643
662
  await ((_b = proxy.start) == null ? void 0 : _b.call(proxy));
644
663
  const wrapped = wrapModuleWithType(proxy, account);
645
- const as = assertEx4(asModuleInstance2(wrapped, {}), () => `Failed to asModuleInstance [${id}]`);
664
+ const as = assertEx3(asModuleInstance2(wrapped, {}), () => `Failed to asModuleInstance [${id}]`);
646
665
  proxy.upResolver.add(as);
647
666
  proxy.downResolver.add(as);
648
667
  this.add(as);
@@ -677,7 +696,7 @@ var _PubSubBridge = class _PubSubBridge extends AbstractBridge {
677
696
  get resolver() {
678
697
  this._resolver = this._resolver ?? new PubSubBridgeModuleResolver({
679
698
  bridge: this,
680
- busClient: assertEx5(this.busClient(), () => "busClient not configured"),
699
+ busClient: assertEx4(this.busClient(), () => "busClient not configured"),
681
700
  wrapperAccount: this.account
682
701
  });
683
702
  return this._resolver;
@@ -686,7 +705,7 @@ var _PubSubBridge = class _PubSubBridge extends AbstractBridge {
686
705
  return `${this.config.name ?? moduleName}`;
687
706
  }
688
707
  get roots() {
689
- return assertEx5(this.config.roots, () => "roots not configured");
708
+ return assertEx4(this.config.roots, () => "roots not configured");
690
709
  }
691
710
  async discoverRoots() {
692
711
  const rootInstances = (await Promise.all(this.roots.map(async (root) => await this.resolver.resolve(root)))).filter(exists);
@@ -697,9 +716,9 @@ var _PubSubBridge = class _PubSubBridge extends AbstractBridge {
697
716
  }
698
717
  async exposeHandler(id, options) {
699
718
  const { maxDepth = 2, direction = "all" } = options ?? {};
700
- const module = assertEx5(await super.resolve(id), () => `Expose failed to locate module [${id}]`);
719
+ const module = assertEx4(await super.resolve(id), () => `Expose failed to locate module [${id}]`);
701
720
  if (module) {
702
- const host = assertEx5(this.busHost(), () => "Not configured as a host");
721
+ const host = assertEx4(this.busHost(), () => "Not configured as a host");
703
722
  host.expose(module.address);
704
723
  const children = await module.resolve("*", {
705
724
  direction,
@@ -735,7 +754,7 @@ var _PubSubBridge = class _PubSubBridge extends AbstractBridge {
735
754
  };
736
755
  const module = await super.resolve(id, filterOptions);
737
756
  if (module) {
738
- const host = assertEx5(this.busHost(), () => "Not configured as a host");
757
+ const host = assertEx4(this.busHost(), () => "Not configured as a host");
739
758
  host.unexpose(module.address);
740
759
  const children = await module.resolve("*", {
741
760
  direction,