bguard 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +270 -122
- 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,16 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
NumberSchema
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
5
|
-
import "../chunk-
|
|
3
|
+
} from "../chunk-CHUPE6SJ.mjs";
|
|
4
|
+
import "../chunk-C3EDEQ3W.mjs";
|
|
5
|
+
import "../chunk-K7X6DVM2.mjs";
|
|
6
6
|
import "../chunk-ASZW6XRM.mjs";
|
|
7
|
-
import "../chunk-
|
|
8
|
-
import "../chunk-
|
|
9
|
-
import "../chunk-
|
|
10
|
-
import "../chunk-
|
|
7
|
+
import "../chunk-H6LHV3EA.mjs";
|
|
8
|
+
import "../chunk-7NBOVYSP.mjs";
|
|
9
|
+
import "../chunk-TRGMD7LA.mjs";
|
|
10
|
+
import "../chunk-BNCT7NOR.mjs";
|
|
11
11
|
import "../chunk-YBVMP4EI.mjs";
|
|
12
|
-
import "../chunk-
|
|
13
|
-
import "../chunk-
|
|
12
|
+
import "../chunk-H32B3NHW.mjs";
|
|
13
|
+
import "../chunk-FGZKNBDP.mjs";
|
|
14
14
|
export {
|
|
15
15
|
NumberSchema
|
|
16
16
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { C as CommonSchema, V as ValidatorContext, O as ObjectShapeSchemaType } from '../CommonSchema-
|
|
1
|
+
import { C as CommonSchema, V as ValidatorContext, O as ObjectShapeSchemaType } from '../CommonSchema-wi9MOXGF.mjs';
|
|
2
|
+
import '../InferType.mjs';
|
|
2
3
|
import '../commonTypes.mjs';
|
|
3
4
|
|
|
4
5
|
declare class ObjectSchema extends CommonSchema {
|
|
@@ -24,8 +25,5 @@ declare class ObjectSchema extends CommonSchema {
|
|
|
24
25
|
*/
|
|
25
26
|
allowUnrecognized(): this;
|
|
26
27
|
}
|
|
27
|
-
type WithObject<Y extends ObjectShapeSchemaType> = ObjectSchema & {
|
|
28
|
-
validation_object: Y;
|
|
29
|
-
};
|
|
30
28
|
|
|
31
|
-
export { ObjectSchema
|
|
29
|
+
export { ObjectSchema };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { C as CommonSchema, V as ValidatorContext, O as ObjectShapeSchemaType } from '../CommonSchema-
|
|
1
|
+
import { C as CommonSchema, V as ValidatorContext, O as ObjectShapeSchemaType } from '../CommonSchema-DOh3bsL-.js';
|
|
2
|
+
import '../InferType.js';
|
|
2
3
|
import '../commonTypes.js';
|
|
3
4
|
|
|
4
5
|
declare class ObjectSchema extends CommonSchema {
|
|
@@ -24,8 +25,5 @@ declare class ObjectSchema extends CommonSchema {
|
|
|
24
25
|
*/
|
|
25
26
|
allowUnrecognized(): this;
|
|
26
27
|
}
|
|
27
|
-
type WithObject<Y extends ObjectShapeSchemaType> = ObjectSchema & {
|
|
28
|
-
validation_object: Y;
|
|
29
|
-
};
|
|
30
28
|
|
|
31
|
-
export { ObjectSchema
|
|
29
|
+
export { ObjectSchema };
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('../chunk-
|
|
5
|
-
require('../chunk-
|
|
6
|
-
require('../chunk-
|
|
3
|
+
var _chunkU4USIJV3js = require('../chunk-U4USIJV3.js');
|
|
4
|
+
require('../chunk-SHJVKSEZ.js');
|
|
5
|
+
require('../chunk-G55SHHAR.js');
|
|
6
|
+
require('../chunk-X762EUSZ.js');
|
|
7
7
|
require('../chunk-VBTWYDEM.js');
|
|
8
|
-
require('../chunk-
|
|
9
|
-
require('../chunk-
|
|
8
|
+
require('../chunk-5YYRBKDP.js');
|
|
9
|
+
require('../chunk-5P6AZJCN.js');
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
exports.ObjectSchema =
|
|
12
|
+
exports.ObjectSchema = _chunkU4USIJV3js.ObjectSchema;
|
|
13
13
|
//# sourceMappingURL=ObjectSchema.js.map
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ObjectSchema
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
5
|
-
import "../chunk-
|
|
6
|
-
import "../chunk-
|
|
3
|
+
} from "../chunk-YUMUCQKL.mjs";
|
|
4
|
+
import "../chunk-7NBOVYSP.mjs";
|
|
5
|
+
import "../chunk-TRGMD7LA.mjs";
|
|
6
|
+
import "../chunk-BNCT7NOR.mjs";
|
|
7
7
|
import "../chunk-YBVMP4EI.mjs";
|
|
8
|
-
import "../chunk-
|
|
9
|
-
import "../chunk-
|
|
8
|
+
import "../chunk-H32B3NHW.mjs";
|
|
9
|
+
import "../chunk-FGZKNBDP.mjs";
|
|
10
10
|
export {
|
|
11
11
|
ObjectSchema
|
|
12
12
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import '../
|
|
1
|
+
import { WithBGuardType } from '../commonTypes.mjs';
|
|
2
|
+
import { C as CommonSchema } from '../CommonSchema-wi9MOXGF.mjs';
|
|
3
|
+
import '../InferType.mjs';
|
|
3
4
|
|
|
4
5
|
declare class StringSchema extends CommonSchema {
|
|
5
6
|
protected _string: number;
|
|
@@ -12,7 +13,7 @@ declare class StringSchema extends CommonSchema {
|
|
|
12
13
|
*
|
|
13
14
|
* @example - string().equalTo('hello'); // Infers the type 'hello'
|
|
14
15
|
*/
|
|
15
|
-
equalTo<Y extends string>(expectedValue: Y):
|
|
16
|
+
equalTo<Y extends string>(expectedValue: Y): WithBGuardType<this, Y>;
|
|
16
17
|
/**
|
|
17
18
|
* Restricts the schema to match one of the specified values and infers the union of those values as the TypeScript type.
|
|
18
19
|
*
|
|
@@ -22,12 +23,8 @@ declare class StringSchema extends CommonSchema {
|
|
|
22
23
|
* @example
|
|
23
24
|
* string().oneOfValues(['foo', 'bar']); // Infers the type 'foo' | 'bar'
|
|
24
25
|
*/
|
|
25
|
-
oneOfValues<Y extends string>(expectedValue: Y[]):
|
|
26
|
+
oneOfValues<Y extends string>(expectedValue: Y[]): WithBGuardType<this, Y>;
|
|
26
27
|
private limitCheck;
|
|
27
28
|
}
|
|
28
|
-
type WithString<T extends StringSchema, Y = string> = T & {
|
|
29
|
-
validation_string: Y;
|
|
30
|
-
};
|
|
31
|
-
type ExtractFromString<T> = T extends WithString<StringSchema, infer Y> ? Y : never;
|
|
32
29
|
|
|
33
|
-
export {
|
|
30
|
+
export { StringSchema };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import '../
|
|
1
|
+
import { WithBGuardType } from '../commonTypes.js';
|
|
2
|
+
import { C as CommonSchema } from '../CommonSchema-DOh3bsL-.js';
|
|
3
|
+
import '../InferType.js';
|
|
3
4
|
|
|
4
5
|
declare class StringSchema extends CommonSchema {
|
|
5
6
|
protected _string: number;
|
|
@@ -12,7 +13,7 @@ declare class StringSchema extends CommonSchema {
|
|
|
12
13
|
*
|
|
13
14
|
* @example - string().equalTo('hello'); // Infers the type 'hello'
|
|
14
15
|
*/
|
|
15
|
-
equalTo<Y extends string>(expectedValue: Y):
|
|
16
|
+
equalTo<Y extends string>(expectedValue: Y): WithBGuardType<this, Y>;
|
|
16
17
|
/**
|
|
17
18
|
* Restricts the schema to match one of the specified values and infers the union of those values as the TypeScript type.
|
|
18
19
|
*
|
|
@@ -22,12 +23,8 @@ declare class StringSchema extends CommonSchema {
|
|
|
22
23
|
* @example
|
|
23
24
|
* string().oneOfValues(['foo', 'bar']); // Infers the type 'foo' | 'bar'
|
|
24
25
|
*/
|
|
25
|
-
oneOfValues<Y extends string>(expectedValue: Y[]):
|
|
26
|
+
oneOfValues<Y extends string>(expectedValue: Y[]): WithBGuardType<this, Y>;
|
|
26
27
|
private limitCheck;
|
|
27
28
|
}
|
|
28
|
-
type WithString<T extends StringSchema, Y = string> = T & {
|
|
29
|
-
validation_string: Y;
|
|
30
|
-
};
|
|
31
|
-
type ExtractFromString<T> = T extends WithString<StringSchema, infer Y> ? Y : never;
|
|
32
29
|
|
|
33
|
-
export {
|
|
30
|
+
export { StringSchema };
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('../chunk-
|
|
5
|
-
require('../chunk-
|
|
3
|
+
var _chunkZ6QU36MMjs = require('../chunk-Z6QU36MM.js');
|
|
4
|
+
require('../chunk-HP3DRZWK.js');
|
|
5
|
+
require('../chunk-IZ3CBVEE.js');
|
|
6
6
|
require('../chunk-42J6CHIO.js');
|
|
7
|
-
require('../chunk-
|
|
8
|
-
require('../chunk-
|
|
9
|
-
require('../chunk-
|
|
10
|
-
require('../chunk-
|
|
7
|
+
require('../chunk-QIDWASOC.js');
|
|
8
|
+
require('../chunk-SHJVKSEZ.js');
|
|
9
|
+
require('../chunk-G55SHHAR.js');
|
|
10
|
+
require('../chunk-X762EUSZ.js');
|
|
11
11
|
require('../chunk-VBTWYDEM.js');
|
|
12
|
-
require('../chunk-
|
|
13
|
-
require('../chunk-
|
|
12
|
+
require('../chunk-5YYRBKDP.js');
|
|
13
|
+
require('../chunk-5P6AZJCN.js');
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
exports.StringSchema =
|
|
16
|
+
exports.StringSchema = _chunkZ6QU36MMjs.StringSchema;
|
|
17
17
|
//# sourceMappingURL=StringSchema.js.map
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
StringSchema
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
5
|
-
import "../chunk-
|
|
3
|
+
} from "../chunk-FP5QAEVQ.mjs";
|
|
4
|
+
import "../chunk-C3EDEQ3W.mjs";
|
|
5
|
+
import "../chunk-K7X6DVM2.mjs";
|
|
6
6
|
import "../chunk-ASZW6XRM.mjs";
|
|
7
|
-
import "../chunk-
|
|
8
|
-
import "../chunk-
|
|
9
|
-
import "../chunk-
|
|
10
|
-
import "../chunk-
|
|
7
|
+
import "../chunk-H6LHV3EA.mjs";
|
|
8
|
+
import "../chunk-7NBOVYSP.mjs";
|
|
9
|
+
import "../chunk-TRGMD7LA.mjs";
|
|
10
|
+
import "../chunk-BNCT7NOR.mjs";
|
|
11
11
|
import "../chunk-YBVMP4EI.mjs";
|
|
12
|
-
import "../chunk-
|
|
13
|
-
import "../chunk-
|
|
12
|
+
import "../chunk-H32B3NHW.mjs";
|
|
13
|
+
import "../chunk-FGZKNBDP.mjs";
|
|
14
14
|
export {
|
|
15
15
|
StringSchema
|
|
16
16
|
};
|
package/lib/translationMap.js
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
7
|
-
require('./chunk-
|
|
6
|
+
var _chunk5YYRBKDPjs = require('./chunk-5YYRBKDP.js');
|
|
7
|
+
require('./chunk-5P6AZJCN.js');
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
exports.clearLocales =
|
|
13
|
+
exports.clearLocales = _chunk5YYRBKDPjs.clearLocales; exports.getTranslationByLocale = _chunk5YYRBKDPjs.getTranslationByLocale; exports.setLocale = _chunk5YYRBKDPjs.setLocale; exports.setToDefaultLocale = _chunk5YYRBKDPjs.setToDefaultLocale;
|
|
14
14
|
//# sourceMappingURL=translationMap.js.map
|
package/lib/translationMap.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { ExceptionContext, PrimitiveType, RequiredValidation } from './commonTypes.mjs';
|
|
2
|
-
|
|
3
|
-
declare const ctxSymbol: unique symbol;
|
|
4
|
-
|
|
5
|
-
declare function innerCheck(schema: CommonSchema, receivedValue: unknown, exCtx: ExceptionContext): unknown;
|
|
6
|
-
|
|
7
|
-
type ObjectShapeSchemaType = Record<string, CommonSchema>;
|
|
8
|
-
interface ValidatorContext {
|
|
9
|
-
type: PrimitiveType[];
|
|
10
|
-
isNullable?: boolean;
|
|
11
|
-
isOptional?: boolean;
|
|
12
|
-
requiredValidations: RequiredValidation[];
|
|
13
|
-
array?: CommonSchema;
|
|
14
|
-
object?: ObjectShapeSchemaType;
|
|
15
|
-
allowUnrecognizedObjectProps?: boolean;
|
|
16
|
-
strictType?: boolean;
|
|
17
|
-
strictTypeValue?: unknown;
|
|
18
|
-
date?: boolean;
|
|
19
|
-
defaultValue?: unknown;
|
|
20
|
-
}
|
|
21
|
-
declare class CommonSchema {
|
|
22
|
-
[ctxSymbol]: ValidatorContext;
|
|
23
|
-
constructor(ctx: ValidatorContext);
|
|
24
|
-
/**
|
|
25
|
-
* @param validators - One or more custom validation functions.
|
|
26
|
-
* @returns {this} The schema instance with the added custom validation.
|
|
27
|
-
*/
|
|
28
|
-
custom(...validators: RequiredValidation[]): this;
|
|
29
|
-
/**
|
|
30
|
-
* Marks the schema as nullable, allowing the value to be `null`.
|
|
31
|
-
*
|
|
32
|
-
* @returns {WithNull<this>} The schema instance marked as nullable.
|
|
33
|
-
*/
|
|
34
|
-
nullable(): WithNull<this>;
|
|
35
|
-
/**
|
|
36
|
-
* Marks the schema as optional, allowing the value to be `undefined`.
|
|
37
|
-
*
|
|
38
|
-
* @returns {WithUndefined<this>} The schema instance marked as optional.
|
|
39
|
-
*/
|
|
40
|
-
optional(): WithUndefined<this>;
|
|
41
|
-
/**
|
|
42
|
-
* Marks the schema as optional, allowing the value to be `undefined`.
|
|
43
|
-
*
|
|
44
|
-
* @returns {this} The schema instance. This method should be used as a last one because it does the check of previous methods and
|
|
45
|
-
*/
|
|
46
|
-
default(defaultValue: unknown): this;
|
|
47
|
-
protected defaultValueCheck(): void;
|
|
48
|
-
}
|
|
49
|
-
type WithNull<T extends CommonSchema> = T & {
|
|
50
|
-
validation_null: true;
|
|
51
|
-
};
|
|
52
|
-
type WithUndefined<T extends CommonSchema> = T & {
|
|
53
|
-
validation_undefined: true;
|
|
54
|
-
};
|
|
55
|
-
type TypeMapping = {
|
|
56
|
-
number: number;
|
|
57
|
-
string: string;
|
|
58
|
-
boolean: boolean;
|
|
59
|
-
undefined: undefined;
|
|
60
|
-
object: object;
|
|
61
|
-
function: Function;
|
|
62
|
-
symbol: symbol;
|
|
63
|
-
bigint: bigint;
|
|
64
|
-
};
|
|
65
|
-
type WithMix<Y = unknown> = CommonSchema & {
|
|
66
|
-
validation_mix: Y;
|
|
67
|
-
};
|
|
68
|
-
type ExtractFromMix<T> = T extends WithMix<infer X> ? X : never;
|
|
69
|
-
type MapMixTypes<T extends PrimitiveType[]> = T extends (infer U)[] ? U extends keyof TypeMapping ? TypeMapping[U] : never : never;
|
|
70
|
-
|
|
71
|
-
export { CommonSchema as C, type ExtractFromMix as E, type MapMixTypes as M, type ObjectShapeSchemaType as O, type ValidatorContext as V, type WithMix as W, type WithUndefined as a, type WithNull as b, ctxSymbol as c, innerCheck as i };
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { ExceptionContext, PrimitiveType, RequiredValidation } from './commonTypes.js';
|
|
2
|
-
|
|
3
|
-
declare const ctxSymbol: unique symbol;
|
|
4
|
-
|
|
5
|
-
declare function innerCheck(schema: CommonSchema, receivedValue: unknown, exCtx: ExceptionContext): unknown;
|
|
6
|
-
|
|
7
|
-
type ObjectShapeSchemaType = Record<string, CommonSchema>;
|
|
8
|
-
interface ValidatorContext {
|
|
9
|
-
type: PrimitiveType[];
|
|
10
|
-
isNullable?: boolean;
|
|
11
|
-
isOptional?: boolean;
|
|
12
|
-
requiredValidations: RequiredValidation[];
|
|
13
|
-
array?: CommonSchema;
|
|
14
|
-
object?: ObjectShapeSchemaType;
|
|
15
|
-
allowUnrecognizedObjectProps?: boolean;
|
|
16
|
-
strictType?: boolean;
|
|
17
|
-
strictTypeValue?: unknown;
|
|
18
|
-
date?: boolean;
|
|
19
|
-
defaultValue?: unknown;
|
|
20
|
-
}
|
|
21
|
-
declare class CommonSchema {
|
|
22
|
-
[ctxSymbol]: ValidatorContext;
|
|
23
|
-
constructor(ctx: ValidatorContext);
|
|
24
|
-
/**
|
|
25
|
-
* @param validators - One or more custom validation functions.
|
|
26
|
-
* @returns {this} The schema instance with the added custom validation.
|
|
27
|
-
*/
|
|
28
|
-
custom(...validators: RequiredValidation[]): this;
|
|
29
|
-
/**
|
|
30
|
-
* Marks the schema as nullable, allowing the value to be `null`.
|
|
31
|
-
*
|
|
32
|
-
* @returns {WithNull<this>} The schema instance marked as nullable.
|
|
33
|
-
*/
|
|
34
|
-
nullable(): WithNull<this>;
|
|
35
|
-
/**
|
|
36
|
-
* Marks the schema as optional, allowing the value to be `undefined`.
|
|
37
|
-
*
|
|
38
|
-
* @returns {WithUndefined<this>} The schema instance marked as optional.
|
|
39
|
-
*/
|
|
40
|
-
optional(): WithUndefined<this>;
|
|
41
|
-
/**
|
|
42
|
-
* Marks the schema as optional, allowing the value to be `undefined`.
|
|
43
|
-
*
|
|
44
|
-
* @returns {this} The schema instance. This method should be used as a last one because it does the check of previous methods and
|
|
45
|
-
*/
|
|
46
|
-
default(defaultValue: unknown): this;
|
|
47
|
-
protected defaultValueCheck(): void;
|
|
48
|
-
}
|
|
49
|
-
type WithNull<T extends CommonSchema> = T & {
|
|
50
|
-
validation_null: true;
|
|
51
|
-
};
|
|
52
|
-
type WithUndefined<T extends CommonSchema> = T & {
|
|
53
|
-
validation_undefined: true;
|
|
54
|
-
};
|
|
55
|
-
type TypeMapping = {
|
|
56
|
-
number: number;
|
|
57
|
-
string: string;
|
|
58
|
-
boolean: boolean;
|
|
59
|
-
undefined: undefined;
|
|
60
|
-
object: object;
|
|
61
|
-
function: Function;
|
|
62
|
-
symbol: symbol;
|
|
63
|
-
bigint: bigint;
|
|
64
|
-
};
|
|
65
|
-
type WithMix<Y = unknown> = CommonSchema & {
|
|
66
|
-
validation_mix: Y;
|
|
67
|
-
};
|
|
68
|
-
type ExtractFromMix<T> = T extends WithMix<infer X> ? X : never;
|
|
69
|
-
type MapMixTypes<T extends PrimitiveType[]> = T extends (infer U)[] ? U extends keyof TypeMapping ? TypeMapping[U] : never : never;
|
|
70
|
-
|
|
71
|
-
export { CommonSchema as C, type ExtractFromMix as E, type MapMixTypes as M, type ObjectShapeSchemaType as O, type ValidatorContext as V, type WithMix as W, type WithUndefined as a, type WithNull as b, ctxSymbol as c, innerCheck as i };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-2D5QE7F4.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;ACZO,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,EAAuC;AACtE,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,EAAyC;AAC5E,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;ADUA;AACA;AACE;AACF,oCAAC","file":"/home/runner/work/bguard/bguard/lib/chunk-2D5QE7F4.js","sourcesContent":[null,"import { equalTo } from '../asserts/mix/equalTo';\nimport { oneOfValues } from '../asserts/mix/oneOfValues';\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): WithString<this, Y> {\n this.limitCheck();\n _setStrictType(this, `'${expectedValue}'`);\n\n return this.custom(equalTo(expectedValue)) as WithString<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[]): WithString<this, Y> {\n this.limitCheck();\n _setStrictType(\n this,\n expectedValue.map((el) => `'${el}'`),\n );\n return this.custom(oneOfValues(expectedValue)) as WithString<this, Y>;\n }\n\n private limitCheck() {\n if (this.limit) throw new BuildSchemaError(ONLY_ONCE);\n this.limit = true;\n }\n}\n\nexport type WithString<T extends StringSchema, Y = string> = T & { validation_string: Y };\nexport type ExtractFromString<T> = T extends WithString<StringSchema, infer Y> ? Y : never;\n"]}
|
package/lib/chunk-3IOQH3K4.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
-
|
|
3
|
-
var _chunkPESVL5YJjs = require('./chunk-PESVL5YJ.js');
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var _chunkPIBDJJUUjs = require('./chunk-PIBDJJUU.js');
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var _chunkAY7HKAG2js = require('./chunk-AY7HKAG2.js');
|
|
10
|
-
|
|
11
|
-
// src/schemas/CommonSchema.ts
|
|
12
|
-
var CommonSchema = class {
|
|
13
|
-
|
|
14
|
-
constructor(ctx) {
|
|
15
|
-
this[_chunkPIBDJJUUjs.ctxSymbol] = ctx;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* @param validators - One or more custom validation functions.
|
|
19
|
-
* @returns {this} The schema instance with the added custom validation.
|
|
20
|
-
*/
|
|
21
|
-
custom(...validators) {
|
|
22
|
-
this.defaultValueCheck();
|
|
23
|
-
this[_chunkPIBDJJUUjs.ctxSymbol].requiredValidations.push(...validators);
|
|
24
|
-
return this;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Marks the schema as nullable, allowing the value to be `null`.
|
|
28
|
-
*
|
|
29
|
-
* @returns {WithNull<this>} The schema instance marked as nullable.
|
|
30
|
-
*/
|
|
31
|
-
nullable() {
|
|
32
|
-
this.defaultValueCheck();
|
|
33
|
-
this[_chunkPIBDJJUUjs.ctxSymbol].isNullable = true;
|
|
34
|
-
return this;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Marks the schema as optional, allowing the value to be `undefined`.
|
|
38
|
-
*
|
|
39
|
-
* @returns {WithUndefined<this>} The schema instance marked as optional.
|
|
40
|
-
*/
|
|
41
|
-
optional() {
|
|
42
|
-
this.defaultValueCheck();
|
|
43
|
-
this[_chunkPIBDJJUUjs.ctxSymbol].isOptional = true;
|
|
44
|
-
return this;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Marks the schema as optional, allowing the value to be `undefined`.
|
|
48
|
-
*
|
|
49
|
-
* @returns {this} The schema instance. This method should be used as a last one because it does the check of previous methods and
|
|
50
|
-
*/
|
|
51
|
-
default(defaultValue) {
|
|
52
|
-
const ctx = this[_chunkPIBDJJUUjs.ctxSymbol];
|
|
53
|
-
if (ctx.isOptional) {
|
|
54
|
-
throw new (0, _chunkAY7HKAG2js.BuildSchemaError)(`Cannot call method 'default' after method 'optional'`);
|
|
55
|
-
}
|
|
56
|
-
try {
|
|
57
|
-
_chunkPESVL5YJjs.parseOrFail.call(void 0, this, defaultValue);
|
|
58
|
-
} catch (e) {
|
|
59
|
-
throw new (0, _chunkAY7HKAG2js.BuildSchemaError)(e.message);
|
|
60
|
-
}
|
|
61
|
-
this[_chunkPIBDJJUUjs.ctxSymbol].defaultValue = defaultValue;
|
|
62
|
-
return this;
|
|
63
|
-
}
|
|
64
|
-
defaultValueCheck() {
|
|
65
|
-
if (this[_chunkPIBDJJUUjs.ctxSymbol].defaultValue !== void 0) {
|
|
66
|
-
throw new (0, _chunkAY7HKAG2js.BuildSchemaError)("Default value must be the last method called in schema");
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
exports.CommonSchema = CommonSchema;
|
|
74
|
-
//# sourceMappingURL=chunk-3IOQH3K4.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-3IOQH3K4.js","../src/schemas/CommonSchema.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACA;ACWO,IAAM,aAAA,EAAN,MAAmB;AAAA,EACxB;AAAU,EACV,WAAA,CAAY,GAAA,EAAuB;AACjC,IAAA,IAAA,CAAK,0BAAS,EAAA,EAAI,GAAA;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,MAAA,CAAA,GAAU,UAAA,EAAwC;AACvD,IAAA,IAAA,CAAK,iBAAA,CAAkB,CAAA;AACvB,IAAA,IAAA,CAAK,0BAAS,CAAA,CAAE,mBAAA,CAAoB,IAAA,CAAK,GAAG,UAAU,CAAA;AACtD,IAAA,OAAO,IAAA;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,QAAA,CAAA,EAA2B;AAChC,IAAA,IAAA,CAAK,iBAAA,CAAkB,CAAA;AACvB,IAAA,IAAA,CAAK,0BAAS,CAAA,CAAE,WAAA,EAAa,IAAA;AAC7B,IAAA,OAAO,IAAA;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,QAAA,CAAA,EAAgC;AACrC,IAAA,IAAA,CAAK,iBAAA,CAAkB,CAAA;AACvB,IAAA,IAAA,CAAK,0BAAS,CAAA,CAAE,WAAA,EAAa,IAAA;AAC7B,IAAA,OAAO,IAAA;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,OAAA,CAAQ,YAAA,EAA6B;AAC1C,IAAA,MAAM,IAAA,EAAM,IAAA,CAAK,0BAAS,CAAA;AAC1B,IAAA,GAAA,CAAI,GAAA,CAAI,UAAA,EAAY;AAClB,MAAA,MAAM,IAAI,sCAAA,CAAiB,CAAA,oDAAA,CAAsD,CAAA;AAAA,IACnF;AAEA,IAAA,IAAI;AACF,MAAA,0CAAA,IAAY,EAAM,YAAY,CAAA;AAAA,IAChC,EAAA,MAAA,CAAS,CAAA,EAAG;AACV,MAAA,MAAM,IAAI,sCAAA,CAAkB,CAAA,CAAY,OAAO,CAAA;AAAA,IACjD;AAEA,IAAA,IAAA,CAAK,0BAAS,CAAA,CAAE,aAAA,EAAe,YAAA;AAC/B,IAAA,OAAO,IAAA;AAAA,EACT;AAAA,EAEU,iBAAA,CAAA,EAAoB;AAC5B,IAAA,GAAA,CAAI,IAAA,CAAK,0BAAS,CAAA,CAAE,aAAA,IAAiB,KAAA,CAAA,EAAW;AAC9C,MAAA,MAAM,IAAI,sCAAA,CAAiB,wDAAwD,CAAA;AAAA,IACrF;AAAA,EACF;AACF,CAAA;ADhBA;AACA;AACE;AACF,oCAAC","file":"/home/runner/work/bguard/bguard/lib/chunk-3IOQH3K4.js","sourcesContent":[null,"import { PrimitiveType, RequiredValidation } from '../commonTypes';\nimport { BuildSchemaError } from '../exceptions';\nimport { ctxSymbol } from '../helpers/core';\nimport { parseOrFail } from '../parseOrFail';\n\nexport type ObjectShapeSchemaType = Record<string, CommonSchema>;\n\nexport interface ValidatorContext {\n type: PrimitiveType[];\n isNullable?: boolean;\n isOptional?: boolean;\n requiredValidations: RequiredValidation[];\n array?: CommonSchema;\n object?: ObjectShapeSchemaType;\n allowUnrecognizedObjectProps?: boolean;\n strictType?: boolean;\n strictTypeValue?: unknown;\n date?: boolean;\n defaultValue?: unknown;\n}\n\nexport class CommonSchema {\n [ctxSymbol]: ValidatorContext;\n constructor(ctx: ValidatorContext) {\n this[ctxSymbol] = ctx;\n }\n\n /**\n * @param validators - One or more custom validation functions.\n * @returns {this} The schema instance with the added custom validation.\n */\n public custom(...validators: RequiredValidation[]): this {\n this.defaultValueCheck();\n this[ctxSymbol].requiredValidations.push(...validators);\n return this;\n }\n\n /**\n * Marks the schema as nullable, allowing the value to be `null`.\n *\n * @returns {WithNull<this>} The schema instance marked as nullable.\n */\n public nullable(): WithNull<this> {\n this.defaultValueCheck();\n this[ctxSymbol].isNullable = true;\n return this as WithNull<this>;\n }\n\n /**\n * Marks the schema as optional, allowing the value to be `undefined`.\n *\n * @returns {WithUndefined<this>} The schema instance marked as optional.\n */\n public optional(): WithUndefined<this> {\n this.defaultValueCheck();\n this[ctxSymbol].isOptional = true;\n return this as WithUndefined<this>;\n }\n\n /**\n * Marks the schema as optional, allowing the value to be `undefined`.\n *\n * @returns {this} The schema instance. This method should be used as a last one because it does the check of previous methods and\n */\n public default(defaultValue: unknown): this {\n const ctx = this[ctxSymbol];\n if (ctx.isOptional) {\n throw new BuildSchemaError(`Cannot call method 'default' after method 'optional'`);\n }\n\n try {\n parseOrFail(this, defaultValue);\n } catch (e) {\n throw new BuildSchemaError((e as Error).message);\n }\n\n this[ctxSymbol].defaultValue = defaultValue;\n return this;\n }\n\n protected defaultValueCheck() {\n if (this[ctxSymbol].defaultValue !== undefined) {\n throw new BuildSchemaError('Default value must be the last method called in schema');\n }\n }\n}\n\nexport type WithNull<T extends CommonSchema> = T & { validation_null: true };\nexport type WithUndefined<T extends CommonSchema> = T & { validation_undefined: true };\n\ntype TypeMapping = {\n number: number;\n string: string;\n boolean: boolean;\n undefined: undefined;\n object: object;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n function: Function;\n symbol: symbol;\n bigint: bigint;\n};\n\nexport type WithMix<Y = unknown> = CommonSchema & { validation_mix: Y };\nexport type ExtractFromMix<T> = T extends WithMix<infer X> ? X : never;\n\nexport type MapMixTypes<T extends PrimitiveType[]> = T extends (infer U)[]\n ? U extends keyof TypeMapping\n ? TypeMapping[U]\n : never\n : never;\n"]}
|
package/lib/chunk-3ZPLJ5KC.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
-
|
|
3
|
-
var _chunkPIBDJJUUjs = require('./chunk-PIBDJJUU.js');
|
|
4
|
-
|
|
5
|
-
// src/helpers/setStrictType.ts
|
|
6
|
-
function _setStrictType(that, val) {
|
|
7
|
-
that[_chunkPIBDJJUUjs.ctxSymbol].strictType = true;
|
|
8
|
-
that[_chunkPIBDJJUUjs.ctxSymbol].strictTypeValue = val;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
exports._setStrictType = _setStrictType;
|
|
14
|
-
//# sourceMappingURL=chunk-3ZPLJ5KC.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/helpers/core.ts"],"sourcesContent":["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 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 schemaData.requiredValidations.forEach((requiredValidation) => {\n requiredValidation(receivedValue, exCtx);\n });\n\n if (schemaData.array) {\n if (!Array.isArray(receivedValue)) return guardException('Array', receivedValue, exCtx, commonTmap['c:array']);\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, { ...exCtx, pathToError: `${pathToError}[${i}]` });\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 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 });\n\n parsedReceivedValue[keyOfSchema] = parsedReceivedObjectValuePropery;\n }\n\n return parsedReceivedValue;\n }\n\n return receivedValue;\n}\n"],"mappings":";;;;;;;;AAAO,IAAM,YAAY,OAAO,eAAe;AAOxC,SAAS,WAAW,QAAsB,eAAwB,OAAkC;AACzG,QAAM,aAAa,MAAM;AACzB,QAAM,aAAa,OAAO,SAAS;AACnC,MAAI,kBAAkB,QAAW;AAC/B,QAAI,WAAW,iBAAiB,OAAW,QAAO,WAAW;AAC7D,QAAI,CAAC,WAAW,WAAY,gBAAe,YAAY,eAAe,OAAO,WAAW,YAAY,CAAC;AACrG,WAAO;AAAA,EACT;AAEA,MAAI,kBAAkB,MAAM;AAC1B,QAAI,CAAC,WAAW,WAAY,gBAAe,YAAY,eAAe,OAAO,WAAW,YAAY,CAAC;AACrG,WAAO;AAAA,EACT;AAEA,MAAI,WAAW,MAAM;AACnB,QAAI,CAAC,iBAAiB,aAAa,EAAG,gBAAe,QAAQ,eAAe,OAAO,WAAW,QAAQ,CAAC;AAAA,EACzG;AAEA,QAAM,YAAY,OAAO;AAEzB,MAAI,WAAW,KAAK,QAAQ;AAC1B,QAAI,CAAC,WAAW,KAAK,SAAS,SAAS;AACrC,qBAAe,WAAW,MAAM,WAAW,OAAO,WAAW,eAAe,CAAC;AAAA,EACjF;AAEA,aAAW,oBAAoB,QAAQ,CAAC,uBAAuB;AAC7D,uBAAmB,eAAe,KAAK;AAAA,EACzC,CAAC;AAED,MAAI,WAAW,OAAO;AACpB,QAAI,CAAC,MAAM,QAAQ,aAAa,EAAG,QAAO,eAAe,SAAS,eAAe,OAAO,WAAW,SAAS,CAAC;AAC7G,UAAMA,UAAS,WAAW;AAC1B,UAAM,cAAc,MAAM;AAC1B,UAAM,sBAAiC,CAAC;AACxC,kBAAc,QAAQ,CAAC,MAAM,MAAM;AACjC,YAAM,gBAAgB,WAAWA,SAAQ,MAAM,EAAE,GAAG,OAAO,aAAa,GAAG,WAAW,IAAI,CAAC,IAAI,CAAC;AAChG,0BAAoB,KAAK,aAAa;AAAA,IACxC,CAAC;AAED,WAAO;AAAA,EACT;AAEA,MAAI,WAAW,QAAQ;AACrB,QAAI,cAAc,SAAU,gBAAe,UAAU,eAAe,OAAO,WAAW,cAAc,CAAC;AACrG,QAAI,MAAM,QAAQ,aAAa,EAAG,gBAAe,UAAU,eAAe,OAAO,WAAW,qBAAqB,CAAC;AAClH,UAAM,cAAc,WAAW;AAC/B,UAAM,sBAA+C,CAAC;AAEtD,QAAI,CAAC,WAAW,8BAA8B;AAC5C,iBAAW,uBAAuB,OAAO,KAAK,aAAa,GAAG;AAC5D,YAAI,YAAY,mBAAmB,MAAM;AACvC,yBAAe,yBAAyB,qBAAqB,OAAO,WAAW,wBAAwB,CAAC;AAAA,MAC5G;AAAA,IACF;AAEA,UAAM,cAAc,MAAM;AAC1B,eAAW,CAAC,aAAa,aAAa,KAAK,OAAO,QAAQ,WAAW,GAAG;AACtE,YAAM,6BAA8B,cAA0C,WAAW;AACzF,UAAI,+BAA+B,QAAW;AAC5C,YAAI,CAAC,cAAc,SAAS,EAAE;AAC5B,yBAAe,YAAY,4BAA4B,OAAO,WAAW,oBAAoB,CAAC;AAAA,MAClG;AAEA,YAAM,mCAAmC,WAAW,eAAe,4BAA4B;AAAA,QAC7F,GAAG;AAAA,QACH,aAAa,GAAG,WAAW,IAAI,WAAW;AAAA,MAC5C,CAAC;AAED,0BAAoB,WAAW,IAAI;AAAA,IACrC;AAEA,WAAO;AAAA,EACT;AAEA,SAAO;AACT;","names":["schema"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/parseOrFail.ts"],"sourcesContent":["import type { InferType } from './InferType';\nimport type { CommonSchema } from './schemas/CommonSchema';\nimport { innerCheck } from './helpers/core';\nimport { getTranslationByLocale } from './translationMap';\nimport { ValidationError } from './exceptions';\ninterface ParseOptions {\n /**\n * Set language keyword to map error messages.\n * @default 'default'\n * @example 'sr' or 'Serbia' or any string to identify language\n */\n lng?: string;\n}\n\n/**\n * Parses and validates a value against the provided schema, returning a type-safe result.\n *\n * This function will throw a `ValidationError` if the value does not conform to the schema.\n * The inferred TypeScript type of the returned value will match the structure defined by the schema.\n *\n * @template T\n * @param {T} schema - The schema to validate the received value against. This schema dictates the expected structure and type of the value.\n * @param {unknown} receivedValue - The value to be validated and parsed according to the schema.\n * @param {ParseOptions} options - Options\n * @param {ParseOptions.lng} options.lng - Set language keyword to map Error message\n * @returns {InferType<T>} The validated value, with its TypeScript type inferred from the schema.\n *\n * @throws {ValidationError} If the received value does not match the schema, a `ValidationError` will be thrown.\n * @throws {Error} If an unexpected error occurs during validation, an error will be thrown with a generic message.\n *\n * @example\n * const schema = object({\n * name: string(),\n * age: number(),\n * });\n *\n * const result = parseOrFail(schema, { name: 'Alice', age: 30 });\n * // result will be inferred as { name: string; age: number }\n *\n * parseOrFail(schema, { name: 'Alice', age: '30' });\n * // Throws ValidationError because 'age' should be a number, not a string.\n */\nexport function parseOrFail<T extends CommonSchema>(\n schema: T,\n receivedValue: unknown,\n options?: ParseOptions,\n): InferType<T> {\n try {\n return innerCheck(schema, receivedValue, {\n t: getTranslationByLocale(options?.lng),\n pathToError: '',\n }) as InferType<T>;\n } catch (e) {\n if (e instanceof ValidationError) throw e;\n /* istanbul ignore next */\n throw new Error('Something unexpected happened');\n }\n}\n"],"mappings":";;;;;;;;;;;AA0CO,SAAS,YACd,QACA,eACA,SACc;AACd,MAAI;AACF,WAAO,WAAW,QAAQ,eAAe;AAAA,MACvC,GAAG,uBAAuB,SAAS,GAAG;AAAA,MACtC,aAAa;AAAA,IACf,CAAC;AAAA,EACH,SAAS,GAAG;AACV,QAAI,aAAa,gBAAiB,OAAM;AAExC,UAAM,IAAI,MAAM,+BAA+B;AAAA,EACjD;AACF;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-AN3VHQEQ.js","../src/parse.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACA;ACqDO,SAAS,KAAA,CACd,MAAA,EACA,aAAA,EACA,OAAA,EACgE;AAChE,EAAA,IAAI;AACF,IAAA,MAAM,IAAA,EAAwB;AAAA,MAC5B,CAAA,EAAG,qDAAA,gBAAuB,OAAA,2BAAS,KAAG,CAAA;AAAA,MACtC,WAAA,EAAa,EAAA;AAAA,MACb,YAAA,kBAAc,OAAA,6BAAS,cAAA;AAAA,MACvB,MAAA,EAAQ,CAAC;AAAA,IACX,CAAA;AAEA,IAAA,MAAM,YAAA,EAAc,yCAAA,MAAW,EAAQ,aAAA,EAAe,GAAG,CAAA;AAEzD,IAAA,GAAA,CAAI,GAAA,CAAI,aAAA,GAAgB,GAAA,CAAI,MAAA,CAAO,MAAA,EAAQ;AACzC,MAAA,OAAO,CAAC,GAAA,CAAI,MAAA,EAAQ,KAAA,CAAS,CAAA;AAAA,IAC/B;AAEA,IAAA,OAAO,CAAC,KAAA,CAAA,EAAW,WAAW,CAAA;AAAA,EAChC,EAAA,MAAA,CAAS,CAAA,EAAG;AACV,IAAA,GAAA,CAAI,EAAA,WAAa,gCAAA,EAAiB;AAChC,MAAA,OAAO,CAAA,CAAE,KAAA;AACT,MAAA,OAAO,CAAC,CAAC,CAAC,CAAA,EAAG,KAAA,CAAS,CAAA;AAAA,IACxB;AAEA,IAAA,OAAO;AAAA,MACL;AAAA,QACE;AAAA,UACE,OAAA,EAAS,+BAAA;AAAA,UACT,QAAA,EAAU,EAAA;AAAA,UACV,QAAA,EAAU,EAAA;AAAA,UACV,WAAA,EAAa;AAAA,QACf;AAAA,MACF,CAAA;AAAA,MACA,KAAA;AAAA,IACF,CAAA;AAAA,EACF;AACF;AD3DA;AACA;AACE;AACF,sBAAC","file":"/home/runner/work/bguard/bguard/lib/chunk-AN3VHQEQ.js","sourcesContent":[null,"import { InferType } from './InferType';\nimport { innerCheck } from './helpers/core';\nimport { getTranslationByLocale } from './translationMap';\nimport { ValidationError } from './exceptions';\nimport { CommonSchema } from './schemas/CommonSchema';\nimport { ExceptionContext, ValidationErrorData } from './commonTypes';\n\ninterface ParseOptions {\n /**\n * Set language keyword to map error messages.\n * @default 'default'\n * @example 'sr' or 'Serbia' or any string to identify language\n */\n lng?: string;\n\n /**\n * If true, collects all validation errors and returns them.\n * If false or undefined, returns the first validation error it can find and stops looking,\n * which provides a small runtime optimization.\n * @default undefined\n */\n getAllErrors?: boolean;\n}\n\n/**\n * Parses and validates a value against the provided schema, returning a type-safe parsedValue.\n *\n * This function will throw a `ValidationError` if the value does not conform to the schema.\n * The inferred TypeScript type of the returned value will match the structure defined by the schema.\n *\n * @template T\n * @param {T} schema - The schema to validate the received value against. This schema dictates the expected structure and type of the value.\n * @param {unknown} receivedValue - The value to be validated and parsed according to the schema.\n * @param {ParseOptions} options - Options\n * @param {ParseOptions.lng} options.lng - Set language keyword to map Error messages\n * @param {ParseOptions.lng} options.getAllErrors - If `false` or `undefined` - returns the first validation error it can find and stops looking, which provides a small runtime optimization.\n * @returns {[undefined, InferType<T>]} A tuple of [undefined, InferType<T>] if parsing is successful.\n * @returns {[ValidationErrorData[], undefined]} A tuple of [ValidationErrorData[], undefined]] if errors occur.\n *\n * @example\n * const schema = object({\n * name: string(),\n * age: number(),\n * });\n *\n * const [errors, parsedValue] = parse(schema, { name: 'Alice', age: 30 });\n * // parsedValue will be inferred as { name: string; age: number }\n *\n *\n * const [errors, parsedValue] = parse(schema, { name: 'Alice', age: '30' });\n * // First element in array \"errors\" will have an error because 'age' should be a number, not a string.\n * // Array 'errors' returns only one element.\n *\n *\n * const [errors, parsedValue] = parse(schema, { name: true, age: '30' }, { getAllErrors: true});\n * // Returns array \"errors\" with multiple errors because 'age' should be a number and 'name' a string.\n * // With provided options { getAllErrors: true}, we can expecte more than one error in 'errors' array.\n *\n *\n * const [errors, parsedValue] = parse(schema, { name: true, age: '30' }, { lng: 'SR'});\n * // First element in array \"errors\" will have an error because 'age' should be a number, not a string.\n * // With provided options { lng: 'SR'}, errors will be translated to a language mapped with keyword 'SR'\n */\nexport function parse<T extends CommonSchema>(\n schema: T,\n receivedValue: unknown,\n options?: ParseOptions,\n): [ValidationErrorData[], undefined] | [undefined, InferType<T>] {\n try {\n const ctx: ExceptionContext = {\n t: getTranslationByLocale(options?.lng),\n pathToError: '',\n getAllErrors: options?.getAllErrors,\n errors: [],\n };\n\n const parsedValue = innerCheck(schema, receivedValue, ctx) as InferType<T>;\n\n if (ctx.getAllErrors && ctx.errors.length) {\n return [ctx.errors, undefined];\n }\n\n return [undefined, parsedValue];\n } catch (e) {\n if (e instanceof ValidationError) {\n delete e.stack;\n return [[e], undefined];\n }\n /* istanbul ignore next */\n return [\n [\n {\n message: 'Something unexpected happened',\n expected: '',\n received: '',\n pathToError: '',\n },\n ],\n undefined,\n ];\n }\n}\n"]}
|
package/lib/chunk-AOUFWACR.mjs
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
parseOrFail
|
|
3
|
-
} from "./chunk-ADSMWGDJ.mjs";
|
|
4
|
-
import {
|
|
5
|
-
ctxSymbol
|
|
6
|
-
} from "./chunk-5LLJ22IG.mjs";
|
|
7
|
-
import {
|
|
8
|
-
BuildSchemaError
|
|
9
|
-
} from "./chunk-NP64RC7B.mjs";
|
|
10
|
-
|
|
11
|
-
// src/schemas/CommonSchema.ts
|
|
12
|
-
var CommonSchema = class {
|
|
13
|
-
[ctxSymbol];
|
|
14
|
-
constructor(ctx) {
|
|
15
|
-
this[ctxSymbol] = ctx;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* @param validators - One or more custom validation functions.
|
|
19
|
-
* @returns {this} The schema instance with the added custom validation.
|
|
20
|
-
*/
|
|
21
|
-
custom(...validators) {
|
|
22
|
-
this.defaultValueCheck();
|
|
23
|
-
this[ctxSymbol].requiredValidations.push(...validators);
|
|
24
|
-
return this;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Marks the schema as nullable, allowing the value to be `null`.
|
|
28
|
-
*
|
|
29
|
-
* @returns {WithNull<this>} The schema instance marked as nullable.
|
|
30
|
-
*/
|
|
31
|
-
nullable() {
|
|
32
|
-
this.defaultValueCheck();
|
|
33
|
-
this[ctxSymbol].isNullable = true;
|
|
34
|
-
return this;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Marks the schema as optional, allowing the value to be `undefined`.
|
|
38
|
-
*
|
|
39
|
-
* @returns {WithUndefined<this>} The schema instance marked as optional.
|
|
40
|
-
*/
|
|
41
|
-
optional() {
|
|
42
|
-
this.defaultValueCheck();
|
|
43
|
-
this[ctxSymbol].isOptional = true;
|
|
44
|
-
return this;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Marks the schema as optional, allowing the value to be `undefined`.
|
|
48
|
-
*
|
|
49
|
-
* @returns {this} The schema instance. This method should be used as a last one because it does the check of previous methods and
|
|
50
|
-
*/
|
|
51
|
-
default(defaultValue) {
|
|
52
|
-
const ctx = this[ctxSymbol];
|
|
53
|
-
if (ctx.isOptional) {
|
|
54
|
-
throw new BuildSchemaError(`Cannot call method 'default' after method 'optional'`);
|
|
55
|
-
}
|
|
56
|
-
try {
|
|
57
|
-
parseOrFail(this, defaultValue);
|
|
58
|
-
} catch (e) {
|
|
59
|
-
throw new BuildSchemaError(e.message);
|
|
60
|
-
}
|
|
61
|
-
this[ctxSymbol].defaultValue = defaultValue;
|
|
62
|
-
return this;
|
|
63
|
-
}
|
|
64
|
-
defaultValueCheck() {
|
|
65
|
-
if (this[ctxSymbol].defaultValue !== void 0) {
|
|
66
|
-
throw new BuildSchemaError("Default value must be the last method called in schema");
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
export {
|
|
72
|
-
CommonSchema
|
|
73
|
-
};
|
|
74
|
-
//# sourceMappingURL=chunk-AOUFWACR.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/schemas/CommonSchema.ts"],"sourcesContent":["import { PrimitiveType, RequiredValidation } from '../commonTypes';\nimport { BuildSchemaError } from '../exceptions';\nimport { ctxSymbol } from '../helpers/core';\nimport { parseOrFail } from '../parseOrFail';\n\nexport type ObjectShapeSchemaType = Record<string, CommonSchema>;\n\nexport interface ValidatorContext {\n type: PrimitiveType[];\n isNullable?: boolean;\n isOptional?: boolean;\n requiredValidations: RequiredValidation[];\n array?: CommonSchema;\n object?: ObjectShapeSchemaType;\n allowUnrecognizedObjectProps?: boolean;\n strictType?: boolean;\n strictTypeValue?: unknown;\n date?: boolean;\n defaultValue?: unknown;\n}\n\nexport class CommonSchema {\n [ctxSymbol]: ValidatorContext;\n constructor(ctx: ValidatorContext) {\n this[ctxSymbol] = ctx;\n }\n\n /**\n * @param validators - One or more custom validation functions.\n * @returns {this} The schema instance with the added custom validation.\n */\n public custom(...validators: RequiredValidation[]): this {\n this.defaultValueCheck();\n this[ctxSymbol].requiredValidations.push(...validators);\n return this;\n }\n\n /**\n * Marks the schema as nullable, allowing the value to be `null`.\n *\n * @returns {WithNull<this>} The schema instance marked as nullable.\n */\n public nullable(): WithNull<this> {\n this.defaultValueCheck();\n this[ctxSymbol].isNullable = true;\n return this as WithNull<this>;\n }\n\n /**\n * Marks the schema as optional, allowing the value to be `undefined`.\n *\n * @returns {WithUndefined<this>} The schema instance marked as optional.\n */\n public optional(): WithUndefined<this> {\n this.defaultValueCheck();\n this[ctxSymbol].isOptional = true;\n return this as WithUndefined<this>;\n }\n\n /**\n * Marks the schema as optional, allowing the value to be `undefined`.\n *\n * @returns {this} The schema instance. This method should be used as a last one because it does the check of previous methods and\n */\n public default(defaultValue: unknown): this {\n const ctx = this[ctxSymbol];\n if (ctx.isOptional) {\n throw new BuildSchemaError(`Cannot call method 'default' after method 'optional'`);\n }\n\n try {\n parseOrFail(this, defaultValue);\n } catch (e) {\n throw new BuildSchemaError((e as Error).message);\n }\n\n this[ctxSymbol].defaultValue = defaultValue;\n return this;\n }\n\n protected defaultValueCheck() {\n if (this[ctxSymbol].defaultValue !== undefined) {\n throw new BuildSchemaError('Default value must be the last method called in schema');\n }\n }\n}\n\nexport type WithNull<T extends CommonSchema> = T & { validation_null: true };\nexport type WithUndefined<T extends CommonSchema> = T & { validation_undefined: true };\n\ntype TypeMapping = {\n number: number;\n string: string;\n boolean: boolean;\n undefined: undefined;\n object: object;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n function: Function;\n symbol: symbol;\n bigint: bigint;\n};\n\nexport type WithMix<Y = unknown> = CommonSchema & { validation_mix: Y };\nexport type ExtractFromMix<T> = T extends WithMix<infer X> ? X : never;\n\nexport type MapMixTypes<T extends PrimitiveType[]> = T extends (infer U)[]\n ? U extends keyof TypeMapping\n ? TypeMapping[U]\n : never\n : never;\n"],"mappings":";;;;;;;;;;;AAqBO,IAAM,eAAN,MAAmB;AAAA,EACxB,CAAC,SAAS;AAAA,EACV,YAAY,KAAuB;AACjC,SAAK,SAAS,IAAI;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,UAAU,YAAwC;AACvD,SAAK,kBAAkB;AACvB,SAAK,SAAS,EAAE,oBAAoB,KAAK,GAAG,UAAU;AACtD,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,WAA2B;AAChC,SAAK,kBAAkB;AACvB,SAAK,SAAS,EAAE,aAAa;AAC7B,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,WAAgC;AACrC,SAAK,kBAAkB;AACvB,SAAK,SAAS,EAAE,aAAa;AAC7B,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,QAAQ,cAA6B;AAC1C,UAAM,MAAM,KAAK,SAAS;AAC1B,QAAI,IAAI,YAAY;AAClB,YAAM,IAAI,iBAAiB,sDAAsD;AAAA,IACnF;AAEA,QAAI;AACF,kBAAY,MAAM,YAAY;AAAA,IAChC,SAAS,GAAG;AACV,YAAM,IAAI,iBAAkB,EAAY,OAAO;AAAA,IACjD;AAEA,SAAK,SAAS,EAAE,eAAe;AAC/B,WAAO;AAAA,EACT;AAAA,EAEU,oBAAoB;AAC5B,QAAI,KAAK,SAAS,EAAE,iBAAiB,QAAW;AAC9C,YAAM,IAAI,iBAAiB,wDAAwD;AAAA,IACrF;AAAA,EACF;AACF;","names":[]}
|