bguard 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 +4 -3
  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/core.js CHANGED
@@ -1,111 +1,10 @@
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/core.ts
21
- var core_exports = {};
22
- __export(core_exports, {
23
- ctxSymbol: () => ctxSymbol,
24
- innerCheck: () => innerCheck
25
- });
26
- module.exports = __toCommonJS(core_exports);
27
3
 
28
- // src/exceptions.ts
29
- var ValidationError = class extends Error {
30
- expected;
31
- received;
32
- pathToError;
33
- message;
34
- constructor(expected, received, pathToError, message) {
35
- super();
36
- this.expected = expected;
37
- this.received = received;
38
- this.pathToError = pathToError;
39
- this.message = message;
40
- }
41
- };
42
- function throwException(expected, received, pathToError, message) {
43
- throw new ValidationError(expected, received, pathToError, message);
44
- }
4
+ var _chunk5NCJN6D2js = require('./chunk-5NCJN6D2.js');
5
+ require('./chunk-2AP4OQMT.js');
45
6
 
46
- // src/core.ts
47
- var ctxSymbol = Symbol("contextSymbol");
48
- function innerCheck(schema, receivedValue, pathToError) {
49
- const ctx = schema[ctxSymbol];
50
- if (receivedValue === void 0) {
51
- if (!ctx.isOptional) throwException("Required", receivedValue, pathToError, "The required value is missing");
52
- return receivedValue;
53
- }
54
- if (receivedValue === null) {
55
- if (!ctx.isNullable) throwException("Not null", receivedValue, pathToError, "Value should not be null");
56
- return receivedValue;
57
- }
58
- if (ctx.array) {
59
- if (!Array.isArray(receivedValue))
60
- throwException("Array", receivedValue, pathToError, "Expected an array but received a different type");
61
- const schema2 = ctx.array;
62
- receivedValue.forEach((elem, i) => {
63
- innerCheck(schema2, elem, `${pathToError}[${i}]`);
64
- });
65
- return receivedValue;
66
- }
67
- const typeOfVal = typeof receivedValue;
68
- if (ctx.object) {
69
- if (typeOfVal !== "object")
70
- throwException("Object", receivedValue, pathToError, "Expected an object but received a different type");
71
- if (Array.isArray(receivedValue))
72
- throwException(
73
- "Object",
74
- receivedValue,
75
- pathToError,
76
- "Expected an object but received an array. Invalid type of data"
77
- );
78
- const shapeSchema = ctx.object;
79
- for (const keyPerReceivedValue of Object.keys(receivedValue)) {
80
- if (shapeSchema[keyPerReceivedValue] === void 0)
81
- throwException("Not allowed", keyPerReceivedValue, pathToError, "This key is not allowed in the object");
82
- }
83
- for (const [keyOfSchema, valueOfSchema] of Object.entries(shapeSchema)) {
84
- const receivedObjectValuePropery = receivedValue[keyOfSchema];
85
- if (receivedObjectValuePropery === void 0) {
86
- if (!valueOfSchema[ctxSymbol].isOptional)
87
- throwException(
88
- "Required",
89
- receivedObjectValuePropery,
90
- pathToError,
91
- "Missing required property in the object"
92
- );
93
- }
94
- innerCheck(valueOfSchema, receivedObjectValuePropery, `${pathToError}.${keyOfSchema}`);
95
- }
96
- return receivedValue;
97
- }
98
- if (ctx.type.length) {
99
- if (!ctx.type.includes(typeOfVal)) throwException(ctx.type, typeOfVal, pathToError, "Invalid type of data");
100
- }
101
- ctx.requiredValidations.forEach((requiredValidation) => {
102
- requiredValidation(receivedValue, pathToError);
103
- });
104
- return receivedValue;
105
- }
106
- // Annotate the CommonJS export names for ESM import in node:
107
- 0 && (module.exports = {
108
- ctxSymbol,
109
- innerCheck
110
- });
7
+
8
+
9
+ exports.ctxSymbol = _chunk5NCJN6D2js.ctxSymbol; exports.innerCheck = _chunk5NCJN6D2js.innerCheck;
111
10
  //# sourceMappingURL=core.js.map
