@ix-xs/node-comfort 1.1.31 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/CHANGELOG.md +190 -0
  2. package/LICENSE +21 -0
  3. package/README.md +210 -748
  4. package/index.js +84 -13
  5. package/package.json +201 -21
  6. package/src/Arr.js +901 -0
  7. package/src/Async.js +585 -0
  8. package/src/Cache.js +329 -0
  9. package/src/Checker.js +979 -188
  10. package/src/Cli.js +1034 -0
  11. package/src/Color.js +415 -0
  12. package/src/Crypto.js +707 -0
  13. package/src/Emitter.js +289 -0
  14. package/src/Env.js +555 -0
  15. package/src/FS.js +1483 -768
  16. package/src/Func.js +692 -0
  17. package/src/Http.js +538 -0
  18. package/src/Id.js +418 -0
  19. package/src/Logger.js +739 -307
  20. package/src/Num.js +849 -0
  21. package/src/Obj.js +904 -0
  22. package/src/SQLite.js +1308 -994
  23. package/src/Schema.js +1586 -0
  24. package/src/Str.js +999 -0
  25. package/src/Sys.js +511 -0
  26. package/src/Time.js +1323 -0
  27. package/src/Utils.js +321 -325
  28. package/src/errors.js +292 -0
  29. package/types/index.d.ts +693 -120
  30. package/types/src/Arr.d.ts +562 -0
  31. package/types/src/Arr.d.ts.map +1 -0
  32. package/types/src/Async.d.ts +321 -0
  33. package/types/src/Async.d.ts.map +1 -0
  34. package/types/src/Cache.d.ts +195 -0
  35. package/types/src/Cache.d.ts.map +1 -0
  36. package/types/src/Checker.d.ts +609 -81
  37. package/types/src/Checker.d.ts.map +1 -1
  38. package/types/src/Cli.d.ts +582 -0
  39. package/types/src/Cli.d.ts.map +1 -0
  40. package/types/src/Color.d.ts +294 -0
  41. package/types/src/Color.d.ts.map +1 -0
  42. package/types/src/Crypto.d.ts +534 -0
  43. package/types/src/Crypto.d.ts.map +1 -0
  44. package/types/src/Emitter.d.ts +170 -0
  45. package/types/src/Emitter.d.ts.map +1 -0
  46. package/types/src/Env.d.ts +382 -0
  47. package/types/src/Env.d.ts.map +1 -0
  48. package/types/src/FS.d.ts +709 -201
  49. package/types/src/FS.d.ts.map +1 -1
  50. package/types/src/Func.d.ts +455 -0
  51. package/types/src/Func.d.ts.map +1 -0
  52. package/types/src/Http.d.ts +374 -0
  53. package/types/src/Http.d.ts.map +1 -0
  54. package/types/src/Id.d.ts +200 -0
  55. package/types/src/Id.d.ts.map +1 -0
  56. package/types/src/Logger.d.ts +374 -24
  57. package/types/src/Logger.d.ts.map +1 -1
  58. package/types/src/Num.d.ts +578 -0
  59. package/types/src/Num.d.ts.map +1 -0
  60. package/types/src/Obj.d.ts +475 -0
  61. package/types/src/Obj.d.ts.map +1 -0
  62. package/types/src/SQLite.d.ts +647 -305
  63. package/types/src/SQLite.d.ts.map +1 -1
  64. package/types/src/Schema.d.ts +940 -0
  65. package/types/src/Schema.d.ts.map +1 -0
  66. package/types/src/Str.d.ts +696 -0
  67. package/types/src/Str.d.ts.map +1 -0
  68. package/types/src/Sys.d.ts +269 -0
  69. package/types/src/Sys.d.ts.map +1 -0
  70. package/types/src/Time.d.ts +664 -0
  71. package/types/src/Time.d.ts.map +1 -0
  72. package/types/src/Utils.d.ts +154 -102
  73. package/types/src/Utils.d.ts.map +1 -1
  74. package/types/src/errors.d.ts +292 -0
  75. package/types/src/errors.d.ts.map +1 -0
  76. package/tsconfig.json +0 -18
  77. package/types/index.d.ts.map +0 -1
