@xyo-network/bridge-pub-sub 2.94.14 → 2.94.16

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 +4 -0
  2. package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.cts.map +1 -1
  3. package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.mts +4 -0
  4. package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.mts.map +1 -1
  5. package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.ts +4 -0
  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 +130 -101
  17. package/dist/browser/index.cjs.map +1 -1
  18. package/dist/browser/index.js +130 -101
  19. package/dist/browser/index.js.map +1 -1
  20. package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.cts +4 -0
  21. package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.cts.map +1 -1
  22. package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.mts +4 -0
  23. package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.mts.map +1 -1
  24. package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.ts +4 -0
  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 +134 -105
  36. package/dist/node/index.cjs.map +1 -1
  37. package/dist/node/index.js +134 -105
  38. package/dist/node/index.js.map +1 -1
  39. package/package.json +19 -18
  40. package/src/AsyncQueryBus/AsyncQueryBusBase.ts +85 -72
  41. package/src/AsyncQueryBus/AsyncQueryBusHost.ts +29 -14
  42. package/src/PubSubBridge.ts +21 -20
@@ -60,6 +60,7 @@ var import_lru_cache2 = require("lru-cache");
60
60
  var import_object2 = require("@xylabs/object");
61
61
  var import_archivist_model = require("@xyo-network/archivist-model");
62
62
  var import_diviner_model = require("@xyo-network/diviner-model");
63
+ var import_async_mutex = require("async-mutex");
63
64
  var import_lru_cache = require("lru-cache");
64
65
  var _AsyncQueryBusBase = class _AsyncQueryBusBase extends import_object2.Base {
65
66
  _lastState;
@@ -70,10 +71,14 @@ var _AsyncQueryBusBase = class _AsyncQueryBusBase extends import_object2.Base {
70
71
  _lastResponsesArchivistAttempt;
71
72
  _lastResponsesDivinerAttempt;
72
73
  _queriesArchivist;
74
+ _queriesArchivistMutex = new import_async_mutex.Mutex();
73
75
  _queriesDiviner;
76
+ _queriesDivinerMutex = new import_async_mutex.Mutex();
74
77
  _reResolveDelay = 5e4;
75
78
  _responsesArchivist;
79
+ _responsesArchivistMutex = new import_async_mutex.Mutex();
76
80
  _responsesDiviner;
81
+ _responsesDivinerMutex = new import_async_mutex.Mutex();
77
82
  constructor(params) {
78
83
  super(params);
79
84
  }
@@ -99,88 +104,96 @@ var _AsyncQueryBusBase = class _AsyncQueryBusBase extends import_object2.Base {
99
104
  return this._lastState;
100
105
  }
101
106
  async queriesArchivist() {
102
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
103
- if (this._queriesArchivist) {
104
- return this._queriesArchivist;
105
- }
106
- if (Date.now() - (this._lastQueriesArchivistAttempt ?? 0) < this._reResolveDelay) {
107
- return;
108
- }
109
- this._lastQueriesArchivistAttempt = Date.now();
110
- 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);
111
- if (resolved) {
112
- const typedResolve = (0, import_archivist_model.asArchivistInstance)(resolved);
113
- if (typedResolve) {
114
- return typedResolve;
107
+ return await this._queriesArchivistMutex.runExclusive(async () => {
108
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
109
+ if (this._queriesArchivist) {
110
+ return this._queriesArchivist;
111
+ }
112
+ if (Date.now() - (this._lastQueriesArchivistAttempt ?? 0) < this._reResolveDelay) {
113
+ return;
114
+ }
115
+ this._lastQueriesArchivistAttempt = Date.now();
116
+ 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);
117
+ if (resolved) {
118
+ const typedResolve = (0, import_archivist_model.asArchivistInstance)(resolved);
119
+ if (typedResolve) {
120
+ return typedResolve;
121
+ } else {
122
+ (_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}]: ${(0, import_object2.toJsonString)(resolved)}`);
123
+ }
115
124
  } else {
116
- (_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}]: ${(0, import_object2.toJsonString)(resolved)}`);
125
+ (_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}]`);
117
126
  }
118
- } else {
119
- (_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}]`);
120
- }
127
+ });
121
128
  }
