field_ios

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

TeraRuntimeClientComposer.swift (1440B)


      1 import Foundation
      2 
      3 extension TeraRuntimeClient {
      4   func reserveComposerID() async throws -> String {
      5     try await addOperation("runtime.composer.reserve") { backend in
      6       try await backend.reserveComposerID()
      7     }
      8   }
      9 
     10   func saveComposer(request: TeraComposerSaveRequest) async throws -> TeraComposerSaveReceipt {
     11     try await addOperation("runtime.composer.save") { backend in
     12       try await backend.saveComposer(request: request)
     13     }
     14   }
     15 
     16   func loadComposer(scope: TeraComposerScope, id: String) async throws -> TeraComposerDraft {
     17     try await addOperation("runtime.composer.load") { backend in
     18       try await backend.loadComposer(scope: scope, id: id)
     19     }
     20   }
     21 
     22   func listComposers(scope: TeraComposerScope, limit: UInt16 = 100, cursor: String? = nil) async throws -> TeraComposerPage {
     23     try await addOperation("runtime.composer.list") { backend in
     24       try await backend.listComposers(scope: scope, limit: limit, cursor: cursor)
     25     }
     26   }
     27 
     28   func addOperation<T: Sendable>(
     29     _ operation: String,
     30     submission: Bool = false,
     31     _ body: @escaping @Sendable (any TeraRuntimeBackend) async throws -> T
     32   ) async throws -> T {
     33     do {
     34       return try await runtimeOperation(operation, submission: submission, body)
     35     } catch let error as TeraRuntimeClientError {
     36       throw error
     37     } catch {
     38       throw TeraRuntimeClientError.add(
     39         Self.failure(from: error, operation: operation)
     40       )
     41     }
     42   }
     43 }