@xyo-network/bridge-pub-sub 2.94.16 → 2.94.18
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 -72
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.cts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.mts +7 -72
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.mts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.ts +7 -72
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.ts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.cts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.mts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.ts.map +1 -1
- package/dist/browser/index.cjs +64 -118
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +60 -114
- package/dist/browser/index.js.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.cts +7 -72
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.cts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.mts +7 -72
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.mts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.ts +7 -72
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.ts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.cts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.mts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.ts.map +1 -1
- package/dist/node/index.cjs +69 -122
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +65 -118
- package/dist/node/index.js.map +1 -1
- package/package.json +18 -18
- package/src/AsyncQueryBus/AsyncQueryBusBase.ts +58 -101
- package/src/AsyncQueryBus/AsyncQueryBusHost.ts +8 -5
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 } from "@xylabs/assert";
|
|
17
|
+
import { assertEx as assertEx2 } 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,28 +24,24 @@ 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 {
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
27
|
+
import { assertEx } from "@xylabs/assert";
|
|
28
|
+
import { Base as Base2 } from "@xylabs/object";
|
|
29
|
+
import { isArchivistInstance } from "@xyo-network/archivist-model";
|
|
30
|
+
import { isDivinerInstance } from "@xyo-network/diviner-model";
|
|
31
|
+
import { resolveModuleIdentifier, traceModuleIdentifier } from "@xyo-network/module-model";
|
|
30
32
|
import { Mutex } from "async-mutex";
|
|
31
33
|
import { LRUCache } from "lru-cache";
|
|
32
34
|
var _AsyncQueryBusBase = class _AsyncQueryBusBase extends Base2 {
|
|
33
35
|
_lastState;
|
|
34
36
|
_targetConfigs = {};
|
|
35
37
|
_targetQueries = {};
|
|
36
|
-
|
|
37
|
-
_lastQueriesDivinerAttempt;
|
|
38
|
-
_lastResponsesArchivistAttempt;
|
|
39
|
-
_lastResponsesDivinerAttempt;
|
|
38
|
+
_lastResolveAttempt = {};
|
|
40
39
|
_queriesArchivist;
|
|
41
|
-
_queriesArchivistMutex = new Mutex();
|
|
42
40
|
_queriesDiviner;
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
_reResolveDelay = 1e3 * 5;
|
|
42
|
+
_resolveMutex = new Mutex();
|
|
45
43
|
_responsesArchivist;
|
|
46
|
-
_responsesArchivistMutex = new Mutex();
|
|
47
44
|
_responsesDiviner;
|
|
48
|
-
_responsesDivinerMutex = new Mutex();
|
|
49
45
|
constructor(params) {
|
|
50
46
|
super(params);
|
|
51
47
|
}
|
|
@@ -71,96 +67,24 @@ var _AsyncQueryBusBase = class _AsyncQueryBusBase extends Base2 {
|
|
|
71
67
|
return this._lastState;
|
|
72
68
|
}
|
|
73
69
|
async queriesArchivist() {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return this._queriesArchivist;
|
|
78
|
-
}
|
|
79
|
-
if (Date.now() - (this._lastQueriesArchivistAttempt ?? 0) < this._reResolveDelay) {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
this._lastQueriesArchivistAttempt = Date.now();
|
|
83
|
-
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);
|
|
84
|
-
if (resolved) {
|
|
85
|
-
const typedResolve = asArchivistInstance(resolved);
|
|
86
|
-
if (typedResolve) {
|
|
87
|
-
return typedResolve;
|
|
88
|
-
} else {
|
|
89
|
-
(_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)}`);
|
|
90
|
-
}
|
|
91
|
-
} else {
|
|
92
|
-
(_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}]`);
|
|
93
|
-
}
|
|
94
|
-
});
|
|
70
|
+
var _a, _b, _c;
|
|
71
|
+
this._queriesArchivist = this._queriesArchivist ?? await this.resolve(assertEx((_c = (_b = (_a = this.config) == null ? void 0 : _a.intersect) == null ? void 0 : _b.queries) == null ? void 0 : _c.archivist, () => "No queries Archivist defined"), isArchivistInstance);
|
|
72
|
+
return this._queriesArchivist;
|
|
95
73
|
}
|
|
96
74
|
async queriesDiviner() {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return this._queriesDiviner;
|
|
101
|
-
}
|
|
102
|
-
if (Date.now() - (this._lastQueriesDivinerAttempt ?? 0) < this._reResolveDelay) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
this._lastQueriesDivinerAttempt = Date.now();
|
|
106
|
-
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);
|
|
107
|
-
if (resolved) {
|
|
108
|
-
const typedResolve = asDivinerInstance(resolved);
|
|
109
|
-
if (typedResolve) {
|
|
110
|
-
return typedResolve;
|
|
111
|
-
} else {
|
|
112
|
-
(_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)}`);
|
|
113
|
-
}
|
|
114
|
-
} else {
|
|
115
|
-
(_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}]`);
|
|
116
|
-
}
|
|
117
|
-
});
|
|
75
|
+
var _a, _b, _c;
|
|
76
|
+
this._queriesDiviner = this._queriesDiviner ?? await this.resolve(assertEx((_c = (_b = (_a = this.config) == null ? void 0 : _a.intersect) == null ? void 0 : _b.queries) == null ? void 0 : _c.boundWitnessDiviner, () => "No queries Diviner defined"), isDivinerInstance);
|
|
77
|
+
return this._queriesDiviner;
|
|
118
78
|
}
|
|
119
79
|
async responsesArchivist() {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
return this._responsesArchivist;
|
|
124
|
-
}
|
|
125
|
-
if (Date.now() - (this._lastResponsesArchivistAttempt ?? 0) < this._reResolveDelay) {
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
this._lastResponsesArchivistAttempt = Date.now();
|
|
129
|
-
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);
|
|
130
|
-
if (resolved) {
|
|
131
|
-
const typedResolve = asArchivistInstance(resolved);
|
|
132
|
-
if (typedResolve) {
|
|
133
|
-
return typedResolve;
|
|
134
|
-
} else {
|
|
135
|
-
(_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)}`);
|
|
136
|
-
}
|
|
137
|
-
} else {
|
|
138
|
-
(_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}]`);
|
|
139
|
-
}
|
|
140
|
-
});
|
|
80
|
+
var _a, _b, _c;
|
|
81
|
+
this._responsesArchivist = this._responsesArchivist ?? await this.resolve(assertEx((_c = (_b = (_a = this.config) == null ? void 0 : _a.intersect) == null ? void 0 : _b.responses) == null ? void 0 : _c.archivist, () => "No responses Archivist defined"), isArchivistInstance);
|
|
82
|
+
return this._responsesArchivist;
|
|
141
83
|
}
|
|
142
84
|
async responsesDiviner() {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
return this._responsesDiviner;
|
|
147
|
-
}
|
|
148
|
-
if (Date.now() - (this._lastResponsesDivinerAttempt ?? 0) < this._reResolveDelay) {
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
this._lastResponsesDivinerAttempt = Date.now();
|
|
152
|
-
const resolved = await this.resolver.resolve((_c = (_b = (_a = this.config) == null ? void 0 : _a.intersect) == null ? void 0 : _b.responses) == null ? void 0 : _c.boundWitnessDiviner);
|
|
153
|
-
if (resolved) {
|
|
154
|
-
const typedResolve = asDivinerInstance(resolved);
|
|
155
|
-
if (typedResolve) {
|
|
156
|
-
return typedResolve;
|
|
157
|
-
} else {
|
|
158
|
-
(_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)}`);
|
|
159
|
-
}
|
|
160
|
-
} else {
|
|
161
|
-
(_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}]`);
|
|
162
|
-
}
|
|
163
|
-
});
|
|
85
|
+
var _a, _b, _c;
|
|
86
|
+
this._responsesDiviner = this._responsesDiviner ?? await this.resolve(assertEx((_c = (_b = (_a = this.config) == null ? void 0 : _a.intersect) == null ? void 0 : _b.responses) == null ? void 0 : _c.boundWitnessDiviner, () => "No responses Diviner defined"), isDivinerInstance);
|
|
87
|
+
return this._responsesDiviner;
|
|
164
88
|
}
|
|
165
89
|
/**
|
|
166
90
|
* Commit the internal state of the process. This is similar
|
|
@@ -192,6 +116,28 @@ var _AsyncQueryBusBase = class _AsyncQueryBusBase extends Base2 {
|
|
|
192
116
|
return state;
|
|
193
117
|
}
|
|
194
118
|
}
|
|
119
|
+
async resolve(id, typeCheck) {
|
|
120
|
+
return await this._resolveMutex.runExclusive(async () => {
|
|
121
|
+
var _a, _b, _c;
|
|
122
|
+
if (this._queriesArchivist) {
|
|
123
|
+
return this._queriesArchivist;
|
|
124
|
+
}
|
|
125
|
+
if (Date.now() - (this._lastResolveAttempt[id] ?? 0) < this._reResolveDelay) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
this._lastResolveAttempt[id] = Date.now();
|
|
129
|
+
const resolved = await resolveModuleIdentifier(this.resolver, id);
|
|
130
|
+
if (resolved) {
|
|
131
|
+
if (typeCheck(resolved)) {
|
|
132
|
+
return resolved;
|
|
133
|
+
} else {
|
|
134
|
+
(_b = this.logger) == null ? void 0 : _b.warn(`Unable to resolve responsesDiviner as correct type [${id}][${(_a = resolved == null ? void 0 : resolved.constructor) == null ? void 0 : _a.name}]: ${resolved.id}`);
|
|
135
|
+
}
|
|
136
|
+
} else {
|
|
137
|
+
(_c = this.logger) == null ? void 0 : _c.debug(`Unable to resolve queriesArchivist [${id}] [${await traceModuleIdentifier(this.resolver, id)}]`);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
195
141
|
};
|
|
196
142
|
__name(_AsyncQueryBusBase, "AsyncQueryBusBase");
|
|
197
143
|
var AsyncQueryBusBase = _AsyncQueryBusBase;
|
|
@@ -251,7 +197,7 @@ var _AsyncQueryBusClient = class _AsyncQueryBusClient extends AsyncQueryBusBase
|
|
|
251
197
|
...query,
|
|
252
198
|
$meta
|
|
253
199
|
});
|
|
254
|
-
const queryArchivist =
|
|
200
|
+
const queryArchivist = assertEx2(await this.queriesArchivist(), () => {
|
|
255
201
|
var _a2, _b2, _c2;
|
|
256
202
|
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}]`;
|
|
257
203
|
});
|
|
@@ -388,11 +334,11 @@ var AsyncQueryBusClient = _AsyncQueryBusClient;
|
|
|
388
334
|
|
|
389
335
|
// src/AsyncQueryBus/AsyncQueryBusHost.ts
|
|
390
336
|
import { containsAll } from "@xylabs/array";
|
|
391
|
-
import { assertEx as
|
|
337
|
+
import { assertEx as assertEx3 } from "@xylabs/assert";
|
|
392
338
|
import { clearTimeoutEx as clearTimeoutEx2, setTimeoutEx as setTimeoutEx2 } from "@xylabs/timer";
|
|
393
339
|
import { isQueryBoundWitnessWithMeta } from "@xyo-network/boundwitness-model";
|
|
394
340
|
import { BoundWitnessDivinerQuerySchema as BoundWitnessDivinerQuerySchema2 } from "@xyo-network/diviner-boundwitness-model";
|
|
395
|
-
import { asModuleInstance, ModuleConfigSchema } from "@xyo-network/module-model";
|
|
341
|
+
import { asModuleInstance, ModuleConfigSchema, traceModuleIdentifier as traceModuleIdentifier2 } from "@xyo-network/module-model";
|
|
396
342
|
import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/payload-builder";
|
|
397
343
|
var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
|
|
398
344
|
_exposedAddresses = /* @__PURE__ */ new Set();
|
|
@@ -421,7 +367,7 @@ var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
|
|
|
421
367
|
throw new Error(`Unable to resolve module to expose [${id}]`);
|
|
422
368
|
}
|
|
423
369
|
if (module) {
|
|
424
|
-
|
|
370
|
+
assertEx3(!failOnAlreadyExposed || !this._exposedAddresses.has(module.address), () => `Address already exposed: ${id} [${module.address}]`);
|
|
425
371
|
this._exposedAddresses.add(module.address);
|
|
426
372
|
this._exposeOptions[module.address] = {
|
|
427
373
|
...options
|
|
@@ -436,7 +382,7 @@ var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
|
|
|
436
382
|
...((_a = this.config) == null ? void 0 : _a.listeningModules) ?? [],
|
|
437
383
|
...this.exposedAddresses.values()
|
|
438
384
|
];
|
|
439
|
-
const mods = await Promise.all(exposedModules.map(async (exposedModule) =>
|
|
385
|
+
const mods = await Promise.all(exposedModules.map(async (exposedModule) => assertEx3(asModuleInstance(await this.resolver.resolve(exposedModule, {
|
|
440
386
|
maxDepth: 10
|
|
441
387
|
})), () => `Unable to resolve listeningModule [${exposedModule}]`)));
|
|
442
388
|
return mods;
|
|
@@ -461,7 +407,7 @@ var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
|
|
|
461
407
|
maxDepth: 10
|
|
462
408
|
}));
|
|
463
409
|
if (module) {
|
|
464
|
-
|
|
410
|
+
assertEx3(!validate || this._exposedAddresses.has(module.address), () => `Address not exposed [${module.address}][${module.id}]`);
|
|
465
411
|
this._exposedAddresses.delete(module.address);
|
|
466
412
|
delete this._exposeOptions[module.address];
|
|
467
413
|
(_a = this.logger) == null ? void 0 : _a.debug(`${module.address} [${module.id}] unexposed`);
|
|
@@ -471,11 +417,11 @@ var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
|
|
|
471
417
|
callLocalModule = async (localModule, query) => {
|
|
472
418
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
473
419
|
const localModuleName = localModule.config.name ?? localModule.address;
|
|
474
|
-
const queryArchivist =
|
|
420
|
+
const queryArchivist = assertEx3(await this.queriesArchivist(), () => {
|
|
475
421
|
var _a2, _b2, _c2;
|
|
476
422
|
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}]`;
|
|
477
423
|
});
|
|
478
|
-
const responsesArchivist =
|
|
424
|
+
const responsesArchivist = assertEx3(await this.responsesArchivist(), () => {
|
|
479
425
|
var _a2, _b2, _c2;
|
|
480
426
|
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}]`;
|
|
481
427
|
});
|
|
@@ -526,8 +472,9 @@ var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
|
|
|
526
472
|
*/
|
|
527
473
|
findQueriesToAddress = async (address) => {
|
|
528
474
|
var _a, _b, _c, _d;
|
|
529
|
-
const
|
|
530
|
-
|
|
475
|
+
const queriesDivinerId = assertEx3((_c = (_b = (_a = this.config) == null ? void 0 : _a.intersect) == null ? void 0 : _b.queries) == null ? void 0 : _c.boundWitnessDiviner, () => "No queries Diviner defined");
|
|
476
|
+
const queriesBoundWitnessDiviner = await this.queriesDiviner();
|
|
477
|
+
if (queriesBoundWitnessDiviner) {
|
|
531
478
|
const timestamp = await this.retrieveState(address);
|
|
532
479
|
const destination = [
|
|
533
480
|
address
|
|
@@ -540,7 +487,7 @@ var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
|
|
|
540
487
|
sort: "asc",
|
|
541
488
|
timestamp
|
|
542
489
|
};
|
|
543
|
-
const result = await
|
|
490
|
+
const result = await queriesBoundWitnessDiviner.divine([
|
|
544
491
|
divinerQuery
|
|
545
492
|
]);
|
|
546
493
|
const queries = result.filter(isQueryBoundWitnessWithMeta);
|
|
@@ -548,7 +495,7 @@ var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
|
|
|
548
495
|
await this.commitState(address, nextState);
|
|
549
496
|
return queries;
|
|
550
497
|
} else {
|
|
551
|
-
(_d = this.logger) == null ? void 0 : _d.warn(`Unable to resolve
|
|
498
|
+
(_d = this.logger) == null ? void 0 : _d.warn(`Unable to resolve queriesBoundWitnessDiviner [${queriesDivinerId}] [${await traceModuleIdentifier2(this.resolver, queriesDivinerId)}]`);
|
|
552
499
|
}
|
|
553
500
|
};
|
|
554
501
|
/**
|
|
@@ -647,13 +594,13 @@ var PubSubBridgeSchema = "network.xyo.bridge.pubsub";
|
|
|
647
594
|
var PubSubBridgeConfigSchema = `${PubSubBridgeSchema}.config`;
|
|
648
595
|
|
|
649
596
|
// src/PubSubBridge.ts
|
|
650
|
-
import { assertEx as
|
|
597
|
+
import { assertEx as assertEx5 } from "@xylabs/assert";
|
|
651
598
|
import { exists } from "@xylabs/exists";
|
|
652
599
|
import { AbstractBridge } from "@xyo-network/abstract-bridge";
|
|
653
600
|
import { creatableModule } from "@xyo-network/module-model";
|
|
654
601
|
|
|
655
602
|
// src/PubSubBridgeModuleResolver.ts
|
|
656
|
-
import { assertEx as
|
|
603
|
+
import { assertEx as assertEx4 } from "@xylabs/assert";
|
|
657
604
|
import { isAddress } from "@xylabs/hex";
|
|
658
605
|
import { AbstractBridgeModuleResolver, wrapModuleWithType } from "@xyo-network/abstract-bridge";
|
|
659
606
|
import { Account } from "@xyo-network/account";
|
|
@@ -668,7 +615,7 @@ var _PubSubBridgeModuleResolver = class _PubSubBridgeModuleResolver extends Abst
|
|
|
668
615
|
}
|
|
669
616
|
const idParts = id.split(":");
|
|
670
617
|
const firstPart = idParts.shift();
|
|
671
|
-
|
|
618
|
+
assertEx4(isAddress(firstPart), () => `Invalid module address: ${firstPart}`);
|
|
672
619
|
const remainderParts = idParts.join(":");
|
|
673
620
|
const account = Account.randomSync();
|
|
674
621
|
const params = {
|
|
@@ -685,13 +632,13 @@ var _PubSubBridgeModuleResolver = class _PubSubBridgeModuleResolver extends Abst
|
|
|
685
632
|
const state = await proxy.state();
|
|
686
633
|
if (state) {
|
|
687
634
|
const configSchema = (_a = state.find((payload) => payload.schema === ConfigSchema)) == null ? void 0 : _a.config;
|
|
688
|
-
const config =
|
|
635
|
+
const config = assertEx4(state.find((payload) => payload.schema === configSchema), () => "Unable to locate config");
|
|
689
636
|
proxy.setConfig(config);
|
|
690
637
|
}
|
|
691
638
|
}
|
|
692
639
|
await ((_b = proxy.start) == null ? void 0 : _b.call(proxy));
|
|
693
640
|
const wrapped = wrapModuleWithType(proxy, account);
|
|
694
|
-
const as =
|
|
641
|
+
const as = assertEx4(asModuleInstance2(wrapped, {}), () => `Failed to asModuleInstance [${id}]`);
|
|
695
642
|
proxy.upResolver.add(as);
|
|
696
643
|
proxy.downResolver.add(as);
|
|
697
644
|
this.add(as);
|
|
@@ -726,7 +673,7 @@ var _PubSubBridge = class _PubSubBridge extends AbstractBridge {
|
|
|
726
673
|
get resolver() {
|
|
727
674
|
this._resolver = this._resolver ?? new PubSubBridgeModuleResolver({
|
|
728
675
|
bridge: this,
|
|
729
|
-
busClient:
|
|
676
|
+
busClient: assertEx5(this.busClient(), () => "busClient not configured"),
|
|
730
677
|
wrapperAccount: this.account
|
|
731
678
|
});
|
|
732
679
|
return this._resolver;
|
|
@@ -735,7 +682,7 @@ var _PubSubBridge = class _PubSubBridge extends AbstractBridge {
|
|
|
735
682
|
return `${this.config.name ?? moduleName}`;
|
|
736
683
|
}
|
|
737
684
|
get roots() {
|
|
738
|
-
return
|
|
685
|
+
return assertEx5(this.config.roots, () => "roots not configured");
|
|
739
686
|
}
|
|
740
687
|
async discoverRoots() {
|
|
741
688
|
const rootInstances = (await Promise.all(this.roots.map(async (root) => await this.resolver.resolve(root)))).filter(exists);
|
|
@@ -746,7 +693,7 @@ var _PubSubBridge = class _PubSubBridge extends AbstractBridge {
|
|
|
746
693
|
}
|
|
747
694
|
async exposeHandler(id, options) {
|
|
748
695
|
const { maxDepth = 2, direction = "all", required = true } = options ?? {};
|
|
749
|
-
const host =
|
|
696
|
+
const host = assertEx5(this.busHost(), () => "Not configured as a host");
|
|
750
697
|
const module = await host.expose(id, {
|
|
751
698
|
required
|
|
752
699
|
});
|
|
@@ -781,7 +728,7 @@ var _PubSubBridge = class _PubSubBridge extends AbstractBridge {
|
|
|
781
728
|
}
|
|
782
729
|
async unexposeHandler(id, options) {
|
|
783
730
|
const { maxDepth = 2, direction = "all", required = true } = options ?? {};
|
|
784
|
-
const host =
|
|
731
|
+
const host = assertEx5(this.busHost(), () => "Not configured as a host");
|
|
785
732
|
const module = await host.unexpose(id, required);
|
|
786
733
|
if (module) {
|
|
787
734
|
const children = maxDepth > 0 ? await module.resolve("*", {
|