-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathindex.d.ts
2339 lines (2013 loc) · 79.4 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// The following definitions have been copied (almost) as-is from:
// https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/hapi__joi
//
// Note: This file is expected to change dramatically in the next major release and have been
// imported here to make migrating back to the "joi" module name simpler. It include known bugs
// and other issues. It does not include some new features included in version 17.2.0 or newer.
//
// TypeScript Version: 2.8
// TODO express type of Schema in a type-parameter (.default, .valid, .example etc)
declare namespace Joi {
type Types =
| 'any'
| 'alternatives'
| 'array'
| 'boolean'
| 'binary'
| 'date'
| 'function'
| 'link'
| 'number'
| 'object'
| 'string'
| 'symbol';
type BasicType = boolean | number | string | any[] | object | null;
type LanguageMessages = Record<string, string>;
type PresenceMode = 'optional' | 'required' | 'forbidden';
interface ErrorFormattingOptions {
/**
* when true, error message templates will escape special characters to HTML entities, for security purposes.
*
* @default false
*/
escapeHtml?: boolean;
/**
* defines the value used to set the label context variable.
*/
label?: 'path' | 'key' | false;
/**
* The preferred language code for error messages.
* The value is matched against keys at the root of the messages object, and then the error code as a child key of that.
* Can be a reference to the value, global context, or local context which is the root value passed to the validation function.
*
* 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.
* Instead, either use the global context, or the absolute value (e.g. `Joi.ref('/variable')`)
*/
language?: keyof LanguageMessages;
/**
* when false, skips rendering error templates. Useful when error messages are generated elsewhere to save processing time.
*
* @default true
*/
render?: boolean;
/**
* when true, the main error will possess a stack trace, otherwise it will be disabled.
* Defaults to false for performances reasons. Has no effect on platforms other than V8/node.js as it uses the Stack trace API.
*
* @default false
*/
stack?: boolean;
/**
* overrides the way values are wrapped (e.g. `[]` around arrays, `""` around labels).
* Each key can be set to a string with one (same character before and after the value) or two characters (first character
* before and second character after), or `false` to disable wrapping.
*/
wrap?: {
/**
* the characters used around `{#label}` references. Defaults to `'"'`.
*
* @default '"'
*/
label?: string | false,
/**
* the characters used around array values. Defaults to `'[]'`
*
* @default '[]'
*/
array?: string | false
/**
* the characters used around array string values. Defaults to no wrapping.
*
* @default false
*/
string?: string | false
};
}
interface BaseValidationOptions {
/**
* when true, stops validation on the first error, otherwise returns all the errors found.
*
* @default true
*/
abortEarly?: boolean;
/**
* when true, allows object to contain unknown keys which are ignored.
*
* @default false
*/
allowUnknown?: boolean;
/**
* when true, return artifacts alongside the value.
*
* @default false
*/
artifacts?: boolean;
/**
* when true, schema caching is enabled (for schemas with explicit caching rules).
*
* @default false
*/
cache?: boolean;
/**
* provides an external data set to be used in references
*/
context?: Context;
/**
* when true, attempts to cast values to the required types (e.g. a string to a number).
*
* @default true
*/
convert?: boolean;
/**
* sets the string format used when converting dates to strings in error messages and casting.
*
* @default 'iso'
*/
dateFormat?: 'date' | 'iso' | 'string' | 'time' | 'utc';
/**
* 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.
*
* @default false
*/
debug?: boolean;
/**
* error formatting settings.
*/
errors?: ErrorFormattingOptions;
/**
* 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).
*
* @default true
*/
externals?: boolean;
/**
* if true, and "abortEarly" is false, the external rules set with `any.external()` will be executed even after synchronous validators have failed.
* This setting has no effect if "abortEarly" is true since external rules get executed after all other validators. Default: false.
*
* @default true
*/
alwaysExecuteExternals?: boolean;
/**
* when true, do not apply default values.
*
* @default false
*/
noDefaults?: boolean;
/**
* when true, inputs are shallow cloned to include non-enumerable properties.
*
* @default false
*/
nonEnumerables?: boolean;
/**
* sets the default presence requirements. Supported modes: 'optional', 'required', and 'forbidden'.
*
* @default 'optional'
*/
presence?: PresenceMode;
/**
* when true, ignores unknown keys with a function value.
*
* @default false
*/
skipFunctions?: boolean;
/**
* remove unknown elements from objects and arrays.
* - when true, all unknown elements will be removed
* - when an object:
* - objects - set to true to remove unknown keys from objects
*
* @default false
*/
stripUnknown?: boolean | { arrays?: boolean; objects?: boolean };
}
interface ValidationOptions extends BaseValidationOptions {
/**
* overrides individual error messages. Defaults to no override (`{}`).
* Messages use the same rules as templates.
* Variables in double braces `{{var}}` are HTML escaped if the option `errors.escapeHtml` is set to true.
*
* @default {}
*/
messages?: LanguageMessages;
}
interface AsyncValidationOptions extends ValidationOptions {
/**
* when true, artifacts are returned alongside the value (i.e. `{ value, artifacts }`)
*
* @default false
*/
artifacts?: boolean;
/**
* when true, warnings are returned alongside the value (i.e. `{ value, warning }`).
*
* @default false
*/
warnings?: boolean;
}
interface LanguageMessageTemplate {
source: string;
rendered: string;
}
interface ErrorValidationOptions extends BaseValidationOptions {
messages?: Record<string, LanguageMessageTemplate>;
}
interface RenameOptions {
/**
* if true, does not delete the old key name, keeping both the new and old keys in place.
*
* @default false
*/
alias?: boolean;
/**
* if true, allows renaming multiple keys to the same destination where the last rename wins.
*
* @default false
*/
multiple?: boolean;
/**
* if true, allows renaming a key over an existing key.
*
* @default false
*/
override?: boolean;
/**
* if true, skip renaming of a key if it's undefined.
*
* @default false
*/
ignoreUndefined?: boolean;
}
interface TopLevelDomainOptions {
/**
* - `true` to use the IANA list of registered TLDs. This is the default value.
* - `false` to allow any TLD not listed in the `deny` list, if present.
* - A `Set` or array of the allowed TLDs. Cannot be used together with `deny`.
*/
allow?: Set<string> | string[] | boolean;
/**
* - A `Set` or array of the forbidden TLDs. Cannot be used together with a custom `allow` list.
*/
deny?: Set<string> | string[];
}
interface HierarchySeparatorOptions {
/**
* overrides the default `.` hierarchy separator. Set to false to treat the key as a literal value.
*
* @default '.'
*/
separator?: string | false;
}
interface EmailOptions {
/**
* if `true`, domains ending with a `.` character are permitted
*
* @default false
*/
allowFullyQualified?: boolean;
/**
* If `true`, Unicode characters are permitted
*
* @default true
*/
allowUnicode?: boolean;
/**
* if `true`, ignore invalid email length errors.
*
* @default false
*/
ignoreLength?: boolean;
/**
* if true, allows multiple email addresses in a single string, separated by , or the separator characters.
*
* @default false
*/
multiple?: boolean;
/**
* when multiple is true, overrides the default , separator. String can be a single character or multiple separator characters.
*
* @default ','
*/
separator?: string | string[];
/**
* 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)
*
* @default { allow: true }
*/
tlds?: TopLevelDomainOptions | false;
/**
* Number of segments required for the domain. Be careful since some domains, such as `io`, directly allow email.
*
* @default 2
*/
minDomainSegments?: number;
/**
* The maximum number of domain segments (e.g. `x.y.z` has 3 segments) allowed. Defaults to no limit.
*
* @default Infinity
*/
maxDomainSegments?: number;
}
interface DomainOptions {
/**
* if `true`, domains ending with a `.` character are permitted
*
* @default false
*/
allowFullyQualified?: boolean;
/**
* If `true`, Unicode characters are permitted
*
* @default true
*/
allowUnicode?: boolean;
/**
* 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)
*
* @default { allow: true }
*/
tlds?: TopLevelDomainOptions | false;
/**
* Number of segments required for the domain.
*
* @default 2
*/
minDomainSegments?: number;
/**
* The maximum number of domain segments (e.g. `x.y.z` has 3 segments) allowed. Defaults to no limit.
*
* @default Infinity
*/
maxDomainSegments?: number;
}
interface HexOptions {
/**
* hex decoded representation must be byte aligned.
* @default false
*/
byteAligned?: boolean;
}
interface IpOptions {
/**
* One or more IP address versions to validate against. Valid values: ipv4, ipv6, ipvfuture
*/
version?: string | string[];
/**
* Used to determine if a CIDR is allowed or not. Valid values: optional, required, forbidden
*/
cidr?: PresenceMode;
}
type GuidVersions = 'uuidv1' | 'uuidv2' | 'uuidv3' | 'uuidv4' | 'uuidv5';
interface GuidOptions {
version?: GuidVersions[] | GuidVersions;
separator?: boolean | '-' | ':';
}
interface UriOptions {
/**
* Specifies one or more acceptable Schemes, should only include the scheme name.
* Can be an Array or String (strings are automatically escaped for use in a Regular Expression).
*/
scheme?: string | RegExp | Array<string | RegExp>;
/**
* Allow relative URIs.
*
* @default false
*/
allowRelative?: boolean;
/**
* Restrict only relative URIs.
*
* @default false
*/
relativeOnly?: boolean;
/**
* Allows unencoded square brackets inside the query string.
* This is NOT RFC 3986 compliant but query strings like abc[]=123&abc[]=456 are very common these days.
*
* @default false
*/
allowQuerySquareBrackets?: boolean;
/**
* Validate the domain component using the options specified in `string.domain()`.
*/
domain?: DomainOptions;
}
interface DataUriOptions {
/**
* optional parameter defaulting to true which will require `=` padding if true or make padding optional if false
*
* @default true
*/
paddingRequired?: boolean;
}
interface Base64Options extends Pick<DataUriOptions, 'paddingRequired'> {
/**
* if true, uses the URI-safe base64 format which replaces `+` with `-` and `\` with `_`.
*
* @default false
*/
urlSafe?: boolean;
}
interface SwitchCases {
/**
* the required condition joi type.
*/
is: SchemaLike;
/**
* the alternative schema type if the condition is true.
*/
then: SchemaLike;
}
interface SwitchDefault {
/**
* the alternative schema type if no cases matched.
* Only one otherwise statement is allowed in switch as the last array item.
*/
otherwise: SchemaLike;
}
interface WhenOptions {
/**
* the required condition joi type.
*/
is?: SchemaLike;
/**
* the negative version of `is` (`then` and `otherwise` have reverse
* roles).
*/
not?: SchemaLike;
/**
* the alternative schema type if the condition is true. Required if otherwise or switch are missing.
*/
then?: SchemaLike;
/**
* the alternative schema type if the condition is false. Required if then or switch are missing.
*/
otherwise?: SchemaLike;
/**
* the list of cases. Required if then is missing. Required if then or otherwise are missing.
*/
switch?: Array<SwitchCases | SwitchDefault>;
/**
* whether to stop applying further conditions if the condition is true.
*/
break?: boolean;
}
interface WhenSchemaOptions {
/**
* the alternative schema type if the condition is true. Required if otherwise is missing.
*/
then?: SchemaLike;
/**
* the alternative schema type if the condition is false. Required if then is missing.
*/
otherwise?: SchemaLike;
}
interface Cache {
/**
* Add an item to the cache.
*
* Note that key and value can be anything including objects, array, etc.
*/
set(key: any, value: any): void;
/**
* Retrieve an item from the cache.
*
* Note that key and value can be anything including objects, array, etc.
*/
get(key: any): any;
}
interface CacheProvisionOptions {
/**
* number of items to store in the cache before the least used items are dropped.
*
* @default 1000
*/
max: number;
}
interface CacheConfiguration {
/**
* Provisions a simple LRU cache for caching simple inputs (`undefined`, `null`, strings, numbers, and booleans).
*/
provision(options?: CacheProvisionOptions): void;
}
interface CompileOptions {
/**
* 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.
* If false, the schema is always compiled using the current version and if older schema components are found, an error is thrown.
*/
legacy: boolean;
}
interface IsSchemaOptions {
/**
* If true, will identify schemas from older versions of joi, otherwise will throw an error.
*
* @default false
*/
legacy: boolean;
}
interface ReferenceOptions extends HierarchySeparatorOptions {
/**
* a function with the signature `function(value)` where `value` is the resolved reference value and the return value is the adjusted value to use.
* 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.
* Cannot be used with `map`.
*
* @example `(value) => value + 5`
*/
adjust?: (value: any) => any;
/**
* an array of array pairs using the format `[[key, value], [key, value]]` used to maps the resolved reference value to another value.
* If the resolved value is not in the map, it is returned as-is.
* Cannot be used with `adjust`.
*/
map?: Array<[any, any]>;
/**
* overrides default prefix characters.
*/
prefix?: {
/**
* references to the globally provided context preference.
*
* @default '$'
*/
global?: string;
/**
* references to error-specific or rule specific context.
*
* @default '#'
*/
local?: string;
/**
* references to the root value being validated.
*
* @default '/'
*/
root?: string;
};
/**
* If set to a number, sets the reference relative starting point.
* Cannot be combined with separator prefix characters.
* Defaults to the reference key prefix (or 1 if none present)
*/
ancestor?: number;
/**
* creates an in-reference.
*/
in?: boolean;
/**
* when true, the reference resolves by reaching into maps and sets.
*/
iterables?: boolean;
/**
* when true, the value of the reference is used instead of its name in error messages
* and template rendering. Defaults to false.
*/
render?: boolean;
}
interface StringRegexOptions {
/**
* optional pattern name.
*/
name?: string;
/**
* when true, the provided pattern will be disallowed instead of required.
*
* @default false
*/
invert?: boolean;
}
interface RuleOptions {
/**
* if true, the rules will not be replaced by the same unique rule later.
*
* For example, `Joi.number().min(1).rule({ keep: true }).min(2)` will keep both `min()` rules instead of the later rule overriding the first.
*
* @default false
*/
keep?: boolean;
/**
* a single message string or a messages object where each key is an error code and corresponding message string as value.
*
* The object is the same as the messages used as an option in `any.validate()`.
* The strings can be plain messages or a message template.
*/
message?: string | LanguageMessages;
/**
* if true, turns any error generated by the ruleset to warnings.
*/
warn?: boolean;
}
interface ErrorReport extends Error {
code: string;
flags: Record<string, ExtensionFlag>;
path: string[];
prefs: ErrorValidationOptions;
messages: LanguageMessages;
state: State;
value: any;
local: any;
}
interface ValidationError extends Error {
name: 'ValidationError';
isJoi: boolean;
/**
* array of errors.
*/
details: ValidationErrorItem[];
/**
* function that returns a string with an annotated version of the object pointing at the places where errors occurred.
*
* NOTE: This method does not exist in browser builds of Joi
*
* @param stripColors - if truthy, will strip the colors out of the output.
*/
annotate(stripColors?: boolean): string;
_original: any;
}
interface ValidationErrorItem {
message: string;
path: Array<string | number>;
type: string;
context?: Context;
}
type ValidationErrorFunction = (errors: ErrorReport[]) => string | ValidationErrorItem | Error;
type ValidationResult<TSchema = any> = {
error: undefined;
warning?: ValidationError;
value: TSchema;
} | {
error: ValidationError;
warning?: ValidationError;
value: undefined;
}
interface CreateErrorOptions {
flags?: boolean;
messages?: LanguageMessages;
}
interface ModifyOptions {
each?: boolean;
once?: boolean;
ref?: boolean;
schema?: boolean;
}
interface MutateRegisterOptions {
family?: any;
key?: any;
}
interface SetFlagOptions {
clone: boolean;
}
interface CustomHelpers<V = any> {
schema: ExtensionBoundSchema;
state: State;
prefs: ValidationOptions;
original: V;
warn: (code: string, local?: Context) => void;
error: (code: string, local?: Context) => ErrorReport;
message: (messages: LanguageMessages, local?: Context) => ErrorReport;
}
type CustomValidator<V = any> = (value: V, helpers: CustomHelpers) => V | ErrorReport;
interface ExternalHelpers {
prefs: ValidationOptions;
path: string[],
label: string,
root: any,
context: any,
error: ExternalValidationFunctionErrorCallback,
}
type ExternalValidationFunction<V = any> = (value: V, helpers: ExternalHelpers) => V | undefined;
type ExternalValidationFunctionErrorCallback = (message: string) => void;
type SchemaLikeWithoutArray = string | number | boolean | null | Schema | SchemaMap;
type SchemaLike = SchemaLikeWithoutArray | object;
type NullableType<T> = undefined | null | T
type IsPrimitiveSubset<T> =
[T] extends [string]
? true
: [T] extends [number]
? true
: [T] extends [bigint]
? true
: [T] extends [boolean]
? true
: [T] extends [symbol]
? true
: [T] extends [null]
? true
: [T] extends [undefined]
? true
: false;
type IsUnion<T, U extends T = T> =
T extends unknown ? [U] extends [T] ? false : true : false;
type IsNonPrimitiveSubsetUnion<T> = true extends IsUnion<T> ? true extends IsPrimitiveSubset<T> ? false : true : false;
type ObjectPropertiesSchema<T = any> =
true extends IsNonPrimitiveSubsetUnion<Exclude<T, undefined | null>>
? Joi.AlternativesSchema
: T extends NullableType<string>
? Joi.StringSchema
: T extends NullableType<number>
? Joi.NumberSchema
: T extends NullableType<bigint>
? Joi.NumberSchema
: T extends NullableType<boolean>
? Joi.BooleanSchema
: T extends NullableType<Date>
? Joi.DateSchema
: T extends NullableType<Array<any>>
? Joi.ArraySchema
: T extends NullableType<object>
? (StrictSchemaMap<T> | ObjectSchema<T>)
: never
type PartialSchemaMap<TSchema = any> = {
[key in keyof TSchema]?: SchemaLike | SchemaLike[];
}
type StrictSchemaMap<TSchema = any> = {
[key in keyof TSchema]-?: ObjectPropertiesSchema<TSchema[key]>
};
type SchemaMap<TSchema = any, isStrict = false> = isStrict extends true ? StrictSchemaMap<TSchema> : PartialSchemaMap<TSchema>
type Schema<P = any> =
| AnySchema
| ArraySchema
| AlternativesSchema
| BinarySchema
| BooleanSchema
| DateSchema
| FunctionSchema
| NumberSchema
| ObjectSchema<P>
| StringSchema
| LinkSchema
| SymbolSchema;
type SchemaFunction = (schema: Schema) => Schema;
interface AddRuleOptions {
name: string;
args?: {
[key: string]: any;
};
}
interface GetRuleOptions {
args?: Record<string, any>;
method?: string;
name: string;
operator?: string;
}
interface SchemaInternals {
/**
* Parent schema object.
*/
$_super: Schema;
/**
* Terms of current schema.
*/
$_terms: Record<string, any>;
/**
* Adds a rule to current validation schema.
*/
$_addRule(rule: string | AddRuleOptions): Schema;
/**
* Internally compiles schema.
*/
$_compile(schema: SchemaLike, options?: CompileOptions): Schema;
/**
* Creates a joi error object.
*/
$_createError(
code: string,
value: any,
context: Context,
state: State,
prefs: ValidationOptions,
options?: CreateErrorOptions,
): Err;
/**
* Get value from given flag.
*/
$_getFlag(name: string): any;
/**
* Retrieve some rule configuration.
*/
$_getRule(name: string): GetRuleOptions | undefined;
$_mapLabels(path: string | string[]): string;
/**
* Returns true if validations runs fine on given value.
*/
$_match(value: any, state: State, prefs: ValidationOptions): boolean;
$_modify(options?: ModifyOptions): Schema;
/**
* Resets current schema.
*/
$_mutateRebuild(): this;
$_mutateRegister(schema: Schema, options?: MutateRegisterOptions): void;
/**
* Get value from given property.
*/
$_property(name: string): any;
/**
* Get schema at given path.
*/
$_reach(path: string[]): Schema;
/**
* Get current schema root references.
*/
$_rootReferences(): any;
/**
* Set flag to given value.
*/
$_setFlag(flag: string, value: any, options?: SetFlagOptions): void;
/**
* Runs internal validations against given value.
*/
$_validate(value: any, state: State, prefs: ValidationOptions): ValidationResult;
}
interface AnySchema<TSchema = any> extends SchemaInternals {
/**
* Flags of current schema.
*/
_flags: Record<string, any>;
/**
* Starts a ruleset in order to apply multiple rule options. The set ends when `rule()`, `keep()`, `message()`, or `warn()` is called.
*/
$: this;
/**
* Starts a ruleset in order to apply multiple rule options. The set ends when `rule()`, `keep()`, `message()`, or `warn()` is called.
*/
ruleset: this;
type?: Types | string;
/**
* Whitelists a value
*/
allow(...values: any[]): this;
/**
* Assign target alteration options to a schema that are applied when `any.tailor()` is called.
* @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.
*/
alter(targets: Record<string, (schema: this) => Schema>): this;
/**
* Assigns the schema an artifact id which is included in the validation result if the rule passed validation.
* @param id - any value other than undefined which will be returned as-is in the result artifacts map.
*/
artifact(id: any): this;
/**
* By default, some Joi methods to function properly need to rely on the Joi instance they are attached to because
* they use `this` internally.
* So `Joi.string()` works but if you extract the function from it and call `string()` it won't.
* `bind()` creates a new Joi instance where all the functions relying on `this` are bound to the Joi instance.
*/
bind(): this;
/**
* Adds caching to the schema which will attempt to cache the validation results (success and failures) of incoming inputs.
* If no cache is passed, a default cache is provisioned by using `cache.provision()` internally.
*/
cache(cache?: Cache): this;
/**
* Casts the validated value to the specified type.
*/
cast(to: 'map' | 'number' | 'set' | 'string'): this;
/**
* Returns a new type that is the result of adding the rules of one type to another.
*/
concat(schema: this): this;
/**
* Adds a custom validation function.
*/
custom(fn: CustomValidator, description?: string): this;
/**
* Sets a default value if the original value is `undefined` where:
* @param value - the default value. One of:
* - a literal value (string, number, object, etc.)
* - a [references](#refkey-options)
* - a function which returns the default value using the signature `function(parent, helpers)` where:
* - `parent` - a clone of the object containing the value being validated. Note that since specifying a
* `parent` argument performs cloning, do not declare format arguments if you are not using them.
* - `helpers` - same as those described in [`any.custom()`](anycustomermethod_description)
*
* When called without any `value` on an object schema type, a default value will be automatically generated
* based on the default values of the object keys.
*
* Note that if value is an object, any changes to the object after `default()` is called will change the
* reference and any future assignment.