@palmares/schemas 0.1.25 → 0.2.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/CHANGELOG.md +26 -0
- package/dist/src/adapter/fields/array.cjs +96 -0
- package/dist/src/adapter/fields/array.d.ts.map +1 -0
- package/dist/src/adapter/fields/array.js +70 -0
- package/dist/src/adapter/fields/boolean.cjs +102 -0
- package/dist/src/adapter/fields/boolean.d.ts.map +1 -0
- package/dist/src/adapter/fields/boolean.js +76 -0
- package/dist/src/adapter/fields/datetime.cjs +102 -0
- package/dist/src/adapter/fields/datetime.d.ts.map +1 -0
- package/dist/src/adapter/fields/datetime.js +76 -0
- package/dist/src/adapter/fields/index.cjs +87 -0
- package/dist/src/adapter/fields/index.d.ts.map +1 -0
- package/dist/src/adapter/fields/index.js +61 -0
- package/dist/src/adapter/fields/number.cjs +102 -0
- package/dist/src/adapter/fields/number.d.ts.map +1 -0
- package/dist/src/adapter/fields/number.js +76 -0
- package/dist/src/adapter/fields/object.cjs +108 -0
- package/dist/src/adapter/fields/object.d.ts.map +1 -0
- package/dist/src/adapter/fields/object.js +82 -0
- package/dist/src/adapter/fields/string.cjs +102 -0
- package/dist/src/adapter/fields/string.d.ts.map +1 -0
- package/dist/src/adapter/fields/string.js +76 -0
- package/dist/src/adapter/fields/union.cjs +102 -0
- package/dist/src/adapter/fields/union.d.ts.map +1 -0
- package/dist/src/adapter/fields/union.js +76 -0
- package/dist/src/adapter/index.cjs +65 -0
- package/dist/src/adapter/index.d.ts.map +1 -0
- package/dist/src/adapter/index.js +40 -0
- package/dist/src/adapter/types.cjs +18 -0
- package/dist/src/adapter/types.d.ts.map +1 -0
- package/dist/src/adapter/types.js +0 -0
- package/dist/src/compile.cjs +59 -0
- package/dist/src/compile.d.ts.map +1 -0
- package/dist/src/compile.js +36 -0
- package/dist/src/conf.cjs +53 -0
- package/dist/src/conf.d.ts.map +1 -0
- package/dist/src/conf.js +27 -0
- package/dist/src/constants.cjs +40 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/constants.js +14 -0
- package/dist/src/domain.cjs +63 -0
- package/dist/src/domain.d.ts.map +1 -0
- package/dist/src/domain.js +40 -0
- package/dist/src/exceptions.cjs +48 -0
- package/dist/{cjs/types → src}/exceptions.d.ts +0 -3
- package/dist/src/exceptions.d.ts.map +1 -0
- package/dist/src/exceptions.js +24 -0
- package/dist/src/index.cjs +6509 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +6445 -0
- package/dist/src/middleware.cjs +58 -0
- package/dist/src/middleware.d.ts.map +1 -0
- package/dist/src/middleware.js +35 -0
- package/dist/src/model.cjs +5992 -0
- package/dist/src/model.d.ts.map +1 -0
- package/dist/src/model.js +5967 -0
- package/dist/src/parsers/convert-from-number.cjs +34 -0
- package/dist/src/parsers/convert-from-number.d.ts.map +1 -0
- package/dist/src/parsers/convert-from-number.js +11 -0
- package/dist/src/parsers/convert-from-string.cjs +40 -0
- package/dist/src/parsers/convert-from-string.d.ts.map +1 -0
- package/dist/src/parsers/convert-from-string.js +17 -0
- package/dist/src/parsers/index.cjs +50 -0
- package/dist/src/parsers/index.d.ts.map +1 -0
- package/dist/src/parsers/index.js +24 -0
- package/dist/src/schema/array.cjs +1863 -0
- package/dist/src/schema/array.d.ts.map +1 -0
- package/dist/src/schema/array.js +1837 -0
- package/dist/src/schema/boolean.cjs +1800 -0
- package/dist/src/schema/boolean.d.ts.map +1 -0
- package/dist/src/schema/boolean.js +1774 -0
- package/dist/src/schema/datetime.cjs +1789 -0
- package/dist/src/schema/datetime.d.ts.map +1 -0
- package/dist/src/schema/datetime.js +1763 -0
- package/dist/src/schema/index.cjs +2026 -0
- package/dist/src/schema/index.d.ts.map +1 -0
- package/dist/src/schema/index.js +2001 -0
- package/dist/src/schema/number.cjs +2026 -0
- package/dist/src/schema/number.d.ts.map +1 -0
- package/dist/src/schema/number.js +2000 -0
- package/dist/src/schema/object.cjs +1795 -0
- package/dist/src/schema/object.d.ts.map +1 -0
- package/dist/src/schema/object.js +1769 -0
- package/dist/src/schema/schema.cjs +844 -0
- package/dist/src/schema/schema.d.ts.map +1 -0
- package/dist/src/schema/schema.js +818 -0
- package/dist/src/schema/string.cjs +2126 -0
- package/dist/src/schema/string.d.ts.map +1 -0
- package/dist/src/schema/string.js +2100 -0
- package/dist/src/schema/types.cjs +18 -0
- package/dist/src/schema/types.d.ts.map +1 -0
- package/dist/src/schema/types.js +0 -0
- package/dist/src/schema/union.cjs +1737 -0
- package/dist/src/schema/union.d.ts.map +1 -0
- package/dist/src/schema/union.js +1711 -0
- package/dist/src/types.cjs +18 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +0 -0
- package/dist/src/utils.cjs +477 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/utils.js +445 -0
- package/dist/src/validators/array.cjs +176 -0
- package/dist/src/validators/array.d.ts.map +1 -0
- package/dist/src/validators/array.js +150 -0
- package/dist/src/validators/boolean.cjs +71 -0
- package/dist/src/validators/boolean.d.ts.map +1 -0
- package/dist/src/validators/boolean.js +47 -0
- package/dist/src/validators/datetime.cjs +129 -0
- package/dist/src/validators/datetime.d.ts.map +1 -0
- package/dist/src/validators/datetime.js +103 -0
- package/dist/src/validators/number.cjs +194 -0
- package/dist/src/validators/number.d.ts.map +1 -0
- package/dist/src/validators/number.js +166 -0
- package/dist/src/validators/object.cjs +69 -0
- package/dist/src/validators/object.d.ts.map +1 -0
- package/dist/src/validators/object.js +46 -0
- package/dist/src/validators/schema.cjs +158 -0
- package/dist/src/validators/schema.d.ts.map +1 -0
- package/dist/src/validators/schema.js +132 -0
- package/dist/src/validators/string.cjs +255 -0
- package/dist/src/validators/string.d.ts.map +1 -0
- package/dist/src/validators/string.js +224 -0
- package/dist/src/validators/types.cjs +18 -0
- package/dist/src/validators/types.d.ts.map +1 -0
- package/dist/src/validators/types.js +0 -0
- package/dist/src/validators/union.cjs +69 -0
- package/dist/src/validators/union.d.ts.map +1 -0
- package/dist/src/validators/union.js +46 -0
- package/dist/src/validators/utils.cjs +165 -0
- package/dist/src/validators/utils.d.ts.map +1 -0
- package/dist/src/validators/utils.js +142 -0
- package/dist/tsconfig.types.tsbuildinfo +1 -0
- package/package.json +15 -23
- package/dist/cjs/src/adapter/fields/array.js +0 -152
- package/dist/cjs/src/adapter/fields/boolean.js +0 -162
- package/dist/cjs/src/adapter/fields/datetime.js +0 -162
- package/dist/cjs/src/adapter/fields/index.js +0 -311
- package/dist/cjs/src/adapter/fields/number.js +0 -162
- package/dist/cjs/src/adapter/fields/object.js +0 -171
- package/dist/cjs/src/adapter/fields/string.js +0 -162
- package/dist/cjs/src/adapter/fields/union.js +0 -162
- package/dist/cjs/src/adapter/index.js +0 -201
- package/dist/cjs/src/adapter/types.js +0 -4
- package/dist/cjs/src/compile.js +0 -262
- package/dist/cjs/src/conf.js +0 -26
- package/dist/cjs/src/constants.js +0 -36
- package/dist/cjs/src/domain.js +0 -156
- package/dist/cjs/src/exceptions.js +0 -168
- package/dist/cjs/src/index.js +0 -317
- package/dist/cjs/src/middleware.js +0 -213
- package/dist/cjs/src/model.js +0 -628
- package/dist/cjs/src/parsers/convert-from-number.js +0 -15
- package/dist/cjs/src/parsers/convert-from-string.js +0 -19
- package/dist/cjs/src/parsers/index.js +0 -20
- package/dist/cjs/src/schema/array.js +0 -1014
- package/dist/cjs/src/schema/boolean.js +0 -883
- package/dist/cjs/src/schema/datetime.js +0 -840
- package/dist/cjs/src/schema/index.js +0 -12
- package/dist/cjs/src/schema/number.js +0 -976
- package/dist/cjs/src/schema/object.js +0 -1052
- package/dist/cjs/src/schema/schema.js +0 -1840
- package/dist/cjs/src/schema/string.js +0 -1038
- package/dist/cjs/src/schema/types.js +0 -4
- package/dist/cjs/src/schema/union.js +0 -1070
- package/dist/cjs/src/types.js +0 -4
- package/dist/cjs/src/utils.js +0 -647
- package/dist/cjs/src/validators/array.js +0 -462
- package/dist/cjs/src/validators/boolean.js +0 -201
- package/dist/cjs/src/validators/datetime.js +0 -291
- package/dist/cjs/src/validators/number.js +0 -375
- package/dist/cjs/src/validators/object.js +0 -291
- package/dist/cjs/src/validators/schema.js +0 -322
- package/dist/cjs/src/validators/string.js +0 -467
- package/dist/cjs/src/validators/types.js +0 -4
- package/dist/cjs/src/validators/union.js +0 -233
- package/dist/cjs/src/validators/utils.js +0 -499
- package/dist/cjs/tsconfig.types.tsbuildinfo +0 -1
- package/dist/cjs/types/adapter/fields/array.d.ts.map +0 -1
- package/dist/cjs/types/adapter/fields/boolean.d.ts.map +0 -1
- package/dist/cjs/types/adapter/fields/datetime.d.ts.map +0 -1
- package/dist/cjs/types/adapter/fields/index.d.ts.map +0 -1
- package/dist/cjs/types/adapter/fields/number.d.ts.map +0 -1
- package/dist/cjs/types/adapter/fields/object.d.ts.map +0 -1
- package/dist/cjs/types/adapter/fields/string.d.ts.map +0 -1
- package/dist/cjs/types/adapter/fields/union.d.ts.map +0 -1
- package/dist/cjs/types/adapter/index.d.ts.map +0 -1
- package/dist/cjs/types/adapter/types.d.ts.map +0 -1
- package/dist/cjs/types/compile.d.ts.map +0 -1
- package/dist/cjs/types/conf.d.ts.map +0 -1
- package/dist/cjs/types/constants.d.ts.map +0 -1
- package/dist/cjs/types/domain.d.ts.map +0 -1
- package/dist/cjs/types/exceptions.d.ts.map +0 -1
- package/dist/cjs/types/index.d.ts.map +0 -1
- package/dist/cjs/types/middleware.d.ts.map +0 -1
- package/dist/cjs/types/model.d.ts.map +0 -1
- package/dist/cjs/types/parsers/convert-from-number.d.ts.map +0 -1
- package/dist/cjs/types/parsers/convert-from-string.d.ts.map +0 -1
- package/dist/cjs/types/parsers/index.d.ts.map +0 -1
- package/dist/cjs/types/schema/array.d.ts.map +0 -1
- package/dist/cjs/types/schema/boolean.d.ts.map +0 -1
- package/dist/cjs/types/schema/datetime.d.ts.map +0 -1
- package/dist/cjs/types/schema/index.d.ts.map +0 -1
- package/dist/cjs/types/schema/number.d.ts.map +0 -1
- package/dist/cjs/types/schema/object.d.ts.map +0 -1
- package/dist/cjs/types/schema/schema.d.ts.map +0 -1
- package/dist/cjs/types/schema/string.d.ts.map +0 -1
- package/dist/cjs/types/schema/types.d.ts.map +0 -1
- package/dist/cjs/types/schema/union.d.ts.map +0 -1
- package/dist/cjs/types/types.d.ts.map +0 -1
- package/dist/cjs/types/utils.d.ts.map +0 -1
- package/dist/cjs/types/validators/array.d.ts.map +0 -1
- package/dist/cjs/types/validators/boolean.d.ts.map +0 -1
- package/dist/cjs/types/validators/datetime.d.ts.map +0 -1
- package/dist/cjs/types/validators/number.d.ts.map +0 -1
- package/dist/cjs/types/validators/object.d.ts.map +0 -1
- package/dist/cjs/types/validators/schema.d.ts.map +0 -1
- package/dist/cjs/types/validators/string.d.ts.map +0 -1
- package/dist/cjs/types/validators/types.d.ts.map +0 -1
- package/dist/cjs/types/validators/union.d.ts.map +0 -1
- package/dist/cjs/types/validators/utils.d.ts.map +0 -1
- package/dist/esm/src/adapter/fields/array.js +0 -13
- package/dist/esm/src/adapter/fields/boolean.js +0 -20
- package/dist/esm/src/adapter/fields/datetime.js +0 -20
- package/dist/esm/src/adapter/fields/index.js +0 -37
- package/dist/esm/src/adapter/fields/number.js +0 -20
- package/dist/esm/src/adapter/fields/object.js +0 -26
- package/dist/esm/src/adapter/fields/string.js +0 -20
- package/dist/esm/src/adapter/fields/union.js +0 -20
- package/dist/esm/src/adapter/index.js +0 -21
- package/dist/esm/src/adapter/types.js +0 -1
- package/dist/esm/src/compile.js +0 -10
- package/dist/esm/src/conf.js +0 -18
- package/dist/esm/src/constants.js +0 -4
- package/dist/esm/src/domain.js +0 -11
- package/dist/esm/src/exceptions.js +0 -15
- package/dist/esm/src/index.js +0 -126
- package/dist/esm/src/middleware.js +0 -29
- package/dist/esm/src/model.js +0 -264
- package/dist/esm/src/parsers/convert-from-number.js +0 -8
- package/dist/esm/src/parsers/convert-from-string.js +0 -14
- package/dist/esm/src/parsers/index.js +0 -2
- package/dist/esm/src/schema/array.js +0 -487
- package/dist/esm/src/schema/boolean.js +0 -520
- package/dist/esm/src/schema/datetime.js +0 -477
- package/dist/esm/src/schema/index.js +0 -3
- package/dist/esm/src/schema/number.js +0 -610
- package/dist/esm/src/schema/object.js +0 -521
- package/dist/esm/src/schema/schema.js +0 -767
- package/dist/esm/src/schema/string.js +0 -668
- package/dist/esm/src/schema/types.js +0 -1
- package/dist/esm/src/schema/union.js +0 -468
- package/dist/esm/src/types.js +0 -14
- package/dist/esm/src/utils.js +0 -207
- package/dist/esm/src/validators/array.js +0 -140
- package/dist/esm/src/validators/boolean.js +0 -37
- package/dist/esm/src/validators/datetime.js +0 -89
- package/dist/esm/src/validators/number.js +0 -148
- package/dist/esm/src/validators/object.js +0 -39
- package/dist/esm/src/validators/schema.js +0 -118
- package/dist/esm/src/validators/string.js +0 -202
- package/dist/esm/src/validators/types.js +0 -1
- package/dist/esm/src/validators/union.js +0 -39
- package/dist/esm/src/validators/utils.js +0 -147
- /package/dist/{cjs/types → src}/adapter/fields/array.d.ts +0 -0
- /package/dist/{cjs/types → src}/adapter/fields/boolean.d.ts +0 -0
- /package/dist/{cjs/types → src}/adapter/fields/datetime.d.ts +0 -0
- /package/dist/{cjs/types → src}/adapter/fields/index.d.ts +0 -0
- /package/dist/{cjs/types → src}/adapter/fields/number.d.ts +0 -0
- /package/dist/{cjs/types → src}/adapter/fields/object.d.ts +0 -0
- /package/dist/{cjs/types → src}/adapter/fields/string.d.ts +0 -0
- /package/dist/{cjs/types → src}/adapter/fields/union.d.ts +0 -0
- /package/dist/{cjs/types → src}/adapter/index.d.ts +0 -0
- /package/dist/{cjs/types → src}/adapter/types.d.ts +0 -0
- /package/dist/{cjs/types → src}/compile.d.ts +0 -0
- /package/dist/{cjs/types → src}/conf.d.ts +0 -0
- /package/dist/{cjs/types → src}/constants.d.ts +0 -0
- /package/dist/{cjs/types → src}/domain.d.ts +0 -0
- /package/dist/{cjs/types → src}/index.d.ts +0 -0
- /package/dist/{cjs/types → src}/middleware.d.ts +0 -0
- /package/dist/{cjs/types → src}/model.d.ts +0 -0
- /package/dist/{cjs/types → src}/parsers/convert-from-number.d.ts +0 -0
- /package/dist/{cjs/types → src}/parsers/convert-from-string.d.ts +0 -0
- /package/dist/{cjs/types → src}/parsers/index.d.ts +0 -0
- /package/dist/{cjs/types → src}/schema/array.d.ts +0 -0
- /package/dist/{cjs/types → src}/schema/boolean.d.ts +0 -0
- /package/dist/{cjs/types → src}/schema/datetime.d.ts +0 -0
- /package/dist/{cjs/types → src}/schema/index.d.ts +0 -0
- /package/dist/{cjs/types → src}/schema/number.d.ts +0 -0
- /package/dist/{cjs/types → src}/schema/object.d.ts +0 -0
- /package/dist/{cjs/types → src}/schema/schema.d.ts +0 -0
- /package/dist/{cjs/types → src}/schema/string.d.ts +0 -0
- /package/dist/{cjs/types → src}/schema/types.d.ts +0 -0
- /package/dist/{cjs/types → src}/schema/union.d.ts +0 -0
- /package/dist/{cjs/types → src}/types.d.ts +0 -0
- /package/dist/{cjs/types → src}/utils.d.ts +0 -0
- /package/dist/{cjs/types → src}/validators/array.d.ts +0 -0
- /package/dist/{cjs/types → src}/validators/boolean.d.ts +0 -0
- /package/dist/{cjs/types → src}/validators/datetime.d.ts +0 -0
- /package/dist/{cjs/types → src}/validators/number.d.ts +0 -0
- /package/dist/{cjs/types → src}/validators/object.d.ts +0 -0
- /package/dist/{cjs/types → src}/validators/schema.d.ts +0 -0
- /package/dist/{cjs/types → src}/validators/string.d.ts +0 -0
- /package/dist/{cjs/types → src}/validators/types.d.ts +0 -0
- /package/dist/{cjs/types → src}/validators/union.d.ts +0 -0
- /package/dist/{cjs/types → src}/validators/utils.d.ts +0 -0
@@ -1,1038 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
3
|
-
value: true
|
4
|
-
});
|
5
|
-
function _export(target, all) {
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
7
|
-
enumerable: true,
|
8
|
-
get: all[name]
|
9
|
-
});
|
10
|
-
}
|
11
|
-
_export(exports, {
|
12
|
-
StringSchema: function() {
|
13
|
-
return StringSchema;
|
14
|
-
},
|
15
|
-
string: function() {
|
16
|
-
return string;
|
17
|
-
}
|
18
|
-
});
|
19
|
-
var _schema = require("./schema");
|
20
|
-
var _utils = require("../utils");
|
21
|
-
var _schema1 = require("../validators/schema");
|
22
|
-
var _string = require("../validators/string");
|
23
|
-
function _assert_this_initialized(self) {
|
24
|
-
if (self === void 0) {
|
25
|
-
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
26
|
-
}
|
27
|
-
return self;
|
28
|
-
}
|
29
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
30
|
-
try {
|
31
|
-
var info = gen[key](arg);
|
32
|
-
var value = info.value;
|
33
|
-
} catch (error) {
|
34
|
-
reject(error);
|
35
|
-
return;
|
36
|
-
}
|
37
|
-
if (info.done) {
|
38
|
-
resolve(value);
|
39
|
-
} else {
|
40
|
-
Promise.resolve(value).then(_next, _throw);
|
41
|
-
}
|
42
|
-
}
|
43
|
-
function _async_to_generator(fn) {
|
44
|
-
return function() {
|
45
|
-
var self = this, args = arguments;
|
46
|
-
return new Promise(function(resolve, reject) {
|
47
|
-
var gen = fn.apply(self, args);
|
48
|
-
function _next(value) {
|
49
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
50
|
-
}
|
51
|
-
function _throw(err) {
|
52
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
53
|
-
}
|
54
|
-
_next(undefined);
|
55
|
-
});
|
56
|
-
};
|
57
|
-
}
|
58
|
-
function _class_call_check(instance, Constructor) {
|
59
|
-
if (!(instance instanceof Constructor)) {
|
60
|
-
throw new TypeError("Cannot call a class as a function");
|
61
|
-
}
|
62
|
-
}
|
63
|
-
function _defineProperties(target, props) {
|
64
|
-
for(var i = 0; i < props.length; i++){
|
65
|
-
var descriptor = props[i];
|
66
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
67
|
-
descriptor.configurable = true;
|
68
|
-
if ("value" in descriptor) descriptor.writable = true;
|
69
|
-
Object.defineProperty(target, descriptor.key, descriptor);
|
70
|
-
}
|
71
|
-
}
|
72
|
-
function _create_class(Constructor, protoProps, staticProps) {
|
73
|
-
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
74
|
-
if (staticProps) _defineProperties(Constructor, staticProps);
|
75
|
-
return Constructor;
|
76
|
-
}
|
77
|
-
function _define_property(obj, key, value) {
|
78
|
-
if (key in obj) {
|
79
|
-
Object.defineProperty(obj, key, {
|
80
|
-
value: value,
|
81
|
-
enumerable: true,
|
82
|
-
configurable: true,
|
83
|
-
writable: true
|
84
|
-
});
|
85
|
-
} else {
|
86
|
-
obj[key] = value;
|
87
|
-
}
|
88
|
-
return obj;
|
89
|
-
}
|
90
|
-
function _get(target, property, receiver) {
|
91
|
-
if (typeof Reflect !== "undefined" && Reflect.get) {
|
92
|
-
_get = Reflect.get;
|
93
|
-
} else {
|
94
|
-
_get = function get(target, property, receiver) {
|
95
|
-
var base = _super_prop_base(target, property);
|
96
|
-
if (!base) return;
|
97
|
-
var desc = Object.getOwnPropertyDescriptor(base, property);
|
98
|
-
if (desc.get) {
|
99
|
-
return desc.get.call(receiver || target);
|
100
|
-
}
|
101
|
-
return desc.value;
|
102
|
-
};
|
103
|
-
}
|
104
|
-
return _get(target, property, receiver || target);
|
105
|
-
}
|
106
|
-
function _get_prototype_of(o) {
|
107
|
-
_get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
|
108
|
-
return o.__proto__ || Object.getPrototypeOf(o);
|
109
|
-
};
|
110
|
-
return _get_prototype_of(o);
|
111
|
-
}
|
112
|
-
function _inherits(subClass, superClass) {
|
113
|
-
if (typeof superClass !== "function" && superClass !== null) {
|
114
|
-
throw new TypeError("Super expression must either be null or a function");
|
115
|
-
}
|
116
|
-
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
117
|
-
constructor: {
|
118
|
-
value: subClass,
|
119
|
-
writable: true,
|
120
|
-
configurable: true
|
121
|
-
}
|
122
|
-
});
|
123
|
-
if (superClass) _set_prototype_of(subClass, superClass);
|
124
|
-
}
|
125
|
-
function _possible_constructor_return(self, call) {
|
126
|
-
if (call && (_type_of(call) === "object" || typeof call === "function")) {
|
127
|
-
return call;
|
128
|
-
}
|
129
|
-
return _assert_this_initialized(self);
|
130
|
-
}
|
131
|
-
function _set_prototype_of(o, p) {
|
132
|
-
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
133
|
-
o.__proto__ = p;
|
134
|
-
return o;
|
135
|
-
};
|
136
|
-
return _set_prototype_of(o, p);
|
137
|
-
}
|
138
|
-
function _super_prop_base(object, property) {
|
139
|
-
while(!Object.prototype.hasOwnProperty.call(object, property)){
|
140
|
-
object = _get_prototype_of(object);
|
141
|
-
if (object === null) break;
|
142
|
-
}
|
143
|
-
return object;
|
144
|
-
}
|
145
|
-
function _type_of(obj) {
|
146
|
-
"@swc/helpers - typeof";
|
147
|
-
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
148
|
-
}
|
149
|
-
function _is_native_reflect_construct() {
|
150
|
-
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
151
|
-
if (Reflect.construct.sham) return false;
|
152
|
-
if (typeof Proxy === "function") return true;
|
153
|
-
try {
|
154
|
-
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
155
|
-
return true;
|
156
|
-
} catch (e) {
|
157
|
-
return false;
|
158
|
-
}
|
159
|
-
}
|
160
|
-
function _create_super(Derived) {
|
161
|
-
var hasNativeReflectConstruct = _is_native_reflect_construct();
|
162
|
-
return function _createSuperInternal() {
|
163
|
-
var Super = _get_prototype_of(Derived), result;
|
164
|
-
if (hasNativeReflectConstruct) {
|
165
|
-
var NewTarget = _get_prototype_of(this).constructor;
|
166
|
-
result = Reflect.construct(Super, arguments, NewTarget);
|
167
|
-
} else {
|
168
|
-
result = Super.apply(this, arguments);
|
169
|
-
}
|
170
|
-
return _possible_constructor_return(this, result);
|
171
|
-
};
|
172
|
-
}
|
173
|
-
function _ts_generator(thisArg, body) {
|
174
|
-
var f, y, t, g, _ = {
|
175
|
-
label: 0,
|
176
|
-
sent: function() {
|
177
|
-
if (t[0] & 1) throw t[1];
|
178
|
-
return t[1];
|
179
|
-
},
|
180
|
-
trys: [],
|
181
|
-
ops: []
|
182
|
-
};
|
183
|
-
return g = {
|
184
|
-
next: verb(0),
|
185
|
-
"throw": verb(1),
|
186
|
-
"return": verb(2)
|
187
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
188
|
-
return this;
|
189
|
-
}), g;
|
190
|
-
function verb(n) {
|
191
|
-
return function(v) {
|
192
|
-
return step([
|
193
|
-
n,
|
194
|
-
v
|
195
|
-
]);
|
196
|
-
};
|
197
|
-
}
|
198
|
-
function step(op) {
|
199
|
-
if (f) throw new TypeError("Generator is already executing.");
|
200
|
-
while(_)try {
|
201
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
202
|
-
if (y = 0, t) op = [
|
203
|
-
op[0] & 2,
|
204
|
-
t.value
|
205
|
-
];
|
206
|
-
switch(op[0]){
|
207
|
-
case 0:
|
208
|
-
case 1:
|
209
|
-
t = op;
|
210
|
-
break;
|
211
|
-
case 4:
|
212
|
-
_.label++;
|
213
|
-
return {
|
214
|
-
value: op[1],
|
215
|
-
done: false
|
216
|
-
};
|
217
|
-
case 5:
|
218
|
-
_.label++;
|
219
|
-
y = op[1];
|
220
|
-
op = [
|
221
|
-
0
|
222
|
-
];
|
223
|
-
continue;
|
224
|
-
case 7:
|
225
|
-
op = _.ops.pop();
|
226
|
-
_.trys.pop();
|
227
|
-
continue;
|
228
|
-
default:
|
229
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
230
|
-
_ = 0;
|
231
|
-
continue;
|
232
|
-
}
|
233
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
234
|
-
_.label = op[1];
|
235
|
-
break;
|
236
|
-
}
|
237
|
-
if (op[0] === 6 && _.label < t[1]) {
|
238
|
-
_.label = t[1];
|
239
|
-
t = op;
|
240
|
-
break;
|
241
|
-
}
|
242
|
-
if (t && _.label < t[2]) {
|
243
|
-
_.label = t[2];
|
244
|
-
_.ops.push(op);
|
245
|
-
break;
|
246
|
-
}
|
247
|
-
if (t[2]) _.ops.pop();
|
248
|
-
_.trys.pop();
|
249
|
-
continue;
|
250
|
-
}
|
251
|
-
op = body.call(thisArg, _);
|
252
|
-
} catch (e) {
|
253
|
-
op = [
|
254
|
-
6,
|
255
|
-
e
|
256
|
-
];
|
257
|
-
y = 0;
|
258
|
-
} finally{
|
259
|
-
f = t = 0;
|
260
|
-
}
|
261
|
-
if (op[0] & 5) throw op[1];
|
262
|
-
return {
|
263
|
-
value: op[0] ? op[1] : void 0,
|
264
|
-
done: true
|
265
|
-
};
|
266
|
-
}
|
267
|
-
}
|
268
|
-
var StringSchema = /*#__PURE__*/ function(Schema) {
|
269
|
-
"use strict";
|
270
|
-
_inherits(StringSchema, Schema);
|
271
|
-
var _super = _create_super(StringSchema);
|
272
|
-
function StringSchema() {
|
273
|
-
_class_call_check(this, StringSchema);
|
274
|
-
var _this;
|
275
|
-
_this = _super.apply(this, arguments);
|
276
|
-
_define_property(_assert_this_initialized(_this), "fieldType", 'string');
|
277
|
-
_define_property(_assert_this_initialized(_this), "__is", void 0);
|
278
|
-
_define_property(_assert_this_initialized(_this), "__email", void 0);
|
279
|
-
_define_property(_assert_this_initialized(_this), "__uuid", void 0);
|
280
|
-
_define_property(_assert_this_initialized(_this), "__minLength", void 0);
|
281
|
-
_define_property(_assert_this_initialized(_this), "__maxLength", void 0);
|
282
|
-
_define_property(_assert_this_initialized(_this), "__regex", void 0);
|
283
|
-
_define_property(_assert_this_initialized(_this), "__endsWith", void 0);
|
284
|
-
_define_property(_assert_this_initialized(_this), "__startsWith", void 0);
|
285
|
-
_define_property(_assert_this_initialized(_this), "__includes", void 0);
|
286
|
-
_define_property(_assert_this_initialized(_this), "__type", {
|
287
|
-
message: 'Invalid type',
|
288
|
-
check: function(value) {
|
289
|
-
return typeof value === 'string';
|
290
|
-
}
|
291
|
-
});
|
292
|
-
return _this;
|
293
|
-
}
|
294
|
-
_create_class(StringSchema, [
|
295
|
-
{
|
296
|
-
key: "__transformToAdapter",
|
297
|
-
value: function __transformToAdapter(options) {
|
298
|
-
var _this = this;
|
299
|
-
return _async_to_generator(function() {
|
300
|
-
return _ts_generator(this, function(_state) {
|
301
|
-
return [
|
302
|
-
2,
|
303
|
-
(0, _utils.defaultTransformToAdapter)(function() {
|
304
|
-
var _ref = _async_to_generator(function(adapter) {
|
305
|
-
return _ts_generator(this, function(_state) {
|
306
|
-
return [
|
307
|
-
2,
|
308
|
-
(0, _utils.defaultTransform)('string', _this, adapter, adapter.string, function() {
|
309
|
-
return {
|
310
|
-
type: _this.__type,
|
311
|
-
is: _this.__is,
|
312
|
-
email: _this.__email,
|
313
|
-
uuid: _this.__uuid,
|
314
|
-
minLength: _this.__minLength,
|
315
|
-
maxLength: _this.__maxLength,
|
316
|
-
regex: _this.__regex,
|
317
|
-
endsWith: _this.__endsWith,
|
318
|
-
startsWith: _this.__startsWith,
|
319
|
-
includes: _this.__includes,
|
320
|
-
nullable: _this.__nullable,
|
321
|
-
optional: _this.__optional,
|
322
|
-
parsers: {
|
323
|
-
nullable: _this.__nullable.allow,
|
324
|
-
optional: _this.__optional.allow
|
325
|
-
}
|
326
|
-
};
|
327
|
-
}, {
|
328
|
-
maxLength: _string.maxLength,
|
329
|
-
minLength: _string.minLength,
|
330
|
-
endsWith: _string.endsWith,
|
331
|
-
startsWith: _string.startsWith,
|
332
|
-
email: _string.email,
|
333
|
-
uuid: _string.uuid,
|
334
|
-
is: _schema1.is,
|
335
|
-
regex: _string.regex,
|
336
|
-
includes: _string.includes,
|
337
|
-
nullable: _schema1.nullable,
|
338
|
-
optional: _schema1.optional
|
339
|
-
}, {
|
340
|
-
validatorsIfFallbackOrNotSupported: (0, _string.stringValidation)(),
|
341
|
-
shouldAddStringVersion: options.shouldAddStringVersion,
|
342
|
-
// eslint-disable-next-line ts/require-await
|
343
|
-
fallbackIfNotSupported: /*#__PURE__*/ _async_to_generator(function() {
|
344
|
-
return _ts_generator(this, function(_state) {
|
345
|
-
return [
|
346
|
-
2,
|
347
|
-
[]
|
348
|
-
];
|
349
|
-
});
|
350
|
-
})
|
351
|
-
})
|
352
|
-
];
|
353
|
-
});
|
354
|
-
});
|
355
|
-
return function(adapter) {
|
356
|
-
return _ref.apply(this, arguments);
|
357
|
-
};
|
358
|
-
}(), _this, _this.__transformedSchemas, options, 'number')
|
359
|
-
];
|
360
|
-
});
|
361
|
-
})();
|
362
|
-
}
|
363
|
-
},
|
364
|
-
{
|
365
|
-
/**
|
366
|
-
* This let's you refine the schema with custom validations. This is useful when you want to validate something that
|
367
|
-
* is not supported by default by the schema adapter.
|
368
|
-
*
|
369
|
-
* @example
|
370
|
-
* ```typescript
|
371
|
-
* import * as p from '@palmares/schemas';
|
372
|
-
*
|
373
|
-
* const numberSchema = p.number().refine((value) => {
|
374
|
-
* if (value < 0) return { code: 'invalid_number', message: 'The number should be greater than 0' };
|
375
|
-
* });
|
376
|
-
*
|
377
|
-
* const { errors, parsed } = await numberSchema.parse(-1);
|
378
|
-
*
|
379
|
-
* // [{ isValid: false, code: 'invalid_number', message: 'The number should be greater than 0', path: [] }]
|
380
|
-
* console.log(errors);
|
381
|
-
* ```
|
382
|
-
*
|
383
|
-
* @param refinementCallback - The callback that will be called to validate the value.
|
384
|
-
* @param options - Options for the refinement.
|
385
|
-
* @param options.isAsync - Whether the callback is async or not. Defaults to true.
|
386
|
-
*/ key: "refine",
|
387
|
-
value: function refine(refinementCallback) {
|
388
|
-
return _get(_get_prototype_of(StringSchema.prototype), "refine", this).call(this, refinementCallback);
|
389
|
-
}
|
390
|
-
},
|
391
|
-
{
|
392
|
-
/**
|
393
|
-
* Allows the value to be either undefined or null.
|
394
|
-
*
|
395
|
-
* @example
|
396
|
-
* ```typescript
|
397
|
-
* import * as p from '@palmares/schemas';
|
398
|
-
*
|
399
|
-
* const numberSchema = p.number().optional();
|
400
|
-
*
|
401
|
-
* const { errors, parsed } = await numberSchema.parse(undefined);
|
402
|
-
*
|
403
|
-
* console.log(parsed); // undefined
|
404
|
-
*
|
405
|
-
* const { errors, parsed } = await numberSchema.parse(null);
|
406
|
-
*
|
407
|
-
* console.log(parsed); // null
|
408
|
-
*
|
409
|
-
* const { errors, parsed } = await numberSchema.parse(1);
|
410
|
-
*
|
411
|
-
* console.log(parsed); // 1
|
412
|
-
* ```
|
413
|
-
*
|
414
|
-
* @returns - The schema we are working with.
|
415
|
-
*/ key: "optional",
|
416
|
-
value: function optional() {
|
417
|
-
return _get(_get_prototype_of(StringSchema.prototype), "optional", this).call(this);
|
418
|
-
}
|
419
|
-
},
|
420
|
-
{
|
421
|
-
/**
|
422
|
-
* Just adds a message when the value is undefined. It's just a syntax sugar for
|
423
|
-
*
|
424
|
-
* ```typescript
|
425
|
-
* p.string().optional({ message: 'This value cannot be null', allow: false })
|
426
|
-
* ```
|
427
|
-
*
|
428
|
-
* @param options - The options of nonOptional function
|
429
|
-
* @param options.message - A custom message if the value is undefined.
|
430
|
-
*
|
431
|
-
* @returns - The schema.
|
432
|
-
*/ key: "nonOptional",
|
433
|
-
value: function nonOptional(options) {
|
434
|
-
return _get(_get_prototype_of(StringSchema.prototype), "optional", this).call(this, {
|
435
|
-
message: options === null || options === void 0 ? void 0 : options.message,
|
436
|
-
allow: false
|
437
|
-
});
|
438
|
-
}
|
439
|
-
},
|
440
|
-
{
|
441
|
-
/**
|
442
|
-
* Allows the value to be null and ONLY null. You can also use this function to set a custom message when the value
|
443
|
-
* is NULL by setting the { message: 'Your custom message', allow: false } on the options.
|
444
|
-
*
|
445
|
-
* @example
|
446
|
-
* ```typescript
|
447
|
-
* import * as p from '@palmares/schemas';
|
448
|
-
*
|
449
|
-
* const numberSchema = p.number().nullable();
|
450
|
-
*
|
451
|
-
* const { errors, parsed } = await numberSchema.parse(null);
|
452
|
-
*
|
453
|
-
* console.log(parsed); // null
|
454
|
-
*
|
455
|
-
* const { errors, parsed } = await numberSchema.parse(undefined);
|
456
|
-
*
|
457
|
-
* console.log(errors); // [{ isValid: false, code: 'invalid_type', message: 'Invalid type', path: [] }]
|
458
|
-
* ```
|
459
|
-
*
|
460
|
-
* @param options - The options for the nullable function.
|
461
|
-
* @param options.message - The message to be shown when the value is not null. Defaults to 'Cannot be null'.
|
462
|
-
* @param options.allow - Whether the value can be null or not. Defaults to true.
|
463
|
-
*
|
464
|
-
* @returns The schema.
|
465
|
-
*/ key: "nullable",
|
466
|
-
value: function nullable(options) {
|
467
|
-
return _get(_get_prototype_of(StringSchema.prototype), "nullable", this).call(this, options);
|
468
|
-
}
|
469
|
-
},
|
470
|
-
{
|
471
|
-
/**
|
472
|
-
* Just adds a message when the value is null. It's just a syntax sugar for
|
473
|
-
*
|
474
|
-
* ```typescript
|
475
|
-
* p.string().nullable({ message: 'This value cannot be null', allow: false })
|
476
|
-
* ```
|
477
|
-
*
|
478
|
-
* @param options - The options of nonNullable function
|
479
|
-
* @param options.message - A custom message if the value is null.
|
480
|
-
*
|
481
|
-
* @returns - The schema.
|
482
|
-
*/ key: "nonNullable",
|
483
|
-
value: function nonNullable(options) {
|
484
|
-
return _get(_get_prototype_of(StringSchema.prototype), "nullable", this).call(this, {
|
485
|
-
message: (options === null || options === void 0 ? void 0 : options.message) || '',
|
486
|
-
allow: false
|
487
|
-
});
|
488
|
-
}
|
489
|
-
},
|
490
|
-
{
|
491
|
-
/**
|
492
|
-
* This method will remove the value from the representation of the schema. If the value is undefined it will keep
|
493
|
-
* that way otherwise it will set the value to undefined after it's validated.
|
494
|
-
* This is used in conjunction with the {@link data} function, the {@link parse} function or {@link validate}
|
495
|
-
* function. This will remove the value from the representation of the schema.
|
496
|
-
*
|
497
|
-
* By default, the value will be removed just from the representation, in other words, when you call the {@link data}
|
498
|
-
* function. But if you want to remove the value from the internal representation, you can pass the argument
|
499
|
-
* `toInternal` as true. Then if you still want to remove the value from the representation, you will need to pass
|
500
|
-
* the argument `toRepresentation` as true as well.
|
501
|
-
*
|
502
|
-
* @example
|
503
|
-
* ```typescript
|
504
|
-
* import * as p from '@palmares/schemas';
|
505
|
-
*
|
506
|
-
* const userSchema = p.object({
|
507
|
-
* id: p.number().optional(),
|
508
|
-
* name: p.string(),
|
509
|
-
* password: p.string().omit()
|
510
|
-
* });
|
511
|
-
*
|
512
|
-
* const user = await userSchema.data({
|
513
|
-
* id: 1,
|
514
|
-
* name: 'John Doe',
|
515
|
-
* password: '123456'
|
516
|
-
* });
|
517
|
-
*
|
518
|
-
* console.log(user); // { id: 1, name: 'John Doe' }
|
519
|
-
* ```
|
520
|
-
*
|
521
|
-
*
|
522
|
-
* @param args - By default, the value will be removed just from the representation, in other words, when you call
|
523
|
-
* the {@link data} function. But if you want to remove the value from the internal representation, you can pass the
|
524
|
-
* argument `toInternal` as true. Then if you still want to remove the value from the representation, you will need
|
525
|
-
* to pass the argument `toRepresentation` as true as well.
|
526
|
-
*
|
527
|
-
* @returns The schema.
|
528
|
-
*/ key: "omit",
|
529
|
-
value: function omit(args) {
|
530
|
-
return _get(_get_prototype_of(StringSchema.prototype), "omit", this).call(this, args);
|
531
|
-
}
|
532
|
-
},
|
533
|
-
{
|
534
|
-
/**
|
535
|
-
* This function is used in conjunction with the {@link validate} function. It's used to save a value to an external
|
536
|
-
* source like a database. You should always return the schema after you save the value, that way we will always have
|
537
|
-
* the correct type of the schema after the save operation.
|
538
|
-
*
|
539
|
-
* You can use the {@link toRepresentation} function to transform and clean the value it returns after the save.
|
540
|
-
*
|
541
|
-
* @example
|
542
|
-
* ```typescript
|
543
|
-
* import * as p from '@palmares/schemas';
|
544
|
-
*
|
545
|
-
* import { User } from './models';
|
546
|
-
*
|
547
|
-
* const userSchema = p.object({
|
548
|
-
* id: p.number().optional(),
|
549
|
-
* name: p.string(),
|
550
|
-
* email: p.string().email(),
|
551
|
-
* }).onSave(async (value) => {
|
552
|
-
* // Create or update the user on the database using palmares models or any other library of your choice.
|
553
|
-
* if (value.id)
|
554
|
-
* await User.default.set(value, { search: { id: value.id } });
|
555
|
-
* else
|
556
|
-
* await User.default.set(value);
|
557
|
-
*
|
558
|
-
* return value;
|
559
|
-
* });
|
560
|
-
*
|
561
|
-
*
|
562
|
-
* // Then, on your controller, do something like this:
|
563
|
-
* const { isValid, save, errors } = await userSchema.validate(req.body);
|
564
|
-
* if (isValid) {
|
565
|
-
* const savedValue = await save();
|
566
|
-
* return Response.json(savedValue, { status: 201 });
|
567
|
-
* }
|
568
|
-
*
|
569
|
-
* return Response.json({ errors }, { status: 400 });
|
570
|
-
* ```
|
571
|
-
*
|
572
|
-
* @param callback - The callback that will be called to save the value on an external source.
|
573
|
-
*
|
574
|
-
* @returns The schema.
|
575
|
-
*/ key: "onSave",
|
576
|
-
value: function onSave(callback) {
|
577
|
-
return _get(_get_prototype_of(StringSchema.prototype), "onSave", this).call(this, callback);
|
578
|
-
}
|
579
|
-
},
|
580
|
-
{
|
581
|
-
/**
|
582
|
-
* This function is used to add a default value to the schema. If the value is either undefined or null, the default
|
583
|
-
* value will be used.
|
584
|
-
*
|
585
|
-
* @example
|
586
|
-
* ```typescript
|
587
|
-
* import * as p from '@palmares/schemas';
|
588
|
-
*
|
589
|
-
* const numberSchema = p.number().default(0);
|
590
|
-
*
|
591
|
-
* const { errors, parsed } = await numberSchema.parse(undefined);
|
592
|
-
*
|
593
|
-
* console.log(parsed); // 0
|
594
|
-
* ```
|
595
|
-
*/ key: "default",
|
596
|
-
value: function _default(defaultValueOrFunction) {
|
597
|
-
return _get(_get_prototype_of(StringSchema.prototype), "default", this).call(this, defaultValueOrFunction);
|
598
|
-
}
|
599
|
-
},
|
600
|
-
{
|
601
|
-
/**
|
602
|
-
* This function let's you customize the schema your own way. After we translate the schema on the adapter we call
|
603
|
-
* this function to let you customize the custom schema your own way. Our API does not support passthrough?
|
604
|
-
* No problem, you can use this function to customize the zod schema.
|
605
|
-
*
|
606
|
-
* @example
|
607
|
-
* ```typescript
|
608
|
-
* import * as p from '@palmares/schemas';
|
609
|
-
*
|
610
|
-
* const numberSchema = p.number().extends((schema) => {
|
611
|
-
* return schema.nonnegative();
|
612
|
-
* });
|
613
|
-
*
|
614
|
-
* const { errors, parsed } = await numberSchema.parse(-1);
|
615
|
-
* // [{ isValid: false, code: 'nonnegative', message: 'The number should be nonnegative', path: [] }]
|
616
|
-
* console.log(errors);
|
617
|
-
* ```
|
618
|
-
*
|
619
|
-
* @param callback - The callback that will be called to customize the schema.
|
620
|
-
* @param toStringCallback - The callback that will be called to transform the schema to a string when you want to
|
621
|
-
* compile the underlying schema to a string so you can save it for future runs.
|
622
|
-
*
|
623
|
-
* @returns The schema.
|
624
|
-
*/ key: "extends",
|
625
|
-
value: function _extends(callback, toStringCallback) {
|
626
|
-
return _get(_get_prototype_of(StringSchema.prototype), "extends", this).call(this, callback, toStringCallback);
|
627
|
-
}
|
628
|
-
},
|
629
|
-
{
|
630
|
-
/**
|
631
|
-
* This function is used to transform the value to the representation of the schema. When using the {@link data}
|
632
|
-
* function. With this function you have full control to add data cleaning for example, transforming the data and
|
633
|
-
* whatever. Another use case is when you want to return deeply nested recursive data.
|
634
|
-
* The schema maps to itself.
|
635
|
-
*
|
636
|
-
* @example
|
637
|
-
* ```typescript
|
638
|
-
* import * as p from '@palmares/schemas';
|
639
|
-
*
|
640
|
-
* const recursiveSchema = p.object({
|
641
|
-
* id: p.number().optional(),
|
642
|
-
* name: p.string(),
|
643
|
-
* }).toRepresentation(async (value) => {
|
644
|
-
* return {
|
645
|
-
* id: value.id,
|
646
|
-
* name: value.name,
|
647
|
-
* children: await Promise.all(value.children.map(async (child) => await recursiveSchema.data(child)))
|
648
|
-
* }
|
649
|
-
* });
|
650
|
-
*
|
651
|
-
* const data = await recursiveSchema.data({
|
652
|
-
* id: 1,
|
653
|
-
* name: 'John Doe',
|
654
|
-
* });
|
655
|
-
* ```
|
656
|
-
*
|
657
|
-
* @example
|
658
|
-
* ```
|
659
|
-
* import * as p from '@palmares/schemas';
|
660
|
-
*
|
661
|
-
* const colorToRGBSchema = p.string().toRepresentation(async (value) => {
|
662
|
-
* switch (value) {
|
663
|
-
* case 'red': return { r: 255, g: 0, b: 0 };
|
664
|
-
* case 'green': return { r: 0, g: 255, b: 0 };
|
665
|
-
* case 'blue': return { r: 0, g: 0, b: 255 };
|
666
|
-
* default: return { r: 0, g: 0, b: 0 };
|
667
|
-
* }
|
668
|
-
* });
|
669
|
-
* ```
|
670
|
-
* @param toRepresentationCallback - The callback that will be called to transform the value to the representation.
|
671
|
-
*
|
672
|
-
* @returns The schema with a new return type
|
673
|
-
*/ key: "toRepresentation",
|
674
|
-
value: function toRepresentation(toRepresentationCallback) {
|
675
|
-
return _get(_get_prototype_of(StringSchema.prototype), "toRepresentation", this).call(this, toRepresentationCallback);
|
676
|
-
}
|
677
|
-
},
|
678
|
-
{
|
679
|
-
/**
|
680
|
-
* This function is used to transform the value to the internal representation of the schema. This is useful when
|
681
|
-
* you want to transform the value to a type that the schema adapter can understand. For example, you might want
|
682
|
-
* to transform a string to a date. This is the function you use.
|
683
|
-
*
|
684
|
-
* @example
|
685
|
-
* ```typescript
|
686
|
-
* import * as p from '@palmares/schemas';
|
687
|
-
*
|
688
|
-
* const dateSchema = p.string().toInternal((value) => {
|
689
|
-
* return new Date(value);
|
690
|
-
* });
|
691
|
-
*
|
692
|
-
* const date = await dateSchema.parse('2021-01-01');
|
693
|
-
*
|
694
|
-
* console.log(date); // Date object
|
695
|
-
*
|
696
|
-
* const rgbToColorSchema = p.object({
|
697
|
-
* r: p.number().min(0).max(255),
|
698
|
-
* g: p.number().min(0).max(255),
|
699
|
-
* b: p.number().min(0).max(255),
|
700
|
-
* }).toInternal(async (value) => {
|
701
|
-
* if (value.r === 255 && value.g === 0 && value.b === 0) return 'red';
|
702
|
-
* if (value.r === 0 && value.g === 255 && value.b === 0) return 'green';
|
703
|
-
* if (value.r === 0 && value.g === 0 && value.b === 255) return 'blue';
|
704
|
-
* return `rgb(${value.r}, ${value.g}, ${value.b})`;
|
705
|
-
* });
|
706
|
-
* ```
|
707
|
-
*
|
708
|
-
* @param toInternalCallback - The callback that will be called to transform the value to the internal representation.
|
709
|
-
*
|
710
|
-
* @returns The schema with a new return type.
|
711
|
-
*/ key: "toInternal",
|
712
|
-
value: function toInternal(toInternalCallback) {
|
713
|
-
return _get(_get_prototype_of(StringSchema.prototype), "toInternal", this).call(this, toInternalCallback);
|
714
|
-
}
|
715
|
-
},
|
716
|
-
{
|
717
|
-
/**
|
718
|
-
* Called before the validation of the schema. Let's say that you want to validate a date that might receive a string,
|
719
|
-
* you can convert that string to a date here BEFORE the validation. This pretty much transforms the value to a
|
720
|
-
* type that the schema adapter can understand.
|
721
|
-
*
|
722
|
-
* @example
|
723
|
-
* ```typescript
|
724
|
-
* import * as p from '@palmares/schemas';
|
725
|
-
* import * as z from 'zod';
|
726
|
-
*
|
727
|
-
* const customRecordToMapSchema = p.schema().appendSchema(z.map()).toValidate(async (value) => {
|
728
|
-
* return new Map(value); // Before validating we transform the value to a map.
|
729
|
-
* });
|
730
|
-
*
|
731
|
-
* const { errors, parsed } = await customRecordToMapSchema.parse({ key: 'value' });
|
732
|
-
* ```
|
733
|
-
*
|
734
|
-
* @param toValidateCallback - The callback that will be called to validate the value.
|
735
|
-
*
|
736
|
-
* @returns The schema with a new return type.
|
737
|
-
*/ key: "toValidate",
|
738
|
-
value: function toValidate(toValidateCallback) {
|
739
|
-
return _get(_get_prototype_of(StringSchema.prototype), "toValidate", this).call(this, toValidateCallback);
|
740
|
-
}
|
741
|
-
},
|
742
|
-
{
|
743
|
-
/**
|
744
|
-
* Defines a list of strings that are allowed, it's useful when you want to restrict the values that are allowed.
|
745
|
-
* Like a selector or a Choice field.
|
746
|
-
*
|
747
|
-
* @example
|
748
|
-
* ```typescript
|
749
|
-
* import * as p from '@palmares/schema';
|
750
|
-
*
|
751
|
-
* const schema = p.string().is(['Argentina', 'Brazil', 'Chile']);
|
752
|
-
*
|
753
|
-
* schema.parse('Argentina'); // { errors: [], parsed: 'Argentina' }
|
754
|
-
* // { errors: [{
|
755
|
-
* // code: 'invalid_value',
|
756
|
-
* // message: 'The value should be equal to Argentina, Brazil, Chile',
|
757
|
-
* // path: [] }], parsed: 'Uruguay' }
|
758
|
-
* schema.parse('Uruguay');
|
759
|
-
* ```
|
760
|
-
*
|
761
|
-
* @param value - The list of numbers that are allowed
|
762
|
-
*
|
763
|
-
* @returns - The schema instance
|
764
|
-
*/ key: "is",
|
765
|
-
value: function is(value, options) {
|
766
|
-
this.__is = {
|
767
|
-
value: value,
|
768
|
-
message: typeof (options === null || options === void 0 ? void 0 : options.message) === 'string' ? options.message : "The value should be equal to ".concat(value.join(', '))
|
769
|
-
};
|
770
|
-
return this;
|
771
|
-
}
|
772
|
-
},
|
773
|
-
{
|
774
|
-
/**
|
775
|
-
* Validates if the string ends with a specific value.
|
776
|
-
*
|
777
|
-
* @example
|
778
|
-
* ```typescript
|
779
|
-
* import * as p from '@palmares/schema';
|
780
|
-
*
|
781
|
-
* const schema = p.string().endsWith('.com');
|
782
|
-
*
|
783
|
-
* schema.parse('example.com'); // { errors: [], parsed: 'example.com' }
|
784
|
-
*
|
785
|
-
* // { errors: [{ code: 'endsWith', message: 'The value should end with .com', path: [] }], parsed: 'example.org' }
|
786
|
-
* schema.parse('example.org');
|
787
|
-
* ```
|
788
|
-
*
|
789
|
-
* @param value - The value that the string should end with.
|
790
|
-
* @param options - The options for the endsWith function.
|
791
|
-
* @param options.message - The message to be shown when the value does not end with the value.
|
792
|
-
*
|
793
|
-
* @returns - The schema instance.
|
794
|
-
*/ key: "endsWith",
|
795
|
-
value: function endsWith(value, options) {
|
796
|
-
this.__endsWith = {
|
797
|
-
value: value,
|
798
|
-
message: (options === null || options === void 0 ? void 0 : options.message) || "The value should end with ".concat(value)
|
799
|
-
};
|
800
|
-
return this;
|
801
|
-
}
|
802
|
-
},
|
803
|
-
{
|
804
|
-
/**
|
805
|
-
* Validates if the string starts with a specific value.
|
806
|
-
*
|
807
|
-
* @example
|
808
|
-
* ```typescript
|
809
|
-
* import * as p from '@palmares/schema';
|
810
|
-
*
|
811
|
-
* const schema = p.string().startsWith('https://');
|
812
|
-
*
|
813
|
-
* schema.parse('https://example.com'); // { errors: [], parsed: 'https://example.com' }
|
814
|
-
* // {
|
815
|
-
* // errors: [{ code: 'startsWith', message: 'The value should start with https://', path: [] }],
|
816
|
-
* // parsed: 'http://example.com'
|
817
|
-
* // }
|
818
|
-
* schema.parse('http://example.com');
|
819
|
-
* ```
|
820
|
-
*
|
821
|
-
* @param value - The value that the string should start with.
|
822
|
-
* @param options - The options for the startsWith function.
|
823
|
-
* @param options.message - The message to be shown when the value does not start with the value.
|
824
|
-
*
|
825
|
-
* @returns - The schema instance.
|
826
|
-
*/ key: "startsWith",
|
827
|
-
value: function startsWith(value, options) {
|
828
|
-
this.__startsWith = {
|
829
|
-
value: value,
|
830
|
-
message: (options === null || options === void 0 ? void 0 : options.message) || "The value should start with ".concat(value)
|
831
|
-
};
|
832
|
-
return this;
|
833
|
-
}
|
834
|
-
},
|
835
|
-
{
|
836
|
-
/**
|
837
|
-
* Checks if the string includes a specific substring.
|
838
|
-
*
|
839
|
-
* @example
|
840
|
-
* ```typescript
|
841
|
-
* import * as p from '@palmares/schema';
|
842
|
-
*
|
843
|
-
* const schema = p.string().includes('for babies');
|
844
|
-
*
|
845
|
-
* schema.parse('Computer graphics for babies'); // { errors: [], parsed: 'Computer graphics for babies' }
|
846
|
-
* // {
|
847
|
-
* // errors: [{
|
848
|
-
* // code: 'includes',
|
849
|
-
* // message: 'The string value should include the following substring 'for babies',
|
850
|
-
* // path: []
|
851
|
-
* // }], parsed: 'example.org' }
|
852
|
-
* schema.parse('Learn javascript as you were 5');
|
853
|
-
* ```
|
854
|
-
*
|
855
|
-
* @param value - The value that the string should include.
|
856
|
-
* @param options - The options for the includes function.
|
857
|
-
* @param options.message - The message to be shown when the value does not include the value.
|
858
|
-
*
|
859
|
-
* @returns - The schema instance.
|
860
|
-
*/ key: "includes",
|
861
|
-
value: function includes(value, options) {
|
862
|
-
this.__includes = {
|
863
|
-
value: value,
|
864
|
-
message: (options === null || options === void 0 ? void 0 : options.message) || "The string value should include the following substring '".concat(value, "'")
|
865
|
-
};
|
866
|
-
return this;
|
867
|
-
}
|
868
|
-
},
|
869
|
-
{
|
870
|
-
/**
|
871
|
-
* Validates if the string matches a specific regex.
|
872
|
-
*
|
873
|
-
* @example
|
874
|
-
* ```typescript
|
875
|
-
* import * as p from '@palmares/schema';
|
876
|
-
*
|
877
|
-
* const schema = p.string().regex(/^[a-z]+$/);
|
878
|
-
*
|
879
|
-
* schema.parse('abc'); // { errors: [], parsed: 'abc' }
|
880
|
-
* // {
|
881
|
-
* // errors: [{
|
882
|
-
* // code: 'regex',
|
883
|
-
* // message: 'The value should match the following regex /^[a-z]+$/',
|
884
|
-
* // path: []
|
885
|
-
* // }],
|
886
|
-
* // parsed: '123'
|
887
|
-
* // }
|
888
|
-
* schema.parse('123');
|
889
|
-
* ```
|
890
|
-
*
|
891
|
-
* @param value - The regex that the string should match.
|
892
|
-
* @param options - The options for the regex function.
|
893
|
-
* @param options.message - The message to be shown when the value does not match the regex.
|
894
|
-
*
|
895
|
-
* @returns - The schema instance.
|
896
|
-
*/ key: "regex",
|
897
|
-
value: function regex(value, options) {
|
898
|
-
this.__regex = {
|
899
|
-
value: value,
|
900
|
-
message: (options === null || options === void 0 ? void 0 : options.message) || "The value should match the following regex '".concat(value.toString(), "'")
|
901
|
-
};
|
902
|
-
return this;
|
903
|
-
}
|
904
|
-
},
|
905
|
-
{
|
906
|
-
/**
|
907
|
-
* Validates if the string has a maximum length. Use { inclusive: true } to allow the value to have the same length
|
908
|
-
* as the maximum length.
|
909
|
-
*
|
910
|
-
* @example
|
911
|
-
* ```typescript
|
912
|
-
* import * as p from '@palmares/schema';
|
913
|
-
*
|
914
|
-
* const schema = p.string().maxLength(5);
|
915
|
-
*
|
916
|
-
* schema.parse('12345'); // { errors: [], parsed: '12345' }
|
917
|
-
* // {
|
918
|
-
* // errors: [{ code: 'maxLength', message: 'The value should have a maximum length of 5', path: [] }],
|
919
|
-
* // parsed: '123
|
920
|
-
* // }
|
921
|
-
* schema.parse('123456');
|
922
|
-
* ```
|
923
|
-
*
|
924
|
-
* @param value - The maximum length that the string should have.
|
925
|
-
* @param options - The options for the maxLength function.
|
926
|
-
* @param options.message - The message to be shown when the value has a length greater than the maximum length.
|
927
|
-
* @param options.inclusive - Whether the value can have the same length as the maximum length. Defaults to false.
|
928
|
-
*
|
929
|
-
* @returns - The schema instance.
|
930
|
-
*/ key: "maxLength",
|
931
|
-
value: function maxLength(value, options) {
|
932
|
-
this.__maxLength = {
|
933
|
-
value: value,
|
934
|
-
message: (options === null || options === void 0 ? void 0 : options.message) || "The value should have a maximum length of ".concat(value)
|
935
|
-
};
|
936
|
-
return this;
|
937
|
-
}
|
938
|
-
},
|
939
|
-
{
|
940
|
-
/**
|
941
|
-
* Validates if the string has a minimum length. Use { inclusive: true } to allow the value to have the same length
|
942
|
-
* as the minimum length.
|
943
|
-
*
|
944
|
-
* @example
|
945
|
-
* ```typescript
|
946
|
-
* import * as p from '@palmares/schema';
|
947
|
-
*
|
948
|
-
* const schema = p.string().minLength(5);
|
949
|
-
*
|
950
|
-
* schema.parse('12345'); // { errors: [], parsed: '12345' }
|
951
|
-
* // {
|
952
|
-
* // errors: [{ code: 'minLength', message: 'The value should have a minimum length of 5', path: [] }],
|
953
|
-
* // parsed: '1234'
|
954
|
-
* // }
|
955
|
-
* schema.parse('1234');
|
956
|
-
* ```
|
957
|
-
*
|
958
|
-
* @param value - The minimum length that the string should have.
|
959
|
-
* @param options - The options for the minLength function.
|
960
|
-
* @param options.message - The message to be shown when the value has a length less than the minimum length.
|
961
|
-
* @param options.inclusive - Whether the value can have the same length as the minimum length. Defaults to false.
|
962
|
-
*
|
963
|
-
* @returns - The schema instance.
|
964
|
-
*/ key: "minLength",
|
965
|
-
value: function minLength(value, options) {
|
966
|
-
this.__minLength = {
|
967
|
-
value: value,
|
968
|
-
message: (options === null || options === void 0 ? void 0 : options.message) || "The value should have a minimum length of ".concat(value)
|
969
|
-
};
|
970
|
-
return this;
|
971
|
-
}
|
972
|
-
},
|
973
|
-
{
|
974
|
-
/**
|
975
|
-
* Validates if the string is a valid UUID.
|
976
|
-
*
|
977
|
-
* @example
|
978
|
-
* ```typescript
|
979
|
-
* import * as p from '@palmares/schema';
|
980
|
-
*
|
981
|
-
* const schema = p.string().uuid();
|
982
|
-
*
|
983
|
-
* // { errors: [], parsed: '550e8400-e29b-41d4-a716-446655440000' }
|
984
|
-
* schema.parse('550e8400-e29b-41d4-a716-446655440000');
|
985
|
-
* ```
|
986
|
-
*
|
987
|
-
* @param options - The options for the uuid function.
|
988
|
-
* @param options.message - The message to be shown when the value is not a valid UUID. Defaults to
|
989
|
-
* 'The value should be a valid UUID'.
|
990
|
-
*
|
991
|
-
* @returns - The schema instance.
|
992
|
-
*/ key: "uuid",
|
993
|
-
value: function uuid(options) {
|
994
|
-
this.__uuid = {
|
995
|
-
message: (options === null || options === void 0 ? void 0 : options.message) || 'The value should be a valid UUID'
|
996
|
-
};
|
997
|
-
return this;
|
998
|
-
}
|
999
|
-
},
|
1000
|
-
{
|
1001
|
-
/**
|
1002
|
-
* Validates if the string is a valid email or not
|
1003
|
-
*
|
1004
|
-
* @example
|
1005
|
-
* ```typescript
|
1006
|
-
*
|
1007
|
-
* import * as p from '@palmares/schema';
|
1008
|
-
*
|
1009
|
-
* const schema = p.string().email();
|
1010
|
-
*
|
1011
|
-
* schema.parse('john.doe@example.com'); // { errors: [], parsed: 'john.doe@example.com' }
|
1012
|
-
* ```
|
1013
|
-
*
|
1014
|
-
* @param options - The options for the email function.
|
1015
|
-
* @param options.message - The message to be shown when the value is not a valid email.
|
1016
|
-
* Defaults to 'The value should be a valid email'.
|
1017
|
-
*
|
1018
|
-
* @returns - The schema instance.
|
1019
|
-
*/ key: "email",
|
1020
|
-
value: function email(options) {
|
1021
|
-
this.__email = {
|
1022
|
-
message: (options === null || options === void 0 ? void 0 : options.message) || 'The value should be a valid email'
|
1023
|
-
};
|
1024
|
-
return this;
|
1025
|
-
}
|
1026
|
-
}
|
1027
|
-
], [
|
1028
|
-
{
|
1029
|
-
key: "new",
|
1030
|
-
value: function _new() {
|
1031
|
-
var returnValue = new StringSchema();
|
1032
|
-
return returnValue;
|
1033
|
-
}
|
1034
|
-
}
|
1035
|
-
]);
|
1036
|
-
return StringSchema;
|
1037
|
-
}(_schema.Schema);
|
1038
|
-
var string = StringSchema.new;
|