@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.
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.cts +7 -68
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.cts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.mts +7 -68
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.mts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.ts +7 -68
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.ts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.cts +24 -3
- package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.cts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.mts +24 -3
- package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.mts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.ts +24 -3
- package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.ts.map +1 -1
- package/dist/browser/PubSubBridge.d.cts.map +1 -1
- package/dist/browser/PubSubBridge.d.mts.map +1 -1
- package/dist/browser/PubSubBridge.d.ts.map +1 -1
- package/dist/browser/index.cjs +106 -132
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +103 -129
- package/dist/browser/index.js.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.cts +7 -68
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.cts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.mts +7 -68
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.mts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.ts +7 -68
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.ts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.cts +24 -3
- package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.cts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.mts +24 -3
- package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.mts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.ts +24 -3
- package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.ts.map +1 -1
- package/dist/node/PubSubBridge.d.cts.map +1 -1
- package/dist/node/PubSubBridge.d.mts.map +1 -1
- package/dist/node/PubSubBridge.d.ts.map +1 -1
- package/dist/node/index.cjs +111 -136
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +108 -133
- package/dist/node/index.js.map +1 -1
- package/package.json +19 -18
- package/src/AsyncQueryBus/AsyncQueryBusBase.ts +59 -89
- package/src/AsyncQueryBus/AsyncQueryBusHost.ts +29 -14
- package/src/PubSubBridge.ts +21 -20
package/dist/browser/index.cjs
CHANGED
|
@@ -43,7 +43,7 @@ var AbstractModuleHost = class extends import_object.Base {
|
|
|
43
43
|
};
|
|
44
44
|
|
|
45
45
|
// src/AsyncQueryBus/AsyncQueryBusClient.ts
|
|
46
|
-
var
|
|
46
|
+
var import_assert2 = require("@xylabs/assert");
|
|
47
47
|
var import_delay = require("@xylabs/delay");
|
|
48
48
|
var import_forget = require("@xylabs/forget");
|
|
49
49
|
var import_timer = require("@xylabs/timer");
|
|
@@ -53,9 +53,12 @@ var import_payload_builder = require("@xyo-network/payload-builder");
|
|
|
53
53
|
var import_lru_cache2 = require("lru-cache");
|
|
54
54
|
|
|
55
55
|
// src/AsyncQueryBus/AsyncQueryBusBase.ts
|
|
56
|
+
var import_assert = require("@xylabs/assert");
|
|
56
57
|
var import_object2 = require("@xylabs/object");
|
|
57
58
|
var import_archivist_model = require("@xyo-network/archivist-model");
|
|
58
59
|
var import_diviner_model = require("@xyo-network/diviner-model");
|
|
60
|
+
var import_module_model = require("@xyo-network/module-model");
|
|
61
|
+
var import_async_mutex = require("async-mutex");
|
|
59
62
|
var import_lru_cache = require("lru-cache");
|
|
60
63
|
var AsyncQueryBusBase = class extends import_object2.Base {
|
|
61
64
|
static {
|
|
@@ -64,13 +67,11 @@ var AsyncQueryBusBase = class extends import_object2.Base {
|
|
|
64
67
|
_lastState;
|
|
65
68
|
_targetConfigs = {};
|
|
66
69
|
_targetQueries = {};
|
|
67
|
-
|
|
68
|
-
_lastQueriesDivinerAttempt;
|
|
69
|
-
_lastResponsesArchivistAttempt;
|
|
70
|
-
_lastResponsesDivinerAttempt;
|
|
70
|
+
_lastResolveAttempt = {};
|
|
71
71
|
_queriesArchivist;
|
|
72
72
|
_queriesDiviner;
|
|
73
|
-
_reResolveDelay =
|
|
73
|
+
_reResolveDelay = 1e3 * 5;
|
|
74
|
+
_resolveMutex = new import_async_mutex.Mutex();
|
|
74
75
|
_responsesArchivist;
|
|
75
76
|
_responsesDiviner;
|
|
76
77
|
constructor(params) {
|
|
@@ -97,84 +98,20 @@ var AsyncQueryBusBase = class extends import_object2.Base {
|
|
|
97
98
|
return this._lastState;
|
|
98
99
|
}
|
|
99
100
|
async queriesArchivist() {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
if (Date.now() - (this._lastQueriesArchivistAttempt ?? 0) < this._reResolveDelay) {
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
this._lastQueriesArchivistAttempt = Date.now();
|
|
107
|
-
const resolved = await this.resolver.resolve(this.config?.intersect?.queries?.archivist);
|
|
108
|
-
if (resolved) {
|
|
109
|
-
const typedResolve = (0, import_archivist_model.asArchivistInstance)(resolved);
|
|
110
|
-
if (typedResolve) {
|
|
111
|
-
return typedResolve;
|
|
112
|
-
} else {
|
|
113
|
-
this.logger?.warn(`Unable to resolve queriesArchivist as correct type [${this.config?.intersect?.queries?.archivist}][${resolved?.constructor?.name}]: ${(0, import_object2.toJsonString)(resolved)}`);
|
|
114
|
-
}
|
|
115
|
-
} else {
|
|
116
|
-
this.logger?.log(`Unable to resolve queriesArchivist [${this.config?.intersect?.queries?.archivist}]`);
|
|
117
|
-
}
|
|
101
|
+
this._queriesArchivist = this._queriesArchivist ?? await this.resolve((0, import_assert.assertEx)(this.config?.intersect?.queries?.archivist, () => "No queries Archivist defined"), import_archivist_model.isArchivistInstance);
|
|
102
|
+
return this._queriesArchivist;
|
|
118
103
|
}
|
|
119
104
|
async queriesDiviner() {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
if (Date.now() - (this._lastQueriesDivinerAttempt ?? 0) < this._reResolveDelay) {
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
this._lastQueriesDivinerAttempt = Date.now();
|
|
127
|
-
const resolved = await this.resolver.resolve(this.config?.intersect?.queries?.boundWitnessDiviner);
|
|
128
|
-
if (resolved) {
|
|
129
|
-
const typedResolve = (0, import_diviner_model.asDivinerInstance)(resolved);
|
|
130
|
-
if (typedResolve) {
|
|
131
|
-
return typedResolve;
|
|
132
|
-
} else {
|
|
133
|
-
this.logger?.warn(`Unable to resolve queriesDiviner as correct type [${this.config?.intersect?.queries?.boundWitnessDiviner}][${resolved?.constructor?.name}]: ${(0, import_object2.toJsonString)(resolved)}`);
|
|
134
|
-
}
|
|
135
|
-
} else {
|
|
136
|
-
this.logger?.log(`Unable to resolve queriesDiviner [${this.config?.intersect?.queries?.boundWitnessDiviner}]`);
|
|
137
|
-
}
|
|
105
|
+
this._queriesDiviner = this._queriesDiviner ?? await this.resolve((0, import_assert.assertEx)(this.config?.intersect?.queries?.boundWitnessDiviner, () => "No queries Diviner defined"), import_diviner_model.isDivinerInstance);
|
|
106
|
+
return this._queriesDiviner;
|
|
138
107
|
}
|
|
139
108
|
async responsesArchivist() {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
if (Date.now() - (this._lastResponsesArchivistAttempt ?? 0) < this._reResolveDelay) {
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
this._lastResponsesArchivistAttempt = Date.now();
|
|
147
|
-
const resolved = await this.resolver.resolve(this.config?.intersect?.responses?.archivist);
|
|
148
|
-
if (resolved) {
|
|
149
|
-
const typedResolve = (0, import_archivist_model.asArchivistInstance)(resolved);
|
|
150
|
-
if (typedResolve) {
|
|
151
|
-
return typedResolve;
|
|
152
|
-
} else {
|
|
153
|
-
this.logger?.warn(`Unable to resolve responseArchivist as correct type [${this.config?.intersect?.responses?.archivist}][${resolved?.constructor?.name}]: ${(0, import_object2.toJsonString)(resolved)}`);
|
|
154
|
-
}
|
|
155
|
-
} else {
|
|
156
|
-
this.logger?.log(`Unable to resolve responseArchivist [${this.config?.intersect?.responses?.archivist}]`);
|
|
157
|
-
}
|
|
109
|
+
this._responsesArchivist = this._responsesArchivist ?? await this.resolve((0, import_assert.assertEx)(this.config?.intersect?.responses?.archivist, () => "No responses Archivist defined"), import_archivist_model.isArchivistInstance);
|
|
110
|
+
return this._responsesArchivist;
|
|
158
111
|
}
|
|
159
112
|
async responsesDiviner() {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
if (Date.now() - (this._lastResponsesDivinerAttempt ?? 0) < this._reResolveDelay) {
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
this._lastResponsesDivinerAttempt = Date.now();
|
|
167
|
-
const resolved = await this.resolver.resolve(this.config?.intersect?.responses?.boundWitnessDiviner);
|
|
168
|
-
if (resolved) {
|
|
169
|
-
const typedResolve = (0, import_diviner_model.asDivinerInstance)(resolved);
|
|
170
|
-
if (typedResolve) {
|
|
171
|
-
return typedResolve;
|
|
172
|
-
} else {
|
|
173
|
-
this.logger?.warn(`Unable to resolve responsesDiviner as correct type [${this.config?.intersect?.responses?.boundWitnessDiviner}][${resolved?.constructor?.name}]: ${(0, import_object2.toJsonString)(resolved)}`);
|
|
174
|
-
}
|
|
175
|
-
} else {
|
|
176
|
-
this.logger?.log(`Unable to resolve responsesDiviner [${this.config?.intersect?.responses?.boundWitnessDiviner}]`);
|
|
177
|
-
}
|
|
113
|
+
this._responsesDiviner = this._responsesDiviner ?? await this.resolve((0, import_assert.assertEx)(this.config?.intersect?.responses?.boundWitnessDiviner, () => "No responses Diviner defined"), import_diviner_model.isDivinerInstance);
|
|
114
|
+
return this._responsesDiviner;
|
|
178
115
|
}
|
|
179
116
|
/**
|
|
180
117
|
* Commit the internal state of the process. This is similar
|
|
@@ -206,6 +143,27 @@ var AsyncQueryBusBase = class extends import_object2.Base {
|
|
|
206
143
|
return state;
|
|
207
144
|
}
|
|
208
145
|
}
|
|
146
|
+
async resolve(id, typeCheck) {
|
|
147
|
+
return await this._resolveMutex.runExclusive(async () => {
|
|
148
|
+
if (this._queriesArchivist) {
|
|
149
|
+
return this._queriesArchivist;
|
|
150
|
+
}
|
|
151
|
+
if (Date.now() - (this._lastResolveAttempt[id] ?? 0) < this._reResolveDelay) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
this._lastResolveAttempt[id] = Date.now();
|
|
155
|
+
const resolved = await this.resolver.resolve(id);
|
|
156
|
+
if (resolved) {
|
|
157
|
+
if (typeCheck(resolved)) {
|
|
158
|
+
return resolved;
|
|
159
|
+
} else {
|
|
160
|
+
this.logger?.warn(`Unable to resolve responsesDiviner as correct type [${id}][${resolved?.constructor?.name}]: ${resolved.id}`);
|
|
161
|
+
}
|
|
162
|
+
} else {
|
|
163
|
+
this.logger?.log(`Unable to resolve queriesArchivist [${id}] [${await (0, import_module_model.traceModuleIdentifier)(this.resolver, id)}]`);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}
|
|
209
167
|
};
|
|
210
168
|
|
|
211
169
|
// src/AsyncQueryBus/model/QueryStatus.ts
|
|
@@ -263,7 +221,7 @@ var AsyncQueryBusClient = class extends AsyncQueryBusBase {
|
|
|
263
221
|
...query,
|
|
264
222
|
$meta
|
|
265
223
|
});
|
|
266
|
-
const queryArchivist = (0,
|
|
224
|
+
const queryArchivist = (0, import_assert2.assertEx)(await this.queriesArchivist(), () => `Unable to contact queriesArchivist [${this.config?.intersect?.queries?.archivist}]`);
|
|
267
225
|
const routedQueryHash = (
|
|
268
226
|
// Trust the signed hash if it's there
|
|
269
227
|
routedQuery?.$hash ?? // TODO: What is the right way to find the dataHash
|
|
@@ -391,11 +349,11 @@ var AsyncQueryBusClient = class extends AsyncQueryBusBase {
|
|
|
391
349
|
|
|
392
350
|
// src/AsyncQueryBus/AsyncQueryBusHost.ts
|
|
393
351
|
var import_array = require("@xylabs/array");
|
|
394
|
-
var
|
|
352
|
+
var import_assert3 = require("@xylabs/assert");
|
|
395
353
|
var import_timer2 = require("@xylabs/timer");
|
|
396
354
|
var import_boundwitness_model2 = require("@xyo-network/boundwitness-model");
|
|
397
355
|
var import_diviner_boundwitness_model2 = require("@xyo-network/diviner-boundwitness-model");
|
|
398
|
-
var
|
|
356
|
+
var import_module_model2 = require("@xyo-network/module-model");
|
|
399
357
|
var import_payload_builder2 = require("@xyo-network/payload-builder");
|
|
400
358
|
var AsyncQueryBusHost = class extends AsyncQueryBusBase {
|
|
401
359
|
static {
|
|
@@ -416,21 +374,32 @@ var AsyncQueryBusHost = class extends AsyncQueryBusBase {
|
|
|
416
374
|
get started() {
|
|
417
375
|
return !!this._pollId;
|
|
418
376
|
}
|
|
419
|
-
expose(
|
|
420
|
-
const { failOnAlreadyExposed } = options;
|
|
421
|
-
(0,
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
377
|
+
async expose(id, options) {
|
|
378
|
+
const { failOnAlreadyExposed, required = true } = options ?? {};
|
|
379
|
+
const module2 = (0, import_module_model2.asModuleInstance)(await this.resolver.resolve(id, {
|
|
380
|
+
maxDepth: 10
|
|
381
|
+
}));
|
|
382
|
+
if (!module2 && required) {
|
|
383
|
+
throw new Error(`Unable to resolve module to expose [${id}]`);
|
|
384
|
+
}
|
|
385
|
+
if (module2) {
|
|
386
|
+
(0, import_assert3.assertEx)(!failOnAlreadyExposed || !this._exposedAddresses.has(module2.address), () => `Address already exposed: ${id} [${module2.address}]`);
|
|
387
|
+
this._exposedAddresses.add(module2.address);
|
|
388
|
+
this._exposeOptions[module2.address] = {
|
|
389
|
+
...options
|
|
390
|
+
};
|
|
391
|
+
this.logger?.debug(`${id} exposed [${module2.address}]`);
|
|
392
|
+
return module2;
|
|
393
|
+
}
|
|
427
394
|
}
|
|
428
395
|
async listeningModules() {
|
|
429
396
|
const exposedModules = [
|
|
430
397
|
...this.config?.listeningModules ?? [],
|
|
431
398
|
...this.exposedAddresses.values()
|
|
432
399
|
];
|
|
433
|
-
const mods = await Promise.all(exposedModules.map(async (
|
|
400
|
+
const mods = await Promise.all(exposedModules.map(async (exposedModule) => (0, import_assert3.assertEx)((0, import_module_model2.asModuleInstance)(await this.resolver.resolve(exposedModule, {
|
|
401
|
+
maxDepth: 10
|
|
402
|
+
})), () => `Unable to resolve listeningModule [${exposedModule}]`)));
|
|
434
403
|
return mods;
|
|
435
404
|
}
|
|
436
405
|
start() {
|
|
@@ -447,16 +416,22 @@ var AsyncQueryBusHost = class extends AsyncQueryBusBase {
|
|
|
447
416
|
(0, import_timer2.clearTimeoutEx)(this._pollId);
|
|
448
417
|
this._pollId = void 0;
|
|
449
418
|
}
|
|
450
|
-
unexpose(
|
|
451
|
-
(0,
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
419
|
+
async unexpose(id, validate = true) {
|
|
420
|
+
const module2 = (0, import_module_model2.asModuleInstance)(await this.resolver.resolve(id, {
|
|
421
|
+
maxDepth: 10
|
|
422
|
+
}));
|
|
423
|
+
if (module2) {
|
|
424
|
+
(0, import_assert3.assertEx)(!validate || this._exposedAddresses.has(module2.address), () => `Address not exposed [${module2.address}][${module2.id}]`);
|
|
425
|
+
this._exposedAddresses.delete(module2.address);
|
|
426
|
+
delete this._exposeOptions[module2.address];
|
|
427
|
+
this.logger?.debug(`${module2.address} [${module2.id}] unexposed`);
|
|
428
|
+
}
|
|
429
|
+
return module2;
|
|
455
430
|
}
|
|
456
431
|
callLocalModule = async (localModule, query) => {
|
|
457
432
|
const localModuleName = localModule.config.name ?? localModule.address;
|
|
458
|
-
const queryArchivist = (0,
|
|
459
|
-
const responsesArchivist = (0,
|
|
433
|
+
const queryArchivist = (0, import_assert3.assertEx)(await this.queriesArchivist(), () => `Unable to contact queriesArchivist [${this.config?.intersect?.queries?.archivist}]`);
|
|
434
|
+
const responsesArchivist = (0, import_assert3.assertEx)(await this.responsesArchivist(), () => `Unable to contact responsesArchivist [${this.config?.intersect?.queries?.archivist}]`);
|
|
460
435
|
const queryDestination = query.$meta?.destination;
|
|
461
436
|
if (queryDestination && queryDestination?.includes(localModule.address)) {
|
|
462
437
|
const queryIndex = query.payload_hashes.indexOf(query.query);
|
|
@@ -475,7 +450,7 @@ var AsyncQueryBusHost = class extends AsyncQueryBusBase {
|
|
|
475
450
|
this.logger?.debug(`Issuing query ${querySchema2} (${queryHash}) addressed to module: ${localModuleName}`);
|
|
476
451
|
const response = await localModule.query(query, queryPayloads, {
|
|
477
452
|
allowedQueries: this._exposeOptions[localModule.address]?.allowedQueries,
|
|
478
|
-
schema:
|
|
453
|
+
schema: import_module_model2.ModuleConfigSchema
|
|
479
454
|
});
|
|
480
455
|
const [bw, payloads, errors] = response;
|
|
481
456
|
this.logger?.debug(`Replying to query ${queryHash} addressed to module: ${localModuleName}`);
|
|
@@ -619,18 +594,18 @@ var PubSubBridgeSchema = "network.xyo.bridge.pubsub";
|
|
|
619
594
|
var PubSubBridgeConfigSchema = `${PubSubBridgeSchema}.config`;
|
|
620
595
|
|
|
621
596
|
// src/PubSubBridge.ts
|
|
622
|
-
var
|
|
597
|
+
var import_assert5 = require("@xylabs/assert");
|
|
623
598
|
var import_exists = require("@xylabs/exists");
|
|
624
599
|
var import_abstract_bridge3 = require("@xyo-network/abstract-bridge");
|
|
625
|
-
var
|
|
600
|
+
var import_module_model4 = require("@xyo-network/module-model");
|
|
626
601
|
|
|
627
602
|
// src/PubSubBridgeModuleResolver.ts
|
|
628
|
-
var
|
|
603
|
+
var import_assert4 = require("@xylabs/assert");
|
|
629
604
|
var import_hex = require("@xylabs/hex");
|
|
630
605
|
var import_abstract_bridge2 = require("@xyo-network/abstract-bridge");
|
|
631
606
|
var import_account = require("@xyo-network/account");
|
|
632
607
|
var import_config_payload_plugin = require("@xyo-network/config-payload-plugin");
|
|
633
|
-
var
|
|
608
|
+
var import_module_model3 = require("@xyo-network/module-model");
|
|
634
609
|
var PubSubBridgeModuleResolver = class extends import_abstract_bridge2.AbstractBridgeModuleResolver {
|
|
635
610
|
static {
|
|
636
611
|
__name(this, "PubSubBridgeModuleResolver");
|
|
@@ -642,14 +617,14 @@ var PubSubBridgeModuleResolver = class extends import_abstract_bridge2.AbstractB
|
|
|
642
617
|
}
|
|
643
618
|
const idParts = id.split(":");
|
|
644
619
|
const firstPart = idParts.shift();
|
|
645
|
-
(0,
|
|
620
|
+
(0, import_assert4.assertEx)((0, import_hex.isAddress)(firstPart), () => `Invalid module address: ${firstPart}`);
|
|
646
621
|
const remainderParts = idParts.join(":");
|
|
647
622
|
const account = import_account.Account.randomSync();
|
|
648
623
|
const params = {
|
|
649
624
|
account,
|
|
650
625
|
busClient: this.params.busClient,
|
|
651
626
|
config: {
|
|
652
|
-
schema:
|
|
627
|
+
schema: import_module_model3.ModuleConfigSchema
|
|
653
628
|
},
|
|
654
629
|
host: this.params.bridge,
|
|
655
630
|
moduleAddress: firstPart
|
|
@@ -659,13 +634,13 @@ var PubSubBridgeModuleResolver = class extends import_abstract_bridge2.AbstractB
|
|
|
659
634
|
const state = await proxy.state();
|
|
660
635
|
if (state) {
|
|
661
636
|
const configSchema = state.find((payload) => payload.schema === import_config_payload_plugin.ConfigSchema)?.config;
|
|
662
|
-
const config = (0,
|
|
637
|
+
const config = (0, import_assert4.assertEx)(state.find((payload) => payload.schema === configSchema), () => "Unable to locate config");
|
|
663
638
|
proxy.setConfig(config);
|
|
664
639
|
}
|
|
665
640
|
}
|
|
666
641
|
await proxy.start?.();
|
|
667
642
|
const wrapped = (0, import_abstract_bridge2.wrapModuleWithType)(proxy, account);
|
|
668
|
-
const as = (0,
|
|
643
|
+
const as = (0, import_assert4.assertEx)((0, import_module_model3.asModuleInstance)(wrapped, {}), () => `Failed to asModuleInstance [${id}]`);
|
|
669
644
|
proxy.upResolver.add(as);
|
|
670
645
|
proxy.downResolver.add(as);
|
|
671
646
|
this.add(as);
|
|
@@ -704,7 +679,7 @@ var PubSubBridge = class extends import_abstract_bridge3.AbstractBridge {
|
|
|
704
679
|
get resolver() {
|
|
705
680
|
this._resolver = this._resolver ?? new PubSubBridgeModuleResolver({
|
|
706
681
|
bridge: this,
|
|
707
|
-
busClient: (0,
|
|
682
|
+
busClient: (0, import_assert5.assertEx)(this.busClient(), () => "busClient not configured"),
|
|
708
683
|
wrapperAccount: this.account
|
|
709
684
|
});
|
|
710
685
|
return this._resolver;
|
|
@@ -713,7 +688,7 @@ var PubSubBridge = class extends import_abstract_bridge3.AbstractBridge {
|
|
|
713
688
|
return `${this.config.name ?? moduleName}`;
|
|
714
689
|
}
|
|
715
690
|
get roots() {
|
|
716
|
-
return (0,
|
|
691
|
+
return (0, import_assert5.assertEx)(this.config.roots, () => "roots not configured");
|
|
717
692
|
}
|
|
718
693
|
async discoverRoots() {
|
|
719
694
|
const rootInstances = (await Promise.all(this.roots.map(async (root) => await this.resolver.resolve(root)))).filter(import_exists.exists);
|
|
@@ -723,22 +698,24 @@ var PubSubBridge = class extends import_abstract_bridge3.AbstractBridge {
|
|
|
723
698
|
return rootInstances;
|
|
724
699
|
}
|
|
725
700
|
async exposeHandler(id, options) {
|
|
726
|
-
const { maxDepth = 2, direction = "all" } = options ?? {};
|
|
727
|
-
const
|
|
701
|
+
const { maxDepth = 2, direction = "all", required = true } = options ?? {};
|
|
702
|
+
const host = (0, import_assert5.assertEx)(this.busHost(), () => "Not configured as a host");
|
|
703
|
+
const module2 = await host.expose(id, {
|
|
704
|
+
required
|
|
705
|
+
});
|
|
728
706
|
if (module2) {
|
|
729
|
-
const
|
|
730
|
-
host.expose(module2.address);
|
|
731
|
-
const children = await module2.resolve("*", {
|
|
707
|
+
const children = maxDepth > 0 ? await module2.resolve("*", {
|
|
732
708
|
direction,
|
|
733
709
|
maxDepth,
|
|
734
710
|
visibility: "public"
|
|
735
|
-
});
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
711
|
+
}) : [];
|
|
712
|
+
const exposedChildren = (await Promise.all(children.map((child) => this.exposeHandler(child.address, {
|
|
713
|
+
maxDepth: maxDepth - 1,
|
|
714
|
+
required: false
|
|
715
|
+
})))).flat().filter(import_exists.exists);
|
|
739
716
|
return [
|
|
740
717
|
module2,
|
|
741
|
-
...
|
|
718
|
+
...exposedChildren
|
|
742
719
|
];
|
|
743
720
|
}
|
|
744
721
|
return [];
|
|
@@ -754,25 +731,22 @@ var PubSubBridge = class extends import_abstract_bridge3.AbstractBridge {
|
|
|
754
731
|
return await super.startHandler();
|
|
755
732
|
}
|
|
756
733
|
async unexposeHandler(id, options) {
|
|
757
|
-
const { maxDepth =
|
|
758
|
-
const
|
|
759
|
-
|
|
760
|
-
};
|
|
761
|
-
const module2 = await super.resolve(id, filterOptions);
|
|
734
|
+
const { maxDepth = 2, direction = "all", required = true } = options ?? {};
|
|
735
|
+
const host = (0, import_assert5.assertEx)(this.busHost(), () => "Not configured as a host");
|
|
736
|
+
const module2 = await host.unexpose(id, required);
|
|
762
737
|
if (module2) {
|
|
763
|
-
const
|
|
764
|
-
host.unexpose(module2.address);
|
|
765
|
-
const children = await module2.resolve("*", {
|
|
738
|
+
const children = maxDepth > 0 ? await module2.resolve("*", {
|
|
766
739
|
direction,
|
|
767
740
|
maxDepth,
|
|
768
741
|
visibility: "public"
|
|
769
|
-
});
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
742
|
+
}) : [];
|
|
743
|
+
const exposedChildren = (await Promise.all(children.map((child) => this.unexposeHandler(child.address, {
|
|
744
|
+
maxDepth: maxDepth - 1,
|
|
745
|
+
required: false
|
|
746
|
+
})))).flat().filter(import_exists.exists);
|
|
773
747
|
return [
|
|
774
748
|
module2,
|
|
775
|
-
...
|
|
749
|
+
...exposedChildren
|
|
776
750
|
];
|
|
777
751
|
}
|
|
778
752
|
return [];
|
|
@@ -803,6 +777,6 @@ var PubSubBridge = class extends import_abstract_bridge3.AbstractBridge {
|
|
|
803
777
|
}
|
|
804
778
|
};
|
|
805
779
|
PubSubBridge = _ts_decorate([
|
|
806
|
-
(0,
|
|
780
|
+
(0, import_module_model4.creatableModule)()
|
|
807
781
|
], PubSubBridge);
|
|
808
782
|
//# sourceMappingURL=index.cjs.map
|