@@ -0,0 +1,940 @@
1
+ declare namespace _exports {
2
+ export { Infer, Shape, Simplify, ObjectOutput, SafeParseResult, Message, RefineOptions, ParseContext, Step, CoerceBuilders };
3
+ }
4
+ declare namespace _exports {
5
+ export { string };
6
+ export { number };
7
+ export { boolean };
8
+ export { bigint };
9
+ export { date };
10
+ export { literal };
11
+ export { enumeration as enum };
12
+ export { array };
13
+ export { object };
14
+ export { union };
15
+ export { tuple };
16
+ export { record };
17
+ export { lazy };
18
+ export { instanceOf };
19
+ export { custom };
20
+ export { any };
21
+ export { unknown };
22
+ export { coerce };
23
+ export { Schema };
24
+ }
25
+ export = _exports;
26
+ /**
27
+ * The type a schema produces.
28
+ */
29
+ type Infer<S> = S extends Schema<infer T> ? T : never;
30
+ /**
31
+ * An object of schemas, as passed to `object()`.
32
+ */
33
+ type Shape = Record<string, Schema<any>>;
34
+ /**
35
+ * Flattens a type so editors show it nicely.
36
+ */
37
+ type Simplify<T> = { [K in keyof T]: T[K]; } & {};
38
+ /**
39
+ * The type of an object schema. Keys that accept `undefined` become optional.
40
+ */
41
+ type ObjectOutput<S extends Shape> = Simplify<{ [K in keyof S as undefined extends Infer<S[K]> ? never : K]: Infer<S[K]>; } & { [K in keyof S as undefined extends Infer<S[K]> ? K : never]?: Infer<S[K]>; }>;
42
+ /**
43
+ * What `safeParse()` returns.
44
+ */
45
+ type SafeParseResult<T> = {
46
+ success: true;
47
+ data: T;
48
+ error?: undefined;
49
+ } | {
50
+ success: false;
51
+ data?: undefined;
52
+ error: ValidationError;
53
+ };
54
+ /**
55
+ * An error message: a string, or a function that gets the invalid value.
56
+ */
57
+ type Message = string | ((value: any) => string);
58
+ /**
59
+ * Options for `refine()`.
60
+ */
61
+ type RefineOptions = {
62
+ /**
63
+ * Defaults to `"Invalid value"`.
64
+ */
65
+ message?: Message | undefined;
66
+ /**
67
+ * Where to report the issue, like `["confirmPassword"]` for a cross-field check.
68
+ */
69
+ path?: (string | number)[] | undefined;
70
+ /**
71
+ * Defaults to `"custom"`.
72
+ */
73
+ code?: string | undefined;
74
+ };
75
+ type ParseContext = {
76
+ issues: import("./errors").ValidationIssue[];
77
+ path: Array<string | number>;
78
+ };
79
+ /**
80
+ * A step in a schema: a check, a transformation or a refinement.
81
+ */
82
+ type Step = {
83
+ kind: "check";
84
+ test: (value: any) => boolean;
85
+ code: string;
86
+ message: Message;
87
+ details?: Record<string, unknown>;
88
+ } | {
89
+ kind: "transform";
90
+ fn: (value: any) => any;
91
+ } | {
92
+ kind: "refine";
93
+ test: (value: any) => boolean;
94
+ options: RefineOptions;
95
+ };
96
+ /**
97
+ * The `s.coerce` builders.
98
+ */
99
+ type CoerceBuilders = {
100
+ /**
101
+ * A string schema that turns any value into a string first.
102
+ */
103
+ string: () => StringSchema;
104
+ /**
105
+ * A number schema that converts strings like `"42"`, booleans and dates first.
106
+ */
107
+ number: () => NumberSchema;
108
+ /**
109
+ * A boolean schema that understands `"true"`, `"1"`, `"yes"`, `"on"` and their opposites.
110
+ */
111
+ boolean: () => BooleanSchema;
112
+ /**
113
+ * A date schema that converts ISO strings and timestamps.
114
+ */
115
+ date: () => DateSchema;
116
+ /**
117
+ * A bigint schema that converts numeric strings and integers.
118
+ */
119
+ bigint: () => BigIntSchema;
120
+ };
121
+ /**
122
+ * A string schema.
123
+ *
124
+ * @example
125
+ * s.string().trim().min(1).max(100);
126
+ * s.string().email();
127
+ *
128
+ * @param {{ message?: Message }} [options] Message when the value isn't a string.
129
+ * @returns {StringSchema}
130
+ */
131
+ declare function string(options?: {
132
+ message?: Message;
133
+ }): StringSchema;
134
+ /**
135
+ * A number. `NaN` and `Infinity` are refused.
136
+ *
137
+ * @example
138
+ * s.number().int().min(0).max(120);
139
+ *
140
+ * @param {{ message?: Message }} [options] Message when the value isn't a number.
141
+ * @returns {NumberSchema}
142
+ */
143
+ declare function number(options?: {
144
+ message?: Message;
145
+ }): NumberSchema;
146
+ /**
147
+ * A boolean schema.
148
+ *
149
+ * @param {{ message?: Message }} [options]
150
+ * @returns {BooleanSchema}
151
+ */
152
+ declare function boolean(options?: {
153
+ message?: Message;
154
+ }): BooleanSchema;
155
+ /**
156
+ * A bigint schema.
157
+ *
158
+ * @param {{ message?: Message }} [options]
159
+ * @returns {BigIntSchema}
160
+ */
161
+ declare function bigint(options?: {
162
+ message?: Message;
163
+ }): BigIntSchema;
164
+ /**
165
+ * A valid `Date`.
166
+ *
167
+ * @example
168
+ * s.date().min("2024-01-01");
169
+ *
170
+ * @param {{ message?: Message }} [options]
171
+ * @returns {DateSchema}
172
+ */
173
+ declare function date(options?: {
174
+ message?: Message;
175
+ }): DateSchema;
176
+ /**
177
+ * Exactly this value.
178
+ *
179
+ * @example
180
+ * s.object({ type: s.literal("circle"), radius: s.number() });
181
+ *
182
+ * @template {string | number | boolean | bigint | null | undefined} L
183
+ * @param {L} value
184
+ * @returns {LiteralSchema<L>}
185
+ */
186
+ declare function literal<L extends string | number | boolean | bigint | null | undefined>(value: L): LiteralSchema<L>;
187
+ /**
188
+ * One of these values. The type is their union.
189
+ *
190
+ * @example
191
+ * const Role = s.enum(["admin", "editor", "viewer"]); // Schema<"admin" | "editor" | "viewer">
192
+ * Role.options; // ["admin", "editor", "viewer"]
193
+ *
194
+ * @template {string | number} V
195
+ * @param {readonly V[]} values
196
+ * @param {{ message?: Message }} [options]
197
+ * @returns {LiteralSchema<V>}
198
+ */
199
+ declare function enumeration<V extends string | number>(values: readonly V[], options?: {
200
+ message?: Message;
201
+ }): LiteralSchema<V>;
202
+ /**
203
+ * An array whose items all match `item`.
204
+ *
205
+ * @example
206
+ * s.array(s.string()).min(1).max(10).unique();
207
+ *
208
+ * @template T
209
+ * @param {Schema<T>} item
210
+ * @returns {ArraySchema<T>}
211
+ */
212
+ declare function array<T>(item: Schema<T>): ArraySchema<T>;
213
+ /**
214
+ * An object with known keys. Unknown keys are dropped; `.strict()` rejects
215
+ * them and `.passthrough()` keeps them.
216
+ *
217
+ * @example
218
+ * const Address = s.object({ street: s.string(), zip: s.string().regex(/^\d{5}$/), city: s.string() });
219
+ *
220
+ * @template {Shape} S
221
+ * @param {S} shape
222
+ * @returns {ObjectSchema<S>}
223
+ */
224
+ declare function object<S extends Shape>(shape: S): ObjectSchema<S>;
225
+ /**
226
+ * Matches any of these schemas; the first that fits wins.
227
+ *
228
+ * @example
229
+ * s.union([s.string(), s.number()]); // Schema<string | number>
230
+ *
231
+ * @template {ReadonlyArray<Schema<any>>} U
232
+ * @param {U} options
233
+ * @returns {UnionSchema<Infer<U[number]>>}
234
+ */
235
+ declare function union<U extends ReadonlyArray<Schema<any>>>(options: U): UnionSchema<Infer<U[number]>>;
236
+ /**
237
+ * A fixed-length array with one schema per position.
238
+ *
239
+ * @example
240
+ * s.tuple([s.number(), s.number()]); // Schema<[number, number]>
241
+ *
242
+ * @template {[Schema<any>, ...Schema<any>[]] | []} T
243
+ * @param {T} items
244
+ * @returns {TupleSchema<{ -readonly [K in keyof T]: Infer<T[K]> }>}
245
+ */
246
+ declare function tuple<T extends [Schema<any>, ...Schema<any>[]] | []>(items: T): TupleSchema<{ -readonly [K in keyof T]: Infer<T[K]>; }>;
247
+ /**
248
+ * An object with any keys whose values match a schema, like a dictionary.
249
+ *
250
+ * @example
251
+ * s.record(s.number()); // Record<string, number>
252
+ * s.record(s.boolean(), s.string().regex(/^[a-z]+$/)); // keys checked too
253
+ *
254
+ * @template V
255
+ * @param {Schema<V>} values
256
+ * @param {Schema<string>} [keys]
257
+ * @returns {RecordSchema<V>}
258
+ */
259
+ declare function record<V>(values: Schema<V>, keys?: Schema<string>): RecordSchema<V>;
260
+ /**
261
+ * A schema defined later, for recursive data like trees.
262
+ *
263
+ * @example
264
+ * const Category = s.object({
265
+ * name: s.string(),
266
+ * children: s.lazy(() => s.array(Category)).default([]),
267
+ * });
268
+ *
269
+ * @template T
270
+ * @param {() => Schema<T>} getter
271
+ * @returns {LazySchema<T>}
272
+ */
273
+ declare function lazy<T>(getter: () => Schema<T>): LazySchema<T>;
274
+ /**
275
+ * An instance of a class.
276
+ *
277
+ * @example
278
+ * s.instanceOf(URL);
279
+ *
280
+ * @template {new (...args: any[]) => any} C
281
+ * @param {C} ctor
282
+ * @param {Message} [message]
283
+ * @returns {CustomSchema<InstanceType<C>>}
284
+ */
285
+ declare function instanceOf<C extends new (...args: any[]) => any>(ctor: C, message?: Message): CustomSchema<InstanceType<C>>;
286
+ /**
287
+ * A schema from any test, usually a type guard.
288
+ *
289
+ * @example
290
+ * const Color = s.custom(nc.isHexColor, "Expected a hex color");
291
+ *
292
+ * @template [T=unknown]
293
+ * @param {((value: unknown) => value is T) | ((value: unknown) => boolean)} test
294
+ * @param {Message} [message]
295
+ * @returns {CustomSchema<T>}
296
+ */
297
+ declare function custom<T = unknown>(test: ((value: unknown) => value is T) | ((value: unknown) => boolean), message?: Message): CustomSchema<T>;
298
+ /**
299
+ * Anything, typed as `any`.
300
+ * @returns {Schema<any>}
301
+ */
302
+ declare function any(): Schema<any>;
303
+ /**
304
+ * Anything, typed as `unknown`.
305
+ * @returns {Schema<unknown>}
306
+ */
307
+ declare function unknown(): Schema<unknown>;
308
+ /**
309
+ * The `s.coerce` builders.
310
+ * @typedef {object} CoerceBuilders
311
+ * @property {() => StringSchema} string A string schema that turns any value into a string first.
312
+ * @property {() => NumberSchema} number A number schema that converts strings like `"42"`, booleans and dates first.
313
+ * @property {() => BooleanSchema} boolean A boolean schema that understands `"true"`, `"1"`, `"yes"`, `"on"` and their opposites.
314
+ * @property {() => DateSchema} date A date schema that converts ISO strings and timestamps.
315
+ * @property {() => BigIntSchema} bigint A bigint schema that converts numeric strings and integers.
316
+ */
317
+ /**
318
+ * Schemas that convert their input before checking it. Query strings, form
319
+ * fields and environment variables are always strings, so this is what you
320
+ * want for them.
321
+ *
322
+ * @example
323
+ * const Query = s.object({
324
+ * page: s.coerce.number().int().min(1).default(1),
325
+ * active: s.coerce.boolean().default(false),
326
+ * });
327
+ * Query.parse({ page: "2", active: "true" }); // { page: 2, active: true }
328
+ *
329
+ * @type {CoerceBuilders}
330
+ */
331
+ declare const coerce: CoerceBuilders;
332
+ /**
333
+ * The base of every schema.
334
+ *
335
+ * @template [T=unknown]
336
+ */
337
+ declare class Schema<T = unknown> {
338
+ /** @protected @type {Step[]} */
339
+ protected _steps: Step[];
340
+ /** @protected */
341
+ protected _optional: boolean;
342
+ /** @protected */
343
+ protected _nullable: boolean;
344
+ /** @protected @type {{ value: unknown } | undefined} */
345
+ protected _default: {
346
+ value: unknown;
347
+ } | undefined;
348
+ /** @protected @type {{ value: unknown } | undefined} */
349
+ protected _catch: {
350
+ value: unknown;
351
+ } | undefined;
352
+ /** @protected @type {Message | undefined} */
353
+ protected _typeMessage: Message | undefined;
354
+ /** @protected @type {string | undefined} */
355
+ protected _description: string | undefined;
356
+ /**
357
+ * Checks the type, and coerces when asked. Subclasses override it.
358
+ * @param {unknown} value
359
+ * @param {ParseContext} _ctx
360
+ * @returns {unknown}
361
+ * @protected
362
+ */
363
+ protected _check(value: unknown, _ctx: ParseContext): unknown;
364
+ /**
365
+ * @returns {this}
366
+ * @protected
367
+ */
368
+ protected _clone(): this;
369
+ /**
370
+ * @param {Step} step
371
+ * @returns {this}
372
+ * @protected
373
+ */
374
+ protected _with(step: Step): this;
375
+ /**
376
+ * @param {unknown} input
377
+ * @param {ParseContext} ctx
378
+ * @returns {unknown} The output, or `INVALID`.
379
+ * @protected
380
+ */
381
+ protected _run(input: unknown, ctx: ParseContext): unknown;
382
+ /**
383
+ * Validates a value and returns it, with defaults and transformations
384
+ * applied. Unknown object keys are dropped.
385
+ *
386
+ * @example
387
+ * const port = s.coerce.number().int().min(1).max(65535).parse(process.env.PORT);
388
+ *
389
+ * @param {unknown} value
390
+ * @returns {T}
391
+ * @throws {ValidationError} Listing every issue with its path.
392
+ */
393
+ parse(value: unknown): T;
394
+ /**
395
+ * Validates a value without throwing.
396
+ *
397
+ * @example
398
+ * const result = User.safeParse(req.body);
399
+ * if (!result.success) return res.status(400).json(result.error.flatten());
400
+ * saveUser(result.data);
401
+ *
402
+ * @param {unknown} value
403
+ * @returns {SafeParseResult<T>}
404
+ */
405
+ safeParse(value: unknown): SafeParseResult<T>;
406
+ /**
407
+ * Is the value valid? Works as a type guard. Transformations don't run.
408
+ *
409
+ * @example
410
+ * if (Email.is(input)) sendMail(input); // input is a string here
411
+ *
412
+ * @param {unknown} value
413
+ * @returns {value is T}
414
+ */
415
+ is(value: unknown): value is T;
416
+ /**
417
+ * Also accepts `undefined`. In an object, the key becomes optional.
418
+ *
419
+ * @example
420
+ * s.object({ nickname: s.string().optional() }); // { nickname?: string }
421
+ *
422
+ * @returns {Schema<T | undefined>}
423
+ */
424
+ optional(): Schema<T | undefined>;
425
+ /**
426
+ * Also accepts `null`.
427
+ *
428
+ * @returns {Schema<T | null>}
429
+ */
430
+ nullable(): Schema<T | null>;
431
+ /**
432
+ * Also accepts `null` and `undefined`.
433
+ *
434
+ * @returns {Schema<T | null | undefined>}
435
+ */
436
+ nullish(): Schema<T | null | undefined>;
437
+ /**
438
+ * Uses this value when the input is `undefined`. Objects are copied each
439
+ * time; pass a function to build a fresh value on every parse.
440
+ *
441
+ * @example
442
+ * s.string().default("guest");
443
+ * s.date().default(() => new Date());
444
+ *
445
+ * @param {Exclude<T, undefined> | (() => Exclude<T, undefined>)} value
446
+ * @returns {Schema<Exclude<T, undefined>>}
447
+ */
448
+ default(value: Exclude<T, undefined> | (() => Exclude<T, undefined>)): Schema<Exclude<T, undefined>>;
449
+ /**
450
+ * Returns this value instead of failing when the input is invalid.
451
+ *
452
+ * @example
453
+ * s.number().catch(0).parse("not a number"); // 0
454
+ *
455
+ * @param {T | ((input: unknown) => T)} value A value, or a function that gets the invalid input.
456
+ * @returns {Schema<T>}
457
+ */
458
+ catch(value: T | ((input: unknown) => T)): Schema<T>;
459
+ /**
460
+ * Changes the value once it's valid. Runs after the checks written before it.
461
+ *
462
+ * @example
463
+ * s.string().transform((value) => value.split(",")); // Schema<string[]>
464
+ *
465
+ * @template U
466
+ * @param {(value: T) => U} fn
467
+ * @returns {Schema<U>}
468
+ */
469
+ transform<U>(fn: (value: T) => U): Schema<U>;
470
+ /**
471
+ * Adds your own rule.
472
+ *
473
+ * @example
474
+ * s.object({ password: s.string(), confirm: s.string() })
475
+ * .refine((v) => v.password === v.confirm, { message: "Passwords don't match", path: ["confirm"] });
476
+ *
477
+ * @param {(value: T) => boolean} test Returns `true` when the value is fine.
478
+ * @param {Message | RefineOptions} [options]
479
+ * @returns {this}
480
+ */
481
+ refine(test: (value: T) => boolean, options?: Message | RefineOptions): this;
482
+ /**
483
+ * Accepts values that match this schema or another one.
484
+ *
485
+ * @example
486
+ * s.string().or(s.number()); // Schema<string | number>
487
+ *
488
+ * @template U
489
+ * @param {Schema<U>} other
490
+ * @returns {Schema<T | U>}
491
+ */
492
+ or<U>(other: Schema<U>): Schema<T | U>;
493
+ /**
494
+ * An array of this schema.
495
+ *
496
+ * @example
497
+ * s.string().email().array(); // Schema<string[]>
498
+ *
499
+ * @returns {ArraySchema<T>}
500
+ */
501
+ array(): ArraySchema<T>;
502
+ /**
503
+ * Attaches a description, available as `.description`. Useful to generate
504
+ * docs or forms.
505
+ *
506
+ * @param {string} text
507
+ * @returns {this}
508
+ */
509
+ describe(text: string): this;
510
+ /** The text set with `describe()`. */
511
+ get description(): string | undefined;
512
+ }
513
+ import { ValidationError } from "./errors.js";
514
+ /**
515
+ * A string schema.
516
+ *
517
+ * @extends {Schema<string>}
518
+ */
519
+ declare class StringSchema extends Schema<string> {
520
+ constructor();
521
+ /** @protected */
522
+ protected _coerce: boolean;
523
+ /**
524
+ * @param {(v: string) => boolean} test
525
+ * @param {string} code
526
+ * @param {Message} message
527
+ * @param {Record<string, unknown>} [details]
528
+ * @returns {this}
529
+ * @protected
530
+ */
531
+ protected _rule(test: (v: string) => boolean, code: string, message: Message, details?: Record<string, unknown>): this;
532
+ /**
533
+ * At least `length` characters.
534
+ * @param {number} length
535
+ * @param {Message} [message]
536
+ * @returns {this}
537
+ */
538
+ min(length: number, message?: Message): this;
539
+ /**
540
+ * At most `length` characters.
541
+ * @param {number} length
542
+ * @param {Message} [message]
543
+ * @returns {this}
544
+ */
545
+ max(length: number, message?: Message): this;
546
+ /**
547
+ * Exactly `length` characters.
548
+ * @param {number} length
549
+ * @param {Message} [message]
550
+ * @returns {this}
551
+ */
552
+ length(length: number, message?: Message): this;
553
+ /**
554
+ * Not the empty string.
555
+ * @param {Message} [message]
556
+ * @returns {this}
557
+ */
558
+ nonempty(message?: Message): this;
559
+ /**
560
+ * A valid email address.
561
+ * @param {Message} [message]
562
+ * @returns {this}
563
+ */
564
+ email(message?: Message): this;
565
+ /**
566
+ * An absolute URL.
567
+ * @param {Message | { message?: Message, protocols?: string[] }} [options] A message, or allowed protocols (http and https by default).
568
+ * @returns {this}
569
+ */
570
+ url(options?: Message | {
571
+ message?: Message;
572
+ protocols?: string[];
573
+ }): this;
574
+ /**
575
+ * A UUID.
576
+ * @param {Message} [message]
577
+ * @returns {this}
578
+ */
579
+ uuid(message?: Message): this;
580
+ /**
581
+ * An IP address.
582
+ * @param {4 | 6 | Message} [versionOrMessage] Only IPv4 or IPv6, or a message.
583
+ * @param {Message} [message]
584
+ * @returns {this}
585
+ */
586
+ ip(versionOrMessage?: 4 | 6 | Message, message?: Message): this;
587
+ /**
588
+ * An ISO 8601 date or date-time, like `2024-01-31T10:00:00Z`.
589
+ * @param {Message} [message]
590
+ * @returns {this}
591
+ */
592
+ datetime(message?: Message): this;
593
+ /**
594
+ * Matches a regular expression.
595
+ * @param {RegExp} pattern
596
+ * @param {Message} [message]
597
+ * @returns {this}
598
+ */
599
+ regex(pattern: RegExp, message?: Message): this;
600
+ /**
601
+ * Starts with `prefix`.
602
+ * @param {string} prefix
603
+ * @param {Message} [message]
604
+ * @returns {this}
605
+ */
606
+ startsWith(prefix: string, message?: Message): this;
607
+ /**
608
+ * Ends with `suffix`.
609
+ * @param {string} suffix
610
+ * @param {Message} [message]
611
+ * @returns {this}
612
+ */
613
+ endsWith(suffix: string, message?: Message): this;
614
+ /**
615
+ * Contains `search`.
616
+ * @param {string} search
617
+ * @param {Message} [message]
618
+ * @returns {this}
619
+ */
620
+ includes(search: string, message?: Message): this;
621
+ /**
622
+ * Trims whitespace before the checks that follow.
623
+ * @returns {this}
624
+ */
625
+ trim(): this;
626
+ /**
627
+ * Lowercases before the checks that follow.
628
+ * @returns {this}
629
+ */
630
+ toLowerCase(): this;
631
+ /**
632
+ * Uppercases before the checks that follow.
633
+ * @returns {this}
634
+ */
635
+ toUpperCase(): this;
636
+ }
637
+ /**
638
+ * A number schema.
639
+ *
640
+ * @extends {Schema<number>}
641
+ */
642
+ declare class NumberSchema extends Schema<number> {
643
+ constructor();
644
+ /** @protected */
645
+ protected _coerce: boolean;
646
+ /**
647
+ * @param {(v: number) => boolean} test
648
+ * @param {string} code
649
+ * @param {Message} message
650
+ * @param {Record<string, unknown>} [details]
651
+ * @returns {this}
652
+ * @protected
653
+ */
654
+ protected _rule(test: (v: number) => boolean, code: string, message: Message, details?: Record<string, unknown>): this;
655
+ /**
656
+ * At least `value`.
657
+ * @param {number} value
658
+ * @param {Message} [message]
659
+ * @returns {this}
660
+ */
661
+ min(value: number, message?: Message): this;
662
+ /**
663
+ * At most `value`.
664
+ * @param {number} value
665
+ * @param {Message} [message]
666
+ * @returns {this}
667
+ */
668
+ max(value: number, message?: Message): this;
669
+ /**
670
+ * An integer.
671
+ * @param {Message} [message]
672
+ * @returns {this}
673
+ */
674
+ int(message?: Message): this;
675
+ /**
676
+ * Greater than 0.
677
+ * @param {Message} [message]
678
+ * @returns {this}
679
+ */
680
+ positive(message?: Message): this;
681
+ /**
682
+ * 0 or more.
683
+ * @param {Message} [message]
684
+ * @returns {this}
685
+ */
686
+ nonnegative(message?: Message): this;
687
+ /**
688
+ * Less than 0.
689
+ * @param {Message} [message]
690
+ * @returns {this}
691
+ */
692
+ negative(message?: Message): this;
693
+ /**
694
+ * A multiple of `step`.
695
+ * @param {number} step
696
+ * @param {Message} [message]
697
+ * @returns {this}
698
+ */
699
+ multipleOf(step: number, message?: Message): this;
700
+ }
701
+ /**
702
+ * A boolean schema.
703
+ *
704
+ * @extends {Schema<boolean>}
705
+ */
706
+ declare class BooleanSchema extends Schema<boolean> {
707
+ constructor();
708
+ /** @protected */
709
+ protected _coerce: boolean;
710
+ }
711
+ /**
712
+ * A date schema.
713
+ *
714
+ * @extends {Schema<Date>}
715
+ */
716
+ declare class DateSchema extends Schema<Date> {
717
+ constructor();
718
+ /** @protected */
719
+ protected _coerce: boolean;
720
+ /**
721
+ * On or after `date`.
722
+ * @param {Date | number | string} date
723
+ * @param {Message} [message]
724
+ * @returns {this}
725
+ */
726
+ min(date: Date | number | string, message?: Message): this;
727
+ /**
728
+ * On or before `date`.
729
+ * @param {Date | number | string} date
730
+ * @param {Message} [message]
731
+ * @returns {this}
732
+ */
733
+ max(date: Date | number | string, message?: Message): this;
734
+ }
735
+ /**
736
+ * A bigint schema.
737
+ *
738
+ * @extends {Schema<bigint>}
739
+ */
740
+ declare class BigIntSchema extends Schema<bigint> {
741
+ constructor();
742
+ /** @protected */
743
+ protected _coerce: boolean;
744
+ }
745
+ /**
746
+ * A schema that accepts a fixed set of values.
747
+ *
748
+ * @template T
749
+ * @extends {Schema<T>}
750
+ */
751
+ declare class LiteralSchema<T> extends Schema<T> {
752
+ /** @param {readonly T[]} values */
753
+ constructor(values: readonly T[]);
754
+ /** @protected */
755
+ protected _values: readonly T[];
756
+ /** The accepted values. */
757
+ get options(): T[];
758
+ }
759
+ /**
760
+ * An array schema.
761
+ *
762
+ * @template T
763
+ * @extends {Schema<T[]>}
764
+ */
765
+ declare class ArraySchema<T> extends Schema<T[]> {
766
+ /** @param {Schema<T>} item */
767
+ constructor(item: Schema<T>);
768
+ /** @protected */
769
+ protected _item: Schema<T>;
770
+ /**
771
+ * @param {(v: T[]) => boolean} test
772
+ * @param {string} code
773
+ * @param {Message} message
774
+ * @returns {this}
775
+ * @protected
776
+ */
777
+ protected _rule(test: (v: T[]) => boolean, code: string, message: Message): this;
778
+ /**
779
+ * At least `count` items.
780
+ * @param {number} count
781
+ * @param {Message} [message]
782
+ * @returns {this}
783
+ */
784
+ min(count: number, message?: Message): this;
785
+ /**
786
+ * At most `count` items.
787
+ * @param {number} count
788
+ * @param {Message} [message]
789
+ * @returns {this}
790
+ */
791
+ max(count: number, message?: Message): this;
792
+ /**
793
+ * Exactly `count` items.
794
+ * @param {number} count
795
+ * @param {Message} [message]
796
+ * @returns {this}
797
+ */
798
+ length(count: number, message?: Message): this;
799
+ /**
800
+ * At least one item.
801
+ * @param {Message} [message]
802
+ * @returns {this}
803
+ */
804
+ nonempty(message?: Message): this;
805
+ /**
806
+ * No duplicates, compared by value or by a key.
807
+ * @param {((item: T) => unknown) | Message} [keyOrMessage] A function returning the key, or a message.
808
+ * @param {Message} [message]
809
+ * @returns {this}
810
+ */
811
+ unique(keyOrMessage?: ((item: T) => unknown) | Message, message?: Message): this;
812
+ /** The schema of the items. */
813
+ get element(): Schema<T>;
814
+ }
815
+ /**
816
+ * An object schema.
817
+ *
818
+ * @template {Shape} S
819
+ * @extends {Schema<ObjectOutput<S>>}
820
+ */
821
+ declare class ObjectSchema<S extends Shape> extends Schema<{ [K_1 in keyof S as undefined extends Infer<S[K_1]> ? never : K_1]: Infer<S[K_1]>; } & { [K_2 in keyof S as undefined extends Infer<S[K_2]> ? K_2 : never]?: Infer<S[K_2]> | undefined; } extends infer T ? { [K in keyof T]: T[K]; } : never> {
822
+ /** @param {S} shape */
823
+ constructor(shape: S);
824
+ /** @protected @type {"strip" | "strict" | "passthrough"} */
825
+ protected _unknown: "strip" | "strict" | "passthrough";
826
+ /** @protected */
827
+ protected _shape: S;
828
+ /** The schema of each key. */
829
+ get shape(): S;
830
+ /**
831
+ * Rejects unknown keys instead of dropping them.
832
+ * @returns {this}
833
+ */
834
+ strict(): this;
835
+ /**
836
+ * Keeps unknown keys instead of dropping them.
837
+ * @returns {this}
838
+ */
839
+ passthrough(): this;
840
+ /**
841
+ * Adds keys, or replaces existing ones.
842
+ * @template {Shape} M
843
+ * @param {M} more
844
+ * @returns {ObjectSchema<Omit<S, keyof M> & M>}
845
+ */
846
+ extend<M extends Shape>(more: M): ObjectSchema<Omit<S, keyof M> & M>;
847
+ /**
848
+ * Keeps only some keys.
849
+ * @template {keyof S & string} K
850
+ * @param {readonly K[]} keys
851
+ * @returns {ObjectSchema<Pick<S, K>>}
852
+ */
853
+ pick<K_3 extends keyof S & string>(keys: readonly K_3[]): ObjectSchema<Pick<S, K_3>>;
854
+ /**
855
+ * Drops some keys.
856
+ * @template {keyof S & string} K
857
+ * @param {readonly K[]} keys
858
+ * @returns {ObjectSchema<Omit<S, K>>}
859
+ */
860
+ omit<K_3 extends keyof S & string>(keys: readonly K_3[]): ObjectSchema<Omit<S, K_3>>;
861
+ /**
862
+ * Makes every key optional, which suits PATCH requests.
863
+ * @returns {ObjectSchema<{ [K in keyof S]: Schema<Infer<S[K]> | undefined> }>}
864
+ */
865
+ partial(): ObjectSchema<{ [K_3 in keyof S]: Schema<Infer<S[K_3]> | undefined>; }>;
866
+ }
867
+ /**
868
+ * A schema that accepts any of several schemas.
869
+ *
870
+ * @template T
871
+ * @extends {Schema<T>}
872
+ */
873
+ declare class UnionSchema<T> extends Schema<T> {
874
+ /** @param {ReadonlyArray<Schema<any>>} options */
875
+ constructor(options: ReadonlyArray<Schema<any>>);
876
+ /** @protected */
877
+ protected _options: readonly Schema<any>[];
878
+ }
879
+ /**
880
+ * A fixed-length array schema.
881
+ *
882
+ * @template {any[]} T
883
+ * @extends {Schema<T>}
884
+ */
885
+ declare class TupleSchema<T extends any[]> extends Schema<T> {
886
+ /** @param {ReadonlyArray<Schema<any>>} items */
887
+ constructor(items: ReadonlyArray<Schema<any>>);
888
+ /** @protected */
889
+ protected _items: readonly Schema<any>[];
890
+ }
891
+ /**
892
+ * A dictionary schema.
893
+ *
894
+ * @template V
895
+ * @extends {Schema<Record<string, V>>}
896
+ */
897
+ declare class RecordSchema<V> extends Schema<Record<string, V>> {
898
+ /**
899
+ * @param {Schema<V>} values
900
+ * @param {Schema<string> | undefined} keys
901
+ */
902
+ constructor(values: Schema<V>, keys: Schema<string> | undefined);
903
+ /** @protected */
904
+ protected _values: Schema<V>;
905
+ /** @protected */
906
+ protected _keys: Schema<string> | undefined;
907
+ }
908
+ /**
909
+ * A schema resolved on first use, for recursive data.
910
+ *
911
+ * @template T
912
+ * @extends {Schema<T>}
913
+ */
914
+ declare class LazySchema<T> extends Schema<T> {
915
+ /** @param {() => Schema<T>} getter */
916
+ constructor(getter: () => Schema<T>);
917
+ /** @protected */
918
+ protected _getter: () => Schema<T>;
919
+ }
920
+ /**
921
+ * A schema built from a test function.
922
+ *
923
+ * @template T
924
+ * @extends {Schema<T>}
925
+ */
926
+ declare class CustomSchema<T> extends Schema<T> {
927
+ /**
928
+ * @param {(value: unknown) => boolean} test
929
+ * @param {Message} message
930
+ * @param {string} expected
931
+ */
932
+ constructor(test: (value: unknown) => boolean, message: Message, expected: string);
933
+ /** @protected */
934
+ protected _test: (value: unknown) => boolean;
935
+ /** @protected */
936
+ protected _message: Message;
937
+ /** @protected */
938
+ protected _expected: string;
939
+ }
940
+ //# sourceMappingURL=Schema.d.ts.map