@apps-in-toss/web-framework 1.2.0 → 1.2.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/dist/cli/chunk-AZQN2M6D.js +63 -0
- package/dist/cli/chunk-PT6B3KQJ.js +209904 -0
- package/dist/cli/lib-GNFDOQZX.js +1007 -0
- package/dist/cli/typescript-WPGJO2BO.js +6 -0
- package/dist/prebuilt/dev.android.js +601 -536
- package/dist/prebuilt/dev.ios.js +599 -534
- package/dist/prebuilt/prod.android.js +337 -433
- package/dist/prebuilt/prod.ios.js +337 -433
- package/dist/prebuilt/prod.json +14 -0
- package/package.json +8 -8
|
@@ -0,0 +1,1007 @@
|
|
|
1
|
+
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
__commonJS,
|
|
4
|
+
init_esm_shims
|
|
5
|
+
} from "./chunk-AZQN2M6D.js";
|
|
6
|
+
|
|
7
|
+
// ../../.yarn/cache/typanion-npm-3.14.0-0a46072207-8b03b19844.zip/node_modules/typanion/lib/index.js
|
|
8
|
+
var require_lib = __commonJS({
|
|
9
|
+
"../../.yarn/cache/typanion-npm-3.14.0-0a46072207-8b03b19844.zip/node_modules/typanion/lib/index.js"(exports) {
|
|
10
|
+
init_esm_shims();
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
var simpleKeyRegExp = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
|
13
|
+
function getPrintable(value) {
|
|
14
|
+
if (value === null)
|
|
15
|
+
return `null`;
|
|
16
|
+
if (value === void 0)
|
|
17
|
+
return `undefined`;
|
|
18
|
+
if (value === ``)
|
|
19
|
+
return `an empty string`;
|
|
20
|
+
if (typeof value === "symbol")
|
|
21
|
+
return `<${value.toString()}>`;
|
|
22
|
+
if (Array.isArray(value))
|
|
23
|
+
return `an array`;
|
|
24
|
+
return JSON.stringify(value);
|
|
25
|
+
}
|
|
26
|
+
function getPrintableArray(value, conjunction) {
|
|
27
|
+
if (value.length === 0)
|
|
28
|
+
return `nothing`;
|
|
29
|
+
if (value.length === 1)
|
|
30
|
+
return getPrintable(value[0]);
|
|
31
|
+
const rest = value.slice(0, -1);
|
|
32
|
+
const trailing = value[value.length - 1];
|
|
33
|
+
const separator = value.length > 2 ? `, ${conjunction} ` : ` ${conjunction} `;
|
|
34
|
+
return `${rest.map((value2) => getPrintable(value2)).join(`, `)}${separator}${getPrintable(trailing)}`;
|
|
35
|
+
}
|
|
36
|
+
function computeKey(state, key) {
|
|
37
|
+
var _a, _b, _c;
|
|
38
|
+
if (typeof key === `number`) {
|
|
39
|
+
return `${(_a = state === null || state === void 0 ? void 0 : state.p) !== null && _a !== void 0 ? _a : `.`}[${key}]`;
|
|
40
|
+
} else if (simpleKeyRegExp.test(key)) {
|
|
41
|
+
return `${(_b = state === null || state === void 0 ? void 0 : state.p) !== null && _b !== void 0 ? _b : ``}.${key}`;
|
|
42
|
+
} else {
|
|
43
|
+
return `${(_c = state === null || state === void 0 ? void 0 : state.p) !== null && _c !== void 0 ? _c : `.`}[${JSON.stringify(key)}]`;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function plural(n, singular, plural2) {
|
|
47
|
+
return n === 1 ? singular : plural2;
|
|
48
|
+
}
|
|
49
|
+
var colorStringRegExp = /^#[0-9a-f]{6}$/i;
|
|
50
|
+
var colorStringAlphaRegExp = /^#[0-9a-f]{6}([0-9a-f]{2})?$/i;
|
|
51
|
+
var base64RegExp = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
|
|
52
|
+
var uuid4RegExp = /^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}$/i;
|
|
53
|
+
var iso8601RegExp = /^(?:[1-9]\d{3}(-?)(?:(?:0[1-9]|1[0-2])\1(?:0[1-9]|1\d|2[0-8])|(?:0[13-9]|1[0-2])\1(?:29|30)|(?:0[13578]|1[02])(?:\1)31|00[1-9]|0[1-9]\d|[12]\d{2}|3(?:[0-5]\d|6[0-5]))|(?:[1-9]\d(?:0[48]|[2468][048]|[13579][26])|(?:[2468][048]|[13579][26])00)(?:(-?)02(?:\2)29|-?366))T(?:[01]\d|2[0-3])(:?)[0-5]\d(?:\3[0-5]\d)?(?:Z|[+-][01]\d(?:\3[0-5]\d)?)$/;
|
|
54
|
+
function pushError({ errors, p } = {}, message) {
|
|
55
|
+
errors === null || errors === void 0 ? void 0 : errors.push(`${p !== null && p !== void 0 ? p : `.`}: ${message}`);
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
function makeSetter(target, key) {
|
|
59
|
+
return (v) => {
|
|
60
|
+
target[key] = v;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function makeCoercionFn(target, key) {
|
|
64
|
+
return (v) => {
|
|
65
|
+
const previous = target[key];
|
|
66
|
+
target[key] = v;
|
|
67
|
+
return makeCoercionFn(target, key).bind(null, previous);
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function makeLazyCoercionFn(fn2, orig, generator) {
|
|
71
|
+
const commit = () => {
|
|
72
|
+
fn2(generator());
|
|
73
|
+
return revert;
|
|
74
|
+
};
|
|
75
|
+
const revert = () => {
|
|
76
|
+
fn2(orig);
|
|
77
|
+
return commit;
|
|
78
|
+
};
|
|
79
|
+
return commit;
|
|
80
|
+
}
|
|
81
|
+
function isUnknown() {
|
|
82
|
+
return makeValidator({
|
|
83
|
+
test: (value, state) => {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
function isLiteral(expected) {
|
|
89
|
+
return makeValidator({
|
|
90
|
+
test: (value, state) => {
|
|
91
|
+
if (value !== expected)
|
|
92
|
+
return pushError(state, `Expected ${getPrintable(expected)} (got ${getPrintable(value)})`);
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
function isString() {
|
|
98
|
+
return makeValidator({
|
|
99
|
+
test: (value, state) => {
|
|
100
|
+
if (typeof value !== `string`)
|
|
101
|
+
return pushError(state, `Expected a string (got ${getPrintable(value)})`);
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
function isEnum(enumSpec) {
|
|
107
|
+
const valuesArray = Array.isArray(enumSpec) ? enumSpec : Object.values(enumSpec);
|
|
108
|
+
const isAlphaNum = valuesArray.every((item) => typeof item === "string" || typeof item === "number");
|
|
109
|
+
const values = new Set(valuesArray);
|
|
110
|
+
if (values.size === 1)
|
|
111
|
+
return isLiteral([...values][0]);
|
|
112
|
+
return makeValidator({
|
|
113
|
+
test: (value, state) => {
|
|
114
|
+
if (!values.has(value)) {
|
|
115
|
+
if (isAlphaNum) {
|
|
116
|
+
return pushError(state, `Expected one of ${getPrintableArray(valuesArray, `or`)} (got ${getPrintable(value)})`);
|
|
117
|
+
} else {
|
|
118
|
+
return pushError(state, `Expected a valid enumeration value (got ${getPrintable(value)})`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
var BOOLEAN_COERCIONS = /* @__PURE__ */ new Map([
|
|
126
|
+
[`true`, true],
|
|
127
|
+
[`True`, true],
|
|
128
|
+
[`1`, true],
|
|
129
|
+
[1, true],
|
|
130
|
+
[`false`, false],
|
|
131
|
+
[`False`, false],
|
|
132
|
+
[`0`, false],
|
|
133
|
+
[0, false]
|
|
134
|
+
]);
|
|
135
|
+
function isBoolean() {
|
|
136
|
+
return makeValidator({
|
|
137
|
+
test: (value, state) => {
|
|
138
|
+
var _a;
|
|
139
|
+
if (typeof value !== `boolean`) {
|
|
140
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
|
|
141
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`)
|
|
142
|
+
return pushError(state, `Unbound coercion result`);
|
|
143
|
+
const coercion = BOOLEAN_COERCIONS.get(value);
|
|
144
|
+
if (typeof coercion !== `undefined`) {
|
|
145
|
+
state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, state.coercion.bind(null, coercion)]);
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return pushError(state, `Expected a boolean (got ${getPrintable(value)})`);
|
|
150
|
+
}
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
function isNumber() {
|
|
156
|
+
return makeValidator({
|
|
157
|
+
test: (value, state) => {
|
|
158
|
+
var _a;
|
|
159
|
+
if (typeof value !== `number`) {
|
|
160
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
|
|
161
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`)
|
|
162
|
+
return pushError(state, `Unbound coercion result`);
|
|
163
|
+
let coercion;
|
|
164
|
+
if (typeof value === `string`) {
|
|
165
|
+
let val;
|
|
166
|
+
try {
|
|
167
|
+
val = JSON.parse(value);
|
|
168
|
+
} catch (_b) {
|
|
169
|
+
}
|
|
170
|
+
if (typeof val === `number`) {
|
|
171
|
+
if (JSON.stringify(val) === value) {
|
|
172
|
+
coercion = val;
|
|
173
|
+
} else {
|
|
174
|
+
return pushError(state, `Received a number that can't be safely represented by the runtime (${value})`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (typeof coercion !== `undefined`) {
|
|
179
|
+
state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, state.coercion.bind(null, coercion)]);
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return pushError(state, `Expected a number (got ${getPrintable(value)})`);
|
|
184
|
+
}
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
function isPayload(spec) {
|
|
190
|
+
return makeValidator({
|
|
191
|
+
test: (value, state) => {
|
|
192
|
+
var _a;
|
|
193
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercions) === `undefined`)
|
|
194
|
+
return pushError(state, `The isPayload predicate can only be used with coercion enabled`);
|
|
195
|
+
if (typeof state.coercion === `undefined`)
|
|
196
|
+
return pushError(state, `Unbound coercion result`);
|
|
197
|
+
if (typeof value !== `string`)
|
|
198
|
+
return pushError(state, `Expected a string (got ${getPrintable(value)})`);
|
|
199
|
+
let inner;
|
|
200
|
+
try {
|
|
201
|
+
inner = JSON.parse(value);
|
|
202
|
+
} catch (_b) {
|
|
203
|
+
return pushError(state, `Expected a JSON string (got ${getPrintable(value)})`);
|
|
204
|
+
}
|
|
205
|
+
const wrapper = { value: inner };
|
|
206
|
+
if (!spec(inner, Object.assign(Object.assign({}, state), { coercion: makeCoercionFn(wrapper, `value`) })))
|
|
207
|
+
return false;
|
|
208
|
+
state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, state.coercion.bind(null, wrapper.value)]);
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
function isDate() {
|
|
214
|
+
return makeValidator({
|
|
215
|
+
test: (value, state) => {
|
|
216
|
+
var _a;
|
|
217
|
+
if (!(value instanceof Date)) {
|
|
218
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
|
|
219
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`)
|
|
220
|
+
return pushError(state, `Unbound coercion result`);
|
|
221
|
+
let coercion;
|
|
222
|
+
if (typeof value === `string` && iso8601RegExp.test(value)) {
|
|
223
|
+
coercion = new Date(value);
|
|
224
|
+
} else {
|
|
225
|
+
let timestamp;
|
|
226
|
+
if (typeof value === `string`) {
|
|
227
|
+
let val;
|
|
228
|
+
try {
|
|
229
|
+
val = JSON.parse(value);
|
|
230
|
+
} catch (_b) {
|
|
231
|
+
}
|
|
232
|
+
if (typeof val === `number`) {
|
|
233
|
+
timestamp = val;
|
|
234
|
+
}
|
|
235
|
+
} else if (typeof value === `number`) {
|
|
236
|
+
timestamp = value;
|
|
237
|
+
}
|
|
238
|
+
if (typeof timestamp !== `undefined`) {
|
|
239
|
+
if (Number.isSafeInteger(timestamp) || !Number.isSafeInteger(timestamp * 1e3)) {
|
|
240
|
+
coercion = new Date(timestamp * 1e3);
|
|
241
|
+
} else {
|
|
242
|
+
return pushError(state, `Received a timestamp that can't be safely represented by the runtime (${value})`);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
if (typeof coercion !== `undefined`) {
|
|
247
|
+
state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, state.coercion.bind(null, coercion)]);
|
|
248
|
+
return true;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return pushError(state, `Expected a date (got ${getPrintable(value)})`);
|
|
252
|
+
}
|
|
253
|
+
return true;
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
function isArray(spec, { delimiter } = {}) {
|
|
258
|
+
return makeValidator({
|
|
259
|
+
test: (value, state) => {
|
|
260
|
+
var _a;
|
|
261
|
+
const originalValue = value;
|
|
262
|
+
if (typeof value === `string` && typeof delimiter !== `undefined`) {
|
|
263
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
|
|
264
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`)
|
|
265
|
+
return pushError(state, `Unbound coercion result`);
|
|
266
|
+
value = value.split(delimiter);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
if (!Array.isArray(value))
|
|
270
|
+
return pushError(state, `Expected an array (got ${getPrintable(value)})`);
|
|
271
|
+
let valid = true;
|
|
272
|
+
for (let t = 0, T = value.length; t < T; ++t) {
|
|
273
|
+
valid = spec(value[t], Object.assign(Object.assign({}, state), { p: computeKey(state, t), coercion: makeCoercionFn(value, t) })) && valid;
|
|
274
|
+
if (!valid && (state === null || state === void 0 ? void 0 : state.errors) == null) {
|
|
275
|
+
break;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
if (value !== originalValue)
|
|
279
|
+
state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, state.coercion.bind(null, value)]);
|
|
280
|
+
return valid;
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
function isSet(spec, { delimiter } = {}) {
|
|
285
|
+
const isArrayValidator = isArray(spec, { delimiter });
|
|
286
|
+
return makeValidator({
|
|
287
|
+
test: (value, state) => {
|
|
288
|
+
var _a, _b;
|
|
289
|
+
if (Object.getPrototypeOf(value).toString() === `[object Set]`) {
|
|
290
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
|
|
291
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`)
|
|
292
|
+
return pushError(state, `Unbound coercion result`);
|
|
293
|
+
const originalValues = [...value];
|
|
294
|
+
const coercedValues = [...value];
|
|
295
|
+
if (!isArrayValidator(coercedValues, Object.assign(Object.assign({}, state), { coercion: void 0 })))
|
|
296
|
+
return false;
|
|
297
|
+
const updateValue = () => coercedValues.some((val, t) => val !== originalValues[t]) ? new Set(coercedValues) : value;
|
|
298
|
+
state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, makeLazyCoercionFn(state.coercion, value, updateValue)]);
|
|
299
|
+
return true;
|
|
300
|
+
} else {
|
|
301
|
+
let valid = true;
|
|
302
|
+
for (const subValue of value) {
|
|
303
|
+
valid = spec(subValue, Object.assign({}, state)) && valid;
|
|
304
|
+
if (!valid && (state === null || state === void 0 ? void 0 : state.errors) == null) {
|
|
305
|
+
break;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
return valid;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
|
|
312
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`)
|
|
313
|
+
return pushError(state, `Unbound coercion result`);
|
|
314
|
+
const store = { value };
|
|
315
|
+
if (!isArrayValidator(value, Object.assign(Object.assign({}, state), { coercion: makeCoercionFn(store, `value`) })))
|
|
316
|
+
return false;
|
|
317
|
+
state.coercions.push([(_b = state.p) !== null && _b !== void 0 ? _b : `.`, makeLazyCoercionFn(state.coercion, value, () => new Set(store.value))]);
|
|
318
|
+
return true;
|
|
319
|
+
}
|
|
320
|
+
return pushError(state, `Expected a set (got ${getPrintable(value)})`);
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
function isMap(keySpec, valueSpec) {
|
|
325
|
+
const isArrayValidator = isArray(isTuple([keySpec, valueSpec]));
|
|
326
|
+
const isRecordValidator = isRecord(valueSpec, { keys: keySpec });
|
|
327
|
+
return makeValidator({
|
|
328
|
+
test: (value, state) => {
|
|
329
|
+
var _a, _b, _c;
|
|
330
|
+
if (Object.getPrototypeOf(value).toString() === `[object Map]`) {
|
|
331
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
|
|
332
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`)
|
|
333
|
+
return pushError(state, `Unbound coercion result`);
|
|
334
|
+
const originalValues = [...value];
|
|
335
|
+
const coercedValues = [...value];
|
|
336
|
+
if (!isArrayValidator(coercedValues, Object.assign(Object.assign({}, state), { coercion: void 0 })))
|
|
337
|
+
return false;
|
|
338
|
+
const updateValue = () => coercedValues.some((val, t) => val[0] !== originalValues[t][0] || val[1] !== originalValues[t][1]) ? new Map(coercedValues) : value;
|
|
339
|
+
state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, makeLazyCoercionFn(state.coercion, value, updateValue)]);
|
|
340
|
+
return true;
|
|
341
|
+
} else {
|
|
342
|
+
let valid = true;
|
|
343
|
+
for (const [key, subValue] of value) {
|
|
344
|
+
valid = keySpec(key, Object.assign({}, state)) && valid;
|
|
345
|
+
if (!valid && (state === null || state === void 0 ? void 0 : state.errors) == null) {
|
|
346
|
+
break;
|
|
347
|
+
}
|
|
348
|
+
valid = valueSpec(subValue, Object.assign(Object.assign({}, state), { p: computeKey(state, key) })) && valid;
|
|
349
|
+
if (!valid && (state === null || state === void 0 ? void 0 : state.errors) == null) {
|
|
350
|
+
break;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
return valid;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
|
|
357
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`)
|
|
358
|
+
return pushError(state, `Unbound coercion result`);
|
|
359
|
+
const store = { value };
|
|
360
|
+
if (Array.isArray(value)) {
|
|
361
|
+
if (!isArrayValidator(value, Object.assign(Object.assign({}, state), { coercion: void 0 })))
|
|
362
|
+
return false;
|
|
363
|
+
state.coercions.push([(_b = state.p) !== null && _b !== void 0 ? _b : `.`, makeLazyCoercionFn(state.coercion, value, () => new Map(store.value))]);
|
|
364
|
+
return true;
|
|
365
|
+
} else {
|
|
366
|
+
if (!isRecordValidator(value, Object.assign(Object.assign({}, state), { coercion: makeCoercionFn(store, `value`) })))
|
|
367
|
+
return false;
|
|
368
|
+
state.coercions.push([(_c = state.p) !== null && _c !== void 0 ? _c : `.`, makeLazyCoercionFn(state.coercion, value, () => new Map(Object.entries(store.value)))]);
|
|
369
|
+
return true;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
return pushError(state, `Expected a map (got ${getPrintable(value)})`);
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
function isTuple(spec, { delimiter } = {}) {
|
|
377
|
+
const lengthValidator = hasExactLength(spec.length);
|
|
378
|
+
return makeValidator({
|
|
379
|
+
test: (value, state) => {
|
|
380
|
+
var _a;
|
|
381
|
+
if (typeof value === `string` && typeof delimiter !== `undefined`) {
|
|
382
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
|
|
383
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`)
|
|
384
|
+
return pushError(state, `Unbound coercion result`);
|
|
385
|
+
value = value.split(delimiter);
|
|
386
|
+
state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, state.coercion.bind(null, value)]);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
if (!Array.isArray(value))
|
|
390
|
+
return pushError(state, `Expected a tuple (got ${getPrintable(value)})`);
|
|
391
|
+
let valid = lengthValidator(value, Object.assign({}, state));
|
|
392
|
+
for (let t = 0, T = value.length; t < T && t < spec.length; ++t) {
|
|
393
|
+
valid = spec[t](value[t], Object.assign(Object.assign({}, state), { p: computeKey(state, t), coercion: makeCoercionFn(value, t) })) && valid;
|
|
394
|
+
if (!valid && (state === null || state === void 0 ? void 0 : state.errors) == null) {
|
|
395
|
+
break;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
return valid;
|
|
399
|
+
}
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
function isRecord(spec, { keys: keySpec = null } = {}) {
|
|
403
|
+
const isArrayValidator = isArray(isTuple([keySpec !== null && keySpec !== void 0 ? keySpec : isString(), spec]));
|
|
404
|
+
return makeValidator({
|
|
405
|
+
test: (value, state) => {
|
|
406
|
+
var _a;
|
|
407
|
+
if (Array.isArray(value)) {
|
|
408
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
|
|
409
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`)
|
|
410
|
+
return pushError(state, `Unbound coercion result`);
|
|
411
|
+
if (!isArrayValidator(value, Object.assign(Object.assign({}, state), { coercion: void 0 })))
|
|
412
|
+
return false;
|
|
413
|
+
value = Object.fromEntries(value);
|
|
414
|
+
state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, state.coercion.bind(null, value)]);
|
|
415
|
+
return true;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
if (typeof value !== `object` || value === null)
|
|
419
|
+
return pushError(state, `Expected an object (got ${getPrintable(value)})`);
|
|
420
|
+
const keys = Object.keys(value);
|
|
421
|
+
let valid = true;
|
|
422
|
+
for (let t = 0, T = keys.length; t < T && (valid || (state === null || state === void 0 ? void 0 : state.errors) != null); ++t) {
|
|
423
|
+
const key = keys[t];
|
|
424
|
+
const sub = value[key];
|
|
425
|
+
if (key === `__proto__` || key === `constructor`) {
|
|
426
|
+
valid = pushError(Object.assign(Object.assign({}, state), { p: computeKey(state, key) }), `Unsafe property name`);
|
|
427
|
+
continue;
|
|
428
|
+
}
|
|
429
|
+
if (keySpec !== null && !keySpec(key, state)) {
|
|
430
|
+
valid = false;
|
|
431
|
+
continue;
|
|
432
|
+
}
|
|
433
|
+
if (!spec(sub, Object.assign(Object.assign({}, state), { p: computeKey(state, key), coercion: makeCoercionFn(value, key) }))) {
|
|
434
|
+
valid = false;
|
|
435
|
+
continue;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
return valid;
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
function isDict(spec, opts = {}) {
|
|
443
|
+
return isRecord(spec, opts);
|
|
444
|
+
}
|
|
445
|
+
function isObject(props, { extra: extraSpec = null } = {}) {
|
|
446
|
+
const specKeys = Object.keys(props);
|
|
447
|
+
const validator = makeValidator({
|
|
448
|
+
test: (value, state) => {
|
|
449
|
+
if (typeof value !== `object` || value === null)
|
|
450
|
+
return pushError(state, `Expected an object (got ${getPrintable(value)})`);
|
|
451
|
+
const keys = /* @__PURE__ */ new Set([...specKeys, ...Object.keys(value)]);
|
|
452
|
+
const extra = {};
|
|
453
|
+
let valid = true;
|
|
454
|
+
for (const key of keys) {
|
|
455
|
+
if (key === `constructor` || key === `__proto__`) {
|
|
456
|
+
valid = pushError(Object.assign(Object.assign({}, state), { p: computeKey(state, key) }), `Unsafe property name`);
|
|
457
|
+
} else {
|
|
458
|
+
const spec = Object.prototype.hasOwnProperty.call(props, key) ? props[key] : void 0;
|
|
459
|
+
const sub = Object.prototype.hasOwnProperty.call(value, key) ? value[key] : void 0;
|
|
460
|
+
if (typeof spec !== `undefined`) {
|
|
461
|
+
valid = spec(sub, Object.assign(Object.assign({}, state), { p: computeKey(state, key), coercion: makeCoercionFn(value, key) })) && valid;
|
|
462
|
+
} else if (extraSpec === null) {
|
|
463
|
+
valid = pushError(Object.assign(Object.assign({}, state), { p: computeKey(state, key) }), `Extraneous property (got ${getPrintable(sub)})`);
|
|
464
|
+
} else {
|
|
465
|
+
Object.defineProperty(extra, key, {
|
|
466
|
+
enumerable: true,
|
|
467
|
+
get: () => sub,
|
|
468
|
+
set: makeSetter(value, key)
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
if (!valid && (state === null || state === void 0 ? void 0 : state.errors) == null) {
|
|
473
|
+
break;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
if (extraSpec !== null && (valid || (state === null || state === void 0 ? void 0 : state.errors) != null))
|
|
477
|
+
valid = extraSpec(extra, state) && valid;
|
|
478
|
+
return valid;
|
|
479
|
+
}
|
|
480
|
+
});
|
|
481
|
+
return Object.assign(validator, {
|
|
482
|
+
properties: props
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
function isPartial(props) {
|
|
486
|
+
return isObject(props, { extra: isRecord(isUnknown()) });
|
|
487
|
+
}
|
|
488
|
+
var isInstanceOf = (constructor) => makeValidator({
|
|
489
|
+
test: (value, state) => {
|
|
490
|
+
if (!(value instanceof constructor))
|
|
491
|
+
return pushError(state, `Expected an instance of ${constructor.name} (got ${getPrintable(value)})`);
|
|
492
|
+
return true;
|
|
493
|
+
}
|
|
494
|
+
});
|
|
495
|
+
var isOneOf = (specs, { exclusive = false } = {}) => makeValidator({
|
|
496
|
+
test: (value, state) => {
|
|
497
|
+
var _a, _b, _c;
|
|
498
|
+
const matches = [];
|
|
499
|
+
const errorBuffer = typeof (state === null || state === void 0 ? void 0 : state.errors) !== `undefined` ? [] : void 0;
|
|
500
|
+
for (let t = 0, T = specs.length; t < T; ++t) {
|
|
501
|
+
const subErrors = typeof (state === null || state === void 0 ? void 0 : state.errors) !== `undefined` ? [] : void 0;
|
|
502
|
+
const subCoercions = typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined` ? [] : void 0;
|
|
503
|
+
if (specs[t](value, Object.assign(Object.assign({}, state), { errors: subErrors, coercions: subCoercions, p: `${(_a = state === null || state === void 0 ? void 0 : state.p) !== null && _a !== void 0 ? _a : `.`}#${t + 1}` }))) {
|
|
504
|
+
matches.push([`#${t + 1}`, subCoercions]);
|
|
505
|
+
if (!exclusive) {
|
|
506
|
+
break;
|
|
507
|
+
}
|
|
508
|
+
} else {
|
|
509
|
+
errorBuffer === null || errorBuffer === void 0 ? void 0 : errorBuffer.push(subErrors[0]);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
if (matches.length === 1) {
|
|
513
|
+
const [, subCoercions] = matches[0];
|
|
514
|
+
if (typeof subCoercions !== `undefined`)
|
|
515
|
+
(_b = state === null || state === void 0 ? void 0 : state.coercions) === null || _b === void 0 ? void 0 : _b.push(...subCoercions);
|
|
516
|
+
return true;
|
|
517
|
+
}
|
|
518
|
+
if (matches.length > 1)
|
|
519
|
+
pushError(state, `Expected to match exactly a single predicate (matched ${matches.join(`, `)})`);
|
|
520
|
+
else
|
|
521
|
+
(_c = state === null || state === void 0 ? void 0 : state.errors) === null || _c === void 0 ? void 0 : _c.push(...errorBuffer);
|
|
522
|
+
return false;
|
|
523
|
+
}
|
|
524
|
+
});
|
|
525
|
+
function makeTrait(value) {
|
|
526
|
+
return () => {
|
|
527
|
+
return value;
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
function makeValidator({ test }) {
|
|
531
|
+
return makeTrait(test)();
|
|
532
|
+
}
|
|
533
|
+
var TypeAssertionError = class extends Error {
|
|
534
|
+
constructor({ errors } = {}) {
|
|
535
|
+
let errorMessage = `Type mismatch`;
|
|
536
|
+
if (errors && errors.length > 0) {
|
|
537
|
+
errorMessage += `
|
|
538
|
+
`;
|
|
539
|
+
for (const error of errors) {
|
|
540
|
+
errorMessage += `
|
|
541
|
+
- ${error}`;
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
super(errorMessage);
|
|
545
|
+
}
|
|
546
|
+
};
|
|
547
|
+
function assert(val, validator) {
|
|
548
|
+
if (!validator(val)) {
|
|
549
|
+
throw new TypeAssertionError();
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
function assertWithErrors(val, validator) {
|
|
553
|
+
const errors = [];
|
|
554
|
+
if (!validator(val, { errors })) {
|
|
555
|
+
throw new TypeAssertionError({ errors });
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
function softAssert(val, validator) {
|
|
559
|
+
}
|
|
560
|
+
function as(value, validator, { coerce = false, errors: storeErrors, throw: throws } = {}) {
|
|
561
|
+
const errors = storeErrors ? [] : void 0;
|
|
562
|
+
if (!coerce) {
|
|
563
|
+
if (validator(value, { errors })) {
|
|
564
|
+
return throws ? value : { value, errors: void 0 };
|
|
565
|
+
} else if (!throws) {
|
|
566
|
+
return { value: void 0, errors: errors !== null && errors !== void 0 ? errors : true };
|
|
567
|
+
} else {
|
|
568
|
+
throw new TypeAssertionError({ errors });
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
const state = { value };
|
|
572
|
+
const coercion = makeCoercionFn(state, `value`);
|
|
573
|
+
const coercions = [];
|
|
574
|
+
if (!validator(value, { errors, coercion, coercions })) {
|
|
575
|
+
if (!throws) {
|
|
576
|
+
return { value: void 0, errors: errors !== null && errors !== void 0 ? errors : true };
|
|
577
|
+
} else {
|
|
578
|
+
throw new TypeAssertionError({ errors });
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
for (const [, apply] of coercions)
|
|
582
|
+
apply();
|
|
583
|
+
if (throws) {
|
|
584
|
+
return state.value;
|
|
585
|
+
} else {
|
|
586
|
+
return { value: state.value, errors: void 0 };
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
function fn(validators, fn2) {
|
|
590
|
+
const isValidArgList = isTuple(validators);
|
|
591
|
+
return (...args) => {
|
|
592
|
+
const check = isValidArgList(args);
|
|
593
|
+
if (!check)
|
|
594
|
+
throw new TypeAssertionError();
|
|
595
|
+
return fn2(...args);
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
function hasMinLength(length) {
|
|
599
|
+
return makeValidator({
|
|
600
|
+
test: (value, state) => {
|
|
601
|
+
if (!(value.length >= length))
|
|
602
|
+
return pushError(state, `Expected to have a length of at least ${length} elements (got ${value.length})`);
|
|
603
|
+
return true;
|
|
604
|
+
}
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
function hasMaxLength(length) {
|
|
608
|
+
return makeValidator({
|
|
609
|
+
test: (value, state) => {
|
|
610
|
+
if (!(value.length <= length))
|
|
611
|
+
return pushError(state, `Expected to have a length of at most ${length} elements (got ${value.length})`);
|
|
612
|
+
return true;
|
|
613
|
+
}
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
function hasExactLength(length) {
|
|
617
|
+
return makeValidator({
|
|
618
|
+
test: (value, state) => {
|
|
619
|
+
if (!(value.length === length))
|
|
620
|
+
return pushError(state, `Expected to have a length of exactly ${length} elements (got ${value.length})`);
|
|
621
|
+
return true;
|
|
622
|
+
}
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
function hasUniqueItems({ map } = {}) {
|
|
626
|
+
return makeValidator({
|
|
627
|
+
test: (value, state) => {
|
|
628
|
+
const set = /* @__PURE__ */ new Set();
|
|
629
|
+
const dup = /* @__PURE__ */ new Set();
|
|
630
|
+
for (let t = 0, T = value.length; t < T; ++t) {
|
|
631
|
+
const sub = value[t];
|
|
632
|
+
const key = typeof map !== `undefined` ? map(sub) : sub;
|
|
633
|
+
if (set.has(key)) {
|
|
634
|
+
if (dup.has(key))
|
|
635
|
+
continue;
|
|
636
|
+
pushError(state, `Expected to contain unique elements; got a duplicate with ${getPrintable(value)}`);
|
|
637
|
+
dup.add(key);
|
|
638
|
+
} else {
|
|
639
|
+
set.add(key);
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
return dup.size === 0;
|
|
643
|
+
}
|
|
644
|
+
});
|
|
645
|
+
}
|
|
646
|
+
function isNegative() {
|
|
647
|
+
return makeValidator({
|
|
648
|
+
test: (value, state) => {
|
|
649
|
+
if (!(value <= 0))
|
|
650
|
+
return pushError(state, `Expected to be negative (got ${value})`);
|
|
651
|
+
return true;
|
|
652
|
+
}
|
|
653
|
+
});
|
|
654
|
+
}
|
|
655
|
+
function isPositive() {
|
|
656
|
+
return makeValidator({
|
|
657
|
+
test: (value, state) => {
|
|
658
|
+
if (!(value >= 0))
|
|
659
|
+
return pushError(state, `Expected to be positive (got ${value})`);
|
|
660
|
+
return true;
|
|
661
|
+
}
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
function isAtLeast(n) {
|
|
665
|
+
return makeValidator({
|
|
666
|
+
test: (value, state) => {
|
|
667
|
+
if (!(value >= n))
|
|
668
|
+
return pushError(state, `Expected to be at least ${n} (got ${value})`);
|
|
669
|
+
return true;
|
|
670
|
+
}
|
|
671
|
+
});
|
|
672
|
+
}
|
|
673
|
+
function isAtMost(n) {
|
|
674
|
+
return makeValidator({
|
|
675
|
+
test: (value, state) => {
|
|
676
|
+
if (!(value <= n))
|
|
677
|
+
return pushError(state, `Expected to be at most ${n} (got ${value})`);
|
|
678
|
+
return true;
|
|
679
|
+
}
|
|
680
|
+
});
|
|
681
|
+
}
|
|
682
|
+
function isInInclusiveRange(a, b) {
|
|
683
|
+
return makeValidator({
|
|
684
|
+
test: (value, state) => {
|
|
685
|
+
if (!(value >= a && value <= b))
|
|
686
|
+
return pushError(state, `Expected to be in the [${a}; ${b}] range (got ${value})`);
|
|
687
|
+
return true;
|
|
688
|
+
}
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
function isInExclusiveRange(a, b) {
|
|
692
|
+
return makeValidator({
|
|
693
|
+
test: (value, state) => {
|
|
694
|
+
if (!(value >= a && value < b))
|
|
695
|
+
return pushError(state, `Expected to be in the [${a}; ${b}[ range (got ${value})`);
|
|
696
|
+
return true;
|
|
697
|
+
}
|
|
698
|
+
});
|
|
699
|
+
}
|
|
700
|
+
function isInteger({ unsafe = false } = {}) {
|
|
701
|
+
return makeValidator({
|
|
702
|
+
test: (value, state) => {
|
|
703
|
+
if (value !== Math.round(value))
|
|
704
|
+
return pushError(state, `Expected to be an integer (got ${value})`);
|
|
705
|
+
if (!unsafe && !Number.isSafeInteger(value))
|
|
706
|
+
return pushError(state, `Expected to be a safe integer (got ${value})`);
|
|
707
|
+
return true;
|
|
708
|
+
}
|
|
709
|
+
});
|
|
710
|
+
}
|
|
711
|
+
function matchesRegExp(regExp) {
|
|
712
|
+
return makeValidator({
|
|
713
|
+
test: (value, state) => {
|
|
714
|
+
if (!regExp.test(value))
|
|
715
|
+
return pushError(state, `Expected to match the pattern ${regExp.toString()} (got ${getPrintable(value)})`);
|
|
716
|
+
return true;
|
|
717
|
+
}
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
function isLowerCase() {
|
|
721
|
+
return makeValidator({
|
|
722
|
+
test: (value, state) => {
|
|
723
|
+
if (value !== value.toLowerCase())
|
|
724
|
+
return pushError(state, `Expected to be all-lowercase (got ${value})`);
|
|
725
|
+
return true;
|
|
726
|
+
}
|
|
727
|
+
});
|
|
728
|
+
}
|
|
729
|
+
function isUpperCase() {
|
|
730
|
+
return makeValidator({
|
|
731
|
+
test: (value, state) => {
|
|
732
|
+
if (value !== value.toUpperCase())
|
|
733
|
+
return pushError(state, `Expected to be all-uppercase (got ${value})`);
|
|
734
|
+
return true;
|
|
735
|
+
}
|
|
736
|
+
});
|
|
737
|
+
}
|
|
738
|
+
function isUUID4() {
|
|
739
|
+
return makeValidator({
|
|
740
|
+
test: (value, state) => {
|
|
741
|
+
if (!uuid4RegExp.test(value))
|
|
742
|
+
return pushError(state, `Expected to be a valid UUID v4 (got ${getPrintable(value)})`);
|
|
743
|
+
return true;
|
|
744
|
+
}
|
|
745
|
+
});
|
|
746
|
+
}
|
|
747
|
+
function isISO8601() {
|
|
748
|
+
return makeValidator({
|
|
749
|
+
test: (value, state) => {
|
|
750
|
+
if (!iso8601RegExp.test(value))
|
|
751
|
+
return pushError(state, `Expected to be a valid ISO 8601 date string (got ${getPrintable(value)})`);
|
|
752
|
+
return true;
|
|
753
|
+
}
|
|
754
|
+
});
|
|
755
|
+
}
|
|
756
|
+
function isHexColor({ alpha = false }) {
|
|
757
|
+
return makeValidator({
|
|
758
|
+
test: (value, state) => {
|
|
759
|
+
const res = alpha ? colorStringRegExp.test(value) : colorStringAlphaRegExp.test(value);
|
|
760
|
+
if (!res)
|
|
761
|
+
return pushError(state, `Expected to be a valid hexadecimal color string (got ${getPrintable(value)})`);
|
|
762
|
+
return true;
|
|
763
|
+
}
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
function isBase64() {
|
|
767
|
+
return makeValidator({
|
|
768
|
+
test: (value, state) => {
|
|
769
|
+
if (!base64RegExp.test(value))
|
|
770
|
+
return pushError(state, `Expected to be a valid base 64 string (got ${getPrintable(value)})`);
|
|
771
|
+
return true;
|
|
772
|
+
}
|
|
773
|
+
});
|
|
774
|
+
}
|
|
775
|
+
function isJSON(spec = isUnknown()) {
|
|
776
|
+
return makeValidator({
|
|
777
|
+
test: (value, state) => {
|
|
778
|
+
let data;
|
|
779
|
+
try {
|
|
780
|
+
data = JSON.parse(value);
|
|
781
|
+
} catch (_a) {
|
|
782
|
+
return pushError(state, `Expected to be a valid JSON string (got ${getPrintable(value)})`);
|
|
783
|
+
}
|
|
784
|
+
return spec(data, state);
|
|
785
|
+
}
|
|
786
|
+
});
|
|
787
|
+
}
|
|
788
|
+
function cascade(spec, ...followups) {
|
|
789
|
+
const resolvedFollowups = Array.isArray(followups[0]) ? followups[0] : followups;
|
|
790
|
+
return makeValidator({
|
|
791
|
+
test: (value, state) => {
|
|
792
|
+
var _a, _b;
|
|
793
|
+
const context = { value };
|
|
794
|
+
const subCoercion = typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined` ? makeCoercionFn(context, `value`) : void 0;
|
|
795
|
+
const subCoercions = typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined` ? [] : void 0;
|
|
796
|
+
if (!spec(value, Object.assign(Object.assign({}, state), { coercion: subCoercion, coercions: subCoercions })))
|
|
797
|
+
return false;
|
|
798
|
+
const reverts = [];
|
|
799
|
+
if (typeof subCoercions !== `undefined`)
|
|
800
|
+
for (const [, coercion] of subCoercions)
|
|
801
|
+
reverts.push(coercion());
|
|
802
|
+
try {
|
|
803
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
|
|
804
|
+
if (context.value !== value) {
|
|
805
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`)
|
|
806
|
+
return pushError(state, `Unbound coercion result`);
|
|
807
|
+
state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, state.coercion.bind(null, context.value)]);
|
|
808
|
+
}
|
|
809
|
+
(_b = state === null || state === void 0 ? void 0 : state.coercions) === null || _b === void 0 ? void 0 : _b.push(...subCoercions);
|
|
810
|
+
}
|
|
811
|
+
return resolvedFollowups.every((spec2) => {
|
|
812
|
+
return spec2(context.value, state);
|
|
813
|
+
});
|
|
814
|
+
} finally {
|
|
815
|
+
for (const revert of reverts) {
|
|
816
|
+
revert();
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
function applyCascade(spec, ...followups) {
|
|
823
|
+
const resolvedFollowups = Array.isArray(followups[0]) ? followups[0] : followups;
|
|
824
|
+
return cascade(spec, resolvedFollowups);
|
|
825
|
+
}
|
|
826
|
+
function isOptional(spec) {
|
|
827
|
+
return makeValidator({
|
|
828
|
+
test: (value, state) => {
|
|
829
|
+
if (typeof value === `undefined`)
|
|
830
|
+
return true;
|
|
831
|
+
return spec(value, state);
|
|
832
|
+
}
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
function isNullable(spec) {
|
|
836
|
+
return makeValidator({
|
|
837
|
+
test: (value, state) => {
|
|
838
|
+
if (value === null)
|
|
839
|
+
return true;
|
|
840
|
+
return spec(value, state);
|
|
841
|
+
}
|
|
842
|
+
});
|
|
843
|
+
}
|
|
844
|
+
var checks = {
|
|
845
|
+
missing: (keys, key) => keys.has(key),
|
|
846
|
+
undefined: (keys, key, value) => keys.has(key) && typeof value[key] !== `undefined`,
|
|
847
|
+
nil: (keys, key, value) => keys.has(key) && value[key] != null,
|
|
848
|
+
falsy: (keys, key, value) => keys.has(key) && !!value[key]
|
|
849
|
+
};
|
|
850
|
+
function hasRequiredKeys(requiredKeys, options) {
|
|
851
|
+
var _a;
|
|
852
|
+
const requiredSet = new Set(requiredKeys);
|
|
853
|
+
const check = checks[(_a = options === null || options === void 0 ? void 0 : options.missingIf) !== null && _a !== void 0 ? _a : "missing"];
|
|
854
|
+
return makeValidator({
|
|
855
|
+
test: (value, state) => {
|
|
856
|
+
const keys = new Set(Object.keys(value));
|
|
857
|
+
const problems = [];
|
|
858
|
+
for (const key of requiredSet)
|
|
859
|
+
if (!check(keys, key, value))
|
|
860
|
+
problems.push(key);
|
|
861
|
+
if (problems.length > 0)
|
|
862
|
+
return pushError(state, `Missing required ${plural(problems.length, `property`, `properties`)} ${getPrintableArray(problems, `and`)}`);
|
|
863
|
+
return true;
|
|
864
|
+
}
|
|
865
|
+
});
|
|
866
|
+
}
|
|
867
|
+
function hasAtLeastOneKey(requiredKeys, options) {
|
|
868
|
+
var _a;
|
|
869
|
+
const requiredSet = new Set(requiredKeys);
|
|
870
|
+
const check = checks[(_a = options === null || options === void 0 ? void 0 : options.missingIf) !== null && _a !== void 0 ? _a : "missing"];
|
|
871
|
+
return makeValidator({
|
|
872
|
+
test: (value, state) => {
|
|
873
|
+
const keys = Object.keys(value);
|
|
874
|
+
const valid = keys.some((key) => check(requiredSet, key, value));
|
|
875
|
+
if (!valid)
|
|
876
|
+
return pushError(state, `Missing at least one property from ${getPrintableArray(Array.from(requiredSet), `or`)}`);
|
|
877
|
+
return true;
|
|
878
|
+
}
|
|
879
|
+
});
|
|
880
|
+
}
|
|
881
|
+
function hasForbiddenKeys(forbiddenKeys, options) {
|
|
882
|
+
var _a;
|
|
883
|
+
const forbiddenSet = new Set(forbiddenKeys);
|
|
884
|
+
const check = checks[(_a = options === null || options === void 0 ? void 0 : options.missingIf) !== null && _a !== void 0 ? _a : "missing"];
|
|
885
|
+
return makeValidator({
|
|
886
|
+
test: (value, state) => {
|
|
887
|
+
const keys = new Set(Object.keys(value));
|
|
888
|
+
const problems = [];
|
|
889
|
+
for (const key of forbiddenSet)
|
|
890
|
+
if (check(keys, key, value))
|
|
891
|
+
problems.push(key);
|
|
892
|
+
if (problems.length > 0)
|
|
893
|
+
return pushError(state, `Forbidden ${plural(problems.length, `property`, `properties`)} ${getPrintableArray(problems, `and`)}`);
|
|
894
|
+
return true;
|
|
895
|
+
}
|
|
896
|
+
});
|
|
897
|
+
}
|
|
898
|
+
function hasMutuallyExclusiveKeys(exclusiveKeys, options) {
|
|
899
|
+
var _a;
|
|
900
|
+
const exclusiveSet = new Set(exclusiveKeys);
|
|
901
|
+
const check = checks[(_a = options === null || options === void 0 ? void 0 : options.missingIf) !== null && _a !== void 0 ? _a : "missing"];
|
|
902
|
+
return makeValidator({
|
|
903
|
+
test: (value, state) => {
|
|
904
|
+
const keys = new Set(Object.keys(value));
|
|
905
|
+
const used = [];
|
|
906
|
+
for (const key of exclusiveSet)
|
|
907
|
+
if (check(keys, key, value))
|
|
908
|
+
used.push(key);
|
|
909
|
+
if (used.length > 1)
|
|
910
|
+
return pushError(state, `Mutually exclusive properties ${getPrintableArray(used, `and`)}`);
|
|
911
|
+
return true;
|
|
912
|
+
}
|
|
913
|
+
});
|
|
914
|
+
}
|
|
915
|
+
(function(KeyRelationship) {
|
|
916
|
+
KeyRelationship["Forbids"] = "Forbids";
|
|
917
|
+
KeyRelationship["Requires"] = "Requires";
|
|
918
|
+
})(exports.KeyRelationship || (exports.KeyRelationship = {}));
|
|
919
|
+
var keyRelationships = {
|
|
920
|
+
[exports.KeyRelationship.Forbids]: {
|
|
921
|
+
expect: false,
|
|
922
|
+
message: `forbids using`
|
|
923
|
+
},
|
|
924
|
+
[exports.KeyRelationship.Requires]: {
|
|
925
|
+
expect: true,
|
|
926
|
+
message: `requires using`
|
|
927
|
+
}
|
|
928
|
+
};
|
|
929
|
+
function hasKeyRelationship(subject, relationship, others, options) {
|
|
930
|
+
var _a, _b;
|
|
931
|
+
const skipped = new Set((_a = options === null || options === void 0 ? void 0 : options.ignore) !== null && _a !== void 0 ? _a : []);
|
|
932
|
+
const check = checks[(_b = options === null || options === void 0 ? void 0 : options.missingIf) !== null && _b !== void 0 ? _b : "missing"];
|
|
933
|
+
const otherSet = new Set(others);
|
|
934
|
+
const spec = keyRelationships[relationship];
|
|
935
|
+
const conjunction = relationship === exports.KeyRelationship.Forbids ? `or` : `and`;
|
|
936
|
+
return makeValidator({
|
|
937
|
+
test: (value, state) => {
|
|
938
|
+
const keys = new Set(Object.keys(value));
|
|
939
|
+
if (!check(keys, subject, value) || skipped.has(value[subject]))
|
|
940
|
+
return true;
|
|
941
|
+
const problems = [];
|
|
942
|
+
for (const key of otherSet)
|
|
943
|
+
if ((check(keys, key, value) && !skipped.has(value[key])) !== spec.expect)
|
|
944
|
+
problems.push(key);
|
|
945
|
+
if (problems.length >= 1)
|
|
946
|
+
return pushError(state, `Property "${subject}" ${spec.message} ${plural(problems.length, `property`, `properties`)} ${getPrintableArray(problems, conjunction)}`);
|
|
947
|
+
return true;
|
|
948
|
+
}
|
|
949
|
+
});
|
|
950
|
+
}
|
|
951
|
+
exports.TypeAssertionError = TypeAssertionError;
|
|
952
|
+
exports.applyCascade = applyCascade;
|
|
953
|
+
exports.as = as;
|
|
954
|
+
exports.assert = assert;
|
|
955
|
+
exports.assertWithErrors = assertWithErrors;
|
|
956
|
+
exports.cascade = cascade;
|
|
957
|
+
exports.fn = fn;
|
|
958
|
+
exports.hasAtLeastOneKey = hasAtLeastOneKey;
|
|
959
|
+
exports.hasExactLength = hasExactLength;
|
|
960
|
+
exports.hasForbiddenKeys = hasForbiddenKeys;
|
|
961
|
+
exports.hasKeyRelationship = hasKeyRelationship;
|
|
962
|
+
exports.hasMaxLength = hasMaxLength;
|
|
963
|
+
exports.hasMinLength = hasMinLength;
|
|
964
|
+
exports.hasMutuallyExclusiveKeys = hasMutuallyExclusiveKeys;
|
|
965
|
+
exports.hasRequiredKeys = hasRequiredKeys;
|
|
966
|
+
exports.hasUniqueItems = hasUniqueItems;
|
|
967
|
+
exports.isArray = isArray;
|
|
968
|
+
exports.isAtLeast = isAtLeast;
|
|
969
|
+
exports.isAtMost = isAtMost;
|
|
970
|
+
exports.isBase64 = isBase64;
|
|
971
|
+
exports.isBoolean = isBoolean;
|
|
972
|
+
exports.isDate = isDate;
|
|
973
|
+
exports.isDict = isDict;
|
|
974
|
+
exports.isEnum = isEnum;
|
|
975
|
+
exports.isHexColor = isHexColor;
|
|
976
|
+
exports.isISO8601 = isISO8601;
|
|
977
|
+
exports.isInExclusiveRange = isInExclusiveRange;
|
|
978
|
+
exports.isInInclusiveRange = isInInclusiveRange;
|
|
979
|
+
exports.isInstanceOf = isInstanceOf;
|
|
980
|
+
exports.isInteger = isInteger;
|
|
981
|
+
exports.isJSON = isJSON;
|
|
982
|
+
exports.isLiteral = isLiteral;
|
|
983
|
+
exports.isLowerCase = isLowerCase;
|
|
984
|
+
exports.isMap = isMap;
|
|
985
|
+
exports.isNegative = isNegative;
|
|
986
|
+
exports.isNullable = isNullable;
|
|
987
|
+
exports.isNumber = isNumber;
|
|
988
|
+
exports.isObject = isObject;
|
|
989
|
+
exports.isOneOf = isOneOf;
|
|
990
|
+
exports.isOptional = isOptional;
|
|
991
|
+
exports.isPartial = isPartial;
|
|
992
|
+
exports.isPayload = isPayload;
|
|
993
|
+
exports.isPositive = isPositive;
|
|
994
|
+
exports.isRecord = isRecord;
|
|
995
|
+
exports.isSet = isSet;
|
|
996
|
+
exports.isString = isString;
|
|
997
|
+
exports.isTuple = isTuple;
|
|
998
|
+
exports.isUUID4 = isUUID4;
|
|
999
|
+
exports.isUnknown = isUnknown;
|
|
1000
|
+
exports.isUpperCase = isUpperCase;
|
|
1001
|
+
exports.makeTrait = makeTrait;
|
|
1002
|
+
exports.makeValidator = makeValidator;
|
|
1003
|
+
exports.matchesRegExp = matchesRegExp;
|
|
1004
|
+
exports.softAssert = softAssert;
|
|
1005
|
+
}
|
|
1006
|
+
});
|
|
1007
|
+
export default require_lib();
|