@xyo-network/diviner-stateful 6.1.0 → 7.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,8 @@
1
+ import { zodAsFactory, zodIsFactory, zodToFactory } from '@xylabs/sdk-js';
1
2
  import type { DivinerConfig } from '@xyo-network/diviner-model';
3
+ import { DivinerConfigZod } from '@xyo-network/diviner-model';
2
4
  import type { ModuleIdentifier } from '@xyo-network/module-model';
5
+ import * as z from 'zod/mini';
3
6
  /**
4
7
  * The schema for a Stateful Diviner config
5
8
  */
@@ -10,6 +13,18 @@ export declare const StatefulDivinerConfigSchema: string & {
10
13
  * The schema for a Stateful Diviner config
11
14
  */
12
15
  export type StatefulDivinerConfigSchema = typeof StatefulDivinerConfigSchema;
16
+ export declare const StatefulDivinerConfigZod: z.ZodMiniObject<Omit<(typeof DivinerConfigZod)['shape'], 'schema'> & {
17
+ schema: z.ZodMiniLiteral<StatefulDivinerConfigSchema>;
18
+ stateStore: z.ZodMiniObject<{
19
+ archivist: z.ZodMiniCustom<ModuleIdentifier, ModuleIdentifier>;
20
+ boundWitnessDiviner: z.ZodMiniCustom<ModuleIdentifier, ModuleIdentifier>;
21
+ payloadDiviner: z.ZodMiniCustom<ModuleIdentifier, ModuleIdentifier>;
22
+ }, z.core.$strip>;
23
+ }, z.core.$strip>;
24
+ export type StatefulDivinerConfigBase = z.infer<typeof StatefulDivinerConfigZod>;
25
+ export declare const isStatefulDivinerConfig: ReturnType<typeof zodIsFactory<StatefulDivinerConfigBase>>;
26
+ export declare const asStatefulDivinerConfig: ReturnType<typeof zodAsFactory<StatefulDivinerConfigBase>>;
27
+ export declare const toStatefulDivinerConfig: ReturnType<typeof zodToFactory<StatefulDivinerConfigBase>>;
13
28
  /**
14
29
  * The config for a Stateful Diviner
15
30
  */
@@ -1 +1 @@
1
- {"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/Config.ts"],"names":[],"mappings":"AAAA,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AAC,cAAc,CAAC,2BAA2B,CAAC,CAAA;IACrD,UAAU,EAAE,CAAC,CAAC,aAAa,CAAC;QAC1B,SAAS,EAAE,CAAC,CAAC,aAAa,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,CAAA;QAC9D,mBAAmB,EAAE,CAAC,CAAC,aAAa,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,CAAA;QACxE,cAAc,EAAE,CAAC,CAAC,aAAa,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,CAAA;KACpE,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;CAClB,EACD,CAAC,CAAC,IAAI,CAAC,MAAM,CAQb,CAAA;AAEF,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAA;AAEhF,eAAO,MAAM,uBAAuB,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,yBAAyB,CAAC,CAA0C,CAAA;AACzI,eAAO,MAAM,uBAAuB,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,yBAAyB,CAAC,CAAqE,CAAA;AACpK,eAAO,MAAM,uBAAuB,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,yBAAyB,CAAC,CAAqE,CAAA;AAEpK;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,aAAa,CAAC;IAChD,MAAM,EAAE,2BAA2B,CAAA;IACnC,UAAU,EAAE;QACV,SAAS,EAAE,gBAAgB,CAAA;QAC3B,mBAAmB,EAAE,gBAAgB,CAAA;QACrC,cAAc,EAAE,gBAAgB,CAAA;KACjC,CAAA;CACF,CAAC,CAAA"}
@@ -1,5 +1,12 @@
1
1
  // src/Config.ts
2
+ import {
3
+ zodAsFactory,
4
+ zodIsFactory,
5
+ zodToFactory
6
+ } from "@xylabs/sdk-js";
7
+ import { DivinerConfigZod } from "@xyo-network/diviner-model";
2
8
  import { asSchema as asSchema2 } from "@xyo-network/sdk-protocol-js";
9
+ import * as z from "zod/mini";
3
10
 
4
11
  // src/Schema.ts
5
12
  import { asSchema } from "@xyo-network/sdk-protocol-js";
@@ -7,6 +14,17 @@ var StatefulDivinerSchema = asSchema("network.xyo.diviner.stateful", true);
7
14
 
