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A;AACY,IAAA;AACb,EAAA;AACD;AAsBoD;AAC1C,EAAA;AACA,EAAA;AACY,iBAAA;AAEqE,EAAA;AACzF,IAAA;AAC6C,MAAA;AAC5C,MAAA;AACA,MAAA;AACwC,QAAA;AACtB,QAAA;AACE,QAAA;AACF,QAAA;AACN,QAAA;AACZ,MAAA;AACD,IAAA;AACY,IAAA;AACY,IAAA;AACD,IAAA;AACxB,EAAA;AACD;AAW6C;AAK1C,EAAA;AACD,IAAA;AACoB,MAAA;AACnB,MAAA;AACmC,MAAA;AACpC,IAAA;AARgB,IAAA;AACA,IAAA;AACA,IAAA;AAOJ,IAAA;AACb,EAAA;AAViB,EAAA;AACA,EAAA;AACA,EAAA;AASlB;AAQO;AACsB,EAAA;AAC3B,IAAA;AACoB,MAAA;AACnB,MAAA;AACS,MAAA;AACV,IAAA;AACY,IAAA;AACb,EAAA;AACD;AAM4C;AACf,EAAA;AAC3B,IAAA;AACwC,MAAA;AACvC,MAAA;AACS,MAAA;AACV,IAAA;AACY,IAAA;AACb,EAAA;AACD;AAQoD;AAIjD,EAAA;AACD,IAAA;AACyC,MAAA;AACxC,MAAA;AACA,MAAA;AACC,QAAA;AACkB,QAAA;AACb,QAAA;AACN,MAAA;AACD,IAAA;AAXgB,IAAA;AACA,IAAA;AAWJ,IAAA;AACb,EAAA;AAbiB,EAAA;AACA,EAAA;AAalB;ADtLmD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/kora/kora/packages/store/dist/chunk-FJFDMAUT.cjs","sourcesContent":[null,"import { KoraError } from '@korajs/core/lite'\n\n// Kept in its own file so the first-paint entry (`lite`) does not load every error class below.\nexport { QueryError } from './query/query-error'\n\n/**\n * Thrown on an insert into a collection with a field declared `t.string().stamp('userId')`\n * when Kora cannot fill it: the app does not know the signed-in user yet, or the insert\n * names another user.\n */\nexport class StampedFieldError extends KoraError {\n\tconstructor(\n\t\tmessage: string,\n\t\tcode: 'STAMP_USER_UNKNOWN' | 'STAMP_MISMATCH',\n\t\tcontext: Record<string, unknown>,\n\t) {\n\t\tsuper(message, code, context)\n\t\tthis.name = 'StampedFieldError'\n\t}\n}\n\n/**\n * Thrown when a record is not found by ID (findById, update, delete on missing record).\n */\nexport class RecordNotFoundError extends KoraError {\n\tconstructor(collection: string, recordId: string) {\n\t\tsuper(`Record \"${recordId}\" not found in collection \"${collection}\"`, 'RECORD_NOT_FOUND', {\n\t\t\tcollection,\n\t\t\trecordId,\n\t\t})\n\t\tthis.name = 'RecordNotFoundError'\n\t}\n}\n\n/**\n * Thrown inside `applyRemoteOperation` when the row's version state changed\n * between the caller's snapshot read and the guarded write (a concurrent local\n * mutation landed in the window). The transaction is rolled back with nothing\n * written; the caller re-reads fresh state, recomputes its merge, and retries.\n * This is the optimistic-concurrency guard that keeps merge-engine results\n * (richtext, add-wins arrays, constraint resolutions) from clobbering newer\n * local edits they never saw.\n */\nexport class OptimisticLockError extends KoraError {\n\tconstructor(collection: string, recordId: string) {\n\t\tsuper(\n\t\t\t`Row version changed while merging record \"${recordId}\" in \"${collection}\"; retry with fresh state`,\n\t\t\t'OPTIMISTIC_LOCK',\n\t\t\t{ collection, recordId },\n\t\t)\n\t\tthis.name = 'OptimisticLockError'\n\t}\n}\n\n/**\n * Thrown when a storage adapter operation fails.\n */\nexport class AdapterError extends KoraError {\n\tconstructor(message: string, context?: Record<string, unknown>) {\n\t\tsuper(message, 'ADAPTER_ERROR', context)\n\t\tthis.name = 'AdapterError'\n\t}\n}\n\n/**\n * Thrown when a write reaches a storage adapter that could not obtain durable\n * storage (it opened, or was promoted to leader, on a non-persistent in-memory\n * database). Kora refuses such writes instead of accepting data that would be\n * lost on reload. Reads still work.\n *\n * Fix: close other tabs or apps using the same origin's OPFS storage and reopen,\n * or opt in explicitly with `allowNonDurable: true` if in-memory storage is\n * acceptable for this app.\n */\nexport class StorageDurabilityError extends KoraError {\n\tconstructor(dbName: string, phase: 'open' | 'promotion', reason: string) {\n\t\tsuper(\n\t\t\t`Database \"${dbName}\" has no durable storage (${reason} during ${phase}); writes are refused so they are not silently lost on reload. Close other tabs or apps using this origin's storage and reload, or set allowNonDurable: true to accept in-memory storage.`,\n\t\t\t'STORAGE_DURABILITY_LOST',\n\t\t\t{ dbName, phase, reason },\n\t\t)\n\t\tthis.name = 'StorageDurabilityError'\n\t}\n}\n\n/**\n * A local write committed to the live database but its backend could not prove\n * that the commit reached durable storage before the write promise returned.\n *\n * The operation still exists in the open store and may already be queued for\n * sync. Callers must not retry it blindly: doing so can duplicate an application\n * action. Keep the app open, surface the failure, and let Kora retry persistence.\n */\nexport class WriteNotDurableError extends KoraError {\n\tpublic override readonly cause: unknown\n\n\tconstructor(\n\t\tpublic readonly operationIds: readonly string[],\n\t\tcause: unknown,\n\t) {\n\t\tconst operationId = operationIds[0] ?? null\n\t\tconst causeCode = durabilityCauseCode(cause)\n\t\tconst superseded = causeCode === 'SNAPSHOT_SUPERSEDED'\n\t\tsuper(\n\t\t\tsuperseded\n\t\t\t\t? 'The change was applied in this tab, but its storage snapshot was superseded and the change may not have been saved. Do not repeat the action blindly; reload the app before making more changes.'\n\t\t\t\t: 'The change was applied locally but could not be confirmed on durable storage. Do not retry it blindly; keep the app open and free storage if needed.',\n\t\t\t'WRITE_NOT_DURABLE',\n\t\t\t{\n\t\t\t\toperationId,\n\t\t\t\toperationIds: [...operationIds],\n\t\t\t\tcauseCode,\n\t\t\t\tfix: superseded\n\t\t\t\t\t? 'Reload the app before making more changes. Do not repeat the action unless the user verifies that it is absent.'\n\t\t\t\t\t: 'Keep the app open and free storage if needed. Do not repeat the action: the local write already committed and Kora will retry persistence.',\n\t\t\t},\n\t\t)\n\t\tthis.name = 'WriteNotDurableError'\n\t\tthis.cause = cause\n\t}\n\n\t/** The first operation, for the common single-record write case. */\n\tget operationId(): string | null {\n\t\treturn this.operationIds[0] ?? null\n\t}\n}\n\nfunction durabilityCauseCode(cause: unknown): string | undefined {\n\tif (typeof cause !== 'object' || cause === null) return undefined\n\tif ('context' in cause && typeof cause.context === 'object' && cause.context !== null) {\n\t\tconst context = cause.context as { code?: unknown }\n\t\tif (typeof context.code === 'string') return context.code\n\t}\n\tif ('code' in cause && typeof cause.code === 'string') return cause.code\n\treturn undefined\n}\n\n/**\n * Thrown when the store opens a database a NEWER build of the app already migrated: its\n * stored schema version is above this code's `schema.version` (RT-109). Running older\n * code against it would write operations of the old schema into the new one, or fail\n * part-way, so the store refuses before changing anything and emits `store:schema-ahead`.\n *\n * Fix: run the newer build (reload while online, or accept the app's update prompt).\n * Never lower `schema.version` in a deployed app.\n */\nexport class SchemaVersionAheadError extends KoraError {\n\tconstructor(\n\t\tpublic readonly dbName: string,\n\t\tpublic readonly storedVersion: number,\n\t\tpublic readonly codeVersion: number,\n\t) {\n\t\tsuper(\n\t\t\t`Database \"${dbName}\" is at schema version ${storedVersion}, newer than this build's schema version ${codeVersion}: a newer build of the app already migrated it. It was not opened and nothing in it changed. Run the newer build (reload while online, or accept the update); never lower schema.version in a deployed app.`,\n\t\t\t'SCHEMA_VERSION_AHEAD',\n\t\t\t{ dbName, storedVersion, codeVersion },\n\t\t)\n\t\tthis.name = 'SchemaVersionAheadError'\n\t}\n}\n\n/**\n * Thrown when an operation is attempted on a store that has not been opened.\n */\nexport class StoreNotOpenError extends KoraError {\n\tconstructor() {\n\t\tsuper('Store is not open. Call store.open() before performing operations.', 'STORE_NOT_OPEN')\n\t\tthis.name = 'StoreNotOpenError'\n\t}\n}\n\n/**\n * Thrown when the Web Worker fails to initialize (WASM load failure, OPFS unavailable, etc.).\n */\nexport class WorkerInitError extends KoraError {\n\tconstructor(message: string, context?: Record<string, unknown>) {\n\t\tsuper(`Worker initialization failed: ${message}`, 'WORKER_INIT_ERROR', context)\n\t\tthis.name = 'WorkerInitError'\n\t}\n}\n\n/**\n * Thrown when the Web Worker does not respond within the configured timeout.\n */\nexport class WorkerTimeoutError extends KoraError {\n\tconstructor(operation: string, timeoutMs: number) {\n\t\tsuper(\n\t\t\t`Worker did not respond within ${timeoutMs}ms for operation \"${operation}\"`,\n\t\t\t'WORKER_TIMEOUT',\n\t\t\t{ operation, timeoutMs },\n\t\t)\n\t\tthis.name = 'WorkerTimeoutError'\n\t}\n}\n\n/**\n * Thrown when a follower tab cannot reach a live leader tab over the multi-tab\n * broadcast channel (the leader tab was closed, crashed, or is unresponsive).\n * Distinct from {@link WorkerTimeoutError}: this fails fast on a confirmed-absent\n * leader instead of waiting out the full RPC timeout.\n */\nexport class NoLeaderError extends KoraError {\n\tconstructor(\n\t\toperation: string,\n\t\tmessage = `No live leader tab is answering multi-tab storage RPC for operation \"${operation}\"`,\n\t\tcode = 'NO_LEADER',\n\t\tcontext: Record<string, unknown> = {},\n\t) {\n\t\tsuper(message, code, { operation, ...context })\n\t\tthis.name = 'NoLeaderError'\n\t}\n}\n\n/**\n * Thrown to a follower tab's pending storage requests when the leader tab that\n * was answering stopped sending heartbeats (hung, frozen, or suspended). The\n * request may or may not have been applied: retry it with the same `requestId`\n * (in the error context). The same leader de-duplicates it; a leader that took\n * over since keeps no record of it, so a retried write may then apply twice.\n * Retriable.\n */\nexport class LeaderUnresponsiveError extends NoLeaderError {\n\tconstructor(operation: string, silentMs: number, requestId: string) {\n\t\tsuper(\n\t\t\toperation,\n\t\t\t`The leader tab stopped responding (no heartbeat for ${silentMs}ms) during \"${operation}\". The request may or may not have been applied; retry it with the same requestId: the same leader de-duplicates it, but a leader that took over since cannot.`,\n\t\t\t'LEADER_UNRESPONSIVE',\n\t\t\t{ silentMs, requestId, retriable: true },\n\t\t)\n\t\tthis.name = 'LeaderUnresponsiveError'\n\t}\n}\n\n/**\n * Thrown to pending storage requests when their bridge was torn down, typically\n * because this tab was just promoted to leader or the leader handed over.\n * Retriable: the next attempt goes to the new leader.\n */\nexport class BridgeTerminatedError extends KoraError {\n\tconstructor(operation: string, reason: string) {\n\t\tsuper(\n\t\t\t`Storage request \"${operation}\" was interrupted (${reason}); retry it against the new storage leader.`,\n\t\t\t'BRIDGE_TERMINATED',\n\t\t\t{ operation, reason, retriable: true },\n\t\t)\n\t\tthis.name = 'BridgeTerminatedError'\n\t}\n}\n\n/** Thrown when a storage request is cancelled through its `AbortSignal`. */\nexport class RequestAbortedError extends KoraError {\n\tconstructor(operation: string, requestId: string) {\n\t\tsuper(\n\t\t\t`Storage request \"${operation}\" was aborted by the caller. A write may already have reached the leader; retry with the same requestId to stay idempotent.`,\n\t\t\t'REQUEST_ABORTED',\n\t\t\t{ operation, requestId },\n\t\t)\n\t\tthis.name = 'RequestAbortedError'\n\t}\n}\n\n/**\n * Thrown when an explicit local-database management operation needs exclusive\n * access but the database is open in some tab or worker on this origin.\n */\nexport class StorageInUseError extends KoraError {\n\tconstructor(dbName: string) {\n\t\tsuper(\n\t\t\t`Database \"${dbName}\" is open in a tab on this origin; close it before managing its local storage.`,\n\t\t\t'STORAGE_IN_USE',\n\t\t\t{ dbName },\n\t\t)\n\t\tthis.name = 'StorageInUseError'\n\t}\n}\n\n/** Thrown when an explicitly named local database does not exist. */\nexport class LocalDatabaseNotFoundError extends KoraError {\n\tconstructor(dbName: string) {\n\t\tsuper(`Database \"${dbName}\" does not exist on this origin.`, 'LOCAL_DATABASE_NOT_FOUND', {\n\t\t\tdbName,\n\t\t})\n\t\tthis.name = 'LocalDatabaseNotFoundError'\n\t}\n}\n\n/**\n * Thrown by `deleteDatabase()` when the database still holds operations that\n * never reached the server. Sync first, or pass `{ force: true }` to discard them.\n */\nexport class UnsyncedDataError extends KoraError {\n\tconstructor(dbName: string) {\n\t\tsuper(\n\t\t\t`Database \"${dbName}\" has unsynced operations; deleting it would lose them. Sync first, or pass { force: true } to discard them deliberately.`,\n\t\t\t'UNSYNCED_DATA',\n\t\t\t{ dbName },\n\t\t)\n\t\tthis.name = 'UnsyncedDataError'\n\t}\n}\n\n/**\n * Thrown when a database's data lives in a storage backend this runtime cannot\n * read (for example it was written to OPFS, and OPFS is unavailable now). Kora\n * refuses to start an empty, disjoint copy rather than hide the existing data.\n */\nexport class StorageBackendMismatchError extends KoraError {\n\tconstructor(dbName: string, recorded: string, requested: string, reason: string) {\n\t\tsuper(\n\t\t\t`Database \"${dbName}\" is stored in ${recorded}, but this session can only use ${requested} (${reason}). Kora will not start a separate empty copy; reload in a browser profile where ${recorded} is available.`,\n\t\t\t'STORAGE_BACKEND_MISMATCH',\n\t\t\t{ dbName, recorded, requested, reason },\n\t\t)\n\t\tthis.name = 'StorageBackendMismatchError'\n\t}\n}\n\n/**\n * Thrown when IndexedDB persistence operations fail (serialize/deserialize).\n */\nexport class PersistenceError extends KoraError {\n\tconstructor(message: string, context?: Record<string, unknown>) {\n\t\tsuper(`Persistence error: ${message}`, 'PERSISTENCE_ERROR', context)\n\t\tthis.name = 'PersistenceError'\n\t}\n}\n\n/**\n * Thrown by a local write while the store's pinned node id (an auth device id) belongs\n * to another user than the one signed in (F9): a browser two users shared. The write\n * could only be stored under the owner's node and would later upload as the owner's.\n */\nexport class NodeOwnedByAnotherUserError extends KoraError {\n\tconstructor(nodeId: string, principal: string | null) {\n\t\tsuper(\n\t\t\t\"This device belongs to another account, so changes made while this account is signed in here cannot be saved: they would be uploaded as the device owner's. Sign in as the device's owner, or use this account on its own device.\",\n\t\t\t'NODE_OWNED_BY_ANOTHER_USER',\n\t\t\t{ nodeId, principal },\n\t\t)\n\t\tthis.name = 'NodeOwnedByAnotherUserError'\n\t}\n}\n\n// Its own module so the first-paint (lite) entry can carry it.\nexport { StoreReadOnlyError } from './read-only-error'\n\n/** Builds named in a {@link BuildSupersededError}. */\nexport interface BuildSupersededInfo {\n\t/** The build this tab runs. */\n\tcurrentBuild: string\n\t/** The build of the tab that superseded it. */\n\tnewerBuild: string\n}\n\n/**\n * Thrown by a write started in a tab that a tab running a newer build of the app (or a\n * later-opened deployment) has superseded (version gate). Nothing of the write was\n * applied. The tab is retiring: it shows \"A new version of this app is available. Reload\n * to continue.\" and only a reload, which loads the newer build, brings writes back.\n * Retriable after the reload. A local refusal: never a server rejection.\n *\n * Carries the collection and operation that were refused, never the data.\n */\nexport class BuildSupersededError extends KoraError {\n\treadonly collection: string | undefined\n\treadonly operation: string\n\treadonly retriable = true\n\n\tconstructor(scope: { collection?: string; operation: string }, info: BuildSupersededInfo) {\n\t\tsuper(\n\t\t\t`A newer version of this app (build \"${info.newerBuild}\") is open in another tab, so this tab (build \"${info.currentBuild}\") no longer writes to the local database: ${scope.operation}${scope.collection ? ` on \"${scope.collection}\"` : ''} was not applied. Reload the page to continue with the new version.`,\n\t\t\t'BUILD_SUPERSEDED',\n\t\t\t{\n\t\t\t\t...(scope.collection !== undefined ? { collection: scope.collection } : {}),\n\t\t\t\toperation: scope.operation,\n\t\t\t\tcurrentBuild: info.currentBuild,\n\t\t\t\tnewerBuild: info.newerBuild,\n\t\t\t\tretriable: true,\n\t\t\t},\n\t\t)\n\t\tthis.name = 'BuildSupersededError'\n\t\tthis.collection = scope.collection\n\t\tthis.operation = scope.operation\n\t}\n}\n\n/**\n * Thrown when the local database was opened by a build whose Kora storage format is newer\n * than this code's (version gate, section 3). Older code does not know the newer layout of\n * Kora's internal tables and keys, so the store refuses before writing anything and emits\n * `store:format-ahead`. Like a schema ahead, it never falls back to an empty database.\n *\n * Fix: run the newer build (reload while online). A release that bumps the format cannot\n * be rolled back by redeploying an earlier build.\n */\nexport class StorageFormatAheadError extends KoraError {\n\tconstructor(\n\t\tpublic readonly dbName: string,\n\t\tpublic readonly storedFormat: number,\n\t\tpublic readonly codeFormat: number,\n\t) {\n\t\tsuper(\n\t\t\t`Database \"${dbName}\" uses Kora storage format ${storedFormat}, newer than this build's format ${codeFormat}: a newer build of the app already opened it. It was not opened and nothing in it changed. Run the newer build (reload while online).`,\n\t\t\t'STORAGE_FORMAT_AHEAD',\n\t\t\t{ dbName, storedFormat, codeFormat },\n\t\t)\n\t\tthis.name = 'StorageFormatAheadError'\n\t}\n}\n\n/**\n * Thrown when a browser has no Web Locks: without them Kora cannot keep two tabs from\n * keeping separate copies of the database and overwriting each other's writes, so storage\n * open is refused (version gate, section 4.1.1). Every browser Kora supports has Web\n * Locks; test environments (jsdom, happy-dom) set `store.allowUncoordinatedTabs: true`.\n */\nexport class TabCoordinationUnavailableError extends KoraError {\n\tconstructor(dbName: string) {\n\t\tsuper(\n\t\t\t`Database \"${dbName}\" was not opened: this browser has no Web Locks (navigator.locks), so Kora cannot keep two tabs of the app from overwriting each other's writes. Use a current browser. In a test environment without Web Locks, set store.allowUncoordinatedTabs: true.`,\n\t\t\t'TAB_COORDINATION_UNAVAILABLE',\n\t\t\t{ dbName },\n\t\t)\n\t\tthis.name = 'TabCoordinationUnavailableError'\n\t}\n}\n\n/**\n * Thrown by a pending version gate open (or resume) when the gate was closed meanwhile\n * (the app or adapter closed while it waited for an older tab): storage does not open.\n */\nexport class VersionGateClosedError extends KoraError {\n\tconstructor(dbName: string) {\n\t\tsuper(\n\t\t\t`The version gate of database \"${dbName}\" was closed before it opened; the database was not opened.`,\n\t\t\t'VERSION_GATE_CLOSED',\n\t\t\t{ dbName },\n\t\t)\n\t\tthis.name = 'VersionGateClosedError'\n\t}\n}\n\n/**\n * Raised (in test builds only, `NODE_ENV=test`) when the instant-updates overlay predicted\n * something the database then disagreed with. Production builds report the same fact as\n * the `store:overlay-diverged` event and keep going; a test build fails loudly so a\n * prediction bug is found by the app's own tests (docs/design/instant-ui-updates.md 6 and 12).\n */\nexport class OverlayDivergedError extends KoraError {\n\tconstructor(\n\t\tpublic readonly collection: string,\n\t\tpublic readonly fields: readonly string[],\n\t) {\n\t\tsuper(\n\t\t\t`Instant updates predicted \"${collection}\" differently from the database (${fields.join(', ')}). The database was right and is what the UI shows now.`,\n\t\t\t'OVERLAY_DIVERGED',\n\t\t\t{\n\t\t\t\tcollection,\n\t\t\t\tfields: [...fields],\n\t\t\t\tfix: 'Report this with the write that caused it, and pass { durable: true } to that write to skip the prediction in the meantime.',\n\t\t\t},\n\t\t)\n\t\tthis.name = 'OverlayDivergedError'\n\t}\n}\n"]}