Cotton code
1176 lines · 28.1 KB · JSONRaw
{  "about": "Send vectors (cotton-rules send.rs): the same tables, stores and makes run natively here and through the Worker's WASM (apps/business test send-vectors). `expect` is written by the Rust test with SEND_VECTORS_WRITE=1 and read back by both.",  "tables": {    "book": {      "columns": [        {          "key": "title",          "type": "text"        },        {          "key": "author",          "type": "text"        },        {          "key": "cover",          "type": "photo"        },        {          "key": "file",          "type": "file"        },        {          "key": "format",          "type": "choice"        },        {          "key": "isbn",          "type": "text"        },        {          "key": "ol_work",          "type": "text"        },        {          "key": "status",          "type": "choice"        },        {          "key": "rating",          "type": "number"        },        {          "key": "position",          "type": "text"        },        {          "key": "review",          "type": "longtext"        },        {          "key": "sent_by",          "type": "text"        },        {          "key": "sent_by_number",          "type": "text"        },        {          "key": "sent_at",          "type": "date"        },        {          "key": "send_id",          "type": "text"        }      ],      "send": {        "columns": [          "title",          "author",          "cover",          "file",          "format",          "isbn",          "ol_work"        ],        "files": [          "cover",          "file"        ],        "same": [          [            "file"          ],          [            "isbn"          ],          [            "ol_work"          ],          [            "title",            "author"          ]        ]      }    },    "highlight": {      "columns": [        {          "key": "book",          "type": "link",          "link_to": "book"        },        {          "key": "book_title",          "type": "text",          "computed": true        },        {          "key": "text",          "type": "longtext"        },        {          "key": "note",          "type": "longtext"        },        {          "key": "colour",          "type": "choice"        },        {          "key": "chapter",          "type": "text"        },        {          "key": "locator",          "type": "text"        },        {          "key": "sent_by",          "type": "text"        },        {          "key": "sent_by_number",          "type": "text"        },        {          "key": "sent_at",          "type": "date"        },        {          "key": "send_id",          "type": "text"        }      ],      "send": {        "columns": [          "text",          "note",          "colour",          "chapter",          "locator"        ],        "same": [          [            "book",            "text",            "locator"          ]        ],        "carry": {          "book": [            "title",            "author",            "isbn",            "ol_work",            "cover"          ]        }      }    },    "record_group": {      "columns": [        {          "key": "table_id",          "type": "text"        },        {          "key": "name",          "type": "text"        },        {          "key": "filter",          "type": "longtext"        },        {          "key": "position",          "type": "number"        },        {          "key": "sent_by",          "type": "text"        },        {          "key": "sent_by_number",          "type": "text"        },        {          "key": "sent_at",          "type": "date"        },        {          "key": "send_id",          "type": "text"        }      ],      "send": {        "columns": [          "table_id",          "name"        ],        "with": [          {            "table": "group_member",            "by": "group",            "record": "record_id",            "table_of": "table_id"          }        ]      }    },    "group_member": {      "columns": [        {          "key": "group",          "type": "link",          "link_to": "record_group"        },        {          "key": "record_id",          "type": "text"        },        {          "key": "place",          "type": "number"        },        {          "key": "sent_by",          "type": "text"        },        {          "key": "sent_by_number",          "type": "text"        },        {          "key": "sent_at",          "type": "date"        },        {          "key": "send_id",          "type": "text"        }      ],      "send": {        "columns": [          "record_id",          "place"        ]      }    },    "recipe": {      "columns": [        {          "key": "title",          "type": "text"        },        {          "key": "picture",          "type": "photo"        },        {          "key": "steps",          "type": "longtext"        },        {          "key": "rating",          "type": "number"        },        {          "key": "cooked_count",          "type": "number",          "computed": true        },        {          "key": "sent_by",          "type": "text"        },        {          "key": "sent_by_number",          "type": "text"        },        {          "key": "sent_at",          "type": "date"        },        {          "key": "send_id",          "type": "text"        }      ],      "send": {        "columns": [          "title",          "picture",          "steps"        ],        "files": [          "picture"        ],        "with": [          {            "table": "recipe_ingredient",            "by": "recipe"          }        ]      }    },    "recipe_ingredient": {      "columns": [        {          "key": "recipe",          "type": "link",          "link_to": "recipe"        },        {          "key": "line",          "type": "text"        },        {          "key": "position",          "type": "number"        },        {          "key": "sent_by",          "type": "text"        },        {          "key": "sent_by_number",          "type": "text"        },        {          "key": "sent_at",          "type": "date"        },        {          "key": "send_id",          "type": "text"        }      ],      "send": {        "columns": [          "line",          "position"        ]      }    },    "message": {      "columns": [        {          "key": "body",          "type": "longtext"        }      ],      "sealed": true    },    "todo": {      "columns": [        {          "key": "title",          "type": "text"        }      ]    }  },  "sender": {    "database": "11111111-1111-4111-8111-111111111111",    "rows": {      "book": [        {          "id": "b1",          "title": "The Synthetic Garden",          "author": "A. Example",          "cover": "11111111-1111-4111-8111-111111111111/photos/aaaa.jpg",          "file": "11111111-1111-4111-8111-111111111111/books/1111.epub",          "format": "epub",          "isbn": "9780000000001",          "status": "reading",          "rating": 4,          "position": "{\"href\":\"ch3\"}",          "review": "Mine alone"        },        {          "id": "b2",          "title": "Second Test Book",          "author": "B. Example",          "file": "11111111-1111-4111-8111-111111111111/books/2222.pdf",          "format": "pdf",          "status": "finished",          "rating": 2        }      ],      "highlight": [        {          "id": "h1",          "book": "b1",          "book_title": "The Synthetic Garden",          "text": "A sentence worth keeping.",          "note": "Why I kept it",          "colour": "teal",          "chapter": "Three",          "locator": "{\"href\":\"ch3\",\"progression\":0.4}"        }      ],      "record_group": [        {          "id": "g1",          "table_id": "book",          "name": "For the train",          "position": 3        }      ],      "group_member": [        {          "id": "m1",          "group": "g1",          "record_id": "b1",          "place": 1        },        {          "id": "m2",          "group": "g1",          "record_id": "b2",          "place": 2        }      ],      "recipe": [        {          "id": "r1",          "title": "Test Dal",          "picture": "11111111-1111-4111-8111-111111111111/photos/dddd.jpg",          "steps": "Boil. Stir.",          "rating": 5,          "cooked_count": 9        }      ],      "recipe_ingredient": [        {          "id": "i1",          "recipe": "r1",          "line": "1 cup lentils",          "position": 1        },        {          "id": "i2",          "recipe": "r1",          "line": "2 cups water",          "position": 2        }      ],      "message": [        {          "id": "x1",          "body": "never"        }      ],      "todo": [        {          "id": "t1",          "title": "never"        }      ]    },    "media": {      "11111111-1111-4111-8111-111111111111/photos/aaaa.jpg": 2000,      "11111111-1111-4111-8111-111111111111/books/1111.epub": 300000,      "11111111-1111-4111-8111-111111111111/books/2222.pdf": 500000,      "11111111-1111-4111-8111-111111111111/photos/dddd.jpg": 1500    }  },  "receivers": {    "empty": {      "database": "22222222-2222-4222-8222-222222222222",      "rows": {}    },    "holds": {      "database": "22222222-2222-4222-8222-222222222222",      "rows": {        "book": [          {            "id": "own-b1",            "title": "My own copy",            "isbn": "9780000000001"          },          {            "id": "own-b2",            "title": "Second Test Book",            "file": "22222222-2222-4222-8222-222222222222/books/2222.pdf"          }        ]      }    }  },  "cases": [    {      "name": "book_with_file",      "table": "book",      "record": "b1",      "receiver": "empty"    },    {      "name": "highlight_alone",      "table": "highlight",      "record": "h1",      "receiver": "empty"    },    {      "name": "highlight_book_held",      "table": "highlight",      "record": "h1",      "receiver": "holds"    },    {      "name": "list",      "table": "record_group",      "record": "g1",      "receiver": "holds"    },    {      "name": "duplicate_book",      "table": "book",      "record": "b2",      "receiver": "holds"    },    {      "name": "recipe",      "table": "recipe",      "record": "r1",      "receiver": "empty"    },    {      "name": "sealed",      "table": "message",      "record": "x1",      "receiver": "empty"    },    {      "name": "no_shape",      "table": "todo",      "record": "t1",      "receiver": "empty"    }  ],  "made_at": "2026-11-13T09:00:00.000Z",  "sent_at": "2026-11-13T09:05:00.000Z",  "from": {    "number": "+15550100001",    "name": "Test Sender"  },  "expect": {    "book_with_file": {      "payload": {        "format": "cotton.send",        "version": 1,        "id": "send-book_with_file",        "from": {          "number": "+15550100001",          "name": "Test Sender"        },        "made_at": "2026-11-13T09:00:00.000Z",        "source_database": "11111111-1111-4111-8111-111111111111",        "root": {          "table": "book",          "id": "b1"        },        "title": "The Synthetic Garden",        "records": [          {            "table": "book",            "id": "b1",            "data": {              "title": "The Synthetic Garden",              "author": "A. Example",              "cover": "11111111-1111-4111-8111-111111111111/photos/aaaa.jpg",              "file": "11111111-1111-4111-8111-111111111111/books/1111.epub",              "format": "epub",              "isbn": "9780000000001"            },            "role": "root"          }        ],        "files": [          {            "key": "11111111-1111-4111-8111-111111111111/books/1111.epub",            "bytes": 300000          },          {            "key": "11111111-1111-4111-8111-111111111111/photos/aaaa.jpg",            "bytes": 2000          }        ],        "bytes": 302000      },      "held": [],      "landing": {        "creates": [          {            "table": "book",            "id": "af1386a1-8b14-517e-ae06-2b1edb02281b",            "data": {              "title": "The Synthetic Garden",              "author": "A. Example",              "cover": "22222222-2222-4222-8222-222222222222/photos/aaaa.jpg",              "file": "22222222-2222-4222-8222-222222222222/books/1111.epub",              "format": "epub",              "isbn": "9780000000001",              "sent_by": "Test Sender",              "sent_by_number": "+15550100001",              "sent_at": "2026-11-13T09:05:00.000Z",              "send_id": "send-book_with_file"            }          }        ],        "copies": [          {            "from": "11111111-1111-4111-8111-111111111111/books/1111.epub",            "to": "22222222-2222-4222-8222-222222222222/books/1111.epub",            "bytes": 300000          },          {            "from": "11111111-1111-4111-8111-111111111111/photos/aaaa.jpg",            "to": "22222222-2222-4222-8222-222222222222/photos/aaaa.jpg",            "bytes": 2000          }        ],        "held": [],        "bytes": 302000,        "root": {          "table": "book",          "id": "af1386a1-8b14-517e-ae06-2b1edb02281b"        }      }    },    "highlight_alone": {      "payload": {        "format": "cotton.send",        "version": 1,        "id": "send-highlight_alone",        "from": {          "number": "+15550100001",          "name": "Test Sender"        },        "made_at": "2026-11-13T09:00:00.000Z",        "source_database": "11111111-1111-4111-8111-111111111111",        "root": {          "table": "highlight",          "id": "h1"        },        "title": "A sentence worth keeping.",        "records": [          {            "table": "highlight",            "id": "h1",            "data": {              "text": "A sentence worth keeping.",              "note": "Why I kept it",              "colour": "teal",              "chapter": "Three",              "locator": "{\"href\":\"ch3\",\"progression\":0.4}",              "book": "b1"            },            "role": "root"          },          {            "table": "book",            "id": "b1",            "data": {              "title": "The Synthetic Garden",              "author": "A. Example",              "isbn": "9780000000001",              "cover": "11111111-1111-4111-8111-111111111111/photos/aaaa.jpg"            },            "role": "carried"          }        ],        "files": [          {            "key": "11111111-1111-4111-8111-111111111111/photos/aaaa.jpg",            "bytes": 2000          }        ],        "bytes": 2000      },      "held": [],      "landing": {        "creates": [          {            "table": "book",            "id": "2ed9b00c-5c1c-5017-8437-349e08ce8163",            "data": {              "title": "The Synthetic Garden",              "author": "A. Example",              "isbn": "9780000000001",              "cover": "22222222-2222-4222-8222-222222222222/photos/aaaa.jpg",              "sent_by": "Test Sender",              "sent_by_number": "+15550100001",              "sent_at": "2026-11-13T09:05:00.000Z",              "send_id": "send-highlight_alone"            }          },          {            "table": "highlight",            "id": "c8c817ed-742e-56a9-8891-7baa4523dc0e",            "data": {              "text": "A sentence worth keeping.",              "note": "Why I kept it",              "colour": "teal",              "chapter": "Three",              "locator": "{\"href\":\"ch3\",\"progression\":0.4}",              "book": "2ed9b00c-5c1c-5017-8437-349e08ce8163",              "sent_by": "Test Sender",              "sent_by_number": "+15550100001",              "sent_at": "2026-11-13T09:05:00.000Z",              "send_id": "send-highlight_alone"            }          }        ],        "copies": [          {            "from": "11111111-1111-4111-8111-111111111111/photos/aaaa.jpg",            "to": "22222222-2222-4222-8222-222222222222/photos/aaaa.jpg",            "bytes": 2000          }        ],        "held": [],        "bytes": 2000,        "root": {          "table": "highlight",          "id": "c8c817ed-742e-56a9-8891-7baa4523dc0e"        }      }    },    "highlight_book_held": {      "payload": {        "format": "cotton.send",        "version": 1,        "id": "send-highlight_book_held",        "from": {          "number": "+15550100001",          "name": "Test Sender"        },        "made_at": "2026-11-13T09:00:00.000Z",        "source_database": "11111111-1111-4111-8111-111111111111",        "root": {          "table": "highlight",          "id": "h1"        },        "title": "A sentence worth keeping.",        "records": [          {            "table": "highlight",            "id": "h1",            "data": {              "text": "A sentence worth keeping.",              "note": "Why I kept it",              "colour": "teal",              "chapter": "Three",              "locator": "{\"href\":\"ch3\",\"progression\":0.4}",              "book": "b1"            },            "role": "root"          },          {            "table": "book",            "id": "b1",            "data": {              "title": "The Synthetic Garden",              "author": "A. Example",              "isbn": "9780000000001",              "cover": "11111111-1111-4111-8111-111111111111/photos/aaaa.jpg"            },            "role": "carried"          }        ],        "files": [          {            "key": "11111111-1111-4111-8111-111111111111/photos/aaaa.jpg",            "bytes": 2000          }        ],        "bytes": 2000      },      "held": [        {          "table": "book",          "sent": "b1",          "id": "own-b1"        }      ],      "landing": {        "creates": [          {            "table": "highlight",            "id": "0c38d7c5-52bf-5353-8456-65a5feb25c64",            "data": {              "text": "A sentence worth keeping.",              "note": "Why I kept it",              "colour": "teal",              "chapter": "Three",              "locator": "{\"href\":\"ch3\",\"progression\":0.4}",              "book": "own-b1",              "sent_by": "Test Sender",              "sent_by_number": "+15550100001",              "sent_at": "2026-11-13T09:05:00.000Z",              "send_id": "send-highlight_book_held"            }          }        ],        "copies": [],        "held": [          {            "table": "book",            "sent": "b1",            "id": "own-b1"          }        ],        "bytes": 0,        "root": {          "table": "highlight",          "id": "0c38d7c5-52bf-5353-8456-65a5feb25c64"        }      }    },    "list": {      "payload": {        "format": "cotton.send",        "version": 1,        "id": "send-list",        "from": {          "number": "+15550100001",          "name": "Test Sender"        },        "made_at": "2026-11-13T09:00:00.000Z",        "source_database": "11111111-1111-4111-8111-111111111111",        "root": {          "table": "record_group",          "id": "g1"        },        "title": "For the train",        "records": [          {            "table": "record_group",            "id": "g1",            "data": {              "table_id": "book",              "name": "For the train"            },            "role": "root"          },          {            "table": "book",            "id": "b1",            "data": {              "title": "The Synthetic Garden",              "author": "A. Example",              "cover": "11111111-1111-4111-8111-111111111111/photos/aaaa.jpg",              "file": "11111111-1111-4111-8111-111111111111/books/1111.epub",              "format": "epub",              "isbn": "9780000000001"            },            "role": "with"          },          {            "table": "group_member",            "id": "m1",            "data": {              "record_id": "b1",              "place": 1,              "group": "g1"            },            "role": "with"          },          {            "table": "book",            "id": "b2",            "data": {              "title": "Second Test Book",              "author": "B. Example",              "file": "11111111-1111-4111-8111-111111111111/books/2222.pdf",              "format": "pdf"            },            "role": "with"          },          {            "table": "group_member",            "id": "m2",            "data": {              "record_id": "b2",              "place": 2,              "group": "g1"            },            "role": "with"          }        ],        "files": [          {            "key": "11111111-1111-4111-8111-111111111111/books/1111.epub",            "bytes": 300000          },          {            "key": "11111111-1111-4111-8111-111111111111/books/2222.pdf",            "bytes": 500000          },          {            "key": "11111111-1111-4111-8111-111111111111/photos/aaaa.jpg",            "bytes": 2000          }        ],        "bytes": 802000      },      "held": [        {          "table": "book",          "sent": "b1",          "id": "own-b1"        },        {          "table": "book",          "sent": "b2",          "id": "own-b2"        }      ],      "landing": {        "creates": [          {            "table": "record_group",            "id": "7c9c379d-72a3-5bdc-8021-577bccdd0e2d",            "data": {              "table_id": "book",              "name": "For the train",              "sent_by": "Test Sender",              "sent_by_number": "+15550100001",              "sent_at": "2026-11-13T09:05:00.000Z",              "send_id": "send-list"            }          },          {            "table": "group_member",            "id": "d396e1f8-67cf-50cd-a27e-67c96f785b64",            "data": {              "record_id": "own-b1",              "place": 1,              "group": "7c9c379d-72a3-5bdc-8021-577bccdd0e2d",              "sent_by": "Test Sender",              "sent_by_number": "+15550100001",              "sent_at": "2026-11-13T09:05:00.000Z",              "send_id": "send-list"            }          },          {            "table": "group_member",            "id": "73b348ed-51e0-52c6-a65d-e236b74a412e",            "data": {              "record_id": "own-b2",              "place": 2,              "group": "7c9c379d-72a3-5bdc-8021-577bccdd0e2d",              "sent_by": "Test Sender",              "sent_by_number": "+15550100001",              "sent_at": "2026-11-13T09:05:00.000Z",              "send_id": "send-list"            }          }        ],        "copies": [],        "held": [          {            "table": "book",            "sent": "b1",            "id": "own-b1"          },          {            "table": "book",            "sent": "b2",            "id": "own-b2"          }        ],        "bytes": 0,        "root": {          "table": "record_group",          "id": "7c9c379d-72a3-5bdc-8021-577bccdd0e2d"        }      }    },    "duplicate_book": {      "payload": {        "format": "cotton.send",        "version": 1,        "id": "send-duplicate_book",        "from": {          "number": "+15550100001",          "name": "Test Sender"        },        "made_at": "2026-11-13T09:00:00.000Z",        "source_database": "11111111-1111-4111-8111-111111111111",        "root": {          "table": "book",          "id": "b2"        },        "title": "Second Test Book",        "records": [          {            "table": "book",            "id": "b2",            "data": {              "title": "Second Test Book",              "author": "B. Example",              "file": "11111111-1111-4111-8111-111111111111/books/2222.pdf",              "format": "pdf"            },            "role": "root"          }        ],        "files": [          {            "key": "11111111-1111-4111-8111-111111111111/books/2222.pdf",            "bytes": 500000          }        ],        "bytes": 500000      },      "held": [        {          "table": "book",          "sent": "b2",          "id": "own-b2"        }      ],      "landing": {        "creates": [],        "copies": [],        "held": [          {            "table": "book",            "sent": "b2",            "id": "own-b2"          }        ],        "bytes": 0,        "root": {          "table": "book",          "id": "own-b2"        }      }    },    "recipe": {      "payload": {        "format": "cotton.send",        "version": 1,        "id": "send-recipe",        "from": {          "number": "+15550100001",          "name": "Test Sender"        },        "made_at": "2026-11-13T09:00:00.000Z",        "source_database": "11111111-1111-4111-8111-111111111111",        "root": {          "table": "recipe",          "id": "r1"        },        "title": "Test Dal",        "records": [          {            "table": "recipe",            "id": "r1",            "data": {              "title": "Test Dal",              "picture": "11111111-1111-4111-8111-111111111111/photos/dddd.jpg",              "steps": "Boil. Stir."            },            "role": "root"          },          {            "table": "recipe_ingredient",            "id": "i1",            "data": {              "line": "1 cup lentils",              "position": 1,              "recipe": "r1"            },            "role": "with"          },          {            "table": "recipe_ingredient",            "id": "i2",            "data": {              "line": "2 cups water",              "position": 2,              "recipe": "r1"            },            "role": "with"          }        ],        "files": [          {            "key": "11111111-1111-4111-8111-111111111111/photos/dddd.jpg",            "bytes": 1500          }        ],        "bytes": 1500      },      "held": [],      "landing": {        "creates": [          {            "table": "recipe",            "id": "567e0b55-7020-551e-b328-71476ecb8cc1",            "data": {              "title": "Test Dal",              "picture": "22222222-2222-4222-8222-222222222222/photos/dddd.jpg",              "steps": "Boil. Stir.",              "sent_by": "Test Sender",              "sent_by_number": "+15550100001",              "sent_at": "2026-11-13T09:05:00.000Z",              "send_id": "send-recipe"            }          },          {            "table": "recipe_ingredient",            "id": "f353187c-9ea2-5cfb-b31a-c26b7506c400",            "data": {              "line": "1 cup lentils",              "position": 1,              "recipe": "567e0b55-7020-551e-b328-71476ecb8cc1",              "sent_by": "Test Sender",              "sent_by_number": "+15550100001",              "sent_at": "2026-11-13T09:05:00.000Z",              "send_id": "send-recipe"            }          },          {            "table": "recipe_ingredient",            "id": "1b8f1715-9cd6-5de7-914e-e7cb482fd60d",            "data": {              "line": "2 cups water",              "position": 2,              "recipe": "567e0b55-7020-551e-b328-71476ecb8cc1",              "sent_by": "Test Sender",              "sent_by_number": "+15550100001",              "sent_at": "2026-11-13T09:05:00.000Z",              "send_id": "send-recipe"            }          }        ],        "copies": [          {            "from": "11111111-1111-4111-8111-111111111111/photos/dddd.jpg",            "to": "22222222-2222-4222-8222-222222222222/photos/dddd.jpg",            "bytes": 1500          }        ],        "held": [],        "bytes": 1500,        "root": {          "table": "recipe",          "id": "567e0b55-7020-551e-b328-71476ecb8cc1"        }      }    },    "sealed": {      "refused": "not_sendable"    },    "no_shape": {      "refused": "not_sendable"    }  }}