@xyo-network/bridge-pub-sub 2.91.0 → 2.91.1
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/AbstractModuleHost/AbstractModuleHost.d.cts +11 -0
- package/dist/browser/AbstractModuleHost/AbstractModuleHost.d.cts.map +1 -0
- package/dist/browser/AbstractModuleHost/AbstractModuleHost.d.mts +11 -0
- package/dist/browser/AbstractModuleHost/AbstractModuleHost.d.mts.map +1 -0
- package/dist/browser/AbstractModuleHost/AbstractModuleHost.d.ts +11 -0
- package/dist/browser/AbstractModuleHost/AbstractModuleHost.d.ts.map +1 -0
- package/dist/browser/AbstractModuleHost/index.d.cts +2 -0
- package/dist/browser/AbstractModuleHost/index.d.cts.map +1 -0
- package/dist/browser/AbstractModuleHost/index.d.mts +2 -0
- package/dist/browser/AbstractModuleHost/index.d.mts.map +1 -0
- package/dist/browser/AbstractModuleHost/index.d.ts +2 -0
- package/dist/browser/AbstractModuleHost/index.d.ts.map +1 -0
- package/dist/browser/AbstractModuleProxy/AbstractModuleProxy.d.cts +90 -0
- package/dist/browser/AbstractModuleProxy/AbstractModuleProxy.d.cts.map +1 -0
- package/dist/browser/AbstractModuleProxy/AbstractModuleProxy.d.mts +90 -0
- package/dist/browser/AbstractModuleProxy/AbstractModuleProxy.d.mts.map +1 -0
- package/dist/browser/AbstractModuleProxy/AbstractModuleProxy.d.ts +90 -0
- package/dist/browser/AbstractModuleProxy/AbstractModuleProxy.d.ts.map +1 -0
- package/dist/browser/AbstractModuleProxy/index.d.cts +2 -0
- package/dist/browser/AbstractModuleProxy/index.d.cts.map +1 -0
- package/dist/browser/AbstractModuleProxy/index.d.mts +2 -0
- package/dist/browser/AbstractModuleProxy/index.d.mts.map +1 -0
- package/dist/browser/AbstractModuleProxy/index.d.ts +2 -0
- package/dist/browser/AbstractModuleProxy/index.d.ts.map +1 -0
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.cts +51 -15
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.cts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.mts +51 -15
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.mts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.ts +51 -15
- package/dist/browser/AsyncQueryBus/AsyncQueryBusBase.d.ts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusClient.d.cts +14 -45
- package/dist/browser/AsyncQueryBus/AsyncQueryBusClient.d.cts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusClient.d.mts +14 -45
- package/dist/browser/AsyncQueryBus/AsyncQueryBusClient.d.mts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusClient.d.ts +14 -45
- package/dist/browser/AsyncQueryBus/AsyncQueryBusClient.d.ts.map +1 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.cts +37 -0
- package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.cts.map +1 -0
- package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.mts +37 -0
- package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.mts.map +1 -0
- package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.ts +37 -0
- package/dist/browser/AsyncQueryBus/AsyncQueryBusHost.d.ts.map +1 -0
- package/dist/browser/AsyncQueryBus/Config.d.cts +21 -31
- package/dist/browser/AsyncQueryBus/Config.d.cts.map +1 -1
- package/dist/browser/AsyncQueryBus/Config.d.mts +21 -31
- package/dist/browser/AsyncQueryBus/Config.d.mts.map +1 -1
- package/dist/browser/AsyncQueryBus/Config.d.ts +21 -31
- package/dist/browser/AsyncQueryBus/Config.d.ts.map +1 -1
- package/dist/browser/AsyncQueryBus/ModuleHost/ModuleHost.d.cts +12 -0
- package/dist/browser/AsyncQueryBus/ModuleHost/ModuleHost.d.cts.map +1 -0
- package/dist/browser/AsyncQueryBus/ModuleHost/ModuleHost.d.mts +12 -0
- package/dist/browser/AsyncQueryBus/ModuleHost/ModuleHost.d.mts.map +1 -0
- package/dist/browser/AsyncQueryBus/ModuleHost/ModuleHost.d.ts +12 -0
- package/dist/browser/AsyncQueryBus/ModuleHost/ModuleHost.d.ts.map +1 -0
- package/dist/browser/AsyncQueryBus/ModuleHost/index.d.cts +2 -0
- package/dist/browser/AsyncQueryBus/ModuleHost/index.d.cts.map +1 -0
- package/dist/browser/AsyncQueryBus/ModuleHost/index.d.mts +2 -0
- package/dist/browser/AsyncQueryBus/ModuleHost/index.d.mts.map +1 -0
- package/dist/browser/AsyncQueryBus/ModuleHost/index.d.ts +2 -0
- package/dist/browser/AsyncQueryBus/ModuleHost/index.d.ts.map +1 -0
- package/dist/browser/AsyncQueryBus/ModuleProxy/ModuleProxy.d.cts +12 -0
- package/dist/browser/AsyncQueryBus/ModuleProxy/ModuleProxy.d.cts.map +1 -0
- package/dist/browser/AsyncQueryBus/ModuleProxy/ModuleProxy.d.mts +12 -0
- package/dist/browser/AsyncQueryBus/ModuleProxy/ModuleProxy.d.mts.map +1 -0
- package/dist/browser/AsyncQueryBus/ModuleProxy/ModuleProxy.d.ts +12 -0
- package/dist/browser/AsyncQueryBus/ModuleProxy/ModuleProxy.d.ts.map +1 -0
- package/dist/browser/AsyncQueryBus/ModuleProxy/index.d.cts +2 -0
- package/dist/browser/AsyncQueryBus/ModuleProxy/index.d.cts.map +1 -0
- package/dist/browser/AsyncQueryBus/ModuleProxy/index.d.mts +2 -0
- package/dist/browser/AsyncQueryBus/ModuleProxy/index.d.mts.map +1 -0
- package/dist/browser/AsyncQueryBus/ModuleProxy/index.d.ts +2 -0
- package/dist/browser/AsyncQueryBus/ModuleProxy/index.d.ts.map +1 -0
- package/dist/browser/AsyncQueryBus/Params.d.cts +5 -3
- package/dist/browser/AsyncQueryBus/Params.d.cts.map +1 -1
- package/dist/browser/AsyncQueryBus/Params.d.mts +5 -3
- package/dist/browser/AsyncQueryBus/Params.d.mts.map +1 -1
- package/dist/browser/AsyncQueryBus/Params.d.ts +5 -3
- package/dist/browser/AsyncQueryBus/Params.d.ts.map +1 -1
- package/dist/browser/AsyncQueryBus/index.d.cts +3 -1
- package/dist/browser/AsyncQueryBus/index.d.cts.map +1 -1
- package/dist/browser/AsyncQueryBus/index.d.mts +3 -1
- package/dist/browser/AsyncQueryBus/index.d.mts.map +1 -1
- package/dist/browser/AsyncQueryBus/index.d.ts +3 -1
- package/dist/browser/AsyncQueryBus/index.d.ts.map +1 -1
- package/dist/browser/Config.d.cts +5 -2
- package/dist/browser/Config.d.cts.map +1 -1
- package/dist/browser/Config.d.mts +5 -2
- package/dist/browser/Config.d.mts.map +1 -1
- package/dist/browser/Config.d.ts +5 -2
- package/dist/browser/Config.d.ts.map +1 -1
- package/dist/browser/PubSubBridge.d.cts +4 -10
- package/dist/browser/PubSubBridge.d.cts.map +1 -1
- package/dist/browser/PubSubBridge.d.mts +4 -10
- package/dist/browser/PubSubBridge.d.mts.map +1 -1
- package/dist/browser/PubSubBridge.d.ts +4 -10
- package/dist/browser/PubSubBridge.d.ts.map +1 -1
- package/dist/browser/index.cjs +331 -126
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.d.cts +1 -0
- package/dist/browser/index.d.cts.map +1 -1
- package/dist/browser/index.d.mts +1 -0
- package/dist/browser/index.d.mts.map +1 -1
- package/dist/browser/index.d.ts +1 -0
- package/dist/browser/index.d.ts.map +1 -1
- package/dist/browser/index.js +332 -127
- package/dist/browser/index.js.map +1 -1
- package/dist/node/AbstractModuleHost/AbstractModuleHost.d.cts +11 -0
- package/dist/node/AbstractModuleHost/AbstractModuleHost.d.cts.map +1 -0
- package/dist/node/AbstractModuleHost/AbstractModuleHost.d.mts +11 -0
- package/dist/node/AbstractModuleHost/AbstractModuleHost.d.mts.map +1 -0
- package/dist/node/AbstractModuleHost/AbstractModuleHost.d.ts +11 -0
- package/dist/node/AbstractModuleHost/AbstractModuleHost.d.ts.map +1 -0
- package/dist/node/AbstractModuleHost/index.d.cts +2 -0
- package/dist/node/AbstractModuleHost/index.d.cts.map +1 -0
- package/dist/node/AbstractModuleHost/index.d.mts +2 -0
- package/dist/node/AbstractModuleHost/index.d.mts.map +1 -0
- package/dist/node/AbstractModuleHost/index.d.ts +2 -0
- package/dist/node/AbstractModuleHost/index.d.ts.map +1 -0
- package/dist/node/AbstractModuleProxy/AbstractModuleProxy.d.cts +90 -0
- package/dist/node/AbstractModuleProxy/AbstractModuleProxy.d.cts.map +1 -0
- package/dist/node/AbstractModuleProxy/AbstractModuleProxy.d.mts +90 -0
- package/dist/node/AbstractModuleProxy/AbstractModuleProxy.d.mts.map +1 -0
- package/dist/node/AbstractModuleProxy/AbstractModuleProxy.d.ts +90 -0
- package/dist/node/AbstractModuleProxy/AbstractModuleProxy.d.ts.map +1 -0
- package/dist/node/AbstractModuleProxy/index.d.cts +2 -0
- package/dist/node/AbstractModuleProxy/index.d.cts.map +1 -0
- package/dist/node/AbstractModuleProxy/index.d.mts +2 -0
- package/dist/node/AbstractModuleProxy/index.d.mts.map +1 -0
- package/dist/node/AbstractModuleProxy/index.d.ts +2 -0
- package/dist/node/AbstractModuleProxy/index.d.ts.map +1 -0
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.cts +51 -15
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.cts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.mts +51 -15
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.mts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.ts +51 -15
- package/dist/node/AsyncQueryBus/AsyncQueryBusBase.d.ts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusClient.d.cts +14 -45
- package/dist/node/AsyncQueryBus/AsyncQueryBusClient.d.cts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusClient.d.mts +14 -45
- package/dist/node/AsyncQueryBus/AsyncQueryBusClient.d.mts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusClient.d.ts +14 -45
- package/dist/node/AsyncQueryBus/AsyncQueryBusClient.d.ts.map +1 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.cts +37 -0
- package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.cts.map +1 -0
- package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.mts +37 -0
- package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.mts.map +1 -0
- package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.ts +37 -0
- package/dist/node/AsyncQueryBus/AsyncQueryBusHost.d.ts.map +1 -0
- package/dist/node/AsyncQueryBus/Config.d.cts +21 -31
- package/dist/node/AsyncQueryBus/Config.d.cts.map +1 -1
- package/dist/node/AsyncQueryBus/Config.d.mts +21 -31
- package/dist/node/AsyncQueryBus/Config.d.mts.map +1 -1
- package/dist/node/AsyncQueryBus/Config.d.ts +21 -31
- package/dist/node/AsyncQueryBus/Config.d.ts.map +1 -1
- package/dist/node/AsyncQueryBus/ModuleHost/ModuleHost.d.cts +12 -0
- package/dist/node/AsyncQueryBus/ModuleHost/ModuleHost.d.cts.map +1 -0
- package/dist/node/AsyncQueryBus/ModuleHost/ModuleHost.d.mts +12 -0
- package/dist/node/AsyncQueryBus/ModuleHost/ModuleHost.d.mts.map +1 -0
- package/dist/node/AsyncQueryBus/ModuleHost/ModuleHost.d.ts +12 -0
- package/dist/node/AsyncQueryBus/ModuleHost/ModuleHost.d.ts.map +1 -0
- package/dist/node/AsyncQueryBus/ModuleHost/index.d.cts +2 -0
- package/dist/node/AsyncQueryBus/ModuleHost/index.d.cts.map +1 -0
- package/dist/node/AsyncQueryBus/ModuleHost/index.d.mts +2 -0
- package/dist/node/AsyncQueryBus/ModuleHost/index.d.mts.map +1 -0
- package/dist/node/AsyncQueryBus/ModuleHost/index.d.ts +2 -0
- package/dist/node/AsyncQueryBus/ModuleHost/index.d.ts.map +1 -0
- package/dist/node/AsyncQueryBus/ModuleProxy/ModuleProxy.d.cts +12 -0
- package/dist/node/AsyncQueryBus/ModuleProxy/ModuleProxy.d.cts.map +1 -0
- package/dist/node/AsyncQueryBus/ModuleProxy/ModuleProxy.d.mts +12 -0
- package/dist/node/AsyncQueryBus/ModuleProxy/ModuleProxy.d.mts.map +1 -0
- package/dist/node/AsyncQueryBus/ModuleProxy/ModuleProxy.d.ts +12 -0
- package/dist/node/AsyncQueryBus/ModuleProxy/ModuleProxy.d.ts.map +1 -0
- package/dist/node/AsyncQueryBus/ModuleProxy/index.d.cts +2 -0
- package/dist/node/AsyncQueryBus/ModuleProxy/index.d.cts.map +1 -0
- package/dist/node/AsyncQueryBus/ModuleProxy/index.d.mts +2 -0
- package/dist/node/AsyncQueryBus/ModuleProxy/index.d.mts.map +1 -0
- package/dist/node/AsyncQueryBus/ModuleProxy/index.d.ts +2 -0
- package/dist/node/AsyncQueryBus/ModuleProxy/index.d.ts.map +1 -0
- package/dist/node/AsyncQueryBus/Params.d.cts +5 -3
- package/dist/node/AsyncQueryBus/Params.d.cts.map +1 -1
- package/dist/node/AsyncQueryBus/Params.d.mts +5 -3
- package/dist/node/AsyncQueryBus/Params.d.mts.map +1 -1
- package/dist/node/AsyncQueryBus/Params.d.ts +5 -3
- package/dist/node/AsyncQueryBus/Params.d.ts.map +1 -1
- package/dist/node/AsyncQueryBus/index.d.cts +3 -1
- package/dist/node/AsyncQueryBus/index.d.cts.map +1 -1
- package/dist/node/AsyncQueryBus/index.d.mts +3 -1
- package/dist/node/AsyncQueryBus/index.d.mts.map +1 -1
- package/dist/node/AsyncQueryBus/index.d.ts +3 -1
- package/dist/node/AsyncQueryBus/index.d.ts.map +1 -1
- package/dist/node/Config.d.cts +5 -2
- package/dist/node/Config.d.cts.map +1 -1
- package/dist/node/Config.d.mts +5 -2
- package/dist/node/Config.d.mts.map +1 -1
- package/dist/node/Config.d.ts +5 -2
- package/dist/node/Config.d.ts.map +1 -1
- package/dist/node/PubSubBridge.d.cts +4 -10
- package/dist/node/PubSubBridge.d.cts.map +1 -1
- package/dist/node/PubSubBridge.d.mts +4 -10
- package/dist/node/PubSubBridge.d.mts.map +1 -1
- package/dist/node/PubSubBridge.d.ts +4 -10
- package/dist/node/PubSubBridge.d.ts.map +1 -1
- package/dist/node/index.cjs +355 -144
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.d.cts +1 -0
- package/dist/node/index.d.cts.map +1 -1
- package/dist/node/index.d.mts +1 -0
- package/dist/node/index.d.mts.map +1 -1
- package/dist/node/index.d.ts +1 -0
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +352 -144
- package/dist/node/index.js.map +1 -1
- package/package.json +30 -24
- package/src/AbstractModuleHost/AbstractModuleHost.ts +12 -0
- package/src/AbstractModuleHost/index.ts +1 -0
- package/src/AbstractModuleProxy/AbstractModuleProxy.ts +239 -0
- package/src/AbstractModuleProxy/index.ts +1 -0
- package/src/AsyncQueryBus/AsyncQueryBusBase.ts +11 -33
- package/src/AsyncQueryBus/AsyncQueryBusClient.ts +69 -61
- package/src/AsyncQueryBus/{AsyncQueryBusServer.ts → AsyncQueryBusHost.ts} +32 -26
- package/src/AsyncQueryBus/Config.ts +23 -33
- package/src/AsyncQueryBus/ModuleHost/ModuleHost.ts +29 -0
- package/src/AsyncQueryBus/ModuleHost/index.ts +1 -0
- package/src/AsyncQueryBus/ModuleProxy/ModuleProxy.ts +19 -0
- package/src/AsyncQueryBus/ModuleProxy/index.ts +1 -0
- package/src/AsyncQueryBus/Params.ts +6 -3
- package/src/AsyncQueryBus/index.ts +3 -1
- package/src/Config.ts +5 -2
- package/src/PubSubBridge.ts +10 -12
- package/src/index.ts +1 -0
- package/dist/browser/AsyncQueryBus/AsyncQueryBusServer.d.cts +0 -75
- package/dist/browser/AsyncQueryBus/AsyncQueryBusServer.d.cts.map +0 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusServer.d.mts +0 -75
- package/dist/browser/AsyncQueryBus/AsyncQueryBusServer.d.mts.map +0 -1
- package/dist/browser/AsyncQueryBus/AsyncQueryBusServer.d.ts +0 -75
- package/dist/browser/AsyncQueryBus/AsyncQueryBusServer.d.ts.map +0 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusServer.d.cts +0 -75
- package/dist/node/AsyncQueryBus/AsyncQueryBusServer.d.cts.map +0 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusServer.d.mts +0 -75
- package/dist/node/AsyncQueryBus/AsyncQueryBusServer.d.mts.map +0 -1
- package/dist/node/AsyncQueryBus/AsyncQueryBusServer.d.ts +0 -75
- package/dist/node/AsyncQueryBus/AsyncQueryBusServer.d.ts.map +0 -1
package/dist/browser/index.js
CHANGED
|
@@ -1,28 +1,185 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
|
|
4
|
+
// src/AbstractModuleProxy/AbstractModuleProxy.ts
|
|
5
|
+
import { assertEx } from "@xylabs/assert";
|
|
6
|
+
import { compact } from "@xylabs/lodash";
|
|
7
|
+
import { Base } from "@xylabs/object";
|
|
8
|
+
import { PromiseEx } from "@xylabs/promise";
|
|
9
|
+
import { QueryBoundWitnessBuilder } from "@xyo-network/boundwitness-builder";
|
|
10
|
+
import { BoundWitnessWrapper } from "@xyo-network/boundwitness-wrapper";
|
|
11
|
+
import { AddressPreviousHashSchema, ModuleAddressQuerySchema, ModuleConfigSchema, ModuleDescribeQuerySchema, ModuleDiscoverQuerySchema, ModuleManifestQuerySchema } from "@xyo-network/module-model";
|
|
12
|
+
import { ModuleErrorSchema } from "@xyo-network/payload-model";
|
|
13
|
+
var AbstractModuleProxy = class extends Base {
|
|
14
|
+
static {
|
|
15
|
+
__name(this, "AbstractModuleProxy");
|
|
16
|
+
}
|
|
17
|
+
static requiredQueries = [
|
|
18
|
+
ModuleDiscoverQuerySchema
|
|
19
|
+
];
|
|
20
|
+
eventData = {};
|
|
21
|
+
proxyParams;
|
|
22
|
+
constructor(params) {
|
|
23
|
+
super({
|
|
24
|
+
config: {
|
|
25
|
+
schema: ModuleConfigSchema
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
this.proxyParams = params;
|
|
29
|
+
}
|
|
30
|
+
get account() {
|
|
31
|
+
return this.proxyParams.account;
|
|
32
|
+
}
|
|
33
|
+
get address() {
|
|
34
|
+
return this.proxyParams.moduleAddress;
|
|
35
|
+
}
|
|
36
|
+
get config() {
|
|
37
|
+
return this.params.config;
|
|
38
|
+
}
|
|
39
|
+
get downResolver() {
|
|
40
|
+
throw new Error("Unsupported");
|
|
41
|
+
}
|
|
42
|
+
get id() {
|
|
43
|
+
return this.proxyParams.moduleAddress;
|
|
44
|
+
}
|
|
45
|
+
get queries() {
|
|
46
|
+
return this.proxyParams.queries;
|
|
47
|
+
}
|
|
48
|
+
get upResolver() {
|
|
49
|
+
throw new Error("Unsupported");
|
|
50
|
+
}
|
|
51
|
+
static hasRequiredQueries(module) {
|
|
52
|
+
return this.missingRequiredQueries(module).length === 0;
|
|
53
|
+
}
|
|
54
|
+
static missingRequiredQueries(module) {
|
|
55
|
+
const moduleQueries = module.queries;
|
|
56
|
+
return compact(this.requiredQueries.map((query) => {
|
|
57
|
+
return moduleQueries.includes(query) ? null : query;
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
async addressPreviousHash() {
|
|
61
|
+
const queryPayload = {
|
|
62
|
+
schema: ModuleAddressQuerySchema
|
|
63
|
+
};
|
|
64
|
+
return assertEx((await this.sendQuery(queryPayload)).find((payload) => payload.schema === AddressPreviousHashSchema), "Result did not include correct payload");
|
|
65
|
+
}
|
|
66
|
+
clearListeners(_eventNames) {
|
|
67
|
+
throw new Error("Unsupported");
|
|
68
|
+
}
|
|
69
|
+
//TODO: Make ModuleDescription into real payload
|
|
70
|
+
async describe() {
|
|
71
|
+
const queryPayload = {
|
|
72
|
+
schema: ModuleDescribeQuerySchema
|
|
73
|
+
};
|
|
74
|
+
return (await this.sendQuery(queryPayload))[0];
|
|
75
|
+
}
|
|
76
|
+
async discover() {
|
|
77
|
+
const queryPayload = {
|
|
78
|
+
schema: ModuleDiscoverQuerySchema
|
|
79
|
+
};
|
|
80
|
+
return await this.sendQuery(queryPayload);
|
|
81
|
+
}
|
|
82
|
+
emit(_eventName, _eventArgs) {
|
|
83
|
+
throw new Error("Unsupported");
|
|
84
|
+
}
|
|
85
|
+
emitSerial(_eventName, _eventArgs) {
|
|
86
|
+
throw new Error("Unsupported");
|
|
87
|
+
}
|
|
88
|
+
listenerCount(_eventNames) {
|
|
89
|
+
throw new Error("Unsupported");
|
|
90
|
+
}
|
|
91
|
+
async manifest(maxDepth) {
|
|
92
|
+
const queryPayload = {
|
|
93
|
+
schema: ModuleManifestQuerySchema,
|
|
94
|
+
...maxDepth === void 0 ? {} : {
|
|
95
|
+
maxDepth
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
return (await this.sendQuery(queryPayload))[0];
|
|
99
|
+
}
|
|
100
|
+
async moduleAddress() {
|
|
101
|
+
const queryPayload = {
|
|
102
|
+
schema: ModuleAddressQuerySchema
|
|
103
|
+
};
|
|
104
|
+
return await this.sendQuery(queryPayload);
|
|
105
|
+
}
|
|
106
|
+
off(_eventNames, _listener) {
|
|
107
|
+
throw new Error("Unsupported");
|
|
108
|
+
}
|
|
109
|
+
offAny(_listener) {
|
|
110
|
+
throw new Error("Unsupported");
|
|
111
|
+
}
|
|
112
|
+
on(_eventNames, _listener) {
|
|
113
|
+
throw new Error("Unsupported");
|
|
114
|
+
}
|
|
115
|
+
onAny(_listener) {
|
|
116
|
+
throw new Error("Unsupported");
|
|
117
|
+
}
|
|
118
|
+
once(_eventName, _listener) {
|
|
119
|
+
throw new Error("Unsupported");
|
|
120
|
+
}
|
|
121
|
+
async previousHash() {
|
|
122
|
+
const queryPayload = {
|
|
123
|
+
schema: ModuleAddressQuerySchema
|
|
124
|
+
};
|
|
125
|
+
return (await this.sendQuery(queryPayload)).pop().previousHash;
|
|
126
|
+
}
|
|
127
|
+
queryable(_query, _payloads) {
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
resolve(nameOrAddressOrFilter, _options) {
|
|
131
|
+
return typeof nameOrAddressOrFilter === "string" ? void 0 : [];
|
|
132
|
+
}
|
|
133
|
+
state() {
|
|
134
|
+
return [];
|
|
135
|
+
}
|
|
136
|
+
bindQuery(query, payloads, account = this.account) {
|
|
137
|
+
const promise = new PromiseEx(async (resolve) => {
|
|
138
|
+
const result = await this.bindQueryInternal(query, payloads, account);
|
|
139
|
+
resolve?.(result);
|
|
140
|
+
return result;
|
|
141
|
+
}, account);
|
|
142
|
+
return promise;
|
|
143
|
+
}
|
|
144
|
+
async bindQueryInternal(query, payloads, account = this.account) {
|
|
145
|
+
const builder = await new QueryBoundWitnessBuilder().payloads(payloads).query(query);
|
|
146
|
+
const result = await (account ? builder.witness(account) : builder).build();
|
|
147
|
+
return result;
|
|
148
|
+
}
|
|
149
|
+
async filterErrors(result) {
|
|
150
|
+
const wrapper = await BoundWitnessWrapper.wrap(result[0], result[1]);
|
|
151
|
+
return wrapper.payloadsBySchema(ModuleErrorSchema);
|
|
152
|
+
}
|
|
153
|
+
async sendQuery(queryPayload, payloads) {
|
|
154
|
+
const query = await this.bindQuery(queryPayload, payloads);
|
|
155
|
+
const [, resultPayloads, errors] = await this.query(query[0], query[1]);
|
|
156
|
+
if (errors && errors.length > 0) {
|
|
157
|
+
throw errors[0];
|
|
158
|
+
}
|
|
159
|
+
return resultPayloads;
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
|
|
4
163
|
// src/AsyncQueryBus/AsyncQueryBusClient.ts
|
|
5
|
-
import { assertEx as assertEx2 } from "@xylabs/assert";
|
|
6
164
|
import { delay } from "@xylabs/delay";
|
|
7
165
|
import { forget } from "@xylabs/forget";
|
|
8
166
|
import { clearTimeoutEx, setTimeoutEx } from "@xylabs/timer";
|
|
9
167
|
import { isBoundWitnessWithMeta } from "@xyo-network/boundwitness-model";
|
|
10
168
|
import { BoundWitnessDivinerQuerySchema } from "@xyo-network/diviner-boundwitness-model";
|
|
11
|
-
import { asModuleInstance } from "@xyo-network/module-model";
|
|
12
169
|
import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
170
|
+
import { LRUCache as LRUCache2 } from "lru-cache";
|
|
13
171
|
|
|
14
172
|
// src/AsyncQueryBus/AsyncQueryBusBase.ts
|
|
15
|
-
import { assertEx } from "@xylabs/assert";
|
|
16
|
-
import { Base } from "@xylabs/object";
|
|
173
|
+
import { assertEx as assertEx2 } from "@xylabs/assert";
|
|
174
|
+
import { Base as Base2 } from "@xylabs/object";
|
|
17
175
|
import { asArchivistInstance } from "@xyo-network/archivist-model";
|
|
18
176
|
import { asDivinerInstance } from "@xyo-network/diviner-model";
|
|
19
177
|
import { LRUCache } from "lru-cache";
|
|
20
|
-
var AsyncQueryBusBase = class extends
|
|
178
|
+
var AsyncQueryBusBase = class extends Base2 {
|
|
21
179
|
static {
|
|
22
180
|
__name(this, "AsyncQueryBusBase");
|
|
23
181
|
}
|
|
24
182
|
_lastState;
|
|
25
|
-
_queryCache;
|
|
26
183
|
_targetConfigs = {};
|
|
27
184
|
_targetQueries = {};
|
|
28
185
|
constructor(params) {
|
|
@@ -31,19 +188,8 @@ var AsyncQueryBusBase = class extends Base {
|
|
|
31
188
|
get config() {
|
|
32
189
|
return this.params.config;
|
|
33
190
|
}
|
|
34
|
-
get individualAddressBatchQueryLimitConfig() {
|
|
35
|
-
return this.config.individualAddressBatchQueryLimit ?? 10;
|
|
36
|
-
}
|
|
37
191
|
get pollFrequencyConfig() {
|
|
38
|
-
return this.config
|
|
39
|
-
}
|
|
40
|
-
get queryCacheConfig() {
|
|
41
|
-
const queryCacheConfig = this.config.queryCache === true ? {} : this.config.queryCache;
|
|
42
|
-
return {
|
|
43
|
-
max: 100,
|
|
44
|
-
ttl: 1e3 * 60,
|
|
45
|
-
...queryCacheConfig
|
|
46
|
-
};
|
|
192
|
+
return this.config?.pollFrequency ?? 1e3;
|
|
47
193
|
}
|
|
48
194
|
get resolver() {
|
|
49
195
|
return this.params.resolver;
|
|
@@ -59,32 +205,17 @@ var AsyncQueryBusBase = class extends Base {
|
|
|
59
205
|
this._lastState = this._lastState ?? new LRUCache(requiredConfig);
|
|
60
206
|
return this._lastState;
|
|
61
207
|
}
|
|
62
|
-
/**
|
|
63
|
-
* A cache of queries that have been issued
|
|
64
|
-
*/
|
|
65
|
-
get queryCache() {
|
|
66
|
-
const config = this.queryCacheConfig;
|
|
67
|
-
const requiredConfig = {
|
|
68
|
-
noUpdateTTL: false,
|
|
69
|
-
ttlAutopurge: true
|
|
70
|
-
};
|
|
71
|
-
this._queryCache = this._queryCache ?? new LRUCache({
|
|
72
|
-
...config,
|
|
73
|
-
...requiredConfig
|
|
74
|
-
});
|
|
75
|
-
return this._queryCache;
|
|
76
|
-
}
|
|
77
208
|
async queriesArchivist() {
|
|
78
|
-
return
|
|
209
|
+
return assertEx2(asArchivistInstance(await this.resolver.resolve(this.config?.clearingHouse?.queries?.archivist)), () => `Unable to resolve queriesArchivist [${this.config?.clearingHouse?.queries?.archivist}]`);
|
|
79
210
|
}
|
|
80
211
|
async queriesDiviner() {
|
|
81
|
-
return
|
|
212
|
+
return assertEx2(asDivinerInstance(await this.resolver.resolve(this.config?.clearingHouse?.queries?.boundWitnessDiviner)), () => `Unable to resolve queriesDiviner [${this.config?.clearingHouse?.queries?.boundWitnessDiviner}]`);
|
|
82
213
|
}
|
|
83
214
|
async responsesArchivist() {
|
|
84
|
-
return
|
|
215
|
+
return assertEx2(asArchivistInstance(await this.resolver.resolve(this.config?.clearingHouse?.responses?.archivist)), () => `Unable to resolve responsesArchivist [${this.config?.clearingHouse?.responses?.archivist}]`);
|
|
85
216
|
}
|
|
86
217
|
async responsesDiviner() {
|
|
87
|
-
return
|
|
218
|
+
return assertEx2(asDivinerInstance(await this.resolver.resolve(this.config?.clearingHouse?.responses?.boundWitnessDiviner)), () => `Unable to resolve responsesDiviner [${this.config?.clearingHouse?.responses?.boundWitnessDiviner}]`);
|
|
88
219
|
}
|
|
89
220
|
/**
|
|
90
221
|
* Commit the internal state of the process. This is similar
|
|
@@ -126,18 +257,40 @@ var AsyncQueryBusClient = class extends AsyncQueryBusBase {
|
|
|
126
257
|
static {
|
|
127
258
|
__name(this, "AsyncQueryBusClient");
|
|
128
259
|
}
|
|
260
|
+
_queryCache;
|
|
261
|
+
_pollCount = 0;
|
|
129
262
|
_pollId;
|
|
130
263
|
constructor(params) {
|
|
131
264
|
super(params);
|
|
132
265
|
}
|
|
266
|
+
get queryCacheConfig() {
|
|
267
|
+
const queryCacheConfig = this.config?.queryCache === true ? {} : this.config?.queryCache;
|
|
268
|
+
return {
|
|
269
|
+
max: 100,
|
|
270
|
+
ttl: 1e3 * 60,
|
|
271
|
+
...queryCacheConfig
|
|
272
|
+
};
|
|
273
|
+
}
|
|
133
274
|
get started() {
|
|
134
275
|
return !!this._pollId;
|
|
135
276
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
277
|
+
/**
|
|
278
|
+
* A cache of queries that have been issued
|
|
279
|
+
*/
|
|
280
|
+
get queryCache() {
|
|
281
|
+
const config = this.queryCacheConfig;
|
|
282
|
+
const requiredConfig = {
|
|
283
|
+
noUpdateTTL: false,
|
|
284
|
+
ttlAutopurge: true
|
|
285
|
+
};
|
|
286
|
+
this._queryCache = this._queryCache ?? new LRUCache2({
|
|
287
|
+
...config,
|
|
288
|
+
...requiredConfig
|
|
139
289
|
});
|
|
140
|
-
return
|
|
290
|
+
return this._queryCache;
|
|
291
|
+
}
|
|
292
|
+
listeningAddresses() {
|
|
293
|
+
return this._queryCache?.keys();
|
|
141
294
|
}
|
|
142
295
|
async send(address, query, payloads) {
|
|
143
296
|
this.logger?.debug(`Begin issuing query to: ${address}`);
|
|
@@ -152,10 +305,6 @@ var AsyncQueryBusClient = class extends AsyncQueryBusBase {
|
|
|
152
305
|
$meta
|
|
153
306
|
});
|
|
154
307
|
const queryArchivist = await this.queriesArchivist();
|
|
155
|
-
const sourceAddress = query.addresses.at(0);
|
|
156
|
-
if (sourceAddress && !this.config.listeningModules?.includes(sourceAddress)) {
|
|
157
|
-
this.config.listeningModules?.push(sourceAddress);
|
|
158
|
-
}
|
|
159
308
|
const routedQueryHash = (
|
|
160
309
|
// Trust the signed hash if it's there
|
|
161
310
|
routedQuery?.$hash ?? // TODO: What is the right way to find the dataHash
|
|
@@ -178,52 +327,43 @@ var AsyncQueryBusClient = class extends AsyncQueryBusBase {
|
|
|
178
327
|
const context = new Promise((resolve) => {
|
|
179
328
|
this.logger?.debug(`Polling for response to query: ${routedQueryHash}`);
|
|
180
329
|
const pollForResponse = /* @__PURE__ */ __name(async () => {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
response
|
|
185
|
-
|
|
186
|
-
this.
|
|
187
|
-
|
|
188
|
-
|
|
330
|
+
try {
|
|
331
|
+
this.start();
|
|
332
|
+
let response = this.queryCache.get(routedQueryHash);
|
|
333
|
+
while (response !== void 0) {
|
|
334
|
+
await delay(100);
|
|
335
|
+
response = this.queryCache.get(routedQueryHash);
|
|
336
|
+
if (response && response !== Pending) {
|
|
337
|
+
this.logger?.debug(`Returning response to query: ${routedQueryHash}`);
|
|
338
|
+
resolve(response);
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
189
341
|
}
|
|
342
|
+
this.logger?.error("Timeout waiting for query response");
|
|
343
|
+
const error = {
|
|
344
|
+
message: "Timeout waiting for query response",
|
|
345
|
+
query: "network.xyo.boundwitness",
|
|
346
|
+
schema: "network.xyo.error.module",
|
|
347
|
+
sources: [
|
|
348
|
+
routedQueryHash
|
|
349
|
+
]
|
|
350
|
+
};
|
|
351
|
+
resolve([
|
|
352
|
+
routedQuery,
|
|
353
|
+
[],
|
|
354
|
+
[
|
|
355
|
+
await PayloadBuilder.build(error)
|
|
356
|
+
]
|
|
357
|
+
]);
|
|
358
|
+
return;
|
|
359
|
+
} finally {
|
|
360
|
+
this.stop();
|
|
190
361
|
}
|
|
191
|
-
this.logger?.error("Timeout waiting for query response");
|
|
192
|
-
const error = {
|
|
193
|
-
message: "Timeout waiting for query response",
|
|
194
|
-
query: "network.xyo.boundwitness",
|
|
195
|
-
schema: "network.xyo.error.module",
|
|
196
|
-
sources: [
|
|
197
|
-
routedQueryHash
|
|
198
|
-
]
|
|
199
|
-
};
|
|
200
|
-
resolve([
|
|
201
|
-
routedQuery,
|
|
202
|
-
[],
|
|
203
|
-
[
|
|
204
|
-
await PayloadBuilder.build(error)
|
|
205
|
-
]
|
|
206
|
-
]);
|
|
207
|
-
return;
|
|
208
362
|
}, "pollForResponse");
|
|
209
363
|
forget(pollForResponse());
|
|
210
364
|
});
|
|
211
365
|
return context;
|
|
212
366
|
}
|
|
213
|
-
start() {
|
|
214
|
-
if (this.started) {
|
|
215
|
-
console.warn("AsyncQueryBus starting when already started");
|
|
216
|
-
}
|
|
217
|
-
this.poll();
|
|
218
|
-
}
|
|
219
|
-
stop() {
|
|
220
|
-
if (!this.started) {
|
|
221
|
-
console.warn("AsyncQueryBus stopping when already stopped");
|
|
222
|
-
}
|
|
223
|
-
if (this._pollId)
|
|
224
|
-
clearTimeoutEx(this._pollId);
|
|
225
|
-
this._pollId = void 0;
|
|
226
|
-
}
|
|
227
367
|
/**
|
|
228
368
|
* Runs the background divine process on a loop with a delay
|
|
229
369
|
* specified by the `config.pollFrequency`
|
|
@@ -275,30 +415,48 @@ var AsyncQueryBusClient = class extends AsyncQueryBusBase {
|
|
|
275
415
|
}
|
|
276
416
|
}));
|
|
277
417
|
};
|
|
418
|
+
start() {
|
|
419
|
+
if (this._pollCount === 0) {
|
|
420
|
+
this.poll();
|
|
421
|
+
}
|
|
422
|
+
this._pollCount++;
|
|
423
|
+
}
|
|
424
|
+
stop() {
|
|
425
|
+
this._pollCount--;
|
|
426
|
+
if (this._pollCount <= 0) {
|
|
427
|
+
if (this._pollId)
|
|
428
|
+
clearTimeoutEx(this._pollId);
|
|
429
|
+
this._pollId = void 0;
|
|
430
|
+
this._pollCount = 0;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
278
433
|
};
|
|
279
434
|
|
|
280
|
-
// src/AsyncQueryBus/
|
|
435
|
+
// src/AsyncQueryBus/AsyncQueryBusHost.ts
|
|
281
436
|
import { containsAll } from "@xylabs/array";
|
|
282
437
|
import { assertEx as assertEx3 } from "@xylabs/assert";
|
|
283
438
|
import { clearTimeoutEx as clearTimeoutEx2, setTimeoutEx as setTimeoutEx2 } from "@xylabs/timer";
|
|
284
439
|
import { isQueryBoundWitnessWithMeta } from "@xyo-network/boundwitness-model";
|
|
285
440
|
import { BoundWitnessDivinerQuerySchema as BoundWitnessDivinerQuerySchema2 } from "@xyo-network/diviner-boundwitness-model";
|
|
286
|
-
import { asModuleInstance
|
|
441
|
+
import { asModuleInstance } from "@xyo-network/module-model";
|
|
287
442
|
import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/payload-builder";
|
|
288
|
-
var
|
|
443
|
+
var AsyncQueryBusHost = class extends AsyncQueryBusBase {
|
|
289
444
|
static {
|
|
290
|
-
__name(this, "
|
|
445
|
+
__name(this, "AsyncQueryBusHost");
|
|
291
446
|
}
|
|
292
447
|
_pollId;
|
|
293
448
|
constructor(params) {
|
|
294
449
|
super(params);
|
|
295
450
|
}
|
|
451
|
+
get perAddressBatchQueryLimit() {
|
|
452
|
+
return this.config?.perAddressBatchQueryLimit ?? 10;
|
|
453
|
+
}
|
|
296
454
|
get started() {
|
|
297
455
|
return !!this._pollId;
|
|
298
456
|
}
|
|
299
457
|
async listeningModules() {
|
|
300
|
-
const mods = this.config
|
|
301
|
-
direction: "
|
|
458
|
+
const mods = this.config?.listeningModules ? await Promise.all(this.config.listeningModules.map(async (listeningModule) => assertEx3(asModuleInstance(await this.resolver.resolve(listeningModule)), () => `Unable to resolve listeningModule [${listeningModule}]`))) : await this.resolver.resolve(void 0, {
|
|
459
|
+
direction: "down"
|
|
302
460
|
});
|
|
303
461
|
return mods;
|
|
304
462
|
}
|
|
@@ -316,27 +474,27 @@ var AsyncQueryBusServer = class extends AsyncQueryBusBase {
|
|
|
316
474
|
clearTimeoutEx2(this._pollId);
|
|
317
475
|
this._pollId = void 0;
|
|
318
476
|
}
|
|
319
|
-
callLocalModule = async (localModule,
|
|
477
|
+
callLocalModule = async (localModule, query) => {
|
|
320
478
|
const localModuleName = localModule.config.name ?? localModule.address;
|
|
321
479
|
const queryArchivist = await this.queriesArchivist();
|
|
322
480
|
const responseArchivist = await this.responsesArchivist();
|
|
323
|
-
const commandDestination =
|
|
481
|
+
const commandDestination = query.$meta?.destination;
|
|
324
482
|
if (commandDestination && commandDestination?.includes(localModule.address)) {
|
|
325
|
-
const queryIndex =
|
|
483
|
+
const queryIndex = query.payload_hashes.indexOf(query.query);
|
|
326
484
|
if (queryIndex !== -1) {
|
|
327
|
-
const querySchema =
|
|
485
|
+
const querySchema = query.payload_schemas[queryIndex];
|
|
328
486
|
if (localModule.queries.includes(querySchema)) {
|
|
329
|
-
const commandPayloads = await queryArchivist.get(
|
|
487
|
+
const commandPayloads = await queryArchivist.get(query.payload_hashes);
|
|
330
488
|
const commandPayloadsDict = await PayloadBuilder2.toAllHashMap(commandPayloads);
|
|
331
|
-
const commandHash = (await PayloadBuilder2.build(
|
|
332
|
-
if (!containsAll(Object.keys(commandPayloadsDict),
|
|
489
|
+
const commandHash = (await PayloadBuilder2.build(query)).$hash;
|
|
490
|
+
if (!containsAll(Object.keys(commandPayloadsDict), query.payload_hashes)) {
|
|
333
491
|
this.logger?.error(`Error processing command ${commandHash} for module ${localModuleName}, missing payloads`);
|
|
334
492
|
return;
|
|
335
493
|
}
|
|
336
494
|
try {
|
|
337
|
-
const commandSchema = commandPayloadsDict[
|
|
495
|
+
const commandSchema = commandPayloadsDict[query.query].schema;
|
|
338
496
|
this.logger?.debug(`Issuing command ${commandSchema} (${commandHash}) addressed to module: ${localModuleName}`);
|
|
339
|
-
const response = await localModule.query(
|
|
497
|
+
const response = await localModule.query(query, commandPayloads);
|
|
340
498
|
const [bw, payloads, errors] = response;
|
|
341
499
|
this.logger?.debug(`Replying to command ${commandHash} addressed to module: ${localModuleName}`);
|
|
342
500
|
const insertResult = await responseArchivist.insert([
|
|
@@ -344,11 +502,11 @@ var AsyncQueryBusServer = class extends AsyncQueryBusBase {
|
|
|
344
502
|
...payloads,
|
|
345
503
|
...errors
|
|
346
504
|
]);
|
|
347
|
-
if (insertResult.length
|
|
505
|
+
if (insertResult.length === 0) {
|
|
348
506
|
this.logger?.error(`Error replying to command ${commandHash} addressed to module: ${localModuleName}`);
|
|
349
507
|
}
|
|
350
|
-
if (
|
|
351
|
-
await this.commitState(localModule.address,
|
|
508
|
+
if (query?.timestamp) {
|
|
509
|
+
await this.commitState(localModule.address, query.timestamp);
|
|
352
510
|
}
|
|
353
511
|
} catch (error) {
|
|
354
512
|
this.logger?.error(`Error processing command ${commandHash} for module ${localModuleName}: ${error}`);
|
|
@@ -361,13 +519,13 @@ var AsyncQueryBusServer = class extends AsyncQueryBusBase {
|
|
|
361
519
|
* Finds unprocessed commands addressed to the supplied address
|
|
362
520
|
* @param address The address to find commands for
|
|
363
521
|
*/
|
|
364
|
-
|
|
522
|
+
findQueriesToAddress = async (address) => {
|
|
365
523
|
const queryBoundWitnessDiviner = await this.queriesDiviner();
|
|
366
524
|
const timestamp = await this.retrieveState(address);
|
|
367
525
|
const destination = [
|
|
368
526
|
address
|
|
369
527
|
];
|
|
370
|
-
const limit = this.
|
|
528
|
+
const limit = this.perAddressBatchQueryLimit;
|
|
371
529
|
const divinerQuery = {
|
|
372
530
|
destination,
|
|
373
531
|
limit,
|
|
@@ -378,10 +536,10 @@ var AsyncQueryBusServer = class extends AsyncQueryBusBase {
|
|
|
378
536
|
const result = await queryBoundWitnessDiviner.divine([
|
|
379
537
|
divinerQuery
|
|
380
538
|
]);
|
|
381
|
-
const
|
|
382
|
-
const nextState = Math.max(...
|
|
539
|
+
const queries = result.filter(isQueryBoundWitnessWithMeta);
|
|
540
|
+
const nextState = queries.length > 0 ? Math.max(...queries.map((c) => c.timestamp ?? 0)) + 1 : timestamp;
|
|
383
541
|
await this.commitState(address, nextState);
|
|
384
|
-
return
|
|
542
|
+
return queries;
|
|
385
543
|
};
|
|
386
544
|
/**
|
|
387
545
|
* Runs the background divine process on a loop with a delay
|
|
@@ -411,12 +569,12 @@ var AsyncQueryBusServer = class extends AsyncQueryBusBase {
|
|
|
411
569
|
try {
|
|
412
570
|
const localModuleName = localModule.config.name ?? localModule.address;
|
|
413
571
|
this.logger?.debug(`Checking for inbound commands to ${localModuleName}`);
|
|
414
|
-
const
|
|
415
|
-
if (
|
|
572
|
+
const queries = await this.findQueriesToAddress(localModule.address);
|
|
573
|
+
if (queries.length === 0)
|
|
416
574
|
return;
|
|
417
575
|
this.logger?.debug(`Found commands addressed to local module: ${localModuleName}`);
|
|
418
|
-
for (const
|
|
419
|
-
await this.callLocalModule(localModule,
|
|
576
|
+
for (const query of queries) {
|
|
577
|
+
await this.callLocalModule(localModule, query);
|
|
420
578
|
}
|
|
421
579
|
} catch (error) {
|
|
422
580
|
this.logger?.error(`Error processing commands for address ${localModule.address}: ${error}`);
|
|
@@ -425,6 +583,52 @@ var AsyncQueryBusServer = class extends AsyncQueryBusBase {
|
|
|
425
583
|
};
|
|
426
584
|
};
|
|
427
585
|
|
|
586
|
+
// src/AbstractModuleHost/AbstractModuleHost.ts
|
|
587
|
+
import { Base as Base3 } from "@xylabs/object";
|
|
588
|
+
var AbstractModuleHost = class extends Base3 {
|
|
589
|
+
static {
|
|
590
|
+
__name(this, "AbstractModuleHost");
|
|
591
|
+
}
|
|
592
|
+
};
|
|
593
|
+
|
|
594
|
+
// src/AsyncQueryBus/ModuleHost/ModuleHost.ts
|
|
595
|
+
var AsyncQueryBusModuleHost = class extends AbstractModuleHost {
|
|
596
|
+
static {
|
|
597
|
+
__name(this, "AsyncQueryBusModuleHost");
|
|
598
|
+
}
|
|
599
|
+
_busHost;
|
|
600
|
+
constructor(params) {
|
|
601
|
+
super(params);
|
|
602
|
+
}
|
|
603
|
+
async start() {
|
|
604
|
+
const listeningModules = this.params.config.listeningModules ?? (await this.params.module.resolve(void 0, {
|
|
605
|
+
direction: "down"
|
|
606
|
+
})).map((m) => m.address);
|
|
607
|
+
this._busHost = new AsyncQueryBusHost({
|
|
608
|
+
config: {
|
|
609
|
+
...this.params.config,
|
|
610
|
+
listeningModules
|
|
611
|
+
},
|
|
612
|
+
logger: this.params.logger,
|
|
613
|
+
resolver: this.params.module
|
|
614
|
+
});
|
|
615
|
+
this._busHost?.start();
|
|
616
|
+
}
|
|
617
|
+
stop() {
|
|
618
|
+
this._busHost?.stop();
|
|
619
|
+
}
|
|
620
|
+
};
|
|
621
|
+
|
|
622
|
+
// src/AsyncQueryBus/ModuleProxy/ModuleProxy.ts
|
|
623
|
+
var AsyncQueryBusModuleProxy = class extends AbstractModuleProxy {
|
|
624
|
+
static {
|
|
625
|
+
__name(this, "AsyncQueryBusModuleProxy");
|
|
626
|
+
}
|
|
627
|
+
async query(query, payloads) {
|
|
628
|
+
return await this.proxyParams.bridgeClient.send(this.address, query, payloads);
|
|
629
|
+
}
|
|
630
|
+
};
|
|
631
|
+
|
|
428
632
|
// src/Schema.ts
|
|
429
633
|
var PubSubBridgeSchema = "network.xyo.bridge.pubsub";
|
|
430
634
|
|
|
@@ -435,9 +639,9 @@ var PubSubBridgeConfigSchema = `${PubSubBridgeSchema}.config`;
|
|
|
435
639
|
import { assertEx as assertEx4 } from "@xylabs/assert";
|
|
436
640
|
import { AbstractBridge } from "@xyo-network/abstract-bridge";
|
|
437
641
|
import { ModuleManifestPayloadSchema } from "@xyo-network/manifest-model";
|
|
438
|
-
import { creatableModule, ModuleManifestQuerySchema } from "@xyo-network/module-model";
|
|
642
|
+
import { creatableModule, ModuleManifestQuerySchema as ModuleManifestQuerySchema2 } from "@xyo-network/module-model";
|
|
439
643
|
import { isPayloadOfSchemaType } from "@xyo-network/payload-model";
|
|
440
|
-
import { LRUCache as
|
|
644
|
+
import { LRUCache as LRUCache3 } from "lru-cache";
|
|
441
645
|
function _ts_decorate(decorators, target, key, desc) {
|
|
442
646
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
443
647
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -465,10 +669,10 @@ var PubSubBridge = class extends AbstractBridge {
|
|
|
465
669
|
_targetConfigs = {};
|
|
466
670
|
_targetQueries = {};
|
|
467
671
|
_busClient;
|
|
468
|
-
|
|
672
|
+
_busHost;
|
|
469
673
|
get discoverCache() {
|
|
470
674
|
const config = this.discoverCacheConfig;
|
|
471
|
-
this._discoverCache = this._discoverCache ?? new
|
|
675
|
+
this._discoverCache = this._discoverCache ?? new LRUCache3({
|
|
472
676
|
ttlAutopurge: true,
|
|
473
677
|
...config
|
|
474
678
|
});
|
|
@@ -525,7 +729,7 @@ var PubSubBridge = class extends AbstractBridge {
|
|
|
525
729
|
const addressToCall = address ?? this.getRootAddress();
|
|
526
730
|
const queryPayload = {
|
|
527
731
|
maxDepth,
|
|
528
|
-
schema:
|
|
732
|
+
schema: ModuleManifestQuerySchema2
|
|
529
733
|
};
|
|
530
734
|
const boundQuery = await this.bindQuery(queryPayload);
|
|
531
735
|
const manifest = assertEx4(await this.targetQuery(addressToCall, boundQuery[0], boundQuery[1]), () => `Unable to resolve [${address}]`)[1];
|
|
@@ -549,32 +753,30 @@ var PubSubBridge = class extends AbstractBridge {
|
|
|
549
753
|
busClient() {
|
|
550
754
|
if (!this._busClient) {
|
|
551
755
|
this._busClient = new AsyncQueryBusClient({
|
|
552
|
-
config: this.config,
|
|
756
|
+
config: this.config.client,
|
|
553
757
|
logger: this.logger,
|
|
554
758
|
resolver: this
|
|
555
759
|
});
|
|
556
760
|
}
|
|
557
761
|
return this._busClient;
|
|
558
762
|
}
|
|
559
|
-
|
|
560
|
-
if (!this.
|
|
561
|
-
this.
|
|
562
|
-
config: this.config,
|
|
763
|
+
busHost() {
|
|
764
|
+
if (!this._busHost) {
|
|
765
|
+
this._busHost = new AsyncQueryBusHost({
|
|
766
|
+
config: this.config.host,
|
|
563
767
|
logger: this.logger,
|
|
564
768
|
resolver: this
|
|
565
769
|
});
|
|
566
770
|
}
|
|
567
|
-
return this.
|
|
771
|
+
return this._busHost;
|
|
568
772
|
}
|
|
569
773
|
async startHandler() {
|
|
570
774
|
await Promise.resolve(this.connect());
|
|
571
|
-
this.
|
|
572
|
-
this.busClient().start();
|
|
775
|
+
this.busHost().start();
|
|
573
776
|
return true;
|
|
574
777
|
}
|
|
575
778
|
stopHandler(_timeout) {
|
|
576
|
-
this.
|
|
577
|
-
this.busServer().stop();
|
|
779
|
+
this.busHost().stop();
|
|
578
780
|
return true;
|
|
579
781
|
}
|
|
580
782
|
};
|
|
@@ -582,8 +784,11 @@ PubSubBridge = _ts_decorate([
|
|
|
582
784
|
creatableModule()
|
|
583
785
|
], PubSubBridge);
|
|
584
786
|
export {
|
|
787
|
+
AbstractModuleProxy,
|
|
585
788
|
AsyncQueryBusClient,
|
|
586
|
-
|
|
789
|
+
AsyncQueryBusHost,
|
|
790
|
+
AsyncQueryBusModuleHost,
|
|
791
|
+
AsyncQueryBusModuleProxy,
|
|
587
792
|
Pending,
|
|
588
793
|
PubSubBridge,
|
|
589
794
|
PubSubBridgeConfigSchema,
|