korajs 0.5.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/create-app.ts","../src/adapter-resolver.ts","../src/app-not-ready-error.ts","../src/apply-pipeline.ts","../src/build-side-effect-entry.ts","../src/audit-bridge.ts","../src/merge-aware-sync-store.ts","../src/store-queue-storage.ts","../src/store-sync-state.ts","../src/sync-query-bridge.ts","../src/sync-status-bridge.ts","../src/validate-config.ts"],"sourcesContent":["// kora — meta-package re-exporting core, store, merge, sync\n// This is the primary entry point for `import { createApp, defineSchema, t } from 'korajs'`\n\n// === createApp factory ===\nexport { createApp } from './create-app'\n\n// === App types ===\nexport type {\n\tAdapterType,\n\tAuthSyncBinding,\n\tKoraApp,\n\tKoraConfig,\n\tStoreOptions,\n\tSyncControl,\n\tSyncOptions,\n\tSequenceAccessor,\n\tTransactionCollectionProxy,\n\tTransactionProxy,\n\tTypedCollectionAccessor,\n\tTypedKoraApp,\n\tTypedKoraConfig,\n} from './types'\n\nexport type { ReplaySnapshot } from '@korajs/store'\nexport type {\n\tAuditExportManifest,\n\tAuditExportOptions,\n\tAuditExportPayload,\n\tPersistedAuditTrace,\n} from '@korajs/store'\nexport {\n\tdecodeAuditExport,\n\treadAuditExportManifest,\n\tverifyAuditExportChecksum,\n} from '@korajs/store'\n\n// === @korajs/core re-exports ===\nexport { defineSchema, migrate, t } from '@korajs/core'\nexport { HybridLogicalClock } from '@korajs/core'\nexport { generateUUIDv7 } from '@korajs/core'\nexport { createOperation } from '@korajs/core'\nexport { KoraError } from '@korajs/core'\nexport { op } from '@korajs/core'\nexport type {\n\tAtomicOp,\n\tAtomicOpType,\n\tCollectionDefinition,\n\tConnectionQuality,\n\tConstraint,\n\tFieldDescriptor,\n\tFieldKindToType,\n\tHLCTimestamp,\n\tInferFieldType,\n\tInferInsertInput,\n\tInferRecord,\n\tInferUpdateInput,\n\tKoraEvent,\n\tKoraEventEmitter,\n\tKoraEventListener,\n\tKoraEventType,\n\tMergeStrategy,\n\tMergeTrace,\n\tMigrationDefinition,\n\tMigrationStep,\n\tOperation,\n\tSchemaDefinition,\n\tSchemaInput,\n\tSequenceConfig,\n\tSyncRuleDefinition,\n\tTypedSchemaDefinition,\n\tVersionVector,\n} from '@korajs/core'\n\n// === @korajs/store re-exports ===\nexport { SequenceManager, Store } from '@korajs/store'\nexport { TransactionContext } from '@korajs/store'\nexport {\n\texportBackup,\n\treadBackupManifest,\n\trestoreBackup,\n\tverifyBackupChecksum,\n} from '@korajs/store'\nexport type {\n\tBackupManifest,\n\tBackupOptions,\n\tBackupProgress,\n\tCollectionAccessor,\n\tCollectionRecord,\n\tRestoreOptions,\n\tRestoreResult,\n\tStorageAdapter,\n\tStoreConfig,\n\tTransactionCollectionAccessor,\n\tTransactionContextConfig,\n} from '@korajs/store'\n\n// === @korajs/merge re-exports ===\nexport { MergeEngine } from '@korajs/merge'\nexport type { MergeInput, MergeResult } from '@korajs/merge'\n\n// === @korajs/sync re-exports ===\nexport { SyncEngine, WebSocketTransport } from '@korajs/sync'\nexport type {\n\tSyncConfig,\n\tSyncDiagnostics,\n\tSyncEncryptionConfig,\n\tSyncState,\n\tSyncStatus,\n\tSyncStatusInfo,\n\tSyncStore,\n} from '@korajs/sync'\n","import type { KoraEventEmitter, Operation, SchemaInput } from '@korajs/core'\nimport { buildScopeMap } from '@korajs/core'\nimport { SimpleEventEmitter } from '@korajs/core/internal'\nimport { Instrumenter } from '@korajs/devtools'\nimport { MergeEngine } from '@korajs/merge'\nimport { Store } from '@korajs/store'\nimport type {\n\tAuditExportOptions,\n\tBackupOptions,\n\tCollectionAccessor,\n\tQueryBuilder,\n\tReplaySnapshot,\n\tRestoreOptions,\n\tRestoreResult,\n\tStorageAdapter,\n} from '@korajs/store'\nimport {\n\tConnectionMonitor,\n\tHttpLongPollingTransport,\n\tReconnectionManager,\n\tSyncEncryptor,\n\tSyncEngine,\n\tWebSocketTransport,\n} from '@korajs/sync'\nimport type { SyncTransport } from '@korajs/sync'\nimport type { SyncStatusInfo } from '@korajs/sync'\nimport { createAdapter, detectAdapterType } from './adapter-resolver'\nimport { AppNotReadyError } from './app-not-ready-error'\nimport { ApplyPipeline } from './apply-pipeline'\nimport { wireAuditPersistence } from './audit-bridge'\nimport { MergeAwareSyncStore } from './merge-aware-sync-store'\nimport { StoreQueueStorage } from './store-queue-storage'\nimport { StoreSyncStatePersistence } from './store-sync-state'\nimport { createSyncQuerySubscriptionHook } from './sync-query-bridge'\nimport { createSyncStatusBridge } from './sync-status-bridge'\nimport type {\n\tAuthSyncBinding,\n\tKoraApp,\n\tKoraConfig,\n\tKoraSyncEvent,\n\tSequenceAccessor,\n\tSyncControl,\n\tTransactionProxy,\n\tTypedKoraApp,\n\tTypedKoraConfig,\n} from './types'\nimport { validateCreateAppConfig } from './validate-config'\n\n/**\n * Creates a new Kora application instance.\n *\n * Wires together store, merge engine, event emitter, and optionally sync\n * into a single developer-facing `KoraApp` object. Collection accessors\n * (e.g. `app.todos`) are defined as properties for immediate use after `await app.ready`.\n *\n * @param config - Application configuration including schema and optional sync settings\n * @returns A KoraApp instance with reactive collections ready for use\n *\n * @example\n * ```typescript\n * const app = createApp({\n * schema: defineSchema({\n * version: 1,\n * collections: {\n * todos: {\n * fields: {\n * title: t.string(),\n * completed: t.boolean().default(false)\n * }\n * }\n * }\n * })\n * })\n *\n * await app.ready\n * const todo = await app.todos.insert({ title: 'Hello' })\n * ```\n */\n/**\n * Creates a new typed Kora application instance.\n * When the schema is created with `defineSchema()`, full type inference flows through\n * to collection accessors, providing autocomplete and type checking for all CRUD operations.\n */\nexport function createApp<const S extends SchemaInput>(config: TypedKoraConfig<S>): TypedKoraApp<S>\n/**\n * Creates a new Kora application instance (untyped fallback).\n */\nexport function createApp(config: KoraConfig): KoraApp\nexport function createApp<const S extends SchemaInput>(\n\tconfig: TypedKoraConfig<S> | KoraConfig,\n): TypedKoraApp<S> | KoraApp {\n\tvalidateCreateAppConfig(config)\n\n\tconst emitter: KoraEventEmitter & { clear(): void } = new SimpleEventEmitter()\n\tconst mergeEngine = new MergeEngine()\n\n\tif (config.onSyncEvent) {\n\t\tconst handler = config.onSyncEvent\n\t\tconst syncTypes = [\n\t\t\t'sync:connected',\n\t\t\t'sync:disconnected',\n\t\t\t'sync:schema-mismatch',\n\t\t\t'sync:auth-failed',\n\t\t\t'sync:sent',\n\t\t\t'sync:received',\n\t\t\t'sync:acknowledged',\n\t\t\t'sync:apply-failed',\n\t\t\t'sync:diagnostics',\n\t\t\t'sync:bandwidth',\n\t\t\t'sync:initial-sync-progress',\n\t\t] as const\n\t\tfor (const type of syncTypes) {\n\t\t\temitter.on(type, (event) => {\n\t\t\t\thandler(event as KoraSyncEvent)\n\t\t\t})\n\t\t}\n\t}\n\n\tlet store: Store | null = null\n\tlet syncEngine: SyncEngine | null = null\n\tlet unsubscribeSync: (() => void) | null = null\n\tlet unsubscribeAudit: (() => void) | null = null\n\tlet reconnectionManager: ReconnectionManager | null = null\n\tlet connectionMonitor: ConnectionMonitor | null = null\n\tlet instrumenter: Instrumenter | null = null\n\tlet intentionalDisconnect = false\n\tlet qualityInterval: ReturnType<typeof setInterval> | null = null\n\tlet syncStatusBridge: ReturnType<typeof createSyncStatusBridge> | null = null\n\tlet destroyDevtoolsOverlay: (() => void) | null = null\n\n\t// Wire DevTools instrumentation immediately (emitter exists synchronously)\n\tif (config.devtools) {\n\t\tinstrumenter = new Instrumenter(emitter, {\n\t\t\tbridgeEnabled: typeof globalThis !== 'undefined' && 'window' in globalThis,\n\t\t})\n\t\tif (typeof globalThis !== 'undefined' && 'window' in globalThis) {\n\t\t\tvoid import('@korajs/devtools/overlay')\n\t\t\t\t.then(({ mountKoraDevtoolsOverlay }) => {\n\t\t\t\t\tif (instrumenter) {\n\t\t\t\t\t\tdestroyDevtoolsOverlay = mountKoraDevtoolsOverlay(instrumenter)\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\t.catch(() => {\n\t\t\t\t\t// Overlay is optional; extension bridge still works.\n\t\t\t\t})\n\t\t}\n\t}\n\n\t// Build the ready promise — resolves when the store is open and wired\n\tconst ready = initializeAsync(config, emitter, mergeEngine).then((result) => {\n\t\tstore = result.store\n\t\tsyncEngine = result.syncEngine\n\t\tunsubscribeSync = result.unsubscribeSync\n\t\tunsubscribeAudit = result.unsubscribeAudit\n\t\tconst authBinding = result.authBinding\n\n\t\tif (config.sync) {\n\t\t\tsyncStatusBridge = createSyncStatusBridge(emitter, () => syncEngine)\n\t\t\tsyncStatusBridge.refresh()\n\t\t}\n\n\t\tif (config.sync && syncEngine && authBinding?.subscribe) {\n\t\t\tauthBinding.subscribe(() => {\n\t\t\t\tconst engine = syncEngine\n\t\t\t\tif (!engine) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tvoid (async () => {\n\t\t\t\t\tconst headers = await authBinding.auth()\n\t\t\t\t\tif (!headers.token) {\n\t\t\t\t\t\tawait engine.stop()\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\n\t\t\t\t\tif (authBinding.resolveScopeMap) {\n\t\t\t\t\t\tconst nextScope = await authBinding.resolveScopeMap()\n\t\t\t\t\t\tengine.updateScope(nextScope)\n\t\t\t\t\t}\n\n\t\t\t\t\tconst status = engine.getStatus().status\n\t\t\t\t\tif (status !== 'offline') {\n\t\t\t\t\t\tawait engine.stop()\n\t\t\t\t\t}\n\t\t\t\t\tawait engine.start()\n\t\t\t\t})()\n\t\t\t})\n\t\t}\n\n\t\t// Wire reconnection and connection quality after sync engine is ready\n\t\tif (config.sync && syncEngine) {\n\t\t\tconnectionMonitor = new ConnectionMonitor()\n\t\t\treconnectionManager = new ReconnectionManager({\n\t\t\t\tinitialDelay: config.sync.reconnectInterval,\n\t\t\t\tmaxDelay: config.sync.maxReconnectInterval,\n\t\t\t})\n\n\t\t\t// Track activity for connection quality\n\t\t\temitter.on('sync:sent', () => connectionMonitor?.recordActivity())\n\t\t\temitter.on('sync:received', () => connectionMonitor?.recordActivity())\n\t\t\temitter.on('sync:acknowledged', () => connectionMonitor?.recordActivity())\n\n\t\t\t// Emit quality on timer while connected\n\t\t\temitter.on('sync:connected', () => {\n\t\t\t\tif (qualityInterval !== null) clearInterval(qualityInterval)\n\t\t\t\tqualityInterval = setInterval(() => {\n\t\t\t\t\tif (connectionMonitor) {\n\t\t\t\t\t\temitter.emit({ type: 'connection:quality', quality: connectionMonitor.getQuality() })\n\t\t\t\t\t}\n\t\t\t\t}, 5000)\n\t\t\t})\n\n\t\t\t// Reset monitor and clear timer on disconnect\n\t\t\temitter.on('sync:disconnected', () => {\n\t\t\t\tconnectionMonitor?.reset()\n\t\t\t\tif (qualityInterval !== null) {\n\t\t\t\t\tclearInterval(qualityInterval)\n\t\t\t\t\tqualityInterval = null\n\t\t\t\t}\n\t\t\t})\n\n\t\t\t// Reconnect immediately when the browser reports connectivity restored\n\t\t\tconst browserGlobal = globalThis as typeof globalThis & {\n\t\t\t\taddEventListener?: (type: string, listener: () => void) => void\n\t\t\t}\n\t\t\tif (typeof browserGlobal.addEventListener === 'function') {\n\t\t\t\tconst engine = syncEngine\n\t\t\t\tbrowserGlobal.addEventListener('online', () => {\n\t\t\t\t\tif (intentionalDisconnect || config.sync?.autoReconnect === false) return\n\t\t\t\t\treconnectionManager?.wake()\n\t\t\t\t\treconnectionManager?.reset()\n\t\t\t\t\tvoid engine.retryNow()\n\t\t\t\t})\n\t\t\t}\n\n\t\t\temitter.on('sync:schema-mismatch', () => {\n\t\t\t\treconnectionManager?.stop()\n\t\t\t\tintentionalDisconnect = true\n\t\t\t})\n\n\t\t\t// Auto-reconnect on unexpected disconnect\n\t\t\tif (config.sync.autoReconnect !== false) {\n\t\t\t\tconst engine = syncEngine\n\t\t\t\temitter.on('sync:disconnected', () => {\n\t\t\t\t\tif (intentionalDisconnect || engine.isSchemaBlocked()) return\n\t\t\t\t\t// Ignore cascading disconnect events from failed reconnection attempts.\n\t\t\t\t\t// The reconnection manager is already retrying — don't restart it.\n\t\t\t\t\tif (reconnectionManager?.isRunning()) return\n\n\t\t\t\t\tengine.setReconnecting(true)\n\t\t\t\t\treconnectionManager?.stop()\n\t\t\t\t\treconnectionManager\n\t\t\t\t\t\t?.start(async () => {\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tawait engine.start()\n\t\t\t\t\t\t\t\tengine.setReconnecting(false)\n\t\t\t\t\t\t\t\treturn true\n\t\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t\treturn false\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.then(() => {\n\t\t\t\t\t\t\t// If reconnection exhausted max attempts without success, clear flag\n\t\t\t\t\t\t\tengine.setReconnecting(false)\n\t\t\t\t\t\t})\n\t\t\t\t})\n\t\t\t}\n\n\t\t\tif (config.sync.autoConnect === true && syncEngine) {\n\t\t\t\tvoid syncEngine.start().catch(() => {\n\t\t\t\t\t// Errors surface via sync:disconnected / sync events; avoid unhandled rejection.\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t})\n\n\tconst offlineSyncStatus = (): SyncStatusInfo => ({\n\t\tstatus: 'offline',\n\t\tpendingOperations: 0,\n\t\tlastSyncedAt: null,\n\t\tlastSuccessfulPush: null,\n\t\tlastSuccessfulPull: null,\n\t\tconflicts: 0,\n\t})\n\n\t// Build sync control\n\tconst syncControl: SyncControl | null = config.sync\n\t\t? {\n\t\t\t\tget status(): SyncStatusInfo {\n\t\t\t\t\treturn syncStatusBridge?.status ?? offlineSyncStatus()\n\t\t\t\t},\n\t\t\t\tsubscribeStatus(listener: (status: SyncStatusInfo) => void): () => void {\n\t\t\t\t\tif (syncStatusBridge) {\n\t\t\t\t\t\treturn syncStatusBridge.subscribe(listener)\n\t\t\t\t\t}\n\t\t\t\t\tlistener(offlineSyncStatus())\n\t\t\t\t\treturn () => {}\n\t\t\t\t},\n\t\t\t\tasync connect(): Promise<void> {\n\t\t\t\t\tawait ready\n\t\t\t\t\tif (syncEngine) {\n\t\t\t\t\t\tintentionalDisconnect = false\n\t\t\t\t\t\treconnectionManager?.stop()\n\t\t\t\t\t\treconnectionManager?.reset()\n\t\t\t\t\t\tawait syncEngine.start()\n\t\t\t\t\t\tsyncStatusBridge?.refresh()\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tasync disconnect(): Promise<void> {\n\t\t\t\t\tawait ready\n\t\t\t\t\tif (syncEngine) {\n\t\t\t\t\t\tintentionalDisconnect = true\n\t\t\t\t\t\treconnectionManager?.stop()\n\t\t\t\t\t\tawait syncEngine.stop()\n\t\t\t\t\t\tsyncStatusBridge?.refresh()\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tgetStatus(): SyncStatusInfo {\n\t\t\t\t\tif (syncEngine) {\n\t\t\t\t\t\treturn syncEngine.getStatus()\n\t\t\t\t\t}\n\t\t\t\t\treturn offlineSyncStatus()\n\t\t\t\t},\n\t\t\t\tasync retryNow(): Promise<void> {\n\t\t\t\t\tawait ready\n\t\t\t\t\tif (syncEngine) {\n\t\t\t\t\t\tawait syncEngine.retryNow()\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tclearSchemaBlock(): void {\n\t\t\t\t\tsyncEngine?.clearSchemaBlock()\n\t\t\t\t},\n\t\t\t\texportDiagnostics() {\n\t\t\t\t\tif (syncEngine) {\n\t\t\t\t\t\treturn syncEngine.exportDiagnostics()\n\t\t\t\t\t}\n\t\t\t\t\treturn {\n\t\t\t\t\t\tstate: 'disconnected' as const,\n\t\t\t\t\t\tstatus: {\n\t\t\t\t\t\t\tstatus: 'offline' as const,\n\t\t\t\t\t\t\tpendingOperations: 0,\n\t\t\t\t\t\t\tlastSyncedAt: null,\n\t\t\t\t\t\t\tlastSuccessfulPush: null,\n\t\t\t\t\t\t\tlastSuccessfulPull: null,\n\t\t\t\t\t\t\tconflicts: 0,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tnodeId: '',\n\t\t\t\t\t\turl: config.sync?.url ?? '',\n\t\t\t\t\t\tschemaVersion: config.schema.version,\n\t\t\t\t\t\tlastSyncedAt: null,\n\t\t\t\t\t\tlastSuccessfulPush: null,\n\t\t\t\t\t\tlastSuccessfulPull: null,\n\t\t\t\t\t\tconflicts: 0,\n\t\t\t\t\t\tpendingOperations: 0,\n\t\t\t\t\t\thasInFlightBatch: false,\n\t\t\t\t\t\treconnecting: false,\n\t\t\t\t\t\ttimestamp: Date.now(),\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t}\n\t\t: null\n\n\t// Shared transaction executor for both transaction() and mutation()\n\tasync function executeTransaction(\n\t\tfn: (tx: TransactionProxy) => Promise<void>,\n\t\tmutationName?: string,\n\t): Promise<Operation[]> {\n\t\tawait ready\n\t\tif (!store) {\n\t\t\tthrow new Error('Store not initialized. Await app.ready before using transactions.')\n\t\t}\n\t\tconst collectionNames = Object.keys(config.schema.collections)\n\n\t\treturn store.transaction(async (tx) => {\n\t\t\tif (mutationName !== undefined) {\n\t\t\t\ttx.setMutationName(mutationName)\n\t\t\t}\n\t\t\tconst proxy: TransactionProxy = {} as TransactionProxy\n\t\t\tfor (const name of collectionNames) {\n\t\t\t\tObject.defineProperty(proxy, name, {\n\t\t\t\t\tget() {\n\t\t\t\t\t\treturn tx.collection(name)\n\t\t\t\t\t},\n\t\t\t\t\tenumerable: true,\n\t\t\t\t\tconfigurable: false,\n\t\t\t\t})\n\t\t\t}\n\t\t\tawait fn(proxy)\n\t\t})\n\t}\n\n\t// Build sequences accessor (delegates to SequenceManager after ready)\n\tconst sequences: SequenceAccessor = {\n\t\tasync next(name, config) {\n\t\t\tawait ready\n\t\t\tif (!store) throw new Error('Store not initialized. Await app.ready before using sequences.')\n\t\t\treturn store.getSequenceManager().next(name, config)\n\t\t},\n\t\tasync current(name, config) {\n\t\t\tawait ready\n\t\t\tif (!store) throw new Error('Store not initialized. Await app.ready before using sequences.')\n\t\t\treturn store.getSequenceManager().current(name, config)\n\t\t},\n\t\tasync reset(name, config) {\n\t\t\tawait ready\n\t\t\tif (!store) throw new Error('Store not initialized. Await app.ready before using sequences.')\n\t\t\treturn store.getSequenceManager().reset(name, config)\n\t\t},\n\t}\n\n\t// Build the KoraApp object\n\tconst app: KoraApp = {\n\t\tready,\n\t\tevents: emitter,\n\t\tsync: syncControl,\n\t\tsequences,\n\t\tgetStore(): Store {\n\t\t\tif (!store) {\n\t\t\t\tthrow new Error('Store not initialized. Await app.ready before accessing the store.')\n\t\t\t}\n\t\t\treturn store\n\t\t},\n\t\tgetSyncEngine(): SyncEngine | null {\n\t\t\treturn syncEngine\n\t\t},\n\t\tasync transaction(fn: (tx: TransactionProxy) => Promise<void>): Promise<Operation[]> {\n\t\t\treturn executeTransaction(fn)\n\t\t},\n\t\tasync mutation(\n\t\t\tname: string,\n\t\t\tfn: (tx: TransactionProxy) => Promise<void>,\n\t\t): Promise<Operation[]> {\n\t\t\treturn executeTransaction(fn, name)\n\t\t},\n\t\tasync close(): Promise<void> {\n\t\t\tawait ready\n\t\t\tintentionalDisconnect = true\n\t\t\tif (qualityInterval !== null) {\n\t\t\t\tclearInterval(qualityInterval)\n\t\t\t\tqualityInterval = null\n\t\t\t}\n\t\t\treconnectionManager?.stop()\n\t\t\tif (destroyDevtoolsOverlay) {\n\t\t\t\tdestroyDevtoolsOverlay()\n\t\t\t\tdestroyDevtoolsOverlay = null\n\t\t\t}\n\t\t\tif (instrumenter) {\n\t\t\t\tinstrumenter.destroy()\n\t\t\t\tinstrumenter = null\n\t\t\t}\n\t\t\tif (unsubscribeSync) {\n\t\t\t\tunsubscribeSync()\n\t\t\t\tunsubscribeSync = null\n\t\t\t}\n\t\t\tif (unsubscribeAudit) {\n\t\t\t\tunsubscribeAudit()\n\t\t\t\tunsubscribeAudit = null\n\t\t\t}\n\t\t\tif (syncEngine) {\n\t\t\t\tawait syncEngine.stop()\n\t\t\t\tsyncEngine = null\n\t\t\t}\n\t\t\tif (syncStatusBridge) {\n\t\t\t\tsyncStatusBridge.destroy()\n\t\t\t\tsyncStatusBridge = null\n\t\t\t}\n\t\t\tif (store) {\n\t\t\t\tawait store.close()\n\t\t\t\tstore = null\n\t\t\t}\n\t\t\temitter.clear()\n\t\t},\n\t\tasync exportBackup(options?: BackupOptions): Promise<Uint8Array> {\n\t\t\tawait ready\n\t\t\tif (!store) {\n\t\t\t\tthrow new Error('Store not initialized. Await app.ready before exporting backup.')\n\t\t\t}\n\t\t\treturn store.exportBackup(options)\n\t\t},\n\t\tasync importBackup(data: Uint8Array, options?: RestoreOptions): Promise<RestoreResult> {\n\t\t\tawait ready\n\t\t\tif (!store) {\n\t\t\t\tthrow new Error('Store not initialized. Await app.ready before importing backup.')\n\t\t\t}\n\t\t\treturn store.importBackup(data, options)\n\t\t},\n\t\tasync replayTo(operationId: string): Promise<ReplaySnapshot> {\n\t\t\tawait ready\n\t\t\tif (!store) {\n\t\t\t\tthrow new Error('Store not initialized. Await app.ready before replaying operations.')\n\t\t\t}\n\t\t\treturn store.replayTo(operationId)\n\t\t},\n\t\tasync exportAudit(options?: AuditExportOptions): Promise<Uint8Array> {\n\t\t\tawait ready\n\t\t\tif (!store) {\n\t\t\t\tthrow new Error('Store not initialized. Await app.ready before exporting audit data.')\n\t\t\t}\n\t\t\treturn store.exportAudit(options)\n\t\t},\n\t}\n\n\t// Define collection accessors via Object.defineProperty.\n\t// Before ready resolves, query methods return empty results.\n\tfor (const collectionName of Object.keys(config.schema.collections)) {\n\t\tObject.defineProperty(app, collectionName, {\n\t\t\tget(): CollectionAccessor {\n\t\t\t\treturn createCollectionAccessor(collectionName, () => store)\n\t\t\t},\n\t\t\tenumerable: true,\n\t\t\tconfigurable: false,\n\t\t})\n\t}\n\n\treturn app\n}\n\n/**\n * Asynchronous initialization: create adapter, open store, wire sync.\n */\nasync function initializeAsync(\n\tconfig: KoraConfig,\n\temitter: KoraEventEmitter,\n\tmergeEngine: MergeEngine,\n): Promise<{\n\tstore: Store\n\tsyncEngine: SyncEngine | null\n\tunsubscribeSync: (() => void) | null\n\tunsubscribeAudit: (() => void) | null\n\tauthBinding: AuthSyncBinding | null\n}> {\n\t// Resolve adapter\n\tconst adapterType = config.store?.adapter ?? detectAdapterType()\n\tconst dbName = config.store?.name ?? 'kora-db'\n\tconst adapter: StorageAdapter = await createAdapter(\n\t\tadapterType,\n\t\tdbName,\n\t\tconfig.store?.workerUrl,\n\t\temitter,\n\t\tconfig.store?.workerResponseTimeoutMs,\n\t\tconfig.store?.sharedWorkerUrl,\n\t)\n\n\t// Device-bound sync node id from auth token (`dev` claim), separate from user id (`sub`).\n\tconst authBinding = config.sync?.authClient\n\tconst authNodeId = authBinding?.resolveNodeId ? await authBinding.resolveNodeId() : undefined\n\n\t// Create and open the store (sync query hook uses a ref filled after SyncEngine is created)\n\tlet syncEngine: SyncEngine | null = null\n\n\tconst store = new Store({\n\t\tschema: config.schema,\n\t\tadapter,\n\t\temitter,\n\t\tdbName,\n\t\tnodeId: authNodeId,\n\t\tisolation: authNodeId ? 'shared' : config.store?.isolation,\n\t\t...(config.sync\n\t\t\t? { onQuerySubscribed: createSyncQuerySubscriptionHook(() => syncEngine) }\n\t\t\t: {}),\n\t})\n\tawait store.open()\n\n\tlet recordConflict: (() => void) | undefined\n\tconst applyPipeline = new ApplyPipeline({\n\t\tstore,\n\t\tmergeEngine,\n\t\temitter,\n\t\tonMergeConflict: () => recordConflict?.(),\n\t})\n\tstore.setLocalMutationHandler(applyPipeline)\n\tconst unsubscribeAudit = wireAuditPersistence(store, emitter)\n\n\t// Wire sync if configured\n\tlet unsubscribeSync: (() => void) | null = null\n\n\tif (config.sync) {\n\t\tconst transport = createSyncTransport(config.sync)\n\t\tconst mergeAwareStore = new MergeAwareSyncStore(store, mergeEngine, emitter, {\n\t\t\tonMergeConflict: () => recordConflict?.(),\n\t\t})\n\n\t\t// Build scope map from auth binding, flat scope values, or static config\n\t\tlet scopeMap = config.sync.scope ? buildScopeMap(config.schema, config.sync.scope) : undefined\n\t\tif (authBinding?.resolveScopeMap) {\n\t\t\tscopeMap = (await authBinding.resolveScopeMap()) ?? scopeMap\n\t\t}\n\n\t\tconst syncAuth = authBinding?.auth ?? config.sync.auth\n\n\t\tconst encryptor =\n\t\t\tconfig.sync.encryption?.enabled === true\n\t\t\t\t? await SyncEncryptor.create(config.sync.encryption)\n\t\t\t\t: undefined\n\n\t\tsyncEngine = new SyncEngine({\n\t\t\ttransport,\n\t\t\tstore: mergeAwareStore,\n\t\t\tconfig: {\n\t\t\t\turl: config.sync.url,\n\t\t\t\ttransport: config.sync.transport,\n\t\t\t\tauth: syncAuth,\n\t\t\t\tbatchSize: config.sync.batchSize,\n\t\t\t\tschemaVersion: config.sync.schemaVersion ?? config.schema.version,\n\t\t\t\tscopeMap,\n\t\t\t\tencryption: config.sync.encryption,\n\t\t\t\tstrictHandshake: config.sync.strictHandshake,\n\t\t\t\toperationTransforms: config.sync.operationTransforms,\n\t\t\t},\n\t\t\temitter,\n\t\t\tqueueStorage: new StoreQueueStorage(adapter),\n\t\t\tsyncState: new StoreSyncStatePersistence(store, scopeMap),\n\t\t\tencryptor,\n\t\t})\n\t\trecordConflict = () => syncEngine?.recordConflict()\n\n\t\t// Wire local mutations → sync outbound queue\n\t\tunsubscribeSync = emitter.on('operation:created', (event) => {\n\t\t\tif (syncEngine) {\n\t\t\t\tsyncEngine.pushOperation(event.operation)\n\t\t\t}\n\t\t})\n\t}\n\n\treturn {\n\t\tstore,\n\t\tsyncEngine,\n\t\tunsubscribeSync,\n\t\tunsubscribeAudit,\n\t\tauthBinding: config.sync?.authClient ?? null,\n\t}\n}\n\nfunction createSyncTransport(sync: NonNullable<KoraConfig['sync']>): SyncTransport {\n\tif (sync.transport === 'http') {\n\t\treturn new HttpLongPollingTransport()\n\t}\n\treturn new WebSocketTransport()\n}\n\nfunction createCollectionAccessor(\n\tcollectionName: string,\n\tgetStore: () => Store | null,\n): CollectionAccessor {\n\treturn {\n\t\tasync insert(data: Record<string, unknown>) {\n\t\t\tconst currentStore = getStore()\n\t\t\tif (!currentStore) {\n\t\t\t\tthrow new Error(`Cannot mutate collection \"${collectionName}\" before app.ready resolves.`)\n\t\t\t}\n\t\t\treturn currentStore.collection(collectionName).insert(data)\n\t\t},\n\t\tasync findById(id: string) {\n\t\t\tconst currentStore = getStore()\n\t\t\tif (!currentStore) return null\n\t\t\treturn currentStore.collection(collectionName).findById(id)\n\t\t},\n\t\tasync update(id: string, data: Record<string, unknown>) {\n\t\t\tconst currentStore = getStore()\n\t\t\tif (!currentStore) {\n\t\t\t\tthrow new Error(`Cannot mutate collection \"${collectionName}\" before app.ready resolves.`)\n\t\t\t}\n\t\t\treturn currentStore.collection(collectionName).update(id, data)\n\t\t},\n\t\tasync delete(id: string) {\n\t\t\tconst currentStore = getStore()\n\t\t\tif (!currentStore) {\n\t\t\t\tthrow new Error(`Cannot mutate collection \"${collectionName}\" before app.ready resolves.`)\n\t\t\t}\n\t\t\treturn currentStore.collection(collectionName).delete(id)\n\t\t},\n\t\twhere(conditions: Record<string, unknown>) {\n\t\t\tconst currentStore = getStore()\n\t\t\tif (!currentStore) {\n\t\t\t\treturn createPendingQueryBuilder(conditions)\n\t\t\t}\n\t\t\treturn currentStore.collection(collectionName).where(conditions)\n\t\t},\n\t}\n}\n\nfunction createPendingQueryBuilder(initialWhere: Record<string, unknown>): QueryBuilder {\n\tconst descriptor = {\n\t\tcollection: '__pending__',\n\t\twhere: { ...initialWhere },\n\t\torderBy: [] as Array<{ field: string; direction: 'asc' | 'desc' }>,\n\t\tlimit: undefined as number | undefined,\n\t\toffset: undefined as number | undefined,\n\t}\n\n\tconst builder = {\n\t\twhere(conditions: Record<string, unknown>) {\n\t\t\tdescriptor.where = { ...descriptor.where, ...conditions }\n\t\t\treturn this\n\t\t},\n\t\torderBy(field: string, direction: 'asc' | 'desc' = 'asc') {\n\t\t\tdescriptor.orderBy.push({ field, direction })\n\t\t\treturn this\n\t\t},\n\t\tlimit(n: number) {\n\t\t\tdescriptor.limit = n\n\t\t\treturn this\n\t\t},\n\t\toffset(n: number) {\n\t\t\tdescriptor.offset = n\n\t\t\treturn this\n\t\t},\n\t\tasync exec() {\n\t\t\tthrow new AppNotReadyError(\n\t\t\t\t'Cannot execute a query before app.ready. Await app.ready or use <KoraProvider app={app}>.',\n\t\t\t)\n\t\t},\n\t\tasync count() {\n\t\t\tthrow new AppNotReadyError(\n\t\t\t\t'Cannot count query results before app.ready. Await app.ready or use <KoraProvider app={app}>.',\n\t\t\t)\n\t\t},\n\t\tsubscribe(_callback: (results: Array<Record<string, unknown>>) => void) {\n\t\t\tthrow new AppNotReadyError(\n\t\t\t\t'Cannot subscribe to a query before app.ready. Await app.ready or use <KoraProvider app={app}>.',\n\t\t\t)\n\t\t},\n\t\tgetDescriptor() {\n\t\t\treturn { ...descriptor, where: { ...descriptor.where }, orderBy: [...descriptor.orderBy] }\n\t\t},\n\t}\n\n\treturn builder as unknown as QueryBuilder\n}\n","import type { KoraEventEmitter } from '@korajs/core'\nimport type { StorageAdapter } from '@korajs/store'\nimport type { AdapterType } from './types'\n\n/** Dynamic import that bundlers cannot statically analyze (optional peer packages). */\nfunction importOptionalPeer<T>(specifier: string): Promise<T> {\n\tconst dynamicImport = new Function('specifier', 'return import(specifier)') as (\n\t\ts: string,\n\t) => Promise<T>\n\treturn dynamicImport(specifier)\n}\n\n/**\n * Detect the best storage adapter for the current environment.\n *\n * - Tauri app: 'tauri-sqlite' (native SQLite via Tauri plugin)\n * - Node.js: 'better-sqlite3'\n * - Browser with OPFS: 'sqlite-wasm'\n * - Browser without OPFS: 'indexeddb'\n */\nexport function detectAdapterType(): AdapterType {\n\t// Tauri environment — detected via __TAURI_INTERNALS__ injected by the Tauri runtime\n\tif (\n\t\ttypeof globalThis !== 'undefined' &&\n\t\ttypeof (globalThis as Record<string, unknown>).__TAURI_INTERNALS__ !== 'undefined'\n\t) {\n\t\treturn 'tauri-sqlite'\n\t}\n\n\t// Node.js environment\n\tif (typeof process !== 'undefined' && process.versions?.node) {\n\t\treturn 'better-sqlite3'\n\t}\n\n\t// Browser environment\n\tif (typeof globalThis.navigator !== 'undefined') {\n\t\t// Check for OPFS support (FileSystemHandle indicates OPFS availability)\n\t\tif (typeof (globalThis as Record<string, unknown>).FileSystemHandle !== 'undefined') {\n\t\t\treturn 'sqlite-wasm'\n\t\t}\n\t\treturn 'indexeddb'\n\t}\n\n\t// Default fallback (e.g., Deno, Bun, or other runtimes)\n\treturn 'better-sqlite3'\n}\n\n/**\n * Create a StorageAdapter for the given adapter type.\n * Uses dynamic imports so unused adapters are not bundled.\n *\n * @param type - The adapter type to create\n * @param dbName - Database name (used by all adapters)\n * @returns A configured StorageAdapter instance\n */\nexport async function createAdapter(\n\ttype: AdapterType,\n\tdbName: string,\n\tworkerUrl?: string | URL,\n\temitter?: KoraEventEmitter,\n\tworkerResponseTimeoutMs?: number,\n\tsharedWorkerUrl?: string | URL,\n): Promise<StorageAdapter> {\n\tswitch (type) {\n\t\tcase 'tauri-sqlite': {\n\t\t\t// @korajs/tauri is only installed in Tauri projects (optional peer dep).\n\t\t\t// Runtime import via Function so Vite/Rollup do not pre-bundle or resolve the module.\n\t\t\tconst { TauriSqliteAdapter } = await importOptionalPeer<{\n\t\t\t\tTauriSqliteAdapter: new (options: { path: string }) => StorageAdapter\n\t\t\t}>('@korajs/tauri')\n\t\t\treturn new TauriSqliteAdapter({ path: `${dbName}.db` })\n\t\t}\n\t\tcase 'better-sqlite3': {\n\t\t\tconst { BetterSqlite3Adapter } = await import(\n\t\t\t\t/* @vite-ignore */ '@korajs/store/better-sqlite3'\n\t\t\t)\n\t\t\treturn new BetterSqlite3Adapter(dbName)\n\t\t}\n\t\tcase 'sqlite-wasm': {\n\t\t\tconst { SqliteWasmAdapter } = await import('@korajs/store/sqlite-wasm')\n\t\t\treturn new SqliteWasmAdapter({ dbName, workerUrl, sharedWorkerUrl, workerResponseTimeoutMs })\n\t\t}\n\t\tcase 'indexeddb': {\n\t\t\tconst { IndexedDbAdapter } = await import('@korajs/store/indexeddb')\n\t\t\treturn new IndexedDbAdapter({ dbName, workerUrl, emitter, workerResponseTimeoutMs })\n\t\t}\n\t\tdefault: {\n\t\t\tconst _exhaustive: never = type\n\t\t\tthrow new Error(`Unknown adapter type: ${_exhaustive}`)\n\t\t}\n\t}\n}\n","import { KoraError } from '@korajs/core'\n\n/**\n * Thrown when collection/query APIs are used before {@link KoraApp.ready} resolves.\n */\nexport class AppNotReadyError extends KoraError {\n\tconstructor(detail: string) {\n\t\tsuper(detail, 'APP_NOT_READY', {\n\t\t\tfix: 'Await app.ready, or wrap your UI in <KoraProvider app={app}> before calling useQuery().',\n\t\t})\n\t\tthis.name = 'AppNotReadyError'\n\t}\n}\n","import type {\n\tCollectionDefinition,\n\tHLCTimestamp,\n\tKoraEventEmitter,\n\tOperation,\n\tSchemaDefinition,\n} from '@korajs/core'\nimport { HybridLogicalClock, KoraError, createOperation } from '@korajs/core'\nimport { topologicalSort } from '@korajs/core/internal'\nimport type { MergeEngine, MergeResult, ReferentialMergeContext, SideEffectOp } from '@korajs/merge'\nimport { buildMergeRelationLookup, checkReferentialIntegrityOnDelete } from '@korajs/merge'\nimport type { ConstraintContext } from '@korajs/merge'\nimport type {\n\tApplyRemoteOptions,\n\tCollectionRecord,\n\tLocalMutationHandler,\n\tStore,\n\tTransactionCommitBatch,\n\tTransactionCommitResult,\n} from '@korajs/store'\nimport { richtextStatesEqual } from '@korajs/store'\nimport {\n\texecuteDelete,\n\texecuteInsert,\n\texecuteUpdate,\n\tresolveCausalDeps,\n} from '@korajs/store/internal'\nimport type { ApplyResult } from '@korajs/sync'\nimport { buildSideEffectEntry } from './build-side-effect-entry'\n\n/**\n * Whether the operation originated locally or arrived from sync.\n */\nexport type ApplyMode = 'local' | 'remote'\n\n/**\n * Dependencies for the unified apply pipeline.\n */\nexport interface ApplyPipelineDeps {\n\treadonly store: Store\n\treadonly mergeEngine: MergeEngine\n\treadonly emitter: KoraEventEmitter | null\n\t/** Called when a field-level merge runs (updates sync conflict counter). */\n\treadonly onMergeConflict?: () => void\n}\n\n/**\n * Context passed into each apply invocation.\n */\nexport interface ApplyContext {\n\treadonly mode: ApplyMode\n\treadonly schema: SchemaDefinition\n}\n\n/**\n * Single entry point for applying remote sync operations with merge + referential integrity.\n */\nexport class ApplyPipeline implements LocalMutationHandler {\n\tprivate readonly relationLookupMap: ReturnType<typeof buildMergeRelationLookup>\n\n\tconstructor(private readonly deps: ApplyPipelineDeps) {\n\t\tthis.relationLookupMap = buildMergeRelationLookup(deps.store.getSchema())\n\t}\n\n\t/** Local insert — same persistence path as remote apply side effects. */\n\tasync insert(collection: string, data: Record<string, unknown>): Promise<CollectionRecord> {\n\t\treturn executeInsert(this.deps.store.createMutationContext(collection), data)\n\t}\n\n\t/** Local update. */\n\tasync update(\n\t\tcollection: string,\n\t\tid: string,\n\t\tdata: Record<string, unknown>,\n\t): Promise<CollectionRecord> {\n\t\treturn executeUpdate(this.deps.store.createMutationContext(collection), id, data)\n\t}\n\n\t/**\n\t * Local delete with merge-package referential integrity (same rules as remote delete).\n\t */\n\tasync delete(collection: string, id: string): Promise<void> {\n\t\tconst ctx = this.deps.store.createMutationContext(collection)\n\t\tconst causalDeps = resolveCausalDeps(ctx)\n\t\tconst operation = await createOperation(\n\t\t\t{\n\t\t\t\tnodeId: ctx.nodeId,\n\t\t\t\ttype: 'delete',\n\t\t\t\tcollection,\n\t\t\t\trecordId: id,\n\t\t\t\tdata: null,\n\t\t\t\tpreviousData: null,\n\t\t\t\tsequenceNumber: await ctx.allocateSequenceNumber(),\n\t\t\t\tcausalDeps,\n\t\t\t\tschemaVersion: ctx.schema.version,\n\t\t\t},\n\t\t\tctx.clock,\n\t\t)\n\t\tctx.causalTracker?.afterOperation(collection, operation.id, ctx.inTransaction)\n\n\t\tconst refCtx = createReferentialMergeContext(this.deps.store)\n\t\tconst check = await checkReferentialIntegrityOnDelete(\n\t\t\toperation,\n\t\t\tthis.deps.store.getSchema(),\n\t\t\trefCtx,\n\t\t\tthis.relationLookupMap,\n\t\t)\n\n\t\tfor (const trace of check.traces) {\n\t\t\tthis.deps.emitter?.emit({ type: 'merge:conflict', trace })\n\t\t}\n\n\t\tif (!check.allowed) {\n\t\t\tthrow new KoraError(\n\t\t\t\t`Cannot delete record \"${id}\" from \"${collection}\": referential restrict policy violated`,\n\t\t\t\t'REFERENTIAL_INTEGRITY',\n\t\t\t\t{ collection, recordId: id },\n\t\t\t)\n\t\t}\n\n\t\tawait executeDelete(ctx, id, {\n\t\t\tskipReferentialEnforcement: true,\n\t\t\toperation,\n\t\t})\n\n\t\tif (check.sideEffectOps.length > 0) {\n\t\t\tawait applySideEffectOps(this.deps.store, check.sideEffectOps, operation.id)\n\t\t}\n\t}\n\n\t/**\n\t * Commit a buffered transaction: merge-package delete enforcement, causal ordering, single DB txn.\n\t */\n\tasync commitTransaction(batch: TransactionCommitBatch): Promise<TransactionCommitResult> {\n\t\tconst store = this.deps.store\n\t\tconst supplemental: TransactionCommitBatch['entries'] = []\n\n\t\tfor (const entry of batch.entries) {\n\t\t\tif (entry.operation.type !== 'delete') {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst refCtx = createReferentialMergeContext(store)\n\t\t\tconst check = await checkReferentialIntegrityOnDelete(\n\t\t\t\tentry.operation,\n\t\t\t\tstore.getSchema(),\n\t\t\t\trefCtx,\n\t\t\t\tthis.relationLookupMap,\n\t\t\t)\n\n\t\t\tfor (const trace of check.traces) {\n\t\t\t\tthis.deps.emitter?.emit({ type: 'merge:conflict', trace })\n\t\t\t}\n\n\t\t\tif (!check.allowed) {\n\t\t\t\tthrow new KoraError(\n\t\t\t\t\t`Cannot delete record \"${entry.operation.recordId}\" from \"${entry.collection}\": referential restrict policy violated`,\n\t\t\t\t\t'REFERENTIAL_INTEGRITY',\n\t\t\t\t\t{ collection: entry.collection, recordId: entry.operation.recordId },\n\t\t\t\t)\n\t\t\t}\n\n\t\t\tfor (const effect of check.sideEffectOps) {\n\t\t\t\tconst ctx = store.createMutationContext(effect.collection, { inTransaction: true })\n\t\t\t\tsupplemental.push(\n\t\t\t\t\tawait buildSideEffectEntry(\n\t\t\t\t\t\tctx,\n\t\t\t\t\t\teffect,\n\t\t\t\t\t\tentry.operation.id,\n\t\t\t\t\t\tbatch.transactionId,\n\t\t\t\t\t\tbatch.mutationName,\n\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\n\t\tconst allEntries = [...batch.entries, ...supplemental]\n\t\tconst sortedOps = topologicalSort(allEntries.map((e) => e.operation))\n\t\tconst commandsByOpId = new Map(allEntries.map((e) => [e.operation.id, e.commands] as const))\n\n\t\tconst ctx = store.createMutationContext(\n\t\t\tbatch.entries[0]?.collection ?? Object.keys(store.getSchema().collections)[0] ?? 'todos',\n\t\t\t{ inTransaction: true },\n\t\t)\n\n\t\tawait ctx.adapter.transaction(async (tx) => {\n\t\t\tfor (const op of sortedOps) {\n\t\t\t\tconst commands = commandsByOpId.get(op.id)\n\t\t\t\tif (!commands) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tfor (const cmd of commands) {\n\t\t\t\t\tawait tx.execute(cmd.sql, cmd.params)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\n\t\tconst affectedCollections = new Set<string>()\n\t\tfor (const entry of allEntries) {\n\t\t\taffectedCollections.add(entry.collection)\n\t\t}\n\n\t\treturn { operations: sortedOps, affectedCollections }\n\t}\n\n\tasync applyRemote(op: Operation): Promise<ApplyResult> {\n\t\treturn this.apply(op, { mode: 'remote', schema: this.deps.store.getSchema() })\n\t}\n\n\tasync apply(op: Operation, context: ApplyContext): Promise<ApplyResult> {\n\t\tif (context.mode === 'local') {\n\t\t\treturn this.deps.store.applyRemoteOperation(op)\n\t\t}\n\n\t\tif (op.type === 'delete') {\n\t\t\treturn this.applyRemoteDelete(op)\n\t\t}\n\n\t\tif (op.type === 'insert' && op.data) {\n\t\t\treturn this.applyRemoteInsert(op)\n\t\t}\n\n\t\tif (op.type === 'update' && op.data && op.previousData) {\n\t\t\treturn this.applyRemoteUpdate(op)\n\t\t}\n\n\t\treturn this.deps.store.applyRemoteOperation(op)\n\t}\n\n\tprivate async applyRemoteDelete(op: Operation): Promise<ApplyResult> {\n\t\tconst blocked = await this.resolveRemoteDeleteVsLocalUpdate(op)\n\t\tif (blocked) {\n\t\t\treturn 'skipped'\n\t\t}\n\n\t\tconst refCtx = createReferentialMergeContext(this.deps.store)\n\t\tconst check = await checkReferentialIntegrityOnDelete(\n\t\t\top,\n\t\t\tthis.deps.store.getSchema(),\n\t\t\trefCtx,\n\t\t\tthis.relationLookupMap,\n\t\t)\n\n\t\tfor (const trace of check.traces) {\n\t\t\tthis.deps.emitter?.emit({ type: 'merge:conflict', trace })\n\t\t}\n\n\t\tif (!check.allowed) {\n\t\t\treturn 'rejected'\n\t\t}\n\n\t\tconst result = await this.deps.store.applyRemoteOperation(op)\n\t\tif (result !== 'applied') {\n\t\t\treturn result\n\t\t}\n\n\t\tif (check.sideEffectOps.length > 0) {\n\t\t\tawait applySideEffectOps(this.deps.store, check.sideEffectOps, op.id)\n\t\t}\n\n\t\treturn 'applied'\n\t}\n\n\t/**\n\t * When a local update is newer than a remote delete, keep the record alive.\n\t */\n\tprivate async resolveRemoteDeleteVsLocalUpdate(op: Operation): Promise<boolean> {\n\t\tconst collectionDef = this.deps.store.getSchema().collections[op.collection]\n\t\tif (!collectionDef) {\n\t\t\treturn false\n\t\t}\n\n\t\tconst localOp = await this.deps.store.getLatestLocalOperationForRecord(\n\t\t\top.collection,\n\t\t\top.recordId,\n\t\t)\n\t\tif (!localOp || localOp.type !== 'update') {\n\t\t\treturn false\n\t\t}\n\n\t\tconst baseState = localOp.previousData ?? {}\n\t\tconst mergeResult = await this.deps.mergeEngine.merge({\n\t\t\tlocal: localOp,\n\t\t\tremote: op,\n\t\t\tbaseState,\n\t\t\tcollectionDef,\n\t\t})\n\n\t\tthis.emitMergeLifecycle(op, localOp, mergeResult)\n\n\t\treturn mergeResult.appliedOperation === 'local'\n\t}\n\n\tprivate async applyRemoteUpdate(op: Operation): Promise<ApplyResult> {\n\t\tconst schema = this.deps.store.getSchema()\n\t\tconst collectionDef = schema.collections[op.collection]\n\t\tif (!collectionDef) {\n\t\t\treturn this.deps.store.applyRemoteOperation(op)\n\t\t}\n\n\t\tconst accessor = this.deps.store.collection(op.collection)\n\t\tconst currentRecord = await accessor.findById(op.recordId)\n\n\t\tif (!currentRecord) {\n\t\t\tconst tombstoneResult = await this.applyRemoteUpdateOnDeletedRow(op, collectionDef)\n\t\t\tif (tombstoneResult !== null) {\n\t\t\t\treturn tombstoneResult\n\t\t\t}\n\t\t\treturn this.deps.store.applyRemoteOperation(op)\n\t\t}\n\n\t\tlet hasConflict = false\n\t\tfor (const field of Object.keys(op.data ?? {})) {\n\t\t\tconst fieldDef = collectionDef.fields[field]\n\t\t\tconst expectedBase = op.previousData?.[field]\n\t\t\tconst currentLocal = currentRecord[field]\n\n\t\t\tif (fieldDef?.kind === 'richtext') {\n\t\t\t\tif (!richtextStatesEqual(currentLocal, expectedBase)) {\n\t\t\t\t\thasConflict = true\n\t\t\t\t}\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (!deepEqual(expectedBase, currentLocal)) {\n\t\t\t\thasConflict = true\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\tif (!hasConflict) {\n\t\t\treturn this.deps.store.applyRemoteOperation(op)\n\t\t}\n\n\t\treturn this.applyMergedUpdate(op, collectionDef, currentRecord, op.previousData ?? {})\n\t}\n\n\t/**\n\t * Remote update vs local soft-delete: merge before materializing to avoid zombie rows.\n\t */\n\tprivate async applyRemoteUpdateOnDeletedRow(\n\t\top: Operation,\n\t\tcollectionDef: CollectionDefinition,\n\t): Promise<ApplyResult | null> {\n\t\tconst snapshot = await this.deps.store.findMaterializedRow(op.collection, op.recordId)\n\t\tif (!snapshot?.deleted) {\n\t\t\treturn null\n\t\t}\n\n\t\tconst localOp = await this.deps.store.getLatestLocalOperationForRecord(\n\t\t\top.collection,\n\t\t\top.recordId,\n\t\t)\n\t\tif (!localOp || localOp.type !== 'delete') {\n\t\t\treturn null\n\t\t}\n\n\t\tconst mergeResult = await this.deps.mergeEngine.merge({\n\t\t\tlocal: localOp,\n\t\t\tremote: op,\n\t\t\tbaseState: op.previousData ?? {},\n\t\t\tcollectionDef,\n\t\t})\n\n\t\tthis.emitMergeLifecycle(op, localOp, mergeResult)\n\n\t\tif (mergeResult.appliedOperation === 'local') {\n\t\t\treturn 'skipped'\n\t\t}\n\n\t\tconst mergedOp: Operation = {\n\t\t\t...op,\n\t\t\tdata: { ...mergeResult.mergedData },\n\t\t\ttimestamp: maxTimestamp(op.timestamp, localOp.timestamp),\n\t\t}\n\n\t\tconst applyResult = await this.deps.store.applyRemoteOperation(mergedOp, {\n\t\t\treactivateIfDeleted: true,\n\t\t})\n\n\t\tif (applyResult === 'applied' && mergeResult.sideEffects.length > 0) {\n\t\t\tawait applySideEffectOps(this.deps.store, mergeResult.sideEffects, op.id)\n\t\t}\n\n\t\treturn applyResult\n\t}\n\n\tprivate async applyMergedUpdate(\n\t\top: Operation,\n\t\tcollectionDef: CollectionDefinition,\n\t\tcurrentRecord: CollectionRecord,\n\t\tbaseState: Record<string, unknown>,\n\t\tapplyOptions?: ApplyRemoteOptions,\n\t): Promise<ApplyResult> {\n\t\tconst localTimestamp = await resolveLocalTimestamp(\n\t\t\tthis.deps.store,\n\t\t\top.collection,\n\t\t\top.recordId,\n\t\t\tcurrentRecord,\n\t\t\tthis.deps.store.getNodeId(),\n\t\t)\n\t\tconst localOp: Operation = {\n\t\t\t...op,\n\t\t\tdata: buildLocalDiff(baseState, currentRecord, Object.keys(op.data ?? {})),\n\t\t\tpreviousData: op.previousData,\n\t\t\tnodeId: this.deps.store.getNodeId(),\n\t\t\ttimestamp: localTimestamp,\n\t\t}\n\n\t\tconst constraintContext = createConstraintContext(this.deps.store)\n\t\tconst mergeResult = await this.deps.mergeEngine.merge(\n\t\t\t{\n\t\t\t\tlocal: localOp,\n\t\t\t\tremote: op,\n\t\t\t\tbaseState,\n\t\t\t\tcollectionDef,\n\t\t\t},\n\t\t\tconstraintContext,\n\t\t)\n\n\t\tthis.emitMergeLifecycle(op, localOp, mergeResult)\n\n\t\tconst mergedOp: Operation = {\n\t\t\t...op,\n\t\t\tdata: mergeResult.mergedData,\n\t\t\ttimestamp: maxTimestamp(op.timestamp, localTimestamp),\n\t\t}\n\n\t\tconst applyResult = await this.deps.store.applyRemoteOperation(mergedOp, applyOptions)\n\n\t\tif (applyResult === 'applied' && mergeResult.sideEffects.length > 0) {\n\t\t\tawait applySideEffectOps(this.deps.store, mergeResult.sideEffects, op.id)\n\t\t}\n\n\t\treturn applyResult\n\t}\n\n\tprivate async applyRemoteInsert(op: Operation): Promise<ApplyResult> {\n\t\tconst collectionDef = this.deps.store.getSchema().collections[op.collection]\n\t\tif (!collectionDef || !op.data) {\n\t\t\treturn this.deps.store.applyRemoteOperation(op)\n\t\t}\n\n\t\tconst snapshot = await this.deps.store.findMaterializedRow(op.collection, op.recordId)\n\t\tif (!snapshot || snapshot.deleted) {\n\t\t\treturn this.deps.store.applyRemoteOperation(op)\n\t\t}\n\n\t\tconst localOp = await resolveLocalOpForRecord(\n\t\t\tthis.deps.store,\n\t\t\top.collection,\n\t\t\top.recordId,\n\t\t\tsnapshot.record,\n\t\t)\n\n\t\tconst mergeResult = await this.deps.mergeEngine.merge({\n\t\t\tlocal: localOp,\n\t\t\tremote: op,\n\t\t\tbaseState: {},\n\t\t\tcollectionDef,\n\t\t})\n\n\t\tthis.emitMergeLifecycle(op, localOp, mergeResult)\n\n\t\tconst mergedOp: Operation = {\n\t\t\t...op,\n\t\t\tdata: mergeResult.mergedData,\n\t\t\ttimestamp: maxTimestamp(op.timestamp, localOp.timestamp),\n\t\t}\n\n\t\treturn this.deps.store.applyRemoteOperation(mergedOp)\n\t}\n\n\tprivate emitMergeLifecycle(remote: Operation, local: Operation, mergeResult: MergeResult): void {\n\t\tthis.deps.emitter?.emit({\n\t\t\ttype: 'merge:started',\n\t\t\toperationA: remote,\n\t\t\toperationB: local,\n\t\t})\n\n\t\tconst hadMergeConflict = mergeResult.traces.some(\n\t\t\t(t) =>\n\t\t\t\tt.strategy !== 'no-conflict-local' &&\n\t\t\t\tt.strategy !== 'no-conflict-remote' &&\n\t\t\t\tt.strategy !== 'no-conflict-unchanged',\n\t\t)\n\t\tif (hadMergeConflict) {\n\t\t\tthis.deps.onMergeConflict?.()\n\t\t}\n\n\t\tfor (const trace of mergeResult.traces) {\n\t\t\tif (\n\t\t\t\ttrace.strategy !== 'no-conflict-local' &&\n\t\t\t\ttrace.strategy !== 'no-conflict-remote' &&\n\t\t\t\ttrace.strategy !== 'no-conflict-unchanged'\n\t\t\t) {\n\t\t\t\tthis.deps.emitter?.emit({ type: 'merge:conflict', trace })\n\t\t\t}\n\t\t}\n\t\tconst firstTrace = mergeResult.traces[0]\n\t\tif (firstTrace) {\n\t\t\tthis.deps.emitter?.emit({ type: 'merge:completed', trace: firstTrace })\n\t\t}\n\t}\n}\n\n/**\n * Prefer the latest local op, then any op in the log for this record, then a snapshot-derived insert.\n */\nasync function resolveLocalOpForRecord(\n\tstore: Store,\n\tcollection: string,\n\trecordId: string,\n\trecord: CollectionRecord,\n): Promise<Operation> {\n\tconst localLatest = await store.getLatestLocalOperationForRecord(collection, recordId)\n\tif (localLatest) {\n\t\treturn localLatest\n\t}\n\n\tconst anyLatest = await store.getLatestOperationForRecord(collection, recordId)\n\tif (anyLatest) {\n\t\treturn anyLatest\n\t}\n\n\treturn syntheticInsertFromSnapshot(\n\t\trecord,\n\t\tcollection,\n\t\tstore.getNodeId(),\n\t\tstore.getSchema().version,\n\t)\n}\n\nfunction syntheticInsertFromSnapshot(\n\trecord: CollectionRecord,\n\tcollection: string,\n\tnodeId: string,\n\tschemaVersion: number,\n): Operation {\n\tconst { id, createdAt, updatedAt, ...fields } = record\n\treturn {\n\t\tid: `synthetic-local-${id}`,\n\t\tnodeId,\n\t\ttype: 'insert',\n\t\tcollection,\n\t\trecordId: id,\n\t\tdata: fields,\n\t\tpreviousData: null,\n\t\ttimestamp: { wallTime: updatedAt, logical: 0, nodeId },\n\t\tsequenceNumber: 0,\n\t\tcausalDeps: [],\n\t\tschemaVersion,\n\t}\n}\n\nfunction createConstraintContext(store: Store): ConstraintContext {\n\treturn {\n\t\tasync queryRecords(collection: string, where: Record<string, unknown>) {\n\t\t\tconst rows = await store.collection(collection).where(where).exec()\n\t\t\treturn rows as Record<string, unknown>[]\n\t\t},\n\t\tasync countRecords(collection: string, where: Record<string, unknown>) {\n\t\t\treturn store.collection(collection).where(where).count()\n\t\t},\n\t}\n}\n\nfunction createReferentialMergeContext(store: Store): ReferentialMergeContext {\n\treturn {\n\t\tasync queryRecords(collection: string, where: Record<string, unknown>) {\n\t\t\tconst rows = await store.collection(collection).where(where).exec()\n\t\t\treturn rows as Record<string, unknown>[]\n\t\t},\n\t\tasync recordExists(collection: string, recordId: string) {\n\t\t\tconst row = await store.collection(collection).findById(recordId)\n\t\t\treturn row !== null\n\t\t},\n\t}\n}\n\nasync function applySideEffectOps(\n\tstore: Store,\n\tsideEffects: SideEffectOp[],\n\tparentOpId: string,\n): Promise<void> {\n\tfor (const effect of sideEffects) {\n\t\tconst ctx = store.createMutationContext(effect.collection, {\n\t\t\textraCausalDeps: [parentOpId],\n\t\t})\n\t\tif (effect.type === 'delete') {\n\t\t\tawait executeDelete(ctx, effect.recordId, { skipReferentialEnforcement: true })\n\t\t} else if (effect.type === 'update' && effect.data) {\n\t\t\tawait executeUpdate(ctx, effect.recordId, effect.data)\n\t\t}\n\t}\n}\n\nfunction buildLocalDiff(\n\tbaseState: Record<string, unknown>,\n\tcurrentRecord: Record<string, unknown>,\n\tfields: string[],\n): Record<string, unknown> {\n\tconst diff: Record<string, unknown> = {}\n\tfor (const field of fields) {\n\t\tdiff[field] = currentRecord[field]\n\t}\n\treturn diff\n}\n\nasync function resolveLocalTimestamp(\n\tstore: Store,\n\tcollection: string,\n\trecordId: string,\n\tcurrentRecord: CollectionRecord,\n\tnodeId: string,\n): Promise<HLCTimestamp> {\n\tconst latestLocal = await store.getLatestLocalOperationForRecord(collection, recordId)\n\tif (latestLocal) {\n\t\treturn latestLocal.timestamp\n\t}\n\tconst updatedAt = currentRecord.updatedAt\n\tif (typeof updatedAt === 'number') {\n\t\treturn { wallTime: updatedAt, logical: 0, nodeId }\n\t}\n\treturn { wallTime: Date.now(), logical: 0, nodeId }\n}\n\nfunction maxTimestamp(a: HLCTimestamp, b: HLCTimestamp): HLCTimestamp {\n\treturn HybridLogicalClock.compare(a, b) >= 0 ? a : b\n}\n\nfunction deepEqual(a: unknown, b: unknown): boolean {\n\tif (a === b) return true\n\tif (a === null || b === null) return false\n\tif (a === undefined || b === undefined) return false\n\tif (typeof a !== typeof b) return false\n\n\tif (Array.isArray(a) && Array.isArray(b)) {\n\t\tif (a.length !== b.length) return false\n\t\treturn a.every((val, i) => deepEqual(val, b[i]))\n\t}\n\n\tif (typeof a === 'object' && typeof b === 'object') {\n\t\tconst keysA = Object.keys(a as Record<string, unknown>)\n\t\tconst keysB = Object.keys(b as Record<string, unknown>)\n\t\tif (keysA.length !== keysB.length) return false\n\t\treturn keysA.every((key) =>\n\t\t\tdeepEqual((a as Record<string, unknown>)[key], (b as Record<string, unknown>)[key]),\n\t\t)\n\t}\n\n\treturn false\n}\n","import { createOperation } from '@korajs/core'\nimport type { SideEffectOp } from '@korajs/merge'\nimport type { TransactionBufferedEntry } from '@korajs/store'\nimport type { LocalMutationContext } from '@korajs/store/internal'\nimport {\n\tbuildInsertQuery,\n\tbuildSoftDeleteQuery,\n\tbuildUpdateQuery,\n\tserializeOperation,\n\tserializeRecord,\n\tserializeRowVersion,\n} from '@korajs/store/internal'\n\n/**\n * Materialize a merge-package referential side effect as an operation log entry + SQL commands.\n */\nexport async function buildSideEffectEntry(\n\tctx: LocalMutationContext,\n\teffect: SideEffectOp,\n\tparentOpId: string,\n\ttransactionId?: string,\n\tmutationName?: string,\n): Promise<TransactionBufferedEntry> {\n\tconst causalDeps = [parentOpId]\n\tconst baseInput = {\n\t\tnodeId: ctx.nodeId,\n\t\tcollection: effect.collection,\n\t\trecordId: effect.recordId,\n\t\tsequenceNumber: await ctx.allocateSequenceNumber(),\n\t\tcausalDeps,\n\t\tschemaVersion: ctx.schema.version,\n\t\t...(transactionId !== undefined ? { transactionId } : {}),\n\t\t...(mutationName !== undefined ? { mutationName } : {}),\n\t}\n\n\tif (effect.type === 'delete') {\n\t\tconst operation = await createOperation(\n\t\t\t{\n\t\t\t\t...baseInput,\n\t\t\t\ttype: 'delete',\n\t\t\t\tdata: null,\n\t\t\t\tpreviousData: effect.previousData,\n\t\t\t},\n\t\t\tctx.clock,\n\t\t)\n\t\tctx.causalTracker?.afterOperation(effect.collection, operation.id, ctx.inTransaction)\n\n\t\tconst version = serializeRowVersion(operation.timestamp)\n\t\tconst deleteQuery = buildSoftDeleteQuery(\n\t\t\teffect.collection,\n\t\t\teffect.recordId,\n\t\t\toperation.timestamp.wallTime,\n\t\t\tversion,\n\t\t)\n\t\tconst opInsert = buildInsertQuery(\n\t\t\t`_kora_ops_${effect.collection}`,\n\t\t\tserializeOperation(operation) as unknown as Record<string, unknown>,\n\t\t)\n\n\t\treturn {\n\t\t\toperation,\n\t\t\tcollection: effect.collection,\n\t\t\tcommands: [\n\t\t\t\t{ sql: deleteQuery.sql, params: deleteQuery.params },\n\t\t\t\t{ sql: opInsert.sql, params: opInsert.params },\n\t\t\t\t{\n\t\t\t\t\tsql: 'INSERT OR REPLACE INTO _kora_version_vector (node_id, sequence_number) VALUES (?, ?)',\n\t\t\t\t\tparams: [ctx.nodeId, operation.sequenceNumber],\n\t\t\t\t},\n\t\t\t],\n\t\t}\n\t}\n\n\tconst operation = await createOperation(\n\t\t{\n\t\t\t...baseInput,\n\t\t\ttype: 'update',\n\t\t\tdata: effect.data,\n\t\t\tpreviousData: effect.previousData,\n\t\t},\n\t\tctx.clock,\n\t)\n\tctx.causalTracker?.afterOperation(effect.collection, operation.id, ctx.inTransaction)\n\n\tconst definition = ctx.schema.collections[effect.collection]\n\tconst serializedChanges =\n\t\teffect.data && definition\n\t\t\t? serializeRecord(effect.data, definition.fields)\n\t\t\t: (effect.data ?? {})\n\tconst version = serializeRowVersion(operation.timestamp)\n\tconst updateQuery = buildUpdateQuery(effect.collection, effect.recordId, {\n\t\t...serializedChanges,\n\t\t_updated_at: operation.timestamp.wallTime,\n\t\t_version: version,\n\t})\n\tconst opInsert = buildInsertQuery(\n\t\t`_kora_ops_${effect.collection}`,\n\t\tserializeOperation(operation) as unknown as Record<string, unknown>,\n\t)\n\n\treturn {\n\t\toperation,\n\t\tcollection: effect.collection,\n\t\tcommands: [\n\t\t\t{ sql: updateQuery.sql, params: updateQuery.params },\n\t\t\t{ sql: opInsert.sql, params: opInsert.params },\n\t\t\t{\n\t\t\t\tsql: 'INSERT OR REPLACE INTO _kora_version_vector (node_id, sequence_number) VALUES (?, ?)',\n\t\t\t\tparams: [ctx.nodeId, operation.sequenceNumber],\n\t\t\t},\n\t\t],\n\t}\n}\n","import type { KoraEvent, KoraEventEmitter } from '@korajs/core'\nimport type { Store } from '@korajs/store'\nimport { persistedAuditTraceFromEvent } from '@korajs/store'\n\nconst AUDIT_EVENT_TYPES = ['merge:completed', 'merge:conflict', 'constraint:violated'] as const\n\ntype AuditEventType = (typeof AUDIT_EVENT_TYPES)[number]\n\nfunction isAuditEvent(event: KoraEvent): event is Extract<KoraEvent, { type: AuditEventType }> {\n\treturn (AUDIT_EVENT_TYPES as readonly string[]).includes(event.type)\n}\n\n/**\n * Persist merge and constraint traces from the event bus to `_kora_audit_traces`.\n */\nexport function wireAuditPersistence(store: Store, emitter: KoraEventEmitter): () => void {\n\tconst unsubscribers = AUDIT_EVENT_TYPES.map((eventType) =>\n\t\temitter.on(eventType, (event) => {\n\t\t\tif (!isAuditEvent(event)) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst trace = persistedAuditTraceFromEvent(event)\n\t\t\tvoid store.appendAuditTrace(trace).catch(() => {\n\t\t\t\t// Audit persistence must not break mutations or sync.\n\t\t\t})\n\t\t}),\n\t)\n\n\treturn () => {\n\t\tfor (const unsub of unsubscribers) {\n\t\t\tunsub()\n\t\t}\n\t}\n}\n","import type { KoraEventEmitter, Operation, VersionVector } from '@korajs/core'\nimport type { MergeEngine } from '@korajs/merge'\nimport type { Store } from '@korajs/store'\nimport type { ApplyResult, SyncStore } from '@korajs/sync'\nimport { ApplyPipeline } from './apply-pipeline'\n\nexport interface MergeAwareSyncStoreOptions {\n\t/** Increments SyncEngine conflict counter when merge runs on a conflicting update. */\n\tonMergeConflict?: () => void\n}\n\n/**\n * Wraps a Store to route remote sync operations through {@link ApplyPipeline}.\n *\n * Ensures remote deletes honor referential integrity (cascade, set-null, restrict)\n * and remote updates use the full three-tier merge engine with constraint context.\n */\nexport class MergeAwareSyncStore implements SyncStore {\n\tprivate readonly pipeline: ApplyPipeline\n\n\tconstructor(\n\t\tprivate readonly store: Store,\n\t\tmergeEngine: MergeEngine,\n\t\temitter: KoraEventEmitter | null,\n\t\toptions?: MergeAwareSyncStoreOptions,\n\t) {\n\t\tthis.pipeline = new ApplyPipeline({\n\t\t\tstore,\n\t\t\tmergeEngine,\n\t\t\temitter,\n\t\t\tonMergeConflict: options?.onMergeConflict,\n\t\t})\n\t}\n\n\tgetVersionVector(): VersionVector {\n\t\treturn this.store.getVersionVector()\n\t}\n\n\tgetNodeId(): string {\n\t\treturn this.store.getNodeId()\n\t}\n\n\tasync getOperationRange(nodeId: string, fromSeq: number, toSeq: number): Promise<Operation[]> {\n\t\treturn this.store.getOperationRange(nodeId, fromSeq, toSeq)\n\t}\n\n\tasync applyRemoteOperation(op: Operation): Promise<ApplyResult> {\n\t\treturn this.pipeline.applyRemote(op)\n\t}\n}\n","import type { Operation } from '@korajs/core'\nimport type { StorageAdapter } from '@korajs/store'\nimport { deserializeOperation, serializeOperation } from '@korajs/store/internal'\nimport type { OperationRow } from '@korajs/store/internal'\nimport type { QueueStorage } from '@korajs/sync'\n\ninterface SyncQueueRow {\n\tid: string\n\tpayload: string\n}\n\ntype QueuePayload = OperationRow & { _collection: string }\n\n/**\n * Persists the outbound sync queue in `_kora_sync_queue` via the local StorageAdapter.\n */\nexport class StoreQueueStorage implements QueueStorage {\n\tconstructor(private readonly adapter: StorageAdapter) {}\n\n\tasync load(): Promise<Operation[]> {\n\t\tconst rows = await this.adapter.query<SyncQueueRow>(\n\t\t\t'SELECT id, payload FROM _kora_sync_queue ORDER BY rowid ASC',\n\t\t)\n\t\treturn rows.map((row) => operationFromQueuePayload(row.payload))\n\t}\n\n\tasync enqueue(op: Operation): Promise<void> {\n\t\tconst row = serializeOperation(op)\n\t\tconst payload: QueuePayload = { ...row, _collection: op.collection }\n\t\tawait this.adapter.execute(\n\t\t\t'INSERT OR REPLACE INTO _kora_sync_queue (id, payload) VALUES (?, ?)',\n\t\t\t[op.id, JSON.stringify(payload)],\n\t\t)\n\t}\n\n\tasync dequeue(ids: string[]): Promise<void> {\n\t\tif (ids.length === 0) return\n\t\tconst placeholders = ids.map(() => '?').join(', ')\n\t\tawait this.adapter.execute(`DELETE FROM _kora_sync_queue WHERE id IN (${placeholders})`, ids)\n\t}\n\n\tasync count(): Promise<number> {\n\t\tconst rows = await this.adapter.query<{ cnt: number }>(\n\t\t\t'SELECT COUNT(*) as cnt FROM _kora_sync_queue',\n\t\t)\n\t\treturn rows[0]?.cnt ?? 0\n\t}\n}\n\nfunction operationFromQueuePayload(payload: string): Operation {\n\tconst parsed = JSON.parse(payload) as QueuePayload\n\tconst op = deserializeOperation(parsed)\n\treturn {\n\t\t...op,\n\t\tcollection: parsed._collection,\n\t}\n}\n","import type { Operation, VersionVector } from '@korajs/core'\nimport { mergeVersionVectors } from '@korajs/store'\nimport type { Store } from '@korajs/store'\nimport { decodeDeltaCursor, encodeDeltaCursor, operationMatchesScope } from '@korajs/sync'\nimport type { DeltaCursor, SyncScopeMap, SyncStatePersistence } from '@korajs/sync'\n\n/**\n * Persists and queries sync acknowledgment state via the local Store.\n */\nexport class StoreSyncStatePersistence implements SyncStatePersistence {\n\tconstructor(\n\t\tprivate readonly store: Store,\n\t\tprivate readonly scope?: SyncScopeMap,\n\t) {}\n\n\tloadLastAckedServerVector(): Promise<VersionVector> {\n\t\treturn this.store.loadLastAckedServerVector()\n\t}\n\n\tsaveLastAckedServerVector(vector: VersionVector): Promise<void> {\n\t\treturn this.store.saveLastAckedServerVector(vector)\n\t}\n\n\tmergeServerVectors(a: VersionVector, b: VersionVector): VersionVector {\n\t\treturn this.store.mergeServerVectors(a, b)\n\t}\n\n\tasync countUnsyncedOperations(serverVector: VersionVector): Promise<number> {\n\t\tconst ops = await this.getUnsyncedOperations(serverVector)\n\t\treturn ops.length\n\t}\n\n\tasync getUnsyncedOperations(serverVector: VersionVector): Promise<Operation[]> {\n\t\tconst ops = await this.store.getUnsyncedOperations(serverVector)\n\t\treturn ops.filter((op) => operationMatchesScope(op, this.scope))\n\t}\n\n\tloadDeltaCursor(): Promise<DeltaCursor | null> {\n\t\treturn this.store.loadDeltaCursor().then((encoded) => decodeDeltaCursor(encoded))\n\t}\n\n\tasync saveDeltaCursor(cursor: DeltaCursor | null): Promise<void> {\n\t\tawait this.store.saveDeltaCursor(cursor ? encodeDeltaCursor(cursor) : null)\n\t}\n}\n","import type { QueryDescriptor } from '@korajs/store'\nimport type { SyncEngine } from '@korajs/sync'\nimport type { SyncQuerySubset } from '@korajs/sync'\n\n/**\n * Extract equality-only WHERE conditions for sync query subset registration.\n * Operator-based filters (e.g. `$gt`) are not representable as sync subsets yet.\n */\nexport function queryDescriptorToSyncSubset(descriptor: QueryDescriptor): SyncQuerySubset | null {\n\tconst where: Record<string, unknown> = {}\n\n\tfor (const [field, value] of Object.entries(descriptor.where)) {\n\t\tif (value === null || value === undefined) {\n\t\t\twhere[field] = value\n\t\t\tcontinue\n\t\t}\n\t\tif (typeof value !== 'object' || Array.isArray(value)) {\n\t\t\twhere[field] = value\n\t\t}\n\t}\n\n\tif (Object.keys(where).length === 0) {\n\t\treturn null\n\t}\n\n\treturn {\n\t\tcollection: descriptor.collection,\n\t\twhere,\n\t}\n}\n\n/**\n * Creates a store hook that registers live query filters with the sync engine.\n */\nexport function createSyncQuerySubscriptionHook(\n\tgetSyncEngine: () => SyncEngine | null,\n): (descriptor: QueryDescriptor) => () => void {\n\treturn (descriptor) => {\n\t\tconst subset = queryDescriptorToSyncSubset(descriptor)\n\t\tif (!subset) {\n\t\t\treturn () => {}\n\t\t}\n\n\t\tconst engine = getSyncEngine()\n\t\tif (!engine) {\n\t\t\treturn () => {}\n\t\t}\n\n\t\treturn engine.registerQuerySubset(subset)\n\t}\n}\n","import type { KoraEventEmitter, KoraEventType } from '@korajs/core'\nimport type { SyncStatusInfo } from '@korajs/sync'\n\nconst OFFLINE_STATUS: SyncStatusInfo = Object.freeze({\n\tstatus: 'offline',\n\tpendingOperations: 0,\n\tlastSyncedAt: null,\n\tlastSuccessfulPush: null,\n\tlastSuccessfulPull: null,\n\tconflicts: 0,\n})\n\n/** Sync-related events that may change {@link SyncStatusInfo}. */\nconst SYNC_STATUS_EVENT_TYPES = [\n\t'sync:connected',\n\t'sync:disconnected',\n\t'sync:schema-mismatch',\n\t'sync:auth-failed',\n\t'sync:sent',\n\t'sync:received',\n\t'sync:acknowledged',\n\t'sync:apply-failed',\n\t'sync:diagnostics',\n\t'sync:initial-sync-progress',\n] as const satisfies readonly KoraEventType[]\n\n/**\n * Event-driven sync status snapshot for non-React consumers (`app.sync.status`).\n */\nexport interface SyncStatusBridge {\n\treadonly status: SyncStatusInfo\n\tsubscribe(listener: (status: SyncStatusInfo) => void): () => void\n\trefresh(): void\n\tdestroy(): void\n}\n\n/**\n * Subscribe to sync events and expose a reactive status snapshot.\n */\nexport function createSyncStatusBridge(\n\temitter: KoraEventEmitter,\n\tgetSyncEngine: () => { getStatus(): SyncStatusInfo } | null,\n): SyncStatusBridge {\n\tlet currentStatus: SyncStatusInfo = OFFLINE_STATUS\n\tconst listeners = new Set<(status: SyncStatusInfo) => void>()\n\n\tconst refresh = (): void => {\n\t\tconst engine = getSyncEngine()\n\t\tconst next = engine ? engine.getStatus() : OFFLINE_STATUS\n\t\tconst prevSerialized = JSON.stringify(currentStatus)\n\t\tconst nextSerialized = JSON.stringify(next)\n\t\tif (prevSerialized === nextSerialized) {\n\t\t\treturn\n\t\t}\n\t\tcurrentStatus = next\n\t\tfor (const listener of listeners) {\n\t\t\tlistener(currentStatus)\n\t\t}\n\t}\n\n\tconst unsubs: Array<() => void> = []\n\tfor (const type of SYNC_STATUS_EVENT_TYPES) {\n\t\tunsubs.push(emitter.on(type, refresh))\n\t}\n\n\tconst bridge: SyncStatusBridge = {\n\t\tget status() {\n\t\t\treturn currentStatus\n\t\t},\n\t\tsubscribe(listener: (status: SyncStatusInfo) => void): () => void {\n\t\t\tlisteners.add(listener)\n\t\t\tlistener(currentStatus)\n\t\t\treturn () => {\n\t\t\t\tlisteners.delete(listener)\n\t\t\t}\n\t\t},\n\t\trefresh,\n\t\tdestroy(): void {\n\t\t\tfor (const unsub of unsubs) {\n\t\t\t\tunsub()\n\t\t\t}\n\t\t\tunsubs.length = 0\n\t\t\tlisteners.clear()\n\t\t},\n\t}\n\n\trefresh()\n\n\treturn bridge\n}\n","import { KoraError, SchemaValidationError } from '@korajs/core'\nimport { detectAdapterType } from './adapter-resolver'\nimport type { KoraConfig } from './types'\n\n/**\n * Fail fast on invalid createApp configuration before opening storage or sync.\n */\nexport function validateCreateAppConfig(config: KoraConfig): void {\n\tif (!config.schema) {\n\t\tthrow new SchemaValidationError('createApp requires a schema.', {\n\t\t\tfix: 'Pass schema: defineSchema({ version: 1, collections: { ... } })',\n\t\t})\n\t}\n\n\tif (config.schema.version < 1) {\n\t\tthrow new SchemaValidationError('Schema version must be at least 1.', {\n\t\t\tversion: config.schema.version,\n\t\t})\n\t}\n\n\tconst collectionNames = Object.keys(config.schema.collections)\n\tif (collectionNames.length === 0) {\n\t\tthrow new SchemaValidationError('Schema must define at least one collection.', {\n\t\t\tfix: 'Add entries under collections in defineSchema().',\n\t\t})\n\t}\n\n\tif (config.sync) {\n\t\tvalidateSyncUrl(config.sync.url, config.sync.transport ?? 'websocket')\n\t}\n\n\tconst adapter = config.store?.adapter ?? detectAdapterType()\n\tconst isBrowser =\n\t\ttypeof globalThis !== 'undefined' &&\n\t\ttypeof (globalThis as Record<string, unknown>).window !== 'undefined'\n\n\tif (\n\t\tisBrowser &&\n\t\t(adapter === 'sqlite-wasm' || adapter === 'indexeddb') &&\n\t\t!config.store?.workerUrl\n\t) {\n\t\tthrow new KoraError(\n\t\t\t'Browser storage requires store.workerUrl pointing to the SQLite WASM worker script.',\n\t\t\t'MISSING_WORKER_URL',\n\t\t\t{\n\t\t\t\tadapter,\n\t\t\t\tfix: 'Add store: { workerUrl: \"/sqlite-wasm-worker.js\" } (see create-kora-app templates).',\n\t\t\t},\n\t\t)\n\t}\n}\n\nfunction validateSyncUrl(url: string, transport: 'websocket' | 'http'): void {\n\tif (!url || url.trim().length === 0) {\n\t\tthrow new KoraError('sync.url is required when sync is configured.', 'INVALID_SYNC_URL', {\n\t\t\tfix: 'Pass sync: { url: \"wss://your-server/kora\" }.',\n\t\t})\n\t}\n\n\ttry {\n\t\tconst parsed = new URL(url)\n\t\tif (transport === 'http') {\n\t\t\tif (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {\n\t\t\t\tthrow new Error('bad protocol')\n\t\t\t}\n\t\t} else if (parsed.protocol !== 'ws:' && parsed.protocol !== 'wss:') {\n\t\t\tthrow new Error('bad protocol')\n\t\t}\n\t} catch {\n\t\tthrow new KoraError(\n\t\t\t`Invalid sync URL \"${url}\" for transport \"${transport}\".`,\n\t\t\t'INVALID_SYNC_URL',\n\t\t\t{\n\t\t\t\turl,\n\t\t\t\ttransport,\n\t\t\t\tfix:\n\t\t\t\t\ttransport === 'http'\n\t\t\t\t\t\t? 'Use an absolute http:// or https:// URL.'\n\t\t\t\t\t\t: 'Use an absolute ws:// or wss:// URL.',\n\t\t\t},\n\t\t)\n\t}\n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ACZ,YAAM,IAAI;AAAA,QACT;AAAA,MACD;AAAA,IACD;AAAA,IACA,MAAM,QAAQ;AACb,YAAM,IAAI;AAAA,QACT;AAAA,MACD;AAAA,IACD;AAAA,IACA,UAAU,WAA8D;AACvE,YAAM,IAAI;AAAA,QACT;AAAA,MACD;AAAA,IACD;AAAA,IACA,gBAAgB;AACf,aAAO,EAAE,GAAG,YAAY,OAAO,EAAE,GAAG,WAAW,MAAM,GAAG,SAAS,CAAC,GAAG,WAAW,OAAO,EAAE;AAAA,IAC1F;AAAA,EACD;AAEA,SAAO;AACR;;;AD1rBA,IAAAC,gBAIO;AAGP,IAAAC,eAAyC;AACzC,IAAAA,eAAmC;AACnC,IAAAA,eAA+B;AAC/B,IAAAA,eAAgC;AAChC,IAAAA,gBAA0B;AAC1B,IAAAA,gBAAmB;AAgCnB,IAAAD,gBAAuC;AACvC,IAAAA,gBAAmC;AACnC,IAAAA,gBAKO;AAgBP,IAAAE,gBAA4B;AAI5B,IAAAC,eAA+C;","names":["import_core","import_internal","import_merge","import_store","import_sync","import_core","import_internal","import_core","operation","version","opInsert","ctx","op","t","import_store","op","import_internal","op","import_store","op","import_core","config","import_store","import_core","import_merge","import_sync"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/create-app.ts","../src/collection-accessor.ts","../src/initialize-app.ts","../src/adapter-resolver.ts","../src/apply-pipeline.ts","../src/build-side-effect-entry.ts","../src/audit-bridge.ts","../src/create-sync-transport.ts","../src/merge-aware-sync-store.ts","../src/store-queue-storage.ts","../src/store-sync-state.ts","../src/sync-query-bridge.ts","../src/sequences-accessor.ts","../src/setup-devtools.ts","../src/sync-control.ts","../src/auth-sync-coordinator.ts","../src/sync-status-bridge.ts","../src/sync-lifecycle.ts","../src/transaction-executor.ts","../src/validate-config.ts","../src/wire-sync-event-forwarding.ts"],"sourcesContent":["// kora — meta-package re-exporting core, store, merge, sync\n// This is the primary entry point for `import { createApp, defineSchema, t } from 'korajs'`\n\n// === createApp factory ===\nexport { createApp } from './create-app'\n\n// === App types ===\nexport type {\n\tAdapterType,\n\tAuthSyncBinding,\n\tKoraApp,\n\tKoraConfig,\n\tStoreOptions,\n\tSyncControl,\n\tSyncOptions,\n\tSequenceAccessor,\n\tTransactionCollectionProxy,\n\tTransactionProxy,\n\tTypedCollectionAccessor,\n\tTypedKoraApp,\n\tTypedKoraConfig,\n} from './types'\n\nexport type { ReplaySnapshot } from '@korajs/store'\nexport type {\n\tAuditExportManifest,\n\tAuditExportOptions,\n\tAuditExportPayload,\n\tPersistedAuditTrace,\n} from '@korajs/store'\nexport {\n\tdecodeAuditExport,\n\treadAuditExportManifest,\n\tverifyAuditExportChecksum,\n} from '@korajs/store'\n\n// === @korajs/core re-exports ===\nexport { defineSchema, migrate, t } from '@korajs/core'\nexport { HybridLogicalClock } from '@korajs/core'\nexport { generateUUIDv7 } from '@korajs/core'\nexport { createOperation } from '@korajs/core'\nexport { KoraError, AppNotReadyError } from '@korajs/core'\nexport { op } from '@korajs/core'\nexport type {\n\tAtomicOp,\n\tAtomicOpType,\n\tCollectionDefinition,\n\tConnectionQuality,\n\tConstraint,\n\tFieldDescriptor,\n\tFieldKindToType,\n\tHLCTimestamp,\n\tInferFieldType,\n\tInferInsertInput,\n\tInferRecord,\n\tInferUpdateInput,\n\tKoraEvent,\n\tKoraEventEmitter,\n\tKoraEventListener,\n\tKoraEventType,\n\tMergeStrategy,\n\tMergeTrace,\n\tMigrationDefinition,\n\tMigrationStep,\n\tOperation,\n\tSchemaDefinition,\n\tSchemaInput,\n\tSequenceConfig,\n\tSyncRuleDefinition,\n\tTypedSchemaDefinition,\n\tVersionVector,\n} from '@korajs/core'\n\n// === @korajs/store re-exports ===\nexport { SequenceManager, Store } from '@korajs/store'\nexport { TransactionContext } from '@korajs/store'\nexport {\n\texportBackup,\n\treadBackupManifest,\n\trestoreBackup,\n\tverifyBackupChecksum,\n} from '@korajs/store'\nexport type {\n\tBackupManifest,\n\tBackupOptions,\n\tBackupProgress,\n\tCollectionAccessor,\n\tCollectionRecord,\n\tRestoreOptions,\n\tRestoreResult,\n\tStorageAdapter,\n\tStoreConfig,\n\tTransactionCollectionAccessor,\n\tTransactionContextConfig,\n} from '@korajs/store'\n\n// === @korajs/merge re-exports ===\nexport { MergeEngine } from '@korajs/merge'\nexport type { MergeInput, MergeResult } from '@korajs/merge'\n\n// === @korajs/sync re-exports ===\nexport { SyncEngine, WebSocketTransport } from '@korajs/sync'\nexport type {\n\tSyncConfig,\n\tSyncDiagnostics,\n\tSyncEncryptionConfig,\n\tSyncState,\n\tSyncStatus,\n\tSyncStatusInfo,\n\tSyncStore,\n} from '@korajs/sync'\n","import type { SchemaInput } from '@korajs/core'\nimport { SimpleEventEmitter } from '@korajs/core/internal'\nimport { MergeEngine } from '@korajs/merge'\nimport type { Store } from '@korajs/store'\nimport { QueryStoreCache } from '@korajs/store'\nimport type { SyncEngine } from '@korajs/sync'\nimport { createCollectionAccessor } from './collection-accessor'\nimport { initializeApp } from './initialize-app'\nimport { createSequencesAccessor } from './sequences-accessor'\nimport { setupDevtools } from './setup-devtools'\nimport { createSyncControl } from './sync-control'\nimport { type SyncRuntimeState, teardownSyncLifecycle, wireSyncLifecycleAfterReady } from './sync-lifecycle'\nimport { createTransactionExecutor } from './transaction-executor'\nimport type { KoraApp, KoraConfig, TypedKoraApp, TypedKoraConfig } from './types'\nimport { validateCreateAppConfig } from './validate-config'\nimport { wireSyncEventForwarding } from './wire-sync-event-forwarding'\n\n/**\n * Creates a new Kora application instance.\n *\n * Wires together store, merge engine, event emitter, and optionally sync\n * into a single developer-facing `KoraApp` object. Collection accessors\n * (e.g. `app.todos`) are defined as properties for immediate use after `await app.ready`.\n */\nexport function createApp<const S extends SchemaInput>(config: TypedKoraConfig<S>): TypedKoraApp<S>\nexport function createApp(config: KoraConfig): KoraApp\nexport function createApp<const S extends SchemaInput>(\n\tconfig: TypedKoraConfig<S> | KoraConfig,\n): TypedKoraApp<S> | KoraApp {\n\tvalidateCreateAppConfig(config)\n\n\tconst emitter = new SimpleEventEmitter()\n\tconst mergeEngine = new MergeEngine()\n\n\tif (config.onSyncEvent) {\n\t\twireSyncEventForwarding(emitter, config.onSyncEvent)\n\t}\n\n\tlet store: Store | null = null\n\tlet unsubscribeSync: (() => void) | null = null\n\tlet unsubscribeAudit: (() => void) | null = null\n\n\tconst syncState: SyncRuntimeState = {\n\t\tsyncEngine: null,\n\t\tsyncStatusBridge: null,\n\t\tauthSyncCoordinator: null,\n\t\treconnectionManager: null,\n\t\tconnectionMonitor: null,\n\t\tqualityInterval: null,\n\t\tintentionalDisconnect: false,\n\t\tremoveOnlineListener: null,\n\t}\n\n\tconst devtools = setupDevtools(config, emitter)\n\tconst queryStoreCache = new QueryStoreCache(config.store?.name ?? 'kora-db')\n\n\tconst ready = initializeApp(config, emitter, mergeEngine).then((init) => {\n\t\tstore = init.store\n\t\tunsubscribeSync = init.unsubscribeSync\n\t\tunsubscribeAudit = init.unsubscribeAudit\n\t\twireSyncLifecycleAfterReady(config, emitter, syncState, init)\n\t})\n\n\tconst getStore = (): Store | null => store\n\tconst executeTransaction = createTransactionExecutor(config, ready, getStore)\n\n\tconst app: KoraApp = {\n\t\tready,\n\t\tevents: emitter,\n\t\tsync: createSyncControl({ config, ready, state: syncState }),\n\t\tsequences: createSequencesAccessor(ready, getStore),\n\t\tgetStore(): Store {\n\t\t\tif (!store) {\n\t\t\t\tthrow new Error('Store not initialized. Await app.ready before accessing the store.')\n\t\t\t}\n\t\t\treturn store\n\t\t},\n\t\tgetSyncEngine(): SyncEngine | null {\n\t\t\treturn syncState.syncEngine\n\t\t},\n\t\tgetQueryStoreCache(): QueryStoreCache {\n\t\t\treturn queryStoreCache\n\t\t},\n\t\ttransaction(fn) {\n\t\t\treturn executeTransaction(fn)\n\t\t},\n\t\tmutation(name, fn) {\n\t\t\treturn executeTransaction(fn, name)\n\t\t},\n\t\tasync close() {\n\t\t\tawait ready\n\t\t\tsyncState.intentionalDisconnect = true\n\t\t\tteardownSyncLifecycle(syncState)\n\t\t\tdevtools.destroyOverlay?.()\n\t\t\tdevtools.instrumenter?.destroy()\n\t\t\tif (unsubscribeSync) {\n\t\t\t\tunsubscribeSync()\n\t\t\t\tunsubscribeSync = null\n\t\t\t}\n\t\t\tif (unsubscribeAudit) {\n\t\t\t\tunsubscribeAudit()\n\t\t\t\tunsubscribeAudit = null\n\t\t\t}\n\t\t\tif (syncState.syncEngine) {\n\t\t\t\tawait syncState.syncEngine.stop()\n\t\t\t\tsyncState.syncEngine = null\n\t\t\t}\n\t\t\tqueryStoreCache.clear()\n\t\t\tif (store) {\n\t\t\t\tawait store.close()\n\t\t\t\tstore = null\n\t\t\t}\n\t\t\temitter.clear()\n\t\t},\n\t\tasync exportBackup(options) {\n\t\t\tawait ready\n\t\t\tif (!store) {\n\t\t\t\tthrow new Error('Store not initialized. Await app.ready before exporting backup.')\n\t\t\t}\n\t\t\treturn store.exportBackup(options)\n\t\t},\n\t\tasync importBackup(data, options) {\n\t\t\tawait ready\n\t\t\tif (!store) {\n\t\t\t\tthrow new Error('Store not initialized. Await app.ready before importing backup.')\n\t\t\t}\n\t\t\treturn store.importBackup(data, options)\n\t\t},\n\t\tasync replayTo(operationId) {\n\t\t\tawait ready\n\t\t\tif (!store) {\n\t\t\t\tthrow new Error('Store not initialized. Await app.ready before replaying operations.')\n\t\t\t}\n\t\t\treturn store.replayTo(operationId)\n\t\t},\n\t\tasync exportAudit(options) {\n\t\t\tawait ready\n\t\t\tif (!store) {\n\t\t\t\tthrow new Error('Store not initialized. Await app.ready before exporting audit data.')\n\t\t\t}\n\t\t\treturn store.exportAudit(options)\n\t\t},\n\t}\n\n\tfor (const collectionName of Object.keys(config.schema.collections)) {\n\t\tObject.defineProperty(app, collectionName, {\n\t\t\tget() {\n\t\t\t\treturn createCollectionAccessor(collectionName, getStore)\n\t\t\t},\n\t\t\tenumerable: true,\n\t\t\tconfigurable: false,\n\t\t})\n\t}\n\n\treturn app\n}\n","import { AppNotReadyError } from '@korajs/core'\nimport type { CollectionAccessor, QueryBuilder, Store } from '@korajs/store'\n\n/**\n * Builds a collection accessor that throws {@link AppNotReadyError} until the store opens.\n */\nexport function createCollectionAccessor(\n\tcollectionName: string,\n\tgetStore: () => Store | null,\n): CollectionAccessor {\n\tconst notReady = (action: string): AppNotReadyError =>\n\t\tnew AppNotReadyError(\n\t\t\t`Cannot ${action} on collection \"${collectionName}\" before app.ready. Await app.ready or use <KoraProvider app={app}>.`,\n\t\t)\n\n\treturn {\n\t\tasync insert(data: Record<string, unknown>) {\n\t\t\tconst currentStore = getStore()\n\t\t\tif (!currentStore) {\n\t\t\t\tthrow notReady('insert into')\n\t\t\t}\n\t\t\treturn currentStore.collection(collectionName).insert(data)\n\t\t},\n\t\tasync findById(id: string) {\n\t\t\tconst currentStore = getStore()\n\t\t\tif (!currentStore) return null\n\t\t\treturn currentStore.collection(collectionName).findById(id)\n\t\t},\n\t\tasync update(id: string, data: Record<string, unknown>) {\n\t\t\tconst currentStore = getStore()\n\t\t\tif (!currentStore) {\n\t\t\t\tthrow notReady('update')\n\t\t\t}\n\t\t\treturn currentStore.collection(collectionName).update(id, data)\n\t\t},\n\t\tasync delete(id: string) {\n\t\t\tconst currentStore = getStore()\n\t\t\tif (!currentStore) {\n\t\t\t\tthrow notReady('delete from')\n\t\t\t}\n\t\t\treturn currentStore.collection(collectionName).delete(id)\n\t\t},\n\t\twhere(conditions: Record<string, unknown>): QueryBuilder {\n\t\t\tconst currentStore = getStore()\n\t\t\tif (!currentStore) {\n\t\t\t\tthrow notReady('query')\n\t\t\t}\n\t\t\treturn currentStore.collection(collectionName).where(conditions)\n\t\t},\n\t}\n}\n","import type { KoraEventEmitter } from '@korajs/core'\nimport { buildScopeMap } from '@korajs/core'\nimport type { MergeEngine } from '@korajs/merge'\nimport { Store } from '@korajs/store'\nimport type { StorageAdapter } from '@korajs/store'\nimport { SyncEncryptor, SyncEngine } from '@korajs/sync'\nimport { createAdapter, detectAdapterType } from './adapter-resolver'\nimport { ApplyPipeline } from './apply-pipeline'\nimport { wireAuditPersistence } from './audit-bridge'\nimport { createSyncTransport } from './create-sync-transport'\nimport { MergeAwareSyncStore } from './merge-aware-sync-store'\nimport { StoreQueueStorage } from './store-queue-storage'\nimport { StoreSyncStatePersistence } from './store-sync-state'\nimport { createSyncQuerySubscriptionHook } from './sync-query-bridge'\nimport type { AuthSyncBinding, KoraConfig } from './types'\n\n/** Result of opening the local store and optionally constructing a sync engine. */\nexport interface InitializeAppResult {\n\tstore: Store\n\tsyncEngine: SyncEngine | null\n\tunsubscribeSync: (() => void) | null\n\tunsubscribeAudit: (() => void) | null\n\tauthBinding: AuthSyncBinding | null\n}\n\n/**\n * Opens the local store, wires apply/audit pipelines, and optionally constructs sync.\n */\nexport async function initializeApp(\n\tconfig: KoraConfig,\n\temitter: KoraEventEmitter,\n\tmergeEngine: MergeEngine,\n): Promise<InitializeAppResult> {\n\tconst adapterType = config.store?.adapter ?? detectAdapterType()\n\tconst dbName = config.store?.name ?? 'kora-db'\n\tconst adapter: StorageAdapter = await createAdapter(\n\t\tadapterType,\n\t\tdbName,\n\t\tconfig.store?.workerUrl,\n\t\temitter,\n\t\tconfig.store?.workerResponseTimeoutMs,\n\t\tconfig.store?.sharedWorkerUrl,\n\t)\n\n\tconst authBinding = config.sync?.authClient ?? null\n\tconst authNodeId = authBinding?.resolveNodeId ? await authBinding.resolveNodeId() : undefined\n\n\tlet syncEngine: SyncEngine | null = null\n\n\tconst store = new Store({\n\t\tschema: config.schema,\n\t\tadapter,\n\t\temitter,\n\t\tdbName,\n\t\tnodeId: authNodeId,\n\t\tisolation: authNodeId ? 'shared' : config.store?.isolation,\n\t\t...(config.sync ? { onQuerySubscribed: createSyncQuerySubscriptionHook(() => syncEngine) } : {}),\n\t})\n\tawait store.open()\n\n\tlet recordConflict: (() => void) | undefined\n\tconst applyPipeline = new ApplyPipeline({\n\t\tstore,\n\t\tmergeEngine,\n\t\temitter,\n\t\tonMergeConflict: () => recordConflict?.(),\n\t})\n\tstore.setLocalMutationHandler(applyPipeline)\n\tconst unsubscribeAudit = wireAuditPersistence(store, emitter)\n\n\tlet unsubscribeSync: (() => void) | null = null\n\n\tif (config.sync) {\n\t\tconst transport = createSyncTransport(config.sync)\n\t\tconst mergeAwareStore = new MergeAwareSyncStore(store, mergeEngine, emitter, {\n\t\t\tonMergeConflict: () => recordConflict?.(),\n\t\t})\n\n\t\tlet scopeMap = config.sync.scope ? buildScopeMap(config.schema, config.sync.scope) : undefined\n\t\tif (authBinding?.resolveScopeMap) {\n\t\t\tscopeMap = (await authBinding.resolveScopeMap()) ?? scopeMap\n\t\t}\n\n\t\tconst syncAuth = authBinding?.auth ?? config.sync.auth\n\n\t\tconst encryptor =\n\t\t\tconfig.sync.encryption?.enabled === true\n\t\t\t\t? await SyncEncryptor.create(config.sync.encryption)\n\t\t\t\t: undefined\n\n\t\tsyncEngine = new SyncEngine({\n\t\t\ttransport,\n\t\t\tstore: mergeAwareStore,\n\t\t\tconfig: {\n\t\t\t\turl: config.sync.url,\n\t\t\t\ttransport: config.sync.transport,\n\t\t\t\tauth: syncAuth,\n\t\t\t\tbatchSize: config.sync.batchSize,\n\t\t\t\tschemaVersion: config.sync.schemaVersion ?? config.schema.version,\n\t\t\t\tscopeMap,\n\t\t\t\tencryption: config.sync.encryption,\n\t\t\t\tstrictHandshake: config.sync.strictHandshake,\n\t\t\t\toperationTransforms: config.sync.operationTransforms,\n\t\t\t},\n\t\t\temitter,\n\t\t\tqueueStorage: new StoreQueueStorage(adapter),\n\t\t\tsyncState: new StoreSyncStatePersistence(store, scopeMap),\n\t\t\tencryptor,\n\t\t})\n\t\trecordConflict = () => syncEngine?.recordConflict()\n\n\t\tunsubscribeSync = emitter.on('operation:created', (event) => {\n\t\t\tif (syncEngine) {\n\t\t\t\tsyncEngine.pushOperation(event.operation)\n\t\t\t}\n\t\t})\n\t}\n\n\treturn {\n\t\tstore,\n\t\tsyncEngine,\n\t\tunsubscribeSync,\n\t\tunsubscribeAudit,\n\t\tauthBinding,\n\t}\n}\n","import type { KoraEventEmitter } from '@korajs/core'\nimport type { StorageAdapter } from '@korajs/store'\nimport type { AdapterType } from './types'\n\n/** Dynamic import that bundlers cannot statically analyze (optional peer packages). */\nfunction importOptionalPeer<T>(specifier: string): Promise<T> {\n\tconst dynamicImport = new Function('specifier', 'return import(specifier)') as (\n\t\ts: string,\n\t) => Promise<T>\n\treturn dynamicImport(specifier)\n}\n\n/**\n * Detect the best storage adapter for the current environment.\n *\n * - Tauri app: 'tauri-sqlite' (native SQLite via Tauri plugin)\n * - Node.js: 'better-sqlite3'\n * - Browser with OPFS: 'sqlite-wasm'\n * - Browser without OPFS: 'indexeddb'\n */\nexport function detectAdapterType(): AdapterType {\n\t// Tauri environment — detected via __TAURI_INTERNALS__ injected by the Tauri runtime\n\tif (\n\t\ttypeof globalThis !== 'undefined' &&\n\t\ttypeof (globalThis as Record<string, unknown>).__TAURI_INTERNALS__ !== 'undefined'\n\t) {\n\t\treturn 'tauri-sqlite'\n\t}\n\n\t// Node.js environment\n\tif (typeof process !== 'undefined' && process.versions?.node) {\n\t\treturn 'better-sqlite3'\n\t}\n\n\t// Browser environment\n\tif (typeof globalThis.navigator !== 'undefined') {\n\t\t// Check for OPFS support (FileSystemHandle indicates OPFS availability)\n\t\tif (typeof (globalThis as Record<string, unknown>).FileSystemHandle !== 'undefined') {\n\t\t\treturn 'sqlite-wasm'\n\t\t}\n\t\treturn 'indexeddb'\n\t}\n\n\t// Default fallback (e.g., Deno, Bun, or other runtimes)\n\treturn 'better-sqlite3'\n}\n\n/**\n * Create a StorageAdapter for the given adapter type.\n * Uses dynamic imports so unused adapters are not bundled.\n *\n * @param type - The adapter type to create\n * @param dbName - Database name (used by all adapters)\n * @returns A configured StorageAdapter instance\n */\nexport async function createAdapter(\n\ttype: AdapterType,\n\tdbName: string,\n\tworkerUrl?: string | URL,\n\temitter?: KoraEventEmitter,\n\tworkerResponseTimeoutMs?: number,\n\tsharedWorkerUrl?: string | URL,\n): Promise<StorageAdapter> {\n\tswitch (type) {\n\t\tcase 'tauri-sqlite': {\n\t\t\t// @korajs/tauri is only installed in Tauri projects (optional peer dep).\n\t\t\t// Runtime import via Function so Vite/Rollup do not pre-bundle or resolve the module.\n\t\t\tconst { TauriSqliteAdapter } = await importOptionalPeer<{\n\t\t\t\tTauriSqliteAdapter: new (options: { path: string }) => StorageAdapter\n\t\t\t}>('@korajs/tauri')\n\t\t\treturn new TauriSqliteAdapter({ path: `${dbName}.db` })\n\t\t}\n\t\tcase 'better-sqlite3': {\n\t\t\tconst { BetterSqlite3Adapter } = await import(\n\t\t\t\t/* @vite-ignore */ '@korajs/store/better-sqlite3'\n\t\t\t)\n\t\t\treturn new BetterSqlite3Adapter(dbName)\n\t\t}\n\t\tcase 'sqlite-wasm': {\n\t\t\tconst { SqliteWasmAdapter } = await import('@korajs/store/sqlite-wasm')\n\t\t\treturn new SqliteWasmAdapter({ dbName, workerUrl, sharedWorkerUrl, workerResponseTimeoutMs })\n\t\t}\n\t\tcase 'indexeddb': {\n\t\t\tconst { IndexedDbAdapter } = await import('@korajs/store/indexeddb')\n\t\t\treturn new IndexedDbAdapter({ dbName, workerUrl, emitter, workerResponseTimeoutMs })\n\t\t}\n\t\tdefault: {\n\t\t\tconst _exhaustive: never = type\n\t\t\tthrow new Error(`Unknown adapter type: ${_exhaustive}`)\n\t\t}\n\t}\n}\n","import type {\n\tCollectionDefinition,\n\tHLCTimestamp,\n\tKoraEventEmitter,\n\tOperation,\n\tSchemaDefinition,\n} from '@korajs/core'\nimport { HybridLogicalClock, KoraError, createOperation } from '@korajs/core'\nimport { topologicalSort } from '@korajs/core/internal'\nimport type { MergeEngine, MergeResult, ReferentialMergeContext, SideEffectOp } from '@korajs/merge'\nimport { buildMergeRelationLookup, checkReferentialIntegrityOnDelete } from '@korajs/merge'\nimport type { ConstraintContext } from '@korajs/merge'\nimport type {\n\tApplyRemoteOptions,\n\tCollectionRecord,\n\tLocalMutationHandler,\n\tStore,\n\tTransactionCommitBatch,\n\tTransactionCommitResult,\n} from '@korajs/store'\nimport { richtextStatesEqual } from '@korajs/store'\nimport {\n\texecuteDelete,\n\texecuteInsert,\n\texecuteUpdate,\n\tresolveCausalDeps,\n} from '@korajs/store/internal'\nimport type { ApplyResult } from '@korajs/sync'\nimport { buildSideEffectEntry } from './build-side-effect-entry'\n\n/**\n * Whether the operation originated locally or arrived from sync.\n */\nexport type ApplyMode = 'local' | 'remote'\n\n/**\n * Dependencies for the unified apply pipeline.\n */\nexport interface ApplyPipelineDeps {\n\treadonly store: Store\n\treadonly mergeEngine: MergeEngine\n\treadonly emitter: KoraEventEmitter | null\n\t/** Called when a field-level merge runs (updates sync conflict counter). */\n\treadonly onMergeConflict?: () => void\n}\n\n/**\n * Context passed into each apply invocation.\n */\nexport interface ApplyContext {\n\treadonly mode: ApplyMode\n\treadonly schema: SchemaDefinition\n}\n\n/**\n * Single entry point for applying remote sync operations with merge + referential integrity.\n */\nexport class ApplyPipeline implements LocalMutationHandler {\n\tprivate readonly relationLookupMap: ReturnType<typeof buildMergeRelationLookup>\n\n\tconstructor(private readonly deps: ApplyPipelineDeps) {\n\t\tthis.relationLookupMap = buildMergeRelationLookup(deps.store.getSchema())\n\t}\n\n\t/** Local insert — same persistence path as remote apply side effects. */\n\tasync insert(collection: string, data: Record<string, unknown>): Promise<CollectionRecord> {\n\t\treturn executeInsert(this.deps.store.createMutationContext(collection), data)\n\t}\n\n\t/** Local update. */\n\tasync update(\n\t\tcollection: string,\n\t\tid: string,\n\t\tdata: Record<string, unknown>,\n\t): Promise<CollectionRecord> {\n\t\treturn executeUpdate(this.deps.store.createMutationContext(collection), id, data)\n\t}\n\n\t/**\n\t * Local delete with merge-package referential integrity (same rules as remote delete).\n\t */\n\tasync delete(collection: string, id: string): Promise<void> {\n\t\tconst ctx = this.deps.store.createMutationContext(collection)\n\t\tconst causalDeps = resolveCausalDeps(ctx)\n\t\tconst operation = await createOperation(\n\t\t\t{\n\t\t\t\tnodeId: ctx.nodeId,\n\t\t\t\ttype: 'delete',\n\t\t\t\tcollection,\n\t\t\t\trecordId: id,\n\t\t\t\tdata: null,\n\t\t\t\tpreviousData: null,\n\t\t\t\tsequenceNumber: await ctx.allocateSequenceNumber(),\n\t\t\t\tcausalDeps,\n\t\t\t\tschemaVersion: ctx.schema.version,\n\t\t\t},\n\t\t\tctx.clock,\n\t\t)\n\t\tctx.causalTracker?.afterOperation(collection, operation.id, ctx.inTransaction)\n\n\t\tconst refCtx = createReferentialMergeContext(this.deps.store)\n\t\tconst check = await checkReferentialIntegrityOnDelete(\n\t\t\toperation,\n\t\t\tthis.deps.store.getSchema(),\n\t\t\trefCtx,\n\t\t\tthis.relationLookupMap,\n\t\t)\n\n\t\tfor (const trace of check.traces) {\n\t\t\tthis.deps.emitter?.emit({ type: 'merge:conflict', trace })\n\t\t}\n\n\t\tif (!check.allowed) {\n\t\t\tthrow new KoraError(\n\t\t\t\t`Cannot delete record \"${id}\" from \"${collection}\": referential restrict policy violated`,\n\t\t\t\t'REFERENTIAL_INTEGRITY',\n\t\t\t\t{ collection, recordId: id },\n\t\t\t)\n\t\t}\n\n\t\tawait executeDelete(ctx, id, {\n\t\t\tskipReferentialEnforcement: true,\n\t\t\toperation,\n\t\t})\n\n\t\tif (check.sideEffectOps.length > 0) {\n\t\t\tawait applySideEffectOps(this.deps.store, check.sideEffectOps, operation.id)\n\t\t}\n\t}\n\n\t/**\n\t * Commit a buffered transaction: merge-package delete enforcement, causal ordering, single DB txn.\n\t */\n\tasync commitTransaction(batch: TransactionCommitBatch): Promise<TransactionCommitResult> {\n\t\tconst store = this.deps.store\n\t\tconst supplemental: TransactionCommitBatch['entries'] = []\n\n\t\tfor (const entry of batch.entries) {\n\t\t\tif (entry.operation.type !== 'delete') {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst refCtx = createReferentialMergeContext(store)\n\t\t\tconst check = await checkReferentialIntegrityOnDelete(\n\t\t\t\tentry.operation,\n\t\t\t\tstore.getSchema(),\n\t\t\t\trefCtx,\n\t\t\t\tthis.relationLookupMap,\n\t\t\t)\n\n\t\t\tfor (const trace of check.traces) {\n\t\t\t\tthis.deps.emitter?.emit({ type: 'merge:conflict', trace })\n\t\t\t}\n\n\t\t\tif (!check.allowed) {\n\t\t\t\tthrow new KoraError(\n\t\t\t\t\t`Cannot delete record \"${entry.operation.recordId}\" from \"${entry.collection}\": referential restrict policy violated`,\n\t\t\t\t\t'REFERENTIAL_INTEGRITY',\n\t\t\t\t\t{ collection: entry.collection, recordId: entry.operation.recordId },\n\t\t\t\t)\n\t\t\t}\n\n\t\t\tfor (const effect of check.sideEffectOps) {\n\t\t\t\tconst ctx = store.createMutationContext(effect.collection, { inTransaction: true })\n\t\t\t\tsupplemental.push(\n\t\t\t\t\tawait buildSideEffectEntry(\n\t\t\t\t\t\tctx,\n\t\t\t\t\t\teffect,\n\t\t\t\t\t\tentry.operation.id,\n\t\t\t\t\t\tbatch.transactionId,\n\t\t\t\t\t\tbatch.mutationName,\n\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\n\t\tconst allEntries = [...batch.entries, ...supplemental]\n\t\tconst sortedOps = topologicalSort(allEntries.map((e) => e.operation))\n\t\tconst commandsByOpId = new Map(allEntries.map((e) => [e.operation.id, e.commands] as const))\n\n\t\tconst ctx = store.createMutationContext(\n\t\t\tbatch.entries[0]?.collection ?? Object.keys(store.getSchema().collections)[0] ?? 'todos',\n\t\t\t{ inTransaction: true },\n\t\t)\n\n\t\tawait ctx.adapter.transaction(async (tx) => {\n\t\t\tfor (const op of sortedOps) {\n\t\t\t\tconst commands = commandsByOpId.get(op.id)\n\t\t\t\tif (!commands) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tfor (const cmd of commands) {\n\t\t\t\t\tawait tx.execute(cmd.sql, cmd.params)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\n\t\tconst affectedCollections = new Set<string>()\n\t\tfor (const entry of allEntries) {\n\t\t\taffectedCollections.add(entry.collection)\n\t\t}\n\n\t\treturn { operations: sortedOps, affectedCollections }\n\t}\n\n\tasync applyRemote(op: Operation): Promise<ApplyResult> {\n\t\treturn this.apply(op, { mode: 'remote', schema: this.deps.store.getSchema() })\n\t}\n\n\tasync apply(op: Operation, context: ApplyContext): Promise<ApplyResult> {\n\t\tif (context.mode === 'local') {\n\t\t\treturn this.deps.store.applyRemoteOperation(op)\n\t\t}\n\n\t\tif (op.type === 'delete') {\n\t\t\treturn this.applyRemoteDelete(op)\n\t\t}\n\n\t\tif (op.type === 'insert' && op.data) {\n\t\t\treturn this.applyRemoteInsert(op)\n\t\t}\n\n\t\tif (op.type === 'update' && op.data && op.previousData) {\n\t\t\treturn this.applyRemoteUpdate(op)\n\t\t}\n\n\t\treturn this.deps.store.applyRemoteOperation(op)\n\t}\n\n\tprivate async applyRemoteDelete(op: Operation): Promise<ApplyResult> {\n\t\tconst blocked = await this.resolveRemoteDeleteVsLocalUpdate(op)\n\t\tif (blocked) {\n\t\t\treturn 'skipped'\n\t\t}\n\n\t\tconst refCtx = createReferentialMergeContext(this.deps.store)\n\t\tconst check = await checkReferentialIntegrityOnDelete(\n\t\t\top,\n\t\t\tthis.deps.store.getSchema(),\n\t\t\trefCtx,\n\t\t\tthis.relationLookupMap,\n\t\t)\n\n\t\tfor (const trace of check.traces) {\n\t\t\tthis.deps.emitter?.emit({ type: 'merge:conflict', trace })\n\t\t}\n\n\t\tif (!check.allowed) {\n\t\t\treturn 'rejected'\n\t\t}\n\n\t\tconst result = await this.deps.store.applyRemoteOperation(op)\n\t\tif (result !== 'applied') {\n\t\t\treturn result\n\t\t}\n\n\t\tif (check.sideEffectOps.length > 0) {\n\t\t\tawait applySideEffectOps(this.deps.store, check.sideEffectOps, op.id)\n\t\t}\n\n\t\treturn 'applied'\n\t}\n\n\t/**\n\t * When a local update is newer than a remote delete, keep the record alive.\n\t */\n\tprivate async resolveRemoteDeleteVsLocalUpdate(op: Operation): Promise<boolean> {\n\t\tconst collectionDef = this.deps.store.getSchema().collections[op.collection]\n\t\tif (!collectionDef) {\n\t\t\treturn false\n\t\t}\n\n\t\tconst localOp = await this.deps.store.getLatestLocalOperationForRecord(\n\t\t\top.collection,\n\t\t\top.recordId,\n\t\t)\n\t\tif (!localOp || localOp.type !== 'update') {\n\t\t\treturn false\n\t\t}\n\n\t\tconst baseState = localOp.previousData ?? {}\n\t\tconst mergeResult = await this.deps.mergeEngine.merge({\n\t\t\tlocal: localOp,\n\t\t\tremote: op,\n\t\t\tbaseState,\n\t\t\tcollectionDef,\n\t\t})\n\n\t\tthis.emitMergeLifecycle(op, localOp, mergeResult)\n\n\t\treturn mergeResult.appliedOperation === 'local'\n\t}\n\n\tprivate async applyRemoteUpdate(op: Operation): Promise<ApplyResult> {\n\t\tconst schema = this.deps.store.getSchema()\n\t\tconst collectionDef = schema.collections[op.collection]\n\t\tif (!collectionDef) {\n\t\t\treturn this.deps.store.applyRemoteOperation(op)\n\t\t}\n\n\t\tconst accessor = this.deps.store.collection(op.collection)\n\t\tconst currentRecord = await accessor.findById(op.recordId)\n\n\t\tif (!currentRecord) {\n\t\t\tconst tombstoneResult = await this.applyRemoteUpdateOnDeletedRow(op, collectionDef)\n\t\t\tif (tombstoneResult !== null) {\n\t\t\t\treturn tombstoneResult\n\t\t\t}\n\t\t\treturn this.deps.store.applyRemoteOperation(op)\n\t\t}\n\n\t\tlet hasConflict = false\n\t\tfor (const field of Object.keys(op.data ?? {})) {\n\t\t\tconst fieldDef = collectionDef.fields[field]\n\t\t\tconst expectedBase = op.previousData?.[field]\n\t\t\tconst currentLocal = currentRecord[field]\n\n\t\t\tif (fieldDef?.kind === 'richtext') {\n\t\t\t\tif (!richtextStatesEqual(currentLocal, expectedBase)) {\n\t\t\t\t\thasConflict = true\n\t\t\t\t}\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (!deepEqual(expectedBase, currentLocal)) {\n\t\t\t\thasConflict = true\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\tif (!hasConflict) {\n\t\t\treturn this.deps.store.applyRemoteOperation(op)\n\t\t}\n\n\t\treturn this.applyMergedUpdate(op, collectionDef, currentRecord, op.previousData ?? {})\n\t}\n\n\t/**\n\t * Remote update vs local soft-delete: merge before materializing to avoid zombie rows.\n\t */\n\tprivate async applyRemoteUpdateOnDeletedRow(\n\t\top: Operation,\n\t\tcollectionDef: CollectionDefinition,\n\t): Promise<ApplyResult | null> {\n\t\tconst snapshot = await this.deps.store.findMaterializedRow(op.collection, op.recordId)\n\t\tif (!snapshot?.deleted) {\n\t\t\treturn null\n\t\t}\n\n\t\tconst localOp = await this.deps.store.getLatestLocalOperationForRecord(\n\t\t\top.collection,\n\t\t\top.recordId,\n\t\t)\n\t\tif (!localOp || localOp.type !== 'delete') {\n\t\t\treturn null\n\t\t}\n\n\t\tconst mergeResult = await this.deps.mergeEngine.merge({\n\t\t\tlocal: localOp,\n\t\t\tremote: op,\n\t\t\tbaseState: op.previousData ?? {},\n\t\t\tcollectionDef,\n\t\t})\n\n\t\tthis.emitMergeLifecycle(op, localOp, mergeResult)\n\n\t\tif (mergeResult.appliedOperation === 'local') {\n\t\t\treturn 'skipped'\n\t\t}\n\n\t\tconst mergedOp: Operation = {\n\t\t\t...op,\n\t\t\tdata: { ...mergeResult.mergedData },\n\t\t\ttimestamp: maxTimestamp(op.timestamp, localOp.timestamp),\n\t\t}\n\n\t\tconst applyResult = await this.deps.store.applyRemoteOperation(mergedOp, {\n\t\t\treactivateIfDeleted: true,\n\t\t})\n\n\t\tif (applyResult === 'applied' && mergeResult.sideEffects.length > 0) {\n\t\t\tawait applySideEffectOps(this.deps.store, mergeResult.sideEffects, op.id)\n\t\t}\n\n\t\treturn applyResult\n\t}\n\n\tprivate async applyMergedUpdate(\n\t\top: Operation,\n\t\tcollectionDef: CollectionDefinition,\n\t\tcurrentRecord: CollectionRecord,\n\t\tbaseState: Record<string, unknown>,\n\t\tapplyOptions?: ApplyRemoteOptions,\n\t): Promise<ApplyResult> {\n\t\tconst localTimestamp = await resolveLocalTimestamp(\n\t\t\tthis.deps.store,\n\t\t\top.collection,\n\t\t\top.recordId,\n\t\t\tcurrentRecord,\n\t\t\tthis.deps.store.getNodeId(),\n\t\t)\n\t\tconst localOp: Operation = {\n\t\t\t...op,\n\t\t\tdata: buildLocalDiff(baseState, currentRecord, Object.keys(op.data ?? {})),\n\t\t\tpreviousData: op.previousData,\n\t\t\tnodeId: this.deps.store.getNodeId(),\n\t\t\ttimestamp: localTimestamp,\n\t\t}\n\n\t\tconst constraintContext = createConstraintContext(this.deps.store)\n\t\tconst mergeResult = await this.deps.mergeEngine.merge(\n\t\t\t{\n\t\t\t\tlocal: localOp,\n\t\t\t\tremote: op,\n\t\t\t\tbaseState,\n\t\t\t\tcollectionDef,\n\t\t\t},\n\t\t\tconstraintContext,\n\t\t)\n\n\t\tthis.emitMergeLifecycle(op, localOp, mergeResult)\n\n\t\tconst mergedOp: Operation = {\n\t\t\t...op,\n\t\t\tdata: mergeResult.mergedData,\n\t\t\ttimestamp: maxTimestamp(op.timestamp, localTimestamp),\n\t\t}\n\n\t\tconst applyResult = await this.deps.store.applyRemoteOperation(mergedOp, applyOptions)\n\n\t\tif (applyResult === 'applied' && mergeResult.sideEffects.length > 0) {\n\t\t\tawait applySideEffectOps(this.deps.store, mergeResult.sideEffects, op.id)\n\t\t}\n\n\t\treturn applyResult\n\t}\n\n\tprivate async applyRemoteInsert(op: Operation): Promise<ApplyResult> {\n\t\tconst collectionDef = this.deps.store.getSchema().collections[op.collection]\n\t\tif (!collectionDef || !op.data) {\n\t\t\treturn this.deps.store.applyRemoteOperation(op)\n\t\t}\n\n\t\tconst snapshot = await this.deps.store.findMaterializedRow(op.collection, op.recordId)\n\t\tif (!snapshot || snapshot.deleted) {\n\t\t\treturn this.deps.store.applyRemoteOperation(op)\n\t\t}\n\n\t\tconst localOp = await resolveLocalOpForRecord(\n\t\t\tthis.deps.store,\n\t\t\top.collection,\n\t\t\top.recordId,\n\t\t\tsnapshot.record,\n\t\t)\n\n\t\tconst mergeResult = await this.deps.mergeEngine.merge({\n\t\t\tlocal: localOp,\n\t\t\tremote: op,\n\t\t\tbaseState: {},\n\t\t\tcollectionDef,\n\t\t})\n\n\t\tthis.emitMergeLifecycle(op, localOp, mergeResult)\n\n\t\tconst mergedOp: Operation = {\n\t\t\t...op,\n\t\t\tdata: mergeResult.mergedData,\n\t\t\ttimestamp: maxTimestamp(op.timestamp, localOp.timestamp),\n\t\t}\n\n\t\treturn this.deps.store.applyRemoteOperation(mergedOp)\n\t}\n\n\tprivate emitMergeLifecycle(remote: Operation, local: Operation, mergeResult: MergeResult): void {\n\t\tthis.deps.emitter?.emit({\n\t\t\ttype: 'merge:started',\n\t\t\toperationA: remote,\n\t\t\toperationB: local,\n\t\t})\n\n\t\tconst hadMergeConflict = mergeResult.traces.some(\n\t\t\t(t) =>\n\t\t\t\tt.strategy !== 'no-conflict-local' &&\n\t\t\t\tt.strategy !== 'no-conflict-remote' &&\n\t\t\t\tt.strategy !== 'no-conflict-unchanged',\n\t\t)\n\t\tif (hadMergeConflict) {\n\t\t\tthis.deps.onMergeConflict?.()\n\t\t}\n\n\t\tfor (const trace of mergeResult.traces) {\n\t\t\tif (\n\t\t\t\ttrace.strategy !== 'no-conflict-local' &&\n\t\t\t\ttrace.strategy !== 'no-conflict-remote' &&\n\t\t\t\ttrace.strategy !== 'no-conflict-unchanged'\n\t\t\t) {\n\t\t\t\tthis.deps.emitter?.emit({ type: 'merge:conflict', trace })\n\t\t\t}\n\t\t}\n\t\tconst firstTrace = mergeResult.traces[0]\n\t\tif (firstTrace) {\n\t\t\tthis.deps.emitter?.emit({ type: 'merge:completed', trace: firstTrace })\n\t\t}\n\t}\n}\n\n/**\n * Prefer the latest local op, then any op in the log for this record, then a snapshot-derived insert.\n */\nasync function resolveLocalOpForRecord(\n\tstore: Store,\n\tcollection: string,\n\trecordId: string,\n\trecord: CollectionRecord,\n): Promise<Operation> {\n\tconst localLatest = await store.getLatestLocalOperationForRecord(collection, recordId)\n\tif (localLatest) {\n\t\treturn localLatest\n\t}\n\n\tconst anyLatest = await store.getLatestOperationForRecord(collection, recordId)\n\tif (anyLatest) {\n\t\treturn anyLatest\n\t}\n\n\treturn syntheticInsertFromSnapshot(\n\t\trecord,\n\t\tcollection,\n\t\tstore.getNodeId(),\n\t\tstore.getSchema().version,\n\t)\n}\n\nfunction syntheticInsertFromSnapshot(\n\trecord: CollectionRecord,\n\tcollection: string,\n\tnodeId: string,\n\tschemaVersion: number,\n): Operation {\n\tconst { id, createdAt, updatedAt, ...fields } = record\n\treturn {\n\t\tid: `synthetic-local-${id}`,\n\t\tnodeId,\n\t\ttype: 'insert',\n\t\tcollection,\n\t\trecordId: id,\n\t\tdata: fields,\n\t\tpreviousData: null,\n\t\ttimestamp: { wallTime: updatedAt, logical: 0, nodeId },\n\t\tsequenceNumber: 0,\n\t\tcausalDeps: [],\n\t\tschemaVersion,\n\t}\n}\n\nfunction createConstraintContext(store: Store): ConstraintContext {\n\treturn {\n\t\tasync queryRecords(collection: string, where: Record<string, unknown>) {\n\t\t\tconst rows = await store.collection(collection).where(where).exec()\n\t\t\treturn rows as Record<string, unknown>[]\n\t\t},\n\t\tasync countRecords(collection: string, where: Record<string, unknown>) {\n\t\t\treturn store.collection(collection).where(where).count()\n\t\t},\n\t}\n}\n\nfunction createReferentialMergeContext(store: Store): ReferentialMergeContext {\n\treturn {\n\t\tasync queryRecords(collection: string, where: Record<string, unknown>) {\n\t\t\tconst rows = await store.collection(collection).where(where).exec()\n\t\t\treturn rows as Record<string, unknown>[]\n\t\t},\n\t\tasync recordExists(collection: string, recordId: string) {\n\t\t\tconst row = await store.collection(collection).findById(recordId)\n\t\t\treturn row !== null\n\t\t},\n\t}\n}\n\nasync function applySideEffectOps(\n\tstore: Store,\n\tsideEffects: SideEffectOp[],\n\tparentOpId: string,\n): Promise<void> {\n\tfor (const effect of sideEffects) {\n\t\tconst ctx = store.createMutationContext(effect.collection, {\n\t\t\textraCausalDeps: [parentOpId],\n\t\t})\n\t\tif (effect.type === 'delete') {\n\t\t\tawait executeDelete(ctx, effect.recordId, { skipReferentialEnforcement: true })\n\t\t} else if (effect.type === 'update' && effect.data) {\n\t\t\tawait executeUpdate(ctx, effect.recordId, effect.data)\n\t\t}\n\t}\n}\n\nfunction buildLocalDiff(\n\tbaseState: Record<string, unknown>,\n\tcurrentRecord: Record<string, unknown>,\n\tfields: string[],\n): Record<string, unknown> {\n\tconst diff: Record<string, unknown> = {}\n\tfor (const field of fields) {\n\t\tdiff[field] = currentRecord[field]\n\t}\n\treturn diff\n}\n\nasync function resolveLocalTimestamp(\n\tstore: Store,\n\tcollection: string,\n\trecordId: string,\n\tcurrentRecord: CollectionRecord,\n\tnodeId: string,\n): Promise<HLCTimestamp> {\n\tconst latestLocal = await store.getLatestLocalOperationForRecord(collection, recordId)\n\tif (latestLocal) {\n\t\treturn latestLocal.timestamp\n\t}\n\tconst updatedAt = currentRecord.updatedAt\n\tif (typeof updatedAt === 'number') {\n\t\treturn { wallTime: updatedAt, logical: 0, nodeId }\n\t}\n\treturn { wallTime: Date.now(), logical: 0, nodeId }\n}\n\nfunction maxTimestamp(a: HLCTimestamp, b: HLCTimestamp): HLCTimestamp {\n\treturn HybridLogicalClock.compare(a, b) >= 0 ? a : b\n}\n\nfunction deepEqual(a: unknown, b: unknown): boolean {\n\tif (a === b) return true\n\tif (a === null || b === null) return false\n\tif (a === undefined || b === undefined) return false\n\tif (typeof a !== typeof b) return false\n\n\tif (Array.isArray(a) && Array.isArray(b)) {\n\t\tif (a.length !== b.length) return false\n\t\treturn a.every((val, i) => deepEqual(val, b[i]))\n\t}\n\n\tif (typeof a === 'object' && typeof b === 'object') {\n\t\tconst keysA = Object.keys(a as Record<string, unknown>)\n\t\tconst keysB = Object.keys(b as Record<string, unknown>)\n\t\tif (keysA.length !== keysB.length) return false\n\t\treturn keysA.every((key) =>\n\t\t\tdeepEqual((a as Record<string, unknown>)[key], (b as Record<string, unknown>)[key]),\n\t\t)\n\t}\n\n\treturn false\n}\n","import { createOperation } from '@korajs/core'\nimport type { SideEffectOp } from '@korajs/merge'\nimport type { TransactionBufferedEntry } from '@korajs/store'\nimport type { LocalMutationContext } from '@korajs/store/internal'\nimport {\n\tbuildInsertQuery,\n\tbuildSoftDeleteQuery,\n\tbuildUpdateQuery,\n\tserializeOperation,\n\tserializeRecord,\n\tserializeRowVersion,\n} from '@korajs/store/internal'\n\n/**\n * Materialize a merge-package referential side effect as an operation log entry + SQL commands.\n */\nexport async function buildSideEffectEntry(\n\tctx: LocalMutationContext,\n\teffect: SideEffectOp,\n\tparentOpId: string,\n\ttransactionId?: string,\n\tmutationName?: string,\n): Promise<TransactionBufferedEntry> {\n\tconst causalDeps = [parentOpId]\n\tconst baseInput = {\n\t\tnodeId: ctx.nodeId,\n\t\tcollection: effect.collection,\n\t\trecordId: effect.recordId,\n\t\tsequenceNumber: await ctx.allocateSequenceNumber(),\n\t\tcausalDeps,\n\t\tschemaVersion: ctx.schema.version,\n\t\t...(transactionId !== undefined ? { transactionId } : {}),\n\t\t...(mutationName !== undefined ? { mutationName } : {}),\n\t}\n\n\tif (effect.type === 'delete') {\n\t\tconst operation = await createOperation(\n\t\t\t{\n\t\t\t\t...baseInput,\n\t\t\t\ttype: 'delete',\n\t\t\t\tdata: null,\n\t\t\t\tpreviousData: effect.previousData,\n\t\t\t},\n\t\t\tctx.clock,\n\t\t)\n\t\tctx.causalTracker?.afterOperation(effect.collection, operation.id, ctx.inTransaction)\n\n\t\tconst version = serializeRowVersion(operation.timestamp)\n\t\tconst deleteQuery = buildSoftDeleteQuery(\n\t\t\teffect.collection,\n\t\t\teffect.recordId,\n\t\t\toperation.timestamp.wallTime,\n\t\t\tversion,\n\t\t)\n\t\tconst opInsert = buildInsertQuery(\n\t\t\t`_kora_ops_${effect.collection}`,\n\t\t\tserializeOperation(operation) as unknown as Record<string, unknown>,\n\t\t)\n\n\t\treturn {\n\t\t\toperation,\n\t\t\tcollection: effect.collection,\n\t\t\tcommands: [\n\t\t\t\t{ sql: deleteQuery.sql, params: deleteQuery.params },\n\t\t\t\t{ sql: opInsert.sql, params: opInsert.params },\n\t\t\t\t{\n\t\t\t\t\tsql: 'INSERT OR REPLACE INTO _kora_version_vector (node_id, sequence_number) VALUES (?, ?)',\n\t\t\t\t\tparams: [ctx.nodeId, operation.sequenceNumber],\n\t\t\t\t},\n\t\t\t],\n\t\t}\n\t}\n\n\tconst operation = await createOperation(\n\t\t{\n\t\t\t...baseInput,\n\t\t\ttype: 'update',\n\t\t\tdata: effect.data,\n\t\t\tpreviousData: effect.previousData,\n\t\t},\n\t\tctx.clock,\n\t)\n\tctx.causalTracker?.afterOperation(effect.collection, operation.id, ctx.inTransaction)\n\n\tconst definition = ctx.schema.collections[effect.collection]\n\tconst serializedChanges =\n\t\teffect.data && definition\n\t\t\t? serializeRecord(effect.data, definition.fields)\n\t\t\t: (effect.data ?? {})\n\tconst version = serializeRowVersion(operation.timestamp)\n\tconst updateQuery = buildUpdateQuery(effect.collection, effect.recordId, {\n\t\t...serializedChanges,\n\t\t_updated_at: operation.timestamp.wallTime,\n\t\t_version: version,\n\t})\n\tconst opInsert = buildInsertQuery(\n\t\t`_kora_ops_${effect.collection}`,\n\t\tserializeOperation(operation) as unknown as Record<string, unknown>,\n\t)\n\n\treturn {\n\t\toperation,\n\t\tcollection: effect.collection,\n\t\tcommands: [\n\t\t\t{ sql: updateQuery.sql, params: updateQuery.params },\n\t\t\t{ sql: opInsert.sql, params: opInsert.params },\n\t\t\t{\n\t\t\t\tsql: 'INSERT OR REPLACE INTO _kora_version_vector (node_id, sequence_number) VALUES (?, ?)',\n\t\t\t\tparams: [ctx.nodeId, operation.sequenceNumber],\n\t\t\t},\n\t\t],\n\t}\n}\n","import type { KoraEvent, KoraEventEmitter } from '@korajs/core'\nimport type { Store } from '@korajs/store'\nimport { persistedAuditTraceFromEvent } from '@korajs/store'\n\nconst AUDIT_EVENT_TYPES = ['merge:completed', 'merge:conflict', 'constraint:violated'] as const\n\ntype AuditEventType = (typeof AUDIT_EVENT_TYPES)[number]\n\nfunction isAuditEvent(event: KoraEvent): event is Extract<KoraEvent, { type: AuditEventType }> {\n\treturn (AUDIT_EVENT_TYPES as readonly string[]).includes(event.type)\n}\n\n/**\n * Persist merge and constraint traces from the event bus to `_kora_audit_traces`.\n */\nexport function wireAuditPersistence(store: Store, emitter: KoraEventEmitter): () => void {\n\tconst unsubscribers = AUDIT_EVENT_TYPES.map((eventType) =>\n\t\temitter.on(eventType, (event) => {\n\t\t\tif (!isAuditEvent(event)) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst trace = persistedAuditTraceFromEvent(event)\n\t\t\tvoid store.appendAuditTrace(trace).catch(() => {\n\t\t\t\t// Audit persistence must not break mutations or sync.\n\t\t\t})\n\t\t}),\n\t)\n\n\treturn () => {\n\t\tfor (const unsub of unsubscribers) {\n\t\t\tunsub()\n\t\t}\n\t}\n}\n","import { HttpLongPollingTransport, WebSocketTransport } from '@korajs/sync'\nimport type { SyncTransport } from '@korajs/sync'\nimport type { KoraConfig } from './types'\n\n/**\n * Instantiates the sync transport matching {@link KoraConfig.sync} settings.\n */\nexport function createSyncTransport(sync: NonNullable<KoraConfig['sync']>): SyncTransport {\n\tif (sync.transport === 'http') {\n\t\treturn new HttpLongPollingTransport()\n\t}\n\treturn new WebSocketTransport()\n}\n","import type { KoraEventEmitter, Operation, VersionVector } from '@korajs/core'\nimport type { MergeEngine } from '@korajs/merge'\nimport type { Store } from '@korajs/store'\nimport type { ApplyResult, SyncStore } from '@korajs/sync'\nimport { ApplyPipeline } from './apply-pipeline'\n\nexport interface MergeAwareSyncStoreOptions {\n\t/** Increments SyncEngine conflict counter when merge runs on a conflicting update. */\n\tonMergeConflict?: () => void\n}\n\n/**\n * Wraps a Store to route remote sync operations through {@link ApplyPipeline}.\n *\n * Ensures remote deletes honor referential integrity (cascade, set-null, restrict)\n * and remote updates use the full three-tier merge engine with constraint context.\n */\nexport class MergeAwareSyncStore implements SyncStore {\n\tprivate readonly pipeline: ApplyPipeline\n\n\tconstructor(\n\t\tprivate readonly store: Store,\n\t\tmergeEngine: MergeEngine,\n\t\temitter: KoraEventEmitter | null,\n\t\toptions?: MergeAwareSyncStoreOptions,\n\t) {\n\t\tthis.pipeline = new ApplyPipeline({\n\t\t\tstore,\n\t\t\tmergeEngine,\n\t\t\temitter,\n\t\t\tonMergeConflict: options?.onMergeConflict,\n\t\t})\n\t}\n\n\tgetVersionVector(): VersionVector {\n\t\treturn this.store.getVersionVector()\n\t}\n\n\tgetNodeId(): string {\n\t\treturn this.store.getNodeId()\n\t}\n\n\tasync getOperationRange(nodeId: string, fromSeq: number, toSeq: number): Promise<Operation[]> {\n\t\treturn this.store.getOperationRange(nodeId, fromSeq, toSeq)\n\t}\n\n\tasync applyRemoteOperation(op: Operation): Promise<ApplyResult> {\n\t\treturn this.pipeline.applyRemote(op)\n\t}\n}\n","import type { Operation } from '@korajs/core'\nimport type { StorageAdapter } from '@korajs/store'\nimport { deserializeOperation, serializeOperation } from '@korajs/store/internal'\nimport type { OperationRow } from '@korajs/store/internal'\nimport type { QueueStorage } from '@korajs/sync'\n\ninterface SyncQueueRow {\n\tid: string\n\tpayload: string\n}\n\ntype QueuePayload = OperationRow & { _collection: string }\n\n/**\n * Persists the outbound sync queue in `_kora_sync_queue` via the local StorageAdapter.\n */\nexport class StoreQueueStorage implements QueueStorage {\n\tconstructor(private readonly adapter: StorageAdapter) {}\n\n\tasync load(): Promise<Operation[]> {\n\t\tconst rows = await this.adapter.query<SyncQueueRow>(\n\t\t\t'SELECT id, payload FROM _kora_sync_queue ORDER BY rowid ASC',\n\t\t)\n\t\treturn rows.map((row) => operationFromQueuePayload(row.payload))\n\t}\n\n\tasync enqueue(op: Operation): Promise<void> {\n\t\tconst row = serializeOperation(op)\n\t\tconst payload: QueuePayload = { ...row, _collection: op.collection }\n\t\tawait this.adapter.execute(\n\t\t\t'INSERT OR REPLACE INTO _kora_sync_queue (id, payload) VALUES (?, ?)',\n\t\t\t[op.id, JSON.stringify(payload)],\n\t\t)\n\t}\n\n\tasync dequeue(ids: string[]): Promise<void> {\n\t\tif (ids.length === 0) return\n\t\tconst placeholders = ids.map(() => '?').join(', ')\n\t\tawait this.adapter.execute(`DELETE FROM _kora_sync_queue WHERE id IN (${placeholders})`, ids)\n\t}\n\n\tasync count(): Promise<number> {\n\t\tconst rows = await this.adapter.query<{ cnt: number }>(\n\t\t\t'SELECT COUNT(*) as cnt FROM _kora_sync_queue',\n\t\t)\n\t\treturn rows[0]?.cnt ?? 0\n\t}\n}\n\nfunction operationFromQueuePayload(payload: string): Operation {\n\tconst parsed = JSON.parse(payload) as QueuePayload\n\tconst op = deserializeOperation(parsed)\n\treturn {\n\t\t...op,\n\t\tcollection: parsed._collection,\n\t}\n}\n","import type { Operation, VersionVector } from '@korajs/core'\nimport { mergeVersionVectors } from '@korajs/store'\nimport type { Store } from '@korajs/store'\nimport { decodeDeltaCursor, encodeDeltaCursor, operationMatchesScope } from '@korajs/sync'\nimport type { DeltaCursor, SyncScopeMap, SyncStatePersistence } from '@korajs/sync'\n\n/**\n * Persists and queries sync acknowledgment state via the local Store.\n */\nexport class StoreSyncStatePersistence implements SyncStatePersistence {\n\tconstructor(\n\t\tprivate readonly store: Store,\n\t\tprivate readonly scope?: SyncScopeMap,\n\t) {}\n\n\tloadLastAckedServerVector(): Promise<VersionVector> {\n\t\treturn this.store.loadLastAckedServerVector()\n\t}\n\n\tsaveLastAckedServerVector(vector: VersionVector): Promise<void> {\n\t\treturn this.store.saveLastAckedServerVector(vector)\n\t}\n\n\tmergeServerVectors(a: VersionVector, b: VersionVector): VersionVector {\n\t\treturn this.store.mergeServerVectors(a, b)\n\t}\n\n\tasync countUnsyncedOperations(serverVector: VersionVector): Promise<number> {\n\t\tconst ops = await this.getUnsyncedOperations(serverVector)\n\t\treturn ops.length\n\t}\n\n\tasync getUnsyncedOperations(serverVector: VersionVector): Promise<Operation[]> {\n\t\tconst ops = await this.store.getUnsyncedOperations(serverVector)\n\t\treturn ops.filter((op) => operationMatchesScope(op, this.scope))\n\t}\n\n\tloadDeltaCursor(): Promise<DeltaCursor | null> {\n\t\treturn this.store.loadDeltaCursor().then((encoded) => decodeDeltaCursor(encoded))\n\t}\n\n\tasync saveDeltaCursor(cursor: DeltaCursor | null): Promise<void> {\n\t\tawait this.store.saveDeltaCursor(cursor ? encodeDeltaCursor(cursor) : null)\n\t}\n}\n","import type { QueryDescriptor } from '@korajs/store'\nimport type { SyncEngine, SyncQuerySubset } from '@korajs/sync'\n\n/**\n * Extract equality-only WHERE conditions for sync query subset registration.\n * Operator-based filters (e.g. `$gt`) are not representable as sync subsets yet.\n */\nexport function queryDescriptorToSyncSubset(descriptor: QueryDescriptor): SyncQuerySubset | null {\n\tconst where: Record<string, unknown> = {}\n\tconst skippedFields: string[] = []\n\n\tfor (const [field, value] of Object.entries(descriptor.where)) {\n\t\tif (value === null || value === undefined) {\n\t\t\twhere[field] = value\n\t\t\tcontinue\n\t\t}\n\t\tif (typeof value !== 'object' || Array.isArray(value)) {\n\t\t\twhere[field] = value\n\t\t\tcontinue\n\t\t}\n\t\tskippedFields.push(field)\n\t}\n\n\tif (skippedFields.length > 0 && typeof console !== 'undefined') {\n\t\tconsole.warn(\n\t\t\t`[Kora] Sync query subset omitted non-equality filters on ${descriptor.collection}: ${skippedFields.join(', ')}. ` +\n\t\t\t\t'Only plain equality WHERE clauses are registered for incremental sync.',\n\t\t)\n\t}\n\n\tif (Object.keys(where).length === 0) {\n\t\treturn null\n\t}\n\n\treturn {\n\t\tcollection: descriptor.collection,\n\t\twhere,\n\t}\n}\n\n/**\n * Creates a store hook that registers live query filters with the sync engine.\n */\nexport function createSyncQuerySubscriptionHook(\n\tgetSyncEngine: () => SyncEngine | null,\n): (descriptor: QueryDescriptor) => () => void {\n\treturn (descriptor) => {\n\t\tconst subset = queryDescriptorToSyncSubset(descriptor)\n\t\tif (!subset) {\n\t\t\treturn () => {}\n\t\t}\n\n\t\tconst engine = getSyncEngine()\n\t\tif (!engine) {\n\t\t\treturn () => {}\n\t\t}\n\n\t\treturn engine.registerQuerySubset(subset)\n\t}\n}\n","import type { Store } from '@korajs/store'\nimport type { SequenceAccessor } from './types'\n\n/**\n * Builds the offline-safe sequences accessor backed by the store sequence manager.\n */\nexport function createSequencesAccessor(\n\tready: Promise<void>,\n\tgetStore: () => Store | null,\n): SequenceAccessor {\n\tconst requireStore = async (): Promise<Store> => {\n\t\tawait ready\n\t\tconst store = getStore()\n\t\tif (!store) {\n\t\t\tthrow new Error('Store not initialized. Await app.ready before using sequences.')\n\t\t}\n\t\treturn store\n\t}\n\n\treturn {\n\t\tasync next(name, config) {\n\t\t\tconst store = await requireStore()\n\t\t\treturn store.getSequenceManager().next(name, config)\n\t\t},\n\t\tasync current(name, config) {\n\t\t\tconst store = await requireStore()\n\t\t\treturn store.getSequenceManager().current(name, config)\n\t\t},\n\t\tasync reset(name, config) {\n\t\t\tconst store = await requireStore()\n\t\t\treturn store.getSequenceManager().reset(name, config)\n\t\t},\n\t}\n}\n","import type { KoraEventEmitter } from '@korajs/core'\nimport { Instrumenter } from '@korajs/devtools'\nimport type { KoraConfig } from './types'\n\nexport interface DevtoolsSetup {\n\tinstrumenter: Instrumenter | null\n\tdestroyOverlay: (() => void) | null\n}\n\n/**\n * Enables DevTools instrumentation and optionally mounts the browser overlay.\n */\nexport function setupDevtools(config: KoraConfig, emitter: KoraEventEmitter): DevtoolsSetup {\n\tif (!config.devtools) {\n\t\treturn { instrumenter: null, destroyOverlay: null }\n\t}\n\n\tconst instrumenter = new Instrumenter(emitter, {\n\t\tbridgeEnabled: typeof globalThis !== 'undefined' && 'window' in globalThis,\n\t})\n\n\tlet destroyOverlay: (() => void) | null = null\n\n\tif (typeof globalThis !== 'undefined' && 'window' in globalThis) {\n\t\tvoid import('@korajs/devtools/overlay')\n\t\t\t.then(({ mountKoraDevtoolsOverlay }) => {\n\t\t\t\tdestroyOverlay = mountKoraDevtoolsOverlay(instrumenter)\n\t\t\t})\n\t\t\t.catch(() => {\n\t\t\t\t// Overlay is optional; extension bridge still works.\n\t\t\t})\n\t}\n\n\treturn { instrumenter, destroyOverlay: () => destroyOverlay?.() }\n}\n","import type { SyncStatusInfo } from '@korajs/sync'\nimport { OFFLINE_SYNC_STATUS } from '@korajs/sync'\nimport type { SyncRuntimeState } from './sync-lifecycle'\nimport type { KoraConfig, SyncControl } from './types'\n\nexport interface CreateSyncControlOptions {\n\tconfig: KoraConfig\n\tready: Promise<void>\n\tstate: SyncRuntimeState\n}\n\n/**\n * Builds the developer-facing `app.sync` control surface.\n */\nexport function createSyncControl(options: CreateSyncControlOptions): SyncControl | null {\n\tconst { config, ready, state } = options\n\n\tif (!config.sync) {\n\t\treturn null\n\t}\n\n\tconst offlineSyncStatus = (): SyncStatusInfo => OFFLINE_SYNC_STATUS\n\n\tconst bridgeStatus = (): SyncStatusInfo =>\n\t\tstate.syncStatusBridge?.status ?? offlineSyncStatus()\n\n\treturn {\n\t\tget status(): SyncStatusInfo {\n\t\t\treturn bridgeStatus()\n\t\t},\n\t\tsubscribeStatus(listener: (status: SyncStatusInfo) => void): () => void {\n\t\t\tif (state.syncStatusBridge) {\n\t\t\t\treturn state.syncStatusBridge.subscribe(listener)\n\t\t\t}\n\t\t\tlistener(offlineSyncStatus())\n\t\t\treturn () => {}\n\t\t},\n\t\tasync connect(): Promise<void> {\n\t\t\tawait ready\n\t\t\tif (state.syncEngine) {\n\t\t\t\tstate.intentionalDisconnect = false\n\t\t\t\tstate.reconnectionManager?.stop()\n\t\t\t\tstate.reconnectionManager?.reset()\n\t\t\t\tawait state.syncEngine.start()\n\t\t\t\tstate.syncStatusBridge?.refresh()\n\t\t\t}\n\t\t},\n\t\tasync disconnect(): Promise<void> {\n\t\t\tawait ready\n\t\t\tif (state.syncEngine) {\n\t\t\t\tstate.intentionalDisconnect = true\n\t\t\t\tstate.reconnectionManager?.stop()\n\t\t\t\tawait state.syncEngine.stop()\n\t\t\t\tstate.syncStatusBridge?.refresh()\n\t\t\t}\n\t\t},\n\t\tgetStatus(): SyncStatusInfo {\n\t\t\tif (state.syncEngine) {\n\t\t\t\treturn state.syncEngine.getStatus()\n\t\t\t}\n\t\t\treturn offlineSyncStatus()\n\t\t},\n\t\tasync retryNow(): Promise<void> {\n\t\t\tawait ready\n\t\t\tif (state.syncEngine) {\n\t\t\t\tawait state.syncEngine.retryNow()\n\t\t\t}\n\t\t},\n\t\tclearSchemaBlock(): void {\n\t\t\tstate.syncEngine?.clearSchemaBlock()\n\t\t},\n\t\texportDiagnostics() {\n\t\t\tif (state.syncEngine) {\n\t\t\t\treturn state.syncEngine.exportDiagnostics()\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tstate: 'disconnected' as const,\n\t\t\t\tstatus: {\n\t\t\t\t\tstatus: 'offline' as const,\n\t\t\t\t\tpendingOperations: 0,\n\t\t\t\t\tlastSyncedAt: null,\n\t\t\t\t\tlastSuccessfulPush: null,\n\t\t\t\t\tlastSuccessfulPull: null,\n\t\t\t\t\tconflicts: 0,\n\t\t\t\t},\n\t\t\t\tnodeId: '',\n\t\t\t\turl: config.sync?.url ?? '',\n\t\t\t\tschemaVersion: config.schema.version,\n\t\t\t\tlastSyncedAt: null,\n\t\t\t\tlastSuccessfulPush: null,\n\t\t\t\tlastSuccessfulPull: null,\n\t\t\t\tconflicts: 0,\n\t\t\t\tpendingOperations: 0,\n\t\t\t\thasInFlightBatch: false,\n\t\t\t\treconnecting: false,\n\t\t\t\ttimestamp: Date.now(),\n\t\t\t}\n\t\t},\n\t}\n}\n","import type { SyncEngine } from '@korajs/sync'\nimport type { AuthSyncBinding } from './types'\n\n/**\n * Serializes auth-driven sync reconnects so overlapping token refresh events\n * do not stack concurrent stop/start cycles on the sync engine.\n */\nexport class AuthSyncCoordinator {\n\tprivate inFlight: Promise<void> | null = null\n\tprivate pending = false\n\tprivate disposed = false\n\n\tconstructor(\n\t\tprivate readonly getEngine: () => SyncEngine | null,\n\t\tprivate readonly authBinding: AuthSyncBinding,\n\t) {}\n\n\tscheduleReconnect(): void {\n\t\tif (this.disposed) {\n\t\t\treturn\n\t\t}\n\n\t\tif (this.inFlight) {\n\t\t\tthis.pending = true\n\t\t\treturn\n\t\t}\n\n\t\tthis.inFlight = this.run().finally(() => {\n\t\t\tthis.inFlight = null\n\t\t\tif (this.pending && !this.disposed) {\n\t\t\t\tthis.pending = false\n\t\t\t\tthis.scheduleReconnect()\n\t\t\t}\n\t\t})\n\t}\n\n\tdestroy(): void {\n\t\tthis.disposed = true\n\t\tthis.pending = false\n\t}\n\n\tprivate async run(): Promise<void> {\n\t\tconst engine = this.getEngine()\n\t\tif (!engine) {\n\t\t\treturn\n\t\t}\n\n\t\tconst headers = await this.authBinding.auth()\n\t\tif (!headers.token) {\n\t\t\tawait engine.stop()\n\t\t\treturn\n\t\t}\n\n\t\tif (this.authBinding.resolveScopeMap) {\n\t\t\tconst nextScope = await this.authBinding.resolveScopeMap()\n\t\t\tengine.updateScope(nextScope)\n\t\t}\n\n\t\tconst status = engine.getStatus().status\n\t\tif (status !== 'offline') {\n\t\t\tawait engine.stop()\n\t\t}\n\t\tawait engine.start()\n\t}\n}\n","import type { KoraEventEmitter } from '@korajs/core'\nimport { createSyncStatusController, type SyncStatusInfo } from '@korajs/sync'\n\n/**\n * Event-driven sync status snapshot for non-React consumers (`app.sync.status`).\n */\nexport interface SyncStatusBridge {\n\treadonly status: SyncStatusInfo\n\tsubscribe(listener: (status: SyncStatusInfo) => void): () => void\n\trefresh(): void\n\tdestroy(): void\n}\n\n/**\n * Subscribe to sync events and expose a reactive status snapshot.\n */\nexport function createSyncStatusBridge(\n\temitter: KoraEventEmitter,\n\tgetSyncEngine: () => { getStatus(): SyncStatusInfo } | null,\n): SyncStatusBridge {\n\tconst controller = createSyncStatusController({\n\t\tgetSyncEngine,\n\t\tsubscribeSyncStatus: null,\n\t\tevents: emitter,\n\t})\n\n\treturn {\n\t\tget status() {\n\t\t\treturn controller.getSnapshot()\n\t\t},\n\t\tsubscribe(listener: (status: SyncStatusInfo) => void): () => void {\n\t\t\treturn controller.subscribe(() => {\n\t\t\t\tlistener(controller.getSnapshot())\n\t\t\t})\n\t\t},\n\t\trefresh: () => controller.refresh(),\n\t\tdestroy: () => controller.destroy(),\n\t}\n}\n","import type { KoraEventEmitter } from '@korajs/core'\nimport { AuthSyncCoordinator } from './auth-sync-coordinator'\nimport type { InitializeAppResult } from './initialize-app'\nimport { createSyncStatusBridge, type SyncStatusBridge } from './sync-status-bridge'\nimport type { KoraConfig } from './types'\nimport {\n\tConnectionMonitor,\n\tReconnectionManager,\n\ttype SyncEngine,\n} from '@korajs/sync'\n\n/** Mutable sync runtime state owned by {@link createApp}. */\nexport interface SyncRuntimeState {\n\tsyncEngine: SyncEngine | null\n\tsyncStatusBridge: SyncStatusBridge | null\n\tauthSyncCoordinator: AuthSyncCoordinator | null\n\treconnectionManager: ReconnectionManager | null\n\tconnectionMonitor: ConnectionMonitor | null\n\tqualityInterval: ReturnType<typeof setInterval> | null\n\tintentionalDisconnect: boolean\n\t/** Removes the browser `online` listener registered in {@link wireSyncLifecycleAfterReady}. */\n\tremoveOnlineListener: (() => void) | null\n}\n\n/**\n * Wires sync status bridge, auth reconnect coordinator, reconnection, and quality monitoring\n * after {@link initializeApp} completes.\n */\nexport function wireSyncLifecycleAfterReady(\n\tconfig: KoraConfig,\n\temitter: KoraEventEmitter,\n\tstate: SyncRuntimeState,\n\tinit: InitializeAppResult,\n): void {\n\tstate.syncEngine = init.syncEngine\n\n\tif (!config.sync) {\n\t\treturn\n\t}\n\n\tstate.syncStatusBridge = createSyncStatusBridge(emitter, () => state.syncEngine)\n\tstate.syncStatusBridge.refresh()\n\n\tif (state.syncEngine && init.authBinding?.subscribe) {\n\t\tstate.authSyncCoordinator = new AuthSyncCoordinator(() => state.syncEngine, init.authBinding)\n\t\tinit.authBinding.subscribe(() => {\n\t\t\tstate.authSyncCoordinator?.scheduleReconnect()\n\t\t})\n\t}\n\n\tif (!state.syncEngine) {\n\t\treturn\n\t}\n\n\tconst syncEngine = state.syncEngine\n\tstate.connectionMonitor = new ConnectionMonitor()\n\tstate.reconnectionManager = new ReconnectionManager({\n\t\tinitialDelay: config.sync.reconnectInterval,\n\t\tmaxDelay: config.sync.maxReconnectInterval,\n\t})\n\n\temitter.on('sync:sent', () => state.connectionMonitor?.recordActivity())\n\temitter.on('sync:received', () => state.connectionMonitor?.recordActivity())\n\temitter.on('sync:acknowledged', () => state.connectionMonitor?.recordActivity())\n\n\temitter.on('sync:connected', () => {\n\t\tif (state.qualityInterval !== null) {\n\t\t\tclearInterval(state.qualityInterval)\n\t\t}\n\t\tstate.qualityInterval = setInterval(() => {\n\t\t\tif (state.connectionMonitor) {\n\t\t\t\temitter.emit({\n\t\t\t\t\ttype: 'connection:quality',\n\t\t\t\t\tquality: state.connectionMonitor.getQuality(),\n\t\t\t\t})\n\t\t\t}\n\t\t}, 5000)\n\t})\n\n\temitter.on('sync:disconnected', () => {\n\t\tstate.connectionMonitor?.reset()\n\t\tif (state.qualityInterval !== null) {\n\t\t\tclearInterval(state.qualityInterval)\n\t\t\tstate.qualityInterval = null\n\t\t}\n\t})\n\n\tconst browserGlobal = globalThis as typeof globalThis & {\n\t\taddEventListener?: (type: string, listener: () => void) => void\n\t\tremoveEventListener?: (type: string, listener: () => void) => void\n\t}\n\tif (typeof browserGlobal.addEventListener === 'function') {\n\t\tconst onOnline = (): void => {\n\t\t\tif (state.intentionalDisconnect || config.sync?.autoReconnect === false) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tstate.reconnectionManager?.wake()\n\t\t\tstate.reconnectionManager?.reset()\n\t\t\tvoid syncEngine.retryNow()\n\t\t}\n\t\tbrowserGlobal.addEventListener('online', onOnline)\n\t\tstate.removeOnlineListener = (): void => {\n\t\t\tbrowserGlobal.removeEventListener?.('online', onOnline)\n\t\t}\n\t}\n\n\temitter.on('sync:schema-mismatch', () => {\n\t\tstate.reconnectionManager?.stop()\n\t\tstate.intentionalDisconnect = true\n\t})\n\n\tif (config.sync.autoReconnect !== false) {\n\t\temitter.on('sync:disconnected', () => {\n\t\t\tif (state.intentionalDisconnect || syncEngine.isSchemaBlocked()) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tif (state.reconnectionManager?.isRunning()) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tsyncEngine.setReconnecting(true)\n\t\t\tstate.reconnectionManager?.stop()\n\t\t\tstate.reconnectionManager\n\t\t\t\t?.start(async () => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait syncEngine.start()\n\t\t\t\t\t\tsyncEngine.setReconnecting(false)\n\t\t\t\t\t\treturn true\n\t\t\t\t\t} catch {\n\t\t\t\t\t\treturn false\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\t.then(() => {\n\t\t\t\t\tsyncEngine.setReconnecting(false)\n\t\t\t\t})\n\t\t})\n\t}\n\n\tif (config.sync.autoConnect === true) {\n\t\tvoid syncEngine.start().catch(() => {\n\t\t\t// Errors surface via sync:disconnected / sync events; avoid unhandled rejection.\n\t\t})\n\t}\n}\n\n/**\n * Stops timers and managers during {@link KoraApp.close}.\n */\nexport function teardownSyncLifecycle(state: SyncRuntimeState): void {\n\tif (state.qualityInterval !== null) {\n\t\tclearInterval(state.qualityInterval)\n\t\tstate.qualityInterval = null\n\t}\n\tstate.reconnectionManager?.stop()\n\tstate.syncStatusBridge?.destroy()\n\tstate.syncStatusBridge = null\n\tstate.authSyncCoordinator?.destroy()\n\tstate.authSyncCoordinator = null\n\tstate.removeOnlineListener?.()\n\tstate.removeOnlineListener = null\n}\n","import type { Operation } from '@korajs/core'\nimport type { Store } from '@korajs/store'\nimport type { KoraConfig, TransactionProxy } from './types'\n\nexport interface TransactionExecutor {\n\t(fn: (tx: TransactionProxy) => Promise<void>, mutationName?: string): Promise<Operation[]>\n}\n\n/**\n * Creates the shared executor used by {@link KoraApp.transaction} and {@link KoraApp.mutation}.\n */\nexport function createTransactionExecutor(\n\tconfig: KoraConfig,\n\tready: Promise<void>,\n\tgetStore: () => Store | null,\n): TransactionExecutor {\n\treturn async (fn, mutationName) => {\n\t\tawait ready\n\t\tconst store = getStore()\n\t\tif (!store) {\n\t\t\tthrow new Error('Store not initialized. Await app.ready before using transactions.')\n\t\t}\n\n\t\tconst collectionNames = Object.keys(config.schema.collections)\n\n\t\treturn store.transaction(async (tx) => {\n\t\t\tif (mutationName !== undefined) {\n\t\t\t\ttx.setMutationName(mutationName)\n\t\t\t}\n\n\t\t\tconst proxy: TransactionProxy = {} as TransactionProxy\n\t\t\tfor (const name of collectionNames) {\n\t\t\t\tObject.defineProperty(proxy, name, {\n\t\t\t\t\tget() {\n\t\t\t\t\t\treturn tx.collection(name)\n\t\t\t\t\t},\n\t\t\t\t\tenumerable: true,\n\t\t\t\t\tconfigurable: false,\n\t\t\t\t})\n\t\t\t}\n\n\t\t\tawait fn(proxy)\n\t\t})\n\t}\n}\n","import { KoraError, SchemaValidationError } from '@korajs/core'\nimport { detectAdapterType } from './adapter-resolver'\nimport type { KoraConfig } from './types'\n\n/**\n * Fail fast on invalid createApp configuration before opening storage or sync.\n */\nexport function validateCreateAppConfig(config: KoraConfig): void {\n\tif (!config.schema) {\n\t\tthrow new SchemaValidationError('createApp requires a schema.', {\n\t\t\tfix: 'Pass schema: defineSchema({ version: 1, collections: { ... } })',\n\t\t})\n\t}\n\n\tif (config.schema.version < 1) {\n\t\tthrow new SchemaValidationError('Schema version must be at least 1.', {\n\t\t\tversion: config.schema.version,\n\t\t})\n\t}\n\n\tconst collectionNames = Object.keys(config.schema.collections)\n\tif (collectionNames.length === 0) {\n\t\tthrow new SchemaValidationError('Schema must define at least one collection.', {\n\t\t\tfix: 'Add entries under collections in defineSchema().',\n\t\t})\n\t}\n\n\tif (config.sync) {\n\t\tvalidateSyncUrl(config.sync.url, config.sync.transport ?? 'websocket')\n\t}\n\n\tconst adapter = config.store?.adapter ?? detectAdapterType()\n\tconst isBrowser =\n\t\ttypeof globalThis !== 'undefined' &&\n\t\ttypeof (globalThis as Record<string, unknown>).window !== 'undefined'\n\n\tif (\n\t\tisBrowser &&\n\t\t(adapter === 'sqlite-wasm' || adapter === 'indexeddb') &&\n\t\t!config.store?.workerUrl\n\t) {\n\t\tthrow new KoraError(\n\t\t\t'Browser storage requires store.workerUrl pointing to the SQLite WASM worker script.',\n\t\t\t'MISSING_WORKER_URL',\n\t\t\t{\n\t\t\t\tadapter,\n\t\t\t\tfix: 'Add store: { workerUrl: \"/sqlite-wasm-worker.js\" } (see create-kora-app templates).',\n\t\t\t},\n\t\t)\n\t}\n}\n\nfunction validateSyncUrl(url: string, transport: 'websocket' | 'http'): void {\n\tif (!url || url.trim().length === 0) {\n\t\tthrow new KoraError('sync.url is required when sync is configured.', 'INVALID_SYNC_URL', {\n\t\t\tfix: 'Pass sync: { url: \"wss://your-server/kora\" }.',\n\t\t})\n\t}\n\n\ttry {\n\t\tconst parsed = new URL(url)\n\t\tif (transport === 'http') {\n\t\t\tif (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {\n\t\t\t\tthrow new Error('bad protocol')\n\t\t\t}\n\t\t} else if (parsed.protocol !== 'ws:' && parsed.protocol !== 'wss:') {\n\t\t\tthrow new Error('bad protocol')\n\t\t}\n\t} catch {\n\t\tthrow new KoraError(\n\t\t\t`Invalid sync URL \"${url}\" for transport \"${transport}\".`,\n\t\t\t'INVALID_SYNC_URL',\n\t\t\t{\n\t\t\t\turl,\n\t\t\t\ttransport,\n\t\t\t\tfix:\n\t\t\t\t\ttransport === 'http'\n\t\t\t\t\t\t? 'Use an absolute http:// or https:// URL.'\n\t\t\t\t\t\t: 'Use an absolute ws:// or wss:// URL.',\n\t\t\t},\n\t\t)\n\t}\n}\n","import type { KoraEventEmitter } from '@korajs/core'\nimport type { KoraSyncEvent } from './types'\n\nconst SYNC_EVENT_TYPES = [\n\t'sync:connected',\n\t'sync:disconnected',\n\t'sync:schema-mismatch',\n\t'sync:auth-failed',\n\t'sync:sent',\n\t'sync:received',\n\t'sync:acknowledged',\n\t'sync:apply-failed',\n\t'sync:diagnostics',\n\t'sync:bandwidth',\n\t'sync:initial-sync-progress',\n] as const\n\n/**\n * Forwards selected sync events from the app emitter to {@link KoraConfig.onSyncEvent}.\n */\nexport function wireSyncEventForwarding(\n\temitter: KoraEventEmitter,\n\thandler: (event: KoraSyncEvent) => void,\n): void {\n\tfor (const type of SYNC_EVENT_TYPES) {\n\t\temitter.on(type, (event) => {\n\t\t\thandler(event as KoraSyncEvent)\n\t\t})\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,IAAAA,mBAAmC;AACnC,IAAAC,gBAA4B;AAE5B,IAAAC,gBAAgC;;;ACJhC,kBAAiC;AAM1B,SAAS,yBACf,gBACA,UACqB;AACrB,QAAM,WAAW,CAAC,WACjB,IAAI;AAAA,IACH,UAAU,MAAM,mBAAmB,cAAc;AAAA,EAClD;AAED,SAAO;AAAA,IACN,MAAM,OAAO,MAA+B;AAC3C,YAAM,eAAe,SAAS;AAC9B,UAAI,CAAC,cAAc;AAClB,cAAM,SAAS,aAAa;AAAA,MAC7B;AACA,aAAO,aAAa,WAAW,cAAc,EAAE,OAAO,IAAI;AAAA,IAC3D;AAAA,IACA,MAAM,SAAS,IAAY;AAC1B,YAAM,eAAe,SAAS;AAC9B,UAAI,CAAC,aAAc,QAAO;AAC1B,aAAO,aAAa,WAAW,cAAc,EAAE,SAAS,EAAE;AAAA,IAC3D;AAAA,IACA,MAAM,OAAO,IAAY,MAA+B;AACvD,YAAM,eAAe,SAAS;AAC9B,UAAI,CAAC,cAAc;AAClB,cAAM,SAAS,QAAQ;AAAA,MACxB;AACA,aAAO,aAAa,WAAW,cAAc,EAAE,OAAO,IAAI,IAAI;AAAA,IA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mB;AAgCnB,IAAAD,gBAAuC;AACvC,IAAAA,gBAAmC;AACnC,IAAAA,gBAKO;AAgBP,IAAAE,gBAA4B;AAI5B,IAAAC,eAA+C;","names":["import_internal","import_merge","import_store","import_core","import_store","import_sync","import_core","import_internal","import_core","operation","version","opInsert","ctx","op","t","import_store","op","import_internal","op","import_store","import_sync","op","import_sync","import_sync","import_sync","import_core","import_store","import_core","import_merge","import_sync"]}
package/dist/index.d.cts CHANGED
@@ -1,12 +1,14 @@
1
1
  import * as _korajs_core from '@korajs/core';
