{"version":3,"sources":["/home/runner/work/kora/kora/packages/store/dist/chunk-XFC5V2H7.cjs","../src/adapters/opfs-names.ts"],"names":[],"mappings":"AAAA;ACWO,IAAM,sBAAA,EAAwB,WAAA;AAG9B,IAAM,iBAAA,EAAmB,YAAA;AAMhC,IAAM,qBAAA,EAAuB,EAAA;AAMtB,SAAS,UAAA,CAAW,KAAA,EAAuB;AACjD,EAAA,IAAI,KAAA,EAAO,UAAA;AACX,EAAA,IAAA,CAAA,IAAS,EAAA,EAAI,CAAA,EAAG,EAAA,EAAI,KAAA,CAAM,MAAA,EAAQ,EAAA,GAAK,CAAA,EAAG;AACzC,IAAA,KAAA,GAAQ,KAAA,CAAM,UAAA,CAAW,CAAC,CAAA;AAC1B,IAAA,KAAA,EAAO,IAAA,CAAK,IAAA,CAAK,IAAA,EAAM,QAAU,CAAA;AAAA,EAClC;AACA,EAAA,OAAA,CAAQ,KAAA,IAAS,CAAA,CAAA,CAAG,QAAA,CAAS,EAAE,CAAA,CAAE,QAAA,CAAS,CAAA,EAAG,GAAG,CAAA;AACjD;AASO,SAAS,eAAA,CAAgB,MAAA,EAAwB;AACvD,EAAA,MAAM,UAAA,EAAY,MAAA,CAAO,OAAA,CAAQ,iBAAA,EAAmB,GAAG,CAAA;AACvD,EAAA,MAAM,KAAA,EAAO,SAAA,CAAU,KAAA,CAAM,CAAA,EAAG,oBAAoB,CAAA;AACpD,EAAA,GAAA,CAAI,KAAA,IAAS,MAAA,EAAQ;AACpB,IAAA,OAAO,CAAA,EAAA;AACR,EAAA;AACU,EAAA;AACX;AAGgB;AACR,EAAA;AACR;AAOgB;AACR,EAAA;AACR;AAGgB;AACR,EAAA;AACR;AAOgB;AACR,EAAA;AACR;AAQgB;AACR,EAAA;AACR;AAGgB;AACR,EAAA;AACR;AAGgB;AACT,EAAA;AACC,EAAA;AACR;AAGgB;AACR,EAAA;AACR;AD1DY;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/kora/kora/packages/store/dist/chunk-XFC5V2H7.cjs","sourcesContent":[null,"/**\n * Names shared by the main thread and the SQLite worker for OPFS pools, Web Locks\n * and database files. Pure functions, so ownership rules are testable in Node.\n *\n * Ownership model (W8a, NEW-STORE-5): one OPFS SyncAccessHandle pool per\n * database. The tab leader lock (`kora-leader-<db>`) already guarantees one\n * leader tab per database, so a pool per database means two different databases\n * on one origin (per-user databases, two Kora apps) never contend for one pool.\n */\n\n/** Pool name every database used before W8a (beta.12 and earlier): one per origin. */\nexport const LEGACY_OPFS_POOL_NAME = 'kora-opfs'\n\n/** Prefix of the per-database pool names. */\nexport const OPFS_POOL_PREFIX = 'kora-opfs-'\n\n/**\n * Longest readable database slug kept in a pool name. Pool names become OPFS\n * directory names (`.<pool>`) and VFS names, so they stay short and portable.\n */\nconst MAX_POOL_SLUG_LENGTH = 48\n\n/**\n * 32-bit FNV-1a hash as 8 hex digits. Used only to keep pool names unique when\n * a database name had to be sanitized or truncated; not a security primitive.\n */\nexport function fnv1a32Hex(value: string): string {\n\tlet hash = 0x811c9dc5\n\tfor (let i = 0; i < value.length; i += 1) {\n\t\thash ^= value.charCodeAt(i)\n\t\thash = Math.imul(hash, 0x01000193)\n\t}\n\treturn (hash >>> 0).toString(16).padStart(8, '0')\n}\n\n/**\n * The OPFS SAH pool that owns `dbName`. Database names that are already safe\n * map to `kora-opfs-<dbName>`; anything sanitized or truncated gets a hash suffix\n * so two distinct names can never share a pool.\n *\n * @example opfsPoolNameFor('school__user_alice') === 'kora-opfs-school__user_alice'\n */\nexport function opfsPoolNameFor(dbName: string): string {\n\tconst sanitized = dbName.replace(/[^a-zA-Z0-9_-]/g, '_')\n\tconst slug = sanitized.slice(0, MAX_POOL_SLUG_LENGTH)\n\tif (slug === dbName) {\n\t\treturn `${OPFS_POOL_PREFIX}${slug}`\n\t}\n\treturn `${OPFS_POOL_PREFIX}${slug}-${fnv1a32Hex(dbName)}`\n}\n\n/** OPFS directory sqlite-wasm uses for a pool (its default is `.` + pool name). */\nexport function opfsPoolDirectory(poolName: string): string {\n\treturn `.${poolName}`\n}\n\n/**\n * Web Lock held by the worker that owns a pool, for the pool's entire life. A\n * new owner (a promoted tab, a reopened database) waits on it instead of racing\n * the previous worker for the file handles.\n */\nexport function opfsPoolLockName(poolName: string): string {\n\treturn `kora-opfs-pool:${poolName}`\n}\n\n/** Tab leader lock for a database (one leader tab per database per origin). */\nexport function leaderLockName(dbName: string): string {\n\treturn `kora-leader-${dbName}`\n}\n\n/**\n * Marker a storage leader running a build with the version gate holds while it holds the\n * leader lock (taken right after, released right after it). The leader lock held without\n * it means a leader running a pre-gate build (version gate, section 8).\n */\nexport function gatedLeaderLockName(dbName: string): string {\n\treturn `kora-gated-leader-${dbName}`\n}\n\n/**\n * Prefix of the lock a gated storage leader holds next to {@link gatedLeaderLockName}, named\n * after its version gate identity (the prefix followed by the identity as JSON). A newer\n * build's gate finds the leader's build there even when the leader's tab lock is not held\n * (a tab frozen while it was being promoted), and waits for it (version gate, rule 4).\n */\nexport function gatedLeaderIdentityLockPrefix(dbName: string): string {\n\treturn `kora-gated-leader-id:${dbName}:`\n}\n\n/** BroadcastChannel carrying follower RPC, heartbeats and pings for a database. */\nexport function storageChannelName(dbName: string): string {\n\treturn `kora-storage-${dbName}`\n}\n\n/** File name of a database inside its pool (unchanged from beta.12 for migration). */\nexport function opfsDatabaseFilename(dbName: string): string {\n\tconst base = dbName.replace(/[^a-zA-Z0-9._-]/g, '_')\n\treturn base.endsWith('.db') ? base : `${base}.db`\n}\n\n/** Absolute path under which the SAH pool tracks a database file. */\nexport function opfsPoolPath(dbName: string): string {\n\treturn `/${opfsDatabaseFilename(dbName)}`\n}\n"]}