@nhtio/validation 1.20250813.0 → 1.20250814.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,9 +2,9 @@ import type { DateTime } from 'luxon';
2
2
  import type { PhoneSchema } from './schemas/phone';
3
3
  import type { BigIntSchema } from './schemas/bigint';
4
4
  import type { DatetimeSchema } from './schemas/datetime';
5
- import type { AnySchema as JoiAnySchema, StringSchema as JoiStringSchema, BinarySchema as JoiBinarySchema, NumberSchema as JoiNumberSchema, BooleanSchema as JoiBooleanSchema, ObjectSchema as JoiObjectSchema, ArraySchema as JoiArraySchema, DateSchema as JoiDateSchema, AlternativesSchema as JoiAlternativesSchema, Reference, BasicType, CustomHelpers, SchemaLikeWithoutArray } from 'joi';
5
+ import type { default as Joi, AnySchema as JoiAnySchema, Reference, BasicType, CustomHelpers } from 'joi';
6
6
  export type DefaultableValue = Reference | BasicType | DateTime | bigint | ((parent: any, helpers: CustomHelpers) => Reference | BasicType | DateTime | bigint);
7
- export type ExtendedSchemaLikeWithoutArray = SchemaLikeWithoutArray | PhoneSchema | BigIntSchema | DatetimeSchema;
7
+ export type ExtendedSchemaLikeWithoutArray = string | number | boolean | null | Schema | Joi.SchemaMap | PhoneSchema | BigIntSchema | DatetimeSchema;
8
8
  /**
9
9
  * Base schema type for all validation schemas.
10
10
  *
@@ -13,7 +13,55 @@ export type ExtendedSchemaLikeWithoutArray = SchemaLikeWithoutArray | PhoneSchem
13
13
  *
14
14
  * @public
15
15
  */
