@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,840 +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
|
-
DatetimeSchema: function() {
|
13
|
-
return DatetimeSchema;
|
14
|
-
},
|
15
|
-
datetime: function() {
|
16
|
-
return datetime;
|
17
|
-
}
|
18
|
-
});
|
19
|
-
var _schema = require("./schema");
|
20
|
-
var _utils = require("../utils");
|
21
|
-
var _datetime = require("../validators/datetime");
|
22
|
-
var _schema1 = require("../validators/schema");
|
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 _instanceof(left, right) {
|
126
|
-
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
127
|
-
return !!right[Symbol.hasInstance](left);
|
128
|
-
} else {
|
129
|
-
return left instanceof right;
|
130
|
-
}
|
131
|
-
}
|
132
|
-
function _possible_constructor_return(self, call) {
|
133
|
-
if (call && (_type_of(call) === "object" || typeof call === "function")) {
|
134
|
-
return call;
|
135
|
-
}
|
136
|
-
return _assert_this_initialized(self);
|
137
|
-
}
|
138
|
-
function _set_prototype_of(o, p) {
|
139
|
-
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
140
|
-
o.__proto__ = p;
|
141
|
-
return o;
|
142
|
-
};
|
143
|
-
return _set_prototype_of(o, p);
|
144
|
-
}
|
145
|
-
function _super_prop_base(object, property) {
|
146
|
-
while(!Object.prototype.hasOwnProperty.call(object, property)){
|
147
|
-
object = _get_prototype_of(object);
|
148
|
-
if (object === null) break;
|
149
|
-
}
|
150
|
-
return object;
|
151
|
-
}
|
152
|
-
function _type_of(obj) {
|
153
|
-
"@swc/helpers - typeof";
|
154
|
-
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
155
|
-
}
|
156
|
-
function _is_native_reflect_construct() {
|
157
|
-
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
158
|
-
if (Reflect.construct.sham) return false;
|
159
|
-
if (typeof Proxy === "function") return true;
|
160
|
-
try {
|
161
|
-
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
162
|
-
return true;
|
163
|
-
} catch (e) {
|
164
|
-
return false;
|
165
|
-
}
|
166
|
-
}
|
167
|
-
function _create_super(Derived) {
|
168
|
-
var hasNativeReflectConstruct = _is_native_reflect_construct();
|
169
|
-
return function _createSuperInternal() {
|
170
|
-
var Super = _get_prototype_of(Derived), result;
|
171
|
-
if (hasNativeReflectConstruct) {
|
172
|
-
var NewTarget = _get_prototype_of(this).constructor;
|
173
|
-
result = Reflect.construct(Super, arguments, NewTarget);
|
174
|
-
} else {
|
175
|
-
result = Super.apply(this, arguments);
|
176
|
-
}
|
177
|
-
return _possible_constructor_return(this, result);
|
178
|
-
};
|
179
|
-
}
|
180
|
-
function _ts_generator(thisArg, body) {
|
181
|
-
var f, y, t, g, _ = {
|
182
|
-
label: 0,
|
183
|
-
sent: function() {
|
184
|
-
if (t[0] & 1) throw t[1];
|
185
|
-
return t[1];
|
186
|
-
},
|
187
|
-
trys: [],
|
188
|
-
ops: []
|
189
|
-
};
|
190
|
-
return g = {
|
191
|
-
next: verb(0),
|
192
|
-
"throw": verb(1),
|
193
|
-
"return": verb(2)
|
194
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
195
|
-
return this;
|
196
|
-
}), g;
|
197
|
-
function verb(n) {
|
198
|
-
return function(v) {
|
199
|
-
return step([
|
200
|
-
n,
|
201
|
-
v
|
202
|
-
]);
|
203
|
-
};
|
204
|
-
}
|
205
|
-
function step(op) {
|
206
|
-
if (f) throw new TypeError("Generator is already executing.");
|
207
|
-
while(_)try {
|
208
|
-
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;
|
209
|
-
if (y = 0, t) op = [
|
210
|
-
op[0] & 2,
|
211
|
-
t.value
|
212
|
-
];
|
213
|
-
switch(op[0]){
|
214
|
-
case 0:
|
215
|
-
case 1:
|
216
|
-
t = op;
|
217
|
-
break;
|
218
|
-
case 4:
|
219
|
-
_.label++;
|
220
|
-
return {
|
221
|
-
value: op[1],
|
222
|
-
done: false
|
223
|
-
};
|
224
|
-
case 5:
|
225
|
-
_.label++;
|
226
|
-
y = op[1];
|
227
|
-
op = [
|
228
|
-
0
|
229
|
-
];
|
230
|
-
continue;
|
231
|
-
case 7:
|
232
|
-
op = _.ops.pop();
|
233
|
-
_.trys.pop();
|
234
|
-
continue;
|
235
|
-
default:
|
236
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
237
|
-
_ = 0;
|
238
|
-
continue;
|
239
|
-
}
|
240
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
241
|
-
_.label = op[1];
|
242
|
-
break;
|
243
|
-
}
|
244
|
-
if (op[0] === 6 && _.label < t[1]) {
|
245
|
-
_.label = t[1];
|
246
|
-
t = op;
|
247
|
-
break;
|
248
|
-
}
|
249
|
-
if (t && _.label < t[2]) {
|
250
|
-
_.label = t[2];
|
251
|
-
_.ops.push(op);
|
252
|
-
break;
|
253
|
-
}
|
254
|
-
if (t[2]) _.ops.pop();
|
255
|
-
_.trys.pop();
|
256
|
-
continue;
|
257
|
-
}
|
258
|
-
op = body.call(thisArg, _);
|
259
|
-
} catch (e) {
|
260
|
-
op = [
|
261
|
-
6,
|
262
|
-
e
|
263
|
-
];
|
264
|
-
y = 0;
|
265
|
-
} finally{
|
266
|
-
f = t = 0;
|
267
|
-
}
|
268
|
-
if (op[0] & 5) throw op[1];
|
269
|
-
return {
|
270
|
-
value: op[0] ? op[1] : void 0,
|
271
|
-
done: true
|
272
|
-
};
|
273
|
-
}
|
274
|
-
}
|
275
|
-
var DatetimeSchema = /*#__PURE__*/ function(Schema) {
|
276
|
-
"use strict";
|
277
|
-
_inherits(DatetimeSchema, Schema);
|
278
|
-
var _super = _create_super(DatetimeSchema);
|
279
|
-
function DatetimeSchema() {
|
280
|
-
_class_call_check(this, DatetimeSchema);
|
281
|
-
var _this;
|
282
|
-
_this = _super.apply(this, arguments);
|
283
|
-
_define_property(_assert_this_initialized(_this), "fieldType", 'datetime');
|
284
|
-
_define_property(_assert_this_initialized(_this), "__allowString", void 0);
|
285
|
-
_define_property(_assert_this_initialized(_this), "__above", void 0);
|
286
|
-
_define_property(_assert_this_initialized(_this), "__below", void 0);
|
287
|
-
_define_property(_assert_this_initialized(_this), "__type", {
|
288
|
-
message: 'Invalid type',
|
289
|
-
check: function(value) {
|
290
|
-
if (typeof value === 'string') {
|
291
|
-
var valueAsDate = new Date(value);
|
292
|
-
if (isNaN(valueAsDate.getTime())) return false;
|
293
|
-
return true;
|
294
|
-
}
|
295
|
-
return _instanceof(value, Date);
|
296
|
-
}
|
297
|
-
});
|
298
|
-
return _this;
|
299
|
-
}
|
300
|
-
_create_class(DatetimeSchema, [
|
301
|
-
{
|
302
|
-
key: "__transformToAdapter",
|
303
|
-
value: function __transformToAdapter(options) {
|
304
|
-
var _this = this;
|
305
|
-
return _async_to_generator(function() {
|
306
|
-
return _ts_generator(this, function(_state) {
|
307
|
-
return [
|
308
|
-
2,
|
309
|
-
(0, _utils.defaultTransformToAdapter)(function() {
|
310
|
-
var _ref = _async_to_generator(function(adapter) {
|
311
|
-
return _ts_generator(this, function(_state) {
|
312
|
-
return [
|
313
|
-
2,
|
314
|
-
(0, _utils.defaultTransform)('datetime', _this, adapter, adapter.datetime, function() {
|
315
|
-
return {
|
316
|
-
allowString: _this.__allowString,
|
317
|
-
below: _this.__below,
|
318
|
-
above: _this.__above,
|
319
|
-
nullable: _this.__nullable,
|
320
|
-
optional: _this.__optional,
|
321
|
-
type: _this.__type,
|
322
|
-
parsers: {
|
323
|
-
nullable: _this.__nullable.allow,
|
324
|
-
optional: _this.__optional.allow
|
325
|
-
}
|
326
|
-
};
|
327
|
-
}, {
|
328
|
-
optional: _schema1.optional,
|
329
|
-
nullable: _schema1.nullable,
|
330
|
-
allowString: _datetime.allowStringParser,
|
331
|
-
above: _datetime.above,
|
332
|
-
below: _datetime.below
|
333
|
-
}, {
|
334
|
-
validatorsIfFallbackOrNotSupported: (0, _datetime.datetimeValidation)(),
|
335
|
-
shouldAddStringVersion: options.shouldAddStringVersion,
|
336
|
-
// eslint-disable-next-line ts/require-await
|
337
|
-
fallbackIfNotSupported: /*#__PURE__*/ _async_to_generator(function() {
|
338
|
-
return _ts_generator(this, function(_state) {
|
339
|
-
return [
|
340
|
-
2,
|
341
|
-
[]
|
342
|
-
];
|
343
|
-
});
|
344
|
-
})
|
345
|
-
})
|
346
|
-
];
|
347
|
-
});
|
348
|
-
});
|
349
|
-
return function(adapter) {
|
350
|
-
return _ref.apply(this, arguments);
|
351
|
-
};
|
352
|
-
}(), _this, _this.__transformedSchemas, options, 'datetime')
|
353
|
-
];
|
354
|
-
});
|
355
|
-
})();
|
356
|
-
}
|
357
|
-
},
|
358
|
-
{
|
359
|
-
/**
|
360
|
-
* This let's you refine the schema with custom validations. This is useful when you want to validate something
|
361
|
-
* that is not supported by default by the schema adapter.
|
362
|
-
*
|
363
|
-
* @example
|
364
|
-
* ```typescript
|
365
|
-
* import * as p from '@palmares/schemas';
|
366
|
-
*
|
367
|
-
* const numberSchema = p.number().refine((value) => {
|
368
|
-
* if (value < 0) return { code: 'invalid_number', message: 'The number should be greater than 0' };
|
369
|
-
* });
|
370
|
-
*
|
371
|
-
* const { errors, parsed } = await numberSchema.parse(-1);
|
372
|
-
*
|
373
|
-
* // [{ isValid: false, code: 'invalid_number', message: 'The number should be greater than 0', path: [] }]
|
374
|
-
* console.log(errors);
|
375
|
-
* ```
|
376
|
-
*
|
377
|
-
* @param refinementCallback - The callback that will be called to validate the value.
|
378
|
-
* @param options - Options for the refinement.
|
379
|
-
* @param options.isAsync - Whether the callback is async or not. Defaults to true.
|
380
|
-
*
|
381
|
-
* @returns The schema.
|
382
|
-
*/ key: "refine",
|
383
|
-
value: function refine(refinementCallback) {
|
384
|
-
return _get(_get_prototype_of(DatetimeSchema.prototype), "refine", this).call(this, refinementCallback);
|
385
|
-
}
|
386
|
-
},
|
387
|
-
{
|
388
|
-
/**
|
389
|
-
* Allows the value to be either undefined or null.
|
390
|
-
*
|
391
|
-
* @example
|
392
|
-
* ```typescript
|
393
|
-
* import * as p from '@palmares/schemas';
|
394
|
-
*
|
395
|
-
* const numberSchema = p.number().optional();
|
396
|
-
*
|
397
|
-
* const { errors, parsed } = await numberSchema.parse(undefined);
|
398
|
-
*
|
399
|
-
* console.log(parsed); // undefined
|
400
|
-
*
|
401
|
-
* const { errors, parsed } = await numberSchema.parse(null);
|
402
|
-
*
|
403
|
-
* console.log(parsed); // null
|
404
|
-
*
|
405
|
-
* const { errors, parsed } = await numberSchema.parse(1);
|
406
|
-
*
|
407
|
-
* console.log(parsed); // 1
|
408
|
-
* ```
|
409
|
-
*
|
410
|
-
* @returns - The schema we are working with.
|
411
|
-
*/ key: "optional",
|
412
|
-
value: function optional(options) {
|
413
|
-
return _get(_get_prototype_of(DatetimeSchema.prototype), "optional", this).call(this, options);
|
414
|
-
}
|
415
|
-
},
|
416
|
-
{
|
417
|
-
/**
|
418
|
-
* Just adds a message when the value is undefined. It's just a syntax sugar for
|
419
|
-
*
|
420
|
-
* ```typescript
|
421
|
-
* p.datetime().optional({ message: 'This value should be defined', allow: false })
|
422
|
-
* ```
|
423
|
-
*
|
424
|
-
* @param options - The options of nonOptional function
|
425
|
-
* @param options.message - A custom message if the value is undefined.
|
426
|
-
*
|
427
|
-
* @returns - The schema.
|
428
|
-
*/ key: "nonOptional",
|
429
|
-
value: function nonOptional(options) {
|
430
|
-
return _get(_get_prototype_of(DatetimeSchema.prototype), "optional", this).call(this, {
|
431
|
-
message: options === null || options === void 0 ? void 0 : options.message,
|
432
|
-
allow: false
|
433
|
-
});
|
434
|
-
}
|
435
|
-
},
|
436
|
-
{
|
437
|
-
/**
|
438
|
-
* Allows the value to be null and ONLY null. You can also use this function to set a custom message when the value
|
439
|
-
* is NULL by setting the { message: 'Your custom message', allow: false } on the options.
|
440
|
-
*
|
441
|
-
* @example
|
442
|
-
* ```typescript
|
443
|
-
* import * as p from '@palmares/schemas';
|
444
|
-
*
|
445
|
-
* const numberSchema = p.number().nullable();
|
446
|
-
*
|
447
|
-
* const { errors, parsed } = await numberSchema.parse(null);
|
448
|
-
*
|
449
|
-
* console.log(parsed); // null
|
450
|
-
*
|
451
|
-
* const { errors, parsed } = await numberSchema.parse(undefined);
|
452
|
-
*
|
453
|
-
* console.log(errors); // [{ isValid: false, code: 'invalid_type', message: 'Invalid type', path: [] }]
|
454
|
-
* ```
|
455
|
-
*
|
456
|
-
* @param options - The options for the nullable function.
|
457
|
-
* @param options.message - The message to be shown when the value is not null. Defaults to 'Cannot be null'.
|
458
|
-
* @param options.allow - Whether the value can be null or not. Defaults to true.
|
459
|
-
*
|
460
|
-
* @returns The schema.
|
461
|
-
*/ key: "nullable",
|
462
|
-
value: function nullable(options) {
|
463
|
-
return _get(_get_prototype_of(DatetimeSchema.prototype), "nullable", this).call(this, options);
|
464
|
-
}
|
465
|
-
},
|
466
|
-
{
|
467
|
-
/**
|
468
|
-
* Just adds a message when the value is null. It's just a syntax sugar for
|
469
|
-
*
|
470
|
-
* ```typescript
|
471
|
-
* p.datetime().nullable({ message: 'This value cannot be null', allow: false })
|
472
|
-
* ```
|
473
|
-
*
|
474
|
-
* @param options - The options of nonNullable function
|
475
|
-
* @param options.message - A custom message if the value is null.
|
476
|
-
*
|
477
|
-
* @returns - The schema.
|
478
|
-
*/ key: "nonNullable",
|
479
|
-
value: function nonNullable(options) {
|
480
|
-
return _get(_get_prototype_of(DatetimeSchema.prototype), "nullable", this).call(this, {
|
481
|
-
message: (options === null || options === void 0 ? void 0 : options.message) || '',
|
482
|
-
allow: false
|
483
|
-
});
|
484
|
-
}
|
485
|
-
},
|
486
|
-
{
|
487
|
-
/**
|
488
|
-
* This method will remove the value from the representation of the schema. If the value is undefined it will keep
|
489
|
-
* that way otherwise it will set the value to undefined after it's validated.
|
490
|
-
* This is used in conjunction with the {@link data} function, the {@link parse} function or {@link validate}
|
491
|
-
* function. This will remove the value from the representation of the schema.
|
492
|
-
*
|
493
|
-
* By default, the value will be removed just from the representation, in other words, when you call the {@link data}
|
494
|
-
* function.But if you want to remove the value from the internal representation, you can pass the argument
|
495
|
-
* `toInternal` as true. Then if you still want to remove the value from the representation, you will need to pass
|
496
|
-
* the argument `toRepresentation` as true as well.
|
497
|
-
*
|
498
|
-
* @example
|
499
|
-
* ```typescript
|
500
|
-
* import * as p from '@palmares/schemas';
|
501
|
-
*
|
502
|
-
* const userSchema = p.object({
|
503
|
-
* id: p.number().optional(),
|
504
|
-
* name: p.string(),
|
505
|
-
* password: p.string().omit()
|
506
|
-
* });
|
507
|
-
*
|
508
|
-
* const user = await userSchema.data({
|
509
|
-
* id: 1,
|
510
|
-
* name: 'John Doe',
|
511
|
-
* password: '123456'
|
512
|
-
* });
|
513
|
-
*
|
514
|
-
* console.log(user); // { id: 1, name: 'John Doe' }
|
515
|
-
* ```
|
516
|
-
*
|
517
|
-
*
|
518
|
-
* @param args - By default, the value will be removed just from the representation, in other words, when you call
|
519
|
-
* the {@link data} function.
|
520
|
-
* But if you want to remove the value from the internal representation, you can pass the argument `toInternal` as
|
521
|
-
* true. Then if you still want to remove the value from the representation, you will need to pass the argument
|
522
|
-
* `toRepresentation` as true as well.
|
523
|
-
*
|
524
|
-
* @returns The schema.
|
525
|
-
*/ key: "omit",
|
526
|
-
value: function omit(args) {
|
527
|
-
return _get(_get_prototype_of(DatetimeSchema.prototype), "omit", this).call(this, args);
|
528
|
-
}
|
529
|
-
},
|
530
|
-
{
|
531
|
-
/**
|
532
|
-
* This function is used in conjunction with the {@link validate} function. It's used to save a value to an external
|
533
|
-
* source like a database. You should always return the schema after you save the value, that way we will always have
|
534
|
-
* the correct type of the schema after the save operation.
|
535
|
-
*
|
536
|
-
* You can use the {@link toRepresentation} function to transform and clean the value it returns after the save.
|
537
|
-
*
|
538
|
-
* @example
|
539
|
-
* ```typescript
|
540
|
-
* import * as p from '@palmares/schemas';
|
541
|
-
*
|
542
|
-
* import { User } from './models';
|
543
|
-
*
|
544
|
-
* const userSchema = p.object({
|
545
|
-
* id: p.number().optional(),
|
546
|
-
* name: p.string(),
|
547
|
-
* email: p.string().email(),
|
548
|
-
* }).onSave(async (value) => {
|
549
|
-
* // Create or update the user on the database using palmares models or any other library of your choice.
|
550
|
-
* if (value.id)
|
551
|
-
* await User.default.set(value, { search: { id: value.id } });
|
552
|
-
* else
|
553
|
-
* await User.default.set(value);
|
554
|
-
*
|
555
|
-
* return value;
|
556
|
-
* });
|
557
|
-
*
|
558
|
-
*
|
559
|
-
* // Then, on your controller, do something like this:
|
560
|
-
* const { isValid, save, errors } = await userSchema.validate(req.body);
|
561
|
-
* if (isValid) {
|
562
|
-
* const savedValue = await save();
|
563
|
-
* return Response.json(savedValue, { status: 201 });
|
564
|
-
* }
|
565
|
-
*
|
566
|
-
* return Response.json({ errors }, { status: 400 });
|
567
|
-
* ```
|
568
|
-
*
|
569
|
-
* @param callback - The callback that will be called to save the value on an external source.
|
570
|
-
*
|
571
|
-
* @returns The schema.
|
572
|
-
*/ key: "onSave",
|
573
|
-
value: function onSave(callback) {
|
574
|
-
return _get(_get_prototype_of(DatetimeSchema.prototype), "onSave", this).call(this, callback);
|
575
|
-
}
|
576
|
-
},
|
577
|
-
{
|
578
|
-
/**
|
579
|
-
* This function is used to add a default value to the schema. If the value is either undefined or null, the default
|
580
|
-
* value will be used.
|
581
|
-
*
|
582
|
-
* @example
|
583
|
-
* ```typescript
|
584
|
-
* import * as p from '@palmares/schemas';
|
585
|
-
*
|
586
|
-
* const numberSchema = p.number().default(0);
|
587
|
-
*
|
588
|
-
* const { errors, parsed } = await numberSchema.parse(undefined);
|
589
|
-
*
|
590
|
-
* console.log(parsed); // 0
|
591
|
-
* ```
|
592
|
-
*/ key: "default",
|
593
|
-
value: function _default(defaultValueOrFunction) {
|
594
|
-
return _get(_get_prototype_of(DatetimeSchema.prototype), "default", this).call(this, defaultValueOrFunction);
|
595
|
-
}
|
596
|
-
},
|
597
|
-
{
|
598
|
-
/**
|
599
|
-
* This function let's you customize the schema your own way. After we translate the schema on the adapter we call
|
600
|
-
* this function to let you customize the custom schema your own way. Our API does not support passthrough?
|
601
|
-
* No problem, you can use this function to customize the zod schema.
|
602
|
-
*
|
603
|
-
* @example
|
604
|
-
* ```typescript
|
605
|
-
* import * as p from '@palmares/schemas';
|
606
|
-
*
|
607
|
-
* const numberSchema = p.number().extends((schema) => {
|
608
|
-
* return schema.nonnegative();
|
609
|
-
* });
|
610
|
-
*
|
611
|
-
* const { errors, parsed } = await numberSchema.parse(-1);
|
612
|
-
*
|
613
|
-
* // [{ isValid: false, code: 'nonnegative', message: 'The number should be nonnegative', path: [] }]
|
614
|
-
* console.log(errors);
|
615
|
-
* ```
|
616
|
-
*
|
617
|
-
* @param callback - The callback that will be called to customize the schema.
|
618
|
-
* @param toStringCallback - The callback that will be called to transform the schema to a string when you want to
|
619
|
-
* compile the underlying schema to a string so you can save it for future runs.
|
620
|
-
*
|
621
|
-
* @returns The schema.
|
622
|
-
*/ key: "extends",
|
623
|
-
value: function _extends(callback, toStringCallback) {
|
624
|
-
return _get(_get_prototype_of(DatetimeSchema.prototype), "extends", this).call(this, callback, toStringCallback);
|
625
|
-
}
|
626
|
-
},
|
627
|
-
{
|
628
|
-
/**
|
629
|
-
* This function is used to transform the value to the representation of the schema. When using the {@link data}
|
630
|
-
* function. With this function you have full control to add data cleaning for example, transforming the data and
|
631
|
-
* whatever. Another use case is when you want to return deeply nested recursive data.
|
632
|
-
* The schema maps to itself.
|
633
|
-
*
|
634
|
-
* @example
|
635
|
-
* ```typescript
|
636
|
-
* import * as p from '@palmares/schemas';
|
637
|
-
*
|
638
|
-
* const recursiveSchema = p.object({
|
639
|
-
* id: p.number().optional(),
|
640
|
-
* name: p.string(),
|
641
|
-
* }).toRepresentation(async (value) => {
|
642
|
-
* return {
|
643
|
-
* id: value.id,
|
644
|
-
* name: value.name,
|
645
|
-
* children: await Promise.all(value.children.map(async (child) => await recursiveSchema.data(child)))
|
646
|
-
* }
|
647
|
-
* });
|
648
|
-
*
|
649
|
-
* const data = await recursiveSchema.data({
|
650
|
-
* id: 1,
|
651
|
-
* name: 'John Doe',
|
652
|
-
* });
|
653
|
-
* ```
|
654
|
-
*
|
655
|
-
* @example
|
656
|
-
* ```
|
657
|
-
* import * as p from '@palmares/schemas';
|
658
|
-
*
|
659
|
-
* const colorToRGBSchema = p.string().toRepresentation(async (value) => {
|
660
|
-
* switch (value) {
|
661
|
-
* case 'red': return { r: 255, g: 0, b: 0 };
|
662
|
-
* case 'green': return { r: 0, g: 255, b: 0 };
|
663
|
-
* case 'blue': return { r: 0, g: 0, b: 255 };
|
664
|
-
* default: return { r: 0, g: 0, b: 0 };
|
665
|
-
* }
|
666
|
-
* });
|
667
|
-
* ```
|
668
|
-
* @param toRepresentationCallback - The callback that will be called to transform the value to the representation.
|
669
|
-
*
|
670
|
-
* @returns The schema with a new return type
|
671
|
-
*/ key: "toRepresentation",
|
672
|
-
value: function toRepresentation(toRepresentationCallback) {
|
673
|
-
return _get(_get_prototype_of(DatetimeSchema.prototype), "toRepresentation", this).call(this, toRepresentationCallback);
|
674
|
-
}
|
675
|
-
},
|
676
|
-
{
|
677
|
-
/**
|
678
|
-
* This function is used to transform the value to the internal representation of the schema. This is useful when you
|
679
|
-
* want to transform the value to a type that the schema adapter can understand. For example, you might want to
|
680
|
-
* transform a string to a date. This is the function you use.
|
681
|
-
*
|
682
|
-
* @example
|
683
|
-
* ```typescript
|
684
|
-
* import * as p from '@palmares/schemas';
|
685
|
-
*
|
686
|
-
* const dateSchema = p.string().toInternal((value) => {
|
687
|
-
* return new Date(value);
|
688
|
-
* });
|
689
|
-
*
|
690
|
-
* const date = await dateSchema.parse('2021-01-01');
|
691
|
-
*
|
692
|
-
* console.log(date); // Date object
|
693
|
-
*
|
694
|
-
* const rgbToColorSchema = p.object({
|
695
|
-
* r: p.number().min(0).max(255),
|
696
|
-
* g: p.number().min(0).max(255),
|
697
|
-
* b: p.number().min(0).max(255),
|
698
|
-
* }).toInternal(async (value) => {
|
699
|
-
* if (value.r === 255 && value.g === 0 && value.b === 0) return 'red';
|
700
|
-
* if (value.r === 0 && value.g === 255 && value.b === 0) return 'green';
|
701
|
-
* if (value.r === 0 && value.g === 0 && value.b === 255) return 'blue';
|
702
|
-
* return `rgb(${value.r}, ${value.g}, ${value.b})`;
|
703
|
-
* });
|
704
|
-
* ```
|
705
|
-
*
|
706
|
-
* @param toInternalCallback - The callback that will be called to transform the value to the internal representation.
|
707
|
-
*
|
708
|
-
* @returns The schema with a new return type.
|
709
|
-
*/ key: "toInternal",
|
710
|
-
value: function toInternal(toInternalCallback) {
|
711
|
-
return _get(_get_prototype_of(DatetimeSchema.prototype), "toInternal", this).call(this, toInternalCallback);
|
712
|
-
}
|
713
|
-
},
|
714
|
-
{
|
715
|
-
/**
|
716
|
-
* Called before the validation of the schema. Let's say that you want to validate a date that might receive a string,
|
717
|
-
* you can convert that string to a date here BEFORE the validation. This pretty much transforms the value to a type
|
718
|
-
* that the schema adapter can understand.
|
719
|
-
*
|
720
|
-
* @example
|
721
|
-
* ```
|
722
|
-
* import * as p from '@palmares/schemas';
|
723
|
-
* import * as z from 'zod';
|
724
|
-
*
|
725
|
-
* const customRecordToMapSchema = p.schema().appendSchema(z.map()).toValidate(async (value) => {
|
726
|
-
* return new Map(value); // Before validating we transform the value to a map.
|
727
|
-
* });
|
728
|
-
*
|
729
|
-
* const { errors, parsed } = await customRecordToMapSchema.parse({ key: 'value' });
|
730
|
-
* ```
|
731
|
-
*
|
732
|
-
* @param toValidateCallback - The callback that will be called to validate the value.
|
733
|
-
*
|
734
|
-
* @returns The schema with a new return type.
|
735
|
-
*/ key: "toValidate",
|
736
|
-
value: function toValidate(toValidateCallback) {
|
737
|
-
return _get(_get_prototype_of(DatetimeSchema.prototype), "toValidate", this).call(this, toValidateCallback);
|
738
|
-
}
|
739
|
-
},
|
740
|
-
{
|
741
|
-
/**
|
742
|
-
* This will allow the value to be a string, it does not validate, it just parses inputs as strings and allows the
|
743
|
-
* result to be a string as well.
|
744
|
-
*
|
745
|
-
* @example
|
746
|
-
* ```typescript
|
747
|
-
* const schema = datetime().allowString();
|
748
|
-
*
|
749
|
-
* schema.parse('2021-01-01T00:00:00.000Z') // works
|
750
|
-
* ```
|
751
|
-
*
|
752
|
-
* @returns - The schema instance
|
753
|
-
*/ key: "allowString",
|
754
|
-
value: function allowString() {
|
755
|
-
this.__allowString = true;
|
756
|
-
return this;
|
757
|
-
}
|
758
|
-
},
|
759
|
-
{
|
760
|
-
/**
|
761
|
-
* This will validate if the value is above the specified date.
|
762
|
-
*
|
763
|
-
* @example
|
764
|
-
* ```ts
|
765
|
-
* const today = new Date();
|
766
|
-
* const yesterday = new Date(today);
|
767
|
-
* yesterday.setDate(today.getDate() - 1);
|
768
|
-
*
|
769
|
-
* datetime().above(today).parse(today) // throws error
|
770
|
-
* datetime().above(today, { inclusive: true }).parse(today) // works
|
771
|
-
* datetime().above(yesterday).parse(today) // works
|
772
|
-
* ```
|
773
|
-
*
|
774
|
-
* @param value - The value that we are comparing against.
|
775
|
-
* @param options - The options that we are passing to the validator.
|
776
|
-
* @param options.inclusive - If the value is inclusive or not. In other words, if the value can be equal to
|
777
|
-
* the specified date.
|
778
|
-
* @param options.message - The message that we are returning if the value is not above the specified date.
|
779
|
-
*
|
780
|
-
* @returns - The schema instance
|
781
|
-
*/ key: "above",
|
782
|
-
value: function above(value, options) {
|
783
|
-
var inclusive = typeof (options === null || options === void 0 ? void 0 : options.inclusive) === 'boolean' ? options.inclusive : false;
|
784
|
-
var message = (options === null || options === void 0 ? void 0 : options.message) || 'Value is not above the specified date';
|
785
|
-
this.__above = {
|
786
|
-
value: value,
|
787
|
-
inclusive: inclusive,
|
788
|
-
message: message
|
789
|
-
};
|
790
|
-
return this;
|
791
|
-
}
|
792
|
-
},
|
793
|
-
{
|
794
|
-
/**
|
795
|
-
* This will validate if the value is below the specified date.
|
796
|
-
*
|
797
|
-
* @example
|
798
|
-
* ```ts
|
799
|
-
* const today = new Date();
|
800
|
-
* const yesterday = new Date(today);
|
801
|
-
* yesterday.setDate(today.getDate() - 1);
|
802
|
-
*
|
803
|
-
* datetime().below(today).parse(today) // throws error
|
804
|
-
* datetime().below(today, { inclusive: true }).parse(today) // works
|
805
|
-
* datetime().below(today).parse(yesterday) // works
|
806
|
-
* ```
|
807
|
-
*
|
808
|
-
* @param value - The value that we are comparing against.
|
809
|
-
* @param options - The options that we are passing to the validator.
|
810
|
-
* @param options.inclusive - If the value is inclusive or not. In other words, if the value can be equal to the
|
811
|
-
* specified date.
|
812
|
-
* @param options.message - The message that we are returning if the value is not above the specified date.
|
813
|
-
*
|
814
|
-
* @returns - The schema instance
|
815
|
-
*/ key: "below",
|
816
|
-
value: function below(value, options) {
|
817
|
-
var inclusive = typeof (options === null || options === void 0 ? void 0 : options.inclusive) === 'boolean' ? options.inclusive : false;
|
818
|
-
var message = (options === null || options === void 0 ? void 0 : options.message) || 'Value is not below the specified date';
|
819
|
-
this.__below = {
|
820
|
-
value: value,
|
821
|
-
inclusive: inclusive,
|
822
|
-
message: message
|
823
|
-
};
|
824
|
-
return this;
|
825
|
-
}
|
826
|
-
}
|
827
|
-
], [
|
828
|
-
{
|
829
|
-
key: "new",
|
830
|
-
value: function _new() {
|
831
|
-
var returnValue = new DatetimeSchema();
|
832
|
-
return returnValue;
|
833
|
-
}
|
834
|
-
}
|
835
|
-
]);
|
836
|
-
return DatetimeSchema;
|
837
|
-
}(_schema.Schema);
|
838
|
-
var datetime = function() {
|
839
|
-
return DatetimeSchema.new();
|
840
|
-
};
|