react-native-cloud-storage 0.1.2 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/README.md +3 -1
  2. package/ios/CloudStorage.m +1 -4
  3. package/ios/CloudStorage.swift +41 -0
  4. package/lib/commonjs/RNCloudStorage.js +16 -0
  5. package/lib/commonjs/RNCloudStorage.js.map +1 -1
  6. package/lib/commonjs/createRNCloudStorage.js +26 -5
  7. package/lib/commonjs/createRNCloudStorage.js.map +1 -1
  8. package/lib/commonjs/google-drive/index.js +22 -6
  9. package/lib/commonjs/google-drive/index.js.map +1 -1
  10. package/lib/commonjs/index.js +18 -1
  11. package/lib/commonjs/index.js.map +1 -1
  12. package/lib/commonjs/types/native.js +18 -0
  13. package/lib/commonjs/types/native.js.map +1 -1
  14. package/lib/commonjs/utils/NativeStorageError.js +16 -0
  15. package/lib/commonjs/utils/NativeStorageError.js.map +1 -0
  16. package/lib/module/RNCloudStorage.js +16 -0
  17. package/lib/module/RNCloudStorage.js.map +1 -1
  18. package/lib/module/createRNCloudStorage.js +26 -5
  19. package/lib/module/createRNCloudStorage.js.map +1 -1
  20. package/lib/module/google-drive/index.js +21 -6
  21. package/lib/module/google-drive/index.js.map +1 -1
  22. package/lib/module/index.js +4 -0
  23. package/lib/module/index.js.map +1 -1
  24. package/lib/module/types/native.js +12 -1
  25. package/lib/module/types/native.js.map +1 -1
  26. package/lib/module/utils/NativeStorageError.js +9 -0
  27. package/lib/module/utils/NativeStorageError.js.map +1 -0
  28. package/lib/typescript/RNCloudStorage.d.ts +8 -1
  29. package/lib/typescript/RNCloudStorage.d.ts.map +1 -1
  30. package/lib/typescript/createRNCloudStorage.d.ts.map +1 -1
  31. package/lib/typescript/google-drive/index.d.ts +2 -1
  32. package/lib/typescript/google-drive/index.d.ts.map +1 -1
  33. package/lib/typescript/google-drive/types.d.ts +5 -0
  34. package/lib/typescript/google-drive/types.d.ts.map +1 -1
  35. package/lib/typescript/index.d.ts +4 -0
  36. package/lib/typescript/index.d.ts.map +1 -1
  37. package/lib/typescript/types/main.d.ts +9 -0
  38. package/lib/typescript/types/main.d.ts.map +1 -1
  39. package/lib/typescript/types/native.d.ts +19 -0
  40. package/lib/typescript/types/native.d.ts.map +1 -1
  41. package/lib/typescript/utils/NativeStorageError.d.ts +8 -0
  42. package/lib/typescript/utils/NativeStorageError.d.ts.map +1 -0
  43. package/package.json +1 -1
  44. package/src/RNCloudStorage.ts +19 -1
  45. package/src/createRNCloudStorage.ts +28 -6
  46. package/src/google-drive/index.ts +41 -8
  47. package/src/google-drive/types.ts +6 -0
  48. package/src/index.ts +4 -0
  49. package/src/types/main.ts +10 -0
  50. package/src/types/native.ts +21 -0
  51. package/src/utils/NativeStorageError.ts +14 -0
package/README.md CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  Save & read from iCloud and Google Drive using React Native
4
4
 
