Skip to content

Commit

Permalink
feat(components): Start implementing finish_push (#26336)
Browse files Browse the repository at this point in the history
This PR adds the `finish_push` endpoint for applying a push. There's still a lot TODO, but I've updated the test script in #26035 to call it.

GitOrigin-RevId: 6f6213d1d5ec0836639a4ba9fc589e590a4db046
  • Loading branch information
sujayakar authored and Convex, Inc. committed May 28, 2024
1 parent fa14679 commit 25bbff3
Show file tree
Hide file tree
Showing 13 changed files with 860 additions and 48 deletions.
15 changes: 15 additions & 0 deletions crates/common/src/bootstrap_model/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ pub struct ComponentMetadata {
pub component_type: ComponentType,
}

impl ComponentMetadata {
pub fn parent_and_name(&self) -> Option<(InternalId, ComponentName)> {
match &self.component_type {
ComponentType::App => None,
ComponentType::ChildComponent { parent, name, .. } => Some((*parent, name.clone())),
}
}
}

#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(any(test, feature = "testing"), derive(proptest_derive::Arbitrary))]
pub enum ComponentType {
Expand All @@ -36,6 +45,12 @@ pub enum ComponentType {
},
}

impl ComponentType {
pub fn is_root(&self) -> bool {
matches!(self, ComponentType::App)
}
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
struct SerializedComponentMetadata {
Expand Down
20 changes: 20 additions & 0 deletions crates/common/src/components/component_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ use value::identifier::Identifier;
#[cfg_attr(any(test, feature = "testing"), derive(proptest_derive::Arbitrary))]
pub struct ComponentName(Identifier);

impl ComponentName {
pub fn min() -> Self {
Self(Identifier::min())
}
}

impl FromStr for ComponentName {
type Err = anyhow::Error;

Expand Down Expand Up @@ -67,6 +73,20 @@ impl ComponentPath {
pub fn is_root(&self) -> bool {
self.path.is_empty()
}

pub fn parent(&self) -> Option<(Self, ComponentName)> {
let mut path = self.path.clone();
match path.pop() {
None => None,
Some(name) => Some((Self { path }, name)),
}
}

pub fn join(&self, name: ComponentName) -> Self {
let mut path = self.path.clone();
path.push(name);
Self { path }
}
}

impl Deref for ComponentPath {
Expand Down
6 changes: 6 additions & 0 deletions crates/convex/sync_types/src/identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ pub fn is_valid_identifier(s: &str) -> bool {
#[derive(Clone, Debug, PartialEq, PartialOrd, Ord, Eq, Hash)]
pub struct Identifier(String);

impl Identifier {
pub fn min() -> Self {
Identifier(MIN_IDENTIFIER.to_string())
}
}

impl FromStr for Identifier {
type Err = anyhow::Error;

Expand Down
41 changes: 40 additions & 1 deletion crates/database/src/bootstrap_model/components/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
pub mod definition;

use std::sync::LazyLock;
use std::{
collections::BTreeMap,
sync::LazyLock,
};

use anyhow::Context;
use common::{
Expand All @@ -13,6 +16,7 @@ use common::{
CanonicalizedComponentFunctionPath,
CanonicalizedComponentModulePath,
ComponentDefinitionId,
ComponentDefinitionPath,
ComponentId,
ComponentName,
ComponentPath,
Expand Down Expand Up @@ -145,6 +149,21 @@ impl<'a, RT: Runtime> BootstrapComponentsModel<'a, RT> {
Ok(Some(component_doc))
}

pub async fn load_all_components(
&mut self,
) -> anyhow::Result<Vec<ParsedDocument<ComponentMetadata>>> {
let mut query = ResolvedQuery::new(
self.tx,
TableNamespace::Global,
Query::full_table_scan(COMPONENTS_TABLE.clone(), Order::Asc),
)?;
let mut components = Vec::new();
while let Some(doc) = query.next(self.tx, None).await? {
components.push(doc.try_into()?);
}
Ok(components)
}

pub async fn get_component_path(
&mut self,
mut component_id: ComponentId,
Expand Down Expand Up @@ -248,6 +267,26 @@ impl<'a, RT: Runtime> BootstrapComponentsModel<'a, RT> {
Ok(doc)
}

pub async fn load_all_definitions(
&mut self,
) -> anyhow::Result<
BTreeMap<ComponentDefinitionPath, ParsedDocument<ComponentDefinitionMetadata>>,
> {
let mut query = ResolvedQuery::new(
self.tx,
TableNamespace::Global,
Query::full_table_scan(COMPONENT_DEFINITIONS_TABLE.clone(), Order::Asc),
)?;
let mut definitions = BTreeMap::new();
while let Some(doc) = query.next(self.tx, None).await? {
let definition: ParsedDocument<ComponentDefinitionMetadata> = doc.try_into()?;
anyhow::ensure!(definitions
.insert(definition.path.clone(), definition)
.is_none());
}
Ok(definitions)
}

pub async fn function_path_to_module(
&mut self,
path: CanonicalizedComponentFunctionPath,
Expand Down
4 changes: 3 additions & 1 deletion crates/indexing/src/index_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,9 @@ impl IndexRegistry {
}
match self.get_pending(index_name) {
Some(_) => anyhow::bail!(index_backfilling_error(printable_index_name)),
None => anyhow::bail!(index_not_found_error(printable_index_name)),
None => {
anyhow::bail!(index_not_found_error(printable_index_name))
},
}
}

Expand Down
Loading

0 comments on commit 25bbff3

Please sign in to comment.