react-native-cloud-storage 1.5.1 → 2.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.
Files changed (107) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +6 -5
  3. package/ios/CloudStorage.swift +52 -262
  4. package/ios/CloudStorage.xcodeproj/project.pbxproj +28 -0
  5. package/ios/CloudStorageEventEmitter.swift +4 -4
  6. package/ios/Utils/CloudKitUtils.swift +112 -0
  7. package/ios/Utils/CloudStorageError.swift +78 -0
  8. package/ios/Utils/FileUtils.swift +132 -0
  9. package/ios/Utils/Promise.swift +58 -0
  10. package/ios/Utils/Types.swift +36 -0
  11. package/lib/commonjs/RNCloudStorage.js +361 -66
  12. package/lib/commonjs/RNCloudStorage.js.map +1 -1
  13. package/lib/commonjs/expo-plugin/types/index.js.map +1 -1
  14. package/lib/commonjs/expo-plugin/withRNCloudStorage.js +2 -3
  15. package/lib/commonjs/expo-plugin/withRNCloudStorage.js.map +1 -1
  16. package/lib/commonjs/expo-plugin/withRNCloudStorageIos.js +4 -7
  17. package/lib/commonjs/expo-plugin/withRNCloudStorageIos.js.map +1 -1
  18. package/lib/commonjs/google-drive/client.js +16 -20
  19. package/lib/commonjs/google-drive/client.js.map +1 -1
  20. package/lib/commonjs/google-drive/index.js +42 -64
  21. package/lib/commonjs/google-drive/index.js.map +1 -1
  22. package/lib/commonjs/google-drive/types.js +1 -2
  23. package/lib/commonjs/google-drive/types.js.map +1 -1
  24. package/lib/commonjs/hooks/useCloudFile.js +14 -17
  25. package/lib/commonjs/hooks/useCloudFile.js.map +1 -1
  26. package/lib/commonjs/hooks/useIsCloudAvailable.js +11 -21
  27. package/lib/commonjs/hooks/useIsCloudAvailable.js.map +1 -1
  28. package/lib/commonjs/index.js +1 -7
  29. package/lib/commonjs/index.js.map +1 -1
  30. package/lib/commonjs/package.json +1 -0
  31. package/lib/commonjs/types/main.js +8 -3
  32. package/lib/commonjs/types/main.js.map +1 -1
  33. package/lib/commonjs/types/native.js +3 -3
  34. package/lib/commonjs/types/native.js.map +1 -1
  35. package/lib/commonjs/utils/CloudStorageError.js +1 -2
  36. package/lib/commonjs/utils/CloudStorageError.js.map +1 -1
  37. package/lib/commonjs/utils/helpers.js +8 -15
  38. package/lib/commonjs/utils/helpers.js.map +1 -1
  39. package/lib/module/RNCloudStorage.js +362 -65
  40. package/lib/module/RNCloudStorage.js.map +1 -1
  41. package/lib/module/expo-plugin/types/index.js +1 -1
  42. package/lib/module/expo-plugin/types/index.js.map +1 -1
  43. package/lib/module/expo-plugin/withRNCloudStorage.js +2 -0
  44. package/lib/module/expo-plugin/withRNCloudStorage.js.map +1 -1
  45. package/lib/module/expo-plugin/withRNCloudStorageIos.js +5 -5
  46. package/lib/module/expo-plugin/withRNCloudStorageIos.js.map +1 -1
  47. package/lib/module/google-drive/client.js +18 -20
  48. package/lib/module/google-drive/client.js.map +1 -1
  49. package/lib/module/google-drive/index.js +41 -62
  50. package/lib/module/google-drive/index.js.map +1 -1
  51. package/lib/module/google-drive/types.js +2 -0
  52. package/lib/module/google-drive/types.js.map +1 -1
  53. package/lib/module/hooks/useCloudFile.js +15 -16
  54. package/lib/module/hooks/useCloudFile.js.map +1 -1
  55. package/lib/module/hooks/useIsCloudAvailable.js +13 -21
  56. package/lib/module/hooks/useIsCloudAvailable.js.map +1 -1
  57. package/lib/module/index.js +2 -5
  58. package/lib/module/index.js.map +1 -1
  59. package/lib/module/package.json +1 -0
  60. package/lib/module/types/main.js +9 -0
  61. package/lib/module/types/main.js.map +1 -1
  62. package/lib/module/types/native.js +4 -1
  63. package/lib/module/types/native.js.map +1 -1
  64. package/lib/module/utils/CloudStorageError.js +2 -0
  65. package/lib/module/utils/CloudStorageError.js.map +1 -1
  66. package/lib/module/utils/helpers.js +8 -13
  67. package/lib/module/utils/helpers.js.map +1 -1
  68. package/lib/typescript/RNCloudStorage.d.ts +159 -39
  69. package/lib/typescript/RNCloudStorage.d.ts.map +1 -1
  70. package/lib/typescript/google-drive/client.d.ts +3 -3
  71. package/lib/typescript/google-drive/client.d.ts.map +1 -1
  72. package/lib/typescript/google-drive/index.d.ts +6 -18
  73. package/lib/typescript/google-drive/index.d.ts.map +1 -1
  74. package/lib/typescript/hooks/useCloudFile.d.ts +4 -7
  75. package/lib/typescript/hooks/useCloudFile.d.ts.map +1 -1
  76. package/lib/typescript/hooks/useIsCloudAvailable.d.ts +3 -2
  77. package/lib/typescript/hooks/useIsCloudAvailable.d.ts.map +1 -1
  78. package/lib/typescript/index.d.ts +0 -4
  79. package/lib/typescript/index.d.ts.map +1 -1
  80. package/lib/typescript/types/main.d.ts +33 -0
  81. package/lib/typescript/types/main.d.ts.map +1 -1
  82. package/lib/typescript/types/native.d.ts +2 -1
  83. package/lib/typescript/types/native.d.ts.map +1 -1
  84. package/lib/typescript/utils/helpers.d.ts +2 -9
  85. package/lib/typescript/utils/helpers.d.ts.map +1 -1
  86. package/package.json +9 -11
  87. package/react-native-cloud-storage.podspec +1 -1
  88. package/src/RNCloudStorage.ts +387 -68
  89. package/src/google-drive/client.ts +8 -7
  90. package/src/google-drive/index.ts +38 -63
  91. package/src/hooks/useCloudFile.ts +13 -16
  92. package/src/hooks/useIsCloudAvailable.ts +12 -25
  93. package/src/index.ts +0 -5
  94. package/src/types/main.ts +38 -0
  95. package/src/types/native.ts +2 -1
  96. package/src/utils/helpers.ts +8 -15
  97. package/ios/CloudStorage.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -4
  98. package/ios/CloudStorage.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
  99. package/ios/CloudStorage.xcodeproj/project.xcworkspace/xcuserdata/max.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  100. package/ios/CloudStorage.xcodeproj/xcuserdata/max.xcuserdatad/xcschemes/xcschememanagement.plist +0 -22
  101. package/lib/commonjs/createRNCloudStorage.js +0 -48
  102. package/lib/commonjs/createRNCloudStorage.js.map +0 -1
  103. package/lib/module/createRNCloudStorage.js +0 -41
  104. package/lib/module/createRNCloudStorage.js.map +0 -1
  105. package/lib/typescript/createRNCloudStorage.d.ts +0 -3
  106. package/lib/typescript/createRNCloudStorage.d.ts.map +0 -1
  107. package/src/createRNCloudStorage.ts +0 -53
