react-native-cloud-sync 0.3.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 +116 -58
- 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 +309 -3
- 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 +307 -3
- package/lib/module/hooks.js.map +1 -1
- package/lib/module/index.js +2 -2
- 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 +68 -0
- package/lib/typescript/commonjs/hooks.d.ts.map +1 -1
- package/lib/typescript/commonjs/index.d.ts +2 -2
- 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 +68 -0
- package/lib/typescript/module/hooks.d.ts.map +1 -1
- package/lib/typescript/module/index.d.ts +2 -2
- 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 +36 -23
- package/plugin/build/index.js +45 -13
- package/react-native-cloud-sync.podspec +10 -3
- package/src/hooks.ts +357 -3
- package/src/index.ts +2 -2
- 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
package/src/resolvers.ts
CHANGED
|
@@ -17,7 +17,7 @@ import type { ResolveCandidate, ResolveFn } from './types'
|
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
19
19
|
export function resolveByTimestamp(field = 'updatedAt'): ResolveFn {
|
|
20
|
-
return (candidates: ResolveCandidate[]): string | null => {
|
|
20
|
+
return declare(false, (candidates: ResolveCandidate[]): string | null => {
|
|
21
21
|
if (candidates.length === 0) return null
|
|
22
22
|
|
|
23
23
|
let best: ResolveCandidate | null = null
|
|
@@ -36,7 +36,19 @@ export function resolveByTimestamp(field = 'updatedAt'): ResolveFn {
|
|
|
36
36
|
// Nothing was datable: fall back to preference order rather than guessing.
|
|
37
37
|
if (best == null) return candidates[0].value
|
|
38
38
|
return best.value
|
|
39
|
-
}
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Tags a resolver with whether it reads `modifiedAt` - see {@link ResolveFn.usesModifiedAt}. */
|
|
43
|
+
function declare(usesModifiedAt: boolean, fn: (c: ResolveCandidate[]) => string | null): ResolveFn {
|
|
44
|
+
const resolver: ResolveFn = fn
|
|
45
|
+
resolver.usesModifiedAt = usesModifiedAt
|
|
46
|
+
return resolver
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Unknown counts as "uses it": over-fetching is slower, under-fetching is wrong. */
|
|
50
|
+
function needsModifiedAt(resolver: ResolveFn): boolean {
|
|
51
|
+
return resolver.usesModifiedAt !== false
|
|
40
52
|
}
|
|
41
53
|
|
|
42
54
|
function timestampOf(value: string, field: string): number {
|
|
@@ -58,8 +70,8 @@ function timestampOf(value: string, field: string): number {
|
|
|
58
70
|
}
|
|
59
71
|
|
|
60
72
|
/** Always takes the first provider that has a value. The default behaviour. */
|
|
61
|
-
export const resolveByPreferenceOrder: ResolveFn = candidates =>
|
|
62
|
-
candidates.length > 0 ? candidates[0].value : null
|
|
73
|
+
export const resolveByPreferenceOrder: ResolveFn = declare(false, candidates =>
|
|
74
|
+
candidates.length > 0 ? candidates[0].value : null)
|
|
63
75
|
|
|
64
76
|
/**
|
|
65
77
|
* Resolves by the *server's* last-modified time rather than a timestamp inside
|
|
@@ -91,7 +103,7 @@ export function resolveByModifiedAt(
|
|
|
91
103
|
): ResolveFn {
|
|
92
104
|
const fallback = options.fallback ?? resolveByPreferenceOrder
|
|
93
105
|
|
|
94
|
-
return (candidates: ResolveCandidate[]): string | null => {
|
|
106
|
+
return declare(true, (candidates: ResolveCandidate[]): string | null => {
|
|
95
107
|
if (candidates.length === 0) return null
|
|
96
108
|
|
|
97
109
|
const dated = candidates.filter(
|
|
@@ -109,7 +121,7 @@ export function resolveByModifiedAt(
|
|
|
109
121
|
for (const candidate of dated) if (candidate.modifiedAt > best.modifiedAt) best = candidate
|
|
110
122
|
|
|
111
123
|
return best.value
|
|
112
|
-
}
|
|
124
|
+
})
|
|
113
125
|
}
|
|
114
126
|
|
|
115
127
|
/**
|
|
@@ -153,7 +165,7 @@ export function resolveByUnion<T = unknown>(
|
|
|
153
165
|
): ResolveFn {
|
|
154
166
|
const keyOf = options.key ?? ((item: T) => JSON.stringify(item))
|
|
155
167
|
|
|
156
|
-
return (candidates: ResolveCandidate[]): string | null => {
|
|
168
|
+
return declare(false, (candidates: ResolveCandidate[]): string | null => {
|
|
157
169
|
if (candidates.length === 0) return null
|
|
158
170
|
|
|
159
171
|
const merged = new Map<string | number, T>()
|
|
@@ -174,7 +186,7 @@ export function resolveByUnion<T = unknown>(
|
|
|
174
186
|
if (!sawArray) return candidates[0].value
|
|
175
187
|
|
|
176
188
|
return JSON.stringify([...merged.values()])
|
|
177
|
-
}
|
|
189
|
+
})
|
|
178
190
|
}
|
|
179
191
|
|
|
180
192
|
function arrayOf<T>(value: string): T[] | null {
|
|
@@ -190,19 +202,22 @@ function arrayOf<T>(value: string): T[] | null {
|
|
|
190
202
|
/**
|
|
191
203
|
* Tries each resolver in turn and takes the first non-null answer.
|
|
192
204
|
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
205
|
+
* Only resolvers that can return `null` for a non-empty candidate list let a
|
|
206
|
+
* later one run. {@link resolveByModifiedAt} never does - with nothing dated it
|
|
207
|
+
* defers to its own `fallback` - so for "server time where the provider
|
|
208
|
+
* reports it, an embedded timestamp where it does not", pass the second one as
|
|
209
|
+
* that fallback instead:
|
|
195
210
|
*
|
|
196
211
|
* ```ts
|
|
197
|
-
*
|
|
212
|
+
* resolveByModifiedAt({ fallback: resolveByTimestamp('updatedAt') })
|
|
198
213
|
* ```
|
|
199
214
|
*/
|
|
200
215
|
export function resolveFirstOf(...resolvers: ResolveFn[]): ResolveFn {
|
|
201
|
-
return (candidates: ResolveCandidate[]): string | null => {
|
|
216
|
+
return declare(resolvers.some(needsModifiedAt), (candidates: ResolveCandidate[]): string | null => {
|
|
202
217
|
for (const resolve of resolvers) {
|
|
203
218
|
const answer = resolve(candidates)
|
|
204
219
|
if (answer != null) return answer
|
|
205
220
|
}
|
|
206
221
|
return null
|
|
207
|
-
}
|
|
222
|
+
})
|
|
208
223
|
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import type { TurboModule } from 'react-native'
|
|
1
|
+
import type { EventSubscription, TurboModule } from 'react-native'
|
|
2
2
|
import { TurboModuleRegistry } from 'react-native'
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
// Same shape as React Native's own codegen `EventEmitter`. Declared here so the
|
|
5
|
+
// spec neither deep-imports a path newer type packages drop nor needs the
|
|
6
|
+
// `CodegenTypes` namespace older codegen cannot parse.
|
|
7
|
+
type EventEmitter<T> = (handler: (arg: T) => void | Promise<void>) => EventSubscription
|
|
4
8
|
|
|
5
9
|
/**
|
|
6
10
|
* Codegen cannot express an index signature, so dynamic dictionaries cross the
|
|
@@ -53,6 +57,16 @@ export interface Spec extends TurboModule {
|
|
|
53
57
|
|
|
54
58
|
// ------------------------------------------- iCloud key-value store (KVS)
|
|
55
59
|
|
|
60
|
+
/**
|
|
61
|
+
* Account status for the key-value store, from `ubiquityIdentityToken`.
|
|
62
|
+
*
|
|
63
|
+
* Unlike `getAccountStatus` this never touches CloudKit, so it is safe in an
|
|
64
|
+
* app with only the key-value-store entitlement - constructing a
|
|
65
|
+
* `CKContainer` there raises an uncatchable `CKException`. Reports only
|
|
66
|
+
* `available` or `noAccount`.
|
|
67
|
+
*/
|
|
68
|
+
kvGetAccountStatus: () => Promise<string>
|
|
69
|
+
|
|
56
70
|
kvGetItem: (key: string) => Promise<string | null>
|
|
57
71
|
kvSetItem: (key: string, value: string) => Promise<void>
|
|
58
72
|
kvRemoveItem: (key: string) => Promise<void>
|