import { M as Migrated, D as DeletableStore, F as FencedStore } from '../runtime-types-f231H8Gq.js'; import { m as memoryJournal$1 } from '../index-_evnHmXt.js'; import '../core-sEWVgnpI.js'; import '@standard-schema/spec'; /** * @packageDocumentation * @demlik/tea/mem — in-memory `Store` adapter for `@demlik/tea`. * * The standard test adapter — used everywhere a Worker or DO would be * overkill. Mirrors the source-only convention from `packages/widget-engine` * and `packages/tea` (no build step). * * Reference semantics, NOT deep-clone semantics: * - `save(state)` stores the reference; subsequent mutations to that * reference by the caller are observable through later `load()` calls. * - `load()` returns the stored reference; mutations made through it are * observable on the next `load()`. * * This matches what a real KV/DO `get()` would NOT do (those serialize + * deserialize), but it also matches what an in-memory cache obviously does. * Adding a deep clone here would lie about the boundary and impose a JSON * round-trip on every test. Tests that need fresh copies should clone at the * call site. * * Boundary parse (invariant 8): `Store` requires `migrate(raw)`. For * `memoryStore` we ship a permissive identity-default — `(raw) => raw as * S | null` — because this adapter is a degenerate same-process boundary: * there is no serialization, the reference we read is structurally the * reference we wrote. The `as` cast here is the documented exception to the * invariant-8 no-`as` rule, scoped to the parameter default. Callers that * want strict parsing (e.g. a test that hand-seeds the cell from outside) * may pass an explicit `parse` to override. */ /** Options for {@link memoryStore}. */ interface MemoryStoreOptions { /** * Refuse a second live writer (#143). With `{ fenced: true }` the returned * store is a `FencedStore` whose version is an in-process counter — honest * for this adapter, since the cell it guards is in this process too. Two * `run`s handed the SAME `memoryStore` are the case it catches, and it is the * cheapest way to exercise the fenced path in a test. A run on a fenced store * must be given an `onError` (see `StoreAndOnError`). */ readonly fenced?: true; } /** * Build an in-memory `Store`. * * @param initial - optional seed value. `undefined` and explicit `null` both * mean "no seed"; `load()` resolves with `null` until the first `save()`. * A concrete `S` seed is returned by `load()` until overwritten. * @param parse - optional boundary parse for the `Store.migrate` contract. * Defaults to identity (`(raw) => raw as S | null`) — honest for this * adapter's degenerate same-process boundary. Pass an explicit parser when * the test wants to reject seeded shapes that don't match `S`. */ declare function memoryStore(initial?: S | null, parse?: (raw: unknown) => Migrated): DeletableStore; declare function memoryStore(initial: S | null | undefined, parse: ((raw: unknown) => Migrated) | undefined, options: MemoryStoreOptions & { readonly fenced: true; }): FencedStore & DeletableStore; declare function memoryStore(initial?: S | null, parse?: (raw: unknown) => Migrated, options?: MemoryStoreOptions): DeletableStore | (FencedStore & DeletableStore); /** * Store opaque journal text in process memory, with explicit opt-in fencing. * @experimental */ declare const memoryJournal: typeof memoryJournal$1; export { type MemoryStoreOptions, memoryJournal, memoryStore };