122
129
  async queriesDiviner() {
123
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
124
- if (this._queriesDiviner) {
125
- return this._queriesDiviner;
126
- }
127
- if (Date.now() - (this._lastQueriesDivinerAttempt ?? 0) < this._reResolveDelay) {
128
- return;
129
- }
130
- this._lastQueriesDivinerAttempt = Date.now();
131
- 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);
132
- if (resolved) {
133
- const typedResolve = (0, import_diviner_model.asDivinerInstance)(resolved);
134
- if (typedResolve) {
135
- return typedResolve;
130
+ return await this._queriesDivinerMutex.runExclusive(async () => {
131
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
132
+ if (this._queriesDiviner) {
133
+ return this._queriesDiviner;
134
+ }
135
+ if (Date.now() - (this._lastQueriesDivinerAttempt ?? 0) < this._reResolveDelay) {
136
+ return;
137
+ }
138
+ this._lastQueriesDivinerAttempt = Date.now();
139
+ 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);
140
+ if (resolved) {
141
+ const typedResolve = (0, import_diviner_model.asDivinerInstance)(resolved);
142
+ if (typedResolve) {
143
+ return typedResolve;
144
+ } else {
145
+ (_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}]: ${(0, import_object2.toJsonString)(resolved)}`);
146
+ }
136
147
  } else {
137
- (_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}]: ${(0, import_object2.toJsonString)(resolved)}`);
148
+ (_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}]`);
138
149
  }
139
- } else {
140
- (_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}]`);
141
- }
150
+ });
142
151
  }
143
152
  async responsesArchivist() {
144
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
145
- if (this._responsesArchivist) {
146
- return this._responsesArchivist;
147
- }
148
- if (Date.now() - (this._lastResponsesArchivistAttempt ?? 0) < this._reResolveDelay) {
149
- return;
150
- }
151
- this._lastResponsesArchivistAttempt = Date.now();
152
- 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);
153
- if (resolved) {
154
- const typedResolve = (0, import_archivist_model.asArchivistInstance)(resolved);
155
- if (typedResolve) {
156
- return typedResolve;
153
+ return await this._responsesArchivistMutex.runExclusive(async () => {
154
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
155
+ if (this._responsesArchivist) {
156
+ return this._responsesArchivist;
157
+ }
158
+ if (Date.now() - (this._lastResponsesArchivistAttempt ?? 0) < this._reResolveDelay) {
159
+ return;
160
+ }
161
+ this._lastResponsesArchivistAttempt = Date.now();
162
+ 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);
163
+ if (resolved) {
164
+ const typedResolve = (0, import_archivist_model.asArchivistInstance)(resolved);
165
+ if (typedResolve) {
166
+ return typedResolve;
167
+ } else {
168
+ (_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}]: ${(0, import_object2.toJsonString)(resolved)}`);
169
+ }
157
170
  } else {
158
- (_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}]: ${(0, import_object2.toJsonString)(resolved)}`);
171
+ (_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}]`);
159
172
  }
160
- } else {
161
- (_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}]`);
162
- }
173
+ });
163
174
  }
