Skip to content

Commit

Permalink
Feat: Delete outdated schema variant endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
vbustamante committed Jul 26, 2024
1 parent 491230a commit d2bbdbd
Show file tree
Hide file tree
Showing 12 changed files with 116 additions and 275 deletions.
17 changes: 9 additions & 8 deletions app/web/src/store/asset.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,16 @@ export const useAssetStore = () => {
const workspaceStore = useWorkspacesStore();
const workspaceId = workspaceStore.selectedWorkspacePk;

const changeSetsStore = useChangeSetsStore();
const selectedChangeSetId = changeSetsStore.selectedChangeSet?.id;

const funcStore = useFuncStore();
const moduleStore = useModuleStore();

let assetSaveDebouncer: ReturnType<typeof keyedDebouncer> | undefined;

const API_PREFIX = `v2/workspaces/${workspaceId}/change-sets/${selectedChangeSetId}/schema-variants`;

return addStoreHooks(
defineStore(`ws${workspaceId || "NONE"}/cs${changeSetId || "NONE"}/asset`, {
state: () => ({
Expand Down Expand Up @@ -432,7 +437,7 @@ export const useAssetStore = () => {

async LOAD_SCHEMA_VARIANT_LIST() {
return new ApiRequest<SchemaVariant[], Visibility>({
url: `v2/workspaces/${workspaceId}/change-sets/${changeSetId}/schema-variants`,
url: `${API_PREFIX}`,
params: { ...visibility },
onSuccess: (response) => {
this.variantList = response;
Expand All @@ -450,12 +455,8 @@ export const useAssetStore = () => {

return new ApiRequest<SchemaVariant>({
method: "post",
url: "/variant/create_unlocked_copy",
url: `${API_PREFIX}/${id}`,
keyRequestStatusBy: id,
params: {
...visibility,
id,
},
onSuccess: (variant) => {
const savedAssetIdx = this.variantList.findIndex(
(a) => a.schemaVariantId === variant.schemaVariantId,
Expand All @@ -473,8 +474,8 @@ export const useAssetStore = () => {
changeSetStore.creatingChangeSet = true;

return new ApiRequest<SchemaVariant>({
method: "post",
url: `v2/workspaces/${workspaceId}/change-sets/${changeSetId}/schema-variants/${id}/delete_unlocked_variant`,
method: "delete",
url: `${API_PREFIX}/${id}`,
keyRequestStatusBy: id,
params: {
// ...visibility,
Expand Down
87 changes: 42 additions & 45 deletions lib/dal/src/schema/variant.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,43 @@
//! This module contains [`SchemaVariant`](SchemaVariant), which is the "class" of a [`Component`](crate::Component).
use std::collections::{HashMap, HashSet, VecDeque};
use std::sync::Arc;

use chrono::Utc;
use petgraph::{Direction, Incoming, Outgoing};
use serde::{Deserialize, Serialize};
use si_events::{ulid::Ulid, ContentHash};
use thiserror::Error;
use url::ParseError;

pub use json::SchemaVariantJson;
pub use json::SchemaVariantMetadataJson;
pub use metadata_view::SchemaVariantMetadataView;
use si_events::{ContentHash, ulid::Ulid};
use si_frontend_types as frontend_types;
use si_layer_cache::LayerDbError;
use si_pkg::SpecError;
use std::collections::{HashMap, HashSet, VecDeque};
use std::sync::Arc;
use telemetry::prelude::*;
use thiserror::Error;
use url::ParseError;
pub use value_from::ValueFrom;

use crate::{
ActionPrototypeId, AttributePrototype,
AttributePrototypeId,
ChangeSetId, ComponentId, ComponentType, DalContext, Func,
FuncId, HelperError, implement_add_edge_to, InputSocket, OutputSocket, OutputSocketId, pk,
Prop, PropId, PropKind, Schema, schema::variant::leaves::{LeafInput, LeafInputLocation, LeafKind}, SchemaError, SchemaId, Timestamp,
TransactionsError, WsEvent, WsEventResult, WsPayload,
};
use crate::{AttributeValue, Component, ComponentError, FuncBackendResponseType, InputSocketId};
use crate::action::prototype::{ActionKind, ActionPrototype};
use crate::attribute::prototype::argument::{
AttributePrototypeArgument, AttributePrototypeArgumentError,
};
use crate::attribute::prototype::AttributePrototypeError;
use crate::attribute::value::{AttributeValueError, ValueIsFor};
use crate::change_set::ChangeSetError;
use crate::func::{FuncError, FuncKind};
use crate::func::argument::{FuncArgument, FuncArgumentError};
use crate::func::intrinsics::IntrinsicFunc;
use crate::func::{FuncError, FuncKind};
use crate::layer_db_types::{
ContentTypeError, InputSocketContent, OutputSocketContent, SchemaVariantContent,
SchemaVariantContentV2,
Expand All @@ -39,15 +54,6 @@ use crate::workspace_snapshot::edge_weight::{
use crate::workspace_snapshot::graph::NodeIndex;
use crate::workspace_snapshot::node_weight::{NodeWeight, NodeWeightError, PropNodeWeight};
use crate::workspace_snapshot::WorkspaceSnapshotError;
use crate::{
implement_add_edge_to, pk,
schema::variant::leaves::{LeafInput, LeafInputLocation, LeafKind},
ActionPrototypeId, AttributePrototype, AttributePrototypeId, ChangeSetId, ComponentId,
ComponentType, DalContext, Func, FuncId, HelperError, InputSocket, OutputSocket,
OutputSocketId, Prop, PropId, PropKind, Schema, SchemaError, SchemaId, Timestamp,
TransactionsError, WsEvent, WsEventResult, WsPayload,
};
use crate::{AttributeValue, Component, ComponentError, FuncBackendResponseType, InputSocketId};

use self::root_prop::RootPropChild;

Expand All @@ -58,11 +64,6 @@ mod metadata_view;
pub mod root_prop;
mod value_from;

pub use json::SchemaVariantJson;
pub use json::SchemaVariantMetadataJson;
pub use metadata_view::SchemaVariantMetadataView;
pub use value_from::ValueFrom;

// FIXME(nick,theo): colors should be required for all schema variants.
// There should be no default in the backend as there should always be a color.
pub const DEFAULT_SCHEMA_VARIANT_COLOR: &str = "#00b0bc";
Expand Down Expand Up @@ -334,7 +335,7 @@ impl WsEvent {
change_set_id: ctx.change_set_id(),
}),
)
.await
.await
}

#[allow(clippy::too_many_arguments)]
Expand Down Expand Up @@ -366,7 +367,7 @@ impl WsEvent {
change_set_id: ctx.change_set_id(),
}),
)
.await
.await
}

pub async fn schema_variant_cloned(
Expand All @@ -380,7 +381,7 @@ impl WsEvent {
change_set_id: ctx.change_set_id(),
}),
)
.await
.await
}

pub async fn schema_variant_update_finished(
Expand All @@ -396,7 +397,7 @@ impl WsEvent {
change_set_id: ctx.change_set_id(),
}),
)
.await
.await
}
}

Expand Down Expand Up @@ -553,7 +554,6 @@ impl SchemaVariant {
}

let schema = variant.schema(ctx).await?;
dbg!(&schema);

// Firstly we want to delete the asset func
let asset_func = variant.get_asset_func(ctx).await?;
Expand All @@ -562,10 +562,7 @@ impl SchemaVariant {
let workspace_snapshot = ctx.workspace_snapshot()?;

if let Some(default_schema_variant_id) = schema.get_default_schema_variant_id(ctx).await? {
dbg!(&default_schema_variant_id);
if variant.id == default_schema_variant_id {
dbg!("Deletion of the schema");
dbg!(&schema);
workspace_snapshot
.remove_node_by_id(ctx.vector_clock_id()?, schema.id())
.await?;
Expand All @@ -586,7 +583,7 @@ impl SchemaVariant {
sv.is_locked = true;
Ok(())
})
.await
.await
}

/// Returns all [`PropIds`](Prop) for a given [`SchemaVariantId`](SchemaVariant).
Expand Down Expand Up @@ -787,9 +784,9 @@ impl SchemaVariant {
Ok(Self::is_default_by_id(ctx, id).await?
&& Self::is_locked_by_id(ctx, id).await?
&& Module::find_for_member_id(ctx, id)
.await
.map_err(|e| SchemaVariantError::Module(e.to_string()))?
.is_none())
.await
.map_err(|e| SchemaVariantError::Module(e.to_string()))?
.is_none())
}

pub async fn get_latest_for_schema(
Expand Down Expand Up @@ -1023,7 +1020,7 @@ impl SchemaVariant {
attribute_prototype.id(),
EdgeWeightKind::Prototype(None),
)
.await?;
.await?;
}

// Push all children onto the work queue.
Expand Down Expand Up @@ -1174,7 +1171,7 @@ impl SchemaVariant {
func_id,
EdgeWeightKind::AuthenticationPrototype,
)
.await?;
.await?;
Ok(())
}

Expand Down Expand Up @@ -1344,7 +1341,7 @@ impl SchemaVariant {
schema_variant_id,
&PropPath::new(["root", leaf_map_prop_name, leaf_item_prop_name]),
)
.await?)
.await?)
}

pub async fn upsert_leaf_function(
Expand Down Expand Up @@ -1382,8 +1379,8 @@ impl SchemaVariant {
for existing_arg in existing_args.drain(..) {
if !inputs.iter().any(
|&LeafInput {
func_argument_id, ..
}| func_argument_id == existing_arg.id,
func_argument_id, ..
}| func_argument_id == existing_arg.id,
) {
FuncArgument::remove(ctx, existing_arg.id).await?;
}
Expand All @@ -1398,7 +1395,7 @@ impl SchemaVariant {
existing_proto_id,
schema_variant_id,
)
.await?;
.await?;
existing_proto_id
}
None => {
Expand All @@ -1415,8 +1412,8 @@ impl SchemaVariant {
component_id,
leaf_kind,
)
.await
.map_err(Box::new)?;
.await
.map_err(Box::new)?;

let new_attribute_value = AttributeValue::new(
ctx,
Expand All @@ -1425,8 +1422,8 @@ impl SchemaVariant {
Some(parent_attribute_value_id),
key.clone(),
)
.await
.map_err(Box::new)?;
.await
.map_err(Box::new)?;
new_attribute_value_ids.push(new_attribute_value.id);
}
if !new_attribute_value_ids.is_empty() {
Expand Down Expand Up @@ -1478,16 +1475,16 @@ impl SchemaVariant {
attribute_prototype_id,
input.func_argument_id,
)
.await?;
.await?;
new_apa.set_value_from_prop_id(ctx, input_prop_id).await?;
}
}

for (apa_id, func_arg_id) in apa_func_arg_ids {
if !inputs.iter().any(
|&LeafInput {
func_argument_id, ..
}| { func_argument_id == func_arg_id },
func_argument_id, ..
}| { func_argument_id == func_arg_id },
) {
AttributePrototypeArgument::remove(ctx, *apa_id).await?;
}
Expand Down
31 changes: 21 additions & 10 deletions lib/dal/src/schema/variant/authoring.rs
Original file line number Diff line number Diff line change
@@ -1,41 +1,42 @@
use std::collections::HashMap;
use std::fmt::Debug;

use base64::engine::general_purpose;
use base64::Engine;
use base64::engine::general_purpose;
use chrono::Utc;
use convert_case::{Case, Casing};
use pkg::import::import_schema_variant;
use serde::{Deserialize, Serialize};
use serde_json::error::Category;
use si_events::ulid::Ulid;
use thiserror::Error;

use pkg::import::import_schema_variant;
use si_events::FuncRunId;
use si_events::ulid::Ulid;
use si_layer_cache::LayerDbError;
use si_pkg::{
FuncSpec, FuncSpecBackendKind, FuncSpecBackendResponseType, FuncSpecData, MergeSkip, PkgSpec,
SchemaVariantSpec, SiPkg, SiPkgError, SpecError,
};
use telemetry::prelude::*;
use thiserror::Error;

use crate::{
Component, ComponentError, ComponentType, DalContext, Func, FuncBackendKind, FuncBackendResponseType,
FuncError, FuncId, HistoryEventError, pkg, Schema, SchemaError, SchemaId,
SchemaVariant, SchemaVariantError, SchemaVariantId,
};
use crate::action::prototype::ActionPrototypeError;
use crate::attribute::prototype::argument::AttributePrototypeArgumentError;
use crate::attribute::prototype::AttributePrototypeError;
use crate::func::authoring::FuncAuthoringError;
use crate::func::intrinsics::IntrinsicFunc;
use crate::func::runner::{FuncRunner, FuncRunnerError};
use crate::pkg::{import_pkg_from_pkg, ImportOptions, PkgError};
use crate::pkg::export::PkgExporter;
use crate::pkg::import::import_only_new_funcs;
use crate::pkg::{import_pkg_from_pkg, ImportOptions, PkgError};
use crate::prop::PropError;
use crate::schema::variant::{SchemaVariantJson, SchemaVariantMetadataJson};
use crate::socket::input::InputSocketError;
use crate::socket::output::OutputSocketError;
use crate::{
pkg, Component, ComponentError, ComponentType, DalContext, Func, FuncBackendKind,
FuncBackendResponseType, FuncError, FuncId, HistoryEventError, Schema, SchemaError, SchemaId,
SchemaVariant, SchemaVariantError, SchemaVariantId,
};

#[allow(missing_docs)]
#[remain::sorted]
Expand All @@ -51,6 +52,8 @@ pub enum VariantAuthoringError {
AttributePrototypeArgument(#[from] AttributePrototypeArgumentError),
#[error("component error: {0}")]
Component(#[from] ComponentError),
#[error("there already exists a Schema with the name {0}")]
DuplicatedSchemaName(String),
#[error("empty value within func run value (FuncId {0} and FuncRunId {1})")]
EmptyValueWithinFuncRunValue(FuncId, FuncRunId),
#[error("func error: {0}")]
Expand Down Expand Up @@ -133,6 +136,10 @@ impl VariantAuthoringClient {
color: impl Into<String>,
) -> VariantAuthoringResult<SchemaVariant> {
let name = name.into();
if Schema::is_name_taken(ctx, &name).await? {
return Err(VariantAuthoringError::DuplicatedSchemaName(name))
};

let variant_version = SchemaVariant::generate_version_string();

let code_base64 = general_purpose::STANDARD_NO_PAD.encode(DEFAULT_ASSET_CODE);
Expand Down Expand Up @@ -204,6 +211,10 @@ impl VariantAuthoringClient {
schema_variant_id: SchemaVariantId,
schema_name: String,
) -> VariantAuthoringResult<(SchemaVariant, Schema)> {
if Schema::is_name_taken(ctx, &schema_name).await? {
return Err(VariantAuthoringError::DuplicatedSchemaName(schema_name))
};

let variant = SchemaVariant::get_by_id_or_error(ctx, schema_variant_id).await?;
let schema = variant.schema(ctx).await?;

Expand Down
7 changes: 5 additions & 2 deletions lib/dal/src/workspace_snapshot/content_address.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use serde::{Deserialize, Serialize};
use si_events::ContentHash;
use strum::EnumDiscriminants;

use si_events::ContentHash;

#[remain::sorted]
#[derive(
EnumDiscriminants, Debug, Serialize, Deserialize, Copy, Clone, PartialEq, Eq, strum::Display,
Expand Down Expand Up @@ -30,7 +31,9 @@ pub enum ContentAddress {
Secret(ContentHash),
StaticArgumentValue(ContentHash),
ValidationOutput(ContentHash),
ValidationPrototype(ContentHash), // TODO(victor): Remove this after module index gets new data
// With validations moving to the props and not having prototypes anymore, this is unused
// TODO(victor): remove this as soon as it does not break graph (de)serialization
ValidationPrototype(ContentHash),
}

impl ContentAddress {
Expand Down
Loading

0 comments on commit d2bbdbd

Please sign in to comment.