@dzeio/schema 0.7.0 → 0.8.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
@@ -3,6 +3,7 @@ import { StandardSchemaV1 } from '@standard-schema/spec';
3
3
  declare abstract class SchemaItem<Output = any, Input = Output> implements StandardSchemaV1<Input, Output> {
4
4
  readonly _output: Output;
5
5
  readonly _input: Input;
6
+ static id: string;
6
7
  '~standard': StandardSchemaV1.Props<Input, Output>;
7
8
  /**
8
9
  * Function calls saved for serialization
@@ -163,11 +164,13 @@ type ModelInfer$1<M extends Model> = {
163
164
  type Literal = string | number | bigint | boolean | null | undefined
164
165
 
165
166
  declare class SchemaAny extends SchemaItem {
167
+ static id: string;
166
168
  isOfType(_input: unknown): _input is any;
167
169
  }
168
170
 
169
171
  type DateFormat = 'default' | 'iso8601' | 'yy-mm-dd' | 'jj/mm/yy';
170
172
  declare class SchemaDate extends SchemaItem<Date> {
173
+ static id: string;
171
174
  parseString(format?: DateFormat): this;
172
175
  isOfType(input: unknown): input is Date;
173
176
  }
@@ -175,6 +178,7 @@ declare class SchemaDate extends SchemaItem<Date> {
175
178
  declare class SchemaRecord<Keys extends SchemaItem<string | number | symbol>, Values extends SchemaItem> extends SchemaItem<Record<SchemaInfer<Keys>, SchemaInfer<Values>>> {
176
179
  private readonly keys;
177
180
  private readonly values;
181
+ static id: string;
178
182
  constructor(keys: Keys, values: Values);
179
183
  isOfType(input: unknown): input is Record<SchemaInfer<Keys>, SchemaInfer<Values>>;
180
184
  protected parseSubItems(input: unknown, options?: ValidationOptions): {
@@ -185,6 +189,7 @@ declare class SchemaRecord<Keys extends SchemaItem<string | number | symbol>, Va
185
189
 
186
190
  declare class SchemaArray<Child extends SchemaItem, Output = SchemaInfer<Child>, Input = SchemaInputInfer<Child>> extends SchemaItem<Array<Output>, Array<Input>> {
187
191
  readonly values: Child;
192
+ static id: string;
188
193
  constructor(values: Child);
189
194
  /**
190
195
  * transform the array so it only contains one of each elements
@@ -206,6 +211,7 @@ declare class SchemaArray<Child extends SchemaItem, Output = SchemaInfer<Child>,
206
211
  }
207
212
 
208
213
  declare class SchemaBoolean extends SchemaItem<boolean> {
214
+ static id: string;
209
215
  /**
210
216
  * @param [trueValue='true'] the truhty value (default to `'true'`)
211
217
  * @param [falseValue='false'] the falthy value (default to `'false'`)
@@ -220,12 +226,14 @@ interface EnumLike {
220
226
  }
221
227
  declare class SchemaEnum<E extends EnumLike> extends SchemaItem<E[keyof E]> {
222
228
  private readonly templateEnum;
229
+ static id: string;
223
230
  private readonly type;
224
231
  constructor(templateEnum: E);
225
232
  isOfType(input: unknown): input is E[keyof E];
226
233
  }
227
234
 
228
235
  declare class SchemaLiteral<Types extends Array<Literal>> extends SchemaItem<Types[number]> {
236
+ static id: string;
229
237
  private readonly values;
230
238
  constructor(...values: Types);
231
239
  isOfType(input: unknown): input is Types[number];
@@ -233,6 +241,7 @@ declare class SchemaLiteral<Types extends Array<Literal>> extends SchemaItem<Typ
233
241
 
234
242
  declare class SchemaNullable<Child extends SchemaItem, Output = SchemaInfer<Child>, Input = SchemaInputInfer<Child>> extends SchemaItem<Output | undefined, Input | null | undefined> {
235
243
  private readonly child;
244
+ static id: string;
236
245
  constructor(child: Child);
237
246
  falsyAsNull(): this;
238
247
  emptyAsNull(): this;
@@ -251,6 +260,7 @@ declare class SchemaNullable<Child extends SchemaItem, Output = SchemaInfer<Chil
251
260
  }
252
261
 
253
262
  declare class SchemaNumber extends SchemaItem<number> {
263
+ static id: string;
254
264
  /**
255
265
  * validate that the number is less or equal than {@link value}
256
266
  * @param value the maxumum value (inclusive)
@@ -289,7 +299,7 @@ type ModelInfer<M extends Record<string, SchemaItem>> = {
289
299
  };
290
300
  declare class SchemaObject<T extends Record<string, SchemaItem> = any> extends SchemaItem<ModelInfer<T>> {
291
301
  readonly model: T;
292
- id: string;
302
+ static id: string;
293
303
  constructor(model: T);
294
304
  isOfType(input: unknown): input is ModelInfer<T>;
295
305
  protected getSubInputs(input: unknown): Array<{
@@ -300,6 +310,7 @@ declare class SchemaObject<T extends Record<string, SchemaItem> = any> extends S
300
310
  }
301
311
 
302
312
  declare class SchemaString extends SchemaItem<string> {
313
+ static id: string;
303
314
  /**
304
315
  * force the input text to be a minimum of `value` size
305
316
  * @param value the minimum length of the text
@@ -340,6 +351,7 @@ declare class SchemaString extends SchemaItem<string> {
340
351
  }
341
352
 
342
353
  declare class SchemaUnion<Children extends Array<SchemaItem>, Outputs = SchemaInfer<Children[number]>, Inputs = SchemaInputInfer<Children[number]>> extends SchemaItem<Outputs, Inputs> {
354
+ static id: string;
343
355
  private readonly schemas;
344
356
  constructor(...schemas: Children);
345
357
  isOfType(input: unknown): input is Outputs;
@@ -354,6 +366,7 @@ type Prettify<T> = T extends unknown ? {
354
366
  } : never;
355
367
  type UnionToIntersection<U> = (U extends U ? (x: U) => void : never) extends ((x: infer I) => void) ? I : never;
356
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;
357
370
  private readonly schemas;
358
371
  constructor(...schemas: Children);
359
372
  isOfType(input: unknown): input is Outputs;
@@ -367,6 +380,7 @@ declare class SchemaDefault<Child extends SchemaItem, Output = SchemaInfer<Child
367
380
  private readonly child;
368
381
  private readonly defaultVal;
369
382
  private readonly strict;
383
+ static id: string;
370
384
  constructor(child: Child, defaultVal: Output, strict?: boolean);
371
385
  unwrap(): Child;
372
386
  isOfType(input: unknown): input is Output;
@@ -378,6 +392,7 @@ declare class SchemaDefault<Child extends SchemaItem, Output = SchemaInfer<Child
378
392
  }
379
393
 
380
394
  declare class SchemaFile extends SchemaItem<File> {
395
+ static id: string;
381
396
  constructor();
382
397
  extension(ext: string, error?: string): this;
383
398
  maxSize(size: number, error?: string): this;
@@ -387,6 +402,7 @@ declare class SchemaFile extends SchemaItem<File> {
387
402
  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']]>]>;
388
403
  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']]>]>;
389
404
  declare class SchemaTuple<Children extends Array<SchemaItem>, Outputs = TupleToOutputs<Children>, Inputs = TupleToInputs<Children>> extends SchemaItem<Outputs, Inputs> {
405
+ static id: string;
390
406
  private readonly children;
391
407
  constructor(...children: Children);
392
408
  isOfType(input: unknown): input is Outputs;
@@ -398,18 +414,23 @@ declare class SchemaTuple<Children extends Array<SchemaItem>, Outputs = TupleToO
398
414
  }
399
415
 
400
416
  declare class SchemaUndefined extends SchemaItem<undefined> {
417
+ static id: string;
401
418
  isOfType(input: unknown): input is undefined;
402
419
  }
403
420
  declare class SchemaNull extends SchemaItem<null> {
421
+ static id: string;
404
422
  isOfType(input: unknown): input is null;
405
423
  }
406
424
  declare class SchemaVoid extends SchemaItem<void> {
425
+ static id: string;
407
426
  isOfType(input: unknown): input is void;
408
427
  }
409
428
  declare class SchemaNullish extends SchemaItem<null | undefined> {
429
+ static id: string;
410
430
  isOfType(input: unknown): input is null | undefined;
411
431
  }
412
432
  declare class SchemaNever extends SchemaItem<never> {
433
+ static id: string;
413
434
  isOfType(_input: unknown): _input is never;
414
435
  }
415
436
 
@@ -425,7 +446,9 @@ declare function parseForm<T extends SchemaItem>(model: T, form: HTMLFormElement
425
446
  * Decorator for modifier functions on SchemaItems to save them in the "savedCalls" property for the serialization
426
447
  */
427
448
  declare function parsable(): (target: object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<any>) => TypedPropertyDescriptor<any>;
428
- type SchemaItemStatic = new (...args: Array<any>) => SchemaItem;
449
+ type SchemaItemStatic = (new (...args: Array<any>) => SchemaItem) & {
450
+ id: string;
451
+ };
429
452
  declare class Schema<T extends Record<string, SchemaItem> = Record<string, SchemaItem>> extends SchemaObject<T> {
430
453
  private static readonly registeredModules;
431
454
  static register(module: SchemaItemStatic): void;
package/dist/Schema.d.ts CHANGED
@@ -3,6 +3,7 @@ import { StandardSchemaV1 } from '@standard-schema/spec';
3
3
  declare abstract class SchemaItem<Output = any, Input = Output> implements StandardSchemaV1<Input, Output> {
4
4
  readonly _output: Output;
5
5
  readonly _input: Input;
6
+ static id: string;
6
7
  '~standard': StandardSchemaV1.Props<Input, Output>;
7
8
  /**
8
9
  * Function calls saved for serialization
@@ -163,11 +164,13 @@ type ModelInfer$1<M extends Model> = {
163
164
  type Literal = string | number | bigint | boolean | null | undefined
164
165
 
165
166
  declare class SchemaAny extends SchemaItem {
167
+ static id: string;
166
168
  isOfType(_input: unknown): _input is any;
167
169
  }
168
170
 
169
171
  type DateFormat = 'default' | 'iso8601' | 'yy-mm-dd' | 'jj/mm/yy';
170
172
  declare class SchemaDate extends SchemaItem<Date> {
173
+ static id: string;
171
174
  parseString(format?: DateFormat): this;
172
175
  isOfType(input: unknown): input is Date;
173
176
  }
@@ -175,6 +178,7 @@ declare class SchemaDate extends SchemaItem<Date> {
175
178
  declare class SchemaRecord<Keys extends SchemaItem<string | number | symbol>, Values extends SchemaItem> extends SchemaItem<Record<SchemaInfer<Keys>, SchemaInfer<Values>>> {
176
179
  private readonly keys;
177
180
  private readonly values;
181
+ static id: string;
178
182
  constructor(keys: Keys, values: Values);
179
183
  isOfType(input: unknown): input is Record<SchemaInfer<Keys>, SchemaInfer<Values>>;
180
184
  protected parseSubItems(input: unknown, options?: ValidationOptions): {
@@ -185,6 +189,7 @@ declare class SchemaRecord<Keys extends SchemaItem<string | number | symbol>, Va
185
189
 
186
190
  declare class SchemaArray<Child extends SchemaItem, Output = SchemaInfer<Child>, Input = SchemaInputInfer<Child>> extends SchemaItem<Array<Output>, Array<Input>> {
187
191
  readonly values: Child;
192
+ static id: string;
188
193
  constructor(values: Child);
189
194
  /**
190
195
  * transform the array so it only contains one of each elements
@@ -206,6 +211,7 @@ declare class SchemaArray<Child extends SchemaItem, Output = SchemaInfer<Child>,
206
211
  }
207
212
 
208
213
  declare class SchemaBoolean extends SchemaItem<boolean> {
214
+ static id: string;
209
215
  /**
210
216
  * @param [trueValue='true'] the truhty value (default to `'true'`)
211
217
  * @param [falseValue='false'] the falthy value (default to `'false'`)
@@ -220,12 +226,14 @@ interface EnumLike {
220
226
  }
221
227
  declare class SchemaEnum<E extends EnumLike> extends SchemaItem<E[keyof E]> {
222
228
  private readonly templateEnum;
229
+ static id: string;
223
230
  private readonly type;
224
231
  constructor(templateEnum: E);
225
232
  isOfType(input: unknown): input is E[keyof E];
226
233
  }
227
234
 
228
235
  declare class SchemaLiteral<Types extends Array<Literal>> extends SchemaItem<Types[number]> {
236
+ static id: string;
229
237
  private readonly values;
230
238
  constructor(...values: Types);
231
239
  isOfType(input: unknown): input is Types[number];
@@ -233,6 +241,7 @@ declare class SchemaLiteral<Types extends Array<Literal>> extends SchemaItem<Typ
233
241
 
234
242
  declare class SchemaNullable<Child extends SchemaItem, Output = SchemaInfer<Child>, Input = SchemaInputInfer<Child>> extends SchemaItem<Output | undefined, Input | null | undefined> {
235
243
  private readonly child;
244
+ static id: string;
236
245
  constructor(child: Child);
237
246
  falsyAsNull(): this;
238
247
  emptyAsNull(): this;
@@ -251,6 +260,7 @@ declare class SchemaNullable<Child extends SchemaItem, Output = SchemaInfer<Chil
251
260
  }
252
261
 
253
262
  declare class SchemaNumber extends SchemaItem<number> {
263
+ static id: string;
254
264
  /**
255
265
  * validate that the number is less or equal than {@link value}
256
266
  * @param value the maxumum value (inclusive)
@@ -289,7 +299,7 @@ type ModelInfer<M extends Record<string, SchemaItem>> = {
289
299
  };
290
300
  declare class SchemaObject<T extends Record<string, SchemaItem> = any> extends SchemaItem<ModelInfer<T>> {
291
301
  readonly model: T;
292
- id: string;
302
+ static id: string;
293
303
  constructor(model: T);
294
304
  isOfType(input: unknown): input is ModelInfer<T>;
295
305
  protected getSubInputs(input: unknown): Array<{
@@ -300,6 +310,7 @@ declare class SchemaObject<T extends Record<string, SchemaItem> = any> extends S
300
310
  }
301
311
 
302
312
  declare class SchemaString extends SchemaItem<string> {
313
+ static id: string;
303
314
  /**
304
315
  * force the input text to be a minimum of `value` size
305
316
  * @param value the minimum length of the text
@@ -340,6 +351,7 @@ declare class SchemaString extends SchemaItem<string> {
340
351
  }
341
352
 
342
353
  declare class SchemaUnion<Children extends Array<SchemaItem>, Outputs = SchemaInfer<Children[number]>, Inputs = SchemaInputInfer<Children[number]>> extends SchemaItem<Outputs, Inputs> {
354
+ static id: string;
343
355
  private readonly schemas;
344
356
  constructor(...schemas: Children);
345
357
  isOfType(input: unknown): input is Outputs;
@@ -354,6 +366,7 @@ type Prettify<T> = T extends unknown ? {
354
366
  } : never;
355
367
  type UnionToIntersection<U> = (U extends U ? (x: U) => void : never) extends ((x: infer I) => void) ? I : never;
356
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;
357
370
  private readonly schemas;
358
371
  constructor(...schemas: Children);
359
372
  isOfType(input: unknown): input is Outputs;
@@ -367,6 +380,7 @@ declare class SchemaDefault<Child extends SchemaItem, Output = SchemaInfer<Child
367
380
  private readonly child;
368
381
  private readonly defaultVal;
369
382
  private readonly strict;
383
+ static id: string;
370
384
  constructor(child: Child, defaultVal: Output, strict?: boolean);
371
385
  unwrap(): Child;
372
386
  isOfType(input: unknown): input is Output;
@@ -378,6 +392,7 @@ declare class SchemaDefault<Child extends SchemaItem, Output = SchemaInfer<Child
378
392
  }
379
393
 
380
394
  declare class SchemaFile extends SchemaItem<File> {
395
+ static id: string;
381
396
  constructor();
382
397
  extension(ext: string, error?: string): this;
383
398
  maxSize(size: number, error?: string): this;
@@ -387,6 +402,7 @@ declare class SchemaFile extends SchemaItem<File> {
387
402
  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']]>]>;
388
403
  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']]>]>;
389
404
  declare class SchemaTuple<Children extends Array<SchemaItem>, Outputs = TupleToOutputs<Children>, Inputs = TupleToInputs<Children>> extends SchemaItem<Outputs, Inputs> {
405
+ static id: string;
390
406
  private readonly children;
391
407
  constructor(...children: Children);
392
408
  isOfType(input: unknown): input is Outputs;
@@ -398,18 +414,23 @@ declare class SchemaTuple<Children extends Array<SchemaItem>, Outputs = TupleToO
398
414
  }
399
415
 
400
416
  declare class SchemaUndefined extends SchemaItem<undefined> {
417
+ static id: string;
401
418
  isOfType(input: unknown): input is undefined;
402
419
  }
403
420
  declare class SchemaNull extends SchemaItem<null> {
421
+ static id: string;
404
422
  isOfType(input: unknown): input is null;
405
423
  }
406
424
  declare class SchemaVoid extends SchemaItem<void> {
425
+ static id: string;
407
426
  isOfType(input: unknown): input is void;
408
427
  }
409
428
  declare class SchemaNullish extends SchemaItem<null | undefined> {
429
+ static id: string;
410
430
  isOfType(input: unknown): input is null | undefined;
411
431
  }
412
432
  declare class SchemaNever extends SchemaItem<never> {
433
+ static id: string;
413
434
  isOfType(_input: unknown): _input is never;
414
435
  }
415
436
 
@@ -425,7 +446,9 @@ declare function parseForm<T extends SchemaItem>(model: T, form: HTMLFormElement
425
446
  * Decorator for modifier functions on SchemaItems to save them in the "savedCalls" property for the serialization
426
447
  */
427
448
  declare function parsable(): (target: object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<any>) => TypedPropertyDescriptor<any>;
428
- type SchemaItemStatic = new (...args: Array<any>) => SchemaItem;
449
+ type SchemaItemStatic = (new (...args: Array<any>) => SchemaItem) & {
450
+ id: string;
451
+ };
429
452
  declare class Schema<T extends Record<string, SchemaItem> = Record<string, SchemaItem>> extends SchemaObject<T> {
430
453
  private static readonly registeredModules;
431
454
  static register(module: SchemaItemStatic): void;
package/dist/Schema.js CHANGED
@@ -211,7 +211,7 @@ var _SchemaItem = class _SchemaItem {
211
211
  toJSON() {
212
212
  var _a;
213
213
  const res = {
214
- _i: this.constructor.name,
214
+ _i: this.constructor.id,
215
215
  a: this.attributes.length > 0 ? this.attributes : void 0,
216
216
  c: (_a = this.items) == null ? void 0 : _a.map((it) => this.deepSerializeItem(it)),
217
217
  f: this.savedCalls.map((it) => it.args ? { n: it.name, a: Array.from(it.args) } : { n: it.name })
@@ -310,6 +310,7 @@ var SchemaArray = class extends SchemaItem {
310
310
  return Array.isArray(input) ? input.map((entry, index) => ({ item: this.values, value: entry, path: index.toString() })) : [];
311
311
  }
312
312
  };
313
+ SchemaArray.id = "array";
313
314
  __decorateClass([
314
315
  parsable()
315
316
  ], SchemaArray.prototype, "unique", 1);
@@ -341,6 +342,7 @@ var SchemaBoolean = class extends SchemaItem {
341
342
  return typeof input === "boolean";
342
343
  }
343
344
  };
345
+ SchemaBoolean.id = "boolean";
344
346
  __decorateClass([
345
347
  parsable()
346
348
  ], SchemaBoolean.prototype, "parseString", 1);
@@ -379,6 +381,7 @@ var SchemaNullable = class extends SchemaItem {
379
381
  return super.parseSubItems(input, options);
380
382
  }
381
383
  };
384
+ SchemaNullable.id = "nullable";
382
385
  __decorateClass([
383
386
  parsable()
384
387
  ], SchemaNullable.prototype, "falsyAsNull", 1);
@@ -395,7 +398,6 @@ var SchemaObject = class extends SchemaItem {
395
398
  constructor(model) {
396
399
  super([model]);
397
400
  this.model = model;
398
- this.id = "object";
399
401
  }
400
402
  isOfType(input) {
401
403
  return (0, import_object_util2.isObject)(input) && !(0, import_object_util2.objectFind)(this.model, (item, key) => !item.isOfType(input[key]));
@@ -404,6 +406,7 @@ var SchemaObject = class extends SchemaItem {
404
406
  return (0, import_object_util2.isObject)(input) ? (0, import_object_util2.objectMap)(this.model, (schema, key) => ({ item: schema, value: input[key], path: key.toString() })) : [];
405
407
  }
406
408
  };
409
+ SchemaObject.id = "object";
407
410
 
408
411
  // src/helpers.ts
409
412
  function isNull(value) {
@@ -488,6 +491,7 @@ var SchemaAny = class extends SchemaItem {
488
491
  return true;
489
492
  }
490
493
  };
494
+ SchemaAny.id = "any";
491
495
 
492
496
  // src/items/date.ts
493
497
  var SchemaDate = class extends SchemaItem {
@@ -531,6 +535,7 @@ var SchemaDate = class extends SchemaItem {
531
535
  return input instanceof Date;
532
536
  }
533
537
  };
538
+ SchemaDate.id = "date";
534
539
  __decorateClass([
535
540
  parsable()
536
541
  ], SchemaDate.prototype, "parseString", 1);
@@ -569,6 +574,7 @@ var SchemaRecord = class extends SchemaItem {
569
574
  return result;
570
575
  }
571
576
  };
577
+ SchemaRecord.id = "record";
572
578
 
573
579
  // src/items/enum.ts
574
580
  var SchemaEnum = class extends SchemaItem {
@@ -589,6 +595,7 @@ var SchemaEnum = class extends SchemaItem {
589
595
  return typeof input === this.type;
590
596
  }
591
597
  };
598
+ SchemaEnum.id = "enum";
592
599
 
593
600
  // src/items/literal.ts
594
601
  var SchemaLiteral = class extends SchemaItem {
@@ -601,6 +608,7 @@ var SchemaLiteral = class extends SchemaItem {
601
608
  return this.values.some((it) => typeof input === typeof it);
602
609
  }
603
610
  };
611
+ SchemaLiteral.id = "literal";
604
612
 
605
613
  // src/items/number.ts
606
614
  var SchemaNumber = class extends SchemaItem {
@@ -654,6 +662,7 @@ var SchemaNumber = class extends SchemaItem {
654
662
  return this.lte(...params);
655
663
  }
656
664
  };
665
+ SchemaNumber.id = "number";
657
666
  __decorateClass([
658
667
  parsable()
659
668
  ], SchemaNumber.prototype, "lte", 1);
@@ -732,6 +741,7 @@ var SchemaString = class extends SchemaItem {
732
741
  return typeof input === "string";
733
742
  }
734
743
  };
744
+ SchemaString.id = "string";
735
745
  __decorateClass([
736
746
  parsable()
737
747
  ], SchemaString.prototype, "min", 1);
@@ -773,6 +783,7 @@ var SchemaUnion = class extends SchemaItem {
773
783
  return result;
774
784
  }
775
785
  };
786
+ SchemaUnion.id = "union";
776
787
 
777
788
  // src/items/intersection.ts
778
789
  var import_object_util5 = require("@dzeio/object-util");
@@ -801,6 +812,7 @@ var SchemaIntersection = class extends SchemaItem {
801
812
  return result;
802
813
  }
803
814
  };
815
+ SchemaIntersection.id = "intersection";
804
816
 
805
817
  // src/items/default.ts
806
818
  var SchemaDefault = class extends SchemaItem {
@@ -820,6 +832,7 @@ var SchemaDefault = class extends SchemaItem {
820
832
  return [{ item: this.child, value: isNull(input) || !this.strict && !input ? this.defaultVal : input, path: void 0 }];
821
833
  }
822
834
  };
835
+ SchemaDefault.id = "default";
823
836
 
824
837
  // src/items/file.ts
825
838
  var SchemaFile = class extends SchemaItem {
@@ -839,6 +852,7 @@ var SchemaFile = class extends SchemaItem {
839
852
  return input instanceof File;
840
853
  }
841
854
  };
855
+ SchemaFile.id = "file";
842
856
  __decorateClass([
843
857
  parsable()
844
858
  ], SchemaFile.prototype, "extension", 1);
@@ -867,6 +881,7 @@ var SchemaTuple = class extends SchemaItem {
867
881
  return Array.isArray(input) ? this.children.map((entry, index) => ({ value: input[index], item: entry, path: index.toString() })) : [];
868
882
  }
869
883
  };