package/lib/core.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/core.ts","../src/exceptions.ts"],"sourcesContent":["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","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;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;;;ADlBO,IAAM,YAAY,OAAO,eAAe;AAKxC,SAAS,WAAW,QAAsB,eAAwB,aAAqB;AAC5F,QAAM,MAAM,OAAO,SAAS;AAC5B,MAAI,kBAAkB,QAAW;AAC/B,QAAI,CAAC,IAAI,WAAY,gBAAe,YAAY,eAAe,aAAa,+BAA+B;AAC3G,WAAO;AAAA,EACT;AAEA,MAAI,kBAAkB,MAAM;AAC1B,QAAI,CAAC,IAAI,WAAY,gBAAe,YAAY,eAAe,aAAa,0BAA0B;AACtG,WAAO;AAAA,EACT;AAEA,MAAI,IAAI,OAAO;AACb,QAAI,CAAC,MAAM,QAAQ,aAAa;AAC9B,qBAAe,SAAS,eAAe,aAAa,iDAAiD;AACvG,UAAMA,UAAS,IAAI;AAEnB,kBAAc,QAAQ,CAAC,MAAM,MAAM;AACjC,iBAAWA,SAAQ,MAAM,GAAG,WAAW,IAAI,CAAC,GAAG;AAAA,IACjD,CAAC;AAED,WAAO;AAAA,EACT;AAEA,QAAM,YAAY,OAAO;AAEzB,MAAI,IAAI,QAAQ;AACd,QAAI,cAAc;AAChB,qBAAe,UAAU,eAAe,aAAa,kDAAkD;AACzG,QAAI,MAAM,QAAQ,aAAa;AAC7B;AAAA,QACE;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AACF,UAAM,cAAc,IAAI;AACxB,eAAW,uBAAuB,OAAO,KAAK,aAAa,GAAG;AAC5D,UAAI,YAAY,mBAAmB,MAAM;AACvC,uBAAe,eAAe,qBAAqB,aAAa,uCAAuC;AAAA,IAC3G;AAEA,eAAW,CAAC,aAAa,aAAa,KAAK,OAAO,QAAQ,WAAW,GAAG;AACtE,YAAM,6BAA8B,cAA0C,WAAW;AACzF,UAAI,+BAA+B,QAAW;AAC5C,YAAI,CAAC,cAAc,SAAS,EAAE;AAC5B;AAAA,YACE;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UACF;AAAA,MACJ;AACA,iBAAW,eAAe,4BAA4B,GAAG,WAAW,IAAI,WAAW,EAAE;AAAA,IACvF;AAEA,WAAO;AAAA,EACT;AAEA,MAAI,IAAI,KAAK,QAAQ;AACnB,QAAI,CAAC,IAAI,KAAK,SAAS,SAAS,EAAG,gBAAe,IAAI,MAAM,WAAW,aAAa,sBAAsB;AAAA,EAC5G;AAEA,MAAI,oBAAoB,QAAQ,CAAC,uBAAuB;AACtD,uBAAmB,eAAe,WAAW;AAAA,EAC/C,CAAC;AAED,SAAO;AACT;","names":["schema"]}
1
+ {"version":3,"sources":["/home/runner/work/bguard/bguard/lib/core.js"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,sDAA4B;AAC5B,+BAA4B;AAC5B;AACE;AACA;AACF,iGAAC","file":"/home/runner/work/bguard/bguard/lib/core.js"}
package/lib/core.mjs CHANGED
@@ -1,81 +1,8 @@
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
- function innerCheck(schema, receivedValue, pathToError) {
22
- const ctx = schema[ctxSymbol];
23
- if (receivedValue === void 0) {
24
- if (!ctx.isOptional) throwException("Required", receivedValue, pathToError, "The required value is missing");
25
- return receivedValue;
26
- }
27
- if (receivedValue === null) {
28
- if (!ctx.isNullable) throwException("Not null", receivedValue, pathToError, "Value should not be null");
29
- return receivedValue;
30
- }
31
- if (ctx.array) {
32
- if (!Array.isArray(receivedValue))
33
- throwException("Array", receivedValue, pathToError, "Expected an array but received a different type");
34
- const schema2 = ctx.array;
35
- receivedValue.forEach((elem, i) => {
36
- innerCheck(schema2, elem, `${pathToError}[${i}]`);
37
- });
38
- return receivedValue;
39
- }
40
- const typeOfVal = typeof receivedValue;
41
- if (ctx.object) {
42
- if (typeOfVal !== "object")
43
- throwException("Object", receivedValue, pathToError, "Expected an object but received a different type");
44
- if (Array.isArray(receivedValue))
45
- throwException(
46
- "Object",
47
- receivedValue,
48
- pathToError,
49
- "Expected an object but received an array. Invalid type of data"
50
- );
51
- const shapeSchema = ctx.object;
52
- for (const keyPerReceivedValue of Object.keys(receivedValue)) {
53
- if (shapeSchema[keyPerReceivedValue] === void 0)
54
- throwException("Not allowed", keyPerReceivedValue, pathToError, "This key is not allowed in the object");
55
- }
56
- for (const [keyOfSchema, valueOfSchema] of Object.entries(shapeSchema)) {
57
- const receivedObjectValuePropery = receivedValue[keyOfSchema];
58
- if (receivedObjectValuePropery === void 0) {
59
- if (!valueOfSchema[ctxSymbol].isOptional)
60
- throwException(
61
- "Required",
62
- receivedObjectValuePropery,
63
- pathToError,
64
- "Missing required property in the object"
65
- );
66
- }
67
- innerCheck(valueOfSchema, receivedObjectValuePropery, `${pathToError}.${keyOfSchema}`);
68
- }
69
- return receivedValue;
70
- }
71
- if (ctx.type.length) {
72
- if (!ctx.type.includes(typeOfVal)) throwException(ctx.type, typeOfVal, pathToError, "Invalid type of data");
73
- }
74
- ctx.requiredValidations.forEach((requiredValidation) => {
75
- requiredValidation(receivedValue, pathToError);
76
- });
77
- return receivedValue;
78
- }
1
+ import {
2
+ ctxSymbol,
3
+ innerCheck
4
+ } from "./chunk-P3Y6IWFA.mjs";
5
+ import "./chunk-QJOXKH7A.mjs";
79
6
  export {
80
7
  ctxSymbol,
81
8
  innerCheck
package/lib/core.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/exceptions.ts","../src/core.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"],"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;AAKxC,SAAS,WAAW,QAAsB,eAAwB,aAAqB;AAC5F,QAAM,MAAM,OAAO,SAAS;AAC5B,MAAI,kBAAkB,QAAW;AAC/B,QAAI,CAAC,IAAI,WAAY,gBAAe,YAAY,eAAe,aAAa,+BAA+B;AAC3G,WAAO;AAAA,EACT;AAEA,MAAI,kBAAkB,MAAM;AAC1B,QAAI,CAAC,IAAI,WAAY,gBAAe,YAAY,eAAe,aAAa,0BAA0B;AACtG,WAAO;AAAA,EACT;AAEA,MAAI,IAAI,OAAO;AACb,QAAI,CAAC,MAAM,QAAQ,aAAa;AAC9B,qBAAe,SAAS,eAAe,aAAa,iDAAiD;AACvG,UAAMA,UAAS,IAAI;AAEnB,kBAAc,QAAQ,CAAC,MAAM,MAAM;AACjC,iBAAWA,SAAQ,MAAM,GAAG,WAAW,IAAI,CAAC,GAAG;AAAA,IACjD,CAAC;AAED,WAAO;AAAA,EACT;AAEA,QAAM,YAAY,OAAO;AAEzB,MAAI,IAAI,QAAQ;AACd,QAAI,cAAc;AAChB,qBAAe,UAAU,eAAe,aAAa,kDAAkD;AACzG,QAAI,MAAM,QAAQ,aAAa;AAC7B;AAAA,QACE;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AACF,UAAM,cAAc,IAAI;AACxB,eAAW,uBAAuB,OAAO,KAAK,aAAa,GAAG;AAC5D,UAAI,YAAY,mBAAmB,MAAM;AACvC,uBAAe,eAAe,qBAAqB,aAAa,uCAAuC;AAAA,IAC3G;AAEA,eAAW,CAAC,aAAa,aAAa,KAAK,OAAO,QAAQ,WAAW,GAAG;AACtE,YAAM,6BAA8B,cAA0C,WAAW;AACzF,UAAI,+BAA+B,QAAW;AAC5C,YAAI,CAAC,cAAc,SAAS,EAAE;AAC5B;AAAA,YACE;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UACF;AAAA,MACJ;AACA,iBAAW,eAAe,4BAA4B,GAAG,WAAW,IAAI,WAAW,EAAE;AAAA,IACvF;AAEA,WAAO;AAAA,EACT;AAEA,MAAI,IAAI,KAAK,QAAQ;AACnB,QAAI,CAAC,IAAI,KAAK,SAAS,SAAS,EAAG,gBAAe,IAAI,MAAM,WAAW,aAAa,sBAAsB;AAAA,EAC5G;AAEA,MAAI,oBAAoB,QAAQ,CAAC,uBAAuB;AACtD,uBAAmB,eAAe,WAAW;AAAA,EAC/C,CAAC;AAED,SAAO;AACT;","names":["schema"]}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/lib/exceptions.js CHANGED
@@ -1,52 +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/exceptions.ts
21
- var exceptions_exports = {};
22
- __export(exceptions_exports, {
23
- BuildSchemaError: () => BuildSchemaError,
24
- ValidationError: () => ValidationError,
25
- throwException: () => throwException
26
- });
27
- module.exports = __toCommonJS(exceptions_exports);
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
- var BuildSchemaError = class extends Error {
42
- };
43
- function throwException(expected, received, pathToError, message) {
44
- throw new ValidationError(expected, received, pathToError, message);
45
- }
46
- // Annotate the CommonJS export names for ESM import in node:
47
- 0 && (module.exports = {
48
- BuildSchemaError,
49
- ValidationError,
50
- throwException
51
- });
3
+
4
+
5
+ var _chunk2AP4OQMTjs = require('./chunk-2AP4OQMT.js');
6
+
7
+
8
+
9
+
10
+ exports.BuildSchemaError = _chunk2AP4OQMTjs.BuildSchemaError; exports.ValidationError = _chunk2AP4OQMTjs.ValidationError; exports.throwException = _chunk2AP4OQMTjs.throwException;
52
11
  //# sourceMappingURL=exceptions.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/exceptions.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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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;AAEO,IAAM,mBAAN,cAA+B,MAAM;AAAC;AAEtC,SAAS,eAAe,UAAmB,UAAmB,aAAqB,SAAwB;AAChH,QAAM,IAAI,gBAAgB,UAAU,UAAU,aAAa,OAAO;AACpE;","names":[]}
1
+ {"version":3,"sources":["/home/runner/work/bguard/bguard/lib/exceptions.js"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACF,sDAA4B;AAC5B;AACE;AACA;AACA;AACF,mLAAC","file":"/home/runner/work/bguard/bguard/lib/exceptions.js"}
@@ -1,22 +1,8 @@
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
- var BuildSchemaError = class extends Error {
16
- };
17
- function throwException(expected, received, pathToError, message) {
18
- throw new ValidationError(expected, received, pathToError, message);
19
- }
1
+ import {
2
+ BuildSchemaError,
3
+ ValidationError,
4
+ throwException
5
+ } from "./chunk-QJOXKH7A.mjs";
20
6
  export {
21
7
  BuildSchemaError,
22
8
  ValidationError,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/exceptions.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"],"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;AAEO,IAAM,mBAAN,cAA+B,MAAM;AAAC;AAEtC,SAAS,eAAe,UAAmB,UAAmB,aAAqB,SAAwB;AAChH,QAAM,IAAI,gBAAgB,UAAU,UAAU,aAAa,OAAO;AACpE;","names":[]}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/lib/index.js CHANGED
@@ -1,301 +1,47 @@
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/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
23
- BuildSchemaError: () => BuildSchemaError,
24
- ValidationError: () => ValidationError,
25
- array: () => array,
26
- boolean: () => boolean,
27
- number: () => number,
28
- object: () => object,
29
- oneOfTypes: () => oneOfTypes,
30
- parseSchema: () => parseSchema,
31
- string: () => string,
32
- throwException: () => throwException
33
- });
34
- module.exports = __toCommonJS(src_exports);
3
+ var _chunkPJP63SJTjs = require('./chunk-PJP63SJT.js');
35
4
 
36
- // src/exceptions.ts
37
- var ValidationError = class extends Error {
38
- expected;
39
- received;
40
- pathToError;
41
- message;
42
- constructor(expected, received, pathToError, message) {
43
- super();
44
- this.expected = expected;
45
- this.received = received;
46
- this.pathToError = pathToError;
47
- this.message = message;
48
- }
49
- };
50
- var BuildSchemaError = class extends Error {
51
- };
52
- function throwException(expected, received, pathToError, message) {
53
- throw new ValidationError(expected, received, pathToError, message);
54
- }
55
5
 
56
- // src/core.ts
57
- var ctxSymbol = Symbol("contextSymbol");
58
- function innerCheck(schema, receivedValue, pathToError) {
59
- const ctx = schema[ctxSymbol];
60
- if (receivedValue === void 0) {
61
- if (!ctx.isOptional) throwException("Required", receivedValue, pathToError, "The required value is missing");
62
- return receivedValue;
63
- }
64
- if (receivedValue === null) {
65
- if (!ctx.isNullable) throwException("Not null", receivedValue, pathToError, "Value should not be null");
66
- return receivedValue;
67
- }
68
- if (ctx.array) {
69
- if (!Array.isArray(receivedValue))
70
- throwException("Array", receivedValue, pathToError, "Expected an array but received a different type");
71
- const schema2 = ctx.array;
72
- receivedValue.forEach((elem, i) => {
73
- innerCheck(schema2, elem, `${pathToError}[${i}]`);
74
- });
75
- return receivedValue;
76
- }
77
- const typeOfVal = typeof receivedValue;
78
- if (ctx.object) {
79
- if (typeOfVal !== "object")
80
- throwException("Object", receivedValue, pathToError, "Expected an object but received a different type");
81
- if (Array.isArray(receivedValue))
82
- throwException(
83
- "Object",
84
- receivedValue,
85
- pathToError,
86
- "Expected an object but received an array. Invalid type of data"
87
- );
88
- const shapeSchema = ctx.object;
89
- for (const keyPerReceivedValue of Object.keys(receivedValue)) {
90
- if (shapeSchema[keyPerReceivedValue] === void 0)
91
- throwException("Not allowed", keyPerReceivedValue, pathToError, "This key is not allowed in the object");
92
- }
93
- for (const [keyOfSchema, valueOfSchema] of Object.entries(shapeSchema)) {
94
- const receivedObjectValuePropery = receivedValue[keyOfSchema];
95
- if (receivedObjectValuePropery === void 0) {
96
- if (!valueOfSchema[ctxSymbol].isOptional)
97
- throwException(
98
- "Required",
99
- receivedObjectValuePropery,
100
- pathToError,
101
- "Missing required property in the object"
102
- );
103
- }
104
- innerCheck(valueOfSchema, receivedObjectValuePropery, `${pathToError}.${keyOfSchema}`);
105
- }
106
- return receivedValue;
107
- }
108
- if (ctx.type.length) {
109
- if (!ctx.type.includes(typeOfVal)) throwException(ctx.type, typeOfVal, pathToError, "Invalid type of data");
110
- }
111
- ctx.requiredValidations.forEach((requiredValidation) => {
112
- requiredValidation(receivedValue, pathToError);
113
- });
114
- return receivedValue;
115
- }
6
+ var _chunkK2S3FS5Kjs = require('./chunk-K2S3FS5K.js');
7
+ require('./chunk-IQ3QYABE.js');
8
+ require('./chunk-PDVXBE27.js');
116
9
 
117
- // src/parseSchema.ts
118
- function parseSchema(schema, receivedValue) {
119
- try {
120
- return innerCheck(schema, receivedValue, "");
121
- } catch (e) {
122
- if (e instanceof ValidationError) throw e;
123
- throw new Error("Something unexpected happened");
124
- }
125
- }
126
10
 
127
- // src/asserts/common/equalTo.ts
128
- var equalTo = (expected) => (received, pathToError) => {
129
- if (expected !== received)
130
- throwException(expected, received, pathToError, "The received value is not equal to expected");
131
- };
11
+ var _chunkL6A7NXUJjs = require('./chunk-L6A7NXUJ.js');
132
12
 
133
- // src/schemas/CommonSchema.ts
134
- var CommonSchema = class {
135
- [ctxSymbol];
136
- constructor(ctx) {
137
- this[ctxSymbol] = ctx;
138
- }
139
- /**
140
- * @param validators - One or more custom validation functions.
141
- * @returns {this} The schema instance with the added custom validation.
142
- */
143
- custom(...validators) {
144
- this[ctxSymbol].requiredValidations.push(...validators);
145
- return this;
146
- }
147
- /**
148
- * Marks the schema as nullable, allowing the value to be `null`.
149
- *
150
- * @returns {WithNull<this>} The schema instance marked as nullable.
151
- */
152
- nullable() {
153
- this[ctxSymbol].isNullable = true;
154
- return this;
155
- }
156
- /**
157
- * Marks the schema as optional, allowing the value to be `undefined`.
158
- *
159
- * @returns {WithUndefined<this>}} The schema instance marked as optional.
160
- */
161
- optional() {
162
- this[ctxSymbol].isOptional = true;
163
- return this;
164
- }
165
- };
166
13
 
167
- // src/schemas/NumberSchema.ts
168
- var NumberSchema = class extends CommonSchema {
169
- _number = 1;
170
- /**
171
- * Restricts the schema to exactly match the specified value and infers the literal value as the TypeScript type.
172
- *
173
- * @param expectedValue - The value that the schema must exactly match.
174
- * @returns - The schema instance restricted to the specified value, with the literal value inferred as the TypeScript type
175
- *
176
- * @example - number().equalTo(42); // Infers the type 42
177
- */
178
- equalTo(expectedValue) {
179
- return this.custom(equalTo(expectedValue));
180
- }
181
- };
14
+ var _chunkA7I2JEQOjs = require('./chunk-A7I2JEQO.js');
182
15
 
183
- // src/asserts/number/index.ts
184
- function number() {
185
- return new NumberSchema({ type: ["number"], requiredValidations: [] });
186
- }
187
16
 
188
- // src/schemas/StringSchema.ts
189
- var StringSchema = class extends CommonSchema {
190
- _string = 1;
191
- /**
192
- * Restricts the schema to exactly match the specified value and infers the literal value as the TypeScript type.
193
- *
194
- * @param expectedValue - The value that the schema must exactly match.
195
- * @returns - The schema instance restricted to the specified value, with the literal value inferred as the TypeScript type
196
- *
197
- * @example - string().equalTo('hello'); // Infers the type 'hello'
198
- */
199
- equalTo(expectedValue) {
200
- return this.custom(equalTo(expectedValue));
201
- }
202
- };
17
+ var _chunkNWY33MFUjs = require('./chunk-NWY33MFU.js');
203
18
 
204
- // src/asserts/string/index.ts
205
- function string() {
206
- return new StringSchema({ type: ["string"], requiredValidations: [] });
207
- }
208
19
 
209
- // src/schemas/BooleanSchema.ts
210
- var isBoolean = (expected) => (received, pathToError) => {
211
- if (received !== expected) throwException(expected, received, pathToError, `The received value is not ${expected}`);
212
- };
213
- var BooleanSchema = class extends CommonSchema {
214
- _boolean = 1;
215
- /**
216
- * Restricts the schema to exactly match the boolean value true and infers the true value as the TypeScript type.
217
- *
218
- * @returns - The schema instance restricted to the value true, with the true value inferred as the TypeScript type
219
- *
220
- * @example - boolean().onlyTrue(); // Infers the type true
221
- */
222
- onlyTrue() {
223
- return this.custom(isBoolean(true));
224
- }
225
- /**
226
- * Restricts the schema to exactly match the boolean value false and infers the false value as the TypeScript type.
227
- *
228
- * @returns - The schema instance restricted to the value false, with the false value inferred as the TypeScript type
229
- *
230
- * @example - boolean().onlyFalse(); // Infers the type false
231
- */
232
- onlyFalse() {
233
- return this.custom(isBoolean(false));
234
- }
235
- };
20
+ var _chunkQKGQ4XZCjs = require('./chunk-QKGQ4XZC.js');
21
+ require('./chunk-GNBSKTFV.js');
22
+ require('./chunk-AXOP6HPJ.js');
236
23
 
237
- // src/asserts/boolean/index.ts
238
- function boolean() {
239
- return new BooleanSchema({ type: ["boolean"], requiredValidations: [] });
240
- }
241
24
 
242
- // src/schemas/ArraySchema.ts
243
- var ArraySchema = class extends CommonSchema {
244
- _array = 1;
245
- constructor(ctx, arraySchema) {
246
- super(ctx);
247
- this.validateArrayEntry(arraySchema);
248
- this[ctxSymbol].array = arraySchema;
249
- }
250
- validateArrayEntry(arraySchema) {
251
- if (!arraySchema) throw new BuildSchemaError("Missing schema in array method");
252
- if (!(arraySchema instanceof CommonSchema)) throw new BuildSchemaError("Invalid schema in array method");
253
- }
254
- };
25
+ var _chunk5ZMICHV3js = require('./chunk-5ZMICHV3.js');
26
+ require('./chunk-YXHH5BF6.js');
27
+ require('./chunk-VPFIIM2X.js');
28
+ require('./chunk-APTTIN2L.js');
29
+ require('./chunk-5NCJN6D2.js');
255
30
 
256
- // src/asserts/array/index.ts
257
- function array(arraySchema) {
258
- return new ArraySchema({ type: [], requiredValidations: [] }, arraySchema);
259
- }
260
31
 
261
- // src/schemas/ObjectSchema.ts
262
- var ObjectSchema = class extends CommonSchema {
263
- _object = 1;
264
- constructor(ctx, shapeSchema) {
265
- super(ctx);
266
- this.validateObjectEntry(shapeSchema);
267
- this[ctxSymbol].object = shapeSchema;
268
- }
269
- validateObjectEntry(shapeSchema) {
270
- if (!shapeSchema) throw new BuildSchemaError("Missing schema in object method");
271
- if (shapeSchema instanceof CommonSchema) throw new BuildSchemaError("Invalid schema in object");
272
- for (const [key, value] of Object.entries(shapeSchema)) {
273
- if (!(value instanceof CommonSchema))
274
- throw new BuildSchemaError(`Invalid schema in object method for property '${key}'`);
275
- }
276
- }
277
- };
278
32
 
279
- // src/asserts/object/index.ts
280
- function object(shapeSchema) {
281
- return new ObjectSchema({ type: [], requiredValidations: [] }, shapeSchema);
282
- }
283
33
 
284
- // src/asserts/common/index.ts
285
- function oneOfTypes(valueTypes) {
286
- return new CommonSchema({ type: valueTypes, requiredValidations: [] });
287
- }
288
- // Annotate the CommonJS export names for ESM import in node:
289
- 0 && (module.exports = {
290
- BuildSchemaError,
291
- ValidationError,
292
- array,
293
- boolean,
294
- number,
295
- object,
296
- oneOfTypes,
297
- parseSchema,
298
- string,
299
- throwException
300
- });
34
+ var _chunk2AP4OQMTjs = require('./chunk-2AP4OQMT.js');
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+ exports.BuildSchemaError = _chunk2AP4OQMTjs.BuildSchemaError; exports.ValidationError = _chunk2AP4OQMTjs.ValidationError; exports.array = _chunkL6A7NXUJjs.array; exports.boolean = _chunkA7I2JEQOjs.boolean; exports.number = _chunkQKGQ4XZCjs.number; exports.object = _chunkK2S3FS5Kjs.object; exports.oneOfTypes = _chunkNWY33MFUjs.oneOfTypes; exports.parseSchema = _chunk5ZMICHV3js.parseSchema; exports.string = _chunkPJP63SJTjs.string; exports.throwException = _chunk2AP4OQMTjs.throwException;
301
47
  //# sourceMappingURL=index.js.map