{"version":3,"file":"state.cjs","names":[],"sources":["../src/state.ts"],"sourcesContent":["import type { UpdateOp, UpdateOpError } from './stream'\n\n/** Input for retrieving a state value. */\nexport type StateGetInput = {\n  /** State scope (namespace). */\n  scope: string\n  /** Key within the scope. */\n  key: string\n}\n\n/** Input for setting a state value. */\nexport type StateSetInput = {\n  /** State scope (namespace). */\n  scope: string\n  /** Key within the scope. */\n  key: string\n  /** Value to store. */\n  // biome-ignore lint/suspicious/noExplicitAny: any is fine here\n  value: any\n}\n\n/** Input for deleting a state value. */\nexport type StateDeleteInput = {\n  /** State scope (namespace). */\n  scope: string\n  /** Key within the scope. */\n  key: string\n}\n\n/** Result of a state delete operation. */\nexport type StateDeleteResult = {\n  /** Previous value (if it existed). */\n  // biome-ignore lint/suspicious/noExplicitAny: any is fine here\n  old_value?: any\n}\n\n/** Input for listing all values in a state scope. */\nexport type StateListInput = {\n  /** State scope (namespace). */\n  scope: string\n}\n\n/** Result of a state set operation. */\nexport type StateSetResult<TData> = {\n  /** Previous value (if it existed). */\n  old_value?: TData\n  /** New value that was stored. */\n  new_value: TData\n}\n\n/** Result of a state update operation. */\nexport type StateUpdateResult<TData> = {\n  /** Previous value (if it existed). */\n  old_value?: TData\n  /** New value after the update. */\n  new_value: TData\n  /**\n   * Per-op errors. Currently emitted only by the `merge` op when input\n   * violates the validation bounds. See {@link UpdateOpError} and the\n   * `UpdateMerge` JSDoc in `./stream` for the error codes. Field is\n   * omitted from the JSON wire when empty.\n   */\n  errors?: UpdateOpError[]\n}\n\n/** Result of a state delete operation. */\nexport type DeleteResult = {\n  /** Previous value (if it existed). */\n  // biome-ignore lint/suspicious/noExplicitAny: any is fine here\n  old_value?: any\n}\n\n/** Input for atomically updating a state value. */\nexport type StateUpdateInput = {\n  /** State scope (namespace). */\n  scope: string\n  /** Key within the scope. */\n  key: string\n  /** Ordered list of update operations to apply atomically. */\n  ops: UpdateOp[]\n}\n\n/** Types of state change events. */\nexport enum StateEventType {\n  Created = 'state:created',\n  Updated = 'state:updated',\n  Deleted = 'state:deleted',\n}\n\n/** Payload for state change events. */\n// biome-ignore lint/suspicious/noExplicitAny: any is fine here\nexport interface StateEventData<TData = any> {\n  type: 'state'\n  /** Type of state change. */\n  event_type: StateEventType\n  /** State scope (namespace). */\n  scope: string\n  /** Key within the scope. */\n  key: string\n  /** Previous value (for update/delete events). */\n  old_value?: TData\n  /** New value (for create/update events). */\n  new_value?: TData\n}\n\n/**\n * Interface for state management operations. Available via the `iii-sdk/state`\n * subpath export.\n */\nexport interface IState {\n  /** Retrieve a value by scope and key. */\n  get<TData>(input: StateGetInput): Promise<TData | null>\n  /** Set (create or overwrite) a state value. */\n  set<TData>(input: StateSetInput): Promise<StateSetResult<TData> | null>\n  /** Delete a state value. */\n  delete(input: StateDeleteInput): Promise<DeleteResult>\n  /** List all values in a scope. */\n  list<TData>(input: StateListInput): Promise<TData[]>\n  /** Apply atomic update operations to a state value. */\n  update<TData>(input: StateUpdateInput): Promise<StateUpdateResult<TData> | null>\n}\n"],"mappings":";;;;AAmFA,IAAY,iBAAL;AACL;AACA;AACA;;KACD"}