@xyo-network/bridge-pub-sub 2.94.15 → 2.94.17

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 (42) hide show
  1. package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.cts +7 -68
  2. package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.cts.map +1 -1
  3. package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.mts +7 -68
  4. package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.mts.map +1 -1
  5. package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.ts +7 -68
  6. package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.ts.map +1 -1
  7. package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.cts +24 -3
  8. package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.cts.map +1 -1
  9. package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.mts +24 -3
  10. package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.mts.map +1 -1
  11. package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.ts +24 -3
  12. package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.ts.map +1 -1
  13. package/dist/browser/PubSubBridge.d.cts.map +1 -1
  14. package/dist/browser/PubSubBridge.d.mts.map +1 -1
  15. package/dist/browser/PubSubBridge.d.ts.map +1 -1
  16. package/dist/browser/index.cjs +106 -132
  17. package/dist/browser/index.cjs.map +1 -1
  18. package/dist/browser/index.js +103 -129
  19. package/dist/browser/index.js.map +1 -1
  20. package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.cts +7 -68
  21. package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.cts.map +1 -1
  22. package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.mts +7 -68
  23. package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.mts.map +1 -1
  24. package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.ts +7 -68
  25. package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.ts.map +1 -1
  26. package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.cts +24 -3
  27. package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.cts.map +1 -1
  28. package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.mts +24 -3
  29. package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.mts.map +1 -1
  30. package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.ts +24 -3
  31. package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.ts.map +1 -1
  32. package/dist/node/PubSubBridge.d.cts.map +1 -1
  33. package/dist/node/PubSubBridge.d.mts.map +1 -1
  34. package/dist/node/PubSubBridge.d.ts.map +1 -1
  35. package/dist/node/index.cjs +111 -136
  36. package/dist/node/index.cjs.map +1 -1
  37. package/dist/node/index.js +108 -133
  38. package/dist/node/index.js.map +1 -1
  39. package/package.json +19 -18
  40. package/src/AsyncQueryBus/AsyncQueryBusBase.ts +59 -89
  41. package/src/AsyncQueryBus/AsyncQueryBusHost.ts +29 -14
  42. package/src/PubSubBridge.ts +21 -20
@@ -14,7 +14,7 @@ __name(_AbstractModuleHost, "AbstractModuleHost");
14
14
  var AbstractModuleHost = _AbstractModuleHost;
15
15
 
16
16
  // src/AsyncQueryBus/AsyncQueryBusClient.ts
17
- import { assertEx } from "@xylabs/assert";
17
+ import { assertEx as assertEx2 } 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,21 +24,22 @@ 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 { Base as Base2, toJsonString } from "@xylabs/object";
28
- import { asArchivistInstance } from "@xyo-network/archivist-model";
29
- import { asDivinerInstance } from "@xyo-network/diviner-model";
27
+ import { assertEx } from "@xylabs/assert";
28
+ import { Base as Base2 } from "@xylabs/object";
29
+ import { isArchivistInstance } from "@xyo-network/archivist-model";
30
+ import { isDivinerInstance } from "@xyo-network/diviner-model";
31
+ import { traceModuleIdentifier } from "@xyo-network/module-model";
32
+ import { Mutex } from "async-mutex";
30
33
  import { LRUCache } from "lru-cache";
