@inploi/flows 0.0.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-VKMPK5WA.mjs +2 -0
- package/dist/chunk-VKMPK5WA.mjs.map +1 -0
- package/dist/interpreter.d.mts +5 -7
- package/dist/interpreter.mjs +1 -1
- package/dist/interpreter.mjs.map +1 -1
- package/dist/linked-list.mjs +1 -1
- package/dist/result-3e1b4efe.d.ts +1742 -0
- package/dist/utils.d.mts +11 -30
- package/dist/utils.mjs +1 -1
- package/package.json +12 -9
- package/dist/chunk-3QWHH45C.mjs +0 -2
- package/dist/chunk-3QWHH45C.mjs.map +0 -1
- package/dist/result-6033e9fc.d.ts +0 -749
|
@@ -0,0 +1,1742 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fallback type.
|
|
3
|
+
*/
|
|
4
|
+
type Fallback<TSchema extends BaseSchema<unknown, unknown, BaseIssue<unknown>>> = MaybeReadonly<InferOutput<TSchema>> | ((dataset?: OutputDataset<InferOutput<TSchema>, InferIssue<TSchema>>, config?: Config<InferIssue<TSchema>>) => MaybeReadonly<InferOutput<TSchema>>);
|
|
5
|
+
/**
|
|
6
|
+
* Schema with fallback type.
|
|
7
|
+
*/
|
|
8
|
+
type SchemaWithFallback<TSchema extends BaseSchema<unknown, unknown, BaseIssue<unknown>>, TFallback extends Fallback<TSchema>> = TSchema & {
|
|
9
|
+
/**
|
|
10
|
+
* The fallback value.
|
|
11
|
+
*/
|
|
12
|
+
readonly fallback: TFallback;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Fallback async type.
|
|
17
|
+
*/
|
|
18
|
+
type FallbackAsync<TSchema extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>> = MaybeReadonly<InferOutput<TSchema>> | ((dataset?: OutputDataset<InferOutput<TSchema>, InferIssue<TSchema>>, config?: Config<InferIssue<TSchema>>) => MaybePromise<MaybeReadonly<InferOutput<TSchema>>>);
|
|
19
|
+
/**
|
|
20
|
+
* Schema with fallback async type.
|
|
21
|
+
*/
|
|
22
|
+
type SchemaWithFallbackAsync<TSchema extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, TFallback extends FallbackAsync<TSchema>> = Omit<TSchema, 'async' | '~standard' | '~run'> & {
|
|
23
|
+
/**
|
|
24
|
+
* The fallback value.
|
|
25
|
+
*/
|
|
26
|
+
readonly fallback: TFallback;
|
|
27
|
+
/**
|
|
28
|
+
* Whether it's async.
|
|
29
|
+
*/
|
|
30
|
+
readonly async: true;
|
|
31
|
+
/**
|
|
32
|
+
* The Standard Schema properties.
|
|
33
|
+
*
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
readonly '~standard': StandardProps<InferInput<TSchema>, InferOutput<TSchema>>;
|
|
37
|
+
/**
|
|
38
|
+
* Parses unknown input values.
|
|
39
|
+
*
|
|
40
|
+
* @param dataset The input dataset.
|
|
41
|
+
* @param config The configuration.
|
|
42
|
+
*
|
|
43
|
+
* @returns The output dataset.
|
|
44
|
+
*
|
|
45
|
+
* @internal
|
|
46
|
+
*/
|
|
47
|
+
readonly '~run': (dataset: UnknownDataset, config: Config<BaseIssue<unknown>>) => Promise<OutputDataset<InferOutput<TSchema>, InferIssue<TSchema>>>;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Schema with pipe type.
|
|
52
|
+
*/
|
|
53
|
+
type SchemaWithPipe<TPipe extends readonly [
|
|
54
|
+
BaseSchema<unknown, unknown, BaseIssue<unknown>>,
|
|
55
|
+
...PipeItem<any, unknown, BaseIssue<unknown>>[]
|
|
56
|
+
]> = Omit<FirstTupleItem<TPipe>, 'pipe' | '~standard' | '~run' | '~types'> & {
|
|
57
|
+
/**
|
|
58
|
+
* The pipe items.
|
|
59
|
+
*/
|
|
60
|
+
readonly pipe: TPipe;
|
|
61
|
+
/**
|
|
62
|
+
* The Standard Schema properties.
|
|
63
|
+
*
|
|
64
|
+
* @internal
|
|
65
|
+
*/
|
|
66
|
+
readonly '~standard': StandardProps<InferInput<FirstTupleItem<TPipe>>, InferOutput<LastTupleItem<TPipe>>>;
|
|
67
|
+
/**
|
|
68
|
+
* Parses unknown input values.
|
|
69
|
+
*
|
|
70
|
+
* @param dataset The input dataset.
|
|
71
|
+
* @param config The configuration.
|
|
72
|
+
*
|
|
73
|
+
* @returns The output dataset.
|
|
74
|
+
*
|
|
75
|
+
* @internal
|
|
76
|
+
*/
|
|
77
|
+
readonly '~run': (dataset: UnknownDataset, config: Config<BaseIssue<unknown>>) => OutputDataset<InferOutput<LastTupleItem<TPipe>>, InferIssue<TPipe[number]>>;
|
|
78
|
+
/**
|
|
79
|
+
* The input, output and issue type.
|
|
80
|
+
*
|
|
81
|
+
* @internal
|
|
82
|
+
*/
|
|
83
|
+
readonly '~types'?: {
|
|
84
|
+
readonly input: InferInput<FirstTupleItem<TPipe>>;
|
|
85
|
+
readonly output: InferOutput<LastTupleItem<TPipe>>;
|
|
86
|
+
readonly issue: InferIssue<TPipe[number]>;
|
|
87
|
+
} | undefined;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Schema with pipe async type.
|
|
92
|
+
*/
|
|
93
|
+
type SchemaWithPipeAsync<TPipe extends readonly [
|
|
94
|
+
(BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>),
|
|
95
|
+
...(PipeItem<any, unknown, BaseIssue<unknown>> | PipeItemAsync<any, unknown, BaseIssue<unknown>>)[]
|
|
96
|
+
]> = Omit<FirstTupleItem<TPipe>, 'async' | 'pipe' | '~standard' | '~run' | '~types'> & {
|
|
97
|
+
/**
|
|
98
|
+
* The pipe items.
|
|
99
|
+
*/
|
|
100
|
+
readonly pipe: TPipe;
|
|
101
|
+
/**
|
|
102
|
+
* Whether it's async.
|
|
103
|
+
*/
|
|
104
|
+
readonly async: true;
|
|
105
|
+
/**
|
|
106
|
+
* The Standard Schema properties.
|
|
107
|
+
*
|
|
108
|
+
* @internal
|
|
109
|
+
*/
|
|
110
|
+
readonly '~standard': StandardProps<InferInput<FirstTupleItem<TPipe>>, InferOutput<LastTupleItem<TPipe>>>;
|
|
111
|
+
/**
|
|
112
|
+
* Parses unknown input values.
|
|
113
|
+
*
|
|
114
|
+
* @param dataset The input dataset.
|
|
115
|
+
* @param config The configuration.
|
|
116
|
+
*
|
|
117
|
+
* @returns The output dataset.
|
|
118
|
+
*
|
|
119
|
+
* @internal
|
|
120
|
+
*/
|
|
121
|
+
readonly '~run': (dataset: UnknownDataset, config: Config<BaseIssue<unknown>>) => Promise<OutputDataset<InferOutput<LastTupleItem<TPipe>>, InferIssue<TPipe[number]>>>;
|
|
122
|
+
/**
|
|
123
|
+
* The input, output and issue type.
|
|
124
|
+
*
|
|
125
|
+
* @internal
|
|
126
|
+
*/
|
|
127
|
+
readonly '~types'?: {
|
|
128
|
+
readonly input: InferInput<FirstTupleItem<TPipe>>;
|
|
129
|
+
readonly output: InferOutput<LastTupleItem<TPipe>>;
|
|
130
|
+
readonly issue: InferIssue<TPipe[number]>;
|
|
131
|
+
} | undefined;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Base metadata interface.
|
|
136
|
+
*/
|
|
137
|
+
interface BaseMetadata<TInput> {
|
|
138
|
+
/**
|
|
139
|
+
* The object kind.
|
|
140
|
+
*/
|
|
141
|
+
readonly kind: 'metadata';
|
|
142
|
+
/**
|
|
143
|
+
* The metadata type.
|
|
144
|
+
*/
|
|
145
|
+
readonly type: string;
|
|
146
|
+
/**
|
|
147
|
+
* The metadata reference.
|
|
148
|
+
*/
|
|
149
|
+
readonly reference: (...args: any[]) => BaseMetadata<any>;
|
|
150
|
+
/**
|
|
151
|
+
* The input, output and issue type.
|
|
152
|
+
*
|
|
153
|
+
* @internal
|
|
154
|
+
*/
|
|
155
|
+
readonly '~types'?: {
|
|
156
|
+
readonly input: TInput;
|
|
157
|
+
readonly output: TInput;
|
|
158
|
+
readonly issue: never;
|
|
159
|
+
} | undefined;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Unknown dataset interface.
|
|
164
|
+
*/
|
|
165
|
+
interface UnknownDataset {
|
|
166
|
+
/**
|
|
167
|
+
* Whether is's typed.
|
|
168
|
+
*/
|
|
169
|
+
typed?: false;
|
|
170
|
+
/**
|
|
171
|
+
* The dataset value.
|
|
172
|
+
*/
|
|
173
|
+
value: unknown;
|
|
174
|
+
/**
|
|
175
|
+
* The dataset issues.
|
|
176
|
+
*/
|
|
177
|
+
issues?: undefined;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Success dataset interface.
|
|
181
|
+
*/
|
|
182
|
+
interface SuccessDataset<TValue> {
|
|
183
|
+
/**
|
|
184
|
+
* Whether is's typed.
|
|
185
|
+
*/
|
|
186
|
+
typed: true;
|
|
187
|
+
/**
|
|
188
|
+
* The dataset value.
|
|
189
|
+
*/
|
|
190
|
+
value: TValue;
|
|
191
|
+
/**
|
|
192
|
+
* The dataset issues.
|
|
193
|
+
*/
|
|
194
|
+
issues?: undefined;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Partial dataset interface.
|
|
198
|
+
*/
|
|
199
|
+
interface PartialDataset<TValue, TIssue extends BaseIssue<unknown>> {
|
|
200
|
+
/**
|
|
201
|
+
* Whether is's typed.
|
|
202
|
+
*/
|
|
203
|
+
typed: true;
|
|
204
|
+
/**
|
|
205
|
+
* The dataset value.
|
|
206
|
+
*/
|
|
207
|
+
value: TValue;
|
|
208
|
+
/**
|
|
209
|
+
* The dataset issues.
|
|
210
|
+
*/
|
|
211
|
+
issues: [TIssue, ...TIssue[]];
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Failure dataset interface.
|
|
215
|
+
*/
|
|
216
|
+
interface FailureDataset<TIssue extends BaseIssue<unknown>> {
|
|
217
|
+
/**
|
|
218
|
+
* Whether is's typed.
|
|
219
|
+
*/
|
|
220
|
+
typed: false;
|
|
221
|
+
/**
|
|
222
|
+
* The dataset value.
|
|
223
|
+
*/
|
|
224
|
+
value: unknown;
|
|
225
|
+
/**
|
|
226
|
+
* The dataset issues.
|
|
227
|
+
*/
|
|
228
|
+
issues: [TIssue, ...TIssue[]];
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Output dataset type.
|
|
232
|
+
*/
|
|
233
|
+
type OutputDataset<TValue, TIssue extends BaseIssue<unknown>> = SuccessDataset<TValue> | PartialDataset<TValue, TIssue> | FailureDataset<TIssue>;
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* The Standard Schema properties interface.
|
|
237
|
+
*/
|
|
238
|
+
interface StandardProps<TInput, TOutput> {
|
|
239
|
+
/**
|
|
240
|
+
* The version number of the standard.
|
|
241
|
+
*/
|
|
242
|
+
readonly version: 1;
|
|
243
|
+
/**
|
|
244
|
+
* The vendor name of the schema library.
|
|
245
|
+
*/
|
|
246
|
+
readonly vendor: 'valibot';
|
|
247
|
+
/**
|
|
248
|
+
* Validates unknown input values.
|
|
249
|
+
*/
|
|
250
|
+
readonly validate: (value: unknown) => StandardResult<TOutput> | Promise<StandardResult<TOutput>>;
|
|
251
|
+
/**
|
|
252
|
+
* Inferred types associated with the schema.
|
|
253
|
+
*/
|
|
254
|
+
readonly types?: StandardTypes<TInput, TOutput> | undefined;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* The result interface of the validate function.
|
|
258
|
+
*/
|
|
259
|
+
type StandardResult<TOutput> = StandardSuccessResult<TOutput> | StandardFailureResult;
|
|
260
|
+
/**
|
|
261
|
+
* The result interface if validation succeeds.
|
|
262
|
+
*/
|
|
263
|
+
interface StandardSuccessResult<TOutput> {
|
|
264
|
+
/**
|
|
265
|
+
* The typed output value.
|
|
266
|
+
*/
|
|
267
|
+
readonly value: TOutput;
|
|
268
|
+
/**
|
|
269
|
+
* The non-existent issues.
|
|
270
|
+
*/
|
|
271
|
+
readonly issues?: undefined;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* The result interface if validation fails.
|
|
275
|
+
*/
|
|
276
|
+
interface StandardFailureResult {
|
|
277
|
+
/**
|
|
278
|
+
* The issues of failed validation.
|
|
279
|
+
*/
|
|
280
|
+
readonly issues: readonly StandardIssue[];
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* The issue interface of the failure output.
|
|
284
|
+
*/
|
|
285
|
+
interface StandardIssue {
|
|
286
|
+
/**
|
|
287
|
+
* The error message of the issue.
|
|
288
|
+
*/
|
|
289
|
+
readonly message: string;
|
|
290
|
+
/**
|
|
291
|
+
* The path of the issue, if any.
|
|
292
|
+
*/
|
|
293
|
+
readonly path?: readonly (PropertyKey | StandardPathItem)[] | undefined;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* The path item interface of the issue.
|
|
297
|
+
*/
|
|
298
|
+
interface StandardPathItem {
|
|
299
|
+
/**
|
|
300
|
+
* The key of the path item.
|
|
301
|
+
*/
|
|
302
|
+
readonly key: PropertyKey;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* The Standard Schema types interface.
|
|
306
|
+
*/
|
|
307
|
+
interface StandardTypes<TInput, TOutput> {
|
|
308
|
+
/**
|
|
309
|
+
* The input type of the schema.
|
|
310
|
+
*/
|
|
311
|
+
readonly input: TInput;
|
|
312
|
+
/**
|
|
313
|
+
* The output type of the schema.
|
|
314
|
+
*/
|
|
315
|
+
readonly output: TOutput;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Base schema interface.
|
|
320
|
+
*/
|
|
321
|
+
interface BaseSchema<TInput, TOutput, TIssue extends BaseIssue<unknown>> {
|
|
322
|
+
/**
|
|
323
|
+
* The object kind.
|
|
324
|
+
*/
|
|
325
|
+
readonly kind: 'schema';
|
|
326
|
+
/**
|
|
327
|
+
* The schema type.
|
|
328
|
+
*/
|
|
329
|
+
readonly type: string;
|
|
330
|
+
/**
|
|
331
|
+
* The schema reference.
|
|
332
|
+
*/
|
|
333
|
+
readonly reference: (...args: any[]) => BaseSchema<unknown, unknown, BaseIssue<unknown>>;
|
|
334
|
+
/**
|
|
335
|
+
* The expected property.
|
|
336
|
+
*/
|
|
337
|
+
readonly expects: string;
|
|
338
|
+
/**
|
|
339
|
+
* Whether it's async.
|
|
340
|
+
*/
|
|
341
|
+
readonly async: false;
|
|
342
|
+
/**
|
|
343
|
+
* The Standard Schema properties.
|
|
344
|
+
*
|
|
345
|
+
* @internal
|
|
346
|
+
*/
|
|
347
|
+
readonly '~standard': StandardProps<TInput, TOutput>;
|
|
348
|
+
/**
|
|
349
|
+
* Parses unknown input values.
|
|
350
|
+
*
|
|
351
|
+
* @param dataset The input dataset.
|
|
352
|
+
* @param config The configuration.
|
|
353
|
+
*
|
|
354
|
+
* @returns The output dataset.
|
|
355
|
+
*
|
|
356
|
+
* @internal
|
|
357
|
+
*/
|
|
358
|
+
readonly '~run': (dataset: UnknownDataset, config: Config<BaseIssue<unknown>>) => OutputDataset<TOutput, TIssue>;
|
|
359
|
+
/**
|
|
360
|
+
* The input, output and issue type.
|
|
361
|
+
*
|
|
362
|
+
* @internal
|
|
363
|
+
*/
|
|
364
|
+
readonly '~types'?: {
|
|
365
|
+
readonly input: TInput;
|
|
366
|
+
readonly output: TOutput;
|
|
367
|
+
readonly issue: TIssue;
|
|
368
|
+
} | undefined;
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Base schema async interface.
|
|
372
|
+
*/
|
|
373
|
+
interface BaseSchemaAsync<TInput, TOutput, TIssue extends BaseIssue<unknown>> extends Omit<BaseSchema<TInput, TOutput, TIssue>, 'reference' | 'async' | '~run'> {
|
|
374
|
+
/**
|
|
375
|
+
* The schema reference.
|
|
376
|
+
*/
|
|
377
|
+
readonly reference: (...args: any[]) => BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>;
|
|
378
|
+
/**
|
|
379
|
+
* Whether it's async.
|
|
380
|
+
*/
|
|
381
|
+
readonly async: true;
|
|
382
|
+
/**
|
|
383
|
+
* Parses unknown input values.
|
|
384
|
+
*
|
|
385
|
+
* @param dataset The input dataset.
|
|
386
|
+
* @param config The configuration.
|
|
387
|
+
*
|
|
388
|
+
* @returns The output dataset.
|
|
389
|
+
*
|
|
390
|
+
* @internal
|
|
391
|
+
*/
|
|
392
|
+
readonly '~run': (dataset: UnknownDataset, config: Config<BaseIssue<unknown>>) => Promise<OutputDataset<TOutput, TIssue>>;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* Base transformation interface.
|
|
397
|
+
*/
|
|
398
|
+
interface BaseTransformation<TInput, TOutput, TIssue extends BaseIssue<unknown>> {
|
|
399
|
+
/**
|
|
400
|
+
* The object kind.
|
|
401
|
+
*/
|
|
402
|
+
readonly kind: 'transformation';
|
|
403
|
+
/**
|
|
404
|
+
* The transformation type.
|
|
405
|
+
*/
|
|
406
|
+
readonly type: string;
|
|
407
|
+
/**
|
|
408
|
+
* The transformation reference.
|
|
409
|
+
*/
|
|
410
|
+
readonly reference: (...args: any[]) => BaseTransformation<any, any, BaseIssue<unknown>>;
|
|
411
|
+
/**
|
|
412
|
+
* Whether it's async.
|
|
413
|
+
*/
|
|
414
|
+
readonly async: false;
|
|
415
|
+
/**
|
|
416
|
+
* Transforms known input values.
|
|
417
|
+
*
|
|
418
|
+
* @param dataset The input dataset.
|
|
419
|
+
* @param config The configuration.
|
|
420
|
+
*
|
|
421
|
+
* @returns The output dataset.
|
|
422
|
+
*
|
|
423
|
+
* @internal
|
|
424
|
+
*/
|
|
425
|
+
readonly '~run': (dataset: SuccessDataset<TInput>, config: Config<BaseIssue<unknown>>) => OutputDataset<TOutput, BaseIssue<unknown> | TIssue>;
|
|
426
|
+
/**
|
|
427
|
+
* The input, output and issue type.
|
|
428
|
+
*
|
|
429
|
+
* @internal
|
|
430
|
+
*/
|
|
431
|
+
readonly '~types'?: {
|
|
432
|
+
readonly input: TInput;
|
|
433
|
+
readonly output: TOutput;
|
|
434
|
+
readonly issue: TIssue;
|
|
435
|
+
} | undefined;
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* Base transformation async interface.
|
|
439
|
+
*/
|
|
440
|
+
interface BaseTransformationAsync<TInput, TOutput, TIssue extends BaseIssue<unknown>> extends Omit<BaseTransformation<TInput, TOutput, TIssue>, 'reference' | 'async' | '~run'> {
|
|
441
|
+
/**
|
|
442
|
+
* The transformation reference.
|
|
443
|
+
*/
|
|
444
|
+
readonly reference: (...args: any[]) => BaseTransformation<any, any, BaseIssue<unknown>> | BaseTransformationAsync<any, any, BaseIssue<unknown>>;
|
|
445
|
+
/**
|
|
446
|
+
* Whether it's async.
|
|
447
|
+
*/
|
|
448
|
+
readonly async: true;
|
|
449
|
+
/**
|
|
450
|
+
* Transforms known input values.
|
|
451
|
+
*
|
|
452
|
+
* @param dataset The input dataset.
|
|
453
|
+
* @param config The configuration.
|
|
454
|
+
*
|
|
455
|
+
* @returns The output dataset.
|
|
456
|
+
*
|
|
457
|
+
* @internal
|
|
458
|
+
*/
|
|
459
|
+
readonly '~run': (dataset: SuccessDataset<TInput>, config: Config<BaseIssue<unknown>>) => Promise<OutputDataset<TOutput, BaseIssue<unknown> | TIssue>>;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* Base validation interface.
|
|
464
|
+
*/
|
|
465
|
+
interface BaseValidation<TInput, TOutput, TIssue extends BaseIssue<unknown>> {
|
|
466
|
+
/**
|
|
467
|
+
* The object kind.
|
|
468
|
+
*/
|
|
469
|
+
readonly kind: 'validation';
|
|
470
|
+
/**
|
|
471
|
+
* The validation type.
|
|
472
|
+
*/
|
|
473
|
+
readonly type: string;
|
|
474
|
+
/**
|
|
475
|
+
* The validation reference.
|
|
476
|
+
*/
|
|
477
|
+
readonly reference: (...args: any[]) => BaseValidation<any, any, BaseIssue<unknown>>;
|
|
478
|
+
/**
|
|
479
|
+
* The expected property.
|
|
480
|
+
*/
|
|
481
|
+
readonly expects: string | null;
|
|
482
|
+
/**
|
|
483
|
+
* Whether it's async.
|
|
484
|
+
*/
|
|
485
|
+
readonly async: false;
|
|
486
|
+
/**
|
|
487
|
+
* Validates known input values.
|
|
488
|
+
*
|
|
489
|
+
* @param dataset The input dataset.
|
|
490
|
+
* @param config The configuration.
|
|
491
|
+
*
|
|
492
|
+
* @returns The output dataset.
|
|
493
|
+
*
|
|
494
|
+
* @internal
|
|
495
|
+
*/
|
|
496
|
+
readonly '~run': (dataset: OutputDataset<TInput, BaseIssue<unknown>>, config: Config<BaseIssue<unknown>>) => OutputDataset<TOutput, BaseIssue<unknown> | TIssue>;
|
|
497
|
+
/**
|
|
498
|
+
* The input, output and issue type.
|
|
499
|
+
*
|
|
500
|
+
* @internal
|
|
501
|
+
*/
|
|
502
|
+
readonly '~types'?: {
|
|
503
|
+
readonly input: TInput;
|
|
504
|
+
readonly output: TOutput;
|
|
505
|
+
readonly issue: TIssue;
|
|
506
|
+
} | undefined;
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Base validation async interface.
|
|
510
|
+
*/
|
|
511
|
+
interface BaseValidationAsync<TInput, TOutput, TIssue extends BaseIssue<unknown>> extends Omit<BaseValidation<TInput, TOutput, TIssue>, 'reference' | 'async' | '~run'> {
|
|
512
|
+
/**
|
|
513
|
+
* The validation reference.
|
|
514
|
+
*/
|
|
515
|
+
readonly reference: (...args: any[]) => BaseValidation<any, any, BaseIssue<unknown>> | BaseValidationAsync<any, any, BaseIssue<unknown>>;
|
|
516
|
+
/**
|
|
517
|
+
* Whether it's async.
|
|
518
|
+
*/
|
|
519
|
+
readonly async: true;
|
|
520
|
+
/**
|
|
521
|
+
* Validates known input values.
|
|
522
|
+
*
|
|
523
|
+
* @param dataset The input dataset.
|
|
524
|
+
* @param config The configuration.
|
|
525
|
+
*
|
|
526
|
+
* @returns The output dataset.
|
|
527
|
+
*
|
|
528
|
+
* @internal
|
|
529
|
+
*/
|
|
530
|
+
readonly '~run': (dataset: OutputDataset<TInput, BaseIssue<unknown>>, config: Config<BaseIssue<unknown>>) => Promise<OutputDataset<TOutput, BaseIssue<unknown> | TIssue>>;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
/**
|
|
534
|
+
* Infer input type.
|
|
535
|
+
*/
|
|
536
|
+
type InferInput<TItem extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>> | BaseValidation<any, unknown, BaseIssue<unknown>> | BaseValidationAsync<any, unknown, BaseIssue<unknown>> | BaseTransformation<any, unknown, BaseIssue<unknown>> | BaseTransformationAsync<any, unknown, BaseIssue<unknown>> | BaseMetadata<any>> = NonNullable<TItem['~types']>['input'];
|
|
537
|
+
/**
|
|
538
|
+
* Infer output type.
|
|
539
|
+
*/
|
|
540
|
+
type InferOutput<TItem extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>> | BaseValidation<any, unknown, BaseIssue<unknown>> | BaseValidationAsync<any, unknown, BaseIssue<unknown>> | BaseTransformation<any, unknown, BaseIssue<unknown>> | BaseTransformationAsync<any, unknown, BaseIssue<unknown>> | BaseMetadata<any>> = NonNullable<TItem['~types']>['output'];
|
|
541
|
+
/**
|
|
542
|
+
* Infer issue type.
|
|
543
|
+
*/
|
|
544
|
+
type InferIssue<TItem extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>> | BaseValidation<any, unknown, BaseIssue<unknown>> | BaseValidationAsync<any, unknown, BaseIssue<unknown>> | BaseTransformation<any, unknown, BaseIssue<unknown>> | BaseTransformationAsync<any, unknown, BaseIssue<unknown>> | BaseMetadata<any>> = NonNullable<TItem['~types']>['issue'];
|
|
545
|
+
/**
|
|
546
|
+
* Constructs a type that is maybe readonly.
|
|
547
|
+
*/
|
|
548
|
+
type MaybeReadonly<TValue> = TValue | Readonly<TValue>;
|
|
549
|
+
/**
|
|
550
|
+
* Constructs a type that is maybe a promise.
|
|
551
|
+
*/
|
|
552
|
+
type MaybePromise<TValue> = TValue | Promise<TValue>;
|
|
553
|
+
/**
|
|
554
|
+
* Prettifies a type for better readability.
|
|
555
|
+
*
|
|
556
|
+
* Hint: This type has no effect and is only used so that TypeScript displays
|
|
557
|
+
* the final type in the preview instead of the utility types used.
|
|
558
|
+
*/
|
|
559
|
+
type Prettify<TObject> = {
|
|
560
|
+
[TKey in keyof TObject]: TObject[TKey];
|
|
561
|
+
} & {};
|
|
562
|
+
/**
|
|
563
|
+
* Marks specific keys as optional.
|
|
564
|
+
*/
|
|
565
|
+
type MarkOptional<TObject, TKeys extends keyof TObject> = {
|
|
566
|
+
[TKey in keyof TObject]?: unknown;
|
|
567
|
+
} & Omit<TObject, TKeys> & Partial<Pick<TObject, TKeys>>;
|
|
568
|
+
/**
|
|
569
|
+
* Extracts first tuple item.
|
|
570
|
+
*/
|
|
571
|
+
type FirstTupleItem<TTuple extends readonly [unknown, ...unknown[]]> = TTuple[0];
|
|
572
|
+
/**
|
|
573
|
+
* Extracts last tuple item.
|
|
574
|
+
*/
|
|
575
|
+
type LastTupleItem<TTuple extends readonly [unknown, ...unknown[]]> = TTuple[TTuple extends readonly [unknown, ...infer TRest] ? TRest['length'] : never];
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* Error message type.
|
|
579
|
+
*/
|
|
580
|
+
type ErrorMessage<TIssue extends BaseIssue<unknown>> = ((issue: TIssue) => string) | string;
|
|
581
|
+
/**
|
|
582
|
+
* Default type.
|
|
583
|
+
*/
|
|
584
|
+
type Default<TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>>, TInput extends null | undefined> = MaybeReadonly<InferInput<TWrapped> | TInput> | ((dataset?: UnknownDataset, config?: Config<InferIssue<TWrapped>>) => MaybeReadonly<InferInput<TWrapped> | TInput>) | undefined;
|
|
585
|
+
/**
|
|
586
|
+
* Default async type.
|
|
587
|
+
*/
|
|
588
|
+
type DefaultAsync<TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, TInput extends null | undefined> = MaybeReadonly<InferInput<TWrapped> | TInput> | ((dataset?: UnknownDataset, config?: Config<InferIssue<TWrapped>>) => MaybePromise<MaybeReadonly<InferInput<TWrapped> | TInput>>) | undefined;
|
|
589
|
+
/**
|
|
590
|
+
* Default value type.
|
|
591
|
+
*/
|
|
592
|
+
type DefaultValue<TDefault extends Default<BaseSchema<unknown, unknown, BaseIssue<unknown>>, null | undefined> | DefaultAsync<BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, null | undefined>> = TDefault extends DefaultAsync<infer TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, infer TInput> ? TDefault extends (dataset?: UnknownDataset, config?: Config<InferIssue<TWrapped>>) => MaybePromise<InferInput<TWrapped> | TInput> ? Awaited<ReturnType<TDefault>> : TDefault : never;
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* Optional entry schema type.
|
|
596
|
+
*/
|
|
597
|
+
type OptionalEntrySchema = ExactOptionalSchema<BaseSchema<unknown, unknown, BaseIssue<unknown>>, unknown> | NullishSchema<BaseSchema<unknown, unknown, BaseIssue<unknown>>, unknown> | OptionalSchema<BaseSchema<unknown, unknown, BaseIssue<unknown>>, unknown>;
|
|
598
|
+
/**
|
|
599
|
+
* Optional entry schema async type.
|
|
600
|
+
*/
|
|
601
|
+
type OptionalEntrySchemaAsync = ExactOptionalSchemaAsync<BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, unknown> | NullishSchemaAsync<BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, unknown> | OptionalSchemaAsync<BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, unknown>;
|
|
602
|
+
/**
|
|
603
|
+
* Object entries interface.
|
|
604
|
+
*/
|
|
605
|
+
interface ObjectEntries {
|
|
606
|
+
[key: string]: BaseSchema<unknown, unknown, BaseIssue<unknown>> | SchemaWithFallback<BaseSchema<unknown, unknown, BaseIssue<unknown>>, unknown> | OptionalEntrySchema;
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* Object entries async interface.
|
|
610
|
+
*/
|
|
611
|
+
interface ObjectEntriesAsync {
|
|
612
|
+
[key: string]: BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>> | SchemaWithFallback<BaseSchema<unknown, unknown, BaseIssue<unknown>>, unknown> | SchemaWithFallbackAsync<BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, unknown> | OptionalEntrySchema | OptionalEntrySchemaAsync;
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* Infer entries input type.
|
|
616
|
+
*/
|
|
617
|
+
type InferEntriesInput<TEntries extends ObjectEntries | ObjectEntriesAsync> = {
|
|
618
|
+
-readonly [TKey in keyof TEntries]: InferInput<TEntries[TKey]>;
|
|
619
|
+
};
|
|
620
|
+
/**
|
|
621
|
+
* Infer entries output type.
|
|
622
|
+
*/
|
|
623
|
+
type InferEntriesOutput<TEntries extends ObjectEntries | ObjectEntriesAsync> = {
|
|
624
|
+
-readonly [TKey in keyof TEntries]: InferOutput<TEntries[TKey]>;
|
|
625
|
+
};
|
|
626
|
+
/**
|
|
627
|
+
* Optional input keys type.
|
|
628
|
+
*/
|
|
629
|
+
type OptionalInputKeys<TEntries extends ObjectEntries | ObjectEntriesAsync> = {
|
|
630
|
+
[TKey in keyof TEntries]: TEntries[TKey] extends OptionalEntrySchema | OptionalEntrySchemaAsync ? TKey : never;
|
|
631
|
+
}[keyof TEntries];
|
|
632
|
+
/**
|
|
633
|
+
* Optional output keys type.
|
|
634
|
+
*/
|
|
635
|
+
type OptionalOutputKeys<TEntries extends ObjectEntries | ObjectEntriesAsync> = {
|
|
636
|
+
[TKey in keyof TEntries]: TEntries[TKey] extends OptionalEntrySchema | OptionalEntrySchemaAsync ? undefined extends TEntries[TKey]['default'] ? TKey : never : never;
|
|
637
|
+
}[keyof TEntries];
|
|
638
|
+
/**
|
|
639
|
+
* Input with question marks type.
|
|
640
|
+
*/
|
|
641
|
+
type InputWithQuestionMarks<TEntries extends ObjectEntries | ObjectEntriesAsync, TObject extends InferEntriesInput<TEntries>> = MarkOptional<TObject, OptionalInputKeys<TEntries>>;
|
|
642
|
+
/**
|
|
643
|
+
* Output with question marks type.
|
|
644
|
+
*/
|
|
645
|
+
type OutputWithQuestionMarks<TEntries extends ObjectEntries | ObjectEntriesAsync, TObject extends InferEntriesOutput<TEntries>> = MarkOptional<TObject, OptionalOutputKeys<TEntries>>;
|
|
646
|
+
/**
|
|
647
|
+
* Readonly output keys type.
|
|
648
|
+
*/
|
|
649
|
+
type ReadonlyOutputKeys<TEntries extends ObjectEntries | ObjectEntriesAsync> = {
|
|
650
|
+
[TKey in keyof TEntries]: TEntries[TKey] extends SchemaWithPipe<infer TPipe> | SchemaWithPipeAsync<infer TPipe> ? ReadonlyAction<any> extends TPipe[number] ? TKey : never : never;
|
|
651
|
+
}[keyof TEntries];
|
|
652
|
+
/**
|
|
653
|
+
* Output with readonly type.
|
|
654
|
+
*/
|
|
655
|
+
type OutputWithReadonly<TEntries extends ObjectEntries | ObjectEntriesAsync, TObject extends OutputWithQuestionMarks<TEntries, InferEntriesOutput<TEntries>>> = Readonly<TObject> & Pick<TObject, Exclude<keyof TObject, ReadonlyOutputKeys<TEntries>>>;
|
|
656
|
+
/**
|
|
657
|
+
* Infer object input type.
|
|
658
|
+
*/
|
|
659
|
+
type InferObjectInput<TEntries extends ObjectEntries | ObjectEntriesAsync> = Prettify<InputWithQuestionMarks<TEntries, InferEntriesInput<TEntries>>>;
|
|
660
|
+
/**
|
|
661
|
+
* Infer object output type.
|
|
662
|
+
*/
|
|
663
|
+
type InferObjectOutput<TEntries extends ObjectEntries | ObjectEntriesAsync> = Prettify<OutputWithReadonly<TEntries, OutputWithQuestionMarks<TEntries, InferEntriesOutput<TEntries>>>>;
|
|
664
|
+
/**
|
|
665
|
+
* Infer object issue type.
|
|
666
|
+
*/
|
|
667
|
+
type InferObjectIssue<TEntries extends ObjectEntries | ObjectEntriesAsync> = InferIssue<TEntries[keyof TEntries]>;
|
|
668
|
+
|
|
669
|
+
/**
|
|
670
|
+
* Array path item interface.
|
|
671
|
+
*/
|
|
672
|
+
interface ArrayPathItem {
|
|
673
|
+
/**
|
|
674
|
+
* The path item type.
|
|
675
|
+
*/
|
|
676
|
+
readonly type: 'array';
|
|
677
|
+
/**
|
|
678
|
+
* The path item origin.
|
|
679
|
+
*/
|
|
680
|
+
readonly origin: 'value';
|
|
681
|
+
/**
|
|
682
|
+
* The path item input.
|
|
683
|
+
*/
|
|
684
|
+
readonly input: MaybeReadonly<unknown[]>;
|
|
685
|
+
/**
|
|
686
|
+
* The path item key.
|
|
687
|
+
*/
|
|
688
|
+
readonly key: number;
|
|
689
|
+
/**
|
|
690
|
+
* The path item value.
|
|
691
|
+
*/
|
|
692
|
+
readonly value: unknown;
|
|
693
|
+
}
|
|
694
|
+
/**
|
|
695
|
+
* Map path item interface.
|
|
696
|
+
*/
|
|
697
|
+
interface MapPathItem {
|
|
698
|
+
/**
|
|
699
|
+
* The path item type.
|
|
700
|
+
*/
|
|
701
|
+
readonly type: 'map';
|
|
702
|
+
/**
|
|
703
|
+
* The path item origin.
|
|
704
|
+
*/
|
|
705
|
+
readonly origin: 'key' | 'value';
|
|
706
|
+
/**
|
|
707
|
+
* The path item input.
|
|
708
|
+
*/
|
|
709
|
+
readonly input: Map<unknown, unknown>;
|
|
710
|
+
/**
|
|
711
|
+
* The path item key.
|
|
712
|
+
*/
|
|
713
|
+
readonly key: unknown;
|
|
714
|
+
/**
|
|
715
|
+
* The path item value.
|
|
716
|
+
*/
|
|
717
|
+
readonly value: unknown;
|
|
718
|
+
}
|
|
719
|
+
/**
|
|
720
|
+
* Object path item interface.
|
|
721
|
+
*/
|
|
722
|
+
interface ObjectPathItem {
|
|
723
|
+
/**
|
|
724
|
+
* The path item type.
|
|
725
|
+
*/
|
|
726
|
+
readonly type: 'object';
|
|
727
|
+
/**
|
|
728
|
+
* The path item origin.
|
|
729
|
+
*/
|
|
730
|
+
readonly origin: 'key' | 'value';
|
|
731
|
+
/**
|
|
732
|
+
* The path item input.
|
|
733
|
+
*/
|
|
734
|
+
readonly input: Record<string, unknown>;
|
|
735
|
+
/**
|
|
736
|
+
* The path item key.
|
|
737
|
+
*/
|
|
738
|
+
readonly key: string;
|
|
739
|
+
/**
|
|
740
|
+
* The path item value.
|
|
741
|
+
*/
|
|
742
|
+
readonly value: unknown;
|
|
743
|
+
}
|
|
744
|
+
/**
|
|
745
|
+
* Set path item interface.
|
|
746
|
+
*/
|
|
747
|
+
interface SetPathItem {
|
|
748
|
+
/**
|
|
749
|
+
* The path item type.
|
|
750
|
+
*/
|
|
751
|
+
readonly type: 'set';
|
|
752
|
+
/**
|
|
753
|
+
* The path item origin.
|
|
754
|
+
*/
|
|
755
|
+
readonly origin: 'value';
|
|
756
|
+
/**
|
|
757
|
+
* The path item input.
|
|
758
|
+
*/
|
|
759
|
+
readonly input: Set<unknown>;
|
|
760
|
+
/**
|
|
761
|
+
* The path item key.
|
|
762
|
+
*/
|
|
763
|
+
readonly key: null;
|
|
764
|
+
/**
|
|
765
|
+
* The path item key.
|
|
766
|
+
*/
|
|
767
|
+
readonly value: unknown;
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
* Unknown path item interface.
|
|
771
|
+
*/
|
|
772
|
+
interface UnknownPathItem {
|
|
773
|
+
/**
|
|
774
|
+
* The path item type.
|
|
775
|
+
*/
|
|
776
|
+
readonly type: 'unknown';
|
|
777
|
+
/**
|
|
778
|
+
* The path item origin.
|
|
779
|
+
*/
|
|
780
|
+
readonly origin: 'key' | 'value';
|
|
781
|
+
/**
|
|
782
|
+
* The path item input.
|
|
783
|
+
*/
|
|
784
|
+
readonly input: unknown;
|
|
785
|
+
/**
|
|
786
|
+
* The path item key.
|
|
787
|
+
*/
|
|
788
|
+
readonly key: unknown;
|
|
789
|
+
/**
|
|
790
|
+
* The path item value.
|
|
791
|
+
*/
|
|
792
|
+
readonly value: unknown;
|
|
793
|
+
}
|
|
794
|
+
/**
|
|
795
|
+
* Issue path item type.
|
|
796
|
+
*/
|
|
797
|
+
type IssuePathItem = ArrayPathItem | MapPathItem | ObjectPathItem | SetPathItem | UnknownPathItem;
|
|
798
|
+
/**
|
|
799
|
+
* Base issue interface.
|
|
800
|
+
*/
|
|
801
|
+
interface BaseIssue<TInput> extends Config<BaseIssue<TInput>> {
|
|
802
|
+
/**
|
|
803
|
+
* The issue kind.
|
|
804
|
+
*/
|
|
805
|
+
readonly kind: 'schema' | 'validation' | 'transformation';
|
|
806
|
+
/**
|
|
807
|
+
* The issue type.
|
|
808
|
+
*/
|
|
809
|
+
readonly type: string;
|
|
810
|
+
/**
|
|
811
|
+
* The raw input data.
|
|
812
|
+
*/
|
|
813
|
+
readonly input: TInput;
|
|
814
|
+
/**
|
|
815
|
+
* The expected property.
|
|
816
|
+
*/
|
|
817
|
+
readonly expected: string | null;
|
|
818
|
+
/**
|
|
819
|
+
* The received property.
|
|
820
|
+
*/
|
|
821
|
+
readonly received: string;
|
|
822
|
+
/**
|
|
823
|
+
* The error message.
|
|
824
|
+
*/
|
|
825
|
+
readonly message: string;
|
|
826
|
+
/**
|
|
827
|
+
* The input requirement.
|
|
828
|
+
*/
|
|
829
|
+
readonly requirement?: unknown | undefined;
|
|
830
|
+
/**
|
|
831
|
+
* The issue path.
|
|
832
|
+
*/
|
|
833
|
+
readonly path?: [IssuePathItem, ...IssuePathItem[]] | undefined;
|
|
834
|
+
/**
|
|
835
|
+
* The sub issues.
|
|
836
|
+
*/
|
|
837
|
+
readonly issues?: [BaseIssue<TInput>, ...BaseIssue<TInput>[]] | undefined;
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
/**
|
|
841
|
+
* Config interface.
|
|
842
|
+
*/
|
|
843
|
+
interface Config<TIssue extends BaseIssue<unknown>> {
|
|
844
|
+
/**
|
|
845
|
+
* The selected language.
|
|
846
|
+
*/
|
|
847
|
+
readonly lang?: string | undefined;
|
|
848
|
+
/**
|
|
849
|
+
* The error message.
|
|
850
|
+
*/
|
|
851
|
+
readonly message?: ErrorMessage<TIssue> | undefined;
|
|
852
|
+
/**
|
|
853
|
+
* Whether it should be aborted early.
|
|
854
|
+
*/
|
|
855
|
+
readonly abortEarly?: boolean | undefined;
|
|
856
|
+
/**
|
|
857
|
+
* Whether a pipe should be aborted early.
|
|
858
|
+
*/
|
|
859
|
+
readonly abortPipeEarly?: boolean | undefined;
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
/**
|
|
863
|
+
* Pipe action type.
|
|
864
|
+
*/
|
|
865
|
+
type PipeAction<TInput, TOutput, TIssue extends BaseIssue<unknown>> = BaseValidation<TInput, TOutput, TIssue> | BaseTransformation<TInput, TOutput, TIssue> | BaseMetadata<TInput>;
|
|
866
|
+
/**
|
|
867
|
+
* Pipe action async type.
|
|
868
|
+
*/
|
|
869
|
+
type PipeActionAsync<TInput, TOutput, TIssue extends BaseIssue<unknown>> = BaseValidationAsync<TInput, TOutput, TIssue> | BaseTransformationAsync<TInput, TOutput, TIssue>;
|
|
870
|
+
/**
|
|
871
|
+
* Pipe item type.
|
|
872
|
+
*/
|
|
873
|
+
type PipeItem<TInput, TOutput, TIssue extends BaseIssue<unknown>> = BaseSchema<TInput, TOutput, TIssue> | PipeAction<TInput, TOutput, TIssue>;
|
|
874
|
+
/**
|
|
875
|
+
* Pipe item async type.
|
|
876
|
+
*/
|
|
877
|
+
type PipeItemAsync<TInput, TOutput, TIssue extends BaseIssue<unknown>> = BaseSchemaAsync<TInput, TOutput, TIssue> | PipeActionAsync<TInput, TOutput, TIssue>;
|
|
878
|
+
|
|
879
|
+
/**
|
|
880
|
+
* Boolean issue interface.
|
|
881
|
+
*/
|
|
882
|
+
interface BooleanIssue extends BaseIssue<unknown> {
|
|
883
|
+
/**
|
|
884
|
+
* The issue kind.
|
|
885
|
+
*/
|
|
886
|
+
readonly kind: 'schema';
|
|
887
|
+
/**
|
|
888
|
+
* The issue type.
|
|
889
|
+
*/
|
|
890
|
+
readonly type: 'boolean';
|
|
891
|
+
/**
|
|
892
|
+
* The expected property.
|
|
893
|
+
*/
|
|
894
|
+
readonly expected: 'boolean';
|
|
895
|
+
}
|
|
896
|
+
/**
|
|
897
|
+
* Boolean schema interface.
|
|
898
|
+
*/
|
|
899
|
+
interface BooleanSchema<TMessage extends ErrorMessage<BooleanIssue> | undefined> extends BaseSchema<boolean, boolean, BooleanIssue> {
|
|
900
|
+
/**
|
|
901
|
+
* The schema type.
|
|
902
|
+
*/
|
|
903
|
+
readonly type: 'boolean';
|
|
904
|
+
/**
|
|
905
|
+
* The schema reference.
|
|
906
|
+
*/
|
|
907
|
+
readonly reference: typeof boolean;
|
|
908
|
+
/**
|
|
909
|
+
* The expected property.
|
|
910
|
+
*/
|
|
911
|
+
readonly expects: 'boolean';
|
|
912
|
+
/**
|
|
913
|
+
* The error message.
|
|
914
|
+
*/
|
|
915
|
+
readonly message: TMessage;
|
|
916
|
+
}
|
|
917
|
+
/**
|
|
918
|
+
* Creates a boolean schema.
|
|
919
|
+
*
|
|
920
|
+
* @returns A boolean schema.
|
|
921
|
+
*/
|
|
922
|
+
declare function boolean(): BooleanSchema<undefined>;
|
|
923
|
+
/**
|
|
924
|
+
* Creates a boolean schema.
|
|
925
|
+
*
|
|
926
|
+
* @param message The error message.
|
|
927
|
+
*
|
|
928
|
+
* @returns A boolean schema.
|
|
929
|
+
*/
|
|
930
|
+
declare function boolean<const TMessage extends ErrorMessage<BooleanIssue> | undefined>(message: TMessage): BooleanSchema<TMessage>;
|
|
931
|
+
|
|
932
|
+
/**
|
|
933
|
+
* Exact optional schema interface.
|
|
934
|
+
*/
|
|
935
|
+
interface ExactOptionalSchema<TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>>, TDefault extends Default<TWrapped, never>> extends BaseSchema<InferInput<TWrapped>, InferOutput<TWrapped>, InferIssue<TWrapped>> {
|
|
936
|
+
/**
|
|
937
|
+
* The schema type.
|
|
938
|
+
*/
|
|
939
|
+
readonly type: 'exact_optional';
|
|
940
|
+
/**
|
|
941
|
+
* The schema reference.
|
|
942
|
+
*/
|
|
943
|
+
readonly reference: typeof exactOptional;
|
|
944
|
+
/**
|
|
945
|
+
* The expected property.
|
|
946
|
+
*/
|
|
947
|
+
readonly expects: TWrapped['expects'];
|
|
948
|
+
/**
|
|
949
|
+
* The wrapped schema.
|
|
950
|
+
*/
|
|
951
|
+
readonly wrapped: TWrapped;
|
|
952
|
+
/**
|
|
953
|
+
* The default value.
|
|
954
|
+
*/
|
|
955
|
+
readonly default: TDefault;
|
|
956
|
+
}
|
|
957
|
+
/**
|
|
958
|
+
* Creates an exact optional schema.
|
|
959
|
+
*
|
|
960
|
+
* @param wrapped The wrapped schema.
|
|
961
|
+
*
|
|
962
|
+
* @returns An exact optional schema.
|
|
963
|
+
*/
|
|
964
|
+
declare function exactOptional<const TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>>>(wrapped: TWrapped): ExactOptionalSchema<TWrapped, undefined>;
|
|
965
|
+
/**
|
|
966
|
+
* Creates an exact optional schema.
|
|
967
|
+
*
|
|
968
|
+
* @param wrapped The wrapped schema.
|
|
969
|
+
* @param default_ The default value.
|
|
970
|
+
*
|
|
971
|
+
* @returns An exact optional schema.
|
|
972
|
+
*/
|
|
973
|
+
declare function exactOptional<const TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>>, const TDefault extends Default<TWrapped, never>>(wrapped: TWrapped, default_: TDefault): ExactOptionalSchema<TWrapped, TDefault>;
|
|
974
|
+
|
|
975
|
+
/**
|
|
976
|
+
* Exact optional schema async interface.
|
|
977
|
+
*/
|
|
978
|
+
interface ExactOptionalSchemaAsync<TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, TDefault extends DefaultAsync<TWrapped, never>> extends BaseSchemaAsync<InferInput<TWrapped>, InferOutput<TWrapped>, InferIssue<TWrapped>> {
|
|
979
|
+
/**
|
|
980
|
+
* The schema type.
|
|
981
|
+
*/
|
|
982
|
+
readonly type: 'exact_optional';
|
|
983
|
+
/**
|
|
984
|
+
* The schema reference.
|
|
985
|
+
*/
|
|
986
|
+
readonly reference: typeof exactOptional | typeof exactOptionalAsync;
|
|
987
|
+
/**
|
|
988
|
+
* The expected property.
|
|
989
|
+
*/
|
|
990
|
+
readonly expects: TWrapped['expects'];
|
|
991
|
+
/**
|
|
992
|
+
* The wrapped schema.
|
|
993
|
+
*/
|
|
994
|
+
readonly wrapped: TWrapped;
|
|
995
|
+
/**
|
|
996
|
+
* The default value.
|
|
997
|
+
*/
|
|
998
|
+
readonly default: TDefault;
|
|
999
|
+
}
|
|
1000
|
+
/**
|
|
1001
|
+
* Creates an exact optional schema.
|
|
1002
|
+
*
|
|
1003
|
+
* @param wrapped The wrapped schema.
|
|
1004
|
+
*
|
|
1005
|
+
* @returns An exact optional schema.
|
|
1006
|
+
*/
|
|
1007
|
+
declare function exactOptionalAsync<const TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>>(wrapped: TWrapped): ExactOptionalSchemaAsync<TWrapped, undefined>;
|
|
1008
|
+
/**
|
|
1009
|
+
* Creates an exact optional schema.
|
|
1010
|
+
*
|
|
1011
|
+
* @param wrapped The wrapped schema.
|
|
1012
|
+
* @param default_ The default value.
|
|
1013
|
+
*
|
|
1014
|
+
* @returns An exact optional schema.
|
|
1015
|
+
*/
|
|
1016
|
+
declare function exactOptionalAsync<const TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, const TDefault extends DefaultAsync<TWrapped, never>>(wrapped: TWrapped, default_: TDefault): ExactOptionalSchemaAsync<TWrapped, TDefault>;
|
|
1017
|
+
|
|
1018
|
+
/**
|
|
1019
|
+
* Literal type.
|
|
1020
|
+
*/
|
|
1021
|
+
type Literal = bigint | boolean | number | string | symbol;
|
|
1022
|
+
/**
|
|
1023
|
+
* Literal issue interface.
|
|
1024
|
+
*/
|
|
1025
|
+
interface LiteralIssue extends BaseIssue<unknown> {
|
|
1026
|
+
/**
|
|
1027
|
+
* The issue kind.
|
|
1028
|
+
*/
|
|
1029
|
+
readonly kind: 'schema';
|
|
1030
|
+
/**
|
|
1031
|
+
* The issue type.
|
|
1032
|
+
*/
|
|
1033
|
+
readonly type: 'literal';
|
|
1034
|
+
/**
|
|
1035
|
+
* The expected property.
|
|
1036
|
+
*/
|
|
1037
|
+
readonly expected: string;
|
|
1038
|
+
}
|
|
1039
|
+
/**
|
|
1040
|
+
* Literal schema interface.
|
|
1041
|
+
*/
|
|
1042
|
+
interface LiteralSchema<TLiteral extends Literal, TMessage extends ErrorMessage<LiteralIssue> | undefined> extends BaseSchema<TLiteral, TLiteral, LiteralIssue> {
|
|
1043
|
+
/**
|
|
1044
|
+
* The schema type.
|
|
1045
|
+
*/
|
|
1046
|
+
readonly type: 'literal';
|
|
1047
|
+
/**
|
|
1048
|
+
* The schema reference.
|
|
1049
|
+
*/
|
|
1050
|
+
readonly reference: typeof literal;
|
|
1051
|
+
/**
|
|
1052
|
+
* The literal value.
|
|
1053
|
+
*/
|
|
1054
|
+
readonly literal: TLiteral;
|
|
1055
|
+
/**
|
|
1056
|
+
* The error message.
|
|
1057
|
+
*/
|
|
1058
|
+
readonly message: TMessage;
|
|
1059
|
+
}
|
|
1060
|
+
/**
|
|
1061
|
+
* Creates a literal schema.
|
|
1062
|
+
*
|
|
1063
|
+
* @param literal_ The literal value.
|
|
1064
|
+
*
|
|
1065
|
+
* @returns A literal schema.
|
|
1066
|
+
*/
|
|
1067
|
+
declare function literal<const TLiteral extends Literal>(literal_: TLiteral): LiteralSchema<TLiteral, undefined>;
|
|
1068
|
+
/**
|
|
1069
|
+
* Creates a literal schema.
|
|
1070
|
+
*
|
|
1071
|
+
* @param literal_ The literal value.
|
|
1072
|
+
* @param message The error message.
|
|
1073
|
+
*
|
|
1074
|
+
* @returns A literal schema.
|
|
1075
|
+
*/
|
|
1076
|
+
declare function literal<const TLiteral extends Literal, const TMessage extends ErrorMessage<LiteralIssue> | undefined>(literal_: TLiteral, message: TMessage): LiteralSchema<TLiteral, TMessage>;
|
|
1077
|
+
|
|
1078
|
+
/**
|
|
1079
|
+
* Infer nullable output type.
|
|
1080
|
+
*/
|
|
1081
|
+
type InferNullableOutput<TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, TDefault extends DefaultAsync<TWrapped, null>> = undefined extends TDefault ? InferOutput<TWrapped> | null : InferOutput<TWrapped> | Extract<DefaultValue<TDefault>, null>;
|
|
1082
|
+
|
|
1083
|
+
/**
|
|
1084
|
+
* Nullable schema interface.
|
|
1085
|
+
*/
|
|
1086
|
+
interface NullableSchema<TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>>, TDefault extends Default<TWrapped, null>> extends BaseSchema<InferInput<TWrapped> | null, InferNullableOutput<TWrapped, TDefault>, InferIssue<TWrapped>> {
|
|
1087
|
+
/**
|
|
1088
|
+
* The schema type.
|
|
1089
|
+
*/
|
|
1090
|
+
readonly type: 'nullable';
|
|
1091
|
+
/**
|
|
1092
|
+
* The schema reference.
|
|
1093
|
+
*/
|
|
1094
|
+
readonly reference: typeof nullable;
|
|
1095
|
+
/**
|
|
1096
|
+
* The expected property.
|
|
1097
|
+
*/
|
|
1098
|
+
readonly expects: `(${TWrapped['expects']} | null)`;
|
|
1099
|
+
/**
|
|
1100
|
+
* The wrapped schema.
|
|
1101
|
+
*/
|
|
1102
|
+
readonly wrapped: TWrapped;
|
|
1103
|
+
/**
|
|
1104
|
+
* The default value.
|
|
1105
|
+
*/
|
|
1106
|
+
readonly default: TDefault;
|
|
1107
|
+
}
|
|
1108
|
+
/**
|
|
1109
|
+
* Creates a nullable schema.
|
|
1110
|
+
*
|
|
1111
|
+
* @param wrapped The wrapped schema.
|
|
1112
|
+
*
|
|
1113
|
+
* @returns A nullable schema.
|
|
1114
|
+
*/
|
|
1115
|
+
declare function nullable<const TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>>>(wrapped: TWrapped): NullableSchema<TWrapped, undefined>;
|
|
1116
|
+
/**
|
|
1117
|
+
* Creates a nullable schema.
|
|
1118
|
+
*
|
|
1119
|
+
* @param wrapped The wrapped schema.
|
|
1120
|
+
* @param default_ The default value.
|
|
1121
|
+
*
|
|
1122
|
+
* @returns A nullable schema.
|
|
1123
|
+
*/
|
|
1124
|
+
declare function nullable<const TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>>, const TDefault extends Default<TWrapped, null>>(wrapped: TWrapped, default_: TDefault): NullableSchema<TWrapped, TDefault>;
|
|
1125
|
+
|
|
1126
|
+
/**
|
|
1127
|
+
* Infer nullish output type.
|
|
1128
|
+
*/
|
|
1129
|
+
type InferNullishOutput<TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, TDefault extends DefaultAsync<TWrapped, null | undefined>> = undefined extends TDefault ? InferOutput<TWrapped> | null | undefined : InferOutput<TWrapped> | Extract<DefaultValue<TDefault>, null | undefined>;
|
|
1130
|
+
|
|
1131
|
+
/**
|
|
1132
|
+
* Nullish schema interface.
|
|
1133
|
+
*/
|
|
1134
|
+
interface NullishSchema<TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>>, TDefault extends Default<TWrapped, null | undefined>> extends BaseSchema<InferInput<TWrapped> | null | undefined, InferNullishOutput<TWrapped, TDefault>, InferIssue<TWrapped>> {
|
|
1135
|
+
/**
|
|
1136
|
+
* The schema type.
|
|
1137
|
+
*/
|
|
1138
|
+
readonly type: 'nullish';
|
|
1139
|
+
/**
|
|
1140
|
+
* The schema reference.
|
|
1141
|
+
*/
|
|
1142
|
+
readonly reference: typeof nullish;
|
|
1143
|
+
/**
|
|
1144
|
+
* The expected property.
|
|
1145
|
+
*/
|
|
1146
|
+
readonly expects: `(${TWrapped['expects']} | null | undefined)`;
|
|
1147
|
+
/**
|
|
1148
|
+
* The wrapped schema.
|
|
1149
|
+
*/
|
|
1150
|
+
readonly wrapped: TWrapped;
|
|
1151
|
+
/**
|
|
1152
|
+
* The default value.
|
|
1153
|
+
*/
|
|
1154
|
+
readonly default: TDefault;
|
|
1155
|
+
}
|
|
1156
|
+
/**
|
|
1157
|
+
* Creates a nullish schema.
|
|
1158
|
+
*
|
|
1159
|
+
* @param wrapped The wrapped schema.
|
|
1160
|
+
*
|
|
1161
|
+
* @returns A nullish schema.
|
|
1162
|
+
*/
|
|
1163
|
+
declare function nullish<const TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>>>(wrapped: TWrapped): NullishSchema<TWrapped, undefined>;
|
|
1164
|
+
/**
|
|
1165
|
+
* Creates a nullish schema.
|
|
1166
|
+
*
|
|
1167
|
+
* @param wrapped The wrapped schema.
|
|
1168
|
+
* @param default_ The default value.
|
|
1169
|
+
*
|
|
1170
|
+
* @returns A nullish schema.
|
|
1171
|
+
*/
|
|
1172
|
+
declare function nullish<const TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>>, const TDefault extends Default<TWrapped, null | undefined>>(wrapped: TWrapped, default_: TDefault): NullishSchema<TWrapped, TDefault>;
|
|
1173
|
+
|
|
1174
|
+
/**
|
|
1175
|
+
* Nullish schema async interface.
|
|
1176
|
+
*/
|
|
1177
|
+
interface NullishSchemaAsync<TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, TDefault extends DefaultAsync<TWrapped, null | undefined>> extends BaseSchemaAsync<InferInput<TWrapped> | null | undefined, InferNullishOutput<TWrapped, TDefault>, InferIssue<TWrapped>> {
|
|
1178
|
+
/**
|
|
1179
|
+
* The schema type.
|
|
1180
|
+
*/
|
|
1181
|
+
readonly type: 'nullish';
|
|
1182
|
+
/**
|
|
1183
|
+
* The schema reference.
|
|
1184
|
+
*/
|
|
1185
|
+
readonly reference: typeof nullish | typeof nullishAsync;
|
|
1186
|
+
/**
|
|
1187
|
+
* The expected property.
|
|
1188
|
+
*/
|
|
1189
|
+
readonly expects: `(${TWrapped['expects']} | null | undefined)`;
|
|
1190
|
+
/**
|
|
1191
|
+
* The wrapped schema.
|
|
1192
|
+
*/
|
|
1193
|
+
readonly wrapped: TWrapped;
|
|
1194
|
+
/**
|
|
1195
|
+
* The default value.
|
|
1196
|
+
*/
|
|
1197
|
+
readonly default: TDefault;
|
|
1198
|
+
}
|
|
1199
|
+
/**
|
|
1200
|
+
* Creates a nullish schema.
|
|
1201
|
+
*
|
|
1202
|
+
* @param wrapped The wrapped schema.
|
|
1203
|
+
*
|
|
1204
|
+
* @returns A nullish schema.
|
|
1205
|
+
*/
|
|
1206
|
+
declare function nullishAsync<const TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>>(wrapped: TWrapped): NullishSchemaAsync<TWrapped, undefined>;
|
|
1207
|
+
/**
|
|
1208
|
+
* Creates a nullish schema.
|
|
1209
|
+
*
|
|
1210
|
+
* @param wrapped The wrapped schema.
|
|
1211
|
+
* @param default_ The default value.
|
|
1212
|
+
*
|
|
1213
|
+
* @returns A nullish schema.
|
|
1214
|
+
*/
|
|
1215
|
+
declare function nullishAsync<const TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, const TDefault extends DefaultAsync<TWrapped, null | undefined>>(wrapped: TWrapped, default_: TDefault): NullishSchemaAsync<TWrapped, TDefault>;
|
|
1216
|
+
|
|
1217
|
+
/**
|
|
1218
|
+
* Number issue interface.
|
|
1219
|
+
*/
|
|
1220
|
+
interface NumberIssue extends BaseIssue<unknown> {
|
|
1221
|
+
/**
|
|
1222
|
+
* The issue kind.
|
|
1223
|
+
*/
|
|
1224
|
+
readonly kind: 'schema';
|
|
1225
|
+
/**
|
|
1226
|
+
* The issue type.
|
|
1227
|
+
*/
|
|
1228
|
+
readonly type: 'number';
|
|
1229
|
+
/**
|
|
1230
|
+
* The expected property.
|
|
1231
|
+
*/
|
|
1232
|
+
readonly expected: 'number';
|
|
1233
|
+
}
|
|
1234
|
+
/**
|
|
1235
|
+
* Number schema interface.
|
|
1236
|
+
*/
|
|
1237
|
+
interface NumberSchema<TMessage extends ErrorMessage<NumberIssue> | undefined> extends BaseSchema<number, number, NumberIssue> {
|
|
1238
|
+
/**
|
|
1239
|
+
* The schema type.
|
|
1240
|
+
*/
|
|
1241
|
+
readonly type: 'number';
|
|
1242
|
+
/**
|
|
1243
|
+
* The schema reference.
|
|
1244
|
+
*/
|
|
1245
|
+
readonly reference: typeof number;
|
|
1246
|
+
/**
|
|
1247
|
+
* The expected property.
|
|
1248
|
+
*/
|
|
1249
|
+
readonly expects: 'number';
|
|
1250
|
+
/**
|
|
1251
|
+
* The error message.
|
|
1252
|
+
*/
|
|
1253
|
+
readonly message: TMessage;
|
|
1254
|
+
}
|
|
1255
|
+
/**
|
|
1256
|
+
* Creates a number schema.
|
|
1257
|
+
*
|
|
1258
|
+
* @returns A number schema.
|
|
1259
|
+
*/
|
|
1260
|
+
declare function number(): NumberSchema<undefined>;
|
|
1261
|
+
/**
|
|
1262
|
+
* Creates a number schema.
|
|
1263
|
+
*
|
|
1264
|
+
* @param message The error message.
|
|
1265
|
+
*
|
|
1266
|
+
* @returns A number schema.
|
|
1267
|
+
*/
|
|
1268
|
+
declare function number<const TMessage extends ErrorMessage<NumberIssue> | undefined>(message: TMessage): NumberSchema<TMessage>;
|
|
1269
|
+
|
|
1270
|
+
/**
|
|
1271
|
+
* Object issue interface.
|
|
1272
|
+
*/
|
|
1273
|
+
interface ObjectIssue extends BaseIssue<unknown> {
|
|
1274
|
+
/**
|
|
1275
|
+
* The issue kind.
|
|
1276
|
+
*/
|
|
1277
|
+
readonly kind: 'schema';
|
|
1278
|
+
/**
|
|
1279
|
+
* The issue type.
|
|
1280
|
+
*/
|
|
1281
|
+
readonly type: 'object';
|
|
1282
|
+
/**
|
|
1283
|
+
* The expected property.
|
|
1284
|
+
*/
|
|
1285
|
+
readonly expected: 'Object' | `"${string}"`;
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
/**
|
|
1289
|
+
* Object schema interface.
|
|
1290
|
+
*/
|
|
1291
|
+
interface ObjectSchema<TEntries extends ObjectEntries, TMessage extends ErrorMessage<ObjectIssue> | undefined> extends BaseSchema<InferObjectInput<TEntries>, InferObjectOutput<TEntries>, ObjectIssue | InferObjectIssue<TEntries>> {
|
|
1292
|
+
/**
|
|
1293
|
+
* The schema type.
|
|
1294
|
+
*/
|
|
1295
|
+
readonly type: 'object';
|
|
1296
|
+
/**
|
|
1297
|
+
* The schema reference.
|
|
1298
|
+
*/
|
|
1299
|
+
readonly reference: typeof object;
|
|
1300
|
+
/**
|
|
1301
|
+
* The expected property.
|
|
1302
|
+
*/
|
|
1303
|
+
readonly expects: 'Object';
|
|
1304
|
+
/**
|
|
1305
|
+
* The entries schema.
|
|
1306
|
+
*/
|
|
1307
|
+
readonly entries: TEntries;
|
|
1308
|
+
/**
|
|
1309
|
+
* The error message.
|
|
1310
|
+
*/
|
|
1311
|
+
readonly message: TMessage;
|
|
1312
|
+
}
|
|
1313
|
+
/**
|
|
1314
|
+
* Creates an object schema.
|
|
1315
|
+
*
|
|
1316
|
+
* Hint: This schema removes unknown entries. The output will only include the
|
|
1317
|
+
* entries you specify. To include unknown entries, use `looseObject`. To
|
|
1318
|
+
* return an issue for unknown entries, use `strictObject`. To include and
|
|
1319
|
+
* validate unknown entries, use `objectWithRest`.
|
|
1320
|
+
*
|
|
1321
|
+
* @param entries The entries schema.
|
|
1322
|
+
*
|
|
1323
|
+
* @returns An object schema.
|
|
1324
|
+
*/
|
|
1325
|
+
declare function object<const TEntries extends ObjectEntries>(entries: TEntries): ObjectSchema<TEntries, undefined>;
|
|
1326
|
+
/**
|
|
1327
|
+
* Creates an object schema.
|
|
1328
|
+
*
|
|
1329
|
+
* Hint: This schema removes unknown entries. The output will only include the
|
|
1330
|
+
* entries you specify. To include unknown entries, use `looseObject`. To
|
|
1331
|
+
* return an issue for unknown entries, use `strictObject`. To include and
|
|
1332
|
+
* validate unknown entries, use `objectWithRest`.
|
|
1333
|
+
*
|
|
1334
|
+
* @param entries The entries schema.
|
|
1335
|
+
* @param message The error message.
|
|
1336
|
+
*
|
|
1337
|
+
* @returns An object schema.
|
|
1338
|
+
*/
|
|
1339
|
+
declare function object<const TEntries extends ObjectEntries, const TMessage extends ErrorMessage<ObjectIssue> | undefined>(entries: TEntries, message: TMessage): ObjectSchema<TEntries, TMessage>;
|
|
1340
|
+
|
|
1341
|
+
/**
|
|
1342
|
+
* Infer optional output type.
|
|
1343
|
+
*/
|
|
1344
|
+
type InferOptionalOutput<TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, TDefault extends DefaultAsync<TWrapped, undefined>> = undefined extends TDefault ? InferOutput<TWrapped> | undefined : InferOutput<TWrapped> | Extract<DefaultValue<TDefault>, undefined>;
|
|
1345
|
+
|
|
1346
|
+
/**
|
|
1347
|
+
* Optional schema interface.
|
|
1348
|
+
*/
|
|
1349
|
+
interface OptionalSchema<TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>>, TDefault extends Default<TWrapped, undefined>> extends BaseSchema<InferInput<TWrapped> | undefined, InferOptionalOutput<TWrapped, TDefault>, InferIssue<TWrapped>> {
|
|
1350
|
+
/**
|
|
1351
|
+
* The schema type.
|
|
1352
|
+
*/
|
|
1353
|
+
readonly type: 'optional';
|
|
1354
|
+
/**
|
|
1355
|
+
* The schema reference.
|
|
1356
|
+
*/
|
|
1357
|
+
readonly reference: typeof optional;
|
|
1358
|
+
/**
|
|
1359
|
+
* The expected property.
|
|
1360
|
+
*/
|
|
1361
|
+
readonly expects: `(${TWrapped['expects']} | undefined)`;
|
|
1362
|
+
/**
|
|
1363
|
+
* The wrapped schema.
|
|
1364
|
+
*/
|
|
1365
|
+
readonly wrapped: TWrapped;
|
|
1366
|
+
/**
|
|
1367
|
+
* The default value.
|
|
1368
|
+
*/
|
|
1369
|
+
readonly default: TDefault;
|
|
1370
|
+
}
|
|
1371
|
+
/**
|
|
1372
|
+
* Creates an optional schema.
|
|
1373
|
+
*
|
|
1374
|
+
* @param wrapped The wrapped schema.
|
|
1375
|
+
*
|
|
1376
|
+
* @returns An optional schema.
|
|
1377
|
+
*/
|
|
1378
|
+
declare function optional<const TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>>>(wrapped: TWrapped): OptionalSchema<TWrapped, undefined>;
|
|
1379
|
+
/**
|
|
1380
|
+
* Creates an optional schema.
|
|
1381
|
+
*
|
|
1382
|
+
* @param wrapped The wrapped schema.
|
|
1383
|
+
* @param default_ The default value.
|
|
1384
|
+
*
|
|
1385
|
+
* @returns An optional schema.
|
|
1386
|
+
*/
|
|
1387
|
+
declare function optional<const TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>>, const TDefault extends Default<TWrapped, undefined>>(wrapped: TWrapped, default_: TDefault): OptionalSchema<TWrapped, TDefault>;
|
|
1388
|
+
|
|
1389
|
+
/**
|
|
1390
|
+
* Optional schema async interface.
|
|
1391
|
+
*/
|
|
1392
|
+
interface OptionalSchemaAsync<TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, TDefault extends DefaultAsync<TWrapped, undefined>> extends BaseSchemaAsync<InferInput<TWrapped> | undefined, InferOptionalOutput<TWrapped, TDefault>, InferIssue<TWrapped>> {
|
|
1393
|
+
/**
|
|
1394
|
+
* The schema type.
|
|
1395
|
+
*/
|
|
1396
|
+
readonly type: 'optional';
|
|
1397
|
+
/**
|
|
1398
|
+
* The schema reference.
|
|
1399
|
+
*/
|
|
1400
|
+
readonly reference: typeof optional | typeof optionalAsync;
|
|
1401
|
+
/**
|
|
1402
|
+
* The expected property.
|
|
1403
|
+
*/
|
|
1404
|
+
readonly expects: `(${TWrapped['expects']} | undefined)`;
|
|
1405
|
+
/**
|
|
1406
|
+
* The wrapped schema.
|
|
1407
|
+
*/
|
|
1408
|
+
readonly wrapped: TWrapped;
|
|
1409
|
+
/**
|
|
1410
|
+
* The default value.
|
|
1411
|
+
*/
|
|
1412
|
+
readonly default: TDefault;
|
|
1413
|
+
}
|
|
1414
|
+
/**
|
|
1415
|
+
* Creates an optional schema.
|
|
1416
|
+
*
|
|
1417
|
+
* @param wrapped The wrapped schema.
|
|
1418
|
+
*
|
|
1419
|
+
* @returns An optional schema.
|
|
1420
|
+
*/
|
|
1421
|
+
declare function optionalAsync<const TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>>(wrapped: TWrapped): OptionalSchemaAsync<TWrapped, undefined>;
|
|
1422
|
+
/**
|
|
1423
|
+
* Creates an optional schema.
|
|
1424
|
+
*
|
|
1425
|
+
* @param wrapped The wrapped schema.
|
|
1426
|
+
* @param default_ The default value.
|
|
1427
|
+
*
|
|
1428
|
+
* @returns An optional schema.
|
|
1429
|
+
*/
|
|
1430
|
+
declare function optionalAsync<const TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, const TDefault extends DefaultAsync<TWrapped, undefined>>(wrapped: TWrapped, default_: TDefault): OptionalSchemaAsync<TWrapped, TDefault>;
|
|
1431
|
+
|
|
1432
|
+
/**
|
|
1433
|
+
* String issue interface.
|
|
1434
|
+
*/
|
|
1435
|
+
interface StringIssue extends BaseIssue<unknown> {
|
|
1436
|
+
/**
|
|
1437
|
+
* The issue kind.
|
|
1438
|
+
*/
|
|
1439
|
+
readonly kind: 'schema';
|
|
1440
|
+
/**
|
|
1441
|
+
* The issue type.
|
|
1442
|
+
*/
|
|
1443
|
+
readonly type: 'string';
|
|
1444
|
+
/**
|
|
1445
|
+
* The expected property.
|
|
1446
|
+
*/
|
|
1447
|
+
readonly expected: 'string';
|
|
1448
|
+
}
|
|
1449
|
+
/**
|
|
1450
|
+
* String schema interface.
|
|
1451
|
+
*/
|
|
1452
|
+
interface StringSchema<TMessage extends ErrorMessage<StringIssue> | undefined> extends BaseSchema<string, string, StringIssue> {
|
|
1453
|
+
/**
|
|
1454
|
+
* The schema type.
|
|
1455
|
+
*/
|
|
1456
|
+
readonly type: 'string';
|
|
1457
|
+
/**
|
|
1458
|
+
* The schema reference.
|
|
1459
|
+
*/
|
|
1460
|
+
readonly reference: typeof string;
|
|
1461
|
+
/**
|
|
1462
|
+
* The expected property.
|
|
1463
|
+
*/
|
|
1464
|
+
readonly expects: 'string';
|
|
1465
|
+
/**
|
|
1466
|
+
* The error message.
|
|
1467
|
+
*/
|
|
1468
|
+
readonly message: TMessage;
|
|
1469
|
+
}
|
|
1470
|
+
/**
|
|
1471
|
+
* Creates a string schema.
|
|
1472
|
+
*
|
|
1473
|
+
* @returns A string schema.
|
|
1474
|
+
*/
|
|
1475
|
+
declare function string(): StringSchema<undefined>;
|
|
1476
|
+
/**
|
|
1477
|
+
* Creates a string schema.
|
|
1478
|
+
*
|
|
1479
|
+
* @param message The error message.
|
|
1480
|
+
*
|
|
1481
|
+
* @returns A string schema.
|
|
1482
|
+
*/
|
|
1483
|
+
declare function string<const TMessage extends ErrorMessage<StringIssue> | undefined>(message: TMessage): StringSchema<TMessage>;
|
|
1484
|
+
|
|
1485
|
+
/**
|
|
1486
|
+
* Unknown schema interface.
|
|
1487
|
+
*/
|
|
1488
|
+
interface UnknownSchema extends BaseSchema<unknown, unknown, never> {
|
|
1489
|
+
/**
|
|
1490
|
+
* The schema type.
|
|
1491
|
+
*/
|
|
1492
|
+
readonly type: 'unknown';
|
|
1493
|
+
/**
|
|
1494
|
+
* The schema reference.
|
|
1495
|
+
*/
|
|
1496
|
+
readonly reference: typeof unknown;
|
|
1497
|
+
/**
|
|
1498
|
+
* The expected property.
|
|
1499
|
+
*/
|
|
1500
|
+
readonly expects: 'unknown';
|
|
1501
|
+
}
|
|
1502
|
+
/**
|
|
1503
|
+
* Creates a unknown schema.
|
|
1504
|
+
*
|
|
1505
|
+
* @returns A unknown schema.
|
|
1506
|
+
*/
|
|
1507
|
+
declare function unknown(): UnknownSchema;
|
|
1508
|
+
|
|
1509
|
+
/**
|
|
1510
|
+
* Readonly output type.
|
|
1511
|
+
*/
|
|
1512
|
+
type ReadonlyOutput<TInput> = TInput extends Map<infer TKey, infer TValue> ? ReadonlyMap<TKey, TValue> : TInput extends Set<infer TValue> ? ReadonlySet<TValue> : Readonly<TInput>;
|
|
1513
|
+
/**
|
|
1514
|
+
* Readonly action interface.
|
|
1515
|
+
*/
|
|
1516
|
+
interface ReadonlyAction<TInput> extends BaseTransformation<TInput, ReadonlyOutput<TInput>, never> {
|
|
1517
|
+
/**
|
|
1518
|
+
* The action type.
|
|
1519
|
+
*/
|
|
1520
|
+
readonly type: 'readonly';
|
|
1521
|
+
/**
|
|
1522
|
+
* The action reference.
|
|
1523
|
+
*/
|
|
1524
|
+
readonly reference: typeof readonly;
|
|
1525
|
+
}
|
|
1526
|
+
/**
|
|
1527
|
+
* Creates a readonly transformation action.
|
|
1528
|
+
*
|
|
1529
|
+
* @returns A readonly action.
|
|
1530
|
+
*/
|
|
1531
|
+
declare function readonly<TInput>(): ReadonlyAction<TInput>;
|
|
1532
|
+
|
|
1533
|
+
/**
|
|
1534
|
+
* A Valibot error with useful information.
|
|
1535
|
+
*/
|
|
1536
|
+
declare class ValiError<TSchema extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>> extends Error {
|
|
1537
|
+
/**
|
|
1538
|
+
* The error issues.
|
|
1539
|
+
*/
|
|
1540
|
+
readonly issues: [InferIssue<TSchema>, ...InferIssue<TSchema>[]];
|
|
1541
|
+
/**
|
|
1542
|
+
* Creates a Valibot error with useful information.
|
|
1543
|
+
*
|
|
1544
|
+
* @param issues The error issues.
|
|
1545
|
+
*/
|
|
1546
|
+
constructor(issues: [InferIssue<TSchema>, ...InferIssue<TSchema>[]]);
|
|
1547
|
+
}
|
|
1548
|
+
|
|
1549
|
+
declare const responseSchema: ObjectSchema<{
|
|
1550
|
+
/** Not necessarily true when we receive a positive response because the API considers only 200 as success */
|
|
1551
|
+
readonly success: BooleanSchema<undefined>;
|
|
1552
|
+
readonly integration_response: ObjectSchema<{
|
|
1553
|
+
readonly service: OptionalSchema<StringSchema<undefined>, undefined>;
|
|
1554
|
+
readonly status: NumberSchema<undefined>;
|
|
1555
|
+
readonly data: UnknownSchema;
|
|
1556
|
+
readonly error: NullableSchema<ObjectSchema<{
|
|
1557
|
+
readonly message: StringSchema<undefined>;
|
|
1558
|
+
readonly data: UnknownSchema;
|
|
1559
|
+
}, undefined>, undefined>;
|
|
1560
|
+
}, undefined>;
|
|
1561
|
+
}, undefined>;
|
|
1562
|
+
type IntegrationResponse = InferOutput<typeof responseSchema>;
|
|
1563
|
+
|
|
1564
|
+
type TextInput = {
|
|
1565
|
+
type: 'text';
|
|
1566
|
+
config: {
|
|
1567
|
+
key: string;
|
|
1568
|
+
optional: boolean;
|
|
1569
|
+
placeholder?: string;
|
|
1570
|
+
format: 'text' | 'email' | 'url' | 'phone';
|
|
1571
|
+
defaultValue?: string;
|
|
1572
|
+
maxChars: number | undefined;
|
|
1573
|
+
minChars: number | undefined;
|
|
1574
|
+
};
|
|
1575
|
+
submission: TextInputSubmission;
|
|
1576
|
+
};
|
|
1577
|
+
type TextInputSubmission = {
|
|
1578
|
+
type: 'string';
|
|
1579
|
+
value: string;
|
|
1580
|
+
};
|
|
1581
|
+
type NumberInput = {
|
|
1582
|
+
type: 'number';
|
|
1583
|
+
config: {
|
|
1584
|
+
key: string;
|
|
1585
|
+
optional: boolean;
|
|
1586
|
+
placeholder?: string;
|
|
1587
|
+
defaultValue?: string;
|
|
1588
|
+
decimalCases?: number;
|
|
1589
|
+
min?: number;
|
|
1590
|
+
max?: number;
|
|
1591
|
+
};
|
|
1592
|
+
submission: NumberInputSubmission;
|
|
1593
|
+
};
|
|
1594
|
+
type NumberInputSubmission = {
|
|
1595
|
+
type: 'number';
|
|
1596
|
+
value: number;
|
|
1597
|
+
};
|
|
1598
|
+
type MultipleChoiceInput = {
|
|
1599
|
+
type: 'multiple-choice';
|
|
1600
|
+
config: {
|
|
1601
|
+
key: string;
|
|
1602
|
+
options: {
|
|
1603
|
+
value: string;
|
|
1604
|
+
label: string;
|
|
1605
|
+
}[];
|
|
1606
|
+
minSelected?: number;
|
|
1607
|
+
maxSelected?: number;
|
|
1608
|
+
};
|
|
1609
|
+
submission: MultipleChoiceInputSubmission;
|
|
1610
|
+
};
|
|
1611
|
+
type MultipleChoiceInputSubmission = {
|
|
1612
|
+
type: 'enum';
|
|
1613
|
+
value: string[];
|
|
1614
|
+
};
|
|
1615
|
+
type BooleanChoiceInput = {
|
|
1616
|
+
type: 'boolean';
|
|
1617
|
+
config: {
|
|
1618
|
+
key: string;
|
|
1619
|
+
labels: {
|
|
1620
|
+
true: string;
|
|
1621
|
+
false: string;
|
|
1622
|
+
};
|
|
1623
|
+
optional: boolean;
|
|
1624
|
+
};
|
|
1625
|
+
submission: BooleanChoiceInputSubmission;
|
|
1626
|
+
};
|
|
1627
|
+
type BooleanChoiceInputSubmission = {
|
|
1628
|
+
type: 'boolean';
|
|
1629
|
+
value: boolean;
|
|
1630
|
+
};
|
|
1631
|
+
type FileToUpload = {
|
|
1632
|
+
name: string;
|
|
1633
|
+
data: string;
|
|
1634
|
+
sizeKb: number;
|
|
1635
|
+
};
|
|
1636
|
+
type FileInput = {
|
|
1637
|
+
type: 'file';
|
|
1638
|
+
config: {
|
|
1639
|
+
key: string;
|
|
1640
|
+
optional: boolean;
|
|
1641
|
+
extensions: string[];
|
|
1642
|
+
fileSizeLimitKib?: number;
|
|
1643
|
+
allowMultiple: boolean;
|
|
1644
|
+
};
|
|
1645
|
+
key: string;
|
|
1646
|
+
submission: FileInputSubmission;
|
|
1647
|
+
};
|
|
1648
|
+
type FileInputSubmission = {
|
|
1649
|
+
type: 'file';
|
|
1650
|
+
value: FileToUpload[];
|
|
1651
|
+
};
|
|
1652
|
+
type SubmitInput = {
|
|
1653
|
+
type: 'submit';
|
|
1654
|
+
config: {
|
|
1655
|
+
key: string;
|
|
1656
|
+
label: string;
|
|
1657
|
+
};
|
|
1658
|
+
submission: SubmitInputSubmission;
|
|
1659
|
+
};
|
|
1660
|
+
type SubmitInputSubmission = {
|
|
1661
|
+
type: 'integration';
|
|
1662
|
+
value: IntegrationResponse;
|
|
1663
|
+
};
|
|
1664
|
+
type AddressInput = {
|
|
1665
|
+
type: 'address';
|
|
1666
|
+
config: {
|
|
1667
|
+
key: string;
|
|
1668
|
+
optional: boolean;
|
|
1669
|
+
/** Keys for remapping
|
|
1670
|
+
* @example {line1: "lineOne"} will send submissions with the key being "lineOne" instead of "line1"
|
|
1671
|
+
*/
|
|
1672
|
+
keys: {
|
|
1673
|
+
line1: string | null;
|
|
1674
|
+
line2: string | null;
|
|
1675
|
+
line3: string | null;
|
|
1676
|
+
city: string | null;
|
|
1677
|
+
state: string | null;
|
|
1678
|
+
postcode: string | null;
|
|
1679
|
+
country: string | null;
|
|
1680
|
+
};
|
|
1681
|
+
placeholder?: string;
|
|
1682
|
+
};
|
|
1683
|
+
submission: AddressInputSubmission;
|
|
1684
|
+
};
|
|
1685
|
+
type AddressInputSubmission = {
|
|
1686
|
+
type: 'address';
|
|
1687
|
+
value: {
|
|
1688
|
+
[remappedKey: string]: string | undefined;
|
|
1689
|
+
};
|
|
1690
|
+
};
|
|
1691
|
+
type PhoneInput = {
|
|
1692
|
+
type: 'phone';
|
|
1693
|
+
config: {
|
|
1694
|
+
key: string;
|
|
1695
|
+
optional: boolean;
|
|
1696
|
+
submissionFormat: 'phone' | 'text';
|
|
1697
|
+
placeholder?: string;
|
|
1698
|
+
defaultValue: {
|
|
1699
|
+
countryCode?: string;
|
|
1700
|
+
phoneNumber?: string;
|
|
1701
|
+
};
|
|
1702
|
+
minChars?: number;
|
|
1703
|
+
maxChars?: number;
|
|
1704
|
+
};
|
|
1705
|
+
submission: PhoneInputSubmission;
|
|
1706
|
+
};
|
|
1707
|
+
type PhoneInputSubmission = {
|
|
1708
|
+
type: 'phone';
|
|
1709
|
+
value: {
|
|
1710
|
+
countryCode: string;
|
|
1711
|
+
phoneNumber: string;
|
|
1712
|
+
};
|
|
1713
|
+
} | {
|
|
1714
|
+
type: 'string';
|
|
1715
|
+
value: string;
|
|
1716
|
+
};
|
|
1717
|
+
type FlowInput = TextInput | NumberInput | MultipleChoiceInput | BooleanChoiceInput | FileInput | SubmitInput | AddressInput | PhoneInput;
|
|
1718
|
+
|
|
1719
|
+
type FlowSubmissions = {
|
|
1720
|
+
[key: string]: FlowInput['submission'] | {
|
|
1721
|
+
type: 'integration';
|
|
1722
|
+
value: unknown;
|
|
1723
|
+
};
|
|
1724
|
+
};
|
|
1725
|
+
|
|
1726
|
+
type Result<R, E> = Ok<R> | Err<E>;
|
|
1727
|
+
interface Ok<R> {
|
|
1728
|
+
ok: true;
|
|
1729
|
+
err: false;
|
|
1730
|
+
val: R;
|
|
1731
|
+
'~brand': 'ok';
|
|
1732
|
+
}
|
|
1733
|
+
declare const Ok: <const R>(val: R) => Ok<R>;
|
|
1734
|
+
interface Err<E> {
|
|
1735
|
+
ok: false;
|
|
1736
|
+
err: true;
|
|
1737
|
+
val: E;
|
|
1738
|
+
'~brand': 'err';
|
|
1739
|
+
}
|
|
1740
|
+
declare const Err: <const E>(val: E) => Err<E>;
|
|
1741
|
+
|
|
1742
|
+
export { Err as E, FlowSubmissions as F, InferOutput as I, LiteralSchema as L, NullableSchema as N, Ok as O, PhoneInput as P, Result as R, StringSchema as S, ValiError as V, FlowInput as a, ObjectSchema as b, OptionalSchema as c };
|