@keepkit/core 0.28.8 → 0.28.10
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 +160 -125
- package/dist/chunk-CSBPFROD.js +276 -0
- package/dist/chunk-CSBPFROD.js.map +1 -0
- package/dist/{chunk-SLH4DFYQ.js → chunk-SS22UTBH.js} +1438 -92
- package/dist/chunk-SS22UTBH.js.map +1 -0
- package/dist/core.d.ts +5 -7
- package/dist/core.js +22 -33
- package/dist/core.js.map +1 -1
- package/dist/react.d.ts +4 -5
- package/dist/react.js +87 -54
- package/dist/react.js.map +1 -1
- package/dist/schema.d.ts +1 -1
- package/dist/storage.d.ts +23 -10
- package/dist/storage.js +4 -1
- package/dist/{store-98vWM3tV.d.ts → store-C8cxvXRV.d.ts} +2 -73
- package/dist/{types-GTCMFt5T.d.ts → types-DjXvE9Zb.d.ts} +243 -1
- package/package.json +1 -1
- package/dist/chunk-EMOPFB5D.js +0 -594
- package/dist/chunk-EMOPFB5D.js.map +0 -1
- package/dist/chunk-SLH4DFYQ.js.map +0 -1
- package/dist/scope-1bxGd68Y.d.ts +0 -46
package/README.md
CHANGED
|
@@ -2,191 +2,226 @@
|
|
|
2
2
|
|
|
3
3
|
[日本語](#日本語) | [English](#english)
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
フレームワーク中立の保存・コレクションプリミティブとReactの低レベルbindingを提供します。通常のReactアプリケーションでは、より少ないコードで利用できる`@keepkit/ui`を推奨します。
|
|
5
|
+
Release: v0.28.10
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
import { KeepButton, KeepProvider, useKeepItem, useKeepList } from "@keepkit/core/react";
|
|
11
|
-
import { createBrowserStorageAdapter } from "@keepkit/core/storage";
|
|
7
|
+
## 日本語
|
|
12
8
|
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
フレームワーク中立の保存処理と、React向けのProvider・hooksを提供します。
|
|
10
|
+
標準の一覧UIが必要な場合は[@keepkit/ui](../keepkit-ui/README.md)を使ってください。記事向けの`presentation="reading"`と行内選択はUIパッケージの追加機能で、Coreの型・保存形式は変更しません。未訪問の判定には既存の`lastOpenedAt`と`recordOpen()`を使います。
|
|
15
11
|
|
|
16
|
-
|
|
17
|
-
<KeepButton item={article} />
|
|
18
|
-
</KeepProvider>;
|
|
12
|
+
### インストールと入口
|
|
19
13
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
targetType: "article",
|
|
23
|
-
search: { query: "react" },
|
|
24
|
-
sort: { by: "updatedAt", direction: "desc" },
|
|
25
|
-
pagination: { page: 1, pageSize: 20 },
|
|
26
|
-
});
|
|
14
|
+
```bash
|
|
15
|
+
pnpm add @keepkit/core
|
|
27
16
|
```
|
|
28
17
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
`
|
|
18
|
+
| import先 | 用途 |
|
|
19
|
+
| --- | --- |
|
|
20
|
+
| `@keepkit/core/core` | 型、ストア、検索、コレクション、バックアップなど。Reactへの依存なし |
|
|
21
|
+
| `@keepkit/core/react` | `createKeepKit`、`KeepProvider`、`KeepButton`、hooks |
|
|
22
|
+
| `@keepkit/core/storage` | localStorage・IndexedDB・fallback・同期adapter |
|
|
23
|
+
| `@keepkit/core/schema` | スキーマの解析・検証 |
|
|
32
24
|
|
|
33
|
-
|
|
25
|
+
パッケージルートにはexportがありません。React bindingはReact 18以降に対応します。
|
|
34
26
|
|
|
35
|
-
|
|
27
|
+
### Reactで使う
|
|
36
28
|
|
|
37
|
-
|
|
29
|
+
```tsx
|
|
30
|
+
import { createKeepKit } from "@keepkit/core/react";
|
|
31
|
+
import { createBrowserStorageAdapter } from "@keepkit/core/storage";
|
|
38
32
|
|
|
39
|
-
|
|
33
|
+
type ArticleMeta = { title: string; url: string };
|
|
34
|
+
const keep = createKeepKit<ArticleMeta>({
|
|
35
|
+
storage: createBrowserStorageAdapter({ key: "my-app:items" }),
|
|
36
|
+
});
|
|
37
|
+
const article = {
|
|
38
|
+
id: "article-123",
|
|
39
|
+
targetType: "article",
|
|
40
|
+
meta: { title: "Example article", url: "/articles/123" },
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
function SavedArticles() {
|
|
44
|
+
const { items, isLoading, error } = keep.useList({ targetType: "article" });
|
|
45
|
+
if (isLoading) return <p>読み込み中…</p>;
|
|
46
|
+
if (error) return <p role="alert">保存一覧を読み込めませんでした。</p>;
|
|
47
|
+
return <ul>{items.map((item) => <li key={item.id}>{item.meta.title}</li>)}</ul>;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function App() {
|
|
51
|
+
return (
|
|
52
|
+
<keep.Provider>
|
|
53
|
+
<keep.Button item={article} />
|
|
54
|
+
<SavedArticles />
|
|
55
|
+
</keep.Provider>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
```
|
|
40
59
|
|
|
41
|
-
|
|
60
|
+
hooksはProvider内のコンポーネントで呼び出します。
|
|
61
|
+
保存入力は`{ id, meta, targetType?, note?, tags?, order? }`が基本です。時刻とタグの正規化はKeepKitが管理します。
|
|
62
|
+
`keep.useItem(article)`で保存・解除・メモ更新などを、`keep.useList(query)`で一覧と一括操作を利用できます。
|
|
42
63
|
|
|
43
|
-
|
|
64
|
+
### 主な機能
|
|
44
65
|
|
|
45
|
-
|
|
66
|
+
| 用途 | API |
|
|
67
|
+
| --- | --- |
|
|
68
|
+
| 検索・絞り込み | `KeepListQuery`の`search`、`tags`、`sort`、`pagination`。Reactなしでは`queryKeepItems` |
|
|
69
|
+
| 整理 | archive・pin・`collectionId`、`createInboxQuery`、`useKeepCollections` |
|
|
70
|
+
| 複数コレクションへの所属・順序 | `addKeepItemToCollection`、`getKeepCollectionItems`、`reorderKeepCollectionItems`、`removeKeepItemFromCollection` |
|
|
71
|
+
| 再発見 | `useKeepItem(item).recordOpen()`、`createRediscoveryQuery`、`useKeepRediscovery` |
|
|
72
|
+
| 閲覧履歴・鑑賞記録・進行位置 | `LocalStorageKeepHistoryStorage`、`LocalStorageKeepViewingRecordStorage`、`LocalStorageKeepProgressStorage` |
|
|
73
|
+
| 保存対象の再検証 | Providerの`validateItem` / `resolveItem`、`revalidateItems` |
|
|
46
74
|
|
|
47
|
-
|
|
75
|
+
一覧は未アーカイブのアイテムを既定で返します。`archiveScope: "all"`で両方を、`archived: true`でアーカイブを取得できます。
|
|
76
|
+
複数コレクションへの所属はアイテムと別に保存され、所属を外しても共有アイテムやメモは残ります。
|
|
48
77
|
|
|
49
|
-
|
|
78
|
+
`before`プラグインや永続化の失敗は保存操作を拒否します。保存成功後のコールバック、`after`プラグイン、`onChange`の例外は`onError(error, { action, id, phase: "notification" })`で報告し、保存済み状態とUndoを維持します。通知例外でも保存操作のPromiseは成功し、後続通知は継続します。
|
|
50
79
|
|
|
51
|
-
|
|
80
|
+
### 保存・同期・バックアップ
|
|
52
81
|
|
|
53
|
-
|
|
82
|
+
- `createBrowserStorageAdapter`はIndexedDB優先で、localStorageへフォールバックします。`scope`でユーザー/テナントを分離できます。
|
|
83
|
+
- `SyncStorageAdapter`と`RemoteSyncDriver`で永続オフラインキュー・再試行・競合処理を組み込みます。定義・所属の同期には、それぞれ`pushCollection` / `pullCollections`、`pushMembership` / `pullMemberships`が必要です。
|
|
84
|
+
- 認証方式はアプリ側で管理します。[認証付き同期の例](../../examples/authenticated-sync/README.md)でトークン取得とscope切り替えを確認できます。
|
|
85
|
+
- `exportItems(storage)` / `importItems(storage, json, { mode: "merge" })`で保存アイテム・コレクション定義・所属をバックアップ・復元します。閲覧履歴・鑑賞記録・進行位置は含みません。
|
|
54
86
|
|
|
55
|
-
|
|
87
|
+
fallbackの更新・削除・全消去・コレクション・所属操作は、ストレージとscopeごとのlocalStorage journalに記録します。journal保存が成功判定です。実データへの反映が失敗しても記録から変更を読み取り、再起動後も復旧を試します。全操作をprimaryへ再生し、読み取りとjournal消去が成功した後にIndexedDBへ戻ります。`clear()`はアイテムと所属を消去し、コレクション定義を保持します。
|
|
56
88
|
|
|
57
|
-
|
|
89
|
+
fallbackへの書き込みと復旧にはWeb Locks APIとJSON保存可能なメタデータが必要です。journal保存失敗はデータ変更前にエラーを返します。Web Locks未対応でも、未反映操作がなくIndexedDBが正常なら従来の保存が使えます。正常なIndexedDBのメタデータにJSON制約は追加しません。
|
|
58
90
|
|
|
59
|
-
|
|
91
|
+
journal v2は完全なアイテム・コレクション・所属のスナップショットと取得時刻を保存します。v1の保留操作も読み込み、空primaryへの既存データ移行後にスナップショットを作ります。障害中の読み取りは最後の永続スナップショットと保留操作を使います。primary保存後のスナップショット更新失敗は保存成功を維持し、`storage.recovery?.getState()`で`snapshotStale`と`issue`を報告します。次の正常読み取りで更新を再試行します。
|
|
60
92
|
|
|
61
|
-
|
|
62
|
-
- `useKeepItem(id, payload)`は`useKeepItem(item)`に変わりました。
|
|
63
|
-
- `useKeepShortcut({ id, itemPayload })`は`useKeepShortcut({ item })`に変わりました。
|
|
64
|
-
- `KeepListOptions`は`KeepListQuery`に変わり、一覧条件は`search`、`sort`、`pagination`へ統一されました。
|
|
93
|
+
標準browser factoryは旧v1保存キーからも読み込み、新しい記録の永続化後に旧キーを削除します。旧キーだけではbackendやscopeを一意に判定できない場合は、記録を保持してエラーを返します。独自の`createRecoveryJournal`を使う場合は、その実装で旧キーを移行してください。
|
|
65
94
|
|
|
66
|
-
|
|
95
|
+
`StorageAdapter.recovery`は任意です。`getState()` / `subscribe()`で状態を観察し、`inspect({ selections })`で書き込みなしに保存元と退避済み旧fallbackを比較します。異なるIDは両方保持し、同じIDの競合は明示選択が必要です。`apply({ token, selections })`は適用直前に再照合し、古い確認を拒否します。修復前のバックアップv2と承認済み操作を一回のjournal保存で確定します。`status: "pending"`は修復内容を保存済み・反映待ちなので、再提出せず`retry()`で続行してください。バックアップは自動削除しません。後続の`inspect()`が返す`retainedBackups`から修復前のJSONバックアップv2を取得できます。項目・所属・コレクションは対象scopeだけを比較・変更します。
|
|
67
96
|
|
|
68
|
-
|
|
97
|
+
`KeepFallbackRecovery`はこの能力を明示的に渡すUIです。[UIガイド](../keepkit-ui/README.md)を参照してください。`SyncStorageAdapter.recovery`は状態表示だけを公開します。分岐の修復は同期を開始する前のstandalone local adapterで行います。
|
|
69
98
|
|
|
70
|
-
|
|
71
|
-
import { KeepButton, KeepProvider, useKeepItem, useKeepList } from "@keepkit/core/react";
|
|
72
|
-
import { createBrowserStorageAdapter } from "@keepkit/core/storage";
|
|
99
|
+
独自の`FallbackStorageAdapter`には`recoveryJournal: FallbackRecoveryJournal<TMeta>`を渡せます。`read` / `write`でv1またはv2の状態を永続化し、`runExclusive`で同じbackendへのアクセスを排他します。任意の`subscribe`は別タブの変更を通知します。browser factoryの`createRecoveryJournal`には保存キー・排他キー・scopeが渡されます。独自排他機構を接続でき、標準実装は排他なしのjournal変更・復旧を拒否します。同一backendの全scopeで排他キーを共有してください。localStorageを使う独自実装は、読み取り前と書き込み後のタスク終了までロックを保持します。標準`LocalStorageRecoveryJournal`はこの待機を含みます。
|
|
73
100
|
|
|
74
|
-
|
|
75
|
-
const article = { id: "article-123", targetType: "article", meta: { title: "Example", url: "/article" } };
|
|
101
|
+
JSON保存するmetadata・バックアップ・localStorage同期キューは、Date、Map/Set、非有限数、undefined、function、symbol、BigInt、循環参照などを`KeepStorageSerializationError`で拒否します。既知の任意フィールドのundefinedは省略できます。正常なIndexedDB保存はJSON互換性を要求しませんが、予備スナップショットの更新やJSON出力は失敗し得ます。
|
|
76
102
|
|
|
77
|
-
|
|
78
|
-
<KeepButton item={article} />
|
|
79
|
-
</KeepProvider>;
|
|
103
|
+
scope付きadapterを別のscopeで包み直しても書き込み先は切り替わりません。その構成の変更操作は保存前に拒否します。切替先のscopeからadapterを作成してください。
|
|
80
104
|
|
|
81
|
-
|
|
82
|
-
const list = useKeepList({
|
|
83
|
-
targetType: "article",
|
|
84
|
-
search: { query: "react" },
|
|
85
|
-
sort: { by: "updatedAt", direction: "desc" },
|
|
86
|
-
pagination: { page: 1, pageSize: 20 },
|
|
87
|
-
});
|
|
88
|
-
```
|
|
105
|
+
導入時は旧実装のタブをすべて更新してください。記録のない削除意図や失われた内容は自動復元できません。スナップショット保存自体が失敗した期間の完全な障害時表示と、排他機構のない環境での安全な書き込みは保証できません。
|
|
89
106
|
|
|
90
|
-
|
|
107
|
+
既存IndexedDBのコレクション保存先は`databaseName:storeName:collections`です。たとえば`("a:b", "c")`と`("a", "b:c")`は同じ保存先になるため、同じscopeで併用しないでください。この既存形式の曖昧なデータは、journal移行では自動分離できません。
|
|
91
108
|
|
|
92
|
-
|
|
109
|
+
**Replace(置換)は空のバックアップでも対象範囲を置き換え、ロールバックしません。** 途中失敗は`KeepBackupImportError`の`failedStage`と`applied`で確認できます。スコープ付きadapterは別scopeのデータを変更前に拒否します。
|
|
93
110
|
|
|
94
|
-
|
|
111
|
+
独自の`StorageAdapter`で定義・所属を扱う場合は、`getCollections` / `setCollection` / `removeCollection`と`getCollectionMemberships` / `setCollectionMembership` / `removeCollectionMembership`を実装してください。Providerのコレクション作成・改名・削除は定義メソッドが揃わない場合に拒否し、アイテムの所属も変更しません。
|
|
95
112
|
|
|
96
|
-
|
|
113
|
+
履歴・鑑賞記録・進行位置のlocalStorage書き込みには、ブラウザーでWeb Locks APIが必要です。未対応や保存先が利用できない場合はエラーを返します。SSRで初期化できますが、永続化操作はブラウザー側で行います。
|
|
114
|
+
履歴・進行位置のキーはアプリ側でユーザーごとに分け、進行位置の取得には記録と一致する言語・コンテンツ版・音声IDを渡してください。
|
|
97
115
|
|
|
98
|
-
|
|
116
|
+
デモと開発手順は[リポジトリREADME](../../README.md)、変更履歴は[リリースノート](../../RELEASE_NOTES.md)を参照してください。
|
|
99
117
|
|
|
100
|
-
|
|
118
|
+
## English
|
|
101
119
|
|
|
102
|
-
|
|
120
|
+
Framework-neutral persistence primitives and React providers and hooks.
|
|
121
|
+
Use [@keepkit/ui](../keepkit-ui/README.md) when you want a ready-made collection UI. Its opt-in `presentation="reading"` and inline selection add UI behavior without changing Core types or storage formats. Unvisited uses the existing `lastOpenedAt` and `recordOpen()` contracts.
|
|
103
122
|
|
|
104
|
-
|
|
123
|
+
### Installation and entry points
|
|
105
124
|
|
|
106
|
-
|
|
125
|
+
```bash
|
|
126
|
+
pnpm add @keepkit/core
|
|
127
|
+
```
|
|
107
128
|
|
|
108
|
-
|
|
129
|
+
| Import | Purpose |
|
|
130
|
+
| --- | --- |
|
|
131
|
+
| `@keepkit/core/core` | Types, store, queries, collections, and backups, with no React imports |
|
|
132
|
+
| `@keepkit/core/react` | `createKeepKit`, `KeepProvider`, `KeepButton`, and hooks |
|
|
133
|
+
| `@keepkit/core/storage` | localStorage, IndexedDB, fallback, and sync adapters |
|
|
134
|
+
| `@keepkit/core/schema` | Schema parsing and validation |
|
|
109
135
|
|
|
110
|
-
|
|
136
|
+
The package root has no export. React bindings support React 18 or later.
|
|
111
137
|
|
|
112
|
-
|
|
138
|
+
### React usage
|
|
113
139
|
|
|
114
|
-
|
|
140
|
+
```tsx
|
|
141
|
+
import { createKeepKit } from "@keepkit/core/react";
|
|
142
|
+
import { createBrowserStorageAdapter } from "@keepkit/core/storage";
|
|
115
143
|
|
|
116
|
-
|
|
144
|
+
type ArticleMeta = { title: string; url: string };
|
|
145
|
+
const keep = createKeepKit<ArticleMeta>({
|
|
146
|
+
storage: createBrowserStorageAdapter({ key: "my-app:items" }),
|
|
147
|
+
});
|
|
148
|
+
const article = {
|
|
149
|
+
id: "article-123",
|
|
150
|
+
targetType: "article",
|
|
151
|
+
meta: { title: "Example article", url: "/articles/123" },
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
function SavedArticles() {
|
|
155
|
+
const { items, isLoading, error } = keep.useList({ targetType: "article" });
|
|
156
|
+
if (isLoading) return <p>Loading…</p>;
|
|
157
|
+
if (error) return <p role="alert">Could not load saved items.</p>;
|
|
158
|
+
return <ul>{items.map((item) => <li key={item.id}>{item.meta.title}</li>)}</ul>;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export function App() {
|
|
162
|
+
return (
|
|
163
|
+
<keep.Provider>
|
|
164
|
+
<keep.Button item={article} />
|
|
165
|
+
<SavedArticles />
|
|
166
|
+
</keep.Provider>
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
```
|
|
117
170
|
|
|
118
|
-
|
|
171
|
+
Call hooks inside components under the provider.
|
|
172
|
+
The basic save input is `{ id, meta, targetType?, note?, tags?, order? }`; KeepKit manages timestamps and tag normalization.
|
|
173
|
+
Use `keep.useItem(article)` for saves, removal, and note updates, and `keep.useList(query)` for lists and bulk operations.
|
|
119
174
|
|
|
120
|
-
|
|
175
|
+
### Main APIs
|
|
121
176
|
|
|
122
|
-
|
|
177
|
+
| Task | API |
|
|
178
|
+
| --- | --- |
|
|
179
|
+
| Search and filtering | `KeepListQuery.search`, `tags`, `sort`, and `pagination`; `queryKeepItems` without React |
|
|
180
|
+
| Organization | Archive, pin, `collectionId`, `createInboxQuery`, and `useKeepCollections` |
|
|
181
|
+
| Multiple collections and ordering | `addKeepItemToCollection`, `getKeepCollectionItems`, `reorderKeepCollectionItems`, `removeKeepItemFromCollection` |
|
|
182
|
+
| Rediscovery | `useKeepItem(item).recordOpen()`, `createRediscoveryQuery`, and `useKeepRediscovery` |
|
|
183
|
+
| History, viewing records, and progress | `LocalStorageKeepHistoryStorage`, `LocalStorageKeepViewingRecordStorage`, `LocalStorageKeepProgressStorage` |
|
|
184
|
+
| Source revalidation | Provider `validateItem` / `resolveItem` and `revalidateItems` |
|
|
123
185
|
|
|
124
|
-
|
|
186
|
+
Lists return unarchived items by default. Use `archiveScope: "all"` for both or `archived: true` for archived items.
|
|
187
|
+
Memberships are stored separately; removing one leaves the shared item and note intact.
|
|
125
188
|
|
|
126
|
-
|
|
189
|
+
Failures in `before` plugins or persistence reject the mutation. Errors from post-save callbacks, `after` plugins, and `onChange` are reported through `onError(error, { action, id, phase: "notification" })`, preserving committed state and Undo. The mutation resolves successfully and later notifications still run.
|
|
127
190
|
|
|
128
|
-
|
|
191
|
+
### Storage, sync, and backups
|
|
129
192
|
|
|
130
|
-
|
|
193
|
+
- `createBrowserStorageAdapter` prefers IndexedDB and falls back to localStorage. Use `scope` to isolate users and tenants.
|
|
194
|
+
- Combine `SyncStorageAdapter` and `RemoteSyncDriver` for durable offline queues, retries, and conflicts. Definition and membership sync require `pushCollection` / `pullCollections` and `pushMembership` / `pullMemberships`, respectively.
|
|
195
|
+
- Authentication belongs to your app. See the [authenticated sync example](../../examples/authenticated-sync/README.md) for tokens and scope changes.
|
|
196
|
+
- 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.
|
|
131
197
|
|
|
132
|
-
|
|
198
|
+
Fallback updates, removals, clears, collection changes, and memberships enter a localStorage journal isolated by storage configuration and scope. Saving the journal commits the mutation. Reads apply recorded changes even if their projection into fallback storage fails, and recovery retries after restart. The adapter returns to IndexedDB after replaying every operation, reading the primary successfully, and clearing the journal. `clear()` removes items and memberships, preserving collection definitions.
|
|
133
199
|
|
|
134
|
-
|
|
200
|
+
Fallback writes and recovery require the Web Locks API and JSON-compatible metadata. Journal write failures reject before changing data. Browsers without Web Locks can still save to a healthy IndexedDB primary when no operations are pending. Healthy IndexedDB metadata gains no JSON restriction.
|
|
135
201
|
|
|
136
|
-
|
|
202
|
+
Journal v2 stores complete item, collection, and membership snapshots with their capture time. It also reads pending v1 operations and creates its first snapshot after migrating legacy data into an empty primary. Outage reads use the last durable snapshot plus pending operations. Failure to refresh the snapshot after a primary commit preserves mutation success and reports `snapshotStale` and `issue` through `storage.recovery?.getState()`. The next healthy read retries the refresh.
|
|
137
203
|
|
|
138
|
-
|
|
204
|
+
The standard browser factory also reads the original v1 storage key and removes it only after persisting the new record. If the old key cannot identify the backend or scope unambiguously, it preserves the record and reports an error. Custom `createRecoveryJournal` implementations must migrate their own older keys.
|
|
139
205
|
|
|
140
|
-
|
|
206
|
+
`StorageAdapter.recovery` is optional. Observe status through `getState()` / `subscribe()`, and compare storage sources and archived legacy fallback through `inspect({ selections })` without writing. Distinct IDs are retained together; conflicting records with the same identity need an explicit choice. `apply({ token, selections })` rechecks the data immediately before applying and rejects stale confirmation. It commits pre-repair v2 backups and the approved operation list in one journal write. A `status: "pending"` result means the repair is saved and awaiting projection: continue through `retry()` instead of submitting it again. Backups are never automatically deleted. Later `inspect()` results expose earlier v2 JSON backups through `retainedBackups`. Comparisons and changes include only the active scope.
|
|
141
207
|
|
|
142
|
-
|
|
208
|
+
`KeepFallbackRecovery` accepts this capability explicitly; see the [UI guide](../keepkit-ui/README.md). `SyncStorageAdapter.recovery` exposes status only. Repair existing branches through a standalone local adapter before starting synchronization.
|
|
143
209
|
|
|
144
|
-
|
|
145
|
-
import {
|
|
146
|
-
LocalStorageKeepHistoryStorage,
|
|
147
|
-
LocalStorageKeepProgressStorage,
|
|
148
|
-
LocalStorageKeepViewingRecordStorage,
|
|
149
|
-
exportItems,
|
|
150
|
-
importItems,
|
|
151
|
-
migrateLegacyCollectionMemberships,
|
|
152
|
-
} from "@keepkit/core/core";
|
|
153
|
-
import { createBrowserStorageAdapter } from "@keepkit/core/storage";
|
|
210
|
+
Custom `FallbackStorageAdapter` instances can accept `recoveryJournal: FallbackRecoveryJournal<TMeta>`. Persist v1 or v2 state through `read` / `write` and provide exclusive access to the same backend through `runExclusive`. Optional `subscribe` notifies consumers of other tabs' changes. The browser factory's `createRecoveryJournal` receives the storage key, lock key, and scope. It supports a custom lock implementation; the default rejects journal changes and recovery without exclusive access. Share the lock key across all scopes using the same backend. Custom localStorage journals must hold the lock across task boundaries before reads and after writes. The standard `LocalStorageRecoveryJournal` includes these waits.
|
|
154
211
|
|
|
155
|
-
|
|
156
|
-
const history = new LocalStorageKeepHistoryStorage({ key: "my-app:user-1:history" });
|
|
157
|
-
await history.record("guide-1", Date.now(), { language: "ja" });
|
|
158
|
-
await migrateLegacyCollectionMemberships(storage);
|
|
159
|
-
const backup = await exportItems(storage);
|
|
160
|
-
await importItems(storage, backup, { mode: "replace" });
|
|
161
|
-
|
|
162
|
-
const progress = new LocalStorageKeepProgressStorage({ key: "my-app:user-1:progress" });
|
|
163
|
-
await progress.saveItem("guide-1", {
|
|
164
|
-
audioId: "guide-1-ja",
|
|
165
|
-
audioPositionMs: 1250,
|
|
166
|
-
readingPosition: "heading-intro",
|
|
167
|
-
language: "ja",
|
|
168
|
-
contentVersion: "v2",
|
|
169
|
-
});
|
|
170
|
-
const resume = await progress.getItem("guide-1", {
|
|
171
|
-
audioId: "guide-1-ja",
|
|
172
|
-
language: "ja",
|
|
173
|
-
contentVersion: "v2",
|
|
174
|
-
});
|
|
175
|
-
const viewings = new LocalStorageKeepViewingRecordStorage({ key: "my-app:user-1:viewings" });
|
|
176
|
-
const record = { id: "viewing-1", itemId: "guide-1", viewedAt: Date.now(), note: "Finished" };
|
|
177
|
-
await viewings.set(record); // Reuse this stable ID when retrying the write.
|
|
178
|
-
```
|
|
212
|
+
JSON metadata, backups, and localStorage sync queues reject Date, Map/Set, non-finite numbers, undefined, functions, symbols, BigInt, and circular references through `KeepStorageSerializationError`. Known optional fields may omit undefined. Healthy IndexedDB saves do not require JSON compatibility, but reserve snapshots and JSON exports may consequently fail.
|
|
179
213
|
|
|
180
|
-
|
|
214
|
+
Wrapping an already scoped adapter with a different scope does not switch its write destination. Such mutations reject before persistence. Create an adapter for the destination scope when switching accounts.
|
|
181
215
|
|
|
182
|
-
|
|
216
|
+
Refresh all tabs running the older implementation when adopting this journal. Missing deletion intent and already lost content cannot be reconstructed automatically. Complete outage views during snapshot-write failures and safe writes without an exclusive-access mechanism cannot be guaranteed.
|
|
183
217
|
|
|
184
|
-
|
|
218
|
+
The existing IndexedDB collection database is named `databaseName:storeName:collections`. For example, `("a:b", "c")` and `("a", "b:c")` share that database, so do not combine them within the same scope. Journal migration cannot automatically separate ambiguous data in this existing format.
|
|
185
219
|
|
|
186
|
-
|
|
220
|
+
**Replace imports overwrite the target data, even with an empty backup, and do not roll back.** Inspect `KeepBackupImportError.failedStage` and `applied` after partial failure. Scoped adapters reject data from another scope before mutation.
|
|
187
221
|
|
|
188
|
-
|
|
222
|
+
Custom `StorageAdapter` implementations need `getCollections` / `setCollection` / `removeCollection` and `getCollectionMemberships` / `setCollectionMembership` / `removeCollectionMembership` to support definitions and memberships. Provider collection creation, renaming, and removal reject before changing item assignments when definition methods are incomplete.
|
|
189
223
|
|
|
190
|
-
|
|
224
|
+
Browser writes to localStorage history, viewing records, and progress require the Web Locks API. Unsupported locks or unavailable storage produce errors. Construction is SSR-safe; persistent operations run in the browser.
|
|
225
|
+
Namespace history and progress keys per account, and pass matching language, content version, and audio ID when reading progress.
|
|
191
226
|
|
|
192
|
-
|
|
227
|
+
See the [repository README](../../README.md) for demos and development, and the [release notes](../../RELEASE_NOTES.md) for changes.
|