Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert to sync validation on node def for better performance #297

Merged
merged 1 commit into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/scripts/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ class ComfyApi extends EventTarget {
const objectInfoUnsafe = await resp.json()
const objectInfo: Record<string, ComfyNodeDef> = {}
for (const key in objectInfoUnsafe) {
const validatedDef = await validateComfyNodeDef(
const validatedDef = validateComfyNodeDef(
objectInfoUnsafe[key],
/* onError=*/ (errorMessage: string) => {
console.warn(
Expand Down
6 changes: 3 additions & 3 deletions src/types/apiTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,11 @@ export type ComfyInputsSpec = z.infer<typeof zComfyInputsSpec>
export type ComfyOutputTypesSpec = z.infer<typeof zComfyOutputTypesSpec>
export type ComfyNodeDef = z.infer<typeof zComfyNodeDef>

export async function validateComfyNodeDef(
export function validateComfyNodeDef(
data: any,
onError: (error: string) => void = console.warn
): Promise<ComfyNodeDef | null> {
const result = await zComfyNodeDef.safeParseAsync(data)
): ComfyNodeDef | null {
const result = zComfyNodeDef.safeParse(data)
if (!result.success) {
const zodError = fromZodError(result.error)
onError(
Expand Down
20 changes: 9 additions & 11 deletions tests-ui/tests/apiTypes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const EXAMPLE_NODE_DEF: ComfyNodeDef = {

describe('validateNodeDef', () => {
it('Should accept a valid node definition', async () => {
expect(await validateComfyNodeDef(EXAMPLE_NODE_DEF)).not.toBeNull()
expect(validateComfyNodeDef(EXAMPLE_NODE_DEF)).not.toBeNull()
})

describe.each([
Expand All @@ -37,14 +37,12 @@ describe('validateNodeDef', () => {
(inputSpec, expected) => {
it(`should accept input spec format: ${JSON.stringify(inputSpec)}`, async () => {
expect(
(
await validateComfyNodeDef({
...EXAMPLE_NODE_DEF,
input: {
required: inputSpec
}
})
).input.required.ckpt_name
validateComfyNodeDef({
...EXAMPLE_NODE_DEF,
input: {
required: inputSpec
}
}).input.required.ckpt_name
).toEqual(expected)
})
}
Expand All @@ -61,7 +59,7 @@ describe('validateNodeDef', () => {
(inputSpec) => {
it(`should accept input spec format: ${JSON.stringify(inputSpec)}`, async () => {
expect(
await validateComfyNodeDef({
validateComfyNodeDef({
...EXAMPLE_NODE_DEF,
input: {
required: inputSpec
Expand All @@ -80,7 +78,7 @@ describe('validateNodeDef', () => {
)

for (const nodeDef of nodeDefs) {
expect(await validateComfyNodeDef(nodeDef)).not.toBeNull()
expect(validateComfyNodeDef(nodeDef)).not.toBeNull()
}
})
})
Loading