🎯 MapView v2.0 - Global Deployment Ready

 MAJOR FEATURES:
• Auto-zoom intelligence với smart bounds fitting
• Enhanced 3D GPS markers với pulsing effects
• Professional route display với 6-layer rendering
• Status-based parking icons với availability indicators
• Production-ready build optimizations

🗺️ AUTO-ZOOM FEATURES:
• Smart bounds fitting cho GPS + selected parking
• Adaptive padding (50px) cho visual balance
• Max zoom control (level 16) để tránh quá gần
• Dynamic centering khi không có selection

🎨 ENHANCED VISUALS:
• 3D GPS marker với multi-layer pulse effects
• Advanced parking icons với status colors
• Selection highlighting với animation
• Dimming system cho non-selected items

🛣️ ROUTE SYSTEM:
• OpenRouteService API integration
• Multi-layer route rendering (glow, shadow, main, animated)
• Real-time distance & duration calculation
• Visual route info trong popup

📱 PRODUCTION READY:
• SSR safe với dynamic imports
• Build errors resolved
• Global deployment via Vercel
• Optimized performance

🌍 DEPLOYMENT:
• Vercel: https://whatever-ctk2auuxr-phong12hexdockworks-projects.vercel.app
• Bundle size: 22.8 kB optimized
• Global CDN distribution
• HTTPS enabled

💾 VERSION CONTROL:
• MapView-v2.0.tsx backup created
• MAPVIEW_VERSIONS.md documentation
• Full version history tracking
This commit is contained in:
2025-07-20 19:52:16 +07:00
parent 3203463a6a
commit c65cc97a33
64624 changed files with 7199453 additions and 6462 deletions

View File

@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=ValidationArguments.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"ValidationArguments.js","sourceRoot":"","sources":["../../../src/validation/ValidationArguments.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Arguments being sent to message builders - user can create message either by simply returning a string,\n * either by returning a function that accepts MessageArguments and returns a message string built based on these arguments.\n */\nexport interface ValidationArguments {\n /**\n * Validating value.\n */\n value: any;\n\n /**\n * Constraints set by this validation type.\n */\n constraints: any[];\n\n /**\n * Name of the target that is being validated.\n */\n targetName: string;\n\n /**\n * Object that is being validated.\n */\n object: object;\n\n /**\n * Name of the object's property being validated.\n */\n property: string;\n}\n"]}

View File

