react-native-cloud-storage 0.4.0 → 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 -1
- 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 +12 -9
- package/lib/commonjs/google-drive/index.js.map +1 -1
- package/lib/commonjs/hooks/useCloudFile.js.map +1 -1
- package/lib/commonjs/hooks/useIsCloudAvailable.js +18 -15
- package/lib/commonjs/hooks/useIsCloudAvailable.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 -1
- 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 +13 -10
- package/lib/module/google-drive/index.js.map +1 -1
- package/lib/module/hooks/useCloudFile.js.map +1 -1
- package/lib/module/hooks/useIsCloudAvailable.js +18 -15
- package/lib/module/hooks/useIsCloudAvailable.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 -7
- 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/hooks/useIsCloudAvailable.d.ts +1 -1
- package/lib/typescript/hooks/useIsCloudAvailable.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 -7
- package/src/createRNCloudStorage.ts +6 -6
- package/src/google-drive/index.ts +31 -26
- package/src/hooks/useCloudFile.ts +2 -2
- package/src/hooks/useIsCloudAvailable.ts +20 -15
- 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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["RNCloudStorage","useCallback","useEffect","useState","useCloudFile","path","scope","content","setContent","read","exists","readFile","then","update","newContent","writeFile","remove","unlink"],"sourceRoot":"../../../src","sources":["hooks/useCloudFile.ts"],"mappings":"AACA,OAAOA,cAAc,MAAM,mBAAmB;AAC9C,SAASC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAExD,OAAO,MAAMC,YAAY,GAAGA,CAACC,IAAY,EAAEC,
|
|
1
|
+
{"version":3,"names":["RNCloudStorage","useCallback","useEffect","useState","useCloudFile","path","scope","content","setContent","read","exists","readFile","then","update","newContent","writeFile","remove","unlink"],"sourceRoot":"../../../src","sources":["hooks/useCloudFile.ts"],"mappings":"AACA,OAAOA,cAAc,MAAM,mBAAmB;AAC9C,SAASC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAExD,OAAO,MAAMC,YAAY,GAAGA,CAACC,IAAY,EAAEC,KAAwB,KAAK;EACtE,MAAM,CAACC,OAAO,EAAEC,UAAU,CAAC,GAAGL,QAAQ,CAAgB,IAAI,CAAC;EAE3D,MAAMM,IAAI,GAAGR,WAAW,CAAC,YAAY;IACnC,MAAMS,MAAM,GAAG,MAAMV,cAAc,CAACU,MAAM,CAACL,IAAI,EAAEC,KAAK,CAAC;IACvD,IAAI,CAACI,MAAM,EAAE;MACXF,UAAU,CAAC,IAAI,CAAC;MAChB;IACF;IACAR,cAAc,CAACW,QAAQ,CAACN,IAAI,EAAEC,KAAK,CAAC,CAACM,IAAI,CAACJ,UAAU,CAAC;EACvD,CAAC,EAAE,CAACH,IAAI,EAAEC,KAAK,CAAC,CAAC;EAEjBJ,SAAS,CAAC,MAAM;IACdO,IAAI,EAAE;EACR,CAAC,EAAE,CAACA,IAAI,CAAC,CAAC;EAEV,MAAMI,MAAM,GAAGZ,WAAW,CACxB,MAAOa,UAAkB,IAAK;IAC5B,MAAMd,cAAc,CAACe,SAAS,CAACV,IAAI,EAAES,UAAU,EAAER,KAAK,CAAC;IACvDG,IAAI,EAAE;EACR,CAAC,EACD,CAACJ,IAAI,EAAEC,KAAK,EAAEG,IAAI,CAAC,CACpB;EAED,MAAMO,MAAM,GAAGf,WAAW,CAAC,YAAY;IACrC,MAAMD,cAAc,CAACiB,MAAM,CAACZ,IAAI,EAAEC,KAAK,CAAC;IACxCE,UAAU,CAAC,IAAI,CAAC;EAClB,CAAC,EAAE,CAACH,IAAI,EAAEC,KAAK,CAAC,CAAC;EAEjB,OAAO;IACLC,OAAO;IACPE,IAAI;IACJI,MAAM;IACNG;EACF,CAAC;AACH,CAAC"}
|
|
@@ -4,22 +4,25 @@ import RNCloudStorage from '../RNCloudStorage';
|
|
|
4
4
|
|
|
5
5
|
// TODO: there must be a better way to do this without a timeout?
|
|
6
6
|
export const useIsCloudAvailable = function () {
|
|
7
|
-
let
|
|
8
|
-
const [
|
|
9
|
-
const [firstCheck] = useState(new Date());
|
|
7
|
+
let iCloudTimeout = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
|
|
8
|
+
const [isAvailable, setIsAvailable] = useState(false);
|
|
10
9
|
useEffect(() => {
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
} else {
|
|
18
|
-
console.log('Cloud storage is not available.');
|
|
10
|
+
const interval = setInterval(async () => {
|
|
11
|
+
const newIsAvailable = await RNCloudStorage.isCloudAvailable();
|
|
12
|
+
setIsAvailable(newIsAvailable);
|
|
13
|
+
if (Platform.OS === 'ios' && newIsAvailable) {
|
|
14
|
+
console.log('Stopped because iCloud became available');
|
|
15
|
+
clearInterval(interval);
|
|
19
16
|
}
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
}, 500);
|
|
18
|
+
if (Platform.OS === 'ios') {
|
|
19
|
+
setTimeout(() => {
|
|
20
|
+
console.log('Stopped because of timeout');
|
|
21
|
+
clearInterval(interval);
|
|
22
|
+
}, iCloudTimeout * 1000);
|
|
23
|
+
}
|
|
24
|
+
return () => clearInterval(interval);
|
|
25
|
+
}, [iCloudTimeout]);
|
|
26
|
+
return isAvailable;
|
|
24
27
|
};
|
|
25
28
|
//# sourceMappingURL=useIsCloudAvailable.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useEffect","useState","Platform","RNCloudStorage","useIsCloudAvailable","
|
|
1
|
+
{"version":3,"names":["useEffect","useState","Platform","RNCloudStorage","useIsCloudAvailable","iCloudTimeout","arguments","length","undefined","isAvailable","setIsAvailable","interval","setInterval","newIsAvailable","isCloudAvailable","OS","console","log","clearInterval","setTimeout"],"sourceRoot":"../../../src","sources":["hooks/useIsCloudAvailable.ts"],"mappings":"AAAA,SAASA,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAC3C,SAASC,QAAQ,QAAQ,cAAc;AACvC,OAAOC,cAAc,MAAM,mBAAmB;;AAE9C;AACA,OAAO,MAAMC,mBAAmB,GAAG,SAAAA,CAAA,EAAwB;EAAA,IAAvBC,aAAa,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,EAAE;EACpD,MAAM,CAACG,WAAW,EAAEC,cAAc,CAAC,GAAGT,QAAQ,CAAC,KAAK,CAAC;EAErDD,SAAS,CAAC,MAAM;IACd,MAAMW,QAAQ,GAAGC,WAAW,CAAC,YAAY;MACvC,MAAMC,cAAc,GAAG,MAAMV,cAAc,CAACW,gBAAgB,EAAE;MAC9DJ,cAAc,CAACG,cAAc,CAAC;MAC9B,IAAIX,QAAQ,CAACa,EAAE,KAAK,KAAK,IAAIF,cAAc,EAAE;QAC3CG,OAAO,CAACC,GAAG,CAAC,yCAAyC,CAAC;QACtDC,aAAa,CAACP,QAAQ,CAAC;MACzB;IACF,CAAC,EAAE,GAAG,CAAC;IAEP,IAAIT,QAAQ,CAACa,EAAE,KAAK,KAAK,EAAE;MACzBI,UAAU,CAAC,MAAM;QACfH,OAAO,CAACC,GAAG,CAAC,4BAA4B,CAAC;QACzCC,aAAa,CAACP,QAAQ,CAAC;MACzB,CAAC,EAAEN,aAAa,GAAG,IAAI,CAAC;IAC1B;IAEA,OAAO,MAAMa,aAAa,CAACP,QAAQ,CAAC;EACtC,CAAC,EAAE,CAACN,aAAa,CAAC,CAAC;EAEnB,OAAOI,WAAW;AACpB,CAAC"}
|
package/lib/module/index.js
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
|
|
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.js.map
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["RNCloudStorage","
|
|
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,SAASA,iBAAiB;AAC1B,SAASD,qBAAqB;AAC9B,eAAeD,cAAc"}
|
package/lib/module/types/main.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export let
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
return
|
|
1
|
+
export let CloudStorageScope = /*#__PURE__*/function (CloudStorageScope) {
|
|
2
|
+
CloudStorageScope["Documents"] = "documents";
|
|
3
|
+
CloudStorageScope["AppData"] = "app_data";
|
|
4
|
+
return CloudStorageScope;
|
|
5
5
|
}({});
|
|
6
6
|
//# sourceMappingURL=main.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["CloudStorageScope"],"sourceRoot":"../../../src","sources":["types/main.ts"],"mappings":"AAAA,WAAYA,iBAAiB,0BAAjBA,iBAAiB;EAAjBA,iBAAiB;EAAjBA,iBAAiB;EAAA,OAAjBA,iBAAiB;AAAA"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export let
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return
|
|
1
|
+
export let CloudStorageErrorCode = /*#__PURE__*/function (CloudStorageErrorCode) {
|
|
2
|
+
CloudStorageErrorCode["FILE_NOT_FOUND"] = "ERR_FILE_NOT_FOUND";
|
|
3
|
+
CloudStorageErrorCode["DIRECTORY_NOT_FOUND"] = "ERR_NO_DIRECTORY_FOUND";
|
|
4
|
+
CloudStorageErrorCode["FILE_ALREADY_EXISTS"] = "ERR_FILE_EXISTS";
|
|
5
|
+
CloudStorageErrorCode["WRITE_ERROR"] = "ERR_WRITE_ERROR";
|
|
6
|
+
CloudStorageErrorCode["READ_ERROR"] = "ERR_READ_ERROR";
|
|
7
|
+
CloudStorageErrorCode["DELETE_ERROR"] = "ERR_DELETE_ERROR";
|
|
8
|
+
CloudStorageErrorCode["STAT_ERROR"] = "ERR_STAT_ERROR";
|
|
9
|
+
CloudStorageErrorCode["UNKNOWN"] = "ERR_UNKNOWN";
|
|
10
|
+
CloudStorageErrorCode["GOOGLE_DRIVE_ACCESS_TOKEN_MISSING"] = "ERR_GOOGLE_DRIVE_ACCESS_TOKEN_MISSING";
|
|
11
|
+
return CloudStorageErrorCode;
|
|
12
12
|
}({});
|
|
13
13
|
//# sourceMappingURL=native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["CloudStorageErrorCode"],"sourceRoot":"../../../src","sources":["types/native.ts"],"mappings":"AAUA,WAAYA,qBAAqB,0BAArBA,qBAAqB;EAArBA,qBAAqB;EAArBA,qBAAqB;EAArBA,qBAAqB;EAArBA,qBAAqB;EAArBA,qBAAqB;EAArBA,qBAAqB;EAArBA,qBAAqB;EAArBA,qBAAqB;EAArBA,qBAAqB;EAAA,OAArBA,qBAAqB;AAAA"}
|
|
@@ -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,5 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CloudStorageFileStat, CloudStorageScope } from './types/main';
|
|
2
2
|
declare const RNCloudStorage: {
|
|
3
|
+
getGoogleDriveAccessToken: () => string | undefined;
|
|
3
4
|
setGoogleDriveAccessToken: (accessToken: string) => string;
|
|
4
5
|
/**
|
|
5
6
|
* Tests whether or not the cloud storage is available. Always returns true for Google Drive. iCloud may be
|
|
@@ -13,7 +14,7 @@ declare const RNCloudStorage: {
|
|
|
13
14
|
* @param scope The directory scope the path is in.
|
|
14
15
|
* @returns A promise that resolves to true if the path exists, false otherwise.
|
|
15
16
|
*/
|
|
16
|
-
exists: (path: string, scope:
|
|
17
|
+
exists: (path: string, scope: CloudStorageScope) => Promise<boolean>;
|
|
17
18
|
/**
|
|
18
19
|
* Writes to the file at the given path, creating it if it doesn't exist or overwriting it if it does.
|
|
19
20
|
* @param path The file to write to.
|
|
@@ -21,28 +22,28 @@ declare const RNCloudStorage: {
|
|
|
21
22
|
* @param scope The directory scope the path is in.
|
|
22
23
|
* @returns A promise that resolves when the file has been written.
|
|
23
24
|
*/
|
|
24
|
-
writeFile: (path: string, data: string, scope:
|
|
25
|
+
writeFile: (path: string, data: string, scope: CloudStorageScope) => Promise<void>;
|
|
25
26
|
/**
|
|
26
27
|
* Reads the contents of the file at the given path.
|
|
27
28
|
* @param path The file to read.
|
|
28
29
|
* @param scope The directory scope the path is in.
|
|
29
30
|
* @returns A promise that resolves to the contents of the file.
|
|
30
31
|
*/
|
|
31
|
-
readFile: (path: string, scope:
|
|
32
|
+
readFile: (path: string, scope: CloudStorageScope) => Promise<string>;
|
|
32
33
|
/**
|
|
33
34
|
* Deletes the file at the given path.
|
|
34
35
|
* @param path The file to delete.
|
|
35
36
|
* @param scope The directory scope the path is in.
|
|
36
37
|
* @returns A promise that resolves when the file has been deleted.
|
|
37
38
|
*/
|
|
38
|
-
unlink: (path: string, scope:
|
|
39
|
+
unlink: (path: string, scope: CloudStorageScope) => Promise<void>;
|
|
39
40
|
/**
|
|
40
41
|
* Gets the size, creation time, and modification time of the file at the given path.
|
|
41
42
|
* @param path The file to stat.
|
|
42
43
|
* @param scope The directory scope the path is in.
|
|
43
|
-
* @returns A promise that resolves to the
|
|
44
|
+
* @returns A promise that resolves to the CloudStorageFileStat object.
|
|
44
45
|
*/
|
|
45
|
-
stat: (path: string, scope:
|
|
46
|
+
stat: (path: string, scope: CloudStorageScope) => Promise<CloudStorageFileStat>;
|
|
46
47
|
};
|
|
47
48
|
export default RNCloudStorage;
|
|
48
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,2 +1,2 @@
|
|
|
1
|
-
export declare const useIsCloudAvailable: (
|
|
1
|
+
export declare const useIsCloudAvailable: (iCloudTimeout?: number) => boolean;
|
|
2
2
|
//# sourceMappingURL=useIsCloudAvailable.d.ts.map
|
|
@@ -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,qCAwB/B,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,9 +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
|
+
getGoogleDriveAccessToken: () => GoogleDriveApiClient.accessToken,
|
|
7
8
|
setGoogleDriveAccessToken: (accessToken: string) => (GoogleDriveApiClient.accessToken = accessToken),
|
|
8
9
|
|
|
9
10
|
/**
|
|
@@ -21,7 +22,7 @@ const RNCloudStorage = {
|
|
|
21
22
|
* @param scope The directory scope the path is in.
|
|
22
23
|
* @returns A promise that resolves to true if the path exists, false otherwise.
|
|
23
24
|
*/
|
|
24
|
-
exists: (path: string, scope:
|
|
25
|
+
exists: (path: string, scope: CloudStorageScope): Promise<boolean> => {
|
|
25
26
|
return nativeInstance.fileExists(path, scope);
|
|
26
27
|
},
|
|
27
28
|
|
|
@@ -32,7 +33,7 @@ const RNCloudStorage = {
|
|
|
32
33
|
* @param scope The directory scope the path is in.
|
|
33
34
|
* @returns A promise that resolves when the file has been written.
|
|
34
35
|
*/
|
|
35
|
-
writeFile: (path: string, data: string, scope:
|
|
36
|
+
writeFile: (path: string, data: string, scope: CloudStorageScope): Promise<void> => {
|
|
36
37
|
return nativeInstance.createFile(path, data, scope, true);
|
|
37
38
|
},
|
|
38
39
|
|
|
@@ -42,7 +43,7 @@ const RNCloudStorage = {
|
|
|
42
43
|
* @param scope The directory scope the path is in.
|
|
43
44
|
* @returns A promise that resolves to the contents of the file.
|
|
44
45
|
*/
|
|
45
|
-
readFile: (path: string, scope:
|
|
46
|
+
readFile: (path: string, scope: CloudStorageScope): Promise<string> => {
|
|
46
47
|
return nativeInstance.readFile(path, scope);
|
|
47
48
|
},
|
|
48
49
|
|
|
@@ -52,7 +53,7 @@ const RNCloudStorage = {
|
|
|
52
53
|
* @param scope The directory scope the path is in.
|
|
53
54
|
* @returns A promise that resolves when the file has been deleted.
|
|
54
55
|
*/
|
|
55
|
-
unlink: (path: string, scope:
|
|
56
|
+
unlink: (path: string, scope: CloudStorageScope): Promise<void> => {
|
|
56
57
|
return nativeInstance.deleteFile(path, scope);
|
|
57
58
|
},
|
|
58
59
|
|
|
@@ -60,9 +61,9 @@ const RNCloudStorage = {
|
|
|
60
61
|
* Gets the size, creation time, and modification time of the file at the given path.
|
|
61
62
|
* @param path The file to stat.
|
|
62
63
|
* @param scope The directory scope the path is in.
|
|
63
|
-
* @returns A promise that resolves to the
|
|
64
|
+
* @returns A promise that resolves to the CloudStorageFileStat object.
|
|
64
65
|
*/
|
|
65
|
-
stat: async (path: string, scope:
|
|
66
|
+
stat: async (path: string, scope: CloudStorageScope): Promise<CloudStorageFileStat> => {
|
|
66
67
|
const native = await nativeInstance.statFile(path, scope);
|
|
67
68
|
|
|
68
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
|
};
|