884
+ SchemaTuple.id = "tuple";
870
885
 
871
886
  // src/items/nullish.ts
872
887
  var SchemaUndefined = class extends SchemaItem {
@@ -874,26 +889,31 @@ var SchemaUndefined = class extends SchemaItem {
874
889
  return typeof input === "undefined";
875
890
  }
876
891
  };
892
+ SchemaUndefined.id = "undefined";
877
893
  var SchemaNull = class extends SchemaItem {
878
894
  isOfType(input) {
879
895
  return input === null;
880
896
  }
881
897
  };
898
+ SchemaNull.id = "null";
882
899
  var SchemaVoid = class extends SchemaItem {
883
900
  isOfType(input) {
884
901
  return typeof input === "undefined";
885
902
  }
886
903
  };
904
+ SchemaVoid.id = "void";
887
905
  var SchemaNullish = class extends SchemaItem {
888
906
  isOfType(input) {
889
907
  return isNull(input);
890
908
  }
891
909
  };
910
+ SchemaNullish.id = "nullish";
892
911
  var SchemaNever = class extends SchemaItem {
893
912
  isOfType(_input) {
894
913
  return false;
895
914
  }
896
915
  };
916
+ SchemaNever.id = "never";
897
917
 
898
918
  // src/Schema.ts