@@ -0,0 +1,48 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ValidationError = void 0;
/**
* Validation error description.
*/
class ValidationError {
/**
*
* @param shouldDecorate decorate the message with ANSI formatter escape codes for better readability
* @param hasParent true when the error is a child of an another one
* @param parentPath path as string to the parent of this property
* @param showConstraintMessages show constraint messages instead of constraint names
*/
toString(shouldDecorate = false, hasParent = false, parentPath = ``, showConstraintMessages = false) {
const boldStart = shouldDecorate ? `\x1b[1m` : ``;
const boldEnd = shouldDecorate ? `\x1b[22m` : ``;
const constraintsToString = () => { var _a; return (showConstraintMessages ? Object.values : Object.keys)((_a = this.constraints) !== null && _a !== void 0 ? _a : {}).join(`, `); };
const propConstraintFailed = (propertyName) => ` - property ${boldStart}${parentPath}${propertyName}${boldEnd} has failed the following constraints: ${boldStart}${constraintsToString()}${boldEnd} \n`;
if (!hasParent) {
return (`An instance of ${boldStart}${this.target ? this.target.constructor.name : 'an object'}${boldEnd} has failed the validation:\n` +
(this.constraints ? propConstraintFailed(this.property) : ``) +
(this.children
? this.children
.map(childError => childError.toString(shouldDecorate, true, this.property, showConstraintMessages))
.join(``)
: ``));
}
else {
// we format numbers as array indexes for better readability.
const formattedProperty = Number.isInteger(+this.property)
? `[${this.property}]`
: `${parentPath ? `.` : ``}${this.property}`;
if (this.constraints) {
return propConstraintFailed(formattedProperty);
}
else {
return this.children
? this.children
.map(childError => childError.toString(shouldDecorate, true, `${parentPath}${formattedProperty}`, showConstraintMessages))
.join(``)
: ``;
}
}
}
}
exports.ValidationError = ValidationError;
//# sourceMappingURL=ValidationError.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"ValidationError.js","sourceRoot":"","sources":["../../../src/validation/ValidationError.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,MAAa,eAAe;IAuC1B;;;;;;OAMG;IACH,QAAQ,CACN,iBAA0B,KAAK,EAC/B,YAAqB,KAAK,EAC1B,aAAq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N,6DAA6D;YAC7D,MAAM,iBAAiB,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC;gBACxD,CAAC,CAAC,IAAI,IAAI,CAAC,QAAQ,GAAG;gBACtB,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;YAE/C,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;gBACrB,OAAO,oBAAoB,CAAC,iBAAiB,CAAC,CAAC;YACjD,CAAC;iBAAM,CAAC;gBACN,OAAO,IAAI,CAAC,QAAQ;oBAClB,CAAC,CAAC,IAAI,CAAC,QAAQ;yBACV,GAAG,CAAC,UAAU,CAAC,EAAE,CAChB,UAAU,CAAC,QAAQ,CAAC,cAAc,EAAE,IAAI,EAAE,GAAG,UAAU,GAAG,iBAAiB,EAAE,EAAE,sBAAsB,CAAC,CACvG;yBACA,IAAI,CAAC,EAAE,CAAC;oBACb,CAAC,CAAC,EAAE,CAAC;YACT,CAAC;QACH,CAAC;IACH,CAAC;CACF;AA1FD,0CA0FC","sourcesContent":["/**\n * Validation error description.\n */\nexport class ValidationError {\n /**\n * Object that was validated.\n *\n * OPTIONAL - configurable via the ValidatorOptions.validationError.target option\n */\n target?: object;\n\n /**\n * Object's property that haven't pass validation.\n */\n property: string;\n\n /**\n * Value that haven't pass a validation.\n *\n * OPTIONAL - configurable via the ValidatorOptions.validationError.value option\n */\n value?: any;\n\n /**\n * Constraints that failed validation with error messages.\n */\n constraints?: {\n [type: string]: string;\n };\n\n /**\n * Contains all nested validation errors of the property.\n */\n children?: ValidationError[];\n\n /*\n * A transient set of data passed through to the validation result for response mapping\n */\n contexts?: {\n [type: string]: any;\n };\n\n /**\n *\n * @param shouldDecorate decorate the message with ANSI formatter escape codes for better readability\n * @param hasParent true when the error is a child of an another one\n * @param parentPath path as string to the parent of this property\n * @param showConstraintMessages show constraint messages instead of constraint names\n */\n toString(\n shouldDecorate: boolean = false,\n hasParent: boolean = false,\n parentPath: string = ``,\n showConstraintMessages: boolean = false\n ): string {\n const boldStart = shouldDecorate ? `\\x1b[1m` : ``;\n const boldEnd = shouldDecorate ? `\\x1b[22m` : ``;\n const constraintsToString = () =>\n (showConstraintMessages ? Object.values : Object.keys)(this.constraints ?? {}).join(`, `);\n const propConstraintFailed = (propertyName: string): string =>\n ` - property ${boldStart}${parentPath}${propertyName}${boldEnd} has failed the following constraints: ${boldStart}${constraintsToString()}${boldEnd} \\n`;\n\n if (!hasParent) {\n return (\n `An instance of ${boldStart}${\n this.target ? this.target.constructor.name : 'an object'\n }${boldEnd} has failed the validation:\\n` +\n (this.constraints ? propConstraintFailed(this.property) : ``) +\n (this.children\n ? this.children\n .map(childError => childError.toString(shouldDecorate, true, this.property, showConstraintMessages))\n .join(``)\n : ``)\n );\n } else {\n // we format numbers as array indexes for better readability.\n const formattedProperty = Number.isInteger(+this.property)\n ? `[${this.property}]`\n : `${parentPath ? `.` : ``}${this.property}`;\n\n if (this.constraints) {\n return propConstraintFailed(formattedProperty);\n } else {\n return this.children\n ? this.children\n .map(childError =>\n childError.toString(shouldDecorate, true, `${parentPath}${formattedProperty}`, showConstraintMessages)\n )\n .join(``)\n : ``;\n }\n }\n }\n}\n"]}

View File

@@ -0,0 +1,324 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ValidationExecutor = void 0;
const ValidationError_1 = require("./ValidationError");
const ValidationTypes_1 = require("./ValidationTypes");
const ValidationUtils_1 = require("./ValidationUtils");
const utils_1 = require("../utils");
const MetadataStorage_1 = require("../metadata/MetadataStorage");
/**
* Executes validation over given object.
*/
class ValidationExecutor {
// -------------------------------------------------------------------------
// Constructor
// -------------------------------------------------------------------------
constructor(validator, validatorOptions) {
this.validator = validator;
this.validatorOptions = validatorOptions;
// -------------------------------------------------------------------------
// Properties
// -------------------------------------------------------------------------
this.awaitingPromises = [];
this.ignoreAsyncValidations = false;
// -------------------------------------------------------------------------
// Private Properties
// -------------------------------------------------------------------------
this.metadataStorage = (0, MetadataStorage_1.getMetadataStorage)();
}
// -------------------------------------------------------------------------
// Public Methods
// -------------------------------------------------------------------------
execute(object, targetSchema, validationErrors) {
var _a, _b;
/**
* If there is no metadata registered it means possibly the dependencies are not flatterned and
* more than one instance is used.
*
* TODO: This needs proper handling, forcing to use the same container or some other proper solution.
*/
if (!this.metadataStorage.hasValidationMetaData && ((_a = this.validatorOptions) === null || _a === void 0 ? void 0 : _a.enableDebugMessages) === true) {
console.warn(`No validation metadata found. No validation will be performed. There are multiple possible reasons:\n` +
` - There may be multiple class-validator versions installed. You will need to flatten your dependencies to fix the issue.\n` +
` - This validation runs before any file with validation decorator was parsed by NodeJS.`);
}
const groups = this.validatorOptions ? this.validatorOptions.groups : undefined;
const strictGroups = (this.validatorOptions && this.validatorOptions.strictGroups) || false;
const always = (this.validatorOptions && this.validatorOptions.always) || false;
/** Forbid unknown values are turned on by default and any other value than false will enable it. */
const forbidUnknownValues = ((_b = this.validatorOptions) === null || _b === void 0 ? void 0 : _b.forbidUnknownValues) === undefined || this.validatorOptions.forbidUnknownValues !== false;
const targetMetadatas = this.metadataStorage.getTargetValidationMetadatas(object.constructor, targetSchema, always, strictGroups, groups);
const groupedMetadatas = this.metadataStorage.groupByPropertyName(targetMetadatas);
if (forbidUnknownValues && !targetMetadatas.length) {
const validationError = new ValidationError_1.ValidationError();
if (!this.validatorOptions ||
!this.validatorOptions.validationError ||
this.validatorOptions.validationError.target === undefined ||
this.validatorOptions.validationError.target === true)
validationError.target = object;
validationError.value = undefined;
validationError.property = undefined;
validationError.children = [];
validationError.constraints = { unknownValue: 'an unknown value was passed to the validate function' };
validationErrors.push(validationError);
return;
}
if (this.validatorOptions && this.validatorOptions.whitelist)
this.whitelist(object, groupedMetadatas, validationErrors);
// General validation
Object.keys(groupedMetadatas).forEach(propertyName => {
const value = object[propertyName];
const definedMetadatas = groupedMetadatas[propertyName].filter(metadata => metadata.type === ValidationTypes_1.ValidationTypes.IS_DEFINED);
const metadatas = groupedMetadatas[propertyName].filter(metadata => metadata.type !== ValidationTypes_1.ValidationTypes.IS_DEFINED && metadata.type !== ValidationTypes_1.ValidationTypes.WHITELIST);
if (value instanceof Promise &&
metadatas.find(metadata => metadata.type === ValidationTypes_1.ValidationTypes.PROMISE_VALIDATION)) {
this.awaitingPromises.push(value.then(resolvedValue => {
this.performValidations(object, resolvedValue, propertyName, definedMetadatas, metadatas, validationErrors);
}));
}
else {
this.performValidations(object, value, propertyName, definedMetadatas, metadatas, validationErrors);
}
});
}
whitelist(object, groupedMetadatas, validationErrors) {
const notAllowedProperties = [];
Object.keys(object).forEach(propertyName => {
// does this property have no metadata?
if (!groupedMetadatas[propertyName] || groupedMetadatas[propertyName].length === 0)
notAllowedProperties.push(propertyName);
});
if (notAllowedProperties.length > 0) {
if (this.validatorOptions && this.validatorOptions.forbidNonWhitelisted) {
// throw errors
notAllowedProperties.forEach(property => {
const validationError = this.generateValidationError(object, object[property], property);
validationError.constraints = { [ValidationTypes_1.ValidationTypes.WHITELIST]: `property ${property} should not exist` };
validationError.children = undefined;
validationErrors.push(validationError);
});
}
else {
// strip non allowed properties
notAllowedProperties.forEach(property => delete object[property]);
}
}
}
stripEmptyErrors(errors) {
return errors.filter(error => {
if (error.children) {
error.children = this.stripEmptyErrors(error.children);
}
if (Object.keys(error.constraints).length === 0) {
if (error.children.length === 0) {
return false;
}
else {
delete error.constraints;
}
}
return true;
});
}
// -------------------------------------------------------------------------
// Private Methods
// -------------------------------------------------------------------------
performValidations(object, value, propertyName, definedMetadatas, metadatas, validationErrors) {
const customValidationMetadatas = metadatas.filter(metadata => metadata.type === ValidationTypes_1.ValidationTypes.CUSTOM_VALIDATION);
const nestedValidationMetadatas = metadatas.filter(metadata => metadata.type === ValidationTypes_1.ValidationTypes.NESTED_VALIDATION);
const conditionalValidationMetadatas = metadatas.filter(metadata => metadata.type === ValidationTypes_1.ValidationTypes.CONDITIONAL_VALIDATION);
const validationError = this.generateValidationError(object, value, propertyName);
validationErrors.push(validationError);
const canValidate = this.conditionalValidations(object, value, conditionalValidationMetadatas);
if (!canValidate) {
return;
}
// handle IS_DEFINED validation type the special way - it should work no matter skipUndefinedProperties/skipMissingProperties is set or not
this.customValidations(object, value, definedMetadatas, validationError);
this.mapContexts(object, value, definedMetadatas, validationError);
if (value === undefined && this.validatorOptions && this.validatorOptions.skipUndefinedProperties === true) {
return;
}
if (value === null && this.validatorOptions && this.validatorOptions.skipNullProperties === true) {
return;
}
if ((value === null || value === undefined) &&
this.validatorOptions &&
this.validatorOptions.skipMissingProperties === true) {
return;
}
this.customValidations(object, value, customValidationMetadatas, validationError);
this.nestedValidations(value, nestedValidationMetadatas, validationError);
this.mapContexts(object, value, metadatas, validationError);
this.mapContexts(object, value, customValidationMetadatas, validationError);
}
generateValidationError(object, value, propertyName) {
const validationError = new ValidationError_1.ValidationError();
if (!this.validatorOptions ||
!this.validatorOptions.validationError ||
this.validatorOptions.validationError.target === undefined ||
this.validatorOptions.validationError.target === true)
validationError.target = object;
if (!this.validatorOptions ||
!this.validatorOptions.validationError ||
this.validatorOptions.validationError.value === undefined ||
this.validatorOptions.validationError.value === true)
validationError.value = value;
validationError.property = propertyName;
validationError.children = [];
validationError.constraints = {};
return validationError;
}
conditionalValidations(object, value, metadatas) {
return metadatas
.map(metadata => metadata.constraints[0](object, value))
.reduce((resultA, resultB) => resultA && resultB, true);
}
customValidations(object, value, metadatas, error) {
metadatas.forEach(metadata => {
this.metadataStorage.getTargetValidatorConstraints(metadata.constraintCls).forEach(customConstraintMetadata => {
if (customConstraintMetadata.async && this.ignoreAsyncValidations)
return;
if (this.validatorOptions &&
this.validatorOptions.stopAtFirstError &&
Object.keys(error.constraints || {}).length > 0)
return;
const validationArguments = {
targetName: object.constructor ? object.constructor.name : undefined,
property: metadata.propertyName,
object: object,
value: value,
constraints: metadata.constraints,
};
if (!metadata.each || !(Array.isArray(value) || value instanceof Set || value instanceof Map)) {
const validatedValue = customConstraintMetadata.instance.validate(value, validationArguments);
if ((0, utils_1.isPromise)(validatedValue)) {
const promise = validatedValue.then(isValid => {
if (!isValid) {
const [type, message] = this.createValidationError(object, value, metadata, customConstraintMetadata);
error.constraints[type] = message;
if (metadata.context) {
if (!error.contexts) {
error.contexts = {};
}
error.contexts[type] = Object.assign(error.contexts[type] || {}, metadata.context);
}
}
});
this.awaitingPromises.push(promise);
}
else {
if (!validatedValue) {
const [type, message] = this.createValidationError(object, value, metadata, customConstraintMetadata);
error.constraints[type] = message;
}
}
return;
}
// convert set and map into array
const arrayValue = (0, utils_1.convertToArray)(value);
// Validation needs to be applied to each array item
const validatedSubValues = arrayValue.map((subValue) => customConstraintMetadata.instance.validate(subValue, validationArguments));
const validationIsAsync = validatedSubValues.some((validatedSubValue) => (0, utils_1.isPromise)(validatedSubValue));
if (validationIsAsync) {
// Wrap plain values (if any) in promises, so that all are async
const asyncValidatedSubValues = validatedSubValues.map((validatedSubValue) => (0, utils_1.isPromise)(validatedSubValue) ? validatedSubValue : Promise.resolve(validatedSubValue));
const asyncValidationIsFinishedPromise = Promise.all(asyncValidatedSubValues).then((flatValidatedValues) => {
const validationResult = flatValidatedValues.every((isValid) => isValid);
if (!validationResult) {
const [type, message] = this.createValidationError(object, value, metadata, customConstraintMetadata);
error.constraints[type] = message;
if (metadata.context) {
if (!error.contexts) {
error.contexts = {};
}
error.contexts[type] = Object.assign(error.contexts[type] || {}, metadata.context);
}
}
});
this.awaitingPromises.push(asyncValidationIsFinishedPromise);
return;
}
const validationResult = validatedSubValues.every((isValid) => isValid);
if (!validationResult) {
const [type, message] = this.createValidationError(object, value, metadata, customConstraintMetadata);
error.constraints[type] = message;
}
});
});
}
nestedValidations(value, metadatas, error) {
if (value === void 0) {
return;
}
metadatas.forEach(metadata => {
if (metadata.type !== ValidationTypes_1.ValidationTypes.NESTED_VALIDATION && metadata.type !== ValidationTypes_1.ValidationTypes.PROMISE_VALIDATION) {
return;
}
else if (this.validatorOptions &&
this.validatorOptions.stopAtFirstError &&
Object.keys(error.constraints || {}).length > 0) {
return;
}
if (Array.isArray(value) || value instanceof Set || value instanceof Map) {
// Treats Set as an array - as index of Set value is value itself and it is common case to have Object as value
const arrayLikeValue = value instanceof Set ? Array.from(value) : value;
arrayLikeValue.forEach((subValue, index) => {
this.performValidations(value, subValue, index.toString(), [], metadatas, error.children);
});
}
else if (value instanceof Object) {
const targetSchema = typeof metadata.target === 'string' ? metadata.target : metadata.target.name;
this.execute(value, targetSchema, error.children);
}
else {
const [type, message] = this.createValidationError(metadata.target, value, metadata);
error.constraints[type] = message;
}
});
}
mapContexts(object, value, metadatas, error) {
return metadatas.forEach(metadata => {
if (metadata.context) {
let customConstraint;
if (metadata.type === ValidationTypes_1.ValidationTypes.CUSTOM_VALIDATION) {
const customConstraints = this.metadataStorage.getTargetValidatorConstraints(metadata.constraintCls);
customConstraint = customConstraints[0];
}
const type = this.getConstraintType(metadata, customConstraint);
if (error.constraints[type]) {
if (!error.contexts) {
error.contexts = {};
}
error.contexts[type] = Object.assign(error.contexts[type] || {}, metadata.context);
}
}
});
}
createValidationError(object, value, metadata, customValidatorMetadata) {
const targetName = object.constructor ? object.constructor.name : undefined;
const type = this.getConstraintType(metadata, customValidatorMetadata);
const validationArguments = {
targetName: targetName,
property: metadata.propertyName,
object: object,
value: value,
constraints: metadata.constraints,
};
let message = metadata.message || '';
if (!metadata.message &&
(!this.validatorOptions || (this.validatorOptions && !this.validatorOptions.dismissDefaultMessages))) {
if (customValidatorMetadata && customValidatorMetadata.instance.defaultMessage instanceof Function) {
message = customValidatorMetadata.instance.defaultMessage(validationArguments);
}
}
const messageString = ValidationUtils_1.ValidationUtils.replaceMessageSpecialTokens(message, validationArguments);
return [type, messageString];
}
getConstraintType(metadata, customValidatorMetadata) {
const type = customValidatorMetadata && customValidatorMetadata.name ? customValidatorMetadata.name : metadata.type;
return type;
}
}
exports.ValidationExecutor = ValidationExecutor;
//# sourceMappingURL=ValidationExecutor.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,27 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ValidationTypes = void 0;
/**
* Validation types.
*/
class ValidationTypes {
/**
* Checks if validation type is valid.
*/
static isValid(type) {
return (type !== 'isValid' &&
type !== 'getMessage' &&
Object.keys(this)
.map(key => this[key])
.indexOf(type) !== -1);
}
}
exports.ValidationTypes = ValidationTypes;
/* system */
ValidationTypes.CUSTOM_VALIDATION = 'customValidation'; // done
ValidationTypes.NESTED_VALIDATION = 'nestedValidation'; // done
ValidationTypes.PROMISE_VALIDATION = 'promiseValidation'; // done
ValidationTypes.CONDITIONAL_VALIDATION = 'conditionalValidation'; // done
ValidationTypes.WHITELIST = 'whitelistValidation'; // done
ValidationTypes.IS_DEFINED = 'isDefined'; // done
//# sourceMappingURL=ValidationTypes.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"ValidationTypes.js","sourceRoot":"","sources":["../../../src/validation/ValidationTypes.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,MAAa,eAAe;IAS1B;;OAEG;IACH,MAAM,CAAC,OAAO,CAAC,IAAY;QACzB,OAAO,CACL,IAAI,KAAK,SAAS;YAClB,IAAI,KAAK,YAAY;YACrB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;iBACd,GAAG,CAAC,GAAG,CAAC,EAAE,CAAE,IAAY,CAAC,GAAG,CAAC,CAAC;iBAC9B,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CACxB,CAAC;IACJ,CAAC;;AApBH,0CAqBC;AApBC,YAAY;AACL,iCAAiB,GAAG,kBAAkB,CAAC,CAAC,OAAO;AAC/C,iCAAiB,GAAG,kBAAkB,CAAC,CAAC,OAAO;AAC/C,kCAAkB,GAAG,mBAAmB,CAAC,CAAC,OAAO;AACjD,sCAAsB,GAAG,uBAAuB,CAAC,CAAC,OAAO;AACzD,yBAAS,GAAG,qBAAqB,CAAC,CAAC,OAAO;AAC1C,0BAAU,GAAG,WAAW,CAAC,CAAC,OAAO","sourcesContent":["/**\n * Validation types.\n */\nexport class ValidationTypes {\n /* system */\n static CUSTOM_VALIDATION = 'customValidation'; // done\n static NESTED_VALIDATION = 'nestedValidation'; // done\n static PROMISE_VALIDATION = 'promiseValidation'; // done\n static CONDITIONAL_VALIDATION = 'conditionalValidation'; // done\n static WHITELIST = 'whitelistValidation'; // done\n static IS_DEFINED = 'isDefined'; // done\n\n /**\n * Checks if validation type is valid.\n */\n static isValid(type: string): boolean {\n return (\n type !== 'isValid' &&\n type !== 'getMessage' &&\n Object.keys(this)\n .map(key => (this as any)[key])\n .indexOf(type) !== -1\n );\n }\n}\n"]}

