@@ -21,33 +21,54 @@ import { oneOf, schemaForType } from 'packages/core/src/utils/ZodUtils';
2121import { z } from 'zod' ;
2222
2323// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
24- function actionFieldNumber ( action : string , name : string , description : string ) {
24+ function actionFieldNumber ( action : string , field : string , description : string ) {
2525 return z . number ( {
26- required_error : `The ${ action } action requires a specified ${ description } with the '${ name } ' field.` ,
27- invalid_type_error : `The ${ action } action requires the value of the '${ name } ' fields to be a number.` ,
26+ error : issue => {
27+ if ( issue . input === undefined ) {
28+ return `The ${ action } action requires a specified ${ description } with the '${ field } ' field.` ;
29+ } else {
30+ return `The ${ action } action requires the value of the '${ field } ' fields to be a number, but got ${ typeof issue . input } .` ;
31+ }
32+ } ,
2833 } ) ;
2934}
3035
3136// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
32- function actionFieldString ( action : string , name : string , description : string ) {
37+ function actionFieldString ( action : string , field : string , description : string ) {
3338 return z . string ( {
34- required_error : `The ${ action } action requires a specified ${ description } with the '${ name } ' field.` ,
39+ error : issue => {
40+ if ( issue . input === undefined ) {
41+ return `The ${ action } action requires a specified ${ description } with the '${ field } ' field.` ;
42+ } else {
43+ return `The ${ action } action requires the value of the '${ field } ' fields to be a string, but got ${ typeof issue . input } .` ;
44+ }
45+ } ,
3546 } ) ;
3647}
3748
3849// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
39- function actionFieldCoerceString ( action : string , name : string , description : string ) {
50+ function actionFieldCoerceString ( action : string , field : string , description : string ) {
4051 return z . coerce . string ( {
41- required_error : `The ${ action } action requires a specified ${ description } with the '${ name } ' field.` ,
42- invalid_type_error : `The ${ action } action requires the value of the '${ name } ' fields to be a string.` ,
52+ error : issue => {
53+ if ( issue . input === undefined ) {
54+ return `The ${ action } action requires a specified ${ description } with the '${ field } ' field.` ;
55+ } else {
56+ return `The ${ action } action requires the value of the '${ field } ' fields to be a string, but got ${ typeof issue . input } .` ;
57+ }
58+ } ,
4359 } ) ;
4460}
4561
4662// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
47- function actionFieldBool ( action : string , name : string , description : string ) {
63+ function actionFieldBool ( action : string , field : string , description : string ) {
4864 return z . boolean ( {
49- required_error : `The ${ action } action requires a specified ${ description } with the '${ name } ' field.` ,
50- invalid_type_error : `The ${ action } action requires the value of the '${ name } ' fields to be a boolean.` ,
65+ error : issue => {
66+ if ( issue . input === undefined ) {
67+ return `The ${ action } action requires a specified ${ description } with the '${ field } ' field.` ;
68+ } else {
69+ return `The ${ action } action requires the value of the '${ field } ' fields to be a boolean, but got ${ typeof issue . input } .` ;
70+ }
71+ } ,
5172 } ) ;
5273}
5374
@@ -62,7 +83,7 @@ export const V_JSButtonAction = schemaForType<JSButtonAction>()(
6283 z . object ( {
6384 type : z . literal ( ButtonActionType . JS ) ,
6485 file : actionFieldString ( 'js' , 'file' , 'file path to the file to run' ) ,
65- args : z . record ( z . unknown ( ) ) . optional ( ) ,
86+ args : z . record ( z . string ( ) , z . unknown ( ) ) . optional ( ) ,
6687 } ) ,
6788) ;
6889
@@ -120,10 +141,7 @@ export const V_UpdateMetadataButtonAction = schemaForType<UpdateMetadataButtonAc
120141 'evaluate' ,
121142 'value for whether to evaluate the value as a JavaScript expression' ,
122143 ) ,
123- value : z . coerce . string ( {
124- required_error : `The updateMetadata action requires a specified value for the update with the 'value' field.` ,
125- invalid_type_error : `The updateMetadata action requires the value of the 'value' fields to be a string.` ,
126- } ) ,
144+ value : actionFieldCoerceString ( 'updateMetadata' , 'value for the update' , 'value' ) ,
127145 } ) ,
128146) ;
129147
@@ -185,7 +203,7 @@ export const V_InlineJSButtonAction = schemaForType<InlineJSButtonAction>()(
185203 z . object ( {
186204 type : z . literal ( ButtonActionType . INLINE_JS ) ,
187205 code : actionFieldString ( 'inlineJS' , 'code' , 'code string to run' ) ,
188- args : z . record ( z . unknown ( ) ) . optional ( ) ,
206+ args : z . record ( z . string ( ) , z . unknown ( ) ) . optional ( ) ,
189207 } ) ,
190208) ;
191209
@@ -225,5 +243,5 @@ export const V_ButtonConfig = schemaForType<ButtonConfig>()(
225243 action : V_ButtonAction . optional ( ) ,
226244 actions : V_ButtonAction . array ( ) . optional ( ) ,
227245 } )
228- . superRefine ( oneOf ( 'action' , 'actions' ) ) ,
246+ . check ( oneOf ( 'action' , 'actions' ) ) ,
229247) ;
0 commit comments