@xyo-network/diviner-indexing-memory 2.84.19 → 2.85.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/Diviner.d.cts +1 -0
- package/dist/browser/Diviner.d.cts.map +1 -1
- package/dist/browser/Diviner.d.mts +1 -0
- package/dist/browser/Diviner.d.mts.map +1 -1
- package/dist/browser/Diviner.d.ts +1 -0
- package/dist/browser/Diviner.d.ts.map +1 -1
- package/dist/browser/index.cjs +89 -56
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +93 -60
- package/dist/browser/index.js.map +1 -1
- package/dist/node/Diviner.d.cts +1 -0
- package/dist/node/Diviner.d.cts.map +1 -1
- package/dist/node/Diviner.d.mts +1 -0
- package/dist/node/Diviner.d.mts.map +1 -1
- package/dist/node/Diviner.d.ts +1 -0
- package/dist/node/Diviner.d.ts.map +1 -1
- package/dist/node/index.cjs +97 -60
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +101 -64
- package/dist/node/index.js.map +1 -1
- package/package.json +12 -12
- package/src/Diviner.ts +3 -1
package/dist/node/index.js
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
4
|
+
var __publicField = (obj, key, value) => {
|
|
5
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
6
|
+
return value;
|
|
7
|
+
};
|
|
8
|
+
|
|
1
9
|
// src/Diviner.ts
|
|
2
10
|
import { assertEx } from "@xylabs/assert";
|
|
3
11
|
import { AbstractDiviner } from "@xyo-network/abstract-diviner";
|
|
@@ -5,16 +13,24 @@ import { ArchivistWrapper } from "@xyo-network/archivist-wrapper";
|
|
|
5
13
|
import { BoundWitnessBuilder } from "@xyo-network/boundwitness-builder";
|
|
6
14
|
import { isBoundWitness } from "@xyo-network/boundwitness-model";
|
|
7
15
|
import { BoundWitnessDivinerQuerySchema } from "@xyo-network/diviner-boundwitness-model";
|
|
8
|
-
import {
|
|
9
|
-
IndexingDivinerConfigSchema
|
|
10
|
-
} from "@xyo-network/diviner-indexing-model";
|
|
16
|
+
import { IndexingDivinerConfigSchema } from "@xyo-network/diviner-indexing-model";
|
|
11
17
|
import { asDivinerInstance, DivinerConfigSchema } from "@xyo-network/diviner-model";
|
|
12
18
|
import { DivinerWrapper } from "@xyo-network/diviner-wrapper";
|
|
13
|
-
import { isModuleState, ModuleStateSchema } from "@xyo-network/module-model";
|
|
19
|
+
import { creatableModule, isModuleState, ModuleStateSchema } from "@xyo-network/module-model";
|
|
14
20
|
import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
21
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
22
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
23
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
24
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
25
|
+
else
|
|
26
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
27
|
+
if (d = decorators[i])
|
|
28
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
29
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
30
|
+
}
|
|
31
|
+
__name(_ts_decorate, "_ts_decorate");
|
|
15
32
|
var moduleName = "IndexingDiviner";
|
|
16
|
-
var
|
|
17
|
-
static configSchemas = [IndexingDivinerConfigSchema, DivinerConfigSchema];
|
|
33
|
+
var _IndexingDiviner = class _IndexingDiviner extends AbstractDiviner {
|
|
18
34
|
_lastState;
|
|
19
35
|
_pollId;
|
|
20
36
|
get payloadDivinerLimit() {
|
|
@@ -24,13 +40,15 @@ var IndexingDiviner = class extends AbstractDiviner {
|
|
|
24
40
|
return this.config.pollFrequency ?? 1e4;
|
|
25
41
|
}
|
|
26
42
|
/**
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
43
|
+
* Works via batched iteration of the source archivist to populate the index.
|
|
44
|
+
* @returns A promise that resolves when the background process is complete
|
|
45
|
+
*/
|
|
30
46
|
backgroundDivine = async () => {
|
|
31
47
|
const lastState = await this.retrieveState();
|
|
32
48
|
const indexCandidateDiviner = await this.getIndexingDivinerStage("stateToIndexCandidateDiviner");
|
|
33
|
-
const results = lastState ? await indexCandidateDiviner.divine([
|
|
49
|
+
const results = lastState ? await indexCandidateDiviner.divine([
|
|
50
|
+
lastState
|
|
51
|
+
]) : await indexCandidateDiviner.divine();
|
|
34
52
|
const nextState = results.find(isModuleState);
|
|
35
53
|
const indexCandidates = results.filter((x) => !isModuleState(x));
|
|
36
54
|
const toIndexTransformDiviner = await this.getIndexingDivinerStage("indexCandidateToIndexDiviner");
|
|
@@ -42,12 +60,12 @@ var IndexingDiviner = class extends AbstractDiviner {
|
|
|
42
60
|
}
|
|
43
61
|
};
|
|
44
62
|
/**
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
63
|
+
* Commit the internal state of the Diviner process. This is similar
|
|
64
|
+
* to a transaction completion in a database and should only be called
|
|
65
|
+
* when results have been successfully persisted to the appropriate
|
|
66
|
+
* external stores.
|
|
67
|
+
* @param nextState The state to commit
|
|
68
|
+
*/
|
|
51
69
|
async commitState(nextState) {
|
|
52
70
|
var _a;
|
|
53
71
|
if (nextState.state.offset === ((_a = this._lastState) == null ? void 0 : _a.state.offset))
|
|
@@ -55,29 +73,33 @@ var IndexingDiviner = class extends AbstractDiviner {
|
|
|
55
73
|
this._lastState = nextState;
|
|
56
74
|
const archivist = await this.getArchivistForStore("stateStore");
|
|
57
75
|
const [bw] = await new BoundWitnessBuilder().payload(nextState).witness(this.account).build();
|
|
58
|
-
await archivist.insert([
|
|
76
|
+
await archivist.insert([
|
|
77
|
+
bw,
|
|
78
|
+
nextState
|
|
79
|
+
]);
|
|
59
80
|
}
|
|
60
81
|
async divineHandler(payloads = []) {
|
|
61
82
|
const indexPayloadDiviner = await this.getPayloadDivinerForStore("indexStore");
|
|
62
83
|
const divinerQueryToIndexQueryDiviner = await this.getIndexingDivinerStage("divinerQueryToIndexQueryDiviner");
|
|
63
84
|
const indexQueryResponseToDivinerQueryResponseDiviner = await this.getIndexingDivinerStage("indexQueryResponseToDivinerQueryResponseDiviner");
|
|
64
|
-
const results = (await Promise.all(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
85
|
+
const results = (await Promise.all(payloads.map(async (payload) => {
|
|
86
|
+
const indexQuery = await divinerQueryToIndexQueryDiviner.divine([
|
|
87
|
+
payload
|
|
88
|
+
]);
|
|
89
|
+
const indexedResults = await indexPayloadDiviner.divine(indexQuery);
|
|
90
|
+
const response = await Promise.all(indexedResults.flat().map((indexedResult) => indexQueryResponseToDivinerQueryResponseDiviner.divine([
|
|
91
|
+
payload,
|
|
92
|
+
indexedResult
|
|
93
|
+
])));
|
|
94
|
+
return response.flat();
|
|
95
|
+
}))).flat();
|
|
74
96
|
return results;
|
|
75
97
|
}
|
|
76
98
|
/**
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
99
|
+
* Retrieves the archivist for the specified store
|
|
100
|
+
* @param store The store to retrieve the archivist for
|
|
101
|
+
* @returns The archivist for the specified store
|
|
102
|
+
*/
|
|
81
103
|
async getArchivistForStore(store) {
|
|
82
104
|
var _a, _b;
|
|
83
105
|
const name = assertEx((_b = (_a = this.config) == null ? void 0 : _a[store]) == null ? void 0 : _b.archivist, () => `${moduleName}: Config for ${store}.archivist not specified`);
|
|
@@ -85,10 +107,10 @@ var IndexingDiviner = class extends AbstractDiviner {
|
|
|
85
107
|
return ArchivistWrapper.wrap(mod, this.account);
|
|
86
108
|
}
|
|
87
109
|
/**
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
110
|
+
* Retrieves the BoundWitness Diviner for the specified store
|
|
111
|
+
* @param store The store to retrieve the BoundWitness Diviner for
|
|
112
|
+
* @returns The BoundWitness Diviner for the specified store
|
|
113
|
+
*/
|
|
92
114
|
async getBoundWitnessDivinerForStore(store) {
|
|
93
115
|
var _a, _b;
|
|
94
116
|
const name = assertEx((_b = (_a = this.config) == null ? void 0 : _a[store]) == null ? void 0 : _b.boundWitnessDiviner, () => `${moduleName}: Config for ${store}.boundWitnessDiviner not specified`);
|
|
@@ -96,24 +118,21 @@ var IndexingDiviner = class extends AbstractDiviner {
|
|
|
96
118
|
return DivinerWrapper.wrap(mod, this.account);
|
|
97
119
|
}
|
|
98
120
|
/**
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
121
|
+
* Gets the Diviner for the supplied Indexing Diviner stage
|
|
122
|
+
* @param transform The Indexing Diviner stage
|
|
123
|
+
* @returns The diviner corresponding to the Indexing Diviner stage
|
|
124
|
+
*/
|
|
103
125
|
async getIndexingDivinerStage(transform) {
|
|
104
126
|
var _a, _b;
|
|
105
|
-
const nameOrAddress = assertEx(
|
|
106
|
-
(_b = (_a = this.config) == null ? void 0 : _a.indexingDivinerStages) == null ? void 0 : _b[transform],
|
|
107
|
-
() => `${moduleName}: Config for indexingDivinerStages.${transform} not specified`
|
|
108
|
-
);
|
|
127
|
+
const nameOrAddress = assertEx((_b = (_a = this.config) == null ? void 0 : _a.indexingDivinerStages) == null ? void 0 : _b[transform], () => `${moduleName}: Config for indexingDivinerStages.${transform} not specified`);
|
|
109
128
|
const mod = await this.resolve(nameOrAddress);
|
|
110
129
|
return assertEx(asDivinerInstance(mod), () => `${moduleName}: Failed to resolve indexing diviner stage for ${transform}`);
|
|
111
130
|
}
|
|
112
131
|
/**
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
132
|
+
* Retrieves the Payload Diviner for the specified store
|
|
133
|
+
* @param store The store to retrieve the Payload Diviner for
|
|
134
|
+
* @returns The Payload Diviner for the specified store
|
|
135
|
+
*/
|
|
117
136
|
async getPayloadDivinerForStore(store) {
|
|
118
137
|
var _a, _b;
|
|
119
138
|
const name = assertEx((_b = (_a = this.config) == null ? void 0 : _a[store]) == null ? void 0 : _b.payloadDiviner, () => `${moduleName}: Config for ${store}.payloadDiviner not specified`);
|
|
@@ -121,37 +140,45 @@ var IndexingDiviner = class extends AbstractDiviner {
|
|
|
121
140
|
return DivinerWrapper.wrap(mod, this.account);
|
|
122
141
|
}
|
|
123
142
|
/**
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
143
|
+
* Retrieves the last state of the Diviner process. Used to recover state after
|
|
144
|
+
* preemptions, reboots, etc.
|
|
145
|
+
*/
|
|
127
146
|
async retrieveState() {
|
|
128
147
|
if (this._lastState)
|
|
129
148
|
return this._lastState;
|
|
130
149
|
let hash = "";
|
|
131
150
|
const diviner = await this.getBoundWitnessDivinerForStore("stateStore");
|
|
132
|
-
const query = await new PayloadBuilder({
|
|
151
|
+
const query = await new PayloadBuilder({
|
|
152
|
+
schema: BoundWitnessDivinerQuerySchema
|
|
153
|
+
}).fields({
|
|
133
154
|
address: this.account.address,
|
|
134
155
|
limit: 1,
|
|
135
156
|
offset: 0,
|
|
136
157
|
order: "desc",
|
|
137
|
-
payload_schemas: [
|
|
158
|
+
payload_schemas: [
|
|
159
|
+
ModuleStateSchema
|
|
160
|
+
]
|
|
138
161
|
}).build();
|
|
139
|
-
const boundWitnesses = await diviner.divine([
|
|
162
|
+
const boundWitnesses = await diviner.divine([
|
|
163
|
+
query
|
|
164
|
+
]);
|
|
140
165
|
if (boundWitnesses.length > 0) {
|
|
141
166
|
const boundWitness = boundWitnesses[0];
|
|
142
167
|
if (isBoundWitness(boundWitness)) {
|
|
143
|
-
hash = boundWitness.addresses.map((address, index) => ({
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
);
|
|
168
|
+
hash = boundWitness.addresses.map((address, index) => ({
|
|
169
|
+
address,
|
|
170
|
+
index
|
|
171
|
+
})).filter(({ address }) => address === this.account.address).reduce((prev, curr) => {
|
|
172
|
+
var _a;
|
|
173
|
+
return ((_a = boundWitness.payload_schemas) == null ? void 0 : _a[curr == null ? void 0 : curr.index]) === ModuleStateSchema ? boundWitness.payload_hashes[curr == null ? void 0 : curr.index] : prev;
|
|
174
|
+
}, "");
|
|
150
175
|
}
|
|
151
176
|
}
|
|
152
177
|
if (hash) {
|
|
153
178
|
const archivist = await this.getArchivistForStore("stateStore");
|
|
154
|
-
const payload = (await archivist.get([
|
|
179
|
+
const payload = (await archivist.get([
|
|
180
|
+
hash
|
|
181
|
+
])).find(isModuleState);
|
|
155
182
|
if (payload) {
|
|
156
183
|
return payload;
|
|
157
184
|
}
|
|
@@ -171,9 +198,9 @@ var IndexingDiviner = class extends AbstractDiviner {
|
|
|
171
198
|
return await super.stopHandler();
|
|
172
199
|
}
|
|
173
200
|
/**
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
201
|
+
* Runs the background divine process on a loop with a delay
|
|
202
|
+
* specified by the `config.pollFrequency`
|
|
203
|
+
*/
|
|
177
204
|
poll() {
|
|
178
205
|
this._pollId = setTimeout(async () => {
|
|
179
206
|
try {
|
|
@@ -190,6 +217,16 @@ var IndexingDiviner = class extends AbstractDiviner {
|
|
|
190
217
|
}, this.pollFrequency);
|
|
191
218
|
}
|
|
192
219
|
};
|
|
220
|
+
__name(_IndexingDiviner, "IndexingDiviner");
|
|
221
|
+
__publicField(_IndexingDiviner, "allowRandomAccount", false);
|
|
222
|
+
__publicField(_IndexingDiviner, "configSchemas", [
|
|
223
|
+
IndexingDivinerConfigSchema,
|
|
224
|
+
DivinerConfigSchema
|
|
225
|
+
]);
|
|
226
|
+
var IndexingDiviner = _IndexingDiviner;
|
|
227
|
+
IndexingDiviner = _ts_decorate([
|
|
228
|
+
creatableModule()
|
|
229
|
+
], IndexingDiviner);
|
|
193
230
|
export {
|
|
194
231
|
IndexingDiviner
|
|
195
232
|
};
|
package/dist/node/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Diviner.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { AbstractDiviner } from '@xyo-network/abstract-diviner'\nimport { ArchivistWrapper } from '@xyo-network/archivist-wrapper'\nimport { BoundWitnessBuilder } from '@xyo-network/boundwitness-builder'\nimport { isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport {\n IndexingDivinerConfig,\n IndexingDivinerConfigSchema,\n IndexingDivinerParams,\n IndexingDivinerStage,\n IndexingDivinerState,\n} from '@xyo-network/diviner-indexing-model'\nimport { asDivinerInstance, DivinerConfigSchema, DivinerModule, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { DivinerWrapper } from '@xyo-network/diviner-wrapper'\nimport { isModuleState, ModuleState, ModuleStateSchema } from '@xyo-network/module-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload } from '@xyo-network/payload-model'\n\nexport type ConfigStoreKey = 'indexStore' | 'stateStore'\n\nexport type ConfigStore = Extract<keyof IndexingDivinerConfig, ConfigStoreKey>\n\nconst moduleName = 'IndexingDiviner'\n\nexport class IndexingDiviner<\n TParams extends IndexingDivinerParams = IndexingDivinerParams,\n TIn extends Payload = Payload,\n TOut extends Payload = Payload,\n TEventData extends DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut> = DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut>,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override readonly configSchemas: string[] = [IndexingDivinerConfigSchema, DivinerConfigSchema]\n\n private _lastState?: ModuleState<IndexingDivinerState>\n private _pollId?: string | number | NodeJS.Timeout\n\n get payloadDivinerLimit() {\n return this.config.payloadDivinerLimit ?? 1000\n }\n\n get pollFrequency() {\n return this.config.pollFrequency ?? 10_000\n }\n\n /**\n * Works via batched iteration of the source archivist to populate the index.\n * @returns A promise that resolves when the background process is complete\n */\n protected backgroundDivine = async (): Promise<void> => {\n // Load last state\n const lastState = await this.retrieveState()\n // Get next batch of results\n const indexCandidateDiviner = await this.getIndexingDivinerStage('stateToIndexCandidateDiviner')\n const results = lastState ? await indexCandidateDiviner.divine([lastState]) : await indexCandidateDiviner.divine()\n // Filter next state out from results\n const nextState = results.find(isModuleState<IndexingDivinerState>)\n const indexCandidates = results.filter((x) => !isModuleState(x))\n // Transform candidates to indexes\n const toIndexTransformDiviner = await this.getIndexingDivinerStage('indexCandidateToIndexDiviner')\n const indexes = await toIndexTransformDiviner.divine(indexCandidates)\n // Insert index results\n const indexArchivist = await this.getArchivistForStore('indexStore')\n await indexArchivist.insert(indexes)\n // Update state\n if (nextState) {\n await this.commitState(nextState)\n }\n }\n\n /**\n * Commit the internal state of the Diviner process. This is similar\n * to a transaction completion in a database and should only be called\n * when results have been successfully persisted to the appropriate\n * external stores.\n * @param nextState The state to commit\n */\n protected async commitState(nextState: ModuleState<IndexingDivinerState>) {\n // Don't commit state if no state has changed\n if (nextState.state.offset === this._lastState?.state.offset) return\n this._lastState = nextState\n const archivist = await this.getArchivistForStore('stateStore')\n const [bw] = await new BoundWitnessBuilder().payload(nextState).witness(this.account).build()\n await archivist.insert([bw, nextState])\n }\n\n protected override async divineHandler(payloads: TIn[] = []): Promise<TOut[]> {\n const indexPayloadDiviner = await this.getPayloadDivinerForStore('indexStore')\n const divinerQueryToIndexQueryDiviner = await this.getIndexingDivinerStage('divinerQueryToIndexQueryDiviner')\n const indexQueryResponseToDivinerQueryResponseDiviner = await this.getIndexingDivinerStage('indexQueryResponseToDivinerQueryResponseDiviner')\n const results = (\n await Promise.all(\n payloads.map(async (payload) => {\n const indexQuery = await divinerQueryToIndexQueryDiviner.divine([payload])\n // Divine the results\n const indexedResults = await indexPayloadDiviner.divine(indexQuery)\n // Transform the results to the response shape\n const response = await Promise.all(\n indexedResults.flat().map((indexedResult) => indexQueryResponseToDivinerQueryResponseDiviner.divine([payload, indexedResult])),\n )\n return response.flat()\n }),\n )\n ).flat()\n // TODO: Infer this type over casting to this type\n return results as TOut[]\n }\n\n /**\n * Retrieves the archivist for the specified store\n * @param store The store to retrieve the archivist for\n * @returns The archivist for the specified store\n */\n protected async getArchivistForStore(store: ConfigStore) {\n const name = assertEx(this.config?.[store]?.archivist, () => `${moduleName}: Config for ${store}.archivist not specified`)\n const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve ${store}.archivist`)\n return ArchivistWrapper.wrap(mod, this.account)\n }\n\n /**\n * Retrieves the BoundWitness Diviner for the specified store\n * @param store The store to retrieve the BoundWitness Diviner for\n * @returns The BoundWitness Diviner for the specified store\n */\n protected async getBoundWitnessDivinerForStore(store: ConfigStore) {\n const name = assertEx(this.config?.[store]?.boundWitnessDiviner, () => `${moduleName}: Config for ${store}.boundWitnessDiviner not specified`)\n const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve ${store}.boundWitnessDiviner`)\n return DivinerWrapper.wrap(mod, this.account)\n }\n\n /**\n * Gets the Diviner for the supplied Indexing Diviner stage\n * @param transform The Indexing Diviner stage\n * @returns The diviner corresponding to the Indexing Diviner stage\n */\n protected async getIndexingDivinerStage(transform: IndexingDivinerStage) {\n const nameOrAddress = assertEx(\n this.config?.indexingDivinerStages?.[transform],\n () => `${moduleName}: Config for indexingDivinerStages.${transform} not specified`,\n )\n const mod = await this.resolve(nameOrAddress)\n return assertEx(asDivinerInstance(mod), () => `${moduleName}: Failed to resolve indexing diviner stage for ${transform}`)\n }\n\n /**\n * Retrieves the Payload Diviner for the specified store\n * @param store The store to retrieve the Payload Diviner for\n * @returns The Payload Diviner for the specified store\n */\n protected async getPayloadDivinerForStore(store: ConfigStore) {\n const name = assertEx(this.config?.[store]?.payloadDiviner, () => `${moduleName}: Config for ${store}.payloadDiviner not specified`)\n const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve ${store}.payloadDiviner`)\n return DivinerWrapper.wrap(mod, this.account)\n }\n\n /**\n * Retrieves the last state of the Diviner process. Used to recover state after\n * preemptions, reboots, etc.\n */\n protected async retrieveState(): Promise<ModuleState<IndexingDivinerState> | undefined> {\n if (this._lastState) return this._lastState\n let hash: string = ''\n const diviner = await this.getBoundWitnessDivinerForStore('stateStore')\n const query = await new PayloadBuilder<BoundWitnessDivinerQueryPayload>({ schema: BoundWitnessDivinerQuerySchema })\n .fields({\n address: this.account.address,\n limit: 1,\n offset: 0,\n order: 'desc',\n payload_schemas: [ModuleStateSchema],\n })\n .build()\n const boundWitnesses = await diviner.divine([query])\n if (boundWitnesses.length > 0) {\n const boundWitness = boundWitnesses[0]\n if (isBoundWitness(boundWitness)) {\n // Find the index for this address in the BoundWitness that is a ModuleState\n hash = boundWitness.addresses\n .map((address, index) => ({ address, index }))\n .filter(({ address }) => address === this.account.address)\n // eslint-disable-next-line unicorn/no-array-reduce\n .reduce(\n (prev, curr) => (boundWitness.payload_schemas?.[curr?.index] === ModuleStateSchema ? boundWitness.payload_hashes[curr?.index] : prev),\n '',\n )\n }\n }\n\n // If we able to located the last state\n if (hash) {\n // Get last state\n const archivist = await this.getArchivistForStore('stateStore')\n const payload = (await archivist.get([hash])).find(isModuleState<IndexingDivinerState>)\n if (payload) {\n return payload\n }\n }\n return undefined\n }\n\n protected override async startHandler(): Promise<boolean> {\n await super.startHandler()\n this.poll()\n return true\n }\n\n protected override async stopHandler(_timeout?: number | undefined): Promise<boolean> {\n if (this._pollId) {\n clearTimeout(this._pollId)\n this._pollId = undefined\n }\n return await super.stopHandler()\n }\n\n /**\n * Runs the background divine process on a loop with a delay\n * specified by the `config.pollFrequency`\n */\n private poll() {\n this._pollId = setTimeout(async () => {\n try {\n await Promise.resolve()\n await this.backgroundDivine()\n } catch (e) {\n console.log(e)\n } finally {\n if (this._pollId) clearTimeout(this._pollId)\n this._pollId = undefined\n this.poll()\n }\n }, this.pollFrequency)\n }\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AACzB,SAAS,uBAAuB;AAChC,SAAS,wBAAwB;AACjC,SAAS,2BAA2B;AACpC,SAAS,sBAAsB;AAC/B,SAA0C,sCAAsC;AAChF;AAAA,EAEE;AAAA,OAIK;AACP,SAAS,mBAAmB,2BAAkE;AAC9F,SAAS,sBAAsB;AAC/B,SAAS,eAA4B,yBAAyB;AAC9D,SAAS,sBAAsB;AAO/B,IAAM,aAAa;AAEZ,IAAM,kBAAN,cAKG,gBAAgD;AAAA,EACxD,OAAyB,gBAA0B,CAAC,6BAA6B,mBAAmB;AAAA,EAE5F;AAAA,EACA;AAAA,EAER,IAAI,sBAAsB;AACxB,WAAO,KAAK,OAAO,uBAAuB;AAAA,EAC5C;AAAA,EAEA,IAAI,gBAAgB;AAClB,WAAO,KAAK,OAAO,iBAAiB;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMU,mBAAmB,YAA2B;AAEtD,UAAM,YAAY,MAAM,KAAK,cAAc;AAE3C,UAAM,wBAAwB,MAAM,KAAK,wBAAwB,8BAA8B;AAC/F,UAAM,UAAU,YAAY,MAAM,sBAAsB,OAAO,CAAC,SAAS,CAAC,IAAI,MAAM,sBAAsB,OAAO;AAEjH,UAAM,YAAY,QAAQ,KAAK,aAAmC;AAClE,UAAM,kBAAkB,QAAQ,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;AAE/D,UAAM,0BAA0B,MAAM,KAAK,wBAAwB,8BAA8B;AACjG,UAAM,UAAU,MAAM,wBAAwB,OAAO,eAAe;AAEpE,UAAM,iBAAiB,MAAM,KAAK,qBAAqB,YAAY;AACnE,UAAM,eAAe,OAAO,OAAO;AAEnC,QAAI,WAAW;AACb,YAAM,KAAK,Y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AW,YAAY;AACpC,UAAI;AACF,cAAM,QAAQ,QAAQ;AACtB,cAAM,KAAK,iBAAiB;AAAA,MAC9B,SAAS,GAAG;AACV,gBAAQ,IAAI,CAAC;AAAA,MACf,UAAE;AACA,YAAI,KAAK;AAAS,uBAAa,KAAK,OAAO;AAC3C,aAAK,UAAU;AACf,aAAK,KAAK;AAAA,MACZ;AAAA,IACF,GAAG,KAAK,aAAa;AAAA,EACvB;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/Diviner.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { AbstractDiviner } from '@xyo-network/abstract-diviner'\nimport { ArchivistWrapper } from '@xyo-network/archivist-wrapper'\nimport { BoundWitnessBuilder } from '@xyo-network/boundwitness-builder'\nimport { isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport {\n IndexingDivinerConfig,\n IndexingDivinerConfigSchema,\n IndexingDivinerParams,\n IndexingDivinerStage,\n IndexingDivinerState,\n} from '@xyo-network/diviner-indexing-model'\nimport { asDivinerInstance, DivinerConfigSchema, DivinerModule, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { DivinerWrapper } from '@xyo-network/diviner-wrapper'\nimport { creatableModule, isModuleState, ModuleState, ModuleStateSchema } from '@xyo-network/module-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload } from '@xyo-network/payload-model'\n\nexport type ConfigStoreKey = 'indexStore' | 'stateStore'\n\nexport type ConfigStore = Extract<keyof IndexingDivinerConfig, ConfigStoreKey>\n\nconst moduleName = 'IndexingDiviner'\n\n@creatableModule<IndexingDiviner>()\nexport class IndexingDiviner<\n TParams extends IndexingDivinerParams = IndexingDivinerParams,\n TIn extends Payload = Payload,\n TOut extends Payload = Payload,\n TEventData extends DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut> = DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut>,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override readonly allowRandomAccount = false\n static override readonly configSchemas: string[] = [IndexingDivinerConfigSchema, DivinerConfigSchema]\n\n private _lastState?: ModuleState<IndexingDivinerState>\n private _pollId?: string | number | NodeJS.Timeout\n\n get payloadDivinerLimit() {\n return this.config.payloadDivinerLimit ?? 1000\n }\n\n get pollFrequency() {\n return this.config.pollFrequency ?? 10_000\n }\n\n /**\n * Works via batched iteration of the source archivist to populate the index.\n * @returns A promise that resolves when the background process is complete\n */\n protected backgroundDivine = async (): Promise<void> => {\n // Load last state\n const lastState = await this.retrieveState()\n // Get next batch of results\n const indexCandidateDiviner = await this.getIndexingDivinerStage('stateToIndexCandidateDiviner')\n const results = lastState ? await indexCandidateDiviner.divine([lastState]) : await indexCandidateDiviner.divine()\n // Filter next state out from results\n const nextState = results.find(isModuleState<IndexingDivinerState>)\n const indexCandidates = results.filter((x) => !isModuleState(x))\n // Transform candidates to indexes\n const toIndexTransformDiviner = await this.getIndexingDivinerStage('indexCandidateToIndexDiviner')\n const indexes = await toIndexTransformDiviner.divine(indexCandidates)\n // Insert index results\n const indexArchivist = await this.getArchivistForStore('indexStore')\n await indexArchivist.insert(indexes)\n // Update state\n if (nextState) {\n await this.commitState(nextState)\n }\n }\n\n /**\n * Commit the internal state of the Diviner process. This is similar\n * to a transaction completion in a database and should only be called\n * when results have been successfully persisted to the appropriate\n * external stores.\n * @param nextState The state to commit\n */\n protected async commitState(nextState: ModuleState<IndexingDivinerState>) {\n // Don't commit state if no state has changed\n if (nextState.state.offset === this._lastState?.state.offset) return\n this._lastState = nextState\n const archivist = await this.getArchivistForStore('stateStore')\n const [bw] = await new BoundWitnessBuilder().payload(nextState).witness(this.account).build()\n await archivist.insert([bw, nextState])\n }\n\n protected override async divineHandler(payloads: TIn[] = []): Promise<TOut[]> {\n const indexPayloadDiviner = await this.getPayloadDivinerForStore('indexStore')\n const divinerQueryToIndexQueryDiviner = await this.getIndexingDivinerStage('divinerQueryToIndexQueryDiviner')\n const indexQueryResponseToDivinerQueryResponseDiviner = await this.getIndexingDivinerStage('indexQueryResponseToDivinerQueryResponseDiviner')\n const results = (\n await Promise.all(\n payloads.map(async (payload) => {\n const indexQuery = await divinerQueryToIndexQueryDiviner.divine([payload])\n // Divine the results\n const indexedResults = await indexPayloadDiviner.divine(indexQuery)\n // Transform the results to the response shape\n const response = await Promise.all(\n indexedResults.flat().map((indexedResult) => indexQueryResponseToDivinerQueryResponseDiviner.divine([payload, indexedResult])),\n )\n return response.flat()\n }),\n )\n ).flat()\n // TODO: Infer this type over casting to this type\n return results as TOut[]\n }\n\n /**\n * Retrieves the archivist for the specified store\n * @param store The store to retrieve the archivist for\n * @returns The archivist for the specified store\n */\n protected async getArchivistForStore(store: ConfigStore) {\n const name = assertEx(this.config?.[store]?.archivist, () => `${moduleName}: Config for ${store}.archivist not specified`)\n const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve ${store}.archivist`)\n return ArchivistWrapper.wrap(mod, this.account)\n }\n\n /**\n * Retrieves the BoundWitness Diviner for the specified store\n * @param store The store to retrieve the BoundWitness Diviner for\n * @returns The BoundWitness Diviner for the specified store\n */\n protected async getBoundWitnessDivinerForStore(store: ConfigStore) {\n const name = assertEx(this.config?.[store]?.boundWitnessDiviner, () => `${moduleName}: Config for ${store}.boundWitnessDiviner not specified`)\n const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve ${store}.boundWitnessDiviner`)\n return DivinerWrapper.wrap(mod, this.account)\n }\n\n /**\n * Gets the Diviner for the supplied Indexing Diviner stage\n * @param transform The Indexing Diviner stage\n * @returns The diviner corresponding to the Indexing Diviner stage\n */\n protected async getIndexingDivinerStage(transform: IndexingDivinerStage) {\n const nameOrAddress = assertEx(\n this.config?.indexingDivinerStages?.[transform],\n () => `${moduleName}: Config for indexingDivinerStages.${transform} not specified`,\n )\n const mod = await this.resolve(nameOrAddress)\n return assertEx(asDivinerInstance(mod), () => `${moduleName}: Failed to resolve indexing diviner stage for ${transform}`)\n }\n\n /**\n * Retrieves the Payload Diviner for the specified store\n * @param store The store to retrieve the Payload Diviner for\n * @returns The Payload Diviner for the specified store\n */\n protected async getPayloadDivinerForStore(store: ConfigStore) {\n const name = assertEx(this.config?.[store]?.payloadDiviner, () => `${moduleName}: Config for ${store}.payloadDiviner not specified`)\n const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve ${store}.payloadDiviner`)\n return DivinerWrapper.wrap(mod, this.account)\n }\n\n /**\n * Retrieves the last state of the Diviner process. Used to recover state after\n * preemptions, reboots, etc.\n */\n protected async retrieveState(): Promise<ModuleState<IndexingDivinerState> | undefined> {\n if (this._lastState) return this._lastState\n let hash: string = ''\n const diviner = await this.getBoundWitnessDivinerForStore('stateStore')\n const query = await new PayloadBuilder<BoundWitnessDivinerQueryPayload>({ schema: BoundWitnessDivinerQuerySchema })\n .fields({\n address: this.account.address,\n limit: 1,\n offset: 0,\n order: 'desc',\n payload_schemas: [ModuleStateSchema],\n })\n .build()\n const boundWitnesses = await diviner.divine([query])\n if (boundWitnesses.length > 0) {\n const boundWitness = boundWitnesses[0]\n if (isBoundWitness(boundWitness)) {\n // Find the index for this address in the BoundWitness that is a ModuleState\n hash = boundWitness.addresses\n .map((address, index) => ({ address, index }))\n .filter(({ address }) => address === this.account.address)\n // eslint-disable-next-line unicorn/no-array-reduce\n .reduce(\n (prev, curr) => (boundWitness.payload_schemas?.[curr?.index] === ModuleStateSchema ? boundWitness.payload_hashes[curr?.index] : prev),\n '',\n )\n }\n }\n\n // If we able to located the last state\n if (hash) {\n // Get last state\n const archivist = await this.getArchivistForStore('stateStore')\n const payload = (await archivist.get([hash])).find(isModuleState<IndexingDivinerState>)\n if (payload) {\n return payload\n }\n }\n return undefined\n }\n\n protected override async startHandler(): Promise<boolean> {\n await super.startHandler()\n this.poll()\n return true\n }\n\n protected override async stopHandler(_timeout?: number | undefined): Promise<boolean> {\n if (this._pollId) {\n clearTimeout(this._pollId)\n this._pollId = undefined\n }\n return await super.stopHandler()\n }\n\n /**\n * Runs the background divine process on a loop with a delay\n * specified by the `config.pollFrequency`\n */\n private poll() {\n this._pollId = setTimeout(async () => {\n try {\n await Promise.resolve()\n await this.backgroundDivine()\n } catch (e) {\n console.log(e)\n } finally {\n if (this._pollId) clearTimeout(this._pollId)\n this._pollId = undefined\n this.poll()\n }\n }, this.pollFrequency)\n }\n}\n"],"mappings":";;;;;;;;;AAAA,SAASA,gBAAgB;AACzB,SAASC,uBAAuB;AAChC,SAASC,wBAAwB;AACjC,SAASC,2BAA2B;AACpC,SAASC,sBAAsB;AAC/B,SAA0CC,sCAAsC;AAChF,SAEEC,mCAIK;AACP,SAASC,mBAAmBC,2BAAkE;AAC9F,SAASC,sBAAsB;AAC/B,SAASC,iBAAiBC,eAA4BC,yBAAyB;AAC/E,SAASC,sBAAsB;;;;;;;;;;;;AAO/B,IAAMC,aAAa;AAGZ,IAAMC,mBAAN,MAAMA,yBAKHC,gBAAAA;EAIAC;EACAC;EAER,IAAIC,sBAAsB;AACxB,WAAO,KAAKC,OAAOD,uBAAuB;EAC5C;EAEA,IAAIE,gBAAgB;AAClB,WAAO,KAAKD,OAAOC,iBAAiB;EACtC;;;;;EAMUC,mBAAmB,YAAA;AAE3B,UAAMC,YAAY,MAAM,KAAKC,cAAa;AAE1C,UAAMC,wBAAwB,MAAM,KAAKC,wBAAwB,8BAAA;AACjE,UAAMC,UAAUJ,YAAY,MAAME,sBAAsBG,OAAO;MAACL;KAAU,IAAI,MAAME,sBAAsBG,OAAM;AAEhH,UAAMC,YAAYF,QAAQG,KAAKC,aAAAA;AAC/B,UAAMC,kBAAkBL,QAAQM,OAAO,CAACC,MAAM,CAACH,cAAcG,CAAAA,CAAAA;AAE7D,UAAMC,0BAA0B,MAAM,KAAKT,wBAAwB,8BAAA;AACnE,UAAMU,UAAU,MAAMD,wBAAwBP,OAAOI,eAAAA;AAErD,UAAMK,iBAAiB,MAAM,KAAKC,qBA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,iBAAgB;MAC7B,SAASuF,GAAG;AACVC,gBAAQC,IAAIF,CAAAA;MACd,UAAA;AACE,YAAI,KAAK3F;AAASyF,uBAAa,KAAKzF,OAAO;AAC3C,aAAKA,UAAUoF;AACf,aAAKE,KAAI;MACX;IACF,GAAG,KAAKnF,aAAa;EACvB;AACF;AA1MUL;AACR,cANWD,kBAMciG,sBAAqB;AAC9C,cAPWjG,kBAOckG,iBAA0B;EAACC;EAA6BC;;AAP5E,IAAMpG,kBAAN;AAAMA,kBAAAA,aAAAA;EADZqG,gBAAAA;GACYrG,eAAAA;","names":["assertEx","AbstractDiviner","ArchivistWrapper","BoundWitnessBuilder","isBoundWitness","BoundWitnessDivinerQuerySchema","IndexingDivinerConfigSchema","asDivinerInstance","DivinerConfigSchema","DivinerWrapper","creatableModule","isModuleState","ModuleStateSchema","PayloadBuilder","moduleName","IndexingDiviner","AbstractDiviner","_lastState","_pollId","payloadDivinerLimit","config","pollFrequency","backgroundDivine","lastState","retrieveState","indexCandidateDiviner","getIndexingDivinerStage","results","divine","nextState","find","isModuleState","indexCandidates","filter","x","toIndexTransformDiviner","indexes","indexArchivist","getArchivistForStore","insert","commitState","state","offset","archivist","bw","BoundWitnessBuilder","payload","witness","account","build","divineHandler","payloads","indexPayloadDiviner","getPayloadDivinerForStore","divinerQueryToIndexQueryDiviner","indexQueryResponseToDivinerQueryResponseDiviner","Promise","all","map","indexQuery","indexedResults","response","flat","indexedResult","store","name","assertEx","mod","resolve","ArchivistWrapper","wrap","getBoundWitnessDivinerForStore","boundWitnessDiviner","DivinerWrapper","transform","nameOrAddress","indexingDivinerStages","asDivinerInstance","payloadDiviner","hash","diviner","query","PayloadBuilder","schema","BoundWitnessDivinerQuerySchema","fields","address","limit","order","payload_schemas","ModuleStateSchema","boundWitnesses","length","boundWitness","isBoundWitness","addresses","index","reduce","prev","curr","payload_hashes","get","undefined","startHandler","poll","stopHandler","_timeout","clearTimeout","setTimeout","e","console","log","allowRandomAccount","configSchemas","IndexingDivinerConfigSchema","DivinerConfigSchema","creatableModule"]}
|
package/package.json
CHANGED
|
@@ -11,17 +11,17 @@
|
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@xylabs/assert": "^2.13.20",
|
|
14
|
-
"@xyo-network/abstract-diviner": "~2.
|
|
15
|
-
"@xyo-network/archivist-wrapper": "~2.
|
|
16
|
-
"@xyo-network/boundwitness-builder": "~2.
|
|
17
|
-
"@xyo-network/boundwitness-model": "~2.
|
|
18
|
-
"@xyo-network/diviner-boundwitness-model": "~2.
|
|
19
|
-
"@xyo-network/diviner-indexing-model": "~2.
|
|
20
|
-
"@xyo-network/diviner-model": "~2.
|
|
21
|
-
"@xyo-network/diviner-wrapper": "~2.
|
|
22
|
-
"@xyo-network/module-model": "~2.
|
|
23
|
-
"@xyo-network/payload-builder": "~2.
|
|
24
|
-
"@xyo-network/payload-model": "~2.
|
|
14
|
+
"@xyo-network/abstract-diviner": "~2.85.1",
|
|
15
|
+
"@xyo-network/archivist-wrapper": "~2.85.1",
|
|
16
|
+
"@xyo-network/boundwitness-builder": "~2.85.1",
|
|
17
|
+
"@xyo-network/boundwitness-model": "~2.85.1",
|
|
18
|
+
"@xyo-network/diviner-boundwitness-model": "~2.85.1",
|
|
19
|
+
"@xyo-network/diviner-indexing-model": "~2.85.1",
|
|
20
|
+
"@xyo-network/diviner-model": "~2.85.1",
|
|
21
|
+
"@xyo-network/diviner-wrapper": "~2.85.1",
|
|
22
|
+
"@xyo-network/module-model": "~2.85.1",
|
|
23
|
+
"@xyo-network/payload-builder": "~2.85.1",
|
|
24
|
+
"@xyo-network/payload-model": "~2.85.1"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@xylabs/ts-scripts-yarn3": "^3.2.25",
|
|
@@ -67,6 +67,6 @@
|
|
|
67
67
|
"url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
|
|
68
68
|
},
|
|
69
69
|
"sideEffects": false,
|
|
70
|
-
"version": "2.
|
|
70
|
+
"version": "2.85.1",
|
|
71
71
|
"type": "module"
|
|
72
72
|
}
|
package/src/Diviner.ts
CHANGED
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
} from '@xyo-network/diviner-indexing-model'
|
|
14
14
|
import { asDivinerInstance, DivinerConfigSchema, DivinerModule, DivinerModuleEventData } from '@xyo-network/diviner-model'
|
|
15
15
|
import { DivinerWrapper } from '@xyo-network/diviner-wrapper'
|
|
16
|
-
import { isModuleState, ModuleState, ModuleStateSchema } from '@xyo-network/module-model'
|
|
16
|
+
import { creatableModule, isModuleState, ModuleState, ModuleStateSchema } from '@xyo-network/module-model'
|
|
17
17
|
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
18
18
|
import { Payload } from '@xyo-network/payload-model'
|
|
19
19
|
|
|
@@ -23,12 +23,14 @@ export type ConfigStore = Extract<keyof IndexingDivinerConfig, ConfigStoreKey>
|
|
|
23
23
|
|
|
24
24
|
const moduleName = 'IndexingDiviner'
|
|
25
25
|
|
|
26
|
+
@creatableModule<IndexingDiviner>()
|
|
26
27
|
export class IndexingDiviner<
|
|
27
28
|
TParams extends IndexingDivinerParams = IndexingDivinerParams,
|
|
28
29
|
TIn extends Payload = Payload,
|
|
29
30
|
TOut extends Payload = Payload,
|
|
30
31
|
TEventData extends DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut> = DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut>,
|
|
31
32
|
> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {
|
|
33
|
+
static override readonly allowRandomAccount = false
|
|
32
34
|
static override readonly configSchemas: string[] = [IndexingDivinerConfigSchema, DivinerConfigSchema]
|
|
33
35
|
|
|
34
36
|
private _lastState?: ModuleState<IndexingDivinerState>
|