bguard 0.7.0 → 0.7.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 +29 -11
- package/lib/asserts/array/index.d.mts +1 -1
- package/lib/asserts/array/index.d.ts +1 -1
- package/lib/asserts/array/index.js +4 -2
- package/lib/asserts/array/index.js.map +1 -1
- package/lib/asserts/array/index.mjs +3 -1
- package/lib/asserts/bigint/index.d.mts +1 -1
- package/lib/asserts/bigint/index.d.ts +1 -1
- package/lib/asserts/bigint/index.js +5 -3
- package/lib/asserts/bigint/index.js.map +1 -1
- package/lib/asserts/bigint/index.mjs +4 -2
- package/lib/asserts/boolean/index.d.mts +1 -1
- package/lib/asserts/boolean/index.d.ts +1 -1
- package/lib/asserts/boolean/index.js +4 -2
- package/lib/asserts/boolean/index.js.map +1 -1
- package/lib/asserts/boolean/index.mjs +3 -1
- package/lib/asserts/coerce/bigint.d.mts +32 -0
- package/lib/asserts/coerce/bigint.d.ts +32 -0
- package/lib/asserts/coerce/bigint.js +16 -0
- package/lib/asserts/coerce/bigint.js.map +1 -0
- package/lib/asserts/coerce/bigint.mjs +16 -0
- package/lib/asserts/coerce/bigint.mjs.map +1 -0
- package/lib/asserts/coerce/boolean.d.mts +35 -0
- package/lib/asserts/coerce/boolean.d.ts +35 -0
- package/lib/asserts/coerce/boolean.js +14 -0
- package/lib/asserts/coerce/boolean.js.map +1 -0
- package/lib/asserts/coerce/boolean.mjs +14 -0
- package/lib/asserts/coerce/boolean.mjs.map +1 -0
- package/lib/asserts/coerce/date.d.mts +32 -0
- package/lib/asserts/coerce/date.d.ts +32 -0
- package/lib/asserts/coerce/date.js +13 -0
- package/lib/asserts/coerce/date.js.map +1 -0
- package/lib/asserts/coerce/date.mjs +13 -0
- package/lib/asserts/coerce/date.mjs.map +1 -0
- package/lib/asserts/coerce/index.d.mts +25 -36
- package/lib/asserts/coerce/index.d.ts +25 -36
- package/lib/asserts/coerce/index.js +28 -8
- package/lib/asserts/coerce/index.js.map +1 -1
- package/lib/asserts/coerce/index.mjs +28 -8
- package/lib/asserts/coerce/number.d.mts +33 -0
- package/lib/asserts/coerce/number.d.ts +33 -0
- package/lib/asserts/coerce/number.js +16 -0
- package/lib/asserts/coerce/number.js.map +1 -0
- package/lib/asserts/coerce/number.mjs +16 -0
- package/lib/asserts/coerce/number.mjs.map +1 -0
- package/lib/asserts/coerce/string.d.mts +30 -0
- package/lib/asserts/coerce/string.d.ts +30 -0
- package/lib/asserts/coerce/string.js +17 -0
- package/lib/asserts/coerce/string.js.map +1 -0
- package/lib/asserts/coerce/string.mjs +17 -0
- package/lib/asserts/coerce/string.mjs.map +1 -0
- package/lib/asserts/date/index.d.mts +1 -1
- package/lib/asserts/date/index.d.ts +1 -1
- package/lib/asserts/date/index.js +4 -2
- package/lib/asserts/date/index.js.map +1 -1
- package/lib/asserts/date/index.mjs +3 -1
- package/lib/asserts/number/index.d.mts +1 -1
- package/lib/asserts/number/index.d.ts +1 -1
- package/lib/asserts/number/index.js +5 -3
- package/lib/asserts/number/index.js.map +1 -1
- package/lib/asserts/number/index.mjs +4 -2
- package/lib/asserts/string/index.d.mts +1 -1
- package/lib/asserts/string/index.d.ts +1 -1
- package/lib/asserts/string/index.js +5 -3
- package/lib/asserts/string/index.js.map +1 -1
- package/lib/asserts/string/index.mjs +4 -2
- package/lib/{chunk-GYLCPX6O.js → chunk-23R5R7PL.js} +3 -2
- package/lib/chunk-23R5R7PL.js.map +1 -0
- package/lib/{chunk-EVM26M2C.js → chunk-4PPMVVQY.js} +5 -4
- package/lib/chunk-4PPMVVQY.js.map +1 -0
- package/lib/chunk-56TWNROC.js +20 -0
- package/lib/chunk-56TWNROC.js.map +1 -0
- package/lib/{chunk-UWONIZJZ.mjs → chunk-5PXMSVTE.mjs} +6 -5
- package/lib/chunk-5PXMSVTE.mjs.map +1 -0
- package/lib/{chunk-B2R5S6OH.mjs → chunk-A2LPSUNQ.mjs} +3 -2
- package/lib/{chunk-B2R5S6OH.mjs.map → chunk-A2LPSUNQ.mjs.map} +1 -1
- package/lib/{chunk-EJCCIGXH.js → chunk-AGB5RWYD.js} +3 -2
- package/lib/chunk-AGB5RWYD.js.map +1 -0
- package/lib/{chunk-CJCIOMS7.mjs → chunk-DS2LUTTF.mjs} +6 -5
- package/lib/chunk-DS2LUTTF.mjs.map +1 -0
- package/lib/{chunk-UCHEFFWR.js → chunk-EI6TQG4L.js} +5 -4
- package/lib/chunk-EI6TQG4L.js.map +1 -0
- package/lib/chunk-ET2I4EXQ.mjs +18 -0
- package/lib/chunk-ET2I4EXQ.mjs.map +1 -0
- package/lib/chunk-FA3S35LQ.mjs +20 -0
- package/lib/chunk-FA3S35LQ.mjs.map +1 -0
- package/lib/{chunk-O646PJXY.mjs → chunk-FU5WAVRB.mjs} +3 -2
- package/lib/{chunk-O646PJXY.mjs.map → chunk-FU5WAVRB.mjs.map} +1 -1
- package/lib/chunk-HU5SDECP.js +29 -0
- package/lib/chunk-HU5SDECP.js.map +1 -0
- package/lib/{chunk-YJZXJKM4.mjs → chunk-J3EKIWPZ.mjs} +6 -5
- package/lib/chunk-J3EKIWPZ.mjs.map +1 -0
- package/lib/chunk-JCX2TB7E.js +13 -0
- package/lib/chunk-JCX2TB7E.js.map +1 -0
- package/lib/chunk-K7CDOU6F.js +13 -0
- package/lib/chunk-K7CDOU6F.js.map +1 -0
- package/lib/chunk-KALHMMEN.mjs +29 -0
- package/lib/chunk-KALHMMEN.mjs.map +1 -0
- package/lib/{chunk-5VZDHJKM.mjs → chunk-KGXWQ3XP.mjs} +3 -2
- package/lib/chunk-KGXWQ3XP.mjs.map +1 -0
- package/lib/chunk-MUXY6Q45.mjs +13 -0
- package/lib/chunk-MUXY6Q45.mjs.map +1 -0
- package/lib/chunk-SBNUNRI3.mjs +13 -0
- package/lib/chunk-SBNUNRI3.mjs.map +1 -0
- package/lib/chunk-TD3Y3IV3.js +13 -0
- package/lib/chunk-TD3Y3IV3.js.map +1 -0
- package/lib/chunk-UCY3HEYZ.mjs +13 -0
- package/lib/chunk-UCY3HEYZ.mjs.map +1 -0
- package/lib/{chunk-L7YFDMZU.js → chunk-WH7WJMFF.js} +5 -4
- package/lib/chunk-WH7WJMFF.js.map +1 -0
- package/lib/chunk-WLZZTIOV.js +18 -0
- package/lib/chunk-WLZZTIOV.js.map +1 -0
- package/lib/{chunk-DPXTSNEX.js → chunk-YPOEO3UF.js} +3 -2
- package/lib/chunk-YPOEO3UF.js.map +1 -0
- package/lib/index.d.mts +5 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +64 -44
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +78 -58
- package/package.json +12 -1
- package/lib/chunk-5VZDHJKM.mjs.map +0 -1
- package/lib/chunk-CJCIOMS7.mjs.map +0 -1
- package/lib/chunk-DPXTSNEX.js.map +0 -1
- package/lib/chunk-EJCCIGXH.js.map +0 -1
- package/lib/chunk-EVM26M2C.js.map +0 -1
- package/lib/chunk-GYLCPX6O.js.map +0 -1
- package/lib/chunk-KGNT5T35.mjs +0 -70
- package/lib/chunk-KGNT5T35.mjs.map +0 -1
- package/lib/chunk-L7YFDMZU.js.map +0 -1
- package/lib/chunk-TLLR2DXI.js +0 -70
- package/lib/chunk-TLLR2DXI.js.map +0 -1
- package/lib/chunk-UCHEFFWR.js.map +0 -1
- package/lib/chunk-UWONIZJZ.mjs.map +0 -1
- package/lib/chunk-YJZXJKM4.mjs.map +0 -1
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
+
StringSchema,
|
|
2
3
|
string
|
|
3
|
-
} from "../../chunk-
|
|
4
|
-
import "../../chunk-D42AL6CN.mjs";
|
|
4
|
+
} from "../../chunk-J3EKIWPZ.mjs";
|
|
5
5
|
import "../../chunk-YQP44G45.mjs";
|
|
6
|
+
import "../../chunk-D42AL6CN.mjs";
|
|
6
7
|
import "../../chunk-POPLWPM4.mjs";
|
|
7
8
|
import "../../chunk-IIL6D2UL.mjs";
|
|
8
9
|
import "../../chunk-LDZFOOWN.mjs";
|
|
@@ -11,6 +12,7 @@ import "../../chunk-YBVMP4EI.mjs";
|
|
|
11
12
|
import "../../chunk-C76DLZFD.mjs";
|
|
12
13
|
import "../../chunk-O2WD4JBG.mjs";
|
|
13
14
|
export {
|
|
15
|
+
StringSchema,
|
|
14
16
|
string
|
|
15
17
|
};
|
|
16
18
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -64,5 +64,6 @@ var BooleanSchema = (_class = class extends _chunk6LUSV3SSjs.CommonSchema {const
|
|
|
64
64
|
|
|
65
65
|
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
|
|
68
|
+
exports.boolean = boolean; exports.BooleanSchema = BooleanSchema;
|
|
69
|
+
//# sourceMappingURL=chunk-23R5R7PL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-23R5R7PL.js","../src/asserts/boolean/index.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACA;ACJA,IAAM,UAAA,EACJ,CAAC,QAAA,EAAA,GACD,CAAC,QAAA,EAAmB,GAAA,EAAA,GAA0B;AAC5C,EAAA,GAAA,CAAI,SAAA,IAAa,QAAA,EAAU,GAAA,CAAI,QAAA,CAAS,QAAA,EAAU,QAAA,EAAU,aAAa,CAAA;AAC3E,CAAA;AAYK,SAAS,OAAA,CAAA,EAAkD;AAChE,EAAA,OAAO,IAAI,aAAA,CAAc,EAAE,IAAA,EAAM,CAAC,SAAS,CAAA,EAAG,mBAAA,EAAqB,CAAC,EAAE,CAAC,CAAA;AACzE;AAEO,IAAM,cAAA,YAAN,MAAA,QAA4B,8BAAa;AAAA,iBACpC,SAAA,EAAW,EAAA;AAAA,EACb;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,UAAA,CAAA,EAAa;AACnB,IAAA,GAAA,CAAI,IAAA,CAAK,KAAA,EAAO,MAAM,IAAI,sCAAA,CAAiB,0BAAS,CAAA;AAAA,EACtD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWO,QAAA,CAAA,EAAuC;AAC5C,IAAA,IAAA,CAAK,UAAA,CAAW,CAAA;AAChB,IAAA,MAAM,KAAA,EAAO,IAAA,CAAK,MAAA,CAAO,SAAA,CAAU,IAAI,CAAC,CAAA;AACxC,IAAA,IAAA,CAAK,MAAA,EAAQ,IAAA;AACb,IAAA,6CAAA,IAAe,EAAM,IAAI,CAAA;AACzB,IAAA,OAAO,IAAA;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWO,SAAA,CAAA,EAAyC;AAC9C,IAAA,IAAA,CAAK,UAAA,CAAW,CAAA;AAChB,IAAA,MAAM,KAAA,EAAO,IAAA,CAAK,MAAA,CAAO,SAAA,CAAU,KAAK,CAAC,CAAA;AACzC,IAAA,IAAA,CAAK,MAAA,EAAQ,IAAA;AACb,IAAA,6CAAA,IAAe,EAAM,KAAK,CAAA;AAC1B,IAAA,OAAO,IAAA;AAAA,EACT;AACF,UAAA;ADXA;AACA;AACE;AACA;AACF,iEAAC","file":"/home/runner/work/bguard/bguard/lib/chunk-23R5R7PL.js","sourcesContent":[null,"import { WithBGuardType } from '../../commonTypes';\nimport { CommonSchema, type ExceptionContext, type RequiredValidation } from '../../core';\nimport { _setStrictType } from '../../helpers/setStrictType';\nimport { BuildSchemaError } from '../../exceptions';\nimport { ONLY_ONCE } from '../../helpers/constants';\n\n// Declared over `unknown` rather than `boolean`: it is applied from inside the class, where `this`\n// is still polymorphic, so the schema's own value type cannot be resolved yet. The comparison is\n// identity-based, so widening the parameter costs nothing.\nconst isBoolean =\n (expected: boolean): RequiredValidation<unknown> =>\n (received: unknown, ctx: ExceptionContext) => {\n if (received !== expected) ctx.addIssue(expected, received, 'c:isBoolean');\n };\n\n/**\n * @description Creates a new schema for validating boolean values.\n * @returns {WithBGuardType<BooleanSchema, boolean>} A new instance of `BooleanSchema` for validating booleans.\n * @example\n * const schema = boolean();\n * parseOrFail(schema, true); // Validates successfully\n * parseOrFail(schema, 'true'); // Throws a validation error\n *\n * @instance Of BooleanSchema\n */\nexport function boolean(): WithBGuardType<BooleanSchema, boolean> {\n return new BooleanSchema({ type: ['boolean'], requiredValidations: [] }) as WithBGuardType<BooleanSchema, boolean>;\n}\n\nexport class BooleanSchema extends CommonSchema {\n protected _boolean = 1;\n private limit: boolean | undefined;\n\n /**\n * Reads the once-only flag without setting it, matching the string, number and bigint schemas.\n * Without it, onlyTrue().onlyFalse() built a schema that rejects both true and false.\n */\n private limitGuard() {\n if (this.limit) throw new BuildSchemaError(ONLY_ONCE);\n }\n\n /**\n * @method onlyTrue\n * @description Restricts the schema to exactly match the boolean value true and infers the true value as the TypeScript type.\n * @returns A new schema restricted to the value true, with the true value inferred as the TypeScript type\n * @example\n * boolean().onlyTrue(); // Infers the type true\n *\n * @public\n */\n public onlyTrue(): WithBGuardType<this, true> {\n this.limitGuard();\n const next = this.custom(isBoolean(true));\n next.limit = true;\n _setStrictType(next, true);\n return next as WithBGuardType<this, true>;\n }\n\n /**\n * @method onlyFalse\n * @description Restricts the schema to exactly match the boolean value false and infers the false value as the TypeScript type.\n * @returns A new schema restricted to the value false, with the false value inferred as the TypeScript type\n * @example\n * boolean().onlyFalse(); // Infers the type false\n *\n * @public\n */\n public onlyFalse(): WithBGuardType<this, false> {\n this.limitGuard();\n const next = this.custom(isBoolean(false));\n next.limit = true;\n _setStrictType(next, false);\n return next as WithBGuardType<this, false>;\n }\n}\n"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _class;
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkOPA6AXSHjs = require('./chunk-OPA6AXSH.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunk3D6TPN7Fjs = require('./chunk-3D6TPN7F.js');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
var _chunkFTHEF6SBjs = require('./chunk-FTHEF6SB.js');
|
|
@@ -62,5 +62,6 @@ var NumberSchema = (_class = class extends _chunk6LUSV3SSjs.CommonSchema {constr
|
|
|
62
62
|
|
|
63
63
|
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
|
|
66
|
+
exports.number = number; exports.NumberSchema = NumberSchema;
|
|
67
|
+
//# sourceMappingURL=chunk-4PPMVVQY.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-4PPMVVQY.js","../src/asserts/number/index.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;ACDO,SAAS,MAAA,CAAA,EAA+C;AAC7D,EAAA,OAAO,IAAI,YAAA,CAAa,EAAE,IAAA,EAAM,CAAC,QAAQ,CAAA,EAAG,mBAAA,EAAqB,CAAC,EAAE,CAAC,CAAA;AACvE;AAEO,IAAM,aAAA,YAAN,MAAA,QAA2B,8BAAa;AAAA,iBACnC,QAAA,EAAU,EAAA;AAAA,EACZ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYD,OAAA,CAA0B,aAAA,EAA2C;AAC1E,IAAA,GAAA,CAAI,IAAA,CAAK,KAAA,EAAO,MAAM,IAAI,sCAAA,CAAiB,0BAAS,CAAA;AAGpD,IAAA,MAAM,KAAA,EAAO,IAAA,CAAK,MAAA,CAAO,sCAAA,aAAqB,CAAC,CAAA;AAC/C,IAAA,IAAA,CAAK,MAAA,EAAQ,IAAA;AACb,IAAA,6CAAA,IAAe,EAAM,aAAa,CAAA;AAClC,IAAA,OAAO,IAAA;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYO,WAAA,CAA8B,aAAA,EAA6C;AAChF,IAAA,GAAA,CAAI,IAAA,CAAK,KAAA,EAAO,MAAM,IAAI,sCAAA,CAAiB,0BAAS,CAAA;AACpD,IAAA,MAAM,KAAA,EAAO,IAAA,CAAK,MAAA,CAAO,0CAAA,aAAyB,CAAC,CAAA;AACnD,IAAA,IAAA,CAAK,MAAA,EAAQ,IAAA;AACb,IAAA,6CAAA,IAAe,EAAM,aAAa,CAAA;AAClC,IAAA,OAAO,IAAA;AAAA,EACT;AACF,UAAA;ADFA;AACA;AACE;AACA;AACF,6DAAC","file":"/home/runner/work/bguard/bguard/lib/chunk-4PPMVVQY.js","sourcesContent":[null,"import { WithBGuardType } from '../../commonTypes';\nimport { BuildSchemaError } from '../../exceptions';\nimport { ONLY_ONCE } from '../../helpers/constants';\nimport { CommonSchema } from '../../core';\nimport { _setStrictType } from '../../helpers/setStrictType';\nimport { equalTo } from '../mix/equalTo';\nimport { oneOfValues } from '../mix/oneOfValues';\n\n/**\n * @description Creates a new schema for validating number values.\n * @returns {NumberSchema} A new instance of `NumberSchema` for validating numbers.\n * @example\n * const schema = number();\n * parseOrFail(schema, 42); // Validates successfully\n * parseOrFail(schema, '42'); // Throws a validation error\n *\n * @instance Of NumberSchema\n */\nexport function number(): WithBGuardType<NumberSchema, number> {\n return new NumberSchema({ type: ['number'], requiredValidations: [] }) as WithBGuardType<NumberSchema, number>;\n}\n\nexport class NumberSchema extends CommonSchema {\n protected _number = 1;\n private limit: boolean | undefined;\n\n /**\n * @method equalTo\n * @description Restricts the schema to exactly match the specified value and infers the literal value as the TypeScript type.\n * @param expectedValue - The value that the schema must exactly match.\n * @returns A new schema restricted to the specified value, with the literal value inferred as the TypeScript type\n * @example\n * number().equalTo(42); // Infers the type 42\n *\n * @public\n */\n public equalTo<Y extends number>(expectedValue: Y): WithBGuardType<this, Y> {\n if (this.limit) throw new BuildSchemaError(ONLY_ONCE);\n // custom() returns the copy, so the strict type and the once-only flag are set on it. Setting\n // them on `this` first would refine the schema this one was derived from.\n const next = this.custom(equalTo(expectedValue));\n next.limit = true;\n _setStrictType(next, expectedValue);\n return next as WithBGuardType<this, Y>;\n }\n\n /**\n * @method oneOfValues\n * @description Restricts the schema to match one of the specified values and infers the union of those values as the TypeScript type.\n * @param expectedValues - An array of values that the schema can match.\n * @returns A new schema restricted to one of the specified values, with the union of those values inferred as the TypeScript type.\n * @example\n * number().oneOfValues([5, 7]); // Infers the type 5 | 7\n *\n * @public\n */\n public oneOfValues<Y extends number>(expectedValue: Y[]): WithBGuardType<this, Y> {\n if (this.limit) throw new BuildSchemaError(ONLY_ONCE);\n const next = this.custom(oneOfValues(expectedValue));\n next.limit = true;\n _setStrictType(next, expectedValue);\n return next as WithBGuardType<this, Y>;\n }\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunk23R5R7PLjs = require('./chunk-23R5R7PL.js');
|
|
4
|
+
|
|
5
|
+
// src/asserts/coerce/boolean.ts
|
|
6
|
+
var coerceBoolean = () => _chunk23R5R7PLjs.boolean.call(void 0, ).transformBeforeValidation((received) => {
|
|
7
|
+
if (typeof received === "string") {
|
|
8
|
+
const lowered = received.toLowerCase();
|
|
9
|
+
if (lowered === "true") return true;
|
|
10
|
+
if (lowered === "false") return false;
|
|
11
|
+
}
|
|
12
|
+
if (received === 1) return true;
|
|
13
|
+
if (received === 0) return false;
|
|
14
|
+
return received;
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
exports.coerceBoolean = coerceBoolean;
|
|
20
|
+
//# sourceMappingURL=chunk-56TWNROC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-56TWNROC.js","../src/asserts/coerce/boolean.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACA;ACuBO,IAAM,cAAA,EAAgB,CAAA,EAAA,GAC3B,sCAAA,CAAQ,CAAE,yBAAA,CAAmC,CAAC,QAAA,EAAA,GAAa;AACzD,EAAA,GAAA,CAAI,OAAO,SAAA,IAAa,QAAA,EAAU;AAChC,IAAA,MAAM,QAAA,EAAU,QAAA,CAAS,WAAA,CAAY,CAAA;AACrC,IAAA,GAAA,CAAI,QAAA,IAAY,MAAA,EAAQ,OAAO,IAAA;AAC/B,IAAA,GAAA,CAAI,QAAA,IAAY,OAAA,EAAS,OAAO,KAAA;AAAA,EAClC;AAEA,EAAA,GAAA,CAAI,SAAA,IAAa,CAAA,EAAG,OAAO,IAAA;AAC3B,EAAA,GAAA,CAAI,SAAA,IAAa,CAAA,EAAG,OAAO,KAAA;AAE3B,EAAA,OAAO,QAAA;AACT,CAAC,CAAA;ADxBH;AACA;AACE;AACF,sCAAC","file":"/home/runner/work/bguard/bguard/lib/chunk-56TWNROC.js","sourcesContent":[null,"import { boolean } from '../boolean/index';\n\n/**\n * A coercing transform must never throw: it runs before validation, and throwing would replace a clear\n * validation error with an unexplained failure. Anything it cannot convert is passed through unchanged\n * so that validation reports the type problem itself.\n *\n * `null` is never coerced, so `nullable()` still decides whether it is allowed rather than it becoming\n * the string `'null'` or the number `0`.\n *\n * The return type is inferred rather than written out. Naming it flattened the schema to\n * `CommonSchema`, which silently dropped the methods only the concrete classes define — `equalTo`,\n * `oneOfValues`, `onlyTrue`, `onlyFalse`.\n */\n/**\n * @description Coerces the received value to a boolean before validating it.\n *\n * Only the values that unambiguously mean a boolean are converted: the strings `'true'` and `'false'`\n * in any case, and the numbers `1` and `0`. Everything else is left for validation to reject.\n *\n * Deliberately narrower than passing the value through `Boolean`, which would accept every input and\n * quietly read `'false'` as `true`.\n *\n * @returns A boolean schema that accepts `unknown` as its input type.\n * @example\n * parseOrFail(coerceBoolean(), 'false'); // false\n */\nexport const coerceBoolean = () =>\n boolean().transformBeforeValidation<unknown>((received) => {\n if (typeof received === 'string') {\n const lowered = received.toLowerCase();\n if (lowered === 'true') return true;\n if (lowered === 'false') return false;\n }\n\n if (received === 1) return true;\n if (received === 0) return false;\n\n return received as boolean;\n });\n"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
oneOfValues
|
|
3
|
-
} from "./chunk-D42AL6CN.mjs";
|
|
4
1
|
import {
|
|
5
2
|
equalTo
|
|
6
3
|
} from "./chunk-YQP44G45.mjs";
|
|
4
|
+
import {
|
|
5
|
+
oneOfValues
|
|
6
|
+
} from "./chunk-D42AL6CN.mjs";
|
|
7
7
|
import {
|
|
8
8
|
_setStrictType
|
|
9
9
|
} from "./chunk-IIL6D2UL.mjs";
|
|
@@ -73,6 +73,7 @@ var BigIntSchema = class extends CommonSchema {
|
|
|
73
73
|
};
|
|
74
74
|
|
|
75
75
|
export {
|
|
76
|
-
bigint
|
|
76
|
+
bigint,
|
|
77
|
+
BigIntSchema
|
|
77
78
|
};
|
|
78
|
-
//# sourceMappingURL=chunk-
|
|
79
|
+
//# sourceMappingURL=chunk-5PXMSVTE.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/asserts/bigint/index.ts"],"sourcesContent":["import { WithBGuardType } from '../../commonTypes';\nimport { BuildSchemaError } from '../../exceptions';\nimport { ONLY_ONCE } from '../../helpers/constants';\nimport { CommonSchema } from '../../core';\nimport { _setStrictType } from '../../helpers/setStrictType';\nimport { equalTo } from '../mix/equalTo';\nimport { oneOfValues } from '../mix/oneOfValues';\n\n/**\n * @description - Creates a new schema for validating bigint values.\n * @returns {WithBGuardType<BigIntSchema, bigint>} A new instance of `BigIntSchema` for validating bigints.\n * @example\n * const schema = bigint();\n * parseOrFail(schema, 42n); // Validates successfully\n * parseOrFail(schema, 42); // Throws a validation error\n * parseOrFail(schema, '42'); // Throws a validation error\n *\n * @instance Of BigIntSchema\n */\nexport function bigint(): WithBGuardType<BigIntSchema, bigint> {\n return new BigIntSchema({ type: ['bigint'], requiredValidations: [] }) as WithBGuardType<BigIntSchema, bigint>;\n}\n\nexport class BigIntSchema extends CommonSchema {\n protected _bigint = 1;\n private limit: boolean | undefined;\n\n /**\n * @method equalTo\n * @description Restricts the schema to exactly match the specified value and infers the literal value as the TypeScript type.\n * @param expectedValue - The value that the schema must exactly match.\n * @returns A new schema restricted to the specified value, with the literal value inferred as the TypeScript type\n * @example\n * bigint().equalTo(42n); // Infers the type 42n\n *\n * @public\n */\n public equalTo<Y extends bigint>(expectedValue: Y): WithBGuardType<this, Y> {\n this.defaultValueCheck();\n this.limitGuard();\n const next = this.custom(equalTo(expectedValue));\n next.limit = true;\n _setStrictType(next, `${expectedValue}n`);\n return next as WithBGuardType<this, Y>;\n }\n\n /**\n * @method oneOfValues\n * @description Restricts the schema to match one of the specified values and infers the union of those values as the TypeScript type.\n * @param expectedValues - An array of values that the schema can match.\n * @returns A new schema restricted to one of the specified values, with the union of those values inferred as the TypeScript type.\n * @example\n * bigint().oneOfValues([5n, 7n]); // Infers the type 5n | 7n\n *\n * @public\n */\n public oneOfValues<Y extends bigint>(expectedValue: Y[]): WithBGuardType<this, Y> {\n this.defaultValueCheck();\n this.limitGuard();\n const next = this.custom(oneOfValues(expectedValue));\n next.limit = true;\n _setStrictType(\n next,\n expectedValue.map((el) => `${el}n`),\n );\n return next as WithBGuardType<this, Y>;\n }\n\n /**\n * Reads the once-only flag without setting it. The flag belongs on the schema that `custom`\n * returns, not on the one it was derived from.\n */\n private limitGuard() {\n if (this.limit) throw new BuildSchemaError(ONLY_ONCE);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAmBO,SAAS,SAA+C;AAC7D,SAAO,IAAI,aAAa,EAAE,MAAM,CAAC,QAAQ,GAAG,qBAAqB,CAAC,EAAE,CAAC;AACvE;AAEO,IAAM,eAAN,cAA2B,aAAa;AAAA,EACnC,UAAU;AAAA,EACZ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYD,QAA0B,eAA2C;AAC1E,SAAK,kBAAkB;AACvB,SAAK,WAAW;AAChB,UAAM,OAAO,KAAK,OAAO,QAAQ,aAAa,CAAC;AAC/C,SAAK,QAAQ;AACb,mBAAe,MAAM,GAAG,aAAa,GAAG;AACxC,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYO,YAA8B,eAA6C;AAChF,SAAK,kBAAkB;AACvB,SAAK,WAAW;AAChB,UAAM,OAAO,KAAK,OAAO,YAAY,aAAa,CAAC;AACnD,SAAK,QAAQ;AACb;AAAA,MACE;AAAA,MACA,cAAc,IAAI,CAAC,OAAO,GAAG,EAAE,GAAG;AAAA,IACpC;AACA,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA,EAMQ,aAAa;AACnB,QAAI,KAAK,MAAO,OAAM,IAAI,iBAAiB,SAAS;AAAA,EACtD;AACF;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/asserts/array/index.ts"],"sourcesContent":["import { type WithArray } from '../../commonTypes';\nimport { BuildSchemaError } from '../../exceptions';\nimport { ctxSymbol } from '../../helpers/constants';\nimport { CommonSchema, type ValidatorContext } from '../../core';\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<ArraySchema, 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<ArraySchema, T> {\n return new ArraySchema({ type: [], requiredValidations: [] }, arraySchema) as WithArray<ArraySchema, T>;\n}\n\
|
|
1
|
+
{"version":3,"sources":["../src/asserts/array/index.ts"],"sourcesContent":["import { type WithArray } from '../../commonTypes';\nimport { BuildSchemaError } from '../../exceptions';\nimport { ctxSymbol } from '../../helpers/constants';\nimport { CommonSchema, type ValidatorContext } from '../../core';\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<ArraySchema, 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<ArraySchema, T> {\n return new ArraySchema({ type: [], requiredValidations: [] }, arraySchema) as WithArray<ArraySchema, T>;\n}\n\nexport class ArraySchema extends CommonSchema {\n protected _array = 1;\n constructor(ctx: ValidatorContext, arraySchema: CommonSchema) {\n super(ctx);\n this.validateArrayEntry(arraySchema);\n this[ctxSymbol].array = arraySchema;\n }\n\n private validateArrayEntry(arraySchema: CommonSchema) {\n if (!arraySchema) throw new BuildSchemaError('Missing schema in array method');\n if (!(arraySchema instanceof CommonSchema)) throw new BuildSchemaError('Invalid schema in array method');\n }\n}\n"],"mappings":";;;;;;;;;;;AAiBO,SAAS,MAA8B,aAA2C;AACvF,SAAO,IAAI,YAAY,EAAE,MAAM,CAAC,GAAG,qBAAqB,CAAC,EAAE,GAAG,WAAW;AAC3E;AAEO,IAAM,cAAN,cAA0B,aAAa;AAAA,EAClC,SAAS;AAAA,EACnB,YAAY,KAAuB,aAA2B;AAC5D,UAAM,GAAG;AACT,SAAK,mBAAmB,WAAW;AACnC,SAAK,SAAS,EAAE,QAAQ;AAAA,EAC1B;AAAA,EAEQ,mBAAmB,aAA2B;AACpD,QAAI,CAAC,YAAa,OAAM,IAAI,iBAAiB,gCAAgC;AAC7E,QAAI,EAAE,uBAAuB,cAAe,OAAM,IAAI,iBAAiB,gCAAgC;AAAA,EACzG;AACF;","names":[]}
|
|
@@ -27,5 +27,6 @@ var ArraySchema = (_class = class extends _chunk6LUSV3SSjs.CommonSchema {
|
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
|
|
31
|
+
exports.array = array; exports.ArraySchema = ArraySchema;
|
|
32
|
+
//# sourceMappingURL=chunk-AGB5RWYD.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-AGB5RWYD.js","../src/asserts/array/index.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACA;ACOO,SAAS,KAAA,CAA8B,WAAA,EAA2C;AACvF,EAAA,OAAO,IAAI,WAAA,CAAY,EAAE,IAAA,EAAM,CAAC,CAAA,EAAG,mBAAA,EAAqB,CAAC,EAAE,CAAA,EAAG,WAAW,CAAA;AAC3E;AAEO,IAAM,YAAA,YAAN,MAAA,QAA0B,8BAAa;AAAA,iBAClC,OAAA,EAAS,EAAA;AAAA,EACnB,WAAA,CAAY,GAAA,EAAuB,WAAA,EAA2B;AAC5D,IAAA,KAAA,CAAM,GAAG,qCAAA;AACT,IAAA,IAAA,CAAK,kBAAA,CAAmB,WAAW,CAAA;AACnC,IAAA,IAAA,CAAK,0BAAS,CAAA,CAAE,MAAA,EAAQ,WAAA;AAAA,EAC1B;AAAA,EAEQ,kBAAA,CAAmB,WAAA,EAA2B;AACpD,IAAA,GAAA,CAAI,CAAC,WAAA,EAAa,MAAM,IAAI,sCAAA,CAAiB,gCAAgC,CAAA;AAC7E,IAAA,GAAA,CAAI,CAAA,CAAE,YAAA,WAAuB,6BAAA,CAAA,EAAe,MAAM,IAAI,sCAAA,CAAiB,gCAAgC,CAAA;AAAA,EACzG;AACF,UAAA;ADPA;AACA;AACE;AACA;AACF,yDAAC","file":"/home/runner/work/bguard/bguard/lib/chunk-AGB5RWYD.js","sourcesContent":[null,"import { type WithArray } from '../../commonTypes';\nimport { BuildSchemaError } from '../../exceptions';\nimport { ctxSymbol } from '../../helpers/constants';\nimport { CommonSchema, type ValidatorContext } from '../../core';\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<ArraySchema, 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<ArraySchema, T> {\n return new ArraySchema({ type: [], requiredValidations: [] }, arraySchema) as WithArray<ArraySchema, T>;\n}\n\nexport class ArraySchema extends CommonSchema {\n protected _array = 1;\n constructor(ctx: ValidatorContext, arraySchema: CommonSchema) {\n super(ctx);\n this.validateArrayEntry(arraySchema);\n this[ctxSymbol].array = arraySchema;\n }\n\n private validateArrayEntry(arraySchema: CommonSchema) {\n if (!arraySchema) throw new BuildSchemaError('Missing schema in array method');\n if (!(arraySchema instanceof CommonSchema)) throw new BuildSchemaError('Invalid schema in array method');\n }\n}\n"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
oneOfValues
|
|
3
|
-
} from "./chunk-D42AL6CN.mjs";
|
|
4
1
|
import {
|
|
5
2
|
equalTo
|
|
6
3
|
} from "./chunk-YQP44G45.mjs";
|
|
4
|
+
import {
|
|
5
|
+
oneOfValues
|
|
6
|
+
} from "./chunk-D42AL6CN.mjs";
|
|
7
7
|
import {
|
|
8
8
|
_setStrictType
|
|
9
9
|
} from "./chunk-IIL6D2UL.mjs";
|
|
@@ -61,6 +61,7 @@ var NumberSchema = class extends CommonSchema {
|
|
|
61
61
|
};
|
|
62
62
|
|
|
63
63
|
export {
|
|
64
|
-
number
|
|
64
|
+
number,
|
|
65
|
+
NumberSchema
|
|
65
66
|
};
|
|
66
|
-
//# sourceMappingURL=chunk-
|
|
67
|
+
//# sourceMappingURL=chunk-DS2LUTTF.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/asserts/number/index.ts"],"sourcesContent":["import { WithBGuardType } from '../../commonTypes';\nimport { BuildSchemaError } from '../../exceptions';\nimport { ONLY_ONCE } from '../../helpers/constants';\nimport { CommonSchema } from '../../core';\nimport { _setStrictType } from '../../helpers/setStrictType';\nimport { equalTo } from '../mix/equalTo';\nimport { oneOfValues } from '../mix/oneOfValues';\n\n/**\n * @description Creates a new schema for validating number values.\n * @returns {NumberSchema} A new instance of `NumberSchema` for validating numbers.\n * @example\n * const schema = number();\n * parseOrFail(schema, 42); // Validates successfully\n * parseOrFail(schema, '42'); // Throws a validation error\n *\n * @instance Of NumberSchema\n */\nexport function number(): WithBGuardType<NumberSchema, number> {\n return new NumberSchema({ type: ['number'], requiredValidations: [] }) as WithBGuardType<NumberSchema, number>;\n}\n\nexport class NumberSchema extends CommonSchema {\n protected _number = 1;\n private limit: boolean | undefined;\n\n /**\n * @method equalTo\n * @description Restricts the schema to exactly match the specified value and infers the literal value as the TypeScript type.\n * @param expectedValue - The value that the schema must exactly match.\n * @returns A new schema restricted to the specified value, with the literal value inferred as the TypeScript type\n * @example\n * number().equalTo(42); // Infers the type 42\n *\n * @public\n */\n public equalTo<Y extends number>(expectedValue: Y): WithBGuardType<this, Y> {\n if (this.limit) throw new BuildSchemaError(ONLY_ONCE);\n // custom() returns the copy, so the strict type and the once-only flag are set on it. Setting\n // them on `this` first would refine the schema this one was derived from.\n const next = this.custom(equalTo(expectedValue));\n next.limit = true;\n _setStrictType(next, expectedValue);\n return next as WithBGuardType<this, Y>;\n }\n\n /**\n * @method oneOfValues\n * @description Restricts the schema to match one of the specified values and infers the union of those values as the TypeScript type.\n * @param expectedValues - An array of values that the schema can match.\n * @returns A new schema restricted to one of the specified values, with the union of those values inferred as the TypeScript type.\n * @example\n * number().oneOfValues([5, 7]); // Infers the type 5 | 7\n *\n * @public\n */\n public oneOfValues<Y extends number>(expectedValue: Y[]): WithBGuardType<this, Y> {\n if (this.limit) throw new BuildSchemaError(ONLY_ONCE);\n const next = this.custom(oneOfValues(expectedValue));\n next.limit = true;\n _setStrictType(next, expectedValue);\n return next as WithBGuardType<this, Y>;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAkBO,SAAS,SAA+C;AAC7D,SAAO,IAAI,aAAa,EAAE,MAAM,CAAC,QAAQ,GAAG,qBAAqB,CAAC,EAAE,CAAC;AACvE;AAEO,IAAM,eAAN,cAA2B,aAAa;AAAA,EACnC,UAAU;AAAA,EACZ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYD,QAA0B,eAA2C;AAC1E,QAAI,KAAK,MAAO,OAAM,IAAI,iBAAiB,SAAS;AAGpD,UAAM,OAAO,KAAK,OAAO,QAAQ,aAAa,CAAC;AAC/C,SAAK,QAAQ;AACb,mBAAe,MAAM,aAAa;AAClC,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYO,YAA8B,eAA6C;AAChF,QAAI,KAAK,MAAO,OAAM,IAAI,iBAAiB,SAAS;AACpD,UAAM,OAAO,KAAK,OAAO,YAAY,aAAa,CAAC;AACnD,SAAK,QAAQ;AACb,mBAAe,MAAM,aAAa;AAClC,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _class;
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkOPA6AXSHjs = require('./chunk-OPA6AXSH.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunk3D6TPN7Fjs = require('./chunk-3D6TPN7F.js');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
var _chunkEEKYR5IAjs = require('./chunk-EEKYR5IA.js');
|
|
@@ -75,5 +75,6 @@ var StringSchema = (_class = class extends _chunk6LUSV3SSjs.CommonSchema {constr
|
|
|
75
75
|
|
|
76
76
|
|
|
77
77
|
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
|
|
79
|
+
exports.string = string; exports.StringSchema = StringSchema;
|
|
80
|
+
//# sourceMappingURL=chunk-EI6TQG4L.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-EI6TQG4L.js","../src/asserts/string/index.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;AACE;AACF,sDAA4B;AAC5B;AACA;ACHO,SAAS,MAAA,CAAA,EAA+C;AAC7D,EAAA,OAAO,IAAI,YAAA,CAAa,EAAE,IAAA,EAAM,CAAC,QAAQ,CAAA,EAAG,mBAAA,EAAqB,CAAC,EAAE,CAAC,CAAA;AACvE;AAEO,IAAM,aAAA,YAAN,MAAA,QAA2B,8BAAa;AAAA,iBACnC,QAAA,EAAU,EAAA;AAAA,EACZ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYD,OAAA,CAA0B,aAAA,EAA2C;AAC1E,IAAA,IAAA,CAAK,UAAA,CAAW,CAAA;AAGhB,IAAA,MAAM,KAAA,EAAO,IAAA,CAAK,MAAA,CAAO,sCAAA,aAAqB,CAAC,CAAA;AAC/C,IAAA,IAAA,CAAK,MAAA,EAAQ,IAAA;AACb,IAAA,6CAAA,IAAe,EAAM,kDAAA,aAAiC,CAAC,CAAA;AACvD,IAAA,OAAO,IAAA;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYO,WAAA,CAA8B,aAAA,EAA6C;AAChF,IAAA,IAAA,CAAK,UAAA,CAAW,CAAA;AAChB,IAAA,MAAM,KAAA,EAAO,IAAA,CAAK,MAAA,CAAO,0CAAA,aAAyB,CAAC,CAAA;AACnD,IAAA,IAAA,CAAK,MAAA,EAAQ,IAAA;AACb,IAAA,6CAAA;AAAA,MACE,IAAA;AAAA,MACA,aAAA,CAAc,GAAA,CAAI,CAAC,EAAA,EAAA,GAAO,kDAAA,EAAsB,CAAC;AAAA,IACnD,CAAA;AACA,IAAA,OAAO,IAAA;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA,EAMQ,UAAA,CAAA,EAAa;AACnB,IAAA,GAAA,CAAI,IAAA,CAAK,KAAA,EAAO,MAAM,IAAI,sCAAA,CAAiB,0BAAS,CAAA;AAAA,EACtD;AACF,UAAA;ADDA;AACA;AACE;AACA;AACF,6DAAC","file":"/home/runner/work/bguard/bguard/lib/chunk-EI6TQG4L.js","sourcesContent":[null,"import { WithBGuardType } from '../../commonTypes';\nimport { BuildSchemaError } from '../../exceptions';\nimport { ONLY_ONCE } from '../../helpers/constants';\nimport { CommonSchema } from '../../core';\nimport { _setStrictType } from '../../helpers/setStrictType';\nimport { _quoteStringLiteral } from '../../helpers/quoteStringLiteral';\nimport { equalTo } from '../mix/equalTo';\nimport { oneOfValues } from '../mix/oneOfValues';\n\n/**\n * @description Creates a new schema for validating string values.\n * @returns {WithBGuardType<StringSchema, string>} A new instance of `StringSchema` for validating strings.\n * @example\n * const schema = string();\n * parseOrFail(schema, 'hello'); // Validates successfully\n * parseOrFail(schema, 123); // Throws a validation error\n *\n * @instance Of StringSchema\n */\nexport function string(): WithBGuardType<StringSchema, string> {\n return new StringSchema({ type: ['string'], requiredValidations: [] }) as WithBGuardType<StringSchema, string>;\n}\n\nexport class StringSchema extends CommonSchema {\n protected _string = 1;\n private limit: boolean | undefined;\n\n /**\n * @method equalTo\n * @description Restricts the schema to exactly match the specified value and infers the literal value as the TypeScript type.\n * @param expectedValue - The value that the schema must exactly match.\n * @returns A new schema restricted to the specified value, with the literal value inferred as the TypeScript type\n * @example\n * string().equalTo('hello'); // Infers the type 'hello'\n *\n * @public\n */\n public equalTo<Y extends string>(expectedValue: Y): WithBGuardType<this, Y> {\n this.limitGuard();\n // custom() returns the copy, so the strict type and the once-only flag are set on it. Setting\n // them on `this` first would refine the schema this one was derived from.\n const next = this.custom(equalTo(expectedValue));\n next.limit = true;\n _setStrictType(next, _quoteStringLiteral(expectedValue));\n return next as WithBGuardType<this, Y>;\n }\n\n /**\n * @method oneOfValues\n * @description Restricts the schema to match one of the specified values and infers the union of those values as the TypeScript type.\n * @param expectedValues - An array of values that the schema can match.\n * @returns A new schema restricted to one of the specified values, with the union of those values inferred as the TypeScript type.\n * @example\n * string().oneOfValues(['foo', 'bar']); // Infers the type 'foo' | 'bar'\n *\n * @public\n */\n public oneOfValues<Y extends string>(expectedValue: Y[]): WithBGuardType<this, Y> {\n this.limitGuard();\n const next = this.custom(oneOfValues(expectedValue));\n next.limit = true;\n _setStrictType(\n next,\n expectedValue.map((el) => _quoteStringLiteral(el)),\n );\n return next as WithBGuardType<this, Y>;\n }\n\n /**\n * Reads the once-only flag without setting it. The flag belongs on the schema that `custom`\n * returns, not on the one it was derived from.\n */\n private limitGuard() {\n if (this.limit) throw new BuildSchemaError(ONLY_ONCE);\n }\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
bigint
|
|
3
|
+
} from "./chunk-5PXMSVTE.mjs";
|
|
4
|
+
|
|
5
|
+
// src/asserts/coerce/bigint.ts
|
|
6
|
+
var coerceBigInt = () => bigint().transformBeforeValidation((received) => {
|
|
7
|
+
if (received === null || typeof received === "bigint") return received;
|
|
8
|
+
try {
|
|
9
|
+
return BigInt(received);
|
|
10
|
+
} catch {
|
|
11
|
+
return received;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export {
|
|
16
|
+
coerceBigInt
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=chunk-ET2I4EXQ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/asserts/coerce/bigint.ts"],"sourcesContent":["import { bigint } from '../bigint/index';\n\n/**\n * A coercing transform must never throw: it runs before validation, and throwing would replace a clear\n * validation error with an unexplained failure. Anything it cannot convert is passed through unchanged\n * so that validation reports the type problem itself.\n *\n * `null` is never coerced, so `nullable()` still decides whether it is allowed rather than it becoming\n * the string `'null'` or the number `0`.\n *\n * The return type is inferred rather than written out. Naming it flattened the schema to\n * `CommonSchema`, which silently dropped the methods only the concrete classes define — `equalTo`,\n * `oneOfValues`, `onlyTrue`, `onlyFalse`.\n */\n/**\n * @description Coerces the received value to a bigint before validating it.\n *\n * `BigInt` throws on a value it cannot read, so the original is kept for validation to reject rather\n * than the error escaping.\n *\n * @returns A bigint schema that accepts `unknown` as its input type.\n * @example\n * parseOrFail(coerceBigInt(), '42'); // 42n\n */\nexport const coerceBigInt = () =>\n bigint().transformBeforeValidation<unknown>((received) => {\n if (received === null || typeof received === 'bigint') return received as bigint;\n\n try {\n return BigInt(received as string | number);\n } catch {\n return received as bigint;\n }\n });\n"],"mappings":";;;;;AAwBO,IAAM,eAAe,MAC1B,OAAO,EAAE,0BAAmC,CAAC,aAAa;AACxD,MAAI,aAAa,QAAQ,OAAO,aAAa,SAAU,QAAO;AAE9D,MAAI;AACF,WAAO,OAAO,QAA2B;AAAA,EAC3C,QAAQ;AACN,WAAO;AAAA,EACT;AACF,CAAC;","names":[]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
boolean
|
|
3
|
+
} from "./chunk-KGXWQ3XP.mjs";
|
|
4
|
+
|
|
5
|
+
// src/asserts/coerce/boolean.ts
|
|
6
|
+
var coerceBoolean = () => boolean().transformBeforeValidation((received) => {
|
|
7
|
+
if (typeof received === "string") {
|
|
8
|
+
const lowered = received.toLowerCase();
|
|
9
|
+
if (lowered === "true") return true;
|
|
10
|
+
if (lowered === "false") return false;
|
|
11
|
+
}
|
|
12
|
+
if (received === 1) return true;
|
|
13
|
+
if (received === 0) return false;
|
|
14
|
+
return received;
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export {
|
|
18
|
+
coerceBoolean
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=chunk-FA3S35LQ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/asserts/coerce/boolean.ts"],"sourcesContent":["import { boolean } from '../boolean/index';\n\n/**\n * A coercing transform must never throw: it runs before validation, and throwing would replace a clear\n * validation error with an unexplained failure. Anything it cannot convert is passed through unchanged\n * so that validation reports the type problem itself.\n *\n * `null` is never coerced, so `nullable()` still decides whether it is allowed rather than it becoming\n * the string `'null'` or the number `0`.\n *\n * The return type is inferred rather than written out. Naming it flattened the schema to\n * `CommonSchema`, which silently dropped the methods only the concrete classes define — `equalTo`,\n * `oneOfValues`, `onlyTrue`, `onlyFalse`.\n */\n/**\n * @description Coerces the received value to a boolean before validating it.\n *\n * Only the values that unambiguously mean a boolean are converted: the strings `'true'` and `'false'`\n * in any case, and the numbers `1` and `0`. Everything else is left for validation to reject.\n *\n * Deliberately narrower than passing the value through `Boolean`, which would accept every input and\n * quietly read `'false'` as `true`.\n *\n * @returns A boolean schema that accepts `unknown` as its input type.\n * @example\n * parseOrFail(coerceBoolean(), 'false'); // false\n */\nexport const coerceBoolean = () =>\n boolean().transformBeforeValidation<unknown>((received) => {\n if (typeof received === 'string') {\n const lowered = received.toLowerCase();\n if (lowered === 'true') return true;\n if (lowered === 'false') return false;\n }\n\n if (received === 1) return true;\n if (received === 0) return false;\n\n return received as boolean;\n });\n"],"mappings":";;;;;AA2BO,IAAM,gBAAgB,MAC3B,QAAQ,EAAE,0BAAmC,CAAC,aAAa;AACzD,MAAI,OAAO,aAAa,UAAU;AAChC,UAAM,UAAU,SAAS,YAAY;AACrC,QAAI,YAAY,OAAQ,QAAO;AAC/B,QAAI,YAAY,QAAS,QAAO;AAAA,EAClC;AAEA,MAAI,aAAa,EAAG,QAAO;AAC3B,MAAI,aAAa,EAAG,QAAO;AAE3B,SAAO;AACT,CAAC;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/asserts/date/index.ts"],"sourcesContent":["import { WithBGuardType } from '../../commonTypes';\nimport { ctxSymbol } from '../../helpers/constants';\nimport { CommonSchema, ValidatorContext } from '../../core';\n\n/**\n * @description Creates a new schema for validating date values.\n * @returns {WithBGuardType<DateSchema, Date>} A new instance of `DateSchema` for validating booleans.\n * @example\n * const schema = date();\n * parseOrFail(schema, true); // Validates successfully\n * parseOrFail(schema, 'true'); // Throws a validation error\n *\n * @instance Of DateSchema\n */\nexport function date(): WithBGuardType<DateSchema, Date> {\n return new DateSchema({ type: ['object'], requiredValidations: [] }) as WithBGuardType<DateSchema, Date>;\n}\n\
|
|
1
|
+
{"version":3,"sources":["../src/asserts/date/index.ts"],"sourcesContent":["import { WithBGuardType } from '../../commonTypes';\nimport { ctxSymbol } from '../../helpers/constants';\nimport { CommonSchema, ValidatorContext } from '../../core';\n\n/**\n * @description Creates a new schema for validating date values.\n * @returns {WithBGuardType<DateSchema, Date>} A new instance of `DateSchema` for validating booleans.\n * @example\n * const schema = date();\n * parseOrFail(schema, true); // Validates successfully\n * parseOrFail(schema, 'true'); // Throws a validation error\n *\n * @instance Of DateSchema\n */\nexport function date(): WithBGuardType<DateSchema, Date> {\n return new DateSchema({ type: ['object'], requiredValidations: [] }) as WithBGuardType<DateSchema, Date>;\n}\n\nexport class DateSchema extends CommonSchema {\n protected _date = 1;\n\n constructor(ctx: ValidatorContext) {\n super(ctx);\n this[ctxSymbol].date = true;\n }\n}\n"],"mappings":";;;;;;;;AAcO,SAAS,OAAyC;AACvD,SAAO,IAAI,WAAW,EAAE,MAAM,CAAC,QAAQ,GAAG,qBAAqB,CAAC,EAAE,CAAC;AACrE;AAEO,IAAM,aAAN,cAAyB,aAAa;AAAA,EACjC,QAAQ;AAAA,EAElB,YAAY,KAAuB;AACjC,UAAM,GAAG;AACT,SAAK,SAAS,EAAE,OAAO;AAAA,EACzB;AACF;","names":[]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkWLZZTIOVjs = require('./chunk-WLZZTIOV.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunk56TWNROCjs = require('./chunk-56TWNROC.js');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var _chunkK7CDOU6Fjs = require('./chunk-K7CDOU6F.js');
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var _chunkJCX2TB7Ejs = require('./chunk-JCX2TB7E.js');
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
var _chunkTD3Y3IV3js = require('./chunk-TD3Y3IV3.js');
|
|
16
|
+
|
|
17
|
+
// src/asserts/coerce/index.ts
|
|
18
|
+
var coerce = {
|
|
19
|
+
string: _chunkTD3Y3IV3js.coerceString,
|
|
20
|
+
number: _chunkJCX2TB7Ejs.coerceNumber,
|
|
21
|
+
boolean: _chunk56TWNROCjs.coerceBoolean,
|
|
22
|
+
bigint: _chunkWLZZTIOVjs.coerceBigInt,
|
|
23
|
+
date: _chunkK7CDOU6Fjs.coerceDate
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
exports.coerce = coerce;
|
|
29
|
+
//# sourceMappingURL=chunk-HU5SDECP.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-HU5SDECP.js","../src/asserts/coerce/index.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACA;ACYO,IAAM,OAAA,EAAS;AAAA,EACpB,MAAA,EAAQ,6BAAA;AAAA,EACR,MAAA,EAAQ,6BAAA;AAAA,EACR,OAAA,EAAS,8BAAA;AAAA,EACT,MAAA,EAAQ,6BAAA;AAAA,EACR,IAAA,EAAM;AACR,CAAA;ADVA;AACA;AACE;AACF,wBAAC","file":"/home/runner/work/bguard/bguard/lib/chunk-HU5SDECP.js","sourcesContent":[null,"import { coerceBigInt } from './bigint';\nimport { coerceBoolean } from './boolean';\nimport { coerceDate } from './date';\nimport { coerceNumber } from './number';\nimport { coerceString } from './string';\n\nexport { coerceBigInt } from './bigint';\nexport { coerceBoolean } from './boolean';\nexport { coerceDate } from './date';\nexport { coerceNumber } from './number';\nexport { coerceString } from './string';\n\n/**\n * The coercing schemas gathered under one name, for when reaching for several of them reads better than\n * five imports.\n *\n * Note that this object references all five, so a bundler has to keep all five wherever it is used —\n * importing it for `coerce.number()` alone still pulls in the string, boolean, bigint and date schemas.\n * Import the one you need from its own module when that matters:\n *\n * ```typescript\n * import { coerceNumber } from 'bguard/coerce/number';\n * ```\n *\n * @example\n * const querySchema = object({ page: coerce.number().default(1), q: coerce.string() });\n * parseOrFail(querySchema, { page: '3', q: 'shoes' }); // { page: 3, q: 'shoes' }\n */\nexport const coerce = {\n string: coerceString,\n number: coerceNumber,\n boolean: coerceBoolean,\n bigint: coerceBigInt,\n date: coerceDate,\n};\n"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
oneOfValues
|
|
3
|
-
} from "./chunk-D42AL6CN.mjs";
|
|
4
1
|
import {
|
|
5
2
|
equalTo
|
|
6
3
|
} from "./chunk-YQP44G45.mjs";
|
|
4
|
+
import {
|
|
5
|
+
oneOfValues
|
|
6
|
+
} from "./chunk-D42AL6CN.mjs";
|
|
7
7
|
import {
|
|
8
8
|
_quoteStringLiteral
|
|
9
9
|
} from "./chunk-POPLWPM4.mjs";
|
|
@@ -74,6 +74,7 @@ var StringSchema = class extends CommonSchema {
|
|
|
74
74
|
};
|
|
75
75
|
|
|
76
76
|
export {
|
|
77
|
-
string
|
|
77
|
+
string,
|
|
78
|
+
StringSchema
|
|
78
79
|
};
|
|
79
|
-
//# sourceMappingURL=chunk-
|
|
80
|
+
//# sourceMappingURL=chunk-J3EKIWPZ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/asserts/string/index.ts"],"sourcesContent":["import { WithBGuardType } from '../../commonTypes';\nimport { BuildSchemaError } from '../../exceptions';\nimport { ONLY_ONCE } from '../../helpers/constants';\nimport { CommonSchema } from '../../core';\nimport { _setStrictType } from '../../helpers/setStrictType';\nimport { _quoteStringLiteral } from '../../helpers/quoteStringLiteral';\nimport { equalTo } from '../mix/equalTo';\nimport { oneOfValues } from '../mix/oneOfValues';\n\n/**\n * @description Creates a new schema for validating string values.\n * @returns {WithBGuardType<StringSchema, string>} A new instance of `StringSchema` for validating strings.\n * @example\n * const schema = string();\n * parseOrFail(schema, 'hello'); // Validates successfully\n * parseOrFail(schema, 123); // Throws a validation error\n *\n * @instance Of StringSchema\n */\nexport function string(): WithBGuardType<StringSchema, string> {\n return new StringSchema({ type: ['string'], requiredValidations: [] }) as WithBGuardType<StringSchema, string>;\n}\n\nexport class StringSchema extends CommonSchema {\n protected _string = 1;\n private limit: boolean | undefined;\n\n /**\n * @method equalTo\n * @description Restricts the schema to exactly match the specified value and infers the literal value as the TypeScript type.\n * @param expectedValue - The value that the schema must exactly match.\n * @returns A new schema restricted to the specified value, with the literal value inferred as the TypeScript type\n * @example\n * string().equalTo('hello'); // Infers the type 'hello'\n *\n * @public\n */\n public equalTo<Y extends string>(expectedValue: Y): WithBGuardType<this, Y> {\n this.limitGuard();\n // custom() returns the copy, so the strict type and the once-only flag are set on it. Setting\n // them on `this` first would refine the schema this one was derived from.\n const next = this.custom(equalTo(expectedValue));\n next.limit = true;\n _setStrictType(next, _quoteStringLiteral(expectedValue));\n return next as WithBGuardType<this, Y>;\n }\n\n /**\n * @method oneOfValues\n * @description Restricts the schema to match one of the specified values and infers the union of those values as the TypeScript type.\n * @param expectedValues - An array of values that the schema can match.\n * @returns A new schema restricted to one of the specified values, with the union of those values inferred as the TypeScript type.\n * @example\n * string().oneOfValues(['foo', 'bar']); // Infers the type 'foo' | 'bar'\n *\n * @public\n */\n public oneOfValues<Y extends string>(expectedValue: Y[]): WithBGuardType<this, Y> {\n this.limitGuard();\n const next = this.custom(oneOfValues(expectedValue));\n next.limit = true;\n _setStrictType(\n next,\n expectedValue.map((el) => _quoteStringLiteral(el)),\n );\n return next as WithBGuardType<this, Y>;\n }\n\n /**\n * Reads the once-only flag without setting it. The flag belongs on the schema that `custom`\n * returns, not on the one it was derived from.\n */\n private limitGuard() {\n if (this.limit) throw new BuildSchemaError(ONLY_ONCE);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAmBO,SAAS,SAA+C;AAC7D,SAAO,IAAI,aAAa,EAAE,MAAM,CAAC,QAAQ,GAAG,qBAAqB,CAAC,EAAE,CAAC;AACvE;AAEO,IAAM,eAAN,cAA2B,aAAa;AAAA,EACnC,UAAU;AAAA,EACZ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYD,QAA0B,eAA2C;AAC1E,SAAK,WAAW;AAGhB,UAAM,OAAO,KAAK,OAAO,QAAQ,aAAa,CAAC;AAC/C,SAAK,QAAQ;AACb,mBAAe,MAAM,oBAAoB,aAAa,CAAC;AACvD,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYO,YAA8B,eAA6C;AAChF,SAAK,WAAW;AAChB,UAAM,OAAO,KAAK,OAAO,YAAY,aAAa,CAAC;AACnD,SAAK,QAAQ;AACb;AAAA,MACE;AAAA,MACA,cAAc,IAAI,CAAC,OAAO,oBAAoB,EAAE,CAAC;AAAA,IACnD;AACA,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA,EAMQ,aAAa;AACnB,QAAI,KAAK,MAAO,OAAM,IAAI,iBAAiB,SAAS;AAAA,EACtD;AACF;","names":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunk4PPMVVQYjs = require('./chunk-4PPMVVQY.js');
|
|
4
|
+
|
|
5
|
+
// src/asserts/coerce/number.ts
|
|
6
|
+
var coerceNumber = () => _chunk4PPMVVQYjs.number.call(void 0, ).transformBeforeValidation(
|
|
7
|
+
(received) => received === null || typeof received === "number" ? received : Number(received)
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
exports.coerceNumber = coerceNumber;
|
|
13
|
+
//# sourceMappingURL=chunk-JCX2TB7E.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-JCX2TB7E.js","../src/asserts/coerce/number.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACA;ACqBO,IAAM,aAAA,EAAe,CAAA,EAAA,GAC1B,qCAAA,CAAO,CAAE,yBAAA;AAAA,EAAmC,CAAC,QAAA,EAAA,GAC3C,SAAA,IAAa,KAAA,GAAQ,OAAO,SAAA,IAAa,SAAA,EAAY,SAAA,EAAsB,MAAA,CAAO,QAAQ;AAC5F,CAAA;ADpBF;AACA;AACE;AACF,oCAAC","file":"/home/runner/work/bguard/bguard/lib/chunk-JCX2TB7E.js","sourcesContent":[null,"import { number } from '../number/index';\n\n/**\n * A coercing transform must never throw: it runs before validation, and throwing would replace a clear\n * validation error with an unexplained failure. Anything it cannot convert is passed through unchanged\n * so that validation reports the type problem itself.\n *\n * `null` is never coerced, so `nullable()` still decides whether it is allowed rather than it becoming\n * the string `'null'` or the number `0`.\n *\n * The return type is inferred rather than written out. Naming it flattened the schema to\n * `CommonSchema`, which silently dropped the methods only the concrete classes define — `equalTo`,\n * `oneOfValues`, `onlyTrue`, `onlyFalse`.\n */\n/**\n * @description Coerces the received value to a number before validating it. Anything that is not\n * already a number is passed through `Number`.\n *\n * A value `Number` cannot read becomes `NaN`, which `number()` rejects, so `'abc'` fails validation\n * rather than passing as a number.\n *\n * @returns A number schema that accepts `unknown` as its input type.\n * @example\n * parseOrFail(coerceNumber(), '42'); // 42\n */\nexport const coerceNumber = () =>\n number().transformBeforeValidation<unknown>((received) =>\n received === null || typeof received === 'number' ? (received as number) : Number(received),\n );\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkYPOEO3UFjs = require('./chunk-YPOEO3UF.js');
|
|
4
|
+
|
|
5
|
+
// src/asserts/coerce/date.ts
|
|
6
|
+
var coerceDate = () => _chunkYPOEO3UFjs.date.call(void 0, ).transformBeforeValidation(
|
|
7
|
+
(received) => received === null || received instanceof Date ? received : new Date(received)
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
exports.coerceDate = coerceDate;
|
|
13
|
+
//# sourceMappingURL=chunk-K7CDOU6F.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-K7CDOU6F.js","../src/asserts/coerce/date.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACA;ACoBO,IAAM,WAAA,EAAa,CAAA,EAAA,GACxB,mCAAA,CAAK,CAAE,yBAAA;AAAA,EAAmC,CAAC,QAAA,EAAA,GACzC,SAAA,IAAa,KAAA,GAAQ,SAAA,WAAoB,KAAA,EAAQ,SAAA,EAAoB,IAAI,IAAA,CAAK,QAAkB;AAClG,CAAA;ADnBF;AACA;AACE;AACF,gCAAC","file":"/home/runner/work/bguard/bguard/lib/chunk-K7CDOU6F.js","sourcesContent":[null,"import { date } from '../date/index';\n\n/**\n * A coercing transform must never throw: it runs before validation, and throwing would replace a clear\n * validation error with an unexplained failure. Anything it cannot convert is passed through unchanged\n * so that validation reports the type problem itself.\n *\n * `null` is never coerced, so `nullable()` still decides whether it is allowed rather than it becoming\n * the string `'null'` or the number `0`.\n *\n * The return type is inferred rather than written out. Naming it flattened the schema to\n * `CommonSchema`, which silently dropped the methods only the concrete classes define — `equalTo`,\n * `oneOfValues`, `onlyTrue`, `onlyFalse`.\n */\n/**\n * @description Coerces the received value to a Date before validating it. Anything that is not already\n * a Date is passed through `new Date`.\n *\n * An unreadable value becomes an invalid Date, which `date()` rejects.\n *\n * @returns A date schema that accepts `unknown` as its input type.\n * @example\n * parseOrFail(coerceDate(), '2024-01-01'); // Date\n */\nexport const coerceDate = () =>\n date().transformBeforeValidation<unknown>((received) =>\n received === null || received instanceof Date ? (received as Date) : new Date(received as string),\n );\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
coerceBigInt
|
|
3
|
+
} from "./chunk-ET2I4EXQ.mjs";
|
|
4
|
+
import {
|
|
5
|
+
coerceBoolean
|
|
6
|
+
} from "./chunk-FA3S35LQ.mjs";
|
|
7
|
+
import {
|
|
8
|
+
coerceDate
|
|
9
|
+
} from "./chunk-MUXY6Q45.mjs";
|
|
10
|
+
import {
|
|
11
|
+
coerceNumber
|
|
12
|
+
} from "./chunk-UCY3HEYZ.mjs";
|
|
13
|
+
import {
|
|
14
|
+
coerceString
|
|
15
|
+
} from "./chunk-SBNUNRI3.mjs";
|
|
16
|
+
|
|
17
|
+
// src/asserts/coerce/index.ts
|
|
18
|
+
var coerce = {
|
|
19
|
+
string: coerceString,
|
|
20
|
+
number: coerceNumber,
|
|
21
|
+
boolean: coerceBoolean,
|
|
22
|
+
bigint: coerceBigInt,
|
|
23
|
+
date: coerceDate
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export {
|
|
27
|
+
coerce
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=chunk-KALHMMEN.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/asserts/coerce/index.ts"],"sourcesContent":["import { coerceBigInt } from './bigint';\nimport { coerceBoolean } from './boolean';\nimport { coerceDate } from './date';\nimport { coerceNumber } from './number';\nimport { coerceString } from './string';\n\nexport { coerceBigInt } from './bigint';\nexport { coerceBoolean } from './boolean';\nexport { coerceDate } from './date';\nexport { coerceNumber } from './number';\nexport { coerceString } from './string';\n\n/**\n * The coercing schemas gathered under one name, for when reaching for several of them reads better than\n * five imports.\n *\n * Note that this object references all five, so a bundler has to keep all five wherever it is used —\n * importing it for `coerce.number()` alone still pulls in the string, boolean, bigint and date schemas.\n * Import the one you need from its own module when that matters:\n *\n * ```typescript\n * import { coerceNumber } from 'bguard/coerce/number';\n * ```\n *\n * @example\n * const querySchema = object({ page: coerce.number().default(1), q: coerce.string() });\n * parseOrFail(querySchema, { page: '3', q: 'shoes' }); // { page: 3, q: 'shoes' }\n */\nexport const coerce = {\n string: coerceString,\n number: coerceNumber,\n boolean: coerceBoolean,\n bigint: coerceBigInt,\n date: coerceDate,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AA4BO,IAAM,SAAS;AAAA,EACpB,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,MAAM;AACR;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/asserts/boolean/index.ts"],"sourcesContent":["import { WithBGuardType } from '../../commonTypes';\nimport { CommonSchema, type ExceptionContext, type RequiredValidation } from '../../core';\nimport { _setStrictType } from '../../helpers/setStrictType';\nimport { BuildSchemaError } from '../../exceptions';\nimport { ONLY_ONCE } from '../../helpers/constants';\n\n// Declared over `unknown` rather than `boolean`: it is applied from inside the class, where `this`\n// is still polymorphic, so the schema's own value type cannot be resolved yet. The comparison is\n// identity-based, so widening the parameter costs nothing.\nconst isBoolean =\n (expected: boolean): RequiredValidation<unknown> =>\n (received: unknown, ctx: ExceptionContext) => {\n if (received !== expected) ctx.addIssue(expected, received, 'c:isBoolean');\n };\n\n/**\n * @description Creates a new schema for validating boolean values.\n * @returns {WithBGuardType<BooleanSchema, boolean>} A new instance of `BooleanSchema` for validating booleans.\n * @example\n * const schema = boolean();\n * parseOrFail(schema, true); // Validates successfully\n * parseOrFail(schema, 'true'); // Throws a validation error\n *\n * @instance Of BooleanSchema\n */\nexport function boolean(): WithBGuardType<BooleanSchema, boolean> {\n return new BooleanSchema({ type: ['boolean'], requiredValidations: [] }) as WithBGuardType<BooleanSchema, boolean>;\n}\n\nexport class BooleanSchema extends CommonSchema {\n protected _boolean = 1;\n private limit: boolean | undefined;\n\n /**\n * Reads the once-only flag without setting it, matching the string, number and bigint schemas.\n * Without it, onlyTrue().onlyFalse() built a schema that rejects both true and false.\n */\n private limitGuard() {\n if (this.limit) throw new BuildSchemaError(ONLY_ONCE);\n }\n\n /**\n * @method onlyTrue\n * @description Restricts the schema to exactly match the boolean value true and infers the true value as the TypeScript type.\n * @returns A new schema restricted to the value true, with the true value inferred as the TypeScript type\n * @example\n * boolean().onlyTrue(); // Infers the type true\n *\n * @public\n */\n public onlyTrue(): WithBGuardType<this, true> {\n this.limitGuard();\n const next = this.custom(isBoolean(true));\n next.limit = true;\n _setStrictType(next, true);\n return next as WithBGuardType<this, true>;\n }\n\n /**\n * @method onlyFalse\n * @description Restricts the schema to exactly match the boolean value false and infers the false value as the TypeScript type.\n * @returns A new schema restricted to the value false, with the false value inferred as the TypeScript type\n * @example\n * boolean().onlyFalse(); // Infers the type false\n *\n * @public\n */\n public onlyFalse(): WithBGuardType<this, false> {\n this.limitGuard();\n const next = this.custom(isBoolean(false));\n next.limit = true;\n _setStrictType(next, false);\n return next as WithBGuardType<this, false>;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AASA,IAAM,YACJ,CAAC,aACD,CAAC,UAAmB,QAA0B;AAC5C,MAAI,aAAa,SAAU,KAAI,SAAS,UAAU,UAAU,aAAa;AAC3E;AAYK,SAAS,UAAkD;AAChE,SAAO,IAAI,cAAc,EAAE,MAAM,CAAC,SAAS,GAAG,qBAAqB,CAAC,EAAE,CAAC;AACzE;AAEO,IAAM,gBAAN,cAA4B,aAAa;AAAA,EACpC,WAAW;AAAA,EACb;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,aAAa;AACnB,QAAI,KAAK,MAAO,OAAM,IAAI,iBAAiB,SAAS;AAAA,EACtD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWO,WAAuC;AAC5C,SAAK,WAAW;AAChB,UAAM,OAAO,KAAK,OAAO,UAAU,IAAI,CAAC;AACxC,SAAK,QAAQ;AACb,mBAAe,MAAM,IAAI;AACzB,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWO,YAAyC;AAC9C,SAAK,WAAW;AAChB,UAAM,OAAO,KAAK,OAAO,UAAU,KAAK,CAAC;AACzC,SAAK,QAAQ;AACb,mBAAe,MAAM,KAAK;AAC1B,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
date
|
|
3
|
+
} from "./chunk-FU5WAVRB.mjs";
|
|
4
|
+
|
|
5
|
+
// src/asserts/coerce/date.ts
|
|
6
|
+
var coerceDate = () => date().transformBeforeValidation(
|
|
7
|
+
(received) => received === null || received instanceof Date ? received : new Date(received)
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
export {
|
|
11
|
+
coerceDate
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=chunk-MUXY6Q45.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/asserts/coerce/date.ts"],"sourcesContent":["import { date } from '../date/index';\n\n/**\n * A coercing transform must never throw: it runs before validation, and throwing would replace a clear\n * validation error with an unexplained failure. Anything it cannot convert is passed through unchanged\n * so that validation reports the type problem itself.\n *\n * `null` is never coerced, so `nullable()` still decides whether it is allowed rather than it becoming\n * the string `'null'` or the number `0`.\n *\n * The return type is inferred rather than written out. Naming it flattened the schema to\n * `CommonSchema`, which silently dropped the methods only the concrete classes define — `equalTo`,\n * `oneOfValues`, `onlyTrue`, `onlyFalse`.\n */\n/**\n * @description Coerces the received value to a Date before validating it. Anything that is not already\n * a Date is passed through `new Date`.\n *\n * An unreadable value becomes an invalid Date, which `date()` rejects.\n *\n * @returns A date schema that accepts `unknown` as its input type.\n * @example\n * parseOrFail(coerceDate(), '2024-01-01'); // Date\n */\nexport const coerceDate = () =>\n date().transformBeforeValidation<unknown>((received) =>\n received === null || received instanceof Date ? (received as Date) : new Date(received as string),\n );\n"],"mappings":";;;;;AAwBO,IAAM,aAAa,MACxB,KAAK,EAAE;AAAA,EAAmC,CAAC,aACzC,aAAa,QAAQ,oBAAoB,OAAQ,WAAoB,IAAI,KAAK,QAAkB;AAClG;","names":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
string
|
|
3
|
+
} from "./chunk-J3EKIWPZ.mjs";
|
|
4
|
+
|
|
5
|
+
// src/asserts/coerce/string.ts
|
|
6
|
+
var coerceString = () => string().transformBeforeValidation(
|
|
7
|
+
(received) => received === null || typeof received === "string" ? received : String(received)
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
export {
|
|
11
|
+
coerceString
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=chunk-SBNUNRI3.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/asserts/coerce/string.ts"],"sourcesContent":["import { string } from '../string/index';\n\n/**\n * A coercing transform must never throw: it runs before validation, and throwing would replace a clear\n * validation error with an unexplained failure. Anything it cannot convert is passed through unchanged\n * so that validation reports the type problem itself.\n *\n * `null` is never coerced, so `nullable()` still decides whether it is allowed rather than it becoming\n * the string `'null'` or the number `0`.\n *\n * The return type is inferred rather than written out. Naming it flattened the schema to\n * `CommonSchema`, which silently dropped the methods only the concrete classes define — `equalTo`,\n * `oneOfValues`, `onlyTrue`, `onlyFalse`.\n */\n/**\n * @description Coerces the received value to a string before validating it. Anything that is not\n * already a string is passed through `String`.\n *\n * @returns A string schema that accepts `unknown` as its input type.\n * @example\n * parseOrFail(coerceString(), 42); // '42'\n */\nexport const coerceString = () =>\n string().transformBeforeValidation<unknown>((received) =>\n received === null || typeof received === 'string' ? (received as string) : String(received),\n );\n"],"mappings":";;;;;AAsBO,IAAM,eAAe,MAC1B,OAAO,EAAE;AAAA,EAAmC,CAAC,aAC3C,aAAa,QAAQ,OAAO,aAAa,WAAY,WAAsB,OAAO,QAAQ;AAC5F;","names":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkEI6TQG4Ljs = require('./chunk-EI6TQG4L.js');
|
|
4
|
+
|
|
5
|
+
// src/asserts/coerce/string.ts
|
|
6
|
+
var coerceString = () => _chunkEI6TQG4Ljs.string.call(void 0, ).transformBeforeValidation(
|
|
7
|
+
(received) => received === null || typeof received === "string" ? received : String(received)
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
exports.coerceString = coerceString;
|
|
13
|
+
//# sourceMappingURL=chunk-TD3Y3IV3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-TD3Y3IV3.js","../src/asserts/coerce/string.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACA;ACkBO,IAAM,aAAA,EAAe,CAAA,EAAA,GAC1B,qCAAA,CAAO,CAAE,yBAAA;AAAA,EAAmC,CAAC,QAAA,EAAA,GAC3C,SAAA,IAAa,KAAA,GAAQ,OAAO,SAAA,IAAa,SAAA,EAAY,SAAA,EAAsB,MAAA,CAAO,QAAQ;AAC5F,CAAA;ADjBF;AACA;AACE;AACF,oCAAC","file":"/home/runner/work/bguard/bguard/lib/chunk-TD3Y3IV3.js","sourcesContent":[null,"import { string } from '../string/index';\n\n/**\n * A coercing transform must never throw: it runs before validation, and throwing would replace a clear\n * validation error with an unexplained failure. Anything it cannot convert is passed through unchanged\n * so that validation reports the type problem itself.\n *\n * `null` is never coerced, so `nullable()` still decides whether it is allowed rather than it becoming\n * the string `'null'` or the number `0`.\n *\n * The return type is inferred rather than written out. Naming it flattened the schema to\n * `CommonSchema`, which silently dropped the methods only the concrete classes define — `equalTo`,\n * `oneOfValues`, `onlyTrue`, `onlyFalse`.\n */\n/**\n * @description Coerces the received value to a string before validating it. Anything that is not\n * already a string is passed through `String`.\n *\n * @returns A string schema that accepts `unknown` as its input type.\n * @example\n * parseOrFail(coerceString(), 42); // '42'\n */\nexport const coerceString = () =>\n string().transformBeforeValidation<unknown>((received) =>\n received === null || typeof received === 'string' ? (received as string) : String(received),\n );\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
number
|
|
3
|
+
} from "./chunk-DS2LUTTF.mjs";
|
|
4
|
+
|
|
5
|
+
// src/asserts/coerce/number.ts
|
|
6
|
+
var coerceNumber = () => number().transformBeforeValidation(
|
|
7
|
+
(received) => received === null || typeof received === "number" ? received : Number(received)
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
export {
|
|
11
|
+
coerceNumber
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=chunk-UCY3HEYZ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/asserts/coerce/number.ts"],"sourcesContent":["import { number } from '../number/index';\n\n/**\n * A coercing transform must never throw: it runs before validation, and throwing would replace a clear\n * validation error with an unexplained failure. Anything it cannot convert is passed through unchanged\n * so that validation reports the type problem itself.\n *\n * `null` is never coerced, so `nullable()` still decides whether it is allowed rather than it becoming\n * the string `'null'` or the number `0`.\n *\n * The return type is inferred rather than written out. Naming it flattened the schema to\n * `CommonSchema`, which silently dropped the methods only the concrete classes define — `equalTo`,\n * `oneOfValues`, `onlyTrue`, `onlyFalse`.\n */\n/**\n * @description Coerces the received value to a number before validating it. Anything that is not\n * already a number is passed through `Number`.\n *\n * A value `Number` cannot read becomes `NaN`, which `number()` rejects, so `'abc'` fails validation\n * rather than passing as a number.\n *\n * @returns A number schema that accepts `unknown` as its input type.\n * @example\n * parseOrFail(coerceNumber(), '42'); // 42\n */\nexport const coerceNumber = () =>\n number().transformBeforeValidation<unknown>((received) =>\n received === null || typeof received === 'number' ? (received as number) : Number(received),\n );\n"],"mappings":";;;;;AAyBO,IAAM,eAAe,MAC1B,OAAO,EAAE;AAAA,EAAmC,CAAC,aAC3C,aAAa,QAAQ,OAAO,aAAa,WAAY,WAAsB,OAAO,QAAQ;AAC5F;","names":[]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _class;
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkOPA6AXSHjs = require('./chunk-OPA6AXSH.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunk3D6TPN7Fjs = require('./chunk-3D6TPN7F.js');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
var _chunkFTHEF6SBjs = require('./chunk-FTHEF6SB.js');
|
|
@@ -74,5 +74,6 @@ var BigIntSchema = (_class = class extends _chunk6LUSV3SSjs.CommonSchema {constr
|
|
|
74
74
|
|
|
75
75
|
|
|
76
76
|
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
|
|
78
|
+
exports.bigint = bigint; exports.BigIntSchema = BigIntSchema;
|
|
79
|
+
//# sourceMappingURL=chunk-WH7WJMFF.js.map
|