reliant-type 1.0.0
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/LICENSE +21 -0
- package/README.md +1305 -0
- package/dist/cjs/constants/SECURITY_CONSTANTS.js +49 -0
- package/dist/cjs/constants/SECURITY_CONSTANTS.js.map +1 -0
- package/dist/cjs/constants/VALIDATION_CONSTANTS.js +103 -0
- package/dist/cjs/constants/VALIDATION_CONSTANTS.js.map +1 -0
- package/dist/cjs/core/schema/extensions/SmartInference.js +200 -0
- package/dist/cjs/core/schema/extensions/SmartInference.js.map +1 -0
- package/dist/cjs/core/schema/extensions/components/AutoDocumentation/Docs.js +100 -0
- package/dist/cjs/core/schema/extensions/components/AutoDocumentation/Docs.js.map +1 -0
- package/dist/cjs/core/schema/extensions/components/AutoDocumentation/DocumentationGenerator.js +192 -0
- package/dist/cjs/core/schema/extensions/components/AutoDocumentation/DocumentationGenerator.js.map +1 -0
- package/dist/cjs/core/schema/extensions/components/AutoDocumentation/InteractiveDocumentationGenerator.js +174 -0
- package/dist/cjs/core/schema/extensions/components/AutoDocumentation/InteractiveDocumentationGenerator.js.map +1 -0
- package/dist/cjs/core/schema/extensions/components/AutoDocumentation/SchemaAnalyzer.js +54 -0
- package/dist/cjs/core/schema/extensions/components/AutoDocumentation/SchemaAnalyzer.js.map +1 -0
- package/dist/cjs/core/schema/extensions/components/AutoDocumentation/TypeScriptGenerator.js +50 -0
- package/dist/cjs/core/schema/extensions/components/AutoDocumentation/TypeScriptGenerator.js.map +1 -0
- package/dist/cjs/core/schema/extensions/components/AutoDocumentation/index.js +15 -0
- package/dist/cjs/core/schema/extensions/components/AutoDocumentation/index.js.map +1 -0
- package/dist/cjs/core/schema/extensions/components/ConditionalValidation/ConditionalBuilder.js +70 -0
- package/dist/cjs/core/schema/extensions/components/ConditionalValidation/ConditionalBuilder.js.map +1 -0
- package/dist/cjs/core/schema/extensions/components/ConditionalValidation/ConditionalElse.js +40 -0
- package/dist/cjs/core/schema/extensions/components/ConditionalValidation/ConditionalElse.js.map +1 -0
- package/dist/cjs/core/schema/extensions/components/ConditionalValidation/ConditionalThen.js +19 -0
- package/dist/cjs/core/schema/extensions/components/ConditionalValidation/ConditionalThen.js.map +1 -0
- package/dist/cjs/core/schema/extensions/components/ConditionalValidation/MultiConditionalBuilder.js +20 -0
- package/dist/cjs/core/schema/extensions/components/ConditionalValidation/MultiConditionalBuilder.js.map +1 -0
- package/dist/cjs/core/schema/extensions/components/ConditionalValidation/MultiConditionalThen.js +49 -0
- package/dist/cjs/core/schema/extensions/components/ConditionalValidation/MultiConditionalThen.js.map +1 -0
- package/dist/cjs/core/schema/extensions/components/ConditionalValidation/index.js +98 -0
- package/dist/cjs/core/schema/extensions/components/ConditionalValidation/index.js.map +1 -0
- package/dist/cjs/core/schema/extensions/components/RealtimeValidation/FormValidator.js +85 -0
- package/dist/cjs/core/schema/extensions/components/RealtimeValidation/FormValidator.js.map +1 -0
- package/dist/cjs/core/schema/extensions/components/RealtimeValidation/LiveValidator.js +133 -0
- package/dist/cjs/core/schema/extensions/components/RealtimeValidation/LiveValidator.js.map +1 -0
- package/dist/cjs/core/schema/extensions/components/RealtimeValidation/StreamValidator.js +351 -0
- package/dist/cjs/core/schema/extensions/components/RealtimeValidation/StreamValidator.js.map +1 -0
- package/dist/cjs/core/schema/extensions/components/RealtimeValidation/index.js +109 -0
- package/dist/cjs/core/schema/extensions/components/RealtimeValidation/index.js.map +1 -0
- package/dist/cjs/core/schema/extensions/index.js +61 -0
- package/dist/cjs/core/schema/extensions/index.js.map +1 -0
- package/dist/cjs/core/schema/extensions/mods/index.js +51 -0
- package/dist/cjs/core/schema/extensions/mods/index.js.map +1 -0
- package/dist/cjs/core/schema/extensions/mods/openapi-converter.js +227 -0
- package/dist/cjs/core/schema/extensions/mods/openapi-converter.js.map +1 -0
- package/dist/cjs/core/schema/extensions/mods/typescript-generator.js +287 -0
- package/dist/cjs/core/schema/extensions/mods/typescript-generator.js.map +1 -0
- package/dist/cjs/core/schema/extensions/mods/validation-engine.js +224 -0
- package/dist/cjs/core/schema/extensions/mods/validation-engine.js.map +1 -0
- package/dist/cjs/core/schema/mode/interfaces/Interface.js +277 -0
- package/dist/cjs/core/schema/mode/interfaces/Interface.js.map +1 -0
- package/dist/cjs/core/schema/mode/interfaces/InterfaceSchema.js +1431 -0
- package/dist/cjs/core/schema/mode/interfaces/InterfaceSchema.js.map +1 -0
- package/dist/cjs/core/schema/mode/interfaces/conditional/evaluator/ConditionalEvaluator.js +520 -0
- package/dist/cjs/core/schema/mode/interfaces/conditional/evaluator/ConditionalEvaluator.js.map +1 -0
- package/dist/cjs/core/schema/mode/interfaces/conditional/parser/ConditionalAST.js +624 -0
- package/dist/cjs/core/schema/mode/interfaces/conditional/parser/ConditionalAST.js.map +1 -0
- package/dist/cjs/core/schema/mode/interfaces/conditional/parser/ConditionalLexer.js +811 -0
- package/dist/cjs/core/schema/mode/interfaces/conditional/parser/ConditionalLexer.js.map +1 -0
- package/dist/cjs/core/schema/mode/interfaces/conditional/parser/ConditionalParser.js +599 -0
- package/dist/cjs/core/schema/mode/interfaces/conditional/parser/ConditionalParser.js.map +1 -0
- package/dist/cjs/core/schema/mode/interfaces/conditional/types/ConditionalTypes.js +89 -0
- package/dist/cjs/core/schema/mode/interfaces/conditional/types/ConditionalTypes.js.map +1 -0
- package/dist/cjs/core/schema/mode/interfaces/errors/ErrorHandler.js +356 -0
- package/dist/cjs/core/schema/mode/interfaces/errors/ErrorHandler.js.map +1 -0
- package/dist/cjs/core/schema/mode/interfaces/errors/types/errors.type.js +80 -0
- package/dist/cjs/core/schema/mode/interfaces/errors/types/errors.type.js.map +1 -0
- package/dist/cjs/core/schema/mode/interfaces/precompilation/FieldPrecompilers.js +778 -0
- package/dist/cjs/core/schema/mode/interfaces/precompilation/FieldPrecompilers.js.map +1 -0
- package/dist/cjs/core/schema/mode/interfaces/precompilation/SchemaPrecompiler.js +523 -0
- package/dist/cjs/core/schema/mode/interfaces/precompilation/SchemaPrecompiler.js.map +1 -0
- package/dist/cjs/core/schema/mode/interfaces/typescript/ConditionalTypes.js +681 -0
- package/dist/cjs/core/schema/mode/interfaces/typescript/ConditionalTypes.js.map +1 -0
- package/dist/cjs/core/schema/mode/interfaces/typescript/IDESupport.js +430 -0
- package/dist/cjs/core/schema/mode/interfaces/typescript/IDESupport.js.map +1 -0
- package/dist/cjs/core/schema/mode/interfaces/typescript/TypeInference.js +225 -0
- package/dist/cjs/core/schema/mode/interfaces/typescript/TypeInference.js.map +1 -0
- package/dist/cjs/core/schema/mode/interfaces/typescript/index.js +44 -0
- package/dist/cjs/core/schema/mode/interfaces/typescript/index.js.map +1 -0
- package/dist/cjs/core/schema/mode/interfaces/validators/ConstraintParser.js +1134 -0
- package/dist/cjs/core/schema/mode/interfaces/validators/ConstraintParser.js.map +1 -0
- package/dist/cjs/core/schema/mode/interfaces/validators/TypeGuards.js +256 -0
- package/dist/cjs/core/schema/mode/interfaces/validators/TypeGuards.js.map +1 -0
- package/dist/cjs/core/schema/mode/interfaces/validators/TypeValidators.js +429 -0
- package/dist/cjs/core/schema/mode/interfaces/validators/TypeValidators.js.map +1 -0
- package/dist/cjs/core/schema/mode/interfaces/validators/UnionCache.js +404 -0
- package/dist/cjs/core/schema/mode/interfaces/validators/UnionCache.js.map +1 -0
- package/dist/cjs/core/schema/mode/interfaces/validators/ValidationHelpers.js +851 -0
- package/dist/cjs/core/schema/mode/interfaces/validators/ValidationHelpers.js.map +1 -0
- package/dist/cjs/core/schema/mode/interfaces/validators/mods/passValidator.js +262 -0
- package/dist/cjs/core/schema/mode/interfaces/validators/mods/passValidator.js.map +1 -0
- package/dist/cjs/core/schema/mode/interfaces/validators/mods/securityValidator.js +887 -0
- package/dist/cjs/core/schema/mode/interfaces/validators/mods/securityValidator.js.map +1 -0
- package/dist/cjs/core/schema/mode/interfaces/validators/mods/urlValidation.js +191 -0
- package/dist/cjs/core/schema/mode/interfaces/validators/mods/urlValidation.js.map +1 -0
- package/dist/cjs/core/schema/optimization/ObjectValidationCache.js +462 -0
- package/dist/cjs/core/schema/optimization/ObjectValidationCache.js.map +1 -0
- package/dist/cjs/core/schema/optimization/PerformanceMonitor.js +773 -0
- package/dist/cjs/core/schema/optimization/PerformanceMonitor.js.map +1 -0
- package/dist/cjs/core/schema/optimization/SchemaCompiler.js +600 -0
- package/dist/cjs/core/schema/optimization/SchemaCompiler.js.map +1 -0
- package/dist/cjs/core/types/ValidatorTypes.js +70 -0
- package/dist/cjs/core/types/ValidatorTypes.js.map +1 -0
- package/dist/cjs/core/types/parser.type.js +12 -0
- package/dist/cjs/core/types/parser.type.js.map +1 -0
- package/dist/cjs/core/utils/Make.js +61 -0
- package/dist/cjs/core/utils/Make.js.map +1 -0
- package/dist/cjs/core/utils/Mod.js +1033 -0
- package/dist/cjs/core/utils/Mod.js.map +1 -0
- package/dist/cjs/core/utils/UrlArgs.js +102 -0
- package/dist/cjs/core/utils/UrlArgs.js.map +1 -0
- package/dist/cjs/core/utils/arrayToEnum.js +18 -0
- package/dist/cjs/core/utils/arrayToEnum.js.map +1 -0
- package/dist/cjs/core/utils/createUrlArgsEnumFArray.js +13 -0
- package/dist/cjs/core/utils/createUrlArgsEnumFArray.js.map +1 -0
- package/dist/cjs/core/utils/securityHelpers.js +215 -0
- package/dist/cjs/core/utils/securityHelpers.js.map +1 -0
- package/dist/cjs/core/utils/securityValidatorHelpers.js +65 -0
- package/dist/cjs/core/utils/securityValidatorHelpers.js.map +1 -0
- package/dist/cjs/index.js +31 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/esm/constants/SECURITY_CONSTANTS.js +47 -0
- package/dist/esm/constants/SECURITY_CONSTANTS.js.map +1 -0
- package/dist/esm/constants/VALIDATION_CONSTANTS.js +98 -0
- package/dist/esm/constants/VALIDATION_CONSTANTS.js.map +1 -0
- package/dist/esm/core/schema/extensions/SmartInference.js +197 -0
- package/dist/esm/core/schema/extensions/SmartInference.js.map +1 -0
- package/dist/esm/core/schema/extensions/components/AutoDocumentation/Docs.js +98 -0
- package/dist/esm/core/schema/extensions/components/AutoDocumentation/Docs.js.map +1 -0
- package/dist/esm/core/schema/extensions/components/AutoDocumentation/DocumentationGenerator.js +190 -0
- package/dist/esm/core/schema/extensions/components/AutoDocumentation/DocumentationGenerator.js.map +1 -0
- package/dist/esm/core/schema/extensions/components/AutoDocumentation/InteractiveDocumentationGenerator.js +172 -0
- package/dist/esm/core/schema/extensions/components/AutoDocumentation/InteractiveDocumentationGenerator.js.map +1 -0
- package/dist/esm/core/schema/extensions/components/AutoDocumentation/SchemaAnalyzer.js +52 -0
- package/dist/esm/core/schema/extensions/components/AutoDocumentation/SchemaAnalyzer.js.map +1 -0
- package/dist/esm/core/schema/extensions/components/AutoDocumentation/TypeScriptGenerator.js +48 -0
- package/dist/esm/core/schema/extensions/components/AutoDocumentation/TypeScriptGenerator.js.map +1 -0
- package/dist/esm/core/schema/extensions/components/AutoDocumentation/index.js +12 -0
- package/dist/esm/core/schema/extensions/components/AutoDocumentation/index.js.map +1 -0
- package/dist/esm/core/schema/extensions/components/ConditionalValidation/ConditionalBuilder.js +68 -0
- package/dist/esm/core/schema/extensions/components/ConditionalValidation/ConditionalBuilder.js.map +1 -0
- package/dist/esm/core/schema/extensions/components/ConditionalValidation/ConditionalElse.js +38 -0
- package/dist/esm/core/schema/extensions/components/ConditionalValidation/ConditionalElse.js.map +1 -0
- package/dist/esm/core/schema/extensions/components/ConditionalValidation/ConditionalThen.js +17 -0
- package/dist/esm/core/schema/extensions/components/ConditionalValidation/ConditionalThen.js.map +1 -0
- package/dist/esm/core/schema/extensions/components/ConditionalValidation/MultiConditionalBuilder.js +18 -0
- package/dist/esm/core/schema/extensions/components/ConditionalValidation/MultiConditionalBuilder.js.map +1 -0
- package/dist/esm/core/schema/extensions/components/ConditionalValidation/MultiConditionalThen.js +45 -0
- package/dist/esm/core/schema/extensions/components/ConditionalValidation/MultiConditionalThen.js.map +1 -0
- package/dist/esm/core/schema/extensions/components/ConditionalValidation/index.js +92 -0
- package/dist/esm/core/schema/extensions/components/ConditionalValidation/index.js.map +1 -0
- package/dist/esm/core/schema/extensions/components/RealtimeValidation/FormValidator.js +83 -0
- package/dist/esm/core/schema/extensions/components/RealtimeValidation/FormValidator.js.map +1 -0
- package/dist/esm/core/schema/extensions/components/RealtimeValidation/LiveValidator.js +131 -0
- package/dist/esm/core/schema/extensions/components/RealtimeValidation/LiveValidator.js.map +1 -0
- package/dist/esm/core/schema/extensions/components/RealtimeValidation/StreamValidator.js +349 -0
- package/dist/esm/core/schema/extensions/components/RealtimeValidation/StreamValidator.js.map +1 -0
- package/dist/esm/core/schema/extensions/components/RealtimeValidation/index.js +103 -0
- package/dist/esm/core/schema/extensions/components/RealtimeValidation/index.js.map +1 -0
- package/dist/esm/core/schema/extensions/index.js +53 -0
- package/dist/esm/core/schema/extensions/index.js.map +1 -0
- package/dist/esm/core/schema/extensions/mods/index.js +47 -0
- package/dist/esm/core/schema/extensions/mods/index.js.map +1 -0
- package/dist/esm/core/schema/extensions/mods/openapi-converter.js +225 -0
- package/dist/esm/core/schema/extensions/mods/openapi-converter.js.map +1 -0
- package/dist/esm/core/schema/extensions/mods/typescript-generator.js +284 -0
- package/dist/esm/core/schema/extensions/mods/typescript-generator.js.map +1 -0
- package/dist/esm/core/schema/extensions/mods/validation-engine.js +222 -0
- package/dist/esm/core/schema/extensions/mods/validation-engine.js.map +1 -0
- package/dist/esm/core/schema/mode/interfaces/Interface.js +269 -0
- package/dist/esm/core/schema/mode/interfaces/Interface.js.map +1 -0
- package/dist/esm/core/schema/mode/interfaces/InterfaceSchema.js +1429 -0
- package/dist/esm/core/schema/mode/interfaces/InterfaceSchema.js.map +1 -0
- package/dist/esm/core/schema/mode/interfaces/conditional/evaluator/ConditionalEvaluator.js +518 -0
- package/dist/esm/core/schema/mode/interfaces/conditional/evaluator/ConditionalEvaluator.js.map +1 -0
- package/dist/esm/core/schema/mode/interfaces/conditional/parser/ConditionalAST.js +620 -0
- package/dist/esm/core/schema/mode/interfaces/conditional/parser/ConditionalAST.js.map +1 -0
- package/dist/esm/core/schema/mode/interfaces/conditional/parser/ConditionalLexer.js +809 -0
- package/dist/esm/core/schema/mode/interfaces/conditional/parser/ConditionalLexer.js.map +1 -0
- package/dist/esm/core/schema/mode/interfaces/conditional/parser/ConditionalParser.js +597 -0
- package/dist/esm/core/schema/mode/interfaces/conditional/parser/ConditionalParser.js.map +1 -0
- package/dist/esm/core/schema/mode/interfaces/conditional/types/ConditionalTypes.js +89 -0
- package/dist/esm/core/schema/mode/interfaces/conditional/types/ConditionalTypes.js.map +1 -0
- package/dist/esm/core/schema/mode/interfaces/errors/ErrorHandler.js +354 -0
- package/dist/esm/core/schema/mode/interfaces/errors/ErrorHandler.js.map +1 -0
- package/dist/esm/core/schema/mode/interfaces/errors/types/errors.type.js +80 -0
- package/dist/esm/core/schema/mode/interfaces/errors/types/errors.type.js.map +1 -0
- package/dist/esm/core/schema/mode/interfaces/precompilation/FieldPrecompilers.js +776 -0
- package/dist/esm/core/schema/mode/interfaces/precompilation/FieldPrecompilers.js.map +1 -0
- package/dist/esm/core/schema/mode/interfaces/precompilation/SchemaPrecompiler.js +521 -0
- package/dist/esm/core/schema/mode/interfaces/precompilation/SchemaPrecompiler.js.map +1 -0
- package/dist/esm/core/schema/mode/interfaces/typescript/ConditionalTypes.js +681 -0
- package/dist/esm/core/schema/mode/interfaces/typescript/ConditionalTypes.js.map +1 -0
- package/dist/esm/core/schema/mode/interfaces/typescript/IDESupport.js +428 -0
- package/dist/esm/core/schema/mode/interfaces/typescript/IDESupport.js.map +1 -0
- package/dist/esm/core/schema/mode/interfaces/typescript/TypeInference.js +223 -0
- package/dist/esm/core/schema/mode/interfaces/typescript/TypeInference.js.map +1 -0
- package/dist/esm/core/schema/mode/interfaces/typescript/index.js +35 -0
- package/dist/esm/core/schema/mode/interfaces/typescript/index.js.map +1 -0
- package/dist/esm/core/schema/mode/interfaces/validators/ConstraintParser.js +1132 -0
- package/dist/esm/core/schema/mode/interfaces/validators/ConstraintParser.js.map +1 -0
- package/dist/esm/core/schema/mode/interfaces/validators/TypeGuards.js +254 -0
- package/dist/esm/core/schema/mode/interfaces/validators/TypeGuards.js.map +1 -0
- package/dist/esm/core/schema/mode/interfaces/validators/TypeValidators.js +427 -0
- package/dist/esm/core/schema/mode/interfaces/validators/TypeValidators.js.map +1 -0
- package/dist/esm/core/schema/mode/interfaces/validators/UnionCache.js +400 -0
- package/dist/esm/core/schema/mode/interfaces/validators/UnionCache.js.map +1 -0
- package/dist/esm/core/schema/mode/interfaces/validators/ValidationHelpers.js +849 -0
- package/dist/esm/core/schema/mode/interfaces/validators/ValidationHelpers.js.map +1 -0
- package/dist/esm/core/schema/mode/interfaces/validators/mods/passValidator.js +260 -0
- package/dist/esm/core/schema/mode/interfaces/validators/mods/passValidator.js.map +1 -0
- package/dist/esm/core/schema/mode/interfaces/validators/mods/securityValidator.js +881 -0
- package/dist/esm/core/schema/mode/interfaces/validators/mods/securityValidator.js.map +1 -0
- package/dist/esm/core/schema/mode/interfaces/validators/mods/urlValidation.js +189 -0
- package/dist/esm/core/schema/mode/interfaces/validators/mods/urlValidation.js.map +1 -0
- package/dist/esm/core/schema/optimization/ObjectValidationCache.js +460 -0
- package/dist/esm/core/schema/optimization/ObjectValidationCache.js.map +1 -0
- package/dist/esm/core/schema/optimization/PerformanceMonitor.js +771 -0
- package/dist/esm/core/schema/optimization/PerformanceMonitor.js.map +1 -0
- package/dist/esm/core/schema/optimization/SchemaCompiler.js +598 -0
- package/dist/esm/core/schema/optimization/SchemaCompiler.js.map +1 -0
- package/dist/esm/core/types/ValidatorTypes.js +65 -0
- package/dist/esm/core/types/ValidatorTypes.js.map +1 -0
- package/dist/esm/core/types/parser.type.js +12 -0
- package/dist/esm/core/types/parser.type.js.map +1 -0
- package/dist/esm/core/utils/Make.js +59 -0
- package/dist/esm/core/utils/Make.js.map +1 -0
- package/dist/esm/core/utils/Mod.js +1031 -0
- package/dist/esm/core/utils/Mod.js.map +1 -0
- package/dist/esm/core/utils/UrlArgs.js +98 -0
- package/dist/esm/core/utils/UrlArgs.js.map +1 -0
- package/dist/esm/core/utils/arrayToEnum.js +16 -0
- package/dist/esm/core/utils/arrayToEnum.js.map +1 -0
- package/dist/esm/core/utils/createUrlArgsEnumFArray.js +11 -0
- package/dist/esm/core/utils/createUrlArgsEnumFArray.js.map +1 -0
- package/dist/esm/core/utils/securityHelpers.js +207 -0
- package/dist/esm/core/utils/securityHelpers.js.map +1 -0
- package/dist/esm/core/utils/securityValidatorHelpers.js +62 -0
- package/dist/esm/core/utils/securityValidatorHelpers.js.map +1 -0
- package/dist/esm/index.js +12 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/schema.d.ts +2595 -0
- package/docs/ALL_TYPES.md +120 -0
- package/docs/API-STABILITY.md +336 -0
- package/docs/CONDITIONAL-VALIDATION.md +637 -0
- package/docs/EXAMPLES.md +876 -0
- package/docs/FIELD-TYPES.md +829 -0
- package/docs/GETTING-STARTED.md +394 -0
- package/docs/LIVE-UTILITY.md +1137 -0
- package/docs/QUICK-REFERENCE.md +346 -0
- package/docs/README.md +205 -0
- package/docs/VSCODE-EXTENSION.md +458 -0
- package/package.json +219 -0
- package/src/bench/BENCHMARK-RESULTS.md +211 -0
- package/src/bench/benchmark-results.json +148 -0
- package/src/bench/performance-comparison.ts +218 -0
- package/src/bench/precompilation-benchmark.ts +218 -0
- package/src/constants/SECURITY_CONSTANTS.ts +44 -0
- package/src/constants/VALIDATION_CONSTANTS.ts +176 -0
- package/src/core/README.md +395 -0
- package/src/core/compiler/SchemaTransformer.ts +279 -0
- package/src/core/compiler/TypeAnalyzer.ts +378 -0
- package/src/core/compiler/TypeScriptCompilerIntegration.ts +220 -0
- package/src/core/compiler/TypeToSchemaConverter.ts +288 -0
- package/src/core/index.ts +70 -0
- package/src/core/schema/extensions/AutoDocumentation.ts +572 -0
- package/src/core/schema/extensions/ConditionalValidation.ts +330 -0
- package/src/core/schema/extensions/README.md +171 -0
- package/src/core/schema/extensions/RealtimeValidation.ts +656 -0
- package/src/core/schema/extensions/SmartInference.ts +224 -0
- package/src/core/schema/extensions/components/AutoDocumentation/Docs.ts +98 -0
- package/src/core/schema/extensions/components/AutoDocumentation/DocumentationGenerator.ts +201 -0
- package/src/core/schema/extensions/components/AutoDocumentation/InteractiveDocumentationGenerator.ts +176 -0
- package/src/core/schema/extensions/components/AutoDocumentation/OpenAPIGenerator.ts +175 -0
- package/src/core/schema/extensions/components/AutoDocumentation/SchemaAnalyzer.ts +49 -0
- package/src/core/schema/extensions/components/AutoDocumentation/TypeScriptGenerator.ts +54 -0
- package/src/core/schema/extensions/components/AutoDocumentation/index.ts +17 -0
- package/src/core/schema/extensions/components/ConditionalValidation/ConditionalBuilder.ts +101 -0
- package/src/core/schema/extensions/components/ConditionalValidation/ConditionalElse.ts +65 -0
- package/src/core/schema/extensions/components/ConditionalValidation/ConditionalThen.ts +33 -0
- package/src/core/schema/extensions/components/ConditionalValidation/Extend.ts +75 -0
- package/src/core/schema/extensions/components/ConditionalValidation/MultiConditionalBuilder.ts +16 -0
- package/src/core/schema/extensions/components/ConditionalValidation/MultiConditionalThen.ts +50 -0
- package/src/core/schema/extensions/components/ConditionalValidation/index.ts +104 -0
- package/src/core/schema/extensions/components/RealtimeValidation/FormValidator.ts +88 -0
- package/src/core/schema/extensions/components/RealtimeValidation/LiveValidator.ts +171 -0
- package/src/core/schema/extensions/components/RealtimeValidation/StreamValidator.ts +397 -0
- package/src/core/schema/extensions/components/RealtimeValidation/index.ts +114 -0
- package/src/core/schema/extensions/index.ts +76 -0
- package/src/core/schema/extensions/mods/index.ts +131 -0
- package/src/core/schema/extensions/mods/openapi-converter.ts +338 -0
- package/src/core/schema/extensions/mods/typescript-generator.ts +379 -0
- package/src/core/schema/extensions/mods/validation-engine.ts +295 -0
- package/src/core/schema/mode/interfaces/Interface.ts +364 -0
- package/src/core/schema/mode/interfaces/InterfaceSchema.ts +1838 -0
- package/src/core/schema/mode/interfaces/README.md +278 -0
- package/src/core/schema/mode/interfaces/conditional/evaluator/ConditionalEvaluator.ts +657 -0
- package/src/core/schema/mode/interfaces/conditional/parser/ConditionalAST.ts +826 -0
- package/src/core/schema/mode/interfaces/conditional/parser/ConditionalLexer.ts +992 -0
- package/src/core/schema/mode/interfaces/conditional/parser/ConditionalParser.ts +803 -0
- package/src/core/schema/mode/interfaces/conditional/parser/readme.md +406 -0
- package/src/core/schema/mode/interfaces/conditional/types/ConditionalTypes.ts +273 -0
- package/src/core/schema/mode/interfaces/errors/ErrorHandler.ts +624 -0
- package/src/core/schema/mode/interfaces/errors/types/errors.type.ts +102 -0
- package/src/core/schema/mode/interfaces/precompilation/FieldPrecompilers.ts +962 -0
- package/src/core/schema/mode/interfaces/precompilation/SchemaPrecompiler.ts +667 -0
- package/src/core/schema/mode/interfaces/typescript/ConditionalTypes.ts +1534 -0
- package/src/core/schema/mode/interfaces/typescript/IDESupport.ts +534 -0
- package/src/core/schema/mode/interfaces/typescript/TypeInference.ts +737 -0
- package/src/core/schema/mode/interfaces/typescript/index.ts +92 -0
- package/src/core/schema/mode/interfaces/validators/ConstraintParser.ts +1438 -0
- package/src/core/schema/mode/interfaces/validators/EnhancedErrorReporting.ts +227 -0
- package/src/core/schema/mode/interfaces/validators/TypeGuards.ts +288 -0
- package/src/core/schema/mode/interfaces/validators/TypeValidators.ts +660 -0
- package/src/core/schema/mode/interfaces/validators/UnionCache.ts +508 -0
- package/src/core/schema/mode/interfaces/validators/ValidationHelpers.ts +1257 -0
- package/src/core/schema/mode/interfaces/validators/index.ts +21 -0
- package/src/core/schema/mode/interfaces/validators/mods/passValidator.ts +424 -0
- package/src/core/schema/mode/interfaces/validators/mods/securityValidator.ts +1634 -0
- package/src/core/schema/mode/interfaces/validators/mods/urlValidation.ts +333 -0
- package/src/core/schema/optimization/ObjectValidationCache.ts +560 -0
- package/src/core/schema/optimization/PerformanceInitializer.ts +188 -0
- package/src/core/schema/optimization/PerformanceMonitor.ts +898 -0
- package/src/core/schema/optimization/SchemaCompiler.ts +730 -0
- package/src/core/testing/TestDataGenerator.ts +590 -0
- package/src/core/types/SchemaValidator.type.ts +210 -0
- package/src/core/types/ValidatorTypes.ts +93 -0
- package/src/core/types/extension.type.ts +109 -0
- package/src/core/types/objValidationCache.ts +17 -0
- package/src/core/types/parser.type.ts +15 -0
- package/src/core/types/perfoMonitor.ts +37 -0
- package/src/core/types/scompiler.ts +22 -0
- package/src/core/types/securityValidator.type.ts +10 -0
- package/src/core/types/types.ts +154 -0
- package/src/core/utils/Make.ts +97 -0
- package/src/core/utils/Mod.ts +1168 -0
- package/src/core/utils/UrlArgs.ts +124 -0
- package/src/core/utils/arrayToEnum.ts +89 -0
- package/src/core/utils/createUrlArgsEnumFArray.ts +11 -0
- package/src/core/utils/securityHelpers.ts +341 -0
- package/src/core/utils/securityValidatorHelpers.ts +76 -0
- package/src/index.ts +124 -0
|
@@ -0,0 +1,624 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralized Error Handler Module
|
|
3
|
+
*
|
|
4
|
+
* Provides a unified system for creating, formatting, and managing validation errors.
|
|
5
|
+
* This makes error handling consistent across the codebase and easier to modify in the future.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { ValidationError } from "../../../../types/types";
|
|
9
|
+
import { ErrorCode, ErrorConfig } from "./types/errors.type";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Centralized error handler class with enhanced functionality
|
|
13
|
+
*/
|
|
14
|
+
export class ErrorHandler {
|
|
15
|
+
private static readonly DEFAULT_CONFIG: ErrorConfig = {
|
|
16
|
+
includeReceivedValue: true,
|
|
17
|
+
maxPathDepth: 10,
|
|
18
|
+
maxMessageLength: 500,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
private static readonly TYPE_MAPPING = new Map([
|
|
22
|
+
["object", "Object"],
|
|
23
|
+
["array", "Array"],
|
|
24
|
+
["string", "String"],
|
|
25
|
+
["number", "Number"],
|
|
26
|
+
["boolean", "Boolean"],
|
|
27
|
+
["function", "Function"],
|
|
28
|
+
["symbol", "Symbol"],
|
|
29
|
+
["bigint", "BigInt"],
|
|
30
|
+
["null", "null"],
|
|
31
|
+
["undefined", "undefined"],
|
|
32
|
+
]);
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Normalize and validate path input
|
|
36
|
+
*/
|
|
37
|
+
private static normalizePath(path: string | string[]): string[] {
|
|
38
|
+
if (typeof path === "string") {
|
|
39
|
+
return path
|
|
40
|
+
.split(".")
|
|
41
|
+
.filter((segment) => segment.length > 0)
|
|
42
|
+
.slice(0, this.DEFAULT_CONFIG.maxPathDepth);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (Array.isArray(path)) {
|
|
46
|
+
return path
|
|
47
|
+
.filter((segment) => typeof segment === "string" && segment.length > 0)
|
|
48
|
+
.slice(0, this.DEFAULT_CONFIG.maxPathDepth);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return [];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Sanitize and truncate message content
|
|
56
|
+
*/
|
|
57
|
+
private static sanitizeMessage(message: string): string {
|
|
58
|
+
if (typeof message !== "string") {
|
|
59
|
+
message = String(message);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Remove potentially harmful characters and excessive whitespace
|
|
63
|
+
const sanitized = message
|
|
64
|
+
.replace(/[\x00-\x1F\x7F]/g, "") // Remove control characters
|
|
65
|
+
.replace(/\s+/g, " ") // Normalize whitespace
|
|
66
|
+
.trim();
|
|
67
|
+
|
|
68
|
+
// Truncate if too long
|
|
69
|
+
return sanitized.length > this.DEFAULT_CONFIG.maxMessageLength
|
|
70
|
+
? sanitized.substring(0, this.DEFAULT_CONFIG.maxMessageLength - 3) + "..."
|
|
71
|
+
: sanitized;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Enhanced value type detection with better precision
|
|
76
|
+
*/
|
|
77
|
+
private static detectValueType(value: unknown): string {
|
|
78
|
+
// Handle primitive null/undefined first
|
|
79
|
+
if (value === null) return "null";
|
|
80
|
+
if (value === undefined) return "undefined";
|
|
81
|
+
|
|
82
|
+
// Handle built-in objects with instanceof checks
|
|
83
|
+
const builtInChecks = [
|
|
84
|
+
[Array, "array"],
|
|
85
|
+
[Date, "date"],
|
|
86
|
+
[RegExp, "regexp"],
|
|
87
|
+
[Error, "error"],
|
|
88
|
+
[Map, "map"],
|
|
89
|
+
[Set, "set"],
|
|
90
|
+
[WeakMap, "weakmap"],
|
|
91
|
+
[WeakSet, "weakset"],
|
|
92
|
+
[Promise, "promise"],
|
|
93
|
+
] as const;
|
|
94
|
+
|
|
95
|
+
for (const [constructor, typeName] of builtInChecks) {
|
|
96
|
+
if (value instanceof constructor) {
|
|
97
|
+
return typeName;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Handle primitives and functions
|
|
102
|
+
const primitiveType = typeof value;
|
|
103
|
+
return this.TYPE_MAPPING.get(primitiveType) || primitiveType;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Create a validation error object with standardized format
|
|
108
|
+
*/
|
|
109
|
+
static createError(
|
|
110
|
+
path: string | string[],
|
|
111
|
+
message: string,
|
|
112
|
+
code: ErrorCode | string,
|
|
113
|
+
expected: string,
|
|
114
|
+
received: any,
|
|
115
|
+
context?: {
|
|
116
|
+
suggestion?: string;
|
|
117
|
+
allowedValues?: any[];
|
|
118
|
+
constraints?: Record<string, any>;
|
|
119
|
+
}
|
|
120
|
+
): ValidationError {
|
|
121
|
+
const normalizedPath = this.normalizePath(path);
|
|
122
|
+
const sanitizedMessage = this.sanitizeMessage(message);
|
|
123
|
+
const detectedType = this.detectValueType(received);
|
|
124
|
+
|
|
125
|
+
return {
|
|
126
|
+
path: normalizedPath,
|
|
127
|
+
message: sanitizedMessage,
|
|
128
|
+
code: code,
|
|
129
|
+
expected: typeof expected === "string" ? expected.trim() : "unknown",
|
|
130
|
+
received,
|
|
131
|
+
receivedType: detectedType,
|
|
132
|
+
context: context ? { ...context } : undefined, // Shallow clone for safety
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Create a type error (when value is of wrong type)
|
|
138
|
+
*/
|
|
139
|
+
static createTypeError(
|
|
140
|
+
path: string | string[],
|
|
141
|
+
expected: string,
|
|
142
|
+
received: unknown
|
|
143
|
+
): ValidationError {
|
|
144
|
+
const receivedType = this.detectValueType(received);
|
|
145
|
+
const sanitizedValue = this.sanitizeReceivedValue(received);
|
|
146
|
+
|
|
147
|
+
// Create a user-friendly message that includes the actual value
|
|
148
|
+
const message =
|
|
149
|
+
expected === "phone"
|
|
150
|
+
? `Invalid phone number format: received "${sanitizedValue}" instead of valid phone number`
|
|
151
|
+
: `Expected ${this.capitalizeFirstLetter(expected)}, but received ${this.capitalizeFirstLetter(receivedType)}: "${sanitizedValue}"`;
|
|
152
|
+
|
|
153
|
+
return this.createError(
|
|
154
|
+
path,
|
|
155
|
+
message,
|
|
156
|
+
ErrorCode.TYPE_ERROR,
|
|
157
|
+
expected,
|
|
158
|
+
received
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Create a string validation error
|
|
164
|
+
*/
|
|
165
|
+
static createStringError(
|
|
166
|
+
path: string | string[],
|
|
167
|
+
constraint: string,
|
|
168
|
+
received: any,
|
|
169
|
+
code: ErrorCode = ErrorCode.INVALID_STRING_FORMAT
|
|
170
|
+
): ValidationError {
|
|
171
|
+
const sanitizedConstraint =
|
|
172
|
+
typeof constraint === "string" ? constraint.trim() : "validation failed";
|
|
173
|
+
|
|
174
|
+
return this.createError(
|
|
175
|
+
path,
|
|
176
|
+
`String ${sanitizedConstraint}`,
|
|
177
|
+
code,
|
|
178
|
+
`string ${sanitizedConstraint}`,
|
|
179
|
+
received
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Create a number validation error
|
|
185
|
+
*/
|
|
186
|
+
static createNumberError(
|
|
187
|
+
path: string | string[],
|
|
188
|
+
constraint: string,
|
|
189
|
+
received: any,
|
|
190
|
+
code: ErrorCode = ErrorCode.INVALID_TYPE
|
|
191
|
+
): ValidationError {
|
|
192
|
+
const sanitizedConstraint =
|
|
193
|
+
typeof constraint === "string" ? constraint.trim() : "validation failed";
|
|
194
|
+
|
|
195
|
+
return this.createError(
|
|
196
|
+
path,
|
|
197
|
+
`Number ${sanitizedConstraint}`,
|
|
198
|
+
code,
|
|
199
|
+
`number ${sanitizedConstraint}`,
|
|
200
|
+
received
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Create an array validation error
|
|
206
|
+
*/
|
|
207
|
+
static createArrayError(
|
|
208
|
+
path: string | string[],
|
|
209
|
+
constraint: string,
|
|
210
|
+
received: any,
|
|
211
|
+
code: ErrorCode = ErrorCode.INVALID_TYPE
|
|
212
|
+
): ValidationError {
|
|
213
|
+
const sanitizedConstraint =
|
|
214
|
+
typeof constraint === "string" ? constraint.trim() : "validation failed";
|
|
215
|
+
|
|
216
|
+
return this.createError(
|
|
217
|
+
path,
|
|
218
|
+
`Array ${sanitizedConstraint}`,
|
|
219
|
+
code,
|
|
220
|
+
`array ${sanitizedConstraint}`,
|
|
221
|
+
received
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Create a URL validation error
|
|
227
|
+
*/
|
|
228
|
+
static createUrlError(
|
|
229
|
+
path: string | string[],
|
|
230
|
+
received: any,
|
|
231
|
+
urlType?: string
|
|
232
|
+
): ValidationError {
|
|
233
|
+
const sanitizedUrlType = urlType?.trim();
|
|
234
|
+
const expected = sanitizedUrlType ? `url.${sanitizedUrlType}` : "url";
|
|
235
|
+
const message = sanitizedUrlType
|
|
236
|
+
? `Invalid URL format for ${sanitizedUrlType}`
|
|
237
|
+
: "Invalid URL format";
|
|
238
|
+
|
|
239
|
+
return this.createError(
|
|
240
|
+
path,
|
|
241
|
+
message,
|
|
242
|
+
ErrorCode.INVALID_URL,
|
|
243
|
+
expected,
|
|
244
|
+
received
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Create an email validation error
|
|
250
|
+
*/
|
|
251
|
+
static createEmailError(
|
|
252
|
+
path: string | string[],
|
|
253
|
+
received: any,
|
|
254
|
+
details?: string
|
|
255
|
+
): ValidationError {
|
|
256
|
+
const sanitizedDetails = details?.trim();
|
|
257
|
+
const message = sanitizedDetails
|
|
258
|
+
? `Invalid email format: ${sanitizedDetails}`
|
|
259
|
+
: "Invalid email format";
|
|
260
|
+
|
|
261
|
+
return this.createError(
|
|
262
|
+
path,
|
|
263
|
+
message,
|
|
264
|
+
ErrorCode.INVALID_EMAIL,
|
|
265
|
+
"email",
|
|
266
|
+
received
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Create a union validation error
|
|
272
|
+
*/
|
|
273
|
+
static createUnionError(
|
|
274
|
+
path: string | string[],
|
|
275
|
+
allowedValues: any[],
|
|
276
|
+
received: any
|
|
277
|
+
): ValidationError {
|
|
278
|
+
const safeAllowedValues = Array.isArray(allowedValues) ? allowedValues : [];
|
|
279
|
+
const expected = safeAllowedValues
|
|
280
|
+
.map((val) => (typeof val === "string" ? val : String(val)))
|
|
281
|
+
.join(" | ");
|
|
282
|
+
|
|
283
|
+
return this.createError(
|
|
284
|
+
path,
|
|
285
|
+
`Expected one of: ${expected}`,
|
|
286
|
+
ErrorCode.INVALID_UNION,
|
|
287
|
+
expected,
|
|
288
|
+
received,
|
|
289
|
+
{ allowedValues: safeAllowedValues }
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Get detailed type information for values (legacy method name for compatibility)
|
|
295
|
+
*/
|
|
296
|
+
static getValueType(value: unknown): string {
|
|
297
|
+
return this.detectValueType(value);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Convert string errors to ValidationError objects
|
|
302
|
+
* (for backward compatibility)
|
|
303
|
+
*/
|
|
304
|
+
static convertStringToError(
|
|
305
|
+
error: string | any,
|
|
306
|
+
code: ErrorCode
|
|
307
|
+
): ValidationError {
|
|
308
|
+
// If it's already a ValidationError object, return as is
|
|
309
|
+
if (this.isValidationError(error)) {
|
|
310
|
+
return error;
|
|
311
|
+
}
|
|
312
|
+
// console.log("converting string to error. Code: ", code);
|
|
313
|
+
// Handle ValidationError-like objects
|
|
314
|
+
if (
|
|
315
|
+
error &&
|
|
316
|
+
typeof error === "object" &&
|
|
317
|
+
typeof error.message === "string"
|
|
318
|
+
) {
|
|
319
|
+
return this.createError(
|
|
320
|
+
error.path || [],
|
|
321
|
+
error.message,
|
|
322
|
+
code || ErrorCode.VALIDATION_ERROR,
|
|
323
|
+
error.expected || "unknown",
|
|
324
|
+
error.received
|
|
325
|
+
);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// Convert to string safely
|
|
329
|
+
const errorString = this.extractErrorMessage(error);
|
|
330
|
+
|
|
331
|
+
// Extract path if it exists (format: "path: message")
|
|
332
|
+
const pathMatch = errorString.match(/^([^:]+):\s*(.+)$/);
|
|
333
|
+
|
|
334
|
+
if (pathMatch) {
|
|
335
|
+
const [, path, message] = pathMatch;
|
|
336
|
+
return this.createError(
|
|
337
|
+
path.trim(),
|
|
338
|
+
message.trim(),
|
|
339
|
+
code,
|
|
340
|
+
"unknown",
|
|
341
|
+
undefined
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// No path found, use generic error
|
|
346
|
+
return this.createError([], errorString, code, "unknown", undefined);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Check if an object is a valid ValidationError
|
|
351
|
+
*/
|
|
352
|
+
private static isValidationError(obj: any): obj is ValidationError {
|
|
353
|
+
return (
|
|
354
|
+
obj &&
|
|
355
|
+
typeof obj === "object" &&
|
|
356
|
+
Array.isArray(obj.path) &&
|
|
357
|
+
typeof obj.message === "string" &&
|
|
358
|
+
typeof obj.code === "string"
|
|
359
|
+
);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Safely extract error message from various error types
|
|
364
|
+
*/
|
|
365
|
+
private static extractErrorMessage(error: any): string {
|
|
366
|
+
if (typeof error === "string") {
|
|
367
|
+
return error;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
if (error && typeof error === "object") {
|
|
371
|
+
if (error.message) {
|
|
372
|
+
return String(error.message);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
if (error.toString && error.toString !== Object.prototype.toString) {
|
|
376
|
+
return error.toString();
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
try {
|
|
380
|
+
return JSON.stringify(error);
|
|
381
|
+
} catch {
|
|
382
|
+
return "[Object]";
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
return String(error);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Convert string array to ValidationError array
|
|
391
|
+
* (for backward compatibility)
|
|
392
|
+
*/
|
|
393
|
+
static convertStringArrayToErrors(
|
|
394
|
+
errors: string[],
|
|
395
|
+
code: string
|
|
396
|
+
): ValidationError[] {
|
|
397
|
+
if (!Array.isArray(errors)) {
|
|
398
|
+
return [];
|
|
399
|
+
}
|
|
400
|
+
return errors.map((error) => this.convertStringToError(error, code as any));
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Create a simple validation error with minimal information
|
|
405
|
+
*/
|
|
406
|
+
static createSimpleError(
|
|
407
|
+
message: string,
|
|
408
|
+
path: string | string[] = [],
|
|
409
|
+
code: ErrorCode | string = ErrorCode.VALIDATION_ERROR
|
|
410
|
+
): ValidationError {
|
|
411
|
+
return this.createError(path, message, code, "valid value", undefined);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* Create an error for missing required fields
|
|
416
|
+
*/
|
|
417
|
+
static createMissingFieldError(
|
|
418
|
+
path: string | string[],
|
|
419
|
+
fieldName: string
|
|
420
|
+
): ValidationError {
|
|
421
|
+
const sanitizedFieldName =
|
|
422
|
+
typeof fieldName === "string" ? fieldName.trim() : "unknown";
|
|
423
|
+
|
|
424
|
+
return this.createError(
|
|
425
|
+
path,
|
|
426
|
+
`Missing required field: ${sanitizedFieldName}`,
|
|
427
|
+
ErrorCode.MISSING_REQUIRED_FIELD,
|
|
428
|
+
`required field: ${sanitizedFieldName}`,
|
|
429
|
+
undefined
|
|
430
|
+
);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* create constant error
|
|
435
|
+
*/
|
|
436
|
+
static createConstantError(
|
|
437
|
+
path: string | string[],
|
|
438
|
+
expected: string | number | boolean,
|
|
439
|
+
received: any,
|
|
440
|
+
constantValue: any
|
|
441
|
+
): ValidationError {
|
|
442
|
+
const safeConstantValue =
|
|
443
|
+
constantValue !== null && constantValue !== undefined
|
|
444
|
+
? String(constantValue)
|
|
445
|
+
: "null";
|
|
446
|
+
|
|
447
|
+
return this.createError(
|
|
448
|
+
path,
|
|
449
|
+
`Expected constant value: ${safeConstantValue}, received ${String(received)}`,
|
|
450
|
+
ErrorCode.CONSTANT_ERROR,
|
|
451
|
+
`constant: ${safeConstantValue}`,
|
|
452
|
+
received
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Create an error for unknown fields
|
|
458
|
+
*/
|
|
459
|
+
static createUnknownFieldError(
|
|
460
|
+
path: string | string[],
|
|
461
|
+
fieldName: string
|
|
462
|
+
): ValidationError {
|
|
463
|
+
const sanitizedFieldName =
|
|
464
|
+
typeof fieldName === "string" ? fieldName.trim() : "unknown";
|
|
465
|
+
|
|
466
|
+
return this.createError(
|
|
467
|
+
path,
|
|
468
|
+
`Unknown field: ${sanitizedFieldName}`,
|
|
469
|
+
ErrorCode.UNKNOWN_FIELD,
|
|
470
|
+
"known field",
|
|
471
|
+
fieldName
|
|
472
|
+
);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* Create an error for invalid fields
|
|
477
|
+
*/
|
|
478
|
+
static createInvalidFieldError(
|
|
479
|
+
path: string | string[],
|
|
480
|
+
fieldName: string,
|
|
481
|
+
expected: string,
|
|
482
|
+
received: any
|
|
483
|
+
): ValidationError {
|
|
484
|
+
const sanitizedFieldName =
|
|
485
|
+
typeof fieldName === "string" ? fieldName.trim() : "unknown";
|
|
486
|
+
|
|
487
|
+
return this.createError(
|
|
488
|
+
path,
|
|
489
|
+
`Invalid field: ${sanitizedFieldName}`,
|
|
490
|
+
ErrorCode.INVALID_FIELD,
|
|
491
|
+
expected,
|
|
492
|
+
received
|
|
493
|
+
);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* conditional error
|
|
498
|
+
*/
|
|
499
|
+
static createConditionalError(
|
|
500
|
+
path: string | string[],
|
|
501
|
+
message: string,
|
|
502
|
+
received: any
|
|
503
|
+
): ValidationError {
|
|
504
|
+
return this.createError(
|
|
505
|
+
path,
|
|
506
|
+
message,
|
|
507
|
+
ErrorCode.CONDITION_ERROR,
|
|
508
|
+
"condition met",
|
|
509
|
+
received
|
|
510
|
+
);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* Create a syntax error
|
|
515
|
+
*/
|
|
516
|
+
static createSyntaxError(
|
|
517
|
+
path: string | string[],
|
|
518
|
+
message: string,
|
|
519
|
+
received: any
|
|
520
|
+
): ValidationError {
|
|
521
|
+
return this.createError(
|
|
522
|
+
path,
|
|
523
|
+
message,
|
|
524
|
+
ErrorCode.SYNTAX_ERROR,
|
|
525
|
+
"valid syntax",
|
|
526
|
+
received
|
|
527
|
+
);
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* password error
|
|
532
|
+
*/
|
|
533
|
+
static createPasswordError(
|
|
534
|
+
path: string | string[],
|
|
535
|
+
message: string,
|
|
536
|
+
received: any
|
|
537
|
+
): ValidationError {
|
|
538
|
+
return this.createError(
|
|
539
|
+
path,
|
|
540
|
+
message,
|
|
541
|
+
ErrorCode.INVALID_PASSWORD,
|
|
542
|
+
"strong password",
|
|
543
|
+
received
|
|
544
|
+
);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* createDateError
|
|
549
|
+
*/
|
|
550
|
+
static createDateError(
|
|
551
|
+
path: string | string[],
|
|
552
|
+
received: any
|
|
553
|
+
): ValidationError {
|
|
554
|
+
return this.createError(
|
|
555
|
+
path,
|
|
556
|
+
"Invalid date format",
|
|
557
|
+
ErrorCode.INVALID_DATE,
|
|
558
|
+
"valid date format",
|
|
559
|
+
received
|
|
560
|
+
);
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
/**
|
|
564
|
+
* Validation error
|
|
565
|
+
*/
|
|
566
|
+
static createValidationError(
|
|
567
|
+
path: string | string[],
|
|
568
|
+
message: string,
|
|
569
|
+
received: any
|
|
570
|
+
): ValidationError {
|
|
571
|
+
// console.log("createValidationError", message);
|
|
572
|
+
return this.createError(
|
|
573
|
+
path,
|
|
574
|
+
`Validation failed: ${message}`,
|
|
575
|
+
ErrorCode.VALIDATION_ERROR,
|
|
576
|
+
"valid value",
|
|
577
|
+
received
|
|
578
|
+
);
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
/**
|
|
582
|
+
* Url components validation error
|
|
583
|
+
*/
|
|
584
|
+
static createUrlCValidationErr(
|
|
585
|
+
path: string | string[],
|
|
586
|
+
message: string,
|
|
587
|
+
received: any
|
|
588
|
+
): ValidationError {
|
|
589
|
+
return this.createError(
|
|
590
|
+
path,
|
|
591
|
+
message,
|
|
592
|
+
ErrorCode.INVALID_URL_ARGS,
|
|
593
|
+
"valid url components",
|
|
594
|
+
received
|
|
595
|
+
);
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
/**
|
|
599
|
+
* Safely capitalize first letter of a string
|
|
600
|
+
*/
|
|
601
|
+
private static capitalizeFirstLetter(str: string): string {
|
|
602
|
+
if (typeof str !== "string" || str.length === 0) {
|
|
603
|
+
return str;
|
|
604
|
+
}
|
|
605
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
/**
|
|
609
|
+
* Sanitize received value for safe display in error messages
|
|
610
|
+
*/
|
|
611
|
+
private static sanitizeReceivedValue(value: any): string {
|
|
612
|
+
if (value === null) return "null";
|
|
613
|
+
if (value === undefined) return "undefined";
|
|
614
|
+
if (typeof value === "string") {
|
|
615
|
+
return value.length > 50
|
|
616
|
+
? `"${value.substring(0, 47)}..."`
|
|
617
|
+
: `"${value}"`;
|
|
618
|
+
}
|
|
619
|
+
if (typeof value === "object") {
|
|
620
|
+
return `[${this.detectValueType(value)}]`;
|
|
621
|
+
}
|
|
622
|
+
return String(value);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error codes for different validation scenarios
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Error codes for different validation scenarios
|
|
6
|
+
*/
|
|
7
|
+
export enum ErrorCode {
|
|
8
|
+
// Type validation errors
|
|
9
|
+
TYPE_ERROR = "ETYPE",
|
|
10
|
+
TYPE_MISMATCH = "ETYPEMISMATCH",
|
|
11
|
+
INVALID_TYPE = "EINVALIDTYPE",
|
|
12
|
+
|
|
13
|
+
// String validation errors
|
|
14
|
+
STRING_TOO_SHORT = "ESTRINGSHORT",
|
|
15
|
+
STRING_TOO_LONG = "ESTRINGLONG",
|
|
16
|
+
INVALID_STRING_FORMAT = "ESTRINGFORMAT",
|
|
17
|
+
PATTERN_MISMATCH = "EPATTERNMISMATCH",
|
|
18
|
+
|
|
19
|
+
// Number validation errors
|
|
20
|
+
NUMBER_TOO_SMALL = "ENUMSMALL",
|
|
21
|
+
NUMBER_TOO_LARGE = "ENUMLARGE",
|
|
22
|
+
NOT_INTEGER = "ENOTINTEGER",
|
|
23
|
+
NOT_POSITIVE = "ENOTPOSITIVE",
|
|
24
|
+
NOT_NEGATIVE = "ENOTNEGATIVE",
|
|
25
|
+
|
|
26
|
+
// Array validation errors
|
|
27
|
+
ARRAY_TOO_SHORT = "EARRAYSHORT",
|
|
28
|
+
ARRAY_TOO_LONG = "EARRAYLONG",
|
|
29
|
+
INVALID_ARRAY_ITEM = "EARRAYITEM",
|
|
30
|
+
INVALID_ARRAY_LENGTH = "EARRAYLENGTH",
|
|
31
|
+
DUPLICATE_ARRAY_ITEM = "EARRDUPLICATE",
|
|
32
|
+
ARRAY_VALUES_NOT_UNIQUE = "EARRAYNOTUNIQUE",
|
|
33
|
+
|
|
34
|
+
// Object validation errors
|
|
35
|
+
MISSING_REQUIRED_FIELD = "EMISSINGFIELD",
|
|
36
|
+
INVALID_FIELD = "EINVALIDFIELD",
|
|
37
|
+
UNKNOWN_FIELD = "EUNKNOWNFIELD",
|
|
38
|
+
|
|
39
|
+
// Conditional validation errors
|
|
40
|
+
CONDITION_ERROR = "ECONDITION",
|
|
41
|
+
SYNTAX_ERROR = "ESYNTAX",
|
|
42
|
+
|
|
43
|
+
// URL validation errors
|
|
44
|
+
INVALID_URL = "EINVALIDURL",
|
|
45
|
+
INVALID_URL_ARGUMENT = "EINVALIDURLARG",
|
|
46
|
+
|
|
47
|
+
// Email validation errors
|
|
48
|
+
INVALID_EMAIL = "EINVALIDEMAIL",
|
|
49
|
+
|
|
50
|
+
// Date validation errors
|
|
51
|
+
INVALID_DATE = "EINVALIDDATE",
|
|
52
|
+
DATE_TOO_EARLY = "EDATEEARLY",
|
|
53
|
+
DATE_TOO_LATE = "EDATELATE",
|
|
54
|
+
|
|
55
|
+
// Union validation errors
|
|
56
|
+
INVALID_UNION = "EINVALIDUNION",
|
|
57
|
+
|
|
58
|
+
// Constant validation errors
|
|
59
|
+
CONSTANT_ERROR = "ECONSTANT",
|
|
60
|
+
|
|
61
|
+
// Password validation errors
|
|
62
|
+
INVALID_PASSWORD = "EPWDVIOLATION",
|
|
63
|
+
|
|
64
|
+
// JSON validation errors
|
|
65
|
+
INVALID_JSON = "EINVALIDJSON",
|
|
66
|
+
|
|
67
|
+
// Security errors
|
|
68
|
+
SECURITY_VIOLATION = "ESECVIOLATION",
|
|
69
|
+
|
|
70
|
+
// URL components validation errors
|
|
71
|
+
INVALID_URL_ARGS = "EINVALIDURLARGS",
|
|
72
|
+
|
|
73
|
+
// Network and connection errors
|
|
74
|
+
CONNECTION_REFUSED = "ECONNREFUSED",
|
|
75
|
+
CONNECTION_TIMEOUT = "ECONNECTIONTIMEOUT",
|
|
76
|
+
CONNECTION_RESET = "ECONNRESET",
|
|
77
|
+
NETWORK_UNREACHABLE = "ENETUNREACH",
|
|
78
|
+
HOST_UNREACHABLE = "EHOSTUNREACH",
|
|
79
|
+
ADDRESS_NOT_AVAILABLE = "EADDRNOTAVAIL",
|
|
80
|
+
|
|
81
|
+
// HTTP errors
|
|
82
|
+
HTTP_ERROR = "EHTTPERROR",
|
|
83
|
+
REQUEST_TIMEOUT = "EREQUESTTIMEOUT",
|
|
84
|
+
BAD_REQUEST = "EBADREQUEST",
|
|
85
|
+
UNAUTHORIZED = "EUNAUTHORIZED",
|
|
86
|
+
FORBIDDEN = "EFORBIDDEN",
|
|
87
|
+
NOT_FOUND = "ENOTFOUND",
|
|
88
|
+
INTERNAL_SERVER_ERROR = "ESERVERERROR",
|
|
89
|
+
|
|
90
|
+
// Generic errors
|
|
91
|
+
VALIDATION_ERROR = "EVALIDATION",
|
|
92
|
+
UNKNOWN_ERROR = "EUNKNOWN",
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Configuration for error message templates and formatting
|
|
97
|
+
*/
|
|
98
|
+
export interface ErrorConfig {
|
|
99
|
+
includeReceivedValue: boolean;
|
|
100
|
+
maxPathDepth: number;
|
|
101
|
+
maxMessageLength: number;
|
|
102
|
+
}
|