@functionland/react-native-fula 1.54.8 → 1.54.9

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/ios/Fula.mm CHANGED
@@ -2,7 +2,8 @@
2
2
 
3
3
  @interface RCT_EXTERN_MODULE(FulaModule, NSObject)
4
4
 
5
- RCT_EXTERN_METHOD(registerLifecycleListener)
5
+ RCT_EXTERN_METHOD(registerLifecycleListener:(RCTPromiseResolveBlock)resolve
6
+ withRejecter:(RCTPromiseRejectBlock)reject)
6
7
 
7
8
  RCT_EXTERN_METHOD(checkConnection: (nonnull NSNumber *) timeout
8
9
  withResolver:(RCTPromiseResolveBlock)resolve
package/ios/Fula.swift CHANGED
@@ -135,7 +135,31 @@ class FulaModule: NSObject {
135
135
  return convertIntToByte(keyInt)
136
136
  }
137
137
 
138
- @objc func registerLifecycleListener() {
138
+ @objc func applicationWillResignActive() {
139
+ // Log that the app will resign active
140
+ os_log("Application will resign active", log: OSLog.viewCycle, type: .info)
141
+ }
142
+
143
+ @objc func applicationDidEnterBackground() {
144
+ // Log that the app has entered the background
145
+ os_log("Application did enter background", log: OSLog.viewCycle, type: .info)
146
+ }
147
+
148
+ @objc func applicationWillTerminate() {
149
+ // Attempt to shut down Fula cleanly (similar to onHostDestroy)
150
+ os_log("Application will terminate - shutting down Fula", log: OSLog.viewCycle, type: .info)
151
+ do {
152
+ if let fulaClient = fula {
153
+ try fulaClient.shutdown()
154
+ os_log("Fula shutdown successfully.", log: OSLog.viewCycle, type: .info)
155
+ }
156
+ } catch {
157
+ os_log("Error shutting down Fula: %{public}@", log: OSLog.viewCycle, type: .error, String(describing: error))
158
+ }
159
+ }
160
+
161
+ @objc(registerLifecycleListener:withRejecter:)
162
+ func registerLifecycleListener(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
139
163
  NotificationCenter.default.addObserver(
140
164
  self,
141
165
  selector: #selector(applicationWillResignActive),
@@ -153,30 +177,15 @@ class FulaModule: NSObject {
153
177
  selector: #selector(applicationWillTerminate),
154
178
  name: UIApplication.willTerminateNotification,
155
179
  object: nil)
180
+
181
+ // Assuming the operation is always successful
182
+ resolve(true)
156
183
  }
157
184
 
158
185
  deinit {
159
186
  NotificationCenter.default.removeObserver(self)
160
187
  }
161
188
 
162
- @objc func applicationWillResignActive() {
163
- // Handle app will resign active (similar to onHostPause)
164
- }
165
-
166
- @objc func applicationDidEnterBackground() {
167
- // Handle app entered background
168
- }
169
-
170
- @objc func applicationWillTerminate() {
171
- // Attempt to shut down Fula cleanly (similar to onHostDestroy)
172
- do {
173
- try shutdownInternal()
174
- } catch {
175
- print("Error shutting down Fula: \(error)")
176
- }
177
- }
178
-
179
-
180
189
  @objc(checkConnection:withResolver:withRejecter:)
181
190
  func checkConnection(timeout: NSNumber, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
182
191
  OSLog.viewCycle.info("ReactNative checkConnection started with timeout=\(timeout)")
@@ -510,7 +519,9 @@ class FulaModule: NSObject {
510
519
 
511
520
  func newClientInternal(identity: Data, storePath: String?, bloxAddr: String, exchange: String, autoFlush: Bool, useRelay: Bool, refresh: Bool) throws -> Data {
512
521
  do {
522
+ OSLog.viewCycle.info("ReactNative fula newClientInternal refresh=\(refresh)")
513
523
  fulaConfig = FulamobileConfig()
524
+ print("ReactNative", "cofig is set: ")
514
525
  if (storePath == nil || storePath!.isEmpty) {
515
526
  fulaConfig!.storePath = fulaStorePath
516
527
  } else {
@@ -552,6 +563,7 @@ class FulaModule: NSObject {
552
563
  func initInternal(identity: Data, storePath: String, bloxAddr: String, exchange: String, autoFlush: Bool, _rootCid: String, useRelay: Bool, refresh: Bool) throws -> [String] {
553
564
 
554
565
  do {
566
+ OSLog.viewCycle.info("ReactNative fula initInternal=\(refresh)")
555
567
  if (fula == nil || refresh) {
556
568
  try newClientInternal(identity: identity, storePath: storePath, bloxAddr: bloxAddr, exchange: exchange, autoFlush: autoFlush, useRelay: useRelay, refresh: refresh)
557
569
  OSLog.viewCycle.info("ReactNative fula initialized: \(self.fula!.id_())")
@@ -1104,11 +1116,15 @@ class FulaModule: NSObject {
1104
1116
  throw MyError.runtimeError("Fula client is not initialized")
1105
1117
  }
1106
1118
  guard let poolID = Int64(poolIDStr) else {
1107
- reject("ERR_FULA", "Invalid poolID - not a valid number: \(poolIDStr)")
1119
+ let error = NSError(domain: "FULAErrorDomain", code: 1001, userInfo: [NSLocalizedDescriptionKey: "Invalid poolID - not a valid number: \(poolIDStr)"])
1120
+ reject("ERR_FULA", "Invalid poolID - not a valid number: \(poolIDStr)", error)
1108
1121
  return
1109
1122
  }
1110
1123
  guard let replicationFactor = Int64(replicationFactorStr) else {
1111
- reject("ERR_FULA", "Invalid replicationFactorStr - not a valid number: \(replicationFactorStr)")
1124
+ let error = NSError(domain: "FULAErrorDomain",
1125
+ code: 1002,
1126
+ userInfo: [NSLocalizedDescriptionKey: "Invalid replicationFactor - not a valid number: \(replicationFactorStr)"])
1127
+ reject("ERR_FULA", "Invalid replicationFactorStr - not a valid number: \(replicationFactorStr)", error)
1112
1128
  return
1113
1129
  }
1114
1130
 
@@ -1119,7 +1135,8 @@ class FulaModule: NSObject {
1119
1135
  throw MyError.runtimeError("Unable to encode CIDs as data")
1120
1136
  }
1121
1137
 
1122
- try fulaClient.batchUploadManifest(cidsData, poolID, replicationFactor)
1138
+ // Adjusted call to match the expected method signature and argument types
1139
+ try fulaClient.batchUploadManifest(cidsData, poolID: Int(poolID), replicationFactor: Int(replicationFactor))
1123
1140
  resolve(true)
1124
1141
  } catch let error {
1125
1142
  print("ReactNative", "batchUploadManifest failed with Error: \(error.localizedDescription)")
@@ -1201,44 +1218,55 @@ class FulaModule: NSObject {
1201
1218
  }
1202
1219
 
1203
1220
  @objc(listPoolJoinRequests:withResolver:withRejecter:)
1204
- func listPoolJoinRequests(poolIDStr: String, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
1221
+ func listPoolJoinRequests(poolIDStr: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
1205
1222
  print("ReactNative", "listPoolJoinRequests: poolIDStr = ", poolIDStr)
1206
1223
  do {
1207
- if let poolID = Int64(poolIDStr) {
1208
- // Conversion successful - use longPoolID
1209
-
1210
- let result = try fula!.poolRequests(poolID)
1211
- let resultString = result.toUTF8String()!
1212
- resolve(resultString)
1224
+ if let poolID = Int64(poolIDStr), let intPoolID = Int(exactly: poolID) {
1225
+ // Conversion to Int successful - use intPoolID
1226
+ let result = try fula!.poolRequests(intPoolID)
1227
+ let resultString = result.toUTF8String()!
1228
+ resolve(resultString)
1213
1229
  } else {
1214
- // Handle invalid input (e.g., "abc", "123.45")
1215
- reject("ERR_FULA", "Invalid poolIDStr - not a valid number: \(poolIDStr)")
1230
+ // Handle invalid input or Int64 not convertible to Int
1231
+ let error = NSError(domain: "FULAErrorDomain",
1232
+ code: 1003,
1233
+ userInfo: [NSLocalizedDescriptionKey: "Invalid poolIDStr - not a valid number or too large: \(poolIDStr)"])
1234
+ reject("ERR_FULA", "Invalid poolIDStr - not a valid number or too large: \(poolIDStr)", error)
1216
1235
  }
1217
1236
  } catch let error {
1218
1237
  print("listPoolJoinRequests", error.localizedDescription)
1219
- reject("ERR_FULA", "listPoolJoinRequests", error)
1238
+ let nsError = error as NSError
1239
+ reject("ERR_FULA", "Failed listPoolJoinRequests due to error", nsError)
1220
1240
  }
1221
-
1222
1241
  }
1223
1242
 
1224
1243
  @objc(listAvailableReplicationRequests:withResolver:withRejecter:)
1225
- func listAvailableReplicationRequests(poolIDStr: String, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
1244
+ func listAvailableReplicationRequests(poolIDStr: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
1226
1245
  print("ReactNative", "listAvailableReplicationRequests: poolIDStr = ", poolIDStr)
1227
1246
  do {
1228
- guard let poolID = Int64(poolIDStr) else {
1229
- reject("ERR_FULA", "Invalid poolID - not a valid number: \(poolIDStr)")
1247
+ guard let poolID = Int64(poolIDStr), let intPoolID = Int(exactly: poolID) else {
1248
+ let error = NSError(domain: "FULAErrorDomain",
1249
+ code: 1004, // Use appropriate error code
1250
+ userInfo: [NSLocalizedDescriptionKey: "Invalid poolID - not a valid number: \(poolIDStr)"])
1251
+ reject("ERR_FULA", "Invalid poolID - not a valid number: \(poolIDStr)", error)
1252
+ return
1253
+ }
1254
+ let result = try fula!.manifestAvailable(intPoolID)
1255
+ guard let resultString = result.toUTF8String() else {
1256
+ let error = NSError(domain: "FULAErrorDomain",
1257
+ code: 1005, // Use appropriate error code
1258
+ userInfo: [NSLocalizedDescriptionKey: "Failed to convert result to UTF8 String"])
1259
+ reject("ERR_FULA", "Conversion Error", error)
1230
1260
  return
1231
1261
  }
1232
- let result = try fula!.manifestAvailable(poolID)
1233
- let resultString = result.toUTF8String()!
1234
1262
  resolve(resultString)
1235
- } catch let error {
1263
+ } catch let error as NSError {
1236
1264
  print("listAvailableReplicationRequests", error.localizedDescription)
1237
- reject("ERR_FULA", "listAvailableReplicationRequests", error)
1265
+ reject("ERR_FULA", "listAvailableReplicationRequests failed with error: \(error.localizedDescription)", error)
1238
1266
  }
1239
-
1240
1267
  }
1241
1268
 
1269
+
1242
1270
  @objc(bloxFreeSpace:withRejecter:)
1243
1271
  func bloxFreeSpace( resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
1244
1272
  print("ReactNative", "bloxFreeSpace")
@@ -1388,17 +1416,27 @@ class FulaModule: NSObject {
1388
1416
  }
1389
1417
  }
1390
1418
 
1391
- @objc(fetchContainerLogs:tailCount:withResolver:withRejecter:)
1392
- func fetchContainerLogs(containerName: String, tailCount: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
1393
- do {
1394
- let result = try fula!.fetchContainerLogs(containerName, tailCount)
1395
- let resultString = result.toUTF8String()!
1396
- resolve(resultString)
1397
- } catch let error {
1398
- print("fetchContainerLogs", error.localizedDescription)
1399
- reject("ERR_FULA", "fetchContainerLogs", error)
1400
- }
1401
- }
1419
+ @objc(fetchContainerLogs:tailCount:withResolver:withRejecter:)
1420
+ func fetchContainerLogs(containerName: String, tailCount: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
1421
+ do {
1422
+ // Since fetchContainerLogs expects a String for tailCount, pass it directly
1423
+ let result = try fula!.fetchContainerLogs(containerName, tailCount: tailCount)
1424
+ guard let resultString = result.toUTF8String() else {
1425
+ // Handle the case where result.toUTF8String() returns nil
1426
+ let error = NSError(domain: "FULAErrorDomain",
1427
+ code: 1007, // Choose a suitable error code
1428
+ userInfo: [NSLocalizedDescriptionKey: "Failed to convert log data to string."])
1429
+ reject("ERR_FULA", "Log Conversion Error", error)
1430
+ return
1431
+ }
1432
+ resolve(resultString)
1433
+ } catch let error as NSError {
1434
+ print("fetchContainerLogs", error.localizedDescription)
1435
+ reject("ERR_FULA", "fetchContainerLogs failed", error)
1436
+ }
1437
+ }
1438
+
1439
+
1402
1440
 
1403
1441
  @objc(getFolderSize:withResolver:withRejecter:)
1404
1442
  func getFolderSize(folderPath: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
@@ -1412,17 +1450,18 @@ class FulaModule: NSObject {
1412
1450
  }
1413
1451
  }
1414
1452
 
1415
- @objc(getDatastoreSize:withResolver:withRejecter:)
1416
- func getDatastoreSize(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
1417
- do {
1418
- let result = try fula!.getDatastoreSize()
1419
- let resultString = result.toUTF8String()!
1420
- resolve(resultString)
1421
- } catch let error {
1422
- print("getDatastoreSize", error.localizedDescription)
1423
- reject("ERR_FULA", "getDatastoreSize", error)
1424
- }
1425
- }
1453
+ @objc(getDatastoreSizeWithResolver:withRejecter:)
1454
+ func getDatastoreSize(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
1455
+ do {
1456
+ let result = try fula!.getDatastoreSize()
1457
+ let resultString = result.toUTF8String()!
1458
+ resolve(resultString)
1459
+ } catch let error {
1460
+ print("getDatastoreSize", error.localizedDescription)
1461
+ let nsError = error as NSError
1462
+ reject("ERR_FULA", "Failed to get datastore size", nsError)
1463
+ }
1464
+ }
1426
1465
 
1427
1466
  //Add Replicate In Pool (replicateInPool)
1428
1467
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@functionland/react-native-fula",
3
- "version": "1.54.8",
3
+ "version": "1.54.9",
4
4
  "description": "This package is a bridge to use the Fula libp2p protocols in the react-native which is using wnfs",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -38,7 +38,7 @@ Pod::Spec.new do |s|
38
38
  s.dependency "ReactCommon/turbomodule/core"
39
39
  end
40
40
  end
41
- s.dependency 'Fula','~> 1.41.0'
41
+ s.dependency 'Fula','~> 1.54.8'
42
42
  s.dependency "Wnfs", "1.1.1"
43
43
  s.dependency 'CryptoSwift', '~> 1.7.1'
44
44
  s.user_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }