@xyo-network/diviner-stateful 5.2.18 → 5.2.19

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":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AAGjE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAG/D,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;AACzF,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAC7D,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAG7E,OAAO,KAAK,EACV,OAAO,EAAE,MAAM,EAEhB,MAAM,4BAA4B,CAAA;AAInC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAIxD;;GAEG;AACH,8BAAsB,eAAe,CACnC,OAAO,SAAS,qBAAqB,GAAG,qBAAqB,EAC7D,GAAG,SAAS,OAAO,GAAG,OAAO,EAC7B,IAAI,SAAS,OAAO,GAAG,OAAO,EAC9B,UAAU,SAAS,sBAAsB,CAAC,eAAe,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,sBAAsB,CAChH,eAAe,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,EACnC,GAAG,EACH,IAAI,CACL,EACD,MAAM,SAAS,eAAe,GAAG,eAAe,CAChD,SAAQ,eAAe,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,CAAC;IACvD,gBAAyB,aAAa,EAAE,MAAM,EAAE,CAAwD;IACxG,gBAAyB,mBAAmB,EAAE,MAAM,CAA8B;IAElF;;OAEG;IACH,SAAS,CAAC,UAAU,CAAC,EAAE,WA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EAAE,UAAU,CAAC;IACvD,gBAAyB,aAAa,EAAE,MAAM,EAAE,CAAwD;IACxG,gBAAyB,mBAAmB,EAAE,MAAM,CAA8B;IAElF;;OAEG;IACH,SAAS,CAAC,UAAU,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;IAE1C;;;;;;OAMG;cACa,WAAW,CAAC,SAAS,EAAE,WAAW,CAAC,MAAM,CAAC;IAS1D;;;;OAIG;cACa,yBAAyB;IAMzC;;;;OAIG;cACa,mCAAmC;IAMnD;;;;OAIG;cACa,8BAA8B;IAM9C;;;OAGG;cACa,aAAa,IAAI,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;CAwC1E"}
@@ -1 +1 @@
1
- {"version":3,"file":"DivinerMixin.d.ts","sourceRoot":"","sources":["../../src/DivinerMixin.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,eAAe,EACf,cAAc,EACd,YAAY,EAGb,MAAM,2BAA2B,CAAA;AASlC,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"}
1
+ {"version":3,"file":"DivinerMixin.d.ts","sourceRoot":"","sources":["../../src/DivinerMixin.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACV,eAAe,EACf,cAAc,EACd,YAAY,EAGb,MAAM,2BAA2B,CAAA;AASlC,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"}
@@ -5,8 +5,7 @@ var StatefulDivinerSchema = "network.xyo.diviner.stateful";
5
5
  var StatefulDivinerConfigSchema = `${StatefulDivinerSchema}.config`;
6
6
 
7
7
  // src/Diviner.ts
8
- import { assertEx } from "@xylabs/assert";
9
- import { toSafeJson } from "@xylabs/object";
8
+ import { assertEx, toSafeJson } from "@xylabs/sdk-js";
10
9
  import { ArchivistWrapper } from "@xyo-network/archivist-wrapper";
11
10
  import { BoundWitnessBuilder } from "@xyo-network/boundwitness-builder";
12
11
  import { isBoundWitness } from "@xyo-network/boundwitness-model";
@@ -105,8 +104,7 @@ var StatefulDiviner = class extends AbstractDiviner {
105
104
  };
106
105
 
107
106
  // src/DivinerMixin.ts
108
- import { assertEx as assertEx2 } from "@xylabs/assert";
109
- import { toSafeJson as toSafeJson2 } from "@xylabs/object";
107
+ import { assertEx as assertEx2, toSafeJson as toSafeJson2 } from "@xylabs/sdk-js";
110
108
  import { asArchivistInstance } from "@xyo-network/archivist-model";
111
109
  import { BoundWitnessBuilder as BoundWitnessBuilder2 } from "@xyo-network/boundwitness-builder";
112
110
  import { isBoundWitness as isBoundWitness2 } from "@xyo-network/boundwitness-model";
@@ -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 { toSafeJson } from '@xylabs/object'\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 type {\n Payload, Schema,\n WithStorageMeta,\n} from '@xyo-network/payload-model'\nimport { SequenceConstants } 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 (toSafeJson(nextState.state) === toSafeJson(this._lastState?.state)) 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 | null = null\n const diviner = await this.getBoundWitnessDivinerForStateStore()\n const query = 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 null as Hash | null,\n )\n }\n }\n\n // If we able to located the last state\n if (hash !== null) {\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 { toSafeJson } from '@xylabs/object'\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 type { WithStorageMeta } from '@xyo-network/payload-model'\nimport { SequenceConstants } 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 * @internal\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 (toSafeJson(nextState.state) === toSafeJson(this._lastState?.state)) 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 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 | null = null\n const diviner = await this.getBoundWitnessDivinerForStore()\n const query = 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 null as Hash | null,\n )\n }\n }\n\n // If we able to located the last state\n if (hash !== null) {\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,IAAM,wBAAwB;;;ACQ9B,IAAM,8BAA8B,GAAG,qBAAqB;;;ACRnE,SAAS,gBAAgB;AAEzB,SAAS,kBAAkB;AAC3B,SAAS,wBAAwB;AACjC,SAAS,2BAA2B;AACpC,SAAS,sBAAsB;AAC/B,SAAS,uBAAuB;AAEhC,SAAS,sCAAsC;AAE/C,SAAS,sBAAsB;AAE/B,SAAS,eAAe,yBAAyB;AACjD,SAAS,sBAAsB;AAK/B,SAAS,yBAAyB;AAKlC,IAAM,aAAa;AAKZ,IAAe,kBAAf,cAUG,gBAAgD;AAAA,EACxD,OAAyB,gBAA0B,CAAC,GAAG,MAAM,eAAe,2BAA2B;AAAA,EACvG,OAAyB,sBAA8B;AAAA;AAAA;AAAA;AAAA,EAK7C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASV,MAAgB,YAAY,WAAgC;AAE1D,QAAI,WAAW,UAAU,KAAK,MAAM,WAAW,KAAK,YAAY,KAAK,EAAG;AACxE,SAAK,aAAa;AAClB,UAAM,YAAY,MAAM,KAAK,0BAA0B;AACvD,UAAM,CAAC,EAAE,IAAI,MAAM,IAAI,oBAAoB,EAAE,QAAQ,SAAS,EAAE,OAAO,KAAK,OAAO,EAAE,MAAM;AAC3F,UAAM,UAAU,OAAO,CAAC,IAAI,SAAS,CAAC;AAAA,EACxC;AAAA;AAAA;A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;AAC1D,YAAM,QAAQ,IAAIF,gBAAgD,EAAE,QAAQH,gCAA+B,CAAC,EACzG,OAAO;AAAA;AAAA,QAEN,OAAO;AAAA,QACP,QAAQI,mBAAkB;AAAA,QAC1B,OAAO;AAAA,QACP,iBAAiB,CAACF,kBAAiB;AAAA,MACrC,CAAC,EACA,MAAM;AACT,YAAM,iBAAiB,MAAM,QAAQ,OAAO,CAAC,KAAK,CAAC;AACnD,UAAI,eAAe,SAAS,GAAG;AAC7B,cAAM,eAAe,eAAe,CAAC;AACrC,YAAIH,gBAAe,YAAY,GAAG;AAEhC,iBAAO,aAAa,UACjB,IAAI,CAAC,SAAS,WAAW,EAAE,SAAS,MAAM,EAAE,EAG5C;AAAA,YACC,CAAC,MAAM,SAAU,aAAa,kBAAkB,MAAM,KAAK,MAAMG,qBAAoB,aAAa,eAAe,MAAM,KAAK,IAAI;AAAA,YAChI;AAAA,UACF;AAAA,QACJ;AAAA,MACF;AAGA,UAAI,SAAS,MAAM;AAEjB,cAAM,YAAY,MAAM,KAAK,qBAAqB;AAClD,cAAM,WAAW,MAAM,UAAU,IAAI,CAAC,IAAI,CAAC,GAAG,KAAKD,cAAqB;AACxE,YAAI,SAAS;AACX,iBAAO;AAAA,QACT;AAAA,MACF;AACA,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;","names":["assertEx","toSafeJson","BoundWitnessBuilder","isBoundWitness","BoundWitnessDivinerQuerySchema","isModuleState","ModuleStateSchema","PayloadBuilder","SequenceConstants","moduleName"]}
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 type { Hash } from '@xylabs/sdk-js'\nimport { assertEx, toSafeJson } from '@xylabs/sdk-js'\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 type {\n Payload, Schema,\n WithStorageMeta,\n} from '@xyo-network/payload-model'\nimport { SequenceConstants } 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 (toSafeJson(nextState.state) === toSafeJson(this._lastState?.state)) 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 | null = null\n const diviner = await this.getBoundWitnessDivinerForStateStore()\n const query = 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 null as Hash | null,\n )\n }\n }\n\n // If we able to located the last state\n if (hash !== null) {\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 type { Hash } from '@xylabs/sdk-js'\nimport { assertEx, toSafeJson } from '@xylabs/sdk-js'\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 type { WithStorageMeta } from '@xyo-network/payload-model'\nimport { SequenceConstants } 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 * @internal\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 (toSafeJson(nextState.state) === toSafeJson(this._lastState?.state)) 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 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 | null = null\n const diviner = await this.getBoundWitnessDivinerForStore()\n const query = 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 null as Hash | null,\n )\n }\n }\n\n // If we able to located the last state\n if (hash !== null) {\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,IAAM,wBAAwB;;;ACQ9B,IAAM,8BAA8B,GAAG,qBAAqB;;;ACPnE,SAAS,UAAU,kBAAkB;AACrC,SAAS,wBAAwB;AACjC,SAAS,2BAA2B;AACpC,SAAS,sBAAsB;AAC/B,SAAS,uBAAuB;AAEhC,SAAS,sCAAsC;AAE/C,SAAS,sBAAsB;AAE/B,SAAS,eAAe,yBAAyB;AACjD,SAAS,sBAAsB;AAK/B,SAAS,yBAAyB;AAKlC,IAAM,aAAa;AAKZ,IAAe,kBAAf,cAUG,gBAAgD;AAAA,EACxD,OAAyB,gBAA0B,CAAC,GAAG,MAAM,eAAe,2BAA2B;AAAA,EACvG,OAAyB,sBAA8B;AAAA;AAAA;AAAA;AAAA,EAK7C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASV,MAAgB,YAAY,WAAgC;AAE1D,QAAI,WAAW,UAAU,KAAK,MAAM,WAAW,KAAK,YAAY,KAAK,EAAG;AACxE,SAAK,aAAa;AAClB,UAAM,YAAY,MAAM,KAAK,0BAA0B;AACvD,UAAM,CAAC,EAAE,IAAI,MAAM,IAAI,oBAAoB,EAAE,QAAQ,SAAS,EAAE,OAAO,KAAK,OAAO,EAAE,MAAM;AAC3F,UAAM,UAAU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B;AACxB,YAAM,UAAU,MAAM,KAAK,+BAA+B;AAC1D,YAAM,QAAQ,IAAIF,gBAAgD,EAAE,QAAQH,gCAA+B,CAAC,EACzG,OAAO;AAAA;AAAA,QAEN,OAAO;AAAA,QACP,QAAQI,mBAAkB;AAAA,QAC1B,OAAO;AAAA,QACP,iBAAiB,CAACF,kBAAiB;AAAA,MACrC,CAAC,EACA,MAAM;AACT,YAAM,iBAAiB,MAAM,QAAQ,OAAO,CAAC,KAAK,CAAC;AACnD,UAAI,eAAe,SAAS,GAAG;AAC7B,cAAM,eAAe,eAAe,CAAC;AACrC,YAAIH,gBAAe,YAAY,GAAG;AAEhC,iBAAO,aAAa,UACjB,IAAI,CAAC,SAAS,WAAW,EAAE,SAAS,MAAM,EAAE,EAG5C;AAAA,YACC,CAAC,MAAM,SAAU,aAAa,kBAAkB,MAAM,KAAK,MAAMG,qBAAoB,aAAa,eAAe,MAAM,KAAK,IAAI;AAAA,YAChI;AAAA,UACF;AAAA,QACJ;AAAA,MACF;AAGA,UAAI,SAAS,MAAM;AAEjB,cAAM,YAAY,MAAM,KAAK,qBAAqB;AAClD,cAAM,WAAW,MAAM,UAAU,IAAI,CAAC,IAAI,CAAC,GAAG,KAAKD,cAAqB;AACxE,YAAI,SAAS;AACX,iBAAO;AAAA,QACT;AAAA,MACF;AACA,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;","names":["assertEx","toSafeJson","BoundWitnessBuilder","isBoundWitness","BoundWitnessDivinerQuerySchema","isModuleState","ModuleStateSchema","PayloadBuilder","SequenceConstants","moduleName"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/diviner-stateful",
3
- "version": "5.2.18",
3
+ "version": "5.2.19",
4
4
  "description": "Primary SDK for using XYO Protocol 2.0",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -36,36 +36,35 @@
