UNPKG

bguard

Version:

**bguard** is a powerful, flexible, and type-safe validation library for TypeScript. It allows developers to define validation schemas for their data structures and ensures that data conforms to the expected types and constraints.

1 lines 21.9 kB
{"version":3,"sources":["../src/core.ts"],"sourcesContent":["import { isValidDateInner } from './helpers/isValidDateInner';\nimport {\n BaseType,\n MetaContext,\n TransformCallback,\n TranslationErrorMap,\n ValidationErrorData,\n WithNull,\n WithUndefined,\n} from './commonTypes';\nimport { type InferType } from './InferType';\nimport { BuildSchemaError, ValidationError } from './exceptions';\nimport { getTranslationByLocale } from './translationMap';\nimport { ctxSymbol } from './helpers/constants';\n\nconst replacePlaceholdersRegex = /{{(.*?)}}/g;\n\nfunction replacePlaceholders(template: string, replacements: Record<string, unknown>): string {\n return template.replace(replacePlaceholdersRegex, (_, key) => {\n return key in replacements ? `${replacements[key] as string}` : `{{${key}}}`;\n });\n}\n\nexport class ExceptionContext {\n constructor(\n public readonly initialReceived: unknown,\n public readonly t: TranslationErrorMap,\n public readonly pathToError: string,\n public readonly errors?: ValidationErrorData[],\n public readonly meta?: MetaContext,\n ) {}\n\n createChild(childPathToError: string, childMeta?: MetaContext) {\n return new ExceptionContext(this.initialReceived, this.t, childPathToError, this.errors, childMeta);\n }\n\n public ref(path: string): unknown {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let ref: any = this.initialReceived;\n const parsedRefPath = path.split('.');\n parsedRefPath.forEach((el) => {\n ref = ref[el];\n });\n\n return ref;\n }\n\n public addIssue(expected: unknown, received: unknown, messageKey: string): never | void {\n const rawMessage = this.t[messageKey] ?? messageKey;\n const message = replacePlaceholders(rawMessage, { e: expected, r: received, p: this.pathToError });\n\n if (this.errors) {\n this.errors.push({\n expected,\n received,\n pathToError: this.pathToError,\n message,\n });\n\n return;\n }\n\n throw new ValidationError(expected, received, this.pathToError, message, this.meta);\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type RequiredValidation = (received: any, ctx: ExceptionContext) => void;\n\nfunction innerCheck(schema: CommonSchema, receivedValue: unknown, exCtx: ExceptionContext): unknown {\n const commonTmap = exCtx.t;\n const schemaData = schema[ctxSymbol];\n\n schemaData.transformListBefore?.forEach((transformCallback) => {\n receivedValue = transformCallback(receivedValue);\n });\n\n if (receivedValue === undefined) {\n if (schemaData.defaultValue !== undefined) return schemaData.defaultValue;\n if (!schemaData.isOptional) exCtx.addIssue('Required', receivedValue, commonTmap['c:optional']);\n return receivedValue;\n }\n\n if (receivedValue === null) {\n if (!schemaData.isNullable) exCtx.addIssue('Not null', receivedValue, commonTmap['c:nullable']);\n return receivedValue;\n }\n\n if (schemaData.date) {\n if (!isValidDateInner(receivedValue)) exCtx.addIssue('Date', receivedValue, commonTmap['c:date']);\n }\n\n const typeOfVal = typeof receivedValue;\n\n if (schemaData.type.length) {\n if (!schemaData.type.includes(typeOfVal)) exCtx.addIssue(schemaData.type, typeOfVal, commonTmap['c:invalidType']);\n }\n\n if (schemaData.array) {\n if (!Array.isArray(receivedValue)) return exCtx.addIssue('Array', receivedValue, commonTmap['c:array']);\n\n schemaData.requiredValidations.forEach((requiredValidation) => {\n requiredValidation(receivedValue, exCtx);\n });\n\n const schema = schemaData.array;\n const pathToError = exCtx.pathToError;\n const parsedReceivedValue: unknown[] = [];\n receivedValue.forEach((elem, i) => {\n const parsedElement = innerCheck(schema, elem, exCtx.createChild(`${pathToError}[${i}]`, schemaData.meta));\n parsedReceivedValue.push(parsedElement);\n });\n\n return parsedReceivedValue;\n }\n\n if (schemaData.object) {\n if (typeOfVal !== 'object') exCtx.addIssue('Object', receivedValue, commonTmap['c:objectType']);\n if (Array.isArray(receivedValue)) exCtx.addIssue('Object', receivedValue, commonTmap['c:objectTypeAsArray']);\n\n schemaData.requiredValidations.forEach((requiredValidation) => {\n requiredValidation(receivedValue, exCtx);\n });\n\n const shapeSchema = schemaData.object;\n const parsedReceivedValue: Record<string, unknown> = {};\n\n if (!schemaData.allowUnrecognizedObjectProps) {\n for (const keyPerReceivedValue of Object.keys(receivedValue)) {\n if (shapeSchema[keyPerReceivedValue] === undefined)\n exCtx.addIssue('Unrecognized property', keyPerReceivedValue, commonTmap['c:unrecognizedProperty']);\n }\n }\n\n const pathToError = exCtx.pathToError;\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 exCtx.addIssue('Required', receivedObjectValuePropery, commonTmap['c:requiredProperty']);\n }\n\n const parsedReceivedObjectValuePropery = innerCheck(\n valueOfSchema,\n receivedObjectValuePropery,\n exCtx.createChild(`${pathToError}.${keyOfSchema}`, schemaData.meta),\n );\n\n parsedReceivedValue[keyOfSchema] = parsedReceivedObjectValuePropery;\n }\n\n return parsedReceivedValue;\n }\n\n schemaData.requiredValidations.forEach((requiredValidation) => {\n requiredValidation(receivedValue, exCtx);\n });\n\n return receivedValue;\n}\n\nexport type ObjectShapeSchemaType = Record<string, CommonSchema>;\n\nexport interface ValidatorContext {\n type: BaseType[];\n isNullable?: boolean;\n isOptional?: boolean;\n requiredValidations: RequiredValidation[];\n array?: CommonSchema;\n object?: ObjectShapeSchemaType;\n allowUnrecognizedObjectProps?: boolean;\n strictType?: boolean;\n strictTypeValue?: unknown;\n date?: boolean;\n defaultValue?: unknown;\n meta?: MetaContext;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n transformListBefore?: TransformCallback<any, any>[];\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 public custom(...validators: RequiredValidation[]): this {\n this.defaultValueCheck();\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 public nullable(): WithNull<this> {\n this.defaultValueCheck();\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 public optional(): WithUndefined<this> {\n this.defaultValueCheck();\n this[ctxSymbol].isOptional = true;\n return this as WithUndefined<this>;\n }\n\n /**\n * Marks the schema as optional, allowing the value to be `undefined`.\n *\n * @returns {this} The schema instance. This method should be used as a last one because it does the check of previous methods and\n */\n public default(defaultValue: InferType<this>): this {\n const ctx = this[ctxSymbol];\n if (ctx.isOptional) {\n throw new BuildSchemaError(`Cannot call method 'default' after method 'optional'`);\n }\n\n try {\n parseOrFail(this, defaultValue);\n } catch (e) {\n throw new BuildSchemaError((e as Error).message);\n }\n\n this[ctxSymbol].defaultValue = defaultValue;\n return this;\n }\n\n /**\n * Applies a transformation to the input value before any validation occurs.\n * The transformation should return a value of the same type as the inferred type of the schema,\n * ensuring that the overall type is not altered.\n *\n * @template In - The type of the input value before transformation (defaults to `unknown`).\n * @param {TransformCallback<In, InferType<this>>} cb - The callback function that performs the transformation.\n * @returns {this} The updated schema with the applied transformation.\n *\n * @example\n * const schema = string()\n * .nullable()\n * .transformBeforeValidation((val) => val + '') // Ensure the value is a string\n * .transformBeforeValidation((val: string) => (val === '' ? null : val)); // Convert empty strings to null\n *\n * // Parse 'test' will pass as 'test' is a valid string longer than 3 characters.\n * parseOrFail(schema, 'test');\n *\n * // Parsing '' will be transformed to null and will pass due to .nullable().\n * parseOrFail(schema, '');\n */\n public transformBeforeValidation<In>(cb: TransformCallback<In, InferType<this>>): this {\n const ctx = this[ctxSymbol];\n if (ctx.transformListBefore) {\n ctx.transformListBefore.push(cb);\n } else {\n ctx.transformListBefore = [cb];\n }\n\n return this;\n }\n\n /**\n * Assigns a unique identifier to the schema.\n * This ID can be used to track or map validation errors back to specific fields\n * in a form or other structures.\n *\n * @param {string} value - The unique identifier for the schema.\n * @returns {this} The updated schema with the assigned ID.\n *\n * @example\n * const schema = string().id('username');\n */\n public id(value: string): this {\n return this.meta('id', value);\n }\n\n /**\n * Provides a description for the schema, offering additional context or information.\n * The description can be used when displaying validation errors or for documentation purposes.\n *\n * @param {string} value - The description for the schema.\n * @returns {this} The updated schema with the added description.\n *\n * @example\n * const schema = string().description('The username of the account holder.');\n */\n public description(value: string): this {\n return this.meta('description', value);\n }\n\n private meta(key: string, value: string): this {\n const ctx = this[ctxSymbol];\n ctx.meta = { ...ctx.meta, [key]: value };\n return this;\n }\n\n protected defaultValueCheck() {\n if (this[ctxSymbol].defaultValue !== undefined) {\n throw new BuildSchemaError('Default value must be the last method called in schema');\n }\n }\n}\n\ninterface ParseOptions {\n /**\n * Set language keyword to map error messages.\n * @default 'default'\n * @example 'sr' or 'Serbia' or any string to identify language\n */\n lng?: string;\n}\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 * @param {ParseOptions} options - Options\n * @param {ParseOptions.lng} options.lng - Set language keyword to map Error message\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 = parseOrFail(schema, { name: 'Alice', age: 30 });\n * // result will be inferred as { name: string; age: number }\n *\n * parseOrFail(schema, { name: 'Alice', age: '30' });\n * // Throws ValidationError because 'age' should be a number, not a string.\n */\nexport function parseOrFail<T extends CommonSchema>(\n schema: T,\n receivedValue: unknown,\n options?: ParseOptions,\n): InferType<T> {\n try {\n const ctx = new ExceptionContext(\n receivedValue,\n getTranslationByLocale(options?.lng),\n '',\n undefined,\n schema[ctxSymbol].meta,\n );\n return innerCheck(schema, receivedValue, ctx) as InferType<T>;\n } catch (e) {\n /* istanbul ignore next */\n if (e instanceof ValidationError) throw e;\n /* istanbul ignore next */\n throw new Error('Something unexpected happened');\n }\n}\n\ninterface ParseOptions {\n /**\n * Set language keyword to map error messages.\n * @default 'default'\n * @example 'sr' or 'Serbia' or any string to identify language\n */\n lng?: string;\n\n /**\n * If true, collects all validation errors and returns them.\n * If false or undefined, returns the first validation error it can find and stops looking,\n * which provides a small runtime optimization.\n * @default undefined\n */\n getAllErrors?: boolean;\n}\n\n/**\n * Parses and validates a value against the provided schema, returning a type-safe parsedValue.\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 * @param {ParseOptions} options - Options\n * @param {ParseOptions.lng} options.lng - Set language keyword to map Error messages\n * @param {ParseOptions.lng} options.getAllErrors - If `false` or `undefined` - returns the first validation error it can find and stops looking, which provides a small runtime optimization.\n * @returns {[undefined, InferType<T>]} A tuple of [undefined, InferType<T>] if parsing is successful.\n * @returns {[ValidationErrorData[], undefined]} A tuple of [ValidationErrorData[], undefined]] if errors occur.\n *\n * @example\n * const schema = object({\n * name: string(),\n * age: number(),\n * });\n *\n * const [errors, parsedValue] = parse(schema, { name: 'Alice', age: 30 });\n * // parsedValue will be inferred as { name: string; age: number }\n *\n *\n * const [errors, parsedValue] = parse(schema, { name: 'Alice', age: '30' });\n * // First element in array \"errors\" will have an error because 'age' should be a number, not a string.\n * // Array 'errors' returns only one element.\n *\n *\n * const [errors, parsedValue] = parse(schema, { name: true, age: '30' }, { getAllErrors: true});\n * // Returns array \"errors\" with multiple errors because 'age' should be a number and 'name' a string.\n * // With provided options { getAllErrors: true}, we can expecte more than one error in 'errors' array.\n *\n *\n * const [errors, parsedValue] = parse(schema, { name: true, age: '30' }, { lng: 'SR'});\n * // First element in array \"errors\" will have an error because 'age' should be a number, not a string.\n * // With provided options { lng: 'SR'}, errors will be translated to a language mapped with keyword 'SR'\n */\nexport function parse<T extends CommonSchema>(\n schema: T,\n receivedValue: unknown,\n options?: ParseOptions,\n): [ValidationErrorData[], undefined] | [undefined, InferType<T>] {\n try {\n const ctx = new ExceptionContext(\n receivedValue,\n getTranslationByLocale(options?.lng),\n '',\n options?.getAllErrors ? [] : undefined,\n schema[ctxSymbol].meta,\n );\n\n const parsedValue = innerCheck(schema, receivedValue, ctx) as InferType<T>;\n\n if (ctx.errors?.length) {\n return [ctx.errors, undefined];\n }\n\n return [undefined, parsedValue];\n } catch (e) {\n /* istanbul ignore next */\n if (e instanceof ValidationError) {\n delete e.stack;\n return [[e], undefined];\n }\n /* istanbul ignore next */\n return [\n [\n {\n message: 'Something unexpected happened',\n expected: '',\n received: '',\n pathToError: '',\n meta: undefined,\n },\n ],\n undefined,\n ];\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAeA,IAAM,2BAA2B;AAEjC,SAAS,oBAAoB,UAAkB,cAA+C;AAC5F,SAAO,SAAS,QAAQ,0BAA0B,CAAC,GAAG,QAAQ;AAC5D,WAAO,OAAO,eAAe,GAAG,aAAa,GAAG,CAAW,KAAK,KAAK,GAAG;AAAA,EAC1E,CAAC;AACH;AAEO,IAAM,mBAAN,MAAM,kBAAiB;AAAA,EAC5B,YACkB,iBACA,GACA,aACA,QACA,MAChB;AALgB;AACA;AACA;AACA;AACA;AAAA,EACf;AAAA,EAEH,YAAY,kBAA0B,WAAyB;AAC7D,WAAO,IAAI,kBAAiB,KAAK,iBAAiB,KAAK,GAAG,kBAAkB,KAAK,QAAQ,SAAS;AAAA,EACpG;AAAA,EAEO,IAAI,MAAuB;AAEhC,QAAI,MAAW,KAAK;AACpB,UAAM,gBAAgB,KAAK,MAAM,GAAG;AACpC,kBAAc,QAAQ,CAAC,OAAO;AAC5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