@keepkit/core 0.28.4 → 0.28.6

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,13 +1,115 @@
1
- import { K as KeepListQuery } from './store-45yaDeER.js';
2
- export { D as DEFAULT_KEEP_URL_PARAMS, I as ImportItemsOptions, a as ImportItemsResult, b as KEEP_BACKUP_FORMAT, c as KEEP_BACKUP_VERSION, d as KeepAutoRevalidationOptions, e as KeepBackup, f as KeepBackupImportError, g as KeepBackupParseError, h as KeepCollectionMeta, i as KeepItemMetadataRefresher, j as KeepItemResolver, k as KeepItemRevalidationRecord, l as KeepItemRevalidationResult, m as KeepItemRevalidationSummary, n as KeepItemRevalidator, o as KeepNavigationState, p as KeepRediscoveryOptions, q as KeepRediscoveryStrategy, r as KeepStore, s as KeepStoreActions, t as KeepStoreState, u as KeepUrlParamNames, v as KeepUrlState, w as KeepUrlSyncOptions, Q as QueryKeepItemsResult, R as RevalidateKeepItemsOptions, x as createInboxQuery, y as createRediscoveryQuery, z as decodeKeepListQuery, A as encodeKeepListQuery, B as exportItems, C as getKeepNavigationState, E as getTagCounts, F as importItems, G as isKeepItemMetadataStale, H as mergeKeepListQueryFromUrl, J as moveKeepItem, L as orderKeepItems, M as queryKeepItems, N as reconcileKeepItems, O as reorderKeepItems, P as revalidateKeepItems, S as serializeKeepListQuery } from './store-45yaDeER.js';
3
- import { K as KeepScope } from './scope-Dtkxpnof.js';
4
- export { S as ScopedStorageAdapter, a as ScopedSyncQueueAdapter, c as createScopedStorageAdapter, g as getKeepScopeKey, i as isSameKeepScope } from './scope-Dtkxpnof.js';
5
- import { R as RemoteSyncDriver, a as StorageAdapter, b as KeepItem, e as KeepPluginContext, f as KeepPlugin, d as SyncOperation, S as SyncScope, g as SyncCapableStorageAdapter, h as RemoteSyncResult, i as KeepSyncAuthError } from './types-C_U5Q44o.js';
6
- export { j as KeepAction, k as KeepChangeContext, l as KeepChangePhase, K as KeepCollectionDefinition, m as KeepConflictContext, n as KeepConflictResolver, o as KeepErrorContext, p as KeepErrorHandler, q as KeepEventHandlers, r as KeepInvalidItemPolicy, s as KeepItemInput, t as KeepItemStatus, u as KeepSchema, v as KeepSchemaParseResult, w as KeepStorageAccessError, x as KeepStorageError, y as KeepStorageOperation, z as KeepStorageParseError, A as KeepStorageQuotaError, B as KeepSyncAuthStatus, C as KeepSyncConflict, D as KeepSyncResolution, E as KeepSyncState, F as KeepSyncStatus, G as KeepUndoState, c as SyncQueueAdapter, H as isKeepSyncAuthError, I as normalizeKeepTags } from './types-C_U5Q44o.js';
1
+ import { a as StorageAdapter, b as KeepCollectionMembership, c as KeepItem, R as RemoteSyncDriver, k as KeepPluginContext, l as KeepPlugin, m as SyncOperation, n as KeepCollectionSyncOperation, o as KeepMembershipSyncOperation, S as SyncScope, p as SyncCapableStorageAdapter, q as RemoteSyncResult, K as KeepCollectionDefinition, r as KeepSyncAuthError } from './types-GTCMFt5T.js';
2
+ export { s as KeepAction, i as KeepChangeContext, t as KeepChangePhase, u as KeepCollectionSyncConflict, v as KeepCollectionSyncResult, w as KeepConflictContext, x as KeepConflictResolver, y as KeepErrorContext, z as KeepErrorHandler, A as KeepEventHandlers, h as KeepInvalidItemPolicy, B as KeepItemInput, f as KeepItemStatus, g as KeepSchema, C as KeepSchemaParseResult, D as KeepStorageAccessError, E as KeepStorageError, F as KeepStorageOperation, G as KeepStorageParseError, H as KeepStorageQuotaError, I as KeepSyncAuthStatus, J as KeepSyncConflict, e as KeepSyncQueueOperation, L as KeepSyncResolution, M as KeepSyncState, N as KeepSyncStatus, j as KeepUndoState, d as SyncQueueAdapter, O as isKeepSyncAuthError, P as normalizeKeepTags } from './types-GTCMFt5T.js';
3
+ import { K as KeepListQuery } from './store-98vWM3tV.js';
4
+ export { D as DEFAULT_KEEP_URL_PARAMS, I as ImportItemsOptions, a as ImportItemsResult, b as KEEP_BACKUP_FORMAT, c as KEEP_BACKUP_VERSION, d as KeepAutoRevalidationOptions, e as KeepBackup, f as KeepBackupAppliedCounts, g as KeepBackupDataType, h as KeepBackupImportError, i as KeepBackupParseError, j as KeepBackupV1, k as KeepBackupV2, l as KeepCollectionMeta, m as KeepItemMetadataRefresher, n as KeepItemResolver, o as KeepItemRevalidationRecord, p as KeepItemRevalidationResult, q as KeepItemRevalidationSummary, r as KeepItemRevalidator, s as KeepNavigationState, t as KeepRediscoveryOptions, u as KeepRediscoveryStrategy, v as KeepStore, w as KeepStoreActions, x as KeepStoreState, y as KeepUrlParamNames, z as KeepUrlState, A as KeepUrlSyncOptions, Q as QueryKeepItemsResult, R as RevalidateKeepItemsOptions, B as createInboxQuery, C as createRediscoveryQuery, E as decodeKeepListQuery, F as encodeKeepListQuery, G as exportItems, H as getKeepNavigationState, J as getTagCounts, L as importItems, M as isKeepItemMetadataStale, N as mergeKeepListQueryFromUrl, O as moveKeepItem, P as orderKeepItems, S as queryKeepItems, T as reconcileKeepItems, U as reorderKeepItems, V as revalidateKeepItems, W as serializeKeepListQuery } from './store-98vWM3tV.js';
5
+ import { K as KeepScope } from './scope-1bxGd68Y.js';
6
+ export { S as ScopedStorageAdapter, a as ScopedSyncQueueAdapter, c as createScopedStorageAdapter, g as getKeepScopeKey, i as isSameKeepScope } from './scope-1bxGd68Y.js';
7
7
  export { KeepSchemaValidationError, parseKeepMeta, validateKeepItem } from './schema.js';
