react-native-cloud-sync 0.3.0 → 0.4.0

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 CHANGED
@@ -13,7 +13,7 @@
13
13
  <h1 align="center">react-native-cloud-sync</h1>
14
14
 
15
15
  <p align="center">
16
- iCloud key-value store, CloudKit and Google Drive behind one API - iOS, Android, web, both architectures.
16
+ iCloud key-value store, CloudKit, iCloud Drive and Google Drive behind one API - iOS, Android, web, both architectures.
17
17
  </p>
18
18
 
19
19
  <p align="center">
@@ -23,35 +23,73 @@
23
23
  <a href="https://kesha-antonov.github.io/react-native-cloud-sync/platform-notes">Platform Notes</a>
24
24
  </p>
25
25
 
26
- ---
26
+ <p align="center">
27
+ <sub>Using it in production? A ⭐ helps other developers find the library.</sub>
28
+ </p>
29
+
30
+ <hr />
31
+
32
+ <table align="center">
33
+ <tr>
34
+ <td align="center" valign="top" width="190">
35
+ <a href="https://cryptoc-app.web.app/"><img src="https://cryptoc-app.web.app/img/icon.png?v=3" width="76" height="76" alt="cryptoc app icon" /></a>
36
+ <br /><br />
37
+ <img src="https://cryptoc-app.web.app/img/qr-get.png?v=2" width="124" height="124" alt="QR code that installs cryptoc" />
38
+ <br />
39
+ <sub>Scan to install</sub>
40
+ <br /><br />
41
+ <a href="https://apps.apple.com/app/cryptoc/id1333169178"><img height="40" src="https://cryptoc-app.web.app/img/appstore.svg?v=2" alt="Download on the App Store" /></a>
42
+ <br />
43
+ <a href="https://play.google.com/store/apps/details?id=co.ssoul.CryptoC"><img height="59" src="https://cryptoc-app.web.app/img/googleplay.png?v=2" alt="Get it on Google Play" /></a>
44
+ </td>
45
+ <td valign="top">
46
+
47
+ ### Support my work
48
+
49
+ **[cryptoc](https://cryptoc-app.web.app/)** - my crypto portfolio app. Your coins on the home screen, lock screen and watch face. iPhone, iPad, Mac, Apple Watch, Android, Android tablet and Wear OS.
50
+
51
+ - Portfolio with average buy price and 24h / 180-day / all-time P&L
52
+ - Widgets in three sizes, refreshed in the background - most days you never open the app
53
+ - Price alerts on 5,000+ coins, delivered while the app is closed
54
+ - **No account, no email, no exchange API keys, no ads.** Your holdings never reach a server - they sync through your own iCloud or Google Drive
55
+ - Free for 3 holdings, and that is not a trial timer
56
+
57
+ <sub>This is the app the library was built for. Downloading it pays for the time that goes into maintaining it.</sub>
58
+
59
+ </td>
60
+ </tr>
61
+ </table>
62
+
63
+ <hr />
27
64
 
28
65
  ## ✨ Features
29
66
 
30
- - ☁️ Four providers behind one API - [`NSUbiquitousKeyValueStore`][kvs] (Apple's small key-value iCloud store), [CloudKit][ck] records, [iCloud Drive][icdrive] documents, Google Drive [`appDataFolder`][appdata] - directly or through one facade.
31
- - 🍏 CloudKit reaches Android and web too, via [CloudKit Web Services][ckws] - the same [private database][ckdb] your iOS app uses.
32
- - 📂 `icloudDocuments` writes into the user's real iCloud Drive, visible in Files.app - unlike an invisible `CKAsset`.
67
+ - ☁️ Four providers behind one API: [`NSUbiquitousKeyValueStore`][kvs] (Apple's small key-value iCloud store), [CloudKit][ck] records, [iCloud Drive][icdrive] documents and Google Drive [`appDataFolder`][appdata]. Use them directly or through one facade.
68
+ - 🔄 Auto-sync between iOS and Android in **both directions**: `mirror` writes to iCloud and Drive together, `resolve` reads back whichever copy is newest, so either platform can be where the user started.
69
+ - 🍏 CloudKit reaches Android and web too, via [CloudKit Web Services][ckws], against the same [private database][ckdb] your iOS app uses.
70
+ - 📂 `icloudDocuments` writes into the user's own iCloud Drive, so the files show up in Files.app.
33
71
  - 🚨 Every failure is a typed rejection (`ERR_NOT_SIGNED_IN`, `ERR_QUOTA_EXCEEDED`, `ERR_RATE_LIMITED` with `retryAfterMs`, ...); `null` means only "key doesn't exist".
34
72
  - 👤 All five [`CKAccountStatus`][ckstatus] values surface as-is, plus `onAccountChange` with `identityChanged`, which drops the previous account's caches and queued writes.
35
73
  - 🔔 `onRemoteChange` fires on every provider and the facade, including Google Drive via its change cursor.
36
- - 📦 Small values go to the key-value store, larger ones to a [`CKRecord`][ckrecord] field, binary as a [`CKAsset`][ckasset] or a resumable Drive upload - sized automatically.
74
+ - 📦 Small values go to the key-value store, larger ones to a [`CKRecord`][ckrecord] field, binary to a [`CKAsset`][ckasset] or a resumable Drive upload. The size check picks the target.
37
75
  - 🔁 Retryable failures queue into a durable outbox: backoff honours retry hints, auto-drains on foreground, bounded, never overwrites a newer write.
38
76
  - 🧺 `multiGet`/`multiSet`/`multiRemove`/`clear` batch for real, one request per provider.
39
- - 🪝 React hooks - `useCloudItem`, `useAccountStatus`, `usePendingWrites` from `/hooks` - without the stale-response and unmounted-`setState` bugs.
40
- - 🔐 `cloudKitEncrypted` uses CloudKit's own `encryptedValues` - ciphertext only, no key exposed; elsewhere, a `codec` seam for your own cipher.
41
- - 🧪 An in-memory provider with fault injection, plus the native mock, both exported (`/testing`, `/jest-mock`) - every failure path testable in Jest.
42
- - ⚙️ React Native 0.71 through 0.86+, old and new architecture, with the `#ifdef` bridge to prove it.
77
+ - 🪝 React hooks from `/hooks`: `useCloudItem`, `useCloudItems`, `useCloudCollection`, `useAccountStatus`, `usePendingWrites`. They drop stale responses and never `setState` after unmount.
78
+ - 🔐 `cloudKitEncrypted` uses CloudKit's own `encryptedValues`, so only ciphertext leaves the device; every other provider has a `codec` seam for your own cipher.
79
+ - 🧪 An in-memory provider with fault injection, plus the native mock, both exported (`/testing`, `/jest-mock`), so every failure path is testable in Jest.
80
+ - ⚙️ React Native 0.71 through 0.86+, old and new architecture, with the `#ifdef` bridge for the legacy one.
43
81
 
44
82
  ## 💡 Why?
45
83
 
46
84
  Cloud storage in React Native is fragmented into single-provider wrappers repeating the same defects: two ship a `setItem` that **reports a failed write as a success** (one checks the wrong error variable, the other discards the result entirely), and a third flattens five iCloud account states into one boolean.
47
85
 
48
- A `catch { return null }` makes "not signed in", "offline", "out of storage" and "no such key" indistinguishable - apps can't tell the user anything useful, or decide whether to retry.
86
+ A `catch { return null }` makes "not signed in", "offline", "out of storage" and "no such key" indistinguishable. The app can't tell the user anything useful, or decide whether to retry.
49
87
 
50
- This library starts from the opposite end: the error contract first, providers second.
88
+ This library was built error contract first, providers second.
51
89
 
52
90
  ## 📚 Upstream documentation
53
91
 
54
- This package is a wrapper: unexpected behavior is usually explained in Apple's or Google's docs, not ours.
92
+ This package is a wrapper. When something behaves unexpectedly, the answer is usually in Apple's or Google's docs.
55
93
 
56
94
  **Apple**
57
95
 
@@ -72,7 +110,7 @@ This package is a wrapper: unexpected behavior is usually explained in Apple's o
72
110
  |---|---|
73
111
  | [The `appDataFolder`][appdata] | The hidden per-app folder this package stores into |
74
112
  | [Drive `files` resource][drivefiles] | The REST endpoints behind the provider |
75
- | [Drive API scopes][drivescopes] | Why `drive.appdata`, not something broader |
113
+ | [Drive API scopes][drivescopes] | Why the scope is `drive.appdata` |
76
114
 
77
115
  [kvs]: https://developer.apple.com/documentation/foundation/nsubiquitouskeyvaluestore
78
116
  [ck]: https://developer.apple.com/documentation/cloudkit
@@ -96,40 +134,40 @@ This package is a wrapper: unexpected behavior is usually explained in Apple's o
96
134
 
97
135
  | | **this** | [kuatsu/<br />cloud-storage][kuatsu] | [icloud-kit][ik] | [expo-cloudkit][ec] | [okwasniewski/<br />icloud-storage][ok] | [cloudkit-<br />storage][jp] |
98
136
  |---|:---:|:---:|:---:|:---:|:---:|:---:|
99
- | iCloud key-value store | ✅ | ✅ | ✅ | – | ✅ | – |
100
- | CloudKit records | ✅ | – | ✅ | ✅ | – | ✅ |
101
- | Google Drive | ✅ | ✅ | – | – | – | – |
137
+ | iCloud key-value store | ✅ | ✅ | ✅ | - | ✅ | - |
138
+ | CloudKit records | ✅ | - | ✅ | ✅ | - | ✅ |
139
+ | Google Drive | ✅ | ✅ | - | - | - | - |
102
140
  | iOS | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
103
- | Android | ✅ | ✅ | – | ❌ [[1]](#note-1) | – | – |
104
- | Web | ✅ | partial [[2]](#note-2) | – | – | – | – |
105
- | **CloudKit on Android/web** | ✅ | – | – | ❌ [[1]](#note-1) | – | – |
106
- | New Architecture | ✅ | ✅ | ✅ | ✅ | ✅ | – |
141
+ | Android | ✅ | ✅ | - | ❌ [[1]](#note-1) | - | - |
142
+ | Web | ✅ | partial [[2]](#note-2) | - | - | - | - |
143
+ | **CloudKit on Android/web** | ✅ | - | - | ❌ [[1]](#note-1) | - | - |
144
+ | New Architecture | ✅ | ✅ | ✅ | ✅ | ✅ | - |
107
145
  | **Legacy Architecture** | ✅ | ❌ | ✅ [[3]](#note-3) | ✅ [[3]](#note-3) | ✅ [[3]](#note-3) | ✅ |
108
- | Typed error codes | ✅ | – | partial | ✅ | – | – |
109
- | 5-value account status | ✅ | boolean | boolean | ✅ | – | – |
110
- | Identity-change event | ✅ | ⚠️ [[4]](#note-4) | – | ✅ | – | – |
111
- | Remote-change event | ✅ | ✅ | – | n/a | ❌ [[5]](#note-5) | ✅ |
112
- | Offline write queue | ✅ | – | – | ✅ | – | – |
113
- | Size tiering | ✅ | – | – | – | – | – |
114
- | Binary / assets | ✅ [[9]](#note-9) | ✅ | ❌ [[6]](#note-6) | ✅ | – | – |
115
- | User-visible iCloud Drive files | ✅ | – | – | – | ✅ | – |
116
- | Native end-to-end encryption | ✅ | – | – | – | – | – |
117
- | Batch operations | ✅ | – | – | – | – | – |
118
- | React hooks | ✅ | ✅ | – | – | – | – |
119
- | Encryption seam | ✅ | – | – | – | – | – |
120
- | Exported test harness | ✅ | – | – | ⚠️ [[7]](#note-7) | – | – |
121
- | Mac Catalyst | ✅ | – | – | ⚠️ | – | – |
146
+ | Typed error codes | ✅ | - | partial | ✅ | - | - |
147
+ | 5-value account status | ✅ | boolean | boolean | ✅ | - | - |
148
+ | Identity-change event | ✅ | ⚠️ [[4]](#note-4) | - | ✅ | - | - |
149
+ | Remote-change event | ✅ | ✅ | - | n/a | ❌ [[5]](#note-5) | ✅ |
150
+ | Offline write queue | ✅ | - | - | ✅ | - | - |
151
+ | Size tiering | ✅ | - | - | - | - | - |
152
+ | Binary / assets | ✅ [[9]](#note-9) | ✅ | ❌ [[6]](#note-6) | ✅ | - | - |
153
+ | User-visible iCloud Drive files | ✅ | - | - | - | ✅ | - |
154
+ | Native end-to-end encryption | ✅ | - | - | - | - | - |
155
+ | Batch operations | ✅ | - | - | - | - | - |
156
+ | React hooks | ✅ | ✅ | - | - | - | - |
157
+ | Encryption seam | ✅ | - | - | - | - | - |
158
+ | Exported test harness | ✅ | - | - | ⚠️ [[7]](#note-7) | - | - |
159
+ | Mac Catalyst | ✅ | - | - | ⚠️ | - | - |
122
160
  | Actively maintained | ✅ | ✅ | ✅ | ❌ [[8]](#note-8) | ❌ [[5]](#note-5) | ❌ |
123
161
 
124
162
  <a id="note-1"></a>**[1]** expo-cloudkit's README: Android throws `CloudKitNotSupportedError` on every call.
125
163
  <a id="note-2"></a>**[2]** Google Drive support is text-based only.
126
- <a id="note-3"></a>**[3]** Via the Expo Modules API - pulls in `expo-modules-core`.
127
- <a id="note-4"></a>**[4]** Fires before JS binds the emitter, crashing with `std::bad_function_call` (SIGABRT) - hit three times.
164
+ <a id="note-3"></a>**[3]** Via the Expo Modules API; pulls in `expo-modules-core`.
165
+ <a id="note-4"></a>**[4]** Fires before JS binds the emitter, crashing with `std::bad_function_call` (SIGABRT); hit three times.
128
166
  <a id="note-5"></a>**[5]** One version ever shipped; the change-listener PR has sat open since February.
129
- <a id="note-6"></a>**[6]** Field type is `string | number | null` - can't hold binary data.
167
+ <a id="note-6"></a>**[6]** Field type is `string | number | null`, so it can't hold binary data.
130
168
  <a id="note-7"></a>**[7]** A mock factory exists, but isn't exported or documented.
131
169
  <a id="note-8"></a>**[8]** No commits since April; the last four releases shipped with Swift that didn't compile.
132
- <a id="note-9"></a>**[9]** `CKAsset` on Apple platforms; CloudKit Web Services' upload-token protocol on Android/web, capped at 15 MB (CloudKit's limit, not this package's). Use [`googleDriveFiles`](https://kesha-antonov.github.io/react-native-cloud-sync/providers/google-drive#large-files) for anything bigger - it chunks and resumes the same way.
170
+ <a id="note-9"></a>**[9]** `CKAsset` on Apple platforms; CloudKit Web Services' upload-token protocol on Android/web, capped at 15 MB by CloudKit. Use [`googleDriveFiles`](https://kesha-antonov.github.io/react-native-cloud-sync/providers/google-drive#large-files) for anything bigger; it chunks and resumes the same way.
133
171
 
134
172
  [kuatsu]: https://github.com/kuatsu/react-native-cloud-storage
135
173
  [ik]: https://github.com/BogdanGeorgian91/react-native-icloud-kit
@@ -143,7 +181,7 @@ This package is a wrapper: unexpected behavior is usually explained in Apple's o
143
181
  |---|---|
144
182
  | [Choosing a provider](https://kesha-antonov.github.io/react-native-cloud-sync/choosing-a-provider) | Which one, what it costs, why to let the user pick |
145
183
  | [iCloud key-value store](https://kesha-antonov.github.io/react-native-cloud-sync/providers/icloud-kv) | Small settings, zero friction, Apple only |
146
- | [CloudKit](https://kesha-antonov.github.io/react-native-cloud-sync/providers/cloudkit) | Records, zones, assets - and the Android/web path |
184
+ | [CloudKit](https://kesha-antonov.github.io/react-native-cloud-sync/providers/cloudkit) | Records, zones, assets, and the Android/web path |
147
185
  | [iCloud Drive](https://kesha-antonov.github.io/react-native-cloud-sync/providers/icloud-drive) | Files in the user's own Drive, visible in Files.app |
148
186
  | [Google Drive](https://kesha-antonov.github.io/react-native-cloud-sync/providers/google-drive) | The always-on cross-platform backend |
149
187
  | [The store facade](https://kesha-antonov.github.io/react-native-cloud-sync/store) | Tiering, outbox, migration, fallthrough |
@@ -170,13 +208,13 @@ Both architectures supported; RN 0.82 removed Legacy Architecture, so that half
170
208
 
171
209
  | | iOS / macOS | Android | Web |
172
210
  |---|:---:|:---:|:---:|
173
- | `icloudKV` | native | – | – |
211
+ | `icloudKV` | native | - | - |
174
212
  | `cloudKit` | native | REST | REST |
175
- | `cloudKitEncrypted` | native | – | – |
176
- | `icloudDocuments` | native | – | – |
213
+ | `cloudKitEncrypted` | native | - | - |
214
+ | `icloudDocuments` | native | - | - |
177
215
  | `googleDrive` | REST | REST | REST |
178
216
 
179
- An unavailable provider rejects with `ERR_UNSUPPORTED_PLATFORM` rather than silently no-op'ing - [Choosing a provider](https://kesha-antonov.github.io/react-native-cloud-sync/choosing-a-provider) covers the trade-offs.
217
+ An unavailable provider rejects with `ERR_UNSUPPORTED_PLATFORM` instead of silently doing nothing. [Choosing a provider](https://kesha-antonov.github.io/react-native-cloud-sync/choosing-a-provider) covers the trade-offs.
180
218
 
181
219
  ## 📦 Installation
182
220
 
@@ -204,7 +242,7 @@ Bare React Native and manual `ios/` entitlement keys: see [Installation](https:/
204
242
 
205
243
  ### iCloud key-value store
206
244
 
207
- No sign-in, no UI - uses the device's existing account.
245
+ No sign-in and no UI; it uses the device's existing account.
208
246
 
209
247
  ```ts
210
248
  import { icloudKV } from 'react-native-cloud-sync'
@@ -216,7 +254,7 @@ const theme = await icloudKV.getItem('settings/theme')
216
254
  icloudKV.onRemoteChange(({ keys }) => reload(keys))
217
255
  ```
218
256
 
219
- [Full guide →](https://kesha-antonov.github.io/react-native-cloud-sync/providers/icloud-kv)
257
+ [Full guide](https://kesha-antonov.github.io/react-native-cloud-sync/providers/icloud-kv)
220
258
 
221
259
  ### CloudKit
222
260
 
@@ -232,11 +270,11 @@ const raw = await cloudKit.getItem('playlist')
232
270
  await cloudKitAssets.save({ recordName: 'avatar', fieldName: 'image', fileUri })
233
271
  ```
234
272
 
235
- Android/web needs an Apple ID sign-in whose token lasts up to two weeks - an explicit import, not background sync. [Full guide →](https://kesha-antonov.github.io/react-native-cloud-sync/providers/cloudkit)
273
+ Android/web needs an Apple ID sign-in, and that token lasts up to two weeks, which suits an explicit import rather than background sync. [Full guide](https://kesha-antonov.github.io/react-native-cloud-sync/providers/cloudkit)
236
274
 
237
275
  ### Sensitive data
238
276
 
239
- CloudKit's own end-to-end encryption - Apple stores ciphertext and holds no key.
277
+ CloudKit's own end-to-end encryption: Apple stores ciphertext and holds no key.
240
278
 
241
279
  ```ts
242
280
  import { cloudKitEncrypted } from 'react-native-cloud-sync'
@@ -244,11 +282,11 @@ import { cloudKitEncrypted } from 'react-native-cloud-sync'
244
282
  await cloudKitEncrypted.setItem('auth.refreshToken', token)
245
283
  ```
246
284
 
247
- Apple-only: the key lives in the user's iCloud Keychain, so nothing server-side can decrypt it. Cross-platform needs the store's `codec` seam instead. [Full guide →](https://kesha-antonov.github.io/react-native-cloud-sync/encryption)
285
+ Apple-only: the key lives in the user's iCloud Keychain, so nothing server-side can decrypt it. Cross-platform needs the store's `codec` seam instead. [Full guide](https://kesha-antonov.github.io/react-native-cloud-sync/encryption)
248
286
 
249
287
  ### iCloud Drive
250
288
 
251
- Files the user can open in Files.app - not hidden in a private database.
289
+ Files the user can open in Files.app.
252
290
 
253
291
  ```ts
254
292
  import { icloudDocuments } from 'react-native-cloud-sync'
@@ -259,7 +297,7 @@ await icloudDocuments.save({ fileUri: localPath, name: 'Export 2024.csv' })
259
297
  const path = await icloudDocuments.fetch({ name: 'Export 2024.csv' })
260
298
  ```
261
299
 
262
- [Full guide →](https://kesha-antonov.github.io/react-native-cloud-sync/providers/icloud-drive)
300
+ [Full guide](https://kesha-antonov.github.io/react-native-cloud-sync/providers/icloud-drive)
263
301
 
264
302
  ### Google Drive
265
303
 
@@ -275,7 +313,7 @@ configureGoogleDrive({
275
313
  await googleDrive.setItem('playlist.json', JSON.stringify(tracks))
276
314
  ```
277
315
 
278
- [Full guide →](https://kesha-antonov.github.io/react-native-cloud-sync/providers/google-drive)
316
+ [Full guide](https://kesha-antonov.github.io/react-native-cloud-sync/providers/google-drive)
279
317
 
280
318
  ### All of them at once
281
319
 
@@ -284,8 +322,8 @@ import { createCloudStore } from 'react-native-cloud-sync'
284
322
 
285
323
  const store = createCloudStore({
286
324
  providers: ['icloudKV', 'googleDrive'], // preference order
287
- writeMode: 'mirror', // write to BOTH, not just the first
288
- resolve: resolveByTimestamp('updatedAt'), // read the newest, not the first
325
+ writeMode: 'mirror', // write to both providers, not only the preferred one
326
+ resolve: resolveByTimestamp('updatedAt'), // read whichever copy is newest
289
327
  tiering: 'auto', // route by size
290
328
  outboxStorage: mmkvAdapter, // survive restarts
291
329
  })
@@ -294,7 +332,7 @@ await store.setItem('playlist', json)
294
332
  await store.flushOutbox() // on reconnect
295
333
  ```
296
334
 
297
- Those two options make sync work in **both** directions across a mixed fleet: `mirror` copies to Drive so non-Apple devices can read it; `resolve` stops an Apple device serving a stale iCloud copy without checking Drive. Either platform can be where the user started. [Full guide →](https://kesha-antonov.github.io/react-native-cloud-sync/store)
335
+ Those two options make sync work in **both** directions across a mixed fleet: `mirror` copies to Drive so non-Apple devices can read it; `resolve` stops an Apple device serving a stale iCloud copy without checking Drive. [Full guide](https://kesha-antonov.github.io/react-native-cloud-sync/store)
298
336
 
299
337
  ### In a component
300
338
 
@@ -304,7 +342,7 @@ import { useCloudItem } from 'react-native-cloud-sync/hooks'
304
342
  const { value, setValue, loading, error } = useCloudItem<Settings>(store, 'settings')
305
343
  ```
306
344
 
307
- Re-reads on remote writes, drops stale responses, never calls `setState` after unmount. [Full guide →](https://kesha-antonov.github.io/react-native-cloud-sync/hooks)
345
+ Re-reads on remote writes, drops stale responses, never calls `setState` after unmount. [Full guide](https://kesha-antonov.github.io/react-native-cloud-sync/hooks)
308
346
 
309
347
  ### Handling failures
310
348
 
@@ -319,7 +357,7 @@ try {
319
357
  }
320
358
  ```
321
359
 
322
- [Full guide →](https://kesha-antonov.github.io/react-native-cloud-sync/errors)
360
+ [Full guide](https://kesha-antonov.github.io/react-native-cloud-sync/errors)
323
361
 
324
362
  ## 🧪 Testing
325
363
 
@@ -334,7 +372,7 @@ const provider = createMemoryProvider({
334
372
  provider.emitAccountChange({ status: 'available', identityChanged: true })
335
373
  ```
336
374
 
337
- Signed-out, offline and account-switch paths, all in Jest without a device. [Full guide →](https://kesha-antonov.github.io/react-native-cloud-sync/testing)
375
+ Signed-out, offline and account-switch paths, all in Jest without a device. [Full guide](https://kesha-antonov.github.io/react-native-cloud-sync/testing)
338
376
 
339
377
  ## 🧪 Example App
340
378
 
@@ -360,6 +398,8 @@ Issues and pull requests welcome. Run `yarn lint`, `yarn typecheck` and `yarn te
360
398
 
361
399
  - [Kesha Antonov](https://github.com/kesha-antonov)
362
400
 
401
+ I also build **[cryptoc](https://cryptoc-app.web.app/)** - a crypto portfolio app with home screen, lock screen and Watch widgets, no account and no exchange API keys. It is where this library came from.
402
+
363
403
  ## 📄 License
364
404
 
365
405
  MIT
@@ -4,7 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.useAccountStatus = useAccountStatus;
7
+ exports.useCloudCollection = useCloudCollection;
7
8
  exports.useCloudItem = useCloudItem;
9
+ exports.useCloudItems = useCloudItems;
8
10
  exports.usePendingWrites = usePendingWrites;
9
11
  exports.useQuota = useQuota;
10
12
  exports.useRemoteChange = useRemoteChange;
@@ -127,6 +129,246 @@ function useCloudItem(store, key, options = {}) {
127
129
  refresh: read
128
130
  };
129
131
  }
132
+ /**
133
+ * Binds a list of keys to component state with one batched `multiGet`.
134
+ *
135
+ * The multi-key sibling of `useCloudItem` - a screen with many cloud-backed
136
+ * records (a list, one key per item) otherwise ends up calling `useCloudItem`
137
+ * once per row: one `getItem` and one `onRemoteChange` subscription each,
138
+ * instead of a single batched read.
139
+ *
140
+ * Only ever fetches keys it does not already hold an answer for. Mount,
141
+ * `refresh()`, and a matching remote-change event all fetch normally, but a
142
+ * key merely joining the tracked list - because a caller like
143
+ * `useCloudCollection` just added it after a local write - is never
144
+ * re-fetched on that account alone, so a slow fetch elsewhere in the list
145
+ * can't land a stale value on top of a write that already resolved locally.
146
+ *
147
+ * ```tsx
148
+ * const { values, setValue } = useCloudItems<Note>(store, noteIds)
149
+ * ```
150
+ */
151
+ function useCloudItems(store, keys, options = {}) {
152
+ const {
153
+ parse = JSON.parse,
154
+ serialize = JSON.stringify,
155
+ watch = true
156
+ } = options;
157
+ const [values, setValuesState] = (0, _react.useState)({});
158
+ const [loading, setLoading] = (0, _react.useState)(true);
159
+ const [error, setError] = (0, _react.useState)(null);
160
+ const mounted = (0, _react.useRef)(true);
161
+ (0, _react.useEffect)(() => {
162
+ mounted.current = true;
163
+ return () => {
164
+ mounted.current = false;
165
+ };
166
+ }, []);
167
+ const parseRef = (0, _react.useRef)(parse);
168
+ parseRef.current = parse;
169
+ const keysRef = (0, _react.useRef)(keys);
170
+ keysRef.current = keys;
171
+ const keysSignature = JSON.stringify(keys);
172
+
173
+ // Latest values alongside the state, so effects can read "do we already
174
+ // have this key" without taking `values` itself as a dependency.
175
+ const valuesRef = (0, _react.useRef)(values);
176
+ const setValues = (0, _react.useCallback)(updater => {
177
+ setValuesState(prev => {
178
+ const next = updater(prev);
179
+ valuesRef.current = next;
180
+ return next;
181
+ });
182
+ }, []);
183
+
184
+ // Per-key ticket, not one shared counter: two fetches for disjoint keys
185
+ // run concurrently (an initial load still in flight plus a remote event for
186
+ // a key that just appeared), and a shared ticket would let the second
187
+ // invalidate the first's unrelated result.
188
+ const keyTicket = (0, _react.useRef)(new Map());
189
+ const bump = key => {
190
+ const next = (keyTicket.current.get(key) ?? 0) + 1;
191
+ keyTicket.current.set(key, next);
192
+ return next;
193
+ };
194
+ const fetchKeys = (0, _react.useCallback)(async toFetch => {
195
+ if (toFetch.length === 0) return;
196
+ const mine = new Map(toFetch.map(k => [k, bump(k)]));
197
+ try {
198
+ const pairs = await store.multiGet(toFetch);
199
+ if (!mounted.current) return;
200
+ setValues(prev => {
201
+ const next = {
202
+ ...prev
203
+ };
204
+ for (const [k, raw] of pairs) {
205
+ // A write or a newer fetch already claimed this key - this answer
206
+ // is no longer the current one.
207
+ if (keyTicket.current.get(k) !== mine.get(k)) continue;
208
+ next[k] = raw == null ? null : parseRef.current(raw);
209
+ }
210
+ return next;
211
+ });
212
+ setError(null);
213
+ } catch (e) {
214
+ if (!mounted.current) return;
215
+ // Only surface the failure if at least one of these keys is still
216
+ // uncontested - a fetch overtaken by a write or another fetch failing
217
+ // is not new information.
218
+ const stillCurrent = toFetch.some(k => keyTicket.current.get(k) === mine.get(k));
219
+ if (stillCurrent) setError((0, _errors.normalizeError)(e));
220
+ }
221
+ }, [store, setValues]);
222
+
223
+ // Fetches keys new to the tracked list and drops values for keys no longer
224
+ // in it. Doubles as the initial load: on mount every key is "missing".
225
+ const hasLoadedOnce = (0, _react.useRef)(false);
226
+ (0, _react.useEffect)(() => {
227
+ const current = keysRef.current;
228
+ const missing = current.filter(k => !(k in valuesRef.current));
229
+ const keep = new Set(current);
230
+ setValues(prev => {
231
+ let changed = false;
232
+ const next = {};
233
+ for (const k of Object.keys(prev)) if (keep.has(k)) next[k] = prev[k];else changed = true;
234
+ return changed ? next : prev;
235
+ });
236
+ if (!hasLoadedOnce.current) {
237
+ hasLoadedOnce.current = true;
238
+ setLoading(true);
239
+ void fetchKeys(missing).finally(() => {
240
+ if (mounted.current) setLoading(false);
241
+ });
242
+ } else if (missing.length > 0) {
243
+ void fetchKeys(missing);
244
+ }
245
+ }, [keysSignature, fetchKeys, setValues]);
246
+ (0, _react.useEffect)(() => {
247
+ if (!watch) return;
248
+ return store.onRemoteChange(e => {
249
+ if (e.keys.length === 0) {
250
+ void fetchKeys(keysRef.current);
251
+ return;
252
+ }
253
+ const intersecting = e.keys.filter(k => keysRef.current.includes(k));
254
+ if (intersecting.length > 0) void fetchKeys(intersecting);
255
+ });
256
+ }, [store, watch, fetchKeys]);
257
+ const setValue = (0, _react.useCallback)(async (key, next) => {
258
+ bump(key);
259
+ setValues(prev => ({
260
+ ...prev,
261
+ [key]: next
262
+ }));
263
+ try {
264
+ await store.setItem(key, serialize(next));
265
+ if (mounted.current) setError(null);
266
+ } catch (e) {
267
+ if (mounted.current) setError((0, _errors.normalizeError)(e));
268
+ throw e;
269
+ }
270
+ }, [store, serialize, setValues]);
271
+ const remove = (0, _react.useCallback)(async key => {
272
+ bump(key);
273
+ setValues(prev => ({
274
+ ...prev,
275
+ [key]: null
276
+ }));
277
+ try {
278
+ await store.removeItem(key);
279
+ if (mounted.current) setError(null);
280
+ } catch (e) {
281
+ if (mounted.current) setError((0, _errors.normalizeError)(e));
282
+ throw e;
283
+ }
284
+ }, [store, setValues]);
285
+ const refresh = (0, _react.useCallback)(async () => {
286
+ setLoading(true);
287
+ try {
288
+ await fetchKeys(keysRef.current);
289
+ } finally {
290
+ if (mounted.current) setLoading(false);
291
+ }
292
+ }, [fetchKeys]);
293
+ return {
294
+ values,
295
+ loading,
296
+ error,
297
+ setValue,
298
+ remove,
299
+ refresh
300
+ };
301
+ }
302
+ /**
303
+ * Live-binds every key starting with `prefix` to component state.
304
+ *
305
+ * Adds the membership index `useCloudItems` needs but does not derive
306
+ * itself: `getAllKeys()` filtered by prefix on mount and after any remote
307
+ * change that could plausibly have added or removed a member, then
308
+ * `useCloudItems` for the values.
309
+ *
310
+ * A `setValue` for a key not seen before joins the collection immediately -
311
+ * a newly created record should appear in its own list without waiting on a
312
+ * round trip to confirm it.
313
+ *
314
+ * ```tsx
315
+ * const { keys, values, setValue, remove } = useCloudCollection<Note>(store, 'note:')
316
+ * ```
317
+ */
318
+ function useCloudCollection(store, prefix, options = {}) {
319
+ const {
320
+ watch = true
321
+ } = options;
322
+ const [keys, setKeys] = (0, _react.useState)([]);
323
+ const mounted = (0, _react.useRef)(true);
324
+ (0, _react.useEffect)(() => {
325
+ mounted.current = true;
326
+ return () => {
327
+ mounted.current = false;
328
+ };
329
+ }, []);
330
+ const listKeys = (0, _react.useCallback)(async () => {
331
+ const all = await store.getAllKeys();
332
+ if (!mounted.current) return;
333
+ setKeys(all.filter(k => k.startsWith(prefix)));
334
+ }, [store, prefix]);
335
+ (0, _react.useEffect)(() => {
336
+ void listKeys();
337
+ }, [listKeys]);
338
+ (0, _react.useEffect)(() => {
339
+ if (!watch) return;
340
+ return store.onRemoteChange(e => {
341
+ // A prefix collection can gain or lose members on another device, not
342
+ // just change the value of one already in it - re-list on an opaque
343
+ // event too, not only one that names a key under this prefix.
344
+ if (e.keys.length > 0 && !e.keys.some(k => k.startsWith(prefix))) return;
345
+ void listKeys();
346
+ });
347
+ }, [store, prefix, watch, listKeys]);
348
+ const items = useCloudItems(store, keys, options);
349
+ const setValue = (0, _react.useCallback)(async (key, next) => {
350
+ if (key.startsWith(prefix)) setKeys(prev => prev.includes(key) ? prev : [...prev, key]);
351
+ await items.setValue(key, next);
352
+ }, [items, prefix]);
353
+ const remove = (0, _react.useCallback)(async key => {
354
+ await items.remove(key);
355
+ setKeys(prev => prev.includes(key) ? prev.filter(k => k !== key) : prev);
356
+ }, [items]);
357
+ const refresh = (0, _react.useCallback)(async () => {
358
+ // Concurrent, not sequential: a key that only `listKeys` turns up gets
359
+ // its value shortly after anyway, through the same membership-diff
360
+ // effect that handles a live remote event, so there is nothing to gain
361
+ // from waiting for the listing before starting `items.refresh()`.
362
+ await Promise.all([listKeys(), items.refresh()]);
363
+ }, [listKeys, items]);
364
+ return {
365
+ ...items,
366
+ setValue,
367
+ remove,
368
+ refresh,
369
+ keys
370
+ };
371
+ }
130
372
  /**
131
373
  * Tracks a provider's account state, including the identity-switch event.
132
374
  *
@@ -1 +1 @@
1
- {"version":3,"names":["_react","require","_errors","useCloudItem","store","key","options","initialValue","parse","JSON","serialize","stringify","watch","value","setLocalValue","useState","loading","setLoading","error","setError","mounted","useRef","useEffect","current","ticket","parseRef","read","useCallback","mine","raw","getItem","e","normalizeError","onRemoteChange","keys","length","includes","setValue","next","setItem","remove","removeItem","refresh","useAccountStatus","provider","status","setStatus","identityChanged","setIdentityChanged","getAccountStatus","onAccountChange","usePendingWrites","pollIntervalMs","pending","setPending","pendingWrites","sync","timer","setInterval","clearInterval","flush","flushOutbox","discard","filter","discardPendingWrites","useRemoteChange","listener","ref","useQuota","quota","setQuota","getQuota","useMemo"],"sourceRoot":"../../src","sources":["hooks.ts"],"mappings":";;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAGA,IAAAC,OAAA,GAAAD,OAAA;AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAmCA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,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AAG2C,QAAQ;EAEtB,IAAA5C,gBAAS,EAAC,MAAMlB,KAAK,CAAC6B,cAAc,CAACF,CAAC,IAAIoC,GAAG,CAAC5C,OAAO,CAACQ,CAAC,CAAC,CAAC,EAAE,CAAC3B,KAAK,CAAC,CAAC;AACrE;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAASgE,QAAQA,CAAChE,KAAiB,EAIxC;EAEA,MAAM,CAACiE,KAAK,EAAEC,QAAQ,CAAC,GAAG,IAAAvD,eAAQ,EAAQ,EAAE,CAAC;EAC7C,MAAM,CAACC,OAAO,EAAEC,UAAU,CAAC,GAAG,IAAAF,eAAQ,EAAC,KAAK,CAAC;EAE7C,MAAMK,OAAO,GAAG,IAAAC,aAAM,EAAC,IAAI,CAAC;EAC5B,IAAAC,gBAAS,EAAC,MAAM;IACdF,OAAO,CAACG,OAAO,GAAG,IAAI;IACtB,OAAO,MAAM;MACXH,OAAO,CAACG,OAAO,GAAG,KAAK;IACzB,CAAC;EACH,CAAC,EAAE,EAAE,CAAC;EAEN,MAAMmB,OAAO,GAAG,IAAAf,kBAAW,EAAC,YAA2B;IACrDV,UAAU,CAAC,IAAI,CAAC;IAChB,IAAI;MACF,MAAMqB,IAAI,GAAG,MAAMlC,KAAK,CAACmE,QAAQ,CAAC,CAAC;MACnC,IAAInD,OAAO,CAACG,OAAO,EAAE+C,QAAQ,CAAChC,IAAI,CAAC;IACrC,CAAC,SACO;MACN,IAAIlB,OAAO,CAACG,OAAO,EAAEN,UAAU,CAAC,KAAK,CAAC;IACxC;EACF,CAAC,EAAE,CAACb,KAAK,CAAC,CAAC;EAEX,OAAO,IAAAoE,cAAO,EAAC,OAAO;IAAEH,KAAK;IAAErD,OAAO;IAAE0B;EAAQ,CAAC,CAAC,EAAE,CAAC2B,KAAK,EAAErD,OAAO,EAAE0B,OAAO,CAAC,CAAC;AAChF","ignoreList":[]}
1
+ {"version":3,"names":["_react","require","_errors","useCloudItem","store","key","options","initialValue","parse","JSON","serialize","stringify","watch","value","setLocalValue","useState","loading","setLoading","error","setError","mounted","useRef","useEffect","current","ticket","parseRef","read","useCallback","mine","raw","getItem","e","normalizeError","onRemoteChange","keys","length","includes","setValue","next","setItem","remove","removeItem","refresh","useCloudItems","values","setValuesState","keysRef","keysSignature","valuesRef","setValues","updater","prev","keyTicket","Map","bump","get","set","fetchKeys","toFetch","map","k","pairs","multiGet","stillCurrent","some","hasLoadedOnce","missing","filter","keep","Set","changed","Object","has","finally","intersecting","useCloudCollection","prefix","setKeys","listKeys","all","getAllKeys","startsWith","items","Promise","useAccountStatus","provider","status","setStatus","identityChanged","setIdentityChanged","getAccountStatus","onAccountChange","usePendingWrites","pollIntervalMs","pending","setPending","pendingWrites","sync","timer","setInterval","clearInterval","flush","flushOutbox","discard","discardPendingWrites","useRemoteChange","listener","ref","useQuota","quota","setQuota","getQuota","useMemo"],"sourceRoot":"../../src","sources":["hooks.ts"],"mappings":";;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAGA,IAAAC,OAAA,GAAAD,OAAA;AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAmCA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,YAAYA,CAC1BC,KAAiB,EACjBC,GAAW,EACXC,OAA+B,GAAG,CAAC,CAAC,EACb;EACvB,MAAM;IACJC,YAAY,GAAG,IAAI;IACnBC,KAAK,GAAGC,IAAI,CAACD,KAA2B;IACxCE,SAAS,GAAGD,IAAI,CAACE,SAAiC;IAClDC,KAAK,GAAG;EACV,CAAC,GAAGN,OAAO;EAEX,MAAM,CAACO,KAAK,EAAEC,aAAa,CAAC,GAAG,IAAAC,eAAQ,EAAWR,YAAY,CAAC;EAC/D,MAAM,CAACS,OAAO,EAAEC,UAAU,CAAC,GAAG,IAAAF,eAAQ,EAAC,IAAI,CAAC;EAC5C,MAAM,CAACG,KAAK,EAAEC,QAAQ,CAAC,GAAG,IAAAJ,eAAQ,EAAwB,IA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