2
2
  import { KoraEventEmitter, SequenceConfig, Operation, SchemaDefinition, KoraEvent, SchemaInput, FieldBuilder, InferRecord, InferInsertInput, InferUpdateInput } from '@korajs/core';
3
- export { AtomicOp, AtomicOpType, CollectionDefinition, ConnectionQuality, Constraint, FieldDescriptor, FieldKindToType, HLCTimestamp, HybridLogicalClock, InferFieldType, InferInsertInput, InferRecord, InferUpdateInput, KoraError, KoraEvent, KoraEventEmitter, KoraEventListener, KoraEventType, MergeStrategy, MergeTrace, MigrationDefinition, MigrationStep, Operation, SchemaDefinition, SchemaInput, SequenceConfig, SyncRuleDefinition, TypedSchemaDefinition, VersionVector, createOperation, defineSchema, generateUUIDv7, migrate, op, t } from '@korajs/core';
3
+ export { AppNotReadyError, AtomicOp, AtomicOpType, CollectionDefinition, ConnectionQuality, Constraint, FieldDescriptor, FieldKindToType, HLCTimestamp, HybridLogicalClock, InferFieldType, InferInsertInput, InferRecord, InferUpdateInput, KoraError, KoraEvent, KoraEventEmitter, KoraEventListener, KoraEventType, MergeStrategy, MergeTrace, MigrationDefinition, MigrationStep, Operation, SchemaDefinition, SchemaInput, SequenceConfig, SyncRuleDefinition, TypedSchemaDefinition, VersionVector, createOperation, defineSchema, generateUUIDv7, migrate, op, t } from '@korajs/core';
4
4
  import * as _korajs_sync from '@korajs/sync';
