@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.
- 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/PubSubBridgeModuleResolver.d.cts +3 -3
- package/dist/browser/PubSubBridgeModuleResolver.d.cts.map +1 -1
- package/dist/browser/PubSubBridgeModuleResolver.d.mts +3 -3
- package/dist/browser/PubSubBridgeModuleResolver.d.mts.map +1 -1
- package/dist/browser/PubSubBridgeModuleResolver.d.ts +3 -3
- package/dist/browser/PubSubBridgeModuleResolver.d.ts.map +1 -1
- package/dist/browser/index.cjs +135 -93
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +135 -93
- 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/PubSubBridgeModuleResolver.d.cts +3 -3
- package/dist/node/PubSubBridgeModuleResolver.d.cts.map +1 -1
- package/dist/node/PubSubBridgeModuleResolver.d.mts +3 -3
- package/dist/node/PubSubBridgeModuleResolver.d.mts.map +1 -1
- package/dist/node/PubSubBridgeModuleResolver.d.ts +3 -3
- package/dist/node/PubSubBridgeModuleResolver.d.ts.map +1 -1
- package/dist/node/index.cjs +141 -122
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +141 -122
- 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/src/PubSubBridgeModuleResolver.ts +5 -5
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_assert = 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,7 +53,6 @@ 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");
|
|
57
56
|
var import_object2 = require("@xylabs/object");
|
|
58
57
|
var import_archivist_model = require("@xyo-network/archivist-model");
|
|
59
58
|
var import_diviner_model = require("@xyo-network/diviner-model");
|
|
@@ -67,13 +66,13 @@ var AsyncQueryBusBase = class extends import_object2.Base {
|
|
|
67
66
|
_targetQueries = {};
|
|
68
67
|
_lastQueriesArchivistAttempt;
|
|
69
68
|
_lastQueriesDivinerAttempt;
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
_lastResponsesArchivistAttempt;
|
|
70
|
+
_lastResponsesDivinerAttempt;
|
|
72
71
|
_queriesArchivist;
|
|
73
72
|
_queriesDiviner;
|
|
74
|
-
_reResolveDelay =
|
|
75
|
-
|
|
76
|
-
|
|
73
|
+
_reResolveDelay = 5e4;
|
|
74
|
+
_responsesArchivist;
|
|
75
|
+
_responsesDiviner;
|
|
77
76
|
constructor(params) {
|
|
78
77
|
super(params);
|
|
79
78
|
}
|
|
@@ -101,46 +100,81 @@ var AsyncQueryBusBase = class extends import_object2.Base {
|
|
|
101
100
|
if (this._queriesArchivist) {
|
|
102
101
|
return this._queriesArchivist;
|
|
103
102
|
}
|
|
104
|
-
if (
|
|
103
|
+
if (Date.now() - (this._lastQueriesArchivistAttempt ?? 0) < this._reResolveDelay) {
|
|
105
104
|
return;
|
|
106
105
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
+
}
|
|
114
118
|
}
|
|
115
119
|
async queriesDiviner() {
|
|
116
120
|
if (this._queriesDiviner) {
|
|
117
121
|
return this._queriesDiviner;
|
|
118
122
|
}
|
|
119
|
-
if (
|
|
123
|
+
if (Date.now() - (this._lastQueriesDivinerAttempt ?? 0) < this._reResolveDelay) {
|
|
120
124
|
return;
|
|
121
125
|
}
|
|
122
|
-
this.
|
|
123
|
-
|
|
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
|
+
}
|
|
124
138
|
}
|
|
125
139
|
async responsesArchivist() {
|
|
126
|
-
if (this.
|
|
127
|
-
return this.
|
|
140
|
+
if (this._responsesArchivist) {
|
|
141
|
+
return this._responsesArchivist;
|
|
128
142
|
}
|
|
129
|
-
if (
|
|
143
|
+
if (Date.now() - (this._lastResponsesArchivistAttempt ?? 0) < this._reResolveDelay) {
|
|
130
144
|
return;
|
|
131
145
|
}
|
|
132
|
-
this.
|
|
133
|
-
|
|
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
|
+
}
|
|
134
158
|
}
|
|
135
159
|
async responsesDiviner() {
|
|
136
|
-
if (this.
|
|
137
|
-
return this.
|
|
160
|
+
if (this._responsesDiviner) {
|
|
161
|
+
return this._responsesDiviner;
|
|
138
162
|
}
|
|
139
|
-
if (
|
|
163
|
+
if (Date.now() - (this._lastResponsesDivinerAttempt ?? 0) < this._reResolveDelay) {
|
|
140
164
|
return;
|
|
141
165
|
}
|
|
142
|
-
this.
|
|
143
|
-
|
|
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
|
+
}
|
|
144
178
|
}
|
|
145
179
|
/**
|
|
146
180
|
* Commit the internal state of the process. This is similar
|
|
@@ -229,7 +263,7 @@ var AsyncQueryBusClient = class extends AsyncQueryBusBase {
|
|
|
229
263
|
...query,
|
|
230
264
|
$meta
|
|
231
265
|
});
|
|
232
|
-
const queryArchivist = (0,
|
|
266
|
+
const queryArchivist = (0, import_assert.assertEx)(await this.queriesArchivist(), () => `Unable to contact queriesArchivist [${this.config?.intersect?.queries?.archivist}]`);
|
|
233
267
|
const routedQueryHash = (
|
|
234
268
|
// Trust the signed hash if it's there
|
|
235
269
|
routedQuery?.$hash ?? // TODO: What is the right way to find the dataHash
|
|
@@ -305,34 +339,38 @@ var AsyncQueryBusClient = class extends AsyncQueryBusBase {
|
|
|
305
339
|
* Background process for processing incoming responses to previously issued queries
|
|
306
340
|
*/
|
|
307
341
|
processIncomingResponses = async () => {
|
|
308
|
-
const responseArchivist =
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
const response = result.find(import_boundwitness_model.isBoundWitnessWithMeta);
|
|
324
|
-
if (response && response?.$meta?.sourceQuery === sourceQuery) {
|
|
325
|
-
this.logger?.debug(`Found response to query: ${sourceQuery}`);
|
|
326
|
-
const payloads = response.payload_hashes?.length > 0 ? await responseArchivist.get(response.payload_hashes) : [];
|
|
327
|
-
this.queryCache.set(sourceQuery, [
|
|
328
|
-
response,
|
|
329
|
-
payloads,
|
|
330
|
-
[]
|
|
342
|
+
const responseArchivist = await this.responsesArchivist();
|
|
343
|
+
if (responseArchivist) {
|
|
344
|
+
const responseBoundWitnessDiviner = await this.responsesDiviner();
|
|
345
|
+
if (responseBoundWitnessDiviner) {
|
|
346
|
+
const pendingCommands = [
|
|
347
|
+
...this.queryCache.entries()
|
|
348
|
+
].filter(([_, status]) => status === Pending);
|
|
349
|
+
await Promise.allSettled(pendingCommands.map(async ([sourceQuery, status]) => {
|
|
350
|
+
if (status === Pending) {
|
|
351
|
+
const divinerQuery = {
|
|
352
|
+
schema: import_diviner_boundwitness_model.BoundWitnessDivinerQuerySchema,
|
|
353
|
+
sourceQuery
|
|
354
|
+
};
|
|
355
|
+
const result = await responseBoundWitnessDiviner.divine([
|
|
356
|
+
divinerQuery
|
|
331
357
|
]);
|
|
358
|
+
if (result && result.length > 0) {
|
|
359
|
+
const response = result.find(import_boundwitness_model.isBoundWitnessWithMeta);
|
|
360
|
+
if (response && response?.$meta?.sourceQuery === sourceQuery) {
|
|
361
|
+
this.logger?.debug(`Found response to query: ${sourceQuery}`);
|
|
362
|
+
const payloads = response.payload_hashes?.length > 0 ? await responseArchivist.get(response.payload_hashes) : [];
|
|
363
|
+
this.queryCache.set(sourceQuery, [
|
|
364
|
+
response,
|
|
365
|
+
payloads,
|
|
366
|
+
[]
|
|
367
|
+
]);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
332
370
|
}
|
|
333
|
-
}
|
|
371
|
+
}));
|
|
334
372
|
}
|
|
335
|
-
}
|
|
373
|
+
}
|
|
336
374
|
};
|
|
337
375
|
start() {
|
|
338
376
|
if (this._pollCount === 0) {
|
|
@@ -353,7 +391,7 @@ var AsyncQueryBusClient = class extends AsyncQueryBusBase {
|
|
|
353
391
|
|
|
354
392
|
// src/AsyncQueryBus/AsyncQueryBusHost.ts
|
|
355
393
|
var import_array = require("@xylabs/array");
|
|
356
|
-
var
|
|
394
|
+
var import_assert2 = require("@xylabs/assert");
|
|
357
395
|
var import_timer2 = require("@xylabs/timer");
|
|
358
396
|
var import_boundwitness_model2 = require("@xyo-network/boundwitness-model");
|
|
359
397
|
var import_diviner_boundwitness_model2 = require("@xyo-network/diviner-boundwitness-model");
|
|
@@ -380,7 +418,7 @@ var AsyncQueryBusHost = class extends AsyncQueryBusBase {
|
|
|
380
418
|
}
|
|
381
419
|
expose(address, options = {}) {
|
|
382
420
|
const { failOnAlreadyExposed } = options;
|
|
383
|
-
(0,
|
|
421
|
+
(0, import_assert2.assertEx)(!failOnAlreadyExposed || !this._exposedAddresses.has(address), () => `Address already exposed [${address}]`);
|
|
384
422
|
this._exposedAddresses.add(address);
|
|
385
423
|
this._exposeOptions[address] = {
|
|
386
424
|
...options
|
|
@@ -392,7 +430,7 @@ var AsyncQueryBusHost = class extends AsyncQueryBusBase {
|
|
|
392
430
|
...this.config?.listeningModules ?? [],
|
|
393
431
|
...this.exposedAddresses.values()
|
|
394
432
|
];
|
|
395
|
-
const mods = await Promise.all(exposedModules.map(async (listeningModule) => (0,
|
|
433
|
+
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}]`)));
|
|
396
434
|
return mods;
|
|
397
435
|
}
|
|
398
436
|
start() {
|
|
@@ -410,15 +448,15 @@ var AsyncQueryBusHost = class extends AsyncQueryBusBase {
|
|
|
410
448
|
this._pollId = void 0;
|
|
411
449
|
}
|
|
412
450
|
unexpose(address, validate = true) {
|
|
413
|
-
(0,
|
|
451
|
+
(0, import_assert2.assertEx)(!validate || this._exposedAddresses.has(address), () => `Address not exposed [${address}]`);
|
|
414
452
|
this._exposedAddresses.delete(address);
|
|
415
453
|
delete this._exposeOptions[address];
|
|
416
454
|
this.logger?.debug(`${address} unexposed`);
|
|
417
455
|
}
|
|
418
456
|
callLocalModule = async (localModule, query) => {
|
|
419
457
|
const localModuleName = localModule.config.name ?? localModule.address;
|
|
420
|
-
const queryArchivist = (0,
|
|
421
|
-
const responsesArchivist = (0,
|
|
458
|
+
const queryArchivist = (0, import_assert2.assertEx)(await this.queriesArchivist(), () => `Unable to contact queriesArchivist [${this.config?.intersect?.queries?.archivist}]`);
|
|
459
|
+
const responsesArchivist = (0, import_assert2.assertEx)(await this.responsesArchivist(), () => `Unable to contact responsesArchivist [${this.config?.intersect?.queries?.archivist}]`);
|
|
422
460
|
const queryDestination = query.$meta?.destination;
|
|
423
461
|
if (queryDestination && queryDestination?.includes(localModule.address)) {
|
|
424
462
|
const queryIndex = query.payload_hashes.indexOf(query.query);
|
|
@@ -465,26 +503,30 @@ var AsyncQueryBusHost = class extends AsyncQueryBusBase {
|
|
|
465
503
|
* @param address The address to find commands for
|
|
466
504
|
*/
|
|
467
505
|
findQueriesToAddress = async (address) => {
|
|
468
|
-
const queryBoundWitnessDiviner =
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
506
|
+
const queryBoundWitnessDiviner = await this.queriesDiviner();
|
|
507
|
+
if (queryBoundWitnessDiviner) {
|
|
508
|
+
const timestamp = await this.retrieveState(address);
|
|
509
|
+
const destination = [
|
|
510
|
+
address
|
|
511
|
+
];
|
|
512
|
+
const limit = this.perAddressBatchQueryLimit;
|
|
513
|
+
const divinerQuery = {
|
|
514
|
+
destination,
|
|
515
|
+
limit,
|
|
516
|
+
schema: import_diviner_boundwitness_model2.BoundWitnessDivinerQuerySchema,
|
|
517
|
+
sort: "asc",
|
|
518
|
+
timestamp
|
|
519
|
+
};
|
|
520
|
+
const result = await queryBoundWitnessDiviner.divine([
|
|
521
|
+
divinerQuery
|
|
522
|
+
]);
|
|
523
|
+
const queries = result.filter(import_boundwitness_model2.isQueryBoundWitnessWithMeta);
|
|
524
|
+
const nextState = queries.length > 0 ? Math.max(...queries.map((c) => c.timestamp ?? 0)) + 1 : timestamp;
|
|
525
|
+
await this.commitState(address, nextState);
|
|
526
|
+
return queries;
|
|
527
|
+
} else {
|
|
528
|
+
this.logger?.warn(`Unable to resolve queryBoundWitnessDiviner [${this.config?.intersect?.queries?.boundWitnessDiviner}]`);
|
|
529
|
+
}
|
|
488
530
|
};
|
|
489
531
|
/**
|
|
490
532
|
* Runs the background divine process on a loop with a delay
|
|
@@ -514,7 +556,7 @@ var AsyncQueryBusHost = class extends AsyncQueryBusBase {
|
|
|
514
556
|
try {
|
|
515
557
|
const localModuleName = localModule.config.name ?? localModule.address;
|
|
516
558
|
this.logger?.debug(`Checking for inbound queries to ${localModuleName} [${localModule.address}]`);
|
|
517
|
-
const queries = await this.findQueriesToAddress(localModule.address);
|
|
559
|
+
const queries = await this.findQueriesToAddress(localModule.address) ?? [];
|
|
518
560
|
if (queries.length === 0)
|
|
519
561
|
return;
|
|
520
562
|
this.logger?.debug(`Found queries addressed to local module: ${localModuleName}`);
|
|
@@ -577,13 +619,13 @@ var PubSubBridgeSchema = "network.xyo.bridge.pubsub";
|
|
|
577
619
|
var PubSubBridgeConfigSchema = `${PubSubBridgeSchema}.config`;
|
|
578
620
|
|
|
579
621
|
// src/PubSubBridge.ts
|
|
580
|
-
var
|
|
622
|
+
var import_assert4 = require("@xylabs/assert");
|
|
581
623
|
var import_exists = require("@xylabs/exists");
|
|
582
624
|
var import_abstract_bridge3 = require("@xyo-network/abstract-bridge");
|
|
583
625
|
var import_module_model3 = require("@xyo-network/module-model");
|
|
584
626
|
|
|
585
627
|
// src/PubSubBridgeModuleResolver.ts
|
|
586
|
-
var
|
|
628
|
+
var import_assert3 = require("@xylabs/assert");
|
|
587
629
|
var import_hex = require("@xylabs/hex");
|
|
588
630
|
var import_abstract_bridge2 = require("@xyo-network/abstract-bridge");
|
|
589
631
|
var import_account = require("@xyo-network/account");
|
|
@@ -600,16 +642,16 @@ var PubSubBridgeModuleResolver = class extends import_abstract_bridge2.AbstractB
|
|
|
600
642
|
}
|
|
601
643
|
const idParts = id.split(":");
|
|
602
644
|
const firstPart = idParts.shift();
|
|
603
|
-
(0,
|
|
645
|
+
(0, import_assert3.assertEx)((0, import_hex.isAddress)(firstPart), () => `Invalid module address: ${firstPart}`);
|
|
604
646
|
const remainderParts = idParts.join(":");
|
|
605
647
|
const account = import_account.Account.randomSync();
|
|
606
648
|
const params = {
|
|
607
649
|
account,
|
|
608
|
-
busClient: this.
|
|
650
|
+
busClient: this.params.busClient,
|
|
609
651
|
config: {
|
|
610
652
|
schema: import_module_model2.ModuleConfigSchema
|
|
611
653
|
},
|
|
612
|
-
host: this.
|
|
654
|
+
host: this.params.bridge,
|
|
613
655
|
moduleAddress: firstPart
|
|
614
656
|
};
|
|
615
657
|
const proxy = new AsyncQueryBusModuleProxy(params);
|
|
@@ -617,13 +659,13 @@ var PubSubBridgeModuleResolver = class extends import_abstract_bridge2.AbstractB
|
|
|
617
659
|
const state = await proxy.state();
|
|
618
660
|
if (state) {
|
|
619
661
|
const configSchema = state.find((payload) => payload.schema === import_config_payload_plugin.ConfigSchema)?.config;
|
|
620
|
-
const config = (0,
|
|
662
|
+
const config = (0, import_assert3.assertEx)(state.find((payload) => payload.schema === configSchema), () => "Unable to locate config");
|
|
621
663
|
proxy.setConfig(config);
|
|
622
664
|
}
|
|
623
665
|
}
|
|
624
666
|
await proxy.start?.();
|
|
625
667
|
const wrapped = (0, import_abstract_bridge2.wrapModuleWithType)(proxy, account);
|
|
626
|
-
const as = (0,
|
|
668
|
+
const as = (0, import_assert3.assertEx)((0, import_module_model2.asModuleInstance)(wrapped, {}), () => `Failed to asModuleInstance [${id}]`);
|
|
627
669
|
proxy.upResolver.add(as);
|
|
628
670
|
proxy.downResolver.add(as);
|
|
629
671
|
this.add(as);
|
|
@@ -662,7 +704,7 @@ var PubSubBridge = class extends import_abstract_bridge3.AbstractBridge {
|
|
|
662
704
|
get resolver() {
|
|
663
705
|
this._resolver = this._resolver ?? new PubSubBridgeModuleResolver({
|
|
664
706
|
bridge: this,
|
|
665
|
-
busClient: (0,
|
|
707
|
+
busClient: (0, import_assert4.assertEx)(this.busClient(), () => "busClient not configured"),
|
|
666
708
|
wrapperAccount: this.account
|
|
667
709
|
});
|
|
668
710
|
return this._resolver;
|
|
@@ -671,7 +713,7 @@ var PubSubBridge = class extends import_abstract_bridge3.AbstractBridge {
|
|
|
671
713
|
return `${this.config.name ?? moduleName}`;
|
|
672
714
|
}
|
|
673
715
|
get roots() {
|
|
674
|
-
return (0,
|
|
716
|
+
return (0, import_assert4.assertEx)(this.config.roots, () => "roots not configured");
|
|
675
717
|
}
|
|
676
718
|
async discoverRoots() {
|
|
677
719
|
const rootInstances = (await Promise.all(this.roots.map(async (root) => await this.resolver.resolve(root)))).filter(import_exists.exists);
|
|
@@ -682,9 +724,9 @@ var PubSubBridge = class extends import_abstract_bridge3.AbstractBridge {
|
|
|
682
724
|
}
|
|
683
725
|
async exposeHandler(id, options) {
|
|
684
726
|
const { maxDepth = 2, direction = "all" } = options ?? {};
|
|
685
|
-
const module2 = (0,
|
|
727
|
+
const module2 = (0, import_assert4.assertEx)(await super.resolve(id), () => `Expose failed to locate module [${id}]`);
|
|
686
728
|
if (module2) {
|
|
687
|
-
const host = (0,
|
|
729
|
+
const host = (0, import_assert4.assertEx)(this.busHost(), () => "Not configured as a host");
|
|
688
730
|
host.expose(module2.address);
|
|
689
731
|
const children = await module2.resolve("*", {
|
|
690
732
|
direction,
|
|
@@ -718,7 +760,7 @@ var PubSubBridge = class extends import_abstract_bridge3.AbstractBridge {
|
|
|
718
760
|
};
|
|
719
761
|
const module2 = await super.resolve(id, filterOptions);
|
|
720
762
|
if (module2) {
|
|
721
|
-
const host = (0,
|
|
763
|
+
const host = (0, import_assert4.assertEx)(this.busHost(), () => "Not configured as a host");
|
|
722
764
|
host.unexpose(module2.address);
|
|
723
765
|
const children = await module2.resolve("*", {
|
|
724
766
|
direction,
|