@@ -20,20 +20,23 @@ import {
2020import { oneOf , schemaForType } from 'packages/core/src/utils/ZodUtils' ;
2121import { z } from 'zod' ;
2222
23+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
2324function numberValidator ( action : string , name : string , description : string ) {
2425 return z . number ( {
2526 required_error : `The ${ action } action requires a specified ${ description } with the '${ name } ' field.` ,
2627 invalid_type_error : `The ${ action } action requires the value of the '${ name } ' fields to be a number.` ,
2728 } ) ;
2829}
2930
31+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
3032function stringValidator ( action : string , name : string , description : string ) {
3133 return z . string ( {
3234 required_error : `The ${ action } action requires a specified ${ description } with the '${ name } ' field.` ,
3335 invalid_type_error : `The ${ action } action requires the value of the '${ name } ' fields to be a string.` ,
3436 } ) ;
3537}
3638
39+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
3740function booleanValidator ( action : string , name : string , description : string ) {
3841 return z . boolean ( {
3942 required_error : `The ${ action } action requires a specified ${ description } with the '${ name } ' field.` ,
@@ -82,69 +85,76 @@ export const V_SleepButtonAction = schemaForType<SleepButtonAction>()(
8285export const V_TemplaterCreateNoteButtonAction = schemaForType < TemplaterCreateNoteButtonAction > ( ) (
8386 z . object ( {
8487 type : z . literal ( ButtonActionType . TEMPLATER_CREATE_NOTE ) ,
85- templateFile : z . string ( ) ,
86- folderPath : z . string ( ) . optional ( ) ,
87- fileName : z . string ( ) . optional ( ) ,
88- openNote : z . boolean ( ) . optional ( ) ,
88+ templateFile : stringValidator ( 'templaterCreateNote' , 'templateFile' , 'template file path' ) ,
89+ folderPath : stringValidator ( 'templaterCreateNote' , 'folderPath' , 'folder path' ) . optional ( ) ,
90+ fileName : stringValidator ( 'templaterCreateNote' , 'fileName' , 'file name' ) . optional ( ) ,
91+ openNote : booleanValidator ( 'templaterCreateNote' , 'openNote' , 'value for whether to open the note' ) . optional ( ) ,
8992 } ) ,
9093) ;
9194export const V_UpdateMetadataButtonAction = schemaForType < UpdateMetadataButtonAction > ( ) (
9295 z . object ( {
9396 type : z . literal ( ButtonActionType . UPDATE_METADATA ) ,
94- bindTarget : z . string ( ) ,
95- evaluate : z . boolean ( ) ,
96- value : z . coerce . string ( ) ,
97+ bindTarget : stringValidator ( 'updateMetadata' , 'bindTarget' , 'bind target to the metadata to update' ) ,
98+ evaluate : booleanValidator (
99+ 'updateMetadata' ,
100+ 'evaluate' ,
101+ 'value for whether to evaluate the value as a JavaScript expression' ,
102+ ) ,
103+ value : z . coerce . string ( {
104+ required_error : `The updateMetadata action requires a specified value for the update with the 'value' field.` ,
105+ invalid_type_error : `The updateMetadata action requires the value of the 'value' fields to be a string.` ,
106+ } ) ,
97107 } ) ,
98108) ;
99109
100110export const V_CreateNoteButtonAction = schemaForType < CreateNoteButtonAction > ( ) (
101111 z . object ( {
102112 type : z . literal ( ButtonActionType . CREATE_NOTE ) ,
103- folderPath : z . string ( ) . optional ( ) ,
104- fileName : z . string ( ) ,
105- openNote : z . boolean ( ) . optional ( ) ,
113+ folderPath : stringValidator ( 'createNote' , 'folderPath' , 'folder path' ) . optional ( ) ,
114+ fileName : stringValidator ( 'createNote' , 'fileName' , 'file name' ) ,
115+ openNote : booleanValidator ( 'createNote' , 'openNote' , 'value for whether to open the note' ) . optional ( ) ,
106116 } ) ,
107117) ;
108118
109119export const V_ReplaceInNoteButtonAction = schemaForType < ReplaceInNoteButtonAction > ( ) (
110120 z . object ( {
111121 type : z . literal ( ButtonActionType . REPLACE_IN_NOTE ) ,
112- fromLine : z . number ( ) ,
113- toLine : z . number ( ) ,
114- replacement : z . string ( ) ,
115- templater : z . boolean ( ) . optional ( ) ,
122+ fromLine : numberValidator ( 'replaceInNote' , 'fromLine' , 'line to replace from' ) ,
123+ toLine : numberValidator ( 'replaceInNote' , 'toLine' , 'line to replace to' ) ,
124+ replacement : stringValidator ( 'replaceInNote' , 'replacement' , 'replacement string' ) ,
125+ templater : booleanValidator ( 'replaceInNote' , 'templater' , 'value for whether to use Templater' ) . optional ( ) ,
116126 } ) ,
117127) ;
118128
119129export const V_ReplaceSelfButtonAction = schemaForType < ReplaceSelfButtonAction > ( ) (
120130 z . object ( {
121131 type : z . literal ( ButtonActionType . REPLACE_SELF ) ,
122- replacement : z . string ( ) ,
123- templater : z . boolean ( ) . optional ( ) ,
132+ replacement : stringValidator ( 'replaceSelf' , 'replacement' , 'replacement string' ) ,
133+ templater : booleanValidator ( 'replaceSelf' , 'templater' , 'value for whether to use Templater' ) . optional ( ) ,
124134 } ) ,
125135) ;
126136
127137export const V_RegexpReplaceInNoteButtonAction = schemaForType < RegexpReplaceInNoteButtonAction > ( ) (
128138 z . object ( {
129139 type : z . literal ( ButtonActionType . REGEXP_REPLACE_IN_NOTE ) ,
130- regexp : z . string ( ) ,
131- replacement : z . string ( ) ,
140+ regexp : stringValidator ( 'regexpReplaceInNote' , 'regexp' , 'search regular expression' ) ,
141+ replacement : stringValidator ( 'regexpReplaceInNote' , 'replacement' , 'replacement string' ) ,
132142 } ) ,
133143) ;
134144
135145export const V_InsertIntoNoteButtonAction = schemaForType < InsertIntoNoteButtonAction > ( ) (
136146 z . object ( {
137147 type : z . literal ( ButtonActionType . INSERT_INTO_NOTE ) ,
138- line : z . number ( ) ,
139- value : z . string ( ) ,
140- templater : z . boolean ( ) . optional ( ) ,
148+ line : numberValidator ( 'insertIntoNote' , 'line' , 'line to insert at' ) ,
149+ value : stringValidator ( 'insertIntoNote' , 'value' , 'string to insert' ) ,
150+ templater : booleanValidator ( 'insertIntoNote' , 'templater' , 'value for whether to use Templater' ) . optional ( ) ,
141151 } ) ,
142152) ;
143153
144154export const V_InlineJsButtonAction = schemaForType < InlineJsButtonAction > ( ) (
145155 z . object ( {
146156 type : z . literal ( ButtonActionType . INLINE_JS ) ,
147- code : z . string ( ) ,
157+ code : stringValidator ( 'inlineJS' , 'code' , 'code string to run' ) ,
148158 } ) ,
149159) ;
150160
0 commit comments