react-native-cloud-storage 2.2.1 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. package/LICENSE +1 -1
  2. package/android/build.gradle +101 -0
  3. package/android/gradle.properties +5 -0
  4. package/android/src/main/AndroidManifest.xml +3 -0
  5. package/android/src/main/AndroidManifestNew.xml +2 -0
  6. package/android/src/main/java/com/voicekit/CloudStorageError.kt +86 -0
  7. package/android/src/main/java/com/voicekit/CloudStorageLocalFileSystemModule.kt +236 -0
  8. package/android/src/main/java/com/voicekit/CloudStoragePackage.kt +17 -0
  9. package/android/src/main/java/com/voicekit/FileUtils.kt +41 -0
  10. package/android/src/main/java/com/voicekit/Types.kt +6 -0
  11. package/app.plugin.js +1 -1
  12. package/{lib/commonjs/RNCloudStorage.js → dist/commonjs/cloud-storage.js} +130 -80
  13. package/dist/commonjs/cloud-storage.js.map +1 -0
  14. package/dist/commonjs/expo-plugin/index.js +13 -0
  15. package/dist/commonjs/expo-plugin/index.js.map +1 -0
  16. package/{lib/commonjs/expo-plugin/withRNCloudStorageIos.js → dist/commonjs/expo-plugin/ios.js} +1 -1
  17. package/dist/commonjs/expo-plugin/ios.js.map +1 -0
  18. package/{lib/commonjs/hooks/useCloudFile.js → dist/commonjs/hooks/use-cloud-file.js} +26 -8
  19. package/dist/commonjs/hooks/use-cloud-file.js.map +1 -0
  20. package/{lib/commonjs/hooks/useIsCloudAvailable.js → dist/commonjs/hooks/use-is-cloud-available.js} +3 -3
  21. package/dist/commonjs/hooks/use-is-cloud-available.js.map +1 -0
  22. package/{lib → dist}/commonjs/index.js +10 -10
  23. package/dist/commonjs/index.js.map +1 -0
  24. package/dist/commonjs/storages/cloudkit.js +10 -0
  25. package/dist/commonjs/storages/cloudkit.js.map +1 -0
  26. package/{lib/commonjs → dist/commonjs/storages}/google-drive/client.js +82 -39
  27. package/dist/commonjs/storages/google-drive/client.js.map +1 -0
  28. package/{lib/commonjs → dist/commonjs/storages}/google-drive/index.js +120 -64
  29. package/dist/commonjs/storages/google-drive/index.js.map +1 -0
  30. package/dist/commonjs/storages/google-drive/types.js.map +1 -0
  31. package/dist/commonjs/types/native.js +28 -0
  32. package/dist/commonjs/types/native.js.map +1 -0
  33. package/{lib/commonjs/utils/CloudStorageError.js → dist/commonjs/utils/cloud-storage-error.js} +3 -1
  34. package/dist/commonjs/utils/cloud-storage-error.js.map +1 -0
  35. package/dist/commonjs/utils/constants.js +24 -0
  36. package/dist/commonjs/utils/constants.js.map +1 -0
  37. package/dist/commonjs/utils/local-fs.js +16 -0
  38. package/dist/commonjs/utils/local-fs.js.map +1 -0
  39. package/dist/commonjs/utils/native.js +35 -0
  40. package/dist/commonjs/utils/native.js.map +1 -0
  41. package/{lib/module/RNCloudStorage.js → dist/module/cloud-storage.js} +130 -80
  42. package/dist/module/cloud-storage.js.map +1 -0
  43. package/dist/module/expo-plugin/index.js +8 -0
  44. package/dist/module/expo-plugin/index.js.map +1 -0
  45. package/{lib/module/expo-plugin/withRNCloudStorageIos.js → dist/module/expo-plugin/ios.js} +1 -1
  46. package/dist/module/expo-plugin/ios.js.map +1 -0
  47. package/{lib/module/hooks/useCloudFile.js → dist/module/hooks/use-cloud-file.js} +25 -7
  48. package/dist/module/hooks/use-cloud-file.js.map +1 -0
  49. package/{lib/module/hooks/useIsCloudAvailable.js → dist/module/hooks/use-is-cloud-available.js} +2 -2
  50. package/dist/module/hooks/use-is-cloud-available.js.map +1 -0
  51. package/dist/module/index.js +9 -0
  52. package/dist/module/index.js.map +1 -0
  53. package/dist/module/storages/cloudkit.js +6 -0
  54. package/dist/module/storages/cloudkit.js.map +1 -0
  55. package/{lib/module → dist/module/storages}/google-drive/client.js +82 -39
  56. package/dist/module/storages/google-drive/client.js.map +1 -0
  57. package/{lib/module → dist/module/storages}/google-drive/index.js +119 -62
  58. package/dist/module/storages/google-drive/index.js.map +1 -0
  59. package/dist/module/storages/google-drive/types.js.map +1 -0
  60. package/dist/module/types/native.js +24 -0
  61. package/dist/module/types/native.js.map +1 -0
  62. package/{lib/module/utils/CloudStorageError.js → dist/module/utils/cloud-storage-error.js} +3 -1
  63. package/dist/module/utils/cloud-storage-error.js.map +1 -0
  64. package/dist/module/utils/constants.js +20 -0
  65. package/dist/module/utils/constants.js.map +1 -0
  66. package/dist/module/utils/local-fs.js +12 -0
  67. package/dist/module/utils/local-fs.js.map +1 -0
  68. package/dist/module/utils/native.js +30 -0
  69. package/dist/module/utils/native.js.map +1 -0
  70. package/{lib/typescript/RNCloudStorage.d.ts → dist/typescript/cloud-storage.d.ts} +60 -8
  71. package/dist/typescript/cloud-storage.d.ts.map +1 -0
  72. package/{lib/typescript/expo-plugin/withRNCloudStorage.d.ts → dist/typescript/expo-plugin/index.d.ts} +1 -1
  73. package/dist/typescript/expo-plugin/index.d.ts.map +1 -0
  74. package/{lib/typescript/expo-plugin/withRNCloudStorageIos.d.ts → dist/typescript/expo-plugin/ios.d.ts} +1 -1
  75. package/dist/typescript/expo-plugin/ios.d.ts.map +1 -0
  76. package/{lib/typescript/hooks/useCloudFile.d.ts → dist/typescript/hooks/use-cloud-file.d.ts} +22 -4
  77. package/dist/typescript/hooks/use-cloud-file.d.ts.map +1 -0
  78. package/{lib/typescript/hooks/useIsCloudAvailable.d.ts → dist/typescript/hooks/use-is-cloud-available.d.ts} +2 -2
  79. package/dist/typescript/hooks/use-is-cloud-available.d.ts.map +1 -0
  80. package/dist/typescript/index.d.ts +7 -0
  81. package/dist/typescript/index.d.ts.map +1 -0
  82. package/dist/typescript/storages/cloudkit.d.ts +3 -0
  83. package/dist/typescript/storages/cloudkit.d.ts.map +1 -0
  84. package/{lib/typescript → dist/typescript/storages}/google-drive/client.d.ts +9 -2
  85. package/dist/typescript/storages/google-drive/client.d.ts.map +1 -0
  86. package/dist/typescript/storages/google-drive/index.d.ts +35 -0
  87. package/dist/typescript/storages/google-drive/index.d.ts.map +1 -0
  88. package/dist/typescript/storages/google-drive/types.d.ts.map +1 -0
  89. package/dist/typescript/types/native.d.ts +64 -0
  90. package/dist/typescript/types/native.d.ts.map +1 -0
  91. package/dist/typescript/utils/cloud-storage-error.d.ts +8 -0
  92. package/dist/typescript/utils/cloud-storage-error.d.ts.map +1 -0
  93. package/dist/typescript/utils/constants.d.ts +4 -0
  94. package/dist/typescript/utils/constants.d.ts.map +1 -0
  95. package/{lib → dist}/typescript/utils/helpers.d.ts.map +1 -1
  96. package/dist/typescript/utils/local-fs.d.ts +3 -0
  97. package/dist/typescript/utils/local-fs.d.ts.map +1 -0
  98. package/dist/typescript/utils/native.d.ts +7 -0
  99. package/dist/typescript/utils/native.d.ts.map +1 -0
  100. package/ios/CloudStorage.xcodeproj/project.pbxproj +12 -6
  101. package/ios/{CloudStorage.m → CloudStorageCloudKit.m} +4 -2
  102. package/ios/{CloudStorage.swift → CloudStorageCloudKit.swift} +60 -5
  103. package/ios/CloudStorageLocalFileSystem.m +15 -0
  104. package/ios/CloudStorageLocalFileSystem.swift +215 -0
  105. package/ios/Utils/CloudKitUtils.swift +4 -4
  106. package/ios/Utils/CloudStorageError.swift +8 -0
  107. package/ios/Utils/FileUtils.swift +19 -0
  108. package/ios/Utils/Types.swift +7 -1
  109. package/package.json +44 -103
  110. package/src/{RNCloudStorage.ts → cloud-storage.ts} +147 -85
  111. package/src/expo-plugin/{withRNCloudStorage.ts → index.ts} +2 -2
  112. package/src/hooks/{useCloudFile.ts → use-cloud-file.ts} +24 -6
  113. package/src/hooks/{useIsCloudAvailable.ts → use-is-cloud-available.ts} +1 -1
  114. package/src/index.ts +5 -6
  115. package/src/storages/cloudkit.ts +5 -0
  116. package/src/{google-drive → storages/google-drive}/client.ts +99 -40
  117. package/src/{google-drive → storages/google-drive}/index.ts +172 -89
  118. package/src/types/native.ts +50 -14
  119. package/src/utils/cloud-storage-error.ts +15 -0
  120. package/src/utils/constants.ts +20 -0
  121. package/src/utils/local-fs.ts +19 -0
  122. package/src/utils/native.ts +40 -0
  123. package/lib/commonjs/RNCloudStorage.js.map +0 -1
  124. package/lib/commonjs/expo-plugin/withRNCloudStorage.js +0 -13
  125. package/lib/commonjs/expo-plugin/withRNCloudStorage.js.map +0 -1
  126. package/lib/commonjs/expo-plugin/withRNCloudStorageIos.js.map +0 -1
  127. package/lib/commonjs/google-drive/client.js.map +0 -1
  128. package/lib/commonjs/google-drive/index.js.map +0 -1
  129. package/lib/commonjs/google-drive/types.js.map +0 -1
  130. package/lib/commonjs/hooks/useCloudFile.js.map +0 -1
  131. package/lib/commonjs/hooks/useIsCloudAvailable.js.map +0 -1
  132. package/lib/commonjs/index.js.map +0 -1
  133. package/lib/commonjs/types/native.js +0 -26
  134. package/lib/commonjs/types/native.js.map +0 -1
  135. package/lib/commonjs/utils/CloudStorageError.js.map +0 -1
  136. package/lib/module/RNCloudStorage.js.map +0 -1
  137. package/lib/module/expo-plugin/withRNCloudStorage.js +0 -8
  138. package/lib/module/expo-plugin/withRNCloudStorage.js.map +0 -1
  139. package/lib/module/expo-plugin/withRNCloudStorageIos.js.map +0 -1
  140. package/lib/module/google-drive/client.js.map +0 -1
  141. package/lib/module/google-drive/index.js.map +0 -1
  142. package/lib/module/google-drive/types.js.map +0 -1
  143. package/lib/module/hooks/useCloudFile.js.map +0 -1
  144. package/lib/module/hooks/useIsCloudAvailable.js.map +0 -1
  145. package/lib/module/index.js +0 -10
  146. package/lib/module/index.js.map +0 -1
  147. package/lib/module/types/native.js +0 -22
  148. package/lib/module/types/native.js.map +0 -1
  149. package/lib/module/utils/CloudStorageError.js.map +0 -1
  150. package/lib/typescript/RNCloudStorage.d.ts.map +0 -1
  151. package/lib/typescript/expo-plugin/withRNCloudStorage.d.ts.map +0 -1
  152. package/lib/typescript/expo-plugin/withRNCloudStorageIos.d.ts.map +0 -1
  153. package/lib/typescript/google-drive/client.d.ts.map +0 -1
  154. package/lib/typescript/google-drive/index.d.ts +0 -34
  155. package/lib/typescript/google-drive/index.d.ts.map +0 -1
  156. package/lib/typescript/google-drive/types.d.ts.map +0 -1
  157. package/lib/typescript/hooks/useCloudFile.d.ts.map +0 -1
  158. package/lib/typescript/hooks/useIsCloudAvailable.d.ts.map +0 -1
  159. package/lib/typescript/index.d.ts +0 -8
  160. package/lib/typescript/index.d.ts.map +0 -1
  161. package/lib/typescript/types/native.d.ts +0 -40
  162. package/lib/typescript/types/native.d.ts.map +0 -1
  163. package/lib/typescript/utils/CloudStorageError.d.ts +0 -8
  164. package/lib/typescript/utils/CloudStorageError.d.ts.map +0 -1
  165. package/src/utils/CloudStorageError.ts +0 -14
  166. /package/{lib → dist}/commonjs/expo-plugin/types/index.js +0 -0
  167. /package/{lib → dist}/commonjs/expo-plugin/types/index.js.map +0 -0
  168. /package/{lib/commonjs → dist/commonjs/storages}/google-drive/types.js +0 -0
  169. /package/{lib → dist}/commonjs/types/main.js +0 -0
  170. /package/{lib → dist}/commonjs/types/main.js.map +0 -0
  171. /package/{lib → dist}/commonjs/utils/helpers.js +0 -0
  172. /package/{lib → dist}/commonjs/utils/helpers.js.map +0 -0
  173. /package/{lib → dist}/module/expo-plugin/types/index.js +0 -0
  174. /package/{lib → dist}/module/expo-plugin/types/index.js.map +0 -0
  175. /package/{lib → dist}/module/package.json +0 -0
  176. /package/{lib/module → dist/module/storages}/google-drive/types.js +0 -0
  177. /package/{lib → dist}/module/types/main.js +0 -0
  178. /package/{lib → dist}/module/types/main.js.map +0 -0
  179. /package/{lib → dist}/module/utils/helpers.js +0 -0
  180. /package/{lib → dist}/module/utils/helpers.js.map +0 -0
  181. /package/{lib → dist}/typescript/expo-plugin/types/index.d.ts +0 -0
  182. /package/{lib → dist}/typescript/expo-plugin/types/index.d.ts.map +0 -0
  183. /package/{lib/typescript → dist/typescript/storages}/google-drive/types.d.ts +0 -0
  184. /package/{lib → dist}/typescript/types/main.d.ts +0 -0
  185. /package/{lib → dist}/typescript/types/main.d.ts.map +0 -0
  186. /package/{lib → dist}/typescript/utils/helpers.d.ts +0 -0
  187. /package/src/expo-plugin/{withRNCloudStorageIos.ts → ios.ts} +0 -0
  188. /package/src/{google-drive → storages/google-drive}/types.ts +0 -0
