field_ios

In-the-field app for Radroots on iOS
git clone https://radroots.dev/git/field_ios.git
Log | Files | Refs | README | LICENSE

TeraRuntimeBackend.swift (12936B)


      1 import Foundation
      2 
      3 protocol TeraRuntimeSubscriptionToken: Sendable {
      4   func cancel() async
      5 }
      6 
      7 protocol TeraRuntimeBackend: Sendable {
      8   func authorVisibility() async throws -> TeraAuthorVisibilityPolicy
      9   func setAuthorVisibility(author: String, visibility: TeraAuthorVisibility) async throws -> TeraAuthorVisibilityPolicy
     10   func prepareRetractionForKeyRemoval(_ request: TeraKeyRemovalRequest) async throws
     11   func cleanupMediaCache(context: TeraLocalNetwork) async throws -> TeraMediaCacheCleanup
     12   func restoreStatus() async throws -> TeraRestoreStatus?
     13   func reconcileRestoredTarget(_ target: TeraRestoreTarget) async throws
     14   func reviewRestoredWork() async throws -> String
     15   func resumeRestoredWork(reviewedInventory: String) async throws
     16   func nativeRecoveryStatus(key: String) async throws -> TeraNativeRecoveryStatus?
     17   func nativeRecoverySchedule() async throws -> TeraNativeRecoverySchedule
     18   func advanceNativeRecoverySchedule(expected: TeraNativeRecoverySchedule, after: String?) async throws -> TeraNativeRecoverySchedule
     19   func reportNativeRecoveryStatus(key: String, reason: TeraNativeRecoveryReason) async throws -> TeraNativeRecoveryStatus?
     20   func recoveryPage(limit: UInt16, cursor: String?) async throws -> TeraRecoveryPage
     21   func recoverNativeUpload(_ receipt: TeraRecoveryUploadReceipt, media: TeraPreparedMediaHandle) async throws -> TeraRecoveryCompletionReceipt
     22   func recoveryParent(key: String) async throws -> TeraRecoveryEntry?
     23   func reserveSubmissionID() async throws -> String
     24   func reserveSubmission(request: TeraSubmissionRequest) async throws -> TeraSubmissionReservation
     25   func prepareSubmission(request: TeraSubmissionRequest, media: [TeraPreparedMediaHandle]) async throws -> TeraSubmissionStatus
     26   func recoverSubmission(request: TeraSubmissionRequest) async throws -> TeraSubmissionStatus?
     27   func submissionStatus(request: TeraSubmissionRequest) async throws -> TeraSubmissionStatus
     28   func requestSubmissionStop(request: TeraSubmissionRequest) async throws -> TeraSubmissionStatus
     29   func reconcileSubmissionLocal(request: TeraSubmissionRequest, context: TeraLocalNetwork) async throws -> TeraSubmissionStatus
     30   func advanceSubmission(request: TeraSubmissionRequest, expectedRevision: UInt64) async throws -> TeraSubmissionStatus
     31   func listSubmissions(scope: TeraComposerScope, limit: UInt16, cursor: String?) async throws -> TeraSubmissionPage
     32   func prepareSubmissionUpload(input: TeraSubmissionMediaRequest) async throws -> TeraSubmissionUploadJob
     33   func uploadSubmissionMedia(input: TeraSubmissionMediaRequest) async throws -> TeraSubmissionStatus
     34   func renewSubmissionUpload(input: TeraSubmissionMediaRequest, renewal: TeraSubmissionUploadRenewal) async throws -> TeraSubmissionUploadJob
     35   func renewSubmissionMedia(input: TeraSubmissionMediaRequest, renewal: TeraSubmissionUploadRenewal) async throws -> TeraSubmissionStatus
     36   func completeSubmissionUpload(input: TeraSubmissionMediaRequest, response: TeraAddBackgroundUploadReceipt) async throws -> TeraSubmissionStatus
     37   func reserveComposerID() async throws -> String
     38   func saveComposer(request: TeraComposerSaveRequest) async throws -> TeraComposerSaveReceipt
     39   func loadComposer(scope: TeraComposerScope, id: String) async throws -> TeraComposerDraft
     40   func listComposers(scope: TeraComposerScope, limit: UInt16, cursor: String?) async throws -> TeraComposerPage
     41   func legacyDraftPage(limit: UInt16, cursor: String?) async throws -> TeraLegacyDraftPage
     42   func snapshot() async throws -> TeraRuntimeSnapshot
     43   func todayPage(request: TeraTodayPageRequest) async throws -> TeraTodayPage
     44   func reconcileToday(request: TeraTodayReconcileRequest) async throws -> TeraTodayPage
     45   func refreshToday(
     46     context: TeraLocalNetwork,
     47     nowUnixSeconds: UInt64,
     48     update: TeraTodayProjectionUpdate,
     49     backfillCursor: String?
     50   ) async throws -> TeraTodaySyncReceipt
     51   func search(
     52     context: TeraLocalNetwork,
     53     query: String,
     54     limit: UInt16,
     55     asOfUnixSeconds: UInt64
     56   ) async throws -> [TeraSearchResult]
     57   func me(
     58     context: TeraLocalNetwork,
     59     asOfUnixSeconds: UInt64
     60   ) async throws -> TeraMeSnapshot
     61   func retrieveMedia(
     62     context: TeraLocalNetwork,
     63     reference: TeraMediaReference
     64   ) async throws -> TeraVerifiedMediaArtifact
     65   func verifiedMediaArtifact(
     66     context: TeraLocalNetwork,
     67     artifactID: String
     68   ) async throws -> TeraVerifiedMediaArtifact?
     69   func invalidateMediaArtifact(
     70     context: TeraLocalNetwork,
     71     artifactID: String
     72   ) async throws -> Bool
     73   func addSchemas() async throws -> [TeraAddSchema]
     74   func saveAddIntent(
     75     input: TeraAddRuntimeInput,
     76     existingDraftID: String?,
     77     expectedRevision: UInt64?
     78   ) async throws -> TeraDraftStatus
     79   func saveRetractionDraft(
     80     id: String,
     81     input: TeraRetractionDraftInput,
     82     authoredAtUnixSeconds: UInt64,
     83     persistedAtUnixMilliseconds: UInt64
     84   ) async throws -> TeraDraftStatus
     85   func saveRevisionIntent(
     86     requestID: String,
     87     target: TeraRevisionTarget,
     88     replacement: TeraAddRuntimeInput
     89   ) async throws -> TeraRevisionStatus
     90   func revisionSourceForm(card: TeraTodayCard, sourceDraftID: String) async throws -> TeraAddForm
     91   func revisionStatus(operationID: String) async throws -> TeraRevisionStatus
     92   func advanceRevision(operationID: String) async throws -> TeraRevisionStatus
     93   func cancelRevision(operationID: String) async throws -> TeraRevisionStatus
     94   func draftStatus(id: String) async throws -> TeraDraftStatus
     95   func draftHeads(limit: UInt16) async throws -> [TeraDraftStatus]
     96   func queueAddIntent(
     97     id: String,
     98     expectedRevision: UInt64
     99   ) async throws -> TeraDraftStatus
    100   func recoverAddIntent(id: String) async throws -> TeraDraftStatus
    101   func uploadAddMediaIntent(input: TeraBlossomUploadIntent) async throws -> TeraDraftStatus
    102   func prepareAddMediaBackground(
    103     input: TeraBlossomUploadIntent
    104   ) async throws -> TeraNativeUploadJob
    105   func completeAddMediaBackground(
    106     input: TeraNativeUploadCompletion
    107   ) async throws -> TeraDraftStatus
    108   func probeBlossom() async throws -> TeraBlossomEvidence
    109   func mobileSettings() async throws -> TeraMobileSettings
    110   func replaceMobileSettings(
    111     input: TeraReplaceSettings
    112   ) async throws -> TeraSettingsTransition
    113   func applyIdentityCommand(
    114     expectedRevision: UInt64,
    115     command: TeraIdentityCommand
    116   ) async throws -> TeraSettingsTransition
    117   func saveProfileMetadata(input: TeraProfileMetadataInput) async throws
    118     -> TeraProfileStatus
    119   func profileStatus(operationID: String) async throws -> TeraProfileStatus
    120   func advanceProfile(operationID: String) async throws -> TeraProfileStatus
    121   func cancelProfile(operationID: String, expectedRevision: UInt64) async throws
    122     -> TeraProfileStatus
    123   func advanceDraft(id: String, expectedRevision: UInt64) async throws -> TeraDraftStatus
    124   func cancelAddIntent(
    125     id: String,
    126     expectedRevision: UInt64
    127   ) async throws -> TeraDraftStatus
    128   func subscribe(
    129     bufferCapacity: Int,
    130     receive: @escaping @Sendable (TeraRuntimeChange) async -> Void
    131   ) async throws -> any TeraRuntimeSubscriptionToken
    132   func shutdown() async throws -> TeraRuntimeShutdownReceipt
    133 }
    134 
    135 extension TeraRuntimeBackend {
    136   func prepareRetractionForKeyRemoval(_: TeraKeyRemovalRequest) async throws {
    137     throw addUnsupported()
    138   }
    139 
    140   func legacyDraftPage(limit _: UInt16, cursor _: String?) async throws -> TeraLegacyDraftPage {
    141     throw addUnsupported()
    142   }
    143 
    144   func reserveComposerID() async throws -> String {
    145     throw addUnsupported()
    146   }
    147 
    148   func saveComposer(request _: TeraComposerSaveRequest) async throws -> TeraComposerSaveReceipt {
    149     throw addUnsupported()
    150   }
    151 
    152   func loadComposer(scope _: TeraComposerScope, id _: String) async throws -> TeraComposerDraft {
    153     throw addUnsupported()
    154   }
    155 
    156   func listComposers(scope _: TeraComposerScope, limit _: UInt16, cursor _: String?) async throws -> TeraComposerPage {
    157     throw addUnsupported()
    158   }
    159 
    160   func reconcileToday(request _: TeraTodayReconcileRequest) async throws -> TeraTodayPage {
    161     throw supportUnsupported()
    162   }
    163 
    164   private func supportUnsupported() -> TeraRuntimeFailure {
    165     .local(
    166       operation: "runtime.support",
    167       code: "ios.support.unsupported",
    168       safeMessage: "This supporting surface is unavailable in the current runtime."
    169     )
    170   }
    171 
    172   private func addUnsupported() -> TeraRuntimeFailure {
    173     .local(
    174       operation: "runtime.add",
    175       code: "ios.add.unsupported",
    176       safeMessage: "Add is unavailable in this runtime."
    177     )
    178   }
    179 
    180   func addSchemas() async throws -> [TeraAddSchema] {
    181     throw addUnsupported()
    182   }
    183 
    184   func saveAddIntent(
    185     input _: TeraAddRuntimeInput,
    186     existingDraftID _: String?,
    187     expectedRevision _: UInt64?
    188   ) async throws -> TeraDraftStatus {
    189     throw addUnsupported()
    190   }
    191 
    192   func saveRetractionDraft(
    193     id _: String,
    194     input _: TeraRetractionDraftInput,
    195     authoredAtUnixSeconds _: UInt64,
    196     persistedAtUnixMilliseconds _: UInt64
    197   ) async throws -> TeraDraftStatus {
    198     throw addUnsupported()
    199   }
    200 
    201   func saveRevisionIntent(
    202     requestID _: String,
    203     target _: TeraRevisionTarget,
    204     replacement _: TeraAddRuntimeInput
    205   ) async throws -> TeraRevisionStatus {
    206     throw addUnsupported()
    207   }
    208 
    209   func revisionSourceForm(card _: TeraTodayCard, sourceDraftID _: String) async throws -> TeraAddForm {
    210     throw addUnsupported()
    211   }
    212 
    213   func revisionStatus(operationID _: String) async throws -> TeraRevisionStatus {
    214     throw addUnsupported()
    215   }
    216 
    217   func advanceRevision(operationID _: String) async throws -> TeraRevisionStatus {
    218     throw addUnsupported()
    219   }
    220 
    221   func cancelRevision(operationID _: String) async throws -> TeraRevisionStatus {
    222     throw addUnsupported()
    223   }
    224 
    225   func draftStatus(id _: String) async throws -> TeraDraftStatus {
    226     throw addUnsupported()
    227   }
    228 
    229   func draftHeads(limit _: UInt16) async throws -> [TeraDraftStatus] {
    230     throw addUnsupported()
    231   }
    232 
    233   func queueAddIntent(
    234     id _: String,
    235     expectedRevision _: UInt64
    236   ) async throws -> TeraDraftStatus {
    237     throw addUnsupported()
    238   }
    239 
    240   func recoverAddIntent(id _: String) async throws -> TeraDraftStatus {
    241     throw addUnsupported()
    242   }
    243 
    244   func uploadAddMediaIntent(input _: TeraBlossomUploadIntent) async throws
    245     -> TeraDraftStatus
    246   {
    247     throw addUnsupported()
    248   }
    249 
    250   func prepareAddMediaBackground(
    251     input _: TeraBlossomUploadIntent
    252   ) async throws -> TeraNativeUploadJob {
    253     throw addUnsupported()
    254   }
    255 
    256   func completeAddMediaBackground(
    257     input _: TeraNativeUploadCompletion
    258   ) async throws -> TeraDraftStatus {
    259     throw addUnsupported()
    260   }
    261 
    262   func probeBlossom() async throws -> TeraBlossomEvidence {
    263     throw supportUnsupported()
    264   }
    265 
    266   func mobileSettings() async throws -> TeraMobileSettings {
    267     throw supportUnsupported()
    268   }
    269 
    270   func replaceMobileSettings(
    271     input _: TeraReplaceSettings
    272   ) async throws -> TeraSettingsTransition {
    273     throw supportUnsupported()
    274   }
    275 
    276   func applyIdentityCommand(
    277     expectedRevision _: UInt64,
    278     command _: TeraIdentityCommand
    279   ) async throws -> TeraSettingsTransition {
    280     throw supportUnsupported()
    281   }
    282 
    283   func saveProfileMetadata(input _: TeraProfileMetadataInput) async throws
    284     -> TeraProfileStatus
    285   {
    286     throw supportUnsupported()
    287   }
    288 
    289   func profileStatus(operationID _: String) async throws -> TeraProfileStatus {
    290     throw supportUnsupported()
    291   }
    292 
    293   func advanceProfile(operationID _: String) async throws -> TeraProfileStatus {
    294     throw supportUnsupported()
    295   }
    296 
    297   func cancelProfile(operationID _: String, expectedRevision _: UInt64) async throws
    298     -> TeraProfileStatus
    299   {
    300     throw supportUnsupported()
    301   }
    302 
    303   func advanceDraft(id _: String, expectedRevision _: UInt64) async throws -> TeraDraftStatus {
    304     throw addUnsupported()
    305   }
    306 
    307   func cancelAddIntent(
    308     id _: String,
    309     expectedRevision _: UInt64
    310   ) async throws -> TeraDraftStatus {
    311     throw addUnsupported()
    312   }
    313 
    314   func search(
    315     context _: TeraLocalNetwork,
    316     query _: String,
    317     limit _: UInt16,
    318     asOfUnixSeconds _: UInt64
    319   ) async throws -> [TeraSearchResult] {
    320     throw supportUnsupported()
    321   }
    322 
    323   func me(
    324     context _: TeraLocalNetwork,
    325     asOfUnixSeconds _: UInt64
    326   ) async throws -> TeraMeSnapshot {
    327     throw supportUnsupported()
    328   }
    329 
    330   func retrieveMedia(
    331     context _: TeraLocalNetwork,
    332     reference _: TeraMediaReference
    333   ) async throws -> TeraVerifiedMediaArtifact {
    334     throw supportUnsupported()
    335   }
    336 
    337   func verifiedMediaArtifact(
    338     context _: TeraLocalNetwork,
    339     artifactID _: String
    340   ) async throws -> TeraVerifiedMediaArtifact? {
    341     throw supportUnsupported()
    342   }
    343 
    344   func invalidateMediaArtifact(
    345     context _: TeraLocalNetwork,
    346     artifactID _: String
    347   ) async throws -> Bool {
    348     throw supportUnsupported()
    349   }
    350 }
    351 
    352 struct TeraRuntimeBackendStart: Sendable {
    353   let backend: any TeraRuntimeBackend
    354   let snapshot: TeraRuntimeSnapshot
    355 }
    356 
    357 typealias TeraRuntimeBackendFactory =
    358   @Sendable (
    359     TeraRuntimeLaunchConfiguration
    360   ) async throws -> TeraRuntimeBackendStart