36
36
  "!**/*.test.*"
37
37
  ],
38
38
  "dependencies": {
39
- "@xylabs/assert": "~5.0.50",
40
- "@xylabs/object": "~5.0.50",
41
- "@xyo-network/archivist-model": "~5.2.18",
42
- "@xyo-network/archivist-wrapper": "~5.2.18",
43
- "@xyo-network/boundwitness-builder": "~5.2.18",
44
- "@xyo-network/boundwitness-model": "~5.2.18",
45
- "@xyo-network/diviner-abstract": "~5.2.18",
46
- "@xyo-network/diviner-boundwitness-model": "~5.2.18",
47
- "@xyo-network/diviner-model": "~5.2.18",
48
- "@xyo-network/diviner-wrapper": "~5.2.18",
49
- "@xyo-network/module-model": "~5.2.18",
50
- "@xyo-network/payload-builder": "~5.2.18",
51
- "@xyo-network/payload-model": "~5.2.18"
39
+ "@xylabs/sdk-js": "~5.0.61",
40
+ "@xyo-network/archivist-model": "~5.2.19",
41
+ "@xyo-network/archivist-wrapper": "~5.2.19",
42
+ "@xyo-network/boundwitness-builder": "~5.2.19",
43
+ "@xyo-network/boundwitness-model": "~5.2.19",
44
+ "@xyo-network/diviner-abstract": "~5.2.19",
45
+ "@xyo-network/diviner-boundwitness-model": "~5.2.19",
46
+ "@xyo-network/diviner-model": "~5.2.19",
47
+ "@xyo-network/diviner-wrapper": "~5.2.19",
48
+ "@xyo-network/module-model": "~5.2.19",
49
+ "@xyo-network/payload-builder": "~5.2.19",
50
+ "@xyo-network/payload-model": "~5.2.19"
52
51
  },
