react-native-cloud-sync 0.1.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.
Files changed (268) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +360 -0
  3. package/app.plugin.js +3 -0
  4. package/ios/CloudSyncError.swift +144 -0
  5. package/ios/CloudSyncImpl.swift +1263 -0
  6. package/ios/RNCloudSync.h +25 -0
  7. package/ios/RNCloudSync.mm +477 -0
  8. package/jest-mock.js +136 -0
  9. package/lib/commonjs/config.js +85 -0
  10. package/lib/commonjs/config.js.map +1 -0
  11. package/lib/commonjs/errors.js +244 -0
  12. package/lib/commonjs/errors.js.map +1 -0
  13. package/lib/commonjs/hooks.js +257 -0
  14. package/lib/commonjs/hooks.js.map +1 -0
  15. package/lib/commonjs/index.js +244 -0
  16. package/lib/commonjs/index.js.map +1 -0
  17. package/lib/commonjs/internal/autoFlush.js +65 -0
  18. package/lib/commonjs/internal/autoFlush.js.map +1 -0
  19. package/lib/commonjs/internal/base64.js +58 -0
  20. package/lib/commonjs/internal/base64.js.map +1 -0
  21. package/lib/commonjs/internal/bytes.js +32 -0
  22. package/lib/commonjs/internal/bytes.js.map +1 -0
  23. package/lib/commonjs/internal/cloudKitRest.js +527 -0
  24. package/lib/commonjs/internal/cloudKitRest.js.map +1 -0
  25. package/lib/commonjs/internal/enums.js +23 -0
  26. package/lib/commonjs/internal/enums.js.map +1 -0
  27. package/lib/commonjs/internal/googleDriveRest.js +624 -0
  28. package/lib/commonjs/internal/googleDriveRest.js.map +1 -0
  29. package/lib/commonjs/internal/keys.js +139 -0
  30. package/lib/commonjs/internal/keys.js.map +1 -0
  31. package/lib/commonjs/internal/logger.js +29 -0
  32. package/lib/commonjs/internal/logger.js.map +1 -0
  33. package/lib/commonjs/internal/nativeModule.js +125 -0
  34. package/lib/commonjs/internal/nativeModule.js.map +1 -0
  35. package/lib/commonjs/internal/timeout.js +72 -0
  36. package/lib/commonjs/internal/timeout.js.map +1 -0
  37. package/lib/commonjs/package.json +1 -0
  38. package/lib/commonjs/providers/cloudKit.js +398 -0
  39. package/lib/commonjs/providers/cloudKit.js.map +1 -0
  40. package/lib/commonjs/providers/cloudKitBackup.js +86 -0
  41. package/lib/commonjs/providers/cloudKitBackup.js.map +1 -0
  42. package/lib/commonjs/providers/cloudKitEncrypted.js +150 -0
  43. package/lib/commonjs/providers/cloudKitEncrypted.js.map +1 -0
  44. package/lib/commonjs/providers/googleDrive.js +219 -0
  45. package/lib/commonjs/providers/googleDrive.js.map +1 -0
  46. package/lib/commonjs/providers/googleDriveFiles.js +68 -0
  47. package/lib/commonjs/providers/googleDriveFiles.js.map +1 -0
  48. package/lib/commonjs/providers/icloudDocuments.js +121 -0
  49. package/lib/commonjs/providers/icloudDocuments.js.map +1 -0
  50. package/lib/commonjs/providers/icloudKV.js +171 -0
  51. package/lib/commonjs/providers/icloudKV.js.map +1 -0
  52. package/lib/commonjs/providers/icloudKV.web.js +42 -0
  53. package/lib/commonjs/providers/icloudKV.web.js.map +1 -0
  54. package/lib/commonjs/providers/memory.js +201 -0
  55. package/lib/commonjs/providers/memory.js.map +1 -0
  56. package/lib/commonjs/resolvers.js +128 -0
  57. package/lib/commonjs/resolvers.js.map +1 -0
  58. package/lib/commonjs/specs/NativeRNCloudSync.js +14 -0
  59. package/lib/commonjs/specs/NativeRNCloudSync.js.map +1 -0
  60. package/lib/commonjs/store.js +1064 -0
  61. package/lib/commonjs/store.js.map +1 -0
  62. package/lib/commonjs/testing.js +32 -0
  63. package/lib/commonjs/testing.js.map +1 -0
  64. package/lib/commonjs/types.js +86 -0
  65. package/lib/commonjs/types.js.map +1 -0
  66. package/lib/module/config.js +72 -0
  67. package/lib/module/config.js.map +1 -0
  68. package/lib/module/errors.js +231 -0
  69. package/lib/module/errors.js.map +1 -0
  70. package/lib/module/hooks.js +250 -0
  71. package/lib/module/hooks.js.map +1 -0
  72. package/lib/module/index.js +46 -0
  73. package/lib/module/index.js.map +1 -0
  74. package/lib/module/internal/autoFlush.js +62 -0
  75. package/lib/module/internal/autoFlush.js.map +1 -0
  76. package/lib/module/internal/base64.js +53 -0
  77. package/lib/module/internal/base64.js.map +1 -0
  78. package/lib/module/internal/bytes.js +28 -0
  79. package/lib/module/internal/bytes.js.map +1 -0
  80. package/lib/module/internal/cloudKitRest.js +518 -0
  81. package/lib/module/internal/cloudKitRest.js.map +1 -0
  82. package/lib/module/internal/enums.js +18 -0
  83. package/lib/module/internal/enums.js.map +1 -0
  84. package/lib/module/internal/googleDriveRest.js +620 -0
  85. package/lib/module/internal/googleDriveRest.js.map +1 -0
  86. package/lib/module/internal/keys.js +134 -0
  87. package/lib/module/internal/keys.js.map +1 -0
  88. package/lib/module/internal/logger.js +23 -0
  89. package/lib/module/internal/logger.js.map +1 -0
  90. package/lib/module/internal/nativeModule.js +117 -0
  91. package/lib/module/internal/nativeModule.js.map +1 -0
  92. package/lib/module/internal/timeout.js +67 -0
  93. package/lib/module/internal/timeout.js.map +1 -0
  94. package/lib/module/package.json +1 -0
  95. package/lib/module/providers/cloudKit.js +392 -0
  96. package/lib/module/providers/cloudKit.js.map +1 -0
  97. package/lib/module/providers/cloudKitBackup.js +82 -0
  98. package/lib/module/providers/cloudKitBackup.js.map +1 -0
  99. package/lib/module/providers/cloudKitEncrypted.js +146 -0
  100. package/lib/module/providers/cloudKitEncrypted.js.map +1 -0
  101. package/lib/module/providers/googleDrive.js +214 -0
  102. package/lib/module/providers/googleDrive.js.map +1 -0
  103. package/lib/module/providers/googleDriveFiles.js +64 -0
  104. package/lib/module/providers/googleDriveFiles.js.map +1 -0
  105. package/lib/module/providers/icloudDocuments.js +117 -0
  106. package/lib/module/providers/icloudDocuments.js.map +1 -0
  107. package/lib/module/providers/icloudKV.js +165 -0
  108. package/lib/module/providers/icloudKV.js.map +1 -0
  109. package/lib/module/providers/icloudKV.web.js +36 -0
  110. package/lib/module/providers/icloudKV.web.js.map +1 -0
  111. package/lib/module/providers/memory.js +197 -0
  112. package/lib/module/providers/memory.js.map +1 -0
  113. package/lib/module/resolvers.js +120 -0
  114. package/lib/module/resolvers.js.map +1 -0
  115. package/lib/module/specs/NativeRNCloudSync.js +12 -0
  116. package/lib/module/specs/NativeRNCloudSync.js.map +1 -0
  117. package/lib/module/store.js +1061 -0
  118. package/lib/module/store.js.map +1 -0
  119. package/lib/module/testing.js +17 -0
  120. package/lib/module/testing.js.map +1 -0
  121. package/lib/module/types.js +82 -0
  122. package/lib/module/types.js.map +1 -0
  123. package/lib/typescript/commonjs/config.d.ts +33 -0
  124. package/lib/typescript/commonjs/config.d.ts.map +1 -0
  125. package/lib/typescript/commonjs/errors.d.ts +140 -0
  126. package/lib/typescript/commonjs/errors.d.ts.map +1 -0
  127. package/lib/typescript/commonjs/hooks.d.ts +109 -0
  128. package/lib/typescript/commonjs/hooks.d.ts.map +1 -0
  129. package/lib/typescript/commonjs/index.d.ts +37 -0
  130. package/lib/typescript/commonjs/index.d.ts.map +1 -0
  131. package/lib/typescript/commonjs/internal/autoFlush.d.ts +45 -0
  132. package/lib/typescript/commonjs/internal/autoFlush.d.ts.map +1 -0
  133. package/lib/typescript/commonjs/internal/base64.d.ts +12 -0
  134. package/lib/typescript/commonjs/internal/base64.d.ts.map +1 -0
  135. package/lib/typescript/commonjs/internal/bytes.d.ts +12 -0
  136. package/lib/typescript/commonjs/internal/bytes.d.ts.map +1 -0
  137. package/lib/typescript/commonjs/internal/cloudKitRest.d.ts +149 -0
  138. package/lib/typescript/commonjs/internal/cloudKitRest.d.ts.map +1 -0
  139. package/lib/typescript/commonjs/internal/enums.d.ts +10 -0
  140. package/lib/typescript/commonjs/internal/enums.d.ts.map +1 -0
  141. package/lib/typescript/commonjs/internal/googleDriveRest.d.ts +232 -0
  142. package/lib/typescript/commonjs/internal/googleDriveRest.d.ts.map +1 -0
  143. package/lib/typescript/commonjs/internal/keys.d.ts +28 -0
  144. package/lib/typescript/commonjs/internal/keys.d.ts.map +1 -0
  145. package/lib/typescript/commonjs/internal/logger.d.ts +10 -0
  146. package/lib/typescript/commonjs/internal/logger.d.ts.map +1 -0
  147. package/lib/typescript/commonjs/internal/nativeModule.d.ts +29 -0
  148. package/lib/typescript/commonjs/internal/nativeModule.d.ts.map +1 -0
  149. package/lib/typescript/commonjs/internal/timeout.d.ts +36 -0
  150. package/lib/typescript/commonjs/internal/timeout.d.ts.map +1 -0
  151. package/lib/typescript/commonjs/package.json +1 -0
  152. package/lib/typescript/commonjs/providers/cloudKit.d.ts +86 -0
  153. package/lib/typescript/commonjs/providers/cloudKit.d.ts.map +1 -0
  154. package/lib/typescript/commonjs/providers/cloudKitBackup.d.ts +65 -0
  155. package/lib/typescript/commonjs/providers/cloudKitBackup.d.ts.map +1 -0
  156. package/lib/typescript/commonjs/providers/cloudKitEncrypted.d.ts +37 -0
  157. package/lib/typescript/commonjs/providers/cloudKitEncrypted.d.ts.map +1 -0
  158. package/lib/typescript/commonjs/providers/googleDrive.d.ts +35 -0
  159. package/lib/typescript/commonjs/providers/googleDrive.d.ts.map +1 -0
  160. package/lib/typescript/commonjs/providers/googleDriveFiles.d.ts +59 -0
  161. package/lib/typescript/commonjs/providers/googleDriveFiles.d.ts.map +1 -0
  162. package/lib/typescript/commonjs/providers/icloudDocuments.d.ts +101 -0
  163. package/lib/typescript/commonjs/providers/icloudDocuments.d.ts.map +1 -0
  164. package/lib/typescript/commonjs/providers/icloudKV.d.ts +26 -0
  165. package/lib/typescript/commonjs/providers/icloudKV.d.ts.map +1 -0
  166. package/lib/typescript/commonjs/providers/icloudKV.web.d.ts +12 -0
  167. package/lib/typescript/commonjs/providers/icloudKV.web.d.ts.map +1 -0
  168. package/lib/typescript/commonjs/providers/memory.d.ts +90 -0
  169. package/lib/typescript/commonjs/providers/memory.d.ts.map +1 -0
  170. package/lib/typescript/commonjs/resolvers.d.ts +60 -0
  171. package/lib/typescript/commonjs/resolvers.d.ts.map +1 -0
  172. package/lib/typescript/commonjs/specs/NativeRNCloudSync.d.ts +133 -0
  173. package/lib/typescript/commonjs/specs/NativeRNCloudSync.d.ts.map +1 -0
  174. package/lib/typescript/commonjs/store.d.ts +118 -0
  175. package/lib/typescript/commonjs/store.d.ts.map +1 -0
  176. package/lib/typescript/commonjs/testing.d.ts +16 -0
  177. package/lib/typescript/commonjs/testing.d.ts.map +1 -0
  178. package/lib/typescript/commonjs/types.d.ts +367 -0
  179. package/lib/typescript/commonjs/types.d.ts.map +1 -0
  180. package/lib/typescript/module/config.d.ts +33 -0
  181. package/lib/typescript/module/config.d.ts.map +1 -0
  182. package/lib/typescript/module/errors.d.ts +140 -0
  183. package/lib/typescript/module/errors.d.ts.map +1 -0
  184. package/lib/typescript/module/hooks.d.ts +109 -0
  185. package/lib/typescript/module/hooks.d.ts.map +1 -0
  186. package/lib/typescript/module/index.d.ts +37 -0
  187. package/lib/typescript/module/index.d.ts.map +1 -0
  188. package/lib/typescript/module/internal/autoFlush.d.ts +45 -0
  189. package/lib/typescript/module/internal/autoFlush.d.ts.map +1 -0
  190. package/lib/typescript/module/internal/base64.d.ts +12 -0
  191. package/lib/typescript/module/internal/base64.d.ts.map +1 -0
  192. package/lib/typescript/module/internal/bytes.d.ts +12 -0
  193. package/lib/typescript/module/internal/bytes.d.ts.map +1 -0
  194. package/lib/typescript/module/internal/cloudKitRest.d.ts +149 -0
  195. package/lib/typescript/module/internal/cloudKitRest.d.ts.map +1 -0
  196. package/lib/typescript/module/internal/enums.d.ts +10 -0
  197. package/lib/typescript/module/internal/enums.d.ts.map +1 -0
  198. package/lib/typescript/module/internal/googleDriveRest.d.ts +232 -0
  199. package/lib/typescript/module/internal/googleDriveRest.d.ts.map +1 -0
  200. package/lib/typescript/module/internal/keys.d.ts +28 -0
  201. package/lib/typescript/module/internal/keys.d.ts.map +1 -0
  202. package/lib/typescript/module/internal/logger.d.ts +10 -0
  203. package/lib/typescript/module/internal/logger.d.ts.map +1 -0
  204. package/lib/typescript/module/internal/nativeModule.d.ts +29 -0
  205. package/lib/typescript/module/internal/nativeModule.d.ts.map +1 -0
  206. package/lib/typescript/module/internal/timeout.d.ts +36 -0
  207. package/lib/typescript/module/internal/timeout.d.ts.map +1 -0
  208. package/lib/typescript/module/package.json +1 -0
  209. package/lib/typescript/module/providers/cloudKit.d.ts +86 -0
  210. package/lib/typescript/module/providers/cloudKit.d.ts.map +1 -0
  211. package/lib/typescript/module/providers/cloudKitBackup.d.ts +65 -0
  212. package/lib/typescript/module/providers/cloudKitBackup.d.ts.map +1 -0
  213. package/lib/typescript/module/providers/cloudKitEncrypted.d.ts +37 -0
  214. package/lib/typescript/module/providers/cloudKitEncrypted.d.ts.map +1 -0
  215. package/lib/typescript/module/providers/googleDrive.d.ts +35 -0
  216. package/lib/typescript/module/providers/googleDrive.d.ts.map +1 -0
  217. package/lib/typescript/module/providers/googleDriveFiles.d.ts +59 -0
  218. package/lib/typescript/module/providers/googleDriveFiles.d.ts.map +1 -0
  219. package/lib/typescript/module/providers/icloudDocuments.d.ts +101 -0
  220. package/lib/typescript/module/providers/icloudDocuments.d.ts.map +1 -0
  221. package/lib/typescript/module/providers/icloudKV.d.ts +26 -0
  222. package/lib/typescript/module/providers/icloudKV.d.ts.map +1 -0
  223. package/lib/typescript/module/providers/icloudKV.web.d.ts +12 -0
  224. package/lib/typescript/module/providers/icloudKV.web.d.ts.map +1 -0
  225. package/lib/typescript/module/providers/memory.d.ts +90 -0
  226. package/lib/typescript/module/providers/memory.d.ts.map +1 -0
  227. package/lib/typescript/module/resolvers.d.ts +60 -0
  228. package/lib/typescript/module/resolvers.d.ts.map +1 -0
  229. package/lib/typescript/module/specs/NativeRNCloudSync.d.ts +133 -0
  230. package/lib/typescript/module/specs/NativeRNCloudSync.d.ts.map +1 -0
  231. package/lib/typescript/module/store.d.ts +118 -0
  232. package/lib/typescript/module/store.d.ts.map +1 -0
  233. package/lib/typescript/module/testing.d.ts +16 -0
  234. package/lib/typescript/module/testing.d.ts.map +1 -0
  235. package/lib/typescript/module/types.d.ts +367 -0
  236. package/lib/typescript/module/types.d.ts.map +1 -0
  237. package/package.json +186 -0
  238. package/plugin/build/index.d.ts +45 -0
  239. package/plugin/build/index.js +93 -0
  240. package/react-native-cloud-sync.podspec +48 -0
  241. package/src/config.ts +94 -0
  242. package/src/errors.ts +263 -0
  243. package/src/hooks.ts +337 -0
  244. package/src/index.ts +113 -0
  245. package/src/internal/autoFlush.ts +87 -0
  246. package/src/internal/base64.ts +63 -0
  247. package/src/internal/bytes.ts +28 -0
  248. package/src/internal/cloudKitRest.ts +654 -0
  249. package/src/internal/enums.ts +35 -0
  250. package/src/internal/googleDriveRest.ts +765 -0
  251. package/src/internal/keys.ts +160 -0
  252. package/src/internal/logger.ts +23 -0
  253. package/src/internal/nativeModule.ts +149 -0
  254. package/src/internal/timeout.ts +83 -0
  255. package/src/providers/cloudKit.ts +510 -0
  256. package/src/providers/cloudKitBackup.ts +124 -0
  257. package/src/providers/cloudKitEncrypted.ts +175 -0
  258. package/src/providers/googleDrive.ts +251 -0
  259. package/src/providers/googleDriveFiles.ts +117 -0
  260. package/src/providers/icloudDocuments.ts +175 -0
  261. package/src/providers/icloudKV.ts +206 -0
  262. package/src/providers/icloudKV.web.ts +41 -0
  263. package/src/providers/memory.ts +302 -0
  264. package/src/resolvers.ts +133 -0
  265. package/src/specs/NativeRNCloudSync.ts +184 -0
  266. package/src/store.ts +1288 -0
  267. package/src/testing.ts +22 -0
  268. package/src/types.ts +426 -0
