@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,8 +17,8 @@ _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");
|
21
|
+
var _schema1 = require("../validators/schema");
|
22
22
|
var _string = require("../validators/string");
|
23
23
|
function _assert_this_initialized(self) {
|
24
24
|
if (self === void 0) {
|
@@ -287,6 +287,12 @@ var StringSchema = /*#__PURE__*/ function(Schema) {
|
|
287
287
|
_define_property(_assert_this_initialized(_this), "__endsWith", void 0);
|
288
288
|
_define_property(_assert_this_initialized(_this), "__startsWith", void 0);
|
289
289
|
_define_property(_assert_this_initialized(_this), "__includes", void 0);
|
290
|
+
_define_property(_assert_this_initialized(_this), "__type", {
|
291
|
+
message: 'Invalid type',
|
292
|
+
check: function(value) {
|
293
|
+
return typeof value === 'string';
|
294
|
+
}
|
295
|
+
});
|
290
296
|
return _this;
|
291
297
|
}
|
292
298
|
_create_class(StringSchema, [
|
@@ -305,6 +311,10 @@ var StringSchema = /*#__PURE__*/ function(Schema) {
|
|
305
311
|
2,
|
306
312
|
(0, _utils.defaultTransform)('string', _this, adapter, adapter.string, function() {
|
307
313
|
return {
|
314
|
+
type: _this.__type,
|
315
|
+
is: _this.__is,
|
316
|
+
email: _this.__email,
|
317
|
+
uuid: _this.__uuid,
|
308
318
|
minLength: _this.__minLength,
|
309
319
|
maxLength: _this.__maxLength,
|
310
320
|
regex: _this.__regex,
|
@@ -323,8 +333,13 @@ var StringSchema = /*#__PURE__*/ function(Schema) {
|
|
323
333
|
minLength: _string.minLength,
|
324
334
|
endsWith: _string.endsWith,
|
325
335
|
startsWith: _string.startsWith,
|
336
|
+
email: _string.email,
|
337
|
+
uuid: _string.uuid,
|
338
|
+
is: _schema1.is,
|
326
339
|
regex: _string.regex,
|
327
|
-
includes: _string.includes
|
340
|
+
includes: _string.includes,
|
341
|
+
nullable: _schema1.nullable,
|
342
|
+
optional: _schema1.optional
|
328
343
|
}, {
|
329
344
|
validatorsIfFallbackOrNotSupported: (0, _string.stringValidation)(),
|
330
345
|
shouldAddStringVersion: options.shouldAddStringVersion,
|
@@ -344,7 +359,7 @@ var StringSchema = /*#__PURE__*/ function(Schema) {
|
|
344
359
|
return function(adapter) {
|
345
360
|
return _ref.apply(this, arguments);
|
346
361
|
};
|
347
|
-
}(), _this.__transformedSchemas, options, 'number')
|
362
|
+
}(), _this, _this.__transformedSchemas, options, 'number')
|
348
363
|
];
|
349
364
|
});
|
350
365
|
})();
|
@@ -352,7 +367,8 @@ var StringSchema = /*#__PURE__*/ function(Schema) {
|
|
352
367
|
},
|
353
368
|
{
|
354
369
|
/**
|
355
|
-
* This let's you refine the schema with custom validations. This is useful when you want to validate something that
|
370
|
+
* This let's you refine the schema with custom validations. This is useful when you want to validate something that
|
371
|
+
* is not supported by default by the schema adapter.
|
356
372
|
*
|
357
373
|
* @example
|
358
374
|
* ```typescript
|
@@ -364,7 +380,8 @@ var StringSchema = /*#__PURE__*/ function(Schema) {
|
|
364
380
|
*
|
365
381
|
* const { errors, parsed } = await numberSchema.parse(-1);
|
366
382
|
*
|
367
|
-
*
|
383
|
+
* // [{ isValid: false, code: 'invalid_number', message: 'The number should be greater than 0', path: [] }]
|
384
|
+
* console.log(errors);
|
368
385
|
* ```
|
369
386
|
*
|
370
387
|
* @param refinementCallback - The callback that will be called to validate the value.
|
@@ -400,14 +417,34 @@ var StringSchema = /*#__PURE__*/ function(Schema) {
|
|
400
417
|
*
|
401
418
|
* @returns - The schema we are working with.
|
402
419
|
*/ key: "optional",
|
403
|
-
value: function optional(
|
404
|
-
return _get(_get_prototype_of(StringSchema.prototype), "optional", this).call(this
|
420
|
+
value: function optional() {
|
421
|
+
return _get(_get_prototype_of(StringSchema.prototype), "optional", this).call(this);
|
422
|
+
}
|
423
|
+
},
|
424
|
+
{
|
425
|
+
/**
|
426
|
+
* Just adds a message when the value is undefined. It's just a syntax sugar for
|
427
|
+
*
|
428
|
+
* ```typescript
|
429
|
+
* p.string().optional({ message: 'This value cannot be null', allow: false })
|
430
|
+
* ```
|
431
|
+
*
|
432
|
+
* @param options - The options of nonOptional function
|
433
|
+
* @param options.message - A custom message if the value is undefined.
|
434
|
+
*
|
435
|
+
* @returns - The schema.
|
436
|
+
*/ key: "nonOptional",
|
437
|
+
value: function nonOptional(options) {
|
438
|
+
return _get(_get_prototype_of(StringSchema.prototype), "optional", this).call(this, {
|
439
|
+
message: options === null || options === void 0 ? void 0 : options.message,
|
440
|
+
allow: false
|
441
|
+
});
|
405
442
|
}
|
406
443
|
},
|
407
444
|
{
|
408
445
|
/**
|
409
|
-
* Allows the value to be null and ONLY null. You can also use this function to set a custom message when the value
|
410
|
-
* the { message: 'Your custom message', allow: false } on the options.
|
446
|
+
* Allows the value to be null and ONLY null. You can also use this function to set a custom message when the value
|
447
|
+
* is NULL by setting the { message: 'Your custom message', allow: false } on the options.
|
411
448
|
*
|
412
449
|
* @example
|
413
450
|
* ```typescript
|
@@ -436,14 +473,35 @@ var StringSchema = /*#__PURE__*/ function(Schema) {
|
|
436
473
|
},
|
437
474
|
{
|
438
475
|
/**
|
439
|
-
*
|
440
|
-
*
|
476
|
+
* Just adds a message when the value is null. It's just a syntax sugar for
|
477
|
+
*
|
478
|
+
* ```typescript
|
479
|
+
* p.string().nullable({ message: 'This value cannot be null', allow: false })
|
480
|
+
* ```
|
481
|
+
*
|
482
|
+
* @param options - The options of nonNullable function
|
483
|
+
* @param options.message - A custom message if the value is null.
|
484
|
+
*
|
485
|
+
* @returns - The schema.
|
486
|
+
*/ key: "nonNullable",
|
487
|
+
value: function nonNullable(options) {
|
488
|
+
return _get(_get_prototype_of(StringSchema.prototype), "nullable", this).call(this, {
|
489
|
+
message: (options === null || options === void 0 ? void 0 : options.message) || '',
|
490
|
+
allow: false
|
491
|
+
});
|
492
|
+
}
|
493
|
+
},
|
494
|
+
{
|
495
|
+
/**
|
496
|
+
* This method will remove the value from the representation of the schema. If the value is undefined it will keep
|
497
|
+
* that way otherwise it will set the value to undefined after it's validated.
|
441
498
|
* This is used in conjunction with the {@link data} function, the {@link parse} function or {@link validate}
|
442
499
|
* function. This will remove the value from the representation of the schema.
|
443
500
|
*
|
444
|
-
* By default, the value will be removed just from the representation, in other words, when you call the {@link data}
|
445
|
-
* But if you want to remove the value from the internal representation, you can pass the argument
|
446
|
-
* Then if you still want to remove the value from the representation, you will need to pass
|
501
|
+
* By default, the value will be removed just from the representation, in other words, when you call the {@link data}
|
502
|
+
* function. But if you want to remove the value from the internal representation, you can pass the argument
|
503
|
+
* `toInternal` as true. Then if you still want to remove the value from the representation, you will need to pass
|
504
|
+
* the argument `toRepresentation` as true as well.
|
447
505
|
*
|
448
506
|
* @example
|
449
507
|
* ```typescript
|
@@ -465,9 +523,10 @@ var StringSchema = /*#__PURE__*/ function(Schema) {
|
|
465
523
|
* ```
|
466
524
|
*
|
467
525
|
*
|
468
|
-
* @param args - By default, the value will be removed just from the representation, in other words, when you call
|
469
|
-
* But if you want to remove the value from the internal representation, you can pass the
|
470
|
-
* Then if you still want to remove the value from the representation, you will need
|
526
|
+
* @param args - By default, the value will be removed just from the representation, in other words, when you call
|
527
|
+
* the {@link data} function. But if you want to remove the value from the internal representation, you can pass the
|
528
|
+
* argument `toInternal` as true. Then if you still want to remove the value from the representation, you will need
|
529
|
+
* to pass the argument `toRepresentation` as true as well.
|
471
530
|
*
|
472
531
|
* @returns The schema.
|
473
532
|
*/ key: "omit",
|
@@ -477,9 +536,9 @@ var StringSchema = /*#__PURE__*/ function(Schema) {
|
|
477
536
|
},
|
478
537
|
{
|
479
538
|
/**
|
480
|
-
* This function is used in conjunction with the {@link validate} function. It's used to save a value to an external
|
481
|
-
* like a database. You should always return the schema after you save the value, that way we will always have
|
482
|
-
* of the schema after the save operation.
|
539
|
+
* This function is used in conjunction with the {@link validate} function. It's used to save a value to an external
|
540
|
+
* source like a database. You should always return the schema after you save the value, that way we will always have
|
541
|
+
* the correct type of the schema after the save operation.
|
483
542
|
*
|
484
543
|
* You can use the {@link toRepresentation} function to transform and clean the value it returns after the save.
|
485
544
|
*
|
@@ -524,7 +583,8 @@ var StringSchema = /*#__PURE__*/ function(Schema) {
|
|
524
583
|
},
|
525
584
|
{
|
526
585
|
/**
|
527
|
-
* This function is used to add a default value to the schema. If the value is either undefined or null, the default
|
586
|
+
* This function is used to add a default value to the schema. If the value is either undefined or null, the default
|
587
|
+
* value will be used.
|
528
588
|
*
|
529
589
|
* @example
|
530
590
|
* ```typescript
|
@@ -543,8 +603,9 @@ var StringSchema = /*#__PURE__*/ function(Schema) {
|
|
543
603
|
},
|
544
604
|
{
|
545
605
|
/**
|
546
|
-
* This function let's you customize the schema your own way. After we translate the schema on the adapter we call
|
547
|
-
* the custom schema your own way. Our API does not support passthrough?
|
606
|
+
* This function let's you customize the schema your own way. After we translate the schema on the adapter we call
|
607
|
+
* this function to let you customize the custom schema your own way. Our API does not support passthrough?
|
608
|
+
* No problem, you can use this function to customize the zod schema.
|
548
609
|
*
|
549
610
|
* @example
|
550
611
|
* ```typescript
|
@@ -555,13 +616,13 @@ var StringSchema = /*#__PURE__*/ function(Schema) {
|
|
555
616
|
* });
|
556
617
|
*
|
557
618
|
* const { errors, parsed } = await numberSchema.parse(-1);
|
558
|
-
*
|
559
|
-
* console.log(errors);
|
619
|
+
* // [{ isValid: false, code: 'nonnegative', message: 'The number should be nonnegative', path: [] }]
|
620
|
+
* console.log(errors);
|
560
621
|
* ```
|
561
622
|
*
|
562
623
|
* @param callback - The callback that will be called to customize the schema.
|
563
|
-
* @param toStringCallback - The callback that will be called to transform the schema to a string when you want to
|
564
|
-
* to a string so you can save it for future runs.
|
624
|
+
* @param toStringCallback - The callback that will be called to transform the schema to a string when you want to
|
625
|
+
* compile the underlying schema to a string so you can save it for future runs.
|
565
626
|
*
|
566
627
|
* @returns The schema.
|
567
628
|
*/ key: "extends",
|
@@ -571,8 +632,9 @@ var StringSchema = /*#__PURE__*/ function(Schema) {
|
|
571
632
|
},
|
572
633
|
{
|
573
634
|
/**
|
574
|
-
* This function is used to transform the value to the representation of the schema. When using the {@link data}
|
575
|
-
* control to add data cleaning for example, transforming the data and
|
635
|
+
* This function is used to transform the value to the representation of the schema. When using the {@link data}
|
636
|
+
* function. With this function you have full control to add data cleaning for example, transforming the data and
|
637
|
+
* whatever. Another use case is when you want to return deeply nested recursive data.
|
576
638
|
* The schema maps to itself.
|
577
639
|
*
|
578
640
|
* @example
|
@@ -619,8 +681,9 @@ var StringSchema = /*#__PURE__*/ function(Schema) {
|
|
619
681
|
},
|
620
682
|
{
|
621
683
|
/**
|
622
|
-
* This function is used to transform the value to the internal representation of the schema. This is useful when
|
623
|
-
* to a type that the schema adapter can understand. For example, you might want
|
684
|
+
* This function is used to transform the value to the internal representation of the schema. This is useful when
|
685
|
+
* you want to transform the value to a type that the schema adapter can understand. For example, you might want
|
686
|
+
* to transform a string to a date. This is the function you use.
|
624
687
|
*
|
625
688
|
* @example
|
626
689
|
* ```typescript
|
@@ -656,8 +719,9 @@ var StringSchema = /*#__PURE__*/ function(Schema) {
|
|
656
719
|
},
|
657
720
|
{
|
658
721
|
/**
|
659
|
-
* Called before the validation of the schema. Let's say that you want to validate a date that might receive a string,
|
660
|
-
* here BEFORE the validation. This pretty much transforms the value to a
|
722
|
+
* Called before the validation of the schema. Let's say that you want to validate a date that might receive a string,
|
723
|
+
* you can convert that string to a date here BEFORE the validation. This pretty much transforms the value to a
|
724
|
+
* type that the schema adapter can understand.
|
661
725
|
*
|
662
726
|
* @example
|
663
727
|
* ```typescript
|
@@ -681,7 +745,8 @@ var StringSchema = /*#__PURE__*/ function(Schema) {
|
|
681
745
|
},
|
682
746
|
{
|
683
747
|
/**
|
684
|
-
* Defines a list of strings that are allowed, it's useful when you want to restrict the values that are allowed.
|
748
|
+
* Defines a list of strings that are allowed, it's useful when you want to restrict the values that are allowed.
|
749
|
+
* Like a selector or a Choice field.
|
685
750
|
*
|
686
751
|
* @example
|
687
752
|
* ```typescript
|
@@ -690,17 +755,21 @@ var StringSchema = /*#__PURE__*/ function(Schema) {
|
|
690
755
|
* const schema = p.string().is(['Argentina', 'Brazil', 'Chile']);
|
691
756
|
*
|
692
757
|
* schema.parse('Argentina'); // { errors: [], parsed: 'Argentina' }
|
693
|
-
*
|
758
|
+
* // { errors: [{
|
759
|
+
* // code: 'invalid_value',
|
760
|
+
* // message: 'The value should be equal to Argentina, Brazil, Chile',
|
761
|
+
* // path: [] }], parsed: 'Uruguay' }
|
762
|
+
* schema.parse('Uruguay');
|
694
763
|
* ```
|
695
764
|
*
|
696
765
|
* @param value - The list of numbers that are allowed
|
697
766
|
*
|
698
767
|
* @returns - The schema instance
|
699
768
|
*/ key: "is",
|
700
|
-
value: function is(value) {
|
769
|
+
value: function is(value, options) {
|
701
770
|
this.__is = {
|
702
771
|
value: value,
|
703
|
-
message: "The value should be equal to ".concat(value.join(', '))
|
772
|
+
message: typeof (options === null || options === void 0 ? void 0 : options.message) === 'string' ? options.message : "The value should be equal to ".concat(value.join(', '))
|
704
773
|
};
|
705
774
|
return this;
|
706
775
|
}
|
@@ -716,7 +785,9 @@ var StringSchema = /*#__PURE__*/ function(Schema) {
|
|
716
785
|
* const schema = p.string().endsWith('.com');
|
717
786
|
*
|
718
787
|
* schema.parse('example.com'); // { errors: [], parsed: 'example.com' }
|
719
|
-
*
|
788
|
+
*
|
789
|
+
* // { errors: [{ code: 'endsWith', message: 'The value should end with .com', path: [] }], parsed: 'example.org' }
|
790
|
+
* schema.parse('example.org');
|
720
791
|
* ```
|
721
792
|
*
|
722
793
|
* @param value - The value that the string should end with.
|
@@ -744,7 +815,11 @@ var StringSchema = /*#__PURE__*/ function(Schema) {
|
|
744
815
|
* const schema = p.string().startsWith('https://');
|
745
816
|
*
|
746
817
|
* schema.parse('https://example.com'); // { errors: [], parsed: 'https://example.com' }
|
747
|
-
*
|
818
|
+
* // {
|
819
|
+
* // errors: [{ code: 'startsWith', message: 'The value should start with https://', path: [] }],
|
820
|
+
* // parsed: 'http://example.com'
|
821
|
+
* // }
|
822
|
+
* schema.parse('http://example.com');
|
748
823
|
* ```
|
749
824
|
*
|
750
825
|
* @param value - The value that the string should start with.
|
@@ -772,7 +847,13 @@ var StringSchema = /*#__PURE__*/ function(Schema) {
|
|
772
847
|
* const schema = p.string().includes('for babies');
|
773
848
|
*
|
774
849
|
* schema.parse('Computer graphics for babies'); // { errors: [], parsed: 'Computer graphics for babies' }
|
775
|
-
*
|
850
|
+
* // {
|
851
|
+
* // errors: [{
|
852
|
+
* // code: 'includes',
|
853
|
+
* // message: 'The string value should include the following substring 'for babies',
|
854
|
+
* // path: []
|
855
|
+
* // }], parsed: 'example.org' }
|
856
|
+
* schema.parse('Learn javascript as you were 5');
|
776
857
|
* ```
|
777
858
|
*
|
778
859
|
* @param value - The value that the string should include.
|
@@ -800,7 +881,15 @@ var StringSchema = /*#__PURE__*/ function(Schema) {
|
|
800
881
|
* const schema = p.string().regex(/^[a-z]+$/);
|
801
882
|
*
|
802
883
|
* schema.parse('abc'); // { errors: [], parsed: 'abc' }
|
803
|
-
*
|
884
|
+
* // {
|
885
|
+
* // errors: [{
|
886
|
+
* // code: 'regex',
|
887
|
+
* // message: 'The value should match the following regex /^[a-z]+$/',
|
888
|
+
* // path: []
|
889
|
+
* // }],
|
890
|
+
* // parsed: '123'
|
891
|
+
* // }
|
892
|
+
* schema.parse('123');
|
804
893
|
* ```
|
805
894
|
*
|
806
895
|
* @param value - The regex that the string should match.
|
@@ -819,7 +908,8 @@ var StringSchema = /*#__PURE__*/ function(Schema) {
|
|
819
908
|
},
|
820
909
|
{
|
821
910
|
/**
|
822
|
-
* Validates if the string has a maximum length. Use { inclusive: true } to allow the value to have the same length
|
911
|
+
* Validates if the string has a maximum length. Use { inclusive: true } to allow the value to have the same length
|
912
|
+
* as the maximum length.
|
823
913
|
*
|
824
914
|
* @example
|
825
915
|
* ```typescript
|
@@ -828,7 +918,11 @@ var StringSchema = /*#__PURE__*/ function(Schema) {
|
|
828
918
|
* const schema = p.string().maxLength(5);
|
829
919
|
*
|
830
920
|
* schema.parse('12345'); // { errors: [], parsed: '12345' }
|
831
|
-
*
|
921
|
+
* // {
|
922
|
+
* // errors: [{ code: 'maxLength', message: 'The value should have a maximum length of 5', path: [] }],
|
923
|
+
* // parsed: '123
|
924
|
+
* // }
|
925
|
+
* schema.parse('123456');
|
832
926
|
* ```
|
833
927
|
*
|
834
928
|
* @param value - The maximum length that the string should have.
|
@@ -841,15 +935,15 @@ var StringSchema = /*#__PURE__*/ function(Schema) {
|
|
841
935
|
value: function maxLength(value, options) {
|
842
936
|
this.__maxLength = {
|
843
937
|
value: value,
|
844
|
-
message: (options === null || options === void 0 ? void 0 : options.message) || "The value should have a maximum length of ".concat(value)
|
845
|
-
inclusive: typeof (options === null || options === void 0 ? void 0 : options.inclusive) === 'boolean' ? options.inclusive : false
|
938
|
+
message: (options === null || options === void 0 ? void 0 : options.message) || "The value should have a maximum length of ".concat(value)
|
846
939
|
};
|
847
940
|
return this;
|
848
941
|
}
|
849
942
|
},
|
850
943
|
{
|
851
944
|
/**
|
852
|
-
* Validates if the string has a minimum length. Use { inclusive: true } to allow the value to have the same length
|
945
|
+
* Validates if the string has a minimum length. Use { inclusive: true } to allow the value to have the same length
|
946
|
+
* as the minimum length.
|
853
947
|
*
|
854
948
|
* @example
|
855
949
|
* ```typescript
|
@@ -858,7 +952,11 @@ var StringSchema = /*#__PURE__*/ function(Schema) {
|
|
858
952
|
* const schema = p.string().minLength(5);
|
859
953
|
*
|
860
954
|
* schema.parse('12345'); // { errors: [], parsed: '12345' }
|
861
|
-
*
|
955
|
+
* // {
|
956
|
+
* // errors: [{ code: 'minLength', message: 'The value should have a minimum length of 5', path: [] }],
|
957
|
+
* // parsed: '1234'
|
958
|
+
* // }
|
959
|
+
* schema.parse('1234');
|
862
960
|
* ```
|
863
961
|
*
|
864
962
|
* @param value - The minimum length that the string should have.
|
@@ -871,8 +969,7 @@ var StringSchema = /*#__PURE__*/ function(Schema) {
|
|
871
969
|
value: function minLength(value, options) {
|
872
970
|
this.__minLength = {
|
873
971
|
value: value,
|
874
|
-
message: (options === null || options === void 0 ? void 0 : options.message) || "The value should have a minimum length of ".concat(value)
|
875
|
-
inclusive: typeof (options === null || options === void 0 ? void 0 : options.inclusive) === 'boolean' ? options.inclusive : false
|
972
|
+
message: (options === null || options === void 0 ? void 0 : options.message) || "The value should have a minimum length of ".concat(value)
|
876
973
|
};
|
877
974
|
return this;
|
878
975
|
}
|
@@ -887,11 +984,13 @@ var StringSchema = /*#__PURE__*/ function(Schema) {
|
|
887
984
|
*
|
888
985
|
* const schema = p.string().uuid();
|
889
986
|
*
|
890
|
-
*
|
987
|
+
* // { errors: [], parsed: '550e8400-e29b-41d4-a716-446655440000' }
|
988
|
+
* schema.parse('550e8400-e29b-41d4-a716-446655440000');
|
891
989
|
* ```
|
892
990
|
*
|
893
991
|
* @param options - The options for the uuid function.
|
894
|
-
* @param options.message - The message to be shown when the value is not a valid UUID. Defaults to
|
992
|
+
* @param options.message - The message to be shown when the value is not a valid UUID. Defaults to
|
993
|
+
* 'The value should be a valid UUID'.
|
895
994
|
*
|
896
995
|
* @returns - The schema instance.
|
897
996
|
*/ key: "uuid",
|
@@ -917,7 +1016,8 @@ var StringSchema = /*#__PURE__*/ function(Schema) {
|
|
917
1016
|
* ```
|
918
1017
|
*
|
919
1018
|
* @param options - The options for the email function.
|
920
|
-
* @param options.message - The message to be shown when the value is not a valid email.
|
1019
|
+
* @param options.message - The message to be shown when the value is not a valid email.
|
1020
|
+
* Defaults to 'The value should be a valid email'.
|
921
1021
|
*
|
922
1022
|
* @returns - The schema instance.
|
923
1023
|
*/ key: "email",
|
@@ -933,12 +1033,6 @@ var StringSchema = /*#__PURE__*/ function(Schema) {
|
|
933
1033
|
key: "new",
|
934
1034
|
value: function _new() {
|
935
1035
|
var returnValue = new StringSchema();
|
936
|
-
var adapterInstance = (0, _conf.getDefaultAdapter)();
|
937
|
-
returnValue.__transformedSchemas[adapterInstance.constructor.name] = {
|
938
|
-
transformed: false,
|
939
|
-
adapter: adapterInstance,
|
940
|
-
schemas: []
|
941
|
-
};
|
942
1036
|
return returnValue;
|
943
1037
|
}
|
944
1038
|
}
|