import { EastType, EastTypeValue, ValueTypeOf } from '@elaraai/east'; import { PlatformFunction } from '@elaraai/east/internal'; import { RecordErrorType } from '@elaraai/e3-ui/internal'; import { RecordSignature, MutationResult, RecordHistoryResult } from '@elaraai/e3-api-client'; import { TrackedChannelStore } from './tracked-channel.js'; import { ReactiveDatasetCacheInterface } from './dataset-store.js'; /** Request shape for {@link RecordApi.mutate} — beast2-encoded positional * args (the extra reducer parameters, after the implicit state). */ export interface RecordMutateArgs { args: Uint8Array[]; } /** * Adapter for the workspace record endpoints. The default wraps * `@elaraai/e3-api-client`'s `workspaceRecordDescribe` / * `workspaceRecordMutate` / `workspaceRecordHistory`. `read()` does NOT go * through here — it reads the record's dataset bytes from the shared cache. */ export interface RecordApi { /** Describe a record's mutations (name + extra arg types), for validation. */ describe(workspace: string, record: string): Promise; /** Apply a mutation synchronously, returning its terminal MutationResult. */ mutate(workspace: string, record: string, mutation: string, req: RecordMutateArgs): Promise; /** Read a record's commit chain (newest first). */ history(workspace: string, record: string, limit: number | undefined, from?: string): Promise; } /** * Build the default {@link RecordApi} that talks to a real e3 server via * `@elaraai/e3-api-client`. */ export declare function createDefaultRecordApi(apiUrl: string, repo: string, getToken: () => string | null): RecordApi; type RecordError = ValueTypeOf; type RecordMutateTag = "idle" | "running" | "committed" | "failed" | "cancelled"; /** A handle's signature, recovered from the instantiated handle type. */ interface RecordHandleSignature { readonly stateType: EastTypeValue; readonly mutations: ReadonlyMap; } /** * Introspect the instantiated handle struct type `H`: the state type comes * from the `read` field's FunctionType output, and the mutation names + arg * types come from the `mutate` sub-struct's non-reserved FunctionType fields. * The handle's shape IS the signature — there are no duplicate signature * arguments to drift out of sync. */ export declare function signatureOfRecordHandleType(handleType: EastTypeValue): RecordHandleSignature; /** Tracked mutation-channel key (one per record). */ export declare function recordChannelKey(workspace: string, name: string): string; /** One tracked mutation channel per `(workspace, record)`. */ interface RecordEntry { status: RecordMutateTag; /** Monotonic; a settling mutation whose seq is no longer current is * discarded (latest-wins, and `cancel` orphans by bumping it). */ launchSeq: number; /** Detail of the last `failed` mutation. */ error?: RecordError; /** The settle promise of the in-flight mutation, if one is running. `start()` * awaits it so a commit lands before the dataflow run reads the record. */ inflight?: Promise; } /** * Encapsulates all `Record.bind` runtime state. The module-level * {@link defaultRecordRuntime} instance backs the registered platform; tests * construct their own for isolation. */ export declare class RecordRuntime extends TrackedChannelStore { private api; private cache; private workspace; private readonly signatureCache; private readonly histories; private readonly historyInFlight; private readonly historyFailed; protected createEntry(): RecordEntry; /** Install the API adapter + dataset cache + workspace — called by the * React provider (or a test/showcase harness) before any handle is used. */ initialize(api: RecordApi, cache: ReactiveDatasetCacheInterface, workspace: string): void; /** Tear down the adapter and all record state. */ clear(): void; private resolveWorkspace; /** The deployed describe signature for a record (fetched once, evicted on failure). */ private signature; /** Validate a mutation's declared arg types against the deployed signature. */ private validate; /** Fetch a record's history once per channel (deduped); notify on settle. */ private fetchHistory; private launchMutation; /** Build the handle value for one `Record.bind` platform evaluation. */ buildHandle(handleType: EastTypeValue, name: string): Record; /** Build a `Record.bind` PlatformFunction bound to this runtime. Pass * `allowed=null` for an unscoped impl; pass a Set of record names for * manifest scoping. */ buildPlatform(allowed: ReadonlySet | null): PlatformFunction; } /** Process-global runtime backing the `RecordPlatform` export. */ export declare const defaultRecordRuntime: RecordRuntime; /** Install the record API adapter + dataset cache + workspace — called by the * React provider on mount (or by a test/showcase harness). */ export declare function initializeRecordApi(api: RecordApi, cache: ReactiveDatasetCacheInterface, workspace: string): void; /** Tear down the record API adapter and all record state. */ export declare function clearRecordApi(): void; /** Global, manifest-unscoped `Record.bind` impl. Registered on module load. */ export declare const RecordPlatform: PlatformFunction[]; /** Build a manifest-scoped `Record.bind` implementation. */ export declare function createScopedRecordPlatform(records: readonly string[]): PlatformFunction[]; /** One offline record implementation for {@link createInMemoryRecordApi}. */ export interface InMemoryRecordDef { /** Record name (what `Record.bind` is bound to). */ name: string; /** The record's state type. */ stateType: EastType | EastTypeValue; /** Initial state value (seeds the dataset cache). */ initial: unknown; /** Mutations — each a reducer over the decoded state + decoded args. */ mutations: { name: string; argTypes: (EastType | EastTypeValue)[]; reduce: (state: unknown, ...args: unknown[]) => unknown; }[]; } /** * Build an offline {@link RecordApi} from local implementations — the * showcase/snapshot harnesses' stand-in for a deployed record. Seeds each * record's current value into the dataset cache so `read()` works offline. */ export declare function createInMemoryRecordApi(cache: ReactiveDatasetCacheInterface, workspace: string, defs: InMemoryRecordDef[]): RecordApi; export {}; //# sourceMappingURL=record-runtime.d.ts.map