@@ -21,13 +21,18 @@ export type MessageAtLocation = FieldMessage & { location: string }
2121/**
2222 * Validators can return their findings on various detail levels
2323 */
24- export type ValidatorOutput = MessageMaybeAtLocation | MarkdownCode | undefined
24+ export type SimpleValidatorOutput = MessageMaybeAtLocation | MarkdownCode | undefined
25+
26+ /**
27+ * Validators can return their findings on various detail levels
28+ */
29+ export type RecursiveValidatorOutput < DataType > = ValidatorFunction < DataType >
2530
2631/**
2732 * Flush out validator messages with all details
2833 */
2934export const wrapValidatorOutput = (
30- output : ValidatorOutput ,
35+ output : SimpleValidatorOutput ,
3136 defaultLocation : string ,
3237 defaultLevel : FieldMessageType
3338) : MessageAtLocation | undefined => {
@@ -95,22 +100,56 @@ export const getDateMessage = (template: DateMessageTemplate, date: Date): strin
95100 * It should return undefined if everything is fine,
96101 * or return the found issues.
97102 */
98- export type SyncValidatorFunction < DataType > = (
103+ export type SyncSimpleValidatorFunction < DataType > = (
104+ value : DataType ,
105+ controls : ValidatorControls ,
106+ reason : string
107+ ) => SingleOrArray < SimpleValidatorOutput >
108+
109+ /**
110+ * An asynchronous validator function
111+ *
112+ * It should return undefined if everything is fine,
113+ * or return the found issues.
114+ */
115+ export type AsyncSimpleValidatorFunction < DataType > = (
116+ value : DataType ,
117+ controls : ValidatorControls ,
118+ reason : string
119+ ) => Promise < SingleOrArray < SimpleValidatorOutput > >
120+
121+ export type SimpleValidatorFunction < DataType > =
122+ | SyncSimpleValidatorFunction < DataType >
123+ | AsyncSimpleValidatorFunction < DataType >
124+
125+ /**
126+ * A synchronous validator function
127+ *
128+ * It should return undefined if everything is fine,
129+ * or return the found issues.
130+ */
131+ export type SyncRecursiveValidatorFunction < DataType > = (
99132 value : DataType ,
100133 controls : ValidatorControls ,
101134 reason : string
102- ) => SingleOrArray < ValidatorOutput >
135+ ) => SingleOrArray < RecursiveValidatorOutput < DataType > >
103136
104137/**
105138 * An asynchronous validator function
106139 *
107140 * It should return undefined if everything is fine,
108141 * or return the found issues.
109142 */
110- export type AsyncValidatorFunction < DataType > = (
143+ export type AsyncRecursiveValidatorFunction < DataType > = (
111144 value : DataType ,
112145 controls : ValidatorControls ,
113146 reason : string
114- ) => Promise < SingleOrArray < ValidatorOutput > >
147+ ) => Promise < SingleOrArray < RecursiveValidatorOutput < DataType > > >
148+
149+ export type RecursiveValidatorFunction < DataType > =
150+ | SyncRecursiveValidatorFunction < DataType >
151+ | AsyncRecursiveValidatorFunction < DataType >
115152
116- export type ValidatorFunction < DataType > = SyncValidatorFunction < DataType > | AsyncValidatorFunction < DataType >
153+ export type ValidatorFunction < DataType > =
154+ | SimpleValidatorFunction < DataType >
155+ | RecursiveValidatorFunction < DataType >
0 commit comments