korajs 0.3.2 → 0.4.0

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/config.ts"],"sourcesContent":["/**\n * Kora CLI/runtime configuration shape loaded from `kora.config.*`.\n */\nexport interface KoraUserConfig {\n\t/** Path to the schema file. Defaults to auto-detection in CLI. */\n\tschema?: string\n\tdev?: {\n\t\t/** Vite development server port. */\n\t\tport?: number\n\t\tsync?:\n\t\t\t| boolean\n\t\t\t| {\n\t\t\t\t/** Enable or disable sync server startup in `kora dev`. */\n\t\t\t\tenabled?: boolean\n\t\t\t\t/** Sync server port (also exposed as PORT/KORA_SYNC_PORT env). */\n\t\t\t\tport?: number\n\t\t\t\t/** Sync server store backend for managed mode (without server.ts). */\n\t\t\t\tstore?:\n\t\t\t\t\t| 'memory'\n\t\t\t\t\t| 'sqlite'\n\t\t\t\t\t| 'postgres'\n\t\t\t\t\t| {\n\t\t\t\t\t\ttype: 'memory'\n\t\t\t\t\t}\n\t\t\t\t\t| {\n\t\t\t\t\t\ttype: 'sqlite'\n\t\t\t\t\t\tfilename?: string\n\t\t\t\t\t}\n\t\t\t\t\t| {\n\t\t\t\t\t\ttype: 'postgres'\n\t\t\t\t\t\tconnectionString: string\n\t\t\t\t\t}\n\t\t\t}\n\t\twatch?:\n\t\t\t| boolean\n\t\t\t| {\n\t\t\t\t/** Enable or disable schema watching. */\n\t\t\t\tenabled?: boolean\n\t\t\t\t/** Debounce duration for schema regeneration. */\n\t\t\t\tdebounceMs?: number\n\t\t\t}\n\t}\n}\n\n/**\n * Defines a typed Kora config.\n */\nexport function defineConfig(config: KoraUserConfig): KoraUserConfig {\n\treturn config\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA+CO,SAAS,aAAa,QAAwC;AACpE,SAAO;AACR;","names":[]}
1
+ {"version":3,"sources":["../src/config.ts"],"sourcesContent":["/**\n * Kora CLI/runtime configuration shape loaded from `kora.config.*`.\n */\nexport interface KoraUserConfig {\n\t/** Path to the schema file. Defaults to auto-detection in CLI. */\n\tschema?: string\n\tdev?: {\n\t\t/** Vite development server port. */\n\t\tport?: number\n\t\tsync?:\n\t\t\t| boolean\n\t\t\t| {\n\t\t\t\t\t/** Enable or disable sync server startup in `kora dev`. */\n\t\t\t\t\tenabled?: boolean\n\t\t\t\t\t/** Sync server port (also exposed as PORT/KORA_SYNC_PORT env). */\n\t\t\t\t\tport?: number\n\t\t\t\t\t/** Sync server store backend for managed mode (without server.ts). */\n\t\t\t\t\tstore?:\n\t\t\t\t\t\t| 'memory'\n\t\t\t\t\t\t| 'sqlite'\n\t\t\t\t\t\t| 'postgres'\n\t\t\t\t\t\t| {\n\t\t\t\t\t\t\t\ttype: 'memory'\n\t\t\t\t\t\t }\n\t\t\t\t\t\t| {\n\t\t\t\t\t\t\t\ttype: 'sqlite'\n\t\t\t\t\t\t\t\tfilename?: string\n\t\t\t\t\t\t }\n\t\t\t\t\t\t| {\n\t\t\t\t\t\t\t\ttype: 'postgres'\n\t\t\t\t\t\t\t\tconnectionString: string\n\t\t\t\t\t\t }\n\t\t\t }\n\t\twatch?:\n\t\t\t| boolean\n\t\t\t| {\n\t\t\t\t\t/** Enable or disable schema watching. */\n\t\t\t\t\tenabled?: boolean\n\t\t\t\t\t/** Debounce duration for schema regeneration. */\n\t\t\t\t\tdebounceMs?: number\n\t\t\t }\n\t}\n}\n\n/**\n * Defines a typed Kora config.\n */\nexport function defineConfig(config: KoraUserConfig): KoraUserConfig {\n\treturn config\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA+CO,SAAS,aAAa,QAAwC;AACpE,SAAO;AACR;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/config.ts"],"sourcesContent":["/**\n * Kora CLI/runtime configuration shape loaded from `kora.config.*`.\n */\nexport interface KoraUserConfig {\n\t/** Path to the schema file. Defaults to auto-detection in CLI. */\n\tschema?: string\n\tdev?: {\n\t\t/** Vite development server port. */\n\t\tport?: number\n\t\tsync?:\n\t\t\t| boolean\n\t\t\t| {\n\t\t\t\t/** Enable or disable sync server startup in `kora dev`. */\n\t\t\t\tenabled?: boolean\n\t\t\t\t/** Sync server port (also exposed as PORT/KORA_SYNC_PORT env). */\n\t\t\t\tport?: number\n\t\t\t\t/** Sync server store backend for managed mode (without server.ts). */\n\t\t\t\tstore?:\n\t\t\t\t\t| 'memory'\n\t\t\t\t\t| 'sqlite'\n\t\t\t\t\t| 'postgres'\n\t\t\t\t\t| {\n\t\t\t\t\t\ttype: 'memory'\n\t\t\t\t\t}\n\t\t\t\t\t| {\n\t\t\t\t\t\ttype: 'sqlite'\n\t\t\t\t\t\tfilename?: string\n\t\t\t\t\t}\n\t\t\t\t\t| {\n\t\t\t\t\t\ttype: 'postgres'\n\t\t\t\t\t\tconnectionString: string\n\t\t\t\t\t}\n\t\t\t}\n\t\twatch?:\n\t\t\t| boolean\n\t\t\t| {\n\t\t\t\t/** Enable or disable schema watching. */\n\t\t\t\tenabled?: boolean\n\t\t\t\t/** Debounce duration for schema regeneration. */\n\t\t\t\tdebounceMs?: number\n\t\t\t}\n\t}\n}\n\n/**\n * Defines a typed Kora config.\n */\nexport function defineConfig(config: KoraUserConfig): KoraUserConfig {\n\treturn config\n}\n"],"mappings":";AA+CO,SAAS,aAAa,QAAwC;AACpE,SAAO;AACR;","names":[]}
1
+ {"version":3,"sources":["../src/config.ts"],"sourcesContent":["/**\n * Kora CLI/runtime configuration shape loaded from `kora.config.*`.\n */\nexport interface KoraUserConfig {\n\t/** Path to the schema file. Defaults to auto-detection in CLI. */\n\tschema?: string\n\tdev?: {\n\t\t/** Vite development server port. */\n\t\tport?: number\n\t\tsync?:\n\t\t\t| boolean\n\t\t\t| {\n\t\t\t\t\t/** Enable or disable sync server startup in `kora dev`. */\n\t\t\t\t\tenabled?: boolean\n\t\t\t\t\t/** Sync server port (also exposed as PORT/KORA_SYNC_PORT env). */\n\t\t\t\t\tport?: number\n\t\t\t\t\t/** Sync server store backend for managed mode (without server.ts). */\n\t\t\t\t\tstore?:\n\t\t\t\t\t\t| 'memory'\n\t\t\t\t\t\t| 'sqlite'\n\t\t\t\t\t\t| 'postgres'\n\t\t\t\t\t\t| {\n\t\t\t\t\t\t\t\ttype: 'memory'\n\t\t\t\t\t\t }\n\t\t\t\t\t\t| {\n\t\t\t\t\t\t\t\ttype: 'sqlite'\n\t\t\t\t\t\t\t\tfilename?: string\n\t\t\t\t\t\t }\n\t\t\t\t\t\t| {\n\t\t\t\t\t\t\t\ttype: 'postgres'\n\t\t\t\t\t\t\t\tconnectionString: string\n\t\t\t\t\t\t }\n\t\t\t }\n\t\twatch?:\n\t\t\t| boolean\n\t\t\t| {\n\t\t\t\t\t/** Enable or disable schema watching. */\n\t\t\t\t\tenabled?: boolean\n\t\t\t\t\t/** Debounce duration for schema regeneration. */\n\t\t\t\t\tdebounceMs?: number\n\t\t\t }\n\t}\n}\n\n/**\n * Defines a typed Kora config.\n */\nexport function defineConfig(config: KoraUserConfig): KoraUserConfig {\n\treturn config\n}\n"],"mappings":";AA+CO,SAAS,aAAa,QAAwC;AACpE,SAAO;AACR;","names":[]}
package/dist/index.cjs CHANGED
@@ -30,21 +30,26 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
- HybridLogicalClock: () => import_core2.HybridLogicalClock,
34
- KoraError: () => import_core5.KoraError,
33
+ HybridLogicalClock: () => import_core3.HybridLogicalClock,
34
+ KoraError: () => import_core6.KoraError,
35
35
  MergeEngine: () => import_merge2.MergeEngine,
36
+ SequenceManager: () => import_store2.SequenceManager,
36
37
  Store: () => import_store2.Store,
37
38
  SyncEngine: () => import_sync2.SyncEngine,
39
+ TransactionContext: () => import_store3.TransactionContext,
38
40
  WebSocketTransport: () => import_sync2.WebSocketTransport,
39
41
  createApp: () => createApp,
40
- createOperation: () => import_core4.createOperation,
41
- defineSchema: () => import_core.defineSchema,
42
- generateUUIDv7: () => import_core3.generateUUIDv7,
43
- t: () => import_core.t
42
+ createOperation: () => import_core5.createOperation,
43
+ defineSchema: () => import_core2.defineSchema,
44
+ generateUUIDv7: () => import_core4.generateUUIDv7,
45
+ migrate: () => import_core2.migrate,
46
+ op: () => import_core7.op,
47
+ t: () => import_core2.t
44
48
  });
