bguard 0.0.4 → 0.0.6
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/lib/{CommonSchema-DeTBsQhn.d.mts → CommonSchema-BIe85W_A.d.mts} +3 -1
- package/lib/{CommonSchema-DeTBsQhn.d.ts → CommonSchema-BIe85W_A.d.ts} +3 -1
- package/lib/InferType.d.mts +18 -0
- package/lib/InferType.d.ts +18 -0
- package/lib/InferType.js +1 -0
- package/lib/InferType.js.map +1 -0
- package/lib/InferType.mjs +1 -0
- package/lib/InferType.mjs.map +1 -0
- package/lib/asserts/array/index.d.mts +18 -2
- package/lib/asserts/array/index.d.ts +18 -2
- package/lib/asserts/array/index.js +7 -86
- package/lib/asserts/array/index.js.map +1 -1
- package/lib/asserts/array/index.mjs +7 -59
- package/lib/asserts/array/index.mjs.map +1 -1
- package/lib/asserts/boolean/index.d.mts +16 -2
- package/lib/asserts/boolean/index.d.ts +16 -2
- package/lib/asserts/boolean/index.js +7 -114
- package/lib/asserts/boolean/index.js.map +1 -1
- package/lib/asserts/boolean/index.mjs +7 -87
- package/lib/asserts/boolean/index.mjs.map +1 -1
- package/lib/asserts/common/equalTo.d.mts +1 -1
- package/lib/asserts/common/equalTo.d.ts +1 -1
- package/lib/asserts/common/equalTo.js +4 -50
- package/lib/asserts/common/equalTo.js.map +1 -1
- package/lib/asserts/common/equalTo.mjs +4 -23
- package/lib/asserts/common/equalTo.mjs.map +1 -1
- package/lib/asserts/common/index.d.mts +1 -1
- package/lib/asserts/common/index.d.ts +1 -1
- package/lib/asserts/common/index.js +6 -68
- package/lib/asserts/common/index.js.map +1 -1
- package/lib/asserts/common/index.mjs +6 -41
- package/lib/asserts/common/index.mjs.map +1 -1
- package/lib/asserts/number/index.d.mts +16 -2
- package/lib/asserts/number/index.d.ts +16 -2
- package/lib/asserts/number/index.js +8 -108
- package/lib/asserts/number/index.js.map +1 -1
- package/lib/asserts/number/index.mjs +8 -81
- package/lib/asserts/number/index.mjs.map +1 -1
- package/lib/asserts/number/max.d.mts +1 -1
- package/lib/asserts/number/max.d.ts +1 -1
- package/lib/asserts/number/max.js +6 -47
- package/lib/asserts/number/max.js.map +1 -1
- package/lib/asserts/number/max.mjs +3 -17
- package/lib/asserts/number/max.mjs.map +1 -1
- package/lib/asserts/number/maxExcluded.d.mts +1 -1
- package/lib/asserts/number/maxExcluded.d.ts +1 -1
- package/lib/asserts/number/maxExcluded.js +6 -47
- package/lib/asserts/number/maxExcluded.js.map +1 -1
- package/lib/asserts/number/maxExcluded.mjs +3 -17
- package/lib/asserts/number/maxExcluded.mjs.map +1 -1
- package/lib/asserts/number/min.d.mts +1 -1
- package/lib/asserts/number/min.d.ts +1 -1
- package/lib/asserts/number/min.js +6 -47
- package/lib/asserts/number/min.js.map +1 -1
- package/lib/asserts/number/min.mjs +3 -17
- package/lib/asserts/number/min.mjs.map +1 -1
- package/lib/asserts/number/minExcluded.d.mts +1 -1
- package/lib/asserts/number/minExcluded.d.ts +1 -1
- package/lib/asserts/number/minExcluded.js +6 -47
- package/lib/asserts/number/minExcluded.js.map +1 -1
- package/lib/asserts/number/minExcluded.mjs +3 -17
- package/lib/asserts/number/minExcluded.mjs.map +1 -1
- package/lib/asserts/number/negative.d.mts +1 -1
- package/lib/asserts/number/negative.d.ts +1 -1
- package/lib/asserts/number/negative.js +6 -47
- package/lib/asserts/number/negative.js.map +1 -1
- package/lib/asserts/number/negative.mjs +3 -17
- package/lib/asserts/number/negative.mjs.map +1 -1
- package/lib/asserts/number/positive.d.mts +1 -1
- package/lib/asserts/number/positive.d.ts +1 -1
- package/lib/asserts/number/positive.js +6 -47
- package/lib/asserts/number/positive.js.map +1 -1
- package/lib/asserts/number/positive.mjs +3 -17
- package/lib/asserts/number/positive.mjs.map +1 -1
- package/lib/asserts/object/index.d.mts +21 -2
- package/lib/asserts/object/index.d.ts +21 -2
- package/lib/asserts/object/index.js +7 -90
- package/lib/asserts/object/index.js.map +1 -1
- package/lib/asserts/object/index.mjs +7 -63
- package/lib/asserts/object/index.mjs.map +1 -1
- package/lib/asserts/string/email.d.mts +1 -1
- package/lib/asserts/string/email.d.ts +1 -1
- package/lib/asserts/string/email.js +6 -47
- package/lib/asserts/string/email.js.map +1 -1
- package/lib/asserts/string/email.mjs +3 -17
- package/lib/asserts/string/email.mjs.map +1 -1
- package/lib/asserts/string/index.d.mts +16 -2
- package/lib/asserts/string/index.d.ts +16 -2
- package/lib/asserts/string/index.js +8 -108
- package/lib/asserts/string/index.js.map +1 -1
- package/lib/asserts/string/index.mjs +8 -81
- package/lib/asserts/string/index.mjs.map +1 -1
- package/lib/asserts/string/maxLength.d.mts +1 -1
- package/lib/asserts/string/maxLength.d.ts +1 -1
- package/lib/asserts/string/maxLength.js +6 -47
- package/lib/asserts/string/maxLength.js.map +1 -1
- package/lib/asserts/string/maxLength.mjs +3 -17
- package/lib/asserts/string/maxLength.mjs.map +1 -1
- package/lib/asserts/string/minLength.d.mts +1 -1
- package/lib/asserts/string/minLength.d.ts +1 -1
- package/lib/asserts/string/minLength.js +6 -47
- package/lib/asserts/string/minLength.js.map +1 -1
- package/lib/asserts/string/minLength.mjs +3 -17
- package/lib/asserts/string/minLength.mjs.map +1 -1
- package/lib/asserts/string/regExp.d.mts +1 -1
- package/lib/asserts/string/regExp.d.ts +1 -1
- package/lib/asserts/string/regExp.js +6 -47
- package/lib/asserts/string/regExp.js.map +1 -1
- package/lib/asserts/string/regExp.mjs +3 -17
- package/lib/asserts/string/regExp.mjs.map +1 -1
- package/lib/chunk-2AP4OQMT.js +26 -0
- package/lib/chunk-2AP4OQMT.js.map +1 -0
- package/lib/chunk-32IQXZRK.mjs +13 -0
- package/lib/chunk-32IQXZRK.mjs.map +1 -0
- package/lib/chunk-3FEJUC3K.mjs +13 -0
- package/lib/chunk-3FEJUC3K.mjs.map +1 -0
- package/lib/chunk-5NCJN6D2.js +70 -0
- package/lib/chunk-5NCJN6D2.js.map +1 -0
- package/lib/chunk-5ZMICHV3.js +21 -0
- package/lib/chunk-5ZMICHV3.js.map +1 -0
- package/lib/chunk-63IQFNFO.mjs +27 -0
- package/lib/chunk-63IQFNFO.mjs.map +1 -0
- package/lib/chunk-A2SAWKJA.mjs +13 -0
- package/lib/chunk-A2SAWKJA.mjs.map +1 -0
- package/lib/chunk-A3UTB4RE.mjs +28 -0
- package/lib/chunk-A3UTB4RE.mjs.map +1 -0
- package/lib/chunk-A7I2JEQO.js +13 -0
- package/lib/chunk-A7I2JEQO.js.map +1 -0
- package/lib/chunk-AJ4WV5DG.mjs +13 -0
- package/lib/chunk-AJ4WV5DG.mjs.map +1 -0
- package/lib/chunk-APTTIN2L.js +42 -0
- package/lib/chunk-APTTIN2L.js.map +1 -0
- package/lib/chunk-AXOP6HPJ.js +14 -0
- package/lib/chunk-AXOP6HPJ.js.map +1 -0
- package/lib/chunk-BGMR7A6X.mjs +13 -0
- package/lib/chunk-BGMR7A6X.mjs.map +1 -0
- package/lib/chunk-FCFO5J5Y.mjs +14 -0
- package/lib/chunk-FCFO5J5Y.mjs.map +1 -0
- package/lib/chunk-GEZME6V2.mjs +39 -0
- package/lib/chunk-GEZME6V2.mjs.map +1 -0
- package/lib/chunk-GNBSKTFV.js +27 -0
- package/lib/chunk-GNBSKTFV.js.map +1 -0
- package/lib/chunk-IQ3QYABE.js +32 -0
- package/lib/chunk-IQ3QYABE.js.map +1 -0
- package/lib/chunk-K2S3FS5K.js +13 -0
- package/lib/chunk-K2S3FS5K.js.map +1 -0
- package/lib/chunk-KCBOOOTF.mjs +13 -0
- package/lib/chunk-KCBOOOTF.mjs.map +1 -0
- package/lib/chunk-L6A7NXUJ.js +13 -0
- package/lib/chunk-L6A7NXUJ.js.map +1 -0
- package/lib/chunk-L7HUXYFV.mjs +42 -0
- package/lib/chunk-L7HUXYFV.mjs.map +1 -0
- package/lib/chunk-LHTJHMKJ.mjs +27 -0
- package/lib/chunk-LHTJHMKJ.mjs.map +1 -0
- package/lib/chunk-NOADI6PO.mjs +21 -0
- package/lib/chunk-NOADI6PO.mjs.map +1 -0
- package/lib/chunk-NWY33MFU.js +13 -0
- package/lib/chunk-NWY33MFU.js.map +1 -0
- package/lib/chunk-P3Y6IWFA.mjs +70 -0
- package/lib/chunk-P3Y6IWFA.mjs.map +1 -0
- package/lib/chunk-PDVXBE27.js +27 -0
- package/lib/chunk-PDVXBE27.js.map +1 -0
- package/lib/chunk-PJP63SJT.js +13 -0
- package/lib/chunk-PJP63SJT.js.map +1 -0
- package/lib/chunk-QJOXKH7A.mjs +26 -0
- package/lib/chunk-QJOXKH7A.mjs.map +1 -0
- package/lib/chunk-QKGQ4XZC.js +13 -0
- package/lib/chunk-QKGQ4XZC.js.map +1 -0
- package/lib/chunk-QYLH5ZAC.mjs +32 -0
- package/lib/chunk-QYLH5ZAC.mjs.map +1 -0
- package/lib/chunk-VPFIIM2X.js +39 -0
- package/lib/chunk-VPFIIM2X.js.map +1 -0
- package/lib/chunk-YXHH5BF6.js +28 -0
- package/lib/chunk-YXHH5BF6.js.map +1 -0
- package/lib/core.d.mts +1 -0
- package/lib/core.d.ts +1 -0
- package/lib/core.js +10 -0
- package/lib/core.js.map +1 -0
- package/lib/core.mjs +10 -0
- package/lib/core.mjs.map +1 -0
- package/lib/exceptions.d.mts +12 -0
- package/lib/exceptions.d.ts +12 -0
- package/lib/exceptions.js +11 -0
- package/lib/exceptions.js.map +1 -0
- package/lib/exceptions.mjs +11 -0
- package/lib/exceptions.mjs.map +1 -0
- package/lib/index.d.mts +14 -51
- package/lib/index.d.ts +14 -51
- package/lib/index.js +29 -277
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +38 -253
- package/lib/index.mjs.map +1 -1
- package/lib/parseSchema.d.mts +37 -0
- package/lib/parseSchema.d.ts +37 -0
- package/lib/parseSchema.js +9 -0
- package/lib/parseSchema.js.map +1 -0
- package/lib/parseSchema.mjs +9 -0
- package/lib/parseSchema.mjs.map +1 -0
- package/lib/schemas/ArraySchema.d.mts +13 -0
- package/lib/schemas/ArraySchema.d.ts +13 -0
- package/lib/schemas/ArraySchema.js +10 -0
- package/lib/schemas/ArraySchema.js.map +1 -0
- package/lib/schemas/ArraySchema.mjs +10 -0
- package/lib/schemas/ArraySchema.mjs.map +1 -0
- package/lib/{index-nzqBrOHf.d.mts → schemas/BooleanSchema.d.mts} +2 -14
- package/lib/{index-B1yBez0g.d.ts → schemas/BooleanSchema.d.ts} +2 -14
- package/lib/schemas/BooleanSchema.js +10 -0
- package/lib/schemas/BooleanSchema.js.map +1 -0
- package/lib/schemas/BooleanSchema.mjs +10 -0
- package/lib/schemas/BooleanSchema.mjs.map +1 -0
- package/lib/schemas/CommonSchema.d.mts +1 -0
- package/lib/schemas/CommonSchema.d.ts +1 -0
- package/lib/schemas/CommonSchema.js +9 -0
- package/lib/schemas/CommonSchema.js.map +1 -0
- package/lib/schemas/CommonSchema.mjs +9 -0
- package/lib/schemas/CommonSchema.mjs.map +1 -0
- package/lib/{index-B63cXDOm.d.mts → schemas/NumberSchema.d.mts} +2 -14
- package/lib/{index-CK_g_aEC.d.ts → schemas/NumberSchema.d.ts} +2 -14
- package/lib/schemas/NumberSchema.js +11 -0
- package/lib/schemas/NumberSchema.js.map +1 -0
- package/lib/schemas/NumberSchema.mjs +11 -0
- package/lib/schemas/NumberSchema.mjs.map +1 -0
- package/lib/schemas/ObjectSchema.d.mts +12 -0
- package/lib/schemas/ObjectSchema.d.ts +12 -0
- package/lib/schemas/ObjectSchema.js +10 -0
- package/lib/schemas/ObjectSchema.js.map +1 -0
- package/lib/schemas/ObjectSchema.mjs +10 -0
- package/lib/schemas/ObjectSchema.mjs.map +1 -0
- package/lib/{index-aBEYpJdZ.d.mts → schemas/StringSchema.d.mts} +2 -14
- package/lib/{index-BEyBEBSm.d.ts → schemas/StringSchema.d.ts} +2 -14
- package/lib/schemas/StringSchema.js +11 -0
- package/lib/schemas/StringSchema.js.map +1 -0
- package/lib/schemas/StringSchema.mjs +11 -0
- package/lib/schemas/StringSchema.mjs.map +1 -0
- package/package.json +30 -28
- package/lib/index-D3R2euaT.d.mts +0 -29
- package/lib/index-DPkImfCy.d.ts +0 -29
- package/lib/index-DitgsWDO.d.ts +0 -27
- package/lib/index-T3KBmyyn.d.mts +0 -27
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
declare const ctxSymbol: unique symbol;
|
|
2
2
|
|
|
3
|
+
declare function innerCheck(schema: CommonSchema, receivedValue: unknown, pathToError: string): {} | null | undefined;
|
|
4
|
+
|
|
3
5
|
type RequiredValidation = (received: any, pathToError: string) => void;
|
|
4
6
|
type ObjectShapeSchemaType = Record<string, CommonSchema>;
|
|
5
7
|
type PrimitiveType = 'number' | 'string' | 'boolean' | 'undefined' | 'object' | 'function' | 'symbol' | 'bigint';
|
|
@@ -54,4 +56,4 @@ type WithMix<Y = unknown> = CommonSchema & {
|
|
|
54
56
|
type ExtractFromMix<T> = T extends WithMix<infer X> ? X : never;
|
|
55
57
|
type MapMixTypes<T extends PrimitiveType[]> = T extends (infer U)[] ? U extends keyof TypeMapping ? TypeMapping[U] : never : never;
|
|
56
58
|
|
|
57
|
-
export { CommonSchema as C, type ExtractFromMix as E, type MapMixTypes as M, type ObjectShapeSchemaType as O, type PrimitiveType as P, type RequiredValidation as R, type ValidatorContext as V, type WithUndefined as W, type WithNull as a, type WithMix as b };
|
|
59
|
+
export { CommonSchema as C, type ExtractFromMix as E, type MapMixTypes as M, type ObjectShapeSchemaType as O, type PrimitiveType as P, type RequiredValidation as R, type ValidatorContext as V, type WithUndefined as W, type WithNull as a, type WithMix as b, ctxSymbol as c, innerCheck as i };
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
declare const ctxSymbol: unique symbol;
|
|
2
2
|
|
|
3
|
+
declare function innerCheck(schema: CommonSchema, receivedValue: unknown, pathToError: string): {} | null | undefined;
|
|
4
|
+
|
|
3
5
|
type RequiredValidation = (received: any, pathToError: string) => void;
|
|
4
6
|
type ObjectShapeSchemaType = Record<string, CommonSchema>;
|
|
5
7
|
type PrimitiveType = 'number' | 'string' | 'boolean' | 'undefined' | 'object' | 'function' | 'symbol' | 'bigint';
|
|
@@ -54,4 +56,4 @@ type WithMix<Y = unknown> = CommonSchema & {
|
|
|
54
56
|
type ExtractFromMix<T> = T extends WithMix<infer X> ? X : never;
|
|
55
57
|
type MapMixTypes<T extends PrimitiveType[]> = T extends (infer U)[] ? U extends keyof TypeMapping ? TypeMapping[U] : never : never;
|
|
56
58
|
|
|
57
|
-
export { CommonSchema as C, type ExtractFromMix as E, type MapMixTypes as M, type ObjectShapeSchemaType as O, type PrimitiveType as P, type RequiredValidation as R, type ValidatorContext as V, type WithUndefined as W, type WithNull as a, type WithMix as b };
|
|
59
|
+
export { CommonSchema as C, type ExtractFromMix as E, type MapMixTypes as M, type ObjectShapeSchemaType as O, type PrimitiveType as P, type RequiredValidation as R, type ValidatorContext as V, type WithUndefined as W, type WithNull as a, type WithMix as b, ctxSymbol as c, innerCheck as i };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ArraySchema, ExtractFromArray } from './schemas/ArraySchema.mjs';
|
|
2
|
+
import { WithBoolean, BooleanSchema, ExtractFromBoolean } from './schemas/BooleanSchema.mjs';
|
|
3
|
+
import { W as WithUndefined, a as WithNull, b as WithMix, E as ExtractFromMix, C as CommonSchema } from './CommonSchema-BIe85W_A.mjs';
|
|
4
|
+
import { WithNumber, NumberSchema, ExtractFromNumber } from './schemas/NumberSchema.mjs';
|
|
5
|
+
import { ObjectSchema, WithObject } from './schemas/ObjectSchema.mjs';
|
|
6
|
+
import { WithString, StringSchema, ExtractFromString } from './schemas/StringSchema.mjs';
|
|
7
|
+
|
|
8
|
+
type InferType<T> = T extends WithUndefined<WithNull<WithString<StringSchema>>> ? ExtractFromString<T> | null | undefined : T extends WithUndefined<WithString<StringSchema>> ? ExtractFromString<T> | undefined : T extends WithNull<WithString<StringSchema>> ? ExtractFromString<T> | null : T extends WithString<StringSchema> ? ExtractFromString<T> : T extends WithUndefined<WithNull<StringSchema>> ? string | null | undefined : T extends WithUndefined<StringSchema> ? string | undefined : T extends WithNull<StringSchema> ? string | null : T extends StringSchema ? string : T extends WithUndefined<WithNull<WithNumber<NumberSchema>>> ? ExtractFromNumber<T> | null | undefined : T extends WithUndefined<WithNumber<NumberSchema>> ? ExtractFromNumber<T> | undefined : T extends WithNull<WithNumber<NumberSchema>> ? ExtractFromNumber<T> | null : T extends WithNumber<NumberSchema> ? ExtractFromNumber<T> : T extends WithUndefined<WithNull<NumberSchema>> ? number | null | undefined : T extends WithUndefined<NumberSchema> ? number | undefined : T extends WithNull<NumberSchema> ? number | null : T extends NumberSchema ? number : T extends WithUndefined<WithNull<WithBoolean<BooleanSchema>>> ? ExtractFromBoolean<T> | null | undefined : T extends WithUndefined<WithBoolean<BooleanSchema>> ? ExtractFromBoolean<T> | undefined : T extends WithNull<WithBoolean<BooleanSchema>> ? ExtractFromBoolean<T> | null : T extends WithBoolean<BooleanSchema> ? ExtractFromBoolean<T> : T extends WithUndefined<WithNull<BooleanSchema>> ? boolean | null | undefined : T extends WithUndefined<BooleanSchema> ? boolean | undefined : T extends WithNull<BooleanSchema> ? boolean | null : T extends BooleanSchema ? boolean : T extends WithUndefined<WithNull<ArraySchema>> ? InferType<ExtractFromArray<T>>[] | null | undefined : T extends WithUndefined<ArraySchema> ? InferType<ExtractFromArray<T>>[] | undefined : T extends WithNull<ArraySchema> ? InferType<ExtractFromArray<T>>[] | null : T extends ArraySchema ? InferType<ExtractFromArray<T>>[] : T extends WithUndefined<WithNull<ObjectSchema>> ? ExtractFromObject<T> | null | undefined : T extends WithUndefined<ObjectSchema> ? ExtractFromObject<T> | undefined : T extends WithNull<ObjectSchema> ? ExtractFromObject<T> | null : T extends ObjectSchema ? ExtractFromObject<T> : T extends WithUndefined<WithNull<WithMix>> ? ExtractFromMix<T> | null | undefined : T extends WithUndefined<WithMix> ? ExtractFromMix<T> | undefined : T extends WithNull<WithMix> ? ExtractFromMix<T> | null : T extends WithMix ? ExtractFromMix<T> : unknown;
|
|
9
|
+
type Merge<T> = T extends infer U ? {
|
|
10
|
+
[K in keyof U]: U[K];
|
|
11
|
+
} : never;
|
|
12
|
+
type ExtractFromObject<T extends ObjectSchema> = T extends WithObject<infer X> ? Merge<{
|
|
13
|
+
[K in keyof X as X[K] extends WithUndefined<CommonSchema> ? never : K]: InferType<X[K]>;
|
|
14
|
+
} & {
|
|
15
|
+
[K in keyof X as X[K] extends WithUndefined<CommonSchema> ? K : never]?: InferType<X[K]>;
|
|
16
|
+
}> : unknown;
|
|
17
|
+
|
|
18
|
+
export type { InferType };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ArraySchema, ExtractFromArray } from './schemas/ArraySchema.js';
|
|
2
|
+
import { WithBoolean, BooleanSchema, ExtractFromBoolean } from './schemas/BooleanSchema.js';
|
|
3
|
+
import { W as WithUndefined, a as WithNull, b as WithMix, E as ExtractFromMix, C as CommonSchema } from './CommonSchema-BIe85W_A.js';
|
|
4
|
+
import { WithNumber, NumberSchema, ExtractFromNumber } from './schemas/NumberSchema.js';
|
|
5
|
+
import { ObjectSchema, WithObject } from './schemas/ObjectSchema.js';
|
|
6
|
+
import { WithString, StringSchema, ExtractFromString } from './schemas/StringSchema.js';
|
|
7
|
+
|
|
8
|
+
type InferType<T> = T extends WithUndefined<WithNull<WithString<StringSchema>>> ? ExtractFromString<T> | null | undefined : T extends WithUndefined<WithString<StringSchema>> ? ExtractFromString<T> | undefined : T extends WithNull<WithString<StringSchema>> ? ExtractFromString<T> | null : T extends WithString<StringSchema> ? ExtractFromString<T> : T extends WithUndefined<WithNull<StringSchema>> ? string | null | undefined : T extends WithUndefined<StringSchema> ? string | undefined : T extends WithNull<StringSchema> ? string | null : T extends StringSchema ? string : T extends WithUndefined<WithNull<WithNumber<NumberSchema>>> ? ExtractFromNumber<T> | null | undefined : T extends WithUndefined<WithNumber<NumberSchema>> ? ExtractFromNumber<T> | undefined : T extends WithNull<WithNumber<NumberSchema>> ? ExtractFromNumber<T> | null : T extends WithNumber<NumberSchema> ? ExtractFromNumber<T> : T extends WithUndefined<WithNull<NumberSchema>> ? number | null | undefined : T extends WithUndefined<NumberSchema> ? number | undefined : T extends WithNull<NumberSchema> ? number | null : T extends NumberSchema ? number : T extends WithUndefined<WithNull<WithBoolean<BooleanSchema>>> ? ExtractFromBoolean<T> | null | undefined : T extends WithUndefined<WithBoolean<BooleanSchema>> ? ExtractFromBoolean<T> | undefined : T extends WithNull<WithBoolean<BooleanSchema>> ? ExtractFromBoolean<T> | null : T extends WithBoolean<BooleanSchema> ? ExtractFromBoolean<T> : T extends WithUndefined<WithNull<BooleanSchema>> ? boolean | null | undefined : T extends WithUndefined<BooleanSchema> ? boolean | undefined : T extends WithNull<BooleanSchema> ? boolean | null : T extends BooleanSchema ? boolean : T extends WithUndefined<WithNull<ArraySchema>> ? InferType<ExtractFromArray<T>>[] | null | undefined : T extends WithUndefined<ArraySchema> ? InferType<ExtractFromArray<T>>[] | undefined : T extends WithNull<ArraySchema> ? InferType<ExtractFromArray<T>>[] | null : T extends ArraySchema ? InferType<ExtractFromArray<T>>[] : T extends WithUndefined<WithNull<ObjectSchema>> ? ExtractFromObject<T> | null | undefined : T extends WithUndefined<ObjectSchema> ? ExtractFromObject<T> | undefined : T extends WithNull<ObjectSchema> ? ExtractFromObject<T> | null : T extends ObjectSchema ? ExtractFromObject<T> : T extends WithUndefined<WithNull<WithMix>> ? ExtractFromMix<T> | null | undefined : T extends WithUndefined<WithMix> ? ExtractFromMix<T> | undefined : T extends WithNull<WithMix> ? ExtractFromMix<T> | null : T extends WithMix ? ExtractFromMix<T> : unknown;
|
|
9
|
+
type Merge<T> = T extends infer U ? {
|
|
10
|
+
[K in keyof U]: U[K];
|
|
11
|
+
} : never;
|
|
12
|
+
type ExtractFromObject<T extends ObjectSchema> = T extends WithObject<infer X> ? Merge<{
|
|
13
|
+
[K in keyof X as X[K] extends WithUndefined<CommonSchema> ? never : K]: InferType<X[K]>;
|
|
14
|
+
} & {
|
|
15
|
+
[K in keyof X as X[K] extends WithUndefined<CommonSchema> ? K : never]?: InferType<X[K]>;
|
|
16
|
+
}> : unknown;
|
|
17
|
+
|
|
18
|
+
export type { InferType };
|
package/lib/InferType.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";//# sourceMappingURL=InferType.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/InferType.js"],"names":[],"mappings":"AAAA","file":"/home/runner/work/bguard/bguard/lib/InferType.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=InferType.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,2 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
import '../../CommonSchema-
|
|
1
|
+
import { WithArray } from '../../schemas/ArraySchema.mjs';
|
|
2
|
+
import { C as CommonSchema } from '../../CommonSchema-BIe85W_A.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Creates a new schema for validating arrays where each element must match the specified schema.
|
|
6
|
+
*
|
|
7
|
+
* @template T
|
|
8
|
+
* @param {T} arraySchema - The schema that each element of the array must match.
|
|
9
|
+
* @returns {WithArray<T>} A new instance of `ArraySchema` for validating arrays of elements that match the specified schema.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const schema = array(string());
|
|
13
|
+
* parseSchema(schema, ['hello', 'world']); // Validates successfully
|
|
14
|
+
* parseSchema(schema, ['hello', 123]); // Throws a validation error
|
|
15
|
+
*/
|
|
16
|
+
declare function array<T extends CommonSchema>(arraySchema: T): WithArray<T>;
|
|
17
|
+
|
|
18
|
+
export { array };
|
|
@@ -1,2 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
import '../../CommonSchema-
|
|
1
|
+
import { WithArray } from '../../schemas/ArraySchema.js';
|
|
2
|
+
import { C as CommonSchema } from '../../CommonSchema-BIe85W_A.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Creates a new schema for validating arrays where each element must match the specified schema.
|
|
6
|
+
*
|
|
7
|
+
* @template T
|
|
8
|
+
* @param {T} arraySchema - The schema that each element of the array must match.
|
|
9
|
+
* @returns {WithArray<T>} A new instance of `ArraySchema` for validating arrays of elements that match the specified schema.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const schema = array(string());
|
|
13
|
+
* parseSchema(schema, ['hello', 'world']); // Validates successfully
|
|
14
|
+
* parseSchema(schema, ['hello', 123]); // Throws a validation error
|
|
15
|
+
*/
|
|
16
|
+
declare function array<T extends CommonSchema>(arraySchema: T): WithArray<T>;
|
|
17
|
+
|
|
18
|
+
export { array };
|
|
@@ -1,90 +1,11 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
19
2
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
module.exports = __toCommonJS(array_exports);
|
|
3
|
+
var _chunkL6A7NXUJjs = require('../../chunk-L6A7NXUJ.js');
|
|
4
|
+
require('../../chunk-YXHH5BF6.js');
|
|
5
|
+
require('../../chunk-APTTIN2L.js');
|
|
6
|
+
require('../../chunk-5NCJN6D2.js');
|
|
7
|
+
require('../../chunk-2AP4OQMT.js');
|
|
26
8
|
|
|
27
|
-
// src/exceptions.ts
|
|
28
|
-
var BuildSchemaError = class extends Error {
|
|
29
|
-
};
|
|
30
9
|
|
|
31
|
-
|
|
32
|
-
var ctxSymbol = Symbol("contextSymbol");
|
|
33
|
-
|
|
34
|
-
// src/schemas/CommonSchema.ts
|
|
35
|
-
var CommonSchema = class {
|
|
36
|
-
[ctxSymbol];
|
|
37
|
-
constructor(ctx) {
|
|
38
|
-
this[ctxSymbol] = ctx;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* @param validators - One or more custom validation functions.
|
|
42
|
-
* @returns {this} The schema instance with the added custom validation.
|
|
43
|
-
*/
|
|
44
|
-
custom(...validators) {
|
|
45
|
-
this[ctxSymbol].requiredValidations.push(...validators);
|
|
46
|
-
return this;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Marks the schema as nullable, allowing the value to be `null`.
|
|
50
|
-
*
|
|
51
|
-
* @returns {WithNull<this>} The schema instance marked as nullable.
|
|
52
|
-
*/
|
|
53
|
-
nullable() {
|
|
54
|
-
this[ctxSymbol].isNullable = true;
|
|
55
|
-
return this;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Marks the schema as optional, allowing the value to be `undefined`.
|
|
59
|
-
*
|
|
60
|
-
* @returns {WithUndefined<this>}} The schema instance marked as optional.
|
|
61
|
-
*/
|
|
62
|
-
optional() {
|
|
63
|
-
this[ctxSymbol].isOptional = true;
|
|
64
|
-
return this;
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
// src/schemas/ArraySchema.ts
|
|
69
|
-
var ArraySchema = class extends CommonSchema {
|
|
70
|
-
_array = 1;
|
|
71
|
-
constructor(ctx, arraySchema) {
|
|
72
|
-
super(ctx);
|
|
73
|
-
this.validateArrayEntry(arraySchema);
|
|
74
|
-
this[ctxSymbol].array = arraySchema;
|
|
75
|
-
}
|
|
76
|
-
validateArrayEntry(arraySchema) {
|
|
77
|
-
if (!arraySchema) throw new BuildSchemaError("Missing schema in array method");
|
|
78
|
-
if (!(arraySchema instanceof CommonSchema)) throw new BuildSchemaError("Invalid schema in array method");
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
// src/asserts/array/index.ts
|
|
83
|
-
function array(arraySchema) {
|
|
84
|
-
return new ArraySchema({ type: [], requiredValidations: [] }, arraySchema);
|
|
85
|
-
}
|
|
86
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
87
|
-
0 && (module.exports = {
|
|
88
|
-
array
|
|
89
|
-
});
|
|
10
|
+
exports.array = _chunkL6A7NXUJjs.array;
|
|
90
11
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/asserts/array/index.js"],"names":[],"mappings":"AAAA;AACE;AACF,0DAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC,mCAAgC;AAChC;AACE;AACF,uCAAC","file":"/home/runner/work/bguard/bguard/lib/asserts/array/index.js"}
|
|
@@ -1,62 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
};
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// src/schemas/CommonSchema.ts
|
|
9
|
-
var CommonSchema = class {
|
|
10
|
-
[ctxSymbol];
|
|
11
|
-
constructor(ctx) {
|
|
12
|
-
this[ctxSymbol] = ctx;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* @param validators - One or more custom validation functions.
|
|
16
|
-
* @returns {this} The schema instance with the added custom validation.
|
|
17
|
-
*/
|
|
18
|
-
custom(...validators) {
|
|
19
|
-
this[ctxSymbol].requiredValidations.push(...validators);
|
|
20
|
-
return this;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Marks the schema as nullable, allowing the value to be `null`.
|
|
24
|
-
*
|
|
25
|
-
* @returns {WithNull<this>} The schema instance marked as nullable.
|
|
26
|
-
*/
|
|
27
|
-
nullable() {
|
|
28
|
-
this[ctxSymbol].isNullable = true;
|
|
29
|
-
return this;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Marks the schema as optional, allowing the value to be `undefined`.
|
|
33
|
-
*
|
|
34
|
-
* @returns {WithUndefined<this>}} The schema instance marked as optional.
|
|
35
|
-
*/
|
|
36
|
-
optional() {
|
|
37
|
-
this[ctxSymbol].isOptional = true;
|
|
38
|
-
return this;
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
// src/schemas/ArraySchema.ts
|
|
43
|
-
var ArraySchema = class extends CommonSchema {
|
|
44
|
-
_array = 1;
|
|
45
|
-
constructor(ctx, arraySchema) {
|
|
46
|
-
super(ctx);
|
|
47
|
-
this.validateArrayEntry(arraySchema);
|
|
48
|
-
this[ctxSymbol].array = arraySchema;
|
|
49
|
-
}
|
|
50
|
-
validateArrayEntry(arraySchema) {
|
|
51
|
-
if (!arraySchema) throw new BuildSchemaError("Missing schema in array method");
|
|
52
|
-
if (!(arraySchema instanceof CommonSchema)) throw new BuildSchemaError("Invalid schema in array method");
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
// src/asserts/array/index.ts
|
|
57
|
-
function array(arraySchema) {
|
|
58
|
-
return new ArraySchema({ type: [], requiredValidations: [] }, arraySchema);
|
|
59
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
array
|
|
3
|
+
} from "../../chunk-A2SAWKJA.mjs";
|
|
4
|
+
import "../../chunk-A3UTB4RE.mjs";
|
|
5
|
+
import "../../chunk-L7HUXYFV.mjs";
|
|
6
|
+
import "../../chunk-P3Y6IWFA.mjs";
|
|
7
|
+
import "../../chunk-QJOXKH7A.mjs";
|
|
60
8
|
export {
|
|
61
9
|
array
|
|
62
10
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,2 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
import '../../CommonSchema-
|
|
1
|
+
import { BooleanSchema } from '../../schemas/BooleanSchema.mjs';
|
|
2
|
+
import '../../CommonSchema-BIe85W_A.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Creates a new schema for validating boolean values.
|
|
6
|
+
*
|
|
7
|
+
* @returns {BooleanSchema} A new instance of `BooleanSchema` for validating booleans.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const schema = boolean();
|
|
11
|
+
* parseSchema(schema, true); // Validates successfully
|
|
12
|
+
* parseSchema(schema, 'true'); // Throws a validation error
|
|
13
|
+
*/
|
|
14
|
+
declare function boolean(): BooleanSchema;
|
|
15
|
+
|
|
16
|
+
export { boolean };
|
|
@@ -1,2 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
import '../../CommonSchema-
|
|
1
|
+
import { BooleanSchema } from '../../schemas/BooleanSchema.js';
|
|
2
|
+
import '../../CommonSchema-BIe85W_A.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Creates a new schema for validating boolean values.
|
|
6
|
+
*
|
|
7
|
+
* @returns {BooleanSchema} A new instance of `BooleanSchema` for validating booleans.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const schema = boolean();
|
|
11
|
+
* parseSchema(schema, true); // Validates successfully
|
|
12
|
+
* parseSchema(schema, 'true'); // Throws a validation error
|
|
13
|
+
*/
|
|
14
|
+
declare function boolean(): BooleanSchema;
|
|
15
|
+
|
|
16
|
+
export { boolean };
|
|
@@ -1,118 +1,11 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
19
2
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
module.exports = __toCommonJS(boolean_exports);
|
|
3
|
+
var _chunkA7I2JEQOjs = require('../../chunk-A7I2JEQO.js');
|
|
4
|
+
require('../../chunk-VPFIIM2X.js');
|
|
5
|
+
require('../../chunk-APTTIN2L.js');
|
|
6
|
+
require('../../chunk-5NCJN6D2.js');
|
|
7
|
+
require('../../chunk-2AP4OQMT.js');
|
|
26
8
|
|
|
27
|
-
// src/exceptions.ts
|
|
28
|
-
var ValidationError = class extends Error {
|
|
29
|
-
expected;
|
|
30
|
-
received;
|
|
31
|
-
pathToError;
|
|
32
|
-
message;
|
|
33
|
-
constructor(expected, received, pathToError, message) {
|
|
34
|
-
super();
|
|
35
|
-
this.expected = expected;
|
|
36
|
-
this.received = received;
|
|
37
|
-
this.pathToError = pathToError;
|
|
38
|
-
this.message = message;
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
function throwException(expected, received, pathToError, message) {
|
|
42
|
-
throw new ValidationError(expected, received, pathToError, message);
|
|
43
|
-
}
|
|
44
9
|
|
|
45
|
-
|
|
46
|
-
var ctxSymbol = Symbol("contextSymbol");
|
|
47
|
-
|
|
48
|
-
// src/schemas/CommonSchema.ts
|
|
49
|
-
var CommonSchema = class {
|
|
50
|
-
[ctxSymbol];
|
|
51
|
-
constructor(ctx) {
|
|
52
|
-
this[ctxSymbol] = ctx;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* @param validators - One or more custom validation functions.
|
|
56
|
-
* @returns {this} The schema instance with the added custom validation.
|
|
57
|
-
*/
|
|
58
|
-
custom(...validators) {
|
|
59
|
-
this[ctxSymbol].requiredValidations.push(...validators);
|
|
60
|
-
return this;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Marks the schema as nullable, allowing the value to be `null`.
|
|
64
|
-
*
|
|
65
|
-
* @returns {WithNull<this>} The schema instance marked as nullable.
|
|
66
|
-
*/
|
|
67
|
-
nullable() {
|
|
68
|
-
this[ctxSymbol].isNullable = true;
|
|
69
|
-
return this;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Marks the schema as optional, allowing the value to be `undefined`.
|
|
73
|
-
*
|
|
74
|
-
* @returns {WithUndefined<this>}} The schema instance marked as optional.
|
|
75
|
-
*/
|
|
76
|
-
optional() {
|
|
77
|
-
this[ctxSymbol].isOptional = true;
|
|
78
|
-
return this;
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
// src/schemas/BooleanSchema.ts
|
|
83
|
-
var isBoolean = (expected) => (received, pathToError) => {
|
|
84
|
-
if (received !== expected) throwException(expected, received, pathToError, `The received value is not ${expected}`);
|
|
85
|
-
};
|
|
86
|
-
var BooleanSchema = class extends CommonSchema {
|
|
87
|
-
_boolean = 1;
|
|
88
|
-
/**
|
|
89
|
-
* Restricts the schema to exactly match the boolean value true and infers the true value as the TypeScript type.
|
|
90
|
-
*
|
|
91
|
-
* @returns - The schema instance restricted to the value true, with the true value inferred as the TypeScript type
|
|
92
|
-
*
|
|
93
|
-
* @example - boolean().onlyTrue(); // Infers the type true
|
|
94
|
-
*/
|
|
95
|
-
onlyTrue() {
|
|
96
|
-
return this.custom(isBoolean(true));
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Restricts the schema to exactly match the boolean value false and infers the false value as the TypeScript type.
|
|
100
|
-
*
|
|
101
|
-
* @returns - The schema instance restricted to the value false, with the false value inferred as the TypeScript type
|
|
102
|
-
*
|
|
103
|
-
* @example - boolean().onlyFalse(); // Infers the type false
|
|
104
|
-
*/
|
|
105
|
-
onlyFalse() {
|
|
106
|
-
return this.custom(isBoolean(false));
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
// src/asserts/boolean/index.ts
|
|
111
|
-
function boolean() {
|
|
112
|
-
return new BooleanSchema({ type: ["boolean"], requiredValidations: [] });
|
|
113
|
-
}
|
|
114
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
115
|
-
0 && (module.exports = {
|
|
116
|
-
boolean
|
|
117
|
-
});
|
|
10
|
+
exports.boolean = _chunkA7I2JEQOjs.boolean;
|
|
118
11
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["
|
|
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;AACE;AACF,2CAAC","file":"/home/runner/work/bguard/bguard/lib/asserts/boolean/index.js"}
|
|
@@ -1,90 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
super();
|
|
9
|
-
this.expected = expected;
|
|
10
|
-
this.received = received;
|
|
11
|
-
this.pathToError = pathToError;
|
|
12
|
-
this.message = message;
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
function throwException(expected, received, pathToError, message) {
|
|
16
|
-
throw new ValidationError(expected, received, pathToError, message);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// src/core.ts
|
|
20
|
-
var ctxSymbol = Symbol("contextSymbol");
|
|
21
|
-
|
|
22
|
-
// src/schemas/CommonSchema.ts
|
|
23
|
-
var CommonSchema = class {
|
|
24
|
-
[ctxSymbol];
|
|
25
|
-
constructor(ctx) {
|
|
26
|
-
this[ctxSymbol] = ctx;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* @param validators - One or more custom validation functions.
|
|
30
|
-
* @returns {this} The schema instance with the added custom validation.
|
|
31
|
-
*/
|
|
32
|
-
custom(...validators) {
|
|
33
|
-
this[ctxSymbol].requiredValidations.push(...validators);
|
|
34
|
-
return this;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Marks the schema as nullable, allowing the value to be `null`.
|
|
38
|
-
*
|
|
39
|
-
* @returns {WithNull<this>} The schema instance marked as nullable.
|
|
40
|
-
*/
|
|
41
|
-
nullable() {
|
|
42
|
-
this[ctxSymbol].isNullable = true;
|
|
43
|
-
return this;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Marks the schema as optional, allowing the value to be `undefined`.
|
|
47
|
-
*
|
|
48
|
-
* @returns {WithUndefined<this>}} The schema instance marked as optional.
|
|
49
|
-
*/
|
|
50
|
-
optional() {
|
|
51
|
-
this[ctxSymbol].isOptional = true;
|
|
52
|
-
return this;
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
// src/schemas/BooleanSchema.ts
|
|
57
|
-
var isBoolean = (expected) => (received, pathToError) => {
|
|
58
|
-
if (received !== expected) throwException(expected, received, pathToError, `The received value is not ${expected}`);
|
|
59
|
-
};
|
|
60
|
-
var BooleanSchema = class extends CommonSchema {
|
|
61
|
-
_boolean = 1;
|
|
62
|
-
/**
|
|
63
|
-
* Restricts the schema to exactly match the boolean value true and infers the true value as the TypeScript type.
|
|
64
|
-
*
|
|
65
|
-
* @returns - The schema instance restricted to the value true, with the true value inferred as the TypeScript type
|
|
66
|
-
*
|
|
67
|
-
* @example - boolean().onlyTrue(); // Infers the type true
|
|
68
|
-
*/
|
|
69
|
-
onlyTrue() {
|
|
70
|
-
return this.custom(isBoolean(true));
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Restricts the schema to exactly match the boolean value false and infers the false value as the TypeScript type.
|
|
74
|
-
*
|
|
75
|
-
* @returns - The schema instance restricted to the value false, with the false value inferred as the TypeScript type
|
|
76
|
-
*
|
|
77
|
-
* @example - boolean().onlyFalse(); // Infers the type false
|
|
78
|
-
*/
|
|
79
|
-
onlyFalse() {
|
|
80
|
-
return this.custom(isBoolean(false));
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
// src/asserts/boolean/index.ts
|
|
85
|
-
function boolean() {
|
|
86
|
-
return new BooleanSchema({ type: ["boolean"], requiredValidations: [] });
|
|
87
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
boolean
|
|
3
|
+
} from "../../chunk-3FEJUC3K.mjs";
|
|
4
|
+
import "../../chunk-GEZME6V2.mjs";
|
|
5
|
+
import "../../chunk-L7HUXYFV.mjs";
|
|
6
|
+
import "../../chunk-P3Y6IWFA.mjs";
|
|
7
|
+
import "../../chunk-QJOXKH7A.mjs";
|
|
88
8
|
export {
|
|
89
9
|
boolean
|
|
90
10
|
};
|