@xyo-network/bridge-pub-sub 2.91.3 → 2.92.0-rc.10
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 +3 -0
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.cts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.mts +3 -0
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.mts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.ts +3 -0
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.ts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.cts +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.mts +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.ts +1 -1
- package/dist/browser/AsyncQueryBus/ModuleHost/ModuleHost.d.cts +1 -1
- package/dist/browser/AsyncQueryBus/ModuleHost/ModuleHost.d.cts.map +1 -1
- package/dist/browser/AsyncQueryBus/ModuleHost/ModuleHost.d.mts +1 -1
- package/dist/browser/AsyncQueryBus/ModuleHost/ModuleHost.d.mts.map +1 -1
- package/dist/browser/AsyncQueryBus/ModuleHost/ModuleHost.d.ts +1 -1
- package/dist/browser/AsyncQueryBus/ModuleHost/ModuleHost.d.ts.map +1 -1
- package/dist/browser/AsyncQueryBus/ModuleProxy/ModuleProxy.d.cts +1 -1
- package/dist/browser/AsyncQueryBus/ModuleProxy/ModuleProxy.d.cts.map +1 -1
- package/dist/browser/AsyncQueryBus/ModuleProxy/ModuleProxy.d.mts +1 -1
- package/dist/browser/AsyncQueryBus/ModuleProxy/ModuleProxy.d.mts.map +1 -1
- package/dist/browser/AsyncQueryBus/ModuleProxy/ModuleProxy.d.ts +1 -1
- package/dist/browser/AsyncQueryBus/ModuleProxy/ModuleProxy.d.ts.map +1 -1
- package/dist/browser/PubSubBridge.d.cts +8 -18
- package/dist/browser/PubSubBridge.d.cts.map +1 -1
- package/dist/browser/PubSubBridge.d.mts +8 -18
- package/dist/browser/PubSubBridge.d.mts.map +1 -1
- package/dist/browser/PubSubBridge.d.ts +8 -18
- package/dist/browser/PubSubBridge.d.ts.map +1 -1
- package/dist/browser/index.cjs +81 -255
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.d.cts +1 -1
- package/dist/browser/index.d.cts.map +1 -1
- package/dist/browser/index.d.mts +1 -1
- package/dist/browser/index.d.mts.map +1 -1
- package/dist/browser/index.d.ts +1 -1
- package/dist/browser/index.d.ts.map +1 -1
- package/dist/browser/index.js +76 -250
- package/dist/browser/index.js.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.cts +3 -0
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.cts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.mts +3 -0
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.mts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.ts +3 -0
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.ts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.cts +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.mts +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.ts +1 -1
- package/dist/node/AsyncQueryBus/ModuleHost/ModuleHost.d.cts +1 -1
- package/dist/node/AsyncQueryBus/ModuleHost/ModuleHost.d.cts.map +1 -1
- package/dist/node/AsyncQueryBus/ModuleHost/ModuleHost.d.mts +1 -1
- package/dist/node/AsyncQueryBus/ModuleHost/ModuleHost.d.mts.map +1 -1
- package/dist/node/AsyncQueryBus/ModuleHost/ModuleHost.d.ts +1 -1
- package/dist/node/AsyncQueryBus/ModuleHost/ModuleHost.d.ts.map +1 -1
- package/dist/node/AsyncQueryBus/ModuleProxy/ModuleProxy.d.cts +1 -1
- package/dist/node/AsyncQueryBus/ModuleProxy/ModuleProxy.d.cts.map +1 -1
- package/dist/node/AsyncQueryBus/ModuleProxy/ModuleProxy.d.mts +1 -1
- package/dist/node/AsyncQueryBus/ModuleProxy/ModuleProxy.d.mts.map +1 -1
- package/dist/node/AsyncQueryBus/ModuleProxy/ModuleProxy.d.ts +1 -1
- package/dist/node/AsyncQueryBus/ModuleProxy/ModuleProxy.d.ts.map +1 -1
- package/dist/node/PubSubBridge.d.cts +8 -18
- package/dist/node/PubSubBridge.d.cts.map +1 -1
- package/dist/node/PubSubBridge.d.mts +8 -18
- package/dist/node/PubSubBridge.d.mts.map +1 -1
- package/dist/node/PubSubBridge.d.ts +8 -18
- package/dist/node/PubSubBridge.d.ts.map +1 -1
- package/dist/node/index.cjs +83 -256
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.d.cts +1 -1
- package/dist/node/index.d.cts.map +1 -1
- package/dist/node/index.d.mts +1 -1
- package/dist/node/index.d.mts.map +1 -1
- package/dist/node/index.d.ts +1 -1
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +77 -250
- package/dist/node/index.js.map +1 -1
- package/package.json +26 -31
- package/src/AsyncQueryBus/AsyncQueryBusBase.ts +11 -0
- package/src/AsyncQueryBus/AsyncQueryBusHost.ts +19 -19
- package/src/AsyncQueryBus/ModuleHost/ModuleHost.ts +1 -1
- package/src/AsyncQueryBus/ModuleProxy/ModuleProxy.ts +1 -1
- package/src/PubSubBridge.ts +32 -89
- package/src/index.ts +1 -1
- package/dist/browser/AbstractModuleProxy/AbstractModuleProxy.d.cts +0 -90
- package/dist/browser/AbstractModuleProxy/AbstractModuleProxy.d.cts.map +0 -1
- package/dist/browser/AbstractModuleProxy/AbstractModuleProxy.d.mts +0 -90
- package/dist/browser/AbstractModuleProxy/AbstractModuleProxy.d.mts.map +0 -1
- package/dist/browser/AbstractModuleProxy/AbstractModuleProxy.d.ts +0 -90
- package/dist/browser/AbstractModuleProxy/AbstractModuleProxy.d.ts.map +0 -1
- package/dist/browser/AbstractModuleProxy/index.d.cts +0 -2
- package/dist/browser/AbstractModuleProxy/index.d.cts.map +0 -1
- package/dist/browser/AbstractModuleProxy/index.d.mts +0 -2
- package/dist/browser/AbstractModuleProxy/index.d.mts.map +0 -1
- package/dist/browser/AbstractModuleProxy/index.d.ts +0 -2
- package/dist/browser/AbstractModuleProxy/index.d.ts.map +0 -1
- package/dist/node/AbstractModuleProxy/AbstractModuleProxy.d.cts +0 -90
- package/dist/node/AbstractModuleProxy/AbstractModuleProxy.d.cts.map +0 -1
- package/dist/node/AbstractModuleProxy/AbstractModuleProxy.d.mts +0 -90
- package/dist/node/AbstractModuleProxy/AbstractModuleProxy.d.mts.map +0 -1
- package/dist/node/AbstractModuleProxy/AbstractModuleProxy.d.ts +0 -90
- package/dist/node/AbstractModuleProxy/AbstractModuleProxy.d.ts.map +0 -1
- package/dist/node/AbstractModuleProxy/index.d.cts +0 -2
- package/dist/node/AbstractModuleProxy/index.d.cts.map +0 -1
- package/dist/node/AbstractModuleProxy/index.d.mts +0 -2
- package/dist/node/AbstractModuleProxy/index.d.mts.map +0 -1
- package/dist/node/AbstractModuleProxy/index.d.ts +0 -2
- package/dist/node/AbstractModuleProxy/index.d.ts.map +0 -1
- package/src/AbstractModuleProxy/AbstractModuleProxy.ts +0 -239
- package/src/AbstractModuleProxy/index.ts +0 -1
package/dist/node/index.js
CHANGED
|
@@ -6,163 +6,12 @@ var __publicField = (obj, key, value) => {
|
|
|
6
6
|
return value;
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
-
// src/
|
|
10
|
-
import { assertEx } from "@xylabs/assert";
|
|
11
|
-
import { compact } from "@xylabs/lodash";
|
|
9
|
+
// src/AbstractModuleHost/AbstractModuleHost.ts
|
|
12
10
|
import { Base } from "@xylabs/object";
|
|
13
|
-
|
|
14
|
-
import { QueryBoundWitnessBuilder } from "@xyo-network/boundwitness-builder";
|
|
15
|
-
import { BoundWitnessWrapper } from "@xyo-network/boundwitness-wrapper";
|
|
16
|
-
import { AddressPreviousHashSchema, ModuleAddressQuerySchema, ModuleConfigSchema, ModuleDescribeQuerySchema, ModuleDiscoverQuerySchema, ModuleManifestQuerySchema } from "@xyo-network/module-model";
|
|
17
|
-
import { ModuleErrorSchema } from "@xyo-network/payload-model";
|
|
18
|
-
var _AbstractModuleProxy = class _AbstractModuleProxy extends Base {
|
|
19
|
-
eventData = {};
|
|
20
|
-
proxyParams;
|
|
21
|
-
constructor(params) {
|
|
22
|
-
super({
|
|
23
|
-
config: {
|
|
24
|
-
schema: ModuleConfigSchema
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
this.proxyParams = params;
|
|
28
|
-
}
|
|
29
|
-
get account() {
|
|
30
|
-
return this.proxyParams.account;
|
|
31
|
-
}
|
|
32
|
-
get address() {
|
|
33
|
-
return this.proxyParams.moduleAddress;
|
|
34
|
-
}
|
|
35
|
-
get config() {
|
|
36
|
-
return this.params.config;
|
|
37
|
-
}
|
|
38
|
-
get downResolver() {
|
|
39
|
-
throw new Error("Unsupported");
|
|
40
|
-
}
|
|
41
|
-
get id() {
|
|
42
|
-
return this.proxyParams.moduleAddress;
|
|
43
|
-
}
|
|
44
|
-
get queries() {
|
|
45
|
-
return this.proxyParams.queries;
|
|
46
|
-
}
|
|
47
|
-
get upResolver() {
|
|
48
|
-
throw new Error("Unsupported");
|
|
49
|
-
}
|
|
50
|
-
static hasRequiredQueries(module) {
|
|
51
|
-
return this.missingRequiredQueries(module).length === 0;
|
|
52
|
-
}
|
|
53
|
-
static missingRequiredQueries(module) {
|
|
54
|
-
const moduleQueries = module.queries;
|
|
55
|
-
return compact(this.requiredQueries.map((query) => {
|
|
56
|
-
return moduleQueries.includes(query) ? null : query;
|
|
57
|
-
}));
|
|
58
|
-
}
|
|
59
|
-
async addressPreviousHash() {
|
|
60
|
-
const queryPayload = {
|
|
61
|
-
schema: ModuleAddressQuerySchema
|
|
62
|
-
};
|
|
63
|
-
return assertEx((await this.sendQuery(queryPayload)).find((payload) => payload.schema === AddressPreviousHashSchema), "Result did not include correct payload");
|
|
64
|
-
}
|
|
65
|
-
clearListeners(_eventNames) {
|
|
66
|
-
throw new Error("Unsupported");
|
|
67
|
-
}
|
|
68
|
-
//TODO: Make ModuleDescription into real payload
|
|
69
|
-
async describe() {
|
|
70
|
-
const queryPayload = {
|
|
71
|
-
schema: ModuleDescribeQuerySchema
|
|
72
|
-
};
|
|
73
|
-
return (await this.sendQuery(queryPayload))[0];
|
|
74
|
-
}
|
|
75
|
-
async discover() {
|
|
76
|
-
const queryPayload = {
|
|
77
|
-
schema: ModuleDiscoverQuerySchema
|
|
78
|
-
};
|
|
79
|
-
return await this.sendQuery(queryPayload);
|
|
80
|
-
}
|
|
81
|
-
emit(_eventName, _eventArgs) {
|
|
82
|
-
throw new Error("Unsupported");
|
|
83
|
-
}
|
|
84
|
-
emitSerial(_eventName, _eventArgs) {
|
|
85
|
-
throw new Error("Unsupported");
|
|
86
|
-
}
|
|
87
|
-
listenerCount(_eventNames) {
|
|
88
|
-
throw new Error("Unsupported");
|
|
89
|
-
}
|
|
90
|
-
async manifest(maxDepth) {
|
|
91
|
-
const queryPayload = {
|
|
92
|
-
schema: ModuleManifestQuerySchema,
|
|
93
|
-
...maxDepth === void 0 ? {} : {
|
|
94
|
-
maxDepth
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
return (await this.sendQuery(queryPayload))[0];
|
|
98
|
-
}
|
|
99
|
-
async moduleAddress() {
|
|
100
|
-
const queryPayload = {
|
|
101
|
-
schema: ModuleAddressQuerySchema
|
|
102
|
-
};
|
|
103
|
-
return await this.sendQuery(queryPayload);
|
|
104
|
-
}
|
|
105
|
-
off(_eventNames, _listener) {
|
|
106
|
-
throw new Error("Unsupported");
|
|
107
|
-
}
|
|
108
|
-
offAny(_listener) {
|
|
109
|
-
throw new Error("Unsupported");
|
|
110
|
-
}
|
|
111
|
-
on(_eventNames, _listener) {
|
|
112
|
-
throw new Error("Unsupported");
|
|
113
|
-
}
|
|
114
|
-
onAny(_listener) {
|
|
115
|
-
throw new Error("Unsupported");
|
|
116
|
-
}
|
|
117
|
-
once(_eventName, _listener) {
|
|
118
|
-
throw new Error("Unsupported");
|
|
119
|
-
}
|
|
120
|
-
async previousHash() {
|
|
121
|
-
const queryPayload = {
|
|
122
|
-
schema: ModuleAddressQuerySchema
|
|
123
|
-
};
|
|
124
|
-
return (await this.sendQuery(queryPayload)).pop().previousHash;
|
|
125
|
-
}
|
|
126
|
-
queryable(_query, _payloads) {
|
|
127
|
-
return true;
|
|
128
|
-
}
|
|
129
|
-
resolve(nameOrAddressOrFilter, _options) {
|
|
130
|
-
return typeof nameOrAddressOrFilter === "string" ? void 0 : [];
|
|
131
|
-
}
|
|
132
|
-
state() {
|
|
133
|
-
return [];
|
|
134
|
-
}
|
|
135
|
-
bindQuery(query, payloads, account = this.account) {
|
|
136
|
-
const promise = new PromiseEx(async (resolve) => {
|
|
137
|
-
const result = await this.bindQueryInternal(query, payloads, account);
|
|
138
|
-
resolve == null ? void 0 : resolve(result);
|
|
139
|
-
return result;
|
|
140
|
-
}, account);
|
|
141
|
-
return promise;
|
|
142
|
-
}
|
|
143
|
-
async bindQueryInternal(query, payloads, account = this.account) {
|
|
144
|
-
const builder = await new QueryBoundWitnessBuilder().payloads(payloads).query(query);
|
|
145
|
-
const result = await (account ? builder.witness(account) : builder).build();
|
|
146
|
-
return result;
|
|
147
|
-
}
|
|
148
|
-
async filterErrors(result) {
|
|
149
|
-
const wrapper = await BoundWitnessWrapper.wrap(result[0], result[1]);
|
|
150
|
-
return wrapper.payloadsBySchema(ModuleErrorSchema);
|
|
151
|
-
}
|
|
152
|
-
async sendQuery(queryPayload, payloads) {
|
|
153
|
-
const query = await this.bindQuery(queryPayload, payloads);
|
|
154
|
-
const [, resultPayloads, errors] = await this.query(query[0], query[1]);
|
|
155
|
-
if (errors && errors.length > 0) {
|
|
156
|
-
throw errors[0];
|
|
157
|
-
}
|
|
158
|
-
return resultPayloads;
|
|
159
|
-
}
|
|
11
|
+
var _AbstractModuleHost = class _AbstractModuleHost extends Base {
|
|
160
12
|
};
|
|
161
|
-
__name(
|
|
162
|
-
|
|
163
|
-
ModuleDiscoverQuerySchema
|
|
164
|
-
]);
|
|
165
|
-
var AbstractModuleProxy = _AbstractModuleProxy;
|
|
13
|
+
__name(_AbstractModuleHost, "AbstractModuleHost");
|
|
14
|
+
var AbstractModuleHost = _AbstractModuleHost;
|
|
166
15
|
|
|
167
16
|
// src/AsyncQueryBus/AsyncQueryBusClient.ts
|
|
168
17
|
import { delay } from "@xylabs/delay";
|
|
@@ -174,12 +23,13 @@ import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
|
174
23
|
import { LRUCache as LRUCache2 } from "lru-cache";
|
|
175
24
|
|
|
176
25
|
// src/AsyncQueryBus/AsyncQueryBusBase.ts
|
|
177
|
-
import { assertEx
|
|
26
|
+
import { assertEx } from "@xylabs/assert";
|
|
178
27
|
import { Base as Base2 } from "@xylabs/object";
|
|
179
28
|
import { asArchivistInstance } from "@xyo-network/archivist-model";
|
|
180
29
|
import { asDivinerInstance } from "@xyo-network/diviner-model";
|
|
181
30
|
import { LRUCache } from "lru-cache";
|
|
182
31
|
var _AsyncQueryBusBase = class _AsyncQueryBusBase extends Base2 {
|
|
32
|
+
_exposedAddresses = /* @__PURE__ */ new Set();
|
|
183
33
|
_lastState;
|
|
184
34
|
_targetConfigs = {};
|
|
185
35
|
_targetQueries = {};
|
|
@@ -207,34 +57,42 @@ var _AsyncQueryBusBase = class _AsyncQueryBusBase extends Base2 {
|
|
|
207
57
|
this._lastState = this._lastState ?? new LRUCache(requiredConfig);
|
|
208
58
|
return this._lastState;
|
|
209
59
|
}
|
|
60
|
+
expose(address, validate = true) {
|
|
61
|
+
assertEx(!validate || !this._exposedAddresses.has(address), () => `Address already exposed [${address}]`);
|
|
62
|
+
this._exposedAddresses.add(address);
|
|
63
|
+
}
|
|
210
64
|
async queriesArchivist() {
|
|
211
65
|
var _a, _b, _c;
|
|
212
|
-
return
|
|
66
|
+
return assertEx(asArchivistInstance(await this.resolver.resolve((_c = (_b = (_a = this.config) == null ? void 0 : _a.intersect) == null ? void 0 : _b.queries) == null ? void 0 : _c.archivist)), () => {
|
|
213
67
|
var _a2, _b2, _c2;
|
|
214
68
|
return `Unable to resolve queriesArchivist [${(_c2 = (_b2 = (_a2 = this.config) == null ? void 0 : _a2.intersect) == null ? void 0 : _b2.queries) == null ? void 0 : _c2.archivist}]`;
|
|
215
69
|
});
|
|
216
70
|
}
|
|
217
71
|
async queriesDiviner() {
|
|
218
72
|
var _a, _b, _c;
|
|
219
|
-
return
|
|
73
|
+
return assertEx(asDivinerInstance(await this.resolver.resolve((_c = (_b = (_a = this.config) == null ? void 0 : _a.intersect) == null ? void 0 : _b.queries) == null ? void 0 : _c.boundWitnessDiviner)), () => {
|
|
220
74
|
var _a2, _b2, _c2;
|
|
221
75
|
return `Unable to resolve queriesDiviner [${(_c2 = (_b2 = (_a2 = this.config) == null ? void 0 : _a2.intersect) == null ? void 0 : _b2.queries) == null ? void 0 : _c2.boundWitnessDiviner}]`;
|
|
222
76
|
});
|
|
223
77
|
}
|
|
224
78
|
async responsesArchivist() {
|
|
225
79
|
var _a, _b, _c;
|
|
226
|
-
return
|
|
80
|
+
return assertEx(asArchivistInstance(await this.resolver.resolve((_c = (_b = (_a = this.config) == null ? void 0 : _a.intersect) == null ? void 0 : _b.responses) == null ? void 0 : _c.archivist)), () => {
|
|
227
81
|
var _a2, _b2, _c2;
|
|
228
82
|
return `Unable to resolve responsesArchivist [${(_c2 = (_b2 = (_a2 = this.config) == null ? void 0 : _a2.intersect) == null ? void 0 : _b2.responses) == null ? void 0 : _c2.archivist}]`;
|
|
229
83
|
});
|
|
230
84
|
}
|
|
231
85
|
async responsesDiviner() {
|
|
232
86
|
var _a, _b, _c;
|
|
233
|
-
return
|
|
87
|
+
return assertEx(asDivinerInstance(await this.resolver.resolve((_c = (_b = (_a = this.config) == null ? void 0 : _a.intersect) == null ? void 0 : _b.responses) == null ? void 0 : _c.boundWitnessDiviner)), () => {
|
|
234
88
|
var _a2, _b2, _c2;
|
|
235
89
|
return `Unable to resolve responsesDiviner [${(_c2 = (_b2 = (_a2 = this.config) == null ? void 0 : _a2.intersect) == null ? void 0 : _b2.responses) == null ? void 0 : _c2.boundWitnessDiviner}]`;
|
|
236
90
|
});
|
|
237
91
|
}
|
|
92
|
+
unexpose(address, validate = true) {
|
|
93
|
+
assertEx(!validate || this._exposedAddresses.has(address), () => `Address not exposed [${address}]`);
|
|
94
|
+
this._exposedAddresses.delete(address);
|
|
95
|
+
}
|
|
238
96
|
/**
|
|
239
97
|
* Commit the internal state of the process. This is similar
|
|
240
98
|
* to a transaction completion in a database and should only be called
|
|
@@ -460,7 +318,7 @@ var AsyncQueryBusClient = _AsyncQueryBusClient;
|
|
|
460
318
|
|
|
461
319
|
// src/AsyncQueryBus/AsyncQueryBusHost.ts
|
|
462
320
|
import { containsAll } from "@xylabs/array";
|
|
463
|
-
import { assertEx as
|
|
321
|
+
import { assertEx as assertEx2 } from "@xylabs/assert";
|
|
464
322
|
import { clearTimeoutEx as clearTimeoutEx2, setTimeoutEx as setTimeoutEx2 } from "@xylabs/timer";
|
|
465
323
|
import { isQueryBoundWitnessWithMeta } from "@xyo-network/boundwitness-model";
|
|
466
324
|
import { BoundWitnessDivinerQuerySchema as BoundWitnessDivinerQuerySchema2 } from "@xyo-network/diviner-boundwitness-model";
|
|
@@ -480,7 +338,7 @@ var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
|
|
|
480
338
|
}
|
|
481
339
|
async listeningModules() {
|
|
482
340
|
var _a;
|
|
483
|
-
const mods = ((_a = this.config) == null ? void 0 : _a.listeningModules) ? await Promise.all(this.config.listeningModules.map(async (listeningModule) =>
|
|
341
|
+
const mods = ((_a = this.config) == null ? void 0 : _a.listeningModules) ? await Promise.all(this.config.listeningModules.map(async (listeningModule) => assertEx2(asModuleInstance(await this.resolver.resolve(listeningModule)), () => `Unable to resolve listeningModule [${listeningModule}]`))) : await this.resolver.resolve(void 0, {
|
|
484
342
|
direction: "down"
|
|
485
343
|
});
|
|
486
344
|
return mods;
|
|
@@ -504,38 +362,39 @@ var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
|
|
|
504
362
|
const localModuleName = localModule.config.name ?? localModule.address;
|
|
505
363
|
const queryArchivist = await this.queriesArchivist();
|
|
506
364
|
const responseArchivist = await this.responsesArchivist();
|
|
507
|
-
const
|
|
508
|
-
if (
|
|
365
|
+
const queryDestination = (_a = query.$meta) == null ? void 0 : _a.destination;
|
|
366
|
+
if (queryDestination && (queryDestination == null ? void 0 : queryDestination.includes(localModule.address))) {
|
|
509
367
|
const queryIndex = query.payload_hashes.indexOf(query.query);
|
|
510
368
|
if (queryIndex !== -1) {
|
|
511
369
|
const querySchema = query.payload_schemas[queryIndex];
|
|
512
370
|
if (localModule.queries.includes(querySchema)) {
|
|
513
|
-
const
|
|
514
|
-
const
|
|
515
|
-
const
|
|
516
|
-
if (!containsAll(Object.keys(
|
|
517
|
-
(_b = this.logger) == null ? void 0 : _b.error(`Error processing command ${
|
|
371
|
+
const queryPayloads = await queryArchivist.get(query.payload_hashes);
|
|
372
|
+
const queryPayloadsDict = await PayloadBuilder2.toAllHashMap(queryPayloads);
|
|
373
|
+
const queryHash = (await PayloadBuilder2.build(query)).$hash;
|
|
374
|
+
if (!containsAll(Object.keys(queryPayloadsDict), query.payload_hashes)) {
|
|
375
|
+
(_b = this.logger) == null ? void 0 : _b.error(`Error processing command ${queryHash} for module ${localModuleName}, missing payloads`);
|
|
518
376
|
return;
|
|
519
377
|
}
|
|
520
378
|
try {
|
|
521
|
-
const
|
|
522
|
-
(_c = this.logger) == null ? void 0 : _c.debug(`Issuing
|
|
523
|
-
const response = await localModule.query(query,
|
|
379
|
+
const querySchema2 = queryPayloadsDict[query.query].schema;
|
|
380
|
+
(_c = this.logger) == null ? void 0 : _c.debug(`Issuing query ${querySchema2} (${queryHash}) addressed to module: ${localModuleName}`);
|
|
381
|
+
const response = await localModule.query(query, queryPayloads);
|
|
524
382
|
const [bw, payloads, errors] = response;
|
|
525
|
-
(_d = this.logger) == null ? void 0 : _d.debug(`Replying to
|
|
383
|
+
(_d = this.logger) == null ? void 0 : _d.debug(`Replying to query ${queryHash} addressed to module: ${localModuleName}`);
|
|
526
384
|
const insertResult = await responseArchivist.insert([
|
|
527
385
|
bw,
|
|
528
386
|
...payloads,
|
|
529
387
|
...errors
|
|
530
388
|
]);
|
|
531
389
|
if (insertResult.length === 0) {
|
|
532
|
-
(_e = this.logger) == null ? void 0 : _e.error(`Error replying to
|
|
390
|
+
(_e = this.logger) == null ? void 0 : _e.error(`Error replying to query ${queryHash} addressed to module: ${localModuleName}`);
|
|
533
391
|
}
|
|
534
392
|
if (query == null ? void 0 : query.timestamp) {
|
|
535
393
|
await this.commitState(localModule.address, query.timestamp);
|
|
536
394
|
}
|
|
537
395
|
} catch (error) {
|
|
538
|
-
(_f = this.logger) == null ? void 0 : _f.error(`Error processing
|
|
396
|
+
(_f = this.logger) == null ? void 0 : _f.error(`Error processing query ${queryHash} for module ${localModuleName}: ${error}`);
|
|
397
|
+
console.error(`Error processing query ${queryHash} for module ${localModuleName}: ${error}`);
|
|
539
398
|
}
|
|
540
399
|
}
|
|
541
400
|
}
|
|
@@ -587,26 +446,26 @@ var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
|
|
|
587
446
|
}, this.pollFrequencyConfig);
|
|
588
447
|
}
|
|
589
448
|
/**
|
|
590
|
-
* Background process for checking for inbound
|
|
449
|
+
* Background process for checking for inbound queries
|
|
591
450
|
*/
|
|
592
451
|
processIncomingQueries = async () => {
|
|
593
452
|
var _a;
|
|
594
|
-
(_a = this.logger) == null ? void 0 : _a.debug("Checking for inbound
|
|
453
|
+
(_a = this.logger) == null ? void 0 : _a.debug("Checking for inbound queries");
|
|
595
454
|
const localModules = await this.listeningModules();
|
|
596
455
|
await Promise.allSettled(localModules.map(async (localModule) => {
|
|
597
456
|
var _a2, _b, _c;
|
|
598
457
|
try {
|
|
599
458
|
const localModuleName = localModule.config.name ?? localModule.address;
|
|
600
|
-
(_a2 = this.logger) == null ? void 0 : _a2.debug(`Checking for inbound
|
|
459
|
+
(_a2 = this.logger) == null ? void 0 : _a2.debug(`Checking for inbound queries to ${localModuleName}`);
|
|
601
460
|
const queries = await this.findQueriesToAddress(localModule.address);
|
|
602
461
|
if (queries.length === 0)
|
|
603
462
|
return;
|
|
604
|
-
(_b = this.logger) == null ? void 0 : _b.debug(`Found
|
|
463
|
+
(_b = this.logger) == null ? void 0 : _b.debug(`Found queries addressed to local module: ${localModuleName}`);
|
|
605
464
|
for (const query of queries) {
|
|
606
465
|
await this.callLocalModule(localModule, query);
|
|
607
466
|
}
|
|
608
467
|
} catch (error) {
|
|
609
|
-
(_c = this.logger) == null ? void 0 : _c.error(`Error processing
|
|
468
|
+
(_c = this.logger) == null ? void 0 : _c.error(`Error processing queries for address ${localModule.address}: ${error}`);
|
|
610
469
|
}
|
|
611
470
|
}));
|
|
612
471
|
};
|
|
@@ -614,13 +473,6 @@ var _AsyncQueryBusHost = class _AsyncQueryBusHost extends AsyncQueryBusBase {
|
|
|
614
473
|
__name(_AsyncQueryBusHost, "AsyncQueryBusHost");
|
|
615
474
|
var AsyncQueryBusHost = _AsyncQueryBusHost;
|
|
616
475
|
|
|
617
|
-
// src/AbstractModuleHost/AbstractModuleHost.ts
|
|
618
|
-
import { Base as Base3 } from "@xylabs/object";
|
|
619
|
-
var _AbstractModuleHost = class _AbstractModuleHost extends Base3 {
|
|
620
|
-
};
|
|
621
|
-
__name(_AbstractModuleHost, "AbstractModuleHost");
|
|
622
|
-
var AbstractModuleHost = _AbstractModuleHost;
|
|
623
|
-
|
|
624
476
|
// src/AsyncQueryBus/ModuleHost/ModuleHost.ts
|
|
625
477
|
var _AsyncQueryBusModuleHost = class _AsyncQueryBusModuleHost extends AbstractModuleHost {
|
|
626
478
|
_busHost;
|
|
@@ -651,6 +503,7 @@ __name(_AsyncQueryBusModuleHost, "AsyncQueryBusModuleHost");
|
|
|
651
503
|
var AsyncQueryBusModuleHost = _AsyncQueryBusModuleHost;
|
|
652
504
|
|
|
653
505
|
// src/AsyncQueryBus/ModuleProxy/ModuleProxy.ts
|
|
506
|
+
import { AbstractModuleProxy } from "@xyo-network/abstract-bridge";
|
|
654
507
|
var _AsyncQueryBusModuleProxy = class _AsyncQueryBusModuleProxy extends AbstractModuleProxy {
|
|
655
508
|
async query(query, payloads) {
|
|
656
509
|
return await this.proxyParams.busClient.send(this.address, query, payloads);
|
|
@@ -666,12 +519,10 @@ var PubSubBridgeSchema = "network.xyo.bridge.pubsub";
|
|
|
666
519
|
var PubSubBridgeConfigSchema = `${PubSubBridgeSchema}.config`;
|
|
667
520
|
|
|
668
521
|
// src/PubSubBridge.ts
|
|
669
|
-
import { assertEx as
|
|
670
|
-
import { isAddress } from "@xylabs/hex";
|
|
522
|
+
import { assertEx as assertEx3 } from "@xylabs/assert";
|
|
671
523
|
import { AbstractBridge } from "@xyo-network/abstract-bridge";
|
|
672
524
|
import { Account } from "@xyo-network/account";
|
|
673
|
-
import {
|
|
674
|
-
import { creatableModule, ModuleConfigSchema as ModuleConfigSchema2 } from "@xyo-network/module-model";
|
|
525
|
+
import { creatableModule } from "@xyo-network/module-model";
|
|
675
526
|
function _ts_decorate(decorators, target, key, desc) {
|
|
676
527
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
677
528
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -688,74 +539,51 @@ var _PubSubBridge = class _PubSubBridge extends AbstractBridge {
|
|
|
688
539
|
_configRootAddress = "";
|
|
689
540
|
_configStateStoreArchivist = "";
|
|
690
541
|
_configStateStoreBoundWitnessDiviner = "";
|
|
542
|
+
_exposedAddresses = [];
|
|
691
543
|
_lastState;
|
|
692
544
|
_busClient;
|
|
693
545
|
_busHost;
|
|
694
546
|
get moduleName() {
|
|
695
547
|
return `${this.config.name ?? moduleName}`;
|
|
696
548
|
}
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
}
|
|
709
|
-
getRootAddress() {
|
|
710
|
-
return this.rootAddress;
|
|
711
|
-
}
|
|
712
|
-
async resolve(idOrFilter, _options) {
|
|
713
|
-
if (idOrFilter === void 0) {
|
|
714
|
-
return [];
|
|
715
|
-
}
|
|
716
|
-
if (typeof idOrFilter === "string") {
|
|
717
|
-
const upResolve = await this.upResolver.resolve(idOrFilter);
|
|
718
|
-
if (upResolve)
|
|
719
|
-
return upResolve;
|
|
720
|
-
assertEx4(!isAddress(idOrFilter), "Name resolutions not supported");
|
|
721
|
-
const params = {
|
|
722
|
-
account: Account.randomSync(),
|
|
723
|
-
busClient: assertEx4(this.busClient(), "Bus client not initialized"),
|
|
724
|
-
moduleAddress: idOrFilter,
|
|
725
|
-
queries: []
|
|
726
|
-
};
|
|
727
|
-
return await Promise.resolve(new AsyncQueryBusModuleProxy(params));
|
|
728
|
-
} else {
|
|
729
|
-
throw new TypeError("Filter not Supported");
|
|
549
|
+
async exposeHandler(id, options) {
|
|
550
|
+
const filterOptions = {
|
|
551
|
+
direction: options == null ? void 0 : options.direction
|
|
552
|
+
};
|
|
553
|
+
const module = await super.resolve(id, filterOptions);
|
|
554
|
+
if (module) {
|
|
555
|
+
const host = assertEx3(this.busHost(), "Not configured as a host");
|
|
556
|
+
host.expose(module.address);
|
|
557
|
+
return [
|
|
558
|
+
module.address
|
|
559
|
+
];
|
|
730
560
|
}
|
|
561
|
+
return [];
|
|
731
562
|
}
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
563
|
+
resolveHandler(id, _options) {
|
|
564
|
+
const account = Account.randomSync();
|
|
565
|
+
const params = {
|
|
566
|
+
account,
|
|
567
|
+
bridge: this,
|
|
568
|
+
busClient: assertEx3(this.busClient(), "Bus client not initialized"),
|
|
569
|
+
moduleAddress: id
|
|
735
570
|
};
|
|
571
|
+
return new AsyncQueryBusModuleProxy(params);
|
|
736
572
|
}
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
name: "",
|
|
741
|
-
schema: ModuleConfigSchema2
|
|
742
|
-
},
|
|
743
|
-
schema: ModuleManifestPayloadSchema
|
|
573
|
+
async unexposeHandler(id, options) {
|
|
574
|
+
const filterOptions = {
|
|
575
|
+
direction: options == null ? void 0 : options.direction
|
|
744
576
|
};
|
|
745
|
-
|
|
746
|
-
|
|
577
|
+
const module = await super.resolve(id, filterOptions);
|
|
578
|
+
if (module) {
|
|
579
|
+
const host = assertEx3(this.busHost(), "Not configured as a host");
|
|
580
|
+
host.unexpose(module.address);
|
|
581
|
+
return [
|
|
582
|
+
module.address
|
|
583
|
+
];
|
|
584
|
+
}
|
|
747
585
|
return [];
|
|
748
586
|
}
|
|
749
|
-
async targetQuery(address, query, payloads) {
|
|
750
|
-
if (!this.connected)
|
|
751
|
-
throw new Error("Not connected");
|
|
752
|
-
await this.started("throw");
|
|
753
|
-
const bus = assertEx4(this.busClient(), "Client not configured");
|
|
754
|
-
return bus == null ? void 0 : bus.send(address, query, payloads);
|
|
755
|
-
}
|
|
756
|
-
targetQueryable(_address, _query, _payloads, _queryConfig) {
|
|
757
|
-
return true;
|
|
758
|
-
}
|
|
759
587
|
busClient() {
|
|
760
588
|
if (!this._busClient && this.config.client) {
|
|
761
589
|
this._busClient = new AsyncQueryBusClient({
|
|
@@ -776,11 +604,10 @@ var _PubSubBridge = class _PubSubBridge extends AbstractBridge {
|
|
|
776
604
|
}
|
|
777
605
|
return this._busHost;
|
|
778
606
|
}
|
|
779
|
-
|
|
607
|
+
startHandler() {
|
|
780
608
|
var _a;
|
|
781
|
-
await Promise.resolve(this.connect());
|
|
782
609
|
(_a = this.busHost()) == null ? void 0 : _a.start();
|
|
783
|
-
return true;
|
|
610
|
+
return Promise.resolve(true);
|
|
784
611
|
}
|
|
785
612
|
stopHandler(_timeout) {
|
|
786
613
|
var _a;
|
|
@@ -797,7 +624,7 @@ PubSubBridge = _ts_decorate([
|
|
|
797
624
|
creatableModule()
|
|
798
625
|
], PubSubBridge);
|
|
799
626
|
export {
|
|
800
|
-
|
|
627
|
+
AbstractModuleHost,
|
|
801
628
|
AsyncQueryBusClient,
|
|
802
629
|
AsyncQueryBusHost,
|
|
803
630
|
AsyncQueryBusModuleHost,
|