react-native-cloud-sync 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -0
- package/ios/CloudSyncError.swift +21 -0
- package/ios/CloudSyncImpl.swift +515 -95
- package/ios/RNCloudSync.mm +73 -1
- package/jest-mock.js +1 -0
- package/lib/commonjs/hooks.js +73 -9
- package/lib/commonjs/hooks.js.map +1 -1
- package/lib/commonjs/internal/autoFlush.js +10 -1
- package/lib/commonjs/internal/autoFlush.js.map +1 -1
- package/lib/commonjs/internal/base64.js +25 -5
- package/lib/commonjs/internal/base64.js.map +1 -1
- package/lib/commonjs/internal/cloudKitRest.js +91 -15
- package/lib/commonjs/internal/cloudKitRest.js.map +1 -1
- package/lib/commonjs/internal/googleDriveRest.js +304 -38
- package/lib/commonjs/internal/googleDriveRest.js.map +1 -1
- package/lib/commonjs/internal/keys.js +34 -17
- package/lib/commonjs/internal/keys.js.map +1 -1
- package/lib/commonjs/internal/records.js +48 -0
- package/lib/commonjs/internal/records.js.map +1 -0
- package/lib/commonjs/providers/cloudKit.js +85 -17
- package/lib/commonjs/providers/cloudKit.js.map +1 -1
- package/lib/commonjs/providers/cloudKitEncrypted.js +30 -7
- package/lib/commonjs/providers/cloudKitEncrypted.js.map +1 -1
- package/lib/commonjs/providers/googleDrive.js +37 -2
- package/lib/commonjs/providers/googleDrive.js.map +1 -1
- package/lib/commonjs/providers/icloudDocuments.js +27 -0
- package/lib/commonjs/providers/icloudDocuments.js.map +1 -1
- package/lib/commonjs/providers/icloudKV.js +13 -3
- package/lib/commonjs/providers/icloudKV.js.map +1 -1
- package/lib/commonjs/providers/icloudKV.web.js +8 -1
- package/lib/commonjs/providers/icloudKV.web.js.map +1 -1
- package/lib/commonjs/providers/memory.js +10 -0
- package/lib/commonjs/providers/memory.js.map +1 -1
- package/lib/commonjs/resolvers.js +27 -13
- package/lib/commonjs/resolvers.js.map +1 -1
- package/lib/commonjs/specs/NativeRNCloudSync.js +3 -0
- package/lib/commonjs/specs/NativeRNCloudSync.js.map +1 -1
- package/lib/commonjs/store.js +360 -173
- package/lib/commonjs/store.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/module/hooks.js +73 -9
- package/lib/module/hooks.js.map +1 -1
- package/lib/module/internal/autoFlush.js +10 -1
- package/lib/module/internal/autoFlush.js.map +1 -1
- package/lib/module/internal/base64.js +25 -5
- package/lib/module/internal/base64.js.map +1 -1
- package/lib/module/internal/cloudKitRest.js +89 -13
- package/lib/module/internal/cloudKitRest.js.map +1 -1
- package/lib/module/internal/googleDriveRest.js +304 -38
- package/lib/module/internal/googleDriveRest.js.map +1 -1
- package/lib/module/internal/keys.js +33 -17
- package/lib/module/internal/keys.js.map +1 -1
- package/lib/module/internal/records.js +41 -0
- package/lib/module/internal/records.js.map +1 -0
- package/lib/module/providers/cloudKit.js +86 -18
- package/lib/module/providers/cloudKit.js.map +1 -1
- package/lib/module/providers/cloudKitEncrypted.js +31 -8
- package/lib/module/providers/cloudKitEncrypted.js.map +1 -1
- package/lib/module/providers/googleDrive.js +37 -2
- package/lib/module/providers/googleDrive.js.map +1 -1
- package/lib/module/providers/icloudDocuments.js +28 -1
- package/lib/module/providers/icloudDocuments.js.map +1 -1
- package/lib/module/providers/icloudKV.js +13 -3
- package/lib/module/providers/icloudKV.js.map +1 -1
- package/lib/module/providers/icloudKV.web.js +8 -1
- package/lib/module/providers/icloudKV.web.js.map +1 -1
- package/lib/module/providers/memory.js +10 -0
- package/lib/module/providers/memory.js.map +1 -1
- package/lib/module/resolvers.js +27 -12
- package/lib/module/resolvers.js.map +1 -1
- package/lib/module/specs/NativeRNCloudSync.js +4 -0
- package/lib/module/specs/NativeRNCloudSync.js.map +1 -1
- package/lib/module/store.js +360 -173
- package/lib/module/store.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/typescript/commonjs/errors.d.ts +16 -16
- package/lib/typescript/commonjs/errors.d.ts.map +1 -1
- package/lib/typescript/commonjs/hooks.d.ts.map +1 -1
- package/lib/typescript/commonjs/internal/autoFlush.d.ts.map +1 -1
- package/lib/typescript/commonjs/internal/base64.d.ts.map +1 -1
- package/lib/typescript/commonjs/internal/cloudKitRest.d.ts +20 -0
- package/lib/typescript/commonjs/internal/cloudKitRest.d.ts.map +1 -1
- package/lib/typescript/commonjs/internal/googleDriveRest.d.ts +19 -0
- package/lib/typescript/commonjs/internal/googleDriveRest.d.ts.map +1 -1
- package/lib/typescript/commonjs/internal/keys.d.ts +18 -3
- package/lib/typescript/commonjs/internal/keys.d.ts.map +1 -1
- package/lib/typescript/commonjs/internal/records.d.ts +24 -0
- package/lib/typescript/commonjs/internal/records.d.ts.map +1 -0
- package/lib/typescript/commonjs/providers/cloudKit.d.ts +1 -1
- package/lib/typescript/commonjs/providers/cloudKit.d.ts.map +1 -1
- package/lib/typescript/commonjs/providers/cloudKitBackup.d.ts +1 -1
- package/lib/typescript/commonjs/providers/cloudKitBackup.d.ts.map +1 -1
- package/lib/typescript/commonjs/providers/cloudKitEncrypted.d.ts.map +1 -1
- package/lib/typescript/commonjs/providers/googleDrive.d.ts.map +1 -1
- package/lib/typescript/commonjs/providers/googleDriveFiles.d.ts.map +1 -1
- package/lib/typescript/commonjs/providers/icloudDocuments.d.ts +1 -1
- package/lib/typescript/commonjs/providers/icloudDocuments.d.ts.map +1 -1
- package/lib/typescript/commonjs/providers/icloudKV.d.ts.map +1 -1
- package/lib/typescript/commonjs/providers/icloudKV.web.d.ts.map +1 -1
- package/lib/typescript/commonjs/providers/memory.d.ts.map +1 -1
- package/lib/typescript/commonjs/resolvers.d.ts +6 -3
- package/lib/typescript/commonjs/resolvers.d.ts.map +1 -1
- package/lib/typescript/commonjs/specs/NativeRNCloudSync.d.ts +12 -3
- package/lib/typescript/commonjs/specs/NativeRNCloudSync.d.ts.map +1 -1
- package/lib/typescript/commonjs/store.d.ts.map +1 -1
- package/lib/typescript/commonjs/types.d.ts +31 -3
- package/lib/typescript/commonjs/types.d.ts.map +1 -1
- package/lib/typescript/module/errors.d.ts +16 -16
- package/lib/typescript/module/errors.d.ts.map +1 -1
- package/lib/typescript/module/hooks.d.ts.map +1 -1
- package/lib/typescript/module/internal/autoFlush.d.ts.map +1 -1
- package/lib/typescript/module/internal/base64.d.ts.map +1 -1
- package/lib/typescript/module/internal/cloudKitRest.d.ts +20 -0
- package/lib/typescript/module/internal/cloudKitRest.d.ts.map +1 -1
- package/lib/typescript/module/internal/googleDriveRest.d.ts +19 -0
- package/lib/typescript/module/internal/googleDriveRest.d.ts.map +1 -1
- package/lib/typescript/module/internal/keys.d.ts +18 -3
- package/lib/typescript/module/internal/keys.d.ts.map +1 -1
- package/lib/typescript/module/internal/records.d.ts +24 -0
- package/lib/typescript/module/internal/records.d.ts.map +1 -0
- package/lib/typescript/module/providers/cloudKit.d.ts +1 -1
- package/lib/typescript/module/providers/cloudKit.d.ts.map +1 -1
- package/lib/typescript/module/providers/cloudKitBackup.d.ts +1 -1
- package/lib/typescript/module/providers/cloudKitBackup.d.ts.map +1 -1
- package/lib/typescript/module/providers/cloudKitEncrypted.d.ts.map +1 -1
- package/lib/typescript/module/providers/googleDrive.d.ts.map +1 -1
- package/lib/typescript/module/providers/googleDriveFiles.d.ts.map +1 -1
- package/lib/typescript/module/providers/icloudDocuments.d.ts +1 -1
- package/lib/typescript/module/providers/icloudDocuments.d.ts.map +1 -1
- package/lib/typescript/module/providers/icloudKV.d.ts.map +1 -1
- package/lib/typescript/module/providers/icloudKV.web.d.ts.map +1 -1
- package/lib/typescript/module/providers/memory.d.ts.map +1 -1
- package/lib/typescript/module/resolvers.d.ts +6 -3
- package/lib/typescript/module/resolvers.d.ts.map +1 -1
- package/lib/typescript/module/specs/NativeRNCloudSync.d.ts +12 -3
- package/lib/typescript/module/specs/NativeRNCloudSync.d.ts.map +1 -1
- package/lib/typescript/module/store.d.ts.map +1 -1
- package/lib/typescript/module/types.d.ts +31 -3
- package/lib/typescript/module/types.d.ts.map +1 -1
- package/package.json +35 -25
- package/plugin/build/index.js +45 -13
- package/react-native-cloud-sync.podspec +10 -3
- package/src/hooks.ts +69 -9
- package/src/internal/autoFlush.ts +10 -1
- package/src/internal/base64.ts +26 -5
- package/src/internal/cloudKitRest.ts +103 -14
- package/src/internal/googleDriveRest.ts +338 -37
- package/src/internal/keys.ts +42 -16
- package/src/internal/records.ts +38 -0
- package/src/providers/cloudKit.ts +96 -20
- package/src/providers/cloudKitEncrypted.ts +37 -8
- package/src/providers/googleDrive.ts +38 -2
- package/src/providers/icloudDocuments.ts +40 -2
- package/src/providers/icloudKV.ts +13 -3
- package/src/providers/icloudKV.web.ts +8 -2
- package/src/providers/memory.ts +8 -0
- package/src/resolvers.ts +28 -13
- package/src/specs/NativeRNCloudSync.ts +16 -2
- package/src/store.ts +433 -190
- package/src/types.ts +32 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { TurboModule } from 'react-native';
|
|
2
|
-
|
|
1
|
+
import type { EventSubscription, TurboModule } from 'react-native';
|
|
2
|
+
type EventEmitter<T> = (handler: (arg: T) => void | Promise<void>) => EventSubscription;
|
|
3
3
|
/**
|
|
4
4
|
* Codegen cannot express an index signature, so dynamic dictionaries cross the
|
|
5
5
|
* bridge as `UnsafeObject`. Same workaround react-native-background-downloader
|
|
@@ -42,6 +42,15 @@ export interface Spec extends TurboModule {
|
|
|
42
42
|
};
|
|
43
43
|
getAccountStatus: () => Promise<string>;
|
|
44
44
|
isAvailable: () => Promise<boolean>;
|
|
45
|
+
/**
|
|
46
|
+
* Account status for the key-value store, from `ubiquityIdentityToken`.
|
|
47
|
+
*
|
|
48
|
+
* Unlike `getAccountStatus` this never touches CloudKit, so it is safe in an
|
|
49
|
+
* app with only the key-value-store entitlement - constructing a
|
|
50
|
+
* `CKContainer` there raises an uncatchable `CKException`. Reports only
|
|
51
|
+
* `available` or `noAccount`.
|
|
52
|
+
*/
|
|
53
|
+
kvGetAccountStatus: () => Promise<string>;
|
|
45
54
|
kvGetItem: (key: string) => Promise<string | null>;
|
|
46
55
|
kvSetItem: (key: string, value: string) => Promise<void>;
|
|
47
56
|
kvRemoveItem: (key: string) => Promise<void>;
|
|
@@ -128,6 +137,6 @@ export interface Spec extends TurboModule {
|
|
|
128
137
|
readonly onAssetProgress: EventEmitter<AssetProgressNativeEvent>;
|
|
129
138
|
setLogsEnabled: (enabled: boolean) => void;
|
|
130
139
|
}
|
|
131
|
-
declare const _default: Spec | null;
|
|
140
|
+
declare const _default: Spec | null | undefined;
|
|
132
141
|
export default _default;
|
|
133
142
|
//# sourceMappingURL=NativeRNCloudSync.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeRNCloudSync.d.ts","sourceRoot":"","sources":["../../../../src/specs/NativeRNCloudSync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"NativeRNCloudSync.d.ts","sourceRoot":"","sources":["../../../../src/specs/NativeRNCloudSync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAMlE,KAAK,YAAY,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,iBAAiB,CAAA;AAEvF;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,CAAA;AAEpD,MAAM,MAAM,uBAAuB,GAAG;IACpC,IAAI,EAAE,MAAM,EAAE,CAAA;IACd,kFAAkF;IAClF,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,MAAM,MAAM,wBAAwB,GAAG;IACrC,4BAA4B;IAC5B,MAAM,EAAE,MAAM,CAAA;IACd,eAAe,EAAE,OAAO,CAA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AMG;IACH,oBAAoB,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,WAAW,KAAK,OAAO,KAAK,MAAM,CAAA;IAEtE,oEAAoE;IACpE,gBAAgB,EAAE,CAAC,QAAQ,EAAE,aAAa,KAAK,IAAI,CAAA;IAEnD;;;;;OAKG;IACH,cAAc,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,iBAAiB,KAAK,IAAI,KAAK,WAAW,CAAA;IACzE;;;;;;OAMG;IACH,eAAe,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,kBAAkB,KAAK,IAAI,KAAK,WAAW,CAAA;IAE3E,uDAAuD;IACvD,OAAO,EAAE,MAAM,IAAI,CAAA;CACpB;AAED,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,iBAAiB,GAAG;IAAE,aAAa,CAAC,EAAE,aAAa,CAAA;CAAE,GAC7D,UAAU,CA2yCZ"}
|
|
@@ -94,6 +94,15 @@ export interface CloudProvider {
|
|
|
94
94
|
* difference between this and a loop is one request against N.
|
|
95
95
|
*/
|
|
96
96
|
multiGet?: (keys: string[]) => Promise<(string | null)[]>;
|
|
97
|
+
/**
|
|
98
|
+
* {@link multiGet} plus each value's server modification time, in one go.
|
|
99
|
+
*
|
|
100
|
+
* Optional. A resolving `multiGet` whose resolver orders on `modifiedAt`
|
|
101
|
+
* uses this when present, falls back to one {@link getItemWithMeta} per key
|
|
102
|
+
* when only that exists, and to plain {@link multiGet} otherwise - so the
|
|
103
|
+
* batched read resolves exactly as `getItem` would.
|
|
104
|
+
*/
|
|
105
|
+
multiGetWithMeta?: (keys: string[]) => Promise<(ItemWithMeta | null)[]>;
|
|
97
106
|
/** Writes many key/value pairs in one go. Optional, same fallback rule. */
|
|
98
107
|
multiSet?: (entries: [string, string][]) => Promise<void>;
|
|
99
108
|
/** Removes many keys in one go. Optional, same fallback rule. */
|
|
@@ -211,7 +220,20 @@ export interface ResolveCandidate {
|
|
|
211
220
|
* the app knows what its values mean. Returning `null` means "none of these",
|
|
212
221
|
* which reads as absent.
|
|
213
222
|
*/
|
|
214
|
-
export
|
|
223
|
+
export interface ResolveFn {
|
|
224
|
+
(candidates: ResolveCandidate[]): string | null;
|
|
225
|
+
/**
|
|
226
|
+
* Whether this resolver reads {@link ResolveCandidate.modifiedAt}.
|
|
227
|
+
*
|
|
228
|
+
* A batched read only has to fetch server timestamps for a resolver that
|
|
229
|
+
* uses them, and fetching them can cost the batching itself. Left
|
|
230
|
+
* undefined, the store assumes it does and fetches them, so a custom
|
|
231
|
+
* resolver resolves identically through `getItem` and `multiGet`. Set it
|
|
232
|
+
* to `false` on a resolver that never looks at `modifiedAt` to keep
|
|
233
|
+
* `multiGet` a single request per provider. The built-in resolvers set it.
|
|
234
|
+
*/
|
|
235
|
+
usesModifiedAt?: boolean;
|
|
236
|
+
}
|
|
215
237
|
export interface CloudStoreOptions {
|
|
216
238
|
/**
|
|
217
239
|
* Providers in preference order.
|
|
@@ -272,8 +294,14 @@ export interface CloudStoreOptions {
|
|
|
272
294
|
*/
|
|
273
295
|
outboxMaxEntries?: number;
|
|
274
296
|
/**
|
|
275
|
-
* Give up on a queued write after this many failed attempts. Default 12
|
|
276
|
-
*
|
|
297
|
+
* Give up on a queued write after this many failed attempts. Default 12.
|
|
298
|
+
*
|
|
299
|
+
* After the n-th failure the next retry waits 2^n seconds, capped at five
|
|
300
|
+
* minutes (or the server's `Retry-After`, when it sends one). With the
|
|
301
|
+
* default that is 2 + 4 + ... + 256 seconds plus three five-minute waits:
|
|
302
|
+
* about 23.5 minutes from the first retry to the last, at minimum. A retry
|
|
303
|
+
* only happens when a flush runs, so with infrequent flushes it spans longer
|
|
304
|
+
* in wall-clock time - {@link outboxMaxAgeMs} bounds that.
|
|
277
305
|
*/
|
|
278
306
|
outboxMaxAttempts?: number;
|
|
279
307
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names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e,CAAA;IACrC;;;;;;;OAOG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B;;;;;;;;;;;;;;;;;;OAkBG;IACH,KAAK,CAAC,EAAE,UAAU,CAAA;IAClB;;;;;;;;;OASG;IACH,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB;;;;;;;;;OASG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,cAAc,KAAK,IAAI,CAAA;CACtC;AAED;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,2EAA2E;IAC3E,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAA;IAChE,+EAA+E;IAC/E,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAA;CACjE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-cloud-sync",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Sync React Native app data across iCloud key-value store, CloudKit, iCloud Drive and Google Drive behind one API - offline-first with automatic retry, real-time updates and optional end-to-end encryption. iOS, Android, Web, old and new architecture",
|
|
5
5
|
"workspaces": [
|
|
6
6
|
"example"
|
|
@@ -134,35 +134,35 @@
|
|
|
134
134
|
"prepare": "husky && bob build && yarn build-plugin"
|
|
135
135
|
},
|
|
136
136
|
"devDependencies": {
|
|
137
|
-
"@babel/core": "^
|
|
137
|
+
"@babel/core": "^8.1.0",
|
|
138
138
|
"@eslint/js": "^10.0.1",
|
|
139
|
-
"@expo/config-plugins": "^
|
|
140
|
-
"@react-native/babel-preset": "^0.
|
|
141
|
-
"@react-native/eslint-config": "^0.
|
|
142
|
-
"@react-native/jest-preset": "^0.
|
|
143
|
-
"@react-native/metro-config": "^0.
|
|
139
|
+
"@expo/config-plugins": "^58.0.12",
|
|
140
|
+
"@react-native/babel-preset": "^0.88.1",
|
|
141
|
+
"@react-native/eslint-config": "^0.88.1",
|
|
142
|
+
"@react-native/jest-preset": "^0.88.1",
|
|
143
|
+
"@react-native/metro-config": "^0.88.1",
|
|
144
144
|
"@stylistic/eslint-plugin": "^5.10.0",
|
|
145
|
-
"@testing-library/react-native": "^
|
|
146
|
-
"@types/jest": "^
|
|
147
|
-
"@types/node": "^26.
|
|
148
|
-
"@types/react": "^19.
|
|
149
|
-
"@
|
|
150
|
-
"babel-jest": "^
|
|
151
|
-
"del-cli": "^
|
|
152
|
-
"eslint": "^10.
|
|
145
|
+
"@testing-library/react-native": "^14.1.0",
|
|
146
|
+
"@types/jest": "^30.0.0",
|
|
147
|
+
"@types/node": "^26.6.6",
|
|
148
|
+
"@types/react": "^19.3.0",
|
|
149
|
+
"@typescript/native": "npm:typescript@^7.0.2",
|
|
150
|
+
"babel-jest": "^30.5.2",
|
|
151
|
+
"del-cli": "^8.0.1",
|
|
152
|
+
"eslint": "^10.14.0",
|
|
153
153
|
"eslint-plugin-import": "^2.32.0",
|
|
154
154
|
"husky": "^9.1.7",
|
|
155
|
-
"jest": "^
|
|
156
|
-
"lint-staged": "^17.
|
|
157
|
-
"react": "19.
|
|
158
|
-
"react-native": "0.
|
|
159
|
-
"react-native-builder-bob": "^0.
|
|
160
|
-
"
|
|
161
|
-
"typescript": "
|
|
162
|
-
"typescript-eslint": "^8.
|
|
155
|
+
"jest": "^30.5.2",
|
|
156
|
+
"lint-staged": "^17.6.0",
|
|
157
|
+
"react": "19.3.0",
|
|
158
|
+
"react-native": "0.88.1",
|
|
159
|
+
"react-native-builder-bob": "^0.44.1",
|
|
160
|
+
"test-renderer": "^1.3.1",
|
|
161
|
+
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
162
|
+
"typescript-eslint": "^8.72.1"
|
|
163
163
|
},
|
|
164
164
|
"engines": {
|
|
165
|
-
"node": ">=
|
|
165
|
+
"node": "^22.18.0 || >=24.11.0"
|
|
166
166
|
},
|
|
167
167
|
"peerDependencies": {
|
|
168
168
|
"react": "*",
|
|
@@ -192,10 +192,20 @@
|
|
|
192
192
|
"esm": true
|
|
193
193
|
}
|
|
194
194
|
],
|
|
195
|
-
|
|
195
|
+
[
|
|
196
|
+
"typescript",
|
|
197
|
+
{
|
|
198
|
+
"tsc": "./node_modules/@typescript/native/bin/tsc"
|
|
199
|
+
}
|
|
200
|
+
]
|
|
196
201
|
]
|
|
197
202
|
},
|
|
198
203
|
"lint-staged": {
|
|
199
204
|
"*.{ts,tsx}": "eslint --fix"
|
|
205
|
+
},
|
|
206
|
+
"resolutions": {
|
|
207
|
+
"babel-jest": "^30.5.2",
|
|
208
|
+
"glob": "^14.0.3",
|
|
209
|
+
"minimatch": "^11.0.4"
|
|
200
210
|
}
|
|
201
211
|
}
|
package/plugin/build/index.js
CHANGED
|
@@ -2,6 +2,22 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const config_plugins_1 = require("@expo/config-plugins");
|
|
4
4
|
const pkg = require('../../package.json');
|
|
5
|
+
/**
|
|
6
|
+
* What an iCloud container identifier looks like: `iCloud.` followed by a
|
|
7
|
+
* reverse-DNS name. Checked because the value is written verbatim into the
|
|
8
|
+
* signed entitlements and Info.plist - a typo, a wildcard (`iCloud.*`) or a
|
|
9
|
+
* build-setting reference there produces a binary that either fails signing
|
|
10
|
+
* late or asks for a container it should not have.
|
|
11
|
+
*/
|
|
12
|
+
const CONTAINER_IDENTIFIER = /^iCloud\.[A-Za-z0-9_-]+(\.[A-Za-z0-9_-]+)*$/;
|
|
13
|
+
function resolveContainerIdentifier(explicit, bundleId) {
|
|
14
|
+
const containerIdentifier = explicit !== null && explicit !== void 0 ? explicit : (bundleId != null ? `iCloud.${bundleId}` : undefined);
|
|
15
|
+
if (containerIdentifier != null && !CONTAINER_IDENTIFIER.test(containerIdentifier))
|
|
16
|
+
throw new Error(`[react-native-cloud-sync] Invalid iCloud container identifier ${JSON.stringify(containerIdentifier)}. `
|
|
17
|
+
+ 'Expected iCloud.<reverse-dns>, e.g. iCloud.com.example.app: '
|
|
18
|
+
+ 'letters, digits, - and _ separated by dots, no wildcards.');
|
|
19
|
+
return containerIdentifier;
|
|
20
|
+
}
|
|
5
21
|
/**
|
|
6
22
|
* Adds the iCloud entitlements this package needs.
|
|
7
23
|
*
|
|
@@ -17,9 +33,10 @@ const withCloudSync = (config, options) => {
|
|
|
17
33
|
const cloudKit = (_b = opts.cloudKit) !== null && _b !== void 0 ? _b : true;
|
|
18
34
|
const iCloudDocuments = (_c = opts.iCloudDocuments) !== null && _c !== void 0 ? _c : false;
|
|
19
35
|
const withEntitlements = (0, config_plugins_1.withEntitlementsPlist)(config, (mod) => {
|
|
20
|
-
var _a, _b
|
|
21
|
-
|
|
22
|
-
const
|
|
36
|
+
var _a, _b;
|
|
37
|
+
var _c, _d, _e, _f;
|
|
38
|
+
const bundleId = (_c = (_a = mod.ios) === null || _a === void 0 ? void 0 : _a.bundleIdentifier) !== null && _c !== void 0 ? _c : (_b = config.ios) === null || _b === void 0 ? void 0 : _b.bundleIdentifier;
|
|
39
|
+
const containerIdentifier = resolveContainerIdentifier(opts.containerIdentifier, bundleId);
|
|
23
40
|
if (containerIdentifier == null)
|
|
24
41
|
throw new Error('[react-native-cloud-sync] Cannot derive an iCloud container identifier. Set '
|
|
25
42
|
+ 'ios.bundleIdentifier in app config, or pass containerIdentifier to the plugin.');
|
|
@@ -30,10 +47,10 @@ const withCloudSync = (config, options) => {
|
|
|
30
47
|
// Assigning the container list outright silently dropped every container
|
|
31
48
|
// the app already had, which breaks that other feature at runtime with no
|
|
32
49
|
// build error to point at.
|
|
33
|
-
const containers = new Set((
|
|
50
|
+
const containers = new Set((_d = entitlements['com.apple.developer.icloud-container-identifiers']) !== null && _d !== void 0 ? _d : []);
|
|
34
51
|
containers.add(containerIdentifier);
|
|
35
52
|
entitlements['com.apple.developer.icloud-container-identifiers'] = [...containers];
|
|
36
|
-
const services = new Set((
|
|
53
|
+
const services = new Set((_e = entitlements['com.apple.developer.icloud-services']) !== null && _e !== void 0 ? _e : []);
|
|
37
54
|
if (cloudKit)
|
|
38
55
|
services.add('CloudKit');
|
|
39
56
|
// The `icloudDocuments` provider writes to the ubiquity container's
|
|
@@ -46,7 +63,7 @@ const withCloudSync = (config, options) => {
|
|
|
46
63
|
if (iCloudDocuments) {
|
|
47
64
|
// Required alongside the service for document-scope access. Merged for
|
|
48
65
|
// the same reason as the list above.
|
|
49
|
-
const ubiquity = new Set((
|
|
66
|
+
const ubiquity = new Set((_f = entitlements['com.apple.developer.ubiquity-container-identifiers']) !== null && _f !== void 0 ? _f : []);
|
|
50
67
|
ubiquity.add(containerIdentifier);
|
|
51
68
|
entitlements['com.apple.developer.ubiquity-container-identifiers'] = [...ubiquity];
|
|
52
69
|
}
|
|
@@ -58,7 +75,7 @@ const withCloudSync = (config, options) => {
|
|
|
58
75
|
= '$(TeamIdentifierPrefix)$(CFBundleIdentifier)';
|
|
59
76
|
return mod;
|
|
60
77
|
});
|
|
61
|
-
if (!iCloudDocuments)
|
|
78
|
+
if (!cloudKit && !iCloudDocuments)
|
|
62
79
|
return withEntitlements;
|
|
63
80
|
// Entitlements alone get the folder syncing but leave it invisible. Files.app
|
|
64
81
|
// only shows a container that declares `NSUbiquitousContainers` with
|
|
@@ -66,20 +83,35 @@ const withCloudSync = (config, options) => {
|
|
|
66
83
|
// app reaches for this provider instead of a CKAsset, so writing one without
|
|
67
84
|
// the other would ship a feature that silently does not do its job.
|
|
68
85
|
return (0, config_plugins_1.withInfoPlist)(withEntitlements, (mod) => {
|
|
69
|
-
var _a, _b
|
|
70
|
-
|
|
71
|
-
const
|
|
86
|
+
var _a, _b;
|
|
87
|
+
var _c, _d, _e, _f, _g, _h;
|
|
88
|
+
const bundleId = (_c = (_a = mod.ios) === null || _a === void 0 ? void 0 : _a.bundleIdentifier) !== null && _c !== void 0 ? _c : (_b = config.ios) === null || _b === void 0 ? void 0 : _b.bundleIdentifier;
|
|
89
|
+
const containerIdentifier = resolveContainerIdentifier(opts.containerIdentifier, bundleId);
|
|
72
90
|
if (containerIdentifier == null)
|
|
73
91
|
return mod;
|
|
92
|
+
// Entitlements live in the code signature and cannot be read back at
|
|
93
|
+
// runtime, so the native side looks the container up here. Without it a
|
|
94
|
+
// `containerIdentifier` passed to this plugin never reached native code,
|
|
95
|
+
// which fell back to `iCloud.<bundle id>` - a different container from the
|
|
96
|
+
// one entitled above whenever the two differ.
|
|
97
|
+
//
|
|
98
|
+
// Only with CloudKit on. Native code builds a CKContainer from this key,
|
|
99
|
+
// and doing that without the CloudKit service traps inside CloudKit. The
|
|
100
|
+
// documents container has its own key for that reason.
|
|
101
|
+
if (cloudKit)
|
|
102
|
+
mod.modResults.RNCloudSyncContainerIdentifier = containerIdentifier;
|
|
103
|
+
if (!iCloudDocuments)
|
|
104
|
+
return mod;
|
|
105
|
+
mod.modResults.RNCloudSyncDocumentsContainerIdentifier = containerIdentifier;
|
|
74
106
|
// Merged, not replaced: an app may already declare a second container here
|
|
75
107
|
// for an unrelated document feature, and overwriting the map would break it
|
|
76
108
|
// at runtime with nothing in the build to point at.
|
|
77
|
-
const existing = (
|
|
109
|
+
const existing = (_d = mod.modResults.NSUbiquitousContainers) !== null && _d !== void 0 ? _d : {};
|
|
78
110
|
const containers = {
|
|
79
111
|
...existing,
|
|
80
112
|
[containerIdentifier]: {
|
|
81
|
-
NSUbiquitousContainerIsDocumentScopePublic: (
|
|
82
|
-
NSUbiquitousContainerName: (
|
|
113
|
+
NSUbiquitousContainerIsDocumentScopePublic: (_e = opts.documentsVisibleInFiles) !== null && _e !== void 0 ? _e : true,
|
|
114
|
+
NSUbiquitousContainerName: (_h = (_g = (_f = opts.documentsFolderName) !== null && _f !== void 0 ? _f : mod.name) !== null && _g !== void 0 ? _g : config.name) !== null && _h !== void 0 ? _h : 'Documents',
|
|
83
115
|
NSUbiquitousContainerSupportedFolderLevels: 'Any',
|
|
84
116
|
},
|
|
85
117
|
};
|
|
@@ -25,9 +25,6 @@ Pod::Spec.new do |s|
|
|
|
25
25
|
# NSUbiquitousKeyValueStore. Both are available under Mac Catalyst.
|
|
26
26
|
s.frameworks = 'CloudKit', 'Foundation'
|
|
27
27
|
|
|
28
|
-
# React Native core dependency, codegen wiring and the new-arch flags.
|
|
29
|
-
install_modules_dependencies(s)
|
|
30
|
-
|
|
31
28
|
# Built up locally and assigned once: `pod_target_xcconfig` is a writer on
|
|
32
29
|
# Pod::Specification with no matching reader, so it cannot be read back and
|
|
33
30
|
# merged into.
|
|
@@ -45,4 +42,14 @@ Pod::Spec.new do |s|
|
|
|
45
42
|
end
|
|
46
43
|
|
|
47
44
|
s.pod_target_xcconfig = xcconfig
|
|
45
|
+
|
|
46
|
+
# React Native core dependency, codegen wiring and the new-arch flags.
|
|
47
|
+
#
|
|
48
|
+
# Must come LAST. It reads the spec's current `compiler_flags` and
|
|
49
|
+
# `pod_target_xcconfig` back out of `spec.to_hash` and merges React Native's
|
|
50
|
+
# header search paths, C++ standard and folly flags into them. Called before
|
|
51
|
+
# the assignments above, it had all of that overwritten - leaving the pod on
|
|
52
|
+
# c++17 with none of React Native's header paths, which breaks the
|
|
53
|
+
# new-architecture build on any React Native that requires C++20 (0.73+).
|
|
54
|
+
install_modules_dependencies(s)
|
|
48
55
|
end
|
package/src/hooks.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
|
|
2
2
|
|
|
3
3
|
import type { CloudStore } from './store'
|
|
4
4
|
import { normalizeError, type CloudSyncError } from './errors'
|
|
5
|
+
import { hasOwn, setOwn } from './internal/records'
|
|
5
6
|
import type {
|
|
6
7
|
AccountChangeEvent,
|
|
7
8
|
AccountStatus,
|
|
@@ -123,9 +124,20 @@ export function useCloudItem<T = unknown>(
|
|
|
123
124
|
}
|
|
124
125
|
}, [store, key])
|
|
125
126
|
|
|
127
|
+
const initialRef = useRef(initialValue)
|
|
128
|
+
initialRef.current = initialValue
|
|
129
|
+
const loadedKey = useRef(key)
|
|
130
|
+
|
|
126
131
|
useEffect(() => {
|
|
132
|
+
// A different key: the value on screen belongs to the previous one. Fall
|
|
133
|
+
// back to `initialValue` while the new key loads rather than showing the
|
|
134
|
+
// old key's value under the new key's name.
|
|
135
|
+
if (loadedKey.current !== key) {
|
|
136
|
+
loadedKey.current = key
|
|
137
|
+
setLocalValue(initialRef.current)
|
|
138
|
+
}
|
|
127
139
|
void read()
|
|
128
|
-
}, [read])
|
|
140
|
+
}, [read, key])
|
|
129
141
|
|
|
130
142
|
useEffect(() => {
|
|
131
143
|
if (!watch) return
|
|
@@ -144,7 +156,10 @@ export function useCloudItem<T = unknown>(
|
|
|
144
156
|
// discard a value the outbox is still going to deliver.
|
|
145
157
|
setLocalValue(next)
|
|
146
158
|
// Invalidate any read in flight, so its older answer cannot land on top.
|
|
159
|
+
// That read's `finally` will no longer clear `loading`, so clear it here:
|
|
160
|
+
// the local value is now the current one.
|
|
147
161
|
ticket.current += 1
|
|
162
|
+
setLoading(false)
|
|
148
163
|
try {
|
|
149
164
|
await store.setItem(key, serialize(next))
|
|
150
165
|
if (mounted.current) setError(null)
|
|
@@ -158,6 +173,7 @@ export function useCloudItem<T = unknown>(
|
|
|
158
173
|
const remove = useCallback(async (): Promise<void> => {
|
|
159
174
|
setLocalValue(null)
|
|
160
175
|
ticket.current += 1
|
|
176
|
+
setLoading(false)
|
|
161
177
|
try {
|
|
162
178
|
await store.removeItem(key)
|
|
163
179
|
if (mounted.current) setError(null)
|
|
@@ -287,7 +303,11 @@ export function useCloudItems<T = unknown>(
|
|
|
287
303
|
// A write or a newer fetch already claimed this key - this answer
|
|
288
304
|
// is no longer the current one.
|
|
289
305
|
if (keyTicket.current.get(k) !== mine.get(k)) continue
|
|
290
|
-
|
|
306
|
+
// Left the tracked list while this fetch was in flight. Storing it
|
|
307
|
+
// would also mark it "already fetched", so if it rejoined later it
|
|
308
|
+
// would show this answer instead of being fetched again.
|
|
309
|
+
if (!keysRef.current.includes(k)) continue
|
|
310
|
+
setOwn(next, k, raw == null ? null : parseRef.current(raw))
|
|
291
311
|
}
|
|
292
312
|
return next
|
|
293
313
|
})
|
|
@@ -308,14 +328,17 @@ export function useCloudItems<T = unknown>(
|
|
|
308
328
|
const hasLoadedOnce = useRef(false)
|
|
309
329
|
useEffect(() => {
|
|
310
330
|
const current = keysRef.current
|
|
311
|
-
|
|
331
|
+
// Own properties only: `in` also sees Object.prototype, so a key named
|
|
332
|
+
// `constructor` or `toString` was treated as already fetched and never
|
|
333
|
+
// loaded.
|
|
334
|
+
const missing = current.filter(k => !hasOwn(valuesRef.current, k))
|
|
312
335
|
|
|
313
336
|
const keep = new Set(current)
|
|
314
337
|
setValues((prev) => {
|
|
315
338
|
let changed = false
|
|
316
339
|
const next: Record<string, T | null> = {}
|
|
317
340
|
for (const k of Object.keys(prev))
|
|
318
|
-
if (keep.has(k)) next
|
|
341
|
+
if (keep.has(k)) setOwn(next, k, prev[k])
|
|
319
342
|
else changed = true
|
|
320
343
|
|
|
321
344
|
return changed ? next : prev
|
|
@@ -421,10 +444,37 @@ export function useCloudCollection<T = unknown>(
|
|
|
421
444
|
}
|
|
422
445
|
}, [])
|
|
423
446
|
|
|
447
|
+
/**
|
|
448
|
+
* Local membership changes, in order, so a listing that was already in
|
|
449
|
+
* flight when one happened cannot undo it: a key created by `setValue`
|
|
450
|
+
* while `getAllKeys` was running would otherwise vanish from the list when
|
|
451
|
+
* the older listing landed, and a removed key would reappear.
|
|
452
|
+
*/
|
|
453
|
+
const localOps = useRef<{ seq: number; key: string; op: 'add' | 'remove' }[]>([])
|
|
454
|
+
const opSeq = useRef(0)
|
|
455
|
+
const listTicket = useRef(0)
|
|
456
|
+
|
|
457
|
+
const recordOp = (key: string, op: 'add' | 'remove'): void => {
|
|
458
|
+
opSeq.current += 1
|
|
459
|
+
localOps.current.push({ seq: opSeq.current, key, op })
|
|
460
|
+
}
|
|
461
|
+
|
|
424
462
|
const listKeys = useCallback(async (): Promise<void> => {
|
|
463
|
+
const mine = ++listTicket.current
|
|
464
|
+
const startedAt = opSeq.current
|
|
425
465
|
const all = await store.getAllKeys()
|
|
426
|
-
|
|
427
|
-
|
|
466
|
+
// A newer listing started after this one; its answer is the fresher one.
|
|
467
|
+
if (!mounted.current || listTicket.current !== mine) return
|
|
468
|
+
|
|
469
|
+
const listed = new Set(all.filter(k => k.startsWith(prefix)))
|
|
470
|
+
for (const { seq, key, op } of localOps.current) {
|
|
471
|
+
if (seq <= startedAt) continue
|
|
472
|
+
if (op === 'add') listed.add(key)
|
|
473
|
+
else listed.delete(key)
|
|
474
|
+
}
|
|
475
|
+
// Everything up to this listing's start is reflected in what it saw.
|
|
476
|
+
localOps.current = localOps.current.filter(o => o.seq > startedAt)
|
|
477
|
+
setKeys([...listed])
|
|
428
478
|
}, [store, prefix])
|
|
429
479
|
|
|
430
480
|
useEffect(() => {
|
|
@@ -445,12 +495,16 @@ export function useCloudCollection<T = unknown>(
|
|
|
445
495
|
const items = useCloudItems<T>(store, keys, options)
|
|
446
496
|
|
|
447
497
|
const setValue = useCallback(async (key: string, next: T): Promise<void> => {
|
|
448
|
-
if (key.startsWith(prefix))
|
|
498
|
+
if (key.startsWith(prefix)) {
|
|
499
|
+
recordOp(key, 'add')
|
|
500
|
+
setKeys(prev => (prev.includes(key) ? prev : [...prev, key]))
|
|
501
|
+
}
|
|
449
502
|
await items.setValue(key, next)
|
|
450
503
|
}, [items, prefix])
|
|
451
504
|
|
|
452
505
|
const remove = useCallback(async (key: string): Promise<void> => {
|
|
453
506
|
await items.remove(key)
|
|
507
|
+
recordOp(key, 'remove')
|
|
454
508
|
setKeys(prev => (prev.includes(key) ? prev.filter(k => k !== key) : prev))
|
|
455
509
|
}, [items])
|
|
456
510
|
|
|
@@ -499,15 +553,20 @@ export function useAccountStatus(provider: CloudProvider): UseAccountStatusResul
|
|
|
499
553
|
}
|
|
500
554
|
}, [])
|
|
501
555
|
|
|
556
|
+
// Bumped by every refresh and every account event, so a status query that
|
|
557
|
+
// was in flight when an event arrived cannot overwrite the newer status.
|
|
558
|
+
const ticket = useRef(0)
|
|
559
|
+
|
|
502
560
|
const refresh = useCallback(async (): Promise<void> => {
|
|
561
|
+
const mine = ++ticket.current
|
|
503
562
|
try {
|
|
504
563
|
const next = await provider.getAccountStatus()
|
|
505
|
-
if (!mounted.current) return
|
|
564
|
+
if (!mounted.current || ticket.current !== mine) return
|
|
506
565
|
setStatus(next)
|
|
507
566
|
setError(null)
|
|
508
567
|
}
|
|
509
568
|
catch (e) {
|
|
510
|
-
if (mounted.current) setError(normalizeError(e))
|
|
569
|
+
if (mounted.current && ticket.current === mine) setError(normalizeError(e))
|
|
511
570
|
}
|
|
512
571
|
}, [provider])
|
|
513
572
|
|
|
@@ -518,6 +577,7 @@ export function useAccountStatus(provider: CloudProvider): UseAccountStatusResul
|
|
|
518
577
|
useEffect(() => {
|
|
519
578
|
if (provider.onAccountChange == null) return
|
|
520
579
|
return provider.onAccountChange((e: AccountChangeEvent) => {
|
|
580
|
+
ticket.current += 1
|
|
521
581
|
setStatus(e.status)
|
|
522
582
|
if (e.identityChanged) setIdentityChanged(true)
|
|
523
583
|
})
|
|
@@ -62,7 +62,16 @@ export function attachAutoFlush(
|
|
|
62
62
|
let appStateSub: { remove: () => void } | null = null
|
|
63
63
|
|
|
64
64
|
if (intervalMs > 0) {
|
|
65
|
-
timer
|
|
65
|
+
// "While the app is in the foreground": a timer can still fire in the
|
|
66
|
+
// background (headless JS, a background fetch window), and a flush there
|
|
67
|
+
// spends the user's background budget on network nobody is waiting for.
|
|
68
|
+
// An unknown state is treated as foreground so the interval never
|
|
69
|
+
// silently stops working.
|
|
70
|
+
timer = setInterval(() => {
|
|
71
|
+
const state = AppState.currentState
|
|
72
|
+
if (state != null && state !== 'active' && state !== 'unknown') return
|
|
73
|
+
safeFlush()
|
|
74
|
+
}, intervalMs)
|
|
66
75
|
// A pending retry must never be the reason a process stays alive.
|
|
67
76
|
timer.unref?.()
|
|
68
77
|
}
|
package/src/internal/base64.ts
CHANGED
|
@@ -42,17 +42,20 @@ export function bytesToBase64(bytes: Uint8Array): string {
|
|
|
42
42
|
export function base64ToBytes(base64: string): Uint8Array {
|
|
43
43
|
// Strip whitespace some fs libraries insert into long base64 strings, and
|
|
44
44
|
// any padding - length is derived from the real character count instead.
|
|
45
|
-
const clean = base64.replace(
|
|
45
|
+
const clean = base64.replace(/\s/g, '').replace(/={1,2}$/, '')
|
|
46
46
|
const len = clean.length
|
|
47
|
+
// One leftover character carries 6 bits - not a byte. Real base64 never
|
|
48
|
+
// ends that way, so it is truncated or not base64 at all.
|
|
49
|
+
if (len % 4 === 1) throw invalidBase64()
|
|
47
50
|
const outLen = Math.floor((len * 3) / 4)
|
|
48
51
|
const bytes = new Uint8Array(outLen)
|
|
49
52
|
|
|
50
53
|
let p = 0
|
|
51
54
|
for (let i = 0; i < len; i += 4) {
|
|
52
|
-
const e0 =
|
|
53
|
-
const e1 = i + 1 < len ?
|
|
54
|
-
const e2 = i + 2 < len ?
|
|
55
|
-
const e3 = i + 3 < len ?
|
|
55
|
+
const e0 = sextet(clean, i)
|
|
56
|
+
const e1 = i + 1 < len ? sextet(clean, i + 1) : 0
|
|
57
|
+
const e2 = i + 2 < len ? sextet(clean, i + 2) : 0
|
|
58
|
+
const e3 = i + 3 < len ? sextet(clean, i + 3) : 0
|
|
56
59
|
|
|
57
60
|
if (p < outLen) bytes[p++] = (e0 << 2) | (e1 >> 4)
|
|
58
61
|
if (p < outLen) bytes[p++] = ((e1 & 0x0f) << 4) | (e2 >> 2)
|
|
@@ -61,3 +64,21 @@ export function base64ToBytes(base64: string): Uint8Array {
|
|
|
61
64
|
|
|
62
65
|
return bytes
|
|
63
66
|
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The 6-bit value at `i`, rejecting anything outside the alphabet.
|
|
70
|
+
*
|
|
71
|
+
* Silently mapping an invalid character to -1 used to write `0xFC`-style
|
|
72
|
+
* garbage into the output, so a corrupted or non-base64 chunk from a file
|
|
73
|
+
* adapter became a corrupted upload or restore with no error anywhere.
|
|
74
|
+
*/
|
|
75
|
+
function sextet(s: string, i: number): number {
|
|
76
|
+
const code = s.charCodeAt(i)
|
|
77
|
+
const v = code < 128 ? DECODE_TABLE[code] : -1
|
|
78
|
+
if (v < 0) throw invalidBase64()
|
|
79
|
+
return v
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function invalidBase64(): TypeError {
|
|
83
|
+
return new TypeError('[RNCloudSync] base64ToBytes: input is not valid base64.')
|
|
84
|
+
}
|