diff --git a/lib/dal/src/func/authoring/save.rs b/lib/dal/src/func/authoring/save.rs index 47bcac7944..852265cc42 100644 --- a/lib/dal/src/func/authoring/save.rs +++ b/lib/dal/src/func/authoring/save.rs @@ -18,10 +18,6 @@ use crate::{ SchemaVariantId, WorkspaceSnapshotError, }; -// create_association -// delete_association(?) -// update_association - #[instrument( name = "func.authoring.save_func.update_associations", level = "debug", @@ -366,8 +362,6 @@ pub(crate) async fn reset_attribute_prototype( AttributeValue::use_default_prototype(ctx, attribute_value_id).await?; return Ok(()); } - // Find the last locked schema variant's equivalent and set the prototype? - // regeneration? } // If we aren't trying to use the default prototype, or the default prototype is the same as the diff --git a/lib/dal/src/func/binding.rs b/lib/dal/src/func/binding.rs index af2a5acd64..6fe884434d 100644 --- a/lib/dal/src/func/binding.rs +++ b/lib/dal/src/func/binding.rs @@ -537,21 +537,22 @@ impl FuncBindings { #[serde(rename_all = "camelCase")] pub struct FuncBindingsWsEventPayload { change_set_id: ChangeSetId, - func_bindings: si_frontend_types::FuncBindings, + #[serde(flatten)] + bindings: si_frontend_types::FuncBindings, types: String, } impl WsEvent { pub async fn func_bindings_updated( ctx: &DalContext, - func_bindings: si_frontend_types::FuncBindings, + bindings: si_frontend_types::FuncBindings, types: String, ) -> WsEventResult { WsEvent::new( ctx, WsPayload::FuncBindingsUpdated(FuncBindingsWsEventPayload { change_set_id: ctx.change_set_id(), - func_bindings, + bindings, types, }), ) diff --git a/lib/dal/src/func/runner.rs b/lib/dal/src/func/runner.rs index 1708945985..c3e6fc90c0 100644 --- a/lib/dal/src/func/runner.rs +++ b/lib/dal/src/func/runner.rs @@ -1049,7 +1049,6 @@ impl FuncRunner { let mut funcs_and_secrets = vec![]; for secret_prop_id in secret_props { - // if manually set: do this let auth_funcs = Self::auth_funcs_for_secret_prop_id( ctx, secret_prop_id, @@ -1080,17 +1079,6 @@ impl FuncRunner { Err(other_err) => return Err(other_err)?, } } - // if not manually set - find input socket - // find connected / inferred matching output socket - // find component of output socket - // find sv of component - // get auth func for it - - // check it's secret props - repeat --- - // if manually set do the above - // if not, check input socket - - // on and on if let Some(value) = maybe_value { let key = Secret::key_from_value_in_attribute_value(value)?; diff --git a/lib/dal/src/socket/output.rs b/lib/dal/src/socket/output.rs index cc3d8fee45..fda9fc9118 100644 --- a/lib/dal/src/socket/output.rs +++ b/lib/dal/src/socket/output.rs @@ -496,7 +496,7 @@ impl From for frontend_types::OutputSocket { id: value.id.into(), name: value.name, //default to false, but figure out how to do this better - eligible_to_recieve_data: false, + eligible_to_receive_data: false, } } } diff --git a/lib/sdf-server/src/server/service/v2.rs b/lib/sdf-server/src/server/service/v2.rs index 8afd7ffdd7..75ed837f8c 100644 --- a/lib/sdf-server/src/server/service/v2.rs +++ b/lib/sdf-server/src/server/service/v2.rs @@ -1,128 +1,20 @@ -use axum::{routing::get, Router}; - use crate::server::state::AppState; +use axum::Router; + pub mod func; pub mod variant; pub fn routes() -> Router { const PREFIX: &str = "/workspaces/:workspace_id/change-sets/:change_set_id"; - - Router::new() - .route( + let mut router: Router = Router::new(); + router = router + .nest( &format!("{PREFIX}/schema-variants"), - get(variant::list_schema_variants), - ) - .route( - &format!("{PREFIX}/schema-variants/:schema_variant_id"), - get(variant::get_variant), + crate::server::service::v2::variant::v2_routes(), ) + .nest( + &format!("{PREFIX}/funcs"), + crate::server::service::v2::func::v2_routes(), + ); + router } - -// pub async fn list_schema_variants( -// HandlerContext(builder): HandlerContext, -// AccessBuilder(access_builder): AccessBuilder, -// PosthogClient(posthog_client): PosthogClient, -// OriginalUri(original_uri): OriginalUri, -// Path((_workspace_pk, change_set_id)): Path<(WorkspacePk, ChangeSetId)>, -// ) -> Result>, SchemaVariantsAPIError> { -// let ctx = builder -// .build(access_builder.build(change_set_id.into())) -// .await?; - -// let mut schema_variants = Vec::new(); - -// // NOTE(victor): This is not optimized, since it loops twice through the defaults, but it'll get the job done for now -// // determining the default should change soon, and then we can get rid of SchemaVariant::get_default_for_schema over here -// for schema_id in Schema::list_ids(&ctx).await? { -// let default_schema_variant = SchemaVariant::get_default_for_schema(&ctx, schema_id).await?; -// if !default_schema_variant.ui_hidden() { -// schema_variants.push( -// default_schema_variant -// .into_frontend_type(&ctx, schema_id) -// .await?, -// ) -// } - -// if let Some(unlocked) = SchemaVariant::get_unlocked_for_schema(&ctx, schema_id).await? { -// if !unlocked.ui_hidden() { -// schema_variants.push(unlocked.into_frontend_type(&ctx, schema_id).await?) -// } -// } -// } - -// track( -// &posthog_client, -// &ctx, -// &original_uri, -// "list_schema_variants", -// serde_json::json!({}), -// ); - -// Ok(Json(schema_variants)) -// } - -// pub async fn get_variant( -// HandlerContext(builder): HandlerContext, -// AccessBuilder(access_builder): AccessBuilder, -// PosthogClient(posthog_client): PosthogClient, -// OriginalUri(original_uri): OriginalUri, -// Path((_workspace_pk, change_set_id, schema_variant_id)): Path<( -// WorkspacePk, -// ChangeSetId, -// SchemaVariantId, -// )>, -// ) -> Result, SchemaVariantsAPIError> { -// let ctx = builder -// .build(access_builder.build(change_set_id.into())) -// .await?; - -// let schema_variant = SchemaVariant::get_by_id(&ctx, schema_variant_id).await?; -// let schema_id = SchemaVariant::schema_id_for_schema_variant_id(&ctx, schema_variant_id).await?; -// let schema_variant = schema_variant.into_frontend_type(&ctx, schema_id).await?; - -// // Ported from `lib/sdf-server/src/server/service/variant/get_variant.rs`, so changes may be -// // desired here... - -// track( -// &posthog_client, -// &ctx, -// &original_uri, -// "get_variant", -// serde_json::json!({ -// "schema_name": &schema_variant.schema_name, -// "variant_category": &schema_variant.category, -// "variant_menu_name": schema_variant.display_name, -// "variant_id": schema_variant.schema_variant_id, -// "schema_id": schema_variant.schema_id, -// "variant_component_type": schema_variant.component_type, -// }), -// ); - -// Ok(Json(schema_variant)) -// } - -// #[remain::sorted] -// #[derive(Debug, Error)] -// pub enum SchemaVariantsAPIError { -// #[error("schema error: {0}")] -// Schema(#[from] dal::SchemaError), -// #[error("schema error: {0}")] -// SchemaVariant(#[from] dal::SchemaVariantError), -// #[error("transactions error: {0}")] -// Transactions(#[from] dal::TransactionsError), -// } - -// impl IntoResponse for SchemaVariantsAPIError { -// fn into_response(self) -> Response { -// let status_code = match &self { -// Self::Transactions(dal::TransactionsError::BadWorkspaceAndChangeSet) => { -// StatusCode::FORBIDDEN -// } -// // When a graph node cannot be found for a schema variant, it is not found -// Self::SchemaVariant(dal::SchemaVariantError::NotFound(_)) => StatusCode::NOT_FOUND, -// _ => ApiError::DEFAULT_ERROR_STATUS_CODE, -// }; - -// ApiError::new(status_code, self).into_response() -// } -// } diff --git a/lib/sdf-server/src/server/service/v2/func.rs b/lib/sdf-server/src/server/service/v2/func.rs index 62ae1b0037..15ea312c31 100644 --- a/lib/sdf-server/src/server/service/v2/func.rs +++ b/lib/sdf-server/src/server/service/v2/func.rs @@ -147,6 +147,7 @@ pub fn v2_routes() -> Router { ) } +// helper to assemble the front end struct to return the code and types so SDF can decide when these events need to fire pub async fn get_code_response(ctx: &DalContext, func_id: FuncId) -> FuncAPIResult { let func = Func::get_by_id_or_error(ctx, func_id).await?; let code = func.code_plaintext()?.unwrap_or("".to_string()); @@ -156,6 +157,8 @@ pub async fn get_code_response(ctx: &DalContext, func_id: FuncId) -> FuncAPIResu types: get_types(ctx, func_id).await?, }) } + +// helper to get updated types to fire WSEvents so SDF can decide when these events need to fire pub async fn get_types(ctx: &DalContext, func_id: FuncId) -> FuncAPIResult { let func = Func::get_by_id_or_error(ctx, func_id).await?; let types = [ diff --git a/lib/sdf-server/src/server/service/v2/func/create_func.rs b/lib/sdf-server/src/server/service/v2/func/create_func.rs index 1434bbaa38..b5c8c3c767 100644 --- a/lib/sdf-server/src/server/service/v2/func/create_func.rs +++ b/lib/sdf-server/src/server/service/v2/func/create_func.rs @@ -10,12 +10,12 @@ use dal::{ authoring::FuncAuthoringClient, binding::{ AttributeArgumentBinding, AttributeFuncArgumentSource, AttributeFuncDestination, - EventualParent, FuncBindings, + EventualParent, }, FuncKind, }, schema::variant::leaves::{LeafInputLocation, LeafKind}, - ChangeSet, ChangeSetId, Func, WorkspacePk, WsEvent, + ChangeSet, ChangeSetId, WorkspacePk, WsEvent, }; use si_frontend_types::{self as frontend_types, FuncBinding, FuncCode, FuncSummary}; @@ -40,7 +40,6 @@ pub struct CreateFuncRequest { pub struct CreateFuncResponse { summary: FuncSummary, code: FuncCode, - binding: frontend_types::FuncBindings, } pub async fn create_func( @@ -64,7 +63,7 @@ pub async fn create_func( let force_change_set_id = ChangeSet::force_new(&mut ctx).await?; - let created_func_response = match request.kind { + let func = match request.kind { FuncKind::Action => { if let FuncBinding::Action { schema_variant_id: Some(schema_variant_id), @@ -72,23 +71,13 @@ pub async fn create_func( .. } = request.binding { - let created_func = FuncAuthoringClient::create_new_action_func( + FuncAuthoringClient::create_new_action_func( &ctx, request.name, kind.into(), schema_variant_id.into(), ) - .await?; - - let func = Func::get_by_id_or_error(&ctx, created_func.id).await?; - let binding = FuncBindings::from_func_id(&ctx, created_func.id) - .await? - .into_frontend_type(); - CreateFuncResponse { - summary: func.into_frontend_type(&ctx).await?, - code: get_code_response(&ctx, created_func.id).await?, - binding, - } + .await? } else { return Err(FuncAPIError::WrongFunctionKindForBinding); } @@ -129,24 +118,14 @@ pub async fn create_func( }); } - let created_func = FuncAuthoringClient::create_new_attribute_func( + FuncAuthoringClient::create_new_attribute_func( &ctx, request.name, eventual_parent, output_location, arg_bindings, ) - .await?; - - let binding = FuncBindings::from_func_id(&ctx, created_func.id) - .await? - .into_frontend_type(); - let func = Func::get_by_id_or_error(&ctx, created_func.id).await?; - CreateFuncResponse { - summary: func.into_frontend_type(&ctx).await?, - code: get_code_response(&ctx, func.id).await?, - binding, - } + .await? } else { return Err(FuncAPIError::WrongFunctionKindForBinding); } @@ -157,22 +136,12 @@ pub async fn create_func( func_id: _, } = request.binding { - let created_func = FuncAuthoringClient::create_new_auth_func( + FuncAuthoringClient::create_new_auth_func( &ctx, request.name, schema_variant_id.into(), ) - .await?; - - let binding = FuncBindings::from_func_id(&ctx, created_func.id) - .await? - .into_frontend_type(); - let new_func = Func::get_by_id_or_error(&ctx, created_func.id).await?; - CreateFuncResponse { - summary: new_func.into_frontend_type(&ctx).await?, - code: get_code_response(&ctx, created_func.id).await?, - binding, - } + .await? } else { return Err(FuncAPIError::WrongFunctionKindForBinding); } @@ -189,23 +158,14 @@ pub async fn create_func( } else { inputs.into_iter().map(|input| input.into()).collect() }; - let created_func = FuncAuthoringClient::create_new_leaf_func( + FuncAuthoringClient::create_new_leaf_func( &ctx, request.name, LeafKind::CodeGeneration, EventualParent::SchemaVariant(schema_variant_id.into()), &inputs, ) - .await?; - let binding = FuncBindings::from_func_id(&ctx, created_func.id) - .await? - .into_frontend_type(); - let new_func = Func::get_by_id_or_error(&ctx, created_func.id).await?; - CreateFuncResponse { - summary: new_func.into_frontend_type(&ctx).await?, - code: get_code_response(&ctx, created_func.id).await?, - binding, - } + .await? } else { return Err(FuncAPIError::WrongFunctionKindForBinding); } @@ -223,39 +183,25 @@ pub async fn create_func( inputs.into_iter().map(|input| input.into()).collect() }; - let created_func = FuncAuthoringClient::create_new_leaf_func( + FuncAuthoringClient::create_new_leaf_func( &ctx, request.name, LeafKind::Qualification, EventualParent::SchemaVariant(schema_variant_id.into()), &inputs, ) - .await?; - let binding = FuncBindings::from_func_id(&ctx, created_func.id) - .await? - .into_frontend_type(); - let new_func = Func::get_by_id_or_error(&ctx, created_func.id) - .await? - .into_frontend_type(&ctx) - .await?; - CreateFuncResponse { - summary: new_func, - code: get_code_response(&ctx, created_func.id).await?, - binding, - } + .await? } else { return Err(FuncAPIError::WrongFunctionKindForBinding); } } _ => return Err(FuncAPIError::WrongFunctionKindForBinding), }; - let types = get_types( - &ctx, - created_func_response.summary.func_id.into_raw_id().into(), - ) - .await?; - WsEvent::func_created(&ctx, created_func_response.summary.clone(), types) + let types = get_types(&ctx, func.id).await?; + let code = get_code_response(&ctx, func.id).await?; + let summary = func.into_frontend_type(&ctx).await?; + WsEvent::func_created(&ctx, summary.clone(), types) .await? .publish_on_commit(&ctx) .await?; @@ -266,9 +212,9 @@ pub async fn create_func( "created_func", serde_json::json!({ "how": "/func/created_func", - "func_id": created_func_response.summary.func_id, - "func_name": created_func_response.summary.name.to_owned(), - "func_kind": created_func_response.summary.kind, + "func_id": summary.func_id, + "func_name": summary.name.to_owned(), + "func_kind": summary.kind, }), ); @@ -280,5 +226,8 @@ pub async fn create_func( response = response.header("force_change_set_id", force_change_set_id.to_string()); } - Ok(response.body(serde_json::to_string(&created_func_response)?)?) + Ok(response.body(serde_json::to_string(&CreateFuncResponse { + summary, + code, + })?)?) } diff --git a/lib/si-frontend-types-rs/src/func.rs b/lib/si-frontend-types-rs/src/func.rs index e96ba63420..ca16e2d53e 100644 --- a/lib/si-frontend-types-rs/src/func.rs +++ b/lib/si-frontend-types-rs/src/func.rs @@ -30,6 +30,7 @@ pub struct FuncSummary { pub display_name: Option, pub is_locked: bool, pub arguments: Vec, + #[serde(flatten)] pub bindings: FuncBindings, } #[derive(Clone, Debug, Deserialize, Eq, Serialize, PartialEq)] diff --git a/lib/si-frontend-types-rs/src/schema_variant.rs b/lib/si-frontend-types-rs/src/schema_variant.rs index 1ec60f30c3..001f58bdfb 100644 --- a/lib/si-frontend-types-rs/src/schema_variant.rs +++ b/lib/si-frontend-types-rs/src/schema_variant.rs @@ -64,7 +64,7 @@ pub struct InputSocket { pub struct OutputSocket { pub id: OutputSocketId, pub name: String, - pub eligible_to_recieve_data: bool, + pub eligible_to_receive_data: bool, } #[derive(Clone, Debug, Deserialize, Eq, Serialize, PartialEq)] #[serde(rename_all = "camelCase")]