Cotton code
32 lines · 1.5 KB · SwiftRaw
// The shell's lines as the core resolves them (`shell.lines`), and a line said// one way on a phone and another on a Mac. The lines themselves — the kit's// bundled snapshot and the sets the core last sent — are CottonValues'// (`ShellLines`), so a face says them with no core; what needs the core or// the host is here.// Every module over CottonKit reads the plain values (`ShellLines`, the card,// a record) as its own, as it did when they lived here.@_exported import CottonValuesimport Foundationextension ShellLines {    /// A line said one way on a phone and another on a Mac: `path.phone` /    /// `path.mac`.    public static func onThisHost(_ set: String, _ path: String, _ fills: [String: String] = [:]) -> String {        HostNoun.sentence(phone: line(set, "\(path).phone", fills), mac: line(set, "\(path).mac", fills))    }    /// Read every set the database's core ships, in one call (`shell.lines`    /// with no set named answers them all). A core that refuses (an older    /// one, no file open yet) leaves the kit's words standing.    public static func refresh(_ core: any CottonCalling) async {        guard            let raw = try? await core.callRaw(CottonMethod.shellLines, requestJSON: "{}"),            let envelope = (try? JSONSerialization.jsonObject(with: Data(raw.utf8))) as? [String: Any],            envelope["ok"] as? Bool == true,            let data = envelope["data"] as? [String: Any],            let sets = data["sets"] as? [String: Any]        else { return }        receive(sets)    }}