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,667 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ULTRA-PERFORMANCE Schema Precompilation Module
|
|
3
|
+
*
|
|
4
|
+
* This module precompiles entire schemas at creation time to eliminate
|
|
5
|
+
* runtime overhead while maintaining full security and validation.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
SchemaValidationResult,
|
|
11
|
+
ValidationError,
|
|
12
|
+
} from "../../../../types/types";
|
|
13
|
+
import { SchemaOptions } from "../Interface";
|
|
14
|
+
import { FieldPrecompilers, CompiledFieldValidator } from "./FieldPrecompilers";
|
|
15
|
+
import { MAX_COMPILATION_DEPTH as IMPORTED_MAX_COMPILATION_DEPTH } from "../../../../../constants/VALIDATION_CONSTANTS";
|
|
16
|
+
import { ErrorHandler } from "../errors/ErrorHandler";
|
|
17
|
+
import { ErrorCode } from "../errors/types/errors.type";
|
|
18
|
+
import { SUPPORTED_VALIDATOR_TYPES } from "../../../../types/ValidatorTypes";
|
|
19
|
+
|
|
20
|
+
// Precompiled validator function signature
|
|
21
|
+
export interface PrecompiledValidator {
|
|
22
|
+
(data: any): SchemaValidationResult;
|
|
23
|
+
_isPrecompiled: true;
|
|
24
|
+
_schemaHash: string;
|
|
25
|
+
_optimizationLevel: OptimizationLevel;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export enum OptimizationLevel {
|
|
29
|
+
NONE = 0,
|
|
30
|
+
BASIC = 1,
|
|
31
|
+
AGGRESSIVE = 2,
|
|
32
|
+
ULTRA = 3,
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
interface FieldCompilation {
|
|
36
|
+
fieldName: string;
|
|
37
|
+
fieldType: string;
|
|
38
|
+
validator: (value: any) => SchemaValidationResult;
|
|
39
|
+
isOptional: boolean;
|
|
40
|
+
hasDefault: boolean;
|
|
41
|
+
defaultValue?: any;
|
|
42
|
+
// Performance flags
|
|
43
|
+
isSimpleType: boolean;
|
|
44
|
+
isUnion: boolean;
|
|
45
|
+
isArray: boolean;
|
|
46
|
+
isNested: boolean;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
interface SchemaCompilation {
|
|
50
|
+
fields: FieldCompilation[];
|
|
51
|
+
validator: PrecompiledValidator;
|
|
52
|
+
optimizationLevel: OptimizationLevel;
|
|
53
|
+
compilationTime: number;
|
|
54
|
+
estimatedPerformanceGain: number;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export class SchemaPrecompiler {
|
|
58
|
+
private static compilationCache = new Map<string, SchemaCompilation>();
|
|
59
|
+
private static performanceStats = {
|
|
60
|
+
compilations: 0,
|
|
61
|
+
cacheHits: 0,
|
|
62
|
+
totalCompilationTime: 0,
|
|
63
|
+
averageSpeedup: 0,
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// SAFETY: Track compilation depth to prevent infinite recursion
|
|
67
|
+
private static compilationDepth = 0;
|
|
68
|
+
private static readonly MAX_COMPILATION_DEPTH =
|
|
69
|
+
IMPORTED_MAX_COMPILATION_DEPTH;
|
|
70
|
+
|
|
71
|
+
// SAFETY: Track circular references
|
|
72
|
+
private static compilationStack = new Set<string>();
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* MAIN ENTRY POINT: Precompile entire schema for maximum performance
|
|
76
|
+
*/
|
|
77
|
+
static precompileSchema(
|
|
78
|
+
schemaDefinition: Record<string, any>,
|
|
79
|
+
options: SchemaOptions = {}
|
|
80
|
+
): PrecompiledValidator {
|
|
81
|
+
const startTime = performance.now();
|
|
82
|
+
|
|
83
|
+
// SAFETY: Check compilation depth to prevent infinite recursion
|
|
84
|
+
if (this.compilationDepth >= this.MAX_COMPILATION_DEPTH) {
|
|
85
|
+
throw new Error(
|
|
86
|
+
`Schema compilation depth exceeded (${this.MAX_COMPILATION_DEPTH}). Possible circular reference detected.`
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Generate cache key
|
|
91
|
+
const schemaHash = this.generateSchemaHash(schemaDefinition, options);
|
|
92
|
+
|
|
93
|
+
// SAFETY: Check for circular references
|
|
94
|
+
if (this.compilationStack.has(schemaHash)) {
|
|
95
|
+
throw new Error(
|
|
96
|
+
`Circular reference detected in schema compilation: ${schemaHash}`
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Check cache first
|
|
101
|
+
const cached = this.compilationCache.get(schemaHash);
|
|
102
|
+
if (cached) {
|
|
103
|
+
this.performanceStats.cacheHits++;
|
|
104
|
+
return cached.validator;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// SAFETY: Track compilation
|
|
108
|
+
this.compilationDepth++;
|
|
109
|
+
this.compilationStack.add(schemaHash);
|
|
110
|
+
|
|
111
|
+
try {
|
|
112
|
+
// Analyze schema complexity and determine optimization level
|
|
113
|
+
const optimizationLevel = this.analyzeOptimizationLevel(schemaDefinition);
|
|
114
|
+
|
|
115
|
+
// Compile fields
|
|
116
|
+
const compiledFields = this.compileFields(schemaDefinition, options);
|
|
117
|
+
|
|
118
|
+
// Generate ultra-optimized validator
|
|
119
|
+
const validator = this.generateOptimizedValidator(
|
|
120
|
+
compiledFields,
|
|
121
|
+
optimizationLevel,
|
|
122
|
+
schemaHash
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
const compilationTime = performance.now() - startTime;
|
|
126
|
+
|
|
127
|
+
// Cache the compilation
|
|
128
|
+
const compilation: SchemaCompilation = {
|
|
129
|
+
fields: compiledFields,
|
|
130
|
+
validator,
|
|
131
|
+
optimizationLevel,
|
|
132
|
+
compilationTime,
|
|
133
|
+
estimatedPerformanceGain: this.estimatePerformanceGain(compiledFields),
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
this.compilationCache.set(schemaHash, compilation);
|
|
137
|
+
this.performanceStats.compilations++;
|
|
138
|
+
this.performanceStats.totalCompilationTime += compilationTime;
|
|
139
|
+
|
|
140
|
+
return validator;
|
|
141
|
+
} catch (error) {
|
|
142
|
+
// console.error('Schema precompilation failed:', error);
|
|
143
|
+
throw error;
|
|
144
|
+
} finally {
|
|
145
|
+
this.compilationDepth--;
|
|
146
|
+
this.compilationStack.delete(schemaHash);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* ULTRA-FAST: Generate specialized validator based on schema patterns
|
|
152
|
+
*/
|
|
153
|
+
private static generateOptimizedValidator(
|
|
154
|
+
fields: FieldCompilation[],
|
|
155
|
+
optimizationLevel: OptimizationLevel,
|
|
156
|
+
schemaHash: string
|
|
157
|
+
): PrecompiledValidator {
|
|
158
|
+
// For ULTRA optimization, generate specialized code paths
|
|
159
|
+
if (optimizationLevel === OptimizationLevel.ULTRA) {
|
|
160
|
+
return this.generateUltraOptimizedValidator(fields, schemaHash);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// For AGGRESSIVE optimization, use compiled field validators
|
|
164
|
+
if (optimizationLevel === OptimizationLevel.AGGRESSIVE) {
|
|
165
|
+
return this.generateAggressiveValidator(fields, schemaHash);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// For BASIC optimization, use cached validators
|
|
169
|
+
return this.generateBasicValidator(fields, schemaHash);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* ULTRA-OPTIMIZED: Generate the fastest possible validator
|
|
174
|
+
* Uses specialized code paths for common patterns
|
|
175
|
+
*/
|
|
176
|
+
private static generateUltraOptimizedValidator(
|
|
177
|
+
fields: FieldCompilation[],
|
|
178
|
+
schemaHash: string
|
|
179
|
+
): PrecompiledValidator {
|
|
180
|
+
// Pre-allocate result objects for zero-allocation validation
|
|
181
|
+
const successResult: SchemaValidationResult = Object.freeze({
|
|
182
|
+
success: true,
|
|
183
|
+
errors: [],
|
|
184
|
+
warnings: [],
|
|
185
|
+
data: null as any, // Will be set during validation
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
// Separate fields by type for specialized handling
|
|
189
|
+
const simpleFields = fields.filter((f) => f.isSimpleType);
|
|
190
|
+
const unionFields = fields.filter((f) => f.isUnion);
|
|
191
|
+
const arrayFields = fields.filter((f) => f.isArray);
|
|
192
|
+
const nestedFields = fields.filter((f) => f.isNested);
|
|
193
|
+
|
|
194
|
+
const validator = (data: any): SchemaValidationResult => {
|
|
195
|
+
// ULTRA-FAST: Type check with early return
|
|
196
|
+
if (typeof data !== "object" || data === null) {
|
|
197
|
+
return {
|
|
198
|
+
success: false,
|
|
199
|
+
errors: [ErrorHandler.createTypeError([], "object", data)],
|
|
200
|
+
warnings: [],
|
|
201
|
+
data: undefined,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const validatedData: any = {};
|
|
206
|
+
const errors: ValidationError[] = [];
|
|
207
|
+
|
|
208
|
+
// OPTIMIZED: Process simple fields first (fastest path)
|
|
209
|
+
for (const field of simpleFields) {
|
|
210
|
+
const value = data[field.fieldName];
|
|
211
|
+
const result = field.validator(value);
|
|
212
|
+
|
|
213
|
+
if (!result.success) {
|
|
214
|
+
// Add field path to errors
|
|
215
|
+
const errorsWithPath = result.errors.map((error) => ({
|
|
216
|
+
...error,
|
|
217
|
+
path: [field.fieldName, ...error.path],
|
|
218
|
+
message: error.message.includes(" in field ")
|
|
219
|
+
? error.message
|
|
220
|
+
: `${error.message} in field "${field.fieldName}"`,
|
|
221
|
+
}));
|
|
222
|
+
errors.push(...errorsWithPath);
|
|
223
|
+
} else {
|
|
224
|
+
validatedData[field.fieldName] = result.data;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// OPTIMIZED: Process union fields with precompiled validators
|
|
229
|
+
for (const field of unionFields) {
|
|
230
|
+
const value = data[field.fieldName];
|
|
231
|
+
const result = field.validator(value);
|
|
232
|
+
|
|
233
|
+
if (!result.success) {
|
|
234
|
+
// Add field path to errors
|
|
235
|
+
const errorsWithPath = result.errors.map((error) => ({
|
|
236
|
+
...error,
|
|
237
|
+
path: [field.fieldName, ...error.path],
|
|
238
|
+
message: error.message.includes(" in field ")
|
|
239
|
+
? error.message
|
|
240
|
+
: `${error.message} in field "${field.fieldName}"`,
|
|
241
|
+
}));
|
|
242
|
+
errors.push(...errorsWithPath);
|
|
243
|
+
} else {
|
|
244
|
+
validatedData[field.fieldName] = result.data;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// OPTIMIZED: Process array fields
|
|
249
|
+
for (const field of arrayFields) {
|
|
250
|
+
const value = data[field.fieldName];
|
|
251
|
+
const result = field.validator(value);
|
|
252
|
+
|
|
253
|
+
if (!result.success) {
|
|
254
|
+
// Add field path to errors
|
|
255
|
+
const errorsWithPath = result.errors.map((error) => ({
|
|
256
|
+
...error,
|
|
257
|
+
path: [field.fieldName, ...error.path],
|
|
258
|
+
message: error.message.includes(" in field ")
|
|
259
|
+
? error.message
|
|
260
|
+
: `${error.message} in field "${field.fieldName}"`,
|
|
261
|
+
}));
|
|
262
|
+
errors.push(...errorsWithPath);
|
|
263
|
+
} else {
|
|
264
|
+
validatedData[field.fieldName] = result.data;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// OPTIMIZED: Process nested fields last
|
|
269
|
+
for (const field of nestedFields) {
|
|
270
|
+
const value = data[field.fieldName];
|
|
271
|
+
const result = field.validator(value);
|
|
272
|
+
|
|
273
|
+
if (!result.success) {
|
|
274
|
+
// Add field path to errors
|
|
275
|
+
const errorsWithPath = result.errors.map((error) => ({
|
|
276
|
+
...error,
|
|
277
|
+
path: [field.fieldName, ...error.path],
|
|
278
|
+
message: error.message.includes(" in field ")
|
|
279
|
+
? error.message
|
|
280
|
+
: `${error.message} in field "${field.fieldName}"`,
|
|
281
|
+
}));
|
|
282
|
+
errors.push(...errorsWithPath);
|
|
283
|
+
} else {
|
|
284
|
+
validatedData[field.fieldName] = result.data;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// ULTRA-FAST: Return result
|
|
289
|
+
if (errors.length === 0) {
|
|
290
|
+
return {
|
|
291
|
+
success: true,
|
|
292
|
+
errors: [],
|
|
293
|
+
warnings: [],
|
|
294
|
+
data: validatedData,
|
|
295
|
+
};
|
|
296
|
+
} else {
|
|
297
|
+
return {
|
|
298
|
+
success: false,
|
|
299
|
+
errors,
|
|
300
|
+
warnings: [],
|
|
301
|
+
data: undefined,
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
// Mark as precompiled
|
|
307
|
+
(validator as any)._isPrecompiled = true;
|
|
308
|
+
(validator as any)._schemaHash = schemaHash;
|
|
309
|
+
(validator as any)._optimizationLevel = OptimizationLevel.ULTRA;
|
|
310
|
+
|
|
311
|
+
return validator as PrecompiledValidator;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Analyze schema to determine optimal optimization level
|
|
316
|
+
*/
|
|
317
|
+
private static analyzeOptimizationLevel(
|
|
318
|
+
schema: Record<string, any>
|
|
319
|
+
): OptimizationLevel {
|
|
320
|
+
const fieldCount = Object.keys(schema).length;
|
|
321
|
+
let complexityScore = 0;
|
|
322
|
+
|
|
323
|
+
for (const [key, value] of Object.entries(schema)) {
|
|
324
|
+
if (typeof value === "string") {
|
|
325
|
+
if (value.includes("|")) complexityScore += 2; // Union
|
|
326
|
+
if (value.includes("[]")) complexityScore += 2; // Array
|
|
327
|
+
if (value.includes("when")) complexityScore += 5; // Conditional
|
|
328
|
+
if (value.includes("(")) complexityScore += 1; // Constraints
|
|
329
|
+
} else if (typeof value === "object") {
|
|
330
|
+
complexityScore += 10; // Nested object
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// Determine optimization level based on complexity
|
|
335
|
+
if (fieldCount <= 5 && complexityScore <= 10) {
|
|
336
|
+
return OptimizationLevel.ULTRA;
|
|
337
|
+
} else if (fieldCount <= 15 && complexityScore <= 30) {
|
|
338
|
+
return OptimizationLevel.AGGRESSIVE;
|
|
339
|
+
} else if (fieldCount <= 50) {
|
|
340
|
+
return OptimizationLevel.BASIC;
|
|
341
|
+
} else {
|
|
342
|
+
return OptimizationLevel.NONE;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Generate schema hash for caching
|
|
348
|
+
*/
|
|
349
|
+
private static generateSchemaHash(
|
|
350
|
+
schema: Record<string, any>,
|
|
351
|
+
options: SchemaOptions
|
|
352
|
+
): string {
|
|
353
|
+
const schemaStr = JSON.stringify(schema, Object.keys(schema).sort());
|
|
354
|
+
const optionsStr = JSON.stringify(options);
|
|
355
|
+
return `${this.simpleHash(schemaStr)}_${this.simpleHash(optionsStr)}`;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
private static simpleHash(str: string): string {
|
|
359
|
+
let hash = 0;
|
|
360
|
+
for (let i = 0; i < str.length; i++) {
|
|
361
|
+
const char = str.charCodeAt(i);
|
|
362
|
+
hash = (hash << 5) - hash + char;
|
|
363
|
+
hash = hash & hash; // Convert to 32-bit integer
|
|
364
|
+
}
|
|
365
|
+
return hash.toString(36);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Compile individual fields with specialized optimizations
|
|
370
|
+
*/
|
|
371
|
+
private static compileFields(
|
|
372
|
+
schema: Record<string, any>,
|
|
373
|
+
options: SchemaOptions
|
|
374
|
+
): FieldCompilation[] {
|
|
375
|
+
const fields: FieldCompilation[] = [];
|
|
376
|
+
|
|
377
|
+
for (const [fieldName, fieldType] of Object.entries(schema)) {
|
|
378
|
+
const compilation = this.compileField(fieldName, fieldType, options, 0);
|
|
379
|
+
fields.push(compilation);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
return fields;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* Compile a single field with maximum optimization
|
|
387
|
+
*/
|
|
388
|
+
private static compileField(
|
|
389
|
+
fieldName: string,
|
|
390
|
+
fieldType: any,
|
|
391
|
+
options: SchemaOptions,
|
|
392
|
+
depth: number = 0
|
|
393
|
+
): FieldCompilation {
|
|
394
|
+
// Handle nested objects properly
|
|
395
|
+
if (
|
|
396
|
+
typeof fieldType === "object" &&
|
|
397
|
+
fieldType !== null &&
|
|
398
|
+
!Array.isArray(fieldType)
|
|
399
|
+
) {
|
|
400
|
+
// This is a nested object - create a validator that recursively validates the nested schema
|
|
401
|
+
const validator = (value: any): SchemaValidationResult => {
|
|
402
|
+
if (
|
|
403
|
+
typeof value !== "object" ||
|
|
404
|
+
value === null ||
|
|
405
|
+
Array.isArray(value)
|
|
406
|
+
) {
|
|
407
|
+
return {
|
|
408
|
+
success: false,
|
|
409
|
+
errors: [ErrorHandler.createTypeError([], "object", value)],
|
|
410
|
+
warnings: [],
|
|
411
|
+
data: undefined,
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// Recursively validate nested object with depth tracking
|
|
416
|
+
const validatedData: any = {};
|
|
417
|
+
const errors: ValidationError[] = [];
|
|
418
|
+
const warnings: string[] = [];
|
|
419
|
+
|
|
420
|
+
for (const [key, nestedFieldType] of Object.entries(fieldType)) {
|
|
421
|
+
const nestedValue = value[key];
|
|
422
|
+
|
|
423
|
+
// For nested fields, use FieldPrecompilers directly for string types
|
|
424
|
+
if (typeof nestedFieldType === "string") {
|
|
425
|
+
const fieldValidator =
|
|
426
|
+
FieldPrecompilers.parseAndCompile(nestedFieldType);
|
|
427
|
+
const result = fieldValidator(nestedValue);
|
|
428
|
+
|
|
429
|
+
if (!result.success) {
|
|
430
|
+
errors.push(...result.errors);
|
|
431
|
+
} else {
|
|
432
|
+
validatedData[key] = result.data;
|
|
433
|
+
if (result.warnings) warnings.push(...result.warnings);
|
|
434
|
+
}
|
|
435
|
+
} else if (
|
|
436
|
+
typeof nestedFieldType === "object" &&
|
|
437
|
+
nestedFieldType !== null
|
|
438
|
+
) {
|
|
439
|
+
// For nested objects, validate recursively with depth limit
|
|
440
|
+
if (depth < this.MAX_COMPILATION_DEPTH - 1) {
|
|
441
|
+
// Safe to recurse - compile and validate the nested object
|
|
442
|
+
const nestedField = this.compileField(
|
|
443
|
+
key,
|
|
444
|
+
nestedFieldType,
|
|
445
|
+
options,
|
|
446
|
+
depth + 1
|
|
447
|
+
);
|
|
448
|
+
const nestedResult = nestedField.validator(nestedValue);
|
|
449
|
+
|
|
450
|
+
if (!nestedResult.success) {
|
|
451
|
+
errors.push(...nestedResult.errors);
|
|
452
|
+
} else {
|
|
453
|
+
validatedData[key] = nestedResult.data;
|
|
454
|
+
if (nestedResult.warnings)
|
|
455
|
+
warnings.push(...nestedResult.warnings);
|
|
456
|
+
}
|
|
457
|
+
} else {
|
|
458
|
+
// Depth limit reached - do basic type checking only
|
|
459
|
+
if (typeof nestedValue === "object" && nestedValue !== null) {
|
|
460
|
+
validatedData[key] = nestedValue;
|
|
461
|
+
warnings.push(
|
|
462
|
+
`${key}: Maximum nesting depth reached - basic validation only`
|
|
463
|
+
);
|
|
464
|
+
} else {
|
|
465
|
+
errors.push(
|
|
466
|
+
ErrorHandler.createTypeError([], "object", nestedValue)
|
|
467
|
+
);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
} else {
|
|
471
|
+
// Unknown field type
|
|
472
|
+
errors.push(
|
|
473
|
+
ErrorHandler.createSimpleError(
|
|
474
|
+
`Unknown field type: ${nestedFieldType}`,
|
|
475
|
+
ErrorCode.TYPE_MISMATCH
|
|
476
|
+
)
|
|
477
|
+
);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
return {
|
|
482
|
+
success: errors.length === 0,
|
|
483
|
+
errors,
|
|
484
|
+
warnings,
|
|
485
|
+
data: errors.length === 0 ? validatedData : undefined,
|
|
486
|
+
};
|
|
487
|
+
};
|
|
488
|
+
|
|
489
|
+
return {
|
|
490
|
+
fieldName,
|
|
491
|
+
fieldType: "[nested object]",
|
|
492
|
+
validator: validator as CompiledFieldValidator,
|
|
493
|
+
isOptional: false,
|
|
494
|
+
hasDefault: false,
|
|
495
|
+
isSimpleType: false,
|
|
496
|
+
isUnion: false,
|
|
497
|
+
isArray: false,
|
|
498
|
+
isNested: true,
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
// Handle string field types
|
|
503
|
+
const fieldTypeStr = String(fieldType);
|
|
504
|
+
|
|
505
|
+
// Create precompiled validator for this field
|
|
506
|
+
const validator = FieldPrecompilers.parseAndCompile(fieldTypeStr);
|
|
507
|
+
|
|
508
|
+
return {
|
|
509
|
+
fieldName,
|
|
510
|
+
fieldType: fieldTypeStr,
|
|
511
|
+
validator,
|
|
512
|
+
isOptional: fieldTypeStr.includes("?"),
|
|
513
|
+
hasDefault: false, // TODO: Extract default values
|
|
514
|
+
isSimpleType: this.isSimpleType(fieldType),
|
|
515
|
+
isUnion: fieldTypeStr.includes("|"),
|
|
516
|
+
isArray: fieldTypeStr.includes("[]"),
|
|
517
|
+
isNested: typeof fieldType === "object",
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
private static isSimpleType(fieldType: any): boolean {
|
|
522
|
+
if (typeof fieldType !== "string") return false;
|
|
523
|
+
|
|
524
|
+
// Handle constants (=value) as simple types
|
|
525
|
+
if (fieldType.startsWith("=")) return true;
|
|
526
|
+
|
|
527
|
+
// Handle record types as simple types (they have precompiled validators)
|
|
528
|
+
if (fieldType.startsWith("record<") || fieldType.startsWith("Record<")) {
|
|
529
|
+
return true;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
const simpleTypes = SUPPORTED_VALIDATOR_TYPES;
|
|
533
|
+
|
|
534
|
+
return simpleTypes.some((type) => fieldType.startsWith(type));
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
private static generateAggressiveValidator(
|
|
538
|
+
fields: FieldCompilation[],
|
|
539
|
+
schemaHash: string
|
|
540
|
+
): PrecompiledValidator {
|
|
541
|
+
// AGGRESSIVE optimization: Use the basic validator for now
|
|
542
|
+
// TODO: Implement more aggressive optimizations like field grouping, early exits, etc.
|
|
543
|
+
const basicValidator = this.generateBasicValidator(fields, schemaHash);
|
|
544
|
+
|
|
545
|
+
// Mark as aggressive optimization level
|
|
546
|
+
(basicValidator as any)._optimizationLevel = OptimizationLevel.AGGRESSIVE;
|
|
547
|
+
|
|
548
|
+
return basicValidator;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
private static generateBasicValidator(
|
|
552
|
+
fields: FieldCompilation[],
|
|
553
|
+
schemaHash: string
|
|
554
|
+
): PrecompiledValidator {
|
|
555
|
+
// BASIC optimization: Use compiled field validators with simple iteration
|
|
556
|
+
const validator = (data: any): SchemaValidationResult => {
|
|
557
|
+
// Fast path for non-objects
|
|
558
|
+
if (typeof data !== "object" || data === null || Array.isArray(data)) {
|
|
559
|
+
return {
|
|
560
|
+
success: false,
|
|
561
|
+
errors: [ErrorHandler.createTypeError([], "object", data)],
|
|
562
|
+
warnings: [],
|
|
563
|
+
data: undefined,
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
const validatedData: any = {};
|
|
568
|
+
const errors: ValidationError[] = [];
|
|
569
|
+
const warnings: string[] = [];
|
|
570
|
+
|
|
571
|
+
// Validate each field using compiled validators
|
|
572
|
+
for (const field of fields) {
|
|
573
|
+
const value = data[field.fieldName];
|
|
574
|
+
|
|
575
|
+
// Handle optional fields
|
|
576
|
+
if (value === undefined) {
|
|
577
|
+
if (!field.isOptional) {
|
|
578
|
+
errors.push(
|
|
579
|
+
ErrorHandler.createMissingFieldError(
|
|
580
|
+
[field.fieldName],
|
|
581
|
+
field.fieldName
|
|
582
|
+
)
|
|
583
|
+
);
|
|
584
|
+
} else if (field.hasDefault) {
|
|
585
|
+
validatedData[field.fieldName] = field.defaultValue;
|
|
586
|
+
}
|
|
587
|
+
continue;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
// Use the compiled field validator
|
|
591
|
+
const result = field.validator(value);
|
|
592
|
+
if (!result.success) {
|
|
593
|
+
// Add field path to errors
|
|
594
|
+
const errorsWithPath = result.errors.map((error) => ({
|
|
595
|
+
...error,
|
|
596
|
+
path: [field.fieldName, ...error.path],
|
|
597
|
+
message: error.message.includes(" in field ")
|
|
598
|
+
? error.message
|
|
599
|
+
: `${error.message} in field "${field.fieldName}"`,
|
|
600
|
+
}));
|
|
601
|
+
errors.push(...errorsWithPath);
|
|
602
|
+
} else {
|
|
603
|
+
validatedData[field.fieldName] = result.data;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
// Collect warnings
|
|
607
|
+
if (result.warnings && result.warnings.length > 0) {
|
|
608
|
+
warnings.push(...result.warnings);
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
// Return validation result
|
|
613
|
+
if (errors.length === 0) {
|
|
614
|
+
return {
|
|
615
|
+
success: true,
|
|
616
|
+
errors: [],
|
|
617
|
+
warnings,
|
|
618
|
+
data: validatedData,
|
|
619
|
+
};
|
|
620
|
+
} else {
|
|
621
|
+
return {
|
|
622
|
+
success: false,
|
|
623
|
+
errors,
|
|
624
|
+
warnings,
|
|
625
|
+
data: undefined,
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
};
|
|
629
|
+
|
|
630
|
+
(validator as any)._isPrecompiled = true;
|
|
631
|
+
(validator as any)._schemaHash = schemaHash;
|
|
632
|
+
(validator as any)._optimizationLevel = OptimizationLevel.BASIC;
|
|
633
|
+
|
|
634
|
+
return validator as PrecompiledValidator;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
private static estimatePerformanceGain(fields: FieldCompilation[]): number {
|
|
638
|
+
// Estimate performance gain based on field types
|
|
639
|
+
let gain = 1.0;
|
|
640
|
+
for (const field of fields) {
|
|
641
|
+
if (field.isUnion) gain += 0.5;
|
|
642
|
+
if (field.isArray) gain += 0.3;
|
|
643
|
+
if (field.isSimpleType) gain += 0.2;
|
|
644
|
+
}
|
|
645
|
+
return Math.min(gain, 5.0); // Cap at 5x improvement
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
/**
|
|
649
|
+
* Get compilation statistics
|
|
650
|
+
*/
|
|
651
|
+
static getStats() {
|
|
652
|
+
return { ...this.performanceStats };
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
/**
|
|
656
|
+
* Clear compilation cache
|
|
657
|
+
*/
|
|
658
|
+
static clearCache(): void {
|
|
659
|
+
this.compilationCache.clear();
|
|
660
|
+
this.performanceStats = {
|
|
661
|
+
compilations: 0,
|
|
662
|
+
cacheHits: 0,
|
|
663
|
+
totalCompilationTime: 0,
|
|
664
|
+
averageSpeedup: 0,
|
|
665
|
+
};
|
|
666
|
+
}
|
|
667
|
+
}
|