korajs 1.0.0-beta.8 → 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 +36 -3
- 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 +36 -3
- package/dist/index.js.map +1 -1
- package/package.json +13 -13
package/dist/index.cjs
CHANGED
|
@@ -1317,7 +1317,10 @@ function createSyncQuerySubscriptionHook(getSyncEngine) {
|
|
|
1317
1317
|
// src/initialize-app.ts
|
|
1318
1318
|
async function initializeApp(config, emitter, mergeEngine) {
|
|
1319
1319
|
const adapterType = config.store?.adapter ?? detectAdapterType();
|
|
1320
|
-
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);
|
|
1321
1324
|
let adapter = await createAdapter(
|
|
1322
1325
|
adapterType,
|
|
1323
1326
|
dbName,
|
|
@@ -1327,7 +1330,6 @@ async function initializeApp(config, emitter, mergeEngine) {
|
|
|
1327
1330
|
config.store?.sharedWorkerUrl,
|
|
1328
1331
|
adapterType === "sqlite-wasm"
|
|
1329
1332
|
);
|
|
1330
|
-
const authBinding = config.sync?.authClient ?? null;
|
|
1331
1333
|
const authNodeId = authBinding?.resolveNodeId ? await authBinding.resolveNodeId() : void 0;
|
|
1332
1334
|
let syncEngine = null;
|
|
1333
1335
|
const encryptionKey = config.sync?.encryption?.key;
|
|
@@ -1458,6 +1460,23 @@ function emitOpfsUnavailable(emitter, dbName, reason) {
|
|
|
1458
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.`
|
|
1459
1461
|
});
|
|
1460
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
|
+
}
|
|
1461
1480
|
|
|
1462
1481
|
// src/sequences-accessor.ts
|
|
1463
1482
|
function createSequencesAccessor(ready, getStore) {
|
|
@@ -1544,6 +1563,16 @@ function createSyncControl(options) {
|
|
|
1544
1563
|
state.syncStatusBridge?.refresh();
|
|
1545
1564
|
}
|
|
1546
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
|
+
},
|
|
1547
1576
|
getStatus() {
|
|
1548
1577
|
if (state.syncEngine) {
|
|
1549
1578
|
return state.syncEngine.getStatus();
|
|
@@ -1580,6 +1609,7 @@ function createSyncControl(options) {
|
|
|
1580
1609
|
state: "disconnected",
|
|
1581
1610
|
status: {
|
|
1582
1611
|
status: "offline",
|
|
1612
|
+
reconnecting: false,
|
|
1583
1613
|
pendingOperations: 0,
|
|
1584
1614
|
lastSyncedAt: null,
|
|
1585
1615
|
lastSuccessfulPush: null,
|
|
@@ -1598,6 +1628,8 @@ function createSyncControl(options) {
|
|
|
1598
1628
|
pendingOperations: 0,
|
|
1599
1629
|
hasInFlightBatch: false,
|
|
1600
1630
|
reconnecting: false,
|
|
1631
|
+
deliveryWatermark: 0,
|
|
1632
|
+
deliveryGapRepeatCount: 0,
|
|
1601
1633
|
timestamp: Date.now()
|
|
1602
1634
|
};
|
|
1603
1635
|
}
|
|
@@ -1654,7 +1686,8 @@ var AuthSyncCoordinator = class {
|
|
|
1654
1686
|
}
|
|
1655
1687
|
const status = engine.getStatus().status;
|
|
1656
1688
|
if (status !== "offline") {
|
|
1657
|
-
await engine.
|
|
1689
|
+
await engine.reconnect();
|
|
1690
|
+
return;
|
|
1658
1691
|
}
|
|
1659
1692
|
await engine.start();
|
|
1660
1693
|
}
|