31
34
  var _AsyncQueryBusBase = class _AsyncQueryBusBase extends Base2 {
32
35
  _lastState;
33
36
  _targetConfigs = {};
34
37
  _targetQueries = {};
35
- _lastQueriesArchivistAttempt;
36
- _lastQueriesDivinerAttempt;
37
- _lastResponsesArchivistAttempt;
38
- _lastResponsesDivinerAttempt;
38
+ _lastResolveAttempt = {};
39
39
  _queriesArchivist;
40
40
  _queriesDiviner;
41
- _reResolveDelay = 5e4;
41
+ _reResolveDelay = 1e3 * 5;
42
+ _resolveMutex = new Mutex();
42
43
  _responsesArchivist;
43
44
  _responsesDiviner;
44
45
  constructor(params) {
@@ -66,88 +67,24 @@ var _AsyncQueryBusBase = class _AsyncQueryBusBase extends Base2 {
66
67
  return this._lastState;
67
68
  }
68
69
  async queriesArchivist() {
69
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
70
- if (this._queriesArchivist) {
71
- return this._queriesArchivist;
72
- }
73
- if (Date.now() - (this._lastQueriesArchivistAttempt ?? 0) < this._reResolveDelay) {
74
- return;
75
- }
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
- }
70
+ var _a, _b, _c;
71
+ this._queriesArchivist = this._queriesArchivist ?? await this.resolve(assertEx((_c = (_b = (_a = this.config) == null ? void 0 : _a.intersect) == null ? void 0 : _b.queries) == null ? void 0 : _c.archivist, () => "No queries Archivist defined"), isArchivistInstance);
72
+ return this._queriesArchivist;
88
73
  }
89
74
  async queriesDiviner() {
90
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
91
- if (this._queriesDiviner) {
92
- return this._queriesDiviner;
93
- }
94
- if (Date.now() - (this._lastQueriesDivinerAttempt ?? 0) < this._reResolveDelay) {
95
- return;
96
- }
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
- }
75
+ var _a, _b, _c;
76
+ this._queriesDiviner = this._queriesDiviner ?? await this.resolve(assertEx((_c = (_b = (_a = this.config) == null ? void 0 : _a.intersect) == null ? void 0 : _b.queries) == null ? void 0 : _c.boundWitnessDiviner, () => "No queries Diviner defined"), isDivinerInstance);
77
+ return this._queriesDiviner;
109
78
  }
110
79
  async responsesArchivist() {
111
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
112
- if (this._responsesArchivist) {
113
- return this._responsesArchivist;
114
- }
115
- if (Date.now() - (this._lastResponsesArchivistAttempt ?? 0) < this._reResolveDelay) {
116
- return;
117
- }
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
- }
80
+ var _a, _b, _c;
81
+ this._responsesArchivist = this._responsesArchivist ?? await this.resolve(assertEx((_c = (_b = (_a = this.config) == null ? void 0 : _a.intersect) == null ? void 0 : _b.responses) == null ? void 0 : _c.archivist, () => "No responses Archivist defined"), isArchivistInstance);
82
+ return this._responsesArchivist;
130
83
  }
131
84
  async responsesDiviner() {
132
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
133
- if (this._responsesDiviner) {
134
- return this._responsesDiviner;
135
- }
136
- if (Date.now() - (this._lastResponsesDivinerAttempt ?? 0) < this._reResolveDelay) {
137
- return;
138
- }
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
- }
85
+ var _a, _b, _c;
86
+ this._responsesDiviner = this._responsesDiviner ?? await this.resolve(assertEx((_c = (_b = (_a = this.config) == null ? void 0 : _a.intersect) == null ? void 0 : _b.responses) == null ? void 0 : _c.boundWitnessDiviner, () => "No responses Diviner defined"), isDivinerInstance);
87
+ return this._responsesDiviner;
151
88
  }
