Skip to content

Commit 98546f9

Browse files
authored
Restrict mutation to sync metadata fields. (#276)
* Restrict mutation to sync metadata fields. * wip * wip
1 parent 5cf865c commit 98546f9

2 files changed

Lines changed: 14 additions & 13 deletions

File tree

Sources/SQLiteData/CloudKit/SyncMetadata.swift

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
@Selection
1717
public struct ID: Hashable, Sendable {
1818
/// The unique identifier of the record synchronized.
19-
public var recordPrimaryKey: String
19+
public let recordPrimaryKey: String
2020

2121
/// The type of the record synchronized, _i.e._ its table name.
22-
public var recordType: String
22+
public let recordType: String
2323
}
2424

2525
/// The unique identifier and type of the record synchronized.
@@ -32,10 +32,10 @@
3232
public var recordType: String { id.recordType }
3333

3434
/// The record zone name.
35-
public var zoneName: String
35+
public let zoneName: String
3636

3737
/// The record owner name.
38-
public var ownerName: String
38+
public let ownerName: String
3939

4040
/// The name of the record synchronized.
4141
///
@@ -53,14 +53,14 @@
5353
@Selection
5454
public struct ParentID: Hashable, Sendable {
5555
/// The unique identifier of the parent record synchronized.
56-
public var parentRecordPrimaryKey: String
56+
public let parentRecordPrimaryKey: String
5757

5858
/// The type of the parent record synchronized, _i.e._ its table name.
59-
public var parentRecordType: String
59+
public let parentRecordType: String
6060
}
6161

6262
/// The identifier and type of this record's parent, if any.
63-
public var parentRecordID: ParentID?
63+
public let parentRecordID: ParentID?
6464

6565
/// The unique identifier of this record's parent, if any.
6666
public var parentRecordPrimaryKey: String? { parentRecordID?.parentRecordPrimaryKey }
@@ -83,19 +83,19 @@
8383
///
8484
/// This record holds only the fields that are archived when using `encodeSystemFields(with:)`.
8585
@Column(as: CKRecord?.SystemFieldsRepresentation.self)
86-
public var lastKnownServerRecord: CKRecord?
86+
public let lastKnownServerRecord: CKRecord?
8787

8888
/// The last known `CKRecord` received from the server with all fields archived.
8989
@Column(as: CKRecord?._AllFieldsRepresentation.self)
90-
public var _lastKnownServerRecordAllFields: CKRecord?
90+
public let _lastKnownServerRecordAllFields: CKRecord?
9191

9292
/// The `CKShare` associated with this record, if it is shared.
9393
@Column(as: CKShare?.SystemFieldsRepresentation.self)
94-
public var share: CKShare?
94+
public let share: CKShare?
9595

9696
/// Determines if the metadata has been "soft" deleted. It will be fully deleted once the
9797
/// next batch of pending changes is processed.
98-
public var _isDeleted = false
98+
public let _isDeleted: Bool
9999

100100
@Column(generated: .virtual)
101101
public let hasLastKnownServerRecord: Bool
@@ -109,7 +109,7 @@
109109
public let isShared: Bool
110110

111111
/// The time the user last modified the record.
112-
public var userModificationTime: Int64
112+
public let userModificationTime: Int64
113113
}
114114

115115
@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
@@ -165,6 +165,7 @@
165165
self.hasLastKnownServerRecord = lastKnownServerRecord != nil
166166
self.isShared = share != nil
167167
self.userModificationTime = userModificationTime
168+
self._isDeleted = false
168169
}
169170

170171
package static func find(_ recordID: CKRecord.ID) -> Where<Self> {

Sources/SQLiteData/Documentation.docc/Articles/CloudKit.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ data for a list when you need it.
533533

534534
While the library tries to make CloudKit synchronization as seamless and hidden as possible,
535535
there are times you will need to access the underlying CloudKit types for your tables and records.
536-
The ``SyncMetadata``table is the central place where this data is stored, and it is publicly
536+
The ``SyncMetadata`` table is the central place where this data is stored, and it is publicly
537537
exposed for you to query it in whichever way you want.
538538

539539
> Important: In order to query the `SyncMetadata` table from your database connection you will need

0 commit comments

Comments
 (0)