164
175
  async responsesDiviner() {
165
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
166
- if (this._responsesDiviner) {
167
- return this._responsesDiviner;
168
- }
169
- if (Date.now() - (this._lastResponsesDivinerAttempt ?? 0) < this._reResolveDelay) {
170
- return;
171
- }
172
- this._lastResponsesDivinerAttempt = Date.now();
173
- 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);
174
- if (resolved) {
175
- const typedResolve = (0, import_diviner_model.asDivinerInstance)(resolved);
176
- if (typedResolve) {
177
- return typedResolve;
176
+ return await this._responsesDivinerMutex.runExclusive(async () => {
177
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
178
+ if (this._responsesDiviner) {
179
+ return this._responsesDiviner;
180
+ }
181
+ if (Date.now() - (this._lastResponsesDivinerAttempt ?? 0) < this._reResolveDelay) {
182
+ return;
183
+ }
184
+ this._lastResponsesDivinerAttempt = Date.now();
185
+ 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);
186
+ if (resolved) {
187
+ const typedResolve = (0, import_diviner_model.asDivinerInstance)(resolved);
188
+ if (typedResolve) {
189
+ return typedResolve;
190
+ } else {
191
+ (_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}]: ${(0, import_object2.toJsonString)(resolved)}`);
192
+ }
178
193
  } else {
179
- (_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}]: ${(0, import_object2.toJsonString)(resolved)}`);
194
+ (_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}]`);
180
195
  }
181
- } else {
182
- (_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}]`);
183
- }
196
+ });
184
197
  }
