bguard 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +208 -4
- package/lib/{CommonSchema-BbGNki0L.d.ts → CommonSchema-9RtxTxdX.d.ts} +3 -2
- package/lib/{CommonSchema-CjsYE4dC.d.mts → CommonSchema-DJmQ3F_9.d.mts} +3 -2
- package/lib/InferType.d.mts +5 -2
- package/lib/InferType.d.ts +5 -2
- package/lib/asserts/array/index.d.mts +4 -4
- package/lib/asserts/array/index.d.ts +4 -4
- package/lib/asserts/array/index.js +10 -5
- package/lib/asserts/array/index.js.map +1 -1
- package/lib/asserts/array/index.mjs +10 -5
- package/lib/asserts/array/index.mjs.map +1 -1
- package/lib/asserts/bigint/bigintMax.d.mts +22 -0
- package/lib/asserts/bigint/bigintMax.d.ts +22 -0
- package/lib/asserts/bigint/bigintMax.js +20 -0
- package/lib/asserts/bigint/bigintMax.js.map +1 -0
- package/lib/asserts/bigint/bigintMax.mjs +20 -0
- package/lib/asserts/bigint/bigintMax.mjs.map +1 -0
- package/lib/asserts/bigint/bigintMaxExcluded.d.mts +22 -0
- package/lib/asserts/bigint/bigintMaxExcluded.d.ts +22 -0
- package/lib/asserts/bigint/bigintMaxExcluded.js +20 -0
- package/lib/asserts/bigint/bigintMaxExcluded.js.map +1 -0
- package/lib/asserts/bigint/bigintMaxExcluded.mjs +20 -0
- package/lib/asserts/bigint/bigintMaxExcluded.mjs.map +1 -0
- package/lib/asserts/bigint/bigintMin.d.mts +22 -0
- package/lib/asserts/bigint/bigintMin.d.ts +22 -0
- package/lib/asserts/bigint/bigintMin.js +20 -0
- package/lib/asserts/bigint/bigintMin.js.map +1 -0
- package/lib/asserts/bigint/bigintMin.mjs +20 -0
- package/lib/asserts/bigint/bigintMin.mjs.map +1 -0
- package/lib/asserts/bigint/bigintMinExcluded.d.mts +22 -0
- package/lib/asserts/bigint/bigintMinExcluded.d.ts +22 -0
- package/lib/asserts/bigint/bigintMinExcluded.js +20 -0
- package/lib/asserts/bigint/bigintMinExcluded.js.map +1 -0
- package/lib/asserts/bigint/bigintMinExcluded.mjs +20 -0
- package/lib/asserts/bigint/bigintMinExcluded.mjs.map +1 -0
- package/lib/asserts/bigint/index.d.mts +18 -0
- package/lib/asserts/bigint/index.d.ts +18 -0
- package/lib/asserts/bigint/index.js +21 -0
- package/lib/asserts/bigint/index.js.map +1 -0
- package/lib/asserts/bigint/index.mjs +21 -0
- package/lib/asserts/bigint/index.mjs.map +1 -0
- package/lib/asserts/boolean/index.d.mts +4 -4
- package/lib/asserts/boolean/index.d.ts +4 -4
- package/lib/asserts/boolean/index.js +11 -6
- package/lib/asserts/boolean/index.js.map +1 -1
- package/lib/asserts/boolean/index.mjs +11 -6
- package/lib/asserts/boolean/index.mjs.map +1 -1
- package/lib/asserts/date/dateMax.d.mts +22 -0
- package/lib/asserts/date/dateMax.d.ts +22 -0
- package/lib/asserts/date/dateMax.js +28 -0
- package/lib/asserts/date/dateMax.js.map +1 -0
- package/lib/asserts/date/dateMax.mjs +28 -0
- package/lib/asserts/date/dateMax.mjs.map +1 -0
- package/lib/asserts/date/dateMin.d.mts +22 -0
- package/lib/asserts/date/dateMin.d.ts +22 -0
- package/lib/asserts/date/dateMin.js +28 -0
- package/lib/asserts/date/dateMin.js.map +1 -0
- package/lib/asserts/date/dateMin.mjs +28 -0
- package/lib/asserts/date/dateMin.mjs.map +1 -0
- package/lib/asserts/date/index.d.mts +17 -0
- package/lib/asserts/date/index.d.ts +17 -0
- package/lib/asserts/date/index.js +16 -0
- package/lib/asserts/date/index.js.map +1 -0
- package/lib/asserts/date/index.mjs +16 -0
- package/lib/asserts/date/index.mjs.map +1 -0
- package/lib/asserts/mix/equalTo.d.mts +1 -1
- package/lib/asserts/mix/equalTo.d.ts +1 -1
- package/lib/asserts/mix/equalTo.js +3 -3
- package/lib/asserts/mix/equalTo.mjs +2 -2
- package/lib/asserts/mix/index.d.mts +4 -3
- package/lib/asserts/mix/index.d.ts +4 -3
- package/lib/asserts/mix/index.js +9 -4
- package/lib/asserts/mix/index.js.map +1 -1
- package/lib/asserts/mix/index.mjs +9 -4
- package/lib/asserts/mix/index.mjs.map +1 -1
- package/lib/asserts/mix/oneOfValues.d.mts +1 -1
- package/lib/asserts/mix/oneOfValues.d.ts +1 -1
- package/lib/asserts/mix/oneOfValues.js +3 -3
- package/lib/asserts/mix/oneOfValues.mjs +2 -2
- package/lib/asserts/number/index.d.mts +4 -4
- package/lib/asserts/number/index.d.ts +4 -4
- package/lib/asserts/number/index.js +14 -9
- package/lib/asserts/number/index.js.map +1 -1
- package/lib/asserts/number/index.mjs +14 -9
- package/lib/asserts/number/index.mjs.map +1 -1
- package/lib/asserts/number/max.js +2 -2
- package/lib/asserts/number/max.mjs +1 -1
- package/lib/asserts/number/maxExcluded.js +2 -2
- package/lib/asserts/number/maxExcluded.mjs +1 -1
- package/lib/asserts/number/min.js +2 -2
- package/lib/asserts/number/min.mjs +1 -1
- package/lib/asserts/number/minExcluded.js +2 -2
- package/lib/asserts/number/minExcluded.mjs +1 -1
- package/lib/asserts/number/negative.js +2 -2
- package/lib/asserts/number/negative.mjs +1 -1
- package/lib/asserts/number/positive.js +2 -2
- package/lib/asserts/number/positive.mjs +1 -1
- package/lib/asserts/object/index.d.mts +4 -4
- package/lib/asserts/object/index.d.ts +4 -4
- package/lib/asserts/object/index.js +10 -5
- package/lib/asserts/object/index.js.map +1 -1
- package/lib/asserts/object/index.mjs +10 -5
- package/lib/asserts/object/index.mjs.map +1 -1
- package/lib/asserts/string/atLeastOneDigit.js +2 -2
- package/lib/asserts/string/atLeastOneDigit.mjs +1 -1
- package/lib/asserts/string/atLeastOneLowerChar.js +2 -2
- package/lib/asserts/string/atLeastOneLowerChar.mjs +1 -1
- package/lib/asserts/string/atLeastOneSpecialChar.js +2 -2
- package/lib/asserts/string/atLeastOneSpecialChar.mjs +1 -1
- package/lib/asserts/string/atLeastOneUpperChar.js +2 -2
- package/lib/asserts/string/atLeastOneUpperChar.mjs +1 -1
- package/lib/asserts/string/contains.js +2 -2
- package/lib/asserts/string/contains.mjs +1 -1
- package/lib/asserts/string/email.js +2 -2
- package/lib/asserts/string/email.mjs +1 -1
- package/lib/asserts/string/endsWith.js +2 -2
- package/lib/asserts/string/endsWith.mjs +1 -1
- package/lib/asserts/string/index.d.mts +4 -4
- package/lib/asserts/string/index.d.ts +4 -4
- package/lib/asserts/string/index.js +14 -9
- package/lib/asserts/string/index.js.map +1 -1
- package/lib/asserts/string/index.mjs +14 -9
- package/lib/asserts/string/index.mjs.map +1 -1
- package/lib/asserts/string/lowerCase.js +2 -2
- package/lib/asserts/string/lowerCase.mjs +1 -1
- package/lib/asserts/string/maxLength.js +2 -2
- package/lib/asserts/string/maxLength.mjs +1 -1
- package/lib/asserts/string/minLength.js +2 -2
- package/lib/asserts/string/minLength.mjs +1 -1
- package/lib/asserts/string/regExp.js +2 -2
- package/lib/asserts/string/regExp.mjs +1 -1
- package/lib/asserts/string/startsWith.js +2 -2
- package/lib/asserts/string/startsWith.mjs +1 -1
- package/lib/asserts/string/upperCase.js +2 -2
- package/lib/asserts/string/upperCase.mjs +1 -1
- package/lib/asserts/string/uuid.js +2 -2
- package/lib/asserts/string/uuid.mjs +1 -1
- package/lib/asserts/string/uuidV1.js +2 -2
- package/lib/asserts/string/uuidV1.mjs +1 -1
- package/lib/asserts/string/uuidV2.js +2 -2
- package/lib/asserts/string/uuidV2.mjs +1 -1
- package/lib/asserts/string/uuidV3.js +2 -2
- package/lib/asserts/string/uuidV3.mjs +1 -1
- package/lib/asserts/string/uuidV4.js +2 -2
- package/lib/asserts/string/uuidV4.mjs +1 -1
- package/lib/asserts/string/uuidV5.js +2 -2
- package/lib/asserts/string/uuidV5.mjs +1 -1
- package/lib/asserts/string/validUrl.js +2 -2
- package/lib/asserts/string/validUrl.mjs +1 -1
- package/lib/{chunk-RRQOET3X.js → chunk-2OINKFOA.js} +6 -6
- package/lib/{chunk-RRQOET3X.js.map → chunk-2OINKFOA.js.map} +1 -1
- package/lib/{chunk-LEQCDD66.js → chunk-32J4WVLE.js} +10 -10
- package/lib/{chunk-LEQCDD66.js.map → chunk-32J4WVLE.js.map} +1 -1
- package/lib/chunk-356HMXOP.js +12 -0
- package/lib/chunk-356HMXOP.js.map +1 -0
- package/lib/{chunk-4CYIMDP2.js → chunk-4SPM2CSQ.js} +3 -3
- package/lib/chunk-4SPM2CSQ.js.map +1 -0
- package/lib/{chunk-WBERBAL4.js → chunk-4SR7J2I4.js} +6 -6
- package/lib/{chunk-WBERBAL4.js.map → chunk-4SR7J2I4.js.map} +1 -1
- package/lib/{chunk-DPBE7TAQ.mjs → chunk-4UF67IQ2.mjs} +3 -3
- package/lib/chunk-4UF67IQ2.mjs.map +1 -0
- package/lib/{chunk-RYVUYVEE.mjs → chunk-54RHVQFA.mjs} +2 -2
- package/lib/{chunk-YUESB2WV.mjs → chunk-5AO66YV5.mjs} +3 -3
- package/lib/{chunk-KQKJASVB.js → chunk-5EIBKBYS.js} +10 -10
- package/lib/{chunk-KQKJASVB.js.map → chunk-5EIBKBYS.js.map} +1 -1
- package/lib/{chunk-IRG4OQAB.js → chunk-7GIRQ5EA.js} +7 -1
- package/lib/chunk-7GIRQ5EA.js.map +1 -0
- package/lib/{chunk-5BVJ6YMH.js → chunk-CQWI6YRI.js} +3 -2
- package/lib/chunk-CQWI6YRI.js.map +1 -0
- package/lib/{chunk-EGEHSELT.js → chunk-EQNVYAKS.js} +7 -7
- package/lib/chunk-EQNVYAKS.js.map +1 -0
- package/lib/chunk-GDSB7CDN.mjs +12 -0
- package/lib/chunk-GDSB7CDN.mjs.map +1 -0
- package/lib/chunk-LWAEUS2F.js +14 -0
- package/lib/{chunk-JSGZ7DKT.js.map → chunk-LWAEUS2F.js.map} +1 -1
- package/lib/{chunk-NNFYXHLU.mjs → chunk-M6OCVAUD.mjs} +2 -2
- package/lib/chunk-M6OCVAUD.mjs.map +1 -0
- package/lib/{chunk-PG2R7P7G.mjs → chunk-MRWZVTNH.mjs} +3 -3
- package/lib/{chunk-DJSLA2ZV.js → chunk-MTJJKWTP.js} +5 -5
- package/lib/{chunk-DJSLA2ZV.js.map → chunk-MTJJKWTP.js.map} +1 -1
- package/lib/{chunk-6TH3DBDK.js → chunk-N6YMNLXG.js} +8 -8
- package/lib/{chunk-6TH3DBDK.js.map → chunk-N6YMNLXG.js.map} +1 -1
- package/lib/{chunk-NDQM5OL4.mjs → chunk-PEWNA24X.mjs} +3 -3
- package/lib/{chunk-CCBCDJXS.mjs → chunk-PJI3DRGP.mjs} +3 -3
- package/lib/{chunk-TCQY2R3U.mjs → chunk-PVOHKGBW.mjs} +3 -3
- package/lib/chunk-QLVLZRHT.js +20 -0
- package/lib/chunk-QLVLZRHT.js.map +1 -0
- package/lib/{chunk-3HTYHE2X.mjs → chunk-QV4JDW3T.mjs} +3 -2
- package/lib/chunk-QV4JDW3T.mjs.map +1 -0
- package/lib/chunk-SEIKS6G7.js +61 -0
- package/lib/chunk-SEIKS6G7.js.map +1 -0
- package/lib/{chunk-JPRCULRQ.mjs → chunk-TP5I237J.mjs} +7 -7
- package/lib/chunk-UV4I7JZR.mjs +61 -0
- package/lib/chunk-UV4I7JZR.mjs.map +1 -0
- package/lib/{chunk-H7CPKW53.js → chunk-VGF3Y2EK.js} +5 -5
- package/lib/{chunk-H7CPKW53.js.map → chunk-VGF3Y2EK.js.map} +1 -1
- package/lib/{chunk-J4VKFJQK.js → chunk-WPHJ4QTB.js} +3 -3
- package/lib/chunk-WPHJ4QTB.js.map +1 -0
- package/lib/chunk-XFR7Y4XX.mjs +20 -0
- package/lib/chunk-XFR7Y4XX.mjs.map +1 -0
- package/lib/{chunk-PH2PMUZP.mjs → chunk-XZTZC73V.mjs} +7 -1
- package/lib/chunk-XZTZC73V.mjs.map +1 -0
- package/lib/{chunk-3O4WCRC2.mjs → chunk-YPAUFM3S.mjs} +2 -2
- package/lib/chunk-YPAUFM3S.mjs.map +1 -0
- package/lib/{chunk-P7IXNCJG.mjs → chunk-Z7OEFOAD.mjs} +7 -7
- package/lib/codeGen.d.mts +1 -1
- package/lib/codeGen.d.ts +1 -1
- package/lib/codeGen.js +4 -2
- package/lib/codeGen.js.map +1 -1
- package/lib/codeGen.mjs +3 -1
- package/lib/codeGen.mjs.map +1 -1
- package/lib/commonTypes.d.mts +1 -0
- package/lib/commonTypes.d.ts +1 -0
- package/lib/helpers/core.d.mts +1 -1
- package/lib/helpers/core.d.ts +1 -1
- package/lib/helpers/core.js +3 -2
- package/lib/helpers/core.js.map +1 -1
- package/lib/helpers/core.mjs +2 -1
- package/lib/helpers/isValidDate.d.mts +3 -0
- package/lib/helpers/isValidDate.d.ts +3 -0
- package/lib/helpers/isValidDate.js +7 -0
- package/lib/helpers/isValidDate.js.map +1 -0
- package/lib/helpers/isValidDate.mjs +7 -0
- package/lib/helpers/isValidDate.mjs.map +1 -0
- package/lib/helpers/setStrictType.d.mts +1 -1
- package/lib/helpers/setStrictType.d.ts +1 -1
- package/lib/helpers/setStrictType.js +4 -3
- package/lib/helpers/setStrictType.js.map +1 -1
- package/lib/helpers/setStrictType.mjs +3 -2
- package/lib/index.d.mts +3 -7
- package/lib/index.d.ts +3 -7
- package/lib/index.js +6 -39
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +6 -39
- package/lib/parse.d.mts +3 -1
- package/lib/parse.d.ts +3 -1
- package/lib/parse.js +5 -4
- package/lib/parse.js.map +1 -1
- package/lib/parse.mjs +4 -3
- package/lib/parseOrFail.d.mts +3 -1
- package/lib/parseOrFail.d.ts +3 -1
- package/lib/parseOrFail.js +5 -4
- package/lib/parseOrFail.js.map +1 -1
- package/lib/parseOrFail.mjs +4 -3
- package/lib/schemas/ArraySchema.d.mts +1 -1
- package/lib/schemas/ArraySchema.d.ts +1 -1
- package/lib/schemas/ArraySchema.js +5 -4
- package/lib/schemas/ArraySchema.js.map +1 -1
- package/lib/schemas/ArraySchema.mjs +4 -3
- package/lib/schemas/BigIntSchema.d.mts +32 -0
- package/lib/schemas/BigIntSchema.d.ts +32 -0
- package/lib/schemas/BigIntSchema.js +16 -0
- package/lib/schemas/BigIntSchema.js.map +1 -0
- package/lib/schemas/BigIntSchema.mjs +16 -0
- package/lib/schemas/BigIntSchema.mjs.map +1 -0
- package/lib/schemas/BooleanSchema.d.mts +1 -1
- package/lib/schemas/BooleanSchema.d.ts +1 -1
- package/lib/schemas/BooleanSchema.js +6 -5
- package/lib/schemas/BooleanSchema.js.map +1 -1
- package/lib/schemas/BooleanSchema.mjs +5 -4
- package/lib/schemas/CommonSchema.d.mts +1 -1
- package/lib/schemas/CommonSchema.d.ts +1 -1
- package/lib/schemas/CommonSchema.js +4 -3
- package/lib/schemas/CommonSchema.js.map +1 -1
- package/lib/schemas/CommonSchema.mjs +3 -2
- package/lib/schemas/DateSchema.d.mts +9 -0
- package/lib/schemas/DateSchema.d.ts +9 -0
- package/lib/schemas/DateSchema.js +11 -0
- package/lib/schemas/DateSchema.js.map +1 -0
- package/lib/schemas/DateSchema.mjs +11 -0
- package/lib/schemas/DateSchema.mjs.map +1 -0
- package/lib/schemas/NumberSchema.d.mts +1 -1
- package/lib/schemas/NumberSchema.d.ts +1 -1
- package/lib/schemas/NumberSchema.js +9 -8
- package/lib/schemas/NumberSchema.js.map +1 -1
- package/lib/schemas/NumberSchema.mjs +8 -7
- package/lib/schemas/ObjectSchema.d.mts +1 -1
- package/lib/schemas/ObjectSchema.d.ts +1 -1
- package/lib/schemas/ObjectSchema.js +5 -4
- package/lib/schemas/ObjectSchema.js.map +1 -1
- package/lib/schemas/ObjectSchema.mjs +4 -3
- package/lib/schemas/StringSchema.d.mts +1 -1
- package/lib/schemas/StringSchema.d.ts +1 -1
- package/lib/schemas/StringSchema.js +9 -8
- package/lib/schemas/StringSchema.js.map +1 -1
- package/lib/schemas/StringSchema.mjs +8 -7
- package/lib/translationMap.js +2 -2
- package/lib/translationMap.mjs +1 -1
- package/package.json +6 -1
- package/lib/chunk-2PM3K3OE.mjs +0 -13
- package/lib/chunk-2PM3K3OE.mjs.map +0 -1
- package/lib/chunk-32RSTOZ4.mjs +0 -13
- package/lib/chunk-32RSTOZ4.mjs.map +0 -1
- package/lib/chunk-3HTYHE2X.mjs.map +0 -1
- package/lib/chunk-3O4WCRC2.mjs.map +0 -1
- package/lib/chunk-4CYIMDP2.js.map +0 -1
- package/lib/chunk-5BVJ6YMH.js.map +0 -1
- package/lib/chunk-DPBE7TAQ.mjs.map +0 -1
- package/lib/chunk-EGEHSELT.js.map +0 -1
- package/lib/chunk-HDSGCAHH.js +0 -13
- package/lib/chunk-HDSGCAHH.js.map +0 -1
- package/lib/chunk-IEUXIOL6.js +0 -13
- package/lib/chunk-IEUXIOL6.js.map +0 -1
- package/lib/chunk-IRG4OQAB.js.map +0 -1
- package/lib/chunk-J4VKFJQK.js.map +0 -1
- package/lib/chunk-JDGZCBXF.mjs +0 -13
- package/lib/chunk-JDGZCBXF.mjs.map +0 -1
- package/lib/chunk-JSGZ7DKT.js +0 -14
- package/lib/chunk-MRISXZQ4.mjs +0 -13
- package/lib/chunk-MRISXZQ4.mjs.map +0 -1
- package/lib/chunk-NNFYXHLU.mjs.map +0 -1
- package/lib/chunk-PH2PMUZP.mjs.map +0 -1
- package/lib/chunk-PXBAS3GA.mjs +0 -13
- package/lib/chunk-PXBAS3GA.mjs.map +0 -1
- package/lib/chunk-QQNQ4IDN.js +0 -13
- package/lib/chunk-QQNQ4IDN.js.map +0 -1
- package/lib/chunk-RD6TBCPQ.js +0 -13
- package/lib/chunk-RD6TBCPQ.js.map +0 -1
- package/lib/chunk-TKZ6FLLR.js +0 -13
- package/lib/chunk-TKZ6FLLR.js.map +0 -1
- package/lib/chunk-VHEA4JZ5.js +0 -13
- package/lib/chunk-VHEA4JZ5.js.map +0 -1
- package/lib/chunk-YML32TPA.mjs +0 -13
- package/lib/chunk-YML32TPA.mjs.map +0 -1
- /package/lib/{chunk-RYVUYVEE.mjs.map → chunk-54RHVQFA.mjs.map} +0 -0
- /package/lib/{chunk-YUESB2WV.mjs.map → chunk-5AO66YV5.mjs.map} +0 -0
- /package/lib/{chunk-PG2R7P7G.mjs.map → chunk-MRWZVTNH.mjs.map} +0 -0
- /package/lib/{chunk-NDQM5OL4.mjs.map → chunk-PEWNA24X.mjs.map} +0 -0
- /package/lib/{chunk-CCBCDJXS.mjs.map → chunk-PJI3DRGP.mjs.map} +0 -0
- /package/lib/{chunk-TCQY2R3U.mjs.map → chunk-PVOHKGBW.mjs.map} +0 -0
- /package/lib/{chunk-JPRCULRQ.mjs.map → chunk-TP5I237J.mjs.map} +0 -0
- /package/lib/{chunk-P7IXNCJG.mjs.map → chunk-Z7OEFOAD.mjs.map} +0 -0
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunk7GIRQ5EAjs = require('./chunk-7GIRQ5EA.js');
|
|
4
4
|
|
|
5
5
|
// src/schemas/CommonSchema.ts
|
|
6
6
|
var CommonSchema = class {
|
|
7
7
|
|
|
8
8
|
constructor(ctx) {
|
|
9
|
-
this[
|
|
9
|
+
this[_chunk7GIRQ5EAjs.ctxSymbol] = ctx;
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
12
|
* @param validators - One or more custom validation functions.
|
|
13
13
|
* @returns {this} The schema instance with the added custom validation.
|
|
14
14
|
*/
|
|
15
15
|
custom(...validators) {
|
|
16
|
-
this[
|
|
16
|
+
this[_chunk7GIRQ5EAjs.ctxSymbol].requiredValidations.push(...validators);
|
|
17
17
|
return this;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
@@ -22,16 +22,16 @@ var CommonSchema = class {
|
|
|
22
22
|
* @returns {WithNull<this>} The schema instance marked as nullable.
|
|
23
23
|
*/
|
|
24
24
|
nullable() {
|
|
25
|
-
this[
|
|
25
|
+
this[_chunk7GIRQ5EAjs.ctxSymbol].isNullable = true;
|
|
26
26
|
return this;
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
29
|
* Marks the schema as optional, allowing the value to be `undefined`.
|
|
30
30
|
*
|
|
31
|
-
* @returns {WithUndefined<this>}
|
|
31
|
+
* @returns {WithUndefined<this>} The schema instance marked as optional.
|
|
32
32
|
*/
|
|
33
33
|
optional() {
|
|
34
|
-
this[
|
|
34
|
+
this[_chunk7GIRQ5EAjs.ctxSymbol].isOptional = true;
|
|
35
35
|
return this;
|
|
36
36
|
}
|
|
37
37
|
};
|
|
@@ -39,4 +39,4 @@ var CommonSchema = class {
|
|
|
39
39
|
|
|
40
40
|
|
|
41
41
|
exports.CommonSchema = CommonSchema;
|
|
42
|
-
//# sourceMappingURL=chunk-
|
|
42
|
+
//# sourceMappingURL=chunk-EQNVYAKS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-EQNVYAKS.js","../src/schemas/CommonSchema.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACA;ACcO,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,EAMA,MAAA,CAAA,GAAU,UAAA,EAAwC;AAChD,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,EAOA,QAAA,CAAA,EAA2B;AACzB,IAAA,IAAA,CAAK,0BAAS,CAAA,CAAE,WAAA,EAAa,IAAA;AAC7B,IAAA,OAAO,IAAA;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,QAAA,CAAA,EAAgC;AAC9B,IAAA,IAAA,CAAK,0BAAS,CAAA,CAAE,WAAA,EAAa,IAAA;AAC7B,IAAA,OAAO,IAAA;AAAA,EACT;AACF,CAAA;ADfA;AACA;AACE;AACF,oCAAC","file":"/home/runner/work/bguard/bguard/lib/chunk-EQNVYAKS.js","sourcesContent":[null,"import { PrimitiveType, RequiredValidation } from '../commonTypes';\nimport { ctxSymbol } from '../helpers/core';\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}\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 custom(...validators: RequiredValidation[]): this {\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 nullable(): WithNull<this> {\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 optional(): WithUndefined<this> {\n this[ctxSymbol].isOptional = true;\n return this as WithUndefined<this>;\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"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// src/helpers/isValidDate.ts
|
|
2
|
+
function isValidDate(d) {
|
|
3
|
+
return (
|
|
4
|
+
// @ts-expect-error we expect d to have getTime method
|
|
5
|
+
Object.prototype.toString.call(d) === "[object Date]" && !isNaN(typeof d?.getTime === "function" && d.getTime())
|
|
6
|
+
);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
isValidDate
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=chunk-GDSB7CDN.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/helpers/isValidDate.ts"],"sourcesContent":["export function isValidDate(d: unknown) {\n return (\n // @ts-expect-error we expect d to have getTime method\n Object.prototype.toString.call(d) === '[object Date]' && !isNaN(typeof d?.getTime === 'function' && d.getTime())\n );\n}\n"],"mappings":";AAAO,SAAS,YAAY,GAAY;AACtC;AAAA;AAAA,IAEE,OAAO,UAAU,SAAS,KAAK,CAAC,MAAM,mBAAmB,CAAC,MAAM,OAAO,GAAG,YAAY,cAAc,EAAE,QAAQ,CAAC;AAAA;AAEnH;","names":[]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunk7GIRQ5EAjs = require('./chunk-7GIRQ5EA.js');
|
|
4
|
+
|
|
5
|
+
// src/helpers/setStrictType.ts
|
|
6
|
+
function _setStrictType(that, val) {
|
|
7
|
+
that[_chunk7GIRQ5EAjs.ctxSymbol].strictType = true;
|
|
8
|
+
that[_chunk7GIRQ5EAjs.ctxSymbol].strictTypeValue = val;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
exports._setStrictType = _setStrictType;
|
|
14
|
+
//# sourceMappingURL=chunk-LWAEUS2F.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-LWAEUS2F.js","../src/helpers/setStrictType.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACA;ACDO,SAAS,cAAA,CAAe,IAAA,EAAoB,GAAA,EAAc;AAC/D,EAAA,IAAA,CAAK,0BAAS,CAAA,CAAE,WAAA,EAAa,IAAA;AAC7B,EAAA,IAAA,CAAK,0BAAS,CAAA,CAAE,gBAAA,EAAkB,GAAA;AACpC;ADGA;AACA;AACE;AACF,wCAAC","file":"/home/runner/work/bguard/bguard/lib/chunk-LWAEUS2F.js","sourcesContent":[null,"import { ctxSymbol } from './core';\nimport type { CommonSchema } from '../schemas/CommonSchema';\n\nexport function _setStrictType(that: CommonSchema, val: unknown) {\n that[ctxSymbol].strictType = true;\n that[ctxSymbol].strictTypeValue = val;\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
setToDefaultLocale
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-QV4JDW3T.mjs";
|
|
4
4
|
import {
|
|
5
5
|
guardException
|
|
6
6
|
} from "./chunk-7XFLH6R2.mjs";
|
|
@@ -18,4 +18,4 @@ setToDefaultLocale(equalTo);
|
|
|
18
18
|
export {
|
|
19
19
|
equalTo
|
|
20
20
|
};
|
|
21
|
-
//# sourceMappingURL=chunk-
|
|
21
|
+
//# sourceMappingURL=chunk-M6OCVAUD.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/asserts/mix/equalTo.ts"],"sourcesContent":["import { guardException } from '../../exceptions';\nimport { ExceptionContext, RequiredValidation } from '../../commonTypes';\nimport { setToDefaultLocale } from '../../translationMap';\n\nconst equalToErrorMessage = 'The received value is not equal to expected';\nconst equalToErrorKey = 'm:equalTo';\n\n/**\n * @description Creates a custom assertion that checks if a value is equal to the expected value.\n * @notice It has already been implemented in the number, bigint and string schema. There is no need to use it as a custom assert.\n * @param {unknown} expected The value that the received value is expected to match.\n * @returns {RequiredValidation} A validation function that takes a received value and an exception context.\n * @throws {ValidationError} If the received value does not match the expected value.\n * @example\n * const schema = number().custom(equalTo(5)); // Define a schema with a custom assertion\n * parseOrFail(schema, 5); // Valid\n * parseOrFail(schema, 3); // Throws an error: 'The received value is not equal to expected'\n *\n * @translation Error Translation Key = 'm:equalTo'\n */\nexport const equalTo =\n (expected: unknown): RequiredValidation =>\n (received: unknown, ctx: ExceptionContext) => {\n if (expected !== received) guardException(expected, received, ctx, equalToErrorKey);\n };\n\nequalTo.key = equalToErrorKey;\nequalTo.message = equalToErrorMessage;\nsetToDefaultLocale(equalTo);\n"],"mappings":";;;;;;;;AAIA,IAAM,sBAAsB;AAC5B,IAAM,kBAAkB;AAejB,IAAM,UACX,CAAC,aACD,CAAC,UAAmB,QAA0B;AAC5C,MAAI,aAAa,SAAU,gBAAe,UAAU,UAAU,KAAK,eAAe;AACpF;AAEF,QAAQ,MAAM;AACd,QAAQ,UAAU;AAClB,mBAAmB,OAAO;","names":[]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
innerCheck
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-XZTZC73V.mjs";
|
|
4
4
|
import {
|
|
5
5
|
getTranslationByLocale
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-QV4JDW3T.mjs";
|
|
7
7
|
import {
|
|
8
8
|
ValidationError
|
|
9
9
|
} from "./chunk-7XFLH6R2.mjs";
|
|
@@ -24,4 +24,4 @@ function parseOrFail(schema, receivedValue, options) {
|
|
|
24
24
|
export {
|
|
25
25
|
parseOrFail
|
|
26
26
|
};
|
|
27
|
-
//# sourceMappingURL=chunk-
|
|
27
|
+
//# sourceMappingURL=chunk-MRWZVTNH.mjs.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
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
|
-
var
|
|
3
|
+
var _chunk7GIRQ5EAjs = require('./chunk-7GIRQ5EA.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkCQWI6YRIjs = require('./chunk-CQWI6YRI.js');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
var _chunkWK4O3HH4js = require('./chunk-WK4O3HH4.js');
|
|
@@ -11,8 +11,8 @@ var _chunkWK4O3HH4js = require('./chunk-WK4O3HH4.js');
|
|
|
11
11
|
// src/parseOrFail.ts
|
|
12
12
|
function parseOrFail(schema, receivedValue, options) {
|
|
13
13
|
try {
|
|
14
|
-
return
|
|
15
|
-
t:
|
|
14
|
+
return _chunk7GIRQ5EAjs.innerCheck.call(void 0, schema, receivedValue, {
|
|
15
|
+
t: _chunkCQWI6YRIjs.getTranslationByLocale.call(void 0, _optionalChain([options, 'optionalAccess', _ => _.lng])),
|
|
16
16
|
pathToError: ""
|
|
17
17
|
});
|
|
18
18
|
} catch (e) {
|
|
@@ -24,4 +24,4 @@ function parseOrFail(schema, receivedValue, options) {
|
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
exports.parseOrFail = parseOrFail;
|
|
27
|
-
//# sourceMappingURL=chunk-
|
|
27
|
+
//# sourceMappingURL=chunk-MTJJKWTP.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-MTJJKWTP.js","../src/parseOrFail.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACA;ACgCO,SAAS,WAAA,CACd,MAAA,EACA,aAAA,EACA,OAAA,EACc;AACd,EAAA,IAAI;AACF,IAAA,OAAO,yCAAA,MAAW,EAAQ,aAAA,EAAe;AAAA,MACvC,CAAA,EAAG,qDAAA,gBAAuB,OAAA,2BAAS,KAAG,CAAA;AAAA,MACtC,WAAA,EAAa;AAAA,IACf,CAAC,CAAA;AAAA,EACH,EAAA,MAAA,CAAS,CAAA,EAAG;AACV,IAAA,GAAA,CAAI,EAAA,WAAa,gCAAA,EAAiB,MAAM,CAAA;AAExC,IAAA,MAAM,IAAI,KAAA,CAAM,+BAA+B,CAAA;AAAA,EACjD;AACF;ADnCA;AACA;AACE;AACF,kCAAC","file":"/home/runner/work/bguard/bguard/lib/chunk-MTJJKWTP.js","sourcesContent":[null,"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"]}
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _class;
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkEQNVYAKSjs = require('./chunk-EQNVYAKS.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunk7GIRQ5EAjs = require('./chunk-7GIRQ5EA.js');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
var _chunkWK4O3HH4js = require('./chunk-WK4O3HH4.js');
|
|
10
10
|
|
|
11
11
|
// src/schemas/ObjectSchema.ts
|
|
12
|
-
var ObjectSchema = (_class = class extends
|
|
12
|
+
var ObjectSchema = (_class = class extends _chunkEQNVYAKSjs.CommonSchema {
|
|
13
13
|
__init() {this._object = 1}
|
|
14
14
|
constructor(ctx, shapeSchema) {
|
|
15
15
|
super(ctx);_class.prototype.__init.call(this);;
|
|
16
16
|
this.validateObjectEntry(shapeSchema);
|
|
17
|
-
this[
|
|
17
|
+
this[_chunk7GIRQ5EAjs.ctxSymbol].object = shapeSchema;
|
|
18
18
|
}
|
|
19
19
|
validateObjectEntry(shapeSchema) {
|
|
20
20
|
if (!shapeSchema) throw new (0, _chunkWK4O3HH4js.BuildSchemaError)("Missing schema in object method");
|
|
21
|
-
if (shapeSchema instanceof
|
|
21
|
+
if (shapeSchema instanceof _chunkEQNVYAKSjs.CommonSchema) throw new (0, _chunkWK4O3HH4js.BuildSchemaError)("Invalid schema in object");
|
|
22
22
|
for (const [key, value] of Object.entries(shapeSchema)) {
|
|
23
|
-
if (!(value instanceof
|
|
23
|
+
if (!(value instanceof _chunkEQNVYAKSjs.CommonSchema))
|
|
24
24
|
throw new (0, _chunkWK4O3HH4js.BuildSchemaError)(`Invalid schema in object method for property '${key}'`);
|
|
25
25
|
}
|
|
26
26
|
}
|
|
@@ -42,7 +42,7 @@ var ObjectSchema = (_class = class extends _chunkEGEHSELTjs.CommonSchema {
|
|
|
42
42
|
* // No error thrown
|
|
43
43
|
*/
|
|
44
44
|
allowUnrecognized() {
|
|
45
|
-
this[
|
|
45
|
+
this[_chunk7GIRQ5EAjs.ctxSymbol].allowUnrecognizedObjectProps = true;
|
|
46
46
|
return this;
|
|
47
47
|
}
|
|
48
48
|
}, _class);
|
|
@@ -50,4 +50,4 @@ var ObjectSchema = (_class = class extends _chunkEGEHSELTjs.CommonSchema {
|
|
|
50
50
|
|
|
51
51
|
|
|
52
52
|
exports.ObjectSchema = ObjectSchema;
|
|
53
|
-
//# sourceMappingURL=chunk-
|
|
53
|
+
//# sourceMappingURL=chunk-N6YMNLXG.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-N6YMNLXG.js","../src/schemas/ObjectSchema.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACA;ACNO,IAAM,aAAA,YAAN,MAAA,QAA2B,8BAAa;AAAA,iBAC7C,QAAA,EAAU,EAAA;AAAA,EACV,WAAA,CAAY,GAAA,EAAuB,WAAA,EAAoC;AACrE,IAAA,KAAA,CAAM,GAAG,qCAAA;AACT,IAAA,IAAA,CAAK,mBAAA,CAAoB,WAAW,CAAA;AACpC,IAAA,IAAA,CAAK,0BAAS,CAAA,CAAE,OAAA,EAAS,WAAA;AAAA,EAC3B;AAAA,EAEQ,mBAAA,CAAoB,WAAA,EAAoC;AAC9D,IAAA,GAAA,CAAI,CAAC,WAAA,EAAa,MAAM,IAAI,sCAAA,CAAiB,iCAAiC,CAAA;AAC9E,IAAA,GAAA,CAAI,YAAA,WAAuB,6BAAA,EAAc,MAAM,IAAI,sCAAA,CAAiB,0BAA0B,CAAA;AAC9F,IAAA,IAAA,CAAA,MAAW,CAAC,GAAA,EAAK,KAAK,EAAA,GAAK,MAAA,CAAO,OAAA,CAAQ,WAAW,CAAA,EAAG;AACtD,MAAA,GAAA,CAAI,CAAA,CAAE,MAAA,WAAiB,6BAAA,CAAA;AACrB,QAAA,MAAM,IAAI,sCAAA,CAAiB,CAAA,8CAAA,EAAiD,GAAG,CAAA,CAAA,CAAG,CAAA;AAAA,IACtF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAmBO,iBAAA,CAAA,EAA0B;AAC/B,IAAA,IAAA,CAAK,0BAAS,CAAA,CAAE,6BAAA,EAA+B,IAAA;AAC/C,IAAA,OAAO,IAAA;AAAA,EACT;AACF,UAAA;ADMA;AACA;AACE;AACF,oCAAC","file":"/home/runner/work/bguard/bguard/lib/chunk-N6YMNLXG.js","sourcesContent":[null,"import { ctxSymbol } from '../helpers/core';\nimport { BuildSchemaError } from '../exceptions';\nimport { CommonSchema, ObjectShapeSchemaType, ValidatorContext } from './CommonSchema';\n\nexport class ObjectSchema extends CommonSchema {\n _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\nexport type WithObject<Y extends ObjectShapeSchemaType> = ObjectSchema & { validation_object: Y };\n"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CommonSchema
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-4UF67IQ2.mjs";
|
|
4
4
|
import {
|
|
5
5
|
ctxSymbol
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-XZTZC73V.mjs";
|
|
7
7
|
import {
|
|
8
8
|
BuildSchemaError
|
|
9
9
|
} from "./chunk-7XFLH6R2.mjs";
|
|
@@ -25,4 +25,4 @@ var ArraySchema = class extends CommonSchema {
|
|
|
25
25
|
export {
|
|
26
26
|
ArraySchema
|
|
27
27
|
};
|
|
28
|
-
//# sourceMappingURL=chunk-
|
|
28
|
+
//# sourceMappingURL=chunk-PEWNA24X.mjs.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
_setStrictType
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-54RHVQFA.mjs";
|
|
4
4
|
import {
|
|
5
5
|
CommonSchema
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-4UF67IQ2.mjs";
|
|
7
7
|
import {
|
|
8
8
|
guardException
|
|
9
9
|
} from "./chunk-7XFLH6R2.mjs";
|
|
@@ -41,4 +41,4 @@ var BooleanSchema = class extends CommonSchema {
|
|
|
41
41
|
export {
|
|
42
42
|
BooleanSchema
|
|
43
43
|
};
|
|
44
|
-
//# sourceMappingURL=chunk-
|
|
44
|
+
//# sourceMappingURL=chunk-PJI3DRGP.mjs.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CommonSchema
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-4UF67IQ2.mjs";
|
|
4
4
|
import {
|
|
5
5
|
ctxSymbol
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-XZTZC73V.mjs";
|
|
7
7
|
import {
|
|
8
8
|
BuildSchemaError
|
|
9
9
|
} from "./chunk-7XFLH6R2.mjs";
|
|
@@ -50,4 +50,4 @@ var ObjectSchema = class extends CommonSchema {
|
|
|
50
50
|
export {
|
|
51
51
|
ObjectSchema
|
|
52
52
|
};
|
|
53
|
-
//# sourceMappingURL=chunk-
|
|
53
|
+
//# sourceMappingURL=chunk-PVOHKGBW.mjs.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _class;
|
|
2
|
+
|
|
3
|
+
var _chunkEQNVYAKSjs = require('./chunk-EQNVYAKS.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunk7GIRQ5EAjs = require('./chunk-7GIRQ5EA.js');
|
|
7
|
+
|
|
8
|
+
// src/schemas/DateSchema.ts
|
|
9
|
+
var DateSchema = (_class = class extends _chunkEQNVYAKSjs.CommonSchema {
|
|
10
|
+
__init() {this._date = 1}
|
|
11
|
+
constructor(ctx) {
|
|
12
|
+
super(ctx);_class.prototype.__init.call(this);;
|
|
13
|
+
this[_chunk7GIRQ5EAjs.ctxSymbol].date = true;
|
|
14
|
+
}
|
|
15
|
+
}, _class);
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
exports.DateSchema = DateSchema;
|
|
20
|
+
//# sourceMappingURL=chunk-QLVLZRHT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-QLVLZRHT.js","../src/schemas/DateSchema.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACA;ACJO,IAAM,WAAA,YAAN,MAAA,QAAyB,8BAAa;AAAA,iBAC3C,MAAA,EAAQ,EAAA;AAAA,EAER,WAAA,CAAY,GAAA,EAAuB;AACjC,IAAA,KAAA,CAAM,GAAG,qCAAA;AACT,IAAA,IAAA,CAAK,0BAAS,CAAA,CAAE,KAAA,EAAO,IAAA;AAAA,EACzB;AACF,UAAA;ADKA;AACA;AACE;AACF,gCAAC","file":"/home/runner/work/bguard/bguard/lib/chunk-QLVLZRHT.js","sourcesContent":[null,"import { ctxSymbol } from '../helpers/core';\nimport { CommonSchema, ValidatorContext } from './CommonSchema';\n\nexport class DateSchema extends CommonSchema {\n _date = 1;\n\n constructor(ctx: ValidatorContext) {\n super(ctx);\n this[ctxSymbol].date = true;\n }\n}\n"]}
|
|
@@ -13,7 +13,8 @@ var defaultErrorMap = {
|
|
|
13
13
|
"c:unrecognizedProperty": "This property is not allowed in the object",
|
|
14
14
|
"c:requiredProperty": "Missing required property in the object",
|
|
15
15
|
"c:invalidType": "Invalid type of data",
|
|
16
|
-
"c:isBoolean": "The received value is not {{e}}"
|
|
16
|
+
"c:isBoolean": "The received value is not {{e}}",
|
|
17
|
+
"c:date": "The received value is not a valid instance of Date"
|
|
17
18
|
//@@end
|
|
18
19
|
};
|
|
19
20
|
var data = {
|
|
@@ -51,4 +52,4 @@ export {
|
|
|
51
52
|
clearLocales,
|
|
52
53
|
getTranslationByLocale
|
|
53
54
|
};
|
|
54
|
-
//# sourceMappingURL=chunk-
|
|
55
|
+
//# sourceMappingURL=chunk-QV4JDW3T.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/translationMap.ts"],"sourcesContent":["import { BuildSchemaError } from './exceptions';\nimport { RequiredValidation, TranslationErrorMap } from './commonTypes';\n\n// c: stands for common\nconst defaultErrorMap: TranslationErrorMap = {\n //@@start\n 'c:optional': 'The required value is missing',\n 'c:nullable': 'Value should not be null',\n 'c:array': 'Expected an array but received a different type',\n 'c:objectType': 'Expected an object but received a different type',\n 'c:objectTypeAsArray': 'Expected an object but received an array. Invalid type of data',\n 'c:unrecognizedProperty': 'This property is not allowed in the object',\n 'c:requiredProperty': 'Missing required property in the object',\n 'c:invalidType': 'Invalid type of data',\n 'c:isBoolean': 'The received value is not {{e}}',\n 'c:date': 'The received value is not a valid instance of Date',\n //@@end\n};\n\nlet data: Record<string, Record<string, string>> = {\n default: { ...defaultErrorMap },\n};\n\nexport function setToDefaultLocale({\n key,\n message,\n}: {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (expected: any): RequiredValidation;\n key: string;\n message: string;\n}) {\n const defaultLocale = data.default!;\n if (defaultLocale[key]) throw new BuildSchemaError('Duplicate default message key');\n defaultLocale[key] = message;\n}\n\nexport function setLocale(lng: string, custom: Partial<TranslationErrorMap>) {\n if (lng === 'default') throw new BuildSchemaError('Invalid language');\n if (!data[lng]) data[lng] = { ...defaultErrorMap };\n const locale = data[lng]!;\n Object.entries(custom).forEach(([messageKey, messageValue]) => {\n locale[messageKey] = messageValue!;\n });\n}\n\nexport function clearLocales() {\n data = {\n default: { ...defaultErrorMap },\n };\n}\n\nexport function getTranslationByLocale(lng?: string): TranslationErrorMap {\n if (!lng) return data['default'] as TranslationErrorMap;\n return (data[lng] ?? data['default']) as TranslationErrorMap;\n}\n"],"mappings":";;;;;AAIA,IAAM,kBAAuC;AAAA;AAAA,EAE3C,cAAc;AAAA,EACd,cAAc;AAAA,EACd,WAAW;AAAA,EACX,gBAAgB;AAAA,EAChB,uBAAuB;AAAA,EACvB,0BAA0B;AAAA,EAC1B,sBAAsB;AAAA,EACtB,iBAAiB;AAAA,EACjB,eAAe;AAAA,EACf,UAAU;AAAA;AAEZ;AAEA,IAAI,OAA+C;AAAA,EACjD,SAAS,EAAE,GAAG,gBAAgB;AAChC;AAEO,SAAS,mBAAmB;AAAA,EACjC;AAAA,EACA;AACF,GAKG;AACD,QAAM,gBAAgB,KAAK;AAC3B,MAAI,cAAc,GAAG,EAAG,OAAM,IAAI,iBAAiB,+BAA+B;AAClF,gBAAc,GAAG,IAAI;AACvB;AAEO,SAAS,UAAU,KAAa,QAAsC;AAC3E,MAAI,QAAQ,UAAW,OAAM,IAAI,iBAAiB,kBAAkB;AACpE,MAAI,CAAC,KAAK,GAAG,EAAG,MAAK,GAAG,IAAI,EAAE,GAAG,gBAAgB;AACjD,QAAM,SAAS,KAAK,GAAG;AACvB,SAAO,QAAQ,MAAM,EAAE,QAAQ,CAAC,CAAC,YAAY,YAAY,MAAM;AAC7D,WAAO,UAAU,IAAI;AAAA,EACvB,CAAC;AACH;AAEO,SAAS,eAAe;AAC7B,SAAO;AAAA,IACL,SAAS,EAAE,GAAG,gBAAgB;AAAA,EAChC;AACF;AAEO,SAAS,uBAAuB,KAAmC;AACxE,MAAI,CAAC,IAAK,QAAO,KAAK,SAAS;AAC/B,SAAQ,KAAK,GAAG,KAAK,KAAK,SAAS;AACrC;","names":[]}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _class;
|
|
2
|
+
|
|
3
|
+
var _chunk4SPM2CSQjs = require('./chunk-4SPM2CSQ.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkWPHJ4QTBjs = require('./chunk-WPHJ4QTB.js');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var _chunk42J6CHIOjs = require('./chunk-42J6CHIO.js');
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var _chunkLWAEUS2Fjs = require('./chunk-LWAEUS2F.js');
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
var _chunkEQNVYAKSjs = require('./chunk-EQNVYAKS.js');
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
var _chunkWK4O3HH4js = require('./chunk-WK4O3HH4.js');
|
|
19
|
+
|
|
20
|
+
// src/schemas/BigIntSchema.ts
|
|
21
|
+
var BigIntSchema = (_class = class extends _chunkEQNVYAKSjs.CommonSchema {constructor(...args) { super(...args); _class.prototype.__init.call(this); }
|
|
22
|
+
__init() {this._bigint = 1}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Restricts the schema to exactly match the specified value and infers the literal value as the TypeScript type.
|
|
26
|
+
*
|
|
27
|
+
* @param expectedValue - The value that the schema must exactly match.
|
|
28
|
+
* @returns - The schema instance restricted to the specified value, with the literal value inferred as the TypeScript type
|
|
29
|
+
*
|
|
30
|
+
* @example - bigint().equalTo(42n); // Infers the type 42n
|
|
31
|
+
*/
|
|
32
|
+
equalTo(expectedValue) {
|
|
33
|
+
if (this.limit) throw new (0, _chunkWK4O3HH4js.BuildSchemaError)(_chunk42J6CHIOjs.ONLY_ONCE);
|
|
34
|
+
this.limit = true;
|
|
35
|
+
_chunkLWAEUS2Fjs._setStrictType.call(void 0, this, `${expectedValue}n`);
|
|
36
|
+
return this.custom(_chunkWPHJ4QTBjs.equalTo.call(void 0, expectedValue));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Restricts the schema to match one of the specified values and infers the union of those values as the TypeScript type.
|
|
40
|
+
*
|
|
41
|
+
* @param expectedValues - An array of values that the schema can match.
|
|
42
|
+
* @returns - The schema instance restricted to one of the specified values, with the union of those values inferred as the TypeScript type.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* bigint().oneOfValues([5n, 7n]); // Infers the type 5n | 7n
|
|
46
|
+
*/
|
|
47
|
+
oneOfValues(expectedValue) {
|
|
48
|
+
if (this.limit) throw new (0, _chunkWK4O3HH4js.BuildSchemaError)(_chunk42J6CHIOjs.ONLY_ONCE);
|
|
49
|
+
this.limit = true;
|
|
50
|
+
_chunkLWAEUS2Fjs._setStrictType.call(void 0,
|
|
51
|
+
this,
|
|
52
|
+
expectedValue.map((el) => `${el}n`)
|
|
53
|
+
);
|
|
54
|
+
return this.custom(_chunk4SPM2CSQjs.oneOfValues.call(void 0, expectedValue));
|
|
55
|
+
}
|
|
56
|
+
}, _class);
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
exports.BigIntSchema = BigIntSchema;
|
|
61
|
+
//# sourceMappingURL=chunk-SEIKS6G7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-SEIKS6G7.js","../src/schemas/BigIntSchema.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,iBAC7C,QAAA,EAAU,EAAA;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUR,OAAA,CAA0B,aAAA,EAAuC;AAC/D,IAAA,GAAA,CAAI,IAAA,CAAK,KAAA,EAAO,MAAM,IAAI,sCAAA,CAAiB,0BAAS,CAAA;AACpD,IAAA,IAAA,CAAK,MAAA,EAAQ,IAAA;AACb,IAAA,6CAAA,IAAe,EAAM,CAAA,EAAA;AACF,IAAA;AACrB,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAW8B,EAAA;AACN,IAAA;AACT,IAAA;AACb,IAAA;AACE,MAAA;AACmB,MAAA;AACrB,IAAA;AACmB,IAAA;AACrB,EAAA;AACF;ADY0B;AACA;AACA;AACA","file":"/home/runner/work/bguard/bguard/lib/chunk-SEIKS6G7.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 BigIntSchema extends CommonSchema {\n _bigint = 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 - bigint().equalTo(42n); // Infers the type 42n\n */\n equalTo<Y extends bigint>(expectedValue: Y): WithBigInt<this, Y> {\n if (this.limit) throw new BuildSchemaError(ONLY_ONCE);\n this.limit = true;\n _setStrictType(this, `${expectedValue}n`);\n return this.custom(equalTo(expectedValue)) as WithBigInt<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 * bigint().oneOfValues([5n, 7n]); // Infers the type 5n | 7n\n */\n oneOfValues<Y extends bigint>(expectedValue: Y[]): WithBigInt<this, Y> {\n if (this.limit) throw new BuildSchemaError(ONLY_ONCE);\n this.limit = true;\n _setStrictType(\n this,\n expectedValue.map((el) => `${el}n`),\n );\n return this.custom(oneOfValues(expectedValue)) as WithBigInt<this, Y>;\n }\n}\n\nexport type WithBigInt<T extends BigIntSchema, Y = bigint> = T & { validation_bigint: Y };\nexport type ExtractFromBigInt<T> = T extends WithBigInt<BigIntSchema, infer Y> ? Y : never;\n"]}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
equalTo
|
|
3
|
-
} from "./chunk-NNFYXHLU.mjs";
|
|
4
1
|
import {
|
|
5
2
|
oneOfValues
|
|
6
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-YPAUFM3S.mjs";
|
|
4
|
+
import {
|
|
5
|
+
equalTo
|
|
6
|
+
} from "./chunk-M6OCVAUD.mjs";
|
|
7
7
|
import {
|
|
8
8
|
ONLY_ONCE
|
|
9
9
|
} from "./chunk-ASZW6XRM.mjs";
|
|
10
10
|
import {
|
|
11
11
|
_setStrictType
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-54RHVQFA.mjs";
|
|
13
13
|
import {
|
|
14
14
|
CommonSchema
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-4UF67IQ2.mjs";
|
|
16
16
|
import {
|
|
17
17
|
BuildSchemaError
|
|
18
18
|
} from "./chunk-7XFLH6R2.mjs";
|
|
@@ -58,4 +58,4 @@ var StringSchema = class extends CommonSchema {
|
|
|
58
58
|
export {
|
|
59
59
|
StringSchema
|
|
60
60
|
};
|
|
61
|
-
//# sourceMappingURL=chunk-
|
|
61
|
+
//# sourceMappingURL=chunk-TP5I237J.mjs.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {
|
|
2
|
+
oneOfValues
|
|
3
|
+
} from "./chunk-YPAUFM3S.mjs";
|
|
4
|
+
import {
|
|
5
|
+
equalTo
|
|
6
|
+
} from "./chunk-M6OCVAUD.mjs";
|
|
7
|
+
import {
|
|
8
|
+
ONLY_ONCE
|
|
9
|
+
} from "./chunk-ASZW6XRM.mjs";
|
|
10
|
+
import {
|
|
11
|
+
_setStrictType
|
|
12
|
+
} from "./chunk-54RHVQFA.mjs";
|
|
13
|
+
import {
|
|
14
|
+
CommonSchema
|
|
15
|
+
} from "./chunk-4UF67IQ2.mjs";
|
|
16
|
+
import {
|
|
17
|
+
BuildSchemaError
|
|
18
|
+
} from "./chunk-7XFLH6R2.mjs";
|
|
19
|
+
|
|
20
|
+
// src/schemas/BigIntSchema.ts
|
|
21
|
+
var BigIntSchema = class extends CommonSchema {
|
|
22
|
+
_bigint = 1;
|
|
23
|
+
limit;
|
|
24
|
+
/**
|
|
25
|
+
* Restricts the schema to exactly match the specified value and infers the literal value as the TypeScript type.
|
|
26
|
+
*
|
|
27
|
+
* @param expectedValue - The value that the schema must exactly match.
|
|
28
|
+
* @returns - The schema instance restricted to the specified value, with the literal value inferred as the TypeScript type
|
|
29
|
+
*
|
|
30
|
+
* @example - bigint().equalTo(42n); // Infers the type 42n
|
|
31
|
+
*/
|
|
32
|
+
equalTo(expectedValue) {
|
|
33
|
+
if (this.limit) throw new BuildSchemaError(ONLY_ONCE);
|
|
34
|
+
this.limit = true;
|
|
35
|
+
_setStrictType(this, `${expectedValue}n`);
|
|
36
|
+
return this.custom(equalTo(expectedValue));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Restricts the schema to match one of the specified values and infers the union of those values as the TypeScript type.
|
|
40
|
+
*
|
|
41
|
+
* @param expectedValues - An array of values that the schema can match.
|
|
42
|
+
* @returns - The schema instance restricted to one of the specified values, with the union of those values inferred as the TypeScript type.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* bigint().oneOfValues([5n, 7n]); // Infers the type 5n | 7n
|
|
46
|
+
*/
|
|
47
|
+
oneOfValues(expectedValue) {
|
|
48
|
+
if (this.limit) throw new BuildSchemaError(ONLY_ONCE);
|
|
49
|
+
this.limit = true;
|
|
50
|
+
_setStrictType(
|
|
51
|
+
this,
|
|
52
|
+
expectedValue.map((el) => `${el}n`)
|
|
53
|
+
);
|
|
54
|
+
return this.custom(oneOfValues(expectedValue));
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export {
|
|
59
|
+
BigIntSchema
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=chunk-UV4I7JZR.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/schemas/BigIntSchema.ts"],"sourcesContent":["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 BigIntSchema extends CommonSchema {\n _bigint = 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 - bigint().equalTo(42n); // Infers the type 42n\n */\n equalTo<Y extends bigint>(expectedValue: Y): WithBigInt<this, Y> {\n if (this.limit) throw new BuildSchemaError(ONLY_ONCE);\n this.limit = true;\n _setStrictType(this, `${expectedValue}n`);\n return this.custom(equalTo(expectedValue)) as WithBigInt<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 * bigint().oneOfValues([5n, 7n]); // Infers the type 5n | 7n\n */\n oneOfValues<Y extends bigint>(expectedValue: Y[]): WithBigInt<this, Y> {\n if (this.limit) throw new BuildSchemaError(ONLY_ONCE);\n this.limit = true;\n _setStrictType(\n this,\n expectedValue.map((el) => `${el}n`),\n );\n return this.custom(oneOfValues(expectedValue)) as WithBigInt<this, Y>;\n }\n}\n\nexport type WithBigInt<T extends BigIntSchema, Y = bigint> = T & { validation_bigint: Y };\nexport type ExtractFromBigInt<T> = T extends WithBigInt<BigIntSchema, infer Y> ? Y : never;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAOO,IAAM,eAAN,cAA2B,aAAa;AAAA,EAC7C,UAAU;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUR,QAA0B,eAAuC;AAC/D,QAAI,KAAK,MAAO,OAAM,IAAI,iBAAiB,SAAS;AACpD,SAAK,QAAQ;AACb,mBAAe,MAAM,GAAG,aAAa,GAAG;AACxC,WAAO,KAAK,OAAO,QAAQ,aAAa,CAAC;AAAA,EAC3C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,YAA8B,eAAyC;AACrE,QAAI,KAAK,MAAO,OAAM,IAAI,iBAAiB,SAAS;AACpD,SAAK,QAAQ;AACb;AAAA,MACE;AAAA,MACA,cAAc,IAAI,CAAC,OAAO,GAAG,EAAE,GAAG;AAAA,IACpC;AACA,WAAO,KAAK,OAAO,YAAY,aAAa,CAAC;AAAA,EAC/C;AACF;","names":[]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
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
|
-
var
|
|
3
|
+
var _chunk7GIRQ5EAjs = require('./chunk-7GIRQ5EA.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkCQWI6YRIjs = require('./chunk-CQWI6YRI.js');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
var _chunkWK4O3HH4js = require('./chunk-WK4O3HH4.js');
|
|
@@ -12,12 +12,12 @@ var _chunkWK4O3HH4js = require('./chunk-WK4O3HH4.js');
|
|
|
12
12
|
function parse(schema, receivedValue, options) {
|
|
13
13
|
try {
|
|
14
14
|
const ctx = {
|
|
15
|
-
t:
|
|
15
|
+
t: _chunkCQWI6YRIjs.getTranslationByLocale.call(void 0, _optionalChain([options, 'optionalAccess', _ => _.lng])),
|
|
16
16
|
pathToError: "",
|
|
17
17
|
getAllErrors: _optionalChain([options, 'optionalAccess', _2 => _2.getAllErrors]),
|
|
18
18
|
errors: []
|
|
19
19
|
};
|
|
20
|
-
const parsedValue =
|
|
20
|
+
const parsedValue = _chunk7GIRQ5EAjs.innerCheck.call(void 0, schema, receivedValue, ctx);
|
|
21
21
|
if (ctx.getAllErrors && ctx.errors.length) {
|
|
22
22
|
return [ctx.errors, void 0];
|
|
23
23
|
}
|
|
@@ -44,4 +44,4 @@ function parse(schema, receivedValue, options) {
|
|
|
44
44
|
|
|
45
45
|
|
|
46
46
|
exports.parse = parse;
|
|
47
|
-
//# sourceMappingURL=chunk-
|
|
47
|
+
//# sourceMappingURL=chunk-VGF3Y2EK.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-VGF3Y2EK.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-VGF3Y2EK.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"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkCQWI6YRIjs = require('./chunk-CQWI6YRI.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
var _chunkWK4O3HH4js = require('./chunk-WK4O3HH4.js');
|
|
@@ -13,9 +13,9 @@ var equalTo = (expected) => (received, ctx) => {
|
|
|
13
13
|
};
|
|
14
14
|
equalTo.key = equalToErrorKey;
|
|
15
15
|
equalTo.message = equalToErrorMessage;
|
|
16
|
-
|
|
16
|
+
_chunkCQWI6YRIjs.setToDefaultLocale.call(void 0, equalTo);
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
exports.equalTo = equalTo;
|
|
21
|
-
//# sourceMappingURL=chunk-
|
|
21
|
+
//# sourceMappingURL=chunk-WPHJ4QTB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-WPHJ4QTB.js","../src/asserts/mix/equalTo.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACA;ACHA,IAAM,oBAAA,EAAsB,6CAAA;AAC5B,IAAM,gBAAA,EAAkB,WAAA;AAejB,IAAM,QAAA,EACX,CAAC,QAAA,EAAA,GACD,CAAC,QAAA,EAAmB,GAAA,EAAA,GAA0B;AAC5C,EAAA,GAAA,CAAI,SAAA,IAAa,QAAA,EAAU,6CAAA,QAAe,EAAU,QAAA,EAAU,GAAA,EAAK,eAAe,CAAA;AACpF,CAAA;AAEF,OAAA,CAAQ,IAAA,EAAM,eAAA;AACd,OAAA,CAAQ,QAAA,EAAU,mBAAA;AAClB,iDAAA,OAA0B,CAAA;ADZ1B;AACA;AACE;AACF,0BAAC","file":"/home/runner/work/bguard/bguard/lib/chunk-WPHJ4QTB.js","sourcesContent":[null,"import { guardException } from '../../exceptions';\nimport { ExceptionContext, RequiredValidation } from '../../commonTypes';\nimport { setToDefaultLocale } from '../../translationMap';\n\nconst equalToErrorMessage = 'The received value is not equal to expected';\nconst equalToErrorKey = 'm:equalTo';\n\n/**\n * @description Creates a custom assertion that checks if a value is equal to the expected value.\n * @notice It has already been implemented in the number, bigint and string schema. There is no need to use it as a custom assert.\n * @param {unknown} expected The value that the received value is expected to match.\n * @returns {RequiredValidation} A validation function that takes a received value and an exception context.\n * @throws {ValidationError} If the received value does not match the expected value.\n * @example\n * const schema = number().custom(equalTo(5)); // Define a schema with a custom assertion\n * parseOrFail(schema, 5); // Valid\n * parseOrFail(schema, 3); // Throws an error: 'The received value is not equal to expected'\n *\n * @translation Error Translation Key = 'm:equalTo'\n */\nexport const equalTo =\n (expected: unknown): RequiredValidation =>\n (received: unknown, ctx: ExceptionContext) => {\n if (expected !== received) guardException(expected, received, ctx, equalToErrorKey);\n };\n\nequalTo.key = equalToErrorKey;\nequalTo.message = equalToErrorMessage;\nsetToDefaultLocale(equalTo);\n"]}
|