899
919
  var import_object_util6 = require("@dzeio/object-util");
@@ -916,7 +936,7 @@ var _Schema = class _Schema extends SchemaObject {
916
936
  this.registeredModules.push(module2);
917
937
  }
918
938
  static getModule(name) {
919
- const module2 = this.registeredModules.find((it) => it.name === name);
939
+ const module2 = this.registeredModules.find((it) => it.id === name);
920
940
  if (!module2) {
921
941
  console.log("Couldn't find module", name);
922
942
  }
package/dist/Schema.mjs CHANGED
@@ -161,7 +161,7 @@ var _SchemaItem = class _SchemaItem {
161
161
  toJSON() {
162
162
  var _a;
163
163
  const res = {
164
- _i: this.constructor.name,
164
+ _i: this.constructor.id,
165
165
  a: this.attributes.length > 0 ? this.attributes : void 0,
166
166
  c: (_a = this.items) == null ? void 0 : _a.map((it) => this.deepSerializeItem(it)),
167
167
  f: this.savedCalls.map((it) => it.args ? { n: it.name, a: Array.from(it.args) } : { n: it.name })
@@ -260,6 +260,7 @@ var SchemaArray = class extends SchemaItem {
260
260
  return Array.isArray(input) ? input.map((entry, index) => ({ item: this.values, value: entry, path: index.toString() })) : [];
261
261
  }
262
262
  };
263
+ SchemaArray.id = "array";
263
264
  __decorateClass([
264
265
  parsable()
265
266
  ], SchemaArray.prototype, "unique", 1);
@@ -291,6 +292,7 @@ var SchemaBoolean = class extends SchemaItem {
291
292
  return typeof input === "boolean";
292
293
  }
293
294
  };
295
+ SchemaBoolean.id = "boolean";
294
296
  __decorateClass([
295
297
  parsable()
296
298
  ], SchemaBoolean.prototype, "parseString", 1);
@@ -329,6 +331,7 @@ var SchemaNullable = class extends SchemaItem {
329
331
  return super.parseSubItems(input, options);
330
332
  }
331
333
  };
334
+ SchemaNullable.id = "nullable";
332
335
  __decorateClass([
333
336
  parsable()
334
337
  ], SchemaNullable.prototype, "falsyAsNull", 1);
@@ -345,7 +348,6 @@ var SchemaObject = class extends SchemaItem {
345
348
  constructor(model) {
346
349
  super([model]);
347
350
  this.model = model;
348
- this.id = "object";
349
351
  }
350
352
  isOfType(input) {
351
353
  return isObject2(input) && !objectFind(this.model, (item, key) => !item.isOfType(input[key]));
@@ -354,6 +356,7 @@ var SchemaObject = class extends SchemaItem {
354
356
  return isObject2(input) ? objectMap(this.model, (schema, key) => ({ item: schema, value: input[key], path: key.toString() })) : [];
355
357
  }
356
358
  };
359
+ SchemaObject.id = "object";
357
360
 
358
361
  // src/helpers.ts
359
362
  function isNull(value) {
@@ -438,6 +441,7 @@ var SchemaAny = class extends SchemaItem {
438
441
  return true;
439
442
  }
440
443
  };
444
+ SchemaAny.id = "any";
441
445
 
442
446
  // src/items/date.ts
443
447
  var SchemaDate = class extends SchemaItem {
@@ -481,6 +485,7 @@ var SchemaDate = class extends SchemaItem {
481
485
  return input instanceof Date;
482
486
  }
483
487
  };
488
+ SchemaDate.id = "date";
484
489
  __decorateClass([
485
490
  parsable()
486
491
  ], SchemaDate.prototype, "parseString", 1);
@@ -519,6 +524,7 @@ var SchemaRecord = class extends SchemaItem {
519
524
  return result;
520
525
  }
521
526
  };
527
+ SchemaRecord.id = "record";
522
528
 
523
529
  // src/items/enum.ts
524
530
  var SchemaEnum = class extends SchemaItem {
@@ -539,6 +545,7 @@ var SchemaEnum = class extends SchemaItem {
539
545
  return typeof input === this.type;
540
546
  }
541
547
  };
548
+ SchemaEnum.id = "enum";
542
549
 
543
550
  // src/items/literal.ts
544
551
  var SchemaLiteral = class extends SchemaItem {
@@ -551,6 +558,7 @@ var SchemaLiteral = class extends SchemaItem {
551
558
  return this.values.some((it) => typeof input === typeof it);
552
559
  }
553
560
  };
561
+ SchemaLiteral.id = "literal";
554
562
 
555
563
  // src/items/number.ts
556
564
  var SchemaNumber = class extends SchemaItem {
@@ -604,6 +612,7 @@ var SchemaNumber = class extends SchemaItem {
604
612
  return this.lte(...params);
605
613
  }
606
614
  };
615
+ SchemaNumber.id = "number";
607
616
  __decorateClass([
608
617
  parsable()
609
618
  ], SchemaNumber.prototype, "lte", 1);
@@ -682,6 +691,7 @@ var SchemaString = class extends SchemaItem {
682
691
  return typeof input === "string";
683
692
  }
684
693
  };
