@xyo-network/bridge-pub-sub 2.94.15 → 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.js
CHANGED
|
@@ -27,6 +27,7 @@ import { LRUCache as LRUCache2 } from "lru-cache";
|
|
|
27
27
|
import { Base as Base2, toJsonString } from "@xylabs/object";
|
|
28
28
|
import { asArchivistInstance } from "@xyo-network/archivist-model";
|
|
29
29
|
import { asDivinerInstance } from "@xyo-network/diviner-model";
|
|
30
|
+
import { Mutex } from "async-mutex";
|
|
30
31
|
import { LRUCache } from "lru-cache";
|
|
31
32
|
var _AsyncQueryBusBase = class _AsyncQueryBusBase extends Base2 {
|
|
32
33
|
_lastState;
|
|
@@ -37,10 +38,14 @@ var _AsyncQueryBusBase = class _AsyncQueryBusBase extends Base2 {
|
|
|
37
38
|
_lastResponsesArchivistAttempt;
|
|
38
39
|
_lastResponsesDivinerAttempt;
|
|
39
40
|
_queriesArchivist;
|
|
41
|
+
_queriesArchivistMutex = new Mutex();
|
|
40
42
|
_queriesDiviner;
|
|
43
|
+
_queriesDivinerMutex = new Mutex();
|
|
41
44
|
_reResolveDelay = 5e4;
|
|
42
45
|
_responsesArchivist;
|
|
46
|
+
_responsesArchivistMutex = new Mutex();
|
|
43
47
|
_responsesDiviner;
|
|
48
|
+
_responsesDivinerMutex = new Mutex();
|
|
44
49
|
constructor(params) {
|
|
45
50
|
super(params);
|
|
46
51
|
}
|
|
@@ -66,88 +71,96 @@ var _AsyncQueryBusBase = class _AsyncQueryBusBase extends Base2 {
|
|
|
66
71
|
return this._lastState;
|
|
67
72
|
}
|
|
68
73
|
async queriesArchivist() {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
74
|
+
return await this._queriesArchivistMutex.runExclusive(async () => {
|
|
75
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
76
|
+
if (this._queriesArchivist) {
|
|
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
|
+
}
|
|
82
91
|
} else {
|
|
83
|
-
(
|
|
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}]`);
|
|
84
93
|
}
|
|
85
|
-
}
|
|
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
|
-
}
|
|
94
|
+
});
|
|
88
95
|
}
|
|
89
96
|
async queriesDiviner() {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
97
|
+
return await this._queriesDivinerMutex.runExclusive(async () => {
|
|
98
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
99
|
+
if (this._queriesDiviner) {
|
|
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
|
+
}
|
|
103
114
|
} else {
|
|
104
|
-
(
|
|
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}]`);
|
|
105
116
|
}
|
|
106
|
-
}
|
|
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
|
-
}
|
|
117
|
+
});
|
|
109
118
|
}
|
|
110
119
|
async responsesArchivist() {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
120
|
+
return await this._responsesArchivistMutex.runExclusive(async () => {
|
|
121
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
122
|
+
if (this._responsesArchivist) {
|
|
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
|
+
}
|
|
124
137
|
} else {
|
|
125
|
-
(
|
|
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}]`);
|
|
126
139
|
}
|
|
127
|
-
}
|
|
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
|
-
}
|
|
140
|
+
});
|
|
130
141
|
}
|
|
131
142
|
async responsesDiviner() {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
143
|
+
return await this._responsesDivinerMutex.runExclusive(async () => {
|
|
144
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
145
|
+
if (this._responsesDiviner) {
|
|
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
|
+
}
|
|
145
160
|
} else {
|
|
146
|
-
(
|
|
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}]`);
|
|
147
162
|
}
|
|
148
|
-
}
|
|
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
|
-
}
|
|
163
|
+
});
|
|
151
164
|
}
|
|
152
165
|
/**
|
|
153
166
|
* Commit the internal state of the process. This is similar
|
|
@@ -398,15 +411,24 @@ var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
|
|
|
398
411
|
get started() {
|
|
399
412
|
return !!this._pollId;
|
|
400
413
|
}
|
|
401
|
-
expose(
|
|
414
|
+
async expose(id, options) {
|
|
402
415
|
var _a;
|
|
403
|
-
const { failOnAlreadyExposed } = options;
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
416
|
+
const { failOnAlreadyExposed, required = true } = options ?? {};
|
|
417
|
+
const module = asModuleInstance(await this.resolver.resolve(id, {
|
|
418
|
+
maxDepth: 10
|
|
419
|
+
}));
|
|
420
|
+
if (!module && required) {
|
|
421
|
+
throw new Error(`Unable to resolve module to expose [${id}]`);
|
|
422
|
+
}
|
|
423
|
+
if (module) {
|
|
424
|
+
assertEx2(!failOnAlreadyExposed || !this._exposedAddresses.has(module.address), () => `Address already exposed: ${id} [${module.address}]`);
|
|
425
|
+
this._exposedAddresses.add(module.address);
|
|
426
|
+
this._exposeOptions[module.address] = {
|
|
427
|
+
...options
|
|
428
|
+
};
|
|
429
|
+
(_a = this.logger) == null ? void 0 : _a.debug(`${id} exposed [${module.address}]`);
|
|
430
|
+
return module;
|
|
431
|
+
}
|
|
410
432
|
}
|
|
411
433
|
async listeningModules() {
|
|
412
434
|
var _a;
|
|
@@ -414,7 +436,9 @@ var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
|
|
|
414
436
|
...((_a = this.config) == null ? void 0 : _a.listeningModules) ?? [],
|
|
415
437
|
...this.exposedAddresses.values()
|
|
416
438
|
];
|
|
417
|
-
const mods = await Promise.all(exposedModules.map(async (
|
|
439
|
+
const mods = await Promise.all(exposedModules.map(async (exposedModule) => assertEx2(asModuleInstance(await this.resolver.resolve(exposedModule, {
|
|
440
|
+
maxDepth: 10
|
|
441
|
+
})), () => `Unable to resolve listeningModule [${exposedModule}]`)));
|
|
418
442
|
return mods;
|
|
419
443
|
}
|
|
420
444
|
start() {
|
|
@@ -431,12 +455,18 @@ var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
|
|
|
431
455
|
clearTimeoutEx2(this._pollId);
|
|
432
456
|
this._pollId = void 0;
|
|
433
457
|
}
|
|
434
|
-
unexpose(
|
|
458
|
+
async unexpose(id, validate = true) {
|
|
435
459
|
var _a;
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
(
|
|
460
|
+
const module = asModuleInstance(await this.resolver.resolve(id, {
|
|
461
|
+
maxDepth: 10
|
|
462
|
+
}));
|
|
463
|
+
if (module) {
|
|
464
|
+
assertEx2(!validate || this._exposedAddresses.has(module.address), () => `Address not exposed [${module.address}][${module.id}]`);
|
|
465
|
+
this._exposedAddresses.delete(module.address);
|
|
466
|
+
delete this._exposeOptions[module.address];
|
|
467
|
+
(_a = this.logger) == null ? void 0 : _a.debug(`${module.address} [${module.id}] unexposed`);
|
|
468
|
+
}
|
|
469
|
+
return module;
|
|
440
470
|
}
|
|
441
471
|
callLocalModule = async (localModule, query) => {
|
|
442
472
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
@@ -715,22 +745,24 @@ var _PubSubBridge = class _PubSubBridge extends AbstractBridge {
|
|
|
715
745
|
return rootInstances;
|
|
716
746
|
}
|
|
717
747
|
async exposeHandler(id, options) {
|
|
718
|
-
const { maxDepth = 2, direction = "all" } = options ?? {};
|
|
719
|
-
const
|
|
748
|
+
const { maxDepth = 2, direction = "all", required = true } = options ?? {};
|
|
749
|
+
const host = assertEx4(this.busHost(), () => "Not configured as a host");
|
|
750
|
+
const module = await host.expose(id, {
|
|
751
|
+
required
|
|
752
|
+
});
|
|
720
753
|
if (module) {
|
|
721
|
-
const
|
|
722
|
-
host.expose(module.address);
|
|
723
|
-
const children = await module.resolve("*", {
|
|
754
|
+
const children = maxDepth > 0 ? await module.resolve("*", {
|
|
724
755
|
direction,
|
|
725
756
|
maxDepth,
|
|
726
757
|
visibility: "public"
|
|
727
|
-
});
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
758
|
+
}) : [];
|
|
759
|
+
const exposedChildren = (await Promise.all(children.map((child) => this.exposeHandler(child.address, {
|
|
760
|
+
maxDepth: maxDepth - 1,
|
|
761
|
+
required: false
|
|
762
|
+
})))).flat().filter(exists);
|
|
731
763
|
return [
|
|
732
764
|
module,
|
|
733
|
-
...
|
|
765
|
+
...exposedChildren
|
|
734
766
|
];
|
|
735
767
|
}
|
|
736
768
|
return [];
|
|
@@ -748,25 +780,22 @@ var _PubSubBridge = class _PubSubBridge extends AbstractBridge {
|
|
|
748
780
|
return await super.startHandler();
|
|
749
781
|
}
|
|
750
782
|
async unexposeHandler(id, options) {
|
|
751
|
-
const { maxDepth =
|
|
752
|
-
const
|
|
753
|
-
|
|
754
|
-
};
|
|
755
|
-
const module = await super.resolve(id, filterOptions);
|
|
783
|
+
const { maxDepth = 2, direction = "all", required = true } = options ?? {};
|
|
784
|
+
const host = assertEx4(this.busHost(), () => "Not configured as a host");
|
|
785
|
+
const module = await host.unexpose(id, required);
|
|
756
786
|
if (module) {
|
|
757
|
-
const
|
|
758
|
-
host.unexpose(module.address);
|
|
759
|
-
const children = await module.resolve("*", {
|
|
787
|
+
const children = maxDepth > 0 ? await module.resolve("*", {
|
|
760
788
|
direction,
|
|
761
789
|
maxDepth,
|
|
762
790
|
visibility: "public"
|
|
763
|
-
});
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
791
|
+
}) : [];
|
|
792
|
+
const exposedChildren = (await Promise.all(children.map((child) => this.unexposeHandler(child.address, {
|
|
793
|
+
maxDepth: maxDepth - 1,
|
|
794
|
+
required: false
|
|
795
|
+
})))).flat().filter(exists);
|
|
767
796
|
return [
|
|
768
797
|
module,
|
|
769
|
-
...
|
|
798
|
+
...exposedChildren
|
|
770
799
|
];
|
|
771
800
|
}
|
|
772
801
|
return [];
|