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
package/README.md
CHANGED
|
@@ -30,7 +30,12 @@ Let's define a schema for a Student object:
|
|
|
30
30
|
|
|
31
31
|
```typeScript
|
|
32
32
|
|
|
33
|
-
import { InferType
|
|
33
|
+
import { InferType } from 'bguard';
|
|
34
|
+
import { object } from 'bguard/object';
|
|
35
|
+
import { array } from 'bguard/array';
|
|
36
|
+
import { number } from 'bguard/number';
|
|
37
|
+
import { string } from 'bguard/string';
|
|
38
|
+
import { boolean } from 'bguard/boolean';
|
|
34
39
|
import { email } from 'bguard/string/email';
|
|
35
40
|
import { min } from 'bguard/number/min';
|
|
36
41
|
import { max } from 'bguard/number/max';
|
|
@@ -399,6 +404,7 @@ We have two sets of translations: common errors and specific assertions.
|
|
|
399
404
|
'c:requiredProperty': 'Missing required property in the object',
|
|
400
405
|
'c:invalidType': 'Invalid type of data',
|
|
401
406
|
'c:isBoolean': 'The received value is not {{e}}',
|
|
407
|
+
'c:date': 'The received value is not a valid instance of Date',
|
|
402
408
|
```
|
|
403
409
|
|
|
404
410
|
<b>Custom Assertion Translations</b>:
|
|
@@ -418,6 +424,7 @@ Keys are constructed as `'{typeId}:{functionName}'`, where `typeId` represents:
|
|
|
418
424
|
- f - function
|
|
419
425
|
- bi - bigint
|
|
420
426
|
- m - mixed
|
|
427
|
+
- dt - date
|
|
421
428
|
|
|
422
429
|
Each `typeId` maps to the folder from which custom assertions are retrieved (except 'common', as explained above).
|
|
423
430
|
|
|
@@ -444,9 +451,176 @@ console.log(maxLength.message); // Output: 'The received value length is greater
|
|
|
444
451
|
|
|
445
452
|
<b>3.</b> IDE Support:
|
|
446
453
|
Each key and message will be visible in text editors that support JSDoc IntelliSense.
|
|
454
|
+
|
|
447
455
|
### Built-in Custom Assert Documentation {#builtin_custom_assert_documentation}
|
|
448
456
|
|
|
457
|
+
#### bigint
|
|
458
|
+
|
|
459
|
+
<b>Prerequisites</b>
|
|
460
|
+
|
|
461
|
+
```typescript
|
|
462
|
+
import { bigint } from 'bguard/bigint';
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
* _Description_ Creates a new schema for validating bigint values.
|
|
466
|
+
* _Example_
|
|
467
|
+
```typescript
|
|
468
|
+
const schema = bigint();
|
|
469
|
+
parseOrFail(schema, 42n); // Validates successfully
|
|
470
|
+
parseOrFail(schema, 42); // Throws a validation error
|
|
471
|
+
parseOrFail(schema, '42'); // Throws a validation error
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
##### bigintMax (bigint)
|
|
476
|
+
|
|
477
|
+
```typescript
|
|
478
|
+
import { bigintMax } from 'bguard/bigint/bigintMax';
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
* _Description_ Asserts that a bigint value does not exceed a specified maximum value.
|
|
482
|
+
* _Param_ {bigint} expected The maximum allowable value.
|
|
483
|
+
* _Throws_ {ValidationError} if the received value exceeds the expected maximum value.
|
|
484
|
+
* _Example_
|
|
485
|
+
```typescript
|
|
486
|
+
const schema = bigint().custom(bigintMax(100n));
|
|
487
|
+
parseOrFail(schema, 99n); // Valid
|
|
488
|
+
parseOrFail(schema, 100n); // Valid
|
|
489
|
+
parseOrFail(schema, 101n); // Throws an error: 'The received value is greater than expected'
|
|
490
|
+
```
|
|
491
|
+
* _See_ Error Translation Key = 'bi:max'
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
##### bigintMaxExcluded (bigint)
|
|
495
|
+
|
|
496
|
+
```typescript
|
|
497
|
+
import { bigintMaxExcluded } from 'bguard/bigint/bigintMaxExcluded';
|
|
498
|
+
```
|
|
499
|
+
|
|
500
|
+
* _Description_ - Asserts that a bigint value is strictly less than a specified maximum value (i.e., the maximum value is excluded).
|
|
501
|
+
* _Param_ {bigint} expected - The maximum allowable value, which is excluded.
|
|
502
|
+
* _Throws_ {ValidationError} if the received value is greater than or equal to the expected maximum value.
|
|
503
|
+
* _Example_
|
|
504
|
+
```typescript
|
|
505
|
+
const schema = bigint().custom(bigintMaxExcluded(100n));
|
|
506
|
+
parseOrFail(schema, 99n); // Valid
|
|
507
|
+
parseOrFail(schema, 100n); // Throws an error: 'The received value is greater than or equal to expected'
|
|
508
|
+
parseOrFail(schema, 101n); // Throws an error: 'The received value is greater than or equal to expected'
|
|
509
|
+
```
|
|
510
|
+
* _See_ Error Translation Key = 'bi:maxExcluded'
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
##### bigintMin (bigint)
|
|
514
|
+
|
|
515
|
+
```typescript
|
|
516
|
+
import { bigintMin } from 'bguard/bigint/bigintMin';
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
* _Description_ Asserts that a bigint value is not less than a specified minimum value.
|
|
520
|
+
* _Param_ {bigint} expected The minimum allowable value.
|
|
521
|
+
* _Throws_ {ValidationError} if the received value is less than the expected minimum value.
|
|
522
|
+
* _Example_
|
|
523
|
+
```typescript
|
|
524
|
+
const schema = bigint().custom(bigintMin(10n));
|
|
525
|
+
parseOrFail(schema, 11n); // Valid
|
|
526
|
+
parseOrFail(schema, 10n); // Valid
|
|
527
|
+
parseOrFail(schema, 9n); // Throws an error: 'The received value is less than expected'
|
|
528
|
+
```
|
|
529
|
+
* _See_ Error Translation Key = 'bi:min'
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
##### bigintMinExcluded (bigint)
|
|
533
|
+
|
|
534
|
+
```typescript
|
|
535
|
+
import { bigintMinExcluded } from 'bguard/bigint/bigintMinExcluded';
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
* _Description_ Asserts that a bigint value is strictly greater than a specified minimum value (i.e., the minimum value is excluded).
|
|
539
|
+
* _Param_ {bigint} expected The minimum allowable value, which is excluded.
|
|
540
|
+
* _Throws_ {ValidationError} if the received value is less than or equal to the expected minimum value.
|
|
541
|
+
* _Example_
|
|
542
|
+
```typescript
|
|
543
|
+
const schema = bigint().custom(bigintMinExcluded(10n));
|
|
544
|
+
parseOrFail(schema, 11n); // Valid
|
|
545
|
+
parseOrFail(schema, 10n); // Throws an error: 'The received value is less than or equal to expected'
|
|
546
|
+
parseOrFail(schema, 9n); // Throws an error: 'The received value is less than or equal to expected'
|
|
547
|
+
```
|
|
548
|
+
* _See_ Error Translation Key = 'bi:minExcluded'
|
|
549
|
+
|
|
550
|
+
#### date
|
|
551
|
+
|
|
552
|
+
<b>Prerequisites</b>
|
|
553
|
+
|
|
554
|
+
```typescript
|
|
555
|
+
import { date } from 'bguard/date';
|
|
556
|
+
```
|
|
557
|
+
|
|
558
|
+
* _Description_ Creates a new schema for validating date values.
|
|
559
|
+
* _Example_
|
|
560
|
+
```typescript
|
|
561
|
+
const schema = date();
|
|
562
|
+
parseOrFail(schema, true); // Validates successfully
|
|
563
|
+
parseOrFail(schema, 'true'); // Throws a validation error
|
|
564
|
+
```
|
|
565
|
+
|
|
566
|
+
|
|
567
|
+
##### dateMax (date)
|
|
568
|
+
|
|
569
|
+
```typescript
|
|
570
|
+
import { dateMax } from 'bguard/date/dateMax';
|
|
571
|
+
```
|
|
572
|
+
|
|
573
|
+
* _Description_ Asserts that a date value is not greater than a specified maximum value.
|
|
574
|
+
* _Param_ {Date | string} expected The maximum allowable value.
|
|
575
|
+
* _Throws_ {ValidationError} if the received value is greater than the expected maximum value.
|
|
576
|
+
* _Example_
|
|
577
|
+
```typescript
|
|
578
|
+
const schema = date().custom(dateMax('2024-12-31'));
|
|
579
|
+
parseOrFail(schema, new Date('2024-12-30')); // Valid
|
|
580
|
+
parseOrFail(schema, new Date('2024-12-31')); // Valid
|
|
581
|
+
parseOrFail(schema, new Date('2025-01-01')); // Throws an error: 'The received value is greater than expected'
|
|
582
|
+
```
|
|
583
|
+
* _See_ Error Translation Key = 'dt:max'
|
|
584
|
+
|
|
585
|
+
|
|
586
|
+
##### dateMin (date)
|
|
587
|
+
|
|
588
|
+
```typescript
|
|
589
|
+
import { dateMin } from 'bguard/date/dateMin';
|
|
590
|
+
```
|
|
591
|
+
|
|
592
|
+
* _Description_ Asserts that a number value is not less than a specified minimum value.
|
|
593
|
+
* _Param_ {Date | string} expected The minimum allowable value.
|
|
594
|
+
* _Throws_ {ValidationError} if the received value is less than the expected minimum value.
|
|
595
|
+
* _Example_
|
|
596
|
+
```typescript
|
|
597
|
+
const schema = date().custom(dateMin('2023-01-01'));
|
|
598
|
+
parseOrFail(schema, new Date('2023-01-02')); // Valid
|
|
599
|
+
parseOrFail(schema, new Date('2023-01-01')); // Valid
|
|
600
|
+
parseOrFail(schema, new Date('2022-12-31')); // Throws an error: 'The received value is less than expected'
|
|
601
|
+
```
|
|
602
|
+
* _See_ Error Translation Key = 'dt:min'
|
|
603
|
+
|
|
449
604
|
#### mix
|
|
605
|
+
|
|
606
|
+
<b>Prerequisites</b>
|
|
607
|
+
|
|
608
|
+
```typescript
|
|
609
|
+
import { oneOfTypes } from 'bguard/mix';
|
|
610
|
+
```
|
|
611
|
+
|
|
612
|
+
* _Description_ Creates a new schema for validating values that can match any one of the specified primitive types.
|
|
613
|
+
|
|
614
|
+
|
|
615
|
+
* _Param_ {T} valueTypes - An array of primitive types that the value can match.
|
|
616
|
+
* _Example_
|
|
617
|
+
```typescript
|
|
618
|
+
const schema = oneOfTypes(['string', 'number']);
|
|
619
|
+
parseOrFail(schema, 'hello'); // Validates successfully
|
|
620
|
+
parseOrFail(schema, 42); // Validates successfully
|
|
621
|
+
parseOrFail(schema, true); // Throws a validation error
|
|
622
|
+
```
|
|
623
|
+
|
|
450
624
|
|
|
451
625
|
##### equalTo (mix)
|
|
452
626
|
|
|
@@ -455,7 +629,7 @@ import { equalTo } from 'bguard/mix/equalTo';
|
|
|
455
629
|
```
|
|
456
630
|
|
|
457
631
|
* _Description_ Creates a custom assertion that checks if a value is equal to the expected value.
|
|
458
|
-
* > **Notice:** It has already been implemented in the number and string schema. There is no need to use it as a custom assert.
|
|
632
|
+
* > **Notice:** It has already been implemented in the number, bigint and string schema. There is no need to use it as a custom assert.
|
|
459
633
|
* _Param_ {unknown} expected The value that the received value is expected to match.
|
|
460
634
|
* _Throws_ {ValidationError} If the received value does not match the expected value.
|
|
461
635
|
* _Example_
|
|
@@ -474,7 +648,7 @@ import { oneOfValues } from 'bguard/mix/oneOfValues';
|
|
|
474
648
|
```
|
|
475
649
|
|
|
476
650
|
* _Description_ Creates a custom assertion that checks if a value is equal to the one of expected values.
|
|
477
|
-
* > **Notice:** It has already been implemented in the number and string schema. There is no need to use it as a custom assert.
|
|
651
|
+
* > **Notice:** It has already been implemented in the number, bigint and string schema. There is no need to use it as a custom assert.
|
|
478
652
|
* _Param_ {unknown} expected The value that the received value is expected to match.
|
|
479
653
|
* _Throws_ {ValidationError} If the received value does not match at least one of the expected values.
|
|
480
654
|
* _Example_
|
|
@@ -487,6 +661,21 @@ import { oneOfValues } from 'bguard/mix/oneOfValues';
|
|
|
487
661
|
* _See_ Error Translation Key = 'm:oneOfValues'
|
|
488
662
|
|
|
489
663
|
#### number
|
|
664
|
+
|
|
665
|
+
<b>Prerequisites</b>
|
|
666
|
+
|
|
667
|
+
```typescript
|
|
668
|
+
import { number } from 'bguard/number';
|
|
669
|
+
```
|
|
670
|
+
|
|
671
|
+
* _Description_ Creates a new schema for validating number values.
|
|
672
|
+
* _Example_
|
|
673
|
+
```typescript
|
|
674
|
+
const schema = number();
|
|
675
|
+
parseOrFail(schema, 42); // Validates successfully
|
|
676
|
+
parseOrFail(schema, '42'); // Throws a validation error
|
|
677
|
+
```
|
|
678
|
+
|
|
490
679
|
|
|
491
680
|
##### max (number)
|
|
492
681
|
|
|
@@ -600,6 +789,21 @@ import { positive } from 'bguard/number/positive';
|
|
|
600
789
|
* _See_ Error Translation Key = 'n:positive'
|
|
601
790
|
|
|
602
791
|
#### string
|
|
792
|
+
|
|
793
|
+
<b>Prerequisites</b>
|
|
794
|
+
|
|
795
|
+
```typescript
|
|
796
|
+
import { string } from 'bguard/string';
|
|
797
|
+
```
|
|
798
|
+
|
|
799
|
+
* _Description_ Creates a new schema for validating string values.
|
|
800
|
+
* _Example_
|
|
801
|
+
```typescript
|
|
802
|
+
const schema = string();
|
|
803
|
+
parseOrFail(schema, 'hello'); // Validates successfully
|
|
804
|
+
parseOrFail(schema, 123); // Throws a validation error
|
|
805
|
+
```
|
|
806
|
+
|
|
603
807
|
|
|
604
808
|
##### atLeastOneDigit (string)
|
|
605
809
|
|
|
@@ -963,4 +1167,4 @@ import { validUrl } from 'bguard/string/validUrl';
|
|
|
963
1167
|
* _See_ Error Translation Key = 's:url'
|
|
964
1168
|
|
|
965
1169
|
### Contributing
|
|
966
|
-
Contributions are welcome! Please open an issue or submit a pull request for any bugs or feature requests.
|
|
1170
|
+
Contributions are welcome! Please open an issue or submit a pull request for any bugs or feature requests.
|
|
@@ -15,6 +15,7 @@ interface ValidatorContext {
|
|
|
15
15
|
allowUnrecognizedObjectProps?: boolean;
|
|
16
16
|
strictType?: boolean;
|
|
17
17
|
strictTypeValue?: unknown;
|
|
18
|
+
date?: boolean;
|
|
18
19
|
}
|
|
19
20
|
declare class CommonSchema {
|
|
20
21
|
[ctxSymbol]: ValidatorContext;
|
|
@@ -33,7 +34,7 @@ declare class CommonSchema {
|
|
|
33
34
|
/**
|
|
34
35
|
* Marks the schema as optional, allowing the value to be `undefined`.
|
|
35
36
|
*
|
|
36
|
-
* @returns {WithUndefined<this>}
|
|
37
|
+
* @returns {WithUndefined<this>} The schema instance marked as optional.
|
|
37
38
|
*/
|
|
38
39
|
optional(): WithUndefined<this>;
|
|
39
40
|
}
|
|
@@ -59,4 +60,4 @@ type WithMix<Y = unknown> = CommonSchema & {
|
|
|
59
60
|
type ExtractFromMix<T> = T extends WithMix<infer X> ? X : never;
|
|
60
61
|
type MapMixTypes<T extends PrimitiveType[]> = T extends (infer U)[] ? U extends keyof TypeMapping ? TypeMapping[U] : never : never;
|
|
61
62
|
|
|
62
|
-
export { CommonSchema as C, type ExtractFromMix as E, type MapMixTypes as M, type ObjectShapeSchemaType as O, type ValidatorContext as V, type
|
|
63
|
+
export { CommonSchema as C, type ExtractFromMix as E, type MapMixTypes as M, type ObjectShapeSchemaType as O, type ValidatorContext as V, type WithMix as W, type WithUndefined as a, type WithNull as b, ctxSymbol as c, innerCheck as i };
|
|
@@ -15,6 +15,7 @@ interface ValidatorContext {
|
|
|
15
15
|
allowUnrecognizedObjectProps?: boolean;
|
|
16
16
|
strictType?: boolean;
|
|
17
17
|
strictTypeValue?: unknown;
|
|
18
|
+
date?: boolean;
|
|
18
19
|
}
|
|
19
20
|
declare class CommonSchema {
|
|
20
21
|
[ctxSymbol]: ValidatorContext;
|
|
@@ -33,7 +34,7 @@ declare class CommonSchema {
|
|
|
33
34
|
/**
|
|
34
35
|
* Marks the schema as optional, allowing the value to be `undefined`.
|
|
35
36
|
*
|
|
36
|
-
* @returns {WithUndefined<this>}
|
|
37
|
+
* @returns {WithUndefined<this>} The schema instance marked as optional.
|
|
37
38
|
*/
|
|
38
39
|
optional(): WithUndefined<this>;
|
|
39
40
|
}
|
|
@@ -59,4 +60,4 @@ type WithMix<Y = unknown> = CommonSchema & {
|
|
|
59
60
|
type ExtractFromMix<T> = T extends WithMix<infer X> ? X : never;
|
|
60
61
|
type MapMixTypes<T extends PrimitiveType[]> = T extends (infer U)[] ? U extends keyof TypeMapping ? TypeMapping[U] : never : never;
|
|
61
62
|
|
|
62
|
-
export { CommonSchema as C, type ExtractFromMix as E, type MapMixTypes as M, type ObjectShapeSchemaType as O, type ValidatorContext as V, type
|
|
63
|
+
export { CommonSchema as C, type ExtractFromMix as E, type MapMixTypes as M, type ObjectShapeSchemaType as O, type ValidatorContext as V, type WithMix as W, type WithUndefined as a, type WithNull as b, ctxSymbol as c, innerCheck as i };
|
package/lib/InferType.d.mts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { ArraySchema, ExtractFromArray } from './schemas/ArraySchema.mjs';
|
|
2
|
+
import { WithBigInt, BigIntSchema, ExtractFromBigInt } from './schemas/BigIntSchema.mjs';
|
|
2
3
|
import { WithBoolean, BooleanSchema, ExtractFromBoolean } from './schemas/BooleanSchema.mjs';
|
|
3
|
-
import { W as
|
|
4
|
+
import { W as WithMix, E as ExtractFromMix, a as WithUndefined, C as CommonSchema, b as WithNull } from './CommonSchema-DJmQ3F_9.mjs';
|
|
5
|
+
import { DateSchema } from './schemas/DateSchema.mjs';
|
|
4
6
|
import { WithNumber, NumberSchema, ExtractFromNumber } from './schemas/NumberSchema.mjs';
|
|
5
7
|
import { ObjectSchema, WithObject } from './schemas/ObjectSchema.mjs';
|
|
6
8
|
import { WithString, StringSchema, ExtractFromString } from './schemas/StringSchema.mjs';
|
|
7
9
|
import './commonTypes.mjs';
|
|
8
10
|
|
|
9
|
-
type
|
|
11
|
+
type ResolveNullish<T, Y> = T extends WithUndefined<WithNull<CommonSchema>> ? Y | null | undefined : T extends WithUndefined<CommonSchema> ? Y | undefined : T extends WithNull<CommonSchema> ? Y | null : Y;
|
|
12
|
+
type InferType<T> = T extends WithString<StringSchema> ? ResolveNullish<T, ExtractFromString<T>> : T extends StringSchema ? ResolveNullish<T, string> : T extends WithNumber<NumberSchema> ? ResolveNullish<T, ExtractFromNumber<T>> : T extends NumberSchema ? ResolveNullish<T, number> : T extends WithBoolean<BooleanSchema> ? ResolveNullish<T, ExtractFromBoolean<T>> : T extends BooleanSchema ? ResolveNullish<T, boolean> : T extends ArraySchema ? ResolveNullish<T, InferType<ExtractFromArray<T>>[]> : T extends ObjectSchema ? ResolveNullish<T, ExtractFromObject<T>> : T extends WithMix ? ResolveNullish<T, ExtractFromMix<T>> : T extends WithBigInt<BigIntSchema> ? ResolveNullish<T, ExtractFromBigInt<T>> : T extends BigIntSchema ? ResolveNullish<T, bigint> : T extends DateSchema ? ResolveNullish<T, Date> : unknown;
|
|
10
13
|
type Merge<T> = T extends infer U ? {
|
|
11
14
|
[K in keyof U]: U[K];
|
|
12
15
|
} : never;
|
package/lib/InferType.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { ArraySchema, ExtractFromArray } from './schemas/ArraySchema.js';
|
|
2
|
+
import { WithBigInt, BigIntSchema, ExtractFromBigInt } from './schemas/BigIntSchema.js';
|
|
2
3
|
import { WithBoolean, BooleanSchema, ExtractFromBoolean } from './schemas/BooleanSchema.js';
|
|
3
|
-
import { W as
|
|
4
|
+
import { W as WithMix, E as ExtractFromMix, a as WithUndefined, C as CommonSchema, b as WithNull } from './CommonSchema-9RtxTxdX.js';
|
|
5
|
+
import { DateSchema } from './schemas/DateSchema.js';
|
|
4
6
|
import { WithNumber, NumberSchema, ExtractFromNumber } from './schemas/NumberSchema.js';
|
|
5
7
|
import { ObjectSchema, WithObject } from './schemas/ObjectSchema.js';
|
|
6
8
|
import { WithString, StringSchema, ExtractFromString } from './schemas/StringSchema.js';
|
|
7
9
|
import './commonTypes.js';
|
|
8
10
|
|
|
9
|
-
type
|
|
11
|
+
type ResolveNullish<T, Y> = T extends WithUndefined<WithNull<CommonSchema>> ? Y | null | undefined : T extends WithUndefined<CommonSchema> ? Y | undefined : T extends WithNull<CommonSchema> ? Y | null : Y;
|
|
12
|
+
type InferType<T> = T extends WithString<StringSchema> ? ResolveNullish<T, ExtractFromString<T>> : T extends StringSchema ? ResolveNullish<T, string> : T extends WithNumber<NumberSchema> ? ResolveNullish<T, ExtractFromNumber<T>> : T extends NumberSchema ? ResolveNullish<T, number> : T extends WithBoolean<BooleanSchema> ? ResolveNullish<T, ExtractFromBoolean<T>> : T extends BooleanSchema ? ResolveNullish<T, boolean> : T extends ArraySchema ? ResolveNullish<T, InferType<ExtractFromArray<T>>[]> : T extends ObjectSchema ? ResolveNullish<T, ExtractFromObject<T>> : T extends WithMix ? ResolveNullish<T, ExtractFromMix<T>> : T extends WithBigInt<BigIntSchema> ? ResolveNullish<T, ExtractFromBigInt<T>> : T extends BigIntSchema ? ResolveNullish<T, bigint> : T extends DateSchema ? ResolveNullish<T, Date> : unknown;
|
|
10
13
|
type Merge<T> = T extends infer U ? {
|
|
11
14
|
[K in keyof U]: U[K];
|
|
12
15
|
} : never;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { WithArray } from '../../schemas/ArraySchema.mjs';
|
|
2
|
-
import { C as CommonSchema } from '../../CommonSchema-
|
|
2
|
+
import { C as CommonSchema } from '../../CommonSchema-DJmQ3F_9.mjs';
|
|
3
3
|
import '../../commonTypes.mjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Creates a new schema for validating arrays where each element must match the specified schema.
|
|
7
|
-
*
|
|
6
|
+
* @description Creates a new schema for validating arrays where each element must match the specified schema.
|
|
8
7
|
* @template T
|
|
9
8
|
* @param {T} arraySchema - The schema that each element of the array must match.
|
|
10
9
|
* @returns {WithArray<T>} A new instance of `ArraySchema` for validating arrays of elements that match the specified schema.
|
|
11
|
-
*
|
|
12
10
|
* @example
|
|
13
11
|
* const schema = array(string());
|
|
14
12
|
* parseOrFail(schema, ['hello', 'world']); // Validates successfully
|
|
15
13
|
* parseOrFail(schema, ['hello', 123]); // Throws a validation error
|
|
14
|
+
*
|
|
15
|
+
* @instance Of ArraySchema
|
|
16
16
|
*/
|
|
17
17
|
declare function array<T extends CommonSchema>(arraySchema: T): WithArray<T>;
|
|
18
18
|
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { WithArray } from '../../schemas/ArraySchema.js';
|
|
2
|
-
import { C as CommonSchema } from '../../CommonSchema-
|
|
2
|
+
import { C as CommonSchema } from '../../CommonSchema-9RtxTxdX.js';
|
|
3
3
|
import '../../commonTypes.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Creates a new schema for validating arrays where each element must match the specified schema.
|
|
7
|
-
*
|
|
6
|
+
* @description Creates a new schema for validating arrays where each element must match the specified schema.
|
|
8
7
|
* @template T
|
|
9
8
|
* @param {T} arraySchema - The schema that each element of the array must match.
|
|
10
9
|
* @returns {WithArray<T>} A new instance of `ArraySchema` for validating arrays of elements that match the specified schema.
|
|
11
|
-
*
|
|
12
10
|
* @example
|
|
13
11
|
* const schema = array(string());
|
|
14
12
|
* parseOrFail(schema, ['hello', 'world']); // Validates successfully
|
|
15
13
|
* parseOrFail(schema, ['hello', 123]); // Throws a validation error
|
|
14
|
+
*
|
|
15
|
+
* @instance Of ArraySchema
|
|
16
16
|
*/
|
|
17
17
|
declare function array<T extends CommonSchema>(arraySchema: T): WithArray<T>;
|
|
18
18
|
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('../../chunk-
|
|
5
|
-
require('../../chunk-
|
|
6
|
-
require('../../chunk-
|
|
3
|
+
var _chunk2OINKFOAjs = require('../../chunk-2OINKFOA.js');
|
|
4
|
+
require('../../chunk-EQNVYAKS.js');
|
|
5
|
+
require('../../chunk-7GIRQ5EA.js');
|
|
6
|
+
require('../../chunk-356HMXOP.js');
|
|
7
7
|
require('../../chunk-WK4O3HH4.js');
|
|
8
8
|
|
|
9
|
+
// src/asserts/array/index.ts
|
|
10
|
+
function array(arraySchema) {
|
|
11
|
+
return new (0, _chunk2OINKFOAjs.ArraySchema)({ type: [], requiredValidations: [] }, arraySchema);
|
|
12
|
+
}
|
|
9
13
|
|
|
10
|
-
|
|
14
|
+
|
|
15
|
+
exports.array = array;
|
|
11
16
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/asserts/array/index.js"],"names":[],"mappings":"AAAA;AACE;AACF,0DAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC;AACE;AACF,
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/asserts/array/index.js","../../../src/asserts/array/index.ts"],"names":[],"mappings":"AAAA;AACE;AACF,0DAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC;AACA;ACOO,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;ADLA;AACE;AACF,sBAAC","file":"/home/runner/work/bguard/bguard/lib/asserts/array/index.js","sourcesContent":[null,"import { ArraySchema, WithArray } from '../../schemas/ArraySchema';\nimport { CommonSchema } from '../../schemas/CommonSchema';\n\n/**\n * @description Creates a new schema for validating arrays where each element must match the specified schema.\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 * @example\n * const schema = array(string());\n * parseOrFail(schema, ['hello', 'world']); // Validates successfully\n * parseOrFail(schema, ['hello', 123]); // Throws a validation error\n *\n * @instance Of ArraySchema\n */\nexport function array<T extends CommonSchema>(arraySchema: T): WithArray<T> {\n return new ArraySchema({ type: [], requiredValidations: [] }, arraySchema) as WithArray<T>;\n}\n"]}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "../../chunk-
|
|
4
|
-
import "../../chunk-
|
|
5
|
-
import "../../chunk-
|
|
6
|
-
import "../../chunk-
|
|
2
|
+
ArraySchema
|
|
3
|
+
} from "../../chunk-PEWNA24X.mjs";
|
|
4
|
+
import "../../chunk-4UF67IQ2.mjs";
|
|
5
|
+
import "../../chunk-XZTZC73V.mjs";
|
|
6
|
+
import "../../chunk-GDSB7CDN.mjs";
|
|
7
7
|
import "../../chunk-7XFLH6R2.mjs";
|
|
8
|
+
|
|
9
|
+
// src/asserts/array/index.ts
|
|
10
|
+
function array(arraySchema) {
|
|
11
|
+
return new ArraySchema({ type: [], requiredValidations: [] }, arraySchema);
|
|
12
|
+
}
|
|
8
13
|
export {
|
|
9
14
|
array
|
|
10
15
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/asserts/array/index.ts"],"sourcesContent":["import { ArraySchema, WithArray } from '../../schemas/ArraySchema';\nimport { CommonSchema } from '../../schemas/CommonSchema';\n\n/**\n * @description Creates a new schema for validating arrays where each element must match the specified schema.\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 * @example\n * const schema = array(string());\n * parseOrFail(schema, ['hello', 'world']); // Validates successfully\n * parseOrFail(schema, ['hello', 123]); // Throws a validation error\n *\n * @instance Of ArraySchema\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,22 @@
|
|
|
1
|
+
import { RequiredValidation } from '../../commonTypes.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @description Asserts that a bigint value does not exceed a specified maximum value.
|
|
5
|
+
* @param {bigint} expected The maximum allowable value.
|
|
6
|
+
* @returns {RequiredValidation} A validation function that takes a received bigint and an exception context.
|
|
7
|
+
* @throws {ValidationError} if the received value exceeds the expected maximum value.
|
|
8
|
+
* @example
|
|
9
|
+
* const schema = bigint().custom(bigintMax(100n));
|
|
10
|
+
* parseOrFail(schema, 99n); // Valid
|
|
11
|
+
* parseOrFail(schema, 100n); // Valid
|
|
12
|
+
* parseOrFail(schema, 101n); // Throws an error: 'The received value is greater than expected'
|
|
13
|
+
*
|
|
14
|
+
* @translation Error Translation Key = 'bi:max'
|
|
15
|
+
*/
|
|
16
|
+
declare const bigintMax: {
|
|
17
|
+
(expected: bigint): RequiredValidation;
|
|
18
|
+
key: string;
|
|
19
|
+
message: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export { bigintMax };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { RequiredValidation } from '../../commonTypes.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @description Asserts that a bigint value does not exceed a specified maximum value.
|
|
5
|
+
* @param {bigint} expected The maximum allowable value.
|
|
6
|
+
* @returns {RequiredValidation} A validation function that takes a received bigint and an exception context.
|
|
7
|
+
* @throws {ValidationError} if the received value exceeds the expected maximum value.
|
|
8
|
+
* @example
|
|
9
|
+
* const schema = bigint().custom(bigintMax(100n));
|
|
10
|
+
* parseOrFail(schema, 99n); // Valid
|
|
11
|
+
* parseOrFail(schema, 100n); // Valid
|
|
12
|
+
* parseOrFail(schema, 101n); // Throws an error: 'The received value is greater than expected'
|
|
13
|
+
*
|
|
14
|
+
* @translation Error Translation Key = 'bi:max'
|
|
15
|
+
*/
|
|
16
|
+
declare const bigintMax: {
|
|
17
|
+
(expected: bigint): RequiredValidation;
|
|
18
|
+
key: string;
|
|
19
|
+
message: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export { bigintMax };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkCQWI6YRIjs = require('../../chunk-CQWI6YRI.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkWK4O3HH4js = require('../../chunk-WK4O3HH4.js');
|
|
7
|
+
|
|
8
|
+
// src/asserts/bigint/bigintMax.ts
|
|
9
|
+
var bigintMaxErrorMessage = "The received value is greater than expected";
|
|
10
|
+
var bigintMaxErrorKey = "bi:max";
|
|
11
|
+
var bigintMax = (expected) => (received, ctx) => {
|
|
12
|
+
if (expected < received) _chunkWK4O3HH4js.guardException.call(void 0, expected, received, ctx, bigintMaxErrorKey);
|
|
13
|
+
};
|
|
14
|
+
bigintMax.key = bigintMaxErrorKey;
|
|
15
|
+
bigintMax.message = bigintMaxErrorMessage;
|
|
16
|
+
_chunkCQWI6YRIjs.setToDefaultLocale.call(void 0, bigintMax);
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
exports.bigintMax = bigintMax;
|
|
20
|
+
//# sourceMappingURL=bigintMax.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/asserts/bigint/bigintMax.js","../../../src/asserts/bigint/bigintMax.ts"],"names":[],"mappings":"AAAA;AACE;AACF,0DAAgC;AAChC;AACE;AACF,0DAAgC;AAChC;AACA;ACHA,IAAM,sBAAA,EAAwB,6CAAA;AAC9B,IAAM,kBAAA,EAAoB,QAAA;AAenB,IAAM,UAAA,EACX,CAAC,QAAA,EAAA,GACD,CAAC,QAAA,EAAkB,GAAA,EAAA,GAA0B;AAC3C,EAAA,GAAA,CAAI,SAAA,EAAW,QAAA,EAAU,6CAAA,QAAe,EAAU,QAAA,EAAU,GAAA,EAAK,iBAAiB,CAAA;AACpF,CAAA;AAEF,SAAA,CAAU,IAAA,EAAM,iBAAA;AAChB,SAAA,CAAU,QAAA,EAAU,qBAAA;AACpB,iDAAA,SAA4B,CAAA;ADZ5B;AACE;AACF,8BAAC","file":"/home/runner/work/bguard/bguard/lib/asserts/bigint/bigintMax.js","sourcesContent":[null,"import { setToDefaultLocale } from '../../translationMap';\nimport { guardException } from '../../exceptions';\nimport { ExceptionContext, RequiredValidation } from '../../commonTypes';\n\nconst bigintMaxErrorMessage = 'The received value is greater than expected';\nconst bigintMaxErrorKey = 'bi:max';\n\n/**\n * @description Asserts that a bigint value does not exceed a specified maximum value.\n * @param {bigint} expected The maximum allowable value.\n * @returns {RequiredValidation} A validation function that takes a received bigint and an exception context.\n * @throws {ValidationError} if the received value exceeds the expected maximum value.\n * @example\n * const schema = bigint().custom(bigintMax(100n));\n * parseOrFail(schema, 99n); // Valid\n * parseOrFail(schema, 100n); // Valid\n * parseOrFail(schema, 101n); // Throws an error: 'The received value is greater than expected'\n *\n * @translation Error Translation Key = 'bi:max'\n */\nexport const bigintMax =\n (expected: bigint): RequiredValidation =>\n (received: bigint, ctx: ExceptionContext) => {\n if (expected < received) guardException(expected, received, ctx, bigintMaxErrorKey);\n };\n\nbigintMax.key = bigintMaxErrorKey;\nbigintMax.message = bigintMaxErrorMessage;\nsetToDefaultLocale(bigintMax);\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
setToDefaultLocale
|
|
3
|
+
} from "../../chunk-QV4JDW3T.mjs";
|
|
4
|
+
import {
|
|
5
|
+
guardException
|
|
6
|
+
} from "../../chunk-7XFLH6R2.mjs";
|
|
7
|
+
|
|
8
|
+
// src/asserts/bigint/bigintMax.ts
|
|
9
|
+
var bigintMaxErrorMessage = "The received value is greater than expected";
|
|
10
|
+
var bigintMaxErrorKey = "bi:max";
|
|
11
|
+
var bigintMax = (expected) => (received, ctx) => {
|
|
12
|
+
if (expected < received) guardException(expected, received, ctx, bigintMaxErrorKey);
|
|
13
|
+
};
|
|
14
|
+
bigintMax.key = bigintMaxErrorKey;
|
|
15
|
+
bigintMax.message = bigintMaxErrorMessage;
|
|
16
|
+
setToDefaultLocale(bigintMax);
|
|
17
|
+
export {
|
|
18
|
+
bigintMax
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=bigintMax.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/asserts/bigint/bigintMax.ts"],"sourcesContent":["import { setToDefaultLocale } from '../../translationMap';\nimport { guardException } from '../../exceptions';\nimport { ExceptionContext, RequiredValidation } from '../../commonTypes';\n\nconst bigintMaxErrorMessage = 'The received value is greater than expected';\nconst bigintMaxErrorKey = 'bi:max';\n\n/**\n * @description Asserts that a bigint value does not exceed a specified maximum value.\n * @param {bigint} expected The maximum allowable value.\n * @returns {RequiredValidation} A validation function that takes a received bigint and an exception context.\n * @throws {ValidationError} if the received value exceeds the expected maximum value.\n * @example\n * const schema = bigint().custom(bigintMax(100n));\n * parseOrFail(schema, 99n); // Valid\n * parseOrFail(schema, 100n); // Valid\n * parseOrFail(schema, 101n); // Throws an error: 'The received value is greater than expected'\n *\n * @translation Error Translation Key = 'bi:max'\n */\nexport const bigintMax =\n (expected: bigint): RequiredValidation =>\n (received: bigint, ctx: ExceptionContext) => {\n if (expected < received) guardException(expected, received, ctx, bigintMaxErrorKey);\n };\n\nbigintMax.key = bigintMaxErrorKey;\nbigintMax.message = bigintMaxErrorMessage;\nsetToDefaultLocale(bigintMax);\n"],"mappings":";;;;;;;;AAIA,IAAM,wBAAwB;AAC9B,IAAM,oBAAoB;AAenB,IAAM,YACX,CAAC,aACD,CAAC,UAAkB,QAA0B;AAC3C,MAAI,WAAW,SAAU,gBAAe,UAAU,UAAU,KAAK,iBAAiB;AACpF;AAEF,UAAU,MAAM;AAChB,UAAU,UAAU;AACpB,mBAAmB,SAAS;","names":[]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { RequiredValidation } from '../../commonTypes.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @description - Asserts that a bigint value is strictly less than a specified maximum value (i.e., the maximum value is excluded).
|
|
5
|
+
* @param {bigint} expected - The maximum allowable value, which is excluded.
|
|
6
|
+
* @returns {RequiredValidation} - A validation function that takes a received bigint and an exception context.
|
|
7
|
+
* @throws {ValidationError} if the received value is greater than or equal to the expected maximum value.
|
|
8
|
+
* @example
|
|
9
|
+
* const schema = bigint().custom(bigintMaxExcluded(100n));
|
|
10
|
+
* parseOrFail(schema, 99n); // Valid
|
|
11
|
+
* parseOrFail(schema, 100n); // Throws an error: 'The received value is greater than or equal to expected'
|
|
12
|
+
* parseOrFail(schema, 101n); // Throws an error: 'The received value is greater than or equal to expected'
|
|
13
|
+
*
|
|
14
|
+
* @translation Error Translation Key = 'bi:maxExcluded'
|
|
15
|
+
*/
|
|
16
|
+
declare const bigintMaxExcluded: {
|
|
17
|
+
(expected: bigint): RequiredValidation;
|
|
18
|
+
key: string;
|
|
19
|
+
message: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export { bigintMaxExcluded };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { RequiredValidation } from '../../commonTypes.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @description - Asserts that a bigint value is strictly less than a specified maximum value (i.e., the maximum value is excluded).
|
|
5
|
+
* @param {bigint} expected - The maximum allowable value, which is excluded.
|
|
6
|
+
* @returns {RequiredValidation} - A validation function that takes a received bigint and an exception context.
|
|
7
|
+
* @throws {ValidationError} if the received value is greater than or equal to the expected maximum value.
|
|
8
|
+
* @example
|
|
9
|
+
* const schema = bigint().custom(bigintMaxExcluded(100n));
|
|
10
|
+
* parseOrFail(schema, 99n); // Valid
|
|
11
|
+
* parseOrFail(schema, 100n); // Throws an error: 'The received value is greater than or equal to expected'
|
|
12
|
+
* parseOrFail(schema, 101n); // Throws an error: 'The received value is greater than or equal to expected'
|
|
13
|
+
*
|
|
14
|
+
* @translation Error Translation Key = 'bi:maxExcluded'
|
|
15
|
+
*/
|
|
16
|
+
declare const bigintMaxExcluded: {
|
|
17
|
+
(expected: bigint): RequiredValidation;
|
|
18
|
+
key: string;
|
|
19
|
+
message: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export { bigintMaxExcluded };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkCQWI6YRIjs = require('../../chunk-CQWI6YRI.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkWK4O3HH4js = require('../../chunk-WK4O3HH4.js');
|
|
7
|
+
|
|
8
|
+
// src/asserts/bigint/bigintMaxExcluded.ts
|
|
9
|
+
var bigintMaxExcludedErrorMessage = "The received value is greater than or equal to expected";
|
|
10
|
+
var bigintMaxExcludedErrorKey = "bi:maxExcluded";
|
|
11
|
+
var bigintMaxExcluded = (expected) => (received, ctx) => {
|
|
12
|
+
if (expected <= received) _chunkWK4O3HH4js.guardException.call(void 0, expected, received, ctx, bigintMaxExcludedErrorKey);
|
|
13
|
+
};
|
|
14
|
+
bigintMaxExcluded.key = bigintMaxExcludedErrorKey;
|
|
15
|
+
bigintMaxExcluded.message = bigintMaxExcludedErrorMessage;
|
|
16
|
+
_chunkCQWI6YRIjs.setToDefaultLocale.call(void 0, bigintMaxExcluded);
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
exports.bigintMaxExcluded = bigintMaxExcluded;
|
|
20
|
+
//# sourceMappingURL=bigintMaxExcluded.js.map
|