@@ -152,7 +152,7 @@ public actor AttachmentQueue {
152152 /// Starts the attachment sync process
153153 public func startSync( ) async throws {
154154 if closed {
155- throw NSError ( domain : " AttachmentError " , code : 4 , userInfo : [ NSLocalizedDescriptionKey : " Attachment queue has been closed " ] )
155+ throw PowerSyncAttachmentError . closed ( " Cannot start syncing on closed attachment queue" )
156156 }
157157
158158 // Ensure the directory where attachments are downloaded exists
@@ -251,24 +251,24 @@ public actor AttachmentQueue {
251251 Attachment (
252252 id: item. id,
253253 filename: filename,
254- state: AttachmentState . queuedDownload. rawValue
254+ state: AttachmentState . queuedDownload
255255 )
256256 )
257- } else if existingQueueItem!. state == AttachmentState . archived. rawValue {
257+ } else if existingQueueItem!. state == AttachmentState . archived {
258258 // The attachment is present again. Need to queue it for sync.
259259 // We might be able to optimize this in future
260260 if existingQueueItem!. hasSynced == 1 {
261261 // No remote action required, we can restore the record (avoids deletion)
262262 attachmentUpdates. append (
263- existingQueueItem!. with ( state: AttachmentState . synced. rawValue )
263+ existingQueueItem!. with ( state: AttachmentState . synced)
264264 )
265265 } else {
266266 // The localURI should be set if the record was meant to be downloaded
267267 // and has been synced. If it's missing and hasSynced is false then
268268 // it must be an upload operation
269269 let newState = existingQueueItem!. localUri == nil ?
270- AttachmentState . queuedDownload. rawValue :
271- AttachmentState . queuedUpload. rawValue
270+ AttachmentState . queuedDownload :
271+ AttachmentState . queuedUpload
272272
273273 attachmentUpdates. append (
274274 existingQueueItem!. with ( state: newState)
@@ -282,10 +282,10 @@ public actor AttachmentQueue {
282282 * Archive any items not specified in the watched items except for items pending delete.
283283 */
284284 for attachment in currentAttachments {
285- if attachment. state != AttachmentState . queuedDelete. rawValue &&
285+ if attachment. state != AttachmentState . queuedDelete &&
286286 items. first ( where: { $0. id == attachment. id } ) == nil {
287287 attachmentUpdates. append (
288- attachment. with ( state: AttachmentState . archived. rawValue )
288+ attachment. with ( state: AttachmentState . archived)
289289 )
290290 }
291291 }
@@ -327,7 +327,7 @@ public actor AttachmentQueue {
327327 let attachment = Attachment (
328328 id: id,
329329 filename: filename,
330- state: AttachmentState . queuedUpload. rawValue ,
330+ state: AttachmentState . queuedUpload,
331331 localUri: localUri,
332332 mediaType: mediaType,
333333 size: fileSize
@@ -352,12 +352,7 @@ public actor AttachmentQueue {
352352 ) async throws -> Attachment {
353353 try await attachmentsService. withLock { context in
354354 guard let attachment = try await context. getAttachment ( id: attachmentId) else {
355- // TODO defined errors
356- throw NSError (
357- domain: " AttachmentError " ,
358- code: 5 ,
359- userInfo: [ NSLocalizedDescriptionKey: " Attachment record with id \( attachmentId) was not found. " ]
360- )
355+ throw PowerSyncAttachmentError . notFound ( " Attachment record with id \( attachmentId) was not found. " )
361356 }
362357
363358 self . logger. debug ( " Marking attachment as deleted " , tag: nil )
@@ -367,7 +362,7 @@ public actor AttachmentQueue {
367362 let updatedAttachment = Attachment (
368363 id: attachment. id,
369364 filename: attachment. filename,
370- state: AttachmentState . queuedDelete. rawValue ,
365+ state: AttachmentState . queuedDelete,
371366 hasSynced: attachment. hasSynced,
372367 localUri: attachment. localUri,
373368 mediaType: attachment. mediaType,
0 commit comments