694
+ SchemaString.id = "string";
685
695
  __decorateClass([
686
696
  parsable()
687
697
  ], SchemaString.prototype, "min", 1);
@@ -723,6 +733,7 @@ var SchemaUnion = class extends SchemaItem {
723
733
  return result;
724
734
  }
725
735
  };
736
+ SchemaUnion.id = "union";
726
737
 
727
738
  // src/items/intersection.ts
728
739
  import { isObject as isObject4 } from "@dzeio/object-util";
@@ -751,6 +762,7 @@ var SchemaIntersection = class extends SchemaItem {
751
762
  return result;
752
763
  }
753
764
  };
765
+ SchemaIntersection.id = "intersection";
754
766
 
755
767
  // src/items/default.ts
756
768
  var SchemaDefault = class extends SchemaItem {
@@ -770,6 +782,7 @@ var SchemaDefault = class extends SchemaItem {
770
782
  return [{ item: this.child, value: isNull(input) || !this.strict && !input ? this.defaultVal : input, path: void 0 }];
771
783
  }
772
784
  };
785
+ SchemaDefault.id = "default";
773
786
 
774
787
  // src/items/file.ts
775
788
  var SchemaFile = class extends SchemaItem {
@@ -789,6 +802,7 @@ var SchemaFile = class extends SchemaItem {
789
802
  return input instanceof File;
790
803
  }
791
804
  };
