bguard 0.0.1 → 0.0.3

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.
Files changed (122) hide show
  1. package/README.md +3 -0
  2. package/lib/CommonSchema-DeTBsQhn.d.mts +57 -0
  3. package/lib/CommonSchema-DeTBsQhn.d.ts +57 -0
  4. package/lib/asserts/array/index.d.mts +2 -0
  5. package/lib/asserts/array/index.d.ts +2 -0
  6. package/lib/asserts/array/index.js +90 -0
  7. package/lib/asserts/array/index.js.map +1 -0
  8. package/lib/asserts/array/index.mjs +63 -0
  9. package/lib/asserts/array/index.mjs.map +1 -0
  10. package/lib/asserts/boolean/index.d.mts +2 -0
  11. package/lib/asserts/boolean/index.d.ts +2 -0
  12. package/lib/asserts/boolean/index.js +118 -0
  13. package/lib/asserts/boolean/index.js.map +1 -0
  14. package/lib/asserts/boolean/index.mjs +91 -0
  15. package/lib/asserts/boolean/index.mjs.map +1 -0
  16. package/lib/asserts/common/equalTo.d.mts +29 -0
  17. package/lib/asserts/common/equalTo.d.ts +29 -0
  18. package/lib/asserts/common/equalTo.js +54 -0
  19. package/lib/asserts/common/equalTo.js.map +1 -0
  20. package/lib/asserts/common/equalTo.mjs +27 -0
  21. package/lib/asserts/common/equalTo.mjs.map +1 -0
  22. package/lib/asserts/common/index.d.mts +18 -0
  23. package/lib/asserts/common/index.d.ts +18 -0
  24. package/lib/asserts/common/index.js +72 -0
  25. package/lib/asserts/common/index.js.map +1 -0
  26. package/lib/asserts/common/index.mjs +45 -0
  27. package/lib/asserts/common/index.mjs.map +1 -0
  28. package/lib/asserts/number/index.d.mts +2 -0
  29. package/lib/asserts/number/index.d.ts +2 -0
  30. package/lib/asserts/number/index.js +112 -0
  31. package/lib/asserts/number/index.js.map +1 -0
  32. package/lib/asserts/number/index.mjs +85 -0
  33. package/lib/asserts/number/index.mjs.map +1 -0
  34. package/lib/asserts/number/max.d.mts +17 -0
  35. package/lib/asserts/number/max.d.ts +17 -0
  36. package/lib/asserts/number/max.js +54 -0
  37. package/lib/asserts/number/max.js.map +1 -0
  38. package/lib/asserts/number/max.mjs +27 -0
  39. package/lib/asserts/number/max.mjs.map +1 -0
  40. package/lib/asserts/number/maxExcluded.d.mts +17 -0
  41. package/lib/asserts/number/maxExcluded.d.ts +17 -0
  42. package/lib/asserts/number/maxExcluded.js +54 -0
  43. package/lib/asserts/number/maxExcluded.js.map +1 -0
  44. package/lib/asserts/number/maxExcluded.mjs +27 -0
  45. package/lib/asserts/number/maxExcluded.mjs.map +1 -0
  46. package/lib/asserts/number/min.d.mts +17 -0
  47. package/lib/asserts/number/min.d.ts +17 -0
  48. package/lib/asserts/number/min.js +54 -0
  49. package/lib/asserts/number/min.js.map +1 -0
  50. package/lib/asserts/number/min.mjs +27 -0
  51. package/lib/asserts/number/min.mjs.map +1 -0
  52. package/lib/asserts/number/minExcluded.d.mts +17 -0
  53. package/lib/asserts/number/minExcluded.d.ts +17 -0
  54. package/lib/asserts/number/minExcluded.js +54 -0
  55. package/lib/asserts/number/minExcluded.js.map +1 -0
  56. package/lib/asserts/number/minExcluded.mjs +27 -0
  57. package/lib/asserts/number/minExcluded.mjs.map +1 -0
  58. package/lib/asserts/number/negative.d.mts +16 -0
  59. package/lib/asserts/number/negative.d.ts +16 -0
  60. package/lib/asserts/number/negative.js +53 -0
  61. package/lib/asserts/number/negative.js.map +1 -0
  62. package/lib/asserts/number/negative.mjs +26 -0
  63. package/lib/asserts/number/negative.mjs.map +1 -0
  64. package/lib/asserts/number/positive.d.mts +16 -0
  65. package/lib/asserts/number/positive.d.ts +16 -0
  66. package/lib/asserts/number/positive.js +53 -0
  67. package/lib/asserts/number/positive.js.map +1 -0
  68. package/lib/asserts/number/positive.mjs +26 -0
  69. package/lib/asserts/number/positive.mjs.map +1 -0
  70. package/lib/asserts/object/index.d.mts +2 -0
  71. package/lib/asserts/object/index.d.ts +2 -0
  72. package/lib/asserts/object/index.js +94 -0
  73. package/lib/asserts/object/index.js.map +1 -0
  74. package/lib/asserts/object/index.mjs +67 -0
  75. package/lib/asserts/object/index.mjs.map +1 -0
  76. package/lib/asserts/string/email.d.mts +16 -0
  77. package/lib/asserts/string/email.d.ts +16 -0
  78. package/lib/asserts/string/email.js +55 -0
  79. package/lib/asserts/string/email.js.map +1 -0
  80. package/lib/asserts/string/email.mjs +28 -0
  81. package/lib/asserts/string/email.mjs.map +1 -0
  82. package/lib/asserts/string/index.d.mts +2 -0
  83. package/lib/asserts/string/index.d.ts +2 -0
  84. package/lib/asserts/string/index.js +112 -0
  85. package/lib/asserts/string/index.js.map +1 -0
  86. package/lib/asserts/string/index.mjs +85 -0
  87. package/lib/asserts/string/index.mjs.map +1 -0
  88. package/lib/asserts/string/maxLength.d.mts +16 -0
  89. package/lib/asserts/string/maxLength.d.ts +16 -0
  90. package/lib/asserts/string/maxLength.js +54 -0
  91. package/lib/asserts/string/maxLength.js.map +1 -0
  92. package/lib/asserts/string/maxLength.mjs +27 -0
  93. package/lib/asserts/string/maxLength.mjs.map +1 -0
  94. package/lib/asserts/string/minLength.d.mts +16 -0
  95. package/lib/asserts/string/minLength.d.ts +16 -0
  96. package/lib/asserts/string/minLength.js +54 -0
  97. package/lib/asserts/string/minLength.js.map +1 -0
  98. package/lib/asserts/string/minLength.mjs +27 -0
  99. package/lib/asserts/string/minLength.mjs.map +1 -0
  100. package/lib/asserts/string/regExp.d.mts +16 -0
  101. package/lib/asserts/string/regExp.d.ts +16 -0
  102. package/lib/asserts/string/regExp.js +54 -0
  103. package/lib/asserts/string/regExp.js.map +1 -0
  104. package/lib/asserts/string/regExp.mjs +27 -0
  105. package/lib/asserts/string/regExp.mjs.map +1 -0
  106. package/lib/index-B1yBez0g.d.ts +39 -0
  107. package/lib/index-B63cXDOm.d.mts +32 -0
  108. package/lib/index-BEyBEBSm.d.ts +32 -0
  109. package/lib/index-CK_g_aEC.d.ts +32 -0
  110. package/lib/index-D3R2euaT.d.mts +29 -0
  111. package/lib/index-DPkImfCy.d.ts +29 -0
  112. package/lib/index-DitgsWDO.d.ts +27 -0
  113. package/lib/index-T3KBmyyn.d.mts +27 -0
  114. package/lib/index-aBEYpJdZ.d.mts +32 -0
  115. package/lib/index-nzqBrOHf.d.mts +39 -0
  116. package/lib/index.d.mts +13 -215
  117. package/lib/index.d.ts +13 -215
  118. package/lib/index.js +1 -0
  119. package/lib/index.js.map +1 -0
  120. package/lib/index.mjs +1 -0
  121. package/lib/index.mjs.map +1 -0
  122. package/package.json +22 -2
@@ -0,0 +1,29 @@
1
+ import { C as CommonSchema, V as ValidatorContext, O as ObjectShapeSchemaType } from './CommonSchema-DeTBsQhn.mjs';
2
+
3
+ declare class ObjectSchema extends CommonSchema {
4
+ _object: number;
5
+ constructor(ctx: ValidatorContext, shapeSchema: ObjectShapeSchemaType);
6
+ private validateObjectEntry;
7
+ }
8
+ type WithObject<Y extends ObjectShapeSchemaType> = ObjectSchema & {
9
+ validation_object: Y;
10
+ };
11
+
12
+ /**
13
+ * Creates a new schema for validating objects where each property must match the specified schema.
14
+ *
15
+ * @template T
16
+ * @param {T} shapeSchema - The schema that each property of the object must match.
17
+ * @returns {WithObject<T>} A new instance of `ObjectSchema` for validating objects with properties matching the specified schema.
18
+ *
19
+ * @example
20
+ * const schema = object({
21
+ * name: string(),
22
+ * age: number()
23
+ * });
24
+ * parseSchema(schema, { name: 'John', age: 30 }); // Validates successfully
25
+ * parseSchema(schema, { name: 'John', age: '30' }); // Throws a validation error
26
+ */
27
+ declare function object<T extends ObjectShapeSchemaType>(shapeSchema: T): WithObject<T>;
28
+
29
+ export { ObjectSchema as O, type WithObject as W, object as o };
@@ -0,0 +1,29 @@
1
+ import { C as CommonSchema, V as ValidatorContext, O as ObjectShapeSchemaType } from './CommonSchema-DeTBsQhn.js';
2
+
3
+ declare class ObjectSchema extends CommonSchema {
4
+ _object: number;
5
+ constructor(ctx: ValidatorContext, shapeSchema: ObjectShapeSchemaType);
6
+ private validateObjectEntry;
7
+ }
8
+ type WithObject<Y extends ObjectShapeSchemaType> = ObjectSchema & {
9
+ validation_object: Y;
10
+ };
11
+
12
+ /**
13
+ * Creates a new schema for validating objects where each property must match the specified schema.
14
+ *
15
+ * @template T
16
+ * @param {T} shapeSchema - The schema that each property of the object must match.
17
+ * @returns {WithObject<T>} A new instance of `ObjectSchema` for validating objects with properties matching the specified schema.
18
+ *
19
+ * @example
20
+ * const schema = object({
21
+ * name: string(),
22
+ * age: number()
23
+ * });
24
+ * parseSchema(schema, { name: 'John', age: 30 }); // Validates successfully
25
+ * parseSchema(schema, { name: 'John', age: '30' }); // Throws a validation error
26
+ */
27
+ declare function object<T extends ObjectShapeSchemaType>(shapeSchema: T): WithObject<T>;
28
+
29
+ export { ObjectSchema as O, type WithObject as W, object as o };
@@ -0,0 +1,27 @@
1
+ import { C as CommonSchema, V as ValidatorContext } from './CommonSchema-DeTBsQhn.js';
2
+
3
+ declare class ArraySchema extends CommonSchema {
4
+ _array: number;
5
+ constructor(ctx: ValidatorContext, arraySchema: CommonSchema);
6
+ private validateArrayEntry;
7
+ }
8
+ type WithArray<Y extends CommonSchema> = ArraySchema & {
9
+ validation_array: Y;
10
+ };
11
+ type ExtractFromArray<T> = T extends WithArray<infer X> ? X : never;
12
+
13
+ /**
14
+ * Creates a new schema for validating arrays where each element must match the specified schema.
15
+ *
16
+ * @template T
17
+ * @param {T} arraySchema - The schema that each element of the array must match.
18
+ * @returns {WithArray<T>} A new instance of `ArraySchema` for validating arrays of elements that match the specified schema.
19
+ *
20
+ * @example
21
+ * const schema = array(string());
22
+ * parseSchema(schema, ['hello', 'world']); // Validates successfully
23
+ * parseSchema(schema, ['hello', 123]); // Throws a validation error
24
+ */
25
+ declare function array<T extends CommonSchema>(arraySchema: T): WithArray<T>;
26
+
27
+ export { ArraySchema as A, type ExtractFromArray as E, array as a };
@@ -0,0 +1,27 @@
1
+ import { C as CommonSchema, V as ValidatorContext } from './CommonSchema-DeTBsQhn.mjs';
2
+
3
+ declare class ArraySchema extends CommonSchema {
4
+ _array: number;
5
+ constructor(ctx: ValidatorContext, arraySchema: CommonSchema);
6
+ private validateArrayEntry;
7
+ }
8
+ type WithArray<Y extends CommonSchema> = ArraySchema & {
9
+ validation_array: Y;
10
+ };
11
+ type ExtractFromArray<T> = T extends WithArray<infer X> ? X : never;
12
+
13
+ /**
14
+ * Creates a new schema for validating arrays where each element must match the specified schema.
15
+ *
16
+ * @template T
17
+ * @param {T} arraySchema - The schema that each element of the array must match.
18
+ * @returns {WithArray<T>} A new instance of `ArraySchema` for validating arrays of elements that match the specified schema.
19
+ *
20
+ * @example
21
+ * const schema = array(string());
22
+ * parseSchema(schema, ['hello', 'world']); // Validates successfully
23
+ * parseSchema(schema, ['hello', 123]); // Throws a validation error
24
+ */
25
+ declare function array<T extends CommonSchema>(arraySchema: T): WithArray<T>;
26
+
27
+ export { ArraySchema as A, type ExtractFromArray as E, array as a };
@@ -0,0 +1,32 @@
1
+ import { C as CommonSchema } from './CommonSchema-DeTBsQhn.mjs';
2
+
3
+ declare class StringSchema extends CommonSchema {
4
+ _string: number;
5
+ /**
6
+ * Restricts the schema to exactly match the specified value and infers the literal value as the TypeScript type.
7
+ *
8
+ * @param expectedValue - The value that the schema must exactly match.
9
+ * @returns - The schema instance restricted to the specified value, with the literal value inferred as the TypeScript type
10
+ *
11
+ * @example - string().equalTo('hello'); // Infers the type 'hello'
12
+ */
13
+ equalTo<Y extends string>(expectedValue: Y): WithString<this, Y>;
14
+ }
15
+ type WithString<T extends StringSchema, Y = string> = T & {
16
+ validation_string: Y;
17
+ };
18
+ type ExtractFromString<T> = T extends WithString<StringSchema, infer Y> ? Y : never;
19
+
20
+ /**
21
+ * Creates a new schema for validating string values.
22
+ *
23
+ * @returns {StringSchema} A new instance of `StringSchema` for validating strings.
24
+ *
25
+ * @example
26
+ * const schema = string();
27
+ * parseSchema(schema, 'hello'); // Validates successfully
28
+ * parseSchema(schema, 123); // Throws a validation error
29
+ */
30
+ declare function string(): StringSchema;
31
+
32
+ export { type ExtractFromString as E, StringSchema as S, type WithString as W, string as s };
@@ -0,0 +1,39 @@
1
+ import { C as CommonSchema } from './CommonSchema-DeTBsQhn.mjs';
2
+
3
+ declare class BooleanSchema extends CommonSchema {
4
+ _boolean: number;
5
+ /**
6
+ * Restricts the schema to exactly match the boolean value true and infers the true value as the TypeScript type.
7
+ *
8
+ * @returns - The schema instance restricted to the value true, with the true value inferred as the TypeScript type
9
+ *
10
+ * @example - boolean().onlyTrue(); // Infers the type true
11
+ */
12
+ onlyTrue(): WithBoolean<this, true>;
13
+ /**
14
+ * Restricts the schema to exactly match the boolean value false and infers the false value as the TypeScript type.
15
+ *
16
+ * @returns - The schema instance restricted to the value false, with the false value inferred as the TypeScript type
17
+ *
18
+ * @example - boolean().onlyFalse(); // Infers the type false
19
+ */
20
+ onlyFalse(): WithBoolean<this, false>;
21
+ }
22
+ type WithBoolean<T extends BooleanSchema, Y = boolean> = T & {
23
+ validation_boolean: Y;
24
+ };
25
+ type ExtractFromBoolean<T> = T extends WithBoolean<BooleanSchema, infer Y> ? Y : never;
26
+
27
+ /**
28
+ * Creates a new schema for validating boolean values.
29
+ *
30
+ * @returns {BooleanSchema} A new instance of `BooleanSchema` for validating booleans.
31
+ *
32
+ * @example
33
+ * const schema = boolean();
34
+ * parseSchema(schema, true); // Validates successfully
35
+ * parseSchema(schema, 'true'); // Throws a validation error
36
+ */
37
+ declare function boolean(): BooleanSchema;
38
+
39
+ export { BooleanSchema as B, type ExtractFromBoolean as E, type WithBoolean as W, boolean as b };
package/lib/index.d.mts CHANGED
@@ -1,135 +1,15 @@
1
- declare const ctxSymbol: unique symbol;
2
-
3
- type RequiredValidation = (received: any, pathToError: string) => void;
4
- type ObjectShapeSchemaType = Record<string, CommonSchema>;
5
- type PrimitiveType = 'number' | 'string' | 'boolean' | 'undefined' | 'object' | 'function' | 'symbol' | 'bigint';
6
- interface ValidatorContext {
7
- type: PrimitiveType[];
8
- isNullable?: boolean;
9
- isOptional?: boolean;
10
- requiredValidations: RequiredValidation[];
11
- array?: CommonSchema;
12
- object?: ObjectShapeSchemaType;
13
- }
14
- declare class CommonSchema {
15
- [ctxSymbol]: ValidatorContext;
16
- constructor(ctx: ValidatorContext);
17
- /**
18
- * @param validators - One or more custom validation functions.
19
- * @returns {this} The schema instance with the added custom validation.
20
- */
21
- custom(...validators: RequiredValidation[]): this;
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(): WithNull<this>;
28
- /**
29
- * Marks the schema as optional, allowing the value to be `undefined`.
30
- *
31
- * @returns {WithUndefined<this>}} The schema instance marked as optional.
32
- */
33
- optional(): WithUndefined<this>;
34
- }
35
- type WithNull<T extends CommonSchema> = T & {
36
- validation_null: true;
37
- };
38
- type WithUndefined<T extends CommonSchema> = T & {
39
- validation_undefined: true;
40
- };
41
- type TypeMapping = {
42
- number: number;
43
- string: string;
44
- boolean: boolean;
45
- undefined: undefined;
46
- object: object;
47
- function: Function;
48
- symbol: symbol;
49
- bigint: bigint;
50
- };
51
- type WithMix<Y = unknown> = CommonSchema & {
52
- validation_mix: Y;
53
- };
54
- type ExtractFromMix<T> = T extends WithMix<infer X> ? X : never;
55
- type MapMixTypes<T extends PrimitiveType[]> = T extends (infer U)[] ? U extends keyof TypeMapping ? TypeMapping[U] : never : never;
56
-
57
- declare class ArraySchema extends CommonSchema {
58
- _array: number;
59
- constructor(ctx: ValidatorContext, arraySchema: CommonSchema);
60
- private validateArrayEntry;
61
- }
62
- type WithArray<Y extends CommonSchema> = ArraySchema & {
63
- validation_array: Y;
64
- };
65
- type ExtractFromArray<T> = T extends WithArray<infer X> ? X : never;
66
-
67
- declare class BooleanSchema extends CommonSchema {
68
- _boolean: number;
69
- /**
70
- * Restricts the schema to exactly match the boolean value true and infers the true value as the TypeScript type.
71
- *
72
- * @returns - The schema instance restricted to the value true, with the true value inferred as the TypeScript type
73
- *
74
- * @example - boolean().onlyTrue(); // Infers the type true
75
- */
76
- onlyTrue(): WithBoolean<this, true>;
77
- /**
78
- * Restricts the schema to exactly match the boolean value false and infers the false value as the TypeScript type.
79
- *
80
- * @returns - The schema instance restricted to the value false, with the false value inferred as the TypeScript type
81
- *
82
- * @example - boolean().onlyFalse(); // Infers the type false
83
- */
84
- onlyFalse(): WithBoolean<this, false>;
85
- }
86
- type WithBoolean<T extends BooleanSchema, Y = boolean> = T & {
87
- validation_boolean: Y;
88
- };
89
- type ExtractFromBoolean<T> = T extends WithBoolean<BooleanSchema, infer Y> ? Y : never;
90
-
91
- declare class NumberSchema extends CommonSchema {
92
- _number: number;
93
- /**
94
- * Restricts the schema to exactly match the specified value and infers the literal value as the TypeScript type.
95
- *
96
- * @param expectedValue - The value that the schema must exactly match.
97
- * @returns - The schema instance restricted to the specified value, with the literal value inferred as the TypeScript type
98
- *
99
- * @example - number().equalTo(42); // Infers the type 42
100
- */
101
- equalTo<Y extends number>(expectedValue: Y): WithNumber<this, Y>;
102
- }
103
- type WithNumber<T extends NumberSchema, Y = number> = T & {
104
- validation_number: Y;
105
- };
106
- type ExtractFromNumber<T> = T extends WithNumber<NumberSchema, infer Y> ? Y : never;
107
-
108
- declare class ObjectSchema extends CommonSchema {
109
- _object: number;
110
- constructor(ctx: ValidatorContext, shapeSchema: ObjectShapeSchemaType);
111
- private validateObjectEntry;
112
- }
113
- type WithObject<Y extends ObjectShapeSchemaType> = ObjectSchema & {
114
- validation_object: Y;
115
- };
116
-
117
- declare class StringSchema extends CommonSchema {
118
- _string: number;
119
- /**
120
- * Restricts the schema to exactly match the specified value and infers the literal value as the TypeScript type.
121
- *
122
- * @param expectedValue - The value that the schema must exactly match.
123
- * @returns - The schema instance restricted to the specified value, with the literal value inferred as the TypeScript type
124
- *
125
- * @example - string().equalTo('hello'); // Infers the type 'hello'
126
- */
127
- equalTo<Y extends string>(expectedValue: Y): WithString<this, Y>;
128
- }
129
- type WithString<T extends StringSchema, Y = string> = T & {
130
- validation_string: Y;
131
- };
132
- type ExtractFromString<T> = T extends WithString<StringSchema, infer Y> ? Y : never;
1
+ import { A as ArraySchema, E as ExtractFromArray } from './index-T3KBmyyn.mjs';
2
+ export { a as array } from './index-T3KBmyyn.mjs';
3
+ import { W as WithBoolean, B as BooleanSchema, E as ExtractFromBoolean } from './index-nzqBrOHf.mjs';
4
+ export { b as boolean } from './index-nzqBrOHf.mjs';
5
+ import { W as WithUndefined, a as WithNull, b as WithMix, E as ExtractFromMix, C as CommonSchema } from './CommonSchema-DeTBsQhn.mjs';
6
+ import { W as WithNumber, N as NumberSchema, E as ExtractFromNumber } from './index-B63cXDOm.mjs';
7
+ export { n as number } from './index-B63cXDOm.mjs';
8
+ import { O as ObjectSchema, W as WithObject } from './index-D3R2euaT.mjs';
9
+ export { o as object } from './index-D3R2euaT.mjs';
10
+ import { W as WithString, S as StringSchema, E as ExtractFromString } from './index-aBEYpJdZ.mjs';
11
+ export { s as string } from './index-aBEYpJdZ.mjs';
12
+ export { oneOfTypes } from './asserts/common/index.mjs';
133
13
 