View File

@@ -0,0 +1,44 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ValidationUtils = exports.constraintToString = void 0;
/**
* Convert the constraint to a string to be shown in an error
*/
function constraintToString(constraint) {
if (Array.isArray(constraint)) {
return constraint.join(', ');
}
if (typeof constraint === 'symbol') {
constraint = constraint.description;
}
return `${constraint}`;
}
exports.constraintToString = constraintToString;
class ValidationUtils {
static replaceMessageSpecialTokens(message, validationArguments) {
let messageString;
if (message instanceof Function) {
messageString = message(validationArguments);
}
else if (typeof message === 'string') {
messageString = message;
}
if (messageString && Array.isArray(validationArguments.constraints)) {
validationArguments.constraints.forEach((constraint, index) => {
messageString = messageString.replace(new RegExp(`\\$constraint${index + 1}`, 'g'), constraintToString(constraint));
});
}
if (messageString &&
validationArguments.value !== undefined &&
validationArguments.value !== null &&
['string', 'boolean', 'number'].includes(typeof validationArguments.value))
messageString = messageString.replace(/\$value/g, validationArguments.value);
if (messageString)
messageString = messageString.replace(/\$property/g, validationArguments.property);
if (messageString)
messageString = messageString.replace(/\$target/g, validationArguments.targetName);
return messageString;
}
}
exports.ValidationUtils = ValidationUtils;
//# sourceMappingURL=ValidationUtils.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"ValidationUtils.js","sourceRoot":"","sources":["../../../src/validation/ValidationUtils.ts"],"names":[],"mapp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AO,CAAC,UAAU,EAAE,mBAAmB,CAAC,KAAK,CAAC,CAAC;QAC/E,IAAI,aAAa;YAAE,aAAa,GAAG,aAAa,CAAC,OAAO,CAAC,aAAa,EAAE,mBAAmB,CAAC,QAAQ,CAAC,CAAC;QACtG,IAAI,aAAa;YAAE,aAAa,GAAG,aAAa,CAAC,OAAO,CAAC,WAAW,EAAE,mBAAmB,CAAC,UAAU,CAAC,CAAC;QAEtG,OAAO,aAAa,CAAC;IACvB,CAAC;CACF;AAjCD,0CAiCC","sourcesContent":["import { ValidationArguments } from './ValidationArguments';\n\n/**\n * Convert the constraint to a string to be shown in an error\n */\nexport function constraintToString(constraint: unknown): string {\n if (Array.isArray(constraint)) {\n return constraint.join(', ');\n }\n\n if (typeof constraint === 'symbol') {\n constraint = constraint.description;\n }\n\n return `${constraint}`;\n}\n\nexport class ValidationUtils {\n static replaceMessageSpecialTokens(\n message: string | ((args: ValidationArguments) => string),\n validationArguments: ValidationArguments\n ): string {\n let messageString: string;\n if (message instanceof Function) {\n messageString = (message as (args: ValidationArguments) => string)(validationArguments);\n } else if (typeof message === 'string') {\n messageString = message;\n }\n\n if (messageString && Array.isArray(validationArguments.constraints)) {\n validationArguments.constraints.forEach((constraint, index) => {\n messageString = messageString.replace(\n new RegExp(`\\\\$constraint${index + 1}`, 'g'),\n constraintToString(constraint)\n );\n });\n }\n\n if (\n messageString &&\n validationArguments.value !== undefined &&\n validationArguments.value !== null &&\n ['string', 'boolean', 'number'].includes(typeof validationArguments.value)\n )\n messageString = messageString.replace(/\\$value/g, validationArguments.value);\n if (messageString) messageString = messageString.replace(/\\$property/g, validationArguments.property);\n if (messageString) messageString = messageString.replace(/\\$target/g, validationArguments.targetName);\n\n return messageString;\n }\n}\n"]}

View File

@@ -0,0 +1,56 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Validator = void 0;
const ValidationExecutor_1 = require("./ValidationExecutor");
/**
* Validator performs validation of the given object based on its metadata.
*/
class Validator {
/**
* Performs validation of the given object based on decorators or validation schema.
*/
validate(objectOrSchemaName, objectOrValidationOptions, maybeValidatorOptions) {
return this.coreValidate(objectOrSchemaName, objectOrValidationOptions, maybeValidatorOptions);
}
/**
* Performs validation of the given object based on decorators or validation schema and reject on error.
*/
async validateOrReject(objectOrSchemaName, objectOrValidationOptions, maybeValidatorOptions) {
const errors = await this.coreValidate(objectOrSchemaName, objectOrValidationOptions, maybeValidatorOptions);
if (errors.length)
return Promise.reject(errors);
}
/**
* Performs validation of the given object based on decorators or validation schema.
*/
validateSync(objectOrSchemaName, objectOrValidationOptions, maybeValidatorOptions) {
const object = typeof objectOrSchemaName === 'string' ? objectOrValidationOptions : objectOrSchemaName;
const options = typeof objectOrSchemaName === 'string' ? maybeValidatorOptions : objectOrValidationOptions;
const schema = typeof objectOrSchemaName === 'string' ? objectOrSchemaName : undefined;
const executor = new ValidationExecutor_1.ValidationExecutor(this, options);
executor.ignoreAsyncValidations = true;
const validationErrors = [];
executor.execute(object, schema, validationErrors);
return executor.stripEmptyErrors(validationErrors);
}
// -------------------------------------------------------------------------
// Private Properties
// -------------------------------------------------------------------------
/**
* Performs validation of the given object based on decorators or validation schema.
* Common method for `validateOrReject` and `validate` methods.
*/
coreValidate(objectOrSchemaName, objectOrValidationOptions, maybeValidatorOptions) {
const object = typeof objectOrSchemaName === 'string' ? objectOrValidationOptions : objectOrSchemaName;
const options = typeof objectOrSchemaName === 'string' ? maybeValidatorOptions : objectOrValidationOptions;
const schema = typeof objectOrSchemaName === 'string' ? objectOrSchemaName : undefined;
const executor = new ValidationExecutor_1.ValidationExecutor(this, options);
const validationErrors = [];
executor.execute(object, schema, validationErrors);
return Promise.all(executor.awaitingPromises).then(() => {
return executor.stripEmptyErrors(validationErrors);
});
}
}
exports.Validator = Validator;
//# sourceMappingURL=Validator.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=ValidatorConstraintInterface.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"ValidatorConstraintInterface.js","sourceRoot":"","sources":["../../../src/validation/ValidatorConstraintInterface.ts"],"names":[],"mappings":"","sourcesContent":["import { ValidationArguments } from './ValidationArguments';\n/**\n * Custom validators must implement this interface to provide custom validation logic.\n */\nexport interface ValidatorConstraintInterface {\n /**\n * Method to be called to perform custom validation over given value.\n */\n validate(value: any, validationArguments?: ValidationArguments): Promise<boolean> | boolean;\n\n /**\n * Gets default message when validation for this constraint fail.\n */\n defaultMessage?(validationArguments?: ValidationArguments): string;\n}\n"]}