8
8
  import { SyncStorageAdapterOptions, BrowserStorageAdapterOptions } from './storage.js';
9
9
  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, StorageAdapterFactoryOptions, SyncStorageAdapter, createBrowserStorageAdapter, createStorageAdapter } from './storage.js';
10
10
 
11
+ type KeepHistoryEntry = {
12
+ itemId: string;
13
+ lastViewedAt: number;
14
+ context?: KeepHistoryContext;
15
+ };
16
+ /** Application-owned revisit details such as language or deck. */
17
+ type KeepHistoryContext = Record<string, string>;
18
+ type KeepViewingRecord = {
19
+ id: string;
20
+ itemId: string;
21
+ viewedAt: number;
22
+ /** Omitted on legacy records written before timestamp tracking was added. */
23
+ createdAt?: number;
24
+ /** Omitted on legacy records written before timestamp tracking was added. */
25
+ updatedAt?: number;
26
+ note?: string;
27
+ };
28
+ interface KeepHistoryStorage {
29
+ getAll(): Promise<KeepHistoryEntry[]>;
30
+ getLimit(): Promise<number>;
31
+ setLimit(limit: number): Promise<void>;
32
+ record(itemId: string, viewedAt?: number, context?: KeepHistoryContext): Promise<KeepHistoryEntry[]>;
33
+ remove(itemId: string): Promise<void>;
34
+ clear(): Promise<void>;
35
+ }
36
+ interface KeepViewingRecordStorage {
37
+ getAll(itemId?: string): Promise<KeepViewingRecord[]>;
38
+ set(record: KeepViewingRecord): Promise<void>;
39
+ add(itemId: string, options?: {
40
+ viewedAt?: number;
41
+ note?: string;
42
+ }): Promise<KeepViewingRecord>;
43
+ remove(id: string): Promise<void>;
44
+ removeForItem(itemId: string): Promise<void>;
45
+ clear(): Promise<void>;
46
+ }
47
+ type LocalStorageActivityOptions = {
48
+ key?: string;
49
+ storage?: Storage;
50
+ maxEntries?: number;
51
+ now?: () => number;
52
+ createId?: () => string;
53
+ };
54
+ declare const DEFAULT_KEEP_HISTORY_KEY = "keepkit:view-history";
55
+ declare const DEFAULT_KEEP_VIEWING_RECORDS_KEY = "keepkit:viewing-records";
56
+ declare const DEFAULT_KEEP_HISTORY_LIMIT = 100;
57
+ /** Local history of opened guides. It never reads or mutates saved items. */
58
+ declare class LocalStorageKeepHistoryStorage implements KeepHistoryStorage {
59
+ private readonly key;
60
+ private readonly limitKey;
61
+ private readonly storage;
62
+ private readonly initialLimit;
63
+ private readonly now;
64
+ private writes;
65
+ constructor(options?: LocalStorageActivityOptions);
66
+ getAll(): Promise<KeepHistoryEntry[]>;
67
+ getLimit(): Promise<number>;
68
+ setLimit(limit: number): Promise<void>;
69
+ record(itemId: string, viewedAt?: number, context?: KeepHistoryContext): Promise<KeepHistoryEntry[]>;
70
+ remove(itemId: string): Promise<void>;
71
+ clear(): Promise<void>;
72
+ private writeEntries;
73
+ private withWriteLock;
74
+ private read;
75
+ private readRaw;
76
+ private writeRaw;
77
+ }
78
+ /** Explicit user-reported viewing events, kept separate from open history and saved items. */
79
+ declare class LocalStorageKeepViewingRecordStorage implements KeepViewingRecordStorage {
80
+ private readonly key;
81
+ private readonly storage;
82
+ private readonly now;
83
+ private readonly createId;
84
+ private writes;
85
+ constructor(options?: LocalStorageActivityOptions);
86
+ getAll(itemId?: string): Promise<KeepViewingRecord[]>;
87
+ set(record: KeepViewingRecord): Promise<void>;
88
+ add(itemId: string, options?: {
89
+ viewedAt?: number;
90
+ note?: string;
91
+ }): Promise<KeepViewingRecord>;
92
+ private saveRecord;
93
+ remove(id: string): Promise<void>;
94
+ removeForItem(itemId: string): Promise<void>;
95
+ clear(): Promise<void>;
96
+ private readRecords;
97
+ private readRaw;
98
+ private writeRecords;
99
+ private withWriteLock;
100
+ }
101
+ declare class KeepActivityStorageError extends Error {
102
+ readonly storageKey: string;
103
+ readonly cause?: unknown;
104
+ constructor(message: string, storageKey: string, cause?: unknown);
105
+ }
106
+
107
+ declare function getKeepCollectionItems<TMeta>(storage: StorageAdapter<TMeta>, collectionId: string): Promise<KeepItem<TMeta>[]>;
108
+ declare function addKeepItemToCollection<TMeta>(storage: StorageAdapter<TMeta>, collectionId: string, itemId: string, order?: number): Promise<KeepCollectionMembership>;
109
+ declare function removeKeepItemFromCollection<TMeta>(storage: StorageAdapter<TMeta>, collectionId: string, itemId: string): Promise<void>;
110
+ /** Reorders only the requested collection and leaves other course membership orders untouched. */
111
+ declare function reorderKeepCollectionItems<TMeta>(storage: StorageAdapter<TMeta>, collectionId: string, itemIds: string[]): Promise<KeepCollectionMembership[]>;
112
+
11
113
  type KeepKitPresetMode = "local" | "sync" | "backup";
