@xyo-network/bridge-pub-sub 2.94.14 → 2.94.16
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 +4 -0
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.cts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.mts +4 -0
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.mts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.ts +4 -0
- 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 +130 -101
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +130 -101
- package/dist/browser/index.js.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.cts +4 -0
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.cts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.mts +4 -0
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.mts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.ts +4 -0
- 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 +134 -105
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +134 -105
- package/dist/node/index.js.map +1 -1
- package/package.json +19 -18
- package/src/AsyncQueryBus/AsyncQueryBusBase.ts +85 -72
- package/src/AsyncQueryBus/AsyncQueryBusHost.ts +29 -14
- package/src/PubSubBridge.ts +21 -20
package/dist/node/index.cjs
CHANGED
|
@@ -60,6 +60,7 @@ var import_lru_cache2 = require("lru-cache");
|
|
|
60
60
|
var import_object2 = require("@xylabs/object");
|
|
61
61
|
var import_archivist_model = require("@xyo-network/archivist-model");
|
|
62
62
|
var import_diviner_model = require("@xyo-network/diviner-model");
|
|
63
|
+
var import_async_mutex = require("async-mutex");
|
|
63
64
|
var import_lru_cache = require("lru-cache");
|
|
64
65
|
var _AsyncQueryBusBase = class _AsyncQueryBusBase extends import_object2.Base {
|
|
65
66
|
_lastState;
|
|
@@ -70,10 +71,14 @@ var _AsyncQueryBusBase = class _AsyncQueryBusBase extends import_object2.Base {
|
|
|
70
71
|
_lastResponsesArchivistAttempt;
|
|
71
72
|
_lastResponsesDivinerAttempt;
|
|
72
73
|
_queriesArchivist;
|
|
74
|
+
_queriesArchivistMutex = new import_async_mutex.Mutex();
|
|
73
75
|
_queriesDiviner;
|
|
76
|
+
_queriesDivinerMutex = new import_async_mutex.Mutex();
|
|
74
77
|
_reResolveDelay = 5e4;
|
|
75
78
|
_responsesArchivist;
|
|
79
|
+
_responsesArchivistMutex = new import_async_mutex.Mutex();
|
|
76
80
|
_responsesDiviner;
|
|
81
|
+
_responsesDivinerMutex = new import_async_mutex.Mutex();
|
|
77
82
|
constructor(params) {
|
|
78
83
|
super(params);
|
|
79
84
|
}
|
|
@@ -99,88 +104,96 @@ var _AsyncQueryBusBase = class _AsyncQueryBusBase extends import_object2.Base {
|
|
|
99
104
|
return this._lastState;
|
|
100
105
|
}
|
|
101
106
|
async queriesArchivist() {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
107
|
+
return await this._queriesArchivistMutex.runExclusive(async () => {
|
|
108
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
109
|
+
if (this._queriesArchivist) {
|
|
110
|
+
return this._queriesArchivist;
|
|
111
|
+
}
|
|
112
|
+
if (Date.now() - (this._lastQueriesArchivistAttempt ?? 0) < this._reResolveDelay) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
this._lastQueriesArchivistAttempt = Date.now();
|
|
116
|
+
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);
|
|
117
|
+
if (resolved) {
|
|
118
|
+
const typedResolve = (0, import_archivist_model.asArchivistInstance)(resolved);
|
|
119
|
+
if (typedResolve) {
|
|
120
|
+
return typedResolve;
|
|
121
|
+
} else {
|
|
122
|
+
(_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)}`);
|
|
123
|
+
}
|
|
115
124
|
} else {
|
|
116
|
-
(
|
|
125
|
+
(_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}]`);
|
|
117
126
|
}
|
|
118
|
-
}
|
|
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
|
-
}
|
|
127
|
+
});
|
|
121
128
|
}
|
|
122
129
|
async queriesDiviner() {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
130
|
+
return await this._queriesDivinerMutex.runExclusive(async () => {
|
|
131
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
132
|
+
if (this._queriesDiviner) {
|
|
133
|
+
return this._queriesDiviner;
|
|
134
|
+
}
|
|
135
|
+
if (Date.now() - (this._lastQueriesDivinerAttempt ?? 0) < this._reResolveDelay) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
this._lastQueriesDivinerAttempt = Date.now();
|
|
139
|
+
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);
|
|
140
|
+
if (resolved) {
|
|
141
|
+
const typedResolve = (0, import_diviner_model.asDivinerInstance)(resolved);
|
|
142
|
+
if (typedResolve) {
|
|
143
|
+
return typedResolve;
|
|
144
|
+
} else {
|
|
145
|
+
(_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)}`);
|
|
146
|
+
}
|
|
136
147
|
} else {
|
|
137
|
-
(
|
|
148
|
+
(_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}]`);
|
|
138
149
|
}
|
|
139
|
-
}
|
|
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
|
-
}
|
|
150
|
+
});
|
|
142
151
|
}
|
|
143
152
|
async responsesArchivist() {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
153
|
+
return await this._responsesArchivistMutex.runExclusive(async () => {
|
|
154
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
155
|
+
if (this._responsesArchivist) {
|
|
156
|
+
return this._responsesArchivist;
|
|
157
|
+
}
|
|
158
|
+
if (Date.now() - (this._lastResponsesArchivistAttempt ?? 0) < this._reResolveDelay) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
this._lastResponsesArchivistAttempt = Date.now();
|
|
162
|
+
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);
|
|
163
|
+
if (resolved) {
|
|
164
|
+
const typedResolve = (0, import_archivist_model.asArchivistInstance)(resolved);
|
|
165
|
+
if (typedResolve) {
|
|
166
|
+
return typedResolve;
|
|
167
|
+
} else {
|
|
168
|
+
(_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)}`);
|
|
169
|
+
}
|
|
157
170
|
} else {
|
|
158
|
-
(
|
|
171
|
+
(_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}]`);
|
|
159
172
|
}
|
|
160
|
-
}
|
|
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
|
-
}
|
|
173
|
+
});
|
|
163
174
|
}
|
|
164
175
|
async responsesDiviner() {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
176
|
+
return await this._responsesDivinerMutex.runExclusive(async () => {
|
|
177
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
178
|
+
if (this._responsesDiviner) {
|
|
179
|
+
return this._responsesDiviner;
|
|
180
|
+
}
|
|
181
|
+
if (Date.now() - (this._lastResponsesDivinerAttempt ?? 0) < this._reResolveDelay) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
this._lastResponsesDivinerAttempt = Date.now();
|
|
185
|
+
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);
|
|
186
|
+
if (resolved) {
|
|
187
|
+
const typedResolve = (0, import_diviner_model.asDivinerInstance)(resolved);
|
|
188
|
+
if (typedResolve) {
|
|
189
|
+
return typedResolve;
|
|
190
|
+
} else {
|
|
191
|
+
(_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)}`);
|
|
192
|
+
}
|
|
178
193
|
} else {
|
|
179
|
-
(
|
|
194
|
+
(_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}]`);
|
|
180
195
|
}
|
|
181
|
-
}
|
|
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
|
-
}
|
|
196
|
+
});
|
|
184
197
|
}
|
|
185
198
|
/**
|
|
186
199
|
* Commit the internal state of the process. This is similar
|
|
@@ -431,15 +444,24 @@ var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
|
|
|
431
444
|
get started() {
|
|
432
445
|
return !!this._pollId;
|
|
433
446
|
}
|
|
434
|
-
expose(
|
|
447
|
+
async expose(id, options) {
|
|
435
448
|
var _a;
|
|
436
|
-
const { failOnAlreadyExposed } = options;
|
|
437
|
-
(0,
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
449
|
+
const { failOnAlreadyExposed, required = true } = options ?? {};
|
|
450
|
+
const module2 = (0, import_module_model.asModuleInstance)(await this.resolver.resolve(id, {
|
|
451
|
+
maxDepth: 10
|
|
452
|
+
}));
|
|
453
|
+
if (!module2 && required) {
|
|
454
|
+
throw new Error(`Unable to resolve module to expose [${id}]`);
|
|
455
|
+
}
|
|
456
|
+
if (module2) {
|
|
457
|
+
(0, import_assert2.assertEx)(!failOnAlreadyExposed || !this._exposedAddresses.has(module2.address), () => `Address already exposed: ${id} [${module2.address}]`);
|
|
458
|
+
this._exposedAddresses.add(module2.address);
|
|
459
|
+
this._exposeOptions[module2.address] = {
|
|
460
|
+
...options
|
|
461
|
+
};
|
|
462
|
+
(_a = this.logger) == null ? void 0 : _a.debug(`${id} exposed [${module2.address}]`);
|
|
463
|
+
return module2;
|
|
464
|
+
}
|
|
443
465
|
}
|
|
444
466
|
async listeningModules() {
|
|
445
467
|
var _a;
|
|
@@ -447,7 +469,9 @@ var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
|
|
|
447
469
|
...((_a = this.config) == null ? void 0 : _a.listeningModules) ?? [],
|
|
448
470
|
...this.exposedAddresses.values()
|
|
449
471
|
];
|
|
450
|
-
const mods = await Promise.all(exposedModules.map(async (
|
|
472
|
+
const mods = await Promise.all(exposedModules.map(async (exposedModule) => (0, import_assert2.assertEx)((0, import_module_model.asModuleInstance)(await this.resolver.resolve(exposedModule, {
|
|
473
|
+
maxDepth: 10
|
|
474
|
+
})), () => `Unable to resolve listeningModule [${exposedModule}]`)));
|
|
451
475
|
return mods;
|
|
452
476
|
}
|
|
453
477
|
start() {
|
|
@@ -464,12 +488,18 @@ var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
|
|
|
464
488
|
(0, import_timer2.clearTimeoutEx)(this._pollId);
|
|
465
489
|
this._pollId = void 0;
|
|
466
490
|
}
|
|
467
|
-
unexpose(
|
|
491
|
+
async unexpose(id, validate = true) {
|
|
468
492
|
var _a;
|
|
469
|
-
(0,
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
(
|
|
493
|
+
const module2 = (0, import_module_model.asModuleInstance)(await this.resolver.resolve(id, {
|
|
494
|
+
maxDepth: 10
|
|
495
|
+
}));
|
|
496
|
+
if (module2) {
|
|
497
|
+
(0, import_assert2.assertEx)(!validate || this._exposedAddresses.has(module2.address), () => `Address not exposed [${module2.address}][${module2.id}]`);
|
|
498
|
+
this._exposedAddresses.delete(module2.address);
|
|
499
|
+
delete this._exposeOptions[module2.address];
|
|
500
|
+
(_a = this.logger) == null ? void 0 : _a.debug(`${module2.address} [${module2.id}] unexposed`);
|
|
501
|
+
}
|
|
502
|
+
return module2;
|
|
473
503
|
}
|
|
474
504
|
callLocalModule = async (localModule, query) => {
|
|
475
505
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
@@ -748,22 +778,24 @@ var _PubSubBridge = class _PubSubBridge extends import_abstract_bridge3.Abstract
|
|
|
748
778
|
return rootInstances;
|
|
749
779
|
}
|
|
750
780
|
async exposeHandler(id, options) {
|
|
751
|
-
const { maxDepth = 2, direction = "all" } = options ?? {};
|
|
752
|
-
const
|
|
781
|
+
const { maxDepth = 2, direction = "all", required = true } = options ?? {};
|
|
782
|
+
const host = (0, import_assert4.assertEx)(this.busHost(), () => "Not configured as a host");
|
|
783
|
+
const module2 = await host.expose(id, {
|
|
784
|
+
required
|
|
785
|
+
});
|
|
753
786
|
if (module2) {
|
|
754
|
-
const
|
|
755
|
-
host.expose(module2.address);
|
|
756
|
-
const children = await module2.resolve("*", {
|
|
787
|
+
const children = maxDepth > 0 ? await module2.resolve("*", {
|
|
757
788
|
direction,
|
|
758
789
|
maxDepth,
|
|
759
790
|
visibility: "public"
|
|
760
|
-
});
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
791
|
+
}) : [];
|
|
792
|
+
const exposedChildren = (await Promise.all(children.map((child) => this.exposeHandler(child.address, {
|
|
793
|
+
maxDepth: maxDepth - 1,
|
|
794
|
+
required: false
|
|
795
|
+
})))).flat().filter(import_exists.exists);
|
|
764
796
|
return [
|
|
765
797
|
module2,
|
|
766
|
-
...
|
|
798
|
+
...exposedChildren
|
|
767
799
|
];
|
|
768
800
|
}
|
|
769
801
|
return [];
|
|
@@ -781,25 +813,22 @@ var _PubSubBridge = class _PubSubBridge extends import_abstract_bridge3.Abstract
|
|
|
781
813
|
return await super.startHandler();
|
|
782
814
|
}
|
|
783
815
|
async unexposeHandler(id, options) {
|
|
784
|
-
const { maxDepth =
|
|
785
|
-
const
|
|
786
|
-
|
|
787
|
-
};
|
|
788
|
-
const module2 = await super.resolve(id, filterOptions);
|
|
816
|
+
const { maxDepth = 2, direction = "all", required = true } = options ?? {};
|
|
817
|
+
const host = (0, import_assert4.assertEx)(this.busHost(), () => "Not configured as a host");
|
|
818
|
+
const module2 = await host.unexpose(id, required);
|
|
789
819
|
if (module2) {
|
|
790
|
-
const
|
|
791
|
-
host.unexpose(module2.address);
|
|
792
|
-
const children = await module2.resolve("*", {
|
|
820
|
+
const children = maxDepth > 0 ? await module2.resolve("*", {
|
|
793
821
|
direction,
|
|
794
822
|
maxDepth,
|
|
795
823
|
visibility: "public"
|
|
796
|
-
});
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
824
|
+
}) : [];
|
|
825
|
+
const exposedChildren = (await Promise.all(children.map((child) => this.unexposeHandler(child.address, {
|
|
826
|
+
maxDepth: maxDepth - 1,
|
|
827
|
+
required: false
|
|
828
|
+
})))).flat().filter(import_exists.exists);
|
|
800
829
|
return [
|
|
801
830
|
module2,
|
|
802
|
-
...
|
|
831
|
+
...exposedChildren
|
|
803
832
|
];
|
|
804
833
|
}
|
|
805
834
|
return [];
|