@@ -21,33 +21,54 @@ import { oneOf, schemaForType } from 'packages/core/src/utils/ZodUtils';
21
21
import { z } from 'zod' ;
22
22
23
23
// 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 ) {
25
25
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
+ } ,
28
33
} ) ;
29
34
}
30
35
31
36
// 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 ) {
33
38
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
+ } ,
35
46
} ) ;
36
47
}
37
48
38
49
// 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 ) {
40
51
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
+ } ,
43
59
} ) ;
44
60
}
45
61
46
62
// 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 ) {
48
64
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
+ } ,
51
72
} ) ;
52
73
}
53
74
@@ -62,7 +83,7 @@ export const V_JSButtonAction = schemaForType<JSButtonAction>()(
62
83
z . object ( {
63
84
type : z . literal ( ButtonActionType . JS ) ,
64
85
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 ( ) ,
66
87
} ) ,
67
88
) ;
68
89
@@ -120,10 +141,7 @@ export const V_UpdateMetadataButtonAction = schemaForType<UpdateMetadataButtonAc
120
141
'evaluate' ,
121
142
'value for whether to evaluate the value as a JavaScript expression' ,
122
143
) ,
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' ) ,
127
145
} ) ,
128
146
) ;
129
147
@@ -185,7 +203,7 @@ export const V_InlineJSButtonAction = schemaForType<InlineJSButtonAction>()(
185
203
z . object ( {
186
204
type : z . literal ( ButtonActionType . INLINE_JS ) ,
187
205
code : actionFieldString ( 'inlineJS' , 'code' , 'code string to run' ) ,
188
- args : z . record ( z . unknown ( ) ) . optional ( ) ,
206
+ args : z . record ( z . string ( ) , z . unknown ( ) ) . optional ( ) ,
189
207
} ) ,
190
208
) ;
191
209
@@ -225,5 +243,5 @@ export const V_ButtonConfig = schemaForType<ButtonConfig>()(
225
243
action : V_ButtonAction . optional ( ) ,
226
244
actions : V_ButtonAction . array ( ) . optional ( ) ,
227
245
} )
228
- . superRefine ( oneOf ( 'action' , 'actions' ) ) ,
246
+ . check ( oneOf ( 'action' , 'actions' ) ) ,
229
247
) ;
0 commit comments