@palmares/schemas 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build$colon$watch.log +424 -0
- package/.turbo/turbo-build.log +13 -0
- package/.turbo/turbo-build:watch.log +26 -0
- package/CHANGELOG.md +11 -0
- package/LICENSE +21 -0
- package/dist/cjs/src/adapter/fields/array.js +157 -0
- package/dist/cjs/src/adapter/fields/boolean.js +167 -0
- package/dist/cjs/src/adapter/fields/datetime.js +167 -0
- package/dist/cjs/src/adapter/fields/index.js +311 -0
- package/dist/cjs/src/adapter/fields/number.js +167 -0
- package/dist/cjs/src/adapter/fields/object.js +167 -0
- package/dist/cjs/src/adapter/fields/string.js +167 -0
- package/dist/cjs/src/adapter/fields/union.js +167 -0
- package/dist/cjs/src/adapter/index.js +198 -0
- package/dist/cjs/src/adapter/types.js +4 -0
- package/dist/cjs/src/compile.js +262 -0
- package/dist/cjs/src/conf.js +27 -0
- package/dist/cjs/src/constants.js +42 -0
- package/dist/cjs/src/domain.js +12 -0
- package/dist/cjs/src/exceptions.js +168 -0
- package/dist/cjs/src/index.js +365 -0
- package/dist/cjs/src/model.js +628 -0
- package/dist/cjs/src/parsers/convert-from-number.js +20 -0
- package/dist/cjs/src/parsers/convert-from-string.js +24 -0
- package/dist/cjs/src/parsers/index.js +25 -0
- package/dist/cjs/src/schema/array.js +890 -0
- package/dist/cjs/src/schema/boolean.js +826 -0
- package/dist/cjs/src/schema/datetime.js +778 -0
- package/dist/cjs/src/schema/index.js +17 -0
- package/dist/cjs/src/schema/number.js +960 -0
- package/dist/cjs/src/schema/object.js +999 -0
- package/dist/cjs/src/schema/schema.js +1788 -0
- package/dist/cjs/src/schema/string.js +948 -0
- package/dist/cjs/src/schema/types.js +4 -0
- package/dist/cjs/src/schema/union.js +952 -0
- package/dist/cjs/src/types.js +4 -0
- package/dist/cjs/src/utils.js +627 -0
- package/dist/cjs/src/validators/array.js +457 -0
- package/dist/cjs/src/validators/boolean.js +199 -0
- package/dist/cjs/src/validators/datetime.js +287 -0
- package/dist/cjs/src/validators/number.js +403 -0
- package/dist/cjs/src/validators/object.js +290 -0
- package/dist/cjs/src/validators/schema.js +318 -0
- package/dist/cjs/src/validators/string.js +439 -0
- package/dist/cjs/src/validators/types.js +4 -0
- package/dist/cjs/src/validators/union.js +232 -0
- package/dist/cjs/src/validators/utils.js +426 -0
- package/dist/cjs/tsconfig.types.tsbuildinfo +1 -0
- package/dist/cjs/types/adapter/fields/array.d.ts +20 -0
- package/dist/cjs/types/adapter/fields/array.d.ts.map +1 -0
- package/dist/cjs/types/adapter/fields/boolean.d.ts +25 -0
- package/dist/cjs/types/adapter/fields/boolean.d.ts.map +1 -0
- package/dist/cjs/types/adapter/fields/datetime.d.ts +25 -0
- package/dist/cjs/types/adapter/fields/datetime.d.ts.map +1 -0
- package/dist/cjs/types/adapter/fields/index.d.ts +31 -0
- package/dist/cjs/types/adapter/fields/index.d.ts.map +1 -0
- package/dist/cjs/types/adapter/fields/number.d.ts +25 -0
- package/dist/cjs/types/adapter/fields/number.d.ts.map +1 -0
- package/dist/cjs/types/adapter/fields/object.d.ts +25 -0
- package/dist/cjs/types/adapter/fields/object.d.ts.map +1 -0
- package/dist/cjs/types/adapter/fields/string.d.ts +25 -0
- package/dist/cjs/types/adapter/fields/string.d.ts.map +1 -0
- package/dist/cjs/types/adapter/fields/union.d.ts +25 -0
- package/dist/cjs/types/adapter/fields/union.d.ts.map +1 -0
- package/dist/cjs/types/adapter/index.d.ts +25 -0
- package/dist/cjs/types/adapter/index.d.ts.map +1 -0
- package/dist/cjs/types/adapter/types.d.ts +144 -0
- package/dist/cjs/types/adapter/types.d.ts.map +1 -0
- package/dist/cjs/types/compile.d.ts +3 -0
- package/dist/cjs/types/compile.d.ts.map +1 -0
- package/dist/cjs/types/conf.d.ts +16 -0
- package/dist/cjs/types/conf.d.ts.map +1 -0
- package/dist/cjs/types/constants.d.ts +6 -0
- package/dist/cjs/types/constants.d.ts.map +1 -0
- package/dist/cjs/types/domain.d.ts +21 -0
- package/dist/cjs/types/domain.d.ts.map +1 -0
- package/dist/cjs/types/exceptions.d.ts +13 -0
- package/dist/cjs/types/exceptions.d.ts.map +1 -0
- package/dist/cjs/types/index.d.ts +240 -0
- package/dist/cjs/types/index.d.ts.map +1 -0
- package/dist/cjs/types/model.d.ts +136 -0
- package/dist/cjs/types/model.d.ts.map +1 -0
- package/dist/cjs/types/parsers/convert-from-number.d.ts +15 -0
- package/dist/cjs/types/parsers/convert-from-number.d.ts.map +1 -0
- package/dist/cjs/types/parsers/convert-from-string.d.ts +9 -0
- package/dist/cjs/types/parsers/convert-from-string.d.ts.map +1 -0
- package/dist/cjs/types/parsers/index.d.ts +3 -0
- package/dist/cjs/types/parsers/index.d.ts.map +1 -0
- package/dist/cjs/types/schema/array.d.ts +429 -0
- package/dist/cjs/types/schema/array.d.ts.map +1 -0
- package/dist/cjs/types/schema/boolean.d.ts +501 -0
- package/dist/cjs/types/schema/boolean.d.ts.map +1 -0
- package/dist/cjs/types/schema/datetime.d.ts +474 -0
- package/dist/cjs/types/schema/datetime.d.ts.map +1 -0
- package/dist/cjs/types/schema/index.d.ts +4 -0
- package/dist/cjs/types/schema/index.d.ts.map +1 -0
- package/dist/cjs/types/schema/number.d.ts +667 -0
- package/dist/cjs/types/schema/number.d.ts.map +1 -0
- package/dist/cjs/types/schema/object.d.ts +450 -0
- package/dist/cjs/types/schema/object.d.ts.map +1 -0
- package/dist/cjs/types/schema/schema.d.ts +646 -0
- package/dist/cjs/types/schema/schema.d.ts.map +1 -0
- package/dist/cjs/types/schema/string.d.ts +606 -0
- package/dist/cjs/types/schema/string.d.ts.map +1 -0
- package/dist/cjs/types/schema/types.d.ts +70 -0
- package/dist/cjs/types/schema/types.d.ts.map +1 -0
- package/dist/cjs/types/schema/union.d.ts +388 -0
- package/dist/cjs/types/schema/union.d.ts.map +1 -0
- package/dist/cjs/types/types.d.ts +11 -0
- package/dist/cjs/types/types.d.ts.map +1 -0
- package/dist/cjs/types/utils.d.ts +79 -0
- package/dist/cjs/types/utils.d.ts.map +1 -0
- package/dist/cjs/types/validators/array.d.ts +8 -0
- package/dist/cjs/types/validators/array.d.ts.map +1 -0
- package/dist/cjs/types/validators/boolean.d.ts +4 -0
- package/dist/cjs/types/validators/boolean.d.ts.map +1 -0
- package/dist/cjs/types/validators/datetime.d.ts +7 -0
- package/dist/cjs/types/validators/datetime.d.ts.map +1 -0
- package/dist/cjs/types/validators/number.d.ts +10 -0
- package/dist/cjs/types/validators/number.d.ts.map +1 -0
- package/dist/cjs/types/validators/object.d.ts +6 -0
- package/dist/cjs/types/validators/object.d.ts.map +1 -0
- package/dist/cjs/types/validators/schema.d.ts +10 -0
- package/dist/cjs/types/validators/schema.d.ts.map +1 -0
- package/dist/cjs/types/validators/string.d.ts +12 -0
- package/dist/cjs/types/validators/string.d.ts.map +1 -0
- package/dist/cjs/types/validators/types.d.ts +2 -0
- package/dist/cjs/types/validators/types.d.ts.map +1 -0
- package/dist/cjs/types/validators/union.d.ts +4 -0
- package/dist/cjs/types/validators/union.d.ts.map +1 -0
- package/dist/cjs/types/validators/utils.d.ts +83 -0
- package/dist/cjs/types/validators/utils.d.ts.map +1 -0
- package/dist/esm/src/adapter/fields/array.js +13 -0
- package/dist/esm/src/adapter/fields/boolean.js +20 -0
- package/dist/esm/src/adapter/fields/datetime.js +20 -0
- package/dist/esm/src/adapter/fields/index.js +37 -0
- package/dist/esm/src/adapter/fields/number.js +20 -0
- package/dist/esm/src/adapter/fields/object.js +20 -0
- package/dist/esm/src/adapter/fields/string.js +20 -0
- package/dist/esm/src/adapter/fields/union.js +20 -0
- package/dist/esm/src/adapter/index.js +18 -0
- package/dist/esm/src/adapter/types.js +1 -0
- package/dist/esm/src/compile.js +10 -0
- package/dist/esm/src/conf.js +19 -0
- package/dist/esm/src/constants.js +5 -0
- package/dist/esm/src/domain.js +2 -0
- package/dist/esm/src/exceptions.js +15 -0
- package/dist/esm/src/index.js +160 -0
- package/dist/esm/src/model.js +255 -0
- package/dist/esm/src/parsers/convert-from-number.js +8 -0
- package/dist/esm/src/parsers/convert-from-string.js +14 -0
- package/dist/esm/src/parsers/index.js +2 -0
- package/dist/esm/src/schema/array.js +403 -0
- package/dist/esm/src/schema/boolean.js +465 -0
- package/dist/esm/src/schema/datetime.js +423 -0
- package/dist/esm/src/schema/index.js +3 -0
- package/dist/esm/src/schema/number.js +592 -0
- package/dist/esm/src/schema/object.js +464 -0
- package/dist/esm/src/schema/schema.js +728 -0
- package/dist/esm/src/schema/string.js +579 -0
- package/dist/esm/src/schema/types.js +1 -0
- package/dist/esm/src/schema/union.js +388 -0
- package/dist/esm/src/types.js +1 -0
- package/dist/esm/src/utils.js +175 -0
- package/dist/esm/src/validators/array.js +135 -0
- package/dist/esm/src/validators/boolean.js +35 -0
- package/dist/esm/src/validators/datetime.js +85 -0
- package/dist/esm/src/validators/number.js +162 -0
- package/dist/esm/src/validators/object.js +38 -0
- package/dist/esm/src/validators/schema.js +114 -0
- package/dist/esm/src/validators/string.js +174 -0
- package/dist/esm/src/validators/types.js +1 -0
- package/dist/esm/src/validators/union.js +38 -0
- package/dist/esm/src/validators/utils.js +120 -0
- package/package.json +48 -0
- package/src/adapter/fields/array.ts +31 -0
- package/src/adapter/fields/boolean.ts +48 -0
- package/src/adapter/fields/datetime.ts +49 -0
- package/src/adapter/fields/index.ts +72 -0
- package/src/adapter/fields/number.ts +49 -0
- package/src/adapter/fields/object.ts +49 -0
- package/src/adapter/fields/string.ts +49 -0
- package/src/adapter/fields/union.ts +49 -0
- package/src/adapter/index.ts +34 -0
- package/src/adapter/types.ts +261 -0
- package/src/compile.ts +14 -0
- package/src/conf.ts +27 -0
- package/src/constants.ts +9 -0
- package/src/domain.ts +3 -0
- package/src/exceptions.ts +17 -0
- package/src/index.ts +338 -0
- package/src/model.ts +501 -0
- package/src/parsers/convert-from-number.ts +13 -0
- package/src/parsers/convert-from-string.ts +19 -0
- package/src/parsers/index.ts +2 -0
- package/src/schema/array.ts +633 -0
- package/src/schema/boolean.ts +700 -0
- package/src/schema/datetime.ts +613 -0
- package/src/schema/index.ts +5 -0
- package/src/schema/number.ts +885 -0
- package/src/schema/object.ts +699 -0
- package/src/schema/schema.ts +1093 -0
- package/src/schema/string.ts +807 -0
- package/src/schema/types.ts +126 -0
- package/src/schema/union.ts +596 -0
- package/src/types.ts +13 -0
- package/src/utils.ts +322 -0
- package/src/validators/array.ts +164 -0
- package/src/validators/boolean.ts +46 -0
- package/src/validators/datetime.ts +113 -0
- package/src/validators/number.ts +188 -0
- package/src/validators/object.ts +55 -0
- package/src/validators/schema.ts +134 -0
- package/src/validators/string.ts +215 -0
- package/src/validators/types.ts +1 -0
- package/src/validators/union.ts +52 -0
- package/src/validators/utils.ts +200 -0
- package/tsconfig.json +9 -0
- package/tsconfig.types.json +10 -0
@@ -0,0 +1,457 @@
|
|
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
|
+
arrayValidation: function() {
|
13
|
+
return arrayValidation;
|
14
|
+
},
|
15
|
+
maxLength: function() {
|
16
|
+
return maxLength;
|
17
|
+
},
|
18
|
+
minLength: function() {
|
19
|
+
return minLength;
|
20
|
+
},
|
21
|
+
nonEmpty: function() {
|
22
|
+
return nonEmpty;
|
23
|
+
}
|
24
|
+
});
|
25
|
+
function _array_like_to_array(arr, len) {
|
26
|
+
if (len == null || len > arr.length) len = arr.length;
|
27
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
28
|
+
return arr2;
|
29
|
+
}
|
30
|
+
function _array_without_holes(arr) {
|
31
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
32
|
+
}
|
33
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
34
|
+
try {
|
35
|
+
var info = gen[key](arg);
|
36
|
+
var value = info.value;
|
37
|
+
} catch (error) {
|
38
|
+
reject(error);
|
39
|
+
return;
|
40
|
+
}
|
41
|
+
if (info.done) {
|
42
|
+
resolve(value);
|
43
|
+
} else {
|
44
|
+
Promise.resolve(value).then(_next, _throw);
|
45
|
+
}
|
46
|
+
}
|
47
|
+
function _async_to_generator(fn) {
|
48
|
+
return function() {
|
49
|
+
var self = this, args = arguments;
|
50
|
+
return new Promise(function(resolve, reject) {
|
51
|
+
var gen = fn.apply(self, args);
|
52
|
+
function _next(value) {
|
53
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
54
|
+
}
|
55
|
+
function _throw(err) {
|
56
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
57
|
+
}
|
58
|
+
_next(undefined);
|
59
|
+
});
|
60
|
+
};
|
61
|
+
}
|
62
|
+
function _iterable_to_array(iter) {
|
63
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
64
|
+
}
|
65
|
+
function _non_iterable_spread() {
|
66
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
67
|
+
}
|
68
|
+
function _to_consumable_array(arr) {
|
69
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
70
|
+
}
|
71
|
+
function _type_of(obj) {
|
72
|
+
"@swc/helpers - typeof";
|
73
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
74
|
+
}
|
75
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
76
|
+
if (!o) return;
|
77
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
78
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
79
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
80
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
81
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
82
|
+
}
|
83
|
+
function _ts_generator(thisArg, body) {
|
84
|
+
var f, y, t, g, _ = {
|
85
|
+
label: 0,
|
86
|
+
sent: function() {
|
87
|
+
if (t[0] & 1) throw t[1];
|
88
|
+
return t[1];
|
89
|
+
},
|
90
|
+
trys: [],
|
91
|
+
ops: []
|
92
|
+
};
|
93
|
+
return g = {
|
94
|
+
next: verb(0),
|
95
|
+
"throw": verb(1),
|
96
|
+
"return": verb(2)
|
97
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
98
|
+
return this;
|
99
|
+
}), g;
|
100
|
+
function verb(n) {
|
101
|
+
return function(v) {
|
102
|
+
return step([
|
103
|
+
n,
|
104
|
+
v
|
105
|
+
]);
|
106
|
+
};
|
107
|
+
}
|
108
|
+
function step(op) {
|
109
|
+
if (f) throw new TypeError("Generator is already executing.");
|
110
|
+
while(_)try {
|
111
|
+
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;
|
112
|
+
if (y = 0, t) op = [
|
113
|
+
op[0] & 2,
|
114
|
+
t.value
|
115
|
+
];
|
116
|
+
switch(op[0]){
|
117
|
+
case 0:
|
118
|
+
case 1:
|
119
|
+
t = op;
|
120
|
+
break;
|
121
|
+
case 4:
|
122
|
+
_.label++;
|
123
|
+
return {
|
124
|
+
value: op[1],
|
125
|
+
done: false
|
126
|
+
};
|
127
|
+
case 5:
|
128
|
+
_.label++;
|
129
|
+
y = op[1];
|
130
|
+
op = [
|
131
|
+
0
|
132
|
+
];
|
133
|
+
continue;
|
134
|
+
case 7:
|
135
|
+
op = _.ops.pop();
|
136
|
+
_.trys.pop();
|
137
|
+
continue;
|
138
|
+
default:
|
139
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
140
|
+
_ = 0;
|
141
|
+
continue;
|
142
|
+
}
|
143
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
144
|
+
_.label = op[1];
|
145
|
+
break;
|
146
|
+
}
|
147
|
+
if (op[0] === 6 && _.label < t[1]) {
|
148
|
+
_.label = t[1];
|
149
|
+
t = op;
|
150
|
+
break;
|
151
|
+
}
|
152
|
+
if (t && _.label < t[2]) {
|
153
|
+
_.label = t[2];
|
154
|
+
_.ops.push(op);
|
155
|
+
break;
|
156
|
+
}
|
157
|
+
if (t[2]) _.ops.pop();
|
158
|
+
_.trys.pop();
|
159
|
+
continue;
|
160
|
+
}
|
161
|
+
op = body.call(thisArg, _);
|
162
|
+
} catch (e) {
|
163
|
+
op = [
|
164
|
+
6,
|
165
|
+
e
|
166
|
+
];
|
167
|
+
y = 0;
|
168
|
+
} finally{
|
169
|
+
f = t = 0;
|
170
|
+
}
|
171
|
+
if (op[0] & 5) throw op[1];
|
172
|
+
return {
|
173
|
+
value: op[0] ? op[1] : void 0,
|
174
|
+
done: true
|
175
|
+
};
|
176
|
+
}
|
177
|
+
}
|
178
|
+
function _ts_values(o) {
|
179
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
180
|
+
if (m) return m.call(o);
|
181
|
+
if (o && typeof o.length === "number") return {
|
182
|
+
next: function() {
|
183
|
+
if (o && i >= o.length) o = void 0;
|
184
|
+
return {
|
185
|
+
value: o && o[i++],
|
186
|
+
done: !o
|
187
|
+
};
|
188
|
+
}
|
189
|
+
};
|
190
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
191
|
+
}
|
192
|
+
function arrayValidation(isTuple, schemas) {
|
193
|
+
return {
|
194
|
+
type: 'medium',
|
195
|
+
callback: function() {
|
196
|
+
var _ref = _async_to_generator(function(value, path, options) {
|
197
|
+
var isNotAnArray, errorsOfArray, schemaIndexByTypeof, parsedValues;
|
198
|
+
return _ts_generator(this, function(_state) {
|
199
|
+
switch(_state.label){
|
200
|
+
case 0:
|
201
|
+
isNotAnArray = Array.isArray(value) === false;
|
202
|
+
if (isNotAnArray) return [
|
203
|
+
2,
|
204
|
+
{
|
205
|
+
parsed: value,
|
206
|
+
preventChildValidation: true,
|
207
|
+
errors: [
|
208
|
+
{
|
209
|
+
isValid: false,
|
210
|
+
code: 'array',
|
211
|
+
// eslint-disable-next-line ts/no-unnecessary-condition
|
212
|
+
path: path || [],
|
213
|
+
message: 'The value must be an array. Received: ' + (typeof value === "undefined" ? "undefined" : _type_of(value))
|
214
|
+
}
|
215
|
+
]
|
216
|
+
}
|
217
|
+
];
|
218
|
+
if (isTuple && value.length !== schemas.length) return [
|
219
|
+
2,
|
220
|
+
{
|
221
|
+
parsed: value,
|
222
|
+
preventChildValidation: true,
|
223
|
+
errors: [
|
224
|
+
{
|
225
|
+
isValid: false,
|
226
|
+
code: 'tuple',
|
227
|
+
// eslint-disable-next-line ts/no-unnecessary-condition
|
228
|
+
path: path || [],
|
229
|
+
message: 'The tuple must have exactly ' + schemas.length + ' elements. Received: ' + value.length
|
230
|
+
}
|
231
|
+
]
|
232
|
+
}
|
233
|
+
];
|
234
|
+
errorsOfArray = [];
|
235
|
+
// To speed things up, we can do a simple type check, if the value is of type number and number is on index 1, and on index 0 is a string,
|
236
|
+
// if the value is a number we can skip checking at index 0.
|
237
|
+
schemaIndexByTypeof = new Map();
|
238
|
+
parsedValues = [];
|
239
|
+
return [
|
240
|
+
4,
|
241
|
+
Promise.all(value.map(function() {
|
242
|
+
var _ref = _async_to_generator(function(element, index) {
|
243
|
+
var _loop, _errorsOfArray, errorsToAppendAfterLoopIfNoSchemaMatched, typeofElement, schemaIndex, existsASchemaIndex, schemasToValidateAgainst, indexOfSchema, _ret;
|
244
|
+
return _ts_generator(this, function(_state) {
|
245
|
+
switch(_state.label){
|
246
|
+
case 0:
|
247
|
+
_loop = function(indexOfSchema) {
|
248
|
+
var _errorsToAppendAfterLoopIfNoSchemaMatched, schemaToValidate, schemaWithProtected, _ref, parsed, errors;
|
249
|
+
return _ts_generator(this, function(_state) {
|
250
|
+
switch(_state.label){
|
251
|
+
case 0:
|
252
|
+
schemaToValidate = schemasToValidateAgainst[indexOfSchema];
|
253
|
+
schemaWithProtected = schemaToValidate;
|
254
|
+
return [
|
255
|
+
4,
|
256
|
+
schemaWithProtected.__parse(element, _to_consumable_array(path).concat([
|
257
|
+
index
|
258
|
+
]), options)
|
259
|
+
];
|
260
|
+
case 1:
|
261
|
+
_ref = _state.sent(), parsed = _ref.parsed, errors = _ref.errors;
|
262
|
+
if (schemaWithProtected.__toInternal && options.toInternalToBubbleUp) options.toInternalToBubbleUp.push(/*#__PURE__*/ _async_to_generator(function() {
|
263
|
+
var _schemaWithProtected___toInternal;
|
264
|
+
return _ts_generator(this, function(_state) {
|
265
|
+
switch(_state.label){
|
266
|
+
case 0:
|
267
|
+
return [
|
268
|
+
4,
|
269
|
+
(_schemaWithProtected___toInternal = schemaWithProtected.__toInternal) === null || _schemaWithProtected___toInternal === void 0 ? void 0 : _schemaWithProtected___toInternal.call(schemaWithProtected, parsed)
|
270
|
+
];
|
271
|
+
case 1:
|
272
|
+
return [
|
273
|
+
2,
|
274
|
+
parsedValues[indexOfSchema] = _state.sent()
|
275
|
+
];
|
276
|
+
}
|
277
|
+
});
|
278
|
+
}));
|
279
|
+
// eslint-disable-next-line ts/no-unnecessary-condition
|
280
|
+
if ((errors || []).length <= 0) {
|
281
|
+
errorsToAppendAfterLoopIfNoSchemaMatched = [];
|
282
|
+
schemaIndexByTypeof.set(typeofElement, indexOfSchema);
|
283
|
+
return [
|
284
|
+
2,
|
285
|
+
{
|
286
|
+
v: parsed
|
287
|
+
}
|
288
|
+
];
|
289
|
+
}
|
290
|
+
(_errorsToAppendAfterLoopIfNoSchemaMatched = errorsToAppendAfterLoopIfNoSchemaMatched).push.apply(_errorsToAppendAfterLoopIfNoSchemaMatched, _to_consumable_array(errors));
|
291
|
+
return [
|
292
|
+
2
|
293
|
+
];
|
294
|
+
}
|
295
|
+
});
|
296
|
+
};
|
297
|
+
errorsToAppendAfterLoopIfNoSchemaMatched = [];
|
298
|
+
typeofElement = typeof element === "undefined" ? "undefined" : _type_of(element);
|
299
|
+
schemaIndex = schemaIndexByTypeof.get(typeofElement);
|
300
|
+
existsASchemaIndex = typeof schemaIndex === 'number';
|
301
|
+
schemasToValidateAgainst = isTuple ? [
|
302
|
+
schemas[index]
|
303
|
+
] : existsASchemaIndex ? [
|
304
|
+
schemas[schemaIndex]
|
305
|
+
] : schemas;
|
306
|
+
indexOfSchema = 0;
|
307
|
+
_state.label = 1;
|
308
|
+
case 1:
|
309
|
+
if (!(indexOfSchema < schemasToValidateAgainst.length)) return [
|
310
|
+
3,
|
311
|
+
4
|
312
|
+
];
|
313
|
+
return [
|
314
|
+
5,
|
315
|
+
_ts_values(_loop(indexOfSchema))
|
316
|
+
];
|
317
|
+
case 2:
|
318
|
+
_ret = _state.sent();
|
319
|
+
if (_type_of(_ret) === "object") return [
|
320
|
+
2,
|
321
|
+
_ret.v
|
322
|
+
];
|
323
|
+
_state.label = 3;
|
324
|
+
case 3:
|
325
|
+
indexOfSchema++;
|
326
|
+
return [
|
327
|
+
3,
|
328
|
+
1
|
329
|
+
];
|
330
|
+
case 4:
|
331
|
+
(_errorsOfArray = errorsOfArray).push.apply(_errorsOfArray, _to_consumable_array(errorsToAppendAfterLoopIfNoSchemaMatched));
|
332
|
+
return [
|
333
|
+
2,
|
334
|
+
element
|
335
|
+
];
|
336
|
+
}
|
337
|
+
});
|
338
|
+
});
|
339
|
+
return function(element, index) {
|
340
|
+
return _ref.apply(this, arguments);
|
341
|
+
};
|
342
|
+
}()))
|
343
|
+
];
|
344
|
+
case 1:
|
345
|
+
parsedValues = _state.sent();
|
346
|
+
return [
|
347
|
+
2,
|
348
|
+
{
|
349
|
+
parsed: parsedValues,
|
350
|
+
errors: errorsOfArray
|
351
|
+
}
|
352
|
+
];
|
353
|
+
}
|
354
|
+
});
|
355
|
+
});
|
356
|
+
return function(value, path, options) {
|
357
|
+
return _ref.apply(this, arguments);
|
358
|
+
};
|
359
|
+
}()
|
360
|
+
};
|
361
|
+
}
|
362
|
+
function minLength(args) {
|
363
|
+
return {
|
364
|
+
type: 'low',
|
365
|
+
// eslint-disable-next-line ts/require-await
|
366
|
+
callback: function() {
|
367
|
+
var _ref = _async_to_generator(function(value, path, _options) {
|
368
|
+
var isValid;
|
369
|
+
return _ts_generator(this, function(_state) {
|
370
|
+
isValid = args.inclusive ? value.length >= args.value : value.length > args.value;
|
371
|
+
return [
|
372
|
+
2,
|
373
|
+
{
|
374
|
+
parsed: value,
|
375
|
+
errors: isValid ? [] : [
|
376
|
+
{
|
377
|
+
isValid: false,
|
378
|
+
code: 'minLength',
|
379
|
+
// eslint-disable-next-line ts/no-unnecessary-condition
|
380
|
+
path: path || [],
|
381
|
+
message: args.message
|
382
|
+
}
|
383
|
+
]
|
384
|
+
}
|
385
|
+
];
|
386
|
+
});
|
387
|
+
});
|
388
|
+
return function(value, path, _options) {
|
389
|
+
return _ref.apply(this, arguments);
|
390
|
+
};
|
391
|
+
}()
|
392
|
+
};
|
393
|
+
}
|
394
|
+
function maxLength(args) {
|
395
|
+
return {
|
396
|
+
type: 'low',
|
397
|
+
// eslint-disable-next-line ts/require-await
|
398
|
+
callback: function() {
|
399
|
+
var _ref = _async_to_generator(function(value, path, _options) {
|
400
|
+
var isValid;
|
401
|
+
return _ts_generator(this, function(_state) {
|
402
|
+
isValid = args.inclusive ? value.length <= args.value : value.length < args.value;
|
403
|
+
return [
|
404
|
+
2,
|
405
|
+
{
|
406
|
+
parsed: value,
|
407
|
+
errors: isValid ? [] : [
|
408
|
+
{
|
409
|
+
isValid: false,
|
410
|
+
code: 'maxLength',
|
411
|
+
// eslint-disable-next-line ts/no-unnecessary-condition
|
412
|
+
path: path || [],
|
413
|
+
message: args.message
|
414
|
+
}
|
415
|
+
]
|
416
|
+
}
|
417
|
+
];
|
418
|
+
});
|
419
|
+
});
|
420
|
+
return function(value, path, _options) {
|
421
|
+
return _ref.apply(this, arguments);
|
422
|
+
};
|
423
|
+
}()
|
424
|
+
};
|
425
|
+
}
|
426
|
+
function nonEmpty(args) {
|
427
|
+
return {
|
428
|
+
type: 'low',
|
429
|
+
// eslint-disable-next-line ts/require-await
|
430
|
+
callback: function() {
|
431
|
+
var _ref = _async_to_generator(function(value, path, _options) {
|
432
|
+
var isValid;
|
433
|
+
return _ts_generator(this, function(_state) {
|
434
|
+
isValid = value.length > 0;
|
435
|
+
return [
|
436
|
+
2,
|
437
|
+
{
|
438
|
+
parsed: value,
|
439
|
+
errors: isValid ? [] : [
|
440
|
+
{
|
441
|
+
isValid: false,
|
442
|
+
code: 'nonEmpty',
|
443
|
+
// eslint-disable-next-line ts/no-unnecessary-condition
|
444
|
+
path: path || [],
|
445
|
+
message: args.message
|
446
|
+
}
|
447
|
+
]
|
448
|
+
}
|
449
|
+
];
|
450
|
+
});
|
451
|
+
});
|
452
|
+
return function(value, path, _options) {
|
453
|
+
return _ref.apply(this, arguments);
|
454
|
+
};
|
455
|
+
}()
|
456
|
+
};
|
457
|
+
}
|
@@ -0,0 +1,199 @@
|
|
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
|
+
allowStringParser: function() {
|
13
|
+
return allowStringParser;
|
14
|
+
},
|
15
|
+
booleanValidation: function() {
|
16
|
+
return booleanValidation;
|
17
|
+
}
|
18
|
+
});
|
19
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
20
|
+
try {
|
21
|
+
var info = gen[key](arg);
|
22
|
+
var value = info.value;
|
23
|
+
} catch (error) {
|
24
|
+
reject(error);
|
25
|
+
return;
|
26
|
+
}
|
27
|
+
if (info.done) {
|
28
|
+
resolve(value);
|
29
|
+
} else {
|
30
|
+
Promise.resolve(value).then(_next, _throw);
|
31
|
+
}
|
32
|
+
}
|
33
|
+
function _async_to_generator(fn) {
|
34
|
+
return function() {
|
35
|
+
var self = this, args = arguments;
|
36
|
+
return new Promise(function(resolve, reject) {
|
37
|
+
var gen = fn.apply(self, args);
|
38
|
+
function _next(value) {
|
39
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
40
|
+
}
|
41
|
+
function _throw(err) {
|
42
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
43
|
+
}
|
44
|
+
_next(undefined);
|
45
|
+
});
|
46
|
+
};
|
47
|
+
}
|
48
|
+
function _ts_generator(thisArg, body) {
|
49
|
+
var f, y, t, g, _ = {
|
50
|
+
label: 0,
|
51
|
+
sent: function() {
|
52
|
+
if (t[0] & 1) throw t[1];
|
53
|
+
return t[1];
|
54
|
+
},
|
55
|
+
trys: [],
|
56
|
+
ops: []
|
57
|
+
};
|
58
|
+
return g = {
|
59
|
+
next: verb(0),
|
60
|
+
"throw": verb(1),
|
61
|
+
"return": verb(2)
|
62
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
63
|
+
return this;
|
64
|
+
}), g;
|
65
|
+
function verb(n) {
|
66
|
+
return function(v) {
|
67
|
+
return step([
|
68
|
+
n,
|
69
|
+
v
|
70
|
+
]);
|
71
|
+
};
|
72
|
+
}
|
73
|
+
function step(op) {
|
74
|
+
if (f) throw new TypeError("Generator is already executing.");
|
75
|
+
while(_)try {
|
76
|
+
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;
|
77
|
+
if (y = 0, t) op = [
|
78
|
+
op[0] & 2,
|
79
|
+
t.value
|
80
|
+
];
|
81
|
+
switch(op[0]){
|
82
|
+
case 0:
|
83
|
+
case 1:
|
84
|
+
t = op;
|
85
|
+
break;
|
86
|
+
case 4:
|
87
|
+
_.label++;
|
88
|
+
return {
|
89
|
+
value: op[1],
|
90
|
+
done: false
|
91
|
+
};
|
92
|
+
case 5:
|
93
|
+
_.label++;
|
94
|
+
y = op[1];
|
95
|
+
op = [
|
96
|
+
0
|
97
|
+
];
|
98
|
+
continue;
|
99
|
+
case 7:
|
100
|
+
op = _.ops.pop();
|
101
|
+
_.trys.pop();
|
102
|
+
continue;
|
103
|
+
default:
|
104
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
105
|
+
_ = 0;
|
106
|
+
continue;
|
107
|
+
}
|
108
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
109
|
+
_.label = op[1];
|
110
|
+
break;
|
111
|
+
}
|
112
|
+
if (op[0] === 6 && _.label < t[1]) {
|
113
|
+
_.label = t[1];
|
114
|
+
t = op;
|
115
|
+
break;
|
116
|
+
}
|
117
|
+
if (t && _.label < t[2]) {
|
118
|
+
_.label = t[2];
|
119
|
+
_.ops.push(op);
|
120
|
+
break;
|
121
|
+
}
|
122
|
+
if (t[2]) _.ops.pop();
|
123
|
+
_.trys.pop();
|
124
|
+
continue;
|
125
|
+
}
|
126
|
+
op = body.call(thisArg, _);
|
127
|
+
} catch (e) {
|
128
|
+
op = [
|
129
|
+
6,
|
130
|
+
e
|
131
|
+
];
|
132
|
+
y = 0;
|
133
|
+
} finally{
|
134
|
+
f = t = 0;
|
135
|
+
}
|
136
|
+
if (op[0] & 5) throw op[1];
|
137
|
+
return {
|
138
|
+
value: op[0] ? op[1] : void 0,
|
139
|
+
done: true
|
140
|
+
};
|
141
|
+
}
|
142
|
+
}
|
143
|
+
function booleanValidation() {
|
144
|
+
return {
|
145
|
+
type: 'medium',
|
146
|
+
// eslint-disable-next-line ts/require-await
|
147
|
+
callback: function() {
|
148
|
+
var _ref = _async_to_generator(function(value, path, _options) {
|
149
|
+
var isValid;
|
150
|
+
return _ts_generator(this, function(_state) {
|
151
|
+
isValid = typeof value === 'boolean';
|
152
|
+
return [
|
153
|
+
2,
|
154
|
+
{
|
155
|
+
parsed: value,
|
156
|
+
errors: isValid ? [] : [
|
157
|
+
{
|
158
|
+
isValid: false,
|
159
|
+
code: 'boolean',
|
160
|
+
// eslint-disable-next-line ts/no-unnecessary-condition
|
161
|
+
path: path || [],
|
162
|
+
message: 'Value is not a boolean'
|
163
|
+
}
|
164
|
+
],
|
165
|
+
preventChildValidation: true
|
166
|
+
}
|
167
|
+
];
|
168
|
+
});
|
169
|
+
});
|
170
|
+
return function(value, path, _options) {
|
171
|
+
return _ref.apply(this, arguments);
|
172
|
+
};
|
173
|
+
}()
|
174
|
+
};
|
175
|
+
}
|
176
|
+
function allowStringParser() {
|
177
|
+
return {
|
178
|
+
type: 'high',
|
179
|
+
// eslint-disable-next-line ts/require-await
|
180
|
+
callback: function() {
|
181
|
+
var _ref = _async_to_generator(function(value, _path, _options) {
|
182
|
+
var parsed;
|
183
|
+
return _ts_generator(this, function(_state) {
|
184
|
+
parsed = Boolean(value);
|
185
|
+
return [
|
186
|
+
2,
|
187
|
+
{
|
188
|
+
parsed: parsed,
|
189
|
+
errors: []
|
190
|
+
}
|
191
|
+
];
|
192
|
+
});
|
193
|
+
});
|
194
|
+
return function(value, _path, _options) {
|
195
|
+
return _ref.apply(this, arguments);
|
196
|
+
};
|
197
|
+
}()
|
198
|
+
};
|
199
|
+
}
|