@xyo-network/bridge-pub-sub 2.94.10 → 2.94.12
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 +66 -6
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.cts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.mts +66 -6
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.mts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.ts +66 -6
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.ts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusClient.d.cts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusClient.d.mts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusClient.d.ts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.cts +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.cts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.mts +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.mts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.ts +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.ts.map +1 -1
- package/dist/browser/index.cjs +133 -91
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +133 -91
- package/dist/browser/index.js.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.cts +66 -6
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.cts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.mts +66 -6
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.mts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.ts +66 -6
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.ts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusClient.d.cts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusClient.d.mts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusClient.d.ts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.cts +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.cts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.mts +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.mts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.ts +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.ts.map +1 -1
- package/dist/node/index.cjs +139 -120
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +139 -120
- package/dist/node/index.js.map +1 -1
- package/package.json +18 -17
- package/src/AsyncQueryBus/AsyncQueryBusBase.ts +69 -40
- package/src/AsyncQueryBus/AsyncQueryBusClient.ts +24 -26
- package/src/AsyncQueryBus/AsyncQueryBusHost.ts +20 -19
package/dist/browser/index.js
CHANGED
|
@@ -10,7 +10,7 @@ var AbstractModuleHost = class extends Base {
|
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
// src/AsyncQueryBus/AsyncQueryBusClient.ts
|
|
13
|
-
import { assertEx
|
|
13
|
+
import { assertEx } from "@xylabs/assert";
|
|
14
14
|
import { delay } from "@xylabs/delay";
|
|
15
15
|
import { forget } from "@xylabs/forget";
|
|
16
16
|
import { clearTimeoutEx, setTimeoutEx } from "@xylabs/timer";
|
|
@@ -20,7 +20,6 @@ import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
|
20
20
|
import { LRUCache as LRUCache2 } from "lru-cache";
|
|
21
21
|
|
|
22
22
|
// src/AsyncQueryBus/AsyncQueryBusBase.ts
|
|
23
|
-
import { assertEx } from "@xylabs/assert";
|
|
24
23
|
import { Base as Base2, toJsonString } from "@xylabs/object";
|
|
25
24
|
import { asArchivistInstance } from "@xyo-network/archivist-model";
|
|
26
25
|
import { asDivinerInstance } from "@xyo-network/diviner-model";
|
|
@@ -34,13 +33,13 @@ var AsyncQueryBusBase = class extends Base2 {
|
|
|
34
33
|
_targetQueries = {};
|
|
35
34
|
_lastQueriesArchivistAttempt;
|
|
36
35
|
_lastQueriesDivinerAttempt;
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
_lastResponsesArchivistAttempt;
|
|
37
|
+
_lastResponsesDivinerAttempt;
|
|
39
38
|
_queriesArchivist;
|
|
40
39
|
_queriesDiviner;
|
|
41
|
-
_reResolveDelay =
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
_reResolveDelay = 5e4;
|
|
41
|
+
_responsesArchivist;
|
|
42
|
+
_responsesDiviner;
|
|
44
43
|
constructor(params) {
|
|
45
44
|
super(params);
|
|
46
45
|
}
|
|
@@ -68,46 +67,81 @@ var AsyncQueryBusBase = class extends Base2 {
|
|
|
68
67
|
if (this._queriesArchivist) {
|
|
69
68
|
return this._queriesArchivist;
|
|
70
69
|
}
|
|
71
|
-
if (
|
|
70
|
+
if (Date.now() - (this._lastQueriesArchivistAttempt ?? 0) < this._reResolveDelay) {
|
|
72
71
|
return;
|
|
73
72
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
73
|
+
this._lastQueriesArchivistAttempt = Date.now();
|
|
74
|
+
const resolved = await this.resolver.resolve(this.config?.intersect?.queries?.archivist);
|
|
75
|
+
if (resolved) {
|
|
76
|
+
const typedResolve = asArchivistInstance(resolved);
|
|
77
|
+
if (typedResolve) {
|
|
78
|
+
return typedResolve;
|
|
79
|
+
} else {
|
|
80
|
+
this.logger?.warn(`Unable to resolve queriesArchivist as correct type [${this.config?.intersect?.queries?.archivist}][${resolved?.constructor?.name}]: ${toJsonString(resolved)}`);
|
|
81
|
+
}
|
|
82
|
+
} else {
|
|
83
|
+
this.logger?.log(`Unable to resolve queriesArchivist [${this.config?.intersect?.queries?.archivist}]`);
|
|
84
|
+
}
|
|
81
85
|
}
|
|
82
86
|
async queriesDiviner() {
|
|
83
87
|
if (this._queriesDiviner) {
|
|
84
88
|
return this._queriesDiviner;
|
|
85
89
|
}
|
|
86
|
-
if (
|
|
90
|
+
if (Date.now() - (this._lastQueriesDivinerAttempt ?? 0) < this._reResolveDelay) {
|
|
87
91
|
return;
|
|
88
92
|
}
|
|
89
|
-
this.
|
|
90
|
-
|
|
93
|
+
this._lastQueriesDivinerAttempt = Date.now();
|
|
94
|
+
const resolved = await this.resolver.resolve(this.config?.intersect?.queries?.boundWitnessDiviner);
|
|
95
|
+
if (resolved) {
|
|
96
|
+
const typedResolve = asDivinerInstance(resolved);
|
|
97
|
+
if (typedResolve) {
|
|
98
|
+
return typedResolve;
|
|
99
|
+
} else {
|
|
100
|
+
this.logger?.warn(`Unable to resolve queriesDiviner as correct type [${this.config?.intersect?.queries?.boundWitnessDiviner}][${resolved?.constructor?.name}]: ${toJsonString(resolved)}`);
|
|
101
|
+
}
|
|
102
|
+
} else {
|
|
103
|
+
this.logger?.log(`Unable to resolve queriesDiviner [${this.config?.intersect?.queries?.boundWitnessDiviner}]`);
|
|
104
|
+
}
|
|
91
105
|
}
|
|
92
106
|
async responsesArchivist() {
|
|
93
|
-
if (this.
|
|
94
|
-
return this.
|
|
107
|
+
if (this._responsesArchivist) {
|
|
108
|
+
return this._responsesArchivist;
|
|
95
109
|
}
|
|
96
|
-
if (
|
|
110
|
+
if (Date.now() - (this._lastResponsesArchivistAttempt ?? 0) < this._reResolveDelay) {
|
|
97
111
|
return;
|
|
98
112
|
}
|
|
99
|
-
this.
|
|
100
|
-
|
|
113
|
+
this._lastResponsesArchivistAttempt = Date.now();
|
|
114
|
+
const resolved = await this.resolver.resolve(this.config?.intersect?.responses?.archivist);
|
|
115
|
+
if (resolved) {
|
|
116
|
+
const typedResolve = asArchivistInstance(resolved);
|
|
117
|
+
if (typedResolve) {
|
|
118
|
+
return typedResolve;
|
|
119
|
+
} else {
|
|
120
|
+
this.logger?.warn(`Unable to resolve responseArchivist as correct type [${this.config?.intersect?.responses?.archivist}][${resolved?.constructor?.name}]: ${toJsonString(resolved)}`);
|
|
121
|
+
}
|
|
122
|
+
} else {
|
|
123
|
+
this.logger?.log(`Unable to resolve responseArchivist [${this.config?.intersect?.responses?.archivist}]`);
|
|
124
|
+
}
|
|
101
125
|
}
|
|
102
126
|
async responsesDiviner() {
|
|
103
|
-
if (this.
|
|
104
|
-
return this.
|
|
127
|
+
if (this._responsesDiviner) {
|
|
128
|
+
return this._responsesDiviner;
|
|
105
129
|
}
|
|
106
|
-
if (
|
|
130
|
+
if (Date.now() - (this._lastResponsesDivinerAttempt ?? 0) < this._reResolveDelay) {
|
|
107
131
|
return;
|
|
108
132
|
}
|
|
109
|
-
this.
|
|
110
|
-
|
|
133
|
+
this._lastResponsesDivinerAttempt = Date.now();
|
|
134
|
+
const resolved = await this.resolver.resolve(this.config?.intersect?.responses?.boundWitnessDiviner);
|
|
135
|
+
if (resolved) {
|
|
136
|
+
const typedResolve = asDivinerInstance(resolved);
|
|
137
|
+
if (typedResolve) {
|
|
138
|
+
return typedResolve;
|
|
139
|
+
} else {
|
|
140
|
+
this.logger?.warn(`Unable to resolve responsesDiviner as correct type [${this.config?.intersect?.responses?.boundWitnessDiviner}][${resolved?.constructor?.name}]: ${toJsonString(resolved)}`);
|
|
141
|
+
}
|
|
142
|
+
} else {
|
|
143
|
+
this.logger?.log(`Unable to resolve responsesDiviner [${this.config?.intersect?.responses?.boundWitnessDiviner}]`);
|
|
144
|
+
}
|
|
111
145
|
}
|
|
112
146
|
/**
|
|
113
147
|
* Commit the internal state of the process. This is similar
|
|
@@ -196,7 +230,7 @@ var AsyncQueryBusClient = class extends AsyncQueryBusBase {
|
|
|
196
230
|
...query,
|
|
197
231
|
$meta
|
|
198
232
|
});
|
|
199
|
-
const queryArchivist =
|
|
233
|
+
const queryArchivist = assertEx(await this.queriesArchivist(), () => `Unable to contact queriesArchivist [${this.config?.intersect?.queries?.archivist}]`);
|
|
200
234
|
const routedQueryHash = (
|
|
201
235
|
// Trust the signed hash if it's there
|
|
202
236
|
routedQuery?.$hash ?? // TODO: What is the right way to find the dataHash
|
|
@@ -272,34 +306,38 @@ var AsyncQueryBusClient = class extends AsyncQueryBusBase {
|
|
|
272
306
|
* Background process for processing incoming responses to previously issued queries
|
|
273
307
|
*/
|
|
274
308
|
processIncomingResponses = async () => {
|
|
275
|
-
const responseArchivist =
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
const response = result.find(isBoundWitnessWithMeta);
|
|
291
|
-
if (response && response?.$meta?.sourceQuery === sourceQuery) {
|
|
292
|
-
this.logger?.debug(`Found response to query: ${sourceQuery}`);
|
|
293
|
-
const payloads = response.payload_hashes?.length > 0 ? await responseArchivist.get(response.payload_hashes) : [];
|
|
294
|
-
this.queryCache.set(sourceQuery, [
|
|
295
|
-
response,
|
|
296
|
-
payloads,
|
|
297
|
-
[]
|
|
309
|
+
const responseArchivist = await this.responsesArchivist();
|
|
310
|
+
if (responseArchivist) {
|
|
311
|
+
const responseBoundWitnessDiviner = await this.responsesDiviner();
|
|
312
|
+
if (responseBoundWitnessDiviner) {
|
|
313
|
+
const pendingCommands = [
|
|
314
|
+
...this.queryCache.entries()
|
|
315
|
+
].filter(([_, status]) => status === Pending);
|
|
316
|
+
await Promise.allSettled(pendingCommands.map(async ([sourceQuery, status]) => {
|
|
317
|
+
if (status === Pending) {
|
|
318
|
+
const divinerQuery = {
|
|
319
|
+
schema: BoundWitnessDivinerQuerySchema,
|
|
320
|
+
sourceQuery
|
|
321
|
+
};
|
|
322
|
+
const result = await responseBoundWitnessDiviner.divine([
|
|
323
|
+
divinerQuery
|
|
298
324
|
]);
|
|
325
|
+
if (result && result.length > 0) {
|
|
326
|
+
const response = result.find(isBoundWitnessWithMeta);
|
|
327
|
+
if (response && response?.$meta?.sourceQuery === sourceQuery) {
|
|
328
|
+
this.logger?.debug(`Found response to query: ${sourceQuery}`);
|
|
329
|
+
const payloads = response.payload_hashes?.length > 0 ? await responseArchivist.get(response.payload_hashes) : [];
|
|
330
|
+
this.queryCache.set(sourceQuery, [
|
|
331
|
+
response,
|
|
332
|
+
payloads,
|
|
333
|
+
[]
|
|
334
|
+
]);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
299
337
|
}
|
|
300
|
-
}
|
|
338
|
+
}));
|
|
301
339
|
}
|
|
302
|
-
}
|
|
340
|
+
}
|
|
303
341
|
};
|
|
304
342
|
start() {
|
|
305
343
|
if (this._pollCount === 0) {
|
|
@@ -320,7 +358,7 @@ var AsyncQueryBusClient = class extends AsyncQueryBusBase {
|
|
|
320
358
|
|
|
321
359
|
// src/AsyncQueryBus/AsyncQueryBusHost.ts
|
|
322
360
|
import { containsAll } from "@xylabs/array";
|
|
323
|
-
import { assertEx as
|
|
361
|
+
import { assertEx as assertEx2 } from "@xylabs/assert";
|
|
324
362
|
import { clearTimeoutEx as clearTimeoutEx2, setTimeoutEx as setTimeoutEx2 } from "@xylabs/timer";
|
|
325
363
|
import { isQueryBoundWitnessWithMeta } from "@xyo-network/boundwitness-model";
|
|
326
364
|
import { BoundWitnessDivinerQuerySchema as BoundWitnessDivinerQuerySchema2 } from "@xyo-network/diviner-boundwitness-model";
|
|
@@ -347,7 +385,7 @@ var AsyncQueryBusHost = class extends AsyncQueryBusBase {
|
|
|
347
385
|
}
|
|
348
386
|
expose(address, options = {}) {
|
|
349
387
|
const { failOnAlreadyExposed } = options;
|
|
350
|
-
|
|
388
|
+
assertEx2(!failOnAlreadyExposed || !this._exposedAddresses.has(address), () => `Address already exposed [${address}]`);
|
|
351
389
|
this._exposedAddresses.add(address);
|
|
352
390
|
this._exposeOptions[address] = {
|
|
353
391
|
...options
|
|
@@ -359,7 +397,7 @@ var AsyncQueryBusHost = class extends AsyncQueryBusBase {
|
|
|
359
397
|
...this.config?.listeningModules ?? [],
|
|
360
398
|
...this.exposedAddresses.values()
|
|
361
399
|
];
|
|
362
|
-
const mods = await Promise.all(exposedModules.map(async (listeningModule) =>
|
|
400
|
+
const mods = await Promise.all(exposedModules.map(async (listeningModule) => assertEx2(asModuleInstance(await this.resolver.resolve(listeningModule)), () => `Unable to resolve listeningModule [${listeningModule}]`)));
|
|
363
401
|
return mods;
|
|
364
402
|
}
|
|
365
403
|
start() {
|
|
@@ -377,15 +415,15 @@ var AsyncQueryBusHost = class extends AsyncQueryBusBase {
|
|
|
377
415
|
this._pollId = void 0;
|
|
378
416
|
}
|
|
379
417
|
unexpose(address, validate = true) {
|
|
380
|
-
|
|
418
|
+
assertEx2(!validate || this._exposedAddresses.has(address), () => `Address not exposed [${address}]`);
|
|
381
419
|
this._exposedAddresses.delete(address);
|
|
382
420
|
delete this._exposeOptions[address];
|
|
383
421
|
this.logger?.debug(`${address} unexposed`);
|
|
384
422
|
}
|
|
385
423
|
callLocalModule = async (localModule, query) => {
|
|
386
424
|
const localModuleName = localModule.config.name ?? localModule.address;
|
|
387
|
-
const queryArchivist =
|
|
388
|
-
const responsesArchivist =
|
|
425
|
+
const queryArchivist = assertEx2(await this.queriesArchivist(), () => `Unable to contact queriesArchivist [${this.config?.intersect?.queries?.archivist}]`);
|
|
426
|
+
const responsesArchivist = assertEx2(await this.responsesArchivist(), () => `Unable to contact responsesArchivist [${this.config?.intersect?.queries?.archivist}]`);
|
|
389
427
|
const queryDestination = query.$meta?.destination;
|
|
390
428
|
if (queryDestination && queryDestination?.includes(localModule.address)) {
|
|
391
429
|
const queryIndex = query.payload_hashes.indexOf(query.query);
|
|
@@ -432,26 +470,30 @@ var AsyncQueryBusHost = class extends AsyncQueryBusBase {
|
|
|
432
470
|
* @param address The address to find commands for
|
|
433
471
|
*/
|
|
434
472
|
findQueriesToAddress = async (address) => {
|
|
435
|
-
const queryBoundWitnessDiviner =
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
473
|
+
const queryBoundWitnessDiviner = await this.queriesDiviner();
|
|
474
|
+
if (queryBoundWitnessDiviner) {
|
|
475
|
+
const timestamp = await this.retrieveState(address);
|
|
476
|
+
const destination = [
|
|
477
|
+
address
|
|
478
|
+
];
|
|
479
|
+
const limit = this.perAddressBatchQueryLimit;
|
|
480
|
+
const divinerQuery = {
|
|
481
|
+
destination,
|
|
482
|
+
limit,
|
|
483
|
+
schema: BoundWitnessDivinerQuerySchema2,
|
|
484
|
+
sort: "asc",
|
|
485
|
+
timestamp
|
|
486
|
+
};
|
|
487
|
+
const result = await queryBoundWitnessDiviner.divine([
|
|
488
|
+
divinerQuery
|
|
489
|
+
]);
|
|
490
|
+
const queries = result.filter(isQueryBoundWitnessWithMeta);
|
|
491
|
+
const nextState = queries.length > 0 ? Math.max(...queries.map((c) => c.timestamp ?? 0)) + 1 : timestamp;
|
|
492
|
+
await this.commitState(address, nextState);
|
|
493
|
+
return queries;
|
|
494
|
+
} else {
|
|
495
|
+
this.logger?.warn(`Unable to resolve queryBoundWitnessDiviner [${this.config?.intersect?.queries?.boundWitnessDiviner}]`);
|
|
496
|
+
}
|
|
455
497
|
};
|
|
456
498
|
/**
|
|
457
499
|
* Runs the background divine process on a loop with a delay
|
|
@@ -481,7 +523,7 @@ var AsyncQueryBusHost = class extends AsyncQueryBusBase {
|
|
|
481
523
|
try {
|
|
482
524
|
const localModuleName = localModule.config.name ?? localModule.address;
|
|
483
525
|
this.logger?.debug(`Checking for inbound queries to ${localModuleName} [${localModule.address}]`);
|
|
484
|
-
const queries = await this.findQueriesToAddress(localModule.address);
|
|
526
|
+
const queries = await this.findQueriesToAddress(localModule.address) ?? [];
|
|
485
527
|
if (queries.length === 0)
|
|
486
528
|
return;
|
|
487
529
|
this.logger?.debug(`Found queries addressed to local module: ${localModuleName}`);
|
|
@@ -544,13 +586,13 @@ var PubSubBridgeSchema = "network.xyo.bridge.pubsub";
|
|
|
544
586
|
var PubSubBridgeConfigSchema = `${PubSubBridgeSchema}.config`;
|
|
545
587
|
|
|
546
588
|
// src/PubSubBridge.ts
|
|
547
|
-
import { assertEx as
|
|
589
|
+
import { assertEx as assertEx4 } from "@xylabs/assert";
|
|
548
590
|
import { exists } from "@xylabs/exists";
|
|
549
591
|
import { AbstractBridge } from "@xyo-network/abstract-bridge";
|
|
550
592
|
import { creatableModule } from "@xyo-network/module-model";
|
|
551
593
|
|
|
552
594
|
// src/PubSubBridgeModuleResolver.ts
|
|
553
|
-
import { assertEx as
|
|
595
|
+
import { assertEx as assertEx3 } from "@xylabs/assert";
|
|
554
596
|
import { isAddress } from "@xylabs/hex";
|
|
555
597
|
import { AbstractBridgeModuleResolver, wrapModuleWithType } from "@xyo-network/abstract-bridge";
|
|
556
598
|
import { Account } from "@xyo-network/account";
|
|
@@ -567,7 +609,7 @@ var PubSubBridgeModuleResolver = class extends AbstractBridgeModuleResolver {
|
|
|
567
609
|
}
|
|
568
610
|
const idParts = id.split(":");
|
|
569
611
|
const firstPart = idParts.shift();
|
|
570
|
-
|
|
612
|
+
assertEx3(isAddress(firstPart), () => `Invalid module address: ${firstPart}`);
|
|
571
613
|
const remainderParts = idParts.join(":");
|
|
572
614
|
const account = Account.randomSync();
|
|
573
615
|
const params = {
|
|
@@ -584,13 +626,13 @@ var PubSubBridgeModuleResolver = class extends AbstractBridgeModuleResolver {
|
|
|
584
626
|
const state = await proxy.state();
|
|
585
627
|
if (state) {
|
|
586
628
|
const configSchema = state.find((payload) => payload.schema === ConfigSchema)?.config;
|
|
587
|
-
const config =
|
|
629
|
+
const config = assertEx3(state.find((payload) => payload.schema === configSchema), () => "Unable to locate config");
|
|
588
630
|
proxy.setConfig(config);
|
|
589
631
|
}
|
|
590
632
|
}
|
|
591
633
|
await proxy.start?.();
|
|
592
634
|
const wrapped = wrapModuleWithType(proxy, account);
|
|
593
|
-
const as =
|
|
635
|
+
const as = assertEx3(asModuleInstance2(wrapped, {}), () => `Failed to asModuleInstance [${id}]`);
|
|
594
636
|
proxy.upResolver.add(as);
|
|
595
637
|
proxy.downResolver.add(as);
|
|
596
638
|
this.add(as);
|
|
@@ -629,7 +671,7 @@ var PubSubBridge = class extends AbstractBridge {
|
|
|
629
671
|
get resolver() {
|
|
630
672
|
this._resolver = this._resolver ?? new PubSubBridgeModuleResolver({
|
|
631
673
|
bridge: this,
|
|
632
|
-
busClient:
|
|
674
|
+
busClient: assertEx4(this.busClient(), () => "busClient not configured"),
|
|
633
675
|
wrapperAccount: this.account
|
|
634
676
|
});
|
|
635
677
|
return this._resolver;
|
|
@@ -638,7 +680,7 @@ var PubSubBridge = class extends AbstractBridge {
|
|
|
638
680
|
return `${this.config.name ?? moduleName}`;
|
|
639
681
|
}
|
|
640
682
|
get roots() {
|
|
641
|
-
return
|
|
683
|
+
return assertEx4(this.config.roots, () => "roots not configured");
|
|
642
684
|
}
|
|
643
685
|
async discoverRoots() {
|
|
644
686
|
const rootInstances = (await Promise.all(this.roots.map(async (root) => await this.resolver.resolve(root)))).filter(exists);
|
|
@@ -649,9 +691,9 @@ var PubSubBridge = class extends AbstractBridge {
|
|
|
649
691
|
}
|
|
650
692
|
async exposeHandler(id, options) {
|
|
651
693
|
const { maxDepth = 2, direction = "all" } = options ?? {};
|
|
652
|
-
const module =
|
|
694
|
+
const module = assertEx4(await super.resolve(id), () => `Expose failed to locate module [${id}]`);
|
|
653
695
|
if (module) {
|
|
654
|
-
const host =
|
|
696
|
+
const host = assertEx4(this.busHost(), () => "Not configured as a host");
|
|
655
697
|
host.expose(module.address);
|
|
656
698
|
const children = await module.resolve("*", {
|
|
657
699
|
direction,
|
|
@@ -685,7 +727,7 @@ var PubSubBridge = class extends AbstractBridge {
|
|
|
685
727
|
};
|
|
686
728
|
const module = await super.resolve(id, filterOptions);
|
|
687
729
|
if (module) {
|
|
688
|
-
const host =
|
|
730
|
+
const host = assertEx4(this.busHost(), () => "Not configured as a host");
|
|
689
731
|
host.unexpose(module.address);
|
|
690
732
|
const children = await module.resolve("*", {
|
|
691
733
|
direction,
|