File tree Expand file tree Collapse file tree 3 files changed +27
-4
lines changed
packages/orm/src/client/crud/validator Expand file tree Collapse file tree 3 files changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -382,9 +382,13 @@ export class InputValidator<Schema extends SchemaDef> {
382382 // zod doesn't preserve object field order after parsing, here we use a
383383 // validation-only custom schema and use the original data if parsing
384384 // is successful
385- const finalSchema = z . custom ( ( v ) => {
386- return schema . safeParse ( v ) . success ;
385+ const finalSchema = z . any ( ) . superRefine ( ( value , ctx ) => {
386+ const parseResult = schema . safeParse ( value ) ;
387+ if ( ! parseResult . success ) {
388+ parseResult . error . issues . forEach ( ( issue ) => ctx . addIssue ( issue as any ) ) ;
389+ }
387390 } ) ;
391+
388392 this . setSchemaCache ( key ! , finalSchema ) ;
389393 return finalSchema ;
390394 }
@@ -495,7 +499,7 @@ export class InputValidator<Schema extends SchemaDef> {
495499 }
496500
497501 // expression builder
498- fields [ '$expr' ] = z . custom ( ( v ) => typeof v === 'function' ) . optional ( ) ;
502+ fields [ '$expr' ] = z . custom ( ( v ) => typeof v === 'function' , { error : '"$expr" must be a function' } ) . optional ( ) ;
499503
500504 // logical operators
501505 fields [ 'AND' ] = this . orArray (
Original file line number Diff line number Diff line change @@ -121,7 +121,7 @@ model User {
121121 } ,
122122 } ,
123123 } ) ,
124- ) . rejects . toThrow ( / i n v a l i d / i ) ;
124+ ) . rejects . toThrow ( 'data.identity.providers[0].id' ) ;
125125 } ) ;
126126
127127 it ( 'works with find' , async ( ) => {
Original file line number Diff line number Diff line change 1+ import { createTestClient } from '@zenstackhq/testtools' ;
2+ import { describe , expect , it } from 'vitest' ;
3+
4+ describe ( 'Regression for issue #558' , ( ) => {
5+ it ( 'verifies issue 558' , async ( ) => {
6+ const db = await createTestClient ( `
7+ type Foo {
8+ x Int
9+ }
10+
11+ model Model {
12+ id String @id @default(cuid())
13+ foo Foo @json
14+ }
15+ ` ) ;
16+
17+ await expect ( db . model . create ( { data : { foo : { x : 'hello' } } } ) ) . rejects . toThrow ( 'data.foo.x' ) ;
18+ } ) ;
19+ } ) ;
You can’t perform that action at this time.
0 commit comments