@palmares/schemas 0.0.1 → 0.1.1
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/.turbo/turbo-build$colon$watch.log +12 -410
- package/.turbo/turbo-build.log +13 -4
- package/CHANGELOG.md +26 -0
- package/__tests__/.drizzle/migrations/0000_skinny_harrier.sql +22 -0
- package/__tests__/.drizzle/migrations/meta/0000_snapshot.json +156 -0
- package/__tests__/.drizzle/migrations/meta/_journal.json +13 -0
- package/__tests__/.drizzle/schema.ts +35 -0
- package/__tests__/drizzle.config.ts +11 -0
- package/__tests__/eslint.config.js +10 -0
- package/__tests__/manage.ts +5 -0
- package/__tests__/node_modules/.bin/drizzle-kit +17 -0
- package/__tests__/node_modules/.bin/esbuild +14 -0
- package/__tests__/node_modules/.bin/tsc +17 -0
- package/__tests__/node_modules/.bin/tsserver +17 -0
- package/__tests__/node_modules/.bin/tsx +17 -0
- package/__tests__/package.json +36 -0
- package/__tests__/sqlite.db +0 -0
- package/__tests__/src/core/array.test.ts +130 -0
- package/__tests__/src/core/boolean.test.ts +66 -0
- package/__tests__/src/core/datetime.test.ts +102 -0
- package/__tests__/src/core/index.ts +35 -0
- package/__tests__/src/core/model.test.ts +260 -0
- package/__tests__/src/core/models.ts +50 -0
- package/__tests__/src/core/numbers.test.ts +177 -0
- package/__tests__/src/core/object.test.ts +198 -0
- package/__tests__/src/core/string.test.ts +222 -0
- package/__tests__/src/core/test.test.ts +59 -0
- package/__tests__/src/core/types.test.ts +97 -0
- package/__tests__/src/core/union.test.ts +99 -0
- package/__tests__/src/settings.ts +71 -0
- package/__tests__/tsconfig.json +11 -0
- package/dist/cjs/src/adapter/fields/index.js +2 -2
- package/dist/cjs/src/adapter/fields/object.js +9 -0
- package/dist/cjs/src/adapter/index.js +1 -0
- package/dist/cjs/src/constants.js +1 -7
- package/dist/cjs/src/domain.js +146 -1
- package/dist/cjs/src/index.js +69 -74
- package/dist/cjs/src/model.js +206 -206
- package/dist/cjs/src/schema/array.js +185 -58
- package/dist/cjs/src/schema/boolean.js +105 -44
- package/dist/cjs/src/schema/datetime.js +104 -38
- package/dist/cjs/src/schema/number.js +134 -114
- package/dist/cjs/src/schema/object.js +106 -43
- package/dist/cjs/src/schema/schema.js +123 -75
- package/dist/cjs/src/schema/string.js +152 -58
- package/dist/cjs/src/schema/union.js +412 -290
- package/dist/cjs/src/utils.js +42 -15
- package/dist/cjs/src/validators/array.js +6 -1
- package/dist/cjs/src/validators/boolean.js +2 -0
- package/dist/cjs/src/validators/datetime.js +4 -0
- package/dist/cjs/src/validators/number.js +12 -40
- package/dist/cjs/src/validators/object.js +1 -0
- package/dist/cjs/src/validators/schema.js +5 -1
- package/dist/cjs/src/validators/string.js +30 -2
- package/dist/cjs/src/validators/union.js +5 -4
- package/dist/cjs/src/validators/utils.js +99 -27
- package/dist/cjs/tsconfig.types.tsbuildinfo +1 -1
- package/dist/cjs/types/adapter/fields/array.d.ts +2 -2
- package/dist/cjs/types/adapter/fields/array.d.ts.map +1 -1
- package/dist/cjs/types/adapter/fields/boolean.d.ts.map +1 -1
- package/dist/cjs/types/adapter/fields/datetime.d.ts.map +1 -1
- package/dist/cjs/types/adapter/fields/index.d.ts +2 -2
- package/dist/cjs/types/adapter/fields/index.d.ts.map +1 -1
- package/dist/cjs/types/adapter/fields/number.d.ts.map +1 -1
- package/dist/cjs/types/adapter/fields/object.d.ts +2 -1
- package/dist/cjs/types/adapter/fields/object.d.ts.map +1 -1
- package/dist/cjs/types/adapter/fields/string.d.ts.map +1 -1
- package/dist/cjs/types/adapter/fields/union.d.ts.map +1 -1
- package/dist/cjs/types/adapter/index.d.ts +1 -0
- package/dist/cjs/types/adapter/index.d.ts.map +1 -1
- package/dist/cjs/types/adapter/types.d.ts +28 -18
- package/dist/cjs/types/adapter/types.d.ts.map +1 -1
- package/dist/cjs/types/constants.d.ts +0 -1
- package/dist/cjs/types/constants.d.ts.map +1 -1
- package/dist/cjs/types/domain.d.ts +5 -4
- package/dist/cjs/types/domain.d.ts.map +1 -1
- package/dist/cjs/types/index.d.ts +78 -55
- package/dist/cjs/types/index.d.ts.map +1 -1
- package/dist/cjs/types/model.d.ts +17 -17
- package/dist/cjs/types/model.d.ts.map +1 -1
- package/dist/cjs/types/schema/array.d.ts +168 -47
- package/dist/cjs/types/schema/array.d.ts.map +1 -1
- package/dist/cjs/types/schema/boolean.d.ts +103 -44
- package/dist/cjs/types/schema/boolean.d.ts.map +1 -1
- package/dist/cjs/types/schema/datetime.d.ts +90 -30
- package/dist/cjs/types/schema/datetime.d.ts.map +1 -1
- package/dist/cjs/types/schema/number.d.ts +133 -125
- package/dist/cjs/types/schema/number.d.ts.map +1 -1
- package/dist/cjs/types/schema/object.d.ts +104 -35
- package/dist/cjs/types/schema/object.d.ts.map +1 -1
- package/dist/cjs/types/schema/schema.d.ts +62 -44
- package/dist/cjs/types/schema/schema.d.ts.map +1 -1
- package/dist/cjs/types/schema/string.d.ts +152 -65
- package/dist/cjs/types/schema/string.d.ts.map +1 -1
- package/dist/cjs/types/schema/types.d.ts +11 -2
- package/dist/cjs/types/schema/types.d.ts.map +1 -1
- package/dist/cjs/types/schema/union.d.ts +133 -40
- package/dist/cjs/types/schema/union.d.ts.map +1 -1
- package/dist/cjs/types/types.d.ts +35 -0
- package/dist/cjs/types/types.d.ts.map +1 -1
- package/dist/cjs/types/utils.d.ts +41 -27
- package/dist/cjs/types/utils.d.ts.map +1 -1
- package/dist/cjs/types/validators/array.d.ts.map +1 -1
- package/dist/cjs/types/validators/boolean.d.ts.map +1 -1
- package/dist/cjs/types/validators/datetime.d.ts.map +1 -1
- package/dist/cjs/types/validators/number.d.ts +5 -6
- package/dist/cjs/types/validators/number.d.ts.map +1 -1
- package/dist/cjs/types/validators/object.d.ts.map +1 -1
- package/dist/cjs/types/validators/schema.d.ts +2 -2
- package/dist/cjs/types/validators/schema.d.ts.map +1 -1
- package/dist/cjs/types/validators/string.d.ts +9 -9
- package/dist/cjs/types/validators/string.d.ts.map +1 -1
- package/dist/cjs/types/validators/utils.d.ts +44 -27
- package/dist/cjs/types/validators/utils.d.ts.map +1 -1
- package/dist/esm/src/adapter/fields/index.js +2 -2
- package/dist/esm/src/adapter/fields/object.js +6 -0
- package/dist/esm/src/adapter/index.js +1 -0
- package/dist/esm/src/constants.js +1 -2
- package/dist/esm/src/domain.js +11 -1
- package/dist/esm/src/index.js +38 -73
- package/dist/esm/src/model.js +83 -78
- package/dist/esm/src/schema/array.js +136 -54
- package/dist/esm/src/schema/boolean.js +98 -44
- package/dist/esm/src/schema/datetime.js +91 -38
- package/dist/esm/src/schema/number.js +127 -110
- package/dist/esm/src/schema/object.js +98 -43
- package/dist/esm/src/schema/schema.js +102 -67
- package/dist/esm/src/schema/string.js +147 -59
- package/dist/esm/src/schema/union.js +119 -40
- package/dist/esm/src/types.js +14 -1
- package/dist/esm/src/utils.js +56 -27
- package/dist/esm/src/validators/array.js +6 -1
- package/dist/esm/src/validators/boolean.js +2 -0
- package/dist/esm/src/validators/datetime.js +4 -0
- package/dist/esm/src/validators/number.js +9 -23
- package/dist/esm/src/validators/object.js +1 -0
- package/dist/esm/src/validators/schema.js +5 -1
- package/dist/esm/src/validators/string.js +30 -2
- package/dist/esm/src/validators/union.js +5 -4
- package/dist/esm/src/validators/utils.js +62 -36
- package/package.json +3 -3
- package/src/adapter/fields/array.ts +2 -2
- package/src/adapter/fields/boolean.ts +3 -8
- package/src/adapter/fields/datetime.ts +3 -9
- package/src/adapter/fields/index.ts +11 -11
- package/src/adapter/fields/number.ts +3 -9
- package/src/adapter/fields/object.ts +13 -10
- package/src/adapter/fields/string.ts +3 -9
- package/src/adapter/fields/union.ts +3 -9
- package/src/adapter/index.ts +1 -0
- package/src/adapter/types.ts +60 -45
- package/src/constants.ts +1 -3
- package/src/domain.ts +15 -1
- package/src/index.ts +189 -211
- package/src/model.ts +119 -115
- package/src/schema/array.ts +274 -90
- package/src/schema/boolean.ts +145 -60
- package/src/schema/datetime.ts +133 -49
- package/src/schema/number.ts +210 -173
- package/src/schema/object.ts +167 -74
- package/src/schema/schema.ts +205 -126
- package/src/schema/string.ts +221 -94
- package/src/schema/types.ts +44 -16
- package/src/schema/union.ts +193 -68
- package/src/types.ts +53 -0
- package/src/utils.ts +115 -57
- package/src/validators/array.ts +46 -27
- package/src/validators/boolean.ts +13 -7
- package/src/validators/datetime.ts +24 -16
- package/src/validators/number.ts +53 -63
- package/src/validators/object.ts +6 -5
- package/src/validators/schema.ts +33 -25
- package/src/validators/string.ts +122 -59
- package/src/validators/union.ts +8 -8
- package/src/validators/utils.ts +67 -42
@@ -17,7 +17,6 @@ _export(exports, {
|
|
17
17
|
}
|
18
18
|
});
|
19
19
|
var _schema = /*#__PURE__*/ _interop_require_default(require("./schema"));
|
20
|
-
var _conf = require("../conf");
|
21
20
|
var _utils = require("../utils");
|
22
21
|
var _array = require("../validators/array");
|
23
22
|
var _schema1 = require("../validators/schema");
|
@@ -360,6 +359,12 @@ var ArraySchema = /*#__PURE__*/ function(Schema) {
|
|
360
359
|
var _this;
|
361
360
|
_this = _super.call(this);
|
362
361
|
_define_property(_assert_this_initialized(_this), "__schemas", void 0);
|
362
|
+
_define_property(_assert_this_initialized(_this), "__type", {
|
363
|
+
message: 'Invalid type',
|
364
|
+
check: function(value) {
|
365
|
+
return Array.isArray(value);
|
366
|
+
}
|
367
|
+
});
|
363
368
|
_define_property(_assert_this_initialized(_this), "__minLength", void 0);
|
364
369
|
_define_property(_assert_this_initialized(_this), "__maxLength", void 0);
|
365
370
|
_define_property(_assert_this_initialized(_this), "__nonEmpty", void 0);
|
@@ -449,6 +454,8 @@ var ArraySchema = /*#__PURE__*/ function(Schema) {
|
|
449
454
|
maxLength: _this.__maxLength,
|
450
455
|
minLength: _this.__minLength,
|
451
456
|
nonEmpty: _this.__nonEmpty,
|
457
|
+
schemas: transformedSchemas,
|
458
|
+
type: _this.__type,
|
452
459
|
parsers: {
|
453
460
|
nullable: _this.__nullable.allow,
|
454
461
|
optional: _this.__optional.allow
|
@@ -479,7 +486,7 @@ var ArraySchema = /*#__PURE__*/ function(Schema) {
|
|
479
486
|
return function(adapter) {
|
480
487
|
return _ref.apply(this, arguments);
|
481
488
|
};
|
482
|
-
}(), _this.__transformedSchemas, options, 'array')
|
489
|
+
}(), _this, _this.__transformedSchemas, options, 'array')
|
483
490
|
];
|
484
491
|
});
|
485
492
|
})();
|
@@ -487,7 +494,8 @@ var ArraySchema = /*#__PURE__*/ function(Schema) {
|
|
487
494
|
},
|
488
495
|
{
|
489
496
|
/**
|
490
|
-
* This let's you refine the schema with custom validations. This is useful when you want to validate something that
|
497
|
+
* This let's you refine the schema with custom validations. This is useful when you want to validate something that
|
498
|
+
* is not supported by default by the schema adapter.
|
491
499
|
*
|
492
500
|
* @example
|
493
501
|
* ```typescript
|
@@ -499,7 +507,8 @@ var ArraySchema = /*#__PURE__*/ function(Schema) {
|
|
499
507
|
*
|
500
508
|
* const { errors, parsed } = await numberSchema.parse(-1);
|
501
509
|
*
|
502
|
-
*
|
510
|
+
* // [{ isValid: false, code: 'invalid_number', message: 'The number should be greater than 0', path: [] }]
|
511
|
+
* console.log(errors);
|
503
512
|
* ```
|
504
513
|
*
|
505
514
|
* @param refinementCallback - The callback that will be called to validate the value.
|
@@ -512,9 +521,10 @@ var ArraySchema = /*#__PURE__*/ function(Schema) {
|
|
512
521
|
},
|
513
522
|
{
|
514
523
|
/**
|
515
|
-
* Allows the value to be either undefined or null. Different from the `optional` method on other schemas, You can
|
516
|
-
*
|
517
|
-
* This
|
524
|
+
* Allows the value to be either undefined or null. Different from the `optional` method on other schemas, You can
|
525
|
+
* pass `outputOnly` as `true` to this method.
|
526
|
+
* This will allow you to pass `null` or `undefined` as a value on the {@link Schema.data} method, but it will not
|
527
|
+
* allow the value to be `null` or `undefined`. This is useful for typing purposes.
|
518
528
|
*
|
519
529
|
* @example
|
520
530
|
* ```typescript
|
@@ -541,8 +551,10 @@ var ArraySchema = /*#__PURE__*/ function(Schema) {
|
|
541
551
|
* company: companySchema.optional({ outputOnly: true })
|
542
552
|
* });
|
543
553
|
*
|
544
|
-
*
|
545
|
-
* const
|
554
|
+
* // Will not allow the company to be null or undefined on a typing level.
|
555
|
+
* const { errors, parsed } = await userSchema.data({ id: 1, name: 'John Doe' });
|
556
|
+
* // Will allow the company to be null or undefined on a typing level
|
557
|
+
* const value = await userSchema.data({ id: 1, name: 'John Doe' });
|
546
558
|
* ```
|
547
559
|
*
|
548
560
|
* @returns - The schema we are working with.
|
@@ -553,8 +565,28 @@ var ArraySchema = /*#__PURE__*/ function(Schema) {
|
|
553
565
|
},
|
554
566
|
{
|
555
567
|
/**
|
556
|
-
*
|
557
|
-
*
|
568
|
+
* Just adds a message when the value is undefined. It's just a syntax sugar for
|
569
|
+
*
|
570
|
+
* ```typescript
|
571
|
+
* p.datetime().optional({ message: 'This value should be defined', allow: false })
|
572
|
+
* ```
|
573
|
+
*
|
574
|
+
* @param options - The options of nonOptional function
|
575
|
+
* @param options.message - A custom message if the value is undefined.
|
576
|
+
*
|
577
|
+
* @returns - The schema.
|
578
|
+
*/ key: "nonOptional",
|
579
|
+
value: function nonOptional(options) {
|
580
|
+
return _get(_get_prototype_of(ArraySchema.prototype), "optional", this).call(this, {
|
581
|
+
message: options === null || options === void 0 ? void 0 : options.message,
|
582
|
+
allow: false
|
583
|
+
});
|
584
|
+
}
|
585
|
+
},
|
586
|
+
{
|
587
|
+
/**
|
588
|
+
* Allows the value to be null and ONLY null. You can also use this function to set a custom message when the value
|
589
|
+
* is NULL by setting the { message: 'Your custom message', allow: false } on the options.
|
558
590
|
*
|
559
591
|
* @example
|
560
592
|
* ```typescript
|
@@ -583,14 +615,35 @@ var ArraySchema = /*#__PURE__*/ function(Schema) {
|
|
583
615
|
},
|
584
616
|
{
|
585
617
|
/**
|
586
|
-
*
|
587
|
-
*
|
618
|
+
* Just adds a message when the value is null. It's just a syntax sugar for
|
619
|
+
*
|
620
|
+
* ```typescript
|
621
|
+
* p.datetime().nullable({ message: 'This value cannot be null', allow: false })
|
622
|
+
* ```
|
623
|
+
*
|
624
|
+
* @param options - The options of nonNullable function
|
625
|
+
* @param options.message - A custom message if the value is null.
|
626
|
+
*
|
627
|
+
* @returns - The schema.
|
628
|
+
*/ key: "nonNullable",
|
629
|
+
value: function nonNullable(options) {
|
630
|
+
return _get(_get_prototype_of(ArraySchema.prototype), "nullable", this).call(this, {
|
631
|
+
message: (options === null || options === void 0 ? void 0 : options.message) || '',
|
632
|
+
allow: false
|
633
|
+
});
|
634
|
+
}
|
635
|
+
},
|
636
|
+
{
|
637
|
+
/**
|
638
|
+
* This method will remove the value from the representation of the schema. If the value is undefined it will keep
|
639
|
+
* that way otherwise it will set the value to undefined after it's validated.
|
588
640
|
* This is used in conjunction with the {@link data} function, the {@link parse} function or {@link validate}
|
589
641
|
* function. This will remove the value from the representation of the schema.
|
590
642
|
*
|
591
|
-
* By default, the value will be removed just from the representation, in other words, when you call the {@link data}
|
592
|
-
* But if you want to remove the value from the internal representation, you can pass the argument
|
593
|
-
* Then if you still want to remove the value from the representation, you will need to pass
|
643
|
+
* By default, the value will be removed just from the representation, in other words, when you call the {@link data}
|
644
|
+
* function. But if you want to remove the value from the internal representation, you can pass the argument
|
645
|
+
* `toInternal` as true. Then if you still want to remove the value from the representation, you will need to pass
|
646
|
+
* the argument `toRepresentation` as true as well.
|
594
647
|
*
|
595
648
|
* @example
|
596
649
|
* ```typescript
|
@@ -612,9 +665,12 @@ var ArraySchema = /*#__PURE__*/ function(Schema) {
|
|
612
665
|
* ```
|
613
666
|
*
|
614
667
|
*
|
615
|
-
* @param args - By default, the value will be removed just from the representation, in other words, when you call
|
616
|
-
*
|
617
|
-
*
|
668
|
+
* @param args - By default, the value will be removed just from the representation, in other words, when you call
|
669
|
+
* the {@link data} function.
|
670
|
+
* But if you want to remove the value from the internal representation, you can pass the argument `toInternal`
|
671
|
+
* as true.
|
672
|
+
* Then if you still want to remove the value from the representation, you will need to pass the argument
|
673
|
+
* `toRepresentation` as true as well.
|
618
674
|
*
|
619
675
|
* @returns The schema.
|
620
676
|
*/ key: "omit",
|
@@ -624,9 +680,9 @@ var ArraySchema = /*#__PURE__*/ function(Schema) {
|
|
624
680
|
},
|
625
681
|
{
|
626
682
|
/**
|
627
|
-
* This function is used in conjunction with the {@link validate} function. It's used to save a value to an external
|
628
|
-
* like a database. You should always return the schema after you save the value, that way we will always have
|
629
|
-
* of the schema after the save operation.
|
683
|
+
* This function is used in conjunction with the {@link validate} function. It's used to save a value to an external
|
684
|
+
* source like a database. You should always return the schema after you save the value, that way we will always have
|
685
|
+
* the correct type of the schema after the save operation.
|
630
686
|
*
|
631
687
|
* You can use the {@link toRepresentation} function to transform and clean the value it returns after the save.
|
632
688
|
*
|
@@ -671,7 +727,8 @@ var ArraySchema = /*#__PURE__*/ function(Schema) {
|
|
671
727
|
},
|
672
728
|
{
|
673
729
|
/**
|
674
|
-
* This function is used to add a default value to the schema. If the value is either undefined or null, the default
|
730
|
+
* This function is used to add a default value to the schema. If the value is either undefined or null, the default
|
731
|
+
* value will be used.
|
675
732
|
*
|
676
733
|
* @example
|
677
734
|
* ```typescript
|
@@ -688,10 +745,94 @@ var ArraySchema = /*#__PURE__*/ function(Schema) {
|
|
688
745
|
return _get(_get_prototype_of(ArraySchema.prototype), "default", this).call(this, defaultValueOrFunction);
|
689
746
|
}
|
690
747
|
},
|
748
|
+
{
|
749
|
+
key: "data",
|
750
|
+
value: /**
|
751
|
+
* This function is used to transform the value to the representation without validating it.
|
752
|
+
* This is useful when you want to return a data from a query directly to the user. But for example
|
753
|
+
* you are returning the data of a user, you can clean the password or any other sensitive data.
|
754
|
+
*
|
755
|
+
* @example
|
756
|
+
* ```typescript
|
757
|
+
* import * as p from '@palmares/schemas';
|
758
|
+
*
|
759
|
+
* const userSchema = p.object({
|
760
|
+
* id: p.number().optional(),
|
761
|
+
* name: p.string(),
|
762
|
+
* email: p.string().email(),
|
763
|
+
* password: p.string().optional()
|
764
|
+
* }).toRepresentation(async (value) => {
|
765
|
+
* return {
|
766
|
+
* id: value.id,
|
767
|
+
* name: value.name,
|
768
|
+
* email: value.email
|
769
|
+
* }
|
770
|
+
* });
|
771
|
+
*
|
772
|
+
* const user = await userSchema.data({
|
773
|
+
* id: 1,
|
774
|
+
* name: 'John Doe',
|
775
|
+
* email: 'john@gmail.com',
|
776
|
+
* password: '123456'
|
777
|
+
* });
|
778
|
+
* ```
|
779
|
+
*/ function data(value) {
|
780
|
+
var _this = this;
|
781
|
+
var _this1 = this, _superprop_get_data = function() {
|
782
|
+
return _get(_get_prototype_of(ArraySchema.prototype), "data", _this);
|
783
|
+
};
|
784
|
+
return _async_to_generator(function() {
|
785
|
+
var parsedValue;
|
786
|
+
return _ts_generator(this, function(_state) {
|
787
|
+
switch(_state.label){
|
788
|
+
case 0:
|
789
|
+
return [
|
790
|
+
4,
|
791
|
+
_superprop_get_data().call(_this1, value)
|
792
|
+
];
|
793
|
+
case 1:
|
794
|
+
parsedValue = _state.sent();
|
795
|
+
if (!Array.isArray(parsedValue)) return [
|
796
|
+
3,
|
797
|
+
3
|
798
|
+
];
|
799
|
+
return [
|
800
|
+
4,
|
801
|
+
Promise.all(Array.isArray(_this1.__schemas[0]) ? parsedValue.map(function(value) {
|
802
|
+
var schema = _this1.__schemas[0][0];
|
803
|
+
return (0, _utils.shouldRunDataOnComplexSchemas)(schema) ? schema.data(value) : value;
|
804
|
+
}) : _this1.__schemas.map(function() {
|
805
|
+
var _ref = _async_to_generator(function(schema) {
|
806
|
+
return _ts_generator(this, function(_state) {
|
807
|
+
return [
|
808
|
+
2,
|
809
|
+
(0, _utils.shouldRunDataOnComplexSchemas)(schema) ? schema.data(value) : value
|
810
|
+
];
|
811
|
+
});
|
812
|
+
});
|
813
|
+
return function(schema) {
|
814
|
+
return _ref.apply(this, arguments);
|
815
|
+
};
|
816
|
+
}()))
|
817
|
+
];
|
818
|
+
case 2:
|
819
|
+
parsedValue = _state.sent();
|
820
|
+
_state.label = 3;
|
821
|
+
case 3:
|
822
|
+
return [
|
823
|
+
2,
|
824
|
+
parsedValue
|
825
|
+
];
|
826
|
+
}
|
827
|
+
});
|
828
|
+
})();
|
829
|
+
}
|
830
|
+
},
|
691
831
|
{
|
692
832
|
/**
|
693
|
-
* This function let's you customize the schema your own way. After we translate the schema on the adapter we call
|
694
|
-
* the custom schema your own way. Our API does not support passthrough?
|
833
|
+
* This function let's you customize the schema your own way. After we translate the schema on the adapter we call
|
834
|
+
* this function to let you customize the custom schema your own way. Our API does not support passthrough?
|
835
|
+
* No problem, you can use this function to customize the zod schema.
|
695
836
|
*
|
696
837
|
* @example
|
697
838
|
* ```typescript
|
@@ -703,12 +844,13 @@ var ArraySchema = /*#__PURE__*/ function(Schema) {
|
|
703
844
|
*
|
704
845
|
* const { errors, parsed } = await numberSchema.parse(-1);
|
705
846
|
*
|
706
|
-
*
|
847
|
+
* // [{ isValid: false, code: 'nonnegative', message: 'The number should be nonnegative', path: [] }]
|
848
|
+
* console.log(errors);
|
707
849
|
* ```
|
708
850
|
*
|
709
851
|
* @param callback - The callback that will be called to customize the schema.
|
710
|
-
* @param toStringCallback - The callback that will be called to transform the schema to a string when you want to
|
711
|
-
* to a string so you can save it for future runs.
|
852
|
+
* @param toStringCallback - The callback that will be called to transform the schema to a string when you want to
|
853
|
+
* compile the underlying schema to a string so you can save it for future runs.
|
712
854
|
*
|
713
855
|
* @returns The schema.
|
714
856
|
*/ key: "extends",
|
@@ -718,8 +860,9 @@ var ArraySchema = /*#__PURE__*/ function(Schema) {
|
|
718
860
|
},
|
719
861
|
{
|
720
862
|
/**
|
721
|
-
* This function is used to transform the value to the representation of the schema. When using the {@link data}
|
722
|
-
* control to add data cleaning for example, transforming the data and
|
863
|
+
* This function is used to transform the value to the representation of the schema. When using the {@link data}
|
864
|
+
* function. With this function you have full control to add data cleaning for example, transforming the data and
|
865
|
+
* whatever. Another use case is when you want to return deeply nested recursive data.
|
723
866
|
* The schema maps to itself.
|
724
867
|
*
|
725
868
|
* @example
|
@@ -766,8 +909,9 @@ var ArraySchema = /*#__PURE__*/ function(Schema) {
|
|
766
909
|
},
|
767
910
|
{
|
768
911
|
/**
|
769
|
-
* This function is used to transform the value to the internal representation of the schema. This is useful when you
|
770
|
-
* to a type that the schema adapter can understand. For example, you might want to
|
912
|
+
* This function is used to transform the value to the internal representation of the schema. This is useful when you
|
913
|
+
* want to transform the value to a type that the schema adapter can understand. For example, you might want to
|
914
|
+
* transform a string to a date. This is the function you use.
|
771
915
|
*
|
772
916
|
* @example
|
773
917
|
* ```typescript
|
@@ -803,8 +947,9 @@ var ArraySchema = /*#__PURE__*/ function(Schema) {
|
|
803
947
|
},
|
804
948
|
{
|
805
949
|
/**
|
806
|
-
* Called before the validation of the schema. Let's say that you want to validate a date that might receive a string,
|
807
|
-
* here BEFORE the validation. This pretty much transforms the value to a type
|
950
|
+
* Called before the validation of the schema. Let's say that you want to validate a date that might receive a string,
|
951
|
+
* you can convert that string to a date here BEFORE the validation. This pretty much transforms the value to a type
|
952
|
+
* that the schema adapter can understand.
|
808
953
|
*
|
809
954
|
* @example
|
810
955
|
* ```
|
@@ -828,12 +973,11 @@ var ArraySchema = /*#__PURE__*/ function(Schema) {
|
|
828
973
|
},
|
829
974
|
{
|
830
975
|
key: "minLength",
|
831
|
-
value: function minLength(value) {
|
832
|
-
var
|
833
|
-
message = message || "The array must have a minimum length of ".concat(value);
|
976
|
+
value: function minLength(value, options) {
|
977
|
+
var message = (options === null || options === void 0 ? void 0 : options.message) || "The array must have a minimum length of ".concat(value);
|
834
978
|
this.__minLength = {
|
835
979
|
value: value,
|
836
|
-
inclusive: inclusive,
|
980
|
+
inclusive: typeof (options === null || options === void 0 ? void 0 : options.inclusive) === 'boolean' ? options.inclusive : true,
|
837
981
|
message: message
|
838
982
|
};
|
839
983
|
return this;
|
@@ -841,22 +985,11 @@ var ArraySchema = /*#__PURE__*/ function(Schema) {
|
|
841
985
|
},
|
842
986
|
{
|
843
987
|
key: "maxLength",
|
844
|
-
value: function maxLength(value) {
|
845
|
-
var
|
846
|
-
message = message || "The array must have a maximum length of ".concat(value);
|
988
|
+
value: function maxLength(value, options) {
|
989
|
+
var message = (options === null || options === void 0 ? void 0 : options.message) || "The array must have a maximum length of ".concat(value);
|
847
990
|
this.__maxLength = {
|
848
991
|
value: value,
|
849
|
-
inclusive: inclusive,
|
850
|
-
message: message
|
851
|
-
};
|
852
|
-
return this;
|
853
|
-
}
|
854
|
-
},
|
855
|
-
{
|
856
|
-
key: "nonEmpty",
|
857
|
-
value: function nonEmpty(message) {
|
858
|
-
message = message || 'The array must not be empty';
|
859
|
-
this.__nonEmpty = {
|
992
|
+
inclusive: typeof (options === null || options === void 0 ? void 0 : options.inclusive) === 'boolean' ? options.inclusive : true,
|
860
993
|
message: message
|
861
994
|
};
|
862
995
|
return this;
|
@@ -870,12 +1003,6 @@ var ArraySchema = /*#__PURE__*/ function(Schema) {
|
|
870
1003
|
schemas[_key] = arguments[_key];
|
871
1004
|
}
|
872
1005
|
var returnValue = _construct(ArraySchema, _to_consumable_array(schemas));
|
873
|
-
var adapterInstance = (0, _conf.getDefaultAdapter)();
|
874
|
-
returnValue.__transformedSchemas[adapterInstance.constructor.name] = {
|
875
|
-
transformed: false,
|
876
|
-
adapter: adapterInstance,
|
877
|
-
schemas: []
|
878
|
-
};
|
879
1006
|
return returnValue;
|
880
1007
|
}
|
881
1008
|
}
|