diff --git a/src/comfy-code-gen.ts b/src/comfy-code-gen.ts index a4bdf10..b685b15 100644 --- a/src/comfy-code-gen.ts +++ b/src/comfy-code-gen.ts @@ -1,4 +1,5 @@ -// Code generation from the workflow JSON file. +// Code generation from the workflow JSON file. This code is very messy and hopefully it will never be touched again. + import type { Static } from "@sinclair/typebox" import type { WorkflowSchema } from "./comfy-types-base" @@ -26,12 +27,12 @@ export function GenerateTSFromJson(json: Static, base = ' done.add(nodeN) } - function resolveArc(value: number | string | boolean | [string, number]) { - if (typeof value !== 'object') return JSON.stringify(value) + function resolveArc(value: number | string | boolean | null | undefined | [string, number]) { + if (typeof value !== 'object' || value === null || value === undefined) return JSON.stringify(value) else { const val = json.extra_data?.extra_pnginfo.workflow.nodes.find(x => x.id === Number.parseInt(value[0]))?.outputs[value[1]] resolveNode(Number.parseInt(value[0])) - return `node_${value[0]}[${JSON.stringify(val.name)}]`; + return `node_${value[0]}[${JSON.stringify(val?.name)}]`; } } diff --git a/src/comfy-types-base.ts b/src/comfy-types-base.ts index 6f647f3..9e0b9d7 100644 --- a/src/comfy-types-base.ts +++ b/src/comfy-types-base.ts @@ -59,7 +59,16 @@ export const WorkflowSchema = t.Object({ workflow: t.Object({ last_node_id: t.Optional(t.Integer()), last_link_id: t.Optional(t.Integer()), - nodes: t.Array(t.Object({})), + nodes: t.Array(t.Object({ + id: t.Integer(), + type: t.String(), + inputs: t.Array(t.Object({})), + outputs: t.Array(t.Object({ + name: t.String(), + type: t.String(), + links: t.Array(t.Integer()), + })) + })), links: t.Array( t.Tuple([ t.Integer({ description: "ID" }),