UNPKG

82.8 kBTypeScriptView Raw
1// The following definitions have been copied (almost) as-is from:
2// https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/hapi__joi
3//
4// Note: This file is expected to change dramatically in the next major release and have been
5// imported here to make migrating back to the "joi" module name simpler. It include known bugs
6// and other issues. It does not include some new features included in version 17.2.0 or newer.
7//
8// TypeScript Version: 2.8
9
10// TODO express type of Schema in a type-parameter (.default, .valid, .example etc)
11
12declare namespace Joi {
13 type Types =
14 | 'any'
15 | 'alternatives'
16 | 'array'
17 | 'boolean'
18 | 'binary'
19 | 'date'
20 | 'function'
21 | 'link'
22 | 'number'
23 | 'object'
24 | 'string'
25 | 'symbol';
26
27 type BasicType = boolean | number | string | any[] | object | null;
28
29 type LanguageMessages = Record<string, string | Record<string, string>>;
30
31 type PresenceMode = 'optional' | 'required' | 'forbidden';
32
33 interface ErrorFormattingOptions {
34 /**
35 * when true, error message templates will escape special characters to HTML entities, for security purposes.
36 *
37 * @default false
38 */
39 escapeHtml?: boolean;
40 /**
41 * defines the value used to set the label context variable.
42 */
43 label?: 'path' | 'key' | false;
44 /**
45 * The preferred language code for error messages.
46 * The value is matched against keys at the root of the messages object, and then the error code as a child key of that.
47 * Can be a reference to the value, global context, or local context which is the root value passed to the validation function.
48 *
49 * Note that references to the value are usually not what you want as they move around the value structure relative to where the error happens.
50 * Instead, either use the global context, or the absolute value (e.g. `Joi.ref('/variable')`)
51 */
52 language?: keyof LanguageMessages;
53 /**
54 * when false, skips rendering error templates. Useful when error messages are generated elsewhere to save processing time.
55 *
56 * @default true
57 */
58 render?: boolean;
59 /**
60 * when true, the main error will possess a stack trace, otherwise it will be disabled.
61 * Defaults to false for performances reasons. Has no effect on platforms other than V8/node.js as it uses the Stack trace API.
62 *
63 * @default false
64 */
65 stack?: boolean;
66 /**
67 * overrides the way values are wrapped (e.g. `[]` around arrays, `""` around labels).
68 * Each key can be set to a string with one (same character before and after the value) or two characters (first character
69 * before and second character after), or `false` to disable wrapping.
70 */
71 wrap?: {
72 /**
73 * the characters used around `{#label}` references. Defaults to `'"'`.
74 *
75 * @default '"'
76 */
77 label?: string | false,
78
79 /**
80 * the characters used around array values. Defaults to `'[]'`
81 *
82 * @default '[]'
83 */
84 array?: string | false
85
86 /**
87 * the characters used around array string values. Defaults to no wrapping.
88 *
89 * @default false
90 */
91 string?: string | false
92 };
93 }
94
95 interface BaseValidationOptions {
96 /**
97 * when true, stops validation on the first error, otherwise returns all the errors found.
98 *
99 * @default true
100 */
101 abortEarly?: boolean;
102 /**
103 * when true, allows object to contain unknown keys which are ignored.
104 *
105 * @default false
106 */
107 allowUnknown?: boolean;
108 /**
109 * when true, return artifacts alongside the value.
110 *
111 * @default false
112 */
113 artifacts?: boolean;
114 /**
115 * when true, schema caching is enabled (for schemas with explicit caching rules).
116 *
117 * @default false
118 */
119 cache?: boolean;
120 /**
121 * provides an external data set to be used in references
122 */
123 context?: Context;
124 /**
125 * when true, attempts to cast values to the required types (e.g. a string to a number).
126 *
127 * @default true
128 */
129 convert?: boolean;
130 /**
131 * sets the string format used when converting dates to strings in error messages and casting.
132 *
133 * @default 'iso'
134 */
135 dateFormat?: 'date' | 'iso' | 'string' | 'time' | 'utc';
136 /**
137 * when true, valid results and throw errors are decorated with a debug property which includes an array of the validation steps used to generate the returned result.
138 *
139 * @default false
140 */
141 debug?: boolean;
142 /**
143 * error formatting settings.
144 */
145 errors?: ErrorFormattingOptions;
146 /**
147 * if false, the external rules set with `any.external()` are ignored, which is required to ignore any external validations in synchronous mode (or an exception is thrown).
148 *
149 * @default true
150 */
151 externals?: boolean;
152 /**
153 * when true, do not apply default values.
154 *
155 * @default false
156 */
157 noDefaults?: boolean;
158 /**
159 * when true, inputs are shallow cloned to include non-enumerable properties.
160 *
161 * @default false
162 */
163 nonEnumerables?: boolean;
164 /**
165 * sets the default presence requirements. Supported modes: 'optional', 'required', and 'forbidden'.
166 *
167 * @default 'optional'
168 */
169 presence?: PresenceMode;
170 /**
171 * when true, ignores unknown keys with a function value.
172 *
173 * @default false
174 */
175 skipFunctions?: boolean;
176 /**
177 * remove unknown elements from objects and arrays.
178 * - when true, all unknown elements will be removed
179 * - when an object:
180 * - objects - set to true to remove unknown keys from objects
181 *
182 * @default false
183 */
184 stripUnknown?: boolean | { arrays?: boolean; objects?: boolean };
185 }
186
187 interface ValidationOptions extends BaseValidationOptions {
188 /**
189 * overrides individual error messages. Defaults to no override (`{}`).
190 * Messages use the same rules as templates.
191 * Variables in double braces `{{var}}` are HTML escaped if the option `errors.escapeHtml` is set to true.
192 *
193 * @default {}
194 */
195 messages?: LanguageMessages;
196 }
197
198 interface AsyncValidationOptions extends ValidationOptions {
199 /**
200 * when true, artifacts are returned alongside the value (i.e. `{ value, artifacts }`)
201 *
202 * @default false
203 */
204 artifacts?: boolean;
205 /**
206 * when true, warnings are returned alongside the value (i.e. `{ value, warning }`).
207 *
208 * @default false
209 */
210 warnings?: boolean;
211 }
212
213 interface LanguageMessageTemplate {
214 source: string;
215 rendered: string;
216 }
217
218 interface ErrorValidationOptions extends BaseValidationOptions {
219 messages?: Record<string, LanguageMessageTemplate>;
220 }
221
222 interface RenameOptions {
223 /**
224 * if true, does not delete the old key name, keeping both the new and old keys in place.
225 *
226 * @default false
227 */
228 alias?: boolean;
229 /**
230 * if true, allows renaming multiple keys to the same destination where the last rename wins.
231 *
232 * @default false
233 */
234 multiple?: boolean;
235 /**
236 * if true, allows renaming a key over an existing key.
237 *
238 * @default false
239 */
240 override?: boolean;
241 /**
242 * if true, skip renaming of a key if it's undefined.
243 *
244 * @default false
245 */
246 ignoreUndefined?: boolean;
247 }
248
249 interface TopLevelDomainOptions {
250 /**
251 * - `true` to use the IANA list of registered TLDs. This is the default value.
252 * - `false` to allow any TLD not listed in the `deny` list, if present.
253 * - A `Set` or array of the allowed TLDs. Cannot be used together with `deny`.
254 */
255 allow?: Set<string> | string[] | boolean;
256 /**
257 * - A `Set` or array of the forbidden TLDs. Cannot be used together with a custom `allow` list.
258 */
259 deny?: Set<string> | string[];
260 }
261
262 interface HierarchySeparatorOptions {
263 /**
264 * overrides the default `.` hierarchy separator. Set to false to treat the key as a literal value.
265 *
266 * @default '.'
267 */
268 separator?: string | false;
269 }
270
271 interface DependencyOptions extends HierarchySeparatorOptions {
272 /**
273 * overrides the default check for a present value.
274 *
275 * @default (resolved) => resolved !== undefined
276 */
277 isPresent?: (resolved: any) => boolean;
278 }
279
280 interface EmailOptions {
281 /**
282 * if `true`, domains ending with a `.` character are permitted
283 *
284 * @default false
285 */
286 allowFullyQualified?: boolean;
287 /**
288 * If `true`, Unicode characters are permitted
289 *
290 * @default true
291 */
292 allowUnicode?: boolean;
293 /**
294 * if `true`, ignore invalid email length errors.
295 *
296 * @default false
297 */
298 ignoreLength?: boolean;
299 /**
300 * if true, allows multiple email addresses in a single string, separated by , or the separator characters.
301 *
302 * @default false
303 */
304 multiple?: boolean;
305 /**
306 * when multiple is true, overrides the default , separator. String can be a single character or multiple separator characters.
307 *
308 * @default ','
309 */
310 separator?: string | string[];
311 /**
312 * Options for TLD (top level domain) validation. By default, the TLD must be a valid name listed on the [IANA registry](http://data.iana.org/TLD/tlds-alpha-by-domain.txt)
313 *
314 * @default { allow: true }
315 */
316 tlds?: TopLevelDomainOptions | false;
317 /**
318 * Number of segments required for the domain. Be careful since some domains, such as `io`, directly allow email.
319 *
320 * @default 2
321 */
322 minDomainSegments?: number;
323 /**
324 * The maximum number of domain segments (e.g. `x.y.z` has 3 segments) allowed. Defaults to no limit.
325 *
326 * @default Infinity
327 */
328 maxDomainSegments?: number;
329 }
330
331 interface DomainOptions {
332 /**
333 * if `true`, domains ending with a `.` character are permitted
334 *
335 * @default false
336 */
337 allowFullyQualified?: boolean;
338 /**
339 * If `true`, Unicode characters are permitted
340 *
341 * @default true
342 */
343 allowUnicode?: boolean;
344
345 /**
346 * Options for TLD (top level domain) validation. By default, the TLD must be a valid name listed on the [IANA registry](http://data.iana.org/TLD/tlds-alpha-by-domain.txt)
347 *
348 * @default { allow: true }
349 */
350 tlds?: TopLevelDomainOptions | false;
351 /**
352 * Number of segments required for the domain.
353 *
354 * @default 2
355 */
356 minDomainSegments?: number;
357 /**
358 * The maximum number of domain segments (e.g. `x.y.z` has 3 segments) allowed. Defaults to no limit.
359 *
360 * @default Infinity
361 */
362 maxDomainSegments?: number;
363 }
364
365 interface HexOptions {
366 /**
367 * hex decoded representation must be byte aligned.
368 * @default false
369 */
370 byteAligned?: boolean;
371 /**
372 * controls whether the prefix `0x` or `0X` is allowed (or required) on hex strings.
373 * When `true`, the prefix must be provided.
374 * When `false`, the prefix is forbidden.
375 * When `optional`, the prefix is allowed but not required.
376 *
377 * @default false
378 */
379 prefix?: boolean | 'optional';
380 }
381
382 interface IpOptions {
383 /**
384 * One or more IP address versions to validate against. Valid values: ipv4, ipv6, ipvfuture
385 */
386 version?: string | string[];
387 /**
388 * Used to determine if a CIDR is allowed or not. Valid values: optional, required, forbidden
389 */
390 cidr?: PresenceMode;
391 }
392
393 type GuidVersions = 'uuidv1' | 'uuidv2' | 'uuidv3' | 'uuidv4' | 'uuidv5' | 'uuidv6' | 'uuidv7' | 'uuidv8';
394
395 interface GuidOptions {
396 version?: GuidVersions[] | GuidVersions;
397 separator?: boolean | '-' | ':';
398 }
399
400 interface UriOptions {
401 /**
402 * Specifies one or more acceptable Schemes, should only include the scheme name.
403 * Can be an Array or String (strings are automatically escaped for use in a Regular Expression).
404 */
405 scheme?: string | RegExp | Array<string | RegExp>;
406 /**
407 * Allow relative URIs.
408 *
409 * @default false
410 */
411 allowRelative?: boolean;
412 /**
413 * Restrict only relative URIs.
414 *
415 * @default false
416 */
417 relativeOnly?: boolean;
418 /**
419 * Allows unencoded square brackets inside the query string.
420 * This is NOT RFC 3986 compliant but query strings like abc[]=123&abc[]=456 are very common these days.
421 *
422 * @default false
423 */
424 allowQuerySquareBrackets?: boolean;
425 /**
426 * Validate the domain component using the options specified in `string.domain()`.
427 */
428 domain?: DomainOptions;
429 /**
430 * Encode URI before validation.
431 *
432 * @default false
433 */
434 encodeUri?: boolean;
435 }
436
437 interface DataUriOptions {
438 /**
439 * optional parameter defaulting to true which will require `=` padding if true or make padding optional if false
440 *
441 * @default true
442 */
443 paddingRequired?: boolean;
444 }
445
446 interface Base64Options extends Pick<DataUriOptions, 'paddingRequired'> {
447 /**
448 * if true, uses the URI-safe base64 format which replaces `+` with `-` and `\` with `_`.
449 *
450 * @default false
451 */
452 urlSafe?: boolean;
453 }
454
455 interface SwitchCases {
456 /**
457 * the required condition joi type.
458 */
459 is: SchemaLike;
460 /**
461 * the alternative schema type if the condition is true.
462 */
463 then: SchemaLike;
464 }
465
466 interface SwitchDefault {
467 /**
468 * the alternative schema type if no cases matched.
469 * Only one otherwise statement is allowed in switch as the last array item.
470 */
471 otherwise: SchemaLike;
472 }
473
474 interface WhenOptions {
475 /**
476 * the required condition joi type.
477 */
478 is?: SchemaLike;
479
480 /**
481 * the negative version of `is` (`then` and `otherwise` have reverse
482 * roles).
483 */
484 not?: SchemaLike;
485
486 /**
487 * the alternative schema type if the condition is true. Required if otherwise or switch are missing.
488 */
489 then?: SchemaLike;
490
491 /**
492 * the alternative schema type if the condition is false. Required if then or switch are missing.
493 */
494 otherwise?: SchemaLike;
495
496 /**
497 * the list of cases. Required if then is missing. Required if then or otherwise are missing.
498 */
499 switch?: Array<SwitchCases | SwitchDefault>;
500
501 /**
502 * whether to stop applying further conditions if the condition is true.
503 */
504 break?: boolean;
505 }
506
507 interface WhenSchemaOptions {
508 /**
509 * the alternative schema type if the condition is true. Required if otherwise is missing.
510 */
511 then?: SchemaLike;
512 /**
513 * the alternative schema type if the condition is false. Required if then is missing.
514 */
515 otherwise?: SchemaLike;
516 }
517
518 interface Cache {
519 /**
520 * Add an item to the cache.
521 *
522 * Note that key and value can be anything including objects, array, etc.
523 */
524 set(key: any, value: any): void;
525
526 /**
527 * Retrieve an item from the cache.
528 *
529 * Note that key and value can be anything including objects, array, etc.
530 */
531 get(key: any): any;
532 }
533 interface CacheProvisionOptions {
534 /**
535 * number of items to store in the cache before the least used items are dropped.
536 *
537 * @default 1000
538 */
539 max: number;
540 }
541
542 interface CacheConfiguration {
543 /**
544 * Provisions a simple LRU cache for caching simple inputs (`undefined`, `null`, strings, numbers, and booleans).
545 */
546 provision(options?: CacheProvisionOptions): void;
547 }
548
549 interface CompileOptions {
550 /**
551 * If true and the provided schema is (or contains parts) using an older version of joi, will return a compiled schema that is compatible with the older version.
552 * If false, the schema is always compiled using the current version and if older schema components are found, an error is thrown.
553 */
554 legacy: boolean;
555 }
556
557 interface IsSchemaOptions {
558 /**
559 * If true, will identify schemas from older versions of joi, otherwise will throw an error.
560 *
561 * @default false
562 */
563 legacy: boolean;
564 }
565
566 interface ReferenceOptions extends HierarchySeparatorOptions {
567 /**
568 * a function with the signature `function(value)` where `value` is the resolved reference value and the return value is the adjusted value to use.
569 * Note that the adjust feature will not perform any type validation on the adjusted value and it must match the value expected by the rule it is used in.
570 * Cannot be used with `map`.
571 *
572 * @example `(value) => value + 5`
573 */
574 adjust?: (value: any) => any;
575
576 /**
577 * an array of array pairs using the format `[[key, value], [key, value]]` used to maps the resolved reference value to another value.
578 * If the resolved value is not in the map, it is returned as-is.
579 * Cannot be used with `adjust`.
580 */
581 map?: Array<[any, any]>;
582
583 /**
584 * overrides default prefix characters.
585 */
586 prefix?: {
587 /**
588 * references to the globally provided context preference.
589 *
590 * @default '$'
591 */
592 global?: string;
593
594 /**
595 * references to error-specific or rule specific context.
596 *
597 * @default '#'
598 */
599 local?: string;
600
601 /**
602 * references to the root value being validated.
603 *
604 * @default '/'
605 */
606 root?: string;
607 };
608
609 /**
610 * If set to a number, sets the reference relative starting point.
611 * Cannot be combined with separator prefix characters.
612 * Defaults to the reference key prefix (or 1 if none present)
613 */
614 ancestor?: number;
615
616 /**
617 * creates an in-reference.
618 */
619 in?: boolean;
620
621 /**
622 * when true, the reference resolves by reaching into maps and sets.
623 */
624 iterables?: boolean;
625
626 /**
627 * when true, the value of the reference is used instead of its name in error messages
628 * and template rendering. Defaults to false.
629 */
630 render?: boolean;
631 }
632
633 interface StringRegexOptions {
634 /**
635 * optional pattern name.
636 */
637 name?: string;
638
639 /**
640 * when true, the provided pattern will be disallowed instead of required.
641 *
642 * @default false
643 */
644 invert?: boolean;
645 }
646
647 interface RuleOptions {
648 /**
649 * if true, the rules will not be replaced by the same unique rule later.
650 *
651 * For example, `Joi.number().min(1).rule({ keep: true }).min(2)` will keep both `min()` rules instead of the later rule overriding the first.
652 *
653 * @default false
654 */
655 keep?: boolean;
656
657 /**
658 * a single message string or a messages object where each key is an error code and corresponding message string as value.
659 *
660 * The object is the same as the messages used as an option in `any.validate()`.
661 * The strings can be plain messages or a message template.
662 */
663 message?: string | LanguageMessages;
664
665 /**
666 * if true, turns any error generated by the ruleset to warnings.
667 */
668 warn?: boolean;
669 }
670
671 interface ErrorReport extends Error {
672 code: string;
673 flags: Record<string, ExtensionFlag>;
674 path: string[];
675 prefs: ErrorValidationOptions;
676 messages: LanguageMessages;
677 state: State;
678 value: any;
679 local: any;
680 }
681
682 interface ValidationError extends Error {
683 name: 'ValidationError';
684
685 isJoi: boolean;
686
687 /**
688 * array of errors.
689 */
690 details: ValidationErrorItem[];
691
692 /**
693 * function that returns a string with an annotated version of the object pointing at the places where errors occurred.
694 *
695 * NOTE: This method does not exist in browser builds of Joi
696 *
697 * @param stripColors - if truthy, will strip the colors out of the output.
698 */
699 annotate(stripColors?: boolean): string;
700
701 _original: any;
702 }
703
704 interface ValidationErrorItem {
705 message: string;
706 path: Array<string | number>;
707 type: string;
708 context?: Context;
709 }
710
711 type ValidationErrorFunction = (errors: ErrorReport[]) => string | ValidationErrorItem | Error | ErrorReport[];
712
713 interface ValidationWarning {
714 message: string;
715
716 details: ValidationErrorItem[];
717 }
718
719 type ValidationResult<TSchema = any> = {
720 error: undefined;
721 warning?: ValidationError;
722 value: TSchema;
723 } | {
724 error: ValidationError;
725 warning?: ValidationError;
726 value: any;
727 }
728
729 interface CreateErrorOptions {
730 flags?: boolean;
731 messages?: LanguageMessages;
732 }
733
734 interface ModifyOptions {
735 each?: boolean;
736 once?: boolean;
737 ref?: boolean;
738 schema?: boolean;
739 }
740
741 interface MutateRegisterOptions {
742 family?: any;
743 key?: any;
744 }
745
746 interface SetFlagOptions {
747 clone: boolean;
748 }
749
750 interface CustomHelpers<V = any> {
751 schema: ExtensionBoundSchema;
752 state: State;
753 prefs: ValidationOptions;
754 original: V;
755 warn: (code: string, local?: Context) => void;
756 error: (code: string, local?: Context, localState?: State) => ErrorReport;
757 message: (messages: LanguageMessages, local?: Context) => ErrorReport;
758 }
759
760 type CustomValidator<V = any, R = V> = (value: V, helpers: CustomHelpers<R>) => R | ErrorReport;
761
762 interface ExternalHelpers<V = any> {
763 schema: ExtensionBoundSchema;
764 linked: ExtensionBoundSchema | null;
765 state: State;
766 prefs: ValidationOptions;
767 original: V;
768 warn: (code: string, local?: Context) => void;
769 error: (code: string, local?: Context) => ErrorReport;
770 message: (messages: LanguageMessages, local?: Context) => ErrorReport;
771 }
772
773 type ExternalValidationFunction<V = any, R = V> = (value: V, helpers: ExternalHelpers<R>) => R | undefined;
774
775 type SchemaLikeWithoutArray = string | number | boolean | null | Schema | SchemaMap;
776 type SchemaLike = SchemaLikeWithoutArray | object;
777
778 type NullableType<T> = undefined | null | T
779
780 type IsPrimitiveSubset<T> =
781 [T] extends [string]
782 ? true
783 : [T] extends [number]
784 ? true
785 : [T] extends [bigint]
786 ? true
787 : [T] extends [boolean]
788 ? true
789 : [T] extends [symbol]
790 ? true
791 : [T] extends [null]
792 ? true
793 : [T] extends [undefined]
794 ? true
795 : false;
796
797 type IsUnion<T, U extends T = T> =
798 T extends unknown ? [U] extends [T] ? false : true : false;
799
800 type IsNonPrimitiveSubsetUnion<T> = true extends IsUnion<T> ? true extends IsPrimitiveSubset<T> ? false : true : false;
801
802 type ObjectPropertiesSchema<T = any> =
803 true extends IsNonPrimitiveSubsetUnion<Exclude<T, undefined | null>>
804 ? Joi.AlternativesSchema
805 : T extends NullableType<string>
806 ? Joi.StringSchema
807 : T extends NullableType<number>
808 ? Joi.NumberSchema
809 : T extends NullableType<bigint>
810 ? Joi.NumberSchema
811 : T extends NullableType<boolean>
812 ? Joi.BooleanSchema
813 : T extends NullableType<Date>
814 ? Joi.DateSchema
815 : T extends NullableType<Buffer>
816 ? Joi.BinarySchema
817 : T extends NullableType<Array<any>>
818 ? Joi.ArraySchema
819 : T extends NullableType<object>
820 ? (StrictSchemaMap<T> | ObjectSchema<T>)
821 : never
822
823 type PartialSchemaMap<TSchema = any> = {
824 [key in keyof TSchema]?: SchemaLike | SchemaLike[];
825 }
826
827 type StrictSchemaMap<TSchema = any> = {
828 [key in keyof TSchema]-?: ObjectPropertiesSchema<TSchema[key]>
829 };
830
831 type SchemaMap<TSchema = any, isStrict = false> = isStrict extends true ? StrictSchemaMap<TSchema> : PartialSchemaMap<TSchema>
832
833 type Schema<P = any> =
834 | AnySchema<P>
835 | ArraySchema<P>
836 | AlternativesSchema<P>
837 | BinarySchema<P>
838 | BooleanSchema<P>
839 | DateSchema<P>
840 | FunctionSchema<P>
841 | NumberSchema<P>
842 | ObjectSchema<P>
843 | StringSchema<P>
844 | LinkSchema<P>
845 | SymbolSchema<P>;
846
847 type SchemaFunction = (schema: Schema) => Schema;
848
849 interface AddRuleOptions {
850 name: string;
851 args?: {
852 [key: string]: any;
853 };
854 }
855
856 interface GetRuleOptions {
857 args?: Record<string, any>;
858 method?: string;
859 name: string;
860 operator?: string;
861 }
862
863 interface SchemaInternals {
864 /**
865 * Parent schema object.
866 */
867 $_super: Schema;
868
869 /**
870 * Terms of current schema.
871 */
872 $_terms: Record<string, any>;
873
874 /**
875 * Adds a rule to current validation schema.
876 */
877 $_addRule(rule: string | AddRuleOptions): Schema;
878
879 /**
880 * Internally compiles schema.
881 */
882 $_compile(schema: SchemaLike, options?: CompileOptions): Schema;
883
884 /**
885 * Creates a joi error object.
886 */
887 $_createError(
888 code: string,
889 value: any,
890 context: Context,
891 state: State,
892 prefs: ValidationOptions,
893 options?: CreateErrorOptions,
894 ): Err;
895
896 /**
897 * Get value from given flag.
898 */
899 $_getFlag(name: string): any;
900
901 /**
902 * Retrieve some rule configuration.
903 */
904 $_getRule(name: string): GetRuleOptions | undefined;
905
906 $_mapLabels(path: string | string[]): string;
907
908 /**
909 * Returns true if validations runs fine on given value.
910 */
911 $_match(value: any, state: State, prefs: ValidationOptions): boolean;
912
913 $_modify(options?: ModifyOptions): Schema;
914
915 /**
916 * Resets current schema.
917 */
918 $_mutateRebuild(): this;
919
920 $_mutateRegister(schema: Schema, options?: MutateRegisterOptions): void;
921
922 /**
923 * Get value from given property.
924 */
925 $_property(name: string): any;
926
927 /**
928 * Get schema at given path.
929 */
930 $_reach(path: string[]): Schema;
931
932 /**
933 * Get current schema root references.
934 */
935 $_rootReferences(): any;
936
937 /**
938 * Set flag to given value.
939 */
940 $_setFlag(flag: string, value: any, options?: SetFlagOptions): void;
941
942 /**
943 * Runs internal validations against given value.
944 */
945 $_validate(value: any, state: State, prefs: ValidationOptions): ValidationResult;
946 }
947
948 interface AnySchema<TSchema = any> extends SchemaInternals {
949 /**
950 * Flags of current schema.
951 */
952 _flags: Record<string, any>;
953
954 /**
955 * Starts a ruleset in order to apply multiple rule options. The set ends when `rule()`, `keep()`, `message()`, or `warn()` is called.
956 */
957 $: this;
958
959 /**
960 * Starts a ruleset in order to apply multiple rule options. The set ends when `rule()`, `keep()`, `message()`, or `warn()` is called.
961 */
962 ruleset: this;
963
964 type?: Types | string;
965
966 /**
967 * Whitelists a value
968 */
969 allow(...values: any[]): this;
970
971 /**
972 * Assign target alteration options to a schema that are applied when `any.tailor()` is called.
973 * @param targets - an object where each key is a target name, and each value is a function that takes an schema and returns an schema.
974 */
975 alter(targets: Record<string, (schema: this) => Schema>): this;
976
977 /**
978 * Assigns the schema an artifact id which is included in the validation result if the rule passed validation.
979 * @param id - any value other than undefined which will be returned as-is in the result artifacts map.
980 */
981 artifact(id: any): this;
982
983 /**
984 * By default, some Joi methods to function properly need to rely on the Joi instance they are attached to because
985 * they use `this` internally.
986 * So `Joi.string()` works but if you extract the function from it and call `string()` it won't.
987 * `bind()` creates a new Joi instance where all the functions relying on `this` are bound to the Joi instance.
988 */
989 bind(): this;
990
991 /**
992 * Adds caching to the schema which will attempt to cache the validation results (success and failures) of incoming inputs.
993 * If no cache is passed, a default cache is provisioned by using `cache.provision()` internally.
994 */
995 cache(cache?: Cache): this;
996
997 /**
998 * Casts the validated value to the specified type.
999 */
1000 cast(to: 'map' | 'number' | 'set' | 'string'): this;
1001
1002 /**
1003 * Returns a new type that is the result of adding the rules of one type to another.
1004 */
1005 concat(schema: this): this;
1006
1007 /**
1008 * Adds a custom validation function.
1009 */
1010 custom(fn: CustomValidator, description?: string): this;
1011
1012 /**
1013 * Sets a default value if the original value is `undefined` where:
1014 * @param value - the default value. One of:
1015 * - a literal value (string, number, object, etc.)
1016 * - a [references](#refkey-options)
1017 * - a function which returns the default value using the signature `function(parent, helpers)` where:
1018 * - `parent` - a clone of the object containing the value being validated. Note that since specifying a
1019 * `parent` argument performs cloning, do not declare format arguments if you are not using them.
1020 * - `helpers` - same as those described in [`any.custom()`](anycustomermethod_description)
1021 *
1022 * When called without any `value` on an object schema type, a default value will be automatically generated
1023 * based on the default values of the object keys.
1024 *
1025 * Note that if value is an object, any changes to the object after `default()` is called will change the
1026 * reference and any future assignment.
1027 */
1028 default(value?: BasicType | Reference | ((parent: any, helpers: CustomHelpers) => BasicType | Reference)): this;
1029
1030 /**
1031 * Returns a plain object representing the schema's rules and properties
1032 */
1033 describe(): Description;
1034
1035 /**
1036 * Annotates the key
1037 */
1038 description(desc: string): this;
1039
1040 /**
1041 * Disallows values.
1042 */
1043 disallow(...values: any[]): this;
1044
1045 /**
1046 * Considers anything that matches the schema to be empty (undefined).
1047 * @param schema - any object or joi schema to match. An undefined schema unsets that rule.
1048 */
1049 empty(schema?: SchemaLike): this;
1050
1051 /**
1052 * Adds the provided values into the allowed whitelist and marks them as the only valid values allowed.
1053 */
1054 equal(...values: any[]): this;
1055
1056 /**
1057 * Overrides the default joi error with a custom error if the rule fails where:
1058 * @param err - can be:
1059 * an instance of `Error` - the override error.
1060 * a `function(errors)`, taking an array of errors as argument, where it must either:
1061 * return a `string` - substitutes the error message with this text
1062 * return a single ` object` or an `Array` of it, where:
1063 * `type` - optional parameter providing the type of the error (eg. `number.min`).
1064 * `message` - optional parameter if `template` is provided, containing the text of the error.
1065 * `template` - optional parameter if `message` is provided, containing a template string, using the same format as usual joi language errors.
1066 * `context` - optional parameter, to provide context to your error if you are using the `template`.
1067 * return an `Error` - same as when you directly provide an `Error`, but you can customize the error message based on the errors.
1068 *
1069 * Note that if you provide an `Error`, it will be returned as-is, unmodified and undecorated with any of the
1070 * normal joi error properties. If validation fails and another error is found before the error
1071 * override, that error will be returned and the override will be ignored (unless the `abortEarly`
1072 * option has been set to `false`).
1073 */
1074 error(err: Error | ValidationErrorFunction): this;
1075
1076 /**
1077 * Annotates the key with an example value, must be valid.
1078 */
1079 example(value: any, options?: { override: boolean }): this;
1080
1081 /**
1082 * Marks a key as required which will not allow undefined as value. All keys are optional by default.
1083 */
1084 exist(): this;
1085
1086 /**
1087 * Adds an external validation rule.
1088 *
1089 * Note that external validation rules are only called after the all other validation rules for the entire schema (from the value root) are checked.
1090 * This means that any changes made to the value by the external rules are not available to any other validation rules during the non-external validation phase.
1091 * If schema validation failed, no external validation rules are called.
1092 */
1093 external(method: ExternalValidationFunction, description?: string): this;
1094
1095 /**
1096 * Returns a sub-schema based on a path of object keys or schema ids.
1097 *
1098 * @param path - a dot `.` separated path string or a pre-split array of path keys. The keys must match the sub-schema id or object key (if no id was explicitly set).
1099 */
1100 extract(path: string | string[]): Schema;
1101
1102 /**
1103 * Sets a failover value if the original value fails passing validation.
1104 *
1105 * @param value - the failover value. value supports references. value may be assigned a function which returns the default value.
1106 *
1107 * If value is specified as a function that accepts a single parameter, that parameter will be a context object that can be used to derive the resulting value.
1108 * Note that if value is an object, any changes to the object after `failover()` is called will change the reference and any future assignment.
1109 * Use a function when setting a dynamic value (e.g. the current time).
1110 * Using a function with a single argument performs some internal cloning which has a performance impact.
1111 * If you do not need access to the context, define the function without any arguments.
1112 */
1113 failover(value: any): this;
1114
1115 /**
1116 * Marks a key as forbidden which will not allow any value except undefined. Used to explicitly forbid keys.
1117 */
1118 forbidden(): this;
1119
1120 /**
1121 * Returns a new schema where each of the path keys listed have been modified.
1122 *
1123 * @param key - an array of key strings, a single key string, or an array of arrays of pre-split key strings.
1124 * @param adjuster - a function which must return a modified schema.
1125 */
1126 fork(key: string | string[] | string[][], adjuster: SchemaFunction): this;
1127
1128 /**
1129 * Sets a schema id for reaching into the schema via `any.extract()`.
1130 * If no id is set, the schema id defaults to the object key it is associated with.
1131 * If the schema is used in an array or alternatives type and no id is set, the schema in unreachable.
1132 */
1133 id(name?: string): this;
1134
1135 /**
1136 * Disallows values.
1137 */
1138 invalid(...values: any[]): this;
1139
1140 /**
1141 * Same as `rule({ keep: true })`.
1142 *
1143 * Note that `keep()` will terminate the current ruleset and cannot be followed by another rule option.
1144 * Use `rule()` to apply multiple rule options.
1145 */
1146 keep(): this;
1147
1148 /**
1149 * Overrides the key name in error messages.
1150 */
1151 label(name: string): this;
1152
1153 /**
1154 * Same as `rule({ message })`.
1155 *
1156 * Note that `message()` will terminate the current ruleset and cannot be followed by another rule option.
1157 * Use `rule()` to apply multiple rule options.
1158 */
1159 message(message: string): this;
1160
1161 /**
1162 * Same as `any.prefs({ messages })`.
1163 * Note that while `any.message()` applies only to the last rule or ruleset, `any.messages()` applies to the entire schema.
1164 */
1165 messages(messages: LanguageMessages): this;
1166
1167 /**
1168 * Attaches metadata to the key.
1169 */
1170 meta(meta: object): this;
1171
1172 /**
1173 * Disallows values.
1174 */
1175 not(...values: any[]): this;
1176
1177 /**
1178 * Annotates the key
1179 */
1180 note(...notes: string[]): this;
1181
1182 /**
1183 * Requires the validated value to match of the provided `any.allow()` values.
1184 * It has not effect when called together with `any.valid()` since it already sets the requirements.
1185 * When used with `any.allow()` it converts it to an `any.valid()`.
1186 */
1187 only(): this;
1188
1189 /**
1190 * Marks a key as optional which will allow undefined as values. Used to annotate the schema for readability as all keys are optional by default.
1191 */
1192 optional(): this;
1193
1194 /**
1195 * Overrides the global validate() options for the current key and any sub-key.
1196 */
1197 options(options: ValidationOptions): this;
1198
1199 /**
1200 * Overrides the global validate() options for the current key and any sub-key.
1201 */
1202 prefs(options: ValidationOptions): this;
1203
1204 /**
1205 * Overrides the global validate() options for the current key and any sub-key.
1206 */
1207 preferences(options: ValidationOptions): this;
1208
1209 /**
1210 * Sets the presence mode for the schema.
1211 */
1212 presence(mode: PresenceMode): this;
1213
1214 /**
1215 * Outputs the original untouched value instead of the casted value.
1216 */
1217 raw(enabled?: boolean): this;
1218
1219 /**
1220 * Marks a key as required which will not allow undefined as value. All keys are optional by default.
1221 */
1222 required(): this;
1223
1224 /**
1225 * Applies a set of rule options to the current ruleset or last rule added.
1226 *
1227 * When applying rule options, the last rule (e.g. `min()`) is used unless there is an active ruleset defined (e.g. `$.min().max()`)
1228 * in which case the options are applied to all the provided rules.
1229 * Once `rule()` is called, the previous rules can no longer be modified and any active ruleset is terminated.
1230 *
1231 * Rule modifications can only be applied to supported rules.
1232 * Most of the `any` methods do not support rule modifications because they are implemented using schema flags (e.g. `required()`) or special
1233 * internal implementation (e.g. `valid()`).
1234 * In those cases, use the `any.messages()` method to override the error codes for the errors you want to customize.
1235 */
1236 rule(options: RuleOptions): this;
1237
1238 /**
1239 * Registers a schema to be used by descendants of the current schema in named link references.
1240 */
1241 shared(ref: Schema): this;
1242
1243 /**
1244 * Sets the options.convert options to false which prevent type casting for the current key and any child keys.
1245 */
1246 strict(isStrict?: boolean): this;
1247
1248 /**
1249 * Marks a key to be removed from a resulting object or array after validation. Used to sanitize output.
1250 * @param [enabled=true] - if true, the value is stripped, otherwise the validated value is retained. Defaults to true.
1251 */
1252 strip(enabled?: boolean): this;
1253
1254 /**
1255 * Annotates the key
1256 */
1257 tag(...tags: string[]): this;
1258
1259 /**
1260 * Applies any assigned target alterations to a copy of the schema that were applied via `any.alter()`.
1261 */
1262 tailor(targets: string | string[]): Schema;
1263
1264 /**
1265 * Annotates the key with an unit name.
1266 */
1267 unit(name: string): this;
1268
1269 /**
1270 * Adds the provided values into the allowed whitelist and marks them as the only valid values allowed.
1271 */
1272 valid(...values: any[]): this;
1273
1274 /**
1275 * Validates a value using the schema and options.
1276 */
1277 validate(value: any, options?: ValidationOptions): ValidationResult<TSchema>;
1278
1279 /**
1280 * Validates a value using the schema and options.
1281 */
1282 validateAsync<TOpts extends AsyncValidationOptions>(
1283 value: any,
1284 options?: TOpts
1285 ): Promise<
1286 TOpts extends { artifacts: true } | { warnings: true }
1287 ? { value: TSchema } & (TOpts extends { artifacts: true }
1288 ? { artifacts: Map<any, string[][]> }
1289 : {}) &
1290 (TOpts extends { warnings: true }
1291 ? { warning: ValidationWarning }
1292 : {})
1293 : TSchema
1294 >;
1295
1296 /**
1297 * Same as `rule({ warn: true })`.
1298 * Note that `warn()` will terminate the current ruleset and cannot be followed by another rule option.
1299 * Use `rule()` to apply multiple rule options.
1300 */
1301 warn(): this;
1302
1303 /**
1304 * Generates a warning.
1305 * When calling `any.validateAsync()`, set the `warning` option to true to enable warnings.
1306 * Warnings are reported separately from errors alongside the result value via the warning key (i.e. `{ value, warning }`).
1307 * Warning are always included when calling `any.validate()`.
1308 */
1309 warning(code: string, context: Context): this;
1310
1311 /**
1312 * Converts the type into an alternatives type where the conditions are merged into the type definition where:
1313 */
1314 when(ref: string | Reference, options: WhenOptions | WhenOptions[]): this;
1315
1316 /**
1317 * Converts the type into an alternatives type where the conditions are merged into the type definition where:
1318 */
1319 when(ref: Schema, options: WhenSchemaOptions): this;
1320 }
1321
1322 interface Description {
1323 type?: Types | string;
1324 label?: string;
1325 description?: string;
1326 flags?: object;
1327 notes?: string[];
1328 tags?: string[];
1329 metas?: any[];
1330 example?: any[];
1331 valids?: any[];
1332 invalids?: any[];
1333 unit?: string;
1334 options?: ValidationOptions;
1335 [key: string]: any;
1336 }
1337
1338 interface Context {
1339 [key: string]: any;
1340 key?: string;
1341 label?: string;
1342 value?: any;
1343 }
1344
1345 interface State {
1346 key?: string;
1347 path?: (string | number)[];
1348 parent?: any;
1349 reference?: any;
1350 ancestors?: any;
1351 localize?(...args: any[]): State;
1352 }
1353
1354 interface BooleanSchema<TSchema = boolean> extends AnySchema<TSchema> {
1355 /**
1356 * Allows for additional values to be considered valid booleans by converting them to false during validation.
1357 * String comparisons are by default case insensitive,
1358 * see `boolean.sensitive()` to change this behavior.
1359 * @param values - strings, numbers or arrays of them
1360 */
1361 falsy(...values: Array<string | number | null>): this;
1362
1363 /**
1364 * Allows the values provided to truthy and falsy as well as the "true" and "false" default conversion
1365 * (when not in `strict()` mode) to be matched in a case insensitive manner.
1366 */
1367 sensitive(enabled?: boolean): this;
1368
1369 /**
1370 * Allows for additional values to be considered valid booleans by converting them to true during validation.
1371 * String comparisons are by default case insensitive, see `boolean.sensitive()` to change this behavior.
1372 * @param values - strings, numbers or arrays of them
1373 */
1374 truthy(...values: Array<string | number | null>): this;
1375 }
1376
1377 interface NumberSchema<TSchema = number> extends AnySchema<TSchema> {
1378 /**
1379 * Specifies that the value must be greater than limit.
1380 * It can also be a reference to another field.
1381 */
1382 greater(limit: number | Reference): this;
1383
1384 /**
1385 * Requires the number to be an integer (no floating point).
1386 */
1387 integer(): this;
1388
1389 /**
1390 * Specifies that the value must be less than limit.
1391 * It can also be a reference to another field.
1392 */
1393 less(limit: number | Reference): this;
1394
1395 /**
1396 * Specifies the maximum value.
1397 * It can also be a reference to another field.
1398 */
1399 max(limit: number | Reference): this;
1400
1401 /**
1402 * Specifies the minimum value.
1403 * It can also be a reference to another field.
1404 */
1405 min(limit: number | Reference): this;
1406
1407 /**
1408 * Specifies that the value must be a multiple of base.
1409 */
1410 multiple(base: number | Reference): this;
1411
1412 /**
1413 * Requires the number to be negative.
1414 */
1415 negative(): this;
1416
1417 /**
1418 * Requires the number to be a TCP port, so between 0 and 65535.
1419 */
1420 port(): this;
1421
1422 /**
1423 * Requires the number to be positive.
1424 */
1425 positive(): this;
1426
1427 /**
1428 * Specifies the maximum number of decimal places where:
1429 * @param limit - the maximum number of decimal places allowed.
1430 */
1431 precision(limit: number): this;
1432
1433 /**
1434 * Requires the number to be negative or positive.
1435 */
1436 sign(sign: 'positive' | 'negative'): this;
1437
1438 /**
1439 * Allows the number to be outside of JavaScript's safety range (Number.MIN_SAFE_INTEGER & Number.MAX_SAFE_INTEGER).
1440 */
1441 unsafe(enabled?: any): this;
1442 }
1443
1444 interface StringSchema<TSchema = string> extends AnySchema<TSchema> {
1445 /**
1446 * Requires the string value to only contain a-z, A-Z, and 0-9.
1447 */
1448 alphanum(): this;
1449
1450 /**
1451 * Requires the string value to be a valid base64 string; does not check the decoded value.
1452 */
1453 base64(options?: Base64Options): this;
1454
1455 /**
1456 * Sets the required string case.
1457 */
1458 case(direction: 'upper' | 'lower'): this;
1459
1460 /**
1461 * Requires the number to be a credit card number (Using Luhn Algorithm).
1462 */
1463 creditCard(): this;
1464
1465 /**
1466 * Requires the string value to be a valid data URI string.
1467 */
1468 dataUri(options?: DataUriOptions): this;
1469
1470 /**
1471 * Requires the string value to be a valid domain.
1472 */
1473 domain(options?: DomainOptions): this;
1474
1475 /**
1476 * Requires the string value to be a valid email address.
1477 */
1478 email(options?: EmailOptions): this;
1479
1480 /**
1481 * Requires the string value to be a valid GUID.
1482 */
1483 guid(options?: GuidOptions): this;
1484
1485 /**
1486 * Requires the string value to be a valid hexadecimal string.
1487 */
1488 hex(options?: HexOptions): this;
1489
1490 /**
1491 * Requires the string value to be a valid hostname as per RFC1123.
1492 */
1493 hostname(): this;
1494
1495 /**
1496 * Allows the value to match any whitelist of blacklist item in a case insensitive comparison.
1497 */
1498 insensitive(): this;
1499
1500 /**
1501 * Requires the string value to be a valid ip address.
1502 */
1503 ip(options?: IpOptions): this;
1504
1505 /**
1506 * Requires the string value to be in valid ISO 8601 date format.
1507 */
1508 isoDate(): this;
1509
1510 /**
1511 * Requires the string value to be in valid ISO 8601 duration format.
1512 */
1513 isoDuration(): this;
1514
1515 /**
1516 * Specifies the exact string length required
1517 * @param limit - the required string length. It can also be a reference to another field.
1518 * @param encoding - if specified, the string length is calculated in bytes using the provided encoding.
1519 */
1520 length(limit: number | Reference, encoding?: string): this;
1521
1522 /**
1523 * Requires the string value to be all lowercase. If the validation convert option is on (enabled by default), the string will be forced to lowercase.
1524 */
1525 lowercase(): this;
1526
1527 /**
1528 * Specifies the maximum number of string characters.
1529 * @param limit - the maximum number of string characters allowed. It can also be a reference to another field.
1530 * @param encoding - if specified, the string length is calculated in bytes using the provided encoding.
1531 */
1532 max(limit: number | Reference, encoding?: string): this;
1533
1534 /**
1535 * Specifies the minimum number string characters.
1536 * @param limit - the minimum number of string characters required. It can also be a reference to another field.
1537 * @param encoding - if specified, the string length is calculated in bytes using the provided encoding.
1538 */
1539 min(limit: number | Reference, encoding?: string): this;
1540
1541 /**
1542 * Requires the string value to be in a unicode normalized form. If the validation convert option is on (enabled by default), the string will be normalized.
1543 * @param [form='NFC'] - The unicode normalization form to use. Valid values: NFC [default], NFD, NFKC, NFKD
1544 */
1545 normalize(form?: 'NFC' | 'NFD' | 'NFKC' | 'NFKD'): this;
1546
1547 /**
1548 * Defines a regular expression rule.
1549 * @param pattern - a regular expression object the string value must match against.
1550 * @param options - optional, can be:
1551 * Name for patterns (useful with multiple patterns). Defaults to 'required'.
1552 * An optional configuration object with the following supported properties:
1553 * name - optional pattern name.
1554 * invert - optional boolean flag. Defaults to false behavior. If specified as true, the provided pattern will be disallowed instead of required.
1555 */
1556 pattern(pattern: RegExp, options?: string | StringRegexOptions): this;
1557
1558 /**
1559 * Defines a regular expression rule.
1560 * @param pattern - a regular expression object the string value must match against.
1561 * @param options - optional, can be:
1562 * Name for patterns (useful with multiple patterns). Defaults to 'required'.
1563 * An optional configuration object with the following supported properties:
1564 * name - optional pattern name.
1565 * invert - optional boolean flag. Defaults to false behavior. If specified as true, the provided pattern will be disallowed instead of required.
1566 */
1567 regex(pattern: RegExp, options?: string | StringRegexOptions): this;
1568
1569 /**
1570 * Replace characters matching the given pattern with the specified replacement string where:
1571 * @param pattern - a regular expression object to match against, or a string of which all occurrences will be replaced.
1572 * @param replacement - the string that will replace the pattern.
1573 */
1574 replace(pattern: RegExp | string, replacement: string): this;
1575
1576 /**
1577 * Requires the string value to only contain a-z, A-Z, 0-9, and underscore _.
1578 */
1579 token(): this;
1580
1581 /**
1582 * Requires the string value to contain no whitespace before or after. If the validation convert option is on (enabled by default), the string will be trimmed.
1583 * @param [enabled=true] - optional parameter defaulting to true which allows you to reset the behavior of trim by providing a falsy value.
1584 */
1585 trim(enabled?: any): this;
1586
1587 /**
1588 * Specifies whether the string.max() limit should be used as a truncation.
1589 * @param [enabled=true] - optional parameter defaulting to true which allows you to reset the behavior of truncate by providing a falsy value.
1590 */
1591 truncate(enabled?: boolean): this;
1592
1593 /**
1594 * Requires the string value to be all uppercase. If the validation convert option is on (enabled by default), the string will be forced to uppercase.
1595 */
1596 uppercase(): this;
1597
1598 /**
1599 * Requires the string value to be a valid RFC 3986 URI.
1600 */
1601 uri(options?: UriOptions): this;
1602
1603 /**
1604 * Requires the string value to be a valid GUID.
1605 */
1606 uuid(options?: GuidOptions): this;
1607 }
1608
1609 interface SymbolSchema<TSchema = Symbol> extends AnySchema<TSchema> {
1610 // TODO: support number and symbol index
1611 map(iterable: Iterable<[string | number | boolean | symbol, symbol]> | { [key: string]: symbol }): this;
1612 }
1613
1614 interface ArraySortOptions {
1615 /**
1616 * @default 'ascending'
1617 */
1618 order?: 'ascending' | 'descending';
1619 by?: string | Reference;
1620 }
1621
1622 interface ArrayUniqueOptions extends HierarchySeparatorOptions {
1623 /**
1624 * if true, undefined values for the dot notation string comparator will not cause the array to fail on uniqueness.
1625 *
1626 * @default false
1627 */
1628 ignoreUndefined?: boolean;
1629 }
1630
1631 type ComparatorFunction = (a: any, b: any) => boolean;
1632
1633 interface ArraySchema<TSchema = any[]> extends AnySchema<TSchema> {
1634 /**
1635 * Verifies that an assertion passes for at least one item in the array, where:
1636 * `schema` - the validation rules required to satisfy the assertion. If the `schema` includes references, they are resolved against
1637 * the array item being tested, not the value of the `ref` target.
1638 */
1639 has(schema: SchemaLike): this;
1640
1641 /**
1642 * List the types allowed for the array values.
1643 * If a given type is .required() then there must be a matching item in the array.
1644 * If a type is .forbidden() then it cannot appear in the array.
1645 * Required items can be added multiple times to signify that multiple items must be found.
1646 * Errors will contain the number of items that didn't match.
1647 * Any unmatched item having a label will be mentioned explicitly.
1648 *
1649 * @param type - a joi schema object to validate each array item against.
1650 */
1651 items(...types: SchemaLikeWithoutArray[]): this;
1652
1653 /**
1654 * Specifies the exact number of items in the array.
1655 */
1656 length(limit: number | Reference): this;
1657
1658 /**
1659 * Specifies the maximum number of items in the array.
1660 */
1661 max(limit: number | Reference): this;
1662
1663 /**
1664 * Specifies the minimum number of items in the array.
1665 */
1666 min(limit: number | Reference): this;
1667
1668 /**
1669 * Lists the types in sequence order for the array values where:
1670 * @param type - a joi schema object to validate against each array item in sequence order. type can be multiple values passed as individual arguments.
1671 * If a given type is .required() then there must be a matching item with the same index position in the array.
1672 * Errors will contain the number of items that didn't match.
1673 * Any unmatched item having a label will be mentioned explicitly.
1674 */
1675 ordered(...types: SchemaLikeWithoutArray[]): this;
1676
1677 /**
1678 * Allow single values to be checked against rules as if it were provided as an array.
1679 * enabled can be used with a falsy value to go back to the default behavior.
1680 */
1681 single(enabled?: any): this;
1682
1683 /**
1684 * Sorts the array by given order.
1685 */
1686 sort(options?: ArraySortOptions): this;
1687
1688 /**
1689 * Allow this array to be sparse.
1690 * enabled can be used with a falsy value to go back to the default behavior.
1691 */
1692 sparse(enabled?: any): this;
1693
1694 /**
1695 * Requires the array values to be unique.
1696 * Remember that if you provide a custom comparator function,
1697 * different types can be passed as parameter depending on the rules you set on items.
1698 * Be aware that a deep equality is performed on elements of the array having a type of object,
1699 * a performance penalty is to be expected for this kind of operation.
1700 */
1701 unique(comparator?: string | ComparatorFunction, options?: ArrayUniqueOptions): this;
1702 }
1703
1704 interface ObjectPatternOptions {
1705 fallthrough?: boolean;
1706 matches: SchemaLike | Reference;
1707 }
1708
1709 interface ObjectSchema<TSchema = any> extends AnySchema<TSchema> {
1710 /**
1711 * Defines an all-or-nothing relationship between keys where if one of the peers is present, all of them are required as well.
1712 *
1713 * Optional settings must be the last argument.
1714 */
1715 and(...peers: Array<string | DependencyOptions>): this;
1716
1717 /**
1718 * Appends the allowed object keys. If schema is null, undefined, or {}, no changes will be applied.
1719 */
1720 append(schema?: SchemaMap<TSchema>): this;
1721 append<TSchemaExtended = any, T = TSchemaExtended>(schema?: SchemaMap<T>): ObjectSchema<T>
1722
1723 /**
1724 * Verifies an assertion where.
1725 */
1726 assert(ref: string | Reference, schema: SchemaLike, message?: string): this;
1727
1728 /**
1729 * Requires the object to be an instance of a given constructor.
1730 *
1731 * @param constructor - the constructor function that the object must be an instance of.
1732 * @param name - an alternate name to use in validation errors. This is useful when the constructor function does not have a name.
1733 */
1734 // tslint:disable-next-line:ban-types
1735 instance(constructor: Function, name?: string): this;
1736
1737 /**
1738 * Sets or extends the allowed object keys.
1739 */
1740 keys(schema?: SchemaMap<TSchema>): this;
1741
1742 /**
1743 * Specifies the exact number of keys in the object.
1744 */
1745 length(limit: number): this;
1746
1747 /**
1748 * Specifies the maximum number of keys in the object.
1749 */
1750 max(limit: number | Reference): this;
1751
1752 /**
1753 * Specifies the minimum number of keys in the object.
1754 */
1755 min(limit: number | Reference): this;
1756
1757 /**
1758 * Defines a relationship between keys where not all peers can be present at the same time.
1759 *
1760 * Optional settings must be the last argument.
1761 */
1762 nand(...peers: Array<string | DependencyOptions>): this;
1763
1764 /**
1765 * Defines a relationship between keys where one of the peers is required (and more than one is allowed).
1766 *
1767 * Optional settings must be the last argument.
1768 */
1769 or(...peers: Array<string | DependencyOptions>): this;
1770
1771 /**
1772 * Defines an exclusive relationship between a set of keys where only one is allowed but none are required.
1773 *
1774 * Optional settings must be the last argument.
1775 */
1776 oxor(...peers: Array<string | DependencyOptions>): this;
1777
1778 /**
1779 * Specify validation rules for unknown keys matching a pattern.
1780 *
1781 * @param pattern - a pattern that can be either a regular expression or a joi schema that will be tested against the unknown key names
1782 * @param schema - the schema object matching keys must validate against
1783 */
1784 pattern(pattern: RegExp | SchemaLike, schema: SchemaLike, options?: ObjectPatternOptions): this;
1785
1786 /**
1787 * Requires the object to be a Joi reference.
1788 */
1789 ref(): this;
1790
1791 /**
1792 * Requires the object to be a `RegExp` object.
1793 */
1794 regex(): this;
1795
1796 /**
1797 * Renames a key to another name (deletes the renamed key).
1798 */
1799 rename(from: string | RegExp, to: string, options?: RenameOptions): this;
1800
1801 /**
1802 * Requires the object to be a Joi schema instance.
1803 */
1804 schema(type?: SchemaLike): this;
1805
1806 /**
1807 * Overrides the handling of unknown keys for the scope of the current object only (does not apply to children).
1808 */
1809 unknown(allow?: boolean): this;
1810
1811 /**
1812 * Requires the presence of other keys whenever the specified key is present.
1813 */
1814 with(key: string, peers: string | string[], options?: DependencyOptions): this;
1815
1816 /**
1817 * Forbids the presence of other keys whenever the specified is present.
1818 */
1819 without(key: string, peers: string | string[], options?: DependencyOptions): this;
1820
1821 /**
1822 * Defines an exclusive relationship between a set of keys. one of them is required but not at the same time.
1823 *
1824 * Optional settings must be the last argument.
1825 */
1826 xor(...peers: Array<string | DependencyOptions>): this;
1827 }
1828
1829 interface BinarySchema<TSchema = Buffer> extends AnySchema<TSchema> {
1830 /**
1831 * Sets the string encoding format if a string input is converted to a buffer.
1832 */
1833 encoding(encoding: string): this;
1834
1835 /**
1836 * Specifies the minimum length of the buffer.
1837 */
1838 min(limit: number | Reference): this;
1839
1840 /**
1841 * Specifies the maximum length of the buffer.
1842 */
1843 max(limit: number | Reference): this;
1844
1845 /**
1846 * Specifies the exact length of the buffer:
1847 */
1848 length(limit: number | Reference): this;
1849 }
1850
1851 interface DateSchema<TSchema = Date> extends AnySchema<TSchema> {
1852 /**
1853 * Specifies that the value must be greater than date.
1854 * Notes: 'now' can be passed in lieu of date so as to always compare relatively to the current date,
1855 * allowing to explicitly ensure a date is either in the past or in the future.
1856 * It can also be a reference to another field.
1857 */
1858 greater(date: 'now' | Date | number | string | Reference): this;
1859
1860 /**
1861 * Requires the string value to be in valid ISO 8601 date format.
1862 */
1863 iso(): this;
1864
1865 /**
1866 * Specifies that the value must be less than date.
1867 * Notes: 'now' can be passed in lieu of date so as to always compare relatively to the current date,
1868 * allowing to explicitly ensure a date is either in the past or in the future.
1869 * It can also be a reference to another field.
1870 */
1871 less(date: 'now' | Date | number | string | Reference): this;
1872
1873 /**
1874 * Specifies the oldest date allowed.
1875 * Notes: 'now' can be passed in lieu of date so as to always compare relatively to the current date,
1876 * allowing to explicitly ensure a date is either in the past or in the future.
1877 * It can also be a reference to another field.
1878 */
1879 min(date: 'now' | Date | number | string | Reference): this;
1880
1881 /**
1882 * Specifies the latest date allowed.
1883 * Notes: 'now' can be passed in lieu of date so as to always compare relatively to the current date,
1884 * allowing to explicitly ensure a date is either in the past or in the future.
1885 * It can also be a reference to another field.
1886 */
1887 max(date: 'now' | Date | number | string | Reference): this;
1888
1889 /**
1890 * Requires the value to be a timestamp interval from Unix Time.
1891 * @param type - the type of timestamp (allowed values are unix or javascript [default])
1892 */
1893 timestamp(type?: 'javascript' | 'unix'): this;
1894 }
1895
1896 interface FunctionSchema<TSchema = Function> extends ObjectSchema<TSchema> {
1897 /**
1898 * Specifies the arity of the function where:
1899 * @param n - the arity expected.
1900 */
1901 arity(n: number): this;
1902
1903 /**
1904 * Requires the function to be a class.
1905 */
1906 class(): this;
1907
1908 /**
1909 * Specifies the minimal arity of the function where:
1910 * @param n - the minimal arity expected.
1911 */
1912 minArity(n: number): this;
1913
1914 /**
1915 * Specifies the minimal arity of the function where:
1916 * @param n - the minimal arity expected.
1917 */
1918 maxArity(n: number): this;
1919 }
1920
1921 interface AlternativesSchema<TSchema = any> extends AnySchema<TSchema> {
1922 /**
1923 * Adds a conditional alternative schema type, either based on another key value, or a schema peeking into the current value.
1924 */
1925 conditional(ref: string | Reference, options: WhenOptions | WhenOptions[]): this;
1926 conditional(ref: Schema, options: WhenSchemaOptions): this;
1927
1928 /**
1929 * Requires the validated value to match a specific set of the provided alternative.try() schemas.
1930 * Cannot be combined with `alternatives.conditional()`.
1931 */
1932 match(mode: 'any' | 'all' | 'one'): this;
1933
1934 /**
1935 * Adds an alternative schema type for attempting to match against the validated value.
1936 */
1937 try(...types: SchemaLikeWithoutArray[]): this;
1938 }
1939
1940 interface LinkSchema<TSchema = any> extends AnySchema<TSchema> {
1941 /**
1942 * Same as `any.concat()` but the schema is merged after the link is resolved which allows merging with schemas of the same type as the resolved link.
1943 * Will throw an exception during validation if the merged types are not compatible.
1944 */
1945 concat(schema: Schema): this;
1946
1947 /**
1948 * Initializes the schema after constructions for cases where the schema has to be constructed first and then initialized.
1949 * If `ref` was not passed to the constructor, `link.ref()` must be called prior to usage.
1950 */
1951 ref(ref: string): this;
1952 }
1953
1954 interface Reference extends Exclude<ReferenceOptions, 'prefix'> {
1955 depth: number;
1956 type: string;
1957 key: string;
1958 root: string;
1959 path: string[];
1960 display: string;
1961 toString(): string;
1962 }
1963
1964 type ExtensionBoundSchema = Schema & SchemaInternals;
1965
1966 interface RuleArgs {
1967 name: string;
1968 ref?: boolean;
1969 assert?: ((value: any) => boolean) | AnySchema;
1970 message?: string;
1971
1972 /**
1973 * Undocumented properties
1974 */
1975 normalize?(value: any): any;
1976 }
1977
1978 type RuleMethod = (...args: any[]) => any;
1979
1980 interface ExtensionRule {
1981 /**
1982 * alternative name for this rule.
1983 */
1984 alias?: string;
1985 /**
1986 * whether rule supports multiple invocations.
1987 */
1988 multi?: boolean;
1989 /**
1990 * Dual rule: converts or validates.
1991 */
1992 convert?: boolean;
1993 /**
1994 * list of arguments accepted by `method`.
1995 */
1996 args?: Array<RuleArgs | string>;
1997 /**
1998 * rule body.
1999 */
2000 method?: RuleMethod | false;
2001 /**
2002 * validation function.
2003 */
2004 validate?(value: any, helpers: any, args: Record<string, any>, options: any): any;
2005
2006 /**
2007 * undocumented flags.
2008 */
2009 priority?: boolean;
2010 manifest?: boolean;
2011 }
2012
2013 interface CoerceResult {
2014 errors?: ErrorReport[];
2015 value?: any;
2016 }
2017
2018 type CoerceFunction = (value: any, helpers: CustomHelpers) => CoerceResult;
2019
2020 interface CoerceObject {
2021 method: CoerceFunction;
2022 from?: string | string[];
2023 }
2024
2025 interface ExtensionFlag {
2026 setter?: string;
2027 default?: any;
2028 }
2029
2030 interface ExtensionTermManifest {
2031 mapped: {
2032 from: string;
2033 to: string;
2034 };
2035 }
2036
2037 interface ExtensionTerm {
2038 init: any[] | null;
2039 register?: any;
2040 manifest?: Record<string, 'schema' | 'single' | ExtensionTermManifest>;
2041 }
2042
2043 interface Extension {
2044 type: string | RegExp;
2045 args?(...args: SchemaLike[]): Schema;
2046 base?: Schema;
2047 coerce?: CoerceFunction | CoerceObject;
2048 flags?: Record<string, ExtensionFlag>;
2049 manifest?: {
2050 build?(obj: ExtensionBoundSchema, desc: Record<string, any>): any;
2051 };
2052 messages?: LanguageMessages | string;
2053 modifiers?: Record<string, (rule: any, enabled?: boolean) => any>;
2054 overrides?: Record<string, (value: any) => Schema>;
2055 prepare?(value: any, helpers: CustomHelpers): any;
2056 rebuild?(schema: ExtensionBoundSchema): void;
2057 rules?: Record<string, ExtensionRule & ThisType<SchemaInternals>>;
2058 terms?: Record<string, ExtensionTerm>;
2059 validate?(value: any, helpers: CustomHelpers): any;
2060
2061 /**
2062 * undocumented options
2063 */
2064 cast?: Record<string, { from(value: any): any; to(value: any, helpers: CustomHelpers): any }>;
2065 properties?: Record<string, any>;
2066 }
2067
2068 type ExtensionFactory = (joi: Root) => Extension;
2069
2070 interface Err {
2071 toString(): string;
2072 }
2073
2074 // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
2075
2076 interface Root {
2077 /**
2078 * Current version of the joi package.
2079 */
2080 version: string;
2081
2082 ValidationError: new (message: string, details: ValidationErrorItem[], original: any) => ValidationError;
2083
2084 /**
2085 * Generates a schema object that matches any data type.
2086 */
2087 any<TSchema = any>(): AnySchema<TSchema>;
2088
2089 /**
2090 * Generates a schema object that matches an array data type.
2091 */
2092 array<TSchema = any[]>(): ArraySchema<TSchema>;
2093
2094 /**
2095 * Generates a schema object that matches a boolean data type (as well as the strings 'true', 'false', 'yes', and 'no'). Can also be called via boolean().
2096 */
2097 bool<TSchema = boolean>(): BooleanSchema<TSchema>;
2098
2099 /**
2100 * Generates a schema object that matches a boolean data type (as well as the strings 'true', 'false', 'yes', and 'no'). Can also be called via bool().
2101 */
2102 boolean<TSchema = boolean>(): BooleanSchema<TSchema>;
2103
2104 /**
2105 * Generates a schema object that matches a Buffer data type (as well as the strings which will be converted to Buffers).
2106 */
2107 binary<TSchema = Buffer>(): BinarySchema<TSchema>;
2108
2109 /**
2110 * Generates a schema object that matches a date type (as well as a JavaScript date string or number of milliseconds).
2111 */
2112 date<TSchema = Date>(): DateSchema<TSchema>;
2113
2114 /**
2115 * Generates a schema object that matches a function type.
2116 */
2117 func<TSchema = Function>(): FunctionSchema<TSchema>;
2118
2119 /**
2120 * Generates a schema object that matches a function type.
2121 */
2122 function<TSchema = Function>(): FunctionSchema<TSchema>;
2123
2124 /**
2125 * Generates a schema object that matches a number data type (as well as strings that can be converted to numbers).
2126 */
2127 number<TSchema = number>(): NumberSchema<TSchema>;
2128
2129 /**
2130 * Generates a schema object that matches an object data type (as well as JSON strings that have been parsed into objects).
2131 */
2132 // tslint:disable-next-line:no-unnecessary-generics
2133 object<TSchema = any, isStrict = false, T = TSchema>(schema?: SchemaMap<T, isStrict>): ObjectSchema<TSchema>;
2134
2135 /**
2136 * Generates a schema object that matches a string data type. Note that empty strings are not allowed by default and must be enabled with allow('').
2137 */
2138 string<TSchema = string>(): StringSchema<TSchema>;
2139
2140 /**
2141 * Generates a schema object that matches any symbol.
2142 */
2143 symbol<TSchema = Symbol>(): SymbolSchema<TSchema>;
2144
2145 /**
2146 * Generates a type that will match one of the provided alternative schemas
2147 */
2148 alternatives<TSchema = any>(types: SchemaLike[]): AlternativesSchema<TSchema>;
2149 alternatives<TSchema = any>(...types: SchemaLike[]): AlternativesSchema<TSchema>;
2150
2151 /**
2152 * Alias for `alternatives`
2153 */
2154 alt<TSchema = any>(types: SchemaLike[]): AlternativesSchema<TSchema>;
2155 alt<TSchema = any>(...types: SchemaLike[]): AlternativesSchema<TSchema>;
2156
2157 /**
2158 * Links to another schema node and reuses it for validation, typically for creative recursive schemas.
2159 *
2160 * @param ref - the reference to the linked schema node.
2161 * Cannot reference itself or its children as well as other links.
2162 * Links can be expressed in relative terms like value references (`Joi.link('...')`),
2163 * in absolute terms from the schema run-time root (`Joi.link('/a')`),
2164 * or using schema ids implicitly using object keys or explicitly using `any.id()` (`Joi.link('#a.b.c')`).
2165 */
2166 link<TSchema = any>(ref?: string): LinkSchema<TSchema>;
2167
2168 /**
2169 * Validates a value against a schema and throws if validation fails.
2170 *
2171 * @param value - the value to validate.
2172 * @param schema - the schema object.
2173 * @param message - optional message string prefix added in front of the error message. may also be an Error object.
2174 */
2175 assert(value: any, schema: Schema, options?: ValidationOptions): void;
2176 assert(value: any, schema: Schema, message: string | Error, options?: ValidationOptions): void;
2177
2178 /**
2179 * Validates a value against a schema, returns valid object, and throws if validation fails.
2180 *
2181 * @param value - the value to validate.
2182 * @param schema - the schema object.
2183 * @param message - optional message string prefix added in front of the error message. may also be an Error object.
2184 */
2185 attempt<TSchema extends Schema>(value: any, schema: TSchema, options?: ValidationOptions): TSchema extends Schema<infer Value> ? Value : never;
2186 attempt<TSchema extends Schema>(value: any, schema: TSchema, message: string | Error, options?: ValidationOptions): TSchema extends Schema<infer Value> ? Value : never;
2187
2188 cache: CacheConfiguration;
2189
2190 /**
2191 * Converts literal schema definition to joi schema object (or returns the same back if already a joi schema object).
2192 */
2193 compile(schema: SchemaLike, options?: CompileOptions): Schema;
2194
2195 /**
2196 * Checks if the provided preferences are valid.
2197 *
2198 * Throws an exception if the prefs object is invalid.
2199 *
2200 * The method is provided to perform inputs validation for the `any.validate()` and `any.validateAsync()` methods.
2201 * Validation is not performed automatically for performance reasons. Instead, manually validate the preferences passed once and reuse.
2202 */
2203 checkPreferences(prefs: ValidationOptions): void;
2204
2205 /**
2206 * Creates a custom validation schema.
2207 */
2208 custom(fn: CustomValidator, description?: string): Schema;
2209
2210 /**
2211 * Creates a new Joi instance that will apply defaults onto newly created schemas
2212 * through the use of the fn function that takes exactly one argument, the schema being created.
2213 *
2214 * @param fn - The function must always return a schema, even if untransformed.
2215 */
2216 defaults(fn: SchemaFunction): Root;
2217
2218 /**
2219 * Generates a dynamic expression using a template string.
2220 */
2221 expression(template: string, options?: ReferenceOptions): any;
2222
2223 /**
2224 * Creates a new Joi instance customized with the extension(s) you provide included.
2225 */
2226 extend(...extensions: Array<Extension | ExtensionFactory>): any;
2227
2228 /**
2229 * Creates a reference that when resolved, is used as an array of values to match against the rule.
2230 */
2231 in(ref: string, options?: ReferenceOptions): Reference;
2232
2233 /**
2234 * Checks whether or not the provided argument is an instance of ValidationError
2235 */
2236 isError(error: any): error is ValidationError;
2237
2238 /**
2239 * Checks whether or not the provided argument is an expression.
2240 */
2241 isExpression(expression: any): boolean;
2242
2243 /**
2244 * Checks whether or not the provided argument is a reference. It's especially useful if you want to post-process error messages.
2245 */
2246 isRef(ref: any): ref is Reference;
2247
2248 /**
2249 * Checks whether or not the provided argument is a joi schema.
2250 */
2251 isSchema(schema: any, options?: CompileOptions): schema is AnySchema;
2252
2253 /**
2254 * A special value used with `any.allow()`, `any.invalid()`, and `any.valid()` as the first value to reset any previously set values.
2255 */
2256 override: symbol;
2257
2258 /**
2259 * Generates a reference to the value of the named key.
2260 */
2261 ref(key: string, options?: ReferenceOptions): Reference;
2262
2263 /**
2264 * Returns an object where each key is a plain joi schema type.
2265 * Useful for creating type shortcuts using deconstruction.
2266 * Note that the types are already formed and do not need to be called as functions (e.g. `string`, not `string()`).
2267 */
2268 types(): {
2269 alternatives: AlternativesSchema;
2270 any: AnySchema;
2271 array: ArraySchema;
2272 binary: BinarySchema;
2273 boolean: BooleanSchema;
2274 date: DateSchema;
2275 function: FunctionSchema;
2276 link: LinkSchema;
2277 number: NumberSchema;
2278 object: ObjectSchema;
2279 string: StringSchema;
2280 symbol: SymbolSchema;
2281 };
2282
2283 /**
2284 * Generates a dynamic expression using a template string.
2285 */
2286 x(template: string, options?: ReferenceOptions): any;
2287
2288 // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
2289 // Below are undocumented APIs. use at your own risk
2290 // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
2291
2292 /**
2293 * Whitelists a value
2294 */
2295 allow(...values: any[]): Schema;
2296
2297 /**
2298 * Adds the provided values into the allowed whitelist and marks them as the only valid values allowed.
2299 */
2300 valid(...values: any[]): Schema;
2301 equal(...values: any[]): Schema;
2302
2303 /**
2304 * Blacklists a value
2305 */
2306 invalid(...values: any[]): Schema;
2307 disallow(...values: any[]): Schema;
2308 not(...values: any[]): Schema;
2309
2310 /**
2311 * Marks a key as required which will not allow undefined as value. All keys are optional by default.
2312 */
2313 required(): Schema;
2314
2315 /**
2316 * Alias of `required`.
2317 */
2318 exist(): Schema;
2319
2320 /**
2321 * Marks a key as optional which will allow undefined as values. Used to annotate the schema for readability as all keys are optional by default.
2322 */
2323 optional(): Schema;
2324
2325 /**
2326 * Marks a key as forbidden which will not allow any value except undefined. Used to explicitly forbid keys.
2327 */
2328 forbidden(): Schema;
2329
2330 /**
2331 * Overrides the global validate() options for the current key and any sub-key.
2332 */
2333 preferences(options: ValidationOptions): Schema;
2334
2335 /**
2336 * Overrides the global validate() options for the current key and any sub-key.
2337 */
2338 prefs(options: ValidationOptions): Schema;
2339
2340 /**
2341 * Converts the type into an alternatives type where the conditions are merged into the type definition where:
2342 */
2343 when(ref: string | Reference, options: WhenOptions | WhenOptions[]): AlternativesSchema;
2344 when(ref: Schema, options: WhenSchemaOptions): AlternativesSchema;
2345
2346 /**
2347 * Unsure, maybe alias for `compile`?
2348 */
2349 build(...args: any[]): any;
2350
2351 /**
2352 * Unsure, maybe alias for `preferences`?
2353 */
2354 options(...args: any[]): any;
2355
2356 /**
2357 * Unsure, maybe leaked from `@hapi/lab/coverage/initialize`
2358 */
2359 trace(...args: any[]): any;
2360 untrace(...args: any[]): any;
2361 }
2362}
2363
2364declare const Joi: Joi.Root;
2365export = Joi;