@keepkit/core 0.28.13 → 0.28.14
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/README.md +5 -1
- package/dist/{chunk-CSBPFROD.js → chunk-36NNVLEU.js} +2 -2
- package/dist/{chunk-SS22UTBH.js → chunk-WKXLHEAK.js} +181 -31
- package/dist/chunk-WKXLHEAK.js.map +1 -0
- package/dist/core.d.ts +7 -6
- package/dist/core.js +167 -13
- package/dist/core.js.map +1 -1
- package/dist/react.d.ts +4 -4
- package/dist/react.js +2 -2
- package/dist/schema.d.ts +1 -1
- package/dist/storage.d.ts +15 -2
- package/dist/storage.js +1 -1
- package/dist/{store-C8cxvXRV.d.ts → store-D-ZFtgDn.d.ts} +1 -1
- package/dist/{types-DjXvE9Zb.d.ts → types-KNIY89_m.d.ts} +24 -1
- package/package.json +1 -1
- package/dist/chunk-SS22UTBH.js.map +0 -1
- /package/dist/{chunk-CSBPFROD.js.map → chunk-36NNVLEU.js.map} +0 -0
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[日本語](#日本語) | [English](#english)
|
|
4
4
|
|
|
5
|
-
Release: v0.28.
|
|
5
|
+
Release: v0.28.14
|
|
6
6
|
|
|
7
7
|
## 日本語
|
|
8
8
|
|
|
@@ -81,6 +81,8 @@ hooksはProvider内のコンポーネントで呼び出します。
|
|
|
81
81
|
|
|
82
82
|
- `createBrowserStorageAdapter`はIndexedDB優先で、localStorageへフォールバックします。`scope`でユーザー/テナントを分離できます。
|
|
83
83
|
- `SyncStorageAdapter`と`RemoteSyncDriver`で永続オフラインキュー・再試行・競合処理を組み込みます。定義・所属の同期には、それぞれ`pushCollection` / `pullCollections`、`pushMembership` / `pullMemberships`が必要です。
|
|
84
|
+
- `remote.pull()`の結果は既定(`itemPullMode: "merge"`)で部分的な一覧として統合し、ローカルのアイテムを削除しません。APIがscope内の全アイテムを返す場合は`itemPullMode: "snapshot"`を指定すると、サーバー受理済み(`revision`あり)で一覧から消えたアイテムを削除します。未送信の変更があるアイテムは残るため、オフライン中に編集したアイテムは再送されます。pullしたアイテムの`revision`がローカルと異なる場合は、`updatedAt`にかかわらずサーバー版を採用します。
|
|
85
|
+
- 400〜499のうち認証・一時エラーではないpush失敗は`getSyncState().rejectedOperations`に残り、独立した後続操作は同期を続けます。ホストは`resolveRejectedSyncOperation(operationId, "retry" | "discard")`で再試行または破棄できます。共有localStorageキューは複数タブの追加・削除をWeb Locks APIで直列化します。ブラウザーがWeb Locksに対応しない場合、安全な更新を拒否します。
|
|
84
86
|
- 認証方式はアプリ側で管理します。[認証付き同期の例](../../examples/authenticated-sync/README.md)でトークン取得とscope切り替えを確認できます。
|
|
85
87
|
- `exportItems(storage)` / `importItems(storage, json, { mode: "merge" })`で保存アイテム・コレクション定義・所属をバックアップ・復元します。閲覧履歴・鑑賞記録・進行位置は含みません。
|
|
86
88
|
|
|
@@ -192,6 +194,8 @@ Failures in `before` plugins or persistence reject the mutation. Errors from pos
|
|
|
192
194
|
|
|
193
195
|
- `createBrowserStorageAdapter` prefers IndexedDB and falls back to localStorage. Use `scope` to isolate users and tenants.
|
|
194
196
|
- Combine `SyncStorageAdapter` and `RemoteSyncDriver` for durable offline queues, retries, and conflicts. Definition and membership sync require `pushCollection` / `pullCollections` and `pushMembership` / `pullMemberships`, respectively.
|
|
197
|
+
- By default (`itemPullMode: "merge"`), `remote.pull()` results are merged as a partial list and never delete local items. If your API returns every item in the scope, set `itemPullMode: "snapshot"` to remove server-acknowledged items (with a `revision`) that are no longer listed. Items with pending local changes are kept, so an item edited offline is pushed again. A pulled item whose `revision` differs from the local copy is adopted regardless of `updatedAt`.
|
|
198
|
+
- Non-authentication, non-transient 4xx push failures are retained in `getSyncState().rejectedOperations`, while later independent operations continue syncing. Hosts can retry or discard one with `resolveRejectedSyncOperation(operationId, "retry" | "discard")`. Shared localStorage queues serialize cross-tab additions and removals with the Web Locks API and reject unsafe writes in browsers without it.
|
|
195
199
|
- Authentication belongs to your app. See the [authenticated sync example](../../examples/authenticated-sync/README.md) for tokens and scope changes.
|
|
196
200
|
- Use `exportItems(storage)` / `importItems(storage, json, { mode: "merge" })` to back up and restore saved items, collection definitions, and memberships. History, viewing records, and progress are excluded.
|
|
197
201
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
persistKeepItems,
|
|
3
3
|
removeKeepItems
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-WKXLHEAK.js";
|
|
5
5
|
|
|
6
6
|
// src/features/items/navigation.ts
|
|
7
7
|
function orderKeepItems(items) {
|
|
@@ -273,4 +273,4 @@ export {
|
|
|
273
273
|
reconcileKeepItems,
|
|
274
274
|
KeepStore
|
|
275
275
|
};
|
|
276
|
-
//# sourceMappingURL=chunk-
|
|
276
|
+
//# sourceMappingURL=chunk-36NNVLEU.js.map
|
|
@@ -403,6 +403,17 @@ function collectionKey(collectionId, scope) {
|
|
|
403
403
|
// src/features/persistence/backup.ts
|
|
404
404
|
var KEEP_BACKUP_FORMAT = "keepkit";
|
|
405
405
|
var KEEP_BACKUP_VERSION = 2;
|
|
406
|
+
function inspectKeepBackup(data) {
|
|
407
|
+
const backup = parseBackup(data);
|
|
408
|
+
return {
|
|
409
|
+
version: backup.version,
|
|
410
|
+
exportedAt: backup.exportedAt,
|
|
411
|
+
itemCount: backup.items.length,
|
|
412
|
+
collectionCount: backup.collections.length,
|
|
413
|
+
membershipCount: backup.memberships.length,
|
|
414
|
+
scopes: collectScopes(backup.items, backup.collections, backup.memberships, backup.scopes)
|
|
415
|
+
};
|
|
416
|
+
}
|
|
406
417
|
var KeepBackupParseError = class extends Error {
|
|
407
418
|
constructor(message, options) {
|
|
408
419
|
super(message);
|
|
@@ -439,6 +450,26 @@ async function exportItems(adapter) {
|
|
|
439
450
|
const json = JSON.parse(serialized);
|
|
440
451
|
return JSON.stringify(json, null, 2);
|
|
441
452
|
}
|
|
453
|
+
function formatItemsAsMarkdown(items, options = {}) {
|
|
454
|
+
if (items.length === 0) return "";
|
|
455
|
+
return items.map((item) => {
|
|
456
|
+
const meta = isRecord(item.meta) ? item.meta : {};
|
|
457
|
+
const rawTitle = typeof meta.title === "string" && meta.title.trim() ? meta.title.trim() : item.id;
|
|
458
|
+
const rawUrl = typeof meta.url === "string" && meta.url.trim() ? meta.url.trim() : void 0;
|
|
459
|
+
const link = rawUrl ? `[${rawTitle}](${rawUrl})` : rawTitle;
|
|
460
|
+
const details = [];
|
|
461
|
+
if (item.collectionId) {
|
|
462
|
+
details.push(`Collection: ${options.collectionLabels?.[item.collectionId] ?? item.collectionId}`);
|
|
463
|
+
}
|
|
464
|
+
if (item.tags && item.tags.length > 0) {
|
|
465
|
+
details.push(`Tags: ${item.tags.map((tag) => `#${tag}`).join(" ")}`);
|
|
466
|
+
}
|
|
467
|
+
if (item.note?.trim()) {
|
|
468
|
+
details.push(item.note.trim());
|
|
469
|
+
}
|
|
470
|
+
return details.length > 0 ? `- ${link} \u2014 ${details.join(" | ")}` : `- ${link}`;
|
|
471
|
+
}).join("\n");
|
|
472
|
+
}
|
|
442
473
|
async function importItems(adapter, data, options = {}) {
|
|
443
474
|
const backup = parseBackup(data);
|
|
444
475
|
const mode = options.mode ?? "merge";
|
|
@@ -1478,6 +1509,40 @@ var LocalStorageSyncQueueAdapter = class {
|
|
|
1478
1509
|
this.storage = options.storage ?? getBrowserStorage();
|
|
1479
1510
|
}
|
|
1480
1511
|
async getAll() {
|
|
1512
|
+
return this.readAll();
|
|
1513
|
+
}
|
|
1514
|
+
async setMany(operations) {
|
|
1515
|
+
if (!this.storage) return;
|
|
1516
|
+
await withLocalStorageWriteLock(
|
|
1517
|
+
this.key,
|
|
1518
|
+
async () => {
|
|
1519
|
+
const byId = new Map((await this.readAll()).map((operation) => [operation.operationId, operation]));
|
|
1520
|
+
for (const operation of operations) byId.set(operation.operationId, operation);
|
|
1521
|
+
this.writeAll([...byId.values()]);
|
|
1522
|
+
},
|
|
1523
|
+
new Error("KeepKit needs the Web Locks API to safely update a sync queue across tabs.")
|
|
1524
|
+
);
|
|
1525
|
+
}
|
|
1526
|
+
async remove(operationIds) {
|
|
1527
|
+
if (!this.storage || operationIds.length === 0) return;
|
|
1528
|
+
await withLocalStorageWriteLock(
|
|
1529
|
+
this.key,
|
|
1530
|
+
async () => {
|
|
1531
|
+
const ids = new Set(operationIds);
|
|
1532
|
+
this.writeAll((await this.readAll()).filter((operation) => !ids.has(operation.operationId)));
|
|
1533
|
+
},
|
|
1534
|
+
new Error("KeepKit needs the Web Locks API to safely update a sync queue across tabs.")
|
|
1535
|
+
);
|
|
1536
|
+
}
|
|
1537
|
+
async clear() {
|
|
1538
|
+
if (!this.storage) return;
|
|
1539
|
+
await withLocalStorageWriteLock(
|
|
1540
|
+
this.key,
|
|
1541
|
+
async () => this.storage?.removeItem(this.key),
|
|
1542
|
+
new Error("KeepKit needs the Web Locks API to safely update a sync queue across tabs.")
|
|
1543
|
+
);
|
|
1544
|
+
}
|
|
1545
|
+
async readAll() {
|
|
1481
1546
|
if (!this.storage) return [];
|
|
1482
1547
|
const raw = this.storage.getItem(this.key);
|
|
1483
1548
|
if (!raw) return [];
|
|
@@ -1492,19 +1557,11 @@ var LocalStorageSyncQueueAdapter = class {
|
|
|
1492
1557
|
}
|
|
1493
1558
|
return value;
|
|
1494
1559
|
}
|
|
1495
|
-
|
|
1560
|
+
writeAll(operations) {
|
|
1496
1561
|
if (!this.storage) return;
|
|
1497
1562
|
const serialized = serializeKeepStorage(operations, { operation: "set", storageKey: this.key });
|
|
1498
1563
|
this.storage.setItem(this.key, serialized);
|
|
1499
1564
|
}
|
|
1500
|
-
async remove(operationIds) {
|
|
1501
|
-
const ids = new Set(operationIds);
|
|
1502
|
-
const current = await this.getAll();
|
|
1503
|
-
await this.setMany(current.filter((operation) => !ids.has(operation.operationId)));
|
|
1504
|
-
}
|
|
1505
|
-
async clear() {
|
|
1506
|
-
this.storage?.removeItem(this.key);
|
|
1507
|
-
}
|
|
1508
1565
|
};
|
|
1509
1566
|
var IndexedDBSyncQueueAdapter = class {
|
|
1510
1567
|
constructor(options = {}) {
|
|
@@ -1614,6 +1671,7 @@ var SyncStorageAdapter = class {
|
|
|
1614
1671
|
this.queueLoaded = false;
|
|
1615
1672
|
this.state = { status: "idle", pendingCount: 0, conflictIds: [], conflicts: [] };
|
|
1616
1673
|
this.conflicts = /* @__PURE__ */ new Map();
|
|
1674
|
+
this.rejectedOperations = /* @__PURE__ */ new Map();
|
|
1617
1675
|
this.disposed = false;
|
|
1618
1676
|
this.getSyncState = () => this.state;
|
|
1619
1677
|
this.subscribeSync = (listener) => {
|
|
@@ -1639,6 +1697,7 @@ var SyncStorageAdapter = class {
|
|
|
1639
1697
|
this.maxRetries = Math.max(0, options.maxRetries ?? 3);
|
|
1640
1698
|
this.retryDelayMs = Math.max(0, options.retryDelayMs ?? 0);
|
|
1641
1699
|
this.retryBackoff = Math.max(1, options.retryBackoff ?? 2);
|
|
1700
|
+
this.itemPullMode = options.itemPullMode ?? "merge";
|
|
1642
1701
|
this.storageKey = this.local.storageKey;
|
|
1643
1702
|
const localRecovery = this.local.recovery;
|
|
1644
1703
|
if (localRecovery && isSameKeepScope(this.local.scope, this.scope ?? this.local.scope)) {
|
|
@@ -1874,6 +1933,18 @@ var SyncStorageAdapter = class {
|
|
|
1874
1933
|
});
|
|
1875
1934
|
if (resolution !== "remote" && this.queueItems.length > 0) await this.flushSync();
|
|
1876
1935
|
}
|
|
1936
|
+
async resolveRejectedSyncOperation(operationId, resolution) {
|
|
1937
|
+
await this.loadQueue();
|
|
1938
|
+
if (!this.rejectedOperations.has(operationId)) return;
|
|
1939
|
+
if (resolution === "discard") {
|
|
1940
|
+
await this.removeQueued(operationId);
|
|
1941
|
+
if (this.queueItems.length > 0) await this.flushSync();
|
|
1942
|
+
return;
|
|
1943
|
+
}
|
|
1944
|
+
this.rejectedOperations.delete(operationId);
|
|
1945
|
+
this.updateState({ status: "pending", error: void 0 });
|
|
1946
|
+
await this.flushSync();
|
|
1947
|
+
}
|
|
1877
1948
|
async resolveCollectionSyncConflict(id, resolution, collection) {
|
|
1878
1949
|
await this.loadQueue();
|
|
1879
1950
|
const conflict = (this.state.collectionConflicts ?? []).find((entry) => entry.operation.id === id);
|
|
@@ -1932,6 +2003,10 @@ var SyncStorageAdapter = class {
|
|
|
1932
2003
|
this.updateState({ status: "syncing", error: void 0 });
|
|
1933
2004
|
for (const operation of [...this.queueItems]) {
|
|
1934
2005
|
if (this.disposed) return;
|
|
2006
|
+
const isBlocked = [...this.rejectedOperations.values()].some(
|
|
2007
|
+
({ operation: rejected }) => rejected.operationId !== operation.operationId && dependsOnRejectedOperation(operation, rejected)
|
|
2008
|
+
);
|
|
2009
|
+
if (isBlocked) continue;
|
|
1935
2010
|
try {
|
|
1936
2011
|
if (isCollectionSyncOperation(operation)) {
|
|
1937
2012
|
if (!this.remote.pushCollection) throw new Error("Remote sync driver does not support collection sync.");
|
|
@@ -2012,11 +2087,25 @@ var SyncStorageAdapter = class {
|
|
|
2012
2087
|
conflicts: [...this.conflicts.values()].filter((conflict) => conflict.id !== operation.id)
|
|
2013
2088
|
});
|
|
2014
2089
|
} catch (error) {
|
|
2090
|
+
if (isPermanentSyncError(error)) {
|
|
2091
|
+
this.rejectedOperations.set(operation.operationId, { operation, error });
|
|
2092
|
+
this.updateState({ status: "syncing" });
|
|
2093
|
+
continue;
|
|
2094
|
+
}
|
|
2015
2095
|
this.updateState({ status: "error", error });
|
|
2016
2096
|
return;
|
|
2017
2097
|
}
|
|
2018
2098
|
}
|
|
2019
|
-
if (this.
|
|
2099
|
+
if (this.rejectedOperations.size > 0) {
|
|
2100
|
+
const rejected = [...this.rejectedOperations.values()];
|
|
2101
|
+
this.updateState({
|
|
2102
|
+
status: "error",
|
|
2103
|
+
error: rejected[rejected.length - 1]?.error,
|
|
2104
|
+
rejectedOperations: rejected
|
|
2105
|
+
});
|
|
2106
|
+
} else if (this.queueItems.length === 0) {
|
|
2107
|
+
this.updateState({ status: "synced", pendingCount: 0 });
|
|
2108
|
+
}
|
|
2020
2109
|
}
|
|
2021
2110
|
createOperation(type, id, item) {
|
|
2022
2111
|
return {
|
|
@@ -2057,13 +2146,21 @@ var SyncStorageAdapter = class {
|
|
|
2057
2146
|
applyScope(item) {
|
|
2058
2147
|
return this.scope ? { ...item, scope: this.scope } : item;
|
|
2059
2148
|
}
|
|
2149
|
+
async removeLocalItems(ids) {
|
|
2150
|
+
const scope = this.scope ?? this.local.scope ?? {};
|
|
2151
|
+
if (this.local.removeMany) {
|
|
2152
|
+
await this.local.removeMany(ids, scope);
|
|
2153
|
+
return;
|
|
2154
|
+
}
|
|
2155
|
+
for (const id of ids) await this.local.remove(id, scope);
|
|
2156
|
+
}
|
|
2060
2157
|
async pushWithRetry(operation) {
|
|
2061
2158
|
let attempt = 0;
|
|
2062
2159
|
while (true) {
|
|
2063
2160
|
try {
|
|
2064
2161
|
return await this.remote.push({ ...operation, attempts: attempt });
|
|
2065
2162
|
} catch (error) {
|
|
2066
|
-
if (isKeepSyncAuthError(error) || attempt >= this.maxRetries) throw error;
|
|
2163
|
+
if (isKeepSyncAuthError(error) || isPermanentSyncError(error) || attempt >= this.maxRetries) throw error;
|
|
2067
2164
|
attempt += 1;
|
|
2068
2165
|
const delay = this.retryDelayMs * this.retryBackoff ** (attempt - 1);
|
|
2069
2166
|
if (delay > 0) await wait(delay);
|
|
@@ -2076,7 +2173,7 @@ var SyncStorageAdapter = class {
|
|
|
2076
2173
|
try {
|
|
2077
2174
|
return await this.remote.pushCollection?.({ ...operation, attempts: attempt });
|
|
2078
2175
|
} catch (error) {
|
|
2079
|
-
if (isKeepSyncAuthError(error) || attempt >= this.maxRetries) throw error;
|
|
2176
|
+
if (isKeepSyncAuthError(error) || isPermanentSyncError(error) || attempt >= this.maxRetries) throw error;
|
|
2080
2177
|
attempt += 1;
|
|
2081
2178
|
const delay = this.retryDelayMs * this.retryBackoff ** (attempt - 1);
|
|
2082
2179
|
if (delay > 0) await wait(delay);
|
|
@@ -2118,7 +2215,7 @@ var SyncStorageAdapter = class {
|
|
|
2118
2215
|
await this.remote.pushMembership?.({ ...operation, attempts: attempt });
|
|
2119
2216
|
return;
|
|
2120
2217
|
} catch (error) {
|
|
2121
|
-
if (isKeepSyncAuthError(error) || attempt >= this.maxRetries) throw error;
|
|
2218
|
+
if (isKeepSyncAuthError(error) || isPermanentSyncError(error) || attempt >= this.maxRetries) throw error;
|
|
2122
2219
|
attempt += 1;
|
|
2123
2220
|
const delay = this.retryDelayMs * this.retryBackoff ** (attempt - 1);
|
|
2124
2221
|
if (delay > 0) await wait(delay);
|
|
@@ -2167,11 +2264,12 @@ var SyncStorageAdapter = class {
|
|
|
2167
2264
|
}
|
|
2168
2265
|
}
|
|
2169
2266
|
async persistQueue(next) {
|
|
2170
|
-
const
|
|
2171
|
-
const
|
|
2172
|
-
const removed = [...
|
|
2267
|
+
const previousById = new Map(this.queueItems.map((operation) => [operation.operationId, operation]));
|
|
2268
|
+
const nextById = new Map(next.map((operation) => [operation.operationId, operation]));
|
|
2269
|
+
const removed = [...previousById.keys()].filter((id) => !nextById.has(id));
|
|
2173
2270
|
if (removed.length > 0) await this.queue.remove(removed);
|
|
2174
|
-
|
|
2271
|
+
const changed = next.filter((operation) => previousById.get(operation.operationId) !== operation);
|
|
2272
|
+
if (changed.length > 0) await this.queue.setMany(changed);
|
|
2175
2273
|
this.queueItems = next;
|
|
2176
2274
|
}
|
|
2177
2275
|
async removeQueued(operationIds) {
|
|
@@ -2179,6 +2277,7 @@ var SyncStorageAdapter = class {
|
|
|
2179
2277
|
const ids = new Set(typeof operationIds === "string" ? [operationIds] : operationIds);
|
|
2180
2278
|
await this.queue.remove([...ids]);
|
|
2181
2279
|
this.queueItems = this.queueItems.filter((operation) => !ids.has(operation.operationId));
|
|
2280
|
+
for (const id of ids) this.rejectedOperations.delete(id);
|
|
2182
2281
|
this.setPendingState();
|
|
2183
2282
|
}
|
|
2184
2283
|
async replaceQueued(previous, next) {
|
|
@@ -2188,9 +2287,12 @@ var SyncStorageAdapter = class {
|
|
|
2188
2287
|
this.setPendingState();
|
|
2189
2288
|
}
|
|
2190
2289
|
setPendingState() {
|
|
2290
|
+
const rejected = [...this.rejectedOperations.values()];
|
|
2191
2291
|
this.updateState({
|
|
2192
|
-
status: this.queueItems.length > 0 ? "pending" : "synced",
|
|
2193
|
-
pendingCount: this.queueItems.length
|
|
2292
|
+
status: rejected.length > 0 ? "error" : this.queueItems.length > 0 ? "pending" : "synced",
|
|
2293
|
+
pendingCount: this.queueItems.length,
|
|
2294
|
+
...rejected.length > 0 ? { error: rejected[rejected.length - 1]?.error } : { error: void 0 },
|
|
2295
|
+
rejectedOperations: rejected
|
|
2194
2296
|
});
|
|
2195
2297
|
}
|
|
2196
2298
|
async pullRemote() {
|
|
@@ -2203,25 +2305,23 @@ var SyncStorageAdapter = class {
|
|
|
2203
2305
|
);
|
|
2204
2306
|
const localItems = await this.getAll();
|
|
2205
2307
|
const localById = new Map(localItems.map((item) => [item.id, item]));
|
|
2308
|
+
const remoteIds = /* @__PURE__ */ new Set();
|
|
2206
2309
|
const remoteById = /* @__PURE__ */ new Map();
|
|
2207
2310
|
for (const item of remoteItems) {
|
|
2208
2311
|
if (this.scope && item.scope && !sameScope2(item.scope, this.scope)) continue;
|
|
2312
|
+
remoteIds.add(item.id);
|
|
2209
2313
|
if (pendingIds.has(item.id)) continue;
|
|
2210
2314
|
const previous = remoteById.get(item.id);
|
|
2211
2315
|
remoteById.set(item.id, previous ? mergeKeepItemLists([item], [previous])[0] ?? item : item);
|
|
2212
2316
|
}
|
|
2213
2317
|
const incoming = [...remoteById.values()].flatMap((item) => {
|
|
2214
|
-
const
|
|
2215
|
-
|
|
2216
|
-
return [];
|
|
2217
|
-
}
|
|
2218
|
-
const merged = current ? mergeKeepItemLists([item], [current])[0] ?? item : item;
|
|
2219
|
-
return [this.applyScope(merged)];
|
|
2318
|
+
const merged = mergePulledItem(item, localById.get(item.id));
|
|
2319
|
+
return merged ? [this.applyScope(merged)] : [];
|
|
2220
2320
|
});
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2321
|
+
const removedIds = this.itemPullMode === "snapshot" ? getSnapshotRemovals(localItems, remoteIds, pendingIds, this.scope ?? this.local.scope) : [];
|
|
2322
|
+
if (incoming.length > 0) await persistKeepItems(this.local, incoming);
|
|
2323
|
+
if (removedIds.length > 0) await this.removeLocalItems(removedIds);
|
|
2324
|
+
if (incoming.length > 0 || removedIds.length > 0) this.notifyDataListeners();
|
|
2225
2325
|
}
|
|
2226
2326
|
if (this.remote.pullCollections && this.local.getCollections && this.local.setCollection && this.local.removeCollection) {
|
|
2227
2327
|
const remoteCollections = await this.remote.pullCollections();
|
|
@@ -2277,11 +2377,15 @@ var SyncStorageAdapter = class {
|
|
|
2277
2377
|
for (const listener of this.dataListeners) listener();
|
|
2278
2378
|
}
|
|
2279
2379
|
updateState(next) {
|
|
2280
|
-
|
|
2380
|
+
const state = {
|
|
2281
2381
|
...this.state,
|
|
2282
2382
|
...next,
|
|
2283
2383
|
pendingCount: next.pendingCount ?? this.queueItems.length
|
|
2284
2384
|
};
|
|
2385
|
+
const rejected = [...this.rejectedOperations.values()];
|
|
2386
|
+
if (rejected.length > 0) state.rejectedOperations = rejected;
|
|
2387
|
+
else delete state.rejectedOperations;
|
|
2388
|
+
this.state = state;
|
|
2285
2389
|
for (const listener of this.listeners) listener();
|
|
2286
2390
|
}
|
|
2287
2391
|
};
|
|
@@ -2364,6 +2468,49 @@ function getScopeKey(options) {
|
|
|
2364
2468
|
function sameScope2(left, right) {
|
|
2365
2469
|
return left?.userId === right.userId && left?.tenantId === right.tenantId;
|
|
2366
2470
|
}
|
|
2471
|
+
function mergePulledItem(remote, current) {
|
|
2472
|
+
if (!current) return remote;
|
|
2473
|
+
if (remote.revision !== void 0 && current.revision !== void 0 && remote.revision !== current.revision) {
|
|
2474
|
+
const lastOpenedAt = Math.max(remote.lastOpenedAt ?? 0, current.lastOpenedAt ?? 0);
|
|
2475
|
+
return lastOpenedAt > 0 ? { ...remote, lastOpenedAt } : remote;
|
|
2476
|
+
}
|
|
2477
|
+
if (remote.updatedAt < current.updatedAt && (remote.lastOpenedAt ?? 0) <= (current.lastOpenedAt ?? 0)) {
|
|
2478
|
+
return void 0;
|
|
2479
|
+
}
|
|
2480
|
+
return mergeKeepItemLists([remote], [current])[0] ?? remote;
|
|
2481
|
+
}
|
|
2482
|
+
function getSnapshotRemovals(localItems, remoteIds, pendingIds, scope) {
|
|
2483
|
+
const isRemovable = (item) => isSameKeepScope(item.scope, scope) && item.revision !== void 0 && !remoteIds.has(item.id) && !pendingIds.has(item.id);
|
|
2484
|
+
return localItems.filter(isRemovable).map((item) => item.id);
|
|
2485
|
+
}
|
|
2486
|
+
function isPermanentSyncError(error) {
|
|
2487
|
+
const status = getHttpStatus(error);
|
|
2488
|
+
return status !== void 0 && status >= 400 && status < 500 && status !== 401 && status !== 403 && status !== 408 && status !== 425 && status !== 429;
|
|
2489
|
+
}
|
|
2490
|
+
function dependsOnRejectedOperation(operation, rejected) {
|
|
2491
|
+
if (isMembershipSyncOperation(rejected)) {
|
|
2492
|
+
if (isMembershipSyncOperation(operation)) return operation.id === rejected.id;
|
|
2493
|
+
if (isCollectionSyncOperation(operation)) return operation.id === rejected.collectionId;
|
|
2494
|
+
return operation.id === rejected.itemId;
|
|
2495
|
+
}
|
|
2496
|
+
if (isMembershipSyncOperation(operation)) {
|
|
2497
|
+
return isCollectionSyncOperation(rejected) ? operation.collectionId === rejected.id : operation.itemId === rejected.id;
|
|
2498
|
+
}
|
|
2499
|
+
if (isCollectionSyncOperation(operation)) {
|
|
2500
|
+
return isCollectionSyncOperation(rejected) && operation.id === rejected.id;
|
|
2501
|
+
}
|
|
2502
|
+
return !isCollectionSyncOperation(rejected) && operation.id === rejected.id;
|
|
2503
|
+
}
|
|
2504
|
+
function getHttpStatus(error) {
|
|
2505
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2506
|
+
while (isRecord(error) && !seen.has(error)) {
|
|
2507
|
+
seen.add(error);
|
|
2508
|
+
if (typeof error.status === "number") return error.status;
|
|
2509
|
+
if (isRecord(error.response) && typeof error.response.status === "number") return error.response.status;
|
|
2510
|
+
error = error.cause;
|
|
2511
|
+
}
|
|
2512
|
+
return void 0;
|
|
2513
|
+
}
|
|
2367
2514
|
function wait(delay) {
|
|
2368
2515
|
return new Promise((resolve) => setTimeout(resolve, delay));
|
|
2369
2516
|
}
|
|
@@ -3264,6 +3411,7 @@ export {
|
|
|
3264
3411
|
normalizeKeepTags,
|
|
3265
3412
|
persistKeepItems,
|
|
3266
3413
|
removeKeepItems,
|
|
3414
|
+
mergeKeepItemLists,
|
|
3267
3415
|
isRecord,
|
|
3268
3416
|
getKeepScopeKey,
|
|
3269
3417
|
isSameKeepScope,
|
|
@@ -3275,9 +3423,11 @@ export {
|
|
|
3275
3423
|
migrateLegacyCollectionMemberships,
|
|
3276
3424
|
KEEP_BACKUP_FORMAT,
|
|
3277
3425
|
KEEP_BACKUP_VERSION,
|
|
3426
|
+
inspectKeepBackup,
|
|
3278
3427
|
KeepBackupParseError,
|
|
3279
3428
|
KeepBackupImportError,
|
|
3280
3429
|
exportItems,
|
|
3430
|
+
formatItemsAsMarkdown,
|
|
3281
3431
|
importItems,
|
|
3282
3432
|
LocalStorageRecoveryJournal,
|
|
3283
3433
|
DEFAULT_SYNC_QUEUE_KEY,
|
|
@@ -3296,4 +3446,4 @@ export {
|
|
|
3296
3446
|
LocalStorageAdapter,
|
|
3297
3447
|
IndexedDBAdapter
|
|
3298
3448
|
};
|
|
3299
|
-
//# sourceMappingURL=chunk-
|
|
3449
|
+
//# sourceMappingURL=chunk-WKXLHEAK.js.map
|