mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-01-26 19:09:52 +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.experimental =
|
||||
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.nodeSource = getNodeSource(obj.python_module)
|
||||
}
|
||||
|
||||
private static transformOutputSpec(obj: any): ComfyOutputsSpec {
|
||||
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
|
||||
|
||||
return new ComfyOutputSpec(
|
||||
index,
|
||||
output_name[index],
|
||||
output_name?.[index],
|
||||
typeString,
|
||||
output_is_list[index],
|
||||
output_is_list?.[index],
|
||||
Array.isArray(type) ? type : undefined,
|
||||
output_tooltips?.[index]
|
||||
)
|
||||
|
||||
@@ -346,10 +346,10 @@ const zComfyOutputTypesSpec = z.array(
|
||||
)
|
||||
|
||||
const zComfyNodeDef = z.object({
|
||||
input: zComfyInputsSpec,
|
||||
output: zComfyOutputTypesSpec,
|
||||
output_is_list: z.array(z.boolean()),
|
||||
output_name: z.array(z.string()),
|
||||
input: zComfyInputsSpec.optional(),
|
||||
output: zComfyOutputTypesSpec.optional(),
|
||||
output_is_list: z.array(z.boolean()).optional(),
|
||||
output_name: z.array(z.string()).optional(),
|
||||
output_tooltips: z.array(z.string()).optional(),
|
||||
name: z.string(),
|
||||
display_name: z.string(),
|
||||
|
||||
@@ -356,6 +356,20 @@ describe('ComfyNodeDefImpl', () => {
|
||||
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', () => {
|
||||
const plainObject = {
|
||||
name: 'ComplexInputNode',
|
||||
|
||||
Reference in New Issue
Block a user