Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

Seanaye/feat/add task projections (#6117)

Sean Ayeda8ba4f680a8
diff --git a/.sqlx/query-58dcd8c3231ed3681efcc9e6acbdd0641d02b34f48e35b2aac077b2fe16a00db.json b/.sqlx/query-58dcd8c3231ed3681efcc9e6acbdd0641d02b34f48e35b2aac077b2fe16a00db.json
new file mode 100644
index 0000000000..997fa0ea6e
--- /dev/null
+++ b/.sqlx/query-58dcd8c3231ed3681efcc9e6acbdd0641d02b34f48e35b2aac077b2fe16a00db.json
@@ -0,0 +1,166 @@
+{
+ "db_name": "PostgreSQL",
+ "query": " \n WITH user_source_ids AS (\n SELECT cp.channel_id::text as source_id FROM comms_channel_participants cp\n WHERE cp.user_id = $1 AND cp.left_at IS NULL\n UNION ALL\n SELECT t.team_id::text FROM team_user t\n WHERE t.user_id = $1\n UNION ALL\n SELECT $1\n ),\n UserAccessibleItems AS (\n SELECT DISTINCT\n ea.entity_id::text as item_id,\n ea.entity_type as item_type\n FROM entity_access ea\n WHERE ea.source_id = ANY(SELECT source_id FROM user_source_ids)\n ),\n Combined AS (\n SELECT\n 'document' as \"item_type!\",\n d.id as \"id!\",\n CAST(COALESCE(di.id, db.id) as TEXT) as \"document_version_id\",\n d.owner as \"user_id!\",\n d.name as \"name!\",\n d.\"branchedFromId\" as \"branched_from_id\",\n d.\"branchedFromVersionId\" as \"branched_from_version_id\",\n d.\"documentFamilyId\" as \"document_family_id\",\n d.\"fileType\" as \"file_type\",\n d.\"createdAt\"::timestamptz as \"created_at!\",\n d.\"updatedAt\"::timestamptz as \"updated_at!\",\n d.\"projectId\" as \"project_id\",\n NULL as \"is_persistent\",\n di.sha as \"sha\",\n dt.sub_type as \"sub_type?: DocumentSubType\",\n EXISTS (\n SELECT 1\n FROM document_email de\n WHERE de.document_id = d.id\n ) as \"is_email_attachment!\",\n (\n dt.sub_type IS DISTINCT FROM 'task'\n OR EXISTS (\n SELECT 1\n FROM entity_properties ep_assignees\n WHERE ep_assignees.entity_id = d.id\n AND ep_assignees.entity_type = 'TASK'\n AND ep_assignees.property_definition_id = $8\n AND ep_assignees.values->'value' @> jsonb_build_array(\n jsonb_build_object('entity_id', $1)\n )\n )\n ) as \"is_important!\",\n ARRAY(\n SELECT status_option_id::uuid\n FROM jsonb_array_elements_text(\n CASE\n WHEN jsonb_typeof(ep_status.values->'value') = 'array'\n THEN ep_status.values->'value'\n ELSE '[]'::jsonb\n END\n ) AS status_option_id\n ) as \"status_option_ids!: Vec<Uuid>\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", d.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN d.\"createdAt\"\n ELSE d.\"updatedAt\"\n END::timestamptz as \"sort_ts!\",\n CASE\n WHEN dt.sub_type = 'task'\n AND ep_status.values->'value' ? $6\n THEN true\n WHEN dt.sub_type = 'task'\n THEN false\n ELSE NULL\n END as \"is_completed\",\n d.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM \"Document\" d\n LEFT JOIN document_sub_type dt ON dt.document_id = d.id\n LEFT JOIN entity_properties ep_status\n ON dt.sub_type = 'task'\n AND ep_status.entity_id = d.id\n AND ep_status.entity_type = 'TASK'\n AND ep_status.property_definition_id = $7\n INNER JOIN UserAccessibleItems uai ON uai.item_id = d.id AND uai.item_type = 'document'\n -- This MUST be a LEFT JOIN to support all three sort methods\n LEFT JOIN \"UserHistory\" uh ON uh.\"itemId\" = d.id AND uh.\"itemType\" = 'document' AND uh.\"userId\" = $1\n LEFT JOIN LATERAL (\n SELECT b.id\n FROM \"DocumentBom\" b\n WHERE b.\"documentId\" = d.id\n ORDER BY b.\"createdAt\" DESC\n LIMIT 1\n ) db ON true\n LEFT JOIN LATERAL (\n SELECT i.id, i.sha\n FROM \"DocumentInstance\" i\n WHERE i.\"documentId\" = d.id\n ORDER BY i.\"updatedAt\" DESC\n LIMIT 1\n ) di ON true\n WHERE d.\"deletedAt\" IS NULL\n\n UNION ALL\n\n SELECT\n 'chat' as \"item_type!\",\n c.id as \"id!\",\n NULL as \"document_version_id\",\n c.\"userId\" as \"user_id!\",\n c.name as \"name!\",\n NULL as \"branched_from_id\",\n NULL as \"branched_from_version_id\",\n NULL as \"document_family_id\",\n NULL as \"file_type\",\n c.\"createdAt\"::timestamptz as \"created_at!\",\n c.\"updatedAt\"::timestamptz as \"updated_at!\",\n c.\"projectId\" as \"project_id\",\n c.\"isPersistent\" as \"is_persistent\",\n NULL as \"sha\",\n NULL as \"sub_type\",\n false as \"is_email_attachment!\",\n true as \"is_important!\",\n ARRAY[]::uuid[] as \"status_option_ids!: Vec<Uuid>\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", c.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN c.\"createdAt\"\n ELSE c.\"updatedAt\"\n END::timestamptz as \"sort_ts!\",\n NULL as \"is_completed\",\n c.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM \"Chat\" c\n INNER JOIN UserAccessibleItems uai ON uai.item_id = c.id AND uai.item_type = 'chat'\n LEFT JOIN \"UserHistory\" uh ON uh.\"itemId\" = c.id AND uh.\"itemType\" = 'chat' AND uh.\"userId\" = $1\n WHERE c.\"deletedAt\" IS NULL\n\n UNION ALL\n\n SELECT\n 'project' as \"item_type!\",\n p.id as \"id!\",\n NULL as \"document_version_id\",\n p.\"userId\" as \"user_id!\",\n p.name as \"name!\",\n NULL as \"branched_from_id\",\n NULL as \"branched_from_version_id\",\n NULL as \"document_family_id\",\n NULL as \"file_type\",\n p.\"createdAt\"::timestamptz as \"created_at!\",\n p.\"updatedAt\"::timestamptz as \"updated_at!\",\n p.\"parentId\" as \"project_id\",\n NULL as \"is_persistent\",\n NULL as \"sha\",\n NULL as \"sub_type\",\n false as \"is_email_attachment!\",\n true as \"is_important!\",\n ARRAY[]::uuid[] as \"status_option_ids!: Vec<Uuid>\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", p.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN p.\"createdAt\"\n ELSE p.\"updatedAt\"\n END::timestamptz as \"sort_ts!\",\n NULL as \"is_completed\",\n p.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM \"Project\" p\n INNER JOIN UserAccessibleItems uai\n ON uai.item_id = p.id\n AND uai.item_type = 'project'\n LEFT JOIN \"UserHistory\" uh\n ON uh.\"itemId\" = p.id\n AND uh.\"itemType\" = 'project'\n AND uh.\"userId\" = $1\n WHERE p.\"deletedAt\" IS NULL\n )\n SELECT Combined.* FROM Combined\n LEFT JOIN frecency_aggregates fa\n ON fa.entity_id = Combined.\"id!\"\n AND fa.entity_type = Combined.\"item_type!\"\n AND fa.user_id = $1\n WHERE fa.id IS NULL\n AND (\n ($4::timestamptz IS NULL)\n OR\n (Combined.\"sort_ts!\", Combined.\"id!\"::text) < ($4, $5)\n )\n ORDER BY Combined.\"sort_ts!\" DESC, Combined.\"id!\" DESC\n LIMIT $3\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "item_type!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "document_version_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "user_id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "name!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 5,
+ "name": "branched_from_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 6,
+ "name": "branched_from_version_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 7,
+ "name": "document_family_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 8,
+ "name": "file_type",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 9,
+ "name": "created_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 10,
+ "name": "updated_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 11,
+ "name": "project_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 12,
+ "name": "is_persistent",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 13,
+ "name": "sha",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 14,
+ "name": "sub_type?: DocumentSubType",
+ "type_info": {
+ "Custom": {
+ "name": "document_sub_type_value",
+ "kind": {
+ "Enum": [
+ "task",
+ "snippet",
+ "skill"
+ ]
+ }
+ }
+ }
+ },
+ {
+ "ordinal": 15,
+ "name": "is_email_attachment!",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 16,
+ "name": "is_important!",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 17,
+ "name": "status_option_ids!: Vec<Uuid>",
+ "type_info": "UuidArray"
+ },
+ {
+ "ordinal": 18,
+ "name": "viewed_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 19,
+ "name": "sort_ts!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 20,
+ "name": "is_completed",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 21,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Int8",
+ "Timestamptz",
+ "Text",
+ "Text",
+ "Uuid",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null
+ ]
+ },
+ "hash": "58dcd8c3231ed3681efcc9e6acbdd0641d02b34f48e35b2aac077b2fe16a00db"
+}
diff --git a/.sqlx/query-73c4071da4ed40b1eaa2f8b1fb498841e1868f43f85bfc501db9384a27ed1eba.json b/.sqlx/query-73c4071da4ed40b1eaa2f8b1fb498841e1868f43f85bfc501db9384a27ed1eba.json
new file mode 100644
index 0000000000..bb8177c93b
--- /dev/null
+++ b/.sqlx/query-73c4071da4ed40b1eaa2f8b1fb498841e1868f43f85bfc501db9384a27ed1eba.json
@@ -0,0 +1,158 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n WITH user_source_ids AS (\n SELECT cp.channel_id::text as source_id FROM comms_channel_participants cp\n WHERE cp.user_id = $1 AND cp.left_at IS NULL\n UNION ALL\n SELECT t.team_id::text FROM team_user t\n WHERE t.user_id = $1\n UNION ALL\n SELECT $1\n ),\n UserAccessibleItems AS (\n SELECT DISTINCT\n ea.entity_id::text as item_id,\n ea.entity_type as item_type\n FROM entity_access ea\n WHERE ea.source_id = ANY(SELECT source_id FROM user_source_ids)\n ),\n Combined AS (\n SELECT\n 'document' as \"item_type!\",\n d.id as \"id!\",\n CAST(COALESCE(di.id, db.id) as TEXT) as \"document_version_id\",\n d.owner as \"user_id!\",\n d.name as \"name!\",\n d.\"branchedFromId\" as \"branched_from_id\",\n d.\"branchedFromVersionId\" as \"branched_from_version_id\",\n d.\"documentFamilyId\" as \"document_family_id\",\n d.\"fileType\" as \"file_type\",\n d.\"createdAt\"::timestamptz as \"created_at!\",\n d.\"updatedAt\"::timestamptz as \"updated_at!\",\n d.\"projectId\" as \"project_id\",\n NULL as \"is_persistent\",\n di.sha as \"sha\",\n dt.sub_type as \"sub_type?: DocumentSubType\",\n EXISTS (\n SELECT 1\n FROM document_email de\n WHERE de.document_id = d.id\n ) as \"is_email_attachment!\",\n (\n dt.sub_type IS DISTINCT FROM 'task'\n OR EXISTS (\n SELECT 1\n FROM entity_properties ep_assignees\n WHERE ep_assignees.entity_id = d.id\n AND ep_assignees.entity_type = 'TASK'\n AND ep_assignees.property_definition_id = $6\n AND ep_assignees.values->'value' @> jsonb_build_array(\n jsonb_build_object('entity_id', $1)\n )\n )\n ) as \"is_important!\",\n ARRAY(\n SELECT status_option_id::uuid\n FROM jsonb_array_elements_text(\n CASE\n WHEN jsonb_typeof(ep_status.values->'value') = 'array'\n THEN ep_status.values->'value'\n ELSE '[]'::jsonb\n END\n ) AS status_option_id\n ) as \"status_option_ids!: Vec<Uuid>\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n CASE\n WHEN dt.sub_type = 'task'\n AND ep_status.values->'value' ? $4\n THEN true\n WHEN dt.sub_type = 'task'\n THEN false\n ELSE NULL\n END as \"is_completed\",\n d.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM \"Document\" d\n LEFT JOIN document_sub_type dt ON dt.document_id = d.id\n LEFT JOIN entity_properties ep_status \n ON dt.sub_type = 'task'\n AND ep_status.entity_id = d.id \n AND ep_status.entity_type = 'TASK'\n AND ep_status.property_definition_id = $5\n INNER JOIN UserAccessibleItems uai \n ON uai.item_id = d.id \n AND uai.item_type = 'document'\n LEFT JOIN \"UserHistory\" uh \n ON uh.\"itemId\" = d.id \n AND uh.\"itemType\" = 'document' \n AND uh.\"userId\" = $1\n LEFT JOIN LATERAL (\n SELECT b.id \n FROM \"DocumentBom\" b \n WHERE b.\"documentId\" = d.id \n ORDER BY b.\"createdAt\" DESC \n LIMIT 1\n ) db ON true\n LEFT JOIN LATERAL (\n SELECT i.id, i.sha \n FROM \"DocumentInstance\" i \n WHERE i.\"documentId\" = d.id \n ORDER BY i.\"updatedAt\" DESC \n LIMIT 1\n ) di ON true\n WHERE d.\"deletedAt\" IS NULL\n AND d.id = ANY($2::text[])\n\n UNION ALL\n \n SELECT\n 'chat' as \"item_type!\",\n c.id as \"id!\",\n NULL as \"document_version_id\",\n c.\"userId\" as \"user_id!\",\n c.name as \"name!\",\n NULL as \"branched_from_id\",\n NULL as \"branched_from_version_id\",\n NULL as \"document_family_id\",\n NULL as \"file_type\",\n c.\"createdAt\"::timestamptz as \"created_at!\",\n c.\"updatedAt\"::timestamptz as \"updated_at!\",\n c.\"projectId\" as \"project_id\",\n c.\"isPersistent\" as \"is_persistent\",\n NULL as \"sha\",\n NULL as \"sub_type\",\n false as \"is_email_attachment!\",\n true as \"is_important!\",\n ARRAY[]::uuid[] as \"status_option_ids!: Vec<Uuid>\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n NULL as \"is_completed\",\n c.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM \"Chat\" c\n INNER JOIN UserAccessibleItems uai\n ON uai.item_id = c.id\n AND uai.item_type = 'chat'\n LEFT JOIN \"UserHistory\" uh\n ON uh.\"itemId\" = c.id\n AND uh.\"itemType\" = 'chat'\n AND uh.\"userId\" = $1\n WHERE c.\"deletedAt\" IS NULL\n AND c.id = ANY($3::text[])\n )\n SELECT * \n FROM Combined\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "item_type!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "document_version_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "user_id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "name!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 5,
+ "name": "branched_from_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 6,
+ "name": "branched_from_version_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 7,
+ "name": "document_family_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 8,
+ "name": "file_type",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 9,
+ "name": "created_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 10,
+ "name": "updated_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 11,
+ "name": "project_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 12,
+ "name": "is_persistent",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 13,
+ "name": "sha",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 14,
+ "name": "sub_type?: DocumentSubType",
+ "type_info": {
+ "Custom": {
+ "name": "document_sub_type_value",
+ "kind": {
+ "Enum": [
+ "task",
+ "snippet",
+ "skill"
+ ]
+ }
+ }
+ }
+ },
+ {
+ "ordinal": 15,
+ "name": "is_email_attachment!",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 16,
+ "name": "is_important!",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 17,
+ "name": "status_option_ids!: Vec<Uuid>",
+ "type_info": "UuidArray"
+ },
+ {
+ "ordinal": 18,
+ "name": "viewed_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 19,
+ "name": "is_completed",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 20,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "TextArray",
+ "TextArray",
+ "Text",
+ "Uuid",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null
+ ]
+ },
+ "hash": "73c4071da4ed40b1eaa2f8b1fb498841e1868f43f85bfc501db9384a27ed1eba"
+}
diff --git a/.sqlx/query-8579e27d0c397a032e967d70e5234ce7cbe591071a2fa1f65da0c7fe6536d691.json b/.sqlx/query-8579e27d0c397a032e967d70e5234ce7cbe591071a2fa1f65da0c7fe6536d691.json
deleted file mode 100644
index cc7f98a1b1..0000000000
--- a/.sqlx/query-8579e27d0c397a032e967d70e5234ce7cbe591071a2fa1f65da0c7fe6536d691.json
+++ /dev/null
@@ -1,153 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": " \n WITH user_source_ids AS (\n SELECT cp.channel_id::text as source_id FROM comms_channel_participants cp\n WHERE cp.user_id = $1 AND cp.left_at IS NULL\n UNION ALL\n SELECT t.team_id::text FROM team_user t\n WHERE t.user_id = $1\n UNION ALL\n SELECT $1\n ),\n UserAccessibleItems AS (\n SELECT DISTINCT\n ea.entity_id::text as item_id,\n ea.entity_type as item_type\n FROM entity_access ea\n WHERE ea.source_id = ANY(SELECT source_id FROM user_source_ids)\n ),\n Combined AS (\n SELECT\n 'document' as \"item_type!\",\n d.id as \"id!\",\n CAST(COALESCE(di.id, db.id) as TEXT) as \"document_version_id\",\n d.owner as \"user_id!\",\n d.name as \"name!\",\n d.\"branchedFromId\" as \"branched_from_id\",\n d.\"branchedFromVersionId\" as \"branched_from_version_id\",\n d.\"documentFamilyId\" as \"document_family_id\",\n d.\"fileType\" as \"file_type\",\n d.\"createdAt\"::timestamptz as \"created_at!\",\n d.\"updatedAt\"::timestamptz as \"updated_at!\",\n d.\"projectId\" as \"project_id\",\n NULL as \"is_persistent\",\n di.sha as \"sha\",\n dt.sub_type as \"sub_type?: DocumentSubType\",\n EXISTS (\n SELECT 1\n FROM document_email de\n WHERE de.document_id = d.id\n ) as \"is_email_attachment!\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", d.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN d.\"createdAt\"\n ELSE d.\"updatedAt\"\n END::timestamptz as \"sort_ts!\",\n CASE\n WHEN dt.sub_type = 'task'\n AND ep_status.values->'value' ? $6\n THEN true\n WHEN dt.sub_type = 'task'\n THEN false\n ELSE NULL\n END as \"is_completed\",\n d.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM \"Document\" d\n LEFT JOIN document_sub_type dt ON dt.document_id = d.id\n LEFT JOIN entity_properties ep_status\n ON dt.sub_type = 'task'\n AND ep_status.entity_id = d.id\n AND ep_status.entity_type = 'TASK'\n AND ep_status.property_definition_id = $7\n INNER JOIN UserAccessibleItems uai ON uai.item_id = d.id AND uai.item_type = 'document'\n -- This MUST be a LEFT JOIN to support all three sort methods\n LEFT JOIN \"UserHistory\" uh ON uh.\"itemId\" = d.id AND uh.\"itemType\" = 'document' AND uh.\"userId\" = $1\n LEFT JOIN LATERAL (\n SELECT b.id\n FROM \"DocumentBom\" b\n WHERE b.\"documentId\" = d.id\n ORDER BY b.\"createdAt\" DESC\n LIMIT 1\n ) db ON true\n LEFT JOIN LATERAL (\n SELECT i.id, i.sha\n FROM \"DocumentInstance\" i\n WHERE i.\"documentId\" = d.id\n ORDER BY i.\"updatedAt\" DESC\n LIMIT 1\n ) di ON true\n WHERE d.\"deletedAt\" IS NULL\n\n UNION ALL\n\n SELECT\n 'chat' as \"item_type!\",\n c.id as \"id!\",\n NULL as \"document_version_id\",\n c.\"userId\" as \"user_id!\",\n c.name as \"name!\",\n NULL as \"branched_from_id\",\n NULL as \"branched_from_version_id\",\n NULL as \"document_family_id\",\n NULL as \"file_type\",\n c.\"createdAt\"::timestamptz as \"created_at!\",\n c.\"updatedAt\"::timestamptz as \"updated_at!\",\n c.\"projectId\" as \"project_id\",\n c.\"isPersistent\" as \"is_persistent\",\n NULL as \"sha\",\n NULL as \"sub_type\",\n false as \"is_email_attachment!\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", c.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN c.\"createdAt\"\n ELSE c.\"updatedAt\"\n END::timestamptz as \"sort_ts!\",\n NULL as \"is_completed\",\n c.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM \"Chat\" c\n INNER JOIN UserAccessibleItems uai ON uai.item_id = c.id AND uai.item_type = 'chat'\n LEFT JOIN \"UserHistory\" uh ON uh.\"itemId\" = c.id AND uh.\"itemType\" = 'chat' AND uh.\"userId\" = $1\n WHERE c.\"deletedAt\" IS NULL\n\n UNION ALL\n\n SELECT\n 'project' as \"item_type!\",\n p.id as \"id!\",\n NULL as \"document_version_id\",\n p.\"userId\" as \"user_id!\",\n p.name as \"name!\",\n NULL as \"branched_from_id\",\n NULL as \"branched_from_version_id\",\n NULL as \"document_family_id\",\n NULL as \"file_type\",\n p.\"createdAt\"::timestamptz as \"created_at!\",\n p.\"updatedAt\"::timestamptz as \"updated_at!\",\n p.\"parentId\" as \"project_id\",\n NULL as \"is_persistent\",\n NULL as \"sha\",\n NULL as \"sub_type\",\n false as \"is_email_attachment!\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", p.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN p.\"createdAt\"\n ELSE p.\"updatedAt\"\n END::timestamptz as \"sort_ts!\",\n NULL as \"is_completed\",\n p.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM \"Project\" p\n INNER JOIN UserAccessibleItems uai\n ON uai.item_id = p.id\n AND uai.item_type = 'project'\n LEFT JOIN \"UserHistory\" uh\n ON uh.\"itemId\" = p.id\n AND uh.\"itemType\" = 'project'\n AND uh.\"userId\" = $1\n WHERE p.\"deletedAt\" IS NULL\n )\n SELECT Combined.* FROM Combined\n LEFT JOIN frecency_aggregates fa\n ON fa.entity_id = Combined.\"id!\"\n AND fa.entity_type = Combined.\"item_type!\"\n AND fa.user_id = $1\n WHERE fa.id IS NULL\n AND (\n ($4::timestamptz IS NULL)\n OR\n (Combined.\"sort_ts!\", Combined.\"id!\"::text) < ($4, $5)\n )\n ORDER BY Combined.\"sort_ts!\" DESC, Combined.\"id!\" DESC\n LIMIT $3\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "item_type!",
- "type_info": "Text"
- },
- {
- "ordinal": 1,
- "name": "id!",
- "type_info": "Text"
- },
- {
- "ordinal": 2,
- "name": "document_version_id",
- "type_info": "Text"
- },
- {
- "ordinal": 3,
- "name": "user_id!",
- "type_info": "Text"
- },
- {
- "ordinal": 4,
- "name": "name!",
- "type_info": "Text"
- },
- {
- "ordinal": 5,
- "name": "branched_from_id",
- "type_info": "Text"
- },
- {
- "ordinal": 6,
- "name": "branched_from_version_id",
- "type_info": "Int8"
- },
- {
- "ordinal": 7,
- "name": "document_family_id",
- "type_info": "Int8"
- },
- {
- "ordinal": 8,
- "name": "file_type",
- "type_info": "Text"
- },
- {
- "ordinal": 9,
- "name": "created_at!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 10,
- "name": "updated_at!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 11,
- "name": "project_id",
- "type_info": "Text"
- },
- {
- "ordinal": 12,
- "name": "is_persistent",
- "type_info": "Bool"
- },
- {
- "ordinal": 13,
- "name": "sha",
- "type_info": "Text"
- },
- {
- "ordinal": 14,
- "name": "sub_type?: DocumentSubType",
- "type_info": {
- "Custom": {
- "name": "document_sub_type_value",
- "kind": {
- "Enum": [
- "task",
- "snippet",
- "skill"
- ]
- }
- }
- }
- },
- {
- "ordinal": 15,
- "name": "is_email_attachment!",
- "type_info": "Bool"
- },
- {
- "ordinal": 16,
- "name": "viewed_at",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 17,
- "name": "sort_ts!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 18,
- "name": "is_completed",
- "type_info": "Bool"
- },
- {
- "ordinal": 19,
- "name": "deleted_at",
- "type_info": "Timestamptz"
- }
- ],
- "parameters": {
- "Left": [
- "Text",
- "Text",
- "Int8",
- "Timestamptz",
- "Text",
- "Text",
- "Uuid"
- ]
- },
- "nullable": [
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null
- ]
- },
- "hash": "8579e27d0c397a032e967d70e5234ce7cbe591071a2fa1f65da0c7fe6536d691"
-}
diff --git a/.sqlx/query-7534a0b8bd8f03e17d0109d031da55d80d43a14a01124781384563d939236245.json b/.sqlx/query-c22f782cbd620dc831763981afc9fc9e83c8dbf3629271b5f678eefcce9d9ada.json
similarity index 57%
rename from .sqlx/query-7534a0b8bd8f03e17d0109d031da55d80d43a14a01124781384563d939236245.json
rename to .sqlx/query-c22f782cbd620dc831763981afc9fc9e83c8dbf3629271b5f678eefcce9d9ada.json
index f5c36657b4..2d57d08760 100644
--- a/.sqlx/query-7534a0b8bd8f03e17d0109d031da55d80d43a14a01124781384563d939236245.json
+++ b/.sqlx/query-c22f782cbd620dc831763981afc9fc9e83c8dbf3629271b5f678eefcce9d9ada.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "\n -- =============================================================================\n -- EXPANDED GENERIC CURSOR SOUP QUERY\n -- =============================================================================\n -- Retrieves all items (documents, chats, projects) that a user has access to,\n -- including both explicit permissions and inherited permissions through the\n -- project hierarchy.\n -- =============================================================================\n\n WITH user_source_ids AS (\n SELECT cp.channel_id::text as source_id FROM comms_channel_participants cp\n WHERE cp.user_id = $1 AND cp.left_at IS NULL\n UNION ALL\n SELECT t.team_id::text FROM team_user t\n WHERE t.user_id = $1\n UNION ALL\n SELECT $1\n ),\n\n UserAccessibleItems AS (\n SELECT DISTINCT\n ea.entity_id::text as item_id,\n ea.entity_type as item_type\n FROM entity_access ea\n WHERE ea.source_id = ANY(SELECT source_id FROM user_source_ids)\n ),\n\n -- Identify the top N items with minimal columns before joining full details.\n -- Performs early filtering and sorting to reduce the data processed in\n -- subsequent joins.\n TopItems AS (\n SELECT item_type, id, sort_ts, updated_at FROM (\n SELECT\n 'document'::text as item_type,\n d.id,\n -- Dynamic sort column based on user's selected sort method\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", d.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN d.\"createdAt\"\n ELSE d.\"updatedAt\"\n END::timestamptz as sort_ts,\n d.\"updatedAt\"::timestamptz as updated_at\n FROM \"Document\" d\n INNER JOIN UserAccessibleItems uai ON uai.item_id = d.id AND uai.item_type = 'document'\n LEFT JOIN \"UserHistory\" uh ON uh.\"itemId\" = d.id AND uh.\"itemType\" = 'document' AND uh.\"userId\" = $1\n WHERE d.\"deletedAt\" IS NULL\n\n UNION ALL\n\n SELECT\n 'chat'::text,\n c.id,\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", c.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN c.\"createdAt\"\n ELSE c.\"updatedAt\"\n END::timestamptz,\n c.\"updatedAt\"::timestamptz\n FROM \"Chat\" c\n INNER JOIN UserAccessibleItems uai ON uai.item_id = c.id AND uai.item_type = 'chat'\n LEFT JOIN \"UserHistory\" uh ON uh.\"itemId\" = c.id AND uh.\"itemType\" = 'chat' AND uh.\"userId\" = $1\n WHERE c.\"deletedAt\" IS NULL\n\n UNION ALL\n\n SELECT\n 'project'::text,\n p.id,\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", p.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN p.\"createdAt\"\n ELSE p.\"updatedAt\"\n END::timestamptz,\n p.\"updatedAt\"::timestamptz\n FROM \"Project\" p\n INNER JOIN UserAccessibleItems uai ON uai.item_id = p.id AND uai.item_type = 'project'\n LEFT JOIN \"UserHistory\" uh ON uh.\"itemId\" = p.id AND uh.\"itemType\" = 'project' AND uh.\"userId\" = $1\n WHERE p.\"deletedAt\" IS NULL\n ) all_items\n WHERE\n -- Cursor-based pagination: skip items we've already seen.\n -- NULL cursor means first page (no items to skip).\n ($4::timestamptz IS NULL)\n OR\n -- Seek method: find items \"before\" the cursor position\n -- using (sort_ts, id) tuple comparison for deterministic ordering\n (sort_ts, id::text) < ($4, $5)\n ORDER BY sort_ts DESC, id DESC\n LIMIT $3\n )\n\n -- Join full item details only for the filtered top items.\n SELECT * FROM (\n SELECT\n 'document' as \"item_type!\",\n d.id as \"id!\",\n CAST(COALESCE(di.id, db.id) as TEXT) as \"document_version_id\",\n d.owner as \"user_id!\",\n d.name as \"name!\",\n d.\"branchedFromId\" as \"branched_from_id\",\n d.\"branchedFromVersionId\" as \"branched_from_version_id\",\n d.\"documentFamilyId\" as \"document_family_id\",\n d.\"fileType\" as \"file_type\",\n d.\"createdAt\"::timestamptz as \"created_at!\",\n d.\"updatedAt\"::timestamptz as \"updated_at!\",\n d.\"projectId\" as \"project_id\",\n NULL as \"is_persistent\",\n di.sha as \"sha\",\n dt.sub_type as \"sub_type?: DocumentSubType\",\n EXISTS (\n SELECT 1\n FROM document_email de\n WHERE de.document_id = d.id\n ) as \"is_email_attachment!\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n t.sort_ts as \"sort_ts!\",\n -- Task completion status: check if status property matches \"completed\"\n CASE\n WHEN dt.sub_type = 'task'\n AND ep_status.values->'value' ? $6\n THEN true\n WHEN dt.sub_type = 'task'\n THEN false\n ELSE NULL\n END as \"is_completed\",\n d.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM TopItems t\n INNER JOIN \"Document\" d ON d.id = t.id\n LEFT JOIN document_sub_type dt ON dt.document_id = d.id\n LEFT JOIN entity_properties ep_status\n ON dt.sub_type = 'task'\n AND ep_status.entity_id = d.id\n AND ep_status.entity_type = 'TASK'\n AND ep_status.property_definition_id = $7\n LEFT JOIN \"UserHistory\" uh\n ON uh.\"itemId\" = d.id AND uh.\"itemType\" = 'document' AND uh.\"userId\" = $1\n -- LATERAL joins to get the latest version info\n LEFT JOIN LATERAL (\n SELECT b.id\n FROM \"DocumentBom\" b\n WHERE b.\"documentId\" = d.id\n ORDER BY b.\"createdAt\" DESC\n LIMIT 1\n ) db ON true\n LEFT JOIN LATERAL (\n SELECT i.id, i.sha\n FROM \"DocumentInstance\" i\n WHERE i.\"documentId\" = d.id\n ORDER BY i.\"updatedAt\" DESC\n LIMIT 1\n ) di ON true\n WHERE t.item_type = 'document'\n\n UNION ALL\n\n SELECT\n 'chat' as \"item_type!\",\n c.id as \"id!\",\n NULL as \"document_version_id\",\n c.\"userId\" as \"user_id!\",\n c.name as \"name!\",\n NULL as \"branched_from_id\",\n NULL as \"branched_from_version_id\",\n NULL as \"document_family_id\",\n NULL as \"file_type\",\n c.\"createdAt\"::timestamptz as \"created_at!\",\n c.\"updatedAt\"::timestamptz as \"updated_at!\",\n c.\"projectId\" as \"project_id\",\n c.\"isPersistent\" as \"is_persistent\",\n NULL as \"sha\",\n NULL as \"sub_type\",\n false as \"is_email_attachment!\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n t.sort_ts as \"sort_ts!\",\n NULL as \"is_completed\",\n c.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM TopItems t\n INNER JOIN \"Chat\" c ON c.id = t.id\n LEFT JOIN \"UserHistory\" uh\n ON uh.\"itemId\" = c.id AND uh.\"itemType\" = 'chat' AND uh.\"userId\" = $1\n WHERE t.item_type = 'chat'\n\n UNION ALL\n\n SELECT\n 'project' as \"item_type!\",\n p.id as \"id!\",\n NULL as \"document_version_id\",\n p.\"userId\" as \"user_id!\",\n p.name as \"name!\",\n NULL as \"branched_from_id\",\n NULL as \"branched_from_version_id\",\n NULL as \"document_family_id\",\n NULL as \"file_type\",\n p.\"createdAt\"::timestamptz as \"created_at!\",\n p.\"updatedAt\"::timestamptz as \"updated_at!\",\n p.\"parentId\" as \"project_id\",\n NULL as \"is_persistent\",\n NULL as \"sha\",\n NULL as \"sub_type\",\n false as \"is_email_attachment!\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n t.sort_ts as \"sort_ts!\",\n NULL as \"is_completed\",\n p.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM TopItems t\n INNER JOIN \"Project\" p ON p.id = t.id\n LEFT JOIN \"UserHistory\" uh\n ON uh.\"itemId\" = p.id AND uh.\"itemType\" = 'project' AND uh.\"userId\" = $1\n WHERE t.item_type = 'project'\n ) Combined\n -- Sort by timestamp descending, with ID as tiebreaker for deterministic pagination.\n -- This ensures consistent ordering when multiple items share the same timestamp,\n -- preventing items from being skipped or duplicated across pages.\n ORDER BY \"sort_ts!\" DESC, \"id!\" DESC\n LIMIT $3\n",
+ "query": "\n -- =============================================================================\n -- EXPANDED GENERIC CURSOR SOUP QUERY\n -- =============================================================================\n -- Retrieves all items (documents, chats, projects) that a user has access to,\n -- including both explicit permissions and inherited permissions through the\n -- project hierarchy.\n -- =============================================================================\n\n WITH user_source_ids AS (\n SELECT cp.channel_id::text as source_id FROM comms_channel_participants cp\n WHERE cp.user_id = $1 AND cp.left_at IS NULL\n UNION ALL\n SELECT t.team_id::text FROM team_user t\n WHERE t.user_id = $1\n UNION ALL\n SELECT $1\n ),\n\n UserAccessibleItems AS (\n SELECT DISTINCT\n ea.entity_id::text as item_id,\n ea.entity_type as item_type\n FROM entity_access ea\n WHERE ea.source_id = ANY(SELECT source_id FROM user_source_ids)\n ),\n\n -- Identify the top N items with minimal columns before joining full details.\n -- Performs early filtering and sorting to reduce the data processed in\n -- subsequent joins.\n TopItems AS (\n SELECT item_type, id, sort_ts, updated_at FROM (\n SELECT\n 'document'::text as item_type,\n d.id,\n -- Dynamic sort column based on user's selected sort method\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", d.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN d.\"createdAt\"\n ELSE d.\"updatedAt\"\n END::timestamptz as sort_ts,\n d.\"updatedAt\"::timestamptz as updated_at\n FROM \"Document\" d\n INNER JOIN UserAccessibleItems uai ON uai.item_id = d.id AND uai.item_type = 'document'\n LEFT JOIN \"UserHistory\" uh ON uh.\"itemId\" = d.id AND uh.\"itemType\" = 'document' AND uh.\"userId\" = $1\n WHERE d.\"deletedAt\" IS NULL\n\n UNION ALL\n\n SELECT\n 'chat'::text,\n c.id,\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", c.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN c.\"createdAt\"\n ELSE c.\"updatedAt\"\n END::timestamptz,\n c.\"updatedAt\"::timestamptz\n FROM \"Chat\" c\n INNER JOIN UserAccessibleItems uai ON uai.item_id = c.id AND uai.item_type = 'chat'\n LEFT JOIN \"UserHistory\" uh ON uh.\"itemId\" = c.id AND uh.\"itemType\" = 'chat' AND uh.\"userId\" = $1\n WHERE c.\"deletedAt\" IS NULL\n\n UNION ALL\n\n SELECT\n 'project'::text,\n p.id,\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", p.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN p.\"createdAt\"\n ELSE p.\"updatedAt\"\n END::timestamptz,\n p.\"updatedAt\"::timestamptz\n FROM \"Project\" p\n INNER JOIN UserAccessibleItems uai ON uai.item_id = p.id AND uai.item_type = 'project'\n LEFT JOIN \"UserHistory\" uh ON uh.\"itemId\" = p.id AND uh.\"itemType\" = 'project' AND uh.\"userId\" = $1\n WHERE p.\"deletedAt\" IS NULL\n ) all_items\n WHERE\n -- Cursor-based pagination: skip items we've already seen.\n -- NULL cursor means first page (no items to skip).\n ($4::timestamptz IS NULL)\n OR\n -- Seek method: find items \"before\" the cursor position\n -- using (sort_ts, id) tuple comparison for deterministic ordering\n (sort_ts, id::text) < ($4, $5)\n ORDER BY sort_ts DESC, id DESC\n LIMIT $3\n )\n\n -- Join full item details only for the filtered top items.\n SELECT * FROM (\n SELECT\n 'document' as \"item_type!\",\n d.id as \"id!\",\n CAST(COALESCE(di.id, db.id) as TEXT) as \"document_version_id\",\n d.owner as \"user_id!\",\n d.name as \"name!\",\n d.\"branchedFromId\" as \"branched_from_id\",\n d.\"branchedFromVersionId\" as \"branched_from_version_id\",\n d.\"documentFamilyId\" as \"document_family_id\",\n d.\"fileType\" as \"file_type\",\n d.\"createdAt\"::timestamptz as \"created_at!\",\n d.\"updatedAt\"::timestamptz as \"updated_at!\",\n d.\"projectId\" as \"project_id\",\n NULL as \"is_persistent\",\n di.sha as \"sha\",\n dt.sub_type as \"sub_type?: DocumentSubType\",\n EXISTS (\n SELECT 1\n FROM document_email de\n WHERE de.document_id = d.id\n ) as \"is_email_attachment!\",\n (\n dt.sub_type IS DISTINCT FROM 'task'\n OR EXISTS (\n SELECT 1\n FROM entity_properties ep_assignees\n WHERE ep_assignees.entity_id = d.id\n AND ep_assignees.entity_type = 'TASK'\n AND ep_assignees.property_definition_id = $8\n AND ep_assignees.values->'value' @> jsonb_build_array(\n jsonb_build_object('entity_id', $1)\n )\n )\n ) as \"is_important!\",\n ARRAY(\n SELECT status_option_id::uuid\n FROM jsonb_array_elements_text(\n CASE\n WHEN jsonb_typeof(ep_status.values->'value') = 'array'\n THEN ep_status.values->'value'\n ELSE '[]'::jsonb\n END\n ) AS status_option_id\n ) as \"status_option_ids!: Vec<Uuid>\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n t.sort_ts as \"sort_ts!\",\n -- Task completion status: check if status property matches \"completed\"\n CASE\n WHEN dt.sub_type = 'task'\n AND ep_status.values->'value' ? $6\n THEN true\n WHEN dt.sub_type = 'task'\n THEN false\n ELSE NULL\n END as \"is_completed\",\n d.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM TopItems t\n INNER JOIN \"Document\" d ON d.id = t.id\n LEFT JOIN document_sub_type dt ON dt.document_id = d.id\n LEFT JOIN entity_properties ep_status\n ON dt.sub_type = 'task'\n AND ep_status.entity_id = d.id\n AND ep_status.entity_type = 'TASK'\n AND ep_status.property_definition_id = $7\n LEFT JOIN \"UserHistory\" uh\n ON uh.\"itemId\" = d.id AND uh.\"itemType\" = 'document' AND uh.\"userId\" = $1\n -- LATERAL joins to get the latest version info\n LEFT JOIN LATERAL (\n SELECT b.id\n FROM \"DocumentBom\" b\n WHERE b.\"documentId\" = d.id\n ORDER BY b.\"createdAt\" DESC\n LIMIT 1\n ) db ON true\n LEFT JOIN LATERAL (\n SELECT i.id, i.sha\n FROM \"DocumentInstance\" i\n WHERE i.\"documentId\" = d.id\n ORDER BY i.\"updatedAt\" DESC\n LIMIT 1\n ) di ON true\n WHERE t.item_type = 'document'\n\n UNION ALL\n\n SELECT\n 'chat' as \"item_type!\",\n c.id as \"id!\",\n NULL as \"document_version_id\",\n c.\"userId\" as \"user_id!\",\n c.name as \"name!\",\n NULL as \"branched_from_id\",\n NULL as \"branched_from_version_id\",\n NULL as \"document_family_id\",\n NULL as \"file_type\",\n c.\"createdAt\"::timestamptz as \"created_at!\",\n c.\"updatedAt\"::timestamptz as \"updated_at!\",\n c.\"projectId\" as \"project_id\",\n c.\"isPersistent\" as \"is_persistent\",\n NULL as \"sha\",\n NULL as \"sub_type\",\n false as \"is_email_attachment!\",\n true as \"is_important!\",\n ARRAY[]::uuid[] as \"status_option_ids!: Vec<Uuid>\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n t.sort_ts as \"sort_ts!\",\n NULL as \"is_completed\",\n c.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM TopItems t\n INNER JOIN \"Chat\" c ON c.id = t.id\n LEFT JOIN \"UserHistory\" uh\n ON uh.\"itemId\" = c.id AND uh.\"itemType\" = 'chat' AND uh.\"userId\" = $1\n WHERE t.item_type = 'chat'\n\n UNION ALL\n\n SELECT\n 'project' as \"item_type!\",\n p.id as \"id!\",\n NULL as \"document_version_id\",\n p.\"userId\" as \"user_id!\",\n p.name as \"name!\",\n NULL as \"branched_from_id\",\n NULL as \"branched_from_version_id\",\n NULL as \"document_family_id\",\n NULL as \"file_type\",\n p.\"createdAt\"::timestamptz as \"created_at!\",\n p.\"updatedAt\"::timestamptz as \"updated_at!\",\n p.\"parentId\" as \"project_id\",\n NULL as \"is_persistent\",\n NULL as \"sha\",\n NULL as \"sub_type\",\n false as \"is_email_attachment!\",\n true as \"is_important!\",\n ARRAY[]::uuid[] as \"status_option_ids!: Vec<Uuid>\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n t.sort_ts as \"sort_ts!\",\n NULL as \"is_completed\",\n p.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM TopItems t\n INNER JOIN \"Project\" p ON p.id = t.id\n LEFT JOIN \"UserHistory\" uh\n ON uh.\"itemId\" = p.id AND uh.\"itemType\" = 'project' AND uh.\"userId\" = $1\n WHERE t.item_type = 'project'\n ) Combined\n -- Sort by timestamp descending, with ID as tiebreaker for deterministic pagination.\n -- This ensures consistent ordering when multiple items share the same timestamp,\n -- preventing items from being skipped or duplicated across pages.\n ORDER BY \"sort_ts!\" DESC, \"id!\" DESC\n LIMIT $3\n",
"describe": {
"columns": [
{
@@ -96,21 +96,31 @@
},
{
"ordinal": 16,
+ "name": "is_important!",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 17,
+ "name": "status_option_ids!: Vec<Uuid>",
+ "type_info": "UuidArray"
+ },
+ {
+ "ordinal": 18,
"name": "viewed_at",
"type_info": "Timestamptz"
},
{
- "ordinal": 17,
+ "ordinal": 19,
"name": "sort_ts!",
"type_info": "Timestamptz"
},
{
- "ordinal": 18,
+ "ordinal": 20,
"name": "is_completed",
"type_info": "Bool"
},
{
- "ordinal": 19,
+ "ordinal": 21,
"name": "deleted_at",
"type_info": "Timestamptz"
}
@@ -123,6 +133,7 @@
"Timestamptz",
"Text",
"Text",
+ "Uuid",
"Uuid"
]
},
@@ -146,8 +157,10 @@
null,
null,
null,
+ null,
+ null,
null
]
},
- "hash": "7534a0b8bd8f03e17d0109d031da55d80d43a14a01124781384563d939236245"
+ "hash": "c22f782cbd620dc831763981afc9fc9e83c8dbf3629271b5f678eefcce9d9ada"
}
diff --git a/.sqlx/query-e17976f1992e4a4ec26b0f2fca80cec95d1f155e69b6166f6bfcebe814c314f0.json b/.sqlx/query-e17976f1992e4a4ec26b0f2fca80cec95d1f155e69b6166f6bfcebe814c314f0.json
deleted file mode 100644
index 781dea68d2..0000000000
--- a/.sqlx/query-e17976f1992e4a4ec26b0f2fca80cec95d1f155e69b6166f6bfcebe814c314f0.json
+++ /dev/null
@@ -1,145 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n WITH user_source_ids AS (\n SELECT cp.channel_id::text as source_id FROM comms_channel_participants cp\n WHERE cp.user_id = $1 AND cp.left_at IS NULL\n UNION ALL\n SELECT t.team_id::text FROM team_user t\n WHERE t.user_id = $1\n UNION ALL\n SELECT $1\n ),\n UserAccessibleItems AS (\n SELECT DISTINCT\n ea.entity_id::text as item_id,\n ea.entity_type as item_type\n FROM entity_access ea\n WHERE ea.source_id = ANY(SELECT source_id FROM user_source_ids)\n ),\n Combined AS (\n SELECT\n 'document' as \"item_type!\",\n d.id as \"id!\",\n CAST(COALESCE(di.id, db.id) as TEXT) as \"document_version_id\",\n d.owner as \"user_id!\",\n d.name as \"name!\",\n d.\"branchedFromId\" as \"branched_from_id\",\n d.\"branchedFromVersionId\" as \"branched_from_version_id\",\n d.\"documentFamilyId\" as \"document_family_id\",\n d.\"fileType\" as \"file_type\",\n d.\"createdAt\"::timestamptz as \"created_at!\",\n d.\"updatedAt\"::timestamptz as \"updated_at!\",\n d.\"projectId\" as \"project_id\",\n NULL as \"is_persistent\",\n di.sha as \"sha\",\n dt.sub_type as \"sub_type?: DocumentSubType\",\n EXISTS (\n SELECT 1\n FROM document_email de\n WHERE de.document_id = d.id\n ) as \"is_email_attachment!\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n CASE\n WHEN dt.sub_type = 'task'\n AND ep_status.values->'value' ? $4\n THEN true\n WHEN dt.sub_type = 'task'\n THEN false\n ELSE NULL\n END as \"is_completed\",\n d.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM \"Document\" d\n LEFT JOIN document_sub_type dt ON dt.document_id = d.id\n LEFT JOIN entity_properties ep_status \n ON dt.sub_type = 'task'\n AND ep_status.entity_id = d.id \n AND ep_status.entity_type = 'TASK'\n AND ep_status.property_definition_id = $5\n INNER JOIN UserAccessibleItems uai \n ON uai.item_id = d.id \n AND uai.item_type = 'document'\n LEFT JOIN \"UserHistory\" uh \n ON uh.\"itemId\" = d.id \n AND uh.\"itemType\" = 'document' \n AND uh.\"userId\" = $1\n LEFT JOIN LATERAL (\n SELECT b.id \n FROM \"DocumentBom\" b \n WHERE b.\"documentId\" = d.id \n ORDER BY b.\"createdAt\" DESC \n LIMIT 1\n ) db ON true\n LEFT JOIN LATERAL (\n SELECT i.id, i.sha \n FROM \"DocumentInstance\" i \n WHERE i.\"documentId\" = d.id \n ORDER BY i.\"updatedAt\" DESC \n LIMIT 1\n ) di ON true\n WHERE d.\"deletedAt\" IS NULL\n AND d.id = ANY($2::text[])\n\n UNION ALL\n \n SELECT\n 'chat' as \"item_type!\",\n c.id as \"id!\",\n NULL as \"document_version_id\",\n c.\"userId\" as \"user_id!\",\n c.name as \"name!\",\n NULL as \"branched_from_id\",\n NULL as \"branched_from_version_id\",\n NULL as \"document_family_id\",\n NULL as \"file_type\",\n c.\"createdAt\"::timestamptz as \"created_at!\",\n c.\"updatedAt\"::timestamptz as \"updated_at!\",\n c.\"projectId\" as \"project_id\",\n c.\"isPersistent\" as \"is_persistent\",\n NULL as \"sha\",\n NULL as \"sub_type\",\n false as \"is_email_attachment!\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n NULL as \"is_completed\",\n c.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM \"Chat\" c\n INNER JOIN UserAccessibleItems uai\n ON uai.item_id = c.id\n AND uai.item_type = 'chat'\n LEFT JOIN \"UserHistory\" uh\n ON uh.\"itemId\" = c.id\n AND uh.\"itemType\" = 'chat'\n AND uh.\"userId\" = $1\n WHERE c.\"deletedAt\" IS NULL\n AND c.id = ANY($3::text[])\n )\n SELECT * \n FROM Combined\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "item_type!",
- "type_info": "Text"
- },
- {
- "ordinal": 1,
- "name": "id!",
- "type_info": "Text"
- },
- {
- "ordinal": 2,
- "name": "document_version_id",
- "type_info": "Text"
- },
- {
- "ordinal": 3,
- "name": "user_id!",
- "type_info": "Text"
- },
- {
- "ordinal": 4,
- "name": "name!",
- "type_info": "Text"
- },
- {
- "ordinal": 5,
- "name": "branched_from_id",
- "type_info": "Text"
- },
- {
- "ordinal": 6,
- "name": "branched_from_version_id",
- "type_info": "Int8"
- },
- {
- "ordinal": 7,
- "name": "document_family_id",
- "type_info": "Int8"
- },
- {
- "ordinal": 8,
- "name": "file_type",
- "type_info": "Text"
- },
- {
- "ordinal": 9,
- "name": "created_at!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 10,
- "name": "updated_at!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 11,
- "name": "project_id",
- "type_info": "Text"
- },
- {
- "ordinal": 12,
- "name": "is_persistent",
- "type_info": "Bool"
- },
- {
- "ordinal": 13,
- "name": "sha",
- "type_info": "Text"
- },
- {
- "ordinal": 14,
- "name": "sub_type?: DocumentSubType",
- "type_info": {
- "Custom": {
- "name": "document_sub_type_value",
- "kind": {
- "Enum": [
- "task",
- "snippet",
- "skill"
- ]
- }
- }
- }
- },
- {
- "ordinal": 15,
- "name": "is_email_attachment!",
- "type_info": "Bool"
- },
- {
- "ordinal": 16,
- "name": "viewed_at",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 17,
- "name": "is_completed",
- "type_info": "Bool"
- },
- {
- "ordinal": 18,
- "name": "deleted_at",
- "type_info": "Timestamptz"
- }
- ],
- "parameters": {
- "Left": [
- "Text",
- "TextArray",
- "TextArray",
- "Text",
- "Uuid"
- ]
- },
- "nullable": [
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null
- ]
- },
- "hash": "e17976f1992e4a4ec26b0f2fca80cec95d1f155e69b6166f6bfcebe814c314f0"
-}
diff --git a/Cargo.lock b/Cargo.lock
index baf2fab809..094e492596 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2970,6 +2970,7 @@ dependencies = [
"soup-filter-cache-adapter",
"soup-filter-projection",
"turso-opfs",
+ "uuid",
"wasm-bindgen",
"wasm-bindgen-futures",
"wasm-bindgen-test",
@@ -8667,6 +8668,7 @@ dependencies = [
"filter_ast",
"item_filters",
"predicate-index",
+ "system_properties",
"thiserror 2.0.18",
"uuid",
]
diff --git a/crates/client/cache-wasm/Cargo.toml b/crates/client/cache-wasm/Cargo.toml
index 5af6db50bb..6795099095 100644
--- a/crates/client/cache-wasm/Cargo.toml
+++ b/crates/client/cache-wasm/Cargo.toml
@@ -42,4 +42,5 @@ wasm-bindgen-futures = { workspace = true }
[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
soup-filter-projection = { path = "../../soup_filter_projection", default-features = false }
+uuid = { workspace = true, features = ["js"] }
wasm-bindgen-test = { workspace = true }
diff --git a/crates/client/cache-wasm/src/shell.rs b/crates/client/cache-wasm/src/shell.rs
index 3daa12520b..6178e10875 100644
--- a/crates/client/cache-wasm/src/shell.rs
+++ b/crates/client/cache-wasm/src/shell.rs
@@ -973,7 +973,7 @@ impl CacheEngine {
})
}
- /// Evaluates one exact `soup-flat-v2` GraphQL filter request.
+ /// Evaluates one exact current-profile GraphQL Soup filter request.
#[wasm_bindgen(js_name = entityFilter)]
pub fn entity_filter(&self, request: JsValue) -> js_sys::Promise {
let state = self.state.clone();
diff --git a/crates/client/cache-wasm/src/shell/test.rs b/crates/client/cache-wasm/src/shell/test.rs
index 93c5b5285a..27b68e8381 100644
--- a/crates/client/cache-wasm/src/shell/test.rs
+++ b/crates/client/cache-wasm/src/shell/test.rs
@@ -304,10 +304,17 @@ fn mutation_variables() -> serde_json::Value {
}})
}
-fn v2_document_supplement(document_id: &str, is_email_attachment: bool) -> String {
+fn v3_document_supplement(
+ document_id: &str,
+ is_email_attachment: bool,
+ is_important: bool,
+ status_option_ids: Vec<uuid::Uuid>,
+) -> String {
encode_cache_projection_supplement(&SoupCacheProjectionSupplement::document(
RecordKey::new(format!("GraphqlSoupDocument:{document_id}")).unwrap(),
is_email_attachment,
+ is_important,
+ status_option_ids,
))
.unwrap()
}
@@ -318,6 +325,26 @@ fn projected_document_item(
is_email_attachment: bool,
sub_type: Option<&str>,
updated_at: i64,
+) -> serde_json::Value {
+ projected_document_item_with_facts(
+ document_id,
+ owner,
+ is_email_attachment,
+ true,
+ Vec::new(),
+ sub_type,
+ updated_at,
+ )
+}
+
+fn projected_document_item_with_facts(
+ document_id: &str,
+ owner: &str,
+ is_email_attachment: bool,
+ is_important: bool,
+ status_option_ids: Vec<uuid::Uuid>,
+ sub_type: Option<&str>,
+ updated_at: i64,
) -> serde_json::Value {
let sub_type = sub_type.map(|sub_type| {
let typename = match sub_type {
@@ -331,7 +358,12 @@ fn projected_document_item(
serde_json::json!({
"__typename": "GraphqlSoupDocument",
"id": document_id,
- "cacheProjection": v2_document_supplement(document_id, is_email_attachment),
+ "cacheProjection": v3_document_supplement(
+ document_id,
+ is_email_attachment,
+ is_important,
+ status_option_ids,
+ ),
"displayName": format!("Document {document_id}"),
"ownerId": owner,
"projectId": null,
@@ -461,6 +493,70 @@ fn documents_preset_filter(document_filter: serde_json::Value) -> serde_json::Va
})
}
+fn my_tasks_filter(owner: &str) -> serde_json::Value {
+ const NIL_ID: &str = "00000000-0000-0000-0000-000000000000";
+ const STATUS_PROPERTY_ID: &str = "00000001-0000-0000-0000-000000000002";
+ serde_json::json!({
+ "filters": {
+ "calendarEventFilter": { "literal": { "id": NIL_ID } },
+ "documentFilter": {
+ "and": {
+ "left": { "literal": { "subType": "TASK" } },
+ "right": {
+ "or": {
+ "left": { "literal": { "owner": owner } },
+ "right": { "literal": { "importance": true } }
+ }
+ }
+ }
+ },
+ "projectFilter": { "literal": { "projectId": NIL_ID } },
+ "chatFilter": { "literal": { "chatId": NIL_ID } },
+ "emailFilter": { "tree": { "literal": { "threadId": NIL_ID } } },
+ "channelFilter": { "literal": { "channelId": NIL_ID } },
+ "channelThreadFilter": { "literal": { "threadId": NIL_ID } },
+ "callFilter": { "literal": { "callId": NIL_ID } },
+ "crmCompanyFilter": { "literal": { "id": NIL_ID } },
+ "foreignEntityFilter": { "literal": { "id": NIL_ID } },
+ "propertiesFilter": {
+ "or": {
+ "left": {
+ "literal": {
+ "propertyDefinitionId": STATUS_PROPERTY_ID,
+ "value": {
+ "selectOption": "00000001-0000-0000-0002-000000000001"
+ }
+ }
+ },
+ "right": {
+ "or": {
+ "left": {
+ "literal": {
+ "propertyDefinitionId": STATUS_PROPERTY_ID,
+ "value": {
+ "selectOption": "00000001-0000-0000-0002-000000000002"
+ }
+ }
+ },
+ "right": {
+ "literal": {
+ "propertyDefinitionId": STATUS_PROPERTY_ID,
+ "value": {
+ "selectOption": "00000001-0000-0000-0002-000000000003"
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "sortMethod": "UPDATED_AT",
+ "sortDirection": "DESC",
+ "limit": 100
+ })
+}
+
fn production_documents_preset_filters() -> Vec<(&'static str, serde_json::Value)> {
let owner = "macro|[email protected]";
let not_task = serde_json::json!({
@@ -686,8 +782,8 @@ async fn operations_preserve_js_boundary_interner_and_ordering() {
}
#[wasm_bindgen_test(async)]
-async fn soup_updated_v2_supplements_advance_revision_and_recompute_documents_presets_locally() {
- const SCOPE: &str = "cache-wasm-realtime-documents-v2";
+async fn soup_updated_v3_supplements_advance_revision_and_recompute_documents_presets_locally() {
+ const SCOPE: &str = "cache-wasm-realtime-documents-v3";
const OWNER: &str = "macro|[email protected]";
const OTHER_OWNER: &str = "macro|[email protected]";
const INITIAL: &str = "00000000-0000-0000-0000-000000000001";
@@ -811,6 +907,98 @@ async fn soup_updated_v2_supplements_advance_revision_and_recompute_documents_pr
close_and_destroy(&engine, SCOPE).await;
}
+#[wasm_bindgen_test(async)]
+async fn soup_updated_v3_recomputes_my_tasks_importance_and_status_locally() {
+ const SCOPE: &str = "cache-wasm-realtime-my-tasks-v3";
+ const VIEWER: &str = "macro|[email protected]";
+ const OWNER_TASK: &str = "00000000-0000-0000-0000-000000000011";
+ const ASSIGNED_TASK: &str = "00000000-0000-0000-0000-000000000012";
+ const COMPLETED_TASK: &str = "00000000-0000-0000-0000-000000000013";
+ let status =
+ |suffix| uuid::Uuid::parse_str(&format!("00000001-0000-0000-0002-{suffix:012}")).unwrap();
+ let key = |id| format!("GraphqlSoupDocument:{id}");
+ let engine = fresh_engine(SCOPE).await;
+
+ let initial: serde_json::Value = from_js(
+ resolved(engine.write_query(
+ write_context(None),
+ SOUP_WITH_PROJECTION_QUERY.into(),
+ Some("SoupWithProjection".into()),
+ js(serde_json::json!({ "input": { "limit": 100 } })),
+ js(serde_json::json!({
+ "user": {
+ "id": "user-1",
+ "soup": {
+ "nextCursor": null,
+ "items": [projected_document_item_with_facts(
+ OWNER_TASK,
+ VIEWER,
+ false,
+ false,
+ vec![status(1)],
+ Some("task"),
+ 10,
+ )]
+ }
+ }
+ })),
+ Some("user-1".into()),
+ ))
+ .await,
+ );
+ assert_eq!(initial["revision"], "1");
+
+ let updates = [
+ projected_document_item_with_facts(
+ ASSIGNED_TASK,
+ false,
+ true,
+ vec![status(2)],
+ Some("task"),
+ 30,
+ ),
+ projected_document_item_with_facts(
+ COMPLETED_TASK,
+ false,
+ true,
+ vec![status(4)],
+ Some("task"),
+ 20,
+ ),
+ ]
+ .into_iter()
+ .map(|item| serde_json::json!({ "__typename": "SoupUpdated", "item": item }))
+ .collect::<Vec<_>>();
+ let realtime: serde_json::Value = from_js(
+ resolved(engine.write_query(
+ write_context(None),
+ SOUP_UPDATES_WITH_PROJECTION_SUBSCRIPTION.into(),
+ Some("SoupUpdatesWithProjection".into()),
+ js(serde_json::json!({})),
+ js(serde_json::json!({ "soupUpdates": updates })),
+ None,
+ ))
+ .await,
+ );
+ assert_eq!(realtime["revision"], "2");
+
+ let filtered: serde_json::Value =
+ from_js(resolved(engine.entity_filter(js(my_tasks_filter(VIEWER)))).await);
+ assert_eq!(
+ filtered,
+ serde_json::json!({
+ "kind": "complete",
+ "revision": "2",
+ "keys": [key(ASSIGNED_TASK), key(OWNER_TASK)],
+ "optimistic": false,
+ })
+ );
+
+ close_and_destroy(&engine, SCOPE).await;
+}
+
#[wasm_bindgen_test(async)]
async fn backfill_supplement_failure_does_not_commit_or_advance_revision() {
const SCOPE: &str = "cache-wasm-backfill-supplement-checkpoint";
diff --git a/crates/complete_graph/src/schema/test.rs b/crates/complete_graph/src/schema/test.rs
index 5662b1c7a1..31ff1b848e 100644
--- a/crates/complete_graph/src/schema/test.rs
+++ b/crates/complete_graph/src/schema/test.rs
@@ -181,6 +181,8 @@ impl SoupService for CountingSoupService {
let document_server_facts = matches!(&item, SoupItem::Document(_)).then_some(
soup::domain::models::SoupDocumentServerFacts {
is_email_attachment: false,
+ is_important: true,
+ status_option_ids: Vec::new(),
},
);
soup::domain::models::SoupProjectionHydration {
diff --git a/crates/item_filter_index/Cargo.toml b/crates/item_filter_index/Cargo.toml
index 1c75d45dab..954d5c4b02 100644
--- a/crates/item_filter_index/Cargo.toml
+++ b/crates/item_filter_index/Cargo.toml
@@ -17,3 +17,4 @@ uuid = { workspace = true, features = ["js"] }
[dev-dependencies]
chrono = { workspace = true }
document_sub_type = { path = "../document_sub_type", default-features = false }
+system_properties = { path = "../system_properties" }
diff --git a/crates/item_filter_index/src/lib.rs b/crates/item_filter_index/src/lib.rs
index 0c783c522b..b14eaa2985 100644
--- a/crates/item_filter_index/src/lib.rs
+++ b/crates/item_filter_index/src/lib.rs
@@ -14,6 +14,7 @@ use item_filters::ast::{
email::EmailLiteral,
foreign_entity::ForeignEntityLiteral,
project::ProjectLiteral,
+ properties::{PropertiesLiteral, PropertyEntityType, PropertyMatchValue},
};
use predicate_index::{
ExactValue, IndexQuery, PartitionPredicate, PredicateExpr, Profile, RangeBound, SortDirection,
@@ -29,12 +30,19 @@ mod test;
pub const SOUP_FLAT_V1: &str = "soup-flat-v1";
/// Stable server-minted profile containing exact derived document facts.
pub const SOUP_FLAT_V2: &str = "soup-flat-v2";
+/// Stable server-minted profile containing viewer-relative task facts.
+pub const SOUP_FLAT_V3: &str = "soup-flat-v3";
+
+// Keep this lightweight crate wasm-compatible instead of depending on the
+// native `system_properties` crate. A native test locks this stable UUID to
+// `SystemPropertyKey::STATUS_UUID`.
+const STATUS_PROPERTY_DEFINITION_ID: Uuid = Uuid::from_u128(0x00000001_0000_0000_0000_000000000002);
/// Opaque vocabulary shared with direct Soup projection generation.
pub mod vocabulary {
use predicate_index::{Profile, Token};
- use crate::{SOUP_FLAT_V1, SOUP_FLAT_V2};
+ use crate::{SOUP_FLAT_V1, SOUP_FLAT_V2, SOUP_FLAT_V3};
fn token(value: &str) -> Token {
Token::new(value).expect("static item-filter-index token is valid")
@@ -50,6 +58,11 @@ pub mod vocabulary {
Profile::new(token(SOUP_FLAT_V2))
}
+ /// Server-minted `soup-flat-v3` profile.
+ pub fn profile_v3() -> Profile {
+ Profile::new(token(SOUP_FLAT_V3))
+ }
+
/// Document partition.
pub fn document_partition() -> Token {
token("document")
@@ -95,6 +108,16 @@ pub mod vocabulary {
token("email-attachment")
}
+ /// Viewer-relative document importance Boolean attribute.
+ pub fn importance() -> Token {
+ token("importance")
+ }
+
+ /// One authoritative task status select-option UUID.
+ pub fn task_status_option() -> Token {
+ token("task-status-option")
+ }
+
/// Creation timestamp and sort attribute.
pub fn created_at() -> Token {
token("created-at")
@@ -173,18 +196,24 @@ pub enum CompileError {
/// Check the complete materialized forest against the direct-field v1 profile.
pub fn check_soup_flat_v1(ast: &EntityFilterAst, request: SoupFlatRequest) -> Eligibility {
- check_soup_flat(ast, request, supported_document_literal_v1)
+ check_soup_flat(ast, request, supported_document_literal_v1, false)
}
/// Check the complete materialized forest against the server-minted v2 profile.
pub fn check_soup_flat_v2(ast: &EntityFilterAst, request: SoupFlatRequest) -> Eligibility {
- check_soup_flat(ast, request, supported_document_literal_v2)
+ check_soup_flat(ast, request, supported_document_literal_v2, false)
+}
+
+/// Check the complete materialized forest against the server-minted v3 profile.
+pub fn check_soup_flat_v3(ast: &EntityFilterAst, request: SoupFlatRequest) -> Eligibility {
+ check_soup_flat(ast, request, supported_document_literal_v3, true)
}
fn check_soup_flat(
ast: &EntityFilterAst,
request: SoupFlatRequest,
supported_document_literal: impl Fn(&DocumentLiteral) -> bool + Copy,
+ supports_status_properties: bool,
) -> Eligibility {
if request.has_cursor {
return Eligibility::Unsupported(UnsupportedReason::Cursor);
@@ -192,7 +221,30 @@ fn check_soup_flat(
if request.sort == SoupIndexSort::Unsupported {
return Eligibility::Unsupported(UnsupportedReason::Sort);
}
- if ast.properties_filter.is_some() {
+ if let Some(properties_filter) = ast.properties_filter.as_deref()
+ && (!supports_status_properties
+ || !supported_expr(Some(properties_filter), supported_status_property_literal)
+ || !ast.project_filter.as_deref().is_some_and(|expr| {
+ proves_none(expr, |literal| {
+ matches!(
+ literal,
+ ProjectLiteral::ProjectId(id) | ProjectLiteral::ProjectIdSelf(id)
+ if id.is_nil()
+ )
+ })
+ })
+ || !ast.chat_filter.as_deref().is_some_and(|expr| {
+ proves_none(expr, |literal| {
+ matches!(
+ literal,
+ ChatLiteral::ChatId(id) | ChatLiteral::ProjectId(id) if id.is_nil()
+ )
+ })
+ }))
+ {
+ // v3 carries task status facts only for Documents. Requiring the other
+ // locally indexed partitions to be provably empty preserves the
+ // server's global property-filter semantics without fabricating facts.
return Eligibility::Unsupported(UnsupportedReason::GlobalProperties);
}
@@ -248,7 +300,10 @@ fn check_soup_flat(
return Eligibility::Unsupported(UnsupportedReason::Partition("reminder"));
}
- if !supported_expr(ast.document_filter.as_deref(), supported_document_literal) {
+ if !supported_expr(ast.document_filter.as_deref(), supported_document_literal)
+ || (supports_status_properties
+ && !supported_v3_importance_shape(ast.document_filter.as_deref(), false))
+ {
return Eligibility::Unsupported(UnsupportedReason::Literal("document"));
}
if !supported_expr(ast.project_filter.as_deref(), supported_project_literal) {
@@ -272,6 +327,7 @@ pub fn compile_soup_flat_v1(
vocabulary::profile(),
supported_document_literal_v1,
compile_document_literal_v1,
+ None,
)
}
@@ -286,19 +342,41 @@ pub fn compile_soup_flat_v2(
vocabulary::profile_v2(),
supported_document_literal_v2,
compile_document_literal_v2,
+ None,
)
}
+/// Compile a request against the viewer-relative server-minted v3 profile.
+pub fn compile_soup_flat_v3(
+ ast: &EntityFilterAst,
+ request: SoupFlatRequest,
+) -> Result<LocalCompileOutcome, CompileError> {
+ compile_soup_flat(
+ ast,
+ request,
+ vocabulary::profile_v3(),
+ supported_document_literal_v3,
+ compile_document_literal_v3,
+ Some(compile_status_property_literal),
+ )
+}
+
+type PropertyLiteralCompiler = fn(&PropertiesLiteral) -> Result<PredicateExpr, CompileError>;
+
fn compile_soup_flat(
ast: &EntityFilterAst,
request: SoupFlatRequest,
profile: Profile,
supported_document_literal: impl Fn(&DocumentLiteral) -> bool + Copy,
compile_document_literal: impl Fn(&DocumentLiteral) -> Result<PredicateExpr, CompileError> + Copy,
+ compile_properties_literal: Option<PropertyLiteralCompiler>,
) -> Result<LocalCompileOutcome, CompileError> {
- if let Eligibility::Unsupported(reason) =
- check_soup_flat(ast, request, supported_document_literal)
- {
+ if let Eligibility::Unsupported(reason) = check_soup_flat(
+ ast,
+ request,
+ supported_document_literal,
+ compile_properties_literal.is_some(),
+ ) {
return Ok(LocalCompileOutcome::Unsupported(reason));
}
@@ -307,12 +385,26 @@ fn compile_soup_flat(
SoupIndexSort::UpdatedAt => vocabulary::updated_at(),
SoupIndexSort::Unsupported => unreachable!("eligibility checked sort"),
};
+ let mut document_predicate =
+ compile_expr(ast.document_filter.as_deref(), compile_document_literal)?;
+ if let Some(properties_filter) = ast.properties_filter.as_deref() {
+ let compile_properties_literal =
+ compile_properties_literal.expect("eligibility checked property support");
+ document_predicate = PredicateExpr::And(
+ Box::new(document_predicate),
+ Box::new(compile_expr(
+ Some(properties_filter),
+ compile_properties_literal,
+ )?),
+ );
+ }
+
let query = IndexQuery {
profile,
partitions: vec![
PartitionPredicate {
partition: vocabulary::document_partition(),
- predicate: compile_expr(ast.document_filter.as_deref(), compile_document_literal)?,
+ predicate: document_predicate,
},
PartitionPredicate {
partition: vocabulary::project_partition(),
@@ -386,6 +478,31 @@ fn supported_document_literal_v2(literal: &DocumentLiteral) -> bool {
)
}
+fn supported_document_literal_v3(literal: &DocumentLiteral) -> bool {
+ supported_document_literal_v2(literal) || matches!(literal, DocumentLiteral::Importance(true))
+}
+
+fn supported_v3_importance_shape(expr: Option<&Expr<DocumentLiteral>>, negated: bool) -> bool {
+ match expr {
+ None => true,
+ Some(Expr::Literal(DocumentLiteral::Importance(value))) => *value && !negated,
+ Some(Expr::Literal(_)) => true,
+ Some(Expr::And(left, right) | Expr::Or(left, right)) => {
+ supported_v3_importance_shape(Some(left), negated)
+ && supported_v3_importance_shape(Some(right), negated)
+ }
+ Some(Expr::Not(expr)) => supported_v3_importance_shape(Some(expr), !negated),
+ }
+}
+
+fn supported_status_property_literal(literal: &PropertiesLiteral) -> bool {
+ literal.property_definition_id == STATUS_PROPERTY_DEFINITION_ID
+ && literal
+ .entity_type
+ .is_none_or(|entity_type| entity_type == PropertyEntityType::Task)
+ && matches!(literal.value, PropertyMatchValue::SelectOption(_))
+}
+
fn supported_project_literal(literal: &ProjectLiteral) -> bool {
matches!(
literal,
@@ -428,16 +545,21 @@ fn compile_expr<T>(
}
fn compile_document_literal_v1(literal: &DocumentLiteral) -> Result<PredicateExpr, CompileError> {
- compile_document_literal(literal, false)
+ compile_document_literal(literal, false, false)
}
fn compile_document_literal_v2(literal: &DocumentLiteral) -> Result<PredicateExpr, CompileError> {
- compile_document_literal(literal, true)
+ compile_document_literal(literal, true, false)
+}
+
+fn compile_document_literal_v3(literal: &DocumentLiteral) -> Result<PredicateExpr, CompileError> {
+ compile_document_literal(literal, true, true)
}
fn compile_document_literal(
literal: &DocumentLiteral,
supports_v2_facts: bool,
+ supports_v3_facts: bool,
) -> Result<PredicateExpr, CompileError> {
Ok(match literal {
DocumentLiteral::Id(id) => exact_uuid(vocabulary::id(), id),
@@ -456,12 +578,26 @@ fn compile_document_literal(
value: ExactValue::new([u8::from(*value)])
.expect("canonical Boolean exact value is bounded"),
},
+ DocumentLiteral::Importance(value) if supports_v3_facts => PredicateExpr::Exact {
+ attribute: vocabulary::importance(),
+ value: ExactValue::new([u8::from(*value)])
+ .expect("canonical Boolean exact value is bounded"),
+ },
DocumentLiteral::CreatedAt(date) => date_expr(vocabulary::created_at(), date),
DocumentLiteral::UpdatedAt(date) => date_expr(vocabulary::updated_at(), date),
_ => unreachable!("eligibility checked document literal"),
})
}
+fn compile_status_property_literal(
+ literal: &PropertiesLiteral,
+) -> Result<PredicateExpr, CompileError> {
+ let PropertyMatchValue::SelectOption(option_id) = &literal.value else {
+ unreachable!("eligibility checked status property value");
+ };
+ Ok(exact_uuid(vocabulary::task_status_option(), option_id))
+}
+
fn compile_project_literal(literal: &ProjectLiteral) -> Result<PredicateExpr, CompileError> {
Ok(match literal {
ProjectLiteral::ProjectId(id) => exact_uuid(vocabulary::project_id(), id),
diff --git a/crates/item_filter_index/src/test.rs b/crates/item_filter_index/src/test.rs
index 68be6e6b03..b352077984 100644
--- a/crates/item_filter_index/src/test.rs
+++ b/crates/item_filter_index/src/test.rs
@@ -7,12 +7,14 @@ use item_filters::ast::{
calendar_event::CalendarEventLiteral,
call::CallLiteral,
channel::{ChannelLiteral, ChannelThreadLiteral},
+ chat::ChatLiteral,
crm_company::CrmCompanyLiteral,
date::DateLiteral,
document::DocumentLiteral,
email::EmailLiteral,
foreign_entity::ForeignEntityLiteral,
- properties::{PropertiesLiteral, PropertyMatchValue},
+ project::ProjectLiteral,
+ properties::{PropertiesLiteral, PropertyEntityType, PropertyMatchValue},
};
use predicate_index::{PredicateExpr, RangeBound};
@@ -43,6 +45,13 @@ fn excluded_deferred_partitions() -> EntityFilterAst {
ast
}
+fn excluded_non_document_local_partitions(ast: &mut EntityFilterAst) {
+ ast.project_filter = Some(Arc::new(Expr::val(ProjectLiteral::ProjectIdSelf(
+ Uuid::nil(),
+ ))));
+ ast.chat_filter = Some(Arc::new(Expr::val(ChatLiteral::ChatId(Uuid::nil()))));
+}
+
#[test]
fn compiles_complete_supported_forest_after_eligibility() {
let id = Uuid::from_u128(1);
@@ -153,6 +162,86 @@ fn v2_subtype_and_attachment_preserve_direct_and_or_not_shapes() {
);
}
+#[test]
+fn v3_compiles_my_tasks_importance_and_status_membership() {
+ assert_eq!(
+ STATUS_PROPERTY_DEFINITION_ID,
+ system_properties::SystemPropertyKey::STATUS_UUID
+ );
+
+ let not_started = Uuid::from_u128(11);
+ let in_progress = Uuid::from_u128(12);
+ let mut ast = excluded_deferred_partitions();
+ excluded_non_document_local_partitions(&mut ast);
+ ast.document_filter = Some(Arc::new(Expr::and(
+ Expr::val(DocumentLiteral::SubType(DocumentSubType::Task)),
+ Expr::val(DocumentLiteral::Importance(true)),
+ )));
+ ast.properties_filter = Some(Arc::new(Expr::or(
+ Expr::val(PropertiesLiteral {
+ property_definition_id: STATUS_PROPERTY_DEFINITION_ID,
+ entity_type: None,
+ value: PropertyMatchValue::SelectOption(not_started),
+ }),
+ Expr::val(PropertiesLiteral {
+ property_definition_id: STATUS_PROPERTY_DEFINITION_ID,
+ entity_type: Some(PropertyEntityType::Task),
+ value: PropertyMatchValue::SelectOption(in_progress),
+ }),
+ )));
+
+ assert_eq!(
+ compile_soup_flat_v2(&ast, request()).unwrap(),
+ LocalCompileOutcome::Unsupported(UnsupportedReason::GlobalProperties)
+ );
+ let LocalCompileOutcome::Supported(query) = compile_soup_flat_v3(&ast, request()).unwrap()
+ else {
+ panic!("My Tasks v3 request fell back");
+ };
+ assert_eq!(query.as_query().profile, vocabulary::profile_v3());
+ let document = &query.as_query().partitions[0].predicate;
+ assert!(format!("{document:?}").contains("importance"));
+ assert!(format!("{document:?}").contains("task-status-option"));
+}
+
+#[test]
+fn v3_rejects_non_status_properties_and_unrestricted_local_partitions() {
+ for importance in [
+ Expr::val(DocumentLiteral::Importance(false)),
+ Expr::is_not(Expr::val(DocumentLiteral::Importance(true))),
+ ] {
+ let mut ast = excluded_deferred_partitions();
+ ast.document_filter = Some(Arc::new(importance));
+ assert_eq!(
+ check_soup_flat_v3(&ast, request()),
+ Eligibility::Unsupported(UnsupportedReason::Literal("document"))
+ );
+ }
+
+ let mut ast = excluded_deferred_partitions();
+ ast.properties_filter = Some(Arc::new(Expr::val(PropertiesLiteral {
+ property_definition_id: Uuid::from_u128(99),
+ entity_type: None,
+ value: PropertyMatchValue::SelectOption(Uuid::from_u128(1)),
+ })));
+ excluded_non_document_local_partitions(&mut ast);
+ assert_eq!(
+ check_soup_flat_v3(&ast, request()),
+ Eligibility::Unsupported(UnsupportedReason::GlobalProperties)
+ );
+
+ ast.properties_filter = Some(Arc::new(Expr::val(PropertiesLiteral {
+ property_definition_id: STATUS_PROPERTY_DEFINITION_ID,
+ entity_type: None,
+ value: PropertyMatchValue::SelectOption(Uuid::from_u128(1)),
+ })));
+ ast.project_filter = None;
+ assert_eq!(
+ check_soup_flat_v3(&ast, request()),
+ Eligibility::Unsupported(UnsupportedReason::GlobalProperties)
+ );
+}
+
#[test]
fn unsupported_supported_partition_literals_force_v1_and_v2_network_fallback() {
for expression in [
diff --git a/crates/macro_db_client/fixtures/entity_filter_tests.sql b/crates/macro_db_client/fixtures/entity_filter_tests.sql
index 36720d3bc4..b15a3a7bc6 100644
--- a/crates/macro_db_client/fixtures/entity_filter_tests.sql
+++ b/crates/macro_db_client/fixtures/entity_filter_tests.sql
@@ -149,6 +149,22 @@ VALUES
'TASK',
'00000001-0000-0000-0000-000000000001',
'{"type": "EntityReference", "value": [{"entity_type": "USER", "entity_id": "macro|[email protected]"}]}'
+ ),
+ -- doc-in-A: Status = Not Started
+ (
+ 'a0000001-0000-0000-0000-000000000004',
+ 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa',
+ 'TASK',
+ '00000001-0000-0000-0000-000000000002',
+ '{"type": "SelectOption", "value": ["00000001-0000-0000-0002-000000000001"]}'
+ ),
+ -- doc-in-B: Status = In Progress
+ (
+ 'a0000001-0000-0000-0000-000000000005',
+ 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb',
+ 'TASK',
+ '00000001-0000-0000-0000-000000000002',
+ '{"type": "SelectOption", "value": ["00000001-0000-0000-0002-000000000002"]}'
);
-- Email attachments linked to some documents via document_email
diff --git a/crates/soup/src/domain/models.rs b/crates/soup/src/domain/models.rs
index 5b6a526947..db41d7ab41 100644
--- a/crates/soup/src/domain/models.rs
+++ b/crates/soup/src/domain/models.rs
@@ -1034,10 +1034,19 @@ fn reminder_or_is_sets_only(expr: &Expr<ReminderLiteral>, out: &mut ReminderFilt
/// This value is internal hydration state. It is deliberately separate from
/// public Soup entity models so relation-backed facts do not become business
/// fields on [`models_soup::document::SoupDocument`].
-#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SoupDocumentServerFacts {
/// Whether `document_email` contains a row for the document.
pub is_email_attachment: bool,
+ /// Whether the document is important to the requesting viewer.
+ ///
+ /// Non-task documents are important. Tasks are important when the viewer
+ /// appears in the authoritative Assignees system property.
+ pub is_important: bool,
+ /// Complete authoritative Status select-option IDs for a task.
+ ///
+ /// Non-task documents and tasks without a Status value carry an empty set.
+ pub status_option_ids: Vec<uuid::Uuid>,
}
/// An authorized Soup item and any server-only facts read by the same
diff --git a/crates/soup/src/domain/service/tests.rs b/crates/soup/src/domain/service/tests.rs
index e99e2130d7..61d2ff995c 100644
--- a/crates/soup/src/domain/service/tests.rs
+++ b/crates/soup/src/domain/service/tests.rs
@@ -2635,6 +2635,8 @@ async fn touched_soup_projection_preserves_authoritative_attachment_facts() {
)),
document_server_facts: Some(SoupDocumentServerFacts {
is_email_attachment: false,
+ is_important: true,
+ status_option_ids: Vec::new(),
}),
},
SoupProjectionHydration {
@@ -2644,6 +2646,8 @@ async fn touched_soup_projection_preserves_authoritative_attachment_facts() {
)),
document_server_facts: Some(SoupDocumentServerFacts {
is_email_attachment: true,
+ is_important: true,
+ status_option_ids: Vec::new(),
}),
},
])
@@ -2685,12 +2689,16 @@ async fn touched_soup_projection_preserves_authoritative_attachment_facts() {
page.items[0].document_server_facts,
Some(SoupDocumentServerFacts {
is_email_attachment: true,
+ is_important: true,
+ status_option_ids: Vec::new(),
})
);
assert_eq!(
page.items[1].document_server_facts,
Some(SoupDocumentServerFacts {
is_email_attachment: false,
+ is_important: true,
+ status_option_ids: Vec::new(),
})
);
}
diff --git a/crates/soup/src/outbound/pg_soup_repo.rs b/crates/soup/src/outbound/pg_soup_repo.rs
index 5bc77ead23..b14dfd085b 100644
--- a/crates/soup/src/outbound/pg_soup_repo.rs
+++ b/crates/soup/src/outbound/pg_soup_repo.rs
@@ -452,6 +452,8 @@ macro_rules! map_soup_projection_hydration {
let document_server_facts = match r.item_type.as_ref() {
"document" => Some($crate::domain::models::SoupDocumentServerFacts {
is_email_attachment: r.is_email_attachment,
+ is_important: r.is_important,
+ status_option_ids: r.status_option_ids.clone(),
}),
_ => None,
};
diff --git a/crates/soup/src/outbound/pg_soup_repo/expanded/by_cursor.rs b/crates/soup/src/outbound/pg_soup_repo/expanded/by_cursor.rs
index 3862adc45a..490d44a92a 100644
--- a/crates/soup/src/outbound/pg_soup_repo/expanded/by_cursor.rs
+++ b/crates/soup/src/outbound/pg_soup_repo/expanded/by_cursor.rs
@@ -31,6 +31,7 @@ async fn expanded_generic_cursor_soup_hydrated(
let cursor_id = cursor_id.as_ref().map(|u| u.to_string());
let status_property_id = SystemPropertyKey::STATUS_UUID;
+ let assignees_property_id = SystemPropertyKey::ASSIGNEES_UUID;
let completed_option_id = StatusOption::COMPLETED_UUID.to_string();
let items: Vec<SoupProjectionHydration> = sqlx::query!(
@@ -151,6 +152,29 @@ r#"
FROM document_email de
WHERE de.document_id = d.id
) as "is_email_attachment!",
+ (
+ dt.sub_type IS DISTINCT FROM 'task'
+ OR EXISTS (
+ SELECT 1
+ FROM entity_properties ep_assignees
+ WHERE ep_assignees.entity_id = d.id
+ AND ep_assignees.entity_type = 'TASK'
+ AND ep_assignees.property_definition_id = $8
+ AND ep_assignees.values->'value' @> jsonb_build_array(
+ jsonb_build_object('entity_id', $1)
+ )
+ )
+ ) as "is_important!",
+ ARRAY(
+ SELECT status_option_id::uuid
+ FROM jsonb_array_elements_text(
+ CASE
+ WHEN jsonb_typeof(ep_status.values->'value') = 'array'
+ THEN ep_status.values->'value'
+ ELSE '[]'::jsonb
+ END
+ ) AS status_option_id
+ ) as "status_option_ids!: Vec<Uuid>",
uh."updatedAt"::timestamptz as "viewed_at",
t.sort_ts as "sort_ts!",
-- Task completion status: check if status property matches "completed"
@@ -209,6 +233,8 @@ r#"
NULL as "sha",
NULL as "sub_type",
false as "is_email_attachment!",
+ true as "is_important!",
+ ARRAY[]::uuid[] as "status_option_ids!: Vec<Uuid>",
uh."updatedAt"::timestamptz as "viewed_at",
t.sort_ts as "sort_ts!",
NULL as "is_completed",
@@ -238,6 +264,8 @@ r#"
NULL as "sha",
NULL as "sub_type",
false as "is_email_attachment!",
+ true as "is_important!",
+ ARRAY[]::uuid[] as "status_option_ids!: Vec<Uuid>",
uh."updatedAt"::timestamptz as "viewed_at",
t.sort_ts as "sort_ts!",
NULL as "is_completed",
@@ -261,6 +289,7 @@ r#"
cursor_id, // $5
completed_option_id, // $6
status_property_id, // $7
+ assignees_property_id, // $8
)
.try_map(map_soup_projection_hydration!())
.fetch_all(db)
@@ -314,6 +343,7 @@ async fn no_frecency_expanded_generic_soup_hydrated(
let cursor_id = cursor_id.as_ref().map(|u| u.to_string());
let status_property_id = SystemPropertyKey::STATUS_UUID;
+ let assignees_property_id = SystemPropertyKey::ASSIGNEES_UUID;
let completed_option_id = StatusOption::COMPLETED_UUID.to_string();
let items: Vec<SoupProjectionHydration> = sqlx::query!(
@@ -356,6 +386,29 @@ r#"
FROM document_email de
WHERE de.document_id = d.id
) as "is_email_attachment!",
+ (
+ dt.sub_type IS DISTINCT FROM 'task'
+ OR EXISTS (
+ SELECT 1
+ FROM entity_properties ep_assignees
+ WHERE ep_assignees.entity_id = d.id
+ AND ep_assignees.entity_type = 'TASK'
+ AND ep_assignees.property_definition_id = $8
+ AND ep_assignees.values->'value' @> jsonb_build_array(
+ jsonb_build_object('entity_id', $1)
+ )
+ )
+ ) as "is_important!",
+ ARRAY(
+ SELECT status_option_id::uuid
+ FROM jsonb_array_elements_text(
+ CASE
+ WHEN jsonb_typeof(ep_status.values->'value') = 'array'
+ THEN ep_status.values->'value'
+ ELSE '[]'::jsonb
+ END
+ ) AS status_option_id
+ ) as "status_option_ids!: Vec<Uuid>",
uh."updatedAt"::timestamptz as "viewed_at",
CASE $2
WHEN 'viewed_updated' THEN COALESCE(uh."updatedAt", d."updatedAt")
@@ -417,6 +470,8 @@ r#"
NULL as "sha",
NULL as "sub_type",
false as "is_email_attachment!",
+ true as "is_important!",
+ ARRAY[]::uuid[] as "status_option_ids!: Vec<Uuid>",
uh."updatedAt"::timestamptz as "viewed_at",
CASE $2
WHEN 'viewed_updated' THEN COALESCE(uh."updatedAt", c."updatedAt")
@@ -450,6 +505,8 @@ r#"
NULL as "sha",
NULL as "sub_type",
false as "is_email_attachment!",
+ true as "is_important!",
+ ARRAY[]::uuid[] as "status_option_ids!: Vec<Uuid>",
uh."updatedAt"::timestamptz as "viewed_at",
CASE $2
WHEN 'viewed_updated' THEN COALESCE(uh."updatedAt", p."updatedAt")
@@ -490,6 +547,7 @@ r#"
cursor_id, // $5
completed_option_id, // $6
status_property_id, // $7
+ assignees_property_id, // $8
)
.try_map(map_soup_projection_hydration!())
.fetch_all(db)
diff --git a/crates/soup/src/outbound/pg_soup_repo/expanded/by_ids.rs b/crates/soup/src/outbound/pg_soup_repo/expanded/by_ids.rs
index d819cb5361..c498eb6ae9 100644
--- a/crates/soup/src/outbound/pg_soup_repo/expanded/by_ids.rs
+++ b/crates/soup/src/outbound/pg_soup_repo/expanded/by_ids.rs
@@ -40,6 +40,7 @@ async fn expanded_soup_by_ids_hydrated<'a>(
}
let status_property_id = SystemPropertyKey::STATUS_UUID;
+ let assignees_property_id = SystemPropertyKey::ASSIGNEES_UUID;
let completed_option_id = StatusOption::COMPLETED_UUID.to_string();
let items: Vec<SoupProjectionHydration> = sqlx::query!(
@@ -82,6 +83,29 @@ async fn expanded_soup_by_ids_hydrated<'a>(
FROM document_email de
WHERE de.document_id = d.id
) as "is_email_attachment!",
+ (
+ dt.sub_type IS DISTINCT FROM 'task'
+ OR EXISTS (
+ SELECT 1
+ FROM entity_properties ep_assignees
+ WHERE ep_assignees.entity_id = d.id
+ AND ep_assignees.entity_type = 'TASK'
+ AND ep_assignees.property_definition_id = $6
+ AND ep_assignees.values->'value' @> jsonb_build_array(
+ jsonb_build_object('entity_id', $1)
+ )
+ )
+ ) as "is_important!",
+ ARRAY(
+ SELECT status_option_id::uuid
+ FROM jsonb_array_elements_text(
+ CASE
+ WHEN jsonb_typeof(ep_status.values->'value') = 'array'
+ THEN ep_status.values->'value'
+ ELSE '[]'::jsonb
+ END
+ ) AS status_option_id
+ ) as "status_option_ids!: Vec<Uuid>",
uh."updatedAt"::timestamptz as "viewed_at",
CASE
WHEN dt.sub_type = 'task'
@@ -142,6 +166,8 @@ async fn expanded_soup_by_ids_hydrated<'a>(
NULL as "sha",
NULL as "sub_type",
false as "is_email_attachment!",
+ true as "is_important!",
+ ARRAY[]::uuid[] as "status_option_ids!: Vec<Uuid>",
uh."updatedAt"::timestamptz as "viewed_at",
NULL as "is_completed",
c."deletedAt"::timestamptz as "deleted_at"
@@ -164,6 +190,7 @@ async fn expanded_soup_by_ids_hydrated<'a>(
chat_ids.as_slice(), // $3
completed_option_id, // $4
status_property_id, // $5
+ assignees_property_id, // $6
)
.try_map(map_soup_projection_hydration!())
.fetch_all(db)
diff --git a/crates/soup/src/outbound/pg_soup_repo/expanded/dynamic.rs b/crates/soup/src/outbound/pg_soup_repo/expanded/dynamic.rs
index 0584c40989..88a9ac04f1 100644
--- a/crates/soup/src/outbound/pg_soup_repo/expanded/dynamic.rs
+++ b/crates/soup/src/outbound/pg_soup_repo/expanded/dynamic.rs
@@ -178,6 +178,29 @@ static DOCUMENT_DETAIL_CLAUSE: &str = r#"
FROM document_email de
WHERE de.document_id = d.id
) as "is_email_attachment",
+ (
+ dt.sub_type IS DISTINCT FROM 'task'
+ OR EXISTS (
+ SELECT 1
+ FROM entity_properties ep_assignees_projection
+ WHERE ep_assignees_projection.entity_id = d.id
+ AND ep_assignees_projection.entity_type = 'TASK'
+ AND ep_assignees_projection.property_definition_id = $8
+ AND ep_assignees_projection.values->'value' @> jsonb_build_array(
+ jsonb_build_object('entity_id', $1)
+ )
+ )
+ ) as "is_important",
+ ARRAY(
+ SELECT status_option_id::uuid
+ FROM jsonb_array_elements_text(
+ CASE
+ WHEN jsonb_typeof(ep_status.values->'value') = 'array'
+ THEN ep_status.values->'value'
+ ELSE '[]'::jsonb
+ END
+ ) AS status_option_id
+ ) as "status_option_ids",
uh."updatedAt"::timestamptz as "viewed_at",
t.sort_ts as "sort_ts",
CASE
@@ -234,6 +257,8 @@ static CHAT_DETAIL_CLAUSE: &str = r#"
NULL as "sha",
NULL as "sub_type",
false as "is_email_attachment",
+ true as "is_important",
+ ARRAY[]::uuid[] as "status_option_ids",
uh."updatedAt"::timestamptz as "viewed_at",
t.sort_ts as "sort_ts",
NULL as "is_completed",
@@ -263,6 +288,8 @@ static PROJECT_DETAIL_CLAUSE: &str = r#"
NULL as "sha",
NULL as "sub_type",
false as "is_email_attachment",
+ true as "is_important",
+ ARRAY[]::uuid[] as "status_option_ids",
uh."updatedAt"::timestamptz as "viewed_at",
t.sort_ts as "sort_ts",
NULL as "is_completed",
@@ -1573,6 +1600,8 @@ fn build_query(
NULL::text as "sha",
NULL::document_sub_type_value as "sub_type",
false as "is_email_attachment",
+ false as "is_important",
+ ARRAY[]::uuid[] as "status_option_ids",
NULL::timestamptz as "viewed_at",
NULL::timestamptz as "sort_ts",
NULL::boolean as "is_completed",
@@ -1603,6 +1632,10 @@ struct DocumentRow {
sub_type: Option<DocumentSubType>,
#[sqlx(default)]
is_email_attachment: bool,
+ #[sqlx(default)]
+ is_important: bool,
+ #[sqlx(default)]
+ status_option_ids: Vec<Uuid>,
is_completed: Option<bool>,
deleted_at: Option<DateTime<Utc>>,
}
@@ -1666,6 +1699,8 @@ impl SoupRow {
match self {
Self::Document(row) => Some(SoupDocumentServerFacts {
is_email_attachment: row.is_email_attachment,
+ is_important: row.is_important,
+ status_option_ids: row.status_option_ids.clone(),
}),
Self::Chat(_) | Self::Project(_) | Self::CalendarEvent(_) => None,
}
@@ -1699,6 +1734,8 @@ impl SoupRow {
viewed_at,
sub_type,
is_email_attachment: _,
+ is_important: _,
+ status_option_ids: _,
is_completed,
deleted_at,
}) => SoupItem::Document(SoupDocument {
diff --git a/crates/soup/src/outbound/pg_soup_repo/expanded/tests.rs b/crates/soup/src/outbound/pg_soup_repo/expanded/tests.rs
index b99c124355..23d1122d44 100644
--- a/crates/soup/src/outbound/pg_soup_repo/expanded/tests.rs
+++ b/crates/soup/src/outbound/pg_soup_repo/expanded/tests.rs
@@ -29,6 +29,7 @@ use models_soup::item::SoupItem;
use sqlx::{PgPool, Pool, Postgres};
use std::collections::HashSet;
use std::sync::Arc;
+use system_properties::{StatusOption, SystemPropertyKey};
use uuid::Uuid;
macro_rules! unwrap_enum {
@@ -5462,7 +5463,7 @@ async fn production_documents_presets_have_authoritative_membership(
),
migrator = "MACRO_DB_MIGRATIONS"
)]
-async fn projection_hydration_carries_attachment_state_from_flat_and_by_id_rows(
+async fn projection_hydration_carries_viewer_relative_facts_from_flat_and_by_id_rows(
db: PgPool,
) -> anyhow::Result<()> {
let user_id = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
@@ -5478,41 +5479,71 @@ async fn projection_hydration_carries_attachment_state_from_flat_and_by_id_rows(
.await?;
let attachment_id = Uuid::parse_str("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa")?;
+ let unimportant_task_id = Uuid::parse_str("bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb")?;
let ordinary_id = Uuid::parse_str("dddddddd-dddd-dddd-dddd-dddddddddddd")?;
let attachment_facts = flat
.iter()
.find(|hydration| hydration.item.id() == attachment_id)
- .and_then(|hydration| hydration.document_server_facts)
+ .and_then(|hydration| hydration.document_server_facts.clone())
.expect("attachment document server facts are hydrated");
+ let unimportant_task_facts = flat
+ .iter()
+ .find(|hydration| hydration.item.id() == unimportant_task_id)
+ .and_then(|hydration| hydration.document_server_facts.clone())
+ .expect("unimportant task server facts are hydrated");
let ordinary_facts = flat
.iter()
.find(|hydration| hydration.item.id() == ordinary_id)
- .and_then(|hydration| hydration.document_server_facts)
+ .and_then(|hydration| hydration.document_server_facts.clone())
.expect("ordinary document server facts are hydrated");
assert_eq!(
attachment_facts,
SoupDocumentServerFacts {
is_email_attachment: true,
+ is_important: true,
+ status_option_ids: vec![StatusOption::NOT_STARTED_UUID],
+ }
+ );
+ assert_eq!(
+ unimportant_task_facts,
+ SoupDocumentServerFacts {
+ is_email_attachment: true,
+ is_important: false,
+ status_option_ids: vec![StatusOption::IN_PROGRESS_UUID],
}
);
assert_eq!(
ordinary_facts,
SoupDocumentServerFacts {
is_email_attachment: false,
+ is_important: true,
+ status_option_ids: Vec::new(),
}
);
let entities = [
EntityType::Document.with_entity_string(attachment_id.to_string()),
+ EntityType::Document.with_entity_string(unimportant_task_id.to_string()),
EntityType::Document.with_entity_string(ordinary_id.to_string()),
];
let by_id = expanded_soup_by_ids_with_projection(&db, user_id, &entities).await?;
- assert_eq!(by_id.len(), 2);
+ assert_eq!(by_id.len(), 3);
assert!(by_id.iter().any(|hydration| {
hydration.item.id() == attachment_id
&& hydration.document_server_facts
== Some(SoupDocumentServerFacts {
is_email_attachment: true,
+ is_important: true,
+ status_option_ids: vec![StatusOption::NOT_STARTED_UUID],
+ })
+ }));
+ assert!(by_id.iter().any(|hydration| {
+ hydration.item.id() == unimportant_task_id
+ && hydration.document_server_facts
+ == Some(SoupDocumentServerFacts {
+ is_email_attachment: true,
+ is_important: false,
+ status_option_ids: vec![StatusOption::IN_PROGRESS_UUID],
})
}));
assert!(by_id.iter().any(|hydration| {
@@ -5520,6 +5551,8 @@ async fn projection_hydration_carries_attachment_state_from_flat_and_by_id_rows(
&& hydration.document_server_facts
== Some(SoupDocumentServerFacts {
is_email_attachment: false,
+ is_important: true,
+ status_option_ids: Vec::new(),
})
}));
@@ -5548,6 +5581,70 @@ async fn projection_hydration_carries_attachment_state_from_flat_and_by_id_rows(
Ok(())
}
+#[sqlx::test(
+ fixtures(
+ path = "../../../../../macro_db_client/fixtures",
+ scripts("entity_filter_tests")
+ ),
+ migrator = "MACRO_DB_MIGRATIONS"
+)]
+async fn projection_status_extraction_treats_non_array_values_as_empty(
+ db: PgPool,
+) -> anyhow::Result<()> {
+ let json_null_status_id = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa";
+ let scalar_status_id = "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb";
+ sqlx::query!(
+ r#"UPDATE entity_properties
+ SET values = CASE entity_id
+ WHEN $1 THEN 'null'::jsonb
+ ELSE '{"type":"String","value":"not-an-array"}'::jsonb
+ END
+ WHERE entity_id IN ($1, $2)
+ AND entity_type = 'TASK'
+ AND property_definition_id = $3"#,
+ json_null_status_id,
+ scalar_status_id,
+ SystemPropertyKey::STATUS_UUID,
+ )
+ .execute(&db)
+ .await?;
+
+ let user_id = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
+ let flat = expanded_dynamic_cursor_soup_with_projection(
+ &db,
+ ExpandedDynamicCursorArgs {
+ user_id: user_id.copied(),
+ limit: 50,
+ cursor: Query::Sort(SimpleSortMethod::CreatedAt, EntityFilterAst::default()),
+ exclude_frecency: false,
+ },
+ )
+ .await?;
+
+ for id in [json_null_status_id, scalar_status_id] {
+ let id = Uuid::parse_str(id)?;
+ let facts = flat
+ .iter()
+ .find(|hydration| hydration.item.id() == id)
+ .and_then(|hydration| hydration.document_server_facts.as_ref())
+ .expect("task document server facts are hydrated");
+ assert!(facts.status_option_ids.is_empty());
+ }
+
+ let entities = [json_null_status_id, scalar_status_id]
+ .map(|id| EntityType::Document.with_entity_string(id.to_string()));
+ let by_id = expanded_soup_by_ids_with_projection(&db, user_id, &entities).await?;
+ assert_eq!(by_id.len(), 2);
+ assert!(by_id.iter().all(|hydration| {
+ hydration
+ .document_server_facts
+ .as_ref()
+ .is_some_and(|facts| facts.status_option_ids.is_empty())
+ }));
+
+ Ok(())
+}
+
// Test filtering documents by is_email_attachment = true (only email attachments)
#[sqlx::test(
fixtures(
diff --git a/crates/soup_filter_cache_adapter/src/lib.rs b/crates/soup_filter_cache_adapter/src/lib.rs
index 6fc219738b..2858ae1c71 100644
--- a/crates/soup_filter_cache_adapter/src/lib.rs
+++ b/crates/soup_filter_cache_adapter/src/lib.rs
@@ -10,7 +10,7 @@ use cache_core::predicate::{ProjectionIncompleteKind, ProjectionMutation};
use graphql_soup_filter_input::materialize_graphql_filter;
use indexmap::IndexMap;
use item_filter_index::{
- LocalCompileOutcome, SoupFlatRequest, SoupIndexSort, compile_soup_flat_v2, vocabulary,
+ LocalCompileOutcome, SoupFlatRequest, SoupIndexSort, compile_soup_flat_v3, vocabulary,
};
use predicate_index::{
ExactAttributePatch, ExactValue, IndexDocument, OptimisticProjectionMutation, RecordKey,
@@ -18,7 +18,7 @@ use predicate_index::{
};
use soup_filter_projection::{
DirectProjectionInput, DirectProjectionPatchInput, DocumentSubType,
- SoupCacheProjectionSupplement, SoupFlatEntityKind, compose_soup_flat_v2,
+ SoupCacheProjectionSupplement, SoupFlatEntityKind, compose_soup_flat_v3,
decode_cache_projection_supplement, patch_direct_fields, project_direct_fields,
};
use std::collections::HashSet;
@@ -60,7 +60,7 @@ pub fn compile_filter_request(
));
}
};
- compile_soup_flat_v2(
+ compile_soup_flat_v3(
&ast,
SoupFlatRequest {
sort,
@@ -80,10 +80,10 @@ pub fn compile_filter_request(
///
/// Document supplements are decoded only where `cacheProjection` is selected
/// for the surrounding entity and are merged with direct fields from that same
-/// object. A selected null or missing Document supplement marks v2 incomplete;
+/// object. A selected null or missing Document supplement marks v3 incomplete;
/// selected null values on direct-only Projects and Chats are expected. Mutation
-/// payloads that omit the field become bounded v2 direct-field patches,
-/// preserving relation-owned facts from an existing complete projection. Query
+/// payloads that omit the field become bounded v3 direct-field patches,
+/// preserving server-owned facts from an existing complete projection. Query
/// and subscription documents without the field retain the legacy v1 direct
/// projection during the staged rollout.
pub fn authoritative_projection_mutations(
@@ -124,7 +124,7 @@ pub fn authoritative_projection_mutations(
let has_incomplete_projection = has_unbound_incomplete_entity
|| mutations
.values()
- .any(|mutation| matches!(mutation, ProjectionMutation::MarkIncomplete { profile, .. } if profile == &vocabulary::profile_v2()));
+ .any(|mutation| matches!(mutation, ProjectionMutation::MarkIncomplete { profile, .. } if profile == &vocabulary::profile_v3()));
if operation_name.is_some_and(|name| name.starts_with("SoupBackfill"))
&& has_incomplete_projection
{
@@ -172,7 +172,7 @@ fn walk_authoritative_object(
let kind = projection_kind(&partition).expect("supported partition has a kind");
let mutation = if projection_fields.is_empty() {
if operation_kind == OperationKind::Mutation {
- match authoritative_v2_patch_for_object(
+ match authoritative_v3_patch_for_object(
record_key.clone(),
partition.clone(),
object,
@@ -180,7 +180,7 @@ fn walk_authoritative_object(
Ok(mutation) => mutation,
Err(()) => Some(ProjectionMutation::MarkIncomplete {
record_key,
- profile: vocabulary::profile_v2(),
+ profile: vocabulary::profile_v3(),
partition,
kind: ProjectionIncompleteKind::Dirty,
}),
@@ -211,7 +211,7 @@ fn walk_authoritative_object(
))
} else {
Some(
- complete_v2_projection_for_object(
+ complete_v3_projection_for_object(
record_key.clone(),
partition.clone(),
object,
@@ -220,7 +220,7 @@ fn walk_authoritative_object(
.map(ProjectionMutation::Replace)
.unwrap_or(ProjectionMutation::MarkIncomplete {
record_key,
- profile: vocabulary::profile_v2(),
+ profile: vocabulary::profile_v3(),
partition,
kind: ProjectionIncompleteKind::IncompatibleVersion,
}),
@@ -307,7 +307,7 @@ fn selected_document_projection_for_object(
) -> ProjectionMutation {
let incomplete = |kind| ProjectionMutation::MarkIncomplete {
record_key: record_key.clone(),
- profile: vocabulary::profile_v2(),
+ profile: vocabulary::profile_v3(),
partition: partition.clone(),
kind,
};
@@ -334,13 +334,13 @@ fn selected_document_projection_for_object(
let Ok(supplement) = decode_cache_projection_supplement(encoded) else {
return incomplete(ProjectionIncompleteKind::IncompatibleVersion);
};
- if supplement.target_profile() != &vocabulary::profile_v2()
+ if supplement.target_profile() != &vocabulary::profile_v3()
|| supplement.record_key() != &record_key
|| supplement.partition() != &partition
{
return incomplete(ProjectionIncompleteKind::IncompatibleVersion);
}
- complete_v2_projection_for_object(
+ complete_v3_projection_for_object(
record_key.clone(),
partition.clone(),
object,
@@ -394,7 +394,7 @@ pub fn optimistic_projection_mutations(
key_text,
OptimisticProjectionMutation::Delete {
record_key,
- profile: vocabulary::profile_v2(),
+ profile: vocabulary::profile_v3(),
partition,
},
);
@@ -416,7 +416,7 @@ pub fn optimistic_projection_mutations(
)
.unwrap_or(OptimisticProjectionMutation::Unknown {
record_key,
- profile: vocabulary::profile_v2(),
+ profile: vocabulary::profile_v3(),
partition,
affected_attributes: Vec::new(),
});
@@ -449,7 +449,7 @@ pub fn dirty_projection_mutations(keys: &[String]) -> Vec<ProjectionMutation> {
let partition = projection_partition(typename)?;
Some(ProjectionMutation::MarkIncomplete {
record_key: RecordKey::new(key.clone()).ok()?,
- profile: vocabulary::profile_v2(),
+ profile: vocabulary::profile_v3(),
partition,
kind: ProjectionIncompleteKind::Dirty,
})
@@ -504,7 +504,7 @@ fn direct_projection_for_object(
.ok()
}
-fn complete_v2_projection_for_object(
+fn complete_v3_projection_for_object(
record_key: RecordKey,
partition: Token,
object: &serde_json::Map<String, serde_json::Value>,
@@ -517,10 +517,10 @@ fn complete_v2_projection_for_object(
} else {
None
};
- compose_soup_flat_v2(input, sub_type, supplement).map_err(|_| ())
+ compose_soup_flat_v3(input, sub_type, supplement).map_err(|_| ())
}
-fn authoritative_v2_patch_for_object(
+fn authoritative_v3_patch_for_object(
record_key: RecordKey,
partition: Token,
object: &serde_json::Map<String, serde_json::Value>,
@@ -589,7 +589,7 @@ fn authoritative_v2_patch_for_object(
}
Ok(Some(ProjectionMutation::Patch {
record_key,
- profile: vocabulary::profile_v2(),
+ profile: vocabulary::profile_v3(),
partition,
exact,
integers,
@@ -635,7 +635,7 @@ fn optimistic_projection_for_object(
Some(created_at_ms),
)
{
- let document = compose_soup_flat_v2(input, None, None).ok()?;
+ let document = compose_soup_flat_v3(input, None, None).ok()?;
return Some(OptimisticProjectionMutation::Replace(document));
}
@@ -693,7 +693,7 @@ fn optimistic_projection_for_object(
}
Some(OptimisticProjectionMutation::Patch {
record_key,
- profile: vocabulary::profile_v2(),
+ profile: vocabulary::profile_v3(),
partition,
exact,
integers,
diff --git a/crates/soup_filter_cache_adapter/src/test.rs b/crates/soup_filter_cache_adapter/src/test.rs
index 0284198c71..d2587e335a 100644
--- a/crates/soup_filter_cache_adapter/src/test.rs
+++ b/crates/soup_filter_cache_adapter/src/test.rs
@@ -1,7 +1,7 @@
use serde::Deserialize;
use soup_filter_projection::{
SoupCacheProjectionSupplement, decode_cache_projection_supplement,
- encode_cache_projection_supplement, validate_soup_flat_v2,
+ encode_cache_projection_supplement, validate_soup_flat_v3,
};
use std::collections::BTreeMap;
@@ -30,7 +30,7 @@ fn optimistic_soup_payloads_compile_to_durable_projection_layers() {
else {
panic!("partial optimistic Soup entity should compile to a patch");
};
- assert_eq!(profile, &vocabulary::profile_v2());
+ assert_eq!(profile, &vocabulary::profile_v3());
assert!(
exact
.iter()
@@ -61,9 +61,9 @@ fn optimistic_soup_payloads_compile_to_durable_projection_layers() {
);
let [OptimisticProjectionMutation::Patch { profile, exact, .. }] = document_create.as_slice()
else {
- panic!("a document create without an attachment fact must patch, not claim completeness");
+ panic!("a document create without server facts must patch, not claim completeness");
};
- assert_eq!(profile, &vocabulary::profile_v2());
+ assert_eq!(profile, &vocabulary::profile_v3());
assert!(
exact
.iter()
@@ -88,9 +88,9 @@ fn optimistic_soup_payloads_compile_to_durable_projection_layers() {
456,
);
let [OptimisticProjectionMutation::Replace(complete)] = complete.as_slice() else {
- panic!("a project optimistic create has every required v2 fact");
+ panic!("a project optimistic create has every required v3 fact");
};
- assert_eq!(complete.profile, vocabulary::profile_v2());
+ assert_eq!(complete.profile, vocabulary::profile_v3());
let deletion = optimistic_projection_mutations(
&serde_json::json!({
@@ -247,9 +247,20 @@ const SUPPLEMENT_BACKFILL: &str = r#"query SoupBackfill {
}"#;
fn document_supplement(id: &str, is_email_attachment: bool) -> String {
+ document_supplement_with_task_facts(id, is_email_attachment, true, Vec::new())
+}
+
+fn document_supplement_with_task_facts(
+ id: &str,
+ is_email_attachment: bool,
+ is_important: bool,
+ status_option_ids: Vec<uuid::Uuid>,
+) -> String {
encode_cache_projection_supplement(&SoupCacheProjectionSupplement::document(
RecordKey::new(format!("GraphqlSoupDocument:{id}")).unwrap(),
is_email_attachment,
+ is_important,
+ status_option_ids,
))
.unwrap()
}
@@ -282,7 +293,7 @@ fn supplement_subscription_data(item: serde_json::Value) -> serde_json::Value {
}
#[test]
-fn selected_document_supplement_composes_direct_fields_and_only_adds_attachment_state() {
+fn selected_document_supplement_composes_direct_and_server_owned_facts() {
let id = "00000000-0000-0000-0000-000000000001";
let encoded = document_supplement(id, false);
let mutations = authoritative_projection_mutations(
@@ -298,7 +309,7 @@ fn selected_document_supplement_composes_direct_fields_and_only_adds_attachment_
let [ProjectionMutation::Replace(document)] = mutations.as_slice() else {
panic!("a valid selected supplement and direct fields must replace authority");
};
- assert_eq!(document.profile, vocabulary::profile_v2());
+ assert_eq!(document.profile, vocabulary::profile_v3());
assert_eq!(document.partition, vocabulary::document_partition());
assert!(document.exact_facts.iter().any(|fact| {
fact.attribute == vocabulary::owner()
@@ -340,6 +351,41 @@ fn selected_document_supplement_composes_direct_fields_and_only_adds_attachment_
);
}
+#[test]
+fn selected_document_supplement_composes_importance_and_status_facts() {
+ let id = "00000000-0000-0000-0000-000000000001";
+ let status_a = uuid::Uuid::from_u128(11);
+ let status_b = uuid::Uuid::from_u128(12);
+ let mutations = authoritative_projection_mutations(
+ SUPPLEMENT_SUBSCRIPTION,
+ Some("Supplement"),
+ &supplement_subscription_data(selected_document(
+ id,
+ serde_json::Value::String(document_supplement_with_task_facts(
+ id,
+ false,
+ false,
+ vec![status_b, status_a],
+ )),
+ serde_json::json!({ "__typename": "GraphqlTaskSubType" }),
+ )),
+ )
+ .unwrap();
+ let [ProjectionMutation::Replace(document)] = mutations.as_slice() else {
+ panic!("viewer-relative facts must compose into one complete projection");
+ };
+ assert!(document.exact_facts.iter().any(|fact| {
+ fact.attribute == vocabulary::importance() && fact.value == ExactValue::new([0]).unwrap()
+ }));
+ let statuses = document
+ .exact_facts
+ .iter()
+ .filter(|fact| fact.attribute == vocabulary::task_status_option())
+ .map(|fact| fact.value.as_bytes())
+ .collect::<Vec<_>>();
+ assert_eq!(statuses, vec![status_a.as_bytes(), status_b.as_bytes()]);
+}
+
#[test]
fn document_subtype_postings_are_composed_from_graphql_typenames() {
for (suffix, typename, expected) in [
@@ -369,7 +415,7 @@ fn document_subtype_postings_are_composed_from_graphql_typenames() {
}
#[test]
-fn selected_project_and_chat_null_supplements_are_valid_direct_only_v2_hydration() {
+fn selected_project_and_chat_null_supplements_are_valid_direct_only_v3_hydration() {
let query = r#"query SoupBackfill {
user { soup(input: { initial: { limit: 2 } }) { items {
__typename
@@ -411,7 +457,7 @@ fn selected_project_and_chat_null_supplements_are_valid_direct_only_v2_hydration
let ProjectionMutation::Replace(document) = mutation else {
panic!("direct-only entity must produce a complete replacement");
};
- validate_soup_flat_v2(document).unwrap();
+ validate_soup_flat_v3(document).unwrap();
assert_ne!(document.partition, vocabulary::document_partition());
}
}
@@ -457,7 +503,7 @@ fn missing_malformed_or_mismatched_document_supplements_remain_incomplete() {
matches!(
mutations.as_slice(),
[ProjectionMutation::MarkIncomplete { profile, kind, .. }]
- if profile == &vocabulary::profile_v2() && *kind == expected_kind
+ if profile == &vocabulary::profile_v3() && *kind == expected_kind
),
"{name}: {mutations:?}"
);
@@ -514,7 +560,7 @@ fn backfill_rejects_invalid_supplements_and_missing_direct_document_fields() {
}
#[test]
-fn partial_mutation_payloads_patch_v2_without_fabricating_relation_facts() {
+fn partial_mutation_payloads_patch_v3_without_fabricating_server_facts() {
let query = r#"mutation PartialRename($inputs: [RenameEntityInput!]!) {
renameEntities(inputs: $inputs) {
results {
@@ -573,9 +619,9 @@ fn partial_mutation_payloads_patch_v2_without_fabricating_relation_facts() {
},
] = mutations.as_slice()
else {
- panic!("partial authoritative entity must produce one v2 patch");
+ panic!("partial authoritative entity must produce one v3 patch");
};
- assert_eq!(profile, &vocabulary::profile_v2());
+ assert_eq!(profile, &vocabulary::profile_v3());
assert!(
exact
.iter()
@@ -718,9 +764,9 @@ fn production_documents_presets_compile_for_created_and_updated_sorts() {
)
.unwrap_or_else(|error| panic!("{name} should materialize: {error}"));
let SoupFilterCompileOutcome::Supported(query) = outcome else {
- panic!("{name} must be soup-flat-v2 eligible");
+ panic!("{name} must be soup-flat-v3 eligible");
};
- assert_eq!(query.as_query().profile, vocabulary::profile_v2(), "{name}");
+ assert_eq!(query.as_query().profile, vocabulary::profile_v3(), "{name}");
assert_eq!(query.as_query().sort_attribute, sort_attribute, "{name}");
assert_eq!(query.as_query().sort_direction, direction, "{name}");
assert_eq!(query.as_query().tie_break_direction, direction, "{name}");
@@ -729,6 +775,66 @@ fn production_documents_presets_compile_for_created_and_updated_sorts() {
}
}
+#[test]
+fn production_my_tasks_importance_and_status_filter_compiles_locally() {
+ let mut filters = production_documents_filters(serde_json::json!({
+ "and": {
+ "left": { "literal": { "subType": "TASK" } },
+ "right": {
+ "or": {
+ "left": { "literal": { "owner": "macro|[email protected]" } },
+ "right": { "literal": { "importance": true } }
+ }
+ }
+ }
+ }));
+ filters.as_object_mut().unwrap().insert(
+ "propertiesFilter".to_owned(),
+ serde_json::json!({
+ "or": {
+ "left": {
+ "literal": {
+ "propertyDefinitionId": "00000001-0000-0000-0000-000000000002",
+ "value": {
+ "selectOption": "00000001-0000-0000-0002-000000000001"
+ }
+ }
+ },
+ "right": {
+ "or": {
+ "left": {
+ "literal": {
+ "propertyDefinitionId": "00000001-0000-0000-0000-000000000002",
+ "value": {
+ "selectOption": "00000001-0000-0000-0002-000000000002"
+ }
+ }
+ },
+ "right": {
+ "literal": {
+ "propertyDefinitionId": "00000001-0000-0000-0000-000000000002",
+ "value": {
+ "selectOption": "00000001-0000-0000-0002-000000000003"
+ }
+ }
+ }
+ }
+ }
+ }
+ }),
+ );
+
+ let SoupFilterCompileOutcome::Supported(query) =
+ compile_filter_request(filters, "UPDATED_AT", "DESC", 100).unwrap()
+ else {
+ panic!("production My Tasks filter must use the local v3 profile");
+ };
+ assert_eq!(query.as_query().profile, vocabulary::profile_v3());
+ let document = &query.as_query().partitions[0].predicate;
+ assert!(format!("{document:?}").contains("importance"));
+ assert!(format!("{document:?}").contains("task-status-option"));
+}
+
#[cfg(not(target_arch = "wasm32"))]
fn differential_document(
id: &str,
@@ -751,6 +857,10 @@ fn differential_document(
attribute: vocabulary::email_attachment(),
value: ExactValue::new([u8::from(is_email_attachment)]).unwrap(),
},
+ predicate_index::ExactFact {
+ attribute: vocabulary::importance(),
+ value: ExactValue::new([1]).unwrap(),
+ },
];
if let Some(sub_type) = sub_type {
exact_facts.push(predicate_index::ExactFact {
@@ -760,7 +870,7 @@ fn differential_document(
}
IndexDocument {
record_key: RecordKey::new(format!("GraphqlSoupDocument:{id}")).unwrap(),
- profile: vocabulary::profile_v2(),
+ profile: vocabulary::profile_v3(),
partition: vocabulary::document_partition(),
exact_facts,
integer_facts: vec![
@@ -833,7 +943,7 @@ fn production_documents_membership_matches_postgres_fixture_reference_and_real_t
),
];
let mut storage =
- cache_turso::TursoStorage::open_in_memory("soup-v2-production-shape-differential")
+ cache_turso::TursoStorage::open_in_memory("soup-v3-production-shape-differential")
.unwrap();
storage
.put_batch_with_projections(
@@ -942,23 +1052,23 @@ fn production_documents_membership_matches_postgres_fixture_reference_and_real_t
}
#[test]
-fn production_documents_presets_keep_unsupported_siblings_all_or_network() {
+fn production_documents_presets_support_importance_in_v3() {
let with_unsupported_sibling = serde_json::json!({
"and": {
"left": { "literal": { "isEmailAttachment": false } },
"right": { "literal": { "importance": true } }
}
});
- assert!(matches!(
- compile_filter_request(
- production_documents_filters(with_unsupported_sibling),
- "UPDATED_AT",
- "DESC",
- 100,
- )
- .unwrap(),
- SoupFilterCompileOutcome::Unsupported
- ));
+ let SoupFilterCompileOutcome::Supported(query) = compile_filter_request(
+ production_documents_filters(with_unsupported_sibling),
+ "UPDATED_AT",
+ "DESC",
+ 100,
+ )
+ .unwrap() else {
+ panic!("importance must compile in soup-flat-v3");
+ };
+ assert_eq!(query.as_query().profile, vocabulary::profile_v3());
}
#[derive(Debug, Deserialize)]
@@ -991,6 +1101,30 @@ struct SemanticCapsuleV1 {
is_email_attachment: bool,
}
+#[derive(Debug, Deserialize)]
+struct CapsuleFixtureFileV2 {
+ fixture_format: String,
+ transport: CapsuleFixtureTransport,
+ capsules: Vec<CapsuleFixtureCaseV2>,
+}
+
+#[derive(Debug, Deserialize)]
+struct CapsuleFixtureCaseV2 {
+ name: String,
+ capsule: SemanticCapsuleV2,
+ expected_base64: String,
+}
+
+#[derive(Debug, Deserialize)]
+struct SemanticCapsuleV2 {
+ target_profile: String,
+ record_key: String,
+ partition: String,
+ is_email_attachment: bool,
+ is_important: bool,
+ status_option_ids: Vec<uuid::Uuid>,
+}
+
#[test]
fn soup_flat_v2_supplement_goldens_lock_typed_server_fact_wire() {
let fixtures: CapsuleFixtureFile = serde_json::from_str(include_str!(
@@ -1037,3 +1171,46 @@ fn soup_flat_v2_supplement_goldens_lock_typed_server_fact_wire() {
);
}
}
+
+#[test]
+fn soup_flat_v3_supplement_goldens_lock_viewer_relative_wire() {
+ let fixtures: CapsuleFixtureFileV2 = serde_json::from_str(include_str!(
+ "../../soup_filter_projection/testdata/soup-flat-v3-capsules.json"
+ ))
+ .expect("valid capsule fixture JSON");
+
+ assert_eq!(fixtures.fixture_format, "server-fact-supplement-capsule-v2");
+ assert_eq!(fixtures.transport.base64_variant, "RFC4648_STANDARD_NO_PAD");
+ assert_eq!(fixtures.transport.frame, "wire-version-byte-plus-postcard");
+ assert_eq!(fixtures.transport.wire_version, 2);
+ assert_eq!(
+ fixtures.transport.max_decoded_bytes,
+ soup_filter_projection::MAX_SOUP_CACHE_PROJECTION_BYTES
+ );
+
+ for case in fixtures.capsules {
+ let decoded = decode_cache_projection_supplement(&case.expected_base64)
+ .unwrap_or_else(|error| panic!("{} must decode: {error}", case.name));
+ assert_eq!(
+ decoded.target_profile().token().as_str(),
+ case.capsule.target_profile
+ );
+ assert_eq!(decoded.record_key().as_str(), case.capsule.record_key);
+ assert_eq!(decoded.partition().as_str(), case.capsule.partition);
+ assert_eq!(
+ decoded.is_email_attachment(),
+ case.capsule.is_email_attachment
+ );
+ assert_eq!(decoded.is_important(), Some(case.capsule.is_important));
+ assert_eq!(
+ decoded.status_option_ids(),
+ Some(case.capsule.status_option_ids.as_slice())
+ );
+ assert_eq!(
+ encode_cache_projection_supplement(&decoded).unwrap(),
+ case.expected_base64,
+ "{} scalar bytes",
+ case.name
+ );
+ }
+}
diff --git a/crates/soup_filter_projection/src/lib.rs b/crates/soup_filter_projection/src/lib.rs
index eeddb7739a..7a23561fcb 100644
--- a/crates/soup_filter_projection/src/lib.rs
+++ b/crates/soup_filter_projection/src/lib.rs
@@ -19,14 +19,18 @@ use thiserror::Error;
mod profile;
mod wire;
-pub use profile::{ProfileValidationError, validate_soup_flat_v2};
+pub use profile::{ProfileValidationError, validate_soup_flat_v2, validate_soup_flat_v3};
pub use wire::{
MAX_SOUP_CACHE_PROJECTION_BYTES, MAX_SOUP_CACHE_PROJECTION_ENCODED_BYTES,
- SOUP_CACHE_PROJECTION_WIRE_VERSION, SoupCacheProjectionCapsuleV1,
- SoupCacheProjectionSupplement, SoupCacheProjectionWireError,
+ SOUP_CACHE_PROJECTION_WIRE_VERSION, SOUP_CACHE_PROJECTION_WIRE_VERSION_V1,
+ SOUP_CACHE_PROJECTION_WIRE_VERSION_V2, SoupCacheProjectionCapsuleV1,
+ SoupCacheProjectionCapsuleV2, SoupCacheProjectionSupplement, SoupCacheProjectionWireError,
decode_cache_projection_supplement, encode_cache_projection_supplement,
};
+/// Maximum authoritative task Status options accepted in one complete projection.
+pub const MAX_TASK_STATUS_OPTION_IDS: usize = 64;
+
#[cfg(test)]
mod test;
@@ -76,6 +80,41 @@ pub enum SoupFlatV2CompositionError {
Profile(#[from] ProfileValidationError),
}
+/// Failure to compose one complete `soup-flat-v3` projection.
+#[derive(Debug, Error, PartialEq, Eq)]
+pub enum SoupFlatV3CompositionError {
+ /// A Document did not carry authoritative server state.
+ #[error("missing authoritative Document projection supplement")]
+ MissingDocumentSupplement,
+ /// A direct-only Project or Chat unexpectedly received a supplement.
+ #[error("unexpected projection supplement for direct-only Soup entity")]
+ UnexpectedSupplement,
+ /// A non-Document projection was supplied a Document subtype.
+ #[error("unexpected Document subtype for Soup entity partition")]
+ UnexpectedDocumentSubType,
+ /// The supplement belongs to another normalized record.
+ #[error("projection supplement record key does not match the GraphQL entity")]
+ SupplementRecordKeyMismatch,
+ /// The supplement targets another complete projection profile.
+ #[error("projection supplement target profile does not match soup-flat-v3")]
+ SupplementTargetProfileMismatch,
+ /// The supplement belongs to another entity partition.
+ #[error("projection supplement partition does not match the GraphQL entity")]
+ SupplementPartitionMismatch,
+ /// The supplement omitted viewer-relative facts required by v3.
+ #[error("projection supplement omitted required soup-flat-v3 facts")]
+ MissingViewerRelativeFacts,
+ /// Direct GraphQL fields could not be projected canonically.
+ #[error(transparent)]
+ Direct(#[from] ProjectionError),
+ /// A composed canonical fact violated generic IR bounds.
+ #[error(transparent)]
+ Validation(#[from] ValidationError),
+ /// The final composed document violated the complete v3 profile.
+ #[error(transparent)]
+ Profile(#[from] ProfileValidationError),
+}
+
/// Supported direct-field Soup entity kind.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SoupFlatEntityKind {
@@ -219,6 +258,78 @@ pub fn compose_soup_flat_v2(
Ok(document)
}
+/// Compose direct GraphQL facts and a server-only supplement into one
+/// canonical, validated `soup-flat-v3` projection.
+///
+/// Documents require exactly one v3 supplement and obtain authoritative
+/// attachment, viewer-relative importance, and complete task Status facts from
+/// it. Projects and Chats remain complete from direct fields alone.
+pub fn compose_soup_flat_v3(
+ input: DirectProjectionInput,
+ document_sub_type: Option<DocumentSubType>,
+ supplement: Option<&SoupCacheProjectionSupplement>,
+) -> Result<IndexDocument, SoupFlatV3CompositionError> {
+ let kind = input.kind;
+ let expected_record_key = input.record_key.clone();
+ let expected_partition = kind.partition();
+ let mut document = project_direct_fields(input)?;
+ document.profile = vocabulary::profile_v3();
+
+ match kind {
+ SoupFlatEntityKind::Document => {
+ let supplement =
+ supplement.ok_or(SoupFlatV3CompositionError::MissingDocumentSupplement)?;
+ if supplement.record_key() != &expected_record_key {
+ return Err(SoupFlatV3CompositionError::SupplementRecordKeyMismatch);
+ }
+ if supplement.target_profile() != &vocabulary::profile_v3() {
+ return Err(SoupFlatV3CompositionError::SupplementTargetProfileMismatch);
+ }
+ if supplement.partition() != &expected_partition {
+ return Err(SoupFlatV3CompositionError::SupplementPartitionMismatch);
+ }
+ if let Some(sub_type) = document_sub_type {
+ document.exact_facts.push(utf8_fact(
+ vocabulary::document_sub_type(),
+ sub_type.to_string(),
+ )?);
+ }
+ document.exact_facts.push(ExactFact {
+ attribute: vocabulary::email_attachment(),
+ value: ExactValue::new([u8::from(supplement.is_email_attachment())])?,
+ });
+ let is_important = supplement
+ .is_important()
+ .ok_or(SoupFlatV3CompositionError::MissingViewerRelativeFacts)?;
+ document.exact_facts.push(ExactFact {
+ attribute: vocabulary::importance(),
+ value: ExactValue::new([u8::from(is_important)])?,
+ });
+ let status_option_ids = supplement
+ .status_option_ids()
+ .ok_or(SoupFlatV3CompositionError::MissingViewerRelativeFacts)?;
+ for status_option_id in status_option_ids {
+ document.exact_facts.push(uuid_fact(
+ vocabulary::task_status_option(),
+ *status_option_id,
+ )?);
+ }
+ }
+ SoupFlatEntityKind::Project | SoupFlatEntityKind::Chat => {
+ if supplement.is_some() {
+ return Err(SoupFlatV3CompositionError::UnexpectedSupplement);
+ }
+ if document_sub_type.is_some() {
+ return Err(SoupFlatV3CompositionError::UnexpectedDocumentSubType);
+ }
+ }
+ }
+
+ document.canonicalize();
+ validate_soup_flat_v3(&document)?;
+ Ok(document)
+}
+
/// Generate a generic optimistic patch from partial direct Soup fields.
pub fn patch_direct_fields(
input: DirectProjectionPatchInput,
@@ -384,7 +495,7 @@ pub fn project_soup_cache_supplement(
record_key: RecordKey,
hydration: &SoupProjectionHydration,
) -> Result<Option<SoupCacheProjectionSupplement>, ProjectionError> {
- let Some(server_facts) = hydration.document_server_facts else {
+ let Some(server_facts) = hydration.document_server_facts.as_ref() else {
return Ok(None);
};
if !matches!(&hydration.item, SoupItem::Document(_)) {
@@ -393,6 +504,8 @@ pub fn project_soup_cache_supplement(
Ok(Some(SoupCacheProjectionSupplement::document(
record_key,
server_facts.is_email_attachment,
+ server_facts.is_important,
+ server_facts.status_option_ids.clone(),
)))
}
diff --git a/crates/soup_filter_projection/src/profile.rs b/crates/soup_filter_projection/src/profile.rs
index 46bf13fad4..d0f3d64428 100644
--- a/crates/soup_filter_projection/src/profile.rs
+++ b/crates/soup_filter_projection/src/profile.rs
@@ -5,16 +5,16 @@ use model_file_type::FileType;
use predicate_index::{ExactFact, IndexDocument, IntegerFact, Token, ValidationError};
use thiserror::Error;
-/// Semantic validation failure for one complete `soup-flat-v2` document.
+/// Semantic validation failure for one complete versioned Soup document.
#[derive(Debug, Error, PartialEq, Eq)]
pub enum ProfileValidationError {
/// Generic storage-neutral document bounds were violated.
#[error(transparent)]
Generic(#[from] ValidationError),
- /// The complete document declares a profile other than `soup-flat-v2`.
+ /// The complete document declares a profile other than the expected version.
#[error("unsupported Soup projection profile `{0}`")]
UnsupportedProfile(String),
- /// The complete document declares a partition outside the v2 profile.
+ /// The complete document declares a partition outside the supported profiles.
#[error("unsupported Soup projection partition `{0}`")]
UnsupportedPartition(String),
/// A fact attribute is not allowed for this partition and profile.
@@ -32,8 +32,17 @@ pub enum ProfileValidationError {
#[error("duplicate Soup projection fact `{0}`")]
Duplicate(&'static str),
/// A fact uses a malformed canonical value.
- #[error("invalid canonical value for Soup projection fact `{0}`")]
+ #[error("invalid canonical value for Soup projection fact `{0}")]
InvalidValue(&'static str),
+ /// A multi-valued fact exceeds its profile-specific bound.
+ #[error("too many values for Soup projection fact `{0}")]
+ TooManyValues(&'static str),
+}
+
+#[derive(Clone, Copy, PartialEq, Eq)]
+enum ProfileVersion {
+ V2,
+ V3,
}
#[derive(Clone, Copy, PartialEq, Eq)]
@@ -46,8 +55,25 @@ enum PartitionKind {
/// Validate strict Soup-specific completeness and canonical value semantics for
/// one composed `soup-flat-v2` index document.
pub fn validate_soup_flat_v2(document: &IndexDocument) -> Result<(), ProfileValidationError> {
+ validate_soup_flat(document, ProfileVersion::V2)
+}
+
+/// Validate strict Soup-specific completeness and canonical value semantics for
+/// one composed `soup-flat-v3` index document.
+pub fn validate_soup_flat_v3(document: &IndexDocument) -> Result<(), ProfileValidationError> {
+ validate_soup_flat(document, ProfileVersion::V3)
+}
+
+fn validate_soup_flat(
+ document: &IndexDocument,
+ version: ProfileVersion,
+) -> Result<(), ProfileValidationError> {
document.validate()?;
- if document.profile != vocabulary::profile_v2() {
+ let expected_profile = match version {
+ ProfileVersion::V2 => vocabulary::profile_v2(),
+ ProfileVersion::V3 => vocabulary::profile_v3(),
+ };
+ if document.profile != expected_profile {
return Err(ProfileValidationError::UnsupportedProfile(
document.profile.token().as_str().to_owned(),
));
@@ -65,13 +91,14 @@ pub fn validate_soup_flat_v2(document: &IndexDocument) -> Result<(), ProfileVali
));
};
- validate_exact_facts(kind, &document.exact_facts)?;
+ validate_exact_facts(version, kind, &document.exact_facts)?;
validate_integer_family("integer", &document.integer_facts)?;
validate_integer_family("sort", &document.sort_facts)?;
Ok(())
}
fn validate_exact_facts(
+ version: ProfileVersion,
kind: PartitionKind,
facts: &[ExactFact],
) -> Result<(), ProfileValidationError> {
@@ -81,6 +108,8 @@ fn validate_exact_facts(
let mut file_type = 0;
let mut sub_type = 0;
let mut email_attachment = 0;
+ let mut importance = 0;
+ let mut status_options = 0;
for fact in facts {
let attribute = &fact.attribute;
@@ -117,6 +146,22 @@ fn validate_exact_facts(
if !matches!(value, [0] | [1]) {
return Err(ProfileValidationError::InvalidValue("email-attachment"));
}
+ } else if version == ProfileVersion::V3
+ && attribute == &vocabulary::importance()
+ && kind == PartitionKind::Document
+ {
+ importance += 1;
+ if !matches!(value, [0] | [1]) {
+ return Err(ProfileValidationError::InvalidValue("importance"));
+ }
+ } else if version == ProfileVersion::V3
+ && attribute == &vocabulary::task_status_option()
+ && kind == PartitionKind::Document
+ {
+ status_options += 1;
+ if value.len() != 16 {
+ return Err(ProfileValidationError::InvalidValue("task-status-option"));
+ }
} else {
return Err(unexpected("exact", attribute));
}
@@ -128,7 +173,15 @@ fn validate_exact_facts(
allow_at_most_one("file-type", file_type)?;
allow_at_most_one("document-sub-type", sub_type)?;
match kind {
- PartitionKind::Document => require_one("email-attachment", email_attachment)?,
+ PartitionKind::Document => {
+ require_one("email-attachment", email_attachment)?;
+ if version == ProfileVersion::V3 {
+ require_one("importance", importance)?;
+ if status_options > crate::MAX_TASK_STATUS_OPTION_IDS {
+ return Err(ProfileValidationError::TooManyValues("task-status-option"));
+ }
+ }
+ }
PartitionKind::Project | PartitionKind::Chat if email_attachment != 0 => {
return Err(ProfileValidationError::UnexpectedAttribute {
family: "exact",
diff --git a/crates/soup_filter_projection/src/test.rs b/crates/soup_filter_projection/src/test.rs
index 295117f292..90f9eb9ce2 100644
--- a/crates/soup_filter_projection/src/test.rs
+++ b/crates/soup_filter_projection/src/test.rs
@@ -52,6 +52,8 @@ fn document_hydration(
item: SoupItem::Document(document(id, sub_type)),
document_server_facts: Some(SoupDocumentServerFacts {
is_email_attachment,
+ is_important: true,
+ status_option_ids: Vec::new(),
}),
}
}
@@ -72,7 +74,8 @@ fn composed_v2_document(
"skill" => DocumentSubType::Skill,
value => panic!("unsupported test subtype {value}"),
});
- let supplement = SoupCacheProjectionSupplement::document(document_key(id), is_email_attachment);
+ let supplement =
+ SoupCacheProjectionSupplement::document_v2(document_key(id), is_email_attachment);
compose_soup_flat_v2(
DirectProjectionInput {
record_key: document_key(id),
@@ -220,15 +223,19 @@ fn document_supplement_contains_only_authoritative_relation_state() {
.unwrap()
.unwrap();
- assert_eq!(supplement.target_profile(), &vocabulary::profile_v2());
+ assert_eq!(supplement.target_profile(), &vocabulary::profile_v3());
assert_eq!(supplement.partition(), &vocabulary::document_partition());
assert_eq!(supplement.record_key(), &document_key(id));
assert!(!supplement.is_email_attachment());
+ assert_eq!(supplement.is_important(), Some(true));
+ assert_eq!(supplement.status_option_ids(), Some(&[] as &[Uuid]));
- let wire = SoupCacheProjectionCapsuleV1::from(&supplement);
- assert_eq!(wire.target_profile, "soup-flat-v2");
+ let wire = SoupCacheProjectionCapsuleV2::try_from(&supplement).unwrap();
+ assert_eq!(wire.target_profile, "soup-flat-v3");
assert_eq!(wire.partition, "document");
assert!(!wire.is_email_attachment);
+ assert!(wire.is_important);
+ assert!(wire.status_option_ids.is_empty());
}
#[test]
@@ -297,6 +304,8 @@ fn document_server_facts_attached_to_another_entity_are_rejected() {
}),
document_server_facts: Some(SoupDocumentServerFacts {
is_email_attachment: false,
+ is_important: true,
+ status_option_ids: Vec::new(),
}),
};
assert!(matches!(
@@ -334,7 +343,7 @@ fn complete_v2_validation_remains_separate_from_the_supplement() {
}
#[test]
-fn supplement_capsule_v1_native_golden_round_trip_is_deterministic() {
+fn supplement_capsule_v2_native_golden_round_trip_is_deterministic() {
let id = Uuid::from_u128(1);
let supplement = project_soup_cache_supplement(
document_key(id),
@@ -346,19 +355,89 @@ fn supplement_capsule_v1_native_golden_round_trip_is_deterministic() {
let encoded = encode_cache_projection_supplement(&supplement).unwrap();
assert_eq!(
encoded,
- "AQxzb3VwLWZsYXQtdjI4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAwMDEIZG9jdW1lbnQA"
+ "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAwMDEIZG9jdW1lbnQAAQA"
);
assert_eq!(
decode_cache_projection_supplement(&encoded).unwrap(),
supplement
);
+
+ let status_supplement = SoupCacheProjectionSupplement::document(
+ document_key(id),
+ true,
+ false,
+ vec![Uuid::from_u128(11), Uuid::from_u128(12)],
+ );
+ let encoded = encode_cache_projection_supplement(&status_supplement).unwrap();
+ assert_eq!(
+ encoded,
+ "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAwMDEIZG9jdW1lbnQBAAIQAAAAAAAAAAAAAAAAAAAACxAAAAAAAAAAAAAAAAAAAAAM"
+ );
+ assert_eq!(
+ decode_cache_projection_supplement(&encoded).unwrap(),
+ status_supplement
+ );
+}
+
+#[test]
+fn complete_v3_projection_contains_viewer_importance_and_status_facts() {
+ let id = Uuid::from_u128(1);
+ let status_a = Uuid::from_u128(11);
+ let status_b = Uuid::from_u128(12);
+ let document = document(id, None);
+ let supplement = SoupCacheProjectionSupplement::document(
+ document_key(id),
+ false,
+ false,
+ vec![status_b, status_a, status_b],
+ );
+ assert_eq!(
+ supplement.status_option_ids(),
+ Some([status_a, status_b].as_slice())
+ );
+
+ let projection = compose_soup_flat_v3(
+ DirectProjectionInput {
+ record_key: document_key(id),
+ kind: SoupFlatEntityKind::Document,
+ id: document.id,
+ owner: document.owner_id.to_string(),
+ project_id: document.project_id,
+ file_type: document.file_type,
+ created_at: document.created_at,
+ updated_at: document.updated_at,
+ },
+ Some(DocumentSubType::Task),
+ Some(&supplement),
+ )
+ .unwrap();
+ validate_soup_flat_v3(&projection).unwrap();
+ assert!(projection.exact_facts.iter().any(|fact| {
+ fact.attribute == vocabulary::importance() && fact.value == ExactValue::new([0]).unwrap()
+ }));
+ let statuses = projection
+ .exact_facts
+ .iter()
+ .filter(|fact| fact.attribute == vocabulary::task_status_option())
+ .map(|fact| fact.value.as_bytes())
+ .collect::<Vec<_>>();
+ assert_eq!(statuses, vec![status_a.as_bytes(), status_b.as_bytes()]);
+
+ let mut missing_importance = projection;
+ missing_importance
+ .exact_facts
+ .retain(|fact| fact.attribute != vocabulary::importance());
+ assert!(matches!(
+ validate_soup_flat_v3(&missing_importance),
+ Err(ProfileValidationError::MissingRequired("importance"))
+ ));
}
#[test]
fn supplement_decoder_rejects_unknown_oversized_and_trailing_frames() {
assert!(matches!(
- decode_cache_projection_supplement(&STANDARD_NO_PAD.encode([0x02])),
- Err(SoupCacheProjectionWireError::UnsupportedWireVersion(0x02))
+ decode_cache_projection_supplement(&STANDARD_NO_PAD.encode([0x03])),
+ Err(SoupCacheProjectionWireError::UnsupportedWireVersion(0x03))
));
assert!(matches!(
decode_cache_projection_supplement(
@@ -368,7 +447,7 @@ fn supplement_decoder_rejects_unknown_oversized_and_trailing_frames() {
));
let supplement =
- SoupCacheProjectionSupplement::document(document_key(Uuid::from_u128(1)), false);
+ SoupCacheProjectionSupplement::document_v2(document_key(Uuid::from_u128(1)), false);
let encoded = encode_cache_projection_supplement(&supplement).unwrap();
let mut framed = STANDARD_NO_PAD.decode(encoded).unwrap();
framed.push(0);
@@ -381,28 +460,28 @@ fn supplement_decoder_rejects_unknown_oversized_and_trailing_frames() {
#[test]
fn supplement_decoder_rejects_invalid_profile_partition_and_record_binding() {
let supplement =
- SoupCacheProjectionSupplement::document(document_key(Uuid::from_u128(1)), false);
+ SoupCacheProjectionSupplement::document_v2(document_key(Uuid::from_u128(1)), false);
let encode_unchecked = |capsule: &SoupCacheProjectionCapsuleV1| {
- let mut framed = vec![SOUP_CACHE_PROJECTION_WIRE_VERSION];
+ let mut framed = vec![SOUP_CACHE_PROJECTION_WIRE_VERSION_V1];
framed.extend(postcard::to_stdvec(capsule).unwrap());
STANDARD_NO_PAD.encode(framed)
};
- let mut unknown_profile = SoupCacheProjectionCapsuleV1::from(&supplement);
+ let mut unknown_profile = SoupCacheProjectionCapsuleV1::try_from(&supplement).unwrap();
unknown_profile.target_profile = "soup-flat-v999".to_owned();
assert!(matches!(
decode_cache_projection_supplement(&encode_unchecked(&unknown_profile)),
Err(SoupCacheProjectionWireError::UnsupportedTargetProfile(_))
));
- let mut wrong_partition = SoupCacheProjectionCapsuleV1::from(&supplement);
+ let mut wrong_partition = SoupCacheProjectionCapsuleV1::try_from(&supplement).unwrap();
wrong_partition.partition = "project".to_owned();
assert!(matches!(
decode_cache_projection_supplement(&encode_unchecked(&wrong_partition)),
Err(SoupCacheProjectionWireError::UnsupportedPartition(_))
));
- let mut wrong_record = SoupCacheProjectionCapsuleV1::from(&supplement);
+ let mut wrong_record = SoupCacheProjectionCapsuleV1::try_from(&supplement).unwrap();
wrong_record.record_key = "GraphqlSoupProject:00000000-0000-0000-0000-000000000001".to_owned();
assert!(matches!(
decode_cache_projection_supplement(&encode_unchecked(&wrong_record)),
diff --git a/crates/soup_filter_projection/src/wire.rs b/crates/soup_filter_projection/src/wire.rs
index 42adc65592..217ca4220e 100644
--- a/crates/soup_filter_projection/src/wire.rs
+++ b/crates/soup_filter_projection/src/wire.rs
@@ -3,9 +3,14 @@ use item_filter_index::vocabulary;
use predicate_index::{Profile, RecordKey, Token, ValidationError};
use serde::{Deserialize, Serialize};
use thiserror::Error;
+use uuid::Uuid;
/// Framing byte for the first immutable Soup server-fact supplement layout.
-pub const SOUP_CACHE_PROJECTION_WIRE_VERSION: u8 = 0x01;
+pub const SOUP_CACHE_PROJECTION_WIRE_VERSION_V1: u8 = 0x01;
+/// Framing byte for the viewer-relative Soup server-fact supplement layout.
+pub const SOUP_CACHE_PROJECTION_WIRE_VERSION_V2: u8 = 0x02;
+/// Framing byte emitted by this version of the server.
+pub const SOUP_CACHE_PROJECTION_WIRE_VERSION: u8 = SOUP_CACHE_PROJECTION_WIRE_VERSION_V2;
/// Maximum decoded bytes accepted for one entity supplement, including framing.
pub const MAX_SOUP_CACHE_PROJECTION_BYTES: usize = 1_024;
/// Maximum RFC 4648 unpadded base64 bytes accepted before decoding.
@@ -24,16 +29,39 @@ pub struct SoupCacheProjectionSupplement {
target_profile: Profile,
partition: Token,
is_email_attachment: bool,
+ is_important: Option<bool>,
+ status_option_ids: Option<Vec<Uuid>>,
}
impl SoupCacheProjectionSupplement {
- /// Construct the supplement for authoritative document relation state.
- pub fn document(record_key: RecordKey, is_email_attachment: bool) -> Self {
+ /// Construct a v2 supplement containing authoritative attachment state.
+ pub fn document_v2(record_key: RecordKey, is_email_attachment: bool) -> Self {
Self {
record_key,
target_profile: vocabulary::profile_v2(),
partition: vocabulary::document_partition(),
is_email_attachment,
+ is_important: None,
+ status_option_ids: None,
+ }
+ }
+
+ /// Construct the current v3 supplement for authoritative document state.
+ pub fn document(
+ record_key: RecordKey,
+ is_email_attachment: bool,
+ is_important: bool,
+ mut status_option_ids: Vec<Uuid>,
+ ) -> Self {
+ status_option_ids.sort_unstable();
+ status_option_ids.dedup();
+ Self {
+ record_key,
+ target_profile: vocabulary::profile_v3(),
+ partition: vocabulary::document_partition(),
+ is_email_attachment,
+ is_important: Some(is_important),
+ status_option_ids: Some(status_option_ids),
}
}
@@ -56,9 +84,19 @@ impl SoupCacheProjectionSupplement {
pub fn is_email_attachment(&self) -> bool {
self.is_email_attachment
}
+
+ /// Read viewer-relative importance when supplied by this wire version.
+ pub fn is_important(&self) -> Option<bool> {
+ self.is_important
+ }
+
+ /// Read the complete task Status option set when supplied by this wire version.
+ pub fn status_option_ids(&self) -> Option<&[Uuid]> {
+ self.status_option_ids.as_deref()
+ }
}
-/// Immutable postcard payload for one server-fact supplement.
+/// Immutable postcard payload for one v2-profile server-fact supplement.
///
/// Field order is wire-significant and locked by cross-adapter golden fixtures.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
@@ -73,6 +111,25 @@ pub struct SoupCacheProjectionCapsuleV1 {
pub is_email_attachment: bool,
}
+/// Immutable postcard payload for one v3-profile server-fact supplement.
+///
+/// Field order is wire-significant and locked by cross-adapter golden fixtures.
+#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
+pub struct SoupCacheProjectionCapsuleV2 {
+ /// Complete projection profile to which these server facts may be applied.
+ pub target_profile: String,
+ /// Defensive normalized-record binding.
+ pub record_key: String,
+ /// Defensive entity-partition binding.
+ pub partition: String,
+ /// Explicit authoritative `document_email` membership state.
+ pub is_email_attachment: bool,
+ /// Viewer-relative importance state.
+ pub is_important: bool,
+ /// Complete canonical task Status select-option UUID set.
+ pub status_option_ids: Vec<Uuid>,
+}
+
/// Failure to encode or decode a bounded Soup server-fact supplement.
#[derive(Debug, Error)]
pub enum SoupCacheProjectionWireError {
@@ -94,39 +151,52 @@ pub enum SoupCacheProjectionWireError {
/// The postcard payload is malformed.
#[error("invalid Soup cache-projection postcard payload")]
InvalidPostcard(#[source] postcard::Error),
- /// Bytes remain after decoding the immutable v1 postcard value.
+ /// Bytes remain after decoding the immutable postcard value.
#[error("Soup cache-projection supplement contains trailing bytes")]
TrailingBytes,
/// A storage-neutral token or key bound is invalid.
#[error(transparent)]
GenericValidation(#[from] ValidationError),
- /// The supplement targets a projection profile not understood by this wire contract.
+ /// The supplement targets a projection profile not understood by its wire contract.
#[error("unsupported Soup cache-projection target profile `{0}`")]
UnsupportedTargetProfile(String),
- /// The supplement declares a partition that has no server-only v1 facts.
+ /// The supplement declares a partition that has no server-only facts.
#[error("unsupported Soup cache-projection supplement partition `{0}`")]
UnsupportedPartition(String),
/// The defensive record key does not identify a document in the declared partition.
#[error("Soup cache-projection record key does not match its document partition")]
RecordKeyPartitionMismatch,
+ /// The status set is oversized or not in canonical sorted, deduplicated order.
+ #[error("Soup cache-projection Status option IDs are not canonical")]
+ NonCanonicalStatusOptionIds,
}
/// Encode one canonical document server-fact supplement as standard unpadded
-/// base64 over a version byte and postcard capsule-v1 payload.
+/// base64 over a version byte and the matching immutable postcard payload.
pub fn encode_cache_projection_supplement(
supplement: &SoupCacheProjectionSupplement,
) -> Result<String, SoupCacheProjectionWireError> {
validate_supplement(supplement)?;
- let capsule = SoupCacheProjectionCapsuleV1::from(supplement);
- let payload =
- postcard::to_stdvec(&capsule).map_err(SoupCacheProjectionWireError::InvalidPostcard)?;
+ let (version, payload) = if supplement.target_profile == vocabulary::profile_v2() {
+ let capsule = SoupCacheProjectionCapsuleV1::try_from(supplement)?;
+ (
+ SOUP_CACHE_PROJECTION_WIRE_VERSION_V1,
+ postcard::to_stdvec(&capsule).map_err(SoupCacheProjectionWireError::InvalidPostcard)?,
+ )
+ } else {
+ let capsule = SoupCacheProjectionCapsuleV2::try_from(supplement)?;
+ (
+ SOUP_CACHE_PROJECTION_WIRE_VERSION_V2,
+ postcard::to_stdvec(&capsule).map_err(SoupCacheProjectionWireError::InvalidPostcard)?,
+ )
+ };
let decoded_len = payload.len().saturating_add(1);
if decoded_len > MAX_SOUP_CACHE_PROJECTION_BYTES {
return Err(SoupCacheProjectionWireError::DecodedTooLarge);
}
let mut framed = Vec::with_capacity(decoded_len);
- framed.push(SOUP_CACHE_PROJECTION_WIRE_VERSION);
+ framed.push(version);
framed.extend(payload);
Ok(STANDARD_NO_PAD.encode(framed))
}
@@ -147,28 +217,75 @@ pub fn decode_cache_projection_supplement(
let (&version, payload) = framed
.split_first()
.ok_or(SoupCacheProjectionWireError::Empty)?;
- if version != SOUP_CACHE_PROJECTION_WIRE_VERSION {
- return Err(SoupCacheProjectionWireError::UnsupportedWireVersion(
+
+ match version {
+ SOUP_CACHE_PROJECTION_WIRE_VERSION_V1 => {
+ decode_postcard::<SoupCacheProjectionCapsuleV1>(payload)?.try_into()
+ }
+ SOUP_CACHE_PROJECTION_WIRE_VERSION_V2 => {
+ decode_postcard::<SoupCacheProjectionCapsuleV2>(payload)?.try_into()
+ }
+ version => Err(SoupCacheProjectionWireError::UnsupportedWireVersion(
version,
- ));
+ )),
}
+}
- let (capsule, trailing) = postcard::take_from_bytes::<SoupCacheProjectionCapsuleV1>(payload)
+fn decode_postcard<T>(payload: &[u8]) -> Result<T, SoupCacheProjectionWireError>
+where
+ T: for<'de> Deserialize<'de>,
+{
+ let (capsule, trailing) = postcard::take_from_bytes::<T>(payload)
.map_err(SoupCacheProjectionWireError::InvalidPostcard)?;
if !trailing.is_empty() {
return Err(SoupCacheProjectionWireError::TrailingBytes);
}
- SoupCacheProjectionSupplement::try_from(capsule)
+ Ok(capsule)
}
-impl From<&SoupCacheProjectionSupplement> for SoupCacheProjectionCapsuleV1 {
- fn from(supplement: &SoupCacheProjectionSupplement) -> Self {
- Self {
+impl TryFrom<&SoupCacheProjectionSupplement> for SoupCacheProjectionCapsuleV1 {
+ type Error = SoupCacheProjectionWireError;
+
+ fn try_from(supplement: &SoupCacheProjectionSupplement) -> Result<Self, Self::Error> {
+ if supplement.target_profile != vocabulary::profile_v2() {
+ return Err(SoupCacheProjectionWireError::UnsupportedTargetProfile(
+ supplement.target_profile.token().as_str().to_owned(),
+ ));
+ }
+ Ok(Self {
target_profile: supplement.target_profile.token().as_str().to_owned(),
record_key: supplement.record_key.as_str().to_owned(),
partition: supplement.partition.as_str().to_owned(),
is_email_attachment: supplement.is_email_attachment,
+ })
+ }
+}
+
+impl TryFrom<&SoupCacheProjectionSupplement> for SoupCacheProjectionCapsuleV2 {
+ type Error = SoupCacheProjectionWireError;
+
+ fn try_from(supplement: &SoupCacheProjectionSupplement) -> Result<Self, Self::Error> {
+ if supplement.target_profile != vocabulary::profile_v3() {
+ return Err(SoupCacheProjectionWireError::UnsupportedTargetProfile(
+ supplement.target_profile.token().as_str().to_owned(),
+ ));
}
+ Ok(Self {
+ target_profile: supplement.target_profile.token().as_str().to_owned(),
+ record_key: supplement.record_key.as_str().to_owned(),
+ partition: supplement.partition.as_str().to_owned(),
+ is_email_attachment: supplement.is_email_attachment,
+ is_important: supplement.is_important.ok_or(
+ SoupCacheProjectionWireError::UnsupportedTargetProfile(
+ supplement.target_profile.token().as_str().to_owned(),
+ ),
+ )?,
+ status_option_ids: supplement.status_option_ids.clone().ok_or(
+ SoupCacheProjectionWireError::UnsupportedTargetProfile(
+ supplement.target_profile.token().as_str().to_owned(),
+ ),
+ )?,
+ })
}
}
@@ -181,6 +298,25 @@ impl TryFrom<SoupCacheProjectionCapsuleV1> for SoupCacheProjectionSupplement {
target_profile: Profile::new(Token::new(capsule.target_profile)?),
partition: Token::new(capsule.partition)?,
is_email_attachment: capsule.is_email_attachment,
+ is_important: None,
+ status_option_ids: None,
+ };
+ validate_supplement(&supplement)?;
+ Ok(supplement)
+ }
+}
+
+impl TryFrom<SoupCacheProjectionCapsuleV2> for SoupCacheProjectionSupplement {
+ type Error = SoupCacheProjectionWireError;
+
+ fn try_from(capsule: SoupCacheProjectionCapsuleV2) -> Result<Self, Self::Error> {
+ let supplement = Self {
+ record_key: RecordKey::new(capsule.record_key)?,
+ target_profile: Profile::new(Token::new(capsule.target_profile)?),
+ partition: Token::new(capsule.partition)?,
+ is_email_attachment: capsule.is_email_attachment,
+ is_important: Some(capsule.is_important),
+ status_option_ids: Some(capsule.status_option_ids),
};
validate_supplement(&supplement)?;
Ok(supplement)
@@ -190,7 +326,25 @@ impl TryFrom<SoupCacheProjectionCapsuleV1> for SoupCacheProjectionSupplement {
fn validate_supplement(
supplement: &SoupCacheProjectionSupplement,
) -> Result<(), SoupCacheProjectionWireError> {
- if supplement.target_profile != vocabulary::profile_v2() {
+ if supplement.target_profile == vocabulary::profile_v2() {
+ if supplement.is_important.is_some() || supplement.status_option_ids.is_some() {
+ return Err(SoupCacheProjectionWireError::UnsupportedTargetProfile(
+ supplement.target_profile.token().as_str().to_owned(),
+ ));
+ }
+ } else if supplement.target_profile == vocabulary::profile_v3() {
+ let Some(status_option_ids) = supplement.status_option_ids.as_deref() else {
+ return Err(SoupCacheProjectionWireError::UnsupportedTargetProfile(
+ supplement.target_profile.token().as_str().to_owned(),
+ ));
+ };
+ if supplement.is_important.is_none()
+ || status_option_ids.len() > crate::MAX_TASK_STATUS_OPTION_IDS
+ || !status_option_ids.windows(2).all(|ids| ids[0] < ids[1])
+ {
+ return Err(SoupCacheProjectionWireError::NonCanonicalStatusOptionIds);
+ }
+ } else {
return Err(SoupCacheProjectionWireError::UnsupportedTargetProfile(
supplement.target_profile.token().as_str().to_owned(),
));
diff --git a/crates/soup_filter_projection/testdata/soup-flat-v3-capsules.json b/crates/soup_filter_projection/testdata/soup-flat-v3-capsules.json
new file mode 100644
index 0000000000..6d8573deec
--- /dev/null
+++ b/crates/soup_filter_projection/testdata/soup-flat-v3-capsules.json
@@ -0,0 +1,38 @@
+{
+ "fixture_format": "server-fact-supplement-capsule-v2",
+ "transport": {
+ "base64_variant": "RFC4648_STANDARD_NO_PAD",
+ "frame": "wire-version-byte-plus-postcard",
+ "wire_version": 2,
+ "max_decoded_bytes": 1024
+ },
+ "capsules": [
+ {
+ "name": "document-not-attachment-important-no-status",
+ "capsule": {
+ "target_profile": "soup-flat-v3",
+ "record_key": "GraphqlSoupDocument:00000000-0000-0000-0000-000000000001",
+ "partition": "document",
+ "is_email_attachment": false,
+ "is_important": true,
+ "status_option_ids": []
+ },
+ "expected_base64": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAwMDEIZG9jdW1lbnQAAQA"
+ },
+ {
+ "name": "document-attachment-unimportant-with-statuses",
+ "capsule": {
+ "target_profile": "soup-flat-v3",
+ "record_key": "GraphqlSoupDocument:00000000-0000-0000-0000-000000000001",
+ "partition": "document",
+ "is_email_attachment": true,
+ "is_important": false,
+ "status_option_ids": [
+ "00000000-0000-0000-0000-00000000000b",
+ "00000000-0000-0000-0000-00000000000c"
+ ]
+ },
+ "expected_base64": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAwMDEIZG9jdW1lbnQBAAIQAAAAAAAAAAAAAAAAAAAACxAAAAAAAAAAAAAAAAAAAAAM"
+ }
+ ]
+}