@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/node/index.cjs
CHANGED
|
@@ -47,7 +47,7 @@ __name(_AbstractModuleHost, "AbstractModuleHost");
|
|
|
47
47
|
var AbstractModuleHost = _AbstractModuleHost;
|
|
48
48
|
|
|
49
49
|
// src/AsyncQueryBus/AsyncQueryBusClient.ts
|
|
50
|
-
var
|
|
50
|
+
var import_assert2 = require("@xylabs/assert");
|
|
51
51
|
var import_delay = require("@xylabs/delay");
|
|
52
52
|
var import_forget = require("@xylabs/forget");
|
|
53
53
|
var import_timer = require("@xylabs/timer");
|
|
@@ -57,21 +57,22 @@ var import_payload_builder = require("@xyo-network/payload-builder");
|
|
|
57
57
|
var import_lru_cache2 = require("lru-cache");
|
|
58
58
|
|
|
59
59
|
// src/AsyncQueryBus/AsyncQueryBusBase.ts
|
|
60
|
+
var import_assert = require("@xylabs/assert");
|
|
60
61
|
var import_object2 = require("@xylabs/object");
|
|
61
62
|
var import_archivist_model = require("@xyo-network/archivist-model");
|
|
62
63
|
var import_diviner_model = require("@xyo-network/diviner-model");
|
|
64
|
+
var import_module_model = require("@xyo-network/module-model");
|
|
65
|
+
var import_async_mutex = require("async-mutex");
|
|
63
66
|
var import_lru_cache = require("lru-cache");
|
|
64
67
|
var _AsyncQueryBusBase = class _AsyncQueryBusBase extends import_object2.Base {
|
|
65
68
|
_lastState;
|
|
66
69
|
_targetConfigs = {};
|
|
67
70
|
_targetQueries = {};
|
|
68
|
-
|
|
69
|
-
_lastQueriesDivinerAttempt;
|
|
70
|
-
_lastResponsesArchivistAttempt;
|
|
71
|
-
_lastResponsesDivinerAttempt;
|
|
71
|
+
_lastResolveAttempt = {};
|
|
72
72
|
_queriesArchivist;
|
|
73
73
|
_queriesDiviner;
|
|
74
|
-
_reResolveDelay =
|
|
74
|
+
_reResolveDelay = 1e3 * 5;
|
|
75
|
+
_resolveMutex = new import_async_mutex.Mutex();
|
|
75
76
|
_responsesArchivist;
|
|
76
77
|
_responsesDiviner;
|
|
77
78
|
constructor(params) {
|
|
@@ -99,88 +100,24 @@ var _AsyncQueryBusBase = class _AsyncQueryBusBase extends import_object2.Base {
|
|
|
99
100
|
return this._lastState;
|
|
100
101
|
}
|
|
101
102
|
async queriesArchivist() {
|
|
102
|
-
var _a, _b, _c
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
if (Date.now() - (this._lastQueriesArchivistAttempt ?? 0) < this._reResolveDelay) {
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
this._lastQueriesArchivistAttempt = Date.now();
|
|
110
|
-
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);
|
|
111
|
-
if (resolved) {
|
|
112
|
-
const typedResolve = (0, import_archivist_model.asArchivistInstance)(resolved);
|
|
113
|
-
if (typedResolve) {
|
|
114
|
-
return typedResolve;
|
|
115
|
-
} else {
|
|
116
|
-
(_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}]: ${(0, import_object2.toJsonString)(resolved)}`);
|
|
117
|
-
}
|
|
118
|
-
} else {
|
|
119
|
-
(_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}]`);
|
|
120
|
-
}
|
|
103
|
+
var _a, _b, _c;
|
|
104
|
+
this._queriesArchivist = this._queriesArchivist ?? await this.resolve((0, import_assert.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"), import_archivist_model.isArchivistInstance);
|
|
105
|
+
return this._queriesArchivist;
|
|
121
106
|
}
|
|
122
107
|
async queriesDiviner() {
|
|
123
|
-
var _a, _b, _c
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
if (Date.now() - (this._lastQueriesDivinerAttempt ?? 0) < this._reResolveDelay) {
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
this._lastQueriesDivinerAttempt = Date.now();
|
|
131
|
-
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);
|
|
132
|
-
if (resolved) {
|
|
133
|
-
const typedResolve = (0, import_diviner_model.asDivinerInstance)(resolved);
|
|
134
|
-
if (typedResolve) {
|
|
135
|
-
return typedResolve;
|
|
136
|
-
} else {
|
|
137
|
-
(_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}]: ${(0, import_object2.toJsonString)(resolved)}`);
|
|
138
|
-
}
|
|
139
|
-
} else {
|
|
140
|
-
(_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}]`);
|
|
141
|
-
}
|
|
108
|
+
var _a, _b, _c;
|
|
109
|
+
this._queriesDiviner = this._queriesDiviner ?? await this.resolve((0, import_assert.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"), import_diviner_model.isDivinerInstance);
|
|
110
|
+
return this._queriesDiviner;
|
|
142
111
|
}
|
|
143
112
|
async responsesArchivist() {
|
|
144
|
-
var _a, _b, _c
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
if (Date.now() - (this._lastResponsesArchivistAttempt ?? 0) < this._reResolveDelay) {
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
this._lastResponsesArchivistAttempt = 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.archivist);
|
|
153
|
-
if (resolved) {
|
|
154
|
-
const typedResolve = (0, import_archivist_model.asArchivistInstance)(resolved);
|
|
155
|
-
if (typedResolve) {
|
|
156
|
-
return typedResolve;
|
|
157
|
-
} else {
|
|
158
|
-
(_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}]: ${(0, import_object2.toJsonString)(resolved)}`);
|
|
159
|
-
}
|
|
160
|
-
} else {
|
|
161
|
-
(_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}]`);
|
|
162
|
-
}
|
|
113
|
+
var _a, _b, _c;
|
|
114
|
+
this._responsesArchivist = this._responsesArchivist ?? await this.resolve((0, import_assert.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"), import_archivist_model.isArchivistInstance);
|
|
115
|
+
return this._responsesArchivist;
|
|
163
116
|
}
|
|
164
117
|
async responsesDiviner() {
|
|
165
|
-
var _a, _b, _c
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
}
|
|
169
|
-
if (Date.now() - (this._lastResponsesDivinerAttempt ?? 0) < this._reResolveDelay) {
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
this._lastResponsesDivinerAttempt = Date.now();
|
|
173
|
-
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);
|
|
174
|
-
if (resolved) {
|
|
175
|
-
const typedResolve = (0, import_diviner_model.asDivinerInstance)(resolved);
|
|
176
|
-
if (typedResolve) {
|
|
177
|
-
return typedResolve;
|
|
178
|
-
} else {
|
|
179
|
-
(_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}]: ${(0, import_object2.toJsonString)(resolved)}`);
|
|
180
|
-
}
|
|
181
|
-
} else {
|
|
182
|
-
(_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}]`);
|
|
183
|
-
}
|
|
118
|
+
var _a, _b, _c;
|
|
119
|
+
this._responsesDiviner = this._responsesDiviner ?? await this.resolve((0, import_assert.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"), import_diviner_model.isDivinerInstance);
|
|
120
|
+
return this._responsesDiviner;
|
|
184
121
|
}
|
|
185
122
|
/**
|
|
186
123
|
* Commit the internal state of the process. This is similar
|
|
@@ -212,6 +149,28 @@ var _AsyncQueryBusBase = class _AsyncQueryBusBase extends import_object2.Base {
|
|
|
212
149
|
return state;
|
|
213
150
|
}
|
|
214
151
|
}
|
|
152
|
+
async resolve(id, typeCheck) {
|
|
153
|
+
return await this._resolveMutex.runExclusive(async () => {
|
|
154
|
+
var _a, _b, _c;
|
|
155
|
+
if (this._queriesArchivist) {
|
|
156
|
+
return this._queriesArchivist;
|
|
157
|
+
}
|
|
158
|
+
if (Date.now() - (this._lastResolveAttempt[id] ?? 0) < this._reResolveDelay) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
this._lastResolveAttempt[id] = Date.now();
|
|
162
|
+
const resolved = await this.resolver.resolve(id);
|
|
163
|
+
if (resolved) {
|
|
164
|
+
if (typeCheck(resolved)) {
|
|
165
|
+
return resolved;
|
|
166
|
+
} else {
|
|
167
|
+
(_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}`);
|
|
168
|
+
}
|
|
169
|
+
} else {
|
|
170
|
+
(_c = this.logger) == null ? void 0 : _c.log(`Unable to resolve queriesArchivist [${id}] [${await (0, import_module_model.traceModuleIdentifier)(this.resolver, id)}]`);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
}
|
|
215
174
|
};
|
|
216
175
|
__name(_AsyncQueryBusBase, "AsyncQueryBusBase");
|
|
217
176
|
var AsyncQueryBusBase = _AsyncQueryBusBase;
|
|
@@ -271,7 +230,7 @@ var _AsyncQueryBusClient = class _AsyncQueryBusClient extends AsyncQueryBusBase
|
|
|
271
230
|
...query,
|
|
272
231
|
$meta
|
|
273
232
|
});
|
|
274
|
-
const queryArchivist = (0,
|
|
233
|
+
const queryArchivist = (0, import_assert2.assertEx)(await this.queriesArchivist(), () => {
|
|
275
234
|
var _a2, _b2, _c2;
|
|
276
235
|
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}]`;
|
|
277
236
|
});
|
|
@@ -408,11 +367,11 @@ var AsyncQueryBusClient = _AsyncQueryBusClient;
|
|
|
408
367
|
|
|
409
368
|
// src/AsyncQueryBus/AsyncQueryBusHost.ts
|
|
410
369
|
var import_array = require("@xylabs/array");
|
|
411
|
-
var
|
|
370
|
+
var import_assert3 = require("@xylabs/assert");
|
|
412
371
|
var import_timer2 = require("@xylabs/timer");
|
|
413
372
|
var import_boundwitness_model2 = require("@xyo-network/boundwitness-model");
|
|
414
373
|
var import_diviner_boundwitness_model2 = require("@xyo-network/diviner-boundwitness-model");
|
|
415
|
-
var
|
|
374
|
+
var import_module_model2 = require("@xyo-network/module-model");
|
|
416
375
|
var import_payload_builder2 = require("@xyo-network/payload-builder");
|
|
417
376
|
var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
|
|
418
377
|
_exposedAddresses = /* @__PURE__ */ new Set();
|
|
@@ -431,15 +390,24 @@ var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
|
|
|
431
390
|
get started() {
|
|
432
391
|
return !!this._pollId;
|
|
433
392
|
}
|
|
434
|
-
expose(
|
|
393
|
+
async expose(id, options) {
|
|
435
394
|
var _a;
|
|
436
|
-
const { failOnAlreadyExposed } = options;
|
|
437
|
-
(0,
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
395
|
+
const { failOnAlreadyExposed, required = true } = options ?? {};
|
|
396
|
+
const module2 = (0, import_module_model2.asModuleInstance)(await this.resolver.resolve(id, {
|
|
397
|
+
maxDepth: 10
|
|
398
|
+
}));
|
|
399
|
+
if (!module2 && required) {
|
|
400
|
+
throw new Error(`Unable to resolve module to expose [${id}]`);
|
|
401
|
+
}
|
|
402
|
+
if (module2) {
|
|
403
|
+
(0, import_assert3.assertEx)(!failOnAlreadyExposed || !this._exposedAddresses.has(module2.address), () => `Address already exposed: ${id} [${module2.address}]`);
|
|
404
|
+
this._exposedAddresses.add(module2.address);
|
|
405
|
+
this._exposeOptions[module2.address] = {
|
|
406
|
+
...options
|
|
407
|
+
};
|
|
408
|
+
(_a = this.logger) == null ? void 0 : _a.debug(`${id} exposed [${module2.address}]`);
|
|
409
|
+
return module2;
|
|
410
|
+
}
|
|
443
411
|
}
|
|
444
412
|
async listeningModules() {
|
|
445
413
|
var _a;
|
|
@@ -447,7 +415,9 @@ var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
|
|
|
447
415
|
...((_a = this.config) == null ? void 0 : _a.listeningModules) ?? [],
|
|
448
416
|
...this.exposedAddresses.values()
|
|
449
417
|
];
|
|
450
|
-
const mods = await Promise.all(exposedModules.map(async (
|
|
418
|
+
const mods = await Promise.all(exposedModules.map(async (exposedModule) => (0, import_assert3.assertEx)((0, import_module_model2.asModuleInstance)(await this.resolver.resolve(exposedModule, {
|
|
419
|
+
maxDepth: 10
|
|
420
|
+
})), () => `Unable to resolve listeningModule [${exposedModule}]`)));
|
|
451
421
|
return mods;
|
|
452
422
|
}
|
|
453
423
|
start() {
|
|
@@ -464,21 +434,27 @@ var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
|
|
|
464
434
|
(0, import_timer2.clearTimeoutEx)(this._pollId);
|
|
465
435
|
this._pollId = void 0;
|
|
466
436
|
}
|
|
467
|
-
unexpose(
|
|
437
|
+
async unexpose(id, validate = true) {
|
|
468
438
|
var _a;
|
|
469
|
-
(0,
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
(
|
|
439
|
+
const module2 = (0, import_module_model2.asModuleInstance)(await this.resolver.resolve(id, {
|
|
440
|
+
maxDepth: 10
|
|
441
|
+
}));
|
|
442
|
+
if (module2) {
|
|
443
|
+
(0, import_assert3.assertEx)(!validate || this._exposedAddresses.has(module2.address), () => `Address not exposed [${module2.address}][${module2.id}]`);
|
|
444
|
+
this._exposedAddresses.delete(module2.address);
|
|
445
|
+
delete this._exposeOptions[module2.address];
|
|
446
|
+
(_a = this.logger) == null ? void 0 : _a.debug(`${module2.address} [${module2.id}] unexposed`);
|
|
447
|
+
}
|
|
448
|
+
return module2;
|
|
473
449
|
}
|
|
474
450
|
callLocalModule = async (localModule, query) => {
|
|
475
451
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
476
452
|
const localModuleName = localModule.config.name ?? localModule.address;
|
|
477
|
-
const queryArchivist = (0,
|
|
453
|
+
const queryArchivist = (0, import_assert3.assertEx)(await this.queriesArchivist(), () => {
|
|
478
454
|
var _a2, _b2, _c2;
|
|
479
455
|
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}]`;
|
|
480
456
|
});
|
|
481
|
-
const responsesArchivist = (0,
|
|
457
|
+
const responsesArchivist = (0, import_assert3.assertEx)(await this.responsesArchivist(), () => {
|
|
482
458
|
var _a2, _b2, _c2;
|
|
483
459
|
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}]`;
|
|
484
460
|
});
|
|
@@ -500,7 +476,7 @@ var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
|
|
|
500
476
|
(_c = this.logger) == null ? void 0 : _c.debug(`Issuing query ${querySchema2} (${queryHash}) addressed to module: ${localModuleName}`);
|
|
501
477
|
const response = await localModule.query(query, queryPayloads, {
|
|
502
478
|
allowedQueries: (_d = this._exposeOptions[localModule.address]) == null ? void 0 : _d.allowedQueries,
|
|
503
|
-
schema:
|
|
479
|
+
schema: import_module_model2.ModuleConfigSchema
|
|
504
480
|
});
|
|
505
481
|
const [bw, payloads, errors] = response;
|
|
506
482
|
(_e = this.logger) == null ? void 0 : _e.debug(`Replying to query ${queryHash} addressed to module: ${localModuleName}`);
|
|
@@ -650,18 +626,18 @@ var PubSubBridgeSchema = "network.xyo.bridge.pubsub";
|
|
|
650
626
|
var PubSubBridgeConfigSchema = `${PubSubBridgeSchema}.config`;
|
|
651
627
|
|
|
652
628
|
// src/PubSubBridge.ts
|
|
653
|
-
var
|
|
629
|
+
var import_assert5 = require("@xylabs/assert");
|
|
654
630
|
var import_exists = require("@xylabs/exists");
|
|
655
631
|
var import_abstract_bridge3 = require("@xyo-network/abstract-bridge");
|
|
656
|
-
var
|
|
632
|
+
var import_module_model4 = require("@xyo-network/module-model");
|
|
657
633
|
|
|
658
634
|
// src/PubSubBridgeModuleResolver.ts
|
|
659
|
-
var
|
|
635
|
+
var import_assert4 = require("@xylabs/assert");
|
|
660
636
|
var import_hex = require("@xylabs/hex");
|
|
661
637
|
var import_abstract_bridge2 = require("@xyo-network/abstract-bridge");
|
|
662
638
|
var import_account = require("@xyo-network/account");
|
|
663
639
|
var import_config_payload_plugin = require("@xyo-network/config-payload-plugin");
|
|
664
|
-
var
|
|
640
|
+
var import_module_model3 = require("@xyo-network/module-model");
|
|
665
641
|
var _PubSubBridgeModuleResolver = class _PubSubBridgeModuleResolver extends import_abstract_bridge2.AbstractBridgeModuleResolver {
|
|
666
642
|
async resolveHandler(id, options) {
|
|
667
643
|
var _a, _b;
|
|
@@ -671,14 +647,14 @@ var _PubSubBridgeModuleResolver = class _PubSubBridgeModuleResolver extends impo
|
|
|
671
647
|
}
|
|
672
648
|
const idParts = id.split(":");
|
|
673
649
|
const firstPart = idParts.shift();
|
|
674
|
-
(0,
|
|
650
|
+
(0, import_assert4.assertEx)((0, import_hex.isAddress)(firstPart), () => `Invalid module address: ${firstPart}`);
|
|
675
651
|
const remainderParts = idParts.join(":");
|
|
676
652
|
const account = import_account.Account.randomSync();
|
|
677
653
|
const params = {
|
|
678
654
|
account,
|
|
679
655
|
busClient: this.params.busClient,
|
|
680
656
|
config: {
|
|
681
|
-
schema:
|
|
657
|
+
schema: import_module_model3.ModuleConfigSchema
|
|
682
658
|
},
|
|
683
659
|
host: this.params.bridge,
|
|
684
660
|
moduleAddress: firstPart
|
|
@@ -688,13 +664,13 @@ var _PubSubBridgeModuleResolver = class _PubSubBridgeModuleResolver extends impo
|
|
|
688
664
|
const state = await proxy.state();
|
|
689
665
|
if (state) {
|
|
690
666
|
const configSchema = (_a = state.find((payload) => payload.schema === import_config_payload_plugin.ConfigSchema)) == null ? void 0 : _a.config;
|
|
691
|
-
const config = (0,
|
|
667
|
+
const config = (0, import_assert4.assertEx)(state.find((payload) => payload.schema === configSchema), () => "Unable to locate config");
|
|
692
668
|
proxy.setConfig(config);
|
|
693
669
|
}
|
|
694
670
|
}
|
|
695
671
|
await ((_b = proxy.start) == null ? void 0 : _b.call(proxy));
|
|
696
672
|
const wrapped = (0, import_abstract_bridge2.wrapModuleWithType)(proxy, account);
|
|
697
|
-
const as = (0,
|
|
673
|
+
const as = (0, import_assert4.assertEx)((0, import_module_model3.asModuleInstance)(wrapped, {}), () => `Failed to asModuleInstance [${id}]`);
|
|
698
674
|
proxy.upResolver.add(as);
|
|
699
675
|
proxy.downResolver.add(as);
|
|
700
676
|
this.add(as);
|
|
@@ -729,7 +705,7 @@ var _PubSubBridge = class _PubSubBridge extends import_abstract_bridge3.Abstract
|
|
|
729
705
|
get resolver() {
|
|
730
706
|
this._resolver = this._resolver ?? new PubSubBridgeModuleResolver({
|
|
731
707
|
bridge: this,
|
|
732
|
-
busClient: (0,
|
|
708
|
+
busClient: (0, import_assert5.assertEx)(this.busClient(), () => "busClient not configured"),
|
|
733
709
|
wrapperAccount: this.account
|
|
734
710
|
});
|
|
735
711
|
return this._resolver;
|
|
@@ -738,7 +714,7 @@ var _PubSubBridge = class _PubSubBridge extends import_abstract_bridge3.Abstract
|
|
|
738
714
|
return `${this.config.name ?? moduleName}`;
|
|
739
715
|
}
|
|
740
716
|
get roots() {
|
|
741
|
-
return (0,
|
|
717
|
+
return (0, import_assert5.assertEx)(this.config.roots, () => "roots not configured");
|
|
742
718
|
}
|
|
743
719
|
async discoverRoots() {
|
|
744
720
|
const rootInstances = (await Promise.all(this.roots.map(async (root) => await this.resolver.resolve(root)))).filter(import_exists.exists);
|
|
@@ -748,22 +724,24 @@ var _PubSubBridge = class _PubSubBridge extends import_abstract_bridge3.Abstract
|
|
|
748
724
|
return rootInstances;
|
|
749
725
|
}
|
|
750
726
|
async exposeHandler(id, options) {
|
|
751
|
-
const { maxDepth = 2, direction = "all" } = options ?? {};
|
|
752
|
-
const
|
|
727
|
+
const { maxDepth = 2, direction = "all", required = true } = options ?? {};
|
|
728
|
+
const host = (0, import_assert5.assertEx)(this.busHost(), () => "Not configured as a host");
|
|
729
|
+
const module2 = await host.expose(id, {
|
|
730
|
+
required
|
|
731
|
+
});
|
|
753
732
|
if (module2) {
|
|
754
|
-
const
|
|
755
|
-
host.expose(module2.address);
|
|
756
|
-
const children = await module2.resolve("*", {
|
|
733
|
+
const children = maxDepth > 0 ? await module2.resolve("*", {
|
|
757
734
|
direction,
|
|
758
735
|
maxDepth,
|
|
759
736
|
visibility: "public"
|
|
760
|
-
});
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
737
|
+
}) : [];
|
|
738
|
+
const exposedChildren = (await Promise.all(children.map((child) => this.exposeHandler(child.address, {
|
|
739
|
+
maxDepth: maxDepth - 1,
|
|
740
|
+
required: false
|
|
741
|
+
})))).flat().filter(import_exists.exists);
|
|
764
742
|
return [
|
|
765
743
|
module2,
|
|
766
|
-
...
|
|
744
|
+
...exposedChildren
|
|
767
745
|
];
|
|
768
746
|
}
|
|
769
747
|
return [];
|
|
@@ -781,25 +759,22 @@ var _PubSubBridge = class _PubSubBridge extends import_abstract_bridge3.Abstract
|
|
|
781
759
|
return await super.startHandler();
|
|
782
760
|
}
|
|
783
761
|
async unexposeHandler(id, options) {
|
|
784
|
-
const { maxDepth =
|
|
785
|
-
const
|
|
786
|
-
|
|
787
|
-
};
|
|
788
|
-
const module2 = await super.resolve(id, filterOptions);
|
|
762
|
+
const { maxDepth = 2, direction = "all", required = true } = options ?? {};
|
|
763
|
+
const host = (0, import_assert5.assertEx)(this.busHost(), () => "Not configured as a host");
|
|
764
|
+
const module2 = await host.unexpose(id, required);
|
|
789
765
|
if (module2) {
|
|
790
|
-
const
|
|
791
|
-
host.unexpose(module2.address);
|
|
792
|
-
const children = await module2.resolve("*", {
|
|
766
|
+
const children = maxDepth > 0 ? await module2.resolve("*", {
|
|
793
767
|
direction,
|
|
794
768
|
maxDepth,
|
|
795
769
|
visibility: "public"
|
|
796
|
-
});
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
770
|
+
}) : [];
|
|
771
|
+
const exposedChildren = (await Promise.all(children.map((child) => this.unexposeHandler(child.address, {
|
|
772
|
+
maxDepth: maxDepth - 1,
|
|
773
|
+
required: false
|
|
774
|
+
})))).flat().filter(import_exists.exists);
|
|
800
775
|
return [
|
|
801
776
|
module2,
|
|
802
|
-
...
|
|
777
|
+
...exposedChildren
|
|
803
778
|
];
|
|
804
779
|
}
|
|
805
780
|
return [];
|
|
@@ -836,7 +811,7 @@ __publicField(_PubSubBridge, "configSchemas", [
|
|
|
836
811
|
]);
|
|
837
812
|
var PubSubBridge = _PubSubBridge;
|
|
838
813
|
PubSubBridge = _ts_decorate([
|
|
839
|
-
(0,
|
|
814
|
+
(0, import_module_model4.creatableModule)()
|
|
840
815
|
], PubSubBridge);
|
|
841
816
|
// Annotate the CommonJS export names for ESM import in node:
|
|
842
817
|
0 && (module.exports = {
|