@@ -5,60 +5,19 @@ import {
5
5
  type CloudStorageProviderOptions,
6
6
  type DeepRequired,
7
7
  } from './types/main';
8
- import type NativeRNCloudStorage from './types/native';
8
+ import { NativeCloudStorageErrorCode, type NativeStorage } from './types/native';
9
9
  import { isProviderSupported } from './utils/helpers';
10
10
  import { NativeEventEmitter, NativeModules, Platform } from 'react-native';
11
- import CloudStorageError from './utils/CloudStorageError';
12
- import { CloudStorageErrorCode } from './types/native';
13
- import GoogleDrive from './google-drive';
14
-
15
- const LINKING_ERROR =
16
- `The package 'react-native-cloud-storage' doesn't seem to be linked. Make sure: \n\n` +
17
- Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
18
- '- You rebuilt the app after installing the package\n' +
19
- '- You are not using Expo Go\n';
20
-
21
- // proxy NativeModules.CloudStorage to catch any errors thrown by the native module and wrap them in a CloudStorageError
22
- const nativeIosInstance = NativeModules.CloudStorage
23
- ? new Proxy(NativeModules.CloudStorage, {
24
- get(target: NativeRNCloudStorage, prop: keyof NativeRNCloudStorage) {
25
- const originalFunction = target[prop];
26
- if (typeof originalFunction === 'function') {
27
- return async (...args: any[]) => {
28
- try {
29
- // @ts-expect-error - we can't know the types of the functions and their arguments
30
- return await originalFunction(...args);
31
- } catch (error: any) {
32
- if (error?.code && Object.values(CloudStorageErrorCode).includes(error.code)) {
33
- throw new CloudStorageError(error?.message || '', error.code as CloudStorageErrorCode);
34
- } else {
35
- throw new CloudStorageError('Unknown error', CloudStorageErrorCode.UNKNOWN, error);
36
- }
37
- }
38
- };
39
- }
40
- return originalFunction;
41
- },
42
- })
43
- : null;
44
-
45
- const defaultProviderOptions: DeepRequired<CloudStorageProviderOptions> = {
46
- [CloudStorageProvider.ICloud]: {
47
- scope: CloudStorageScope.AppData,
48
- },
49
- [CloudStorageProvider.GoogleDrive]: {
50
- scope: CloudStorageScope.AppData,
51
- accessToken: null,
52
- strictFilenames: false,
53
- timeout: 3000,
54
- },
55
- };
11
+ import GoogleDrive from './storages/google-drive';
12
+ import { NativeCloudKit } from './storages/cloudkit';
13
+ import { DEFAULT_PROVIDER_OPTIONS, LINKING_ERROR } from './utils/constants';
14
+ import CloudStorageError from './utils/cloud-storage-error';
56
15
 
