react-native-cloud-storage 0.6.0 → 1.0.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 +0 -2
- package/ios/CloudStorage.m +1 -0
- package/ios/CloudStorage.swift +106 -65
- package/ios/CloudStorage.xcodeproj/project.pbxproj +1 -3
- package/ios/CloudStorage.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -0
- package/ios/CloudStorage.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/ios/CloudStorage.xcodeproj/project.xcworkspace/xcuserdata/max.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/CloudStorage.xcodeproj/xcuserdata/max.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
- package/lib/commonjs/RNCloudStorage.js +26 -12
- package/lib/commonjs/RNCloudStorage.js.map +1 -1
- package/lib/commonjs/expo-plugin/types/index.js +2 -0
- package/lib/commonjs/expo-plugin/types/index.js.map +1 -0
- package/lib/commonjs/expo-plugin/withRNCloudStorage.js +1 -1
- package/lib/commonjs/expo-plugin/withRNCloudStorage.js.map +1 -1
- package/lib/commonjs/expo-plugin/withRNCloudStorageIos.js +3 -3
- package/lib/commonjs/expo-plugin/withRNCloudStorageIos.js.map +1 -1
- package/lib/commonjs/google-drive/index.js +33 -4
- package/lib/commonjs/google-drive/index.js.map +1 -1
- package/lib/commonjs/hooks/useCloudFile.js +14 -3
- package/lib/commonjs/hooks/useCloudFile.js.map +1 -1
- package/lib/commonjs/hooks/useIsCloudAvailable.js +0 -2
- package/lib/commonjs/hooks/useIsCloudAvailable.js.map +1 -1
- package/lib/commonjs/index.js +10 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/types/native.js +1 -1
- package/lib/commonjs/utils/helpers.js +23 -0
- package/lib/commonjs/utils/helpers.js.map +1 -0
- package/lib/module/RNCloudStorage.js +26 -12
- package/lib/module/RNCloudStorage.js.map +1 -1
- package/lib/module/expo-plugin/types/index.js +2 -0
- package/lib/module/expo-plugin/types/index.js.map +1 -0
- package/lib/module/expo-plugin/withRNCloudStorage.js +1 -2
- package/lib/module/expo-plugin/withRNCloudStorage.js.map +1 -1
- package/lib/module/expo-plugin/withRNCloudStorageIos.js +3 -3
- package/lib/module/expo-plugin/withRNCloudStorageIos.js.map +1 -1
- package/lib/module/google-drive/index.js +33 -4
- package/lib/module/google-drive/index.js.map +1 -1
- package/lib/module/hooks/useCloudFile.js +15 -3
- package/lib/module/hooks/useCloudFile.js.map +1 -1
- package/lib/module/hooks/useIsCloudAvailable.js +0 -2
- package/lib/module/hooks/useIsCloudAvailable.js.map +1 -1
- package/lib/module/index.js +5 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/types/native.js +1 -1
- package/lib/module/utils/helpers.js +16 -0
- package/lib/module/utils/helpers.js.map +1 -0
- package/lib/typescript/RNCloudStorage.d.ts +22 -13
- package/lib/typescript/RNCloudStorage.d.ts.map +1 -1
- package/lib/typescript/expo-plugin/types/index.d.ts +7 -0
- package/lib/typescript/expo-plugin/types/index.d.ts.map +1 -0
- package/lib/typescript/expo-plugin/withRNCloudStorage.d.ts +1 -6
- package/lib/typescript/expo-plugin/withRNCloudStorage.d.ts.map +1 -1
- package/lib/typescript/expo-plugin/withRNCloudStorageIos.d.ts +3 -2
- package/lib/typescript/expo-plugin/withRNCloudStorageIos.d.ts.map +1 -1
- package/lib/typescript/google-drive/index.d.ts +8 -1
- package/lib/typescript/google-drive/index.d.ts.map +1 -1
- package/lib/typescript/hooks/useCloudFile.d.ts +13 -2
- package/lib/typescript/hooks/useCloudFile.d.ts.map +1 -1
- package/lib/typescript/hooks/useIsCloudAvailable.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +4 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/types/native.d.ts +2 -1
- package/lib/typescript/types/native.d.ts.map +1 -1
- package/lib/typescript/utils/helpers.d.ts +10 -0
- package/lib/typescript/utils/helpers.d.ts.map +1 -0
- package/package.json +24 -20
- package/react-native-cloud-storage.podspec +7 -1
- package/src/RNCloudStorage.ts +33 -19
- package/src/expo-plugin/types/index.ts +6 -0
- package/src/expo-plugin/withRNCloudStorage.ts +2 -7
- package/src/expo-plugin/withRNCloudStorageIos.ts +8 -10
- package/src/google-drive/index.ts +42 -4
- package/src/hooks/useCloudFile.ts +14 -3
- package/src/hooks/useIsCloudAvailable.ts +0 -2
- package/src/index.ts +5 -1
- package/src/types/native.ts +2 -1
- package/src/utils/helpers.ts +17 -0
package/lib/module/index.js
CHANGED
|
@@ -4,6 +4,10 @@ export * from './types/main';
|
|
|
4
4
|
export * from './hooks/useCloudFile';
|
|
5
5
|
export * from './hooks/useIsCloudAvailable';
|
|
6
6
|
import CloudStorageError from './utils/CloudStorageError';
|
|
7
|
-
export { CloudStorageError, CloudStorageErrorCode };
|
|
7
|
+
export { RNCloudStorage as CloudStorage, CloudStorageError, CloudStorageErrorCode };
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated Use the named export `CloudStorage` instead.
|
|
11
|
+
*/
|
|
8
12
|
export default RNCloudStorage;
|
|
9
13
|
//# sourceMappingURL=index.js.map
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["RNCloudStorage","CloudStorageErrorCode","CloudStorageError"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"AAAA,OAAOA,cAAc,MAAM,kBAAkB;AAC7C,SAASC,qBAAqB,QAAQ,gBAAgB;AACtD,cAAc,cAAc;AAC5B,cAAc,sBAAsB;AACpC,cAAc,6BAA6B;AAC3C,OAAOC,iBAAiB,MAAM,2BAA2B;AAEzD,
|
|
1
|
+
{"version":3,"names":["RNCloudStorage","CloudStorageErrorCode","CloudStorageError","CloudStorage"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"AAAA,OAAOA,cAAc,MAAM,kBAAkB;AAC7C,SAASC,qBAAqB,QAAQ,gBAAgB;AACtD,cAAc,cAAc;AAC5B,cAAc,sBAAsB;AACpC,cAAc,6BAA6B;AAC3C,OAAOC,iBAAiB,MAAM,2BAA2B;AAEzD,SAASF,cAAc,IAAIG,YAAY,EAAED,iBAAiB,EAAED,qBAAqB;;AAEjF;AACA;AACA;AACA,eAAeD,cAAc"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export let CloudStorageErrorCode = /*#__PURE__*/function (CloudStorageErrorCode) {
|
|
2
2
|
CloudStorageErrorCode["FILE_NOT_FOUND"] = "ERR_FILE_NOT_FOUND";
|
|
3
3
|
CloudStorageErrorCode["PATH_IS_DIRECTORY"] = "ERR_PATH_IS_DIRECTORY";
|
|
4
|
-
CloudStorageErrorCode["DIRECTORY_NOT_FOUND"] = "
|
|
4
|
+
CloudStorageErrorCode["DIRECTORY_NOT_FOUND"] = "ERR_DIRECTORY_NOT_FOUND";
|
|
5
5
|
CloudStorageErrorCode["FILE_ALREADY_EXISTS"] = "ERR_FILE_EXISTS";
|
|
6
6
|
CloudStorageErrorCode["MULTIPLE_FILES_SAME_NAME"] = "ERR_MULTIPLE_FILES_SAME_NAME";
|
|
7
7
|
CloudStorageErrorCode["AUTHENTICATION_FAILED"] = "ERR_AUTHENTICATION_FAILED";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the path starts with a leading slash and adds one if it doesn't to maintain backwards compatibility.
|
|
3
|
+
* Will log a warning to the console if it had to add a leading slash. Will throw an error in the future.
|
|
4
|
+
*
|
|
5
|
+
* @param path The path to check.
|
|
6
|
+
* @returns The path with a leading slash, if it didn't have one already.
|
|
7
|
+
* @private
|
|
8
|
+
*/
|
|
9
|
+
export const verifyLeadingSlash = path => {
|
|
10
|
+
if (!path.startsWith('/')) {
|
|
11
|
+
console.warn(`[react-native-cloud-storage] Path "${path}" did not start with a leading slash. This is deprecated and will be an error in the future.`);
|
|
12
|
+
return `/${path}`;
|
|
13
|
+
}
|
|
14
|
+
return path;
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["verifyLeadingSlash","path","startsWith","console","warn"],"sourceRoot":"../../../src","sources":["utils/helpers.ts"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,kBAAkB,GAAIC,IAAY,IAAK;EAClD,IAAI,CAACA,IAAI,CAACC,UAAU,CAAC,GAAG,CAAC,EAAE;IACzBC,OAAO,CAACC,IAAI,CACT,sCAAqCH,IAAK,8FAA6F,CACzI;IACD,OAAQ,IAAGA,IAAK,EAAC;EACnB;EACA,OAAOA,IAAI;AACb,CAAC"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type CloudStorageFileStat, CloudStorageScope } from './types/main';
|
|
2
2
|
declare const RNCloudStorage: {
|
|
3
|
+
getDefaultScope: () => CloudStorageScope;
|
|
4
|
+
setDefaultScope: (scope: CloudStorageScope) => CloudStorageScope;
|
|
3
5
|
getGoogleDriveAccessToken: () => string | undefined;
|
|
4
6
|
setGoogleDriveAccessToken: (accessToken: string) => string;
|
|
5
7
|
setThrowOnFilesWithSameName: (enable: boolean) => boolean;
|
|
@@ -18,46 +20,53 @@ declare const RNCloudStorage: {
|
|
|
18
20
|
/**
|
|
19
21
|
* Tests whether or not the file at the given path exists.
|
|
20
22
|
* @param path The path to test.
|
|
21
|
-
* @param scope The directory scope the path is in.
|
|
23
|
+
* @param scope The directory scope the path is in. Defaults to the set default scope.
|
|
22
24
|
* @returns A promise that resolves to true if the path exists, false otherwise.
|
|
23
25
|
*/
|
|
24
|
-
exists: (path: string, scope
|
|
26
|
+
exists: (path: string, scope?: CloudStorageScope) => Promise<boolean>;
|
|
25
27
|
/**
|
|
26
28
|
* Writes to the file at the given path, creating it if it doesn't exist or overwriting it if it does.
|
|
27
29
|
* @param path The file to write to.
|
|
28
30
|
* @param data The data to write.
|
|
29
|
-
* @param scope The directory scope the path is in.
|
|
31
|
+
* @param scope The directory scope the path is in. Defaults to the set default scope.
|
|
30
32
|
* @returns A promise that resolves when the file has been written.
|
|
31
33
|
*/
|
|
32
|
-
writeFile: (path: string, data: string, scope
|
|
34
|
+
writeFile: (path: string, data: string, scope?: CloudStorageScope) => Promise<void>;
|
|
33
35
|
/**
|
|
34
36
|
* Creates a new directory at the given path.
|
|
35
37
|
* @param path The directory to create.
|
|
36
|
-
* @param scope The directory scope the path is in.
|
|
38
|
+
* @param scope The directory scope the path is in. Defaults to the set default scope.
|
|
37
39
|
* @returns A promise that resolves when the directory has been created.
|
|
38
40
|
*/
|
|
39
|
-
mkdir: (path: string, scope
|
|
41
|
+
mkdir: (path: string, scope?: CloudStorageScope) => Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Lists the contents of the directory at the given path.
|
|
44
|
+
* @param path The directory to list.
|
|
45
|
+
* @param scope The directory scope the path is in. Defaults to the set default scope.
|
|
46
|
+
* @returns A promise that resolves to an array of file names, excluding '.' and '..'.
|
|
47
|
+
*/
|
|
48
|
+
readdir: (path: string, scope?: CloudStorageScope) => Promise<string[]>;
|
|
40
49
|
/**
|
|
41
50
|
* Reads the contents of the file at the given path.
|
|
42
51
|
* @param path The file to read.
|
|
43
|
-
* @param scope The directory scope the path is in.
|
|
52
|
+
* @param scope The directory scope the path is in. Defaults to the set default scope.
|
|
44
53
|
* @returns A promise that resolves to the contents of the file.
|
|
45
54
|
*/
|
|
46
|
-
readFile: (path: string, scope
|
|
55
|
+
readFile: (path: string, scope?: CloudStorageScope) => Promise<string>;
|
|
47
56
|
/**
|
|
48
57
|
* Deletes the file at the given path.
|
|
49
58
|
* @param path The file to delete.
|
|
50
|
-
* @param scope The directory scope the path is in.
|
|
59
|
+
* @param scope The directory scope the path is in. Defaults to the set default scope.
|
|
51
60
|
* @returns A promise that resolves when the file has been deleted.
|
|
52
61
|
*/
|
|
53
|
-
unlink: (path: string, scope
|
|
62
|
+
unlink: (path: string, scope?: CloudStorageScope) => Promise<void>;
|
|
54
63
|
/**
|
|
55
64
|
* Gets the size, creation time, and modification time of the file at the given path.
|
|
56
65
|
* @param path The file to stat.
|
|
57
|
-
* @param scope The directory scope the path is in.
|
|
66
|
+
* @param scope The directory scope the path is in. Defaults to the set default scope.
|
|
58
67
|
* @returns A promise that resolves to the CloudStorageFileStat object.
|
|
59
68
|
*/
|
|
60
|
-
stat: (path: string, scope
|
|
69
|
+
stat: (path: string, scope?: CloudStorageScope) => Promise<CloudStorageFileStat>;
|
|
61
70
|
};
|
|
62
71
|
export default RNCloudStorage;
|
|
63
72
|
//# sourceMappingURL=RNCloudStorage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RNCloudStorage.d.ts","sourceRoot":"","sources":["../../src/RNCloudStorage.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"RNCloudStorage.d.ts","sourceRoot":"","sources":["../../src/RNCloudStorage.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAO5E,QAAA,MAAM,cAAc;;6BAEO,iBAAiB;;6CAED,MAAM;0CACT,OAAO;;;;;;;IAS7C;;;;OAIG;4BACyB,QAAQ,OAAO,CAAC;IAI5C;;;;;OAKG;mBACY,MAAM,UAAU,iBAAiB,KAAG,QAAQ,OAAO,CAAC;IAInE;;;;;;OAMG;sBACe,MAAM,QAAQ,MAAM,UAAU,iBAAiB,KAAG,QAAQ,IAAI,CAAC;IAIjF;;;;;OAKG;kBACW,MAAM,UAAU,iBAAiB,KAAG,QAAQ,IAAI,CAAC;IAI/D;;;;;OAKG;oBACa,MAAM,UAAU,iBAAiB,KAAG,QAAQ,MAAM,EAAE,CAAC;IAIrE;;;;;OAKG;qBACc,MAAM,UAAU,iBAAiB,KAAG,QAAQ,MAAM,CAAC;IAIpE;;;;;OAKG;mBACY,MAAM,UAAU,iBAAiB,KAAG,QAAQ,IAAI,CAAC;IAIhE;;;;;OAKG;iBACgB,MAAM,UAAU,iBAAiB,KAAG,QAAQ,oBAAoB,CAAC;CAWrF,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/expo-plugin/types/index.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iCAAiC;IAChD;;OAEG;IACH,0BAA0B,CAAC,EAAE,YAAY,GAAG,aAAa,CAAC;CAC3D"}
|
|
@@ -1,10 +1,5 @@
|
|
|
1
|
+
import type { RNCloudStorageConfigPluginOptions } from './types';
|
|
1
2
|
import type { ConfigPlugin } from '@expo/config-plugins';
|
|
2
|
-
interface RNCloudStorageConfigPluginOptions {
|
|
3
|
-
/**
|
|
4
|
-
* The iCloud container environment to use. Defaults to 'Production'.
|
|
5
|
-
*/
|
|
6
|
-
iCloudContainerEnvironment?: 'Production' | 'Development';
|
|
7
|
-
}
|
|
8
3
|
declare const withRNCloudStorage: ConfigPlugin<RNCloudStorageConfigPluginOptions>;
|
|
9
4
|
export default withRNCloudStorage;
|
|
10
5
|
//# sourceMappingURL=withRNCloudStorage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withRNCloudStorage.d.ts","sourceRoot":"","sources":["../../../src/expo-plugin/withRNCloudStorage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"withRNCloudStorage.d.ts","sourceRoot":"","sources":["../../../src/expo-plugin/withRNCloudStorage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,SAAS,CAAC;AAEjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAIzD,QAAA,MAAM,kBAAkB,EAAE,YAAY,CAAC,iCAAiC,CAChC,CAAC;AAEzC,eAAe,kBAAkB,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
|
|
1
|
+
import { type ConfigPlugin } from '@expo/config-plugins';
|
|
2
|
+
import type { RNCloudStorageConfigPluginOptions } from './types';
|
|
3
|
+
declare const withRNCloudStorageIos: ConfigPlugin<RNCloudStorageConfigPluginOptions>;
|
|
3
4
|
export default withRNCloudStorageIos;
|
|
4
5
|
//# sourceMappingURL=withRNCloudStorageIos.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withRNCloudStorageIos.d.ts","sourceRoot":"","sources":["../../../src/expo-plugin/withRNCloudStorageIos.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"withRNCloudStorageIos.d.ts","sourceRoot":"","sources":["../../../src/expo-plugin/withRNCloudStorageIos.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqD,KAAK,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAC5G,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,SAAS,CAAC;AAqCjE,QAAA,MAAM,qBAAqB,EAAE,YAAY,CAAC,iCAAiC,CACyB,CAAC;AAErG,eAAe,qBAAqB,CAAC"}
|
|
@@ -20,11 +20,18 @@ export default class GoogleDriveApiClient implements NativeRNCloudStorage {
|
|
|
20
20
|
private getRootDirectory;
|
|
21
21
|
private resolvePathToDirectories;
|
|
22
22
|
private findParentDirectoryId;
|
|
23
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Gets the Google Drive ID of the root directory for the given scope.
|
|
25
|
+
* @param scope The scope to get the root directory for.
|
|
26
|
+
* @returns A promise that resolves to the ID of the root directory or null if it could not be found.
|
|
27
|
+
*/
|
|
28
|
+
private getRootDirectoryId;
|
|
29
|
+
private listInternalFiles;
|
|
24
30
|
private checkIfMultipleFilesWithSameName;
|
|
25
31
|
private getFileId;
|
|
26
32
|
fileExists(path: string, scope: NativeRNCloudCloudStorageScope): Promise<boolean>;
|
|
27
33
|
createFile(path: string, data: string, scope: NativeRNCloudCloudStorageScope, overwrite: boolean): Promise<void>;
|
|
34
|
+
listFiles(path: string, scope: NativeRNCloudCloudStorageScope): Promise<string[]>;
|
|
28
35
|
createDirectory(path: string, scope: NativeRNCloudCloudStorageScope): Promise<void>;
|
|
29
36
|
readFile(path: string, scope: NativeRNCloudCloudStorageScope): Promise<string>;
|
|
30
37
|
deleteFile(path: string, scope: NativeRNCloudCloudStorageScope): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/google-drive/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,oBAAoB,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAEL,KAAK,iCAAiC,EACtC,KAAK,8BAA8B,EACpC,MAAM,iBAAiB,CAAC;AAIzB,MAAM,CAAC,OAAO,OAAO,oBAAqB,YAAW,oBAAoB;IACvE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAwB;IAC5C,OAAc,wBAAwB,UAAS;IACxC,4BAA4B,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,EAAE,CAAA;KAAE,KAAK,IAAI,CAAC,EAAE,CAAC;;IAwB1G,WAAkB,WAAW,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS,EAE5D;IAED,WAAkB,WAAW,IAAI,MAAM,GAAG,SAAS,CAElD;IAEM,4BAA4B,CAAC,UAAU,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,EAAE,CAAA;KAAE,KAAK,IAAI,GAAG;QACjH,MAAM,EAAE,MAAM,IAAI,CAAC;KACpB;IAUM,gBAAgB,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAA0D;IAEzG,OAAO,CAAC,gBAAgB;IASxB,OAAO,CAAC,wBAAwB;IAQhC,OAAO,CAAC,qBAAqB;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/google-drive/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,oBAAoB,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAEL,KAAK,iCAAiC,EACtC,KAAK,8BAA8B,EACpC,MAAM,iBAAiB,CAAC;AAIzB,MAAM,CAAC,OAAO,OAAO,oBAAqB,YAAW,oBAAoB;IACvE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAwB;IAC5C,OAAc,wBAAwB,UAAS;IACxC,4BAA4B,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,EAAE,CAAA;KAAE,KAAK,IAAI,CAAC,EAAE,CAAC;;IAwB1G,WAAkB,WAAW,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS,EAE5D;IAED,WAAkB,WAAW,IAAI,MAAM,GAAG,SAAS,CAElD;IAEM,4BAA4B,CAAC,UAAU,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,EAAE,CAAA;KAAE,KAAK,IAAI,GAAG;QACjH,MAAM,EAAE,MAAM,IAAI,CAAC;KACpB;IAUM,gBAAgB,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAA0D;IAEzG,OAAO,CAAC,gBAAgB;IASxB,OAAO,CAAC,wBAAwB;IAQhC,OAAO,CAAC,qBAAqB;IAiD7B;;;;OAIG;YACW,kBAAkB;YASlB,iBAAiB;IAS/B,OAAO,CAAC,gCAAgC;YAyB1B,SAAS;IAiDjB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,8BAA8B,GAAG,OAAO,CAAC,OAAO,CAAC;IAUjF,UAAU,CACd,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,8BAA8B,EACrC,SAAS,EAAE,OAAO,GACjB,OAAO,CAAC,IAAI,CAAC;IA2CV,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,8BAA8B,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAajF,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,8BAA8B,GAAG,OAAO,CAAC,IAAI,CAAC;IA8BnF,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,8BAA8B,GAAG,OAAO,CAAC,MAAM,CAAC;IAM9E,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,8BAA8B,GAAG,OAAO,CAAC,IAAI,CAAC;IAK9E,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,8BAA8B,GAAG,OAAO,CAAC,iCAAiC,CAAC;CAgBhH"}
|
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
import type { CloudStorageScope } from '../types/main';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* A utility hook for reading and writing to a single file in the cloud.
|
|
4
|
+
* @param path The path to the file.
|
|
5
|
+
* @param scope The directory scope the path is in. If not provided, defaults to the default scope set in the library.
|
|
6
|
+
* @returns An object containing the file's contents and functions for reading, writing, and removing the file.
|
|
7
|
+
*/
|
|
8
|
+
export declare const useCloudFile: (path: string, scope?: CloudStorageScope) => {
|
|
3
9
|
content: string | null;
|
|
4
10
|
read: () => Promise<void>;
|
|
5
|
-
|
|
11
|
+
write: (newContent: string) => Promise<void>;
|
|
6
12
|
remove: () => Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated Use `write` instead.
|
|
15
|
+
* @alias write
|
|
16
|
+
*/
|
|
17
|
+
update: (newContent: string) => Promise<void>;
|
|
7
18
|
};
|
|
8
19
|
//# sourceMappingURL=useCloudFile.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCloudFile.d.ts","sourceRoot":"","sources":["../../../src/hooks/useCloudFile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAIvD,eAAO,MAAM,YAAY,SAAU,MAAM,
|
|
1
|
+
{"version":3,"file":"useCloudFile.d.ts","sourceRoot":"","sources":["../../../src/hooks/useCloudFile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAIvD;;;;;GAKG;AACH,eAAO,MAAM,YAAY,SAAU,MAAM,UAAU,iBAAiB;;;wBAiB7C,MAAM;;IAiBzB;;;OAGG;yBApBgB,MAAM;CAuB5B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIsCloudAvailable.d.ts","sourceRoot":"","sources":["../../../src/hooks/useIsCloudAvailable.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,mBAAmB,
|
|
1
|
+
{"version":3,"file":"useIsCloudAvailable.d.ts","sourceRoot":"","sources":["../../../src/hooks/useIsCloudAvailable.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,mBAAmB,qCAsB/B,CAAC"}
|
|
@@ -4,6 +4,9 @@ export * from './types/main';
|
|
|
4
4
|
export * from './hooks/useCloudFile';
|
|
5
5
|
export * from './hooks/useIsCloudAvailable';
|
|
6
6
|
import CloudStorageError from './utils/CloudStorageError';
|
|
7
|
-
export { CloudStorageError, CloudStorageErrorCode };
|
|
7
|
+
export { RNCloudStorage as CloudStorage, CloudStorageError, CloudStorageErrorCode };
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated Use the named export `CloudStorage` instead.
|
|
10
|
+
*/
|
|
8
11
|
export default RNCloudStorage;
|
|
9
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACvD,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,6BAA6B,CAAC;AAC5C,OAAO,iBAAiB,MAAM,2BAA2B,CAAC;AAE1D,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACvD,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,6BAA6B,CAAC;AAC5C,OAAO,iBAAiB,MAAM,2BAA2B,CAAC;AAE1D,OAAO,EAAE,cAAc,IAAI,YAAY,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,CAAC;AAEpF;;GAEG;AACH,eAAe,cAAc,CAAC"}
|
|
@@ -9,7 +9,7 @@ export interface NativeRNCloudCloudStorageFileStat {
|
|
|
9
9
|
export declare enum CloudStorageErrorCode {
|
|
10
10
|
FILE_NOT_FOUND = "ERR_FILE_NOT_FOUND",
|
|
11
11
|
PATH_IS_DIRECTORY = "ERR_PATH_IS_DIRECTORY",
|
|
12
|
-
DIRECTORY_NOT_FOUND = "
|
|
12
|
+
DIRECTORY_NOT_FOUND = "ERR_DIRECTORY_NOT_FOUND",
|
|
13
13
|
FILE_ALREADY_EXISTS = "ERR_FILE_EXISTS",
|
|
14
14
|
MULTIPLE_FILES_SAME_NAME = "ERR_MULTIPLE_FILES_SAME_NAME",
|
|
15
15
|
AUTHENTICATION_FAILED = "ERR_AUTHENTICATION_FAILED",
|
|
@@ -24,6 +24,7 @@ export default interface NativeRNCloudStorage {
|
|
|
24
24
|
fileExists: (path: string, scope: NativeRNCloudCloudStorageScope) => Promise<boolean>;
|
|
25
25
|
createFile: (path: string, data: string, scope: NativeRNCloudCloudStorageScope, overwrite: boolean) => Promise<void>;
|
|
26
26
|
createDirectory: (path: string, scope: NativeRNCloudCloudStorageScope) => Promise<void>;
|
|
27
|
+
listFiles: (path: string, scope: NativeRNCloudCloudStorageScope) => Promise<string[]>;
|
|
27
28
|
readFile: (path: string, scope: NativeRNCloudCloudStorageScope) => Promise<string>;
|
|
28
29
|
deleteFile: (path: string, scope: NativeRNCloudCloudStorageScope) => Promise<void>;
|
|
29
30
|
statFile: (path: string, scope: NativeRNCloudCloudStorageScope) => Promise<NativeRNCloudCloudStorageFileStat>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../../../src/types/native.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,8BAA8B,GAAG,WAAW,GAAG,UAAU,CAAC;AAEtE,MAAM,WAAW,iCAAiC;IAChD,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,OAAO,CAAC;IACrB,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,oBAAY,qBAAqB;IAC/B,cAAc,uBAAuB;IACrC,iBAAiB,0BAA0B;IAC3C,mBAAmB,
|
|
1
|
+
{"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../../../src/types/native.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,8BAA8B,GAAG,WAAW,GAAG,UAAU,CAAC;AAEtE,MAAM,WAAW,iCAAiC;IAChD,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,OAAO,CAAC;IACrB,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,oBAAY,qBAAqB;IAC/B,cAAc,uBAAuB;IACrC,iBAAiB,0BAA0B;IAC3C,mBAAmB,4BAA4B;IAC/C,mBAAmB,oBAAoB;IACvC,wBAAwB,iCAAiC;IACzD,qBAAqB,8BAA8B;IACnD,WAAW,oBAAoB;IAC/B,UAAU,mBAAmB;IAC7B,YAAY,qBAAqB;IACjC,UAAU,mBAAmB;IAC7B,OAAO,gBAAgB;IACvB,iCAAiC,0CAA0C;CAC5E;AAED,MAAM,CAAC,OAAO,WAAW,oBAAoB;IAC3C,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,8BAA8B,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACtF,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,8BAA8B,EAAE,SAAS,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACrH,eAAe,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,8BAA8B,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACxF,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,8BAA8B,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACtF,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,8BAA8B,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACnF,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,8BAA8B,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACnF,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,8BAA8B,KAAK,OAAO,CAAC,iCAAiC,CAAC,CAAC;IAC9G,gBAAgB,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;CAC1C"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the path starts with a leading slash and adds one if it doesn't to maintain backwards compatibility.
|
|
3
|
+
* Will log a warning to the console if it had to add a leading slash. Will throw an error in the future.
|
|
4
|
+
*
|
|
5
|
+
* @param path The path to check.
|
|
6
|
+
* @returns The path with a leading slash, if it didn't have one already.
|
|
7
|
+
* @private
|
|
8
|
+
*/
|
|
9
|
+
export declare const verifyLeadingSlash: (path: string) => string;
|
|
10
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/utils/helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,SAAU,MAAM,WAQ9C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-cloud-storage",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Save to & read from iCloud and Google Drive using React Native",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -29,34 +29,35 @@
|
|
|
29
29
|
],
|
|
30
30
|
"scripts": {
|
|
31
31
|
"test": "jest",
|
|
32
|
+
"example": "yarn workspace react-native-cloud-storage-example",
|
|
33
|
+
"docs": "yarn workspace react-native-cloud-storage-docs",
|
|
32
34
|
"typecheck": "tsc --noEmit",
|
|
33
35
|
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"docs": "yarn --cwd docs",
|
|
38
|
-
"bootstrap": "yarn example && yarn docs && yarn install && yarn example pods",
|
|
39
|
-
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build"
|
|
36
|
+
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
|
|
37
|
+
"prepare": "bob build",
|
|
38
|
+
"release": "release-it"
|
|
40
39
|
},
|
|
41
40
|
"keywords": [
|
|
42
41
|
"react-native",
|
|
43
42
|
"ios",
|
|
44
43
|
"android"
|
|
45
44
|
],
|
|
46
|
-
"repository": "https://github.com/
|
|
47
|
-
"author": "Kuatsu
|
|
45
|
+
"repository": "https://github.com/Kuatsu/react-native-cloud-storage",
|
|
46
|
+
"author": "Kuatsu App Agency <hello@kuatsu.de> (https://github.com/Kuatsu)",
|
|
48
47
|
"license": "MIT",
|
|
49
48
|
"bugs": {
|
|
50
|
-
"url": "https://github.com/
|
|
49
|
+
"url": "https://github.com/Kuatsu/react-native-cloud-storage/issues"
|
|
51
50
|
},
|
|
52
|
-
"homepage": "https://github.com/
|
|
51
|
+
"homepage": "https://github.com/Kuatsu/react-native-cloud-storage#readme",
|
|
53
52
|
"publishConfig": {
|
|
54
53
|
"registry": "https://registry.npmjs.org/"
|
|
55
54
|
},
|
|
56
55
|
"devDependencies": {
|
|
57
56
|
"@commitlint/config-conventional": "^17.0.2",
|
|
58
|
-
"@evilmartians/lefthook": "^1.
|
|
59
|
-
"@
|
|
57
|
+
"@evilmartians/lefthook": "^1.5.0",
|
|
58
|
+
"@expo/config-plugins": "^7.2.5",
|
|
59
|
+
"@react-native-community/eslint-config": "^3.2.0",
|
|
60
|
+
"@react-native/eslint-config": "^0.72.2",
|
|
60
61
|
"@release-it/conventional-changelog": "^5.0.0",
|
|
61
62
|
"@types/jest": "^28.1.2",
|
|
62
63
|
"@types/react": "~17.0.21",
|
|
@@ -66,21 +67,20 @@
|
|
|
66
67
|
"eslint": "^8.4.1",
|
|
67
68
|
"eslint-config-prettier": "^8.5.0",
|
|
68
69
|
"eslint-plugin-prettier": "^4.0.0",
|
|
69
|
-
"expo": "^47.0.0",
|
|
70
70
|
"jest": "^28.1.1",
|
|
71
71
|
"pod-install": "^0.1.0",
|
|
72
72
|
"prettier": "^2.0.5",
|
|
73
73
|
"react": "18.2.0",
|
|
74
|
-
"react-native": "0.
|
|
75
|
-
"react-native-builder-bob": "^0.20.
|
|
74
|
+
"react-native": "0.72.5",
|
|
75
|
+
"react-native-builder-bob": "^0.20.0",
|
|
76
76
|
"release-it": "^15.0.0",
|
|
77
|
-
"typescript": "^
|
|
77
|
+
"typescript": "^5.0.2"
|
|
78
78
|
},
|
|
79
79
|
"resolutions": {
|
|
80
80
|
"@types/react": "17.0.21"
|
|
81
81
|
},
|
|
82
82
|
"peerDependencies": {
|
|
83
|
-
"expo": ">=
|
|
83
|
+
"expo": ">=48.0.0",
|
|
84
84
|
"react": "*",
|
|
85
85
|
"react-native": "*"
|
|
86
86
|
},
|
|
@@ -89,10 +89,14 @@
|
|
|
89
89
|
"optional": true
|
|
90
90
|
}
|
|
91
91
|
},
|
|
92
|
+
"workspaces": [
|
|
93
|
+
"example",
|
|
94
|
+
"docs"
|
|
95
|
+
],
|
|
92
96
|
"engines": {
|
|
93
|
-
"node": ">=
|
|
97
|
+
"node": ">= 18.0.0"
|
|
94
98
|
},
|
|
95
|
-
"packageManager": "
|
|
99
|
+
"packageManager": "yarn@3.6.1",
|
|
96
100
|
"jest": {
|
|
97
101
|
"preset": "react-native",
|
|
98
102
|
"modulePathIgnorePatterns": [
|
|
@@ -12,10 +12,15 @@ Pod::Spec.new do |s|
|
|
|
12
12
|
s.authors = package["author"]
|
|
13
13
|
|
|
14
14
|
s.platforms = { :ios => "11.0" }
|
|
15
|
-
s.source = { :git => "https://github.com/
|
|
15
|
+
s.source = { :git => "https://github.com/Kuatsu/react-native-cloud-storage.git", :tag => "#{s.version}" }
|
|
16
16
|
|
|
17
17
|
s.source_files = "ios/**/*.{h,m,mm,swift}"
|
|
18
18
|
|
|
19
|
+
# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
|
|
20
|
+
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
|
|
21
|
+
if respond_to?(:install_modules_dependencies, true)
|
|
22
|
+
install_modules_dependencies(s)
|
|
23
|
+
else
|
|
19
24
|
s.dependency "React-Core"
|
|
20
25
|
|
|
21
26
|
# Don't install the dependencies when we run `pod install` in the old architecture.
|
|
@@ -31,5 +36,6 @@ Pod::Spec.new do |s|
|
|
|
31
36
|
s.dependency "RCTRequired"
|
|
32
37
|
s.dependency "RCTTypeSafety"
|
|
33
38
|
s.dependency "ReactCommon/turbomodule/core"
|
|
39
|
+
end
|
|
34
40
|
end
|
|
35
41
|
end
|
package/src/RNCloudStorage.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import createRNCloudStorage from './createRNCloudStorage';
|
|
2
2
|
import GoogleDriveApiClient from './google-drive';
|
|
3
|
-
import type
|
|
3
|
+
import { type CloudStorageFileStat, CloudStorageScope } from './types/main';
|
|
4
4
|
import { Platform } from 'react-native';
|
|
5
|
+
import { verifyLeadingSlash } from './utils/helpers';
|
|
5
6
|
|
|
6
7
|
const nativeInstance = createRNCloudStorage();
|
|
8
|
+
let defaultScope = CloudStorageScope.AppData;
|
|
7
9
|
|
|
8
10
|
const RNCloudStorage = {
|
|
11
|
+
getDefaultScope: () => defaultScope,
|
|
12
|
+
setDefaultScope: (scope: CloudStorageScope) => (defaultScope = scope),
|
|
9
13
|
getGoogleDriveAccessToken: () => GoogleDriveApiClient.accessToken,
|
|
10
14
|
setGoogleDriveAccessToken: (accessToken: string) => (GoogleDriveApiClient.accessToken = accessToken),
|
|
11
15
|
setThrowOnFilesWithSameName: (enable: boolean) => (GoogleDriveApiClient.throwOnFilesWithSameName = enable),
|
|
@@ -29,62 +33,72 @@ const RNCloudStorage = {
|
|
|
29
33
|
/**
|
|
30
34
|
* Tests whether or not the file at the given path exists.
|
|
31
35
|
* @param path The path to test.
|
|
32
|
-
* @param scope The directory scope the path is in.
|
|
36
|
+
* @param scope The directory scope the path is in. Defaults to the set default scope.
|
|
33
37
|
* @returns A promise that resolves to true if the path exists, false otherwise.
|
|
34
38
|
*/
|
|
35
|
-
exists: (path: string, scope
|
|
36
|
-
return nativeInstance.fileExists(path, scope);
|
|
39
|
+
exists: (path: string, scope?: CloudStorageScope): Promise<boolean> => {
|
|
40
|
+
return nativeInstance.fileExists(verifyLeadingSlash(path), scope ?? defaultScope);
|
|
37
41
|
},
|
|
38
42
|
|
|
39
43
|
/**
|
|
40
44
|
* Writes to the file at the given path, creating it if it doesn't exist or overwriting it if it does.
|
|
41
45
|
* @param path The file to write to.
|
|
42
46
|
* @param data The data to write.
|
|
43
|
-
* @param scope The directory scope the path is in.
|
|
47
|
+
* @param scope The directory scope the path is in. Defaults to the set default scope.
|
|
44
48
|
* @returns A promise that resolves when the file has been written.
|
|
45
49
|
*/
|
|
46
|
-
writeFile: (path: string, data: string, scope
|
|
47
|
-
return nativeInstance.createFile(path, data, scope, true);
|
|
50
|
+
writeFile: (path: string, data: string, scope?: CloudStorageScope): Promise<void> => {
|
|
51
|
+
return nativeInstance.createFile(verifyLeadingSlash(path), data, scope ?? defaultScope, true);
|
|
48
52
|
},
|
|
49
53
|
|
|
50
54
|
/**
|
|
51
55
|
* Creates a new directory at the given path.
|
|
52
56
|
* @param path The directory to create.
|
|
53
|
-
* @param scope The directory scope the path is in.
|
|
57
|
+
* @param scope The directory scope the path is in. Defaults to the set default scope.
|
|
54
58
|
* @returns A promise that resolves when the directory has been created.
|
|
55
59
|
*/
|
|
56
|
-
mkdir: (path: string, scope
|
|
57
|
-
return nativeInstance.createDirectory(path, scope);
|
|
60
|
+
mkdir: (path: string, scope?: CloudStorageScope): Promise<void> => {
|
|
61
|
+
return nativeInstance.createDirectory(verifyLeadingSlash(path), scope ?? defaultScope);
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Lists the contents of the directory at the given path.
|
|
66
|
+
* @param path The directory to list.
|
|
67
|
+
* @param scope The directory scope the path is in. Defaults to the set default scope.
|
|
68
|
+
* @returns A promise that resolves to an array of file names, excluding '.' and '..'.
|
|
69
|
+
*/
|
|
70
|
+
readdir: (path: string, scope?: CloudStorageScope): Promise<string[]> => {
|
|
71
|
+
return nativeInstance.listFiles(verifyLeadingSlash(path), scope ?? defaultScope);
|
|
58
72
|
},
|
|
59
73
|
|
|
60
74
|
/**
|
|
61
75
|
* Reads the contents of the file at the given path.
|
|
62
76
|
* @param path The file to read.
|
|
63
|
-
* @param scope The directory scope the path is in.
|
|
77
|
+
* @param scope The directory scope the path is in. Defaults to the set default scope.
|
|
64
78
|
* @returns A promise that resolves to the contents of the file.
|
|
65
79
|
*/
|
|
66
|
-
readFile: (path: string, scope
|
|
67
|
-
return nativeInstance.readFile(path, scope);
|
|
80
|
+
readFile: (path: string, scope?: CloudStorageScope): Promise<string> => {
|
|
81
|
+
return nativeInstance.readFile(verifyLeadingSlash(path), scope ?? defaultScope);
|
|
68
82
|
},
|
|
69
83
|
|
|
70
84
|
/**
|
|
71
85
|
* Deletes the file at the given path.
|
|
72
86
|
* @param path The file to delete.
|
|
73
|
-
* @param scope The directory scope the path is in.
|
|
87
|
+
* @param scope The directory scope the path is in. Defaults to the set default scope.
|
|
74
88
|
* @returns A promise that resolves when the file has been deleted.
|
|
75
89
|
*/
|
|
76
|
-
unlink: (path: string, scope
|
|
77
|
-
return nativeInstance.deleteFile(path, scope);
|
|
90
|
+
unlink: (path: string, scope?: CloudStorageScope): Promise<void> => {
|
|
91
|
+
return nativeInstance.deleteFile(verifyLeadingSlash(path), scope ?? defaultScope);
|
|
78
92
|
},
|
|
79
93
|
|
|
80
94
|
/**
|
|
81
95
|
* Gets the size, creation time, and modification time of the file at the given path.
|
|
82
96
|
* @param path The file to stat.
|
|
83
|
-
* @param scope The directory scope the path is in.
|
|
97
|
+
* @param scope The directory scope the path is in. Defaults to the set default scope.
|
|
84
98
|
* @returns A promise that resolves to the CloudStorageFileStat object.
|
|
85
99
|
*/
|
|
86
|
-
stat: async (path: string, scope
|
|
87
|
-
const native = await nativeInstance.statFile(path, scope);
|
|
100
|
+
stat: async (path: string, scope?: CloudStorageScope): Promise<CloudStorageFileStat> => {
|
|
101
|
+
const native = await nativeInstance.statFile(verifyLeadingSlash(path), scope ?? defaultScope);
|
|
88
102
|
|
|
89
103
|
return {
|
|
90
104
|
...native,
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
+
import type { RNCloudStorageConfigPluginOptions } from './types';
|
|
1
2
|
import withRNCloudStorageIos from './withRNCloudStorageIos';
|
|
2
3
|
import type { ConfigPlugin } from '@expo/config-plugins';
|
|
3
4
|
|
|
4
5
|
// Android config plugin not needed as there's no native code to configure.
|
|
5
6
|
|
|
6
|
-
interface RNCloudStorageConfigPluginOptions {
|
|
7
|
-
/**
|
|
8
|
-
* The iCloud container environment to use. Defaults to 'Production'.
|
|
9
|
-
*/
|
|
10
|
-
iCloudContainerEnvironment?: 'Production' | 'Development';
|
|
11
|
-
}
|
|
12
7
|
const withRNCloudStorage: ConfigPlugin<RNCloudStorageConfigPluginOptions> = (config, options) =>
|
|
13
|
-
withRNCloudStorageIos(config, options
|
|
8
|
+
withRNCloudStorageIos(config, options);
|
|
14
9
|
|
|
15
10
|
export default withRNCloudStorage;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { withEntitlementsPlist, withInfoPlist, withPlugins } from '@expo/config-plugins';
|
|
2
|
-
import type {
|
|
1
|
+
import { withEntitlementsPlist, withInfoPlist, withPlugins, type ConfigPlugin } from '@expo/config-plugins';
|
|
2
|
+
import type { RNCloudStorageConfigPluginOptions } from './types';
|
|
3
3
|
|
|
4
|
-
const withRNCloudStorageInfoPlist = (config
|
|
4
|
+
const withRNCloudStorageInfoPlist: ConfigPlugin = (config) =>
|
|
5
5
|
withInfoPlist(config, async (newConfig) => {
|
|
6
6
|
if (!config.ios?.bundleIdentifier) {
|
|
7
7
|
throw new Error('Missing iOS bundle identifier');
|
|
@@ -18,10 +18,7 @@ const withRNCloudStorageInfoPlist = (config: ExpoConfig) =>
|
|
|
18
18
|
return newConfig;
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
-
const withRNCloudStorageEntitlementsPlist = (
|
|
22
|
-
config: ExpoConfig,
|
|
23
|
-
iCloudContainerEnvironment: 'Production' | 'Development'
|
|
24
|
-
) =>
|
|
21
|
+
const withRNCloudStorageEntitlementsPlist: ConfigPlugin<RNCloudStorageConfigPluginOptions> = (config, options) =>
|
|
25
22
|
withEntitlementsPlist(config, async (newConfig) => {
|
|
26
23
|
if (!config.ios?.bundleIdentifier) {
|
|
27
24
|
throw new Error('Missing iOS bundle identifier');
|
|
@@ -29,7 +26,8 @@ const withRNCloudStorageEntitlementsPlist = (
|
|
|
29
26
|
const entitlementsPlist = newConfig.modResults;
|
|
30
27
|
entitlementsPlist['com.apple.developer.icloud-container-identifiers'] = [`iCloud.${config.ios.bundleIdentifier}`];
|
|
31
28
|
entitlementsPlist['com.apple.developer.icloud-services'] = ['CloudDocuments'];
|
|
32
|
-
entitlementsPlist['com.apple.developer.icloud-container-environment'] =
|
|
29
|
+
entitlementsPlist['com.apple.developer.icloud-container-environment'] =
|
|
30
|
+
options?.iCloudContainerEnvironment ?? 'Production';
|
|
33
31
|
entitlementsPlist['com.apple.developer.ubiquity-container-identifiers'] = [`iCloud.${config.ios.bundleIdentifier}`];
|
|
34
32
|
entitlementsPlist[
|
|
35
33
|
'com.apple.developer.ubiquity-kvstore-identifier'
|
|
@@ -38,7 +36,7 @@ const withRNCloudStorageEntitlementsPlist = (
|
|
|
38
36
|
return newConfig;
|
|
39
37
|
});
|
|
40
38
|
|
|
41
|
-
const withRNCloudStorageIos = (config
|
|
42
|
-
withPlugins(config, [withRNCloudStorageInfoPlist, [withRNCloudStorageEntitlementsPlist,
|
|
39
|
+
const withRNCloudStorageIos: ConfigPlugin<RNCloudStorageConfigPluginOptions> = (config, options) =>
|
|
40
|
+
withPlugins(config, [withRNCloudStorageInfoPlist, [withRNCloudStorageEntitlementsPlist, options]]);
|
|
43
41
|
|
|
44
42
|
export default withRNCloudStorageIos;
|