Cotton code
837 lines · 22.0 KB · JSONRaw
{  "format_version": 1,  "id": "video",  "name": "Video",  "plural": "Videos",  "record_route": "/videos/video/[id]",  "picture": {"photo": "photo:879a439235a2a7dd14f5f40f15e4667ef45f7f0051936d0a23ba24f69bc04c74", "object": "tool-videos"},  "builtin": true,  "engine": "media",  "takes_files": true,  "columns": [    {      "key": "key",      "name": "Film",      "type": "file",      "readonly": true,      "poster": "poster_key",      "size": [        "width",        "height"      ],      "caption": "caption",      "caption_fallback": "duration_ms"    },    {      "key": "poster_key",      "name": "Poster",      "type": "photo",      "readonly": true    },    {      "key": "caption",      "name": "Caption",      "type": "text",      "placeholder": "Add a caption"    },    {      "key": "taken_at",      "name": "Taken",      "type": "date",      "readonly": true    },    {      "key": "duration_ms",      "name": "Length",      "type": "number",      "readonly": true,      "format": "duration_ms"    },    {      "key": "place_name",      "name": "Place",      "type": "text",      "readonly": true    },    {      "key": "albums",      "name": "Albums",      "type": "link",      "link_to": "album",      "multiple": true,      "readonly": true    },    {      "key": "people",      "name": "People",      "type": "link",      "link_to": "person",      "multiple": true,      "readonly": true    },    {      "key": "summary",      "name": "Description",      "type": "longtext",      "readonly": true,      "placeholder": "Not described yet."    },    {      "key": "summary_at",      "name": "Described",      "type": "date",      "readonly": true    },    {      "key": "review_note",      "name": "Review",      "type": "text"    },    {      "key": "review_by",      "name": "Suggested by",      "type": "text",      "readonly": true    },    {      "key": "review_at",      "name": "Suggested",      "type": "date",      "readonly": true    },    {      "key": "favourite",      "name": "Favourite",      "type": "bool",      "readonly": true    },    {      "key": "width",      "name": "Dimensions",      "type": "number",      "readonly": true,      "format": "dimensions",      "pair": "height"    },    {      "key": "height",      "name": "Height",      "type": "number",      "readonly": true    },    {      "key": "size_bytes",      "name": "Size",      "type": "number",      "readonly": true,      "format": "bytes"    },    {      "key": "original_filename",      "name": "File name",      "type": "text",      "readonly": true    }  ],  "title": "caption",  "date": null,  "project": null,  "order": null,  "slip": {    "title": "caption",    "subtitle": "place_name",    "trailing": "duration_ms",    "photo": "poster_key",    "player": "key",    "toggle": null,    "badge": {      "column": "key",      "symbol": "play.fill",      "spoken": "Video"    },    "title_fallback": "place_name"  },  "viewer": {},  "tile": {    "face": "polaroid-grid"  },  "polaroid": {    "caption": "duration_ms"  },  "layout": "sheet",  "grid": {    "columns": 4  },  "sort": {    "column": "taken_at",    "descending": true  },  "by_month": "taken_at",  "months": {    "over": 0,    "undated": "No date"  },  "search": [    "caption",    "summary"  ],  "empty": {    "title": "No videos yet.",    "message": "Pictures and videos from your chats land here on their own."  },  "links": [    {      "label": "Deleted",      "table": "bin",      "where": {        "table": "video"      }    }  ],  "deletion": {    "bin": true  },  "page": [    {      "heading": null,      "columns": [        "key",        "caption"      ],      "hand": [        "taken_at",        "place_name"      ]    },    {      "heading": null,      "columns": [        "albums"      ],      "when": {        "column": "albums",        "present": true      }    },    {      "heading": null,      "columns": [        "people"      ],      "when": {        "column": "people",        "present": true      }    },    {      "heading": "What Cotton saw",      "columns": [        "summary"      ],      "hand": [        "described {summary_at}"      ]    },    {      "heading": null,      "when": {        "column": "review_note",        "present": true      },      "note": "suggested for review",      "ink": "red",      "columns": [        "review_note"      ],      "hand": "Suggested by {review_by} on {review_at}",      "actions": [        {          "label": "Keep",          "object": "star",          "sets": {            "review_note": null          }        }      ]    },    {      "heading": "Details",      "columns": [        "original_filename"      ],      "hand": [        "size_bytes",        "duration_ms"      ]    }  ],  "instructions": "A video is one film the owner keeps, with a poster frame, its length and when and where it was taken. Films are prints in the one Photos library; a film's page plays it. The caption is the owner's; the description is written by a worker from what the film shows. Describe only what is visible, and never name a person in a film the owner has not confirmed.",  "add": false,  "parts": {    "shape": "sheet",    "head": {      "facts": [        "taken_at",        "duration_ms"      ]    },    "links": [],    "body": "summary",    "lists": [],    "acts": {      "more": [        "describe"      ],      "away": "delete"    },    "cards": [      {        "column": "duration_ms"      },      {        "column": "taken_at"      },      {        "column": "place_name"      },      {        "column": "review_note"      }    ]  },  "commands": [    {      "id": "describe",      "label": "Write a description",      "receipt": "Described",      "kind": "update",      "method": "media.describe",      "object": "lens",      "bindings": {        "id": "$id"      }    },    {      "id": "delete",      "label": "Delete",      "kind": "delete",      "verb": "delete_record",      "data": {        "table": "video"      },      "bindings": {        "id": "$id"      },      "confirm": "Undo on the receipt brings it back.",      "receipt": "Deleted",      "does": "destroys"    }  ],  "tool": {    "name": "Videos",    "key": "videos",    "card_stock": "slate",    "icon": "video",    "route": "/videos"  ,"purpose":"Your videos and recordings."},  "tables": [    {      "name": "cotton_videos",      "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": "key",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    key TEXT NOT NULL",          "position": 2        },        {          "name": "sha256",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    sha256 TEXT NOT NULL",          "position": 3        },        {          "name": "content_type",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    content_type TEXT NOT NULL",          "position": 4        },        {          "name": "size_bytes",          "type": "INTEGER",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    size_bytes INTEGER NOT NULL",          "position": 5        },        {          "name": "width",          "type": "INTEGER",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    width INTEGER",          "position": 6        },        {          "name": "height",          "type": "INTEGER",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    height INTEGER",          "position": 7        },        {          "name": "duration_ms",          "type": "INTEGER",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    duration_ms INTEGER",          "position": 8        },        {          "name": "taken_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    taken_at TEXT NOT NULL",          "position": 9        },        {          "name": "preview",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    preview TEXT",          "position": 10        },        {          "name": "poster_key",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    poster_key TEXT",          "position": 11        },        {          "name": "caption",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    caption TEXT",          "position": 12        },        {          "name": "summary",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    summary TEXT",          "position": 13        },        {          "name": "summary_by",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    summary_by TEXT",          "position": 14        },        {          "name": "summary_at",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    summary_at TEXT",          "position": 15        },        {          "name": "review_note",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    review_note TEXT",          "position": 16        },        {          "name": "review_by",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    review_by TEXT",          "position": 17        },        {          "name": "review_at",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    review_at TEXT",          "position": 18        },        {          "name": "taken_offset",          "type": "INTEGER",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    taken_offset INTEGER",          "position": 19        },        {          "name": "latitude",          "type": "REAL",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    latitude REAL",          "position": 20        },        {          "name": "longitude",          "type": "REAL",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    longitude REAL",          "position": 21        },        {          "name": "place_name",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    place_name TEXT",          "position": 22        },        {          "name": "place_city",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    place_city TEXT",          "position": 23        },        {          "name": "place_region",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    place_region TEXT",          "position": 24        },        {          "name": "place_country",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    place_country TEXT",          "position": 25        },        {          "name": "camera_make",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    camera_make TEXT",          "position": 26        },        {          "name": "camera_model",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    camera_model TEXT",          "position": 27        },        {          "name": "orientation",          "type": "INTEGER",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    orientation INTEGER",          "position": 28        },        {          "name": "favourite",          "type": "INTEGER",          "default": "0",          "nullable": false,          "primary_key": false,          "declaration": "\n    favourite INTEGER NOT NULL DEFAULT 0",          "position": 29        },        {          "name": "subtypes",          "type": "TEXT",          "default": "'[]'",          "nullable": false,          "primary_key": false,          "declaration": "\n    subtypes TEXT NOT NULL DEFAULT '[]'",          "position": 30        },        {          "name": "original_filename",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    original_filename TEXT",          "position": 31        },        {          "name": "aesthetic_score",          "type": "REAL",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    aesthetic_score REAL",          "position": 32        },        {          "name": "curation_score",          "type": "REAL",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    curation_score REAL",          "position": 33        },        {          "name": "labels",          "type": "TEXT",          "default": "'[]'",          "nullable": false,          "primary_key": false,          "declaration": "\n    labels TEXT NOT NULL DEFAULT '[]'",          "position": 34        },        {          "name": "phash",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    phash TEXT",          "position": 35        },        {          "name": "created_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    created_at TEXT NOT NULL",          "position": 36        },        {          "name": "updated_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    updated_at TEXT NOT NULL",          "position": 37        },        {          "name": "_hlc",          "type": "TEXT",          "default": "''",          "nullable": false,          "primary_key": false,          "declaration": "\n    _hlc TEXT NOT NULL DEFAULT ''",          "position": 38        },        {          "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": 39        },        {          "name": "_born",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    _born TEXT",          "position": 40        },        {          "name": "trashed_at",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    trashed_at TEXT",          "position": 41        }      ],      "constraints": [        {          "declaration": "\n    UNIQUE (workspace_id, sha256)",          "position": 42        },        {          "declaration": "\n    CHECK (id = 'video:' || sha256)",          "position": 43        },        {          "declaration": "\n    CHECK (sha256 NOT GLOB '*[^0-9a-f]*' AND length(sha256) = 64)",          "position": 44        },        {          "declaration": "\n    CHECK (size_bytes >= 0)",          "position": 45        },        {          "declaration": "\n    CHECK (width IS NULL OR width > 0)",          "position": 46        },        {          "declaration": "\n    CHECK (height IS NULL OR height > 0)",          "position": 47        },        {          "declaration": "\n    CHECK (caption IS NULL OR length(caption) <= 500)",          "position": 48        },        {          "declaration": "\n    CHECK (review_note IS NULL OR (length(trim(review_note)) > 0 AND length(review_note) <= 280))",          "position": 49        },        {          "declaration": "\n    CHECK ((summary IS NULL) = (summary_at IS NULL))",          "position": 50        },        {          "declaration": "\n    CHECK ((review_note IS NULL) = (review_at IS NULL))",          "position": 51        },        {          "declaration": "\n    CHECK ((latitude IS NULL) = (longitude IS NULL))",          "position": 52        },        {          "declaration": "\n    CHECK (latitude IS NULL OR (latitude >= -90 AND latitude <= 90))",          "position": 53        },        {          "declaration": "\n    CHECK (longitude IS NULL OR (longitude >= -180 AND longitude <= 180))",          "position": 54        },        {          "declaration": "\n    CHECK (orientation IS NULL OR (orientation >= 1 AND orientation <= 8))",          "position": 55        },        {          "declaration": "\n    CHECK (taken_offset IS NULL OR (taken_offset >= -86400 AND taken_offset <= 86400))",          "position": 56        },        {          "declaration": "\n    CHECK (favourite IN (0, 1))",          "position": 57        },        {          "declaration": "\n    CHECK (json_type(subtypes) = 'array')",          "position": 58        },        {          "declaration": "\n    CHECK (json_type(labels) = 'array')",          "position": 59        },        {          "declaration": "\n    CHECK (aesthetic_score IS NULL OR (aesthetic_score >= -1 AND aesthetic_score <= 1))",          "position": 60        },        {          "declaration": "\n    CHECK (curation_score IS NULL OR (curation_score >= -1 AND curation_score <= 1))",          "position": 61        },        {          "declaration": "\n    CHECK (phash IS NULL OR (length(phash) = 16 AND phash NOT GLOB '*[^0-9a-f]*'))",          "position": 62        },        {          "declaration": "\n    CHECK (duration_ms IS NULL OR duration_ms >= 0)",          "position": 63        },        {          "declaration": "\n    FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n  ",          "position": 64        }      ],      "prefix": "CREATE TABLE \"cotton_videos\" (",      "suffix": ")",      "indexes": [        "CREATE INDEX idx_cotton_videos_taken ON cotton_videos (workspace_id, taken_at DESC)",        "CREATE INDEX idx_cotton_videos_review ON cotton_videos (workspace_id, review_at) WHERE review_note IS NOT NULL",        "CREATE INDEX idx_cotton_videos_undescribed ON cotton_videos (workspace_id, taken_at DESC) WHERE summary IS NULL",        "CREATE INDEX idx_cotton_videos_place ON cotton_videos (workspace_id, place_city)",        "CREATE INDEX idx_cotton_videos_favourite ON cotton_videos (workspace_id, taken_at DESC) WHERE favourite = 1",        "CREATE INDEX idx_cotton_videos_phash ON cotton_videos (workspace_id, phash) WHERE phash IS NOT NULL",        "CREATE INDEX idx_cotton_videos_origin ON cotton_videos (origin_handle) WHERE origin_handle IS NOT NULL",        "CREATE INDEX IF NOT EXISTS idx_cotton_videos_author ON cotton_videos (substr(_hlc, 20), _hlc)"      ],      "full_text": [        "CREATE VIRTUAL TABLE fts_videos USING fts5(\n       caption, summary, content = 'cotton_videos', content_rowid = 'rowid',\n       tokenize = 'unicode61 remove_diacritics 2'\n     )"      ],      "triggers": [        "CREATE TRIGGER fts_videos_ai AFTER INSERT ON cotton_videos WHEN new.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_videos'), 0) BEGIN\n       INSERT INTO fts_videos (rowid, caption, summary) VALUES (new.rowid, new.caption, new.summary);\n     END",        "CREATE TRIGGER fts_videos_ad AFTER DELETE ON cotton_videos WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_videos'), 0) BEGIN\n       INSERT INTO fts_videos (fts_videos, rowid, caption, summary) VALUES ('delete', old.rowid, old.caption, old.summary);\n     END",        "CREATE TRIGGER fts_videos_au AFTER UPDATE OF caption, summary ON cotton_videos\n       FOR EACH ROW WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_videos'), 0) AND (new.caption IS NOT old.caption OR new.summary IS NOT old.summary) BEGIN\n       INSERT INTO fts_videos (fts_videos, rowid, caption, summary) VALUES ('delete', old.rowid, old.caption, old.summary);\n       INSERT INTO fts_videos (rowid, caption, summary) VALUES (new.rowid, new.caption, new.summary);\n     END"      ]    }  ]}