Skip to content

Commit

Permalink
Merge pull request #953 from thewtex/duplicate-json-compatible
Browse files Browse the repository at this point in the history
Duplicate json compatible
  • Loading branch information
thewtex authored Sep 26, 2023
2 parents 8c488ec + 3ff0d73 commit 27db106
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
20 changes: 9 additions & 11 deletions src/bindgen/typescript/function-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ function functionModule (srcOutputDir, forNode, interfaceJson, modulePascalCase,
let functionContent = `import {\n`
const usedInterfaceTypes = new Set()
let needMountDirs = false
let needJsonCompatible = false
const pipelineComponents = ['inputs', 'outputs', 'parameters']
pipelineComponents.forEach((pipelineComponent) => {
interfaceJson[pipelineComponent].forEach((value) => {
Expand All @@ -49,10 +48,6 @@ function functionModule (srcOutputDir, forNode, interfaceJson, modulePascalCase,
needMountDirs = true
return
}
if (interfaceType === 'JsonCompatible' && pipelineComponent === 'inputs') {
needJsonCompatible = true
return
}
if (!(pipelineComponent === 'inputs' && interfaceType === 'BinaryStream')) {
usedInterfaceTypes.add(interfaceType)
}
Expand All @@ -65,9 +60,6 @@ function functionModule (srcOutputDir, forNode, interfaceJson, modulePascalCase,
functionContent += ' InterfaceTypes,\n'
functionContent += ' PipelineOutput,\n'
functionContent += ' PipelineInput,\n'
if (needJsonCompatible) {
functionContent += ' JsonCompatible,\n'
}
if (forNode) {
functionContent += ' runPipelineNode\n'
} else {
Expand Down Expand Up @@ -331,7 +323,9 @@ function functionModule (srcOutputDir, forNode, interfaceJson, modulePascalCase,
}
}
functionContent += '\n'
outputCount++
if (!interfaceType.includes('File')) {
outputCount++
}
} else {
functionContent += ` args.push(${camel}.toString())\n\n`
}
Expand Down Expand Up @@ -436,10 +430,11 @@ function functionModule (srcOutputDir, forNode, interfaceJson, modulePascalCase,
if (!forNode) {
functionContent += ' webWorker: usedWebWorker as Worker,\n'
}
interfaceJson.outputs.forEach((output, index) => {
outputCount = 0
interfaceJson.outputs.forEach((output) => {
const camel = camelCase(output.name)
const interfaceType = interfaceJsonTypeToInterfaceType.get(output.type)
const outputIndex = haveArray ? `${camel}Index` : index.toString()
const outputIndex = haveArray ? `${camel}Index` : outputCount.toString()
if (interfaceType.includes('TextStream') || interfaceType.includes('BinaryStream')) {
if (haveArray) {
const isArray = output.itemsExpectedMax > 1
Expand All @@ -465,6 +460,9 @@ function functionModule (srcOutputDir, forNode, interfaceJson, modulePascalCase,
functionContent += ` ${camel}: outputs[${outputIndex}].data as ${interfaceType},\n`
}
}
if (!interfaceType.includes('File')) {
outputCount++
}
})
functionContent += ' }\n'
functionContent += ' return result\n'
Expand Down
2 changes: 1 addition & 1 deletion src/bindgen/typescript/types-require-import.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const typesRequireImport = ['Image', 'Mesh', 'PolyData', 'TextFile', 'BinaryFile', 'TextFile', 'BinaryFile']
const typesRequireImport = ['Image', 'Mesh', 'PolyData', 'TextFile', 'BinaryFile', 'TextFile', 'BinaryFile', 'JsonCompatible']

export default typesRequireImport

0 comments on commit 27db106

Please sign in to comment.