Cotton code
854 lines · 22.9 KB · JSONRaw
{  "format_version": 1,  "id": "photo",  "name": "Photo",  "plural": "Photos",  "record_route": "/photos/photo/[id]",  "picture": null,  "builtin": true,  "engine": "media",  "takes_files": true,  "commands": [{"id": "describe", "label": "Write a description", "receipt": "Described", "kind": "update", "method": "media.describe", "object": "lens", "bindings": {"id": "$id"}}, {"id": "delete", "label": "Delete", "receipt": "Deleted", "kind": "delete", "verb": "delete_record", "data": {"table": "photo"}, "bindings": {"id": "$id"}, "confirm": "It can come back from the Bin. Undo on the receipt brings it back now.", "does": "destroys"}],  "columns": [    {      "key": "key",      "name": "Picture",      "type": "photo",      "readonly": true,      "size": [        "width",        "height"      ],      "caption": "caption"    },    {      "key": "caption",      "name": "Caption",      "type": "text",      "placeholder": "Add a caption"    },    {      "key": "taken_at",      "name": "Taken",      "type": "date",      "readonly": true    },    {      "key": "place_name",      "name": "Place",      "type": "text",      "readonly": true    },    {      "key": "place_city",      "name": "City",      "type": "text",      "readonly": true    },    {      "key": "place_country",      "name": "Country",      "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": "camera_make",      "name": "Camera make",      "type": "text",      "readonly": true    },    {      "key": "camera_model",      "name": "Camera",      "type": "text",      "readonly": true    },    {      "key": "original_filename",      "name": "File name",      "type": "text",      "readonly": true    },    {      "key": "ocr_text",      "name": "Text in the picture",      "type": "longtext",      "readonly": true    }  ],  "title": "caption",  "date": null,  "project": null,  "order": null,  "slip": {    "title": "caption",    "subtitle": "place_name",    "trailing": "taken_at",    "photo": "key",    "toggle": null,    "title_fallback": "place_name"  },  "viewer": {},  "tile": {    "face": "polaroid-grid"  },  "polaroid": {},  "layout": "sheet",  "grid": {    "columns": 4  },  "sort": {    "column": "taken_at",    "descending": true  },  "by_month": "taken_at",  "months": {    "over": 0,    "undated": "No date"  },  "search": [    "caption",    "summary"  ],  "search_placeholder": "What's in your photos",  "empty": {    "title": "No photos yet.",    "message": "Pictures from your chats land here on their own.",    "search": {      "title": "No matches yet"    }  },  "select": {    "verb": "delete"  },  "links": [    {      "label": "Deleted",      "table": "bin",      "where": {        "table": "photo"      }    }  ],  "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          }        },        {          "label": "Delete",          "delete": true        }      ]    },    {      "heading": "People",      "list": {        "table": "face",        "link": "photo_id"      }    },    {      "heading": "Details",      "columns": [        "place_city",        "place_country",        "camera_make",        "camera_model",        "ocr_text"      ],      "hand": [        "size_bytes",        "width"      ]    }  ],  "instructions": "A photo is one picture the owner keeps, with when and where it was taken. The caption is the owner's; the description and the text read from the picture are written by a worker. Describe only what is visible, and never name a person in a photo the owner has not confirmed.",  "add": false,  "tables": [    {      "name": "cotton_photos",      "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": "taken_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    taken_at TEXT NOT NULL",          "position": 8        },        {          "name": "preview",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    preview TEXT",          "position": 9        },        {          "name": "caption",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    caption TEXT",          "position": 10        },        {          "name": "summary",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    summary TEXT",          "position": 11        },        {          "name": "summary_by",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    summary_by TEXT",          "position": 12        },        {          "name": "summary_at",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    summary_at TEXT",          "position": 13        },        {          "name": "review_note",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    review_note TEXT",          "position": 14        },        {          "name": "review_by",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    review_by TEXT",          "position": 15        },        {          "name": "review_at",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    review_at TEXT",          "position": 16        },        {          "name": "taken_offset",          "type": "INTEGER",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    taken_offset INTEGER",          "position": 17        },        {          "name": "latitude",          "type": "REAL",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    latitude REAL",          "position": 18        },        {          "name": "longitude",          "type": "REAL",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    longitude REAL",          "position": 19        },        {          "name": "place_name",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    place_name TEXT",          "position": 20        },        {          "name": "place_city",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    place_city TEXT",          "position": 21        },        {          "name": "place_region",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    place_region TEXT",          "position": 22        },        {          "name": "place_country",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    place_country TEXT",          "position": 23        },        {          "name": "camera_make",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    camera_make TEXT",          "position": 24        },        {          "name": "camera_model",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    camera_model TEXT",          "position": 25        },        {          "name": "orientation",          "type": "INTEGER",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    orientation INTEGER",          "position": 26        },        {          "name": "favourite",          "type": "INTEGER",          "default": "0",          "nullable": false,          "primary_key": false,          "declaration": "\n    favourite INTEGER NOT NULL DEFAULT 0",          "position": 27        },        {          "name": "subtypes",          "type": "TEXT",          "default": "'[]'",          "nullable": false,          "primary_key": false,          "declaration": "\n    subtypes TEXT NOT NULL DEFAULT '[]'",          "position": 28        },        {          "name": "original_filename",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    original_filename TEXT",          "position": 29        },        {          "name": "aesthetic_score",          "type": "REAL",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    aesthetic_score REAL",          "position": 30        },        {          "name": "curation_score",          "type": "REAL",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    curation_score REAL",          "position": 31        },        {          "name": "labels",          "type": "TEXT",          "default": "'[]'",          "nullable": false,          "primary_key": false,          "declaration": "\n    labels TEXT NOT NULL DEFAULT '[]'",          "position": 32        },        {          "name": "phash",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    phash TEXT",          "position": 33        },        {          "name": "created_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    created_at TEXT NOT NULL",          "position": 34        },        {          "name": "updated_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    updated_at TEXT NOT NULL",          "position": 35        },        {          "name": "_hlc",          "type": "TEXT",          "default": "''",          "nullable": false,          "primary_key": false,          "declaration": "\n    _hlc TEXT NOT NULL DEFAULT ''",          "position": 36        },        {          "name": "ocr_text",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": " ocr_text TEXT",          "position": 37        },        {          "name": "is_utility",          "type": "INTEGER",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": " is_utility INTEGER CHECK (is_utility IS NULL OR is_utility IN (0, 1))",          "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        },        {          "name": "image_embedding",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": " image_embedding TEXT CHECK (image_embedding IS NULL OR length(image_embedding) > 0)",          "position": 42        },        {          "name": "image_embedding_model",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": " image_embedding_model TEXT CHECK (image_embedding_model IS NULL OR length(image_embedding_model) > 0)",          "position": 43        }      ],      "constraints": [        {          "declaration": "\n    UNIQUE (workspace_id, sha256)",          "position": 44        },        {          "declaration": "\n    CHECK (id = 'photo:' || sha256)",          "position": 45        },        {          "declaration": "\n    CHECK (sha256 NOT GLOB '*[^0-9a-f]*' AND length(sha256) = 64)",          "position": 46        },        {          "declaration": "\n    CHECK (size_bytes >= 0)",          "position": 47        },        {          "declaration": "\n    CHECK (width IS NULL OR width > 0)",          "position": 48        },        {          "declaration": "\n    CHECK (height IS NULL OR height > 0)",          "position": 49        },        {          "declaration": "\n    CHECK (caption IS NULL OR length(caption) <= 500)",          "position": 50        },        {          "declaration": "\n    CHECK (review_note IS NULL OR (length(trim(review_note)) > 0 AND length(review_note) <= 280))",          "position": 51        },        {          "declaration": "\n    CHECK ((summary IS NULL) = (summary_at IS NULL))",          "position": 52        },        {          "declaration": "\n    CHECK ((review_note IS NULL) = (review_at IS NULL))",          "position": 53        },        {          "declaration": "\n    CHECK ((latitude IS NULL) = (longitude IS NULL))",          "position": 54        },        {          "declaration": "\n    CHECK (latitude IS NULL OR (latitude >= -90 AND latitude <= 90))",          "position": 55        },        {          "declaration": "\n    CHECK (longitude IS NULL OR (longitude >= -180 AND longitude <= 180))",          "position": 56        },        {          "declaration": "\n    CHECK (orientation IS NULL OR (orientation >= 1 AND orientation <= 8))",          "position": 57        },        {          "declaration": "\n    CHECK (taken_offset IS NULL OR (taken_offset >= -86400 AND taken_offset <= 86400))",          "position": 58        },        {          "declaration": "\n    CHECK (favourite IN (0, 1))",          "position": 59        },        {          "declaration": "\n    CHECK (json_type(subtypes) = 'array')",          "position": 60        },        {          "declaration": "\n    CHECK (json_type(labels) = 'array')",          "position": 61        },        {          "declaration": "\n    CHECK (aesthetic_score IS NULL OR (aesthetic_score >= -1 AND aesthetic_score <= 1))",          "position": 62        },        {          "declaration": "\n    CHECK (curation_score IS NULL OR (curation_score >= -1 AND curation_score <= 1))",          "position": 63        },        {          "declaration": "\n    CHECK (phash IS NULL OR (length(phash) = 16 AND phash NOT GLOB '*[^0-9a-f]*'))",          "position": 64        },        {          "declaration": "\n    FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n  ",          "position": 65        }      ],      "prefix": "CREATE TABLE \"cotton_photos\" (",      "suffix": ")",      "indexes": [        "CREATE INDEX idx_cotton_photos_taken ON cotton_photos (workspace_id, taken_at DESC)",        "CREATE INDEX idx_cotton_photos_review ON cotton_photos (workspace_id, review_at) WHERE review_note IS NOT NULL",        "CREATE INDEX idx_cotton_photos_undescribed ON cotton_photos (workspace_id, taken_at DESC) WHERE summary IS NULL",        "CREATE INDEX idx_cotton_photos_place ON cotton_photos (workspace_id, place_city)",        "CREATE INDEX idx_cotton_photos_favourite ON cotton_photos (workspace_id, taken_at DESC) WHERE favourite = 1",        "CREATE INDEX idx_cotton_photos_phash ON cotton_photos (workspace_id, phash) WHERE phash IS NOT NULL",        "CREATE INDEX idx_cotton_photos_utility ON cotton_photos (workspace_id, taken_at DESC) WHERE is_utility = 1",        "CREATE INDEX idx_cotton_photos_origin ON cotton_photos (origin_handle) WHERE origin_handle IS NOT NULL",        "CREATE INDEX IF NOT EXISTS idx_cotton_photos_author ON cotton_photos (substr(_hlc, 20), _hlc)"      ],      "full_text": [        "CREATE VIRTUAL TABLE fts_photos USING fts5(\n       caption, summary, ocr_text, content = 'cotton_photos', content_rowid = 'rowid',\n       tokenize = 'unicode61 remove_diacritics 2'\n     )"      ],      "triggers": [        "CREATE TRIGGER fts_photos_ai AFTER INSERT ON cotton_photos WHEN new.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_photos'), 0) BEGIN\n       INSERT INTO fts_photos (rowid, caption, summary, ocr_text) VALUES (new.rowid, new.caption, new.summary, new.ocr_text);\n     END",        "CREATE TRIGGER fts_photos_ad AFTER DELETE ON cotton_photos WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_photos'), 0) BEGIN\n       INSERT INTO fts_photos (fts_photos, rowid, caption, summary, ocr_text) VALUES ('delete', old.rowid, old.caption, old.summary, old.ocr_text);\n     END",        "CREATE TRIGGER fts_photos_au AFTER UPDATE OF caption, summary, ocr_text ON cotton_photos\n       FOR EACH ROW WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_photos'), 0) AND (new.caption IS NOT old.caption OR new.summary IS NOT old.summary OR new.ocr_text IS NOT old.ocr_text) BEGIN\n       INSERT INTO fts_photos (fts_photos, rowid, caption, summary, ocr_text) VALUES ('delete', old.rowid, old.caption, old.summary, old.ocr_text);\n       INSERT INTO fts_photos (rowid, caption, summary, ocr_text) VALUES (new.rowid, new.caption, new.summary, new.ocr_text);\n     END"      ]    }  ],  "parts": {    "shape": "sheet",    "head": {      "facts": [        "taken_at",        "place_name"      ]    },    "links": [],    "body": "summary",    "lists": [      {        "table": "face",        "relation": "photo_id",        "heading": "People"      }    ],    "acts": {      "more": [        "describe"      ],      "away": "delete"    },    "cards": [      {        "column": "taken_at"      },      {        "column": "place_name"      },      {        "column": "review_note"      },      {        "column": "ocr_text",        "row": true      }    ]  }}