1mod ids;
2mod queries;
3mod tables;
4#[cfg(test)]
5pub mod tests;
6
7use crate::{executor::Executor, Error, Result};
8use anyhow::anyhow;
9use collections::{BTreeMap, HashMap, HashSet};
10use dashmap::DashMap;
11use futures::StreamExt;
12use rand::{prelude::StdRng, Rng, SeedableRng};
13use rpc::{
14 proto::{self},
15 ConnectionId, ExtensionMetadata,
16};
17use sea_orm::{
18 entity::prelude::*,
19 sea_query::{Alias, Expr, OnConflict},
20 ActiveValue, Condition, ConnectionTrait, DatabaseConnection, DatabaseTransaction, DbErr,
21 FromQueryResult, IntoActiveModel, IsolationLevel, JoinType, QueryOrder, QuerySelect, Statement,
22 TransactionTrait,
23};
24use semantic_version::SemanticVersion;
25use serde::{Deserialize, Serialize};
26use sqlx::{
27 migrate::{Migrate, Migration, MigrationSource},
28 Connection,
29};
30use std::ops::RangeInclusive;
31use std::{
32 fmt::Write as _,
33 future::Future,
34 marker::PhantomData,
35 ops::{Deref, DerefMut},
36 path::Path,
37 rc::Rc,
38 sync::Arc,
39 time::Duration,
40};
41use time::PrimitiveDateTime;
42use tokio::sync::{Mutex, OwnedMutexGuard};
43
44#[cfg(test)]
45pub use tests::TestDb;
46
47pub use ids::*;
48pub use queries::billing_subscriptions::CreateBillingSubscriptionParams;
49pub use queries::contributors::ContributorSelector;
50pub use sea_orm::ConnectOptions;
51pub use tables::user::Model as User;
52pub use tables::*;
53
54/// Database gives you a handle that lets you access the database.
55/// It handles pooling internally.
56pub struct Database {
57 options: ConnectOptions,
58 pool: DatabaseConnection,
59 rooms: DashMap<RoomId, Arc<Mutex<()>>>,
60 projects: DashMap<ProjectId, Arc<Mutex<()>>>,
61 rng: Mutex<StdRng>,
62 executor: Executor,
63 notification_kinds_by_id: HashMap<NotificationKindId, &'static str>,
64 notification_kinds_by_name: HashMap<String, NotificationKindId>,
65 #[cfg(test)]
66 runtime: Option<tokio::runtime::Runtime>,
67}
68
69// The `Database` type has so many methods that its impl blocks are split into
70// separate files in the `queries` folder.
71impl Database {
72 /// Connects to the database with the given options
73 pub async fn new(options: ConnectOptions, executor: Executor) -> Result<Self> {
74 sqlx::any::install_default_drivers();
75 Ok(Self {
76 options: options.clone(),
77 pool: sea_orm::Database::connect(options).await?,
78 rooms: DashMap::with_capacity(16384),
79 projects: DashMap::with_capacity(16384),
80 rng: Mutex::new(StdRng::seed_from_u64(0)),
81 notification_kinds_by_id: HashMap::default(),
82 notification_kinds_by_name: HashMap::default(),
83 executor,
84 #[cfg(test)]
85 runtime: None,
86 })
87 }
88
89 #[cfg(test)]
90 pub fn reset(&self) {
91 self.rooms.clear();
92 self.projects.clear();
93 }
94
95 /// Runs the database migrations.
96 pub async fn migrate(
97 &self,
98 migrations_path: &Path,
99 ignore_checksum_mismatch: bool,
100 ) -> anyhow::Result<Vec<(Migration, Duration)>> {
101 let migrations = MigrationSource::resolve(migrations_path)
102 .await
103 .map_err(|err| anyhow!("failed to load migrations: {err:?}"))?;
104
105 let mut connection = sqlx::AnyConnection::connect(self.options.get_url()).await?;
106
107 connection.ensure_migrations_table().await?;
108 let applied_migrations: HashMap<_, _> = connection
109 .list_applied_migrations()
110 .await?
111 .into_iter()
112 .map(|m| (m.version, m))
113 .collect();
114
115 let mut new_migrations = Vec::new();
116 for migration in migrations {
117 match applied_migrations.get(&migration.version) {
118 Some(applied_migration) => {
119 if migration.checksum != applied_migration.checksum && !ignore_checksum_mismatch
120 {
121 Err(anyhow!(
122 "checksum mismatch for applied migration {}",
123 migration.description
124 ))?;
125 }
126 }
127 None => {
128 let elapsed = connection.apply(&migration).await?;
129 new_migrations.push((migration, elapsed));
130 }
131 }
132 }
133
134 Ok(new_migrations)
135 }
136
137 /// Transaction runs things in a transaction. If you want to call other methods
138 /// and pass the transaction around you need to reborrow the transaction at each
139 /// call site with: `&*tx`.
140 pub async fn transaction<F, Fut, T>(&self, f: F) -> Result<T>
141 where
142 F: Send + Fn(TransactionHandle) -> Fut,
143 Fut: Send + Future<Output = Result<T>>,
144 {
145 let body = async {
146 let mut i = 0;
147 loop {
148 let (tx, result) = self.with_transaction(&f).await?;
149 match result {
150 Ok(result) => match tx.commit().await.map_err(Into::into) {
151 Ok(()) => return Ok(result),
152 Err(error) => {
153 if !self.retry_on_serialization_error(&error, i).await {
154 return Err(error);
155 }
156 }
157 },
158 Err(error) => {
159 tx.rollback().await?;
160 if !self.retry_on_serialization_error(&error, i).await {
161 return Err(error);
162 }
163 }
164 }
165 i += 1;
166 }
167 };
168
169 self.run(body).await
170 }
171
172 pub async fn weak_transaction<F, Fut, T>(&self, f: F) -> Result<T>
173 where
174 F: Send + Fn(TransactionHandle) -> Fut,
175 Fut: Send + Future<Output = Result<T>>,
176 {
177 let body = async {
178 let (tx, result) = self.with_weak_transaction(&f).await?;
179 match result {
180 Ok(result) => match tx.commit().await.map_err(Into::into) {
181 Ok(()) => return Ok(result),
182 Err(error) => {
183 return Err(error);
184 }
185 },
186 Err(error) => {
187 tx.rollback().await?;
188 return Err(error);
189 }
190 }
191 };
192
193 self.run(body).await
194 }
195
196 /// The same as room_transaction, but if you need to only optionally return a Room.
197 async fn optional_room_transaction<F, Fut, T>(
198 &self,
199 f: F,
200 ) -> Result<Option<TransactionGuard<T>>>
201 where
202 F: Send + Fn(TransactionHandle) -> Fut,
203 Fut: Send + Future<Output = Result<Option<(RoomId, T)>>>,
204 {
205 let body = async {
206 let mut i = 0;
207 loop {
208 let (tx, result) = self.with_transaction(&f).await?;
209 match result {
210 Ok(Some((room_id, data))) => {
211 let lock = self.rooms.entry(room_id).or_default().clone();
212 let _guard = lock.lock_owned().await;
213 match tx.commit().await.map_err(Into::into) {
214 Ok(()) => {
215 return Ok(Some(TransactionGuard {
216 data,
217 _guard,
218 _not_send: PhantomData,
219 }));
220 }
221 Err(error) => {
222 if !self.retry_on_serialization_error(&error, i).await {
223 return Err(error);
224 }
225 }
226 }
227 }
228 Ok(None) => match tx.commit().await.map_err(Into::into) {
229 Ok(()) => return Ok(None),
230 Err(error) => {
231 if !self.retry_on_serialization_error(&error, i).await {
232 return Err(error);
233 }
234 }
235 },
236 Err(error) => {
237 tx.rollback().await?;
238 if !self.retry_on_serialization_error(&error, i).await {
239 return Err(error);
240 }
241 }
242 }
243 i += 1;
244 }
245 };
246
247 self.run(body).await
248 }
249
250 async fn project_transaction<F, Fut, T>(
251 &self,
252 project_id: ProjectId,
253 f: F,
254 ) -> Result<TransactionGuard<T>>
255 where
256 F: Send + Fn(TransactionHandle) -> Fut,
257 Fut: Send + Future<Output = Result<T>>,
258 {
259 let room_id = Database::room_id_for_project(&self, project_id).await?;
260 let body = async {
261 let mut i = 0;
262 loop {
263 let lock = if let Some(room_id) = room_id {
264 self.rooms.entry(room_id).or_default().clone()
265 } else {
266 self.projects.entry(project_id).or_default().clone()
267 };
268 let _guard = lock.lock_owned().await;
269 let (tx, result) = self.with_transaction(&f).await?;
270 match result {
271 Ok(data) => match tx.commit().await.map_err(Into::into) {
272 Ok(()) => {
273 return Ok(TransactionGuard {
274 data,
275 _guard,
276 _not_send: PhantomData,
277 });
278 }
279 Err(error) => {
280 if !self.retry_on_serialization_error(&error, i).await {
281 return Err(error);
282 }
283 }
284 },
285 Err(error) => {
286 tx.rollback().await?;
287 if !self.retry_on_serialization_error(&error, i).await {
288 return Err(error);
289 }
290 }
291 }
292 i += 1;
293 }
294 };
295
296 self.run(body).await
297 }
298
299 /// room_transaction runs the block in a transaction. It returns a RoomGuard, that keeps
300 /// the database locked until it is dropped. This ensures that updates sent to clients are
301 /// properly serialized with respect to database changes.
302 async fn room_transaction<F, Fut, T>(
303 &self,
304 room_id: RoomId,
305 f: F,
306 ) -> Result<TransactionGuard<T>>
307 where
308 F: Send + Fn(TransactionHandle) -> Fut,
309 Fut: Send + Future<Output = Result<T>>,
310 {
311 let body = async {
312 let mut i = 0;
313 loop {
314 let lock = self.rooms.entry(room_id).or_default().clone();
315 let _guard = lock.lock_owned().await;
316 let (tx, result) = self.with_transaction(&f).await?;
317 match result {
318 Ok(data) => match tx.commit().await.map_err(Into::into) {
319 Ok(()) => {
320 return Ok(TransactionGuard {
321 data,
322 _guard,
323 _not_send: PhantomData,
324 });
325 }
326 Err(error) => {
327 if !self.retry_on_serialization_error(&error, i).await {
328 return Err(error);
329 }
330 }
331 },
332 Err(error) => {
333 tx.rollback().await?;
334 if !self.retry_on_serialization_error(&error, i).await {
335 return Err(error);
336 }
337 }
338 }
339 i += 1;
340 }
341 };
342
343 self.run(body).await
344 }
345
346 async fn with_transaction<F, Fut, T>(&self, f: &F) -> Result<(DatabaseTransaction, Result<T>)>
347 where
348 F: Send + Fn(TransactionHandle) -> Fut,
349 Fut: Send + Future<Output = Result<T>>,
350 {
351 let tx = self
352 .pool
353 .begin_with_config(Some(IsolationLevel::Serializable), None)
354 .await?;
355
356 let mut tx = Arc::new(Some(tx));
357 let result = f(TransactionHandle(tx.clone())).await;
358 let Some(tx) = Arc::get_mut(&mut tx).and_then(|tx| tx.take()) else {
359 return Err(anyhow!(
360 "couldn't complete transaction because it's still in use"
361 ))?;
362 };
363
364 Ok((tx, result))
365 }
366
367 async fn with_weak_transaction<F, Fut, T>(
368 &self,
369 f: &F,
370 ) -> Result<(DatabaseTransaction, Result<T>)>
371 where
372 F: Send + Fn(TransactionHandle) -> Fut,
373 Fut: Send + Future<Output = Result<T>>,
374 {
375 let tx = self
376 .pool
377 .begin_with_config(Some(IsolationLevel::ReadCommitted), None)
378 .await?;
379
380 let mut tx = Arc::new(Some(tx));
381 let result = f(TransactionHandle(tx.clone())).await;
382 let Some(tx) = Arc::get_mut(&mut tx).and_then(|tx| tx.take()) else {
383 return Err(anyhow!(
384 "couldn't complete transaction because it's still in use"
385 ))?;
386 };
387
388 Ok((tx, result))
389 }
390
391 async fn run<F, T>(&self, future: F) -> Result<T>
392 where
393 F: Future<Output = Result<T>>,
394 {
395 #[cfg(test)]
396 {
397 if let Executor::Deterministic(executor) = &self.executor {
398 executor.simulate_random_delay().await;
399 }
400
401 self.runtime.as_ref().unwrap().block_on(future)
402 }
403
404 #[cfg(not(test))]
405 {
406 future.await
407 }
408 }
409
410 async fn retry_on_serialization_error(&self, error: &Error, prev_attempt_count: usize) -> bool {
411 // If the error is due to a failure to serialize concurrent transactions, then retry
412 // this transaction after a delay. With each subsequent retry, double the delay duration.
413 // Also vary the delay randomly in order to ensure different database connections retry
414 // at different times.
415 const SLEEPS: [f32; 10] = [10., 20., 40., 80., 160., 320., 640., 1280., 2560., 5120.];
416 if is_serialization_error(error) && prev_attempt_count < SLEEPS.len() {
417 let base_delay = SLEEPS[prev_attempt_count];
418 let randomized_delay = base_delay * self.rng.lock().await.gen_range(0.5..=2.0);
419 log::warn!(
420 "retrying transaction after serialization error. delay: {} ms.",
421 randomized_delay
422 );
423 self.executor
424 .sleep(Duration::from_millis(randomized_delay as u64))
425 .await;
426 true
427 } else {
428 false
429 }
430 }
431}
432
433fn is_serialization_error(error: &Error) -> bool {
434 const SERIALIZATION_FAILURE_CODE: &str = "40001";
435 match error {
436 Error::Database(
437 DbErr::Exec(sea_orm::RuntimeErr::SqlxError(error))
438 | DbErr::Query(sea_orm::RuntimeErr::SqlxError(error)),
439 ) if error
440 .as_database_error()
441 .and_then(|error| error.code())
442 .as_deref()
443 == Some(SERIALIZATION_FAILURE_CODE) =>
444 {
445 true
446 }
447 _ => false,
448 }
449}
450
451/// A handle to a [`DatabaseTransaction`].
452pub struct TransactionHandle(Arc<Option<DatabaseTransaction>>);
453
454impl Deref for TransactionHandle {
455 type Target = DatabaseTransaction;
456
457 fn deref(&self) -> &Self::Target {
458 self.0.as_ref().as_ref().unwrap()
459 }
460}
461
462/// [`TransactionGuard`] keeps a database transaction alive until it is dropped.
463/// It wraps data that depends on the state of the database and prevents an additional
464/// transaction from starting that would invalidate that data.
465pub struct TransactionGuard<T> {
466 data: T,
467 _guard: OwnedMutexGuard<()>,
468 _not_send: PhantomData<Rc<()>>,
469}
470
471impl<T> Deref for TransactionGuard<T> {
472 type Target = T;
473
474 fn deref(&self) -> &T {
475 &self.data
476 }
477}
478
479impl<T> DerefMut for TransactionGuard<T> {
480 fn deref_mut(&mut self) -> &mut T {
481 &mut self.data
482 }
483}
484
485impl<T> TransactionGuard<T> {
486 /// Returns the inner value of the guard.
487 pub fn into_inner(self) -> T {
488 self.data
489 }
490}
491
492#[derive(Clone, Debug, PartialEq, Eq)]
493pub enum Contact {
494 Accepted { user_id: UserId, busy: bool },
495 Outgoing { user_id: UserId },
496 Incoming { user_id: UserId },
497}
498
499impl Contact {
500 pub fn user_id(&self) -> UserId {
501 match self {
502 Contact::Accepted { user_id, .. } => *user_id,
503 Contact::Outgoing { user_id } => *user_id,
504 Contact::Incoming { user_id, .. } => *user_id,
505 }
506 }
507}
508
509pub type NotificationBatch = Vec<(UserId, proto::Notification)>;
510
511pub struct CreatedChannelMessage {
512 pub message_id: MessageId,
513 pub participant_connection_ids: HashSet<ConnectionId>,
514 pub notifications: NotificationBatch,
515}
516
517pub struct UpdatedChannelMessage {
518 pub message_id: MessageId,
519 pub participant_connection_ids: Vec<ConnectionId>,
520 pub notifications: NotificationBatch,
521 pub reply_to_message_id: Option<MessageId>,
522 pub timestamp: PrimitiveDateTime,
523 pub deleted_mention_notification_ids: Vec<NotificationId>,
524 pub updated_mention_notifications: Vec<rpc::proto::Notification>,
525}
526
527#[derive(Clone, Debug, PartialEq, Eq, FromQueryResult, Serialize, Deserialize)]
528pub struct Invite {
529 pub email_address: String,
530 pub email_confirmation_code: String,
531}
532
533#[derive(Clone, Debug, Deserialize)]
534pub struct NewSignup {
535 pub email_address: String,
536 pub platform_mac: bool,
537 pub platform_windows: bool,
538 pub platform_linux: bool,
539 pub editor_features: Vec<String>,
540 pub programming_languages: Vec<String>,
541 pub device_id: Option<String>,
542 pub added_to_mailing_list: bool,
543 pub created_at: Option<DateTime>,
544}
545
546#[derive(Clone, Debug, PartialEq, Deserialize, Serialize, FromQueryResult)]
547pub struct WaitlistSummary {
548 pub count: i64,
549 pub linux_count: i64,
550 pub mac_count: i64,
551 pub windows_count: i64,
552 pub unknown_count: i64,
553}
554
555/// The parameters to create a new user.
556#[derive(Debug, Serialize, Deserialize)]
557pub struct NewUserParams {
558 pub github_login: String,
559 pub github_user_id: i32,
560}
561
562/// The result of creating a new user.
563#[derive(Debug)]
564pub struct NewUserResult {
565 pub user_id: UserId,
566 pub metrics_id: String,
567 pub inviting_user_id: Option<UserId>,
568 pub signup_device_id: Option<String>,
569}
570
571/// The result of updating a channel membership.
572#[derive(Debug)]
573pub struct MembershipUpdated {
574 pub channel_id: ChannelId,
575 pub new_channels: ChannelsForUser,
576 pub removed_channels: Vec<ChannelId>,
577}
578
579/// The result of setting a member's role.
580#[derive(Debug)]
581#[allow(clippy::large_enum_variant)]
582pub enum SetMemberRoleResult {
583 InviteUpdated(Channel),
584 MembershipUpdated(MembershipUpdated),
585}
586
587/// The result of inviting a member to a channel.
588#[derive(Debug)]
589pub struct InviteMemberResult {
590 pub channel: Channel,
591 pub notifications: NotificationBatch,
592}
593
594#[derive(Debug)]
595pub struct RespondToChannelInvite {
596 pub membership_update: Option<MembershipUpdated>,
597 pub notifications: NotificationBatch,
598}
599
600#[derive(Debug)]
601pub struct RemoveChannelMemberResult {
602 pub membership_update: MembershipUpdated,
603 pub notification_id: Option<NotificationId>,
604}
605
606#[derive(Debug, PartialEq, Eq, Hash)]
607pub struct Channel {
608 pub id: ChannelId,
609 pub name: String,
610 pub visibility: ChannelVisibility,
611 /// parent_path is the channel ids from the root to this one (not including this one)
612 pub parent_path: Vec<ChannelId>,
613}
614
615impl Channel {
616 pub fn from_model(value: channel::Model) -> Self {
617 Channel {
618 id: value.id,
619 visibility: value.visibility,
620 name: value.clone().name,
621 parent_path: value.ancestors().collect(),
622 }
623 }
624
625 pub fn to_proto(&self) -> proto::Channel {
626 proto::Channel {
627 id: self.id.to_proto(),
628 name: self.name.clone(),
629 visibility: self.visibility.into(),
630 parent_path: self.parent_path.iter().map(|c| c.to_proto()).collect(),
631 }
632 }
633}
634
635#[derive(Debug, PartialEq, Eq, Hash)]
636pub struct ChannelMember {
637 pub role: ChannelRole,
638 pub user_id: UserId,
639 pub kind: proto::channel_member::Kind,
640}
641
642impl ChannelMember {
643 pub fn to_proto(&self) -> proto::ChannelMember {
644 proto::ChannelMember {
645 role: self.role.into(),
646 user_id: self.user_id.to_proto(),
647 kind: self.kind.into(),
648 }
649 }
650}
651
652#[derive(Debug, PartialEq)]
653pub struct ChannelsForUser {
654 pub channels: Vec<Channel>,
655 pub channel_memberships: Vec<channel_member::Model>,
656 pub channel_participants: HashMap<ChannelId, Vec<UserId>>,
657 pub hosted_projects: Vec<proto::HostedProject>,
658 pub invited_channels: Vec<Channel>,
659
660 pub observed_buffer_versions: Vec<proto::ChannelBufferVersion>,
661 pub observed_channel_messages: Vec<proto::ChannelMessageId>,
662 pub latest_buffer_versions: Vec<proto::ChannelBufferVersion>,
663 pub latest_channel_messages: Vec<proto::ChannelMessageId>,
664}
665
666#[derive(Debug)]
667pub struct RejoinedChannelBuffer {
668 pub buffer: proto::RejoinedChannelBuffer,
669 pub old_connection_id: ConnectionId,
670}
671
672#[derive(Clone)]
673pub struct JoinRoom {
674 pub room: proto::Room,
675 pub channel: Option<channel::Model>,
676}
677
678pub struct RejoinedRoom {
679 pub room: proto::Room,
680 pub rejoined_projects: Vec<RejoinedProject>,
681 pub reshared_projects: Vec<ResharedProject>,
682 pub channel: Option<channel::Model>,
683}
684
685pub struct ResharedProject {
686 pub id: ProjectId,
687 pub old_connection_id: ConnectionId,
688 pub collaborators: Vec<ProjectCollaborator>,
689 pub worktrees: Vec<proto::WorktreeMetadata>,
690}
691
692pub struct RejoinedProject {
693 pub id: ProjectId,
694 pub old_connection_id: ConnectionId,
695 pub collaborators: Vec<ProjectCollaborator>,
696 pub worktrees: Vec<RejoinedWorktree>,
697 pub language_servers: Vec<proto::LanguageServer>,
698}
699
700impl RejoinedProject {
701 pub fn to_proto(&self) -> proto::RejoinedProject {
702 proto::RejoinedProject {
703 id: self.id.to_proto(),
704 worktrees: self
705 .worktrees
706 .iter()
707 .map(|worktree| proto::WorktreeMetadata {
708 id: worktree.id,
709 root_name: worktree.root_name.clone(),
710 visible: worktree.visible,
711 abs_path: worktree.abs_path.clone(),
712 })
713 .collect(),
714 collaborators: self
715 .collaborators
716 .iter()
717 .map(|collaborator| collaborator.to_proto())
718 .collect(),
719 language_servers: self.language_servers.clone(),
720 }
721 }
722}
723
724#[derive(Debug)]
725pub struct RejoinedWorktree {
726 pub id: u64,
727 pub abs_path: String,
728 pub root_name: String,
729 pub visible: bool,
730 pub updated_entries: Vec<proto::Entry>,
731 pub removed_entries: Vec<u64>,
732 pub updated_repositories: Vec<proto::RepositoryEntry>,
733 pub removed_repositories: Vec<u64>,
734 pub diagnostic_summaries: Vec<proto::DiagnosticSummary>,
735 pub settings_files: Vec<WorktreeSettingsFile>,
736 pub scan_id: u64,
737 pub completed_scan_id: u64,
738}
739
740pub struct LeftRoom {
741 pub room: proto::Room,
742 pub channel: Option<channel::Model>,
743 pub left_projects: HashMap<ProjectId, LeftProject>,
744 pub canceled_calls_to_user_ids: Vec<UserId>,
745 pub deleted: bool,
746}
747
748pub struct RefreshedRoom {
749 pub room: proto::Room,
750 pub channel: Option<channel::Model>,
751 pub stale_participant_user_ids: Vec<UserId>,
752 pub canceled_calls_to_user_ids: Vec<UserId>,
753}
754
755pub struct RefreshedChannelBuffer {
756 pub connection_ids: Vec<ConnectionId>,
757 pub collaborators: Vec<proto::Collaborator>,
758}
759
760pub struct Project {
761 pub id: ProjectId,
762 pub role: ChannelRole,
763 pub collaborators: Vec<ProjectCollaborator>,
764 pub worktrees: BTreeMap<u64, Worktree>,
765 pub language_servers: Vec<proto::LanguageServer>,
766 pub dev_server_project_id: Option<DevServerProjectId>,
767}
768
769pub struct ProjectCollaborator {
770 pub connection_id: ConnectionId,
771 pub user_id: UserId,
772 pub replica_id: ReplicaId,
773 pub is_host: bool,
774}
775
776impl ProjectCollaborator {
777 pub fn to_proto(&self) -> proto::Collaborator {
778 proto::Collaborator {
779 peer_id: Some(self.connection_id.into()),
780 replica_id: self.replica_id.0 as u32,
781 user_id: self.user_id.to_proto(),
782 }
783 }
784}
785
786#[derive(Debug)]
787pub struct LeftProject {
788 pub id: ProjectId,
789 pub should_unshare: bool,
790 pub connection_ids: Vec<ConnectionId>,
791}
792
793pub struct Worktree {
794 pub id: u64,
795 pub abs_path: String,
796 pub root_name: String,
797 pub visible: bool,
798 pub entries: Vec<proto::Entry>,
799 pub repository_entries: BTreeMap<u64, proto::RepositoryEntry>,
800 pub diagnostic_summaries: Vec<proto::DiagnosticSummary>,
801 pub settings_files: Vec<WorktreeSettingsFile>,
802 pub scan_id: u64,
803 pub completed_scan_id: u64,
804}
805
806#[derive(Debug)]
807pub struct WorktreeSettingsFile {
808 pub path: String,
809 pub content: String,
810}
811
812pub struct NewExtensionVersion {
813 pub name: String,
814 pub version: semver::Version,
815 pub description: String,
816 pub authors: Vec<String>,
817 pub repository: String,
818 pub schema_version: i32,
819 pub wasm_api_version: Option<String>,
820 pub published_at: PrimitiveDateTime,
821}
822
823pub struct ExtensionVersionConstraints {
824 pub schema_versions: RangeInclusive<i32>,
825 pub wasm_api_versions: RangeInclusive<SemanticVersion>,
826}