bguard 0.0.9 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +844 -26
- package/lib/{CommonSchema-BIe85W_A.d.mts → CommonSchema-BbGNki0L.d.ts} +7 -4
- package/lib/{CommonSchema-BIe85W_A.d.ts → CommonSchema-CjsYE4dC.d.mts} +7 -4
- package/lib/InferType.d.mts +2 -1
- package/lib/InferType.d.ts +2 -1
- package/lib/asserts/array/index.d.mts +4 -3
- package/lib/asserts/array/index.d.ts +4 -3
- package/lib/asserts/array/index.js +6 -6
- package/lib/asserts/array/index.mjs +5 -5
- package/lib/asserts/boolean/index.d.mts +4 -3
- package/lib/asserts/boolean/index.d.ts +4 -3
- package/lib/asserts/boolean/index.js +7 -6
- package/lib/asserts/boolean/index.js.map +1 -1
- package/lib/asserts/boolean/index.mjs +6 -5
- package/lib/asserts/mix/equalTo.d.mts +22 -0
- package/lib/asserts/mix/equalTo.d.ts +22 -0
- package/lib/asserts/mix/equalTo.js +9 -0
- package/lib/asserts/mix/equalTo.js.map +1 -0
- package/lib/asserts/mix/equalTo.mjs +9 -0
- package/lib/asserts/{common → mix}/index.d.mts +5 -4
- package/lib/asserts/{common → mix}/index.d.ts +5 -4
- package/lib/asserts/mix/index.js +10 -0
- package/lib/asserts/mix/index.js.map +1 -0
- package/lib/asserts/mix/index.mjs +10 -0
- package/lib/asserts/mix/oneOfValues.d.mts +23 -0
- package/lib/asserts/mix/oneOfValues.d.ts +23 -0
- package/lib/asserts/mix/oneOfValues.js +9 -0
- package/lib/asserts/mix/oneOfValues.js.map +1 -0
- package/lib/asserts/mix/oneOfValues.mjs +9 -0
- package/lib/asserts/number/index.d.mts +4 -3
- package/lib/asserts/number/index.d.ts +4 -3
- package/lib/asserts/number/index.js +11 -7
- package/lib/asserts/number/index.js.map +1 -1
- package/lib/asserts/number/index.mjs +10 -6
- package/lib/asserts/number/max.d.mts +15 -10
- package/lib/asserts/number/max.d.ts +15 -10
- package/lib/asserts/number/max.js +11 -4
- package/lib/asserts/number/max.js.map +1 -1
- package/lib/asserts/number/max.mjs +12 -5
- package/lib/asserts/number/max.mjs.map +1 -1
- package/lib/asserts/number/maxExcluded.d.mts +14 -9
- package/lib/asserts/number/maxExcluded.d.ts +14 -9
- package/lib/asserts/number/maxExcluded.js +11 -4
- package/lib/asserts/number/maxExcluded.js.map +1 -1
- package/lib/asserts/number/maxExcluded.mjs +12 -5
- package/lib/asserts/number/maxExcluded.mjs.map +1 -1
- package/lib/asserts/number/min.d.mts +15 -10
- package/lib/asserts/number/min.d.ts +15 -10
- package/lib/asserts/number/min.js +11 -4
- package/lib/asserts/number/min.js.map +1 -1
- package/lib/asserts/number/min.mjs +12 -5
- package/lib/asserts/number/min.mjs.map +1 -1
- package/lib/asserts/number/minExcluded.d.mts +15 -10
- package/lib/asserts/number/minExcluded.d.ts +15 -10
- package/lib/asserts/number/minExcluded.js +11 -4
- package/lib/asserts/number/minExcluded.js.map +1 -1
- package/lib/asserts/number/minExcluded.mjs +12 -5
- package/lib/asserts/number/minExcluded.mjs.map +1 -1
- package/lib/asserts/number/negative.d.mts +14 -9
- package/lib/asserts/number/negative.d.ts +14 -9
- package/lib/asserts/number/negative.js +11 -3
- package/lib/asserts/number/negative.js.map +1 -1
- package/lib/asserts/number/negative.mjs +12 -4
- package/lib/asserts/number/negative.mjs.map +1 -1
- package/lib/asserts/number/positive.d.mts +14 -9
- package/lib/asserts/number/positive.d.ts +14 -9
- package/lib/asserts/number/positive.js +11 -3
- package/lib/asserts/number/positive.js.map +1 -1
- package/lib/asserts/number/positive.mjs +12 -4
- package/lib/asserts/number/positive.mjs.map +1 -1
- package/lib/asserts/object/index.d.mts +4 -3
- package/lib/asserts/object/index.d.ts +4 -3
- package/lib/asserts/object/index.js +6 -6
- package/lib/asserts/object/index.mjs +5 -5
- package/lib/asserts/string/atLeastOneDigit.d.mts +20 -0
- package/lib/asserts/string/atLeastOneDigit.d.ts +20 -0
- package/lib/asserts/string/atLeastOneDigit.js +21 -0
- package/lib/asserts/string/atLeastOneDigit.js.map +1 -0
- package/lib/asserts/string/atLeastOneDigit.mjs +21 -0
- package/lib/asserts/string/atLeastOneDigit.mjs.map +1 -0
- package/lib/asserts/string/atLeastOneLowerChar.d.mts +20 -0
- package/lib/asserts/string/atLeastOneLowerChar.d.ts +20 -0
- package/lib/asserts/string/atLeastOneLowerChar.js +22 -0
- package/lib/asserts/string/atLeastOneLowerChar.js.map +1 -0
- package/lib/asserts/string/atLeastOneLowerChar.mjs +22 -0
- package/lib/asserts/string/atLeastOneLowerChar.mjs.map +1 -0
- package/lib/asserts/string/atLeastOneSpecialChar.d.mts +25 -0
- package/lib/asserts/string/atLeastOneSpecialChar.d.ts +25 -0
- package/lib/asserts/string/atLeastOneSpecialChar.js +26 -0
- package/lib/asserts/string/atLeastOneSpecialChar.js.map +1 -0
- package/lib/asserts/string/atLeastOneSpecialChar.mjs +26 -0
- package/lib/asserts/string/atLeastOneSpecialChar.mjs.map +1 -0
- package/lib/asserts/string/atLeastOneUpperChar.d.mts +20 -0
- package/lib/asserts/string/atLeastOneUpperChar.d.ts +20 -0
- package/lib/asserts/string/atLeastOneUpperChar.js +22 -0
- package/lib/asserts/string/atLeastOneUpperChar.js.map +1 -0
- package/lib/asserts/string/atLeastOneUpperChar.mjs +22 -0
- package/lib/asserts/string/atLeastOneUpperChar.mjs.map +1 -0
- package/lib/asserts/string/contains.d.mts +21 -0
- package/lib/asserts/string/contains.d.ts +21 -0
- package/lib/asserts/string/contains.js +22 -0
- package/lib/asserts/string/contains.js.map +1 -0
- package/lib/asserts/string/contains.mjs +22 -0
- package/lib/asserts/string/contains.mjs.map +1 -0
- package/lib/asserts/string/email.d.mts +13 -9
- package/lib/asserts/string/email.d.ts +13 -9
- package/lib/asserts/string/email.js +11 -4
- package/lib/asserts/string/email.js.map +1 -1
- package/lib/asserts/string/email.mjs +12 -5
- package/lib/asserts/string/email.mjs.map +1 -1
- package/lib/asserts/string/endsWith.d.mts +21 -0
- package/lib/asserts/string/endsWith.d.ts +21 -0
- package/lib/asserts/string/endsWith.js +22 -0
- package/lib/asserts/string/endsWith.js.map +1 -0
- package/lib/asserts/string/endsWith.mjs +22 -0
- package/lib/asserts/string/endsWith.mjs.map +1 -0
- package/lib/asserts/string/index.d.mts +4 -3
- package/lib/asserts/string/index.d.ts +4 -3
- package/lib/asserts/string/index.js +11 -7
- package/lib/asserts/string/index.js.map +1 -1
- package/lib/asserts/string/index.mjs +10 -6
- package/lib/asserts/string/lowerCase.d.mts +20 -0
- package/lib/asserts/string/lowerCase.d.ts +20 -0
- package/lib/asserts/string/lowerCase.js +20 -0
- package/lib/asserts/string/lowerCase.js.map +1 -0
- package/lib/asserts/string/lowerCase.mjs +20 -0
- package/lib/asserts/string/lowerCase.mjs.map +1 -0
- package/lib/asserts/string/maxLength.d.mts +14 -9
- package/lib/asserts/string/maxLength.d.ts +14 -9
- package/lib/asserts/string/maxLength.js +11 -4
- package/lib/asserts/string/maxLength.js.map +1 -1
- package/lib/asserts/string/maxLength.mjs +12 -5
- package/lib/asserts/string/maxLength.mjs.map +1 -1
- package/lib/asserts/string/minLength.d.mts +14 -9
- package/lib/asserts/string/minLength.d.ts +14 -9
- package/lib/asserts/string/minLength.js +11 -4
- package/lib/asserts/string/minLength.js.map +1 -1
- package/lib/asserts/string/minLength.mjs +12 -5
- package/lib/asserts/string/minLength.mjs.map +1 -1
- package/lib/asserts/string/regExp.d.mts +14 -9
- package/lib/asserts/string/regExp.d.ts +14 -9
- package/lib/asserts/string/regExp.js +11 -4
- package/lib/asserts/string/regExp.js.map +1 -1
- package/lib/asserts/string/regExp.mjs +12 -5
- package/lib/asserts/string/regExp.mjs.map +1 -1
- package/lib/asserts/string/startsWith.d.mts +21 -0
- package/lib/asserts/string/startsWith.d.ts +21 -0
- package/lib/asserts/string/startsWith.js +22 -0
- package/lib/asserts/string/startsWith.js.map +1 -0
- package/lib/asserts/string/startsWith.mjs +22 -0
- package/lib/asserts/string/startsWith.mjs.map +1 -0
- package/lib/asserts/string/upperCase.d.mts +21 -0
- package/lib/asserts/string/upperCase.d.ts +21 -0
- package/lib/asserts/string/upperCase.js +22 -0
- package/lib/asserts/string/upperCase.js.map +1 -0
- package/lib/asserts/string/upperCase.mjs +22 -0
- package/lib/asserts/string/upperCase.mjs.map +1 -0
- package/lib/asserts/string/uuid.d.mts +20 -0
- package/lib/asserts/string/uuid.d.ts +20 -0
- package/lib/asserts/string/uuid.js +23 -0
- package/lib/asserts/string/uuid.js.map +1 -0
- package/lib/asserts/string/uuid.mjs +23 -0
- package/lib/asserts/string/uuid.mjs.map +1 -0
- package/lib/asserts/string/uuidV1.d.mts +21 -0
- package/lib/asserts/string/uuidV1.d.ts +21 -0
- package/lib/asserts/string/uuidV1.js +23 -0
- package/lib/asserts/string/uuidV1.js.map +1 -0
- package/lib/asserts/string/uuidV1.mjs +23 -0
- package/lib/asserts/string/uuidV1.mjs.map +1 -0
- package/lib/asserts/string/uuidV2.d.mts +21 -0
- package/lib/asserts/string/uuidV2.d.ts +21 -0
- package/lib/asserts/string/uuidV2.js +23 -0
- package/lib/asserts/string/uuidV2.js.map +1 -0
- package/lib/asserts/string/uuidV2.mjs +23 -0
- package/lib/asserts/string/uuidV2.mjs.map +1 -0
- package/lib/asserts/string/uuidV3.d.mts +21 -0
- package/lib/asserts/string/uuidV3.d.ts +21 -0
- package/lib/asserts/string/uuidV3.js +23 -0
- package/lib/asserts/string/uuidV3.js.map +1 -0
- package/lib/asserts/string/uuidV3.mjs +23 -0
- package/lib/asserts/string/uuidV3.mjs.map +1 -0
- package/lib/asserts/string/uuidV4.d.mts +23 -0
- package/lib/asserts/string/uuidV4.d.ts +23 -0
- package/lib/asserts/string/uuidV4.js +23 -0
- package/lib/asserts/string/uuidV4.js.map +1 -0
- package/lib/asserts/string/uuidV4.mjs +23 -0
- package/lib/asserts/string/uuidV4.mjs.map +1 -0
- package/lib/asserts/string/uuidV5.d.mts +21 -0
- package/lib/asserts/string/uuidV5.d.ts +21 -0
- package/lib/asserts/string/uuidV5.js +23 -0
- package/lib/asserts/string/uuidV5.js.map +1 -0
- package/lib/asserts/string/uuidV5.mjs +23 -0
- package/lib/asserts/string/uuidV5.mjs.map +1 -0
- package/lib/asserts/string/validUrl.d.mts +23 -0
- package/lib/asserts/string/validUrl.d.ts +23 -0
- package/lib/asserts/string/validUrl.js +32 -0
- package/lib/asserts/string/validUrl.js.map +1 -0
- package/lib/asserts/string/validUrl.mjs +32 -0
- package/lib/asserts/string/validUrl.mjs.map +1 -0
- package/lib/{chunk-32IQXZRK.mjs → chunk-2PM3K3OE.mjs} +2 -2
- package/lib/{chunk-32IQXZRK.mjs.map → chunk-2PM3K3OE.mjs.map} +1 -1
- package/lib/{chunk-KCBOOOTF.mjs → chunk-32RSTOZ4.mjs} +2 -2
- package/lib/{chunk-KCBOOOTF.mjs.map → chunk-32RSTOZ4.mjs.map} +1 -1
- package/lib/chunk-3HTYHE2X.mjs +54 -0
- package/lib/chunk-3HTYHE2X.mjs.map +1 -0
- package/lib/chunk-3O4WCRC2.mjs +21 -0
- package/lib/chunk-3O4WCRC2.mjs.map +1 -0
- package/lib/chunk-42J6CHIO.js +7 -0
- package/lib/chunk-42J6CHIO.js.map +1 -0
- package/lib/chunk-4CYIMDP2.js +21 -0
- package/lib/chunk-4CYIMDP2.js.map +1 -0
- package/lib/chunk-5BVJ6YMH.js +54 -0
- package/lib/chunk-5BVJ6YMH.js.map +1 -0
- package/lib/chunk-6TH3DBDK.js +53 -0
- package/lib/chunk-6TH3DBDK.js.map +1 -0
- package/lib/chunk-7XFLH6R2.mjs +44 -0
- package/lib/chunk-7XFLH6R2.mjs.map +1 -0
- package/lib/chunk-ASZW6XRM.mjs +7 -0
- package/lib/chunk-ASZW6XRM.mjs.map +1 -0
- package/lib/{chunk-GEZME6V2.mjs → chunk-CCBCDJXS.mjs} +11 -6
- package/lib/chunk-CCBCDJXS.mjs.map +1 -0
- package/lib/chunk-DJSLA2ZV.js +27 -0
- package/lib/chunk-DJSLA2ZV.js.map +1 -0
- package/lib/{chunk-L7HUXYFV.mjs → chunk-DPBE7TAQ.mjs} +2 -2
- package/lib/chunk-DPBE7TAQ.mjs.map +1 -0
- package/lib/{chunk-APTTIN2L.js → chunk-EGEHSELT.js} +6 -6
- package/lib/chunk-EGEHSELT.js.map +1 -0
- package/lib/chunk-H7CPKW53.js +47 -0
- package/lib/chunk-H7CPKW53.js.map +1 -0
- package/lib/{chunk-A7I2JEQO.js → chunk-HDSGCAHH.js} +3 -3
- package/lib/{chunk-A7I2JEQO.js.map → chunk-HDSGCAHH.js.map} +1 -1
- package/lib/{chunk-L6A7NXUJ.js → chunk-IEUXIOL6.js} +3 -3
- package/lib/{chunk-L6A7NXUJ.js.map → chunk-IEUXIOL6.js.map} +1 -1
- package/lib/chunk-IRG4OQAB.js +63 -0
- package/lib/chunk-IRG4OQAB.js.map +1 -0
- package/lib/chunk-J4VKFJQK.js +21 -0
- package/lib/chunk-J4VKFJQK.js.map +1 -0
- package/lib/{chunk-A2SAWKJA.mjs → chunk-JDGZCBXF.mjs} +2 -2
- package/lib/{chunk-A2SAWKJA.mjs.map → chunk-JDGZCBXF.mjs.map} +1 -1
- package/lib/chunk-JPRCULRQ.mjs +61 -0
- package/lib/chunk-JPRCULRQ.mjs.map +1 -0
- package/lib/chunk-JSGZ7DKT.js +14 -0
- package/lib/chunk-JSGZ7DKT.js.map +1 -0
- package/lib/chunk-KQKJASVB.js +58 -0
- package/lib/chunk-KQKJASVB.js.map +1 -0
- package/lib/chunk-LEQCDD66.js +61 -0
- package/lib/chunk-LEQCDD66.js.map +1 -0
- package/lib/{chunk-AJ4WV5DG.mjs → chunk-MRISXZQ4.mjs} +3 -3
- package/lib/chunk-MRISXZQ4.mjs.map +1 -0
- package/lib/{chunk-A3UTB4RE.mjs → chunk-NDQM5OL4.mjs} +4 -4
- package/lib/chunk-NDQM5OL4.mjs.map +1 -0
- package/lib/chunk-NNFYXHLU.mjs +21 -0
- package/lib/chunk-NNFYXHLU.mjs.map +1 -0
- package/lib/chunk-P7IXNCJG.mjs +58 -0
- package/lib/chunk-P7IXNCJG.mjs.map +1 -0
- package/lib/chunk-PG2R7P7G.mjs +27 -0
- package/lib/chunk-PG2R7P7G.mjs.map +1 -0
- package/lib/chunk-PH2PMUZP.mjs +63 -0
- package/lib/chunk-PH2PMUZP.mjs.map +1 -0
- package/lib/{chunk-BGMR7A6X.mjs → chunk-PXBAS3GA.mjs} +2 -2
- package/lib/{chunk-BGMR7A6X.mjs.map → chunk-PXBAS3GA.mjs.map} +1 -1
- package/lib/chunk-QQNQ4IDN.js +13 -0
- package/lib/chunk-QQNQ4IDN.js.map +1 -0
- package/lib/{chunk-QKGQ4XZC.js → chunk-RD6TBCPQ.js} +3 -3
- package/lib/{chunk-QKGQ4XZC.js.map → chunk-RD6TBCPQ.js.map} +1 -1
- package/lib/chunk-RRQOET3X.js +28 -0
- package/lib/chunk-RRQOET3X.js.map +1 -0
- package/lib/chunk-RYVUYVEE.mjs +14 -0
- package/lib/chunk-RYVUYVEE.mjs.map +1 -0
- package/lib/{chunk-QYLH5ZAC.mjs → chunk-TCQY2R3U.mjs} +25 -4
- package/lib/chunk-TCQY2R3U.mjs.map +1 -0
- package/lib/{chunk-PJP63SJT.js → chunk-TKZ6FLLR.js} +3 -3
- package/lib/{chunk-PJP63SJT.js.map → chunk-TKZ6FLLR.js.map} +1 -1
- package/lib/{chunk-K2S3FS5K.js → chunk-VHEA4JZ5.js} +3 -3
- package/lib/{chunk-K2S3FS5K.js.map → chunk-VHEA4JZ5.js.map} +1 -1
- package/lib/{chunk-VPFIIM2X.js → chunk-WBERBAL4.js} +11 -6
- package/lib/chunk-WBERBAL4.js.map +1 -0
- package/lib/chunk-WK4O3HH4.js +44 -0
- package/lib/chunk-WK4O3HH4.js.map +1 -0
- package/lib/{chunk-3FEJUC3K.mjs → chunk-YML32TPA.mjs} +2 -2
- package/lib/{chunk-3FEJUC3K.mjs.map → chunk-YML32TPA.mjs.map} +1 -1
- package/lib/chunk-YUESB2WV.mjs +47 -0
- package/lib/chunk-YUESB2WV.mjs.map +1 -0
- package/lib/codeGen.d.mts +7 -0
- package/lib/codeGen.d.ts +7 -0
- package/lib/codeGen.js +51 -0
- package/lib/codeGen.js.map +1 -0
- package/lib/codeGen.mjs +51 -0
- package/lib/codeGen.mjs.map +1 -0
- package/lib/commonTypes.d.mts +31 -0
- package/lib/commonTypes.d.ts +31 -0
- package/lib/commonTypes.js +1 -0
- package/lib/commonTypes.js.map +1 -0
- package/lib/commonTypes.mjs +1 -0
- package/lib/exceptions.d.mts +4 -2
- package/lib/exceptions.d.ts +4 -2
- package/lib/exceptions.js +2 -2
- package/lib/exceptions.mjs +3 -3
- package/lib/helpers/constants.d.mts +3 -0
- package/lib/helpers/constants.d.ts +3 -0
- package/lib/helpers/constants.js +7 -0
- package/lib/helpers/constants.js.map +1 -0
- package/lib/helpers/constants.mjs +7 -0
- package/lib/helpers/constants.mjs.map +1 -0
- package/lib/helpers/core.d.mts +2 -0
- package/lib/helpers/core.d.ts +2 -0
- package/lib/helpers/core.js +10 -0
- package/lib/helpers/core.js.map +1 -0
- package/lib/helpers/core.mjs +10 -0
- package/lib/helpers/core.mjs.map +1 -0
- package/lib/helpers/setStrictType.d.mts +6 -0
- package/lib/helpers/setStrictType.d.ts +6 -0
- package/lib/helpers/setStrictType.js +9 -0
- package/lib/helpers/setStrictType.js.map +1 -0
- package/lib/helpers/setStrictType.mjs +9 -0
- package/lib/helpers/setStrictType.mjs.map +1 -0
- package/lib/index.d.mts +7 -4
- package/lib/index.d.ts +7 -4
- package/lib/index.js +32 -17
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +37 -22
- package/lib/parse.d.mts +66 -0
- package/lib/parse.d.ts +66 -0
- package/lib/parse.js +10 -0
- package/lib/parse.js.map +1 -0
- package/lib/parse.mjs +10 -0
- package/lib/parse.mjs.map +1 -0
- package/lib/{parseSchema.d.mts → parseOrFail.d.mts} +16 -5
- package/lib/{parseSchema.d.ts → parseOrFail.d.ts} +16 -5
- package/lib/parseOrFail.js +10 -0
- package/lib/parseOrFail.js.map +1 -0
- package/lib/parseOrFail.mjs +10 -0
- package/lib/parseOrFail.mjs.map +1 -0
- package/lib/schemas/ArraySchema.d.mts +2 -1
- package/lib/schemas/ArraySchema.d.ts +2 -1
- package/lib/schemas/ArraySchema.js +5 -5
- package/lib/schemas/ArraySchema.mjs +4 -4
- package/lib/schemas/BooleanSchema.d.mts +2 -1
- package/lib/schemas/BooleanSchema.d.ts +2 -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 +2 -1
- package/lib/schemas/CommonSchema.d.ts +2 -1
- package/lib/schemas/CommonSchema.js +4 -4
- package/lib/schemas/CommonSchema.mjs +3 -3
- package/lib/schemas/NumberSchema.d.mts +13 -1
- package/lib/schemas/NumberSchema.d.ts +13 -1
- package/lib/schemas/NumberSchema.js +10 -6
- package/lib/schemas/NumberSchema.js.map +1 -1
- package/lib/schemas/NumberSchema.mjs +9 -5
- package/lib/schemas/ObjectSchema.d.mts +20 -1
- package/lib/schemas/ObjectSchema.d.ts +20 -1
- package/lib/schemas/ObjectSchema.js +5 -5
- package/lib/schemas/ObjectSchema.mjs +4 -4
- package/lib/schemas/StringSchema.d.mts +13 -1
- package/lib/schemas/StringSchema.d.ts +13 -1
- package/lib/schemas/StringSchema.js +10 -6
- package/lib/schemas/StringSchema.js.map +1 -1
- package/lib/schemas/StringSchema.mjs +9 -5
- package/lib/translationMap.d.mts +12 -0
- package/lib/translationMap.d.ts +12 -0
- package/lib/translationMap.js +14 -0
- package/lib/translationMap.js.map +1 -0
- package/lib/translationMap.mjs +14 -0
- package/lib/translationMap.mjs.map +1 -0
- package/package.json +23 -6
- package/lib/asserts/common/equalTo.d.mts +0 -29
- package/lib/asserts/common/equalTo.d.ts +0 -29
- package/lib/asserts/common/equalTo.js +0 -8
- package/lib/asserts/common/equalTo.js.map +0 -1
- package/lib/asserts/common/equalTo.mjs +0 -8
- package/lib/asserts/common/index.js +0 -10
- package/lib/asserts/common/index.js.map +0 -1
- package/lib/asserts/common/index.mjs +0 -10
- package/lib/chunk-2AP4OQMT.js +0 -26
- package/lib/chunk-2AP4OQMT.js.map +0 -1
- package/lib/chunk-5NCJN6D2.js +0 -70
- package/lib/chunk-5NCJN6D2.js.map +0 -1
- package/lib/chunk-5ZMICHV3.js +0 -21
- package/lib/chunk-5ZMICHV3.js.map +0 -1
- package/lib/chunk-63IQFNFO.mjs +0 -27
- package/lib/chunk-63IQFNFO.mjs.map +0 -1
- package/lib/chunk-A3UTB4RE.mjs.map +0 -1
- package/lib/chunk-AJ4WV5DG.mjs.map +0 -1
- package/lib/chunk-APTTIN2L.js.map +0 -1
- package/lib/chunk-AXOP6HPJ.js +0 -14
- package/lib/chunk-AXOP6HPJ.js.map +0 -1
- package/lib/chunk-FCFO5J5Y.mjs +0 -14
- package/lib/chunk-FCFO5J5Y.mjs.map +0 -1
- package/lib/chunk-GEZME6V2.mjs.map +0 -1
- package/lib/chunk-GNBSKTFV.js +0 -27
- package/lib/chunk-GNBSKTFV.js.map +0 -1
- package/lib/chunk-IQ3QYABE.js +0 -32
- package/lib/chunk-IQ3QYABE.js.map +0 -1
- package/lib/chunk-L7HUXYFV.mjs.map +0 -1
- package/lib/chunk-LHTJHMKJ.mjs +0 -27
- package/lib/chunk-LHTJHMKJ.mjs.map +0 -1
- package/lib/chunk-NOADI6PO.mjs +0 -21
- package/lib/chunk-NOADI6PO.mjs.map +0 -1
- package/lib/chunk-NWY33MFU.js +0 -13
- package/lib/chunk-NWY33MFU.js.map +0 -1
- package/lib/chunk-P3Y6IWFA.mjs +0 -70
- package/lib/chunk-P3Y6IWFA.mjs.map +0 -1
- package/lib/chunk-PDVXBE27.js +0 -27
- package/lib/chunk-PDVXBE27.js.map +0 -1
- package/lib/chunk-QJOXKH7A.mjs +0 -26
- package/lib/chunk-QJOXKH7A.mjs.map +0 -1
- package/lib/chunk-QYLH5ZAC.mjs.map +0 -1
- package/lib/chunk-VPFIIM2X.js.map +0 -1
- package/lib/chunk-YXHH5BF6.js +0 -28
- package/lib/chunk-YXHH5BF6.js.map +0 -1
- package/lib/core.d.mts +0 -1
- package/lib/core.d.ts +0 -1
- package/lib/core.js +0 -10
- package/lib/core.js.map +0 -1
- package/lib/core.mjs +0 -10
- package/lib/parseSchema.js +0 -9
- package/lib/parseSchema.js.map +0 -1
- package/lib/parseSchema.mjs +0 -9
- /package/lib/asserts/{common → mix}/equalTo.mjs.map +0 -0
- /package/lib/asserts/{common → mix}/index.mjs.map +0 -0
- /package/lib/{core.mjs.map → asserts/mix/oneOfValues.mjs.map} +0 -0
- /package/lib/{parseSchema.mjs.map → commonTypes.mjs.map} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/schemas/BooleanSchema.ts"],"sourcesContent":["import { CommonSchema } from './CommonSchema';\nimport { guardException } from '../exceptions';\nimport { ExceptionContext } from '../commonTypes';\nimport { _setStrictType } from '../helpers/setStrictType';\n\nconst isBoolean = (expected: boolean) => (received: boolean, ctx: ExceptionContext) => {\n if (received !== expected) guardException(expected, received, ctx, 'c:isBoolean');\n};\n\nexport class BooleanSchema extends CommonSchema {\n _boolean = 1;\n\n /**\n * Restricts the schema to exactly match the boolean value true and infers the true value as the TypeScript type.\n *\n * @returns - The schema instance restricted to the value true, with the true value inferred as the TypeScript type\n *\n * @example - boolean().onlyTrue(); // Infers the type true\n */\n onlyTrue(): WithBoolean<this, true> {\n _setStrictType(this, true);\n return this.custom(isBoolean(true)) as WithBoolean<this, true>;\n }\n\n /**\n * Restricts the schema to exactly match the boolean value false and infers the false value as the TypeScript type.\n *\n * @returns - The schema instance restricted to the value false, with the false value inferred as the TypeScript type\n *\n * @example - boolean().onlyFalse(); // Infers the type false\n */\n onlyFalse(): WithBoolean<this, false> {\n _setStrictType(this, false);\n return this.custom(isBoolean(false)) as WithBoolean<this, false>;\n }\n}\n\nexport type WithBoolean<T extends BooleanSchema, Y = boolean> = T & { validation_boolean: Y };\nexport type ExtractFromBoolean<T> = T extends WithBoolean<BooleanSchema, infer Y> ? Y : never;\n"],"mappings":";;;;;;;;;;;AAKA,IAAM,YAAY,CAAC,aAAsB,CAAC,UAAmB,QAA0B;AACrF,MAAI,aAAa,SAAU,gBAAe,UAAU,UAAU,KAAK,aAAa;AAClF;AAEO,IAAM,gBAAN,cAA4B,aAAa;AAAA,EAC9C,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASX,WAAoC;AAClC,mBAAe,MAAM,IAAI;AACzB,WAAO,KAAK,OAAO,UAAU,IAAI,CAAC;AAAA,EACpC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,YAAsC;AACpC,mBAAe,MAAM,KAAK;AAC1B,WAAO,KAAK,OAAO,UAAU,KAAK,CAAC;AAAA,EACrC;AACF;","names":[]}
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
|
|
3
|
+
var _chunkIRG4OQABjs = require('./chunk-IRG4OQAB.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunk5BVJ6YMHjs = require('./chunk-5BVJ6YMH.js');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var _chunkWK4O3HH4js = require('./chunk-WK4O3HH4.js');
|
|
10
|
+
|
|
11
|
+
// src/parseOrFail.ts
|
|
12
|
+
function parseOrFail(schema, receivedValue, options) {
|
|
13
|
+
try {
|
|
14
|
+
return _chunkIRG4OQABjs.innerCheck.call(void 0, schema, receivedValue, {
|
|
15
|
+
t: _chunk5BVJ6YMHjs.getTranslationByLocale.call(void 0, _optionalChain([options, 'optionalAccess', _ => _.lng])),
|
|
16
|
+
pathToError: ""
|
|
17
|
+
});
|
|
18
|
+
} catch (e) {
|
|
19
|
+
if (e instanceof _chunkWK4O3HH4js.ValidationError) throw e;
|
|
20
|
+
throw new Error("Something unexpected happened");
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
exports.parseOrFail = parseOrFail;
|
|
27
|
+
//# sourceMappingURL=chunk-DJSLA2ZV.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-DJSLA2ZV.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-DJSLA2ZV.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,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ctxSymbol
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-PH2PMUZP.mjs";
|
|
4
4
|
|
|
5
5
|
// src/schemas/CommonSchema.ts
|
|
6
6
|
var CommonSchema = class {
|
|
@@ -39,4 +39,4 @@ var CommonSchema = class {
|
|
|
39
39
|
export {
|
|
40
40
|
CommonSchema
|
|
41
41
|
};
|
|
42
|
-
//# sourceMappingURL=chunk-
|
|
42
|
+
//# sourceMappingURL=chunk-DPBE7TAQ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/schemas/CommonSchema.ts"],"sourcesContent":["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}\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"],"mappings":";;;;;AAiBO,IAAM,eAAN,MAAmB;AAAA,EACxB,CAAC,SAAS;AAAA,EACV,YAAY,KAAuB;AACjC,SAAK,SAAS,IAAI;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,UAAU,YAAwC;AAChD,SAAK,SAAS,EAAE,oBAAoB,KAAK,GAAG,UAAU;AACtD,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,WAA2B;AACzB,SAAK,SAAS,EAAE,aAAa;AAC7B,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,WAAgC;AAC9B,SAAK,SAAS,EAAE,aAAa;AAC7B,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkIRG4OQABjs = require('./chunk-IRG4OQAB.js');
|
|
4
4
|
|
|
5
5
|
// src/schemas/CommonSchema.ts
|
|
6
6
|
var CommonSchema = class {
|
|
7
7
|
|
|
8
8
|
constructor(ctx) {
|
|
9
|
-
this[
|
|
9
|
+
this[_chunkIRG4OQABjs.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[_chunkIRG4OQABjs.ctxSymbol].requiredValidations.push(...validators);
|
|
17
17
|
return this;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
@@ -22,7 +22,7 @@ var CommonSchema = class {
|
|
|
22
22
|
* @returns {WithNull<this>} The schema instance marked as nullable.
|
|
23
23
|
*/
|
|
24
24
|
nullable() {
|
|
25
|
-
this[
|
|
25
|
+
this[_chunkIRG4OQABjs.ctxSymbol].isNullable = true;
|
|
26
26
|
return this;
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
@@ -31,7 +31,7 @@ var CommonSchema = class {
|
|
|
31
31
|
* @returns {WithUndefined<this>}} The schema instance marked as optional.
|
|
32
32
|
*/
|
|
33
33
|
optional() {
|
|
34
|
-
this[
|
|
34
|
+
this[_chunkIRG4OQABjs.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-EGEHSELT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-EGEHSELT.js","../src/schemas/CommonSchema.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACA;ACaO,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;ADdA;AACA;AACE;AACF,oCAAC","file":"/home/runner/work/bguard/bguard/lib/chunk-EGEHSELT.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}\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,47 @@
|
|
|
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
|
+
|
|
3
|
+
var _chunkIRG4OQABjs = require('./chunk-IRG4OQAB.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunk5BVJ6YMHjs = require('./chunk-5BVJ6YMH.js');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var _chunkWK4O3HH4js = require('./chunk-WK4O3HH4.js');
|
|
10
|
+
|
|
11
|
+
// src/parse.ts
|
|
12
|
+
function parse(schema, receivedValue, options) {
|
|
13
|
+
try {
|
|
14
|
+
const ctx = {
|
|
15
|
+
t: _chunk5BVJ6YMHjs.getTranslationByLocale.call(void 0, _optionalChain([options, 'optionalAccess', _ => _.lng])),
|
|
16
|
+
pathToError: "",
|
|
17
|
+
getAllErrors: _optionalChain([options, 'optionalAccess', _2 => _2.getAllErrors]),
|
|
18
|
+
errors: []
|
|
19
|
+
};
|
|
20
|
+
const parsedValue = _chunkIRG4OQABjs.innerCheck.call(void 0, schema, receivedValue, ctx);
|
|
21
|
+
if (ctx.getAllErrors && ctx.errors.length) {
|
|
22
|
+
return [ctx.errors, void 0];
|
|
23
|
+
}
|
|
24
|
+
return [void 0, parsedValue];
|
|
25
|
+
} catch (e) {
|
|
26
|
+
if (e instanceof _chunkWK4O3HH4js.ValidationError) {
|
|
27
|
+
delete e.stack;
|
|
28
|
+
return [[e], void 0];
|
|
29
|
+
}
|
|
30
|
+
return [
|
|
31
|
+
[
|
|
32
|
+
{
|
|
33
|
+
message: "Something unexpected happened",
|
|
34
|
+
expected: "",
|
|
35
|
+
received: "",
|
|
36
|
+
pathToError: ""
|
|
37
|
+
}
|
|
38
|
+
],
|
|
39
|
+
void 0
|
|
40
|
+
];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
exports.parse = parse;
|
|
47
|
+
//# sourceMappingURL=chunk-H7CPKW53.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-H7CPKW53.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-H7CPKW53.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,13 +1,13 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkWBERBAL4js = require('./chunk-WBERBAL4.js');
|
|
4
4
|
|
|
5
5
|
// src/asserts/boolean/index.ts
|
|
6
6
|
function boolean() {
|
|
7
|
-
return new (0,
|
|
7
|
+
return new (0, _chunkWBERBAL4js.BooleanSchema)({ type: ["boolean"], requiredValidations: [] });
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
exports.boolean = boolean;
|
|
13
|
-
//# sourceMappingURL=chunk-
|
|
13
|
+
//# sourceMappingURL=chunk-HDSGCAHH.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-HDSGCAHH.js","../src/asserts/boolean/index.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACA;ACQO,SAAS,OAAA,CAAA,EAAyB;AACvC,EAAA,OAAO,IAAI,mCAAA,CAAc,EAAE,IAAA,EAAM,CAAC,SAAS,CAAA,EAAG,mBAAA,EAAqB,CAAC,EAAE,CAAC,CAAA;AACzE;ADNA;AACA;AACE;AACF,0BAAC","file":"/home/runner/work/bguard/bguard/lib/chunk-HDSGCAHH.js","sourcesContent":[null,"import { BooleanSchema } from '../../schemas/BooleanSchema';\n\n/**\n * Creates a new schema for validating boolean values.\n *\n * @returns {BooleanSchema} A new instance of `BooleanSchema` for validating booleans.\n *\n * @example\n * const schema = boolean();\n * parseOrFail(schema, true); // Validates successfully\n * parseOrFail(schema, 'true'); // Throws a validation error\n */\nexport function boolean(): BooleanSchema {\n return new BooleanSchema({ type: ['boolean'], requiredValidations: [] });\n}\n"]}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkRRQOET3Xjs = require('./chunk-RRQOET3X.js');
|
|
4
4
|
|
|
5
5
|
// src/asserts/array/index.ts
|
|
6
6
|
function array(arraySchema) {
|
|
7
|
-
return new (0,
|
|
7
|
+
return new (0, _chunkRRQOET3Xjs.ArraySchema)({ type: [], requiredValidations: [] }, arraySchema);
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
exports.array = array;
|
|
13
|
-
//# sourceMappingURL=chunk-
|
|
13
|
+
//# sourceMappingURL=chunk-IEUXIOL6.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-IEUXIOL6.js","../src/asserts/array/index.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACA;ACWO,SAAS,KAAA,CAA8B,WAAA,EAA8B;AAC1E,EAAA,OAAO,IAAI,iCAAA,CAAY,EAAE,IAAA,EAAM,CAAC,CAAA,EAAG,mBAAA,EAAqB,CAAC,EAAE,CAAA,EAAG,WAAW,CAAA;AAC3E;ADTA;AACA;AACE;AACF,sBAAC","file":"/home/runner/work/bguard/bguard/lib/chunk-IEUXIOL6.js","sourcesContent":[null,"import { ArraySchema, WithArray } from '../../schemas/ArraySchema';\nimport { CommonSchema } from '../../schemas/CommonSchema';\n\n/**\n * Creates a new schema for validating arrays where each element must match the specified schema.\n *\n * @template T\n * @param {T} arraySchema - The schema that each element of the array must match.\n * @returns {WithArray<T>} A new instance of `ArraySchema` for validating arrays of elements that match the specified schema.\n *\n * @example\n * const schema = array(string());\n * parseOrFail(schema, ['hello', 'world']); // Validates successfully\n * parseOrFail(schema, ['hello', 123]); // Throws a validation error\n */\nexport function array<T extends CommonSchema>(arraySchema: T): WithArray<T> {\n return new ArraySchema({ type: [], requiredValidations: [] }, arraySchema) as WithArray<T>;\n}\n"]}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkWK4O3HH4js = require('./chunk-WK4O3HH4.js');
|
|
4
|
+
|
|
5
|
+
// src/helpers/core.ts
|
|
6
|
+
var ctxSymbol = Symbol("contextSymbol");
|
|
7
|
+
function innerCheck(schema, receivedValue, exCtx) {
|
|
8
|
+
const commonTmap = exCtx.t;
|
|
9
|
+
const schemaData = schema[ctxSymbol];
|
|
10
|
+
if (receivedValue === void 0) {
|
|
11
|
+
if (!schemaData.isOptional) _chunkWK4O3HH4js.guardException.call(void 0, "Required", receivedValue, exCtx, commonTmap["c:optional"]);
|
|
12
|
+
return receivedValue;
|
|
13
|
+
}
|
|
14
|
+
if (receivedValue === null) {
|
|
15
|
+
if (!schemaData.isNullable) _chunkWK4O3HH4js.guardException.call(void 0, "Not null", receivedValue, exCtx, commonTmap["c:nullable"]);
|
|
16
|
+
return receivedValue;
|
|
17
|
+
}
|
|
18
|
+
if (schemaData.array) {
|
|
19
|
+
if (!Array.isArray(receivedValue)) return _chunkWK4O3HH4js.guardException.call(void 0, "Array", receivedValue, exCtx, commonTmap["c:array"]);
|
|
20
|
+
const schema2 = schemaData.array;
|
|
21
|
+
const pathToError = exCtx.pathToError;
|
|
22
|
+
receivedValue.forEach((elem, i) => {
|
|
23
|
+
innerCheck(schema2, elem, { ...exCtx, pathToError: `${pathToError}[${i}]` });
|
|
24
|
+
});
|
|
25
|
+
return receivedValue;
|
|
26
|
+
}
|
|
27
|
+
const typeOfVal = typeof receivedValue;
|
|
28
|
+
if (schemaData.object) {
|
|
29
|
+
if (typeOfVal !== "object") _chunkWK4O3HH4js.guardException.call(void 0, "Object", receivedValue, exCtx, commonTmap["c:objectType"]);
|
|
30
|
+
if (Array.isArray(receivedValue)) _chunkWK4O3HH4js.guardException.call(void 0, "Object", receivedValue, exCtx, commonTmap["c:objectTypeAsArray"]);
|
|
31
|
+
const shapeSchema = schemaData.object;
|
|
32
|
+
if (!schemaData.allowUnrecognizedObjectProps) {
|
|
33
|
+
for (const keyPerReceivedValue of Object.keys(receivedValue)) {
|
|
34
|
+
if (shapeSchema[keyPerReceivedValue] === void 0)
|
|
35
|
+
_chunkWK4O3HH4js.guardException.call(void 0, "Unrecognized property", keyPerReceivedValue, exCtx, commonTmap["c:unrecognizedProperty"]);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const pathToError = exCtx.pathToError;
|
|
39
|
+
for (const [keyOfSchema, valueOfSchema] of Object.entries(shapeSchema)) {
|
|
40
|
+
const receivedObjectValuePropery = receivedValue[keyOfSchema];
|
|
41
|
+
if (receivedObjectValuePropery === void 0) {
|
|
42
|
+
if (!valueOfSchema[ctxSymbol].isOptional)
|
|
43
|
+
_chunkWK4O3HH4js.guardException.call(void 0, "Required", receivedObjectValuePropery, exCtx, commonTmap["c:requiredProperty"]);
|
|
44
|
+
}
|
|
45
|
+
innerCheck(valueOfSchema, receivedObjectValuePropery, { ...exCtx, pathToError: `${pathToError}.${keyOfSchema}` });
|
|
46
|
+
}
|
|
47
|
+
return receivedValue;
|
|
48
|
+
}
|
|
49
|
+
if (schemaData.type.length) {
|
|
50
|
+
if (!schemaData.type.includes(typeOfVal))
|
|
51
|
+
_chunkWK4O3HH4js.guardException.call(void 0, schemaData.type, typeOfVal, exCtx, commonTmap["c:invalidType"]);
|
|
52
|
+
}
|
|
53
|
+
schemaData.requiredValidations.forEach((requiredValidation) => {
|
|
54
|
+
requiredValidation(receivedValue, exCtx);
|
|
55
|
+
});
|
|
56
|
+
return receivedValue;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
exports.ctxSymbol = ctxSymbol; exports.innerCheck = innerCheck;
|
|
63
|
+
//# sourceMappingURL=chunk-IRG4OQAB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-IRG4OQAB.js","../src/helpers/core.ts"],"names":["schema"],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACA;ACJO,IAAM,UAAA,EAAY,MAAA,CAAO,eAAe,CAAA;AAMxC,SAAS,UAAA,CAAW,MAAA,EAAsB,aAAA,EAAwB,KAAA,EAAyB;AAChG,EAAA,MAAM,WAAA,EAAa,KAAA,CAAM,CAAA;AACzB,EAAA,MAAM,WAAA,EAAa,MAAA,CAAO,SAAS,CAAA;AACnC,EAAA,GAAA,CAAI,cAAA,IAAkB,KAAA,CAAA,EAAW;AAC/B,IAAA,GAAA,CAAI,CAAC,UAAA,CAAW,UAAA,EAAY,6CAAA,UAAe,EAAY,aAAA,EAAe,KAAA,EAAO,UAAA,CAAW,YAAY,CAAC,CAAA;AACrG,IAAA,OAAO,aAAA;AAAA,EACT;AAEA,EAAA,GAAA,CAAI,cAAA,IAAkB,IAAA,EAAM;AAC1B,IAAA,GAAA,CAAI,CAAC,UAAA,CAAW,UAAA,EAAY,6CAAA,UAAe,EAAY,aAAA,EAAe,KAAA,EAAO,UAAA,CAAW,YAAY,CAAC,CAAA;AACrG,IAAA,OAAO,aAAA;AAAA,EACT;AAEA,EAAA,GAAA,CAAI,UAAA,CAAW,KAAA,EAAO;AACpB,IAAA,GAAA,CAAI,CAAC,KAAA,CAAM,OAAA,CAAQ,aAAa,CAAA,EAAG,OAAO,6CAAA,OAAe,EAAS,aAAA,EAAe,KAAA,EAAO,UAAA,CAAW,SAAS,CAAC,CAAA;AAC7G,IAAA,MAAMA,QAAAA,EAAS,UAAA,CAAW,KAAA;AAC1B,IAAA,MAAM,YAAA,EAAc,KAAA,CAAM,WAAA;AAC1B,IAAA,aAAA,CAAc,OAAA,CAAQ,CAAC,IAAA,EAAM,CAAA,EAAA,GAAM;AACjC,MAAA,UAAA,CAAWA,OAAAA,EAAQ,IAAA,EAAM,EAAE,GAAG,KAAA,EAAO,WAAA,EAAa,CAAA,EAAA;AACnD,IAAA;AAEM,IAAA;AACT,EAAA;AAEyB,EAAA;AAEF,EAAA;AACgC,IAAA;AACJ,IAAA;AAClB,IAAA;AAEe,IAAA;AACE,MAAA;AACH,QAAA;AACC,UAAA;AAC5C,MAAA;AACF,IAAA;AAE0B,IAAA;AACwB,IAAA;AAC8B,MAAA;AAChC,MAAA;AACd,QAAA;AACD,UAAA;AAC/B,MAAA;AAE0B,MAAA;AAC5B,IAAA;AAEO,IAAA;AACT,EAAA;AAE4B,EAAA;AACa,IAAA;AACa,MAAA;AACtD,EAAA;AAEwC,EAAA;AACC,IAAA;AACxC,EAAA;AAEM,EAAA;AACT;ADX0D;AACA;AACA;AACA;AACA","file":"/home/runner/work/bguard/bguard/lib/chunk-IRG4OQAB.js","sourcesContent":[null,"export const ctxSymbol = Symbol('contextSymbol');\n\nimport { ExceptionContext } from '../commonTypes';\nimport { guardException } from '../exceptions';\nimport type { CommonSchema } from '../schemas/CommonSchema';\n\nexport function innerCheck(schema: CommonSchema, receivedValue: unknown, exCtx: ExceptionContext) {\n const commonTmap = exCtx.t;\n const schemaData = schema[ctxSymbol];\n if (receivedValue === undefined) {\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.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 receivedValue.forEach((elem, i) => {\n innerCheck(schema, elem, { ...exCtx, pathToError: `${pathToError}[${i}]` });\n });\n\n return receivedValue;\n }\n\n const typeOfVal = typeof receivedValue;\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\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 innerCheck(valueOfSchema, receivedObjectValuePropery, { ...exCtx, pathToError: `${pathToError}.${keyOfSchema}` });\n }\n\n return receivedValue;\n }\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 return receivedValue;\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunk5BVJ6YMHjs = require('./chunk-5BVJ6YMH.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkWK4O3HH4js = require('./chunk-WK4O3HH4.js');
|
|
7
|
+
|
|
8
|
+
// src/asserts/mix/equalTo.ts
|
|
9
|
+
var equalToErrorMessage = "The received value is not equal to expected";
|
|
10
|
+
var equalToErrorKey = "m:equalTo";
|
|
11
|
+
var equalTo = (expected) => (received, ctx) => {
|
|
12
|
+
if (expected !== received) _chunkWK4O3HH4js.guardException.call(void 0, expected, received, ctx, equalToErrorKey);
|
|
13
|
+
};
|
|
14
|
+
equalTo.key = equalToErrorKey;
|
|
15
|
+
equalTo.message = equalToErrorMessage;
|
|
16
|
+
_chunk5BVJ6YMHjs.setToDefaultLocale.call(void 0, equalTo);
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
exports.equalTo = equalTo;
|
|
21
|
+
//# sourceMappingURL=chunk-J4VKFJQK.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-J4VKFJQK.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-J4VKFJQK.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 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"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ArraySchema
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-NDQM5OL4.mjs";
|
|
4
4
|
|
|
5
5
|
// src/asserts/array/index.ts
|
|
6
6
|
function array(arraySchema) {
|
|
@@ -10,4 +10,4 @@ function array(arraySchema) {
|
|
|
10
10
|
export {
|
|
11
11
|
array
|
|
12
12
|
};
|
|
13
|
-
//# sourceMappingURL=chunk-
|
|
13
|
+
//# sourceMappingURL=chunk-JDGZCBXF.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/asserts/array/index.ts"],"sourcesContent":["import { ArraySchema, WithArray } from '../../schemas/ArraySchema';\nimport { CommonSchema } from '../../schemas/CommonSchema';\n\n/**\n * Creates a new schema for validating arrays where each element must match the specified schema.\n *\n * @template T\n * @param {T} arraySchema - The schema that each element of the array must match.\n * @returns {WithArray<T>} A new instance of `ArraySchema` for validating arrays of elements that match the specified schema.\n *\n * @example\n * const schema = array(string());\n *
|
|
1
|
+
{"version":3,"sources":["../src/asserts/array/index.ts"],"sourcesContent":["import { ArraySchema, WithArray } from '../../schemas/ArraySchema';\nimport { CommonSchema } from '../../schemas/CommonSchema';\n\n/**\n * Creates a new schema for validating arrays where each element must match the specified schema.\n *\n * @template T\n * @param {T} arraySchema - The schema that each element of the array must match.\n * @returns {WithArray<T>} A new instance of `ArraySchema` for validating arrays of elements that match the specified schema.\n *\n * @example\n * const schema = array(string());\n * parseOrFail(schema, ['hello', 'world']); // Validates successfully\n * parseOrFail(schema, ['hello', 123]); // Throws a validation error\n */\nexport function array<T extends CommonSchema>(arraySchema: T): WithArray<T> {\n return new ArraySchema({ type: [], requiredValidations: [] }, arraySchema) as WithArray<T>;\n}\n"],"mappings":";;;;;AAeO,SAAS,MAA8B,aAA8B;AAC1E,SAAO,IAAI,YAAY,EAAE,MAAM,CAAC,GAAG,qBAAqB,CAAC,EAAE,GAAG,WAAW;AAC3E;","names":[]}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {
|
|
2
|
+
equalTo
|
|
3
|
+
} from "./chunk-NNFYXHLU.mjs";
|
|
4
|
+
import {
|
|
5
|
+
oneOfValues
|
|
6
|
+
} from "./chunk-3O4WCRC2.mjs";
|
|
7
|
+
import {
|
|
8
|
+
ONLY_ONCE
|
|
9
|
+
} from "./chunk-ASZW6XRM.mjs";
|
|
10
|
+
import {
|
|
11
|
+
_setStrictType
|
|
12
|
+
} from "./chunk-RYVUYVEE.mjs";
|
|
13
|
+
import {
|
|
14
|
+
CommonSchema
|
|
15
|
+
} from "./chunk-DPBE7TAQ.mjs";
|
|
16
|
+
import {
|
|
17
|
+
BuildSchemaError
|
|
18
|
+
} from "./chunk-7XFLH6R2.mjs";
|
|
19
|
+
|
|
20
|
+
// src/schemas/StringSchema.ts
|
|
21
|
+
var StringSchema = class extends CommonSchema {
|
|
22
|
+
_string = 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 - string().equalTo('hello'); // Infers the type 'hello'
|
|
31
|
+
*/
|
|
32
|
+
equalTo(expectedValue) {
|
|
33
|
+
if (this.limit) throw new BuildSchemaError(ONLY_ONCE);
|
|
34
|
+
this.limit = true;
|
|
35
|
+
_setStrictType(this, `'${expectedValue}'`);
|
|
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
|
+
* string().oneOfValues(['foo', 'bar']); // Infers the type 'foo' | 'bar'
|
|
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}'`)
|
|
53
|
+
);
|
|
54
|
+
return this.custom(oneOfValues(expectedValue));
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export {
|
|
59
|
+
StringSchema
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=chunk-JPRCULRQ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/schemas/StringSchema.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 StringSchema extends CommonSchema {\n _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 equalTo<Y extends string>(expectedValue: Y): WithString<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 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 oneOfValues<Y extends string>(expectedValue: Y[]): WithString<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 return this.custom(oneOfValues(expectedValue)) as WithString<this, Y>;\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"],"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,IAAI,aAAa,GAAG;AAEzC,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,IAAI,EAAE,GAAG;AAAA,IACrC;AACA,WAAO,KAAK,OAAO,YAAY,aAAa,CAAC;AAAA,EAC/C;AACF;","names":[]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkIRG4OQABjs = require('./chunk-IRG4OQAB.js');
|
|
4
|
+
|
|
5
|
+
// src/helpers/setStrictType.ts
|
|
6
|
+
function _setStrictType(that, val) {
|
|
7
|
+
that[_chunkIRG4OQABjs.ctxSymbol].strictType = true;
|
|
8
|
+
that[_chunkIRG4OQABjs.ctxSymbol].strictTypeValue = val;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
exports._setStrictType = _setStrictType;
|
|
14
|
+
//# sourceMappingURL=chunk-JSGZ7DKT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-JSGZ7DKT.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-JSGZ7DKT.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"]}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _class;
|
|
2
|
+
|
|
3
|
+
var _chunkJ4VKFJQKjs = require('./chunk-J4VKFJQK.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunk4CYIMDP2js = require('./chunk-4CYIMDP2.js');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var _chunk42J6CHIOjs = require('./chunk-42J6CHIO.js');
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var _chunkJSGZ7DKTjs = require('./chunk-JSGZ7DKT.js');
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
var _chunkEGEHSELTjs = require('./chunk-EGEHSELT.js');
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
var _chunkWK4O3HH4js = require('./chunk-WK4O3HH4.js');
|
|
19
|
+
|
|
20
|
+
// src/schemas/NumberSchema.ts
|
|
21
|
+
var NumberSchema = (_class = class extends _chunkEGEHSELTjs.CommonSchema {constructor(...args) { super(...args); _class.prototype.__init.call(this); }
|
|
22
|
+
__init() {this._number = 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 - number().equalTo(42); // Infers the type 42
|
|
31
|
+
*/
|
|
32
|
+
equalTo(expectedValue) {
|
|
33
|
+
if (this.limit) throw new (0, _chunkWK4O3HH4js.BuildSchemaError)(_chunk42J6CHIOjs.ONLY_ONCE);
|
|
34
|
+
this.limit = true;
|
|
35
|
+
_chunkJSGZ7DKTjs._setStrictType.call(void 0, this, expectedValue);
|
|
36
|
+
return this.custom(_chunkJ4VKFJQKjs.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
|
+
* number().oneOfValues([5, 7]); // Infers the type 5 | 7
|
|
46
|
+
*/
|
|
47
|
+
oneOfValues(expectedValue) {
|
|
48
|
+
if (this.limit) throw new (0, _chunkWK4O3HH4js.BuildSchemaError)(_chunk42J6CHIOjs.ONLY_ONCE);
|
|
49
|
+
this.limit = true;
|
|
50
|
+
_chunkJSGZ7DKTjs._setStrictType.call(void 0, this, expectedValue);
|
|
51
|
+
return this.custom(_chunk4CYIMDP2js.oneOfValues.call(void 0, expectedValue));
|
|
52
|
+
}
|
|
53
|
+
}, _class);
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
exports.NumberSchema = NumberSchema;
|
|
58
|
+
//# sourceMappingURL=chunk-KQKJASVB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-KQKJASVB.js","../src/schemas/NumberSchema.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,aAAa,CAAA;AAClC,IAAA,OAAO,IAAA,CAAK,MAAA,CAAO,sCAAA,aAAqB,CAAC,CAAA;AAAA,EAC3C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,WAAA,CAA8B,aAAA,EAAyC;AACrE,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,aAAa,CAAA;AAClC,IAAA,OAAO,IAAA,CAAK,MAAA,CAAO,0CAAA,aAAyB,CAAC,CAAA;AAAA,EAC/C;AACF,UAAA;ADYA;AACA;AACE;AACF,oCAAC","file":"/home/runner/work/bguard/bguard/lib/chunk-KQKJASVB.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 NumberSchema extends CommonSchema {\n _number = 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 - number().equalTo(42); // Infers the type 42\n */\n equalTo<Y extends number>(expectedValue: Y): WithNumber<this, Y> {\n if (this.limit) throw new BuildSchemaError(ONLY_ONCE);\n this.limit = true;\n _setStrictType(this, expectedValue);\n return this.custom(equalTo(expectedValue)) as WithNumber<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 * number().oneOfValues([5, 7]); // Infers the type 5 | 7\n */\n oneOfValues<Y extends number>(expectedValue: Y[]): WithNumber<this, Y> {\n if (this.limit) throw new BuildSchemaError(ONLY_ONCE);\n this.limit = true;\n _setStrictType(this, expectedValue);\n return this.custom(oneOfValues(expectedValue)) as WithNumber<this, Y>;\n }\n}\n\nexport type WithNumber<T extends NumberSchema, Y = number> = T & { validation_number: Y };\nexport type ExtractFromNumber<T> = T extends WithNumber<NumberSchema, infer Y> ? Y : never;\n"]}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _class;
|
|
2
|
+
|
|
3
|
+
var _chunkJ4VKFJQKjs = require('./chunk-J4VKFJQK.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunk4CYIMDP2js = require('./chunk-4CYIMDP2.js');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var _chunk42J6CHIOjs = require('./chunk-42J6CHIO.js');
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var _chunkJSGZ7DKTjs = require('./chunk-JSGZ7DKT.js');
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
var _chunkEGEHSELTjs = require('./chunk-EGEHSELT.js');
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
var _chunkWK4O3HH4js = require('./chunk-WK4O3HH4.js');
|
|
19
|
+
|
|
20
|
+
// src/schemas/StringSchema.ts
|
|
21
|
+
var StringSchema = (_class = class extends _chunkEGEHSELTjs.CommonSchema {constructor(...args) { super(...args); _class.prototype.__init.call(this); }
|
|
22
|
+
__init() {this._string = 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 - string().equalTo('hello'); // Infers the type 'hello'
|
|
31
|
+
*/
|
|
32
|
+
equalTo(expectedValue) {
|
|
33
|
+
if (this.limit) throw new (0, _chunkWK4O3HH4js.BuildSchemaError)(_chunk42J6CHIOjs.ONLY_ONCE);
|
|
34
|
+
this.limit = true;
|
|
35
|
+
_chunkJSGZ7DKTjs._setStrictType.call(void 0, this, `'${expectedValue}'`);
|
|
36
|
+
return this.custom(_chunkJ4VKFJQKjs.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
|
+
* string().oneOfValues(['foo', 'bar']); // Infers the type 'foo' | 'bar'
|
|
46
|
+
*/
|
|
47
|
+
oneOfValues(expectedValue) {
|
|
48
|
+
if (this.limit) throw new (0, _chunkWK4O3HH4js.BuildSchemaError)(_chunk42J6CHIOjs.ONLY_ONCE);
|
|
49
|
+
this.limit = true;
|
|
50
|
+
_chunkJSGZ7DKTjs._setStrictType.call(void 0,
|
|
51
|
+
this,
|
|
52
|
+
expectedValue.map((el) => `'${el}'`)
|
|
53
|
+
);
|
|
54
|
+
return this.custom(_chunk4CYIMDP2js.oneOfValues.call(void 0, expectedValue));
|
|
55
|
+
}
|
|
56
|
+
}, _class);
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
exports.StringSchema = StringSchema;
|
|
61
|
+
//# sourceMappingURL=chunk-LEQCDD66.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-LEQCDD66.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,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,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,EAWA,WAAA,CAA8B,aAAA,EAAyC;AACrE,IAAA,GAAA,CAAI,IAAA,CAAK,KAAA,EAAO,MAAM,IAAI,sCAAA,CAAiB,0BAAS,CAAA;AACpD,IAAA,IAAA,CAAK,MAAA,EAAQ,IAAA;AACb,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;AACF,UAAA;ADWA;AACA;AACE;AACF,oCAAC","file":"/home/runner/work/bguard/bguard/lib/chunk-LEQCDD66.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 _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 equalTo<Y extends string>(expectedValue: Y): WithString<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 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 oneOfValues<Y extends string>(expectedValue: Y[]): WithString<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 return this.custom(oneOfValues(expectedValue)) as WithString<this, Y>;\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"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CommonSchema
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-DPBE7TAQ.mjs";
|
|
4
4
|
|
|
5
|
-
// src/asserts/
|
|
5
|
+
// src/asserts/mix/index.ts
|
|
6
6
|
function oneOfTypes(valueTypes) {
|
|
7
7
|
return new CommonSchema({ type: valueTypes, requiredValidations: [] });
|
|
8
8
|
}
|
|
@@ -10,4 +10,4 @@ function oneOfTypes(valueTypes) {
|
|
|
10
10
|
export {
|
|
11
11
|
oneOfTypes
|
|
12
12
|
};
|
|
13
|
-
//# sourceMappingURL=chunk-
|
|
13
|
+
//# sourceMappingURL=chunk-MRISXZQ4.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/asserts/mix/index.ts"],"sourcesContent":["import { PrimitiveType } from '../../commonTypes';\nimport { CommonSchema, MapMixTypes, WithMix } from '../../schemas/CommonSchema';\n\n/**\n * Creates a new schema for validating values that can match any one of the specified primitive types.\n *\n * @template T\n * @param {T} valueTypes - An array of primitive types that the value can match.\n * @returns {WithMix<MapMixTypes<T>>} A new schema for validating values that can match any of the specified types.\n *\n * @example\n * const schema = oneOfTypes(['string', 'number']);\n * parseOrFail(schema, 'hello'); // Validates successfully\n * parseOrFail(schema, 42); // Validates successfully\n * parseOrFail(schema, true); // Throws a validation error\n */\nexport function oneOfTypes<T extends PrimitiveType[]>(valueTypes: T): WithMix<MapMixTypes<T>> {\n return new CommonSchema({ type: valueTypes, requiredValidations: [] }) as WithMix<MapMixTypes<T>>;\n}\n"],"mappings":";;;;;AAgBO,SAAS,WAAsC,YAAwC;AAC5F,SAAO,IAAI,aAAa,EAAE,MAAM,YAAY,qBAAqB,CAAC,EAAE,CAAC;AACvE;","names":[]}
|