12
114
  type KeepKitPresetOptions<TMeta = Record<string, unknown>> = {
13
115
  mode?: KeepKitPresetMode;
@@ -29,6 +131,74 @@ type KeepKitSetup<TMeta = Record<string, unknown>> = {
29
131
  declare function createKeepKitPreset<TMeta = Record<string, unknown>>(options?: KeepKitPresetOptions<TMeta>): KeepKitSetup<TMeta>;
30
132
  declare const createKeepKitSetup: typeof createKeepKitPreset;
31
133
 
134
+ type KeepCourseProgress = {
135
+ kind: "course";
136
+ courseId: string;
137
+ currentItemId?: string;
138
+ updatedAt: number;
139
+ };
140
+ type KeepItemProgress = {
141
+ kind: "item";
142
+ itemId: string;
143
+ audioPositionMs?: number;
144
+ /** App-defined heading ID or legacy numeric offset. */
145
+ readingPosition?: number | string;
146
+ audioId?: string;
147
+ language?: string;
148
+ contentVersion?: string;
149
+ updatedAt: number;
150
+ };
151
+ type KeepProgressRecord = KeepCourseProgress | KeepItemProgress;
152
+ type KeepProgressCompatibility = {
153
+ language?: string;
154
+ contentVersion?: string;
155
+ audioId?: string;
156
+ };
157
+ interface KeepProgressStorage {
158
+ getAll(): Promise<KeepProgressRecord[]>;
159
+ getCourse(courseId: string): Promise<KeepCourseProgress | undefined>;
160
+ getItem(itemId: string, compatibility?: KeepProgressCompatibility): Promise<KeepItemProgress | undefined>;
161
+ saveCourse(courseId: string, currentItemId?: string): Promise<KeepCourseProgress>;
162
+ saveItem(itemId: string, progress: Omit<KeepItemProgress, "kind" | "itemId" | "updatedAt">): Promise<KeepItemProgress>;
163
+ set(record: KeepProgressRecord): Promise<void>;
164
+ resetCourse(courseId: string): Promise<void>;
165
+ resetItem(itemId: string): Promise<void>;
166
+ clear(): Promise<void>;
167
+ }
168
+ type LocalStorageProgressOptions = {
169
+ key?: string;
170
+ storage?: Storage;
171
+ now?: () => number;
172
+ };
173
+ declare const DEFAULT_KEEP_PROGRESS_KEY = "keepkit:progress";
174
+ /** Stores course and reader progress independently of saved items and open history. */
175
+ declare class LocalStorageKeepProgressStorage implements KeepProgressStorage {
176
+ private readonly key;
177
+ private readonly storage;
178
+ private readonly now;
179
+ private writes;
180
+ constructor(options?: LocalStorageProgressOptions);
181
+ getAll(): Promise<KeepProgressRecord[]>;
182
+ getCourse(courseId: string): Promise<KeepCourseProgress | undefined>;
183
+ getItem(itemId: string, compatibility?: KeepProgressCompatibility): Promise<KeepItemProgress | undefined>;
184
+ saveCourse(courseId: string, currentItemId?: string): Promise<KeepCourseProgress>;
185
+ saveItem(itemId: string, progress: Omit<KeepItemProgress, "kind" | "itemId" | "updatedAt">): Promise<KeepItemProgress>;
186
+ set(record: KeepProgressRecord): Promise<void>;
187
+ resetCourse(courseId: string): Promise<void>;
188
+ resetItem(itemId: string): Promise<void>;
189
+ clear(): Promise<void>;
190
+ private readRaw;
191
+ private writeRecords;
192
+ private withWriteLock;
193
+ }
194
+ /** Reject stale reader offsets when the selected language or content revision changed. */
195
+ declare function isProgressCompatible(record: KeepItemProgress, compatibility?: KeepProgressCompatibility): boolean;
196
+ declare class KeepProgressStorageError extends Error {
197
+ readonly storageKey: string;
198
+ readonly cause?: unknown;
199
+ constructor(message: string, storageKey: string, cause?: unknown);
200
+ }
201
+
32
202
  type KeepSavedView<TMeta = Record<string, unknown>> = {
33
203
  id: string;
34
204
  name: string;
@@ -63,6 +233,13 @@ declare class LocalStorageKeepSavedViewStorage<TMeta = Record<string, unknown>>
63
233
  declare function mergeKeepItems<TMeta>(localItems: KeepItem<TMeta>[], target: StorageAdapter<TMeta>): Promise<KeepItem<TMeta>[]>;
64
234
  /** Read anonymous items, merge them into the target, then clear the source. */
65
235
  declare function migrateKeepItems<TMeta>(source: StorageAdapter<TMeta>, target: StorageAdapter<TMeta>): Promise<KeepItem<TMeta>[]>;
236
+ type LegacyCollectionMigrationResult = {
237
+ migrated: number;
238
+ skipped: number;
239
+ missingCollectionIds: string[];
240
+ };
241
+ /** Move legacy single-collection item fields into course-specific memberships once. */
242
+ declare function migrateLegacyCollectionMemberships<TMeta>(storage: StorageAdapter<TMeta>): Promise<LegacyCollectionMigrationResult>;
66
243
 
67
244
  type KeepInvalidationPluginOptions<TMeta = Record<string, unknown>> = {
68
245
  /** Query keys to invalidate after a successful local KeepKit mutation. */
@@ -78,14 +255,22 @@ type AuthenticatedSyncRequestContext<TMeta = Record<string, unknown>> = {
78
255
  token: string | null;
79
256
  scope?: SyncScope;
80
257
  operation?: SyncOperation<TMeta>;
258
+ collectionOperation?: KeepCollectionSyncOperation;
259
+ membershipOperation?: KeepMembershipSyncOperation;
81
260
  };
82
261
  /** Transport boundary for auth-aware requests; cookies and bearer tokens remain host concerns. */
83
262
  type AuthenticatedSyncTransport<TMeta = Record<string, unknown>> = {
84
263
  push: (operation: SyncOperation<TMeta>, context: AuthenticatedSyncRequestContext<TMeta>) => Promise<RemoteSyncResult<TMeta>>;
85
264
  pull?: (context: AuthenticatedSyncRequestContext<TMeta>) => Promise<KeepItem<TMeta>[]>;
265
+ pushCollection?: (operation: KeepCollectionSyncOperation, context: AuthenticatedSyncRequestContext<TMeta>) => Promise<void>;
266
+ pullCollections?: (context: AuthenticatedSyncRequestContext<TMeta>) => Promise<KeepCollectionDefinition[]>;
267
+ pushMembership?: (operation: KeepMembershipSyncOperation, context: AuthenticatedSyncRequestContext<TMeta>) => Promise<void>;
268
+ pullMemberships?: (context: AuthenticatedSyncRequestContext<TMeta>) => Promise<KeepCollectionMembership[]>;
86
269
  };
87
270
  type AuthenticatedSyncAuthContext<TMeta = Record<string, unknown>> = {
88
271
  operation?: SyncOperation<TMeta>;
272
+ collectionOperation?: KeepCollectionSyncOperation;
273
+ membershipOperation?: KeepMembershipSyncOperation;
89
274
  scope?: SyncScope;
90
275
  };
91
276
  type AuthenticatedSyncKitOptions<TMeta = Record<string, unknown>> = Omit<SyncStorageAdapterOptions<TMeta>, "local" | "remote" | "scope"> & {
@@ -116,4 +301,4 @@ type AuthenticatedSyncKit<TMeta = Record<string, unknown>> = {
116
301
  /** Creates auth-independent sync wiring with per-request tokens and isolated account scopes. */
117
302
  declare function createAuthenticatedSyncKit<TMeta = Record<string, unknown>>(options: AuthenticatedSyncKitOptions<TMeta>): AuthenticatedSyncKit<TMeta>;
118
303
 
119
- export { type AuthenticatedSyncAuthContext, type AuthenticatedSyncKit, type AuthenticatedSyncKitOptions, type AuthenticatedSyncRequestContext, type AuthenticatedSyncTransport, BrowserStorageAdapterOptions, DEFAULT_SAVED_VIEWS_STORAGE_KEY, type KeepInvalidationPluginOptions, KeepItem, type KeepKitPresetMode, type KeepKitPresetOptions, type KeepKitSetup, KeepListQuery, KeepPlugin, KeepPluginContext, type KeepSavedView, type KeepSavedViewStorage, KeepScope, KeepSyncAuthError, LocalStorageKeepSavedViewStorage, RemoteSyncDriver, RemoteSyncResult, StorageAdapter, SyncCapableStorageAdapter, SyncOperation, SyncScope, SyncStorageAdapterOptions, createAuthenticatedSyncKit, createKeepInvalidationPlugin, createKeepKitPreset, createKeepKitSetup, mergeKeepItems, migrateKeepItems };
304
+ 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 };