diff --git a/backend/Cargo.lock b/backend/Cargo.lock index db341750ea7e2..57c82ebadcdb5 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -4523,9 +4523,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.70" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" +checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" dependencies = [ "wasm-bindgen", ] @@ -5058,16 +5058,6 @@ dependencies = [ "unicase", ] -[[package]] -name = "minicov" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c71e683cd655513b99affab7d317deb690528255a0d5f717f1024093c12b169" -dependencies = [ - "cc", - "walkdir", -] - [[package]] name = "minimal-lexical" version = "0.2.1" @@ -10211,20 +10201,19 @@ checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b" [[package]] name = "wasm-bindgen" -version = "0.2.93" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" dependencies = [ "cfg-if", - "once_cell", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.93" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" dependencies = [ "bumpalo", "log", @@ -10237,9 +10226,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.43" +version = "0.4.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +checksum = "76bc14366121efc8dbb487ab05bcc9d346b3b5ec0eaa76e46594cabbe51762c0" dependencies = [ "cfg-if", "js-sys", @@ -10249,9 +10238,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.93" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -10259,9 +10248,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.93" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", @@ -10272,19 +10261,18 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.93" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" +checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" [[package]] name = "wasm-bindgen-test" -version = "0.3.43" +version = "0.3.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68497a05fb21143a08a7d24fc81763384a3072ee43c44e86aad1744d6adef9d9" +checksum = "d9bf62a58e0780af3e852044583deee40983e5886da43a271dd772379987667b" dependencies = [ "console_error_panic_hook", "js-sys", - "minicov", "scoped-tls", "wasm-bindgen", "wasm-bindgen-futures", @@ -10293,9 +10281,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-test-macro" -version = "0.3.43" +version = "0.3.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b8220be1fa9e4c889b30fd207d4906657e7e90b12e0e6b0c8b8d8709f5de021" +checksum = "b7f89739351a2e03cb94beb799d47fb2cac01759b40ec441f7de39b00cbf7ef0" dependencies = [ "proc-macro2", "quote", @@ -10326,9 +10314,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.70" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" dependencies = [ "js-sys", "wasm-bindgen", diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 7c7ab8179dbb5..d7aaf4fd513d9 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -219,7 +219,7 @@ rsmq_async = { version = "5.1.5" } gosyn = "0.2.6" bytes = "1.4.0" gethostname = "0.4.3" -wasm-bindgen = "0.2.92" +wasm-bindgen = "=0.2.92" serde-wasm-bindgen = "0.6.5" wasm-bindgen-test = "0.3.42" convert_case = "0.6.0" diff --git a/cli/bootstrap/common.ts b/cli/bootstrap/common.ts index 44b2026b415c4..87eaf159eccb6 100644 --- a/cli/bootstrap/common.ts +++ b/cli/bootstrap/common.ts @@ -9,9 +9,11 @@ export interface SchemaProperty { contentEncoding?: "base64" | "binary"; format?: string; items?: { - type?: "string" | "number" | "bytes" | "object"; + type?: "string" | "number" | "bytes" | "object" | "resource"; contentEncoding?: "base64"; enum?: string[]; + resourceType?: string; + properties?: { [name: string]: SchemaProperty }; }; min?: number; max?: number; diff --git a/cli/metadata.ts b/cli/metadata.ts index 0da0fb1268f68..1d0fa16eb3bc9 100644 --- a/cli/metadata.ts +++ b/cli/metadata.ts @@ -530,17 +530,19 @@ function sortObject(obj: any): any { ); } +//copied straight fron frontend /src/utils/inferArgs.ts export function argSigToJsonSchemaType( t: | string | { resource: string | null } | { list: - | string + | (string | { object: { key: string; typ: any }[] }) | { str: any } | { object: { key: string; typ: any }[] } | null; } + | { dynselect: string } | { str: string[] | null } | { object: { key: string; typ: any }[] } | { @@ -553,7 +555,7 @@ export function argSigToJsonSchemaType( }, oldS: SchemaProperty ): void { - let newS: SchemaProperty = { type: "" }; + const newS: SchemaProperty = { type: "" }; if (t === "int") { newS.type = "integer"; } else if (t === "float") { @@ -618,6 +620,9 @@ export function argSigToJsonSchemaType( if (t.str) { newS.originalType = "enum"; newS.enum = t.str; + } else if (oldS.originalType == "string" && oldS.enum) { + newS.originalType = "string"; + newS.enum = oldS.enum; } else { newS.originalType = "string"; newS.enum = undefined; @@ -625,6 +630,9 @@ export function argSigToJsonSchemaType( } else if (typeof t !== "string" && `resource` in t) { newS.type = "object"; newS.format = `resource-${t.resource}`; + } else if (typeof t !== "string" && `dynselect` in t) { + newS.type = "object"; + newS.format = `dynselect-${t.dynselect}`; } else if (typeof t !== "string" && `list` in t) { newS.type = "array"; if (t.list === "int" || t.list === "float") { @@ -635,6 +643,31 @@ export function argSigToJsonSchemaType( newS.items = { type: "string" }; } else if (t.list && typeof t.list == "object" && "str" in t.list) { newS.items = { type: "string", enum: t.list.str }; + } else if ( + t.list && + typeof t.list == "object" && + "resource" in t.list && + t.list.resource + ) { + newS.items = { + type: "resource", + resourceType: t.list.resource as string, + }; + } else if ( + t.list && + typeof t.list == "object" && + "object" in t.list && + t.list.object && + t.list.object.length > 0 + ) { + const properties: Record = {}; + for (const prop of t.list.object) { + properties[prop.key] = { description: "", type: "" }; + + argSigToJsonSchemaType(prop.typ, properties[prop.key]); + } + + newS.items = { type: "object", properties: properties }; } else { newS.items = { type: "object" }; } diff --git a/cli/wasm/windmill_parser_wasm.generated.d.ts b/cli/wasm/windmill_parser_wasm.generated.d.ts index 23c90544228ad..10824a1c62f85 100644 --- a/cli/wasm/windmill_parser_wasm.generated.d.ts +++ b/cli/wasm/windmill_parser_wasm.generated.d.ts @@ -18,7 +18,8 @@ export interface InstantiateResult { parse_mssql: typeof parse_mssql; parse_db_resource: typeof parse_db_resource; parse_graphql: typeof parse_graphql; - parse_php: typeof parse_php + parse_php: typeof parse_php; + parse_rust: typeof parse_rust }; } @@ -118,3 +119,8 @@ export function parse_graphql(code: string): string; * @returns {string} */ export function parse_php(code: string): string; +/** +* @param {string} code +* @returns {string} +*/ +export function parse_rust(code: string): string; diff --git a/cli/wasm/windmill_parser_wasm.generated.js b/cli/wasm/windmill_parser_wasm.generated.js index 3866aad19a8df..ea2404efeb2f9 100644 --- a/cli/wasm/windmill_parser_wasm.generated.js +++ b/cli/wasm/windmill_parser_wasm.generated.js @@ -4,7 +4,7 @@ // deno-fmt-ignore-file /// -// source-hash: ae1bfe27a90c5656a723fb7ced38f4857a5d6931 +// source-hash: d36b5583d8f6223c130a246a8713b8621d55b990 let wasm; const heap = new Array(128).fill(undefined); @@ -15,20 +15,6 @@ function getObject(idx) { return heap[idx]; } -let heap_next = heap.length; - -function dropObject(idx) { - if (idx < 132) return; - heap[idx] = heap_next; - heap_next = idx; -} - -function takeObject(idx) { - const ret = getObject(idx); - dropObject(idx); - return ret; -} - let WASM_VECTOR_LEN = 0; let cachedUint8Memory0 = null; @@ -103,19 +89,27 @@ function getInt32Memory0() { return cachedInt32Memory0; } -const cachedTextDecoder = typeof TextDecoder !== "undefined" - ? new TextDecoder("utf-8", { ignoreBOM: true, fatal: true }) - : { - decode: () => { - throw Error("TextDecoder not available"); - }, - }; +let heap_next = heap.length; -if (typeof TextDecoder !== "undefined") cachedTextDecoder.decode(); +function dropObject(idx) { + if (idx < 132) return; + heap[idx] = heap_next; + heap_next = idx; +} -function getStringFromWasm0(ptr, len) { - ptr = ptr >>> 0; - return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len)); +function takeObject(idx) { + const ret = getObject(idx); + dropObject(idx); + return ret; +} + +let cachedFloat64Memory0 = null; + +function getFloat64Memory0() { + if (cachedFloat64Memory0 === null || cachedFloat64Memory0.byteLength === 0) { + cachedFloat64Memory0 = new Float64Array(wasm.memory.buffer); + } + return cachedFloat64Memory0; } function addHeapObject(obj) { @@ -127,13 +121,19 @@ function addHeapObject(obj) { return idx; } -let cachedFloat64Memory0 = null; +const cachedTextDecoder = typeof TextDecoder !== "undefined" + ? new TextDecoder("utf-8", { ignoreBOM: true, fatal: true }) + : { + decode: () => { + throw Error("TextDecoder not available"); + }, + }; -function getFloat64Memory0() { - if (cachedFloat64Memory0 === null || cachedFloat64Memory0.byteLength === 0) { - cachedFloat64Memory0 = new Float64Array(wasm.memory.buffer); - } - return cachedFloat64Memory0; +if (typeof TextDecoder !== "undefined") cachedTextDecoder.decode(); + +function getStringFromWasm0(ptr, len) { + ptr = ptr >>> 0; + return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len)); } let cachedBigInt64Memory0 = null; @@ -616,6 +616,33 @@ export function parse_php(code) { } } +/** + * @param {string} code + * @returns {string} + */ +export function parse_rust(code) { + let deferred2_0; + let deferred2_1; + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + const ptr0 = passStringToWasm0( + code, + wasm.__wbindgen_malloc, + wasm.__wbindgen_realloc, + ); + const len0 = WASM_VECTOR_LEN; + wasm.parse_rust(retptr, ptr0, len0); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + deferred2_0 = r0; + deferred2_1 = r1; + return getStringFromWasm0(r0, r1); + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + wasm.__wbindgen_free(deferred2_0, deferred2_1, 1); + } +} + function handleError(f, args) { try { return f.apply(this, args); @@ -626,9 +653,6 @@ function handleError(f, args) { const imports = { __wbindgen_placeholder__: { - __wbindgen_object_drop_ref: function (arg0) { - takeObject(arg0); - }, __wbindgen_string_get: function (arg0, arg1) { const obj = getObject(arg1); const ret = typeof obj === "string" ? obj : undefined; @@ -643,13 +667,8 @@ const imports = { getInt32Memory0()[arg0 / 4 + 1] = len1; getInt32Memory0()[arg0 / 4 + 0] = ptr1; }, - __wbg_eval_c74b339326c2fc56: function (arg0, arg1) { - const ret = eval(getStringFromWasm0(arg0, arg1)); - return addHeapObject(ret); - }, - __wbindgen_error_new: function (arg0, arg1) { - const ret = new Error(getStringFromWasm0(arg0, arg1)); - return addHeapObject(ret); + __wbindgen_object_drop_ref: function (arg0) { + takeObject(arg0); }, __wbindgen_boolean_get: function (arg0) { const v = getObject(arg0); @@ -687,6 +706,14 @@ const imports = { const ret = BigInt.asUintN(64, arg0); return addHeapObject(ret); }, + __wbindgen_error_new: function (arg0, arg1) { + const ret = new Error(getStringFromWasm0(arg0, arg1)); + return addHeapObject(ret); + }, + __wbg_eval_c227cc6614cd76e5: function (arg0, arg1) { + const ret = eval(getStringFromWasm0(arg0, arg1)); + return addHeapObject(ret); + }, __wbindgen_jsval_loose_eq: function (arg0, arg1) { const ret = getObject(arg0) == getObject(arg1); return ret; @@ -965,6 +992,7 @@ function getWasmInstanceExports() { parse_db_resource, parse_graphql, parse_php, + parse_rust, }; } diff --git a/cli/wasm/windmill_parser_wasm_bg.wasm b/cli/wasm/windmill_parser_wasm_bg.wasm index f2f34e37a2504..de163879c8024 100644 Binary files a/cli/wasm/windmill_parser_wasm_bg.wasm and b/cli/wasm/windmill_parser_wasm_bg.wasm differ diff --git a/frontend/src/lib/infer.ts b/frontend/src/lib/infer.ts index edd8774c55f9a..23a1c055025bb 100644 --- a/frontend/src/lib/infer.ts +++ b/frontend/src/lib/infer.ts @@ -4,11 +4,7 @@ import type { Schema, SupportedLanguage } from './common.js' import { emptySchema, sortObject } from './utils.js' import { tick } from 'svelte' -import initTsParser, { - parse_deno, - parse_outputs, - parse_ts_imports -} from 'windmill-parser-wasm-ts' +import initTsParser, { parse_deno, parse_outputs, parse_ts_imports } from 'windmill-parser-wasm-ts' import initRegexParsers, { parse_sql, parse_mysql, @@ -18,20 +14,12 @@ import initRegexParsers, { parse_mssql, parse_db_resource, parse_bash, - parse_powershell, + parse_powershell } from 'windmill-parser-wasm-regex' -import initPythonParser, { - parse_python, -} from 'windmill-parser-wasm-py' -import initGoParser, { - parse_go, -} from 'windmill-parser-wasm-go' -import initPhpParser, { - parse_php, -} from 'windmill-parser-wasm-php' -import initRustParser, { - parse_rust, -} from 'windmill-parser-wasm-rust' +import initPythonParser, { parse_python } from 'windmill-parser-wasm-py' +import initGoParser, { parse_go } from 'windmill-parser-wasm-go' +import initPhpParser, { parse_php } from 'windmill-parser-wasm-php' +import initRustParser, { parse_rust } from 'windmill-parser-wasm-rust' import wasmUrlTs from 'windmill-parser-wasm-ts/windmill_parser_wasm_bg.wasm?url' import wasmUrlRegex from 'windmill-parser-wasm-regex/windmill_parser_wasm_bg.wasm?url' @@ -44,7 +32,7 @@ import { argSigToJsonSchemaType } from './inferArgSig.js' const loadSchemaLastRun = writable<[string | undefined, MainArgSignature | undefined]>(undefined) -let initializeTsPromise : Promise | undefined = undefined; +let initializeTsPromise: Promise | undefined = undefined export async function initWasmTs() { if (initializeTsPromise == undefined) { initializeTsPromise = initTsParser(wasmUrlTs) diff --git a/frontend/src/lib/inferArgSig.ts b/frontend/src/lib/inferArgSig.ts index 5316ff26a5a28..54d63873e2a15 100644 --- a/frontend/src/lib/inferArgSig.ts +++ b/frontend/src/lib/inferArgSig.ts @@ -24,7 +24,7 @@ export function argSigToJsonSchemaType( }, oldS: SchemaProperty ): void { - let newS: SchemaProperty = { type: '' } + const newS: SchemaProperty = { type: '' } if (t === 'int') { newS.type = 'integer' } else if (t === 'float') { @@ -52,7 +52,7 @@ export function argSigToJsonSchemaType( if (t.oneof) { newS.oneOf = t.oneof.map((obj) => { const oldObjS = oldS.oneOf?.find((o) => o?.title === obj.label) ?? undefined - const properties = {} + const properties: Record = {} for (const prop of obj.properties) { if (oldObjS?.properties && prop.key in oldObjS?.properties) { properties[prop.key] = oldObjS?.properties[prop.key] @@ -72,7 +72,7 @@ export function argSigToJsonSchemaType( } else if (typeof t !== 'string' && `object` in t) { newS.type = 'object' if (t.object) { - const properties = {} + const properties: Record = {} for (const prop of t.object) { if (oldS.properties && prop.key in oldS.properties) { properties[prop.key] = oldS.properties[prop.key] @@ -112,7 +112,10 @@ export function argSigToJsonSchemaType( } else if (t.list && typeof t.list == 'object' && 'str' in t.list) { newS.items = { type: 'string', enum: t.list.str } } else if (t.list && typeof t.list == 'object' && 'resource' in t.list && t.list.resource) { - newS.items = { type: 'resource', resourceType: t.list.resource as string } + newS.items = { + type: 'resource', + resourceType: t.list.resource as string + } } else if ( t.list && typeof t.list == 'object' && @@ -120,7 +123,7 @@ export function argSigToJsonSchemaType( t.list.object && t.list.object.length > 0 ) { - const properties = {} + const properties: Record = {} for (const prop of t.list.object) { properties[prop.key] = { description: '', type: '' } @@ -154,7 +157,9 @@ export function argSigToJsonSchemaType( ] preservedFields.forEach((field) => { + // @ts-ignore if (oldS[field] !== undefined) { + // @ts-ignore newS[field] = oldS[field] } }) @@ -162,6 +167,7 @@ export function argSigToJsonSchemaType( if (oldS.type != newS.type) { for (const prop of Object.getOwnPropertyNames(newS)) { if (prop != 'description') { + // @ts-ignore delete oldS[prop] } }