@dzeio/schema 0.9.0 → 0.10.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,13 @@ 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";
174
167
  parseString(format?: DateFormat): this;
175
168
  isOfType(input: unknown): input is Date;
176
169
  }
@@ -178,8 +171,10 @@ declare class SchemaDate extends SchemaItem<Date> {
178
171
  declare class SchemaRecord<Keys extends SchemaItem<string | number | symbol>, Values extends SchemaItem> extends SchemaItem<Record<SchemaInfer<Keys>, SchemaInfer<Values>>> {
179
172
  private readonly keys;
180
173
  private readonly values;
181
- static id: string;
174
+ static readonly id = "record";
182
175
  constructor(keys: Keys, values: Values);
176
+ unwrap(): Values;
177
+ isKeyOfType(key: unknown): boolean;
183
178
  isOfType(input: unknown): input is Record<SchemaInfer<Keys>, SchemaInfer<Values>>;
184
179
  protected parseSubItems(input: unknown, options?: ValidationOptions): {
185
180
  input: unknown;
@@ -189,7 +184,7 @@ declare class SchemaRecord<Keys extends SchemaItem<string | number | symbol>, Va
189
184
 
190
185
  declare class SchemaArray<Child extends SchemaItem, Output = SchemaInfer<Child>, Input = SchemaInputInfer<Child>> extends SchemaItem<Array<Output>, Array<Input>> {
191
186
  readonly values: Child;
192
- static id: string;
187
+ static readonly id = "array";
193
188
  constructor(values: Child);
194
189
  /**
195
190
  * transform the array so it only contains one of each elements
@@ -211,7 +206,7 @@ declare class SchemaArray<Child extends SchemaItem, Output = SchemaInfer<Child>,
211
206
  }
212
207
 
213
208
  declare class SchemaBoolean extends SchemaItem<boolean> {
214
- static id: string;
209
+ static readonly id = "boolean";
215
210
  /**
216
211
  * @param [trueValue='true'] the truhty value (default to `'true'`)
217
212
  * @param [falseValue='false'] the falthy value (default to `'false'`)
@@ -226,14 +221,14 @@ interface EnumLike {
226
221
  }
227
222
  declare class SchemaEnum<E extends EnumLike> extends SchemaItem<E[keyof E]> {
228
223
  private readonly templateEnum;
229
- static id: string;
224
+ static readonly id = "enum";
230
225
  private readonly type;
231
226
  constructor(templateEnum: E);
232
227
  isOfType(input: unknown): input is E[keyof E];
233
228
  }
234
229
 
235
230
  declare class SchemaLiteral<Types extends Array<Literal>> extends SchemaItem<Types[number]> {
236
- static id: string;
231
+ static readonly id = "literal";
237
232
  private readonly values;
238
233
  constructor(...values: Types);
239
234
  isOfType(input: unknown): input is Types[number];
@@ -241,7 +236,7 @@ declare class SchemaLiteral<Types extends Array<Literal>> extends SchemaItem<Typ
241
236
 
242
237
  declare class SchemaNullable<Child extends SchemaItem, Output = SchemaInfer<Child>, Input = SchemaInputInfer<Child>> extends SchemaItem<Output | undefined, Input | null | undefined> {
243
238
  private readonly child;
244
- static id: string;
239
+ static readonly id = "nullable";
245
240
  constructor(child: Child);
246
241
  falsyAsNull(): this;
247
242
  emptyAsNull(): this;
@@ -260,7 +255,7 @@ declare class SchemaNullable<Child extends SchemaItem, Output = SchemaInfer<Chil
260
255
  }
261
256
 
262
257
  declare class SchemaNumber extends SchemaItem<number> {
263
- static id: string;
258
+ static readonly id = "number";
264
259
  /**
265
260
  * validate that the number is less or equal than {@link value}
266
261
  * @param value the maxumum value (inclusive)
@@ -299,7 +294,7 @@ type ModelInfer<M extends Record<string, SchemaItem>> = {
299
294
  };
300
295
  declare class SchemaObject<T extends Record<string, SchemaItem> = any> extends SchemaItem<ModelInfer<T>> {
301
296
  readonly model: T;
302
- static id: string;
297
+ static readonly id = "object";
303
298
  constructor(model: T);
304
299
  isOfType(input: unknown): input is ModelInfer<T>;
305
300
  protected getSubInputs(input: unknown): Array<{
@@ -310,7 +305,7 @@ declare class SchemaObject<T extends Record<string, SchemaItem> = any> extends S
310
305
  }
311
306
 
312
307
  declare class SchemaString extends SchemaItem<string> {
313
- static id: string;
308
+ static readonly id = "string";
314
309
  /**
315
310
  * force the input text to be a minimum of `value` size
316
311
  * @param value the minimum length of the text
@@ -329,7 +324,11 @@ declare class SchemaString extends SchemaItem<string> {
329
324
  */
330
325
  max(value: number, message?: string): this;
331
326
  /**
332
- * the value must not be empty (`''`)
327
+ * trim the input text before all validations
328
+ */
329
+ trim(): this;
330
+ /**
331
+ * force the input text to be not empty (`''`)
333
332
  * @param message
334
333
  * @returns
335
334
  */
@@ -351,9 +350,10 @@ declare class SchemaString extends SchemaItem<string> {
351
350
  }
352
351
 
353
352
  declare class SchemaUnion<Children extends Array<SchemaItem>, Outputs = SchemaInfer<Children[number]>, Inputs = SchemaInputInfer<Children[number]>> extends SchemaItem<Outputs, Inputs> {
354
- static id: string;
353
+ static readonly id = "union";
355
354
  private readonly schemas;
356
355
  constructor(...schemas: Children);
356
+ unwrap(): Children;
357
357
  isOfType(input: unknown): input is Outputs;
358
358
  protected parseSubItems(input: unknown, options?: ValidationOptions): {
359
359
  input: unknown;
@@ -366,9 +366,10 @@ type Prettify<T> = T extends unknown ? {
366
366
  } : never;
367
367
  type UnionToIntersection<U> = (U extends U ? (x: U) => void : never) extends ((x: infer I) => void) ? I : never;
368
368
  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;
369
+ static readonly id = "intersection";
370
370
  private readonly schemas;
371
371
  constructor(...schemas: Children);
372
+ unwrap(): Children;
372
373
  isOfType(input: unknown): input is Outputs;
373
374
  protected parseSubItems(input: unknown, options?: ValidationOptions): {
374
375
  input: unknown;
@@ -380,7 +381,7 @@ declare class SchemaDefault<Child extends SchemaItem, Output = SchemaInfer<Child
380
381
  private readonly child;
381
382
  private readonly defaultVal;
382
383
  private readonly strict;
383
- static id: string;
384
+ static readonly id = "default";
384
385
  constructor(child: Child, defaultVal: Output, strict?: boolean);
385
386
  unwrap(): Child;
386
387
  isOfType(input: unknown): input is Output;
@@ -392,7 +393,7 @@ declare class SchemaDefault<Child extends SchemaItem, Output = SchemaInfer<Child
392
393
  }
393
394
 
394
395
  declare class SchemaFile extends SchemaItem<File> {
395
- static id: string;
396
+ static readonly id = "file";
396
397
  constructor();
397
398
  extension(ext: string, error?: string): this;
398
399
  maxSize(size: number, error?: string): this;
@@ -402,9 +403,10 @@ declare class SchemaFile extends SchemaItem<File> {
402
403
  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
404
  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
405
  declare class SchemaTuple<Children extends Array<SchemaItem>, Outputs = TupleToOutputs<Children>, Inputs = TupleToInputs<Children>> extends SchemaItem<Outputs, Inputs> {
405
- static id: string;
406
+ static readonly id = "tuple";
406
407
  private readonly children;
407
408
  constructor(...children: Children);
409
+ unwrap(): Children;
408
410
  isOfType(input: unknown): input is Outputs;
409
411
  protected getSubInputs(input: unknown): Array<{
410
412
  item: SchemaItem;
@@ -414,23 +416,23 @@ declare class SchemaTuple<Children extends Array<SchemaItem>, Outputs = TupleToO
414
416
  }
415
417
 
416
418
  declare class SchemaUndefined extends SchemaItem<undefined> {
417
- static id: string;
419
+ static readonly id = "undefined";
418
420
  isOfType(input: unknown): input is undefined;
419
421
  }
420
422
  declare class SchemaNull extends SchemaItem<null> {
421
- static id: string;
423
+ static readonly id = "null";
422
424
  isOfType(input: unknown): input is null;
423
425
  }
424
426
  declare class SchemaVoid extends SchemaItem<void> {
425
- static id: string;
427
+ static readonly id = "void";
426
428
  isOfType(input: unknown): input is void;
427
429
  }
428
430
  declare class SchemaNullish extends SchemaItem<null | undefined> {
429
- static id: string;
431
+ static readonly id = "nullish";
430
432
  isOfType(input: unknown): input is null | undefined;
431
433
  }
432
434
  declare class SchemaNever extends SchemaItem<never> {
433
- static id: string;
435
+ static readonly id = "never";
434
436
  isOfType(_input: unknown): _input is never;
435
437
  }
436
438
 
@@ -441,6 +443,12 @@ declare function parseQuery<T extends SchemaItem>(schema: T, query: URLSearchPar
441
443
  */
442
444
  declare function parseFormData<T extends SchemaItem>(schema: T, data: FormData, opts?: Parameters<T['parse']>[1]): ReturnType<T['parse']>;
443
445
  declare function parseForm<T extends SchemaItem>(model: T, form: HTMLFormElement, opts?: Parameters<T['parse']>[1]): ReturnType<T['parse']>;
446
+ /**
447
+ * @param schema
448
+ * @param path
449
+ * @returns the correct SchemaItem associated to a key targeted according to the indicated path
450
+ */
451
+ declare function getSchemaItemAtPath(schema: SchemaItem | undefined, path: Array<string | number>): SchemaItem | undefined;
444
452
 
445
453
  /**
446
454
  * Decorator for modifier functions on SchemaItems to save them in the "savedCalls" property for the serialization
@@ -503,4 +511,4 @@ declare class Schema<T extends Record<string, SchemaItem> = Record<string, Schem
503
511
  }
504
512
  declare const s: typeof Schema;
505
513
 
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 };
514
+ 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,13 @@ 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";
174
167
  parseString(format?: DateFormat): this;
175
168
  isOfType(input: unknown): input is Date;
176
169
  }
@@ -178,8 +171,10 @@ declare class SchemaDate extends SchemaItem<Date> {
178
171
  declare class SchemaRecord<Keys extends SchemaItem<string | number | symbol>, Values extends SchemaItem> extends SchemaItem<Record<SchemaInfer<Keys>, SchemaInfer<Values>>> {
179
172
  private readonly keys;
180
173
  private readonly values;
181
- static id: string;
174
+ static readonly id = "record";
182
175
  constructor(keys: Keys, values: Values);
176
+ unwrap(): Values;
177
+ isKeyOfType(key: unknown): boolean;
183
178
  isOfType(input: unknown): input is Record<SchemaInfer<Keys>, SchemaInfer<Values>>;
184
179
  protected parseSubItems(input: unknown, options?: ValidationOptions): {
185
180
  input: unknown;
@@ -189,7 +184,7 @@ declare class SchemaRecord<Keys extends SchemaItem<string | number | symbol>, Va
189
184
 
190
185
  declare class SchemaArray<Child extends SchemaItem, Output = SchemaInfer<Child>, Input = SchemaInputInfer<Child>> extends SchemaItem<Array<Output>, Array<Input>> {
191
186
  readonly values: Child;
192
- static id: string;
187
+ static readonly id = "array";
193
188
  constructor(values: Child);
194
189
  /**
195
190
  * transform the array so it only contains one of each elements
@@ -211,7 +206,7 @@ declare class SchemaArray<Child extends SchemaItem, Output = SchemaInfer<Child>,
211
206
  }
212
207
 
213
208
  declare class SchemaBoolean extends SchemaItem<boolean> {
214
- static id: string;
209
+ static readonly id = "boolean";
215
210
  /**
216
211
  * @param [trueValue='true'] the truhty value (default to `'true'`)
217
212
  * @param [falseValue='false'] the falthy value (default to `'false'`)
@@ -226,14 +221,14 @@ interface EnumLike {
226
221
  }
227
222
  declare class SchemaEnum<E extends EnumLike> extends SchemaItem<E[keyof E]> {
228
223
  private readonly templateEnum;
229
- static id: string;
224
+ static readonly id = "enum";
230
225
  private readonly type;
231
226
  constructor(templateEnum: E);
232
227
  isOfType(input: unknown): input is E[keyof E];
233
228
  }
234
229
 
235
230
  declare class SchemaLiteral<Types extends Array<Literal>> extends SchemaItem<Types[number]> {
236
- static id: string;
231
+ static readonly id = "literal";
237
232
  private readonly values;
238
233
  constructor(...values: Types);
239
234
  isOfType(input: unknown): input is Types[number];
@@ -241,7 +236,7 @@ declare class SchemaLiteral<Types extends Array<Literal>> extends SchemaItem<Typ
241
236
 
242
237
  declare class SchemaNullable<Child extends SchemaItem, Output = SchemaInfer<Child>, Input = SchemaInputInfer<Child>> extends SchemaItem<Output | undefined, Input | null | undefined> {
243
238
  private readonly child;
244
- static id: string;
239
+ static readonly id = "nullable";
245
240
  constructor(child: Child);
246
241
  falsyAsNull(): this;
247
242
  emptyAsNull(): this;
@@ -260,7 +255,7 @@ declare class SchemaNullable<Child extends SchemaItem, Output = SchemaInfer<Chil
260
255
  }
261
256
 
262
257
  declare class SchemaNumber extends SchemaItem<number> {
263
- static id: string;
258
+ static readonly id = "number";
264
259
  /**
265
260
  * validate that the number is less or equal than {@link value}
266
261
  * @param value the maxumum value (inclusive)
@@ -299,7 +294,7 @@ type ModelInfer<M extends Record<string, SchemaItem>> = {
299
294
  };
300
295
  declare class SchemaObject<T extends Record<string, SchemaItem> = any> extends SchemaItem<ModelInfer<T>> {
301
296
  readonly model: T;
302
- static id: string;
297
+ static readonly id = "object";
303
298
  constructor(model: T);
304
299
  isOfType(input: unknown): input is ModelInfer<T>;
305
300
  protected getSubInputs(input: unknown): Array<{
@@ -310,7 +305,7 @@ declare class SchemaObject<T extends Record<string, SchemaItem> = any> extends S
310
305
  }
311
306
 
312
307
  declare class SchemaString extends SchemaItem<string> {
313
- static id: string;
308
+ static readonly id = "string";
314
309
  /**
315
310
  * force the input text to be a minimum of `value` size
316
311
  * @param value the minimum length of the text
@@ -329,7 +324,11 @@ declare class SchemaString extends SchemaItem<string> {
329
324
  */
330
325
  max(value: number, message?: string): this;
331
326
  /**
332
- * the value must not be empty (`''`)
327
+ * trim the input text before all validations
328
+ */
329
+ trim(): this;
330
+ /**
331
+ * force the input text to be not empty (`''`)
333
332
  * @param message
334
333
  * @returns
335
334
  */
@@ -351,9 +350,10 @@ declare class SchemaString extends SchemaItem<string> {
351
350
  }
352
351
 
353
352
  declare class SchemaUnion<Children extends Array<SchemaItem>, Outputs = SchemaInfer<Children[number]>, Inputs = SchemaInputInfer<Children[number]>> extends SchemaItem<Outputs, Inputs> {
354
- static id: string;
353
+ static readonly id = "union";
355
354
  private readonly schemas;
356
355
  constructor(...schemas: Children);
356
+ unwrap(): Children;
357
357
  isOfType(input: unknown): input is Outputs;
358
358
  protected parseSubItems(input: unknown, options?: ValidationOptions): {
359
359
  input: unknown;
@@ -366,9 +366,10 @@ type Prettify<T> = T extends unknown ? {
366
366
  } : never;
367
367
  type UnionToIntersection<U> = (U extends U ? (x: U) => void : never) extends ((x: infer I) => void) ? I : never;
368
368
  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;
369
+ static readonly id = "intersection";
370
370
  private readonly schemas;
371
371
  constructor(...schemas: Children);
372
+ unwrap(): Children;
372
373
  isOfType(input: unknown): input is Outputs;
373
374
  protected parseSubItems(input: unknown, options?: ValidationOptions): {
374
375
  input: unknown;
@@ -380,7 +381,7 @@ declare class SchemaDefault<Child extends SchemaItem, Output = SchemaInfer<Child
380
381
  private readonly child;
381
382
  private readonly defaultVal;
382
383
  private readonly strict;
383
- static id: string;
384
+ static readonly id = "default";
384
385
  constructor(child: Child, defaultVal: Output, strict?: boolean);
385
386
  unwrap(): Child;
386
387
  isOfType(input: unknown): input is Output;
@@ -392,7 +393,7 @@ declare class SchemaDefault<Child extends SchemaItem, Output = SchemaInfer<Child
392
393
  }
393
394
 
394
395
  declare class SchemaFile extends SchemaItem<File> {
395
- static id: string;
396
+ static readonly id = "file";
396
397
  constructor();
397
398
  extension(ext: string, error?: string): this;
398
399
  maxSize(size: number, error?: string): this;
@@ -402,9 +403,10 @@ declare class SchemaFile extends SchemaItem<File> {
402
403
  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
404
  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
405
  declare class SchemaTuple<Children extends Array<SchemaItem>, Outputs = TupleToOutputs<Children>, Inputs = TupleToInputs<Children>> extends SchemaItem<Outputs, Inputs> {
405
- static id: string;
406
+ static readonly id = "tuple";
406
407
  private readonly children;
407
408
  constructor(...children: Children);
409
+ unwrap(): Children;
408
410
  isOfType(input: unknown): input is Outputs;
409
411
  protected getSubInputs(input: unknown): Array<{
410
412
  item: SchemaItem;
@@ -414,23 +416,23 @@ declare class SchemaTuple<Children extends Array<SchemaItem>, Outputs = TupleToO
414
416
  }
415
417
 
416
418
  declare class SchemaUndefined extends SchemaItem<undefined> {
417
- static id: string;
419
+ static readonly id = "undefined";
418
420
  isOfType(input: unknown): input is undefined;
419
421
  }
420
422
  declare class SchemaNull extends SchemaItem<null> {
421
- static id: string;
423
+ static readonly id = "null";
422
424
  isOfType(input: unknown): input is null;
423
425
  }
424
426
  declare class SchemaVoid extends SchemaItem<void> {
425
- static id: string;
427
+ static readonly id = "void";
426
428
  isOfType(input: unknown): input is void;
427
429
  }
428
430
  declare class SchemaNullish extends SchemaItem<null | undefined> {
429
- static id: string;
431
+ static readonly id = "nullish";
430
432
  isOfType(input: unknown): input is null | undefined;
431
433
  }
432
434
  declare class SchemaNever extends SchemaItem<never> {
433
- static id: string;
435
+ static readonly id = "never";
434
436
  isOfType(_input: unknown): _input is never;
435
437
  }
436
438
 
@@ -441,6 +443,12 @@ declare function parseQuery<T extends SchemaItem>(schema: T, query: URLSearchPar
441
443
  */
442
444
  declare function parseFormData<T extends SchemaItem>(schema: T, data: FormData, opts?: Parameters<T['parse']>[1]): ReturnType<T['parse']>;
443
445
  declare function parseForm<T extends SchemaItem>(model: T, form: HTMLFormElement, opts?: Parameters<T['parse']>[1]): ReturnType<T['parse']>;
446
+ /**
447
+ * @param schema
448
+ * @param path
449
+ * @returns the correct SchemaItem associated to a key targeted according to the indicated path
450
+ */
451
+ declare function getSchemaItemAtPath(schema: SchemaItem | undefined, path: Array<string | number>): SchemaItem | undefined;
444
452
 
445
453
  /**
446
454
  * Decorator for modifier functions on SchemaItems to save them in the "savedCalls" property for the serialization
@@ -503,4 +511,4 @@ declare class Schema<T extends Record<string, SchemaItem> = Record<string, Schem
503
511
  }
504
512
  declare const s: typeof Schema;
505
513
 
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 };
514
+ 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 };