Skip to content

Commit

Permalink
configure routes correctly, flatten FuncBindings struct, feedback fro…
Browse files Browse the repository at this point in the history
…m Victor!
  • Loading branch information
britmyerss committed Jul 1, 2024
1 parent b92534c commit bf23144
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 217 deletions.
6 changes: 0 additions & 6 deletions lib/dal/src/func/authoring/save.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ use crate::{
SchemaVariantId, WorkspaceSnapshotError,
};

// create_association
// delete_association(?)
// update_association

#[instrument(
name = "func.authoring.save_func.update_associations",
level = "debug",
Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions lib/dal/src/func/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
WsEvent::new(
ctx,
WsPayload::FuncBindingsUpdated(FuncBindingsWsEventPayload {
change_set_id: ctx.change_set_id(),
func_bindings,
bindings,
types,
}),
)
Expand Down
12 changes: 0 additions & 12 deletions lib/dal/src/func/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)?;
Expand Down
2 changes: 1 addition & 1 deletion lib/dal/src/socket/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ impl From<OutputSocket> 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,
}
}
}
130 changes: 11 additions & 119 deletions lib/sdf-server/src/server/service/v2.rs
Original file line number Diff line number Diff line change
@@ -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<AppState> {
const PREFIX: &str = "/workspaces/:workspace_id/change-sets/:change_set_id";

Router::new()
.route(
let mut router: Router<AppState> = 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<Json<Vec<frontend_types::SchemaVariant>>, 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<Json<frontend_types::SchemaVariant>, 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()
// }
// }
3 changes: 3 additions & 0 deletions lib/sdf-server/src/server/service/v2/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ pub fn v2_routes() -> Router<AppState> {
)
}

// 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<FuncCode> {
let func = Func::get_by_id_or_error(ctx, func_id).await?;
let code = func.code_plaintext()?.unwrap_or("".to_string());
Expand All @@ -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<String> {
let func = Func::get_by_id_or_error(ctx, func_id).await?;
let types = [
Expand Down
Loading

0 comments on commit bf23144

Please sign in to comment.