@xyo-network/diviner-indexing-memory 3.18.9 → 4.0.0
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/neutral/index.mjs +4 -4
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/types/Diviner.d.ts +7 -43
- package/dist/types/Diviner.d.ts.map +1 -1
- package/package.json +18 -17
- package/src/Diviner.ts +6 -6
package/dist/neutral/index.mjs
CHANGED
|
@@ -17,6 +17,7 @@ var __superGet = (cls, obj, key) => __reflectGet(__getProtoOf(cls), key, obj);
|
|
|
17
17
|
// src/Diviner.ts
|
|
18
18
|
import { assertEx } from "@xylabs/assert";
|
|
19
19
|
import { clearTimeoutEx, setTimeoutEx } from "@xylabs/timer";
|
|
20
|
+
import { isString } from "@xylabs/typeof";
|
|
20
21
|
import { ArchivistWrapper } from "@xyo-network/archivist-wrapper";
|
|
21
22
|
import { BoundWitnessBuilder } from "@xyo-network/boundwitness-builder";
|
|
22
23
|
import { isBoundWitness } from "@xyo-network/boundwitness-model";
|
|
@@ -177,14 +178,13 @@ var IndexingDiviner = class extends AbstractDiviner {
|
|
|
177
178
|
async startHandler() {
|
|
178
179
|
await super.startHandler();
|
|
179
180
|
this.poll();
|
|
180
|
-
return true;
|
|
181
181
|
}
|
|
182
182
|
async stopHandler(_timeout) {
|
|
183
|
-
if (this._pollId) {
|
|
183
|
+
if (isString(this._pollId)) {
|
|
184
184
|
clearTimeout(this._pollId);
|
|
185
185
|
this._pollId = void 0;
|
|
186
186
|
}
|
|
187
|
-
|
|
187
|
+
await super.stopHandler();
|
|
188
188
|
}
|
|
189
189
|
/**
|
|
190
190
|
* Runs the background divine process on a loop with a delay
|
|
@@ -205,7 +205,7 @@ var IndexingDiviner = class extends AbstractDiviner {
|
|
|
205
205
|
}, this.pollFrequency);
|
|
206
206
|
}
|
|
207
207
|
};
|
|
208
|
-
__publicField(IndexingDiviner, "allowRandomAccount",
|
|
208
|
+
__publicField(IndexingDiviner, "allowRandomAccount", true);
|
|
209
209
|
__publicField(IndexingDiviner, "configSchemas", [...__superGet(IndexingDiviner, IndexingDiviner, "configSchemas"), IndexingDivinerConfigSchema]);
|
|
210
210
|
__publicField(IndexingDiviner, "defaultConfigSchema", IndexingDivinerConfigSchema);
|
|
211
211
|
IndexingDiviner = __decorateClass([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Diviner.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { Hash } from '@xylabs/hex'\nimport { clearTimeoutEx, setTimeoutEx } from '@xylabs/timer'\nimport { ArchivistWrapper } from '@xyo-network/archivist-wrapper'\nimport { BoundWitnessBuilder } from '@xyo-network/boundwitness-builder'\nimport { isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { AbstractDiviner } from '@xyo-network/diviner-abstract'\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 {\n asDivinerInstance, DivinerInstance, DivinerModuleEventData,\n} from '@xyo-network/diviner-model'\nimport { DivinerWrapper } from '@xyo-network/diviner-wrapper'\nimport {\n creatableModule, isModuleState, ModuleState, ModuleStateSchema,\n} from '@xyo-network/module-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport {\n Payload, Schema, SequenceConstants, WithStorageMeta,\n} 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<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<\n DivinerInstance<TParams, TIn, TOut>,\n TIn,\n TOut\n >,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override readonly allowRandomAccount = false\n static override readonly configSchemas: Schema[] = [...super.configSchemas, IndexingDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = IndexingDivinerConfigSchema\n\n private _lastState?: ModuleState<IndexingDivinerState>\n private _pollId?: string\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.cursor === this._lastState?.state.cursor) return\n this._lastState = nextState\n const archivist = await this.getArchivistForStore('stateStore')\n const [bw] = await new BoundWitnessBuilder().payload(nextState).signer(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 [${name}]`)\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 [${name}]`)\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}`) as DivinerInstance\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 [${name}]`)\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 const accountAddress = this.account.address\n if (this._lastState) return this._lastState\n let hash: Hash = ''\n const diviner = await this.getBoundWitnessDivinerForStore('stateStore')\n const query = new PayloadBuilder<BoundWitnessDivinerQueryPayload>({ schema: BoundWitnessDivinerQuerySchema })\n .fields({\n address: accountAddress,\n limit: 1,\n cursor: SequenceConstants.minLocalSequence,\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 === accountAddress)\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 '' as Hash,\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 as WithStorageMeta<ModuleState<IndexingDivinerState>>\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 = setTimeoutEx(async () => {\n try {\n await Promise.resolve()\n await this.backgroundDivine()\n } catch (e) {\n console.log(e)\n } finally {\n if (this._pollId) clearTimeoutEx(this._pollId)\n this._pollId = undefined\n this.poll()\n }\n }, this.pollFrequency)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA,SAAS,gBAAgB;AAEzB,SAAS,gBAAgB,oBAAoB;AAC7C,SAAS,wBAAwB;AACjC,SAAS,2BAA2B;AACpC,SAAS,sBAAsB;AAC/B,SAAS,uBAAuB;AAChC,SAA0C,sCAAsC;AAChF;AAAA,EAEE;AAAA,OAIK;AACP;AAAA,EACE;AAAA,OACK;AACP,SAAS,sBAAsB;AAC/B;AAAA,EACE;AAAA,EAAiB;AAAA,EAA4B;AAAA,OACxC;AACP,SAAS,sBAAsB;AAC/B;AAAA,EACmB;AAAA,OACZ;AAMP,IAAM,aAAa;AAGZ,IAAM,kBAAN,cASG,gBAAgD;AAAA,EAKhD;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,YA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T;AAAA,EAEA,MAAyB,eAAiC;AACxD,UAAM,MAAM,aAAa;AACzB,SAAK,KAAK;AACV,WAAO;AAAA,EACT;AAAA,EAEA,MAAyB,YAAY,UAAiD;AACpF,QAAI,KAAK,SAAS;AAChB,mBAAa,KAAK,OAAO;AACzB,WAAK,UAAU;AAAA,IACjB;AACA,WAAO,MAAM,MAAM,YAAY;AAAA,EACjC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMQ,OAAO;AACb,SAAK,UAAU,aAAa,YAAY;AACtC,UAAI;AACF,cAAM,QAAQ,QAAQ;AACtB,cAAM,KAAK,iBAAiB;AAAA,MAC9B,SAAS,GAAG;AACV,gBAAQ,IAAI,CAAC;AAAA,MACf,UAAE;AACA,YAAI,KAAK,QAAS,gBAAe,KAAK,OAAO;AAC7C,aAAK,UAAU;AACf,aAAK,KAAK;AAAA,MACZ;AAAA,IACF,GAAG,KAAK,aAAa;AAAA,EACvB;AACF;AA3ME,cAVW,iBAUc,sBAAqB;AAC9C,cAXW,iBAWc,iBAA0B,CAAC,GAAG,6CAAM,kBAAe,2BAA2B;AACvG,cAZW,iBAYc,uBAA8B;AAZ5C,kBAAN;AAAA,EADN,gBAAiC;AAAA,GACrB;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/Diviner.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { Hash } from '@xylabs/hex'\nimport { clearTimeoutEx, setTimeoutEx } from '@xylabs/timer'\nimport { isString } from '@xylabs/typeof'\nimport { ArchivistWrapper } from '@xyo-network/archivist-wrapper'\nimport { BoundWitnessBuilder } from '@xyo-network/boundwitness-builder'\nimport { isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { AbstractDiviner } from '@xyo-network/diviner-abstract'\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 {\n asDivinerInstance, DivinerInstance, DivinerModuleEventData,\n} from '@xyo-network/diviner-model'\nimport { DivinerWrapper } from '@xyo-network/diviner-wrapper'\nimport {\n creatableModule, isModuleState, ModuleState, ModuleStateSchema,\n} from '@xyo-network/module-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport {\n Payload, Schema, SequenceConstants, WithStorageMeta,\n} 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<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<\n DivinerInstance<TParams, TIn, TOut>,\n TIn,\n TOut\n >,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override readonly allowRandomAccount = true\n static override readonly configSchemas: Schema[] = [...super.configSchemas, IndexingDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = IndexingDivinerConfigSchema\n\n private _lastState?: ModuleState<IndexingDivinerState>\n private _pollId?: string\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.cursor === this._lastState?.state.cursor) return\n this._lastState = nextState\n const archivist = await this.getArchivistForStore('stateStore')\n const [bw] = await new BoundWitnessBuilder().payload(nextState).signer(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 [${name}]`)\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 [${name}]`)\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}`) as DivinerInstance\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 [${name}]`)\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 const accountAddress = this.account.address\n if (this._lastState) return this._lastState\n let hash: Hash = ''\n const diviner = await this.getBoundWitnessDivinerForStore('stateStore')\n const query = new PayloadBuilder<BoundWitnessDivinerQueryPayload>({ schema: BoundWitnessDivinerQuerySchema })\n .fields({\n address: accountAddress,\n limit: 1,\n cursor: SequenceConstants.minLocalSequence,\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 === accountAddress)\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 '' as Hash,\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 as WithStorageMeta<ModuleState<IndexingDivinerState>>\n }\n }\n return undefined\n }\n\n protected override async startHandler() {\n await super.startHandler()\n this.poll()\n }\n\n protected override async stopHandler(_timeout?: number | undefined) {\n if (isString(this._pollId)) {\n clearTimeout(this._pollId)\n this._pollId = undefined\n }\n 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 = setTimeoutEx(async () => {\n try {\n await Promise.resolve()\n await this.backgroundDivine()\n } catch (e) {\n console.log(e)\n } finally {\n if (this._pollId) clearTimeoutEx(this._pollId)\n this._pollId = undefined\n this.poll()\n }\n }, this.pollFrequency)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA,SAAS,gBAAgB;AAEzB,SAAS,gBAAgB,oBAAoB;AAC7C,SAAS,gBAAgB;AACzB,SAAS,wBAAwB;AACjC,SAAS,2BAA2B;AACpC,SAAS,sBAAsB;AAC/B,SAAS,uBAAuB;AAChC,SAA0C,sCAAsC;AAChF;AAAA,E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ZW,iBAYc,uBAA8B;AAZ5C,kBAAN;AAAA,EADN,gBAAiC;AAAA,GACrB;","names":[]}
|
package/dist/types/Diviner.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { Payload, Schema } from '@xyo-network/payload-model';
|
|
|
8
8
|
export type ConfigStoreKey = 'indexStore' | 'stateStore';
|
|
9
9
|
export type ConfigStore = Extract<keyof IndexingDivinerConfig, ConfigStoreKey>;
|
|
10
10
|
export declare class IndexingDiviner<TParams extends IndexingDivinerParams = IndexingDivinerParams, TIn extends Payload = Payload, TOut extends Payload = Payload, TEventData extends DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut>> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {
|
|
11
|
-
static readonly allowRandomAccount =
|
|
11
|
+
static readonly allowRandomAccount = true;
|
|
12
12
|
static readonly configSchemas: Schema[];
|
|
13
13
|
static readonly defaultConfigSchema: Schema;
|
|
14
14
|
private _lastState?;
|
|
@@ -34,68 +34,32 @@ export declare class IndexingDiviner<TParams extends IndexingDivinerParams = Ind
|
|
|
34
34
|
* @param store The store to retrieve the archivist for
|
|
35
35
|
* @returns The archivist for the specified store
|
|
36
36
|
*/
|
|
37
|
-
protected getArchivistForStore(store: ConfigStore): Promise<ArchivistWrapper<import("@xyo-network/archivist-model").ArchivistModuleInstance<import("@
|
|
38
|
-
account?: import("@xyo-network/account-model").AccountInstance | "random";
|
|
39
|
-
addToResolvers?: boolean;
|
|
40
|
-
additionalSigners?: import("@xyo-network/account-model").AccountInstance[];
|
|
41
|
-
allowNameResolution?: boolean;
|
|
42
|
-
config: import("@xyo-network/module-model").AnyConfigSchema<import("@xyo-network/archivist-model").ArchivistConfig>;
|
|
43
|
-
ephemeralQueryAccountEnabled?: boolean;
|
|
44
|
-
moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[];
|
|
45
|
-
statusReporter?: import("@xyo-network/module-model").ModuleStatusReporter;
|
|
46
|
-
} & import("@xyo-network/module-model").ModuleChildrenParams, import("@xyo-network/archivist-model").ArchivistModuleEventData>>>;
|
|
37
|
+
protected getArchivistForStore(store: ConfigStore): Promise<ArchivistWrapper<import("@xyo-network/archivist-model").ArchivistModuleInstance<import("@xyo-network/module-model").ModuleParams<import("@xyo-network/module-model").AnyConfigSchema<import("@xyo-network/archivist-model").ArchivistConfig>>, import("@xyo-network/archivist-model").ArchivistModuleEventData>>>;
|
|
47
38
|
/**
|
|
48
39
|
* Retrieves the BoundWitness Diviner for the specified store
|
|
49
40
|
* @param store The store to retrieve the BoundWitness Diviner for
|
|
50
41
|
* @returns The BoundWitness Diviner for the specified store
|
|
51
42
|
*/
|
|
52
|
-
protected getBoundWitnessDivinerForStore(store: ConfigStore): Promise<DivinerWrapper<import("@xyo-network/diviner-model").DivinerModule<import("@
|
|
53
|
-
account?: import("@xyo-network/account-model").AccountInstance | "random";
|
|
54
|
-
addToResolvers?: boolean;
|
|
55
|
-
additionalSigners?: import("@xyo-network/account-model").AccountInstance[];
|
|
56
|
-
allowNameResolution?: boolean;
|
|
57
|
-
config: import("@xyo-network/module-model").AnyConfigSchema<import("@xyo-network/diviner-model").DivinerConfig>;
|
|
58
|
-
ephemeralQueryAccountEnabled?: boolean;
|
|
59
|
-
moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[];
|
|
60
|
-
statusReporter?: import("@xyo-network/module-model").ModuleStatusReporter;
|
|
61
|
-
} & import("@xyo-network/module-model").ModuleChildrenParams, DivinerModuleEventData>, Payload, Payload>>;
|
|
43
|
+
protected getBoundWitnessDivinerForStore(store: ConfigStore): Promise<DivinerWrapper<import("@xyo-network/diviner-model").DivinerModule<import("@xyo-network/diviner-model").DivinerParams<import("@xyo-network/module-model").AnyConfigSchema<import("@xyo-network/diviner-model").DivinerConfig>>, DivinerModuleEventData>, Payload, Payload>>;
|
|
62
44
|
/**
|
|
63
45
|
* Gets the Diviner for the supplied Indexing Diviner stage
|
|
64
46
|
* @param transform The Indexing Diviner stage
|
|
65
47
|
* @returns The diviner corresponding to the Indexing Diviner stage
|
|
66
48
|
*/
|
|
67
|
-
protected getIndexingDivinerStage(transform: IndexingDivinerStage): Promise<DivinerInstance<import("@
|
|
68
|
-
account?: import("@xyo-network/account-model").AccountInstance | "random";
|
|
69
|
-
addToResolvers?: boolean;
|
|
70
|
-
additionalSigners?: import("@xyo-network/account-model").AccountInstance[];
|
|
71
|
-
allowNameResolution?: boolean;
|
|
72
|
-
config: import("@xyo-network/module-model").AnyConfigSchema<import("@xyo-network/diviner-model").DivinerConfig>;
|
|
73
|
-
ephemeralQueryAccountEnabled?: boolean;
|
|
74
|
-
moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[];
|
|
75
|
-
statusReporter?: import("@xyo-network/module-model").ModuleStatusReporter;
|
|
76
|
-
} & import("@xyo-network/module-model").ModuleChildrenParams, Payload, Payload, DivinerModuleEventData>>;
|
|
49
|
+
protected getIndexingDivinerStage(transform: IndexingDivinerStage): Promise<DivinerInstance<import("@xyo-network/diviner-model").DivinerParams<import("@xyo-network/module-model").AnyConfigSchema<import("@xyo-network/diviner-model").DivinerConfig>>, Payload, Payload, DivinerModuleEventData>>;
|
|
77
50
|
/**
|
|
78
51
|
* Retrieves the Payload Diviner for the specified store
|
|
79
52
|
* @param store The store to retrieve the Payload Diviner for
|
|
80
53
|
* @returns The Payload Diviner for the specified store
|
|
81
54
|
*/
|
|
82
|
-
protected getPayloadDivinerForStore(store: ConfigStore): Promise<DivinerWrapper<import("@xyo-network/diviner-model").DivinerModule<import("@
|
|
83
|
-
account?: import("@xyo-network/account-model").AccountInstance | "random";
|
|
84
|
-
addToResolvers?: boolean;
|
|
85
|
-
additionalSigners?: import("@xyo-network/account-model").AccountInstance[];
|
|
86
|
-
allowNameResolution?: boolean;
|
|
87
|
-
config: import("@xyo-network/module-model").AnyConfigSchema<import("@xyo-network/diviner-model").DivinerConfig>;
|
|
88
|
-
ephemeralQueryAccountEnabled?: boolean;
|
|
89
|
-
moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[];
|
|
90
|
-
statusReporter?: import("@xyo-network/module-model").ModuleStatusReporter;
|
|
91
|
-
} & import("@xyo-network/module-model").ModuleChildrenParams, DivinerModuleEventData>, Payload, Payload>>;
|
|
55
|
+
protected getPayloadDivinerForStore(store: ConfigStore): Promise<DivinerWrapper<import("@xyo-network/diviner-model").DivinerModule<import("@xyo-network/diviner-model").DivinerParams<import("@xyo-network/module-model").AnyConfigSchema<import("@xyo-network/diviner-model").DivinerConfig>>, DivinerModuleEventData>, Payload, Payload>>;
|
|
92
56
|
/**
|
|
93
57
|
* Retrieves the last state of the Diviner process. Used to recover state after
|
|
94
58
|
* preemptions, reboots, etc.
|
|
95
59
|
*/
|
|
96
60
|
protected retrieveState(): Promise<ModuleState<IndexingDivinerState> | undefined>;
|
|
97
|
-
protected startHandler(): Promise<
|
|
98
|
-
protected stopHandler(_timeout?: number | undefined): Promise<
|
|
61
|
+
protected startHandler(): Promise<void>;
|
|
62
|
+
protected stopHandler(_timeout?: number | undefined): Promise<void>;
|
|
99
63
|
/**
|
|
100
64
|
* Runs the background divine process on a loop with a delay
|
|
101
65
|
* specified by the `config.pollFrequency`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AAGjE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAE/D,OAAO,EACL,qBAAqB,EAErB,qBAAqB,EACrB,oBAAoB,EACpB,oBAAoB,EACrB,MAAM,qCAAqC,CAAA;AAC5C,OAAO,EACc,eAAe,EAAE,sBAAsB,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AIG;cACa,oBAAoB,CAAC,KAAK,EAAE,WAAW;IAMvD;;;;OAIG;cACa,8BAA8B,CAAC,KAAK,EAAE,WAAW;IAMjE;;;;OAIG;cACa,uBAAuB,CAAC,SAAS,EAAE,oBAAoB;IASvE;;;;OAIG;cACa,yBAAyB,CAAC,KAAK,EAAE,WAAW;IAM5D;;;OAGG;cACa,aAAa,IAAI,OAAO,CAAC,WAAW,CAAC,oBAAoB,CAAC,GAAG,SAAS,CAAC;cA0C9D,YAAY;cAKZ,WAAW,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS;IAQlE;;;OAGG;IACH,OAAO,CAAC,IAAI;CAcb"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/diviner-indexing-memory",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
5
5
|
"homepage": "https://xyo.network",
|
|
6
6
|
"bugs": {
|
|
@@ -29,24 +29,25 @@
|
|
|
29
29
|
"module": "dist/neutral/index.mjs",
|
|
30
30
|
"types": "dist/types/index.d.ts",
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@xylabs/assert": "^4.
|
|
33
|
-
"@xylabs/timer": "^4.
|
|
34
|
-
"@
|
|
35
|
-
"@xyo-network/
|
|
36
|
-
"@xyo-network/boundwitness-
|
|
37
|
-
"@xyo-network/
|
|
38
|
-
"@xyo-network/diviner-
|
|
39
|
-
"@xyo-network/diviner-
|
|
40
|
-
"@xyo-network/diviner-model": "^
|
|
41
|
-
"@xyo-network/diviner-
|
|
42
|
-
"@xyo-network/
|
|
43
|
-
"@xyo-network/
|
|
44
|
-
"@xyo-network/payload-
|
|
32
|
+
"@xylabs/assert": "^4.12.30",
|
|
33
|
+
"@xylabs/timer": "^4.12.30",
|
|
34
|
+
"@xylabs/typeof": "^4.12.30",
|
|
35
|
+
"@xyo-network/archivist-wrapper": "^4.0.0",
|
|
36
|
+
"@xyo-network/boundwitness-builder": "^4.0.0",
|
|
37
|
+
"@xyo-network/boundwitness-model": "^4.0.0",
|
|
38
|
+
"@xyo-network/diviner-abstract": "^4.0.0",
|
|
39
|
+
"@xyo-network/diviner-boundwitness-model": "^4.0.0",
|
|
40
|
+
"@xyo-network/diviner-indexing-model": "^4.0.0",
|
|
41
|
+
"@xyo-network/diviner-model": "^4.0.0",
|
|
42
|
+
"@xyo-network/diviner-wrapper": "^4.0.0",
|
|
43
|
+
"@xyo-network/module-model": "^4.0.0",
|
|
44
|
+
"@xyo-network/payload-builder": "^4.0.0",
|
|
45
|
+
"@xyo-network/payload-model": "^4.0.0"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
47
|
-
"@xylabs/hex": "^4.
|
|
48
|
-
"@xylabs/ts-scripts-yarn3": "^6.5.
|
|
49
|
-
"@xylabs/tsconfig": "^6.5.
|
|
48
|
+
"@xylabs/hex": "^4.12.30",
|
|
49
|
+
"@xylabs/ts-scripts-yarn3": "^6.5.12",
|
|
50
|
+
"@xylabs/tsconfig": "^6.5.12",
|
|
50
51
|
"typescript": "^5.8.3"
|
|
51
52
|
},
|
|
52
53
|
"publishConfig": {
|
package/src/Diviner.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { assertEx } from '@xylabs/assert'
|
|
2
2
|
import { Hash } from '@xylabs/hex'
|
|
3
3
|
import { clearTimeoutEx, setTimeoutEx } from '@xylabs/timer'
|
|
4
|
+
import { isString } from '@xylabs/typeof'
|
|
4
5
|
import { ArchivistWrapper } from '@xyo-network/archivist-wrapper'
|
|
5
6
|
import { BoundWitnessBuilder } from '@xyo-network/boundwitness-builder'
|
|
6
7
|
import { isBoundWitness } from '@xyo-network/boundwitness-model'
|
|
@@ -42,7 +43,7 @@ export class IndexingDiviner<
|
|
|
42
43
|
TOut
|
|
43
44
|
>,
|
|
44
45
|
> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {
|
|
45
|
-
static override readonly allowRandomAccount =
|
|
46
|
+
static override readonly allowRandomAccount = true
|
|
46
47
|
static override readonly configSchemas: Schema[] = [...super.configSchemas, IndexingDivinerConfigSchema]
|
|
47
48
|
static override readonly defaultConfigSchema: Schema = IndexingDivinerConfigSchema
|
|
48
49
|
|
|
@@ -213,18 +214,17 @@ export class IndexingDiviner<
|
|
|
213
214
|
return undefined
|
|
214
215
|
}
|
|
215
216
|
|
|
216
|
-
protected override async startHandler()
|
|
217
|
+
protected override async startHandler() {
|
|
217
218
|
await super.startHandler()
|
|
218
219
|
this.poll()
|
|
219
|
-
return true
|
|
220
220
|
}
|
|
221
221
|
|
|
222
|
-
protected override async stopHandler(_timeout?: number | undefined)
|
|
223
|
-
if (this._pollId) {
|
|
222
|
+
protected override async stopHandler(_timeout?: number | undefined) {
|
|
223
|
+
if (isString(this._pollId)) {
|
|
224
224
|
clearTimeout(this._pollId)
|
|
225
225
|
this._pollId = undefined
|
|
226
226
|
}
|
|
227
|
-
|
|
227
|
+
await super.stopHandler()
|
|
228
228
|
}
|
|
229
229
|
|
|
230
230
|
/**
|