diff --git a/backend/Cargo.lock b/backend/Cargo.lock index 11f3c1c83a..6c08ecb94a 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -17542,6 +17542,7 @@ dependencies = [ "rand 0.9.5", "serde", "serde_json", + "serde_yml", "sqlx", "strum", "tracing", diff --git a/backend/windmill-api/openapi.yaml b/backend/windmill-api/openapi.yaml index 7db216f173..ee85abee21 100644 --- a/backend/windmill-api/openapi.yaml +++ b/backend/windmill-api/openapi.yaml @@ -11097,40 +11097,7 @@ paths: schema: type: array items: - allOf: - - $ref: "#/components/schemas/Script" - - type: object - properties: - is_draft: - type: boolean - description: | - True when the authed user has a draft for this - script — either no deployed row exists at this - path (draft-only) or the user saved a per-user - draft on top of the deployed row. - draft_path: - type: string - description: | - User-typed path the editor has staged but not - yet deployed. Surfaced for draft-only rows so - the home list can render the meaningful name - instead of the autogenerated - `u/{user}/draft_{uuid}` URL path. Omitted - when unchanged. - draft_users: - description: | - Workspace users (including the authed user, and - the legacy NULL-email row if any) who have a - per-user draft at this path. Drives the home - page's user-avatar circles inside the Draft - badge. Omitted when no drafts exist. - type: array - items: - type: object - properties: - username: - type: string - nullable: true + $ref: "#/components/schemas/ListableScript" /w/{workspace}/scripts/list_paths: get: @@ -32214,6 +32181,109 @@ components: - type - path + ListableScript: + type: object + description: | + A script as returned by the list endpoint: the deployed row's summary + fields, without its content, lock or schema. + properties: + hash: + type: string + path: + type: string + summary: + type: string + description: + type: string + created_at: + type: string + format: date-time + archived: + type: boolean + extra_perms: + type: object + additionalProperties: + type: boolean + language: + $ref: "#/components/schemas/ScriptLang" + kind: + type: string + enum: [script, failure, trigger, approval, preprocessor] + starred: + type: boolean + tag: + type: string + nullable: true + draft_only: + type: boolean + description: | + True on rows built from a draft that was never deployed. Omitted + on deployed rows. + has_deploy_errors: + type: boolean + ws_error_handler_muted: + type: boolean + nullable: true + auto_kind: + type: string + use_codebase: + type: boolean + description: Omitted when false. + deployment_msg: + type: string + description: Only returned with `with_deployment_msg=true`. + labels: + type: array + items: + type: string + inherited_labels: + type: array + items: + type: string + is_draft: + type: boolean + description: | + True when the authed user has a draft for this + script — either no deployed row exists at this + path (draft-only) or the user saved a per-user + draft on top of the deployed row. Omitted when false. + draft_path: + type: string + description: | + User-typed path the editor has staged but not + yet deployed. Surfaced for draft-only rows so + the home list can render the meaningful name + instead of the autogenerated + `u/{user}/draft_{uuid}` URL path. Omitted + when unchanged. + draft_users: + description: | + Workspace users (including the authed user, and + the legacy NULL-email row if any) who have a + per-user draft at this path. Drives the home + page's user-avatar circles inside the Draft + badge. Omitted when no drafts exist. + type: array + items: + type: object + properties: + username: + type: string + nullable: true + required: + - hash + - path + - summary + - created_at + - archived + - extra_perms + - language + - kind + - starred + - tag + - has_deploy_errors + - ws_error_handler_muted + Script: type: object properties: diff --git a/backend/windmill-types/Cargo.toml b/backend/windmill-types/Cargo.toml index 84fa209ddd..fb5eb1a458 100644 --- a/backend/windmill-types/Cargo.toml +++ b/backend/windmill-types/Cargo.toml @@ -26,3 +26,6 @@ bitflags.workspace = true [target.'cfg(not(target_arch = "wasm32"))'.dependencies] sqlx = { workspace = true, features = ["postgres"] } + +[dev-dependencies] +serde_yml.workspace = true diff --git a/backend/windmill-types/tests/listable_script_openapi.rs b/backend/windmill-types/tests/listable_script_openapi.rs new file mode 100644 index 0000000000..0d5254b7e0 --- /dev/null +++ b/backend/windmill-types/tests/listable_script_openapi.rs @@ -0,0 +1,78 @@ +//! `openapi.yaml` describes the `/scripts/list` row by hand, so a field added to +//! `ListableScript` must also be added to its `ListableScript` schema, or every +//! generated client silently lacks it. + +use std::collections::BTreeSet; + +use serde_json::Value; +use windmill_types::scripts::{ListableScript, ScriptHash, ScriptKind, ScriptLang}; +use windmill_types::user_drafts::DraftUserRef; + +fn listable_script(populated: bool) -> ListableScript { + let some = |s: &str| populated.then(|| s.to_string()); + ListableScript { + hash: ScriptHash(1), + path: "f/a/b".to_string(), + summary: String::new(), + created_at: chrono::Utc::now(), + archived: false, + extra_perms: serde_json::json!({}), + language: ScriptLang::Bun, + starred: false, + tag: None, + description: some("d"), + draft_only: populated.then_some(true), + has_deploy_errors: false, + ws_error_handler_muted: None, + auto_kind: some("lib"), + use_codebase: populated, + deployment_msg: some("m"), + kind: ScriptKind::Script, + labels: populated.then(|| vec!["l".to_string()]), + is_draft: populated, + draft_path: some("u/x/y"), + draft_users: populated.then(|| sqlx::types::Json(vec![DraftUserRef { username: None }])), + inherited_labels: populated.then(|| vec!["l".to_string()]), + } +} + +fn keys(script: &ListableScript) -> BTreeSet { + match serde_json::to_value(script).unwrap() { + Value::Object(o) => o.into_iter().map(|(k, _)| k).collect(), + v => panic!("ListableScript serialized to {v}"), + } +} + +#[test] +fn listable_script_schema_matches_its_serialization() { + let spec: serde_yml::Value = serde_yml::from_str(include_str!(concat!( + env!("CARGO_MANIFEST_DIR"), + "/../windmill-api/openapi.yaml" + ))) + .unwrap(); + let schema = &spec["components"]["schemas"]["ListableScript"]; + let names = |v: &serde_yml::Value| -> BTreeSet { + match v { + serde_yml::Value::Mapping(m) => { + m.keys().map(|k| k.as_str().unwrap().to_string()).collect() + } + serde_yml::Value::Sequence(s) => { + s.iter().map(|k| k.as_str().unwrap().to_string()).collect() + } + v => panic!("unexpected {v:?}"), + } + }; + let properties = names(&schema["properties"]); + let required = names(&schema["required"]); + + assert_eq!( + keys(&listable_script(true)), + properties, + "ListableScript's serialized fields and the properties of its openapi.yaml schema differ" + ); + assert_eq!( + keys(&listable_script(false)), + required, + "the fields ListableScript always serializes and the `required` list of its openapi.yaml schema differ" + ); +} diff --git a/cli/src/commands/script/script.ts b/cli/src/commands/script/script.ts index ccb56aff07..28f7ab588c 100644 --- a/cli/src/commands/script/script.ts +++ b/cli/src/commands/script/script.ts @@ -74,7 +74,11 @@ import { createTarBlob, type TarEntry } from "../../utils/tar.ts"; import { withEsbuild } from "../../utils/esbuild_loader.ts"; import { execSync } from "node:child_process"; -import { NewScript, Script, ScriptModule } from "../../../gen/types.gen.ts"; +import { + ListableScript, + NewScript, + ScriptModule, +} from "../../../gen/types.gen.ts"; import { isRawAppBackendPath as isRawAppBackendPathInternal, isAppInlineScriptPath as isAppInlineScriptPathInternal, @@ -1383,7 +1387,7 @@ async function list( let page = 0; const perPage = 10; - const total: Script[] = []; + const total: ListableScript[] = []; while (true) { const res = await wmill.listScripts({ workspace: workspace.workspaceId, @@ -1404,10 +1408,10 @@ async function list( console.log(JSON.stringify(total)); } else { new Table() - .header(["path", "summary", "language", "created by"]) + .header(["path", "summary", "language", "created at"]) .padding(2) .border(true) - .body(total.map((x) => [x.path, x.summary, x.language, x.created_by])) + .body(total.map((x) => [x.path, x.summary, x.language, x.created_at])) .render(); } } diff --git a/frontend/src/lib/components/apps/editor/settingsPanel/mainInput/WorkspaceScriptList.svelte b/frontend/src/lib/components/apps/editor/settingsPanel/mainInput/WorkspaceScriptList.svelte index 13447c4787..3680879c88 100644 --- a/frontend/src/lib/components/apps/editor/settingsPanel/mainInput/WorkspaceScriptList.svelte +++ b/frontend/src/lib/components/apps/editor/settingsPanel/mainInput/WorkspaceScriptList.svelte @@ -6,7 +6,7 @@ import SearchItems from '$lib/components/SearchItems.svelte' import NoItemFound from '$lib/components/home/NoItemFound.svelte' import RowIcon from '$lib/components/common/table/RowIcon.svelte' - import { type Script, ScriptService } from '$lib/gen' + import { type ListableScript, ScriptService } from '$lib/gen' import { emptyString } from '$lib/utils' import { Skeleton } from '$lib/components/common' import { useOperatingWorkspace } from '$lib/components/operatingWorkspace.svelte' @@ -20,8 +20,8 @@ let { filter = $bindable(''), children }: Props = $props() - let scripts: Script[] | undefined = $state(undefined) - let filteredItems: (Script & { marked?: string })[] = $state([]) + let scripts: ListableScript[] | undefined = $state(undefined) + let filteredItems: (ListableScript & { marked?: string })[] = $state([]) let prefilteredItems = $derived(scripts ?? []) const dispatch = createEventDispatcher() diff --git a/frontend/src/lib/components/copilot/StepGenQuick.svelte b/frontend/src/lib/components/copilot/StepGenQuick.svelte index 3890cacd58..15c04f092b 100644 --- a/frontend/src/lib/components/copilot/StepGenQuick.svelte +++ b/frontend/src/lib/components/copilot/StepGenQuick.svelte @@ -1,6 +1,6 @@