57
16
  export default class RNCloudStorage {
58
17
  private static defaultInstance: RNCloudStorage;
59
18
  private provider: {
60
19
  provider: CloudStorageProvider;
61
- options: (typeof defaultProviderOptions)[keyof typeof defaultProviderOptions];
20
+ options: (typeof DEFAULT_PROVIDER_OPTIONS)[keyof typeof DEFAULT_PROVIDER_OPTIONS];
62
21
  };
63
22
  private cloudAvailabilityListeners: ((available: boolean) => void)[] = [];
64
23
 
@@ -77,7 +36,7 @@ export default class RNCloudStorage {
77
36
 
78
37
  this.provider = {
79
38
  provider: provider ?? RNCloudStorage.getDefaultProvider(),
80
- options: defaultProviderOptions[provider ?? RNCloudStorage.getDefaultProvider()],
39
+ options: DEFAULT_PROVIDER_OPTIONS[provider ?? RNCloudStorage.getDefaultProvider()],
81
40
  };
82
41
 
83
42
  this.setProvider(provider ?? RNCloudStorage.getDefaultProvider());
@@ -86,22 +45,24 @@ export default class RNCloudStorage {
86
45
  }
87
46
  }
88
47
 
89
- private get nativeInstance(): NativeRNCloudStorage {
48
+ private get nativeStorage(): NativeStorage {
90
49
  switch (this.provider.provider) {
91
- case CloudStorageProvider.ICloud:
50
+ case CloudStorageProvider.ICloud: {
92
51
  return (
93
- nativeIosInstance ??
94
- new Proxy(
52
+ NativeCloudKit ??
53
+ (new Proxy(
95
54
  {},
96
55
  {
97
56
  get() {
98
57
  throw new Error(LINKING_ERROR);
99
58
  },
100
59
  }
101
- )
60
+ ) as NativeStorage)
102
61
  );
103
- default:
62
+ }
63
+ default: {
104
64
  return new GoogleDrive(this.provider.options as DeepRequired<CloudStorageProviderOptions['googledrive']>);
65
+ }
105
66
  }
106
67
  }
107
68
 
@@ -111,10 +72,12 @@ export default class RNCloudStorage {
111
72
  */
112
73
  static getDefaultProvider(): CloudStorageProvider {
113
74
  switch (Platform.OS) {
114
- case 'ios':
75
+ case 'ios': {
115
76
  return CloudStorageProvider.ICloud;
116
- default:
77
+ }
78
+ default: {
117
79
  return CloudStorageProvider.GoogleDrive;
80
+ }
118
81
  }
119
82
  }
120
83
 
@@ -123,7 +86,7 @@ export default class RNCloudStorage {
123
86
  * @returns An array of supported CloudStorageProviders.
124
87
  */
125
88
  static getSupportedProviders(): CloudStorageProvider[] {
126
- return Object.values(CloudStorageProvider).filter(isProviderSupported);
89
+ return Object.values(CloudStorageProvider).filter((provider) => isProviderSupported(provider));
127
90
  }
128
91
 
129
92
  /**
@@ -145,23 +108,23 @@ export default class RNCloudStorage {
145
108
 
146
109
  this.provider = {
147
110
  provider,
148
- options: defaultProviderOptions[provider],
111
+ options: DEFAULT_PROVIDER_OPTIONS[provider],
149
112
  };
150
113
 
151
114
  // Emit an event to notify useIsCloudAvailable() hook consumers of the new cloud availability status
152
- this.nativeInstance.isCloudAvailable().then((available) => {
153
- this.cloudAvailabilityListeners.forEach((listener) => {
115
+ this.nativeStorage.isCloudAvailable().then((available) => {
116
+ for (const listener of this.cloudAvailabilityListeners) {
154
117
  listener(available);
155
- });
118
+ }
156
119
  });
157
120
 
158
121
  if (provider === CloudStorageProvider.ICloud) {
159
122
  // Listen to native cloud availability change events
160
123
  const eventEmitter = new NativeEventEmitter(NativeModules.CloudStorageEventEmitter);
161
124
  eventEmitter.addListener('RNCloudStorage.cloud.availability-changed', (event: { available: boolean }) => {
162
- this.cloudAvailabilityListeners.forEach((listener) => {
125
+ for (const listener of this.cloudAvailabilityListeners) {
163
126
  listener(event.available);
164
- });
127
+ }
165
128
  });
166
129
  }
167
130
  }
@@ -187,11 +150,11 @@ export default class RNCloudStorage {
187
150
 
188
151
  if (this.provider.provider === CloudStorageProvider.GoogleDrive && 'accessToken' in newOptions) {
189
152
  // Emit an event to notify useIsCloudAvailable() hook consumers of the new cloud availability status
190
- this.cloudAvailabilityListeners.forEach((listener) => {
153
+ for (const listener of this.cloudAvailabilityListeners) {
191
154
  listener(
192
155
  !!(newOptions as Required<CloudStorageProviderOptions[CloudStorageProvider.GoogleDrive]>).accessToken?.length
193
156
  );
194
- });
157
+ }
195
158
  }
196
159
  }
197
160
 
@@ -211,7 +174,7 @@ export default class RNCloudStorage {
211
174
  * @returns A promise that resolves to true if the cloud storage is available, false otherwise.
212
175
  */
213
176
  isCloudAvailable(): Promise<boolean> {
214
- return this.nativeInstance.isCloudAvailable();
177
+ return this.nativeStorage.isCloudAvailable();
215
178
  }
216
179
 
217
180
  /**
@@ -222,7 +185,7 @@ export default class RNCloudStorage {
222
185
  * @returns A promise that resolves when the data has been appended.
223
186
  */
224
187
  appendFile(path: string, data: string, scope?: CloudStorageScope): Promise<void> {
225
- return this.nativeInstance.appendToFile(path, data, scope ?? this.provider.options.scope);
188
+ return this.nativeStorage.appendToFile(path, data, scope ?? this.provider.options.scope);
226
189
  }
227
190
 
228
191
  /**
@@ -232,7 +195,7 @@ export default class RNCloudStorage {
232
195
  * @returns A promise that resolves to true if the path exists, false otherwise.
233
196
  */
234
197
  exists(path: string, scope?: CloudStorageScope): Promise<boolean> {
235
- return this.nativeInstance.fileExists(path, scope ?? this.provider.options.scope);
198
+ return this.nativeStorage.fileExists(path, scope ?? this.provider.options.scope);
236
199
  }
237
200
 
238
201
  /**
@@ -243,7 +206,7 @@ export default class RNCloudStorage {
243
206
  * @returns A promise that resolves when the file has been written.
244
207
  */
245
208
  writeFile(path: string, data: string, scope?: CloudStorageScope): Promise<void> {
246
- return this.nativeInstance.createFile(path, data, scope ?? this.provider.options.scope, true);
209
+ return this.nativeStorage.createFile(path, data, scope ?? this.provider.options.scope, true);
247
210
  }
248
211
 
249
212
  /**
@@ -253,7 +216,7 @@ export default class RNCloudStorage {
253
216
  * @returns A promise that resolves when the directory has been created.
254
217
  */
255
218
  mkdir(path: string, scope?: CloudStorageScope): Promise<void> {
256
- return this.nativeInstance.createDirectory(path, scope ?? this.provider.options.scope);
219
+ return this.nativeStorage.createDirectory(path, scope ?? this.provider.options.scope);
257
220
  }
258
221
 
259
222
  /**
@@ -263,7 +226,7 @@ export default class RNCloudStorage {
263
226
  * @returns A promise that resolves to an array of file names, excluding '.' and '..'.
264
227
  */
265
228
  readdir(path: string, scope?: CloudStorageScope): Promise<string[]> {
266
- return this.nativeInstance.listFiles(path, scope ?? this.provider.options.scope);
229
+ return this.nativeStorage.listFiles(path, scope ?? this.provider.options.scope);
267
230
  }
268
231
 
269
232
  /**
@@ -273,17 +236,72 @@ export default class RNCloudStorage {
273
236
  * @returns A promise that resolves to the contents of the file.
274
237
  */
275
238
  readFile(path: string, scope?: CloudStorageScope): Promise<string> {
276
- return this.nativeInstance.readFile(path, scope ?? this.provider.options.scope);
239
+ return this.nativeStorage.readFile(path, scope ?? this.provider.options.scope);
277
240
  }
278
241
 
279
242
  /**
280
- * Downloads the file at the given path. Does not have any effect on Google Drive.
281
- * @param path The file to trigger the download for.
243
+ * Triggers synchronization for the file at the given path. Does not have any effect on Google Drive.
244
+ * @param path The file to trigger synchronization for.
282
245
  * @param scope The directory scope the path is in. Defaults to set default scope set for the current provider.
283
- * @returns A promise that resolves once the download has been triggered.
246
+ * @returns A promise that resolves once the synchronization has been triggered.
284
247
  */
285
- downloadFile(path: string, scope?: CloudStorageScope): Promise<void> {
286
- return this.nativeInstance.downloadFile(path, scope ?? this.provider.options.scope);
248
+ triggerSync(path: string, scope?: CloudStorageScope): Promise<void> {
249
+ return this.nativeStorage.triggerSync(path, scope ?? this.provider.options.scope);
250
+ }
251
+
252
+ /**
253
+ * Uploads the file at the given local path to the given path, creating it if it doesn't exist or overwriting it if it does.
254
+ * @param remotePath The remote path to upload to.
255
+ * @param localPath The local path of the file to upload.
256
+ * @param options The options for the upload. Must contain a `mimeType` property.
257
+ * @param scope The directory scope the path is in. Defaults to set default scope set for the current provider.
258
+ * @returns A promise that resolves when the file has been uploaded.
259
+ */
260
+ uploadFile(
261
+ remotePath: string,
262
+ localPath: string,
263
+ options: { mimeType: string },
264
+ scope?: CloudStorageScope
265
+ ): Promise<void> {
266
+ return this.nativeStorage.uploadFile(
267
+ remotePath,
268
+ localPath,
269
+ options.mimeType,
270
+ scope ?? this.provider.options.scope,
271
+ true
272
+ );
273
+ }
274
+
275
+ /**
276
+ * Triggers synchronization for the file at the given path. Does not have any effect on Google Drive.
277
+ * @param path The file to trigger synchronization for.
278
+ * @param scope The directory scope the path is in. Defaults to set default scope set for the current provider.
279
+ * @returns A promise that resolves once the synchronization has been triggered.
280
+ * @deprecated Use `triggerSync` instead.
281
+ */
282
+ downloadFile(path: string, scope?: CloudStorageScope): Promise<void>;
283
+ /**
284
+ * Downloads the cloud file at the given remote path to the given local path.
285
+ * @param remotePath The remote path of the file to download from the cloud.
286
+ * @param localPath The local path to download the cloud file to.
287
+ * @param scope The directory scope the path is in. Defaults to set default scope set for the current provider.
288
+ */
289
+ downloadFile(remotePath: string, localPath: string, scope?: CloudStorageScope): Promise<void>;
290
+ downloadFile(remotePathOrPath: string, localPathOrScope?: string, scope?: CloudStorageScope): Promise<void> {
291
+ if (
292
+ !localPathOrScope ||
293
+ (!scope &&
294
+ typeof localPathOrScope === 'string' &&
295
+ Object.values(CloudStorageScope).includes(localPathOrScope as CloudStorageScope))
296
+ ) {
297
+ // deprecated `triggerSync` call
298
+ return this.triggerSync(remotePathOrPath, scope);
299
+ }
300
+
301
+ if (!localPathOrScope) {
302
+ throw new CloudStorageError('Invalid arguments provided to downloadFile', NativeCloudStorageErrorCode.UNKNOWN);
303
+ }
304
+ return this.nativeStorage.downloadFile(remotePathOrPath, localPathOrScope, scope ?? this.provider.options.scope);
287
305
  }
288
306
 
289
307
  /**
@@ -293,7 +311,7 @@ export default class RNCloudStorage {
293
311
  * @returns A promise that resolves when the file has been deleted.
294
312
  */
295
313
  unlink(path: string, scope?: CloudStorageScope): Promise<void> {
296
- return this.nativeInstance.deleteFile(path, scope ?? this.provider.options.scope);
314
+ return this.nativeStorage.deleteFile(path, scope ?? this.provider.options.scope);
297
315
  }
298
316
 
299
317
  /**
@@ -304,7 +322,7 @@ export default class RNCloudStorage {
304
322
  * @returns A promise that resolves when the directory has been deleted.
305
323
  */
306
324
  rmdir(path: string, options?: { recursive?: boolean }, scope?: CloudStorageScope): Promise<void> {
307
- return this.nativeInstance.deleteDirectory(path, options?.recursive ?? false, scope ?? this.provider.options.scope);
325
+ return this.nativeStorage.deleteDirectory(path, options?.recursive ?? false, scope ?? this.provider.options.scope);
308
326
  }
309
327
 
310
328
  /**
@@ -314,7 +332,7 @@ export default class RNCloudStorage {
314
332
  * @returns A promise that resolves to the CloudStorageFileStat object.
315
333
  */
316
334
  async stat(path: string, scope?: CloudStorageScope): Promise<CloudStorageFileStat> {
317
- const native = await this.nativeInstance.statFile(path, scope ?? this.provider.options.scope);
335
+ const native = await this.nativeStorage.statFile(path, scope ?? this.provider.options.scope);
318
336
 
319
337
  return {
320
338
  ...native,
@@ -438,13 +456,57 @@ export default class RNCloudStorage {
438
456
  }
439
457
 
440
458
  /**
441
- * Downloads the file at the given path in the provider of the default static instance. Does not have any effect on Google Drive.
442
- * @param path The file to trigger the download for.
459
+ * Triggers synchronization for the file at the given path in the provider of the default static instance. Does not have any effect on Google Drive.
460
+ * @param path The file to trigger synchronization for.
443
461
  * @param scope The directory scope the path is in. Defaults to the default scope set for the default static instance.
444
- * @returns A promise that resolves once the download has been triggered.
462
+ * @returns A promise that resolves once the synchronization has been triggered.
463
+ */
464
+ static triggerSync(path: string, scope?: CloudStorageScope): Promise<void> {
465
+ return RNCloudStorage.getDefaultInstance().triggerSync(path, scope);
466
+ }
467
+
468
+ /**
469
+ * Uploads the file at the given local path to the given path in the provider of the default static instance, creating it if it doesn't exist or overwriting it if it does.
470
+ * @param remotePath The remote path to upload to.
471
+ * @param localPath The local path of the file to upload.
472
+ * @param options The options for the upload. Must contain a `mimeType` property.
473
+ * @param scope The directory scope the path is in. Defaults to set default scope set for the current provider.
474
+ * @returns A promise that resolves when the file has been uploaded.
445
475
  */
446
- static downloadFile(path: string, scope?: CloudStorageScope): Promise<void> {
447
- return RNCloudStorage.getDefaultInstance().downloadFile(path, scope);
476
+ static uploadFile(
477
+ remotePath: string,
478
+ localPath: string,
479
+ options: { mimeType: string },
480
+ scope?: CloudStorageScope
481
+ ): Promise<void> {
482
+ return RNCloudStorage.getDefaultInstance().uploadFile(remotePath, localPath, options, scope);
483
+ }
484
+
485
+ /**
486
+ * Triggers synchronization for the file at the given path in the provider of the default static instance. Does not have any effect on Google Drive.
487
+ * @param path The file to trigger synchronization for.
488
+ * @param scope The directory scope the path is in. Defaults to set default scope set for the current provider.
489
+ * @returns A promise that resolves once the synchronization has been triggered.
490
+ * @deprecated Use `triggerSync` instead.
491
+ */
492
+ static downloadFile(path: string, scope?: CloudStorageScope): Promise<void>;
493
+ /**
494
+ * Downloads the cloud file at the given remote path to the given local path.
495
+ * @param remotePath The remote path of the file to download from the cloud.
496
+ * @param localPath The local path to download the cloud file to.
497
+ * @param scope The directory scope the path is in. Defaults to set default scope set for the current provider.
498
+ */
499
+ static downloadFile(remotePath: string, localPath: string, scope?: CloudStorageScope): Promise<void>;
500
+ static downloadFile(remotePathOrPath: string, localPathOrScope?: string, scope?: CloudStorageScope): Promise<void> {
501
+ if (typeof scope === 'string') {
502
+ if (!localPathOrScope) {
503
+ throw new CloudStorageError('Invalid arguments provided to downloadFile', NativeCloudStorageErrorCode.UNKNOWN);
504
+ }
505
+ return RNCloudStorage.getDefaultInstance().downloadFile(remotePathOrPath, localPathOrScope, scope);
506
+ } else {
507
+ // deprecated `triggerSync` call
508
+ return RNCloudStorage.getDefaultInstance().triggerSync(remotePathOrPath, scope);
509
+ }
448
510
  }
449
511
 
450
512
  /**
@@ -1,8 +1,8 @@
1
1
  import type { RNCloudStorageConfigPluginOptions } from './types';
2
- import withRNCloudStorageIos from './withRNCloudStorageIos';
2
+ import withRNCloudStorageIos from './ios';
3
3
  import type { ConfigPlugin } from '@expo/config-plugins';
4
4
 
5
- // Android config plugin not needed as there's no native code to configure.
5
+ // Android config plugin not needed as there's nothing to configure.
6
6
 
7
7
  const withRNCloudStorage: ConfigPlugin<RNCloudStorageConfigPluginOptions> = (config, options) =>
8
8
  withRNCloudStorageIos(config, options);
@@ -1,5 +1,5 @@
1
1
  import type { CloudStorageScope } from '../types/main';
2
- import RNCloudStorage from '../RNCloudStorage';
2
+ import RNCloudStorage from '../cloud-storage';
3
3
  import { useCallback, useEffect, useState } from 'react';
4
4
 
5
5
  /**
@@ -39,19 +39,37 @@ export const useCloudFile = (path: string, scope?: CloudStorageScope, cloudStora
39
39
  setContent(null);
40
40
  }, [path, scope, instance]);
41
41
 
42
- const download = useCallback(async () => {
43
- await instance.downloadFile(path, scope);
42
+ const sync = useCallback(async () => {
43
+ await instance.triggerSync(path, scope);
44
44
  }, [path, scope, instance]);
45
45
 
46
46
  return {
47
+ /**
48
+ * The content of the file.
49
+ */
47
50
  content,
51
+ /**
52
+ * Reads the file from the cloud.
53
+ */
48
54
  read,
55
+ /**
56
+ * Writes new content to the file.
57
+ */
49
58
  write,
59
+ /**
60
+ * Deletes the file.
61
+ */
50
62
  remove,
51
63
  /**
52
- * Downloads the file from iCloud to the device. Needed if the file hasn't been synced yet. Has no effect on
53
- * Google Drive.
64
+ * Triggers synchronization for the file. Needed if the file hasn't been synced yet from iCloud.
65
+ * Has no effect on Google Drive.
66
+ */
67
+ sync,
68
+ /**
69
+ * Triggers synchronization for the file. Needed if the file hasn't been synced yet from iCloud.
70
+ * Has no effect on Google Drive.
71
+ * @deprecated Use `sync` instead.
54
72
  */
55
- download,
73
+ download: sync,
56
74
  };
57
75
  };
@@ -1,5 +1,5 @@
1
1
  import { useCallback, useEffect, useState } from 'react';
2
- import RNCloudStorage from '../RNCloudStorage';
2
+ import RNCloudStorage from '../cloud-storage';
3
3
 
4
4
  /**
5
5
  * A hook that tests whether or not the cloud storage is available.
package/src/index.ts CHANGED
@@ -1,8 +1,7 @@
1
- import RNCloudStorage from './RNCloudStorage';
2
- import { CloudStorageErrorCode } from './types/native';
3
1
  export * from './types/main';
4
- export * from './hooks/useCloudFile';
5
- export * from './hooks/useIsCloudAvailable';
6
- import CloudStorageError from './utils/CloudStorageError';
2
+ export * from './hooks/use-cloud-file';
3
+ export * from './hooks/use-is-cloud-available';
7
4
 
8
- export { RNCloudStorage as CloudStorage, CloudStorageError, CloudStorageErrorCode };
5
+ export { NativeCloudStorageErrorCode as CloudStorageErrorCode } from './types/native';
6
+ export { default as CloudStorageError } from './utils/cloud-storage-error';
7
+ export { default as CloudStorage } from './cloud-storage';
@@ -0,0 +1,5 @@
1
+ import { NativeModules } from 'react-native';
2
+ import { NativeStorage } from '../types/native';
3
+ import { createProxiedNativeModule } from '../utils/native';
4
+
5
+ export const NativeCloudKit = createProxiedNativeModule<NativeStorage>(NativeModules.CloudStorageCloudKit);