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,778 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('../validators/TypeValidators.js');
|
|
4
|
+
var ConstraintParser = require('../validators/ConstraintParser.js');
|
|
5
|
+
var ValidationHelpers = require('../validators/ValidationHelpers.js');
|
|
6
|
+
var ErrorHandler = require('../errors/ErrorHandler.js');
|
|
7
|
+
var errors_type = require('../errors/types/errors.type.js');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Field-Specific Precompilers
|
|
11
|
+
*
|
|
12
|
+
* Each field type gets its own specialized precompiler for maximum performance
|
|
13
|
+
*/
|
|
14
|
+
class FieldPrecompilers {
|
|
15
|
+
/**
|
|
16
|
+
* Precompile union field validators
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
static precompileUnion(unionType) {
|
|
20
|
+
// Use the fixed union validation from ValidationHelpers
|
|
21
|
+
const validator = (value) => {
|
|
22
|
+
return ValidationHelpers.ValidationHelpers.validateUnionType(unionType, value);
|
|
23
|
+
};
|
|
24
|
+
validator._fieldType = unionType;
|
|
25
|
+
validator._isCompiled = true;
|
|
26
|
+
return validator;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Precompile string field validators
|
|
30
|
+
*/
|
|
31
|
+
static precompileString(constraints = {}) {
|
|
32
|
+
const { minLength, maxLength, pattern } = constraints;
|
|
33
|
+
// Pre-compile validation logic based on constraints
|
|
34
|
+
if (!minLength && !maxLength && !pattern) {
|
|
35
|
+
// Simple string validation
|
|
36
|
+
const validator = (value) => {
|
|
37
|
+
if (typeof value === "string") {
|
|
38
|
+
return {
|
|
39
|
+
success: true,
|
|
40
|
+
errors: [],
|
|
41
|
+
warnings: [],
|
|
42
|
+
data: value,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
success: false,
|
|
47
|
+
errors: [ErrorHandler.ErrorHandler.createTypeError([], "string", value)],
|
|
48
|
+
warnings: [],
|
|
49
|
+
data: undefined,
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
validator._fieldType = "string";
|
|
53
|
+
validator._isCompiled = true;
|
|
54
|
+
return validator;
|
|
55
|
+
}
|
|
56
|
+
// OPTIMIZED: String with constraints
|
|
57
|
+
const validator = (value) => {
|
|
58
|
+
if (typeof value !== "string") {
|
|
59
|
+
return {
|
|
60
|
+
success: false,
|
|
61
|
+
errors: [ErrorHandler.ErrorHandler.createTypeError([], "string", value)],
|
|
62
|
+
warnings: [],
|
|
63
|
+
data: undefined,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
const errors = [];
|
|
67
|
+
if (minLength !== undefined && value.length < minLength) {
|
|
68
|
+
errors.push({
|
|
69
|
+
code: "STRING_TOO_SHORT",
|
|
70
|
+
message: `String must be at least ${minLength} characters`,
|
|
71
|
+
path: [],
|
|
72
|
+
expected: `string(minLength: ${minLength})`,
|
|
73
|
+
received: value,
|
|
74
|
+
receivedType: "string",
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
if (maxLength !== undefined && value.length > maxLength) {
|
|
78
|
+
errors.push({
|
|
79
|
+
code: "STRING_TOO_LONG",
|
|
80
|
+
message: `String must be at most ${maxLength} characters`,
|
|
81
|
+
path: [],
|
|
82
|
+
expected: `string(maxLength: ${maxLength})`,
|
|
83
|
+
received: value,
|
|
84
|
+
receivedType: "string",
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
if (pattern && !pattern.test(value)) {
|
|
88
|
+
errors.push({
|
|
89
|
+
code: "STRING_PATTERN_MISMATCH",
|
|
90
|
+
message: `String does not match required pattern`,
|
|
91
|
+
path: [],
|
|
92
|
+
expected: `string(pattern: ${pattern})`,
|
|
93
|
+
received: value,
|
|
94
|
+
receivedType: "string",
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
if (errors.length > 0) {
|
|
98
|
+
return {
|
|
99
|
+
success: false,
|
|
100
|
+
errors,
|
|
101
|
+
warnings: [],
|
|
102
|
+
data: undefined,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
success: true,
|
|
107
|
+
errors: [],
|
|
108
|
+
warnings: [],
|
|
109
|
+
data: value,
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
validator._fieldType =
|
|
113
|
+
`string(${minLength || ""},${maxLength || ""})`;
|
|
114
|
+
validator._isCompiled = true;
|
|
115
|
+
return validator;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Precompile float field validators (for float and double types)
|
|
119
|
+
*/
|
|
120
|
+
static precompileFloat(constraints = {}) {
|
|
121
|
+
const { min, max } = constraints;
|
|
122
|
+
const validator = (value) => {
|
|
123
|
+
// DEBUG: Add logging to see what's happening
|
|
124
|
+
// console.log("🔍 precompileFloat validator executing:");
|
|
125
|
+
// console.log(" - value:", value, "type:", typeof value);
|
|
126
|
+
// console.log(" - constraints: min =", min, ", max =", max);
|
|
127
|
+
if (typeof value !== "number" || isNaN(value) || !isFinite(value)) {
|
|
128
|
+
// console.log(" - FAIL: not a valid number");
|
|
129
|
+
return {
|
|
130
|
+
success: false,
|
|
131
|
+
errors: [ErrorHandler.ErrorHandler.createTypeError([], "float", value)],
|
|
132
|
+
warnings: [],
|
|
133
|
+
data: undefined,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
const errors = [];
|
|
137
|
+
if (min !== undefined && value < min) {
|
|
138
|
+
// console.log(" - FAIL: value", value, "< min", min);
|
|
139
|
+
errors.push({
|
|
140
|
+
code: errors_type.ErrorCode.NUMBER_TOO_SMALL,
|
|
141
|
+
message: `Float must be at least ${min}`,
|
|
142
|
+
path: [],
|
|
143
|
+
expected: `float(min: ${min})`,
|
|
144
|
+
received: value,
|
|
145
|
+
receivedType: "number",
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
if (max !== undefined && value > max) {
|
|
149
|
+
// console.log(" - FAIL: value", value, "> max", max);
|
|
150
|
+
errors.push({
|
|
151
|
+
code: errors_type.ErrorCode.NUMBER_TOO_LARGE,
|
|
152
|
+
message: `Float must be at most ${max}`,
|
|
153
|
+
path: [],
|
|
154
|
+
expected: `float(max: ${max})`,
|
|
155
|
+
received: value,
|
|
156
|
+
receivedType: "number",
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
if (errors.length > 0) {
|
|
160
|
+
// console.log(" - FINAL RESULT: FAIL with errors:", errors);
|
|
161
|
+
return {
|
|
162
|
+
success: false,
|
|
163
|
+
errors,
|
|
164
|
+
warnings: [],
|
|
165
|
+
data: undefined,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
// console.log(" - FINAL RESULT: PASS");
|
|
169
|
+
return {
|
|
170
|
+
success: true,
|
|
171
|
+
errors: [],
|
|
172
|
+
warnings: [],
|
|
173
|
+
data: value,
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
validator._fieldType = `float(${min || ""},${max || ""})`;
|
|
177
|
+
validator._isCompiled = true;
|
|
178
|
+
return validator;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Precompile positive number field validators
|
|
182
|
+
*/
|
|
183
|
+
static precompilePositiveNumber(constraints = {}) {
|
|
184
|
+
const { min, max } = constraints;
|
|
185
|
+
const validator = (value) => {
|
|
186
|
+
if (typeof value !== "number" || isNaN(value) || !isFinite(value)) {
|
|
187
|
+
return {
|
|
188
|
+
success: false,
|
|
189
|
+
errors: [ErrorHandler.ErrorHandler.createTypeError([], "positive number", value)],
|
|
190
|
+
warnings: [],
|
|
191
|
+
data: undefined,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
const errors = [];
|
|
195
|
+
// CRITICAL: Positive validation - must be > 0
|
|
196
|
+
if (value <= 0) {
|
|
197
|
+
errors.push({
|
|
198
|
+
code: "NUMBER_NOT_POSITIVE",
|
|
199
|
+
message: "Number must be positive",
|
|
200
|
+
path: [],
|
|
201
|
+
expected: "positive",
|
|
202
|
+
received: value,
|
|
203
|
+
receivedType: "number",
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
if (min !== undefined && value < min) {
|
|
207
|
+
errors.push({
|
|
208
|
+
code: errors_type.ErrorCode.NUMBER_TOO_SMALL,
|
|
209
|
+
message: `Number must be at least ${min}`,
|
|
210
|
+
path: [],
|
|
211
|
+
expected: `positive(min: ${min})`,
|
|
212
|
+
received: value,
|
|
213
|
+
receivedType: "number",
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
if (max !== undefined && value > max) {
|
|
217
|
+
errors.push({
|
|
218
|
+
code: errors_type.ErrorCode.NUMBER_TOO_LARGE,
|
|
219
|
+
message: `Number must be at most ${max}`,
|
|
220
|
+
path: [],
|
|
221
|
+
expected: `positive(max: ${max})`,
|
|
222
|
+
received: value,
|
|
223
|
+
receivedType: "number",
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
if (errors.length > 0) {
|
|
227
|
+
return {
|
|
228
|
+
success: false,
|
|
229
|
+
errors,
|
|
230
|
+
warnings: [],
|
|
231
|
+
data: undefined,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
return {
|
|
235
|
+
success: true,
|
|
236
|
+
errors: [],
|
|
237
|
+
warnings: [],
|
|
238
|
+
data: value,
|
|
239
|
+
};
|
|
240
|
+
};
|
|
241
|
+
validator._fieldType = `positive(${min || ""},${max || ""})`;
|
|
242
|
+
validator._isCompiled = true;
|
|
243
|
+
return validator;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Precompile negative number field validators
|
|
247
|
+
*/
|
|
248
|
+
static precompileNegativeNumber(constraints = {}) {
|
|
249
|
+
const { min, max } = constraints;
|
|
250
|
+
const validator = (value) => {
|
|
251
|
+
if (typeof value !== "number" || isNaN(value) || !isFinite(value)) {
|
|
252
|
+
return {
|
|
253
|
+
success: false,
|
|
254
|
+
errors: [ErrorHandler.ErrorHandler.createTypeError([], "negative number", value)],
|
|
255
|
+
warnings: [],
|
|
256
|
+
data: undefined,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
const errors = [];
|
|
260
|
+
// CRITICAL: Negative validation - must be < 0
|
|
261
|
+
if (value >= 0) {
|
|
262
|
+
errors.push({
|
|
263
|
+
code: errors_type.ErrorCode.NOT_NEGATIVE,
|
|
264
|
+
message: "Number must be negative",
|
|
265
|
+
path: [],
|
|
266
|
+
expected: "negative",
|
|
267
|
+
received: value,
|
|
268
|
+
receivedType: "number",
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
if (min !== undefined && value < min) {
|
|
272
|
+
errors.push({
|
|
273
|
+
code: errors_type.ErrorCode.NUMBER_TOO_SMALL,
|
|
274
|
+
message: `Number must be at least ${min}`,
|
|
275
|
+
path: [],
|
|
276
|
+
expected: `negative(min: ${min})`,
|
|
277
|
+
received: value,
|
|
278
|
+
receivedType: "number",
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
if (max !== undefined && value > max) {
|
|
282
|
+
errors.push({
|
|
283
|
+
code: errors_type.ErrorCode.NUMBER_TOO_LARGE,
|
|
284
|
+
message: `Number must be at most ${max}`,
|
|
285
|
+
path: [],
|
|
286
|
+
expected: `negative(max: ${max})`,
|
|
287
|
+
received: value,
|
|
288
|
+
receivedType: "number",
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
if (errors.length > 0) {
|
|
292
|
+
return {
|
|
293
|
+
success: false,
|
|
294
|
+
errors,
|
|
295
|
+
warnings: [],
|
|
296
|
+
data: undefined,
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
return {
|
|
300
|
+
success: true,
|
|
301
|
+
errors: [],
|
|
302
|
+
warnings: [],
|
|
303
|
+
data: value,
|
|
304
|
+
};
|
|
305
|
+
};
|
|
306
|
+
validator._fieldType = `negative(${min || ""},${max || ""})`;
|
|
307
|
+
validator._isCompiled = true;
|
|
308
|
+
return validator;
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Precompile number field validators
|
|
312
|
+
*/
|
|
313
|
+
static precompileNumber(constraints = {}) {
|
|
314
|
+
const { min, max, integer, strictlyPositive, strictlyNegative } = constraints;
|
|
315
|
+
const validator = (value) => {
|
|
316
|
+
// DEBUG: Add logging to see if validator is being called
|
|
317
|
+
// // console.log("🔍 precompileNumber validator executing:");
|
|
318
|
+
// // console.log(" - value:", value, "type:", typeof value);
|
|
319
|
+
// // console.log(
|
|
320
|
+
// " - constraints: strictlyPositive =",
|
|
321
|
+
// strictlyPositive,
|
|
322
|
+
// ", strictlyNegative =",
|
|
323
|
+
// strictlyNegative
|
|
324
|
+
// );
|
|
325
|
+
if (typeof value !== "number" || isNaN(value)) {
|
|
326
|
+
// // console.log(" - FAIL: not a number");
|
|
327
|
+
return {
|
|
328
|
+
success: false,
|
|
329
|
+
errors: [ErrorHandler.ErrorHandler.createTypeError([], "number", value)],
|
|
330
|
+
warnings: [],
|
|
331
|
+
data: undefined,
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
const errors = [];
|
|
335
|
+
if (integer && !Number.isInteger(value)) {
|
|
336
|
+
// // console.log(" - FAIL: not an integer");
|
|
337
|
+
errors.push({
|
|
338
|
+
code: errors_type.ErrorCode.NOT_INTEGER,
|
|
339
|
+
message: "Number must be an integer",
|
|
340
|
+
path: [],
|
|
341
|
+
expected: "integer",
|
|
342
|
+
received: value,
|
|
343
|
+
receivedType: "number",
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
// CRITICAL FIX: Handle strict positive/negative validation
|
|
347
|
+
if (strictlyPositive && value <= 0) {
|
|
348
|
+
// console.log(" - FAIL: not strictly positive (value <= 0)");
|
|
349
|
+
errors.push({
|
|
350
|
+
code: errors_type.ErrorCode.NOT_POSITIVE,
|
|
351
|
+
message: "Number must be positive",
|
|
352
|
+
path: [],
|
|
353
|
+
expected: "positive",
|
|
354
|
+
received: value,
|
|
355
|
+
receivedType: "number",
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
if (strictlyNegative && value >= 0) {
|
|
359
|
+
// console.log(" - FAIL: not strictly negative (value >= 0)");
|
|
360
|
+
errors.push({
|
|
361
|
+
code: errors_type.ErrorCode.NOT_NEGATIVE,
|
|
362
|
+
message: "Number must be negative",
|
|
363
|
+
path: [],
|
|
364
|
+
expected: "negative",
|
|
365
|
+
received: value,
|
|
366
|
+
receivedType: "number",
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
if (min !== undefined && value < min) {
|
|
370
|
+
// console.log(" - FAIL: value < min");
|
|
371
|
+
errors.push({
|
|
372
|
+
code: errors_type.ErrorCode.NUMBER_TOO_SMALL,
|
|
373
|
+
message: `Number must be at least ${min}`,
|
|
374
|
+
path: [],
|
|
375
|
+
expected: `number(min: ${min})`,
|
|
376
|
+
received: value,
|
|
377
|
+
receivedType: "number",
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
if (max !== undefined && value > max) {
|
|
381
|
+
// console.log(" - FAIL: value > max");
|
|
382
|
+
errors.push({
|
|
383
|
+
code: errors_type.ErrorCode.NUMBER_TOO_LARGE,
|
|
384
|
+
message: `Number must be at most ${max}`,
|
|
385
|
+
path: [],
|
|
386
|
+
expected: `number(max: ${max})`,
|
|
387
|
+
received: value,
|
|
388
|
+
receivedType: "number",
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
if (errors.length > 0) {
|
|
392
|
+
// console.log(" - FINAL RESULT: FAIL with errors:", errors);
|
|
393
|
+
return {
|
|
394
|
+
success: false,
|
|
395
|
+
errors,
|
|
396
|
+
warnings: [],
|
|
397
|
+
data: undefined,
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
// console.log(" - FINAL RESULT: PASS");
|
|
401
|
+
return {
|
|
402
|
+
success: true,
|
|
403
|
+
errors: [],
|
|
404
|
+
warnings: [],
|
|
405
|
+
data: value,
|
|
406
|
+
};
|
|
407
|
+
};
|
|
408
|
+
validator._fieldType = `number(${min || ""},${max || ""})`;
|
|
409
|
+
validator._isCompiled = true;
|
|
410
|
+
return validator;
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Precompile boolean field validators
|
|
414
|
+
*/
|
|
415
|
+
static precompileBoolean() {
|
|
416
|
+
const validator = (value) => {
|
|
417
|
+
if (typeof value === "boolean") {
|
|
418
|
+
return {
|
|
419
|
+
success: true,
|
|
420
|
+
errors: [],
|
|
421
|
+
warnings: [],
|
|
422
|
+
data: value,
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
return {
|
|
426
|
+
success: false,
|
|
427
|
+
errors: [ErrorHandler.ErrorHandler.createTypeError([], "boolean", value)],
|
|
428
|
+
warnings: [],
|
|
429
|
+
data: undefined,
|
|
430
|
+
};
|
|
431
|
+
};
|
|
432
|
+
validator._fieldType = "boolean";
|
|
433
|
+
validator._isCompiled = true;
|
|
434
|
+
return validator;
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Precompile array field validators
|
|
438
|
+
*/
|
|
439
|
+
static precompileArray(elementValidator, constraints = {}) {
|
|
440
|
+
const { minLength, maxLength, unique } = constraints;
|
|
441
|
+
const validator = (value) => {
|
|
442
|
+
if (!Array.isArray(value)) {
|
|
443
|
+
return {
|
|
444
|
+
success: false,
|
|
445
|
+
errors: [ErrorHandler.ErrorHandler.createTypeError([], "array", value)],
|
|
446
|
+
warnings: [],
|
|
447
|
+
data: undefined,
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
const errors = [];
|
|
451
|
+
if (minLength !== undefined && value.length < minLength) {
|
|
452
|
+
errors.push({
|
|
453
|
+
code: errors_type.ErrorCode.ARRAY_TOO_SHORT,
|
|
454
|
+
message: `Array must have at least ${minLength} elements`,
|
|
455
|
+
path: [],
|
|
456
|
+
expected: `array(minLength: ${minLength})`,
|
|
457
|
+
received: value,
|
|
458
|
+
receivedType: "array",
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
if (maxLength !== undefined && value.length > maxLength) {
|
|
462
|
+
errors.push({
|
|
463
|
+
code: errors_type.ErrorCode.ARRAY_TOO_LONG,
|
|
464
|
+
message: `Array must have at most ${maxLength} elements`,
|
|
465
|
+
path: [],
|
|
466
|
+
expected: `array(maxLength: ${maxLength})`,
|
|
467
|
+
received: value,
|
|
468
|
+
receivedType: "array",
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
// Validate each element
|
|
472
|
+
const validatedArray = [];
|
|
473
|
+
for (let i = 0; i < value.length; i++) {
|
|
474
|
+
const elementResult = elementValidator(value[i]);
|
|
475
|
+
if (!elementResult.success) {
|
|
476
|
+
errors.push(...elementResult.errors.map((error) => ({
|
|
477
|
+
...error,
|
|
478
|
+
path: [i.toString(), ...error.path],
|
|
479
|
+
})));
|
|
480
|
+
}
|
|
481
|
+
else {
|
|
482
|
+
validatedArray.push(elementResult.data);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
// Check uniqueness if required
|
|
486
|
+
if (unique && validatedArray.length > 0) {
|
|
487
|
+
const uniqueValues = new Set(validatedArray.map((v) => JSON.stringify(v)));
|
|
488
|
+
if (uniqueValues.size !== validatedArray.length) {
|
|
489
|
+
errors.push({
|
|
490
|
+
code: errors_type.ErrorCode.ARRAY_VALUES_NOT_UNIQUE,
|
|
491
|
+
message: "Array elements must be unique",
|
|
492
|
+
path: [],
|
|
493
|
+
expected: "unique",
|
|
494
|
+
received: value,
|
|
495
|
+
receivedType: "array",
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
if (errors.length > 0) {
|
|
500
|
+
return {
|
|
501
|
+
success: false,
|
|
502
|
+
errors,
|
|
503
|
+
warnings: [],
|
|
504
|
+
data: undefined,
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
return {
|
|
508
|
+
success: true,
|
|
509
|
+
errors: [],
|
|
510
|
+
warnings: [],
|
|
511
|
+
data: validatedArray,
|
|
512
|
+
};
|
|
513
|
+
};
|
|
514
|
+
validator._fieldType = `${elementValidator._fieldType}[]`;
|
|
515
|
+
validator._isCompiled = true;
|
|
516
|
+
return validator;
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* Precompile optional field validators
|
|
520
|
+
*/
|
|
521
|
+
static precompileOptional(baseValidator, defaultValue) {
|
|
522
|
+
const validator = (value) => {
|
|
523
|
+
if (value === undefined) {
|
|
524
|
+
return {
|
|
525
|
+
success: true,
|
|
526
|
+
errors: [],
|
|
527
|
+
warnings: [],
|
|
528
|
+
data: defaultValue,
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
return baseValidator(value);
|
|
532
|
+
};
|
|
533
|
+
validator._fieldType = `${baseValidator._fieldType}?`;
|
|
534
|
+
validator._isCompiled = true;
|
|
535
|
+
return validator;
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* Precompile constant field validators
|
|
539
|
+
*/
|
|
540
|
+
static precompileConstant(constantValue) {
|
|
541
|
+
const stringValue = String(constantValue);
|
|
542
|
+
const validator = (value) => {
|
|
543
|
+
if (value === constantValue || String(value) === stringValue) {
|
|
544
|
+
return {
|
|
545
|
+
success: true,
|
|
546
|
+
errors: [],
|
|
547
|
+
warnings: [],
|
|
548
|
+
data: constantValue,
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
return {
|
|
552
|
+
success: false,
|
|
553
|
+
errors: [
|
|
554
|
+
ErrorHandler.ErrorHandler.createConstantError([], "constant", value, constantValue),
|
|
555
|
+
],
|
|
556
|
+
warnings: [],
|
|
557
|
+
data: undefined,
|
|
558
|
+
};
|
|
559
|
+
};
|
|
560
|
+
validator._fieldType = `=${constantValue}`;
|
|
561
|
+
validator._isCompiled = true;
|
|
562
|
+
return validator;
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* Precompile record field types (record<string, number>, Record<string, any>, etc.)
|
|
566
|
+
*/
|
|
567
|
+
static precompileRecord(recordType) {
|
|
568
|
+
const validator = (value) => {
|
|
569
|
+
// Use ValidationHelpers.validateRecordType for proper record validation
|
|
570
|
+
return ValidationHelpers.ValidationHelpers.validateRecordType(recordType, value, (fieldType, value) => {
|
|
571
|
+
// Recursively validate nested field types using the same precompiler system
|
|
572
|
+
const nestedValidator = FieldPrecompilers.parseAndCompile(fieldType);
|
|
573
|
+
return nestedValidator(value);
|
|
574
|
+
});
|
|
575
|
+
};
|
|
576
|
+
validator._fieldType = recordType;
|
|
577
|
+
validator._isCompiled = true;
|
|
578
|
+
return validator;
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Precompile special field types (email, url, json, etc.)
|
|
582
|
+
*/
|
|
583
|
+
static precompileSpecialType(type) {
|
|
584
|
+
const validator = (value) => {
|
|
585
|
+
// CRITICAL FIX: Parse constraints from the type string for proper validation
|
|
586
|
+
const parsed = ConstraintParser.ConstraintParser.parseConstraints(type);
|
|
587
|
+
// Use the imported ValidationHelpers with proper constraints
|
|
588
|
+
return ValidationHelpers.ValidationHelpers.routeTypeValidation(parsed.type, value, { ...parsed.constraints }, parsed.constraints);
|
|
589
|
+
};
|
|
590
|
+
validator._fieldType = type;
|
|
591
|
+
validator._isCompiled = true;
|
|
592
|
+
return validator;
|
|
593
|
+
}
|
|
594
|
+
/**
|
|
595
|
+
* Parse field type and create appropriate precompiled validator
|
|
596
|
+
*/
|
|
597
|
+
static parseAndCompile(fieldType) {
|
|
598
|
+
// Handle optional fields
|
|
599
|
+
const isOptional = fieldType.endsWith("?");
|
|
600
|
+
const baseType = isOptional ? fieldType.slice(0, -1) : fieldType;
|
|
601
|
+
// Handle constants
|
|
602
|
+
if (baseType.startsWith("=")) {
|
|
603
|
+
const constantValue = baseType.slice(1);
|
|
604
|
+
const validator = this.precompileConstant(constantValue);
|
|
605
|
+
return isOptional ? this.precompileOptional(validator) : validator;
|
|
606
|
+
}
|
|
607
|
+
// Handle unions
|
|
608
|
+
if (baseType.includes("|")) {
|
|
609
|
+
const validator = this.precompileUnion(baseType);
|
|
610
|
+
return isOptional ? this.precompileOptional(validator) : validator;
|
|
611
|
+
}
|
|
612
|
+
// Handle arrays
|
|
613
|
+
if (baseType.endsWith("[]")) {
|
|
614
|
+
const elementType = baseType.slice(0, -2);
|
|
615
|
+
const elementValidator = this.parseAndCompile(elementType);
|
|
616
|
+
const validator = this.precompileArray(elementValidator);
|
|
617
|
+
return isOptional ? this.precompileOptional(validator) : validator;
|
|
618
|
+
}
|
|
619
|
+
// Handle record types (record<string, number>, Record<string, any>, etc.)
|
|
620
|
+
if ((baseType.startsWith("record<") && baseType.endsWith(">")) ||
|
|
621
|
+
(baseType.startsWith("Record<") && baseType.endsWith(">"))) {
|
|
622
|
+
const validator = this.precompileRecord(baseType);
|
|
623
|
+
return isOptional ? this.precompileOptional(validator) : validator;
|
|
624
|
+
}
|
|
625
|
+
// Handle basic types with constraints (including URL args like url.https)
|
|
626
|
+
const constraintMatch = baseType.match(/^([\w.]+)(?:\(([^)]*)\))?$/);
|
|
627
|
+
if (constraintMatch) {
|
|
628
|
+
const [, type, constraintsStr] = constraintMatch;
|
|
629
|
+
switch (type) {
|
|
630
|
+
case "string":
|
|
631
|
+
const stringConstraints = this.parseStringConstraints(constraintsStr);
|
|
632
|
+
const stringValidator = this.precompileString(stringConstraints);
|
|
633
|
+
return isOptional
|
|
634
|
+
? this.precompileOptional(stringValidator)
|
|
635
|
+
: stringValidator;
|
|
636
|
+
case "number":
|
|
637
|
+
case "int":
|
|
638
|
+
case "integer":
|
|
639
|
+
case "float":
|
|
640
|
+
const numberConstraints = this.parseNumberConstraints(constraintsStr, type);
|
|
641
|
+
const numberValidator = this.precompileNumber(numberConstraints);
|
|
642
|
+
return isOptional
|
|
643
|
+
? this.precompileOptional(numberValidator)
|
|
644
|
+
: numberValidator;
|
|
645
|
+
case "positive":
|
|
646
|
+
// CRITICAL FIX: Handle positive numbers with proper validation
|
|
647
|
+
const positiveConstraints = this.parseNumberConstraints(constraintsStr, type);
|
|
648
|
+
const positiveValidator = this.precompilePositiveNumber(positiveConstraints);
|
|
649
|
+
return isOptional
|
|
650
|
+
? this.precompileOptional(positiveValidator)
|
|
651
|
+
: positiveValidator;
|
|
652
|
+
case "negative":
|
|
653
|
+
// CRITICAL FIX: Handle negative numbers with proper validation
|
|
654
|
+
const negativeConstraints = this.parseNumberConstraints(constraintsStr, type);
|
|
655
|
+
const negativeValidator = this.precompileNegativeNumber(negativeConstraints);
|
|
656
|
+
return isOptional
|
|
657
|
+
? this.precompileOptional(negativeValidator)
|
|
658
|
+
: negativeValidator;
|
|
659
|
+
case "double":
|
|
660
|
+
// CRITICAL FIX: Handle double with float constraints to match ValidationHelpers routing
|
|
661
|
+
const doubleConstraints = this.parseNumberConstraints(constraintsStr, type);
|
|
662
|
+
const doubleValidator = this.precompileFloat(doubleConstraints);
|
|
663
|
+
return isOptional
|
|
664
|
+
? this.precompileOptional(doubleValidator)
|
|
665
|
+
: doubleValidator;
|
|
666
|
+
case "boolean":
|
|
667
|
+
case "bool":
|
|
668
|
+
const boolValidator = this.precompileBoolean();
|
|
669
|
+
return isOptional
|
|
670
|
+
? this.precompileOptional(boolValidator)
|
|
671
|
+
: boolValidator;
|
|
672
|
+
// Handle new field types by delegating to ValidationHelpers
|
|
673
|
+
case "json":
|
|
674
|
+
case "ip":
|
|
675
|
+
case "password":
|
|
676
|
+
case "text":
|
|
677
|
+
case "object":
|
|
678
|
+
case "url":
|
|
679
|
+
case "email":
|
|
680
|
+
case "uuid":
|
|
681
|
+
case "phone":
|
|
682
|
+
case "slug":
|
|
683
|
+
case "username":
|
|
684
|
+
case "hexcolor":
|
|
685
|
+
case "base64":
|
|
686
|
+
case "jwt":
|
|
687
|
+
case "semver":
|
|
688
|
+
case "date":
|
|
689
|
+
case "any":
|
|
690
|
+
const specialValidator = this.precompileSpecialType(type);
|
|
691
|
+
return isOptional
|
|
692
|
+
? this.precompileOptional(specialValidator)
|
|
693
|
+
: specialValidator;
|
|
694
|
+
default:
|
|
695
|
+
// Check if it's a URL arg (url.https, url.http, etc.)
|
|
696
|
+
if (type.startsWith("url.")) {
|
|
697
|
+
const urlArgValidator = this.precompileSpecialType(type);
|
|
698
|
+
return isOptional
|
|
699
|
+
? this.precompileOptional(urlArgValidator)
|
|
700
|
+
: urlArgValidator;
|
|
701
|
+
}
|
|
702
|
+
// Fallback for unknown types
|
|
703
|
+
return this.createFallbackValidator(fieldType);
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
return this.createFallbackValidator(fieldType);
|
|
707
|
+
}
|
|
708
|
+
static parseStringConstraints(constraintsStr) {
|
|
709
|
+
if (!constraintsStr)
|
|
710
|
+
return {};
|
|
711
|
+
// CRITICAL FIX: Use ConstraintParser to properly handle regex patterns
|
|
712
|
+
const ConstraintParser = require("../validators/ConstraintParser").ConstraintParser;
|
|
713
|
+
try {
|
|
714
|
+
// Parse the full constraint string using the proper parser
|
|
715
|
+
const fullType = `string(${constraintsStr})`;
|
|
716
|
+
const parsed = ConstraintParser.parseConstraints(fullType);
|
|
717
|
+
// Extract the constraints we need
|
|
718
|
+
const constraints = {};
|
|
719
|
+
if (parsed.constraints.minLength !== undefined) {
|
|
720
|
+
constraints.minLength = parsed.constraints.minLength;
|
|
721
|
+
}
|
|
722
|
+
if (parsed.constraints.maxLength !== undefined) {
|
|
723
|
+
constraints.maxLength = parsed.constraints.maxLength;
|
|
724
|
+
}
|
|
725
|
+
if (parsed.constraints.pattern) {
|
|
726
|
+
constraints.pattern = parsed.constraints.pattern;
|
|
727
|
+
}
|
|
728
|
+
return constraints;
|
|
729
|
+
}
|
|
730
|
+
catch (error) {
|
|
731
|
+
// Fallback to simple parsing for backward compatibility
|
|
732
|
+
const parts = constraintsStr.split(",");
|
|
733
|
+
const constraints = {};
|
|
734
|
+
if (parts[0] && parts[0].trim()) {
|
|
735
|
+
constraints.minLength = parseInt(parts[0].trim());
|
|
736
|
+
}
|
|
737
|
+
if (parts[1] && parts[1].trim()) {
|
|
738
|
+
constraints.maxLength = parseInt(parts[1].trim());
|
|
739
|
+
}
|
|
740
|
+
return constraints;
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
static parseNumberConstraints(constraintsStr, type) {
|
|
744
|
+
const constraints = {};
|
|
745
|
+
if (type === "int" || type === "integer") {
|
|
746
|
+
constraints.integer = true;
|
|
747
|
+
}
|
|
748
|
+
// NOTE: positive and negative types are now handled by separate precompilers
|
|
749
|
+
// No need to set special constraints here
|
|
750
|
+
if (constraintsStr) {
|
|
751
|
+
const parts = constraintsStr.split(",");
|
|
752
|
+
if (parts[0] && parts[0].trim()) {
|
|
753
|
+
constraints.min = parseFloat(parts[0].trim());
|
|
754
|
+
}
|
|
755
|
+
if (parts[1] && parts[1].trim()) {
|
|
756
|
+
constraints.max = parseFloat(parts[1].trim());
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
return constraints;
|
|
760
|
+
}
|
|
761
|
+
static createFallbackValidator(fieldType) {
|
|
762
|
+
const validator = (value) => {
|
|
763
|
+
// Basic fallback validation
|
|
764
|
+
return {
|
|
765
|
+
success: true,
|
|
766
|
+
errors: [],
|
|
767
|
+
warnings: [`Fallback validation used for type: ${fieldType}`],
|
|
768
|
+
data: value,
|
|
769
|
+
};
|
|
770
|
+
};
|
|
771
|
+
validator._fieldType = fieldType;
|
|
772
|
+
validator._isCompiled = true;
|
|
773
|
+
return validator;
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
exports.FieldPrecompilers = FieldPrecompilers;
|
|
778
|
+
//# sourceMappingURL=FieldPrecompilers.js.map
|