-
Notifications
You must be signed in to change notification settings - Fork 541
feat: sync foundation - types, schema, API stubs, client state, hashing #4213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
devin-ai-integration
wants to merge
2
commits into
main
Choose a base branch
from
devin/1771944285-sync-foundation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| use axum::body::Bytes; | ||
| use axum::extract::Path; | ||
| use axum::http::StatusCode; | ||
| use uuid::Uuid; | ||
|
|
||
| use crate::error::Result; | ||
|
|
||
| /// POST /vaults/:vault_id/blobs -- upload blob | ||
| pub async fn upload_blob(Path(_vault_id): Path<Uuid>, _body: Bytes) -> Result<StatusCode> { | ||
| Err(crate::error::SyncError::Internal( | ||
| "not implemented".to_string(), | ||
| )) | ||
| } | ||
|
|
||
| /// HEAD /vaults/:vault_id/blobs/:hash -- check blob existence | ||
| pub async fn check_blob(Path((_vault_id, _hash)): Path<(Uuid, String)>) -> Result<StatusCode> { | ||
| Err(crate::error::SyncError::Internal( | ||
| "not implemented".to_string(), | ||
| )) | ||
| } | ||
|
|
||
| /// GET /vaults/:vault_id/blobs/:hash -- download blob | ||
| pub async fn download_blob(Path((_vault_id, _hash)): Path<(Uuid, String)>) -> Result<Bytes> { | ||
| Err(crate::error::SyncError::Internal( | ||
| "not implemented".to_string(), | ||
| )) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| use axum::Json; | ||
| use axum::extract::{Path, Query}; | ||
| use axum::http::StatusCode; | ||
| use serde::Deserialize; | ||
| use uuid::Uuid; | ||
|
|
||
| use crate::error::Result; | ||
| use crate::types::{PullOpsResponse, PushOpsRequest, PushOpsResponse}; | ||
|
|
||
| #[derive(Deserialize)] | ||
| pub struct PullOpsQuery { | ||
| pub cursor: Option<i64>, | ||
|
Check warning on line 12 in crates/api-sync/src/routes/ops.rs
|
||
| pub limit: Option<i64>, | ||
| } | ||
|
|
||
| /// POST /vaults/:vault_id/ops -- push operations | ||
| pub async fn push_ops( | ||
| Path(_vault_id): Path<Uuid>, | ||
| Json(_body): Json<PushOpsRequest>, | ||
| ) -> Result<(StatusCode, Json<PushOpsResponse>)> { | ||
| Err(crate::error::SyncError::Internal( | ||
| "not implemented".to_string(), | ||
| )) | ||
| } | ||
|
|
||
| /// GET /vaults/:vault_id/ops?cursor=N&limit=100 -- pull operations | ||
| pub async fn pull_ops( | ||
| Path(_vault_id): Path<Uuid>, | ||
| Query(_query): Query<PullOpsQuery>, | ||
| ) -> Result<Json<PullOpsResponse>> { | ||
| Err(crate::error::SyncError::Internal( | ||
| "not implemented".to_string(), | ||
| )) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| use axum::Json; | ||
| use axum::extract::Path; | ||
| use axum::http::StatusCode; | ||
| use uuid::Uuid; | ||
|
|
||
| use crate::error::Result; | ||
| use crate::types::{ | ||
| CreateVaultRequest, CreateVaultResponse, ListVaultsResponse, RegisterDeviceRequest, | ||
| RegisterDeviceResponse, | ||
| }; | ||
|
|
||
| /// POST /vaults -- create vault | ||
| pub async fn create_vault( | ||
| Json(_body): Json<CreateVaultRequest>, | ||
| ) -> Result<(StatusCode, Json<CreateVaultResponse>)> { | ||
| Err(crate::error::SyncError::Internal( | ||
| "not implemented".to_string(), | ||
| )) | ||
| } | ||
|
|
||
| /// GET /vaults -- list user's vaults | ||
| pub async fn list_vaults() -> Result<Json<ListVaultsResponse>> { | ||
| Err(crate::error::SyncError::Internal( | ||
| "not implemented".to_string(), | ||
| )) | ||
| } | ||
|
|
||
| /// POST /vaults/:vault_id/devices -- register device | ||
| pub async fn register_device( | ||
| Path(_vault_id): Path<Uuid>, | ||
| Json(_body): Json<RegisterDeviceRequest>, | ||
| ) -> Result<(StatusCode, Json<RegisterDeviceResponse>)> { | ||
| Err(crate::error::SyncError::Internal( | ||
| "not implemented".to_string(), | ||
| )) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| use std::fmt; | ||
|
|
||
| use chrono::{DateTime, Utc}; | ||
| use serde::{Deserialize, Serialize}; | ||
| use uuid::Uuid; | ||
|
|
||
| // --- Newtypes --- | ||
|
|
||
| #[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] | ||
| pub struct VaultId(pub Uuid); | ||
|
|
||
| impl fmt::Display for VaultId { | ||
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| write!(f, "{}", self.0) | ||
| } | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] | ||
| pub struct FileId(pub Uuid); | ||
|
|
||
| impl fmt::Display for FileId { | ||
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| write!(f, "{}", self.0) | ||
| } | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] | ||
| pub struct DeviceId(pub Uuid); | ||
|
|
||
| impl fmt::Display for DeviceId { | ||
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| write!(f, "{}", self.0) | ||
| } | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] | ||
| pub struct BlobHash(pub String); | ||
|
|
||
| impl fmt::Display for BlobHash { | ||
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| write!(f, "{}", self.0) | ||
| } | ||
| } | ||
|
|
||
| // --- OpType --- | ||
|
|
||
| #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] | ||
| #[serde(rename_all = "snake_case")] | ||
| pub enum OpType { | ||
| Create, | ||
| Modify, | ||
| Move, | ||
| Delete, | ||
| } | ||
|
|
||
| // --- OperationPayload --- | ||
|
|
||
| #[derive(Debug, Clone, Serialize, Deserialize)] | ||
| #[serde(tag = "type", rename_all = "snake_case")] | ||
| pub enum OperationPayload { | ||
| /// Small content (< 256KB) -- stored inline in Postgres | ||
| Inline { content: Vec<u8> }, | ||
| /// Large content -- stored in S3, referenced by hash | ||
| BlobRef { hash: BlobHash, size_bytes: u64 }, | ||
| /// Move operation -- new path | ||
| MoveTo { new_path: String }, | ||
| /// Delete -- tombstone, no content | ||
| Tombstone, | ||
| } | ||
|
|
||
| // --- Operation --- | ||
|
|
||
| #[derive(Debug, Clone, Serialize, Deserialize)] | ||
| pub struct Operation { | ||
| pub id: Uuid, | ||
| pub vault_id: VaultId, | ||
| pub file_id: FileId, | ||
| pub author_user_id: Uuid, | ||
| pub author_device_id: DeviceId, | ||
| pub base_version: i64, | ||
| pub op_type: OpType, | ||
| pub payload: OperationPayload, | ||
| pub created_at: DateTime<Utc>, | ||
| /// Monotonic ordering for cursor-based pull | ||
| pub seq: i64, | ||
| } | ||
|
|
||
| // --- FileEntry --- | ||
|
|
||
| #[derive(Debug, Clone, Serialize, Deserialize)] | ||
| pub struct FileEntry { | ||
| pub id: FileId, | ||
| pub vault_id: VaultId, | ||
| pub path: String, | ||
| pub version: i64, | ||
| pub content_hash: Option<BlobHash>, | ||
| pub is_deleted: bool, | ||
| } | ||
|
|
||
| // --- Request/Response types --- | ||
|
|
||
| #[derive(Debug, Clone, Serialize, Deserialize)] | ||
| pub struct PushOperation { | ||
| pub file_id: FileId, | ||
| pub base_version: i64, | ||
| pub op_type: OpType, | ||
| pub payload: OperationPayload, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Serialize, Deserialize)] | ||
| pub struct PushOpsRequest { | ||
| pub ops: Vec<PushOperation>, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Serialize, Deserialize)] | ||
| pub struct PushOpsResponse { | ||
| pub accepted: Vec<Uuid>, | ||
| pub rejected: Vec<RejectedOp>, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Serialize, Deserialize)] | ||
| pub struct RejectedOp { | ||
| pub file_id: FileId, | ||
| pub reason: String, | ||
| pub current_version: i64, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Serialize, Deserialize)] | ||
| pub struct PullOpsResponse { | ||
| pub ops: Vec<Operation>, | ||
| pub next_cursor: Option<i64>, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Serialize, Deserialize)] | ||
| pub struct CreateVaultRequest { | ||
| pub name: Option<String>, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Serialize, Deserialize)] | ||
| pub struct CreateVaultResponse { | ||
| pub vault_id: VaultId, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Serialize, Deserialize)] | ||
| pub struct VaultInfo { | ||
| pub id: VaultId, | ||
| pub created_at: DateTime<Utc>, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Serialize, Deserialize)] | ||
| pub struct ListVaultsResponse { | ||
| pub vaults: Vec<VaultInfo>, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Serialize, Deserialize)] | ||
| pub struct RegisterDeviceRequest { | ||
| pub device_id: DeviceId, | ||
| pub name: String, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Serialize, Deserialize)] | ||
| pub struct RegisterDeviceResponse { | ||
| pub device_id: DeviceId, | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚩
SyncConfigusessupabase_anon_keybut the API typically needs service role keyAt
apps/api/src/main.rs:170,SyncConfigis constructed withsupabase_anon_key. Looking atcrates/api-sync/src/config.rs:11-17, the config storessupabase_anon_key. However, the server-side sync operations (creating vaults, managing files) will likely need thesupabase_service_role_keyfor admin-level database operations, similar to howNangoConfigatapps/api/src/main.rs:78usessupabase_service_role_key. This may need to be changed when the stub implementations are filled in.Was this helpful? React with 👍 or 👎 to provide feedback.