Skip to content

Commit faa5166

Browse files
ymc9claude
andcommitted
fix(orm): preserve array mutation shape for optional typed-JSON fields
makeNullableTypedJsonMutationSchema was rebuilding the schema from type and attributes via makeScalarSchema, discarding any prior array/list mutation shape (set, push, etc.) built by the caller. Pass the already-built fieldSchema so the full shape is preserved. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent e9482fe commit faa5166

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

packages/orm/src/client/zod/factory.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -613,8 +613,9 @@ export class ZodSchemaFactory<
613613
// For optional typed JSON fields, allow DbNull, JsonNull, and null.
614614
// z.union doesn't work here because `z.any()` (returned by `makeScalarSchema`)
615615
// always wins, so we create a wrapper superRefine instead.
616-
private makeNullableTypedJsonMutationSchema(type: string, attributes?: readonly AttributeApplication[]) {
617-
const baseSchema = this.makeScalarSchema(type, attributes);
616+
// The caller must pass the already-built fieldSchema so that array/list
617+
// mutation shapes (set, push, etc.) are preserved.
618+
private makeNullableTypedJsonMutationSchema(fieldSchema: z.ZodTypeAny) {
618619
return z
619620
.any()
620621
.superRefine((value, ctx) => {
@@ -626,7 +627,7 @@ export class ZodSchemaFactory<
626627
) {
627628
return;
628629
}
629-
const parseResult = baseSchema.safeParse(value);
630+
const parseResult = fieldSchema.safeParse(value);
630631
if (!parseResult.success) {
631632
parseResult.error.issues.forEach((issue) => ctx.addIssue(issue as any));
632633
}
@@ -1337,7 +1338,7 @@ export class ZodSchemaFactory<
13371338
// DbNull for Json fields
13381339
fieldSchema = z.union([fieldSchema, z.instanceof(DbNullClass)]);
13391340
} else if (this.isTypeDefType(fieldDef.type)) {
1340-
fieldSchema = this.makeNullableTypedJsonMutationSchema(fieldDef.type, fieldDef.attributes);
1341+
fieldSchema = this.makeNullableTypedJsonMutationSchema(fieldSchema);
13411342
} else {
13421343
fieldSchema = fieldSchema.nullable();
13431344
}
@@ -1697,7 +1698,7 @@ export class ZodSchemaFactory<
16971698
// DbNull for Json fields
16981699
fieldSchema = z.union([fieldSchema, z.instanceof(DbNullClass)]);
16991700
} else if (this.isTypeDefType(fieldDef.type)) {
1700-
fieldSchema = this.makeNullableTypedJsonMutationSchema(fieldDef.type, fieldDef.attributes);
1701+
fieldSchema = this.makeNullableTypedJsonMutationSchema(fieldSchema);
17011702
} else {
17021703
fieldSchema = fieldSchema.nullable();
17031704
}

0 commit comments

Comments
 (0)