@keepkit/core 0.28.9 → 0.28.11

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,594 +0,0 @@
1
- import {
2
- validateKeepItem
3
- } from "./chunk-5W4QSJHV.js";
4
- import {
5
- isKeepCollectionDefinition,
6
- isKeepCollectionMembership,
7
- isKeepItem,
8
- isRecord,
9
- mergeKeepItemLists,
10
- persistKeepItems,
11
- removeKeepItems
12
- } from "./chunk-SLH4DFYQ.js";
13
-
14
- // src/features/items/navigation.ts
15
- function orderKeepItems(items) {
16
- if (!items.some((item) => item.order !== void 0)) return [...items];
17
- return items.map((item, index) => ({ item, index })).sort((left, right) => {
18
- const leftOrder = left.item.order;
19
- const rightOrder = right.item.order;
20
- if (leftOrder === void 0 && rightOrder !== void 0) return 1;
21
- if (leftOrder !== void 0 && rightOrder === void 0) return -1;
22
- if (leftOrder !== void 0 && rightOrder !== void 0 && leftOrder !== rightOrder) {
23
- return leftOrder - rightOrder;
24
- }
25
- return left.index - right.index;
26
- }).map(({ item }) => item);
27
- }
28
- function getKeepNavigationState(source, current) {
29
- const items = orderKeepItems(source);
30
- const currentIndex = typeof current === "number" ? Number.isInteger(current) && current >= 0 && current < items.length ? current : -1 : current === void 0 ? -1 : items.findIndex((item) => item.id === current);
31
- const currentItem = currentIndex >= 0 ? items[currentIndex] ?? null : null;
32
- return {
33
- items,
34
- currentIndex,
35
- currentPosition: currentIndex >= 0 ? currentIndex + 1 : null,
36
- currentItem,
37
- hasNext: currentIndex >= 0 && currentIndex < items.length - 1,
38
- hasPrev: currentIndex > 0,
39
- nextItem: currentIndex >= 0 ? items[currentIndex + 1] ?? null : null,
40
- prevItem: currentIndex > 0 ? items[currentIndex - 1] ?? null : null
41
- };
42
- }
43
- function reorderKeepItems(source, orderedIds) {
44
- const byId = new Map(source.map((item) => [item.id, item]));
45
- const seen = /* @__PURE__ */ new Set();
46
- for (const id of orderedIds) {
47
- if (!byId.has(id)) throw new Error(`Cannot reorder unknown Keep item "${id}".`);
48
- if (seen.has(id)) throw new Error(`Cannot reorder Keep items with duplicate id "${id}".`);
49
- seen.add(id);
50
- }
51
- const current = orderKeepItems(source);
52
- const sequence = [...orderedIds, ...current.map((item) => item.id).filter((id) => !seen.has(id))];
53
- return sequence.map((id, order) => {
54
- const item = byId.get(id);
55
- if (!item) throw new Error(`Cannot reorder unknown Keep item "${id}".`);
56
- return { ...item, order };
57
- });
58
- }
59
- function moveKeepItem(source, id, targetIndex) {
60
- const items = orderKeepItems(source);
61
- const currentIndex = items.findIndex((item2) => item2.id === id);
62
- if (currentIndex < 0) throw new Error(`Cannot move unknown Keep item "${id}".`);
63
- if (!Number.isInteger(targetIndex)) throw new Error("Keep item targetIndex must be an integer.");
64
- const nextIndex = Math.min(Math.max(0, targetIndex), items.length - 1);
65
- const [item] = items.splice(currentIndex, 1);
66
- items.splice(nextIndex, 0, item);
67
- return reorderKeepItems(
68
- items,
69
- items.map((entry) => entry.id)
70
- );
71
- }
72
-
73
- // src/features/persistence/migration.ts
74
- async function mergeKeepItems(localItems, target) {
75
- if (target.merge) return target.merge(localItems);
76
- const merged = mergeKeepItemLists(await target.getAll(), localItems);
77
- await Promise.all(merged.map((item) => target.set(item)));
78
- return merged;
79
- }
80
- async function migrateKeepItems(source, target) {
81
- const localItems = await source.getAll();
82
- const merged = await mergeKeepItems(localItems, target);
83
- await source.clear();
84
- return merged;
85
- }
86
- async function migrateLegacyCollectionMemberships(storage) {
87
- if (!storage.getCollectionMemberships || !storage.setCollectionMembership) {
88
- throw new TypeError("The storage adapter does not support collection memberships.");
89
- }
90
- const [items, memberships, collections] = await Promise.all([
91
- storage.getAll(),
92
- storage.getCollectionMemberships(),
93
- storage.getCollections?.() ?? Promise.resolve([])
94
- ]);
95
- const existing = new Set(memberships.map(membershipKey));
96
- const collectionIds = new Set(collections.map((collection) => collectionKey(collection.id, collection.scope)));
97
- const missingCollectionIds = /* @__PURE__ */ new Set();
98
- let migrated = 0;
99
- let skipped = 0;
100
- for (const item of items) {
101
- if (!item.collectionId) continue;
102
- const membership = {
103
- collectionId: item.collectionId,
104
- itemId: item.id,
105
- order: item.order ?? 0,
106
- ...item.scope ? { scope: item.scope } : {}
107
- };
108
- const key = membershipKey(membership);
109
- if (!collectionIds.has(collectionKey(item.collectionId, item.scope))) {
110
- missingCollectionIds.add(item.collectionId);
111
- }
112
- if (existing.has(key)) {
113
- skipped += 1;
114
- const { collectionId: _legacyCollectionId2, ...migratedItem2 } = item;
115
- await storage.set(migratedItem2);
116
- continue;
117
- }
118
- await storage.setCollectionMembership(membership);
119
- existing.add(key);
120
- migrated += 1;
121
- const { collectionId: _legacyCollectionId, ...migratedItem } = item;
122
- await storage.set(migratedItem);
123
- }
124
- return { migrated, skipped, missingCollectionIds: [...missingCollectionIds] };
125
- }
126
- function membershipKey(membership) {
127
- return `${membership.scope?.tenantId ?? ""}\0${membership.scope?.userId ?? ""}\0${membership.collectionId}\0${membership.itemId}`;
128
- }
129
- function collectionKey(collectionId, scope) {
130
- return `${scope?.tenantId ?? ""}\0${scope?.userId ?? ""}\0${collectionId}`;
131
- }
132
-
133
- // src/features/persistence/backup.ts
134
- var KEEP_BACKUP_FORMAT = "keepkit";
135
- var KEEP_BACKUP_VERSION = 2;
136
- var KeepBackupParseError = class extends Error {
137
- constructor(message, options) {
138
- super(message);
139
- this.name = "KeepBackupParseError";
140
- if (options?.cause !== void 0) this.cause = options.cause;
141
- }
142
- };
143
- var KeepBackupImportError = class extends Error {
144
- constructor(message, options) {
145
- super(message);
146
- this.name = "KeepBackupImportError";
147
- this.mode = options.mode;
148
- this.imported = options.imported;
149
- this.failed = options.failed;
150
- this.applied = options.applied ?? { items: options.imported, collections: 0, memberships: 0 };
151
- this.failedStage = options.failedStage ?? "items";
152
- if (options.cause !== void 0) this.cause = options.cause;
153
- }
154
- };
155
- async function exportItems(adapter) {
156
- const items = await adapter.getAll();
157
- const collections = await adapter.getCollections?.() ?? [];
158
- const memberships = await adapter.getCollectionMemberships?.() ?? [];
159
- const backup = {
160
- format: KEEP_BACKUP_FORMAT,
161
- version: KEEP_BACKUP_VERSION,
162
- exportedAt: Date.now(),
163
- items,
164
- collections,
165
- memberships,
166
- scopes: collectScopes(items, collections, memberships, adapter.scope ? [adapter.scope] : [])
167
- };
168
- return JSON.stringify(backup, null, 2);
169
- }
170
- async function importItems(adapter, data, options = {}) {
171
- const backup = parseBackup(data);
172
- const mode = options.mode ?? "merge";
173
- const scopes = collectScopes(backup.items, backup.collections, backup.memberships, backup.scopes);
174
- if (adapter.scope && scopes.some((scope) => !sameScope(scope, adapter.scope))) {
175
- throw new KeepBackupImportError("The backup contains data outside the active storage scope.", {
176
- mode,
177
- imported: 0,
178
- failed: backup.items.length + backup.collections.length + backup.memberships.length,
179
- applied: { items: 0, collections: 0, memberships: 0 },
180
- failedStage: "validation"
181
- });
182
- }
183
- if (backup.collections.length > 0 && (!adapter.getCollections || !adapter.setCollection || !adapter.removeCollection) || backup.memberships.length > 0 && (!adapter.getCollectionMemberships || !adapter.setCollectionMembership || !adapter.removeCollectionMembership)) {
184
- throw new KeepBackupImportError("The storage adapter cannot restore collection data from this backup.", {
185
- mode,
186
- imported: 0,
187
- failed: backup.items.length + backup.collections.length + backup.memberships.length,
188
- applied: { items: 0, collections: 0, memberships: 0 },
189
- failedStage: "validation"
190
- });
191
- }
192
- const validItems = [];
193
- let failed = 0;
194
- for (const item of backup.items) {
195
- if (!options.schema) {
196
- validItems.push(item);
197
- continue;
198
- }
199
- try {
200
- validItems.push(await validateKeepItem(item, options.schema));
201
- } catch (cause) {
202
- options.onInvalidItem?.(cause, item);
203
- if ((options.invalidItemPolicy ?? "error") === "drop") {
204
- failed += 1;
205
- continue;
206
- }
207
- throw cause;
208
- }
209
- }
210
- const applied = { items: 0, collections: 0, memberships: 0 };
211
- const missingCollectionIds = backup.version === 1 ? [...new Set(backup.items.flatMap((item) => item.collectionId ? [item.collectionId] : []))] : [];
212
- try {
213
- if (mode === "replace") {
214
- await adapter.clear();
215
- await restoreCollections(adapter, [], "replace", "backup", applied);
216
- await restoreMemberships(adapter, [], "replace", applied);
217
- }
218
- } catch (cause) {
219
- throw new KeepBackupImportError("KeepKit could not clear the data being replaced.", {
220
- mode,
221
- imported: applied.items,
222
- failed: validItems.length + failed,
223
- applied,
224
- failedStage: "clear",
225
- cause
226
- });
227
- }
228
- for (const item of validItems) {
229
- try {
230
- if (mode === "merge") await mergeKeepItems([item], adapter);
231
- else await adapter.set(item);
232
- applied.items += 1;
233
- } catch (cause) {
234
- throw new KeepBackupImportError(`KeepKit could not restore item ${item.id}.`, {
235
- mode,
236
- imported: applied.items,
237
- failed: validItems.length + failed - applied.items,
238
- applied,
239
- failedStage: "items",
240
- cause
241
- });
242
- }
243
- }
244
- try {
245
- await restoreCollections(adapter, backup.collections, mode, options.collectionNameConflict ?? "backup", applied);
246
- } catch (cause) {
247
- throw new KeepBackupImportError("KeepKit could not restore collection definitions.", {
248
- mode,
249
- imported: applied.items,
250
- failed: validItems.length + failed - applied.items,
251
- applied,
252
- failedStage: "collections",
253
- cause
254
- });
255
- }
256
- try {
257
- await restoreMemberships(adapter, backup.memberships, mode, applied);
258
- } catch (cause) {
259
- throw new KeepBackupImportError("KeepKit could not restore collection memberships.", {
260
- mode,
261
- imported: applied.items,
262
- failed: validItems.length + failed - applied.items,
263
- applied,
264
- failedStage: "memberships",
265
- cause
266
- });
267
- }
268
- let items;
269
- try {
270
- items = await adapter.getAll();
271
- } catch (cause) {
272
- throw new KeepBackupImportError("KeepKit restored the backup but could not read the resulting items.", {
273
- mode,
274
- imported: applied.items,
275
- failed,
276
- applied,
277
- failedStage: "items",
278
- cause
279
- });
280
- }
281
- return {
282
- mode,
283
- imported: applied.items,
284
- failed,
285
- total: items.length,
286
- items,
287
- applied,
288
- missingCollectionIds,
289
- includedData: backup.version === 1 ? ["items"] : ["items", "collections", "memberships"],
290
- scopes
291
- };
292
- }
293
- function parseBackup(data) {
294
- let value = data;
295
- if (typeof data === "string") {
296
- try {
297
- value = JSON.parse(data);
298
- } catch (cause) {
299
- throw new KeepBackupParseError("KeepKit backup is not valid JSON.", { cause });
300
- }
301
- }
302
- if (!isRecord(value)) throw new KeepBackupParseError("KeepKit backup must be an object.");
303
- if (value.format !== KEEP_BACKUP_FORMAT || value.version !== 1 && value.version !== KEEP_BACKUP_VERSION) {
304
- throw new KeepBackupParseError("KeepKit backup format or version is unsupported.");
305
- }
306
- if (typeof value.exportedAt !== "number" || !Number.isFinite(value.exportedAt)) {
307
- throw new KeepBackupParseError("KeepKit backup has an invalid export timestamp.");
308
- }
309
- if (!Array.isArray(value.items) || !value.items.every(isKeepItem)) {
310
- throw new KeepBackupParseError("KeepKit backup contains invalid items.");
311
- }
312
- if (value.version === 1) {
313
- return {
314
- format: KEEP_BACKUP_FORMAT,
315
- version: 1,
316
- exportedAt: value.exportedAt,
317
- items: value.items,
318
- collections: [],
319
- memberships: [],
320
- scopes: []
321
- };
322
- }
323
- if (!Array.isArray(value.collections) || !value.collections.every(isKeepCollectionDefinition) || !Array.isArray(value.memberships) || !value.memberships.every(isKeepCollectionMembership)) {
324
- throw new KeepBackupParseError("KeepKit backup contains invalid collection data.");
325
- }
326
- if (value.scopes !== void 0 && (!Array.isArray(value.scopes) || !value.scopes.every(isSyncScope))) {
327
- throw new KeepBackupParseError("KeepKit backup contains invalid scope data.");
328
- }
329
- return value;
330
- }
331
- function collectScopes(items, collections, memberships, declaredScopes = []) {
332
- const scopes = [
333
- ...declaredScopes,
334
- ...[...items, ...collections, ...memberships].flatMap((record) => record.scope ? [record.scope] : [])
335
- ].filter((scope, index, all) => all.findIndex((entry) => sameScope(entry, scope)) === index);
336
- return scopes.map((scope) => ({ ...scope }));
337
- }
338
- function sameScope(left, right) {
339
- return left.userId === right?.userId && left.tenantId === right?.tenantId;
340
- }
341
- function isSyncScope(value) {
342
- return isRecord(value) && (value.userId === void 0 || typeof value.userId === "string") && (value.tenantId === void 0 || typeof value.tenantId === "string");
343
- }
344
- async function restoreCollections(adapter, collections, mode, conflict, applied) {
345
- if (!adapter.getCollections || !adapter.setCollection || !adapter.removeCollection) return;
346
- const existing = await adapter.getCollections();
347
- if (mode === "replace") {
348
- for (const collection of existing) await adapter.removeCollection(collection.id, collection.scope);
349
- }
350
- for (const collection of collections) {
351
- const current = existing.find(
352
- (entry) => entry.id === collection.id && sameScope(entry.scope ?? {}, collection.scope)
353
- );
354
- const value = mode === "merge" && conflict === "existing" && current ? { ...collection, name: current.name } : collection;
355
- await adapter.setCollection(value);
356
- applied.collections += 1;
357
- }
358
- }
359
- async function restoreMemberships(adapter, memberships, mode, applied) {
360
- if (!adapter.getCollectionMemberships || !adapter.setCollectionMembership || !adapter.removeCollectionMembership)
361
- return;
362
- if (mode === "replace") {
363
- const current = await adapter.getCollectionMemberships();
364
- for (const membership of current) {
365
- await adapter.removeCollectionMembership(membership.collectionId, membership.itemId, membership.scope);
366
- }
367
- }
368
- for (const membership of memberships) {
369
- await adapter.setCollectionMembership(membership);
370
- applied.memberships += 1;
371
- }
372
- }
373
-
374
- // src/features/items/query.ts
375
- function createInboxQuery(options = {}) {
376
- return { organization: { collection: "unassigned", ...options.organization } };
377
- }
378
- var DEFAULT_REDISCOVERY_INACTIVE_FOR_MS = 30 * 24 * 60 * 60 * 1e3;
379
- function createRediscoveryQuery(options) {
380
- if (options.strategy === "never-opened") return { activity: { opened: "never" } };
381
- if (options.strategy === "recently-opened") {
382
- return { activity: { opened: "ever" }, sort: { by: "lastOpenedAt", direction: "desc" } };
383
- }
384
- return { activity: { inactiveForMs: options.inactiveForMs ?? DEFAULT_REDISCOVERY_INACTIVE_FOR_MS } };
385
- }
386
- function queryKeepItems(source, query = {}) {
387
- const filtered = source.filter((item) => {
388
- const [from, to] = query.savedBetween ?? [];
389
- const savedAt = item.savedAt;
390
- const lowerBound = from === void 0 ? void 0 : toTimestamp(from);
391
- const upperBound = to === void 0 ? void 0 : toTimestamp(to);
392
- return (query.targetType === void 0 || item.targetType === query.targetType) && (query.tags === void 0 || query.tags.every((tag) => item.tags?.includes(tag))) && matchesArchiveScope(item, query) && (query.collectionId === void 0 || item.collectionId === query.collectionId) && matchesOrganization(item, query.organization) && matchesActivity(item, query.activity) && (lowerBound === void 0 || savedAt >= lowerBound) && (upperBound === void 0 || savedAt <= upperBound) && matchesSearch(item, query.search) && (query.filter?.(item) ?? true);
393
- });
394
- const tagCounts = getTagCounts(filtered);
395
- const sortBy = query.sort?.by;
396
- const direction = query.sort?.direction === "asc" ? 1 : -1;
397
- const sortedBase = sortBy ? filtered.map((item, index) => ({ item, index })).sort((a, b) => compareSortValues(a.item[sortBy], b.item[sortBy], direction) || a.index - b.index).map(({ item }) => item) : orderKeepItems(filtered);
398
- const sorted = query.pinnedFirst ? [...sortedBase.filter((item) => item.pinned === true), ...sortedBase.filter((item) => item.pinned !== true)] : sortedBase;
399
- const pageSize = Math.max(1, query.pagination?.pageSize ?? (sorted.length || 1));
400
- const pageCount = Math.max(1, Math.ceil(sorted.length / pageSize));
401
- const page = Math.min(Math.max(1, query.pagination?.page ?? 1), pageCount);
402
- const offset = (page - 1) * pageSize;
403
- return {
404
- items: sorted.slice(offset, offset + pageSize),
405
- totalCount: sorted.length,
406
- tagCounts,
407
- page,
408
- pageCount,
409
- hasNextPage: page < pageCount,
410
- hasPreviousPage: page > 1
411
- };
412
- }
413
- function matchesOrganization(item, organization) {
414
- if (organization?.collection === "assigned" && !item.collectionId?.trim()) return false;
415
- if (organization?.collection === "unassigned" && item.collectionId?.trim()) return false;
416
- if (organization?.tags === "assigned" && !item.tags?.some((tag) => tag.trim())) return false;
417
- if (organization?.tags === "unassigned" && item.tags?.some((tag) => tag.trim())) return false;
418
- if (organization?.note === "assigned" && !item.note?.trim()) return false;
419
- if (organization?.note === "unassigned" && item.note?.trim()) return false;
420
- return true;
421
- }
422
- function matchesActivity(item, activity) {
423
- if (!activity) return true;
424
- const lastOpenedAt = item.lastOpenedAt;
425
- const opened = lastOpenedAt !== void 0;
426
- if (activity.opened === "ever" && !opened) return false;
427
- if (activity.opened === "never" && opened) return false;
428
- if (activity.lastOpenedBefore !== void 0 && (!opened || lastOpenedAt >= activity.lastOpenedBefore)) return false;
429
- if (activity.lastOpenedAfter !== void 0 && (!opened || lastOpenedAt <= activity.lastOpenedAfter)) return false;
430
- if (activity.inactiveForMs !== void 0) {
431
- const cutoff = Date.now() - activity.inactiveForMs;
432
- const lastActivityAt = item.lastOpenedAt ?? item.savedAt;
433
- if (lastActivityAt > cutoff) return false;
434
- }
435
- return true;
436
- }
437
- function compareSortValues(left, right, direction) {
438
- if (left === void 0 && right === void 0) return 0;
439
- if (left === void 0) return 1;
440
- if (right === void 0) return -1;
441
- return (left - right) * direction;
442
- }
443
- function matchesArchiveScope(item, query) {
444
- if (query.archiveScope === "all") return true;
445
- if (query.archiveScope === "archived") return item.archived === true;
446
- if (query.archiveScope === "active") return item.archived !== true;
447
- return query.archived === true ? item.archived === true : item.archived !== true;
448
- }
449
- function getTagCounts(items) {
450
- const counts = {};
451
- for (const item of items) {
452
- for (const tag of item.tags ?? []) counts[tag] = (counts[tag] ?? 0) + 1;
453
- }
454
- return Object.fromEntries(Object.entries(counts).sort(([a], [b]) => a.localeCompare(b)));
455
- }
456
- function matchesSearch(item, search) {
457
- const query = search?.query;
458
- if (!query?.trim()) return true;
459
- const fields = search?.fields ?? ["note", "meta", "tags"];
460
- const values = fields.map((field) => {
461
- if (field === "note") return item.note ?? "";
462
- if (field === "tags") return (item.tags ?? []).join(" ");
463
- try {
464
- return JSON.stringify(item.meta) ?? "";
465
- } catch {
466
- return String(item.meta);
467
- }
468
- });
469
- const text = values.join(" ").toLocaleLowerCase();
470
- const normalized = query.trim().toLocaleLowerCase();
471
- const needles = search?.tokenize === false ? [normalized] : normalized.split(/\s+/).filter(Boolean);
472
- const matches = needles.map((needle) => text.includes(needle));
473
- return search?.mode === "or" ? matches.some(Boolean) : matches.every(Boolean);
474
- }
475
- function toTimestamp(value) {
476
- return value instanceof Date ? value.getTime() : value;
477
- }
478
-
479
- // src/features/items/revalidation.ts
480
- function isKeepItemMetadataStale(item, maxAgeMs, now = Date.now) {
481
- return item.metaUpdatedAt === void 0 || now() - item.metaUpdatedAt >= maxAgeMs;
482
- }
483
- async function revalidateKeepItems(source, revalidator, options = {}) {
484
- const removeStatuses = new Set(options.removeStatuses ?? []);
485
- const now = options.now ?? Date.now;
486
- const items = [];
487
- const updatedItems = [];
488
- const removedIds = [];
489
- const results = [];
490
- for (const item of source) {
491
- const rawResult = await revalidator(item);
492
- const result = typeof rawResult === "string" ? { status: rawResult } : rawResult;
493
- const reason = result.status === "available" ? void 0 : result.reason;
494
- const defaultResolved = {
495
- ...item,
496
- status: result.status,
497
- ...result.status === "available" ? { statusReason: void 0 } : { statusReason: reason }
498
- };
499
- const resolved = options.resolveItem ? await options.resolveItem(item, result) : defaultResolved;
500
- if (resolved === void 0) {
501
- removedIds.push(item.id);
502
- results.push({ item, status: result.status, reason, updated: false });
503
- continue;
504
- }
505
- if (result.status === "available") {
506
- const timestamp = now();
507
- const availableItem = clearItemStatus(resolved);
508
- const updated = result.meta === void 0 ? availableItem : { ...availableItem, meta: result.meta, metaUpdatedAt: timestamp, updatedAt: timestamp };
509
- const didUpdate = updated !== item;
510
- items.push(updated);
511
- if (didUpdate) updatedItems.push(updated);
512
- results.push({ item: updated, status: "available", updated: didUpdate });
513
- continue;
514
- }
515
- const withStatus = { ...resolved, status: result.status, ...reason ? { statusReason: reason } : {} };
516
- const shouldRemove = removeStatuses.has(result.status);
517
- if (shouldRemove) removedIds.push(item.id);
518
- else items.push(withStatus);
519
- if (!shouldRemove && withStatus !== item) updatedItems.push(withStatus);
520
- results.push({ item: withStatus, status: result.status, reason, updated: !shouldRemove && withStatus !== item });
521
- }
522
- return {
523
- items,
524
- checked: source.length,
525
- updated: updatedItems.length,
526
- removed: removedIds.length,
527
- updatedItems,
528
- removedIds,
529
- results
530
- };
531
- }
532
- async function reconcileKeepItems(storage, revalidator, options = {}) {
533
- const source = await storage.getAll();
534
- const summary = await revalidateKeepItems(source, revalidator, options);
535
- if (summary.updatedItems.length > 0) await persistKeepItems(storage, summary.updatedItems);
536
- if (summary.removedIds.length > 0) await removeKeepItems(storage, summary.removedIds);
537
- return summary;
538
- }
539
- function clearItemStatus(item) {
540
- const next = { ...item };
541
- delete next.status;
542
- delete next.statusReason;
543
- return next;
544
- }
545
-
546
- // src/features/store/store.ts
547
- var KeepStore = class {
548
- constructor(initialState) {
549
- this.listeners = /* @__PURE__ */ new Set();
550
- this.getSnapshot = () => this.state;
551
- this.subscribe = (listener) => {
552
- this.listeners.add(listener);
553
- return () => this.listeners.delete(listener);
554
- };
555
- this.state = initialState;
556
- }
557
- setState(next) {
558
- let changed = false;
559
- for (const key of Object.keys(next)) {
560
- if (!Object.is(this.state[key], next[key])) {
561
- changed = true;
562
- break;
563
- }
564
- }
565
- if (!changed) return;
566
- this.state = { ...this.state, ...next };
567
- for (const listener of this.listeners) listener();
568
- }
569
- };
570
-
571
- export {
572
- orderKeepItems,
573
- getKeepNavigationState,
574
- reorderKeepItems,
575
- moveKeepItem,
576
- mergeKeepItems,
577
- migrateKeepItems,
578
- migrateLegacyCollectionMemberships,
579
- KEEP_BACKUP_FORMAT,
580
- KEEP_BACKUP_VERSION,
581
- KeepBackupParseError,
582
- KeepBackupImportError,
583
- exportItems,
584
- importItems,
585
- createInboxQuery,
586
- createRediscoveryQuery,
587
- queryKeepItems,
588
- getTagCounts,
589
- isKeepItemMetadataStale,
590
- revalidateKeepItems,
591
- reconcileKeepItems,
592
- KeepStore
593
- };
594
- //# sourceMappingURL=chunk-EMOPFB5D.js.map