@onekeyfe/react-native-cloud-kit-module 1.1.13 → 1.1.14

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.
@@ -1,6 +1,7 @@
1
1
  package com.margelo.nitro.cloudkitmodule
2
2
 
3
3
  import com.facebook.proguard.annotations.DoNotStrip
4
+ import com.margelo.nitro.core.NullType
4
5
  import com.margelo.nitro.core.Promise
5
6
 
6
7
  @DoNotStrip
@@ -29,8 +30,8 @@ class CloudKitModule : HybridCloudKitModuleSpec() {
29
30
  )
30
31
  }
31
32
 
32
- override fun fetchRecord(params: FetchRecordParams): Promise<RecordResult?> {
33
- return Promise.resolved(null)
33
+ override fun fetchRecord(params: FetchRecordParams): Promise<Variant_NullType_RecordResult> {
34
+ return Promise.resolved(Variant_NullType_RecordResult.First(NullType.NULL))
34
35
  }
35
36
 
36
37
  override fun deleteRecord(params: DeleteRecordParams): Promise<Unit> {
@@ -3,12 +3,13 @@ import CloudKit
3
3
  import NitroModules
4
4
 
5
5
  class CloudKitModule: HybridCloudKitModuleSpec {
6
+
6
7
  // MARK: - Properties
7
8
  private let container = CKContainer.default()
8
9
  private lazy var database = container.privateCloudDatabase
9
10
 
10
11
  // MARK: - Check Availability
11
-
12
+
12
13
  public func isAvailable() throws -> Promise<Bool> {
13
14
  return Promise.async {
14
15
  let status = try await self.container.accountStatus()
@@ -17,7 +18,7 @@ class CloudKitModule: HybridCloudKitModuleSpec {
17
18
  }
18
19
 
19
20
  // MARK: - Get Account Info
20
-
21
+
21
22
  public func getAccountInfo() throws -> Promise<AccountInfoResult> {
22
23
  return Promise.async {
23
24
  let status = try await self.container.accountStatus()
@@ -47,7 +48,7 @@ class CloudKitModule: HybridCloudKitModuleSpec {
47
48
  }
48
49
 
49
50
  // MARK: - Save Record
50
-
51
+
51
52
  public func saveRecord(params: SaveRecordParams) throws -> Promise<SaveRecordResult> {
52
53
  return Promise.async {
53
54
  let ckRecordID = CKRecord.ID(recordName: params.recordID)
@@ -74,40 +75,41 @@ class CloudKitModule: HybridCloudKitModuleSpec {
74
75
  }
75
76
 
76
77
  // MARK: - Fetch Record
77
-
78
- public func fetchRecord(params: FetchRecordParams) throws -> Promise<RecordResult?> {
78
+
79
+ public func fetchRecord(params: FetchRecordParams) throws -> NitroModules.Promise<Variant_NullType_RecordResult> {
79
80
  return Promise.async {
80
81
  let ckRecordID = CKRecord.ID(recordName: params.recordID)
81
-
82
+
82
83
  do {
83
84
  let record = try await self.database.record(for: ckRecordID)
84
-
85
+
85
86
  let data = record[CloudKitConstants.recordDataField] as? String ?? ""
86
87
  let meta = record[CloudKitConstants.recordMetaField] as? String ?? ""
87
88
  let createdAt = Int64((record.creationDate?.timeIntervalSince1970 ?? 0) * 1000)
88
89
  let modifiedAt = Int64((record.modificationDate?.timeIntervalSince1970 ?? 0) * 1000)
89
-
90
- let result = RecordResult(
91
- recordID: record.recordID.recordName,
92
- recordType: record.recordType,
93
- data: data,
94
- meta: meta,
95
- createdAt: Double(createdAt),
96
- modifiedAt: Double(modifiedAt)
90
+
91
+ let result = Variant_NullType_RecordResult.second(
92
+ RecordResult(
93
+ recordID: record.recordID.recordName,
94
+ recordType: record.recordType,
95
+ data: data,
96
+ meta: meta,
97
+ createdAt: Double(createdAt),
98
+ modifiedAt: Double(modifiedAt))
97
99
  )
98
100
  return result
99
101
  } catch let error as CKError where error.code == .unknownItem {
100
- return nil
102
+ return Variant_NullType_RecordResult.first(NullType.null)
101
103
  }
102
104
  }
103
105
  }
104
106
 
105
107
  // MARK: - Delete Record
106
-
108
+
107
109
  public func deleteRecord(params: DeleteRecordParams) throws -> Promise<Void> {
108
110
  return Promise.async {
109
111
  let ckRecordID = CKRecord.ID(recordName: params.recordID)
110
-
112
+
111
113
  do {
112
114
  _ = try await self.database.deleteRecord(withID: ckRecordID)
113
115
  return Void()
@@ -119,11 +121,11 @@ class CloudKitModule: HybridCloudKitModuleSpec {
119
121
  }
120
122
 
121
123
  // MARK: - Record Exists
122
-
124
+
123
125
  public func recordExists(params: RecordExistsParams) throws -> Promise<Bool> {
124
126
  return Promise.async {
125
127
  let ckRecordID = CKRecord.ID(recordName: params.recordID)
126
-
128
+
127
129
  do {
128
130
  _ = try await self.database.record(for: ckRecordID)
129
131
  return true
@@ -134,7 +136,7 @@ class CloudKitModule: HybridCloudKitModuleSpec {
134
136
  }
135
137
 
136
138
  // MARK: - Query Records
137
-
139
+
138
140
  public func queryRecords(params: QueryRecordsParams) throws -> Promise<QueryRecordsResult> {
139
141
  return Promise.async {
140
142
  let predicate = NSPredicate(value: true)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/react-native-cloud-kit-module",
3
- "version": "1.1.13",
3
+ "version": "1.1.14",
4
4
  "description": "react-native-cloud-kit-module",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",