@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/node/index.js
CHANGED
|
@@ -14,7 +14,7 @@ __name(_AbstractModuleHost, "AbstractModuleHost");
|
|
|
14
14
|
var AbstractModuleHost = _AbstractModuleHost;
|
|
15
15
|
|
|
16
16
|
// src/AsyncQueryBus/AsyncQueryBusClient.ts
|
|
17
|
-
import { assertEx
|
|
17
|
+
import { assertEx } 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,7 +24,6 @@ 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 { assertEx } from "@xylabs/assert";
|
|
28
27
|
import { Base as Base2, toJsonString } from "@xylabs/object";
|
|
29
28
|
import { asArchivistInstance } from "@xyo-network/archivist-model";
|
|
30
29
|
import { asDivinerInstance } from "@xyo-network/diviner-model";
|
|
@@ -35,13 +34,13 @@ var _AsyncQueryBusBase = class _AsyncQueryBusBase extends Base2 {
|
|
|
35
34
|
_targetQueries = {};
|
|
36
35
|
_lastQueriesArchivistAttempt;
|
|
37
36
|
_lastQueriesDivinerAttempt;
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
_lastResponsesArchivistAttempt;
|
|
38
|
+
_lastResponsesDivinerAttempt;
|
|
40
39
|
_queriesArchivist;
|
|
41
40
|
_queriesDiviner;
|
|
42
|
-
_reResolveDelay =
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
_reResolveDelay = 5e4;
|
|
42
|
+
_responsesArchivist;
|
|
43
|
+
_responsesDiviner;
|
|
45
44
|
constructor(params) {
|
|
46
45
|
super(params);
|
|
47
46
|
}
|
|
@@ -67,68 +66,88 @@ var _AsyncQueryBusBase = class _AsyncQueryBusBase extends Base2 {
|
|
|
67
66
|
return this._lastState;
|
|
68
67
|
}
|
|
69
68
|
async queriesArchivist() {
|
|
70
|
-
var _a, _b, _c;
|
|
69
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
71
70
|
if (this._queriesArchivist) {
|
|
72
71
|
return this._queriesArchivist;
|
|
73
72
|
}
|
|
74
|
-
if (
|
|
73
|
+
if (Date.now() - (this._lastQueriesArchivistAttempt ?? 0) < this._reResolveDelay) {
|
|
75
74
|
return;
|
|
76
75
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
return result;
|
|
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
|
+
}
|
|
90
88
|
}
|
|
91
89
|
async queriesDiviner() {
|
|
92
|
-
var _a, _b, _c;
|
|
90
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
93
91
|
if (this._queriesDiviner) {
|
|
94
92
|
return this._queriesDiviner;
|
|
95
93
|
}
|
|
96
|
-
if (
|
|
94
|
+
if (Date.now() - (this._lastQueriesDivinerAttempt ?? 0) < this._reResolveDelay) {
|
|
97
95
|
return;
|
|
98
96
|
}
|
|
99
|
-
this.
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
+
}
|
|
104
109
|
}
|
|
105
110
|
async responsesArchivist() {
|
|
106
|
-
var _a, _b, _c;
|
|
107
|
-
if (this.
|
|
108
|
-
return this.
|
|
111
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
112
|
+
if (this._responsesArchivist) {
|
|
113
|
+
return this._responsesArchivist;
|
|
109
114
|
}
|
|
110
|
-
if (
|
|
115
|
+
if (Date.now() - (this._lastResponsesArchivistAttempt ?? 0) < this._reResolveDelay) {
|
|
111
116
|
return;
|
|
112
117
|
}
|
|
113
|
-
this.
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
+
}
|
|
118
130
|
}
|
|
119
131
|
async responsesDiviner() {
|
|
120
|
-
var _a, _b, _c;
|
|
121
|
-
if (this.
|
|
122
|
-
return this.
|
|
132
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
133
|
+
if (this._responsesDiviner) {
|
|
134
|
+
return this._responsesDiviner;
|
|
123
135
|
}
|
|
124
|
-
if (
|
|
136
|
+
if (Date.now() - (this._lastResponsesDivinerAttempt ?? 0) < this._reResolveDelay) {
|
|
125
137
|
return;
|
|
126
138
|
}
|
|
127
|
-
this.
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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
|
+
}
|
|
132
151
|
}
|
|
133
152
|
/**
|
|
134
153
|
* Commit the internal state of the process. This is similar
|
|
@@ -219,7 +238,7 @@ var _AsyncQueryBusClient = class _AsyncQueryBusClient extends AsyncQueryBusBase
|
|
|
219
238
|
...query,
|
|
220
239
|
$meta
|
|
221
240
|
});
|
|
222
|
-
const queryArchivist =
|
|
241
|
+
const queryArchivist = assertEx(await this.queriesArchivist(), () => {
|
|
223
242
|
var _a2, _b2, _c2;
|
|
224
243
|
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}]`;
|
|
225
244
|
});
|
|
@@ -301,41 +320,39 @@ var _AsyncQueryBusClient = class _AsyncQueryBusClient extends AsyncQueryBusBase
|
|
|
301
320
|
* Background process for processing incoming responses to previously issued queries
|
|
302
321
|
*/
|
|
303
322
|
processIncomingResponses = async () => {
|
|
304
|
-
const responseArchivist =
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
sourceQuery
|
|
321
|
-
};
|
|
322
|
-
const result = await responseBoundWitnessDiviner.divine([
|
|
323
|
-
divinerQuery
|
|
324
|
-
]);
|
|
325
|
-
if (result && result.length > 0) {
|
|
326
|
-
const response = result.find(isBoundWitnessWithMeta);
|
|
327
|
-
if (response && ((_a = response == null ? void 0 : response.$meta) == null ? void 0 : _a.sourceQuery) === sourceQuery) {
|
|
328
|
-
(_b = this.logger) == null ? void 0 : _b.debug(`Found response to query: ${sourceQuery}`);
|
|
329
|
-
const payloads = ((_c = response.payload_hashes) == null ? void 0 : _c.length) > 0 ? await responseArchivist.get(response.payload_hashes) : [];
|
|
330
|
-
this.queryCache.set(sourceQuery, [
|
|
331
|
-
response,
|
|
332
|
-
payloads,
|
|
333
|
-
[]
|
|
323
|
+
const responseArchivist = await this.responsesArchivist();
|
|
324
|
+
if (responseArchivist) {
|
|
325
|
+
const responseBoundWitnessDiviner = await this.responsesDiviner();
|
|
326
|
+
if (responseBoundWitnessDiviner) {
|
|
327
|
+
const pendingCommands = [
|
|
328
|
+
...this.queryCache.entries()
|
|
329
|
+
].filter(([_, status]) => status === Pending);
|
|
330
|
+
await Promise.allSettled(pendingCommands.map(async ([sourceQuery, status]) => {
|
|
331
|
+
var _a, _b, _c;
|
|
332
|
+
if (status === Pending) {
|
|
333
|
+
const divinerQuery = {
|
|
334
|
+
schema: BoundWitnessDivinerQuerySchema,
|
|
335
|
+
sourceQuery
|
|
336
|
+
};
|
|
337
|
+
const result = await responseBoundWitnessDiviner.divine([
|
|
338
|
+
divinerQuery
|
|
334
339
|
]);
|
|
340
|
+
if (result && result.length > 0) {
|
|
341
|
+
const response = result.find(isBoundWitnessWithMeta);
|
|
342
|
+
if (response && ((_a = response == null ? void 0 : response.$meta) == null ? void 0 : _a.sourceQuery) === sourceQuery) {
|
|
343
|
+
(_b = this.logger) == null ? void 0 : _b.debug(`Found response to query: ${sourceQuery}`);
|
|
344
|
+
const payloads = ((_c = response.payload_hashes) == null ? void 0 : _c.length) > 0 ? await responseArchivist.get(response.payload_hashes) : [];
|
|
345
|
+
this.queryCache.set(sourceQuery, [
|
|
346
|
+
response,
|
|
347
|
+
payloads,
|
|
348
|
+
[]
|
|
349
|
+
]);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
335
352
|
}
|
|
336
|
-
}
|
|
353
|
+
}));
|
|
337
354
|
}
|
|
338
|
-
}
|
|
355
|
+
}
|
|
339
356
|
};
|
|
340
357
|
start() {
|
|
341
358
|
if (this._pollCount === 0) {
|
|
@@ -358,7 +375,7 @@ var AsyncQueryBusClient = _AsyncQueryBusClient;
|
|
|
358
375
|
|
|
359
376
|
// src/AsyncQueryBus/AsyncQueryBusHost.ts
|
|
360
377
|
import { containsAll } from "@xylabs/array";
|
|
361
|
-
import { assertEx as
|
|
378
|
+
import { assertEx as assertEx2 } from "@xylabs/assert";
|
|
362
379
|
import { clearTimeoutEx as clearTimeoutEx2, setTimeoutEx as setTimeoutEx2 } from "@xylabs/timer";
|
|
363
380
|
import { isQueryBoundWitnessWithMeta } from "@xyo-network/boundwitness-model";
|
|
364
381
|
import { BoundWitnessDivinerQuerySchema as BoundWitnessDivinerQuerySchema2 } from "@xyo-network/diviner-boundwitness-model";
|
|
@@ -384,7 +401,7 @@ var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
|
|
|
384
401
|
expose(address, options = {}) {
|
|
385
402
|
var _a;
|
|
386
403
|
const { failOnAlreadyExposed } = options;
|
|
387
|
-
|
|
404
|
+
assertEx2(!failOnAlreadyExposed || !this._exposedAddresses.has(address), () => `Address already exposed [${address}]`);
|
|
388
405
|
this._exposedAddresses.add(address);
|
|
389
406
|
this._exposeOptions[address] = {
|
|
390
407
|
...options
|
|
@@ -397,7 +414,7 @@ var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
|
|
|
397
414
|
...((_a = this.config) == null ? void 0 : _a.listeningModules) ?? [],
|
|
398
415
|
...this.exposedAddresses.values()
|
|
399
416
|
];
|
|
400
|
-
const mods = await Promise.all(exposedModules.map(async (listeningModule) =>
|
|
417
|
+
const mods = await Promise.all(exposedModules.map(async (listeningModule) => assertEx2(asModuleInstance(await this.resolver.resolve(listeningModule)), () => `Unable to resolve listeningModule [${listeningModule}]`)));
|
|
401
418
|
return mods;
|
|
402
419
|
}
|
|
403
420
|
start() {
|
|
@@ -416,7 +433,7 @@ var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
|
|
|
416
433
|
}
|
|
417
434
|
unexpose(address, validate = true) {
|
|
418
435
|
var _a;
|
|
419
|
-
|
|
436
|
+
assertEx2(!validate || this._exposedAddresses.has(address), () => `Address not exposed [${address}]`);
|
|
420
437
|
this._exposedAddresses.delete(address);
|
|
421
438
|
delete this._exposeOptions[address];
|
|
422
439
|
(_a = this.logger) == null ? void 0 : _a.debug(`${address} unexposed`);
|
|
@@ -424,11 +441,11 @@ var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
|
|
|
424
441
|
callLocalModule = async (localModule, query) => {
|
|
425
442
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
426
443
|
const localModuleName = localModule.config.name ?? localModule.address;
|
|
427
|
-
const queryArchivist =
|
|
444
|
+
const queryArchivist = assertEx2(await this.queriesArchivist(), () => {
|
|
428
445
|
var _a2, _b2, _c2;
|
|
429
446
|
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}]`;
|
|
430
447
|
});
|
|
431
|
-
const responsesArchivist =
|
|
448
|
+
const responsesArchivist = assertEx2(await this.responsesArchivist(), () => {
|
|
432
449
|
var _a2, _b2, _c2;
|
|
433
450
|
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}]`;
|
|
434
451
|
});
|
|
@@ -478,29 +495,31 @@ var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
|
|
|
478
495
|
* @param address The address to find commands for
|
|
479
496
|
*/
|
|
480
497
|
findQueriesToAddress = async (address) => {
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
498
|
+
var _a, _b, _c, _d;
|
|
499
|
+
const queryBoundWitnessDiviner = await this.queriesDiviner();
|
|
500
|
+
if (queryBoundWitnessDiviner) {
|
|
501
|
+
const timestamp = await this.retrieveState(address);
|
|
502
|
+
const destination = [
|
|
503
|
+
address
|
|
504
|
+
];
|
|
505
|
+
const limit = this.perAddressBatchQueryLimit;
|
|
506
|
+
const divinerQuery = {
|
|
507
|
+
destination,
|
|
508
|
+
limit,
|
|
509
|
+
schema: BoundWitnessDivinerQuerySchema2,
|
|
510
|
+
sort: "asc",
|
|
511
|
+
timestamp
|
|
512
|
+
};
|
|
513
|
+
const result = await queryBoundWitnessDiviner.divine([
|
|
514
|
+
divinerQuery
|
|
515
|
+
]);
|
|
516
|
+
const queries = result.filter(isQueryBoundWitnessWithMeta);
|
|
517
|
+
const nextState = queries.length > 0 ? Math.max(...queries.map((c) => c.timestamp ?? 0)) + 1 : timestamp;
|
|
518
|
+
await this.commitState(address, nextState);
|
|
519
|
+
return queries;
|
|
520
|
+
} else {
|
|
521
|
+
(_d = this.logger) == null ? void 0 : _d.warn(`Unable to resolve queryBoundWitnessDiviner [${(_c = (_b = (_a = this.config) == null ? void 0 : _a.intersect) == null ? void 0 : _b.queries) == null ? void 0 : _c.boundWitnessDiviner}]`);
|
|
522
|
+
}
|
|
504
523
|
};
|
|
505
524
|
/**
|
|
506
525
|
* Runs the background divine process on a loop with a delay
|
|
@@ -533,7 +552,7 @@ var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
|
|
|
533
552
|
try {
|
|
534
553
|
const localModuleName = localModule.config.name ?? localModule.address;
|
|
535
554
|
(_a2 = this.logger) == null ? void 0 : _a2.debug(`Checking for inbound queries to ${localModuleName} [${localModule.address}]`);
|
|
536
|
-
const queries = await this.findQueriesToAddress(localModule.address);
|
|
555
|
+
const queries = await this.findQueriesToAddress(localModule.address) ?? [];
|
|
537
556
|
if (queries.length === 0)
|
|
538
557
|
return;
|
|
539
558
|
(_b = this.logger) == null ? void 0 : _b.debug(`Found queries addressed to local module: ${localModuleName}`);
|
|
@@ -598,13 +617,13 @@ var PubSubBridgeSchema = "network.xyo.bridge.pubsub";
|
|
|
598
617
|
var PubSubBridgeConfigSchema = `${PubSubBridgeSchema}.config`;
|
|
599
618
|
|
|
600
619
|
// src/PubSubBridge.ts
|
|
601
|
-
import { assertEx as
|
|
620
|
+
import { assertEx as assertEx4 } from "@xylabs/assert";
|
|
602
621
|
import { exists } from "@xylabs/exists";
|
|
603
622
|
import { AbstractBridge } from "@xyo-network/abstract-bridge";
|
|
604
623
|
import { creatableModule } from "@xyo-network/module-model";
|
|
605
624
|
|
|
606
625
|
// src/PubSubBridgeModuleResolver.ts
|
|
607
|
-
import { assertEx as
|
|
626
|
+
import { assertEx as assertEx3 } from "@xylabs/assert";
|
|
608
627
|
import { isAddress } from "@xylabs/hex";
|
|
609
628
|
import { AbstractBridgeModuleResolver, wrapModuleWithType } from "@xyo-network/abstract-bridge";
|
|
610
629
|
import { Account } from "@xyo-network/account";
|
|
@@ -619,7 +638,7 @@ var _PubSubBridgeModuleResolver = class _PubSubBridgeModuleResolver extends Abst
|
|
|
619
638
|
}
|
|
620
639
|
const idParts = id.split(":");
|
|
621
640
|
const firstPart = idParts.shift();
|
|
622
|
-
|
|
641
|
+
assertEx3(isAddress(firstPart), () => `Invalid module address: ${firstPart}`);
|
|
623
642
|
const remainderParts = idParts.join(":");
|
|
624
643
|
const account = Account.randomSync();
|
|
625
644
|
const params = {
|
|
@@ -636,13 +655,13 @@ var _PubSubBridgeModuleResolver = class _PubSubBridgeModuleResolver extends Abst
|
|
|
636
655
|
const state = await proxy.state();
|
|
637
656
|
if (state) {
|
|
638
657
|
const configSchema = (_a = state.find((payload) => payload.schema === ConfigSchema)) == null ? void 0 : _a.config;
|
|
639
|
-
const config =
|
|
658
|
+
const config = assertEx3(state.find((payload) => payload.schema === configSchema), () => "Unable to locate config");
|
|
640
659
|
proxy.setConfig(config);
|
|
641
660
|
}
|
|
642
661
|
}
|
|
643
662
|
await ((_b = proxy.start) == null ? void 0 : _b.call(proxy));
|
|
644
663
|
const wrapped = wrapModuleWithType(proxy, account);
|
|
645
|
-
const as =
|
|
664
|
+
const as = assertEx3(asModuleInstance2(wrapped, {}), () => `Failed to asModuleInstance [${id}]`);
|
|
646
665
|
proxy.upResolver.add(as);
|
|
647
666
|
proxy.downResolver.add(as);
|
|
648
667
|
this.add(as);
|
|
@@ -677,7 +696,7 @@ var _PubSubBridge = class _PubSubBridge extends AbstractBridge {
|
|
|
677
696
|
get resolver() {
|
|
678
697
|
this._resolver = this._resolver ?? new PubSubBridgeModuleResolver({
|
|
679
698
|
bridge: this,
|
|
680
|
-
busClient:
|
|
699
|
+
busClient: assertEx4(this.busClient(), () => "busClient not configured"),
|
|
681
700
|
wrapperAccount: this.account
|
|
682
701
|
});
|
|
683
702
|
return this._resolver;
|
|
@@ -686,7 +705,7 @@ var _PubSubBridge = class _PubSubBridge extends AbstractBridge {
|
|
|
686
705
|
return `${this.config.name ?? moduleName}`;
|
|
687
706
|
}
|
|
688
707
|
get roots() {
|
|
689
|
-
return
|
|
708
|
+
return assertEx4(this.config.roots, () => "roots not configured");
|
|
690
709
|
}
|
|
691
710
|
async discoverRoots() {
|
|
692
711
|
const rootInstances = (await Promise.all(this.roots.map(async (root) => await this.resolver.resolve(root)))).filter(exists);
|
|
@@ -697,9 +716,9 @@ var _PubSubBridge = class _PubSubBridge extends AbstractBridge {
|
|
|
697
716
|
}
|
|
698
717
|
async exposeHandler(id, options) {
|
|
699
718
|
const { maxDepth = 2, direction = "all" } = options ?? {};
|
|
700
|
-
const module =
|
|
719
|
+
const module = assertEx4(await super.resolve(id), () => `Expose failed to locate module [${id}]`);
|
|
701
720
|
if (module) {
|
|
702
|
-
const host =
|
|
721
|
+
const host = assertEx4(this.busHost(), () => "Not configured as a host");
|
|
703
722
|
host.expose(module.address);
|
|
704
723
|
const children = await module.resolve("*", {
|
|
705
724
|
direction,
|
|
@@ -735,7 +754,7 @@ var _PubSubBridge = class _PubSubBridge extends AbstractBridge {
|
|
|
735
754
|
};
|
|
736
755
|
const module = await super.resolve(id, filterOptions);
|
|
737
756
|
if (module) {
|
|
738
|
-
const host =
|
|
757
|
+
const host = assertEx4(this.busHost(), () => "Not configured as a host");
|
|
739
758
|
host.unexpose(module.address);
|
|
740
759
|
const children = await module.resolve("*", {
|
|
741
760
|
direction,
|