53
52
  "devDependencies": {
54
- "@xylabs/hex": "~5.0.50",
55
- "@xylabs/ts-scripts-yarn3": "~7.2.8",
56
- "@xylabs/tsconfig": "~7.2.8",
57
- "@xylabs/vitest-extended": "~5.0.50",
58
- "@xyo-network/account": "~5.2.18",
59
- "@xyo-network/archivist-memory": "~5.2.18",
60
- "@xyo-network/diviner-boundwitness-memory": "~5.2.18",
61
- "@xyo-network/diviner-payload-generic": "~5.2.18",
62
- "@xyo-network/diviner-payload-memory": "~5.2.18",
63
- "@xyo-network/manifest": "~5.2.18",
64
- "@xyo-network/module-factory-locator": "~5.2.18",
65
- "@xyo-network/node-memory": "~5.2.18",
66
- "@xyo-network/wallet": "~5.2.18",
53
+ "@xylabs/sdk-js": "~5.0.61",
54
+ "@xylabs/ts-scripts-yarn3": "~7.2.32",
55
+ "@xylabs/tsconfig": "~7.2.32",
56
+ "@xylabs/vitest-extended": "~5.0.61",
57
+ "@xyo-network/account": "~5.2.19",
58
+ "@xyo-network/archivist-memory": "~5.2.19",
59
+ "@xyo-network/diviner-boundwitness-memory": "~5.2.19",
60
+ "@xyo-network/diviner-payload-generic": "~5.2.19",
61
+ "@xyo-network/diviner-payload-memory": "~5.2.19",
62
+ "@xyo-network/manifest": "~5.2.19",
63
+ "@xyo-network/module-factory-locator": "~5.2.19",
64
+ "@xyo-network/node-memory": "~5.2.19",
65
+ "@xyo-network/wallet": "~5.2.19",
67
66
  "typescript": "~5.9.3",
68
- "vitest": "~4.0.15"
67
+ "vitest": "~4.0.16"
69
68
  },
