bguard 0.3.0 → 0.4.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/README.md +269 -121
- package/lib/CommonSchema-DOh3bsL-.d.ts +110 -0
- package/lib/CommonSchema-wi9MOXGF.d.mts +110 -0
- package/lib/InferType.d.mts +6 -14
- package/lib/InferType.d.ts +6 -14
- package/lib/asserts/array/index.d.mts +6 -5
- package/lib/asserts/array/index.d.ts +6 -5
- package/lib/asserts/array/index.js +7 -7
- package/lib/asserts/array/index.js.map +1 -1
- package/lib/asserts/array/index.mjs +6 -6
- package/lib/asserts/array/index.mjs.map +1 -1
- package/lib/asserts/array/maxArrayLength.js +4 -4
- package/lib/asserts/array/maxArrayLength.mjs +2 -2
- package/lib/asserts/array/minArrayLength.js +4 -4
- package/lib/asserts/array/minArrayLength.mjs +2 -2
- package/lib/asserts/bigint/bigintMax.js +4 -4
- package/lib/asserts/bigint/bigintMax.mjs +2 -2
- package/lib/asserts/bigint/bigintMaxExcluded.js +4 -4
- package/lib/asserts/bigint/bigintMaxExcluded.mjs +2 -2
- package/lib/asserts/bigint/bigintMin.js +4 -4
- package/lib/asserts/bigint/bigintMin.mjs +2 -2
- package/lib/asserts/bigint/bigintMinExcluded.js +4 -4
- package/lib/asserts/bigint/bigintMinExcluded.mjs +2 -2
- package/lib/asserts/bigint/index.d.mts +5 -4
- package/lib/asserts/bigint/index.d.ts +5 -4
- package/lib/asserts/bigint/index.js +10 -10
- package/lib/asserts/bigint/index.js.map +1 -1
- package/lib/asserts/bigint/index.mjs +9 -9
- package/lib/asserts/bigint/index.mjs.map +1 -1
- package/lib/asserts/boolean/index.d.mts +5 -4
- package/lib/asserts/boolean/index.d.ts +5 -4
- package/lib/asserts/boolean/index.js +8 -8
- package/lib/asserts/boolean/index.js.map +1 -1
- package/lib/asserts/boolean/index.mjs +7 -7
- package/lib/asserts/boolean/index.mjs.map +1 -1
- package/lib/asserts/date/dateMax.js +5 -5
- package/lib/asserts/date/dateMax.mjs +2 -2
- package/lib/asserts/date/dateMin.js +5 -5
- package/lib/asserts/date/dateMin.mjs +2 -2
- package/lib/asserts/date/index.d.mts +5 -4
- package/lib/asserts/date/index.d.ts +5 -4
- package/lib/asserts/date/index.js +7 -7
- package/lib/asserts/date/index.js.map +1 -1
- package/lib/asserts/date/index.mjs +6 -6
- package/lib/asserts/date/index.mjs.map +1 -1
- package/lib/asserts/mix/equalTo.js +4 -4
- package/lib/asserts/mix/equalTo.mjs +3 -3
- package/lib/asserts/mix/index.d.mts +5 -4
- package/lib/asserts/mix/index.d.ts +5 -4
- package/lib/asserts/mix/index.js +6 -6
- package/lib/asserts/mix/index.js.map +1 -1
- package/lib/asserts/mix/index.mjs +5 -5
- package/lib/asserts/mix/index.mjs.map +1 -1
- package/lib/asserts/mix/oneOfValues.js +4 -4
- package/lib/asserts/mix/oneOfValues.mjs +3 -3
- package/lib/asserts/number/index.d.mts +4 -3
- package/lib/asserts/number/index.d.ts +4 -3
- package/lib/asserts/number/index.js +10 -10
- package/lib/asserts/number/index.js.map +1 -1
- package/lib/asserts/number/index.mjs +9 -9
- package/lib/asserts/number/index.mjs.map +1 -1
- package/lib/asserts/number/max.js +4 -4
- package/lib/asserts/number/max.mjs +2 -2
- package/lib/asserts/number/maxExcluded.js +4 -4
- package/lib/asserts/number/maxExcluded.mjs +2 -2
- package/lib/asserts/number/min.js +4 -4
- package/lib/asserts/number/min.mjs +2 -2
- package/lib/asserts/number/minExcluded.js +4 -4
- package/lib/asserts/number/minExcluded.mjs +2 -2
- package/lib/asserts/number/negative.js +4 -4
- package/lib/asserts/number/negative.mjs +2 -2
- package/lib/asserts/number/positive.js +4 -4
- package/lib/asserts/number/positive.mjs +2 -2
- package/lib/asserts/object/index.d.mts +6 -5
- package/lib/asserts/object/index.d.ts +6 -5
- package/lib/asserts/object/index.js +7 -7
- package/lib/asserts/object/index.js.map +1 -1
- package/lib/asserts/object/index.mjs +6 -6
- package/lib/asserts/object/index.mjs.map +1 -1
- package/lib/asserts/object/maxKeys.d.mts +30 -0
- package/lib/asserts/object/maxKeys.d.ts +30 -0
- package/lib/asserts/object/maxKeys.js +23 -0
- package/lib/asserts/object/maxKeys.js.map +1 -0
- package/lib/asserts/object/maxKeys.mjs +23 -0
- package/lib/asserts/object/maxKeys.mjs.map +1 -0
- package/lib/asserts/string/atLeastOneDigit.js +4 -4
- package/lib/asserts/string/atLeastOneDigit.mjs +2 -2
- package/lib/asserts/string/atLeastOneLowerChar.js +4 -4
- package/lib/asserts/string/atLeastOneLowerChar.mjs +2 -2
- package/lib/asserts/string/atLeastOneSpecialChar.js +4 -4
- package/lib/asserts/string/atLeastOneSpecialChar.mjs +2 -2
- package/lib/asserts/string/atLeastOneUpperChar.js +4 -4
- package/lib/asserts/string/atLeastOneUpperChar.mjs +2 -2
- package/lib/asserts/string/contains.js +4 -4
- package/lib/asserts/string/contains.mjs +2 -2
- package/lib/asserts/string/email.js +4 -4
- package/lib/asserts/string/email.mjs +2 -2
- package/lib/asserts/string/endsWith.js +4 -4
- package/lib/asserts/string/endsWith.mjs +2 -2
- package/lib/asserts/string/index.d.mts +5 -4
- package/lib/asserts/string/index.d.ts +5 -4
- package/lib/asserts/string/index.js +10 -10
- package/lib/asserts/string/index.js.map +1 -1
- package/lib/asserts/string/index.mjs +9 -9
- package/lib/asserts/string/index.mjs.map +1 -1
- package/lib/asserts/string/isValidDate.js +4 -4
- package/lib/asserts/string/isValidDate.mjs +2 -2
- package/lib/asserts/string/isValidDateTime.js +4 -4
- package/lib/asserts/string/isValidDateTime.mjs +2 -2
- package/lib/asserts/string/isValidTime.js +5 -5
- package/lib/asserts/string/isValidTime.mjs +2 -2
- package/lib/asserts/string/lowerCase.js +4 -4
- package/lib/asserts/string/lowerCase.mjs +2 -2
- package/lib/asserts/string/maxLength.js +4 -4
- package/lib/asserts/string/maxLength.mjs +2 -2
- package/lib/asserts/string/minLength.js +4 -4
- package/lib/asserts/string/minLength.mjs +2 -2
- package/lib/asserts/string/regExp.js +4 -4
- package/lib/asserts/string/regExp.mjs +2 -2
- package/lib/asserts/string/startsWith.js +4 -4
- package/lib/asserts/string/startsWith.mjs +2 -2
- package/lib/asserts/string/upperCase.js +4 -4
- package/lib/asserts/string/upperCase.mjs +2 -2
- package/lib/asserts/string/uuid.js +4 -4
- package/lib/asserts/string/uuid.mjs +2 -2
- package/lib/asserts/string/uuidV1.js +4 -4
- package/lib/asserts/string/uuidV1.mjs +2 -2
- package/lib/asserts/string/uuidV2.js +4 -4
- package/lib/asserts/string/uuidV2.mjs +2 -2
- package/lib/asserts/string/uuidV3.js +4 -4
- package/lib/asserts/string/uuidV3.mjs +2 -2
- package/lib/asserts/string/uuidV4.js +4 -4
- package/lib/asserts/string/uuidV4.mjs +2 -2
- package/lib/asserts/string/uuidV5.js +4 -4
- package/lib/asserts/string/uuidV5.mjs +2 -2
- package/lib/asserts/string/validUrl.js +4 -4
- package/lib/asserts/string/validUrl.mjs +2 -2
- package/lib/{chunk-OJSTQQ3N.js → chunk-2KQASECD.js} +5 -5
- package/lib/{chunk-OJSTQQ3N.js.map → chunk-2KQASECD.js.map} +1 -1
- package/lib/{chunk-AY7HKAG2.js → chunk-5P6AZJCN.js} +5 -3
- package/lib/chunk-5P6AZJCN.js.map +1 -0
- package/lib/{chunk-AN3VHQEQ.js → chunk-5WHCMWXK.js} +12 -9
- package/lib/chunk-5WHCMWXK.js.map +1 -0
- package/lib/{chunk-UZ2PWO4O.js → chunk-5YYRBKDP.js} +4 -4
- package/lib/{chunk-UZ2PWO4O.js.map → chunk-5YYRBKDP.js.map} +1 -1
- package/lib/{chunk-YPAFWVDL.mjs → chunk-6D5W7SSQ.mjs} +4 -4
- package/lib/chunk-6D5W7SSQ.mjs.map +1 -0
- package/lib/chunk-7NBOVYSP.mjs +136 -0
- package/lib/chunk-7NBOVYSP.mjs.map +1 -0
- package/lib/{chunk-5LLJ22IG.mjs → chunk-BNCT7NOR.mjs} +21 -7
- package/lib/chunk-BNCT7NOR.mjs.map +1 -0
- package/lib/{chunk-BUXOCPHI.mjs → chunk-C3EDEQ3W.mjs} +3 -3
- package/lib/{chunk-TQWUSDQD.mjs → chunk-CHUPE6SJ.mjs} +6 -6
- package/lib/chunk-CHUPE6SJ.mjs.map +1 -0
- package/lib/{chunk-ZVW3IHBW.js → chunk-ECBOZ3BM.js} +8 -8
- package/lib/chunk-ECBOZ3BM.js.map +1 -0
- package/lib/{chunk-NP64RC7B.mjs → chunk-FGZKNBDP.mjs} +5 -3
- package/lib/chunk-FGZKNBDP.mjs.map +1 -0
- package/lib/{chunk-ZWE5Q37U.mjs → chunk-FP5QAEVQ.mjs} +6 -6
- package/lib/chunk-FP5QAEVQ.mjs.map +1 -0
- package/lib/{chunk-PESVL5YJ.js → chunk-G55SHHAR.js} +10 -8
- package/lib/chunk-G55SHHAR.js.map +1 -0
- package/lib/{chunk-4GDBM5LP.mjs → chunk-H32B3NHW.mjs} +2 -2
- package/lib/{chunk-D42ISCFK.mjs → chunk-H6LHV3EA.mjs} +2 -2
- package/lib/{chunk-SPWF5IFU.js → chunk-HP3DRZWK.js} +5 -5
- package/lib/{chunk-SPWF5IFU.js.map → chunk-HP3DRZWK.js.map} +1 -1
- package/lib/{chunk-W2GOLG3K.js → chunk-IZ3CBVEE.js} +5 -5
- package/lib/{chunk-W2GOLG3K.js.map → chunk-IZ3CBVEE.js.map} +1 -1
- package/lib/{chunk-OHEMRF7Y.mjs → chunk-K7X6DVM2.mjs} +3 -3
- package/lib/{chunk-KBZUNXJB.mjs → chunk-LPR3G5T3.mjs} +4 -4
- package/lib/{chunk-KBZUNXJB.mjs.map → chunk-LPR3G5T3.mjs.map} +1 -1
- package/lib/{chunk-2MFBOVP2.mjs → chunk-MHBY5OIQ.mjs} +3 -3
- package/lib/{chunk-EU3ZZF7Y.js → chunk-MLNQZ445.js} +13 -13
- package/lib/chunk-MLNQZ445.js.map +1 -0
- package/lib/chunk-QIDWASOC.js +14 -0
- package/lib/{chunk-3ZPLJ5KC.js.map → chunk-QIDWASOC.js.map} +1 -1
- package/lib/chunk-SHJVKSEZ.js +136 -0
- package/lib/chunk-SHJVKSEZ.js.map +1 -0
- package/lib/{chunk-ADSMWGDJ.mjs → chunk-TRGMD7LA.mjs} +7 -5
- package/lib/chunk-TRGMD7LA.mjs.map +1 -0
- package/lib/{chunk-OKF3BVUD.mjs → chunk-TV5IZY4L.mjs} +9 -6
- package/lib/chunk-TV5IZY4L.mjs.map +1 -0
- package/lib/{chunk-OO6BTBVP.js → chunk-U4USIJV3.js} +11 -11
- package/lib/{chunk-OO6BTBVP.js.map → chunk-U4USIJV3.js.map} +1 -1
- package/lib/{chunk-P6V6S6TZ.js → chunk-UUY7DPHK.js} +12 -12
- package/lib/chunk-UUY7DPHK.js.map +1 -0
- package/lib/chunk-VW4RMQD4.js +28 -0
- package/lib/{chunk-LYNVPN3R.js.map → chunk-VW4RMQD4.js.map} +1 -1
- package/lib/{chunk-ZMEQCIRN.mjs → chunk-WK4FJ5GD.mjs} +6 -6
- package/lib/chunk-WK4FJ5GD.mjs.map +1 -0
- package/lib/{chunk-PIBDJJUU.js → chunk-X762EUSZ.js} +31 -17
- package/lib/chunk-X762EUSZ.js.map +1 -0
- package/lib/{chunk-5HT3PYSG.mjs → chunk-YUMUCQKL.mjs} +4 -4
- package/lib/{chunk-5HT3PYSG.mjs.map → chunk-YUMUCQKL.mjs.map} +1 -1
- package/lib/{chunk-2D5QE7F4.js → chunk-Z6QU36MM.js} +12 -12
- package/lib/chunk-Z6QU36MM.js.map +1 -0
- package/lib/codeGen.d.mts +2 -1
- package/lib/codeGen.d.ts +2 -1
- package/lib/codeGen.js +3 -3
- package/lib/codeGen.mjs +2 -2
- package/lib/commonTypes.d.mts +26 -2
- package/lib/commonTypes.d.ts +26 -2
- package/lib/exceptions.d.mts +3 -2
- package/lib/exceptions.d.ts +3 -2
- package/lib/exceptions.js +2 -2
- package/lib/exceptions.mjs +1 -1
- package/lib/helpers/core.d.mts +2 -1
- package/lib/helpers/core.d.ts +2 -1
- package/lib/helpers/core.js +3 -3
- package/lib/helpers/core.mjs +2 -2
- package/lib/helpers/setStrictType.d.mts +2 -1
- package/lib/helpers/setStrictType.d.ts +2 -1
- package/lib/helpers/setStrictType.js +4 -4
- package/lib/helpers/setStrictType.mjs +3 -3
- package/lib/index.d.mts +1 -8
- package/lib/index.d.ts +1 -8
- package/lib/index.js +6 -6
- package/lib/index.mjs +5 -5
- package/lib/parse.d.mts +1 -8
- package/lib/parse.d.ts +1 -8
- package/lib/parse.js +5 -5
- package/lib/parse.mjs +4 -4
- package/lib/parseOrFail.d.mts +1 -8
- package/lib/parseOrFail.d.ts +1 -8
- package/lib/parseOrFail.js +5 -5
- package/lib/parseOrFail.mjs +4 -4
- package/lib/schemas/ArraySchema.d.mts +3 -6
- package/lib/schemas/ArraySchema.d.ts +3 -6
- package/lib/schemas/ArraySchema.js +7 -7
- package/lib/schemas/ArraySchema.mjs +6 -6
- package/lib/schemas/BigIntSchema.d.mts +6 -9
- package/lib/schemas/BigIntSchema.d.ts +6 -9
- package/lib/schemas/BigIntSchema.js +10 -10
- package/lib/schemas/BigIntSchema.mjs +9 -9
- package/lib/schemas/BooleanSchema.d.mts +6 -9
- package/lib/schemas/BooleanSchema.d.ts +6 -9
- package/lib/schemas/BooleanSchema.js +8 -8
- package/lib/schemas/BooleanSchema.mjs +7 -7
- package/lib/schemas/CommonSchema.d.mts +2 -1
- package/lib/schemas/CommonSchema.d.ts +2 -1
- package/lib/schemas/CommonSchema.js +6 -6
- package/lib/schemas/CommonSchema.mjs +5 -5
- package/lib/schemas/DateSchema.d.mts +2 -1
- package/lib/schemas/DateSchema.d.ts +2 -1
- package/lib/schemas/DateSchema.js +7 -7
- package/lib/schemas/DateSchema.mjs +6 -6
- package/lib/schemas/NumberSchema.d.mts +6 -9
- package/lib/schemas/NumberSchema.d.ts +6 -9
- package/lib/schemas/NumberSchema.js +10 -10
- package/lib/schemas/NumberSchema.mjs +9 -9
- package/lib/schemas/ObjectSchema.d.mts +3 -5
- package/lib/schemas/ObjectSchema.d.ts +3 -5
- package/lib/schemas/ObjectSchema.js +7 -7
- package/lib/schemas/ObjectSchema.mjs +6 -6
- package/lib/schemas/StringSchema.d.mts +6 -9
- package/lib/schemas/StringSchema.d.ts +6 -9
- package/lib/schemas/StringSchema.js +10 -10
- package/lib/schemas/StringSchema.mjs +9 -9
- package/lib/translationMap.js +3 -3
- package/lib/translationMap.mjs +2 -2
- package/package.json +1 -1
- package/lib/CommonSchema-CiY7spmg.d.mts +0 -71
- package/lib/CommonSchema-D9QVJBJe.d.ts +0 -71
- package/lib/chunk-2D5QE7F4.js.map +0 -1
- package/lib/chunk-3IOQH3K4.js +0 -74
- package/lib/chunk-3IOQH3K4.js.map +0 -1
- package/lib/chunk-3ZPLJ5KC.js +0 -14
- package/lib/chunk-5LLJ22IG.mjs.map +0 -1
- package/lib/chunk-ADSMWGDJ.mjs.map +0 -1
- package/lib/chunk-AN3VHQEQ.js.map +0 -1
- package/lib/chunk-AOUFWACR.mjs +0 -74
- package/lib/chunk-AOUFWACR.mjs.map +0 -1
- package/lib/chunk-AY7HKAG2.js.map +0 -1
- package/lib/chunk-EU3ZZF7Y.js.map +0 -1
- package/lib/chunk-LYNVPN3R.js +0 -28
- package/lib/chunk-NP64RC7B.mjs.map +0 -1
- package/lib/chunk-OKF3BVUD.mjs.map +0 -1
- package/lib/chunk-P6V6S6TZ.js.map +0 -1
- package/lib/chunk-PESVL5YJ.js.map +0 -1
- package/lib/chunk-PIBDJJUU.js.map +0 -1
- package/lib/chunk-TQWUSDQD.mjs.map +0 -1
- package/lib/chunk-YPAFWVDL.mjs.map +0 -1
- package/lib/chunk-ZMEQCIRN.mjs.map +0 -1
- package/lib/chunk-ZVW3IHBW.js.map +0 -1
- package/lib/chunk-ZWE5Q37U.mjs.map +0 -1
- /package/lib/{chunk-BUXOCPHI.mjs.map → chunk-C3EDEQ3W.mjs.map} +0 -0
- /package/lib/{chunk-4GDBM5LP.mjs.map → chunk-H32B3NHW.mjs.map} +0 -0
- /package/lib/{chunk-D42ISCFK.mjs.map → chunk-H6LHV3EA.mjs.map} +0 -0
- /package/lib/{chunk-OHEMRF7Y.mjs.map → chunk-K7X6DVM2.mjs.map} +0 -0
- /package/lib/{chunk-2MFBOVP2.mjs.map → chunk-MHBY5OIQ.mjs.map} +0 -0
|
@@ -1,55 +1,65 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
3
|
var _chunkVBTWYDEMjs = require('./chunk-VBTWYDEM.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunk5P6AZJCNjs = require('./chunk-5P6AZJCN.js');
|
|
7
7
|
|
|
8
8
|
// src/helpers/core.ts
|
|
9
9
|
var ctxSymbol = Symbol("contextSymbol");
|
|
10
10
|
function innerCheck(schema, receivedValue, exCtx) {
|
|
11
11
|
const commonTmap = exCtx.t;
|
|
12
12
|
const schemaData = schema[ctxSymbol];
|
|
13
|
+
_optionalChain([schemaData, 'access', _ => _.transformListBefore, 'optionalAccess', _2 => _2.forEach, 'call', _3 => _3((transformCallback) => {
|
|
14
|
+
receivedValue = transformCallback(receivedValue);
|
|
15
|
+
})]);
|
|
13
16
|
if (receivedValue === void 0) {
|
|
14
17
|
if (schemaData.defaultValue !== void 0) return schemaData.defaultValue;
|
|
15
|
-
if (!schemaData.isOptional)
|
|
18
|
+
if (!schemaData.isOptional) _chunk5P6AZJCNjs.guardException.call(void 0, "Required", receivedValue, exCtx, commonTmap["c:optional"]);
|
|
16
19
|
return receivedValue;
|
|
17
20
|
}
|
|
18
21
|
if (receivedValue === null) {
|
|
19
|
-
if (!schemaData.isNullable)
|
|
22
|
+
if (!schemaData.isNullable) _chunk5P6AZJCNjs.guardException.call(void 0, "Not null", receivedValue, exCtx, commonTmap["c:nullable"]);
|
|
20
23
|
return receivedValue;
|
|
21
24
|
}
|
|
22
25
|
if (schemaData.date) {
|
|
23
|
-
if (!_chunkVBTWYDEMjs.isValidDateInner.call(void 0, receivedValue))
|
|
26
|
+
if (!_chunkVBTWYDEMjs.isValidDateInner.call(void 0, receivedValue)) _chunk5P6AZJCNjs.guardException.call(void 0, "Date", receivedValue, exCtx, commonTmap["c:date"]);
|
|
24
27
|
}
|
|
25
28
|
const typeOfVal = typeof receivedValue;
|
|
26
29
|
if (schemaData.type.length) {
|
|
27
30
|
if (!schemaData.type.includes(typeOfVal))
|
|
28
|
-
|
|
31
|
+
_chunk5P6AZJCNjs.guardException.call(void 0, schemaData.type, typeOfVal, exCtx, commonTmap["c:invalidType"]);
|
|
29
32
|
}
|
|
30
|
-
schemaData.requiredValidations.forEach((requiredValidation) => {
|
|
31
|
-
requiredValidation(receivedValue, exCtx);
|
|
32
|
-
});
|
|
33
33
|
if (schemaData.array) {
|
|
34
|
-
if (!Array.isArray(receivedValue)) return
|
|
34
|
+
if (!Array.isArray(receivedValue)) return _chunk5P6AZJCNjs.guardException.call(void 0, "Array", receivedValue, exCtx, commonTmap["c:array"]);
|
|
35
|
+
schemaData.requiredValidations.forEach((requiredValidation) => {
|
|
36
|
+
requiredValidation(receivedValue, exCtx);
|
|
37
|
+
});
|
|
35
38
|
const schema2 = schemaData.array;
|
|
36
39
|
const pathToError = exCtx.pathToError;
|
|
37
40
|
const parsedReceivedValue = [];
|
|
38
41
|
receivedValue.forEach((elem, i) => {
|
|
39
|
-
const parsedElement = innerCheck(schema2, elem, {
|
|
42
|
+
const parsedElement = innerCheck(schema2, elem, {
|
|
43
|
+
...exCtx,
|
|
44
|
+
pathToError: `${pathToError}[${i}]`,
|
|
45
|
+
meta: schemaData.meta
|
|
46
|
+
});
|
|
40
47
|
parsedReceivedValue.push(parsedElement);
|
|
41
48
|
});
|
|
42
49
|
return parsedReceivedValue;
|
|
43
50
|
}
|
|
44
51
|
if (schemaData.object) {
|
|
45
|
-
if (typeOfVal !== "object")
|
|
46
|
-
if (Array.isArray(receivedValue))
|
|
52
|
+
if (typeOfVal !== "object") _chunk5P6AZJCNjs.guardException.call(void 0, "Object", receivedValue, exCtx, commonTmap["c:objectType"]);
|
|
53
|
+
if (Array.isArray(receivedValue)) _chunk5P6AZJCNjs.guardException.call(void 0, "Object", receivedValue, exCtx, commonTmap["c:objectTypeAsArray"]);
|
|
54
|
+
schemaData.requiredValidations.forEach((requiredValidation) => {
|
|
55
|
+
requiredValidation(receivedValue, exCtx);
|
|
56
|
+
});
|
|
47
57
|
const shapeSchema = schemaData.object;
|
|
48
58
|
const parsedReceivedValue = {};
|
|
49
59
|
if (!schemaData.allowUnrecognizedObjectProps) {
|
|
50
60
|
for (const keyPerReceivedValue of Object.keys(receivedValue)) {
|
|
51
61
|
if (shapeSchema[keyPerReceivedValue] === void 0)
|
|
52
|
-
|
|
62
|
+
_chunk5P6AZJCNjs.guardException.call(void 0, "Unrecognized property", keyPerReceivedValue, exCtx, commonTmap["c:unrecognizedProperty"]);
|
|
53
63
|
}
|
|
54
64
|
}
|
|
55
65
|
const pathToError = exCtx.pathToError;
|
|
@@ -57,16 +67,20 @@ function innerCheck(schema, receivedValue, exCtx) {
|
|
|
57
67
|
const receivedObjectValuePropery = receivedValue[keyOfSchema];
|
|
58
68
|
if (receivedObjectValuePropery === void 0) {
|
|
59
69
|
if (!valueOfSchema[ctxSymbol].isOptional)
|
|
60
|
-
|
|
70
|
+
_chunk5P6AZJCNjs.guardException.call(void 0, "Required", receivedObjectValuePropery, exCtx, commonTmap["c:requiredProperty"]);
|
|
61
71
|
}
|
|
62
72
|
const parsedReceivedObjectValuePropery = innerCheck(valueOfSchema, receivedObjectValuePropery, {
|
|
63
73
|
...exCtx,
|
|
64
|
-
pathToError: `${pathToError}.${keyOfSchema}
|
|
74
|
+
pathToError: `${pathToError}.${keyOfSchema}`,
|
|
75
|
+
meta: schemaData.meta
|
|
65
76
|
});
|
|
66
77
|
parsedReceivedValue[keyOfSchema] = parsedReceivedObjectValuePropery;
|
|
67
78
|
}
|
|
68
79
|
return parsedReceivedValue;
|
|
69
80
|
}
|
|
81
|
+
schemaData.requiredValidations.forEach((requiredValidation) => {
|
|
82
|
+
requiredValidation(receivedValue, exCtx);
|
|
83
|
+
});
|
|
70
84
|
return receivedValue;
|
|
71
85
|
}
|
|
72
86
|
|
|
@@ -74,4 +88,4 @@ function innerCheck(schema, receivedValue, exCtx) {
|
|
|
74
88
|
|
|
75
89
|
|
|
76
90
|
exports.ctxSymbol = ctxSymbol; exports.innerCheck = innerCheck;
|
|
77
|
-
//# sourceMappingURL=chunk-
|
|
91
|
+
//# sourceMappingURL=chunk-X762EUSZ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-X762EUSZ.js","../src/helpers/core.ts"],"names":["schema"],"mappings":"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","file":"/home/runner/work/bguard/bguard/lib/chunk-X762EUSZ.js","sourcesContent":[null,"export const ctxSymbol = Symbol('contextSymbol');\n\nimport { ExceptionContext } from '../commonTypes';\nimport { guardException } from '../exceptions';\nimport type { CommonSchema } from '../schemas/CommonSchema';\nimport { isValidDateInner } from './isValidDateInner';\n\nexport function innerCheck(schema: CommonSchema, receivedValue: unknown, exCtx: ExceptionContext): unknown {\n const commonTmap = exCtx.t;\n const schemaData = schema[ctxSymbol];\n\n schemaData.transformListBefore?.forEach((transformCallback) => {\n receivedValue = transformCallback(receivedValue);\n });\n\n if (receivedValue === undefined) {\n if (schemaData.defaultValue !== undefined) return schemaData.defaultValue;\n if (!schemaData.isOptional) guardException('Required', receivedValue, exCtx, commonTmap['c:optional']);\n return receivedValue;\n }\n\n if (receivedValue === null) {\n if (!schemaData.isNullable) guardException('Not null', receivedValue, exCtx, commonTmap['c:nullable']);\n return receivedValue;\n }\n\n if (schemaData.date) {\n if (!isValidDateInner(receivedValue)) guardException('Date', receivedValue, exCtx, commonTmap['c:date']);\n }\n\n const typeOfVal = typeof receivedValue;\n\n if (schemaData.type.length) {\n if (!schemaData.type.includes(typeOfVal))\n guardException(schemaData.type, typeOfVal, exCtx, commonTmap['c:invalidType']);\n }\n\n if (schemaData.array) {\n if (!Array.isArray(receivedValue)) return guardException('Array', receivedValue, exCtx, commonTmap['c:array']);\n\n schemaData.requiredValidations.forEach((requiredValidation) => {\n requiredValidation(receivedValue, exCtx);\n });\n\n const schema = schemaData.array;\n const pathToError = exCtx.pathToError;\n const parsedReceivedValue: unknown[] = [];\n receivedValue.forEach((elem, i) => {\n const parsedElement = innerCheck(schema, elem, {\n ...exCtx,\n pathToError: `${pathToError}[${i}]`,\n meta: schemaData.meta,\n });\n parsedReceivedValue.push(parsedElement);\n });\n\n return parsedReceivedValue;\n }\n\n if (schemaData.object) {\n if (typeOfVal !== 'object') guardException('Object', receivedValue, exCtx, commonTmap['c:objectType']);\n if (Array.isArray(receivedValue)) guardException('Object', receivedValue, exCtx, commonTmap['c:objectTypeAsArray']);\n\n schemaData.requiredValidations.forEach((requiredValidation) => {\n requiredValidation(receivedValue, exCtx);\n });\n\n const shapeSchema = schemaData.object;\n const parsedReceivedValue: Record<string, unknown> = {};\n\n if (!schemaData.allowUnrecognizedObjectProps) {\n for (const keyPerReceivedValue of Object.keys(receivedValue)) {\n if (shapeSchema[keyPerReceivedValue] === undefined)\n guardException('Unrecognized property', keyPerReceivedValue, exCtx, commonTmap['c:unrecognizedProperty']);\n }\n }\n\n const pathToError = exCtx.pathToError;\n for (const [keyOfSchema, valueOfSchema] of Object.entries(shapeSchema)) {\n const receivedObjectValuePropery = (receivedValue as Record<string, unknown>)[keyOfSchema];\n if (receivedObjectValuePropery === undefined) {\n if (!valueOfSchema[ctxSymbol].isOptional)\n guardException('Required', receivedObjectValuePropery, exCtx, commonTmap['c:requiredProperty']);\n }\n\n const parsedReceivedObjectValuePropery = innerCheck(valueOfSchema, receivedObjectValuePropery, {\n ...exCtx,\n pathToError: `${pathToError}.${keyOfSchema}`,\n meta: schemaData.meta,\n });\n\n parsedReceivedValue[keyOfSchema] = parsedReceivedObjectValuePropery;\n }\n\n return parsedReceivedValue;\n }\n\n schemaData.requiredValidations.forEach((requiredValidation) => {\n requiredValidation(receivedValue, exCtx);\n });\n\n return receivedValue;\n}\n"]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CommonSchema
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-7NBOVYSP.mjs";
|
|
4
4
|
import {
|
|
5
5
|
ctxSymbol
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-BNCT7NOR.mjs";
|
|
7
7
|
import {
|
|
8
8
|
BuildSchemaError
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-FGZKNBDP.mjs";
|
|
10
10
|
|
|
11
11
|
// src/schemas/ObjectSchema.ts
|
|
12
12
|
var ObjectSchema = class extends CommonSchema {
|
|
@@ -50,4 +50,4 @@ var ObjectSchema = class extends CommonSchema {
|
|
|
50
50
|
export {
|
|
51
51
|
ObjectSchema
|
|
52
52
|
};
|
|
53
|
-
//# sourceMappingURL=chunk-
|
|
53
|
+
//# sourceMappingURL=chunk-YUMUCQKL.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/schemas/ObjectSchema.ts"],"sourcesContent":["import { ctxSymbol } from '../helpers/core';\nimport { BuildSchemaError } from '../exceptions';\nimport { CommonSchema, ObjectShapeSchemaType, ValidatorContext } from './CommonSchema';\n\nexport class ObjectSchema extends CommonSchema {\n protected _object = 1;\n constructor(ctx: ValidatorContext, shapeSchema: ObjectShapeSchemaType) {\n super(ctx);\n this.validateObjectEntry(shapeSchema);\n this[ctxSymbol].object = shapeSchema;\n }\n\n private validateObjectEntry(shapeSchema: ObjectShapeSchemaType) {\n if (!shapeSchema) throw new BuildSchemaError('Missing schema in object method');\n if (shapeSchema instanceof CommonSchema) throw new BuildSchemaError('Invalid schema in object');\n for (const [key, value] of Object.entries(shapeSchema)) {\n if (!(value instanceof CommonSchema))\n throw new BuildSchemaError(`Invalid schema in object method for property '${key}'`);\n }\n }\n\n /**\n * Allows unrecognized properties in the validated object.\n * When this method is called, the validation will not fail\n * if the received object contains properties not specified\n * in the validation schema.\n *\n * @returns {this} The current ObjectSchema instance.\n *\n * @example\n * const userSchema = object({\n * name: string(),\n * age: number(),\n * }).allowUnrecognized();\n *\n * parseOrFail(userSchema, ({ name: 'John', age: 30, extra: 'value' }););\n * // No error thrown\n */\n public allowUnrecognized(): this {\n this[ctxSymbol].allowUnrecognizedObjectProps = true;\n return this;\n }\n}\n
|
|
1
|
+
{"version":3,"sources":["../src/schemas/ObjectSchema.ts"],"sourcesContent":["import { ctxSymbol } from '../helpers/core';\nimport { BuildSchemaError } from '../exceptions';\nimport { CommonSchema, ObjectShapeSchemaType, ValidatorContext } from './CommonSchema';\n\nexport class ObjectSchema extends CommonSchema {\n protected _object = 1;\n constructor(ctx: ValidatorContext, shapeSchema: ObjectShapeSchemaType) {\n super(ctx);\n this.validateObjectEntry(shapeSchema);\n this[ctxSymbol].object = shapeSchema;\n }\n\n private validateObjectEntry(shapeSchema: ObjectShapeSchemaType) {\n if (!shapeSchema) throw new BuildSchemaError('Missing schema in object method');\n if (shapeSchema instanceof CommonSchema) throw new BuildSchemaError('Invalid schema in object');\n for (const [key, value] of Object.entries(shapeSchema)) {\n if (!(value instanceof CommonSchema))\n throw new BuildSchemaError(`Invalid schema in object method for property '${key}'`);\n }\n }\n\n /**\n * Allows unrecognized properties in the validated object.\n * When this method is called, the validation will not fail\n * if the received object contains properties not specified\n * in the validation schema.\n *\n * @returns {this} The current ObjectSchema instance.\n *\n * @example\n * const userSchema = object({\n * name: string(),\n * age: number(),\n * }).allowUnrecognized();\n *\n * parseOrFail(userSchema, ({ name: 'John', age: 30, extra: 'value' }););\n * // No error thrown\n */\n public allowUnrecognized(): this {\n this[ctxSymbol].allowUnrecognizedObjectProps = true;\n return this;\n }\n}\n"],"mappings":";;;;;;;;;;;AAIO,IAAM,eAAN,cAA2B,aAAa;AAAA,EACnC,UAAU;AAAA,EACpB,YAAY,KAAuB,aAAoC;AACrE,UAAM,GAAG;AACT,SAAK,oBAAoB,WAAW;AACpC,SAAK,SAAS,EAAE,SAAS;AAAA,EAC3B;AAAA,EAEQ,oBAAoB,aAAoC;AAC9D,QAAI,CAAC,YAAa,OAAM,IAAI,iBAAiB,iCAAiC;AAC9E,QAAI,uBAAuB,aAAc,OAAM,IAAI,iBAAiB,0BAA0B;AAC9F,eAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,WAAW,GAAG;AACtD,UAAI,EAAE,iBAAiB;AACrB,cAAM,IAAI,iBAAiB,iDAAiD,GAAG,GAAG;AAAA,IACtF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAmBO,oBAA0B;AAC/B,SAAK,SAAS,EAAE,+BAA+B;AAC/C,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _class;
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkHP3DRZWKjs = require('./chunk-HP3DRZWK.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkIZ3CBVEEjs = require('./chunk-IZ3CBVEE.js');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
var _chunk42J6CHIOjs = require('./chunk-42J6CHIO.js');
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _chunkQIDWASOCjs = require('./chunk-QIDWASOC.js');
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
var
|
|
15
|
+
var _chunkSHJVKSEZjs = require('./chunk-SHJVKSEZ.js');
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
var
|
|
18
|
+
var _chunk5P6AZJCNjs = require('./chunk-5P6AZJCN.js');
|
|
19
19
|
|
|
20
20
|
// src/schemas/StringSchema.ts
|
|
21
|
-
var StringSchema = (_class = class extends
|
|
21
|
+
var StringSchema = (_class = class extends _chunkSHJVKSEZjs.CommonSchema {constructor(...args) { super(...args); _class.prototype.__init.call(this); }
|
|
22
22
|
__init() {this._string = 1}
|
|
23
23
|
|
|
24
24
|
/**
|
|
@@ -31,8 +31,8 @@ var StringSchema = (_class = class extends _chunk3IOQH3K4js.CommonSchema {constr
|
|
|
31
31
|
*/
|
|
32
32
|
equalTo(expectedValue) {
|
|
33
33
|
this.limitCheck();
|
|
34
|
-
|
|
35
|
-
return this.custom(
|
|
34
|
+
_chunkQIDWASOCjs._setStrictType.call(void 0, this, `'${expectedValue}'`);
|
|
35
|
+
return this.custom(_chunkHP3DRZWKjs.equalTo.call(void 0, expectedValue));
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
38
|
* Restricts the schema to match one of the specified values and infers the union of those values as the TypeScript type.
|
|
@@ -45,14 +45,14 @@ var StringSchema = (_class = class extends _chunk3IOQH3K4js.CommonSchema {constr
|
|
|
45
45
|
*/
|
|
46
46
|
oneOfValues(expectedValue) {
|
|
47
47
|
this.limitCheck();
|
|
48
|
-
|
|
48
|
+
_chunkQIDWASOCjs._setStrictType.call(void 0,
|
|
49
49
|
this,
|
|
50
50
|
expectedValue.map((el) => `'${el}'`)
|
|
51
51
|
);
|
|
52
|
-
return this.custom(
|
|
52
|
+
return this.custom(_chunkIZ3CBVEEjs.oneOfValues.call(void 0, expectedValue));
|
|
53
53
|
}
|
|
54
54
|
limitCheck() {
|
|
55
|
-
if (this.limit) throw new (0,
|
|
55
|
+
if (this.limit) throw new (0, _chunk5P6AZJCNjs.BuildSchemaError)(_chunk42J6CHIOjs.ONLY_ONCE);
|
|
56
56
|
this.limit = true;
|
|
57
57
|
}
|
|
58
58
|
}, _class);
|
|
@@ -60,4 +60,4 @@ var StringSchema = (_class = class extends _chunk3IOQH3K4js.CommonSchema {constr
|
|
|
60
60
|
|
|
61
61
|
|
|
62
62
|
exports.StringSchema = StringSchema;
|
|
63
|
-
//# sourceMappingURL=chunk-
|
|
63
|
+
//# sourceMappingURL=chunk-Z6QU36MM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-Z6QU36MM.js","../src/schemas/StringSchema.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACA;ACXO,IAAM,aAAA,YAAN,MAAA,QAA2B,8BAAa;AAAA,iBACnC,QAAA,EAAU,EAAA;AAAA,EACZ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUD,OAAA,CAA0B,aAAA,EAA2C;AAC1E,IAAA,IAAA,CAAK,UAAA,CAAW,CAAA;AAChB,IAAA,6CAAA,IAAe,EAAM,CAAA,CAAA,EAAI,aAAa,CAAA,CAAA,CAAG,CAAA;AAEzC,IAAA,OAAO,IAAA,CAAK,MAAA,CAAO,sCAAA,aAAqB,CAAC,CAAA;AAAA,EAC3C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWO,WAAA,CAA8B,aAAA,EAA6C;AAChF,IAAA,IAAA,CAAK,UAAA,CAAW,CAAA;AAChB,IAAA,6CAAA;AAAA,MACE,IAAA;AAAA,MACA,aAAA,CAAc,GAAA,CAAI,CAAC,EAAA,EAAA,GAAO,CAAA,CAAA,EAAI,EAAE,CAAA,CAAA,CAAG;AAAA,IACrC,CAAA;AACA,IAAA,OAAO,IAAA,CAAK,MAAA,CAAO,0CAAA,aAAyB,CAAC,CAAA;AAAA,EAC/C;AAAA,EAEQ,UAAA,CAAA,EAAa;AACnB,IAAA,GAAA,CAAI,IAAA,CAAK,KAAA,EAAO,MAAM,IAAI,sCAAA,CAAiB,0BAAS,CAAA;AACpD,IAAA,IAAA,CAAK,MAAA,EAAQ,IAAA;AAAA,EACf;AACF,UAAA;ADSA;AACA;AACE;AACF,oCAAC","file":"/home/runner/work/bguard/bguard/lib/chunk-Z6QU36MM.js","sourcesContent":[null,"import { equalTo } from '../asserts/mix/equalTo';\nimport { oneOfValues } from '../asserts/mix/oneOfValues';\nimport { WithBGuardType } from '../commonTypes';\nimport { BuildSchemaError } from '../exceptions';\nimport { ONLY_ONCE } from '../helpers/constants';\nimport { _setStrictType } from '../helpers/setStrictType';\nimport { CommonSchema } from './CommonSchema';\n\nexport class StringSchema extends CommonSchema {\n protected _string = 1;\n private limit: boolean | undefined;\n\n /**\n * Restricts the schema to exactly match the specified value and infers the literal value as the TypeScript type.\n *\n * @param expectedValue - The value that the schema must exactly match.\n * @returns - The schema instance restricted to the specified value, with the literal value inferred as the TypeScript type\n *\n * @example - string().equalTo('hello'); // Infers the type 'hello'\n */\n public equalTo<Y extends string>(expectedValue: Y): WithBGuardType<this, Y> {\n this.limitCheck();\n _setStrictType(this, `'${expectedValue}'`);\n\n return this.custom(equalTo(expectedValue)) as WithBGuardType<this, Y>;\n }\n\n /**\n * Restricts the schema to match one of the specified values and infers the union of those values as the TypeScript type.\n *\n * @param expectedValues - An array of values that the schema can match.\n * @returns - The schema instance restricted to one of the specified values, with the union of those values inferred as the TypeScript type.\n *\n * @example\n * string().oneOfValues(['foo', 'bar']); // Infers the type 'foo' | 'bar'\n */\n public oneOfValues<Y extends string>(expectedValue: Y[]): WithBGuardType<this, Y> {\n this.limitCheck();\n _setStrictType(\n this,\n expectedValue.map((el) => `'${el}'`),\n );\n return this.custom(oneOfValues(expectedValue)) as WithBGuardType<this, Y>;\n }\n\n private limitCheck() {\n if (this.limit) throw new BuildSchemaError(ONLY_ONCE);\n this.limit = true;\n }\n}\n"]}
|
package/lib/codeGen.d.mts
CHANGED
package/lib/codeGen.d.ts
CHANGED
package/lib/codeGen.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkX762EUSZjs = require('./chunk-X762EUSZ.js');
|
|
4
4
|
require('./chunk-VBTWYDEM.js');
|
|
5
|
-
require('./chunk-
|
|
5
|
+
require('./chunk-5P6AZJCN.js');
|
|
6
6
|
|
|
7
7
|
// src/codeGen.ts
|
|
8
8
|
function generateBaseType(schemaData) {
|
|
@@ -17,7 +17,7 @@ function generateBaseType(schemaData) {
|
|
|
17
17
|
}
|
|
18
18
|
var INDENT_DEFAULT = ` `;
|
|
19
19
|
function innerGenerator(schema, isProperty, indent = INDENT_DEFAULT) {
|
|
20
|
-
const schemaData = schema[
|
|
20
|
+
const schemaData = schema[_chunkX762EUSZjs.ctxSymbol];
|
|
21
21
|
let code = "";
|
|
22
22
|
if (isProperty) {
|
|
23
23
|
code = code + (schemaData.isOptional ? "?: " : ": ");
|
package/lib/codeGen.mjs
CHANGED
package/lib/commonTypes.d.mts
CHANGED
|
@@ -16,9 +16,15 @@ interface ValidationErrorData {
|
|
|
16
16
|
expected: unknown;
|
|
17
17
|
received: unknown;
|
|
18
18
|
pathToError: string;
|
|
19
|
+
meta?: MetaContext;
|
|
20
|
+
}
|
|
21
|
+
interface MetaContext {
|
|
22
|
+
id?: string;
|
|
23
|
+
description?: string;
|
|
19
24
|
}
|
|
20
25
|
type ExceptionContext = {
|
|
21
26
|
pathToError: string;
|
|
27
|
+
meta?: MetaContext;
|
|
22
28
|
t: TranslationErrorMap;
|
|
23
29
|
} & ({
|
|
24
30
|
getAllErrors?: false;
|
|
@@ -27,6 +33,24 @@ type ExceptionContext = {
|
|
|
27
33
|
errors: ValidationErrorData[];
|
|
28
34
|
});
|
|
29
35
|
type RequiredValidation = (received: any, ctx: ExceptionContext) => void;
|
|
30
|
-
type
|
|
36
|
+
type BaseType = 'number' | 'string' | 'boolean' | 'undefined' | 'object' | 'function' | 'symbol' | 'bigint';
|
|
37
|
+
type WithBGuardType<T, Y> = T & {
|
|
38
|
+
validation_bguard: Y;
|
|
39
|
+
};
|
|
40
|
+
type ExtractFromBGuardType<T> = T extends WithBGuardType<unknown, infer Y> ? Y : never;
|
|
41
|
+
type WithNull<T> = T & {
|
|
42
|
+
validation_null: true;
|
|
43
|
+
};
|
|
44
|
+
type WithUndefined<T> = T & {
|
|
45
|
+
validation_undefined: true;
|
|
46
|
+
};
|
|
47
|
+
type WithArray<T, Y> = T & {
|
|
48
|
+
validation_array: Y;
|
|
49
|
+
};
|
|
50
|
+
type ExtractFromArray<T> = T extends WithArray<unknown, infer X> ? X : never;
|
|
51
|
+
type WithObject<T, Y> = T & {
|
|
52
|
+
validation_object: Y;
|
|
53
|
+
};
|
|
54
|
+
type TransformCallback<In = unknown, Out = unknown> = (val: In) => Out;
|
|
31
55
|
|
|
32
|
-
export type { ExceptionContext,
|
|
56
|
+
export type { BaseType, ExceptionContext, ExtractFromArray, ExtractFromBGuardType, MetaContext, RequiredValidation, TransformCallback, TranslationErrorMap, ValidationErrorData, WithArray, WithBGuardType, WithNull, WithObject, WithUndefined };
|
package/lib/commonTypes.d.ts
CHANGED
|
@@ -16,9 +16,15 @@ interface ValidationErrorData {
|
|
|
16
16
|
expected: unknown;
|
|
17
17
|
received: unknown;
|
|
18
18
|
pathToError: string;
|
|
19
|
+
meta?: MetaContext;
|
|
20
|
+
}
|
|
21
|
+
interface MetaContext {
|
|
22
|
+
id?: string;
|
|
23
|
+
description?: string;
|
|
19
24
|
}
|
|
20
25
|
type ExceptionContext = {
|
|
21
26
|
pathToError: string;
|
|
27
|
+
meta?: MetaContext;
|
|
22
28
|
t: TranslationErrorMap;
|
|
23
29
|
} & ({
|
|
24
30
|
getAllErrors?: false;
|
|
@@ -27,6 +33,24 @@ type ExceptionContext = {
|
|
|
27
33
|
errors: ValidationErrorData[];
|
|
28
34
|
});
|
|
29
35
|
type RequiredValidation = (received: any, ctx: ExceptionContext) => void;
|
|
30
|
-
type
|
|
36
|
+
type BaseType = 'number' | 'string' | 'boolean' | 'undefined' | 'object' | 'function' | 'symbol' | 'bigint';
|
|
37
|
+
type WithBGuardType<T, Y> = T & {
|
|
38
|
+
validation_bguard: Y;
|
|
39
|
+
};
|
|
40
|
+
type ExtractFromBGuardType<T> = T extends WithBGuardType<unknown, infer Y> ? Y : never;
|
|
41
|
+
type WithNull<T> = T & {
|
|
42
|
+
validation_null: true;
|
|
43
|
+
};
|
|
44
|
+
type WithUndefined<T> = T & {
|
|
45
|
+
validation_undefined: true;
|
|
46
|
+
};
|
|
47
|
+
type WithArray<T, Y> = T & {
|
|
48
|
+
validation_array: Y;
|
|
49
|
+
};
|
|
50
|
+
type ExtractFromArray<T> = T extends WithArray<unknown, infer X> ? X : never;
|
|
51
|
+
type WithObject<T, Y> = T & {
|
|
52
|
+
validation_object: Y;
|
|
53
|
+
};
|
|
54
|
+
type TransformCallback<In = unknown, Out = unknown> = (val: In) => Out;
|
|
31
55
|
|
|
32
|
-
export type { ExceptionContext,
|
|
56
|
+
export type { BaseType, ExceptionContext, ExtractFromArray, ExtractFromBGuardType, MetaContext, RequiredValidation, TransformCallback, TranslationErrorMap, ValidationErrorData, WithArray, WithBGuardType, WithNull, WithObject, WithUndefined };
|
package/lib/exceptions.d.mts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { ExceptionContext } from './commonTypes.mjs';
|
|
1
|
+
import { MetaContext, ExceptionContext } from './commonTypes.mjs';
|
|
2
2
|
|
|
3
3
|
declare class ValidationError extends Error {
|
|
4
4
|
expected: unknown;
|
|
5
5
|
received: unknown;
|
|
6
6
|
pathToError: string;
|
|
7
7
|
message: string;
|
|
8
|
-
|
|
8
|
+
meta?: MetaContext;
|
|
9
|
+
constructor(expected: unknown, received: unknown, pathToError: string, message: string, meta?: MetaContext);
|
|
9
10
|
}
|
|
10
11
|
declare class BuildSchemaError extends Error {
|
|
11
12
|
}
|
package/lib/exceptions.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { ExceptionContext } from './commonTypes.js';
|
|
1
|
+
import { MetaContext, ExceptionContext } from './commonTypes.js';
|
|
2
2
|
|
|
3
3
|
declare class ValidationError extends Error {
|
|
4
4
|
expected: unknown;
|
|
5
5
|
received: unknown;
|
|
6
6
|
pathToError: string;
|
|
7
7
|
message: string;
|
|
8
|
-
|
|
8
|
+
meta?: MetaContext;
|
|
9
|
+
constructor(expected: unknown, received: unknown, pathToError: string, message: string, meta?: MetaContext);
|
|
9
10
|
}
|
|
10
11
|
declare class BuildSchemaError extends Error {
|
|
11
12
|
}
|
package/lib/exceptions.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _chunk5P6AZJCNjs = require('./chunk-5P6AZJCN.js');
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
exports.BuildSchemaError =
|
|
10
|
+
exports.BuildSchemaError = _chunk5P6AZJCNjs.BuildSchemaError; exports.ValidationError = _chunk5P6AZJCNjs.ValidationError; exports.guardException = _chunk5P6AZJCNjs.guardException;
|
|
11
11
|
//# sourceMappingURL=exceptions.js.map
|
package/lib/exceptions.mjs
CHANGED
package/lib/helpers/core.d.mts
CHANGED
package/lib/helpers/core.d.ts
CHANGED
package/lib/helpers/core.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunkX762EUSZjs = require('../chunk-X762EUSZ.js');
|
|
5
5
|
require('../chunk-VBTWYDEM.js');
|
|
6
|
-
require('../chunk-
|
|
6
|
+
require('../chunk-5P6AZJCN.js');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
exports.ctxSymbol =
|
|
10
|
+
exports.ctxSymbol = _chunkX762EUSZjs.ctxSymbol; exports.innerCheck = _chunkX762EUSZjs.innerCheck;
|
|
11
11
|
//# sourceMappingURL=core.js.map
|
package/lib/helpers/core.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { C as CommonSchema } from '../CommonSchema-
|
|
1
|
+
import { C as CommonSchema } from '../CommonSchema-wi9MOXGF.mjs';
|
|
2
|
+
import '../InferType.mjs';
|
|
2
3
|
import '../commonTypes.mjs';
|
|
3
4
|
|
|
4
5
|
declare function _setStrictType(that: CommonSchema, val: unknown): void;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('../chunk-
|
|
3
|
+
var _chunkQIDWASOCjs = require('../chunk-QIDWASOC.js');
|
|
4
|
+
require('../chunk-X762EUSZ.js');
|
|
5
5
|
require('../chunk-VBTWYDEM.js');
|
|
6
|
-
require('../chunk-
|
|
6
|
+
require('../chunk-5P6AZJCN.js');
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
exports._setStrictType =
|
|
9
|
+
exports._setStrictType = _chunkQIDWASOCjs._setStrictType;
|
|
10
10
|
//# sourceMappingURL=setStrictType.js.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
_setStrictType
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
3
|
+
} from "../chunk-H6LHV3EA.mjs";
|
|
4
|
+
import "../chunk-BNCT7NOR.mjs";
|
|
5
5
|
import "../chunk-YBVMP4EI.mjs";
|
|
6
|
-
import "../chunk-
|
|
6
|
+
import "../chunk-FGZKNBDP.mjs";
|
|
7
7
|
export {
|
|
8
8
|
_setStrictType
|
|
9
9
|
};
|
package/lib/index.d.mts
CHANGED
|
@@ -3,12 +3,5 @@ export { parse } from './parse.mjs';
|
|
|
3
3
|
export { parseOrFail } from './parseOrFail.mjs';
|
|
4
4
|
export { BuildSchemaError, ValidationError, guardException } from './exceptions.mjs';
|
|
5
5
|
export { clearLocales, setLocale, setToDefaultLocale } from './translationMap.mjs';
|
|
6
|
-
import './schemas/ArraySchema.mjs';
|
|
7
|
-
import './CommonSchema-CiY7spmg.mjs';
|
|
8
6
|
import './commonTypes.mjs';
|
|
9
|
-
import './
|
|
10
|
-
import './schemas/BooleanSchema.mjs';
|
|
11
|
-
import './schemas/DateSchema.mjs';
|
|
12
|
-
import './schemas/NumberSchema.mjs';
|
|
13
|
-
import './schemas/ObjectSchema.mjs';
|
|
14
|
-
import './schemas/StringSchema.mjs';
|
|
7
|
+
import './CommonSchema-wi9MOXGF.mjs';
|
package/lib/index.d.ts
CHANGED
|
@@ -3,12 +3,5 @@ export { parse } from './parse.js';
|
|
|
3
3
|
export { parseOrFail } from './parseOrFail.js';
|
|
4
4
|
export { BuildSchemaError, ValidationError, guardException } from './exceptions.js';
|
|
5
5
|
export { clearLocales, setLocale, setToDefaultLocale } from './translationMap.js';
|
|
6
|
-
import './schemas/ArraySchema.js';
|
|
7
|
-
import './CommonSchema-D9QVJBJe.js';
|
|
8
6
|
import './commonTypes.js';
|
|
9
|
-
import './
|
|
10
|
-
import './schemas/BooleanSchema.js';
|
|
11
|
-
import './schemas/DateSchema.js';
|
|
12
|
-
import './schemas/NumberSchema.js';
|
|
13
|
-
import './schemas/ObjectSchema.js';
|
|
14
|
-
import './schemas/StringSchema.js';
|
|
7
|
+
import './CommonSchema-DOh3bsL-.js';
|
package/lib/index.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunk5WHCMWXKjs = require('./chunk-5WHCMWXK.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
7
|
-
require('./chunk-
|
|
6
|
+
var _chunkG55SHHARjs = require('./chunk-G55SHHAR.js');
|
|
7
|
+
require('./chunk-X762EUSZ.js');
|
|
8
8
|
require('./chunk-VBTWYDEM.js');
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
var
|
|
13
|
+
var _chunk5YYRBKDPjs = require('./chunk-5YYRBKDP.js');
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
var
|
|
18
|
+
var _chunk5P6AZJCNjs = require('./chunk-5P6AZJCN.js');
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
|
|
@@ -25,5 +25,5 @@ var _chunkAY7HKAG2js = require('./chunk-AY7HKAG2.js');
|
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
exports.BuildSchemaError =
|
|
28
|
+
exports.BuildSchemaError = _chunk5P6AZJCNjs.BuildSchemaError; exports.ValidationError = _chunk5P6AZJCNjs.ValidationError; exports.clearLocales = _chunk5YYRBKDPjs.clearLocales; exports.guardException = _chunk5P6AZJCNjs.guardException; exports.parse = _chunk5WHCMWXKjs.parse; exports.parseOrFail = _chunkG55SHHARjs.parseOrFail; exports.setLocale = _chunk5YYRBKDPjs.setLocale; exports.setToDefaultLocale = _chunk5YYRBKDPjs.setToDefaultLocale;
|
|
29
29
|
//# sourceMappingURL=index.js.map
|
package/lib/index.mjs
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import {
|
|
2
2
|
parse
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-TV5IZY4L.mjs";
|
|
4
4
|
import {
|
|
5
5
|
parseOrFail
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-
|
|
6
|
+
} from "./chunk-TRGMD7LA.mjs";
|
|
7
|
+
import "./chunk-BNCT7NOR.mjs";
|
|
8
8
|
import "./chunk-YBVMP4EI.mjs";
|
|
9
9
|
import {
|
|
10
10
|
clearLocales,
|
|
11
11
|
setLocale,
|
|
12
12
|
setToDefaultLocale
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-H32B3NHW.mjs";
|
|
14
14
|
import {
|
|
15
15
|
BuildSchemaError,
|
|
16
16
|
ValidationError,
|
|
17
17
|
guardException
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-FGZKNBDP.mjs";
|
|
19
19
|
export {
|
|
20
20
|
BuildSchemaError,
|
|
21
21
|
ValidationError,
|
package/lib/parse.d.mts
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
import { InferType } from './InferType.mjs';
|
|
2
|
-
import { C as CommonSchema } from './CommonSchema-
|
|
2
|
+
import { C as CommonSchema } from './CommonSchema-wi9MOXGF.mjs';
|
|
3
3
|
import { ValidationErrorData } from './commonTypes.mjs';
|
|
4
|
-
import './schemas/ArraySchema.mjs';
|
|
5
|
-
import './schemas/BigIntSchema.mjs';
|
|
6
|
-
import './schemas/BooleanSchema.mjs';
|
|
7
|
-
import './schemas/DateSchema.mjs';
|
|
8
|
-
import './schemas/NumberSchema.mjs';
|
|
9
|
-
import './schemas/ObjectSchema.mjs';
|
|
10
|
-
import './schemas/StringSchema.mjs';
|
|
11
4
|
|
|
12
5
|
interface ParseOptions {
|
|
13
6
|
/**
|