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.
- package/lib/InferType.js +1 -19
- package/lib/InferType.js.map +1 -1
- package/lib/asserts/array/index.js +7 -86
- package/lib/asserts/array/index.js.map +1 -1
- package/lib/asserts/array/index.mjs +7 -59
- package/lib/asserts/array/index.mjs.map +1 -1
- package/lib/asserts/boolean/index.js +7 -114
- package/lib/asserts/boolean/index.js.map +1 -1
- package/lib/asserts/boolean/index.mjs +7 -87
- package/lib/asserts/boolean/index.mjs.map +1 -1
- package/lib/asserts/common/equalTo.js +4 -50
- package/lib/asserts/common/equalTo.js.map +1 -1
- package/lib/asserts/common/equalTo.mjs +4 -23
- package/lib/asserts/common/equalTo.mjs.map +1 -1
- package/lib/asserts/common/index.js +6 -68
- package/lib/asserts/common/index.js.map +1 -1
- package/lib/asserts/common/index.mjs +6 -41
- package/lib/asserts/common/index.mjs.map +1 -1
- package/lib/asserts/number/index.js +8 -108
- package/lib/asserts/number/index.js.map +1 -1
- package/lib/asserts/number/index.mjs +8 -81
- package/lib/asserts/number/index.mjs.map +1 -1
- package/lib/asserts/number/max.js +6 -47
- package/lib/asserts/number/max.js.map +1 -1
- package/lib/asserts/number/max.mjs +3 -17
- package/lib/asserts/number/max.mjs.map +1 -1
- package/lib/asserts/number/maxExcluded.js +6 -47
- package/lib/asserts/number/maxExcluded.js.map +1 -1
- package/lib/asserts/number/maxExcluded.mjs +3 -17
- package/lib/asserts/number/maxExcluded.mjs.map +1 -1
- package/lib/asserts/number/min.js +6 -47
- package/lib/asserts/number/min.js.map +1 -1
- package/lib/asserts/number/min.mjs +3 -17
- package/lib/asserts/number/min.mjs.map +1 -1
- package/lib/asserts/number/minExcluded.js +6 -47
- package/lib/asserts/number/minExcluded.js.map +1 -1
- package/lib/asserts/number/minExcluded.mjs +3 -17
- package/lib/asserts/number/minExcluded.mjs.map +1 -1
- package/lib/asserts/number/negative.js +6 -47
- package/lib/asserts/number/negative.js.map +1 -1
- package/lib/asserts/number/negative.mjs +3 -17
- package/lib/asserts/number/negative.mjs.map +1 -1
- package/lib/asserts/number/positive.js +6 -47
- package/lib/asserts/number/positive.js.map +1 -1
- package/lib/asserts/number/positive.mjs +3 -17
- package/lib/asserts/number/positive.mjs.map +1 -1
- package/lib/asserts/object/index.js +7 -90
- package/lib/asserts/object/index.js.map +1 -1
- package/lib/asserts/object/index.mjs +7 -63
- package/lib/asserts/object/index.mjs.map +1 -1
- package/lib/asserts/string/email.js +6 -47
- package/lib/asserts/string/email.js.map +1 -1
- package/lib/asserts/string/email.mjs +3 -17
- package/lib/asserts/string/email.mjs.map +1 -1
- package/lib/asserts/string/index.js +8 -108
- package/lib/asserts/string/index.js.map +1 -1
- package/lib/asserts/string/index.mjs +8 -81
- package/lib/asserts/string/index.mjs.map +1 -1
- package/lib/asserts/string/maxLength.js +6 -47
- package/lib/asserts/string/maxLength.js.map +1 -1
- package/lib/asserts/string/maxLength.mjs +3 -17
- package/lib/asserts/string/maxLength.mjs.map +1 -1
- package/lib/asserts/string/minLength.js +6 -47
- package/lib/asserts/string/minLength.js.map +1 -1
- package/lib/asserts/string/minLength.mjs +3 -17
- package/lib/asserts/string/minLength.mjs.map +1 -1
- package/lib/asserts/string/regExp.js +6 -47
- package/lib/asserts/string/regExp.js.map +1 -1
- package/lib/asserts/string/regExp.mjs +3 -17
- package/lib/asserts/string/regExp.mjs.map +1 -1
- package/lib/chunk-2AP4OQMT.js +26 -0
- package/lib/chunk-2AP4OQMT.js.map +1 -0
- package/lib/chunk-32IQXZRK.mjs +13 -0
- package/lib/chunk-32IQXZRK.mjs.map +1 -0
- package/lib/chunk-3FEJUC3K.mjs +13 -0
- package/lib/chunk-3FEJUC3K.mjs.map +1 -0
- package/lib/chunk-5NCJN6D2.js +70 -0
- package/lib/chunk-5NCJN6D2.js.map +1 -0
- package/lib/chunk-5ZMICHV3.js +21 -0
- package/lib/chunk-5ZMICHV3.js.map +1 -0
- package/lib/chunk-63IQFNFO.mjs +27 -0
- package/lib/chunk-63IQFNFO.mjs.map +1 -0
- package/lib/chunk-A2SAWKJA.mjs +13 -0
- package/lib/chunk-A2SAWKJA.mjs.map +1 -0
- package/lib/chunk-A3UTB4RE.mjs +28 -0
- package/lib/chunk-A3UTB4RE.mjs.map +1 -0
- package/lib/chunk-A7I2JEQO.js +13 -0
- package/lib/chunk-A7I2JEQO.js.map +1 -0
- package/lib/chunk-AJ4WV5DG.mjs +13 -0
- package/lib/chunk-AJ4WV5DG.mjs.map +1 -0
- package/lib/chunk-APTTIN2L.js +42 -0
- package/lib/chunk-APTTIN2L.js.map +1 -0
- package/lib/chunk-AXOP6HPJ.js +14 -0
- package/lib/chunk-AXOP6HPJ.js.map +1 -0
- package/lib/chunk-BGMR7A6X.mjs +13 -0
- package/lib/chunk-BGMR7A6X.mjs.map +1 -0
- package/lib/chunk-FCFO5J5Y.mjs +14 -0
- package/lib/chunk-FCFO5J5Y.mjs.map +1 -0
- package/lib/chunk-GEZME6V2.mjs +39 -0
- package/lib/chunk-GEZME6V2.mjs.map +1 -0
- package/lib/chunk-GNBSKTFV.js +27 -0
- package/lib/chunk-GNBSKTFV.js.map +1 -0
- package/lib/chunk-IQ3QYABE.js +32 -0
- package/lib/chunk-IQ3QYABE.js.map +1 -0
- package/lib/chunk-K2S3FS5K.js +13 -0
- package/lib/chunk-K2S3FS5K.js.map +1 -0
- package/lib/chunk-KCBOOOTF.mjs +13 -0
- package/lib/chunk-KCBOOOTF.mjs.map +1 -0
- package/lib/chunk-L6A7NXUJ.js +13 -0
- package/lib/chunk-L6A7NXUJ.js.map +1 -0
- package/lib/chunk-L7HUXYFV.mjs +42 -0
- package/lib/chunk-L7HUXYFV.mjs.map +1 -0
- package/lib/chunk-LHTJHMKJ.mjs +27 -0
- package/lib/chunk-LHTJHMKJ.mjs.map +1 -0
- package/lib/chunk-NOADI6PO.mjs +21 -0
- package/lib/chunk-NOADI6PO.mjs.map +1 -0
- package/lib/chunk-NWY33MFU.js +13 -0
- package/lib/chunk-NWY33MFU.js.map +1 -0
- package/lib/chunk-P3Y6IWFA.mjs +70 -0
- package/lib/chunk-P3Y6IWFA.mjs.map +1 -0
- package/lib/chunk-PDVXBE27.js +27 -0
- package/lib/chunk-PDVXBE27.js.map +1 -0
- package/lib/chunk-PJP63SJT.js +13 -0
- package/lib/chunk-PJP63SJT.js.map +1 -0
- package/lib/chunk-QJOXKH7A.mjs +26 -0
- package/lib/chunk-QJOXKH7A.mjs.map +1 -0
- package/lib/chunk-QKGQ4XZC.js +13 -0
- package/lib/chunk-QKGQ4XZC.js.map +1 -0
- package/lib/chunk-QYLH5ZAC.mjs +32 -0
- package/lib/chunk-QYLH5ZAC.mjs.map +1 -0
- package/lib/chunk-VPFIIM2X.js +39 -0
- package/lib/chunk-VPFIIM2X.js.map +1 -0
- package/lib/chunk-YXHH5BF6.js +28 -0
- package/lib/chunk-YXHH5BF6.js.map +1 -0
- package/lib/core.js +6 -107
- package/lib/core.js.map +1 -1
- package/lib/core.mjs +5 -78
- package/lib/core.mjs.map +1 -1
- package/lib/exceptions.js +9 -50
- package/lib/exceptions.js.map +1 -1
- package/lib/exceptions.mjs +5 -19
- package/lib/exceptions.mjs.map +1 -1
- package/lib/index.js +29 -283
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +34 -252
- package/lib/index.mjs.map +1 -1
- package/lib/parseSchema.js +5 -115
- package/lib/parseSchema.js.map +1 -1
- package/lib/parseSchema.mjs +5 -88
- package/lib/parseSchema.mjs.map +1 -1
- package/lib/schemas/ArraySchema.js +6 -81
- package/lib/schemas/ArraySchema.js.map +1 -1
- package/lib/schemas/ArraySchema.mjs +6 -54
- package/lib/schemas/ArraySchema.mjs.map +1 -1
- package/lib/schemas/BooleanSchema.js +6 -109
- package/lib/schemas/BooleanSchema.js.map +1 -1
- package/lib/schemas/BooleanSchema.mjs +6 -82
- package/lib/schemas/BooleanSchema.mjs.map +1 -1
- package/lib/schemas/CommonSchema.js +5 -63
- package/lib/schemas/CommonSchema.js.map +1 -1
- package/lib/schemas/CommonSchema.mjs +5 -36
- package/lib/schemas/CommonSchema.mjs.map +1 -1
- package/lib/schemas/NumberSchema.js +7 -103
- package/lib/schemas/NumberSchema.js.map +1 -1
- package/lib/schemas/NumberSchema.mjs +7 -76
- package/lib/schemas/NumberSchema.mjs.map +1 -1
- package/lib/schemas/ObjectSchema.js +6 -85
- package/lib/schemas/ObjectSchema.js.map +1 -1
- package/lib/schemas/ObjectSchema.mjs +6 -58
- package/lib/schemas/ObjectSchema.mjs.map +1 -1
- package/lib/schemas/StringSchema.js +7 -103
- package/lib/schemas/StringSchema.js.map +1 -1
- package/lib/schemas/StringSchema.mjs +7 -76
- package/lib/schemas/StringSchema.mjs.map +1 -1
- package/package.json +15 -14
- package/lib/__tests__/ArraySchema.test.d.mts +0 -2
- package/lib/__tests__/ArraySchema.test.d.ts +0 -2
- package/lib/__tests__/ArraySchema.test.js +0 -201
- package/lib/__tests__/ArraySchema.test.js.map +0 -1
- package/lib/__tests__/ArraySchema.test.mjs +0 -199
- package/lib/__tests__/ArraySchema.test.mjs.map +0 -1
- package/lib/__tests__/BooleanSchema.test.d.mts +0 -2
- package/lib/__tests__/BooleanSchema.test.d.ts +0 -2
- package/lib/__tests__/BooleanSchema.test.js +0 -219
- package/lib/__tests__/BooleanSchema.test.js.map +0 -1
- package/lib/__tests__/BooleanSchema.test.mjs +0 -217
- package/lib/__tests__/BooleanSchema.test.mjs.map +0 -1
- package/lib/__tests__/CommonSchema.test.d.mts +0 -2
- package/lib/__tests__/CommonSchema.test.d.ts +0 -2
- package/lib/__tests__/CommonSchema.test.js +0 -253
- package/lib/__tests__/CommonSchema.test.js.map +0 -1
- package/lib/__tests__/CommonSchema.test.mjs +0 -251
- package/lib/__tests__/CommonSchema.test.mjs.map +0 -1
- package/lib/__tests__/MixTypes.test.d.mts +0 -2
- package/lib/__tests__/MixTypes.test.d.ts +0 -2
- package/lib/__tests__/MixTypes.test.js +0 -165
- package/lib/__tests__/MixTypes.test.js.map +0 -1
- package/lib/__tests__/MixTypes.test.mjs +0 -163
- package/lib/__tests__/MixTypes.test.mjs.map +0 -1
- package/lib/__tests__/NumberSchema.test.d.mts +0 -2
- package/lib/__tests__/NumberSchema.test.d.ts +0 -2
- package/lib/__tests__/NumberSchema.test.js +0 -253
- package/lib/__tests__/NumberSchema.test.js.map +0 -1
- package/lib/__tests__/NumberSchema.test.mjs +0 -251
- package/lib/__tests__/NumberSchema.test.mjs.map +0 -1
- package/lib/__tests__/ObjectSchema.test.d.mts +0 -2
- package/lib/__tests__/ObjectSchema.test.d.ts +0 -2
- package/lib/__tests__/ObjectSchema.test.js +0 -356
- package/lib/__tests__/ObjectSchema.test.js.map +0 -1
- package/lib/__tests__/ObjectSchema.test.mjs +0 -354
- package/lib/__tests__/ObjectSchema.test.mjs.map +0 -1
- package/lib/__tests__/StringSchema.test.d.mts +0 -2
- package/lib/__tests__/StringSchema.test.d.ts +0 -2
- package/lib/__tests__/StringSchema.test.js +0 -228
- package/lib/__tests__/StringSchema.test.js.map +0 -1
- package/lib/__tests__/StringSchema.test.mjs +0 -226
- package/lib/__tests__/StringSchema.test.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/schemas/BooleanSchema.ts"],"sourcesContent":["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":";;;;;;;;AAGA,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;","names":[]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _class;
|
|
2
|
+
|
|
3
|
+
var _chunkAXOP6HPJjs = require('./chunk-AXOP6HPJ.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkAPTTIN2Ljs = require('./chunk-APTTIN2L.js');
|
|
7
|
+
|
|
8
|
+
// src/schemas/NumberSchema.ts
|
|
9
|
+
var NumberSchema = (_class = class extends _chunkAPTTIN2Ljs.CommonSchema {constructor(...args) { super(...args); _class.prototype.__init.call(this); }
|
|
10
|
+
__init() {this._number = 1}
|
|
11
|
+
/**
|
|
12
|
+
* Restricts the schema to exactly match the specified value and infers the literal value as the TypeScript type.
|
|
13
|
+
*
|
|
14
|
+
* @param expectedValue - The value that the schema must exactly match.
|
|
15
|
+
* @returns - The schema instance restricted to the specified value, with the literal value inferred as the TypeScript type
|
|
16
|
+
*
|
|
17
|
+
* @example - number().equalTo(42); // Infers the type 42
|
|
18
|
+
*/
|
|
19
|
+
equalTo(expectedValue) {
|
|
20
|
+
return this.custom(_chunkAXOP6HPJjs.equalTo.call(void 0, expectedValue));
|
|
21
|
+
}
|
|
22
|
+
}, _class);
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
exports.NumberSchema = NumberSchema;
|
|
27
|
+
//# sourceMappingURL=chunk-GNBSKTFV.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-GNBSKTFV.js","../src/schemas/NumberSchema.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACA;ACHO,IAAM,aAAA,YAAN,MAAA,QAA2B,8BAAa;AAAA,iBAC7C,QAAA,EAAU,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUV,OAAA,CAA0B,aAAA,EAAuC;AAC/D,IAAA,OAAO,IAAA,CAAK,MAAA,CAAO,sCAAA,aAAqB,CAAC,CAAA;AAAA,EAC3C;AACF,UAAA;ADIA;AACA;AACE;AACF,oCAAC","file":"/home/runner/work/bguard/bguard/lib/chunk-GNBSKTFV.js","sourcesContent":[null,"import { equalTo } from '../asserts/common/equalTo';\n\nimport { CommonSchema } from './CommonSchema';\n\nexport class NumberSchema extends CommonSchema {\n _number = 1;\n\n /**\n * Restricts the schema to exactly match the specified value and infers the literal value as the TypeScript type.\n *\n * @param expectedValue - The value that the schema must exactly match.\n * @returns - The schema instance restricted to the specified value, with the literal value inferred as the TypeScript type\n *\n * @example - number().equalTo(42); // Infers the type 42\n */\n equalTo<Y extends number>(expectedValue: Y): WithNumber<this, Y> {\n return this.custom(equalTo(expectedValue)) as WithNumber<this, Y>;\n }\n}\n\nexport type WithNumber<T extends NumberSchema, Y = number> = T & { validation_number: Y };\nexport type ExtractFromNumber<T> = T extends WithNumber<NumberSchema, infer Y> ? Y : never;\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _class;
|
|
2
|
+
|
|
3
|
+
var _chunkAPTTIN2Ljs = require('./chunk-APTTIN2L.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunk5NCJN6D2js = require('./chunk-5NCJN6D2.js');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var _chunk2AP4OQMTjs = require('./chunk-2AP4OQMT.js');
|
|
10
|
+
|
|
11
|
+
// src/schemas/ObjectSchema.ts
|
|
12
|
+
var ObjectSchema = (_class = class extends _chunkAPTTIN2Ljs.CommonSchema {
|
|
13
|
+
__init() {this._object = 1}
|
|
14
|
+
constructor(ctx, shapeSchema) {
|
|
15
|
+
super(ctx);_class.prototype.__init.call(this);;
|
|
16
|
+
this.validateObjectEntry(shapeSchema);
|
|
17
|
+
this[_chunk5NCJN6D2js.ctxSymbol].object = shapeSchema;
|
|
18
|
+
}
|
|
19
|
+
validateObjectEntry(shapeSchema) {
|
|
20
|
+
if (!shapeSchema) throw new (0, _chunk2AP4OQMTjs.BuildSchemaError)("Missing schema in object method");
|
|
21
|
+
if (shapeSchema instanceof _chunkAPTTIN2Ljs.CommonSchema) throw new (0, _chunk2AP4OQMTjs.BuildSchemaError)("Invalid schema in object");
|
|
22
|
+
for (const [key, value] of Object.entries(shapeSchema)) {
|
|
23
|
+
if (!(value instanceof _chunkAPTTIN2Ljs.CommonSchema))
|
|
24
|
+
throw new (0, _chunk2AP4OQMTjs.BuildSchemaError)(`Invalid schema in object method for property '${key}'`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}, _class);
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
exports.ObjectSchema = ObjectSchema;
|
|
32
|
+
//# sourceMappingURL=chunk-IQ3QYABE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-IQ3QYABE.js","../src/schemas/ObjectSchema.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACA;ACNO,IAAM,aAAA,YAAN,MAAA,QAA2B,8BAAa;AAAA,iBAC7C,QAAA,EAAU,EAAA;AAAA,EACV,WAAA,CAAY,GAAA,EAAuB,WAAA,EAAoC;AACrE,IAAA,KAAA,CAAM,GAAG,qCAAA;AACT,IAAA,IAAA,CAAK,mBAAA,CAAoB,WAAW,CAAA;AACpC,IAAA,IAAA,CAAK,0BAAS,CAAA,CAAE,OAAA,EAAS,WAAA;AAAA,EAC3B;AAAA,EAEQ,mBAAA,CAAoB,WAAA,EAAoC;AAC9D,IAAA,GAAA,CAAI,CAAC,WAAA,EAAa,MAAM,IAAI,sCAAA,CAAiB,iCAAiC,CAAA;AAC9E,IAAA,GAAA,CAAI,YAAA,WAAuB,6BAAA,EAAc,MAAM,IAAI,sCAAA,CAAiB,0BAA0B,CAAA;AAC9F,IAAA,IAAA,CAAA,MAAW,CAAC,GAAA,EAAK,KAAK,EAAA,GAAK,MAAA,CAAO,OAAA,CAAQ,WAAW,CAAA,EAAG;AACtD,MAAA,GAAA,CAAI,CAAA,CAAE,MAAA,WAAiB,6BAAA,CAAA;AACrB,QAAA,MAAM,IAAI,sCAAA,CAAiB,CAAA,8CAAA,EAAiD,GAAG,CAAA,CAAA,CAAG,CAAA;AAAA,IACtF;AAAA,EACF;AACF,UAAA;ADOA;AACA;AACE;AACF,oCAAC","file":"/home/runner/work/bguard/bguard/lib/chunk-IQ3QYABE.js","sourcesContent":[null,"import { ctxSymbol } from '../core';\nimport { BuildSchemaError } from '../exceptions';\nimport { CommonSchema, ObjectShapeSchemaType, ValidatorContext } from './CommonSchema';\n\nexport class ObjectSchema extends CommonSchema {\n _object = 1;\n constructor(ctx: ValidatorContext, shapeSchema: ObjectShapeSchemaType) {\n super(ctx);\n this.validateObjectEntry(shapeSchema);\n this[ctxSymbol].object = shapeSchema;\n }\n\n private validateObjectEntry(shapeSchema: ObjectShapeSchemaType) {\n if (!shapeSchema) throw new BuildSchemaError('Missing schema in object method');\n if (shapeSchema instanceof CommonSchema) throw new BuildSchemaError('Invalid schema in object');\n for (const [key, value] of Object.entries(shapeSchema)) {\n if (!(value instanceof CommonSchema))\n throw new BuildSchemaError(`Invalid schema in object method for property '${key}'`);\n }\n }\n}\n\nexport type WithObject<Y extends ObjectShapeSchemaType> = ObjectSchema & { validation_object: Y };\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkIQ3QYABEjs = require('./chunk-IQ3QYABE.js');
|
|
4
|
+
|
|
5
|
+
// src/asserts/object/index.ts
|
|
6
|
+
function object(shapeSchema) {
|
|
7
|
+
return new (0, _chunkIQ3QYABEjs.ObjectSchema)({ type: [], requiredValidations: [] }, shapeSchema);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
exports.object = object;
|
|
13
|
+
//# sourceMappingURL=chunk-K2S3FS5K.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-K2S3FS5K.js","../src/asserts/object/index.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACA;ACcO,SAAS,MAAA,CAAwC,WAAA,EAA+B;AACrF,EAAA,OAAO,IAAI,kCAAA,CAAa,EAAE,IAAA,EAAM,CAAC,CAAA,EAAG,mBAAA,EAAqB,CAAC,EAAE,CAAA,EAAG,WAAW,CAAA;AAC5E;ADZA;AACA;AACE;AACF,wBAAC","file":"/home/runner/work/bguard/bguard/lib/chunk-K2S3FS5K.js","sourcesContent":[null,"import { ObjectShapeSchemaType } from '../../schemas/CommonSchema';\nimport { ObjectSchema, WithObject } from '../../schemas/ObjectSchema';\n\n/**\n * Creates a new schema for validating objects where each property must match the specified schema.\n *\n * @template T\n * @param {T} shapeSchema - The schema that each property of the object must match.\n * @returns {WithObject<T>} A new instance of `ObjectSchema` for validating objects with properties matching the specified schema.\n *\n * @example\n * const schema = object({\n * name: string(),\n * age: number()\n * });\n * parseSchema(schema, { name: 'John', age: 30 }); // Validates successfully\n * parseSchema(schema, { name: 'John', age: '30' }); // Throws a validation error\n */\nexport function object<T extends ObjectShapeSchemaType>(shapeSchema: T): WithObject<T> {\n return new ObjectSchema({ type: [], requiredValidations: [] }, shapeSchema) as WithObject<T>;\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
StringSchema
|
|
3
|
+
} from "./chunk-LHTJHMKJ.mjs";
|
|
4
|
+
|
|
5
|
+
// src/asserts/string/index.ts
|
|
6
|
+
function string() {
|
|
7
|
+
return new StringSchema({ type: ["string"], requiredValidations: [] });
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export {
|
|
11
|
+
string
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=chunk-KCBOOOTF.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/asserts/string/index.ts"],"sourcesContent":["import { StringSchema } from '../../schemas/StringSchema';\n\n/**\n * Creates a new schema for validating string values.\n *\n * @returns {StringSchema} A new instance of `StringSchema` for validating strings.\n *\n * @example\n * const schema = string();\n * parseSchema(schema, 'hello'); // Validates successfully\n * parseSchema(schema, 123); // Throws a validation error\n */\nexport function string(): StringSchema {\n return new StringSchema({ type: ['string'], requiredValidations: [] });\n}\n"],"mappings":";;;;;AAYO,SAAS,SAAuB;AACrC,SAAO,IAAI,aAAa,EAAE,MAAM,CAAC,QAAQ,GAAG,qBAAqB,CAAC,EAAE,CAAC;AACvE;","names":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkYXHH5BF6js = require('./chunk-YXHH5BF6.js');
|
|
4
|
+
|
|
5
|
+
// src/asserts/array/index.ts
|
|
6
|
+
function array(arraySchema) {
|
|
7
|
+
return new (0, _chunkYXHH5BF6js.ArraySchema)({ type: [], requiredValidations: [] }, arraySchema);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
exports.array = array;
|
|
13
|
+
//# sourceMappingURL=chunk-L6A7NXUJ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-L6A7NXUJ.js","../src/asserts/array/index.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACA;ACWO,SAAS,KAAA,CAA8B,WAAA,EAA8B;AAC1E,EAAA,OAAO,IAAI,iCAAA,CAAY,EAAE,IAAA,EAAM,CAAC,CAAA,EAAG,mBAAA,EAAqB,CAAC,EAAE,CAAA,EAAG,WAAW,CAAA;AAC3E;ADTA;AACA;AACE;AACF,sBAAC","file":"/home/runner/work/bguard/bguard/lib/chunk-L6A7NXUJ.js","sourcesContent":[null,"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"]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ctxSymbol
|
|
3
|
+
} from "./chunk-P3Y6IWFA.mjs";
|
|
4
|
+
|
|
5
|
+
// src/schemas/CommonSchema.ts
|
|
6
|
+
var CommonSchema = class {
|
|
7
|
+
[ctxSymbol];
|
|
8
|
+
constructor(ctx) {
|
|
9
|
+
this[ctxSymbol] = ctx;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* @param validators - One or more custom validation functions.
|
|
13
|
+
* @returns {this} The schema instance with the added custom validation.
|
|
14
|
+
*/
|
|
15
|
+
custom(...validators) {
|
|
16
|
+
this[ctxSymbol].requiredValidations.push(...validators);
|
|
17
|
+
return this;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Marks the schema as nullable, allowing the value to be `null`.
|
|
21
|
+
*
|
|
22
|
+
* @returns {WithNull<this>} The schema instance marked as nullable.
|
|
23
|
+
*/
|
|
24
|
+
nullable() {
|
|
25
|
+
this[ctxSymbol].isNullable = true;
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Marks the schema as optional, allowing the value to be `undefined`.
|
|
30
|
+
*
|
|
31
|
+
* @returns {WithUndefined<this>}} The schema instance marked as optional.
|
|
32
|
+
*/
|
|
33
|
+
optional() {
|
|
34
|
+
this[ctxSymbol].isOptional = true;
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export {
|
|
40
|
+
CommonSchema
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=chunk-L7HUXYFV.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/schemas/CommonSchema.ts"],"sourcesContent":["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"],"mappings":";;;;;AAgBO,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;","names":[]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {
|
|
2
|
+
equalTo
|
|
3
|
+
} from "./chunk-FCFO5J5Y.mjs";
|
|
4
|
+
import {
|
|
5
|
+
CommonSchema
|
|
6
|
+
} from "./chunk-L7HUXYFV.mjs";
|
|
7
|
+
|
|
8
|
+
// src/schemas/StringSchema.ts
|
|
9
|
+
var StringSchema = class extends CommonSchema {
|
|
10
|
+
_string = 1;
|
|
11
|
+
/**
|
|
12
|
+
* Restricts the schema to exactly match the specified value and infers the literal value as the TypeScript type.
|
|
13
|
+
*
|
|
14
|
+
* @param expectedValue - The value that the schema must exactly match.
|
|
15
|
+
* @returns - The schema instance restricted to the specified value, with the literal value inferred as the TypeScript type
|
|
16
|
+
*
|
|
17
|
+
* @example - string().equalTo('hello'); // Infers the type 'hello'
|
|
18
|
+
*/
|
|
19
|
+
equalTo(expectedValue) {
|
|
20
|
+
return this.custom(equalTo(expectedValue));
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export {
|
|
25
|
+
StringSchema
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=chunk-LHTJHMKJ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/schemas/StringSchema.ts"],"sourcesContent":["import { equalTo } from '../asserts/common/equalTo';\nimport { CommonSchema } from './CommonSchema';\n\nexport class StringSchema extends CommonSchema {\n _string = 1;\n\n /**\n * Restricts the schema to exactly match the specified value and infers the literal value as the TypeScript type.\n *\n * @param expectedValue - The value that the schema must exactly match.\n * @returns - The schema instance restricted to the specified value, with the literal value inferred as the TypeScript type\n *\n * @example - string().equalTo('hello'); // Infers the type 'hello'\n */\n equalTo<Y extends string>(expectedValue: Y): WithString<this, Y> {\n return this.custom(equalTo(expectedValue)) as WithString<this, Y>;\n }\n}\n\nexport type WithString<T extends StringSchema, Y = string> = T & { validation_string: Y };\nexport type ExtractFromString<T> = T extends WithString<StringSchema, infer Y> ? Y : never;\n"],"mappings":";;;;;;;;AAGO,IAAM,eAAN,cAA2B,aAAa;AAAA,EAC7C,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUV,QAA0B,eAAuC;AAC/D,WAAO,KAAK,OAAO,QAAQ,aAAa,CAAC;AAAA,EAC3C;AACF;","names":[]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {
|
|
2
|
+
innerCheck
|
|
3
|
+
} from "./chunk-P3Y6IWFA.mjs";
|
|
4
|
+
import {
|
|
5
|
+
ValidationError
|
|
6
|
+
} from "./chunk-QJOXKH7A.mjs";
|
|
7
|
+
|
|
8
|
+
// src/parseSchema.ts
|
|
9
|
+
function parseSchema(schema, receivedValue) {
|
|
10
|
+
try {
|
|
11
|
+
return innerCheck(schema, receivedValue, "");
|
|
12
|
+
} catch (e) {
|
|
13
|
+
if (e instanceof ValidationError) throw e;
|
|
14
|
+
throw new Error("Something unexpected happened");
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export {
|
|
19
|
+
parseSchema
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=chunk-NOADI6PO.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/parseSchema.ts"],"sourcesContent":["import { InferType } from './InferType';\nimport { innerCheck } from './core';\nimport { ValidationError } from './exceptions';\nimport { CommonSchema } from './schemas/CommonSchema';\n\n/**\n * Parses and validates a value against the provided schema, returning a type-safe result.\n *\n * This function will throw a `ValidationError` if the value does not conform to the schema.\n * The inferred TypeScript type of the returned value will match the structure defined by the schema.\n *\n * @template T\n * @param {T} schema - The schema to validate the received value against. This schema dictates the expected structure and type of the value.\n * @param {unknown} receivedValue - The value to be validated and parsed according to the schema.\n * @returns {InferType<T>} The validated value, with its TypeScript type inferred from the schema.\n *\n * @throws {ValidationError} If the received value does not match the schema, a `ValidationError` will be thrown.\n * @throws {Error} If an unexpected error occurs during validation, an error will be thrown with a generic message.\n *\n * @example\n * const schema = object({\n * name: string(),\n * age: number(),\n * });\n *\n * const result = parseSchema(schema, { name: 'Alice', age: 30 });\n * // result will be inferred as { name: string; age: number }\n *\n * parseSchema(schema, { name: 'Alice', age: '30' });\n * // Throws ValidationError because 'age' should be a number, not a string.\n */\nexport function parseSchema<T extends CommonSchema>(schema: T, receivedValue: unknown): InferType<T> {\n try {\n return innerCheck(schema, receivedValue, '') as InferType<T>;\n } catch (e) {\n if (e instanceof ValidationError) throw e;\n /* istanbul ignore next */\n throw new Error('Something unexpected happened');\n }\n}\n"],"mappings":";;;;;;;;AA+BO,SAAS,YAAoC,QAAW,eAAsC;AACnG,MAAI;AACF,WAAO,WAAW,QAAQ,eAAe,EAAE;AAAA,EAC7C,SAAS,GAAG;AACV,QAAI,aAAa,gBAAiB,OAAM;AAExC,UAAM,IAAI,MAAM,+BAA+B;AAAA,EACjD;AACF;","names":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkAPTTIN2Ljs = require('./chunk-APTTIN2L.js');
|
|
4
|
+
|
|
5
|
+
// src/asserts/common/index.ts
|
|
6
|
+
function oneOfTypes(valueTypes) {
|
|
7
|
+
return new (0, _chunkAPTTIN2Ljs.CommonSchema)({ type: valueTypes, requiredValidations: [] });
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
exports.oneOfTypes = oneOfTypes;
|
|
13
|
+
//# sourceMappingURL=chunk-NWY33MFU.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-NWY33MFU.js","../src/asserts/common/index.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACA;ACWO,SAAS,UAAA,CAAsC,UAAA,EAAwC;AAC5F,EAAA,OAAO,IAAI,kCAAA,CAAa,EAAE,IAAA,EAAM,UAAA,EAAY,mBAAA,EAAqB,CAAC,EAAE,CAAC,CAAA;AACvE;ADTA;AACA;AACE;AACF,gCAAC","file":"/home/runner/work/bguard/bguard/lib/chunk-NWY33MFU.js","sourcesContent":[null,"import { CommonSchema, MapMixTypes, PrimitiveType, WithMix } from '../../schemas/CommonSchema';\n\n/**\n * Creates a new schema for validating values that can match any one of the specified primitive types.\n *\n * @template T\n * @param {T} valueTypes - An array of primitive types that the value can match.\n * @returns {WithMix<MapMixTypes<T>>} A new schema for validating values that can match any of the specified types.\n *\n * @example\n * const schema = oneOfTypes(['string', 'number']);\n * parseSchema(schema, 'hello'); // Validates successfully\n * parseSchema(schema, 42); // Validates successfully\n * parseSchema(schema, true); // Throws a validation error\n */\nexport function oneOfTypes<T extends PrimitiveType[]>(valueTypes: T): WithMix<MapMixTypes<T>> {\n return new CommonSchema({ type: valueTypes, requiredValidations: [] }) as WithMix<MapMixTypes<T>>;\n}\n"]}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import {
|
|
2
|
+
throwException
|
|
3
|
+
} from "./chunk-QJOXKH7A.mjs";
|
|
4
|
+
|
|
5
|
+
// src/core.ts
|
|
6
|
+
var ctxSymbol = Symbol("contextSymbol");
|
|
7
|
+
function innerCheck(schema, receivedValue, pathToError) {
|
|
8
|
+
const ctx = schema[ctxSymbol];
|
|
9
|
+
if (receivedValue === void 0) {
|
|
10
|
+
if (!ctx.isOptional) throwException("Required", receivedValue, pathToError, "The required value is missing");
|
|
11
|
+
return receivedValue;
|
|
12
|
+
}
|
|
13
|
+
if (receivedValue === null) {
|
|
14
|
+
if (!ctx.isNullable) throwException("Not null", receivedValue, pathToError, "Value should not be null");
|
|
15
|
+
return receivedValue;
|
|
16
|
+
}
|
|
17
|
+
if (ctx.array) {
|
|
18
|
+
if (!Array.isArray(receivedValue))
|
|
19
|
+
throwException("Array", receivedValue, pathToError, "Expected an array but received a different type");
|
|
20
|
+
const schema2 = ctx.array;
|
|
21
|
+
receivedValue.forEach((elem, i) => {
|
|
22
|
+
innerCheck(schema2, elem, `${pathToError}[${i}]`);
|
|
23
|
+
});
|
|
24
|
+
return receivedValue;
|
|
25
|
+
}
|
|
26
|
+
const typeOfVal = typeof receivedValue;
|
|
27
|
+
if (ctx.object) {
|
|
28
|
+
if (typeOfVal !== "object")
|
|
29
|
+
throwException("Object", receivedValue, pathToError, "Expected an object but received a different type");
|
|
30
|
+
if (Array.isArray(receivedValue))
|
|
31
|
+
throwException(
|
|
32
|
+
"Object",
|
|
33
|
+
receivedValue,
|
|
34
|
+
pathToError,
|
|
35
|
+
"Expected an object but received an array. Invalid type of data"
|
|
36
|
+
);
|
|
37
|
+
const shapeSchema = ctx.object;
|
|
38
|
+
for (const keyPerReceivedValue of Object.keys(receivedValue)) {
|
|
39
|
+
if (shapeSchema[keyPerReceivedValue] === void 0)
|
|
40
|
+
throwException("Not allowed", keyPerReceivedValue, pathToError, "This key is not allowed in the object");
|
|
41
|
+
}
|
|
42
|
+
for (const [keyOfSchema, valueOfSchema] of Object.entries(shapeSchema)) {
|
|
43
|
+
const receivedObjectValuePropery = receivedValue[keyOfSchema];
|
|
44
|
+
if (receivedObjectValuePropery === void 0) {
|
|
45
|
+
if (!valueOfSchema[ctxSymbol].isOptional)
|
|
46
|
+
throwException(
|
|
47
|
+
"Required",
|
|
48
|
+
receivedObjectValuePropery,
|
|
49
|
+
pathToError,
|
|
50
|
+
"Missing required property in the object"
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
innerCheck(valueOfSchema, receivedObjectValuePropery, `${pathToError}.${keyOfSchema}`);
|
|
54
|
+
}
|
|
55
|
+
return receivedValue;
|
|
56
|
+
}
|
|
57
|
+
if (ctx.type.length) {
|
|
58
|
+
if (!ctx.type.includes(typeOfVal)) throwException(ctx.type, typeOfVal, pathToError, "Invalid type of data");
|
|
59
|
+
}
|
|
60
|
+
ctx.requiredValidations.forEach((requiredValidation) => {
|
|
61
|
+
requiredValidation(receivedValue, pathToError);
|
|
62
|
+
});
|
|
63
|
+
return receivedValue;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export {
|
|
67
|
+
ctxSymbol,
|
|
68
|
+
innerCheck
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=chunk-P3Y6IWFA.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core.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"],"mappings":";;;;;AAAO,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"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _class;
|
|
2
|
+
|
|
3
|
+
var _chunkAXOP6HPJjs = require('./chunk-AXOP6HPJ.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkAPTTIN2Ljs = require('./chunk-APTTIN2L.js');
|
|
7
|
+
|
|
8
|
+
// src/schemas/StringSchema.ts
|
|
9
|
+
var StringSchema = (_class = class extends _chunkAPTTIN2Ljs.CommonSchema {constructor(...args) { super(...args); _class.prototype.__init.call(this); }
|
|
10
|
+
__init() {this._string = 1}
|
|
11
|
+
/**
|
|
12
|
+
* Restricts the schema to exactly match the specified value and infers the literal value as the TypeScript type.
|
|
13
|
+
*
|
|
14
|
+
* @param expectedValue - The value that the schema must exactly match.
|
|
15
|
+
* @returns - The schema instance restricted to the specified value, with the literal value inferred as the TypeScript type
|
|
16
|
+
*
|
|
17
|
+
* @example - string().equalTo('hello'); // Infers the type 'hello'
|
|
18
|
+
*/
|
|
19
|
+
equalTo(expectedValue) {
|
|
20
|
+
return this.custom(_chunkAXOP6HPJjs.equalTo.call(void 0, expectedValue));
|
|
21
|
+
}
|
|
22
|
+
}, _class);
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
exports.StringSchema = StringSchema;
|
|
27
|
+
//# sourceMappingURL=chunk-PDVXBE27.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-PDVXBE27.js","../src/schemas/StringSchema.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACA;ACJO,IAAM,aAAA,YAAN,MAAA,QAA2B,8BAAa;AAAA,iBAC7C,QAAA,EAAU,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUV,OAAA,CAA0B,aAAA,EAAuC;AAC/D,IAAA,OAAO,IAAA,CAAK,MAAA,CAAO,sCAAA,aAAqB,CAAC,CAAA;AAAA,EAC3C;AACF,UAAA;ADKA;AACA;AACE;AACF,oCAAC","file":"/home/runner/work/bguard/bguard/lib/chunk-PDVXBE27.js","sourcesContent":[null,"import { equalTo } from '../asserts/common/equalTo';\nimport { CommonSchema } from './CommonSchema';\n\nexport class StringSchema extends CommonSchema {\n _string = 1;\n\n /**\n * Restricts the schema to exactly match the specified value and infers the literal value as the TypeScript type.\n *\n * @param expectedValue - The value that the schema must exactly match.\n * @returns - The schema instance restricted to the specified value, with the literal value inferred as the TypeScript type\n *\n * @example - string().equalTo('hello'); // Infers the type 'hello'\n */\n equalTo<Y extends string>(expectedValue: Y): WithString<this, Y> {\n return this.custom(equalTo(expectedValue)) as WithString<this, Y>;\n }\n}\n\nexport type WithString<T extends StringSchema, Y = string> = T & { validation_string: Y };\nexport type ExtractFromString<T> = T extends WithString<StringSchema, infer Y> ? Y : never;\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkPDVXBE27js = require('./chunk-PDVXBE27.js');
|
|
4
|
+
|
|
5
|
+
// src/asserts/string/index.ts
|
|
6
|
+
function string() {
|
|
7
|
+
return new (0, _chunkPDVXBE27js.StringSchema)({ type: ["string"], requiredValidations: [] });
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
exports.string = string;
|
|
13
|
+
//# sourceMappingURL=chunk-PJP63SJT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-PJP63SJT.js","../src/asserts/string/index.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACA;ACQO,SAAS,MAAA,CAAA,EAAuB;AACrC,EAAA,OAAO,IAAI,kCAAA,CAAa,EAAE,IAAA,EAAM,CAAC,QAAQ,CAAA,EAAG,mBAAA,EAAqB,CAAC,EAAE,CAAC,CAAA;AACvE;ADNA;AACA;AACE;AACF,wBAAC","file":"/home/runner/work/bguard/bguard/lib/chunk-PJP63SJT.js","sourcesContent":[null,"import { StringSchema } from '../../schemas/StringSchema';\n\n/**\n * Creates a new schema for validating string values.\n *\n * @returns {StringSchema} A new instance of `StringSchema` for validating strings.\n *\n * @example\n * const schema = string();\n * parseSchema(schema, 'hello'); // Validates successfully\n * parseSchema(schema, 123); // Throws a validation error\n */\nexport function string(): StringSchema {\n return new StringSchema({ type: ['string'], requiredValidations: [] });\n}\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
}
|
|
20
|
+
|
|
21
|
+
export {
|
|
22
|
+
ValidationError,
|
|
23
|
+
BuildSchemaError,
|
|
24
|
+
throwException
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=chunk-QJOXKH7A.mjs.map
|
|
@@ -0,0 +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":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkGNBSKTFVjs = require('./chunk-GNBSKTFV.js');
|
|
4
|
+
|
|
5
|
+
// src/asserts/number/index.ts
|
|
6
|
+
function number() {
|
|
7
|
+
return new (0, _chunkGNBSKTFVjs.NumberSchema)({ type: ["number"], requiredValidations: [] });
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
exports.number = number;
|
|
13
|
+
//# sourceMappingURL=chunk-QKGQ4XZC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-QKGQ4XZC.js","../src/asserts/number/index.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACA;ACQO,SAAS,MAAA,CAAA,EAAuB;AACrC,EAAA,OAAO,IAAI,kCAAA,CAAa,EAAE,IAAA,EAAM,CAAC,QAAQ,CAAA,EAAG,mBAAA,EAAqB,CAAC,EAAE,CAAC,CAAA;AACvE;ADNA;AACA;AACE;AACF,wBAAC","file":"/home/runner/work/bguard/bguard/lib/chunk-QKGQ4XZC.js","sourcesContent":[null,"import { NumberSchema } from '../../schemas/NumberSchema';\n\n/**\n * Creates a new schema for validating number values.\n *\n * @returns {NumberSchema} A new instance of `NumberSchema` for validating numbers.\n *\n * @example\n * const schema = number();\n * parseSchema(schema, 42); // Validates successfully\n * parseSchema(schema, '42'); // Throws a validation error\n */\nexport function number(): NumberSchema {\n return new NumberSchema({ type: ['number'], requiredValidations: [] });\n}\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CommonSchema
|
|
3
|
+
} from "./chunk-L7HUXYFV.mjs";
|
|
4
|
+
import {
|
|
5
|
+
ctxSymbol
|
|
6
|
+
} from "./chunk-P3Y6IWFA.mjs";
|
|
7
|
+
import {
|
|
8
|
+
BuildSchemaError
|
|
9
|
+
} from "./chunk-QJOXKH7A.mjs";
|
|
10
|
+
|
|
11
|
+
// src/schemas/ObjectSchema.ts
|
|
12
|
+
var ObjectSchema = class extends CommonSchema {
|
|
13
|
+
_object = 1;
|
|
14
|
+
constructor(ctx, shapeSchema) {
|
|
15
|
+
super(ctx);
|
|
16
|
+
this.validateObjectEntry(shapeSchema);
|
|
17
|
+
this[ctxSymbol].object = shapeSchema;
|
|
18
|
+
}
|
|
19
|
+
validateObjectEntry(shapeSchema) {
|
|
20
|
+
if (!shapeSchema) throw new BuildSchemaError("Missing schema in object method");
|
|
21
|
+
if (shapeSchema instanceof CommonSchema) throw new BuildSchemaError("Invalid schema in object");
|
|
22
|
+
for (const [key, value] of Object.entries(shapeSchema)) {
|
|
23
|
+
if (!(value instanceof CommonSchema))
|
|
24
|
+
throw new BuildSchemaError(`Invalid schema in object method for property '${key}'`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export {
|
|
30
|
+
ObjectSchema
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=chunk-QYLH5ZAC.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/schemas/ObjectSchema.ts"],"sourcesContent":["import { ctxSymbol } from '../core';\nimport { BuildSchemaError } from '../exceptions';\nimport { CommonSchema, ObjectShapeSchemaType, ValidatorContext } from './CommonSchema';\n\nexport class ObjectSchema extends CommonSchema {\n _object = 1;\n constructor(ctx: ValidatorContext, shapeSchema: ObjectShapeSchemaType) {\n super(ctx);\n this.validateObjectEntry(shapeSchema);\n this[ctxSymbol].object = shapeSchema;\n }\n\n private validateObjectEntry(shapeSchema: ObjectShapeSchemaType) {\n if (!shapeSchema) throw new BuildSchemaError('Missing schema in object method');\n if (shapeSchema instanceof CommonSchema) throw new BuildSchemaError('Invalid schema in object');\n for (const [key, value] of Object.entries(shapeSchema)) {\n if (!(value instanceof CommonSchema))\n throw new BuildSchemaError(`Invalid schema in object method for property '${key}'`);\n }\n }\n}\n\nexport type WithObject<Y extends ObjectShapeSchemaType> = ObjectSchema & { validation_object: Y };\n"],"mappings":";;;;;;;;;;;AAIO,IAAM,eAAN,cAA2B,aAAa;AAAA,EAC7C,UAAU;AAAA,EACV,YAAY,KAAuB,aAAoC;AACrE,UAAM,GAAG;AACT,SAAK,oBAAoB,WAAW;AACpC,SAAK,SAAS,EAAE,SAAS;AAAA,EAC3B;AAAA,EAEQ,oBAAoB,aAAoC;AAC9D,QAAI,CAAC,YAAa,OAAM,IAAI,iBAAiB,iCAAiC;AAC9E,QAAI,uBAAuB,aAAc,OAAM,IAAI,iBAAiB,0BAA0B;AAC9F,eAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,WAAW,GAAG;AACtD,UAAI,EAAE,iBAAiB;AACrB,cAAM,IAAI,iBAAiB,iDAAiD,GAAG,GAAG;AAAA,IACtF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _class;
|
|
2
|
+
|
|
3
|
+
var _chunkAPTTIN2Ljs = require('./chunk-APTTIN2L.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunk2AP4OQMTjs = require('./chunk-2AP4OQMT.js');
|
|
7
|
+
|
|
8
|
+
// src/schemas/BooleanSchema.ts
|
|
9
|
+
var isBoolean = (expected) => (received, pathToError) => {
|
|
10
|
+
if (received !== expected) _chunk2AP4OQMTjs.throwException.call(void 0, expected, received, pathToError, `The received value is not ${expected}`);
|
|
11
|
+
};
|
|
12
|
+
var BooleanSchema = (_class = class extends _chunkAPTTIN2Ljs.CommonSchema {constructor(...args) { super(...args); _class.prototype.__init.call(this); }
|
|
13
|
+
__init() {this._boolean = 1}
|
|
14
|
+
/**
|
|
15
|
+
* Restricts the schema to exactly match the boolean value true and infers the true value as the TypeScript type.
|
|
16
|
+
*
|
|
17
|
+
* @returns - The schema instance restricted to the value true, with the true value inferred as the TypeScript type
|
|
18
|
+
*
|
|
19
|
+
* @example - boolean().onlyTrue(); // Infers the type true
|
|
20
|
+
*/
|
|
21
|
+
onlyTrue() {
|
|
22
|
+
return this.custom(isBoolean(true));
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Restricts the schema to exactly match the boolean value false and infers the false value as the TypeScript type.
|
|
26
|
+
*
|
|
27
|
+
* @returns - The schema instance restricted to the value false, with the false value inferred as the TypeScript type
|
|
28
|
+
*
|
|
29
|
+
* @example - boolean().onlyFalse(); // Infers the type false
|
|
30
|
+
*/
|
|
31
|
+
onlyFalse() {
|
|
32
|
+
return this.custom(isBoolean(false));
|
|
33
|
+
}
|
|
34
|
+
}, _class);
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
exports.BooleanSchema = BooleanSchema;
|
|
39
|
+
//# sourceMappingURL=chunk-VPFIIM2X.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-VPFIIM2X.js","../src/schemas/BooleanSchema.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACA;ACJA,IAAM,UAAA,EAAY,CAAC,QAAA,EAAA,GAAsB,CAAC,QAAA,EAAmB,WAAA,EAAA,GAAwB;AACnF,EAAA,GAAA,CAAI,SAAA,IAAa,QAAA,EAAU,6CAAA,QAAe,EAAU,QAAA,EAAU,WAAA,EAAa,CAAA,0BAAA,EAA6B,QAAQ,CAAA,CAAA;AAClH;AAEgD;AACnC,iBAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASyB,EAAA;AACA,IAAA;AACpC,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASsC,EAAA;AACD,IAAA;AACrC,EAAA;AACF;ADGmH;AACA;AACA;AACA","file":"/home/runner/work/bguard/bguard/lib/chunk-VPFIIM2X.js","sourcesContent":[null,"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"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _class;
|
|
2
|
+
|
|
3
|
+
var _chunkAPTTIN2Ljs = require('./chunk-APTTIN2L.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunk5NCJN6D2js = require('./chunk-5NCJN6D2.js');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var _chunk2AP4OQMTjs = require('./chunk-2AP4OQMT.js');
|
|
10
|
+
|
|
11
|
+
// src/schemas/ArraySchema.ts
|
|
12
|
+
var ArraySchema = (_class = class extends _chunkAPTTIN2Ljs.CommonSchema {
|
|
13
|
+
__init() {this._array = 1}
|
|
14
|
+
constructor(ctx, arraySchema) {
|
|
15
|
+
super(ctx);_class.prototype.__init.call(this);;
|
|
16
|
+
this.validateArrayEntry(arraySchema);
|
|
17
|
+
this[_chunk5NCJN6D2js.ctxSymbol].array = arraySchema;
|
|
18
|
+
}
|
|
19
|
+
validateArrayEntry(arraySchema) {
|
|
20
|
+
if (!arraySchema) throw new (0, _chunk2AP4OQMTjs.BuildSchemaError)("Missing schema in array method");
|
|
21
|
+
if (!(arraySchema instanceof _chunkAPTTIN2Ljs.CommonSchema)) throw new (0, _chunk2AP4OQMTjs.BuildSchemaError)("Invalid schema in array method");
|
|
22
|
+
}
|
|
23
|
+
}, _class);
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
exports.ArraySchema = ArraySchema;
|
|
28
|
+
//# sourceMappingURL=chunk-YXHH5BF6.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bguard/bguard/lib/chunk-YXHH5BF6.js","../src/schemas/ArraySchema.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACA;ACNO,IAAM,YAAA,YAAN,MAAA,QAA0B,8BAAa;AAAA,iBAC5C,OAAA,EAAS,EAAA;AAAA,EACT,WAAA,CAAY,GAAA,EAAuB,WAAA,EAA2B;AAC5D,IAAA,KAAA,CAAM,GAAG,qCAAA;AACT,IAAA,IAAA,CAAK,kBAAA,CAAmB,WAAW,CAAA;AACnC,IAAA,IAAA,CAAK,0BAAS,CAAA,CAAE,MAAA,EAAQ,WAAA;AAAA,EAC1B;AAAA,EAEQ,kBAAA,CAAmB,WAAA,EAA2B;AACpD,IAAA,GAAA,CAAI,CAAC,WAAA,EAAa,MAAM,IAAI,sCAAA,CAAiB,gCAAgC,CAAA;AAC7E,IAAA,GAAA,CAAI,CAAA,CAAE,YAAA,WAAuB,6BAAA,CAAA,EAAe,MAAM,IAAI,sCAAA,CAAiB,gCAAgC,CAAA;AAAA,EACzG;AACF,UAAA;ADOA;AACA;AACE;AACF,kCAAC","file":"/home/runner/work/bguard/bguard/lib/chunk-YXHH5BF6.js","sourcesContent":[null,"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"]}
|