diff --git a/backend/parsers/windmill-parser-ts/src/lib.rs b/backend/parsers/windmill-parser-ts/src/lib.rs index b820a7771b..e0b1640ffb 100644 --- a/backend/parsers/windmill-parser-ts/src/lib.rs +++ b/backend/parsers/windmill-parser-ts/src/lib.rs @@ -370,18 +370,27 @@ fn tstype_to_typ(ts_type: &TsType) -> (Typ, bool) { TsType::TsUnionOrIntersectionType(TsUnionOrIntersectionType::TsUnionType( TsUnionType { types, .. }, )) => { - if let Some(p) = if types.len() != 2 { - None + let (is_undefined_option, undefined_position) = if types.len() == 2 { + (true, find_undefined(types)) + } else if types.into_iter().all(|x| { + x.as_ts_lit_type().is_some_and(|y| y.lit.as_str().is_some()) + || x.as_ts_keyword_type().is_some_and(|y| { + y.kind == TsKeywordTypeKind::TsUndefinedKeyword + || y.kind == TsKeywordTypeKind::TsStringKeyword + || y.kind == TsKeywordTypeKind::TsNullKeyword + }) + }) { + (false, find_undefined(types)) } else { - types.into_iter().position(|x| match **x { - TsType::TsKeywordType(TsKeywordType { kind, .. }) => { - kind == TsKeywordTypeKind::TsUndefinedKeyword - || kind == TsKeywordTypeKind::TsNullKeyword - } - _ => false, - }) - } { - let other_p = if p == 0 { 1 } else { 0 }; + (false, None) + }; + + if is_undefined_option && undefined_position.is_some() { + let other_p = if undefined_position.unwrap() == 0 { + 1 + } else { + 0 + }; (tstype_to_typ(&types[other_p]).0, true) } else { let literals = types @@ -389,6 +398,8 @@ fn tstype_to_typ(ts_type: &TsType) -> (Typ, bool) { .filter(|x| match ***x { TsType::TsKeywordType(TsKeywordType { kind, .. }) => { kind != TsKeywordTypeKind::TsStringKeyword + && kind != TsKeywordTypeKind::TsUndefinedKeyword + && kind != TsKeywordTypeKind::TsNullKeyword } _ => true, }) @@ -404,7 +415,7 @@ fn tstype_to_typ(ts_type: &TsType) -> (Typ, bool) { } else { ( Typ::Str(Some(literals.into_iter().filter_map(|x| x).collect())), - false, + undefined_position.is_some(), ) } } @@ -441,6 +452,16 @@ fn tstype_to_typ(ts_type: &TsType) -> (Typ, bool) { } } +fn find_undefined(types: &Vec>) -> Option { + types.into_iter().position(|x| match **x { + TsType::TsKeywordType(TsKeywordType { kind, .. }) => { + kind == TsKeywordTypeKind::TsUndefinedKeyword + || kind == TsKeywordTypeKind::TsNullKeyword + } + _ => false, + }) +} + #[cfg(target_arch = "wasm32")] #[wasm_bindgen] extern "C" { diff --git a/backend/parsers/windmill-parser-wasm/pkg/package.json b/backend/parsers/windmill-parser-wasm/pkg/package.json index 1cf537d852..ee2f1cd2f7 100644 --- a/backend/parsers/windmill-parser-wasm/pkg/package.json +++ b/backend/parsers/windmill-parser-wasm/pkg/package.json @@ -3,7 +3,7 @@ "collaborators": [ "Ruben Fiszel " ], - "version": "1.237.0", + "version": "1.274.0", "files": [ "windmill_parser_wasm_bg.wasm", "windmill_parser_wasm.js", diff --git a/backend/parsers/windmill-parser-wasm/pkg/windmill_parser_wasm.js b/backend/parsers/windmill-parser-wasm/pkg/windmill_parser_wasm.js index c145179c12..961c8adfcb 100644 --- a/backend/parsers/windmill-parser-wasm/pkg/windmill_parser_wasm.js +++ b/backend/parsers/windmill-parser-wasm/pkg/windmill_parser_wasm.js @@ -538,10 +538,6 @@ async function __wbg_load(module, imports) { function __wbg_get_imports() { const imports = {}; imports.wbg = {}; - imports.wbg.__wbg_eval_ff4183ac1495b791 = function(arg0, arg1) { - const ret = eval(getStringFromWasm0(arg0, arg1)); - return addHeapObject(ret); - }; imports.wbg.__wbindgen_object_drop_ref = function(arg0) { takeObject(arg0); }; @@ -593,6 +589,10 @@ function __wbg_get_imports() { const ret = getObject(arg0) in getObject(arg1); return ret; }; + imports.wbg.__wbg_eval_69b0e521a846e4c2 = function(arg0, arg1) { + const ret = eval(getStringFromWasm0(arg0, arg1)); + return addHeapObject(ret); + }; imports.wbg.__wbindgen_jsval_loose_eq = function(arg0, arg1) { const ret = getObject(arg0) == getObject(arg1); return ret; diff --git a/backend/parsers/windmill-parser-wasm/pkg/windmill_parser_wasm_bg.wasm b/backend/parsers/windmill-parser-wasm/pkg/windmill_parser_wasm_bg.wasm index 9ca2d1c831..e1fa4518bd 100644 Binary files a/backend/parsers/windmill-parser-wasm/pkg/windmill_parser_wasm_bg.wasm and b/backend/parsers/windmill-parser-wasm/pkg/windmill_parser_wasm_bg.wasm differ diff --git a/backend/parsers/windmill-parser-wasm/tests/wasm.rs b/backend/parsers/windmill-parser-wasm/tests/wasm.rs index 3d7cfbc465..3c6fd4d291 100644 --- a/backend/parsers/windmill-parser-wasm/tests/wasm.rs +++ b/backend/parsers/windmill-parser-wasm/tests/wasm.rs @@ -10,7 +10,8 @@ export function main(test1?: string, test2: string = \"burkina\", test3: wmill.Resource<'postgres'>, b64: Base64, ls: Base64[], email: Email, literal: \"test\", literal_union: \"test\" | \"test2\", opt_type?: string | null, opt_type_union: string | null, opt_type_union_union2: string | undefined, - min_object: {a: string, b: number}) { + min_object: {a: string, b: number}, + literals_with_undefined: \"foo\" | \"bar\" | undefined) { console.log(42) } "; @@ -106,6 +107,13 @@ export function main(test1?: string, test2: string = \"burkina\", ]), default: None, has_default: false + }, + Arg { + otyp: None, + name: "literals_with_undefined".to_string(), + typ: Typ::Str(Some(vec!["foo".to_string(), "bar".to_string()])), + default: None, + has_default: true } ] } @@ -113,7 +121,6 @@ export function main(test1?: string, test2: string = \"burkina\", Ok(()) } - #[wasm_bindgen_test] fn test_parse_deno_sig_implicit_types() -> anyhow::Result<()> { let code = " diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 3aed6fab2e..283da26bce 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -51,7 +51,7 @@ "vscode-languageclient": "~9.0.1", "vscode-uri": "~3.0.8", "vscode-ws-jsonrpc": "~3.1.0", - "windmill-parser-wasm": "^1.237.0", + "windmill-parser-wasm": "^1.274.0", "y-monaco": "^0.1.4", "y-websocket": "^1.5.0", "yaml": "^2.3.4", @@ -10085,9 +10085,9 @@ } }, "node_modules/windmill-parser-wasm": { - "version": "1.237.0", - "resolved": "https://registry.npmjs.org/windmill-parser-wasm/-/windmill-parser-wasm-1.237.0.tgz", - "integrity": "sha512-MGO9rkSnkFMOkkkEr/whFzkbyeHX4E6JwYLazlDgyprNNibpEi7GXcOeuz+QgbzDNrTLo/sYN6bYqcHt4Jk6dQ==" + "version": "1.274.0", + "resolved": "https://registry.npmjs.org/windmill-parser-wasm/-/windmill-parser-wasm-1.274.0.tgz", + "integrity": "sha512-p3fqgj/XIzcoJFGcIw/ss2kAvrACaCXdPkKuADVRkGjgz8hVuVpA795phFkKOZEydpXGByfq7vXTUZJ3mJp5eA==" }, "node_modules/wordwrap": { "version": "1.0.0", diff --git a/frontend/package.json b/frontend/package.json index 08b71d1fd5..2530929480 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -133,7 +133,7 @@ "vscode-languageclient": "~9.0.1", "vscode-uri": "~3.0.8", "vscode-ws-jsonrpc": "~3.1.0", - "windmill-parser-wasm": "^1.237.0", + "windmill-parser-wasm": "^1.274.0", "y-monaco": "^0.1.4", "y-websocket": "^1.5.0", "yaml": "^2.3.4", diff --git a/frontend/src/lib/components/ArgEnum.svelte b/frontend/src/lib/components/ArgEnum.svelte index b32e5017df..ec67b12d2d 100644 --- a/frontend/src/lib/components/ArgEnum.svelte +++ b/frontend/src/lib/components/ArgEnum.svelte @@ -6,7 +6,7 @@ export let disabled: boolean export let value: any export let enum_: string[] | undefined - export let autofocus: boolean + export let autofocus: boolean | null export let defaultValue: string | undefined export let valid: boolean export let create: boolean @@ -26,7 +26,7 @@
The folder "{name}" does not exist in the workspace. You can create it by clicking the - button below. An item can seemingly be in a folder given its path without the folder existing. A windmill folder has settable permissions that its children inherit. If an item is within a non-existing folders, only admins will see it. + button below. An item can seemingly be in a folder given its path without the folder + existing. A windmill folder has settable permissions that its children inherit. If an item + is within a non-existing folders, only admins will see it. diff --git a/frontend/src/lib/components/LightweightArgInput.svelte b/frontend/src/lib/components/LightweightArgInput.svelte index 0c7f2798a0..9ac2fc0c94 100644 --- a/frontend/src/lib/components/LightweightArgInput.svelte +++ b/frontend/src/lib/components/LightweightArgInput.svelte @@ -139,7 +139,7 @@ if (defaultValue === undefined || defaultValue === null) { if (inputCat === 'string') { value = '' - } else if (inputCat == 'enum') { + } else if (inputCat == 'enum' && required) { value = enum_?.[0] } else if (inputCat == 'boolean') { value = false diff --git a/frontend/src/lib/components/SchemaForm.svelte b/frontend/src/lib/components/SchemaForm.svelte index 96056f7d50..856571a5b3 100644 --- a/frontend/src/lib/components/SchemaForm.svelte +++ b/frontend/src/lib/components/SchemaForm.svelte @@ -132,7 +132,7 @@ {disablePortal} {resourceTypes} {prettifyHeader} - autofocus={i == 0 && autofocus} + autofocus={i == 0 && autofocus ? true : null} label={argName} description={schema.properties[argName].description} bind:value={args[argName]} diff --git a/frontend/src/lib/components/ShareModal.svelte b/frontend/src/lib/components/ShareModal.svelte index cbd226102a..8c96034213 100644 --- a/frontend/src/lib/components/ShareModal.svelte +++ b/frontend/src/lib/components/ShareModal.svelte @@ -125,6 +125,7 @@
{#key ownerKind}