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.
- package/LICENSE +21 -0
- package/README.md +360 -0
- package/app.plugin.js +3 -0
- package/ios/CloudSyncError.swift +144 -0
- package/ios/CloudSyncImpl.swift +1263 -0
- package/ios/RNCloudSync.h +25 -0
- package/ios/RNCloudSync.mm +477 -0
- package/jest-mock.js +136 -0
- package/lib/commonjs/config.js +85 -0
- package/lib/commonjs/config.js.map +1 -0
- package/lib/commonjs/errors.js +244 -0
- package/lib/commonjs/errors.js.map +1 -0
- package/lib/commonjs/hooks.js +257 -0
- package/lib/commonjs/hooks.js.map +1 -0
- package/lib/commonjs/index.js +244 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/internal/autoFlush.js +65 -0
- package/lib/commonjs/internal/autoFlush.js.map +1 -0
- package/lib/commonjs/internal/base64.js +58 -0
- package/lib/commonjs/internal/base64.js.map +1 -0
- package/lib/commonjs/internal/bytes.js +32 -0
- package/lib/commonjs/internal/bytes.js.map +1 -0
- package/lib/commonjs/internal/cloudKitRest.js +527 -0
- package/lib/commonjs/internal/cloudKitRest.js.map +1 -0
- package/lib/commonjs/internal/enums.js +23 -0
- package/lib/commonjs/internal/enums.js.map +1 -0
- package/lib/commonjs/internal/googleDriveRest.js +624 -0
- package/lib/commonjs/internal/googleDriveRest.js.map +1 -0
- package/lib/commonjs/internal/keys.js +139 -0
- package/lib/commonjs/internal/keys.js.map +1 -0
- package/lib/commonjs/internal/logger.js +29 -0
- package/lib/commonjs/internal/logger.js.map +1 -0
- package/lib/commonjs/internal/nativeModule.js +125 -0
- package/lib/commonjs/internal/nativeModule.js.map +1 -0
- package/lib/commonjs/internal/timeout.js +72 -0
- package/lib/commonjs/internal/timeout.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/providers/cloudKit.js +398 -0
- package/lib/commonjs/providers/cloudKit.js.map +1 -0
- package/lib/commonjs/providers/cloudKitBackup.js +86 -0
- package/lib/commonjs/providers/cloudKitBackup.js.map +1 -0
- package/lib/commonjs/providers/cloudKitEncrypted.js +150 -0
- package/lib/commonjs/providers/cloudKitEncrypted.js.map +1 -0
- package/lib/commonjs/providers/googleDrive.js +219 -0
- package/lib/commonjs/providers/googleDrive.js.map +1 -0
- package/lib/commonjs/providers/googleDriveFiles.js +68 -0
- package/lib/commonjs/providers/googleDriveFiles.js.map +1 -0
- package/lib/commonjs/providers/icloudDocuments.js +121 -0
- package/lib/commonjs/providers/icloudDocuments.js.map +1 -0
- package/lib/commonjs/providers/icloudKV.js +171 -0
- package/lib/commonjs/providers/icloudKV.js.map +1 -0
- package/lib/commonjs/providers/icloudKV.web.js +42 -0
- package/lib/commonjs/providers/icloudKV.web.js.map +1 -0
- package/lib/commonjs/providers/memory.js +201 -0
- package/lib/commonjs/providers/memory.js.map +1 -0
- package/lib/commonjs/resolvers.js +128 -0
- package/lib/commonjs/resolvers.js.map +1 -0
- package/lib/commonjs/specs/NativeRNCloudSync.js +14 -0
- package/lib/commonjs/specs/NativeRNCloudSync.js.map +1 -0
- package/lib/commonjs/store.js +1064 -0
- package/lib/commonjs/store.js.map +1 -0
- package/lib/commonjs/testing.js +32 -0
- package/lib/commonjs/testing.js.map +1 -0
- package/lib/commonjs/types.js +86 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/module/config.js +72 -0
- package/lib/module/config.js.map +1 -0
- package/lib/module/errors.js +231 -0
- package/lib/module/errors.js.map +1 -0
- package/lib/module/hooks.js +250 -0
- package/lib/module/hooks.js.map +1 -0
- package/lib/module/index.js +46 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/internal/autoFlush.js +62 -0
- package/lib/module/internal/autoFlush.js.map +1 -0
- package/lib/module/internal/base64.js +53 -0
- package/lib/module/internal/base64.js.map +1 -0
- package/lib/module/internal/bytes.js +28 -0
- package/lib/module/internal/bytes.js.map +1 -0
- package/lib/module/internal/cloudKitRest.js +518 -0
- package/lib/module/internal/cloudKitRest.js.map +1 -0
- package/lib/module/internal/enums.js +18 -0
- package/lib/module/internal/enums.js.map +1 -0
- package/lib/module/internal/googleDriveRest.js +620 -0
- package/lib/module/internal/googleDriveRest.js.map +1 -0
- package/lib/module/internal/keys.js +134 -0
- package/lib/module/internal/keys.js.map +1 -0
- package/lib/module/internal/logger.js +23 -0
- package/lib/module/internal/logger.js.map +1 -0
- package/lib/module/internal/nativeModule.js +117 -0
- package/lib/module/internal/nativeModule.js.map +1 -0
- package/lib/module/internal/timeout.js +67 -0
- package/lib/module/internal/timeout.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/providers/cloudKit.js +392 -0
- package/lib/module/providers/cloudKit.js.map +1 -0
- package/lib/module/providers/cloudKitBackup.js +82 -0
- package/lib/module/providers/cloudKitBackup.js.map +1 -0
- package/lib/module/providers/cloudKitEncrypted.js +146 -0
- package/lib/module/providers/cloudKitEncrypted.js.map +1 -0
- package/lib/module/providers/googleDrive.js +214 -0
- package/lib/module/providers/googleDrive.js.map +1 -0
- package/lib/module/providers/googleDriveFiles.js +64 -0
- package/lib/module/providers/googleDriveFiles.js.map +1 -0
- package/lib/module/providers/icloudDocuments.js +117 -0
- package/lib/module/providers/icloudDocuments.js.map +1 -0
- package/lib/module/providers/icloudKV.js +165 -0
- package/lib/module/providers/icloudKV.js.map +1 -0
- package/lib/module/providers/icloudKV.web.js +36 -0
- package/lib/module/providers/icloudKV.web.js.map +1 -0
- package/lib/module/providers/memory.js +197 -0
- package/lib/module/providers/memory.js.map +1 -0
- package/lib/module/resolvers.js +120 -0
- package/lib/module/resolvers.js.map +1 -0
- package/lib/module/specs/NativeRNCloudSync.js +12 -0
- package/lib/module/specs/NativeRNCloudSync.js.map +1 -0
- package/lib/module/store.js +1061 -0
- package/lib/module/store.js.map +1 -0
- package/lib/module/testing.js +17 -0
- package/lib/module/testing.js.map +1 -0
- package/lib/module/types.js +82 -0
- package/lib/module/types.js.map +1 -0
- package/lib/typescript/commonjs/config.d.ts +33 -0
- package/lib/typescript/commonjs/config.d.ts.map +1 -0
- package/lib/typescript/commonjs/errors.d.ts +140 -0
- package/lib/typescript/commonjs/errors.d.ts.map +1 -0
- package/lib/typescript/commonjs/hooks.d.ts +109 -0
- package/lib/typescript/commonjs/hooks.d.ts.map +1 -0
- package/lib/typescript/commonjs/index.d.ts +37 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/internal/autoFlush.d.ts +45 -0
- package/lib/typescript/commonjs/internal/autoFlush.d.ts.map +1 -0
- package/lib/typescript/commonjs/internal/base64.d.ts +12 -0
- package/lib/typescript/commonjs/internal/base64.d.ts.map +1 -0
- package/lib/typescript/commonjs/internal/bytes.d.ts +12 -0
- package/lib/typescript/commonjs/internal/bytes.d.ts.map +1 -0
- package/lib/typescript/commonjs/internal/cloudKitRest.d.ts +149 -0
- package/lib/typescript/commonjs/internal/cloudKitRest.d.ts.map +1 -0
- package/lib/typescript/commonjs/internal/enums.d.ts +10 -0
- package/lib/typescript/commonjs/internal/enums.d.ts.map +1 -0
- package/lib/typescript/commonjs/internal/googleDriveRest.d.ts +232 -0
- package/lib/typescript/commonjs/internal/googleDriveRest.d.ts.map +1 -0
- package/lib/typescript/commonjs/internal/keys.d.ts +28 -0
- package/lib/typescript/commonjs/internal/keys.d.ts.map +1 -0
- package/lib/typescript/commonjs/internal/logger.d.ts +10 -0
- package/lib/typescript/commonjs/internal/logger.d.ts.map +1 -0
- package/lib/typescript/commonjs/internal/nativeModule.d.ts +29 -0
- package/lib/typescript/commonjs/internal/nativeModule.d.ts.map +1 -0
- package/lib/typescript/commonjs/internal/timeout.d.ts +36 -0
- package/lib/typescript/commonjs/internal/timeout.d.ts.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/providers/cloudKit.d.ts +86 -0
- package/lib/typescript/commonjs/providers/cloudKit.d.ts.map +1 -0
- package/lib/typescript/commonjs/providers/cloudKitBackup.d.ts +65 -0
- package/lib/typescript/commonjs/providers/cloudKitBackup.d.ts.map +1 -0
- package/lib/typescript/commonjs/providers/cloudKitEncrypted.d.ts +37 -0
- package/lib/typescript/commonjs/providers/cloudKitEncrypted.d.ts.map +1 -0
- package/lib/typescript/commonjs/providers/googleDrive.d.ts +35 -0
- package/lib/typescript/commonjs/providers/googleDrive.d.ts.map +1 -0
- package/lib/typescript/commonjs/providers/googleDriveFiles.d.ts +59 -0
- package/lib/typescript/commonjs/providers/googleDriveFiles.d.ts.map +1 -0
- package/lib/typescript/commonjs/providers/icloudDocuments.d.ts +101 -0
- package/lib/typescript/commonjs/providers/icloudDocuments.d.ts.map +1 -0
- package/lib/typescript/commonjs/providers/icloudKV.d.ts +26 -0
- package/lib/typescript/commonjs/providers/icloudKV.d.ts.map +1 -0
- package/lib/typescript/commonjs/providers/icloudKV.web.d.ts +12 -0
- package/lib/typescript/commonjs/providers/icloudKV.web.d.ts.map +1 -0
- package/lib/typescript/commonjs/providers/memory.d.ts +90 -0
- package/lib/typescript/commonjs/providers/memory.d.ts.map +1 -0
- package/lib/typescript/commonjs/resolvers.d.ts +60 -0
- package/lib/typescript/commonjs/resolvers.d.ts.map +1 -0
- package/lib/typescript/commonjs/specs/NativeRNCloudSync.d.ts +133 -0
- package/lib/typescript/commonjs/specs/NativeRNCloudSync.d.ts.map +1 -0
- package/lib/typescript/commonjs/store.d.ts +118 -0
- package/lib/typescript/commonjs/store.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing.d.ts +16 -0
- package/lib/typescript/commonjs/testing.d.ts.map +1 -0
- package/lib/typescript/commonjs/types.d.ts +367 -0
- package/lib/typescript/commonjs/types.d.ts.map +1 -0
- package/lib/typescript/module/config.d.ts +33 -0
- package/lib/typescript/module/config.d.ts.map +1 -0
- package/lib/typescript/module/errors.d.ts +140 -0
- package/lib/typescript/module/errors.d.ts.map +1 -0
- package/lib/typescript/module/hooks.d.ts +109 -0
- package/lib/typescript/module/hooks.d.ts.map +1 -0
- package/lib/typescript/module/index.d.ts +37 -0
- package/lib/typescript/module/index.d.ts.map +1 -0
- package/lib/typescript/module/internal/autoFlush.d.ts +45 -0
- package/lib/typescript/module/internal/autoFlush.d.ts.map +1 -0
- package/lib/typescript/module/internal/base64.d.ts +12 -0
- package/lib/typescript/module/internal/base64.d.ts.map +1 -0
- package/lib/typescript/module/internal/bytes.d.ts +12 -0
- package/lib/typescript/module/internal/bytes.d.ts.map +1 -0
- package/lib/typescript/module/internal/cloudKitRest.d.ts +149 -0
- package/lib/typescript/module/internal/cloudKitRest.d.ts.map +1 -0
- package/lib/typescript/module/internal/enums.d.ts +10 -0
- package/lib/typescript/module/internal/enums.d.ts.map +1 -0
- package/lib/typescript/module/internal/googleDriveRest.d.ts +232 -0
- package/lib/typescript/module/internal/googleDriveRest.d.ts.map +1 -0
- package/lib/typescript/module/internal/keys.d.ts +28 -0
- package/lib/typescript/module/internal/keys.d.ts.map +1 -0
- package/lib/typescript/module/internal/logger.d.ts +10 -0
- package/lib/typescript/module/internal/logger.d.ts.map +1 -0
- package/lib/typescript/module/internal/nativeModule.d.ts +29 -0
- package/lib/typescript/module/internal/nativeModule.d.ts.map +1 -0
- package/lib/typescript/module/internal/timeout.d.ts +36 -0
- package/lib/typescript/module/internal/timeout.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/providers/cloudKit.d.ts +86 -0
- package/lib/typescript/module/providers/cloudKit.d.ts.map +1 -0
- package/lib/typescript/module/providers/cloudKitBackup.d.ts +65 -0
- package/lib/typescript/module/providers/cloudKitBackup.d.ts.map +1 -0
- package/lib/typescript/module/providers/cloudKitEncrypted.d.ts +37 -0
- package/lib/typescript/module/providers/cloudKitEncrypted.d.ts.map +1 -0
- package/lib/typescript/module/providers/googleDrive.d.ts +35 -0
- package/lib/typescript/module/providers/googleDrive.d.ts.map +1 -0
- package/lib/typescript/module/providers/googleDriveFiles.d.ts +59 -0
- package/lib/typescript/module/providers/googleDriveFiles.d.ts.map +1 -0
- package/lib/typescript/module/providers/icloudDocuments.d.ts +101 -0
- package/lib/typescript/module/providers/icloudDocuments.d.ts.map +1 -0
- package/lib/typescript/module/providers/icloudKV.d.ts +26 -0
- package/lib/typescript/module/providers/icloudKV.d.ts.map +1 -0
- package/lib/typescript/module/providers/icloudKV.web.d.ts +12 -0
- package/lib/typescript/module/providers/icloudKV.web.d.ts.map +1 -0
- package/lib/typescript/module/providers/memory.d.ts +90 -0
- package/lib/typescript/module/providers/memory.d.ts.map +1 -0
- package/lib/typescript/module/resolvers.d.ts +60 -0
- package/lib/typescript/module/resolvers.d.ts.map +1 -0
- package/lib/typescript/module/specs/NativeRNCloudSync.d.ts +133 -0
- package/lib/typescript/module/specs/NativeRNCloudSync.d.ts.map +1 -0
- package/lib/typescript/module/store.d.ts +118 -0
- package/lib/typescript/module/store.d.ts.map +1 -0
- package/lib/typescript/module/testing.d.ts +16 -0
- package/lib/typescript/module/testing.d.ts.map +1 -0
- package/lib/typescript/module/types.d.ts +367 -0
- package/lib/typescript/module/types.d.ts.map +1 -0
- package/package.json +186 -0
- package/plugin/build/index.d.ts +45 -0
- package/plugin/build/index.js +93 -0
- package/react-native-cloud-sync.podspec +48 -0
- package/src/config.ts +94 -0
- package/src/errors.ts +263 -0
- package/src/hooks.ts +337 -0
- package/src/index.ts +113 -0
- package/src/internal/autoFlush.ts +87 -0
- package/src/internal/base64.ts +63 -0
- package/src/internal/bytes.ts +28 -0
- package/src/internal/cloudKitRest.ts +654 -0
- package/src/internal/enums.ts +35 -0
- package/src/internal/googleDriveRest.ts +765 -0
- package/src/internal/keys.ts +160 -0
- package/src/internal/logger.ts +23 -0
- package/src/internal/nativeModule.ts +149 -0
- package/src/internal/timeout.ts +83 -0
- package/src/providers/cloudKit.ts +510 -0
- package/src/providers/cloudKitBackup.ts +124 -0
- package/src/providers/cloudKitEncrypted.ts +175 -0
- package/src/providers/googleDrive.ts +251 -0
- package/src/providers/googleDriveFiles.ts +117 -0
- package/src/providers/icloudDocuments.ts +175 -0
- package/src/providers/icloudKV.ts +206 -0
- package/src/providers/icloudKV.web.ts +41 -0
- package/src/providers/memory.ts +302 -0
- package/src/resolvers.ts +133 -0
- package/src/specs/NativeRNCloudSync.ts +184 -0
- package/src/store.ts +1288 -0
- package/src/testing.ts +22 -0
- package/src/types.ts +426 -0
|
@@ -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';
|
|
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,UAAU,CAAA;AA8B5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,iBAAiB,EAAE,aAyG/B,CAAA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type GoogleDriveConfig } from '../internal/googleDriveRest';
|
|
2
|
+
import type { CloudProvider, ProviderName } from '../types';
|
|
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,6BAA6B,CAAA;AAEvF,OAAO,KAAK,EAAiB,aAAa,EAAE,YAAY,EAAqB,MAAM,UAAU,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"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { AbortLike } from '../internal/timeout';
|
|
2
|
+
export interface DriveFileProgressEvent {
|
|
3
|
+
bytesTransferred: number;
|
|
4
|
+
bytesTotal: number;
|
|
5
|
+
/** `bytesTransferred / bytesTotal`, or 0 while `bytesTotal` is still 0. */
|
|
6
|
+
fraction: number;
|
|
7
|
+
}
|
|
8
|
+
export interface DriveFileSaveOptions {
|
|
9
|
+
/** Called repeatedly while the upload is in flight. */
|
|
10
|
+
onProgress?: (e: DriveFileProgressEvent) => void;
|
|
11
|
+
/**
|
|
12
|
+
* Cancels the transfer, rejecting with `ERR_CANCELLED`.
|
|
13
|
+
*
|
|
14
|
+
* Checked between chunks, so a cancel takes effect during the transfer rather
|
|
15
|
+
* than only once the whole file has moved - which is the entire point when
|
|
16
|
+
* the file is several hundred megabytes. Bytes already accepted stay in the
|
|
17
|
+
* resumable session; a later `save` of the same name starts a fresh one.
|
|
18
|
+
*
|
|
19
|
+
* Typed structurally rather than as the DOM `AbortSignal`, so any polyfill
|
|
20
|
+
* works and consumers do not need `lib.dom` in their tsconfig.
|
|
21
|
+
*/
|
|
22
|
+
signal?: AbortLike;
|
|
23
|
+
}
|
|
24
|
+
export interface DriveFileFetchOptions {
|
|
25
|
+
/** Called repeatedly while the download is in flight. */
|
|
26
|
+
onProgress?: (e: DriveFileProgressEvent) => void;
|
|
27
|
+
/** Cancels the transfer, rejecting with `ERR_CANCELLED`. Checked between chunks. */
|
|
28
|
+
signal?: AbortLike;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Binary files in Drive's `appDataFolder`, for anything too large to hold in
|
|
32
|
+
* memory as a JS string the way `googleDrive.setItem` does - the Android/web
|
|
33
|
+
* equivalent of `cloudKitAssets`' `CKAsset` on Apple platforms.
|
|
34
|
+
*
|
|
35
|
+
* Uploads use Drive's resumable protocol, reading the source in fixed chunks;
|
|
36
|
+
* downloads write in the same fixed chunks. Neither ever holds more than one
|
|
37
|
+
* chunk (8 MiB by default) in memory. Both go through a `GoogleDriveFileAdapter`
|
|
38
|
+
* (`configureGoogleDriveFiles`) for the actual disk I/O - this package has no
|
|
39
|
+
* filesystem dependency of its own, so the host app supplies one using
|
|
40
|
+
* whichever fs library it already has. See the CloudKit/Google Drive guides
|
|
41
|
+
* for the file adapter's exact contract and setup examples.
|
|
42
|
+
*/
|
|
43
|
+
export declare const googleDriveFiles: {
|
|
44
|
+
/** Uploads `fileUri` as `name`, overwriting whatever was there. */
|
|
45
|
+
save: (options: {
|
|
46
|
+
name: string;
|
|
47
|
+
fileUri: string;
|
|
48
|
+
} & DriveFileSaveOptions) => Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Downloads `name` into `destinationUri`, resolving `destinationUri` back
|
|
51
|
+
* once complete, or `null` when no such file exists - `destinationUri` is
|
|
52
|
+
* never touched in that case.
|
|
53
|
+
*/
|
|
54
|
+
fetch: (options: {
|
|
55
|
+
name: string;
|
|
56
|
+
destinationUri: string;
|
|
57
|
+
} & DriveFileFetchOptions) => Promise<string | null>;
|
|
58
|
+
};
|
|
59
|
+
//# sourceMappingURL=googleDriveFiles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"googleDriveFiles.d.ts","sourceRoot":"","sources":["../../../../src/providers/googleDriveFiles.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAIpD,MAAM,WAAW,sBAAsB;IACrC,gBAAgB,EAAE,MAAM,CAAA;IACxB,UAAU,EAAE,MAAM,CAAA;IAClB,2EAA2E;IAC3E,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,oBAAoB;IACnC,uDAAuD;IACvD,UAAU,CAAC,EAAE,CAAC,CAAC,EAAE,sBAAsB,KAAK,IAAI,CAAA;IAChD;;;;;;;;;;OAUG;IACH,MAAM,CAAC,EAAE,SAAS,CAAA;CACnB;AAED,MAAM,WAAW,qBAAqB;IACpC,yDAAyD;IACzD,UAAU,CAAC,EAAE,CAAC,CAAC,EAAE,sBAAsB,KAAK,IAAI,CAAA;IAChD,oFAAoF;IACpF,MAAM,CAAC,EAAE,SAAS,CAAA;CACnB;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,gBAAgB;IAC3B,mEAAmE;oBAExD;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,oBAAoB,KAChE,OAAO,CAAC,IAAI,CAAC;IAoBhB;;;;OAIG;qBAEQ;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,MAAM,CAAA;KAAE,GAAG,qBAAqB,KACxE,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;CAqB1B,CAAA"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
export interface DocumentEntry {
|
|
2
|
+
name: string;
|
|
3
|
+
sizeBytes: number;
|
|
4
|
+
/**
|
|
5
|
+
* False when the file exists in the account but has no local copy on this
|
|
6
|
+
* device.
|
|
7
|
+
*
|
|
8
|
+
* The distinction that makes iCloud Drive different from a normal directory:
|
|
9
|
+
* a listing shows files this device has never downloaded, and reading one
|
|
10
|
+
* without calling {@link icloudDocuments.fetch} first gives you nothing.
|
|
11
|
+
*/
|
|
12
|
+
isDownloaded: boolean;
|
|
13
|
+
isDownloading: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface DocumentFetchOptions {
|
|
16
|
+
/**
|
|
17
|
+
* Copy the file here once it is downloaded, and resolve this path instead of
|
|
18
|
+
* the in-container one.
|
|
19
|
+
*
|
|
20
|
+
* Worth doing for anything you intend to keep: the system may evict a
|
|
21
|
+
* downloaded copy from the container to reclaim space, turning it back into a
|
|
22
|
+
* placeholder.
|
|
23
|
+
*/
|
|
24
|
+
destinationUri?: string;
|
|
25
|
+
/**
|
|
26
|
+
* How long to wait for the download. Default 60000.
|
|
27
|
+
*
|
|
28
|
+
* A timeout is not a failure of the transfer - iOS keeps downloading in the
|
|
29
|
+
* background - so `ERR_TIMEOUT` here means "not yet", and it is classified as
|
|
30
|
+
* retryable for exactly that reason.
|
|
31
|
+
*/
|
|
32
|
+
timeoutMs?: number;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Files in the user's own iCloud Drive.
|
|
36
|
+
*
|
|
37
|
+
* This is the one thing no `CKRecord` or `CKAsset` API can do, and the most
|
|
38
|
+
* common iCloud request in mobile apps: *put this file where the user can find
|
|
39
|
+
* it*. A `CKAsset` lives in the app's private CloudKit database - the user
|
|
40
|
+
* cannot see it, open it, or hand it to another app. A file written here lands
|
|
41
|
+
* in the app's folder in iCloud Drive, visible in Files.app, syncing to every
|
|
42
|
+
* device signed into the same Apple ID, and surviving the app being deleted.
|
|
43
|
+
*
|
|
44
|
+
* Requirements beyond the CloudKit entitlement:
|
|
45
|
+
*
|
|
46
|
+
* - the **iCloud Documents** service on the container (the config plugin's
|
|
47
|
+
* `iCloudDocuments: true` option adds it);
|
|
48
|
+
* - an `NSUbiquitousContainers` Info.plist entry with
|
|
49
|
+
* `NSUbiquitousContainerIsDocumentScopePublic` set, or the folder syncs but
|
|
50
|
+
* stays invisible in Files.app. The plugin writes this too.
|
|
51
|
+
*
|
|
52
|
+
* Apple platforms only, and unlike the other providers that is not a gap to be
|
|
53
|
+
* filled later: there is no REST surface for iCloud Drive and no browser API.
|
|
54
|
+
* Use {@link googleDriveFiles} for user-visible files elsewhere.
|
|
55
|
+
*
|
|
56
|
+
* Not a {@link CloudProvider}: the contract there is keys to string values, and
|
|
57
|
+
* this moves files by path. Same reason `cloudKitAssets` is its own API.
|
|
58
|
+
*/
|
|
59
|
+
export declare const icloudDocuments: {
|
|
60
|
+
/** Whether this device has a usable iCloud Drive container right now. */
|
|
61
|
+
isAvailable: () => Promise<boolean>;
|
|
62
|
+
/**
|
|
63
|
+
* Copies a local file into iCloud Drive under `name`, replacing whatever was
|
|
64
|
+
* there. Resolves the resulting iCloud path.
|
|
65
|
+
*
|
|
66
|
+
* Resolving means "handed to iCloud", not "in the cloud" - the system uploads
|
|
67
|
+
* in the background whether or not the app is running. Same distinction as
|
|
68
|
+
* `icloudKVSync()`, and for the same reason: there is no API that waits for
|
|
69
|
+
* the upload.
|
|
70
|
+
*/
|
|
71
|
+
save: (options: {
|
|
72
|
+
fileUri: string;
|
|
73
|
+
name: string;
|
|
74
|
+
}) => Promise<string>;
|
|
75
|
+
/**
|
|
76
|
+
* Downloads `name` if this device does not have it yet, then resolves a local
|
|
77
|
+
* path - or `null` when no such file exists in the account.
|
|
78
|
+
*
|
|
79
|
+
* The download step is the point. A file listed by {@link list} may be a
|
|
80
|
+
* placeholder with no local bytes, and opening that gives you an empty file
|
|
81
|
+
* rather than an error.
|
|
82
|
+
*
|
|
83
|
+
* Byte-level progress is not reported: that needs an `NSMetadataQuery`, which
|
|
84
|
+
* needs a live run loop, and this runs off the main thread on purpose. Use
|
|
85
|
+
* {@link list} to poll `isDownloading` if you need to show something.
|
|
86
|
+
*/
|
|
87
|
+
fetch: (options: {
|
|
88
|
+
name: string;
|
|
89
|
+
} & DocumentFetchOptions) => Promise<string | null>;
|
|
90
|
+
/**
|
|
91
|
+
* Everything in the app's iCloud Drive folder, including files this device
|
|
92
|
+
* has not downloaded.
|
|
93
|
+
*/
|
|
94
|
+
list: () => Promise<DocumentEntry[]>;
|
|
95
|
+
/**
|
|
96
|
+
* Deletes a file from iCloud Drive - on every device, and from the user's
|
|
97
|
+
* Files.app. Resolves false when it was already gone.
|
|
98
|
+
*/
|
|
99
|
+
remove: (name: string) => Promise<boolean>;
|
|
100
|
+
};
|
|
101
|
+
//# sourceMappingURL=icloudDocuments.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"icloudDocuments.d.ts","sourceRoot":"","sources":["../../../../src/providers/icloudDocuments.ts"],"names":[],"mappings":"AA0BA,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,CAAA;IACjB;;;;;;;OAOG;IACH,YAAY,EAAE,OAAO,CAAA;IACrB,aAAa,EAAE,OAAO,CAAA;CACvB;AAED,MAAM,WAAW,oBAAoB;IACnC;;;;;;;OAOG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,eAAe;IAC1B,yEAAyE;uBAClD,OAAO,CAAC,OAAO,CAAC;IAYvC;;;;;;;;OAQG;oBACmB;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,KAAG,OAAO,CAAC,MAAM,CAAC;IAUzE;;;;;;;;;;;OAWG;qBAEQ;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,oBAAoB,KAC/C,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAczB;;;OAGG;gBACa,OAAO,CAAC,aAAa,EAAE,CAAC;IAUxC;;;OAGG;mBACkB,MAAM,KAAG,OAAO,CAAC,OAAO,CAAC;CAS/C,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { CloudProvider } from '../types';
|
|
2
|
+
export declare const icloudKV: CloudProvider;
|
|
3
|
+
/**
|
|
4
|
+
* Every key and value in the store, in one call.
|
|
5
|
+
*
|
|
6
|
+
* Not part of the {@link CloudProvider} contract, because no other provider can
|
|
7
|
+
* do it cheaply - CloudKit and Drive would both have to fetch every record.
|
|
8
|
+
* Here the whole store is already a local dictionary, so this is one bridge hop
|
|
9
|
+
* against the N+1 that `getAllKeys()` plus a read per key would cost.
|
|
10
|
+
*
|
|
11
|
+
* Values the store holds as something other than a string (it also accepts
|
|
12
|
+
* numbers, dates and data) are omitted rather than coerced, since a
|
|
13
|
+
* stringified number would not round-trip back through `setItem`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getAllItems(): Promise<Record<string, string>>;
|
|
16
|
+
/**
|
|
17
|
+
* Flushes pending changes to disk.
|
|
18
|
+
*
|
|
19
|
+
* Exposed separately because it is not part of the generic {@link CloudProvider}
|
|
20
|
+
* contract - and because its semantics are routinely misread. It maps to
|
|
21
|
+
* `NSUbiquitousKeyValueStore.synchronize()`, which schedules an upload; it does
|
|
22
|
+
* not wait for or confirm one. A resolved `sync()` means "queued", never
|
|
23
|
+
* "stored in iCloud".
|
|
24
|
+
*/
|
|
25
|
+
export declare function sync(): Promise<boolean>;
|
|
26
|
+
//# sourceMappingURL=icloudKV.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"icloudKV.d.ts","sourceRoot":"","sources":["../../../../src/providers/icloudKV.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAGV,aAAa,EAGd,MAAM,UAAU,CAAA;AA2CjB,eAAO,MAAM,QAAQ,EAAE,aA2GtB,CAAA;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAQnE;AAED;;;;;;;;GAQG;AACH,wBAAsB,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC,CAQ7C"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CloudProvider } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Web build of the iCloud key-value provider.
|
|
4
|
+
*
|
|
5
|
+
* Every operation rejects with `ERR_UNSUPPORTED_PLATFORM` rather than resolving
|
|
6
|
+
* `null` or silently no-oping, so a web build fails loudly at the call site
|
|
7
|
+
* instead of appearing to work and quietly dropping data.
|
|
8
|
+
*/
|
|
9
|
+
export declare const icloudKV: CloudProvider;
|
|
10
|
+
export declare function sync(): Promise<boolean>;
|
|
11
|
+
export declare function getAllItems(): Promise<Record<string, string>>;
|
|
12
|
+
//# sourceMappingURL=icloudKV.web.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"icloudKV.web.d.ts","sourceRoot":"","sources":["../../../../src/providers/icloudKV.web.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAiB,aAAa,EAAE,MAAM,UAAU,CAAA;AAY5D;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,EAAE,aAYtB,CAAA;AAED,wBAAgB,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC,CAEvC;AAED,wBAAgB,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAE7D"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { ErrorCode } from '../errors';
|
|
2
|
+
import type { AccountChangeEvent, AccountStatus, CloudProvider, RemoteChangeEvent } from '../types';
|
|
3
|
+
export type FaultOp = 'getItem' | 'setItem' | 'removeItem' | 'getAllKeys' | 'getAccountStatus';
|
|
4
|
+
export interface Fault {
|
|
5
|
+
code: ErrorCode;
|
|
6
|
+
message?: string;
|
|
7
|
+
retryAfterMs?: number;
|
|
8
|
+
limitBytes?: number;
|
|
9
|
+
actualBytes?: number;
|
|
10
|
+
serverValue?: string | null;
|
|
11
|
+
/**
|
|
12
|
+
* Fail only this many times, then succeed. Useful for asserting that retry and
|
|
13
|
+
* outbox logic converges instead of looping.
|
|
14
|
+
*/
|
|
15
|
+
times?: number;
|
|
16
|
+
/**
|
|
17
|
+
* Fail only for keys this returns true for. Defaults to every key.
|
|
18
|
+
*
|
|
19
|
+
* Real backends fail per record, not per operation - one oversized or
|
|
20
|
+
* conflicting key while the rest of a batch goes through. Scoping a fault to
|
|
21
|
+
* a key is also what makes interleaving tests deterministic, since two
|
|
22
|
+
* operations in flight no longer compete for the same `times` budget.
|
|
23
|
+
*/
|
|
24
|
+
only?: (key: string) => boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface MemoryProviderOptions {
|
|
27
|
+
/** Seed data the provider starts with. */
|
|
28
|
+
initial?: Record<string, string>;
|
|
29
|
+
/** Per-operation failures to inject. */
|
|
30
|
+
faults?: Partial<Record<FaultOp, Fault>>;
|
|
31
|
+
/** Account status reported by `getAccountStatus`. Defaults to `available`. */
|
|
32
|
+
accountStatus?: AccountStatus;
|
|
33
|
+
/** Artificial delay in ms applied to every operation. */
|
|
34
|
+
latencyMs?: number;
|
|
35
|
+
/**
|
|
36
|
+
* What `isAvailable()` reports. Defaults to true.
|
|
37
|
+
*
|
|
38
|
+
* Set false to reproduce the signed-out fleet - the case where the store must
|
|
39
|
+
* refuse to answer a read rather than resolving `null`, because `null` there
|
|
40
|
+
* reads as "no backup exists" and the documented first-launch recipe seeds
|
|
41
|
+
* empty state over the user's real data.
|
|
42
|
+
*/
|
|
43
|
+
available?: boolean;
|
|
44
|
+
/** A name other than `'memory'`, for tests that need two distinct doubles. */
|
|
45
|
+
name?: string;
|
|
46
|
+
/** Quota reported by `getQuota()`. Omitted means the provider reports none. */
|
|
47
|
+
quota?: {
|
|
48
|
+
usedBytes?: number;
|
|
49
|
+
totalBytes?: number;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/** A provider name other than the four built in. Used to type custom doubles. */
|
|
53
|
+
export type MemoryProviderName = string;
|
|
54
|
+
export interface MemoryProvider extends CloudProvider {
|
|
55
|
+
/** Direct read of the backing map, bypassing fault injection. */
|
|
56
|
+
dump: () => Record<string, string>;
|
|
57
|
+
/** Replace the backing data without going through `setItem`. */
|
|
58
|
+
seed: (data: Record<string, string>) => void;
|
|
59
|
+
/** Clear data, faults and listeners. */
|
|
60
|
+
reset: () => void;
|
|
61
|
+
/** Install or replace a fault at runtime. */
|
|
62
|
+
setFault: (op: FaultOp, fault: Fault | null) => void;
|
|
63
|
+
/** Fire a remote-change event, as if another device had written. */
|
|
64
|
+
emitRemoteChange: (e: Partial<RemoteChangeEvent>) => void;
|
|
65
|
+
/** Fire an account-change event, including the identity-switch case. */
|
|
66
|
+
emitAccountChange: (e: Partial<AccountChangeEvent>) => void;
|
|
67
|
+
/** Flip what `isAvailable()` reports, to simulate signing out mid-session. */
|
|
68
|
+
setAvailable: (value: boolean) => void;
|
|
69
|
+
/** How many times each operation has been called. */
|
|
70
|
+
readonly calls: Readonly<Record<FaultOp, number>>;
|
|
71
|
+
/** How many times the store asked this provider to drop cached state. */
|
|
72
|
+
readonly cacheClears: number;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* An in-memory provider with fault injection.
|
|
76
|
+
*
|
|
77
|
+
* This exists because cloud storage is the hardest thing in a mobile app to test
|
|
78
|
+
* honestly. iCloud on the simulator is unreliable enough that the most-used
|
|
79
|
+
* library in this space gave up on it publicly - "We've therefore stopped
|
|
80
|
+
* testing the library on the simulator and test on a real device only and would
|
|
81
|
+
* encourage users to do the same." Real-device-only testing means the failure
|
|
82
|
+
* paths that matter most (signed out, offline, quota exceeded, rate limited,
|
|
83
|
+
* account switched mid-session) are effectively never exercised.
|
|
84
|
+
*
|
|
85
|
+
* So they are exercised here instead, deterministically, in Jest. This is
|
|
86
|
+
* exported from the package entry (`react-native-cloud-sync/testing`)
|
|
87
|
+
* rather than buried in source, so it is usable without reaching into internals.
|
|
88
|
+
*/
|
|
89
|
+
export declare function createMemoryProvider(options?: MemoryProviderOptions): MemoryProvider;
|
|
90
|
+
//# sourceMappingURL=memory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../../../src/providers/memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,SAAS,EAAE,MAAM,WAAW,CAAA;AACrD,OAAO,KAAK,EACV,kBAAkB,EAClB,aAAa,EACb,aAAa,EACb,iBAAiB,EAElB,MAAM,UAAU,CAAA;AAIjB,MAAM,MAAM,OAAO,GAAG,SAAS,GAAG,SAAS,GAAG,YAAY,GAAG,YAAY,GAAG,kBAAkB,CAAA;AAQ9F,MAAM,WAAW,KAAK;IACpB,IAAI,EAAE,SAAS,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;;;;;;OAOG;IACH,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAA;CAChC;AAED,MAAM,WAAW,qBAAqB;IACpC,0CAA0C;IAC1C,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,wCAAwC;IACxC,MAAM,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAA;IACxC,8EAA8E;IAC9E,aAAa,CAAC,EAAE,aAAa,CAAA;IAC7B,yDAAyD;IACzD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,8EAA8E;IAC9E,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,+EAA+E;IAC/E,KAAK,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CACpD;AAED,iFAAiF;AACjF,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAA;AAEvC,MAAM,WAAW,cAAe,SAAQ,aAAa;IACnD,iEAAiE;IACjE,IAAI,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAClC,gEAAgE;IAChE,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,IAAI,CAAA;IAC5C,wCAAwC;IACxC,KAAK,EAAE,MAAM,IAAI,CAAA;IACjB,6CAA6C;IAC7C,QAAQ,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI,KAAK,IAAI,CAAA;IACpD,oEAAoE;IACpE,gBAAgB,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,KAAK,IAAI,CAAA;IACzD,wEAAwE;IACxE,iBAAiB,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,KAAK,IAAI,CAAA;IAC3D,8EAA8E;IAC9E,YAAY,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;IACtC,qDAAqD;IACrD,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAA;IACjD,yEAAyE;IACzE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;CAC7B;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,GAAE,qBAA0B,GAAG,cAAc,CAoMxF"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { ResolveFn } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Resolves by a numeric timestamp inside a JSON value.
|
|
4
|
+
*
|
|
5
|
+
* The common shape by far: values are JSON objects carrying `updatedAt` (or
|
|
6
|
+
* similar), and the newest wins. Candidates that are not JSON, or that lack the
|
|
7
|
+
* field, lose to any that have it - a value you cannot date is not evidence
|
|
8
|
+
* against one you can.
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* createCloudStore({
|
|
12
|
+
* providers: ['icloudKV', 'googleDrive'],
|
|
13
|
+
* writeMode: 'mirror',
|
|
14
|
+
* resolve: resolveByTimestamp('updatedAt'),
|
|
15
|
+
* })
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function resolveByTimestamp(field?: string): ResolveFn;
|
|
19
|
+
/** Always takes the first provider that has a value. The default behaviour. */
|
|
20
|
+
export declare const resolveByPreferenceOrder: ResolveFn;
|
|
21
|
+
/**
|
|
22
|
+
* Resolves by the *server's* last-modified time rather than a timestamp inside
|
|
23
|
+
* the value.
|
|
24
|
+
*
|
|
25
|
+
* {@link resolveByTimestamp} requires every value to be JSON carrying a field
|
|
26
|
+
* the app remembered to update - a real constraint, and one that silently fails
|
|
27
|
+
* open the day someone writes a plain string or forgets to bump `updatedAt`.
|
|
28
|
+
* Both CloudKit (`modified.timestamp`) and Drive (`modifiedTime`) already
|
|
29
|
+
* report a modification time, one query parameter away, so this orders on that
|
|
30
|
+
* instead and works on payloads the app never had to instrument.
|
|
31
|
+
*
|
|
32
|
+
* The catch, and the reason this is not the default: `NSUbiquitousKeyValueStore`
|
|
33
|
+
* exposes no per-key timestamp at all, so an `icloudKV` candidate never carries
|
|
34
|
+
* one. Pass `fallback` to say what should happen then - by default an undated
|
|
35
|
+
* candidate loses to any dated one, and preference order breaks a tie among
|
|
36
|
+
* undated ones.
|
|
37
|
+
*
|
|
38
|
+
* ```ts
|
|
39
|
+
* createCloudStore({
|
|
40
|
+
* providers: ['cloudKit', 'googleDrive'], // both report server time
|
|
41
|
+
* writeMode: 'mirror',
|
|
42
|
+
* resolve: resolveByModifiedAt(),
|
|
43
|
+
* })
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function resolveByModifiedAt(options?: {
|
|
47
|
+
fallback?: ResolveFn;
|
|
48
|
+
}): ResolveFn;
|
|
49
|
+
/**
|
|
50
|
+
* Tries each resolver in turn and takes the first non-null answer.
|
|
51
|
+
*
|
|
52
|
+
* The practical combination for a mixed fleet: server time where the provider
|
|
53
|
+
* reports it, an embedded timestamp where it does not.
|
|
54
|
+
*
|
|
55
|
+
* ```ts
|
|
56
|
+
* resolveFirstOf(resolveByModifiedAt(), resolveByTimestamp('updatedAt'))
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare function resolveFirstOf(...resolvers: ResolveFn[]): ResolveFn;
|
|
60
|
+
//# sourceMappingURL=resolvers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolvers.d.ts","sourceRoot":"","sources":["../../../src/resolvers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAoB,SAAS,EAAE,MAAM,SAAS,CAAA;AAE1D;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,SAAc,GAAG,SAAS,CAqBjE;AAoBD,+EAA+E;AAC/E,eAAO,MAAM,wBAAwB,EAAE,SACa,CAAA;AAEpD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,GAAE;IAAE,QAAQ,CAAC,EAAE,SAAS,CAAA;CAAO,GACrC,SAAS,CAsBX;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,GAAG,SAAS,EAAE,SAAS,EAAE,GAAG,SAAS,CAQnE"}
|