korajs 1.0.0-beta.1 → 1.0.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -228,7 +228,13 @@ async function createAdapter(type, dbName, workerUrl, emitter, workerResponseTim
228
228
  }
229
229
  case "sqlite-wasm": {
230
230
  const { SqliteWasmAdapter } = await import("@korajs/store/sqlite-wasm");
231
- return new SqliteWasmAdapter({ dbName, workerUrl, sharedWorkerUrl, workerResponseTimeoutMs });
231
+ return new SqliteWasmAdapter({
232
+ dbName,
233
+ workerUrl,
234
+ sharedWorkerUrl,
235
+ workerResponseTimeoutMs,
236
+ emitter
237
+ });
232
238
  }
233
239
  case "indexeddb": {
234
240
  const { IndexedDbAdapter } = await import("@korajs/store/indexeddb");
@@ -1109,6 +1115,50 @@ function operationFromQueuePayload(payload) {
1109
1115
  };
1110
1116
  }
1111
1117
 
1118
+ // src/store-rejected-storage.ts
1119
+ var StoreRejectedOperationStorage = class {
1120
+ constructor(adapter) {
1121
+ this.adapter = adapter;
1122
+ }
1123
+ adapter;
1124
+ async record(rejected) {
1125
+ await this.adapter.execute(
1126
+ "INSERT OR REPLACE INTO _kora_sync_rejected (operation_id, collection, record_id, code, message, retriable, rejected_at) VALUES (?, ?, ?, ?, ?, ?, ?)",
1127
+ [
1128
+ rejected.operationId,
1129
+ rejected.collection,
1130
+ rejected.recordId,
1131
+ rejected.code,
1132
+ rejected.message,
1133
+ rejected.retriable ? 1 : 0,
1134
+ rejected.rejectedAt
1135
+ ]
1136
+ );
1137
+ }
1138
+ async list() {
1139
+ const rows = await this.adapter.query(
1140
+ "SELECT operation_id, collection, record_id, code, message, retriable, rejected_at FROM _kora_sync_rejected ORDER BY rejected_at ASC"
1141
+ );
1142
+ return rows.map((row) => ({
1143
+ operationId: row.operation_id,
1144
+ collection: row.collection,
1145
+ recordId: row.record_id,
1146
+ code: row.code,
1147
+ message: row.message,
1148
+ retriable: row.retriable === 1,
1149
+ rejectedAt: row.rejected_at
1150
+ }));
1151
+ }
1152
+ async remove(operationIds) {
1153
+ if (operationIds.length === 0) return;
1154
+ const placeholders = operationIds.map(() => "?").join(", ");
1155
+ await this.adapter.execute(
1156
+ `DELETE FROM _kora_sync_rejected WHERE operation_id IN (${placeholders})`,
1157
+ operationIds
1158
+ );
1159
+ }
1160
+ };
1161
+
1112
1162
  // src/store-sync-state.ts
1113
1163
  var import_store7 = require("@korajs/store");
1114
1164
  var import_sync2 = require("@korajs/sync");
@@ -1255,6 +1305,7 @@ async function initializeApp(config, emitter, mergeEngine) {
1255
1305
  },
1256
1306
  emitter,
1257
1307
  queueStorage: new StoreQueueStorage(adapter),
1308
+ rejectedStorage: new StoreRejectedOperationStorage(adapter),
1258
1309
  syncState: new StoreSyncStatePersistence(store, scopeMap),
1259
1310
  encryptor
1260
1311
  });
@@ -1384,6 +1435,19 @@ function createSyncControl(options) {
1384
1435
  clearSchemaBlock() {
1385
1436
  state.syncEngine?.clearSchemaBlock();
1386
1437
  },
1438
+ async getRejectedOperations() {
1439
+ await ready;
1440
+ if (state.syncEngine) {
1441
+ return state.syncEngine.getRejectedOperations();
1442
+ }
1443
+ return [];
1444
+ },
1445
+ async clearRejectedOperations(operationIds) {
1446
+ await ready;
1447
+ if (state.syncEngine) {
1448
+ await state.syncEngine.clearRejectedOperations(operationIds);
1449
+ }
1450
+ },
1387
1451
  exportDiagnostics() {
1388
1452
  if (state.syncEngine) {
1389
1453
  return state.syncEngine.exportDiagnostics();
@@ -1705,6 +1769,7 @@ var SYNC_EVENT_TYPES = [
1705
1769
  "sync:received",
1706
1770
  "sync:acknowledged",
1707
1771
  "sync:apply-failed",
1772
+ "sync:operation-rejected",
1708
1773
  "sync:diagnostics",
1709
1774
  "sync:bandwidth",
1710
1775
  "sync:initial-sync-progress"