diff --git a/src/bindgen/typescript/demo/output-demo-run-typescript.js b/src/bindgen/typescript/demo/output-demo-run-typescript.js index 9d416331d..fd38837b5 100644 --- a/src/bindgen/typescript/demo/output-demo-run-typescript.js +++ b/src/bindgen/typescript/demo/output-demo-run-typescript.js @@ -12,7 +12,11 @@ function outputDemoRunTypeScript(functionName, prefix, indent, parameter) { result += `${prefix}${indent}${parameterName}OutputDownload.disabled = false\n` result += `${prefix}${indent}const ${parameterName}Output = document.getElementById("${functionName}-${parameter.name}-details")\n` const textDataProp = parameter.type.includes('FILE') ? '.data' : '' - result += `${prefix}${indent}${parameterName}Output.innerHTML = \`
$\{globalThis.escapeHtml(${parameterName}${textDataProp}.substring(0, 1024).toString() + ' ...')}\`\n` + if (parameter.itemsExpectedMax > 1) { + result += `${prefix}${indent}${parameterName}Output.innerHTML = \`
$\{globalThis.escapeHtml(JSON.stringify(${parameterName}))}\`\n` + } else { + result += `${prefix}${indent}${parameterName}Output.innerHTML = \`
$\{globalThis.escapeHtml(${parameterName}${textDataProp}.substring(0, 1024).toString() + ' ...')}\`\n` + } result += `${prefix}${indent}${parameterName}Output.disabled = false\n` } break @@ -23,7 +27,11 @@ function outputDemoRunTypeScript(functionName, prefix, indent, parameter) { result += `${prefix}${indent}${parameterName}OutputDownload.disabled = false\n` result += `${prefix}${indent}const ${parameterName}Output = document.getElementById("${functionName}-${parameter.name}-details")\n` const binaryDataProp = parameter.type.includes('FILE') ? '.data' : '' - result += `${prefix}${indent}${parameterName}Output.innerHTML = \`
$\{globalThis.escapeHtml(${parameterName}${binaryDataProp}.subarray(0, 1024).toString() + ' ...')}\`\n` + if (parameter.itemsExpectedMax > 1) { + result += `${prefix}${indent}${parameterName}Output.innerHTML = \`
$\{globalThis.escapeHtml(JSON.stringify(${parameterName})}\`\n` + } else { + result += `${prefix}${indent}${parameterName}Output.innerHTML = \`
$\{globalThis.escapeHtml(${parameterName}${binaryDataProp}.subarray(0, 1024).toString() + ' ...')}\`\n` + } result += `${prefix}${indent}${parameterName}Output.disabled = false\n` } break diff --git a/src/bindgen/typescript/demo/output-demo-typescript.js b/src/bindgen/typescript/demo/output-demo-typescript.js index 9da9e0bda..c2fbfcb15 100644 --- a/src/bindgen/typescript/demo/output-demo-typescript.js +++ b/src/bindgen/typescript/demo/output-demo-typescript.js @@ -14,8 +14,13 @@ function outputDemoTypeScript(functionName, prefix, indent, parameter) { result += `${prefix}${indent}${indent}event.stopPropagation()\n` result += `${prefix}${indent}${indent}if (model.outputs.has("${parameterName}")) {\n` const textDataProp = parameter.type.includes('FILE') ? '.data' : '' - const downloadFileName = parameter.type.includes('FILE') ? `model.outputs.get("${parameterName}").path`: `"${parameterName}.txt"` - result += `${prefix}${indent}${indent}${indent}globalThis.downloadFile(new TextEncoder().encode(model.outputs.get("${parameterName}")${textDataProp}), ${downloadFileName})\n` + if (parameter.itemsExpectedMax > 1) { + const downloadFileName = parameter.type.includes('FILE') ? `o.path`: `"${parameterName}.txt"` + result += `${prefix}${indent}${indent}${indent}model.outputs.get("${parameterName}").forEach((o) => globalThis.downloadFile(new TextEncoder().encode(o${textDataProp}), ${downloadFileName}))\n` + } else { + const downloadFileName = parameter.type.includes('FILE') ? `model.outputs.get("${parameterName}").path`: `"${parameterName}.txt"` + result += `${prefix}${indent}${indent}${indent}globalThis.downloadFile(new TextEncoder().encode(model.outputs.get("${parameterName}")${textDataProp}), ${downloadFileName})\n` + } result += `${prefix}${indent}${indent}}\n` result += `${prefix}${indent}})\n` } @@ -29,8 +34,13 @@ function outputDemoTypeScript(functionName, prefix, indent, parameter) { result += `${prefix}${indent}${indent}event.stopPropagation()\n` result += `${prefix}${indent}${indent}if (model.outputs.has("${parameterName}")) {\n` const binaryDataProp = parameter.type.includes('FILE') ? '.data' : '' - const downloadFileName = parameter.type.includes('FILE') ? `model.outputs.get("${parameterName}").path`: `"${parameterName}.bin"` - result += `${prefix}${indent}${indent}${indent}globalThis.downloadFile(model.outputs.get("${parameterName}")${binaryDataProp}, ${downloadFileName})\n` + if (parameter.itemsExpectedMax > 1) { + const downloadFileName = parameter.type.includes('FILE') ? `o.path`: `"${parameterName}.bin"` + result += `${prefix}${indent}${indent}${indent}model.outputs.get("${parameterName}").forEach((o) => globalThis.downloadFile(o${binaryDataProp}, ${downloadFileName}))\n` + } else { + const downloadFileName = parameter.type.includes('FILE') ? `model.outputs.get("${parameterName}").path`: `"${parameterName}.bin"` + result += `${prefix}${indent}${indent}${indent}globalThis.downloadFile(model.outputs.get("${parameterName}")${binaryDataProp}, ${downloadFileName})\n` + } result += `${prefix}${indent}${indent}}\n` result += `${prefix}${indent}})\n` } diff --git a/src/bindgen/typescript/function-module.js b/src/bindgen/typescript/function-module.js index 55b0497d7..f497bd6d6 100644 --- a/src/bindgen/typescript/function-module.js +++ b/src/bindgen/typescript/function-module.js @@ -195,6 +195,7 @@ function functionModule (srcOutputDir, forNode, interfaceJson, modulePascalCase, } }) } + let haveArray = false functionContent += ' const desiredOutputs: Array