8
15
  // src/Config.ts
9
16
  var StatefulDivinerConfigSchema = asSchema2(`${StatefulDivinerSchema}.config`, true);
17
+ var StatefulDivinerConfigZod = z.extend(DivinerConfigZod, {
18
+ schema: z.literal(StatefulDivinerConfigSchema),
19
+ stateStore: z.object({
20
+ archivist: z.custom(),
21
+ boundWitnessDiviner: z.custom(),
22
+ payloadDiviner: z.custom()
23
+ })
24
+ });
25
+ var isStatefulDivinerConfig = zodIsFactory(StatefulDivinerConfigZod);
26
+ var asStatefulDivinerConfig = zodAsFactory(StatefulDivinerConfigZod, "asStatefulDivinerConfig");
27
+ var toStatefulDivinerConfig = zodToFactory(StatefulDivinerConfigZod, "toStatefulDivinerConfig");
10
28
 
11
29
  // src/Diviner.ts
12
30
  import { assertEx, toSafeJson } from "@xylabs/sdk-js";
@@ -218,7 +236,11 @@ var StatefulModuleMixin = (ModuleBase) => {
218
236
  export {
219
237
  StatefulDiviner,
220
238
  StatefulDivinerConfigSchema,
239
+ StatefulDivinerConfigZod,
221
240
  StatefulDivinerSchema,
222
- StatefulModuleMixin
241
+ StatefulModuleMixin,
242
+ asStatefulDivinerConfig,
243
+ isStatefulDivinerConfig,
244
+ toStatefulDivinerConfig
223
245
  };
224
246
  //# sourceMappingURL=index.mjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/Config.ts", "../../src/Schema.ts", "../../src/Diviner.ts", "../../src/DivinerMixin.ts"],
4
- "sourcesContent": ["import type { DivinerConfig } from '@xyo-network/diviner-model'\nimport type { ModuleIdentifier } from '@xyo-network/module-model'\nimport { asSchema } from '@xyo-network/sdk-protocol-js'\n\nimport { StatefulDivinerSchema } from './Schema.ts'\n\n/**\n * The schema for a Stateful Diviner config\n */\nexport const StatefulDivinerConfigSchema: string & {\n readonly __schema: true\n} = asSchema(`${StatefulDivinerSchema}.config`, true)\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 { asSchema } from '@xyo-network/sdk-protocol-js'\n\nexport const StatefulDivinerSchema: 'network.xyo.diviner.stateful' & {\n readonly __schema: true\n} = asSchema('network.xyo.diviner.stateful', true)\nexport type StatefulDivinerSchema = typeof StatefulDivinerSchema\n", "import type { Hash } from '@xylabs/sdk-js'\nimport { assertEx, toSafeJson } from '@xylabs/sdk-js'\nimport type {\n ArchivistConfig, ArchivistModuleEventData, ArchivistModuleInstance,\n} from '@xyo-network/archivist-model'\nimport { ArchivistWrapper } from '@xyo-network/archivist-wrapper'\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 {\n DivinerConfig, DivinerInstance, DivinerModule, DivinerModuleEventData, DivinerParams,\n} from '@xyo-network/diviner-model'\nimport { DivinerWrapper } from '@xyo-network/diviner-wrapper'\nimport type {\n AnyConfigSchema, ModuleState, QueryableModuleParams, StateDictionary,\n} from '@xyo-network/module-model'\nimport { isModuleState, ModuleStateSchema } from '@xyo-network/module-model'\nimport type {\n Payload, Schema,\n WithStorageMeta,\n} from '@xyo-network/sdk-protocol-js'\nimport {\n BoundWitnessBuilder, isBoundWitness, PayloadBuilder, SequenceConstants,\n} from '@xyo-network/sdk-protocol-js'\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>): Promise<void> {\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(): Promise<ArchivistWrapper<ArchivistModuleInstance<QueryableModuleParams<AnyConfigSchema<ArchivistConfig>>, ArchivistModuleEventData>>> {\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(): Promise<DivinerWrapper<DivinerModule<DivinerParams<AnyConfigSchema<DivinerConfig>>, DivinerModuleEventData>, Payload, Payload>> {\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(): Promise<DivinerWrapper<DivinerModule<DivinerParams<AnyConfigSchema<DivinerConfig>>, DivinerModuleEventData>, Payload, Payload>> {\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 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 ModuleState,\n QueryableModuleParams,\n StateDictionary,\n} from '@xyo-network/module-model'\nimport {\n isModuleState,\n ModuleStateSchema,\n} from '@xyo-network/module-model'\nimport type { WithStorageMeta } from '@xyo-network/sdk-protocol-js'\nimport {\n BoundWitnessBuilder, isBoundWitness, PayloadBuilder, SequenceConstants,\n} from '@xyo-network/sdk-protocol-js'\n\nimport type { StatefulDivinerConfig } from './Config.ts'\n\nexport type StatefulModuleParams = QueryableModuleParams<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"],
5
- "mappings": ";AAEA,SAAS,YAAAA,iBAAgB;;;ACFzB,SAAS,gBAAgB;AAElB,IAAM,wBAET,SAAS,gCAAgC,IAAI;;;ADK1C,IAAM,8BAETC,UAAS,GAAG,qBAAqB,WAAW,IAAI;;;AEVpD,SAAS,UAAU,kBAAkB;AAIrC,SAAS,wBAAwB;AACjC,SAAS,uBAAuB;AAEhC,SAAS,sCAAsC;AAI/C,SAAS,sBAAsB;AAI/B,SAAS,eAAe,yBAAyB;AAKjD;AAAA,EACE;AAAA,EAAqB;AAAA,EA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,CAAC,IAAI,CAAC,GAAG,KAAKD,cAAqB;AACxE,YAAI,SAAS;AACX,iBAAO;AAAA,QACT;AAAA,MACF;AACA,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;",
4
+ "sourcesContent": ["import {\n zodAsFactory, zodIsFactory, zodToFactory,\n} from '@xylabs/sdk-js'\nimport type { DivinerConfig } from '@xyo-network/diviner-model'\nimport { DivinerConfigZod } from '@xyo-network/diviner-model'\nimport type { ModuleIdentifier } from '@xyo-network/module-model'\nimport { asSchema } from '@xyo-network/sdk-protocol-js'\nimport * as z from 'zod/mini'\n\nimport { StatefulDivinerSchema } from './Schema.ts'\n\n/**\n * The schema for a Stateful Diviner config\n */\nexport const StatefulDivinerConfigSchema: string & {\n readonly __schema: true\n} = asSchema(`${StatefulDivinerSchema}.config`, true)\n/**\n * The schema for a Stateful Diviner config\n */\nexport type StatefulDivinerConfigSchema = typeof StatefulDivinerConfigSchema\n\nexport const StatefulDivinerConfigZod: z.ZodMiniObject<\n Omit<(typeof DivinerConfigZod)['shape'], 'schema'> & {\n schema: z.ZodMiniLiteral<StatefulDivinerConfigSchema>\n stateStore: z.ZodMiniObject<{\n archivist: z.ZodMiniCustom<ModuleIdentifier, ModuleIdentifier>\n boundWitnessDiviner: z.ZodMiniCustom<ModuleIdentifier, ModuleIdentifier>\n payloadDiviner: z.ZodMiniCustom<ModuleIdentifier, ModuleIdentifier>\n }, z.core.$strip>\n },\n z.core.$strip\n> = z.extend(DivinerConfigZod, {\n schema: z.literal(StatefulDivinerConfigSchema),\n stateStore: z.object({\n archivist: z.custom<ModuleIdentifier>(),\n boundWitnessDiviner: z.custom<ModuleIdentifier>(),\n payloadDiviner: z.custom<ModuleIdentifier>(),\n }),\n})\n\nexport type StatefulDivinerConfigBase = z.infer<typeof StatefulDivinerConfigZod>\n\nexport const isStatefulDivinerConfig: ReturnType<typeof zodIsFactory<StatefulDivinerConfigBase>> = zodIsFactory(StatefulDivinerConfigZod)\nexport const asStatefulDivinerConfig: ReturnType<typeof zodAsFactory<StatefulDivinerConfigBase>> = zodAsFactory(StatefulDivinerConfigZod, 'asStatefulDivinerConfig')\nexport const toStatefulDivinerConfig: ReturnType<typeof zodToFactory<StatefulDivinerConfigBase>> = zodToFactory(StatefulDivinerConfigZod, 'toStatefulDivinerConfig')\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 { asSchema } from '@xyo-network/sdk-protocol-js'\n\nexport const StatefulDivinerSchema: 'network.xyo.diviner.stateful' & {\n readonly __schema: true\n} = asSchema('network.xyo.diviner.stateful', true)\nexport type StatefulDivinerSchema = typeof StatefulDivinerSchema\n", "import type { Hash } from '@xylabs/sdk-js'\nimport { assertEx, toSafeJson } from '@xylabs/sdk-js'\nimport type {\n ArchivistConfig, ArchivistModuleEventData, ArchivistModuleInstance,\n} from '@xyo-network/archivist-model'\nimport { ArchivistWrapper } from '@xyo-network/archivist-wrapper'\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 {\n DivinerConfig, DivinerInstance, DivinerModule, DivinerModuleEventData, DivinerParams,\n} from '@xyo-network/diviner-model'\nimport { DivinerWrapper } from '@xyo-network/diviner-wrapper'\nimport type {\n AnyConfigSchema, ModuleState, QueryableModuleParams, StateDictionary,\n} from '@xyo-network/module-model'\nimport { isModuleState, ModuleStateSchema } from '@xyo-network/module-model'\nimport type {\n Payload, Schema,\n WithStorageMeta,\n} from '@xyo-network/sdk-protocol-js'\nimport {\n BoundWitnessBuilder, isBoundWitness, PayloadBuilder, SequenceConstants,\n} from '@xyo-network/sdk-protocol-js'\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>): Promise<void> {\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(): Promise<ArchivistWrapper<ArchivistModuleInstance<QueryableModuleParams<AnyConfigSchema<ArchivistConfig>>, ArchivistModuleEventData>>> {\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(): Promise<DivinerWrapper<DivinerModule<DivinerParams<AnyConfigSchema<DivinerConfig>>, DivinerModuleEventData>, Payload, Payload>> {\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(): Promise<DivinerWrapper<DivinerModule<DivinerParams<AnyConfigSchema<DivinerConfig>>, DivinerModuleEventData>, Payload, Payload>> {\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 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 ModuleState,\n QueryableModuleParams,\n StateDictionary,\n} from '@xyo-network/module-model'\nimport {\n isModuleState,\n ModuleStateSchema,\n} from '@xyo-network/module-model'\nimport type { WithStorageMeta } from '@xyo-network/sdk-protocol-js'\nimport {\n BoundWitnessBuilder, isBoundWitness, PayloadBuilder, SequenceConstants,\n} from '@xyo-network/sdk-protocol-js'\n\nimport type { StatefulDivinerConfig } from './Config.ts'\n\nexport type StatefulModuleParams = QueryableModuleParams<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"],
5
+ "mappings": ";AAAA;AAAA,EACE;AAAA,EAAc;AAAA,EAAc;AAAA,OACvB;AAEP,SAAS,wBAAwB;AAEjC,SAAS,YAAAA,iBAAgB;AACzB,YAAY,OAAO;;;ACPnB,SAAS,gBAAgB;AAElB,IAAM,wBAET,SAAS,gCAAgC,IAAI;;;ADU1C,IAAM,8BAETC,UAAS,GAAG,qBAAqB,WAAW,IAAI;AAM7C,IAAM,2BAUP,SAA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EACA,MAAM;AACT,YAAM,iBAAiB,MAAM,QAAQ,OAAO,CAAC,KAAK,CAAC;AACnD,UAAI,eAAe,SAAS,GAAG;AAC7B,cAAM,eAAe,eAAe,CAAC;AACrC,YAAIE,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,MAAMF,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;",
6
6
  "names": ["asSchema", "asSchema", "assertEx", "toSafeJson", "BoundWitnessDivinerQuerySchema", "isModuleState", "ModuleStateSchema", "BoundWitnessBuilder", "isBoundWitness", "PayloadBuilder", "SequenceConstants", "moduleName"]
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/diviner-stateful",
3
- "version": "6.1.0",
3
+ "version": "7.0.1",
4
4
  "description": "Primary SDK for using XYO Protocol 2.0",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -34,49 +34,49 @@
34
34
  "README.md"
35
35
  ],