5
5
  import { SyncStatusInfo, SyncEngine } from '@korajs/sync';
6
6
  export { SyncConfig, SyncDiagnostics, SyncEncryptionConfig, SyncEngine, SyncState, SyncStatus, SyncStatusInfo, SyncStore, WebSocketTransport } from '@korajs/sync';
7
7
  import * as _korajs_store from '@korajs/store';
8
8
  import { CollectionRecord, BackupOptions, RestoreOptions, RestoreResult, ReplaySnapshot, AuditExportOptions, QueryBuilder, CollectionAccessor } from '@korajs/store';
9
9
  export { AuditExportManifest, AuditExportOptions, AuditExportPayload, BackupManifest, BackupOptions, BackupProgress, CollectionAccessor, CollectionRecord, PersistedAuditTrace, ReplaySnapshot, RestoreOptions, RestoreResult, SequenceManager, StorageAdapter, Store, StoreConfig, TransactionCollectionAccessor, TransactionContext, TransactionContextConfig, decodeAuditExport, exportBackup, readAuditExportManifest, readBackupManifest, restoreBackup, verifyAuditExportChecksum, verifyBackupChecksum } from '@korajs/store';
10
+ import { AuthSyncBinding } from '@korajs/core/bindings';
11
+ export { AuthSyncBinding } from '@korajs/core/bindings';
10
12
  export { MergeEngine, MergeInput, MergeResult } from '@korajs/merge';
