Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update schema and func endpoints to v2 #4241

Merged
merged 2 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
32 changes: 16 additions & 16 deletions app/web/src/store/func/funcs.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
},
Expand All @@ -231,7 +231,7 @@ export const useFuncStore = () => {
async DELETE_UNLOCKED_FUNC(funcId: FuncId) {
return new ApiRequest<DeleteFuncResponse>({
method: "delete",
url: `${API_PREFIX}/${funcId}/delete`,
url: `${API_PREFIX}/${funcId}`,
});
},
async UPDATE_FUNC(func: FuncSummary) {
Expand All @@ -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,
Expand Down Expand Up @@ -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,
},
Expand All @@ -291,8 +291,8 @@ export const useFuncStore = () => {
changeSetsStore.creatingChangeSet = true;

return new ApiRequest<null>({
method: "post",
url: `${API_PREFIX}/${funcId}/bindings/update`,
method: "put",
url: `${API_PREFIX}/${funcId}/bindings`,
params: {
funcId,
bindings,
Expand Down Expand Up @@ -328,8 +328,8 @@ export const useFuncStore = () => {
changeSetsStore.creatingChangeSet = true;

return new ApiRequest<null>({
method: "post",
url: `${API_PREFIX}/${funcId}/bindings/delete`,
method: "delete",
url: `${API_PREFIX}/${funcId}/bindings`,
params: {
bindings,
},
Expand All @@ -346,7 +346,7 @@ export const useFuncStore = () => {

return new ApiRequest<null>({
method: "post",
url: `${API_PREFIX}/${funcId}/create_argument`,
url: `${API_PREFIX}/${funcId}/arguments`,
params: {
...funcArg,
},
Expand All @@ -362,8 +362,8 @@ export const useFuncStore = () => {
changeSetsStore.creatingChangeSet = true;

return new ApiRequest<null>({
method: "post",
url: `${API_PREFIX}/${funcId}/${funcArg.id}/update`,
method: "put",
url: `${API_PREFIX}/${funcId}/arguments/${funcArg.id}`,
params: {
...funcArg,
},
Expand All @@ -382,8 +382,8 @@ export const useFuncStore = () => {
changeSetsStore.creatingChangeSet = true;

return new ApiRequest<null>({
method: "post",
url: `${API_PREFIX}/${funcId}/${funcArgumentId}/delete`,
method: "delete",
url: `${API_PREFIX}/${funcId}/arguments/${funcArgumentId}`,
onFail: () => {
changeSetsStore.creatingChangeSet = false;
},
Expand Down Expand Up @@ -484,7 +484,7 @@ export const useFuncStore = () => {
async SAVE_FUNC(func: FuncCode) {
return new ApiRequest<FuncCode>({
method: "post",
url: `${API_PREFIX}/${func.funcId}/save_code`,
url: `${API_PREFIX}/${func.funcId}/code`,
params: { code: func.code },
onFail: () => {
changeSetsStore.creatingChangeSet = false;
Expand Down
8 changes: 3 additions & 5 deletions app/web/src/store/func_runs.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: () => ({
Expand All @@ -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<GetFuncRunResponse>({
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;
Expand Down
5 changes: 2 additions & 3 deletions lib/dal/src/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
1 change: 0 additions & 1 deletion lib/dal/src/func/binding/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
23 changes: 10 additions & 13 deletions lib/dal/src/schema/variant.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
//! 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 thiserror::Error;
use url::ParseError;

pub use json::SchemaVariantJson;
pub use json::SchemaVariantMetadataJson;
pub use metadata_view::SchemaVariantMetadataView;
use si_events::{ulid::Ulid, ContentHash};
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::action::prototype::{ActionKind, ActionPrototype};
use crate::attribute::prototype::argument::{
Expand Down Expand Up @@ -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 @@ -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 Down
15 changes: 13 additions & 2 deletions lib/dal/src/schema/variant/authoring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ use base64::engine::general_purpose;
use base64::Engine;
use chrono::Utc;
use convert_case::{Case, Casing};
use pkg::import::import_schema_variant;
use serde::{Deserialize, Serialize};
use serde_json::error::Category;
use thiserror::Error;

use pkg::import::import_schema_variant;
use si_events::ulid::Ulid;
use si_events::FuncRunId;
use si_layer_cache::LayerDbError;
Expand All @@ -16,7 +18,6 @@ use si_pkg::{
SchemaVariantSpec, SiPkg, SiPkgError, SpecError,
};
use telemetry::prelude::*;
use thiserror::Error;

use crate::action::prototype::ActionPrototypeError;
use crate::attribute::prototype::argument::AttributePrototypeArgumentError;
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ async fn clone_variant(ctx: &mut DalContext) {

assert!(default_schema_variant.is_some());

let clone_name = format!("{}-clone", schema.name());
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading