bguard 0.0.5 → 0.0.7

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 (217) hide show
  1. package/lib/InferType.js +1 -19
  2. package/lib/InferType.js.map +1 -1
  3. package/lib/asserts/array/index.js +7 -86
  4. package/lib/asserts/array/index.js.map +1 -1
  5. package/lib/asserts/array/index.mjs +7 -59
  6. package/lib/asserts/array/index.mjs.map +1 -1
  7. package/lib/asserts/boolean/index.js +7 -114
  8. package/lib/asserts/boolean/index.js.map +1 -1
  9. package/lib/asserts/boolean/index.mjs +7 -87
  10. package/lib/asserts/boolean/index.mjs.map +1 -1
  11. package/lib/asserts/common/equalTo.js +4 -50
  12. package/lib/asserts/common/equalTo.js.map +1 -1
  13. package/lib/asserts/common/equalTo.mjs +4 -23
  14. package/lib/asserts/common/equalTo.mjs.map +1 -1
  15. package/lib/asserts/common/index.js +6 -68
  16. package/lib/asserts/common/index.js.map +1 -1
  17. package/lib/asserts/common/index.mjs +6 -41
  18. package/lib/asserts/common/index.mjs.map +1 -1
  19. package/lib/asserts/number/index.js +8 -108
  20. package/lib/asserts/number/index.js.map +1 -1
  21. package/lib/asserts/number/index.mjs +8 -81
  22. package/lib/asserts/number/index.mjs.map +1 -1
  23. package/lib/asserts/number/max.js +6 -47
  24. package/lib/asserts/number/max.js.map +1 -1
  25. package/lib/asserts/number/max.mjs +3 -17
  26. package/lib/asserts/number/max.mjs.map +1 -1
  27. package/lib/asserts/number/maxExcluded.js +6 -47
  28. package/lib/asserts/number/maxExcluded.js.map +1 -1
  29. package/lib/asserts/number/maxExcluded.mjs +3 -17
  30. package/lib/asserts/number/maxExcluded.mjs.map +1 -1
  31. package/lib/asserts/number/min.js +6 -47
  32. package/lib/asserts/number/min.js.map +1 -1
  33. package/lib/asserts/number/min.mjs +3 -17
  34. package/lib/asserts/number/min.mjs.map +1 -1
  35. package/lib/asserts/number/minExcluded.js +6 -47
  36. package/lib/asserts/number/minExcluded.js.map +1 -1
  37. package/lib/asserts/number/minExcluded.mjs +3 -17
  38. package/lib/asserts/number/minExcluded.mjs.map +1 -1
  39. package/lib/asserts/number/negative.js +6 -47
  40. package/lib/asserts/number/negative.js.map +1 -1
  41. package/lib/asserts/number/negative.mjs +3 -17
  42. package/lib/asserts/number/negative.mjs.map +1 -1
  43. package/lib/asserts/number/positive.js +6 -47
  44. package/lib/asserts/number/positive.js.map +1 -1
  45. package/lib/asserts/number/positive.mjs +3 -17
  46. package/lib/asserts/number/positive.mjs.map +1 -1
  47. package/lib/asserts/object/index.js +7 -90
  48. package/lib/asserts/object/index.js.map +1 -1
  49. package/lib/asserts/object/index.mjs +7 -63
  50. package/lib/asserts/object/index.mjs.map +1 -1
  51. package/lib/asserts/string/email.js +6 -47
  52. package/lib/asserts/string/email.js.map +1 -1
  53. package/lib/asserts/string/email.mjs +3 -17
  54. package/lib/asserts/string/email.mjs.map +1 -1
  55. package/lib/asserts/string/index.js +8 -108
  56. package/lib/asserts/string/index.js.map +1 -1
  57. package/lib/asserts/string/index.mjs +8 -81
  58. package/lib/asserts/string/index.mjs.map +1 -1
  59. package/lib/asserts/string/maxLength.js +6 -47
  60. package/lib/asserts/string/maxLength.js.map +1 -1
  61. package/lib/asserts/string/maxLength.mjs +3 -17
  62. package/lib/asserts/string/maxLength.mjs.map +1 -1
  63. package/lib/asserts/string/minLength.js +6 -47
  64. package/lib/asserts/string/minLength.js.map +1 -1
  65. package/lib/asserts/string/minLength.mjs +3 -17
  66. package/lib/asserts/string/minLength.mjs.map +1 -1
  67. package/lib/asserts/string/regExp.js +6 -47
  68. package/lib/asserts/string/regExp.js.map +1 -1
  69. package/lib/asserts/string/regExp.mjs +3 -17
  70. package/lib/asserts/string/regExp.mjs.map +1 -1
  71. package/lib/chunk-2AP4OQMT.js +26 -0
  72. package/lib/chunk-2AP4OQMT.js.map +1 -0
  73. package/lib/chunk-32IQXZRK.mjs +13 -0
  74. package/lib/chunk-32IQXZRK.mjs.map +1 -0
  75. package/lib/chunk-3FEJUC3K.mjs +13 -0
  76. package/lib/chunk-3FEJUC3K.mjs.map +1 -0
  77. package/lib/chunk-5NCJN6D2.js +70 -0
  78. package/lib/chunk-5NCJN6D2.js.map +1 -0
  79. package/lib/chunk-5ZMICHV3.js +21 -0
  80. package/lib/chunk-5ZMICHV3.js.map +1 -0
  81. package/lib/chunk-63IQFNFO.mjs +27 -0
  82. package/lib/chunk-63IQFNFO.mjs.map +1 -0
  83. package/lib/chunk-A2SAWKJA.mjs +13 -0
  84. package/lib/chunk-A2SAWKJA.mjs.map +1 -0
  85. package/lib/chunk-A3UTB4RE.mjs +28 -0
  86. package/lib/chunk-A3UTB4RE.mjs.map +1 -0
  87. package/lib/chunk-A7I2JEQO.js +13 -0
  88. package/lib/chunk-A7I2JEQO.js.map +1 -0
  89. package/lib/chunk-AJ4WV5DG.mjs +13 -0
  90. package/lib/chunk-AJ4WV5DG.mjs.map +1 -0
  91. package/lib/chunk-APTTIN2L.js +42 -0
  92. package/lib/chunk-APTTIN2L.js.map +1 -0
  93. package/lib/chunk-AXOP6HPJ.js +14 -0
  94. package/lib/chunk-AXOP6HPJ.js.map +1 -0
  95. package/lib/chunk-BGMR7A6X.mjs +13 -0
  96. package/lib/chunk-BGMR7A6X.mjs.map +1 -0
  97. package/lib/chunk-FCFO5J5Y.mjs +14 -0
  98. package/lib/chunk-FCFO5J5Y.mjs.map +1 -0
  99. package/lib/chunk-GEZME6V2.mjs +39 -0
  100. package/lib/chunk-GEZME6V2.mjs.map +1 -0
  101. package/lib/chunk-GNBSKTFV.js +27 -0
  102. package/lib/chunk-GNBSKTFV.js.map +1 -0
  103. package/lib/chunk-IQ3QYABE.js +32 -0
  104. package/lib/chunk-IQ3QYABE.js.map +1 -0
  105. package/lib/chunk-K2S3FS5K.js +13 -0
  106. package/lib/chunk-K2S3FS5K.js.map +1 -0
  107. package/lib/chunk-KCBOOOTF.mjs +13 -0
  108. package/lib/chunk-KCBOOOTF.mjs.map +1 -0
  109. package/lib/chunk-L6A7NXUJ.js +13 -0
  110. package/lib/chunk-L6A7NXUJ.js.map +1 -0
  111. package/lib/chunk-L7HUXYFV.mjs +42 -0
  112. package/lib/chunk-L7HUXYFV.mjs.map +1 -0
  113. package/lib/chunk-LHTJHMKJ.mjs +27 -0
  114. package/lib/chunk-LHTJHMKJ.mjs.map +1 -0
  115. package/lib/chunk-NOADI6PO.mjs +21 -0
  116. package/lib/chunk-NOADI6PO.mjs.map +1 -0
  117. package/lib/chunk-NWY33MFU.js +13 -0
  118. package/lib/chunk-NWY33MFU.js.map +1 -0
  119. package/lib/chunk-P3Y6IWFA.mjs +70 -0
  120. package/lib/chunk-P3Y6IWFA.mjs.map +1 -0
  121. package/lib/chunk-PDVXBE27.js +27 -0
  122. package/lib/chunk-PDVXBE27.js.map +1 -0
  123. package/lib/chunk-PJP63SJT.js +13 -0
  124. package/lib/chunk-PJP63SJT.js.map +1 -0
  125. package/lib/chunk-QJOXKH7A.mjs +26 -0
  126. package/lib/chunk-QJOXKH7A.mjs.map +1 -0
  127. package/lib/chunk-QKGQ4XZC.js +13 -0
  128. package/lib/chunk-QKGQ4XZC.js.map +1 -0
  129. package/lib/chunk-QYLH5ZAC.mjs +32 -0
  130. package/lib/chunk-QYLH5ZAC.mjs.map +1 -0
  131. package/lib/chunk-VPFIIM2X.js +39 -0
  132. package/lib/chunk-VPFIIM2X.js.map +1 -0
  133. package/lib/chunk-YXHH5BF6.js +28 -0
  134. package/lib/chunk-YXHH5BF6.js.map +1 -0
  135. package/lib/core.js +6 -107
  136. package/lib/core.js.map +1 -1
  137. package/lib/core.mjs +5 -78
  138. package/lib/core.mjs.map +1 -1
  139. package/lib/exceptions.js +9 -50
  140. package/lib/exceptions.js.map +1 -1
  141. package/lib/exceptions.mjs +5 -19
  142. package/lib/exceptions.mjs.map +1 -1
  143. package/lib/index.js +29 -283
  144. package/lib/index.js.map +1 -1
  145. package/lib/index.mjs +34 -252
  146. package/lib/index.mjs.map +1 -1
  147. package/lib/parseSchema.js +5 -115
  148. package/lib/parseSchema.js.map +1 -1
  149. package/lib/parseSchema.mjs +5 -88
  150. package/lib/parseSchema.mjs.map +1 -1
  151. package/lib/schemas/ArraySchema.js +6 -81
  152. package/lib/schemas/ArraySchema.js.map +1 -1
  153. package/lib/schemas/ArraySchema.mjs +6 -54
  154. package/lib/schemas/ArraySchema.mjs.map +1 -1
  155. package/lib/schemas/BooleanSchema.js +6 -109
  156. package/lib/schemas/BooleanSchema.js.map +1 -1
  157. package/lib/schemas/BooleanSchema.mjs +6 -82
  158. package/lib/schemas/BooleanSchema.mjs.map +1 -1
  159. package/lib/schemas/CommonSchema.js +5 -63
  160. package/lib/schemas/CommonSchema.js.map +1 -1
  161. package/lib/schemas/CommonSchema.mjs +5 -36
  162. package/lib/schemas/CommonSchema.mjs.map +1 -1
  163. package/lib/schemas/NumberSchema.js +7 -103
  164. package/lib/schemas/NumberSchema.js.map +1 -1
  165. package/lib/schemas/NumberSchema.mjs +7 -76
  166. package/lib/schemas/NumberSchema.mjs.map +1 -1
  167. package/lib/schemas/ObjectSchema.js +6 -85
  168. package/lib/schemas/ObjectSchema.js.map +1 -1
  169. package/lib/schemas/ObjectSchema.mjs +6 -58
  170. package/lib/schemas/ObjectSchema.mjs.map +1 -1
  171. package/lib/schemas/StringSchema.js +7 -103
  172. package/lib/schemas/StringSchema.js.map +1 -1
  173. package/lib/schemas/StringSchema.mjs +7 -76
  174. package/lib/schemas/StringSchema.mjs.map +1 -1
  175. package/package.json +15 -14
  176. package/lib/__tests__/ArraySchema.test.d.mts +0 -2
  177. package/lib/__tests__/ArraySchema.test.d.ts +0 -2
  178. package/lib/__tests__/ArraySchema.test.js +0 -201
  179. package/lib/__tests__/ArraySchema.test.js.map +0 -1
  180. package/lib/__tests__/ArraySchema.test.mjs +0 -199
  181. package/lib/__tests__/ArraySchema.test.mjs.map +0 -1
  182. package/lib/__tests__/BooleanSchema.test.d.mts +0 -2
  183. package/lib/__tests__/BooleanSchema.test.d.ts +0 -2
  184. package/lib/__tests__/BooleanSchema.test.js +0 -219
  185. package/lib/__tests__/BooleanSchema.test.js.map +0 -1
  186. package/lib/__tests__/BooleanSchema.test.mjs +0 -217
  187. package/lib/__tests__/BooleanSchema.test.mjs.map +0 -1
  188. package/lib/__tests__/CommonSchema.test.d.mts +0 -2
  189. package/lib/__tests__/CommonSchema.test.d.ts +0 -2
  190. package/lib/__tests__/CommonSchema.test.js +0 -253
  191. package/lib/__tests__/CommonSchema.test.js.map +0 -1
  192. package/lib/__tests__/CommonSchema.test.mjs +0 -251
  193. package/lib/__tests__/CommonSchema.test.mjs.map +0 -1
  194. package/lib/__tests__/MixTypes.test.d.mts +0 -2
  195. package/lib/__tests__/MixTypes.test.d.ts +0 -2
  196. package/lib/__tests__/MixTypes.test.js +0 -165
  197. package/lib/__tests__/MixTypes.test.js.map +0 -1
  198. package/lib/__tests__/MixTypes.test.mjs +0 -163
  199. package/lib/__tests__/MixTypes.test.mjs.map +0 -1
  200. package/lib/__tests__/NumberSchema.test.d.mts +0 -2
  201. package/lib/__tests__/NumberSchema.test.d.ts +0 -2
  202. package/lib/__tests__/NumberSchema.test.js +0 -253
  203. package/lib/__tests__/NumberSchema.test.js.map +0 -1
  204. package/lib/__tests__/NumberSchema.test.mjs +0 -251
  205. package/lib/__tests__/NumberSchema.test.mjs.map +0 -1
  206. package/lib/__tests__/ObjectSchema.test.d.mts +0 -2
  207. package/lib/__tests__/ObjectSchema.test.d.ts +0 -2
  208. package/lib/__tests__/ObjectSchema.test.js +0 -356
  209. package/lib/__tests__/ObjectSchema.test.js.map +0 -1
  210. package/lib/__tests__/ObjectSchema.test.mjs +0 -354
  211. package/lib/__tests__/ObjectSchema.test.mjs.map +0 -1
  212. package/lib/__tests__/StringSchema.test.d.mts +0 -2
  213. package/lib/__tests__/StringSchema.test.d.ts +0 -2
  214. package/lib/__tests__/StringSchema.test.js +0 -228
  215. package/lib/__tests__/StringSchema.test.js.map +0 -1
  216. package/lib/__tests__/StringSchema.test.mjs +0 -226
  217. package/lib/__tests__/StringSchema.test.mjs.map +0 -1
package/lib/InferType.js CHANGED
@@ -1,19 +1 @@
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 __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
-
16
- // src/InferType.ts
17
- var InferType_exports = {};
18
- module.exports = __toCommonJS(InferType_exports);
19
- //# sourceMappingURL=InferType.js.map
1
+ "use strict";//# sourceMappingURL=InferType.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/InferType.ts"],"sourcesContent":["import type { ArraySchema, ExtractFromArray } from './schemas/ArraySchema';\nimport type { BooleanSchema, ExtractFromBoolean, WithBoolean } from './schemas/BooleanSchema';\nimport type { CommonSchema, ExtractFromMix, WithMix, WithNull, WithUndefined } from './schemas/CommonSchema';\nimport type { ExtractFromNumber, NumberSchema, WithNumber } from './schemas/NumberSchema';\nimport type { ObjectSchema, WithObject } from './schemas/ObjectSchema';\nimport type { ExtractFromString, StringSchema, WithString } from './schemas/StringSchema';\n\n// prettier-ignore\nexport type InferType<T> =\n // with string\n T extends WithUndefined<WithNull<WithString<StringSchema>>>\n ? ExtractFromString<T> | null | undefined\n : T extends WithUndefined<WithString<StringSchema>>\n ? ExtractFromString<T> | undefined\n : T extends WithNull<WithString<StringSchema>>\n ? ExtractFromString<T> | null\n : T extends WithString<StringSchema>\n ? ExtractFromString<T> \n\n // string\n : T extends WithUndefined<WithNull<StringSchema>>\n ? string | null | undefined\n : T extends WithUndefined<StringSchema>\n ? string | undefined\n : T extends WithNull<StringSchema>\n ? string | null\n : T extends StringSchema\n ? string\n\n : // with number\n T extends WithUndefined<WithNull<WithNumber<NumberSchema>>>\n ? ExtractFromNumber<T> | null | undefined\n : T extends WithUndefined<WithNumber<NumberSchema>>\n ? ExtractFromNumber<T> | undefined\n : T extends WithNull<WithNumber<NumberSchema>>\n ? ExtractFromNumber<T> | null\n : T extends WithNumber<NumberSchema>\n ? ExtractFromNumber<T>\n\n : // number\n T extends WithUndefined<WithNull<NumberSchema>>\n ? number | null | undefined\n : T extends WithUndefined<NumberSchema>\n ? number | undefined\n : T extends WithNull<NumberSchema>\n ? number | null\n : T extends NumberSchema\n ? number\n\n : // with boolean\n T extends WithUndefined<WithNull<WithBoolean<BooleanSchema>>>\n ? ExtractFromBoolean<T> | null | undefined\n : T extends WithUndefined<WithBoolean<BooleanSchema>>\n ? ExtractFromBoolean<T> | undefined\n : T extends WithNull<WithBoolean<BooleanSchema>>\n ? ExtractFromBoolean<T> | null\n : T extends WithBoolean<BooleanSchema>\n ? ExtractFromBoolean<T>\n\n : // boolean\n T extends WithUndefined<WithNull<BooleanSchema>>\n ? boolean | null | undefined\n : T extends WithUndefined<BooleanSchema>\n ? boolean | undefined\n : T extends WithNull<BooleanSchema>\n ? boolean | null\n : T extends BooleanSchema\n ? boolean\n\n : // array\n T extends WithUndefined<WithNull<ArraySchema>>\n ? InferType<ExtractFromArray<T>>[] | null | undefined\n : T extends WithUndefined<ArraySchema>\n ? InferType<ExtractFromArray<T>>[] | undefined\n : T extends WithNull<ArraySchema>\n ? InferType<ExtractFromArray<T>>[] | null\n : T extends ArraySchema\n ? InferType<ExtractFromArray<T>>[]\n\n : // object\n T extends WithUndefined<WithNull<ObjectSchema>>\n ? ExtractFromObject<T> | null | undefined\n : T extends WithUndefined<ObjectSchema>\n ? ExtractFromObject<T> | undefined\n : T extends WithNull<ObjectSchema>\n ? ExtractFromObject<T> | null\n : T extends ObjectSchema\n ? ExtractFromObject<T>\n\n : // with mix\n T extends WithUndefined<WithNull<WithMix>>\n ? ExtractFromMix<T> | null | undefined\n : T extends WithUndefined<WithMix>\n ? ExtractFromMix<T> | undefined\n : T extends WithNull<WithMix>\n ? ExtractFromMix<T> | null\n : T extends WithMix\n ? ExtractFromMix<T>\n\n : unknown;\n\ntype Merge<T> = T extends infer U ? { [K in keyof U]: U[K] } : never;\n\ntype ExtractFromObject<T extends ObjectSchema> =\n T extends WithObject<infer X>\n ? Merge<\n { [K in keyof X as X[K] extends WithUndefined<CommonSchema> ? never : K]: InferType<X[K]> } & {\n [K in keyof X as X[K] extends WithUndefined<CommonSchema> ? K : never]?: InferType<X[K]>;\n }\n >\n : unknown;\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["/home/runner/work/bguard/bguard/lib/InferType.js"],"names":[],"mappings":"AAAA","file":"/home/runner/work/bguard/bguard/lib/InferType.js"}
@@ -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
- // src/asserts/array/index.ts
21
- var array_exports = {};
22
- __export(array_exports, {
23
- array: () => array
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
- // src/core.ts
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":["../../../src/asserts/array/index.ts","../../../src/exceptions.ts","../../../src/core.ts","../../../src/schemas/CommonSchema.ts","../../../src/schemas/ArraySchema.ts"],"sourcesContent":["import { ArraySchema, WithArray } from '../../schemas/ArraySchema';\nimport { CommonSchema } from '../../schemas/CommonSchema';\n\n/**\n * Creates a new schema for validating arrays where each element must match the specified schema.\n *\n * @template T\n * @param {T} arraySchema - The schema that each element of the array must match.\n * @returns {WithArray<T>} A new instance of `ArraySchema` for validating arrays of elements that match the specified schema.\n *\n * @example\n * const schema = array(string());\n * parseSchema(schema, ['hello', 'world']); // Validates successfully\n * parseSchema(schema, ['hello', 123]); // Throws a validation error\n */\nexport function array<T extends CommonSchema>(arraySchema: T): WithArray<T> {\n return new ArraySchema({ type: [], requiredValidations: [] }, arraySchema) as WithArray<T>;\n}\n","export class ValidationError extends Error {\n expected: unknown;\n received: unknown;\n pathToError: string;\n message: string;\n constructor(expected: unknown, received: unknown, pathToError: string, message: string) {\n super();\n this.expected = expected;\n this.received = received;\n this.pathToError = pathToError;\n this.message = message;\n }\n}\n\nexport class BuildSchemaError extends Error {}\n\nexport function throwException(expected: unknown, received: unknown, pathToError: string, message: string): never {\n throw new ValidationError(expected, received, pathToError, message);\n}\n","export const ctxSymbol = Symbol('contextSymbol');\n\nimport { throwException } from './exceptions';\nimport type { CommonSchema } from './schemas/CommonSchema';\n\nexport function innerCheck(schema: CommonSchema, receivedValue: unknown, pathToError: string) {\n const ctx = schema[ctxSymbol];\n if (receivedValue === undefined) {\n if (!ctx.isOptional) throwException('Required', receivedValue, pathToError, 'The required value is missing');\n return receivedValue;\n }\n\n if (receivedValue === null) {\n if (!ctx.isNullable) throwException('Not null', receivedValue, pathToError, 'Value should not be null');\n return receivedValue;\n }\n\n if (ctx.array) {\n if (!Array.isArray(receivedValue))\n throwException('Array', receivedValue, pathToError, 'Expected an array but received a different type');\n const schema = ctx.array;\n\n receivedValue.forEach((elem, i) => {\n innerCheck(schema, elem, `${pathToError}[${i}]`);\n });\n\n return receivedValue;\n }\n\n const typeOfVal = typeof receivedValue;\n\n if (ctx.object) {\n if (typeOfVal !== 'object')\n throwException('Object', receivedValue, pathToError, 'Expected an object but received a different type');\n if (Array.isArray(receivedValue))\n throwException(\n 'Object',\n receivedValue,\n pathToError,\n 'Expected an object but received an array. Invalid type of data',\n );\n const shapeSchema = ctx.object;\n for (const keyPerReceivedValue of Object.keys(receivedValue)) {\n if (shapeSchema[keyPerReceivedValue] === undefined)\n throwException('Not allowed', keyPerReceivedValue, pathToError, 'This key is not allowed in the object');\n }\n\n for (const [keyOfSchema, valueOfSchema] of Object.entries(shapeSchema)) {\n const receivedObjectValuePropery = (receivedValue as Record<string, unknown>)[keyOfSchema];\n if (receivedObjectValuePropery === undefined) {\n if (!valueOfSchema[ctxSymbol].isOptional)\n throwException(\n 'Required',\n receivedObjectValuePropery,\n pathToError,\n 'Missing required property in the object',\n );\n }\n innerCheck(valueOfSchema, receivedObjectValuePropery, `${pathToError}.${keyOfSchema}`);\n }\n\n return receivedValue;\n }\n\n if (ctx.type.length) {\n if (!ctx.type.includes(typeOfVal)) throwException(ctx.type, typeOfVal, pathToError, 'Invalid type of data');\n }\n\n ctx.requiredValidations.forEach((requiredValidation) => {\n requiredValidation(receivedValue, pathToError);\n });\n\n return receivedValue;\n}\n","import { ctxSymbol } from '../core';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type RequiredValidation = (received: any, pathToError: string) => void;\nexport type ObjectShapeSchemaType = Record<string, CommonSchema>;\n\nexport type PrimitiveType = 'number' | 'string' | 'boolean' | 'undefined' | 'object' | 'function' | 'symbol' | 'bigint';\nexport interface ValidatorContext {\n type: PrimitiveType[];\n isNullable?: boolean;\n isOptional?: boolean;\n requiredValidations: RequiredValidation[];\n array?: CommonSchema;\n object?: ObjectShapeSchemaType;\n}\n\nexport class CommonSchema {\n [ctxSymbol]: ValidatorContext;\n constructor(ctx: ValidatorContext) {\n this[ctxSymbol] = ctx;\n }\n\n /**\n * @param validators - One or more custom validation functions.\n * @returns {this} The schema instance with the added custom validation.\n */\n custom(...validators: RequiredValidation[]): this {\n this[ctxSymbol].requiredValidations.push(...validators);\n return this;\n }\n\n /**\n * Marks the schema as nullable, allowing the value to be `null`.\n *\n * @returns {WithNull<this>} The schema instance marked as nullable.\n */\n nullable(): WithNull<this> {\n this[ctxSymbol].isNullable = true;\n return this as WithNull<this>;\n }\n\n /**\n * Marks the schema as optional, allowing the value to be `undefined`.\n *\n * @returns {WithUndefined<this>}} The schema instance marked as optional.\n */\n optional(): WithUndefined<this> {\n this[ctxSymbol].isOptional = true;\n return this as WithUndefined<this>;\n }\n}\n\nexport type WithNull<T extends CommonSchema> = T & { validation_null: true };\nexport type WithUndefined<T extends CommonSchema> = T & { validation_undefined: true };\n\ntype TypeMapping = {\n number: number;\n string: string;\n boolean: boolean;\n undefined: undefined;\n object: object;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n function: Function;\n symbol: symbol;\n bigint: bigint;\n};\n\nexport type WithMix<Y = unknown> = CommonSchema & { validation_mix: Y };\nexport type ExtractFromMix<T> = T extends WithMix<infer X> ? X : never;\n\nexport type MapMixTypes<T extends PrimitiveType[]> = T extends (infer U)[]\n ? U extends keyof TypeMapping\n ? TypeMapping[U]\n : never\n : never;\n","import { ctxSymbol } from '../core';\nimport { BuildSchemaError } from '../exceptions';\nimport { CommonSchema, ValidatorContext } from './CommonSchema';\n\nexport class ArraySchema extends CommonSchema {\n _array = 1;\n constructor(ctx: ValidatorContext, arraySchema: CommonSchema) {\n super(ctx);\n this.validateArrayEntry(arraySchema);\n this[ctxSymbol].array = arraySchema;\n }\n\n private validateArrayEntry(arraySchema: CommonSchema) {\n if (!arraySchema) throw new BuildSchemaError('Missing schema in array method');\n if (!(arraySchema instanceof CommonSchema)) throw new BuildSchemaError('Invalid schema in array method');\n }\n}\n\nexport type WithArray<Y extends CommonSchema> = ArraySchema & { validation_array: Y };\nexport type ExtractFromArray<T> = T extends WithArray<infer X> ? X : never;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACcO,IAAM,mBAAN,cAA+B,MAAM;AAAC;;;ACdtC,IAAM,YAAY,OAAO,eAAe;;;ACgBxC,IAAM,eAAN,MAAmB;AAAA,EACxB,CAAC,SAAS;AAAA,EACV,YAAY,KAAuB;AACjC,SAAK,SAAS,IAAI;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,UAAU,YAAwC;AAChD,SAAK,SAAS,EAAE,oBAAoB,KAAK,GAAG,UAAU;AACtD,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,WAA2B;AACzB,SAAK,SAAS,EAAE,aAAa;AAC7B,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,WAAgC;AAC9B,SAAK,SAAS,EAAE,aAAa;AAC7B,WAAO;AAAA,EACT;AACF;;;AC9CO,IAAM,cAAN,cAA0B,aAAa;AAAA,EAC5C,SAAS;AAAA,EACT,YAAY,KAAuB,aAA2B;AAC5D,UAAM,GAAG;AACT,SAAK,mBAAmB,WAAW;AACnC,SAAK,SAAS,EAAE,QAAQ;AAAA,EAC1B;AAAA,EAEQ,mBAAmB,aAA2B;AACpD,QAAI,CAAC,YAAa,OAAM,IAAI,iBAAiB,gCAAgC;AAC7E,QAAI,EAAE,uBAAuB,cAAe,OAAM,IAAI,iBAAiB,gCAAgC;AAAA,EACzG;AACF;;;AJDO,SAAS,MAA8B,aAA8B;AAC1E,SAAO,IAAI,YAAY,EAAE,MAAM,CAAC,GAAG,qBAAqB,CAAC,EAAE,GAAG,WAAW;AAC3E;","names":[]}
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
- // src/exceptions.ts
2
- var BuildSchemaError = class extends Error {
3
- };
4
-
5
- // src/core.ts
6
- var ctxSymbol = Symbol("contextSymbol");
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":["../../../src/exceptions.ts","../../../src/core.ts","../../../src/schemas/CommonSchema.ts","../../../src/schemas/ArraySchema.ts","../../../src/asserts/array/index.ts"],"sourcesContent":["export class ValidationError extends Error {\n expected: unknown;\n received: unknown;\n pathToError: string;\n message: string;\n constructor(expected: unknown, received: unknown, pathToError: string, message: string) {\n super();\n this.expected = expected;\n this.received = received;\n this.pathToError = pathToError;\n this.message = message;\n }\n}\n\nexport class BuildSchemaError extends Error {}\n\nexport function throwException(expected: unknown, received: unknown, pathToError: string, message: string): never {\n throw new ValidationError(expected, received, pathToError, message);\n}\n","export const ctxSymbol = Symbol('contextSymbol');\n\nimport { throwException } from './exceptions';\nimport type { CommonSchema } from './schemas/CommonSchema';\n\nexport function innerCheck(schema: CommonSchema, receivedValue: unknown, pathToError: string) {\n const ctx = schema[ctxSymbol];\n if (receivedValue === undefined) {\n if (!ctx.isOptional) throwException('Required', receivedValue, pathToError, 'The required value is missing');\n return receivedValue;\n }\n\n if (receivedValue === null) {\n if (!ctx.isNullable) throwException('Not null', receivedValue, pathToError, 'Value should not be null');\n return receivedValue;\n }\n\n if (ctx.array) {\n if (!Array.isArray(receivedValue))\n throwException('Array', receivedValue, pathToError, 'Expected an array but received a different type');\n const schema = ctx.array;\n\n receivedValue.forEach((elem, i) => {\n innerCheck(schema, elem, `${pathToError}[${i}]`);\n });\n\n return receivedValue;\n }\n\n const typeOfVal = typeof receivedValue;\n\n if (ctx.object) {\n if (typeOfVal !== 'object')\n throwException('Object', receivedValue, pathToError, 'Expected an object but received a different type');\n if (Array.isArray(receivedValue))\n throwException(\n 'Object',\n receivedValue,\n pathToError,\n 'Expected an object but received an array. Invalid type of data',\n );\n const shapeSchema = ctx.object;\n for (const keyPerReceivedValue of Object.keys(receivedValue)) {\n if (shapeSchema[keyPerReceivedValue] === undefined)\n throwException('Not allowed', keyPerReceivedValue, pathToError, 'This key is not allowed in the object');\n }\n\n for (const [keyOfSchema, valueOfSchema] of Object.entries(shapeSchema)) {\n const receivedObjectValuePropery = (receivedValue as Record<string, unknown>)[keyOfSchema];\n if (receivedObjectValuePropery === undefined) {\n if (!valueOfSchema[ctxSymbol].isOptional)\n throwException(\n 'Required',\n receivedObjectValuePropery,\n pathToError,\n 'Missing required property in the object',\n );\n }\n innerCheck(valueOfSchema, receivedObjectValuePropery, `${pathToError}.${keyOfSchema}`);\n }\n\n return receivedValue;\n }\n\n if (ctx.type.length) {\n if (!ctx.type.includes(typeOfVal)) throwException(ctx.type, typeOfVal, pathToError, 'Invalid type of data');\n }\n\n ctx.requiredValidations.forEach((requiredValidation) => {\n requiredValidation(receivedValue, pathToError);\n });\n\n return receivedValue;\n}\n","import { ctxSymbol } from '../core';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type RequiredValidation = (received: any, pathToError: string) => void;\nexport type ObjectShapeSchemaType = Record<string, CommonSchema>;\n\nexport type PrimitiveType = 'number' | 'string' | 'boolean' | 'undefined' | 'object' | 'function' | 'symbol' | 'bigint';\nexport interface ValidatorContext {\n type: PrimitiveType[];\n isNullable?: boolean;\n isOptional?: boolean;\n requiredValidations: RequiredValidation[];\n array?: CommonSchema;\n object?: ObjectShapeSchemaType;\n}\n\nexport class CommonSchema {\n [ctxSymbol]: ValidatorContext;\n constructor(ctx: ValidatorContext) {\n this[ctxSymbol] = ctx;\n }\n\n /**\n * @param validators - One or more custom validation functions.\n * @returns {this} The schema instance with the added custom validation.\n */\n custom(...validators: RequiredValidation[]): this {\n this[ctxSymbol].requiredValidations.push(...validators);\n return this;\n }\n\n /**\n * Marks the schema as nullable, allowing the value to be `null`.\n *\n * @returns {WithNull<this>} The schema instance marked as nullable.\n */\n nullable(): WithNull<this> {\n this[ctxSymbol].isNullable = true;\n return this as WithNull<this>;\n }\n\n /**\n * Marks the schema as optional, allowing the value to be `undefined`.\n *\n * @returns {WithUndefined<this>}} The schema instance marked as optional.\n */\n optional(): WithUndefined<this> {\n this[ctxSymbol].isOptional = true;\n return this as WithUndefined<this>;\n }\n}\n\nexport type WithNull<T extends CommonSchema> = T & { validation_null: true };\nexport type WithUndefined<T extends CommonSchema> = T & { validation_undefined: true };\n\ntype TypeMapping = {\n number: number;\n string: string;\n boolean: boolean;\n undefined: undefined;\n object: object;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n function: Function;\n symbol: symbol;\n bigint: bigint;\n};\n\nexport type WithMix<Y = unknown> = CommonSchema & { validation_mix: Y };\nexport type ExtractFromMix<T> = T extends WithMix<infer X> ? X : never;\n\nexport type MapMixTypes<T extends PrimitiveType[]> = T extends (infer U)[]\n ? U extends keyof TypeMapping\n ? TypeMapping[U]\n : never\n : never;\n","import { ctxSymbol } from '../core';\nimport { BuildSchemaError } from '../exceptions';\nimport { CommonSchema, ValidatorContext } from './CommonSchema';\n\nexport class ArraySchema extends CommonSchema {\n _array = 1;\n constructor(ctx: ValidatorContext, arraySchema: CommonSchema) {\n super(ctx);\n this.validateArrayEntry(arraySchema);\n this[ctxSymbol].array = arraySchema;\n }\n\n private validateArrayEntry(arraySchema: CommonSchema) {\n if (!arraySchema) throw new BuildSchemaError('Missing schema in array method');\n if (!(arraySchema instanceof CommonSchema)) throw new BuildSchemaError('Invalid schema in array method');\n }\n}\n\nexport type WithArray<Y extends CommonSchema> = ArraySchema & { validation_array: Y };\nexport type ExtractFromArray<T> = T extends WithArray<infer X> ? X : never;\n","import { ArraySchema, WithArray } from '../../schemas/ArraySchema';\nimport { CommonSchema } from '../../schemas/CommonSchema';\n\n/**\n * Creates a new schema for validating arrays where each element must match the specified schema.\n *\n * @template T\n * @param {T} arraySchema - The schema that each element of the array must match.\n * @returns {WithArray<T>} A new instance of `ArraySchema` for validating arrays of elements that match the specified schema.\n *\n * @example\n * const schema = array(string());\n * parseSchema(schema, ['hello', 'world']); // Validates successfully\n * parseSchema(schema, ['hello', 123]); // Throws a validation error\n */\nexport function array<T extends CommonSchema>(arraySchema: T): WithArray<T> {\n return new ArraySchema({ type: [], requiredValidations: [] }, arraySchema) as WithArray<T>;\n}\n"],"mappings":";AAcO,IAAM,mBAAN,cAA+B,MAAM;AAAC;;;ACdtC,IAAM,YAAY,OAAO,eAAe;;;ACgBxC,IAAM,eAAN,MAAmB;AAAA,EACxB,CAAC,SAAS;AAAA,EACV,YAAY,KAAuB;AACjC,SAAK,SAAS,IAAI;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,UAAU,YAAwC;AAChD,SAAK,SAAS,EAAE,oBAAoB,KAAK,GAAG,UAAU;AACtD,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,WAA2B;AACzB,SAAK,SAAS,EAAE,aAAa;AAC7B,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,WAAgC;AAC9B,SAAK,SAAS,EAAE,aAAa;AAC7B,WAAO;AAAA,EACT;AACF;;;AC9CO,IAAM,cAAN,cAA0B,aAAa;AAAA,EAC5C,SAAS;AAAA,EACT,YAAY,KAAuB,aAA2B;AAC5D,UAAM,GAAG;AACT,SAAK,mBAAmB,WAAW;AACnC,SAAK,SAAS,EAAE,QAAQ;AAAA,EAC1B;AAAA,EAEQ,mBAAmB,aAA2B;AACpD,QAAI,CAAC,YAAa,OAAM,IAAI,iBAAiB,gCAAgC;AAC7E,QAAI,EAAE,uBAAuB,cAAe,OAAM,IAAI,iBAAiB,gCAAgC;AAAA,EACzG;AACF;;;ACDO,SAAS,MAA8B,aAA8B;AAC1E,SAAO,IAAI,YAAY,EAAE,MAAM,CAAC,GAAG,qBAAqB,CAAC,EAAE,GAAG,WAAW;AAC3E;","names":[]}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -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
- // src/asserts/boolean/index.ts
21
- var boolean_exports = {};
22
- __export(boolean_exports, {
23
- boolean: () => boolean
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
- // src/core.ts
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":["../../../src/asserts/boolean/index.ts","../../../src/exceptions.ts","../../../src/core.ts","../../../src/schemas/CommonSchema.ts","../../../src/schemas/BooleanSchema.ts"],"sourcesContent":["import { BooleanSchema } from '../../schemas/BooleanSchema';\n\n/**\n * Creates a new schema for validating boolean values.\n *\n * @returns {BooleanSchema} A new instance of `BooleanSchema` for validating booleans.\n *\n * @example\n * const schema = boolean();\n * parseSchema(schema, true); // Validates successfully\n * parseSchema(schema, 'true'); // Throws a validation error\n */\nexport function boolean(): BooleanSchema {\n return new BooleanSchema({ type: ['boolean'], requiredValidations: [] });\n}\n","export class ValidationError extends Error {\n expected: unknown;\n received: unknown;\n pathToError: string;\n message: string;\n constructor(expected: unknown, received: unknown, pathToError: string, message: string) {\n super();\n this.expected = expected;\n this.received = received;\n this.pathToError = pathToError;\n this.message = message;\n }\n}\n\nexport class BuildSchemaError extends Error {}\n\nexport function throwException(expected: unknown, received: unknown, pathToError: string, message: string): never {\n throw new ValidationError(expected, received, pathToError, message);\n}\n","export const ctxSymbol = Symbol('contextSymbol');\n\nimport { throwException } from './exceptions';\nimport type { CommonSchema } from './schemas/CommonSchema';\n\nexport function innerCheck(schema: CommonSchema, receivedValue: unknown, pathToError: string) {\n const ctx = schema[ctxSymbol];\n if (receivedValue === undefined) {\n if (!ctx.isOptional) throwException('Required', receivedValue, pathToError, 'The required value is missing');\n return receivedValue;\n }\n\n if (receivedValue === null) {\n if (!ctx.isNullable) throwException('Not null', receivedValue, pathToError, 'Value should not be null');\n return receivedValue;\n }\n\n if (ctx.array) {\n if (!Array.isArray(receivedValue))\n throwException('Array', receivedValue, pathToError, 'Expected an array but received a different type');\n const schema = ctx.array;\n\n receivedValue.forEach((elem, i) => {\n innerCheck(schema, elem, `${pathToError}[${i}]`);\n });\n\n return receivedValue;\n }\n\n const typeOfVal = typeof receivedValue;\n\n if (ctx.object) {\n if (typeOfVal !== 'object')\n throwException('Object', receivedValue, pathToError, 'Expected an object but received a different type');\n if (Array.isArray(receivedValue))\n throwException(\n 'Object',\n receivedValue,\n pathToError,\n 'Expected an object but received an array. Invalid type of data',\n );\n const shapeSchema = ctx.object;\n for (const keyPerReceivedValue of Object.keys(receivedValue)) {\n if (shapeSchema[keyPerReceivedValue] === undefined)\n throwException('Not allowed', keyPerReceivedValue, pathToError, 'This key is not allowed in the object');\n }\n\n for (const [keyOfSchema, valueOfSchema] of Object.entries(shapeSchema)) {\n const receivedObjectValuePropery = (receivedValue as Record<string, unknown>)[keyOfSchema];\n if (receivedObjectValuePropery === undefined) {\n if (!valueOfSchema[ctxSymbol].isOptional)\n throwException(\n 'Required',\n receivedObjectValuePropery,\n pathToError,\n 'Missing required property in the object',\n );\n }\n innerCheck(valueOfSchema, receivedObjectValuePropery, `${pathToError}.${keyOfSchema}`);\n }\n\n return receivedValue;\n }\n\n if (ctx.type.length) {\n if (!ctx.type.includes(typeOfVal)) throwException(ctx.type, typeOfVal, pathToError, 'Invalid type of data');\n }\n\n ctx.requiredValidations.forEach((requiredValidation) => {\n requiredValidation(receivedValue, pathToError);\n });\n\n return receivedValue;\n}\n","import { ctxSymbol } from '../core';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type RequiredValidation = (received: any, pathToError: string) => void;\nexport type ObjectShapeSchemaType = Record<string, CommonSchema>;\n\nexport type PrimitiveType = 'number' | 'string' | 'boolean' | 'undefined' | 'object' | 'function' | 'symbol' | 'bigint';\nexport interface ValidatorContext {\n type: PrimitiveType[];\n isNullable?: boolean;\n isOptional?: boolean;\n requiredValidations: RequiredValidation[];\n array?: CommonSchema;\n object?: ObjectShapeSchemaType;\n}\n\nexport class CommonSchema {\n [ctxSymbol]: ValidatorContext;\n constructor(ctx: ValidatorContext) {\n this[ctxSymbol] = ctx;\n }\n\n /**\n * @param validators - One or more custom validation functions.\n * @returns {this} The schema instance with the added custom validation.\n */\n custom(...validators: RequiredValidation[]): this {\n this[ctxSymbol].requiredValidations.push(...validators);\n return this;\n }\n\n /**\n * Marks the schema as nullable, allowing the value to be `null`.\n *\n * @returns {WithNull<this>} The schema instance marked as nullable.\n */\n nullable(): WithNull<this> {\n this[ctxSymbol].isNullable = true;\n return this as WithNull<this>;\n }\n\n /**\n * Marks the schema as optional, allowing the value to be `undefined`.\n *\n * @returns {WithUndefined<this>}} The schema instance marked as optional.\n */\n optional(): WithUndefined<this> {\n this[ctxSymbol].isOptional = true;\n return this as WithUndefined<this>;\n }\n}\n\nexport type WithNull<T extends CommonSchema> = T & { validation_null: true };\nexport type WithUndefined<T extends CommonSchema> = T & { validation_undefined: true };\n\ntype TypeMapping = {\n number: number;\n string: string;\n boolean: boolean;\n undefined: undefined;\n object: object;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n function: Function;\n symbol: symbol;\n bigint: bigint;\n};\n\nexport type WithMix<Y = unknown> = CommonSchema & { validation_mix: Y };\nexport type ExtractFromMix<T> = T extends WithMix<infer X> ? X : never;\n\nexport type MapMixTypes<T extends PrimitiveType[]> = T extends (infer U)[]\n ? U extends keyof TypeMapping\n ? TypeMapping[U]\n : never\n : never;\n","import { CommonSchema } from './CommonSchema';\nimport { throwException } from '../exceptions';\n\nconst isBoolean = (expected: boolean) => (received: boolean, pathToError: string) => {\n if (received !== expected) throwException(expected, received, pathToError, `The received value is not ${expected}`);\n};\n\nexport class BooleanSchema extends CommonSchema {\n _boolean = 1;\n\n /**\n * Restricts the schema to exactly match the boolean value true and infers the true value as the TypeScript type.\n *\n * @returns - The schema instance restricted to the value true, with the true value inferred as the TypeScript type\n *\n * @example - boolean().onlyTrue(); // Infers the type true\n */\n onlyTrue(): WithBoolean<this, true> {\n return this.custom(isBoolean(true)) as WithBoolean<this, true>;\n }\n\n /**\n * Restricts the schema to exactly match the boolean value false and infers the false value as the TypeScript type.\n *\n * @returns - The schema instance restricted to the value false, with the false value inferred as the TypeScript type\n *\n * @example - boolean().onlyFalse(); // Infers the type false\n */\n onlyFalse(): WithBoolean<this, false> {\n return this.custom(isBoolean(false)) as WithBoolean<this, false>;\n }\n}\n\nexport type WithBoolean<T extends BooleanSchema, Y = boolean> = T & { validation_boolean: Y };\nexport type ExtractFromBoolean<T> = T extends WithBoolean<BooleanSchema, infer Y> ? Y : never;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,kBAAN,cAA8B,MAAM;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAAY,UAAmB,UAAmB,aAAqB,SAAiB;AACtF,UAAM;AACN,SAAK,WAAW;AAChB,SAAK,WAAW;AAChB,SAAK,cAAc;AACnB,SAAK,UAAU;AAAA,EACjB;AACF;AAIO,SAAS,eAAe,UAAmB,UAAmB,aAAqB,SAAwB;AAChH,QAAM,IAAI,gBAAgB,UAAU,UAAU,aAAa,OAAO;AACpE;;;AClBO,IAAM,YAAY,OAAO,eAAe;;;ACgBxC,IAAM,eAAN,MAAmB;AAAA,EACxB,CAAC,SAAS;AAAA,EACV,YAAY,KAAuB;AACjC,SAAK,SAAS,IAAI;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,UAAU,YAAwC;AAChD,SAAK,SAAS,EAAE,oBAAoB,KAAK,GAAG,UAAU;AACtD,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,WAA2B;AACzB,SAAK,SAAS,EAAE,aAAa;AAC7B,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,WAAgC;AAC9B,SAAK,SAAS,EAAE,aAAa;AAC7B,WAAO;AAAA,EACT;AACF;;;AC/CA,IAAM,YAAY,CAAC,aAAsB,CAAC,UAAmB,gBAAwB;AACnF,MAAI,aAAa,SAAU,gBAAe,UAAU,UAAU,aAAa,6BAA6B,QAAQ,EAAE;AACpH;AAEO,IAAM,gBAAN,cAA4B,aAAa;AAAA,EAC9C,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASX,WAAoC;AAClC,WAAO,KAAK,OAAO,UAAU,IAAI,CAAC;AAAA,EACpC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,YAAsC;AACpC,WAAO,KAAK,OAAO,UAAU,KAAK,CAAC;AAAA,EACrC;AACF;;;AJnBO,SAAS,UAAyB;AACvC,SAAO,IAAI,cAAc,EAAE,MAAM,CAAC,SAAS,GAAG,qBAAqB,CAAC,EAAE,CAAC;AACzE;","names":[]}
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
- // src/exceptions.ts
2
- var ValidationError = class extends Error {
3
- expected;
4
- received;
5
- pathToError;
6
- message;
7
- constructor(expected, received, pathToError, message) {
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
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/exceptions.ts","../../../src/core.ts","../../../src/schemas/CommonSchema.ts","../../../src/schemas/BooleanSchema.ts","../../../src/asserts/boolean/index.ts"],"sourcesContent":["export class ValidationError extends Error {\n expected: unknown;\n received: unknown;\n pathToError: string;\n message: string;\n constructor(expected: unknown, received: unknown, pathToError: string, message: string) {\n super();\n this.expected = expected;\n this.received = received;\n this.pathToError = pathToError;\n this.message = message;\n }\n}\n\nexport class BuildSchemaError extends Error {}\n\nexport function throwException(expected: unknown, received: unknown, pathToError: string, message: string): never {\n throw new ValidationError(expected, received, pathToError, message);\n}\n","export const ctxSymbol = Symbol('contextSymbol');\n\nimport { throwException } from './exceptions';\nimport type { CommonSchema } from './schemas/CommonSchema';\n\nexport function innerCheck(schema: CommonSchema, receivedValue: unknown, pathToError: string) {\n const ctx = schema[ctxSymbol];\n if (receivedValue === undefined) {\n if (!ctx.isOptional) throwException('Required', receivedValue, pathToError, 'The required value is missing');\n return receivedValue;\n }\n\n if (receivedValue === null) {\n if (!ctx.isNullable) throwException('Not null', receivedValue, pathToError, 'Value should not be null');\n return receivedValue;\n }\n\n if (ctx.array) {\n if (!Array.isArray(receivedValue))\n throwException('Array', receivedValue, pathToError, 'Expected an array but received a different type');\n const schema = ctx.array;\n\n receivedValue.forEach((elem, i) => {\n innerCheck(schema, elem, `${pathToError}[${i}]`);\n });\n\n return receivedValue;\n }\n\n const typeOfVal = typeof receivedValue;\n\n if (ctx.object) {\n if (typeOfVal !== 'object')\n throwException('Object', receivedValue, pathToError, 'Expected an object but received a different type');\n if (Array.isArray(receivedValue))\n throwException(\n 'Object',\n receivedValue,\n pathToError,\n 'Expected an object but received an array. Invalid type of data',\n );\n const shapeSchema = ctx.object;\n for (const keyPerReceivedValue of Object.keys(receivedValue)) {\n if (shapeSchema[keyPerReceivedValue] === undefined)\n throwException('Not allowed', keyPerReceivedValue, pathToError, 'This key is not allowed in the object');\n }\n\n for (const [keyOfSchema, valueOfSchema] of Object.entries(shapeSchema)) {\n const receivedObjectValuePropery = (receivedValue as Record<string, unknown>)[keyOfSchema];\n if (receivedObjectValuePropery === undefined) {\n if (!valueOfSchema[ctxSymbol].isOptional)\n throwException(\n 'Required',\n receivedObjectValuePropery,\n pathToError,\n 'Missing required property in the object',\n );\n }\n innerCheck(valueOfSchema, receivedObjectValuePropery, `${pathToError}.${keyOfSchema}`);\n }\n\n return receivedValue;\n }\n\n if (ctx.type.length) {\n if (!ctx.type.includes(typeOfVal)) throwException(ctx.type, typeOfVal, pathToError, 'Invalid type of data');\n }\n\n ctx.requiredValidations.forEach((requiredValidation) => {\n requiredValidation(receivedValue, pathToError);\n });\n\n return receivedValue;\n}\n","import { ctxSymbol } from '../core';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type RequiredValidation = (received: any, pathToError: string) => void;\nexport type ObjectShapeSchemaType = Record<string, CommonSchema>;\n\nexport type PrimitiveType = 'number' | 'string' | 'boolean' | 'undefined' | 'object' | 'function' | 'symbol' | 'bigint';\nexport interface ValidatorContext {\n type: PrimitiveType[];\n isNullable?: boolean;\n isOptional?: boolean;\n requiredValidations: RequiredValidation[];\n array?: CommonSchema;\n object?: ObjectShapeSchemaType;\n}\n\nexport class CommonSchema {\n [ctxSymbol]: ValidatorContext;\n constructor(ctx: ValidatorContext) {\n this[ctxSymbol] = ctx;\n }\n\n /**\n * @param validators - One or more custom validation functions.\n * @returns {this} The schema instance with the added custom validation.\n */\n custom(...validators: RequiredValidation[]): this {\n this[ctxSymbol].requiredValidations.push(...validators);\n return this;\n }\n\n /**\n * Marks the schema as nullable, allowing the value to be `null`.\n *\n * @returns {WithNull<this>} The schema instance marked as nullable.\n */\n nullable(): WithNull<this> {\n this[ctxSymbol].isNullable = true;\n return this as WithNull<this>;\n }\n\n /**\n * Marks the schema as optional, allowing the value to be `undefined`.\n *\n * @returns {WithUndefined<this>}} The schema instance marked as optional.\n */\n optional(): WithUndefined<this> {\n this[ctxSymbol].isOptional = true;\n return this as WithUndefined<this>;\n }\n}\n\nexport type WithNull<T extends CommonSchema> = T & { validation_null: true };\nexport type WithUndefined<T extends CommonSchema> = T & { validation_undefined: true };\n\ntype TypeMapping = {\n number: number;\n string: string;\n boolean: boolean;\n undefined: undefined;\n object: object;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n function: Function;\n symbol: symbol;\n bigint: bigint;\n};\n\nexport type WithMix<Y = unknown> = CommonSchema & { validation_mix: Y };\nexport type ExtractFromMix<T> = T extends WithMix<infer X> ? X : never;\n\nexport type MapMixTypes<T extends PrimitiveType[]> = T extends (infer U)[]\n ? U extends keyof TypeMapping\n ? TypeMapping[U]\n : never\n : never;\n","import { CommonSchema } from './CommonSchema';\nimport { throwException } from '../exceptions';\n\nconst isBoolean = (expected: boolean) => (received: boolean, pathToError: string) => {\n if (received !== expected) throwException(expected, received, pathToError, `The received value is not ${expected}`);\n};\n\nexport class BooleanSchema extends CommonSchema {\n _boolean = 1;\n\n /**\n * Restricts the schema to exactly match the boolean value true and infers the true value as the TypeScript type.\n *\n * @returns - The schema instance restricted to the value true, with the true value inferred as the TypeScript type\n *\n * @example - boolean().onlyTrue(); // Infers the type true\n */\n onlyTrue(): WithBoolean<this, true> {\n return this.custom(isBoolean(true)) as WithBoolean<this, true>;\n }\n\n /**\n * Restricts the schema to exactly match the boolean value false and infers the false value as the TypeScript type.\n *\n * @returns - The schema instance restricted to the value false, with the false value inferred as the TypeScript type\n *\n * @example - boolean().onlyFalse(); // Infers the type false\n */\n onlyFalse(): WithBoolean<this, false> {\n return this.custom(isBoolean(false)) as WithBoolean<this, false>;\n }\n}\n\nexport type WithBoolean<T extends BooleanSchema, Y = boolean> = T & { validation_boolean: Y };\nexport type ExtractFromBoolean<T> = T extends WithBoolean<BooleanSchema, infer Y> ? Y : never;\n","import { BooleanSchema } from '../../schemas/BooleanSchema';\n\n/**\n * Creates a new schema for validating boolean values.\n *\n * @returns {BooleanSchema} A new instance of `BooleanSchema` for validating booleans.\n *\n * @example\n * const schema = boolean();\n * parseSchema(schema, true); // Validates successfully\n * parseSchema(schema, 'true'); // Throws a validation error\n */\nexport function boolean(): BooleanSchema {\n return new BooleanSchema({ type: ['boolean'], requiredValidations: [] });\n}\n"],"mappings":";AAAO,IAAM,kBAAN,cAA8B,MAAM;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAAY,UAAmB,UAAmB,aAAqB,SAAiB;AACtF,UAAM;AACN,SAAK,WAAW;AAChB,SAAK,WAAW;AAChB,SAAK,cAAc;AACnB,SAAK,UAAU;AAAA,EACjB;AACF;AAIO,SAAS,eAAe,UAAmB,UAAmB,aAAqB,SAAwB;AAChH,QAAM,IAAI,gBAAgB,UAAU,UAAU,aAAa,OAAO;AACpE;;;AClBO,IAAM,YAAY,OAAO,eAAe;;;ACgBxC,IAAM,eAAN,MAAmB;AAAA,EACxB,CAAC,SAAS;AAAA,EACV,YAAY,KAAuB;AACjC,SAAK,SAAS,IAAI;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,UAAU,YAAwC;AAChD,SAAK,SAAS,EAAE,oBAAoB,KAAK,GAAG,UAAU;AACtD,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,WAA2B;AACzB,SAAK,SAAS,EAAE,aAAa;AAC7B,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,WAAgC;AAC9B,SAAK,SAAS,EAAE,aAAa;AAC7B,WAAO;AAAA,EACT;AACF;;;AC/CA,IAAM,YAAY,CAAC,aAAsB,CAAC,UAAmB,gBAAwB;AACnF,MAAI,aAAa,SAAU,gBAAe,UAAU,UAAU,aAAa,6BAA6B,QAAQ,EAAE;AACpH;AAEO,IAAM,gBAAN,cAA4B,aAAa;AAAA,EAC9C,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASX,WAAoC;AAClC,WAAO,KAAK,OAAO,UAAU,IAAI,CAAC;AAAA,EACpC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,YAAsC;AACpC,WAAO,KAAK,OAAO,UAAU,KAAK,CAAC;AAAA,EACrC;AACF;;;ACnBO,SAAS,UAAyB;AACvC,SAAO,IAAI,cAAc,EAAE,MAAM,CAAC,SAAS,GAAG,qBAAqB,CAAC,EAAE,CAAC;AACzE;","names":[]}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,54 +1,8 @@
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
- // src/asserts/common/equalTo.ts
21
- var equalTo_exports = {};
22
- __export(equalTo_exports, {
23
- equalTo: () => equalTo
24
- });
25
- module.exports = __toCommonJS(equalTo_exports);
3
+ var _chunkAXOP6HPJjs = require('../../chunk-AXOP6HPJ.js');
4
+ require('../../chunk-2AP4OQMT.js');
26
5
 
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
6
 
45
- // src/asserts/common/equalTo.ts
46
- var equalTo = (expected) => (received, pathToError) => {
47
- if (expected !== received)
48
- throwException(expected, received, pathToError, "The received value is not equal to expected");
49
- };
50
- // Annotate the CommonJS export names for ESM import in node:
51
- 0 && (module.exports = {
52
- equalTo
53
- });
7
+ exports.equalTo = _chunkAXOP6HPJjs.equalTo;
54
8
  //# sourceMappingURL=equalTo.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/asserts/common/equalTo.ts","../../../src/exceptions.ts"],"sourcesContent":["import { throwException } from '../../exceptions';\nimport { RequiredValidation } from '../../schemas/CommonSchema';\n\n/**\n * Creates a custom assertion that checks if a value is equal to the expected value.\n *\n * This assertion can be used within a `.custom` method to enforce that a value strictly matches the expected value.\n * It will throw a `ValidationError` if the values are not equal.\n *\n * @param {unknown} expected - The value that the received value is expected to match.\n * @returns {RequiredValidation} A function that takes the received value and the path to the error,\n * and throws a `ValidationError` if the received value does not equal the expected value.\n *\n * @throws {ValidationError} If the received value does not match the expected value.\n *\n * @example\n * import { number, equalTo } from 'bguard';\n *\n * // Define a schema with a custom assertion\n * const schema = number().custom(equalTo(5));\n *\n * // This will pass\n * parseSchema(schema, 5);\n *\n * // This will throw a ValidationError\n * parseSchema(schema, 3);\n */\nexport const equalTo =\n (expected: unknown): RequiredValidation =>\n (received: number, pathToError: string) => {\n if (expected !== received)\n throwException(expected, received, pathToError, 'The received value is not equal to expected');\n };\n","export class ValidationError extends Error {\n expected: unknown;\n received: unknown;\n pathToError: string;\n message: string;\n constructor(expected: unknown, received: unknown, pathToError: string, message: string) {\n super();\n this.expected = expected;\n this.received = received;\n this.pathToError = pathToError;\n this.message = message;\n }\n}\n\nexport class BuildSchemaError extends Error {}\n\nexport function throwException(expected: unknown, received: unknown, pathToError: string, message: string): never {\n throw new ValidationError(expected, received, pathToError, message);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,kBAAN,cAA8B,MAAM;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAAY,UAAmB,UAAmB,aAAqB,SAAiB;AACtF,UAAM;AACN,SAAK,WAAW;AAChB,SAAK,WAAW;AAChB,SAAK,cAAc;AACnB,SAAK,UAAU;AAAA,EACjB;AACF;AAIO,SAAS,eAAe,UAAmB,UAAmB,aAAqB,SAAwB;AAChH,QAAM,IAAI,gBAAgB,UAAU,UAAU,aAAa,OAAO;AACpE;;;ADSO,IAAM,UACX,CAAC,aACD,CAAC,UAAkB,gBAAwB;AACzC,MAAI,aAAa;AACf,mBAAe,UAAU,UAAU,aAAa,6CAA6C;AACjG;","names":[]}
1
+ {"version":3,"sources":["/home/runner/work/bguard/bguard/lib/asserts/common/equalTo.js"],"names":[],"mappings":"AAAA;AACE;AACF,0DAAgC;AAChC,mCAAgC;AAChC;AACE;AACF,2CAAC","file":"/home/runner/work/bguard/bguard/lib/asserts/common/equalTo.js"}
@@ -1,26 +1,7 @@
1
- // src/exceptions.ts
2
- var ValidationError = class extends Error {
3
- expected;
4
- received;
5
- pathToError;
6
- message;
7
- constructor(expected, received, pathToError, message) {
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/asserts/common/equalTo.ts
20
- var equalTo = (expected) => (received, pathToError) => {
21
- if (expected !== received)
22
- throwException(expected, received, pathToError, "The received value is not equal to expected");
23
- };
1
+ import {
2
+ equalTo
3
+ } from "../../chunk-FCFO5J5Y.mjs";
4
+ import "../../chunk-QJOXKH7A.mjs";
24
5
  export {
25
6
  equalTo
26
7
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/exceptions.ts","../../../src/asserts/common/equalTo.ts"],"sourcesContent":["export class ValidationError extends Error {\n expected: unknown;\n received: unknown;\n pathToError: string;\n message: string;\n constructor(expected: unknown, received: unknown, pathToError: string, message: string) {\n super();\n this.expected = expected;\n this.received = received;\n this.pathToError = pathToError;\n this.message = message;\n }\n}\n\nexport class BuildSchemaError extends Error {}\n\nexport function throwException(expected: unknown, received: unknown, pathToError: string, message: string): never {\n throw new ValidationError(expected, received, pathToError, message);\n}\n","import { throwException } from '../../exceptions';\nimport { RequiredValidation } from '../../schemas/CommonSchema';\n\n/**\n * Creates a custom assertion that checks if a value is equal to the expected value.\n *\n * This assertion can be used within a `.custom` method to enforce that a value strictly matches the expected value.\n * It will throw a `ValidationError` if the values are not equal.\n *\n * @param {unknown} expected - The value that the received value is expected to match.\n * @returns {RequiredValidation} A function that takes the received value and the path to the error,\n * and throws a `ValidationError` if the received value does not equal the expected value.\n *\n * @throws {ValidationError} If the received value does not match the expected value.\n *\n * @example\n * import { number, equalTo } from 'bguard';\n *\n * // Define a schema with a custom assertion\n * const schema = number().custom(equalTo(5));\n *\n * // This will pass\n * parseSchema(schema, 5);\n *\n * // This will throw a ValidationError\n * parseSchema(schema, 3);\n */\nexport const equalTo =\n (expected: unknown): RequiredValidation =>\n (received: number, pathToError: string) => {\n if (expected !== received)\n throwException(expected, received, pathToError, 'The received value is not equal to expected');\n };\n"],"mappings":";AAAO,IAAM,kBAAN,cAA8B,MAAM;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAAY,UAAmB,UAAmB,aAAqB,SAAiB;AACtF,UAAM;AACN,SAAK,WAAW;AAChB,SAAK,WAAW;AAChB,SAAK,cAAc;AACnB,SAAK,UAAU;AAAA,EACjB;AACF;AAIO,SAAS,eAAe,UAAmB,UAAmB,aAAqB,SAAwB;AAChH,QAAM,IAAI,gBAAgB,UAAU,UAAU,aAAa,OAAO;AACpE;;;ACSO,IAAM,UACX,CAAC,aACD,CAAC,UAAkB,gBAAwB;AACzC,MAAI,aAAa;AACf,mBAAe,UAAU,UAAU,aAAa,6CAA6C;AACjG;","names":[]}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}