Cotton code
530 lines · 12.3 KB · JSONRaw
{  "format_version": 1,  "id": "news_edition",  "name": "News edition",  "plural": "News",  "builtin": true,  "visibility": "owner",  "date": "covered_to",  "title": "edition_label",  "columns": [    {      "key": "status",      "type": "choice",      "choices": [        "queued",        "harvesting",        "writing",        "ready",        "failed"      ],      "labels": {        "queued": "Queued",        "harvesting": "Harvesting",        "writing": "Writing",        "ready": "Ready",        "failed": "Failed"      },      "readonly": true,      "shown_when": {        "column": "status",        "values": [          "failed"        ]      }    },    {      "key": "trigger_kind",      "name": "Started by",      "type": "choice",      "choices": [        "scheduled",        "manual",        "stale_open"      ],      "readonly": true    },    {      "key": "edition_label",      "name": "Edition",      "type": "text",      "readonly": true    },    {      "key": "covered_from",      "name": "Covers from",      "type": "date",      "format": "calendar-datetime",      "readonly": true,      "fact": false,      "reading": "Covers {value}"    },    {      "key": "covered_to",      "name": "Covers to",      "type": "date",      "format": "calendar-datetime",      "readonly": true,      "fact": true,      "reading": "{value}"    },    {      "key": "story_count",      "name": "Stories",      "type": "number",      "readonly": true,      "units": {        "one": "story",        "other": "stories",        "zero": "0 stories"      }    },    {      "key": "read_minutes",      "name": "Minutes to read",      "type": "number",      "readonly": true,      "fact": true,      "reading": "{value} min read",      "units": {        "one": "minute",        "other": "minutes"      }    },    {      "key": "quiet",      "type": "longtext",      "readonly": true    },    {      "key": "notes",      "type": "longtext",      "readonly": true    },    {      "key": "model",      "type": "text",      "readonly": true    },    {      "key": "opened_at",      "name": "Opened",      "type": "date",      "readonly": true    },    {      "key": "status_changed_at",      "type": "date",      "format": "calendar-datetime",      "readonly": true    },    {      "key": "failed_stage",      "name": "Failed at",      "type": "choice",      "choices": [        "harvest",        "write"      ],      "readonly": true    },    {      "key": "error_code",      "name": "Problem",      "type": "text",      "readonly": true    },    {      "key": "state_message",      "type": "longtext",      "readonly": true    },    {      "key": "figure",      "type": "text",      "readonly": true    }  ],  "instructions": "A news edition is one written round-up of the news the owner follows, covering a span of time. Status runs from queued through harvesting and writing to ready, or failed at a named stage. Report stories as their sources gave them; the quiet list names topics with nothing new.",  "tables": [    {      "name": "cotton_news_editions",      "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": "status",          "type": "TEXT",          "default": "'queued'",          "nullable": false,          "primary_key": false,          "declaration": "\n    status TEXT NOT NULL DEFAULT 'queued'",          "position": 2        },        {          "name": "trigger_kind",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    trigger_kind TEXT NOT NULL",          "position": 3        },        {          "name": "edition_label",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    edition_label TEXT",          "position": 4        },        {          "name": "covered_from",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    covered_from TEXT NOT NULL",          "position": 5        },        {          "name": "covered_to",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    covered_to TEXT",          "position": 6        },        {          "name": "story_count",          "type": "INTEGER",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    story_count INTEGER",          "position": 7        },        {          "name": "read_minutes",          "type": "INTEGER",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    read_minutes INTEGER",          "position": 8        },        {          "name": "quiet",          "type": "TEXT",          "default": "'[]'",          "nullable": false,          "primary_key": false,          "declaration": "\n    quiet TEXT NOT NULL DEFAULT '[]'",          "position": 9        },        {          "name": "notes",          "type": "TEXT",          "default": "'[]'",          "nullable": false,          "primary_key": false,          "declaration": "\n    notes TEXT NOT NULL DEFAULT '[]'",          "position": 10        },        {          "name": "model",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    model TEXT",          "position": 11        },        {          "name": "opened_at",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    opened_at TEXT",          "position": 12        },        {          "name": "status_changed_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    status_changed_at TEXT NOT NULL",          "position": 13        },        {          "name": "failed_stage",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    failed_stage TEXT",          "position": 14        },        {          "name": "error_code",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    error_code TEXT",          "position": 15        },        {          "name": "created_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    created_at TEXT NOT NULL",          "position": 16        },        {          "name": "updated_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    updated_at TEXT NOT NULL",          "position": 17        },        {          "name": "_hlc",          "type": "TEXT",          "default": "''",          "nullable": false,          "primary_key": false,          "declaration": "\n    _hlc TEXT NOT NULL DEFAULT ''",          "position": 18        },        {          "name": "_born",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    _born TEXT",          "position": 19        }      ],      "constraints": [        {          "declaration": "\n    CHECK ((status = 'failed') = (failed_stage IS NOT NULL))",          "position": 20        },        {          "declaration": "\n    CHECK (failed_stage IS NULL OR failed_stage IN ('harvest', 'write'))",          "position": 21        },        {          "declaration": "\n    CHECK ((read_minutes IS NULL) OR (read_minutes >= 0))",          "position": 22        },        {          "declaration": "\n    CHECK (status IN ('queued', 'harvesting', 'writing', 'ready', 'failed'))",          "position": 23        },        {          "declaration": "\n    CHECK ((story_count IS NULL) OR (story_count >= 0))",          "position": 24        },        {          "declaration": "\n    CHECK (trigger_kind IN ('scheduled', 'manual', 'stale_open'))",          "position": 25        },        {          "declaration": "\n    FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n  ",          "position": 26        }      ],      "prefix": "CREATE TABLE cotton_news_editions (",      "suffix": ")",      "indexes": [        "CREATE INDEX idx_cotton_news_editions_pipeline ON cotton_news_editions (status, status_changed_at) WHERE status IN ('queued', 'harvesting', 'writing')",        "CREATE INDEX idx_cotton_news_editions_workspace_created ON cotton_news_editions (workspace_id, created_at DESC)",        "CREATE INDEX IF NOT EXISTS idx_cotton_news_editions_author ON cotton_news_editions (substr(_hlc, 20), _hlc)"      ],      "full_text": [],      "triggers": []    }  ],  "picture": {    "photo": "photo:54118bbc8327cc8d43e587bd19db1841feff49cc5220ae6ca7384167e9cb414e",    "object": "tool-news"  },  "engine": "news",  "project": null,  "order": null,  "slip": {    "title": "edition_label",    "subtitle": "covered_to",    "trailing": "figure",    "photo": null,    "toggle": null  },  "tile": {    "face": "slip-list"  },  "page": [    {      "heading": null,      "columns": [        "edition_label",        "covered_from",        "covered_to",        "story_count",        "read_minutes",        "status"      ]    },    {      "heading": "Stories",      "columns": [],      "list": {        "table": "news_story",        "link": "edition_id"      }    },    {      "heading": "Progress",      "columns": [        "state_message"      ]    },    {      "heading": "Edition notes",      "columns": [        "quiet",        "notes"      ]    }  ],  "page_parts": [    "title",    "facts",    "sections",    "grid"  ],  "record_route": "/news/edition/[id]",  "sort": {    "column": "covered_to",    "descending": true  },  "empty": {    "title": "No news yet.",    "message": "Add a topic, and Cotton writes your first edition at 7:00 in the morning."  },  "create": {    "label": "Add a topic",    "path": "/news/topic/new"  },  "delete": false,  "related": [    {      "label": "Topics",      "table": "news_topic",      "new": true    },    {      "label": "News settings",      "table": "news_settings"    }  ],  "commands": [    {      "id": "opened",      "label": "Mark read",      "kind": "update",      "verb": "mark_news_edition_opened",      "data": {},      "bindings": {        "id": "$id"      }    }  ],  "on_open": "opened",  "tool": {    "views": [      {        "id": "all",        "label": "All",        "visibility": "owner",        "is_default": true,        "read": {          "table": "news_edition"        }      }    ],    "name": "News",    "purpose": "News from the topics and sources you chose.",    "key": "news",    "icon": "newspaper",    "card_stock": "grey",    "route": "/news",    "figures": [      {        "read": "freshEdition",        "many": "Fresh edition"      }    ]  },  "parts": {    "shape": "desk",    "head": {      "facts": [        "covered_to",        "read_minutes"      ]    },    "links": [],    "lists": [      {        "table": "news_story",        "relation": "edition_id",        "heading": "Stories"      }    ],    "acts": {      "more": []    },    "cards": [      {        "column": "state_message",        "when": {          "column": "status",          "values": [            "queued",            "harvesting",            "writing",            "failed"          ]        }      }    ],    "strip": []  }}