@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.js CHANGED
@@ -46,10 +46,12 @@ __export(Schema_exports, {
46
46
  SchemaObject: () => SchemaObject,
47
47
  SchemaRecord: () => SchemaRecord,
48
48
  SchemaString: () => SchemaString,
49
+ SchemaTuple: () => SchemaTuple,
49
50
  SchemaUndefined: () => SchemaUndefined,
50
51
  SchemaUnion: () => SchemaUnion,
51
52
  SchemaVoid: () => SchemaVoid,
52
53
  default: () => Schema,
54
+ getSchemaItemAtPath: () => getSchemaItemAtPath,
53
55
  isNull: () => isNull,
54
56
  parsable: () => parsable,
55
57
  parseForm: () => parseForm,
@@ -60,12 +62,104 @@ __export(Schema_exports, {
60
62
  module.exports = __toCommonJS(Schema_exports);
61
63
 
62
64
  // src/helpers.ts
63
- var import_object_util3 = require("@dzeio/object-util");
65
+ var import_object_util = require("@dzeio/object-util");
66
+ function isNull(value) {
67
+ return value === void 0 || value === null;
68
+ }
69
+ function parseQuery(schema, query, opts) {
70
+ const record = {};
71
+ for (const [key, value] of query) {
72
+ const keys = key.split(".").map((it) => /^\d+$/g.test(it) ? Number.parseInt(it, 10) : it);
73
+ const schemaItem = getSchemaItemAtPath(schema, keys);
74
+ const allValues = query.getAll(key);
75
+ const finalValue = (schemaItem == null ? void 0 : schemaItem.parse(allValues).valid) ? allValues : value;
76
+ (0, import_object_util.objectSet)(record, keys, finalValue);
77
+ }
78
+ return schema.parse(record, opts);
79
+ }
80
+ function parseFormData(schema, data, opts) {
81
+ const record = {};
82
+ for (const [key, value] of data) {
83
+ const keys = key.split(".").map((it) => /^\d+$/g.test(it) ? Number.parseInt(it, 10) : it);
84
+ const schemaItem = getSchemaItemAtPath(schema, keys);
85
+ const allValues = data.getAll(key);
86
+ const finalValue = (schemaItem == null ? void 0 : schemaItem.parse(allValues).valid) ? allValues : value;
87
+ (0, import_object_util.objectSet)(record, keys, finalValue);
88
+ }
89
+ const handleBoolean = (value, keys) => {
90
+ var _a;
91
+ if (value instanceof SchemaNullable) {
92
+ handleBoolean(value.unwrap(), keys);
93
+ }
94
+ if (value instanceof SchemaArray) {
95
+ const elements = (0, import_object_util.objectGet)(record, keys);
96
+ for (let it = 0; it < ((_a = elements == null ? void 0 : elements.length) != null ? _a : 0); it++) {
97
+ handleBoolean(value.unwrap(), [...keys, it]);
98
+ }
99
+ }
100
+ if (value instanceof SchemaObject) {
101
+ handleSchemaForBoolean(value.model, keys);
102
+ }
103
+ if (value instanceof SchemaBoolean && typeof (0, import_object_util.objectGet)(record, keys) === "undefined") {
104
+ (0, import_object_util.objectSet)(record, keys, false);
105
+ }
106
+ };
107
+ const handleSchemaForBoolean = (model, keys = []) => {
108
+ (0, import_object_util.objectLoop)(model, (value, key) => {
109
+ handleBoolean(value, [...keys, key]);
110
+ });
111
+ };
112
+ if (schema instanceof SchemaObject) {
113
+ handleSchemaForBoolean(schema.model);
114
+ }
115
+ return schema.parse(record, opts);
116
+ }
117
+ function parseForm(model, form, opts) {
118
+ return parseFormData(model, new FormData(form), opts);
119
+ }
120
+ function getSchemaItemAtPath(schema, path) {
121
+ while (schema instanceof SchemaNullable || schema instanceof SchemaDefault) {
122
+ schema = schema.unwrap();
123
+ }
124
+ if (path.length === 0 || !schema) {
125
+ return schema;
126
+ }
127
+ if (schema instanceof SchemaUnion || schema instanceof SchemaIntersection) {
128
+ for (const child of schema.unwrap()) {
129
+ try {
130
+ const result = getSchemaItemAtPath(child, path);
131
+ if (!result) {
132
+ continue;
133
+ }
134
+ return result;
135
+ } catch {
136
+ continue;
137
+ }
138
+ }
139
+ return void 0;
140
+ }
141
+ const key = path[0];
142
+ const next = path.slice(1);
143
+ if (schema instanceof SchemaArray && typeof key === "number") {
144
+ return getSchemaItemAtPath(schema.unwrap(), next);
145
+ }
146
+ if (schema instanceof SchemaTuple && typeof key === "number") {
147
+ return getSchemaItemAtPath(schema.unwrap()[key], next);
148
+ }
149
+ if (schema instanceof SchemaObject && typeof key === "string") {
150
+ return getSchemaItemAtPath(schema.model[key], next);
151
+ }
152
+ if (schema instanceof SchemaRecord && schema.isKeyOfType(key)) {
153
+ return getSchemaItemAtPath(schema.unwrap(), next);
154
+ }
155
+ return void 0;
156
+ }
64
157
 
65
158
  // src/SchemaItem.ts
66
- var import_object_util = require("@dzeio/object-util");
159
+ var import_object_util2 = require("@dzeio/object-util");
67
160
  var _SchemaItem = class _SchemaItem {
68
161
  constructor(items) {
162
+ this.id = this.constructor.id;
69
163
  // standard Schema V1 spec
70
164
  this["~standard"] = {
71
165
  vendor: "aptatio",
@@ -102,7 +196,6 @@ var _SchemaItem = class _SchemaItem {
102
196
  *
103
197
  * note: The type of the final Pre-Process MUST be valid
104
198
  */
105
- // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
106
199
  this.preProcess = [];
107
200
  /**
108
201
  * post process the variable after it being validated
@@ -119,6 +212,10 @@ var _SchemaItem = class _SchemaItem {
119
212
  this.items = Array.isArray(items) ? items : Array.from(items);
120
213
  }
121
214
  }
215
+ setInvalidError(err) {
216
+ this.invalidError = err;
217
+ return this;
218
+ }
122
219
  parseJSON() {
123
220
  this.addPreProcess((input) => {
124
221
  try {
@@ -140,10 +237,6 @@ var _SchemaItem = class _SchemaItem {
140
237
  attr(...attributes) {
141
238
  return this.attrs(...attributes);
142
239
  }
143
- setInvalidError(err) {
144
- this.invalidError = err;
145
- return this;
146
- }
147
240
  clone() {
148
241
  return Schema.fromJSON(this.toJSON());
149
242
  }
@@ -216,24 +309,13 @@ var _SchemaItem = class _SchemaItem {
216
309
  c: (_a = this.items) == null ? void 0 : _a.map((it) => this.deepSerializeItem(it)),
217
310
  f: this.savedCalls.map((it) => it.args ? { n: it.name, a: Array.from(it.args) } : { n: it.name })
218
311
  };
219
- (0, import_object_util.objectClean)(res, { deep: false });
312
+ (0, import_object_util2.objectClean)(res, { deep: false });
220
313
  return res;
221
314
  }
222
- deepSerializeItem(item) {
223
- if (item instanceof _SchemaItem) {
224
- return item.toJSON();
225
- } else if (Array.isArray(item)) {
226
- return item.map((it) => this.deepSerializeItem(it));
227
- } else if ((0, import_object_util.isObject)(item)) {
228
- return (0, import_object_util.objectRemap)(item, (value, key) => ({ value: this.deepSerializeItem(value), key }));
229
- }
230
- return item;
231
- }
232
315
  addValidation(fn, error) {
233
316
  this.validations.push(typeof fn === "function" ? { fn, error } : fn);
234
317
  return this;
235
318
  }
236
- // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
237
319
  addPreProcess(fn) {
238
320
  this.preProcess.push(fn);
239
321
  return this;
@@ -248,8 +330,8 @@ var _SchemaItem = class _SchemaItem {
248
330
  }
249
331
  /** Sets the "part" of the input that this sub schema handles. Overrides the input with the result */
250
332
  updateSubItemInput(path, input, value) {
251
- if (path && (0, import_object_util.isObject)(input)) {
252
- (0, import_object_util.objectSet)(input, path.split("."), value);
333
+ if (path && (0, import_object_util2.isObject)(input)) {
334
+ (0, import_object_util2.objectSet)(input, path.split("."), value);
253
335
  return input;
254
336
  } else {
255
337
  return value;
@@ -273,220 +355,27 @@ var _SchemaItem = class _SchemaItem {
273
355
  }
274
356
  return result;
275
357
  }
276
- };
277
- __decorateClass([
278
- parsable()
279
- ], _SchemaItem.prototype, "parseJSON", 1);
280
- __decorateClass([
281
- parsable()
282
- ], _SchemaItem.prototype, "in", 1);
283
- __decorateClass([
284
- parsable()
285
- ], _SchemaItem.prototype, "setInvalidError", 1);
286
- var SchemaItem = _SchemaItem;
287
-
288
- // src/items/array.ts
289
- var SchemaArray = class extends SchemaItem {
290
- constructor(values) {
291
- super([values]);
292
- this.values = values;
293
- }
294
- unique() {
295
- this.postProcess.push((input) => input.filter((it, idx) => input.indexOf(it) === idx));
296
- return this;
297
- }
298
- clean() {
299
- this.postProcess.push((input) => input.filter((it) => !isNull(it)));
300
- return this;
301
- }
302
- split(separator = ",") {
303
- this.addPreProcess((it) => typeof it === "string" ? it.split(separator) : it);
304
- return this;
305
- }
306
- unwrap() {
307
- return this.values;
308
- }
309
- isOfType(input) {
310
- return Array.isArray(input) && input.every((entry) => this.values.isOfType(entry));
311
- }
312
- getSubInputs(input) {
313
- return Array.isArray(input) ? input.map((entry, index) => ({ item: this.values, value: entry, path: index.toString() })) : [];
314
- }
315
- };
316
- SchemaArray.id = "array";
317
- __decorateClass([
318
- parsable()
319
- ], SchemaArray.prototype, "unique", 1);
320
- __decorateClass([
321
- parsable()
322
- ], SchemaArray.prototype, "clean", 1);
323
- __decorateClass([
324
- parsable()
325
- ], SchemaArray.prototype, "split", 1);
326
-
327
- // src/items/boolean.ts
328
- var SchemaBoolean = class extends SchemaItem {
329
- parseString(trueValue = "true", falseValue = "false") {
330
- this.addPreProcess((input) => {
331
- if (typeof input !== "string") {
332
- return input;
333
- }
334
- if (input === trueValue) {
335
- return true;
336
- }
337
- if (input === falseValue) {
338
- return false;
339
- }
340
- return input;
341
- });
342
- return this;
343
- }
344
- isOfType(input) {
345
- return typeof input === "boolean";
346
- }
347
- };
348
- SchemaBoolean.id = "boolean";
349
- __decorateClass([
350
- parsable()
351
- ], SchemaBoolean.prototype, "parseString", 1);
352
-
353
- // src/items/nullable.ts
354
- var SchemaNullable = class extends SchemaItem {
355
- constructor(child) {
356
- super([child]);
357
- this.child = child;
358
- }
359
- falsyAsNull() {
360
- this.addPreProcess((it) => !it ? void 0 : it);
361
- return this;
362
- }
363
- emptyAsNull() {
364
- this.addPreProcess((it) => it === "" ? void 0 : it);
365
- return this;
366
- }
367
- emptyFileAsNull() {
368
- this.addPreProcess((it) => it instanceof File && it.size === 0 ? void 0 : it);
369
- return this;
370
- }
371
- unwrap() {
372
- return this.child;
373
- }
374
- isOfType(input) {
375
- return typeof input === "undefined" || this.child.isOfType(input);
376
- }
377
- getSubInputs(input) {
378
- return [{ value: input, item: this.child, path: void 0 }];
379
- }
380
- parseSubItems(input, options) {
381
- if (isNull(input)) {
382
- return { input: void 0 };
358
+ deepSerializeItem(item) {
359
+ if (item instanceof _SchemaItem) {
360
+ return item.toJSON();
361
+ } else if (Array.isArray(item)) {
362
+ return item.map((it) => this.deepSerializeItem(it));
363
+ } else if ((0, import_object_util2.isObject)(item)) {
364
+ return (0, import_object_util2.objectRemap)(item, (value, key) => ({ value: this.deepSerializeItem(value), key }));
383
365
  }
384
- return super.parseSubItems(input, options);
366
+ return item;
385
367
  }
386
368
  };
387
- SchemaNullable.id = "nullable";
388
369
  __decorateClass([
389
370
  parsable()
390
- ], SchemaNullable.prototype, "falsyAsNull", 1);
371
+ ], _SchemaItem.prototype, "setInvalidError", 1);
391
372
  __decorateClass([
392
373
  parsable()
393
- ], SchemaNullable.prototype, "emptyAsNull", 1);
374
+ ], _SchemaItem.prototype, "parseJSON", 1);
394
375
  __decorateClass([
395
376
  parsable()
396
- ], SchemaNullable.prototype, "emptyFileAsNull", 1);
397
-
398
- // src/items/object.ts
399
- var import_object_util2 = require("@dzeio/object-util");
400
- var SchemaObject = class extends SchemaItem {
401
- constructor(model) {
402
- super([model]);
403
- this.model = model;
404
- }
405
- isOfType(input) {
406
- return (0, import_object_util2.isObject)(input) && !(0, import_object_util2.objectFind)(this.model, (item, key) => !item.isOfType(input[key]));
407
- }
408
- getSubInputs(input) {
409
- return (0, import_object_util2.isObject)(input) ? (0, import_object_util2.objectMap)(this.model, (schema, key) => ({ item: schema, value: input[key], path: key.toString() })) : [];
410
- }
411
- };
412
- SchemaObject.id = "object";
413
-
414
- // src/helpers.ts
415
- function isNull(value) {
416
- return typeof value === "undefined" || value === null;
417
- }
418
- function parseQuery(schema, query, opts) {
419
- const record = {};
420
- for (const [key, value] of query) {
421
- const keys = key.split(".").map((it) => /^\d+$/g.test(it) ? Number.parseInt(it, 10) : it);
422
- const schemaItem = getSchemaItemAtPath(schema, keys);
423
- const allValues = query.getAll(key);
424
- const finalValue = schemaItem && schemaItem.parse(allValues).valid ? allValues : value;
425
- (0, import_object_util3.objectSet)(record, keys, finalValue);
426
- }
427
- return schema.parse(record, opts);
428
- }
429
- function parseFormData(schema, data, opts) {
430
- const record = {};
431
- for (const [key, value] of data) {
432
- const keys = key.split(".").map((it) => /^\d+$/g.test(it) ? Number.parseInt(it, 10) : it);
433
- const schemaItem = getSchemaItemAtPath(schema, keys);
434
- const allValues = data.getAll(key);
435
- const finalValue = schemaItem && schemaItem.parse(allValues).valid ? allValues : value;
436
- (0, import_object_util3.objectSet)(record, keys, finalValue);
437
- }
438
- const handleBoolean = (value, keys) => {
439
- var _a;
440
- if (value instanceof SchemaNullable) {
441
- handleBoolean(value.unwrap(), keys);
442
- }
443
- if (value instanceof SchemaArray) {
444
- const elements = (0, import_object_util3.objectGet)(record, keys);
445
- for (let it = 0; it < ((_a = elements == null ? void 0 : elements.length) != null ? _a : 0); it++) {
446
- handleBoolean(value.unwrap(), [...keys, it]);
447
- }
448
- }
449
- if (value instanceof SchemaObject) {
450
- handleSchemaForBoolean(value.model, keys);
451
- }
452
- if (value instanceof SchemaBoolean && typeof (0, import_object_util3.objectGet)(record, keys) === "undefined") {
453
- (0, import_object_util3.objectSet)(record, keys, false);
454
- }
455
- };
456
- const handleSchemaForBoolean = (model, keys = []) => {
457
- (0, import_object_util3.objectLoop)(model, (value, key) => {
458
- handleBoolean(value, [...keys, key]);
459
- });
460
- };
461
- if (schema instanceof SchemaObject) {
462
- handleSchemaForBoolean(schema.model);
463
- }
464
- return schema.parse(record, opts);
465
- }
466
- function parseForm(model, form, opts) {
467
- return parseFormData(model, new FormData(form), opts);
468
- }
469
- function getSchemaItemAtPath(schema, path) {
470
- let current = schema;
471
- const internalPath = (0, import_object_util3.objectClone)(path);
472
- for (const key of path) {
473
- if (!current) {
474
- return void 0;
475
- }
476
- internalPath.shift();
477
- while (current instanceof SchemaNullable || current instanceof SchemaDefault) {
478
- current = current.unwrap();
479
- }
480
- if (current instanceof SchemaObject) {
481
- current = current.model[key];
482
- current = getSchemaItemAtPath(current, internalPath);
483
- }
484
- }
485
- while (current instanceof SchemaNullable || current instanceof SchemaDefault) {
486
- current = current.unwrap();
487
- }
488
- return current;
489
- }
377
+ ], _SchemaItem.prototype, "in", 1);
378
+ var SchemaItem = _SchemaItem;
490
379
 
491
380
  // src/items/any.ts
492
381
  var SchemaAny = class extends SchemaItem {
@@ -527,7 +416,7 @@ var SchemaDate = class extends SchemaItem {
527
416
  break;
528
417
  }
529
418
  }
530
- if (!date || isNaN(date.getDate())) {
419
+ if (!date || Number.isNaN(date.getDate())) {
531
420
  return input;
532
421
  }
533
422
  return date;
@@ -544,21 +433,27 @@ __decorateClass([
544
433
  ], SchemaDate.prototype, "parseString", 1);
545
434
 
546
435
  // src/items/record.ts
547
- var import_object_util4 = require("@dzeio/object-util");
436
+ var import_object_util3 = require("@dzeio/object-util");
548
437
  var SchemaRecord = class extends SchemaItem {
549
438
  constructor(keys, values) {
550
439
  super([keys, values]);
551
440
  this.keys = keys;
552
441
  this.values = values;
553
442
  }
443
+ unwrap() {
444
+ return this.values;
445
+ }
446
+ isKeyOfType(key) {
447
+ return this.keys.parse(key).valid;
448
+ }
554
449
  isOfType(input) {
555
- return (0, import_object_util4.isObject)(input) && Object.prototype.toString.call(input) === "[object Object]";
450
+ return (0, import_object_util3.isObject)(input) && Object.prototype.toString.call(input) === "[object Object]";
556
451
  }
557
452
  parseSubItems(input, options) {
558
453
  const result = { input, errors: [] };
559
- if ((0, import_object_util4.isObject)(input)) {
454
+ if ((0, import_object_util3.isObject)(input)) {
560
455
  const clone = {};
561
- (0, import_object_util4.objectLoop)(input, (value, key) => {
456
+ (0, import_object_util3.objectLoop)(input, (value, key) => {
562
457
  var _a, _b;
563
458
  const res1 = this.keys.parse(key);
564
459
  const res2 = this.values.parse(value);
@@ -579,6 +474,71 @@ var SchemaRecord = class extends SchemaItem {
579
474
  };
580
475
  SchemaRecord.id = "record";
581
476
 
477
+ // src/items/array.ts
478
+ var SchemaArray = class extends SchemaItem {
479
+ constructor(values) {
480
+ super([values]);
481
+ this.values = values;
482
+ }
483
+ unique() {
484
+ this.postProcess.push((input) => input.filter((it, idx) => input.indexOf(it) === idx));
485
+ return this;
486
+ }
487
+ clean() {
488
+ this.postProcess.push((input) => input.filter((it) => !isNull(it)));
489
+ return this;
490
+ }
491
+ split(separator = ",") {
492
+ this.addPreProcess((it) => typeof it === "string" ? it.split(separator) : it);
493
+ return this;
494
+ }
495
+ unwrap() {
496
+ return this.values;
497
+ }
498
+ isOfType(input) {
499
+ return Array.isArray(input) && input.every((entry) => this.values.isOfType(entry));
500
+ }
501
+ getSubInputs(input) {
502
+ return Array.isArray(input) ? input.map((entry, index) => ({ item: this.values, value: entry, path: index.toString() })) : [];
503
+ }
504
+ };
505
+ SchemaArray.id = "array";
506
+ __decorateClass([
507
+ parsable()
508
+ ], SchemaArray.prototype, "unique", 1);
509
+ __decorateClass([
510
+ parsable()
511
+ ], SchemaArray.prototype, "clean", 1);
512
+ __decorateClass([
513
+ parsable()
514
+ ], SchemaArray.prototype, "split", 1);
515
+
516
+ // src/items/boolean.ts
517
+ var SchemaBoolean = class extends SchemaItem {
518
+ parseString(trueValue = "true", falseValue = "false") {
519
+ this.addPreProcess((input) => {
520
+ if (typeof input !== "string") {
521
+ return input;
522
+ }
523
+ if (input === trueValue) {
524
+ return true;
525
+ }
526
+ if (input === falseValue) {
527
+ return false;
528
+ }
529
+ return input;
530
+ });
531
+ return this;
532
+ }
533
+ isOfType(input) {
534
+ return typeof input === "boolean";
535
+ }
536
+ };
537
+ SchemaBoolean.id = "boolean";
538
+ __decorateClass([
539
+ parsable()
540
+ ], SchemaBoolean.prototype, "parseString", 1);
541
+
582
542
  // src/items/enum.ts
583
543
  var SchemaEnum = class extends SchemaItem {
584
544
  constructor(templateEnum) {
@@ -613,6 +573,51 @@ var SchemaLiteral = class extends SchemaItem {
613
573
  };
614
574
  SchemaLiteral.id = "literal";
615
575
 
576
+ // src/items/nullable.ts
577
+ var SchemaNullable = class extends SchemaItem {
578
+ constructor(child) {
579
+ super([child]);
580
+ this.child = child;
581
+ }
582
+ falsyAsNull() {
583
+ this.addPreProcess((it) => !it ? void 0 : it);
584
+ return this;
585
+ }
586
+ emptyAsNull() {
587
+ this.addPreProcess((it) => it === "" ? void 0 : it);
588
+ return this;
589
+ }
590
+ emptyFileAsNull() {
591
+ this.addPreProcess((it) => it instanceof File && it.size === 0 ? void 0 : it);
592
+ return this;
593
+ }
594
+ unwrap() {
595
+ return this.child;
596
+ }
597
+ isOfType(input) {
598
+ return input === void 0 || this.child.isOfType(input);
599
+ }
600
+ getSubInputs(input) {
601
+ return [{ value: input, item: this.child, path: void 0 }];
602
+ }
603
+ parseSubItems(input, options) {
604
+ if (isNull(input)) {
605
+ return { input: void 0 };
606
+ }
607
+ return super.parseSubItems(input, options);
608
+ }
609
+ };
610
+ SchemaNullable.id = "nullable";
611
+ __decorateClass([
612
+ parsable()
613
+ ], SchemaNullable.prototype, "falsyAsNull", 1);
614
+ __decorateClass([
615
+ parsable()
616
+ ], SchemaNullable.prototype, "emptyAsNull", 1);
617
+ __decorateClass([
618
+ parsable()
619
+ ], SchemaNullable.prototype, "emptyFileAsNull", 1);
620
+
616
621
  // src/items/number.ts
617
622
  var SchemaNumber = class extends SchemaItem {
618
623
  lte(value, message) {
@@ -682,6 +687,22 @@ __decorateClass([
682
687
  parsable()
683
688
  ], SchemaNumber.prototype, "parseString", 1);
684
689
 
690
+ // src/items/object.ts
691
+ var import_object_util4 = require("@dzeio/object-util");
692
+ var SchemaObject = class extends SchemaItem {
693
+ constructor(model) {
694
+ super([model]);
695
+ this.model = model;
696
+ }
697
+ isOfType(input) {
698
+ return (0, import_object_util4.isObject)(input) && !(0, import_object_util4.objectFind)(this.model, (item, key) => !item.isOfType(input[key]));
699
+ }
700
+ getSubInputs(input) {
701
+ return (0, import_object_util4.isObject)(input) ? (0, import_object_util4.objectMap)(this.model, (schema, key) => ({ item: schema, value: input[key], path: key.toString() })) : [];
702
+ }
703
+ };
704
+ SchemaObject.id = "object";
705
+
685
706
  // src/items/string.ts
686
707
  var SchemaString = class extends SchemaItem {
687
708
  min(value, message) {
@@ -707,6 +728,15 @@ var SchemaString = class extends SchemaItem {
707
728
  });
708
729
  return this;
709
730
  }
731
+ trim() {
732
+ this.addPreProcess((input) => {
733
+ if (typeof input !== "string") {
734
+ return input;
735
+ }
736
+ return input.trim();
737
+ });
738
+ return this;
739
+ }
710
740
  notEmpty(message) {
711
741
  this.addValidation({
712
742
  fn(input) {
@@ -754,6 +784,9 @@ __decorateClass([
754
784
  __decorateClass([
755
785
  parsable()
756
786
  ], SchemaString.prototype, "max", 1);
787
+ __decorateClass([
788
+ parsable()
789
+ ], SchemaString.prototype, "trim", 1);
757
790
  __decorateClass([
758
791
  parsable()
759
792
  ], SchemaString.prototype, "notEmpty", 1);
@@ -770,6 +803,9 @@ var SchemaUnion = class extends SchemaItem {
770
803
  super(schemas);
771
804
  this.schemas = schemas;
772
805
  }
806
+ unwrap() {
807
+ return this.schemas;
808
+ }
773
809
  isOfType(input) {
774
810
  return this.schemas.some((it) => it.isOfType(input));
775
811
  }
@@ -795,6 +831,9 @@ var SchemaIntersection = class extends SchemaItem {
795
831
  super(schemas);
796
832
  this.schemas = schemas;
797
833
  }
834
+ unwrap() {
835
+ return this.schemas;
836
+ }
798
837
  isOfType(input) {
799
838
  return this.schemas.every((it) => it.isOfType(input));
800
839
  }
@@ -869,6 +908,9 @@ var SchemaTuple = class extends SchemaItem {
869
908
  super(children);
870
909
  this.children = children;
871
910
  }
911
+ unwrap() {
912
+ return this.children;
913
+ }
872
914
  isOfType(input) {
873
915
  if (!Array.isArray(input) || input.length > this.items.length) {
874
916
  return false;
@@ -889,7 +931,7 @@ SchemaTuple.id = "tuple";
889
931
  // src/items/nullish.ts
890
932
  var SchemaUndefined = class extends SchemaItem {
891
933
  isOfType(input) {
892
- return typeof input === "undefined";
934
+ return input === void 0;
893
935
  }
894
936
  };
895
937
  SchemaUndefined.id = "undefined";
@@ -901,7 +943,7 @@ var SchemaNull = class extends SchemaItem {
901
943
  SchemaNull.id = "null";
902
944
  var SchemaVoid = class extends SchemaItem {
903
945
  isOfType(input) {
904
- return typeof input === "undefined";
946
+ return input === void 0;
905
947
  }
906
948
  };
907
949
  SchemaVoid.id = "void";
@@ -1117,9 +1159,11 @@ var s = Schema;
1117
1159
  SchemaObject,
1118
1160
  SchemaRecord,
1119
1161
  SchemaString,
1162
+ SchemaTuple,
1120
1163
  SchemaUndefined,
1121
1164
  SchemaUnion,
1122
1165
  SchemaVoid,
1166
+ getSchemaItemAtPath,
1123
1167
  isNull,
1124
1168
  parsable,
1125
1169
  parseForm,