@xyo-network/diviner-stateful 3.6.0-rc.4 → 3.6.0-rc.5
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DivinerMixin.d.ts","sourceRoot":"","sources":["../../src/DivinerMixin.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACV,eAAe,EACf,cAAc,EACd,YAAY,EACZ,WAAW,EACX,eAAe,EAChB,MAAM,2BAA2B,CAAA;AAQlC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAExD,MAAM,MAAM,oBAAoB,GAAG,YAAY,CAAC,eAAe,CAAC,qBAAqB,CAAC,CAAC,CAAA;AAGvF,MAAM,MAAM,SAAS,CAAC,OAAO,SAAS,oBAAoB,GAAG,oBAAoB,IAAI,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,cAAc,CAAC,OAAO,CAAC,CAAA;AAIpI;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAC9B,OAAO,SAAS,oBAAoB;;;;;;;;;;;;;;;;;;;;;GACpC,OAAO,SAAS,SAAS,CAAC,OAAO,CAAC,uBAClC,MAAM,SAAS,eAAe,gCAElB,OAAO,6BAd8E,GAAG,EAAE;iBAiBvF,WAAW,CAAC,MAAM,CAAC;IAEhC;;;;;;OAMG;2BAC0B,WAAW,CAAC,MAAM,CAAC;IAUhD;;;;OAIG;;
|
|
1
|
+
{"version":3,"file":"DivinerMixin.d.ts","sourceRoot":"","sources":["../../src/DivinerMixin.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACV,eAAe,EACf,cAAc,EACd,YAAY,EACZ,WAAW,EACX,eAAe,EAChB,MAAM,2BAA2B,CAAA;AAQlC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAExD,MAAM,MAAM,oBAAoB,GAAG,YAAY,CAAC,eAAe,CAAC,qBAAqB,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IA/CnoC;;;OAGG;qBACoB,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;;;;;;;;;;sRAvFhD,CAAC,6DAAwB,CAAC;4RAKzC,CAAC,6DAAyB,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uBApBW,CAAC,yBACtC,CAAC;2FAMI,CAAC,yBACV,CAAC;;;;;;;;;;;;YAwIA,CAAA"}
|
package/dist/neutral/index.mjs
CHANGED
|
@@ -17,7 +17,7 @@ import { BoundWitnessDivinerQuerySchema } from "@xyo-network/diviner-boundwitnes
|
|
|
17
17
|
import { DivinerWrapper } from "@xyo-network/diviner-wrapper";
|
|
18
18
|
import { isModuleState, ModuleStateSchema } from "@xyo-network/module-model";
|
|
19
19
|
import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
20
|
-
import {
|
|
20
|
+
import { SequenceConstants } from "@xyo-network/payload-model";
|
|
21
21
|
var moduleName = "StatefulDiviner";
|
|
22
22
|
var StatefulDiviner = class extends AbstractDiviner {
|
|
23
23
|
static {
|
|
@@ -92,7 +92,7 @@ var StatefulDiviner = class extends AbstractDiviner {
|
|
|
92
92
|
}).fields({
|
|
93
93
|
address: this.account.address,
|
|
94
94
|
limit: 1,
|
|
95
|
-
cursor:
|
|
95
|
+
cursor: SequenceConstants.minLocalSequence,
|
|
96
96
|
order: "desc",
|
|
97
97
|
payload_schemas: [
|
|
98
98
|
ModuleStateSchema
|
|
@@ -132,7 +132,7 @@ import { BoundWitnessDivinerQuerySchema as BoundWitnessDivinerQuerySchema2 } fro
|
|
|
132
132
|
import { asDivinerInstance } from "@xyo-network/diviner-model";
|
|
133
133
|
import { isModuleState as isModuleState2, ModuleStateSchema as ModuleStateSchema2 } from "@xyo-network/module-model";
|
|
134
134
|
import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/payload-builder";
|
|
135
|
-
import {
|
|
135
|
+
import { SequenceConstants as SequenceConstants2 } from "@xyo-network/payload-model";
|
|
136
136
|
var moduleName2 = "StatefulModuleMixin";
|
|
137
137
|
var StatefulModuleMixin = /* @__PURE__ */ __name((ModuleBase) => {
|
|
138
138
|
let StatefulModuleBase = class StatefulModuleBase extends ModuleBase {
|
|
@@ -203,7 +203,7 @@ var StatefulModuleMixin = /* @__PURE__ */ __name((ModuleBase) => {
|
|
|
203
203
|
}).fields({
|
|
204
204
|
// address: this.account.address,
|
|
205
205
|
limit: 1,
|
|
206
|
-
cursor:
|
|
206
|
+
cursor: SequenceConstants2.minLocalSequence,
|
|
207
207
|
order: "desc",
|
|
208
208
|
payload_schemas: [
|
|
209
209
|
ModuleStateSchema2
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Schema.ts","../../src/Config.ts","../../src/Diviner.ts","../../src/DivinerMixin.ts"],"sourcesContent":["export const StatefulDivinerSchema = 'network.xyo.diviner.stateful' as const\nexport type StatefulDivinerSchema = typeof StatefulDivinerSchema\n","import type { DivinerConfig } from '@xyo-network/diviner-model'\nimport type { ModuleIdentifier } from '@xyo-network/module-model'\n\nimport { StatefulDivinerSchema } from './Schema.ts'\n\n/**\n * The schema for a Stateful Diviner config\n */\nexport const StatefulDivinerConfigSchema = `${StatefulDivinerSchema}.config` as const\n/**\n * The schema for a Stateful Diviner config\n */\nexport type StatefulDivinerConfigSchema = typeof StatefulDivinerConfigSchema\n\n/**\n * The config for a Stateful Diviner\n */\nexport type StatefulDivinerConfig = DivinerConfig<{\n schema: StatefulDivinerConfigSchema\n stateStore: {\n archivist: ModuleIdentifier\n boundWitnessDiviner: ModuleIdentifier\n payloadDiviner: ModuleIdentifier\n }\n}>\n","import { assertEx } from '@xylabs/assert'\nimport type { Hash } from '@xylabs/hex'\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 type { BoundWitnessDivinerQueryPayload } from '@xyo-network/diviner-boundwitness-model'\nimport { BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport type { DivinerInstance, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { DivinerWrapper } from '@xyo-network/diviner-wrapper'\nimport type { ModuleState, StateDictionary } from '@xyo-network/module-model'\nimport { isModuleState, ModuleStateSchema } from '@xyo-network/module-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport {\n type Payload, type Schema, StorageMetaConstants,\n type WithStorageMeta,\n} from '@xyo-network/payload-model'\n\nimport { StatefulDivinerConfigSchema } from './Config.ts'\nimport type { StatefulDivinerParams } from './Params.ts'\n\nconst moduleName = 'StatefulDiviner'\n\n/**\n * A Diviner that maintains state\n */\nexport abstract class StatefulDiviner<\n TParams extends StatefulDivinerParams = StatefulDivinerParams,\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 TState extends StateDictionary = StateDictionary,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, StatefulDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = StatefulDivinerConfigSchema\n\n /**\n * The last state\n */\n protected _lastState?: ModuleState<TState>\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<TState>) {\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.getArchivistForStateStore()\n const [bw] = await new BoundWitnessBuilder().payload(nextState).signer(this.account).build()\n await archivist.insert([bw, nextState])\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 getArchivistForStateStore() {\n const name = assertEx(this.config?.stateStore.archivist, () => `${moduleName}: Config for stateStore.archivist not specified`)\n const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve stateStore.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 getBoundWitnessDivinerForStateStore() {\n const name = assertEx(this.config?.stateStore.boundWitnessDiviner, () => `${moduleName}: Config for stateStore.boundWitnessDiviner not specified`)\n const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve stateStore.boundWitnessDiviner`)\n return DivinerWrapper.wrap(mod, this.account)\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 getPayloadDivinerForStateStore() {\n const name = assertEx(this.config?.stateStore?.payloadDiviner, () => `${moduleName}: Config for stateStore.payloadDiviner not specified`)\n const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve stateStore.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<TState> | undefined> {\n if (this._lastState) return this._lastState\n let hash: Hash = ''\n const diviner = await this.getBoundWitnessDivinerForStateStore()\n const query = await new PayloadBuilder<BoundWitnessDivinerQueryPayload>({ schema: BoundWitnessDivinerQuerySchema })\n .fields({\n address: this.account.address,\n limit: 1,\n cursor: StorageMetaConstants.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 === 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 '' 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.getArchivistForStateStore()\n const payload = (await archivist.get([hash])).find(isModuleState<TState>)\n if (payload) {\n return payload as WithStorageMeta<ModuleState<TState>>\n }\n }\n return undefined\n }\n}\n","import { assertEx } from '@xylabs/assert'\nimport type { Hash } from '@xylabs/hex'\nimport { asArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitnessBuilder } from '@xyo-network/boundwitness-builder'\nimport { isBoundWitness } from '@xyo-network/boundwitness-model'\nimport type { BoundWitnessDivinerQueryPayload } from '@xyo-network/diviner-boundwitness-model'\nimport { BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport { asDivinerInstance } from '@xyo-network/diviner-model'\nimport type {\n AnyConfigSchema,\n ModuleInstance,\n ModuleParams,\n ModuleState,\n StateDictionary,\n} from '@xyo-network/module-model'\nimport {\n isModuleState,\n ModuleStateSchema,\n} from '@xyo-network/module-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { StorageMetaConstants, type WithStorageMeta } from '@xyo-network/payload-model'\n\nimport type { StatefulDivinerConfig } from './Config.ts'\n\nexport type StatefulModuleParams = ModuleParams<AnyConfigSchema<StatefulDivinerConfig>>\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyModule<TParams extends StatefulModuleParams = StatefulModuleParams> = new (...args: any[]) => ModuleInstance<TParams>\n\nconst moduleName = 'StatefulModuleMixin'\n\n/**\n * @ignore Inherit from StatefulDiviner instead\n * @param ModuleBase\n * @returns\n */\nexport const StatefulModuleMixin = <\n TParams extends StatefulModuleParams = StatefulModuleParams,\n TModule extends AnyModule<TParams> = AnyModule<TParams>,\n TState extends StateDictionary = StateDictionary,\n>(\n ModuleBase: TModule,\n) => {\n abstract class StatefulModuleBase extends ModuleBase {\n _lastState?: ModuleState<TState>\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 async commitState(nextState: ModuleState<TState>) {\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()\n // const [bw] = await new BoundWitnessBuilder().payload(nextState).signer(this.account).build()\n const [bw] = await (await new BoundWitnessBuilder().payload(nextState)).build()\n await archivist.insert([bw, nextState])\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 async getArchivistForStore() {\n const name = assertEx(this.config?.stateStore?.archivist, () => `${moduleName}: Config for stateStore.archivist not specified`)\n const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve stateStore.archivist`)\n // return ArchivistWrapper.wrap(mod, this.account)\n const instance = asArchivistInstance(mod)\n return assertEx(instance, () => `${moduleName}: Failed to wrap archivist instance`)\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 async getBoundWitnessDivinerForStore() {\n const name = assertEx(\n this.config?.stateStore?.boundWitnessDiviner,\n () => `${moduleName}: Config for stateStore.boundWitnessDiviner not specified`,\n )\n const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve stateStore.boundWitnessDiviner`)\n // return DivinerWrapper.wrap(mod, this.account)\n const instance = asDivinerInstance(mod)\n return assertEx(instance, () => `${moduleName}: Failed to wrap diviner instance`)\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 async getPayloadDivinerForStateStore() {\n const name = assertEx(this.config?.stateStore?.payloadDiviner, () => `${moduleName}: Config for stateStore.payloadDiviner not specified`)\n const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve stateStore.payloadDiviner`)\n // return DivinerWrapper.wrap(mod, this.account)\n const instance = asDivinerInstance(mod)\n return assertEx(instance, () => `${moduleName}: Failed to wrap diviner instance`)\n }\n\n /**\n * Retrieves the last state of the Diviner process. Used to recover state after\n * preemptions, reboots, etc.\n */\n async retrieveState(): Promise<ModuleState<TState> | undefined> {\n if (this._lastState) return this._lastState\n let hash: Hash = ''\n const diviner = await this.getBoundWitnessDivinerForStore()\n const query = await new PayloadBuilder<BoundWitnessDivinerQueryPayload>({ schema: BoundWitnessDivinerQuerySchema })\n .fields({\n // address: this.account.address,\n limit: 1,\n cursor: StorageMetaConstants.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 === 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 '' 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()\n const payload = (await archivist.get([hash])).find(isModuleState<TState>)\n if (payload) {\n return payload as WithSt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,IAASE,MAChI,EAAA;QAEN;MACF;AAGA,UAAIxB,MAAM;AAER,cAAMrB,YAAY,MAAM,KAAKC,qBAAoB;AACjD,cAAMG,WAAW,MAAMJ,UAAUgD,IAAI;UAAC3B;SAAK,GAAG4B,KAAKC,cAAAA;AACnD,YAAI9C,SAAS;AACX,iBAAOA;QACT;MACF;AACA,aAAO+C;IACT;EACF;AACA,SAAOzD;AACT,GAnHmC;","names":["StatefulDivinerSchema","StatefulDivinerConfigSchema","StatefulDivinerSchema","assertEx","ArchivistWrapper","BoundWitnessBuilder","isBoundWitness","AbstractDiviner","BoundWitnessDivinerQuerySchema","DivinerWrapper","isModuleState","ModuleStateSchema","PayloadBuilder","StorageMetaConstants","moduleName","StatefulDiviner","AbstractDiviner","configSchemas","StatefulDivinerConfigSchema","defaultConfigSchema","_lastState","commitState","nextState","state","offset","archivist","getArchivistForStateStore","bw","BoundWitnessBuilder","payload","signer","account","build","insert","name","assertEx","config","stateStore","mod","resolve","ArchivistWrapper","wrap","getBoundWitnessDivinerForStateStore","boundWitnessDiviner","DivinerWrapper","getPayloadDivinerForStateStore","payloadDiviner","retrieveState","hash","diviner","query","PayloadBuilder","schema","BoundWitnessDivinerQuerySchema","fields","address","limit","cursor","StorageMetaConstants","minLocalSequence","order","payload_schemas","ModuleStateSchema","boundWitnesses","divine","length","boundWitness","isBoundWitness","addresses","map","index","filter","reduce","prev","curr","payload_hashes","get","find","isModuleState","undefined","assertEx","asArchivistInstance","BoundWitnessBuilder","isBoundWitness","BoundWitnessDivinerQuerySchema","asDivinerInstance","isModuleState","ModuleStateSchema","PayloadBuilder","StorageMetaConstants","moduleName","StatefulModuleMixin","ModuleBase","StatefulModuleBase","_lastState","commitState","nextState","state","offset","archivist","getArchivistForStore","bw","BoundWitnessBuilder","payload","build","insert","name","assertEx","config","stateStore","mod","resolve","instance","asArchivistInstance","getBoundWitnessDivinerForStore","boundWitnessDiviner","asDivinerInstance","getPayloadDivinerForStateStore","payloadDiviner","retrieveState","hash","diviner","query","PayloadBuilder","schema","BoundWitnessDivinerQuerySchema","fields","limit","cursor","StorageMetaConstants","minLocalSequence","order","payload_schemas","ModuleStateSchema","boundWitnesses","divine","length","boundWitness","isBoundWitness","addresses","map","address","index","reduce","prev","curr","payload_hashes","get","find","isModuleState","undefined"]}
|
|
1
|
+
{"version":3,"sources":["../../src/Schema.ts","../../src/Config.ts","../../src/Diviner.ts","../../src/DivinerMixin.ts"],"sourcesContent":["export const StatefulDivinerSchema = 'network.xyo.diviner.stateful' as const\nexport type StatefulDivinerSchema = typeof StatefulDivinerSchema\n","import type { DivinerConfig } from '@xyo-network/diviner-model'\nimport type { ModuleIdentifier } from '@xyo-network/module-model'\n\nimport { StatefulDivinerSchema } from './Schema.ts'\n\n/**\n * The schema for a Stateful Diviner config\n */\nexport const StatefulDivinerConfigSchema = `${StatefulDivinerSchema}.config` as const\n/**\n * The schema for a Stateful Diviner config\n */\nexport type StatefulDivinerConfigSchema = typeof StatefulDivinerConfigSchema\n\n/**\n * The config for a Stateful Diviner\n */\nexport type StatefulDivinerConfig = DivinerConfig<{\n schema: StatefulDivinerConfigSchema\n stateStore: {\n archivist: ModuleIdentifier\n boundWitnessDiviner: ModuleIdentifier\n payloadDiviner: ModuleIdentifier\n }\n}>\n","import { assertEx } from '@xylabs/assert'\nimport type { Hash } from '@xylabs/hex'\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 type { BoundWitnessDivinerQueryPayload } from '@xyo-network/diviner-boundwitness-model'\nimport { BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport type { DivinerInstance, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { DivinerWrapper } from '@xyo-network/diviner-wrapper'\nimport type { ModuleState, StateDictionary } from '@xyo-network/module-model'\nimport { isModuleState, ModuleStateSchema } from '@xyo-network/module-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport {\n type Payload, type Schema, SequenceConstants,\n type WithStorageMeta,\n} from '@xyo-network/payload-model'\n\nimport { StatefulDivinerConfigSchema } from './Config.ts'\nimport type { StatefulDivinerParams } from './Params.ts'\n\nconst moduleName = 'StatefulDiviner'\n\n/**\n * A Diviner that maintains state\n */\nexport abstract class StatefulDiviner<\n TParams extends StatefulDivinerParams = StatefulDivinerParams,\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 TState extends StateDictionary = StateDictionary,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, StatefulDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = StatefulDivinerConfigSchema\n\n /**\n * The last state\n */\n protected _lastState?: ModuleState<TState>\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<TState>) {\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.getArchivistForStateStore()\n const [bw] = await new BoundWitnessBuilder().payload(nextState).signer(this.account).build()\n await archivist.insert([bw, nextState])\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 getArchivistForStateStore() {\n const name = assertEx(this.config?.stateStore.archivist, () => `${moduleName}: Config for stateStore.archivist not specified`)\n const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve stateStore.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 getBoundWitnessDivinerForStateStore() {\n const name = assertEx(this.config?.stateStore.boundWitnessDiviner, () => `${moduleName}: Config for stateStore.boundWitnessDiviner not specified`)\n const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve stateStore.boundWitnessDiviner`)\n return DivinerWrapper.wrap(mod, this.account)\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 getPayloadDivinerForStateStore() {\n const name = assertEx(this.config?.stateStore?.payloadDiviner, () => `${moduleName}: Config for stateStore.payloadDiviner not specified`)\n const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve stateStore.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<TState> | undefined> {\n if (this._lastState) return this._lastState\n let hash: Hash = ''\n const diviner = await this.getBoundWitnessDivinerForStateStore()\n const query = await new PayloadBuilder<BoundWitnessDivinerQueryPayload>({ schema: BoundWitnessDivinerQuerySchema })\n .fields({\n address: this.account.address,\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 === 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 '' 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.getArchivistForStateStore()\n const payload = (await archivist.get([hash])).find(isModuleState<TState>)\n if (payload) {\n return payload as WithStorageMeta<ModuleState<TState>>\n }\n }\n return undefined\n }\n}\n","import { assertEx } from '@xylabs/assert'\nimport type { Hash } from '@xylabs/hex'\nimport { asArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitnessBuilder } from '@xyo-network/boundwitness-builder'\nimport { isBoundWitness } from '@xyo-network/boundwitness-model'\nimport type { BoundWitnessDivinerQueryPayload } from '@xyo-network/diviner-boundwitness-model'\nimport { BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport { asDivinerInstance } from '@xyo-network/diviner-model'\nimport type {\n AnyConfigSchema,\n ModuleInstance,\n ModuleParams,\n ModuleState,\n StateDictionary,\n} from '@xyo-network/module-model'\nimport {\n isModuleState,\n ModuleStateSchema,\n} from '@xyo-network/module-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { SequenceConstants, type WithStorageMeta } from '@xyo-network/payload-model'\n\nimport type { StatefulDivinerConfig } from './Config.ts'\n\nexport type StatefulModuleParams = ModuleParams<AnyConfigSchema<StatefulDivinerConfig>>\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyModule<TParams extends StatefulModuleParams = StatefulModuleParams> = new (...args: any[]) => ModuleInstance<TParams>\n\nconst moduleName = 'StatefulModuleMixin'\n\n/**\n * @ignore Inherit from StatefulDiviner instead\n * @param ModuleBase\n * @returns\n */\nexport const StatefulModuleMixin = <\n TParams extends StatefulModuleParams = StatefulModuleParams,\n TModule extends AnyModule<TParams> = AnyModule<TParams>,\n TState extends StateDictionary = StateDictionary,\n>(\n ModuleBase: TModule,\n) => {\n abstract class StatefulModuleBase extends ModuleBase {\n _lastState?: ModuleState<TState>\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 async commitState(nextState: ModuleState<TState>) {\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()\n // const [bw] = await new BoundWitnessBuilder().payload(nextState).signer(this.account).build()\n const [bw] = await (await new BoundWitnessBuilder().payload(nextState)).build()\n await archivist.insert([bw, nextState])\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 async getArchivistForStore() {\n const name = assertEx(this.config?.stateStore?.archivist, () => `${moduleName}: Config for stateStore.archivist not specified`)\n const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve stateStore.archivist`)\n // return ArchivistWrapper.wrap(mod, this.account)\n const instance = asArchivistInstance(mod)\n return assertEx(instance, () => `${moduleName}: Failed to wrap archivist instance`)\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 async getBoundWitnessDivinerForStore() {\n const name = assertEx(\n this.config?.stateStore?.boundWitnessDiviner,\n () => `${moduleName}: Config for stateStore.boundWitnessDiviner not specified`,\n )\n const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve stateStore.boundWitnessDiviner`)\n // return DivinerWrapper.wrap(mod, this.account)\n const instance = asDivinerInstance(mod)\n return assertEx(instance, () => `${moduleName}: Failed to wrap diviner instance`)\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 async getPayloadDivinerForStateStore() {\n const name = assertEx(this.config?.stateStore?.payloadDiviner, () => `${moduleName}: Config for stateStore.payloadDiviner not specified`)\n const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve stateStore.payloadDiviner`)\n // return DivinerWrapper.wrap(mod, this.account)\n const instance = asDivinerInstance(mod)\n return assertEx(instance, () => `${moduleName}: Failed to wrap diviner instance`)\n }\n\n /**\n * Retrieves the last state of the Diviner process. Used to recover state after\n * preemptions, reboots, etc.\n */\n async retrieveState(): Promise<ModuleState<TState> | undefined> {\n if (this._lastState) return this._lastState\n let hash: Hash = ''\n const diviner = await this.getBoundWitnessDivinerForStore()\n const query = await new PayloadBuilder<BoundWitnessDivinerQueryPayload>({ schema: BoundWitnessDivinerQuerySchema })\n .fields({\n // address: this.account.address,\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 === 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 '' 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()\n const payload = (await archivist.get([hash])).find(isModuleState<TState>)\n if (payload) {\n return payload as WithStorageMeta<ModuleState<TState>>\n }\n }\n return undefined\n }\n }\n return StatefulModuleBase\n}\n"],"mappings":";;;;AAAO,IAAMA,wBAAwB;;;ACQ9B,IAAMC,8BAA8B,GAAGC,qBAAAA;;;ACR9C,SAASC,gBAAgB;AAEzB,SAASC,wBAAwB;AACjC,SAASC,2BAA2B;AACpC,SAASC,sBAAsB;AAC/B,SAASC,uBAAuB;AAEhC,SAASC,sCAAsC;AAE/C,SAASC,sBAAsB;AAE/B,SAASC,eAAeC,yBAAyB;AACjD,SAASC,sBAAsB;AAC/B,SAC6BC,yBAEtB;AAKP,IAAMC,aAAa;AAKZ,IAAeC,kBAAf,cAUGC,gBAAAA;EApCV,OAoCUA;;;EACR,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeC;;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AAMsB,WAAWI,kBAAkBN,GAAAA;AACnC,aAAOH,UAASK,UAAU,MAAM,GAAGtB,WAAAA,mCAA6C;IAClF;;;;;IAMA,MAAM6B,gBAA0D;AAC9D,UAAI,KAAKzB,WAAY,QAAO,KAAKA;AACjC,UAAI0B,OAAa;AACjB,YAAMC,UAAU,MAAM,KAAKP,+BAA8B;AACzD,YAAMQ,QAAQ,MAAM,IAAIC,gBAAgD;QAAEC,QAAQC;MAA+B,CAAA,EAC9GC,OAAO;;QAENC,OAAO;QACPC,QAAQC,mBAAkBC;QAC1BC,OAAO;QACPC,iBAAiB;UAACC;;MACpB,CAAA,EACC7B,MAAK;AACR,YAAM8B,iBAAiB,MAAMb,QAAQc,OAAO;QAACb;OAAM;AACnD,UAAIY,eAAeE,SAAS,GAAG;AAC7B,cAAMC,eAAeH,eAAe,CAAA;AACpC,YAAII,gBAAeD,YAAAA,GAAe;AAEhCjB,iBAAOiB,aAAaE,UACjBC,IAAI,CAACC,SAASC,WAAW;YAAED;YAASC;UAAM,EAAA,EAG1CC,OACC,CAACC,MAAMC,SAAUR,aAAaL,kBAAkBa,MAAMH,KAAAA,MAAWT,qBAAoBI,aAAaS,eAAeD,MAAMH,KAAAA,IAASE,MAChI,EAAA;QAEN;MACF;AAGA,UAAIxB,MAAM;AAER,cAAMrB,YAAY,MAAM,KAAKC,qBAAoB;AACjD,cAAMG,WAAW,MAAMJ,UAAUgD,IAAI;UAAC3B;SAAK,GAAG4B,KAAKC,cAAAA;AACnD,YAAI9C,SAAS;AACX,iBAAOA;QACT;MACF;AACA,aAAO+C;IACT;EACF;AACA,SAAOzD;AACT,GAnHmC;","names":["StatefulDivinerSchema","StatefulDivinerConfigSchema","StatefulDivinerSchema","assertEx","ArchivistWrapper","BoundWitnessBuilder","isBoundWitness","AbstractDiviner","BoundWitnessDivinerQuerySchema","DivinerWrapper","isModuleState","ModuleStateSchema","PayloadBuilder","SequenceConstants","moduleName","StatefulDiviner","AbstractDiviner","configSchemas","StatefulDivinerConfigSchema","defaultConfigSchema","_lastState","commitState","nextState","state","offset","archivist","getArchivistForStateStore","bw","BoundWitnessBuilder","payload","signer","account","build","insert","name","assertEx","config","stateStore","mod","resolve","ArchivistWrapper","wrap","getBoundWitnessDivinerForStateStore","boundWitnessDiviner","DivinerWrapper","getPayloadDivinerForStateStore","payloadDiviner","retrieveState","hash","diviner","query","PayloadBuilder","schema","BoundWitnessDivinerQuerySchema","fields","address","limit","cursor","SequenceConstants","minLocalSequence","order","payload_schemas","ModuleStateSchema","boundWitnesses","divine","length","boundWitness","isBoundWitness","addresses","map","index","filter","reduce","prev","curr","payload_hashes","get","find","isModuleState","undefined","assertEx","asArchivistInstance","BoundWitnessBuilder","isBoundWitness","BoundWitnessDivinerQuerySchema","asDivinerInstance","isModuleState","ModuleStateSchema","PayloadBuilder","SequenceConstants","moduleName","StatefulModuleMixin","ModuleBase","StatefulModuleBase","_lastState","commitState","nextState","state","offset","archivist","getArchivistForStore","bw","BoundWitnessBuilder","payload","build","insert","name","assertEx","config","stateStore","mod","resolve","instance","asArchivistInstance","getBoundWitnessDivinerForStore","boundWitnessDiviner","asDivinerInstance","getPayloadDivinerForStateStore","payloadDiviner","retrieveState","hash","diviner","query","PayloadBuilder","schema","BoundWitnessDivinerQuerySchema","fields","limit","cursor","SequenceConstants","minLocalSequence","order","payload_schemas","ModuleStateSchema","boundWitnesses","divine","length","boundWitness","isBoundWitness","addresses","map","address","index","reduce","prev","curr","payload_hashes","get","find","isModuleState","undefined"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/diviner-stateful",
|
|
3
|
-
"version": "3.6.0-rc.
|
|
3
|
+
"version": "3.6.0-rc.5",
|
|
4
4
|
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
5
5
|
"homepage": "https://xyo.network",
|
|
6
6
|
"bugs": {
|
|
@@ -29,31 +29,31 @@
|
|
|
29
29
|
"module": "dist/neutral/index.mjs",
|
|
30
30
|
"types": "dist/neutral/index.d.ts",
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@xylabs/assert": "^4.4.
|
|
33
|
-
"@xylabs/hex": "^4.4.
|
|
34
|
-
"@xyo-network/archivist-model": "^3.6.0-rc.
|
|
35
|
-
"@xyo-network/archivist-wrapper": "^3.6.0-rc.
|
|
36
|
-
"@xyo-network/boundwitness-builder": "^3.6.0-rc.
|
|
37
|
-
"@xyo-network/boundwitness-model": "^3.6.0-rc.
|
|
38
|
-
"@xyo-network/diviner-abstract": "^3.6.0-rc.
|
|
39
|
-
"@xyo-network/diviner-boundwitness-model": "^3.6.0-rc.
|
|
40
|
-
"@xyo-network/diviner-model": "^3.6.0-rc.
|
|
41
|
-
"@xyo-network/diviner-wrapper": "^3.6.0-rc.
|
|
42
|
-
"@xyo-network/module-model": "^3.6.0-rc.
|
|
43
|
-
"@xyo-network/payload-builder": "^3.6.0-rc.
|
|
44
|
-
"@xyo-network/payload-model": "^3.6.0-rc.
|
|
32
|
+
"@xylabs/assert": "^4.4.14",
|
|
33
|
+
"@xylabs/hex": "^4.4.14",
|
|
34
|
+
"@xyo-network/archivist-model": "^3.6.0-rc.5",
|
|
35
|
+
"@xyo-network/archivist-wrapper": "^3.6.0-rc.5",
|
|
36
|
+
"@xyo-network/boundwitness-builder": "^3.6.0-rc.5",
|
|
37
|
+
"@xyo-network/boundwitness-model": "^3.6.0-rc.5",
|
|
38
|
+
"@xyo-network/diviner-abstract": "^3.6.0-rc.5",
|
|
39
|
+
"@xyo-network/diviner-boundwitness-model": "^3.6.0-rc.5",
|
|
40
|
+
"@xyo-network/diviner-model": "^3.6.0-rc.5",
|
|
41
|
+
"@xyo-network/diviner-wrapper": "^3.6.0-rc.5",
|
|
42
|
+
"@xyo-network/module-model": "^3.6.0-rc.5",
|
|
43
|
+
"@xyo-network/payload-builder": "^3.6.0-rc.5",
|
|
44
|
+
"@xyo-network/payload-model": "^3.6.0-rc.5"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@xylabs/ts-scripts-yarn3": "^4.2.4",
|
|
48
48
|
"@xylabs/tsconfig": "^4.2.4",
|
|
49
|
-
"@xylabs/vitest-extended": "^4.4.
|
|
50
|
-
"@xyo-network/account": "^3.6.0-rc.
|
|
51
|
-
"@xyo-network/archivist-memory": "^3.6.0-rc.
|
|
52
|
-
"@xyo-network/diviner-boundwitness-memory": "^3.6.0-rc.
|
|
53
|
-
"@xyo-network/diviner-payload-memory": "^3.6.0-rc.
|
|
54
|
-
"@xyo-network/manifest": "^3.6.0-rc.
|
|
55
|
-
"@xyo-network/module-factory-locator": "^3.6.0-rc.
|
|
56
|
-
"@xyo-network/node-memory": "^3.6.0-rc.
|
|
49
|
+
"@xylabs/vitest-extended": "^4.4.14",
|
|
50
|
+
"@xyo-network/account": "^3.6.0-rc.5",
|
|
51
|
+
"@xyo-network/archivist-memory": "^3.6.0-rc.5",
|
|
52
|
+
"@xyo-network/diviner-boundwitness-memory": "^3.6.0-rc.5",
|
|
53
|
+
"@xyo-network/diviner-payload-memory": "^3.6.0-rc.5",
|
|
54
|
+
"@xyo-network/manifest": "^3.6.0-rc.5",
|
|
55
|
+
"@xyo-network/module-factory-locator": "^3.6.0-rc.5",
|
|
56
|
+
"@xyo-network/node-memory": "^3.6.0-rc.5",
|
|
57
57
|
"typescript": "^5.7.2",
|
|
58
58
|
"vitest": "^2.1.8"
|
|
59
59
|
},
|
package/src/Diviner.ts
CHANGED
|
@@ -12,7 +12,7 @@ import type { ModuleState, StateDictionary } from '@xyo-network/module-model'
|
|
|
12
12
|
import { isModuleState, ModuleStateSchema } from '@xyo-network/module-model'
|
|
13
13
|
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
14
14
|
import {
|
|
15
|
-
type Payload, type Schema,
|
|
15
|
+
type Payload, type Schema, SequenceConstants,
|
|
16
16
|
type WithStorageMeta,
|
|
17
17
|
} from '@xyo-network/payload-model'
|
|
18
18
|
|
|
@@ -104,7 +104,7 @@ export abstract class StatefulDiviner<
|
|
|
104
104
|
.fields({
|
|
105
105
|
address: this.account.address,
|
|
106
106
|
limit: 1,
|
|
107
|
-
cursor:
|
|
107
|
+
cursor: SequenceConstants.minLocalSequence,
|
|
108
108
|
order: 'desc',
|
|
109
109
|
payload_schemas: [ModuleStateSchema],
|
|
110
110
|
})
|
package/src/DivinerMixin.ts
CHANGED
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
ModuleStateSchema,
|
|
19
19
|
} from '@xyo-network/module-model'
|
|
20
20
|
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
21
|
-
import {
|
|
21
|
+
import { SequenceConstants, type WithStorageMeta } from '@xyo-network/payload-model'
|
|
22
22
|
|
|
23
23
|
import type { StatefulDivinerConfig } from './Config.ts'
|
|
24
24
|
|
|
@@ -115,7 +115,7 @@ export const StatefulModuleMixin = <
|
|
|
115
115
|
.fields({
|
|
116
116
|
// address: this.account.address,
|
|
117
117
|
limit: 1,
|
|
118
|
-
cursor:
|
|
118
|
+
cursor: SequenceConstants.minLocalSequence,
|
|
119
119
|
order: 'desc',
|
|
120
120
|
payload_schemas: [ModuleStateSchema],
|
|
121
121
|
})
|