16
- export interface AnySchema<TSchema = any> extends Omit<JoiAnySchema<TSchema>, 'default'> {
16
+ export interface AnySchema<TSchema = any> extends Omit<JoiAnySchema<TSchema>, 'allow' | 'alter' | 'artifact' | 'bind' | 'cache' | 'cast' | 'concat' | 'custom' | 'default' | 'description' | 'disallow' | 'empty' | 'equal' | 'error' | 'example' | 'exist' | 'external' | 'failover' | 'forbidden' | 'fork' | 'id' | 'invalid' | 'keep' | 'label' | 'message' | 'messages' | 'meta' | 'not' | 'note' | 'only' | 'optional' | 'options' | 'preferences' | 'prefs' | 'presence' | 'raw' | 'required' | 'rule' | 'shared' | 'strict' | 'strip' | 'tag' | 'unit' | 'valid' | 'warn' | 'warning' | 'when'> {
17
+ allow(...values: any[]): this;
18
+ alter(targets: Record<string, (schema: this) => Schema>): this;
19
+ artifact(id: any): this;
20
+ bind(): this;
21
+ cache(cache?: Joi.Cache): this;
22
+ concat(schema: this): this;
23
+ custom(fn: Joi.CustomValidator, description?: string): this;
24
+ description(desc: string): this;
25
+ disallow(...values: any[]): this;
26
+ empty(schema?: Joi.SchemaLike): this;
27
+ equal(...values: any[]): this;
28
+ error(err: Error | Joi.ValidationErrorFunction): this;
29
+ example(value: any, options?: {
30
+ override: boolean;
31
+ }): this;
32
+ exist(): this;
33
+ external(method: Joi.ExternalValidationFunction, description?: string): this;
34
+ failover(value: any): this;
35
+ forbidden(): this;
36
+ fork(key: string | string[] | string[][], adjuster: Joi.SchemaFunction): this;
37
+ id(name?: string): this;
38
+ invalid(...values: any[]): this;
39
+ keep(): this;
40
+ label(name: string): this;
41
+ message(message: string): this;
42
+ messages(messages: Joi.LanguageMessages): this;
43
+ meta(meta: object): this;
44
+ not(...values: any[]): this;
45
+ note(...notes: string[]): this;
46
+ only(): this;
47
+ optional(): this;
48
+ options(options: Joi.ValidationOptions): this;
49
+ prefs(options: Joi.ValidationOptions): this;
50
+ preferences(options: Joi.ValidationOptions): this;
51
+ presence(mode: Joi.PresenceMode): this;
52
+ raw(enabled?: boolean): this;
53
+ required(): this;
54
+ rule(options: Joi.RuleOptions): this;
55
+ shared(ref: Schema): this;
56
+ strict(isStrict?: boolean): this;
57
+ strip(enabled?: boolean): this;
58
+ tag(...tags: string[]): this;
59
+ unit(name: string): this;
60
+ valid(...values: any[]): this;
61
+ warn(): this;
62
+ warning(code: string, context: Joi.Context): this;
63
+ when(ref: string | Reference, options: Joi.WhenOptions | Joi.WhenOptions[]): this;
64
+ when(ref: Schema, options: Joi.WhenSchemaOptions): this;
17
65
  /**
18
66
  * Sets a default value if the original value is `undefined`.
19
67
  *
@@ -38,7 +86,142 @@ export interface AnySchema<TSchema = any> extends Omit<JoiAnySchema<TSchema>, 'd
38
86
  *
39
87
  * @public
40
88
  */
41
- export interface StringSchema<TSchema = string> extends Omit<JoiStringSchema<TSchema>, 'default'> {
89
+ export interface StringSchema<TSchema = string> extends AnySchema<TSchema> {
90
+ /**
91
+ * Requires the string value to only contain a-z, A-Z, and 0-9.
92
+ */
93
+ alphanum(): this;
94
+ /**
95
+ * Requires the string value to be a valid base64 string; does not check the decoded value.
96
+ */
97
+ base64(options?: Joi.Base64Options): this;
98
+ /**
99
+ * Sets the required string case.
100
+ */
101
+ case(direction: 'upper' | 'lower'): this;
102
+ /**
103
+ * Requires the number to be a credit card number (Using Luhn Algorithm).
104
+ */
105
+ creditCard(): this;
106
+ /**
107
+ * Requires the string value to be a valid data URI string.
108
+ */
109
+ dataUri(options?: Joi.DataUriOptions): this;
110
+ /**
111
+ * Requires the string value to be a valid domain.
112
+ */
113
+ domain(options?: Joi.DomainOptions): this;
114
+ /**
115
+ * Requires the string value to be a valid email address.
116
+ */
117
+ email(options?: Joi.EmailOptions): this;
118
+ /**
119
+ * Requires the string value to be a valid GUID.
120
+ */
121
+ guid(options?: Joi.GuidOptions): this;
122
+ /**
123
+ * Requires the string value to be a valid hexadecimal string.
124
+ */
125
+ hex(options?: Joi.HexOptions): this;
126
+ /**
127
+ * Requires the string value to be a valid hostname as per RFC1123.
128
+ */
129
+ hostname(): this;
130
+ /**
131
+ * Allows the value to match any whitelist of blacklist item in a case insensitive comparison.
132
+ */
133
+ insensitive(): this;
134
+ /**
135
+ * Requires the string value to be a valid ip address.
136
+ */
137
+ ip(options?: Joi.IpOptions): this;
138
+ /**
139
+ * Requires the string value to be in valid ISO 8601 date format.
140
+ */
141
+ isoDate(): this;
142
+ /**
143
+ * Requires the string value to be in valid ISO 8601 duration format.
144
+ */
145
+ isoDuration(): this;
146
+ /**
147
+ * Specifies the exact string length required
148
+ * @param limit - the required string length. It can also be a reference to another field.
149
+ * @param encoding - if specified, the string length is calculated in bytes using the provided encoding.
150
+ */
151
+ length(limit: number | Reference, encoding?: string): this;
152
+ /**
153
+ * 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.
154
+ */
155
+ lowercase(): this;
156
+ /**
157
+ * Specifies the maximum number of string characters.
158
+ * @param limit - the maximum number of string characters allowed. It can also be a reference to another field.
159
+ * @param encoding - if specified, the string length is calculated in bytes using the provided encoding.
160
+ */
161
+ max(limit: number | Reference, encoding?: string): this;
162
+ /**
163
+ * Specifies the minimum number string characters.
164
+ * @param limit - the minimum number of string characters required. It can also be a reference to another field.
165
+ * @param encoding - if specified, the string length is calculated in bytes using the provided encoding.
166
+ */
167
+ min(limit: number | Reference, encoding?: string): this;
168
+ /**
169
+ * 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.
170
+ * @param [form='NFC'] - The unicode normalization form to use. Valid values: NFC [default], NFD, NFKC, NFKD
171
+ */
172
+ normalize(form?: 'NFC' | 'NFD' | 'NFKC' | 'NFKD'): this;
173
+ /**
174
+ * Defines a regular expression rule.
175
+ * @param pattern - a regular expression object the string value must match against.
176
+ * @param options - optional, can be:
177
+ * Name for patterns (useful with multiple patterns). Defaults to 'required'.
178
+ * An optional configuration object with the following supported properties:
179
+ * name - optional pattern name.
180
+ * invert - optional boolean flag. Defaults to false behavior. If specified as true, the provided pattern will be disallowed instead of required.
181
+ */
182
+ pattern(pattern: RegExp, options?: string | Joi.StringRegexOptions): this;
183
+ /**
184
+ * Defines a regular expression rule.
185
+ * @param pattern - a regular expression object the string value must match against.
186
+ * @param options - optional, can be:
187
+ * Name for patterns (useful with multiple patterns). Defaults to 'required'.
188
+ * An optional configuration object with the following supported properties:
189
+ * name - optional pattern name.
190
+ * invert - optional boolean flag. Defaults to false behavior. If specified as true, the provided pattern will be disallowed instead of required.
191
+ */
192
+ regex(pattern: RegExp, options?: string | Joi.StringRegexOptions): this;
193
+ /**
194
+ * Replace characters matching the given pattern with the specified replacement string where:
195
+ * @param pattern - a regular expression object to match against, or a string of which all occurrences will be replaced.
196
+ * @param replacement - the string that will replace the pattern.
197
+ */
198
+ replace(pattern: RegExp | string, replacement: string): this;
199
+ /**
200
+ * Requires the string value to only contain a-z, A-Z, 0-9, and underscore _.
201
+ */
202
+ token(): this;
203
+ /**
204
+ * 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.
205
+ * @param [enabled=true] - optional parameter defaulting to true which allows you to reset the behavior of trim by providing a falsy value.
206
+ */
207
+ trim(enabled?: any): this;
208
+ /**
209
+ * Specifies whether the string.max() limit should be used as a truncation.
210
+ * @param [enabled=true] - optional parameter defaulting to true which allows you to reset the behavior of truncate by providing a falsy value.
211
+ */
212
+ truncate(enabled?: boolean): this;
213
+ /**
214
+ * 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.
215
+ */
216
+ uppercase(): this;
217
+ /**
218
+ * Requires the string value to be a valid RFC 3986 URI.
219
+ */
220
+ uri(options?: Joi.UriOptions): this;
221
+ /**
222
+ * Requires the string value to be a valid GUID.
223
+ */
224
+ uuid(options?: Joi.GuidOptions): this;
42
225
  /**
43
226
  * Sets a default value if the original value is `undefined`.
44
227
  *
@@ -56,7 +239,23 @@ export interface StringSchema<TSchema = string> extends Omit<JoiStringSchema<TSc
56
239
  *
57
240
  * @public
58
241
  */
59
- export interface BinarySchema<TSchema = Buffer> extends Omit<JoiBinarySchema<TSchema>, 'default'> {
242
+ export interface BinarySchema<TSchema = Buffer> extends AnySchema<TSchema> {
243
+ /**
244
+ * Sets the string encoding format if a string input is converted to a buffer.
245
+ */
246
+ encoding(encoding: string): this;
247
+ /**
248
+ * Specifies the minimum length of the buffer.
249
+ */
250
+ min(limit: number | Reference): this;
251
+ /**
252
+ * Specifies the maximum length of the buffer.
253
+ */
254
+ max(limit: number | Reference): this;
255
+ /**
256
+ * Specifies the exact length of the buffer:
257
+ */
258
+ length(limit: number | Reference): this;
60
259
  /**
61
260
  * Sets a default value if the original value is `undefined`.
62
261
  *
@@ -74,7 +273,60 @@ export interface BinarySchema<TSchema = Buffer> extends Omit<JoiBinarySchema<TSc
74
273
  *
75
274
  * @public
76
275
  */
77
- export interface NumberSchema<TSchema = number> extends Omit<JoiNumberSchema<TSchema>, 'default'> {
276
+ export interface NumberSchema<TSchema = number> extends AnySchema<TSchema> {
277
+ /**
278
+ * Specifies that the value must be greater than limit.
279
+ * It can also be a reference to another field.
280
+ */
281
+ greater(limit: number | Reference): this;
282
+ /**
283
+ * Requires the number to be an integer (no floating point).
284
+ */
285
+ integer(): this;
286
+ /**
287
+ * Specifies that the value must be less than limit.
288
+ * It can also be a reference to another field.
289
+ */
290
+ less(limit: number | Reference): this;
291
+ /**
292
+ * Specifies the maximum value.
293
+ * It can also be a reference to another field.
294
+ */
295
+ max(limit: number | Reference): this;
296
+ /**
297
+ * Specifies the minimum value.
298
+ * It can also be a reference to another field.
299
+ */
300
+ min(limit: number | Reference): this;
301
+ /**
302
+ * Specifies that the value must be a multiple of base.
303
+ */
304
+ multiple(base: number | Reference): this;
305
+ /**
306
+ * Requires the number to be negative.
307
+ */
308
+ negative(): this;
309
+ /**
310
+ * Requires the number to be a TCP port, so between 0 and 65535.
311
+ */
312
+ port(): this;
313
+ /**
314
+ * Requires the number to be positive.
315
+ */
316
+ positive(): this;
317
+ /**
318
+ * Specifies the maximum number of decimal places where:
319
+ * @param limit - the maximum number of decimal places allowed.
320
+ */
321
+ precision(limit: number): this;
322
+ /**
323
+ * Requires the number to be negative or positive.
324
+ */
325
+ sign(sign: 'positive' | 'negative'): this;
326
+ /**
327
+ * Allows the number to be outside of JavaScript's safety range (Number.MIN_SAFE_INTEGER & Number.MAX_SAFE_INTEGER).
328
+ */
329
+ unsafe(enabled?: any): this;
78
330
  /**
79
331
  * Sets a default value if the original value is `undefined`.
80
332
  *
@@ -92,7 +344,10 @@ export interface NumberSchema<TSchema = number> extends Omit<JoiNumberSchema<TSc
92
344
  *
93
345
  * @public
94
346
  */
95
- export interface BooleanSchema<TSchema = boolean> extends Omit<JoiBooleanSchema<TSchema>, 'default'> {
347
+ export interface BooleanSchema<TSchema = boolean> extends AnySchema<TSchema> {
348
+ falsy(...values: Array<string | number | null>): this;
349
+ sensitive(enabled?: boolean): this;
350
+ truthy(...values: Array<string | number | null>): this;
96
351
  /**
97
352
  * Sets a default value if the original value is `undefined`.
98
353
  *
@@ -110,7 +365,104 @@ export interface BooleanSchema<TSchema = boolean> extends Omit<JoiBooleanSchema<
110
365
  *
111
366
  * @public
112
367
  */
113
- export interface ObjectSchema<TSchema = any> extends Omit<JoiObjectSchema<TSchema>, 'default'> {
368
+ export interface ObjectSchema<TSchema = any> extends AnySchema<TSchema> {
369
+ /**
370
+ * Defines an all-or-nothing relationship between keys where if one of the peers is present, all of them are required as well.
371
+ *
372
+ * Optional settings must be the last argument.
373
+ */
374
+ and(...peers: Array<string | Joi.DependencyOptions>): this;
375
+ /**
376
+ * Appends the allowed object keys. If schema is null, undefined, or {}, no changes will be applied.
377
+ */
378
+ append(schema?: Joi.SchemaMap<TSchema>): this;
379
+ append<TSchemaExtended = any, T = TSchemaExtended>(schema?: Joi.SchemaMap<T>): ObjectSchema<T>;
380
+ /**
381
+ * Verifies an assertion where.
382
+ */
383
+ assert(ref: string | Reference, schema: Joi.SchemaLike, message?: string): this;
384
+ /**
385
+ * Requires the object to be an instance of a given constructor.
386
+ *
387
+ * @param constructor - the constructor function that the object must be an instance of.
388
+ * @param name - an alternate name to use in validation errors. This is useful when the constructor function does not have a name.
389
+ */
390
+ instance(constructor: Function, name?: string): this;
391
+ /**
392
+ * Sets or extends the allowed object keys.
393
+ */
394
+ keys(schema?: Joi.SchemaMap<TSchema>): this;
395
+ /**
396
+ * Specifies the exact number of keys in the object.
397
+ */
398
+ length(limit: number): this;
399
+ /**
400
+ * Specifies the maximum number of keys in the object.
401
+ */
402
+ max(limit: number | Reference): this;
403
+ /**
404
+ * Specifies the minimum number of keys in the object.
405
+ */
406
+ min(limit: number | Reference): this;
407
+ /**
408
+ * Defines a relationship between keys where not all peers can be present at the same time.
409
+ *
410
+ * Optional settings must be the last argument.
411
+ */
412
+ nand(...peers: Array<string | Joi.DependencyOptions>): this;
413
+ /**
414
+ * Defines a relationship between keys where one of the peers is required (and more than one is allowed).
415
+ *
416
+ * Optional settings must be the last argument.
417
+ */
418
+ or(...peers: Array<string | Joi.DependencyOptions>): this;
419
+ /**
420
+ * Defines an exclusive relationship between a set of keys where only one is allowed but none are required.
421
+ *
422
+ * Optional settings must be the last argument.
423
+ */
424
+ oxor(...peers: Array<string | Joi.DependencyOptions>): this;
425
+ /**
426
+ * Specify validation rules for unknown keys matching a pattern.
427
+ *
428
+ * @param pattern - a pattern that can be either a regular expression or a joi schema that will be tested against the unknown key names
429
+ * @param schema - the schema object matching keys must validate against
430
+ */
431
+ pattern(pattern: RegExp | Joi.SchemaLike, schema: Joi.SchemaLike, options?: Joi.ObjectPatternOptions): this;
432
+ /**
433
+ * Requires the object to be a Joi reference.
434
+ */
435
+ ref(): this;
436
+ /**
437
+ * Requires the object to be a `RegExp` object.
438
+ */
439
+ regex(): this;
440
+ /**
441
+ * Renames a key to another name (deletes the renamed key).
442
+ */
443
+ rename(from: string | RegExp, to: string, options?: Joi.RenameOptions): this;
444
+ /**
445
+ * Requires the object to be a Joi schema instance.
446
+ */
447
+ schema(type?: Joi.SchemaLike): this;
448
+ /**
449
+ * Overrides the handling of unknown keys for the scope of the current object only (does not apply to children).
450
+ */
451
+ unknown(allow?: boolean): this;
452
+ /**
453
+ * Requires the presence of other keys whenever the specified key is present.
454
+ */
455
+ with(key: string, peers: string | string[], options?: Joi.DependencyOptions): this;
456
+ /**
457
+ * Forbids the presence of other keys whenever the specified is present.
458
+ */
459
+ without(key: string, peers: string | string[], options?: Joi.DependencyOptions): this;
460
+ /**
461
+ * Defines an exclusive relationship between a set of keys. one of them is required but not at the same time.
462
+ *
463
+ * Optional settings must be the last argument.
464
+ */
465
+ xor(...peers: Array<string | Joi.DependencyOptions>): this;
114
466
  /**
115
467
  * Sets a default value if the original value is `undefined`.
116
468
  *
@@ -131,7 +483,47 @@ export interface ObjectSchema<TSchema = any> extends Omit<JoiObjectSchema<TSchem
131
483
  *
132
484
  * @public
133
485
  */
134
- export interface ArraySchema<TSchema = any[]> extends Omit<JoiArraySchema<TSchema>, 'default'> {
486
+ export interface ArraySchema<TSchema = any[]> extends AnySchema<TSchema> {
487
+ /**
488
+ * Verifies that an assertion passes for at least one item in the array, where:
489
+ * `schema` - the validation rules required to satisfy the assertion. If the `schema` includes references, they are resolved against
490
+ * the array item being tested, not the value of the `ref` target.
491
+ */
492
+ has(schema: Joi.SchemaLike): this;
493
+ /**
494
+ * Specifies the exact number of items in the array.
495
+ */
496
+ length(limit: number | Reference): this;
497
+ /**
498
+ * Specifies the maximum number of items in the array.
499
+ */
500
+ max(limit: number | Reference): this;
501
+ /**
502
+ * Specifies the minimum number of items in the array.
503
+ */
504
+ min(limit: number | Reference): this;
505
+ /**
506
+ * Allow single values to be checked against rules as if it were provided as an array.
507
+ * enabled can be used with a falsy value to go back to the default behavior.
508
+ */
509
+ single(enabled?: any): this;
510
+ /**
511
+ * Sorts the array by given order.
512
+ */
513
+ sort(options?: Joi.ArraySortOptions): this;
514
+ /**
515
+ * Allow this array to be sparse.
516
+ * enabled can be used with a falsy value to go back to the default behavior.
517
+ */
518
+ sparse(enabled?: any): this;
519
+ /**
520
+ * Requires the array values to be unique.
521
+ * Remember that if you provide a custom comparator function,
522
+ * different types can be passed as parameter depending on the rules you set on items.
523
+ * Be aware that a deep equality is performed on elements of the array having a type of object,
524
+ * a performance penalty is to be expected for this kind of operation.
525
+ */
526
+ unique(comparator?: string | Joi.ComparatorFunction, options?: Joi.ArrayUniqueOptions): this;
135
527
  /**
136
528
  * Sets a default value if the original value is `undefined`.
137
529
  *
@@ -143,7 +535,24 @@ export interface ArraySchema<TSchema = any[]> extends Omit<JoiArraySchema<TSchem
143
535
  * - `helpers` - Validation helper functions for custom validation logic
144
536
  */
145
537
  default(value?: DefaultableValue): this;
538
+ /**
539
+ * List the types allowed for the array values.
540
+ * If a given type is .required() then there must be a matching item in the array.
541
+ * If a type is .forbidden() then it cannot appear in the array.
542
+ * Required items can be added multiple times to signify that multiple items must be found.
543
+ * Errors will contain the number of items that didn't match.
544
+ * Any unmatched item having a label will be mentioned explicitly.
545
+ *
546
+ * @param type - a joi schema object to validate each array item against.
547
+ */
146
548
  items(...types: ExtendedSchemaLikeWithoutArray[]): this;
549
+ /**
550
+ * Lists the types in sequence order for the array values where:
551
+ * @param type - a joi schema object to validate against each array item in sequence order. type can be multiple values passed as individual arguments.
552
+ * If a given type is .required() then there must be a matching item with the same index position in the array.
553
+ * Errors will contain the number of items that didn't match.
554
+ * Any unmatched item having a label will be mentioned explicitly.
555
+ */
147
556
  ordered(...types: ExtendedSchemaLikeWithoutArray[]): this;
148
557
  }
149
558
  /**
@@ -151,7 +560,44 @@ export interface ArraySchema<TSchema = any[]> extends Omit<JoiArraySchema<TSchem
151
560
  *
152
561
  * @public
153
562
  */
154
- export interface DateSchema<TSchema = Date> extends Omit<JoiDateSchema<TSchema>, 'default'> {
563
+ export interface DateSchema<TSchema = Date> extends AnySchema<TSchema> {
564
+ /**
565
+ * Specifies that the value must be greater than date.
566
+ * Notes: 'now' can be passed in lieu of date so as to always compare relatively to the current date,
567
+ * allowing to explicitly ensure a date is either in the past or in the future.
568
+ * It can also be a reference to another field.
569
+ */
570
+ greater(date: 'now' | Date | number | string | Reference): this;
571
+ /**
572
+ * Requires the string value to be in valid ISO 8601 date format.
573
+ */
574
+ iso(): this;
575
+ /**
576
+ * Specifies that the value must be less than date.
577
+ * Notes: 'now' can be passed in lieu of date so as to always compare relatively to the current date,
578
+ * allowing to explicitly ensure a date is either in the past or in the future.
579
+ * It can also be a reference to another field.
580
+ */
581
+ less(date: 'now' | Date | number | string | Reference): this;
582
+ /**
583
+ * Specifies the oldest date allowed.
584
+ * Notes: 'now' can be passed in lieu of date so as to always compare relatively to the current date,
585
+ * allowing to explicitly ensure a date is either in the past or in the future.
586
+ * It can also be a reference to another field.
587
+ */
588
+ min(date: 'now' | Date | number | string | Reference): this;
589
+ /**
590
+ * Specifies the latest date allowed.
591
+ * Notes: 'now' can be passed in lieu of date so as to always compare relatively to the current date,
592
+ * allowing to explicitly ensure a date is either in the past or in the future.
593
+ * It can also be a reference to another field.
594
+ */
595
+ max(date: 'now' | Date | number | string | Reference): this;
596
+ /**
597
+ * Requires the value to be a timestamp interval from Unix Time.
598
+ * @param type - the type of timestamp (allowed values are unix or javascript [default])
599
+ */
600
+ timestamp(type?: 'javascript' | 'unix'): this;
155
601
  /**
156
602
  * Sets a default value if the original value is `undefined`.
157
603
  *
@@ -169,7 +615,77 @@ export interface DateSchema<TSchema = Date> extends Omit<JoiDateSchema<TSchema>,
169
615
  *
170
616
  * @public
171
617
  */
172
- export interface AlternativesSchema<TSchema = any> extends Omit<JoiAlternativesSchema<TSchema>, 'default' | 'try'> {
618
+ export interface AlternativesSchema<TSchema = any> extends AnySchema<TSchema> {
619
+ /**
620
+ * Adds a conditional alternative schema type, either based on another key value, or a schema peeking into the current value.
621
+ */
622
+ conditional(ref: string | Reference, options: Joi.WhenOptions | Joi.WhenOptions[]): this;
623
+ conditional(ref: Schema, options: Joi.WhenSchemaOptions): this;
624
+ /**
625
+ * Requires the validated value to match a specific set of the provided alternative.try() schemas.
626
+ * Cannot be combined with `alternatives.conditional()`.
627
+ */
628
+ match(mode: 'any' | 'all' | 'one'): this;
629
+ /**
630
+ * Adds an alternative schema type for attempting to match against the validated value.
631
+ */
173
632
  try(...types: ExtendedSchemaLikeWithoutArray[]): this;
174
633
  default(value?: DefaultableValue): this;
175
634
  }
635
+ /**
636
+ * Schema type for function validation.
637
+ *
638
+ * @public
639
+ */
640
+ export interface FunctionSchema<TSchema = Function> extends AnySchema<TSchema> {
641
+ /**
642
+ * Specifies the arity of the function where:
643
+ * @param n - the arity expected.
644
+ */
645
+ arity(n: number): this;
646
+ /**
647
+ * Requires the function to be a class.
648
+ */
649
+ class(): this;
650
+ /**
651
+ * Specifies the minimal arity of the function where:
652
+ * @param n - the minimal arity expected.
653
+ */
654
+ minArity(n: number): this;
655
+ /**
656
+ * Specifies the minimal arity of the function where:
657
+ * @param n - the minimal arity expected.
658
+ */
659
+ maxArity(n: number): this;
660
+ }
661
+ /**
662
+ * Schema type for link validation.
663
+ *
664
+ * @public
665
+ */
666
+ export interface LinkSchema<TSchema = any> extends AnySchema<TSchema> {
667
+ /**
668
+ * 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.
669
+ * Will throw an exception during validation if the merged types are not compatible.
670
+ */
671
+ concat(schema: Schema | Joi.Schema): this;
672
+ /**
673
+ * Initializes the schema after constructions for cases where the schema has to be constructed first and then initialized.
674
+ * If `ref` was not passed to the constructor, `link.ref()` must be called prior to usage.
675
+ */
676
+ ref(ref: string): this;
677
+ }
678
+ /**
679
+ * Schema type for symbol validation.
680
+ *
681
+ * @public
682
+ */
683
+ export interface SymbolSchema<TSchema = symbol> extends AnySchema<TSchema> {
684
+ map(iterable: Iterable<[string | number | boolean | symbol, symbol]> | {
685
+ [key: string]: symbol;
686
+ }): this;
687
+ }
688
+ /**
689
+ * A union type that includes all schema types.
690
+ */
691
+ export type Schema = AnySchema | StringSchema | BinarySchema | NumberSchema | BooleanSchema | ObjectSchema | ArraySchema | DateSchema | AlternativesSchema | FunctionSchema | LinkSchema | SymbolSchema | BigIntSchema | DatetimeSchema | PhoneSchema;
@@ -1,4 +1,4 @@
1
- import type { AnySchema } from './schemas';
1
+ import type { Schema } from './schemas';
2
2
  /**
3
3
  * Encodes a validation schema into a compressed, base64-encoded string for transport between environments.
4
4
  *
@@ -46,7 +46,7 @@ import type { AnySchema } from './schemas';
46
46
  *
47
47
  * @see {@link decode} For decoding schemas from encoded strings
48
48
  */
49
- export declare const encode: (schema: AnySchema) => string;
49
+ export declare const encode: (schema: Schema) => string;
50
50
  /**
51
51
  * Decodes a base64-encoded schema string back into a usable validation schema.
52
52
  *
@@ -103,4 +103,4 @@ export declare const encode: (schema: AnySchema) => string;
103
103
  *
104
104
  * @see {@link encode} For encoding schemas into transportable strings
105
105
  */
106
- export declare const decode: (base64: string) => AnySchema;
106
+ export declare const decode: (base64: string) => Schema;