805
+ SchemaFile.id = "file";
792
806
  __decorateClass([
793
807
  parsable()
794
808
  ], SchemaFile.prototype, "extension", 1);
@@ -817,6 +831,7 @@ var SchemaTuple = class extends SchemaItem {
817
831
  return Array.isArray(input) ? this.children.map((entry, index) => ({ value: input[index], item: entry, path: index.toString() })) : [];
818
832
  }
819
833
  };
834
+ SchemaTuple.id = "tuple";
820
835
 
821
836
  // src/items/nullish.ts
822
837
  var SchemaUndefined = class extends SchemaItem {
@@ -824,26 +839,31 @@ var SchemaUndefined = class extends SchemaItem {
824
839
  return typeof input === "undefined";
825
840
  }
826
841
  };
842
+ SchemaUndefined.id = "undefined";
827
843
  var SchemaNull = class extends SchemaItem {
828
844
  isOfType(input) {
829
845
  return input === null;
830
846
  }
831
847
  };
848
+ SchemaNull.id = "null";
832
849
  var SchemaVoid = class extends SchemaItem {
833
850
  isOfType(input) {
834
851
  return typeof input === "undefined";
835
852
  }
836
853
  };
854
+ SchemaVoid.id = "void";
837
855
  var SchemaNullish = class extends SchemaItem {
838
856
  isOfType(input) {
839
857
  return isNull(input);
840
858
  }
841
859
  };
860
+ SchemaNullish.id = "nullish";
842
861
  var SchemaNever = class extends SchemaItem {
843
862
  isOfType(_input) {
844
863
  return false;
845
864
  }
846
865
  };
866
+ SchemaNever.id = "never";
847
867
 
848
868
  // src/Schema.ts
849
869
  import { isObject as isObject5, objectRemap as objectRemap2 } from "@dzeio/object-util";
@@ -866,7 +886,7 @@ var _Schema = class _Schema extends SchemaObject {
866
886
  this.registeredModules.push(module);
867
887
  }
868
888
  static getModule(name) {
869
- const module = this.registeredModules.find((it) => it.name === name);
889
+ const module = this.registeredModules.find((it) => it.id === name);
870
890
  if (!module) {
871
891
  console.log("Couldn't find module", name);
872
892
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dzeio/schema",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "dependencies": {
5
5
  "@dzeio/object-util": "^1.9.2"
6
6
  },