Cotton code
62 lines · 2.3 KB · SwiftRaw
import Foundation// A screen's board, through the boundary: read off the database's catalogue// (`definitions.catalogue`, `DefinitionCatalogues`) and// `definitions.passedOver` filed (design note 26203e21 §4, §8). The row is// handed over as its JSON, because what a board MEANS — its closed set of// parts — is CottonUI's `DefinitionCatalogue.board`, and this side only carries it./// The board a screen draws, as the core answered it.public struct DrawnBoard: Sendable, Equatable {    /// The board, as JSON — the person's own row, or the shipped default.    public let definition: Data    /// Why a row stored for the screen was not drawn.    public let passedOver: String?    public init(definition: Data, passedOver: String? = nil) {        self.definition = definition        self.passedOver = passedOver    }}public protocol BoardsCalling: Sendable {    /// The board the screen `id` draws ("home", "tools", "database").    func board(_ id: String) async throws -> DrawnBoard    /// A part of a kind this build does not draw, filed as ONE Feedback row    /// per database, board and part, ever. Answers whether a row was filed.    @discardableResult    func passedOver(board: String, part: String, databaseId: String, databaseName: String) async throws -> Bool}/// The core's own answers.public struct CoreBoards: BoardsCalling {    private let core: any CottonCalling    public init(core: any CottonCalling) {        self.core = core    }    public func board(_ id: String) async throws -> DrawnBoard {        guard let board = try await DefinitionCatalogues.shared.catalogue(core).boards[id] else {            throw CatalogueRefusal.malformed("there is no board \(id)")        }        return board    }    public func passedOver(board: String, part: String, databaseId: String, databaseName: String) async throws -> Bool {        let answer = try await core.call(            CottonMethod.definitionsPassedOver,            PassedOver(board: board, part: part, databaseId: databaseId, databaseName: databaseName),            as: Filed.self)        return answer.filed    }    private struct PassedOver: Encodable {        let board: String        let part: String        let databaseId: String        let databaseName: String    }    private struct Filed: Decodable { let filed: Bool }}