Cotton code
321 lines · 8.4 KB · JSONRaw
{  "format_version": 1,  "id": "news_topic",  "reorder": true,  "name": "Topic",  "plural": "Topics",  "picture": {"photo": "photo:54118bbc8327cc8d43e587bd19db1841feff49cc5220ae6ca7384167e9cb414e", "object": "tool-news"},  "builtin": true,  "links": [{"label": "Deleted", "table": "bin", "where": {"table": "news_topic"}}],  "deletion": {"bin": true},  "commands": [{"id":"delete","label":"Delete", "receipt": "Deleted","kind":"delete","verb":"delete_record","data":{"table":"news_topic"},"bindings":{"id":"$id"},"confirm":"It can come back from the Bin. Undo on the receipt brings it back now.","does":"destroys"}],  "engine": "news",  "columns": [    {      "key": "name",      "type": "text",      "required": true,      "placeholder": "What do you want to follow?"    },    {      "key": "brief",      "name": "What I care about",      "type": "longtext"    },    {      "key": "exclusions",      "name": "What to leave out",      "type": "longtext"    },    {      "key": "kind",      "name": "How",      "type": "choice",      "default": "search",      "labels": {        "search": "Search the web for it",        "source": "One site I name"      },      "choices": [        "search",        "source"      ]    },    {      "key": "source_url",      "name": "Site",      "type": "text",      "placeholder": "The site, when it is one site",      "shown_when": {        "column": "kind",        "values": [          "source"        ]      }    },    {      "key": "active",      "name": "Follow",      "type": "bool",      "default": true    },    {      "key": "position",      "type": "number",      "readonly": true    },    {      "key": "pause_reason",      "type": "longtext",      "readonly": true    },    {      "key": "last_covered_at",      "type": "date",      "readonly": true    },    {      "key": "meta",      "type": "text",      "readonly": true    }  ],  "title": "name",  "date": null,  "project": null,  "order": "position",  "slip": {    "title": "name",    "subtitle": "brief",    "trailing": "meta",    "photo": null,    "toggle": "active",    "toggle_style": "switch"  },  "tile": {    "face": "slip-list"  },  "page": [    {      "heading": null,      "columns": [        "name",        "brief",        "exclusions",        "kind",        "source_url",        "active"      ]    },    {      "heading": "Keeping up",      "columns": [        "pause_reason",        "last_covered_at"      ]    }  ],  "related": [    {      "label": "Stories",      "table": "news_story",      "column": "topic_id"    }  ],  "instructions": "A news topic is a subject or a site the owner follows: kind search follows a subject by its name, kind source reads one address (source_url). Kind and address change together: a source needs its address, and a search topic has none. Topics are kept in the owner's order (position). A topic the owner stopped reading may be paused automatically, and pause_reason says so; setting active follows it again.",  "tables": [    {      "name": "cotton_news_topics",      "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": "name",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    name TEXT NOT NULL",          "position": 2        },        {          "name": "brief",          "type": "TEXT",          "default": "''",          "nullable": false,          "primary_key": false,          "declaration": "\n    brief TEXT NOT NULL DEFAULT ''",          "position": 3        },        {          "name": "exclusions",          "type": "TEXT",          "default": "''",          "nullable": false,          "primary_key": false,          "declaration": "\n    exclusions TEXT NOT NULL DEFAULT ''",          "position": 4        },        {          "name": "kind",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    kind TEXT NOT NULL",          "position": 5        },        {          "name": "source_url",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    source_url TEXT",          "position": 6        },        {          "name": "active",          "type": "INTEGER",          "default": "1",          "nullable": false,          "primary_key": false,          "declaration": "\n    active INTEGER NOT NULL DEFAULT 1",          "position": 7        },        {          "name": "paused_reason",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    paused_reason TEXT",          "position": 8        },        {          "name": "unopened_streak",          "type": "INTEGER",          "default": "0",          "nullable": false,          "primary_key": false,          "declaration": "\n    unopened_streak INTEGER NOT NULL DEFAULT 0",          "position": 9        },        {          "name": "last_new_at",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    last_new_at TEXT",          "position": 10        },        {          "name": "sort_order",          "type": "REAL",          "default": "0",          "nullable": false,          "primary_key": false,          "declaration": "\n    sort_order REAL NOT NULL DEFAULT 0",          "position": 11        },        {          "name": "created_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    created_at TEXT NOT NULL",          "position": 12        },        {          "name": "updated_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    updated_at TEXT NOT NULL",          "position": 13        },        {          "name": "_hlc",          "type": "TEXT",          "default": "''",          "nullable": false,          "primary_key": false,          "declaration": "\n    _hlc TEXT NOT NULL DEFAULT ''",          "position": 14        },        {          "name": "_born",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    _born TEXT",          "position": 15        },        {          "name": "trashed_at",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    trashed_at TEXT",          "position": 16        }      ],      "constraints": [        {          "declaration": "\n    CHECK (kind IN ('search', 'source'))",          "position": 17        },        {          "declaration": "\n    CHECK (length(trim(name)) > 0)",          "position": 18        },        {          "declaration": "\n    CHECK (paused_reason IS NULL OR paused_reason IN ('user', 'auto'))",          "position": 19        },        {          "declaration": "\n    CHECK ((source_url IS NULL) OR (kind = 'source'))",          "position": 20        },        {          "declaration": "\n    CHECK (unopened_streak >= 0)",          "position": 21        },        {          "declaration": "\n    FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n  ",          "position": 22        }      ],      "prefix": "CREATE TABLE cotton_news_topics (",      "suffix": ")",      "indexes": [        "CREATE INDEX idx_cotton_news_topics_workspace_active ON cotton_news_topics (workspace_id, active, sort_order)",        "CREATE INDEX IF NOT EXISTS idx_cotton_news_topics_author ON cotton_news_topics (substr(_hlc, 20), _hlc)"      ],      "full_text": [],      "triggers": []    }  ]}