5
- **⚠️ WARNING**: This project is still considered unstable. Please proceed with caution and report any issues you're encountering.
5
+ ![npm bundle size](https://img.shields.io/bundlephobia/min/react-native-cloud-storage?style=flat-square) ![GitHub](https://img.shields.io/github/license/kuatsu/react-native-cloud-storage?style=flat-square) ![GitHub last commit](https://img.shields.io/github/last-commit/kuatsu/react-native-cloud-storage)
6
+
7
+ **⚠️ WARNING**: This project is still considered unstable. The API might change drastically in new versions. Please proceed with caution and report any issues you're encountering.
6
8
 
7
9
  ## Installation
8
10
 
@@ -2,14 +2,11 @@
2
2
 
3
3
  @interface RCT_EXTERN_MODULE(CloudStorage, NSObject)
4
4
 
5
- RCT_EXTERN_METHOD(multiply:(float)a withB:(float)b
6
- withResolver:(RCTPromiseResolveBlock)resolve
7
- withRejecter:(RCTPromiseRejectBlock)reject)
8
-
9
5
  RCT_EXTERN_METHOD(fileExists:(NSString *)path withScope:(NSString *)scope withResolver:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject)
10
6
  RCT_EXTERN_METHOD(createFile:(NSString *)path withData:(NSString *)data withScope:(NSString *)scope withOverwrite:(BOOL)overwrite withResolver:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject)
11
7
  RCT_EXTERN_METHOD(readFile:(NSString *)path withScope:(NSString *)scope withResolver:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject)
12
8
  RCT_EXTERN_METHOD(deleteFile:(NSString *)path withScope:(NSString *)scope withResolver:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject)
9
+ RCT_EXTERN_METHOD(statFile:(NSString *)path withScope:(NSString *)scope withResolver:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject)
13
10
 
14
11
  + (BOOL)requiresMainQueueSetup
15
12
  {
@@ -81,6 +81,47 @@ class CloudStorage: NSObject {
81
81
  }
82
82
  }
83
83
 
84
+ /* return an object with the following properties:
85
+ * size: filesize in bytes
86
+ * birthtimeMs: creation time in milliseconds
87
+ * mtimeMs: modification time in milliseconds
88
+ * isDirectory: true if the path is a directory
89
+ * isFile: true if the path is a file
90
+ */
91
+ @objc(statFile:withScope:withResolver:withRejecter:)
92
+ func statFile(path: String, scope: String, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
93
+ let fileManager = FileManager.default
94
+ let directory = getDirectory(scope)
95
+ if (directory == nil) {
96
+ reject("ERR_NO_DIRECTORY_FOUND", "No directory found for scope \(scope)", nil)
97
+ return
98
+ }
99
+ let filePath = directory?.appendingPathComponent(path)
100
+ let fileExists = fileManager.fileExists(atPath: filePath!.path)
101
+ if (!fileExists) {
102
+ reject("ERR_FILE_NOT_FOUND", "File \(path) not found", nil)
103
+ return
104
+ }
105
+ do {
106
+ let attributes = try fileManager.attributesOfItem(atPath: filePath!.path)
107
+ let size = attributes[FileAttributeKey.size] as! UInt64
108
+ let birthtime = attributes[FileAttributeKey.creationDate] as! Date
109
+ let mtime = attributes[FileAttributeKey.modificationDate] as! Date
110
+ let isDirectory = attributes[FileAttributeKey.type] as! FileAttributeType == FileAttributeType.typeDirectory
111
+ let isFile = attributes[FileAttributeKey.type] as! FileAttributeType == FileAttributeType.typeRegular
112
+ let result = [
113
+ "size": size,
114
+ "birthtimeMs": birthtime.timeIntervalSince1970 * 1000,
115
+ "mtimeMs": mtime.timeIntervalSince1970 * 1000,
116
+ "isDirectory": isDirectory,
117
+ "isFile": isFile
118
+ ] as [String : Any]
119
+ resolve(result)
120
+ } catch {
121
+ reject("ERR_STAT_ERROR", "Error getting stats for file \(path)", error)
122
+ }
123
+ }
124
+
84
125
  /// Returns the iCloud directory URL for the given scope.
85
126
  ///
86
127
  /// - Parameter scope: The scope of the directory. Can be either "documents" or "hidden".
@@ -46,6 +46,22 @@ const RNCloudStorage = {
46
46
  */
47
47
  unlink: (path, scope) => {
48
48
  return nativeInstance.deleteFile(path, scope);
49
+ },
50
+ /**
51
+ * Gets the size, creation time, and modification time of the file at the given path.
52
+ * @param path The file to stat.
53
+ * @param scope The directory scope the path is in.
54
+ * @returns A promise that resolves to the StorageFileStat object.
55
+ */
56
+ stat: async (path, scope) => {
57
+ const native = await nativeInstance.statFile(path, scope);
58
+ return {
59
+ ...native,
60
+ birthtime: new Date(native.birthtimeMs),
61
+ mtime: new Date(native.mtimeMs),
62
+ isDirectory: () => native.isDirectory,
63
+ isFile: () => native.isFile
64
+ };
49
65
  }
50
66
  };
51
67
  var _default = RNCloudStorage;
@@ -1 +1 @@
1
- {"version":3,"names":["_createRNCloudStorage","_interopRequireDefault","require","_googleDrive","obj","__esModule","default","nativeInstance","createRNCloudStorage","RNCloudStorage","setGoogleDriveAccessToken","accessToken","GoogleDriveApiClient","exists","path","scope","fileExists","writeFile","data","createFile","readFile","unlink","deleteFile","_default","exports"],"sourceRoot":"../../src","sources":["RNCloudStorage.ts"],"mappings":";;;;;;AAAA,IAAAA,qBAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAF,sBAAA,CAAAC,OAAA;AAAkD,SAAAD,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAGlD,MAAMG,cAAc,GAAG,IAAAC,6BAAoB,GAAE;AAC7C,MAAMC,cAAc,GAAG;EACrBC,yBAAyB,EAAGC,WAAmB,IAAMC,oBAAoB,CAACD,WAAW,GAAGA,WAAY;EACpG;AACF;AACA;AACA;AACA;AACA;EACEE,MAAM,EAAEA,CAACC,IAAY,EAAEC,KAAmB,KAAuB;IAC/D,OAAOR,cAAc,CAACS,UAAU,CAACF,IAAI,EAAEC,KAAK,CAAC;EAC/C,CAAC;EAED;AACF;AACA;AACA;AACA;AACA;AACA;EACEE,SAAS,EAAEA,CAACH,IAAY,EAAEI,IAAY,EAAEH,KAAmB,KAAoB;IAC7E,OAAOR,cAAc,CAACY,UAAU,CAACL,IAAI,EAAEI,IAAI,EAAEH,KAAK,EAAE,IAAI,CAAC;EAC3D,CAAC;EAED;AACF;AACA;AACA;AACA;AACA;EACEK,QAAQ,EAAEA,CAACN,IAAY,EAAEC,KAAmB,KAAsB;IAChE,OAAOR,cAAc,CAACa,QAAQ,CAACN,IAAI,EAAEC,KAAK,CAAC;EAC7C,CAAC;EAED;AACF;AACA;AACA;AACA;AACA;EACEM,MAAM,EAAEA,CAACP,IAAY,EAAEC,KAAmB,KAAoB;IAC5D,OAAOR,cAAc,CAACe,UAAU,CAACR,IAAI,EAAEC,KAAK,CAAC;EAC/C;AACF,CAAC;AAAC,IAAAQ,QAAA,GAEad,cAAc;AAAAe,OAAA,CAAAlB,OAAA,GAAAiB,QAAA"}
1
+ {"version":3,"names":["_createRNCloudStorage","_interopRequireDefault","require","_googleDrive","obj","__esModule","default","nativeInstance","createRNCloudStorage","RNCloudStorage","setGoogleDriveAccessToken","accessToken","GoogleDriveApiClient","exists","path","scope","fileExists","writeFile","data","createFile","readFile","unlink","deleteFile","stat","native","statFile","birthtime","Date","birthtimeMs","mtime","mtimeMs","isDirectory","isFile","_default","exports"],"sourceRoot":"../../src","sources":["RNCloudStorage.ts"],"mappings":";;;;;;AAAA,IAAAA,qBAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAF,sBAAA,CAAAC,OAAA;AAAkD,SAAAD,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAGlD,MAAMG,cAAc,GAAG,IAAAC,6BAAoB,GAAE;AAC7C,MAAMC,cAAc,GAAG;EACrBC,yBAAyB,EAAGC,WAAmB,IAAMC,oBAAoB,CAACD,WAAW,GAAGA,WAAY;EACpG;AACF;AACA;AACA;AACA;AACA;EACEE,MAAM,EAAEA,CAACC,IAAY,EAAEC,KAAmB,KAAuB;IAC/D,OAAOR,cAAc,CAACS,UAAU,CAACF,IAAI,EAAEC,KAAK,CAAC;EAC/C,CAAC;EAED;AACF;AACA;AACA;AACA;AACA;AACA;EACEE,SAAS,EAAEA,CAACH,IAAY,EAAEI,IAAY,EAAEH,KAAmB,KAAoB;IAC7E,OAAOR,cAAc,CAACY,UAAU,CAACL,IAAI,EAAEI,IAAI,EAAEH,KAAK,EAAE,IAAI,CAAC;EAC3D,CAAC;EAED;AACF;AACA;AACA;AACA;AACA;EACEK,QAAQ,EAAEA,CAACN,IAAY,EAAEC,KAAmB,KAAsB;IAChE,OAAOR,cAAc,CAACa,QAAQ,CAACN,IAAI,EAAEC,KAAK,CAAC;EAC7C,CAAC;EAED;AACF;AACA;AACA;AACA;AACA;EACEM,MAAM,EAAEA,CAACP,IAAY,EAAEC,KAAmB,KAAoB;IAC5D,OAAOR,cAAc,CAACe,UAAU,CAACR,IAAI,EAAEC,KAAK,CAAC;EAC/C,CAAC;EAED;AACF;AACA;AACA;AACA;AACA;EACEQ,IAAI,EAAE,MAAAA,CAAOT,IAAY,EAAEC,KAAmB,KAA+B;IAC3E,MAAMS,MAAM,GAAG,MAAMjB,cAAc,CAACkB,QAAQ,CAACX,IAAI,EAAEC,KAAK,CAAC;IAEzD,OAAO;MACL,GAAGS,MAAM;MACTE,SAAS,EAAE,IAAIC,IAAI,CAACH,MAAM,CAACI,WAAW,CAAC;MACvCC,KAAK,EAAE,IAAIF,IAAI,CAACH,MAAM,CAACM,OAAO,CAAC;MAC/BC,WAAW,EAAEA,CAAA,KAAMP,MAAM,CAACO,WAAW;MACrCC,MAAM,EAAEA,CAAA,KAAMR,MAAM,CAACQ;IACvB,CAAC;EACH;AACF,CAAC;AAAC,IAAAC,QAAA,GAEaxB,cAAc;AAAAyB,OAAA,CAAA5B,OAAA,GAAA2B,QAAA"}
@@ -6,22 +6,43 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = createRNCloudStorage;
7
7
  var _reactNative = require("react-native");
8
8
  var _googleDrive = _interopRequireDefault(require("./google-drive"));
9
+ var _native = require("./types/native");
10
+ var _NativeStorageError = _interopRequireDefault(require("./utils/NativeStorageError"));
9
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
12
  const LINKING_ERROR = `The package 'react-native-cloud-storage' doesn't seem to be linked. Make sure: \n\n` + _reactNative.Platform.select({
11
13
  ios: "- You have run 'pod install'\n",
12
14
  default: ''
13
15
  }) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
16
+
17
+ // proxy NativeModules.CloudStorage to catch any errors thrown by the native module and wrap them in a NativeStorageError
18
+ const nativeIosInstance = _reactNative.NativeModules.CloudStorage ? new Proxy(_reactNative.NativeModules.CloudStorage, {
19
+ get(target, prop) {
20
+ const originalFunction = target[prop];
21
+ if (typeof originalFunction === 'function') {
22
+ return async function () {
23
+ try {
24
+ // @ts-expect-error - we can't know the types of the functions and their arguments
25
+ return await originalFunction(...arguments);
26
+ } catch (error) {
27
+ if (error !== null && error !== void 0 && error.code && Object.values(_native.NativeStorageErrorCode).includes(error.code)) {
28
+ throw new _NativeStorageError.default((error === null || error === void 0 ? void 0 : error.message) || '', error.code);
29
+ } else {
30
+ throw new _NativeStorageError.default('Unknown error', _native.NativeStorageErrorCode.UNKNOWN, error);
31
+ }
32
+ }
33
+ };
34
+ }
35
+ return originalFunction;
36
+ }
37
+ }) : null;
14
38
  function createRNCloudStorage() {
15
39
  if (_reactNative.Platform.OS === 'ios') {
16
- return _reactNative.NativeModules.CloudStorage ?? new Proxy({}, {
40
+ return nativeIosInstance ?? new Proxy({}, {
17
41
  get() {
18
42
  throw new Error(LINKING_ERROR);
19
43
  }
20
44
  });
21
45
  }
22
- if (_reactNative.Platform.OS === 'android') {
23
- return new _googleDrive.default();
24
- }
25
- throw new Error('Unsupported platform');
46
+ return new _googleDrive.default();
26
47
  }
27
48
  //# sourceMappingURL=createRNCloudStorage.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_reactNative","require","_googleDrive","_interopRequireDefault","obj","__esModule","default","LINKING_ERROR","Platform","select","ios","createRNCloudStorage","OS","NativeModules","CloudStorage","Proxy","get","Error","GoogleDriveApiClient"],"sourceRoot":"../../src","sources":["createRNCloudStorage.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,YAAA,GAAAC,sBAAA,CAAAF,OAAA;AAAkD,SAAAE,uBAAAC,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAElD,MAAMG,aAAa,GAChB,qFAAoF,GACrFC,qBAAQ,CAACC,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEJ,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;AAElB,SAASK,oBAAoBA,CAAA,EAAyB;EACnE,IAAIH,qBAAQ,CAACI,EAAE,KAAK,KAAK,EAAE;IACzB,OACGC,0BAAa,CAACC,YAAY,IAC3B,IAAIC,KAAK,CACP,CAAC,CAAC,EACF;MACEC,GAAGA,CAAA,EAAG;QACJ,MAAM,IAAIC,KAAK,CAACV,aAAa,CAAC;MAChC;IACF,CAAC,CACF;EAEL;EAEA,IAAIC,qBAAQ,CAACI,EAAE,KAAK,SAAS,EAAE;IAC7B,OAAO,IAAIM,oBAAoB,EAAE;EACnC;EAEA,MAAM,IAAID,KAAK,CAAC,sBAAsB,CAAC;AACzC"}
1
+ {"version":3,"names":["_reactNative","require","_googleDrive","_interopRequireDefault","_native","_NativeStorageError","obj","__esModule","default","LINKING_ERROR","Platform","select","ios","nativeIosInstance","NativeModules","CloudStorage","Proxy","get","target","prop","originalFunction","arguments","error","code","Object","values","NativeStorageErrorCode","includes","NativeStorageError","message","UNKNOWN","createRNCloudStorage","OS","Error","GoogleDriveApiClient"],"sourceRoot":"../../src","sources":["createRNCloudStorage.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,YAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,mBAAA,GAAAF,sBAAA,CAAAF,OAAA;AAA4D,SAAAE,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAE5D,MAAMG,aAAa,GAChB,qFAAoF,GACrFC,qBAAQ,CAACC,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEJ,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;;AAEjC;AACA,MAAMK,iBAAiB,GAAGC,0BAAa,CAACC,YAAY,GAChD,IAAIC,KAAK,CAACF,0BAAa,CAACC,YAAY,EAAE;EACpCE,GAAGA,CAACC,MAA4B,EAAEC,IAAgC,EAAE;IAClE,MAAMC,gBAAgB,GAAGF,MAAM,CAACC,IAAI,CAAC;IACrC,IAAI,OAAOC,gBAAgB,KAAK,UAAU,EAAE;MAC1C,OAAO,kBAA0B;QAC/B,IAAI;UACF;UACA,OAAO,MAAMA,gBAAgB,CAAC,GAAAC,SAAO,CAAC;QACxC,CAAC,CAAC,OAAOC,KAAU,EAAE;UACnB,IAAIA,KAAK,aAALA,KAAK,eAALA,KAAK,CAAEC,IAAI,IAAIC,MAAM,CAACC,MAAM,CAACC,8BAAsB,CAAC,CAACC,QAAQ,CAACL,KAAK,CAACC,IAAI,CAAC,EAAE;YAC7E,MAAM,IAAIK,2BAAkB,CAAC,CAAAN,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEO,OAAO,KAAI,EAAE,EAAEP,KAAK,CAACC,IAAI,CAA2B;UAC1F,CAAC,MAAM;YACL,MAAM,IAAIK,2BAAkB,CAAC,eAAe,EAAEF,8BAAsB,CAACI,OAAO,EAAER,KAAK,CAAC;UACtF;QACF;MACF,CAAC;IACH;IACA,OAAOF,gBAAgB;EACzB;AACF,CAAC,CAAC,GACF,IAAI;AAEO,SAASW,oBAAoBA,CAAA,EAAyB;EACnE,IAAIrB,qBAAQ,CAACsB,EAAE,KAAK,KAAK,EAAE;IACzB,OACEnB,iBAAiB,IACjB,IAAIG,KAAK,CACP,CAAC,CAAC,EACF;MACEC,GAAGA,CAAA,EAAG;QACJ,MAAM,IAAIgB,KAAK,CAACxB,aAAa,CAAC;MAChC;IACF,CAAC,CACF;EAEL;EAEA,OAAO,IAAIyB,oBAAoB,EAAE;AACnC"}
@@ -5,6 +5,9 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _reactNativeGoogleDriveApiWrapperJs = require("react-native-google-drive-api-wrapper-js");
8
+ var _native = require("../types/native");
9
+ var _NativeStorageError = _interopRequireDefault(require("../utils/NativeStorageError"));
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
11
  class GoogleDriveApiClient {
9
12
  static drive = new _reactNativeGoogleDriveApiWrapperJs.GDrive();
10
13
  constructor() {
@@ -14,7 +17,7 @@ class GoogleDriveApiClient {
14
17
  get(target, prop) {
15
18
  if (typeof target[prop] === 'function') {
16
19
  if (!GoogleDriveApiClient.drive.accessToken) {
17
- throw new Error(`Google Drive access token is not set, cannot call function ${prop.toString()}`);
20
+ throw new _NativeStorageError.default(`Google Drive access token is not set, cannot call function ${prop.toString()}`, _native.NativeStorageErrorCode.GOOGLE_DRIVE_ACCESS_TOKEN_MISSING);
18
21
  }
19
22
  }
20
23
  return target[prop];
@@ -64,16 +67,16 @@ class GoogleDriveApiClient {
64
67
  }
65
68
  }
66
69
  if (!topDirectoryId) {
67
- throw new Error(`Could not find top directory with name ${directoryTree[0]}`);
70
+ throw new _NativeStorageError.default(`Could not find top directory with name ${directoryTree[0]}`, _native.NativeStorageErrorCode.DIRECTORY_NOT_FOUND);
68
71
  }
69
72
 
70
73
  // now, we traverse the directories array and get the id of the last directory from the files array
71
74
  let currentDirectoryId = topDirectoryId;
72
75
  for (let i = 1; i < directoryTree.length; i++) {
73
76
  const currentDirectory = files.find(f => f.id === currentDirectoryId);
74
- if (!currentDirectory) throw new Error(`Could not find directory with id ${currentDirectoryId}`);
77
+ if (!currentDirectory) throw new _NativeStorageError.default(`Could not find directory with id ${currentDirectoryId}`, _native.NativeStorageErrorCode.DIRECTORY_NOT_FOUND);
75
78
  const nextDirectory = files.find(f => f.name === directoryTree[i] && f.parents[0] === currentDirectoryId);
76
- if (!nextDirectory) throw new Error(`Could not find directory with name ${directoryTree[i]}`);
79
+ if (!nextDirectory) throw new _NativeStorageError.default(`Could not find directory with name ${directoryTree[i]}`, _native.NativeStorageErrorCode.DIRECTORY_NOT_FOUND);
77
80
  currentDirectoryId = nextDirectory.id;
78
81
  }
79
82
  return currentDirectoryId;
@@ -100,7 +103,7 @@ class GoogleDriveApiClient {
100
103
  } else {
101
104
  file = files.find(f => f.name === filename && f.parents[0] === parentDirectoryId);
102
105
  }
103
- if (!file) throw new Error(`File not found`);
106
+ if (!file) throw new _NativeStorageError.default(`File not found`, _native.NativeStorageErrorCode.FILE_NOT_FOUND);
104
107
  return file.id;
105
108
  }
106
109
  async fileExists(path, scope) {
@@ -108,7 +111,7 @@ class GoogleDriveApiClient {
108
111
  await this.getFileId(path, scope);
109
112
  return true;
110
113
  } catch (e) {
111
- if (e.message === 'File not found') return false;else throw e;
114
+ if (e instanceof _NativeStorageError.default && e.code === _native.NativeStorageErrorCode.FILE_NOT_FOUND) return false;else throw e;
112
115
  }
113
116
  }
114
117
  async createFile(path, data, scope, overwrite) {
@@ -144,6 +147,19 @@ class GoogleDriveApiClient {
144
147
  const fileId = await this.getFileId(path, scope);
145
148
  await GoogleDriveApiClient.drive.files.delete(fileId);
146
149
  }
150
+ async statFile(path, scope) {
151
+ const fileId = await this.getFileId(path, scope);
152
+ const file = await GoogleDriveApiClient.drive.files.get(fileId, {
153
+ fields: 'id,kind,mimeType,name,parents,spaces,size,createdTime,modifiedTime'
154
+ });
155
+ return {
156
+ size: file.size ?? 0,
157
+ birthtimeMs: new Date(file.createdTime).getTime(),
158
+ mtimeMs: new Date(file.modifiedTime).getTime(),
159
+ isDirectory: file.mimeType === _reactNativeGoogleDriveApiWrapperJs.MimeTypes.FOLDER,
160
+ isFile: file.mimeType !== _reactNativeGoogleDriveApiWrapperJs.MimeTypes.FOLDER
161
+ };
162
+ }
147
163
  }
148
164
  var _default = GoogleDriveApiClient;
149
165
  exports.default = _default;
@@ -1 +1 @@
1
- {"version":3,"names":["_reactNativeGoogleDriveApiWrapperJs","require","GoogleDriveApiClient","drive","GDrive","constructor","fetchTimeout","Proxy","get","target","prop","accessToken","Error","toString","getRootDirectory","scope","resolvePathToDirectories","path","startsWith","slice","endsWith","directories","split","actualFilename","pop","filename","findParentDirectoryId","files","directoryTree","possibleTopDirectories","filter","f","mimeType","MimeTypes","FOLDER","name","topDirectoryId","length","id","possibleTopDirectory","find","parents","currentDirectoryId","i","currentDirectory","nextDirectory","listFiles","list","spaces","fields","getFileId","parentDirectoryId","file","f2","fileExists","e","message","createFile","data","overwrite","fileId","uploader","newMultipartUploader","setData","TEXT","setIdOfFileToUpdate","setRequestBody","undefined","execute","readFile","content","getText","deleteFile","delete","_default","exports","default"],"sourceRoot":"../../../src","sources":["google-drive/index.ts"],"mappings":";;;;;;AAAA,IAAAA,mCAAA,GAAAC,OAAA;AAKA,MAAMC,oBAAoB,CAAiC;EACzD,OAAeC,KAAK,GAAW,IAAIC,0CAAM,EAAE;EAE3CC,WAAWA,CAAA,EAAG;IACZH,oBAAoB,CAACC,KAAK,CAACG,YAAY,GAAG,IAAI;IAC9C,OAAO,IAAIC,KAAK,CAAC,IAAI,EAAE;MACrB;MACAC,GAAGA,CAACC,MAA4B,EAAEC,IAAgC,EAAE;QAClE,IAAI,OAAOD,MAAM,CAACC,IAAI,CAAC,KAAK,UAAU,EAAE;UACtC,IAAI,CAACR,oBAAoB,CAACC,KAAK,CAACQ,WAAW,EAAE;YAC3C,MAAM,IAAIC,KAAK,CAAE,8DAA6DF,IAAI,CAACG,QAAQ,EAAG,EAAC,CAAC;UAClG;QACF;QAEA,OAAOJ,MAAM,CAACC,IAAI,CAAC;MACrB;IACF,CAAC,CAAC;EACJ;;EAEA;EACA,WAAkBC,WAAWA,CAACA,WAAmB,EAAE;IACjDT,oBAAoB,CAACC,KAAK,CAACQ,WAAW,GAAGA,WAAW;EACtD;EAEA,WAAkBA,WAAWA,CAAA,EAAW;IACtC,OAAOT,oBAAoB,CAACC,KAAK,CAACQ,WAAW;EAC/C;EAEQG,gBAAgBA,CAACC,KAAgC,EAA6B;IACpF,QAAQA,KAAK;MACX,KAAK,WAAW;QACd,OAAO,OAAO;MAChB,KAAK,QAAQ;QACX,OAAO,eAAe;IAAC;EAE7B;EAEQC,wBAAwBA,CAACC,IAAY,EAA+C;IAC1F,IAAIA,IAAI,CAACC,UAAU,CAAC,GAAG,CAAC,EAAED,IAAI,GAAGA,IAAI,CAACE,KAAK,CAAC,CAAC,CAAC;IAC9C,IAAIF,IAAI,CAACG,QAAQ,CAAC,GAAG,CAAC,EAAEH,IAAI,GAAGA,IAAI,CAACE,KAAK,CAAC,CAAC,EAAE,CAAC,C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AEC,QAAQ,CAACI,mBAAmB,CAACL,MAAM,CAAC,CAAC,KAC5C;MACH,MAAMjC,KAAK,GAAG,MAAM,IAAI,CAACmB,SAAS,CAAC/B,KAAK,CAAC;MACzC,MAAM;QAAEM,WAAW;QAAEI;MAAS,CAAC,GAAG,IAAI,CAACT,wBAAwB,CAACC,IAAI,CAAC;MACrE,MAAMkC,iBAAiB,GAAG,IAAI,CAACzB,qBAAqB,CAACC,KAAK,EAAEN,WAAW,CAAC;MACxEwC,QAAQ,CAACK,cAAc,CAAC;QACtB/B,IAAI,EAAEV,QAAQ;QACdgB,OAAO,EAAEU,iBAAiB,GACtB,CAACA,iBAAiB,CAAC,GACnBpC,KAAK,KAAK,QAAQ,GAClB,CAAC,IAAI,CAACD,gBAAgB,CAACC,KAAK,CAAC,CAAC,GAC9BoD;MACN,CAAC,CAAC;IACJ;IACA,MAAMN,QAAQ,CAACO,OAAO,EAAE;EAC1B;EAEA,MAAMC,QAAQA,CAACpD,IAAY,EAAEF,KAAgC,EAAmB;IAC9E,MAAM6C,MAAM,GAAG,MAAM,IAAI,CAACV,SAAS,CAACjC,IAAI,EAAEF,KAAK,CAAC;IAChD,MAAMuD,OAAO,GAAG,MAAMpE,oBAAoB,CAACC,KAAK,CAACwB,KAAK,CAAC4C,OAAO,CAACX,MAAM,CAAC;IACtE,OAAOU,OAAO;EAChB;EAEA,MAAME,UAAUA,CAACvD,IAAY,EAAEF,KAAgC,EAAiB;IAC9E,MAAM6C,MAAM,GAAG,MAAM,IAAI,CAACV,SAAS,CAACjC,IAAI,EAAEF,KAAK,CAAC;IAChD,MAAMb,oBAAoB,CAACC,KAAK,CAACwB,KAAK,CAAC8C,MAAM,CAACb,MAAM,CAAC;EACvD;AACF;AAAC,IAAAc,QAAA,GAEcxE,oBAAoB;AAAAyE,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
1
+ {"version":3,"names":["_reactNativeGoogleDriveApiWrapperJs","require","_native","_NativeStorageError","_interopRequireDefault","obj","__esModule","default","GoogleDriveApiClient","drive","GDrive","constructor","fetchTimeout","Proxy","get","target","prop","accessToken","NativeStorageError","toString","NativeStorageErrorCode","GOOGLE_DRIVE_ACCESS_TOKEN_MISSING","getRootDirectory","scope","resolvePathToDirectories","path","startsWith","slice","endsWith","directories","split","actualFilename","pop","filename","findParentDirectoryId","files","directoryTree","possibleTopDirectories","filter","f","mimeType","MimeTypes","FOLDER","name","topDirectoryId","length","id","possibleTopDirectory","find","parents","DIRECTORY_NOT_FOUND","currentDirectoryId","i","currentDirectory","nextDirectory","listFiles","list","spaces","fields","getFileId","parentDirectoryId","file","f2","FILE_NOT_FOUND","fileExists","e","code","createFile","data","overwrite","fileId","uploader","newMultipartUploader","setData","TEXT","setIdOfFileToUpdate","setRequestBody","undefined","execute","readFile","content","getText","deleteFile","delete","statFile","size","birthtimeMs","Date","createdTime","getTime","mtimeMs","modifiedTime","isDirectory","isFile","_default","exports"],"sourceRoot":"../../../src","sources":["google-drive/index.ts"],"mappings":";;;;;;AAAA,IAAAA,mCAAA,GAAAC,OAAA;AAEA,IAAAC,OAAA,GAAAD,OAAA;AAMA,IAAAE,mBAAA,GAAAC,sBAAA,CAAAH,OAAA;AAA6D,SAAAG,uBAAAC,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAE7D,MAAMG,oBAAoB,CAAiC;EACzD,OAAeC,KAAK,GAAW,IAAIC,0CAAM,EAAE;EAE3CC,WAAWA,CAAA,EAAG;IACZH,oBAAoB,CAACC,KAAK,CAACG,YAAY,GAAG,IAAI;IAC9C,OAAO,IAAIC,KAAK,CAAC,IAAI,EAAE;MACrB;MACAC,GAAGA,CAACC,MAA4B,EAAEC,IAAgC,EAAE;QAClE,IAAI,OAAOD,MAAM,CAACC,IAAI,CAAC,KAAK,UAAU,EAAE;UACtC,IAAI,CAACR,oBAAoB,CAACC,KAAK,CAACQ,WAAW,EAAE;YAC3C,MAAM,IAAIC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,IAAIH,IAAI,CAAC1B,IAAI,CAAC8B,YAAY,CAAE,CAACF,OAAO,EAAE;MAC/CG,WAAW,EAAE/B,IAAI,CAACrB,QAAQ,KAAKC,6CAAS,CAACC,MAAM;MAC/CmD,MAAM,EAAEhC,IAAI,CAACrB,QAAQ,KAAKC,6CAAS,CAACC;IACtC,CAAC;EACH;AACF;AAAC,IAAAoD,QAAA,GAEctF,oBAAoB;AAAAuF,OAAA,CAAAxF,OAAA,GAAAuF,QAAA"}
@@ -3,9 +3,25 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- var _exportNames = {};
6
+ var _exportNames = {
7
+ NativeStorageErrorCode: true,
8
+ NativeStorageError: true
9
+ };
10
+ Object.defineProperty(exports, "NativeStorageError", {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _NativeStorageError.default;
14
+ }
15
+ });
16
+ Object.defineProperty(exports, "NativeStorageErrorCode", {
17
+ enumerable: true,
18
+ get: function () {
19
+ return _native.NativeStorageErrorCode;
20
+ }
21
+ });
7
22
  exports.default = void 0;
8
23
  var _RNCloudStorage = _interopRequireDefault(require("./RNCloudStorage"));
24
+ var _native = require("./types/native");
9
25
  var _main = require("./types/main");
10
26
  Object.keys(_main).forEach(function (key) {
11
27
  if (key === "default" || key === "__esModule") return;
@@ -30,6 +46,7 @@ Object.keys(_useCloudFile).forEach(function (key) {
30
46
  }
31
47
  });
32
48
  });
49
+ var _NativeStorageError = _interopRequireDefault(require("./utils/NativeStorageError"));
33
50
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
34
51
  var _default = _RNCloudStorage.default;
35
52
  exports.default = _default;
@@ -1 +1 @@
1
- {"version":3,"names":["_RNCloudStorage","_interopRequireDefault","require","_main","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_useCloudFile","obj","__esModule","default","_default","RNCloudStorage"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;AAAA,IAAAA,eAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAAAE,MAAA,CAAAC,IAAA,CAAAF,KAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,KAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,KAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AACA,IAAAS,aAAA,GAAAd,OAAA;AAAAE,MAAA,CAAAC,IAAA,CAAAW,aAAA,EAAAV,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAS,aAAA,CAAAT,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,aAAA,CAAAT,GAAA;IAAA;EAAA;AAAA;AAAqC,SAAAN,uBAAAgB,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,IAAAG,QAAA,GAEtBC,uBAAc;AAAAT,OAAA,CAAAO,OAAA,GAAAC,QAAA"}
1
+ {"version":3,"names":["_RNCloudStorage","_interopRequireDefault","require","_native","_main","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumer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AAAF,GAAA;AAAA,IAAAG,QAAA,GAI7CC,uBAAc;AAAAV,OAAA,CAAAQ,OAAA,GAAAC,QAAA"}
@@ -1,2 +1,20 @@
1
1
  "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.NativeStorageErrorCode = void 0;
7
+ let NativeStorageErrorCode = /*#__PURE__*/function (NativeStorageErrorCode) {
8
+ NativeStorageErrorCode["FILE_NOT_FOUND"] = "ERR_FILE_NOT_FOUND";
9
+ NativeStorageErrorCode["DIRECTORY_NOT_FOUND"] = "ERR_NO_DIRECTORY_FOUND";
10
+ NativeStorageErrorCode["FILE_ALREADY_EXISTS"] = "ERR_FILE_EXISTS";
11
+ NativeStorageErrorCode["WRITE_ERROR"] = "ERR_WRITE_ERROR";
12
+ NativeStorageErrorCode["READ_ERROR"] = "ERR_READ_ERROR";
13
+ NativeStorageErrorCode["DELETE_ERROR"] = "ERR_DELETE_ERROR";
14
+ NativeStorageErrorCode["STAT_ERROR"] = "ERR_STAT_ERROR";
15
+ NativeStorageErrorCode["UNKNOWN"] = "ERR_UNKNOWN";
16
+ NativeStorageErrorCode["GOOGLE_DRIVE_ACCESS_TOKEN_MISSING"] = "ERR_GOOGLE_DRIVE_ACCESS_TOKEN_MISSING";
17
+ return NativeStorageErrorCode;
18
+ }({});
19
+ exports.NativeStorageErrorCode = NativeStorageErrorCode;
2
20
  //# sourceMappingURL=native.js.map
@@ -1 +1 @@
1
- {"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/native.ts"],"mappings":""}
1
+ {"version":3,"names":["NativeStorageErrorCode","exports"],"sourceRoot":"../../../src","sources":["types/native.ts"],"mappings":";;;;;;IAUYA,sBAAsB,0BAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAA,OAAtBA,sBAAsB;AAAA;AAAAC,OAAA,CAAAD,sBAAA,GAAAA,sBAAA"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ class NativeStorageError extends Error {
8
+ constructor(message, code, details) {
9
+ super(message);
10
+ this.code = code;
11
+ this.details = details;
12
+ }
13
+ }
14
+ var _default = NativeStorageError;
15
+ exports.default = _default;
16
+ //# sourceMappingURL=NativeStorageError.js.map
@@ -0,0 +1 @@
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"}
@@ -39,6 +39,22 @@ const RNCloudStorage = {
39
39
  */
40
40
  unlink: (path, scope) => {
41
41
  return nativeInstance.deleteFile(path, scope);
42
+ },
43
+ /**
44
+ * Gets the size, creation time, and modification time of the file at the given path.
45
+ * @param path The file to stat.
46
+ * @param scope The directory scope the path is in.
47
+ * @returns A promise that resolves to the StorageFileStat object.
48
+ */
49
+ stat: async (path, scope) => {
50
+ const native = await nativeInstance.statFile(path, scope);
51
+ return {
52
+ ...native,
53
+ birthtime: new Date(native.birthtimeMs),
54
+ mtime: new Date(native.mtimeMs),
55
+ isDirectory: () => native.isDirectory,
56
+ isFile: () => native.isFile
57
+ };
42
58
  }
43
59
  };
44
60
  export default RNCloudStorage;
@@ -1 +1 @@
1
- {"version":3,"names":["createRNCloudStorage","GoogleDriveApiClient","nativeInstance","RNCloudStorage","setGoogleDriveAccessToken","accessToken","exists","path","scope","fileExists","writeFile","data","createFile","readFile","unlink","deleteFile"],"sourceRoot":"../../src","sources":["RNCloudStorage.ts"],"mappings":"AAAA,OAAOA,oBAAoB,MAAM,wBAAwB;AACzD,OAAOC,oBAAoB,MAAM,gBAAgB;AAGjD,MAAMC,cAAc,GAAGF,oBAAoB,EAAE;AAC7C,MAAMG,cAAc,GAAG;EACrBC,yBAAyB,EAAGC,WAAmB,IAAMJ,oBAAoB,CAACI,WAAW,GAAGA,WAAY;EACpG;AACF;AACA;AACA;AACA;AACA;EACEC,MAAM,EAAEA,CAACC,IAAY,EAAEC,KAAmB,KAAuB;IAC/D,OAAON,cAAc,CAACO,UAAU,CAACF,IAAI,EAAEC,KAAK,CAAC;EAC/C,CAAC;EAED;AACF;AACA;AACA;AACA;AACA;AACA;EACEE,SAAS,EAAEA,CAACH,IAAY,EAAEI,IAAY,EAAEH,KAAmB,KAAoB;IAC7E,OAAON,cAAc,CAACU,UAAU,CAACL,IAAI,EAAEI,IAAI,EAAEH,KAAK,EAAE,IAAI,CAAC;EAC3D,CAAC;EAED;AACF;AACA;AACA;AACA;AACA;EACEK,QAAQ,EAAEA,CAACN,IAAY,EAAEC,KAAmB,KAAsB;IAChE,OAAON,cAAc,CAACW,QAAQ,CAACN,IAAI,EAAEC,KAAK,CAAC;EAC7C,CAAC;EAED;AACF;AACA;AACA;AACA;AACA;EACEM,MAAM,EAAEA,CAACP,IAAY,EAAEC,KAAmB,KAAoB;IAC5D,OAAON,cAAc,CAACa,UAAU,CAACR,IAAI,EAAEC,KAAK,CAAC;EAC/C;AACF,CAAC;AAED,eAAeL,cAAc"}
1
+ {"version":3,"names":["createRNCloudStorage","GoogleDriveApiClient","nativeInstance","RNCloudStorage","setGoogleDriveAccessToken","accessToken","exists","path","scope","fileExists","writeFile","data","createFile","readFile","unlink","deleteFile","stat","native","statFile","birthtime","Date","birthtimeMs","mtime","mtimeMs","isDirectory","isFile"],"sourceRoot":"../../src","sources":["RNCloudStorage.ts"],"mappings":"AAAA,OAAOA,oBAAoB,MAAM,wBAAwB;AACzD,OAAOC,oBAAoB,MAAM,gBAAgB;AAGjD,MAAMC,cAAc,GAAGF,oBAAoB,EAAE;AAC7C,MAAMG,cAAc,GAAG;EACrBC,yBAAyB,EAAGC,WAAmB,IAAMJ,oBAAoB,CAACI,WAAW,GAAGA,WAAY;EACpG;AACF;AACA;AACA;AACA;AACA;EACEC,MAAM,EAAEA,CAACC,IAAY,EAAEC,KAAmB,KAAuB;IAC/D,OAAON,cAAc,CAACO,UAAU,CAACF,IAAI,EAAEC,KAAK,CAAC;EAC/C,CAAC;EAED;AACF;AACA;AACA;AACA;AACA;AACA;EACEE,SAAS,EAAEA,CAACH,IAAY,EAAEI,IAAY,EAAEH,KAAmB,KAAoB;IAC7E,OAAON,cAAc,CAACU,UAAU,CAACL,IAAI,EAAEI,IAAI,EAAEH,KAAK,EAAE,IAAI,CAAC;EAC3D,CAAC;EAED;AACF;AACA;AACA;AACA;AACA;EACEK,QAAQ,EAAEA,CAACN,IAAY,EAAEC,KAAmB,KAAsB;IAChE,OAAON,cAAc,CAACW,QAAQ,CAACN,IAAI,EAAEC,KAAK,CAAC;EAC7C,CAAC;EAED;AACF;AACA;AACA;AACA;AACA;EACEM,MAAM,EAAEA,CAACP,IAAY,EAAEC,KAAmB,KAAoB;IAC5D,OAAON,cAAc,CAACa,UAAU,CAACR,IAAI,EAAEC,KAAK,CAAC;EAC/C,CAAC;EAED;AACF;AACA;AACA;AACA;AACA;EACEQ,IAAI,EAAE,MAAAA,CAAOT,IAAY,EAAEC,KAAmB,KAA+B;IAC3E,MAAMS,MAAM,GAAG,MAAMf,cAAc,CAACgB,QAAQ,CAACX,IAAI,EAAEC,KAAK,CAAC;IAEzD,OAAO;MACL,GAAGS,MAAM;MACTE,SAAS,EAAE,IAAIC,IAAI,CAACH,MAAM,CAACI,WAAW,CAAC;MACvCC,KAAK,EAAE,IAAIF,IAAI,CAACH,MAAM,CAACM,OAAO,CAAC;MAC/BC,WAAW,EAAEA,CAAA,KAAMP,MAAM,CAACO,WAAW;MACrCC,MAAM,EAAEA,CAAA,KAAMR,MAAM,CAACQ;IACvB,CAAC;EACH;AACF,CAAC;AAED,eAAetB,cAAc"}
@@ -1,20 +1,41 @@
1
1
  import { NativeModules, Platform } from 'react-native';
2
2
  import GoogleDriveApiClient from './google-drive';
3
+ import { NativeStorageErrorCode } from './types/native';
4
+ import NativeStorageError from './utils/NativeStorageError';
3
5
  const LINKING_ERROR = `The package 'react-native-cloud-storage' doesn't seem to be linked. Make sure: \n\n` + Platform.select({
4
6
  ios: "- You have run 'pod install'\n",
5
7
  default: ''
6
8
  }) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
9
+
10
+ // proxy NativeModules.CloudStorage to catch any errors thrown by the native module and wrap them in a NativeStorageError
11
+ const nativeIosInstance = NativeModules.CloudStorage ? new Proxy(NativeModules.CloudStorage, {
12
+ get(target, prop) {
13
+ const originalFunction = target[prop];
14
+ if (typeof originalFunction === 'function') {
15
+ return async function () {
16
+ try {
17
+ // @ts-expect-error - we can't know the types of the functions and their arguments
18
+ return await originalFunction(...arguments);
19
+ } catch (error) {
20
+ if (error !== null && error !== void 0 && error.code && Object.values(NativeStorageErrorCode).includes(error.code)) {
21
+ throw new NativeStorageError((error === null || error === void 0 ? void 0 : error.message) || '', error.code);
22
+ } else {
23
+ throw new NativeStorageError('Unknown error', NativeStorageErrorCode.UNKNOWN, error);
24
+ }
25
+ }
26
+ };
27
+ }
28
+ return originalFunction;
29
+ }
30
+ }) : null;
7
31
  export default function createRNCloudStorage() {
8
32
  if (Platform.OS === 'ios') {
9
- return NativeModules.CloudStorage ?? new Proxy({}, {
33
+ return nativeIosInstance ?? new Proxy({}, {
10
34
  get() {
11
35
  throw new Error(LINKING_ERROR);
12
36
  }
13
37
  });
14
38
  }
15
- if (Platform.OS === 'android') {
16
- return new GoogleDriveApiClient();
17
- }
18
- throw new Error('Unsupported platform');
39
+ return new GoogleDriveApiClient();
19
40
  }
20
41
  //# sourceMappingURL=createRNCloudStorage.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["NativeModules","Platform","GoogleDriveApiClient","LINKING_ERROR","select","ios","default","createRNCloudStorage","OS","CloudStorage","Proxy","get","Error"],"sourceRoot":"../../src","sources":["createRNCloudStorage.ts"],"mappings":"AAAA,SAASA,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AAEtD,OAAOC,oBAAoB,MAAM,gBAAgB;AAEjD,MAAMC,aAAa,GAChB,qFAAoF,GACrFF,QAAQ,CAACG,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;AAEjC,eAAe,SAASC,oBAAoBA,CAAA,EAAyB;EACnE,IAAIN,QAAQ,CAACO,EAAE,KAAK,KAAK,EAAE;IACzB,OACGR,aAAa,CAACS,YAAY,IAC3B,IAAIC,KAAK,CACP,CAAC,CAAC,EACF;MACEC,GAAGA,CAAA,EAAG;QACJ,MAAM,IAAIC,KAAK,CAACT,aAAa,CAAC;MAChC;IACF,CAAC,CACF;EAEL;EAEA,IAAIF,QAAQ,CAACO,EAAE,KAAK,SAAS,EAAE;IAC7B,OAAO,IAAIN,oBAAoB,EAAE;EACnC;EAEA,MAAM,IAAIU,KAAK,CAAC,sBAAsB,CAAC;AACzC"}
1
+ {"version":3,"names":["NativeModules","Platform","GoogleDriveApiClient","NativeStorageErrorCode","NativeStorageError","LINKING_ERROR","select","ios","default","nativeIosInstance","CloudStorage","Proxy","get","target","prop","originalFunction","arguments","error","code","Object","values","includes","message","UNKNOWN","createRNCloudStorage","OS","Error"],"sourceRoot":"../../src","sources":["createRNCloudStorage.ts"],"mappings":"AAAA,SAASA,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AAEtD,OAAOC,oBAAoB,MAAM,gBAAgB;AACjD,SAASC,sBAAsB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CAAA,EAAG;QACJ,MAAM,IAAIc,KAAK,CAACrB,aAAa,CAAC;MAChC;IACF,CAAC,CACF;EAEL;EAEA,OAAO,IAAIH,oBAAoB,EAAE;AACnC"}
@@ -1,4 +1,6 @@
1
1
  import { GDrive, MimeTypes } from 'react-native-google-drive-api-wrapper-js';
2
+ import { NativeStorageErrorCode } from '../types/native';
3
+ import NativeStorageError from '../utils/NativeStorageError';
2
4
  class GoogleDriveApiClient {
3
5
  static drive = new GDrive();
4
6
  constructor() {
@@ -8,7 +10,7 @@ class GoogleDriveApiClient {
8
10
  get(target, prop) {
9
11
  if (typeof target[prop] === 'function') {
10
12
  if (!GoogleDriveApiClient.drive.accessToken) {
11
- throw new Error(`Google Drive access token is not set, cannot call function ${prop.toString()}`);
13
+ throw new NativeStorageError(`Google Drive access token is not set, cannot call function ${prop.toString()}`, NativeStorageErrorCode.GOOGLE_DRIVE_ACCESS_TOKEN_MISSING);
12
14
  }
13
15
  }
14
16
  return target[prop];
@@ -58,16 +60,16 @@ class GoogleDriveApiClient {
58
60
  }
59
61
  }
60
62
  if (!topDirectoryId) {
61
- throw new Error(`Could not find top directory with name ${directoryTree[0]}`);
63
+ throw new NativeStorageError(`Could not find top directory with name ${directoryTree[0]}`, NativeStorageErrorCode.DIRECTORY_NOT_FOUND);
62
64
  }
63
65
 
64
66
  // now, we traverse the directories array and get the id of the last directory from the files array
65
67
  let currentDirectoryId = topDirectoryId;
66
68
  for (let i = 1; i < directoryTree.length; i++) {
67
69
  const currentDirectory = files.find(f => f.id === currentDirectoryId);
68
- if (!currentDirectory) throw new Error(`Could not find directory with id ${currentDirectoryId}`);
70
+ if (!currentDirectory) throw new NativeStorageError(`Could not find directory with id ${currentDirectoryId}`, NativeStorageErrorCode.DIRECTORY_NOT_FOUND);
69
71
  const nextDirectory = files.find(f => f.name === directoryTree[i] && f.parents[0] === currentDirectoryId);
70
- if (!nextDirectory) throw new Error(`Could not find directory with name ${directoryTree[i]}`);
72
+ if (!nextDirectory) throw new NativeStorageError(`Could not find directory with name ${directoryTree[i]}`, NativeStorageErrorCode.DIRECTORY_NOT_FOUND);
71
73
  currentDirectoryId = nextDirectory.id;
72
74
  }
73
75
  return currentDirectoryId;
@@ -94,7 +96,7 @@ class GoogleDriveApiClient {
94
96
  } else {
95
97
  file = files.find(f => f.name === filename && f.parents[0] === parentDirectoryId);
96
98
  }
97
- if (!file) throw new Error(`File not found`);
99
+ if (!file) throw new NativeStorageError(`File not found`, NativeStorageErrorCode.FILE_NOT_FOUND);
98
100
  return file.id;
99
101
  }
100
102
  async fileExists(path, scope) {
@@ -102,7 +104,7 @@ class GoogleDriveApiClient {
102
104
  await this.getFileId(path, scope);
103
105
  return true;
104
106
  } catch (e) {
105
- if (e.message === 'File not found') return false;else throw e;
107
+ if (e instanceof NativeStorageError && e.code === NativeStorageErrorCode.FILE_NOT_FOUND) return false;else throw e;
106
108
  }
107
109
  }
108
110
  async createFile(path, data, scope, overwrite) {
@@ -138,6 +140,19 @@ class GoogleDriveApiClient {
138
140
  const fileId = await this.getFileId(path, scope);
139
141
  await GoogleDriveApiClient.drive.files.delete(fileId);
140
142
  }
143
+ async statFile(path, scope) {
144
+ const fileId = await this.getFileId(path, scope);
145
+ const file = await GoogleDriveApiClient.drive.files.get(fileId, {
146
+ fields: 'id,kind,mimeType,name,parents,spaces,size,createdTime,modifiedTime'
147
+ });
148
+ return {
149
+ size: file.size ?? 0,
150
+ birthtimeMs: new Date(file.createdTime).getTime(),
151
+ mtimeMs: new Date(file.modifiedTime).getTime(),
152
+ isDirectory: file.mimeType === MimeTypes.FOLDER,
153
+ isFile: file.mimeType !== MimeTypes.FOLDER
154
+ };
155
+ }
141
156
  }
142
157
  export default GoogleDriveApiClient;
143
158
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["GDrive","MimeTypes","GoogleDriveApiClient","drive","constructor","fetchTimeout","Proxy","get","target","prop","accessToken","Error","toString","getRootDirectory","scope","resolvePathToDirectories","path","startsWith","slice","endsWith","directories","split","actualFilename","pop","filename","findParentDirectoryId","files","directoryTree","possibleTopDirectories","filter","f","mimeType","FOLDER","name","topDirectoryId","length","id","possibleTopDirectory","find","parents","currentDirectoryId","i","currentDirectory","nextDirectory","listFiles","list","spaces","fields","getFileId","parentDirectoryId","file","f2","fileExists","e","message","createFile","data","overwrite","fileId","uploader","newMultipartUploader","setData","TEXT","setIdOfFileToUpdate","setRequestBody","undefined","execute","readFile","content","getText","deleteFile","delete"],"sourceRoot":"../../../src","sources":["google-drive/index.ts"],"mappings":"AAAA,SAASA,MAAM,EAAEC,SAAS,QAAQ,0CAA0C;AAK5E,MAAMC,oBAAoB,CAAiC;EACzD,OAAeC,KAAK,GAAW,IAAIH,MAAM,EAAE;EAE3CI,WAAWA,CAAA,EAAG;IACZF,oBAAoB,CAACC,KAAK,CAACE,YAAY,GAAG,IAAI;IAC9C,OAAO,IAAIC,KAAK,CAAC,IAAI,EAAE;MACrB;MACAC,GAAGA,CAACC,MAA4B,EAAEC,IAAgC,EAAE;QAClE,IAAI,OAAOD,MAAM,CAACC,IAAI,CAAC,KAAK,UAAU,EAAE;UACtC,IAAI,CAACP,oBAAoB,CAACC,KAAK,CAACO,WAAW,EAAE;YAC3C,MAAM,IAAIC,KAAK,CAAE,8DAA6DF,IAAI,CAACG,QAAQ,EAAG,EAAC,CAAC;UAClG;QACF;QAEA,OAAOJ,MAAM,CAACC,IAAI,CAAC;MACrB;IACF,CAAC,CAAC;EACJ;;EAEA;EACA,WAAkBC,WAAWA,CAACA,WAAmB,EAAE;IACjDR,oBAAoB,CAACC,KAAK,CAACO,WAAW,GAAGA,WAAW;EACtD;EAEA,WAAkBA,WAAWA,CAAA,EAAW;IACtC,OAAOR,oBAAoB,CAACC,KAAK,CAACO,WAAW;EAC/C;EAEQG,gBAAgBA,CAACC,KAAgC,EAA6B;IACpF,QAAQA,KAAK;MACX,KAAK,WAAW;QACd,OAAO,OAAO;MAChB,KAAK,QAAQ;QACX,OAAO,eAAe;I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AAEF,KAAK,CAAC;IAChD,MAAMZ,oBAAoB,CAACC,KAAK,CAACuB,KAAK,CAAC6C,MAAM,CAACb,MAAM,CAAC;EACvD;AACF;AAEA,eAAexD,oBAAoB"}
1
+ {"version":3,"names":["GDrive","MimeTypes","NativeStorageErrorCode","NativeStorageError","GoogleDriveApiClient","drive","constructor","fetchTimeout","Proxy","get","target","prop","accessToken","toString","GOOGLE_DRIVE_ACCESS_TOKEN_MISSING","getRootDirectory","scope","resolvePathToDirectories","path","startsWith","slice","endsWith","directories","split","actualFilename","pop","filename","findParentDirectoryId","files","directoryTree","possibleTopDirectories","filter","f","mimeType","FOLDER","name","topDirectoryId","length","id","possibleTopDirectory","find","parents","DIRECTORY_NOT_FOUND","currentDirectoryId","i","currentDirectory","nextDirectory","listFiles","list","spaces","fields","getFileId","parentDirectoryId","file","f2","FILE_NOT_FOUND","fileExists","e","code","createFile","data","overwrite","fileId","uploader","newMultipartUploader","setData","TEXT","setIdOfFileToUpdate","setRequestBody","undefined","execute","readFile","content","getText","deleteFile","delete","statFile","size","birthtimeMs","Date","createdTime","getTime","mtimeMs","modifiedTime","isDirectory","isFile"],"sourceRoot":"../../../src","sources":["google-drive/index.ts"],"mappings":"AAAA,SAASA,MAAM,EAAEC,SAAS,QAAQ,0CAA0C;AAE5E,SACEC,sBAAsB,QAGjB,iBAAiB;AAExB,OAAOC,kBAAkB,MAAM,6BAA6B;AAE5D,MAAMC,oBAAoB,CAAiC;EACzD,OAAeC,KAAK,GAAW,IAAIL,MAAM,EAAE;EAE3CM,WAAWA,CAAA,EAAG;IACZF,oBAAoB,CAACC,KAAK,CAACE,YAAY,GAAG,IAAI;IAC9C,OAAO,IAAIC,KAAK,CAAC,IAAI,EAAE;MACrB;MACAC,GAAGA,CAACC,MAA4B,EAAEC,IAAgC,EAAE;QAClE,IAAI,OAAOD,MAAM,CAACC,IAAI,CAAC,KAAK,UAAU,EAAE;UACtC,IAAI,CAACP,oBAAoB,CAACC,KAAK,CAACO,WAA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C,OAAO,EAAE,IAAIH,IAAI,CAAC1B,IAAI,CAAC8B,YAAY,CAAE,CAACF,OAAO,EAAE;MAC/CG,WAAW,EAAE/B,IAAI,CAACpB,QAAQ,KAAKhC,SAAS,CAACiC,MAAM;MAC/CmD,MAAM,EAAEhC,IAAI,CAACpB,QAAQ,KAAKhC,SAAS,CAACiC;IACtC,CAAC;EACH;AACF;AAEA,eAAe9B,oBAAoB"}
@@ -1,5 +1,9 @@
1
1
  import RNCloudStorage from './RNCloudStorage';
2
+ import { NativeStorageErrorCode } from './types/native';
2
3
  export * from './types/main';
3
4
  export * from './hooks/useCloudFile';
5
+ import NativeStorageError from './utils/NativeStorageError';
6
+ export { NativeStorageError };
7
+ export { NativeStorageErrorCode };
4
8
  export default RNCloudStorage;
5
9
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["RNCloudStorage"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"AAAA,OAAOA,cAAc,MAAM,kBAAkB;AAC7C,cAAc,cAAc;AAC5B,cAAc,sBAAsB;AAEpC,eAAeA,cAAc"}
1
+ {"version":3,"names":["RNCloudStorage","NativeStorageErrorCode","NativeStorageError"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"AAAA,OAAOA,cAAc,MAAM,kBAAkB;AAC7C,SAASC,sBAAsB,QAAQ,gBAAgB;AACvD,cAAc,cAAc;AAC5B,cAAc,sBAAsB;AACpC,OAAOC,kBAAkB,MAAM,4BAA4B;AAE3D,SAASA,kBAAkB;AAC3B,SAASD,sBAAsB;AAC/B,eAAeD,cAAc"}
@@ -1,2 +1,13 @@
1
-
1
+ export let NativeStorageErrorCode = /*#__PURE__*/function (NativeStorageErrorCode) {
2
+ NativeStorageErrorCode["FILE_NOT_FOUND"] = "ERR_FILE_NOT_FOUND";
3
+ NativeStorageErrorCode["DIRECTORY_NOT_FOUND"] = "ERR_NO_DIRECTORY_FOUND";
4
+ NativeStorageErrorCode["FILE_ALREADY_EXISTS"] = "ERR_FILE_EXISTS";
5
+ NativeStorageErrorCode["WRITE_ERROR"] = "ERR_WRITE_ERROR";
6
+ NativeStorageErrorCode["READ_ERROR"] = "ERR_READ_ERROR";
7
+ NativeStorageErrorCode["DELETE_ERROR"] = "ERR_DELETE_ERROR";
8
+ NativeStorageErrorCode["STAT_ERROR"] = "ERR_STAT_ERROR";
9
+ NativeStorageErrorCode["UNKNOWN"] = "ERR_UNKNOWN";
10
+ NativeStorageErrorCode["GOOGLE_DRIVE_ACCESS_TOKEN_MISSING"] = "ERR_GOOGLE_DRIVE_ACCESS_TOKEN_MISSING";
11
+ return NativeStorageErrorCode;
12
+ }({});
2
13
  //# sourceMappingURL=native.js.map
@@ -1 +1 @@
1
- {"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/native.ts"],"mappings":""}
1
+ {"version":3,"names":["NativeStorageErrorCode"],"sourceRoot":"../../../src","sources":["types/native.ts"],"mappings":"AAUA,WAAYA,sBAAsB,0BAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAA,OAAtBA,sBAAsB;AAAA"}
@@ -0,0 +1,9 @@
1
+ class NativeStorageError extends Error {
2
+ constructor(message, code, details) {
3
+ super(message);
4
+ this.code = code;
5
+ this.details = details;
6
+ }
7
+ }
8
+ export default NativeStorageError;
9
+ //# sourceMappingURL=NativeStorageError.js.map
@@ -0,0 +1 @@
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,4 +1,4 @@
1
- import type { StorageScope } from './types/main';
1
+ import type { StorageFileStat, StorageScope } from './types/main';
2
2
  declare const RNCloudStorage: {
3
3
  setGoogleDriveAccessToken: (accessToken: string) => string;
4
4
  /**
@@ -30,6 +30,13 @@ declare const RNCloudStorage: {
30
30
  * @returns A promise that resolves when the file has been deleted.
31
31
  */
32
32
  unlink: (path: string, scope: StorageScope) => Promise<void>;
33
+ /**
34
+ * Gets the size, creation time, and modification time of the file at the given path.
35
+ * @param path The file to stat.
36
+ * @param scope The directory scope the path is in.
37
+ * @returns A promise that resolves to the StorageFileStat object.
38
+ */
39
+ stat: (path: string, scope: StorageScope) => Promise<StorageFileStat>;
33
40
  };
34
41
  export default RNCloudStorage;
35
42
  //# 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,YAAY,EAAE,MAAM,cAAc,CAAC;AAGjD,QAAA,MAAM,cAAc;6CACuB,MAAM;IAC/C;;;;;OAKG;mBACY,MAAM,SAAS,YAAY,KAAG,QAAQ,OAAO,CAAC;IAI7D;;;;;;OAMG;sBACe,MAAM,QAAQ,MAAM,SAAS,YAAY,KAAG,QAAQ,IAAI,CAAC;IAI3E;;;;;OAKG;qBACc,MAAM,SAAS,YAAY,KAAG,QAAQ,MAAM,CAAC;IAI9D;;;;;OAKG;mBACY,MAAM,SAAS,YAAY,KAAG,QAAQ,IAAI,CAAC;CAG3D,CAAC;AAEF,eAAe,cAAc,CAAC"}
1
+ {"version":3,"file":"RNCloudStorage.d.ts","sourceRoot":"","sources":["../../src/RNCloudStorage.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAGlE,QAAA,MAAM,cAAc;6CACuB,MAAM;IAC/C;;;;;OAKG;mBACY,MAAM,SAAS,YAAY,KAAG,QAAQ,OAAO,CAAC;IAI7D;;;;;;OAMG;sBACe,MAAM,QAAQ,MAAM,SAAS,YAAY,KAAG,QAAQ,IAAI,CAAC;IAI3E;;;;;OAKG;qBACc,MAAM,SAAS,YAAY,KAAG,QAAQ,MAAM,CAAC;IAI9D;;;;;OAKG;mBACY,MAAM,SAAS,YAAY,KAAG,QAAQ,IAAI,CAAC;IAI1D;;;;;OAKG;iBACgB,MAAM,SAAS,YAAY,KAAG,QAAQ,eAAe,CAAC;CAW1E,CAAC;AAEF,eAAe,cAAc,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"createRNCloudStorage.d.ts","sourceRoot":"","sources":["../../src/createRNCloudStorage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,oBAAoB,MAAM,gBAAgB,CAAC;AASvD,MAAM,CAAC,OAAO,UAAU,oBAAoB,IAAI,oBAAoB,CAoBnE"}
1
+ {"version":3,"file":"createRNCloudStorage.d.ts","sourceRoot":"","sources":["../../src/createRNCloudStorage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,oBAAoB,MAAM,gBAAgB,CAAC;AAmCvD,MAAM,CAAC,OAAO,UAAU,oBAAoB,IAAI,oBAAoB,CAgBnE"}
@@ -1,5 +1,5 @@
1
1
  import type NativeRNCloudStorage from '../types/native';
2
- import type { NativeRNCloudStorageScope } from '../types/native';
2
+ import { type NativeRNCloudStorageFileStat, type NativeRNCloudStorageScope } from '../types/native';
3
3
  declare class GoogleDriveApiClient implements NativeRNCloudStorage {
4
4
  private static drive;
5
5
  constructor();
@@ -14,6 +14,7 @@ declare class GoogleDriveApiClient implements NativeRNCloudStorage {
14
14
  createFile(path: string, data: string, scope: NativeRNCloudStorageScope, overwrite: boolean): Promise<void>;
15
15
  readFile(path: string, scope: NativeRNCloudStorageScope): Promise<string>;
16
16
  deleteFile(path: string, scope: NativeRNCloudStorageScope): Promise<void>;
17
+ statFile(path: string, scope: NativeRNCloudStorageScope): Promise<NativeRNCloudStorageFileStat>;
17
18
  }
18
19
  export default GoogleDriveApiClient;
19
20
  //# 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,KAAK,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAGjE,cAAM,oBAAqB,YAAW,oBAAoB;IACxD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAwB;;IAmB5C,WAAkB,WAAW,CAAC,WAAW,EAAE,MAAM,EAEhD;IAED,WAAkB,WAAW,IAAI,MAAM,CAEtC;IAED,OAAO,CAAC,gBAAgB;IASxB,OAAO,CAAC,wBAAwB;IAQhC,OAAO,CAAC,qBAAqB;YAsCf,SAAS;YAST,SAAS;IAgBjB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,yBAAyB,GAAG,OAAO,CAAC,OAAO,CAAC;IAU5E,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,yBAAyB,EAAE,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IA2B3G,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,yBAAyB,GAAG,OAAO,CAAC,MAAM,CAAC;IAMzE,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,yBAAyB,GAAG,OAAO,CAAC,IAAI,CAAC;CAIhF;AAED,eAAe,oBAAoB,CAAC"}
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,4BAA4B,EACjC,KAAK,yBAAyB,EAC/B,MAAM,iBAAiB,CAAC;AAIzB,cAAM,oBAAqB,YAAW,oBAAoB;IACxD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAwB;;IAsB5C,WAAkB,WAAW,CAAC,WAAW,EAAE,MAAM,EAEhD;IAED,WAAkB,WAAW,IAAI,MAAM,CAEtC;IAED,OAAO,CAAC,gBAAgB;IASxB,OAAO,CAAC,wBAAwB;IAQhC,OAAO,CAAC,qBAAqB;YAiDf,SAAS;YAST,SAAS;IAgBjB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,yBAAyB,GAAG,OAAO,CAAC,OAAO,CAAC;IAU5E,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,yBAAyB,EAAE,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IA2B3G,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,yBAAyB,GAAG,OAAO,CAAC,MAAM,CAAC;IAMzE,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,yBAAyB,GAAG,OAAO,CAAC,IAAI,CAAC;IAKzE,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,yBAAyB,GAAG,OAAO,CAAC,4BAA4B,CAAC;CAatG;AAED,eAAe,oBAAoB,CAAC"}
@@ -6,6 +6,11 @@ export interface GoogleDriveFile {
6
6
  parents: string[];
7
7
  spaces: ('appDataFolder' | 'drive')[];
8
8
  }
9
+ export interface GoogleDriveDetailedFile extends GoogleDriveFile {
10
+ createdTime: string;
11
+ modifiedTime: string;
12
+ size?: number;
13
+ }
9
14
  export interface GoogleDriveListOperationQueryParameters {
10
15
  corpora?: 'user' | 'drive' | 'domain' | 'allDrives';
11
16
  driveId?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/google-drive/types.ts"],"names":[],"mappings":"AAAA,MA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StorageErrorCode } from './types/native';
2
3
  export * from './types/main';
3
4
  export * from './hooks/useCloudFile';
5
+ import NativeStorageError from './utils/NativeStorageError';
6
+ export { NativeStorageError };
7
+ export { NativeStorageErrorCode };
4
8
  export default RNCloudStorage;
5
9
  //# 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,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AAErC,eAAe,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,OAAO,kBAAkB,MAAM,4BAA4B,CAAC;AAE5D,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAC9B,OAAO,EAAE,sBAAsB,EAAE,CAAC;AAClC,eAAe,cAAc,CAAC"}
@@ -2,4 +2,13 @@ export declare enum StorageScope {
2
2
  Documents = "documents",
3
3
  Hidden = "hidden"
4
4
  }
5
+ export interface StorageFileStat {
6
+ size: number;
7
+ birthtimeMs: number;
8
+ mtimeMs: number;
9
+ birthtime: Date;
10
+ mtime: Date;
11
+ isDirectory: () => boolean;
12
+ isFile: () => boolean;
13
+ }
5
14
  //# sourceMappingURL=main.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../../src/types/main.ts"],"names":[],"mappings":"AAAA,oBAAY,YAAY;IACtB,SAAS,cAAc;IACvB,MAAM,WAAW;CAClB"}
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../../src/types/main.ts"],"names":[],"mappings":"AAAA,oBAAY,YAAY;IACtB,SAAS,cAAc;IACvB,MAAM,WAAW;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B,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,8 +1,27 @@
1
1
  export type NativeRNCloudStorageScope = 'documents' | 'hidden';
2
+ export interface NativeRNCloudStorageFileStat {
3
+ size: number;
4
+ birthtimeMs: number;
5
+ mtimeMs: number;
6
+ isDirectory: boolean;
7
+ isFile: boolean;
8
+ }
9
+ export declare enum NativeStorageErrorCode {
10
+ FILE_NOT_FOUND = "ERR_FILE_NOT_FOUND",
11
+ DIRECTORY_NOT_FOUND = "ERR_NO_DIRECTORY_FOUND",
12
+ FILE_ALREADY_EXISTS = "ERR_FILE_EXISTS",
13
+ WRITE_ERROR = "ERR_WRITE_ERROR",
14
+ READ_ERROR = "ERR_READ_ERROR",
15
+ DELETE_ERROR = "ERR_DELETE_ERROR",
16
+ STAT_ERROR = "ERR_STAT_ERROR",
17
+ UNKNOWN = "ERR_UNKNOWN",
18
+ GOOGLE_DRIVE_ACCESS_TOKEN_MISSING = "ERR_GOOGLE_DRIVE_ACCESS_TOKEN_MISSING"
19
+ }
2
20
  export default interface NativeRNCloudStorage {
3
21
  fileExists: (path: string, scope: NativeRNCloudStorageScope) => Promise<boolean>;
4
22
  createFile: (path: string, data: string, scope: NativeRNCloudStorageScope, overwrite: boolean) => Promise<void>;
5
23
  readFile: (path: string, scope: NativeRNCloudStorageScope) => Promise<string>;
6
24
  deleteFile: (path: string, scope: NativeRNCloudStorageScope) => Promise<void>;
25
+ statFile: (path: string, scope: NativeRNCloudStorageScope) => Promise<NativeRNCloudStorageFileStat>;
7
26
  }
8
27
  //# 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,yBAAyB,GAAG,WAAW,GAAG,QAAQ,CAAC;AAE/D,MAAM,CAAC,OAAO,WAAW,oBAAoB;IAC3C,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,yBAAyB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACjF,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,yBAAyB,EAAE,SAAS,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAChH,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,yBAAyB,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAC9E,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,yBAAyB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/E"}
1
+ {"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../../../src/types/native.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,yBAAyB,GAAG,WAAW,GAAG,QAAQ,CAAC;AAE/D,MAAM,WAAW,4BAA4B;IAC3C,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,sBAAsB;IAChC,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,yBAAyB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACjF,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,yBAAyB,EAAE,SAAS,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAChH,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,yBAAyB,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAC9E,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,yBAAyB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9E,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,yBAAyB,KAAK,OAAO,CAAC,4BAA4B,CAAC,CAAC;CACrG"}
@@ -0,0 +1,8 @@
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
@@ -0,0 +1 @@
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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-cloud-storage",
3
- "version": "0.1.2",
3
+ "version": "0.3.1",
4
4
  "description": "test",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -1,6 +1,6 @@
1
1
  import createRNCloudStorage from './createRNCloudStorage';
2
2
  import GoogleDriveApiClient from './google-drive';
3
- import type { StorageScope } from './types/main';
3
+ import type { StorageFileStat, StorageScope } from './types/main';
4
4
 
5
5
  const nativeInstance = createRNCloudStorage();
6
6
  const RNCloudStorage = {
@@ -45,6 +45,24 @@ const RNCloudStorage = {
45
45
  unlink: (path: string, scope: StorageScope): Promise<void> => {
46
46
  return nativeInstance.deleteFile(path, scope);
47
47
  },
48
+
49
+ /**
50
+ * Gets the size, creation time, and modification time of the file at the given path.
51
+ * @param path The file to stat.
52
+ * @param scope The directory scope the path is in.
53
+ * @returns A promise that resolves to the StorageFileStat object.
54
+ */
55
+ stat: async (path: string, scope: StorageScope): Promise<StorageFileStat> => {
56
+ const native = await nativeInstance.statFile(path, scope);
57
+
58
+ return {
59
+ ...native,
60
+ birthtime: new Date(native.birthtimeMs),
61
+ mtime: new Date(native.mtimeMs),
62
+ isDirectory: () => native.isDirectory,
63
+ isFile: () => native.isFile,
64
+ };
65
+ },
48
66
  };
49
67
 
50
68
  export default RNCloudStorage;
@@ -1,6 +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 { NativeStorageErrorCode } from './types/native';
5
+ import NativeStorageError from './utils/NativeStorageError';
4
6
 
5
7
  const LINKING_ERROR =
6
8
  `The package 'react-native-cloud-storage' doesn't seem to be linked. Make sure: \n\n` +
@@ -8,10 +10,34 @@ const LINKING_ERROR =
8
10
  '- You rebuilt the app after installing the package\n' +
9
11
  '- You are not using Expo Go\n';
10
12
 
13
+ // proxy NativeModules.CloudStorage to catch any errors thrown by the native module and wrap them in a NativeStorageError
14
+ const nativeIosInstance = NativeModules.CloudStorage
15
+ ? new Proxy(NativeModules.CloudStorage, {
16
+ get(target: NativeRNCloudStorage, prop: keyof NativeRNCloudStorage) {
17
+ const originalFunction = target[prop];
18
+ if (typeof originalFunction === 'function') {
19
+ return async (...args: any[]) => {
20
+ try {
21
+ // @ts-expect-error - we can't know the types of the functions and their arguments
22
+ return await originalFunction(...args);
23
+ } catch (error: any) {
24
+ if (error?.code && Object.values(NativeStorageErrorCode).includes(error.code)) {
25
+ throw new NativeStorageError(error?.message || '', error.code as NativeStorageErrorCode);
26
+ } else {
27
+ throw new NativeStorageError('Unknown error', NativeStorageErrorCode.UNKNOWN, error);
28
+ }
29
+ }
30
+ };
31
+ }
32
+ return originalFunction;
33
+ },
34
+ })
35
+ : null;
36
+
11
37
  export default function createRNCloudStorage(): NativeRNCloudStorage {
12
38
  if (Platform.OS === 'ios') {
13
39
  return (
14
- (NativeModules.CloudStorage as NativeRNCloudStorage) ??
40
+ nativeIosInstance ??
15
41
  new Proxy(
16
42
  {},
17
43
  {
@@ -23,9 +49,5 @@ export default function createRNCloudStorage(): NativeRNCloudStorage {
23
49
  );
24
50
  }
25
51
 
26
- if (Platform.OS === 'android') {
27
- return new GoogleDriveApiClient();
28
- }
29
-
30
- throw new Error('Unsupported platform');
52
+ return new GoogleDriveApiClient();
31
53
  }
@@ -1,7 +1,12 @@
1
1
  import { GDrive, MimeTypes } from 'react-native-google-drive-api-wrapper-js';
2
2
  import type NativeRNCloudStorage from '../types/native';
3
- import type { NativeRNCloudStorageScope } from '../types/native';
4
- import type { GoogleDriveFile, GoogleDriveListOperationResponse } from './types';
3
+ import {
4
+ NativeStorageErrorCode,
5
+ type NativeRNCloudStorageFileStat,
6
+ type NativeRNCloudStorageScope,
7
+ } from '../types/native';
8
+ import type { GoogleDriveDetailedFile, GoogleDriveFile, GoogleDriveListOperationResponse } from './types';
9
+ import NativeStorageError from '../utils/NativeStorageError';
5
10
 
6
11
  class GoogleDriveApiClient implements NativeRNCloudStorage {
7
12
  private static drive: GDrive = new GDrive();
@@ -13,7 +18,10 @@ class GoogleDriveApiClient implements NativeRNCloudStorage {
13
18
  get(target: GoogleDriveApiClient, prop: keyof GoogleDriveApiClient) {
14
19
  if (typeof target[prop] === 'function') {
15
20
  if (!GoogleDriveApiClient.drive.accessToken) {
16
- throw new Error(`Google Drive access token is not set, cannot call function ${prop.toString()}`);
21
+ throw new NativeStorageError(
22
+ `Google Drive access token is not set, cannot call function ${prop.toString()}`,
23
+ NativeStorageErrorCode.GOOGLE_DRIVE_ACCESS_TOKEN_MISSING
24
+ );
17
25
  }
18
26
  }
19
27
 
@@ -70,16 +78,27 @@ class GoogleDriveApiClient implements NativeRNCloudStorage {
70
78
  }
71
79
 
72
80
  if (!topDirectoryId) {
73
- throw new Error(`Could not find top directory with name ${directoryTree[0]}`);
81
+ throw new NativeStorageError(
82
+ `Could not find top directory with name ${directoryTree[0]}`,
83
+ NativeStorageErrorCode.DIRECTORY_NOT_FOUND
84
+ );
74
85
  }
75
86
 
76
87
  // now, we traverse the directories array and get the id of the last directory from the files array
77
88
  let currentDirectoryId = topDirectoryId;
78
89
  for (let i = 1; i < directoryTree.length; i++) {
79
90
  const currentDirectory = files.find((f) => f.id === currentDirectoryId);
80
- if (!currentDirectory) throw new Error(`Could not find directory with id ${currentDirectoryId}`);
91
+ if (!currentDirectory)
92
+ throw new NativeStorageError(
93
+ `Could not find directory with id ${currentDirectoryId}`,
94
+ NativeStorageErrorCode.DIRECTORY_NOT_FOUND
95
+ );
81
96
  const nextDirectory = files.find((f) => f.name === directoryTree[i] && f.parents![0] === currentDirectoryId);
82
- if (!nextDirectory) throw new Error(`Could not find directory with name ${directoryTree[i]}`);
97
+ if (!nextDirectory)
98
+ throw new NativeStorageError(
99
+ `Could not find directory with name ${directoryTree[i]}`,
100
+ NativeStorageErrorCode.DIRECTORY_NOT_FOUND
101
+ );
83
102
  currentDirectoryId = nextDirectory.id;
84
103
  }
85
104
 
@@ -107,7 +126,7 @@ class GoogleDriveApiClient implements NativeRNCloudStorage {
107
126
  } else {
108
127
  file = files.find((f) => f.name === filename && f.parents![0] === parentDirectoryId);
109
128
  }
110
- if (!file) throw new Error(`File not found`);
129
+ if (!file) throw new NativeStorageError(`File not found`, NativeStorageErrorCode.FILE_NOT_FOUND);
111
130
  return file.id;
112
131
  }
113
132
 
@@ -116,7 +135,7 @@ class GoogleDriveApiClient implements NativeRNCloudStorage {
116
135
  await this.getFileId(path, scope);
117
136
  return true;
118
137
  } catch (e: any) {
119
- if (e.message === 'File not found') return false;
138
+ if (e instanceof NativeStorageError && e.code === NativeStorageErrorCode.FILE_NOT_FOUND) return false;
120
139
  else throw e;
121
140
  }
122
141
  }
@@ -158,6 +177,20 @@ class GoogleDriveApiClient implements NativeRNCloudStorage {
158
177
  const fileId = await this.getFileId(path, scope);
159
178
  await GoogleDriveApiClient.drive.files.delete(fileId);
160
179
  }
180
+
181
+ async statFile(path: string, scope: NativeRNCloudStorageScope): Promise<NativeRNCloudStorageFileStat> {
182
+ const fileId = await this.getFileId(path, scope);
183
+ const file: GoogleDriveDetailedFile = await GoogleDriveApiClient.drive.files.get(fileId, {
184
+ fields: 'id,kind,mimeType,name,parents,spaces,size,createdTime,modifiedTime',
185
+ });
186
+ return {
187
+ size: file.size ?? 0,
188
+ birthtimeMs: new Date(file.createdTime!).getTime(),
189
+ mtimeMs: new Date(file.modifiedTime!).getTime(),
190
+ isDirectory: file.mimeType === MimeTypes.FOLDER,
191
+ isFile: file.mimeType !== MimeTypes.FOLDER,
192
+ };
193
+ }
161
194
  }
162
195
 
163
196
  export default GoogleDriveApiClient;
@@ -7,6 +7,12 @@ export interface GoogleDriveFile {
7
7
  spaces: ('appDataFolder' | 'drive')[];
8
8
  }
9
9
 
10
+ export interface GoogleDriveDetailedFile extends GoogleDriveFile {
11
+ createdTime: string;
12
+ modifiedTime: string;
13
+ size?: number;
14
+ }
15
+
10
16
  export interface GoogleDriveListOperationQueryParameters {
11
17
  corpora?: 'user' | 'drive' | 'domain' | 'allDrives';
12
18
  driveId?: string;
package/src/index.ts CHANGED
@@ -1,5 +1,9 @@
1
1
  import RNCloudStorage from './RNCloudStorage';
2
+ import { NativeStorageErrorCode } from './types/native';
2
3
  export * from './types/main';
3
4
  export * from './hooks/useCloudFile';
5
+ import NativeStorageError from './utils/NativeStorageError';
4
6
 
7
+ export { NativeStorageError };
8
+ export { NativeStorageErrorCode };
5
9
  export default RNCloudStorage;
package/src/types/main.ts CHANGED
@@ -2,3 +2,13 @@ export enum StorageScope {
2
2
  Documents = 'documents',
3
3
  Hidden = 'hidden',
4
4
  }
5
+
6
+ export interface StorageFileStat {
7
+ size: number;
8
+ birthtimeMs: number;
9
+ mtimeMs: number;
10
+ birthtime: Date;
11
+ mtime: Date;
12
+ isDirectory: () => boolean;
13
+ isFile: () => boolean;
14
+ }
@@ -1,8 +1,29 @@
1
1
  export type NativeRNCloudStorageScope = 'documents' | 'hidden';
2
2
 
3
+ export interface NativeRNCloudStorageFileStat {
4
+ size: number;
5
+ birthtimeMs: number;
6
+ mtimeMs: number;
7
+ isDirectory: boolean;
8
+ isFile: boolean;
9
+ }
10
+
11
+ export enum NativeStorageErrorCode {
12
+ FILE_NOT_FOUND = 'ERR_FILE_NOT_FOUND',
13
+ DIRECTORY_NOT_FOUND = 'ERR_NO_DIRECTORY_FOUND',
14
+ FILE_ALREADY_EXISTS = 'ERR_FILE_EXISTS',
15
+ WRITE_ERROR = 'ERR_WRITE_ERROR',
16
+ READ_ERROR = 'ERR_READ_ERROR',
17
+ DELETE_ERROR = 'ERR_DELETE_ERROR',
18
+ STAT_ERROR = 'ERR_STAT_ERROR',
19
+ UNKNOWN = 'ERR_UNKNOWN',
20
+ GOOGLE_DRIVE_ACCESS_TOKEN_MISSING = 'ERR_GOOGLE_DRIVE_ACCESS_TOKEN_MISSING',
21
+ }
22
+
3
23
  export default interface NativeRNCloudStorage {
4
24
  fileExists: (path: string, scope: NativeRNCloudStorageScope) => Promise<boolean>;
5
25
  createFile: (path: string, data: string, scope: NativeRNCloudStorageScope, overwrite: boolean) => Promise<void>;
6
26
  readFile: (path: string, scope: NativeRNCloudStorageScope) => Promise<string>;
7
27
  deleteFile: (path: string, scope: NativeRNCloudStorageScope) => Promise<void>;
28
+ statFile: (path: string, scope: NativeRNCloudStorageScope) => Promise<NativeRNCloudStorageFileStat>;
8
29
  }
@@ -0,0 +1,14 @@
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;