/** * Storage adapter conformance helpers for third-party adapter authors. * * Imported via `@lostgradient/weft/storage/testing`. These helpers register * `bun:test` suites against a caller-provided adapter factory, so this subpath * is intended for Bun test files rather than production runtime bundles. * * @module @lostgradient/weft/storage/testing */ import type { Storage, StorageCapabilities } from './interface.ts'; /** * Options for {@link runStorageCapabilityConformance}. * * @example * ```ts * import type { CapabilityConformanceOptions } from '@lostgradient/weft/storage/testing'; * import { MemoryStorage, type StorageCapabilities } from '@lostgradient/weft/storage'; * * const expected = { * persistence: 'ephemeral', * readAfterWrite: 'linearizable', * scanConsistency: 'snapshot', * atomicBatch: true, * conditionalBatch: true, * boundedRangeDelete: true, * } satisfies StorageCapabilities; * * const options: CapabilityConformanceOptions = { * create: () => new MemoryStorage(), * expected, * }; * ``` */ export type CapabilityConformanceOptions = { /** Construct a fresh, empty adapter for each conformance case. */ readonly create: () => Storage | Promise; /** Expected capability row for this adapter, asserted exactly. */ readonly expected: StorageCapabilities; }; /** * Options for {@link runConcurrentConditionalBatchConformance}. * * @example * ```ts * import type { ConcurrentConditionalBatchConformanceOptions } from '@lostgradient/weft/storage/testing'; * import { BunSQLiteStorage } from '@lostgradient/weft/storage/sqlite/bun'; * * const options: ConcurrentConditionalBatchConformanceOptions = { * create: () => new BunSQLiteStorage(':memory:'), * }; * ``` */ export type ConcurrentConditionalBatchConformanceOptions = { /** Construct a fresh, empty adapter that can stage concurrent write transactions. */ readonly create: () => Storage | Promise; }; /** * Options for {@link runBinaryAndLargeScanStorageConformance}. * * @example * ```ts * import type { BinaryAndLargeScanConformanceOptions } from '@lostgradient/weft/storage/testing'; * import { MemoryStorage } from '@lostgradient/weft/storage'; * * const options: BinaryAndLargeScanConformanceOptions = { * create: () => new MemoryStorage(), * }; * ``` */ export type BinaryAndLargeScanConformanceOptions = { /** Construct a fresh, empty adapter for each conformance case. */ readonly create: () => Storage | Promise; /** Optional timeout for adapters whose local large-scan test needs more time. */ readonly largeScanTimeoutMs?: number; }; /** * Construct a fresh, empty adapter for each basic-contract case. * * @example * ```ts * import type { BasicStorageContractOptions } from '@lostgradient/weft/storage/testing'; * import { MemoryStorage } from '@lostgradient/weft/storage'; * * const options: BasicStorageContractOptions = { * create: () => new MemoryStorage(), * }; * ``` */ export type BasicStorageContractOptions = { readonly create: () => Storage | Promise; }; /** * Register a shared `describe` block for binary byte round-trips and large * sorted prefix scans. Use this alongside the basic contract for adapters whose * production storage can exercise larger result sets locally. * * @example * ```ts * import { runBinaryAndLargeScanStorageConformance } from '@lostgradient/weft/storage/testing'; * import { MemoryStorage } from '@lostgradient/weft/storage'; * * runBinaryAndLargeScanStorageConformance('MemoryStorage', { * create: () => new MemoryStorage(), * }); * ``` */ export declare function runBinaryAndLargeScanStorageConformance(name: string, options: BinaryAndLargeScanConformanceOptions): void; /** * Register a shared `describe` block that proves an adapter's declared * {@link StorageCapabilities} against its actual behavior, not just its * self-report. The suite asserts the exact capability row, then behaviorally * verifies read-after-write, snapshot scans, and compare-and-swap contention * when the adapter claims those stronger guarantees. * * @example * ```ts * import { runStorageCapabilityConformance } from '@lostgradient/weft/storage/testing'; * import { MemoryStorage, type StorageCapabilities } from '@lostgradient/weft/storage'; * * const expected = { * persistence: 'ephemeral', * readAfterWrite: 'linearizable', * scanConsistency: 'snapshot', * atomicBatch: true, * conditionalBatch: true, * boundedRangeDelete: true, * } satisfies StorageCapabilities; * * runStorageCapabilityConformance('MemoryStorage', { * create: () => new MemoryStorage(), * expected, * }); * ``` */ export declare function runStorageCapabilityConformance(name: string, options: CapabilityConformanceOptions): void; /** * Register a shared `describe` block that exercises concurrent * compare-and-swap writes against one adapter instance. Use this in addition to * {@link runStorageCapabilityConformance} for storage backends that can stage * overlapping write transactions locally. Synchronous in-memory adapters still * run these calls in the same JavaScript turn, so pair this helper with an * adapter-specific multi-connection test when true IO-level contention matters. * * @example * ```ts * import { runConcurrentConditionalBatchConformance } from '@lostgradient/weft/storage/testing'; * import { BunSQLiteStorage } from '@lostgradient/weft/storage/sqlite/bun'; * * runConcurrentConditionalBatchConformance('BunSQLiteStorage', { * create: () => new BunSQLiteStorage(':memory:'), * }); * ``` */ export declare function runConcurrentConditionalBatchConformance(name: string, options: ConcurrentConditionalBatchConformanceOptions): void; /** * Register the complete basic key/value and scan contract that every storage * adapter must satisfy: get, put, overwrite, delete (including missing keys), * prefix scans, limits, reverse ordering, exclusive and inclusive range * bounds, no-match scans, empty-prefix scans, and put/delete batches. * * @example * ```ts * import { runBasicStorageContract } from '@lostgradient/weft/storage/testing'; * import { MemoryStorage } from '@lostgradient/weft/storage'; * * runBasicStorageContract('MemoryStorage', { * create: () => new MemoryStorage(), * }); * ``` */ export declare function runBasicStorageContract(name: string, options: BasicStorageContractOptions): void;