View File

@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=ValidatorOptions.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"ValidatorOptions.js","sourceRoot":"","sources":["../../../src/validation/ValidatorOptions.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Options passed to validator during validation.\n */\nexport interface ValidatorOptions {\n /**\n * If set to true then class-validator will print extra warning messages to the console when something is not right.\n */\n enableDebugMessages?: boolean;\n\n /**\n * If set to true then validator will skip validation of all properties that are undefined in the validating object.\n */\n skipUndefinedProperties?: boolean;\n\n /**\n * If set to true then validator will skip validation of all properties that are null in the validating object.\n */\n skipNullProperties?: boolean;\n\n /**\n * If set to true then validator will skip validation of all properties that are null or undefined in the validating object.\n */\n skipMissingProperties?: boolean;\n\n /**\n * If set to true validator will strip validated object of any properties that do not have any decorators.\n *\n * Tip: if no other decorator is suitable for your property use @Allow decorator.\n */\n whitelist?: boolean;\n\n /**\n * If set to true, instead of stripping non-whitelisted properties validator will throw an error\n */\n forbidNonWhitelisted?: boolean;\n\n /**\n * Groups to be used during validation of the object.\n */\n groups?: string[];\n\n /**\n * Set default for `always` option of decorators. Default can be overridden in decorator options.\n */\n always?: boolean;\n\n /**\n * If [groups]{@link ValidatorOptions#groups} is not given or is empty,\n * ignore decorators with at least one group.\n */\n strictGroups?: boolean;\n\n /**\n * If set to true, the validation will not use default messages.\n * Error message always will be undefined if its not explicitly set.\n */\n dismissDefaultMessages?: boolean;\n\n /**\n * ValidationError special options.\n */\n validationError?: {\n /**\n * Indicates if target should be exposed in ValidationError.\n */\n target?: boolean;\n\n /**\n * Indicates if validated value should be exposed in ValidationError.\n */\n value?: boolean;\n };\n\n /**\n * Fails validation for objects unknown to class-validator. Defaults to true.\n *\n * For instance, since a plain empty object has no annotations used for validation:\n * - `validate({})` // fails.\n * - `validate({}, { forbidUnknownValues: true })` // fails.\n * - `validate({}, { forbidUnknownValues: false })` // passes.\n * - `validate(new SomeAnnotatedEmptyClass(), { forbidUnknownValues: true })` // passes.\n */\n forbidUnknownValues?: boolean;\n\n /**\n * When set to true, validation of the given property will stop after encountering the first error. Defaults to false.\n */\n stopAtFirstError?: boolean;\n}\n"]}