11
13
 
12
14
  /**
@@ -37,25 +39,7 @@ interface StoreOptions {
37
39
  /** Max wait for a worker RPC (e.g. `open`). Defaults to 30000ms. */
38
40
  workerResponseTimeoutMs?: number;
39
41
  }
40
- /**
41
- * Pre-built auth binding from `createKoraAuthSync()` in `@korajs/auth`.
42
- * Wires token refresh, JWT scope maps, and device-bound sync node ids.
43
- */
44
- interface AuthSyncBinding {
45
- /** Returns the access token for sync handshake (empty string when signed out). */
46
- auth: () => Promise<{
47
- token: string;
48
- }>;
49
- /** Builds a scope map from the current token and schema. */
50
- resolveScopeMap?: () => Promise<Record<string, Record<string, unknown>> | undefined>;
51
- /**
52
- * Returns the device-bound sync node id from the token `dev` claim.
53
- * Separate from the user id (`sub`).
54
- */
55
- resolveNodeId?: () => Promise<string | undefined>;
56
- /** Notifies when auth state changes so sync can refresh scope or reconnect. */
57
- subscribe?: (listener: () => void) => () => void;
58
- }
42
+
59
43
  /**
60
44
  * Sync configuration within createApp.
61
45
  */
@@ -250,6 +234,8 @@ interface KoraApp {
250
234
  getStore(): _korajs_store.Store;
251
235
  /** Get the underlying SyncEngine instance. Null if sync not configured. */
252
236
  getSyncEngine(): SyncEngine | null;
237
+ /** Per-app reference-counted cache for framework query subscriptions. */
238
+ getQueryStoreCache(): _korajs_store.QueryStoreCache;
253
239
  /** Gracefully close the app: stop sync, close store. */
254
240
  close(): Promise<void>;
255
241
  /**
@@ -344,6 +330,8 @@ type TypedKoraApp<S extends SchemaInput> = {
344
330
  getStore(): _korajs_store.Store;
345
331
  /** Get the underlying SyncEngine instance. Null if sync not configured. */
346
332
  getSyncEngine(): SyncEngine | null;
333
+ /** Per-app reference-counted cache for framework query subscriptions. */
334
+ getQueryStoreCache(): _korajs_store.QueryStoreCache;
347
335
  /** Gracefully close the app: stop sync, close store. */
348
336
  close(): Promise<void>;
349
337
  /** Execute multiple mutations atomically within a transaction. */
@@ -370,39 +358,8 @@ type TypedKoraApp<S extends SchemaInput> = {
370
358
  * Wires together store, merge engine, event emitter, and optionally sync
371
359
  * into a single developer-facing `KoraApp` object. Collection accessors
372
360
  * (e.g. `app.todos`) are defined as properties for immediate use after `await app.ready`.
373
- *
374
- * @param config - Application configuration including schema and optional sync settings
375
- * @returns A KoraApp instance with reactive collections ready for use
376
- *
377
- * @example
378
- * ```typescript
379
- * const app = createApp({
380
- * schema: defineSchema({
381
- * version: 1,
382
- * collections: {
383
- * todos: {
384
- * fields: {
385
- * title: t.string(),
386
- * completed: t.boolean().default(false)
387
- * }
388
- * }
389
- * }
390
- * })
391
- * })
392
- *
393
- * await app.ready
394
- * const todo = await app.todos.insert({ title: 'Hello' })
395
- * ```
396
- */
397
- /**
398
- * Creates a new typed Kora application instance.
399
- * When the schema is created with `defineSchema()`, full type inference flows through
400
- * to collection accessors, providing autocomplete and type checking for all CRUD operations.
401
361
  */
402
362
  declare function createApp<const S extends SchemaInput>(config: TypedKoraConfig<S>): TypedKoraApp<S>;
403
- /**
404
- * Creates a new Kora application instance (untyped fallback).
405
- */
406
363
  declare function createApp(config: KoraConfig): KoraApp;
407
364
 
408
- export { type AdapterType, type AuthSyncBinding, type KoraApp, type KoraConfig, type SequenceAccessor, type StoreOptions, type SyncControl, type SyncOptions, type TransactionCollectionProxy, type TransactionProxy, type TypedCollectionAccessor, type TypedKoraApp, type TypedKoraConfig, createApp };
365
+ export { type AdapterType, type KoraApp, type KoraConfig, type SequenceAccessor, type StoreOptions, type SyncControl, type SyncOptions, type TransactionCollectionProxy, type TransactionProxy, type TypedCollectionAccessor, type TypedKoraApp, type TypedKoraConfig, createApp };