// What a write answers — the change, its receipt, the command it was and what// it opened — over the records `CottonValues/TableRecord.swift` holds.importCottonKitimportCottonValuesimportFoundation/// What every write answers: the change the app shows with its byline and can/// undo. `before` is nil for a create, `after` nil for a delete.////// `undoable` and `reason` are the core's own words on the change (cotton-core's/// change JSON carries `undoable` and `reason`): whoever minted the change says/// whether `undo(change_id)` can take it back, so a receipt never offers an/// Undo the verbs would refuse — or one this build cannot send at all.publicstructChangeRecord: Hashable, Sendable, Identifiable {publicvar id: Stringpublicvar byline: Stringpublicvar before: TableRecord?publicvar after: TableRecord?/// The record this one was folded into by the write (`moved_to`): a/// person merged into the other side of "Same as …?" lives on as that/// record, and the page that showed it shows that record's page instead./// Nil for every other write.publicvar movedTo: RecordRef?/// Whether the verbs can take this change back.publicvar undoable: Bool/// Why not, in words, when `undoable` is false.publicvar reason: String?/// What happened, in the core's words (`change.receipt`): the receipt/// prints these and composes none of its own. Nil from a store that/// answers none (the fixtures, Settings' own tables).publicvar said: ChangeSaid?/// The command this change was (`records.command`): its Undo is the/// command the definition names, run on the same record.publicvar command: CommandTaken?/// What an `open` command answered: the record or the address to open./// Such a change changed nothing and wears no receipt.publicvar opened: CommandOpened?/// The record a create command wrote, alongside its durable receipt and Undo.publicvar created: RecordLink?/// A change only this device's memory holds — a field of a draft nothing/// has written yet. It wears no receipt: there is nothing to report or undo.publicvar quiet = false/// The core saved an intent whose serving Mac has not confirmed it yet./// It cannot dismiss a record or announce a completed change.publicvar pending = falsepublicinit( id: String, byline: String, before: TableRecord?, after: TableRecord?, movedTo: RecordRef? = nil, undoable: Bool = true, reason: String? = nil, said: ChangeSaid? = nil, command: CommandTaken? = nil, opened: CommandOpened? = nil ) {self.said = saidself.command = commandself.opened = openedself.id = idself.byline = bylineself.before = beforeself.after = afterself.movedTo = movedToself.undoable = undoableself.reason = reason }}/// The core's receipt for a change: a verb and the record's name ("Added Call/// the plumber", "Pinned"), and a before and after only for words.publicstructChangeSaid: Hashable, Sendable, Decodable {publicstructWords: Hashable, Sendable, Decodable {publicvar name: Stringpublicvar before: String?publicvar after: String? }/// added, appended, deleted, put_back, archived, switched, edited,/// changed, reordered — or `command` for a command's own words.publicvar kind: Stringpublicvar said: Stringpublicvar words: [Words]publicinit(kind: String, said: String, words: [Words] = []) {self.kind = kindself.said = saidself.words = words }privateenumCodingKeys: String, CodingKey { case kind, said, words }publicinit(from decoder: Decoder) throws {let c = try decoder.container(keyedBy: CodingKeys.self) kind = try c.decode(String.self, forKey: .kind) said = try c.decode(String.self, forKey: .said) words = try c.decodeIfPresent([Words].self, forKey: .words) ?? [] }}/// A command that ran on one record, and what takes it back: a command of/// its table (`undo`), or — when the app method it ran answered its own way/// back — that same method with what was there before (`undoCall`).publicstructCommandTaken: Hashable, Sendable {publicvar table: Stringpublicvar record: Stringpublicvar undo: String?publicvar undoCall: CommandUndoCall?publicinit(table: String, record: String, undo: String?, undoCall: CommandUndoCall? = nil) {self.table = tableself.record = recordself.undo = undoself.undoCall = undoCall }}/// An app method's own way back (`records.command`'s `undo_call`): the same/// method, with the arguments that put back what it changed. The core checks/// it is the command's own method; the app only sends it back.publicstructCommandUndoCall: Hashable, Sendable {publicvar method: String/// The arguments, as the JSON the core answered.publicvar args: Stringpublicinit(method: String, args: String) {self.method = methodself.args = args }}/// What an `open` command opens: a link's record, or a url column's address.publicenumCommandOpened: Hashable, Sendable {case record(RecordLink)/// A record the act made at the object (`RecordCommand.lands`), coming by/// sync: stood on once it is here (an article's Fetch, its download).case landed(RecordLink)case address(String)case platform(RecordPlatformAction)/// A database to show (`shows_database`): a restored one, its cap back/// on the arc — the page it was restored from closes onto it.case database(String)}/// One record of one table, by id.publicstructRecordRef: Hashable, Sendable, Codable {publicvar table: Stringpublicvar id: Stringpublicinit(table: String, id: String) {self.table = tableself.id = id }}extension JSONValue {/// A stamp of any read as the core resolved it (`page::attach_stamp_parts`/// puts `@day_parts` beside the stamps), or nil.publicfunc day(_ key: String) -> DayParts? {guardlet parts = self["@day_parts"]?[key] else { returnnil }returnDayParts(RecordValue(parts)) }}