134
14
  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;
135
15
  type Merge<T> = T extends infer U ? {
@@ -169,86 +49,4 @@ type ExtractFromObject<T extends ObjectSchema> = T extends WithObject<infer X> ?
169
49
  */
170
50
  declare function parseSchema<T extends CommonSchema>(schema: T, receivedValue: unknown): InferType<T>;
171
51
 
172
- /**
173
- * Creates a new schema for validating number values.
174
- *
175
- * @returns {NumberSchema} A new instance of `NumberSchema` for validating numbers.
176
- *
177
- * @example
178
- * const schema = number();
179
- * parseSchema(schema, 42); // Validates successfully
180
- * parseSchema(schema, '42'); // Throws a validation error
181
- */
182
- declare function number(): NumberSchema;
183
-
184
- /**
185
- * Creates a new schema for validating string values.
186
- *
187
- * @returns {StringSchema} A new instance of `StringSchema` for validating strings.
188
- *
189
- * @example
190
- * const schema = string();
191
- * parseSchema(schema, 'hello'); // Validates successfully
192
- * parseSchema(schema, 123); // Throws a validation error
193
- */
194
- declare function string(): StringSchema;
195
-
196
- /**
197
- * Creates a new schema for validating boolean values.
198
- *
199
- * @returns {BooleanSchema} A new instance of `BooleanSchema` for validating booleans.
200
- *
201
- * @example
202
- * const schema = boolean();
203
- * parseSchema(schema, true); // Validates successfully
204
- * parseSchema(schema, 'true'); // Throws a validation error
205
- */
206
- declare function boolean(): BooleanSchema;
207
-
208
- /**
209
- * Creates a new schema for validating arrays where each element must match the specified schema.
210
- *
211
- * @template T
212
- * @param {T} arraySchema - The schema that each element of the array must match.
213
- * @returns {WithArray<T>} A new instance of `ArraySchema` for validating arrays of elements that match the specified schema.
214
- *
215
- * @example
216
- * const schema = array(string());
217
- * parseSchema(schema, ['hello', 'world']); // Validates successfully
218
- * parseSchema(schema, ['hello', 123]); // Throws a validation error
219
- */
220
- declare function array<T extends CommonSchema>(arraySchema: T): WithArray<T>;
221
-
222
- /**
223
- * Creates a new schema for validating objects where each property must match the specified schema.
224
- *
225
- * @template T
226
- * @param {T} shapeSchema - The schema that each property of the object must match.
227
- * @returns {WithObject<T>} A new instance of `ObjectSchema` for validating objects with properties matching the specified schema.
228
- *
229
- * @example
230
- * const schema = object({
231
- * name: string(),
232
- * age: number()
233
- * });
234
- * parseSchema(schema, { name: 'John', age: 30 }); // Validates successfully
235
- * parseSchema(schema, { name: 'John', age: '30' }); // Throws a validation error
236
- */
237
- declare function object<T extends ObjectShapeSchemaType>(shapeSchema: T): WithObject<T>;
238
-
239
- /**
240
- * Creates a new schema for validating values that can match any one of the specified primitive types.
241
- *
242
- * @template T
243
- * @param {T} valueTypes - An array of primitive types that the value can match.
244
- * @returns {WithMix<MapMixTypes<T>>} A new schema for validating values that can match any of the specified types.
245
- *
246
- * @example
247
- * const schema = oneOfTypes(['string', 'number']);
248
- * parseSchema(schema, 'hello'); // Validates successfully
249
- * parseSchema(schema, 42); // Validates successfully
250
- * parseSchema(schema, true); // Throws a validation error
251
- */
252
- declare function oneOfTypes<T extends PrimitiveType[]>(valueTypes: T): WithMix<MapMixTypes<T>>;
253
-
254
- export { type InferType, array, boolean, number, object, oneOfTypes, parseSchema, string };
52
+ export { type InferType, parseSchema };
package/lib/index.d.ts CHANGED
@@ -1,135 +1,15 @@
1
- declare const ctxSymbol: unique symbol;
2
-
3
- type RequiredValidation = (received: any, pathToError: string) => void;
4
- type ObjectShapeSchemaType = Record<string, CommonSchema>;
5
- type PrimitiveType = 'number' | 'string' | 'boolean' | 'undefined' | 'object' | 'function' | 'symbol' | 'bigint';
6
- interface ValidatorContext {
7
- type: PrimitiveType[];
8
- isNullable?: boolean;
9
- isOptional?: boolean;
10
- requiredValidations: RequiredValidation[];
11
- array?: CommonSchema;
12
- object?: ObjectShapeSchemaType;
13
- }
14
- declare class CommonSchema {
15
- [ctxSymbol]: ValidatorContext;
16
- constructor(ctx: ValidatorContext);
17
- /**
18
- * @param validators - One or more custom validation functions.
19
- * @returns {this} The schema instance with the added custom validation.
20
- */
21
- custom(...validators: RequiredValidation[]): this;
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(): WithNull<this>;
28
- /**
29
- * Marks the schema as optional, allowing the value to be `undefined`.
30
- *
31
- * @returns {WithUndefined<this>}} The schema instance marked as optional.
32
- */
33
- optional(): WithUndefined<this>;
34
- }
35
- type WithNull<T extends CommonSchema> = T & {
36
- validation_null: true;
37
- };
38
- type WithUndefined<T extends CommonSchema> = T & {
39
- validation_undefined: true;
40
- };
41
- type TypeMapping = {
42
- number: number;
43
- string: string;
44
- boolean: boolean;
45
- undefined: undefined;
46
- object: object;
47
- function: Function;
48
- symbol: symbol;
49
- bigint: bigint;
50
- };
51
- type WithMix<Y = unknown> = CommonSchema & {
52
- validation_mix: Y;
53
- };
54
- type ExtractFromMix<T> = T extends WithMix<infer X> ? X : never;
55
- type MapMixTypes<T extends PrimitiveType[]> = T extends (infer U)[] ? U extends keyof TypeMapping ? TypeMapping[U] : never : never;
56
-
57
- declare class ArraySchema extends CommonSchema {
58
- _array: number;
59
- constructor(ctx: ValidatorContext, arraySchema: CommonSchema);
60
- private validateArrayEntry;
61
- }
62
- type WithArray<Y extends CommonSchema> = ArraySchema & {
63
- validation_array: Y;
64
- };
65
- type ExtractFromArray<T> = T extends WithArray<infer X> ? X : never;
66
-
67
- declare class BooleanSchema extends CommonSchema {
68
- _boolean: number;
69
- /**
70
- * Restricts the schema to exactly match the boolean value true and infers the true value as the TypeScript type.
71
- *
72
- * @returns - The schema instance restricted to the value true, with the true value inferred as the TypeScript type
73
- *
74
- * @example - boolean().onlyTrue(); // Infers the type true
75
- */
76
- onlyTrue(): WithBoolean<this, true>;
77
- /**
78
- * Restricts the schema to exactly match the boolean value false and infers the false value as the TypeScript type.
79
- *
80
- * @returns - The schema instance restricted to the value false, with the false value inferred as the TypeScript type
81
- *
82
- * @example - boolean().onlyFalse(); // Infers the type false
83
- */
84
- onlyFalse(): WithBoolean<this, false>;
85
- }
86
- type WithBoolean<T extends BooleanSchema, Y = boolean> = T & {
87
- validation_boolean: Y;
88
- };
89
- type ExtractFromBoolean<T> = T extends WithBoolean<BooleanSchema, infer Y> ? Y : never;
90
-
91
- declare class NumberSchema extends CommonSchema {
92
- _number: number;
93
- /**
94
- * Restricts the schema to exactly match the specified value and infers the literal value as the TypeScript type.
95
- *
96
- * @param expectedValue - The value that the schema must exactly match.
97
- * @returns - The schema instance restricted to the specified value, with the literal value inferred as the TypeScript type
98
- *
99
- * @example - number().equalTo(42); // Infers the type 42
100
- */
101
- equalTo<Y extends number>(expectedValue: Y): WithNumber<this, Y>;
102
- }
103
- type WithNumber<T extends NumberSchema, Y = number> = T & {
104
- validation_number: Y;
105
- };
106
- type ExtractFromNumber<T> = T extends WithNumber<NumberSchema, infer Y> ? Y : never;
107
-
108
- declare class ObjectSchema extends CommonSchema {
109
- _object: number;
110
- constructor(ctx: ValidatorContext, shapeSchema: ObjectShapeSchemaType);
111
- private validateObjectEntry;
112
- }
113
- type WithObject<Y extends ObjectShapeSchemaType> = ObjectSchema & {
114
- validation_object: Y;
115
- };
116
-
117
- declare class StringSchema extends CommonSchema {
118
- _string: number;
119
- /**
120
- * Restricts the schema to exactly match the specified value and infers the literal value as the TypeScript type.
121
- *
122
- * @param expectedValue - The value that the schema must exactly match.
123
- * @returns - The schema instance restricted to the specified value, with the literal value inferred as the TypeScript type
124
- *
125
- * @example - string().equalTo('hello'); // Infers the type 'hello'
126
- */
127
- equalTo<Y extends string>(expectedValue: Y): WithString<this, Y>;
128
- }
129
- type WithString<T extends StringSchema, Y = string> = T & {
130
- validation_string: Y;
131
- };
132
- type ExtractFromString<T> = T extends WithString<StringSchema, infer Y> ? Y : never;
1
+ import { A as ArraySchema, E as ExtractFromArray } from './index-DitgsWDO.js';
2
+ export { a as array } from './index-DitgsWDO.js';
3
+ import { W as WithBoolean, B as BooleanSchema, E as ExtractFromBoolean } from './index-B1yBez0g.js';
4
+ export { b as boolean } from './index-B1yBez0g.js';
5
+ import { W as WithUndefined, a as WithNull, b as WithMix, E as ExtractFromMix, C as CommonSchema } from './CommonSchema-DeTBsQhn.js';
6
+ import { W as WithNumber, N as NumberSchema, E as ExtractFromNumber } from './index-CK_g_aEC.js';
7
+ export { n as number } from './index-CK_g_aEC.js';
8
+ import { O as ObjectSchema, W as WithObject } from './index-DPkImfCy.js';
9
+ export { o as object } from './index-DPkImfCy.js';
10
+ import { W as WithString, S as StringSchema, E as ExtractFromString } from './index-BEyBEBSm.js';
11
+ export { s as string } from './index-BEyBEBSm.js';
12
+ export { oneOfTypes } from './asserts/common/index.js';
133
13
 
134
14
  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;
135
15
  type Merge<T> = T extends infer U ? {
@@ -169,86 +49,4 @@ type ExtractFromObject<T extends ObjectSchema> = T extends WithObject<infer X> ?
169
49
  */
170
50
  declare function parseSchema<T extends CommonSchema>(schema: T, receivedValue: unknown): InferType<T>;
171
51
 
172
- /**
173
- * Creates a new schema for validating number values.
174
- *
175
- * @returns {NumberSchema} A new instance of `NumberSchema` for validating numbers.
176
- *
177
- * @example
178
- * const schema = number();
179
- * parseSchema(schema, 42); // Validates successfully
180
- * parseSchema(schema, '42'); // Throws a validation error
181
- */
182
- declare function number(): NumberSchema;
183
-
184
- /**
185
- * Creates a new schema for validating string values.
186
- *
187
- * @returns {StringSchema} A new instance of `StringSchema` for validating strings.
188
- *
189
- * @example
190
- * const schema = string();
191
- * parseSchema(schema, 'hello'); // Validates successfully
192
- * parseSchema(schema, 123); // Throws a validation error
193
- */
194
- declare function string(): StringSchema;
195
-
196
- /**
197
- * Creates a new schema for validating boolean values.
198
- *
199
- * @returns {BooleanSchema} A new instance of `BooleanSchema` for validating booleans.
200
- *
201
- * @example
202
- * const schema = boolean();
203
- * parseSchema(schema, true); // Validates successfully
204
- * parseSchema(schema, 'true'); // Throws a validation error
205
- */
206
- declare function boolean(): BooleanSchema;
207
-
208
- /**
209
- * Creates a new schema for validating arrays where each element must match the specified schema.
210
- *
211
- * @template T
212
- * @param {T} arraySchema - The schema that each element of the array must match.
213
- * @returns {WithArray<T>} A new instance of `ArraySchema` for validating arrays of elements that match the specified schema.
214
- *
215
- * @example
216
- * const schema = array(string());
217
- * parseSchema(schema, ['hello', 'world']); // Validates successfully
218
- * parseSchema(schema, ['hello', 123]); // Throws a validation error
219
- */
220
- declare function array<T extends CommonSchema>(arraySchema: T): WithArray<T>;
221
-
222
- /**
223
- * Creates a new schema for validating objects where each property must match the specified schema.
224
- *
225
- * @template T
226
- * @param {T} shapeSchema - The schema that each property of the object must match.
227
- * @returns {WithObject<T>} A new instance of `ObjectSchema` for validating objects with properties matching the specified schema.
228
- *
229
- * @example
230
- * const schema = object({
231
- * name: string(),
232
- * age: number()
233
- * });
234
- * parseSchema(schema, { name: 'John', age: 30 }); // Validates successfully
235
- * parseSchema(schema, { name: 'John', age: '30' }); // Throws a validation error
236
- */
237
- declare function object<T extends ObjectShapeSchemaType>(shapeSchema: T): WithObject<T>;
238
-
239
- /**
240
- * Creates a new schema for validating values that can match any one of the specified primitive types.
241
- *
242
- * @template T
243
- * @param {T} valueTypes - An array of primitive types that the value can match.
244
- * @returns {WithMix<MapMixTypes<T>>} A new schema for validating values that can match any of the specified types.
245
- *
246
- * @example
247
- * const schema = oneOfTypes(['string', 'number']);
248
- * parseSchema(schema, 'hello'); // Validates successfully
249
- * parseSchema(schema, 42); // Validates successfully
250
- * parseSchema(schema, true); // Throws a validation error
251
- */
252
- declare function oneOfTypes<T extends PrimitiveType[]>(valueTypes: T): WithMix<MapMixTypes<T>>;
253
-
254
- export { type InferType, array, boolean, number, object, oneOfTypes, parseSchema, string };
52
+ export { type InferType, parseSchema };