@keepkit/core 0.28.12 → 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/dist/core.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { S as StorageAdapter, d as KeepCollectionMembership, K as KeepItem, e as KeepScope, R as RemoteSyncDriver, f as KeepPluginContext, g as KeepPlugin, h as SyncOperation, i as KeepCollectionSyncOperation, j as KeepMembershipSyncOperation, k as SyncScope, l as SyncCapableStorageAdapter, m as RemoteSyncResult, n as KeepCollectionDefinition, o as KeepSyncAuthError } from './types-DjXvE9Zb.js';
2
- export { F as FallbackRecoveryJournal, p as FallbackRecoveryJournalState, q as FallbackRecoveryJournalV2, r as FallbackRecoveryOperation, s as FallbackRecoverySnapshot, I as ImportItemsOptions, t as ImportItemsResult, u as KEEP_BACKUP_FORMAT, v as KEEP_BACKUP_VERSION, w as KeepAction, x as KeepBackup, y as KeepBackupAppliedCounts, z as KeepBackupDataType, A as KeepBackupImportError, B as KeepBackupParseError, C as KeepBackupV1, D as KeepBackupV2, b as KeepChangeContext, E as KeepChangePhase, G as KeepCollectionSyncConflict, H as KeepCollectionSyncResult, J as KeepConflictContext, L as KeepConflictResolver, M as KeepErrorContext, N as KeepErrorHandler, O as KeepEventHandlers, P as KeepInvalidItemPolicy, Q as KeepItemInput, a as KeepItemStatus, T as KeepRecoveryInspection, U as KeepRecoveryResult, V as KeepRecoveryRow, W as KeepRecoveryState, X as KeepSchema, Y as KeepSchemaParseResult, Z as KeepStorageAccessError, _ as KeepStorageError, $ as KeepStorageOperation, a0 as KeepStorageParseError, a1 as KeepStorageQuotaError, a2 as KeepStorageRecovery, a3 as KeepStorageSerializationError, a4 as KeepSyncAuthStatus, a5 as KeepSyncConflict, a6 as KeepSyncQueueOperation, a7 as KeepSyncResolution, a8 as KeepSyncState, a9 as KeepSyncStatus, c as KeepUndoState, aa as LocalStorageRecoveryJournal, ab as ScopedStorageAdapter, ac as ScopedSyncQueueAdapter, ad as SyncQueueAdapter, ae as createScopedStorageAdapter, af as exportItems, ag as getKeepScopeKey, ah as importItems, ai as isKeepSyncAuthError, aj as isSameKeepScope, ak as normalizeKeepTags } from './types-DjXvE9Zb.js';
3
- import { K as KeepListQuery } from './store-C8cxvXRV.js';
4
- export { D as DEFAULT_KEEP_URL_PARAMS, a as KeepAutoRevalidationOptions, b as KeepCollectionMeta, c as KeepItemMetadataRefresher, d as KeepItemResolver, e as KeepItemRevalidationRecord, f as KeepItemRevalidationResult, g as KeepItemRevalidationSummary, h as KeepItemRevalidator, i as KeepNavigationState, j as KeepRediscoveryOptions, k as KeepRediscoveryStrategy, l as KeepStore, m as KeepStoreActions, n as KeepStoreState, o as KeepUrlParamNames, p as KeepUrlState, q as KeepUrlSyncOptions, Q as QueryKeepItemsResult, R as RevalidateKeepItemsOptions, r as createInboxQuery, s as createRediscoveryQuery, t as decodeKeepListQuery, u as encodeKeepListQuery, v as getKeepNavigationState, w as getTagCounts, x as isKeepItemMetadataStale, y as mergeKeepListQueryFromUrl, z as moveKeepItem, A as orderKeepItems, B as queryKeepItems, C as reconcileKeepItems, E as reorderKeepItems, F as revalidateKeepItems, G as serializeKeepListQuery } from './store-C8cxvXRV.js';
1
+ import { S as StorageAdapter, d as KeepCollectionMembership, K as KeepItem, e as KeepScope, R as RemoteSyncDriver, f as KeepPluginContext, g as KeepPlugin, h as SyncOperation, i as KeepCollectionSyncOperation, j as KeepMembershipSyncOperation, k as SyncScope, l as SyncCapableStorageAdapter, m as RemoteSyncResult, n as KeepCollectionSyncResult, o as KeepCollectionDefinition, p as KeepSyncAuthError } from './types-KNIY89_m.js';
2
+ export { F as FallbackRecoveryJournal, q as FallbackRecoveryJournalState, r as FallbackRecoveryJournalV2, s as FallbackRecoveryOperation, t as FallbackRecoverySnapshot, I as ImportItemsOptions, u as ImportItemsResult, v as KEEP_BACKUP_FORMAT, w as KEEP_BACKUP_VERSION, x as KeepAction, y as KeepBackup, z as KeepBackupAppliedCounts, A as KeepBackupDataType, B as KeepBackupImportError, C as KeepBackupParseError, D as KeepBackupSummary, E as KeepBackupV1, G as KeepBackupV2, b as KeepChangeContext, H as KeepChangePhase, J as KeepCollectionSyncConflict, L as KeepConflictContext, M as KeepConflictResolver, N as KeepErrorContext, O as KeepErrorHandler, P as KeepEventHandlers, Q as KeepInvalidItemPolicy, T as KeepItemInput, a as KeepItemStatus, U as KeepRecoveryInspection, V as KeepRecoveryResult, W as KeepRecoveryRow, X as KeepRecoveryState, Y as KeepSchema, Z as KeepSchemaParseResult, _ as KeepStorageAccessError, $ as KeepStorageError, a0 as KeepStorageOperation, a1 as KeepStorageParseError, a2 as KeepStorageQuotaError, a3 as KeepStorageRecovery, a4 as KeepStorageSerializationError, a5 as KeepSyncAuthStatus, a6 as KeepSyncConflict, a7 as KeepSyncQueueOperation, a8 as KeepSyncRejectedOperation, a9 as KeepSyncResolution, aa as KeepSyncState, ab as KeepSyncStatus, c as KeepUndoState, ac as LocalStorageRecoveryJournal, ad as ScopedStorageAdapter, ae as ScopedSyncQueueAdapter, af as SyncQueueAdapter, ag as createScopedStorageAdapter, ah as exportItems, ai as formatItemsAsMarkdown, aj as getKeepScopeKey, ak as importItems, al as inspectKeepBackup, am as isKeepSyncAuthError, an as isSameKeepScope, ao as normalizeKeepTags } from './types-KNIY89_m.js';
3
+ import { K as KeepListQuery } from './store-D-ZFtgDn.js';
4
+ export { D as DEFAULT_KEEP_URL_PARAMS, a as KeepAutoRevalidationOptions, b as KeepCollectionMeta, c as KeepItemMetadataRefresher, d as KeepItemResolver, e as KeepItemRevalidationRecord, f as KeepItemRevalidationResult, g as KeepItemRevalidationSummary, h as KeepItemRevalidator, i as KeepNavigationState, j as KeepRediscoveryOptions, k as KeepRediscoveryStrategy, l as KeepStore, m as KeepStoreActions, n as KeepStoreState, o as KeepUrlParamNames, p as KeepUrlState, q as KeepUrlSyncOptions, Q as QueryKeepItemsResult, R as RevalidateKeepItemsOptions, r as createInboxQuery, s as createRediscoveryQuery, t as decodeKeepListQuery, u as encodeKeepListQuery, v as getKeepNavigationState, w as getTagCounts, x as isKeepItemMetadataStale, y as mergeKeepListQueryFromUrl, z as moveKeepItem, A as orderKeepItems, B as queryKeepItems, C as reconcileKeepItems, E as reorderKeepItems, F as revalidateKeepItems, G as serializeKeepListQuery } from './store-D-ZFtgDn.js';
5
5
  export { KeepSchemaValidationError, parseKeepMeta, validateKeepItem } from './schema.js';
