react-native-cloud-storage 0.4.1 → 0.4.2
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/lib/commonjs/RNCloudStorage.js +2 -2
- package/lib/commonjs/RNCloudStorage.js.map +1 -1
- package/lib/commonjs/createRNCloudStorage.js +5 -5
- package/lib/commonjs/createRNCloudStorage.js.map +1 -1
- package/lib/commonjs/google-drive/index.js +7 -7
- package/lib/commonjs/google-drive/index.js.map +1 -1
- package/lib/commonjs/hooks/useCloudFile.js.map +1 -1
- package/lib/commonjs/index.js +7 -7
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/types/main.js +6 -6
- package/lib/commonjs/types/main.js.map +1 -1
- package/lib/commonjs/types/native.js +13 -13
- package/lib/commonjs/types/native.js.map +1 -1
- package/lib/commonjs/utils/{NativeStorageError.js → CloudStorageError.js} +3 -3
- package/lib/commonjs/utils/CloudStorageError.js.map +1 -0
- package/lib/module/RNCloudStorage.js +2 -2
- package/lib/module/RNCloudStorage.js.map +1 -1
- package/lib/module/createRNCloudStorage.js +6 -6
- package/lib/module/createRNCloudStorage.js.map +1 -1
- package/lib/module/google-drive/index.js +8 -8
- package/lib/module/google-drive/index.js.map +1 -1
- package/lib/module/hooks/useCloudFile.js.map +1 -1
- package/lib/module/index.js +4 -4
- package/lib/module/index.js.map +1 -1
- package/lib/module/types/main.js +4 -4
- package/lib/module/types/main.js.map +1 -1
- package/lib/module/types/native.js +11 -11
- package/lib/module/types/native.js.map +1 -1
- package/lib/module/utils/CloudStorageError.js +9 -0
- package/lib/module/utils/CloudStorageError.js.map +1 -0
- package/lib/typescript/RNCloudStorage.d.ts +8 -8
- package/lib/typescript/RNCloudStorage.d.ts.map +1 -1
- package/lib/typescript/google-drive/index.d.ts +8 -8
- package/lib/typescript/google-drive/index.d.ts.map +1 -1
- package/lib/typescript/hooks/useCloudFile.d.ts +2 -2
- package/lib/typescript/hooks/useCloudFile.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +4 -4
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/types/main.d.ts +2 -2
- package/lib/typescript/types/main.d.ts.map +1 -1
- package/lib/typescript/types/native.d.ts +8 -8
- package/lib/typescript/types/native.d.ts.map +1 -1
- package/lib/typescript/utils/CloudStorageError.d.ts +8 -0
- package/lib/typescript/utils/CloudStorageError.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/RNCloudStorage.ts +8 -8
- package/src/createRNCloudStorage.ts +6 -6
- package/src/google-drive/index.ts +29 -24
- package/src/hooks/useCloudFile.ts +2 -2
- package/src/index.ts +4 -4
- package/src/types/main.ts +2 -2
- package/src/types/native.ts +8 -8
- package/src/utils/CloudStorageError.ts +14 -0
- package/lib/commonjs/utils/NativeStorageError.js.map +0 -1
- package/lib/module/utils/NativeStorageError.js +0 -9
- package/lib/module/utils/NativeStorageError.js.map +0 -1
- package/lib/typescript/utils/NativeStorageError.d.ts +0 -8
- package/lib/typescript/utils/NativeStorageError.d.ts.map +0 -1
- package/src/utils/NativeStorageError.ts +0 -14
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["CloudStorageError","Error","constructor","message","code","details"],"sourceRoot":"../../../src","sources":["utils/CloudStorageError.ts"],"mappings":"AAEA,MAAMA,iBAAiB,SAASC,KAAK,CAAC;EAIpCC,WAAWA,CAACC,OAAe,EAAEC,IAA2B,EAAEC,OAAa,EAAE;IACvE,KAAK,CAACF,OAAO,CAAC;IACd,IAAI,CAACC,IAAI,GAAGA,IAAI;IAChB,IAAI,CAACC,OAAO,GAAGA,OAAO;EACxB;AACF;AAEA,eAAeL,iBAAiB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CloudStorageFileStat, CloudStorageScope } from './types/main';
|
|
2
2
|
declare const RNCloudStorage: {
|
|
3
|
-
|
|
3
|
+
getGoogleDriveAccessToken: () => string | undefined;
|
|
4
4
|
setGoogleDriveAccessToken: (accessToken: string) => string;
|
|
5
5
|
/**
|
|
6
6
|
* Tests whether or not the cloud storage is available. Always returns true for Google Drive. iCloud may be
|
|
@@ -14,7 +14,7 @@ declare const RNCloudStorage: {
|
|
|
14
14
|
* @param scope The directory scope the path is in.
|
|
15
15
|
* @returns A promise that resolves to true if the path exists, false otherwise.
|
|
16
16
|
*/
|
|
17
|
-
exists: (path: string, scope:
|
|
17
|
+
exists: (path: string, scope: CloudStorageScope) => Promise<boolean>;
|
|
18
18
|
/**
|
|
19
19
|
* Writes to the file at the given path, creating it if it doesn't exist or overwriting it if it does.
|
|
20
20
|
* @param path The file to write to.
|
|
@@ -22,28 +22,28 @@ declare const RNCloudStorage: {
|
|
|
22
22
|
* @param scope The directory scope the path is in.
|
|
23
23
|
* @returns A promise that resolves when the file has been written.
|
|
24
24
|
*/
|
|
25
|
-
writeFile: (path: string, data: string, scope:
|
|
25
|
+
writeFile: (path: string, data: string, scope: CloudStorageScope) => Promise<void>;
|
|
26
26
|
/**
|
|
27
27
|
* Reads the contents of the file at the given path.
|
|
28
28
|
* @param path The file to read.
|
|
29
29
|
* @param scope The directory scope the path is in.
|
|
30
30
|
* @returns A promise that resolves to the contents of the file.
|
|
31
31
|
*/
|
|
32
|
-
readFile: (path: string, scope:
|
|
32
|
+
readFile: (path: string, scope: CloudStorageScope) => Promise<string>;
|
|
33
33
|
/**
|
|
34
34
|
* Deletes the file at the given path.
|
|
35
35
|
* @param path The file to delete.
|
|
36
36
|
* @param scope The directory scope the path is in.
|
|
37
37
|
* @returns A promise that resolves when the file has been deleted.
|
|
38
38
|
*/
|
|
39
|
-
unlink: (path: string, scope:
|
|
39
|
+
unlink: (path: string, scope: CloudStorageScope) => Promise<void>;
|
|
40
40
|
/**
|
|
41
41
|
* Gets the size, creation time, and modification time of the file at the given path.
|
|
42
42
|
* @param path The file to stat.
|
|
43
43
|
* @param scope The directory scope the path is in.
|
|
44
|
-
* @returns A promise that resolves to the
|
|
44
|
+
* @returns A promise that resolves to the CloudStorageFileStat object.
|
|
45
45
|
*/
|
|
46
|
-
stat: (path: string, scope:
|
|
46
|
+
stat: (path: string, scope: CloudStorageScope) => Promise<CloudStorageFileStat>;
|
|
47
47
|
};
|
|
48
48
|
export default RNCloudStorage;
|
|
49
49
|
//# sourceMappingURL=RNCloudStorage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RNCloudStorage.d.ts","sourceRoot":"","sources":["../../src/RNCloudStorage.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"RNCloudStorage.d.ts","sourceRoot":"","sources":["../../src/RNCloudStorage.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAG5E,QAAA,MAAM,cAAc;;6CAEuB,MAAM;IAE/C;;;;OAIG;4BACyB,QAAQ,OAAO,CAAC;IAI5C;;;;;OAKG;mBACY,MAAM,SAAS,iBAAiB,KAAG,QAAQ,OAAO,CAAC;IAIlE;;;;;;OAMG;sBACe,MAAM,QAAQ,MAAM,SAAS,iBAAiB,KAAG,QAAQ,IAAI,CAAC;IAIhF;;;;;OAKG;qBACc,MAAM,SAAS,iBAAiB,KAAG,QAAQ,MAAM,CAAC;IAInE;;;;;OAKG;mBACY,MAAM,SAAS,iBAAiB,KAAG,QAAQ,IAAI,CAAC;IAI/D;;;;;OAKG;iBACgB,MAAM,SAAS,iBAAiB,KAAG,QAAQ,oBAAoB,CAAC;CAWpF,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import type NativeRNCloudStorage from '../types/native';
|
|
2
|
-
import { type
|
|
2
|
+
import { type NativeRNCloudCloudStorageFileStat, type NativeRNCloudCloudStorageScope } from '../types/native';
|
|
3
3
|
declare class GoogleDriveApiClient implements NativeRNCloudStorage {
|
|
4
4
|
private static drive;
|
|
5
5
|
constructor();
|
|
6
|
-
static set accessToken(accessToken: string);
|
|
7
|
-
static get accessToken(): string;
|
|
6
|
+
static set accessToken(accessToken: string | undefined);
|
|
7
|
+
static get accessToken(): string | undefined;
|
|
8
8
|
isCloudAvailable: () => Promise<boolean>;
|
|
9
9
|
private getRootDirectory;
|
|
10
10
|
private resolvePathToDirectories;
|
|
11
11
|
private findParentDirectoryId;
|
|
12
12
|
private listFiles;
|
|
13
13
|
private getFileId;
|
|
14
|
-
fileExists(path: string, scope:
|
|
15
|
-
createFile(path: string, data: string, scope:
|
|
16
|
-
readFile(path: string, scope:
|
|
17
|
-
deleteFile(path: string, scope:
|
|
18
|
-
statFile(path: string, scope:
|
|
14
|
+
fileExists(path: string, scope: NativeRNCloudCloudStorageScope): Promise<boolean>;
|
|
15
|
+
createFile(path: string, data: string, scope: NativeRNCloudCloudStorageScope, overwrite: boolean): Promise<void>;
|
|
16
|
+
readFile(path: string, scope: NativeRNCloudCloudStorageScope): Promise<string>;
|
|
17
|
+
deleteFile(path: string, scope: NativeRNCloudCloudStorageScope): Promise<void>;
|
|
18
|
+
statFile(path: string, scope: NativeRNCloudCloudStorageScope): Promise<NativeRNCloudCloudStorageFileStat>;
|
|
19
19
|
}
|
|
20
20
|
export default GoogleDriveApiClient;
|
|
21
21
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -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,
|
|
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,cAAM,oBAAqB,YAAW,oBAAoB;IACxD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAwB;;IAsB5C,WAAkB,WAAW,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS,EAE5D;IAED,WAAkB,WAAW,IAAI,MAAM,GAAG,SAAS,CAElD;IAEM,gBAAgB,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAA0D;IAEzG,OAAO,CAAC,gBAAgB;IASxB,OAAO,CAAC,wBAAwB;IAQhC,OAAO,CAAC,qBAAqB;YAiDf,SAAS;YAST,SAAS;IAgBjB,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;IA2BV,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;CAahH;AAED,eAAe,oBAAoB,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const useCloudFile: (path: string, scope:
|
|
1
|
+
import type { CloudStorageScope } from '../types/main';
|
|
2
|
+
export declare const useCloudFile: (path: string, scope: CloudStorageScope) => {
|
|
3
3
|
content: string | null;
|
|
4
4
|
read: () => Promise<void>;
|
|
5
5
|
update: (newContent: string) => Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCloudFile.d.ts","sourceRoot":"","sources":["../../../src/hooks/useCloudFile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
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,SAAS,iBAAiB;;;yBAiB5C,MAAM;;CAkB5B,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import RNCloudStorage from './RNCloudStorage';
|
|
2
|
-
import {
|
|
2
|
+
import { CloudStorageErrorCode } from './types/native';
|
|
3
3
|
export * from './types/main';
|
|
4
4
|
export * from './hooks/useCloudFile';
|
|
5
5
|
export * from './hooks/useIsCloudAvailable';
|
|
6
|
-
import
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
6
|
+
import CloudStorageError from './utils/CloudStorageError';
|
|
7
|
+
export { CloudStorageError };
|
|
8
|
+
export { CloudStorageErrorCode };
|
|
9
9
|
export default RNCloudStorage;
|
|
10
10
|
//# 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,
|
|
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,CAAC;AAC7B,OAAO,EAAE,qBAAqB,EAAE,CAAC;AACjC,eAAe,cAAc,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export declare enum
|
|
1
|
+
export declare enum CloudStorageScope {
|
|
2
2
|
Documents = "documents",
|
|
3
3
|
AppData = "app_data"
|
|
4
4
|
}
|
|
5
|
-
export interface
|
|
5
|
+
export interface CloudStorageFileStat {
|
|
6
6
|
size: number;
|
|
7
7
|
birthtimeMs: number;
|
|
8
8
|
mtimeMs: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../../src/types/main.ts"],"names":[],"mappings":"AAAA,oBAAY,
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../../src/types/main.ts"],"names":[],"mappings":"AAAA,oBAAY,iBAAiB;IAC3B,SAAS,cAAc;IACvB,OAAO,aAAa;CACrB;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;IAChB,KAAK,EAAE,IAAI,CAAC;IACZ,WAAW,EAAE,MAAM,OAAO,CAAC;IAC3B,MAAM,EAAE,MAAM,OAAO,CAAC;CACvB"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export type
|
|
2
|
-
export interface
|
|
1
|
+
export type NativeRNCloudCloudStorageScope = 'documents' | 'app_data';
|
|
2
|
+
export interface NativeRNCloudCloudStorageFileStat {
|
|
3
3
|
size: number;
|
|
4
4
|
birthtimeMs: number;
|
|
5
5
|
mtimeMs: number;
|
|
6
6
|
isDirectory: boolean;
|
|
7
7
|
isFile: boolean;
|
|
8
8
|
}
|
|
9
|
-
export declare enum
|
|
9
|
+
export declare enum CloudStorageErrorCode {
|
|
10
10
|
FILE_NOT_FOUND = "ERR_FILE_NOT_FOUND",
|
|
11
11
|
DIRECTORY_NOT_FOUND = "ERR_NO_DIRECTORY_FOUND",
|
|
12
12
|
FILE_ALREADY_EXISTS = "ERR_FILE_EXISTS",
|
|
@@ -18,11 +18,11 @@ export declare enum NativeStorageErrorCode {
|
|
|
18
18
|
GOOGLE_DRIVE_ACCESS_TOKEN_MISSING = "ERR_GOOGLE_DRIVE_ACCESS_TOKEN_MISSING"
|
|
19
19
|
}
|
|
20
20
|
export default interface NativeRNCloudStorage {
|
|
21
|
-
fileExists: (path: string, scope:
|
|
22
|
-
createFile: (path: string, data: string, scope:
|
|
23
|
-
readFile: (path: string, scope:
|
|
24
|
-
deleteFile: (path: string, scope:
|
|
25
|
-
statFile: (path: string, scope:
|
|
21
|
+
fileExists: (path: string, scope: NativeRNCloudCloudStorageScope) => Promise<boolean>;
|
|
22
|
+
createFile: (path: string, data: string, scope: NativeRNCloudCloudStorageScope, overwrite: boolean) => Promise<void>;
|
|
23
|
+
readFile: (path: string, scope: NativeRNCloudCloudStorageScope) => Promise<string>;
|
|
24
|
+
deleteFile: (path: string, scope: NativeRNCloudCloudStorageScope) => Promise<void>;
|
|
25
|
+
statFile: (path: string, scope: NativeRNCloudCloudStorageScope) => Promise<NativeRNCloudCloudStorageFileStat>;
|
|
26
26
|
isCloudAvailable: () => Promise<boolean>;
|
|
27
27
|
}
|
|
28
28
|
//# sourceMappingURL=native.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../../../src/types/native.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,
|
|
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,mBAAmB,2BAA2B;IAC9C,mBAAmB,oBAAoB;IACvC,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,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,8 @@
|
|
|
1
|
+
import type { CloudStorageErrorCode } from '../types/native';
|
|
2
|
+
declare class CloudStorageError extends Error {
|
|
3
|
+
code: CloudStorageErrorCode;
|
|
4
|
+
details?: any;
|
|
5
|
+
constructor(message: string, code: CloudStorageErrorCode, details?: any);
|
|
6
|
+
}
|
|
7
|
+
export default CloudStorageError;
|
|
8
|
+
//# sourceMappingURL=CloudStorageError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CloudStorageError.d.ts","sourceRoot":"","sources":["../../../src/utils/CloudStorageError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAE7D,cAAM,iBAAkB,SAAQ,KAAK;IACnC,IAAI,EAAE,qBAAqB,CAAC;IAC5B,OAAO,CAAC,EAAE,GAAG,CAAC;gBAEF,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,qBAAqB,EAAE,OAAO,CAAC,EAAE,GAAG;CAKxE;AAED,eAAe,iBAAiB,CAAC"}
|
package/package.json
CHANGED
package/src/RNCloudStorage.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
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
|
|
|
5
5
|
const nativeInstance = createRNCloudStorage();
|
|
6
6
|
const RNCloudStorage = {
|
|
7
|
-
|
|
7
|
+
getGoogleDriveAccessToken: () => GoogleDriveApiClient.accessToken,
|
|
8
8
|
setGoogleDriveAccessToken: (accessToken: string) => (GoogleDriveApiClient.accessToken = accessToken),
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -22,7 +22,7 @@ const RNCloudStorage = {
|
|
|
22
22
|
* @param scope The directory scope the path is in.
|
|
23
23
|
* @returns A promise that resolves to true if the path exists, false otherwise.
|
|
24
24
|
*/
|
|
25
|
-
exists: (path: string, scope:
|
|
25
|
+
exists: (path: string, scope: CloudStorageScope): Promise<boolean> => {
|
|
26
26
|
return nativeInstance.fileExists(path, scope);
|
|
27
27
|
},
|
|
28
28
|
|
|
@@ -33,7 +33,7 @@ const RNCloudStorage = {
|
|
|
33
33
|
* @param scope The directory scope the path is in.
|
|
34
34
|
* @returns A promise that resolves when the file has been written.
|
|
35
35
|
*/
|
|
36
|
-
writeFile: (path: string, data: string, scope:
|
|
36
|
+
writeFile: (path: string, data: string, scope: CloudStorageScope): Promise<void> => {
|
|
37
37
|
return nativeInstance.createFile(path, data, scope, true);
|
|
38
38
|
},
|
|
39
39
|
|
|
@@ -43,7 +43,7 @@ const RNCloudStorage = {
|
|
|
43
43
|
* @param scope The directory scope the path is in.
|
|
44
44
|
* @returns A promise that resolves to the contents of the file.
|
|
45
45
|
*/
|
|
46
|
-
readFile: (path: string, scope:
|
|
46
|
+
readFile: (path: string, scope: CloudStorageScope): Promise<string> => {
|
|
47
47
|
return nativeInstance.readFile(path, scope);
|
|
48
48
|
},
|
|
49
49
|
|
|
@@ -53,7 +53,7 @@ const RNCloudStorage = {
|
|
|
53
53
|
* @param scope The directory scope the path is in.
|
|
54
54
|
* @returns A promise that resolves when the file has been deleted.
|
|
55
55
|
*/
|
|
56
|
-
unlink: (path: string, scope:
|
|
56
|
+
unlink: (path: string, scope: CloudStorageScope): Promise<void> => {
|
|
57
57
|
return nativeInstance.deleteFile(path, scope);
|
|
58
58
|
},
|
|
59
59
|
|
|
@@ -61,9 +61,9 @@ const RNCloudStorage = {
|
|
|
61
61
|
* Gets the size, creation time, and modification time of the file at the given path.
|
|
62
62
|
* @param path The file to stat.
|
|
63
63
|
* @param scope The directory scope the path is in.
|
|
64
|
-
* @returns A promise that resolves to the
|
|
64
|
+
* @returns A promise that resolves to the CloudStorageFileStat object.
|
|
65
65
|
*/
|
|
66
|
-
stat: async (path: string, scope:
|
|
66
|
+
stat: async (path: string, scope: CloudStorageScope): Promise<CloudStorageFileStat> => {
|
|
67
67
|
const native = await nativeInstance.statFile(path, scope);
|
|
68
68
|
|
|
69
69
|
return {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { NativeModules, Platform } from 'react-native';
|
|
2
2
|
import type NativeRNCloudStorage from './types/native';
|
|
3
3
|
import GoogleDriveApiClient from './google-drive';
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
4
|
+
import { CloudStorageErrorCode } from './types/native';
|
|
5
|
+
import CloudStorageError from './utils/CloudStorageError';
|
|
6
6
|
|
|
7
7
|
const LINKING_ERROR =
|
|
8
8
|
`The package 'react-native-cloud-storage' doesn't seem to be linked. Make sure: \n\n` +
|
|
@@ -10,7 +10,7 @@ const LINKING_ERROR =
|
|
|
10
10
|
'- You rebuilt the app after installing the package\n' +
|
|
11
11
|
'- You are not using Expo Go\n';
|
|
12
12
|
|
|
13
|
-
// proxy NativeModules.CloudStorage to catch any errors thrown by the native module and wrap them in a
|
|
13
|
+
// proxy NativeModules.CloudStorage to catch any errors thrown by the native module and wrap them in a CloudStorageError
|
|
14
14
|
const nativeIosInstance = NativeModules.CloudStorage
|
|
15
15
|
? new Proxy(NativeModules.CloudStorage, {
|
|
16
16
|
get(target: NativeRNCloudStorage, prop: keyof NativeRNCloudStorage) {
|
|
@@ -21,10 +21,10 @@ const nativeIosInstance = NativeModules.CloudStorage
|
|
|
21
21
|
// @ts-expect-error - we can't know the types of the functions and their arguments
|
|
22
22
|
return await originalFunction(...args);
|
|
23
23
|
} catch (error: any) {
|
|
24
|
-
if (error?.code && Object.values(
|
|
25
|
-
throw new
|
|
24
|
+
if (error?.code && Object.values(CloudStorageErrorCode).includes(error.code)) {
|
|
25
|
+
throw new CloudStorageError(error?.message || '', error.code as CloudStorageErrorCode);
|
|
26
26
|
} else {
|
|
27
|
-
throw new
|
|
27
|
+
throw new CloudStorageError('Unknown error', CloudStorageErrorCode.UNKNOWN, error);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { GDrive, MimeTypes } from 'react-native-google-drive-api-wrapper-js';
|
|
2
2
|
import type NativeRNCloudStorage from '../types/native';
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
type
|
|
6
|
-
type
|
|
4
|
+
CloudStorageErrorCode,
|
|
5
|
+
type NativeRNCloudCloudStorageFileStat,
|
|
6
|
+
type NativeRNCloudCloudStorageScope,
|
|
7
7
|
} from '../types/native';
|
|
8
8
|
import type { GoogleDriveDetailedFile, GoogleDriveFile, GoogleDriveListOperationResponse } from './types';
|
|
9
|
-
import
|
|
9
|
+
import CloudStorageError from '../utils/CloudStorageError';
|
|
10
10
|
|
|
11
11
|
class GoogleDriveApiClient implements NativeRNCloudStorage {
|
|
12
12
|
private static drive: GDrive = new GDrive();
|
|
@@ -18,9 +18,9 @@ class GoogleDriveApiClient implements NativeRNCloudStorage {
|
|
|
18
18
|
get(target: GoogleDriveApiClient, prop: keyof GoogleDriveApiClient) {
|
|
19
19
|
if (typeof target[prop] === 'function' && prop !== 'isCloudAvailable') {
|
|
20
20
|
if (!GoogleDriveApiClient.drive.accessToken) {
|
|
21
|
-
throw new
|
|
21
|
+
throw new CloudStorageError(
|
|
22
22
|
`Google Drive access token is not set, cannot call function ${prop.toString()}`,
|
|
23
|
-
|
|
23
|
+
CloudStorageErrorCode.GOOGLE_DRIVE_ACCESS_TOKEN_MISSING
|
|
24
24
|
);
|
|
25
25
|
}
|
|
26
26
|
}
|
|
@@ -31,17 +31,17 @@ class GoogleDriveApiClient implements NativeRNCloudStorage {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
// when setting accessToken, set it on the GDrive instance
|
|
34
|
-
public static set accessToken(accessToken: string) {
|
|
34
|
+
public static set accessToken(accessToken: string | undefined) {
|
|
35
35
|
GoogleDriveApiClient.drive.accessToken = accessToken;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
public static get accessToken(): string {
|
|
38
|
+
public static get accessToken(): string | undefined {
|
|
39
39
|
return GoogleDriveApiClient.drive.accessToken;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
public isCloudAvailable: () => Promise<boolean> = async () => !!GoogleDriveApiClient.accessToken?.length;
|
|
43
43
|
|
|
44
|
-
private getRootDirectory(scope:
|
|
44
|
+
private getRootDirectory(scope: NativeRNCloudCloudStorageScope): 'drive' | 'appDataFolder' {
|
|
45
45
|
switch (scope) {
|
|
46
46
|
case 'documents':
|
|
47
47
|
return 'drive';
|
|
@@ -80,9 +80,9 @@ class GoogleDriveApiClient implements NativeRNCloudStorage {
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
if (!topDirectoryId) {
|
|
83
|
-
throw new
|
|
83
|
+
throw new CloudStorageError(
|
|
84
84
|
`Could not find top directory with name ${directoryTree[0]}`,
|
|
85
|
-
|
|
85
|
+
CloudStorageErrorCode.DIRECTORY_NOT_FOUND
|
|
86
86
|
);
|
|
87
87
|
}
|
|
88
88
|
|
|
@@ -91,15 +91,15 @@ class GoogleDriveApiClient implements NativeRNCloudStorage {
|
|
|
91
91
|
for (let i = 1; i < directoryTree.length; i++) {
|
|
92
92
|
const currentDirectory = files.find((f) => f.id === currentDirectoryId);
|
|
93
93
|
if (!currentDirectory)
|
|
94
|
-
throw new
|
|
94
|
+
throw new CloudStorageError(
|
|
95
95
|
`Could not find directory with id ${currentDirectoryId}`,
|
|
96
|
-
|
|
96
|
+
CloudStorageErrorCode.DIRECTORY_NOT_FOUND
|
|
97
97
|
);
|
|
98
98
|
const nextDirectory = files.find((f) => f.name === directoryTree[i] && f.parents![0] === currentDirectoryId);
|
|
99
99
|
if (!nextDirectory)
|
|
100
|
-
throw new
|
|
100
|
+
throw new CloudStorageError(
|
|
101
101
|
`Could not find directory with name ${directoryTree[i]}`,
|
|
102
|
-
|
|
102
|
+
CloudStorageErrorCode.DIRECTORY_NOT_FOUND
|
|
103
103
|
);
|
|
104
104
|
currentDirectoryId = nextDirectory.id;
|
|
105
105
|
}
|
|
@@ -107,7 +107,7 @@ class GoogleDriveApiClient implements NativeRNCloudStorage {
|
|
|
107
107
|
return currentDirectoryId;
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
private async listFiles(scope:
|
|
110
|
+
private async listFiles(scope: NativeRNCloudCloudStorageScope): Promise<GoogleDriveFile[]> {
|
|
111
111
|
const files: GoogleDriveListOperationResponse = await GoogleDriveApiClient.drive.files.list({
|
|
112
112
|
spaces: [this.getRootDirectory(scope)],
|
|
113
113
|
fields: 'files(id,kind,mimeType,name,parents,spaces)',
|
|
@@ -116,7 +116,7 @@ class GoogleDriveApiClient implements NativeRNCloudStorage {
|
|
|
116
116
|
return files.files;
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
-
private async getFileId(path: string, scope:
|
|
119
|
+
private async getFileId(path: string, scope: NativeRNCloudCloudStorageScope): Promise<string> {
|
|
120
120
|
const files = await this.listFiles(scope);
|
|
121
121
|
const { directories, filename } = this.resolvePathToDirectories(path);
|
|
122
122
|
const parentDirectoryId = this.findParentDirectoryId(files, directories);
|
|
@@ -128,21 +128,26 @@ class GoogleDriveApiClient implements NativeRNCloudStorage {
|
|
|
128
128
|
} else {
|
|
129
129
|
file = files.find((f) => f.name === filename && f.parents![0] === parentDirectoryId);
|
|
130
130
|
}
|
|
131
|
-
if (!file) throw new
|
|
131
|
+
if (!file) throw new CloudStorageError(`File not found`, CloudStorageErrorCode.FILE_NOT_FOUND);
|
|
132
132
|
return file.id;
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
-
async fileExists(path: string, scope:
|
|
135
|
+
async fileExists(path: string, scope: NativeRNCloudCloudStorageScope): Promise<boolean> {
|
|
136
136
|
try {
|
|
137
137
|
await this.getFileId(path, scope);
|
|
138
138
|
return true;
|
|
139
139
|
} catch (e: any) {
|
|
140
|
-
if (e instanceof
|
|
140
|
+
if (e instanceof CloudStorageError && e.code === CloudStorageErrorCode.FILE_NOT_FOUND) return false;
|
|
141
141
|
else throw e;
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
async createFile(
|
|
145
|
+
async createFile(
|
|
146
|
+
path: string,
|
|
147
|
+
data: string,
|
|
148
|
+
scope: NativeRNCloudCloudStorageScope,
|
|
149
|
+
overwrite: boolean
|
|
150
|
+
): Promise<void> {
|
|
146
151
|
let fileId: string | undefined;
|
|
147
152
|
if (overwrite) {
|
|
148
153
|
try {
|
|
@@ -169,18 +174,18 @@ class GoogleDriveApiClient implements NativeRNCloudStorage {
|
|
|
169
174
|
await uploader.execute();
|
|
170
175
|
}
|
|
171
176
|
|
|
172
|
-
async readFile(path: string, scope:
|
|
177
|
+
async readFile(path: string, scope: NativeRNCloudCloudStorageScope): Promise<string> {
|
|
173
178
|
const fileId = await this.getFileId(path, scope);
|
|
174
179
|
const content = await GoogleDriveApiClient.drive.files.getText(fileId);
|
|
175
180
|
return content;
|
|
176
181
|
}
|
|
177
182
|
|
|
178
|
-
async deleteFile(path: string, scope:
|
|
183
|
+
async deleteFile(path: string, scope: NativeRNCloudCloudStorageScope): Promise<void> {
|
|
179
184
|
const fileId = await this.getFileId(path, scope);
|
|
180
185
|
await GoogleDriveApiClient.drive.files.delete(fileId);
|
|
181
186
|
}
|
|
182
187
|
|
|
183
|
-
async statFile(path: string, scope:
|
|
188
|
+
async statFile(path: string, scope: NativeRNCloudCloudStorageScope): Promise<NativeRNCloudCloudStorageFileStat> {
|
|
184
189
|
const fileId = await this.getFileId(path, scope);
|
|
185
190
|
const file: GoogleDriveDetailedFile = await GoogleDriveApiClient.drive.files.get(fileId, {
|
|
186
191
|
fields: 'id,kind,mimeType,name,parents,spaces,size,createdTime,modifiedTime',
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CloudStorageScope } from '../types/main';
|
|
2
2
|
import RNCloudStorage from '../RNCloudStorage';
|
|
3
3
|
import { useCallback, useEffect, useState } from 'react';
|
|
4
4
|
|
|
5
|
-
export const useCloudFile = (path: string, scope:
|
|
5
|
+
export const useCloudFile = (path: string, scope: CloudStorageScope) => {
|
|
6
6
|
const [content, setContent] = useState<string | null>(null);
|
|
7
7
|
|
|
8
8
|
const read = useCallback(async () => {
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import RNCloudStorage from './RNCloudStorage';
|
|
2
|
-
import {
|
|
2
|
+
import { CloudStorageErrorCode } from './types/native';
|
|
3
3
|
export * from './types/main';
|
|
4
4
|
export * from './hooks/useCloudFile';
|
|
5
5
|
export * from './hooks/useIsCloudAvailable';
|
|
6
|
-
import
|
|
6
|
+
import CloudStorageError from './utils/CloudStorageError';
|
|
7
7
|
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
8
|
+
export { CloudStorageError };
|
|
9
|
+
export { CloudStorageErrorCode };
|
|
10
10
|
export default RNCloudStorage;
|
package/src/types/main.ts
CHANGED
package/src/types/native.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type NativeRNCloudCloudStorageScope = 'documents' | 'app_data';
|
|
2
2
|
|
|
3
|
-
export interface
|
|
3
|
+
export interface NativeRNCloudCloudStorageFileStat {
|
|
4
4
|
size: number;
|
|
5
5
|
birthtimeMs: number;
|
|
6
6
|
mtimeMs: number;
|
|
@@ -8,7 +8,7 @@ export interface NativeRNCloudStorageFileStat {
|
|
|
8
8
|
isFile: boolean;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
export enum
|
|
11
|
+
export enum CloudStorageErrorCode {
|
|
12
12
|
FILE_NOT_FOUND = 'ERR_FILE_NOT_FOUND',
|
|
13
13
|
DIRECTORY_NOT_FOUND = 'ERR_NO_DIRECTORY_FOUND',
|
|
14
14
|
FILE_ALREADY_EXISTS = 'ERR_FILE_EXISTS',
|
|
@@ -21,10 +21,10 @@ export enum NativeStorageErrorCode {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export default interface NativeRNCloudStorage {
|
|
24
|
-
fileExists: (path: string, scope:
|
|
25
|
-
createFile: (path: string, data: string, scope:
|
|
26
|
-
readFile: (path: string, scope:
|
|
27
|
-
deleteFile: (path: string, scope:
|
|
28
|
-
statFile: (path: string, scope:
|
|
24
|
+
fileExists: (path: string, scope: NativeRNCloudCloudStorageScope) => Promise<boolean>;
|
|
25
|
+
createFile: (path: string, data: string, scope: NativeRNCloudCloudStorageScope, overwrite: boolean) => Promise<void>;
|
|
26
|
+
readFile: (path: string, scope: NativeRNCloudCloudStorageScope) => Promise<string>;
|
|
27
|
+
deleteFile: (path: string, scope: NativeRNCloudCloudStorageScope) => Promise<void>;
|
|
28
|
+
statFile: (path: string, scope: NativeRNCloudCloudStorageScope) => Promise<NativeRNCloudCloudStorageFileStat>;
|
|
29
29
|
isCloudAvailable: () => Promise<boolean>;
|
|
30
30
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { CloudStorageErrorCode } from '../types/native';
|
|
2
|
+
|
|
3
|
+
class CloudStorageError extends Error {
|
|
4
|
+
code: CloudStorageErrorCode;
|
|
5
|
+
details?: any;
|
|
6
|
+
|
|
7
|
+
constructor(message: string, code: CloudStorageErrorCode, details?: any) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.code = code;
|
|
10
|
+
this.details = details;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default CloudStorageError;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["NativeStorageError","Error","constructor","message","code","details","_default","exports","default"],"sourceRoot":"../../../src","sources":["utils/NativeStorageError.ts"],"mappings":";;;;;;AAEA,MAAMA,kBAAkB,SAASC,KAAK,CAAC;EAIrCC,WAAWA,CAACC,OAAe,EAAEC,IAA4B,EAAEC,OAAa,EAAE;IACxE,KAAK,CAACF,OAAO,CAAC;IACd,IAAI,CAACC,IAAI,GAAGA,IAAI;IAChB,IAAI,CAACC,OAAO,GAAGA,OAAO;EACxB;AACF;AAAC,IAAAC,QAAA,GAEcN,kBAAkB;AAAAO,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["NativeStorageError","Error","constructor","message","code","details"],"sourceRoot":"../../../src","sources":["utils/NativeStorageError.ts"],"mappings":"AAEA,MAAMA,kBAAkB,SAASC,KAAK,CAAC;EAIrCC,WAAWA,CAACC,OAAe,EAAEC,IAA4B,EAAEC,OAAa,EAAE;IACxE,KAAK,CAACF,OAAO,CAAC;IACd,IAAI,CAACC,IAAI,GAAGA,IAAI;IAChB,IAAI,CAACC,OAAO,GAAGA,OAAO;EACxB;AACF;AAEA,eAAeL,kBAAkB"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { NativeStorageErrorCode } from '../types/native';
|
|
2
|
-
declare class NativeStorageError extends Error {
|
|
3
|
-
code: NativeStorageErrorCode;
|
|
4
|
-
details?: any;
|
|
5
|
-
constructor(message: string, code: NativeStorageErrorCode, details?: any);
|
|
6
|
-
}
|
|
7
|
-
export default NativeStorageError;
|
|
8
|
-
//# sourceMappingURL=NativeStorageError.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NativeStorageError.d.ts","sourceRoot":"","sources":["../../../src/utils/NativeStorageError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAE9D,cAAM,kBAAmB,SAAQ,KAAK;IACpC,IAAI,EAAE,sBAAsB,CAAC;IAC7B,OAAO,CAAC,EAAE,GAAG,CAAC;gBAEF,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,sBAAsB,EAAE,OAAO,CAAC,EAAE,GAAG;CAKzE;AAED,eAAe,kBAAkB,CAAC"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { NativeStorageErrorCode } from '../types/native';
|
|
2
|
-
|
|
3
|
-
class NativeStorageError extends Error {
|
|
4
|
-
code: NativeStorageErrorCode;
|
|
5
|
-
details?: any;
|
|
6
|
-
|
|
7
|
-
constructor(message: string, code: NativeStorageErrorCode, details?: any) {
|
|
8
|
-
super(message);
|
|
9
|
-
this.code = code;
|
|
10
|
-
this.details = details;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export default NativeStorageError;
|