mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-29 02:32:18 +00:00
Fix node def handling of undefined fields (#1199)
* Fix node def handling * nit * Add test
This commit is contained in:
@@ -169,21 +169,21 @@ export class ComfyNodeDefImpl {
|
|||||||
this.deprecated = obj.deprecated ?? obj.category === ''
|
this.deprecated = obj.deprecated ?? obj.category === ''
|
||||||
this.experimental =
|
this.experimental =
|
||||||
obj.experimental ?? obj.category.startsWith('_for_testing')
|
obj.experimental ?? obj.category.startsWith('_for_testing')
|
||||||
this.input = new ComfyInputsSpec(obj.input)
|
this.input = new ComfyInputsSpec(obj.input ?? {})
|
||||||
this.output = ComfyNodeDefImpl.transformOutputSpec(obj)
|
this.output = ComfyNodeDefImpl.transformOutputSpec(obj)
|
||||||
this.nodeSource = getNodeSource(obj.python_module)
|
this.nodeSource = getNodeSource(obj.python_module)
|
||||||
}
|
}
|
||||||
|
|
||||||
private static transformOutputSpec(obj: any): ComfyOutputsSpec {
|
private static transformOutputSpec(obj: any): ComfyOutputsSpec {
|
||||||
const { output, output_is_list, output_name, output_tooltips } = obj
|
const { output, output_is_list, output_name, output_tooltips } = obj
|
||||||
const result = output.map((type: string | any[], index: number) => {
|
const result = (output ?? []).map((type: string | any[], index: number) => {
|
||||||
const typeString = Array.isArray(type) ? 'COMBO' : type
|
const typeString = Array.isArray(type) ? 'COMBO' : type
|
||||||
|
|
||||||
return new ComfyOutputSpec(
|
return new ComfyOutputSpec(
|
||||||
index,
|
index,
|
||||||
output_name[index],
|
output_name?.[index],
|
||||||
typeString,
|
typeString,
|
||||||
output_is_list[index],
|
output_is_list?.[index],
|
||||||
Array.isArray(type) ? type : undefined,
|
Array.isArray(type) ? type : undefined,
|
||||||
output_tooltips?.[index]
|
output_tooltips?.[index]
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -346,10 +346,10 @@ const zComfyOutputTypesSpec = z.array(
|
|||||||
)
|
)
|
||||||
|
|
||||||
const zComfyNodeDef = z.object({
|
const zComfyNodeDef = z.object({
|
||||||
input: zComfyInputsSpec,
|
input: zComfyInputsSpec.optional(),
|
||||||
output: zComfyOutputTypesSpec,
|
output: zComfyOutputTypesSpec.optional(),
|
||||||
output_is_list: z.array(z.boolean()),
|
output_is_list: z.array(z.boolean()).optional(),
|
||||||
output_name: z.array(z.string()),
|
output_name: z.array(z.string()).optional(),
|
||||||
output_tooltips: z.array(z.string()).optional(),
|
output_tooltips: z.array(z.string()).optional(),
|
||||||
name: z.string(),
|
name: z.string(),
|
||||||
display_name: z.string(),
|
display_name: z.string(),
|
||||||
|
|||||||
@@ -356,6 +356,20 @@ describe('ComfyNodeDefImpl', () => {
|
|||||||
expect(result.output.all).toEqual([])
|
expect(result.output.all).toEqual([])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should handle undefined fields', () => {
|
||||||
|
const plainObject = {
|
||||||
|
name: 'EmptyOutputNode',
|
||||||
|
display_name: 'Empty Output Node',
|
||||||
|
category: 'Test',
|
||||||
|
python_module: 'test_module',
|
||||||
|
description: 'A node with no outputs'
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = new ComfyNodeDefImpl(plainObject)
|
||||||
|
expect(result.output.all).toEqual([])
|
||||||
|
expect(result.input.all).toEqual([])
|
||||||
|
})
|
||||||
|
|
||||||
it('should handle complex input specifications', () => {
|
it('should handle complex input specifications', () => {
|
||||||
const plainObject = {
|
const plainObject = {
|
||||||
name: 'ComplexInputNode',
|
name: 'ComplexInputNode',
|
||||||
|
|||||||
Reference in New Issue
Block a user