70
69
  "publishConfig": {
71
70
  "access": "public"
package/src/Diviner.ts CHANGED
@@ -1,6 +1,5 @@
1
- import { assertEx } from '@xylabs/assert'
2
- import type { Hash } from '@xylabs/hex'
3
- import { toSafeJson } from '@xylabs/object'
1
+ import type { Hash } from '@xylabs/sdk-js'
2
+ import { assertEx, toSafeJson } from '@xylabs/sdk-js'
4
3
  import { ArchivistWrapper } from '@xyo-network/archivist-wrapper'
5
4
  import { BoundWitnessBuilder } from '@xyo-network/boundwitness-builder'
6
5
  import { isBoundWitness } from '@xyo-network/boundwitness-model'
@@ -1,6 +1,5 @@
1
- import { assertEx } from '@xylabs/assert'
2
- import type { Hash } from '@xylabs/hex'
3
- import { toSafeJson } from '@xylabs/object'
1
+ import type { Hash } from '@xylabs/sdk-js'
2
+ import { assertEx, toSafeJson } from '@xylabs/sdk-js'
4
3
  import { asArchivistInstance } from '@xyo-network/archivist-model'
5
4
  import { BoundWitnessBuilder } from '@xyo-network/boundwitness-builder'
6
5
  import { isBoundWitness } from '@xyo-network/boundwitness-model'