Cotton code
40 lines · 1.5 KB · SwiftRaw
// What the root publishes for the converted tools (`RootView`): the record// verbs, the table definitions and the titles a link column shows.// The shipping root's are the core's (`AppTables.core`); the fixtures are for// tests and previews only.import CottonValuesimport Foundationimport SwiftUIpublic struct AppTables: Sendable {    public let records: any Records    public let definitions: TableDefinitions    public let linkTitles: LinkTitles    /// The root's tables: every verb through the core (`CoreRecords`), the    /// shipped built-ins until the catalogue of imported tools answers (the    /// root reads the definitions again then). Link titles start empty: a list and a page    /// resolve the titles of the rows they read (`Records.linkTitles(for:)`).    @MainActor    public static func core(_ records: CoreRecords, writer: ScreenWriter) -> AppTables {        AppTables(            records: records,            // What the store last read, until the database's own catalogue is read.            definitions: TableDefinitions(records.knownDefinitions, read: false),            linkTitles: LinkTitles())    }}extension LinkTitles {    /// Every record's title by id, for link columns.    public init(_ definitions: [TableDefinition], _ records: [String: [TableRecord]]) {        var titles: [String: String] = [:]        for definition in definitions {            for record in records[definition.id] ?? [] {                titles[record.id] = record.said?.slip.name            }        }        self.init(titles)    }}