@bitcobblers/wod-wiki-storage 0.43.2150 → 0.43.2152
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/dist/idb/index.cjs +42 -1
- package/dist/idb/index.cjs.map +1 -1
- package/dist/idb/index.d.cts +41 -2
- package/dist/idb/index.d.ts +41 -2
- package/dist/idb/index.mjs +37 -2
- package/dist/idb/index.mjs.map +1 -1
- package/package.json +6 -6
package/dist/idb/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/idb/index.ts"],"names":["def","store","table","legacy"],"mappings":";;;;;;;;AAgCO,IAAM,WAAA,GAAc;AAQ3B,IAAM,YAAA,GAAe,aAAA;AACrB,IAAM,gBAAA,GAAmB,YAAA;AACzB,IAAM,iBAAA,GAAoB;AAAA,EACxB,EAAE,IAAA,EAAM,YAAA,EAAc,OAAA,EAAS,KAAA,EAAO,eAAe,IAAA,EAAK;AAAA,EAC1D,EAAE,IAAA,EAAM,gBAAA,EAAkB,OAAA,EAAS,KAAA;AACrC,CAAA;AAGA,IAAM,oBAAA,GAAuB,gBAAA;AAE7B,IAAM,iBAAA,GAA0C,UAAA,CAAW,MAAA,CAAO,CAAA,GAAA,KAAO,CAAC,GAAA,CAAI,MAAM,CAAA,CAAE,GAAA,CAAI,CAAA,GAAA,KAAO,GAAA,CAAI,IAAI,CAAA;AAGzG,IAAM,iBAAA,GAAoB,GAAA;AAC1B,IAAM,mBAAA,GAAsB,GAAA;AAG5B,IAAM,kBAAA,GAA6C,EAAE,WAAA,EAAa,MAAA,EAAO;AAGzE,IAAM,mBAAA,GAAsE;AAAA,EAC1E,EAAE,IAAA,EAAM,UAAA,EAAY,SAAS,CAAC,IAAA,EAAM,SAAS,CAAA,EAAE;AAAA,EAC/C,EAAE,IAAA,EAAM,SAAA,EAAW,OAAA,EAAS,IAAA;AAC9B,CAAA;AAUA,IAAM,YAAN,MAAgB;AAAA,EACL,MA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A,EAAgB,CAAA;AAAA,MAChB,GAAI,KAAA,GAAQ,EAAE,IAAA,EAAM,KAAA,CAAM,MAAM,EAAA,EAAI,KAAA,CAAM,EAAA,EAAG,GAAI,EAAC;AAAA,MAClD,QAAA,EAAU,GAAA,CAAI,QAAA,KAAa,QAAA,GAAW,QAAQ,GAAA,CAAI;AAAA,KACpD;AACA,IAAA,OAAQ,IAAA,CAAiC,SAAA;AACzC,IAAA,OAAQ,IAAA,CAAiC,cAAA;AACzC,IAAA,IAAI,IAAA,CAAK,OAAO,GAAA,CAAI,EAAA,QAAU,UAAA,CAAW,MAAA,CAAO,IAAI,EAAE,CAAA;AACtD,IAAA,MAAM,UAAA,CAAW,IAAI,IAAI,CAAA;AAAA,EAC3B;AAIA,EAAA,EAAA,CAAG,kBAAkB,UAAU,CAAA;AACjC","file":"index.mjs","sourcesContent":["/**\n * IndexedDB adapter — the browser data plane (moved verbatim from the\n * playground app; the shared user policy and the schema32 sync cutover live\n * here now). Local-first invariants:\n *\n * - Every committed local transaction group is durable in `sync_outbox`,\n * written in the SAME native transaction as the data writes.\n * - Snapshots (`snapshotRows`, bootstrap, conversion) are policy-compliant:\n * they carry user data only, per the shared policy in `../policy`.\n * - `sync_state` holds pull cursors, upload watermarks and frozen\n * bootstrap runs (durable retry identities), all per backup target.\n */\n\nimport { openDB, type IDBPDatabase, type IDBPTransaction } from 'idb';\nimport type {\n IReadOnlyStore, IReadWriteStore, IStorage, IStorageTransaction, StoreName, StoreType,\n} from '../contract';\nimport { DB_VERSION, STORE_DEFS } from '../schema';\nimport { USER_OWNED_STORES, stampUserOwned } from '../membership';\nimport { keyFromValue, type KeyDTO } from '../wire';\nimport type { Note, Session, BlockRevision } from '../entities';\nimport {\n rowsEqual, validateStorageRow, validateNoteWrite, validateSessionWrite, validateStoredPins,\n} from '../validation';\nimport { collectUserScopeContext, isUserOwnedRow, USER_DELETED_SEED_PREFIX, type UserScopeContext } from '../policy';\nimport { readRawSyncOps, readLegacyRows, type SyncEntry, type SyncMutation } from '../sql/sync';\nimport type { Database } from '../sql/connection';\nimport {\n parseDocumentSections, actionableSectionKind, matchDialectFence, KNOWN_SECTION_WIDGETS,\n} from '@bitcobblers/wod-wiki-core';\nimport { toEventRows, toSummaryEventRows } from '@bitcobblers/wod-wiki-wql';\n\nexport const IDB_DB_NAME = 'wodwiki-db';\n\n// Browser-local sync stores — NOT part of the shared STORE_DEFS spec (the\n// SQL/API schema is unchanged). `sync_outbox` is the durable journal: one\n// entry per committed local transaction group, written in the SAME native\n// transaction as the data writes, so an aborted transaction never journals\n// and a journaled group always reflects committed data. `sync_state` holds\n// the pull cursor, the upload watermark and frozen bootstrap runs.\nconst OUTBOX_STORE = 'sync_outbox';\nconst SYNC_STATE_STORE = 'sync_state';\nconst LOCAL_SYNC_STORES = [\n { name: OUTBOX_STORE, keyPath: 'seq', autoIncrement: true },\n { name: SYNC_STATE_STORE, keyPath: 'key' },\n] as const;\n\n/** sync_state keys of frozen bootstrap runs (TursoSyncEngine naming). */\nconst BOOTSTRAP_RUN_PREFIX = 'bootstrap-run:';\n\nconst NON_SYSTEM_STORES: readonly StoreName[] = STORE_DEFS.filter(def => !def.system).map(def => def.name);\n\n// Bootstrap chunks: whole ops only, bounded per group for network batches.\nconst BOOTSTRAP_MAX_OPS = 500;\nconst BOOTSTRAP_MAX_BYTES = 1_000_000;\n\n/** Stores whose rows carry a raw binary field (base64 in the op log). */\nconst BINARY_SYNC_FIELDS: Record<string, string> = { attachments: 'data' };\n\n/** Legacy direct-Turso tables that predate the current STORE_DEFS spec. */\nconst LEGACY_EXTRA_TABLES: { name: string; keyPath: string | string[] }[] = [\n { name: 'segments', keyPath: ['id', 'version'] },\n { name: 'results', keyPath: 'id' },\n];\n\ntype Mode = 'readonly' | 'readwrite';\n/** Native tx handle; write methods are guarded at runtime by `mutable`, so\n * the handle is typed readwrite to keep put/delete/clear defined. */\ntype Tx = IDBPTransaction<unknown, string, 'readwrite'>;\n\n/** Per-transaction mutation collector — becomes one outbox entry on commit.\n * `ctx` lazily caches the tx's user-scope context (seed note ids) for\n * journal-time ownership classification; invalidated when notes change. */\nclass TxJournal {\n readonly ops: SyncMutation[] = [];\n ctx?: Promise<UserScopeContext>;\n}\n\n/** Post-commit outbox notification — the sync engine debounces uploads off\n * these instead of polling the network while the app is idle. Fired only\n * AFTER the committing transaction durably lands (fire-and-forget). */\nconst outboxListeners = new Set<() => void>();\n\nexport function subscribeOutboxWrites(listener: () => void): () => void {\n outboxListeners.add(listener);\n return () => {\n outboxListeners.delete(listener);\n };\n}\n\nfunction notifyOutboxCommit(): void {\n for (const listener of outboxListeners) listener();\n}\n\nfunction isKeyRange(key: unknown): key is IDBKeyRange {\n return key !== null && typeof key === 'object' && !Array.isArray(key)\n && ('lower' in key || 'upper' in key || 'lowerOpen' in key || 'upperOpen' in key);\n}\n\n/** Approximate encoded op-log size of one mutation: JSON envelope plus\n * base64-inflated binary cells (ArrayBuffer serializes as {} in JSON, so a\n * plain JSON.stringify would undercount attachment-heavy batches). */\nfunction mutationBytes(op: SyncMutation): number {\n if (op.op !== 'put') return 32; // envelope + key estimate\n let bytes = 32;\n const field = BINARY_SYNC_FIELDS[op.store];\n const value: unknown = op.value;\n const data = field && value !== null && typeof value === 'object' && !Array.isArray(value) && field in value\n ? Reflect.get(value, field)\n : undefined;\n bytes += typeof data === 'string' ? data.length\n : data instanceof ArrayBuffer ? Math.ceil(data.byteLength / 3) * 4 + 64\n : JSON.stringify(op.value)?.length ?? 0;\n return bytes;\n}\n\n/**\n * One policy-compliant snapshot as put mutations, in STORE_DEFS order.\n * Strict: a row whose key cannot be derived is corrupted data — it fails\n * the pass instead of being silently dropped.\n *\n * Immutable revision history is emitted BEFORE notes and sessions so chunk\n * boundaries (bootstrap/conversion grouping) can never split a pin from the\n * revision it references: every chunk that carries a consumer row already\n * carries its history.\n */\nconst SNAPSHOT_OP_ORDER: readonly StoreName[] = [\n 'block_revisions',\n 'notes',\n 'sessions',\n ...NON_SYSTEM_STORES.filter(\n name => name !== 'block_revisions' && name !== 'notes' && name !== 'sessions',\n ),\n];\n\n/** Snapshot ops are always puts — narrowed so callers can read store/key. */\ntype SnapshotPut = Extract<SyncMutation, { op: 'put' }>;\n\nasync function policySnapshotOps(\n readAll: (store: StoreName) => Promise<unknown[]>,\n): Promise<SnapshotPut[]> {\n const ctx = collectUserScopeContext(await readAll('notes'));\n const ops: SnapshotPut[] = [];\n for (const store of SNAPSHOT_OP_ORDER) {\n const def = STORE_DEFS.find(candidate => candidate.name === store)!;\n for (const row of await readAll(store)) {\n if (!isUserOwnedRow(store, row, ctx)) continue;\n ops.push({ op: 'put', store, key: keyFromValue(def, row), value: row });\n }\n }\n return ops;\n}\n\nclass IDBStore<T> implements IReadWriteStore<T> {\n constructor(\n private readonly owner: IndexedDBStorage,\n private readonly name: StoreName,\n private readonly tx?: Tx,\n private readonly mutable = false,\n private readonly touched?: { notes: Set<string>; sessions: Set<string> },\n private readonly journal?: TxJournal,\n ) {}\n\n async get(key: IDBValidKey): Promise<T | undefined> {\n if (this.tx) return this.tx.objectStore(this.name).get(key);\n return (await this.owner.open()).get(this.name, key);\n }\n\n async getMany(keys: IDBValidKey[]): Promise<(T | undefined)[]> {\n if (this.tx) return Promise.all(keys.map(key => this.tx!.objectStore(this.name).get(key)));\n return this.owner.transaction([this.name], 'readonly', tx => tx.readonly(this.name).getMany(keys)) as Promise<(T | undefined)[]>;\n }\n\n async getAll(query?: IDBValidKey | IDBKeyRange, count?: number): Promise<T[]> {\n if (this.tx) return this.tx.objectStore(this.name).getAll(query, count);\n return (await this.owner.open()).getAll(this.name, query, count);\n }\n\n async getAllFromIndex(index: string, query?: IDBValidKey | IDBKeyRange, count?: number): Promise<T[]> {\n if (this.tx) return this.tx.objectStore(this.name).index(index).getAll(query, count);\n return (await this.owner.open()).getAllFromIndex(this.name, index, query, count);\n }\n\n async getAllFromIndexMany(index: string, keys: IDBValidKey[]): Promise<T[][]> {\n if (this.tx) return Promise.all(keys.map(key => this.tx!.objectStore(this.name).index(index).getAll(key)));\n return this.owner.transaction([this.name], 'readonly', tx => tx.readonly(this.name).getAllFromIndexMany(index, keys)) as Promise<T[][]>;\n }\n\n async count(query?: IDBValidKey | IDBKeyRange): Promise<number> {\n if (this.tx) return this.tx.objectStore(this.name).count(query);\n return (await this.owner.open()).count(this.name, query);\n }\n\n async countFromIndex(index: string, query?: IDBValidKey | IDBKeyRange): Promise<number> {\n if (this.tx) return this.tx.objectStore(this.name).index(index).count(query);\n return (await this.owner.open()).countFromIndex(this.name, index, query);\n }\n\n async put(value: T, _key?: IDBValidKey): Promise<IDBValidKey> {\n if (!this.mutable) throw new Error('read-only store');\n if (!this.tx) {\n const scope = this.name === 'notes' ? [this.name, 'block_revisions'] as const : [this.name, 'block_revisions', 'notes'] as const;\n return this.owner.transaction([...scope], 'readwrite', tx => tx.readwrite(this.name).put(value as StoreType<typeof this.name>));\n }\n const stored = this.owner.stamp(this.name, value);\n validateStorageRow(this.name, stored);\n const def = STORE_DEFS.find(def => def.name === this.name)!;\n const key = keyFromValue(def, stored);\n const store = this.tx.objectStore(this.name);\n const previous = await store.get(key);\n if (this.name === 'block_revisions' && previous !== undefined && !rowsEqual(previous, stored)) throw new Error('immutable block revision collision');\n if (this.name === 'notes') validateNoteWrite(previous, stored);\n if (this.name === 'sessions') validateSessionWrite(previous, stored);\n if (rowsEqual(previous, stored)) return key;\n const result = await store.put(stored);\n if (!def.system && this.journal) {\n // Journal-time ownership classification (§3.4), INSIDE the write\n // transaction: user→user and seed→user emit complete user puts;\n // seed→seed ships nothing (the remote re-imports seed data itself);\n // user→seed emits a tombstone for the former user record instead of\n // silently dropping it.\n const ctx = this.name === 'notes'\n ? undefined\n : await (this.journal.ctx ??= this.owner.policyContext(this.tx!));\n const wasUser = previous !== undefined && isUserOwnedRow(this.name, previous, ctx ?? collectUserScopeContext([]));\n const isUser = isUserOwnedRow(this.name, stored, ctx ?? collectUserScopeContext([]));\n if (isUser) {\n if (this.name === 'notes' && stored !== null && typeof stored === 'object' && 'id' in stored) {\n for (const revision of await this.tx.objectStore('block_revisions').index('by-note').getAll(String(stored.id))) {\n this.journal.ops.push({ op: 'put', store: 'block_revisions', key: [revision.noteId, revision.blockId, revision.version], value: revision });\n }\n } else if (this.name === 'sessions' && stored !== null && typeof stored === 'object' && 'noteId' in stored && 'blockId' in stored && 'blockVersion' in stored) {\n const revisionKey = [stored.noteId, stored.blockId, stored.blockVersion] as IDBValidKey;\n const revision = await this.tx.objectStore('block_revisions').get(revisionKey);\n if (revision) this.journal.ops.push({ op: 'put', store: 'block_revisions', key: revisionKey as KeyDTO, value: revision });\n }\n this.journal.ops.push({ op: 'put', store: this.name, key: key as KeyDTO, value: stored });\n }\n else if (wasUser) this.journal.ops.push({ op: 'delete', store: this.name, key: key as KeyDTO });\n // notes writes shift seed provenance — reclassify later stores in\n // this transaction against the post-write notes.\n if (this.name === 'notes') this.journal.ctx = undefined;\n }\n if (this.name === 'notes') this.touched?.notes.add(String(key));\n if (this.name === 'sessions') this.touched?.sessions.add(String(key));\n return result;\n }\n\n async putMany(values: T[], keys?: IDBValidKey[]): Promise<IDBValidKey[]> {\n if (keys && keys.length !== values.length) throw new Error('putMany key count mismatch');\n if (!this.tx) {\n const scope = this.name === 'notes' ? [this.name, 'block_revisions'] as const : [this.name, 'block_revisions', 'notes'] as const;\n return this.owner.transaction([...scope], 'readwrite', tx => tx.readwrite(this.name).putMany(values as StoreType<typeof this.name>[], keys));\n }\n const out: IDBValidKey[] = [];\n for (let i = 0; i < values.length; i++) out.push(await this.put(values[i], keys?.[i]));\n return out;\n }\n\n async delete(key: IDBValidKey | IDBKeyRange): Promise<void> {\n if (!this.mutable) throw new Error('read-only store');\n if (this.name === 'block_revisions') throw new Error('block history requires explicit wipe');\n if (!this.tx) {\n // Journal-time ownership classification reads notes in the same tx.\n const scope = this.name === 'notes' ? [this.name] as const : [this.name, 'notes'] as const;\n return this.owner.transaction([...scope], 'readwrite', tx => tx.readwrite(this.name).delete(key));\n }\n if (this.name === 'notes') {\n for (const note of await this.tx.objectStore('notes').getAll(key)) {\n for (const name of ['block_index', 'block_efforts', 'block_equipment'] as const) {\n const store = this.tx.objectStore(name);\n for (const id of await store.index('by-note').getAllKeys(note.id)) {\n const projection = new IDBStore(this.owner, name, this.tx, true, this.touched, this.journal);\n await projection.delete(id);\n }\n }\n }\n }\n await this.recordDelete(key);\n await this.tx.objectStore(this.name).delete(key);\n }\n\n /** Journal a delete as per-key tombstones (ranges expand to their keys).\n * Journal-time ownership: only deletes of USER-scope rows ship — a seed\n * row's removal is re-imported remotely, not a user mutation (deleting a\n * seed NOTE carries intent via the user-deleted-seed meta tombstone the\n * caller writes in the same transaction). */\n private async recordDelete(key: IDBValidKey | IDBKeyRange): Promise<void> {\n if (!this.journal) return;\n const store = this.tx!.objectStore(this.name);\n const keys = isKeyRange(key) ? await store.getAllKeys(key) : [key as IDBValidKey];\n const ctx = this.name === 'notes'\n ? undefined\n : await (this.journal.ctx ??= this.owner.policyContext(this.tx!));\n for (const k of keys) {\n const previous = await store.get(k);\n if (previous !== undefined && !isUserOwnedRow(this.name, previous, ctx ?? collectUserScopeContext([]))) continue;\n this.journal.ops.push({ op: 'delete', store: this.name, key: k as KeyDTO });\n }\n }\n\n /**\n * User-scope clear: expands to per-key deletes of user-owned rows,\n * journaled the same way so replay preserves exactly what the local clear\n * preserved — seed content (re-importable), pinned revision history\n * (block_revisions requires explicit wipe) and seed-deletion tombstones\n * survive a clear. A journaled `{op:'clear'}` would wipe seed rows on\n * every replaying device.\n */\n async clear(): Promise<void> {\n if (!this.mutable) throw new Error('read-only store');\n if (this.name === 'block_revisions') throw new Error('block history requires explicit wipe');\n if (!this.tx) {\n const scope = this.name === 'notes' ? ['notes', 'block_index', 'block_efforts'] as const : [this.name, 'notes'] as const;\n return this.owner.transaction([...scope], 'readwrite', tx => tx.readwrite(this.name).clear());\n }\n const store = this.tx.objectStore(this.name);\n const rows = await store.getAll() as unknown[];\n const notes = this.name === 'notes' ? rows : await this.tx.objectStore('notes').getAll() as unknown[];\n const ctx = collectUserScopeContext(notes);\n for (const row of rows) {\n const key = keyFromValue(STORE_DEFS.find(def => def.name === this.name)!, row);\n if (!isUserOwnedRow(this.name, row, ctx)) continue;\n if (this.name === 'meta' && typeof key === 'string' && key.startsWith(USER_DELETED_SEED_PREFIX)) continue;\n if (this.name === 'notes' && typeof key === 'string') {\n // Cascade the note's projections first — keys read BEFORE deletion,\n // each journaled as its own tombstone.\n for (const name of ['block_index', 'block_efforts', 'block_equipment'] as const) {\n const projections = this.tx.objectStore(name);\n for (const id of await projections.index('by-note').getAllKeys(key)) {\n this.journal?.ops.push({ op: 'delete', store: name, key: id as KeyDTO });\n await projections.delete(id);\n }\n }\n }\n await this.recordDelete(key);\n await store.delete(key);\n }\n }\n}\n\n// ---------------------------------------------------------------------------\n// Legacy row shapes (V20–V28) — read-only migration input, never written back.\n// ---------------------------------------------------------------------------\n\ninterface LegacySessionData {\n logs?: unknown[];\n startTime?: number;\n endTime?: number;\n duration?: number;\n completed?: boolean;\n roundsCompleted?: number;\n totalRounds?: number;\n repsCompleted?: number;\n}\n\ntype LegacySession = Session & { data?: LegacySessionData; segmentId?: string; segmentVersion?: number; version?: number };\n\ninterface LegacySegment {\n id: string;\n version: number;\n noteId: string;\n position?: number;\n dataType: string;\n rawContent: string;\n sourceContent?: string;\n createdAt: number;\n isHistory?: boolean;\n}\n\ninterface LegacyBlockIndexRow {\n id: string;\n noteId: string;\n segmentId: string;\n segmentVersion?: number;\n position?: number;\n dataType: string;\n rawContent: string;\n noteTitle: string;\n createdAt: number;\n isStatic?: boolean;\n sourceId?: string;\n sourcePath?: string;\n routeId?: string;\n blockContentId?: string;\n}\n\nconst SEGMENT_TO_BLOCK_KIND: Record<string, 'wod'> = { script: 'wod', wod: 'wod' };\n\nfunction legacyDialect(rawContent: string): { dialect?: 'time' | 'log'; sport?: string } {\n const first = rawContent.slice(0, rawContent.indexOf('\\n'));\n return matchDialectFence(first.trim()) ?? {};\n}\n\nexport class IndexedDBStorage implements IStorage {\n private opening?: Promise<IDBPDatabase>;\n constructor(private readonly options: {\n getUserId?: () => string;\n /** Called just before a schema migration runs (oldVersion < DB_VERSION). */\n onUpgradeStart?: (fromVersion: number) => void;\n /** Database file name; the sync engine migrates scratch copies under\n * their own name so a remote-schema conversion never touches the\n * live database. Defaults to the app database. */\n dbName?: string;\n } = {}) {}\n\n open(): Promise<IDBPDatabase> {\n if (typeof indexedDB === 'undefined') return Promise.reject(new Error('IndexedDB is unavailable in this environment'));\n if (!this.opening) {\n let newer = false;\n let pre20 = 0;\n let migrationError: Error | undefined;\n this.opening = openDB(this.options.dbName ?? IDB_DB_NAME, DB_VERSION, {\n upgrade: async (db, oldVersion, _version, tx) => {\n void tx.done.catch(() => {});\n if (oldVersion > DB_VERSION) {\n // A newer client owns this database — never downgrade or rewrite it.\n newer = true;\n tx.abort();\n return;\n }\n if (oldVersion !== 0 && oldVersion < 20) {\n // Pre-V20 layouts predate the versioned migration chain. Their\n // rows are NEVER silently destroyed: the upgrade aborts with an\n // actionable error so the user can export from an older app or\n // explicitly clear site data. The database file stays untouched.\n pre20 = oldVersion;\n tx.abort();\n return;\n }\n try {\n createMissingStores(db, tx);\n if (oldVersion !== 0 && oldVersion < DB_VERSION) this.options.onUpgradeStart?.(oldVersion);\n await migrateSchema(db, oldVersion, tx);\n } catch (error) {\n migrationError = error instanceof Error ? error : new Error(String(error));\n try { tx.abort(); } catch { /* The failed request may already have aborted it. */ }\n }\n },\n blocking: () => { void this.close(); },\n }).catch(error => {\n this.opening = undefined;\n if (migrationError) throw migrationError;\n if (pre20 !== 0) {\n throw new Error(\n `local database schema v${pre20} predates the supported migration chain (v20+). `\n + 'Open this browser profile in an intermediate app version to export your data, '\n + 'or clear site data to start fresh — the old database was left untouched.',\n );\n }\n throw newer || (error instanceof DOMException && error.name === 'VersionError')\n ? new Error(`database schema is newer than this client supports (v${DB_VERSION}); refusing to downgrade`) : error;\n });\n }\n return this.opening;\n }\n\n stamp(store: StoreName, value: unknown): unknown {\n const userId = this.options.getUserId?.();\n return userId ? stampUserOwned(store, value, userId) : value;\n }\n\n /** User-scope context (proven seed note ids) from the notes of `tx` —\n * journal-time ownership classification reads it INSIDE the same\n * transaction, so a seed import's note writes are visible to the link\n * writes that follow in the same commit. Internal seam for IDBStore. */\n async policyContext(tx?: Tx): Promise<UserScopeContext> {\n const notes = tx\n ? await tx.objectStore('notes').getAll() as unknown[]\n : await (await this.open()).getAll('notes') as unknown[];\n return collectUserScopeContext(notes);\n }\n\n readonly<K extends StoreName>(store: K): IReadOnlyStore<StoreType<K>> { return new IDBStore(this, store); }\n readwrite<K extends StoreName>(store: K): IReadWriteStore<StoreType<K>> { return new IDBStore(this, store, undefined, true); }\n\n async transaction<K extends StoreName, R>(stores: K[], mode: Mode, fn: (tx: IStorageTransaction) => Promise<R>): Promise<R> {\n const db = await this.open();\n const journal = mode === 'readwrite' ? new TxJournal() : undefined;\n const scope = new Set<string>(stores);\n if (mode === 'readwrite') {\n scope.add('block_revisions');\n scope.add(OUTBOX_STORE);\n scope.add('notes');\n if (scope.has('notes')) {\n scope.add('block_index');\n scope.add('block_efforts');\n scope.add('block_equipment');\n }\n }\n const native = db.transaction([...scope], mode) as Tx;\n const done = native.done;\n void done.catch(() => {});\n const touched = { notes: new Set<string>(), sessions: new Set<string>() };\n const adapter: IStorageTransaction = {\n readonly: name => {\n if (!scope.has(name)) throw new Error('store outside transaction scope');\n return new IDBStore(this, name, native);\n },\n readwrite: name => {\n if (mode !== 'readwrite') throw new Error('read-only transaction');\n if (!scope.has(name)) throw new Error('store outside transaction scope');\n return new IDBStore(this, name, native, true, touched, journal);\n },\n };\n try {\n const result = await fn(adapter);\n const notes = (await Promise.all([...touched.notes].map(id => native.objectStore('notes').get(id)))).filter(Boolean) as Note[];\n const sessions = (await Promise.all([...touched.sessions].map(id => native.objectStore('sessions').get(id)))).filter(Boolean) as Session[];\n await validateStoredPins(notes, sessions, keys => Promise.all(keys.map(key => native.objectStore('block_revisions').get(key))) as Promise<(BlockRevision | undefined)[]>);\n // Durable outbox: the journal entry lands in the SAME transaction as\n // the data writes — it commits with them and vanishes with them.\n if (journal && journal.ops.length > 0) {\n await native.objectStore(OUTBOX_STORE).put({ id: crypto.randomUUID(), at: Date.now(), ops: journal.ops });\n }\n await done;\n if (journal && journal.ops.length > 0) notifyOutboxCommit();\n return result;\n } catch (error) {\n try { native.abort(); } catch { /* The native request may have already aborted. */ }\n await done.catch(() => {});\n throw error;\n }\n }\n\n async wipeUserData(): Promise<void> {\n const names = STORE_DEFS.filter(def => !def.system && def.name !== 'block_revisions').map(def => def.name);\n await this.transaction(names, 'readwrite', async tx => {\n for (const name of names) await tx.readwrite(name).clear();\n });\n }\n\n async wipe(): Promise<void> {\n const db = await this.open();\n const names = STORE_DEFS.filter(def => !def.system).map(def => def.name);\n const tx = db.transaction([...names, OUTBOX_STORE], 'readwrite');\n await Promise.all(names.map(name => tx.objectStore(name).clear()));\n await tx.objectStore(OUTBOX_STORE).put({ id: crypto.randomUUID(), at: Date.now(), ops: [{ op: 'wipe' }] });\n await tx.done;\n notifyOutboxCommit();\n }\n\n // -----------------------------------------------------------------------\n // Sync seams (Turso backup engine only — not part of IStorage).\n // -----------------------------------------------------------------------\n\n /** Pending committed transaction groups, in commit order. */\n async readOutbox(afterSeq: number, limit: number): Promise<{ seq: number; id: string; at: number; ops: SyncMutation[] }[]> {\n const db = await this.open();\n const range = IDBKeyRange.lowerBound(afterSeq, true);\n // IDB counts are unsigned long — clamp callers' \"unbounded\" shorthand.\n return (await db.getAll(OUTBOX_STORE, range, Math.min(limit, 0xffffffff))) as { seq: number; id: string; at: number; ops: SyncMutation[] }[];\n }\n\n /** Drop acknowledged groups. Callers pass only the contiguous acked\n * watermark — a failed upload never truncates pending writes. */\n async ackOutbox(upToSeq: number): Promise<void> {\n const db = await this.open();\n const keys = await db.getAllKeys(OUTBOX_STORE, IDBKeyRange.upperBound(upToSeq));\n const tx = db.transaction(OUTBOX_STORE, 'readwrite');\n await Promise.all(keys.map(key => tx.store.delete(key)));\n await tx.done;\n }\n\n async getSyncState<T>(key: string): Promise<T | undefined> {\n const row = (await (await this.open()).get(SYNC_STATE_STORE, key)) as { value: T } | undefined;\n return row?.value;\n }\n\n async setSyncState(key: string, value: unknown): Promise<void> {\n await (await this.open()).put(SYNC_STATE_STORE, { key, value });\n }\n\n /**\n * Freeze ONE durable bootstrap run for `key` (per backup target): a\n * policy-compliant snapshot of the current rows, chunked into ≤500-op /\n * ≤~1MB entries with a unique run UUID and stable chunk ids, persisted in\n * `sync_state[key]` in the SAME readwrite transaction that reads the data\n * — so a retry returns the byte-identical frozen entries (idempotent\n * remote replays), and a crash before the commit freezes nothing. No\n * network happens here.\n *\n * Pending outbox groups are read INSIDE the same transaction: their\n * touched keys/stores are excluded from the snapshot so the journal (which\n * ships after the bootstrap, in commit order) stays the last writer and\n * nothing ships twice. A pending wipe freezes an empty run — the journal\n * wipe itself still ships and decides the remote's end state.\n *\n * The engine deletes the frozen run (`db.delete('sync_state', key)`) only\n * after the remote commit; until then every retry replays these entries.\n */\n async captureSyncBootstrap(key: string): Promise<SyncEntry[]> {\n const db = await this.open();\n const tx = db.transaction([...NON_SYSTEM_STORES, OUTBOX_STORE, SYNC_STATE_STORE], 'readwrite');\n const state = tx.objectStore(SYNC_STATE_STORE);\n const frozen = await state.get(key) as { value?: SyncEntry[] } | undefined;\n if (frozen !== undefined && Array.isArray(frozen.value)) {\n await tx.done;\n return frozen.value;\n }\n const pendingKeys = new Set<string>();\n const clearedStores = new Set<string>();\n let wiped = false;\n for (const group of await tx.objectStore(OUTBOX_STORE).getAll() as { ops: SyncMutation[] }[]) {\n for (const op of group.ops) {\n if (op.op === 'put' || op.op === 'delete') pendingKeys.add(`${op.store}:${JSON.stringify(op.key)}`);\n else if (op.op === 'clear') clearedStores.add(op.store);\n else wiped = true;\n }\n }\n const run = crypto.randomUUID();\n const entries: SyncEntry[] = [];\n if (!wiped) {\n let ops: SyncMutation[] = [];\n let bytes = 0;\n const flush = (): void => {\n if (ops.length === 0) return;\n entries.push({ id: `bootstrap:${run}:${entries.length}`, at: Date.now(), ops });\n ops = [];\n bytes = 0;\n };\n for (const op of await policySnapshotOps(store => tx.objectStore(store).getAll() as Promise<unknown[]>)) {\n if (clearedStores.has(op.store)) continue;\n // Immutable history is NEVER excluded: a snapshotted note/session\n // may pin a revision still pending in the journal, and the snapshot\n // ships first — the pinned revision must already be on the remote.\n // Revision-first op ordering keeps every chunk self-contained.\n if (op.store !== 'block_revisions' && pendingKeys.has(`${op.store}:${JSON.stringify(op.key)}`)) continue;\n const size = mutationBytes(op);\n if (ops.length > 0 && (ops.length >= BOOTSTRAP_MAX_OPS || bytes + size > BOOTSTRAP_MAX_BYTES)) flush();\n ops.push(op);\n bytes += size;\n }\n flush();\n }\n // Frozen BEFORE any network I/O — same transaction as the snapshot read.\n await state.put({ key, value: entries });\n await tx.done;\n return entries;\n }\n\n /**\n * Validate every stored pin (note blocks + session pins against\n * block_revisions) in ONE consistent readonly read — the post-restore\n * gate: a replayed backup with missing history fails loudly here instead\n * of surfacing later as broken sessions.\n */\n async validateSyncState(): Promise<void> {\n const db = await this.open();\n const tx = db.transaction(['notes', 'sessions', 'block_revisions'], 'readonly');\n const notes = await tx.objectStore('notes').getAll() as Note[];\n const sessions = await tx.objectStore('sessions').getAll() as Session[];\n const revisions = tx.objectStore('block_revisions');\n await validateStoredPins(\n notes,\n sessions,\n keys => Promise.all(keys.map(key => revisions.get(key))) as Promise<(BlockRevision | undefined)[]>,\n );\n await tx.done;\n }\n\n /**\n * Apply remotely committed mutations locally (pull/replay) WITHOUT\n * journaling — a pulled mutation must never re-enter the outbox. Runs in\n * one native transaction together with the cursor update.\n *\n * Unsent-edit overlay: pending outbox groups (committed local writes not\n * yet acknowledged remotely) are read INSIDE the same transaction and\n * replayed after the remote rows — a local edit/delete/clear/wipe that\n * committed while the pull was on the network stays the visible state;\n * the remote row is backed up locally, not clobbered over the user.\n *\n * Conflict policy (deterministic, history-preserving):\n * - notes: an incoming row with a LOWER sourceRevision than the existing\n * row is stale — skipped, never clobbers newer history.\n * - block_revisions: same key with different contents keeps BOTH rows —\n * the incoming version is re-keyed to the next free version for that\n * block. Immutable history is never silently replaced.\n * - memberships (system): remote mutations are skipped — identity truth\n * stays local and snapshot/upload never include them.\n *\n * Returns committed-boundary counts of canonical consumer records (notes +\n * efforts only; internal/journal rows never reach the sync toast).\n * `cursorKey` keeps cursors per backup target.\n */\n async applySyncMutations(\n mutations: SyncMutation[],\n cursorRev: number | null,\n cursorKey = 'cursor',\n ): Promise<{ added: number; updated: number }> {\n const defsByName = new Map<string, (typeof STORE_DEFS)[number]>(STORE_DEFS.map(def => [def.name, def]));\n for (const mutation of mutations) {\n if (mutation.op === 'clear' || mutation.op === 'wipe') continue;\n const def = defsByName.get(mutation.store);\n if (!def) throw new Error(`unknown store in sync mutation: ${String(mutation.store)}`);\n if (mutation.op === 'put' || mutation.op === 'delete') {\n const parts = Array.isArray(mutation.key) ? mutation.key : [mutation.key];\n if (parts.length !== def.keyPath.length || !parts.every(part => typeof part === 'string' || typeof part === 'number')) {\n throw new Error(`sync ${mutation.op} key arity/shape mismatch for ${mutation.store}`);\n }\n }\n if (mutation.op === 'put') validateStorageRow(mutation.store, mutation.value);\n }\n const db = await this.open();\n const names = NON_SYSTEM_STORES as StoreName[];\n const tx = db.transaction([...names, OUTBOX_STORE, SYNC_STATE_STORE], 'readwrite');\n\n // Counting baseline: every canonical key this batch touches, read before\n // any write lands.\n const canonical = (store: StoreName): store is 'notes' | 'efforts' => store === 'notes' || store === 'efforts';\n const touched = new Map<string, { store: 'notes' | 'efforts'; key: IDBValidKey; before: unknown; beforeExists: boolean }>();\n for (const mutation of mutations) {\n if (mutation.op === 'clear' || mutation.op === 'wipe') continue;\n if (!canonical(mutation.store)) continue;\n const id = `${mutation.store}:${JSON.stringify(mutation.key)}`;\n if (touched.has(id)) continue;\n const key = mutation.key as IDBValidKey;\n const before = await tx.objectStore(mutation.store).get(key);\n touched.set(id, { store: mutation.store, key, before, beforeExists: before !== undefined });\n }\n\n const applyOne = async (mutation: SyncMutation, preferLocal: boolean): Promise<void> => {\n if (mutation.op === 'wipe') {\n for (const name of names) await tx.objectStore(name).clear();\n return;\n }\n if (mutation.store === 'memberships') return; // system store: never applied remotely\n if (mutation.op === 'clear') {\n if (mutation.store === 'block_revisions') return;\n const store = tx.objectStore(mutation.store);\n const ctx = collectUserScopeContext(await tx.objectStore('notes').getAll());\n for (const row of await store.getAll()) {\n if (!isUserOwnedRow(mutation.store, row, ctx)) continue;\n const key = keyFromValue(defsByName.get(mutation.store)!, row);\n if (mutation.store === 'meta' && typeof key === 'string' && key.startsWith(USER_DELETED_SEED_PREFIX)) continue;\n await applyOne({ op: 'delete', store: mutation.store, key }, preferLocal);\n }\n return;\n }\n if (mutation.op === 'delete') {\n if (mutation.store === 'notes') {\n const noteId = String(Array.isArray(mutation.key) ? mutation.key[0] : mutation.key);\n for (const name of ['block_index', 'block_efforts', 'block_equipment'] as const) {\n const store = tx.objectStore(name);\n for (const id of await store.index('by-note').getAllKeys(noteId)) await store.delete(id);\n }\n }\n if (mutation.store !== 'block_revisions') await tx.objectStore(mutation.store).delete(mutation.key as IDBValidKey);\n return;\n }\n // put\n const store = tx.objectStore(mutation.store);\n if (mutation.store === 'block_revisions') {\n const existing = await store.get(mutation.key as IDBValidKey);\n if (existing !== undefined && !rowsEqual(existing, mutation.value) && !preferLocal) {\n // Immutable-history collision: preserve BOTH as versioned records —\n // the incoming row moves to the next free version for that block.\n // Both rows passed validateStorageRow when written (the incoming row\n // just above; the existing row at its original commit), so the\n // revision shape is guaranteed here.\n const incoming = mutation.value as BlockRevision;\n const existingRow = existing as BlockRevision;\n let version = existingRow.version + 1;\n while (await store.get([incoming.noteId, incoming.blockId, version] as IDBValidKey) !== undefined) version += 1;\n await store.put({ ...incoming, version });\n return;\n }\n if (existing === undefined || !rowsEqual(existing, mutation.value)) await store.put(mutation.value);\n return;\n }\n if (mutation.store === 'notes' && !preferLocal) {\n const existing = await store.get(mutation.key as IDBValidKey);\n // Same validateStorageRow guarantee as above: rows in the store carry\n // the note shape, so comparing source revisions is safe.\n if (existing !== undefined) {\n const existingNote = existing as Note;\n const incomingNote = mutation.value as Note;\n if (existingNote.sourceRevision > incomingNote.sourceRevision) return; // stale remote write\n }\n }\n await store.put(mutation.value);\n };\n\n for (const mutation of mutations) await applyOne(mutation, false);\n\n // Unsent-edit overlay: replay pending outbox groups in commit order so\n // the user's latest local writes remain the visible latest state.\n const pending = ((await tx.objectStore(OUTBOX_STORE).getAll()) as { seq: number; ops: SyncMutation[] }[])\n .sort((a, b) => a.seq - b.seq);\n for (const group of pending) {\n for (const op of group.ops) await applyOne(op, true);\n }\n\n // Committed-boundary counts: canonical notes/efforts whose final visible\n // value is new or changed relative to the pre-pull baseline.\n let added = 0;\n let updated = 0;\n for (const entry of touched.values()) {\n const final = await tx.objectStore(entry.store).get(entry.key);\n if (final === undefined) continue; // deleted by the batch — not an add/update\n if (!entry.beforeExists) added += 1;\n else if (!rowsEqual(entry.before, final)) updated += 1;\n }\n\n if (cursorRev !== null) await tx.objectStore(SYNC_STATE_STORE).put({ key: cursorKey, value: { rev: cursorRev } });\n await tx.done;\n return { added, updated };\n }\n\n /**\n * Consistent atomic snapshot, policy-compliant (shared user policy): only\n * user-scope rows of the non-system stores, read in ONE readonly\n * transaction — the backup never mixes the pre/post state of a concurrent\n * local commit. System stores (memberships) are excluded: they never sync.\n * Use `snapshotAllRows` for the lossless (unfiltered) form.\n */\n async snapshotRows(): Promise<{ store: StoreName; rows: unknown[] }[]> {\n const db = await this.open();\n const defs = STORE_DEFS.filter(def => !def.system);\n const tx = db.transaction(defs.map(def => def.name), 'readonly');\n // Ownership context comes from the SAME snapshot transaction — reading\n // notes before opening it could diverge from a concurrent note write.\n const ctx = collectUserScopeContext(await tx.objectStore('notes').getAll() as unknown[]);\n const out = await Promise.all(\n defs.map(async def => ({\n store: def.name,\n rows: ((await tx.objectStore(def.name).getAll() as unknown[])).filter(row => isUserOwnedRow(def.name, row, ctx)),\n })),\n );\n await tx.done;\n return out;\n }\n\n /** Lossless snapshot of every NON-SYSTEM store (meta included) in one\n * readonly transaction — local export / restore emptiness checks. A\n * freshly initialized database may hold a default membership, so the\n * system store is excluded from both uses. */\n async snapshotAllRows(): Promise<{ store: StoreName; rows: unknown[] }[]> {\n const db = await this.open();\n const defs = STORE_DEFS.filter(def => !def.system);\n const tx = db.transaction(defs.map(def => def.name), 'readonly');\n const out = await Promise.all(\n defs.map(async def => ({ store: def.name, rows: await tx.objectStore(def.name).getAll() as unknown[] })),\n );\n await tx.done;\n return out;\n }\n\n async close(): Promise<void> {\n const opening = this.opening;\n this.opening = undefined;\n (await opening?.catch(() => undefined))?.close();\n }\n}\n\n// ---------------------------------------------------------------------------\n// Cross-schema conversion — the exact IndexedDB upgrade chain on a scratch\n// database. Reads the source WITHOUT writing it; used by the CLI to migrate\n// older remotes into fresh v32 targets (trusted runtimes load\n// fake-indexeddb as the browser adapter first).\n// ---------------------------------------------------------------------------\n\ntype ScratchOp =\n | { kind: 'put'; table: string; row: unknown }\n | { kind: 'delete'; table: string; key: IDBValidKey }\n | { kind: 'clear'; table: string };\n\n/** Scratch layout: current stores plus the pre-V26 legacy tables. */\nconst SCRATCH_TABLES: readonly { name: string; keyPath: string[] }[] = [\n ...STORE_DEFS.map(def => ({ name: def.name, keyPath: def.keyPath })),\n ...LEGACY_EXTRA_TABLES.map(table => ({ name: table.name, keyPath: Array.isArray(table.keyPath) ? table.keyPath : [table.keyPath] })),\n];\n\nconst SCRATCH_TABLE_BY_NAME: Record<string, string[]> = Object.fromEntries(\n SCRATCH_TABLES.map(table => [table.name, table.keyPath]),\n);\n\nfunction assertKnownStore(store: string): void {\n if (!SCRATCH_TABLE_BY_NAME[store]) throw new Error(`unknown store \"${store}\" in source op log; copy aborted`);\n}\n\n/** Derive a row's key from its keyPath fields — malformed rows fail. */\nfunction rowKey(table: string, row: Record<string, unknown>): IDBValidKey {\n const parts: IDBValidKey[] = [];\n for (const part of SCRATCH_TABLE_BY_NAME[table]) {\n const value = row[part];\n if (typeof value !== 'string' && typeof value !== 'number' && !(value instanceof Date)) {\n throw new Error(`row for store \"${table}\" is missing keyPath field \"${part}\"; copy aborted`);\n }\n parts.push(value);\n }\n return parts.length === 1 ? parts[0] : parts;\n}\n\n/** Narrow a raw (unvalidated) op key to what IndexedDB accepts. */\nfunction isIdbKey(value: unknown): value is IDBValidKey {\n return typeof value === 'string' || typeof value === 'number' || value instanceof Date\n || (Array.isArray(value) && value.length > 0 && value.every(isIdbKey));\n}\n\nfunction arrayBuffersEqual(a: ArrayBuffer, b: ArrayBuffer): boolean {\n if (a.byteLength !== b.byteLength) return false;\n const left = new Uint8Array(a);\n const right = new Uint8Array(b);\n return left.every((byte, i) => byte === right[i]);\n}\n\nfunction deleteIdbDatabase(name: string): Promise<void> {\n const idb = globalThis.indexedDB;\n if (!idb) return Promise.resolve();\n return new Promise<void>((resolve, reject) => {\n const request = idb.deleteDatabase(name);\n request.onsuccess = () => { resolve(); };\n request.onerror = () => { reject(request.error ?? new Error(`failed to delete ${name}`)); };\n // A still-open connection blocks deletion; the scratch rows are\n // disposable either way, so don't hang the conversion on it.\n request.onblocked = () => { resolve(); };\n });\n}\n\n/** Replay raw remote-era rows into a unique scratch IndexedDB created at the\n * SOURCE schema version (generic keyPath-only stores + legacy tables), so\n * opening it through IndexedDBStorage runs the same versioned chain the\n * browser runs locally. */\nasync function buildScratch(name: string, version: number, ops: ScratchOp[]): Promise<void> {\n const db = await openDB(name, version, {\n upgrade(scratch) {\n for (const table of SCRATCH_TABLES) {\n if (!scratch.objectStoreNames.contains(table.name)) {\n scratch.createObjectStore(table.name, { keyPath: table.keyPath.length === 1 ? table.keyPath[0] : table.keyPath });\n }\n }\n },\n });\n try {\n for (const op of ops) {\n if (!db.objectStoreNames.contains(op.table)) {\n throw new Error(`unknown store \"${op.table}\" in source; copy aborted`);\n }\n if (op.kind === 'put') await db.transaction(op.table, 'readwrite').objectStore(op.table).put(op.row);\n else if (op.kind === 'delete') await db.transaction(op.table, 'readwrite').objectStore(op.table).delete(op.key);\n else await db.transaction(op.table, 'readwrite').objectStore(op.table).clear();\n }\n } finally {\n db.close();\n }\n}\n\n/** Attachment rows are the binary payload. The terminal source map replays\n * the lifted ops in order (puts, deletes, clears — wipes already expanded\n * to clears), so deleted/wiped attachments are NOT required to survive;\n * surviving ones must match the converted rows byte-for-byte (zero-byte\n * buffers are valid). */\nasync function assertBinaryPreserved(sourceOps: ScratchOp[], converted: IndexedDBStorage): Promise<void> {\n const source = new Map<string, Record<string, unknown>>();\n for (const op of sourceOps) {\n if (op.kind === 'clear') {\n if (op.table === 'attachments') source.clear();\n } else if (op.kind === 'put' && op.table === 'attachments') {\n if (op.row === null || typeof op.row !== 'object' || Array.isArray(op.row) || !('id' in op.row)) {\n throw new Error('malformed attachment row in source; copy aborted');\n }\n source.set(String((op.row as Record<string, unknown>).id), op.row as Record<string, unknown>);\n } else if (op.kind === 'delete' && op.table === 'attachments') {\n source.delete(String(op.key));\n }\n }\n if (source.size === 0) return;\n const rows = await converted.readonly('attachments').getAll();\n const byId = new Map(rows.map(row => [row.id, row]));\n for (const [id, row] of source) {\n const restored = byId.get(id);\n if (!restored) throw new Error(`attachment ${id} missing after conversion; copy aborted, source untouched`);\n const before = row.data;\n const after = restored.data;\n if (typeof before === 'string' || typeof after === 'string') {\n if (before !== after) throw new Error(`attachment ${id} payload changed during conversion; copy aborted, source untouched`);\n } else if (!(before instanceof ArrayBuffer) || !(after instanceof ArrayBuffer) || !arrayBuffersEqual(before, after)) {\n throw new Error(`attachment ${id} payload changed during conversion; copy aborted, source untouched`);\n }\n }\n}\n\n/**\n * Convert an older backup into policy-compliant current-schema mutations\n * WITHOUT touching the source:\n *\n * 1. Lift the source data as ordered scratch ops (op-log replay in log\n * order, or legacy direct-Turso per-store rows incl. segments/results).\n * 2. Replay them into a unique scratch IndexedDB created AT `fromVersion`,\n * then open it through IndexedDBStorage — the same versioned migration\n * chain the browser runs locally rebuilds segments-era rows into\n * note-owned blocks, revisions, sessions and events.\n * 3. Validate strictly (all note/session pins, binary payloads, derivable\n * keys — any miss fails the copy) and return policy-compliant PUTS ONLY\n * (the caller applies them to a fresh, reserved target).\n */\nexport async function convertSyncSource(db: Database, fromVersion: number, legacy: boolean): Promise<SyncMutation[]> {\n if (!Number.isSafeInteger(fromVersion) || fromVersion < 20) {\n throw new Error(\n `Backup database schema v${fromVersion} predates the supported migration chain (v20+); the source was left untouched. `\n + 'Restore it with an intermediate app version, or point this app at a fresh backup database.',\n );\n }\n if (fromVersion > DB_VERSION) {\n throw new Error(`Backup database schema is newer than this converter supports (v${fromVersion} > v${DB_VERSION}); refusing to downgrade.`);\n }\n const raw: ScratchOp[] = [];\n if (legacy) {\n for (const table of [...NON_SYSTEM_STORES, ...LEGACY_EXTRA_TABLES.map(table => table.name)]) {\n for (const row of await readLegacyRows(db, table)) raw.push({ kind: 'put', table, row });\n }\n } else {\n // Raw replay with STRICT lift-time validation (§3.5): unknown stores,\n // unknown ops, malformed payloads and put keys that disagree with the\n // row's own keyPath fields fail the copy before anything is replayed.\n for (const op of await readRawSyncOps(db)) {\n if (op.op === 'wipe') {\n for (const name of [...NON_SYSTEM_STORES, ...LEGACY_EXTRA_TABLES.map(table => table.name)]) {\n raw.push({ kind: 'clear', table: name });\n }\n } else if (op.op === 'clear') {\n assertKnownStore(op.store);\n raw.push({ kind: 'clear', table: op.store });\n } else if (op.op === 'put') {\n assertKnownStore(op.store);\n if (op.value === undefined || op.value === null || typeof op.value !== 'object' || Array.isArray(op.value)) {\n throw new Error(`malformed put payload for store \"${op.store}\" in source op log; copy aborted`);\n }\n if (JSON.stringify(rowKey(op.store, op.value as Record<string, unknown>)) !== JSON.stringify(op.key)) {\n throw new Error(`put key ${JSON.stringify(op.key)} does not match store \"${op.store}\" keyPath fields; copy aborted`);\n }\n raw.push({ kind: 'put', table: op.store, row: op.value });\n } else if (op.op === 'delete') {\n assertKnownStore(op.store);\n if (!isIdbKey(op.key)) {\n throw new Error(`malformed delete key for store \"${op.store}\" in source op log; copy aborted`);\n }\n raw.push({ kind: 'delete', table: op.store, key: op.key });\n } else {\n throw new Error(`unknown op \"${String((op as { op?: unknown }).op)}\" in source op log; copy aborted`);\n }\n }\n }\n const scratch = `wodwiki-convert-${crypto.randomUUID()}`;\n const converted = new IndexedDBStorage({ dbName: scratch });\n try {\n await buildScratch(scratch, fromVersion, raw);\n await converted.open();\n await converted.validateSyncState(); // strict: missing pinned revisions fail the copy\n await assertBinaryPreserved(raw, converted);\n return await policySnapshotOps(store => converted.readonly(store).getAll() as Promise<unknown[]>);\n } finally {\n await converted.close();\n await deleteIdbDatabase(scratch).catch(() => undefined);\n }\n}\n\n// ---------------------------------------------------------------------------\n// Schema creation + versioned data migration (V20 → V32).\n// ---------------------------------------------------------------------------\n\nfunction createMissingStores(db: IDBPDatabase, tx: IDBPTransaction<unknown, string, 'versionchange'>): void {\n for (const def of STORE_DEFS) {\n if (db.objectStoreNames.contains(def.name)) {\n // Existing stores (pre-DB_VERSION layouts) keep whatever index set\n // they were born with — backfill indexes the current schema needs.\n const existing = tx.objectStore(def.name);\n for (const index of def.indexes) {\n if (!existing.indexNames.contains(index.name)) existing.createIndex(index.name, index.keyPath.length === 1 ? index.keyPath[0] : index.keyPath, { unique: index.unique, multiEntry: index.multiEntry });\n }\n continue;\n }\n const store = db.createObjectStore(def.name, { keyPath: def.keyPath.length === 1 ? def.keyPath[0] : def.keyPath });\n for (const index of def.indexes) store.createIndex(index.name, index.keyPath.length === 1 ? index.keyPath[0] : index.keyPath, { unique: index.unique, multiEntry: index.multiEntry });\n }\n for (const local of LOCAL_SYNC_STORES) {\n if (db.objectStoreNames.contains(local.name)) continue;\n db.createObjectStore(local.name, { keyPath: local.keyPath, autoIncrement: 'autoIncrement' in local ? local.autoIncrement : false });\n }\n}\n\nasync function migrateSchema(db: IDBPDatabase, oldVersion: number, tx: IDBPTransaction<unknown, string, 'versionchange'>): Promise<void> {\n const store = (name: string) => tx.objectStore(name);\n\n // V20 → V21: flatten sessions, drop data.logs, project legacy logs\n // idempotently into event rows.\n if (oldVersion === 20 && db.objectStoreNames.contains('sessions')) {\n const sessionsStore = store('sessions');\n const eventsStore = store('events');\n for await (const cursor of sessionsStore) {\n const legacy = cursor.value as LegacySession;\n const logs = legacy.data?.logs ?? [];\n let alreadyProjected = false;\n for await (const _ev of eventsStore.index('by-result-grain').iterate(IDBKeyRange.bound([legacy.id, ''], [legacy.id, []]))) {\n alreadyProjected = true;\n break;\n }\n if (!alreadyProjected && logs.length > 0) {\n const identity = {\n noteId: legacy.noteId, resultId: legacy.id, segmentId: legacy.segmentId,\n segmentVersion: legacy.segmentVersion, blockContentId: legacy.blockContentId,\n origin: legacy.origin, pageId: legacy.pageId,\n workoutTimestamp: legacy.data?.endTime ?? legacy.createdAt,\n };\n for (const row of toEventRows(logs as never, identity)) await eventsStore.put(row);\n for (const row of toSummaryEventRows(logs as never, identity)) await eventsStore.put(row);\n }\n const flat: Session = {\n ...legacy,\n startTime: legacy.data?.startTime ?? legacy.createdAt,\n endTime: legacy.data?.endTime ?? legacy.createdAt,\n duration: legacy.data?.duration ?? 0,\n completed: legacy.data?.completed ?? true,\n roundsCompleted: legacy.data?.roundsCompleted,\n totalRounds: legacy.data?.totalRounds,\n repsCompleted: legacy.data?.repsCompleted,\n };\n delete (flat as unknown as Record<string, unknown>).data;\n await cursor.update(flat);\n }\n }\n\n // V21 → V22: invalidate the pre-V22 seed checkpoint so the V22 seed\n // data re-applies cleanly.\n if (oldVersion === 21 && db.objectStoreNames.contains('meta')) {\n await store('meta').delete('seed');\n }\n\n // V25: memberships store + by-user ownership index on every user-owned\n // store. Presence-guarded: mixed-state databases exist in the wild.\n if (oldVersion < 25) {\n for (const name of USER_OWNED_STORES) {\n if (!db.objectStoreNames.contains(name)) continue;\n const s = store(name);\n if (!s.indexNames.contains('by-user')) s.createIndex('by-user', 'userId');\n }\n }\n\n // V26: results → sessions. Residual legacy rows are read BEFORE the store\n // disappears; inline logs are projected per deterministic id (existing\n // rows never overwritten, absent detail/summary rows added). The legacy\n // duplicate is discarded only after the canonical row is safe.\n if (db.objectStoreNames.contains('results')) {\n const sessionsStore = store('sessions');\n const resultsStore = store('results');\n const eventsStore = store('events');\n for await (const cursor of resultsStore) {\n const { data: legacyData, ...legacyRow } = cursor.value as LegacySession;\n const logs = legacyData?.logs ?? [];\n if (logs.length > 0) {\n const identity = {\n noteId: legacyRow.noteId, resultId: legacyRow.id, segmentId: legacyRow.segmentId,\n segmentVersion: legacyRow.segmentVersion, blockContentId: legacyRow.blockContentId,\n origin: legacyRow.origin, pageId: legacyRow.pageId,\n workoutTimestamp: legacyData?.endTime ?? legacyRow.createdAt,\n };\n for (const row of toEventRows(logs as never, identity)) {\n if ((await eventsStore.get(row.id)) === undefined) await eventsStore.put(row);\n }\n for (const row of toSummaryEventRows(logs as never, identity)) {\n if ((await eventsStore.get(row.id)) === undefined) await eventsStore.put(row);\n }\n }\n if ((await sessionsStore.getKey(legacyRow.id)) !== undefined) continue;\n await sessionsStore.put({\n ...legacyRow,\n startTime: legacyData?.startTime ?? legacyRow.startTime ?? legacyRow.createdAt,\n endTime: legacyData?.endTime ?? legacyRow.endTime ?? legacyRow.createdAt,\n duration: legacyData?.duration ?? legacyRow.duration ?? 0,\n completed: legacyData?.completed ?? legacyRow.completed ?? true,\n roundsCompleted: legacyData?.roundsCompleted ?? legacyRow.roundsCompleted,\n totalRounds: legacyData?.totalRounds ?? legacyRow.totalRounds,\n repsCompleted: legacyData?.repsCompleted ?? legacyRow.repsCompleted,\n });\n }\n db.deleteObjectStore('results');\n }\n\n // V26/V27 repairs (presence-guarded — the first V26 cut shipped without\n // these on real databases, so version 26 is ambiguous).\n if (db.objectStoreNames.contains('block_index') && !store('block_index').indexNames.contains('by-source')) {\n store('block_index').createIndex('by-source', 'sourceId');\n }\n if (db.objectStoreNames.contains('notes') && !store('notes').indexNames.contains('by-created')) {\n store('notes').createIndex('by-created', 'createdAt');\n }\n if (db.objectStoreNames.contains('efforts') && !store('efforts').indexNames.contains('by-source')) {\n store('efforts').createIndex('by-source', 'registrySource');\n }\n if (db.objectStoreNames.contains('note_tags') && !store('note_tags').indexNames.contains('by-note-tag')) {\n const noteTags = store('note_tags');\n // Unique pair index requires deterministic duplicate cleanup first —\n // duplicate links keep the lexicographically smallest row id.\n const winnerByPair = new Map<string, string>();\n const dupes: string[] = [];\n for await (const cursor of noteTags) {\n const row = cursor.value as { id: string; noteId: string; tagId: string };\n const pair = `${row.noteId}${row.tagId}`;\n const winner = winnerByPair.get(pair);\n if (winner === undefined || row.id < winner) {\n winnerByPair.set(pair, row.id);\n if (winner !== undefined) dupes.push(winner);\n } else {\n dupes.push(row.id);\n }\n }\n for (const id of dupes) await noteTags.delete(id);\n noteTags.createIndex('by-note-tag', ['noteId', 'tagId'], { unique: true });\n }\n\n // V28: dashboard typing repair — a note whose frontmatter segment says\n // `dashboard: true` gains type 'dashboard' / sourceId 'dashboards'.\n // Runs BEFORE the V29 pass consumes the segments store. Idempotent.\n if (db.objectStoreNames.contains('notes') && db.objectStoreNames.contains('segments')) {\n const segments = store('segments');\n const notes = store('notes');\n const repaired = new Set<string>();\n for await (const cursor of segments) {\n const segment = cursor.value as LegacySegment;\n if (segment.dataType !== 'frontmatter' || repaired.has(segment.noteId)) continue;\n if (!/(^|\\n)dashboard:\\s*[\"']?true[\"']?\\s*(\\n|$)/.test(segment.rawContent)) continue;\n repaired.add(segment.noteId);\n const note = await notes.get(segment.noteId);\n if (!note || (note.type === 'dashboard' && note.sourceId === 'dashboards')) continue;\n await notes.put({ ...note, type: 'dashboard', sourceId: note.sourceId ?? 'dashboards' });\n }\n }\n\n // V29: segments → note-owned blocks + block_revisions; sessions/events\n // segment fields → block fields; block_index rows remapped. The segments\n // store is dropped only after every note is rebuilt — the source of truth\n // survives until the migration transaction commits.\n if (db.objectStoreNames.contains('segments')) {\n await migrateSegmentsToBlocks(db, tx);\n }\n\n // V32: pending puts already exist in the terminal snapshot. Keep deletion\n // intent before that snapshot, with legacy wipes narrowed to user clears.\n // One group keeps history and its consumers together during replay.\n if (oldVersion >= 30 && oldVersion < 32 && db.objectStoreNames.contains(OUTBOX_STORE)) {\n const outbox = store(OUTBOX_STORE);\n const ops: SyncMutation[] = [];\n for (const group of await outbox.getAll() as { ops: SyncMutation[] }[]) {\n for (const mutation of group.ops) {\n if (mutation.op === 'wipe') {\n for (const name of NON_SYSTEM_STORES) {\n if (name !== 'block_revisions') ops.push({ op: 'clear', store: name });\n }\n } else if (mutation.op !== 'put' && mutation.store !== 'memberships' && mutation.store !== 'block_revisions') {\n ops.push(mutation);\n }\n }\n }\n ops.push(...await policySnapshotOps(name => store(name).getAll() as Promise<unknown[]>));\n await outbox.clear();\n if (ops.length > 0) await outbox.put({ id: crypto.randomUUID(), at: Date.now(), ops });\n if (db.objectStoreNames.contains(SYNC_STATE_STORE)) {\n const state = store(SYNC_STATE_STORE);\n for (const key of await state.getAllKeys()) {\n if (typeof key === 'string' && key.startsWith(BOOTSTRAP_RUN_PREFIX)) await state.delete(key);\n }\n }\n }\n}\n\nasync function migrateSegmentsToBlocks(db: IDBPDatabase, tx: IDBPTransaction<unknown, string, 'versionchange'>): Promise<void> {\n const store = (name: string) => tx.objectStore(name);\n const segments = (await store('segments').getAll()) as LegacySegment[];\n const notesStore = store('notes');\n const revisionsStore = store('block_revisions');\n\n // Group every versioned segment by note, then by positional segment id.\n const byNote = new Map<string, LegacySegment[]>();\n for (const segment of segments) {\n const list = byNote.get(segment.noteId);\n if (list) list.push(segment);\n else byNote.set(segment.noteId, [segment]);\n }\n\n // blockId per (noteId, segmentId) — sessions and block_index join through it.\n const blockIdBySegment = new Map<string, string>();\n const blockById = new Map<string, { noteId: string; from?: number; to?: number; version: number }>();\n\n for (const [noteId, noteSegments] of byNote) {\n const latestById = new Map<string, LegacySegment>();\n for (const segment of noteSegments) {\n const current = latestById.get(segment.id);\n if (!current || segment.version > current.version) latestById.set(segment.id, segment);\n }\n const latest = [...latestById.values()].sort((a, b) => (a.position ?? Number.MAX_SAFE_INTEGER) - (b.position ?? Number.MAX_SAFE_INTEGER) || a.id.localeCompare(b.id));\n const rawContent = latest.map(segment => segment.sourceContent ?? `${segment.rawContent}\\n`).join('');\n\n const note = await notesStore.get(noteId);\n if (!note) continue; // orphan segments without their note keep no state\n\n // Reconcile actionable blocks against the rebuilt source, preserving the\n // legacy positional segment id as the block id so session/block_index\n // references stay valid. Blocks with no legacy counterpart get a stable\n // positional id.\n const sections = parseDocumentSections(rawContent, { registeredWidgets: KNOWN_SECTION_WIDGETS });\n const actionableSections = sections.filter(section => actionableSectionKind(section) !== null);\n const legacyActionable = latest.filter(segment => segment.dataType in SEGMENT_TO_BLOCK_KIND);\n const blocks: Note['blocks'] = {};\n actionableSections.forEach((section, index) => {\n const kind = actionableSectionKind(section)!;\n const legacy = legacyActionable[index];\n let id = legacy?.id ?? `migrated-${index}`;\n while (Object.hasOwn(blocks, id)) id = `${id}-${index}`;\n const dialect = kind === 'wod' && (section.type === 'time' || section.type === 'log')\n ? { dialect: section.type, ...(section.sport ? { sport: section.sport } : {}) }\n : {};\n blocks[id] = { id, kind, version: legacy?.version ?? 1, sourceRevision: 1, from: section.from, to: section.to, ...dialect };\n if (legacy) blockIdBySegment.set(`${noteId}${legacy.id}`, id);\n blockById.set(`${noteId}${id}`, { noteId, from: section.from, to: section.to, version: blocks[id].version });\n });\n\n const legacy = note as Record<string, unknown>;\n delete legacy.segments;\n delete legacy.segmentIds;\n await notesStore.put({ ...legacy, rawContent, sourceRevision: 1, blocks });\n\n // Every versioned segment of an actionable id becomes a block revision\n // (historical segments included — the revision store is the history).\n const revisioned = new Set(legacyActionable.map(segment => segment.id));\n for (const segment of noteSegments) {\n if (!revisioned.has(segment.id)) continue;\n const dialect = legacyDialect(segment.rawContent);\n await revisionsStore.put({\n noteId, blockId: segment.id, version: segment.version, kind: 'wod',\n rawContent: segment.rawContent, savedAt: segment.createdAt, ...dialect,\n } satisfies BlockRevision);\n }\n }\n\n // Sessions: segmentId/segmentVersion (and the retired compute `version`)\n // become blockId/blockVersion. Values carry over unchanged — the V29 pass\n // above preserved legacy segment ids as block ids.\n const sessionsStore = store('sessions');\n for (const row of (await sessionsStore.getAll()) as LegacySession[]) {\n if (row.segmentId === undefined && row.segmentVersion === undefined && row.version === undefined) continue;\n const { segmentId, segmentVersion, version, ...rest } = row;\n await sessionsStore.put({\n ...rest,\n blockId: rest.blockId ?? segmentId ?? '',\n blockVersion: rest.blockVersion ?? segmentVersion ?? version ?? 1,\n } as Session);\n }\n\n // Events: same rename on the version field.\n const eventsStore = store('events');\n for (const row of await eventsStore.getAll() as Record<string, unknown>[]) {\n if (row.segmentVersion === undefined && row.segmentId === undefined) continue;\n const { segmentVersion, segmentId, ...rest } = row;\n await eventsStore.put({\n ...rest,\n ...(rest.blockId === undefined && segmentId !== undefined ? { blockId: segmentId } : {}),\n ...(rest.blockVersion === undefined && segmentVersion !== undefined ? { blockVersion: segmentVersion } : {}),\n });\n }\n\n // block_index: `${noteId}:${segmentId}:${segmentVersion}` →\n // `${noteId}:${blockId}` with the note block's offsets. Rows whose segment\n // vanished from the segments store keep their legacy id as the block id —\n // the index is a derived projection, never silently dropped.\n const blockIndex = store('block_index');\n for (const row of (await blockIndex.getAll()) as LegacyBlockIndexRow[]) {\n const mapped = blockIdBySegment.get(`${row.noteId}${row.segmentId}`) ?? row.segmentId;\n const block = blockById.get(`${row.noteId}${mapped}`);\n const next = {\n ...row,\n id: `${row.noteId}:${mapped}`,\n blockId: mapped,\n blockVersion: block?.version ?? row.segmentVersion ?? 1,\n sourceRevision: 1,\n ...(block ? { from: block.from, to: block.to } : {}),\n dataType: row.dataType === 'script' ? 'wod' : row.dataType,\n };\n delete (next as Record<string, unknown>).segmentId;\n delete (next as Record<string, unknown>).segmentVersion;\n if (next.id !== row.id) await blockIndex.delete(row.id);\n await blockIndex.put(next);\n }\n // block_efforts already carries blockId = the legacy positional segment id,\n // which the V29 pass preserved — no remap needed.\n\n db.deleteObjectStore('segments');\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/idb/catalog.ts","../../src/idb/index.ts"],"names":["def","store","table","legacy"],"mappings":";;;;;;;;;AAiBO,IAAM,2BAAA,GAAsC;AAI5C,SAAS,yBAAyB,IAAA,EAA+B;AACtE,EAAA,OAAO,OAAO,IAAA,KAAS,QAAA,IAAY,mCAAA,CAAoC,KAAK,IAAI,CAAA;AAClF;AAIA,eAAsB,kBAAA,GAAmD;AACvE,EAAA,MAAM,MAAM,UAAA,CAAW,SAAA;AACvB,EAAA,IAAI,CAAC,GAAA,IAAO,OAAO,IAAI,SAAA,KAAc,UAAA,SAAmB,EAAC;AACzD,EAAA,MAAM,OAAA,GAAU,MAAM,GAAA,CAAI,SAAA,GAAY,KAAA,CAAM,MAAM,EAAuB,CAAA;AACzE,EAAA,OAAO,OAAA,CAAQ,OAAA;AAAA,IAAQ,CAAC,UACtB,OAAO,KAAA,CAAM,SAAS,QAAA,GAClB,CAAC,EAAE,IAAA,EAAM,KAAA,CAAM,MAAM,OAAA,EAAS,OAAO,MAAM,OAAA,KAAY,QAAA,GAAW,MAAM,OAAA,GAAU,IAAA,EAAM,CAAA,GACxF;AAAC,GACP;AACF;AAIA,eAAsB,oBAAoB,IAAA,EAA6B;AACrE,EAAA,IAAI,CAAC,wBAAA,CAAyB,IAAI,CAAA,EAAG,MAAM,IAAI,KAAA,CAAM,CAAA,6BAAA,EAAgC,MAAA,CAAO,IAAI,CAAC,CAAA,EAAA,CAAI,CAAA;AACrG,EAAA,MAAM,MAAM,UAAA,CAAW,SAAA;AACvB,EAAA,IAAI,CAAC,GAAA,EAAK;AACV,EAAA,MAAM,IAAI,OAAA,CAAc,CAAC,OAAA,EAAS,MAAA,KAAW;AAC3C,IAAA,MAAM,OAAA,GAAU,GAAA,CAAI,cAAA,CAAe,IAAI,CAAA;AACvC,IAAA,OAAA,CAAQ,SAAA,GAAY,MA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I,SAAS,CAAA,CAAE,CAAA,IAAK,GAAA,CAAI,SAAA;AAC5E,IAAA,MAAM,KAAA,GAAQ,UAAU,GAAA,CAAI,CAAA,EAAG,IAAI,MAAM,CAAA,EAAG,MAAM,CAAA,CAAE,CAAA;AACpD,IAAA,MAAM,IAAA,GAAO;AAAA,MACX,GAAG,GAAA;AAAA,MACH,EAAA,EAAI,CAAA,EAAG,GAAA,CAAI,MAAM,IAAI,MAAM,CAAA,CAAA;AAAA,MAC3B,OAAA,EAAS,MAAA;AAAA,MACT,YAAA,EAAc,KAAA,EAAO,OAAA,IAAW,GAAA,CAAI,cAAA,IAAkB,CAAA;AAAA,MACtD,cAAA,EAAgB,CAAA;AAAA,MAChB,GAAI,KAAA,GAAQ,EAAE,IAAA,EAAM,KAAA,CAAM,MAAM,EAAA,EAAI,KAAA,CAAM,EAAA,EAAG,GAAI,EAAC;AAAA,MAClD,QAAA,EAAU,GAAA,CAAI,QAAA,KAAa,QAAA,GAAW,QAAQ,GAAA,CAAI;AAAA,KACpD;AACA,IAAA,OAAQ,IAAA,CAAiC,SAAA;AACzC,IAAA,OAAQ,IAAA,CAAiC,cAAA;AACzC,IAAA,IAAI,IAAA,CAAK,OAAO,GAAA,CAAI,EAAA,QAAU,UAAA,CAAW,MAAA,CAAO,IAAI,EAAE,CAAA;AACtD,IAAA,MAAM,UAAA,CAAW,IAAI,IAAI,CAAA;AAAA,EAC3B;AAIA,EAAA,EAAA,CAAG,kBAAkB,UAAU,CAAA;AACjC","file":"index.mjs","sourcesContent":["/**\n * Local database catalog — enumerate/delete the browser-local IndexedDB\n * databases behind the active-profile selector. The default app database is\n * never created or destroyed here: the catalog only manages the auxiliary\n * (restore/scratch) databases that the database switcher offers.\n *\n * This module deliberately does NOT import the storage adapter: the adapter\n * lives in ./index, which re-exports this catalog, so an import back would\n * close a module cycle. Creating a database (which needs the adapter's\n * schema upgrade path) therefore lives beside the adapter in ./index.\n */\n\nexport interface LocalDatabaseInfo { name: string; version: number | null }\n\n/** Canonical app-database name (\"wodwiki-db\"). Defined HERE, not imported\n * from ./index, because the re-export cycle would read it before index.ts\n * initialized it (index.ts: export const IDB_DB_NAME = DEFAULT_LOCAL_DATABASE_NAME). */\nexport const DEFAULT_LOCAL_DATABASE_NAME: string = 'wodwiki-db';\n\n/** Same rule as the app-side isValidLocalDbName — one name vocabulary\n * everywhere (restore, catalog, settings persistence). */\nexport function isValidLocalDatabaseName(name: unknown): name is string {\n return typeof name === 'string' && /^[A-Za-z0-9][A-Za-z0-9._-]{0,99}$/.test(name);\n}\n\n/** Native enumeration when the browser exposes it; [] otherwise (old\n * Safari/Firefox lack databases()) — never throws. */\nexport async function listLocalDatabases(): Promise<LocalDatabaseInfo[]> {\n const idb = globalThis.indexedDB;\n if (!idb || typeof idb.databases !== 'function') return [];\n const entries = await idb.databases().catch(() => [] as IDBDatabaseInfo[]);\n return entries.flatMap((entry) =>\n typeof entry.name === 'string'\n ? [{ name: entry.name, version: typeof entry.version === 'number' ? entry.version : null }]\n : [],\n );\n}\n\n/** Delete one named database only; a blocked delete resolves (an open\n * connection elsewhere wins — the scratch data is disposable). */\nexport async function deleteLocalDatabase(name: string): Promise<void> {\n if (!isValidLocalDatabaseName(name)) throw new Error(`Invalid local database name \"${String(name)}\".`);\n const idb = globalThis.indexedDB;\n if (!idb) return;\n await new Promise<void>((resolve, reject) => {\n const request = idb.deleteDatabase(name);\n request.onsuccess = () => resolve();\n request.onerror = () => reject(request.error ?? new Error(`Failed to delete local database \"${name}\".`));\n request.onblocked = () => resolve();\n });\n}\n","/**\n * IndexedDB adapter — the browser data plane (moved verbatim from the\n * playground app; the shared user policy and the schema32 sync cutover live\n * here now). Local-first invariants:\n *\n * - Every committed local transaction group is durable in `sync_outbox`,\n * written in the SAME native transaction as the data writes.\n * - Snapshots (`snapshotRows`, bootstrap, conversion) are policy-compliant:\n * they carry user data only, per the shared policy in `../policy`.\n * - `sync_state` holds pull cursors, upload watermarks and frozen\n * bootstrap runs (durable retry identities), all per backup target.\n */\n\nimport { openDB, type IDBPDatabase, type IDBPTransaction } from 'idb';\nimport type {\n IReadOnlyStore, IReadWriteStore, IStorage, IStorageTransaction, StoreName, StoreType,\n} from '../contract';\nimport { DB_VERSION, STORE_DEFS } from '../schema';\nimport {\n DEFAULT_LOCAL_DATABASE_NAME, isValidLocalDatabaseName, type LocalDatabaseInfo,\n} from './catalog';\nimport { USER_OWNED_STORES, stampUserOwned } from '../membership';\nimport { keyFromValue, type KeyDTO } from '../wire';\nimport type { Note, Session, BlockRevision } from '../entities';\nimport {\n rowsEqual, validateStorageRow, validateNoteWrite, validateSessionWrite, validateStoredPins,\n} from '../validation';\nimport { collectUserScopeContext, isUserOwnedRow, USER_DELETED_SEED_PREFIX, type UserScopeContext } from '../policy';\nimport { readRawSyncOps, readLegacyRows, type SyncEntry, type SyncMutation } from '../sql/sync';\nimport type { Database } from '../sql/connection';\nimport {\n parseDocumentSections, actionableSectionKind, matchDialectFence, KNOWN_SECTION_WIDGETS,\n} from '@bitcobblers/wod-wiki-core';\nimport { toEventRows, toSummaryEventRows } from '@bitcobblers/wod-wiki-wql';\n\nexport const IDB_DB_NAME = DEFAULT_LOCAL_DATABASE_NAME;\n\nexport {\n DEFAULT_LOCAL_DATABASE_NAME, deleteLocalDatabase,\n isValidLocalDatabaseName, listLocalDatabases, type LocalDatabaseInfo,\n} from './catalog';\n\n/** Create a named database at the current schema (DB_VERSION) by opening it\n * through the regular adapter, then close. Refuses the default database —\n * the catalog never touches the live app profile.\n *\n * Lives beside the adapter (not in ./catalog) because it needs the\n * adapter's schema upgrade path, and the adapter's module re-exports the\n * catalog — importing the adapter back from the catalog would close a\n * module cycle. */\nexport async function createLocalDatabase(name: string): Promise<LocalDatabaseInfo> {\n if (!isValidLocalDatabaseName(name)) throw new Error(`Invalid local database name \"${String(name)}\".`);\n if (name === DEFAULT_LOCAL_DATABASE_NAME) throw new Error('The default database cannot be created here.');\n const storage = new IndexedDBStorage({ dbName: name });\n try {\n await storage.open();\n } finally {\n await storage.close().catch(() => undefined);\n }\n return { name, version: DB_VERSION };\n}\n\n// Browser-local sync stores — NOT part of the shared STORE_DEFS spec (the\n// SQL/API schema is unchanged). `sync_outbox` is the durable journal: one\n// entry per committed local transaction group, written in the SAME native\n// transaction as the data writes, so an aborted transaction never journals\n// and a journaled group always reflects committed data. `sync_state` holds\n// the pull cursor, the upload watermark and frozen bootstrap runs.\nconst OUTBOX_STORE = 'sync_outbox';\nconst SYNC_STATE_STORE = 'sync_state';\nconst LOCAL_SYNC_STORES = [\n { name: OUTBOX_STORE, keyPath: 'seq', autoIncrement: true },\n { name: SYNC_STATE_STORE, keyPath: 'key' },\n] as const;\n\n/** sync_state keys of frozen bootstrap runs (TursoSyncEngine naming). */\nconst BOOTSTRAP_RUN_PREFIX = 'bootstrap-run:';\n\nconst NON_SYSTEM_STORES: readonly StoreName[] = STORE_DEFS.filter(def => !def.system).map(def => def.name);\n\n// Bootstrap chunks: whole ops only, bounded per group for network batches.\nconst BOOTSTRAP_MAX_OPS = 500;\nconst BOOTSTRAP_MAX_BYTES = 1_000_000;\n\n/** Stores whose rows carry a raw binary field (base64 in the op log). */\nconst BINARY_SYNC_FIELDS: Record<string, string> = { attachments: 'data' };\n\n/** Legacy direct-Turso tables that predate the current STORE_DEFS spec. */\nconst LEGACY_EXTRA_TABLES: { name: string; keyPath: string | string[] }[] = [\n { name: 'segments', keyPath: ['id', 'version'] },\n { name: 'results', keyPath: 'id' },\n];\n\ntype Mode = 'readonly' | 'readwrite';\n/** Native tx handle; write methods are guarded at runtime by `mutable`, so\n * the handle is typed readwrite to keep put/delete/clear defined. */\ntype Tx = IDBPTransaction<unknown, string, 'readwrite'>;\n\n/** Per-transaction mutation collector — becomes one outbox entry on commit.\n * `ctx` lazily caches the tx's user-scope context (seed note ids) for\n * journal-time ownership classification; invalidated when notes change. */\nclass TxJournal {\n readonly ops: SyncMutation[] = [];\n ctx?: Promise<UserScopeContext>;\n}\n\n/** Post-commit outbox notification — the sync engine debounces uploads off\n * these instead of polling the network while the app is idle. Fired only\n * AFTER the committing transaction durably lands (fire-and-forget). */\nconst outboxListeners = new Set<() => void>();\n\nexport function subscribeOutboxWrites(listener: () => void): () => void {\n outboxListeners.add(listener);\n return () => {\n outboxListeners.delete(listener);\n };\n}\n\nfunction notifyOutboxCommit(): void {\n for (const listener of outboxListeners) listener();\n}\n\nfunction isKeyRange(key: unknown): key is IDBKeyRange {\n return key !== null && typeof key === 'object' && !Array.isArray(key)\n && ('lower' in key || 'upper' in key || 'lowerOpen' in key || 'upperOpen' in key);\n}\n\n/** Approximate encoded op-log size of one mutation: JSON envelope plus\n * base64-inflated binary cells (ArrayBuffer serializes as {} in JSON, so a\n * plain JSON.stringify would undercount attachment-heavy batches). */\nfunction mutationBytes(op: SyncMutation): number {\n if (op.op !== 'put') return 32; // envelope + key estimate\n let bytes = 32;\n const field = BINARY_SYNC_FIELDS[op.store];\n const value: unknown = op.value;\n const data = field && value !== null && typeof value === 'object' && !Array.isArray(value) && field in value\n ? Reflect.get(value, field)\n : undefined;\n bytes += typeof data === 'string' ? data.length\n : data instanceof ArrayBuffer ? Math.ceil(data.byteLength / 3) * 4 + 64\n : JSON.stringify(op.value)?.length ?? 0;\n return bytes;\n}\n\n/**\n * One policy-compliant snapshot as put mutations, in STORE_DEFS order.\n * Strict: a row whose key cannot be derived is corrupted data — it fails\n * the pass instead of being silently dropped.\n *\n * Immutable revision history is emitted BEFORE notes and sessions so chunk\n * boundaries (bootstrap/conversion grouping) can never split a pin from the\n * revision it references: every chunk that carries a consumer row already\n * carries its history.\n */\nconst SNAPSHOT_OP_ORDER: readonly StoreName[] = [\n 'block_revisions',\n 'notes',\n 'sessions',\n ...NON_SYSTEM_STORES.filter(\n name => name !== 'block_revisions' && name !== 'notes' && name !== 'sessions',\n ),\n];\n\n/** Snapshot ops are always puts — narrowed so callers can read store/key. */\ntype SnapshotPut = Extract<SyncMutation, { op: 'put' }>;\n\nasync function policySnapshotOps(\n readAll: (store: StoreName) => Promise<unknown[]>,\n): Promise<SnapshotPut[]> {\n const ctx = collectUserScopeContext(await readAll('notes'));\n const ops: SnapshotPut[] = [];\n for (const store of SNAPSHOT_OP_ORDER) {\n const def = STORE_DEFS.find(candidate => candidate.name === store)!;\n for (const row of await readAll(store)) {\n if (!isUserOwnedRow(store, row, ctx)) continue;\n ops.push({ op: 'put', store, key: keyFromValue(def, row), value: row });\n }\n }\n return ops;\n}\n\nclass IDBStore<T> implements IReadWriteStore<T> {\n constructor(\n private readonly owner: IndexedDBStorage,\n private readonly name: StoreName,\n private readonly tx?: Tx,\n private readonly mutable = false,\n private readonly touched?: { notes: Set<string>; sessions: Set<string> },\n private readonly journal?: TxJournal,\n ) {}\n\n async get(key: IDBValidKey): Promise<T | undefined> {\n if (this.tx) return this.tx.objectStore(this.name).get(key);\n return (await this.owner.open()).get(this.name, key);\n }\n\n async getMany(keys: IDBValidKey[]): Promise<(T | undefined)[]> {\n if (this.tx) return Promise.all(keys.map(key => this.tx!.objectStore(this.name).get(key)));\n return this.owner.transaction([this.name], 'readonly', tx => tx.readonly(this.name).getMany(keys)) as Promise<(T | undefined)[]>;\n }\n\n async getAll(query?: IDBValidKey | IDBKeyRange, count?: number): Promise<T[]> {\n if (this.tx) return this.tx.objectStore(this.name).getAll(query, count);\n return (await this.owner.open()).getAll(this.name, query, count);\n }\n\n async getAllFromIndex(index: string, query?: IDBValidKey | IDBKeyRange, count?: number): Promise<T[]> {\n if (this.tx) return this.tx.objectStore(this.name).index(index).getAll(query, count);\n return (await this.owner.open()).getAllFromIndex(this.name, index, query, count);\n }\n\n async getAllFromIndexMany(index: string, keys: IDBValidKey[]): Promise<T[][]> {\n if (this.tx) return Promise.all(keys.map(key => this.tx!.objectStore(this.name).index(index).getAll(key)));\n return this.owner.transaction([this.name], 'readonly', tx => tx.readonly(this.name).getAllFromIndexMany(index, keys)) as Promise<T[][]>;\n }\n\n async count(query?: IDBValidKey | IDBKeyRange): Promise<number> {\n if (this.tx) return this.tx.objectStore(this.name).count(query);\n return (await this.owner.open()).count(this.name, query);\n }\n\n async countFromIndex(index: string, query?: IDBValidKey | IDBKeyRange): Promise<number> {\n if (this.tx) return this.tx.objectStore(this.name).index(index).count(query);\n return (await this.owner.open()).countFromIndex(this.name, index, query);\n }\n\n async put(value: T, _key?: IDBValidKey): Promise<IDBValidKey> {\n if (!this.mutable) throw new Error('read-only store');\n if (!this.tx) {\n const scope = this.name === 'notes' ? [this.name, 'block_revisions'] as const : [this.name, 'block_revisions', 'notes'] as const;\n return this.owner.transaction([...scope], 'readwrite', tx => tx.readwrite(this.name).put(value as StoreType<typeof this.name>));\n }\n const stored = this.owner.stamp(this.name, value);\n validateStorageRow(this.name, stored);\n const def = STORE_DEFS.find(def => def.name === this.name)!;\n const key = keyFromValue(def, stored);\n const store = this.tx.objectStore(this.name);\n const previous = await store.get(key);\n if (this.name === 'block_revisions' && previous !== undefined && !rowsEqual(previous, stored)) throw new Error('immutable block revision collision');\n if (this.name === 'notes') validateNoteWrite(previous, stored);\n if (this.name === 'sessions') validateSessionWrite(previous, stored);\n if (rowsEqual(previous, stored)) return key;\n const result = await store.put(stored);\n if (!def.system && this.journal) {\n // Journal-time ownership classification (§3.4), INSIDE the write\n // transaction: user→user and seed→user emit complete user puts;\n // seed→seed ships nothing (the remote re-imports seed data itself);\n // user→seed emits a tombstone for the former user record instead of\n // silently dropping it.\n const ctx = this.name === 'notes'\n ? undefined\n : await (this.journal.ctx ??= this.owner.policyContext(this.tx!));\n const wasUser = previous !== undefined && isUserOwnedRow(this.name, previous, ctx ?? collectUserScopeContext([]));\n const isUser = isUserOwnedRow(this.name, stored, ctx ?? collectUserScopeContext([]));\n if (isUser) {\n if (this.name === 'notes' && stored !== null && typeof stored === 'object' && 'id' in stored) {\n for (const revision of await this.tx.objectStore('block_revisions').index('by-note').getAll(String(stored.id))) {\n this.journal.ops.push({ op: 'put', store: 'block_revisions', key: [revision.noteId, revision.blockId, revision.version], value: revision });\n }\n } else if (this.name === 'sessions' && stored !== null && typeof stored === 'object' && 'noteId' in stored && 'blockId' in stored && 'blockVersion' in stored) {\n const revisionKey = [stored.noteId, stored.blockId, stored.blockVersion] as IDBValidKey;\n const revision = await this.tx.objectStore('block_revisions').get(revisionKey);\n if (revision) this.journal.ops.push({ op: 'put', store: 'block_revisions', key: revisionKey as KeyDTO, value: revision });\n }\n this.journal.ops.push({ op: 'put', store: this.name, key: key as KeyDTO, value: stored });\n }\n else if (wasUser) this.journal.ops.push({ op: 'delete', store: this.name, key: key as KeyDTO });\n // notes writes shift seed provenance — reclassify later stores in\n // this transaction against the post-write notes.\n if (this.name === 'notes') this.journal.ctx = undefined;\n }\n if (this.name === 'notes') this.touched?.notes.add(String(key));\n if (this.name === 'sessions') this.touched?.sessions.add(String(key));\n return result;\n }\n\n async putMany(values: T[], keys?: IDBValidKey[]): Promise<IDBValidKey[]> {\n if (keys && keys.length !== values.length) throw new Error('putMany key count mismatch');\n if (!this.tx) {\n const scope = this.name === 'notes' ? [this.name, 'block_revisions'] as const : [this.name, 'block_revisions', 'notes'] as const;\n return this.owner.transaction([...scope], 'readwrite', tx => tx.readwrite(this.name).putMany(values as StoreType<typeof this.name>[], keys));\n }\n const out: IDBValidKey[] = [];\n for (let i = 0; i < values.length; i++) out.push(await this.put(values[i], keys?.[i]));\n return out;\n }\n\n async delete(key: IDBValidKey | IDBKeyRange): Promise<void> {\n if (!this.mutable) throw new Error('read-only store');\n if (this.name === 'block_revisions') throw new Error('block history requires explicit wipe');\n if (!this.tx) {\n // Journal-time ownership classification reads notes in the same tx.\n const scope = this.name === 'notes' ? [this.name] as const : [this.name, 'notes'] as const;\n return this.owner.transaction([...scope], 'readwrite', tx => tx.readwrite(this.name).delete(key));\n }\n if (this.name === 'notes') {\n for (const note of await this.tx.objectStore('notes').getAll(key)) {\n for (const name of ['block_index', 'block_efforts', 'block_equipment'] as const) {\n const store = this.tx.objectStore(name);\n for (const id of await store.index('by-note').getAllKeys(note.id)) {\n const projection = new IDBStore(this.owner, name, this.tx, true, this.touched, this.journal);\n await projection.delete(id);\n }\n }\n }\n }\n await this.recordDelete(key);\n await this.tx.objectStore(this.name).delete(key);\n }\n\n /** Journal a delete as per-key tombstones (ranges expand to their keys).\n * Journal-time ownership: only deletes of USER-scope rows ship — a seed\n * row's removal is re-imported remotely, not a user mutation (deleting a\n * seed NOTE carries intent via the user-deleted-seed meta tombstone the\n * caller writes in the same transaction). */\n private async recordDelete(key: IDBValidKey | IDBKeyRange): Promise<void> {\n if (!this.journal) return;\n const store = this.tx!.objectStore(this.name);\n const keys = isKeyRange(key) ? await store.getAllKeys(key) : [key as IDBValidKey];\n const ctx = this.name === 'notes'\n ? undefined\n : await (this.journal.ctx ??= this.owner.policyContext(this.tx!));\n for (const k of keys) {\n const previous = await store.get(k);\n if (previous !== undefined && !isUserOwnedRow(this.name, previous, ctx ?? collectUserScopeContext([]))) continue;\n this.journal.ops.push({ op: 'delete', store: this.name, key: k as KeyDTO });\n }\n }\n\n /**\n * User-scope clear: expands to per-key deletes of user-owned rows,\n * journaled the same way so replay preserves exactly what the local clear\n * preserved — seed content (re-importable), pinned revision history\n * (block_revisions requires explicit wipe) and seed-deletion tombstones\n * survive a clear. A journaled `{op:'clear'}` would wipe seed rows on\n * every replaying device.\n */\n async clear(): Promise<void> {\n if (!this.mutable) throw new Error('read-only store');\n if (this.name === 'block_revisions') throw new Error('block history requires explicit wipe');\n if (!this.tx) {\n const scope = this.name === 'notes' ? ['notes', 'block_index', 'block_efforts'] as const : [this.name, 'notes'] as const;\n return this.owner.transaction([...scope], 'readwrite', tx => tx.readwrite(this.name).clear());\n }\n const store = this.tx.objectStore(this.name);\n const rows = await store.getAll() as unknown[];\n const notes = this.name === 'notes' ? rows : await this.tx.objectStore('notes').getAll() as unknown[];\n const ctx = collectUserScopeContext(notes);\n for (const row of rows) {\n const key = keyFromValue(STORE_DEFS.find(def => def.name === this.name)!, row);\n if (!isUserOwnedRow(this.name, row, ctx)) continue;\n if (this.name === 'meta' && typeof key === 'string' && key.startsWith(USER_DELETED_SEED_PREFIX)) continue;\n if (this.name === 'notes' && typeof key === 'string') {\n // Cascade the note's projections first — keys read BEFORE deletion,\n // each journaled as its own tombstone.\n for (const name of ['block_index', 'block_efforts', 'block_equipment'] as const) {\n const projections = this.tx.objectStore(name);\n for (const id of await projections.index('by-note').getAllKeys(key)) {\n this.journal?.ops.push({ op: 'delete', store: name, key: id as KeyDTO });\n await projections.delete(id);\n }\n }\n }\n await this.recordDelete(key);\n await store.delete(key);\n }\n }\n}\n\n// ---------------------------------------------------------------------------\n// Legacy row shapes (V20–V28) — read-only migration input, never written back.\n// ---------------------------------------------------------------------------\n\ninterface LegacySessionData {\n logs?: unknown[];\n startTime?: number;\n endTime?: number;\n duration?: number;\n completed?: boolean;\n roundsCompleted?: number;\n totalRounds?: number;\n repsCompleted?: number;\n}\n\ntype LegacySession = Session & { data?: LegacySessionData; segmentId?: string; segmentVersion?: number; version?: number };\n\ninterface LegacySegment {\n id: string;\n version: number;\n noteId: string;\n position?: number;\n dataType: string;\n rawContent: string;\n sourceContent?: string;\n createdAt: number;\n isHistory?: boolean;\n}\n\ninterface LegacyBlockIndexRow {\n id: string;\n noteId: string;\n segmentId: string;\n segmentVersion?: number;\n position?: number;\n dataType: string;\n rawContent: string;\n noteTitle: string;\n createdAt: number;\n isStatic?: boolean;\n sourceId?: string;\n sourcePath?: string;\n routeId?: string;\n blockContentId?: string;\n}\n\nconst SEGMENT_TO_BLOCK_KIND: Record<string, 'wod'> = { script: 'wod', wod: 'wod' };\n\nfunction legacyDialect(rawContent: string): { dialect?: 'time' | 'log'; sport?: string } {\n const first = rawContent.slice(0, rawContent.indexOf('\\n'));\n return matchDialectFence(first.trim()) ?? {};\n}\n\nexport class IndexedDBStorage implements IStorage {\n private opening?: Promise<IDBPDatabase>;\n constructor(private readonly options: {\n getUserId?: () => string;\n /** Called just before a schema migration runs (oldVersion < DB_VERSION). */\n onUpgradeStart?: (fromVersion: number) => void;\n /** Database file name; the sync engine migrates scratch copies under\n * their own name so a remote-schema conversion never touches the\n * live database. Defaults to the app database. */\n dbName?: string;\n } = {}) {}\n\n open(): Promise<IDBPDatabase> {\n if (typeof indexedDB === 'undefined') return Promise.reject(new Error('IndexedDB is unavailable in this environment'));\n if (!this.opening) {\n let newer = false;\n let pre20 = 0;\n let migrationError: Error | undefined;\n this.opening = openDB(this.options.dbName ?? IDB_DB_NAME, DB_VERSION, {\n upgrade: async (db, oldVersion, _version, tx) => {\n void tx.done.catch(() => {});\n if (oldVersion > DB_VERSION) {\n // A newer client owns this database — never downgrade or rewrite it.\n newer = true;\n tx.abort();\n return;\n }\n if (oldVersion !== 0 && oldVersion < 20) {\n // Pre-V20 layouts predate the versioned migration chain. Their\n // rows are NEVER silently destroyed: the upgrade aborts with an\n // actionable error so the user can export from an older app or\n // explicitly clear site data. The database file stays untouched.\n pre20 = oldVersion;\n tx.abort();\n return;\n }\n try {\n createMissingStores(db, tx);\n if (oldVersion !== 0 && oldVersion < DB_VERSION) this.options.onUpgradeStart?.(oldVersion);\n await migrateSchema(db, oldVersion, tx);\n } catch (error) {\n migrationError = error instanceof Error ? error : new Error(String(error));\n try { tx.abort(); } catch { /* The failed request may already have aborted it. */ }\n }\n },\n blocking: () => { void this.close(); },\n }).catch(error => {\n this.opening = undefined;\n if (migrationError) throw migrationError;\n if (pre20 !== 0) {\n throw new Error(\n `local database schema v${pre20} predates the supported migration chain (v20+). `\n + 'Open this browser profile in an intermediate app version to export your data, '\n + 'or clear site data to start fresh — the old database was left untouched.',\n );\n }\n throw newer || (error instanceof DOMException && error.name === 'VersionError')\n ? new Error(`database schema is newer than this client supports (v${DB_VERSION}); refusing to downgrade`) : error;\n });\n }\n return this.opening;\n }\n\n stamp(store: StoreName, value: unknown): unknown {\n const userId = this.options.getUserId?.();\n return userId ? stampUserOwned(store, value, userId) : value;\n }\n\n /** User-scope context (proven seed note ids) from the notes of `tx` —\n * journal-time ownership classification reads it INSIDE the same\n * transaction, so a seed import's note writes are visible to the link\n * writes that follow in the same commit. Internal seam for IDBStore. */\n async policyContext(tx?: Tx): Promise<UserScopeContext> {\n const notes = tx\n ? await tx.objectStore('notes').getAll() as unknown[]\n : await (await this.open()).getAll('notes') as unknown[];\n return collectUserScopeContext(notes);\n }\n\n readonly<K extends StoreName>(store: K): IReadOnlyStore<StoreType<K>> { return new IDBStore(this, store); }\n readwrite<K extends StoreName>(store: K): IReadWriteStore<StoreType<K>> { return new IDBStore(this, store, undefined, true); }\n\n async transaction<K extends StoreName, R>(stores: K[], mode: Mode, fn: (tx: IStorageTransaction) => Promise<R>): Promise<R> {\n const db = await this.open();\n const journal = mode === 'readwrite' ? new TxJournal() : undefined;\n const scope = new Set<string>(stores);\n if (mode === 'readwrite') {\n scope.add('block_revisions');\n scope.add(OUTBOX_STORE);\n scope.add('notes');\n if (scope.has('notes')) {\n scope.add('block_index');\n scope.add('block_efforts');\n scope.add('block_equipment');\n }\n }\n const native = db.transaction([...scope], mode) as Tx;\n const done = native.done;\n void done.catch(() => {});\n const touched = { notes: new Set<string>(), sessions: new Set<string>() };\n const adapter: IStorageTransaction = {\n readonly: name => {\n if (!scope.has(name)) throw new Error('store outside transaction scope');\n return new IDBStore(this, name, native);\n },\n readwrite: name => {\n if (mode !== 'readwrite') throw new Error('read-only transaction');\n if (!scope.has(name)) throw new Error('store outside transaction scope');\n return new IDBStore(this, name, native, true, touched, journal);\n },\n };\n try {\n const result = await fn(adapter);\n const notes = (await Promise.all([...touched.notes].map(id => native.objectStore('notes').get(id)))).filter(Boolean) as Note[];\n const sessions = (await Promise.all([...touched.sessions].map(id => native.objectStore('sessions').get(id)))).filter(Boolean) as Session[];\n await validateStoredPins(notes, sessions, keys => Promise.all(keys.map(key => native.objectStore('block_revisions').get(key))) as Promise<(BlockRevision | undefined)[]>);\n // Durable outbox: the journal entry lands in the SAME transaction as\n // the data writes — it commits with them and vanishes with them.\n if (journal && journal.ops.length > 0) {\n await native.objectStore(OUTBOX_STORE).put({ id: crypto.randomUUID(), at: Date.now(), ops: journal.ops });\n }\n await done;\n if (journal && journal.ops.length > 0) notifyOutboxCommit();\n return result;\n } catch (error) {\n try { native.abort(); } catch { /* The native request may have already aborted. */ }\n await done.catch(() => {});\n throw error;\n }\n }\n\n async wipeUserData(): Promise<void> {\n const names = STORE_DEFS.filter(def => !def.system && def.name !== 'block_revisions').map(def => def.name);\n await this.transaction(names, 'readwrite', async tx => {\n for (const name of names) await tx.readwrite(name).clear();\n });\n }\n\n async wipe(): Promise<void> {\n const db = await this.open();\n const names = STORE_DEFS.filter(def => !def.system).map(def => def.name);\n const tx = db.transaction([...names, OUTBOX_STORE], 'readwrite');\n await Promise.all(names.map(name => tx.objectStore(name).clear()));\n await tx.objectStore(OUTBOX_STORE).put({ id: crypto.randomUUID(), at: Date.now(), ops: [{ op: 'wipe' }] });\n await tx.done;\n notifyOutboxCommit();\n }\n\n // -----------------------------------------------------------------------\n // Sync seams (Turso backup engine only — not part of IStorage).\n // -----------------------------------------------------------------------\n\n /** Pending committed transaction groups, in commit order. */\n async readOutbox(afterSeq: number, limit: number): Promise<{ seq: number; id: string; at: number; ops: SyncMutation[] }[]> {\n const db = await this.open();\n const range = IDBKeyRange.lowerBound(afterSeq, true);\n // IDB counts are unsigned long — clamp callers' \"unbounded\" shorthand.\n return (await db.getAll(OUTBOX_STORE, range, Math.min(limit, 0xffffffff))) as { seq: number; id: string; at: number; ops: SyncMutation[] }[];\n }\n\n /** Drop acknowledged groups. Callers pass only the contiguous acked\n * watermark — a failed upload never truncates pending writes. */\n async ackOutbox(upToSeq: number): Promise<void> {\n const db = await this.open();\n const keys = await db.getAllKeys(OUTBOX_STORE, IDBKeyRange.upperBound(upToSeq));\n const tx = db.transaction(OUTBOX_STORE, 'readwrite');\n await Promise.all(keys.map(key => tx.store.delete(key)));\n await tx.done;\n }\n\n async getSyncState<T>(key: string): Promise<T | undefined> {\n const row = (await (await this.open()).get(SYNC_STATE_STORE, key)) as { value: T } | undefined;\n return row?.value;\n }\n\n async setSyncState(key: string, value: unknown): Promise<void> {\n await (await this.open()).put(SYNC_STATE_STORE, { key, value });\n }\n\n /**\n * Freeze ONE durable bootstrap run for `key` (per backup target): a\n * policy-compliant snapshot of the current rows, chunked into ≤500-op /\n * ≤~1MB entries with a unique run UUID and stable chunk ids, persisted in\n * `sync_state[key]` in the SAME readwrite transaction that reads the data\n * — so a retry returns the byte-identical frozen entries (idempotent\n * remote replays), and a crash before the commit freezes nothing. No\n * network happens here.\n *\n * Pending outbox groups are read INSIDE the same transaction: their\n * touched keys/stores are excluded from the snapshot so the journal (which\n * ships after the bootstrap, in commit order) stays the last writer and\n * nothing ships twice. A pending wipe freezes an empty run — the journal\n * wipe itself still ships and decides the remote's end state.\n *\n * The engine deletes the frozen run (`db.delete('sync_state', key)`) only\n * after the remote commit; until then every retry replays these entries.\n */\n async captureSyncBootstrap(key: string): Promise<SyncEntry[]> {\n const db = await this.open();\n const tx = db.transaction([...NON_SYSTEM_STORES, OUTBOX_STORE, SYNC_STATE_STORE], 'readwrite');\n const state = tx.objectStore(SYNC_STATE_STORE);\n const frozen = await state.get(key) as { value?: SyncEntry[] } | undefined;\n if (frozen !== undefined && Array.isArray(frozen.value)) {\n await tx.done;\n return frozen.value;\n }\n const pendingKeys = new Set<string>();\n const clearedStores = new Set<string>();\n let wiped = false;\n for (const group of await tx.objectStore(OUTBOX_STORE).getAll() as { ops: SyncMutation[] }[]) {\n for (const op of group.ops) {\n if (op.op === 'put' || op.op === 'delete') pendingKeys.add(`${op.store}:${JSON.stringify(op.key)}`);\n else if (op.op === 'clear') clearedStores.add(op.store);\n else wiped = true;\n }\n }\n const run = crypto.randomUUID();\n const entries: SyncEntry[] = [];\n if (!wiped) {\n let ops: SyncMutation[] = [];\n let bytes = 0;\n const flush = (): void => {\n if (ops.length === 0) return;\n entries.push({ id: `bootstrap:${run}:${entries.length}`, at: Date.now(), ops });\n ops = [];\n bytes = 0;\n };\n for (const op of await policySnapshotOps(store => tx.objectStore(store).getAll() as Promise<unknown[]>)) {\n if (clearedStores.has(op.store)) continue;\n // Immutable history is NEVER excluded: a snapshotted note/session\n // may pin a revision still pending in the journal, and the snapshot\n // ships first — the pinned revision must already be on the remote.\n // Revision-first op ordering keeps every chunk self-contained.\n if (op.store !== 'block_revisions' && pendingKeys.has(`${op.store}:${JSON.stringify(op.key)}`)) continue;\n const size = mutationBytes(op);\n if (ops.length > 0 && (ops.length >= BOOTSTRAP_MAX_OPS || bytes + size > BOOTSTRAP_MAX_BYTES)) flush();\n ops.push(op);\n bytes += size;\n }\n flush();\n }\n // Frozen BEFORE any network I/O — same transaction as the snapshot read.\n await state.put({ key, value: entries });\n await tx.done;\n return entries;\n }\n\n /**\n * Validate every stored pin (note blocks + session pins against\n * block_revisions) in ONE consistent readonly read — the post-restore\n * gate: a replayed backup with missing history fails loudly here instead\n * of surfacing later as broken sessions.\n */\n async validateSyncState(): Promise<void> {\n const db = await this.open();\n const tx = db.transaction(['notes', 'sessions', 'block_revisions'], 'readonly');\n const notes = await tx.objectStore('notes').getAll() as Note[];\n const sessions = await tx.objectStore('sessions').getAll() as Session[];\n const revisions = tx.objectStore('block_revisions');\n await validateStoredPins(\n notes,\n sessions,\n keys => Promise.all(keys.map(key => revisions.get(key))) as Promise<(BlockRevision | undefined)[]>,\n );\n await tx.done;\n }\n\n /**\n * Apply remotely committed mutations locally (pull/replay) WITHOUT\n * journaling — a pulled mutation must never re-enter the outbox. Runs in\n * one native transaction together with the cursor update.\n *\n * Unsent-edit overlay: pending outbox groups (committed local writes not\n * yet acknowledged remotely) are read INSIDE the same transaction and\n * replayed after the remote rows — a local edit/delete/clear/wipe that\n * committed while the pull was on the network stays the visible state;\n * the remote row is backed up locally, not clobbered over the user.\n *\n * Conflict policy (deterministic, history-preserving):\n * - notes: an incoming row with a LOWER sourceRevision than the existing\n * row is stale — skipped, never clobbers newer history.\n * - block_revisions: same key with different contents keeps BOTH rows —\n * the incoming version is re-keyed to the next free version for that\n * block. Immutable history is never silently replaced.\n * - memberships (system): remote mutations are skipped — identity truth\n * stays local and snapshot/upload never include them.\n *\n * Returns committed-boundary counts of canonical consumer records (notes +\n * efforts only; internal/journal rows never reach the sync toast).\n * `cursorKey` keeps cursors per backup target.\n */\n async applySyncMutations(\n mutations: SyncMutation[],\n cursorRev: number | null,\n cursorKey = 'cursor',\n ): Promise<{ added: number; updated: number }> {\n const defsByName = new Map<string, (typeof STORE_DEFS)[number]>(STORE_DEFS.map(def => [def.name, def]));\n for (const mutation of mutations) {\n if (mutation.op === 'clear' || mutation.op === 'wipe') continue;\n const def = defsByName.get(mutation.store);\n if (!def) throw new Error(`unknown store in sync mutation: ${String(mutation.store)}`);\n if (mutation.op === 'put' || mutation.op === 'delete') {\n const parts = Array.isArray(mutation.key) ? mutation.key : [mutation.key];\n if (parts.length !== def.keyPath.length || !parts.every(part => typeof part === 'string' || typeof part === 'number')) {\n throw new Error(`sync ${mutation.op} key arity/shape mismatch for ${mutation.store}`);\n }\n }\n if (mutation.op === 'put') validateStorageRow(mutation.store, mutation.value);\n }\n const db = await this.open();\n const names = NON_SYSTEM_STORES as StoreName[];\n const tx = db.transaction([...names, OUTBOX_STORE, SYNC_STATE_STORE], 'readwrite');\n\n // Counting baseline: every canonical key this batch touches, read before\n // any write lands.\n const canonical = (store: StoreName): store is 'notes' | 'efforts' => store === 'notes' || store === 'efforts';\n const touched = new Map<string, { store: 'notes' | 'efforts'; key: IDBValidKey; before: unknown; beforeExists: boolean }>();\n for (const mutation of mutations) {\n if (mutation.op === 'clear' || mutation.op === 'wipe') continue;\n if (!canonical(mutation.store)) continue;\n const id = `${mutation.store}:${JSON.stringify(mutation.key)}`;\n if (touched.has(id)) continue;\n const key = mutation.key as IDBValidKey;\n const before = await tx.objectStore(mutation.store).get(key);\n touched.set(id, { store: mutation.store, key, before, beforeExists: before !== undefined });\n }\n\n const applyOne = async (mutation: SyncMutation, preferLocal: boolean): Promise<void> => {\n if (mutation.op === 'wipe') {\n for (const name of names) await tx.objectStore(name).clear();\n return;\n }\n if (mutation.store === 'memberships') return; // system store: never applied remotely\n if (mutation.op === 'clear') {\n if (mutation.store === 'block_revisions') return;\n const store = tx.objectStore(mutation.store);\n const ctx = collectUserScopeContext(await tx.objectStore('notes').getAll());\n for (const row of await store.getAll()) {\n if (!isUserOwnedRow(mutation.store, row, ctx)) continue;\n const key = keyFromValue(defsByName.get(mutation.store)!, row);\n if (mutation.store === 'meta' && typeof key === 'string' && key.startsWith(USER_DELETED_SEED_PREFIX)) continue;\n await applyOne({ op: 'delete', store: mutation.store, key }, preferLocal);\n }\n return;\n }\n if (mutation.op === 'delete') {\n if (mutation.store === 'notes') {\n const noteId = String(Array.isArray(mutation.key) ? mutation.key[0] : mutation.key);\n for (const name of ['block_index', 'block_efforts', 'block_equipment'] as const) {\n const store = tx.objectStore(name);\n for (const id of await store.index('by-note').getAllKeys(noteId)) await store.delete(id);\n }\n }\n if (mutation.store !== 'block_revisions') await tx.objectStore(mutation.store).delete(mutation.key as IDBValidKey);\n return;\n }\n // put\n const store = tx.objectStore(mutation.store);\n if (mutation.store === 'block_revisions') {\n const existing = await store.get(mutation.key as IDBValidKey);\n if (existing !== undefined && !rowsEqual(existing, mutation.value) && !preferLocal) {\n // Immutable-history collision: preserve BOTH as versioned records —\n // the incoming row moves to the next free version for that block.\n // Both rows passed validateStorageRow when written (the incoming row\n // just above; the existing row at its original commit), so the\n // revision shape is guaranteed here.\n const incoming = mutation.value as BlockRevision;\n const existingRow = existing as BlockRevision;\n let version = existingRow.version + 1;\n while (await store.get([incoming.noteId, incoming.blockId, version] as IDBValidKey) !== undefined) version += 1;\n await store.put({ ...incoming, version });\n return;\n }\n if (existing === undefined || !rowsEqual(existing, mutation.value)) await store.put(mutation.value);\n return;\n }\n if (mutation.store === 'notes' && !preferLocal) {\n const existing = await store.get(mutation.key as IDBValidKey);\n // Same validateStorageRow guarantee as above: rows in the store carry\n // the note shape, so comparing source revisions is safe.\n if (existing !== undefined) {\n const existingNote = existing as Note;\n const incomingNote = mutation.value as Note;\n if (existingNote.sourceRevision > incomingNote.sourceRevision) return; // stale remote write\n }\n }\n await store.put(mutation.value);\n };\n\n for (const mutation of mutations) await applyOne(mutation, false);\n\n // Unsent-edit overlay: replay pending outbox groups in commit order so\n // the user's latest local writes remain the visible latest state.\n const pending = ((await tx.objectStore(OUTBOX_STORE).getAll()) as { seq: number; ops: SyncMutation[] }[])\n .sort((a, b) => a.seq - b.seq);\n for (const group of pending) {\n for (const op of group.ops) await applyOne(op, true);\n }\n\n // Committed-boundary counts: canonical notes/efforts whose final visible\n // value is new or changed relative to the pre-pull baseline.\n let added = 0;\n let updated = 0;\n for (const entry of touched.values()) {\n const final = await tx.objectStore(entry.store).get(entry.key);\n if (final === undefined) continue; // deleted by the batch — not an add/update\n if (!entry.beforeExists) added += 1;\n else if (!rowsEqual(entry.before, final)) updated += 1;\n }\n\n if (cursorRev !== null) await tx.objectStore(SYNC_STATE_STORE).put({ key: cursorKey, value: { rev: cursorRev } });\n await tx.done;\n return { added, updated };\n }\n\n /**\n * Consistent atomic snapshot, policy-compliant (shared user policy): only\n * user-scope rows of the non-system stores, read in ONE readonly\n * transaction — the backup never mixes the pre/post state of a concurrent\n * local commit. System stores (memberships) are excluded: they never sync.\n * Use `snapshotAllRows` for the lossless (unfiltered) form.\n */\n async snapshotRows(): Promise<{ store: StoreName; rows: unknown[] }[]> {\n const db = await this.open();\n const defs = STORE_DEFS.filter(def => !def.system);\n const tx = db.transaction(defs.map(def => def.name), 'readonly');\n // Ownership context comes from the SAME snapshot transaction — reading\n // notes before opening it could diverge from a concurrent note write.\n const ctx = collectUserScopeContext(await tx.objectStore('notes').getAll() as unknown[]);\n const out = await Promise.all(\n defs.map(async def => ({\n store: def.name,\n rows: ((await tx.objectStore(def.name).getAll() as unknown[])).filter(row => isUserOwnedRow(def.name, row, ctx)),\n })),\n );\n await tx.done;\n return out;\n }\n\n /** Lossless snapshot of every NON-SYSTEM store (meta included) in one\n * readonly transaction — local export / restore emptiness checks. A\n * freshly initialized database may hold a default membership, so the\n * system store is excluded from both uses. */\n async snapshotAllRows(): Promise<{ store: StoreName; rows: unknown[] }[]> {\n const db = await this.open();\n const defs = STORE_DEFS.filter(def => !def.system);\n const tx = db.transaction(defs.map(def => def.name), 'readonly');\n const out = await Promise.all(\n defs.map(async def => ({ store: def.name, rows: await tx.objectStore(def.name).getAll() as unknown[] })),\n );\n await tx.done;\n return out;\n }\n\n async close(): Promise<void> {\n const opening = this.opening;\n this.opening = undefined;\n (await opening?.catch(() => undefined))?.close();\n }\n}\n\n// ---------------------------------------------------------------------------\n// Cross-schema conversion — the exact IndexedDB upgrade chain on a scratch\n// database. Reads the source WITHOUT writing it; used by the CLI to migrate\n// older remotes into fresh v32 targets (trusted runtimes load\n// fake-indexeddb as the browser adapter first).\n// ---------------------------------------------------------------------------\n\ntype ScratchOp =\n | { kind: 'put'; table: string; row: unknown }\n | { kind: 'delete'; table: string; key: IDBValidKey }\n | { kind: 'clear'; table: string };\n\n/** Scratch layout: current stores plus the pre-V26 legacy tables. */\nconst SCRATCH_TABLES: readonly { name: string; keyPath: string[] }[] = [\n ...STORE_DEFS.map(def => ({ name: def.name, keyPath: def.keyPath })),\n ...LEGACY_EXTRA_TABLES.map(table => ({ name: table.name, keyPath: Array.isArray(table.keyPath) ? table.keyPath : [table.keyPath] })),\n];\n\nconst SCRATCH_TABLE_BY_NAME: Record<string, string[]> = Object.fromEntries(\n SCRATCH_TABLES.map(table => [table.name, table.keyPath]),\n);\n\nfunction assertKnownStore(store: string): void {\n if (!SCRATCH_TABLE_BY_NAME[store]) throw new Error(`unknown store \"${store}\" in source op log; copy aborted`);\n}\n\n/** Derive a row's key from its keyPath fields — malformed rows fail. */\nfunction rowKey(table: string, row: Record<string, unknown>): IDBValidKey {\n const parts: IDBValidKey[] = [];\n for (const part of SCRATCH_TABLE_BY_NAME[table]) {\n const value = row[part];\n if (typeof value !== 'string' && typeof value !== 'number' && !(value instanceof Date)) {\n throw new Error(`row for store \"${table}\" is missing keyPath field \"${part}\"; copy aborted`);\n }\n parts.push(value);\n }\n return parts.length === 1 ? parts[0] : parts;\n}\n\n/** Narrow a raw (unvalidated) op key to what IndexedDB accepts. */\nfunction isIdbKey(value: unknown): value is IDBValidKey {\n return typeof value === 'string' || typeof value === 'number' || value instanceof Date\n || (Array.isArray(value) && value.length > 0 && value.every(isIdbKey));\n}\n\nfunction arrayBuffersEqual(a: ArrayBuffer, b: ArrayBuffer): boolean {\n if (a.byteLength !== b.byteLength) return false;\n const left = new Uint8Array(a);\n const right = new Uint8Array(b);\n return left.every((byte, i) => byte === right[i]);\n}\n\nfunction deleteIdbDatabase(name: string): Promise<void> {\n const idb = globalThis.indexedDB;\n if (!idb) return Promise.resolve();\n return new Promise<void>((resolve, reject) => {\n const request = idb.deleteDatabase(name);\n request.onsuccess = () => { resolve(); };\n request.onerror = () => { reject(request.error ?? new Error(`failed to delete ${name}`)); };\n // A still-open connection blocks deletion; the scratch rows are\n // disposable either way, so don't hang the conversion on it.\n request.onblocked = () => { resolve(); };\n });\n}\n\n/** Replay raw remote-era rows into a unique scratch IndexedDB created at the\n * SOURCE schema version (generic keyPath-only stores + legacy tables), so\n * opening it through IndexedDBStorage runs the same versioned chain the\n * browser runs locally. */\nasync function buildScratch(name: string, version: number, ops: ScratchOp[]): Promise<void> {\n const db = await openDB(name, version, {\n upgrade(scratch) {\n for (const table of SCRATCH_TABLES) {\n if (!scratch.objectStoreNames.contains(table.name)) {\n scratch.createObjectStore(table.name, { keyPath: table.keyPath.length === 1 ? table.keyPath[0] : table.keyPath });\n }\n }\n },\n });\n try {\n for (const op of ops) {\n if (!db.objectStoreNames.contains(op.table)) {\n throw new Error(`unknown store \"${op.table}\" in source; copy aborted`);\n }\n if (op.kind === 'put') await db.transaction(op.table, 'readwrite').objectStore(op.table).put(op.row);\n else if (op.kind === 'delete') await db.transaction(op.table, 'readwrite').objectStore(op.table).delete(op.key);\n else await db.transaction(op.table, 'readwrite').objectStore(op.table).clear();\n }\n } finally {\n db.close();\n }\n}\n\n/** Attachment rows are the binary payload. The terminal source map replays\n * the lifted ops in order (puts, deletes, clears — wipes already expanded\n * to clears), so deleted/wiped attachments are NOT required to survive;\n * surviving ones must match the converted rows byte-for-byte (zero-byte\n * buffers are valid). */\nasync function assertBinaryPreserved(sourceOps: ScratchOp[], converted: IndexedDBStorage): Promise<void> {\n const source = new Map<string, Record<string, unknown>>();\n for (const op of sourceOps) {\n if (op.kind === 'clear') {\n if (op.table === 'attachments') source.clear();\n } else if (op.kind === 'put' && op.table === 'attachments') {\n if (op.row === null || typeof op.row !== 'object' || Array.isArray(op.row) || !('id' in op.row)) {\n throw new Error('malformed attachment row in source; copy aborted');\n }\n source.set(String((op.row as Record<string, unknown>).id), op.row as Record<string, unknown>);\n } else if (op.kind === 'delete' && op.table === 'attachments') {\n source.delete(String(op.key));\n }\n }\n if (source.size === 0) return;\n const rows = await converted.readonly('attachments').getAll();\n const byId = new Map(rows.map(row => [row.id, row]));\n for (const [id, row] of source) {\n const restored = byId.get(id);\n if (!restored) throw new Error(`attachment ${id} missing after conversion; copy aborted, source untouched`);\n const before = row.data;\n const after = restored.data;\n if (typeof before === 'string' || typeof after === 'string') {\n if (before !== after) throw new Error(`attachment ${id} payload changed during conversion; copy aborted, source untouched`);\n } else if (!(before instanceof ArrayBuffer) || !(after instanceof ArrayBuffer) || !arrayBuffersEqual(before, after)) {\n throw new Error(`attachment ${id} payload changed during conversion; copy aborted, source untouched`);\n }\n }\n}\n\n/**\n * Convert an older backup into policy-compliant current-schema mutations\n * WITHOUT touching the source:\n *\n * 1. Lift the source data as ordered scratch ops (op-log replay in log\n * order, or legacy direct-Turso per-store rows incl. segments/results).\n * 2. Replay them into a unique scratch IndexedDB created AT `fromVersion`,\n * then open it through IndexedDBStorage — the same versioned migration\n * chain the browser runs locally rebuilds segments-era rows into\n * note-owned blocks, revisions, sessions and events.\n * 3. Validate strictly (all note/session pins, binary payloads, derivable\n * keys — any miss fails the copy) and return policy-compliant PUTS ONLY\n * (the caller applies them to a fresh, reserved target).\n */\nexport async function convertSyncSource(db: Database, fromVersion: number, legacy: boolean): Promise<SyncMutation[]> {\n if (!Number.isSafeInteger(fromVersion) || fromVersion < 20) {\n throw new Error(\n `Backup database schema v${fromVersion} predates the supported migration chain (v20+); the source was left untouched. `\n + 'Restore it with an intermediate app version, or point this app at a fresh backup database.',\n );\n }\n if (fromVersion > DB_VERSION) {\n throw new Error(`Backup database schema is newer than this converter supports (v${fromVersion} > v${DB_VERSION}); refusing to downgrade.`);\n }\n const raw: ScratchOp[] = [];\n if (legacy) {\n for (const table of [...NON_SYSTEM_STORES, ...LEGACY_EXTRA_TABLES.map(table => table.name)]) {\n for (const row of await readLegacyRows(db, table)) raw.push({ kind: 'put', table, row });\n }\n } else {\n // Raw replay with STRICT lift-time validation (§3.5): unknown stores,\n // unknown ops, malformed payloads and put keys that disagree with the\n // row's own keyPath fields fail the copy before anything is replayed.\n for (const op of await readRawSyncOps(db)) {\n if (op.op === 'wipe') {\n for (const name of [...NON_SYSTEM_STORES, ...LEGACY_EXTRA_TABLES.map(table => table.name)]) {\n raw.push({ kind: 'clear', table: name });\n }\n } else if (op.op === 'clear') {\n assertKnownStore(op.store);\n raw.push({ kind: 'clear', table: op.store });\n } else if (op.op === 'put') {\n assertKnownStore(op.store);\n if (op.value === undefined || op.value === null || typeof op.value !== 'object' || Array.isArray(op.value)) {\n throw new Error(`malformed put payload for store \"${op.store}\" in source op log; copy aborted`);\n }\n if (JSON.stringify(rowKey(op.store, op.value as Record<string, unknown>)) !== JSON.stringify(op.key)) {\n throw new Error(`put key ${JSON.stringify(op.key)} does not match store \"${op.store}\" keyPath fields; copy aborted`);\n }\n raw.push({ kind: 'put', table: op.store, row: op.value });\n } else if (op.op === 'delete') {\n assertKnownStore(op.store);\n if (!isIdbKey(op.key)) {\n throw new Error(`malformed delete key for store \"${op.store}\" in source op log; copy aborted`);\n }\n raw.push({ kind: 'delete', table: op.store, key: op.key });\n } else {\n throw new Error(`unknown op \"${String((op as { op?: unknown }).op)}\" in source op log; copy aborted`);\n }\n }\n }\n const scratch = `wodwiki-convert-${crypto.randomUUID()}`;\n const converted = new IndexedDBStorage({ dbName: scratch });\n try {\n await buildScratch(scratch, fromVersion, raw);\n await converted.open();\n await converted.validateSyncState(); // strict: missing pinned revisions fail the copy\n await assertBinaryPreserved(raw, converted);\n return await policySnapshotOps(store => converted.readonly(store).getAll() as Promise<unknown[]>);\n } finally {\n await converted.close();\n await deleteIdbDatabase(scratch).catch(() => undefined);\n }\n}\n\n// ---------------------------------------------------------------------------\n// Schema creation + versioned data migration (V20 → V32).\n// ---------------------------------------------------------------------------\n\nfunction createMissingStores(db: IDBPDatabase, tx: IDBPTransaction<unknown, string, 'versionchange'>): void {\n for (const def of STORE_DEFS) {\n if (db.objectStoreNames.contains(def.name)) {\n // Existing stores (pre-DB_VERSION layouts) keep whatever index set\n // they were born with — backfill indexes the current schema needs.\n const existing = tx.objectStore(def.name);\n for (const index of def.indexes) {\n if (!existing.indexNames.contains(index.name)) existing.createIndex(index.name, index.keyPath.length === 1 ? index.keyPath[0] : index.keyPath, { unique: index.unique, multiEntry: index.multiEntry });\n }\n continue;\n }\n const store = db.createObjectStore(def.name, { keyPath: def.keyPath.length === 1 ? def.keyPath[0] : def.keyPath });\n for (const index of def.indexes) store.createIndex(index.name, index.keyPath.length === 1 ? index.keyPath[0] : index.keyPath, { unique: index.unique, multiEntry: index.multiEntry });\n }\n for (const local of LOCAL_SYNC_STORES) {\n if (db.objectStoreNames.contains(local.name)) continue;\n db.createObjectStore(local.name, { keyPath: local.keyPath, autoIncrement: 'autoIncrement' in local ? local.autoIncrement : false });\n }\n}\n\nasync function migrateSchema(db: IDBPDatabase, oldVersion: number, tx: IDBPTransaction<unknown, string, 'versionchange'>): Promise<void> {\n const store = (name: string) => tx.objectStore(name);\n\n // V20 → V21: flatten sessions, drop data.logs, project legacy logs\n // idempotently into event rows.\n if (oldVersion === 20 && db.objectStoreNames.contains('sessions')) {\n const sessionsStore = store('sessions');\n const eventsStore = store('events');\n for await (const cursor of sessionsStore) {\n const legacy = cursor.value as LegacySession;\n const logs = legacy.data?.logs ?? [];\n let alreadyProjected = false;\n for await (const _ev of eventsStore.index('by-result-grain').iterate(IDBKeyRange.bound([legacy.id, ''], [legacy.id, []]))) {\n alreadyProjected = true;\n break;\n }\n if (!alreadyProjected && logs.length > 0) {\n const identity = {\n noteId: legacy.noteId, resultId: legacy.id, segmentId: legacy.segmentId,\n segmentVersion: legacy.segmentVersion, blockContentId: legacy.blockContentId,\n origin: legacy.origin, pageId: legacy.pageId,\n workoutTimestamp: legacy.data?.endTime ?? legacy.createdAt,\n };\n for (const row of toEventRows(logs as never, identity)) await eventsStore.put(row);\n for (const row of toSummaryEventRows(logs as never, identity)) await eventsStore.put(row);\n }\n const flat: Session = {\n ...legacy,\n startTime: legacy.data?.startTime ?? legacy.createdAt,\n endTime: legacy.data?.endTime ?? legacy.createdAt,\n duration: legacy.data?.duration ?? 0,\n completed: legacy.data?.completed ?? true,\n roundsCompleted: legacy.data?.roundsCompleted,\n totalRounds: legacy.data?.totalRounds,\n repsCompleted: legacy.data?.repsCompleted,\n };\n delete (flat as unknown as Record<string, unknown>).data;\n await cursor.update(flat);\n }\n }\n\n // V21 → V22: invalidate the pre-V22 seed checkpoint so the V22 seed\n // data re-applies cleanly.\n if (oldVersion === 21 && db.objectStoreNames.contains('meta')) {\n await store('meta').delete('seed');\n }\n\n // V25: memberships store + by-user ownership index on every user-owned\n // store. Presence-guarded: mixed-state databases exist in the wild.\n if (oldVersion < 25) {\n for (const name of USER_OWNED_STORES) {\n if (!db.objectStoreNames.contains(name)) continue;\n const s = store(name);\n if (!s.indexNames.contains('by-user')) s.createIndex('by-user', 'userId');\n }\n }\n\n // V26: results → sessions. Residual legacy rows are read BEFORE the store\n // disappears; inline logs are projected per deterministic id (existing\n // rows never overwritten, absent detail/summary rows added). The legacy\n // duplicate is discarded only after the canonical row is safe.\n if (db.objectStoreNames.contains('results')) {\n const sessionsStore = store('sessions');\n const resultsStore = store('results');\n const eventsStore = store('events');\n for await (const cursor of resultsStore) {\n const { data: legacyData, ...legacyRow } = cursor.value as LegacySession;\n const logs = legacyData?.logs ?? [];\n if (logs.length > 0) {\n const identity = {\n noteId: legacyRow.noteId, resultId: legacyRow.id, segmentId: legacyRow.segmentId,\n segmentVersion: legacyRow.segmentVersion, blockContentId: legacyRow.blockContentId,\n origin: legacyRow.origin, pageId: legacyRow.pageId,\n workoutTimestamp: legacyData?.endTime ?? legacyRow.createdAt,\n };\n for (const row of toEventRows(logs as never, identity)) {\n if ((await eventsStore.get(row.id)) === undefined) await eventsStore.put(row);\n }\n for (const row of toSummaryEventRows(logs as never, identity)) {\n if ((await eventsStore.get(row.id)) === undefined) await eventsStore.put(row);\n }\n }\n if ((await sessionsStore.getKey(legacyRow.id)) !== undefined) continue;\n await sessionsStore.put({\n ...legacyRow,\n startTime: legacyData?.startTime ?? legacyRow.startTime ?? legacyRow.createdAt,\n endTime: legacyData?.endTime ?? legacyRow.endTime ?? legacyRow.createdAt,\n duration: legacyData?.duration ?? legacyRow.duration ?? 0,\n completed: legacyData?.completed ?? legacyRow.completed ?? true,\n roundsCompleted: legacyData?.roundsCompleted ?? legacyRow.roundsCompleted,\n totalRounds: legacyData?.totalRounds ?? legacyRow.totalRounds,\n repsCompleted: legacyData?.repsCompleted ?? legacyRow.repsCompleted,\n });\n }\n db.deleteObjectStore('results');\n }\n\n // V26/V27 repairs (presence-guarded — the first V26 cut shipped without\n // these on real databases, so version 26 is ambiguous).\n if (db.objectStoreNames.contains('block_index') && !store('block_index').indexNames.contains('by-source')) {\n store('block_index').createIndex('by-source', 'sourceId');\n }\n if (db.objectStoreNames.contains('notes') && !store('notes').indexNames.contains('by-created')) {\n store('notes').createIndex('by-created', 'createdAt');\n }\n if (db.objectStoreNames.contains('efforts') && !store('efforts').indexNames.contains('by-source')) {\n store('efforts').createIndex('by-source', 'registrySource');\n }\n if (db.objectStoreNames.contains('note_tags') && !store('note_tags').indexNames.contains('by-note-tag')) {\n const noteTags = store('note_tags');\n // Unique pair index requires deterministic duplicate cleanup first —\n // duplicate links keep the lexicographically smallest row id.\n const winnerByPair = new Map<string, string>();\n const dupes: string[] = [];\n for await (const cursor of noteTags) {\n const row = cursor.value as { id: string; noteId: string; tagId: string };\n const pair = `${row.noteId}${row.tagId}`;\n const winner = winnerByPair.get(pair);\n if (winner === undefined || row.id < winner) {\n winnerByPair.set(pair, row.id);\n if (winner !== undefined) dupes.push(winner);\n } else {\n dupes.push(row.id);\n }\n }\n for (const id of dupes) await noteTags.delete(id);\n noteTags.createIndex('by-note-tag', ['noteId', 'tagId'], { unique: true });\n }\n\n // V28: dashboard typing repair — a note whose frontmatter segment says\n // `dashboard: true` gains type 'dashboard' / sourceId 'dashboards'.\n // Runs BEFORE the V29 pass consumes the segments store. Idempotent.\n if (db.objectStoreNames.contains('notes') && db.objectStoreNames.contains('segments')) {\n const segments = store('segments');\n const notes = store('notes');\n const repaired = new Set<string>();\n for await (const cursor of segments) {\n const segment = cursor.value as LegacySegment;\n if (segment.dataType !== 'frontmatter' || repaired.has(segment.noteId)) continue;\n if (!/(^|\\n)dashboard:\\s*[\"']?true[\"']?\\s*(\\n|$)/.test(segment.rawContent)) continue;\n repaired.add(segment.noteId);\n const note = await notes.get(segment.noteId);\n if (!note || (note.type === 'dashboard' && note.sourceId === 'dashboards')) continue;\n await notes.put({ ...note, type: 'dashboard', sourceId: note.sourceId ?? 'dashboards' });\n }\n }\n\n // V29: segments → note-owned blocks + block_revisions; sessions/events\n // segment fields → block fields; block_index rows remapped. The segments\n // store is dropped only after every note is rebuilt — the source of truth\n // survives until the migration transaction commits.\n if (db.objectStoreNames.contains('segments')) {\n await migrateSegmentsToBlocks(db, tx);\n }\n\n // V32: pending puts already exist in the terminal snapshot. Keep deletion\n // intent before that snapshot, with legacy wipes narrowed to user clears.\n // One group keeps history and its consumers together during replay.\n if (oldVersion >= 30 && oldVersion < 32 && db.objectStoreNames.contains(OUTBOX_STORE)) {\n const outbox = store(OUTBOX_STORE);\n const ops: SyncMutation[] = [];\n for (const group of await outbox.getAll() as { ops: SyncMutation[] }[]) {\n for (const mutation of group.ops) {\n if (mutation.op === 'wipe') {\n for (const name of NON_SYSTEM_STORES) {\n if (name !== 'block_revisions') ops.push({ op: 'clear', store: name });\n }\n } else if (mutation.op !== 'put' && mutation.store !== 'memberships' && mutation.store !== 'block_revisions') {\n ops.push(mutation);\n }\n }\n }\n ops.push(...await policySnapshotOps(name => store(name).getAll() as Promise<unknown[]>));\n await outbox.clear();\n if (ops.length > 0) await outbox.put({ id: crypto.randomUUID(), at: Date.now(), ops });\n if (db.objectStoreNames.contains(SYNC_STATE_STORE)) {\n const state = store(SYNC_STATE_STORE);\n for (const key of await state.getAllKeys()) {\n if (typeof key === 'string' && key.startsWith(BOOTSTRAP_RUN_PREFIX)) await state.delete(key);\n }\n }\n }\n}\n\nasync function migrateSegmentsToBlocks(db: IDBPDatabase, tx: IDBPTransaction<unknown, string, 'versionchange'>): Promise<void> {\n const store = (name: string) => tx.objectStore(name);\n const segments = (await store('segments').getAll()) as LegacySegment[];\n const notesStore = store('notes');\n const revisionsStore = store('block_revisions');\n\n // Group every versioned segment by note, then by positional segment id.\n const byNote = new Map<string, LegacySegment[]>();\n for (const segment of segments) {\n const list = byNote.get(segment.noteId);\n if (list) list.push(segment);\n else byNote.set(segment.noteId, [segment]);\n }\n\n // blockId per (noteId, segmentId) — sessions and block_index join through it.\n const blockIdBySegment = new Map<string, string>();\n const blockById = new Map<string, { noteId: string; from?: number; to?: number; version: number }>();\n\n for (const [noteId, noteSegments] of byNote) {\n const latestById = new Map<string, LegacySegment>();\n for (const segment of noteSegments) {\n const current = latestById.get(segment.id);\n if (!current || segment.version > current.version) latestById.set(segment.id, segment);\n }\n const latest = [...latestById.values()].sort((a, b) => (a.position ?? Number.MAX_SAFE_INTEGER) - (b.position ?? Number.MAX_SAFE_INTEGER) || a.id.localeCompare(b.id));\n const rawContent = latest.map(segment => segment.sourceContent ?? `${segment.rawContent}\\n`).join('');\n\n const note = await notesStore.get(noteId);\n if (!note) continue; // orphan segments without their note keep no state\n\n // Reconcile actionable blocks against the rebuilt source, preserving the\n // legacy positional segment id as the block id so session/block_index\n // references stay valid. Blocks with no legacy counterpart get a stable\n // positional id.\n const sections = parseDocumentSections(rawContent, { registeredWidgets: KNOWN_SECTION_WIDGETS });\n const actionableSections = sections.filter(section => actionableSectionKind(section) !== null);\n const legacyActionable = latest.filter(segment => segment.dataType in SEGMENT_TO_BLOCK_KIND);\n const blocks: Note['blocks'] = {};\n actionableSections.forEach((section, index) => {\n const kind = actionableSectionKind(section)!;\n const legacy = legacyActionable[index];\n let id = legacy?.id ?? `migrated-${index}`;\n while (Object.hasOwn(blocks, id)) id = `${id}-${index}`;\n const dialect = kind === 'wod' && (section.type === 'time' || section.type === 'log')\n ? { dialect: section.type, ...(section.sport ? { sport: section.sport } : {}) }\n : {};\n blocks[id] = { id, kind, version: legacy?.version ?? 1, sourceRevision: 1, from: section.from, to: section.to, ...dialect };\n if (legacy) blockIdBySegment.set(`${noteId}${legacy.id}`, id);\n blockById.set(`${noteId}${id}`, { noteId, from: section.from, to: section.to, version: blocks[id].version });\n });\n\n const legacy = note as Record<string, unknown>;\n delete legacy.segments;\n delete legacy.segmentIds;\n await notesStore.put({ ...legacy, rawContent, sourceRevision: 1, blocks });\n\n // Every versioned segment of an actionable id becomes a block revision\n // (historical segments included — the revision store is the history).\n const revisioned = new Set(legacyActionable.map(segment => segment.id));\n for (const segment of noteSegments) {\n if (!revisioned.has(segment.id)) continue;\n const dialect = legacyDialect(segment.rawContent);\n await revisionsStore.put({\n noteId, blockId: segment.id, version: segment.version, kind: 'wod',\n rawContent: segment.rawContent, savedAt: segment.createdAt, ...dialect,\n } satisfies BlockRevision);\n }\n }\n\n // Sessions: segmentId/segmentVersion (and the retired compute `version`)\n // become blockId/blockVersion. Values carry over unchanged — the V29 pass\n // above preserved legacy segment ids as block ids.\n const sessionsStore = store('sessions');\n for (const row of (await sessionsStore.getAll()) as LegacySession[]) {\n if (row.segmentId === undefined && row.segmentVersion === undefined && row.version === undefined) continue;\n const { segmentId, segmentVersion, version, ...rest } = row;\n await sessionsStore.put({\n ...rest,\n blockId: rest.blockId ?? segmentId ?? '',\n blockVersion: rest.blockVersion ?? segmentVersion ?? version ?? 1,\n } as Session);\n }\n\n // Events: same rename on the version field.\n const eventsStore = store('events');\n for (const row of await eventsStore.getAll() as Record<string, unknown>[]) {\n if (row.segmentVersion === undefined && row.segmentId === undefined) continue;\n const { segmentVersion, segmentId, ...rest } = row;\n await eventsStore.put({\n ...rest,\n ...(rest.blockId === undefined && segmentId !== undefined ? { blockId: segmentId } : {}),\n ...(rest.blockVersion === undefined && segmentVersion !== undefined ? { blockVersion: segmentVersion } : {}),\n });\n }\n\n // block_index: `${noteId}:${segmentId}:${segmentVersion}` →\n // `${noteId}:${blockId}` with the note block's offsets. Rows whose segment\n // vanished from the segments store keep their legacy id as the block id —\n // the index is a derived projection, never silently dropped.\n const blockIndex = store('block_index');\n for (const row of (await blockIndex.getAll()) as LegacyBlockIndexRow[]) {\n const mapped = blockIdBySegment.get(`${row.noteId}${row.segmentId}`) ?? row.segmentId;\n const block = blockById.get(`${row.noteId}${mapped}`);\n const next = {\n ...row,\n id: `${row.noteId}:${mapped}`,\n blockId: mapped,\n blockVersion: block?.version ?? row.segmentVersion ?? 1,\n sourceRevision: 1,\n ...(block ? { from: block.from, to: block.to } : {}),\n dataType: row.dataType === 'script' ? 'wod' : row.dataType,\n };\n delete (next as Record<string, unknown>).segmentId;\n delete (next as Record<string, unknown>).segmentVersion;\n if (next.id !== row.id) await blockIndex.delete(row.id);\n await blockIndex.put(next);\n }\n // block_efforts already carries blockId = the legacy positional segment id,\n // which the V29 pass preserved — no remap needed.\n\n db.deleteObjectStore('segments');\n}\n"]}
|