@@ -0,0 +1,232 @@
1
+ import { type AbortLike } from './timeout.js';
2
+ /**
3
+ * Google Drive `appDataFolder` REST client.
4
+ *
5
+ * `appDataFolder` is a hidden per-app, per-Google-account folder: nothing shows
6
+ * up in the user's visible Drive, and the data survives an app uninstall because
7
+ * it is tied to the account rather than the install.
8
+ *
9
+ * Auth is deliberately injected rather than owned. The library does not depend
10
+ * on `@react-native-google-signin/google-signin` (or any other sign-in library),
11
+ * so the host app keeps control of the consent flow, and the same client works
12
+ * unchanged in a browser where that library does not apply.
13
+ */
14
+ export interface GoogleDriveConfig {
15
+ /**
16
+ * Returns a valid OAuth access token with the `drive.appdata` scope, or null
17
+ * if the user is not connected. Called before every request, so implementers
18
+ * should refresh silently here rather than caching a stale token.
19
+ */
20
+ getAccessToken: () => Promise<string | null> | string | null;
21
+ /** Called when Drive rejects the token, so the host can prompt for reconnect. */
22
+ onAuthExpired?: () => Promise<void> | void;
23
+ fetchImpl?: typeof fetch;
24
+ /**
25
+ * Bytes per chunk for `uploadFile`/`downloadFile`. Default 8 MiB.
26
+ *
27
+ * Must be a multiple of 256 KiB (262144) - Google's resumable upload
28
+ * protocol requires that for every chunk but the last. Lowered in tests to
29
+ * exercise the multi-chunk path without a multi-MB fixture.
30
+ */
31
+ chunkBytes?: number;
32
+ /**
33
+ * What to do when `appDataFolder` holds more than one file with the same
34
+ * name. Default `'newest'`.
35
+ *
36
+ * Drive names are not unique - it is a file store with ids, not a key-value
37
+ * store - so two devices creating the same key while both are offline
38
+ * genuinely produce two files. Picking whichever the API happened to list
39
+ * first is the worst option: the choice is unspecified, so two devices can
40
+ * settle on different files and diverge permanently with no error anywhere.
41
+ *
42
+ * `'newest'` picks the most recently modified, which every device agrees on.
43
+ * `'error'` raises {@link ErrorCode.CONFLICT} instead, for apps that would
44
+ * rather reconcile explicitly than have one copy quietly win.
45
+ */
46
+ onDuplicateName?: 'newest' | 'error';
47
+ /**
48
+ * Abandon a request that has not answered in this long. Default 60000.
49
+ *
50
+ * Longer than the CloudKit client's because one "request" here can be a whole
51
+ * 8 MiB chunk on a slow connection. `fetch` in React Native has no timeout of
52
+ * its own, so without this a dead socket hangs the transfer forever.
53
+ */
54
+ timeoutMs?: number;
55
+ }
56
+ /** A local file `uploadFile` reads from, in fixed-size pieces. */
57
+ export interface DriveChunkSource {
58
+ size: number;
59
+ read: (start: number, length: number) => Promise<Uint8Array>;
60
+ }
61
+ /** A local file `downloadFile` writes into, one piece at a time. */
62
+ export interface DriveChunkSink {
63
+ write: (bytes: Uint8Array, isFirstChunk: boolean) => Promise<void>;
64
+ }
65
+ /**
66
+ * Local file I/O for `googleDriveFiles`, supplied by the host app rather than
67
+ * this package depending on a filesystem library.
68
+ *
69
+ * base64 in and out - not a stream or a byte array - because that is the
70
+ * primitive RN filesystem libraries actually expose for a chunked read/write
71
+ * (`expo-file-system`'s `readAsStringAsync`/`writeAsStringAsync` with
72
+ * `EncodingType.Base64` and `position`/`length`/`append`), so the adapter
73
+ * mirrors that rather than inventing an abstraction nothing implements
74
+ * natively. `googleDriveFiles` does the base64 <-> bytes conversion at the
75
+ * boundary; a chunk is capped at `chunkBytes` (8 MiB default), so the base64
76
+ * string is never larger than that either.
77
+ */
78
+ export interface GoogleDriveFileAdapter {
79
+ /** Size in bytes of the local file at `uri`. */
80
+ statSize: (uri: string) => Promise<number>;
81
+ /** Reads `length` bytes starting at `position` from the local file at `uri`, base64-encoded. */
82
+ readChunk: (uri: string, position: number, length: number) => Promise<string>;
83
+ /** Creates (or overwrites) the local file at `uri` with these base64-encoded bytes. */
84
+ writeChunk: (uri: string, base64: string) => Promise<void>;
85
+ /** Appends base64-encoded bytes to a file `writeChunk` already created. */
86
+ appendChunk: (uri: string, base64: string) => Promise<void>;
87
+ }
88
+ export declare class GoogleDriveClient {
89
+ private readonly config;
90
+ /**
91
+ * name -> fileId.
92
+ *
93
+ * Drive has no "get by name" endpoint, so every read would otherwise cost a
94
+ * list query. react-native-cloud-storage's Drive backend does exactly that and
95
+ * additionally lists the *whole* drive before filtering client-side, which its
96
+ * users measured in minutes (kuatsu#49) and which can loop forever (kuatsu#39).
97
+ * A scoped `q=` query plus this cache keeps a read to one request, usually zero.
98
+ */
99
+ private readonly idCache;
100
+ /**
101
+ * name -> the metadata the last listing reported.
102
+ *
103
+ * Kept beside the id cache so `getItemWithMeta` does not need a second round
104
+ * trip to learn a modification time the `q=` query already returned.
105
+ */
106
+ private readonly metaCache;
107
+ private readonly chunkBytes;
108
+ constructor(config: GoogleDriveConfig);
109
+ private get fetch();
110
+ private requireToken;
111
+ /**
112
+ * `extraOkStatuses` is for the resumable-upload protocol, where 308 ("Resume
113
+ * Incomplete") is an expected, successful outcome rather than an error - the
114
+ * caller inspects the response itself rather than getting a thrown rejection.
115
+ */
116
+ private request;
117
+ /**
118
+ * Resolves a file name to its id within appDataFolder, or null if absent.
119
+ *
120
+ * Pass `refresh` to bypass the memo after a cached id turned out to be stale.
121
+ */
122
+ private findFileId;
123
+ /**
124
+ * Chooses between several files that share a name.
125
+ *
126
+ * Deterministically, and that is the whole point: the list order Drive
127
+ * returns is unspecified, so picking the first match lets two devices settle
128
+ * on two different files for the same key and diverge forever, silently.
129
+ * Ordering by modification time - newest first, ties broken by id - gives
130
+ * every device the same answer.
131
+ */
132
+ private pickAmongDuplicates;
133
+ /** Records what a listing told us about a file, ids and metadata together. */
134
+ private remember;
135
+ getItem(name: string): Promise<string | null>;
136
+ /**
137
+ * A read that also reports Drive's own `modifiedTime`.
138
+ *
139
+ * Free: resolving a name to an id is already a listing, and asking that
140
+ * listing for `modifiedTime` costs nothing extra. Surfacing it is what lets
141
+ * {@link resolveByModifiedAt} order copies without the app embedding a
142
+ * timestamp in its payload.
143
+ */
144
+ getItemWithMeta(name: string): Promise<{
145
+ value: string;
146
+ modifiedAt?: number;
147
+ version?: string;
148
+ } | null>;
149
+ /**
150
+ * Storage usage for the whole Google account.
151
+ *
152
+ * Note this is the account's total, not the `appDataFolder`'s share of it -
153
+ * Drive reports no per-folder usage. Still the number a "you are running out
154
+ * of space" prompt needs, because that is the limit a write will actually hit.
155
+ * `limit` is absent for unlimited (Workspace pooled) accounts.
156
+ */
157
+ getQuota(): Promise<{
158
+ usedBytes?: number;
159
+ totalBytes?: number;
160
+ }>;
161
+ setItem(name: string, value: string): Promise<void>;
162
+ /**
163
+ * Uploads `source` as `name`, using Drive's resumable protocol instead of
164
+ * `setItem`'s single-request multipart body.
165
+ *
166
+ * Two things a whole-file `setItem(name, base64OfEverything)` cannot do at
167
+ * a few hundred MB: hold the payload in memory as one JS string, and recover
168
+ * from a dropped connection without starting over. Reading happens in fixed
169
+ * chunks through `source.read`, so peak memory is one chunk rather than the
170
+ * whole file, and a chunk that fails mid-flight is retried - by asking Drive
171
+ * how many bytes it actually has and resuming from there - rather than
172
+ * restarting the transfer.
173
+ *
174
+ * That resumability is scoped to this call: the session lives only in
175
+ * memory, so if the process dies mid-upload, the next call to `uploadFile`
176
+ * starts a fresh session from byte 0. Persisting the session URI so a
177
+ * restart can resume it too is future scope, not something callers should
178
+ * assume works today.
179
+ */
180
+ uploadFile(name: string, source: DriveChunkSource, onProgress?: (bytesTransferred: number, bytesTotal: number) => void, signal?: AbortLike): Promise<void>;
181
+ private startResumableSession;
182
+ /** One chunk, with a single retry that re-queries the server's real offset first. */
183
+ private putChunkWithRetry;
184
+ private putChunk;
185
+ /** Asks Drive how much of an in-flight resumable session it actually has. */
186
+ private queryUploadOffset;
187
+ /**
188
+ * Downloads `name` into `sink`, in the same fixed-size chunks `uploadFile`
189
+ * writes in - so a restore never holds the whole file in memory either.
190
+ * Resolves `false` when no such file exists, `true` once every chunk has
191
+ * been handed to the sink.
192
+ */
193
+ downloadFile(name: string, sink: DriveChunkSink, onProgress?: (bytesTransferred: number, bytesTotal: number) => void, signal?: AbortLike): Promise<boolean>;
194
+ private fileSize;
195
+ removeItem(name: string): Promise<void>;
196
+ getAllKeys(): Promise<string[]>;
197
+ /**
198
+ * A cursor marking "everything up to now", for {@link pollChanges}.
199
+ *
200
+ * Drive's change feed is cursor-based rather than time-based, so a watcher
201
+ * has to take a starting cursor before it can ask what changed since.
202
+ */
203
+ getStartPageToken(): Promise<string>;
204
+ /**
205
+ * What changed in `appDataFolder` since `pageToken`, and the cursor to use
206
+ * next time.
207
+ *
208
+ * This is how a non-Apple platform learns that another device wrote something
209
+ * - CloudKit gets `NSUbiquitousKeyValueStore` notifications and `CKAccountChanged`
210
+ * for free, but Drive has no push channel without a server to receive its
211
+ * webhooks, so the honest equivalent is a cursor the app polls. Cheap: a poll
212
+ * with nothing to report is one request returning an empty list.
213
+ *
214
+ * Deletions are included - `removed` entries and trashed files both surface,
215
+ * because "another device deleted this key" is exactly as important as
216
+ * "another device changed it".
217
+ */
218
+ pollChanges(pageToken: string): Promise<{
219
+ names: string[];
220
+ nextToken: string;
221
+ }>;
222
+ /** Drops whatever name currently memoises this file id. */
223
+ private forgetById;
224
+ /**
225
+ * Whether an access token can currently be obtained, without making a network
226
+ * request. Backs the provider's `isAvailable()` probe.
227
+ */
228
+ hasToken(): Promise<boolean>;
229
+ /** Drops memoised file ids. Call after an account switch. */
230
+ clearCache(): void;
231
+ }
232
+ //# sourceMappingURL=googleDriveRest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"googleDriveRest.d.ts","sourceRoot":"","sources":["../../../../src/internal/googleDriveRest.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,28 @@
1
+ import type { ProviderName } from '../types.js';
2
+ export interface KeyRule {
3
+ /** Human-readable statement of what was violated. */
4
+ reason: string;
5
+ /** The provider whose limit this is, or null when every provider shares it. */
6
+ provider: ProviderName | null;
7
+ }
8
+ /**
9
+ * The first rule `key` breaks for this set of providers, or null when it is
10
+ * usable everywhere.
11
+ *
12
+ * Provider-aware on purpose: the 64-byte ceiling is the key-value store's
13
+ * alone, and rejecting a 100-character key for an app that only configured
14
+ * Drive would be a false alarm.
15
+ */
16
+ export declare function checkKey(key: string, providers: readonly ProviderName[]): KeyRule | null;
17
+ /** Throws {@link ErrorCode.INVALID_KEY} when `key` is unusable. */
18
+ export declare function assertKey(key: string, providers: readonly ProviderName[]): void;
19
+ /**
20
+ * Rewrites an arbitrary string into a key that passes {@link checkKey}.
21
+ *
22
+ * For callers whose keys come from somewhere they do not control - a file name,
23
+ * a user-entered label, an id from another system. Illegal characters become
24
+ * `-`, and anything too long is truncated and suffixed with a short hash of the
25
+ * original so two different long keys cannot collide.
26
+ */
27
+ export declare function sanitizeKey(raw: string, maxBytes?: number): string;
28
+ //# sourceMappingURL=keys.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../../../src/internal/keys.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAU,CAAA;AAkD5C,MAAM,WAAW,OAAO;IACtB,qDAAqD;IACrD,MAAM,EAAE,MAAM,CAAA;IACd,+EAA+E;IAC/E,QAAQ,EAAE,YAAY,GAAG,IAAI,CAAA;CAC9B;AAED;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,YAAY,EAAE,GAAG,OAAO,GAAG,IAAI,CA8CxF;AAED,mEAAmE;AACnE,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,YAAY,EAAE,GAAG,IAAI,CAS/E;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,SAAmB,GAAG,MAAM,CAe5E"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Toggles verbose logging in both JS and the native layer.
3
+ *
4
+ * Off by default: a storage library logging every read on a hot path is noise,
5
+ * and cloud payloads can contain user data that should not land in a device log.
6
+ */
7
+ export declare function setLogsEnabled(value: boolean): void;
8
+ export declare function isLogsEnabled(): boolean;
9
+ export declare function log(...args: unknown[]): void;
10
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../../src/internal/logger.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAGnD;AAED,wBAAgB,aAAa,IAAI,OAAO,CAEvC;AAED,wBAAgB,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAG5C"}
@@ -0,0 +1,29 @@
1
+ import type { Spec } from '../specs/NativeRNCloudSync.js';
2
+ import type { Unsubscribe } from '../types.js';
3
+ /**
4
+ * Resolves the native module lazily.
5
+ *
6
+ * New arch exposes it through TurboModuleRegistry; old arch through the
7
+ * NativeModules proxy. Resolution is deferred rather than done at import time
8
+ * so that merely importing this package on a platform without the native module
9
+ * (web, or Android for the iCloud provider) does not throw at bundle-evaluation
10
+ * time - which is exactly the crash cryptoc had to work around with a
11
+ * `Platform.OS === 'ios' ? requireNativeModule(...) : null` guard.
12
+ */
13
+ export declare function getNativeModule(): Spec | null;
14
+ /** Like {@link getNativeModule} but throws a diagnostic instead of returning null. */
15
+ export declare function requireNativeModule(): Spec;
16
+ export declare function hasNativeModule(): boolean;
17
+ /**
18
+ * Event names differ per architecture.
19
+ *
20
+ * Codegen's EventEmitter properties must be named `onSomething`, while the old
21
+ * architecture's `supportedEvents` list uses the bare name. Rather than leak
22
+ * that split into every call site, subscribe through this helper.
23
+ * (react-native-background-downloader carries the same `onDownloadBegin` vs
24
+ * `downloadBegin` split for the same reason.)
25
+ */
26
+ export declare function subscribeNativeEvent<T>(newArchName: 'onRemoteChange' | 'onAccountChange' | 'onAssetProgress', legacyName: 'remoteChange' | 'accountChange' | 'assetProgress', listener: (e: T) => void): Unsubscribe;
27
+ /** Exposed for tests and diagnostics only. */
28
+ export declare function __resetNativeModuleCache(): void;
29
+ //# sourceMappingURL=nativeModule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nativeModule.d.ts","sourceRoot":"","sources":["../../../../src/internal/nativeModule.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,+BAA4B,CAAA;AAEtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAU,CAAA;AAsB3C;;;;;;;;;GASG;AACH,wBAAgB,eAAe,IAAI,IAAI,GAAG,IAAI,CAuC7C;AAED,sFAAsF;AACtF,wBAAgB,mBAAmB,IAAI,IAAI,CAW1C;AAED,wBAAgB,eAAe,IAAI,OAAO,CAEzC;AAgBD;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EACpC,WAAW,EAAE,gBAAgB,GAAG,iBAAiB,GAAG,iBAAiB,EACrE,UAAU,EAAE,cAAc,GAAG,eAAe,GAAG,eAAe,EAC9D,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,GACvB,WAAW,CAkBb;AAED,8CAA8C;AAC9C,wBAAgB,wBAAwB,IAAI,IAAI,CAK/C"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Rejects with {@link ErrorCode.TIMEOUT} if `promise` has not settled in time.
3
+ *
4
+ * React Native's `fetch` has no default timeout, and neither does CloudKit's
5
+ * native stack, so an unanswered socket hangs an operation forever. That is
6
+ * worse than an error: the store calls `isAvailable()` before every operation,
7
+ * so one hung probe stalls reads and writes that would otherwise have fallen
8
+ * through to a working provider.
9
+ *
10
+ * The underlying work is *not* cancelled - a promise cannot be. This only stops
11
+ * the caller waiting on it, which is why the timeout error is classified as
12
+ * retryable rather than as a failure.
13
+ */
14
+ export declare function withTimeout<T>(promise: Promise<T>, ms: number, provider?: string): Promise<T>;
15
+ /**
16
+ * The subset of `AbortSignal` this package needs.
17
+ *
18
+ * Typed structurally rather than as the DOM `AbortSignal` so a caller can pass
19
+ * one from any polyfill, and so the package does not require `lib.dom` to be in
20
+ * a consumer's `tsconfig`.
21
+ */
22
+ export interface AbortLike {
23
+ readonly aborted: boolean;
24
+ addEventListener: (type: 'abort', listener: () => void) => void;
25
+ removeEventListener: (type: 'abort', listener: () => void) => void;
26
+ }
27
+ /** Throws {@link ErrorCode.CANCELLED} if the signal is already aborted. */
28
+ export declare function throwIfAborted(signal: AbortLike | undefined, provider?: string): void;
29
+ /**
30
+ * Races `promise` against an abort signal.
31
+ *
32
+ * Used by the chunked transfer paths, where "cancel" has to take effect between
33
+ * chunks rather than only once the whole multi-hundred-megabyte file has moved.
34
+ */
35
+ export declare function withAbort<T>(promise: Promise<T>, signal: AbortLike | undefined, provider?: string): Promise<T>;
36
+ //# sourceMappingURL=timeout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timeout.d.ts","sourceRoot":"","sources":["../../../../src/internal/timeout.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAiB7F;AAED;;;;;;GAMG;AACH,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;IACzB,gBAAgB,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,KAAK,IAAI,CAAA;IAC/D,mBAAmB,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,KAAK,IAAI,CAAA;CACnE;AAED,2EAA2E;AAC3E,wBAAgB,cAAc,CAAC,MAAM,EAAE,SAAS,GAAG,SAAS,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAErF;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,CAAC,EACzB,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EACnB,MAAM,EAAE,SAAS,GAAG,SAAS,EAC7B,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,CAAC,CAAC,CAoBZ"}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,86 @@
1
+ import { type CloudKitRestConfig } from '../internal/cloudKitRest.js';
2
+ import type { AssetProgressEvent, CloudProvider, ProviderName, Unsubscribe } from '../types.js';
3
+ export declare const cloudKit: CloudProvider;
4
+ /**
5
+ * A CloudKit provider with its own REST credentials and its own name.
6
+ *
7
+ * `configureCloudKit` sets one client for the whole process. That is right for
8
+ * a normal app, but leaves no way to reach two containers at once - a staging
9
+ * container beside production, or a migration that copies between them - and no
10
+ * way for two tests to hold different configurations.
11
+ *
12
+ * REST only, and that is not a limitation that can be lifted: the native path
13
+ * authenticates as whatever iCloud account the *device* is signed into, so
14
+ * "another set of credentials" has no meaning there. On iOS this therefore
15
+ * still talks to CloudKit Web Services rather than to `CloudKit.framework`.
16
+ */
17
+ export declare function createCloudKitProvider(config: CloudKitRestConfig & {
18
+ name?: ProviderName;
19
+ }): CloudProvider;
20
+ /** Custom zones. Native only - the REST client uses the default zone. */
21
+ export declare const zones: {
22
+ create: (zoneName: string) => Promise<void>;
23
+ remove: (zoneName: string) => Promise<void>;
24
+ list: () => Promise<string[]>;
25
+ };
26
+ /**
27
+ * Binary assets (`CKAsset`).
28
+ *
29
+ * Native only. CloudKit Web Services does expose an asset upload flow, but it
30
+ * is a separate multi-step protocol (request an upload URL, POST the bytes,
31
+ * then reference the returned token in a record) that this package does not
32
+ * implement yet - so on Android and web these reject with
33
+ * `ERR_UNSUPPORTED_PLATFORM` rather than appearing to work.
34
+ *
35
+ * Assets are deliberately an explicit API rather than something the store
36
+ * facade routes to automatically: the caller passes a file path, not a string,
37
+ * so there is no way to infer the intent from a `setItem` call.
38
+ */
39
+ export declare const assets: {
40
+ /**
41
+ * Uploads a local file as a field on a record.
42
+ *
43
+ * Progress is reported per record through {@link onProgress}; a CKAsset is
44
+ * streamed from disk, so a large file does not have to be held in memory the
45
+ * way a base64 round trip would.
46
+ */
47
+ save: (options: {
48
+ recordName: string;
49
+ fieldName: string;
50
+ /** `file://` URL or a plain path. */
51
+ fileUri: string;
52
+ recordType?: string;
53
+ zoneName?: string | null;
54
+ }) => Promise<void>;
55
+ /**
56
+ * Downloads an asset field and resolves a local file path, or `null` when the
57
+ * record or field does not exist.
58
+ *
59
+ * Pass `destinationUri` for anything the user is going to keep or hand to a
60
+ * share sheet. Without it the file lands in the app's temporary directory
61
+ * under a name derived from the record, and iOS may reclaim that at any
62
+ * time - fine for restoring straight back into the app, wrong for an export.
63
+ * Parent directories are created if they do not exist.
64
+ */
65
+ fetch: (options: {
66
+ recordName: string;
67
+ fieldName: string;
68
+ zoneName?: string | null;
69
+ destinationUri?: string;
70
+ }) => Promise<string | null>;
71
+ /**
72
+ * Cancels an in-flight {@link save} or {@link fetch}, rejecting that call
73
+ * with `ERR_CANCELLED`. Resolves true when there was a transfer to cancel.
74
+ *
75
+ * Identified by record and field rather than by a handle, because that is
76
+ * what identifies a transfer everywhere else in this API - `onProgress`
77
+ * reports the same pair, so a UI already has it.
78
+ */
79
+ cancel: (options: {
80
+ recordName: string;
81
+ fieldName: string;
82
+ }) => Promise<boolean>;
83
+ /** Upload/download progress for asset transfers. Native only. */
84
+ onProgress: (listener: (e: AssetProgressEvent) => void) => Unsubscribe;
85
+ };
86
+ //# sourceMappingURL=cloudKit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloudKit.d.ts","sourceRoot":"","sources":["../../../../src/providers/cloudKit.ts"],"names":[],"mappings":"AAIA,OAAO,EAAsB,KAAK,kBAAkB,EAAE,MAAM,6BAA0B,CAAA;AAGtF,OAAO,KAAK,EAGV,kBAAkB,EAClB,aAAa,EACb,YAAY,EACZ,WAAW,EACZ,MAAM,aAAU,CAAA;AAiCjB,eAAO,MAAM,QAAQ,EAAE,aAoMtB,CAAA;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,kBAAkB,GAAG;IAAE,IAAI,CAAC,EAAE,YAAY,CAAA;CAAE,GACnD,aAAa,CA8Ff;AAED,yEAAyE;AACzE,eAAO,MAAM,KAAK;uBACS,MAAM,KAAG,OAAO,CAAC,IAAI,CAAC;uBAQtB,MAAM,KAAG,OAAO,CAAC,IAAI,CAAC;gBAQ/B,OAAO,CAAC,MAAM,EAAE,CAAC;CAQlC,CAAA;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,MAAM;IACjB;;;;;;OAMG;oBAEQ;QACP,UAAU,EAAE,MAAM,CAAA;QAClB,SAAS,EAAE,MAAM,CAAA;QACjB,qCAAqC;QACrC,OAAO,EAAE,MAAM,CAAA;QACf,UAAU,CAAC,EAAE,MAAM,CAAA;QACnB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KACzB,KACA,OAAO,CAAC,IAAI,CAAC;IAsBhB;;;;;;;;;OASG;qBAEQ;QACP,UAAU,EAAE,MAAM,CAAA;QAClB,SAAS,EAAE,MAAM,CAAA;QACjB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;QACxB,cAAc,CAAC,EAAE,MAAM,CAAA;KACxB,KACA,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAoBzB;;;;;;;OAOG;sBAEQ;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,KACjD,OAAO,CAAC,OAAO,CAAC;IAUnB,iEAAiE;2BAC1C,CAAC,CAAC,EAAE,kBAAkB,KAAK,IAAI,KAAG,WAAW;CAerE,CAAA"}
@@ -0,0 +1,65 @@
1
+ export interface BackupProgressEvent {
2
+ bytesTransferred: number;
3
+ bytesTotal: number;
4
+ /**
5
+ * `bytesTransferred / bytesTotal`, or 0 while `bytesTotal` is still unknown.
6
+ * `save` knows the size from the first callback (the file is local);
7
+ * `restore` does too, as long as the backup was written by a version of this
8
+ * package that stores the size alongside the asset - older backups fall back
9
+ * to 0 until the transfer completes.
10
+ */
11
+ fraction: number;
12
+ }
13
+ export interface BackupOptions {
14
+ /** CKRecord name identifying this backup. Default `'backup'`. */
15
+ recordName?: string;
16
+ /** Asset field name on that record. Default `'file'`. */
17
+ fieldName?: string;
18
+ zoneName?: string | null;
19
+ /** Called repeatedly while the transfer is in flight, scoped to this call only. */
20
+ onProgress?: (e: BackupProgressEvent) => void;
21
+ /**
22
+ * Where `restore` puts the downloaded file. Ignored by `save`.
23
+ *
24
+ * Pass one whenever the user is going to see the result - an export they
25
+ * save to Files, a database they hand to a share sheet. Without it the file
26
+ * lands in the app's temporary directory, which iOS may reclaim at any time
27
+ * and which the user cannot reach. Parent directories are created for you.
28
+ */
29
+ destinationUri?: string;
30
+ }
31
+ /**
32
+ * Backup/restore built on {@link assets} (`CKAsset`), for a single named blob -
33
+ * a database export, an archive, anything too big for a `CKRecord` field.
34
+ *
35
+ * `cloudKitAssets.onProgress` is a global feed shared by every asset transfer
36
+ * in the app, keyed by `recordName`/`fieldName`, so a caller backing up one
37
+ * file would otherwise have to filter it and manage the subscription by hand.
38
+ * This scopes that to the single transfer each call makes, and unsubscribes
39
+ * when it settles - including on failure.
40
+ *
41
+ * Native only, same as `cloudKitAssets` - rejects with `ERR_UNSUPPORTED_PLATFORM`
42
+ * on Android and web.
43
+ */
44
+ export declare const cloudKitBackup: {
45
+ /**
46
+ * Uploads `fileUri` as this backup's CKAsset, overwriting whatever was there.
47
+ */
48
+ save: (fileUri: string, options?: BackupOptions) => Promise<void>;
49
+ /**
50
+ * Downloads the backup to a local file path, or resolves `null` when none
51
+ * has been saved yet.
52
+ */
53
+ restore: (options?: BackupOptions) => Promise<string | null>;
54
+ /**
55
+ * Cancels a `save` or `restore` in progress, rejecting that call with
56
+ * `ERR_CANCELLED`. Resolves true when there was one to cancel.
57
+ *
58
+ * A backup is the transfer users are most likely to want to stop - it is the
59
+ * biggest, and it is the one they start by accident. Takes the same
60
+ * `recordName`/`fieldName` defaults as the call it cancels, so cancelling the
61
+ * default backup is `cloudKitBackup.cancel()`.
62
+ */
63
+ cancel: (options?: Pick<BackupOptions, "recordName" | "fieldName">) => Promise<boolean>;
64
+ };
65
+ //# sourceMappingURL=cloudKitBackup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloudKitBackup.d.ts","sourceRoot":"","sources":["../../../../src/providers/cloudKitBackup.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,mBAAmB;IAClC,gBAAgB,EAAE,MAAM,CAAA;IACxB,UAAU,EAAE,MAAM,CAAA;IAClB;;;;;;OAMG;IACH,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B,iEAAiE;IACjE,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,yDAAyD;IACzD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,mFAAmF;IACnF,UAAU,CAAC,EAAE,CAAC,CAAC,EAAE,mBAAmB,KAAK,IAAI,CAAA;IAC7C;;;;;;;OAOG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,cAAc;IACzB;;OAEG;oBACmB,MAAM,YAAW,aAAa,KAAQ,OAAO,CAAC,IAAI,CAAC;IAazE;;;OAGG;wBACsB,aAAa,KAAQ,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAkBpE;;;;;;;;OAQG;uBAEQ,IAAI,CAAC,aAAa,EAAE,YAAY,GAAG,WAAW,CAAC,KACvD,OAAO,CAAC,OAAO,CAAC;CAKpB,CAAA"}
@@ -0,0 +1,37 @@
1
+ import type { CloudProvider } from '../types.js';
2
+ /**
3
+ * CloudKit's own end-to-end encryption, via `CKRecord.encryptedValues`.
4
+ *
5
+ * The genuinely native answer to "can I store sensitive data here". Values
6
+ * written through this provider are encrypted on device with a key from the
7
+ * user's iCloud Keychain; Apple stores ciphertext and cannot read it, whether
8
+ * or not the user has turned on Advanced Data Protection. Nothing to configure,
9
+ * no key for you to manage, no passphrase for the user to lose.
10
+ *
11
+ * What it costs, and none of these are avoidable:
12
+ *
13
+ * - **Apple platforms only.** The decryption key is in the iCloud Keychain,
14
+ * which CloudKit Web Services cannot reach, so a value written here is
15
+ * permanently unreadable from Android and web. Not a gap to be closed
16
+ * later - it is what end-to-end means. Reach for the store facade's
17
+ * `codec` if the same data has to be readable off-Apple.
18
+ * - **Not queryable.** CloudKit cannot index an encrypted field, so no
19
+ * server-side filtering or sorting on the value. `getAllKeys()` still
20
+ * works, because it queries record *names*, which are not encrypted.
21
+ * - **Record names are not encrypted either.** Your keys are visible to
22
+ * Apple; only values are protected. Do not put anything sensitive in a key.
23
+ * - **Its own record type** (`EncryptedKVBlob`), so it can coexist with
24
+ * `cloudKit` rather than colliding with its schema.
25
+ *
26
+ * Usable through the facade like any other provider, as long as every provider
27
+ * in the list can actually serve the data:
28
+ *
29
+ * ```ts
30
+ * const secrets = createCloudStore({ providers: ['cloudKitEncrypted'] })
31
+ * ```
32
+ *
33
+ * Mixing it with `googleDrive` in one store is almost always a mistake - the
34
+ * Drive copy would be plaintext, which quietly undoes the encryption.
35
+ */
36
+ export declare const cloudKitEncrypted: CloudProvider;
37
+ //# sourceMappingURL=cloudKitEncrypted.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloudKitEncrypted.d.ts","sourceRoot":"","sources":["../../../../src/providers/cloudKitEncrypted.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAiB,aAAa,EAAE,MAAM,aAAU,CAAA;AA8B5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,iBAAiB,EAAE,aAyG/B,CAAA"}
@@ -0,0 +1,35 @@
1
+ import { type GoogleDriveConfig } from '../internal/googleDriveRest.js';
2
+ import type { CloudProvider, ProviderName } from '../types.js';
3
+ /**
4
+ * Google Drive `appDataFolder`, using the credentials from
5
+ * `configureGoogleDrive()`.
6
+ *
7
+ * The only provider that works identically on iOS, Android and web, which makes
8
+ * it the sensible continuous backend for cross-platform apps - CloudKit's
9
+ * Android/web path needs a periodic Apple ID re-auth, this does not.
10
+ */
11
+ export declare const googleDrive: CloudProvider;
12
+ /**
13
+ * A Drive provider with its own credentials and its own name.
14
+ *
15
+ * `configureGoogleDrive` sets one client for the whole process, which is right
16
+ * for the overwhelmingly common single-account app but leaves no way to reach
17
+ * two accounts at once - a profile switcher, a "copy my data to another
18
+ * account" flow, or a test that needs two isolated instances. Those need a
19
+ * provider that owns its config rather than reading a module-level singleton.
20
+ *
21
+ * ```ts
22
+ * const work = createGoogleDriveProvider({
23
+ * name: 'drive:work',
24
+ * getAccessToken: () => workToken(),
25
+ * })
26
+ * const store = createCloudStore({ providers: ['drive:work'] })
27
+ * store.registerProvider(work)
28
+ * ```
29
+ */
30
+ export declare function createGoogleDriveProvider(config: GoogleDriveConfig & {
31
+ name?: ProviderName;
32
+ /** How often `onRemoteChange` polls Drive's change cursor. Default 30000. */
33
+ changePollIntervalMs?: number;
34
+ }): CloudProvider;
35
+ //# sourceMappingURL=googleDrive.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"googleDrive.d.ts","sourceRoot":"","sources":["../../../../src/providers/googleDrive.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,KAAK,iBAAiB,EAAE,MAAM,gCAA6B,CAAA;AAEvF,OAAO,KAAK,EAAiB,aAAa,EAAE,YAAY,EAAqB,MAAM,aAAU,CAAA;AAyM7F;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,EAAE,aAIzB,CAAA;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,iBAAiB,GAAG;IAC1B,IAAI,CAAC,EAAE,YAAY,CAAA;IACnB,6EAA6E;IAC7E,oBAAoB,CAAC,EAAE,MAAM,CAAA;CAC9B,GACA,aAAa,CAQf"}