@orkestrel/indexeddb 0.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.
- package/LICENSE +21 -0
- package/README.md +35 -0
- package/dist/src/browser/IndexedDBCursor.d.ts +28 -0
- package/dist/src/browser/IndexedDBDatabase.d.ts +27 -0
- package/dist/src/browser/IndexedDBIndex.d.ts +31 -0
- package/dist/src/browser/IndexedDBStore.d.ts +41 -0
- package/dist/src/browser/IndexedDBTransaction.d.ts +24 -0
- package/dist/src/browser/IndexedDBTransactionStore.d.ts +34 -0
- package/dist/src/browser/constants.d.ts +10 -0
- package/dist/src/browser/errors.d.ts +30 -0
- package/dist/src/browser/factories.d.ts +30 -0
- package/dist/src/browser/helpers.d.ts +130 -0
- package/dist/src/browser/index.d.ts +11 -0
- package/dist/src/browser/index.js +939 -0
- package/dist/src/browser/index.js.map +1 -0
- package/dist/src/browser/types.d.ts +290 -0
- package/package.json +77 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["#cursor","#request","#key","#primary","#direction","#value","#advance","#store","#name","#definition","#connect","#index","#resolve","#name","#definition","#connect","#store","#resolve","#store","#name","#resolve","#transaction","#stores","#active","#finished","#name","#version","#stores","#upgrade","#database","#closed","#opening","#open","#run","#request","#missing","#createStore","#context"],"sources":["../../../src/browser/constants.ts","../../../src/browser/errors.ts","../../../node_modules/@orkestrel/contract/dist/src/core/index.js","../../../src/browser/helpers.ts","../../../src/browser/IndexedDBCursor.ts","../../../src/browser/IndexedDBIndex.ts","../../../src/browser/IndexedDBStore.ts","../../../src/browser/IndexedDBTransactionStore.ts","../../../src/browser/IndexedDBTransaction.ts","../../../src/browser/IndexedDBDatabase.ts","../../../src/browser/factories.ts"],"sourcesContent":["import type { IndexedDBErrorCode } from './types.js'\n\n/**\n * Native `DOMException.name` → our {@link IndexedDBErrorCode}.\n *\n * @remarks\n * The mapping the request boundary's `wrapError` reads to translate a raw\n * IndexedDB fault into a typed {@link IndexedDBError} code; an unmapped name\n * falls back to `UNKNOWN`. Frozen plain data (AGENTS §5).\n */\nexport const ERROR_CODES: Readonly<Record<string, IndexedDBErrorCode>> = Object.freeze({\n\tConstraintError: 'CONSTRAINT',\n\tQuotaExceededError: 'QUOTA',\n\tAbortError: 'ABORTED',\n\tNotFoundError: 'NOT_FOUND',\n\tDataError: 'DATA',\n\tVersionError: 'UPGRADE',\n\tTransactionInactiveError: 'INACTIVE',\n\tInvalidStateError: 'INVALID',\n})\n","// Errors for the IndexedDB wrapper. A single `IndexedDBError` carries a\n// machine-readable `code` mapped from the native `DOMException.name` at the\n// request boundary, so a `catch` branches on `error.code` rather than parsing a\n// message. It is deliberately richer than the core `DatabaseError`'s four codes:\n// the wrapper sits *below* the core, right on the raw IndexedDB surface, where\n// constraint, quota, and abort faults are all distinct and worth naming\n// (AGENTS §12).\n\nimport type { IndexedDBErrorCode } from './types.js'\n\n/**\n * An error thrown by the IndexedDB wrapper.\n *\n * @remarks\n * Carries an {@link IndexedDBErrorCode} and the originating native error as the\n * standard `cause`. Construct it directly for wrapper-lifecycle faults; the\n * internal `wrapError` maps a native `DOMException` to the right code at the\n * request boundary. Narrow a caught value with `instanceof IndexedDBError`.\n *\n * @example\n * ```ts\n * try {\n * \tawait store.add(row)\n * } catch (error) {\n * \tif (error instanceof IndexedDBError && error.code === 'CONSTRAINT') await store.set(row)\n * }\n * ```\n */\nexport class IndexedDBError extends Error {\n\treadonly code: IndexedDBErrorCode\n\n\tconstructor(code: IndexedDBErrorCode, message: string, cause?: unknown) {\n\t\tsuper(message, { cause })\n\t\tthis.name = 'IndexedDBError'\n\t\tthis.code = code\n\t}\n}\n\n/**\n * Whether a value is an {@link IndexedDBError}.\n *\n * @param value - The value to test\n * @returns `true` when `value` is an `IndexedDBError`\n */\nexport function isIndexedDBError(value: unknown): value is IndexedDBError {\n\treturn value instanceof IndexedDBError\n}\n","//#region src/core/constants.ts\n/**\n* The seven standard JSON Schema `type` names, frozen.\n*\n* @remarks\n* The runtime source of truth for the {@link JSONSchemaType} vocabulary. Compose\n* it with the shipped primitives instead of reaching for a bespoke guard:\n* `literalOf(...JSON_SCHEMA_TYPES)` is the guard, and\n* `parseEnum(value, JSON_SCHEMA_TYPES)` / `parseEnumField(record, path, JSON_SCHEMA_TYPES)`\n* is the parser.\n*\n* @example\n* ```ts\n* import { JSON_SCHEMA_TYPES, literalOf, parseEnumField } from '@src/core'\n*\n* const isSchemaType = literalOf(...JSON_SCHEMA_TYPES) // Guard<JSONSchemaType>\n* parseEnumField(schema, 'type', JSON_SCHEMA_TYPES) // JSONSchemaType | undefined\n* ```\n*/\nvar JSON_SCHEMA_TYPES = Object.freeze([\n\t\"null\",\n\t\"boolean\",\n\t\"object\",\n\t\"array\",\n\t\"number\",\n\t\"integer\",\n\t\"string\"\n]);\n//#endregion\n//#region src/core/validators.ts\n/** Determine whether a value is `null`. */\nfunction isNull(value) {\n\treturn value === null;\n}\n/** Determine whether a value is `undefined`. */\nfunction isUndefined(value) {\n\treturn value === void 0;\n}\n/** Determine whether a value is defined (neither `null` nor `undefined`). */\nfunction isDefined(value) {\n\treturn value !== null && value !== void 0;\n}\n/** Determine whether a value is a string. */\nfunction isString(value) {\n\treturn typeof value === \"string\";\n}\n/**\n* Determine whether a value is a number.\n*\n* @remarks\n* Includes `NaN` and `±Infinity` — use {@link isFiniteNumber} to exclude them.\n*/\nfunction isNumber(value) {\n\treturn typeof value === \"number\";\n}\n/** Determine whether a value is a finite number (excludes `NaN` and `±Infinity`). */\nfunction isFiniteNumber(value) {\n\treturn typeof value === \"number\" && Number.isFinite(value);\n}\n/** Determine whether a value is a finite integer (excludes `NaN`, `±Infinity`, and fractional numbers). */\nfunction isInteger(value) {\n\treturn Number.isInteger(value);\n}\n/** Determine whether a value is a boolean. */\nfunction isBoolean(value) {\n\treturn typeof value === \"boolean\";\n}\n/** Determine whether a value is exactly `true`. */\nfunction isTrue(value) {\n\treturn value === true;\n}\n/** Determine whether a value is exactly `false`. */\nfunction isFalse(value) {\n\treturn value === false;\n}\n/** Determine whether a value is a bigint. */\nfunction isBigInt(value) {\n\treturn typeof value === \"bigint\";\n}\n/** Determine whether a value is a symbol. */\nfunction isSymbol(value) {\n\treturn typeof value === \"symbol\";\n}\n/** Determine whether a value is callable. */\nfunction isFunction(value) {\n\treturn typeof value === \"function\";\n}\n/** Determine whether a value is a string or `null`. */\nfunction isNullableString(value) {\n\treturn value === null || isString(value);\n}\n/** Determine whether a value is a number or `null` (the number may be `NaN` / `±Infinity`). */\nfunction isNullableNumber(value) {\n\treturn value === null || isNumber(value);\n}\n/** Determine whether a value is a boolean or `null`. */\nfunction isNullableBoolean(value) {\n\treturn value === null || isBoolean(value);\n}\n/** Determine whether a value is a `Date`. */\nfunction isDate(value) {\n\treturn value instanceof Date;\n}\n/** Determine whether a value is a `RegExp`. */\nfunction isRegExp(value) {\n\treturn value instanceof RegExp;\n}\n/** Determine whether a value is an `Error`. */\nfunction isError(value) {\n\treturn value instanceof Error;\n}\n/** Determine whether a value is a native `Promise` (use {@link isPromiseLike} for any thenable). */\nfunction isPromise(value) {\n\treturn value instanceof Promise;\n}\n/**\n* Determine whether a value is promise-like — an object exposing callable\n* `then`, `catch`, and `finally` methods.\n*\n* @remarks\n* Accepts any object with all three methods, not only native `Promise`\n* instances. Use {@link isPromise} when you specifically need `instanceof Promise`.\n*/\nfunction isPromiseLike(value) {\n\tif (!isObject(value)) return false;\n\tconst outcome = attempt(() => {\n\t\tconst thenValue = Reflect.get(value, \"then\");\n\t\tconst catchValue = Reflect.get(value, \"catch\");\n\t\tconst finallyValue = Reflect.get(value, \"finally\");\n\t\treturn isFunction(thenValue) && isFunction(catchValue) && isFunction(finallyValue);\n\t});\n\treturn outcome.success && outcome.value;\n}\n/** Determine whether a value is an `ArrayBuffer`. */\nfunction isArrayBuffer(value) {\n\treturn value instanceof ArrayBuffer;\n}\n/**\n* Determine whether a value is a `SharedArrayBuffer`.\n*\n* @remarks\n* Guards the global existence of `SharedArrayBuffer` first — safe where it is\n* absent or disabled (e.g. a context that is not cross-origin isolated).\n*/\nfunction isSharedArrayBuffer(value) {\n\treturn typeof SharedArrayBuffer !== \"undefined\" && value instanceof SharedArrayBuffer;\n}\n/**\n* Determine whether a value implements the iterable protocol (`Symbol.iterator`).\n*\n* @remarks\n* Strings are explicitly included: a string has a callable `Symbol.iterator`\n* but is not an object, so the generic object path alone would miss it.\n*/\nfunction isIterable(value) {\n\tif (isString(value)) return true;\n\tif (!isObject(value)) return false;\n\tconst outcome = attempt(() => isFunction(Reflect.get(value, Symbol.iterator)));\n\treturn outcome.success && outcome.value;\n}\n/** Determine whether a value implements the async iterable protocol (`Symbol.asyncIterator`). */\nfunction isAsyncIterable(value) {\n\tif (!isObject(value)) return false;\n\tconst outcome = attempt(() => isFunction(Reflect.get(value, Symbol.asyncIterator)));\n\treturn outcome.success && outcome.value;\n}\n/**\n* Determine whether a value is a non-null object.\n*\n* @remarks\n* `true` for arrays, class instances, plain objects, `Map`, `Set`, etc. — use\n* {@link isRecord} when you need a plain-record check.\n*/\nfunction isObject(value) {\n\treturn typeof value === \"object\" && value !== null;\n}\n/**\n* Determine whether a value is a plain record (object literal or null-prototype),\n* not an array or class instance.\n*\n* @remarks\n* Use instead of {@link isObject} to distinguish a plain `{}` /\n* `Object.create(null)` from arrays, `Date`, `Map`, etc. The prototype-chain\n* test is realm-agnostic: rather than comparing against the current realm's\n* `Object.prototype` (which a plain object from another `vm.Context`, iframe,\n* or worker would fail), it accepts any value whose prototype is `null`, OR\n* whose prototype's own prototype is `null` — the shape every plain object\n* has in every realm, since `Object.prototype` itself always sits one step\n* above `null`. Arrays and class instances are still rejected: an array's\n* prototype chain runs through `Array.prototype` before `null`, and a class\n* instance's runs through the class's own prototype. The whole body runs\n* inside `attempt` (AGENTS §14) so a revoked `Proxy` or a hostile\n* `getPrototypeOf` trap cannot escape as a thrown error.\n*/\nfunction isRecord(value) {\n\tconst outcome = attempt(() => {\n\t\tif (!isObject(value) || isArray(value)) return false;\n\t\tconst prototype = Object.getPrototypeOf(value);\n\t\treturn prototype === null || Object.getPrototypeOf(prototype) === null;\n\t});\n\treturn outcome.success && outcome.value;\n}\n/** Determine whether a value is a `Map`. */\nfunction isMap(value) {\n\treturn value instanceof Map;\n}\n/** Determine whether a value is a `Set`. */\nfunction isSet(value) {\n\treturn value instanceof Set;\n}\n/** Determine whether a value is a `WeakMap`. */\nfunction isWeakMap(value) {\n\treturn value instanceof WeakMap;\n}\n/** Determine whether a value is a `WeakSet`. */\nfunction isWeakSet(value) {\n\treturn value instanceof WeakSet;\n}\n/** Determine whether a value is an array. */\nfunction isArray(value) {\n\treturn Array.isArray(value);\n}\n/** Determine whether a value is a `DataView`. */\nfunction isDataView(value) {\n\treturn value instanceof DataView;\n}\n/** Determine whether a value is an `ArrayBufferView` (any typed array or `DataView`). */\nfunction isArrayBufferView(value) {\n\treturn ArrayBuffer.isView(value);\n}\n/** Determine whether a value is an `Int8Array`. */\nfunction isInt8Array(value) {\n\treturn value instanceof Int8Array;\n}\n/** Determine whether a value is a `Uint8Array`. */\nfunction isUint8Array(value) {\n\treturn value instanceof Uint8Array;\n}\n/** Determine whether a value is a `Uint8ClampedArray`. */\nfunction isUint8ClampedArray(value) {\n\treturn value instanceof Uint8ClampedArray;\n}\n/** Determine whether a value is an `Int16Array`. */\nfunction isInt16Array(value) {\n\treturn value instanceof Int16Array;\n}\n/** Determine whether a value is a `Uint16Array`. */\nfunction isUint16Array(value) {\n\treturn value instanceof Uint16Array;\n}\n/** Determine whether a value is an `Int32Array`. */\nfunction isInt32Array(value) {\n\treturn value instanceof Int32Array;\n}\n/** Determine whether a value is a `Uint32Array`. */\nfunction isUint32Array(value) {\n\treturn value instanceof Uint32Array;\n}\n/** Determine whether a value is a `Float32Array`. */\nfunction isFloat32Array(value) {\n\treturn value instanceof Float32Array;\n}\n/** Determine whether a value is a `Float64Array`. */\nfunction isFloat64Array(value) {\n\treturn value instanceof Float64Array;\n}\n/**\n* Determine whether a value is a `BigInt64Array`.\n*\n* @remarks\n* Guards the global existence of `BigInt64Array` first — safe in environments\n* that pre-date the BigInt typed-array additions.\n*/\nfunction isBigInt64Array(value) {\n\treturn typeof BigInt64Array !== \"undefined\" && value instanceof BigInt64Array;\n}\n/**\n* Determine whether a value is a `BigUint64Array`.\n*\n* @remarks\n* Guards the global existence of `BigUint64Array` first — safe in environments\n* that pre-date the BigInt typed-array additions.\n*/\nfunction isBigUint64Array(value) {\n\treturn typeof BigUint64Array !== \"undefined\" && value instanceof BigUint64Array;\n}\n/** Determine whether a value is the empty string `''`. */\nfunction isEmptyString(value) {\n\treturn isString(value) && value.length === 0;\n}\n/** Determine whether a value is an empty array. */\nfunction isEmptyArray(value) {\n\treturn isArray(value) && value.length === 0;\n}\n/** Determine whether a value is an empty plain object (no own string or enumerable symbol keys). */\nfunction isEmptyObject(value) {\n\tif (!isRecord(value)) return false;\n\treturn Object.keys(value).length === 0 && enumerableSymbolCount(value) === 0;\n}\n/** Determine whether a value is an empty `Map`. */\nfunction isEmptyMap(value) {\n\treturn value instanceof Map && value.size === 0;\n}\n/** Determine whether a value is an empty `Set`. */\nfunction isEmptySet(value) {\n\treturn value instanceof Set && value.size === 0;\n}\n/** Determine whether a value is a non-empty string (at least one character). */\nfunction isNonEmptyString(value) {\n\treturn isString(value) && value.length > 0;\n}\n/** Determine whether a value is a non-empty array (at least one element). */\nfunction isNonEmptyArray(value) {\n\treturn isArray(value) && value.length > 0;\n}\n/** Determine whether a value is a non-empty plain object (at least one own string or enumerable symbol key). */\nfunction isNonEmptyObject(value) {\n\tif (!isRecord(value)) return false;\n\treturn Object.keys(value).length > 0 || enumerableSymbolCount(value) > 0;\n}\n/** Determine whether a value is a non-empty `Map` (at least one entry). */\nfunction isNonEmptyMap(value) {\n\treturn value instanceof Map && value.size > 0;\n}\n/** Determine whether a value is a non-empty `Set` (at least one element). */\nfunction isNonEmptySet(value) {\n\treturn value instanceof Set && value.size > 0;\n}\n/** Determine whether a value is a function that declares zero parameters (`Function.length === 0`). */\nfunction isZeroArg(value) {\n\treturn isFunction(value) && value.length === 0;\n}\n/**\n* Determine whether a value is a native `async function`.\n*\n* @remarks\n* Uses `constructor.name === 'AsyncFunction'` — not `instanceof`, which is\n* unreliable across realms. The `?.` keeps the guard total (§14): a function\n* whose `constructor` was nulled yields `undefined`, never a thrown `null.name`.\n*/\nfunction isAsyncFunction(value) {\n\treturn isFunction(value) && value.constructor?.name === \"AsyncFunction\";\n}\n/** Determine whether a value is a generator function (`function*`). */\nfunction isGeneratorFunction(value) {\n\treturn isFunction(value) && value.constructor?.name === \"GeneratorFunction\";\n}\n/** Determine whether a value is an async generator function (`async function*`). */\nfunction isAsyncGeneratorFunction(value) {\n\treturn isFunction(value) && value.constructor?.name === \"AsyncGeneratorFunction\";\n}\n/** Determine whether a value is a zero-argument async function. */\nfunction isZeroArgAsync(value) {\n\treturn isZeroArg(value) && isAsyncFunction(value);\n}\n/** Determine whether a value is a zero-argument generator function. */\nfunction isZeroArgGenerator(value) {\n\treturn isZeroArg(value) && isGeneratorFunction(value);\n}\n/** Determine whether a value is a zero-argument async generator function. */\nfunction isZeroArgAsyncGenerator(value) {\n\treturn isZeroArg(value) && isAsyncGeneratorFunction(value);\n}\n/**\n* Determine whether a value can be used as a `new`-target constructor.\n*\n* @remarks\n* Probes with `Reflect.construct(String, [], value)`: a real constructor\n* succeeds, while arrow functions, plain functions, and non-functions throw\n* and yield `false`. Never throws. Backs the `instanceOf` combinator.\n*/\nfunction isConstructor(value) {\n\tif (!isFunction(value)) return false;\n\ttry {\n\t\tReflect.construct(String, [], value);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n/**\n* Determine whether a value is a cycle-safe JSON value.\n*\n* @remarks\n* Total guard: never throws, returns `false` for cycles, functions, `Date`\n* instances, class instances, `NaN`, and `±Infinity`. Arrays and plain records\n* are walked with an ancestor set so recursive input fails instead of hanging.\n* The whole walk runs inside `attempt` (AGENTS §14): a hostile getter on a\n* record property, or a revoked `Proxy` anywhere in the structure, is caught\n* and yields `false` instead of escaping as a thrown error.\n*\n* @param value - The value to test\n* @returns `true` when the value has a JSON representation\n*\n* @example\n* ```ts\n* isJSONValue({ nested: [1, 'x', null] }) // true\n* isJSONValue(Number.NaN) // false\n* ```\n*/\nfunction isJSONValue(value) {\n\tconst ancestors = /* @__PURE__ */ new WeakSet();\n\tconst check = (entry) => {\n\t\tif (entry === null || isString(entry) || isBoolean(entry) || isFiniteNumber(entry)) return true;\n\t\tif (Array.isArray(entry)) {\n\t\t\tif (ancestors.has(entry)) return false;\n\t\t\tancestors.add(entry);\n\t\t\tconst valid = entry.every(check);\n\t\t\tancestors.delete(entry);\n\t\t\treturn valid;\n\t\t}\n\t\tif (!isRecord(entry)) return false;\n\t\tif (ancestors.has(entry)) return false;\n\t\tancestors.add(entry);\n\t\tconst valid = Object.values(entry).every(check);\n\t\tancestors.delete(entry);\n\t\treturn valid;\n\t};\n\tconst outcome = attempt(() => check(value));\n\treturn outcome.success && outcome.value;\n}\n/**\n* Determine whether a value is a primitive JSON value.\n*\n* @remarks\n* The flat leaf of any JSON document: `null`, a string, a **finite** number, or\n* a boolean. Uses {@link isFiniteNumber} (not {@link isNumber}) because real JSON\n* carries no `NaN` / `±Infinity` — `JSON.stringify(NaN)` is `'null'`.\n*\n* The recursive {@link isJSONValue} guard is shipped and stays total with\n* cycle-safe walking. Dedicated `isJSONObject` / `isJSONSchema` validators and\n* the broad `JSONSchemaDefinition` remain omitted; compose narrower shapes with\n* the combinators and gate untrusted strings with `parseJSON` / `parseJSONAs`.\n*\n* @param value - The value to test\n* @returns `true` when `value` is `null`, a string, a finite number, or a boolean\n*\n* @example\n* ```ts\n* isJSONPrimitive(null) // true\n* isJSONPrimitive('hi') // true\n* isJSONPrimitive(42) // true\n* isJSONPrimitive(Number.NaN) // false — not representable in JSON\n* isJSONPrimitive({}) // false\n* ```\n*/\nfunction isJSONPrimitive(value) {\n\treturn isNull(value) || isString(value) || isFiniteNumber(value) || isBoolean(value);\n}\n//#endregion\n//#region src/core/helpers.ts\n/**\n* Invoke a callback and capture its outcome as a {@link Result}, never letting\n* a throw escape.\n*\n* @remarks\n* The single sanctioned never-throw boundary for the guards (AGENTS §14). The\n* `whereOf`, `lazyOf`, and `transformOf` combinators invoke caller-supplied\n* callbacks *inside* a guard body, yet a guard must NEVER throw — it returns a\n* `boolean`. This converts a throwing callback into a `Failure` so the\n* surrounding guard can treat it as a non-match instead of propagating the\n* exception, written once and shared rather than copy-pasted as ad-hoc\n* `try`/`catch`.\n*\n* @param callback - The callback to invoke with no arguments\n* @returns A `Success` carrying the return value, or a `Failure` carrying the\n* thrown reason normalised to an `Error`\n*\n* @example\n* ```ts\n* const outcome = attempt(() => predicate(value))\n* return outcome.success && outcome.value\n* ```\n*/\nfunction attempt(callback) {\n\ttry {\n\t\treturn {\n\t\t\tsuccess: true,\n\t\t\tvalue: callback()\n\t\t};\n\t} catch (reason) {\n\t\tif (reason instanceof Error) return {\n\t\t\tsuccess: false,\n\t\t\terror: reason\n\t\t};\n\t\tlet message = \"Unknown thrown value\";\n\t\ttry {\n\t\t\tmessage = String(reason);\n\t\t} catch {}\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: new Error(message)\n\t\t};\n\t}\n}\n/**\n* Resolve a (possibly nested) field value from a record by a key or key path.\n*\n* @remarks\n* A single `string` is ONE key (never split on `.`, so dotted keys are safe); a\n* string array descends left-to-right through nested objects. Intermediates may\n* be any object — records, class instances, or arrays indexed by string. Returns\n* `undefined` the moment a segment is missing or lands on a non-object, so the\n* lookup is total — even against a hostile getter or Proxy trap that throws on\n* read, contained via {@link attempt} so the throw never escapes.\n*\n* @param record - The source record\n* @param path - A property key, or a key path descending into nested objects\n* @returns The resolved value, or `undefined`\n*\n* @example\n* ```ts\n* resolveField({ user: { name: 'Ada' } }, ['user', 'name']) // 'Ada'\n* resolveField({ 'a.b': 1 }, 'a.b') // 1 (one key)\n* resolveField({ a: 1 }, ['a', 'b']) // undefined\n* ```\n*/\nfunction resolveField(record, path) {\n\tconst keys = isString(path) ? [path] : path;\n\tlet current = record;\n\tfor (const key of keys) {\n\t\tif (!isObject(current)) return void 0;\n\t\tconst container = current;\n\t\tconst outcome = attempt(() => Reflect.get(container, key));\n\t\tif (!outcome.success) return void 0;\n\t\tcurrent = outcome.value;\n\t}\n\treturn current;\n}\n/**\n* Build a deterministic pseudo-random source seeded from a single number.\n*\n* @remarks\n* A mulberry32 generator — the same seed always yields the same sequence, so\n* generated seed data is reproducible across runs. Used as the default random\n* source for {@link compileGenerator}, seeded from the wall clock so casual\n* callers still get varied output without passing a source themselves.\n*\n* @param seed - The seed for the sequence\n* @returns A {@link RandomFunction} returning values in `[0, 1)`\n*\n* @example\n* ```ts\n* const random = seededRandom(42)\n* random() // always the same first value for seed 42\n* ```\n*/\nfunction seededRandom(seed) {\n\tlet state = seed >>> 0;\n\treturn () => {\n\t\tstate = state + 1831565813 >>> 0;\n\t\tlet t = state;\n\t\tt = Math.imul(t ^ t >>> 15, t | 1);\n\t\tt ^= t + Math.imul(t ^ t >>> 7, t | 61);\n\t\treturn ((t ^ t >>> 14) >>> 0) / 4294967296;\n\t};\n}\n/**\n* Count the enumerable own-symbol keys on a value.\n*\n* @remarks\n* String keys are ignored — only `Object.getOwnPropertySymbols` entries whose\n* descriptor is `enumerable` are counted. Backs the object-emptiness guards\n* (`isEmptyObject` / `isNonEmptyObject`) so a record keyed only by an\n* enumerable symbol is not mistaken for empty.\n*\n* @param value - The object to inspect\n* @returns The number of enumerable own-symbol keys\n*\n* @example\n* ```ts\n* const flag = Symbol('flag')\n* enumerableSymbolCount(Object.defineProperty({}, flag, { value: 1, enumerable: true })) // 1\n* enumerableSymbolCount({}) // 0\n* ```\n*/\nfunction enumerableSymbolCount(value) {\n\tlet count = 0;\n\tfor (const symbol of Object.getOwnPropertySymbols(value)) if (Object.getOwnPropertyDescriptor(value, symbol)?.enumerable) count += 1;\n\treturn count;\n}\n/**\n* Narrow a compiled {@link JSONSchema} down to the open `Readonly<Record<string, unknown>>` shape\n* tool definitions advertise as `parameters` — through the {@link isRecord} boundary guard, never\n* an assertion (AGENTS §14).\n*\n* @remarks\n* A `JSONSchema` is the closed contract-compiler fragment (it has no index signature), whereas a\n* tool advertises its `parameters` as an open record. The two are structurally compatible but not\n* assignable, so the schema crosses that boundary through `isRecord` — a compiled contract schema\n* is always a record, so the guard passes; the `undefined` fallback only satisfies the type's\n* optionality. This is the single sanctioned narrowing from a compiled contract schema to the open\n* tool-parameters record, so the crossing lives once rather than being copy-pasted per call site.\n*\n* @param schema - The compiled JSON Schema (a contract's `schema`)\n* @returns The schema as the open tool-parameters record, or `undefined` when it is not a record\n*\n* @example\n* ```ts\n* import { createContract, schemaToParameters } from '@src/core'\n*\n* const contract = createContract(shape)\n* const parameters = schemaToParameters(contract.schema) // the open record a tool advertises\n* ```\n*/\nfunction schemaToParameters(schema) {\n\treturn isRecord(schema) ? schema : void 0;\n}\n//#endregion\n//#region src/core/combinators.ts\nfunction arrayOf(elementGuard) {\n\treturn (value) => {\n\t\tif (!isArray(value)) return false;\n\t\tconst outcome = attempt(() => value.every(elementGuard));\n\t\treturn outcome.success && outcome.value;\n\t};\n}\nfunction tupleOf(...guards) {\n\treturn (value) => {\n\t\tif (!isArray(value)) return false;\n\t\tconst outcome = attempt(() => {\n\t\t\tif (value.length !== guards.length) return false;\n\t\t\tfor (let index = 0; index < guards.length; index += 1) {\n\t\t\t\tconst guard = guards[index];\n\t\t\t\tif (!guard?.(value[index])) return false;\n\t\t\t}\n\t\t\treturn true;\n\t\t});\n\t\treturn outcome.success && outcome.value;\n\t};\n}\n/**\n* Build a guard that accepts values identical (via `Object.is`) to one of the\n* provided literal primitives.\n*\n* @example\n* ```ts\n* const isRole = literalOf('admin', 'member', 'guest')\n* isRole('admin') // true\n* isRole('owner') // false\n* ```\n*/\nfunction literalOf(...literals) {\n\treturn (value) => literals.some((literal) => Object.is(literal, value));\n}\n/**\n* Build a guard that accepts instances of the provided constructor.\n*\n* @remarks\n* Verifies that `ctor` is a real constructor (via {@link isConstructor}) first,\n* so passing an arrow function does not silently produce a broken guard.\n*\n* @example\n* ```ts\n* const isDateValue = instanceOf(Date)\n* isDateValue(new Date()) // true\n* isDateValue({}) // false\n* ```\n*/\nfunction instanceOf(ctor) {\n\treturn (value) => isConstructor(ctor) && isObject(value) && value instanceof ctor;\n}\n/**\n* Build a guard from a native `enum` or any object whose values are strings or\n* numbers.\n*\n* @example\n* ```ts\n* enum Direction { Up = 'up', Down = 'down' }\n* const isDirection = enumOf(Direction)\n* isDirection('up') // true\n* isDirection('left') // false\n* ```\n*/\nfunction enumOf(enumeration) {\n\tconst values = new Set(Object.values(enumeration));\n\treturn (value) => (isString(value) || isNumber(value)) && values.has(value);\n}\nfunction setOf(elementGuard) {\n\treturn (value) => {\n\t\tif (!isSet(value)) return false;\n\t\tconst outcome = attempt(() => {\n\t\t\tfor (const entry of value) if (!elementGuard(entry)) return false;\n\t\t\treturn true;\n\t\t});\n\t\treturn outcome.success && outcome.value;\n\t};\n}\nfunction mapOf(keyGuard, valueGuard) {\n\treturn (value) => {\n\t\tif (!isMap(value)) return false;\n\t\tconst outcome = attempt(() => {\n\t\t\tfor (const [key, entryValue] of value) if (!keyGuard(key) || !valueGuard(entryValue)) return false;\n\t\t\treturn true;\n\t\t});\n\t\treturn outcome.success && outcome.value;\n\t};\n}\n/**\n* Build a guard that accepts plain records matching a guard shape.\n*\n* @remarks\n* Three calling modes depending on the `optional` argument:\n* - **No `optional`** — all shape keys required; extra keys rejected.\n* - **`optional: K[]`** — the listed keys are optional; all others required.\n* - **`optional: true`** — every shape key is optional.\n*\n* Key presence is tested with `Object.hasOwn`, so a shape key satisfied only by\n* an inherited prototype member (`toString`, `constructor`, …) counts as absent.\n* A non-object / `null` / array input returns `false` rather than throwing. The\n* extra-key check only inspects `Object.keys` (string keys), so an extra\n* enumerable SYMBOL key is never rejected — intentional, for JSON fidelity, and\n* matches the compiled guard.\n*\n* @example\n* ```ts\n* const isUser = recordOf({ name: isString, age: isNumber })\n* isUser({ name: 'Ada', age: 36 }) // true\n* isUser({ name: 'Ada' }) // false — age missing\n*\n* const isPartial = recordOf({ name: isString, age: isNumber }, ['age'])\n* isPartial({ name: 'Ada' }) // true\n* ```\n*/\nfunction recordOf(shape, optional) {\n\tconst allowed = /* @__PURE__ */ new Set();\n\tfor (const key in shape) if (Object.prototype.hasOwnProperty.call(shape, key)) allowed.add(key);\n\tconst optionalSet = new Set(optional === true ? [...allowed] : isArray(optional) ? optional.map((key) => String(key)) : []);\n\treturn (value) => {\n\t\tif (!isRecord(value)) return false;\n\t\tconst outcome = attempt(() => {\n\t\t\tfor (const key of Object.keys(value)) if (!allowed.has(key)) return false;\n\t\t\tfor (const key in shape) {\n\t\t\t\tif (!Object.prototype.hasOwnProperty.call(shape, key)) continue;\n\t\t\t\tconst present = Object.hasOwn(value, key);\n\t\t\t\tif (!optionalSet.has(key) && !present) return false;\n\t\t\t\tif (present) {\n\t\t\t\t\tconst guard = shape[key];\n\t\t\t\t\tif (!guard(value[key])) return false;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t});\n\t\treturn outcome.success && outcome.value;\n\t};\n}\nfunction iterableOf(elementGuard) {\n\treturn (value) => {\n\t\tif (!isIterable(value)) return false;\n\t\tconst outcome = attempt(() => {\n\t\t\tfor (const entry of value) if (!elementGuard(entry)) return false;\n\t\t\treturn true;\n\t\t});\n\t\treturn outcome.success && outcome.value;\n\t};\n}\n/**\n* Build a guard that accepts values that are own keys of the provided object.\n*\n* @remarks\n* Membership is tested with `Object.hasOwn`, so inherited prototype-chain keys\n* (`toString`, `constructor`, …) are rejected. An own property that shadows a\n* prototype name is accepted.\n*\n* @example\n* ```ts\n* const COLORS = { red: '#f00', green: '#0f0', blue: '#00f' } as const\n* const isColorKey = keyOf(COLORS)\n* isColorKey('red') // true\n* isColorKey('purple') // false\n* isColorKey('toString') // false — inherited, not an own key\n* ```\n*/\nfunction keyOf(value) {\n\treturn (entry) => (isString(entry) || isSymbol(entry) || isNumber(entry)) && Object.hasOwn(value, entry);\n}\n/**\n* Build a new guard shape by keeping only the listed keys — the structural\n* equivalent of `Pick<T, K>`. Produces a shape for {@link recordOf}, not a guard.\n*\n* @example\n* ```ts\n* const full = { name: isString, age: isNumber, role: isString }\n* const isName = recordOf(pickOf(full, ['name']))\n* isName({ name: 'Ada' }) // true\n* ```\n*/\nfunction pickOf(shape, keys) {\n\tconst result = Object.create(null);\n\tfor (const key of keys) if (Object.prototype.hasOwnProperty.call(shape, key)) result[key] = shape[key];\n\treturn result;\n}\n/**\n* Build a new guard shape by removing the listed keys — the structural\n* equivalent of `Omit<T, K>`. Produces a shape for {@link recordOf}, not a guard.\n*\n* @example\n* ```ts\n* const full = { name: isString, age: isNumber, role: isString }\n* const isPublic = recordOf(omitOf(full, ['role']))\n* isPublic({ name: 'Ada', age: 36 }) // true\n* ```\n*/\nfunction omitOf(shape, keys) {\n\tconst skipped = /* @__PURE__ */ new Set();\n\tfor (const key of keys) skipped.add(key);\n\tconst result = Object.create(null);\n\tfor (const key in shape) {\n\t\tif (!Object.prototype.hasOwnProperty.call(shape, key)) continue;\n\t\tif (!skipped.has(key)) result[key] = shape[key];\n\t}\n\treturn result;\n}\nfunction andOf(left, right) {\n\treturn (value) => left(value) && right(value);\n}\nfunction orOf(left, right) {\n\treturn (value) => left(value) || right(value);\n}\n/**\n* Negate a guard or predicate — passes when `guard` returns `false`.\n*\n* @remarks\n* Typed as `Guard<unknown>` because `Exclude<unknown, T>` is not useful; use\n* {@link complementOf} when you need the narrowed `Exclude<TBase, TExcluded>`.\n*\n* @example\n* ```ts\n* const isNotNull = notOf(isNull)\n* ```\n*/\nfunction notOf(guard) {\n\treturn (value) => !guard(value);\n}\n/**\n* Build a guard for `Exclude<TBase, TExcluded>` — accepts values that pass\n* `base` but not `excluded`.\n*\n* @example\n* ```ts\n* const isNonEmpty = complementOf(isString, isEmptyString)\n* isNonEmpty('hi') // true\n* isNonEmpty('') // false\n* ```\n*/\nfunction complementOf(base, excluded) {\n\treturn (value) => {\n\t\tif (!base(value)) return false;\n\t\treturn !excluded(value);\n\t};\n}\nfunction unionOf(...guards) {\n\treturn (value) => guards.some((guard) => guard(value));\n}\nfunction intersectionOf(...guards) {\n\treturn (value) => guards.every((guard) => guard(value));\n}\nfunction whereOf(base, predicate) {\n\treturn (value) => {\n\t\tif (!base(value)) return false;\n\t\tconst outcome = attempt(() => predicate(value));\n\t\treturn outcome.success && outcome.value;\n\t};\n}\n/**\n* Defer guard creation until first use by calling `thunk()` on every\n* invocation.\n*\n* @remarks\n* `thunk` is called on every guard call, not cached — this lets it close over a\n* binding assigned *after* `lazyOf` is called, the primary use case for\n* self-referential recursive guards. Per §14 a throw from `thunk` (or the guard\n* it resolves to) is contained and reported as a non-match.\n*\n* A recursive guard built this way has no cycle/depth detection: a cyclic or\n* pathologically deep input is stack-bounded — the overflow is contained and the\n* guard returns `false` rather than throwing, but it is not validated correctly\n* past that bound.\n*\n* @example\n* ```ts\n* type Tree = { value: number; children: Tree[] }\n* let isTree: Guard<Tree>\n* isTree = recordOf({ value: isNumber, children: arrayOf(lazyOf(() => isTree)) })\n* ```\n*/\nfunction lazyOf(thunk) {\n\treturn (value) => {\n\t\tconst outcome = attempt(() => thunk()(value));\n\t\treturn outcome.success && outcome.value;\n\t};\n}\nfunction transformOf(base, project, target) {\n\treturn (value) => {\n\t\tif (!base(value)) return false;\n\t\tconst outcome = attempt(() => project(value));\n\t\treturn outcome.success && target(outcome.value);\n\t};\n}\n/**\n* Build a guard that accepts finite numbers within an inclusive `[min, max]`\n* range.\n*\n* @remarks\n* Refines {@link isFiniteNumber} with the bound comparison, so `NaN` /\n* `±Infinity` are rejected before any comparison runs. An absent bound never\n* constrains that side. Reused for a number's own value AND, applied to a\n* `.length`, for string and array length refinements — the single source of the\n* bound logic shared by the compiled guard and parser (compilers.ts).\n*\n* @example\n* ```ts\n* const inRange = boundsOf(1, 5)\n* inRange(3) // true\n* inRange(0) // false — below min\n* inRange(6) // false — above max\n*\n* const atLeastTwo = boundsOf(2)\n* atLeastTwo(2) // true — unbounded above\n* ```\n*/\nfunction boundsOf(min, max) {\n\treturn whereOf(isFiniteNumber, (value) => (min === void 0 || value >= min) && (max === void 0 || value <= max));\n}\n/**\n* Build a guard that accepts strings matching a regular expression.\n*\n* @example\n* ```ts\n* const isHex = matchOf(/^[0-9a-f]+$/)\n* isHex('1a2f') // true\n* isHex('xyz') // false\n* ```\n*/\nfunction matchOf(pattern) {\n\treturn whereOf(isString, (value) => pattern.test(value));\n}\n/**\n* Build a guard that accepts strings satisfying optional length and pattern\n* refinements — `min` / `max` length and a `pattern`.\n*\n* @remarks\n* Composes {@link isString} with {@link boundsOf} on the string's `.length` and\n* an inline `pattern.test` (the same refinement {@link matchOf} performs). When all three options are absent it returns\n* the bare {@link isString} guard (the unconstrained fast path), so an\n* unrefined string leaf pays no wrapping cost. The single source of the string\n* refinement shared by the compiled guard and parser (compilers.ts).\n*\n* @example\n* ```ts\n* const isSlug = stringOf({ min: 1, max: 32, pattern: /^[a-z-]+$/ })\n* isSlug('hello-world') // true\n* isSlug('') // false — below min\n* isSlug('Hello') // false — pattern miss\n*\n* stringOf() // identical to isString\n* ```\n*/\nfunction stringOf(options) {\n\tconst min = options?.min;\n\tconst max = options?.max;\n\tconst pattern = options?.pattern;\n\tif (min === void 0 && max === void 0 && pattern === void 0) return isString;\n\tconst withinLength = boundsOf(min, max);\n\treturn whereOf(isString, (value) => withinLength(value.length) && (pattern === void 0 || pattern.test(value)));\n}\n/**\n* Extend a guard to also allow `null`.\n*\n* @example\n* ```ts\n* const isNullableString = nullableOf(isString)\n* isNullableString('hi') // true\n* isNullableString(null) // true\n* isNullableString(42) // false\n* ```\n*/\nfunction nullableOf(guard) {\n\treturn (value) => value === null || guard(value);\n}\n/**\n* Extend a guard to also allow `undefined` — the optional counterpart of\n* {@link nullableOf}.\n*\n* @example\n* ```ts\n* const isOptionalString = optionalOf(isString)\n* isOptionalString('hi') // true\n* isOptionalString(undefined) // true\n* isOptionalString(null) // false\n* ```\n*/\nfunction optionalOf(guard) {\n\treturn (value) => value === void 0 || guard(value);\n}\n//#endregion\n//#region src/core/parsers.ts\n/**\n* Parse an unknown value to a string.\n*\n* @remarks\n* A string is returned unchanged; a finite number is coerced to its decimal\n* string (`42` → `'42'`). `NaN`, `±Infinity`, and every other type → `undefined`.\n*\n* @param value - The value to parse\n* @returns A string, or `undefined`\n*/\nfunction parseString(value) {\n\tif (isString(value)) return value;\n\tif (isFiniteNumber(value)) return String(value);\n}\n/**\n* Parse an unknown value to a finite number.\n*\n* @remarks\n* A finite number is returned unchanged; a non-blank numeric string is parsed\n* via `Number(...)`. `NaN`, `±Infinity`, blank/non-numeric strings, and every\n* other type → `undefined`.\n*\n* @param value - The value to parse\n* @returns A finite number, or `undefined`\n*/\nfunction parseNumber(value) {\n\tif (typeof value === \"number\") return Number.isFinite(value) ? value : void 0;\n\tif (isString(value)) {\n\t\tif (value.trim() === \"\") return void 0;\n\t\tconst parsed = Number(value);\n\t\treturn Number.isFinite(parsed) ? parsed : void 0;\n\t}\n}\n/**\n* Parse an unknown value to a finite integer.\n*\n* @remarks\n* Accepts whatever {@link parseNumber} accepts, then requires the result to have\n* no fractional part. `3.14` / `'3.14'` → `undefined`.\n*\n* @param value - The value to parse\n* @returns A finite integer, or `undefined`\n*/\nfunction parseInteger(value) {\n\tconst parsed = parseNumber(value);\n\tif (parsed === void 0) return void 0;\n\treturn Number.isInteger(parsed) ? parsed : void 0;\n}\n/**\n* Parse an unknown value to a boolean.\n*\n* @remarks\n* A boolean is returned unchanged. The strings `'true'` / `'false'` / `'1'` /\n* `'0'` and the numbers `1` / `0` coerce to the matching boolean. Everything\n* else → `undefined`.\n*\n* @param value - The value to parse\n* @returns A boolean, or `undefined`\n*/\nfunction parseBoolean(value) {\n\tif (typeof value === \"boolean\") return value;\n\tif (value === \"true\" || value === \"1\" || value === 1) return true;\n\tif (value === \"false\" || value === \"0\" || value === 0) return false;\n}\n/**\n* Parse an unknown value to `null`.\n*\n* @remarks\n* A successful parse returns `null` itself — distinct from the `undefined`\n* failure sentinel every other parser in this file uses. Only `null` passes;\n* every other value (including `undefined`) → `undefined`.\n*\n* @param value - The value to parse\n* @returns `null` on a successful parse, or `undefined`\n*/\nfunction parseNull(value) {\n\treturn isNull(value) ? value : void 0;\n}\n/**\n* Parse an unknown value to a plain record — the input reference, never cloned.\n*\n* @param value - The value to parse\n* @returns The record, or `undefined`\n*/\nfunction parseRecord(value) {\n\treturn isRecord(value) ? value : void 0;\n}\n/**\n* Parse an unknown value to an array — the input reference, never cloned —\n* optionally guarding every element.\n*\n* @remarks\n* Without a `guard`, element types are NOT verified; let `T` default to\n* `unknown` rather than asserting a specific element type.\n*\n* @param value - The value to parse\n* @param guard - Optional element guard\n* @returns The array, or `undefined`\n*/\nfunction parseArray(value, guard) {\n\tif (!isArray(value)) return void 0;\n\tif (guard !== void 0 && !value.every(guard)) return void 0;\n\treturn value;\n}\n/**\n* Parse an unknown value to a cycle-safe JSON value — the input reference,\n* never cloned.\n*\n* @remarks\n* Unlike {@link parseRecord} / {@link parseArray}, this is a DEEP gate: it\n* walks the entire tree via {@link isJSONValue} rather than checking only the\n* top-level shape. That walk is cycle-safe and total (never throws) because\n* `isJSONValue` runs its own probe inside a guard, so an adversarial\n* structure (a cycle, a hostile getter) yields `undefined` instead of hanging\n* or throwing.\n*\n* @param value - The value to parse\n* @returns The value, or `undefined` when it is not a valid JSON value\n*/\nfunction parseJSONValue(value) {\n\treturn isJSONValue(value) ? value : void 0;\n}\n/**\n* Parse an unknown value as one of the allowed literal primitives.\n*\n* @remarks\n* Pairs with {@link literalOf} — both match by `Object.is`, so the\n* `parseEnum ↔ literalOf(...allowed)` pairing covers every literal primitive\n* (string, number, or boolean), not only strings. Matching is identity, never\n* cross-type coercion: `parseEnum('1', [1])` stays `undefined`.\n*\n* @param value - The value to parse\n* @param allowed - The permitted literal values\n* @returns The matched literal (by identity), or `undefined`\n*/\nfunction parseEnum(value, allowed) {\n\tfor (const option of allowed) if (Object.is(value, option)) return option;\n}\n/**\n* Read and parse a string field from a record by key or nested key path.\n*\n* @param record - The source record\n* @param path - A property key, or a key path descending into nested objects\n* @returns A string, or `undefined`\n*/\nfunction parseStringField(record, path) {\n\treturn parseString(resolveField(record, path));\n}\n/**\n* Read and parse a finite-number field from a record by key or nested key path.\n*\n* @param record - The source record\n* @param path - A property key, or a key path descending into nested objects\n* @returns A finite number, or `undefined`\n*/\nfunction parseNumberField(record, path) {\n\treturn parseNumber(resolveField(record, path));\n}\n/**\n* Read and parse a finite-integer field from a record by key or nested key path.\n*\n* @param record - The source record\n* @param path - A property key, or a key path descending into nested objects\n* @returns A finite integer, or `undefined`\n*/\nfunction parseIntegerField(record, path) {\n\treturn parseInteger(resolveField(record, path));\n}\n/**\n* Read and parse a boolean field from a record by key or nested key path.\n*\n* @param record - The source record\n* @param path - A property key, or a key path descending into nested objects\n* @returns A boolean, or `undefined`\n*/\nfunction parseBooleanField(record, path) {\n\treturn parseBoolean(resolveField(record, path));\n}\n/**\n* Read and parse a `null` field from a record by key or nested key path.\n*\n* @remarks\n* A successful parse returns `null` itself — distinct from the `undefined`\n* failure sentinel, which also covers a missing field.\n*\n* @param record - The source record\n* @param path - A property key, or a key path descending into nested objects\n* @returns `null` on a successful parse, or `undefined`\n*/\nfunction parseNullField(record, path) {\n\treturn parseNull(resolveField(record, path));\n}\n/**\n* Read and parse a nested record field from a record by key or nested key path.\n*\n* @param record - The source record\n* @param path - A property key, or a key path descending into nested objects\n* @returns A plain record, or `undefined`\n*/\nfunction parseRecordField(record, path) {\n\treturn parseRecord(resolveField(record, path));\n}\n/**\n* Read and parse an array field from a record by key or nested key path,\n* optionally guarding elements.\n*\n* @param record - The source record\n* @param path - A property key, or a key path descending into nested objects\n* @param guard - Optional element guard\n* @returns An array, or `undefined`\n*/\nfunction parseArrayField(record, path, guard) {\n\treturn parseArray(resolveField(record, path), guard);\n}\n/**\n* Read and parse an enum field from a record by key or nested key path.\n*\n* @param record - The source record\n* @param path - A property key, or a key path descending into nested objects\n* @param allowed - The permitted literal values\n* @returns The matched literal, or `undefined`\n*/\nfunction parseEnumField(record, path, allowed) {\n\treturn parseEnum(resolveField(record, path), allowed);\n}\n/**\n* Read and parse a JSON-value field from a record by key or nested key path.\n*\n* @remarks\n* Deep-gates the field's whole subtree via {@link parseJSONValue} — see that\n* function's remarks for why this differs from the shallow\n* {@link parseRecordField} / {@link parseArrayField}.\n*\n* @param record - The source record\n* @param path - A property key, or a key path descending into nested objects\n* @returns The value, or `undefined`\n*/\nfunction parseJSONValueField(record, path) {\n\treturn parseJSONValue(resolveField(record, path));\n}\n/**\n* Parse a JSON string, returning `undefined` instead of throwing.\n*\n* @remarks\n* The safe boundary for untrusted JSON text: a malformed string yields\n* `undefined`, never an exception. Returns `unknown` — a successful parse proves\n* nothing about shape, so narrow the result with a guard (or use\n* {@link parseJSONAs}). A large document is not walked here; parsing is shallow\n* and lazy validation is the caller's to compose.\n*\n* @param value - The JSON string to parse\n* @returns The parsed value, or `undefined` when `value` is not valid JSON\n*/\nfunction parseJSON(value) {\n\ttry {\n\t\treturn JSON.parse(value);\n\t} catch {\n\t\treturn;\n\t}\n}\n/**\n* Parse a JSON string and validate the result against a guard.\n*\n* @remarks\n* The lazy, safe path from an untrusted string to a typed `T`: parse, then check\n* the parsed value with the guard you bring — typically one composed from the\n* combinators (`recordOf`, `arrayOf`, …). Only the shape the guard inspects is\n* validated, so a large document is never walked in full unless the guard does.\n*\n* @param value - The JSON string to parse\n* @param guard - The guard for the expected shape\n* @returns The parsed value when it satisfies `guard`, otherwise `undefined`\n*\n* @example\n* ```ts\n* const isConfig = recordOf({ host: isString, tags: arrayOf(isString) })\n* parseJSONAs('{\"host\":\"localhost\",\"tags\":[\"a\"]}', isConfig) // { host: 'localhost', tags: ['a'] }\n* parseJSONAs('{\"host\":\"localhost\"}', isConfig) // undefined — guard fails\n* parseJSONAs('not json', isConfig) // undefined — never throws\n* ```\n*/\nfunction parseJSONAs(value, guard) {\n\tconst parsed = parseJSON(value);\n\tif (parsed === void 0) return void 0;\n\treturn guard(parsed) ? parsed : void 0;\n}\n//#endregion\n//#region src/core/compilers.ts\n/**\n* Validate that a {@link ContractShape} tree is well-formed — a pure recursive\n* prepass run before compilation.\n*\n* @remarks\n* Fail-fast, per AGENTS §12: a malformed shape is a programmer error, so this\n* throws a plain `Error` immediately rather than surfacing as a silently-wrong\n* guard, parser, schema, or generator later. Checks, recursively:\n*\n* - An {@link OptionalShape} is only legal as a direct object-property value —\n* `optionalShape` wrapping an array item, a union variant, another\n* optional/nullable's inner shape, `additionalProperties`, or the top-level\n* shape all throw. An object property IS the one legal placement: its value\n* is unwrapped to `.inner` before recursing, so `.inner` itself is validated\n* as a normal (non-optional-wrapping) shape.\n* - A {@link UnionShape} needs at least one variant; a {@link LiteralShape}\n* needs at least one value and rejects non-finite (`NaN` / `Infinity` /\n* `-Infinity`) number values.\n* - A bounded {@link StringShape} / {@link NumberShape} / {@link ArrayShape}\n* needs `min <= max` when both are set.\n* - An integer {@link NumberShape} (`integer: true`) needs a non-empty integer\n* range: `Math.ceil(min ?? -Infinity) <= Math.floor(max ?? Infinity)`.\n* - `null` / `json` / `raw` / `boolean` are always-valid leaves. Recursion\n* continues into array items, object properties (and `additionalProperties`\n* when it is a shape), union variants, and optional/nullable inner shapes.\n*\n* @param shape - The shape to validate\n* @throws {Error} When the shape is malformed\n*/\nfunction validateShape(shape) {\n\tswitch (shape.type) {\n\t\tcase \"string\":\n\t\t\tif (shape.min !== void 0 && shape.max !== void 0 && shape.min > shape.max) throw new Error(\"validateShape: a string shape has min greater than max\");\n\t\t\treturn;\n\t\tcase \"number\":\n\t\t\tif (shape.min !== void 0 && shape.max !== void 0 && shape.min > shape.max) throw new Error(\"validateShape: a number shape has min greater than max\");\n\t\t\tif (shape.integer === true) {\n\t\t\t\tif (Math.ceil(shape.min ?? Number.NEGATIVE_INFINITY) > Math.floor(shape.max ?? Number.POSITIVE_INFINITY)) throw new Error(\"validateShape: an integer number shape has an empty integer range\");\n\t\t\t}\n\t\t\treturn;\n\t\tcase \"boolean\":\n\t\tcase \"null\":\n\t\tcase \"json\":\n\t\tcase \"raw\": return;\n\t\tcase \"literal\":\n\t\t\tif (shape.values.length === 0) throw new Error(\"validateShape: a literal shape needs at least one value\");\n\t\t\tfor (const value of shape.values) if (typeof value === \"number\" && !Number.isFinite(value)) throw new Error(\"validateShape: a literal shape may not contain non-finite number values\");\n\t\t\treturn;\n\t\tcase \"array\":\n\t\t\tif (shape.min !== void 0 && shape.max !== void 0 && shape.min > shape.max) throw new Error(\"validateShape: an array shape has min greater than max\");\n\t\t\tvalidateShape(shape.items);\n\t\t\treturn;\n\t\tcase \"object\": {\n\t\t\tfor (const key of Object.keys(shape.properties)) {\n\t\t\t\tconst child = shape.properties[key];\n\t\t\t\tif (child === void 0) continue;\n\t\t\t\tvalidateShape(child.type === \"optional\" ? child.inner : child);\n\t\t\t}\n\t\t\tconst extra = shape.additionalProperties;\n\t\t\tif (extra !== void 0 && extra !== true && extra !== false) validateShape(extra);\n\t\t\treturn;\n\t\t}\n\t\tcase \"union\":\n\t\t\tif (shape.variants.length === 0) throw new Error(\"validateShape: a union shape needs at least one variant\");\n\t\t\tfor (const variant of shape.variants) validateShape(variant);\n\t\t\treturn;\n\t\tcase \"optional\": throw new Error(\"validateShape: an optional shape may only appear as a direct object-property value\");\n\t\tcase \"nullable\":\n\t\t\tvalidateShape(shape.inner);\n\t\t\treturn;\n\t}\n}\n/**\n* Compile a {@link ContractShape} into a JSON Schema document.\n*\n* @remarks\n* Object shapes emit `additionalProperties: false` (unless opened) and list only\n* required keys in `required`; nullable shapes emit an `anyOf` with `{ type:\n* 'null' }`. Emission only — it never inspects a runtime value.\n*\n* @param shape - The shape to compile\n* @returns The emitted JSON Schema\n*/\nfunction compileSchema(shape) {\n\tswitch (shape.type) {\n\t\tcase \"string\": return {\n\t\t\ttype: \"string\",\n\t\t\t...shape.min !== void 0 ? { minLength: shape.min } : {},\n\t\t\t...shape.max !== void 0 ? { maxLength: shape.max } : {},\n\t\t\t...shape.pattern !== void 0 ? { pattern: shape.pattern.source } : {},\n\t\t\t...shape.description !== void 0 ? { description: shape.description } : {}\n\t\t};\n\t\tcase \"number\": return {\n\t\t\ttype: shape.integer === true ? \"integer\" : \"number\",\n\t\t\t...shape.min !== void 0 ? { minimum: shape.min } : {},\n\t\t\t...shape.max !== void 0 ? { maximum: shape.max } : {},\n\t\t\t...shape.description !== void 0 ? { description: shape.description } : {}\n\t\t};\n\t\tcase \"boolean\": return {\n\t\t\ttype: \"boolean\",\n\t\t\t...shape.description !== void 0 ? { description: shape.description } : {}\n\t\t};\n\t\tcase \"null\": return {\n\t\t\ttype: \"null\",\n\t\t\t...shape.description !== void 0 ? { description: shape.description } : {}\n\t\t};\n\t\tcase \"json\": return { ...shape.description !== void 0 ? { description: shape.description } : {} };\n\t\tcase \"literal\": return {\n\t\t\tenum: [...shape.values],\n\t\t\t...shape.description !== void 0 ? { description: shape.description } : {}\n\t\t};\n\t\tcase \"array\": return {\n\t\t\ttype: \"array\",\n\t\t\titems: compileSchema(shape.items),\n\t\t\t...shape.min !== void 0 ? { minItems: shape.min } : {},\n\t\t\t...shape.max !== void 0 ? { maxItems: shape.max } : {},\n\t\t\t...shape.description !== void 0 ? { description: shape.description } : {}\n\t\t};\n\t\tcase \"object\": {\n\t\t\tconst properties = {};\n\t\t\tconst required = [];\n\t\t\tfor (const key of Object.keys(shape.properties)) {\n\t\t\t\tconst child = shape.properties[key];\n\t\t\t\tif (child === void 0) continue;\n\t\t\t\tproperties[key] = compileSchema(child);\n\t\t\t\tif (child.type !== \"optional\") required.push(key);\n\t\t\t}\n\t\t\tconst extra = shape.additionalProperties;\n\t\t\tconst additionalProperties = extra === true ? true : extra !== void 0 && extra !== false ? compileSchema(extra) : false;\n\t\t\treturn {\n\t\t\t\ttype: \"object\",\n\t\t\t\t...Object.keys(properties).length > 0 ? { properties } : {},\n\t\t\t\t...required.length > 0 ? { required } : {},\n\t\t\t\tadditionalProperties,\n\t\t\t\t...shape.description !== void 0 ? { description: shape.description } : {}\n\t\t\t};\n\t\t}\n\t\tcase \"union\": return {\n\t\t\t...shape.mode === \"oneOf\" ? { oneOf: shape.variants.map((variant) => compileSchema(variant)) } : { anyOf: shape.variants.map((variant) => compileSchema(variant)) },\n\t\t\t...shape.description !== void 0 ? { description: shape.description } : {}\n\t\t};\n\t\tcase \"optional\": return compileSchema(shape.inner);\n\t\tcase \"nullable\": return { anyOf: [compileSchema(shape.inner), { type: \"null\" }] };\n\t\tcase \"raw\": return shape.schema;\n\t}\n}\n/**\n* Compile a {@link ContractShape} into a runtime type guard.\n*\n* @remarks\n* Reuses the combinators: `literalOf` for literals, `arrayOf` for arrays,\n* `recordOf` for closed objects, `unionOf` for unions, `nullableOf` for nullable,\n* and `whereOf` for constraint refinement. Like every guard it is total — it\n* never throws (AGENTS §14).\n*\n* @param shape - The shape to compile\n* @returns A guard narrowing to the shape's inferred type\n*/\nfunction compileGuard(shape) {\n\tswitch (shape.type) {\n\t\tcase \"string\": return stringOf({\n\t\t\tmin: shape.min,\n\t\t\tmax: shape.max,\n\t\t\tpattern: shape.pattern\n\t\t});\n\t\tcase \"number\": {\n\t\t\tconst base = shape.integer === true ? isInteger : isFiniteNumber;\n\t\t\tif (shape.min === void 0 && shape.max === void 0) return base;\n\t\t\treturn shape.integer === true ? intersectionOf(isInteger, boundsOf(shape.min, shape.max)) : boundsOf(shape.min, shape.max);\n\t\t}\n\t\tcase \"boolean\": return isBoolean;\n\t\tcase \"null\": return isNull;\n\t\tcase \"json\": return isJSONValue;\n\t\tcase \"literal\": return literalOf(...shape.values);\n\t\tcase \"array\": {\n\t\t\tconst base = arrayOf(compileGuard(shape.items));\n\t\t\tif (shape.min === void 0 && shape.max === void 0) return base;\n\t\t\tconst withinLength = boundsOf(shape.min, shape.max);\n\t\t\treturn whereOf(base, (value) => withinLength(value.length));\n\t\t}\n\t\tcase \"object\": {\n\t\t\tconst map = Object.create(null);\n\t\t\tconst optionalKeys = [];\n\t\t\tfor (const key of Object.keys(shape.properties)) {\n\t\t\t\tconst child = shape.properties[key];\n\t\t\t\tif (child === void 0) continue;\n\t\t\t\tif (child.type === \"optional\") {\n\t\t\t\t\tmap[key] = compileGuard(child.inner);\n\t\t\t\t\toptionalKeys.push(key);\n\t\t\t\t} else map[key] = compileGuard(child);\n\t\t\t}\n\t\t\tconst extra = shape.additionalProperties;\n\t\t\tif (extra === void 0 || extra === false) return optionalKeys.length > 0 ? recordOf(map, optionalKeys) : recordOf(map);\n\t\t\tconst additional = extra === true ? void 0 : compileGuard(extra);\n\t\t\tconst required = Object.keys(map).filter((key) => !optionalKeys.includes(key));\n\t\t\treturn (value) => {\n\t\t\t\tif (!isRecord(value)) return false;\n\t\t\t\tfor (const key of required) if (!Object.hasOwn(value, key)) return false;\n\t\t\t\tconst outcome = attempt(() => {\n\t\t\t\t\tfor (const key of Object.keys(value)) {\n\t\t\t\t\t\tconst guard = Object.hasOwn(map, key) ? map[key] : void 0;\n\t\t\t\t\t\tif (guard !== void 0) {\n\t\t\t\t\t\t\tif (!guard(value[key])) return false;\n\t\t\t\t\t\t} else if (additional !== void 0 && !additional(value[key])) return false;\n\t\t\t\t\t}\n\t\t\t\t\treturn true;\n\t\t\t\t});\n\t\t\t\treturn outcome.success && outcome.value;\n\t\t\t};\n\t\t}\n\t\tcase \"union\": return unionOf(...shape.variants.map((variant) => compileGuard(variant)));\n\t\tcase \"optional\": return orOf(isUndefined, compileGuard(shape.inner));\n\t\tcase \"nullable\": return nullableOf(compileGuard(shape.inner));\n\t\tcase \"raw\": return (_value) => true;\n\t}\n}\n/**\n* Compile a {@link ContractShape} into an input parser.\n*\n* @remarks\n* Reuses the leaf parsers (`parseString` / `parseInteger` / `parseNumber` /\n* `parseBoolean` / `parseRecord`) and coerces structurally. An object fails as a\n* whole on any required-field failure; a union returns a guard-valid value\n* unchanged, otherwise the first variant that both parses and guards wins.\n*\n* After coercing a leaf, it re-applies that leaf's REFINEMENTS through the same\n* combinators `compileGuard` uses — `stringOf` for a string's length/pattern and\n* `boundsOf` for a number's value and an array's length — so a value that coerces\n* but violates a bound parses to `undefined`. The result is full parse↔guard\n* soundness (AGENTS §14): a non-`undefined` parse always satisfies the contract's\n* `is`, refinements included.\n*\n* @param shape - The shape to compile\n* @returns A parser yielding the shape's inferred type or `undefined`\n*/\nfunction compileParser(shape) {\n\tswitch (shape.type) {\n\t\tcase \"string\": {\n\t\t\tif (shape.min === void 0 && shape.max === void 0 && shape.pattern === void 0) return parseString;\n\t\t\tconst guard = stringOf({\n\t\t\t\tmin: shape.min,\n\t\t\t\tmax: shape.max,\n\t\t\t\tpattern: shape.pattern\n\t\t\t});\n\t\t\treturn (value) => {\n\t\t\t\tconst parsed = parseString(value);\n\t\t\t\treturn parsed !== void 0 && guard(parsed) ? parsed : void 0;\n\t\t\t};\n\t\t}\n\t\tcase \"number\": {\n\t\t\tconst base = shape.integer === true ? parseInteger : parseNumber;\n\t\t\tif (shape.min === void 0 && shape.max === void 0) return base;\n\t\t\tconst within = boundsOf(shape.min, shape.max);\n\t\t\treturn (value) => {\n\t\t\t\tconst parsed = base(value);\n\t\t\t\treturn parsed !== void 0 && within(parsed) ? parsed : void 0;\n\t\t\t};\n\t\t}\n\t\tcase \"boolean\": return parseBoolean;\n\t\tcase \"null\": return (value) => value === null ? null : void 0;\n\t\tcase \"json\": return (value) => isJSONValue(value) ? value : void 0;\n\t\tcase \"literal\": {\n\t\t\tconst allowed = new Set(shape.values);\n\t\t\treturn (value) => {\n\t\t\t\tif (allowed.has(value)) return value;\n\t\t\t\tif (isString(value)) {\n\t\t\t\t\tconst trimmed = value.trim();\n\t\t\t\t\tif (allowed.has(trimmed)) return trimmed;\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\t\tcase \"array\": {\n\t\t\tconst item = compileParser(shape.items);\n\t\t\tconst unbounded = shape.min === void 0 && shape.max === void 0;\n\t\t\tconst withinLength = boundsOf(shape.min, shape.max);\n\t\t\treturn (value) => {\n\t\t\t\tif (!isArray(value)) return void 0;\n\t\t\t\tconst result = [];\n\t\t\t\tfor (const entry of value) {\n\t\t\t\t\tconst parsed = item(entry);\n\t\t\t\t\tif (parsed === void 0) return void 0;\n\t\t\t\t\tresult.push(parsed);\n\t\t\t\t}\n\t\t\t\treturn unbounded || withinLength(result.length) ? result : void 0;\n\t\t\t};\n\t\t}\n\t\tcase \"object\": {\n\t\t\tconst entries = [];\n\t\t\tfor (const key of Object.keys(shape.properties)) {\n\t\t\t\tconst child = shape.properties[key];\n\t\t\t\tif (child === void 0) continue;\n\t\t\t\tconst optional = child.type === \"optional\";\n\t\t\t\tentries.push({\n\t\t\t\t\tkey,\n\t\t\t\t\tparse: compileParser(optional ? child.inner : child),\n\t\t\t\t\toptional\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst known = new Set(entries.map((entry) => entry.key));\n\t\t\tconst extra = shape.additionalProperties;\n\t\t\tconst additional = extra === void 0 || extra === false || extra === true ? void 0 : compileParser(extra);\n\t\t\tconst open = extra === true || additional !== void 0;\n\t\t\treturn (value) => {\n\t\t\t\tconst record = parseRecord(value);\n\t\t\t\tif (record === void 0) return void 0;\n\t\t\t\tconst outcome = attempt(() => {\n\t\t\t\t\tconst result = Object.create(null);\n\t\t\t\t\tfor (const entry of entries) {\n\t\t\t\t\t\tconst raw = record[entry.key];\n\t\t\t\t\t\tif (raw === void 0) {\n\t\t\t\t\t\t\tif (entry.optional) continue;\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst parsed = entry.parse(raw);\n\t\t\t\t\t\tif (parsed === void 0) return void 0;\n\t\t\t\t\t\tresult[entry.key] = parsed;\n\t\t\t\t\t}\n\t\t\t\t\tif (open) for (const key of Object.keys(record)) {\n\t\t\t\t\t\tif (known.has(key)) continue;\n\t\t\t\t\t\tif (additional === void 0) result[key] = record[key];\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tconst parsed = additional(record[key]);\n\t\t\t\t\t\t\tif (parsed === void 0) return void 0;\n\t\t\t\t\t\t\tresult[key] = parsed;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\treturn result;\n\t\t\t\t});\n\t\t\t\treturn outcome.success ? outcome.value : void 0;\n\t\t\t};\n\t\t}\n\t\tcase \"union\": {\n\t\t\tconst variants = shape.variants.map((variant) => ({\n\t\t\t\tparse: compileParser(variant),\n\t\t\t\tguard: compileGuard(variant)\n\t\t\t}));\n\t\t\treturn (value) => {\n\t\t\t\tfor (const variant of variants) if (variant.guard(value)) return value;\n\t\t\t\tfor (const variant of variants) {\n\t\t\t\t\tconst parsed = variant.parse(value);\n\t\t\t\t\tif (parsed !== void 0 && variant.guard(parsed)) return parsed;\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\t\tcase \"optional\": {\n\t\t\tconst inner = compileParser(shape.inner);\n\t\t\treturn (value) => value === void 0 ? void 0 : inner(value);\n\t\t}\n\t\tcase \"nullable\": {\n\t\t\tconst inner = compileParser(shape.inner);\n\t\t\treturn (value) => value === null ? null : inner(value);\n\t\t}\n\t\tcase \"raw\": return (value) => value;\n\t}\n}\n/**\n* Compile a {@link ContractShape} into a deterministic seed value.\n*\n* @remarks\n* The same shape and the same `random` source always produce the same value, so\n* seed data is reproducible. Defaults to a {@link seededRandom} source seeded\n* from the wall clock when none is supplied. Throws on a degenerate empty\n* `literalShape` / `unionShape`, on a pattern-constrained `stringShape` whose\n* generated sample cannot satisfy the pattern, or on a `rawShape` (its embedded\n* schema is arbitrary and cannot be auto-generated) — a programmer error that\n* cannot generate a value (AGENTS §12). `createContract` runs\n* {@link validateShape} first, so a degenerate `literalShape` / `unionShape` /\n* bounded shape is normally caught there; these throws remain here as defense\n* for standalone `compileGenerator` use.\n*\n* @param shape - The shape to generate from\n* @param random - A seeded random source (defaults to `seededRandom(Date.now())`)\n* @returns A value matching the shape\n*/\nfunction compileGenerator(shape, random = seededRandom(Date.now())) {\n\tswitch (shape.type) {\n\t\tcase \"string\": {\n\t\t\tconst min = shape.min ?? 0;\n\t\t\tconst max = shape.max ?? Math.max(min, 12);\n\t\t\tconst length = Math.max(min, Math.min(max, 8));\n\t\t\tconst alphabet = \"abcdefghijklmnopqrstuvwxyz0123456789\";\n\t\t\tlet value = \"\";\n\t\t\tfor (let index = 0; index < length; index += 1) value += alphabet[Math.floor(random() * 36)];\n\t\t\tif (shape.pattern !== void 0 && !shape.pattern.test(value)) throw new Error(\"compileGenerator: a pattern-constrained string shape cannot be auto-generated — supply or verify values another way\");\n\t\t\treturn value;\n\t\t}\n\t\tcase \"number\": {\n\t\t\tconst min = shape.min ?? 0;\n\t\t\tconst max = shape.max ?? 100;\n\t\t\tif (shape.integer === true) {\n\t\t\t\tconst lo = Math.ceil(min);\n\t\t\t\tconst hi = Math.floor(max);\n\t\t\t\treturn Math.floor(random() * (hi - lo + 1)) + lo;\n\t\t\t}\n\t\t\treturn random() * (max - min) + min;\n\t\t}\n\t\tcase \"boolean\": return random() >= .5;\n\t\tcase \"null\": return null;\n\t\tcase \"json\": {\n\t\t\tconst pick = Math.floor(random() * 5);\n\t\t\tif (pick === 0) return null;\n\t\t\tif (pick === 1) return random() >= .5;\n\t\t\tif (pick === 2) return Math.floor(random() * 1e3);\n\t\t\tif (pick === 3) {\n\t\t\t\tconst alphabet = \"abcdefghijklmnopqrstuvwxyz\";\n\t\t\t\tlet value = \"\";\n\t\t\t\tfor (let index = 0; index < 6; index += 1) value += alphabet[Math.floor(random() * 26)];\n\t\t\t\treturn value;\n\t\t\t}\n\t\t\treturn { value: Math.floor(random() * 1e3) };\n\t\t}\n\t\tcase \"literal\":\n\t\t\tif (shape.values.length === 0) throw new Error(\"compileGenerator: a literal shape needs at least one value\");\n\t\t\treturn shape.values[Math.floor(random() * shape.values.length)];\n\t\tcase \"array\": {\n\t\t\tconst lo = shape.min ?? Math.min(1, shape.max ?? 1);\n\t\t\tconst hi = shape.max ?? Math.max(lo, 3);\n\t\t\tconst length = Math.floor(random() * (hi - lo + 1)) + lo;\n\t\t\tconst result = [];\n\t\t\tfor (let index = 0; index < length; index += 1) result.push(compileGenerator(shape.items, random));\n\t\t\treturn result;\n\t\t}\n\t\tcase \"object\": {\n\t\t\tconst result = {};\n\t\t\tfor (const key of Object.keys(shape.properties)) {\n\t\t\t\tconst child = shape.properties[key];\n\t\t\t\tif (child === void 0) continue;\n\t\t\t\tif (child.type === \"optional\" && random() < .3) continue;\n\t\t\t\tresult[key] = compileGenerator(child, random);\n\t\t\t}\n\t\t\tconst extra = shape.additionalProperties;\n\t\t\tif (extra !== void 0 && extra !== true && extra !== false) {\n\t\t\t\tconst count = 1 + Math.floor(random() * 2);\n\t\t\t\tfor (let index = 0; index < count; index += 1) {\n\t\t\t\t\tconst key = `key${index}`;\n\t\t\t\t\tif (Object.hasOwn(result, key)) continue;\n\t\t\t\t\tresult[key] = compileGenerator(extra, random);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\t\tcase \"union\":\n\t\t\tif (shape.variants.length === 0) throw new Error(\"compileGenerator: a union shape needs at least one variant\");\n\t\t\treturn compileGenerator(shape.variants[Math.floor(random() * shape.variants.length)], random);\n\t\tcase \"optional\": return compileGenerator(shape.inner, random);\n\t\tcase \"nullable\": return random() < .2 ? null : compileGenerator(shape.inner, random);\n\t\tcase \"raw\": throw new Error(\"compileGenerator: a raw shape embeds an arbitrary JSON Schema and cannot be auto-generated — supply values another way\");\n\t}\n}\nfunction createContract(shape) {\n\tvalidateShape(shape);\n\tconst schema = compileSchema(shape);\n\tconst guard = compileGuard(shape);\n\tconst parser = compileParser(shape);\n\treturn {\n\t\tschema,\n\t\tis: guard,\n\t\tparse(value) {\n\t\t\treturn parser(value);\n\t\t},\n\t\tgenerate(random) {\n\t\t\treturn compileGenerator(shape, random);\n\t\t}\n\t};\n}\n//#endregion\n//#region src/core/shapers.ts\n/**\n* Build a string {@link StringShape}.\n*\n* @param options - Optional length (`min` / `max`), `pattern`, and `description`\n* @returns A string shape\n*\n* @example\n* ```ts\n* const name = stringShape({ min: 1, max: 80, description: 'Display name' })\n* ```\n*/\nfunction stringShape(options) {\n\treturn {\n\t\ttype: \"string\",\n\t\tmin: options?.min,\n\t\tmax: options?.max,\n\t\tpattern: options?.pattern,\n\t\tdescription: options?.description\n\t};\n}\n/**\n* Build a numeric {@link NumberShape}.\n*\n* @param options - Optional bounds (`min` / `max`), `integer`, and `description`\n* @returns A number shape\n*/\nfunction numberShape(options) {\n\treturn {\n\t\ttype: \"number\",\n\t\tmin: options?.min,\n\t\tmax: options?.max,\n\t\tinteger: options?.integer,\n\t\tdescription: options?.description\n\t};\n}\n/**\n* Build an integer {@link NumberShape} — forces `integer: true`.\n*\n* @remarks\n* The emitted JSON Schema uses `\"type\": \"integer\"` and the guard rejects\n* fractional numbers.\n*\n* @param options - Optional bounds and `description` (no `integer` key)\n* @returns An integer number shape\n*/\nfunction integerShape(options) {\n\treturn {\n\t\ttype: \"number\",\n\t\tinteger: true,\n\t\tmin: options?.min,\n\t\tmax: options?.max,\n\t\tdescription: options?.description\n\t};\n}\n/**\n* Build a {@link BooleanShape}.\n*\n* @param options - Optional `description`\n* @returns A boolean shape\n*/\nfunction booleanShape(options) {\n\treturn {\n\t\ttype: \"boolean\",\n\t\tdescription: options?.description\n\t};\n}\n/**\n* Build a {@link NullShape}.\n*\n* @param options - Optional `description`\n* @returns A null shape\n*/\nfunction nullShape(options) {\n\treturn {\n\t\ttype: \"null\",\n\t\tdescription: options?.description\n\t};\n}\n/**\n* Build a literal shape from a fixed set of primitive values.\n*\n* @param values - The permitted literals\n* @param options - Optional `description`\n* @returns A literal shape whose `Infer` is the union of `values`\n*\n* @example\n* ```ts\n* const role = literalShape(['admin', 'member', 'guest'])\n* // Infer<typeof role> = 'admin' | 'member' | 'guest'\n*\n* const via = literalShape(['function', 'tool', 'agent'], { description: 'How to run the step.' })\n* ```\n*/\nfunction literalShape(values, options) {\n\treturn {\n\t\ttype: \"literal\",\n\t\tvalues,\n\t\tdescription: options?.description\n\t};\n}\n/**\n* Build an {@link ArrayShape} from an element shape.\n*\n* @param items - The element shape\n* @param options - Optional length bounds and `description`\n* @returns An array shape\n*\n* @example\n* ```ts\n* const tags = arrayShape(stringShape(), { max: 10 })\n* ```\n*/\nfunction arrayShape(items, options) {\n\treturn {\n\t\ttype: \"array\",\n\t\titems,\n\t\tmin: options?.min,\n\t\tmax: options?.max,\n\t\tdescription: options?.description\n\t};\n}\n/**\n* Build an {@link ObjectShape} from a property map.\n*\n* @remarks\n* Wrap any property in {@link optionalShape} to allow its absence. By default\n* the compiled guard rejects unknown keys; pass `additionalProperties` to open\n* the object.\n*\n* @param properties - Map of property names to child shapes\n* @param options - Optional `additionalProperties` and `description`\n* @returns An object shape\n*\n* @example\n* ```ts\n* const user = objectShape({\n* \tname: stringShape({ min: 1 }),\n* \tage: integerShape({ min: 0, max: 120 }),\n* \tbio: optionalShape(stringShape()),\n* })\n* ```\n*/\nfunction objectShape(properties, options) {\n\treturn {\n\t\ttype: \"object\",\n\t\tproperties,\n\t\tadditionalProperties: options?.additionalProperties,\n\t\tdescription: options?.description\n\t};\n}\n/**\n* Build an open {@link ObjectShape} with no fixed properties — a dictionary.\n*\n* @remarks\n* Every value is validated against `values`; keys are unconstrained. Equivalent\n* to `objectShape({}, { additionalProperties: values })`.\n*\n* @param values - The shape every value must match\n* @param options - Optional `description`\n* @returns An open object shape\n*\n* @example\n* ```ts\n* const bindings = recordShape(numberShape()) // ~ Record<string, number>\n* ```\n*/\nfunction recordShape(values, options) {\n\treturn {\n\t\ttype: \"object\",\n\t\tproperties: {},\n\t\tadditionalProperties: values,\n\t\tdescription: options?.description\n\t};\n}\n/**\n* Build a {@link UnionShape} from a list of variant shapes (`anyOf` in JSON Schema).\n*\n* @param variants - The candidate shapes; the first match wins at runtime\n* @returns A union shape whose `Infer` is the union of the variants\n*\n* @example\n* ```ts\n* const id = unionShape(stringShape(), integerShape())\n* // Infer<typeof id> = string | number\n* ```\n*/\nfunction unionShape(...variants) {\n\treturn {\n\t\ttype: \"union\",\n\t\tvariants\n\t};\n}\n/**\n* Build a {@link UnionShape} that emits `oneOf` (exactly one match) in JSON Schema.\n*\n* @remarks\n* Runtime behavior is identical to {@link unionShape} — only the emitted schema\n* keyword differs (`oneOf` vs `anyOf`).\n*\n* @param variants - The candidate shapes\n* @returns A union shape with `mode: 'oneOf'`\n*/\nfunction oneOfShape(...variants) {\n\treturn {\n\t\ttype: \"union\",\n\t\tvariants,\n\t\tmode: \"oneOf\"\n\t};\n}\n/**\n* Wrap a shape so it may be absent (`undefined`).\n*\n* @remarks\n* As an {@link objectShape} property, the field becomes a true optional property\n* in the inferred type.\n*\n* @param inner - The wrapped shape\n* @returns An optional shape\n*/\nfunction optionalShape(inner) {\n\treturn {\n\t\ttype: \"optional\",\n\t\tinner\n\t};\n}\n/**\n* Wrap a shape so it may be `null`.\n*\n* @param inner - The wrapped shape\n* @returns A nullable shape\n*/\nfunction nullableShape(inner) {\n\treturn {\n\t\ttype: \"nullable\",\n\t\tinner\n\t};\n}\n/**\n* Build a {@link JSONShape}.\n*\n* @remarks\n* The sound counterpart of {@link rawShape}: `rawShape` embeds an arbitrary\n* schema fragment and accepts anything at runtime, while `jsonShape` validates\n* that a value is real JSON (via {@link isJSONValue}).\n*\n* @param options - Optional `description`\n* @returns A JSON passthrough shape\n*/\nfunction jsonShape(options) {\n\treturn {\n\t\ttype: \"json\",\n\t\tdescription: options?.description\n\t};\n}\n/**\n* Build a {@link RawShape} from a JSON Schema fragment.\n*\n* @remarks\n* For values the shape DSL can't express. The compiled guard accepts any value;\n* the parser passes it through; the schema is emitted verbatim.\n*\n* @param schema - The JSON Schema fragment to embed\n* @returns A raw shape\n*/\nfunction rawShape(schema) {\n\treturn {\n\t\ttype: \"raw\",\n\t\tschema\n\t};\n}\n//#endregion\nexport { JSON_SCHEMA_TYPES, andOf, arrayOf, arrayShape, attempt, booleanShape, boundsOf, compileGenerator, compileGuard, compileParser, compileSchema, complementOf, createContract, enumOf, enumerableSymbolCount, instanceOf, integerShape, intersectionOf, isArray, isArrayBuffer, isArrayBufferView, isAsyncFunction, isAsyncGeneratorFunction, isAsyncIterable, isBigInt, isBigInt64Array, isBigUint64Array, isBoolean, isConstructor, isDataView, isDate, isDefined, isEmptyArray, isEmptyMap, isEmptyObject, isEmptySet, isEmptyString, isError, isFalse, isFiniteNumber, isFloat32Array, isFloat64Array, isFunction, isGeneratorFunction, isInt16Array, isInt32Array, isInt8Array, isInteger, isIterable, isJSONPrimitive, isJSONValue, isMap, isNonEmptyArray, isNonEmptyMap, isNonEmptyObject, isNonEmptySet, isNonEmptyString, isNull, isNullableBoolean, isNullableNumber, isNullableString, isNumber, isObject, isPromise, isPromiseLike, isRecord, isRegExp, isSet, isSharedArrayBuffer, isString, isSymbol, isTrue, isUint16Array, isUint32Array, isUint8Array, isUint8ClampedArray, isUndefined, isWeakMap, isWeakSet, isZeroArg, isZeroArgAsync, isZeroArgAsyncGenerator, isZeroArgGenerator, iterableOf, jsonShape, keyOf, lazyOf, literalOf, literalShape, mapOf, matchOf, notOf, nullShape, nullableOf, nullableShape, numberShape, objectShape, omitOf, oneOfShape, optionalOf, optionalShape, orOf, parseArray, parseArrayField, parseBoolean, parseBooleanField, parseEnum, parseEnumField, parseInteger, parseIntegerField, parseJSON, parseJSONAs, parseJSONValue, parseJSONValueField, parseNull, parseNullField, parseNumber, parseNumberField, parseRecord, parseRecordField, parseString, parseStringField, pickOf, rawShape, recordOf, recordShape, resolveField, schemaToParameters, seededRandom, setOf, stringOf, stringShape, transformOf, tupleOf, unionOf, unionShape, validateShape, whereOf };\n\n//# sourceMappingURL=index.js.map","import type { Row } from './types.js'\nimport { isRecord } from '@orkestrel/contract'\nimport { ERROR_CODES } from './constants.js'\nimport { IndexedDBError } from './errors.js'\n\n// The browser surface's cross-cutting helpers: the feature-detection probe a\n// consumer runs *before* entering the rest of this module (`isIndexedDBSupported`,\n// to fall back to another storage strategy where storage is absent), and the\n// wrapper's foundation — the two Promise bridges every class builds on\n// (`IDBRequest` → value, `IDBTransaction` → completion), the `range` key-range\n// builders that stand in for a query DSL, and the small read primitives the\n// store / index / transaction-store classes share over a native\n// `IDBObjectStore | IDBIndex`, each narrowing the structured clone to a `Row`\n// with `isRecord` at the boundary (the same `as`-free bridge used throughout).\n\n/**\n * Whether IndexedDB is available in this environment.\n *\n * @remarks\n * Gate IndexedDB code with this and fall back to another storage strategy where\n * it is absent (a non-browser runtime, a privacy mode that disables storage).\n * The entry probe, checked before reaching for the rest of this module.\n *\n * @returns `true` when `globalThis.indexedDB` exists\n */\nexport function isIndexedDBSupported(): boolean {\n\treturn typeof globalThis.indexedDB !== 'undefined'\n}\n\n/**\n * Resolve an `IDBRequest` to its result, rejecting with an {@link IndexedDBError}.\n *\n * @remarks\n * The single bridge from IndexedDB's event-based requests to Promises. Issue the\n * request, then `await` this — within an implicit transaction, issue every request\n * for that transaction before the first `await`, so they share it.\n *\n * @param request - The pending request\n * @returns Its `result` on success\n */\nexport function promisifyRequest<T>(request: IDBRequest<T>): Promise<T> {\n\treturn new Promise((resolve, reject) => {\n\t\trequest.onsuccess = () => resolve(request.result)\n\t\trequest.onerror = () => reject(wrapError(request.error))\n\t})\n}\n\n/**\n * Resolve once an `IDBTransaction` commits, rejecting if it errors or aborts.\n *\n * @remarks\n * Await this after issuing the writes of a `readwrite` transaction to guarantee\n * they are durable before continuing.\n *\n * @param transaction - The transaction to await\n */\nexport function promisifyTransaction(transaction: IDBTransaction): Promise<void> {\n\treturn new Promise((resolve, reject) => {\n\t\t// `addEventListener` rather than the `on*` slots: a caller may already have\n\t\t// its own `on*` handlers on this transaction (`IndexedDBTransaction`'s\n\t\t// constructor tracks `active` / `finished` the same way) — assigning would\n\t\t// clobber whichever handler ran second to set up.\n\t\ttransaction.addEventListener('complete', () => resolve())\n\t\ttransaction.addEventListener('error', () => reject(wrapError(transaction.error)))\n\t\ttransaction.addEventListener('abort', () => reject(wrapError(transaction.error)))\n\t})\n}\n\n/**\n * Run a synchronous native IndexedDB call, wrapping a thrown `DOMException`\n * into a typed {@link IndexedDBError}.\n *\n * @remarks\n * Native IndexedDB throws SYNCHRONOUSLY (not through a request's `onerror`)\n * from calls like `database.transaction(...)` or an inactive/closed store's\n * `get` / `put` / `openCursor` — `TransactionInactiveError` /\n * `InvalidStateError` never reach {@link promisifyRequest}'s `onerror`\n * bridge. Every request-issuing call site wraps its native invocation in this\n * so those faults surface as the same typed `IndexedDBError` as an\n * asynchronous one.\n *\n * @param action - The synchronous native call to run\n * @returns Its return value\n */\nexport function guardSync<T>(action: () => T): T {\n\ttry {\n\t\treturn action()\n\t} catch (error) {\n\t\tif (error instanceof DOMException) throw wrapError(error)\n\t\tthrow error\n\t}\n}\n\n/**\n * Read one record by key from a store or index, narrowing it to a {@link Row}.\n *\n * @remarks\n * The shared point-read of every store-like class (`IndexedDBStore`,\n * `IndexedDBIndex`, `IndexedDBTransactionStore`): issue the native `get`, then\n * narrow the structured clone with `isRecord` — a non-record (or a miss) reads as\n * `undefined`, never an unchecked cast. On an index, `source.get` returns the\n * first record for the index key.\n *\n * @param source - The object store or index to read from\n * @param key - The key (a primary key for a store, an index key for an index)\n * @returns The record, or `undefined` on a miss\n */\nexport async function readRecord(\n\tsource: IDBObjectStore | IDBIndex,\n\tkey: IDBValidKey,\n): Promise<Row | undefined> {\n\tconst value = await promisifyRequest<unknown>(guardSync(() => source.get(key)))\n\treturn isRecord(value) ? value : undefined\n}\n\n/**\n * Read many records from a store or index over an optional key range.\n *\n * @remarks\n * The shared bulk read of every store-like class: issue the native `getAll` over\n * an optional `query` (a key range or a single key) and `count` cap, then keep\n * only the records with `isRecord` — the same boundary narrowing as\n * {@link readRecord}, applied across the batch.\n *\n * @param source - The object store or index to read from\n * @param query - A key range or single key to restrict the read, or `null` for all\n * @param count - The maximum number of records to read\n * @returns The matching records\n */\nexport async function readRecords(\n\tsource: IDBObjectStore | IDBIndex,\n\tquery?: IDBKeyRange | IDBValidKey | null,\n\tcount?: number,\n): Promise<readonly Row[]> {\n\tconst all = await promisifyRequest<unknown[]>(\n\t\tguardSync(() => source.getAll(query ?? undefined, count)),\n\t)\n\treturn all.filter(isRecord)\n}\n\n/**\n * Whether a key is present in a store or index.\n *\n * @remarks\n * The shared presence test of every store-like class: a native `count` of the\n * key, true when at least one record matches — cheaper than reading the record\n * when only existence matters.\n *\n * @param source - The object store or index to test\n * @param key - The key to look for\n * @returns `true` when at least one record has the key\n */\nexport async function hasKey(\n\tsource: IDBObjectStore | IDBIndex,\n\tkey: IDBValidKey,\n): Promise<boolean> {\n\treturn (await promisifyRequest(guardSync(() => source.count(key)))) > 0\n}\n\n/**\n * Key-range builders — the wrapper's filter vocabulary.\n *\n * @remarks\n * Each returns an `IDBKeyRange` to pass to `records` / `keys` / `count` / `cursor`,\n * so a read is index-backed (O(log n)) rather than a full scan. `only` (exact),\n * `above` / `from` (greater than, exclusive / inclusive), `below` / `to` (less\n * than, exclusive / inclusive), `between` (bounded), and `prefix` (string\n * starts-with).\n */\nexport const range = {\n\tonly(value: IDBValidKey): IDBKeyRange {\n\t\treturn IDBKeyRange.only(value)\n\t},\n\tabove(value: IDBValidKey): IDBKeyRange {\n\t\treturn IDBKeyRange.lowerBound(value, true)\n\t},\n\tfrom(value: IDBValidKey): IDBKeyRange {\n\t\treturn IDBKeyRange.lowerBound(value, false)\n\t},\n\tbelow(value: IDBValidKey): IDBKeyRange {\n\t\treturn IDBKeyRange.upperBound(value, true)\n\t},\n\tto(value: IDBValidKey): IDBKeyRange {\n\t\treturn IDBKeyRange.upperBound(value, false)\n\t},\n\tbetween(\n\t\tlower: IDBValidKey,\n\t\tupper: IDBValidKey,\n\t\toptions?: { readonly lowerOpen?: boolean; readonly upperOpen?: boolean },\n\t): IDBKeyRange {\n\t\treturn IDBKeyRange.bound(lower, upper, options?.lowerOpen ?? false, options?.upperOpen ?? false)\n\t},\n\tprefix(value: string): IDBKeyRange {\n\t\t// Every string with this prefix: [value, value + U+FFFF]. U+FFFF sorts above\n\t\t// any normal code unit, so it caps the range without excluding the prefix.\n\t\treturn IDBKeyRange.bound(value, value + '', false, false)\n\t},\n}\n\n/**\n * Map a native IndexedDB `DOMException` to a typed {@link IndexedDBError}.\n *\n * @remarks\n * The boundary the two Promise bridges ({@link promisifyRequest} /\n * {@link promisifyTransaction}) share: it reads {@link ERROR_CODES} to pick the\n * machine-readable code for the native `name`, falling back to `UNKNOWN` for an\n * unmapped name or a `null` error.\n *\n * @param error - The native error, or `null` when none is attached\n * @returns The wrapped, typed error\n */\nexport function wrapError(error: DOMException | null): IndexedDBError {\n\tif (error === null) return new IndexedDBError('UNKNOWN', 'Unknown IndexedDB error')\n\tconst code = ERROR_CODES[error.name] ?? 'UNKNOWN'\n\treturn new IndexedDBError(code, error.message || `IndexedDB error: ${error.name}`, error)\n}\n","import { isRecord } from '@orkestrel/contract'\nimport type { IndexedDBCursorInterface, Row } from './types.js'\nimport { guardSync, promisifyRequest } from './helpers.js'\n\n/**\n * A promisified value cursor over an object store or index.\n *\n * @remarks\n * Wraps `IDBCursorWithValue` and the request that drives it. The position\n * (`key` / `primary` / `value`) is snapshot at construction because IndexedDB\n * mutates the live cursor object in place on each advance. `continue` / `seek` /\n * `advance` re-arm the shared request and resolve to the next position (a fresh\n * `IndexedDBCursor`) or `null` at the end. `update` / `delete` act on the current\n * record — they require the cursor's transaction to be `readwrite` (a `store`\n * cursor), so they reject on an `index` cursor's read-only transaction.\n */\nexport class IndexedDBCursor implements IndexedDBCursorInterface {\n\treadonly #cursor: IDBCursorWithValue\n\treadonly #request: IDBRequest<IDBCursorWithValue | null>\n\treadonly #key: IDBValidKey\n\treadonly #primary: IDBValidKey\n\t#value: Row\n\treadonly #direction: IDBCursorDirection\n\n\tconstructor(cursor: IDBCursorWithValue, request: IDBRequest<IDBCursorWithValue | null>) {\n\t\tthis.#cursor = cursor\n\t\tthis.#request = request\n\t\tthis.#key = cursor.key\n\t\tthis.#primary = cursor.primaryKey\n\t\tthis.#value = isRecord(cursor.value) ? cursor.value : {}\n\t\tthis.#direction = cursor.direction\n\t}\n\n\tget cursor(): IDBCursorWithValue {\n\t\treturn this.#cursor\n\t}\n\n\tget source(): IDBObjectStore | IDBIndex {\n\t\treturn this.#cursor.source\n\t}\n\n\tget key(): IDBValidKey {\n\t\treturn this.#key\n\t}\n\n\tget primary(): IDBValidKey {\n\t\treturn this.#primary\n\t}\n\n\tget value(): Row {\n\t\treturn this.#value\n\t}\n\n\tget direction(): IDBCursorDirection {\n\t\treturn this.#direction\n\t}\n\n\tasync continue(key?: IDBValidKey): Promise<IndexedDBCursorInterface | null> {\n\t\tguardSync(() => {\n\t\t\tif (key === undefined) this.#cursor.continue()\n\t\t\telse this.#cursor.continue(key)\n\t\t})\n\t\treturn this.#advance()\n\t}\n\n\tasync seek(key: IDBValidKey, primary: IDBValidKey): Promise<IndexedDBCursorInterface | null> {\n\t\tguardSync(() => this.#cursor.continuePrimaryKey(key, primary))\n\t\treturn this.#advance()\n\t}\n\n\tasync advance(count: number): Promise<IndexedDBCursorInterface | null> {\n\t\tguardSync(() => this.#cursor.advance(count))\n\t\treturn this.#advance()\n\t}\n\n\tasync update(value: Row): Promise<IDBValidKey> {\n\t\tconst key = await promisifyRequest(guardSync(() => this.#cursor.update(value)))\n\t\tthis.#value = value\n\t\treturn key\n\t}\n\n\tasync delete(): Promise<void> {\n\t\tawait promisifyRequest(guardSync(() => this.#cursor.delete()))\n\t}\n\n\t// Await the shared request after a move, wrapping the next position (or null).\n\tasync #advance(): Promise<IndexedDBCursorInterface | null> {\n\t\tconst next = await promisifyRequest(this.#request)\n\t\treturn next ? new IndexedDBCursor(next, this.#request) : null\n\t}\n}\n","import { isArray } from '@orkestrel/contract'\nimport type {\n\tCursorOptions,\n\tIndexDefinition,\n\tIndexedDBCursorInterface,\n\tIndexedDBIndexInterface,\n\tKeyPath,\n\tRow,\n} from './types.js'\nimport { IndexedDBError } from './errors.js'\nimport { guardSync, hasKey, promisifyRequest, readRecord, readRecords } from './helpers.js'\nimport { IndexedDBCursor } from './IndexedDBCursor.js'\n\n/**\n * A secondary index on a store — a read-only view keyed by an indexed path.\n *\n * @remarks\n * Reached through `store.index(name)`. Each call opens its own `readonly`\n * transaction. `get` / `resolve` fetch the first record for an index key\n * (`resolve` throws `NOT_FOUND`); `records` reads the matching records and `keys`\n * their **primary** keys; `primary` maps an index key to one primary key; `count`\n * / `has` test presence; `cursor` streams matches. Reads batch by their array\n * overload (AGENTS §9.2).\n */\nexport class IndexedDBIndex implements IndexedDBIndexInterface {\n\treadonly #store: string\n\treadonly #name: string\n\treadonly #definition: IndexDefinition\n\treadonly #connect: () => Promise<IDBDatabase>\n\n\tconstructor(\n\t\tstore: string,\n\t\tname: string,\n\t\tdefinition: IndexDefinition,\n\t\tconnect: () => Promise<IDBDatabase>,\n\t) {\n\t\tthis.#store = store\n\t\tthis.#name = name\n\t\tthis.#definition = definition\n\t\tthis.#connect = connect\n\t}\n\n\tget name(): string {\n\t\treturn this.#name\n\t}\n\n\tget path(): KeyPath {\n\t\treturn this.#definition.path\n\t}\n\n\tget unique(): boolean {\n\t\treturn this.#definition.unique ?? false\n\t}\n\n\tget multiple(): boolean {\n\t\treturn this.#definition.multiple ?? false\n\t}\n\n\tget(keys: readonly IDBValidKey[]): Promise<readonly (Row | undefined)[]>\n\tget(key: IDBValidKey): Promise<Row | undefined>\n\tasync get(\n\t\tkeyOrKeys: IDBValidKey | readonly IDBValidKey[],\n\t): Promise<Row | undefined | readonly (Row | undefined)[]> {\n\t\tconst index = await this.#index()\n\t\tif (isArray<IDBValidKey>(keyOrKeys)) {\n\t\t\treturn Promise.all(keyOrKeys.map((key) => readRecord(index, key)))\n\t\t}\n\t\treturn readRecord(index, keyOrKeys)\n\t}\n\n\tresolve(keys: readonly IDBValidKey[]): Promise<readonly Row[]>\n\tresolve(key: IDBValidKey): Promise<Row>\n\tasync resolve(keyOrKeys: IDBValidKey | readonly IDBValidKey[]): Promise<Row | readonly Row[]> {\n\t\tconst index = await this.#index()\n\t\tif (isArray<IDBValidKey>(keyOrKeys)) {\n\t\t\treturn Promise.all(keyOrKeys.map((key) => this.#resolve(index, key)))\n\t\t}\n\t\treturn this.#resolve(index, keyOrKeys)\n\t}\n\n\tasync records(query?: IDBKeyRange | IDBValidKey | null, count?: number): Promise<readonly Row[]> {\n\t\tconst index = await this.#index()\n\t\treturn readRecords(index, query, count)\n\t}\n\n\tasync keys(\n\t\tquery?: IDBKeyRange | IDBValidKey | null,\n\t\tcount?: number,\n\t): Promise<readonly IDBValidKey[]> {\n\t\tconst index = await this.#index()\n\t\treturn promisifyRequest(guardSync(() => index.getAllKeys(query ?? undefined, count)))\n\t}\n\n\tasync primary(key: IDBValidKey): Promise<IDBValidKey | undefined> {\n\t\tconst index = await this.#index()\n\t\treturn promisifyRequest(guardSync(() => index.getKey(key)))\n\t}\n\n\thas(keys: readonly IDBValidKey[]): Promise<readonly boolean[]>\n\thas(key: IDBValidKey): Promise<boolean>\n\tasync has(\n\t\tkeyOrKeys: IDBValidKey | readonly IDBValidKey[],\n\t): Promise<boolean | readonly boolean[]> {\n\t\tconst index = await this.#index()\n\t\tif (isArray<IDBValidKey>(keyOrKeys)) {\n\t\t\treturn Promise.all(keyOrKeys.map((key) => hasKey(index, key)))\n\t\t}\n\t\treturn hasKey(index, keyOrKeys)\n\t}\n\n\tasync count(query?: IDBKeyRange | IDBValidKey | null): Promise<number> {\n\t\tconst index = await this.#index()\n\t\treturn promisifyRequest(guardSync(() => index.count(query ?? undefined)))\n\t}\n\n\tasync cursor(options?: CursorOptions): Promise<IndexedDBCursorInterface | null> {\n\t\tconst index = await this.#index()\n\t\tconst request = guardSync(() =>\n\t\t\tindex.openCursor(options?.query ?? null, options?.direction ?? 'next'),\n\t\t)\n\t\tconst cursor = await promisifyRequest(request)\n\t\treturn cursor ? new IndexedDBCursor(cursor, request) : null\n\t}\n\n\t// Open this index in a fresh readonly transaction.\n\tasync #index(): Promise<IDBIndex> {\n\t\tconst database = await this.#connect()\n\t\treturn guardSync(() =>\n\t\t\tdatabase.transaction([this.#store], 'readonly').objectStore(this.#store).index(this.#name),\n\t\t)\n\t}\n\n\tasync #resolve(index: IDBIndex, key: IDBValidKey): Promise<Row> {\n\t\tconst value = await readRecord(index, key)\n\t\tif (value === undefined) {\n\t\t\tthrow new IndexedDBError(\n\t\t\t\t'NOT_FOUND',\n\t\t\t\t`No record in index '${this.#name}' of store '${this.#store}' for key ${String(key)}`,\n\t\t\t)\n\t\t}\n\t\treturn value\n\t}\n}\n","import { isArray } from '@orkestrel/contract'\nimport type {\n\tCursorOptions,\n\tIndexedDBCursorInterface,\n\tIndexedDBIndexInterface,\n\tIndexedDBStoreInterface,\n\tKeyPath,\n\tRow,\n\tStoreDefinition,\n} from './types.js'\nimport { IndexedDBError } from './errors.js'\nimport {\n\tguardSync,\n\thasKey,\n\tpromisifyRequest,\n\tpromisifyTransaction,\n\treadRecord,\n\treadRecords,\n} from './helpers.js'\nimport { IndexedDBCursor } from './IndexedDBCursor.js'\nimport { IndexedDBIndex } from './IndexedDBIndex.js'\n\n/**\n * An object store — the full keyed CRUD surface plus index, count, and cursor\n * access.\n *\n * @remarks\n * Reached through `database.store(name)`. Each call runs in its own implicit\n * transaction (`readonly` for reads, `readwrite` for writes), awaiting completion\n * so writes are durable on return; for atomic multi-operation work use the\n * database's `read` / `write`. The keyed verbs batch by their array overload — and\n * those overloads are declared first, because an array is itself both a record and\n * a compound `IDBValidKey`, so the array signature must take precedence to read as\n * a batch (AGENTS §9.2). Pass `range.only([…])` to `records` / `count` to act on a\n * single compound key.\n */\nexport class IndexedDBStore implements IndexedDBStoreInterface {\n\treadonly #name: string\n\treadonly #definition: StoreDefinition\n\treadonly #connect: () => Promise<IDBDatabase>\n\n\tconstructor(name: string, definition: StoreDefinition, connect: () => Promise<IDBDatabase>) {\n\t\tthis.#name = name\n\t\tthis.#definition = definition\n\t\tthis.#connect = connect\n\t}\n\n\tget name(): string {\n\t\treturn this.#name\n\t}\n\n\tget path(): KeyPath | null {\n\t\treturn this.#definition.path ?? null\n\t}\n\n\tget indexes(): readonly string[] {\n\t\treturn (this.#definition.indexes ?? []).map((index) => index.name)\n\t}\n\n\tget increment(): boolean {\n\t\treturn this.#definition.increment ?? false\n\t}\n\n\tget(keys: readonly IDBValidKey[]): Promise<readonly (Row | undefined)[]>\n\tget(key: IDBValidKey): Promise<Row | undefined>\n\tasync get(\n\t\tkeyOrKeys: IDBValidKey | readonly IDBValidKey[],\n\t): Promise<Row | undefined | readonly (Row | undefined)[]> {\n\t\tconst store = await this.#store('readonly')\n\t\tif (isArray<IDBValidKey>(keyOrKeys)) {\n\t\t\treturn Promise.all(keyOrKeys.map((key) => readRecord(store, key)))\n\t\t}\n\t\treturn readRecord(store, keyOrKeys)\n\t}\n\n\tresolve(keys: readonly IDBValidKey[]): Promise<readonly Row[]>\n\tresolve(key: IDBValidKey): Promise<Row>\n\tasync resolve(keyOrKeys: IDBValidKey | readonly IDBValidKey[]): Promise<Row | readonly Row[]> {\n\t\tconst store = await this.#store('readonly')\n\t\tif (isArray<IDBValidKey>(keyOrKeys)) {\n\t\t\treturn Promise.all(keyOrKeys.map((key) => this.#resolve(store, key)))\n\t\t}\n\t\treturn this.#resolve(store, keyOrKeys)\n\t}\n\n\tasync records(query?: IDBKeyRange | IDBValidKey | null, count?: number): Promise<readonly Row[]> {\n\t\tconst store = await this.#store('readonly')\n\t\treturn readRecords(store, query, count)\n\t}\n\n\tasync keys(\n\t\tquery?: IDBKeyRange | IDBValidKey | null,\n\t\tcount?: number,\n\t): Promise<readonly IDBValidKey[]> {\n\t\tconst store = await this.#store('readonly')\n\t\treturn promisifyRequest(guardSync(() => store.getAllKeys(query ?? undefined, count)))\n\t}\n\n\thas(keys: readonly IDBValidKey[]): Promise<readonly boolean[]>\n\thas(key: IDBValidKey): Promise<boolean>\n\tasync has(\n\t\tkeyOrKeys: IDBValidKey | readonly IDBValidKey[],\n\t): Promise<boolean | readonly boolean[]> {\n\t\tconst store = await this.#store('readonly')\n\t\tif (isArray<IDBValidKey>(keyOrKeys)) {\n\t\t\treturn Promise.all(keyOrKeys.map((key) => hasKey(store, key)))\n\t\t}\n\t\treturn hasKey(store, keyOrKeys)\n\t}\n\n\tasync count(query?: IDBKeyRange | IDBValidKey | null): Promise<number> {\n\t\tconst store = await this.#store('readonly')\n\t\treturn promisifyRequest(guardSync(() => store.count(query ?? undefined)))\n\t}\n\n\tset(values: readonly Row[]): Promise<readonly IDBValidKey[]>\n\tset(value: Row, key?: IDBValidKey): Promise<IDBValidKey>\n\tasync set(\n\t\tvalueOrValues: Row | readonly Row[],\n\t\tkey?: IDBValidKey,\n\t): Promise<IDBValidKey | readonly IDBValidKey[]> {\n\t\tconst store = await this.#store('readwrite')\n\t\tif (isArray<Row>(valueOrValues)) {\n\t\t\tconst keys = await Promise.all(\n\t\t\t\tvalueOrValues.map((value) => promisifyRequest(guardSync(() => store.put(value)))),\n\t\t\t)\n\t\t\tawait promisifyTransaction(store.transaction)\n\t\t\treturn keys\n\t\t}\n\t\tconst written = await promisifyRequest(\n\t\t\tguardSync(() =>\n\t\t\t\tkey === undefined ? store.put(valueOrValues) : store.put(valueOrValues, key),\n\t\t\t),\n\t\t)\n\t\tawait promisifyTransaction(store.transaction)\n\t\treturn written\n\t}\n\n\tadd(values: readonly Row[]): Promise<readonly IDBValidKey[]>\n\tadd(value: Row, key?: IDBValidKey): Promise<IDBValidKey>\n\tasync add(\n\t\tvalueOrValues: Row | readonly Row[],\n\t\tkey?: IDBValidKey,\n\t): Promise<IDBValidKey | readonly IDBValidKey[]> {\n\t\tconst store = await this.#store('readwrite')\n\t\tif (isArray<Row>(valueOrValues)) {\n\t\t\tconst keys = await Promise.all(\n\t\t\t\tvalueOrValues.map((value) => promisifyRequest(guardSync(() => store.add(value)))),\n\t\t\t)\n\t\t\tawait promisifyTransaction(store.transaction)\n\t\t\treturn keys\n\t\t}\n\t\tconst written = await promisifyRequest(\n\t\t\tguardSync(() =>\n\t\t\t\tkey === undefined ? store.add(valueOrValues) : store.add(valueOrValues, key),\n\t\t\t),\n\t\t)\n\t\tawait promisifyTransaction(store.transaction)\n\t\treturn written\n\t}\n\n\tremove(keys: readonly IDBValidKey[]): Promise<void>\n\tremove(key: IDBValidKey): Promise<void>\n\tasync remove(keyOrKeys: IDBValidKey | readonly IDBValidKey[]): Promise<void> {\n\t\tconst store = await this.#store('readwrite')\n\t\tif (isArray<IDBValidKey>(keyOrKeys)) {\n\t\t\tawait Promise.all(\n\t\t\t\tkeyOrKeys.map((key) => promisifyRequest(guardSync(() => store.delete(key)))),\n\t\t\t)\n\t\t} else {\n\t\t\tawait promisifyRequest(guardSync(() => store.delete(keyOrKeys)))\n\t\t}\n\t\tawait promisifyTransaction(store.transaction)\n\t}\n\n\tasync clear(): Promise<void> {\n\t\tconst store = await this.#store('readwrite')\n\t\tawait promisifyRequest(guardSync(() => store.clear()))\n\t\tawait promisifyTransaction(store.transaction)\n\t}\n\n\tindex(name: string): IndexedDBIndexInterface {\n\t\tconst definition = (this.#definition.indexes ?? []).find((index) => index.name === name)\n\t\tif (definition === undefined) {\n\t\t\tthrow new IndexedDBError(\n\t\t\t\t'NOT_FOUND',\n\t\t\t\t`Index '${name}' is not declared on store '${this.#name}'`,\n\t\t\t)\n\t\t}\n\t\treturn new IndexedDBIndex(this.#name, name, definition, this.#connect)\n\t}\n\n\tasync cursor(options?: CursorOptions): Promise<IndexedDBCursorInterface | null> {\n\t\tconst store = await this.#store('readwrite')\n\t\tconst request = guardSync(() =>\n\t\t\tstore.openCursor(options?.query ?? null, options?.direction ?? 'next'),\n\t\t)\n\t\tconst cursor = await promisifyRequest(request)\n\t\treturn cursor ? new IndexedDBCursor(cursor, request) : null\n\t}\n\n\t// Open this object store in a fresh transaction of the given mode.\n\tasync #store(mode: IDBTransactionMode): Promise<IDBObjectStore> {\n\t\tconst database = await this.#connect()\n\t\treturn guardSync(() => database.transaction([this.#name], mode).objectStore(this.#name))\n\t}\n\n\tasync #resolve(store: IDBObjectStore, key: IDBValidKey): Promise<Row> {\n\t\tconst value = await readRecord(store, key)\n\t\tif (value === undefined) {\n\t\t\tthrow new IndexedDBError(\n\t\t\t\t'NOT_FOUND',\n\t\t\t\t`No record in store '${this.#name}' for key ${String(key)}`,\n\t\t\t)\n\t\t}\n\t\treturn value\n\t}\n}\n","import { isArray } from '@orkestrel/contract'\nimport type {\n\tCursorOptions,\n\tIndexedDBCursorInterface,\n\tIndexedDBTransactionStoreInterface,\n\tRow,\n} from './types.js'\nimport { IndexedDBError } from './errors.js'\nimport { guardSync, hasKey, promisifyRequest, readRecord, readRecords } from './helpers.js'\nimport { IndexedDBCursor } from './IndexedDBCursor.js'\n\n/**\n * An object store bound to an explicit transaction.\n *\n * @remarks\n * The same CRUD surface as a standalone store, but every call runs in the owning\n * transaction (opened by the database's `read` / `write`) rather than its own — so\n * a sequence of reads and writes commits atomically when the scope resolves. It\n * does not await transaction completion per call (the scope does that once) and\n * omits `index`; keep your awaited operations on IndexedDB requests only, so the\n * transaction stays active across them.\n */\nexport class IndexedDBTransactionStore implements IndexedDBTransactionStoreInterface {\n\treadonly #store: IDBObjectStore\n\treadonly #name: string\n\n\tconstructor(store: IDBObjectStore) {\n\t\tthis.#store = store\n\t\tthis.#name = store.name\n\t}\n\n\tget store(): IDBObjectStore {\n\t\treturn this.#store\n\t}\n\n\tget(keys: readonly IDBValidKey[]): Promise<readonly (Row | undefined)[]>\n\tget(key: IDBValidKey): Promise<Row | undefined>\n\tasync get(\n\t\tkeyOrKeys: IDBValidKey | readonly IDBValidKey[],\n\t): Promise<Row | undefined | readonly (Row | undefined)[]> {\n\t\tif (isArray<IDBValidKey>(keyOrKeys)) {\n\t\t\treturn Promise.all(keyOrKeys.map((key) => readRecord(this.#store, key)))\n\t\t}\n\t\treturn readRecord(this.#store, keyOrKeys)\n\t}\n\n\tresolve(keys: readonly IDBValidKey[]): Promise<readonly Row[]>\n\tresolve(key: IDBValidKey): Promise<Row>\n\tasync resolve(keyOrKeys: IDBValidKey | readonly IDBValidKey[]): Promise<Row | readonly Row[]> {\n\t\tif (isArray<IDBValidKey>(keyOrKeys)) {\n\t\t\treturn Promise.all(keyOrKeys.map((key) => this.#resolve(key)))\n\t\t}\n\t\treturn this.#resolve(keyOrKeys)\n\t}\n\n\tasync records(query?: IDBKeyRange | IDBValidKey | null, count?: number): Promise<readonly Row[]> {\n\t\treturn readRecords(this.#store, query, count)\n\t}\n\n\tasync keys(\n\t\tquery?: IDBKeyRange | IDBValidKey | null,\n\t\tcount?: number,\n\t): Promise<readonly IDBValidKey[]> {\n\t\treturn promisifyRequest(guardSync(() => this.#store.getAllKeys(query ?? undefined, count)))\n\t}\n\n\thas(keys: readonly IDBValidKey[]): Promise<readonly boolean[]>\n\thas(key: IDBValidKey): Promise<boolean>\n\tasync has(\n\t\tkeyOrKeys: IDBValidKey | readonly IDBValidKey[],\n\t): Promise<boolean | readonly boolean[]> {\n\t\tif (isArray<IDBValidKey>(keyOrKeys)) {\n\t\t\treturn Promise.all(keyOrKeys.map((key) => hasKey(this.#store, key)))\n\t\t}\n\t\treturn hasKey(this.#store, keyOrKeys)\n\t}\n\n\tasync count(query?: IDBKeyRange | IDBValidKey | null): Promise<number> {\n\t\treturn promisifyRequest(guardSync(() => this.#store.count(query ?? undefined)))\n\t}\n\n\tset(values: readonly Row[]): Promise<readonly IDBValidKey[]>\n\tset(value: Row, key?: IDBValidKey): Promise<IDBValidKey>\n\tasync set(\n\t\tvalueOrValues: Row | readonly Row[],\n\t\tkey?: IDBValidKey,\n\t): Promise<IDBValidKey | readonly IDBValidKey[]> {\n\t\tif (isArray<Row>(valueOrValues)) {\n\t\t\treturn Promise.all(\n\t\t\t\tvalueOrValues.map((value) => promisifyRequest(guardSync(() => this.#store.put(value)))),\n\t\t\t)\n\t\t}\n\t\treturn promisifyRequest(\n\t\t\tguardSync(() =>\n\t\t\t\tkey === undefined ? this.#store.put(valueOrValues) : this.#store.put(valueOrValues, key),\n\t\t\t),\n\t\t)\n\t}\n\n\tadd(values: readonly Row[]): Promise<readonly IDBValidKey[]>\n\tadd(value: Row, key?: IDBValidKey): Promise<IDBValidKey>\n\tasync add(\n\t\tvalueOrValues: Row | readonly Row[],\n\t\tkey?: IDBValidKey,\n\t): Promise<IDBValidKey | readonly IDBValidKey[]> {\n\t\tif (isArray<Row>(valueOrValues)) {\n\t\t\treturn Promise.all(\n\t\t\t\tvalueOrValues.map((value) => promisifyRequest(guardSync(() => this.#store.add(value)))),\n\t\t\t)\n\t\t}\n\t\treturn promisifyRequest(\n\t\t\tguardSync(() =>\n\t\t\t\tkey === undefined ? this.#store.add(valueOrValues) : this.#store.add(valueOrValues, key),\n\t\t\t),\n\t\t)\n\t}\n\n\tremove(keys: readonly IDBValidKey[]): Promise<void>\n\tremove(key: IDBValidKey): Promise<void>\n\tasync remove(keyOrKeys: IDBValidKey | readonly IDBValidKey[]): Promise<void> {\n\t\tif (isArray<IDBValidKey>(keyOrKeys)) {\n\t\t\tawait Promise.all(\n\t\t\t\tkeyOrKeys.map((key) => promisifyRequest(guardSync(() => this.#store.delete(key)))),\n\t\t\t)\n\t\t\treturn\n\t\t}\n\t\tawait promisifyRequest(guardSync(() => this.#store.delete(keyOrKeys)))\n\t}\n\n\tasync clear(): Promise<void> {\n\t\tawait promisifyRequest(guardSync(() => this.#store.clear()))\n\t}\n\n\tasync cursor(options?: CursorOptions): Promise<IndexedDBCursorInterface | null> {\n\t\tconst request = guardSync(() =>\n\t\t\tthis.#store.openCursor(options?.query ?? null, options?.direction ?? 'next'),\n\t\t)\n\t\tconst cursor = await promisifyRequest(request)\n\t\treturn cursor ? new IndexedDBCursor(cursor, request) : null\n\t}\n\n\tasync #resolve(key: IDBValidKey): Promise<Row> {\n\t\tconst value = await readRecord(this.#store, key)\n\t\tif (value === undefined) {\n\t\t\tthrow new IndexedDBError(\n\t\t\t\t'NOT_FOUND',\n\t\t\t\t`No record in store '${this.#name}' for key ${String(key)}`,\n\t\t\t)\n\t\t}\n\t\treturn value\n\t}\n}\n","import type {\n\tIndexedDBTransactionInterface,\n\tIndexedDBTransactionStoreInterface,\n\tStoresShape,\n} from './types.js'\nimport { IndexedDBError } from './errors.js'\nimport { IndexedDBTransactionStore } from './IndexedDBTransactionStore.js'\n\n/**\n * An explicit transaction over one or more stores.\n *\n * @remarks\n * Wraps `IDBTransaction` with state tracking and typed, scope-bound store access.\n * Constructed by the database's `read` / `write`, which await its completion (or\n * roll it back on a throw). `store` reaches a store within the transaction's scope;\n * `abort` rolls back; `commit` flushes early (the scope's completion commits\n * otherwise). `active` is true until commit or abort; `finished` is its complement.\n */\nexport class IndexedDBTransaction<\n\tStores extends StoresShape = StoresShape,\n> implements IndexedDBTransactionInterface<Stores> {\n\treadonly #transaction: IDBTransaction\n\treadonly #stores: readonly string[]\n\t#active = true\n\t#finished = false\n\n\tconstructor(transaction: IDBTransaction) {\n\t\tthis.#transaction = transaction\n\t\tthis.#stores = Array.from(transaction.objectStoreNames)\n\t\tconst settle = (): void => {\n\t\t\tthis.#active = false\n\t\t\tthis.#finished = true\n\t\t}\n\t\t// `addEventListener` rather than the `on*` slots: `#run` also awaits this\n\t\t// same native transaction through `promisifyTransaction`, which listens the\n\t\t// same way — assigning `on*` here would clobber whichever handler is wired\n\t\t// second.\n\t\ttransaction.addEventListener('complete', settle)\n\t\ttransaction.addEventListener('abort', settle)\n\t\ttransaction.addEventListener('error', settle)\n\t}\n\n\tget transaction(): IDBTransaction {\n\t\treturn this.#transaction\n\t}\n\n\tget mode(): IDBTransactionMode {\n\t\treturn this.#transaction.mode\n\t}\n\n\tget stores(): readonly string[] {\n\t\treturn this.#stores\n\t}\n\n\tget active(): boolean {\n\t\treturn this.#active\n\t}\n\n\tget finished(): boolean {\n\t\treturn this.#finished\n\t}\n\n\tget error(): DOMException | null {\n\t\treturn this.#transaction.error\n\t}\n\n\tstore<K extends keyof Stores & string>(name: K): IndexedDBTransactionStoreInterface {\n\t\tif (!this.#stores.includes(name)) {\n\t\t\tthrow new IndexedDBError(\n\t\t\t\t'NOT_FOUND',\n\t\t\t\t`Store '${name}' is outside this transaction's scope (${this.#stores.join(', ')})`,\n\t\t\t)\n\t\t}\n\t\tif (!this.#active) {\n\t\t\tthrow new IndexedDBError(\n\t\t\t\t'ABORTED',\n\t\t\t\t`Transaction over ${this.#stores.join(', ')} is no longer active`,\n\t\t\t)\n\t\t}\n\t\treturn new IndexedDBTransactionStore(this.#transaction.objectStore(name))\n\t}\n\n\tabort(): void {\n\t\tif (this.#finished) {\n\t\t\tthrow new IndexedDBError('ABORTED', 'Cannot abort an already-finished transaction')\n\t\t}\n\t\tthis.#transaction.abort()\n\t\tthis.#active = false\n\t\tthis.#finished = true\n\t}\n\n\tcommit(): void {\n\t\tif (this.#finished) {\n\t\t\tthrow new IndexedDBError('ABORTED', 'Cannot commit an already-finished transaction')\n\t\t}\n\t\tthis.#transaction.commit()\n\t}\n}\n","import { isArray } from '@orkestrel/contract'\nimport type {\n\tIndexedDBDatabaseInterface,\n\tIndexedDBDatabaseOptions,\n\tIndexedDBStoreInterface,\n\tIndexedDBTransactionInterface,\n\tIndexedDBUpgradeContext,\n\tStoreDefinition,\n\tStoresShape,\n} from './types.js'\nimport { IndexedDBError } from './errors.js'\nimport { guardSync, promisifyTransaction } from './helpers.js'\nimport { IndexedDBStore } from './IndexedDBStore.js'\nimport { IndexedDBTransaction } from './IndexedDBTransaction.js'\nimport { IndexedDBTransactionStore } from './IndexedDBTransactionStore.js'\n\n/**\n * A browser-native IndexedDB database — a typed, Promise-based handle.\n *\n * @remarks\n * Connects lazily on first use (`connect`, also awaited internally by every store\n * operation), creating any missing stores from their definitions inside\n * `onupgradeneeded`. `store` reaches a typed store; `read` / `write` run an atomic\n * scope over one or more stores, committing on resolve and rolling back on a throw;\n * `close` releases the connection and `drop` deletes the database. Schema changes\n * beyond creating new stores (dropping stores, altering indexes) are deferred.\n */\nexport class IndexedDBDatabase<\n\tStores extends StoresShape = StoresShape,\n> implements IndexedDBDatabaseInterface<Stores> {\n\treadonly #name: string\n\treadonly #version: number | undefined\n\treadonly #stores: Stores\n\treadonly #upgrade: ((context: IndexedDBUpgradeContext) => void | Promise<void>) | undefined\n\t#database: IDBDatabase | undefined\n\t#opening: Promise<IDBDatabase> | undefined\n\t#closed = false\n\n\tconstructor(options: IndexedDBDatabaseOptions<Stores>) {\n\t\tif (options.name.length === 0) {\n\t\t\tthrow new IndexedDBError('OPEN', 'Database name must be a non-empty string')\n\t\t}\n\t\tif (\n\t\t\toptions.version !== undefined &&\n\t\t\t(!Number.isInteger(options.version) || options.version < 1)\n\t\t) {\n\t\t\tthrow new IndexedDBError(\n\t\t\t\t'OPEN',\n\t\t\t\t`Database version must be a positive integer, got ${String(options.version)}`,\n\t\t\t)\n\t\t}\n\t\tthis.#name = options.name\n\t\tthis.#version = options.version\n\t\tthis.#stores = options.stores\n\t\tthis.#upgrade = options.upgrade\n\t}\n\n\tget database(): IDBDatabase {\n\t\tif (this.#database === undefined) {\n\t\t\tthrow new IndexedDBError(\n\t\t\t\t'NOT_OPEN',\n\t\t\t\t`Database '${this.#name}' is not open — call connect() first`,\n\t\t\t)\n\t\t}\n\t\treturn this.#database\n\t}\n\n\tget name(): string {\n\t\treturn this.#name\n\t}\n\n\tget version(): number {\n\t\treturn this.#database?.version ?? this.#version ?? 0\n\t}\n\n\tget stores(): readonly string[] {\n\t\tif (this.#database !== undefined) return Array.from(this.#database.objectStoreNames)\n\t\treturn Object.keys(this.#stores)\n\t}\n\n\tget open(): boolean {\n\t\treturn this.#database !== undefined && !this.#closed\n\t}\n\n\tconnect(): Promise<IDBDatabase> {\n\t\tif (this.#closed) {\n\t\t\tthrow new IndexedDBError('CLOSED', `Database '${this.#name}' has been closed`)\n\t\t}\n\t\tif (this.#database !== undefined) return Promise.resolve(this.#database)\n\t\tif (this.#opening !== undefined) return this.#opening\n\t\t// Clear the latch on failure so a later call can retry the open.\n\t\tthis.#opening = this.#open().catch((error: unknown) => {\n\t\t\tthis.#opening = undefined\n\t\t\tthrow error\n\t\t})\n\t\treturn this.#opening\n\t}\n\n\tstore<K extends keyof Stores & string>(name: K): IndexedDBStoreInterface {\n\t\tconst definition = this.#stores[name]\n\t\tif (definition === undefined) {\n\t\t\tthrow new IndexedDBError(\n\t\t\t\t'NOT_FOUND',\n\t\t\t\t`Store '${name}' is not declared on database '${this.#name}'`,\n\t\t\t)\n\t\t}\n\t\treturn new IndexedDBStore(name, definition, () => this.connect())\n\t}\n\n\tread(\n\t\tstores: (keyof Stores & string) | readonly (keyof Stores & string)[],\n\t\tscope: (tx: IndexedDBTransactionInterface<Stores>) => void | Promise<void>,\n\t): Promise<void> {\n\t\treturn this.#run('readonly', stores, scope)\n\t}\n\n\twrite(\n\t\tstores: (keyof Stores & string) | readonly (keyof Stores & string)[],\n\t\tscope: (tx: IndexedDBTransactionInterface<Stores>) => void | Promise<void>,\n\t): Promise<void> {\n\t\treturn this.#run('readwrite', stores, scope)\n\t}\n\n\tclose(): void {\n\t\tthis.#database?.close()\n\t\tthis.#database = undefined\n\t\tthis.#opening = undefined\n\t\tthis.#closed = true\n\t}\n\n\tasync drop(): Promise<void> {\n\t\tthis.close()\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tconst request = globalThis.indexedDB.deleteDatabase(this.#name)\n\t\t\trequest.onsuccess = () => resolve()\n\t\t\trequest.onerror = () =>\n\t\t\t\treject(\n\t\t\t\t\tnew IndexedDBError('UNKNOWN', `Failed to delete database '${this.#name}'`, request.error),\n\t\t\t\t)\n\t\t\trequest.onblocked = () =>\n\t\t\t\treject(\n\t\t\t\t\tnew IndexedDBError(\n\t\t\t\t\t\t'BLOCKED',\n\t\t\t\t\t\t`Deletion of '${this.#name}' is blocked by another connection`,\n\t\t\t\t\t),\n\t\t\t\t)\n\t\t})\n\t}\n\n\t// Open a scoped transaction, run the scope, then commit (or roll back on throw).\n\tasync #run(\n\t\tmode: IDBTransactionMode,\n\t\tstores: (keyof Stores & string) | readonly (keyof Stores & string)[],\n\t\tscope: (tx: IndexedDBTransactionInterface<Stores>) => void | Promise<void>,\n\t): Promise<void> {\n\t\tconst database = await this.connect()\n\t\tconst names = isArray<string>(stores) ? [...stores] : [stores]\n\t\tconst native = guardSync(() => database.transaction(names, mode))\n\t\tconst tx = new IndexedDBTransaction<Stores>(native)\n\t\ttry {\n\t\t\tawait scope(tx)\n\t\t\tawait promisifyTransaction(native)\n\t\t} catch (error) {\n\t\t\tif (tx.active) {\n\t\t\t\ttry {\n\t\t\t\t\ttx.abort()\n\t\t\t\t} catch {\n\t\t\t\t\t// Already settled by the native transaction — nothing to roll back.\n\t\t\t\t}\n\t\t\t}\n\t\t\tthrow error\n\t\t}\n\t}\n\n\t// Open the connection: at the configured version, or — in auto-managed mode (no\n\t// version) — at the database's current version, bumping once to create any\n\t// declared store the stored schema is missing.\n\tasync #open(): Promise<IDBDatabase> {\n\t\tlet database = await this.#request(this.#version)\n\t\tif (this.#version === undefined) {\n\t\t\tconst missing = this.#missing(database)\n\t\t\tif (missing.length > 0) {\n\t\t\t\tconst next = database.version + 1\n\t\t\t\tdatabase.close()\n\t\t\t\tdatabase = await this.#request(next)\n\t\t\t}\n\t\t}\n\t\tdatabase.onclose = () => {\n\t\t\tthis.#database = undefined\n\t\t}\n\t\t// Yield to another context's version-change upgrade instead of blocking it\n\t\t// indefinitely — without this, two tabs over the same database hang: the\n\t\t// second tab's `open` sits in `onblocked` forever because this connection\n\t\t// never closes on its own. `close()` here is self-initiated, so `onclose`\n\t\t// does NOT fire (the browser only fires it when the connection closes for a\n\t\t// reason other than `close()` itself) — clear the same latches `onclose`\n\t\t// clears so a later operation on this handle lazily reconnects instead of\n\t\t// forever holding a closed `#database`.\n\t\tdatabase.onversionchange = () => {\n\t\t\tdatabase.close()\n\t\t\tthis.#database = undefined\n\t\t\tthis.#opening = undefined\n\t\t}\n\t\tthis.#database = database\n\t\treturn database\n\t}\n\n\t// One `indexedDB.open`, creating any missing declared store in `onupgradeneeded`.\n\t#request(version: number | undefined): Promise<IDBDatabase> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\t// Set when `options.upgrade` returns a Promise that rejects — captured\n\t\t\t// here rather than left as a dangling, unhandled rejection, and routed\n\t\t\t// into `onerror` below: the failed upgrade aborts its versionchange\n\t\t\t// transaction, which fails this very open request.\n\t\t\tlet upgradeError: unknown\n\t\t\tconst request =\n\t\t\t\tversion === undefined\n\t\t\t\t\t? globalThis.indexedDB.open(this.#name)\n\t\t\t\t\t: globalThis.indexedDB.open(this.#name, version)\n\t\t\trequest.onupgradeneeded = (event) => {\n\t\t\t\tconst database = request.result\n\t\t\t\tfor (const [name, definition] of Object.entries(this.#stores)) {\n\t\t\t\t\tif (!database.objectStoreNames.contains(name)) {\n\t\t\t\t\t\tthis.#createStore(database, name, definition)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (this.#upgrade !== undefined) {\n\t\t\t\t\tconst transaction = request.transaction\n\t\t\t\t\tif (transaction !== null) {\n\t\t\t\t\t\tconst result = this.#upgrade(this.#context(database, transaction, event))\n\t\t\t\t\t\tif (result !== undefined) {\n\t\t\t\t\t\t\tresult.catch((error: unknown) => {\n\t\t\t\t\t\t\t\tupgradeError = error\n\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\ttransaction.abort()\n\t\t\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t\t\t// Already settled — the versionchange transaction committed or\n\t\t\t\t\t\t\t\t\t// aborted before the rejection arrived; nothing to roll back.\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\trequest.onsuccess = () => resolve(request.result)\n\t\t\trequest.onerror = () =>\n\t\t\t\treject(\n\t\t\t\t\tupgradeError !== undefined\n\t\t\t\t\t\t? new IndexedDBError('UPGRADE', `Upgrade of '${this.#name}' failed`, upgradeError)\n\t\t\t\t\t\t: new IndexedDBError('OPEN', `Failed to open database '${this.#name}'`, request.error),\n\t\t\t\t)\n\t\t\trequest.onblocked = () =>\n\t\t\t\treject(\n\t\t\t\t\tnew IndexedDBError('BLOCKED', `Open of '${this.#name}' is blocked by another connection`),\n\t\t\t\t)\n\t\t})\n\t}\n\n\t// Declared stores the open database does not yet contain.\n\t#missing(database: IDBDatabase): readonly string[] {\n\t\treturn Object.keys(this.#stores).filter((name) => !database.objectStoreNames.contains(name))\n\t}\n\n\t// Build the upgrade context passed to `options.upgrade`, after the built-in\n\t// create-missing-stores pass so `stores` reflects any store just created.\n\t#context(\n\t\tdatabase: IDBDatabase,\n\t\ttransaction: IDBTransaction,\n\t\tevent: IDBVersionChangeEvent,\n\t): IndexedDBUpgradeContext {\n\t\treturn {\n\t\t\ttransaction,\n\t\t\told: event.oldVersion,\n\t\t\tversion: event.newVersion ?? database.version,\n\t\t\tstores: Array.from(database.objectStoreNames),\n\t\t\tcreate: (name, definition) => {\n\t\t\t\tthis.#createStore(database, name, definition)\n\t\t\t},\n\t\t\tdrop: (name) => {\n\t\t\t\tdatabase.deleteObjectStore(name)\n\t\t\t},\n\t\t\tstore: (name) => new IndexedDBTransactionStore(transaction.objectStore(name)),\n\t\t}\n\t}\n\n\t#createStore(database: IDBDatabase, name: string, definition: StoreDefinition): void {\n\t\tconst options: IDBObjectStoreParameters = { autoIncrement: definition.increment ?? false }\n\t\tif (definition.path !== undefined) {\n\t\t\toptions.keyPath = typeof definition.path === 'string' ? definition.path : [...definition.path]\n\t\t}\n\t\tconst store = database.createObjectStore(name, options)\n\t\tfor (const index of definition.indexes ?? []) {\n\t\t\tconst keyPath = typeof index.path === 'string' ? index.path : [...index.path]\n\t\t\tstore.createIndex(index.name, keyPath, {\n\t\t\t\tunique: index.unique ?? false,\n\t\t\t\tmultiEntry: index.multiple ?? false,\n\t\t\t})\n\t\t}\n\t}\n}\n","import type { IndexedDBDatabaseInterface, IndexedDBDatabaseOptions, StoresShape } from './types.js'\nimport { IndexedDBDatabase } from './IndexedDBDatabase.js'\n\n/**\n * Create a browser-native IndexedDB database over a store schema.\n *\n * @remarks\n * The `const` type parameter captures the literal store names, so `db.store(name)`\n * and `db.read` / `db.write` are checked against the declared stores. Stores are\n * created from their definitions the first time the database opens at a new\n * `version`; omit `version` for auto-managed mode, where the database bumps its\n * own version once to create any declared store the stored schema is missing.\n *\n * @param options - The database `name`, `version`, and `stores` schema\n * @returns A typed {@link IndexedDBDatabaseInterface}\n *\n * @example\n * ```ts\n * import { createIndexedDBDatabase, range } from '@src/browser'\n *\n * const db = createIndexedDBDatabase({\n * \tname: 'app',\n * \tversion: 1,\n * \tstores: {\n * \t\tusers: { path: 'id', indexes: [{ name: 'byAge', path: 'age' }] },\n * \t},\n * })\n * await db.store('users').set({ id: 'u1', name: 'Ada', age: 36 })\n * await db.store('users').index('byAge').records(range.from(18)) // adults, index-backed\n * ```\n */\nexport function createIndexedDBDatabase<const Stores extends StoresShape>(\n\toptions: IndexedDBDatabaseOptions<Stores>,\n): IndexedDBDatabaseInterface<Stores> {\n\treturn new IndexedDBDatabase(options)\n}\n"],"x_google_ignoreList":[2],"mappings":";;;;;;;;;AAUA,IAAa,cAA4D,OAAO,OAAO;CACtF,iBAAiB;CACjB,oBAAoB;CACpB,YAAY;CACZ,eAAe;CACf,WAAW;CACX,cAAc;CACd,0BAA0B;CAC1B,mBAAmB;AACpB,CAAC;;;;;;;;;;;;;;;;;;;;;ACSD,IAAa,iBAAb,cAAoC,MAAM;CACzC;CAEA,YAAY,MAA0B,SAAiB,OAAiB;EACvE,MAAM,SAAS,EAAE,MAAM,CAAC;EACxB,KAAK,OAAO;EACZ,KAAK,OAAO;CACb;AACD;;;;;;;AAQA,SAAgB,iBAAiB,OAAyC;CACzE,OAAO,iBAAiB;AACzB;AC3BwB,OAAO,OAAO;CACrC;CACA;CACA;CACA;CACA;CACA;CACA;AACD,CAAC;;;;;;;;AAkJD,SAAS,SAAS,OAAO;CACxB,OAAO,OAAO,UAAU,YAAY,UAAU;AAC/C;;;;;;;;;;;;;;;;;;;AAmBA,SAAS,SAAS,OAAO;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,aAAa,UAAU,MAAM,UAAU;GAC7C;GACA,OAAO,SAAS;IACf,SAAS,kBAAkB,IAAI;GAChC;GACA,QAAQ,SAAS,IAAI,0BAA0B,YAAY,YAAY,IAAI,CAAC;EAC7E;CACD;CAEA,aAAa,UAAuB,MAAc,YAAmC;EACpF,MAAM,UAAoC,EAAE,eAAe,WAAW,aAAa,MAAM;EACzF,IAAI,WAAW,SAAS,KAAA,GACvB,QAAQ,UAAU,OAAO,WAAW,SAAS,WAAW,WAAW,OAAO,CAAC,GAAG,WAAW,IAAI;EAE9F,MAAM,QAAQ,SAAS,kBAAkB,MAAM,OAAO;EACtD,KAAK,MAAM,SAAS,WAAW,WAAW,CAAC,GAAG;GAC7C,MAAM,UAAU,OAAO,MAAM,SAAS,WAAW,MAAM,OAAO,CAAC,GAAG,MAAM,IAAI;GAC5E,MAAM,YAAY,MAAM,MAAM,SAAS;IACtC,QAAQ,MAAM,UAAU;IACxB,YAAY,MAAM,YAAY;GAC/B,CAAC;EACF;CACD;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC5QA,SAAgB,wBACf,SACqC;CACrC,OAAO,IAAI,kBAAkB,OAAO;AACrC"}
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A record stored in, and read from, an object store.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* The value shape every store / index / transaction-store CRUD method reads and
|
|
6
|
+
* writes. A structured-clone value narrowed with `isRecord` at the read
|
|
7
|
+
* boundary (see `helpers.ts`), never an unchecked cast.
|
|
8
|
+
*/
|
|
9
|
+
export type Row = Record<string, unknown>;
|
|
10
|
+
/**
|
|
11
|
+
* A machine-readable {@link IndexedDBError} code.
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* Each maps from a native `DOMException.name` or a wrapper-lifecycle fault:
|
|
15
|
+
* `NOT_OPEN` (used before `connect`), `CLOSED` (used after `close`), `NOT_FOUND`
|
|
16
|
+
* (a `resolve` miss), `CONSTRAINT` (a unique-key violation), `QUOTA` (storage
|
|
17
|
+
* full), `ABORTED` (a transaction rolled back), `BLOCKED` (an open held up by
|
|
18
|
+
* another live connection), `DATA` (an invalid key or value), `OPEN` /
|
|
19
|
+
* `UPGRADE` (a failed open or schema upgrade), `INACTIVE` (the transaction went
|
|
20
|
+
* inactive — IndexedDB's auto-commit fault, raised when an operation runs after
|
|
21
|
+
* a non-IDB `await` deactivated its transaction — reachable through
|
|
22
|
+
* `IndexedDBTransactionStoreInterface`), `INVALID` (native `InvalidStateError` —
|
|
23
|
+
* a defensive mapping for a deleted store/index or similarly invalid native
|
|
24
|
+
* handle; not cleanly reachable through this wrapper's public API, which always
|
|
25
|
+
* opens a fresh transaction or routes through the auto-commit-guarded
|
|
26
|
+
* transaction store above), and `UNKNOWN` (any unmapped fault).
|
|
27
|
+
*/
|
|
28
|
+
export type IndexedDBErrorCode = 'NOT_OPEN' | 'CLOSED' | 'NOT_FOUND' | 'CONSTRAINT' | 'QUOTA' | 'ABORTED' | 'BLOCKED' | 'DATA' | 'OPEN' | 'UPGRADE' | 'INACTIVE' | 'INVALID' | 'UNKNOWN';
|
|
29
|
+
/**
|
|
30
|
+
* A key path — one field, or several for a compound key.
|
|
31
|
+
*
|
|
32
|
+
* @remarks
|
|
33
|
+
* A single string addresses one field; an array addresses a compound key over
|
|
34
|
+
* several fields, in order.
|
|
35
|
+
*/
|
|
36
|
+
export type KeyPath = string | readonly string[];
|
|
37
|
+
/**
|
|
38
|
+
* A secondary index on a store.
|
|
39
|
+
*
|
|
40
|
+
* @remarks
|
|
41
|
+
* `name` identifies the index for `store.index(name)`; `path` is the field(s) it
|
|
42
|
+
* indexes; `unique` enforces one record per indexed value; `multiple` (IndexedDB's
|
|
43
|
+
* `multiEntry`) indexes each element of an array value separately.
|
|
44
|
+
*/
|
|
45
|
+
export interface IndexDefinition {
|
|
46
|
+
readonly name: string;
|
|
47
|
+
readonly path: KeyPath;
|
|
48
|
+
readonly unique?: boolean;
|
|
49
|
+
readonly multiple?: boolean;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* A store's schema.
|
|
53
|
+
*
|
|
54
|
+
* @remarks
|
|
55
|
+
* `path` is the in-line key path (omit it for an **out-of-line** store, where the
|
|
56
|
+
* key is passed explicitly to `set` / `add`); `increment` auto-generates numeric
|
|
57
|
+
* keys; `indexes` declares secondary indexes.
|
|
58
|
+
* Stores are created from these definitions inside `onupgradeneeded`.
|
|
59
|
+
*/
|
|
60
|
+
export interface StoreDefinition {
|
|
61
|
+
readonly path?: KeyPath;
|
|
62
|
+
readonly increment?: boolean;
|
|
63
|
+
readonly indexes?: readonly IndexDefinition[];
|
|
64
|
+
}
|
|
65
|
+
/** A database's stores — a map of store name to its {@link StoreDefinition}. */
|
|
66
|
+
export type StoresShape = Readonly<Record<string, StoreDefinition>>;
|
|
67
|
+
/**
|
|
68
|
+
* The escape hatch into a version-change upgrade, passed to
|
|
69
|
+
* `IndexedDBDatabaseOptions.upgrade`.
|
|
70
|
+
*
|
|
71
|
+
* @remarks
|
|
72
|
+
* Runs INSIDE `onupgradeneeded`, after the built-in create-missing-stores pass —
|
|
73
|
+
* so `stores` already reflects any store just created from the declared schema.
|
|
74
|
+
* `transaction` is the raw versionchange `IDBTransaction`, the escape hatch for
|
|
75
|
+
* native operations this wrapper does not model directly (creating or dropping an
|
|
76
|
+
* index on an EXISTING store, or anything else the raw API offers); `old` /
|
|
77
|
+
* `version` are the prior and target database versions (`old` is `0` on first
|
|
78
|
+
* create); `create` / `drop` add or remove a whole store; `store` reaches a
|
|
79
|
+
* transaction-bound store for data migration. Everything invoked here must stay
|
|
80
|
+
* within the versionchange transaction — no non-IDB `await`, or it auto-commits
|
|
81
|
+
* and the upgrade fails.
|
|
82
|
+
*/
|
|
83
|
+
export interface IndexedDBUpgradeContext {
|
|
84
|
+
readonly transaction: IDBTransaction;
|
|
85
|
+
readonly old: number;
|
|
86
|
+
readonly version: number;
|
|
87
|
+
readonly stores: readonly string[];
|
|
88
|
+
create(name: string, definition: StoreDefinition): void;
|
|
89
|
+
drop(name: string): void;
|
|
90
|
+
store(name: string): IndexedDBTransactionStoreInterface;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Options for `createIndexedDBDatabase`.
|
|
94
|
+
*
|
|
95
|
+
* @remarks
|
|
96
|
+
* `name` is passed to `indexedDB.open`. `version` is optional: give it to pin an
|
|
97
|
+
* explicit schema version (a higher number than the stored one triggers an upgrade
|
|
98
|
+
* that creates any missing `stores`); omit it for **auto-managed** mode, where the
|
|
99
|
+
* database opens at its current version and bumps once to create any declared store
|
|
100
|
+
* the stored schema is missing — so adding a store never needs a manual version
|
|
101
|
+
* bump. `upgrade` runs after the built-in create-missing-stores pass, inside the
|
|
102
|
+
* same versionchange transaction — use it to drop a store, add or remove an index
|
|
103
|
+
* on an existing store (via `context.transaction`), or migrate data with
|
|
104
|
+
* `context.store(name)`. It may return `void` or a `Promise<void>` — an async
|
|
105
|
+
* `upgrade` may `await` the IDB requests it issues through `context.store(...)`
|
|
106
|
+
* (see the auto-commit rule on {@link IndexedDBUpgradeContext}); a rejection
|
|
107
|
+
* aborts the versionchange transaction and rejects the pending `connect()` with
|
|
108
|
+
* an `IndexedDBError` (code `UPGRADE`) instead of an unhandled rejection.
|
|
109
|
+
*/
|
|
110
|
+
export interface IndexedDBDatabaseOptions<Stores extends StoresShape = StoresShape> {
|
|
111
|
+
readonly name: string;
|
|
112
|
+
readonly version?: number;
|
|
113
|
+
readonly stores: Stores;
|
|
114
|
+
readonly upgrade?: (context: IndexedDBUpgradeContext) => void | Promise<void>;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Options for opening a cursor.
|
|
118
|
+
*
|
|
119
|
+
* @remarks
|
|
120
|
+
* `query` restricts iteration to a key range (or a single key); `direction` sets
|
|
121
|
+
* the traversal order (`next` / `prev` / their `unique` variants).
|
|
122
|
+
*/
|
|
123
|
+
export interface CursorOptions {
|
|
124
|
+
readonly query?: IDBKeyRange | IDBValidKey | null;
|
|
125
|
+
readonly direction?: IDBCursorDirection;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* A promisified value cursor for streaming and in-place mutation.
|
|
129
|
+
*
|
|
130
|
+
* @remarks
|
|
131
|
+
* Wraps `IDBCursorWithValue`. `key` / `primary` / `value` snapshot the current
|
|
132
|
+
* position (IndexedDB reuses the live cursor object on advance, so they are read
|
|
133
|
+
* eagerly). `continue` / `seek` / `advance` resolve to the next cursor or `null`
|
|
134
|
+
* at the end; `update` / `delete` mutate the record at the current position. The
|
|
135
|
+
* owning transaction stays alive only while you drive the cursor promptly — do no
|
|
136
|
+
* unrelated `await` between steps, or it auto-commits.
|
|
137
|
+
*/
|
|
138
|
+
export interface IndexedDBCursorInterface {
|
|
139
|
+
readonly cursor: IDBCursorWithValue;
|
|
140
|
+
readonly source: IDBObjectStore | IDBIndex;
|
|
141
|
+
readonly key: IDBValidKey;
|
|
142
|
+
readonly primary: IDBValidKey;
|
|
143
|
+
readonly value: Row;
|
|
144
|
+
readonly direction: IDBCursorDirection;
|
|
145
|
+
continue(key?: IDBValidKey): Promise<IndexedDBCursorInterface | null>;
|
|
146
|
+
seek(key: IDBValidKey, primary: IDBValidKey): Promise<IndexedDBCursorInterface | null>;
|
|
147
|
+
advance(count: number): Promise<IndexedDBCursorInterface | null>;
|
|
148
|
+
update(value: Row): Promise<IDBValidKey>;
|
|
149
|
+
delete(): Promise<void>;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* A secondary index — read access by an indexed key path.
|
|
153
|
+
*
|
|
154
|
+
* @remarks
|
|
155
|
+
* Indexes are read-only views over a store. `get` / `resolve` fetch the first
|
|
156
|
+
* record for an index key (`resolve` throws `NOT_FOUND` on a miss); `records` /
|
|
157
|
+
* `keys` read many (the matching records, and their **primary** keys); `primary`
|
|
158
|
+
* maps an index key to one primary key; `count` / `has` test presence; `cursor`
|
|
159
|
+
* streams matches. A read of several keys is the array overload of the same verb
|
|
160
|
+
* (AGENTS §9.2).
|
|
161
|
+
*/
|
|
162
|
+
export interface IndexedDBIndexInterface {
|
|
163
|
+
readonly name: string;
|
|
164
|
+
readonly path: KeyPath;
|
|
165
|
+
readonly unique: boolean;
|
|
166
|
+
readonly multiple: boolean;
|
|
167
|
+
get(keys: readonly IDBValidKey[]): Promise<readonly (Row | undefined)[]>;
|
|
168
|
+
get(key: IDBValidKey): Promise<Row | undefined>;
|
|
169
|
+
resolve(keys: readonly IDBValidKey[]): Promise<readonly Row[]>;
|
|
170
|
+
resolve(key: IDBValidKey): Promise<Row>;
|
|
171
|
+
records(query?: IDBKeyRange | IDBValidKey | null, count?: number): Promise<readonly Row[]>;
|
|
172
|
+
keys(query?: IDBKeyRange | IDBValidKey | null, count?: number): Promise<readonly IDBValidKey[]>;
|
|
173
|
+
primary(key: IDBValidKey): Promise<IDBValidKey | undefined>;
|
|
174
|
+
has(keys: readonly IDBValidKey[]): Promise<readonly boolean[]>;
|
|
175
|
+
has(key: IDBValidKey): Promise<boolean>;
|
|
176
|
+
count(query?: IDBKeyRange | IDBValidKey | null): Promise<number>;
|
|
177
|
+
cursor(options?: CursorOptions): Promise<IndexedDBCursorInterface | null>;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* An object store — the full keyed CRUD surface, plus index, count, and cursor
|
|
181
|
+
* access.
|
|
182
|
+
*
|
|
183
|
+
* @remarks
|
|
184
|
+
* Each call runs in its own implicit transaction; for atomic multi-operation work
|
|
185
|
+
* use the database's `read` / `write`. `get` / `resolve` read by key (`resolve`
|
|
186
|
+
* throws `NOT_FOUND`); `records` / `keys` read many over an optional key range;
|
|
187
|
+
* `set` upserts and `add` inserts (throwing `CONSTRAINT` on a duplicate);
|
|
188
|
+
* `remove` deletes; `clear` empties the store. The keyed verbs batch by their
|
|
189
|
+
* array overload — listed first, since an array is itself a valid record and a
|
|
190
|
+
* compound `IDBValidKey`, so the array signature must win (AGENTS §9.2). To act on
|
|
191
|
+
* a single **compound** key, pass `range.only([…])` to `records` / `count`.
|
|
192
|
+
*/
|
|
193
|
+
export interface IndexedDBStoreInterface {
|
|
194
|
+
readonly name: string;
|
|
195
|
+
readonly path: KeyPath | null;
|
|
196
|
+
readonly indexes: readonly string[];
|
|
197
|
+
readonly increment: boolean;
|
|
198
|
+
get(keys: readonly IDBValidKey[]): Promise<readonly (Row | undefined)[]>;
|
|
199
|
+
get(key: IDBValidKey): Promise<Row | undefined>;
|
|
200
|
+
resolve(keys: readonly IDBValidKey[]): Promise<readonly Row[]>;
|
|
201
|
+
resolve(key: IDBValidKey): Promise<Row>;
|
|
202
|
+
records(query?: IDBKeyRange | IDBValidKey | null, count?: number): Promise<readonly Row[]>;
|
|
203
|
+
keys(query?: IDBKeyRange | IDBValidKey | null, count?: number): Promise<readonly IDBValidKey[]>;
|
|
204
|
+
has(keys: readonly IDBValidKey[]): Promise<readonly boolean[]>;
|
|
205
|
+
has(key: IDBValidKey): Promise<boolean>;
|
|
206
|
+
count(query?: IDBKeyRange | IDBValidKey | null): Promise<number>;
|
|
207
|
+
set(values: readonly Row[]): Promise<readonly IDBValidKey[]>;
|
|
208
|
+
set(value: Row, key?: IDBValidKey): Promise<IDBValidKey>;
|
|
209
|
+
add(values: readonly Row[]): Promise<readonly IDBValidKey[]>;
|
|
210
|
+
add(value: Row, key?: IDBValidKey): Promise<IDBValidKey>;
|
|
211
|
+
remove(keys: readonly IDBValidKey[]): Promise<void>;
|
|
212
|
+
remove(key: IDBValidKey): Promise<void>;
|
|
213
|
+
clear(): Promise<void>;
|
|
214
|
+
index(name: string): IndexedDBIndexInterface;
|
|
215
|
+
cursor(options?: CursorOptions): Promise<IndexedDBCursorInterface | null>;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* An object store bound to an explicit transaction.
|
|
219
|
+
*
|
|
220
|
+
* @remarks
|
|
221
|
+
* The same CRUD surface as {@link IndexedDBStoreInterface}, but every call runs in
|
|
222
|
+
* the owning transaction (opened by the database's `read` / `write`) rather than
|
|
223
|
+
* its own — so a sequence of reads and writes is atomic. It drops `index` and the
|
|
224
|
+
* standalone implicit-transaction conveniences; reach the live `store` for those.
|
|
225
|
+
*/
|
|
226
|
+
export interface IndexedDBTransactionStoreInterface {
|
|
227
|
+
readonly store: IDBObjectStore;
|
|
228
|
+
get(keys: readonly IDBValidKey[]): Promise<readonly (Row | undefined)[]>;
|
|
229
|
+
get(key: IDBValidKey): Promise<Row | undefined>;
|
|
230
|
+
resolve(keys: readonly IDBValidKey[]): Promise<readonly Row[]>;
|
|
231
|
+
resolve(key: IDBValidKey): Promise<Row>;
|
|
232
|
+
records(query?: IDBKeyRange | IDBValidKey | null, count?: number): Promise<readonly Row[]>;
|
|
233
|
+
keys(query?: IDBKeyRange | IDBValidKey | null, count?: number): Promise<readonly IDBValidKey[]>;
|
|
234
|
+
has(keys: readonly IDBValidKey[]): Promise<readonly boolean[]>;
|
|
235
|
+
has(key: IDBValidKey): Promise<boolean>;
|
|
236
|
+
count(query?: IDBKeyRange | IDBValidKey | null): Promise<number>;
|
|
237
|
+
set(values: readonly Row[]): Promise<readonly IDBValidKey[]>;
|
|
238
|
+
set(value: Row, key?: IDBValidKey): Promise<IDBValidKey>;
|
|
239
|
+
add(values: readonly Row[]): Promise<readonly IDBValidKey[]>;
|
|
240
|
+
add(value: Row, key?: IDBValidKey): Promise<IDBValidKey>;
|
|
241
|
+
remove(keys: readonly IDBValidKey[]): Promise<void>;
|
|
242
|
+
remove(key: IDBValidKey): Promise<void>;
|
|
243
|
+
clear(): Promise<void>;
|
|
244
|
+
cursor(options?: CursorOptions): Promise<IndexedDBCursorInterface | null>;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* An explicit transaction over one or more stores.
|
|
248
|
+
*
|
|
249
|
+
* @remarks
|
|
250
|
+
* Obtained through the `scope` callback of the database's `read` / `write`. `store`
|
|
251
|
+
* reaches a typed, transaction-bound store; the transaction commits automatically
|
|
252
|
+
* when the scope resolves, or rolls back if it throws or `abort` is called.
|
|
253
|
+
* `active` is true while it still accepts operations; `finished` is true after
|
|
254
|
+
* commit or abort.
|
|
255
|
+
*/
|
|
256
|
+
export interface IndexedDBTransactionInterface<Stores extends StoresShape = StoresShape> {
|
|
257
|
+
readonly transaction: IDBTransaction;
|
|
258
|
+
readonly mode: IDBTransactionMode;
|
|
259
|
+
readonly stores: readonly string[];
|
|
260
|
+
readonly active: boolean;
|
|
261
|
+
readonly finished: boolean;
|
|
262
|
+
readonly error: DOMException | null;
|
|
263
|
+
store<K extends keyof Stores & string>(name: K): IndexedDBTransactionStoreInterface;
|
|
264
|
+
abort(): void;
|
|
265
|
+
commit(): void;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* A browser-native IndexedDB database.
|
|
269
|
+
*
|
|
270
|
+
* @remarks
|
|
271
|
+
* A typed, Promise-based handle over `IDBDatabase`. It connects lazily on first
|
|
272
|
+
* use (`connect`, also awaited by every store operation); `store` reaches a typed
|
|
273
|
+
* store; `read` / `write` run an atomic scope over one or more stores; `close`
|
|
274
|
+
* releases the connection and `drop` deletes the database. `stores` lists the
|
|
275
|
+
* declared (or, once open, the live) store names; `open` reports whether a live
|
|
276
|
+
* connection is held.
|
|
277
|
+
*/
|
|
278
|
+
export interface IndexedDBDatabaseInterface<Stores extends StoresShape = StoresShape> {
|
|
279
|
+
readonly database: IDBDatabase;
|
|
280
|
+
readonly name: string;
|
|
281
|
+
readonly version: number;
|
|
282
|
+
readonly stores: readonly string[];
|
|
283
|
+
readonly open: boolean;
|
|
284
|
+
connect(): Promise<IDBDatabase>;
|
|
285
|
+
store<K extends keyof Stores & string>(name: K): IndexedDBStoreInterface;
|
|
286
|
+
read(stores: (keyof Stores & string) | readonly (keyof Stores & string)[], scope: (tx: IndexedDBTransactionInterface<Stores>) => void | Promise<void>): Promise<void>;
|
|
287
|
+
write(stores: (keyof Stores & string) | readonly (keyof Stores & string)[], scope: (tx: IndexedDBTransactionInterface<Stores>) => void | Promise<void>): Promise<void>;
|
|
288
|
+
close(): void;
|
|
289
|
+
drop(): Promise<void>;
|
|
290
|
+
}
|