Skip to content

armgit / macro

Public Imported from GitHub
0

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

Seanaye/chore/delete unneeded (#304)

Sean Aye23348437eeb5
diff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lock
index 246d733fc6..69052509c7 100644
--- a/rust/cloud-storage/Cargo.lock
+++ b/rust/cloud-storage/Cargo.lock
@@ -2682,9 +2682,9 @@ dependencies = [
[[package]]
name = "doppleganger"
-version = "0.1.0"
+version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4f6e63a190778be95e1805cdb16becc932fbe6caa42150edfdad948242ba75aa"
+checksum = "07082bf0ceb443d51d52cdb522e014d470ad2f1a22be809361b7947bb6dd828f"
dependencies = [
"doppleganger-core",
"doppleganger-macros",
@@ -2692,9 +2692,9 @@ dependencies = [
[[package]]
name = "doppleganger-core"
-version = "0.1.0"
+version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "314f5bc3b014813956a5f373d5d310b1cdfa7b2295fbb875e7f4512dd382dd34"
+checksum = "3163e3d866a7e9935810855bce91e1ade21a4ff355cba093451f2a327650e640"
dependencies = [
"chrono",
"uuid",
@@ -2702,9 +2702,9 @@ dependencies = [
[[package]]
name = "doppleganger-macros"
-version = "0.1.0"
+version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "abdff597f92f7f4f55ab8dfa59385189b870bb8df39dae33513092986feff984"
+checksum = "f5ef4fbea2d3584cf0547c8587b73ede38972d4e01f050fb41790ef0f664bfbd"
dependencies = [
"doppleganger-macros-parse",
"proc-macro2",
@@ -2714,9 +2714,9 @@ dependencies = [
[[package]]
name = "doppleganger-macros-parse"
-version = "0.1.0"
+version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "847fd9f860890bb89d4c67838a1be9c0af044fd42ed211d87ac290cf9d53bafd"
+checksum = "d6802888ef9324ea57ef9ea11a6e42a44c9deeeb2d17dc856882713d54428fee"
dependencies = [
"proc-macro2",
"quote",
@@ -2832,6 +2832,7 @@ dependencies = [
"anyhow",
"axum",
"chrono",
+ "doppleganger",
"frecency",
"macro_user_id",
"model-entity",
diff --git a/rust/cloud-storage/Cargo.toml b/rust/cloud-storage/Cargo.toml
index 283e3e9e52..939b5e1240 100644
--- a/rust/cloud-storage/Cargo.toml
+++ b/rust/cloud-storage/Cargo.toml
@@ -210,7 +210,7 @@ bzip2 = { version = "0.5.1", default-features = false, features = [
"libbz2-rs-sys",
] }
derive_builder = "0.20.2"
-doppleganger = "0.1"
+doppleganger = "0.3"
once_cell = "1.21.3"
scraper = "0.18"
strum_macros = "0.27.1"
diff --git a/rust/cloud-storage/email/Cargo.toml b/rust/cloud-storage/email/Cargo.toml
index e05536449b..08ce9f3e4c 100644
--- a/rust/cloud-storage/email/Cargo.toml
+++ b/rust/cloud-storage/email/Cargo.toml
@@ -22,6 +22,7 @@ ports = ["dep:tokio", "frecency/ports"]
anyhow = { workspace = true }
axum = { workspace = true, optional = true }
chrono = { workspace = true, features = ["serde"] }
+doppleganger = { workspace = true }
frecency = { path = "../frecency" }
macro_user_id = { path = "../macro_user_id" }
model-entity = { path = "../model-entity" }
diff --git a/rust/cloud-storage/email/src/inbound/axum/api_types.rs b/rust/cloud-storage/email/src/inbound/axum/api_types.rs
index 933eecd349..79845076e7 100644
--- a/rust/cloud-storage/email/src/inbound/axum/api_types.rs
+++ b/rust/cloud-storage/email/src/inbound/axum/api_types.rs
@@ -1,4 +1,6 @@
use chrono::{DateTime, Utc};
+use doppleganger::{Doppleganger, Mirror};
+use macro_user_id::user_id::MacroUserIdStr;
use models_pagination::{PaginatedOpaqueCursor, SimpleSortMethod};
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
@@ -33,49 +35,31 @@ impl ApiSortMethod {
}
}
-#[derive(Debug, ToSchema, Serialize, Deserialize)]
+#[derive(Debug, ToSchema, Serialize, Deserialize, Doppleganger)]
#[cfg_attr(feature = "ai_schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "camelCase")]
+#[dg(backward = EnrichedEmailThreadPreview)]
struct ApiThreadPreviewCursor {
#[serde(flatten)]
thread: ApiThreadPreviewCursorInner,
attachments: Vec<ApiAttachment>,
+ #[dg(rename = "attachments_macro")]
macro_attachments: Vec<ApiAttachmentMacro>,
+ #[dg(rename = "participants")]
contacts: Vec<ApiContact>,
frecency_score: Option<f64>,
}
-impl ApiThreadPreviewCursor {
- #[inline]
- fn new(model: EnrichedEmailThreadPreview) -> Self {
- let EnrichedEmailThreadPreview {
- thread,
- attachments,
- attachments_macro,
- frecency_score,
- participants,
- } = model;
-
- ApiThreadPreviewCursor {
- thread: ApiThreadPreviewCursorInner::new(thread),
- attachments: attachments.into_iter().map(ApiAttachment::new).collect(),
- macro_attachments: attachments_macro
- .into_iter()
- .map(ApiAttachmentMacro::new)
- .collect(),
- contacts: participants.into_iter().map(ApiContact::new).collect(),
- frecency_score,
- }
- }
-}
-
-#[derive(Debug, ToSchema, Serialize, Deserialize)]
+#[derive(Debug, ToSchema, Serialize, Deserialize, Doppleganger)]
#[cfg_attr(feature = "ai_schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "camelCase")]
+#[dg(backward = EmailThreadPreview)]
pub struct ApiThreadPreviewCursorInner {
id: Uuid,
provider_id: Option<String>,
- owner_id: String,
+ #[schema(value_type = String)]
+ #[cfg_attr(feature = "ai_schema", schemars(with = "String"))]
+ owner_id: MacroUserIdStr<'static>,
inbox_visible: bool,
is_read: bool,
is_draft: bool,
@@ -104,52 +88,10 @@ pub struct ApiThreadPreviewCursorInner {
viewed_at: Option<DateTime<Utc>>,
}
-impl ApiThreadPreviewCursorInner {
- #[inline]
- fn new(thread: EmailThreadPreview) -> Self {
- let EmailThreadPreview {
- id,
- provider_id,
- owner_id,
- inbox_visible,
- is_read,
- is_draft,
- is_important,
- name,
- snippet,
- sender_email,
- sender_name,
- sender_photo_url,
- sort_ts,
- created_at,
- updated_at,
- viewed_at,
- } = thread;
-
- Self {
- id,
- provider_id,
- owner_id: owner_id.to_string(),
- inbox_visible,
- is_read,
- is_draft,
- is_important,
- name,
- snippet,
- sender_email,
- sender_name,
- sender_photo_url,
- sort_ts,
- created_at,
- updated_at,
- viewed_at,
- }
- }
-}
-
-#[derive(Debug, ToSchema, Serialize, Deserialize)]
+#[derive(Debug, ToSchema, Serialize, Deserialize, Doppleganger)]
#[cfg_attr(feature = "ai_schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "camelCase")]
+#[dg(backward = Attachment)]
pub struct ApiAttachment {
id: Uuid,
message_id: Uuid,
@@ -167,37 +109,10 @@ pub struct ApiAttachment {
created_at: DateTime<Utc>,
}
-impl ApiAttachment {
- #[inline]
- fn new(model: Attachment) -> Self {
- let Attachment {
- id,
- thread_id: _,
- message_id,
- provider_attachment_id,
- filename,
- mime_type,
- size_bytes,
- content_id,
- created_at,
- } = model;
-
- ApiAttachment {
- id,
- message_id,
- provider_attachment_id,
- filename,
- mime_type,
- size_bytes,
- content_id,
- created_at,
- }
- }
-}
-
-#[derive(Debug, ToSchema, Serialize, Deserialize)]
+#[derive(Debug, ToSchema, Serialize, Deserialize, Doppleganger)]
#[cfg_attr(feature = "ai_schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "camelCase")]
+#[dg(backward = AttachmentMacro)]
pub struct ApiAttachmentMacro {
db_id: Uuid,
message_id: Uuid,
@@ -205,28 +120,10 @@ pub struct ApiAttachmentMacro {
item_type: String,
}
-impl ApiAttachmentMacro {
- #[inline]
- fn new(model: AttachmentMacro) -> Self {
- let AttachmentMacro {
- thread_id: _,
- db_id,
- message_id,
- item_id,
- item_type,
- } = model;
- ApiAttachmentMacro {
- db_id,
- message_id,
- item_id,
- item_type,
- }
- }
-}
-
-#[derive(Debug, ToSchema, Serialize, Deserialize)]
+#[derive(Debug, ToSchema, Serialize, Deserialize, Doppleganger)]
#[cfg_attr(feature = "ai_schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "camelCase")]
+#[dg(backward = Contact)]
pub struct ApiContact {
id: Uuid,
link_id: Uuid,
@@ -235,28 +132,6 @@ pub struct ApiContact {
sfs_photo_url: Option<String>,
}
-impl ApiContact {
- #[inline]
- fn new(model: Contact) -> Self {
- let Contact {
- id,
- thread_id: _,
- link_id,
- name,
- email_address,
- sfs_photo_url,
- } = model;
-
- ApiContact {
- id,
- link_id,
- name,
- email_address,
- sfs_photo_url,
- }
- }
-}
-
#[derive(Debug, ToSchema, Serialize, Deserialize)]
#[cfg_attr(feature = "ai_schema", derive(schemars::JsonSchema))]
pub struct ApiPaginatedThreadCursor {
@@ -271,7 +146,10 @@ impl ApiPaginatedThreadCursor {
items, next_cursor, ..
} = model;
ApiPaginatedThreadCursor {
- items: items.into_iter().map(ApiThreadPreviewCursor::new).collect(),
+ items: items
+ .into_iter()
+ .map(ApiThreadPreviewCursor::mirror)
+ .collect(),
next_cursor,
}
}
diff --git a/rust/cloud-storage/email/src/outbound/email_pg_repo.rs b/rust/cloud-storage/email/src/outbound/email_pg_repo.rs
index 3626a1d324..05d1547060 100644
--- a/rust/cloud-storage/email/src/outbound/email_pg_repo.rs
+++ b/rust/cloud-storage/email/src/outbound/email_pg_repo.rs
@@ -6,6 +6,7 @@ use crate::domain::{
ports::EmailRepo,
};
use db_types::*;
+use doppleganger::{Doppleganger, Mirror};
use macro_user_id::{cowlike::CowLike, user_id::MacroUserIdStr};
use sqlx::PgPool;
use uuid::Uuid;
@@ -122,7 +123,7 @@ impl EmailRepo for EmailPgRepo {
.fetch_all(&self.pool)
.await?
.into_iter()
- .map(AttachmentDbRow::into_model)
+ .map(AttachmentDbRow::mirror)
.collect())
}
@@ -156,13 +157,14 @@ impl EmailRepo for EmailPgRepo {
.fetch_all(&self.pool)
.await?
.into_iter()
- .map(AttachmentMacroDbRow::into_model)
+ .map(AttachmentMacroDbRow::mirror)
.collect())
}
async fn contacts_by_thread_ids(&self, thread_ids: &[Uuid]) -> Result<Vec<Contact>, Self::Err> {
// Define a struct to hold the joined results
- #[derive(Debug)]
+ #[derive(Debug, Doppleganger)]
+ #[dg(forward = Contact)]
struct ThreadContactResult {
thread_id: Uuid,
id: Uuid,
@@ -172,27 +174,6 @@ impl EmailRepo for EmailPgRepo {
sfs_photo_url: Option<String>,
}
- impl ThreadContactResult {
- fn into_model(self) -> Contact {
- let ThreadContactResult {
- thread_id,
- id,
- link_id,
- email_address,
- name,
- sfs_photo_url,
- } = self;
- Contact {
- id,
- link_id,
- thread_id,
- name,
- email_address,
- sfs_photo_url,
- }
- }
- }
-
Ok(sqlx::query_as!(
ThreadContactResult,
r#"
@@ -209,7 +190,7 @@ impl EmailRepo for EmailPgRepo {
.fetch_all(&self.pool)
.await?
.into_iter()
- .map(ThreadContactResult::into_model)
+ .map(ThreadContactResult::mirror)
.collect())
}
}
diff --git a/rust/cloud-storage/email/src/outbound/email_pg_repo/db_types.rs b/rust/cloud-storage/email/src/outbound/email_pg_repo/db_types.rs
index 7b560b4770..f1c4ddc0c7 100644
--- a/rust/cloud-storage/email/src/outbound/email_pg_repo/db_types.rs
+++ b/rust/cloud-storage/email/src/outbound/email_pg_repo/db_types.rs
@@ -1,9 +1,13 @@
use crate::domain::models::{Attachment, AttachmentMacro, EmailThreadPreview};
use chrono::{DateTime, Utc};
+use doppleganger::Doppleganger;
use macro_user_id::{cowlike::CowLike, user_id::MacroUserIdStr};
use uuid::Uuid;
+#[derive(Doppleganger)]
+#[dg(forward = AttachmentMacro)]
pub struct AttachmentMacroDbRow {
+ #[dg(rename = "db_id")]
pub id: Uuid,
pub message_id: Uuid,
pub item_id: Uuid,
@@ -12,30 +16,13 @@ pub struct AttachmentMacroDbRow {
dead_code,
reason = "We need this field to use query_as with the current query, but we never read it"
)]
- pub created_at: DateTime<Utc>,
+ #[dg(ignore)]
+ pub(crate) created_at: DateTime<Utc>,
pub thread_id: Uuid,
}
-impl AttachmentMacroDbRow {
- pub fn into_model(self) -> AttachmentMacro {
- let AttachmentMacroDbRow {
- id,
- message_id,
- item_id,
- item_type,
- created_at: _,
- thread_id,
- } = self;
- AttachmentMacro {
- thread_id,
- db_id: id,
- message_id,
- item_id,
- item_type,
- }
- }
-}
-
+#[derive(Doppleganger)]
+#[dg(forward = Attachment)]
pub struct AttachmentDbRow {
pub id: Uuid,
pub message_id: Uuid,
@@ -50,34 +37,6 @@ pub struct AttachmentDbRow {
pub thread_id: Uuid,
}
-impl AttachmentDbRow {
- pub fn into_model(self) -> Attachment {
- let AttachmentDbRow {
- id,
- message_id,
- provider_attachment_id,
- filename,
- mime_type,
- size_bytes,
- content_id,
- created_at,
- thread_id,
- } = self;
-
- Attachment {
- id,
- thread_id,
- message_id,
- provider_attachment_id,
- filename,
- mime_type,
- size_bytes,
- content_id,
- created_at,
- }
- }
-}
-
/// thread summary returned in preview cursor endpoint
#[derive(Debug, Clone)]
pub struct ThreadPreviewCursorDbRow {