@xyo-network/diviner-stateful 2.107.1 → 2.107.4

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,"sources":["../../src/index.ts","../../src/Schema.ts","../../src/Config.ts","../../src/Diviner.ts","../../src/DivinerMixin.ts"],"sourcesContent":["export * from './Config'\nexport * from './Diviner'\nexport * from './DivinerMixin'\nexport * from './Params'\nexport * from './Schema'\n","export const StatefulDivinerSchema = 'network.xyo.diviner.stateful' as const\nexport type StatefulDivinerSchema = typeof StatefulDivinerSchema\n","import { DivinerConfig } from '@xyo-network/diviner-model'\nimport { ModuleIdentifier } from '@xyo-network/module-model'\n\nimport { StatefulDivinerSchema } from './Schema'\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 { 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 { BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport { DivinerInstance, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { DivinerWrapper } from '@xyo-network/diviner-wrapper'\nimport { isModuleState, ModuleState, ModuleStateSchema, StateDictionary } from '@xyo-network/module-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload, Schema, WithMeta } from '@xyo-network/payload-model'\n\nimport { StatefulDivinerConfigSchema } from './Config'\nimport { StatefulDivinerParams } from './Params'\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?: WithMeta<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: WithMeta<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<WithMeta<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 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 '' 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 WithMeta<ModuleState<TState>>\n }\n }\n return undefined\n }\n}\n","import { assertEx } from '@xylabs/assert'\nimport { 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 { BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport { asDivinerInstance } from '@xyo-network/diviner-model'\nimport {\n AnyConfigSchema,\n isModuleState,\n ModuleInstance,\n ModuleParams,\n ModuleState,\n ModuleStateSchema,\n StateDictionary,\n} from '@xyo-network/module-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { WithMeta } from '@xyo-network/payload-model'\n\nimport { StatefulDivinerConfig } from './Config'\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?: WithMeta<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: WithMeta<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 * 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 * Retrieves the last state of the Diviner process. Used to recover state after\n * preemptions, reboots, etc.\n */\n async retrieveState(): Promise<WithMeta<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 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 '' 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 WithMeta<ModuleState<TState>>\n }\n }\n return undefined\n }\n }\n return StatefulModuleBase\n}\n"],"mappings":"yqBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,EAAA,gCAAAC,EAAA,0BAAAC,EAAA,wBAAAC,IAAA,eAAAC,EAAAN,GCAO,IAAMO,EAAwB,+BCQ9B,IAAMC,EAA8B,GAAGC,CAAAA,UCR9C,IAAAC,EAAyB,0BAEzBC,EAAiC,0CACjCC,EAAoC,6CACpCC,EAA+B,2CAC/BC,EAAgC,yCAChCC,EAAgF,mDAEhFC,EAA+B,wCAC/BC,EAA+E,qCAC/EC,EAA+B,wCAM/B,IAAMC,EAAa,kBAKGC,EAAf,MAAeA,UAUZC,iBAAAA,CAOEC,WASV,MAAgBC,YAAYC,EAA0C,CA/CxE,IAAAC,EAiDI,GAAID,EAAUE,MAAMC,WAAWF,EAAA,KAAKH,aAAL,YAAAG,EAAiBC,MAAMC,QAAQ,OAC9D,KAAKL,WAAaE,EAClB,IAAMI,EAAY,MAA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B,KAAMH,YAAS,MAAM,KAAKI,QAAQL,CAAAA,EAAO,IAAM,GAAGlB,CAAAA,+CAAyD,EAE3GwB,KAAWI,qBAAkBN,CAAAA,EACnC,SAAOH,YAASK,EAAU,IAAM,GAAGxB,CAAAA,mCAA6C,CAClF,CAKA,MAAM+B,eAAoE,CACxE,GAAI,KAAK1B,WAAY,OAAO,KAAKA,WACjC,IAAI2B,EAAa,GACXC,EAAU,MAAM,KAAKP,+BAA8B,EACnDQ,EAAQ,MAAM,IAAIC,iBAAgD,CAAEC,OAAQC,gCAA+B,CAAA,EAC9GC,OAAO,CAENC,MAAO,EACP9B,OAAQ,EACR+B,MAAO,OACPC,gBAAiB,CAACC,oBACpB,CAAA,EACC3B,MAAK,EACF4B,EAAiB,MAAMV,EAAQW,OAAO,CAACV,EAAM,EACnD,GAAIS,EAAeE,OAAS,EAAG,CAC7B,IAAMC,EAAeH,EAAe,CAAA,KAChCI,kBAAeD,CAAAA,IAEjBd,EAAOc,EAAaE,UACjBC,IAAI,CAACC,EAASC,KAAW,CAAED,QAAAA,EAASC,MAAAA,CAAM,EAAA,EAG1CC,OACC,CAACC,EAAMC,IAAAA,CA/HrB,IAAAlD,EA+H+B0C,QAAAA,EAAAA,EAAaL,kBAAbK,YAAAA,EAA+BQ,GAAAA,YAAAA,EAAMH,UAAWT,oBAAoBI,EAAaS,eAAeD,GAAAA,YAAAA,EAAMH,KAAAA,EAASE,GAChI,EAAA,EAGR,CAGA,GAAIrB,EAAM,CAGR,IAAMlB,GAAW,MADC,MAAM,KAAKH,qBAAoB,GAChB6C,IAAI,CAACxB,EAAK,GAAGyB,KAAKC,eAAAA,EACnD,GAAI5C,EACF,OAAOA,CAEX,CAEF,CACF,EAxG0CX,EAAAA,EAAAA,sBAA1CC,CA0GF,EAjHmC","names":["src_exports","__export","StatefulDiviner","StatefulDivinerConfigSchema","StatefulDivinerSchema","StatefulModuleMixin","__toCommonJS","StatefulDivinerSchema","StatefulDivinerConfigSchema","StatefulDivinerSchema","import_assert","import_archivist_wrapper","import_boundwitness_builder","import_boundwitness_model","import_diviner_abstract","import_diviner_boundwitness_model","import_diviner_wrapper","import_module_model","import_payload_builder","moduleName","StatefulDiviner","AbstractDiviner","_lastState","commitState","nextState","_a","state","offset","archivist","getArchivistForStateStore","bw","BoundWitnessBuilder","payload","signer","account","build","insert","name","assertEx","config","stateStore","mod","resolve","ArchivistWrapper","wrap","getBoundWitnessDivinerForStateStore","boundWitnessDiviner","DivinerWrapper","getPayloadDivinerForStateStore","_b","payloadDiviner","retrieveState","hash","diviner","query","PayloadBuilder","schema","BoundWitnessDivinerQuerySchema","fields","address","limit","order","payload_schemas","ModuleStateSchema","boundWitnesses","divine","length","boundWitness","isBoundWitness","addresses","map","index","filter","reduce","prev","curr","payload_hashes","get","find","isModuleState","__publicField","configSchemas","__superGet","_StatefulDiviner","StatefulDivinerConfigSchema","defaultConfigSchema","import_assert","import_archivist_model","import_boundwitness_builder","import_boundwitness_model","import_diviner_boundwitness_model","import_diviner_model","import_module_model","import_payload_builder","moduleName","StatefulModuleMixin","__name","ModuleBase","_a","_lastState","commitState","nextState","state","offset","archivist","getArchivistForStore","bw","BoundWitnessBuilder","payload","build","insert","_b","name","assertEx","config","stateStore","mod","resolve","instance","asArchivistInstance","getBoundWitnessDivinerForStore","boundWitnessDiviner","asDivinerInstance","getPayloadDivinerForStateStore","payloadDiviner","retrieveState","hash","diviner","query","PayloadBuilder","schema","BoundWitnessDivinerQuerySchema","fields","limit","order","payload_schemas","ModuleStateSchema","boundWitnesses","divine","length","boundWitness","isBoundWitness","addresses","map","address","index","reduce","prev","curr","payload_hashes","get","find","isModuleState"]}
1
+ {"version":3,"sources":["../../src/index.ts","../../src/Schema.ts","../../src/Config.ts","../../src/Diviner.ts","../../src/DivinerMixin.ts"],"sourcesContent":["export * from './Config'\nexport * from './Diviner'\nexport * from './DivinerMixin'\nexport * from './Params'\nexport * from './Schema'\n","export const StatefulDivinerSchema = 'network.xyo.diviner.stateful' as const\nexport type StatefulDivinerSchema = typeof StatefulDivinerSchema\n","import { DivinerConfig } from '@xyo-network/diviner-model'\nimport { ModuleIdentifier } from '@xyo-network/module-model'\n\nimport { StatefulDivinerSchema } from './Schema'\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 { 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 { BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport { DivinerInstance, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { DivinerWrapper } from '@xyo-network/diviner-wrapper'\nimport { isModuleState, ModuleState, ModuleStateSchema, StateDictionary } from '@xyo-network/module-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload, Schema, WithMeta } from '@xyo-network/payload-model'\n\nimport { StatefulDivinerConfigSchema } from './Config'\nimport { StatefulDivinerParams } from './Params'\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?: WithMeta<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: WithMeta<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<WithMeta<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 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 '' 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 WithMeta<ModuleState<TState>>\n }\n }\n return undefined\n }\n}\n","import { assertEx } from '@xylabs/assert'\nimport { 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 { BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport { asDivinerInstance } from '@xyo-network/diviner-model'\nimport {\n AnyConfigSchema,\n isModuleState,\n ModuleInstance,\n ModuleParams,\n ModuleState,\n ModuleStateSchema,\n StateDictionary,\n} from '@xyo-network/module-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { WithMeta } from '@xyo-network/payload-model'\n\nimport { StatefulDivinerConfig } from './Config'\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?: WithMeta<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: WithMeta<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 * 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 * Retrieves the last state of the Diviner process. Used to recover state after\n * preemptions, reboots, etc.\n */\n async retrieveState(): Promise<WithMeta<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 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 '' 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 WithMeta<ModuleState<TState>>\n }\n }\n return undefined\n }\n }\n return StatefulModuleBase\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;ACAO,IAAMA,wBAAwB;;;ACQ9B,IAAMC,8BAA8B,GAAGC,qBAAAA;;;ACR9C,oBAAyB;AAEzB,+BAAiC;AACjC,kCAAoC;AACpC,gCAA+B;AAC/B,8BAAgC;AAChC,wCAAgF;AAEhF,6BAA+B;AAC/B,0BAA+E;AAC/E,6BAA+B;AAM/B,IAAMC,aAAa;AAKZ,IAAeC,mBAAf,MAAeA,yBAUZC,wCAAAA;;;;EAOEC;;;;;;;;EASV,MAAgBC,YAAYC,WAA0C;AA/CxE;AAiDI,QAAIA,UAAUC,MAAMC,aAAW,UAAKJ,eAAL,mBAAiBG,MAAMC,QAAQ;AAC9D,SAAKJ,aAAaE;AAClB,UAAMG,YAAY,MAAM,KAAKC,0BAAyB;AACtD,UAAM,CAACC,EAAAA,IAAM,MAAM,IAAIC,gDAAAA,EAAsBC,QAAQP,SAAAA,EAAWQ,OAAO,KAAKC,OAAO,EAAEC,MAAK;AAC1F,UAAMP,UAAUQ,OAAO;MAACN;MAAIL;KAAU;EACxC;;;;;;EAOA,MAAgBI,4BAA4B;AA7D9C;AA8DI,UAAMQ,WAAOC,yBAAS,UAAKC,WAAL,mBAAaC,WAAWZ,WAAW,MAAM,GAAGR,UAAAA,iDAA2D;AAC7H,UAAMqB,UAAMH,wBAAS,MAAM,KAAKI,QAAQL,IAAAA,GAAO,MAAM,GAAGjB,UAAAA,0CAAoD;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CAAA,EAC9GC,OAAO;;QAENC,OAAO;QACP7B,QAAQ;QACR8B,OAAO;QACPC,iBAAiB;UAACC;;MACpB,CAAA,EACC1B,MAAK;AACR,YAAM2B,iBAAiB,MAAMV,QAAQW,OAAO;QAACV;OAAM;AACnD,UAAIS,eAAeE,SAAS,GAAG;AAC7B,cAAMC,eAAeH,eAAe,CAAA;AACpC,gBAAII,2CAAeD,YAAAA,GAAe;AAEhCd,iBAAOc,aAAaE,UACjBC,IAAI,CAACC,SAASC,WAAW;YAAED;YAASC;UAAM,EAAA,EAG1CC,OACC,CAACC,MAAMC,SAAAA;AA/HrB,gBAAA9C;AA+H+BsC,qBAAAA,MAAAA,aAAaL,oBAAbK,gBAAAA,IAA+BQ,6BAAMH,YAAWT,yCAAoBI,aAAaS,eAAeD,6BAAMH,KAAAA,IAASE;aAChI,EAAA;QAEN;MACF;AAGA,UAAIrB,MAAM;AAER,cAAMrB,YAAY,MAAM,KAAKC,qBAAoB;AACjD,cAAMG,WAAW,MAAMJ,UAAU6C,IAAI;UAACxB;SAAK,GAAGyB,KAAKC,kCAAAA;AACnD,YAAI3C,SAAS;AACX,iBAAOA;QACT;MACF;AACA,aAAO4C;IACT;EACF,GAxG0CxD,kCAA1C;AAyGA,SAAOC;AACT,GAjHmC;","names":["StatefulDivinerSchema","StatefulDivinerConfigSchema","StatefulDivinerSchema","moduleName","StatefulDiviner","AbstractDiviner","_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","order","payload_schemas","ModuleStateSchema","boundWitnesses","divine","length","boundWitness","isBoundWitness","addresses","map","index","filter","reduce","prev","curr","payload_hashes","get","find","isModuleState","undefined","configSchemas","StatefulDivinerConfigSchema","defaultConfigSchema","import_assert","import_boundwitness_builder","import_boundwitness_model","import_diviner_boundwitness_model","import_module_model","import_payload_builder","moduleName","StatefulModuleMixin","ModuleBase","StatefulModuleBase","_lastState","commitState","nextState","_a","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","order","payload_schemas","ModuleStateSchema","boundWitnesses","divine","length","boundWitness","isBoundWitness","addresses","map","address","index","reduce","prev","curr","payload_hashes","get","find","isModuleState","undefined"]}
@@ -1,2 +1,258 @@
1
- var y=Object.defineProperty;var M=Object.getPrototypeOf;var _=Reflect.get;var A=(d,t,e)=>t in d?y(d,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):d[t]=e;var S=(d,t)=>y(d,"name",{value:t,configurable:!0});var u=(d,t,e)=>A(d,typeof t!="symbol"?t+"":t,e);var D=(d,t,e)=>_(M(d),e,t);var W="network.xyo.diviner.stateful";var w=`${W}.config`;import{assertEx as v}from"@xylabs/assert";import{ArchivistWrapper as C}from"@xyo-network/archivist-wrapper";import{BoundWitnessBuilder as P}from"@xyo-network/boundwitness-builder";import{isBoundWitness as q}from"@xyo-network/boundwitness-model";import{AbstractDiviner as E}from"@xyo-network/diviner-abstract";import{BoundWitnessDivinerQuerySchema as I}from"@xyo-network/diviner-boundwitness-model";import{DivinerWrapper as F}from"@xyo-network/diviner-wrapper";import{isModuleState as N,ModuleStateSchema as b}from"@xyo-network/module-model";import{PayloadBuilder as Q}from"@xyo-network/payload-builder";var p="StatefulDiviner",m=class m extends E{_lastState;async commitState(t){var i;if(t.state.offset===((i=this._lastState)==null?void 0:i.state.offset))return;this._lastState=t;let e=await this.getArchivistForStateStore(),[r]=await new P().payload(t).signer(this.account).build();await e.insert([r,t])}async getArchivistForStateStore(){var r;let t=v((r=this.config)==null?void 0:r.stateStore.archivist,()=>`${p}: Config for stateStore.archivist not specified`),e=v(await this.resolve(t),()=>`${p}: Failed to resolve stateStore.archivist`);return C.wrap(e,this.account)}async getBoundWitnessDivinerForStateStore(){var r;let t=v((r=this.config)==null?void 0:r.stateStore.boundWitnessDiviner,()=>`${p}: Config for stateStore.boundWitnessDiviner not specified`),e=v(await this.resolve(t),()=>`${p}: Failed to resolve stateStore.boundWitnessDiviner`);return F.wrap(e,this.account)}async getPayloadDivinerForStateStore(){var r,i;let t=v((i=(r=this.config)==null?void 0:r.stateStore)==null?void 0:i.payloadDiviner,()=>`${p}: Config for stateStore.payloadDiviner not specified`),e=v(await this.resolve(t),()=>`${p}: Failed to resolve stateStore.payloadDiviner`);return F.wrap(e,this.account)}async retrieveState(){if(this._lastState)return this._lastState;let t="",e=await this.getBoundWitnessDivinerForStateStore(),r=await new Q({schema:I}).fields({address:this.account.address,limit:1,offset:0,order:"desc",payload_schemas:[b]}).build(),i=await e.divine([r]);if(i.length>0){let n=i[0];q(n)&&(t=n.addresses.map((o,s)=>({address:o,index:s})).filter(({address:o})=>o===this.account.address).reduce((o,s)=>{var a;return((a=n.payload_schemas)==null?void 0:a[s==null?void 0:s.index])===b?n.payload_hashes[s==null?void 0:s.index]:o},""))}if(t){let o=(await(await this.getArchivistForStateStore()).get([t])).find(N);if(o)return o}}};S(m,"StatefulDiviner"),u(m,"configSchemas",[...D(m,m,"configSchemas"),w]),u(m,"defaultConfigSchema",w);var B=m;import{assertEx as c}from"@xylabs/assert";import{asArchivistInstance as k}from"@xyo-network/archivist-model";import{BoundWitnessBuilder as j}from"@xyo-network/boundwitness-builder";import{isBoundWitness as z}from"@xyo-network/boundwitness-model";import{BoundWitnessDivinerQuerySchema as G}from"@xyo-network/diviner-boundwitness-model";import{asDivinerInstance as $}from"@xyo-network/diviner-model";import{isModuleState as H,ModuleStateSchema as x}from"@xyo-network/module-model";import{PayloadBuilder as J}from"@xyo-network/payload-builder";var f="StatefulModuleMixin",vt=S(d=>{var e;return e=class extends d{_lastState;async commitState(i){var s;if(i.state.offset===((s=this._lastState)==null?void 0:s.state.offset))return;this._lastState=i;let n=await this.getArchivistForStore(),[o]=await(await new j().payload(i)).build();await n.insert([o,i])}async getArchivistForStore(){var s,a;let i=c((a=(s=this.config)==null?void 0:s.stateStore)==null?void 0:a.archivist,()=>`${f}: Config for stateStore.archivist not specified`),n=c(await this.resolve(i),()=>`${f}: Failed to resolve stateStore.archivist`),o=k(n);return c(o,()=>`${f}: Failed to wrap archivist instance`)}async getBoundWitnessDivinerForStore(){var s,a;let i=c((a=(s=this.config)==null?void 0:s.stateStore)==null?void 0:a.boundWitnessDiviner,()=>`${f}: Config for stateStore.boundWitnessDiviner not specified`),n=c(await this.resolve(i),()=>`${f}: Failed to resolve stateStore.boundWitnessDiviner`),o=$(n);return c(o,()=>`${f}: Failed to wrap diviner instance`)}async getPayloadDivinerForStateStore(){var s,a;let i=c((a=(s=this.config)==null?void 0:s.stateStore)==null?void 0:a.payloadDiviner,()=>`${f}: Config for stateStore.payloadDiviner not specified`),n=c(await this.resolve(i),()=>`${f}: Failed to resolve stateStore.payloadDiviner`),o=$(n);return c(o,()=>`${f}: Failed to wrap diviner instance`)}async retrieveState(){if(this._lastState)return this._lastState;let i="",n=await this.getBoundWitnessDivinerForStore(),o=await new J({schema:G}).fields({limit:1,offset:0,order:"desc",payload_schemas:[x]}).build(),s=await n.divine([o]);if(s.length>0){let a=s[0];z(a)&&(i=a.addresses.map((h,l)=>({address:h,index:l})).reduce((h,l)=>{var g;return((g=a.payload_schemas)==null?void 0:g[l==null?void 0:l.index])===x?a.payload_hashes[l==null?void 0:l.index]:h},""))}if(i){let h=(await(await this.getArchivistForStore()).get([i])).find(H);if(h)return h}}},S(e,"StatefulModuleBase"),e},"StatefulModuleMixin");export{B as StatefulDiviner,w as StatefulDivinerConfigSchema,W as StatefulDivinerSchema,vt as StatefulModuleMixin};
1
+ var __defProp = Object.defineProperty;
2
+ var __getProtoOf = Object.getPrototypeOf;
3
+ var __reflectGet = Reflect.get;
4
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
7
+ var __superGet = (cls, obj, key) => __reflectGet(__getProtoOf(cls), key, obj);
8
+
9
+ // src/Schema.ts
10
+ var StatefulDivinerSchema = "network.xyo.diviner.stateful";
11
+
12
+ // src/Config.ts
13
+ var StatefulDivinerConfigSchema = `${StatefulDivinerSchema}.config`;
14
+
15
+ // src/Diviner.ts
16
+ import { assertEx } from "@xylabs/assert";
17
+ import { ArchivistWrapper } from "@xyo-network/archivist-wrapper";
18
+ import { BoundWitnessBuilder } from "@xyo-network/boundwitness-builder";
19
+ import { isBoundWitness } from "@xyo-network/boundwitness-model";
20
+ import { AbstractDiviner } from "@xyo-network/diviner-abstract";
21
+ import { BoundWitnessDivinerQuerySchema } from "@xyo-network/diviner-boundwitness-model";
22
+ import { DivinerWrapper } from "@xyo-network/diviner-wrapper";
23
+ import { isModuleState, ModuleStateSchema } from "@xyo-network/module-model";
24
+ import { PayloadBuilder } from "@xyo-network/payload-builder";
25
+ var moduleName = "StatefulDiviner";
26
+ var _StatefulDiviner = class _StatefulDiviner extends AbstractDiviner {
27
+ /**
28
+ * The last state
29
+ */
30
+ _lastState;
31
+ /**
32
+ * Commit the internal state of the Diviner process. This is similar
33
+ * to a transaction completion in a database and should only be called
34
+ * when results have been successfully persisted to the appropriate
35
+ * external stores.
36
+ * @param nextState The state to commit
37
+ */
38
+ async commitState(nextState) {
39
+ var _a;
40
+ if (nextState.state.offset === ((_a = this._lastState) == null ? void 0 : _a.state.offset)) return;
41
+ this._lastState = nextState;
42
+ const archivist = await this.getArchivistForStateStore();
43
+ const [bw] = await new BoundWitnessBuilder().payload(nextState).signer(this.account).build();
44
+ await archivist.insert([
45
+ bw,
46
+ nextState
47
+ ]);
48
+ }
49
+ /**
50
+ * Retrieves the archivist for the specified store
51
+ * @param store The store to retrieve the archivist for
52
+ * @returns The archivist for the specified store
53
+ */
54
+ async getArchivistForStateStore() {
55
+ var _a;
56
+ const name = assertEx((_a = this.config) == null ? void 0 : _a.stateStore.archivist, () => `${moduleName}: Config for stateStore.archivist not specified`);
57
+ const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve stateStore.archivist`);
58
+ return ArchivistWrapper.wrap(mod, this.account);
59
+ }
60
+ /**
61
+ * Retrieves the BoundWitness Diviner for the specified store
62
+ * @param store The store to retrieve the BoundWitness Diviner for
63
+ * @returns The BoundWitness Diviner for the specified store
64
+ */
65
+ async getBoundWitnessDivinerForStateStore() {
66
+ var _a;
67
+ const name = assertEx((_a = this.config) == null ? void 0 : _a.stateStore.boundWitnessDiviner, () => `${moduleName}: Config for stateStore.boundWitnessDiviner not specified`);
68
+ const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve stateStore.boundWitnessDiviner`);
69
+ return DivinerWrapper.wrap(mod, this.account);
70
+ }
71
+ /**
72
+ * Retrieves the Payload Diviner for the specified store
73
+ * @param store The store to retrieve the Payload Diviner for
74
+ * @returns The Payload Diviner for the specified store
75
+ */
76
+ async getPayloadDivinerForStateStore() {
77
+ var _a, _b;
78
+ const name = assertEx((_b = (_a = this.config) == null ? void 0 : _a.stateStore) == null ? void 0 : _b.payloadDiviner, () => `${moduleName}: Config for stateStore.payloadDiviner not specified`);
79
+ const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve stateStore.payloadDiviner`);
80
+ return DivinerWrapper.wrap(mod, this.account);
81
+ }
82
+ /**
83
+ * Retrieves the last state of the Diviner process. Used to recover state after
84
+ * preemptions, reboots, etc.
85
+ */
86
+ async retrieveState() {
87
+ if (this._lastState) return this._lastState;
88
+ let hash = "";
89
+ const diviner = await this.getBoundWitnessDivinerForStateStore();
90
+ const query = await new PayloadBuilder({
91
+ schema: BoundWitnessDivinerQuerySchema
92
+ }).fields({
93
+ address: this.account.address,
94
+ limit: 1,
95
+ offset: 0,
96
+ order: "desc",
97
+ payload_schemas: [
98
+ ModuleStateSchema
99
+ ]
100
+ }).build();
101
+ const boundWitnesses = await diviner.divine([
102
+ query
103
+ ]);
104
+ if (boundWitnesses.length > 0) {
105
+ const boundWitness = boundWitnesses[0];
106
+ if (isBoundWitness(boundWitness)) {
107
+ hash = boundWitness.addresses.map((address, index) => ({
108
+ address,
109
+ index
110
+ })).filter(({ address }) => address === this.account.address).reduce((prev, curr) => {
111
+ var _a;
112
+ 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;
113
+ }, "");
114
+ }
115
+ }
116
+ if (hash) {
117
+ const archivist = await this.getArchivistForStateStore();
118
+ const payload = (await archivist.get([
119
+ hash
120
+ ])).find(isModuleState);
121
+ if (payload) {
122
+ return payload;
123
+ }
124
+ }
125
+ return void 0;
126
+ }
127
+ };
128
+ __name(_StatefulDiviner, "StatefulDiviner");
129
+ __publicField(_StatefulDiviner, "configSchemas", [
130
+ ...__superGet(_StatefulDiviner, _StatefulDiviner, "configSchemas"),
131
+ StatefulDivinerConfigSchema
132
+ ]);
133
+ __publicField(_StatefulDiviner, "defaultConfigSchema", StatefulDivinerConfigSchema);
134
+ var StatefulDiviner = _StatefulDiviner;
135
+
136
+ // src/DivinerMixin.ts
137
+ import { assertEx as assertEx2 } from "@xylabs/assert";
138
+ import { asArchivistInstance } from "@xyo-network/archivist-model";
139
+ import { BoundWitnessBuilder as BoundWitnessBuilder2 } from "@xyo-network/boundwitness-builder";
140
+ import { isBoundWitness as isBoundWitness2 } from "@xyo-network/boundwitness-model";
141
+ import { BoundWitnessDivinerQuerySchema as BoundWitnessDivinerQuerySchema2 } from "@xyo-network/diviner-boundwitness-model";
142
+ import { asDivinerInstance } from "@xyo-network/diviner-model";
143
+ import { isModuleState as isModuleState2, ModuleStateSchema as ModuleStateSchema2 } from "@xyo-network/module-model";
144
+ import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/payload-builder";
145
+ var moduleName2 = "StatefulModuleMixin";
146
+ var StatefulModuleMixin = /* @__PURE__ */ __name((ModuleBase) => {
147
+ var _a;
148
+ let StatefulModuleBase = (_a = class extends ModuleBase {
149
+ _lastState;
150
+ /**
151
+ * Commit the internal state of the Diviner process. This is similar
152
+ * to a transaction completion in a database and should only be called
153
+ * when results have been successfully persisted to the appropriate
154
+ * external stores.
155
+ * @param nextState The state to commit
156
+ */
157
+ async commitState(nextState) {
158
+ var _a2;
159
+ if (nextState.state.offset === ((_a2 = this._lastState) == null ? void 0 : _a2.state.offset)) return;
160
+ this._lastState = nextState;
161
+ const archivist = await this.getArchivistForStore();
162
+ const [bw] = await (await new BoundWitnessBuilder2().payload(nextState)).build();
163
+ await archivist.insert([
164
+ bw,
165
+ nextState
166
+ ]);
167
+ }
168
+ /**
169
+ * Retrieves the archivist for the specified store
170
+ * @param store The store to retrieve the archivist for
171
+ * @returns The archivist for the specified store
172
+ */
173
+ async getArchivistForStore() {
174
+ var _a2, _b;
175
+ const name = assertEx2((_b = (_a2 = this.config) == null ? void 0 : _a2.stateStore) == null ? void 0 : _b.archivist, () => `${moduleName2}: Config for stateStore.archivist not specified`);
176
+ const mod = assertEx2(await this.resolve(name), () => `${moduleName2}: Failed to resolve stateStore.archivist`);
177
+ const instance = asArchivistInstance(mod);
178
+ return assertEx2(instance, () => `${moduleName2}: Failed to wrap archivist instance`);
179
+ }
180
+ /**
181
+ * Retrieves the BoundWitness Diviner for the specified store
182
+ * @param store The store to retrieve the BoundWitness Diviner for
183
+ * @returns The BoundWitness Diviner for the specified store
184
+ */
185
+ async getBoundWitnessDivinerForStore() {
186
+ var _a2, _b;
187
+ const name = assertEx2((_b = (_a2 = this.config) == null ? void 0 : _a2.stateStore) == null ? void 0 : _b.boundWitnessDiviner, () => `${moduleName2}: Config for stateStore.boundWitnessDiviner not specified`);
188
+ const mod = assertEx2(await this.resolve(name), () => `${moduleName2}: Failed to resolve stateStore.boundWitnessDiviner`);
189
+ const instance = asDivinerInstance(mod);
190
+ return assertEx2(instance, () => `${moduleName2}: Failed to wrap diviner instance`);
191
+ }
192
+ /**
193
+ * Retrieves the Payload Diviner for the specified store
194
+ * @param store The store to retrieve the Payload Diviner for
195
+ * @returns The Payload Diviner for the specified store
196
+ */
197
+ async getPayloadDivinerForStateStore() {
198
+ var _a2, _b;
199
+ const name = assertEx2((_b = (_a2 = this.config) == null ? void 0 : _a2.stateStore) == null ? void 0 : _b.payloadDiviner, () => `${moduleName2}: Config for stateStore.payloadDiviner not specified`);
200
+ const mod = assertEx2(await this.resolve(name), () => `${moduleName2}: Failed to resolve stateStore.payloadDiviner`);
201
+ const instance = asDivinerInstance(mod);
202
+ return assertEx2(instance, () => `${moduleName2}: Failed to wrap diviner instance`);
203
+ }
204
+ /**
205
+ * Retrieves the last state of the Diviner process. Used to recover state after
206
+ * preemptions, reboots, etc.
207
+ */
208
+ async retrieveState() {
209
+ if (this._lastState) return this._lastState;
210
+ let hash = "";
211
+ const diviner = await this.getBoundWitnessDivinerForStore();
212
+ const query = await new PayloadBuilder2({
213
+ schema: BoundWitnessDivinerQuerySchema2
214
+ }).fields({
215
+ // address: this.account.address,
216
+ limit: 1,
217
+ offset: 0,
218
+ order: "desc",
219
+ payload_schemas: [
220
+ ModuleStateSchema2
221
+ ]
222
+ }).build();
223
+ const boundWitnesses = await diviner.divine([
224
+ query
225
+ ]);
226
+ if (boundWitnesses.length > 0) {
227
+ const boundWitness = boundWitnesses[0];
228
+ if (isBoundWitness2(boundWitness)) {
229
+ hash = boundWitness.addresses.map((address, index) => ({
230
+ address,
231
+ index
232
+ })).reduce((prev, curr) => {
233
+ var _a2;
234
+ return ((_a2 = boundWitness.payload_schemas) == null ? void 0 : _a2[curr == null ? void 0 : curr.index]) === ModuleStateSchema2 ? boundWitness.payload_hashes[curr == null ? void 0 : curr.index] : prev;
235
+ }, "");
236
+ }
237
+ }
238
+ if (hash) {
239
+ const archivist = await this.getArchivistForStore();
240
+ const payload = (await archivist.get([
241
+ hash
242
+ ])).find(isModuleState2);
243
+ if (payload) {
244
+ return payload;
245
+ }
246
+ }
247
+ return void 0;
248
+ }
249
+ }, __name(_a, "StatefulModuleBase"), _a);
250
+ return StatefulModuleBase;
251
+ }, "StatefulModuleMixin");
252
+ export {
253
+ StatefulDiviner,
254
+ StatefulDivinerConfigSchema,
255
+ StatefulDivinerSchema,
256
+ StatefulModuleMixin
257
+ };
2
258
  //# sourceMappingURL=index.js.map
@@ -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 { DivinerConfig } from '@xyo-network/diviner-model'\nimport { ModuleIdentifier } from '@xyo-network/module-model'\n\nimport { StatefulDivinerSchema } from './Schema'\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 { 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 { BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport { DivinerInstance, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { DivinerWrapper } from '@xyo-network/diviner-wrapper'\nimport { isModuleState, ModuleState, ModuleStateSchema, StateDictionary } from '@xyo-network/module-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload, Schema, WithMeta } from '@xyo-network/payload-model'\n\nimport { StatefulDivinerConfigSchema } from './Config'\nimport { StatefulDivinerParams } from './Params'\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?: WithMeta<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: WithMeta<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<WithMeta<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 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 '' 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 WithMeta<ModuleState<TState>>\n }\n }\n return undefined\n }\n}\n","import { assertEx } from '@xylabs/assert'\nimport { 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 { BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport { asDivinerInstance } from '@xyo-network/diviner-model'\nimport {\n AnyConfigSchema,\n isModuleState,\n ModuleInstance,\n ModuleParams,\n ModuleState,\n ModuleStateSchema,\n StateDictionary,\n} from '@xyo-network/module-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { WithMeta } from '@xyo-network/payload-model'\n\nimport { StatefulDivinerConfig } from './Config'\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?: WithMeta<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: WithMeta<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 * 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 * Retrieves the last state of the Diviner process. Used to recover state after\n * preemptions, reboots, etc.\n */\n async retrieveState(): Promise<WithMeta<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 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 '' 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 WithMeta<ModuleState<TState>>\n }\n }\n return undefined\n }\n }\n return StatefulModuleBase\n}\n"],"mappings":"gSAAO,IAAMA,EAAwB,+BCQ9B,IAAMC,EAA8B,GAAGC,CAAAA,UCR9C,OAASC,YAAAA,MAAgB,iBAEzB,OAASC,oBAAAA,MAAwB,iCACjC,OAASC,uBAAAA,MAA2B,oCACpC,OAASC,kBAAAA,MAAsB,kCAC/B,OAASC,mBAAAA,MAAuB,gCAChC,OAA0CC,kCAAAA,MAAsC,0CAEhF,OAASC,kBAAAA,MAAsB,+BAC/B,OAASC,iBAAAA,EAA4BC,qBAAAA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,EAAMH,KAAAA,EAASE,GAChI,EAAA,EAGR,CAGA,GAAIrB,EAAM,CAGR,IAAMlB,GAAW,MADC,MAAM,KAAKH,qBAAoB,GAChB6C,IAAI,CAACxB,EAAK,GAAGyB,KAAKC,CAAAA,EACnD,GAAI5C,EACF,OAAOA,CAEX,CAEF,CACF,EAxG0CX,EAAAA,EAAAA,sBAA1CC,CA0GF,EAjHmC","names":["StatefulDivinerSchema","StatefulDivinerConfigSchema","StatefulDivinerSchema","assertEx","ArchivistWrapper","BoundWitnessBuilder","isBoundWitness","AbstractDiviner","BoundWitnessDivinerQuerySchema","DivinerWrapper","isModuleState","ModuleStateSchema","PayloadBuilder","moduleName","StatefulDiviner","AbstractDiviner","_lastState","commitState","nextState","_a","state","offset","archivist","getArchivistForStateStore","bw","BoundWitnessBuilder","payload","signer","account","build","insert","name","assertEx","config","stateStore","mod","resolve","ArchivistWrapper","wrap","getBoundWitnessDivinerForStateStore","boundWitnessDiviner","DivinerWrapper","getPayloadDivinerForStateStore","_b","payloadDiviner","retrieveState","hash","diviner","query","PayloadBuilder","schema","BoundWitnessDivinerQuerySchema","fields","address","limit","order","payload_schemas","ModuleStateSchema","boundWitnesses","divine","length","boundWitness","isBoundWitness","addresses","map","index","filter","reduce","prev","curr","payload_hashes","get","find","isModuleState","__publicField","configSchemas","__superGet","_StatefulDiviner","StatefulDivinerConfigSchema","defaultConfigSchema","assertEx","asArchivistInstance","BoundWitnessBuilder","isBoundWitness","BoundWitnessDivinerQuerySchema","asDivinerInstance","isModuleState","ModuleStateSchema","PayloadBuilder","moduleName","StatefulModuleMixin","__name","ModuleBase","_a","_lastState","commitState","nextState","state","offset","archivist","getArchivistForStore","bw","BoundWitnessBuilder","payload","build","insert","_b","name","assertEx","config","stateStore","mod","resolve","instance","asArchivistInstance","getBoundWitnessDivinerForStore","boundWitnessDiviner","asDivinerInstance","getPayloadDivinerForStateStore","payloadDiviner","retrieveState","hash","diviner","query","PayloadBuilder","schema","BoundWitnessDivinerQuerySchema","fields","limit","order","payload_schemas","ModuleStateSchema","boundWitnesses","divine","length","boundWitness","isBoundWitness","addresses","map","address","index","reduce","prev","curr","payload_hashes","get","find","isModuleState"]}
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 { DivinerConfig } from '@xyo-network/diviner-model'\nimport { ModuleIdentifier } from '@xyo-network/module-model'\n\nimport { StatefulDivinerSchema } from './Schema'\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 { 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 { BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport { DivinerInstance, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { DivinerWrapper } from '@xyo-network/diviner-wrapper'\nimport { isModuleState, ModuleState, ModuleStateSchema, StateDictionary } from '@xyo-network/module-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload, Schema, WithMeta } from '@xyo-network/payload-model'\n\nimport { StatefulDivinerConfigSchema } from './Config'\nimport { StatefulDivinerParams } from './Params'\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?: WithMeta<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: WithMeta<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<WithMeta<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 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 '' 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 WithMeta<ModuleState<TState>>\n }\n }\n return undefined\n }\n}\n","import { assertEx } from '@xylabs/assert'\nimport { 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 { BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport { asDivinerInstance } from '@xyo-network/diviner-model'\nimport {\n AnyConfigSchema,\n isModuleState,\n ModuleInstance,\n ModuleParams,\n ModuleState,\n ModuleStateSchema,\n StateDictionary,\n} from '@xyo-network/module-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { WithMeta } from '@xyo-network/payload-model'\n\nimport { StatefulDivinerConfig } from './Config'\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?: WithMeta<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: WithMeta<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 * 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 * Retrieves the last state of the Diviner process. Used to recover state after\n * preemptions, reboots, etc.\n */\n async retrieveState(): Promise<WithMeta<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 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 '' 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 WithMeta<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;AAChC,SAA0CC,sCAAsC;AAEhF,SAASC,sBAAsB;AAC/B,SAASC,eAA4BC,yBAA0C;AAC/E,SAASC,sBAAsB;AAM/B,IAAMC,aAAa;AAKZ,IAAeC,mBAAf,MAAeA,yBAUZC,gBAAAA;;;;EAOEC;;;;;;;;EASV,MAAgBC,YAAYC,WAA0C;AA/CxE;AAiDI,QAAIA,UAAUC,MAAMC,aAAW,UAAKJ,eAAL,mBAAiBG,MAAMC,QAAQ;AAC9D,SAAKJ,aAAaE;AAClB,UAAMG,YAAY,MAAM,KAAKC,0BAAyB;AACtD,UAAM,CAACC,EAAAA,IAAM,MAAM,IAAIC,oBAAAA,EAAsBC,QAAQP,SAAAA,EAAWQ,OAAO,KAAKC,OAAO,EAAEC,MAAK;AAC1F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AM,GAAGjB,WAAAA,+CAAyD;AAEjH,YAAMuB,WAAWI,kBAAkBN,GAAAA;AACnC,aAAOH,UAASK,UAAU,MAAM,GAAGvB,WAAAA,mCAA6C;IAClF;;;;;IAKA,MAAM8B,gBAAoE;AACxE,UAAI,KAAK1B,WAAY,QAAO,KAAKA;AACjC,UAAI2B,OAAa;AACjB,YAAMC,UAAU,MAAM,KAAKP,+BAA8B;AACzD,YAAMQ,QAAQ,MAAM,IAAIC,gBAAgD;QAAEC,QAAQC;MAA+B,CAAA,EAC9GC,OAAO;;QAENC,OAAO;QACP7B,QAAQ;QACR8B,OAAO;QACPC,iBAAiB;UAACC;;MACpB,CAAA,EACC1B,MAAK;AACR,YAAM2B,iBAAiB,MAAMV,QAAQW,OAAO;QAACV;OAAM;AACnD,UAAIS,eAAeE,SAAS,GAAG;AAC7B,cAAMC,eAAeH,eAAe,CAAA;AACpC,YAAII,gBAAeD,YAAAA,GAAe;AAEhCd,iBAAOc,aAAaE,UACjBC,IAAI,CAACC,SAASC,WAAW;YAAED;YAASC;UAAM,EAAA,EAG1CC,OACC,CAACC,MAAMC,SAAAA;AA/HrB,gBAAA9C;AA+H+BsC,qBAAAA,MAAAA,aAAaL,oBAAbK,gBAAAA,IAA+BQ,6BAAMH,YAAWT,qBAAoBI,aAAaS,eAAeD,6BAAMH,KAAAA,IAASE;aAChI,EAAA;QAEN;MACF;AAGA,UAAIrB,MAAM;AAER,cAAMrB,YAAY,MAAM,KAAKC,qBAAoB;AACjD,cAAMG,WAAW,MAAMJ,UAAU6C,IAAI;UAACxB;SAAK,GAAGyB,KAAKC,cAAAA;AACnD,YAAI3C,SAAS;AACX,iBAAOA;QACT;MACF;AACA,aAAO4C;IACT;EACF,GAxG0CxD,kCAA1C;AAyGA,SAAOC;AACT,GAjHmC;","names":["StatefulDivinerSchema","StatefulDivinerConfigSchema","StatefulDivinerSchema","assertEx","ArchivistWrapper","BoundWitnessBuilder","isBoundWitness","AbstractDiviner","BoundWitnessDivinerQuerySchema","DivinerWrapper","isModuleState","ModuleStateSchema","PayloadBuilder","moduleName","StatefulDiviner","AbstractDiviner","_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","order","payload_schemas","ModuleStateSchema","boundWitnesses","divine","length","boundWitness","isBoundWitness","addresses","map","index","filter","reduce","prev","curr","payload_hashes","get","find","isModuleState","undefined","configSchemas","StatefulDivinerConfigSchema","defaultConfigSchema","assertEx","asArchivistInstance","BoundWitnessBuilder","isBoundWitness","BoundWitnessDivinerQuerySchema","asDivinerInstance","isModuleState","ModuleStateSchema","PayloadBuilder","moduleName","StatefulModuleMixin","ModuleBase","StatefulModuleBase","_lastState","commitState","nextState","_a","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","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
@@ -12,28 +12,28 @@
12
12
  "dependencies": {
13
13
  "@xylabs/assert": "^3.5.1",
14
14
  "@xylabs/hex": "^3.5.1",
15
- "@xyo-network/archivist-model": "~2.107.1",
16
- "@xyo-network/archivist-wrapper": "~2.107.1",
17
- "@xyo-network/boundwitness-builder": "~2.107.1",
18
- "@xyo-network/boundwitness-model": "~2.107.1",
19
- "@xyo-network/diviner-abstract": "~2.107.1",
20
- "@xyo-network/diviner-boundwitness-model": "~2.107.1",
21
- "@xyo-network/diviner-model": "~2.107.1",
22
- "@xyo-network/diviner-wrapper": "~2.107.1",
23
- "@xyo-network/module-model": "~2.107.1",
24
- "@xyo-network/payload-builder": "~2.107.1",
25
- "@xyo-network/payload-model": "~2.107.1"
15
+ "@xyo-network/archivist-model": "~2.107.4",
16
+ "@xyo-network/archivist-wrapper": "~2.107.4",
17
+ "@xyo-network/boundwitness-builder": "~2.107.4",
18
+ "@xyo-network/boundwitness-model": "~2.107.4",
19
+ "@xyo-network/diviner-abstract": "~2.107.4",
20
+ "@xyo-network/diviner-boundwitness-model": "~2.107.4",
21
+ "@xyo-network/diviner-model": "~2.107.4",
22
+ "@xyo-network/diviner-wrapper": "~2.107.4",
23
+ "@xyo-network/module-model": "~2.107.4",
24
+ "@xyo-network/payload-builder": "~2.107.4",
25
+ "@xyo-network/payload-model": "~2.107.4"
26
26
  },
27
27
  "devDependencies": {
28
- "@xylabs/ts-scripts-yarn3": "^3.11.9",
29
- "@xylabs/tsconfig": "^3.11.9",
30
- "@xyo-network/account": "~2.107.1",
31
- "@xyo-network/archivist-memory": "~2.107.1",
32
- "@xyo-network/diviner-boundwitness-memory": "~2.107.1",
33
- "@xyo-network/diviner-payload-memory": "~2.107.1",
34
- "@xyo-network/manifest": "~2.107.1",
35
- "@xyo-network/module-factory-locator": "~2.107.1",
36
- "@xyo-network/node-memory": "~2.107.1",
28
+ "@xylabs/ts-scripts-yarn3": "^3.11.10",
29
+ "@xylabs/tsconfig": "^3.11.10",
30
+ "@xyo-network/account": "~2.107.4",
31
+ "@xyo-network/archivist-memory": "~2.107.4",
32
+ "@xyo-network/diviner-boundwitness-memory": "~2.107.4",
33
+ "@xyo-network/diviner-payload-memory": "~2.107.4",
34
+ "@xyo-network/manifest": "~2.107.4",
35
+ "@xyo-network/module-factory-locator": "~2.107.4",
36
+ "@xyo-network/node-memory": "~2.107.4",
37
37
  "typescript": "^5.5.2"
38
38
  },
39
39
  "description": "Primary SDK for using XYO Protocol 2.0",
@@ -75,6 +75,6 @@
75
75
  "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
76
76
  },
77
77
  "sideEffects": false,
78
- "version": "2.107.1",
78
+ "version": "2.107.4",
79
79
  "type": "module"
80
80
  }