diff --git a/app/web/src/store/func/funcs.store.ts b/app/web/src/store/func/funcs.store.ts index d3da9c74ca..0c5dc8233c 100644 --- a/app/web/src/store/func/funcs.store.ts +++ b/app/web/src/store/func/funcs.store.ts @@ -190,7 +190,7 @@ export const useFuncStore = () => { return new ApiRequest<{ summary: FuncSummary; code: FuncCode }>({ method: "post", - url: `${API_PREFIX}/create`, + url: `${API_PREFIX}`, params: { ...createFuncRequest }, onSuccess: (response) => { // summary coming through the WsEvent @@ -208,7 +208,7 @@ export const useFuncStore = () => { ) { return new ApiRequest<{ summary: FuncSummary; code: FuncCode }>({ method: "post", - url: `${API_PREFIX}/${funcId}/create_unlocked_copy`, + url: `${API_PREFIX}/${funcId}`, params: { schemaVariantId, }, @@ -231,7 +231,7 @@ export const useFuncStore = () => { async DELETE_UNLOCKED_FUNC(funcId: FuncId) { return new ApiRequest({ method: "delete", - url: `${API_PREFIX}/${funcId}/delete`, + url: `${API_PREFIX}/${funcId}`, }); }, async UPDATE_FUNC(func: FuncSummary) { @@ -242,8 +242,8 @@ export const useFuncStore = () => { const isHead = changeSetsStore.headSelected; return new ApiRequest({ - method: "post", - url: `${API_PREFIX}/${func.funcId}/update`, + method: "put", + url: `${API_PREFIX}/${func.funcId}`, params: { displayName: func.displayName, description: func.description, @@ -275,7 +275,7 @@ export const useFuncStore = () => { return new ApiRequest<{ bindings: FuncBinding[] }>({ method: "post", - url: `${API_PREFIX}/${funcId}/bindings/create`, + url: `${API_PREFIX}/${funcId}/bindings`, params: { bindings, }, @@ -291,8 +291,8 @@ export const useFuncStore = () => { changeSetsStore.creatingChangeSet = true; return new ApiRequest({ - method: "post", - url: `${API_PREFIX}/${funcId}/bindings/update`, + method: "put", + url: `${API_PREFIX}/${funcId}/bindings`, params: { funcId, bindings, @@ -328,8 +328,8 @@ export const useFuncStore = () => { changeSetsStore.creatingChangeSet = true; return new ApiRequest({ - method: "post", - url: `${API_PREFIX}/${funcId}/bindings/delete`, + method: "delete", + url: `${API_PREFIX}/${funcId}/bindings`, params: { bindings, }, @@ -346,7 +346,7 @@ export const useFuncStore = () => { return new ApiRequest({ method: "post", - url: `${API_PREFIX}/${funcId}/create_argument`, + url: `${API_PREFIX}/${funcId}/arguments`, params: { ...funcArg, }, @@ -362,8 +362,8 @@ export const useFuncStore = () => { changeSetsStore.creatingChangeSet = true; return new ApiRequest({ - method: "post", - url: `${API_PREFIX}/${funcId}/${funcArg.id}/update`, + method: "put", + url: `${API_PREFIX}/${funcId}/arguments/${funcArg.id}`, params: { ...funcArg, }, @@ -382,8 +382,8 @@ export const useFuncStore = () => { changeSetsStore.creatingChangeSet = true; return new ApiRequest({ - method: "post", - url: `${API_PREFIX}/${funcId}/${funcArgumentId}/delete`, + method: "delete", + url: `${API_PREFIX}/${funcId}/arguments/${funcArgumentId}`, onFail: () => { changeSetsStore.creatingChangeSet = false; }, @@ -484,7 +484,7 @@ export const useFuncStore = () => { async SAVE_FUNC(func: FuncCode) { return new ApiRequest({ method: "post", - url: `${API_PREFIX}/${func.funcId}/save_code`, + url: `${API_PREFIX}/${func.funcId}/code`, params: { code: func.code }, onFail: () => { changeSetsStore.creatingChangeSet = false; diff --git a/app/web/src/store/func_runs.store.ts b/app/web/src/store/func_runs.store.ts index e29cbbfeed..3826a55195 100644 --- a/app/web/src/store/func_runs.store.ts +++ b/app/web/src/store/func_runs.store.ts @@ -134,6 +134,8 @@ export const useFuncRunsStore = () => { const changeSetsStore = useChangeSetsStore(); const changeSetId = changeSetsStore.selectedChangeSetId; + const API_PREFIX = `v2/workspaces/${workspaceId}/change-sets/${changeSetId}/funcs/runs`; + return addStoreHooks( defineStore(`ws${workspaceId || "NONE"}/func_runs`, { state: () => ({ @@ -143,12 +145,8 @@ export const useFuncRunsStore = () => { async GET_FUNC_RUN(funcRunId: FuncRunId) { // note: this lookup is not cached, always re-fetch, even though the payload is large. things may have changed since last load! return new ApiRequest({ - url: "/func/get_func_run", + url: `${API_PREFIX}/${funcRunId}`, headers: { accept: "application/json" }, - params: { - funcRunId, - visibility_change_set_pk: changeSetId, - }, onSuccess: (response) => { if (response.funcRun) { this.funcRuns[response.funcRun.id] = response.funcRun; diff --git a/lib/dal/src/func.rs b/lib/dal/src/func.rs index 481fffca12..b6f9f74a97 100644 --- a/lib/dal/src/func.rs +++ b/lib/dal/src/func.rs @@ -691,15 +691,14 @@ impl Func { .await .map_err(Box::new)? { - dbg!(&arg); // create new func args for the new func FuncArgument::new(ctx, arg.name, arg.kind, arg.element_kind, new_func.id) .await .map_err(Box::new)?; } - dbg!(FuncArgument::list_for_func(ctx, new_func.id) + FuncArgument::list_for_func(ctx, new_func.id) .await - .map_err(Box::new)?); + .map_err(Box::new)?; Ok(new_func) } diff --git a/lib/dal/src/func/binding/attribute.rs b/lib/dal/src/func/binding/attribute.rs index b27ba5f8e6..d02c4fd4c8 100644 --- a/lib/dal/src/func/binding/attribute.rs +++ b/lib/dal/src/func/binding/attribute.rs @@ -289,7 +289,6 @@ impl AttributeBinding { WorkspaceSnapshotGraphError::NodeWithIdNotFound(raw_id), ), ) if raw_id == arg.func_argument_id.into() => { - dbg!("raw id == arg.func_arg.id.into"); continue; } err => return Err(err.into()), diff --git a/lib/dal/tests/integration_test/func/authoring/binding/attribute.rs b/lib/dal/tests/integration_test/func/authoring/binding/attribute.rs index f94cc057bf..c930bc9db3 100644 --- a/lib/dal/tests/integration_test/func/authoring/binding/attribute.rs +++ b/lib/dal/tests/integration_test/func/authoring/binding/attribute.rs @@ -83,9 +83,9 @@ async fn create_attribute_prototype_with_attribute_prototype_argument(ctx: &mut .expect("could not perform find by name for func") .expect("func argument not found"); - dbg!(FuncArgument::list_for_func(ctx, func_id) + FuncArgument::list_for_func(ctx, func_id) .await - .expect("could list")); + .expect("could list"); let prototype_arguments = vec![AttributeArgumentBinding { func_argument_id: func_argument.id, attribute_prototype_argument_id: None, @@ -251,7 +251,6 @@ async fn detach_attribute_func(ctx: &mut DalContext) { .await .expect("unable to get the funcs for a schema variant"); let total_funcs = funcs.len(); - dbg!(&funcs); // Detach one attribute func to the schema variant and commit. let func_id = Func::find_id_by_name(ctx, "test:falloutEntriesToGalaxies") diff --git a/lib/dal/tests/integration_test/schema/variant/authoring/clone_variant.rs b/lib/dal/tests/integration_test/schema/variant/authoring/clone_variant.rs index 9b0c2f4c81..8abe1cad93 100644 --- a/lib/dal/tests/integration_test/schema/variant/authoring/clone_variant.rs +++ b/lib/dal/tests/integration_test/schema/variant/authoring/clone_variant.rs @@ -29,10 +29,11 @@ async fn clone_variant(ctx: &mut DalContext) { assert!(default_schema_variant.is_some()); + let clone_name = format!("{}-clone", schema.name().to_string()); let (new_schema_variant, _) = VariantAuthoringClient::new_schema_with_cloned_variant( ctx, default_schema_variant.expect("unable to get the schema variant id from the option"), - schema.name().to_string(), + dbg!(clone_name), ) .await .expect("unable to clone the schema variant"); diff --git a/lib/dal/tests/integration_test/schema/variant/authoring/update_variant.rs b/lib/dal/tests/integration_test/schema/variant/authoring/update_variant.rs index c615a08160..14df4030b8 100644 --- a/lib/dal/tests/integration_test/schema/variant/authoring/update_variant.rs +++ b/lib/dal/tests/integration_test/schema/variant/authoring/update_variant.rs @@ -632,14 +632,12 @@ async fn update_variant_with_leaf_func(ctx: &mut DalContext) { .expect("could not commit and update snapshot"); // Check the qualifications for all components. - let component_one_qualifications = - dbg!(Component::list_qualifications(ctx, component_one.id()) - .await - .expect("could not list qualifications")); - let component_two_qualifications = - dbg!(Component::list_qualifications(ctx, component_two.id()) - .await - .expect("could not list qualifications")); + let component_one_qualifications = Component::list_qualifications(ctx, component_one.id()) + .await + .expect("could not list qualifications"); + let component_two_qualifications = Component::list_qualifications(ctx, component_two.id()) + .await + .expect("could not list qualifications"); assert_eq!( 3, // expected diff --git a/lib/sdf-server/src/server/routes.rs b/lib/sdf-server/src/server/routes.rs index de03bc0b71..c46b766ddc 100644 --- a/lib/sdf-server/src/server/routes.rs +++ b/lib/sdf-server/src/server/routes.rs @@ -43,7 +43,6 @@ pub fn routes(state: AppState) -> Router { crate::server::service::component::routes(), ) .nest("/api/diagram", crate::server::service::diagram::routes()) - .nest("/api/func", crate::server::service::func::routes()) .nest("/api/graphviz", crate::server::service::graphviz::routes()) .nest( "/api/qualification", diff --git a/lib/sdf-server/src/server/service.rs b/lib/sdf-server/src/server/service.rs index 76c0f4983d..d37a4d7f15 100644 --- a/lib/sdf-server/src/server/service.rs +++ b/lib/sdf-server/src/server/service.rs @@ -11,7 +11,6 @@ pub mod attribute; pub mod change_set; pub mod component; pub mod diagram; -pub mod func; pub mod graphviz; pub mod module; pub mod node_debug; diff --git a/lib/sdf-server/src/server/service/dev.rs b/lib/sdf-server/src/server/service/dev.rs index 77a12896d1..e7bd01b850 100644 --- a/lib/sdf-server/src/server/service/dev.rs +++ b/lib/sdf-server/src/server/service/dev.rs @@ -14,8 +14,6 @@ use thiserror::Error; // }; use crate::server::state::AppState; -// use crate::service::dev::author_single_schema_with_default_variant::author_single_schema_with_default_variant; -use crate::service::func; #[remain::sorted] #[derive(Debug, Error)] @@ -34,8 +32,6 @@ pub enum DevError { #[error(transparent)] Pg(#[from] si_data_pg::PgError), #[error(transparent)] - SdfFunc(#[from] func::FuncError), - #[error(transparent)] StandardModel(#[from] StandardModelError), #[error("user error: {0}")] User(#[from] UserError), diff --git a/lib/sdf-server/src/server/service/func.rs b/lib/sdf-server/src/server/service/func.rs deleted file mode 100644 index 7ddf3636e9..0000000000 --- a/lib/sdf-server/src/server/service/func.rs +++ /dev/null @@ -1,139 +0,0 @@ -use crate::server::state::AppState; -use axum::http::StatusCode; -use axum::{ - response::{IntoResponse, Response}, - routing::{get, post}, - Json, Router, -}; -use dal::func::authoring::FuncAuthoringError; -use dal::func::summary::FuncSummaryError; -use dal::func::view::FuncViewError; -use dal::func::FuncAssociationsError; -use dal::input_sources::InputSourcesError; -use dal::schema::variant::SchemaVariantError; -use dal::{attribute::prototype::AttributePrototypeError, func::argument::FuncArgumentError}; -use dal::{workspace_snapshot::WorkspaceSnapshotError, FuncId, TransactionsError}; -use dal::{ChangeSetError, WsEventError}; -use si_layer_cache::LayerDbError; -use thiserror::Error; - -pub mod create_attribute_prototype; -pub mod create_func; -pub mod create_func_argument; -pub mod delete_func; -pub mod delete_func_argument; -pub mod get_func; -pub mod get_func_associations; -pub mod get_func_run; -pub mod list_func_arguments; -pub mod list_funcs; -pub mod list_input_sources; -pub mod remove_attribute_prototype; -pub mod save_and_exec; -pub mod save_func; -pub mod test_execute; -pub mod update_attribute_prototype; -pub mod update_func_argument; - -#[remain::sorted] -#[derive(Error, Debug)] -pub enum FuncError { - #[error("attribute prototype error: {0}")] - AttributePrototype(#[from] AttributePrototypeError), - #[error("change set error: {0}")] - ChangeSet(#[from] ChangeSetError), - #[error("dal func error: {0}")] - Func(#[from] dal::func::FuncError), - #[error("func argument error: {0}")] - FuncArgument(#[from] FuncArgumentError), - #[error("func associations error: {0}")] - FuncAssociations(#[from] FuncAssociationsError), - #[error("func authoring error: {0}")] - FuncAuthoring(#[from] FuncAuthoringError), - #[error("func {0} cannot be converted to frontend variant")] - FuncCannotBeTurnedIntoVariant(FuncId), - #[error("The function name \"{0}\" is reserved")] - FuncNameReserved(String), - #[error("func summary error: {0}")] - FuncSummary(#[from] FuncSummaryError), - #[error("func view error: {0}")] - FuncView(#[from] FuncViewError), - #[error("hyper error: {0}")] - Hyper(#[from] hyper::http::Error), - #[error("input sources error: {0}")] - InputSources(#[from] InputSourcesError), - #[error("layer db error: {0}")] - LayerDb(#[from] LayerDbError), - #[error("schema variant error: {0}")] - SchemaVariant(#[from] SchemaVariantError), - #[error("json serialization error: {0}")] - SerdeJson(#[from] serde_json::Error), - #[error("transaction error: {0}")] - Transactions(#[from] TransactionsError), - #[error("workspace snapshot error: {0}")] - WorkspaceSnapshot(#[from] WorkspaceSnapshotError), - #[error("could not publish websocket event: {0}")] - WsEvent(#[from] WsEventError), -} - -pub type FuncResult = Result; - -impl IntoResponse for FuncError { - fn into_response(self) -> Response { - let (status, error_message) = (StatusCode::INTERNAL_SERVER_ERROR, self.to_string()); - - let body = Json( - serde_json::json!({ "error": { "message": error_message, "code": 42, "statusCode": status.as_u16() } }), - ); - - (status, body).into_response() - } -} - -pub fn routes() -> Router { - Router::new() - .route( - "/create_attribute_prototype", - post(create_attribute_prototype::create_attribute_prototype), - ) - .route("/create_func", post(create_func::create_func)) - .route( - "/create_func_argument", - post(create_func_argument::create_func_argument), - ) - .route("/delete_func", post(delete_func::delete_func)) - .route( - "/delete_func_argument", - post(delete_func_argument::delete_func_argument), - ) - .route("/get_func", get(get_func::get_func)) - .route( - "/get_func_associations", - get(get_func_associations::get_func_associations), - ) - .route("/get_func_run", get(get_func_run::get_func_run)) - .route( - "/list_func_arguments", - get(list_func_arguments::list_func_arguments), - ) - .route("/list_funcs", get(list_funcs::list_funcs)) - .route( - "/list_input_sources", - get(list_input_sources::list_input_sources), - ) - .route( - "/remove_attribute_prototype", - post(remove_attribute_prototype::remove_attribute_prototype), - ) - .route("/save_and_exec", post(save_and_exec::save_and_exec)) - .route("/save_func", post(save_func::save_func)) - .route("/test_execute", post(test_execute::test_execute)) - .route( - "/update_attribute_prototype", - post(update_attribute_prototype::update_attribute_prototype), - ) - .route( - "/update_func_argument", - post(update_func_argument::update_func_argument), - ) -} diff --git a/lib/sdf-server/src/server/service/func/create_attribute_prototype.rs b/lib/sdf-server/src/server/service/func/create_attribute_prototype.rs deleted file mode 100644 index 47bbea13b9..0000000000 --- a/lib/sdf-server/src/server/service/func/create_attribute_prototype.rs +++ /dev/null @@ -1,57 +0,0 @@ -use axum::{response::IntoResponse, Json}; -use dal::func::authoring::FuncAuthoringClient; -use dal::func::AttributePrototypeArgumentBag; -use dal::{ - ChangeSet, ComponentId, FuncId, OutputSocketId, PropId, SchemaVariantId, Visibility, WsEvent, -}; -use serde::{Deserialize, Serialize}; - -use super::FuncResult; -use crate::server::extract::{AccessBuilder, HandlerContext}; - -#[derive(Deserialize, Serialize, Debug)] -#[serde(rename_all = "camelCase")] -pub struct CreateAttributePrototypeRequest { - func_id: FuncId, - schema_variant_id: SchemaVariantId, - component_id: Option, - prop_id: Option, - output_socket_id: Option, - prototype_arguments: Vec, - #[serde(flatten)] - pub visibility: Visibility, -} - -pub async fn create_attribute_prototype( - HandlerContext(builder): HandlerContext, - AccessBuilder(request_ctx): AccessBuilder, - Json(request): Json, -) -> FuncResult { - let mut ctx = builder.build(request_ctx.build(request.visibility)).await?; - let force_change_set_id = ChangeSet::force_new(&mut ctx).await?; - - FuncAuthoringClient::create_attribute_prototype( - &ctx, - request.func_id, - request.schema_variant_id, - request.component_id, - request.prop_id, - request.output_socket_id, - request.prototype_arguments, - ) - .await?; - - WsEvent::func_saved(&ctx, request.func_id) - .await? - .publish_on_commit(&ctx) - .await?; - - ctx.commit().await?; - - let mut response = axum::response::Response::builder(); - response = response.header("Content-Type", "application/json"); - if let Some(force_change_set_id) = force_change_set_id { - response = response.header("force_change_set_id", force_change_set_id.to_string()); - } - Ok(response.body(axum::body::Empty::new())?) -} diff --git a/lib/sdf-server/src/server/service/func/create_func.rs b/lib/sdf-server/src/server/service/func/create_func.rs deleted file mode 100644 index 7a18efde55..0000000000 --- a/lib/sdf-server/src/server/service/func/create_func.rs +++ /dev/null @@ -1,67 +0,0 @@ -use axum::extract::OriginalUri; -use axum::{response::IntoResponse, Json}; -use dal::func::authoring::{CreateFuncOptions, FuncAuthoringClient}; -use dal::func::FuncKind; -use dal::{ChangeSet, Visibility}; -use serde::{Deserialize, Serialize}; - -use super::FuncResult; -use crate::server::extract::{AccessBuilder, HandlerContext, PosthogClient}; -use crate::server::tracking::track; -use crate::service::func::FuncError; - -#[derive(Deserialize, Serialize, Debug)] -#[serde(rename_all = "camelCase")] -pub struct CreateFuncRequest { - kind: FuncKind, - name: Option, - options: Option, - #[serde(flatten)] - pub visibility: Visibility, -} - -pub async fn create_func( - HandlerContext(builder): HandlerContext, - AccessBuilder(request_ctx): AccessBuilder, - PosthogClient(posthog_client): PosthogClient, - OriginalUri(original_uri): OriginalUri, - Json(request): Json, -) -> FuncResult { - let mut ctx = builder.build(request_ctx.build(request.visibility)).await?; - - if let Some(name) = request.name.as_deref() { - if dal::func::is_intrinsic(name) - || ["si:resourcePayloadToValue", "si:normalizeToArray"].contains(&name) - { - return Err(FuncError::FuncNameReserved(name.into())); - } - } - - let force_change_set_id = ChangeSet::force_new(&mut ctx).await?; - - let created_func = - FuncAuthoringClient::create_func(&ctx, request.kind, request.name, request.options).await?; - - track( - &posthog_client, - &ctx, - &original_uri, - "created_func", - serde_json::json!({ - "how": "/func/created_func", - "func_id": created_func.id, - "func_handler": created_func.handler.as_ref().map(|h| h.to_owned()), - "func_name": created_func.name.to_owned(), - "func_kind": created_func.kind, - }), - ); - - ctx.commit().await?; - - let mut response = axum::response::Response::builder(); - response = response.header("Content-Type", "application/json"); - if let Some(force_change_set_id) = force_change_set_id { - response = response.header("force_change_set_id", force_change_set_id.to_string()); - } - Ok(response.body(serde_json::to_string(&created_func)?)?) -} diff --git a/lib/sdf-server/src/server/service/func/create_func_argument.rs b/lib/sdf-server/src/server/service/func/create_func_argument.rs deleted file mode 100644 index 5820aedcde..0000000000 --- a/lib/sdf-server/src/server/service/func/create_func_argument.rs +++ /dev/null @@ -1,51 +0,0 @@ -use axum::{response::IntoResponse, Json}; -use dal::func::argument::FuncArgumentKind; -use dal::func::authoring::FuncAuthoringClient; -use dal::{ChangeSet, FuncId, Visibility, WsEvent}; -use serde::{Deserialize, Serialize}; - -use super::FuncResult; -use crate::server::extract::{AccessBuilder, HandlerContext}; - -#[derive(Deserialize, Serialize, Debug)] -#[serde(rename_all = "camelCase")] -pub struct CreateFuncArgumentRequest { - func_id: FuncId, - name: String, - kind: FuncArgumentKind, - element_kind: Option, - #[serde(flatten)] - pub visibility: Visibility, -} - -pub async fn create_func_argument( - HandlerContext(builder): HandlerContext, - AccessBuilder(request_ctx): AccessBuilder, - Json(request): Json, -) -> FuncResult { - let mut ctx = builder.build(request_ctx.build(request.visibility)).await?; - let force_change_set_id = ChangeSet::force_new(&mut ctx).await?; - - FuncAuthoringClient::create_func_argument( - &ctx, - request.func_id, - request.name, - request.kind, - request.element_kind, - ) - .await?; - - WsEvent::func_arguments_saved(&ctx, request.func_id) - .await? - .publish_on_commit(&ctx) - .await?; - - ctx.commit().await?; - - let mut response = axum::response::Response::builder(); - response = response.header("Content-Type", "application/json"); - if let Some(force_change_set_id) = force_change_set_id { - response = response.header("force_change_set_id", force_change_set_id.to_string()); - } - Ok(response.body(axum::body::Empty::new())?) -} diff --git a/lib/sdf-server/src/server/service/func/delete_func.rs b/lib/sdf-server/src/server/service/func/delete_func.rs deleted file mode 100644 index fb99e38714..0000000000 --- a/lib/sdf-server/src/server/service/func/delete_func.rs +++ /dev/null @@ -1,66 +0,0 @@ -use axum::extract::OriginalUri; -use axum::{response::IntoResponse, Json}; -use dal::func::authoring::FuncAuthoringClient; -use dal::{ChangeSet, Func, FuncId, Visibility, WsEvent}; -use serde::{Deserialize, Serialize}; - -use super::FuncResult; -use crate::server::extract::{AccessBuilder, HandlerContext, PosthogClient}; -use crate::server::tracking::track; - -#[derive(Deserialize, Serialize, Debug)] -#[serde(rename_all = "camelCase")] -pub struct DeleteFuncRequest { - pub id: FuncId, - #[serde(flatten)] - pub visibility: Visibility, -} - -#[derive(Deserialize, Serialize, Debug)] -#[serde(rename_all = "camelCase")] -pub struct DeleteFuncResponse { - pub success: bool, -} - -pub async fn delete_func( - HandlerContext(builder): HandlerContext, - AccessBuilder(request_ctx): AccessBuilder, - PosthogClient(posthog_client): PosthogClient, - OriginalUri(original_uri): OriginalUri, - Json(request): Json, -) -> FuncResult { - let mut ctx = builder.build(request_ctx.build(request.visibility)).await?; - - let force_change_set_id = ChangeSet::force_new(&mut ctx).await?; - // first remove all existing associations - FuncAuthoringClient::detach_func_from_everywhere(&ctx, request.id).await?; - // then delete func - let func_name = Func::delete_by_id(&ctx, request.id).await?; - - track( - &posthog_client, - &ctx, - &original_uri, - "deleted_func", - serde_json::json!({ - "how": "/func/deleted_func", - "func_id": request.id, - "func_name": func_name, - }), - ); - - WsEvent::func_deleted(&ctx, request.id) - .await? - .publish_on_commit(&ctx) - .await?; - ctx.commit().await?; - - let mut response = axum::response::Response::builder(); - response = response.header("Content-Type", "application/json"); - if let Some(force_change_set_id) = force_change_set_id { - response = response.header("force_change_set_id", force_change_set_id.to_string()); - } - Ok(response.body(serde_json::to_string(&DeleteFuncResponse { - success: true, - })?)?) -} diff --git a/lib/sdf-server/src/server/service/func/delete_func_argument.rs b/lib/sdf-server/src/server/service/func/delete_func_argument.rs deleted file mode 100644 index 14a2dcaba8..0000000000 --- a/lib/sdf-server/src/server/service/func/delete_func_argument.rs +++ /dev/null @@ -1,42 +0,0 @@ -use axum::{response::IntoResponse, Json}; -use dal::func::argument::FuncArgumentId; -use dal::func::authoring::FuncAuthoringClient; -use dal::{ChangeSet, FuncId, Visibility, WsEvent}; -use serde::{Deserialize, Serialize}; - -use super::FuncResult; -use crate::server::extract::{AccessBuilder, HandlerContext}; - -#[derive(Deserialize, Serialize, Debug)] -#[serde(rename_all = "camelCase")] -pub struct DeleteFuncArgumentRequest { - func_id: FuncId, - func_argument_id: FuncArgumentId, - #[serde(flatten)] - pub visibility: Visibility, -} - -pub async fn delete_func_argument( - HandlerContext(builder): HandlerContext, - AccessBuilder(request_ctx): AccessBuilder, - Json(request): Json, -) -> FuncResult { - let mut ctx = builder.build(request_ctx.build(request.visibility)).await?; - let force_change_set_id = ChangeSet::force_new(&mut ctx).await?; - - FuncAuthoringClient::delete_func_argument(&ctx, request.func_argument_id).await?; - - WsEvent::func_arguments_saved(&ctx, request.func_id) - .await? - .publish_on_commit(&ctx) - .await?; - - ctx.commit().await?; - - let mut response = axum::response::Response::builder(); - response = response.header("Content-Type", "application/json"); - if let Some(force_change_set_id) = force_change_set_id { - response = response.header("force_change_set_id", force_change_set_id.to_string()); - } - Ok(response.body(axum::body::Empty::new())?) -} diff --git a/lib/sdf-server/src/server/service/func/get_func.rs b/lib/sdf-server/src/server/service/func/get_func.rs deleted file mode 100644 index 666d109cd9..0000000000 --- a/lib/sdf-server/src/server/service/func/get_func.rs +++ /dev/null @@ -1,55 +0,0 @@ -use axum::extract::OriginalUri; -use axum::{extract::Query, Json}; -use serde::{Deserialize, Serialize}; - -use dal::func::view::FuncView; -use dal::{Func, FuncId, Visibility}; - -use super::FuncResult; -use crate::server::extract::{AccessBuilder, HandlerContext, PosthogClient}; -use crate::server::tracking::track; - -#[derive(Deserialize, Serialize, Debug)] -#[serde(rename_all = "camelCase")] -pub struct GetLatestFuncExecutionRequest { - pub id: FuncId, - #[serde(flatten)] - pub visibility: Visibility, -} - -#[derive(Deserialize, Serialize, Debug)] -#[serde(rename_all = "camelCase")] -pub struct GetFuncRequest { - pub id: FuncId, - #[serde(flatten)] - pub visibility: Visibility, -} - -type GetFuncResponse = FuncView; - -pub async fn get_func( - HandlerContext(builder): HandlerContext, - AccessBuilder(request_ctx): AccessBuilder, - PosthogClient(posthog_client): PosthogClient, - OriginalUri(original_uri): OriginalUri, - Query(request): Query, -) -> FuncResult> { - let ctx = builder.build(request_ctx.build(request.visibility)).await?; - - let func = Func::get_by_id_or_error(&ctx, request.id).await?; - let view = FuncView::assemble(&ctx, &func).await?; - - track( - &posthog_client, - &ctx, - &original_uri, - "get_func", - serde_json::json!({ - "how": "/func/get_func", - "func_id": request.id, - "func_name": func.name, - }), - ); - - Ok(Json(view)) -} diff --git a/lib/sdf-server/src/server/service/func/get_func_associations.rs b/lib/sdf-server/src/server/service/func/get_func_associations.rs deleted file mode 100644 index 93e60dab39..0000000000 --- a/lib/sdf-server/src/server/service/func/get_func_associations.rs +++ /dev/null @@ -1,51 +0,0 @@ -use axum::extract::OriginalUri; -use axum::{extract::Query, Json}; -use serde::{Deserialize, Serialize}; - -use dal::func::FuncAssociations; -use dal::{Func, FuncId, Visibility}; - -use super::FuncResult; -use crate::server::extract::{AccessBuilder, HandlerContext, PosthogClient}; -use crate::server::tracking::track; - -#[derive(Deserialize, Serialize, Debug)] -#[serde(rename_all = "camelCase")] -pub struct GetFuncAssociationsRequest { - pub id: FuncId, - #[serde(flatten)] - pub visibility: Visibility, -} - -#[derive(Deserialize, Serialize, Debug)] -#[serde(rename_all = "camelCase")] -pub struct GetFuncAssociationsResponse { - pub associations: Option, -} - -pub async fn get_func_associations( - HandlerContext(builder): HandlerContext, - AccessBuilder(request_ctx): AccessBuilder, - PosthogClient(posthog_client): PosthogClient, - OriginalUri(original_uri): OriginalUri, - Query(request): Query, -) -> FuncResult> { - let ctx = builder.build(request_ctx.build(request.visibility)).await?; - - let func = Func::get_by_id_or_error(&ctx, request.id).await?; - let (associations, _input_type) = FuncAssociations::from_func(&ctx, &func).await?; - - track( - &posthog_client, - &ctx, - &original_uri, - "get_func_associations", - serde_json::json!({ - "how": "/func/get_func_associations", - "func_id": func.id, - "func_name": func.name - }), - ); - - Ok(Json(GetFuncAssociationsResponse { associations })) -} diff --git a/lib/sdf-server/src/server/service/func/list_func_arguments.rs b/lib/sdf-server/src/server/service/func/list_func_arguments.rs deleted file mode 100644 index 6aa9c37b9d..0000000000 --- a/lib/sdf-server/src/server/service/func/list_func_arguments.rs +++ /dev/null @@ -1,33 +0,0 @@ -use axum::{extract::Query, Json}; -use dal::func::argument::FuncArgument; -use dal::{FuncId, Visibility}; -use serde::{Deserialize, Serialize}; - -use super::FuncResult; -use crate::server::extract::{AccessBuilder, HandlerContext}; - -#[derive(Deserialize, Serialize, Debug)] -#[serde(rename_all = "camelCase")] -pub struct ListFuncArgumentsRequest { - pub func_id: FuncId, - #[serde(flatten)] - pub visibility: Visibility, -} - -#[derive(Deserialize, Serialize, Debug, Eq, PartialEq, Clone)] -#[serde(rename_all = "camelCase")] -pub struct ListFuncArgumentsResponse { - pub func_arguments: Vec, -} - -pub async fn list_func_arguments( - HandlerContext(builder): HandlerContext, - AccessBuilder(request_ctx): AccessBuilder, - Query(request): Query, -) -> FuncResult> { - let ctx = builder.build(request_ctx.build(request.visibility)).await?; - - let func_arguments = FuncArgument::list_for_func(&ctx, request.func_id).await?; - - Ok(Json(ListFuncArgumentsResponse { func_arguments })) -} diff --git a/lib/sdf-server/src/server/service/func/list_funcs.rs b/lib/sdf-server/src/server/service/func/list_funcs.rs deleted file mode 100644 index 0086246dd3..0000000000 --- a/lib/sdf-server/src/server/service/func/list_funcs.rs +++ /dev/null @@ -1,32 +0,0 @@ -use axum::{extract::Query, Json}; -use dal::func::summary::FuncSummary; -use dal::Visibility; -use serde::{Deserialize, Serialize}; - -use super::FuncResult; -use crate::server::extract::{AccessBuilder, HandlerContext}; - -#[derive(Deserialize, Serialize, Debug)] -#[serde(rename_all = "camelCase")] -pub struct ListFuncsRequest { - #[serde(flatten)] - pub visibility: Visibility, -} - -#[derive(Deserialize, Serialize, Debug, Eq, PartialEq, Clone)] -#[serde(rename_all = "camelCase")] -pub struct ListFuncsResponse { - pub funcs: Vec, -} - -pub async fn list_funcs( - HandlerContext(builder): HandlerContext, - AccessBuilder(request_ctx): AccessBuilder, - Query(request): Query, -) -> FuncResult> { - let ctx = builder.build(request_ctx.build(request.visibility)).await?; - - let funcs = FuncSummary::list(&ctx).await?; - - Ok(Json(ListFuncsResponse { funcs })) -} diff --git a/lib/sdf-server/src/server/service/func/list_input_sources.rs b/lib/sdf-server/src/server/service/func/list_input_sources.rs deleted file mode 100644 index 49a43e58aa..0000000000 --- a/lib/sdf-server/src/server/service/func/list_input_sources.rs +++ /dev/null @@ -1,34 +0,0 @@ -use axum::{extract::Query, Json}; -use dal::input_sources::InputSources; -use dal::{SchemaVariantId, Visibility}; -use serde::{Deserialize, Serialize}; - -use super::FuncResult; -use crate::server::extract::{AccessBuilder, HandlerContext}; - -#[derive(Deserialize, Serialize, Debug)] -#[serde(rename_all = "camelCase")] -pub struct ListInputSourcesRequest { - schema_variant_id: Option, - #[serde(flatten)] - pub visibility: Visibility, -} - -pub type ListInputSourcesResponse = InputSources; - -pub async fn list_input_sources( - HandlerContext(builder): HandlerContext, - AccessBuilder(request_ctx): AccessBuilder, - Query(request): Query, -) -> FuncResult> { - let ctx = builder.build(request_ctx.build(request.visibility)).await?; - - let input_sources = match request.schema_variant_id { - Some(provided_schema_variant_id) => { - InputSources::assemble(&ctx, provided_schema_variant_id).await? - } - None => InputSources::assemble_for_all_schema_variants(&ctx).await?, - }; - - Ok(Json(input_sources)) -} diff --git a/lib/sdf-server/src/server/service/func/remove_attribute_prototype.rs b/lib/sdf-server/src/server/service/func/remove_attribute_prototype.rs deleted file mode 100644 index 2e77d03c55..0000000000 --- a/lib/sdf-server/src/server/service/func/remove_attribute_prototype.rs +++ /dev/null @@ -1,40 +0,0 @@ -use axum::{response::IntoResponse, Json}; -use dal::func::authoring::FuncAuthoringClient; -use dal::{AttributePrototype, AttributePrototypeId, ChangeSet, Visibility, WsEvent}; -use serde::{Deserialize, Serialize}; - -use super::FuncResult; -use crate::server::extract::{AccessBuilder, HandlerContext}; - -#[derive(Deserialize, Serialize, Debug)] -#[serde(rename_all = "camelCase")] -pub struct RemoveAttributePrototypeRequest { - attribute_prototype_id: AttributePrototypeId, - #[serde(flatten)] - pub visibility: Visibility, -} - -pub async fn remove_attribute_prototype( - HandlerContext(builder): HandlerContext, - AccessBuilder(request_ctx): AccessBuilder, - Json(request): Json, -) -> FuncResult { - let mut ctx = builder.build(request_ctx.build(request.visibility)).await?; - let force_change_set_id = ChangeSet::force_new(&mut ctx).await?; - let func_id = AttributePrototype::func_id(&ctx, request.attribute_prototype_id).await?; - FuncAuthoringClient::remove_attribute_prototype(&ctx, request.attribute_prototype_id).await?; - - WsEvent::func_saved(&ctx, func_id) - .await? - .publish_on_commit(&ctx) - .await?; - - ctx.commit().await?; - - let mut response = axum::response::Response::builder(); - response = response.header("Content-Type", "application/json"); - if let Some(force_change_set_id) = force_change_set_id { - response = response.header("force_change_set_id", force_change_set_id.to_string()); - } - Ok(response.body(axum::body::Empty::new())?) -} diff --git a/lib/sdf-server/src/server/service/func/save_and_exec.rs b/lib/sdf-server/src/server/service/func/save_and_exec.rs deleted file mode 100644 index f3a85fec31..0000000000 --- a/lib/sdf-server/src/server/service/func/save_and_exec.rs +++ /dev/null @@ -1,63 +0,0 @@ -use axum::extract::OriginalUri; -use axum::{response::IntoResponse, Json}; -use dal::func::authoring::FuncAuthoringClient; -use dal::{ChangeSet, WsEvent}; - -use super::{save_func::SaveFuncRequest, FuncResult}; -use crate::server::extract::{AccessBuilder, HandlerContext, PosthogClient}; -use crate::server::tracking::track; - -pub async fn save_and_exec( - HandlerContext(builder): HandlerContext, - AccessBuilder(request_ctx): AccessBuilder, - PosthogClient(posthog_client): PosthogClient, - OriginalUri(original_uri): OriginalUri, - Json(request): Json, -) -> FuncResult { - let mut ctx = builder.build(request_ctx.build(request.visibility)).await?; - - let force_change_set_id = ChangeSet::force_new(&mut ctx).await?; - - // Cache for posthog tracking. - let func_id = request.id; - let func_name = request.name.clone(); - - FuncAuthoringClient::save_func( - &ctx, - func_id, - request.display_name, - request.name, - request.description, - request.code, - request.associations, - ) - .await?; - - FuncAuthoringClient::execute_func(&ctx, func_id).await?; - - track( - &posthog_client, - &ctx, - &original_uri, - "save_and_exec", - serde_json::json!({ - "how": "/func/save_and_exec", - "func_id": func_id, - "func_name": func_name.as_str(), - }), - ); - - WsEvent::func_saved(&ctx, func_id) - .await? - .publish_on_commit(&ctx) - .await?; - - ctx.commit().await?; - - let mut response = axum::response::Response::builder(); - response = response.header("Content-Type", "application/json"); - if let Some(force_change_set_id) = force_change_set_id { - response = response.header("force_change_set_id", force_change_set_id.to_string()); - } - Ok(response.body(axum::body::Empty::new())?) -} diff --git a/lib/sdf-server/src/server/service/func/save_func.rs b/lib/sdf-server/src/server/service/func/save_func.rs deleted file mode 100644 index a096515a81..0000000000 --- a/lib/sdf-server/src/server/service/func/save_func.rs +++ /dev/null @@ -1,76 +0,0 @@ -use axum::extract::OriginalUri; -use axum::{response::IntoResponse, Json}; -use dal::func::authoring::FuncAuthoringClient; -use dal::func::FuncAssociations; -use dal::{ChangeSet, FuncId, Visibility, WsEvent}; -use serde::{Deserialize, Serialize}; - -use crate::server::extract::{AccessBuilder, HandlerContext, PosthogClient}; -use crate::server::tracking::track; -use crate::service::func::FuncResult; - -#[derive(Deserialize, Serialize, Debug)] -#[serde(rename_all = "camelCase")] -pub struct SaveFuncRequest { - pub id: FuncId, - pub display_name: Option, - pub name: String, - pub description: Option, - pub code: Option, - pub associations: Option, - #[serde(flatten)] - pub visibility: Visibility, -} - -pub async fn save_func( - HandlerContext(builder): HandlerContext, - AccessBuilder(request_ctx): AccessBuilder, - PosthogClient(posthog_client): PosthogClient, - OriginalUri(original_uri): OriginalUri, - Json(request): Json, -) -> FuncResult { - let mut ctx = builder.build(request_ctx.build(request.visibility)).await?; - - let force_change_set_id = ChangeSet::force_new(&mut ctx).await?; - - // Cache for posthog tracking. - let func_id = request.id; - let func_name = request.name.clone(); - - FuncAuthoringClient::save_func( - &ctx, - request.id, - request.display_name, - request.name, - request.description, - request.code, - request.associations, - ) - .await?; - - track( - &posthog_client, - &ctx, - &original_uri, - "save_func", - serde_json::json!({ - "how": "/func/save_func", - "func_id": func_id, - "func_name": func_name.as_str(), - }), - ); - - WsEvent::func_saved(&ctx, func_id) - .await? - .publish_on_commit(&ctx) - .await?; - - ctx.commit().await?; - - let mut response = axum::response::Response::builder(); - response = response.header("Content-Type", "application/json"); - if let Some(force_change_set_id) = force_change_set_id { - response = response.header("force_change_set_id", force_change_set_id.to_string()); - } - Ok(response.body(axum::body::Empty::new())?) -} diff --git a/lib/sdf-server/src/server/service/func/test_execute.rs b/lib/sdf-server/src/server/service/func/test_execute.rs deleted file mode 100644 index df177fc538..0000000000 --- a/lib/sdf-server/src/server/service/func/test_execute.rs +++ /dev/null @@ -1,62 +0,0 @@ -use axum::extract::OriginalUri; -use axum::Json; -use dal::func::authoring::FuncAuthoringClient; -use dal::{ComponentId, FuncId, Visibility}; -use serde::{Deserialize, Serialize}; -use si_events::FuncRunId; - -use super::FuncResult; -use crate::server::extract::{AccessBuilder, HandlerContext, PosthogClient}; -use crate::server::tracking::track; - -#[derive(Debug, Deserialize, Serialize)] -#[serde(rename_all = "camelCase")] -pub struct TestExecuteFuncRequest { - pub id: FuncId, - pub args: serde_json::Value, - pub code: String, - pub component_id: ComponentId, - #[serde(flatten)] - pub visibility: Visibility, -} - -#[derive(Debug, Deserialize, Serialize)] -#[serde(rename_all = "camelCase")] -pub struct TestExecuteFuncResponse { - func_run_id: FuncRunId, -} - -pub async fn test_execute( - HandlerContext(builder): HandlerContext, - AccessBuilder(request_ctx): AccessBuilder, - PosthogClient(posthog_client): PosthogClient, - OriginalUri(original_uri): OriginalUri, - Json(req): Json, -) -> FuncResult> { - let ctx = builder.build(request_ctx.build(req.visibility)).await?; - - let func_run_id = FuncAuthoringClient::test_execute_func( - &ctx, - req.id, - req.args, - Some(req.code), - req.component_id, - ) - .await?; - - track( - &posthog_client, - &ctx, - &original_uri, - "test_execute", - serde_json::json!({ - "how": "/func/test_execute", - "id": req.id, - "component_id": req.component_id, - }), - ); - - ctx.commit().await?; - - Ok(Json(TestExecuteFuncResponse { func_run_id })) -} diff --git a/lib/sdf-server/src/server/service/func/update_attribute_prototype.rs b/lib/sdf-server/src/server/service/func/update_attribute_prototype.rs deleted file mode 100644 index 7eadcb3f75..0000000000 --- a/lib/sdf-server/src/server/service/func/update_attribute_prototype.rs +++ /dev/null @@ -1,53 +0,0 @@ -use axum::{response::IntoResponse, Json}; -use dal::func::authoring::FuncAuthoringClient; -use dal::func::AttributePrototypeArgumentBag; -use dal::{AttributePrototypeId, ChangeSet, FuncId, OutputSocketId, PropId, Visibility, WsEvent}; -use serde::{Deserialize, Serialize}; - -use super::FuncResult; -use crate::server::extract::{AccessBuilder, HandlerContext}; - -#[derive(Deserialize, Serialize, Debug)] -#[serde(rename_all = "camelCase")] -pub struct UpdateAttributePrototypeRequest { - func_id: FuncId, - attribute_prototype_id: AttributePrototypeId, - prop_id: Option, - output_socket_id: Option, - prototype_arguments: Vec, - #[serde(flatten)] - pub visibility: Visibility, -} - -pub async fn update_attribute_prototype( - HandlerContext(builder): HandlerContext, - AccessBuilder(request_ctx): AccessBuilder, - Json(request): Json, -) -> FuncResult { - let mut ctx = builder.build(request_ctx.build(request.visibility)).await?; - let force_change_set_id = ChangeSet::force_new(&mut ctx).await?; - - FuncAuthoringClient::update_attribute_prototype( - &ctx, - request.func_id, - request.attribute_prototype_id, - request.prop_id, - request.output_socket_id, - request.prototype_arguments, - ) - .await?; - - WsEvent::func_saved(&ctx, request.func_id) - .await? - .publish_on_commit(&ctx) - .await?; - - ctx.commit().await?; - - let mut response = axum::response::Response::builder(); - response = response.header("Content-Type", "application/json"); - if let Some(force_change_set_id) = force_change_set_id { - response = response.header("force_change_set_id", force_change_set_id.to_string()); - } - Ok(response.body(axum::body::Empty::new())?) -} diff --git a/lib/sdf-server/src/server/service/func/update_func_argument.rs b/lib/sdf-server/src/server/service/func/update_func_argument.rs deleted file mode 100644 index e047004b7a..0000000000 --- a/lib/sdf-server/src/server/service/func/update_func_argument.rs +++ /dev/null @@ -1,50 +0,0 @@ -use axum::{response::IntoResponse, Json}; -use dal::func::argument::{FuncArgument, FuncArgumentId, FuncArgumentKind}; -use dal::{ChangeSet, FuncId, Visibility, WsEvent}; -use serde::{Deserialize, Serialize}; - -use super::FuncResult; -use crate::server::extract::{AccessBuilder, HandlerContext}; - -#[derive(Deserialize, Serialize, Debug)] -#[serde(rename_all = "camelCase")] -pub struct UpdateFuncArgumentRequest { - func_id: FuncId, - func_argument_id: FuncArgumentId, - name: String, - kind: FuncArgumentKind, - element_kind: Option, - #[serde(flatten)] - pub visibility: Visibility, -} - -pub async fn update_func_argument( - HandlerContext(builder): HandlerContext, - AccessBuilder(request_ctx): AccessBuilder, - Json(request): Json, -) -> FuncResult { - let mut ctx = builder.build(request_ctx.build(request.visibility)).await?; - let force_change_set_id = ChangeSet::force_new(&mut ctx).await?; - - FuncArgument::modify_by_id(&ctx, request.func_argument_id, |existing_arg| { - existing_arg.name = request.name; - existing_arg.kind = request.kind; - existing_arg.element_kind = request.element_kind; - Ok(()) - }) - .await?; - - WsEvent::func_arguments_saved(&ctx, request.func_id) - .await? - .publish_on_commit(&ctx) - .await?; - - ctx.commit().await?; - - let mut response = axum::response::Response::builder(); - response = response.header("Content-Type", "application/json"); - if let Some(force_change_set_id) = force_change_set_id { - response = response.header("force_change_set_id", force_change_set_id.to_string()); - } - Ok(response.body(axum::body::Empty::new())?) -} diff --git a/lib/sdf-server/src/server/service/v2/func.rs b/lib/sdf-server/src/server/service/v2/func.rs index aabed53459..c2ef074d84 100644 --- a/lib/sdf-server/src/server/service/v2/func.rs +++ b/lib/sdf-server/src/server/service/v2/func.rs @@ -1,7 +1,8 @@ +use crate::{server::state::AppState, service::ApiError}; use axum::{ http::StatusCode, response::{IntoResponse, Response}, - routing::{delete, get, post}, + routing::{delete, get, post, put}, Router, }; use dal::{ @@ -9,10 +10,9 @@ use dal::{ ChangeSetError, DalContext, Func, FuncError, FuncId, WsEventError, }; use si_frontend_types::FuncCode; +use si_layer_cache::LayerDbError; use thiserror::Error; -use crate::{server::state::AppState, service::ApiError}; - pub mod argument; pub mod binding; pub mod create_func; @@ -20,6 +20,7 @@ pub mod create_unlocked_copy; pub mod delete_func; pub mod execute_func; pub mod get_code; +mod get_func_run; pub mod list_all_funcs; pub mod list_funcs; pub mod save_code; @@ -49,6 +50,8 @@ pub enum FuncAPIError { FuncNotFound(FuncId), #[error("hyper error: {0}")] Http(#[from] axum::http::Error), + #[error("layer db error: {0}")] + LayerDb(#[from] LayerDbError), #[error("missing action kind")] MissingActionKindForActionFunc, #[error("missing action prototype")] @@ -117,28 +120,29 @@ pub fn v2_routes() -> Router { .route("/", get(list_funcs::list_funcs)) .route("/including_pruned", get(list_all_funcs::list_all_funcs)) .route("/code", get(get_code::get_code)) // accepts a list of func_ids - .route("/create", post(create_func::create_func)) - .route("/:func_id/update", post(update_func::update_func)) // only save the func's metadata - .route("/:func_id/save_code", post(save_code::save_code)) // only saves func code + .route("/runs/:func_run_id", get(get_code::get_code)) // accepts a list of func_ids + .route("/", post(create_func::create_func)) + .route("/:func_id", put(update_func::update_func)) // only save the func's metadata + .route("/:func_id/code", post(get_func_run::get_func_run)) // only saves func code .route("/:func_id/test_execute", post(test_execute::test_execute)) .route("/:func_id/execute", post(execute_func::execute_func)) .route( - "/:func_id/create_unlocked_copy", + "/:func_id", post(create_unlocked_copy::create_unlocked_copy), ) - .route("/:func_id/delete", delete(delete_func::delete_func)) + .route("/:func_id", delete(delete_func::delete_func)) // Func Bindings .route( - "/:func_id/bindings/create", + "/:func_id/bindings", post(binding::create_binding::create_binding), ) .route( - "/:func_id/bindings/delete", - post(binding::delete_binding::delete_binding), + "/:func_id/bindings", + delete(binding::delete_binding::delete_binding), ) .route( - "/:func_id/bindings/update", - post(binding::update_binding::update_binding), + "/:func_id/bindings", + put(binding::update_binding::update_binding), ) // Reset Attribute Bindings .route( @@ -147,16 +151,16 @@ pub fn v2_routes() -> Router { ) // Func Arguments .route( - "/:func_id/:func_argument_id/update", - post(argument::update_argument::update_func_argument), + "/:func_id/arguments", + post(argument::create_argument::create_func_argument), ) .route( - "/:func_id/create_argument", - post(argument::create_argument::create_func_argument), + "/:func_id/arguments/:func_argument_id", + put(argument::update_argument::update_func_argument), ) .route( - "/:func_id/:func_argument_id/delete", - post(argument::delete_argument::delete_func_argument), + "/:func_id/arguments/:func_argument_id", + delete(argument::delete_argument::delete_func_argument), ) } diff --git a/lib/sdf-server/src/server/service/func/get_func_run.rs b/lib/sdf-server/src/server/service/v2/func/get_func_run.rs similarity index 93% rename from lib/sdf-server/src/server/service/func/get_func_run.rs rename to lib/sdf-server/src/server/service/v2/func/get_func_run.rs index 7d03a26700..fc6c92147c 100644 --- a/lib/sdf-server/src/server/service/func/get_func_run.rs +++ b/lib/sdf-server/src/server/service/v2/func/get_func_run.rs @@ -1,18 +1,17 @@ -use std::sync::Arc; - -use axum::{extract::Query, Json}; +use axum::extract::Path; +use axum::Json; use chrono::{DateTime, Utc}; -use dal::ContentHash; -use dal::Visibility; +use dal::{ContentHash, WorkspacePk}; use serde::{Deserialize, Serialize}; use si_events::{ ActionId, ActionKind, ActionPrototypeId, ActionResultState, Actor, AttributeValueId, CasValue, ChangeSetId, ComponentId, FuncBackendKind, FuncBackendResponseType, FuncKind, FuncRun, FuncRunId, FuncRunLog, FuncRunLogId, FuncRunState, OutputLine, }; +use std::sync::Arc; -use super::FuncResult; use crate::server::extract::{AccessBuilder, HandlerContext}; +use crate::service::v2::func::FuncAPIResult; /// A one-to-one mapping of cyclone's "OutputStream" type. #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)] @@ -145,14 +144,6 @@ impl FuncRunView { } } -#[derive(Deserialize, Serialize, Debug)] -#[serde(rename_all = "camelCase")] -pub struct GetFuncRun { - pub func_run_id: FuncRunId, - #[serde(flatten)] - pub visibility: Visibility, -} - #[derive(Deserialize, Serialize, Debug, Eq, PartialEq, Clone)] #[serde(rename_all = "camelCase")] pub struct GetFuncRunResponse { @@ -161,12 +152,18 @@ pub struct GetFuncRunResponse { pub async fn get_func_run( HandlerContext(builder): HandlerContext, - AccessBuilder(request_ctx): AccessBuilder, - Query(request): Query, -) -> FuncResult> { - let ctx = builder.build(request_ctx.build(request.visibility)).await?; - - let maybe_func_run = ctx.layer_db().func_run().read(request.func_run_id).await?; + AccessBuilder(access_builder): AccessBuilder, + Path((_workspace_pk, change_set_id, func_run_id)): Path<( + WorkspacePk, + dal::ChangeSetId, + FuncRunId, + )>, +) -> FuncAPIResult> { + let ctx = builder + .build(access_builder.build(change_set_id.into())) + .await?; + + let maybe_func_run = ctx.layer_db().func_run().read(func_run_id).await?; match maybe_func_run { Some(func_run) => {