Cotton code
37 lines · 1.8 KB · SwiftRaw
// The one seam a change id travels through to be taken back: the generic verb// `undo(change_id)` (shared format, "Generic verbs"; cotton-core defines it in// the generic-records work, #1257). A `Records` conformer that serves definition// tables answers `undo(change:)` by sending the change's id here and nowhere// else — it never re-writes `before` itself, because the core decides what// putting a change back means (a later edit to the same field refuses it).//// Two answer it: `CoreRecords` (the root's, `records.undo` over cotton-ffi)// and `FixtureRecords` (in memory, for tests and previews only). NO SILENT FALLBACK: a build whose core does not answer the// verb says so (`answersUndo` false), every change it mints is `undoable:// false`, and its receipt offers no Undo rather than pretending one.//// The Settings tables are not served here: their rows are an engine's, written// by its own methods (`SettingsRecords`), so their change ids are minted in the// app and taken back by the inverse method — the core has never seen them.import Foundationpublic protocol GenericVerbs: Sendable {    /// Whether this build answers `undo(change_id)` at all. False: nothing is    /// offered for undo.    var answersUndo: Bool { get }    /// Takes back the change named by `changeId`; answers the undoing change    /// (itself undoable only when the core says so).    func undo(changeId: String) async throws -> ChangeRecord}public enum GenericVerbsError: Error, Equatable, Sendable {    /// This build's core does not answer the verb.    case absent(verb: String)}/// The words a receipt prints when no Undo is offered because the verb is not/// in this build.enum GenericVerbsWords {    static var undoAbsent: String { ShellLines.line("definitions", "refused.no_undo") }}