Cotton code
744 lines · 19.2 KB · JSONRaw
{  "format_version": 1,  "id": "note",  "name": "Note",  "plural": "Notes",  "visibility": "owner",  "title": "title",  "columns": [    {      "key": "kind",      "name": "Kind",      "type": "choice",      "choices": [        "note",        "journal"      ],      "default": "note",      "readonly": true    },    {      "key": "title",      "name": "Title",      "type": "text",      "placeholder": "Title"    },    {      "key": "body",      "name": "Body",      "type": "longtext",      "placeholder": "Start writing…"    },    {      "key": "journal_date",      "name": "Journal date",      "type": "text",      "readonly": true    },    {      "key": "project",      "name": "Project",      "type": "link",      "link_to": "project"    },    {      "key": "author_kind",      "name": "Author kind",      "type": "choice",      "choices": [        "user",        "agent"      ],      "default": "user",      "readonly": true    },    {      "key": "author_label",      "name": "Author label",      "type": "text",      "readonly": true    },    {      "key": "managed_by",      "type": "text",      "readonly": true,      "name": "Kept in step with"    },    {      "key": "external_id",      "name": "External id",      "type": "text",      "readonly": true    },    {      "key": "pinned",      "type": "bool",      "default": false,      "readonly": true,      "name": "Pinned"    },    {      "key": "archived_at",      "type": "date",      "name": "Archived"    },    {      "key": "trashed_at",      "name": "Trashed at",      "type": "text",      "readonly": true    },    {      "key": "project_id",      "name": "Project",      "type": "link",      "link_to": "project"    },    {      "key": "updated_at",      "name": "Edited",      "type": "date",      "readonly": true,      "format": "ago"    },    {      "key": "words",      "name": "Words",      "type": "number",      "readonly": true,      "units": {        "one": "word",        "other": "words",        "zero": ""      }    },    {      "key": "published_at",      "name": "Published",      "type": "date",      "readonly": true    },    {      "key": "people",      "name": "People",      "type": "link",      "link_to": "person",      "readonly": true,      "multiple": true,      "edges": true    }  ],  "instructions": "A note is free-form writing in markdown with an optional title; when the title is empty the first line of the body stands in. Keep the person's words as they wrote them, and add to a note rather than rewriting it unless asked. A note can belong to one project directly and to more through project links.",  "tables": [    {      "name": "cotton_notes",      "columns": [        {          "name": "id",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": true,          "declaration": "\n    id TEXT PRIMARY KEY",          "position": 0        },        {          "name": "kind",          "type": "TEXT",          "default": "'note'",          "nullable": false,          "primary_key": false,          "declaration": "\n    kind TEXT NOT NULL DEFAULT 'note'",          "position": 1        },        {          "name": "title",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    title TEXT",          "position": 2        },        {          "name": "body",          "type": "TEXT",          "default": "''",          "nullable": false,          "primary_key": false,          "declaration": "\n    body TEXT NOT NULL DEFAULT ''",          "position": 3        },        {          "name": "journal_date",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    journal_date TEXT",          "position": 4        },        {          "name": "project_id",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    project_id TEXT",          "position": 5        },        {          "name": "published_at",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    published_at TEXT",          "position": 6        },        {          "name": "public_slug",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    public_slug TEXT",          "position": 7        },        {          "name": "source_inbox_id",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    source_inbox_id TEXT",          "position": 8        },        {          "name": "created_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    created_at TEXT NOT NULL",          "position": 9        },        {          "name": "updated_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    updated_at TEXT NOT NULL",          "position": 10        },        {          "name": "archived_at",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    archived_at TEXT",          "position": 11        },        {          "name": "trashed_at",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    trashed_at TEXT",          "position": 12        },        {          "name": "author_kind",          "type": "TEXT",          "default": "'user'",          "nullable": false,          "primary_key": false,          "declaration": "\n    author_kind TEXT NOT NULL DEFAULT 'user'",          "position": 13        },        {          "name": "author_label",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    author_label TEXT",          "position": 14        },        {          "name": "managed_by",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    managed_by TEXT",          "position": 15        },        {          "name": "external_id",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    external_id TEXT",          "position": 16        },        {          "name": "source_hash",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    source_hash TEXT",          "position": 17        },        {          "name": "workspace_id",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    workspace_id TEXT NOT NULL",          "position": 18        },        {          "name": "_hlc",          "type": "TEXT",          "default": "''",          "nullable": false,          "primary_key": false,          "declaration": "\n    _hlc TEXT NOT NULL DEFAULT ''",          "position": 19        },        {          "name": "origin_handle",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": " origin_handle TEXT CHECK (origin_handle IS NULL OR length(origin_handle) > 0)",          "position": 20        },        {          "name": "_born",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    _born TEXT",          "position": 21        },        {          "name": "pinned",          "type": "INTEGER",          "default": "0",          "nullable": false,          "primary_key": false,          "declaration": "\n    pinned INTEGER NOT NULL DEFAULT 0 CHECK (pinned IN (0, 1))",          "position": 22        }      ],      "constraints": [        {          "declaration": "\n    CHECK (author_kind IN ('user', 'agent'))",          "position": 23        },        {          "declaration": "\n    CHECK ((author_kind = 'agent') = (author_label IS NOT NULL))",          "position": 24        },        {          "declaration": "\n    CHECK (kind IN ('note', 'journal'))",          "position": 25        },        {          "declaration": "\n    FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n  ",          "position": 26        }      ],      "prefix": "CREATE TABLE cotton_notes (",      "suffix": ")",      "indexes": [        "CREATE INDEX idx_cotton_notes_home ON cotton_notes (workspace_id) WHERE kind = 'note' AND managed_by IS NULL AND archived_at IS NULL AND trashed_at IS NULL",        "CREATE INDEX idx_cotton_notes_managed ON cotton_notes (managed_by) WHERE managed_by IS NOT NULL",        "CREATE INDEX idx_cotton_notes_workspace ON cotton_notes (workspace_id)",        "CREATE UNIQUE INDEX idx_cotton_notes_workspace_external ON cotton_notes (workspace_id, external_id) WHERE external_id IS NOT NULL",        "CREATE UNIQUE INDEX uq_cotton_notes_public_slug ON cotton_notes (public_slug) WHERE public_slug IS NOT NULL",        "CREATE UNIQUE INDEX uq_cotton_notes_journal_day ON cotton_notes (workspace_id, journal_date, COALESCE(project_id, '')) WHERE kind = 'journal'",        "CREATE INDEX idx_cotton_notes_origin ON cotton_notes (origin_handle) WHERE origin_handle IS NOT NULL",        "CREATE INDEX IF NOT EXISTS idx_cotton_notes_author ON cotton_notes (substr(_hlc, 20), _hlc)"      ],      "full_text": [        "CREATE VIRTUAL TABLE fts_notes USING fts5(\n       title, body, content = 'cotton_notes', content_rowid = 'rowid',\n       tokenize = 'unicode61 remove_diacritics 2'\n     )"      ],      "triggers": [        "CREATE TRIGGER fts_notes_ai AFTER INSERT ON cotton_notes WHEN new.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_notes'), 0) BEGIN\n       INSERT INTO fts_notes (rowid, title, body) VALUES (new.rowid, new.title, new.body);\n     END",        "CREATE TRIGGER fts_notes_ad AFTER DELETE ON cotton_notes WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_notes'), 0) BEGIN\n       INSERT INTO fts_notes (fts_notes, rowid, title, body) VALUES ('delete', old.rowid, old.title, old.body);\n     END",        "CREATE TRIGGER fts_notes_au AFTER UPDATE OF title, body ON cotton_notes\n       FOR EACH ROW WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_notes'), 0) AND (new.title IS NOT old.title OR new.body IS NOT old.body) BEGIN\n       INSERT INTO fts_notes (fts_notes, rowid, title, body) VALUES ('delete', old.rowid, old.title, old.body);\n       INSERT INTO fts_notes (rowid, title, body) VALUES (new.rowid, new.title, new.body);\n     END"      ]    },    {      "name": "cotton_note_attachments",      "columns": [        {          "name": "id",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": true,          "declaration": "\n    id TEXT PRIMARY KEY",          "position": 0        },        {          "name": "workspace_id",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    workspace_id TEXT NOT NULL",          "position": 1        },        {          "name": "note_id",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    note_id TEXT NOT NULL",          "position": 2        },        {          "name": "record_kind",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    record_kind TEXT NOT NULL",          "position": 3        },        {          "name": "record_id",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    record_id TEXT NOT NULL",          "position": 4        },        {          "name": "position",          "type": "INTEGER",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    position INTEGER NOT NULL",          "position": 5        },        {          "name": "caption",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    caption TEXT",          "position": 6        },        {          "name": "created_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    created_at TEXT NOT NULL",          "position": 7        },        {          "name": "updated_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    updated_at TEXT NOT NULL",          "position": 8        },        {          "name": "origin_handle",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    origin_handle TEXT CHECK (origin_handle IS NULL OR length(origin_handle) > 0)",          "position": 9        },        {          "name": "_hlc",          "type": "TEXT",          "default": "''",          "nullable": false,          "primary_key": false,          "declaration": "\n    _hlc TEXT NOT NULL DEFAULT ''",          "position": 10        },        {          "name": "_born",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    _born TEXT",          "position": 11        }      ],      "constraints": [        {          "declaration": "\n    UNIQUE (note_id, record_kind, record_id)",          "position": 12        },        {          "declaration": "\n    CHECK (record_kind IN ('photo', 'video', 'document'))",          "position": 13        },        {          "declaration": "\n    CHECK (length(record_id) > 0)",          "position": 14        },        {          "declaration": "\n    CHECK (position >= 0)",          "position": 15        },        {          "declaration": "\n    CHECK (caption IS NULL OR length(caption) <= 500)",          "position": 16        },        {          "declaration": "\n    FOREIGN KEY (note_id) REFERENCES cotton_notes(id)",          "position": 17        },        {          "declaration": "\n    FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n  ",          "position": 18        }      ],      "prefix": "CREATE TABLE IF NOT EXISTS cotton_note_attachments (",      "suffix": ")",      "indexes": [        "CREATE INDEX IF NOT EXISTS idx_cotton_note_attachments_author ON cotton_note_attachments (substr(_hlc, 20), _hlc)",        "CREATE INDEX IF NOT EXISTS idx_cotton_note_attachments_note ON cotton_note_attachments (note_id, position)"      ],      "full_text": [],      "triggers": []    }  ],  "card": {    "face": "note.page",    "fields": [      {        "slot": "title",        "column": "title"      },      {        "slot": "date",        "column": "updated_at",        "form": "weekday_date"      },      {        "slot": "body",        "column": "body"      }    ],    "offers": [      "note.page",      "note"    ]  },  "picture": {    "photo": "photo:c5eb8f1ca78553c5419f520da4fd600be292251b4211ff367b203f8a920620e7",    "object": "tool-notes"  },  "builtin": true,  "engine": "notes",  "date": "updated_at",  "project": "project_id",  "order": null,  "slip": {    "title": "title",    "subtitle": "body",    "trailing": "updated_at",    "photo": null,    "toggle": null,    "title_fallback": "body",    "dye": "cream"  },  "tile": {    "face": "slip-list",    "current": {      "column": "updated_at",      "days": 7    }  },  "page": [    {      "heading": null,      "columns": [        "updated_at",        "body"      ]    },    {      "heading": "Details",      "columns": [        "project_id"      ]    }  ],  "archived": "archived_at",  "readonly_when": "managed_by",  "kept_by": {    "when": "managed_by",    "says": "Kept by your assistant"  },  "record_route": "/notes/note/[id]",  "linked_when": {    "made": "written {when}"  },  "record_kind": "note",  "pins": true,  "filing_rank": 2,  "made_by_verb": true,  "role": "note",  "projects_read": {    "kind": "note",    "read": "record",    "families": [      "core",      "projects"    ]  },  "sort": {    "column": "updated_at",    "descending": true  },  "by_month": "updated_at",  "empty": {    "title": "No notes yet"  },  "create": {    "label": "New note"  },  "deletion": {    "bin": true  },  "links": [    {      "label": "Deleted",      "table": "bin",      "where": {        "table": "note"      }    }  ],  "commands": [    {      "id": "pin",      "label": "Pin",      "kind": "update",      "verb": "update_note",      "data": {        "pinned": true      },      "bindings": {        "id": "$id"      },      "when": {        "pinned": false      },      "receipt": "Pinned",      "undo": "unpin",      "object": "pushpin"    },    {      "id": "unpin",      "label": "Unpin",      "kind": "update",      "verb": "update_note",      "data": {        "pinned": false      },      "bindings": {        "id": "$id"      },      "when": {        "pinned": true      },      "receipt": "Unpinned",      "undo": "pin",      "object": "pushpin"    },    {      "id": "delete",      "label": "Delete",      "kind": "delete",      "verb": "delete_record",      "data": {        "table": "note"      },      "confirm": "It can come back from Deleted, and Undo on the receipt brings it back now.",      "bindings": {        "id": "$id"      },      "receipt": "Deleted",      "does": "destroys"    }  ],  "groups": {    "stack": "slips"  },  "tool": {    "views": [      {        "id": "all",        "label": "All",        "visibility": "owner",        "is_default": true,        "read": {          "table": "note"        }      }    ],    "name": "Notes",    "purpose": "Notes and ideas you want to keep.",    "key": "notes",    "icon": "notebook-text",    "card_stock": "cream",    "route": "/notes",    "figures": [      {        "read": "notes",        "one": "1 note",        "many": "{n} notes"      }    ]  },  "parts": {    "shape": "desk",    "head": {      "facts": [        "updated_at"      ]    },    "links": [],    "body": "body",    "lists": [],    "acts": {      "more": [        "pin",        "unpin"      ],      "away": "delete"    },    "strip": []  }}