36
36
  "dependencies": {
37
- "@xyo-network/archivist-model": "~6.1.0",
38
- "@xyo-network/archivist-wrapper": "~6.1.0",
39
- "@xyo-network/diviner-abstract": "~6.1.0",
40
- "@xyo-network/diviner-boundwitness": "~6.1.0",
41
- "@xyo-network/diviner-model": "~6.1.0",
42
- "@xyo-network/module-model": "~6.1.0",
43
- "@xyo-network/diviner-wrapper": "~6.1.0"
37
+ "@xyo-network/archivist-model": "~7.0.1",
38
+ "@xyo-network/diviner-wrapper": "~7.0.1",
39
+ "@xyo-network/module-model": "~7.0.1",
40
+ "@xyo-network/diviner-abstract": "~7.0.1",
41
+ "@xyo-network/archivist-wrapper": "~7.0.1",
42
+ "@xyo-network/diviner-model": "~7.0.1",
43
+ "@xyo-network/diviner-boundwitness": "~7.0.1"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@bitauth/libauth": "~3.0.0",
47
47
  "@metamask/providers": "^22.1.1",
48
48
  "@noble/post-quantum": "~0.6.1",
49
49
  "@opentelemetry/api": "^1.9.1",
50
- "@opentelemetry/sdk-trace-base": "^2.7.1",
50
+ "@opentelemetry/sdk-trace-base": "^2.8.0",
51
51
  "@scure/base": "~2.2.0",
52
52
  "@scure/bip39": "~2.2.0",
53
- "@xylabs/geo": "^6.1.0",
54
- "@xylabs/sdk-js": "^6.1.0",
55
- "@xylabs/threads": "^6.1.0",
56
- "@xylabs/toolchain": "^8.1.20",
57
- "@xylabs/tsconfig": "^8.1.20",
58
- "@xylabs/vitest-extended": "^6.1.0",
59
- "@xyo-network/sdk-protocol-js": "^6.1.0",
53
+ "@xylabs/geo": "^6.1.4",
54
+ "@xylabs/sdk-js": "^6.1.4",
55
+ "@xylabs/threads": "^6.1.4",
56
+ "@xylabs/toolchain": "^8.3.0",
57
+ "@xylabs/tsconfig": "^8.3.0",
58
+ "@xylabs/vitest-extended": "^6.1.4",
59
+ "@xyo-network/sdk-protocol-js": "^7.0.3",
60
60
  "ajv": "^8.20.0",
61
61
  "async-mutex": "^0.5.0",
62
62
  "debug": "~4.4.3",
63
- "eslint": "^10.4.1",
64
- "ethers": "^6.16.0",
63
+ "eslint": "^10.5.0",
64
+ "ethers": "^6.17.0",
65
65
  "hash-wasm": "~4.12.0",
66
66
  "idb": "^8.0.3",
67
67
  "lru-cache": "^11.5.1",
68
68
  "observable-fns": "~0.6.1",
69
69
  "tslib": "^2.8.1",
70
70
  "typescript": "~6.0.3",
71
- "vite": "^8.0.16",
72
- "vitest": "~4.1.8",
71
+ "vite": "^8.1.0",
72
+ "vitest": "~4.1.9",
73
73
  "webextension-polyfill": "^0.12.0",
74
74
  "zod": "^4.4.3",
75
- "@xyo-network/archivist-memory": "~6.1.0",
76
- "@xyo-network/diviner-payload-generic": "~6.1.0",
77
- "@xyo-network/manifest-wrapper": "~6.1.0",
78
- "@xyo-network/module-factory-locator": "~6.1.0",
79
- "@xyo-network/node-memory": "~6.1.0"
75
+ "@xyo-network/archivist-memory": "~7.0.1",
76
+ "@xyo-network/manifest-wrapper": "~7.0.1",
77
+ "@xyo-network/module-factory-locator": "~7.0.1",
78
+ "@xyo-network/diviner-payload-generic": "~7.0.1",
79
+ "@xyo-network/node-memory": "~7.0.1"
80
80
  },
81
81
  "peerDependencies": {
82
82
  "@bitauth/libauth": "~3.0",
@@ -89,7 +89,7 @@
89
89
  "@xylabs/geo": "^6.0",
90
90
  "@xylabs/sdk-js": "^6.0",
91
91
  "@xylabs/threads": "^6.0",
92
- "@xyo-network/sdk-protocol-js": "^6.1",
92
+ "@xyo-network/sdk-protocol-js": "^7.0",
93
93
  "ajv": "^8.20",
94
94
  "async-mutex": "^0.5",
95
95
  "debug": "~4.4",