3
3
* @requires core
4
4
*/
5
5
import * as constants from '../constants.js' ;
6
- import * as z from 'zod' ;
6
+ import { z } from 'zod/v4 ' ;
7
7
import dataDoc from '../../../docs/parameterData.json' ;
8
8
9
9
function validateParams ( p5 , fn , lifecycles ) {
@@ -230,6 +230,10 @@ function validateParams(p5, fn, lifecycles) {
230
230
param = param ?. replace ( / ^ \. \. \. ( .+ ) \[ \] $ / , '$1' ) ;
231
231
232
232
let schema = generateTypeSchema ( param ) ;
233
+ if ( ! schema || typeof schema . optional !== 'function' ) {
234
+ schema = z . any ( ) ;
235
+ }
236
+
233
237
if ( isOptional ) {
234
238
schema = schema . optional ( ) ;
235
239
}
@@ -318,7 +322,7 @@ function validateParams(p5, fn, lifecycles) {
318
322
}
319
323
320
324
const numArgs = args . length ;
321
- const schemaItems = schema . items ;
325
+ const schemaItems = schema . def . items ;
322
326
const numSchemaItems = schemaItems . length ;
323
327
const numRequiredSchemaItems = schemaItems . filter ( item => ! item . isOptional ( ) ) . length ;
324
328
@@ -353,11 +357,11 @@ function validateParams(p5, fn, lifecycles) {
353
357
} ;
354
358
355
359
// Default to the first schema, so that we are guaranteed to return a result.
356
- let closestSchema = schema . _def . options [ 0 ] ;
360
+ let closestSchema = schema . def . options [ 0 ] ;
357
361
// We want to return the schema with the lowest score.
358
362
let bestScore = Infinity ;
359
363
360
- const schemaUnion = schema . _def . options ;
364
+ const schemaUnion = schema . def . options ;
361
365
schemaUnion . forEach ( schema => {
362
366
const score = scoreSchema ( schema ) ;
363
367
if ( score < bestScore ) {
@@ -386,7 +390,7 @@ function validateParams(p5, fn, lifecycles) {
386
390
// (after scoring the schema closeness in `findClosestSchema`). Here, we
387
391
// always print the first error so that user can work through the errors
388
392
// one by one.
389
- let currentError = zodErrorObj . errors [ 0 ] ;
393
+ let currentError = zodErrorObj . issues [ 0 ] ;
390
394
391
395
// Helper function to build a type mismatch message.
392
396
const buildTypeMismatchMessage = ( actualType , expectedTypeStr , position ) => {
@@ -403,11 +407,11 @@ function validateParams(p5, fn, lifecycles) {
403
407
const expectedTypes = new Set ( ) ;
404
408
let actualType ;
405
409
406
- error . unionErrors . forEach ( err => {
407
- const issue = err . issues [ 0 ] ;
410
+ error . errors . forEach ( err => {
411
+ const issue = err [ 0 ] ;
408
412
if ( issue ) {
409
413
if ( ! actualType ) {
410
- actualType = issue . received ;
414
+ actualType = issue . message ;
411
415
}
412
416
413
417
if ( issue . code === 'invalid_type' ) {
@@ -416,8 +420,9 @@ function validateParams(p5, fn, lifecycles) {
416
420
// The case for constants. Since we don't want to print out the actual
417
421
// constant values in the error message, the error message will
418
422
// direct users to the documentation.
419
- else if ( issue . code === 'invalid_literal ' ) {
423
+ else if ( issue . code === 'invalid_value ' ) {
420
424
expectedTypes . add ( "constant (please refer to documentation for allowed values)" ) ;
425
+ actualType = args [ error . path [ 0 ] ] ;
421
426
} else if ( issue . code === 'custom' ) {
422
427
const match = issue . message . match ( / I n p u t n o t i n s t a n c e o f ( \w + ) / ) ;
423
428
if ( match ) expectedTypes . add ( match [ 1 ] ) ;
@@ -452,7 +457,7 @@ function validateParams(p5, fn, lifecycles) {
452
457
break ;
453
458
}
454
459
case 'invalid_type' : {
455
- message += buildTypeMismatchMessage ( currentError . received , currentError . expected , currentError . path . join ( '.' ) ) ;
460
+ message += buildTypeMismatchMessage ( currentError . message , currentError . expected , currentError . path . join ( '.' ) ) ;
456
461
break ;
457
462
}
458
463
case 'too_big' : {
0 commit comments