6
6
  import { SyncStorageAdapterOptions, BrowserStorageAdapterOptions } from './storage.js';
7
7
  export { DEFAULT_INDEXEDDB_DATABASE, DEFAULT_INDEXEDDB_STORE, DEFAULT_STORAGE_KEY, DEFAULT_SYNC_QUEUE_DATABASE, DEFAULT_SYNC_QUEUE_KEY, DEFAULT_SYNC_QUEUE_STORE, FallbackStorageAdapter, FallbackStorageAdapterOptions, FallbackSyncQueueAdapter, FallbackSyncQueueAdapterOptions, IndexedDBAdapter, IndexedDBAdapterOptions, IndexedDBSyncQueueAdapter, IndexedDBSyncQueueOptions, LocalStorageAdapter, LocalStorageAdapterOptions, LocalStorageSyncQueueAdapter, LocalStorageSyncQueueOptions, RecoveryJournalFactoryContext, StorageAdapterFactoryOptions, SyncStorageAdapter, createBrowserStorageAdapter, createStorageAdapter } from './storage.js';
@@ -257,7 +257,8 @@ type AuthenticatedSyncRequestContext<TMeta = Record<string, unknown>> = {
257
257
  type AuthenticatedSyncTransport<TMeta = Record<string, unknown>> = {
258
258
  push: (operation: SyncOperation<TMeta>, context: AuthenticatedSyncRequestContext<TMeta>) => Promise<RemoteSyncResult<TMeta>>;
259
259
  pull?: (context: AuthenticatedSyncRequestContext<TMeta>) => Promise<KeepItem<TMeta>[]>;
260
- pushCollection?: (operation: KeepCollectionSyncOperation, context: AuthenticatedSyncRequestContext<TMeta>) => Promise<void>;
260
+ /** Return the server result so collection revisions and conflicts reach the sync queue. */
261
+ pushCollection?: (operation: KeepCollectionSyncOperation, context: AuthenticatedSyncRequestContext<TMeta>) => Promise<void | KeepCollectionSyncResult>;
261
262
  pullCollections?: (context: AuthenticatedSyncRequestContext<TMeta>) => Promise<KeepCollectionDefinition[]>;
262
263
  pushMembership?: (operation: KeepMembershipSyncOperation, context: AuthenticatedSyncRequestContext<TMeta>) => Promise<void>;
263
264
  pullMemberships?: (context: AuthenticatedSyncRequestContext<TMeta>) => Promise<KeepCollectionMembership[]>;
@@ -296,4 +297,4 @@ type AuthenticatedSyncKit<TMeta = Record<string, unknown>> = {
296
297
  /** Creates auth-independent sync wiring with per-request tokens and isolated account scopes. */
297
298
  declare function createAuthenticatedSyncKit<TMeta = Record<string, unknown>>(options: AuthenticatedSyncKitOptions<TMeta>): AuthenticatedSyncKit<TMeta>;
298
299
 
299
- export { type AuthenticatedSyncAuthContext, type AuthenticatedSyncKit, type AuthenticatedSyncKitOptions, type AuthenticatedSyncRequestContext, type AuthenticatedSyncTransport, BrowserStorageAdapterOptions, DEFAULT_KEEP_HISTORY_KEY, DEFAULT_KEEP_HISTORY_LIMIT, DEFAULT_KEEP_PROGRESS_KEY, DEFAULT_KEEP_VIEWING_RECORDS_KEY, DEFAULT_SAVED_VIEWS_STORAGE_KEY, KeepActivityStorageError, KeepCollectionDefinition, KeepCollectionMembership, KeepCollectionSyncOperation, type KeepCourseProgress, type KeepHistoryContext, type KeepHistoryEntry, type KeepHistoryStorage, type KeepInvalidationPluginOptions, KeepItem, type KeepItemProgress, type KeepKitPresetMode, type KeepKitPresetOptions, type KeepKitSetup, KeepListQuery, KeepMembershipSyncOperation, KeepPlugin, KeepPluginContext, type KeepProgressCompatibility, type KeepProgressRecord, type KeepProgressStorage, KeepProgressStorageError, type KeepSavedView, type KeepSavedViewStorage, KeepScope, KeepSyncAuthError, type KeepViewingRecord, type KeepViewingRecordStorage, type LegacyCollectionMigrationResult, type LocalStorageActivityOptions, LocalStorageKeepHistoryStorage, LocalStorageKeepProgressStorage, LocalStorageKeepSavedViewStorage, LocalStorageKeepViewingRecordStorage, type LocalStorageProgressOptions, RemoteSyncDriver, RemoteSyncResult, StorageAdapter, SyncCapableStorageAdapter, SyncOperation, SyncScope, SyncStorageAdapterOptions, addKeepItemToCollection, createAuthenticatedSyncKit, createKeepInvalidationPlugin, createKeepKitPreset, createKeepKitSetup, getKeepCollectionItems, isProgressCompatible, mergeKeepItems, migrateKeepItems, migrateLegacyCollectionMemberships, removeKeepItemFromCollection, reorderKeepCollectionItems };
300
+ export { type AuthenticatedSyncAuthContext, type AuthenticatedSyncKit, type AuthenticatedSyncKitOptions, type AuthenticatedSyncRequestContext, type AuthenticatedSyncTransport, BrowserStorageAdapterOptions, DEFAULT_KEEP_HISTORY_KEY, DEFAULT_KEEP_HISTORY_LIMIT, DEFAULT_KEEP_PROGRESS_KEY, DEFAULT_KEEP_VIEWING_RECORDS_KEY, DEFAULT_SAVED_VIEWS_STORAGE_KEY, KeepActivityStorageError, KeepCollectionDefinition, KeepCollectionMembership, KeepCollectionSyncOperation, KeepCollectionSyncResult, type KeepCourseProgress, type KeepHistoryContext, type KeepHistoryEntry, type KeepHistoryStorage, type KeepInvalidationPluginOptions, KeepItem, type KeepItemProgress, type KeepKitPresetMode, type KeepKitPresetOptions, type KeepKitSetup, KeepListQuery, KeepMembershipSyncOperation, KeepPlugin, KeepPluginContext, type KeepProgressCompatibility, type KeepProgressRecord, type KeepProgressStorage, KeepProgressStorageError, type KeepSavedView, type KeepSavedViewStorage, KeepScope, KeepSyncAuthError, type KeepViewingRecord, type KeepViewingRecordStorage, type LegacyCollectionMigrationResult, type LocalStorageActivityOptions, LocalStorageKeepHistoryStorage, LocalStorageKeepProgressStorage, LocalStorageKeepSavedViewStorage, LocalStorageKeepViewingRecordStorage, type LocalStorageProgressOptions, RemoteSyncDriver, RemoteSyncResult, StorageAdapter, SyncCapableStorageAdapter, SyncOperation, SyncScope, SyncStorageAdapterOptions, addKeepItemToCollection, createAuthenticatedSyncKit, createKeepInvalidationPlugin, createKeepKitPreset, createKeepKitSetup, getKeepCollectionItems, isProgressCompatible, mergeKeepItems, migrateKeepItems, migrateLegacyCollectionMemberships, removeKeepItemFromCollection, reorderKeepCollectionItems };
package/dist/core.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  reconcileKeepItems,
12
12
  reorderKeepItems,
13
13
  revalidateKeepItems
14
- } from "./chunk-CSBPFROD.js";
14
+ } from "./chunk-36NNVLEU.js";
15
15
  import {
16
16
  DEFAULT_INDEXEDDB_DATABASE,
17
17
  DEFAULT_INDEXEDDB_STORE,
@@ -43,16 +43,19 @@ import {
43
43
  createScopedStorageAdapter,
44
44
  createStorageAdapter,
45
45
  exportItems,
46
+ formatItemsAsMarkdown,
46
47
  getKeepScopeKey,
47
48
  importItems,
49
+ inspectKeepBackup,
48
50
  isKeepSyncAuthError,
49
51
  isSameKeepScope,
52
+ mergeKeepItemLists,
50
53
  mergeKeepItems,
51
54
  migrateKeepItems,
52
55
  migrateLegacyCollectionMemberships,
53
56
  normalizeKeepTags,
54
57
  withLocalStorageWriteLock
55
- } from "./chunk-SS22UTBH.js";
58
+ } from "./chunk-WKXLHEAK.js";
56
59
  import {
57
60
  KeepSchemaValidationError,
58
61
  parseKeepMeta,
@@ -941,7 +944,9 @@ var AuthenticatedSyncStorageController = class {
941
944
  this.disposed = false;
942
945
  this.options = options;
943
946
  this.currentScope = options.scope;
944
- this.current = this.createAdapter(this.currentScope);
947
+ this.scopeResolved = options.scope !== void 0 || !options.getScope;
948
+ this.accountAware = options.scope !== void 0 || options.getScope !== void 0;
949
+ this.current = this.scopeResolved ? this.createAdapter(this.currentScope) : this.createPendingAdapter();
945
950
  this.attach(this.current);
946
951
  if (this.current.getCollections && this.current.setCollection && this.current.removeCollection) {
947
952
  this.getCollections = async () => {
@@ -1035,19 +1040,38 @@ var AuthenticatedSyncStorageController = class {
1035
1040
  }
1036
1041
  return this.current.resolveSyncConflict(id, resolution, item);
1037
1042
  }
1043
+ async resolveRejectedSyncOperation(operationId, resolution) {
1044
+ await this.ensureScope();
1045
+ if (!this.current.resolveRejectedSyncOperation) {
1046
+ throw new Error("The authenticated sync adapter does not support resolving rejected operations.");
1047
+ }
1048
+ return this.current.resolveRejectedSyncOperation(operationId, resolution);
1049
+ }
1050
+ async resolveCollectionSyncConflict(id, resolution, collection) {
1051
+ await this.ensureScope();
1052
+ if (!this.current.resolveCollectionSyncConflict) {
1053
+ throw new Error("The authenticated sync adapter does not support collection conflict resolution.");
1054
+ }
1055
+ return this.current.resolveCollectionSyncConflict(id, resolution, collection);
1056
+ }
1038
1057
  async setScope(nextScope) {
1039
1058
  const run = this.transition.then(async () => {
1040
- if (isSameKeepScope(this.currentScope, nextScope)) return;
1059
+ if (this.scopeResolved && isSameKeepScope(this.currentScope, nextScope)) return;
1041
1060
  if (this.disposed) throw new Error("AuthenticatedSyncKit has been disposed.");
1042
1061
  const previousScope = this.currentScope;
1062
+ const scopeChanged = !isSameKeepScope(previousScope, nextScope);
1043
1063
  this.unsubscribeData();
1044
1064
  this.unsubscribeSync();
1045
1065
  this.current.dispose?.();
1066
+ this.scopeResolved = true;
1067
+ if (nextScope) this.accountAware = true;
1046
1068
  this.currentScope = nextScope;
1047
1069
  this.current = this.createAdapter(nextScope);
1048
1070
  this.attach(this.current);
1049
- await this.options.onScopeChange?.(nextScope, previousScope);
1050
- this.notify(this.scopeListeners);
1071
+ if (scopeChanged) {
1072
+ await this.options.onScopeChange?.(nextScope, previousScope);
1073
+ this.notify(this.scopeListeners);
1074
+ }
1051
1075
  this.notify(this.dataListeners);
1052
1076
  this.notify(this.syncListeners);
1053
1077
  });
@@ -1072,17 +1096,41 @@ var AuthenticatedSyncStorageController = class {
1072
1096
  this.syncListeners.clear();
1073
1097
  }
1074
1098
  createAdapter(scope) {
1075
- const local = this.options.local ? scope ? createScopedStorageAdapter(this.options.local, scope) : this.options.local : createBrowserStorageAdapter({ key: this.options.key, databaseName: this.options.databaseName, scope });
1076
- const queue = this.options.queue && scope ? new ScopedSyncQueueAdapter(this.options.queue, scope) : this.options.queue;
1077
- const remote = createAuthenticatedRemote(this.options, scope);
1078
1099
  return new SyncStorageAdapter({
1079
1100
  ...this.options,
1080
- local,
1081
- remote,
1082
- queue,
1101
+ local: this.createLocal(scope),
1102
+ remote: createAuthenticatedRemote(this.options, scope),
1103
+ queue: this.createQueue(scope),
1083
1104
  scope
1084
1105
  });
1085
1106
  }
1107
+ createPendingAdapter() {
1108
+ return new PendingScopeSyncStorageAdapter({
1109
+ ...this.options,
1110
+ local: this.createLocal(void 0),
1111
+ remote: {
1112
+ push: async () => {
1113
+ throw new Error("KeepKit cannot sync before the authenticated scope is resolved.");
1114
+ }
1115
+ },
1116
+ queue: new EmptySyncQueueAdapter(),
1117
+ scope: void 0
1118
+ });
1119
+ }
1120
+ createLocal(scope) {
1121
+ const { local, key, databaseName, userId, tenantId } = this.options;
1122
+ if (!local) return createBrowserStorageAdapter({ key, databaseName, scope });
1123
+ if (scope) return createScopedStorageAdapter(local, scope);
1124
+ if (userId || tenantId || !this.accountAware) return local;
1125
+ return new UnscopedStorageAdapter(local);
1126
+ }
1127
+ createQueue(scope) {
1128
+ const { queue, userId, tenantId } = this.options;
1129
+ if (!queue) return void 0;
1130
+ if (scope) return new ScopedSyncQueueAdapter(queue, scope);
1131
+ if (userId || tenantId) return queue;
1132
+ return new UnscopedSyncQueueAdapter(queue);
1133
+ }
1086
1134
  attach(adapter) {
1087
1135
  this.unsubscribeData = adapter.subscribe?.(() => this.notify(this.dataListeners)) ?? (() => void 0);
1088
1136
  this.unsubscribeSync = adapter.subscribeSync(() => this.notify(this.syncListeners));
@@ -1095,6 +1143,106 @@ var AuthenticatedSyncStorageController = class {
1095
1143
  for (const listener of listeners) listener();
1096
1144
  }
1097
1145
  };
1146
+ var PendingScopeSyncStorageAdapter = class extends SyncStorageAdapter {
1147
+ async flushSync() {
1148
+ }
1149
+ async retrySync() {
1150
+ }
1151
+ };
1152
+ var EmptySyncQueueAdapter = class {
1153
+ async getAll() {
1154
+ return [];
1155
+ }
1156
+ async setMany() {
1157
+ throw new Error("KeepKit cannot queue operations before the authenticated scope is resolved.");
1158
+ }
1159
+ async remove() {
1160
+ }
1161
+ async clear() {
1162
+ }
1163
+ };
1164
+ var UnscopedSyncQueueAdapter = class {
1165
+ constructor(base) {
1166
+ this.base = base;
1167
+ }
1168
+ async getAll() {
1169
+ return (await this.base.getAll()).filter(isUnscopedOperation);
1170
+ }
1171
+ async setMany(operations) {
1172
+ const ids = new Set(operations.map((operation) => operation.operationId));
1173
+ const current = await this.base.getAll();
1174
+ const preserved = current.filter((operation) => !ids.has(operation.operationId) || !isUnscopedOperation(operation));
1175
+ await this.base.setMany([...preserved, ...operations]);
1176
+ }
1177
+ async remove(operationIds) {
1178
+ const ids = new Set(operationIds);
1179
+ const unscopedIds = (await this.getAll()).filter((operation) => ids.has(operation.operationId)).map((operation) => operation.operationId);
1180
+ await this.base.remove(unscopedIds);
1181
+ }
1182
+ async clear() {
1183
+ const unscopedIds = (await this.getAll()).map((operation) => operation.operationId);
1184
+ await this.base.remove(unscopedIds);
1185
+ }
1186
+ };
1187
+ function isUnscopedOperation(operation) {
1188
+ return isSameKeepScope(operation.scope, void 0);
1189
+ }
1190
+ var UNSCOPED = {};
1191
+ function isUnscoped(value) {
1192
+ return isSameKeepScope(value.scope, void 0);
1193
+ }
1194
+ var UnscopedStorageAdapter = class {
1195
+ constructor(base) {
1196
+ this.base = base;
1197
+ this.storageKey = base.storageKey;
1198
+ if (isSameKeepScope(base.scope, void 0)) this.recovery = base.recovery;
1199
+ if (base.getCollections && base.setCollection && base.removeCollection) {
1200
+ const getCollections = base.getCollections.bind(base);
1201
+ const removeCollection = base.removeCollection.bind(base);
1202
+ this.getCollections = async () => (await getCollections()).filter(isUnscoped);
1203
+ this.setCollection = base.setCollection.bind(base);
1204
+ this.removeCollection = (id) => removeCollection(id, UNSCOPED);
1205
+ }
1206
+ if (base.getCollectionMemberships && base.setCollectionMembership && base.removeCollectionMembership) {
1207
+ const getMemberships = base.getCollectionMemberships.bind(base);
1208
+ const removeMembership = base.removeCollectionMembership.bind(base);
1209
+ this.getCollectionMemberships = async () => (await getMemberships()).filter(isUnscoped);
1210
+ this.setCollectionMembership = base.setCollectionMembership.bind(base);
1211
+ this.removeCollectionMembership = (collectionId, itemId) => removeMembership(collectionId, itemId, UNSCOPED);
1212
+ }
1213
+ }
1214
+ async getAll() {
1215
+ return (await this.base.getAll()).filter(isUnscoped);
1216
+ }
1217
+ async set(item) {
1218
+ await this.base.set(item);
1219
+ }
1220
+ async setMany(items) {
1221
+ if (this.base.setMany) await this.base.setMany(items);
1222
+ else for (const item of items) await this.base.set(item);
1223
+ }
1224
+ async remove(id) {
1225
+ await this.removeMany([id]);
1226
+ }
1227
+ async removeMany(ids) {
1228
+ const uniqueIds = [...new Set(ids)];
1229
+ if (this.base.removeMany) await this.base.removeMany(uniqueIds, UNSCOPED);
1230
+ else for (const id of uniqueIds) await this.base.remove(id, UNSCOPED);
1231
+ }
1232
+ async clear() {
1233
+ await this.removeMany((await this.getAll()).map((item) => item.id));
1234
+ const memberships = await this.getCollectionMemberships?.() ?? [];
1235
+ for (const { collectionId, itemId } of memberships) await this.removeCollectionMembership?.(collectionId, itemId);
1236
+ }
1237
+ async merge(items) {
1238
+ const merged = mergeKeepItemLists(await this.getAll(), items);
1239
+ await this.setMany(merged);
1240
+ return merged;
1241
+ }
1242
+ subscribe(listener) {
1243
+ return this.base.subscribe?.(listener) ?? (() => void 0);
1244
+ }
1245
+ };
1098
1246
  function createAuthenticatedRemote(options, scope) {
1099
1247
  const pull = options.transport.pull;
1100
1248
  const pullCollections = options.transport.pullCollections;
@@ -1119,7 +1267,11 @@ function createAuthenticatedRemote(options, scope) {
1119
1267
  pushCollection: options.transport.pushCollection ? async (collectionOperation) => {
1120
1268
  try {
1121
1269
  const token = await options.getAuthToken();
1122
- await options.transport.pushCollection?.(collectionOperation, { token, scope, collectionOperation });
1270
+ return await options.transport.pushCollection?.(collectionOperation, {
1271
+ token,
1272
+ scope,
1273
+ collectionOperation
1274
+ });
1123
1275
  } catch (cause) {
1124
1276
  return handleAuthFailure(cause, options, { collectionOperation, scope });
1125
1277
  }
@@ -1220,11 +1372,13 @@ export {
1220
1372
  decodeKeepListQuery,
1221
1373
  encodeKeepListQuery,
1222
1374
  exportItems,
1375
+ formatItemsAsMarkdown,
1223
1376
  getKeepCollectionItems,
1224
1377
  getKeepNavigationState,
1225
1378
  getKeepScopeKey,
1226
1379
  getTagCounts,
1227
1380
  importItems,
1381
+ inspectKeepBackup,
1228
1382
  isKeepItemMetadataStale,
1229
1383
  isKeepSyncAuthError,
1230
1384
  isProgressCompatible,