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
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../jest/setup.ts","../../src/exceptions.ts","../../src/core.ts","../../src/parseSchema.ts","../../src/asserts/string/regExp.ts","../../src/asserts/common/equalTo.ts","../../src/schemas/CommonSchema.ts","../../src/schemas/StringSchema.ts","../../src/asserts/string/index.ts","../../src/asserts/string/maxLength.ts","../../src/__tests__/StringSchema.test.ts"],"sourcesContent":["export type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false;\n\nexport function expectEqualTypes<X, Y>(areEqual: Equal<X, Y>): void {\n expect(typeof areEqual).toBe('boolean');\n}\n","export class ValidationError extends Error {\n expected: unknown;\n received: unknown;\n pathToError: string;\n message: string;\n constructor(expected: unknown, received: unknown, pathToError: string, message: string) {\n super();\n this.expected = expected;\n this.received = received;\n this.pathToError = pathToError;\n this.message = message;\n }\n}\n\nexport class BuildSchemaError extends Error {}\n\nexport function throwException(expected: unknown, received: unknown, pathToError: string, message: string): never {\n throw new ValidationError(expected, received, pathToError, message);\n}\n","export const ctxSymbol = Symbol('contextSymbol');\n\nimport { throwException } from './exceptions';\nimport type { CommonSchema } from './schemas/CommonSchema';\n\nexport function innerCheck(schema: CommonSchema, receivedValue: unknown, pathToError: string) {\n const ctx = schema[ctxSymbol];\n if (receivedValue === undefined) {\n if (!ctx.isOptional) throwException('Required', receivedValue, pathToError, 'The required value is missing');\n return receivedValue;\n }\n\n if (receivedValue === null) {\n if (!ctx.isNullable) throwException('Not null', receivedValue, pathToError, 'Value should not be null');\n return receivedValue;\n }\n\n if (ctx.array) {\n if (!Array.isArray(receivedValue))\n throwException('Array', receivedValue, pathToError, 'Expected an array but received a different type');\n const schema = ctx.array;\n\n receivedValue.forEach((elem, i) => {\n innerCheck(schema, elem, `${pathToError}[${i}]`);\n });\n\n return receivedValue;\n }\n\n const typeOfVal = typeof receivedValue;\n\n if (ctx.object) {\n if (typeOfVal !== 'object')\n throwException('Object', receivedValue, pathToError, 'Expected an object but received a different type');\n if (Array.isArray(receivedValue))\n throwException(\n 'Object',\n receivedValue,\n pathToError,\n 'Expected an object but received an array. Invalid type of data',\n );\n const shapeSchema = ctx.object;\n for (const keyPerReceivedValue of Object.keys(receivedValue)) {\n if (shapeSchema[keyPerReceivedValue] === undefined)\n throwException('Not allowed', keyPerReceivedValue, pathToError, 'This key is not allowed in the object');\n }\n\n for (const [keyOfSchema, valueOfSchema] of Object.entries(shapeSchema)) {\n const receivedObjectValuePropery = (receivedValue as Record<string, unknown>)[keyOfSchema];\n if (receivedObjectValuePropery === undefined) {\n if (!valueOfSchema[ctxSymbol].isOptional)\n throwException(\n 'Required',\n receivedObjectValuePropery,\n pathToError,\n 'Missing required property in the object',\n );\n }\n innerCheck(valueOfSchema, receivedObjectValuePropery, `${pathToError}.${keyOfSchema}`);\n }\n\n return receivedValue;\n }\n\n if (ctx.type.length) {\n if (!ctx.type.includes(typeOfVal)) throwException(ctx.type, typeOfVal, pathToError, 'Invalid type of data');\n }\n\n ctx.requiredValidations.forEach((requiredValidation) => {\n requiredValidation(receivedValue, pathToError);\n });\n\n return receivedValue;\n}\n","import { 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","import { throwException } from '../../exceptions';\nimport type { RequiredValidation } from '../../schemas/CommonSchema';\n\n/**\n * Asserts that a string value matches a specified regular expression pattern.\n *\n * @param {RegExp} expected - The regular expression pattern that the string value should match.\n * @returns {RequiredValidation} - A validation function that takes a received string and a path to the error message. Throws an error if the received value does not match the expected pattern.\n *\n * @example\n * const schema = string().custom(regExp(/^[A-Za-z0-9]+$/)); // Validates against alphanumeric pattern\n * parseSchema(schema, 'valid123'); // Valid\n * parseSchema(schema, 'invalid!@#'); // Throws an error: 'The received value does not match the required text pattern'\n */\nexport const regExp =\n (expected: RegExp): RequiredValidation =>\n (received: string, pathToError: string) => {\n if (!expected.test(received))\n throwException(expected, received, pathToError, 'The received value does not match the required text pattern');\n };\n","import { throwException } from '../../exceptions';\nimport { RequiredValidation } from '../../schemas/CommonSchema';\n\n/**\n * Creates a custom assertion that checks if a value is equal to the expected value.\n *\n * This assertion can be used within a `.custom` method to enforce that a value strictly matches the expected value.\n * It will throw a `ValidationError` if the values are not equal.\n *\n * @param {unknown} expected - The value that the received value is expected to match.\n * @returns {RequiredValidation} A function that takes the received value and the path to the error,\n * and throws a `ValidationError` if the received value does not equal the expected value.\n *\n * @throws {ValidationError} If the received value does not match the expected value.\n *\n * @example\n * import { number, equalTo } from 'bguard';\n *\n * // Define a schema with a custom assertion\n * const schema = number().custom(equalTo(5));\n *\n * // This will pass\n * parseSchema(schema, 5);\n *\n * // This will throw a ValidationError\n * parseSchema(schema, 3);\n */\nexport const equalTo =\n (expected: unknown): RequiredValidation =>\n (received: number, pathToError: string) => {\n if (expected !== received)\n throwException(expected, received, pathToError, 'The received value is not equal to expected');\n };\n","import { ctxSymbol } from '../core';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type RequiredValidation = (received: any, pathToError: string) => void;\nexport type ObjectShapeSchemaType = Record<string, CommonSchema>;\n\nexport type PrimitiveType = 'number' | 'string' | 'boolean' | 'undefined' | 'object' | 'function' | 'symbol' | 'bigint';\nexport interface ValidatorContext {\n type: PrimitiveType[];\n isNullable?: boolean;\n isOptional?: boolean;\n requiredValidations: RequiredValidation[];\n array?: CommonSchema;\n object?: ObjectShapeSchemaType;\n}\n\nexport class CommonSchema {\n [ctxSymbol]: ValidatorContext;\n constructor(ctx: ValidatorContext) {\n this[ctxSymbol] = ctx;\n }\n\n /**\n * @param validators - One or more custom validation functions.\n * @returns {this} The schema instance with the added custom validation.\n */\n custom(...validators: RequiredValidation[]): this {\n this[ctxSymbol].requiredValidations.push(...validators);\n return this;\n }\n\n /**\n * Marks the schema as nullable, allowing the value to be `null`.\n *\n * @returns {WithNull<this>} The schema instance marked as nullable.\n */\n nullable(): WithNull<this> {\n this[ctxSymbol].isNullable = true;\n return this as WithNull<this>;\n }\n\n /**\n * Marks the schema as optional, allowing the value to be `undefined`.\n *\n * @returns {WithUndefined<this>}} The schema instance marked as optional.\n */\n optional(): WithUndefined<this> {\n this[ctxSymbol].isOptional = true;\n return this as WithUndefined<this>;\n }\n}\n\nexport type WithNull<T extends CommonSchema> = T & { validation_null: true };\nexport type WithUndefined<T extends CommonSchema> = T & { validation_undefined: true };\n\ntype TypeMapping = {\n number: number;\n string: string;\n boolean: boolean;\n undefined: undefined;\n object: object;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n function: Function;\n symbol: symbol;\n bigint: bigint;\n};\n\nexport type WithMix<Y = unknown> = CommonSchema & { validation_mix: Y };\nexport type ExtractFromMix<T> = T extends WithMix<infer X> ? X : never;\n\nexport type MapMixTypes<T extends PrimitiveType[]> = T extends (infer U)[]\n ? U extends keyof TypeMapping\n ? TypeMapping[U]\n : never\n : never;\n","import { 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","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","import { throwException } from '../../exceptions';\nimport type { RequiredValidation } from '../../schemas/CommonSchema';\n\n/**\n * Asserts that the length of a string value is not greater than a specified maximum length.\n *\n * @param {number} expected - The maximum allowed length for the string.\n * @returns {RequiredValidation} - A validation function that takes a received string and a path to the error message. Throws an error if the length of the received value is greater than the expected length.\n *\n * @example\n * const schema = string().custom(maxLength(10));\n * parseSchema(schema, 'short'); // Valid\n * parseSchema(schema, 'this is a very long string'); // Throws an error: 'The received value length is greater than expected'\n */\nexport const maxLength =\n (expected: number): RequiredValidation =>\n (received: string, pathToError: string) => {\n if (received.length > expected)\n throwException(expected, received, pathToError, 'The received value length is greater than expected');\n };\n","import { expectEqualTypes } from '../../jest/setup';\nimport { parseSchema } from '../parseSchema';\nimport { regExp } from '../asserts/string/regExp';\nimport { InferType } from '../';\nimport { string } from '../asserts/string';\nimport { maxLength } from '../asserts/string/maxLength';\n\ndescribe('StringSchema', () => {\n const emailRegExp = /^[^@]+@[^@]+\\.[^@]+$/;\n\n it('should be a string', () => {\n const stringSchema = string();\n // eslint-disable-next-line @typescript-eslint/no-inferrable-types\n const actualString: string = 'this is a string';\n expectEqualTypes<typeof actualString, InferType<typeof stringSchema>>(true);\n const parsedValue = parseSchema(stringSchema, actualString);\n expect(parsedValue).toBe(actualString);\n });\n\n it('should not be a string', () => {\n const stringSchema = string();\n // eslint-disable-next-line @typescript-eslint/no-inferrable-types\n const actualNumber: number = 9;\n expectEqualTypes<typeof actualNumber, InferType<typeof stringSchema>>(false);\n expect(() => parseSchema(stringSchema, actualNumber)).toThrow('Invalid type of data');\n });\n\n it('should be an email', () => {\n const emailSchema = string().custom(regExp(emailRegExp));\n // eslint-disable-next-line @typescript-eslint/no-inferrable-types\n const email: string = 'mygoodemail@email.com';\n expectEqualTypes<typeof email, InferType<typeof emailSchema>>(true);\n const parsedValue = parseSchema(emailSchema, email);\n expect(parsedValue).toBe(email);\n });\n\n it('should not be an email', () => {\n const emailSchema = string().custom(regExp(emailRegExp));\n // eslint-disable-next-line @typescript-eslint/no-inferrable-types\n const email: string = 'mybademailemail.com';\n expectEqualTypes<typeof email, InferType<typeof emailSchema>>(true);\n expect(() => parseSchema(emailSchema, email)).toThrow(\n 'The received value does not match the required text pattern',\n );\n });\n\n it('should be equal to', () => {\n const stringLiteralSchema = string().equalTo('rightStringLiteral');\n const rightStringLiteral = 'rightStringLiteral';\n const wrongStringLiteral = 'wrongStringLiteral';\n expectEqualTypes<typeof rightStringLiteral, InferType<typeof stringLiteralSchema>>(true);\n expectEqualTypes<typeof wrongStringLiteral, InferType<typeof stringLiteralSchema>>(false);\n expect(rightStringLiteral).toBe(rightStringLiteral);\n expect(() => parseSchema(stringLiteralSchema, wrongStringLiteral)).toThrow(\n 'The received value is not equal to expected',\n );\n });\n\n it('should be an alphanumeric pattern', () => {\n const alphanumericSchema = string().custom(regExp(/^[A-Za-z0-9]+$/));\n expectEqualTypes<string, InferType<typeof alphanumericSchema>>(true);\n expect(parseSchema(alphanumericSchema, 'valid123')).toBe('valid123');\n expect(() => parseSchema(alphanumericSchema, 'invalid!@#')).toThrow(\n 'The received value does not match the required text pattern',\n );\n });\n\n it('should be an alphanumeric pattern', () => {\n const textSchema = string().custom(maxLength(5));\n expectEqualTypes<string, InferType<typeof textSchema>>(true);\n expect(parseSchema(textSchema, 'short')).toBe('short');\n expect(parseSchema(textSchema, 'yes')).toBe('yes');\n expect(() => parseSchema(textSchema, 'toolong')).toThrow('The received value length is greater than expected');\n });\n});\n"],"mappings":";;;AAEO,SAAS,iBAAuB,UAA6B;AAClE,SAAO,OAAO,QAAQ,EAAE,KAAK,SAAS;AACxC;;;ACJO,IAAM,kBAAN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eof areEqual).toBe("boolean");
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
// src/exceptions.ts
|
|
7
|
-
var ValidationError = class extends Error {
|
|
8
|
-
expected;
|
|
9
|
-
received;
|
|
10
|
-
pathToError;
|
|
11
|
-
message;
|
|
12
|
-
constructor(expected, received, pathToError, message) {
|
|
13
|
-
super();
|
|
14
|
-
this.expected = expected;
|
|
15
|
-
this.received = received;
|
|
16
|
-
this.pathToError = pathToError;
|
|
17
|
-
this.message = message;
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
function throwException(expected, received, pathToError, message) {
|
|
21
|
-
throw new ValidationError(expected, received, pathToError, message);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// src/core.ts
|
|
25
|
-
var ctxSymbol = Symbol("contextSymbol");
|
|
26
|
-
function innerCheck(schema, receivedValue, pathToError) {
|
|
27
|
-
const ctx = schema[ctxSymbol];
|
|
28
|
-
if (receivedValue === void 0) {
|
|
29
|
-
if (!ctx.isOptional) throwException("Required", receivedValue, pathToError, "The required value is missing");
|
|
30
|
-
return receivedValue;
|
|
31
|
-
}
|
|
32
|
-
if (receivedValue === null) {
|
|
33
|
-
if (!ctx.isNullable) throwException("Not null", receivedValue, pathToError, "Value should not be null");
|
|
34
|
-
return receivedValue;
|
|
35
|
-
}
|
|
36
|
-
if (ctx.array) {
|
|
37
|
-
if (!Array.isArray(receivedValue))
|
|
38
|
-
throwException("Array", receivedValue, pathToError, "Expected an array but received a different type");
|
|
39
|
-
const schema2 = ctx.array;
|
|
40
|
-
receivedValue.forEach((elem, i) => {
|
|
41
|
-
innerCheck(schema2, elem, `${pathToError}[${i}]`);
|
|
42
|
-
});
|
|
43
|
-
return receivedValue;
|
|
44
|
-
}
|
|
45
|
-
const typeOfVal = typeof receivedValue;
|
|
46
|
-
if (ctx.object) {
|
|
47
|
-
if (typeOfVal !== "object")
|
|
48
|
-
throwException("Object", receivedValue, pathToError, "Expected an object but received a different type");
|
|
49
|
-
if (Array.isArray(receivedValue))
|
|
50
|
-
throwException(
|
|
51
|
-
"Object",
|
|
52
|
-
receivedValue,
|
|
53
|
-
pathToError,
|
|
54
|
-
"Expected an object but received an array. Invalid type of data"
|
|
55
|
-
);
|
|
56
|
-
const shapeSchema = ctx.object;
|
|
57
|
-
for (const keyPerReceivedValue of Object.keys(receivedValue)) {
|
|
58
|
-
if (shapeSchema[keyPerReceivedValue] === void 0)
|
|
59
|
-
throwException("Not allowed", keyPerReceivedValue, pathToError, "This key is not allowed in the object");
|
|
60
|
-
}
|
|
61
|
-
for (const [keyOfSchema, valueOfSchema] of Object.entries(shapeSchema)) {
|
|
62
|
-
const receivedObjectValuePropery = receivedValue[keyOfSchema];
|
|
63
|
-
if (receivedObjectValuePropery === void 0) {
|
|
64
|
-
if (!valueOfSchema[ctxSymbol].isOptional)
|
|
65
|
-
throwException(
|
|
66
|
-
"Required",
|
|
67
|
-
receivedObjectValuePropery,
|
|
68
|
-
pathToError,
|
|
69
|
-
"Missing required property in the object"
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
innerCheck(valueOfSchema, receivedObjectValuePropery, `${pathToError}.${keyOfSchema}`);
|
|
73
|
-
}
|
|
74
|
-
return receivedValue;
|
|
75
|
-
}
|
|
76
|
-
if (ctx.type.length) {
|
|
77
|
-
if (!ctx.type.includes(typeOfVal)) throwException(ctx.type, typeOfVal, pathToError, "Invalid type of data");
|
|
78
|
-
}
|
|
79
|
-
ctx.requiredValidations.forEach((requiredValidation) => {
|
|
80
|
-
requiredValidation(receivedValue, pathToError);
|
|
81
|
-
});
|
|
82
|
-
return receivedValue;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// src/parseSchema.ts
|
|
86
|
-
function parseSchema(schema, receivedValue) {
|
|
87
|
-
try {
|
|
88
|
-
return innerCheck(schema, receivedValue, "");
|
|
89
|
-
} catch (e) {
|
|
90
|
-
if (e instanceof ValidationError) throw e;
|
|
91
|
-
throw new Error("Something unexpected happened");
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// src/asserts/string/regExp.ts
|
|
96
|
-
var regExp = (expected) => (received, pathToError) => {
|
|
97
|
-
if (!expected.test(received))
|
|
98
|
-
throwException(expected, received, pathToError, "The received value does not match the required text pattern");
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
// src/asserts/common/equalTo.ts
|
|
102
|
-
var equalTo = (expected) => (received, pathToError) => {
|
|
103
|
-
if (expected !== received)
|
|
104
|
-
throwException(expected, received, pathToError, "The received value is not equal to expected");
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
// src/schemas/CommonSchema.ts
|
|
108
|
-
var CommonSchema = class {
|
|
109
|
-
[ctxSymbol];
|
|
110
|
-
constructor(ctx) {
|
|
111
|
-
this[ctxSymbol] = ctx;
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* @param validators - One or more custom validation functions.
|
|
115
|
-
* @returns {this} The schema instance with the added custom validation.
|
|
116
|
-
*/
|
|
117
|
-
custom(...validators) {
|
|
118
|
-
this[ctxSymbol].requiredValidations.push(...validators);
|
|
119
|
-
return this;
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Marks the schema as nullable, allowing the value to be `null`.
|
|
123
|
-
*
|
|
124
|
-
* @returns {WithNull<this>} The schema instance marked as nullable.
|
|
125
|
-
*/
|
|
126
|
-
nullable() {
|
|
127
|
-
this[ctxSymbol].isNullable = true;
|
|
128
|
-
return this;
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Marks the schema as optional, allowing the value to be `undefined`.
|
|
132
|
-
*
|
|
133
|
-
* @returns {WithUndefined<this>}} The schema instance marked as optional.
|
|
134
|
-
*/
|
|
135
|
-
optional() {
|
|
136
|
-
this[ctxSymbol].isOptional = true;
|
|
137
|
-
return this;
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
// src/schemas/StringSchema.ts
|
|
142
|
-
var StringSchema = class extends CommonSchema {
|
|
143
|
-
_string = 1;
|
|
144
|
-
/**
|
|
145
|
-
* Restricts the schema to exactly match the specified value and infers the literal value as the TypeScript type.
|
|
146
|
-
*
|
|
147
|
-
* @param expectedValue - The value that the schema must exactly match.
|
|
148
|
-
* @returns - The schema instance restricted to the specified value, with the literal value inferred as the TypeScript type
|
|
149
|
-
*
|
|
150
|
-
* @example - string().equalTo('hello'); // Infers the type 'hello'
|
|
151
|
-
*/
|
|
152
|
-
equalTo(expectedValue) {
|
|
153
|
-
return this.custom(equalTo(expectedValue));
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
// src/asserts/string/index.ts
|
|
158
|
-
function string() {
|
|
159
|
-
return new StringSchema({ type: ["string"], requiredValidations: [] });
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// src/asserts/string/maxLength.ts
|
|
163
|
-
var maxLength = (expected) => (received, pathToError) => {
|
|
164
|
-
if (received.length > expected)
|
|
165
|
-
throwException(expected, received, pathToError, "The received value length is greater than expected");
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
// src/__tests__/StringSchema.test.ts
|
|
169
|
-
describe("StringSchema", () => {
|
|
170
|
-
const emailRegExp = /^[^@]+@[^@]+\.[^@]+$/;
|
|
171
|
-
it("should be a string", () => {
|
|
172
|
-
const stringSchema = string();
|
|
173
|
-
const actualString = "this is a string";
|
|
174
|
-
expectEqualTypes(true);
|
|
175
|
-
const parsedValue = parseSchema(stringSchema, actualString);
|
|
176
|
-
expect(parsedValue).toBe(actualString);
|
|
177
|
-
});
|
|
178
|
-
it("should not be a string", () => {
|
|
179
|
-
const stringSchema = string();
|
|
180
|
-
const actualNumber = 9;
|
|
181
|
-
expectEqualTypes(false);
|
|
182
|
-
expect(() => parseSchema(stringSchema, actualNumber)).toThrow("Invalid type of data");
|
|
183
|
-
});
|
|
184
|
-
it("should be an email", () => {
|
|
185
|
-
const emailSchema = string().custom(regExp(emailRegExp));
|
|
186
|
-
const email = "mygoodemail@email.com";
|
|
187
|
-
expectEqualTypes(true);
|
|
188
|
-
const parsedValue = parseSchema(emailSchema, email);
|
|
189
|
-
expect(parsedValue).toBe(email);
|
|
190
|
-
});
|
|
191
|
-
it("should not be an email", () => {
|
|
192
|
-
const emailSchema = string().custom(regExp(emailRegExp));
|
|
193
|
-
const email = "mybademailemail.com";
|
|
194
|
-
expectEqualTypes(true);
|
|
195
|
-
expect(() => parseSchema(emailSchema, email)).toThrow(
|
|
196
|
-
"The received value does not match the required text pattern"
|
|
197
|
-
);
|
|
198
|
-
});
|
|
199
|
-
it("should be equal to", () => {
|
|
200
|
-
const stringLiteralSchema = string().equalTo("rightStringLiteral");
|
|
201
|
-
const rightStringLiteral = "rightStringLiteral";
|
|
202
|
-
const wrongStringLiteral = "wrongStringLiteral";
|
|
203
|
-
expectEqualTypes(true);
|
|
204
|
-
expectEqualTypes(false);
|
|
205
|
-
expect(rightStringLiteral).toBe(rightStringLiteral);
|
|
206
|
-
expect(() => parseSchema(stringLiteralSchema, wrongStringLiteral)).toThrow(
|
|
207
|
-
"The received value is not equal to expected"
|
|
208
|
-
);
|
|
209
|
-
});
|
|
210
|
-
it("should be an alphanumeric pattern", () => {
|
|
211
|
-
const alphanumericSchema = string().custom(regExp(/^[A-Za-z0-9]+$/));
|
|
212
|
-
expectEqualTypes(true);
|
|
213
|
-
expect(parseSchema(alphanumericSchema, "valid123")).toBe("valid123");
|
|
214
|
-
expect(() => parseSchema(alphanumericSchema, "invalid!@#")).toThrow(
|
|
215
|
-
"The received value does not match the required text pattern"
|
|
216
|
-
);
|
|
217
|
-
});
|
|
218
|
-
it("should be an alphanumeric pattern", () => {
|
|
219
|
-
const textSchema = string().custom(maxLength(5));
|
|
220
|
-
expectEqualTypes(true);
|
|
221
|
-
expect(parseSchema(textSchema, "short")).toBe("short");
|
|
222
|
-
expect(parseSchema(textSchema, "yes")).toBe("yes");
|
|
223
|
-
expect(() => parseSchema(textSchema, "toolong")).toThrow("The received value length is greater than expected");
|
|
224
|
-
});
|
|
225
|
-
});
|
|
226
|
-
//# sourceMappingURL=StringSchema.test.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../jest/setup.ts","../../src/exceptions.ts","../../src/core.ts","../../src/parseSchema.ts","../../src/asserts/string/regExp.ts","../../src/asserts/common/equalTo.ts","../../src/schemas/CommonSchema.ts","../../src/schemas/StringSchema.ts","../../src/asserts/string/index.ts","../../src/asserts/string/maxLength.ts","../../src/__tests__/StringSchema.test.ts"],"sourcesContent":["export type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false;\n\nexport function expectEqualTypes<X, Y>(areEqual: Equal<X, Y>): void {\n expect(typeof areEqual).toBe('boolean');\n}\n","export class ValidationError extends Error {\n expected: unknown;\n received: unknown;\n pathToError: string;\n message: string;\n constructor(expected: unknown, received: unknown, pathToError: string, message: string) {\n super();\n this.expected = expected;\n this.received = received;\n this.pathToError = pathToError;\n this.message = message;\n }\n}\n\nexport class BuildSchemaError extends Error {}\n\nexport function throwException(expected: unknown, received: unknown, pathToError: string, message: string): never {\n throw new ValidationError(expected, received, pathToError, message);\n}\n","export const ctxSymbol = Symbol('contextSymbol');\n\nimport { throwException } from './exceptions';\nimport type { CommonSchema } from './schemas/CommonSchema';\n\nexport function innerCheck(schema: CommonSchema, receivedValue: unknown, pathToError: string) {\n const ctx = schema[ctxSymbol];\n if (receivedValue === undefined) {\n if (!ctx.isOptional) throwException('Required', receivedValue, pathToError, 'The required value is missing');\n return receivedValue;\n }\n\n if (receivedValue === null) {\n if (!ctx.isNullable) throwException('Not null', receivedValue, pathToError, 'Value should not be null');\n return receivedValue;\n }\n\n if (ctx.array) {\n if (!Array.isArray(receivedValue))\n throwException('Array', receivedValue, pathToError, 'Expected an array but received a different type');\n const schema = ctx.array;\n\n receivedValue.forEach((elem, i) => {\n innerCheck(schema, elem, `${pathToError}[${i}]`);\n });\n\n return receivedValue;\n }\n\n const typeOfVal = typeof receivedValue;\n\n if (ctx.object) {\n if (typeOfVal !== 'object')\n throwException('Object', receivedValue, pathToError, 'Expected an object but received a different type');\n if (Array.isArray(receivedValue))\n throwException(\n 'Object',\n receivedValue,\n pathToError,\n 'Expected an object but received an array. Invalid type of data',\n );\n const shapeSchema = ctx.object;\n for (const keyPerReceivedValue of Object.keys(receivedValue)) {\n if (shapeSchema[keyPerReceivedValue] === undefined)\n throwException('Not allowed', keyPerReceivedValue, pathToError, 'This key is not allowed in the object');\n }\n\n for (const [keyOfSchema, valueOfSchema] of Object.entries(shapeSchema)) {\n const receivedObjectValuePropery = (receivedValue as Record<string, unknown>)[keyOfSchema];\n if (receivedObjectValuePropery === undefined) {\n if (!valueOfSchema[ctxSymbol].isOptional)\n throwException(\n 'Required',\n receivedObjectValuePropery,\n pathToError,\n 'Missing required property in the object',\n );\n }\n innerCheck(valueOfSchema, receivedObjectValuePropery, `${pathToError}.${keyOfSchema}`);\n }\n\n return receivedValue;\n }\n\n if (ctx.type.length) {\n if (!ctx.type.includes(typeOfVal)) throwException(ctx.type, typeOfVal, pathToError, 'Invalid type of data');\n }\n\n ctx.requiredValidations.forEach((requiredValidation) => {\n requiredValidation(receivedValue, pathToError);\n });\n\n return receivedValue;\n}\n","import { 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","import { throwException } from '../../exceptions';\nimport type { RequiredValidation } from '../../schemas/CommonSchema';\n\n/**\n * Asserts that a string value matches a specified regular expression pattern.\n *\n * @param {RegExp} expected - The regular expression pattern that the string value should match.\n * @returns {RequiredValidation} - A validation function that takes a received string and a path to the error message. Throws an error if the received value does not match the expected pattern.\n *\n * @example\n * const schema = string().custom(regExp(/^[A-Za-z0-9]+$/)); // Validates against alphanumeric pattern\n * parseSchema(schema, 'valid123'); // Valid\n * parseSchema(schema, 'invalid!@#'); // Throws an error: 'The received value does not match the required text pattern'\n */\nexport const regExp =\n (expected: RegExp): RequiredValidation =>\n (received: string, pathToError: string) => {\n if (!expected.test(received))\n throwException(expected, received, pathToError, 'The received value does not match the required text pattern');\n };\n","import { throwException } from '../../exceptions';\nimport { RequiredValidation } from '../../schemas/CommonSchema';\n\n/**\n * Creates a custom assertion that checks if a value is equal to the expected value.\n *\n * This assertion can be used within a `.custom` method to enforce that a value strictly matches the expected value.\n * It will throw a `ValidationError` if the values are not equal.\n *\n * @param {unknown} expected - The value that the received value is expected to match.\n * @returns {RequiredValidation} A function that takes the received value and the path to the error,\n * and throws a `ValidationError` if the received value does not equal the expected value.\n *\n * @throws {ValidationError} If the received value does not match the expected value.\n *\n * @example\n * import { number, equalTo } from 'bguard';\n *\n * // Define a schema with a custom assertion\n * const schema = number().custom(equalTo(5));\n *\n * // This will pass\n * parseSchema(schema, 5);\n *\n * // This will throw a ValidationError\n * parseSchema(schema, 3);\n */\nexport const equalTo =\n (expected: unknown): RequiredValidation =>\n (received: number, pathToError: string) => {\n if (expected !== received)\n throwException(expected, received, pathToError, 'The received value is not equal to expected');\n };\n","import { ctxSymbol } from '../core';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type RequiredValidation = (received: any, pathToError: string) => void;\nexport type ObjectShapeSchemaType = Record<string, CommonSchema>;\n\nexport type PrimitiveType = 'number' | 'string' | 'boolean' | 'undefined' | 'object' | 'function' | 'symbol' | 'bigint';\nexport interface ValidatorContext {\n type: PrimitiveType[];\n isNullable?: boolean;\n isOptional?: boolean;\n requiredValidations: RequiredValidation[];\n array?: CommonSchema;\n object?: ObjectShapeSchemaType;\n}\n\nexport class CommonSchema {\n [ctxSymbol]: ValidatorContext;\n constructor(ctx: ValidatorContext) {\n this[ctxSymbol] = ctx;\n }\n\n /**\n * @param validators - One or more custom validation functions.\n * @returns {this} The schema instance with the added custom validation.\n */\n custom(...validators: RequiredValidation[]): this {\n this[ctxSymbol].requiredValidations.push(...validators);\n return this;\n }\n\n /**\n * Marks the schema as nullable, allowing the value to be `null`.\n *\n * @returns {WithNull<this>} The schema instance marked as nullable.\n */\n nullable(): WithNull<this> {\n this[ctxSymbol].isNullable = true;\n return this as WithNull<this>;\n }\n\n /**\n * Marks the schema as optional, allowing the value to be `undefined`.\n *\n * @returns {WithUndefined<this>}} The schema instance marked as optional.\n */\n optional(): WithUndefined<this> {\n this[ctxSymbol].isOptional = true;\n return this as WithUndefined<this>;\n }\n}\n\nexport type WithNull<T extends CommonSchema> = T & { validation_null: true };\nexport type WithUndefined<T extends CommonSchema> = T & { validation_undefined: true };\n\ntype TypeMapping = {\n number: number;\n string: string;\n boolean: boolean;\n undefined: undefined;\n object: object;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n function: Function;\n symbol: symbol;\n bigint: bigint;\n};\n\nexport type WithMix<Y = unknown> = CommonSchema & { validation_mix: Y };\nexport type ExtractFromMix<T> = T extends WithMix<infer X> ? X : never;\n\nexport type MapMixTypes<T extends PrimitiveType[]> = T extends (infer U)[]\n ? U extends keyof TypeMapping\n ? TypeMapping[U]\n : never\n : never;\n","import { 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","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","import { throwException } from '../../exceptions';\nimport type { RequiredValidation } from '../../schemas/CommonSchema';\n\n/**\n * Asserts that the length of a string value is not greater than a specified maximum length.\n *\n * @param {number} expected - The maximum allowed length for the string.\n * @returns {RequiredValidation} - A validation function that takes a received string and a path to the error message. Throws an error if the length of the received value is greater than the expected length.\n *\n * @example\n * const schema = string().custom(maxLength(10));\n * parseSchema(schema, 'short'); // Valid\n * parseSchema(schema, 'this is a very long string'); // Throws an error: 'The received value length is greater than expected'\n */\nexport const maxLength =\n (expected: number): RequiredValidation =>\n (received: string, pathToError: string) => {\n if (received.length > expected)\n throwException(expected, received, pathToError, 'The received value length is greater than expected');\n };\n","import { expectEqualTypes } from '../../jest/setup';\nimport { parseSchema } from '../parseSchema';\nimport { regExp } from '../asserts/string/regExp';\nimport { InferType } from '../';\nimport { string } from '../asserts/string';\nimport { maxLength } from '../asserts/string/maxLength';\n\ndescribe('StringSchema', () => {\n const emailRegExp = /^[^@]+@[^@]+\\.[^@]+$/;\n\n it('should be a string', () => {\n const stringSchema = string();\n // eslint-disable-next-line @typescript-eslint/no-inferrable-types\n const actualString: string = 'this is a string';\n expectEqualTypes<typeof actualString, InferType<typeof stringSchema>>(true);\n const parsedValue = parseSchema(stringSchema, actualString);\n expect(parsedValue).toBe(actualString);\n });\n\n it('should not be a string', () => {\n const stringSchema = string();\n // eslint-disable-next-line @typescript-eslint/no-inferrable-types\n const actualNumber: number = 9;\n expectEqualTypes<typeof actualNumber, InferType<typeof stringSchema>>(false);\n expect(() => parseSchema(stringSchema, actualNumber)).toThrow('Invalid type of data');\n });\n\n it('should be an email', () => {\n const emailSchema = string().custom(regExp(emailRegExp));\n // eslint-disable-next-line @typescript-eslint/no-inferrable-types\n const email: string = 'mygoodemail@email.com';\n expectEqualTypes<typeof email, InferType<typeof emailSchema>>(true);\n const parsedValue = parseSchema(emailSchema, email);\n expect(parsedValue).toBe(email);\n });\n\n it('should not be an email', () => {\n const emailSchema = string().custom(regExp(emailRegExp));\n // eslint-disable-next-line @typescript-eslint/no-inferrable-types\n const email: string = 'mybademailemail.com';\n expectEqualTypes<typeof email, InferType<typeof emailSchema>>(true);\n expect(() => parseSchema(emailSchema, email)).toThrow(\n 'The received value does not match the required text pattern',\n );\n });\n\n it('should be equal to', () => {\n const stringLiteralSchema = string().equalTo('rightStringLiteral');\n const rightStringLiteral = 'rightStringLiteral';\n const wrongStringLiteral = 'wrongStringLiteral';\n expectEqualTypes<typeof rightStringLiteral, InferType<typeof stringLiteralSchema>>(true);\n expectEqualTypes<typeof wrongStringLiteral, InferType<typeof stringLiteralSchema>>(false);\n expect(rightStringLiteral).toBe(rightStringLiteral);\n expect(() => parseSchema(stringLiteralSchema, wrongStringLiteral)).toThrow(\n 'The received value is not equal to expected',\n );\n });\n\n it('should be an alphanumeric pattern', () => {\n const alphanumericSchema = string().custom(regExp(/^[A-Za-z0-9]+$/));\n expectEqualTypes<string, InferType<typeof alphanumericSchema>>(true);\n expect(parseSchema(alphanumericSchema, 'valid123')).toBe('valid123');\n expect(() => parseSchema(alphanumericSchema, 'invalid!@#')).toThrow(\n 'The received value does not match the required text pattern',\n );\n });\n\n it('should be an alphanumeric pattern', () => {\n const textSchema = string().custom(maxLength(5));\n expectEqualTypes<string, InferType<typeof textSchema>>(true);\n expect(parseSchema(textSchema, 'short')).toBe('short');\n expect(parseSchema(textSchema, 'yes')).toBe('yes');\n expect(() => parseSchema(textSchema, 'toolong')).toThrow('The received value length is greater than expected');\n });\n});\n"],"mappings":";AAEO,SAAS,iBAAuB,UAA6B;AAClE,SAAO,OAAO,QAAQ,EAAE,KAAK,SAAS;AACxC;;;ACJO,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,MA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