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.

feat(soup): improve model typing (#268)

Sean Ayeb4609acb3b66
diff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lock
index 86ecc79864..1680d51156 100644
--- a/rust/cloud-storage/Cargo.lock
+++ b/rust/cloud-storage/Cargo.lock
@@ -5455,11 +5455,13 @@ version = "0.1.0"
dependencies = [
"anyhow",
"chrono",
+ "macro_user_id",
"model-entity",
"models_pagination",
"serde",
"strum",
"utoipa",
+ "uuid",
]
[[package]]
diff --git a/rust/cloud-storage/document_storage_service/Cargo.toml b/rust/cloud-storage/document_storage_service/Cargo.toml
index 8d4a9c43c7..e263400c2e 100644
--- a/rust/cloud-storage/document_storage_service/Cargo.toml
+++ b/rust/cloud-storage/document_storage_service/Cargo.toml
@@ -74,7 +74,7 @@ model_notifications = { path = "../model_notifications" }
models_bulk_upload = { path = "../models_bulk_upload" }
models_pagination = { path = "../models_pagination", features = ["axum"] }
models_permissions = { path = "../models_permissions" }
-models_soup = { path = "../models_soup" }
+models_soup = { path = "../models_soup", features = ["schema"] }
rayon = "1.10.0"
redis = { workspace = true, features = [
"aio",
diff --git a/rust/cloud-storage/macro_db_client/fixtures/mixed_items_expanded.sql b/rust/cloud-storage/macro_db_client/fixtures/mixed_items_expanded.sql
index cb692a3f7f..6c6c346ee6 100644
--- a/rust/cloud-storage/macro_db_client/fixtures/mixed_items_expanded.sql
+++ b/rust/cloud-storage/macro_db_client/fixtures/mixed_items_expanded.sql
@@ -22,24 +22,24 @@ ON CONFLICT DO NOTHING;
-- SCENARIO: Top-level project A. User will get 'view' access to this.
INSERT INTO public."Project" ("id", "name", "userId", "parentId", "createdAt", "updatedAt")
-VALUES ('project-A', 'Project A (User has VIEW)', 'macro|[email protected]', NULL, '2023-01-01 10:00:00', '2023-01-01 10:00:00');
+VALUES ('aaaaaaaa-ffff-ffff-ffff-ffffffffffff', 'Project A (User has VIEW)', 'macro|[email protected]', NULL, '2023-01-01 10:00:00', '2023-01-01 10:00:00');
-- SCENARIO: Nested project B, inside A.
INSERT INTO public."Project" ("id", "name", "userId", "parentId", "createdAt", "updatedAt")
-VALUES ('project-B', 'Project B (Child of A)', 'macro|[email protected]', 'project-A', '2023-01-01 11:00:00', '2023-01-01 11:00:00');
+VALUES ('bbbbbbbb-ffff-ffff-ffff-ffffffffffff', 'Project B (Child of A)', 'macro|[email protected]', 'aaaaaaaa-ffff-ffff-ffff-ffffffffffff', '2023-01-01 11:00:00', '2023-01-01 11:00:00');
-- SCENARIO: Deeply nested project C, inside B.
INSERT INTO public."Project" ("id", "name", "userId", "parentId", "createdAt", "updatedAt")
-VALUES ('project-C', 'Project C (Child of B)', 'macro|[email protected]', 'project-B', '2023-01-01 12:00:00', '2023-01-01 12:00:00');
+VALUES ('cccccccc-ffff-ffff-ffff-ffffffffffff', 'Project C (Child of B)', 'macro|[email protected]', 'bbbbbbbb-ffff-ffff-ffff-ffffffffffff', '2023-01-01 12:00:00', '2023-01-01 12:00:00');
-- SCENARIO: Another top-level project D. User will get 'owner' access to this project
-- but only 'comment' access to the document inside, to test which permission wins.
INSERT INTO public."Project" ("id", "name", "userId", "parentId", "createdAt", "updatedAt")
-VALUES ('project-D', 'Project D (User has OWNER)', 'macro|[email protected]', NULL, '2023-01-02 10:00:00', '2023-01-02 10:00:00');
+VALUES ('dddddddd-ffff-ffff-ffff-ffffffffffff', 'Project D (User has OWNER)', 'macro|[email protected]', NULL, '2023-01-02 10:00:00', '2023-01-02 10:00:00');
-- SCENARIO: An isolated project the user should NOT have access to.
INSERT INTO public."Project" ("id", "name", "userId", "parentId", "createdAt", "updatedAt")
-VALUES ('project-isolated', 'Isolated Project', 'macro|[email protected]', NULL, '2023-01-03 10:00:00', '2023-01-03 10:00:00');
+VALUES ('99999999-ffff-ffff-ffff-ffffffffffff', 'Isolated Project', 'macro|[email protected]', NULL, '2023-01-03 10:00:00', '2023-01-03 10:00:00');
---------------------------------------------------
@@ -48,41 +48,41 @@ VALUES ('project-isolated', 'Isolated Project', 'macro|[email protected]', NULL, '
-- Document Families (one for each document)
INSERT INTO public."DocumentFamily" ("id", "rootDocumentId")
-VALUES (1, 'doc-in-A'),
- (2, 'doc-in-B'),
- (3, 'doc-in-C'),
- (4, 'doc-in-D'),
- (5, 'doc-standalone'),
- (6, 'doc-isolated');
+VALUES (1, '11111111-aaaa-aaaa-aaaa-aaaaaaaaaaaa'),
+ (2, '11111111-bbbb-bbbb-bbbb-bbbbbbbbbbbb'),
+ (3, '11111111-cccc-cccc-cccc-cccccccccccc'),
+ (4, '11111111-dddd-dddd-dddd-dddddddddddd'),
+ (5, '11111111-0000-0000-0000-000000000000'),
+ (6, '11111111-9999-9999-9999-999999999999');
-- Documents
INSERT INTO public."Document" ("id", "name", "owner", "projectId", "documentFamilyId", "fileType", "createdAt",
"updatedAt")
-VALUES ('doc-in-A', 'Document in A', 'macro|[email protected]', 'project-A', 1, 'pdf', '2023-01-05 10:00:00', '2023-01-05 10:00:00'),
- ('doc-in-B', 'Document in B', 'macro|[email protected]', 'project-B', 2, 'pdf', '2023-01-05 11:00:00', '2023-01-05 11:00:00'),
- ('doc-in-C', 'Document in C', 'macro|[email protected]', 'project-C', 3, 'pdf', '2023-01-05 12:00:00', '2023-01-05 12:00:00'),
- ('doc-in-D', 'Document in D', 'macro|[email protected]', 'project-D', 4, 'pdf', '2023-01-05 13:00:00', '2023-01-05 13:00:00'),
- ('doc-standalone', 'Standalone Document', 'macro|[email protected]', NULL, 5, 'pdf', '2023-01-05 14:00:00',
+VALUES ('11111111-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'Document in A', 'macro|[email protected]', 'aaaaaaaa-ffff-ffff-ffff-ffffffffffff', 1, 'pdf', '2023-01-05 10:00:00', '2023-01-05 10:00:00'),
+ ('11111111-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'Document in B', 'macro|[email protected]', 'bbbbbbbb-ffff-ffff-ffff-ffffffffffff', 2, 'pdf', '2023-01-05 11:00:00', '2023-01-05 11:00:00'),
+ ('11111111-cccc-cccc-cccc-cccccccccccc', 'Document in C', 'macro|[email protected]', 'cccccccc-ffff-ffff-ffff-ffffffffffff', 3, 'pdf', '2023-01-05 12:00:00', '2023-01-05 12:00:00'),
+ ('11111111-dddd-dddd-dddd-dddddddddddd', 'Document in D', 'macro|[email protected]', 'dddddddd-ffff-ffff-ffff-ffffffffffff', 4, 'pdf', '2023-01-05 13:00:00', '2023-01-05 13:00:00'),
+ ('11111111-0000-0000-0000-000000000000', 'Standalone Document', 'macro|[email protected]', NULL, 5, 'pdf', '2023-01-05 14:00:00',
'2023-01-05 14:00:00'),
- ('doc-isolated', 'Isolated Document', 'macro|[email protected]', 'project-isolated', 6, 'pdf', '2023-01-05 15:00:00',
+ ('11111111-9999-9999-9999-999999999999', 'Isolated Document', 'macro|[email protected]', '99999999-ffff-ffff-ffff-ffffffffffff', 6, 'pdf', '2023-01-05 15:00:00',
'2023-01-05 15:00:00');
-- Document Instances (one for each document)
INSERT INTO public."DocumentInstance" ("id", "documentId", "sha", "createdAt", "updatedAt")
-VALUES (1, 'doc-in-A', 'sha_A', '2023-01-05 10:00:00', '2023-01-05 10:00:00'),
- (2, 'doc-in-B', 'sha_B', '2023-01-05 11:00:00', '2023-01-05 11:00:00'),
- (3, 'doc-in-C', 'sha_C', '2023-01-05 12:00:00', '2023-01-05 12:00:00'),
- (4, 'doc-in-D', 'sha_D', '2023-01-05 13:00:00', '2023-01-05 13:00:00'),
- (5, 'doc-standalone', 'sha_standalone', '2023-01-05 14:00:00', '2023-01-05 14:00:00'),
- (6, 'doc-isolated', 'sha_isolated', '2023-01-05 15:00:00', '2023-01-05 15:00:00');
+VALUES (1, '11111111-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'sha_A', '2023-01-05 10:00:00', '2023-01-05 10:00:00'),
+ (2, '11111111-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'sha_B', '2023-01-05 11:00:00', '2023-01-05 11:00:00'),
+ (3, '11111111-cccc-cccc-cccc-cccccccccccc', 'sha_C', '2023-01-05 12:00:00', '2023-01-05 12:00:00'),
+ (4, '11111111-dddd-dddd-dddd-dddddddddddd', 'sha_D', '2023-01-05 13:00:00', '2023-01-05 13:00:00'),
+ (5, '11111111-0000-0000-0000-000000000000', 'sha_standalone', '2023-01-05 14:00:00', '2023-01-05 14:00:00'),
+ (6, '11111111-9999-9999-9999-999999999999', 'sha_isolated', '2023-01-05 15:00:00', '2023-01-05 15:00:00');
-- Chats
INSERT INTO public."Chat" ("id", "name", "userId", "projectId", "createdAt", "updatedAt")
-VALUES ('chat-in-A', 'Chat in A', 'macro|[email protected]', 'project-A', '2023-01-06 10:00:00', '2023-01-06 10:00:00'),
- ('chat-in-B', 'Chat in B', 'macro|[email protected]', 'project-B', '2023-01-06 11:00:00', '2023-01-06 11:00:00'),
- ('chat-in-C', 'Chat in C', 'macro|[email protected]', 'project-C', '2023-01-06 12:00:00', '2023-01-06 12:00:00'),
- ('chat-standalone', 'Standalone Chat', 'macro|[email protected]', NULL, '2023-01-06 13:00:00', '2023-01-06 13:00:00'),
- ('chat-isolated', 'Isolated Chat', 'macro|[email protected]', 'project-isolated', '2023-01-06 14:00:00', '2023-01-06 14:00:00');
+VALUES ('22222222-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'Chat in A', 'macro|[email protected]', 'aaaaaaaa-ffff-ffff-ffff-ffffffffffff', '2023-01-06 10:00:00', '2023-01-06 10:00:00'),
+ ('22222222-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'Chat in B', 'macro|[email protected]', 'bbbbbbbb-ffff-ffff-ffff-ffffffffffff', '2023-01-06 11:00:00', '2023-01-06 11:00:00'),
+ ('22222222-cccc-cccc-cccc-cccccccccccc', 'Chat in C', 'macro|[email protected]', 'cccccccc-ffff-ffff-ffff-ffffffffffff', '2023-01-06 12:00:00', '2023-01-06 12:00:00'),
+ ('22222222-0000-0000-0000-000000000000', 'Standalone Chat', 'macro|[email protected]', NULL, '2023-01-06 13:00:00', '2023-01-06 13:00:00'),
+ ('22222222-9999-9999-9999-999999999999', 'Isolated Chat', 'macro|[email protected]', '99999999-ffff-ffff-ffff-ffffffffffff', '2023-01-06 14:00:00', '2023-01-06 14:00:00');
---------------------------------------------------
-- USER ACCESS PERMISSIONS (UserItemAccess)
@@ -91,20 +91,20 @@ VALUES ('chat-in-A', 'Chat in A', 'macro|[email protected]', 'project-A', '2023-01
INSERT INTO public."UserItemAccess" ("id", "user_id", "item_id", "item_type", "access_level")
VALUES
-- SCENARIO: User gets 'view' on project-A. Access to items in A, B, and C should be inherited from this.
-(gen_random_uuid(), 'macro|[email protected]', 'project-A', 'project', 'view'),
+(gen_random_uuid(), 'macro|[email protected]', 'aaaaaaaa-ffff-ffff-ffff-ffffffffffff', 'project', 'view'),
-- SCENARIO: Direct 'edit' on doc-in-B should override inherited 'view' from project-A.
-- We add a 'view' record too, to ensure DISTINCT ON correctly picks the higher 'edit' level.
-(gen_random_uuid(), 'macro|[email protected]', 'doc-in-B', 'document', 'view'),
-(gen_random_uuid(), 'macro|[email protected]', 'doc-in-B', 'document', 'edit'),
+(gen_random_uuid(), 'macro|[email protected]', '11111111-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'document', 'view'),
+(gen_random_uuid(), 'macro|[email protected]', '11111111-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'document', 'edit'),
-- SCENARIO: Inherited 'owner' from project-D should override direct 'comment' on doc-in-D.
-(gen_random_uuid(), 'macro|[email protected]', 'project-D', 'project', 'owner'),
-(gen_random_uuid(), 'macro|[email protected]', 'doc-in-D', 'document', 'comment'),
+(gen_random_uuid(), 'macro|[email protected]', 'dddddddd-ffff-ffff-ffff-ffffffffffff', 'project', 'owner'),
+(gen_random_uuid(), 'macro|[email protected]', '11111111-dddd-dddd-dddd-dddddddddddd', 'document', 'comment'),
-- SCENARIO: Direct access to items not in any project.
-(gen_random_uuid(), 'macro|[email protected]', 'doc-standalone', 'document', 'owner'),
-(gen_random_uuid(), 'macro|[email protected]', 'chat-standalone', 'chat', 'owner');
+(gen_random_uuid(), 'macro|[email protected]', '11111111-0000-0000-0000-000000000000', 'document', 'owner'),
+(gen_random_uuid(), 'macro|[email protected]', '22222222-0000-0000-0000-000000000000', 'chat', 'owner');
-- NOTE: There are no access records for project-B, project-C, doc-in-A, chat-in-A, etc.
-- Their visibility depends entirely on the inherited permission from project-A.
@@ -113,14 +113,14 @@ VALUES
-- These items should NOT be returned by the query for 'macro|[email protected]'.
INSERT INTO public."UserHistory" ("userId", "itemId", "itemType", "createdAt", "updatedAt")
-VALUES ('macro|[email protected]', 'doc-in-B', 'document', '2024-01-01 00:00:00', '2024-01-10 10:00:00'), -- Most recent
- ('macro|[email protected]', 'chat-standalone', 'chat', '2024-01-01 00:00:00', '2024-01-09 10:00:00'),
- ('macro|[email protected]', 'doc-in-A', 'document', '2024-01-01 00:00:00', '2024-01-08 10:00:00'),
- ('macro|[email protected]', 'chat-in-A', 'chat', '2024-01-01 00:00:00', '2024-01-07 10:00:00'),
- ('macro|[email protected]', 'doc-standalone', 'document', '2024-01-01 00:00:00', '2024-01-06 14:00:00'),
- ('macro|[email protected]', 'doc-in-D', 'document', '2024-01-01 00:00:00',
+VALUES ('macro|[email protected]', '11111111-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'document', '2024-01-01 00:00:00', '2024-01-10 10:00:00'), -- Most recent
+ ('macro|[email protected]', '22222222-0000-0000-0000-000000000000', 'chat', '2024-01-01 00:00:00', '2024-01-09 10:00:00'),
+ ('macro|[email protected]', '11111111-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'document', '2024-01-01 00:00:00', '2024-01-08 10:00:00'),
+ ('macro|[email protected]', '22222222-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'chat', '2024-01-01 00:00:00', '2024-01-07 10:00:00'),
+ ('macro|[email protected]', '11111111-0000-0000-0000-000000000000', 'document', '2024-01-01 00:00:00', '2024-01-06 14:00:00'),
+ ('macro|[email protected]', '11111111-dddd-dddd-dddd-dddddddddddd', 'document', '2024-01-01 00:00:00',
'2023-01-05 13:30:00'), -- History time is newer than item time
- ('macro|[email protected]', 'chat-in-C', 'chat', '2024-01-01 00:00:00', '2023-01-04 10:00:00');
+ ('macro|[email protected]', '22222222-cccc-cccc-cccc-cccccccccccc', 'chat', '2024-01-01 00:00:00', '2023-01-04 10:00:00');
-- Re-enable foreign key constraints
SET session_replication_role = 'origin';
diff --git a/rust/cloud-storage/macro_db_client/fixtures/mixed_items_unexpanded.sql b/rust/cloud-storage/macro_db_client/fixtures/mixed_items_unexpanded.sql
index cf2199d32e..0df9904650 100644
--- a/rust/cloud-storage/macro_db_client/fixtures/mixed_items_unexpanded.sql
+++ b/rust/cloud-storage/macro_db_client/fixtures/mixed_items_unexpanded.sql
@@ -18,33 +18,33 @@ VALUES ('macro|[email protected]', '[email protected]', 'stripe_id', 1);
-- Item Creation with distinct timestamp orders
-- Project: Newest created, Oldest updated, Middle viewed
INSERT INTO public."Project" ("id", "name", "userId", "createdAt", "updatedAt")
-VALUES ('test-project', 'Project Alpha', 'macro|[email protected]', '2024-01-03 10:00:00', '2024-02-01 10:00:00');
+VALUES ('ffffffff-ffff-ffff-ffff-ffffffffffff', 'Project Alpha', 'macro|[email protected]', '2024-01-03 10:00:00', '2024-02-01 10:00:00');
-- Chat: Middle created, Newest updated, Oldest viewed
INSERT INTO public."Chat" ("id", "userId", "name", "isPersistent", "createdAt", "updatedAt")
-VALUES ('test-chat', 'macro|[email protected]', 'Chat Bravo', true, '2024-01-02 10:00:00', '2024-02-03 10:00:00');
+VALUES ('cccccccc-1111-1111-1111-111111111111', 'macro|[email protected]', 'Chat Bravo', true, '2024-01-02 10:00:00', '2024-02-03 10:00:00');
-- Document: Oldest created, Middle updated, Newest viewed
INSERT INTO public."Document" ("id", "name", "fileType", "owner", "createdAt", "updatedAt")
-VALUES ('test-document', 'Document Charlie', 'pdf', 'macro|[email protected]', '2024-01-01 10:00:00',
+VALUES ('dddddddd-dddd-dddd-dddd-dddddddddddd', 'Document Charlie', 'pdf', 'macro|[email protected]', '2024-01-01 10:00:00',
'2024-02-02 10:00:00');
-- Dependencies
INSERT INTO public."DocumentFamily" ("id", "rootDocumentId")
-VALUES (1, 'test-document');
+VALUES (1, 'dddddddd-dddd-dddd-dddd-dddddddddddd');
INSERT INTO public."DocumentInstance" ("id", "documentId", "sha")
-VALUES (1, 'test-document', 'sha-charlie');
+VALUES (1, 'dddddddd-dddd-dddd-dddd-dddddddddddd', 'sha-charlie');
-- User Access
INSERT INTO public."UserItemAccess" ("id", "user_id", "item_id", "item_type", "access_level")
-VALUES (gen_random_uuid(), 'macro|[email protected]', 'test-project', 'project', 'owner'),
- (gen_random_uuid(), 'macro|[email protected]', 'test-chat', 'chat', 'owner'),
- (gen_random_uuid(), 'macro|[email protected]', 'test-document', 'document', 'owner');
+VALUES (gen_random_uuid(), 'macro|[email protected]', 'ffffffff-ffff-ffff-ffff-ffffffffffff', 'project', 'owner'),
+ (gen_random_uuid(), 'macro|[email protected]', 'cccccccc-1111-1111-1111-111111111111', 'chat', 'owner'),
+ (gen_random_uuid(), 'macro|[email protected]', 'dddddddd-dddd-dddd-dddd-dddddddddddd', 'document', 'owner');
-- User History with its own distinct ordering
INSERT INTO public."UserHistory" ("userId", "itemId", "itemType", "updatedAt")
-VALUES ('macro|[email protected]', 'test-document', 'document', '2024-03-03 10:00:00'), -- Newest viewed
- ('macro|[email protected]', 'test-project', 'project', '2024-03-02 10:00:00'), -- Middle viewed
- ('macro|[email protected]', 'test-chat', 'chat', '2024-03-01 10:00:00'); -- Oldest viewed
+VALUES ('macro|[email protected]', 'dddddddd-dddd-dddd-dddd-dddddddddddd', 'document', '2024-03-03 10:00:00'), -- Newest viewed
+ ('macro|[email protected]', 'ffffffff-ffff-ffff-ffff-ffffffffffff', 'project', '2024-03-02 10:00:00'), -- Middle viewed
+ ('macro|[email protected]', 'cccccccc-1111-1111-1111-111111111111', 'chat', '2024-03-01 10:00:00'); -- Oldest viewed
SET session_replication_role = 'origin';
\ No newline at end of file
diff --git a/rust/cloud-storage/macro_db_client/fixtures/mixed_items_unexpanded_history.sql b/rust/cloud-storage/macro_db_client/fixtures/mixed_items_unexpanded_history.sql
index d43fd9f4e4..2260b44c2b 100644
--- a/rust/cloud-storage/macro_db_client/fixtures/mixed_items_unexpanded_history.sql
+++ b/rust/cloud-storage/macro_db_client/fixtures/mixed_items_unexpanded_history.sql
@@ -14,25 +14,25 @@ INSERT INTO public."User" ("id", "email", "stripeCustomerId", "organizationId")
VALUES ('macro|[email protected]', '[email protected]', 'stripe_id', 1)
ON CONFLICT DO NOTHING;
INSERT INTO public."Project" ("id", "name", "userId", "createdAt", "updatedAt")
-VALUES ('test-project', 'Test Project', 'macro|[email protected]', '2023-01-17 12:00:00', '2023-01-17 12:00:00');
+VALUES ('ffffffff-ffff-ffff-ffff-ffffffffffff', 'Test Project', 'macro|[email protected]', '2023-01-17 12:00:00', '2023-01-17 12:00:00');
INSERT INTO public."DocumentFamily" ("id", "rootDocumentId")
-VALUES (1, 'test-document');
+VALUES (1, 'dddddddd-dddd-dddd-dddd-dddddddddddd');
INSERT INTO public."Document" ("id", "name", "fileType", "owner", "createdAt", "updatedAt", "documentFamilyId",
"projectId")
-VALUES ('test-document', 'Test Document', 'pdf', 'macro|[email protected]', '2023-01-15 10:00:00', '2023-01-15 10:00:00', 1,
- 'test-project');
+VALUES ('dddddddd-dddd-dddd-dddd-dddddddddddd', 'Test Document', 'pdf', 'macro|[email protected]', '2023-01-15 10:00:00', '2023-01-15 10:00:00', 1,
+ 'ffffffff-ffff-ffff-ffff-ffffffffffff');
INSERT INTO public."DocumentInstance" ("id", "revisionName", "documentId", "createdAt", "updatedAt", "sha")
-VALUES (1, 'Test Document', 'test-document', '2023-01-15 10:00:00', '2023-01-15 10:00:00', 'abc123sha');
+VALUES (1, 'Test Document', 'dddddddd-dddd-dddd-dddd-dddddddddddd', '2023-01-15 10:00:00', '2023-01-15 10:00:00', 'abc123sha');
INSERT INTO public."Chat" ("id", "userId", "name", "createdAt", "updatedAt", "isPersistent", "projectId")
-VALUES ('test-chat', 'macro|[email protected]', 'Test Chat', '2023-01-16 11:00:00', '2023-01-16 11:00:00', true,
- 'test-project');
+VALUES ('cccccccc-1111-1111-1111-111111111111', 'macro|[email protected]', 'Test Chat', '2023-01-16 11:00:00', '2023-01-16 11:00:00', true,
+ 'ffffffff-ffff-ffff-ffff-ffffffffffff');
-- Add user access to all items (Same as original)
INSERT INTO public."UserItemAccess" ("id", "user_id", "item_id", "item_type", "access_level", "created_at")
-VALUES (gen_random_uuid(), 'macro|[email protected]', 'test-document', 'document', 'owner', '2023-01-15 10:00:00'),
- (gen_random_uuid(), 'macro|[email protected]', 'test-document', 'document', 'view', '2023-01-15 10:30:00'),
- (gen_random_uuid(), 'macro|[email protected]', 'test-chat', 'chat', 'owner', '2023-01-16 11:00:00'),
- (gen_random_uuid(), 'macro|[email protected]', 'test-project', 'project', 'owner', '2023-01-17 12:00:00');
+VALUES (gen_random_uuid(), 'macro|[email protected]', 'dddddddd-dddd-dddd-dddd-dddddddddddd', 'document', 'owner', '2023-01-15 10:00:00'),
+ (gen_random_uuid(), 'macro|[email protected]', 'dddddddd-dddd-dddd-dddd-dddddddddddd', 'document', 'view', '2023-01-15 10:30:00'),
+ (gen_random_uuid(), 'macro|[email protected]', 'cccccccc-1111-1111-1111-111111111111', 'chat', 'owner', '2023-01-16 11:00:00'),
+ (gen_random_uuid(), 'macro|[email protected]', 'ffffffff-ffff-ffff-ffff-ffffffffffff', 'project', 'owner', '2023-01-17 12:00:00');
---------------------------------------------------
-- NEW: USER HISTORY DATA
@@ -42,9 +42,9 @@ VALUES (gen_random_uuid(), 'macro|[email protected]', 'test-document', 'document', '
INSERT INTO public."UserHistory" ("userId", "itemId", "itemType", "createdAt", "updatedAt")
VALUES
-- Make the document the most recently viewed item
-('macro|[email protected]', 'test-document', 'document', '2024-02-15 09:00:00', '2024-02-15 10:00:00'),
+('macro|[email protected]', 'dddddddd-dddd-dddd-dddd-dddddddddddd', 'document', '2024-02-15 09:00:00', '2024-02-15 10:00:00'),
-- Make the project the second most recently viewed item
-('macro|[email protected]', 'test-project', 'project', '2024-02-14 09:00:00', '2024-02-14 10:00:00');
+('macro|[email protected]', 'ffffffff-ffff-ffff-ffff-ffffffffffff', 'project', '2024-02-14 09:00:00', '2024-02-14 10:00:00');
-- Re-enable foreign key constraints
SET session_replication_role = 'origin';
\ No newline at end of file
diff --git a/rust/cloud-storage/macro_db_client/fixtures/no_frecency_items.sql b/rust/cloud-storage/macro_db_client/fixtures/no_frecency_items.sql
index b44c1f65f7..66c3159b79 100644
--- a/rust/cloud-storage/macro_db_client/fixtures/no_frecency_items.sql
+++ b/rust/cloud-storage/macro_db_client/fixtures/no_frecency_items.sql
@@ -13,66 +13,66 @@ VALUES ('macro|[email protected]', '[email protected]', 'stripe_id_1', '1');
-- Project Hierarchy
INSERT INTO public."Project" ("id", "name", "userId", "createdAt", "updatedAt")
-VALUES ('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'Project A', 'macro|[email protected]', '2024-01-01 09:00:00', '2024-01-01 09:00:00');
+VALUES ('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'Project A', 'macro|[email protected]', '2024-01-01 09:00:00', '2024-01-01 09:00:00'),
+ ('88888888-ffff-ffff-ffff-ffffffffffff', 'Project With Frecency', 'macro|[email protected]', '2024-01-17 10:00:00', '2024-02-08 10:00:00'),
+ ('88888888-8888-8888-8888-888888888888', 'Project No Frecency', 'macro|[email protected]', '2024-01-01 10:00:00', '2024-02-07 10:00:00');
--- Give user access to the project
+-- Give user access to the projects
INSERT INTO public."UserItemAccess" ("id", "user_id", "item_id", "item_type", "access_level")
-VALUES (gen_random_uuid(), 'macro|[email protected]', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'project', 'owner');
+VALUES (gen_random_uuid(), 'macro|[email protected]', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'project', 'owner'),
+ (gen_random_uuid(), 'macro|[email protected]', '88888888-ffff-ffff-ffff-ffffffffffff', 'project', 'owner'),
+ (gen_random_uuid(), 'macro|[email protected]', '88888888-8888-8888-8888-888888888888', 'project', 'owner');
--- Create documents (3 with frecency, 2 without)
+-- Create documents (2 with frecency, 2 without)
-- Documents WITH frecency (should be filtered out)
INSERT INTO public."Document" ("id", "name", "owner", "projectId", "createdAt", "updatedAt")
-VALUES ('11111111-1111-1111-1111-111111111111', 'Doc With Frecency 1', 'macro|[email protected]', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', '2024-01-10 10:00:00', '2024-02-15 10:00:00'),
- ('22222222-2222-2222-2222-222222222222', 'Doc With Frecency 2', 'macro|[email protected]', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', '2024-01-11 10:00:00', '2024-02-14 10:00:00'),
- ('33333333-3333-3333-3333-333333333333', 'Doc With Frecency 3', 'macro|[email protected]', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', '2024-01-12 10:00:00', '2024-02-13 10:00:00');
+VALUES ('44444444-ffff-ffff-ffff-ffffffffffff', 'Doc With Frecency 1', 'macro|[email protected]', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', '2024-01-10 10:00:00', '2024-02-15 10:00:00'),
+ ('55555555-ffff-ffff-ffff-ffffffffffff', 'Doc With Frecency 2', 'macro|[email protected]', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', '2024-01-11 10:00:00', '2024-02-14 10:00:00');
-- Documents WITHOUT frecency (should be returned)
INSERT INTO public."Document" ("id", "name", "owner", "projectId", "createdAt", "updatedAt")
-VALUES ('44444444-4444-4444-4444-444444444444', 'Doc No Frecency 1', 'macro|[email protected]', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', '2024-01-13 10:00:00', '2024-02-12 10:00:00'),
- ('55555555-5555-5555-5555-555555555555', 'Doc No Frecency 2', 'macro|[email protected]', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', '2024-01-14 10:00:00', '2024-02-11 10:00:00');
+VALUES ('44444444-4444-4444-4444-444444444444', 'Doc No Frecency 1', 'macro|[email protected]', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', '2024-01-13 10:00:00', '2024-02-13 10:00:00'),
+ ('55555555-5555-5555-5555-555555555555', 'Doc No Frecency 2', 'macro|[email protected]', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', '2024-01-14 10:00:00', '2024-02-12 10:00:00');
--- Create chats (2 with frecency, 2 without)
--- Chats WITH frecency (should be filtered out)
+-- Create chats (1 with frecency, 2 without)
+-- Chat WITH frecency (should be filtered out)
INSERT INTO public."Chat" ("id", "name", "userId", "projectId", "createdAt", "updatedAt")
-VALUES ('66666666-6666-6666-6666-666666666666', 'Chat With Frecency 1', 'macro|[email protected]', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', '2024-01-15 10:00:00', '2024-02-10 10:00:00'),
- ('77777777-7777-7777-7777-777777777777', 'Chat With Frecency 2', 'macro|[email protected]', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', '2024-01-16 10:00:00', '2024-02-09 10:00:00');
+VALUES ('66666666-ffff-ffff-ffff-ffffffffffff', 'Chat With Frecency 1', 'macro|[email protected]', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', '2024-01-14 10:00:00', '2024-02-11 10:00:00');
-- Chats WITHOUT frecency (should be returned)
INSERT INTO public."Chat" ("id", "name", "userId", "projectId", "createdAt", "updatedAt")
-VALUES ('88888888-8888-8888-8888-888888888888', 'Chat No Frecency 1', 'macro|[email protected]', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', '2024-01-17 10:00:00', '2024-02-08 10:00:00'),
- ('99999999-9999-9999-9999-999999999999', 'Chat No Frecency 2', 'macro|[email protected]', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', '2024-01-18 10:00:00', '2024-02-07 10:00:00');
+VALUES ('66666666-6666-6666-6666-666666666666', 'Chat No Frecency 1', 'macro|[email protected]', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', '2024-01-17 10:00:00', '2024-02-10 10:00:00'),
+ ('77777777-7777-7777-7777-777777777777', 'Chat No Frecency 2', 'macro|[email protected]', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', '2024-01-18 10:00:00', '2024-02-09 10:00:00');
-- Dependencies for documents
INSERT INTO public."DocumentFamily" ("id", "rootDocumentId")
-VALUES (1, '11111111-1111-1111-1111-111111111111'),
- (2, '22222222-2222-2222-2222-222222222222'),
- (3, '33333333-3333-3333-3333-333333333333'),
- (4, '44444444-4444-4444-4444-444444444444'),
- (5, '55555555-5555-5555-5555-555555555555');
+VALUES (1, '44444444-ffff-ffff-ffff-ffffffffffff'),
+ (2, '55555555-ffff-ffff-ffff-ffffffffffff'),
+ (3, '44444444-4444-4444-4444-444444444444'),
+ (4, '55555555-5555-5555-5555-555555555555');
INSERT INTO public."DocumentInstance" ("id", "documentId", "sha")
-VALUES (1, '11111111-1111-1111-1111-111111111111', 'sha-1'),
- (2, '22222222-2222-2222-2222-222222222222', 'sha-2'),
- (3, '33333333-3333-3333-3333-333333333333', 'sha-3'),
- (4, '44444444-4444-4444-4444-444444444444', 'sha-4'),
- (5, '55555555-5555-5555-5555-555555555555', 'sha-5');
+VALUES (1, '44444444-ffff-ffff-ffff-ffffffffffff', 'sha-1'),
+ (2, '55555555-ffff-ffff-ffff-ffffffffffff', 'sha-2'),
+ (3, '44444444-4444-4444-4444-444444444444', 'sha-3'),
+ (4, '55555555-5555-5555-5555-555555555555', 'sha-4');
-- User History entries for ordering tests
INSERT INTO public."UserHistory" ("userId", "itemId", "itemType", "updatedAt")
-VALUES ('macro|[email protected]', '44444444-4444-4444-4444-444444444444', 'document', '2024-03-15 10:00:00'),
- ('macro|[email protected]', '55555555-5555-5555-5555-555555555555', 'document', '2024-03-14 10:00:00'),
- ('macro|[email protected]', '88888888-8888-8888-8888-888888888888', 'chat', '2024-03-13 10:00:00'),
- ('macro|[email protected]', '99999999-9999-9999-9999-999999999999', 'chat', '2024-03-12 10:00:00'),
- ('macro|[email protected]', '11111111-1111-1111-1111-111111111111', 'document', '2024-03-11 10:00:00'),
- ('macro|[email protected]', '22222222-2222-2222-2222-222222222222', 'document', '2024-03-10 10:00:00'),
- ('macro|[email protected]', '66666666-6666-6666-6666-666666666666', 'chat', '2024-03-09 10:00:00');
+VALUES ('macro|[email protected]', '44444444-4444-4444-4444-444444444444', 'document', '2024-03-17 10:00:00'),
+ ('macro|[email protected]', '55555555-5555-5555-5555-555555555555', 'document', '2024-03-16 10:00:00'),
+ ('macro|[email protected]', '66666666-6666-6666-6666-666666666666', 'chat', '2024-03-15 10:00:00'),
+ ('macro|[email protected]', '77777777-7777-7777-7777-777777777777', 'chat', '2024-03-14 10:00:00'),
+ ('macro|[email protected]', '88888888-8888-8888-8888-888888888888', 'project', '2024-03-13 10:00:00'),
+ ('macro|[email protected]', '44444444-ffff-ffff-ffff-ffffffffffff', 'document', '2024-03-12 10:00:00'),
+ ('macro|[email protected]', '66666666-ffff-ffff-ffff-ffffffffffff', 'chat', '2024-03-11 10:00:00');
-- Insert frecency_aggregates for items WITH frecency
INSERT INTO public."frecency_aggregates" ("user_id", "entity_id", "entity_type", "frecency_score", "event_count", "first_event", "recent_events")
-VALUES ('macro|[email protected]', '11111111-1111-1111-1111-111111111111', 'document', 100.0, 10, '2024-01-10 10:00:00', '[]'::jsonb),
- ('macro|[email protected]', '22222222-2222-2222-2222-222222222222', 'document', 90.0, 8, '2024-01-11 10:00:00', '[]'::jsonb),
- ('macro|[email protected]', '33333333-3333-3333-3333-333333333333', 'document', 80.0, 6, '2024-01-12 10:00:00', '[]'::jsonb),
- ('macro|[email protected]', '66666666-6666-6666-6666-666666666666', 'chat', 70.0, 5, '2024-01-15 10:00:00', '[]'::jsonb),
- ('macro|[email protected]', '77777777-7777-7777-7777-777777777777', 'chat', 60.0, 4, '2024-01-16 10:00:00', '[]'::jsonb);
+VALUES ('macro|[email protected]', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'project', 110.0, 12, '2024-01-01 09:00:00', '[]'::jsonb),
+ ('macro|[email protected]', '44444444-ffff-ffff-ffff-ffffffffffff', 'document', 100.0, 10, '2024-01-10 10:00:00', '[]'::jsonb),
+ ('macro|[email protected]', '55555555-ffff-ffff-ffff-ffffffffffff', 'document', 90.0, 8, '2024-01-11 10:00:00', '[]'::jsonb),
+ ('macro|[email protected]', '66666666-ffff-ffff-ffff-ffffffffffff', 'chat', 80.0, 6, '2024-01-14 10:00:00', '[]'::jsonb),
+ ('macro|[email protected]', '88888888-ffff-ffff-ffff-ffffffffffff', 'project', 70.0, 5, '2024-01-17 10:00:00', '[]'::jsonb);
SET session_replication_role = 'origin';
diff --git a/rust/cloud-storage/macro_db_client/fixtures/no_frecency_items_unexpanded.sql b/rust/cloud-storage/macro_db_client/fixtures/no_frecency_items_unexpanded.sql
index 4a298d9a2c..50ccca7776 100644
--- a/rust/cloud-storage/macro_db_client/fixtures/no_frecency_items_unexpanded.sql
+++ b/rust/cloud-storage/macro_db_client/fixtures/no_frecency_items_unexpanded.sql
@@ -14,73 +14,73 @@ VALUES ('macro|[email protected]', '[email protected]', 'stripe_id_1', '1');
-- Create documents (2 with frecency, 2 without)
-- Documents WITH frecency (should be filtered out)
INSERT INTO public."Document" ("id", "name", "owner", "createdAt", "updatedAt")
-VALUES ('doc-with-frecency-1', 'Doc With Frecency 1', 'macro|[email protected]', '2024-01-10 10:00:00', '2024-02-15 10:00:00'),
- ('doc-with-frecency-2', 'Doc With Frecency 2', 'macro|[email protected]', '2024-01-11 10:00:00', '2024-02-14 10:00:00');
+VALUES ('44444444-ffff-ffff-ffff-ffffffffffff', 'Doc With Frecency 1', 'macro|[email protected]', '2024-01-10 10:00:00', '2024-02-15 10:00:00'),
+ ('55555555-ffff-ffff-ffff-ffffffffffff', 'Doc With Frecency 2', 'macro|[email protected]', '2024-01-11 10:00:00', '2024-02-14 10:00:00');
-- Documents WITHOUT frecency (should be returned)
INSERT INTO public."Document" ("id", "name", "owner", "createdAt", "updatedAt")
-VALUES ('doc-no-frecency-1', 'Doc No Frecency 1', 'macro|[email protected]', '2024-01-12 10:00:00', '2024-02-13 10:00:00'),
- ('doc-no-frecency-2', 'Doc No Frecency 2', 'macro|[email protected]', '2024-01-13 10:00:00', '2024-02-12 10:00:00');
+VALUES ('44444444-4444-4444-4444-444444444444', 'Doc No Frecency 1', 'macro|[email protected]', '2024-01-12 10:00:00', '2024-02-13 10:00:00'),
+ ('55555555-5555-5555-5555-555555555555', 'Doc No Frecency 2', 'macro|[email protected]', '2024-01-13 10:00:00', '2024-02-12 10:00:00');
-- Create chats (1 with frecency, 2 without)
-- Chat WITH frecency (should be filtered out)
INSERT INTO public."Chat" ("id", "name", "userId", "createdAt", "updatedAt")
-VALUES ('chat-with-frecency-1', 'Chat With Frecency 1', 'macro|[email protected]', '2024-01-14 10:00:00', '2024-02-11 10:00:00');
+VALUES ('66666666-ffff-ffff-ffff-ffffffffffff', 'Chat With Frecency 1', 'macro|[email protected]', '2024-01-14 10:00:00', '2024-02-11 10:00:00');
-- Chats WITHOUT frecency (should be returned)
INSERT INTO public."Chat" ("id", "name", "userId", "createdAt", "updatedAt")
-VALUES ('chat-no-frecency-1', 'Chat No Frecency 1', 'macro|[email protected]', '2024-01-15 10:00:00', '2024-02-10 10:00:00'),
- ('chat-no-frecency-2', 'Chat No Frecency 2', 'macro|[email protected]', '2024-01-16 10:00:00', '2024-02-09 10:00:00');
+VALUES ('66666666-6666-6666-6666-666666666666', 'Chat No Frecency 1', 'macro|[email protected]', '2024-01-15 10:00:00', '2024-02-10 10:00:00'),
+ ('77777777-7777-7777-7777-777777777777', 'Chat No Frecency 2', 'macro|[email protected]', '2024-01-16 10:00:00', '2024-02-09 10:00:00');
-- Create projects (1 with frecency, 1 without)
-- Project WITH frecency (should be filtered out)
INSERT INTO public."Project" ("id", "name", "userId", "createdAt", "updatedAt")
-VALUES ('project-with-frecency', 'Project With Frecency', 'macro|[email protected]', '2024-01-17 10:00:00', '2024-02-08 10:00:00');
+VALUES ('88888888-ffff-ffff-ffff-ffffffffffff', 'Project With Frecency', 'macro|[email protected]', '2024-01-17 10:00:00', '2024-02-08 10:00:00');
-- Project WITHOUT frecency (should be returned)
INSERT INTO public."Project" ("id", "name", "userId", "createdAt", "updatedAt")
-VALUES ('project-no-frecency', 'Project No Frecency', 'macro|[email protected]', '2024-01-18 10:00:00', '2024-02-07 10:00:00');
+VALUES ('88888888-8888-8888-8888-888888888888', 'Project No Frecency', 'macro|[email protected]', '2024-01-18 10:00:00', '2024-02-07 10:00:00');
-- Explicit UserItemAccess grants for all items (unexpanded requires this)
INSERT INTO public."UserItemAccess" ("id", "user_id", "item_id", "item_type", "access_level")
-VALUES (gen_random_uuid(), 'macro|[email protected]', 'doc-with-frecency-1', 'document', 'owner'),
- (gen_random_uuid(), 'macro|[email protected]', 'doc-with-frecency-2', 'document', 'owner'),
- (gen_random_uuid(), 'macro|[email protected]', 'doc-no-frecency-1', 'document', 'owner'),
- (gen_random_uuid(), 'macro|[email protected]', 'doc-no-frecency-2', 'document', 'owner'),
- (gen_random_uuid(), 'macro|[email protected]', 'chat-with-frecency-1', 'chat', 'owner'),
- (gen_random_uuid(), 'macro|[email protected]', 'chat-no-frecency-1', 'chat', 'owner'),
- (gen_random_uuid(), 'macro|[email protected]', 'chat-no-frecency-2', 'chat', 'owner'),
- (gen_random_uuid(), 'macro|[email protected]', 'project-with-frecency', 'project', 'owner'),
- (gen_random_uuid(), 'macro|[email protected]', 'project-no-frecency', 'project', 'owner');
+VALUES (gen_random_uuid(), 'macro|[email protected]', '44444444-ffff-ffff-ffff-ffffffffffff', 'document', 'owner'),
+ (gen_random_uuid(), 'macro|[email protected]', '55555555-ffff-ffff-ffff-ffffffffffff', 'document', 'owner'),
+ (gen_random_uuid(), 'macro|[email protected]', '44444444-4444-4444-4444-444444444444', 'document', 'owner'),
+ (gen_random_uuid(), 'macro|[email protected]', '55555555-5555-5555-5555-555555555555', 'document', 'owner'),
+ (gen_random_uuid(), 'macro|[email protected]', '66666666-ffff-ffff-ffff-ffffffffffff', 'chat', 'owner'),
+ (gen_random_uuid(), 'macro|[email protected]', '66666666-6666-6666-6666-666666666666', 'chat', 'owner'),
+ (gen_random_uuid(), 'macro|[email protected]', '77777777-7777-7777-7777-777777777777', 'chat', 'owner'),
+ (gen_random_uuid(), 'macro|[email protected]', '88888888-ffff-ffff-ffff-ffffffffffff', 'project', 'owner'),
+ (gen_random_uuid(), 'macro|[email protected]', '88888888-8888-8888-8888-888888888888', 'project', 'owner');
-- Dependencies for documents
INSERT INTO public."DocumentFamily" ("id", "rootDocumentId")
-VALUES (1, 'doc-with-frecency-1'),
- (2, 'doc-with-frecency-2'),
- (3, 'doc-no-frecency-1'),
- (4, 'doc-no-frecency-2');
+VALUES (1, '44444444-ffff-ffff-ffff-ffffffffffff'),
+ (2, '55555555-ffff-ffff-ffff-ffffffffffff'),
+ (3, '44444444-4444-4444-4444-444444444444'),
+ (4, '55555555-5555-5555-5555-555555555555');
INSERT INTO public."DocumentInstance" ("id", "documentId", "sha")
-VALUES (1, 'doc-with-frecency-1', 'sha-1'),
- (2, 'doc-with-frecency-2', 'sha-2'),
- (3, 'doc-no-frecency-1', 'sha-3'),
- (4, 'doc-no-frecency-2', 'sha-4');
+VALUES (1, '44444444-ffff-ffff-ffff-ffffffffffff', 'sha-1'),
+ (2, '55555555-ffff-ffff-ffff-ffffffffffff', 'sha-2'),
+ (3, '44444444-4444-4444-4444-444444444444', 'sha-3'),
+ (4, '55555555-5555-5555-5555-555555555555', 'sha-4');
-- User History entries for ordering tests
INSERT INTO public."UserHistory" ("userId", "itemId", "itemType", "updatedAt")
-VALUES ('macro|[email protected]', 'doc-no-frecency-1', 'document', '2024-03-17 10:00:00'),
- ('macro|[email protected]', 'doc-no-frecency-2', 'document', '2024-03-16 10:00:00'),
- ('macro|[email protected]', 'chat-no-frecency-1', 'chat', '2024-03-15 10:00:00'),
- ('macro|[email protected]', 'chat-no-frecency-2', 'chat', '2024-03-14 10:00:00'),
- ('macro|[email protected]', 'project-no-frecency', 'project', '2024-03-13 10:00:00'),
- ('macro|[email protected]', 'doc-with-frecency-1', 'document', '2024-03-12 10:00:00'),
- ('macro|[email protected]', 'chat-with-frecency-1', 'chat', '2024-03-11 10:00:00');
+VALUES ('macro|[email protected]', '44444444-4444-4444-4444-444444444444', 'document', '2024-03-17 10:00:00'),
+ ('macro|[email protected]', '55555555-5555-5555-5555-555555555555', 'document', '2024-03-16 10:00:00'),
+ ('macro|[email protected]', '66666666-6666-6666-6666-666666666666', 'chat', '2024-03-15 10:00:00'),
+ ('macro|[email protected]', '77777777-7777-7777-7777-777777777777', 'chat', '2024-03-14 10:00:00'),
+ ('macro|[email protected]', '88888888-8888-8888-8888-888888888888', 'project', '2024-03-13 10:00:00'),
+ ('macro|[email protected]', '44444444-ffff-ffff-ffff-ffffffffffff', 'document', '2024-03-12 10:00:00'),
+ ('macro|[email protected]', '66666666-ffff-ffff-ffff-ffffffffffff', 'chat', '2024-03-11 10:00:00');
-- Insert frecency_aggregates for items WITH frecency
INSERT INTO public."frecency_aggregates" ("user_id", "entity_id", "entity_type", "frecency_score", "event_count", "first_event", "recent_events")
-VALUES ('macro|[email protected]', 'doc-with-frecency-1', 'document', 100.0, 10, '2024-01-10 10:00:00', '[]'::jsonb),
- ('macro|[email protected]', 'doc-with-frecency-2', 'document', 90.0, 8, '2024-01-11 10:00:00', '[]'::jsonb),
- ('macro|[email protected]', 'chat-with-frecency-1', 'chat', 80.0, 6, '2024-01-14 10:00:00', '[]'::jsonb),
- ('macro|[email protected]', 'project-with-frecency', 'project', 70.0, 5, '2024-01-17 10:00:00', '[]'::jsonb);
+VALUES ('macro|[email protected]', '44444444-ffff-ffff-ffff-ffffffffffff', 'document', 100.0, 10, '2024-01-10 10:00:00', '[]'::jsonb),
+ ('macro|[email protected]', '55555555-ffff-ffff-ffff-ffffffffffff', 'document', 90.0, 8, '2024-01-11 10:00:00', '[]'::jsonb),
+ ('macro|[email protected]', '66666666-ffff-ffff-ffff-ffffffffffff', 'chat', 80.0, 6, '2024-01-14 10:00:00', '[]'::jsonb),
+ ('macro|[email protected]', '88888888-ffff-ffff-ffff-ffffffffffff', 'project', 70.0, 5, '2024-01-17 10:00:00', '[]'::jsonb);
SET session_replication_role = 'origin';
diff --git a/rust/cloud-storage/macro_db_client/fixtures/simple_items.sql b/rust/cloud-storage/macro_db_client/fixtures/simple_items.sql
index edfa87eceb..b4b8ecc75d 100644
--- a/rust/cloud-storage/macro_db_client/fixtures/simple_items.sql
+++ b/rust/cloud-storage/macro_db_client/fixtures/simple_items.sql
@@ -14,32 +14,32 @@ VALUES ('macro|[email protected]', '[email protected]', 'stripe_id');
-- Document A: Oldest created, middle updated, newest viewed
INSERT INTO public."Document" ("id", "name", "fileType", "owner", "createdAt", "updatedAt")
-VALUES ('doc-A', 'Doc A', 'txt', 'macro|[email protected]', '2024-01-01 10:00:00', '2024-01-02 11:00:00');
+VALUES ('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'Doc A', 'txt', 'macro|[email protected]', '2024-01-01 10:00:00', '2024-01-02 11:00:00');
-- Document B: Newest created, oldest updated, middle viewed
INSERT INTO public."Document" ("id", "name", "fileType", "owner", "createdAt", "updatedAt")
-VALUES ('doc-B', 'Doc B', 'pdf', 'macro|[email protected]', '2024-01-01 12:00:00', '2024-01-02 10:00:00');
+VALUES ('bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'Doc B', 'pdf', 'macro|[email protected]', '2024-01-01 12:00:00', '2024-01-02 10:00:00');
-- Document C: Middle created, newest updated, oldest viewed
INSERT INTO public."Document" ("id", "name", "fileType", "owner", "createdAt", "updatedAt")
-VALUES ('doc-C', 'Doc C', 'pdf', 'macro|[email protected]', '2024-01-01 11:00:00', '2024-01-02 12:00:00');
+VALUES ('cccccccc-cccc-cccc-cccc-cccccccccccc', 'Doc C', 'pdf', 'macro|[email protected]', '2024-01-01 11:00:00', '2024-01-02 12:00:00');
-- Instances (needed for the query to run)
INSERT INTO public."DocumentInstance" ("documentId", "sha")
-VALUES ('doc-A', 'sha-a'),
- ('doc-B', 'sha-b'),
- ('doc-C', 'sha-c');
+VALUES ('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'sha-a'),
+ ('bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'sha-b'),
+ ('cccccccc-cccc-cccc-cccc-cccccccccccc', 'sha-c');
-- Give the user access to all three documents
INSERT INTO public."UserItemAccess" ("id", "user_id", "item_id", "item_type", "access_level")
-VALUES (gen_random_uuid(), 'macro|[email protected]', 'doc-A', 'document', 'owner'),
- (gen_random_uuid(), 'macro|[email protected]', 'doc-B', 'document', 'owner'),
- (gen_random_uuid(), 'macro|[email protected]', 'doc-C', 'document', 'owner');
+VALUES (gen_random_uuid(), 'macro|[email protected]', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'document', 'owner'),
+ (gen_random_uuid(), 'macro|[email protected]', 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'document', 'owner'),
+ (gen_random_uuid(), 'macro|[email protected]', 'cccccccc-cccc-cccc-cccc-cccccccccccc', 'document', 'owner');
-- Create UserHistory entries with their own distinct ordering
INSERT INTO public."UserHistory" ("userId", "itemId", "itemType", "updatedAt")
-VALUES ('macro|[email protected]', 'doc-A', 'document', '2024-01-03 12:00:00'), -- Newest viewed
- ('macro|[email protected]', 'doc-B', 'document', '2024-01-03 11:00:00');
+VALUES ('macro|[email protected]', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'document', '2024-01-03 12:00:00'), -- Newest viewed
+ ('macro|[email protected]', 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'document', '2024-01-03 11:00:00');
-- Doc C has no user_history entry
-- Oldest viewed
diff --git a/rust/cloud-storage/macro_db_client/fixtures/sorting_expanded_items.sql b/rust/cloud-storage/macro_db_client/fixtures/sorting_expanded_items.sql
index 4757e53249..107636d15b 100644
--- a/rust/cloud-storage/macro_db_client/fixtures/sorting_expanded_items.sql
+++ b/rust/cloud-storage/macro_db_client/fixtures/sorting_expanded_items.sql
@@ -19,42 +19,42 @@ VALUES ('macro|[email protected]', '[email protected]', 'stripe_id_1', '1');
-- Project Hierarchy (A -> B)
INSERT INTO public."Project" ("id", "name", "userId", "parentId", "createdAt", "updatedAt")
-VALUES ('project-A', 'Project A', 'macro|[email protected]', NULL, '2024-01-01 09:00:00', '2024-01-01 09:00:00'),
- ('project-B', 'Project B', 'macro|[email protected]', 'project-A', '2024-01-01 09:30:00', '2024-01-01 09:30:00');
+VALUES ('aaaaaaaa-ffff-ffff-ffff-ffffffffffff', 'Project A', 'macro|[email protected]', NULL, '2024-01-01 09:00:00', '2024-01-01 09:00:00'),
+ ('bbbbbbbb-ffff-ffff-ffff-ffffffffffff', 'Project B', 'macro|[email protected]', 'aaaaaaaa-ffff-ffff-ffff-ffffffffffff', '2024-01-01 09:30:00', '2024-01-01 09:30:00');
-- Give user access to the top-level project to test hierarchical access
INSERT INTO public."UserItemAccess" ("id", "user_id", "item_id", "item_type", "access_level")
-VALUES (gen_random_uuid(), 'macro|[email protected]', 'project-A', 'project', 'owner');
+VALUES (gen_random_uuid(), 'macro|[email protected]', 'aaaaaaaa-ffff-ffff-ffff-ffffffffffff', 'project', 'owner');
-- Item Creation
-- Document A (in Project A): Oldest created, Middle updated, Newest viewed
INSERT INTO public."Document" ("id", "name", "owner", "projectId", "createdAt", "updatedAt")
-VALUES ('doc-A', 'Doc A', 'macro|[email protected]', 'project-A', '2024-01-10 10:00:00', '2024-02-11 10:00:00');
+VALUES ('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'Doc A', 'macro|[email protected]', 'aaaaaaaa-ffff-ffff-ffff-ffffffffffff', '2024-01-10 10:00:00', '2024-02-11 10:00:00');
-- Chat A (in Project A): Middle created, Newest updated, Oldest viewed
INSERT INTO public."Chat" ("id", "name", "userId", "projectId", "createdAt", "updatedAt")
-VALUES ('chat-A', 'Chat A', 'macro|[email protected]', 'project-A', '2024-01-11 10:00:00', '2024-02-12 10:00:00');
+VALUES ('aaaaaaaa-cccc-cccc-cccc-cccccccccccc', 'Chat A', 'macro|[email protected]', 'aaaaaaaa-ffff-ffff-ffff-ffffffffffff', '2024-01-11 10:00:00', '2024-02-12 10:00:00');
-- Document B (in Project B): Newest created, Oldest updated, Middle viewed
INSERT INTO public."Document" ("id", "name", "owner", "projectId", "createdAt", "updatedAt")
-VALUES ('doc-B', 'Doc B', 'macro|[email protected]', 'project-B', '2024-01-12 10:00:00', '2024-02-10 10:00:00');
+VALUES ('bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'Doc B', 'macro|[email protected]', 'bbbbbbbb-ffff-ffff-ffff-ffffffffffff', '2024-01-12 10:00:00', '2024-02-10 10:00:00');
-- Chat B (in Project B): Accessible, but has NO UserHistory entry.
INSERT INTO public."Chat" ("id", "name", "userId", "projectId", "createdAt", "updatedAt")
-VALUES ('chat-B', 'Chat B', 'macro|[email protected]', 'project-B', '2024-01-13 10:00:00', '2024-02-09 10:00:00');
+VALUES ('bbbbbbbb-cccc-cccc-cccc-cccccccccccc', 'Chat B', 'macro|[email protected]', 'bbbbbbbb-ffff-ffff-ffff-ffffffffffff', '2024-01-13 10:00:00', '2024-02-09 10:00:00');
-- Dependencies
INSERT INTO public."DocumentFamily" ("id", "rootDocumentId")
-VALUES (1, 'doc-A'),
- (2, 'doc-B');
+VALUES (1, 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'),
+ (2, 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb');
INSERT INTO public."DocumentInstance" ("id", "documentId", "sha")
-VALUES (1, 'doc-A', 'sha-a'),
- (2, 'doc-B', 'sha-b');
+VALUES (1, 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'sha-a'),
+ (2, 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'sha-b');
-- User History with its own distinct ordering. Note that 'chat-B' is missing.
INSERT INTO public."UserHistory" ("userId", "itemId", "itemType", "updatedAt")
-VALUES ('macro|[email protected]', 'doc-A', 'document', '2024-03-12 10:00:00'), -- Newest viewed
- ('macro|[email protected]', 'doc-B', 'document', '2024-03-11 10:00:00'), -- Middle viewed
- ('macro|[email protected]', 'chat-A', 'chat', '2024-03-10 10:00:00'); -- Oldest viewed
+VALUES ('macro|[email protected]', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'document', '2024-03-12 10:00:00'), -- Newest viewed
+ ('macro|[email protected]', 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'document', '2024-03-11 10:00:00'), -- Middle viewed
+ ('macro|[email protected]', 'aaaaaaaa-cccc-cccc-cccc-cccccccccccc', 'chat', '2024-03-10 10:00:00'); -- Oldest viewed
SET session_replication_role = 'origin';
diff --git a/rust/cloud-storage/models_soup/Cargo.toml b/rust/cloud-storage/models_soup/Cargo.toml
index 321e2fac66..c36a5af439 100644
--- a/rust/cloud-storage/models_soup/Cargo.toml
+++ b/rust/cloud-storage/models_soup/Cargo.toml
@@ -6,12 +6,15 @@ version = "0.1.0"
[features]
mock = []
+schema = ["dep:utoipa"]
[dependencies]
anyhow = { workspace = true }
chrono = { workspace = true }
+macro_user_id = { path = "../macro_user_id" }
model-entity = { path = "../model-entity" }
models_pagination = { path = "../models_pagination" }
serde = { workspace = true }
strum = { workspace = true }
-utoipa = { workspace = true }
+utoipa = { workspace = true, optional = true }
+uuid = { workspace = true }
diff --git a/rust/cloud-storage/models_soup/src/chat.rs b/rust/cloud-storage/models_soup/src/chat.rs
index 3807765ec2..bfb868446c 100644
--- a/rust/cloud-storage/models_soup/src/chat.rs
+++ b/rust/cloud-storage/models_soup/src/chat.rs
@@ -1,65 +1,42 @@
use chrono::Utc;
+use macro_user_id::user_id::MacroUserIdStr;
use serde::{Deserialize, Serialize};
-use utoipa::ToSchema;
+use uuid::Uuid;
-#[derive(Serialize, Clone, Deserialize, Debug, ToSchema)]
+#[derive(Serialize, Clone, Deserialize, Debug)]
#[cfg_attr(feature = "mock", derive(PartialEq, Eq))]
#[serde(rename_all = "camelCase")]
+#[cfg_attr(feature = "schema", derive(utoipa::ToSchema))]
pub struct SoupChat {
/// The chat uuid
- pub id: String,
+ pub id: Uuid,
/// The name of the chat
pub name: String,
/// Who the chat belongs to
- pub owner_id: String,
+ #[cfg_attr(feature = "schema", schema(value_type = String))]
+ pub owner_id: MacroUserIdStr<'static>,
/// The project id of the chat
#[serde(skip_serializing_if = "Option::is_none")]
- pub project_id: Option<String>,
+ pub project_id: Option<Uuid>,
/// Whether the chat is persistent or not
pub is_persistent: bool,
/// The time the chat was created
#[serde(with = "chrono::serde::ts_milliseconds")]
- #[schema(value_type = i64)]
+ #[cfg_attr(feature = "schema", schema(value_type = i64))]
pub created_at: chrono::DateTime<Utc>,
/// The time the chat was last updated
#[serde(with = "chrono::serde::ts_milliseconds")]
- #[schema(value_type = i64)]
+ #[cfg_attr(feature = "schema", schema(value_type = i64))]
pub updated_at: chrono::DateTime<Utc>,
/// The time the chat was last viewed
#[serde(with = "chrono::serde::ts_milliseconds_option")]
- #[schema(value_type = i64, nullable = true)]
+ #[cfg_attr(feature = "schema", schema(value_type = i64, nullable = true))]
pub viewed_at: Option<chrono::DateTime<Utc>>,
}
-
-#[expect(
- clippy::too_many_arguments,
- reason = "no good reason but too hard to fix right now"
-)]
-pub fn map_soup_chat(
- id: String,
- user_id: String,
- name: String,
- project_id: Option<String>,
- is_persistent: Option<bool>,
- created_at: chrono::DateTime<Utc>,
- updated_at: chrono::DateTime<Utc>,
- viewed_at: Option<chrono::DateTime<Utc>>,
-) -> SoupChat {
- SoupChat {
- id,
- owner_id: user_id,
- name,
- project_id,
- created_at,
- updated_at,
- is_persistent: is_persistent.unwrap_or(false),
- viewed_at,
- }
-}
diff --git a/rust/cloud-storage/models_soup/src/document.rs b/rust/cloud-storage/models_soup/src/document.rs
index 61fee9a9a2..2209a687cf 100644
--- a/rust/cloud-storage/models_soup/src/document.rs
+++ b/rust/cloud-storage/models_soup/src/document.rs
@@ -1,19 +1,22 @@
use chrono::Utc;
-use utoipa::ToSchema;
+use macro_user_id::user_id::MacroUserIdStr;
+use uuid::Uuid;
-#[derive(serde::Serialize, serde::Deserialize, Debug, ToSchema, Clone)]
+#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
#[cfg_attr(feature = "mock", derive(PartialEq, Eq))]
#[serde(rename_all = "camelCase")]
+#[cfg_attr(feature = "schema", derive(utoipa::ToSchema))]
pub struct SoupDocument {
/// The document id
- pub id: String,
+ pub id: Uuid,
/// The version of the document
/// This could be the document_instance_id or document_bom_id depending on the file type
pub document_version_id: i64,
/// The owner of the document
- pub owner_id: String,
+ #[cfg_attr(feature = "schema", schema(value_type = String))]
+ pub owner_id: MacroUserIdStr<'static>,
/// The name of the document
pub name: String,
@@ -29,11 +32,11 @@ pub struct SoupDocument {
/// The id of the project that this document belongs to
#[serde(skip_serializing_if = "Option::is_none")]
- pub project_id: Option<String>,
+ pub project_id: Option<Uuid>,
/// The id of the document this document branched from
#[serde(skip_serializing_if = "Option::is_none")]
- pub branched_from_id: Option<String>,
+ pub branched_from_id: Option<Uuid>,
/// The id of the version this document branched from
/// This could be either DocumentInstance or DocumentBom id depending on the file type
@@ -46,54 +49,16 @@ pub struct SoupDocument {
/// The time the document was created
#[serde(with = "chrono::serde::ts_milliseconds")]
- #[schema(value_type = i64)]
+ #[cfg_attr(feature = "schema", schema(value_type = i64))]
pub created_at: chrono::DateTime<Utc>,
/// The time the document instance / document BOM was updated
#[serde(with = "chrono::serde::ts_milliseconds")]
- #[schema(value_type = i64)]
+ #[cfg_attr(feature = "schema", schema(value_type = i64))]
pub updated_at: chrono::DateTime<Utc>,
/// The time the document was last viewed
#[serde(with = "chrono::serde::ts_milliseconds_option")]
- #[schema(value_type = i64, nullable = true)]
+ #[cfg_attr(feature = "schema", schema(value_type = i64, nullable = true))]
pub viewed_at: Option<chrono::DateTime<Utc>>,
}
-
-#[expect(
- clippy::too_many_arguments,
- reason = "no good reason but too hard to fix right now"
-)]
-pub fn map_soup_document(
- id: String,
- user_id: String,
- document_version_id: Option<String>,
- name: String,
- sha: Option<String>,
- file_type: Option<String>,
- document_family_id: Option<i64>,
- branched_from_id: Option<String>,
- branched_from_version_id: Option<i64>,
- project_id: Option<String>,
- created_at: chrono::DateTime<Utc>,
- updated_at: chrono::DateTime<Utc>,
- viewed_at: Option<chrono::DateTime<Utc>>,
-) -> anyhow::Result<SoupDocument> {
- Ok(SoupDocument {
- id,
- owner_id: user_id,
- document_version_id: document_version_id
- .ok_or_else(|| anyhow::anyhow!("document_version_id is required"))?
- .parse::<i64>()?,
- name,
- sha,
- file_type,
- document_family_id,
- branched_from_id,
- branched_from_version_id,
- project_id,
- created_at,
- updated_at,
- viewed_at,
- })
-}
diff --git a/rust/cloud-storage/models_soup/src/item.rs b/rust/cloud-storage/models_soup/src/item.rs
index 55daa16e05..6c9be711f6 100644
--- a/rust/cloud-storage/models_soup/src/item.rs
+++ b/rust/cloud-storage/models_soup/src/item.rs
@@ -6,25 +6,26 @@ use model_entity::{Entity, EntityType};
use models_pagination::{Identify, SimpleSortMethod, SortOn};
use serde::{Deserialize, Serialize, Serializer};
use strum::EnumString;
-use utoipa::ToSchema;
+use uuid::Uuid;
-#[derive(Debug, Clone, Eq, PartialEq, ToSchema, EnumString, Deserialize, Serialize)]
+#[derive(Debug, Clone, Eq, PartialEq, EnumString, Deserialize, Serialize)]
#[strum(serialize_all = "snake_case")]
#[serde(rename_all = "snake_case")]
+#[cfg_attr(feature = "schema", derive(utoipa::ToSchema))]
pub enum SoupItemType {
Document,
Chat,
Project,
}
-#[derive(Deserialize, Clone, ToSchema, Debug)]
+#[derive(Deserialize, Clone, Debug)]
#[cfg_attr(feature = "mock", derive(PartialEq, Eq))]
#[serde(untagged)]
-#[schema(discriminator(property_name = "type", mapping(
+#[cfg_attr(feature = "schema", derive(utoipa::ToSchema), schema(discriminator(property_name = "type", mapping(
("document" = "#/components/schemas/SoupDocument"),
("chat" = "#/components/schemas/SoupChat"),
("project" = "#/components/schemas/SoupProject"),
-)))]
+))))]
pub enum SoupItem {
Document(SoupDocument),
Chat(SoupChat),
@@ -33,14 +34,16 @@ pub enum SoupItem {
impl SoupItem {
/// return the [Entity] for this soup item
- pub fn entity(&self) -> Entity<'_> {
+ pub fn entity(&self) -> Entity<'static> {
match self {
SoupItem::Document(soup_document) => {
- EntityType::Document.with_entity_str(&soup_document.id)
+ EntityType::Document.with_entity_string(soup_document.id.to_string())
+ }
+ SoupItem::Chat(soup_chat) => {
+ EntityType::Chat.with_entity_string(soup_chat.id.to_string())
}
- SoupItem::Chat(soup_chat) => EntityType::Chat.with_entity_str(&soup_chat.id),
SoupItem::Project(soup_project) => {
- EntityType::Project.with_entity_str(&soup_project.id)
+ EntityType::Project.with_entity_string(soup_project.id.to_string())
}
}
}
@@ -90,24 +93,6 @@ impl Serialize for SoupItem {
}
}
-impl From<SoupProject> for SoupItem {
- fn from(val: SoupProject) -> Self {
- SoupItem::Project(val)
- }
-}
-
-impl From<SoupDocument> for SoupItem {
- fn from(val: SoupDocument) -> Self {
- SoupItem::Document(val)
- }
-}
-
-impl From<SoupChat> for SoupItem {
- fn from(val: SoupChat) -> Self {
- SoupItem::Chat(val)
- }
-}
-
impl SoupItem {
fn cursor_timestamp(&self, sort: SimpleSortMethod) -> DateTime<Utc> {
match (self, sort) {
@@ -148,13 +133,13 @@ impl SoupItem {
}
impl Identify for SoupItem {
- type Id = String;
+ type Id = Uuid;
fn id(&self) -> Self::Id {
match self {
- SoupItem::Document(soup_document) => soup_document.id.clone(),
- SoupItem::Chat(soup_chat) => soup_chat.id.clone(),
- SoupItem::Project(soup_project) => soup_project.id.clone(),
+ SoupItem::Document(soup_document) => soup_document.id,
+ SoupItem::Chat(soup_chat) => soup_chat.id,
+ SoupItem::Project(soup_project) => soup_project.id,
}
}
}
diff --git a/rust/cloud-storage/models_soup/src/project.rs b/rust/cloud-storage/models_soup/src/project.rs
index 0acd70417d..87a64aefc8 100644
--- a/rust/cloud-storage/models_soup/src/project.rs
+++ b/rust/cloud-storage/models_soup/src/project.rs
@@ -1,56 +1,39 @@
use chrono::Utc;
+use macro_user_id::user_id::MacroUserIdStr;
use serde::{Deserialize, Serialize};
-use utoipa::ToSchema;
+use uuid::Uuid;
-#[derive(Serialize, Clone, Deserialize, Debug, ToSchema)]
+#[derive(Serialize, Clone, Deserialize, Debug)]
#[cfg_attr(feature = "mock", derive(PartialEq, Eq))]
#[serde(rename_all = "camelCase")]
+#[cfg_attr(feature = "schema", derive(utoipa::ToSchema))]
pub struct SoupProject {
/// The id of the project
- pub id: String,
+ pub id: Uuid,
/// The name of the project
pub name: String,
/// The user id of who created the project
- pub owner_id: String,
+ #[cfg_attr(feature = "schema", schema(value_type = String))]
+ pub owner_id: MacroUserIdStr<'static>,
/// The parent project id
#[serde(skip_serializing_if = "Option::is_none")]
- pub parent_id: Option<String>,
+ pub parent_id: Option<Uuid>,
/// The time the project was created
#[serde(with = "chrono::serde::ts_milliseconds")]
- #[schema(value_type = i64)]
+ #[cfg_attr(feature = "schema", schema(value_type = i64))]
pub created_at: chrono::DateTime<Utc>,
/// The time the project was updated
#[serde(with = "chrono::serde::ts_milliseconds")]
- #[schema(value_type = i64)]
+ #[cfg_attr(feature = "schema", schema(value_type = i64))]
pub updated_at: chrono::DateTime<Utc>,
/// The time the document was last viewed
#[serde(with = "chrono::serde::ts_milliseconds_option")]
- #[schema(value_type = i64, nullable = true)]
+ #[cfg_attr(feature = "schema", schema(value_type = i64, nullable = true))]
pub viewed_at: Option<chrono::DateTime<Utc>>,
}
-
-pub fn map_soup_project(
- id: String,
- owner: String,
- name: String,
- parent_id: Option<String>,
- created_at: chrono::DateTime<Utc>,
- updated_at: chrono::DateTime<Utc>,
- viewed_at: Option<chrono::DateTime<Utc>>,
-) -> SoupProject {
- SoupProject {
- id,
- owner_id: owner,
- name,
- parent_id,
- created_at,
- updated_at,
- viewed_at,
- }
-}
diff --git a/rust/cloud-storage/soup/Cargo.toml b/rust/cloud-storage/soup/Cargo.toml
index 93b71d63ee..2711e69414 100644
--- a/rust/cloud-storage/soup/Cargo.toml
+++ b/rust/cloud-storage/soup/Cargo.toml
@@ -11,6 +11,7 @@ axum = [
"dep:model_user",
"dep:utoipa",
"models_pagination/axum",
+ "models_soup/schema",
]
diff --git a/rust/cloud-storage/soup/src/domain/service/tests.rs b/rust/cloud-storage/soup/src/domain/service/tests.rs
index a085f7911a..5767e041b9 100644
--- a/rust/cloud-storage/soup/src/domain/service/tests.rs
+++ b/rust/cloud-storage/soup/src/domain/service/tests.rs
@@ -10,18 +10,45 @@ use models_pagination::{Cursor, CursorVal, FrecencyValue, SimpleSortMethod, Type
use models_soup::document::SoupDocument;
use ordered_float::OrderedFloat;
use sqlx::types::chrono::{DateTime, Utc};
+use uuid::Uuid;
use super::*;
-fn soup_document(id: String) -> SoupDocument {
- soup_document_with_updated(id, Default::default())
+fn soup_document(id: &str) -> SoupDocument {
+ // Create a deterministic UUID from the string ID
+ let uuid = Uuid::parse_str(id).unwrap_or_else(|_| {
+ // For simple IDs like "doc-1", create a zero UUID with the number embedded
+ let num: u128 = id
+ .chars()
+ .filter(|c| c.is_numeric())
+ .collect::<String>()
+ .parse()
+ .unwrap_or(0);
+ Uuid::from_u128(num)
+ });
+ soup_document_uuid_with_updated(uuid, Default::default())
+}
+
+fn soup_document_with_updated(id: &str, updated_at: DateTime<Utc>) -> SoupDocument {
+ // Create a deterministic UUID from the string ID
+ let uuid = Uuid::parse_str(id).unwrap_or_else(|_| {
+ // For simple IDs like "doc-1", create a zero UUID with the number embedded
+ let num: u128 = id
+ .chars()
+ .filter(|c| c.is_numeric())
+ .collect::<String>()
+ .parse()
+ .unwrap_or(0);
+ Uuid::from_u128(num)
+ });
+ soup_document_uuid_with_updated(uuid, updated_at)
}
-fn soup_document_with_updated(id: String, updated_at: DateTime<Utc>) -> SoupDocument {
+fn soup_document_uuid_with_updated(id: Uuid, updated_at: DateTime<Utc>) -> SoupDocument {
SoupDocument {
id,
document_version_id: 1,
- owner_id: "macro|[email protected]".to_string(),
+ owner_id: MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),
name: Default::default(),
file_type: None,
sha: None,
@@ -57,7 +84,7 @@ async fn it_should_not_query_frecency() {
.times(1)
.returning(|_params| {
Box::pin(async move {
- Ok(Some(soup_document("my-document".to_string()))
+ Ok(Some(soup_document("my-document"))
.into_iter()
.cycle()
.take(10)
@@ -101,7 +128,8 @@ async fn it_should_query_frecency() {
Ok((1..=req.limit)
.map(|i| {
AggregateFrecency::new_mock(
- EntityType::Document.with_entity_string(format!("my-document-{i}")),
+ EntityType::Document
+ .with_entity_string(uuid::Uuid::from_u128(i as u128).to_string()),
420.0,
)
})
@@ -131,7 +159,7 @@ async fn it_should_query_frecency() {
let res = Ok(params
.entities
.iter()
- .map(|v| soup_document(v.entity_id.to_string()))
+ .map(|v| soup_document(&v.entity_id))
.map(SoupItem::Document)
.collect());
Box::pin(async move { res })
@@ -169,7 +197,8 @@ async fn it_should_sort_frecency_descending() {
Ok((1..=req.limit)
.map(|v| {
AggregateFrecency::new_mock(
- EntityType::Document.with_entity_string(format!("my-document-{v}")),
+ EntityType::Document
+ .with_entity_string(uuid::Uuid::from_u128(v as u128).to_string()),
f64::from(v),
)
})
@@ -198,7 +227,7 @@ async fn it_should_sort_frecency_descending() {
let res = Ok(params
.entities
.iter()
- .map(|v| soup_document(v.entity_id.to_string()))
+ .map(|v| soup_document(&v.entity_id))
.map(SoupItem::Document)
.collect());
@@ -239,7 +268,8 @@ async fn frecency_should_fallback() {
.returning(|_params| {
let iter = (1..=25).map(|v| {
AggregateFrecency::new_mock(
- EntityType::Document.with_entity_string(format!("doc-{v}")),
+ EntityType::Document
+ .with_entity_string(uuid::Uuid::from_u128(v as u128).to_string()),
v.into(),
)
});
@@ -254,7 +284,7 @@ async fn frecency_should_fallback() {
let vec = params
.entities
.iter()
- .map(|id| soup_document(id.entity_id.to_string()))
+ .map(|id| soup_document(&id.entity_id))
.map(SoupItem::Document)
.collect();
Box::pin(async move { Ok(vec) })
@@ -277,7 +307,7 @@ async fn frecency_should_fallback() {
let iter = (26..=200)
.map(|v| {
soup_document_with_updated(
- format!("doc-{v}"),
+ &uuid::Uuid::from_u128(v as u128).to_string(),
DateTime::default() + Days::new(v),
)
})
@@ -313,7 +343,8 @@ async fn frecency_should_fallback() {
assert_matches!(
typed_cursor,
Cursor { id, limit: 100, val: CursorVal { sort_type: Frecency, last_val: FrecencyValue::UpdatedAt(updated) }, filter: None } => {
- assert_eq!(id, "doc-100");
+ let expected_uuid_str = Uuid::from_u128(100).to_string();
+ assert_eq!(id, expected_uuid_str);
assert_eq!(updated, <DateTime<Utc>>::default() + Days::new(100));
});
@@ -331,7 +362,8 @@ async fn frecency_should_paginate() {
.returning(|params| {
let iter = (1..=params.limit).map(|v| {
AggregateFrecency::new_mock(
- EntityType::Document.with_entity_string(format!("doc-{v}")),
+ EntityType::Document
+ .with_entity_string(uuid::Uuid::from_u128(v as u128).to_string()),
v.into(),
)
});
@@ -345,7 +377,7 @@ async fn frecency_should_paginate() {
let vec = params
.entities
.iter()
- .map(|id| soup_document(id.entity_id.to_string()))
+ .map(|id| soup_document(&id.entity_id))
.map(SoupItem::Document)
.collect();
Box::pin(async move { Ok(vec) })
@@ -379,7 +411,8 @@ async fn frecency_should_paginate() {
assert_matches!(
typed_cursor,
Cursor { id, limit: 100, val: CursorVal { sort_type: Frecency, last_val: FrecencyValue::FrecencyScore(score) }, filter: None} => {
- assert_eq!(id, "doc-1");
+ let expected_uuid_str = Uuid::from_u128(1).to_string();
+ assert_eq!(id, expected_uuid_str);
// last item should be the lowest score because we sort desc
assert_eq!(score as u32, 1u32);
});
@@ -397,7 +430,8 @@ async fn frecency_should_resume_cursor() {
.returning(|params| {
let iter = (1..=params.limit).map(|v| {
AggregateFrecency::new_mock(
- EntityType::Document.with_entity_string(format!("doc-next-{v}")),
+ EntityType::Document
+ .with_entity_string(uuid::Uuid::from_u128(v as u128).to_string()),
5.0 - (f64::from(v) / params.limit as f64),
)
});
@@ -411,7 +445,7 @@ async fn frecency_should_resume_cursor() {
let vec = params
.entities
.iter()
- .map(|id| soup_document(id.entity_id.to_string()))
+ .map(|id| soup_document(&id.entity_id))
.map(SoupItem::Document)
.collect();
Box::pin(async move { Ok(vec) })
@@ -422,7 +456,7 @@ async fn frecency_should_resume_cursor() {
soup_type: SoupType::UnExpanded,
limit: 100,
cursor: SoupQuery::Frecency(Query::Cursor(Cursor {
- id: "doc-5".to_string(),
+ id: Uuid::from_u128(5).to_string(),
limit: 100,
val: CursorVal {
sort_type: Frecency,
@@ -450,7 +484,8 @@ async fn frecency_should_resume_cursor() {
assert_matches!(
typed_cursor,
Cursor { id, limit: 100, val: CursorVal { sort_type: Frecency, last_val: FrecencyValue::FrecencyScore(score) }, filter: None} => {
- assert_eq!(id, "doc-next-100");
+ let expected_uuid_str = Uuid::from_u128(100).to_string(); // "next-100" -> 100
+ assert_eq!(id, expected_uuid_str);
// last item should be the lowest score because we sort desc
assert_eq!(score as u32, 4u32);
});
@@ -480,7 +515,8 @@ async fn frecency_fallback_cursor_should_resume() {
} => {
let expected_time = <DateTime<Utc>>::default() + Days::new(5);
assert_eq!(last_val, &expected_time);
- assert_eq!(id, "doc-100");
+ let expected_uuid_str = Uuid::from_u128(100).to_string();
+ assert_eq!(id, &expected_uuid_str);
true
})
})
@@ -489,7 +525,7 @@ async fn frecency_fallback_cursor_should_resume() {
let iter = (1..=params.limit * 2)
.map(|v| {
soup_document_with_updated(
- format!("doc-next-{v}"),
+ &uuid::Uuid::from_u128(v as u128).to_string(),
DateTime::default() + Days::new(v.into()),
)
})
@@ -504,7 +540,7 @@ async fn frecency_fallback_cursor_should_resume() {
soup_type: SoupType::UnExpanded,
limit: 100,
cursor: SoupQuery::Frecency(Query::Cursor(Cursor {
- id: "doc-100".to_string(),
+ id: Uuid::from_u128(100).to_string(),
limit: 100,
val: CursorVal {
sort_type: Frecency,
@@ -521,7 +557,8 @@ async fn frecency_fallback_cursor_should_resume() {
assert!(res.items.iter().all(|v| v.frecency_score.is_none()));
let cursor = res.next_cursor.unwrap().decode_json().unwrap();
assert_matches!(cursor, Cursor { id, limit: 100, val: CursorVal { sort_type: Frecency, last_val: FrecencyValue::UpdatedAt(updated) }, filter: None } => {
- assert_eq!(id, "doc-next-100");
+ let expected_uuid_str = Uuid::from_u128(100).to_string(); // "next-100" -> 100
+ assert_eq!(id, expected_uuid_str);
let expected_date = <DateTime<Utc>>::default() + Days::new(100);
assert_eq!(updated, expected_date);
})
@@ -549,7 +586,7 @@ async fn cursor_should_return_simple_sort() {
.times(1)
.returning(|_params| {
let res = (0..100)
- .map(|i| soup_document(format!("my-document-{i}")))
+ .map(|i| soup_document(&format!("my-document-{i}")))
.map(SoupItem::Document)
.collect();
Box::pin(async move { Ok(res) })
@@ -571,7 +608,8 @@ async fn cursor_should_return_simple_sort() {
let simple_cursor = res.unwrap_left();
let cursor_decoded = simple_cursor.next_cursor.unwrap().decode_json().unwrap();
assert_matches!(cursor_decoded, Cursor { id, limit: 20, val: CursorVal { sort_type: SimpleSortMethod::ViewedUpdated, last_val }, filter } => {
- assert_eq!(id, "my-document-19");
+ let expected_uuid_str = Uuid::from_u128(19).to_string(); // "my-document-19" -> 19
+ assert_eq!(id, expected_uuid_str);
let date: DateTime<Utc> = Default::default();
assert_eq!(last_val, date);
assert!(filter.is_none());
@@ -590,7 +628,8 @@ async fn cursor_should_return_frecency() {
.returning(|params| {
let iter = (1..=params.limit).map(|v| {
AggregateFrecency::new_mock(
- EntityType::Document.with_entity_string(format!("doc-{v}")),
+ EntityType::Document
+ .with_entity_string(uuid::Uuid::from_u128(v as u128).to_string()),
v.into(),
)
});
@@ -604,7 +643,7 @@ async fn cursor_should_return_frecency() {
let vec = params
.entities
.iter()
- .map(|id| soup_document(id.entity_id.to_string()))
+ .map(|id| soup_document(&id.entity_id))
.map(SoupItem::Document)
.collect();
Box::pin(async move { Ok(vec) })
@@ -624,7 +663,8 @@ async fn cursor_should_return_frecency() {
let cursor_decoded = simple_cursor.next_cursor.unwrap().decode_json().unwrap();
assert_matches!(cursor_decoded, Cursor { id, limit: 100, val: CursorVal { sort_type: Frecency, last_val: FrecencyValue::FrecencyScore(1.0) }, filter } => {
// frecency sort is descending so the last item is id 1
- assert_eq!(id, "doc-1");
+ let expected_uuid_str = Uuid::from_u128(1).to_string();
+ assert_eq!(id, expected_uuid_str);
assert!(filter.is_none());
})
}
diff --git a/rust/cloud-storage/soup/src/outbound/pg_soup_repo.rs b/rust/cloud-storage/soup/src/outbound/pg_soup_repo.rs
index a3cfabe554..abba68b325 100644
--- a/rust/cloud-storage/soup/src/outbound/pg_soup_repo.rs
+++ b/rust/cloud-storage/soup/src/outbound/pg_soup_repo.rs
@@ -123,3 +123,92 @@ async fn not_implemented<Ok>(_req: SimpleSortRequest<'_>) -> Result<Ok, sqlx::Er
"Unexpanded soup ast filters are not yet supported".to_string(),
))
}
+
+/// utility fn for queries to create a sqlx err
+fn type_err<E: std::fmt::Display>(e: E) -> sqlx::Error {
+ sqlx::Error::TypeNotFound {
+ type_name: e.to_string(),
+ }
+}
+
+/// this defines a macro which maps the soup query types for statically checked soup queries
+/// This must be a macro because compile time queries cannot have a named type so we can't use a function
+#[macro_export]
+macro_rules! map_soup_type {
+ () => {
+ |r| match r.item_type.as_ref() {
+ "document" => Ok(::models_soup::item::SoupItem::Document(
+ ::models_soup::document::SoupDocument {
+ id: Uuid::parse_str(&r.id).map_err(type_err)?,
+ document_version_id: r
+ .document_version_id
+ .ok_or_else(|| type_err("document version id must exist"))
+ .and_then(|s| FromStr::from_str(&s).map_err(type_err))?,
+ owner_id: MacroUserIdStr::parse_from_str(&r.user_id)
+ .map_err(type_err)?
+ .into_owned(),
+ name: r.name,
+ file_type: r.file_type,
+ sha: r.sha,
+ project_id: r
+ .project_id
+ .as_deref()
+ .map(Uuid::parse_str)
+ .transpose()
+ .map_err(type_err)?,
+ branched_from_id: r
+ .branched_from_id
+ .as_deref()
+ .map(Uuid::parse_str)
+ .transpose()
+ .map_err(type_err)?,
+ branched_from_version_id: r.branched_from_version_id,
+ document_family_id: r.document_family_id,
+ created_at: r.created_at,
+ updated_at: r.updated_at,
+ viewed_at: r.viewed_at,
+ },
+ )),
+ "chat" => Ok(::models_soup::item::SoupItem::Chat(
+ ::models_soup::chat::SoupChat {
+ id: Uuid::parse_str(&r.id).map_err(type_err)?,
+ name: r.name,
+ owner_id: MacroUserIdStr::parse_from_str(&r.user_id)
+ .map_err(type_err)?
+ .into_owned(),
+ project_id: r
+ .project_id
+ .as_deref()
+ .map(Uuid::parse_str)
+ .transpose()
+ .map_err(type_err)?,
+ is_persistent: r.is_persistent.unwrap_or_default(),
+ created_at: r.created_at,
+ updated_at: r.updated_at,
+ viewed_at: r.viewed_at,
+ },
+ )),
+ "project" => Ok(::models_soup::item::SoupItem::Project(
+ ::models_soup::project::SoupProject {
+ id: Uuid::parse_str(&r.id).map_err(type_err)?,
+ name: r.name,
+ owner_id: MacroUserIdStr::parse_from_str(&r.user_id)
+ .map_err(type_err)?
+ .into_owned(),
+ parent_id: r
+ .project_id
+ .as_deref()
+ .map(Uuid::parse_str)
+ .transpose()
+ .map_err(type_err)?,
+ created_at: r.created_at,
+ updated_at: r.updated_at,
+ viewed_at: r.viewed_at,
+ },
+ )),
+ _ => Err(sqlx::Error::TypeNotFound {
+ type_name: r.item_type,
+ }),
+ }
+ };
+}
diff --git a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/by_cursor.rs b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/by_cursor.rs
index 17e35954dd..c67eb732e9 100644
--- a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/by_cursor.rs
+++ b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/by_cursor.rs
@@ -1,8 +1,12 @@
+use crate::map_soup_type;
+use crate::outbound::pg_soup_repo::type_err;
+use macro_user_id::cowlike::CowLike;
use macro_user_id::user_id::MacroUserIdStr;
use models_pagination::{Frecency, Query, SimpleSortMethod};
-use models_soup::project::map_soup_project;
-use models_soup::{chat::map_soup_chat, document::map_soup_document, item::SoupItem};
+use models_soup::item::SoupItem;
use sqlx::PgPool;
+use std::str::FromStr;
+use uuid::Uuid;
/// Returns objects that a user has EXPLICIT and IMPLICIT access to.
///
@@ -185,51 +189,7 @@ r#"
cursor_timestamp, // $4
cursor_id, // $5
)
- .try_map(|r| match r.item_type.as_ref() {
- "document" => {
- let document = map_soup_document(
- r.id,
- r.user_id,
- r.document_version_id,
- r.name,
- r.sha,
- r.file_type,
- r.document_family_id,
- r.branched_from_id,
- r.branched_from_version_id,
- r.project_id,
- r.created_at,
- r.updated_at,
- r.viewed_at,
- )
- .map_err(|e| sqlx::Error::TypeNotFound {
- type_name: e.to_string(),
- })?;
- Ok(SoupItem::Document(document))
- }
- "chat" => Ok(SoupItem::Chat(map_soup_chat(
- r.id,
- r.user_id,
- r.name,
- r.project_id,
- r.is_persistent,
- r.created_at,
- r.updated_at,
- r.viewed_at,
- ))),
- "project" => Ok(SoupItem::Project(map_soup_project(
- r.id,
- r.user_id,
- r.name,
- r.project_id,
- r.created_at,
- r.updated_at,
- r.viewed_at,
- ))),
- _ => Err(sqlx::Error::TypeNotFound {
- type_name: r.item_type,
- }),
- })
+ .try_map(map_soup_type!())
.fetch_all(db)
.await?;
@@ -418,51 +378,7 @@ r#"
cursor_timestamp, // $4
cursor_id, // $5
)
- .try_map(|r| match r.item_type.as_ref() {
- "document" => {
- let document = map_soup_document(
- r.id,
- r.user_id,
- r.document_version_id,
- r.name,
- r.sha,
- r.file_type,
- r.document_family_id,
- r.branched_from_id,
- r.branched_from_version_id,
- r.project_id,
- r.created_at,
- r.updated_at,
- r.viewed_at,
- )
- .map_err(|e| sqlx::Error::TypeNotFound {
- type_name: e.to_string(),
- })?;
- Ok(SoupItem::Document(document))
- }
- "chat" => Ok(SoupItem::Chat(map_soup_chat(
- r.id,
- r.user_id,
- r.name,
- r.project_id,
- r.is_persistent,
- r.created_at,
- r.updated_at,
- r.viewed_at,
- ))),
- "project" => Ok(SoupItem::Project(map_soup_project(
- r.id,
- r.user_id,
- r.name,
- r.project_id,
- r.created_at,
- r.updated_at,
- r.viewed_at,
- ))),
- _ => Err(sqlx::Error::TypeNotFound {
- type_name: r.item_type,
- }),
- })
+ .try_map(map_soup_type!())
.fetch_all(db)
.await?;
diff --git a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/by_ids.rs b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/by_ids.rs
index 7cf8ecdf14..06bc5f0894 100644
--- a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/by_ids.rs
+++ b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/by_ids.rs
@@ -1,7 +1,10 @@
-use macro_user_id::user_id::MacroUserIdStr;
+use crate::{map_soup_type, outbound::pg_soup_repo::type_err};
+use macro_user_id::{cowlike::CowLike, user_id::MacroUserIdStr};
use model_entity::{Entity, EntityType};
-use models_soup::{chat::map_soup_chat, document::map_soup_document, item::SoupItem};
+use models_soup::item::SoupItem;
use sqlx::PgPool;
+use std::str::FromStr;
+use uuid::Uuid;
/// Returns objects that a user has EXPLICIT and IMPLICIT access to by their IDs, excluding project items.
///
@@ -150,42 +153,7 @@ pub async fn expanded_soup_by_ids<'a>(
document_ids.as_slice(), // $2
chat_ids.as_slice(), // $3
)
- .try_map(|r| match r.item_type.as_ref() {
- "document" => {
- let document = map_soup_document(
- r.id,
- r.user_id,
- r.document_version_id,
- r.name,
- r.sha,
- r.file_type,
- r.document_family_id,
- r.branched_from_id,
- r.branched_from_version_id,
- r.project_id,
- r.created_at,
- r.updated_at,
- r.viewed_at,
- )
- .map_err(|e| sqlx::Error::TypeNotFound {
- type_name: e.to_string(),
- })?;
- Ok(SoupItem::Document(document))
- }
- "chat" => Ok(SoupItem::Chat(map_soup_chat(
- r.id,
- r.user_id,
- r.name,
- r.project_id,
- r.is_persistent,
- r.created_at,
- r.updated_at,
- r.viewed_at,
- ))),
- _ => Err(sqlx::Error::TypeNotFound {
- type_name: r.item_type,
- }),
- })
+ .try_map(map_soup_type!())
.fetch_all(db)
.await?;
diff --git a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/dynamic.rs b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/dynamic.rs
index 623e62284d..310f58d253 100644
--- a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/dynamic.rs
+++ b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/dynamic.rs
@@ -1,16 +1,21 @@
//! This module exposes a expanded dynamic query builder which is able to build specific soup queries
//! which filter out content basd on some input ast
+use std::str::FromStr;
+
use chrono::{DateTime, Utc};
use filter_ast::Expr;
use item_filters::ast::{
EntityFilterAst, chat::ChatLiteral, document::DocumentLiteral, project::ProjectLiteral,
};
-use macro_user_id::user_id::MacroUserIdStr;
+use macro_user_id::{cowlike::CowLike, user_id::MacroUserIdStr};
use models_pagination::{Query, SimpleSortMethod};
use models_soup::{chat::SoupChat, document::SoupDocument, item::SoupItem, project::SoupProject};
use recursion::CollapsibleExt;
use sqlx::{PgPool, Postgres, QueryBuilder, Row, postgres::PgRow, prelude::FromRow};
+use uuid::Uuid;
+
+use crate::outbound::pg_soup_repo::type_err;
static PREFIX: &str = r#"
WITH RECURSIVE ProjectHierarchy AS (
@@ -371,16 +376,26 @@ impl SoupRow {
updated_at,
viewed_at,
}) => SoupItem::Document(SoupDocument {
- id,
+ id: Uuid::parse_str(&id).map_err(type_err)?,
document_version_id: document_version_id
.parse()
.map_err(|e| sqlx::Error::Decode(Box::new(e)))?,
- owner_id: user_id,
+ owner_id: MacroUserIdStr::parse_from_str(&user_id)
+ .map_err(type_err)?
+ .into_owned(),
name,
file_type,
sha,
- project_id,
- branched_from_id,
+ project_id: project_id
+ .as_deref()
+ .map(Uuid::from_str)
+ .transpose()
+ .map_err(type_err)?,
+ branched_from_id: branched_from_id
+ .as_deref()
+ .map(Uuid::from_str)
+ .transpose()
+ .map_err(type_err)?,
branched_from_version_id,
document_family_id,
created_at,
@@ -397,10 +412,16 @@ impl SoupRow {
updated_at,
viewed_at,
}) => SoupItem::Chat(SoupChat {
- id,
+ id: Uuid::parse_str(&id).map_err(type_err)?,
name,
- owner_id: user_id,
- project_id,
+ owner_id: MacroUserIdStr::parse_from_str(&user_id)
+ .map_err(type_err)?
+ .into_owned(),
+ project_id: project_id
+ .as_deref()
+ .map(Uuid::parse_str)
+ .transpose()
+ .map_err(type_err)?,
is_persistent,
created_at,
updated_at,
@@ -415,10 +436,16 @@ impl SoupRow {
updated_at,
viewed_at,
}) => SoupItem::Project(SoupProject {
- id,
+ id: Uuid::parse_str(&id).map_err(type_err)?,
name,
- owner_id: user_id,
- parent_id: project_id,
+ owner_id: MacroUserIdStr::parse_from_str(&user_id)
+ .map_err(type_err)?
+ .into_owned(),
+ parent_id: project_id
+ .as_deref()
+ .map(Uuid::from_str)
+ .transpose()
+ .map_err(type_err)?,
created_at,
updated_at,
viewed_at,
diff --git a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/tests.rs b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/tests.rs
index d2e92f6850..7a57faa57f 100644
--- a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/tests.rs
+++ b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/tests.rs
@@ -11,6 +11,7 @@ use models_pagination::{Frecency, PaginateOn, Query, SimpleSortMethod};
use models_soup::item::SoupItem;
use sqlx::{PgPool, Pool, Postgres};
use std::collections::HashSet;
+use uuid::Uuid;
// 2 items have no viewing history, so they should be last in the response when sorting by viewed_at
#[sqlx::test(
@@ -33,32 +34,32 @@ async fn test_viewed_at_orders_nulls_last(pool: Pool<Postgres>) -> anyhow::Resul
assert_eq!(items.len(), 13, "Should get 13 total items");
// Make sure we got only the items with a history entry.
- let returned_ids: HashSet<String> = items
+ let returned_ids: HashSet<Uuid> = items
.iter()
.map(|item| match item {
- SoupItem::Chat(c) => c.id.clone(),
- SoupItem::Document(d) => d.id.clone(),
- SoupItem::Project(p) => p.id.clone(),
+ SoupItem::Chat(c) => c.id,
+ SoupItem::Document(d) => d.id,
+ SoupItem::Project(p) => p.id,
})
.collect();
- let expected_ids: HashSet<String> = [
- "chat-standalone",
- "doc-in-B",
- "doc-in-D",
- "project-C",
- "project-D",
- "doc-in-C",
- "chat-in-B",
- "project-A",
- "chat-in-A",
- "doc-standalone",
- "chat-in-C",
- "project-B",
- "doc-in-A",
+ let expected_ids: HashSet<Uuid> = [
+ "22222222-0000-0000-0000-000000000000", // chat-standalone
+ "11111111-bbbb-bbbb-bbbb-bbbbbbbbbbbb", // doc-in-B
+ "11111111-dddd-dddd-dddd-dddddddddddd", // doc-in-D
+ "cccccccc-ffff-ffff-ffff-ffffffffffff", // project-C
+ "dddddddd-ffff-ffff-ffff-ffffffffffff", // project-D
+ "11111111-cccc-cccc-cccc-cccccccccccc", // doc-in-C
+ "22222222-bbbb-bbbb-bbbb-bbbbbbbbbbbb", // chat-in-B
+ "aaaaaaaa-ffff-ffff-ffff-ffffffffffff", // project-A
+ "22222222-aaaa-aaaa-aaaa-aaaaaaaaaaaa", // chat-in-A
+ "11111111-0000-0000-0000-000000000000", // doc-standalone
+ "22222222-cccc-cccc-cccc-cccccccccccc", // chat-in-C
+ "bbbbbbbb-ffff-ffff-ffff-ffffffffffff", // project-B
+ "11111111-aaaa-aaaa-aaaa-aaaaaaaaaaaa", // doc-in-A
]
.iter()
- .map(|&s| s.to_string())
+ .map(|&s| Uuid::parse_str(s).unwrap())
.collect();
assert_eq!(
@@ -67,29 +68,29 @@ async fn test_viewed_at_orders_nulls_last(pool: Pool<Postgres>) -> anyhow::Resul
);
// Check that items are ordered by their UserHistory.updatedAt timestamp.
- let ordered_ids: Vec<&str> = items
+ let ordered_ids: Vec<Uuid> = items
.iter()
.map(|item| match item {
- SoupItem::Chat(c) => c.id.as_str(),
- SoupItem::Document(d) => d.id.as_str(),
- SoupItem::Project(p) => p.id.as_str(),
+ SoupItem::Chat(c) => c.id,
+ SoupItem::Document(d) => d.id,
+ SoupItem::Project(p) => p.id,
})
.collect();
- let expected_order = vec![
- "doc-in-B", // 2024-01-10
- "chat-standalone", // 2024-01-09
- "doc-in-A", // 2024-01-08
- "chat-in-A", // 2024-01-07
- "doc-standalone", // 2024-01-06
- "doc-in-D", // 2023-01-05
- "chat-in-C", // 2023-01-04
- "chat-in-B", // null - coalesces to epoch in query, then sorts by updated_at
- "doc-in-C", // null - coalesces to epoch in query, then sorts by updated_at
- "project-D", // null - coalesces to epoch in query, then sorts by updated_at
- "project-C", // null - coalesces to epoch in query, then sorts by updated_at
- "project-B", // null - coalesces to epoch in query, then sorts by updated_at
- "project-A", // null - coalesces to epoch in query, then sorts by updated_at
+ let expected_order: Vec<Uuid> = vec![
+ Uuid::parse_str("11111111-bbbb-bbbb-bbbb-bbbbbbbbbbbb").unwrap(), // doc-in-B - 2024-01-10
+ Uuid::parse_str("22222222-0000-0000-0000-000000000000").unwrap(), // chat-standalone - 2024-01-09
+ Uuid::parse_str("11111111-aaaa-aaaa-aaaa-aaaaaaaaaaaa").unwrap(), // doc-in-A - 2024-01-08
+ Uuid::parse_str("22222222-aaaa-aaaa-aaaa-aaaaaaaaaaaa").unwrap(), // chat-in-A - 2024-01-07
+ Uuid::parse_str("11111111-0000-0000-0000-000000000000").unwrap(), // doc-standalone - 2024-01-06
+ Uuid::parse_str("11111111-dddd-dddd-dddd-dddddddddddd").unwrap(), // doc-in-D - 2023-01-05
+ Uuid::parse_str("22222222-cccc-cccc-cccc-cccccccccccc").unwrap(), // chat-in-C - 2023-01-04
+ Uuid::parse_str("22222222-bbbb-bbbb-bbbb-bbbbbbbbbbbb").unwrap(), // chat-in-B - null
+ Uuid::parse_str("11111111-cccc-cccc-cccc-cccccccccccc").unwrap(), // doc-in-C - null
+ Uuid::parse_str("dddddddd-ffff-ffff-ffff-ffffffffffff").unwrap(), // project-D - null
+ Uuid::parse_str("cccccccc-ffff-ffff-ffff-ffffffffffff").unwrap(), // project-C - null
+ Uuid::parse_str("bbbbbbbb-ffff-ffff-ffff-ffffffffffff").unwrap(), // project-B - null
+ Uuid::parse_str("aaaaaaaa-ffff-ffff-ffff-ffffffffffff").unwrap(), // project-A - null
];
assert_eq!(
ordered_ids, expected_order,
@@ -97,14 +98,14 @@ async fn test_viewed_at_orders_nulls_last(pool: Pool<Postgres>) -> anyhow::Resul
);
// Map for easier lookup when checking item details
- let items_map: std::collections::HashMap<&str, &SoupItem> = items
+ let items_map: std::collections::HashMap<Uuid, &SoupItem> = items
.iter()
.map(|item| {
(
match item {
- SoupItem::Chat(c) => c.id.as_str(),
- SoupItem::Document(d) => d.id.as_str(),
- SoupItem::Project(p) => p.id.as_str(),
+ SoupItem::Chat(c) => c.id,
+ SoupItem::Document(d) => d.id,
+ SoupItem::Project(p) => p.id,
},
item,
)
@@ -112,7 +113,8 @@ async fn test_viewed_at_orders_nulls_last(pool: Pool<Postgres>) -> anyhow::Resul
.collect();
// Check a standalone item that is still present
- if let Some(SoupItem::Chat(chat)) = items_map.get("chat-standalone") {
+ let chat_uuid = Uuid::parse_str("22222222-0000-0000-0000-000000000000").unwrap(); // chat-standalone
+ if let Some(SoupItem::Chat(chat)) = items_map.get(&chat_uuid) {
assert_eq!(chat.name, "Standalone Chat");
assert_eq!(chat.project_id, None, "Standalone shouldn't have project");
} else {
@@ -120,11 +122,12 @@ async fn test_viewed_at_orders_nulls_last(pool: Pool<Postgres>) -> anyhow::Resul
}
// Check an item with both inherited and direct access that is still present
- if let Some(SoupItem::Document(doc)) = items_map.get("doc-in-B") {
+ let doc_uuid = Uuid::parse_str("11111111-bbbb-bbbb-bbbb-bbbbbbbbbbbb").unwrap(); // doc-in-B
+ if let Some(SoupItem::Document(doc)) = items_map.get(&doc_uuid) {
assert_eq!(doc.name, "Document in B");
assert_eq!(
- doc.project_id.as_deref(),
- Some("project-B"),
+ doc.project_id.as_ref(),
+ Some(&Uuid::parse_str("bbbbbbbb-ffff-ffff-ffff-ffffffffffff").unwrap()), // project-B
"Wrong project on mixed access doc"
);
} else {
@@ -160,9 +163,10 @@ async fn test_get_user_items_expanded_cursor(pool: Pool<Postgres>) -> anyhow::Re
match &items[0] {
SoupItem::Document(doc) => {
+ let expected_uuid = Uuid::parse_str("11111111-bbbb-bbbb-bbbb-bbbbbbbbbbbb").unwrap(); // doc-in-B
assert_eq!(
- doc.id, "doc-in-B",
- "First item should be document with ID test-document"
+ doc.id, expected_uuid,
+ "First item should be document with ID doc-in-B"
);
}
_ => panic!("First item should be a document"),
@@ -173,7 +177,15 @@ async fn test_get_user_items_expanded_cursor(pool: Pool<Postgres>) -> anyhow::Re
user_id.copied(),
1,
Query::new(
- result.next_cursor.map(|s| s.decode_json().unwrap()),
+ result.next_cursor.map(|s| {
+ let decoded = s.decode_json().unwrap();
+ models_pagination::Cursor {
+ id: decoded.id.to_string(),
+ limit: decoded.limit,
+ val: decoded.val,
+ filter: decoded.filter,
+ }
+ }),
SimpleSortMethod::ViewedAt,
(),
),
@@ -184,9 +196,10 @@ async fn test_get_user_items_expanded_cursor(pool: Pool<Postgres>) -> anyhow::Re
match &items[0] {
SoupItem::Chat(chat) => {
+ let expected_uuid = Uuid::parse_str("22222222-0000-0000-0000-000000000000").unwrap(); // chat-standalone
assert_eq!(
- chat.id, "chat-standalone",
- "Second item should be chat with ID test-chat"
+ chat.id, expected_uuid,
+ "Second item should be chat with ID chat-standalone"
);
}
_ => panic!("Second item should be a chat"),
@@ -207,13 +220,13 @@ async fn test_expanded_generic_sorting_methods(pool: Pool<Postgres>) -> anyhow::
let user_id = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
// --- Helper to extract IDs for easy comparison ---
- let get_item_ids = |items: &[SoupItem]| -> Vec<String> {
+ let get_item_ids = |items: &[SoupItem]| -> Vec<Uuid> {
items
.iter()
.map(|item| match item {
- SoupItem::Document(d) => d.id.clone(),
- SoupItem::Chat(c) => c.id.clone(),
- SoupItem::Project(p) => p.id.clone(),
+ SoupItem::Document(d) => d.id,
+ SoupItem::Chat(c) => c.id,
+ SoupItem::Project(p) => p.id,
})
.collect()
};
@@ -235,16 +248,19 @@ async fn test_expanded_generic_sorting_methods(pool: Pool<Postgres>) -> anyhow::
);
let item_ids = get_item_ids(&items);
+ let expected_ids: Vec<Uuid> = vec![
+ "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", // doc-A
+ "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb", // doc-B
+ "aaaaaaaa-cccc-cccc-cccc-cccccccccccc", // chat-A
+ "bbbbbbbb-cccc-cccc-cccc-cccccccccccc", // chat-B
+ "bbbbbbbb-ffff-ffff-ffff-ffffffffffff", // project-B
+ "aaaaaaaa-ffff-ffff-ffff-ffffffffffff", // project-A
+ ]
+ .iter()
+ .map(|&s| Uuid::parse_str(s).unwrap())
+ .collect();
assert_eq!(
- item_ids,
- vec![
- "doc-A",
- "doc-B",
- "chat-A",
- "chat-B",
- "project-B",
- "project-A"
- ],
+ item_ids, expected_ids,
"Failed to sort correctly by LastViewed"
);
}
@@ -262,16 +278,19 @@ async fn test_expanded_generic_sorting_methods(pool: Pool<Postgres>) -> anyhow::
assert_eq!(items.len(), 6, "UpdatedAt should return all 6 items");
let item_ids = get_item_ids(&items);
+ let expected_ids: Vec<Uuid> = vec![
+ "aaaaaaaa-cccc-cccc-cccc-cccccccccccc", // chat-A
+ "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", // doc-A
+ "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb", // doc-B
+ "bbbbbbbb-cccc-cccc-cccc-cccccccccccc", // chat-B
+ "bbbbbbbb-ffff-ffff-ffff-ffffffffffff", // project-B
+ "aaaaaaaa-ffff-ffff-ffff-ffffffffffff", // project-A
+ ]
+ .iter()
+ .map(|&s| Uuid::parse_str(s).unwrap())
+ .collect();
assert_eq!(
- item_ids,
- vec![
- "chat-A",
- "doc-A",
- "doc-B",
- "chat-B",
- "project-B",
- "project-A"
- ],
+ item_ids, expected_ids,
"Failed to sort correctly by UpdatedAt"
);
}
@@ -289,16 +308,19 @@ async fn test_expanded_generic_sorting_methods(pool: Pool<Postgres>) -> anyhow::
assert_eq!(items.len(), 6, "CreatedAt should return all 6 items");
let item_ids = get_item_ids(&items);
+ let expected_ids: Vec<Uuid> = vec![
+ "bbbbbbbb-cccc-cccc-cccc-cccccccccccc", // chat-B
+ "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb", // doc-B
+ "aaaaaaaa-cccc-cccc-cccc-cccccccccccc", // chat-A
+ "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", // doc-A
+ "bbbbbbbb-ffff-ffff-ffff-ffffffffffff", // project-B
+ "aaaaaaaa-ffff-ffff-ffff-ffffffffffff", // project-A
+ ]
+ .iter()
+ .map(|&s| Uuid::parse_str(s).unwrap())
+ .collect();
assert_eq!(
- item_ids,
- vec![
- "chat-B",
- "doc-B",
- "chat-A",
- "doc-A",
- "project-B",
- "project-A"
- ],
+ item_ids, expected_ids,
"Failed to sort correctly by CreatedAt"
);
}
@@ -319,11 +341,11 @@ async fn test_expanded_soup_by_ids(pool: Pool<Postgres>) {
// Request specific items, including some we have implicit access to through projects
let entities = [
- EntityType::Document.with_entity_str("doc-in-A"),
- EntityType::Chat.with_entity_str("chat-in-B"),
- EntityType::Document.with_entity_str("doc-standalone"),
- EntityType::Chat.with_entity_str("chat-standalone"),
- EntityType::Project.with_entity_str("project-A"), // Should be ignored in expanded soup
+ EntityType::Document.with_entity_str("11111111-aaaa-aaaa-aaaa-aaaaaaaaaaaa"), // doc-in-A
+ EntityType::Chat.with_entity_str("22222222-bbbb-bbbb-bbbb-bbbbbbbbbbbb"), // chat-in-B
+ EntityType::Document.with_entity_str("11111111-0000-0000-0000-000000000000"), // doc-standalone
+ EntityType::Chat.with_entity_str("22222222-0000-0000-0000-000000000000"), // chat-standalone
+ EntityType::Project.with_entity_str("aaaaaaaa-ffff-ffff-ffff-ffffffffffff"), // project-A - Should be ignored in expanded soup
];
let items = expanded_soup_by_ids(&pool, user_id, &entities)
@@ -342,9 +364,11 @@ async fn test_expanded_soup_by_ids(pool: Pool<Postgres>) {
SoupItem::Chat(_) | SoupItem::Project(_) => None,
})
.expect("The document should exist");
- assert_eq!(doc.id, "doc-in-A");
+ let expected_doc_id = Uuid::parse_str("11111111-aaaa-aaaa-aaaa-aaaaaaaaaaaa").unwrap(); // doc-in-A
+ let expected_project_id = Uuid::parse_str("aaaaaaaa-ffff-ffff-ffff-ffffffffffff").unwrap(); // project-A
+ assert_eq!(doc.id, expected_doc_id);
assert_eq!(doc.name, "Document in A");
- assert_eq!(doc.project_id.as_deref(), Some("project-A"));
+ assert_eq!(doc.project_id, Some(expected_project_id));
// chat-in-B is in project-B which is a child of project-A
let chat = items
@@ -354,9 +378,11 @@ async fn test_expanded_soup_by_ids(pool: Pool<Postgres>) {
SoupItem::Document(_) | SoupItem::Project(_) => None,
})
.expect("The chat should exist");
- assert_eq!(chat.id, "chat-in-B");
+ let expected_chat_id = Uuid::parse_str("22222222-bbbb-bbbb-bbbb-bbbbbbbbbbbb").unwrap(); // chat-in-B
+ let expected_project_id = Uuid::parse_str("bbbbbbbb-ffff-ffff-ffff-ffffffffffff").unwrap(); // project-B
+ assert_eq!(chat.id, expected_chat_id);
assert_eq!(chat.name, "Chat in B");
- assert_eq!(chat.project_id.as_deref(), Some("project-B"));
+ assert_eq!(chat.project_id.as_ref(), Some(&expected_project_id));
}
#[sqlx::test(
@@ -370,8 +396,8 @@ async fn it_should_be_empty(pool: Pool<Postgres>) {
let user_id = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
// Test with non-existent items
let non_existent_entities = [
- EntityType::Document.with_entity_str("non-existent-doc"),
- EntityType::Chat.with_entity_str("non-existent-chat"),
+ EntityType::Document.with_entity_str("00000000-0000-0000-0000-000000000000"), // non-existent-doc
+ EntityType::Chat.with_entity_str("00000000-0000-0000-000000000001"), // non-existent-chat
];
let empty_result = expanded_soup_by_ids(&pool, user_id.copied(), &non_existent_entities)
@@ -385,8 +411,8 @@ async fn it_should_be_empty(pool: Pool<Postgres>) {
// Test with only projects (should return empty)
let project_only_entities = [
- EntityType::Project.with_entity_str("project-A"),
- EntityType::Project.with_entity_str("project-B"),
+ EntityType::Project.with_entity_str("aaaaaaaa-ffff-ffff-ffff-ffffffffffff"), // project-A
+ EntityType::Project.with_entity_str("bbbbbbbb-ffff-ffff-ffff-ffffffffffff"), // project-B
];
let project_result = expanded_soup_by_ids(&pool, user_id, &project_only_entities)
@@ -429,24 +455,24 @@ async fn test_no_frecency_expanded_filters_out_frecency_items(
);
// Verify the returned items are the ones WITHOUT frecency
- let returned_ids: HashSet<String> = items
+ let returned_ids: HashSet<Uuid> = items
.iter()
.map(|item| match item {
- SoupItem::Chat(c) => c.id.clone(),
- SoupItem::Document(d) => d.id.clone(),
- SoupItem::Project(p) => p.id.clone(),
+ SoupItem::Chat(c) => c.id,
+ SoupItem::Document(d) => d.id,
+ SoupItem::Project(p) => p.id,
})
.collect();
- let expected_ids: HashSet<String> = [
+ let expected_ids: HashSet<Uuid> = [
"44444444-4444-4444-4444-444444444444", // doc-no-frecency-1
"55555555-5555-5555-5555-555555555555", // doc-no-frecency-2
- "88888888-8888-8888-8888-888888888888", // chat-no-frecency-1
- "99999999-9999-9999-9999-999999999999", // chat-no-frecency-2
- "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", // project-A
+ "66666666-6666-6666-6666-666666666666", // chat-no-frecency-1
+ "77777777-7777-7777-7777-777777777777", // chat-no-frecency-2
+ "88888888-8888-8888-8888-888888888888", // project-no-frecency
]
.iter()
- .map(|&s| s.to_string())
+ .map(|&s| Uuid::parse_str(s).unwrap())
.collect();
assert_eq!(
@@ -456,15 +482,14 @@ async fn test_no_frecency_expanded_filters_out_frecency_items(
// Verify none of the frecency items are returned
let frecency_items = [
- "11111111-1111-1111-1111-111111111111", // doc-with-frecency-1
- "22222222-2222-2222-2222-222222222222", // doc-with-frecency-2
- "33333333-3333-3333-3333-333333333333", // doc-with-frecency-3
- "66666666-6666-6666-6666-666666666666", // chat-with-frecency-1
- "77777777-7777-7777-7777-777777777777", // chat-with-frecency-2
+ Uuid::parse_str("44444444-ffff-ffff-ffff-ffffffffffff").unwrap(), // doc-with-frecency-1
+ Uuid::parse_str("55555555-ffff-ffff-ffff-ffffffffffff").unwrap(), // doc-with-frecency-2
+ Uuid::parse_str("66666666-ffff-ffff-ffff-ffffffffffff").unwrap(), // chat-with-frecency-1
+ Uuid::parse_str("88888888-ffff-ffff-ffff-ffffffffffff").unwrap(), // project-with-frecency
];
for frecency_id in &frecency_items {
assert!(
- !returned_ids.contains(*frecency_id),
+ !returned_ids.contains(frecency_id),
"Should not return item with frecency: {}",
frecency_id
);
@@ -484,13 +509,13 @@ async fn test_no_frecency_expanded_filters_out_frecency_items(
async fn test_no_frecency_expanded_sorting_methods(pool: Pool<Postgres>) -> anyhow::Result<()> {
let user_id = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
- let get_item_ids = |items: &[SoupItem]| -> Vec<String> {
+ let get_item_ids = |items: &[SoupItem]| -> Vec<Uuid> {
items
.iter()
.map(|item| match item {
- SoupItem::Document(d) => d.id.clone(),
- SoupItem::Chat(c) => c.id.clone(),
- SoupItem::Project(p) => p.id.clone(),
+ SoupItem::Document(d) => d.id,
+ SoupItem::Chat(c) => c.id,
+ SoupItem::Project(p) => p.id,
})
.collect()
};
@@ -508,16 +533,16 @@ async fn test_no_frecency_expanded_sorting_methods(pool: Pool<Postgres>) -> anyh
let item_ids = get_item_ids(&items);
// Ordered by updatedAt DESC: doc-no-frecency-1 (2/12), doc-no-frecency-2 (2/11),
- // chat-no-frecency-1 (2/08), chat-no-frecency-2 (2/07), project-A (1/01)
+ // chat-no-frecency-1 (2/08), chat-no-frecency-2 (2/07), project-no-frecency (1/01)
+ let expected_ids = vec![
+ Uuid::parse_str("44444444-4444-4444-4444-444444444444").unwrap(), // doc-no-frecency-1
+ Uuid::parse_str("55555555-5555-5555-5555-555555555555").unwrap(), // doc-no-frecency-2
+ Uuid::parse_str("66666666-6666-6666-6666-666666666666").unwrap(), // chat-no-frecency-1
+ Uuid::parse_str("77777777-7777-7777-7777-777777777777").unwrap(), // chat-no-frecency-2
+ Uuid::parse_str("88888888-8888-8888-8888-888888888888").unwrap(), // project-no-frecency
+ ];
assert_eq!(
- item_ids,
- vec![
- "44444444-4444-4444-4444-444444444444", // doc-no-frecency-1
- "55555555-5555-5555-5555-555555555555", // doc-no-frecency-2
- "88888888-8888-8888-8888-888888888888", // chat-no-frecency-1
- "99999999-9999-9999-9999-999999999999", // chat-no-frecency-2
- "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", // project-A
- ],
+ item_ids, expected_ids,
"Failed to sort correctly by UpdatedAt"
);
}
@@ -535,16 +560,16 @@ async fn test_no_frecency_expanded_sorting_methods(pool: Pool<Postgres>) -> anyh
let item_ids = get_item_ids(&items);
// Ordered by createdAt DESC: chat-no-frecency-2 (1/18), chat-no-frecency-1 (1/17),
- // doc-no-frecency-2 (1/14), doc-no-frecency-1 (1/13), project-A (1/01)
+ // doc-no-frecency-2 (1/14), doc-no-frecency-1 (1/13), project-no-frecency (1/01)
+ let expected_ids = vec![
+ Uuid::parse_str("77777777-7777-7777-7777-777777777777").unwrap(), // chat-no-frecency-2
+ Uuid::parse_str("66666666-6666-6666-6666-666666666666").unwrap(), // chat-no-frecency-1
+ Uuid::parse_str("55555555-5555-5555-5555-555555555555").unwrap(), // doc-no-frecency-2
+ Uuid::parse_str("44444444-4444-4444-4444-444444444444").unwrap(), // doc-no-frecency-1
+ Uuid::parse_str("88888888-8888-8888-8888-888888888888").unwrap(), // project-no-frecency
+ ];
assert_eq!(
- item_ids,
- vec![
- "99999999-9999-9999-9999-999999999999", // chat-no-frecency-2
- "88888888-8888-8888-8888-888888888888", // chat-no-frecency-1
- "55555555-5555-5555-5555-555555555555", // doc-no-frecency-2
- "44444444-4444-4444-4444-444444444444", // doc-no-frecency-1
- "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", // project-A
- ],
+ item_ids, expected_ids,
"Failed to sort correctly by CreatedAt"
);
}
@@ -561,17 +586,17 @@ async fn test_no_frecency_expanded_sorting_methods(pool: Pool<Postgres>) -> anyh
assert_eq!(items.len(), 5, "ViewedAt should return 5 items");
let item_ids = get_item_ids(&items);
- // Ordered by UserHistory.updatedAt DESC: doc-no-frecency-1 (3/15), doc-no-frecency-2 (3/14),
- // chat-no-frecency-1 (3/13), chat-no-frecency-2 (3/12), project-A (no history - coalesces to epoch)
+ // Ordered by UserHistory.updatedAt DESC: doc-no-frecency-1 (3/17), doc-no-frecency-2 (3/16),
+ // chat-no-frecency-1 (3/15), chat-no-frecency-2 (3/14), project-no-frecency (3/13)
+ let expected_ids = vec![
+ Uuid::parse_str("44444444-4444-4444-4444-444444444444").unwrap(), // doc-no-frecency-1
+ Uuid::parse_str("55555555-5555-5555-5555-555555555555").unwrap(), // doc-no-frecency-2
+ Uuid::parse_str("66666666-6666-6666-6666-666666666666").unwrap(), // chat-no-frecency-1
+ Uuid::parse_str("77777777-7777-7777-7777-777777777777").unwrap(), // chat-no-frecency-2
+ Uuid::parse_str("88888888-8888-8888-8888-888888888888").unwrap(), // project-no-frecency
+ ];
assert_eq!(
- item_ids,
- vec![
- "44444444-4444-4444-4444-444444444444", // doc-no-frecency-1
- "55555555-5555-5555-5555-555555555555", // doc-no-frecency-2
- "88888888-8888-8888-8888-888888888888", // chat-no-frecency-1
- "99999999-9999-9999-9999-999999999999", // chat-no-frecency-2
- "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", // project-A
- ],
+ item_ids, expected_ids,
"Failed to sort correctly by ViewedAt"
);
}
@@ -609,7 +634,8 @@ async fn test_no_frecency_expanded_cursor_pagination(pool: Pool<Postgres>) -> an
match &result.items[0] {
SoupItem::Document(doc) => {
assert_eq!(
- doc.id, "44444444-4444-4444-4444-444444444444",
+ doc.id,
+ Uuid::parse_str("44444444-4444-4444-4444-444444444444").unwrap(),
"First item should be doc-no-frecency-1"
);
}
@@ -619,7 +645,8 @@ async fn test_no_frecency_expanded_cursor_pagination(pool: Pool<Postgres>) -> an
match &result.items[1] {
SoupItem::Document(doc) => {
assert_eq!(
- doc.id, "55555555-5555-5555-5555-555555555555",
+ doc.id,
+ Uuid::parse_str("55555555-5555-5555-5555-555555555555").unwrap(),
"Second item should be doc-no-frecency-2"
);
}
@@ -632,7 +659,15 @@ async fn test_no_frecency_expanded_cursor_pagination(pool: Pool<Postgres>) -> an
user_id.copied(),
2,
Query::new(
- result.next_cursor.map(|s| s.decode_json().unwrap()),
+ result.next_cursor.map(|s| {
+ let decoded = s.decode_json().unwrap();
+ models_pagination::Cursor {
+ id: decoded.id.to_string(),
+ limit: decoded.limit,
+ val: decoded.val,
+ filter: decoded.filter,
+ }
+ }),
SimpleSortMethod::UpdatedAt,
Frecency,
),
@@ -645,7 +680,8 @@ async fn test_no_frecency_expanded_cursor_pagination(pool: Pool<Postgres>) -> an
match &items[0] {
SoupItem::Chat(chat) => {
assert_eq!(
- chat.id, "88888888-8888-8888-8888-888888888888",
+ chat.id,
+ Uuid::parse_str("66666666-6666-6666-6666-666666666666").unwrap(),
"Third item should be chat-no-frecency-1"
);
}
@@ -655,7 +691,8 @@ async fn test_no_frecency_expanded_cursor_pagination(pool: Pool<Postgres>) -> an
match &items[1] {
SoupItem::Chat(chat) => {
assert_eq!(
- chat.id, "99999999-9999-9999-9999-999999999999",
+ chat.id,
+ Uuid::parse_str("77777777-7777-7777-7777-777777777777").unwrap(),
"Fourth item should be chat-no-frecency-2"
);
}
@@ -695,21 +732,21 @@ async fn empty_ast_returns_same_as_static_query(db: PgPool) {
.unwrap();
// Compare the IDs since SoupItem doesn't implement PartialEq
- let ast_ids: Vec<String> = ast_res
+ let ast_ids: Vec<Uuid> = ast_res
.iter()
.map(|item| match item {
- SoupItem::Chat(c) => c.id.clone(),
- SoupItem::Document(d) => d.id.clone(),
- SoupItem::Project(p) => p.id.clone(),
+ SoupItem::Chat(c) => c.id,
+ SoupItem::Document(d) => d.id,
+ SoupItem::Project(p) => p.id,
})
.collect();
- let static_ids: Vec<String> = static_res
+ let static_ids: Vec<Uuid> = static_res
.iter()
.map(|item| match item {
- SoupItem::Chat(c) => c.id.clone(),
- SoupItem::Document(d) => d.id.clone(),
- SoupItem::Project(p) => p.id.clone(),
+ SoupItem::Chat(c) => c.id,
+ SoupItem::Document(d) => d.id,
+ SoupItem::Project(p) => p.id,
})
.collect();
@@ -828,14 +865,14 @@ async fn test_filter_by_document_ids(db: PgPool) -> anyhow::Result<()> {
.await?;
// Should get 2 documents (filtered), all chats, and all projects
- let mut document_ids: HashSet<String> = HashSet::new();
+ let mut document_ids: HashSet<Uuid> = HashSet::new();
let mut chat_count = 0;
let mut project_count = 0;
for item in &items {
match item {
SoupItem::Document(d) => {
- document_ids.insert(d.id.clone());
+ document_ids.insert(d.id);
}
SoupItem::Chat(_) => {
chat_count += 1;
@@ -852,12 +889,12 @@ async fn test_filter_by_document_ids(db: PgPool) -> anyhow::Result<()> {
let returned_ids = document_ids;
- let expected_ids: HashSet<String> = [
+ let expected_ids: HashSet<Uuid> = [
"aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
"eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee",
]
.iter()
- .map(|&s| s.to_string())
+ .map(|&s| Uuid::parse_str(s).unwrap())
.collect();
assert_eq!(
@@ -913,10 +950,10 @@ async fn test_filter_documents_by_project_id(db: PgPool) -> anyhow::Result<()> {
match item {
SoupItem::Document(doc) => {
assert_eq!(
- doc.project_id.as_deref(),
- Some("11111111-1111-1111-1111-111111111111")
+ doc.project_id.as_ref(),
+ Some(&Uuid::parse_str("11111111-1111-1111-1111-111111111111").unwrap())
);
- found_doc_id = Some(doc.id.clone());
+ found_doc_id = Some(doc.id);
doc_count += 1;
}
SoupItem::Chat(_) => {
@@ -930,8 +967,8 @@ async fn test_filter_documents_by_project_id(db: PgPool) -> anyhow::Result<()> {
assert_eq!(doc_count, 1, "Should get 1 document in project-A");
assert_eq!(
- found_doc_id.as_deref(),
- Some("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa")
+ found_doc_id.as_ref(),
+ Some(&Uuid::parse_str("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa").unwrap())
);
assert_eq!(chat_count, 4, "Should get all chats");
assert_eq!(project_count, 4, "Should get all projects");
@@ -987,10 +1024,10 @@ async fn test_filter_chats_by_project_id(db: PgPool) -> anyhow::Result<()> {
}
SoupItem::Chat(chat) => {
assert_eq!(
- chat.project_id.as_deref(),
- Some("22222222-2222-2222-2222-222222222222")
+ chat.project_id.as_ref(),
+ Some(&Uuid::parse_str("22222222-2222-2222-2222-222222222222").unwrap())
);
- found_chat_id = Some(chat.id.clone());
+ found_chat_id = Some(chat.id);
chat_count += 1;
}
SoupItem::Project(_) => {
@@ -1001,8 +1038,8 @@ async fn test_filter_chats_by_project_id(db: PgPool) -> anyhow::Result<()> {
assert_eq!(chat_count, 1, "Should get 1 chat in project-B");
assert_eq!(
- found_chat_id.as_deref(),
- Some("b2b2b2b2-b2b2-b2b2-b2b2-b2b2b2b2b2b2")
+ found_chat_id.as_ref(),
+ Some(&Uuid::parse_str("b2b2b2b2-b2b2-b2b2-b2b2-b2b2b2b2b2b2").unwrap())
);
assert_eq!(doc_count, 5, "Should get all documents");
assert_eq!(project_count, 4, "Should get all projects");
@@ -1049,14 +1086,14 @@ async fn test_filter_by_chat_ids(db: PgPool) -> anyhow::Result<()> {
.await?;
// Should get 2 chats (filtered), all documents, and all projects
- let mut chat_ids: HashSet<String> = HashSet::new();
+ let mut chat_ids: HashSet<Uuid> = HashSet::new();
let mut doc_count = 0;
let mut project_count = 0;
for item in &items {
match item {
SoupItem::Chat(c) => {
- chat_ids.insert(c.id.clone());
+ chat_ids.insert(c.id);
}
SoupItem::Document(_) => {
doc_count += 1;
@@ -1073,12 +1110,12 @@ async fn test_filter_by_chat_ids(db: PgPool) -> anyhow::Result<()> {
let returned_ids = chat_ids;
- let expected_ids: HashSet<String> = [
+ let expected_ids: HashSet<Uuid> = [
"a1a1a1a1-a1a1-a1a1-a1a1-a1a1a1a1a1a1",
"d4d4d4d4-d4d4-d4d4-d4d4-d4d4d4d4d4d4",
]
.iter()
- .map(|&s| s.to_string())
+ .map(|&s| Uuid::parse_str(s).unwrap())
.collect();
assert_eq!(returned_ids, expected_ids, "Should get the correct chats");
@@ -1125,14 +1162,14 @@ async fn test_filter_by_project_ids(db: PgPool) -> anyhow::Result<()> {
.await?;
// Should get 2 projects (filtered), all documents, and all chats
- let mut project_ids: HashSet<String> = HashSet::new();
+ let mut project_ids: HashSet<Uuid> = HashSet::new();
let mut doc_count = 0;
let mut chat_count = 0;
for item in &items {
match item {
SoupItem::Project(p) => {
- project_ids.insert(p.id.clone());
+ project_ids.insert(p.id);
}
SoupItem::Document(_) => {
doc_count += 1;
@@ -1149,12 +1186,12 @@ async fn test_filter_by_project_ids(db: PgPool) -> anyhow::Result<()> {
let returned_ids = project_ids;
- let expected_ids: HashSet<String> = [
+ let expected_ids: HashSet<Uuid> = [
"11111111-1111-1111-1111-111111111111",
"44444444-4444-4444-4444-444444444444",
]
.iter()
- .map(|&s| s.to_string())
+ .map(|&s| Uuid::parse_str(s).unwrap())
.collect();
assert_eq!(
@@ -1225,23 +1262,26 @@ async fn test_combined_entity_filters(db: PgPool) -> anyhow::Result<()> {
match item {
SoupItem::Document(doc) => {
doc_count += 1;
+ let doc_a = Uuid::parse_str("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa").unwrap();
+ let doc_b = Uuid::parse_str("bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb").unwrap();
assert!(
- doc.id == "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
- || doc.id == "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
+ doc.id == doc_a || doc.id == doc_b,
"Document should be in project-A or project-B"
);
}
SoupItem::Chat(chat) => {
chat_count += 1;
assert_eq!(
- chat.id, "d4d4d4d4-d4d4-d4d4-d4d4-d4d4d4d4d4d4",
+ chat.id,
+ Uuid::parse_str("d4d4d4d4-d4d4-d4d4-d4d4-d4d4d4d4d4d4").unwrap(),
"Should only get standalone chat"
);
}
SoupItem::Project(project) => {
project_count += 1;
assert_eq!(
- project.id, "44444444-4444-4444-4444-444444444444",
+ project.id,
+ Uuid::parse_str("44444444-4444-4444-4444-444444444444").unwrap(),
"Should only get project-D"
);
}
@@ -1300,14 +1340,14 @@ async fn test_multiple_filter_criteria_documents(db: PgPool) -> anyhow::Result<(
.await?;
// Should get 2 documents matching all criteria, all chats, and all projects
- let mut document_ids: HashSet<String> = HashSet::new();
+ let mut document_ids: HashSet<Uuid> = HashSet::new();
let mut chat_count = 0;
let mut project_count = 0;
for item in &items {
match item {
SoupItem::Document(d) => {
- document_ids.insert(d.id.clone());
+ document_ids.insert(d.id);
}
SoupItem::Chat(_) => {
chat_count += 1;
@@ -1328,12 +1368,12 @@ async fn test_multiple_filter_criteria_documents(db: PgPool) -> anyhow::Result<(
let returned_ids = document_ids;
- let expected_ids: HashSet<String> = [
+ let expected_ids: HashSet<Uuid> = [
"aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
"bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
]
.iter()
- .map(|&s| s.to_string())
+ .map(|&s| Uuid::parse_str(s).unwrap())
.collect();
assert_eq!(returned_ids, expected_ids);
@@ -1449,7 +1489,8 @@ async fn test_filter_by_owner(db: PgPool) -> anyhow::Result<()> {
match item {
SoupItem::Document(doc) => {
assert_eq!(
- doc.owner_id, "macro|[email protected]",
+ doc.owner_id.as_ref(),
"All documents should be owned by user-1"
);
doc_count += 1;
@@ -1596,7 +1637,7 @@ async fn test_cursor_pagination_with_document_filter(db: PgPool) -> anyhow::Resu
user_id: user_id.copied(),
limit: 3,
cursor: Query::Cursor(models_pagination::Cursor {
- id: cursor_decoded.id,
+ id: cursor_decoded.id.to_string(),
limit: cursor_decoded.limit,
val: cursor_decoded.val,
filter: filters_for_cursor,
@@ -1628,23 +1669,23 @@ async fn test_cursor_pagination_with_document_filter(db: PgPool) -> anyhow::Resu
}
// Verify no duplicate items between pages
- let first_page_ids: HashSet<String> = first_page_items
+ let first_page_ids: HashSet<Uuid> = first_page_items
.iter()
.map(|item| match item {
- SoupItem::Document(d) => d.id.clone(),
- SoupItem::Chat(c) => c.id.clone(),
- SoupItem::Project(p) => p.id.clone(),
+ SoupItem::Document(d) => d.id,
+ SoupItem::Chat(c) => c.id,
+ SoupItem::Project(p) => p.id,
})
.collect();
for item in &second_page_items {
let id = match item {
- SoupItem::Document(d) => &d.id,
- SoupItem::Chat(c) => &c.id,
- SoupItem::Project(p) => &p.id,
+ SoupItem::Document(d) => d.id,
+ SoupItem::Chat(c) => c.id,
+ SoupItem::Project(p) => p.id,
};
assert!(
- !first_page_ids.contains(id),
+ !first_page_ids.contains(&id),
"No item should appear on both pages"
);
}
@@ -1711,7 +1752,7 @@ async fn test_cursor_pagination_with_combined_filters(db: PgPool) -> anyhow::Res
user_id: user_id.copied(),
limit: 2,
cursor: Query::Cursor(models_pagination::Cursor {
- id: cursor_decoded.id,
+ id: cursor_decoded.id.to_string(),
limit: cursor_decoded.limit,
val: cursor_decoded.val,
filter: filters_for_cursor,
@@ -1725,16 +1766,18 @@ async fn test_cursor_pagination_with_combined_filters(db: PgPool) -> anyhow::Res
for item in &second_page_items {
match item {
SoupItem::Document(doc) => {
- let project_id = doc.project_id.as_deref().unwrap();
+ let project_id = doc.project_id.as_ref().unwrap();
+ let proj_a = Uuid::parse_str("11111111-1111-1111-1111-111111111111").unwrap();
+ let proj_b = Uuid::parse_str("22222222-2222-2222-2222-222222222222").unwrap();
assert!(
- project_id == "11111111-1111-1111-1111-111111111111"
- || project_id == "22222222-2222-2222-2222-222222222222",
+ *project_id == proj_a || *project_id == proj_b,
"Documents should be in filtered projects"
);
}
SoupItem::Chat(chat) => {
assert_eq!(
- chat.id, "a1a1a1a1-a1a1-a1a1-a1a1-a1a1a1a1a1a1",
+ chat.id,
+ Uuid::parse_str("a1a1a1a1-a1a1-a1a1-a1a1-a1a1a1a1a1a1").unwrap(),
"Only the filtered chat should appear"
);
}
@@ -1803,7 +1846,7 @@ async fn test_cursor_pagination_filter_consistency(db: PgPool) -> anyhow::Result
let filters_for_cursor =
EntityFilterAst::new_from_filters(entity_filters.clone())?.unwrap();
current_query = Query::Cursor(models_pagination::Cursor {
- id: cursor_decoded.id,
+ id: cursor_decoded.id.to_string(),
limit: cursor_decoded.limit,
val: cursor_decoded.val,
filter: filters_for_cursor,
@@ -1815,12 +1858,12 @@ async fn test_cursor_pagination_filter_consistency(db: PgPool) -> anyhow::Result
// Count filtered documents across all pages
let mut filtered_doc_count = 0;
- let expected_doc_ids: HashSet<String> = [
+ let expected_doc_ids: HashSet<Uuid> = [
"aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
"bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
]
.iter()
- .map(|&s| s.to_string())
+ .map(|&s| Uuid::parse_str(s).unwrap())
.collect();
for item in &all_items {
@@ -1841,12 +1884,12 @@ async fn test_cursor_pagination_filter_consistency(db: PgPool) -> anyhow::Result
);
// Verify no duplicate items
- let all_ids: Vec<String> = all_items
+ let all_ids: Vec<Uuid> = all_items
.iter()
.map(|item| match item {
- SoupItem::Document(d) => d.id.clone(),
- SoupItem::Chat(c) => c.id.clone(),
- SoupItem::Project(p) => p.id.clone(),
+ SoupItem::Document(d) => d.id,
+ SoupItem::Chat(c) => c.id,
+ SoupItem::Project(p) => p.id,
})
.collect();
@@ -1900,10 +1943,11 @@ async fn test_cursor_pagination_with_single_item_filter(db: PgPool) -> anyhow::R
.into_page();
// Count the filtered chat in first page
+ let expected_chat_id = Uuid::parse_str("a1a1a1a1-a1a1-a1a1-a1a1-a1a1a1a1a1a1").unwrap();
let chat_count_page1 = result
.items
.iter()
- .filter(|item| matches!(item, SoupItem::Chat(c) if c.id == "a1a1a1a1-a1a1-a1a1-a1a1-a1a1a1a1a1a1"))
+ .filter(|item| matches!(item, SoupItem::Chat(c) if c.id == expected_chat_id))
.count();
// We should see the filtered chat (it might be on page 1 or later depending on sort order)
@@ -1917,7 +1961,7 @@ async fn test_cursor_pagination_with_single_item_filter(db: PgPool) -> anyhow::R
user_id: user_id.copied(),
limit: 5,
cursor: Query::Cursor(models_pagination::Cursor {
- id: cursor_decoded.id,
+ id: cursor_decoded.id.to_string(),
limit: cursor_decoded.limit,
val: cursor_decoded.val,
filter: filters_for_cursor,
@@ -1930,7 +1974,7 @@ async fn test_cursor_pagination_with_single_item_filter(db: PgPool) -> anyhow::R
// Count the filtered chat in second page
let chat_count_page2 = second_page_items
.iter()
- .filter(|item| matches!(item, SoupItem::Chat(c) if c.id == "a1a1a1a1-a1a1-a1a1-a1a1-a1a1a1a1a1a1"))
+ .filter(|item| matches!(item, SoupItem::Chat(c) if c.id == expected_chat_id))
.count();
// Across both pages, we should see exactly 1 instance of the filtered chat
@@ -1973,7 +2017,7 @@ async fn test_dynamic_query_with_ast_and_frecency_exclusion(
document_ids: vec![
"44444444-4444-4444-4444-444444444444".to_string(), // doc-no-frecency-1
"55555555-5555-5555-5555-555555555555".to_string(), // doc-no-frecency-2
- "11111111-1111-1111-1111-111111111111".to_string(), // doc-with-frecency-1
+ "44444444-ffff-ffff-ffff-ffffffffffff".to_string(), // doc-with-frecency-1
],
..Default::default()
},
@@ -2007,7 +2051,7 @@ async fn test_dynamic_query_with_ast_and_frecency_exclusion(
// The no_frecency_items fixture has:
// - 44444444-4444-4444-4444-444444444444 (no frecency) - should be included
// - 55555555-5555-5555-5555-555555555555 (no frecency) - should be included
- // - 11111111-1111-1111-1111-111111111111 (has frecency) - excluded by frecency filter
+ // - 44444444-ffff-ffff-ffff-ffffffffffff (has frecency) - excluded by frecency filter
// So we should only get 2 documents
assert_eq!(
items.len(),
@@ -2024,20 +2068,20 @@ async fn test_dynamic_query_with_ast_and_frecency_exclusion(
}
// Verify the returned document IDs
- let returned_ids: HashSet<String> = items
+ let returned_ids: HashSet<Uuid> = items
.iter()
.map(|item| match item {
- SoupItem::Document(d) => d.id.clone(),
+ SoupItem::Document(d) => d.id,
_ => unreachable!(),
})
.collect();
- let expected_ids: HashSet<String> = [
+ let expected_ids: HashSet<Uuid> = [
"44444444-4444-4444-4444-444444444444",
"55555555-5555-5555-5555-555555555555",
]
.iter()
- .map(|&s| s.to_string())
+ .map(|&s| Uuid::parse_str(s).unwrap())
.collect();
assert_eq!(
@@ -2064,21 +2108,21 @@ async fn test_dynamic_query_with_ast_and_frecency_exclusion(
"Should return all documents matching AST filter when frecency is not excluded"
);
- let returned_with_frecency_ids: HashSet<String> = items_with_frecency
+ let returned_with_frecency_ids: HashSet<Uuid> = items_with_frecency
.iter()
.map(|item| match item {
- SoupItem::Document(d) => d.id.clone(),
+ SoupItem::Document(d) => d.id,
_ => unreachable!(),
})
.collect();
- let expected_with_frecency_ids: HashSet<String> = [
+ let expected_with_frecency_ids: HashSet<Uuid> = [
"44444444-4444-4444-4444-444444444444",
"55555555-5555-5555-5555-555555555555",
- "11111111-1111-1111-1111-111111111111",
+ "44444444-ffff-ffff-ffff-ffffffffffff",
]
.iter()
- .map(|&s| s.to_string())
+ .map(|&s| Uuid::parse_str(s).unwrap())
.collect();
assert_eq!(
diff --git a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/unexpanded/by_cursor.rs b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/unexpanded/by_cursor.rs
index b2ebaae4e5..af2b5f1ee6 100644
--- a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/unexpanded/by_cursor.rs
+++ b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/unexpanded/by_cursor.rs
@@ -1,9 +1,10 @@
-use macro_user_id::user_id::MacroUserIdStr;
+use crate::{map_soup_type, outbound::pg_soup_repo::type_err};
+use macro_user_id::{cowlike::CowLike, user_id::MacroUserIdStr};
use models_pagination::{Query, SimpleSortMethod};
-use models_soup::{
- chat::map_soup_chat, document::map_soup_document, item::SoupItem, project::map_soup_project,
-};
+use models_soup::item::SoupItem;
use sqlx::PgPool;
+use std::str::FromStr;
+use uuid::Uuid;
/// Returns objects that a user has EXPLICIT access to, including project items.
///
@@ -168,51 +169,7 @@ pub async fn unexpanded_generic_cursor_soup(
cursor_timestamp, // $4
cursor_id, // $5
)
- .try_map(|r| match r.item_type.as_ref() {
- "document" => {
- let document = map_soup_document(
- r.id,
- r.user_id,
- r.document_version_id,
- r.name,
- r.sha,
- r.file_type,
- r.document_family_id,
- r.branched_from_id,
- r.branched_from_version_id,
- r.project_id,
- r.created_at,
- r.updated_at,
- r.viewed_at,
- )
- .map_err(|e| sqlx::Error::TypeNotFound {
- type_name: e.to_string(),
- })?;
- Ok(SoupItem::Document(document))
- }
- "chat" => Ok(SoupItem::Chat(map_soup_chat(
- r.id,
- r.user_id,
- r.name,
- r.project_id,
- r.is_persistent,
- r.created_at,
- r.updated_at,
- r.viewed_at,
- ))),
- "project" => Ok(SoupItem::Project(map_soup_project(
- r.id,
- r.user_id,
- r.name,
- r.project_id,
- r.created_at,
- r.updated_at,
- r.viewed_at,
- ))),
- _ => Err(sqlx::Error::TypeNotFound {
- type_name: r.item_type,
- }),
- })
+ .try_map(map_soup_type!())
.fetch_all(db)
.await?;
@@ -389,51 +346,7 @@ pub async fn no_frecency_unexpanded_generic_cursor_soup(
cursor_timestamp, // $4
cursor_id, // $5
)
- .try_map(|r| match r.item_type.as_ref() {
- "document" => {
- let document = map_soup_document(
- r.id,
- r.user_id,
- r.document_version_id,
- r.name,
- r.sha,
- r.file_type,
- r.document_family_id,
- r.branched_from_id,
- r.branched_from_version_id,
- r.project_id,
- r.created_at,
- r.updated_at,
- r.viewed_at,
- )
- .map_err(|e| sqlx::Error::TypeNotFound {
- type_name: e.to_string(),
- })?;
- Ok(SoupItem::Document(document))
- }
- "chat" => Ok(SoupItem::Chat(map_soup_chat(
- r.id,
- r.user_id,
- r.name,
- r.project_id,
- r.is_persistent,
- r.created_at,
- r.updated_at,
- r.viewed_at,
- ))),
- "project" => Ok(SoupItem::Project(map_soup_project(
- r.id,
- r.user_id,
- r.name,
- r.project_id,
- r.created_at,
- r.updated_at,
- r.viewed_at,
- ))),
- _ => Err(sqlx::Error::TypeNotFound {
- type_name: r.item_type,
- }),
- })
+ .try_map(map_soup_type!())
.fetch_all(db)
.await?;
diff --git a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/unexpanded/by_ids.rs b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/unexpanded/by_ids.rs
index 64efd7b4e0..95d5a16637 100644
--- a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/unexpanded/by_ids.rs
+++ b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/unexpanded/by_ids.rs
@@ -1,9 +1,10 @@
-use macro_user_id::user_id::MacroUserIdStr;
+use crate::{map_soup_type, outbound::pg_soup_repo::type_err};
+use macro_user_id::{cowlike::CowLike, user_id::MacroUserIdStr};
use model_entity::{Entity, EntityType};
-use models_soup::{
- chat::map_soup_chat, document::map_soup_document, item::SoupItem, project::map_soup_project,
-};
+use models_soup::item::SoupItem;
use sqlx::PgPool;
+use std::str::FromStr;
+use uuid::Uuid;
/// Returns objects that a user has EXPLICIT access to by their IDs, including project items.
///
@@ -160,51 +161,7 @@ pub async fn unexpanded_soup_by_ids<'a>(
chat_ids.as_slice(), // $3
project_ids.as_slice(), // $4
)
- .try_map(|r| match r.item_type.as_ref() {
- "document" => {
- let document = map_soup_document(
- r.id,
- r.user_id,
- r.document_version_id,
- r.name,
- r.sha,
- r.file_type,
- r.document_family_id,
- r.branched_from_id,
- r.branched_from_version_id,
- r.project_id,
- r.created_at,
- r.updated_at,
- r.viewed_at,
- )
- .map_err(|e| sqlx::Error::TypeNotFound {
- type_name: e.to_string(),
- })?;
- Ok(SoupItem::Document(document))
- }
- "chat" => Ok(SoupItem::Chat(map_soup_chat(
- r.id,
- r.user_id,
- r.name,
- r.project_id,
- r.is_persistent,
- r.created_at,
- r.updated_at,
- r.viewed_at,
- ))),
- "project" => Ok(SoupItem::Project(map_soup_project(
- r.id,
- r.user_id,
- r.name,
- r.project_id,
- r.created_at,
- r.updated_at,
- r.viewed_at,
- ))),
- _ => Err(sqlx::Error::TypeNotFound {
- type_name: r.item_type,
- }),
- })
+ .try_map(map_soup_type!())
.fetch_all(db)
.await?;
diff --git a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/unexpanded/tests.rs b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/unexpanded/tests.rs
index 6aa434d5dc..21d0047c66 100644
--- a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/unexpanded/tests.rs
+++ b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/unexpanded/tests.rs
@@ -9,6 +9,7 @@ use models_pagination::{PaginateOn, Query, SimpleSortMethod};
use models_soup::item::SoupItem;
use sqlx::{Pool, Postgres};
use std::collections::HashSet;
+use uuid::Uuid;
// testing the sorting methods work as expected
#[sqlx::test(
@@ -21,13 +22,13 @@ use std::collections::HashSet;
async fn test_unexpanded_generic_sorting_methods(pool: Pool<Postgres>) -> anyhow::Result<()> {
let user_id = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
- let get_item_ids = |items: &[SoupItem]| -> Vec<String> {
+ let get_item_ids = |items: &[SoupItem]| -> Vec<Uuid> {
items
.iter()
.map(|item| match item {
- SoupItem::Document(d) => d.id.clone(),
- SoupItem::Chat(c) => c.id.clone(),
- SoupItem::Project(p) => p.id.clone(),
+ SoupItem::Document(d) => d.id,
+ SoupItem::Chat(c) => c.id,
+ SoupItem::Project(p) => p.id,
})
.collect()
};
@@ -43,9 +44,13 @@ async fn test_unexpanded_generic_sorting_methods(pool: Pool<Postgres>) -> anyhow
assert_eq!(result.len(), 3, "LastViewed should return 3 items");
let item_ids = get_item_ids(&result);
+ let expected_ids = vec![
+ Uuid::parse_str("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa").unwrap(),
+ Uuid::parse_str("bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb").unwrap(),
+ Uuid::parse_str("cccccccc-cccc-cccc-cccc-cccccccccccc").unwrap(),
+ ];
assert_eq!(
- item_ids,
- vec!["doc-A", "doc-B", "doc-C"],
+ item_ids, expected_ids,
"Failed to sort correctly by LastViewed"
);
}
@@ -61,9 +66,13 @@ async fn test_unexpanded_generic_sorting_methods(pool: Pool<Postgres>) -> anyhow
assert_eq!(result.len(), 3, "UpdatedAt should return 3 items");
let item_ids = get_item_ids(&result);
+ let expected_ids = vec![
+ Uuid::parse_str("cccccccc-cccc-cccc-cccc-cccccccccccc").unwrap(),
+ Uuid::parse_str("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa").unwrap(),
+ Uuid::parse_str("bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb").unwrap(),
+ ];
assert_eq!(
- item_ids,
- vec!["doc-C", "doc-A", "doc-B"],
+ item_ids, expected_ids,
"Failed to sort correctly by UpdatedAt"
);
}
@@ -79,9 +88,13 @@ async fn test_unexpanded_generic_sorting_methods(pool: Pool<Postgres>) -> anyhow
assert_eq!(result.len(), 3, "CreatedAt should return 3 items");
let item_ids = get_item_ids(&result);
+ let expected_ids = vec![
+ Uuid::parse_str("bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb").unwrap(),
+ Uuid::parse_str("cccccccc-cccc-cccc-cccc-cccccccccccc").unwrap(),
+ Uuid::parse_str("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa").unwrap(),
+ ];
assert_eq!(
- item_ids,
- vec!["doc-B", "doc-C", "doc-A"],
+ item_ids, expected_ids,
"Failed to sort correctly by CreatedAt"
);
}
@@ -101,13 +114,13 @@ async fn test_unexpanded_generic_mixed_types_sorting(pool: Pool<Postgres>) -> an
let user_id = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
// --- Helper to extract IDs for easy comparison ---
- let get_item_ids = |items: &[SoupItem]| -> Vec<String> {
+ let get_item_ids = |items: &[SoupItem]| -> Vec<Uuid> {
items
.iter()
.map(|item| match item {
- SoupItem::Document(d) => d.id.clone(),
- SoupItem::Chat(c) => c.id.clone(),
- SoupItem::Project(p) => p.id.clone(),
+ SoupItem::Document(d) => d.id,
+ SoupItem::Chat(c) => c.id,
+ SoupItem::Project(p) => p.id,
})
.collect()
};
@@ -124,37 +137,45 @@ async fn test_unexpanded_generic_mixed_types_sorting(pool: Pool<Postgres>) -> an
assert_eq!(result.len(), 3, "LastViewed should return 3 items");
let item_ids = get_item_ids(&result);
+ let expected_ids = vec![
+ Uuid::parse_str("dddddddd-dddd-dddd-dddd-dddddddddddd").unwrap(),
+ Uuid::parse_str("ffffffff-ffff-ffff-ffff-ffffffffffff").unwrap(),
+ Uuid::parse_str("cccccccc-1111-1111-1111-111111111111").unwrap(),
+ ];
assert_eq!(
- item_ids,
- vec!["test-document", "test-project", "test-chat"],
+ item_ids, expected_ids,
"Failed to sort correctly by LastViewed"
);
// Perform detailed property checks once, since the set of items is the same.
- let items_map: std::collections::HashMap<String, &SoupItem> = result
+ let items_map: std::collections::HashMap<Uuid, &SoupItem> = result
.iter()
.map(|item| {
let id = match item {
- SoupItem::Document(d) => d.id.clone(),
- SoupItem::Chat(c) => c.id.clone(),
- SoupItem::Project(p) => p.id.clone(),
+ SoupItem::Document(d) => d.id,
+ SoupItem::Chat(c) => c.id,
+ SoupItem::Project(p) => p.id,
};
(id, item)
})
.collect();
- if let Some(SoupItem::Document(doc)) = items_map.get("test-document") {
+ let test_doc_uuid = Uuid::parse_str("dddddddd-dddd-dddd-dddd-dddddddddddd").unwrap(); // test-document
+ let test_chat_uuid = Uuid::parse_str("cccccccc-1111-1111-1111-111111111111").unwrap(); // test-chat
+ let test_project_uuid = Uuid::parse_str("ffffffff-ffff-ffff-ffff-ffffffffffff").unwrap(); // test-project
+
+ if let Some(SoupItem::Document(doc)) = items_map.get(&test_doc_uuid) {
assert_eq!(doc.name, "Document Charlie");
assert_eq!(doc.file_type.as_deref(), Some("pdf"));
} else {
panic!("Missing test-document");
}
- if let Some(SoupItem::Chat(chat)) = items_map.get("test-chat") {
+ if let Some(SoupItem::Chat(chat)) = items_map.get(&test_chat_uuid) {
assert_eq!(chat.name, "Chat Bravo");
} else {
panic!("Missing test-chat");
}
- if let Some(SoupItem::Project(project)) = items_map.get("test-project") {
+ if let Some(SoupItem::Project(project)) = items_map.get(&test_project_uuid) {
assert_eq!(project.name, "Project Alpha");
} else {
panic!("Missing test-project");
@@ -173,9 +194,13 @@ async fn test_unexpanded_generic_mixed_types_sorting(pool: Pool<Postgres>) -> an
assert_eq!(result.len(), 3, "UpdatedAt should return 3 items");
let item_ids = get_item_ids(&result);
+ let expected_ids = vec![
+ Uuid::parse_str("cccccccc-1111-1111-1111-111111111111").unwrap(),
+ Uuid::parse_str("dddddddd-dddd-dddd-dddd-dddddddddddd").unwrap(),
+ Uuid::parse_str("ffffffff-ffff-ffff-ffff-ffffffffffff").unwrap(),
+ ];
assert_eq!(
- item_ids,
- vec!["test-chat", "test-document", "test-project"],
+ item_ids, expected_ids,
"Failed to sort correctly by UpdatedAt"
);
}
@@ -192,9 +217,13 @@ async fn test_unexpanded_generic_mixed_types_sorting(pool: Pool<Postgres>) -> an
assert_eq!(result.len(), 3, "CreatedAt should return 3 items");
let item_ids = get_item_ids(&result);
+ let expected_ids = vec![
+ Uuid::parse_str("ffffffff-ffff-ffff-ffff-ffffffffffff").unwrap(),
+ Uuid::parse_str("cccccccc-1111-1111-1111-111111111111").unwrap(),
+ Uuid::parse_str("dddddddd-dddd-dddd-dddd-dddddddddddd").unwrap(),
+ ];
assert_eq!(
- item_ids,
- vec!["test-project", "test-chat", "test-document"],
+ item_ids, expected_ids,
"Failed to sort correctly by CreatedAt"
);
}
@@ -225,34 +254,44 @@ async fn test_get_user_items_unexpanded_cursor(pool: Pool<Postgres>) -> anyhow::
assert_eq!(result.items.len(), 1, "Should get 1 item");
+ let expected_doc_uuid = Uuid::parse_str("dddddddd-dddd-dddd-dddd-dddddddddddd").unwrap();
match &result.items[0] {
SoupItem::Document(doc) => {
assert_eq!(
- doc.id, "test-document",
+ doc.id, expected_doc_uuid,
"First item should be document with ID test-document"
);
}
_ => panic!("First item should be a document"),
}
- let result = unexpanded_generic_cursor_soup(
+ let items_page2 = unexpanded_generic_cursor_soup(
&pool,
user_id,
1,
Query::new(
- result.next_cursor.map(|s| s.decode_json().unwrap()),
+ result.next_cursor.map(|s| {
+ let decoded = s.decode_json().unwrap();
+ models_pagination::Cursor {
+ id: decoded.id.to_string(),
+ limit: decoded.limit,
+ val: decoded.val,
+ filter: decoded.filter,
+ }
+ }),
SimpleSortMethod::ViewedAt,
(),
),
)
.await?;
- assert_eq!(result.len(), 1, "Should get 1 item");
+ assert_eq!(items_page2.len(), 1, "Should get 1 item");
- match &result[0] {
+ let expected_proj_uuid = Uuid::parse_str("ffffffff-ffff-ffff-ffff-ffffffffffff").unwrap();
+ match &items_page2[0] {
SoupItem::Project(project) => {
assert_eq!(
- project.id, "test-project",
+ project.id, expected_proj_uuid,
"Second item should be project with ID test-project"
);
}
@@ -275,10 +314,10 @@ async fn test_unexpanded_soup_by_ids(pool: Pool<Postgres>) {
// Request specific items in a specific order
let entities = [
- EntityType::Chat.with_entity_str("test-chat"),
- EntityType::Document.with_entity_str("test-document"),
- EntityType::Project.with_entity_str("test-project"),
- EntityType::Document.with_entity_str("non-existent"), // Should not appear in results
+ EntityType::Chat.with_entity_str("cccccccc-1111-1111-1111-111111111111"),
+ EntityType::Document.with_entity_str("dddddddd-dddd-dddd-dddd-dddddddddddd"),
+ EntityType::Project.with_entity_str("ffffffff-ffff-ffff-ffff-ffffffffffff"),
+ EntityType::Document.with_entity_str("00000000-0000-0000-0000-000000000000"), // Should not appear in results
];
let items = unexpanded_soup_by_ids(&pool, user_id, &entities)
@@ -324,9 +363,9 @@ async fn it_should_be_empty(pool: Pool<Postgres>) {
// Test with only non-existent items
let non_existent_entities = [
- EntityType::Document.with_entity_str("non-existent-doc"),
- EntityType::Chat.with_entity_str("non-existent-chat"),
- EntityType::Project.with_entity_str("non-existent-project"),
+ EntityType::Document.with_entity_str("00000000-0000-0000-0000-000000000001"),
+ EntityType::Chat.with_entity_str("00000000-0000-0000-0000-000000000002"),
+ EntityType::Project.with_entity_str("00000000-0000-0000-0000-000000000003"),
];
let empty_result = unexpanded_soup_by_ids(&pool, user_id, &non_existent_entities)
@@ -352,9 +391,9 @@ async fn test_unexpanded_soup_by_ids_simple(pool: Pool<Postgres>) {
// Request documents in a specific order
let entities = [
- EntityType::Document.with_entity_str("doc-C"),
- EntityType::Document.with_entity_str("doc-A"),
- EntityType::Document.with_entity_str("doc-B"),
+ EntityType::Document.with_entity_str("cccccccc-cccc-cccc-cccc-cccccccccccc"),
+ EntityType::Document.with_entity_str("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"),
+ EntityType::Document.with_entity_str("bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb"),
];
let items = unexpanded_soup_by_ids(&pool, user_id.copied(), &entities)
@@ -365,10 +404,10 @@ async fn test_unexpanded_soup_by_ids_simple(pool: Pool<Postgres>) {
// Test with duplicate entity IDs (should still return unique items)
let entities_with_duplicates = [
- EntityType::Document.with_entity_str("doc-A"),
- EntityType::Document.with_entity_str("doc-B"),
- EntityType::Document.with_entity_str("doc-A"), // Duplicate
- EntityType::Document.with_entity_str("doc-C"),
+ EntityType::Document.with_entity_str("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"),
+ EntityType::Document.with_entity_str("bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb"),
+ EntityType::Document.with_entity_str("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"), // Duplicate
+ EntityType::Document.with_entity_str("cccccccc-cccc-cccc-cccc-cccccccccccc"),
];
let items = unexpanded_soup_by_ids(&pool, user_id.copied(), &entities_with_duplicates)
@@ -395,9 +434,9 @@ async fn test_unexpanded_soup_by_ids_access_control(pool: Pool<Postgres>) -> any
// Request all items, but only those with explicit access should be returned
let entities = [
- EntityType::Document.with_entity_str("test-document"),
- EntityType::Chat.with_entity_str("test-chat"),
- EntityType::Project.with_entity_str("test-project"),
+ EntityType::Document.with_entity_str("dddddddd-dddd-dddd-dddd-dddddddddddd"),
+ EntityType::Chat.with_entity_str("cccccccc-1111-1111-1111-111111111111"),
+ EntityType::Project.with_entity_str("ffffffff-ffff-ffff-ffff-ffffffffffff"),
];
let items = unexpanded_soup_by_ids(&pool, user_id, &entities).await?;
@@ -449,24 +488,24 @@ async fn test_no_frecency_unexpanded_filters_out_frecency_items(
);
// Verify the returned items are the ones WITHOUT frecency
- let returned_ids: HashSet<String> = items
+ let returned_ids: HashSet<Uuid> = items
.iter()
.map(|item| match item {
- SoupItem::Chat(c) => c.id.clone(),
- SoupItem::Document(d) => d.id.clone(),
- SoupItem::Project(p) => p.id.clone(),
+ SoupItem::Chat(c) => c.id,
+ SoupItem::Document(d) => d.id,
+ SoupItem::Project(p) => p.id,
})
.collect();
- let expected_ids: HashSet<String> = [
- "doc-no-frecency-1",
- "doc-no-frecency-2",
- "chat-no-frecency-1",
- "chat-no-frecency-2",
- "project-no-frecency",
+ let expected_ids: HashSet<Uuid> = [
+ "44444444-4444-4444-4444-444444444444", // doc-no-frecency-1
+ "55555555-5555-5555-5555-555555555555", // doc-no-frecency-2
+ "66666666-6666-6666-6666-666666666666", // chat-no-frecency-1
+ "77777777-7777-7777-7777-777777777777", // chat-no-frecency-2
+ "88888888-8888-8888-8888-888888888888", // project-no-frecency
]
.iter()
- .map(|&s| s.to_string())
+ .map(|&s| Uuid::parse_str(s).unwrap())
.collect();
assert_eq!(
@@ -476,14 +515,14 @@ async fn test_no_frecency_unexpanded_filters_out_frecency_items(
// Verify none of the frecency items are returned
let frecency_items = [
- "doc-with-frecency-1",
- "doc-with-frecency-2",
- "chat-with-frecency-1",
- "project-with-frecency",
+ Uuid::parse_str("44444444-ffff-ffff-ffff-ffffffffffff").unwrap(), // doc-with-frecency-1
+ Uuid::parse_str("55555555-ffff-ffff-ffff-ffffffffffff").unwrap(), // doc-with-frecency-2
+ Uuid::parse_str("66666666-ffff-ffff-ffff-ffffffffffff").unwrap(), // chat-with-frecency-1
+ Uuid::parse_str("88888888-ffff-ffff-ffff-ffffffffffff").unwrap(), // project-with-frecency
];
for frecency_id in &frecency_items {
assert!(
- !returned_ids.contains(*frecency_id),
+ !returned_ids.contains(frecency_id),
"Should not return item with frecency: {}",
frecency_id
);
@@ -503,13 +542,13 @@ async fn test_no_frecency_unexpanded_filters_out_frecency_items(
async fn test_no_frecency_unexpanded_sorting_methods(pool: Pool<Postgres>) -> anyhow::Result<()> {
let user_id = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
- let get_item_ids = |items: &[SoupItem]| -> Vec<String> {
+ let get_item_ids = |items: &[SoupItem]| -> Vec<Uuid> {
items
.iter()
.map(|item| match item {
- SoupItem::Document(d) => d.id.clone(),
- SoupItem::Chat(c) => c.id.clone(),
- SoupItem::Project(p) => p.id.clone(),
+ SoupItem::Document(d) => d.id,
+ SoupItem::Chat(c) => c.id,
+ SoupItem::Project(p) => p.id,
})
.collect()
};
@@ -528,15 +567,15 @@ async fn test_no_frecency_unexpanded_sorting_methods(pool: Pool<Postgres>) -> an
let item_ids = get_item_ids(&items);
// Ordered by updatedAt DESC: doc-no-frecency-1 (2/13), doc-no-frecency-2 (2/12),
// chat-no-frecency-1 (2/10), chat-no-frecency-2 (2/09), project-no-frecency (2/07)
+ let expected_ids = vec![
+ Uuid::parse_str("44444444-4444-4444-4444-444444444444").unwrap(), // doc-no-frecency-1
+ Uuid::parse_str("55555555-5555-5555-5555-555555555555").unwrap(), // doc-no-frecency-2
+ Uuid::parse_str("66666666-6666-6666-6666-666666666666").unwrap(), // chat-no-frecency-1
+ Uuid::parse_str("77777777-7777-7777-7777-777777777777").unwrap(), // chat-no-frecency-2
+ Uuid::parse_str("88888888-8888-8888-8888-888888888888").unwrap(), // project-no-frecency
+ ];
assert_eq!(
- item_ids,
- vec![
- "doc-no-frecency-1",
- "doc-no-frecency-2",
- "chat-no-frecency-1",
- "chat-no-frecency-2",
- "project-no-frecency"
- ],
+ item_ids, expected_ids,
"Failed to sort correctly by UpdatedAt"
);
}
@@ -555,15 +594,15 @@ async fn test_no_frecency_unexpanded_sorting_methods(pool: Pool<Postgres>) -> an
let item_ids = get_item_ids(&items);
// Ordered by createdAt DESC: project-no-frecency (1/18), chat-no-frecency-2 (1/16),
// chat-no-frecency-1 (1/15), doc-no-frecency-2 (1/13), doc-no-frecency-1 (1/12)
+ let expected_ids = vec![
+ Uuid::parse_str("88888888-8888-8888-8888-888888888888").unwrap(), // project-no-frecency
+ Uuid::parse_str("77777777-7777-7777-7777-777777777777").unwrap(), // chat-no-frecency-2
+ Uuid::parse_str("66666666-6666-6666-6666-666666666666").unwrap(), // chat-no-frecency-1
+ Uuid::parse_str("55555555-5555-5555-5555-555555555555").unwrap(), // doc-no-frecency-2
+ Uuid::parse_str("44444444-4444-4444-4444-444444444444").unwrap(), // doc-no-frecency-1
+ ];
assert_eq!(
- item_ids,
- vec![
- "project-no-frecency",
- "chat-no-frecency-2",
- "chat-no-frecency-1",
- "doc-no-frecency-2",
- "doc-no-frecency-1"
- ],
+ item_ids, expected_ids,
"Failed to sort correctly by CreatedAt"
);
}
@@ -582,15 +621,15 @@ async fn test_no_frecency_unexpanded_sorting_methods(pool: Pool<Postgres>) -> an
let item_ids = get_item_ids(&items);
// Ordered by UserHistory.updatedAt DESC: doc-no-frecency-1 (3/17), doc-no-frecency-2 (3/16),
// chat-no-frecency-1 (3/15), chat-no-frecency-2 (3/14), project-no-frecency (3/13)
+ let expected_ids = vec![
+ Uuid::parse_str("44444444-4444-4444-4444-444444444444").unwrap(), // doc-no-frecency-1
+ Uuid::parse_str("55555555-5555-5555-5555-555555555555").unwrap(), // doc-no-frecency-2
+ Uuid::parse_str("66666666-6666-6666-6666-666666666666").unwrap(), // chat-no-frecency-1
+ Uuid::parse_str("77777777-7777-7777-7777-777777777777").unwrap(), // chat-no-frecency-2
+ Uuid::parse_str("88888888-8888-8888-8888-888888888888").unwrap(), // project-no-frecency
+ ];
assert_eq!(
- item_ids,
- vec![
- "doc-no-frecency-1",
- "doc-no-frecency-2",
- "chat-no-frecency-1",
- "chat-no-frecency-2",
- "project-no-frecency"
- ],
+ item_ids, expected_ids,
"Failed to sort correctly by ViewedAt"
);
}
@@ -624,22 +663,19 @@ async fn test_no_frecency_unexpanded_cursor_pagination(pool: Pool<Postgres>) ->
assert_eq!(result.items.len(), 2, "Should get 2 items in first page");
// First two items should be the most recently updated
+ let doc1_uuid = Uuid::parse_str("44444444-4444-4444-4444-444444444444").unwrap();
+ let doc2_uuid = Uuid::parse_str("55555555-5555-5555-5555-555555555555").unwrap();
+
match &result.items[0] {
SoupItem::Document(doc) => {
- assert_eq!(
- doc.id, "doc-no-frecency-1",
- "First item should be doc-no-frecency-1"
- );
+ assert_eq!(doc.id, doc1_uuid, "First item should be doc-no-frecency-1");
}
_ => panic!("First item should be a document"),
}
match &result.items[1] {
SoupItem::Document(doc) => {
- assert_eq!(
- doc.id, "doc-no-frecency-2",
- "Second item should be doc-no-frecency-2"
- );
+ assert_eq!(doc.id, doc2_uuid, "Second item should be doc-no-frecency-2");
}
_ => panic!("Second item should be a document"),
}
@@ -650,7 +686,15 @@ async fn test_no_frecency_unexpanded_cursor_pagination(pool: Pool<Postgres>) ->
user_id,
2,
Query::new(
- result.next_cursor.map(|s| s.decode_json().unwrap()),
+ result.next_cursor.map(|s| {
+ let decoded = s.decode_json().unwrap();
+ models_pagination::Cursor {
+ id: decoded.id.to_string(),
+ limit: decoded.limit,
+ val: decoded.val,
+ filter: decoded.filter,
+ }
+ }),
SimpleSortMethod::UpdatedAt,
(),
),
@@ -660,10 +704,13 @@ async fn test_no_frecency_unexpanded_cursor_pagination(pool: Pool<Postgres>) ->
assert_eq!(items.len(), 2, "Should get 2 items in second page");
// Next two items should be the chats
+ let chat1_uuid = Uuid::parse_str("66666666-6666-6666-6666-666666666666").unwrap();
+ let chat2_uuid = Uuid::parse_str("77777777-7777-7777-7777-777777777777").unwrap();
+
match &items[0] {
SoupItem::Chat(chat) => {
assert_eq!(
- chat.id, "chat-no-frecency-1",
+ chat.id, chat1_uuid,
"Third item should be chat-no-frecency-1"
);
}
@@ -673,7 +720,7 @@ async fn test_no_frecency_unexpanded_cursor_pagination(pool: Pool<Postgres>) ->
match &items[1] {
SoupItem::Chat(chat) => {
assert_eq!(
- chat.id, "chat-no-frecency-2",
+ chat.id, chat2_uuid,
"Fourth item should be chat-no-frecency-2"
);
}