45
49
  module.exports = __toCommonJS(index_exports);
46
50
 
47
51
  // src/create-app.ts
52
+ var import_core = require("@korajs/core");
48
53
  var import_internal = require("@korajs/core/internal");
49
54
  var import_devtools = require("@korajs/devtools");
50
55
  var import_merge = require("@korajs/merge");
@@ -70,8 +75,10 @@ function detectAdapterType() {
70
75
  async function createAdapter(type, dbName, workerUrl) {
71
76
  switch (type) {
72
77
  case "tauri-sqlite": {
73
- const dynamicImport = new Function("specifier", "return import(specifier)");
74
- const { TauriSqliteAdapter } = await dynamicImport("@korajs/tauri");
78
+ const { TauriSqliteAdapter } = await import(
79
+ /* @vite-ignore */
80
+ "@korajs/tauri"
81
+ );
75
82
  return new TauriSqliteAdapter({ path: `${dbName}.db` });
76
83
  }
77
84
  case "better-sqlite3": {
@@ -115,23 +122,23 @@ var MergeAwareSyncStore = class {
115
122
  async getOperationRange(nodeId, fromSeq, toSeq) {
116
123
  return this.store.getOperationRange(nodeId, fromSeq, toSeq);
117
124
  }
118
- async applyRemoteOperation(op) {
119
- if (op.type !== "update" || !op.data || !op.previousData) {
120
- return this.store.applyRemoteOperation(op);
125
+ async applyRemoteOperation(op2) {
126
+ if (op2.type !== "update" || !op2.data || !op2.previousData) {
127
+ return this.store.applyRemoteOperation(op2);
121
128
  }
122
129
  const schema = this.store.getSchema();
123
- const collectionDef = schema.collections[op.collection];
130
+ const collectionDef = schema.collections[op2.collection];
124
131
  if (!collectionDef) {
125
- return this.store.applyRemoteOperation(op);
132
+ return this.store.applyRemoteOperation(op2);
126
133
  }
127
- const accessor = this.store.collection(op.collection);
128
- const currentRecord = await accessor.findById(op.recordId);
134
+ const accessor = this.store.collection(op2.collection);
135
+ const currentRecord = await accessor.findById(op2.recordId);
129
136
  if (!currentRecord) {
130
- return this.store.applyRemoteOperation(op);
137
+ return this.store.applyRemoteOperation(op2);
131
138
  }
132
139
  let hasConflict = false;
133
- for (const field of Object.keys(op.data)) {
134
- const expectedBase = op.previousData[field];
140
+ for (const field of Object.keys(op2.data)) {
141
+ const expectedBase = op2.previousData[field];
135
142
  const currentLocal = currentRecord[field];
136
143
  if (!deepEqual(expectedBase, currentLocal)) {
137
144
  hasConflict = true;
@@ -139,24 +146,24 @@ var MergeAwareSyncStore = class {
139
146
  }
140
147
  }
141
148
  if (!hasConflict) {
142
- return this.store.applyRemoteOperation(op);
149
+ return this.store.applyRemoteOperation(op2);
143
150
  }
144
151
  this.emitter?.emit({
145
152
  type: "merge:started",
146
- operationA: op,
147
- operationB: op
153
+ operationA: op2,
154
+ operationB: op2
148
155
  });
149
- const baseState = { ...op.previousData };
156
+ const baseState = { ...op2.previousData };
150
157
  const localOp = {
151
- ...op,
158
+ ...op2,
152
159
  // The "local" operation's data is the diff between base and current local state
153
- data: buildLocalDiff(op.previousData, currentRecord, Object.keys(op.data)),
154
- previousData: op.previousData,
160
+ data: buildLocalDiff(op2.previousData, currentRecord, Object.keys(op2.data)),
161
+ previousData: op2.previousData,
155
162
  nodeId: this.store.getNodeId()
156
163
  };
157
164
  const input = {
158
165
  local: localOp,
159
- remote: op,
166
+ remote: op2,
160
167
  baseState,
161
168
  collectionDef
162
169
  };
@@ -169,7 +176,7 @@ var MergeAwareSyncStore = class {
169
176
  this.emitter?.emit({ type: "merge:completed", trace: firstTrace });
170
177
  }
171
178
  const mergedOp = {
172
- ...op,
179
+ ...op2,
173
180
  data: result.mergedData
174
181
  };
175
182
  return this.store.applyRemoteOperation(mergedOp);
@@ -291,13 +298,104 @@ function createApp(config) {
291
298
  if (syncEngine) {
292
299
  return syncEngine.getStatus();
293
300
  }
294
- return { status: "offline", pendingOperations: 0, lastSyncedAt: null };
301
+ return {
302
+ status: "offline",
303
+ pendingOperations: 0,
304
+ lastSyncedAt: null,
305
+ lastSuccessfulPush: null,
306
+ lastSuccessfulPull: null,
307
+ conflicts: 0
308
+ };
309
+ },
310
+ async retryNow() {
311
+ await ready;
312
+ if (syncEngine) {
313
+ await syncEngine.retryNow();
314
+ }
315
+ },
316
+ exportDiagnostics() {
317
+ if (syncEngine) {
318
+ return syncEngine.exportDiagnostics();
319
+ }
320
+ return {
321
+ state: "disconnected",
322
+ status: {
323
+ status: "offline",
324
+ pendingOperations: 0,
325
+ lastSyncedAt: null,
326
+ lastSuccessfulPush: null,
327
+ lastSuccessfulPull: null,
328
+ conflicts: 0
329
+ },
330
+ nodeId: "",
331
+ url: config.sync?.url ?? "",
332
+ schemaVersion: config.schema.version,
333
+ lastSyncedAt: null,
334
+ lastSuccessfulPush: null,
335
+ lastSuccessfulPull: null,
336
+ conflicts: 0,
337
+ pendingOperations: 0,
338
+ hasInFlightBatch: false,
339
+ reconnecting: false,
340
+ timestamp: Date.now()
341
+ };
295
342
  }
296
343
  } : null;
344
+ async function executeTransaction(fn, mutationName) {
345
+ await ready;
346
+ if (!store) {
347
+ throw new Error("Store not initialized. Await app.ready before using transactions.");
348
+ }
349
+ const txContext = store.createTransaction();
350
+ if (mutationName !== void 0) {
351
+ txContext.setMutationName(mutationName);
352
+ }
353
+ const collectionNames = Object.keys(config.schema.collections);
354
+ const proxy = {};
355
+ for (const name of collectionNames) {
356
+ Object.defineProperty(proxy, name, {
357
+ get() {
358
+ return txContext.collection(name);
359
+ },
360
+ enumerable: true,
361
+ configurable: false
362
+ });
363
+ }
364
+ try {
365
+ await fn(proxy);
366
+ const { operations } = await txContext.commit();
367
+ for (const op2 of operations) {
368
+ store.getSubscriptionManager().notify(op2.collection, op2);
369
+ emitter.emit({ type: "operation:created", operation: op2 });
370
+ }
371
+ return operations;
372
+ } catch (error) {
373
+ txContext.rollback();
374
+ throw error;
375
+ }
376
+ }
377
+ const sequences = {
378
+ async next(name, config2) {
379
+ await ready;
380
+ if (!store) throw new Error("Store not initialized. Await app.ready before using sequences.");
381
+ return store.getSequenceManager().next(name, config2);
382
+ },
383
+ async current(name, config2) {
384
+ await ready;
385
+ if (!store) throw new Error("Store not initialized. Await app.ready before using sequences.");
386
+ return store.getSequenceManager().current(name, config2);
387
+ },
388
+ async reset(name, config2) {
389
+ await ready;
390
+ if (!store) throw new Error("Store not initialized. Await app.ready before using sequences.");
391
+ return store.getSequenceManager().reset(name, config2);
392
+ }
393
+ };
297
394
  const app = {
298
395
  ready,
299
396
  events: emitter,
300
397
  sync: syncControl,
398
+ sequences,
301
399
  getStore() {
302
400
  if (!store) {
303
401
  throw new Error("Store not initialized. Await app.ready before accessing the store.");
@@ -307,6 +405,12 @@ function createApp(config) {
307
405
  getSyncEngine() {
308
406
  return syncEngine;
309
407
  },
408
+ async transaction(fn) {
409
+ return executeTransaction(fn);
410
+ },
411
+ async mutation(name, fn) {
412
+ return executeTransaction(fn, name);
413
+ },
310
414
  async close() {
311
415
  await ready;
312
416
  intentionalDisconnect = true;
@@ -360,6 +464,7 @@ async function initializeAsync(config, emitter, mergeEngine) {
360
464
  if (config.sync) {
361
465
  const transport = new import_sync.WebSocketTransport();
362
466
  const mergeAwareStore = new MergeAwareSyncStore(store, mergeEngine, emitter);
467
+ const scopeMap = config.sync.scope ? (0, import_core.buildScopeMap)(config.schema, config.sync.scope) : void 0;
363
468
  syncEngine = new import_sync.SyncEngine({
364
469
  transport,
365
470
  store: mergeAwareStore,
@@ -368,7 +473,8 @@ async function initializeAsync(config, emitter, mergeEngine) {
368
473
  transport: config.sync.transport,
369
474
  auth: config.sync.auth,
370
475
  batchSize: config.sync.batchSize,
371
- schemaVersion: config.sync.schemaVersion ?? config.schema.version
476
+ schemaVersion: config.sync.schemaVersion ?? config.schema.version,
477
+ scopeMap
372
478
  },
373
479
  emitter
374
480
  });
@@ -461,12 +567,14 @@ function createPendingQueryBuilder(initialWhere) {
461
567
  }
462
568
 
463
569
  // src/index.ts
464
- var import_core = require("@korajs/core");
465
570
  var import_core2 = require("@korajs/core");
466
571
  var import_core3 = require("@korajs/core");
467
572
  var import_core4 = require("@korajs/core");
468
573
  var import_core5 = require("@korajs/core");
574
+ var import_core6 = require("@korajs/core");
575
+ var import_core7 = require("@korajs/core");
469
576
  var import_store2 = require("@korajs/store");
577
+ var import_store3 = require("@korajs/store");
470
578
  var import_merge2 = require("@korajs/merge");
471
579
  var import_sync2 = require("@korajs/sync");
472
580
  // Annotate the CommonJS export names for ESM import in node:
@@ -474,13 +582,17 @@ var import_sync2 = require("@korajs/sync");
474
582
  HybridLogicalClock,
475
583
  KoraError,
476
584
  MergeEngine,
585
+ SequenceManager,
477
586
  Store,
478
587
  SyncEngine,
588
+ TransactionContext,
479
589
  WebSocketTransport,
480
590
  createApp,
481
591
  createOperation,
482
592
  defineSchema,
483
593
  generateUUIDv7,
594
+ migrate,
595
+ op,
484
596
  t
485
597
  });
486
598
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/create-app.ts","../src/adapter-resolver.ts","../src/merge-aware-sync-store.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\tKoraApp,\n\tKoraConfig,\n\tStoreOptions,\n\tSyncControl,\n\tSyncOptions,\n\tTypedCollectionAccessor,\n\tTypedKoraApp,\n\tTypedKoraConfig,\n} from './types'\n\n// === @korajs/core re-exports ===\nexport { defineSchema, 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 type {\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\tOperation,\n\tSchemaDefinition,\n\tSchemaInput,\n\tTypedSchemaDefinition,\n\tVersionVector,\n} from '@korajs/core'\n\n// === @korajs/store re-exports ===\nexport { Store } from '@korajs/store'\nexport type {\n\tCollectionAccessor,\n\tCollectionRecord,\n\tStorageAdapter,\n\tStoreConfig,\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\tSyncState,\n\tSyncStatus,\n\tSyncStatusInfo,\n\tSyncStore,\n} from '@korajs/sync'\n","import type { KoraEventEmitter, Operation, SchemaInput } 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 { CollectionAccessor, StorageAdapter } from '@korajs/store'\nimport type { QueryBuilder } from '@korajs/store'\nimport { ConnectionMonitor, ReconnectionManager, SyncEngine, WebSocketTransport } from '@korajs/sync'\nimport type { SyncStatusInfo } from '@korajs/sync'\nimport { createAdapter, detectAdapterType } from './adapter-resolver'\nimport { MergeAwareSyncStore } from './merge-aware-sync-store'\nimport type { KoraApp, KoraConfig, SyncControl, TypedKoraApp, TypedKoraConfig } from './types'\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(config: KoraConfig): KoraApp {\n\tconst emitter: KoraEventEmitter & { clear(): void } = new SimpleEventEmitter()\n\tconst mergeEngine = new MergeEngine()\n\n\tlet store: Store | null = null\n\tlet syncEngine: SyncEngine | null = null\n\tlet unsubscribeSync: (() => 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\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}\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\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// 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) 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?.start(async () => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tawait engine.start()\n\t\t\t\t\t\t\tengine.setReconnecting(false)\n\t\t\t\t\t\t\treturn true\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\treturn false\n\t\t\t\t\t\t}\n\t\t\t\t\t}).then(() => {\n\t\t\t\t\t\t// If reconnection exhausted max attempts without success, clear flag\n\t\t\t\t\t\tengine.setReconnecting(false)\n\t\t\t\t\t})\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t})\n\n\t// Build sync control\n\tconst syncControl: SyncControl | null = config.sync\n\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}\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}\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 { status: 'offline', pendingOperations: 0, lastSyncedAt: null }\n\t\t\t\t},\n\t\t\t}\n\t\t: null\n\n\t// Build the KoraApp object\n\tconst app: KoraApp = {\n\t\tready,\n\t\tevents: emitter,\n\t\tsync: syncControl,\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 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 (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 (syncEngine) {\n\t\t\t\tawait syncEngine.stop()\n\t\t\t\tsyncEngine = 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}\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}> {\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(adapterType, dbName, config.store?.workerUrl)\n\n\t// Create and open the store\n\tconst store = new Store({\n\t\tschema: config.schema,\n\t\tadapter,\n\t\temitter,\n\t})\n\tawait store.open()\n\n\t// Wire sync if configured\n\tlet syncEngine: SyncEngine | null = null\n\tlet unsubscribeSync: (() => void) | null = null\n\n\tif (config.sync) {\n\t\tconst transport = new WebSocketTransport()\n\t\tconst mergeAwareStore = new MergeAwareSyncStore(store, mergeEngine, emitter)\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: config.sync.auth,\n\t\t\t\tbatchSize: config.sync.batchSize,\n\t\t\t\tschemaVersion: config.sync.schemaVersion ?? config.schema.version,\n\t\t\t},\n\t\t\temitter,\n\t\t})\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 { store, syncEngine, unsubscribeSync }\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\treturn []\n\t\t},\n\t\tasync count() {\n\t\t\treturn 0\n\t\t},\n\t\tsubscribe(callback: (results: Array<Record<string, unknown>>) => void) {\n\t\t\tvoid callback([])\n\t\t\treturn () => {}\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 { StorageAdapter } from '@korajs/store'\nimport type { AdapterType } from './types'\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): Promise<StorageAdapter> {\n\tswitch (type) {\n\t\tcase 'tauri-sqlite': {\n\t\t\t// Use Function-based import to prevent bundlers (Vite/Rollup/webpack)\n\t\t\t// from resolving @korajs/tauri at build time. This package is only\n\t\t\t// available in Tauri environments and must not be bundled for web.\n\t\t\tconst dynamicImport = new Function('specifier', 'return import(specifier)') as (\n\t\t\t\ts: string,\n\t\t\t) => Promise<{ TauriSqliteAdapter: new (opts: { path: string }) => StorageAdapter }>\n\t\t\tconst { TauriSqliteAdapter } = await dynamicImport('@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 })\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 })\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 { KoraEventEmitter, Operation, VersionVector } from '@korajs/core'\nimport type { MergeEngine, MergeInput } from '@korajs/merge'\nimport type { Store } from '@korajs/store'\nimport type { ApplyResult, SyncStore } from '@korajs/sync'\n\n/**\n * Wraps a Store to interpose merge resolution before applying remote operations.\n *\n * For inserts and deletes, delegates directly to the underlying Store.\n * For updates, checks whether the remote operation's previousData conflicts\n * with the current local state. If so, runs MergeEngine to resolve and\n * applies the merged result instead.\n *\n * This keeps MergeEngine integration out of Store and SyncEngine internals.\n */\nexport class MergeAwareSyncStore implements SyncStore {\n\tconstructor(\n\t\tprivate readonly store: Store,\n\t\tprivate readonly mergeEngine: MergeEngine,\n\t\tprivate readonly emitter: KoraEventEmitter | null,\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\t// Only intercept updates that have previousData (needed for 3-way merge)\n\t\tif (op.type !== 'update' || !op.data || !op.previousData) {\n\t\t\treturn this.store.applyRemoteOperation(op)\n\t\t}\n\n\t\t// Look up current local record to detect conflicts\n\t\tconst schema = this.store.getSchema()\n\t\tconst collectionDef = schema.collections[op.collection]\n\t\tif (!collectionDef) {\n\t\t\treturn this.store.applyRemoteOperation(op)\n\t\t}\n\n\t\tconst accessor = this.store.collection(op.collection)\n\t\tconst currentRecord = await accessor.findById(op.recordId)\n\n\t\t// If record doesn't exist locally, delegate directly\n\t\tif (!currentRecord) {\n\t\t\treturn this.store.applyRemoteOperation(op)\n\t\t}\n\n\t\t// Check for conflicts: do any of the remote op's changed fields differ\n\t\t// from what the remote op expected them to be (previousData)?\n\t\tlet hasConflict = false\n\t\tfor (const field of Object.keys(op.data)) {\n\t\t\tconst expectedBase = op.previousData[field]\n\t\t\tconst currentLocal = currentRecord[field]\n\n\t\t\t// If the local state doesn't match what the remote expected,\n\t\t\t// it means the local side also changed this field — conflict.\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\t// No conflict: safe to apply directly\n\t\tif (!hasConflict) {\n\t\t\treturn this.store.applyRemoteOperation(op)\n\t\t}\n\n\t\t// Conflict detected — run merge engine\n\t\t// Build a synthetic \"local operation\" representing the current local state changes\n\t\t// relative to the same base the remote operation used.\n\t\tthis.emitter?.emit({\n\t\t\ttype: 'merge:started',\n\t\t\toperationA: op,\n\t\t\toperationB: op,\n\t\t})\n\n\t\tconst baseState: Record<string, unknown> = { ...op.previousData }\n\t\tconst localOp: Operation = {\n\t\t\t...op,\n\t\t\t// The \"local\" operation's data is the diff between base and current local state\n\t\t\tdata: buildLocalDiff(op.previousData, currentRecord, Object.keys(op.data)),\n\t\t\tpreviousData: op.previousData,\n\t\t\tnodeId: this.store.getNodeId(),\n\t\t}\n\n\t\tconst input: MergeInput = {\n\t\t\tlocal: localOp,\n\t\t\tremote: op,\n\t\t\tbaseState,\n\t\t\tcollectionDef,\n\t\t}\n\n\t\tconst result = this.mergeEngine.mergeFields(input)\n\n\t\t// Emit merge traces\n\t\tfor (const trace of result.traces) {\n\t\t\tthis.emitter?.emit({ type: 'merge:conflict', trace })\n\t\t}\n\t\tconst firstTrace = result.traces[0]\n\t\tif (firstTrace) {\n\t\t\tthis.emitter?.emit({ type: 'merge:completed', trace: firstTrace })\n\t\t}\n\n\t\t// Create a modified operation with the merged data to apply\n\t\tconst mergedOp: Operation = {\n\t\t\t...op,\n\t\t\tdata: result.mergedData,\n\t\t}\n\n\t\treturn this.store.applyRemoteOperation(mergedOp)\n\t}\n}\n\n/**\n * Build the local diff: for each field the remote op changed,\n * extract the current local value (which may differ from both base and remote).\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\n/**\n * Simple deep equality check for comparing field values.\n * Handles primitives, arrays, and plain objects.\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,sBAAmC;AACnC,sBAA6B;AAC7B,mBAA4B;AAC5B,mBAAsB;AAGtB,kBAAuF;;;ACIhF,SAAS,oBAAiC;AAEhD,MACC,OAAO,eAAe,eACtB,OAAQ,WAAuC,wBAAwB,aACtE;AACD,WAAO;AAAA,EACR;AAGA,MAAI,OAAO,YAAY,eAAe,QAAQ,UAAU,MAAM;AAC7D,WAAO;AAAA,EACR;AAGA,MAAI,OAAO,WAAW,cAAc,aAAa;AAEhD,QAAI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,cAAc,EAAE,MAAM,UAAU;AAAA,IAChE;AAAA,EACD;AACD;AAEA,SAAS,0BAA0B,cAAqD;AACvF,QAAM,aAAa;AAAA,IAClB,YAAY;AAAA,IACZ,OAAO,EAAE,GAAG,aAAa;AAAA,IACzB,SAAS,CAAC;AAAA,IACV,OAAO;AAAA,IACP,QAAQ;AAAA,EACT;AAEA,QAAM,UAAU;AAAA,IACf,MAAM,YAAqC;AAC1C,iBAAW,QAAQ,EAAE,GAAG,WAAW,OAAO,GAAG,WAAW;AACxD,aAAO;AAAA,IACR;AAAA,IACA,QAAQ,OAAe,YAA4B,OAAO;AACzD,iBAAW,QAAQ,KAAK,EAAE,OAAO,UAAU,CAAC;AAC5C,aAAO;AAAA,IACR;AAAA,IACA,MAAM,GAAW;AAChB,iBAAW,QAAQ;AACnB,aAAO;AAAA,IACR;AAAA,IACA,OAAO,GAAW;AACjB,iBAAW,SAAS;AACpB,aAAO;AAAA,IACR;AAAA,IACA,MAAM,OAAO;AACZ,aAAO,CAAC;AAAA,IACT;AAAA,IACA,MAAM,QAAQ;AACb,aAAO;AAAA,IACR;AAAA,IACA,UAAU,UAA6D;AACtE,WAAK,SAAS,CAAC,CAAC;AAChB,aAAO,MAAM;AAAA,MAAC;AAAA,IACf;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;;;ADzVA,kBAAgC;AAChC,IAAAA,eAAmC;AACnC,IAAAA,eAA+B;AAC/B,IAAAA,eAAgC;AAChC,IAAAA,eAA0B;AA0B1B,IAAAC,gBAAsB;AAStB,IAAAC,gBAA4B;AAI5B,IAAAC,eAA+C;","names":["import_core","import_store","import_merge","import_sync"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/create-app.ts","../src/adapter-resolver.ts","../src/merge-aware-sync-store.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\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\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\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 type {\n\tCollectionAccessor,\n\tCollectionRecord,\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\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 { CollectionAccessor, StorageAdapter } from '@korajs/store'\nimport type { QueryBuilder } from '@korajs/store'\nimport {\n\tConnectionMonitor,\n\tReconnectionManager,\n\tSyncEngine,\n\tWebSocketTransport,\n} from '@korajs/sync'\nimport type { SyncStatusInfo } from '@korajs/sync'\nimport { createAdapter, detectAdapterType } from './adapter-resolver'\nimport { MergeAwareSyncStore } from './merge-aware-sync-store'\nimport type {\n\tKoraApp,\n\tKoraConfig,\n\tSequenceAccessor,\n\tSyncControl,\n\tTransactionProxy,\n\tTypedKoraApp,\n\tTypedKoraConfig,\n} from './types'\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(config: KoraConfig): KoraApp {\n\tconst emitter: KoraEventEmitter & { clear(): void } = new SimpleEventEmitter()\n\tconst mergeEngine = new MergeEngine()\n\n\tlet store: Store | null = null\n\tlet syncEngine: SyncEngine | null = null\n\tlet unsubscribeSync: (() => 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\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}\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\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// 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) 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\t\t}\n\t})\n\n\t// Build sync control\n\tconst syncControl: SyncControl | null = config.sync\n\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}\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}\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 {\n\t\t\t\t\t\tstatus: 'offline',\n\t\t\t\t\t\tpendingOperations: 0,\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}\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\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 txContext = store.createTransaction()\n\t\tif (mutationName !== undefined) {\n\t\t\ttxContext.setMutationName(mutationName)\n\t\t}\n\t\tconst collectionNames = Object.keys(config.schema.collections)\n\n\t\t// Build proxy with collection accessors as direct properties\n\t\tconst proxy: TransactionProxy = {} as TransactionProxy\n\t\tfor (const name of collectionNames) {\n\t\t\tObject.defineProperty(proxy, name, {\n\t\t\t\tget() {\n\t\t\t\t\treturn txContext.collection(name)\n\t\t\t\t},\n\t\t\t\tenumerable: true,\n\t\t\t\tconfigurable: false,\n\t\t\t})\n\t\t}\n\n\t\ttry {\n\t\t\tawait fn(proxy)\n\t\t\tconst { operations } = await txContext.commit()\n\n\t\t\t// Notify subscriptions and emit events after commit\n\t\t\tfor (const op of operations) {\n\t\t\t\tstore.getSubscriptionManager().notify(op.collection, op)\n\t\t\t\temitter.emit({ type: 'operation:created', operation: op })\n\t\t\t}\n\n\t\t\treturn operations\n\t\t} catch (error) {\n\t\t\ttxContext.rollback()\n\t\t\tthrow error\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 (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 (syncEngine) {\n\t\t\t\tawait syncEngine.stop()\n\t\t\t\tsyncEngine = 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}\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}> {\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(adapterType, dbName, config.store?.workerUrl)\n\n\t// Create and open the store\n\tconst store = new Store({\n\t\tschema: config.schema,\n\t\tadapter,\n\t\temitter,\n\t})\n\tawait store.open()\n\n\t// Wire sync if configured\n\tlet syncEngine: SyncEngine | null = null\n\tlet unsubscribeSync: (() => void) | null = null\n\n\tif (config.sync) {\n\t\tconst transport = new WebSocketTransport()\n\t\tconst mergeAwareStore = new MergeAwareSyncStore(store, mergeEngine, emitter)\n\n\t\t// Build scope map from schema scope declarations + flat scope values\n\t\tconst scopeMap = config.sync.scope ? buildScopeMap(config.schema, config.sync.scope) : 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: config.sync.auth,\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},\n\t\t\temitter,\n\t\t})\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 { store, syncEngine, unsubscribeSync }\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\treturn []\n\t\t},\n\t\tasync count() {\n\t\t\treturn 0\n\t\t},\n\t\tsubscribe(callback: (results: Array<Record<string, unknown>>) => void) {\n\t\t\tvoid callback([])\n\t\t\treturn () => {}\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 { StorageAdapter } from '@korajs/store'\nimport type { AdapterType } from './types'\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): 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// This code path only runs when __TAURI_INTERNALS__ is detected.\n\t\t\t// Using @vite-ignore so Vite doesn't statically analyze this import —\n\t\t\t// it will still resolve it at runtime through Vite's dev server.\n\t\t\tconst { TauriSqliteAdapter } = await import(/* @vite-ignore */ '@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 })\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 })\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 { KoraEventEmitter, Operation, VersionVector } from '@korajs/core'\nimport type { MergeEngine, MergeInput } from '@korajs/merge'\nimport type { Store } from '@korajs/store'\nimport type { ApplyResult, SyncStore } from '@korajs/sync'\n\n/**\n * Wraps a Store to interpose merge resolution before applying remote operations.\n *\n * For inserts and deletes, delegates directly to the underlying Store.\n * For updates, checks whether the remote operation's previousData conflicts\n * with the current local state. If so, runs MergeEngine to resolve and\n * applies the merged result instead.\n *\n * This keeps MergeEngine integration out of Store and SyncEngine internals.\n */\nexport class MergeAwareSyncStore implements SyncStore {\n\tconstructor(\n\t\tprivate readonly store: Store,\n\t\tprivate readonly mergeEngine: MergeEngine,\n\t\tprivate readonly emitter: KoraEventEmitter | null,\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\t// Only intercept updates that have previousData (needed for 3-way merge)\n\t\tif (op.type !== 'update' || !op.data || !op.previousData) {\n\t\t\treturn this.store.applyRemoteOperation(op)\n\t\t}\n\n\t\t// Look up current local record to detect conflicts\n\t\tconst schema = this.store.getSchema()\n\t\tconst collectionDef = schema.collections[op.collection]\n\t\tif (!collectionDef) {\n\t\t\treturn this.store.applyRemoteOperation(op)\n\t\t}\n\n\t\tconst accessor = this.store.collection(op.collection)\n\t\tconst currentRecord = await accessor.findById(op.recordId)\n\n\t\t// If record doesn't exist locally, delegate directly\n\t\tif (!currentRecord) {\n\t\t\treturn this.store.applyRemoteOperation(op)\n\t\t}\n\n\t\t// Check for conflicts: do any of the remote op's changed fields differ\n\t\t// from what the remote op expected them to be (previousData)?\n\t\tlet hasConflict = false\n\t\tfor (const field of Object.keys(op.data)) {\n\t\t\tconst expectedBase = op.previousData[field]\n\t\t\tconst currentLocal = currentRecord[field]\n\n\t\t\t// If the local state doesn't match what the remote expected,\n\t\t\t// it means the local side also changed this field — conflict.\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\t// No conflict: safe to apply directly\n\t\tif (!hasConflict) {\n\t\t\treturn this.store.applyRemoteOperation(op)\n\t\t}\n\n\t\t// Conflict detected — run merge engine\n\t\t// Build a synthetic \"local operation\" representing the current local state changes\n\t\t// relative to the same base the remote operation used.\n\t\tthis.emitter?.emit({\n\t\t\ttype: 'merge:started',\n\t\t\toperationA: op,\n\t\t\toperationB: op,\n\t\t})\n\n\t\tconst baseState: Record<string, unknown> = { ...op.previousData }\n\t\tconst localOp: Operation = {\n\t\t\t...op,\n\t\t\t// The \"local\" operation's data is the diff between base and current local state\n\t\t\tdata: buildLocalDiff(op.previousData, currentRecord, Object.keys(op.data)),\n\t\t\tpreviousData: op.previousData,\n\t\t\tnodeId: this.store.getNodeId(),\n\t\t}\n\n\t\tconst input: MergeInput = {\n\t\t\tlocal: localOp,\n\t\t\tremote: op,\n\t\t\tbaseState,\n\t\t\tcollectionDef,\n\t\t}\n\n\t\tconst result = this.mergeEngine.mergeFields(input)\n\n\t\t// Emit merge traces\n\t\tfor (const trace of result.traces) {\n\t\t\tthis.emitter?.emit({ type: 'merge:conflict', trace })\n\t\t}\n\t\tconst firstTrace = result.traces[0]\n\t\tif (firstTrace) {\n\t\t\tthis.emitter?.emit({ type: 'merge:completed', trace: firstTrace })\n\t\t}\n\n\t\t// Create a modified operation with the merged data to apply\n\t\tconst mergedOp: Operation = {\n\t\t\t...op,\n\t\t\tdata: result.mergedData,\n\t\t}\n\n\t\treturn this.store.applyRemoteOperation(mergedOp)\n\t}\n}\n\n/**\n * Build the local diff: for each field the remote op changed,\n * extract the current local value (which may differ from both base and remote).\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\n/**\n * Simple deep equality check for comparing field values.\n * Handles primitives, arrays, and plain objects.\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,kBAA8B;AAC9B,sBAAmC;AACnC,sBAA6B;AAC7B,mBAA4B;AAC5B,mBAAsB;AAGtB,kBAKO;;;ACFA,SAAS,oBAAiC;AAEhD,MACC,OAAO,eAAe,eACtB,OAAQ,WAAuC,wBAAwB,aACtE;AACD,WAAO;AAAA,EACR;AAGA,MAAI,OAAO,YAAY,eAAe,QAAQ,UAAU,MAAM;AAC7D,WAAO;AAAA,EACR;AAGA,MAAI,OAAO,WAAW,cAAc,aAAa;AAEhD,QAAI,OAAQ,WAAuC,qBAAqB,aAAa;AACpF,aAAO;AAAA,IACR;AACA,WAAO;AAAA,EACR;AAGA,SAAO;AACR;AAUA,eAAsB,cACrB,MACA,QACA,WAC0B;AAC1B,UAAQ,MAAM;AAAA,IACb,KAAK,gBAAgB;AAKpB,YAAM,EAAE,mBAAmB,IAAI,MAAM;AAAA;AAAA,QAA0B;AA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