@nhtio/validation 0.1.0-master-952eca46 → 0.1.0-master-b4207fd6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs +85585 -84041
- package/index.cjs.map +1 -1
- package/index.d.mts +13349 -0
- package/index.mjs +85599 -84051
- package/index.mjs.map +1 -1
- package/package.json +5 -3
- package/index.d.ts +0 -36
- package/private/core/errors.d.ts +0 -4
- package/private/core/manifest.d.ts +0 -1
- package/private/core/root.d.ts +0 -56
- package/private/guards.d.ts +0 -67
- package/private/index.d.ts +0 -245
- package/private/libs/knex/client.d.ts +0 -62
- package/private/libs/knex/index.d.ts +0 -10
- package/private/libs/knex/logger.d.ts +0 -15
- package/private/libs/knex/make_knex.d.ts +0 -2
- package/private/libs/knex/transaction.d.ts +0 -37
- package/private/patches/fqdn.d.ts +0 -5
- package/private/patches/i18n.d.ts +0 -51
- package/private/patches/index.d.ts +0 -3
- package/private/patches/json.d.ts +0 -2
- package/private/patches/knex.d.ts +0 -16
- package/private/schemas/bigint.d.ts +0 -95
- package/private/schemas/datetime.d.ts +0 -654
- package/private/schemas/phone.d.ts +0 -199
- package/private/schemas.d.ts +0 -840
- package/private/types.d.ts +0 -69
- package/private/utils.d.ts +0 -186
|
@@ -1,654 +0,0 @@
|
|
|
1
|
-
import { DateTime } from 'luxon';
|
|
2
|
-
import { ExtensionFactory, CustomHelpers, Reference } from 'joi';
|
|
3
|
-
import type { Dayjs } from 'dayjs';
|
|
4
|
-
import type { Tokens } from '../types';
|
|
5
|
-
import type { AnySchema } from '../schemas';
|
|
6
|
-
import type { Zone, LocaleOptions, DateObjectUnits, ZoneOptions, ToISOTimeOptions, ToISODateOptions, ToSQLOptions, ToRelativeOptions } from 'luxon';
|
|
7
|
-
type CallbackOrValue<T> = T | ((dt: DateTime, helpers: CustomHelpers) => T);
|
|
8
|
-
export declare const messages: {
|
|
9
|
-
'datetime.base': string;
|
|
10
|
-
'datetime.exactly': string;
|
|
11
|
-
'datetime.equals': string;
|
|
12
|
-
'datetime.after': string;
|
|
13
|
-
'datetime.greater': string;
|
|
14
|
-
'datetime.before': string;
|
|
15
|
-
'datetime.less': string;
|
|
16
|
-
'datetime.afterOrEqual': string;
|
|
17
|
-
'datetime.min': string;
|
|
18
|
-
'datetime.beforeOrEqual': string;
|
|
19
|
-
'datetime.max': string;
|
|
20
|
-
'datetime.weekend': string;
|
|
21
|
-
'datetime.weekday': string;
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* Types that can be parsed into a DateTime object.
|
|
25
|
-
*
|
|
26
|
-
* Supports Luxon DateTime objects, JavaScript Date objects, Day.js objects,
|
|
27
|
-
* ISO strings, Unix timestamps, and Luxon DateObjectUnits.
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* ```typescript
|
|
31
|
-
* const schema = joi.datetime()
|
|
32
|
-
*
|
|
33
|
-
* // All of these are valid Parseable types:
|
|
34
|
-
* schema.validate('2023-01-01T00:00:00Z') // ISO string
|
|
35
|
-
* schema.validate(1672531200000) // Unix timestamp
|
|
36
|
-
* schema.validate(new Date()) // JavaScript Date
|
|
37
|
-
* schema.validate(DateTime.now()) // Luxon DateTime
|
|
38
|
-
* schema.validate({ year: 2023, month: 1, day: 1 }) // DateObjectUnits
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
export type Parseable = DateTime | Date | Dayjs | string | number | DateObjectUnits;
|
|
42
|
-
/**
|
|
43
|
-
* Schema for datetime validation with comprehensive formatting and comparison methods.
|
|
44
|
-
*
|
|
45
|
-
* Extends the base AnySchema to provide datetime-specific validation rules including
|
|
46
|
-
* comparisons (before/after), weekend/weekday checks, timezone conversions, and
|
|
47
|
-
* various output formatting options.
|
|
48
|
-
*
|
|
49
|
-
* @template TSchema - The output type after validation and potential transformation
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```typescript
|
|
53
|
-
* const schema: DatetimeSchema = joi.datetime()
|
|
54
|
-
* .after('2023-01-01')
|
|
55
|
-
* .toUTC()
|
|
56
|
-
* .toISO()
|
|
57
|
-
*
|
|
58
|
-
* const result = schema.validate('2023-06-15T10:30:00Z')
|
|
59
|
-
* // Returns ISO string in UTC timezone
|
|
60
|
-
* ```
|
|
61
|
-
*/
|
|
62
|
-
export interface DatetimeSchema<TSchema = DateTime> extends AnySchema<TSchema> {
|
|
63
|
-
/**
|
|
64
|
-
* Validates that the datetime is exactly equal to the specified limit.
|
|
65
|
-
* Uses strict equality comparison (===) between DateTime objects.
|
|
66
|
-
*
|
|
67
|
-
* @param limit - The datetime value to compare against
|
|
68
|
-
* @returns The schema instance for method chaining
|
|
69
|
-
*
|
|
70
|
-
* @example
|
|
71
|
-
* ```typescript
|
|
72
|
-
* const schema = joi.datetime().exactly('2023-01-01T00:00:00Z')
|
|
73
|
-
* schema.validate('2023-01-01T00:00:00Z') // Valid
|
|
74
|
-
* schema.validate('2023-01-01T00:00:01Z') // Invalid
|
|
75
|
-
* ```
|
|
76
|
-
*/
|
|
77
|
-
exactly(limit: Parseable | Reference): this;
|
|
78
|
-
/**
|
|
79
|
-
* Validates that the datetime is equal to the specified limit.
|
|
80
|
-
* Uses loose equality comparison (==) between DateTime objects.
|
|
81
|
-
*
|
|
82
|
-
* @param limit - The datetime value to compare against
|
|
83
|
-
* @returns The schema instance for method chaining
|
|
84
|
-
*
|
|
85
|
-
* @example
|
|
86
|
-
* ```typescript
|
|
87
|
-
* const schema = joi.datetime().equals('2023-01-01T00:00:00Z')
|
|
88
|
-
* schema.validate('2023-01-01T00:00:00.000Z') // Valid (same moment)
|
|
89
|
-
* ```
|
|
90
|
-
*/
|
|
91
|
-
equals(limit: Parseable | Reference): this;
|
|
92
|
-
/**
|
|
93
|
-
* Validates that the datetime is after the specified limit.
|
|
94
|
-
*
|
|
95
|
-
* @param limit - The datetime value that the input must be after
|
|
96
|
-
* @returns The schema instance for method chaining
|
|
97
|
-
*
|
|
98
|
-
* @example
|
|
99
|
-
* ```typescript
|
|
100
|
-
* const schema = joi.datetime().after('2023-01-01T00:00:00Z')
|
|
101
|
-
* schema.validate('2023-01-02T00:00:00Z') // Valid
|
|
102
|
-
* schema.validate('2022-12-31T23:59:59Z') // Invalid
|
|
103
|
-
* ```
|
|
104
|
-
*/
|
|
105
|
-
after(limit: Parseable | Reference): this;
|
|
106
|
-
/**
|
|
107
|
-
* Validates that the datetime is greater than the specified limit.
|
|
108
|
-
* Alias for `after()`.
|
|
109
|
-
*
|
|
110
|
-
* @param limit - The datetime value that the input must be greater than
|
|
111
|
-
* @returns The schema instance for method chaining
|
|
112
|
-
*/
|
|
113
|
-
greater(limit: Parseable | Reference): this;
|
|
114
|
-
/**
|
|
115
|
-
* Validates that the datetime is before the specified limit.
|
|
116
|
-
*
|
|
117
|
-
* @param limit - The datetime value that the input must be before
|
|
118
|
-
* @returns The schema instance for method chaining
|
|
119
|
-
*
|
|
120
|
-
* @example
|
|
121
|
-
* ```typescript
|
|
122
|
-
* const schema = joi.datetime().before('2023-12-31T23:59:59Z')
|
|
123
|
-
* schema.validate('2023-06-15T12:00:00Z') // Valid
|
|
124
|
-
* schema.validate('2024-01-01T00:00:00Z') // Invalid
|
|
125
|
-
* ```
|
|
126
|
-
*/
|
|
127
|
-
before(limit: Parseable | Reference): this;
|
|
128
|
-
/**
|
|
129
|
-
* Validates that the datetime is less than the specified limit.
|
|
130
|
-
* Alias for `before()`.
|
|
131
|
-
*
|
|
132
|
-
* @param limit - The datetime value that the input must be less than
|
|
133
|
-
* @returns The schema instance for method chaining
|
|
134
|
-
*/
|
|
135
|
-
less(limit: Parseable | Reference): this;
|
|
136
|
-
/**
|
|
137
|
-
* Validates that the datetime is after or equal to the specified limit.
|
|
138
|
-
*
|
|
139
|
-
* @param limit - The datetime value that the input must be after or equal to
|
|
140
|
-
* @returns The schema instance for method chaining
|
|
141
|
-
*
|
|
142
|
-
* @example
|
|
143
|
-
* ```typescript
|
|
144
|
-
* const schema = joi.datetime().afterOrEqual('2023-01-01T00:00:00Z')
|
|
145
|
-
* schema.validate('2023-01-01T00:00:00Z') // Valid (equal)
|
|
146
|
-
* schema.validate('2023-01-02T00:00:00Z') // Valid (after)
|
|
147
|
-
* schema.validate('2022-12-31T23:59:59Z') // Invalid
|
|
148
|
-
* ```
|
|
149
|
-
*/
|
|
150
|
-
afterOrEqual(limit: Parseable | Reference): this;
|
|
151
|
-
/**
|
|
152
|
-
* Validates that the datetime is greater than or equal to the specified limit.
|
|
153
|
-
* Alias for `afterOrEqual()`.
|
|
154
|
-
*
|
|
155
|
-
* @param limit - The minimum datetime value
|
|
156
|
-
* @returns The schema instance for method chaining
|
|
157
|
-
*/
|
|
158
|
-
min(limit: Parseable | Reference): this;
|
|
159
|
-
/**
|
|
160
|
-
* Validates that the datetime is before or equal to the specified limit.
|
|
161
|
-
*
|
|
162
|
-
* @param limit - The datetime value that the input must be before or equal to
|
|
163
|
-
* @returns The schema instance for method chaining
|
|
164
|
-
*
|
|
165
|
-
* @example
|
|
166
|
-
* ```typescript
|
|
167
|
-
* const schema = joi.datetime().beforeOrEqual('2023-12-31T23:59:59Z')
|
|
168
|
-
* schema.validate('2023-12-31T23:59:59Z') // Valid (equal)
|
|
169
|
-
* schema.validate('2023-06-15T12:00:00Z') // Valid (before)
|
|
170
|
-
* schema.validate('2024-01-01T00:00:00Z') // Invalid
|
|
171
|
-
* ```
|
|
172
|
-
*/
|
|
173
|
-
beforeOrEqual(limit: Parseable | Reference): this;
|
|
174
|
-
/**
|
|
175
|
-
* Validates that the datetime is less than or equal to the specified limit.
|
|
176
|
-
* Alias for `beforeOrEqual()`.
|
|
177
|
-
*
|
|
178
|
-
* @param limit - The maximum datetime value
|
|
179
|
-
* @returns The schema instance for method chaining
|
|
180
|
-
*/
|
|
181
|
-
max(limit: Parseable | Reference): this;
|
|
182
|
-
/**
|
|
183
|
-
* Validates that the datetime falls on a weekend day.
|
|
184
|
-
* Based on the configured weekend days in Luxon settings (default: Saturday and Sunday).
|
|
185
|
-
*
|
|
186
|
-
* @returns The schema instance for method chaining
|
|
187
|
-
*
|
|
188
|
-
* @example
|
|
189
|
-
* ```typescript
|
|
190
|
-
* const schema = joi.datetime().weekend()
|
|
191
|
-
* schema.validate('2023-07-01T12:00:00Z') // Valid if Saturday
|
|
192
|
-
* schema.validate('2023-07-03T12:00:00Z') // Invalid if Monday
|
|
193
|
-
* ```
|
|
194
|
-
*/
|
|
195
|
-
weekend(): this;
|
|
196
|
-
/**
|
|
197
|
-
* Validates that the datetime falls on a weekday (non-weekend day).
|
|
198
|
-
* Based on the configured weekend days in Luxon settings.
|
|
199
|
-
*
|
|
200
|
-
* @returns The schema instance for method chaining
|
|
201
|
-
*
|
|
202
|
-
* @example
|
|
203
|
-
* ```typescript
|
|
204
|
-
* const schema = joi.datetime().weekday()
|
|
205
|
-
* schema.validate('2023-07-03T12:00:00Z') // Valid if Monday
|
|
206
|
-
* schema.validate('2023-07-01T12:00:00Z') // Invalid if Saturday
|
|
207
|
-
* ```
|
|
208
|
-
*/
|
|
209
|
-
weekday(): this;
|
|
210
|
-
/**
|
|
211
|
-
* Converts the datetime to UTC timezone during validation.
|
|
212
|
-
* The output will be a DateTime object in UTC.
|
|
213
|
-
*
|
|
214
|
-
* @returns The schema instance for method chaining
|
|
215
|
-
*
|
|
216
|
-
* @example
|
|
217
|
-
* ```typescript
|
|
218
|
-
* const schema = joi.datetime().toUTC()
|
|
219
|
-
* const result = schema.validate('2023-07-15T10:30:00-05:00')
|
|
220
|
-
* // Returns DateTime in UTC: 2023-07-15T15:30:00Z
|
|
221
|
-
* ```
|
|
222
|
-
*/
|
|
223
|
-
toUTC(): this;
|
|
224
|
-
/**
|
|
225
|
-
* Converts the datetime to local timezone during validation.
|
|
226
|
-
* The output will be a DateTime object in the system's local timezone.
|
|
227
|
-
*
|
|
228
|
-
* @returns The schema instance for method chaining
|
|
229
|
-
*
|
|
230
|
-
* @example
|
|
231
|
-
* ```typescript
|
|
232
|
-
* const schema = joi.datetime().toLocal()
|
|
233
|
-
* const result = schema.validate('2023-07-15T15:30:00Z')
|
|
234
|
-
* // Returns DateTime in local timezone
|
|
235
|
-
* ```
|
|
236
|
-
*/
|
|
237
|
-
toLocal(): this;
|
|
238
|
-
/**
|
|
239
|
-
* Sets the timezone for the datetime during validation.
|
|
240
|
-
*
|
|
241
|
-
* @param zone - The timezone to set (IANA timezone name or Luxon Zone object)
|
|
242
|
-
* @returns The schema instance for method chaining
|
|
243
|
-
*
|
|
244
|
-
* @example
|
|
245
|
-
* ```typescript
|
|
246
|
-
* const schema = joi.datetime().setZone('America/New_York')
|
|
247
|
-
* const result = schema.validate('2023-07-15T15:30:00Z')
|
|
248
|
-
* // Returns DateTime in Eastern timezone
|
|
249
|
-
* ```
|
|
250
|
-
*/
|
|
251
|
-
setZone(zone: string | Zone, opts?: ZoneOptions): this;
|
|
252
|
-
/**
|
|
253
|
-
* Formats the datetime using a custom format string during validation.
|
|
254
|
-
*
|
|
255
|
-
* @param format - The format string (Luxon format tokens) or callback function
|
|
256
|
-
* @returns The schema instance for method chaining
|
|
257
|
-
*
|
|
258
|
-
* @example Static format
|
|
259
|
-
* ```typescript
|
|
260
|
-
* const schema = joi.datetime().toFormat('yyyy-MM-dd HH:mm:ss')
|
|
261
|
-
* const result = schema.validate('2023-07-15T15:30:00Z')
|
|
262
|
-
* // Returns: "2023-07-15 15:30:00"
|
|
263
|
-
* ```
|
|
264
|
-
*
|
|
265
|
-
* @example Callback function (serializable)
|
|
266
|
-
* ```typescript
|
|
267
|
-
* const schema = joi.datetime().toFormat((dt, helpers) =>
|
|
268
|
-
* dt.year > 2000 ? 'yyyy-MM-dd' : 'MM/dd/yy'
|
|
269
|
-
* )
|
|
270
|
-
* ```
|
|
271
|
-
*/
|
|
272
|
-
toFormat(format: CallbackOrValue<Tokens>): this;
|
|
273
|
-
/**
|
|
274
|
-
* Formats the datetime using locale-specific formatting during validation.
|
|
275
|
-
*
|
|
276
|
-
* @param formatOpts - Locale formatting options or callback function
|
|
277
|
-
* @returns The schema instance for method chaining
|
|
278
|
-
*
|
|
279
|
-
* @example Static options
|
|
280
|
-
* ```typescript
|
|
281
|
-
* const schema = joi.datetime().toLocalizedString({ month: 'long', day: 'numeric' })
|
|
282
|
-
* const result = schema.validate('2023-07-15T15:30:00Z')
|
|
283
|
-
* // Returns: "July 15" (or localized equivalent)
|
|
284
|
-
* ```
|
|
285
|
-
*
|
|
286
|
-
* @example Callback function (serializable)
|
|
287
|
-
* ```typescript
|
|
288
|
-
* const schema = joi.datetime().toLocalizedString((dt, helpers) => ({
|
|
289
|
-
* month: dt.month > 6 ? 'long' : 'short',
|
|
290
|
-
* day: 'numeric'
|
|
291
|
-
* }))
|
|
292
|
-
* ```
|
|
293
|
-
*/
|
|
294
|
-
toLocalizedString(formatOpts: CallbackOrValue<LocaleOptions>): this;
|
|
295
|
-
/**
|
|
296
|
-
* Converts the datetime to ISO 8601 string format during validation.
|
|
297
|
-
*
|
|
298
|
-
* @param opts - Options for ISO string formatting or callback function
|
|
299
|
-
* @returns The schema instance for method chaining
|
|
300
|
-
*
|
|
301
|
-
* @example Static options
|
|
302
|
-
* ```typescript
|
|
303
|
-
* const schema = joi.datetime().toISO({ suppressMilliseconds: true })
|
|
304
|
-
* const result = schema.validate('July 15, 2023 3:30 PM')
|
|
305
|
-
* // Returns: "2023-07-15T15:30:00Z"
|
|
306
|
-
* ```
|
|
307
|
-
*
|
|
308
|
-
* @example Callback function (serializable)
|
|
309
|
-
* ```typescript
|
|
310
|
-
* const schema = joi.datetime().toISO((dt, helpers) => ({
|
|
311
|
-
* suppressMilliseconds: true,
|
|
312
|
-
* extendedZone: dt.year > 1970,
|
|
313
|
-
* precision: 'seconds'
|
|
314
|
-
* }))
|
|
315
|
-
* ```
|
|
316
|
-
*/
|
|
317
|
-
toISO(opts?: CallbackOrValue<ToISOTimeOptions>): this;
|
|
318
|
-
/**
|
|
319
|
-
* Converts the datetime to ISO date format (YYYY-MM-DD) during validation.
|
|
320
|
-
*
|
|
321
|
-
* @param opts - Options for ISO date formatting or callback function
|
|
322
|
-
* @returns The schema instance for method chaining
|
|
323
|
-
*
|
|
324
|
-
* @example Static options
|
|
325
|
-
* ```typescript
|
|
326
|
-
* const schema = joi.datetime().toISODate()
|
|
327
|
-
* const result = schema.validate('July 15, 2023 3:30 PM')
|
|
328
|
-
* // Returns: "2023-07-15"
|
|
329
|
-
* ```
|
|
330
|
-
*
|
|
331
|
-
* @example Callback function (serializable)
|
|
332
|
-
* ```typescript
|
|
333
|
-
* const schema = joi.datetime().toISODate((dt, helpers) => ({
|
|
334
|
-
* format: dt.year > 2000 ? 'extended' : 'basic'
|
|
335
|
-
* }))
|
|
336
|
-
* ```
|
|
337
|
-
*/
|
|
338
|
-
toISODate(opts?: CallbackOrValue<ToISODateOptions>): this;
|
|
339
|
-
/**
|
|
340
|
-
* Converts the datetime to ISO week date format during validation.
|
|
341
|
-
*
|
|
342
|
-
* @returns The schema instance for method chaining
|
|
343
|
-
*
|
|
344
|
-
* @example
|
|
345
|
-
* ```typescript
|
|
346
|
-
* const schema = joi.datetime().toISOWeekDate()
|
|
347
|
-
* const result = schema.validate('2023-07-15T15:30:00Z')
|
|
348
|
-
* // Returns: "2023-W28-6"
|
|
349
|
-
* ```
|
|
350
|
-
*/
|
|
351
|
-
toISOWeekDate(): this;
|
|
352
|
-
/**
|
|
353
|
-
* Converts the datetime to ISO time format during validation.
|
|
354
|
-
*
|
|
355
|
-
* @param opts - Options for ISO time formatting or callback function
|
|
356
|
-
* @returns The schema instance for method chaining
|
|
357
|
-
*
|
|
358
|
-
* @example Static options
|
|
359
|
-
* ```typescript
|
|
360
|
-
* const schema = joi.datetime().toISOTime({ suppressMilliseconds: true })
|
|
361
|
-
* const result = schema.validate('2023-07-15T15:30:00Z')
|
|
362
|
-
* // Returns: "15:30:00Z"
|
|
363
|
-
* ```
|
|
364
|
-
*
|
|
365
|
-
* @example Callback function (serializable)
|
|
366
|
-
* ```typescript
|
|
367
|
-
* const schema = joi.datetime().toISOTime((dt, helpers) => ({
|
|
368
|
-
* suppressMilliseconds: dt.millisecond === 0
|
|
369
|
-
* }))
|
|
370
|
-
* ```
|
|
371
|
-
*/
|
|
372
|
-
toISOTime(opts?: CallbackOrValue<ToISOTimeOptions>): this;
|
|
373
|
-
/**
|
|
374
|
-
* Converts the datetime to RFC 2822 format during validation.
|
|
375
|
-
*
|
|
376
|
-
* @returns The schema instance for method chaining
|
|
377
|
-
*
|
|
378
|
-
* @example
|
|
379
|
-
* ```typescript
|
|
380
|
-
* const schema = joi.datetime().toRFC2822()
|
|
381
|
-
* const result = schema.validate('2023-07-15T15:30:00Z')
|
|
382
|
-
* // Returns: "Sat, 15 Jul 2023 15:30:00 +0000"
|
|
383
|
-
* ```
|
|
384
|
-
*/
|
|
385
|
-
toRFC2822(): this;
|
|
386
|
-
/**
|
|
387
|
-
* Converts the datetime to HTTP date format during validation.
|
|
388
|
-
*
|
|
389
|
-
* @returns The schema instance for method chaining
|
|
390
|
-
*
|
|
391
|
-
* @example
|
|
392
|
-
* ```typescript
|
|
393
|
-
* const schema = joi.datetime().toHTTP()
|
|
394
|
-
* const result = schema.validate('2023-07-15T15:30:00Z')
|
|
395
|
-
* // Returns: "Sat, 15 Jul 2023 15:30:00 GMT"
|
|
396
|
-
* ```
|
|
397
|
-
*/
|
|
398
|
-
toHTTP(): this;
|
|
399
|
-
/**
|
|
400
|
-
* Converts the datetime to SQL date format (YYYY-MM-DD) during validation.
|
|
401
|
-
*
|
|
402
|
-
* @returns The schema instance for method chaining
|
|
403
|
-
*
|
|
404
|
-
* @example
|
|
405
|
-
* ```typescript
|
|
406
|
-
* const schema = joi.datetime().toSQLDate()
|
|
407
|
-
* const result = schema.validate('2023-07-15T15:30:00Z')
|
|
408
|
-
* // Returns: "2023-07-15"
|
|
409
|
-
* ```
|
|
410
|
-
*/
|
|
411
|
-
toSQLDate(): this;
|
|
412
|
-
/**
|
|
413
|
-
* Converts the datetime to SQL time format (HH:mm:ss.SSS) during validation.
|
|
414
|
-
*
|
|
415
|
-
* @param opts - Options for SQL time formatting or callback function
|
|
416
|
-
* @returns The schema instance for method chaining
|
|
417
|
-
*
|
|
418
|
-
* @example Static options
|
|
419
|
-
* ```typescript
|
|
420
|
-
* const schema = joi.datetime().toSQLTime({ includeZone: true })
|
|
421
|
-
* const result = schema.validate('2023-07-15T15:30:45.123Z')
|
|
422
|
-
* // Returns: "15:30:45.123 Z"
|
|
423
|
-
* ```
|
|
424
|
-
*
|
|
425
|
-
* @example Callback function (serializable)
|
|
426
|
-
* ```typescript
|
|
427
|
-
* const schema = joi.datetime().toSQLTime((dt, helpers) => ({
|
|
428
|
-
* includeZone: dt.zone.name !== 'UTC'
|
|
429
|
-
* }))
|
|
430
|
-
* ```
|
|
431
|
-
*/
|
|
432
|
-
toSQLTime(opts?: CallbackOrValue<ToSQLOptions>): this;
|
|
433
|
-
/**
|
|
434
|
-
* Converts the datetime to SQL datetime format during validation.
|
|
435
|
-
*
|
|
436
|
-
* @param opts - Options for SQL formatting or callback function
|
|
437
|
-
* @returns The schema instance for method chaining
|
|
438
|
-
*
|
|
439
|
-
* @example Static options
|
|
440
|
-
* ```typescript
|
|
441
|
-
* const schema = joi.datetime().toSQL({ includeZone: false })
|
|
442
|
-
* const result = schema.validate('2023-07-15T15:30:45.123Z')
|
|
443
|
-
* // Returns: "2023-07-15 15:30:45.123"
|
|
444
|
-
* ```
|
|
445
|
-
*
|
|
446
|
-
* @example Callback function (serializable)
|
|
447
|
-
* ```typescript
|
|
448
|
-
* const schema = joi.datetime().toSQL((dt, helpers) => ({
|
|
449
|
-
* includeZone: dt.zone.name !== 'UTC'
|
|
450
|
-
* }))
|
|
451
|
-
* ```
|
|
452
|
-
*/
|
|
453
|
-
toSQL(opts?: CallbackOrValue<ToSQLOptions>): this;
|
|
454
|
-
/**
|
|
455
|
-
* Converts the datetime to milliseconds since Unix epoch during validation.
|
|
456
|
-
*
|
|
457
|
-
* @returns The schema instance for method chaining
|
|
458
|
-
*
|
|
459
|
-
* @example
|
|
460
|
-
* ```typescript
|
|
461
|
-
* const schema = joi.datetime().toMillis()
|
|
462
|
-
* const result = schema.validate('2023-07-15T15:30:00Z')
|
|
463
|
-
* // Returns: 1689433800000
|
|
464
|
-
* ```
|
|
465
|
-
*/
|
|
466
|
-
toMillis(): this;
|
|
467
|
-
/**
|
|
468
|
-
* Converts the datetime to seconds since Unix epoch during validation.
|
|
469
|
-
*
|
|
470
|
-
* @returns The schema instance for method chaining
|
|
471
|
-
*
|
|
472
|
-
* @example
|
|
473
|
-
* ```typescript
|
|
474
|
-
* const schema = joi.datetime().toSeconds()
|
|
475
|
-
* const result = schema.validate('2023-07-15T15:30:00Z')
|
|
476
|
-
* // Returns: 1689433800.0
|
|
477
|
-
* ```
|
|
478
|
-
*/
|
|
479
|
-
toSeconds(): this;
|
|
480
|
-
/**
|
|
481
|
-
* Converts the datetime to Unix timestamp (seconds as integer) during validation.
|
|
482
|
-
*
|
|
483
|
-
* @returns The schema instance for method chaining
|
|
484
|
-
*
|
|
485
|
-
* @example
|
|
486
|
-
* ```typescript
|
|
487
|
-
* const schema = joi.datetime().toUnixInteger()
|
|
488
|
-
* const result = schema.validate('2023-07-15T15:30:00Z')
|
|
489
|
-
* // Returns: 1689433800
|
|
490
|
-
* ```
|
|
491
|
-
*/
|
|
492
|
-
toUnixInteger(): this;
|
|
493
|
-
/**
|
|
494
|
-
* Converts the datetime to JSON string format during validation.
|
|
495
|
-
*
|
|
496
|
-
* @returns The schema instance for method chaining
|
|
497
|
-
*
|
|
498
|
-
* @example
|
|
499
|
-
* ```typescript
|
|
500
|
-
* const schema = joi.datetime().toJSON()
|
|
501
|
-
* const result = schema.validate('2023-07-15T15:30:00Z')
|
|
502
|
-
* // Returns: "2023-07-15T15:30:00.000Z"
|
|
503
|
-
* ```
|
|
504
|
-
*/
|
|
505
|
-
toJSON(): this;
|
|
506
|
-
/**
|
|
507
|
-
* Converts the datetime to BSON format during validation.
|
|
508
|
-
*
|
|
509
|
-
* @returns The schema instance for method chaining
|
|
510
|
-
*
|
|
511
|
-
* @example
|
|
512
|
-
* ```typescript
|
|
513
|
-
* const schema = joi.datetime().toBSON()
|
|
514
|
-
* const result = schema.validate('2023-07-15T15:30:00Z')
|
|
515
|
-
* // Returns: Date object for BSON serialization
|
|
516
|
-
* ```
|
|
517
|
-
*/
|
|
518
|
-
toBSON(): this;
|
|
519
|
-
/**
|
|
520
|
-
* Converts the datetime to a plain object representation during validation.
|
|
521
|
-
*
|
|
522
|
-
* @param opts - Options for object conversion or callback function
|
|
523
|
-
* @returns The schema instance for method chaining
|
|
524
|
-
*
|
|
525
|
-
* @example Static options
|
|
526
|
-
* ```typescript
|
|
527
|
-
* const schema = joi.datetime().toObject({ includeConfig: true })
|
|
528
|
-
* const result = schema.validate('2023-07-15T15:30:00Z')
|
|
529
|
-
* // Returns: { year: 2023, month: 7, day: 15, hour: 15, minute: 30, second: 0, millisecond: 0 }
|
|
530
|
-
* ```
|
|
531
|
-
*
|
|
532
|
-
* @example Callback function (serializable)
|
|
533
|
-
* ```typescript
|
|
534
|
-
* const schema = joi.datetime().toObject((dt, helpers) => ({
|
|
535
|
-
* includeConfig: dt.year > 2000
|
|
536
|
-
* }))
|
|
537
|
-
* ```
|
|
538
|
-
*/
|
|
539
|
-
toObject(opts?: CallbackOrValue<{
|
|
540
|
-
includeConfig?: boolean;
|
|
541
|
-
}>): this;
|
|
542
|
-
/**
|
|
543
|
-
* Converts the datetime to a JavaScript Date object during validation.
|
|
544
|
-
*
|
|
545
|
-
* @returns The schema instance for method chaining
|
|
546
|
-
*
|
|
547
|
-
* @example
|
|
548
|
-
* ```typescript
|
|
549
|
-
* const schema = joi.datetime().toJSDate()
|
|
550
|
-
* const result = schema.validate('2023-07-15T15:30:00Z')
|
|
551
|
-
* // Returns: Date object
|
|
552
|
-
* ```
|
|
553
|
-
*/
|
|
554
|
-
toJSDate(): this;
|
|
555
|
-
/**
|
|
556
|
-
* Converts the datetime to a relative time string during validation.
|
|
557
|
-
*
|
|
558
|
-
* @param opts - Options for relative time formatting or callback function
|
|
559
|
-
* @returns The schema instance for method chaining
|
|
560
|
-
*
|
|
561
|
-
* @example Static options
|
|
562
|
-
* ```typescript
|
|
563
|
-
* const schema = joi.datetime().toRelative({ base: DateTime.now() })
|
|
564
|
-
* const result = schema.validate('2023-07-15T15:30:00Z')
|
|
565
|
-
* // Returns: "2 hours ago" (relative to current time)
|
|
566
|
-
* ```
|
|
567
|
-
*
|
|
568
|
-
* @example Callback function (serializable)
|
|
569
|
-
* ```typescript
|
|
570
|
-
* const schema = joi.datetime().toRelative((dt, helpers) => ({
|
|
571
|
-
* base: dt.year > 2020 ? DateTime.now() : DateTime.fromISO('2020-01-01')
|
|
572
|
-
* }))
|
|
573
|
-
* ```
|
|
574
|
-
*/
|
|
575
|
-
toRelative(opts?: CallbackOrValue<ToRelativeOptions>): this;
|
|
576
|
-
/**
|
|
577
|
-
* Sets the locale for the datetime during validation.
|
|
578
|
-
*
|
|
579
|
-
* @param locale - The locale code (e.g., 'en-US', 'fr-FR')
|
|
580
|
-
* @returns The schema instance for method chaining
|
|
581
|
-
*
|
|
582
|
-
* @example
|
|
583
|
-
* ```typescript
|
|
584
|
-
* const schema = joi.datetime().setLocale('fr-FR').toLocaleString()
|
|
585
|
-
* const result = schema.validate('2023-07-15T15:30:00Z')
|
|
586
|
-
* // Returns localized string in French
|
|
587
|
-
* ```
|
|
588
|
-
*/
|
|
589
|
-
setLocale(locale: string): this;
|
|
590
|
-
}
|
|
591
|
-
/**
|
|
592
|
-
* Joi extension factory for datetime validation using Luxon.
|
|
593
|
-
*
|
|
594
|
-
* Creates a comprehensive datetime validation schema that can parse various input formats
|
|
595
|
-
* (ISO strings, Unix timestamps, JavaScript Dates, Day.js objects, etc.) and convert them
|
|
596
|
-
* to Luxon DateTime objects. Provides extensive validation rules for comparisons, formatting,
|
|
597
|
-
* timezone handling, and output transformations.
|
|
598
|
-
*
|
|
599
|
-
* The schema automatically handles timezone conversion to UTC by default for consistent
|
|
600
|
-
* datetime handling across different environments. All parsing attempts maintain UTC timezone
|
|
601
|
-
* unless explicitly overridden.
|
|
602
|
-
*
|
|
603
|
-
* @param this - The Joi root instance
|
|
604
|
-
* @param joi - The Joi root instance for creating base schemas
|
|
605
|
-
* @returns Joi extension configuration object
|
|
606
|
-
*
|
|
607
|
-
* @example Basic Usage
|
|
608
|
-
* ```typescript
|
|
609
|
-
* import Joi from 'joi'
|
|
610
|
-
* import { datetime } from './datetime'
|
|
611
|
-
*
|
|
612
|
-
* const extendedJoi = Joi.extend(datetime)
|
|
613
|
-
*
|
|
614
|
-
* const schema = extendedJoi.datetime()
|
|
615
|
-
* const result = schema.validate('2023-07-15T15:30:00Z')
|
|
616
|
-
* // Returns { value: DateTime, error: undefined }
|
|
617
|
-
* ```
|
|
618
|
-
*
|
|
619
|
-
* @example With Validation Rules
|
|
620
|
-
* ```typescript
|
|
621
|
-
* const schema = extendedJoi.datetime()
|
|
622
|
-
* .after('2023-01-01')
|
|
623
|
-
* .before('2024-01-01')
|
|
624
|
-
* .weekday()
|
|
625
|
-
*
|
|
626
|
-
* schema.validate('2023-07-17T10:00:00Z') // Valid (Monday in 2023)
|
|
627
|
-
* schema.validate('2023-07-15T10:00:00Z') // Invalid (Saturday)
|
|
628
|
-
* ```
|
|
629
|
-
*
|
|
630
|
-
* @example With Output Formatting
|
|
631
|
-
* ```typescript
|
|
632
|
-
* const schema = extendedJoi.datetime()
|
|
633
|
-
* .toUTC()
|
|
634
|
-
* .toISO()
|
|
635
|
-
*
|
|
636
|
-
* const result = schema.validate('2023-07-15T10:30:00-05:00')
|
|
637
|
-
* // Returns: "2023-07-15T15:30:00.000Z"
|
|
638
|
-
* ```
|
|
639
|
-
*
|
|
640
|
-
* @example Supported Input Formats
|
|
641
|
-
* ```typescript
|
|
642
|
-
* const schema = extendedJoi.datetime()
|
|
643
|
-
*
|
|
644
|
-
* // All of these are valid inputs:
|
|
645
|
-
* schema.validate('2023-07-15T15:30:00Z') // ISO string
|
|
646
|
-
* schema.validate('Sat, 15 Jul 2023 15:30:00 GMT') // RFC2822
|
|
647
|
-
* schema.validate(1689433800000) // Unix timestamp (ms)
|
|
648
|
-
* schema.validate(new Date()) // JavaScript Date
|
|
649
|
-
* schema.validate(DateTime.now()) // Luxon DateTime
|
|
650
|
-
* schema.validate({ year: 2023, month: 7, day: 15 }) // DateObjectUnits
|
|
651
|
-
* ```
|
|
652
|
-
*/
|
|
653
|
-
export declare const datetime: ExtensionFactory;
|
|
654
|
-
export {};
|