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,219 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createGoogleDriveProvider = createGoogleDriveProvider;
|
|
7
|
+
exports.googleDrive = void 0;
|
|
8
|
+
var _config = require("../config.js");
|
|
9
|
+
var _googleDriveRest = require("../internal/googleDriveRest.js");
|
|
10
|
+
var _errors = require("../errors.js");
|
|
11
|
+
const NAME = 'googleDrive';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* How often the change cursor is polled once something subscribes.
|
|
15
|
+
*
|
|
16
|
+
* 30s is a compromise: fast enough that a second device feels responsive,
|
|
17
|
+
* slow enough that a backgrounded app is not spending battery on a feed that
|
|
18
|
+
* is usually empty.
|
|
19
|
+
*/
|
|
20
|
+
const DEFAULT_POLL_INTERVAL_MS = 30_000;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Builds a Drive provider over whichever client `getClient` returns.
|
|
24
|
+
*
|
|
25
|
+
* Written as a factory so the package-level singleton and the per-instance
|
|
26
|
+
* providers from {@link createGoogleDriveProvider} share one implementation
|
|
27
|
+
* instead of two copies that drift.
|
|
28
|
+
*/
|
|
29
|
+
function makeDriveProvider(name, getClient, isConfigured, pollIntervalMs = DEFAULT_POLL_INTERVAL_MS) {
|
|
30
|
+
const provider = {
|
|
31
|
+
name,
|
|
32
|
+
isAvailable: async () => {
|
|
33
|
+
if (!isConfigured()) return false;
|
|
34
|
+
try {
|
|
35
|
+
// Only checks that a token can be obtained. Deliberately does not list
|
|
36
|
+
// files - `isAvailable` is safe to call on a render path, and a full
|
|
37
|
+
// listing is a paginated network round trip.
|
|
38
|
+
return await getClient().hasToken();
|
|
39
|
+
} catch {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
getAccountStatus: () => Promise.resolve(isConfigured() ? 'available' : 'noAccount'),
|
|
44
|
+
getItem: async key => {
|
|
45
|
+
try {
|
|
46
|
+
return await getClient().getItem(key);
|
|
47
|
+
} catch (e) {
|
|
48
|
+
throw (0, _errors.normalizeError)(e, name);
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
getItemWithMeta: async key => {
|
|
52
|
+
try {
|
|
53
|
+
return await getClient().getItemWithMeta(key);
|
|
54
|
+
} catch (e) {
|
|
55
|
+
throw (0, _errors.normalizeError)(e, name);
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
setItem: async (key, value) => {
|
|
59
|
+
try {
|
|
60
|
+
await getClient().setItem(key, value);
|
|
61
|
+
} catch (e) {
|
|
62
|
+
throw (0, _errors.normalizeError)(e, name);
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
removeItem: async key => {
|
|
66
|
+
try {
|
|
67
|
+
await getClient().removeItem(key);
|
|
68
|
+
} catch (e) {
|
|
69
|
+
throw (0, _errors.normalizeError)(e, name);
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
getAllKeys: async () => {
|
|
73
|
+
try {
|
|
74
|
+
return await getClient().getAllKeys();
|
|
75
|
+
} catch (e) {
|
|
76
|
+
throw (0, _errors.normalizeError)(e, name);
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
/**
|
|
80
|
+
* Storage usage for the Google account.
|
|
81
|
+
*
|
|
82
|
+
* Drive reports no per-folder figure, so this is the whole account's -
|
|
83
|
+
* which is the number that matters anyway, since that is the limit a write
|
|
84
|
+
* actually hits. `totalBytes` is absent on pooled/unlimited accounts.
|
|
85
|
+
*/
|
|
86
|
+
getQuota: async () => {
|
|
87
|
+
try {
|
|
88
|
+
return {
|
|
89
|
+
...(await getClient().getQuota()),
|
|
90
|
+
provider: name
|
|
91
|
+
};
|
|
92
|
+
} catch (e) {
|
|
93
|
+
throw (0, _errors.normalizeError)(e, name);
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
// Deliberately no multiGet/multiSet: Drive stores one file per key and has
|
|
97
|
+
// no batch endpoint for content (the JSON-RPC batch endpoint was retired in
|
|
98
|
+
// 2020 and never carried media bodies). Advertising a batch API that
|
|
99
|
+
// secretly looped would hide N round trips behind a call that looks like
|
|
100
|
+
// one, so the store's own sequential fallback is used - same cost, honest
|
|
101
|
+
// about it.
|
|
102
|
+
|
|
103
|
+
clearCaches: () => {
|
|
104
|
+
// Memoised file ids belong to the account that was signed in when they
|
|
105
|
+
// were recorded. Handing them to the next user is a cross-account leak.
|
|
106
|
+
if (isConfigured()) getClient().clearCache();
|
|
107
|
+
stopWatching();
|
|
108
|
+
},
|
|
109
|
+
/**
|
|
110
|
+
* Fires when another device changed something in `appDataFolder`.
|
|
111
|
+
*
|
|
112
|
+
* Drive has no push channel a mobile client can subscribe to - its webhooks
|
|
113
|
+
* need a public HTTPS endpoint to deliver to - so this polls Drive's change
|
|
114
|
+
* cursor. That is the honest implementation, and it is cheap: a poll with
|
|
115
|
+
* nothing to report is one request returning an empty list.
|
|
116
|
+
*
|
|
117
|
+
* Polling starts with the first subscriber and stops with the last, so an
|
|
118
|
+
* app that never subscribes never makes a request. Interval comes from
|
|
119
|
+
* `changePollIntervalMs` (default 30s).
|
|
120
|
+
*/
|
|
121
|
+
onRemoteChange: listener => {
|
|
122
|
+
changeListeners.add(listener);
|
|
123
|
+
startWatching();
|
|
124
|
+
return () => {
|
|
125
|
+
changeListeners.delete(listener);
|
|
126
|
+
if (changeListeners.size === 0) stopWatching();
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// ---------------------------------------------------------- change polling
|
|
132
|
+
|
|
133
|
+
const changeListeners = new Set();
|
|
134
|
+
let timer = null;
|
|
135
|
+
let cursor = null;
|
|
136
|
+
let polling = false;
|
|
137
|
+
function startWatching() {
|
|
138
|
+
if (timer != null || !isConfigured()) return;
|
|
139
|
+
timer = setInterval(() => {
|
|
140
|
+
void poll();
|
|
141
|
+
}, pollIntervalMs);
|
|
142
|
+
// Never hold the process open for a background poll - this is a cache
|
|
143
|
+
// refresh, not work anyone is waiting on.
|
|
144
|
+
timer.unref?.();
|
|
145
|
+
}
|
|
146
|
+
function stopWatching() {
|
|
147
|
+
if (timer != null) clearInterval(timer);
|
|
148
|
+
timer = null;
|
|
149
|
+
cursor = null;
|
|
150
|
+
}
|
|
151
|
+
async function poll() {
|
|
152
|
+
// Skip rather than queue: a poll that outruns its interval on a slow link
|
|
153
|
+
// would otherwise pile up requests behind it.
|
|
154
|
+
if (polling || !isConfigured()) return;
|
|
155
|
+
polling = true;
|
|
156
|
+
try {
|
|
157
|
+
const client = getClient();
|
|
158
|
+
if (cursor == null) {
|
|
159
|
+
// First tick only establishes the starting cursor. Reporting everything
|
|
160
|
+
// that ever happened as "just changed" would make every subscriber
|
|
161
|
+
// re-read the whole store on launch.
|
|
162
|
+
cursor = await client.getStartPageToken();
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const {
|
|
166
|
+
names,
|
|
167
|
+
nextToken
|
|
168
|
+
} = await client.pollChanges(cursor);
|
|
169
|
+
cursor = nextToken;
|
|
170
|
+
if (names.length === 0) return;
|
|
171
|
+
const event = {
|
|
172
|
+
keys: names,
|
|
173
|
+
reason: 'serverChange',
|
|
174
|
+
provider: name
|
|
175
|
+
};
|
|
176
|
+
for (const l of changeListeners) l(event);
|
|
177
|
+
} catch {
|
|
178
|
+
// A failed poll is not the app's problem: the next tick tries again, and
|
|
179
|
+
// the cursor is only advanced on success so nothing is skipped.
|
|
180
|
+
} finally {
|
|
181
|
+
polling = false;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return provider;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Google Drive `appDataFolder`, using the credentials from
|
|
189
|
+
* `configureGoogleDrive()`.
|
|
190
|
+
*
|
|
191
|
+
* The only provider that works identically on iOS, Android and web, which makes
|
|
192
|
+
* it the sensible continuous backend for cross-platform apps - CloudKit's
|
|
193
|
+
* Android/web path needs a periodic Apple ID re-auth, this does not.
|
|
194
|
+
*/
|
|
195
|
+
const googleDrive = exports.googleDrive = makeDriveProvider(NAME, _config.getGoogleDriveClient, _config.isGoogleDriveConfigured);
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* A Drive provider with its own credentials and its own name.
|
|
199
|
+
*
|
|
200
|
+
* `configureGoogleDrive` sets one client for the whole process, which is right
|
|
201
|
+
* for the overwhelmingly common single-account app but leaves no way to reach
|
|
202
|
+
* two accounts at once - a profile switcher, a "copy my data to another
|
|
203
|
+
* account" flow, or a test that needs two isolated instances. Those need a
|
|
204
|
+
* provider that owns its config rather than reading a module-level singleton.
|
|
205
|
+
*
|
|
206
|
+
* ```ts
|
|
207
|
+
* const work = createGoogleDriveProvider({
|
|
208
|
+
* name: 'drive:work',
|
|
209
|
+
* getAccessToken: () => workToken(),
|
|
210
|
+
* })
|
|
211
|
+
* const store = createCloudStore({ providers: ['drive:work'] })
|
|
212
|
+
* store.registerProvider(work)
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
function createGoogleDriveProvider(config) {
|
|
216
|
+
const client = new _googleDriveRest.GoogleDriveClient(config);
|
|
217
|
+
return makeDriveProvider(config.name ?? NAME, () => client, () => true, config.changePollIntervalMs);
|
|
218
|
+
}
|
|
219
|
+
//# sourceMappingURL=googleDrive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_config","require","_googleDriveRest","_errors","NAME","DEFAULT_POLL_INTERVAL_MS","makeDriveProvider","name","getClient","isConfigured","pollIntervalMs","provider","isAvailable","hasToken","getAccountStatus","Promise","resolve","getItem","key","e","normalizeError","getItemWithMeta","setItem","value","removeItem","getAllKeys","getQuota","clearCaches","clearCache","stopWatching","onRemoteChange","listener","changeListeners","add","startWatching","delete","size","Set","timer","cursor","polling","setInterval","poll","unref","clearInterval","client","getStartPageToken","names","nextToken","pollChanges","length","event","keys","reason","l","googleDrive","exports","getGoogleDriveClient","isGoogleDriveConfigured","createGoogleDriveProvider","config","GoogleDriveClient","changePollIntervalMs"],"sourceRoot":"../../../src","sources":["providers/googleDrive.ts"],"mappings":";;;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AAGA,MAAMG,IAAI,GAAG,aAAsB;;AAEnC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,wBAAwB,GAAG,MAAM;;AAEvC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,iBAAiBA,CACxBC,IAAkB,EAClBC,SAAkC,EAClCC,YAA2B,EAC3BC,cAAc,GAAGL,wBAAwB,EAC1B;EACf,MAAMM,QAAuB,GAAG;IAC9BJ,IAAI;IAEJK,WAAW,EAAE,MAAAA,CAAA,KAAY;MACvB,IAAI,CAACH,YAAY,CAAC,CAAC,EAAE,OAAO,KAAK;MACjC,IAAI;QACF;QACA;QACA;QACA,OAAO,MAAMD,SAAS,CAAC,CAAC,CAACK,QAAQ,CAAC,CAAC;MACrC,CAAC,CACD,MAAM;QACJ,OAAO,KAAK;MACd;IACF,CAAC;IAEDC,gBAAgB,EAAEA,CAAA,KAChBC,OAAO,CAACC,OAAO,CAACP,YAAY,CAAC,CAAC,GAAG,WAAW,GAAG,WAAW,CAAC;IAE7DQ,OAAO,EAAE,MAAOC,GAAW,IAAK;MAC9B,IAAI;QACF,OAAO,MAAMV,SAAS,CAAC,CAAC,CAACS,OAAO,CAACC,GAAG,CAAC;MACvC,CAAC,CACD,OAAOC,CAAC,EAAE;QACR,MAAM,IAAAC,sBAAc,EAACD,CAAC,EAAEZ,IAA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Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.googleDriveFiles = void 0;
|
|
7
|
+
var _config = require("../config.js");
|
|
8
|
+
var _errors = require("../errors.js");
|
|
9
|
+
var _base = require("../internal/base64.js");
|
|
10
|
+
const NAME = 'googleDrive';
|
|
11
|
+
/**
|
|
12
|
+
* Binary files in Drive's `appDataFolder`, for anything too large to hold in
|
|
13
|
+
* memory as a JS string the way `googleDrive.setItem` does - the Android/web
|
|
14
|
+
* equivalent of `cloudKitAssets`' `CKAsset` on Apple platforms.
|
|
15
|
+
*
|
|
16
|
+
* Uploads use Drive's resumable protocol, reading the source in fixed chunks;
|
|
17
|
+
* downloads write in the same fixed chunks. Neither ever holds more than one
|
|
18
|
+
* chunk (8 MiB by default) in memory. Both go through a `GoogleDriveFileAdapter`
|
|
19
|
+
* (`configureGoogleDriveFiles`) for the actual disk I/O - this package has no
|
|
20
|
+
* filesystem dependency of its own, so the host app supplies one using
|
|
21
|
+
* whichever fs library it already has. See the CloudKit/Google Drive guides
|
|
22
|
+
* for the file adapter's exact contract and setup examples.
|
|
23
|
+
*/
|
|
24
|
+
const googleDriveFiles = exports.googleDriveFiles = {
|
|
25
|
+
/** Uploads `fileUri` as `name`, overwriting whatever was there. */
|
|
26
|
+
save: async options => {
|
|
27
|
+
const adapter = (0, _config.getGoogleDriveFileAdapter)();
|
|
28
|
+
try {
|
|
29
|
+
const size = await adapter.statSize(options.fileUri);
|
|
30
|
+
const source = {
|
|
31
|
+
size,
|
|
32
|
+
read: async (start, length) => (0, _base.base64ToBytes)(await adapter.readChunk(options.fileUri, start, length))
|
|
33
|
+
};
|
|
34
|
+
await (0, _config.getGoogleDriveClient)().uploadFile(options.name, source, forward(options.onProgress), options.signal);
|
|
35
|
+
} catch (e) {
|
|
36
|
+
throw (0, _errors.normalizeError)(e, NAME);
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
/**
|
|
40
|
+
* Downloads `name` into `destinationUri`, resolving `destinationUri` back
|
|
41
|
+
* once complete, or `null` when no such file exists - `destinationUri` is
|
|
42
|
+
* never touched in that case.
|
|
43
|
+
*/
|
|
44
|
+
fetch: async options => {
|
|
45
|
+
const adapter = (0, _config.getGoogleDriveFileAdapter)();
|
|
46
|
+
const sink = {
|
|
47
|
+
write: async (bytes, isFirstChunk) => {
|
|
48
|
+
const base64 = (0, _base.bytesToBase64)(bytes);
|
|
49
|
+
if (isFirstChunk) await adapter.writeChunk(options.destinationUri, base64);else await adapter.appendChunk(options.destinationUri, base64);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
try {
|
|
53
|
+
const found = await (0, _config.getGoogleDriveClient)().downloadFile(options.name, sink, forward(options.onProgress), options.signal);
|
|
54
|
+
return found ? options.destinationUri : null;
|
|
55
|
+
} catch (e) {
|
|
56
|
+
throw (0, _errors.normalizeError)(e, NAME);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
function forward(onProgress) {
|
|
61
|
+
if (onProgress == null) return undefined;
|
|
62
|
+
return (bytesTransferred, bytesTotal) => onProgress({
|
|
63
|
+
bytesTransferred,
|
|
64
|
+
bytesTotal,
|
|
65
|
+
fraction: bytesTotal > 0 ? bytesTransferred / bytesTotal : 0
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=googleDriveFiles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_config","require","_errors","_base","NAME","googleDriveFiles","exports","save","options","adapter","getGoogleDriveFileAdapter","size","statSize","fileUri","source","read","start","length","base64ToBytes","readChunk","getGoogleDriveClient","uploadFile","name","forward","onProgress","signal","e","normalizeError","fetch","sink","write","bytes","isFirstChunk","base64","bytesToBase64","writeChunk","destinationUri","appendChunk","found","downloadFile","undefined","bytesTransferred","bytesTotal","fraction"],"sourceRoot":"../../../src","sources":["providers/googleDriveFiles.ts"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GA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AC3B,OAAO,CAAC4B,cAAc,EAAEH,MAAM,CAAC,MACrE,MAAMxB,OAAO,CAAC4B,WAAW,CAAC7B,OAAO,CAAC4B,cAAc,EAAEH,MAAM,CAAC;MAChE;IACF,CAAC;IAED,IAAI;MACF,MAAMK,KAAK,GAAG,MAAM,IAAAlB,4BAAoB,EAAC,CAAC,CAACmB,YAAY,CACrD/B,OAAO,CAACc,IAAI,EAAEO,IAAI,EAAEN,OAAO,CAACf,OAAO,CAACgB,UAAU,CAAC,EAAEhB,OAAO,CAACiB,MAC3D,CAAC;MACD,OAAOa,KAAK,GAAG9B,OAAO,CAAC4B,cAAc,GAAG,IAAI;IAC9C,CAAC,CACD,OAAOV,CAAC,EAAE;MACR,MAAM,IAAAC,sBAAc,EAACD,CAAC,EAAEtB,IAAI,CAAC;IAC/B;EACF;AACF,CAAC;AAED,SAASmB,OAAOA,CACdC,UAA8C,EACwB;EACtE,IAAIA,UAAU,IAAI,IAAI,EAAE,OAAOgB,SAAS;EACxC,OAAO,CAACC,gBAAgB,EAAEC,UAAU,KAClClB,UAAU,CAAC;IACTiB,gBAAgB;IAChBC,UAAU;IACVC,QAAQ,EAAED,UAAU,GAAG,CAAC,GAAGD,gBAAgB,GAAGC,UAAU,GAAG;EAC7D,CAAC,CAAC;AACN","ignoreList":[]}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.icloudDocuments = void 0;
|
|
7
|
+
var _reactNative = require("react-native");
|
|
8
|
+
var _nativeModule = require("../internal/nativeModule.js");
|
|
9
|
+
var _errors = require("../errors.js");
|
|
10
|
+
const NAME = 'icloudDocuments';
|
|
11
|
+
const APPLE_PLATFORMS = ['ios', 'macos'];
|
|
12
|
+
|
|
13
|
+
/** Default wait for a file to come down from iCloud before reporting a timeout. */
|
|
14
|
+
const DEFAULT_FETCH_TIMEOUT_MS = 60_000;
|
|
15
|
+
function isApplePlatform() {
|
|
16
|
+
const os = _reactNative.Platform?.OS;
|
|
17
|
+
return os != null && APPLE_PLATFORMS.includes(os);
|
|
18
|
+
}
|
|
19
|
+
function assertSupported() {
|
|
20
|
+
if (!isApplePlatform() || (0, _nativeModule.getNativeModule)() == null) throw (0, _errors.unsupportedPlatform)(NAME, 'iCloud Drive is an Apple filesystem feature with no REST or browser equivalent. ' + 'Use googleDriveFiles for user-visible files on Android and web.');
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Files in the user's own iCloud Drive.
|
|
24
|
+
*
|
|
25
|
+
* This is the one thing no `CKRecord` or `CKAsset` API can do, and the most
|
|
26
|
+
* common iCloud request in mobile apps: *put this file where the user can find
|
|
27
|
+
* it*. A `CKAsset` lives in the app's private CloudKit database - the user
|
|
28
|
+
* cannot see it, open it, or hand it to another app. A file written here lands
|
|
29
|
+
* in the app's folder in iCloud Drive, visible in Files.app, syncing to every
|
|
30
|
+
* device signed into the same Apple ID, and surviving the app being deleted.
|
|
31
|
+
*
|
|
32
|
+
* Requirements beyond the CloudKit entitlement:
|
|
33
|
+
*
|
|
34
|
+
* - the **iCloud Documents** service on the container (the config plugin's
|
|
35
|
+
* `iCloudDocuments: true` option adds it);
|
|
36
|
+
* - an `NSUbiquitousContainers` Info.plist entry with
|
|
37
|
+
* `NSUbiquitousContainerIsDocumentScopePublic` set, or the folder syncs but
|
|
38
|
+
* stays invisible in Files.app. The plugin writes this too.
|
|
39
|
+
*
|
|
40
|
+
* Apple platforms only, and unlike the other providers that is not a gap to be
|
|
41
|
+
* filled later: there is no REST surface for iCloud Drive and no browser API.
|
|
42
|
+
* Use {@link googleDriveFiles} for user-visible files elsewhere.
|
|
43
|
+
*
|
|
44
|
+
* Not a {@link CloudProvider}: the contract there is keys to string values, and
|
|
45
|
+
* this moves files by path. Same reason `cloudKitAssets` is its own API.
|
|
46
|
+
*/
|
|
47
|
+
const icloudDocuments = exports.icloudDocuments = {
|
|
48
|
+
/** Whether this device has a usable iCloud Drive container right now. */
|
|
49
|
+
isAvailable: async () => {
|
|
50
|
+
if (!isApplePlatform()) return false;
|
|
51
|
+
const m = (0, _nativeModule.getNativeModule)();
|
|
52
|
+
if (m == null) return false;
|
|
53
|
+
try {
|
|
54
|
+
return await m.docIsAvailable();
|
|
55
|
+
} catch {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
/**
|
|
60
|
+
* Copies a local file into iCloud Drive under `name`, replacing whatever was
|
|
61
|
+
* there. Resolves the resulting iCloud path.
|
|
62
|
+
*
|
|
63
|
+
* Resolving means "handed to iCloud", not "in the cloud" - the system uploads
|
|
64
|
+
* in the background whether or not the app is running. Same distinction as
|
|
65
|
+
* `icloudKVSync()`, and for the same reason: there is no API that waits for
|
|
66
|
+
* the upload.
|
|
67
|
+
*/
|
|
68
|
+
save: async options => {
|
|
69
|
+
assertSupported();
|
|
70
|
+
try {
|
|
71
|
+
return await (0, _nativeModule.requireNativeModule)().docSave(options.fileUri, options.name);
|
|
72
|
+
} catch (e) {
|
|
73
|
+
throw (0, _errors.normalizeError)(e, NAME);
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
/**
|
|
77
|
+
* Downloads `name` if this device does not have it yet, then resolves a local
|
|
78
|
+
* path - or `null` when no such file exists in the account.
|
|
79
|
+
*
|
|
80
|
+
* The download step is the point. A file listed by {@link list} may be a
|
|
81
|
+
* placeholder with no local bytes, and opening that gives you an empty file
|
|
82
|
+
* rather than an error.
|
|
83
|
+
*
|
|
84
|
+
* Byte-level progress is not reported: that needs an `NSMetadataQuery`, which
|
|
85
|
+
* needs a live run loop, and this runs off the main thread on purpose. Use
|
|
86
|
+
* {@link list} to poll `isDownloading` if you need to show something.
|
|
87
|
+
*/
|
|
88
|
+
fetch: async options => {
|
|
89
|
+
assertSupported();
|
|
90
|
+
try {
|
|
91
|
+
return await (0, _nativeModule.requireNativeModule)().docFetch(options.name, options.destinationUri ?? null, options.timeoutMs ?? DEFAULT_FETCH_TIMEOUT_MS);
|
|
92
|
+
} catch (e) {
|
|
93
|
+
throw (0, _errors.normalizeError)(e, NAME);
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
/**
|
|
97
|
+
* Everything in the app's iCloud Drive folder, including files this device
|
|
98
|
+
* has not downloaded.
|
|
99
|
+
*/
|
|
100
|
+
list: async () => {
|
|
101
|
+
assertSupported();
|
|
102
|
+
try {
|
|
103
|
+
return await (0, _nativeModule.requireNativeModule)().docList();
|
|
104
|
+
} catch (e) {
|
|
105
|
+
throw (0, _errors.normalizeError)(e, NAME);
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
/**
|
|
109
|
+
* Deletes a file from iCloud Drive - on every device, and from the user's
|
|
110
|
+
* Files.app. Resolves false when it was already gone.
|
|
111
|
+
*/
|
|
112
|
+
remove: async name => {
|
|
113
|
+
assertSupported();
|
|
114
|
+
try {
|
|
115
|
+
return await (0, _nativeModule.requireNativeModule)().docRemove(name);
|
|
116
|
+
} catch (e) {
|
|
117
|
+
throw (0, _errors.normalizeError)(e, NAME);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
//# sourceMappingURL=icloudDocuments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_nativeModule","_errors","NAME","APPLE_PLATFORMS","DEFAULT_FETCH_TIMEOUT_MS","isApplePlatform","os","Platform","OS","includes","assertSupported","getNativeModule","unsupportedPlatform","icloudDocuments","exports","isAvailable","m","docIsAvailable","save","options","requireNativeModule","docSave","fileUri","name","e","normalizeError","fetch","docFetch","destinationUri","timeoutMs","list","docList","remove","docRemove"],"sourceRoot":"../../../src","sources":["providers/icloudDocuments.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AAEA,MAAMG,IAA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,EAAE;MACR,MAAM,IAAAC,sBAAc,EAACD,CAAC,EAAEtB,IAAI,CAAC;IAC/B;EACF,CAAC;EAED;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEwB,KAAK,EAAE,MACLP,OAAgD,IACrB;IAC3BT,eAAe,CAAC,CAAC;IACjB,IAAI;MACF,OAAO,MAAM,IAAAU,iCAAmB,EAAC,CAAC,CAACO,QAAQ,CACzCR,OAAO,CAACI,IAAI,EACZJ,OAAO,CAACS,cAAc,IAAI,IAAI,EAC9BT,OAAO,CAACU,SAAS,IAAIzB,wBACvB,CAAC;IACH,CAAC,CACD,OAAOoB,CAAC,EAAE;MACR,MAAM,IAAAC,sBAAc,EAACD,CAAC,EAAEtB,IAAI,CAAC;IAC/B;EACF,CAAC;EAED;AACF;AACA;AACA;EACE4B,IAAI,EAAE,MAAAA,CAAA,KAAsC;IAC1CpB,eAAe,CAAC,CAAC;IACjB,IAAI;MACF,OAAO,MAAM,IAAAU,iCAAmB,EAAC,CAAC,CAACW,OAAO,CAAC,CAAC;IAC9C,CAAC,CACD,OAAOP,CAAC,EAAE;MACR,MAAM,IAAAC,sBAAc,EAACD,CAAC,EAAEtB,IAAI,CAAC;IAC/B;EACF,CAAC;EAED;AACF;AACA;AACA;EACE8B,MAAM,EAAE,MAAOT,IAAY,IAAuB;IAChDb,eAAe,CAAC,CAAC;IACjB,IAAI;MACF,OAAO,MAAM,IAAAU,iCAAmB,EAAC,CAAC,CAACa,SAAS,CAACV,IAAI,CAAC;IACpD,CAAC,CACD,OAAOC,CAAC,EAAE;MACR,MAAM,IAAAC,sBAAc,EAACD,CAAC,EAAEtB,IAAI,CAAC;IAC/B;EACF;AACF,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getAllItems = getAllItems;
|
|
7
|
+
exports.icloudKV = void 0;
|
|
8
|
+
exports.sync = sync;
|
|
9
|
+
var _reactNative = require("react-native");
|
|
10
|
+
var _nativeModule = require("../internal/nativeModule.js");
|
|
11
|
+
var _errors = require("../errors.js");
|
|
12
|
+
var _enums = require("../internal/enums.js");
|
|
13
|
+
const NAME = 'icloudKV';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* `NSUbiquitousKeyValueStore`.
|
|
17
|
+
*
|
|
18
|
+
* Apple-only by construction: there is no browser or Android API for the iCloud
|
|
19
|
+
* key-value store, and no REST surface either. Reach for `cloudKit` when you
|
|
20
|
+
* need the same data on Android or web.
|
|
21
|
+
*
|
|
22
|
+
* Hard limits, enforced here rather than left to fail silently at the OS layer:
|
|
23
|
+
* 1 MB total, 1 MB per key, 1024 keys.
|
|
24
|
+
*/
|
|
25
|
+
const APPLE_PLATFORMS = ['ios', 'macos'];
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* True on a platform where `NSUbiquitousKeyValueStore` can exist at all.
|
|
29
|
+
*
|
|
30
|
+
* `Platform.OS` is read defensively because a non-Metro web bundler
|
|
31
|
+
* (webpack/Vite/Next) does not resolve the `.web.ts` platform extension, so
|
|
32
|
+
* this file - not `icloudKV.web.ts` - is what a react-native-web build loads.
|
|
33
|
+
* It must reach the same conclusion there by itself.
|
|
34
|
+
*/
|
|
35
|
+
function isApplePlatform() {
|
|
36
|
+
const os = _reactNative.Platform?.OS;
|
|
37
|
+
return os != null && APPLE_PLATFORMS.includes(os);
|
|
38
|
+
}
|
|
39
|
+
function assertPlatform() {
|
|
40
|
+
if (!isApplePlatform()) throw (0, _errors.unsupportedPlatform)(NAME, `NSUbiquitousKeyValueStore exists only on Apple platforms (got '${String(_reactNative.Platform?.OS)}'). ` + `Use the cloudKit provider for cross-platform access to the same account.`);
|
|
41
|
+
}
|
|
42
|
+
const icloudKV = exports.icloudKV = {
|
|
43
|
+
name: NAME,
|
|
44
|
+
isAvailable: async () => {
|
|
45
|
+
if (!isApplePlatform()) return false;
|
|
46
|
+
const m = (0, _nativeModule.getNativeModule)();
|
|
47
|
+
if (m == null) return false;
|
|
48
|
+
try {
|
|
49
|
+
return await m.isAvailable();
|
|
50
|
+
} catch {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
getAccountStatus: async () => {
|
|
55
|
+
assertPlatform();
|
|
56
|
+
try {
|
|
57
|
+
return (0, _enums.toAccountStatus)(await (0, _nativeModule.requireNativeModule)().getAccountStatus());
|
|
58
|
+
} catch (e) {
|
|
59
|
+
throw (0, _errors.normalizeError)(e, NAME);
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
getItem: async key => {
|
|
63
|
+
assertPlatform();
|
|
64
|
+
try {
|
|
65
|
+
return await (0, _nativeModule.requireNativeModule)().kvGetItem(key);
|
|
66
|
+
} catch (e) {
|
|
67
|
+
throw (0, _errors.normalizeError)(e, NAME);
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
setItem: async (key, value) => {
|
|
71
|
+
assertPlatform();
|
|
72
|
+
try {
|
|
73
|
+
await (0, _nativeModule.requireNativeModule)().kvSetItem(key, value);
|
|
74
|
+
} catch (e) {
|
|
75
|
+
throw (0, _errors.normalizeError)(e, NAME);
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
removeItem: async key => {
|
|
79
|
+
assertPlatform();
|
|
80
|
+
try {
|
|
81
|
+
await (0, _nativeModule.requireNativeModule)().kvRemoveItem(key);
|
|
82
|
+
} catch (e) {
|
|
83
|
+
throw (0, _errors.normalizeError)(e, NAME);
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
getAllKeys: async () => {
|
|
87
|
+
assertPlatform();
|
|
88
|
+
try {
|
|
89
|
+
return await (0, _nativeModule.requireNativeModule)().kvGetAllKeys();
|
|
90
|
+
} catch (e) {
|
|
91
|
+
throw (0, _errors.normalizeError)(e, NAME);
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
/**
|
|
95
|
+
* How full the key-value store is.
|
|
96
|
+
*
|
|
97
|
+
* `totalBytes` is Apple's 1 MB ceiling rather than a per-account quota - the
|
|
98
|
+
* key-value store has a fixed size, not a share of the user's iCloud storage.
|
|
99
|
+
* The number worth watching, since exceeding it is silent.
|
|
100
|
+
*/
|
|
101
|
+
getQuota: async () => {
|
|
102
|
+
if (!isApplePlatform()) return null;
|
|
103
|
+
const m = (0, _nativeModule.getNativeModule)();
|
|
104
|
+
if (m == null) return null;
|
|
105
|
+
try {
|
|
106
|
+
const usage = await m.kvGetUsage();
|
|
107
|
+
return {
|
|
108
|
+
usedBytes: usage.usedBytes,
|
|
109
|
+
totalBytes: usage.totalBytes,
|
|
110
|
+
provider: NAME
|
|
111
|
+
};
|
|
112
|
+
} catch (e) {
|
|
113
|
+
throw (0, _errors.normalizeError)(e, NAME);
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
onRemoteChange: listener => (0, _nativeModule.subscribeNativeEvent)('onRemoteChange', 'remoteChange', e => {
|
|
117
|
+
if (e.provider !== NAME) return;
|
|
118
|
+
listener({
|
|
119
|
+
keys: e.keys,
|
|
120
|
+
reason: (0, _enums.toChangeReason)(e.reason),
|
|
121
|
+
provider: NAME
|
|
122
|
+
});
|
|
123
|
+
}),
|
|
124
|
+
onAccountChange: listener => (0, _nativeModule.subscribeNativeEvent)('onAccountChange', 'accountChange', e => {
|
|
125
|
+
listener({
|
|
126
|
+
status: (0, _enums.toAccountStatus)(e.status),
|
|
127
|
+
identityChanged: e.identityChanged,
|
|
128
|
+
provider: NAME
|
|
129
|
+
});
|
|
130
|
+
})
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Every key and value in the store, in one call.
|
|
135
|
+
*
|
|
136
|
+
* Not part of the {@link CloudProvider} contract, because no other provider can
|
|
137
|
+
* do it cheaply - CloudKit and Drive would both have to fetch every record.
|
|
138
|
+
* Here the whole store is already a local dictionary, so this is one bridge hop
|
|
139
|
+
* against the N+1 that `getAllKeys()` plus a read per key would cost.
|
|
140
|
+
*
|
|
141
|
+
* Values the store holds as something other than a string (it also accepts
|
|
142
|
+
* numbers, dates and data) are omitted rather than coerced, since a
|
|
143
|
+
* stringified number would not round-trip back through `setItem`.
|
|
144
|
+
*/
|
|
145
|
+
async function getAllItems() {
|
|
146
|
+
assertPlatform();
|
|
147
|
+
try {
|
|
148
|
+
return await (0, _nativeModule.requireNativeModule)().kvGetAllItems();
|
|
149
|
+
} catch (e) {
|
|
150
|
+
throw (0, _errors.normalizeError)(e, NAME);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Flushes pending changes to disk.
|
|
156
|
+
*
|
|
157
|
+
* Exposed separately because it is not part of the generic {@link CloudProvider}
|
|
158
|
+
* contract - and because its semantics are routinely misread. It maps to
|
|
159
|
+
* `NSUbiquitousKeyValueStore.synchronize()`, which schedules an upload; it does
|
|
160
|
+
* not wait for or confirm one. A resolved `sync()` means "queued", never
|
|
161
|
+
* "stored in iCloud".
|
|
162
|
+
*/
|
|
163
|
+
async function sync() {
|
|
164
|
+
assertPlatform();
|
|
165
|
+
try {
|
|
166
|
+
return await (0, _nativeModule.requireNativeModule)().kvSync();
|
|
167
|
+
} catch (e) {
|
|
168
|
+
throw (0, _errors.normalizeError)(e, NAME);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=icloudKV.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_nativeModule","_errors","_enums","NAME","APPLE_PLATFORMS","isApplePlatform","os","Platform","OS","includes","assertPlatform","unsupportedPlatform","String","icloudKV","exports","name","isAvailable","m","getNativeModule","getAccountStatus","toAccountStatus","requireNativeModule","e","normalizeError","getItem","key","kvGetItem","setItem","value","kvSetItem","removeItem","kvRemoveItem","getAllKeys","kvGetAllKeys","getQuota","usage","kvGetUsage","usedBytes","totalBytes","provider","onRemoteChange","listener","subscribeNativeEvent","keys","reason","toChangeReason","onAccountChange","status","identityChanged","getAllItems","kvGetAllItems","sync","kvSync"],"sourceRoot":"../../../src","sources":["providers/icloudKV.ts"],"mappings":";;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,aAAA,GAAAD,OAAA;AAKA,IAAAE,OAAA,GAAAF,OAAA;AAYA,IAAAG,MAAA,GAAAH,OAAA;AAEA,MAAMI,IAAI,GAAG,UAAmB;;AAEhC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,eAAe,GAAG,CAAC,KAAK,EAAE,OAAO,CAAU;;AAEjD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,eAAeA,CAAA,EAAY;EAClC,MAAMC,EAAsB,GAAGC,qBAAQ,EAAEC,EAAE;EAC3C,OAAOF,EAAE,IAAI,IAAI,IAAKF,eAAe,CAAuBK,QAAQ,CAACH,EAAE,CAAC;AAC1E;AAEA,SAASI,cAAcA,CAAA,EAAS;EAC9B,IAAI,CAACL,eAAe,CAAC,CAAC,EACpB,MAAM,IAAAM,2BAAmB,EACvBR,IAAI,EACJ,kEAAkES,MAAM,CAACL,qBAAQ,EAAEC,EAAE,CAAC,MAAM,GAC1F,0EACJ,CAAC;AACL;AAEO,MAAMK,QAAuB,GAAAC,OAAA,CAAAD,QAAA,GAAG;EACrCE,IAAI,EAAEZ,IAAI;EAEVa,WAAW,EAAE,MAAAA,CAAA,KAAY;IACvB,IAAI,CAACX,eAAe,CAAC,CAAC,EAAE,OAAO,KAAK;IACpC,MAAMY,CAAC,GAAG,IAAAC,6BAAe,EAAC,CAAC;IAC3B,IAAID,CAAC,IAAI,IAAI,EAAE,OAAO,KAAK;IAC3B,IAAI;MACF,OAAO,MAAMA,CAAC,CAACD,WAAW,CAAC,CAAC;IAC9B,CAAC,CACD,MAAM;MACJ,OAAO,KAAK;IACd;EACF,CAAC;EAEDG,gBAAgB,EA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,EAAEpC;IACZ,CAAC,CAAC;EACJ,CACF;AACJ,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAe8C,WAAWA,CAAA,EAAoC;EACnEvC,cAAc,CAAC,CAAC;EAChB,IAAI;IACF,OAAO,MAAM,IAAAW,iCAAmB,EAAC,CAAC,CAAC6B,aAAa,CAAC,CAAC;EACpD,CAAC,CACD,OAAO5B,CAAC,EAAE;IACR,MAAM,IAAAC,sBAAc,EAACD,CAAC,EAAEnB,IAAI,CAAC;EAC/B;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAegD,IAAIA,CAAA,EAAqB;EAC7CzC,cAAc,CAAC,CAAC;EAChB,IAAI;IACF,OAAO,MAAM,IAAAW,iCAAmB,EAAC,CAAC,CAAC+B,MAAM,CAAC,CAAC;EAC7C,CAAC,CACD,OAAO9B,CAAC,EAAE;IACR,MAAM,IAAAC,sBAAc,EAACD,CAAC,EAAEnB,IAAI,CAAC;EAC/B;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getAllItems = getAllItems;
|
|
7
|
+
exports.icloudKV = void 0;
|
|
8
|
+
exports.sync = sync;
|
|
9
|
+
var _errors = require("../errors.js");
|
|
10
|
+
const NAME = 'icloudKV';
|
|
11
|
+
const DETAIL = 'NSUbiquitousKeyValueStore has no browser API. Use the cloudKit provider, which ' + 'reaches the same private database over CloudKit Web Services.';
|
|
12
|
+
function reject() {
|
|
13
|
+
throw (0, _errors.unsupportedPlatform)(NAME, DETAIL);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Web build of the iCloud key-value provider.
|
|
18
|
+
*
|
|
19
|
+
* Every operation rejects with `ERR_UNSUPPORTED_PLATFORM` rather than resolving
|
|
20
|
+
* `null` or silently no-oping, so a web build fails loudly at the call site
|
|
21
|
+
* instead of appearing to work and quietly dropping data.
|
|
22
|
+
*/
|
|
23
|
+
const icloudKV = exports.icloudKV = {
|
|
24
|
+
name: NAME,
|
|
25
|
+
isAvailable: () => Promise.resolve(false),
|
|
26
|
+
getAccountStatus: () => Promise.resolve('couldNotDetermine'),
|
|
27
|
+
getItem: reject,
|
|
28
|
+
setItem: reject,
|
|
29
|
+
removeItem: reject,
|
|
30
|
+
getAllKeys: reject,
|
|
31
|
+
// Not `reject`: a quota question has a truthful answer on web - there is no
|
|
32
|
+
// key-value store here to be full - and `getQuota` is documented as reporting
|
|
33
|
+
// `null` for a provider that does not know.
|
|
34
|
+
getQuota: () => Promise.resolve(null)
|
|
35
|
+
};
|
|
36
|
+
function sync() {
|
|
37
|
+
return reject();
|
|
38
|
+
}
|
|
39
|
+
function getAllItems() {
|
|
40
|
+
return reject();
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=icloudKV.web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_errors","require","NAME","DETAIL","reject","unsupportedPlatform","icloudKV","exports","name","isAvailable","Promise","resolve","getAccountStatus","getItem","setItem","removeItem","getAllKeys","getQuota","sync","getAllItems"],"sourceRoot":"../../../src","sources":["providers/icloudKV.web.ts"],"mappings":";;;;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAGA,MAAMC,IAAI,GAAG,UAAmB;AAEhC,MAAMC,MAAM,GACR,iFAAiF,GAC/E,+DAA+D;AAErE,SAASC,MAAMA,CAAA,EAAU;EACvB,MAAM,IAAAC,2BAAmB,EAACH,IAAI,EAAEC,MAAM,CAAC;AACzC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMG,QAAuB,GAAAC,OAAA,CAAAD,QAAA,GAAG;EACrCE,IAAI,EAAEN,IAAI;EACVO,WAAW,EAAEA,CAAA,KAAMC,OAAO,CAACC,OAAO,CAAC,KAAK,CAAC;EACzCC,gBAAgB,EAAEA,CAAA,KAA8BF,OAAO,CAACC,OAAO,CAAC,mBAAmB,CAAC;EACpFE,OAAO,EAAET,MAAM;EACfU,OAAO,EAAEV,MAAM;EACfW,UAAU,EAAEX,MAAM;EAClBY,UAAU,EAAEZ,MAAM;EAClB;EACA;EACA;EACAa,QAAQ,EAAEA,CAAA,KAAMP,OAAO,CAACC,OAAO,CAAC,IAAI;AACtC,CAAC;AAEM,SAASO,IAAIA,CAAA,EAAqB;EACvC,OAAOd,MAAM,CAAC,CAAC;AACjB;AAEO,SAASe,WAAWA,CAAA,EAAoC;EAC7D,OAAOf,MAAM,CAAC,CAAC;AACjB","ignoreList":[]}
|