@dzeio/schema 0.9.0 → 0.11.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.
package/dist/Schema.d.mts CHANGED
@@ -1,9 +1,10 @@
1
1
  import { StandardSchemaV1 } from '@standard-schema/spec';
2
2
 
3
3
  declare abstract class SchemaItem<Output = any, Input = Output> implements StandardSchemaV1<Input, Output> {
4
+ static readonly id: string;
4
5
  readonly _output: Output;
5
6
  readonly _input: Input;
6
- static id: string;
7
+ readonly id: string;
7
8
  '~standard': StandardSchemaV1.Props<Input, Output>;
8
9
  /**
9
10
  * Function calls saved for serialization
@@ -42,6 +43,7 @@ declare abstract class SchemaItem<Output = any, Input = Output> implements Stand
42
43
  protected readonly items?: Array<unknown>;
43
44
  private invalidError;
44
45
  constructor(items?: Array<unknown> | IArguments);
46
+ setInvalidError(err: string): this;
45
47
  parseJSON(): this;
46
48
  /**
47
49
  * make sure the value is one of the `values`
@@ -50,7 +52,6 @@ declare abstract class SchemaItem<Output = any, Input = Output> implements Stand
50
52
  in(...values: Array<Output>): this;
51
53
  attrs(...attributes: Array<string>): this;
52
54
  attr(...attributes: Array<string>): this;
53
- setInvalidError(err: string): this;
54
55
  clone(): this;
55
56
  defaultValue(value: Output, strict?: boolean): SchemaDefault<this>;
56
57
  default: (value: Output, strict?: boolean) => SchemaDefault<this>;
@@ -58,17 +59,8 @@ declare abstract class SchemaItem<Output = any, Input = Output> implements Stand
58
59
  or<Other extends SchemaItem>(other: Other): SchemaUnion<[this, Other]>;
59
60
  and<Type extends SchemaItem>(other: Type): SchemaIntersection<[this, Type]>;
60
61
  array(): SchemaArray<this>;
61
- /**
62
- * schemas implementing unwrap can return their child component (mostly the value)
63
- *
64
- * ex: s.record(s.number(), s.string()) returns s.string()
65
- *
66
- * es2: s.nullable(s.string()) returns s.string()
67
- */
68
- unwrap?(): SchemaItem;
69
62
  parse(input: unknown, options?: ValidationOptions): ValidationResult<Output>;
70
63
  toJSON(): SchemaJSON;
71
- private deepSerializeItem;
72
64
  addValidation(fn: ((input: Output) => boolean) | {
73
65
  fn: (input: Output) => boolean;
74
66
  error?: string;
@@ -87,6 +79,7 @@ declare abstract class SchemaItem<Output = any, Input = Output> implements Stand
87
79
  input: unknown;
88
80
  errors?: Array<ValidationError>;
89
81
  };
82
+ private deepSerializeItem;
90
83
  abstract isOfType(input: unknown): input is Output;
91
84
  }
92
85
 
@@ -164,13 +157,14 @@ type ModelInfer$1<M extends Model> = {
164
157
  type Literal = string | number | bigint | boolean | null | undefined
165
158
 
166
159
  declare class SchemaAny extends SchemaItem {
167
- static id: string;
160
+ static readonly id = "any";
168
161
  isOfType(_input: unknown): _input is any;
169
162
  }
170
163
 
171
164
  type DateFormat = 'default' | 'iso8601' | 'yy-mm-dd' | 'jj/mm/yy';
172
165
  declare class SchemaDate extends SchemaItem<Date> {
173
- static id: string;
166
+ static readonly id = "date";
167
+ constructor();
174
168
  parseString(format?: DateFormat): this;
175
169
  isOfType(input: unknown): input is Date;
176
170
  }
@@ -178,8 +172,10 @@ declare class SchemaDate extends SchemaItem<Date> {
178
172
  declare class SchemaRecord<Keys extends SchemaItem<string | number | symbol>, Values extends SchemaItem> extends SchemaItem<Record<SchemaInfer<Keys>, SchemaInfer<Values>>> {
179
173
  private readonly keys;
180
174
  private readonly values;
181
- static id: string;
175
+ static readonly id = "record";
182
176
  constructor(keys: Keys, values: Values);
177
+ unwrap(): Values;
178
+ isKeyOfType(key: unknown): boolean;
183
179
  isOfType(input: unknown): input is Record<SchemaInfer<Keys>, SchemaInfer<Values>>;
184
180
  protected parseSubItems(input: unknown, options?: ValidationOptions): {
185
181
  input: unknown;
@@ -189,7 +185,7 @@ declare class SchemaRecord<Keys extends SchemaItem<string | number | symbol>, Va
189
185
 
190
186
  declare class SchemaArray<Child extends SchemaItem, Output = SchemaInfer<Child>, Input = SchemaInputInfer<Child>> extends SchemaItem<Array<Output>, Array<Input>> {
191
187
  readonly values: Child;
192
- static id: string;
188
+ static readonly id = "array";
193
189
  constructor(values: Child);
194
190
  /**
195
191
  * transform the array so it only contains one of each elements
@@ -211,7 +207,7 @@ declare class SchemaArray<Child extends SchemaItem, Output = SchemaInfer<Child>,
211
207
  }
212
208
 
213
209
  declare class SchemaBoolean extends SchemaItem<boolean> {
214
- static id: string;
210
+ static readonly id = "boolean";
215
211
  /**
216
212
  * @param [trueValue='true'] the truhty value (default to `'true'`)
217
213
  * @param [falseValue='false'] the falthy value (default to `'false'`)
@@ -226,14 +222,14 @@ interface EnumLike {
226
222
  }
227
223
  declare class SchemaEnum<E extends EnumLike> extends SchemaItem<E[keyof E]> {
228
224
  private readonly templateEnum;
229
- static id: string;
225
+ static readonly id = "enum";
230
226
  private readonly type;
231
227
  constructor(templateEnum: E);
232
228
  isOfType(input: unknown): input is E[keyof E];
233
229
  }
234
230
 
235
231
  declare class SchemaLiteral<Types extends Array<Literal>> extends SchemaItem<Types[number]> {
236
- static id: string;
232
+ static readonly id = "literal";
237
233
  private readonly values;
238
234
  constructor(...values: Types);
239
235
  isOfType(input: unknown): input is Types[number];
@@ -241,7 +237,7 @@ declare class SchemaLiteral<Types extends Array<Literal>> extends SchemaItem<Typ
241
237
 
242
238
  declare class SchemaNullable<Child extends SchemaItem, Output = SchemaInfer<Child>, Input = SchemaInputInfer<Child>> extends SchemaItem<Output | undefined, Input | null | undefined> {
243
239
  private readonly child;
244
- static id: string;
240
+ static readonly id = "nullable";
245
241
  constructor(child: Child);
246
242
  falsyAsNull(): this;
247
243
  emptyAsNull(): this;
@@ -260,7 +256,7 @@ declare class SchemaNullable<Child extends SchemaItem, Output = SchemaInfer<Chil
260
256
  }
261
257
 
262
258
  declare class SchemaNumber extends SchemaItem<number> {
263
- static id: string;
259
+ static readonly id = "number";
264
260
  /**
265
261
  * validate that the number is less or equal than {@link value}
266
262
  * @param value the maxumum value (inclusive)
@@ -299,7 +295,7 @@ type ModelInfer<M extends Record<string, SchemaItem>> = {
299
295
  };
300
296
  declare class SchemaObject<T extends Record<string, SchemaItem> = any> extends SchemaItem<ModelInfer<T>> {
301
297
  readonly model: T;
302
- static id: string;
298
+ static readonly id = "object";
303
299
  constructor(model: T);
304
300
  isOfType(input: unknown): input is ModelInfer<T>;
305
301
  protected getSubInputs(input: unknown): Array<{
@@ -310,7 +306,7 @@ declare class SchemaObject<T extends Record<string, SchemaItem> = any> extends S
310
306
  }
311
307
 
312
308
  declare class SchemaString extends SchemaItem<string> {
313
- static id: string;
309
+ static readonly id = "string";
314
310
  /**
315
311
  * force the input text to be a minimum of `value` size
316
312
  * @param value the minimum length of the text
@@ -329,7 +325,11 @@ declare class SchemaString extends SchemaItem<string> {
329
325
  */
330
326
  max(value: number, message?: string): this;
331
327
  /**
332
- * the value must not be empty (`''`)
328
+ * trim the input text before all validations
329
+ */
330
+ trim(): this;
331
+ /**
332
+ * force the input text to be not empty (`''`)
333
333
  * @param message
334
334
  * @returns
335
335
  */
@@ -351,9 +351,10 @@ declare class SchemaString extends SchemaItem<string> {
351
351
  }
352
352
 
353
353
  declare class SchemaUnion<Children extends Array<SchemaItem>, Outputs = SchemaInfer<Children[number]>, Inputs = SchemaInputInfer<Children[number]>> extends SchemaItem<Outputs, Inputs> {
354
- static id: string;
354
+ static readonly id = "union";
355
355
  private readonly schemas;
356
356
  constructor(...schemas: Children);
357
+ unwrap(): Children;
357
358
  isOfType(input: unknown): input is Outputs;
358
359
  protected parseSubItems(input: unknown, options?: ValidationOptions): {
359
360
  input: unknown;
@@ -366,9 +367,10 @@ type Prettify<T> = T extends unknown ? {
366
367
  } : never;
367
368
  type UnionToIntersection<U> = (U extends U ? (x: U) => void : never) extends ((x: infer I) => void) ? I : never;
368
369
  declare class SchemaIntersection<Children extends Array<SchemaItem>, Outputs = Prettify<UnionToIntersection<SchemaInfer<Children[number]>>>, Inputs = Prettify<UnionToIntersection<SchemaInfer<Children[number]>>>> extends SchemaItem<Outputs, Inputs> {
369
- static id: string;
370
+ static readonly id = "intersection";
370
371
  private readonly schemas;
371
372
  constructor(...schemas: Children);
373
+ unwrap(): Children;
372
374
  isOfType(input: unknown): input is Outputs;
373
375
  protected parseSubItems(input: unknown, options?: ValidationOptions): {
374
376
  input: unknown;
@@ -380,7 +382,7 @@ declare class SchemaDefault<Child extends SchemaItem, Output = SchemaInfer<Child
380
382
  private readonly child;
381
383
  private readonly defaultVal;
382
384
  private readonly strict;
383
- static id: string;
385
+ static readonly id = "default";
384
386
  constructor(child: Child, defaultVal: Output, strict?: boolean);
385
387
  unwrap(): Child;
386
388
  isOfType(input: unknown): input is Output;
@@ -392,7 +394,7 @@ declare class SchemaDefault<Child extends SchemaItem, Output = SchemaInfer<Child
392
394
  }
393
395
 
394
396
  declare class SchemaFile extends SchemaItem<File> {
395
- static id: string;
397
+ static readonly id = "file";
396
398
  constructor();
397
399
  extension(ext: string, error?: string): this;
398
400
  maxSize(size: number, error?: string): this;
@@ -402,9 +404,10 @@ declare class SchemaFile extends SchemaItem<File> {
402
404
  type TupleToOutputs<Tuple extends Array<SchemaItem>, Result extends Array<any> = []> = number extends Tuple['length'] ? Array<SchemaInfer<Tuple[number]>> : Tuple[Result['length']] extends undefined ? Result : TupleToOutputs<Tuple, [...Result, SchemaInfer<Tuple[Result['length']]>]>;
403
405
  type TupleToInputs<Tuple extends Array<SchemaItem>, Result extends Array<any> = []> = number extends Tuple['length'] ? Array<SchemaInputInfer<Tuple[number]>> : Tuple[Result['length']] extends undefined ? Result : TupleToInputs<Tuple, [...Result, SchemaInputInfer<Tuple[Result['length']]>]>;
404
406
  declare class SchemaTuple<Children extends Array<SchemaItem>, Outputs = TupleToOutputs<Children>, Inputs = TupleToInputs<Children>> extends SchemaItem<Outputs, Inputs> {
405
- static id: string;
407
+ static readonly id = "tuple";
406
408
  private readonly children;
407
409
  constructor(...children: Children);
410
+ unwrap(): Children;
408
411
  isOfType(input: unknown): input is Outputs;
409
412
  protected getSubInputs(input: unknown): Array<{
410
413
  item: SchemaItem;
@@ -414,23 +417,23 @@ declare class SchemaTuple<Children extends Array<SchemaItem>, Outputs = TupleToO
414
417
  }
415
418
 
416
419
  declare class SchemaUndefined extends SchemaItem<undefined> {
417
- static id: string;
420
+ static readonly id = "undefined";
418
421
  isOfType(input: unknown): input is undefined;
419
422
  }
420
423
  declare class SchemaNull extends SchemaItem<null> {
421
- static id: string;
424
+ static readonly id = "null";
422
425
  isOfType(input: unknown): input is null;
423
426
  }
424
427
  declare class SchemaVoid extends SchemaItem<void> {
425
- static id: string;
428
+ static readonly id = "void";
426
429
  isOfType(input: unknown): input is void;
427
430
  }
428
431
  declare class SchemaNullish extends SchemaItem<null | undefined> {
429
- static id: string;
432
+ static readonly id = "nullish";
430
433
  isOfType(input: unknown): input is null | undefined;
431
434
  }
432
435
  declare class SchemaNever extends SchemaItem<never> {
433
- static id: string;
436
+ static readonly id = "never";
434
437
  isOfType(_input: unknown): _input is never;
435
438
  }
436
439
 
@@ -441,6 +444,12 @@ declare function parseQuery<T extends SchemaItem>(schema: T, query: URLSearchPar
441
444
  */
442
445
  declare function parseFormData<T extends SchemaItem>(schema: T, data: FormData, opts?: Parameters<T['parse']>[1]): ReturnType<T['parse']>;
443
446
  declare function parseForm<T extends SchemaItem>(model: T, form: HTMLFormElement, opts?: Parameters<T['parse']>[1]): ReturnType<T['parse']>;
447
+ /**
448
+ * @param schema
449
+ * @param path
450
+ * @returns the correct SchemaItem associated to a key targeted according to the indicated path
451
+ */
452
+ declare function getSchemaItemAtPath(schema: SchemaItem | undefined, path: Array<string | number>): SchemaItem | undefined;
444
453
 
445
454
  /**
446
455
  * Decorator for modifier functions on SchemaItems to save them in the "savedCalls" property for the serialization
@@ -503,4 +512,4 @@ declare class Schema<T extends Record<string, SchemaItem> = Record<string, Schem
503
512
  }
504
513
  declare const s: typeof Schema;
505
514
 
506
- export { type Infer, type InputInfer, type Literal, type Model, type ModelInfer$1 as ModelInfer, SchemaAny, SchemaArray, SchemaBoolean, SchemaDate, SchemaDefault, SchemaEnum, SchemaFile, type SchemaInfer, type SchemaInputInfer, SchemaIntersection, SchemaItem, type SchemaItemJSON, type SchemaJSON, SchemaLiteral, SchemaNever, SchemaNull, SchemaNullable, SchemaNullish, SchemaNumber, SchemaObject, SchemaRecord, SchemaString, SchemaUndefined, SchemaUnion, SchemaVoid, type ValidationError, type ValidationOptions, type ValidationResult, type ValidationResultOld, Schema as default, isNull, parsable, parseForm, parseFormData, parseQuery, s };
515
+ export { type Infer, type InputInfer, type Literal, type Model, type ModelInfer$1 as ModelInfer, SchemaAny, SchemaArray, SchemaBoolean, SchemaDate, SchemaDefault, SchemaEnum, SchemaFile, type SchemaInfer, type SchemaInputInfer, SchemaIntersection, SchemaItem, type SchemaItemJSON, type SchemaJSON, SchemaLiteral, SchemaNever, SchemaNull, SchemaNullable, SchemaNullish, SchemaNumber, SchemaObject, SchemaRecord, SchemaString, SchemaTuple, SchemaUndefined, SchemaUnion, SchemaVoid, type ValidationError, type ValidationOptions, type ValidationResult, type ValidationResultOld, Schema as default, getSchemaItemAtPath, isNull, parsable, parseForm, parseFormData, parseQuery, s };
package/dist/Schema.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  import { StandardSchemaV1 } from '@standard-schema/spec';
2
2
 
3
3
  declare abstract class SchemaItem<Output = any, Input = Output> implements StandardSchemaV1<Input, Output> {
4
+ static readonly id: string;
4
5
  readonly _output: Output;
5
6
  readonly _input: Input;
6
- static id: string;
7
+ readonly id: string;
7
8
  '~standard': StandardSchemaV1.Props<Input, Output>;
8
9
  /**
9
10
  * Function calls saved for serialization
@@ -42,6 +43,7 @@ declare abstract class SchemaItem<Output = any, Input = Output> implements Stand
42
43
  protected readonly items?: Array<unknown>;
43
44
  private invalidError;
44
45
  constructor(items?: Array<unknown> | IArguments);
46
+ setInvalidError(err: string): this;
45
47
  parseJSON(): this;
46
48
  /**
47
49
  * make sure the value is one of the `values`
@@ -50,7 +52,6 @@ declare abstract class SchemaItem<Output = any, Input = Output> implements Stand
50
52
  in(...values: Array<Output>): this;
51
53
  attrs(...attributes: Array<string>): this;
52
54
  attr(...attributes: Array<string>): this;
53
- setInvalidError(err: string): this;
54
55
  clone(): this;
55
56
  defaultValue(value: Output, strict?: boolean): SchemaDefault<this>;
56
57
  default: (value: Output, strict?: boolean) => SchemaDefault<this>;
@@ -58,17 +59,8 @@ declare abstract class SchemaItem<Output = any, Input = Output> implements Stand
58
59
  or<Other extends SchemaItem>(other: Other): SchemaUnion<[this, Other]>;
59
60
  and<Type extends SchemaItem>(other: Type): SchemaIntersection<[this, Type]>;
60
61
  array(): SchemaArray<this>;
61
- /**
62
- * schemas implementing unwrap can return their child component (mostly the value)
63
- *
64
- * ex: s.record(s.number(), s.string()) returns s.string()
65
- *
66
- * es2: s.nullable(s.string()) returns s.string()
67
- */
68
- unwrap?(): SchemaItem;
69
62
  parse(input: unknown, options?: ValidationOptions): ValidationResult<Output>;
70
63
  toJSON(): SchemaJSON;
71
- private deepSerializeItem;
72
64
  addValidation(fn: ((input: Output) => boolean) | {
73
65
  fn: (input: Output) => boolean;
74
66
  error?: string;
@@ -87,6 +79,7 @@ declare abstract class SchemaItem<Output = any, Input = Output> implements Stand
87
79
  input: unknown;
88
80
  errors?: Array<ValidationError>;
89
81
  };
82
+ private deepSerializeItem;
90
83
  abstract isOfType(input: unknown): input is Output;
91
84
  }
92
85
 
@@ -164,13 +157,14 @@ type ModelInfer$1<M extends Model> = {
164
157
  type Literal = string | number | bigint | boolean | null | undefined
165
158
 
166
159
  declare class SchemaAny extends SchemaItem {
167
- static id: string;
160
+ static readonly id = "any";
168
161
  isOfType(_input: unknown): _input is any;
169
162
  }
170
163
 
171
164
  type DateFormat = 'default' | 'iso8601' | 'yy-mm-dd' | 'jj/mm/yy';
172
165
  declare class SchemaDate extends SchemaItem<Date> {
173
- static id: string;
166
+ static readonly id = "date";
167
+ constructor();
174
168
  parseString(format?: DateFormat): this;
175
169
  isOfType(input: unknown): input is Date;
176
170
  }
@@ -178,8 +172,10 @@ declare class SchemaDate extends SchemaItem<Date> {
178
172
  declare class SchemaRecord<Keys extends SchemaItem<string | number | symbol>, Values extends SchemaItem> extends SchemaItem<Record<SchemaInfer<Keys>, SchemaInfer<Values>>> {
179
173
  private readonly keys;
180
174
  private readonly values;
181
- static id: string;
175
+ static readonly id = "record";
182
176
  constructor(keys: Keys, values: Values);
177
+ unwrap(): Values;
178
+ isKeyOfType(key: unknown): boolean;
183
179
  isOfType(input: unknown): input is Record<SchemaInfer<Keys>, SchemaInfer<Values>>;
184
180
  protected parseSubItems(input: unknown, options?: ValidationOptions): {
185
181
  input: unknown;
@@ -189,7 +185,7 @@ declare class SchemaRecord<Keys extends SchemaItem<string | number | symbol>, Va
189
185
 
190
186
  declare class SchemaArray<Child extends SchemaItem, Output = SchemaInfer<Child>, Input = SchemaInputInfer<Child>> extends SchemaItem<Array<Output>, Array<Input>> {
191
187
  readonly values: Child;
192
- static id: string;
188
+ static readonly id = "array";
193
189
  constructor(values: Child);
194
190
  /**
195
191
  * transform the array so it only contains one of each elements
@@ -211,7 +207,7 @@ declare class SchemaArray<Child extends SchemaItem, Output = SchemaInfer<Child>,
211
207
  }
212
208
 
213
209
  declare class SchemaBoolean extends SchemaItem<boolean> {
214
- static id: string;
210
+ static readonly id = "boolean";
215
211
  /**
216
212
  * @param [trueValue='true'] the truhty value (default to `'true'`)
217
213
  * @param [falseValue='false'] the falthy value (default to `'false'`)
@@ -226,14 +222,14 @@ interface EnumLike {
226
222
  }
227
223
  declare class SchemaEnum<E extends EnumLike> extends SchemaItem<E[keyof E]> {
228
224
  private readonly templateEnum;
229
- static id: string;
225
+ static readonly id = "enum";
230
226
  private readonly type;
231
227
  constructor(templateEnum: E);
232
228
  isOfType(input: unknown): input is E[keyof E];
233
229
  }
234
230
 
235
231
  declare class SchemaLiteral<Types extends Array<Literal>> extends SchemaItem<Types[number]> {
236
- static id: string;
232
+ static readonly id = "literal";
237
233
  private readonly values;
238
234
  constructor(...values: Types);
239
235
  isOfType(input: unknown): input is Types[number];
@@ -241,7 +237,7 @@ declare class SchemaLiteral<Types extends Array<Literal>> extends SchemaItem<Typ
241
237
 
242
238
  declare class SchemaNullable<Child extends SchemaItem, Output = SchemaInfer<Child>, Input = SchemaInputInfer<Child>> extends SchemaItem<Output | undefined, Input | null | undefined> {
243
239
  private readonly child;
244
- static id: string;
240
+ static readonly id = "nullable";
245
241
  constructor(child: Child);
246
242
  falsyAsNull(): this;
247
243
  emptyAsNull(): this;
@@ -260,7 +256,7 @@ declare class SchemaNullable<Child extends SchemaItem, Output = SchemaInfer<Chil
260
256
  }
261
257
 
262
258
  declare class SchemaNumber extends SchemaItem<number> {
263
- static id: string;
259
+ static readonly id = "number";
264
260
  /**
265
261
  * validate that the number is less or equal than {@link value}
266
262
  * @param value the maxumum value (inclusive)
@@ -299,7 +295,7 @@ type ModelInfer<M extends Record<string, SchemaItem>> = {
299
295
  };
300
296
  declare class SchemaObject<T extends Record<string, SchemaItem> = any> extends SchemaItem<ModelInfer<T>> {
301
297
  readonly model: T;
302
- static id: string;
298
+ static readonly id = "object";
303
299
  constructor(model: T);
304
300
  isOfType(input: unknown): input is ModelInfer<T>;
305
301
  protected getSubInputs(input: unknown): Array<{
@@ -310,7 +306,7 @@ declare class SchemaObject<T extends Record<string, SchemaItem> = any> extends S
310
306
  }
311
307
 
312
308
  declare class SchemaString extends SchemaItem<string> {
313
- static id: string;
309
+ static readonly id = "string";
314
310
  /**
315
311
  * force the input text to be a minimum of `value` size
316
312
  * @param value the minimum length of the text
@@ -329,7 +325,11 @@ declare class SchemaString extends SchemaItem<string> {
329
325
  */
330
326
  max(value: number, message?: string): this;
331
327
  /**
332
- * the value must not be empty (`''`)
328
+ * trim the input text before all validations
329
+ */
330
+ trim(): this;
331
+ /**
332
+ * force the input text to be not empty (`''`)
333
333
  * @param message
334
334
  * @returns
335
335
  */
@@ -351,9 +351,10 @@ declare class SchemaString extends SchemaItem<string> {
351
351
  }
352
352
 
353
353
  declare class SchemaUnion<Children extends Array<SchemaItem>, Outputs = SchemaInfer<Children[number]>, Inputs = SchemaInputInfer<Children[number]>> extends SchemaItem<Outputs, Inputs> {
354
- static id: string;
354
+ static readonly id = "union";
355
355
  private readonly schemas;
356
356
  constructor(...schemas: Children);
357
+ unwrap(): Children;
357
358
  isOfType(input: unknown): input is Outputs;
358
359
  protected parseSubItems(input: unknown, options?: ValidationOptions): {
359
360
  input: unknown;
@@ -366,9 +367,10 @@ type Prettify<T> = T extends unknown ? {
366
367
  } : never;
367
368
  type UnionToIntersection<U> = (U extends U ? (x: U) => void : never) extends ((x: infer I) => void) ? I : never;
368
369
  declare class SchemaIntersection<Children extends Array<SchemaItem>, Outputs = Prettify<UnionToIntersection<SchemaInfer<Children[number]>>>, Inputs = Prettify<UnionToIntersection<SchemaInfer<Children[number]>>>> extends SchemaItem<Outputs, Inputs> {
369
- static id: string;
370
+ static readonly id = "intersection";
370
371
  private readonly schemas;
371
372
  constructor(...schemas: Children);
373
+ unwrap(): Children;
372
374
  isOfType(input: unknown): input is Outputs;
373
375
  protected parseSubItems(input: unknown, options?: ValidationOptions): {
374
376
  input: unknown;
@@ -380,7 +382,7 @@ declare class SchemaDefault<Child extends SchemaItem, Output = SchemaInfer<Child
380
382
  private readonly child;
381
383
  private readonly defaultVal;
382
384
  private readonly strict;
383
- static id: string;
385
+ static readonly id = "default";
384
386
  constructor(child: Child, defaultVal: Output, strict?: boolean);
385
387
  unwrap(): Child;
386
388
  isOfType(input: unknown): input is Output;
@@ -392,7 +394,7 @@ declare class SchemaDefault<Child extends SchemaItem, Output = SchemaInfer<Child
392
394
  }
393
395
 
394
396
  declare class SchemaFile extends SchemaItem<File> {
395
- static id: string;
397
+ static readonly id = "file";
396
398
  constructor();
397
399
  extension(ext: string, error?: string): this;
398
400
  maxSize(size: number, error?: string): this;
@@ -402,9 +404,10 @@ declare class SchemaFile extends SchemaItem<File> {
402
404
  type TupleToOutputs<Tuple extends Array<SchemaItem>, Result extends Array<any> = []> = number extends Tuple['length'] ? Array<SchemaInfer<Tuple[number]>> : Tuple[Result['length']] extends undefined ? Result : TupleToOutputs<Tuple, [...Result, SchemaInfer<Tuple[Result['length']]>]>;
403
405
  type TupleToInputs<Tuple extends Array<SchemaItem>, Result extends Array<any> = []> = number extends Tuple['length'] ? Array<SchemaInputInfer<Tuple[number]>> : Tuple[Result['length']] extends undefined ? Result : TupleToInputs<Tuple, [...Result, SchemaInputInfer<Tuple[Result['length']]>]>;
404
406
  declare class SchemaTuple<Children extends Array<SchemaItem>, Outputs = TupleToOutputs<Children>, Inputs = TupleToInputs<Children>> extends SchemaItem<Outputs, Inputs> {
405
- static id: string;
407
+ static readonly id = "tuple";
406
408
  private readonly children;
407
409
  constructor(...children: Children);
410
+ unwrap(): Children;
408
411
  isOfType(input: unknown): input is Outputs;
409
412
  protected getSubInputs(input: unknown): Array<{
410
413
  item: SchemaItem;
@@ -414,23 +417,23 @@ declare class SchemaTuple<Children extends Array<SchemaItem>, Outputs = TupleToO
414
417
  }
415
418
 
416
419
  declare class SchemaUndefined extends SchemaItem<undefined> {
417
- static id: string;
420
+ static readonly id = "undefined";
418
421
  isOfType(input: unknown): input is undefined;
419
422
  }
420
423
  declare class SchemaNull extends SchemaItem<null> {
421
- static id: string;
424
+ static readonly id = "null";
422
425
  isOfType(input: unknown): input is null;
423
426
  }
424
427
  declare class SchemaVoid extends SchemaItem<void> {
425
- static id: string;
428
+ static readonly id = "void";
426
429
  isOfType(input: unknown): input is void;
427
430
  }
428
431
  declare class SchemaNullish extends SchemaItem<null | undefined> {
429
- static id: string;
432
+ static readonly id = "nullish";
430
433
  isOfType(input: unknown): input is null | undefined;
431
434
  }
432
435
  declare class SchemaNever extends SchemaItem<never> {
433
- static id: string;
436
+ static readonly id = "never";
434
437
  isOfType(_input: unknown): _input is never;
435
438
  }
436
439
 
@@ -441,6 +444,12 @@ declare function parseQuery<T extends SchemaItem>(schema: T, query: URLSearchPar
441
444
  */
442
445
  declare function parseFormData<T extends SchemaItem>(schema: T, data: FormData, opts?: Parameters<T['parse']>[1]): ReturnType<T['parse']>;
443
446
  declare function parseForm<T extends SchemaItem>(model: T, form: HTMLFormElement, opts?: Parameters<T['parse']>[1]): ReturnType<T['parse']>;
447
+ /**
448
+ * @param schema
449
+ * @param path
450
+ * @returns the correct SchemaItem associated to a key targeted according to the indicated path
451
+ */
452
+ declare function getSchemaItemAtPath(schema: SchemaItem | undefined, path: Array<string | number>): SchemaItem | undefined;
444
453
 
445
454
  /**
446
455
  * Decorator for modifier functions on SchemaItems to save them in the "savedCalls" property for the serialization
@@ -503,4 +512,4 @@ declare class Schema<T extends Record<string, SchemaItem> = Record<string, Schem
503
512
  }
504
513
  declare const s: typeof Schema;
505
514
 
506
- export { type Infer, type InputInfer, type Literal, type Model, type ModelInfer$1 as ModelInfer, SchemaAny, SchemaArray, SchemaBoolean, SchemaDate, SchemaDefault, SchemaEnum, SchemaFile, type SchemaInfer, type SchemaInputInfer, SchemaIntersection, SchemaItem, type SchemaItemJSON, type SchemaJSON, SchemaLiteral, SchemaNever, SchemaNull, SchemaNullable, SchemaNullish, SchemaNumber, SchemaObject, SchemaRecord, SchemaString, SchemaUndefined, SchemaUnion, SchemaVoid, type ValidationError, type ValidationOptions, type ValidationResult, type ValidationResultOld, Schema as default, isNull, parsable, parseForm, parseFormData, parseQuery, s };
515
+ export { type Infer, type InputInfer, type Literal, type Model, type ModelInfer$1 as ModelInfer, SchemaAny, SchemaArray, SchemaBoolean, SchemaDate, SchemaDefault, SchemaEnum, SchemaFile, type SchemaInfer, type SchemaInputInfer, SchemaIntersection, SchemaItem, type SchemaItemJSON, type SchemaJSON, SchemaLiteral, SchemaNever, SchemaNull, SchemaNullable, SchemaNullish, SchemaNumber, SchemaObject, SchemaRecord, SchemaString, SchemaTuple, SchemaUndefined, SchemaUnion, SchemaVoid, type ValidationError, type ValidationOptions, type ValidationResult, type ValidationResultOld, Schema as default, getSchemaItemAtPath, isNull, parsable, parseForm, parseFormData, parseQuery, s };