@@ -1,53 +0,0 @@
1
- import { NativeModules, Platform } from 'react-native';
2
- import type NativeRNCloudStorage from './types/native';
3
- import GoogleDrive from './google-drive';
4
- import { CloudStorageErrorCode } from './types/native';
5
- import CloudStorageError from './utils/CloudStorageError';
6
-
7
- const LINKING_ERROR =
8
- `The package 'react-native-cloud-storage' doesn't seem to be linked. Make sure: \n\n` +
9
- Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
10
- '- You rebuilt the app after installing the package\n' +
11
- '- You are not using Expo Go\n';
12
-
13
- // proxy NativeModules.CloudStorage to catch any errors thrown by the native module and wrap them in a CloudStorageError
14
- const nativeIosInstance = NativeModules.CloudStorage
15
- ? new Proxy(NativeModules.CloudStorage, {
16
- get(target: NativeRNCloudStorage, prop: keyof NativeRNCloudStorage) {
17
- const originalFunction = target[prop];
18
- if (typeof originalFunction === 'function') {
19
- return async (...args: any[]) => {
20
- try {
21
- // @ts-expect-error - we can't know the types of the functions and their arguments
22
- return await originalFunction(...args);
23
- } catch (error: any) {
24
- if (error?.code && Object.values(CloudStorageErrorCode).includes(error.code)) {
25
- throw new CloudStorageError(error?.message || '', error.code as CloudStorageErrorCode);
26
- } else {
27
- throw new CloudStorageError('Unknown error', CloudStorageErrorCode.UNKNOWN, error);
28
- }
29
- }
30
- };
31
- }
32
- return originalFunction;
33
- },
34
- })
35
- : null;
36
-
37
- export default function createRNCloudStorage(): NativeRNCloudStorage {
38
- if (Platform.OS === 'ios') {
39
- return (
40
- nativeIosInstance ??
41
- new Proxy(
42
- {},
43
- {
44
- get() {
45
- throw new Error(LINKING_ERROR);
46
- },
47
- }
48
- )
49
- );
50
- }
51
-
52
- return new GoogleDrive();
53
- }