TeraGeneratedTodaySync.swift (3017B)
1 import Foundation 2 import TeraKitBindings 3 4 extension FfiTodaySyncRecord { 5 var appValue: TeraTodaySyncReceipt { 6 TeraTodaySyncReceipt( 7 relayState: relayState.appValue, termination: termination.appValue, 8 targets: targets.map(\.appValue), pagesFetched: pagesFetched, 9 eventsObserved: eventsObserved, eventsAdmitted: eventsAdmitted, 10 eventsRejected: eventsRejected, projection: projection.appValue, discovery: discovery.appValue 11 ) 12 } 13 } 14 15 extension FfiTodayTargetSyncRecord { 16 var appValue: TeraTodayTargetSyncReceipt { 17 TeraTodayTargetSyncReceipt( 18 targetFingerprint: targetFingerprint, finalState: finalState?.appValue, summary: summary?.appValue 19 ) 20 } 21 } 22 23 extension FfiTodayTargetPageSummary { 24 var appValue: TeraTodayTargetPageSummary { 25 TeraTodayTargetPageSummary( 26 pagesObserved: pagesObserved, incompletePages: incompletePages, 27 missingOutcomePages: missingOutcomePages, lastIncomplete: lastIncomplete?.appValue 28 ) 29 } 30 } 31 32 extension FfiTodayRelaySyncState { 33 var appValue: TeraTodayRelaySyncState { 34 switch self { 35 case .complete: .complete 36 case .partial: .partial 37 case .offline: .offline 38 } 39 } 40 } 41 42 extension FfiTodaySyncTermination { 43 var appValue: TeraTodaySyncTermination { 44 switch self { 45 case .complete: .complete 46 case .pageLimit: .pageLimit 47 case .deadline: .deadline 48 case .cancelled: .cancelled 49 case .sourceFailed: .sourceFailed 50 } 51 } 52 } 53 54 extension FfiTodayTargetSyncState { 55 var appValue: TeraTodayTargetSyncState { 56 switch self { 57 case .complete: .complete 58 case .partial: .partial 59 case .unavailable: .unavailable 60 case .failedRetryable: .failedRetryable 61 case .failedTerminal: .failedTerminal 62 case .cancelled: .cancelled 63 } 64 } 65 } 66 67 extension FfiTodayRefreshRecord { 68 var appValue: TeraTodayRefreshReceipt { 69 TeraTodayRefreshReceipt( 70 update: update.appValue, 71 sourceEvents: sourceEvents, 72 visibleCards: visibleCards, 73 profiles: profiles, 74 threadEntries: threadEntries, 75 contentGeneration: contentGeneration, 76 changed: changed 77 ) 78 } 79 } 80 81 extension FfiTodayProjectionUpdate { 82 var appValue: TeraTodayProjectionUpdate { 83 switch self { 84 case .incremental: .incremental 85 case .rebuild: .rebuild 86 } 87 } 88 } 89 90 extension FfiTodayDiscoveryRecord { 91 var appValue: TeraTodayDiscoveryReceipt { 92 TeraTodayDiscoveryReceipt(continuation: continuation, hadIncompleteResponses: hadIncompleteResponses) 93 } 94 } 95 96 enum TeraGeneratedTodayOperation { 97 static func run( 98 runtime: TeraRuntime, context: FfiLocalNetworkRecord, nowUnixSeconds: UInt64, 99 update: FfiTodayProjectionUpdate, backfillCursor: String? 100 ) async throws -> FfiTodaySyncRecord { 101 if let backfillCursor { 102 return try await runtime.phase1BackfillToday( 103 context: context, nowUnixS: nowUnixSeconds, cursor: backfillCursor 104 ) 105 } 106 return try await runtime.phase1SyncToday( 107 context: context, nowUnixS: nowUnixSeconds, update: update 108 ) 109 } 110 }