152
89
  /**
153
90
  * Commit the internal state of the process. This is similar
@@ -179,6 +116,28 @@ var _AsyncQueryBusBase = class _AsyncQueryBusBase extends Base2 {
179
116
  return state;
180
117
  }
181
118
  }
119
+ async resolve(id, typeCheck) {
120
+ return await this._resolveMutex.runExclusive(async () => {
121
+ var _a, _b, _c;
122
+ if (this._queriesArchivist) {
123
+ return this._queriesArchivist;
124
+ }
125
+ if (Date.now() - (this._lastResolveAttempt[id] ?? 0) < this._reResolveDelay) {
126
+ return;
127
+ }
128
+ this._lastResolveAttempt[id] = Date.now();
129
+ const resolved = await this.resolver.resolve(id);
130
+ if (resolved) {
131
+ if (typeCheck(resolved)) {
132
+ return resolved;
133
+ } else {
134
+ (_b = this.logger) == null ? void 0 : _b.warn(`Unable to resolve responsesDiviner as correct type [${id}][${(_a = resolved == null ? void 0 : resolved.constructor) == null ? void 0 : _a.name}]: ${resolved.id}`);
135
+ }
136
+ } else {
137
+ (_c = this.logger) == null ? void 0 : _c.log(`Unable to resolve queriesArchivist [${id}] [${await traceModuleIdentifier(this.resolver, id)}]`);
138
+ }
139
+ });
140
+ }
182
141
  };
183
142
  __name(_AsyncQueryBusBase, "AsyncQueryBusBase");
184
143
  var AsyncQueryBusBase = _AsyncQueryBusBase;
@@ -238,7 +197,7 @@ var _AsyncQueryBusClient = class _AsyncQueryBusClient extends AsyncQueryBusBase
238
197
  ...query,
239
198
  $meta
240
199
  });
241
- const queryArchivist = assertEx(await this.queriesArchivist(), () => {
200
+ const queryArchivist = assertEx2(await this.queriesArchivist(), () => {
242
201
  var _a2, _b2, _c2;
243
202
  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}]`;
244
203
  });
@@ -375,7 +334,7 @@ var AsyncQueryBusClient = _AsyncQueryBusClient;
375
334
 
376
335
  // src/AsyncQueryBus/AsyncQueryBusHost.ts
377
336
  import { containsAll } from "@xylabs/array";
378
- import { assertEx as assertEx2 } from "@xylabs/assert";
337
+ import { assertEx as assertEx3 } from "@xylabs/assert";
379
338
  import { clearTimeoutEx as clearTimeoutEx2, setTimeoutEx as setTimeoutEx2 } from "@xylabs/timer";
380
339
  import { isQueryBoundWitnessWithMeta } from "@xyo-network/boundwitness-model";
381
340
  import { BoundWitnessDivinerQuerySchema as BoundWitnessDivinerQuerySchema2 } from "@xyo-network/diviner-boundwitness-model";
@@ -398,15 +357,24 @@ var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
398
357
  get started() {
399
358
  return !!this._pollId;
400
359
  }
401
- expose(address, options = {}) {
360
+ async expose(id, options) {
402
361
  var _a;
403
- const { failOnAlreadyExposed } = options;
404
- assertEx2(!failOnAlreadyExposed || !this._exposedAddresses.has(address), () => `Address already exposed [${address}]`);
405
- this._exposedAddresses.add(address);
406
- this._exposeOptions[address] = {
407
- ...options
408
- };
409
- (_a = this.logger) == null ? void 0 : _a.debug(`${address} exposed`);
362
+ const { failOnAlreadyExposed, required = true } = options ?? {};
363
+ const module = asModuleInstance(await this.resolver.resolve(id, {
364
+ maxDepth: 10
365
+ }));
366
+ if (!module && required) {
367
+ throw new Error(`Unable to resolve module to expose [${id}]`);
368
+ }
369
+ if (module) {
370
+ assertEx3(!failOnAlreadyExposed || !this._exposedAddresses.has(module.address), () => `Address already exposed: ${id} [${module.address}]`);
371
+ this._exposedAddresses.add(module.address);
372
+ this._exposeOptions[module.address] = {
373
+ ...options
374
+ };
375
+ (_a = this.logger) == null ? void 0 : _a.debug(`${id} exposed [${module.address}]`);
376
+ return module;
377
+ }
410
378
  }
411
379
  async listeningModules() {
412
380
  var _a;
@@ -414,7 +382,9 @@ var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
414
382
  ...((_a = this.config) == null ? void 0 : _a.listeningModules) ?? [],
415
383
  ...this.exposedAddresses.values()
416
384
  ];
417
- const mods = await Promise.all(exposedModules.map(async (listeningModule) => assertEx2(asModuleInstance(await this.resolver.resolve(listeningModule)), () => `Unable to resolve listeningModule [${listeningModule}]`)));
385
+ const mods = await Promise.all(exposedModules.map(async (exposedModule) => assertEx3(asModuleInstance(await this.resolver.resolve(exposedModule, {
386
+ maxDepth: 10
387
+ })), () => `Unable to resolve listeningModule [${exposedModule}]`)));
418
388
  return mods;
419
389
  }
420
390
  start() {
@@ -431,21 +401,27 @@ var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
431
401
  clearTimeoutEx2(this._pollId);
432
402
  this._pollId = void 0;
433
403
  }
434
- unexpose(address, validate = true) {
404
+ async unexpose(id, validate = true) {
435
405
  var _a;
436
- assertEx2(!validate || this._exposedAddresses.has(address), () => `Address not exposed [${address}]`);
437
- this._exposedAddresses.delete(address);
438
- delete this._exposeOptions[address];
439
- (_a = this.logger) == null ? void 0 : _a.debug(`${address} unexposed`);
406
+ const module = asModuleInstance(await this.resolver.resolve(id, {
407
+ maxDepth: 10
408
+ }));
409
+ if (module) {
410
+ assertEx3(!validate || this._exposedAddresses.has(module.address), () => `Address not exposed [${module.address}][${module.id}]`);
411
+ this._exposedAddresses.delete(module.address);
412
+ delete this._exposeOptions[module.address];
413
+ (_a = this.logger) == null ? void 0 : _a.debug(`${module.address} [${module.id}] unexposed`);
414
+ }
415
+ return module;
440
416
  }
441
417
  callLocalModule = async (localModule, query) => {
442
418
  var _a, _b, _c, _d, _e, _f, _g;
443
419
  const localModuleName = localModule.config.name ?? localModule.address;
444
- const queryArchivist = assertEx2(await this.queriesArchivist(), () => {
420
+ const queryArchivist = assertEx3(await this.queriesArchivist(), () => {
445
421
  var _a2, _b2, _c2;
446
422
  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}]`;
447
423
  });
448
- const responsesArchivist = assertEx2(await this.responsesArchivist(), () => {
424
+ const responsesArchivist = assertEx3(await this.responsesArchivist(), () => {
449
425
  var _a2, _b2, _c2;
450
426
  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}]`;
451
427
  });
@@ -617,13 +593,13 @@ var PubSubBridgeSchema = "network.xyo.bridge.pubsub";
617
593
  var PubSubBridgeConfigSchema = `${PubSubBridgeSchema}.config`;
618
594
 
619
595
  // src/PubSubBridge.ts
620
- import { assertEx as assertEx4 } from "@xylabs/assert";
596
+ import { assertEx as assertEx5 } from "@xylabs/assert";
621
597
  import { exists } from "@xylabs/exists";
622
598
  import { AbstractBridge } from "@xyo-network/abstract-bridge";
623
599
  import { creatableModule } from "@xyo-network/module-model";
624
600
 
625
601
  // src/PubSubBridgeModuleResolver.ts
626
- import { assertEx as assertEx3 } from "@xylabs/assert";
602
+ import { assertEx as assertEx4 } from "@xylabs/assert";
627
603
  import { isAddress } from "@xylabs/hex";
628
604
  import { AbstractBridgeModuleResolver, wrapModuleWithType } from "@xyo-network/abstract-bridge";
629
605
  import { Account } from "@xyo-network/account";
@@ -638,7 +614,7 @@ var _PubSubBridgeModuleResolver = class _PubSubBridgeModuleResolver extends Abst
638
614
  }
639
615
  const idParts = id.split(":");
640
616
  const firstPart = idParts.shift();
641
- assertEx3(isAddress(firstPart), () => `Invalid module address: ${firstPart}`);
617
+ assertEx4(isAddress(firstPart), () => `Invalid module address: ${firstPart}`);
642
618
  const remainderParts = idParts.join(":");
643
619
  const account = Account.randomSync();
644
620
  const params = {
@@ -655,13 +631,13 @@ var _PubSubBridgeModuleResolver = class _PubSubBridgeModuleResolver extends Abst
655
631
  const state = await proxy.state();
656
632
  if (state) {
657
633
  const configSchema = (_a = state.find((payload) => payload.schema === ConfigSchema)) == null ? void 0 : _a.config;
658
- const config = assertEx3(state.find((payload) => payload.schema === configSchema), () => "Unable to locate config");
634
+ const config = assertEx4(state.find((payload) => payload.schema === configSchema), () => "Unable to locate config");
659
635
  proxy.setConfig(config);
660
636
  }
661
637
  }
662
638
  await ((_b = proxy.start) == null ? void 0 : _b.call(proxy));
663
639
  const wrapped = wrapModuleWithType(proxy, account);
664
- const as = assertEx3(asModuleInstance2(wrapped, {}), () => `Failed to asModuleInstance [${id}]`);
640
+ const as = assertEx4(asModuleInstance2(wrapped, {}), () => `Failed to asModuleInstance [${id}]`);
665
641
  proxy.upResolver.add(as);
666
642
  proxy.downResolver.add(as);
667
643
  this.add(as);
@@ -696,7 +672,7 @@ var _PubSubBridge = class _PubSubBridge extends AbstractBridge {
696
672
  get resolver() {
697
673
  this._resolver = this._resolver ?? new PubSubBridgeModuleResolver({
698
674
  bridge: this,
699
- busClient: assertEx4(this.busClient(), () => "busClient not configured"),
675
+ busClient: assertEx5(this.busClient(), () => "busClient not configured"),
700
676
  wrapperAccount: this.account
701
677
  });
702
678
  return this._resolver;
@@ -705,7 +681,7 @@ var _PubSubBridge = class _PubSubBridge extends AbstractBridge {
705
681
  return `${this.config.name ?? moduleName}`;
706
682
  }
707
683
  get roots() {
708
- return assertEx4(this.config.roots, () => "roots not configured");
684
+ return assertEx5(this.config.roots, () => "roots not configured");
709
685
  }
710
686
  async discoverRoots() {
711
687
  const rootInstances = (await Promise.all(this.roots.map(async (root) => await this.resolver.resolve(root)))).filter(exists);
@@ -715,22 +691,24 @@ var _PubSubBridge = class _PubSubBridge extends AbstractBridge {
715
691
  return rootInstances;
716
692
  }
717
693
  async exposeHandler(id, options) {
718
- const { maxDepth = 2, direction = "all" } = options ?? {};
719
- const module = assertEx4(await super.resolve(id), () => `Expose failed to locate module [${id}]`);
694
+ const { maxDepth = 2, direction = "all", required = true } = options ?? {};
695
+ const host = assertEx5(this.busHost(), () => "Not configured as a host");
696
+ const module = await host.expose(id, {
697
+ required
698
+ });
720
699
  if (module) {
721
- const host = assertEx4(this.busHost(), () => "Not configured as a host");
722
- host.expose(module.address);
723
- const children = await module.resolve("*", {
700
+ const children = maxDepth > 0 ? await module.resolve("*", {
724
701
  direction,
725
702
  maxDepth,
726
703
  visibility: "public"
727
- });
728
- for (const child of children) {
729
- host.expose(child.address);
730
- }
704
+ }) : [];
705
+ const exposedChildren = (await Promise.all(children.map((child) => this.exposeHandler(child.address, {
706
+ maxDepth: maxDepth - 1,
707
+ required: false
708
+ })))).flat().filter(exists);
731
709
  return [
732
710
  module,
733
- ...children
711
+ ...exposedChildren
734
712
  ];
735
713
  }
736
714
  return [];
@@ -748,25 +726,22 @@ var _PubSubBridge = class _PubSubBridge extends AbstractBridge {
748
726
  return await super.startHandler();
749
727
  }
750
728
  async unexposeHandler(id, options) {
751
- const { maxDepth = 10, direction } = options ?? {};
752
- const filterOptions = {
753
- direction
754
- };
755
- const module = await super.resolve(id, filterOptions);
729
+ const { maxDepth = 2, direction = "all", required = true } = options ?? {};
730
+ const host = assertEx5(this.busHost(), () => "Not configured as a host");
731
+ const module = await host.unexpose(id, required);
756
732
  if (module) {
757
- const host = assertEx4(this.busHost(), () => "Not configured as a host");
758
- host.unexpose(module.address);
759
- const children = await module.resolve("*", {
733
+ const children = maxDepth > 0 ? await module.resolve("*", {
760
734
  direction,
761
735
  maxDepth,
762
736
  visibility: "public"
763
- });
764
- for (const child of children) {
765
- host.unexpose(child.address);
766
- }
737
+ }) : [];
738
+ const exposedChildren = (await Promise.all(children.map((child) => this.unexposeHandler(child.address, {
739
+ maxDepth: maxDepth - 1,
740
+ required: false
741
+ })))).flat().filter(exists);
767
742
  return [
768
743
  module,
769
- ...children
744
+ ...exposedChildren
770
745
  ];
771
746
  }
772
747
  return [];