Cotton code
1065 lines · 25.1 KB · JSONRaw
{  "format_version": 1,  "id": "person",  "name": "Person",  "plural": "People",  "record_route": "/people/person/[id]",  "picture": {    "photo": "photo:7d85a3b839e062730add96ea91492c4753f8951d2e7157d7d94552a6a301ec24",    "object": "tool-people",    "link_object": "people"  },  "builtin": true,  "engine": "people",  "owner_sections": [    {      "heading": "Voice words",      "list": {        "table": "voice_word",        "limit": 5,        "whole": "All voice words"      },      "role": "side"    },    {      "heading": "Devices",      "list": {        "table": "device",        "limit": 1,        "whole": "All devices"      },      "role": "side"    }  ],  "projects_read": {    "kind": "person",    "read": "person",    "families": [      "people",      "projects"    ]  },  "role": "person",  "filing_rank": 4,  "record_kind": "person",  "voice_words": [    "full_name",    "org",    "city"  ],  "columns": [    {      "key": "full_name",      "name": "Name",      "type": "text",      "required": true,      "placeholder": "Their name"    },    {      "key": "avatar_key",      "name": "Photo",      "type": "photo",      "opens": {        "table": "photo",        "column": "avatar_photo_id"      }    },    {      "key": "avatar_photo_id",      "media": true,      "name": "Original",      "type": "link",      "link_to": "photo",      "readonly": true    },    {      "key": "role_title",      "name": "Role",      "type": "text",      "fact": true,      "reading": "{value}"    },    {      "key": "org",      "name": "Organisation",      "type": "text",      "fact": true,      "reading": "{value}"    },    {      "key": "phones",      "name": "Phone",      "type": "text",      "multiple": true,      "readonly": true,      "reach": {        "kind": "phone",        "channel": "thread_channel"      }    },    {      "key": "emails",      "name": "Email",      "type": "text",      "multiple": true,      "readonly": true,      "reach": "email"    },    {      "key": "city",      "name": "City",      "type": "place",      "place": {        "id": "city_place",        "country": "country",        "zone": "timezone"      }    },    {      "key": "city_place",      "name": "Place",      "type": "text",      "readonly": true    },    {      "key": "country",      "name": "Country",      "type": "text",      "readonly": true    },    {      "key": "language",      "name": "Language",      "type": "choice",      "required": true,      "default": "en",      "choices": [        "en",        "hi",        "ta",        "te",        "bn",        "mr",        "gu",        "kn",        "ml",        "pa",        "ur",        "ar",        "fr",        "de",        "es",        "pt",        "it",        "nl",        "sv",        "da",        "no",        "fi",        "is",        "pl",        "cs",        "sk",        "hu",        "ro",        "bg",        "el",        "ru",        "uk",        "tr",        "he",        "fa",        "zh",        "ja",        "ko",        "vi",        "th",        "id",        "ms",        "fil",        "sw",        "af",        "ca",        "eu",        "gl",        "hr",        "sr",        "sl",        "lt",        "lv",        "et",        "km",        "lo",        "my",        "ne",        "si",        "am",        "az",        "hy",        "ka",        "kk",        "uz",        "mn",        "zu"      ],      "choice_names": {        "en": "English",        "hi": "Hindi",        "ta": "Tamil",        "te": "Telugu",        "bn": "Bengali",        "mr": "Marathi",        "gu": "Gujarati",        "kn": "Kannada",        "ml": "Malayalam",        "pa": "Punjabi",        "ur": "Urdu",        "ar": "Arabic",        "fr": "French",        "de": "German",        "es": "Spanish",        "pt": "Portuguese",        "it": "Italian",        "nl": "Dutch",        "sv": "Swedish",        "da": "Danish",        "no": "Norwegian",        "fi": "Finnish",        "is": "Icelandic",        "pl": "Polish",        "cs": "Czech",        "sk": "Slovak",        "hu": "Hungarian",        "ro": "Romanian",        "bg": "Bulgarian",        "el": "Greek",        "ru": "Russian",        "uk": "Ukrainian",        "tr": "Turkish",        "he": "Hebrew",        "fa": "Persian",        "zh": "Chinese",        "ja": "Japanese",        "ko": "Korean",        "vi": "Vietnamese",        "th": "Thai",        "id": "Indonesian",        "ms": "Malay",        "fil": "Filipino",        "sw": "Swahili",        "af": "Afrikaans",        "ca": "Catalan",        "eu": "Basque",        "gl": "Galician",        "hr": "Croatian",        "sr": "Serbian",        "sl": "Slovenian",        "lt": "Lithuanian",        "lv": "Latvian",        "et": "Estonian",        "km": "Khmer",        "lo": "Lao",        "my": "Burmese",        "ne": "Nepali",        "si": "Sinhala",        "am": "Amharic",        "az": "Azerbaijani",        "hy": "Armenian",        "ka": "Georgian",        "kk": "Kazakh",        "uz": "Uzbek",        "mn": "Mongolian",        "zu": "Zulu"      }    },    {      "key": "instagrams",      "name": "Instagram",      "type": "text",      "multiple": true,      "readonly": true,      "reach": "instagram"    },    {      "key": "timezone",      "name": "Time zone",      "type": "text",      "readonly": true,      "zone": true    },    {      "key": "birthday",      "name": "Birthday",      "type": "date",      "yearly": true,      "readonly": true    },    {      "key": "birth_day",      "name": "Birthday",      "type": "number",      "readonly": true    },    {      "key": "birth_month",      "name": "Birth month",      "type": "number",      "readonly": true    },    {      "key": "birth_year",      "name": "Birth year",      "type": "number",      "readonly": true    },    {      "key": "balance",      "name": "Between you",      "type": "amount",      "readonly": true,      "signs": {        "positive": "{first} owes you",        "negative": "You owe {first}",        "zero": "You're square."      },      "currency": "balance_currency"    },    {      "key": "balances",      "name": "Between you",      "type": "text",      "readonly": true    },    {      "key": "balance_currency",      "name": "Currency of the balance",      "type": "text",      "readonly": true    },    {      "key": "summary",      "name": "Summary",      "type": "longtext",      "placeholder": "Add a summary — how you know {first}, and what they do.",      "provenance": {        "by": "summary_by",        "at": "summary_updated_at",        "since": "summary_since"      }    },    {      "key": "summary_by",      "name": "Summary by",      "type": "text",      "readonly": true    },    {      "key": "summary_updated_at",      "name": "Summary written",      "type": "date",      "readonly": true    },    {      "key": "summary_since",      "name": "Since the summary",      "type": "text",      "readonly": true    },    {      "key": "thread_channel",      "name": "Messages over",      "type": "text",      "readonly": true    },    {      "key": "archived_at",      "name": "Archived",      "type": "date"    }  ],  "title": "full_name",  "date": null,  "project": null,  "order": null,  "slip": {    "title": "full_name",    "subtitle": [      "org",      "role_title",      "city"    ],    "trailing": "timezone",    "photo": "avatar_key",    "toggle": null  },  "tile": {    "face": "polaroid-grid"  },  "page": [    {      "heading": null,      "columns": [        "avatar_key",        "full_name",        "role_title",        "org",        "city",        "language",        "birthday",        "timezone"      ]    },    {      "heading": "Handles",      "list": {        "table": "person_handle",        "link": "person_id",        "limit": 5,        "add": "Add a handle"      }    },    {      "heading": "Languages",      "list": {        "table": "person_language",        "link": "person_id",        "add": "Add a language"      }    },    {      "heading": "Money",      "columns": [        "balance",        "balances"      ]    },    {      "heading": "Summary",      "columns": [        "summary"      ]    },    {      "heading": "Same person?",      "list": {        "table": "person_suggestion",        "link": "person_id"      }    },    {      "heading": "Todos",      "list": {        "table": "todo",        "link": "people",        "limit": 4,        "columns": 2      }    },    {      "heading": "Messages",      "list": {        "table": "thread",        "link": "member_people",        "limit": 3      }    },    {      "heading": "Calls",      "list": {        "table": "call",        "link": "person_id",        "limit": 3      }    },    {      "heading": "Open between you",      "list": {        "table": "money_claim",        "link": "person_id",        "limit": 3,        "empty": "Nothing is open between you."      }    },    {      "heading": "Notes",      "list": {        "table": "person_note",        "link": "person_id",        "with": [          {            "table": "note",            "link": "people"          }        ],        "limit": 3      }    },    {      "heading": "Events",      "list": {        "table": "event",        "link": "people",        "limit": 3      }    },    {      "heading": "Photos",      "list": {        "table": "photo",        "link": "people",        "with": [          {            "table": "video",            "link": "people"          }        ],        "limit": 6,        "columns": 3      }    },    {      "heading": "Social",      "list": {        "table": "story",        "link": "person_id",        "limit": 6,        "columns": 3      }    },    {      "heading": "Is this {first}?",      "list": {        "table": "face",        "link": "suggested_person_id"      }    },    {      "heading": "Documents",      "list": {        "table": "document",        "link": "people",        "limit": 3,        "columns": 2      }    }  ],  "archived": "archived_at",  "sort": {    "column": "full_name"  },  "layout": "cards",  "grid": {    "columns": 4  },  "empty": {    "title": "No people yet.",    "message": "Add someone by name, or bring in the contacts that matter from this phone."  },  "create": {    "label": "New person"  },  "index": "full_name",  "search": [    "full_name",    "org",    "city"  ],  "delete": false,  "instructions": "A person is someone the owner knows: name, how to reach them, where they work and live, and their birthday. Search for an existing person before adding one, because duplicates split their history. The summary is a short description of who they are to the owner; keep it factual and never invent contact details. A person is archived, never deleted. Never invent a photo; a person with no photo shows none.",  "links": [    {      "label": "Import contacts",      "table": "import",      "path": "/people/import"    }  ],  "actions": [    {      "label": "Call",      "column": "id",      "scheme": "call-person"    },    {      "label": "Video call",      "column": "id",      "scheme": "video-call-person"    }  ],  "groups": {    "actions": [      {        "label": "Call everyone",        "column": "id",        "scheme": "call-group"      },      {        "label": "Video call",        "column": "id",        "scheme": "video-call-group"      }    ],    "stack": "polaroids",    "widget": {      "face": "polaroids",      "sizes": [        "medium",        "large"      ]    }  },  "parts": {    "shape": "sheet",    "head": {      "facts": [        "role_title"      ]    },    "links": [],    "body": "summary",    "lists": [      {        "table": "person_handle",        "relation": "person_id",        "heading": "Handles",        "main_act": "keep"      },      {        "table": "person_language",        "relation": "person_id",        "heading": "Languages"      },      {        "table": "person_suggestion",        "relation": "person_id",        "heading": "Same person?"      },      {        "table": "todo",        "relation": "people",        "heading": "Todos"      },      {        "table": "thread",        "relation": "member_people",        "heading": "Messages"      },      {        "table": "call",        "relation": "person_id",        "heading": "Calls"      },      {        "table": "person_note",        "relation": "person_id",        "heading": "Notes",        "face": "notes"      },      {        "table": "event",        "relation": "people",        "heading": "Events"      },      {        "table": "photo",        "relation": "people",        "heading": "Photos",        "face": "photos"      },      {        "table": "story",        "relation": "person_id",        "heading": "Social"      },      {        "table": "document",        "relation": "people",        "heading": "Documents"      }    ],    "acts": {      "more": []    },    "cards": [      {        "column": "city"      },      {        "column": "timezone",        "when": {          "column": "city",          "present": false        }      },      {        "column": "birthday"      },      {        "column": "language",        "object": "message"      },      {        "column": "org"      },      {        "column": "summary",        "row": true      }    ],    "strip": []  },  "tool": {    "name": "People",    "key": "people",    "card_stock": "rose",    "icon": "users",    "route": "/people",    "figures": [      {        "read": "people",        "one": "1 person",        "many": "{n} people"      }    ]  ,"purpose":"People and how to reach them."},  "tables": [    {      "name": "cotton_people",      "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": "full_name",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    full_name TEXT NOT NULL",          "position": 2        },        {          "name": "org",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    org TEXT",          "position": 3        },        {          "name": "role_title",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    role_title TEXT",          "position": 4        },        {          "name": "city",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    city TEXT",          "position": 5        },        {          "name": "summary",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    summary TEXT",          "position": 6        },        {          "name": "summary_updated_at",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    summary_updated_at TEXT",          "position": 7        },        {          "name": "summary_by",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    summary_by TEXT",          "position": 8        },        {          "name": "contact_source",          "type": "TEXT",          "default": "'manual'",          "nullable": false,          "primary_key": false,          "declaration": "\n    contact_source TEXT NOT NULL DEFAULT 'manual'",          "position": 9        },        {          "name": "device_contact_id",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    device_contact_id TEXT",          "position": 10        },        {          "name": "archived_at",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    archived_at TEXT",          "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": "birth_month",          "type": "INTEGER",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    birth_month INTEGER",          "position": 14        },        {          "name": "birth_day",          "type": "INTEGER",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    birth_day INTEGER",          "position": 15        },        {          "name": "birth_year",          "type": "INTEGER",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    birth_year INTEGER",          "position": 16        },        {          "name": "timezone",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    timezone TEXT",          "position": 17        },        {          "name": "avatar_url",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    avatar_url TEXT",          "position": 18        },        {          "name": "avatar_key",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    avatar_key TEXT",          "position": 19        },        {          "name": "device_contact_snapshot",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    device_contact_snapshot TEXT",          "position": 20        },        {          "name": "_hlc",          "type": "TEXT",          "default": "''",          "nullable": false,          "primary_key": false,          "declaration": "\n    _hlc TEXT NOT NULL DEFAULT ''",          "position": 21        },        {          "name": "_born",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    _born TEXT",          "position": 22        },        {          "name": "city_filled_at",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    city_filled_at TEXT",          "position": 23        },        {          "name": "avatar_photo_id",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    avatar_photo_id TEXT",          "position": 24        },        {          "name": "trashed_at",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": " trashed_at TEXT",          "position": 25        },        {          "name": "language",          "type": "TEXT",          "default": "'en'",          "nullable": false,          "primary_key": false,          "declaration": " language TEXT NOT NULL DEFAULT 'en' CHECK (length(language) BETWEEN 2 AND 3 AND language NOT GLOB '*[^a-z]*')",          "position": 26        },        {          "name": "face_embedding",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": " face_embedding TEXT CHECK (face_embedding IS NULL OR length(face_embedding) > 0)",          "position": 27        },        {          "name": "face_embedding_model",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": " face_embedding_model TEXT CHECK (face_embedding_model IS NULL OR length(face_embedding_model) > 0)",          "position": 28        },        {          "name": "face_embedding_from",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": " face_embedding_from TEXT CHECK (face_embedding_from IS NULL OR length(face_embedding_from) > 0)",          "position": 29        },        {          "name": "city_place",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": " city_place TEXT",          "position": 30        },        {          "name": "country",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": " country TEXT",          "position": 31        }      ],      "constraints": [        {          "declaration": "\n    CHECK ((birth_day IS NULL) OR ((birth_day >= 1) AND (birth_day <= 31)))",          "position": 32        },        {          "declaration": "\n    CHECK ((birth_month IS NULL) OR ((birth_month >= 1) AND (birth_month <= 12)))",          "position": 33        },        {          "declaration": "\n    CHECK (((birth_month IS NOT NULL) + (birth_day IS NOT NULL)) IN (0, 2))",          "position": 34        },        {          "declaration": "\n    CHECK (contact_source IN ('import', 'manual', 'apple_library'))",          "position": 35        },        {          "declaration": "\n    CHECK ((summary IS NULL) OR (length(summary) <= 4000))",          "position": 36        },        {          "declaration": "\n    CHECK ((summary_by IS NULL) OR (length(trim(summary_by)) > 0))",          "position": 37        },        {          "declaration": "\n    FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n  ",          "position": 38        }      ],      "prefix": "CREATE TABLE \"cotton_people\" (",      "suffix": ")",      "indexes": [        "CREATE INDEX idx_cotton_people_workspace ON cotton_people (workspace_id)",        "CREATE UNIQUE INDEX uq_cotton_people_device_contact ON cotton_people (workspace_id, device_contact_id) WHERE device_contact_id IS NOT NULL",        "CREATE INDEX idx_cotton_people_city_filled ON cotton_people (workspace_id, city_filled_at) WHERE city_filled_at IS NOT NULL",        "CREATE INDEX IF NOT EXISTS idx_cotton_people_author ON cotton_people (substr(_hlc, 20), _hlc)"      ],      "full_text": [        "CREATE VIRTUAL TABLE fts_people USING fts5(\n       full_name, org, role_title, summary, content = 'cotton_people', content_rowid = 'rowid',\n       tokenize = 'unicode61 remove_diacritics 2'\n     )"      ],      "triggers": [        "CREATE TRIGGER fts_people_ai AFTER INSERT ON cotton_people WHEN new.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_people'), 0) BEGIN\n       INSERT INTO fts_people (rowid, full_name, org, role_title, summary) VALUES (new.rowid, new.full_name, new.org, new.role_title, new.summary);\n     END",        "CREATE TRIGGER fts_people_ad AFTER DELETE ON cotton_people WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_people'), 0) BEGIN\n       INSERT INTO fts_people (fts_people, rowid, full_name, org, role_title, summary) VALUES ('delete', old.rowid, old.full_name, old.org, old.role_title, old.summary);\n     END",        "CREATE TRIGGER fts_people_au AFTER UPDATE OF full_name, org, role_title, summary ON cotton_people\n       FOR EACH ROW WHEN old.rowid >= coalesce((SELECT floor FROM _fts_fill WHERE fts = 'fts_people'), 0) AND (new.full_name IS NOT old.full_name OR new.org IS NOT old.org OR new.role_title IS NOT old.role_title OR new.summary IS NOT old.summary) BEGIN\n       INSERT INTO fts_people (fts_people, rowid, full_name, org, role_title, summary) VALUES ('delete', old.rowid, old.full_name, old.org, old.role_title, old.summary);\n       INSERT INTO fts_people (rowid, full_name, org, role_title, summary) VALUES (new.rowid, new.full_name, new.org, new.role_title, new.summary);\n     END"      ]    }  ]}