Skip to content

Commit c48f68e

Browse files
authored
Revert to sync validation on node def for better performance (#297)
1 parent 0210c7f commit c48f68e

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

src/scripts/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ class ComfyApi extends EventTarget {
249249
const objectInfoUnsafe = await resp.json()
250250
const objectInfo: Record<string, ComfyNodeDef> = {}
251251
for (const key in objectInfoUnsafe) {
252-
const validatedDef = await validateComfyNodeDef(
252+
const validatedDef = validateComfyNodeDef(
253253
objectInfoUnsafe[key],
254254
/* onError=*/ (errorMessage: string) => {
255255
console.warn(

src/types/apiTypes.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,11 +285,11 @@ export type ComfyInputsSpec = z.infer<typeof zComfyInputsSpec>
285285
export type ComfyOutputTypesSpec = z.infer<typeof zComfyOutputTypesSpec>
286286
export type ComfyNodeDef = z.infer<typeof zComfyNodeDef>
287287

288-
export async function validateComfyNodeDef(
288+
export function validateComfyNodeDef(
289289
data: any,
290290
onError: (error: string) => void = console.warn
291-
): Promise<ComfyNodeDef | null> {
292-
const result = await zComfyNodeDef.safeParseAsync(data)
291+
): ComfyNodeDef | null {
292+
const result = zComfyNodeDef.safeParse(data)
293293
if (!result.success) {
294294
const zodError = fromZodError(result.error)
295295
onError(

tests-ui/tests/apiTypes.test.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const EXAMPLE_NODE_DEF: ComfyNodeDef = {
2121

2222
describe('validateNodeDef', () => {
2323
it('Should accept a valid node definition', async () => {
24-
expect(await validateComfyNodeDef(EXAMPLE_NODE_DEF)).not.toBeNull()
24+
expect(validateComfyNodeDef(EXAMPLE_NODE_DEF)).not.toBeNull()
2525
})
2626

2727
describe.each([
@@ -37,14 +37,12 @@ describe('validateNodeDef', () => {
3737
(inputSpec, expected) => {
3838
it(`should accept input spec format: ${JSON.stringify(inputSpec)}`, async () => {
3939
expect(
40-
(
41-
await validateComfyNodeDef({
42-
...EXAMPLE_NODE_DEF,
43-
input: {
44-
required: inputSpec
45-
}
46-
})
47-
).input.required.ckpt_name
40+
validateComfyNodeDef({
41+
...EXAMPLE_NODE_DEF,
42+
input: {
43+
required: inputSpec
44+
}
45+
}).input.required.ckpt_name
4846
).toEqual(expected)
4947
})
5048
}
@@ -61,7 +59,7 @@ describe('validateNodeDef', () => {
6159
(inputSpec) => {
6260
it(`should accept input spec format: ${JSON.stringify(inputSpec)}`, async () => {
6361
expect(
64-
await validateComfyNodeDef({
62+
validateComfyNodeDef({
6563
...EXAMPLE_NODE_DEF,
6664
input: {
6765
required: inputSpec
@@ -80,7 +78,7 @@ describe('validateNodeDef', () => {
8078
)
8179

8280
for (const nodeDef of nodeDefs) {
83-
expect(await validateComfyNodeDef(nodeDef)).not.toBeNull()
81+
expect(validateComfyNodeDef(nodeDef)).not.toBeNull()
8482
}
8583
})
8684
})

0 commit comments

Comments
 (0)