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
package/README.md
CHANGED
|
@@ -722,29 +722,47 @@ message that came from `address.street`. `treeifyErrors` keeps the full structur
|
|
|
722
722
|
For input that does not arrive already typed — query strings, form data, environment variables.
|
|
723
723
|
|
|
724
724
|
```typeScript
|
|
725
|
-
import {
|
|
725
|
+
import { coerceNumber } from 'bguard/coerce/number';
|
|
726
|
+
import { coerceBoolean } from 'bguard/coerce/boolean';
|
|
726
727
|
import { object } from 'bguard/object';
|
|
727
728
|
import { parseOrFail } from 'bguard';
|
|
728
729
|
|
|
729
730
|
const querySchema = object({
|
|
730
|
-
page:
|
|
731
|
-
limit:
|
|
732
|
-
active:
|
|
731
|
+
page: coerceNumber().default(1),
|
|
732
|
+
limit: coerceNumber(),
|
|
733
|
+
active: coerceBoolean(),
|
|
733
734
|
});
|
|
734
735
|
|
|
735
736
|
parseOrFail(querySchema, { limit: '20', active: 'true' });
|
|
736
737
|
// { page: 1, limit: 20, active: true }
|
|
737
738
|
```
|
|
738
739
|
|
|
739
|
-
`
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
740
|
+
`coerceString`, `coerceNumber`, `coerceBoolean`, `coerceBigInt` and `coerceDate` convert the value
|
|
741
|
+
before validating it. Each lives in its own module — `bguard/coerce/number` and so on — like every other
|
|
742
|
+
assertion in the package.
|
|
743
|
+
|
|
744
|
+
They are also gathered on a `coerce` object for when several read better together:
|
|
745
|
+
|
|
746
|
+
```typeScript
|
|
747
|
+
import { coerce } from 'bguard/coerce';
|
|
748
|
+
import { object } from 'bguard/object';
|
|
749
|
+
|
|
750
|
+
object({ page: coerce.number(), q: coerce.string() });
|
|
751
|
+
```
|
|
752
|
+
|
|
753
|
+
> **Notice:** that object references all five, so a bundler has to keep all five wherever it is used.
|
|
754
|
+
> Reaching for `coerce.number()` alone still pulls in the string, boolean, bigint and date schemas —
|
|
755
|
+
> measured at 2033 bytes against 87 for importing `coerceNumber` from its own module. Import the one you
|
|
756
|
+
> need when bundle size matters.
|
|
757
|
+
|
|
758
|
+
Anything a helper cannot convert is left alone, so validation reports the type problem rather than the conversion silently
|
|
759
|
+
succeeding: `coerceNumber()` on `'abc'` fails, because `Number('abc')` is `NaN` and `number()` rejects
|
|
760
|
+
that.
|
|
743
761
|
|
|
744
762
|
`null` is never coerced, so `nullable()` still decides whether it is allowed instead of it becoming the
|
|
745
763
|
string `'null'` or the number `0`.
|
|
746
764
|
|
|
747
|
-
> **Notice:** `
|
|
765
|
+
> **Notice:** `coerceBoolean()` only converts what unambiguously means a boolean — the strings
|
|
748
766
|
> `'true'` and `'false'` in any case, and the numbers `1` and `0`. Everything else is rejected. This is
|
|
749
767
|
> deliberately narrower than passing the value through `Boolean`, which would accept every input and
|
|
750
768
|
> read `'false'` as `true`.
|
|
@@ -755,12 +773,12 @@ string `'null'` or the number `0`.
|
|
|
755
773
|
*accepts*. The two differ wherever a schema converts or supplies something:
|
|
756
774
|
|
|
757
775
|
```typeScript
|
|
758
|
-
import {
|
|
776
|
+
import { coerceNumber } from 'bguard/coerce/number';
|
|
759
777
|
import { object } from 'bguard/object';
|
|
760
778
|
import { string } from 'bguard/string';
|
|
761
779
|
import type { InferType, InferInput } from 'bguard/InferType';
|
|
762
780
|
|
|
763
|
-
const schema = object({ page:
|
|
781
|
+
const schema = object({ page: coerceNumber().default(1), q: string() });
|
|
764
782
|
|
|
765
783
|
type Output = InferType<typeof schema>; // { page: number; q: string }
|
|
766
784
|
type Input = InferInput<typeof schema>; // { q: string; page?: unknown }
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
var _chunkAGB5RWYDjs = require('../../chunk-AGB5RWYD.js');
|
|
4
5
|
require('../../chunk-6LUSV3SS.js');
|
|
5
6
|
require('../../chunk-ZJGY6EOE.js');
|
|
6
7
|
require('../../chunk-VBTWYDEM.js');
|
|
@@ -8,5 +9,6 @@ require('../../chunk-LHEU4XAC.js');
|
|
|
8
9
|
require('../../chunk-ZWFSAKQK.js');
|
|
9
10
|
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
|
|
13
|
+
exports.ArraySchema = _chunkAGB5RWYDjs.ArraySchema; exports.array = _chunkAGB5RWYDjs.array;
|
|
12
14
|
//# 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,mCAAgC;AAChC;AACE;AACF,
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/asserts/array/index.js"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,0DAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC;AACE;AACA;AACF,2FAAC","file":"/home/runner/work/bguard/bguard/lib/asserts/array/index.js"}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
|
+
ArraySchema,
|
|
2
3
|
array
|
|
3
|
-
} from "../../chunk-
|
|
4
|
+
} from "../../chunk-A2LPSUNQ.mjs";
|
|
4
5
|
import "../../chunk-LDZFOOWN.mjs";
|
|
5
6
|
import "../../chunk-65X7NTUS.mjs";
|
|
6
7
|
import "../../chunk-YBVMP4EI.mjs";
|
|
7
8
|
import "../../chunk-C76DLZFD.mjs";
|
|
8
9
|
import "../../chunk-O2WD4JBG.mjs";
|
|
9
10
|
export {
|
|
11
|
+
ArraySchema,
|
|
10
12
|
array
|
|
11
13
|
};
|
|
12
14
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
require('../../chunk-
|
|
3
|
+
|
|
4
|
+
var _chunkWH7WJMFFjs = require('../../chunk-WH7WJMFF.js');
|
|
5
5
|
require('../../chunk-OPA6AXSH.js');
|
|
6
|
+
require('../../chunk-3D6TPN7F.js');
|
|
6
7
|
require('../../chunk-FTHEF6SB.js');
|
|
7
8
|
require('../../chunk-6LUSV3SS.js');
|
|
8
9
|
require('../../chunk-ZJGY6EOE.js');
|
|
@@ -11,5 +12,6 @@ require('../../chunk-LHEU4XAC.js');
|
|
|
11
12
|
require('../../chunk-ZWFSAKQK.js');
|
|
12
13
|
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
|
|
16
|
+
exports.BigIntSchema = _chunkWH7WJMFFjs.BigIntSchema; exports.bigint = _chunkWH7WJMFFjs.bigint;
|
|
15
17
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/asserts/bigint/index.js"],"names":[],"mappings":"AAAA;AACE;AACF,0DAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC;AACE;AACF
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/asserts/bigint/index.js"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,0DAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC;AACE;AACA;AACF,+FAAC","file":"/home/runner/work/bguard/bguard/lib/asserts/bigint/index.js"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
+
BigIntSchema,
|
|
2
3
|
bigint
|
|
3
|
-
} from "../../chunk-
|
|
4
|
-
import "../../chunk-D42AL6CN.mjs";
|
|
4
|
+
} from "../../chunk-5PXMSVTE.mjs";
|
|
5
5
|
import "../../chunk-YQP44G45.mjs";
|
|
6
|
+
import "../../chunk-D42AL6CN.mjs";
|
|
6
7
|
import "../../chunk-IIL6D2UL.mjs";
|
|
7
8
|
import "../../chunk-LDZFOOWN.mjs";
|
|
8
9
|
import "../../chunk-65X7NTUS.mjs";
|
|
@@ -10,6 +11,7 @@ import "../../chunk-YBVMP4EI.mjs";
|
|
|
10
11
|
import "../../chunk-C76DLZFD.mjs";
|
|
11
12
|
import "../../chunk-O2WD4JBG.mjs";
|
|
12
13
|
export {
|
|
14
|
+
BigIntSchema,
|
|
13
15
|
bigint
|
|
14
16
|
};
|
|
15
17
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
var _chunk23R5R7PLjs = require('../../chunk-23R5R7PL.js');
|
|
4
5
|
require('../../chunk-FTHEF6SB.js');
|
|
5
6
|
require('../../chunk-6LUSV3SS.js');
|
|
6
7
|
require('../../chunk-ZJGY6EOE.js');
|
|
@@ -9,5 +10,6 @@ require('../../chunk-LHEU4XAC.js');
|
|
|
9
10
|
require('../../chunk-ZWFSAKQK.js');
|
|
10
11
|
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
|
|
14
|
+
exports.BooleanSchema = _chunk23R5R7PLjs.BooleanSchema; exports.boolean = _chunk23R5R7PLjs.boolean;
|
|
13
15
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/asserts/boolean/index.js"],"names":[],"mappings":"AAAA;AACE;AACF,0DAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC;AACE;AACF,
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/asserts/boolean/index.js"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,0DAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC;AACE;AACA;AACF,mGAAC","file":"/home/runner/work/bguard/bguard/lib/asserts/boolean/index.js"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
+
BooleanSchema,
|
|
2
3
|
boolean
|
|
3
|
-
} from "../../chunk-
|
|
4
|
+
} from "../../chunk-KGXWQ3XP.mjs";
|
|
4
5
|
import "../../chunk-IIL6D2UL.mjs";
|
|
5
6
|
import "../../chunk-LDZFOOWN.mjs";
|
|
6
7
|
import "../../chunk-65X7NTUS.mjs";
|
|
@@ -8,6 +9,7 @@ import "../../chunk-YBVMP4EI.mjs";
|
|
|
8
9
|
import "../../chunk-C76DLZFD.mjs";
|
|
9
10
|
import "../../chunk-O2WD4JBG.mjs";
|
|
10
11
|
export {
|
|
12
|
+
BooleanSchema,
|
|
11
13
|
boolean
|
|
12
14
|
};
|
|
13
15
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { WithInput, WithBGuardType } from '../../commonTypes.mjs';
|
|
2
|
+
import { BigIntSchema } from '../bigint/index.mjs';
|
|
3
|
+
import '../../core.mjs';
|
|
4
|
+
import '../../InferType.mjs';
|
|
5
|
+
import '../../helpers/constants.mjs';
|
|
6
|
+
import '../../standardSchema.mjs';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A coercing transform must never throw: it runs before validation, and throwing would replace a clear
|
|
10
|
+
* validation error with an unexplained failure. Anything it cannot convert is passed through unchanged
|
|
11
|
+
* so that validation reports the type problem itself.
|
|
12
|
+
*
|
|
13
|
+
* `null` is never coerced, so `nullable()` still decides whether it is allowed rather than it becoming
|
|
14
|
+
* the string `'null'` or the number `0`.
|
|
15
|
+
*
|
|
16
|
+
* The return type is inferred rather than written out. Naming it flattened the schema to
|
|
17
|
+
* `CommonSchema`, which silently dropped the methods only the concrete classes define — `equalTo`,
|
|
18
|
+
* `oneOfValues`, `onlyTrue`, `onlyFalse`.
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* @description Coerces the received value to a bigint before validating it.
|
|
22
|
+
*
|
|
23
|
+
* `BigInt` throws on a value it cannot read, so the original is kept for validation to reject rather
|
|
24
|
+
* than the error escaping.
|
|
25
|
+
*
|
|
26
|
+
* @returns A bigint schema that accepts `unknown` as its input type.
|
|
27
|
+
* @example
|
|
28
|
+
* parseOrFail(coerceBigInt(), '42'); // 42n
|
|
29
|
+
*/
|
|
30
|
+
declare const coerceBigInt: () => WithInput<WithBGuardType<BigIntSchema, bigint>, unknown>;
|
|
31
|
+
|
|
32
|
+
export { coerceBigInt };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { WithInput, WithBGuardType } from '../../commonTypes.js';
|
|
2
|
+
import { BigIntSchema } from '../bigint/index.js';
|
|
3
|
+
import '../../core.js';
|
|
4
|
+
import '../../InferType.js';
|
|
5
|
+
import '../../helpers/constants.js';
|
|
6
|
+
import '../../standardSchema.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A coercing transform must never throw: it runs before validation, and throwing would replace a clear
|
|
10
|
+
* validation error with an unexplained failure. Anything it cannot convert is passed through unchanged
|
|
11
|
+
* so that validation reports the type problem itself.
|
|
12
|
+
*
|
|
13
|
+
* `null` is never coerced, so `nullable()` still decides whether it is allowed rather than it becoming
|
|
14
|
+
* the string `'null'` or the number `0`.
|
|
15
|
+
*
|
|
16
|
+
* The return type is inferred rather than written out. Naming it flattened the schema to
|
|
17
|
+
* `CommonSchema`, which silently dropped the methods only the concrete classes define — `equalTo`,
|
|
18
|
+
* `oneOfValues`, `onlyTrue`, `onlyFalse`.
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* @description Coerces the received value to a bigint before validating it.
|
|
22
|
+
*
|
|
23
|
+
* `BigInt` throws on a value it cannot read, so the original is kept for validation to reject rather
|
|
24
|
+
* than the error escaping.
|
|
25
|
+
*
|
|
26
|
+
* @returns A bigint schema that accepts `unknown` as its input type.
|
|
27
|
+
* @example
|
|
28
|
+
* parseOrFail(coerceBigInt(), '42'); // 42n
|
|
29
|
+
*/
|
|
30
|
+
declare const coerceBigInt: () => WithInput<WithBGuardType<BigIntSchema, bigint>, unknown>;
|
|
31
|
+
|
|
32
|
+
export { coerceBigInt };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkWLZZTIOVjs = require('../../chunk-WLZZTIOV.js');
|
|
4
|
+
require('../../chunk-WH7WJMFF.js');
|
|
5
|
+
require('../../chunk-OPA6AXSH.js');
|
|
6
|
+
require('../../chunk-3D6TPN7F.js');
|
|
7
|
+
require('../../chunk-FTHEF6SB.js');
|
|
8
|
+
require('../../chunk-6LUSV3SS.js');
|
|
9
|
+
require('../../chunk-ZJGY6EOE.js');
|
|
10
|
+
require('../../chunk-VBTWYDEM.js');
|
|
11
|
+
require('../../chunk-LHEU4XAC.js');
|
|
12
|
+
require('../../chunk-ZWFSAKQK.js');
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
exports.coerceBigInt = _chunkWLZZTIOVjs.coerceBigInt;
|
|
16
|
+
//# sourceMappingURL=bigint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/asserts/coerce/bigint.js"],"names":[],"mappings":"AAAA;AACE;AACF,0DAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC;AACE;AACF,qDAAC","file":"/home/runner/work/bguard/bguard/lib/asserts/coerce/bigint.js"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
coerceBigInt
|
|
3
|
+
} from "../../chunk-ET2I4EXQ.mjs";
|
|
4
|
+
import "../../chunk-5PXMSVTE.mjs";
|
|
5
|
+
import "../../chunk-YQP44G45.mjs";
|
|
6
|
+
import "../../chunk-D42AL6CN.mjs";
|
|
7
|
+
import "../../chunk-IIL6D2UL.mjs";
|
|
8
|
+
import "../../chunk-LDZFOOWN.mjs";
|
|
9
|
+
import "../../chunk-65X7NTUS.mjs";
|
|
10
|
+
import "../../chunk-YBVMP4EI.mjs";
|
|
11
|
+
import "../../chunk-C76DLZFD.mjs";
|
|
12
|
+
import "../../chunk-O2WD4JBG.mjs";
|
|
13
|
+
export {
|
|
14
|
+
coerceBigInt
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=bigint.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { WithInput, WithBGuardType } from '../../commonTypes.mjs';
|
|
2
|
+
import { BooleanSchema } from '../boolean/index.mjs';
|
|
3
|
+
import '../../core.mjs';
|
|
4
|
+
import '../../InferType.mjs';
|
|
5
|
+
import '../../helpers/constants.mjs';
|
|
6
|
+
import '../../standardSchema.mjs';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A coercing transform must never throw: it runs before validation, and throwing would replace a clear
|
|
10
|
+
* validation error with an unexplained failure. Anything it cannot convert is passed through unchanged
|
|
11
|
+
* so that validation reports the type problem itself.
|
|
12
|
+
*
|
|
13
|
+
* `null` is never coerced, so `nullable()` still decides whether it is allowed rather than it becoming
|
|
14
|
+
* the string `'null'` or the number `0`.
|
|
15
|
+
*
|
|
16
|
+
* The return type is inferred rather than written out. Naming it flattened the schema to
|
|
17
|
+
* `CommonSchema`, which silently dropped the methods only the concrete classes define — `equalTo`,
|
|
18
|
+
* `oneOfValues`, `onlyTrue`, `onlyFalse`.
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* @description Coerces the received value to a boolean before validating it.
|
|
22
|
+
*
|
|
23
|
+
* Only the values that unambiguously mean a boolean are converted: the strings `'true'` and `'false'`
|
|
24
|
+
* in any case, and the numbers `1` and `0`. Everything else is left for validation to reject.
|
|
25
|
+
*
|
|
26
|
+
* Deliberately narrower than passing the value through `Boolean`, which would accept every input and
|
|
27
|
+
* quietly read `'false'` as `true`.
|
|
28
|
+
*
|
|
29
|
+
* @returns A boolean schema that accepts `unknown` as its input type.
|
|
30
|
+
* @example
|
|
31
|
+
* parseOrFail(coerceBoolean(), 'false'); // false
|
|
32
|
+
*/
|
|
33
|
+
declare const coerceBoolean: () => WithInput<WithBGuardType<BooleanSchema, boolean>, unknown>;
|
|
34
|
+
|
|
35
|
+
export { coerceBoolean };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { WithInput, WithBGuardType } from '../../commonTypes.js';
|
|
2
|
+
import { BooleanSchema } from '../boolean/index.js';
|
|
3
|
+
import '../../core.js';
|
|
4
|
+
import '../../InferType.js';
|
|
5
|
+
import '../../helpers/constants.js';
|
|
6
|
+
import '../../standardSchema.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A coercing transform must never throw: it runs before validation, and throwing would replace a clear
|
|
10
|
+
* validation error with an unexplained failure. Anything it cannot convert is passed through unchanged
|
|
11
|
+
* so that validation reports the type problem itself.
|
|
12
|
+
*
|
|
13
|
+
* `null` is never coerced, so `nullable()` still decides whether it is allowed rather than it becoming
|
|
14
|
+
* the string `'null'` or the number `0`.
|
|
15
|
+
*
|
|
16
|
+
* The return type is inferred rather than written out. Naming it flattened the schema to
|
|
17
|
+
* `CommonSchema`, which silently dropped the methods only the concrete classes define — `equalTo`,
|
|
18
|
+
* `oneOfValues`, `onlyTrue`, `onlyFalse`.
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* @description Coerces the received value to a boolean before validating it.
|
|
22
|
+
*
|
|
23
|
+
* Only the values that unambiguously mean a boolean are converted: the strings `'true'` and `'false'`
|
|
24
|
+
* in any case, and the numbers `1` and `0`. Everything else is left for validation to reject.
|
|
25
|
+
*
|
|
26
|
+
* Deliberately narrower than passing the value through `Boolean`, which would accept every input and
|
|
27
|
+
* quietly read `'false'` as `true`.
|
|
28
|
+
*
|
|
29
|
+
* @returns A boolean schema that accepts `unknown` as its input type.
|
|
30
|
+
* @example
|
|
31
|
+
* parseOrFail(coerceBoolean(), 'false'); // false
|
|
32
|
+
*/
|
|
33
|
+
declare const coerceBoolean: () => WithInput<WithBGuardType<BooleanSchema, boolean>, unknown>;
|
|
34
|
+
|
|
35
|
+
export { coerceBoolean };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunk56TWNROCjs = require('../../chunk-56TWNROC.js');
|
|
4
|
+
require('../../chunk-23R5R7PL.js');
|
|
5
|
+
require('../../chunk-FTHEF6SB.js');
|
|
6
|
+
require('../../chunk-6LUSV3SS.js');
|
|
7
|
+
require('../../chunk-ZJGY6EOE.js');
|
|
8
|
+
require('../../chunk-VBTWYDEM.js');
|
|
9
|
+
require('../../chunk-LHEU4XAC.js');
|
|
10
|
+
require('../../chunk-ZWFSAKQK.js');
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
exports.coerceBoolean = _chunk56TWNROCjs.coerceBoolean;
|
|
14
|
+
//# sourceMappingURL=boolean.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/asserts/coerce/boolean.js"],"names":[],"mappings":"AAAA;AACE;AACF,0DAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC;AACE;AACF,uDAAC","file":"/home/runner/work/bguard/bguard/lib/asserts/coerce/boolean.js"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {
|
|
2
|
+
coerceBoolean
|
|
3
|
+
} from "../../chunk-FA3S35LQ.mjs";
|
|
4
|
+
import "../../chunk-KGXWQ3XP.mjs";
|
|
5
|
+
import "../../chunk-IIL6D2UL.mjs";
|
|
6
|
+
import "../../chunk-LDZFOOWN.mjs";
|
|
7
|
+
import "../../chunk-65X7NTUS.mjs";
|
|
8
|
+
import "../../chunk-YBVMP4EI.mjs";
|
|
9
|
+
import "../../chunk-C76DLZFD.mjs";
|
|
10
|
+
import "../../chunk-O2WD4JBG.mjs";
|
|
11
|
+
export {
|
|
12
|
+
coerceBoolean
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=boolean.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { WithInput, WithBGuardType } from '../../commonTypes.mjs';
|
|
2
|
+
import { DateSchema } from '../date/index.mjs';
|
|
3
|
+
import '../../core.mjs';
|
|
4
|
+
import '../../InferType.mjs';
|
|
5
|
+
import '../../helpers/constants.mjs';
|
|
6
|
+
import '../../standardSchema.mjs';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A coercing transform must never throw: it runs before validation, and throwing would replace a clear
|
|
10
|
+
* validation error with an unexplained failure. Anything it cannot convert is passed through unchanged
|
|
11
|
+
* so that validation reports the type problem itself.
|
|
12
|
+
*
|
|
13
|
+
* `null` is never coerced, so `nullable()` still decides whether it is allowed rather than it becoming
|
|
14
|
+
* the string `'null'` or the number `0`.
|
|
15
|
+
*
|
|
16
|
+
* The return type is inferred rather than written out. Naming it flattened the schema to
|
|
17
|
+
* `CommonSchema`, which silently dropped the methods only the concrete classes define — `equalTo`,
|
|
18
|
+
* `oneOfValues`, `onlyTrue`, `onlyFalse`.
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* @description Coerces the received value to a Date before validating it. Anything that is not already
|
|
22
|
+
* a Date is passed through `new Date`.
|
|
23
|
+
*
|
|
24
|
+
* An unreadable value becomes an invalid Date, which `date()` rejects.
|
|
25
|
+
*
|
|
26
|
+
* @returns A date schema that accepts `unknown` as its input type.
|
|
27
|
+
* @example
|
|
28
|
+
* parseOrFail(coerceDate(), '2024-01-01'); // Date
|
|
29
|
+
*/
|
|
30
|
+
declare const coerceDate: () => WithInput<WithBGuardType<DateSchema, Date>, unknown>;
|
|
31
|
+
|
|
32
|
+
export { coerceDate };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { WithInput, WithBGuardType } from '../../commonTypes.js';
|
|
2
|
+
import { DateSchema } from '../date/index.js';
|
|
3
|
+
import '../../core.js';
|
|
4
|
+
import '../../InferType.js';
|
|
5
|
+
import '../../helpers/constants.js';
|
|
6
|
+
import '../../standardSchema.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A coercing transform must never throw: it runs before validation, and throwing would replace a clear
|
|
10
|
+
* validation error with an unexplained failure. Anything it cannot convert is passed through unchanged
|
|
11
|
+
* so that validation reports the type problem itself.
|
|
12
|
+
*
|
|
13
|
+
* `null` is never coerced, so `nullable()` still decides whether it is allowed rather than it becoming
|
|
14
|
+
* the string `'null'` or the number `0`.
|
|
15
|
+
*
|
|
16
|
+
* The return type is inferred rather than written out. Naming it flattened the schema to
|
|
17
|
+
* `CommonSchema`, which silently dropped the methods only the concrete classes define — `equalTo`,
|
|
18
|
+
* `oneOfValues`, `onlyTrue`, `onlyFalse`.
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* @description Coerces the received value to a Date before validating it. Anything that is not already
|
|
22
|
+
* a Date is passed through `new Date`.
|
|
23
|
+
*
|
|
24
|
+
* An unreadable value becomes an invalid Date, which `date()` rejects.
|
|
25
|
+
*
|
|
26
|
+
* @returns A date schema that accepts `unknown` as its input type.
|
|
27
|
+
* @example
|
|
28
|
+
* parseOrFail(coerceDate(), '2024-01-01'); // Date
|
|
29
|
+
*/
|
|
30
|
+
declare const coerceDate: () => WithInput<WithBGuardType<DateSchema, Date>, unknown>;
|
|
31
|
+
|
|
32
|
+
export { coerceDate };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkK7CDOU6Fjs = require('../../chunk-K7CDOU6F.js');
|
|
4
|
+
require('../../chunk-YPOEO3UF.js');
|
|
5
|
+
require('../../chunk-6LUSV3SS.js');
|
|
6
|
+
require('../../chunk-ZJGY6EOE.js');
|
|
7
|
+
require('../../chunk-VBTWYDEM.js');
|
|
8
|
+
require('../../chunk-LHEU4XAC.js');
|
|
9
|
+
require('../../chunk-ZWFSAKQK.js');
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
exports.coerceDate = _chunkK7CDOU6Fjs.coerceDate;
|
|
13
|
+
//# sourceMappingURL=date.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/asserts/coerce/date.js"],"names":[],"mappings":"AAAA;AACE;AACF,0DAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC;AACE;AACF,iDAAC","file":"/home/runner/work/bguard/bguard/lib/asserts/coerce/date.js"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
coerceDate
|
|
3
|
+
} from "../../chunk-MUXY6Q45.mjs";
|
|
4
|
+
import "../../chunk-FU5WAVRB.mjs";
|
|
5
|
+
import "../../chunk-LDZFOOWN.mjs";
|
|
6
|
+
import "../../chunk-65X7NTUS.mjs";
|
|
7
|
+
import "../../chunk-YBVMP4EI.mjs";
|
|
8
|
+
import "../../chunk-C76DLZFD.mjs";
|
|
9
|
+
import "../../chunk-O2WD4JBG.mjs";
|
|
10
|
+
export {
|
|
11
|
+
coerceDate
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=date.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|