185
198
  /**
186
199
  * Commit the internal state of the process. This is similar
@@ -431,15 +444,24 @@ var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
431
444
  get started() {
432
445
  return !!this._pollId;
433
446
  }
434
- expose(address, options = {}) {
447
+ async expose(id, options) {
435
448
  var _a;
436
- const { failOnAlreadyExposed } = options;
437
- (0, import_assert2.assertEx)(!failOnAlreadyExposed || !this._exposedAddresses.has(address), () => `Address already exposed [${address}]`);
438
- this._exposedAddresses.add(address);
439
- this._exposeOptions[address] = {
440
- ...options
441
- };
442
- (_a = this.logger) == null ? void 0 : _a.debug(`${address} exposed`);
449
+ const { failOnAlreadyExposed, required = true } = options ?? {};
450
+ const module2 = (0, import_module_model.asModuleInstance)(await this.resolver.resolve(id, {
451
+ maxDepth: 10
452
+ }));
453
+ if (!module2 && required) {
454
+ throw new Error(`Unable to resolve module to expose [${id}]`);
455
+ }
456
+ if (module2) {
457
+ (0, import_assert2.assertEx)(!failOnAlreadyExposed || !this._exposedAddresses.has(module2.address), () => `Address already exposed: ${id} [${module2.address}]`);
458
+ this._exposedAddresses.add(module2.address);
459
+ this._exposeOptions[module2.address] = {
460
+ ...options
461
+ };
462
+ (_a = this.logger) == null ? void 0 : _a.debug(`${id} exposed [${module2.address}]`);
463
+ return module2;
464
+ }
443
465
  }
444
466
  async listeningModules() {
445
467
  var _a;
@@ -447,7 +469,9 @@ var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
447
469
  ...((_a = this.config) == null ? void 0 : _a.listeningModules) ?? [],
448
470
  ...this.exposedAddresses.values()
449
471
  ];
450
- const mods = await Promise.all(exposedModules.map(async (listeningModule) => (0, import_assert2.assertEx)((0, import_module_model.asModuleInstance)(await this.resolver.resolve(listeningModule)), () => `Unable to resolve listeningModule [${listeningModule}]`)));
472
+ const mods = await Promise.all(exposedModules.map(async (exposedModule) => (0, import_assert2.assertEx)((0, import_module_model.asModuleInstance)(await this.resolver.resolve(exposedModule, {
473
+ maxDepth: 10
474
+ })), () => `Unable to resolve listeningModule [${exposedModule}]`)));
451
475
  return mods;
452
476
  }
453
477
  start() {
@@ -464,12 +488,18 @@ var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
464
488
  (0, import_timer2.clearTimeoutEx)(this._pollId);
465
489
  this._pollId = void 0;
466
490
  }
467
- unexpose(address, validate = true) {
491
+ async unexpose(id, validate = true) {
468
492
  var _a;
469
- (0, import_assert2.assertEx)(!validate || this._exposedAddresses.has(address), () => `Address not exposed [${address}]`);
470
- this._exposedAddresses.delete(address);
471
- delete this._exposeOptions[address];
472
- (_a = this.logger) == null ? void 0 : _a.debug(`${address} unexposed`);
493
+ const module2 = (0, import_module_model.asModuleInstance)(await this.resolver.resolve(id, {
494
+ maxDepth: 10
495
+ }));
496
+ if (module2) {
497
+ (0, import_assert2.assertEx)(!validate || this._exposedAddresses.has(module2.address), () => `Address not exposed [${module2.address}][${module2.id}]`);
498
+ this._exposedAddresses.delete(module2.address);
499
+ delete this._exposeOptions[module2.address];
500
+ (_a = this.logger) == null ? void 0 : _a.debug(`${module2.address} [${module2.id}] unexposed`);
501
+ }
502
+ return module2;
473
503
  }
474
504
  callLocalModule = async (localModule, query) => {
475
505
  var _a, _b, _c, _d, _e, _f, _g;
@@ -748,22 +778,24 @@ var _PubSubBridge = class _PubSubBridge extends import_abstract_bridge3.Abstract
748
778
  return rootInstances;
749
779
  }
750
780
  async exposeHandler(id, options) {
751
- const { maxDepth = 2, direction = "all" } = options ?? {};
752
- const module2 = (0, import_assert4.assertEx)(await super.resolve(id), () => `Expose failed to locate module [${id}]`);
781
+ const { maxDepth = 2, direction = "all", required = true } = options ?? {};
782
+ const host = (0, import_assert4.assertEx)(this.busHost(), () => "Not configured as a host");
783
+ const module2 = await host.expose(id, {
784
+ required
785
+ });
753
786
  if (module2) {
754
- const host = (0, import_assert4.assertEx)(this.busHost(), () => "Not configured as a host");
755
- host.expose(module2.address);
756
- const children = await module2.resolve("*", {
787
+ const children = maxDepth > 0 ? await module2.resolve("*", {
757
788
  direction,
758
789
  maxDepth,
759
790
  visibility: "public"
760
- });
761
- for (const child of children) {
762
- host.expose(child.address);
763
- }
791
+ }) : [];
792
+ const exposedChildren = (await Promise.all(children.map((child) => this.exposeHandler(child.address, {
793
+ maxDepth: maxDepth - 1,
794
+ required: false
795
+ })))).flat().filter(import_exists.exists);
764
796
  return [
765
797
  module2,
766
- ...children
798
+ ...exposedChildren
767
799
  ];
768
800
  }
769
801
  return [];
@@ -781,25 +813,22 @@ var _PubSubBridge = class _PubSubBridge extends import_abstract_bridge3.Abstract
781
813
  return await super.startHandler();
782
814
  }
783
815
  async unexposeHandler(id, options) {
784
- const { maxDepth = 5, direction } = options ?? {};
785
- const filterOptions = {
786
- direction
787
- };
788
- const module2 = await super.resolve(id, filterOptions);
816
+ const { maxDepth = 2, direction = "all", required = true } = options ?? {};
817
+ const host = (0, import_assert4.assertEx)(this.busHost(), () => "Not configured as a host");
818
+ const module2 = await host.unexpose(id, required);
789
819
  if (module2) {
790
- const host = (0, import_assert4.assertEx)(this.busHost(), () => "Not configured as a host");
791
- host.unexpose(module2.address);
792
- const children = await module2.resolve("*", {
820
+ const children = maxDepth > 0 ? await module2.resolve("*", {
793
821
  direction,
794
822
  maxDepth,
795
823
  visibility: "public"
796
- });
797
- for (const child of children) {
798
- host.unexpose(child.address);
799
- }
824
+ }) : [];
825
+ const exposedChildren = (await Promise.all(children.map((child) => this.unexposeHandler(child.address, {
826
+ maxDepth: maxDepth - 1,
827
+ required: false
828
+ })))).flat().filter(import_exists.exists);
800
829
  return [
801
830
  module2,
802
- ...children
831
+ ...exposedChildren
803
832
  ];
804
833
  }
805
834
  return [];