korajs 1.0.0-beta.7 → 1.0.0-beta.9
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 +37 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +37 -11
- package/dist/index.js.map +1 -1
- package/package.json +13 -13
package/dist/index.cjs
CHANGED
|
@@ -1294,12 +1294,9 @@ function queryDescriptorToSyncSubset(descriptor) {
|
|
|
1294
1294
|
}
|
|
1295
1295
|
if (skippedFields.length > 0 && typeof console !== "undefined") {
|
|
1296
1296
|
console.warn(
|
|
1297
|
-
`[Kora] Sync query subset
|
|
1297
|
+
`[Kora] Sync query subset widened non-equality filters on ${descriptor.collection}: ${skippedFields.join(", ")}. Only plain equality WHERE clauses are represented for incremental sync; unsupported predicates sync the containing collection subset and are filtered locally.`
|
|
1298
1298
|
);
|
|
1299
1299
|
}
|
|
1300
|
-
if (Object.keys(where).length === 0) {
|
|
1301
|
-
return null;
|
|
1302
|
-
}
|
|
1303
1300
|
return {
|
|
1304
1301
|
collection: descriptor.collection,
|
|
1305
1302
|
where
|
|
@@ -1308,10 +1305,6 @@ function queryDescriptorToSyncSubset(descriptor) {
|
|
|
1308
1305
|
function createSyncQuerySubscriptionHook(getSyncEngine) {
|
|
1309
1306
|
return (descriptor) => {
|
|
1310
1307
|
const subset = queryDescriptorToSyncSubset(descriptor);
|
|
1311
|
-
if (!subset) {
|
|
1312
|
-
return () => {
|
|
1313
|
-
};
|
|
1314
|
-
}
|
|
1315
1308
|
const engine = getSyncEngine();
|
|
1316
1309
|
if (!engine) {
|
|
1317
1310
|
return () => {
|
|
@@ -1324,7 +1317,10 @@ function createSyncQuerySubscriptionHook(getSyncEngine) {
|
|
|
1324
1317
|
// src/initialize-app.ts
|
|
1325
1318
|
async function initializeApp(config, emitter, mergeEngine) {
|
|
1326
1319
|
const adapterType = config.store?.adapter ?? detectAdapterType();
|
|
1327
|
-
const
|
|
1320
|
+
const baseDbName = config.store?.name ?? "kora-db";
|
|
1321
|
+
const authBinding = config.sync?.authClient ?? null;
|
|
1322
|
+
const authUserId = config.store?.namespaceByAuthUser && authBinding?.resolveUserId ? await authBinding.resolveUserId() : void 0;
|
|
1323
|
+
const dbName = resolveLocalDbName(baseDbName, authUserId, config.store?.namespaceByAuthUser);
|
|
1328
1324
|
let adapter = await createAdapter(
|
|
1329
1325
|
adapterType,
|
|
1330
1326
|
dbName,
|
|
@@ -1334,7 +1330,6 @@ async function initializeApp(config, emitter, mergeEngine) {
|
|
|
1334
1330
|
config.store?.sharedWorkerUrl,
|
|
1335
1331
|
adapterType === "sqlite-wasm"
|
|
1336
1332
|
);
|
|
1337
|
-
const authBinding = config.sync?.authClient ?? null;
|
|
1338
1333
|
const authNodeId = authBinding?.resolveNodeId ? await authBinding.resolveNodeId() : void 0;
|
|
1339
1334
|
let syncEngine = null;
|
|
1340
1335
|
const encryptionKey = config.sync?.encryption?.key;
|
|
@@ -1465,6 +1460,23 @@ function emitOpfsUnavailable(emitter, dbName, reason) {
|
|
|
1465
1460
|
message: `OPFS persistence is unavailable (${reason}) for database "${dbName}", and IndexedDB fallback could not open; the store is running in memory and data will not survive a reload.`
|
|
1466
1461
|
});
|
|
1467
1462
|
}
|
|
1463
|
+
function resolveLocalDbName(baseName, authUserId, namespaceByAuthUser) {
|
|
1464
|
+
if (!namespaceByAuthUser) {
|
|
1465
|
+
return baseName;
|
|
1466
|
+
}
|
|
1467
|
+
return `${baseName}__user_${encodeDbNameComponent(authUserId ?? "signed-out")}`;
|
|
1468
|
+
}
|
|
1469
|
+
function encodeDbNameComponent(value) {
|
|
1470
|
+
let encoded = "";
|
|
1471
|
+
for (const char of value) {
|
|
1472
|
+
if (/^[A-Za-z0-9._-]$/.test(char)) {
|
|
1473
|
+
encoded += char;
|
|
1474
|
+
continue;
|
|
1475
|
+
}
|
|
1476
|
+
encoded += `_${char.codePointAt(0)?.toString(16) ?? "0"}`;
|
|
1477
|
+
}
|
|
1478
|
+
return encoded || "empty";
|
|
1479
|
+
}
|
|
1468
1480
|
|
|
1469
1481
|
// src/sequences-accessor.ts
|
|
1470
1482
|
function createSequencesAccessor(ready, getStore) {
|
|
@@ -1551,6 +1563,16 @@ function createSyncControl(options) {
|
|
|
1551
1563
|
state.syncStatusBridge?.refresh();
|
|
1552
1564
|
}
|
|
1553
1565
|
},
|
|
1566
|
+
async reconnect() {
|
|
1567
|
+
await ready;
|
|
1568
|
+
if (state.syncEngine) {
|
|
1569
|
+
state.intentionalDisconnect = false;
|
|
1570
|
+
state.reconnectionManager?.stop();
|
|
1571
|
+
state.reconnectionManager?.reset();
|
|
1572
|
+
await state.syncEngine.reconnect();
|
|
1573
|
+
state.syncStatusBridge?.refresh();
|
|
1574
|
+
}
|
|
1575
|
+
},
|
|
1554
1576
|
getStatus() {
|
|
1555
1577
|
if (state.syncEngine) {
|
|
1556
1578
|
return state.syncEngine.getStatus();
|
|
@@ -1587,6 +1609,7 @@ function createSyncControl(options) {
|
|
|
1587
1609
|
state: "disconnected",
|
|
1588
1610
|
status: {
|
|
1589
1611
|
status: "offline",
|
|
1612
|
+
reconnecting: false,
|
|
1590
1613
|
pendingOperations: 0,
|
|
1591
1614
|
lastSyncedAt: null,
|
|
1592
1615
|
lastSuccessfulPush: null,
|
|
@@ -1605,6 +1628,8 @@ function createSyncControl(options) {
|
|
|
1605
1628
|
pendingOperations: 0,
|
|
1606
1629
|
hasInFlightBatch: false,
|
|
1607
1630
|
reconnecting: false,
|
|
1631
|
+
deliveryWatermark: 0,
|
|
1632
|
+
deliveryGapRepeatCount: 0,
|
|
1608
1633
|
timestamp: Date.now()
|
|
1609
1634
|
};
|
|
1610
1635
|
}
|
|
@@ -1661,7 +1686,8 @@ var AuthSyncCoordinator = class {
|
|
|
1661
1686
|
}
|
|
1662
1687
|
const status = engine.getStatus().status;
|
|
1663
1688
|
if (status !== "offline") {
|
|
1664
|
-
await engine.
|
|
1689
|
+
await engine.reconnect();
|
|
1690
|
+
return;
|
|
1665
1691
|
}
|
|
1666
1692
|
await engine.start();
|
|
1667
1693
|
}
|