TeraGeneratedInvalidation.swift (1979B)
1 import TeraKitBindings 2 3 extension FfiRuntimeChangeRecord { 4 var appValue: TeraRuntimeChange { 5 TeraRuntimeChange( 6 schemaVersion: schemaVersion, 7 scope: TeraRuntimeChangeScope( 8 publicKey: scope.publicKey, 9 sourceGeneration: scope.sourceGeneration, 10 context: scope.context.map { 11 TeraLocalNetwork( 12 schemaVersion: $0.schemaVersion, id: $0.id, label: $0.label, 13 relayURLs: $0.relayUrls, locality: $0.locality, 14 followedAuthors: $0.followedAuthors, generation: $0.generation 15 ) 16 } 17 ), 18 epoch: epoch, revision: revision.appValue, delivery: delivery.appValue, kind: kind.appValue, entityID: entityId 19 ) 20 } 21 } 22 23 extension FfiRuntimeChangeDelivery { 24 fileprivate var appValue: TeraRuntimeChangeDelivery { 25 switch self { 26 case .change: .change 27 case .resnapshotRequired: .resnapshotRequired 28 } 29 } 30 } 31 32 /// The continuation is immutable and synchronizes delivery and termination. 33 final class TeraGeneratedRuntimeObserver: TeraRuntimeObserver, Sendable { 34 private let continuation: AsyncStream<TeraRuntimeChange>.Continuation 35 36 init(continuation: AsyncStream<TeraRuntimeChange>.Continuation) { 37 self.continuation = continuation 38 } 39 40 func onChange(change: FfiRuntimeChangeRecord) { 41 change.appValue.yield(to: continuation) 42 } 43 44 func finish() { 45 continuation.finish() 46 } 47 } 48 49 extension FfiInvalidationRevision { 50 fileprivate var appValue: TeraProjectionRevision { 51 switch self { 52 case let .current(value): TeraProjectionRevision(rawValue: value) 53 case .exhausted: .exhausted 54 } 55 } 56 } 57 58 extension FfiRuntimeChangeKind { 59 fileprivate var appValue: TeraRuntimeChangeKind { 60 switch self { 61 case .initial: .initial 62 case .identity: .identity 63 case .settings: .settings 64 case .profile: .profile 65 case .today: .today 66 case .drafts: .drafts 67 case .relay: .relay 68 case .media: .media 69 case .lifecycle: .lifecycle 70 } 71 } 72 }