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,560 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Production Object Validation Cache System
|
|
3
|
+
*
|
|
4
|
+
* High-performance caching for object validation with intelligent
|
|
5
|
+
* hot-path optimization and memory management.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { SchemaValidationResult, ValidationError } from "../../types/types";
|
|
9
|
+
import type {
|
|
10
|
+
CachedValidation,
|
|
11
|
+
ValidationPath,
|
|
12
|
+
} from "../../types/objValidationCache";
|
|
13
|
+
import { ErrorHandler } from "../mode/interfaces/errors/ErrorHandler";
|
|
14
|
+
// Fast hash function for objects
|
|
15
|
+
function djb2Hash(str: string): string {
|
|
16
|
+
let hash = 5381;
|
|
17
|
+
for (let i = 0; i < str.length; i++) {
|
|
18
|
+
hash = (hash << 5) + hash + str.charCodeAt(i);
|
|
19
|
+
}
|
|
20
|
+
return (hash >>> 0).toString(36);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Optimized object key extractor
|
|
24
|
+
function getObjectKeys(obj: any): string {
|
|
25
|
+
if (typeof obj !== "object" || obj === null) return typeof obj;
|
|
26
|
+
|
|
27
|
+
const keys = [];
|
|
28
|
+
for (const key in obj) {
|
|
29
|
+
if (obj.hasOwnProperty(key)) keys.push(key);
|
|
30
|
+
}
|
|
31
|
+
return keys.sort().join(",");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export class ObjectValidationCache {
|
|
35
|
+
private static cache = new Map<string, CachedValidation>();
|
|
36
|
+
private static pathCache = new Map<string, ValidationPath>();
|
|
37
|
+
private static structureCache = new Map<
|
|
38
|
+
string,
|
|
39
|
+
(value: any) => SchemaValidationResult
|
|
40
|
+
>();
|
|
41
|
+
private static hotPaths = new Set<string>();
|
|
42
|
+
|
|
43
|
+
private static readonly MAX_CACHE_SIZE = 5000;
|
|
44
|
+
private static readonly HOT_PATH_THRESHOLD = 10;
|
|
45
|
+
private static readonly CACHE_TTL = 300000; // 5 minutes
|
|
46
|
+
|
|
47
|
+
private static stats = {
|
|
48
|
+
hits: 0,
|
|
49
|
+
misses: 0,
|
|
50
|
+
hotPathHits: 0,
|
|
51
|
+
structureHits: 0,
|
|
52
|
+
evictions: 0,
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Get cached validation result or compute and cache new one
|
|
57
|
+
*/
|
|
58
|
+
static getCachedValidation(
|
|
59
|
+
value: any,
|
|
60
|
+
validator: (value: any) => SchemaValidationResult,
|
|
61
|
+
path: string[] = []
|
|
62
|
+
): SchemaValidationResult {
|
|
63
|
+
const cacheKey = this.generateCacheKey(value, path);
|
|
64
|
+
const structureHash = this.generateStructureHash(value);
|
|
65
|
+
|
|
66
|
+
// Check cache
|
|
67
|
+
const cached = this.cache.get(cacheKey);
|
|
68
|
+
if (cached && this.isCacheValid(cached)) {
|
|
69
|
+
cached.accessCount++;
|
|
70
|
+
cached.lastAccessed = Date.now();
|
|
71
|
+
this.stats.hits++;
|
|
72
|
+
|
|
73
|
+
// Mark as hot path if accessed frequently
|
|
74
|
+
if (cached.accessCount >= this.HOT_PATH_THRESHOLD) {
|
|
75
|
+
this.markAsHotPath(path);
|
|
76
|
+
this.stats.hotPathHits++;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return cached.result;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
this.stats.misses++;
|
|
83
|
+
|
|
84
|
+
// Compute validation
|
|
85
|
+
const startTime = Date.now();
|
|
86
|
+
const result = validator(value);
|
|
87
|
+
const validationTime = Date.now() - startTime;
|
|
88
|
+
|
|
89
|
+
// Cache the result
|
|
90
|
+
const cacheEntry: CachedValidation = {
|
|
91
|
+
result,
|
|
92
|
+
structureHash,
|
|
93
|
+
accessCount: 1,
|
|
94
|
+
lastAccessed: Date.now(),
|
|
95
|
+
validationTime,
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
this.cache.set(cacheKey, cacheEntry);
|
|
99
|
+
this.updatePathStatistics(path, validationTime);
|
|
100
|
+
this.cleanupCache();
|
|
101
|
+
|
|
102
|
+
return result;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Optimized validation for nested objects
|
|
107
|
+
*/
|
|
108
|
+
static validateNestedObject(
|
|
109
|
+
value: any,
|
|
110
|
+
schema: Record<string, any>,
|
|
111
|
+
path: string[] = []
|
|
112
|
+
): SchemaValidationResult {
|
|
113
|
+
if (typeof value !== "object" || value === null) {
|
|
114
|
+
return {
|
|
115
|
+
success: false,
|
|
116
|
+
errors: [ErrorHandler.createTypeError([], "object", value)],
|
|
117
|
+
warnings: [],
|
|
118
|
+
data: value,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Check if this is a hot path
|
|
123
|
+
const pathKey = path.join(".");
|
|
124
|
+
if (this.hotPaths.has(pathKey)) {
|
|
125
|
+
return this.validateHotPath(value, schema, path);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Standard nested validation with caching
|
|
129
|
+
return this.validateWithStructuralCaching(value, schema, path);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Optimized validation for frequently accessed paths
|
|
134
|
+
*/
|
|
135
|
+
private static validateHotPath(
|
|
136
|
+
value: any,
|
|
137
|
+
schema: Record<string, any>,
|
|
138
|
+
path: string[]
|
|
139
|
+
): SchemaValidationResult {
|
|
140
|
+
const pathKey = path.join(".");
|
|
141
|
+
const cachedPath = this.pathCache.get(pathKey);
|
|
142
|
+
|
|
143
|
+
if (cachedPath) {
|
|
144
|
+
return cachedPath.validator(value);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Compile optimized validator for this hot path
|
|
148
|
+
const optimizedValidator = this.compileHotPathValidator(schema);
|
|
149
|
+
|
|
150
|
+
this.pathCache.set(pathKey, {
|
|
151
|
+
path,
|
|
152
|
+
validator: optimizedValidator,
|
|
153
|
+
isHotPath: true,
|
|
154
|
+
avgValidationTime: 0,
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
return optimizedValidator(value);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Validation with structural caching
|
|
162
|
+
*/
|
|
163
|
+
private static validateWithStructuralCaching(
|
|
164
|
+
value: any,
|
|
165
|
+
schema: Record<string, any>,
|
|
166
|
+
path: string[]
|
|
167
|
+
): SchemaValidationResult {
|
|
168
|
+
const structureKey = this.generateStructureKey(schema);
|
|
169
|
+
|
|
170
|
+
// Check if we have a cached structure validator
|
|
171
|
+
let structureValidator = this.structureCache.get(structureKey);
|
|
172
|
+
if (!structureValidator) {
|
|
173
|
+
structureValidator = this.compileStructureValidator(schema);
|
|
174
|
+
this.structureCache.set(structureKey, structureValidator);
|
|
175
|
+
this.stats.structureHits++;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return structureValidator(value);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Compile optimized validator for hot paths
|
|
183
|
+
*/
|
|
184
|
+
private static compileHotPathValidator(
|
|
185
|
+
schema: Record<string, any>
|
|
186
|
+
): (value: any) => SchemaValidationResult {
|
|
187
|
+
// Pre-compile field validators for maximum performance
|
|
188
|
+
const validationChecks: Array<
|
|
189
|
+
(value: any, errors: ValidationError[], data: any) => void
|
|
190
|
+
> = [];
|
|
191
|
+
|
|
192
|
+
for (const [key, fieldType] of Object.entries(schema)) {
|
|
193
|
+
const isOptional = this.isOptional(fieldType);
|
|
194
|
+
const cleanType = isOptional ? fieldType.slice(0, -1) : fieldType;
|
|
195
|
+
|
|
196
|
+
// Create optimized validation function for this field
|
|
197
|
+
const fieldValidator = this.createFieldValidator(
|
|
198
|
+
key,
|
|
199
|
+
cleanType,
|
|
200
|
+
isOptional
|
|
201
|
+
);
|
|
202
|
+
validationChecks.push(fieldValidator);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Return highly optimized validator
|
|
206
|
+
return (value: any): SchemaValidationResult => {
|
|
207
|
+
const errors: ValidationError[] = [];
|
|
208
|
+
const validatedData: any = {};
|
|
209
|
+
|
|
210
|
+
// Execute all field validations in a tight loop
|
|
211
|
+
for (let i = 0; i < validationChecks.length; i++) {
|
|
212
|
+
validationChecks[i](value, errors, validatedData);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return {
|
|
216
|
+
success: errors.length === 0,
|
|
217
|
+
errors,
|
|
218
|
+
warnings: [],
|
|
219
|
+
data: validatedData,
|
|
220
|
+
};
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Create optimized field validator
|
|
226
|
+
*/
|
|
227
|
+
private static createFieldValidator(
|
|
228
|
+
key: string,
|
|
229
|
+
fieldType: string,
|
|
230
|
+
isOptional: boolean
|
|
231
|
+
): (value: any, errors: ValidationError[], data: any) => void {
|
|
232
|
+
// Pre-compile type checking logic
|
|
233
|
+
if (fieldType === "string") {
|
|
234
|
+
return (value: any, errors: ValidationError[], data: any) => {
|
|
235
|
+
const fieldValue = value[key];
|
|
236
|
+
if (fieldValue === undefined) {
|
|
237
|
+
if (!isOptional)
|
|
238
|
+
errors.push(ErrorHandler.createMissingFieldError([], key));
|
|
239
|
+
} else if (typeof fieldValue !== "string") {
|
|
240
|
+
errors.push(ErrorHandler.createTypeError([], "string", fieldValue));
|
|
241
|
+
} else {
|
|
242
|
+
data[key] = fieldValue;
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (fieldType === "number") {
|
|
248
|
+
return (value: any, errors: ValidationError[], data: any) => {
|
|
249
|
+
const fieldValue = value[key];
|
|
250
|
+
if (fieldValue === undefined) {
|
|
251
|
+
if (!isOptional)
|
|
252
|
+
errors.push(ErrorHandler.createMissingFieldError([], key));
|
|
253
|
+
} else if (typeof fieldValue !== "number" || isNaN(fieldValue)) {
|
|
254
|
+
errors.push(ErrorHandler.createTypeError([], "number", fieldValue));
|
|
255
|
+
} else {
|
|
256
|
+
data[key] = fieldValue;
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (fieldType === "boolean") {
|
|
262
|
+
return (value: any, errors: ValidationError[], data: any) => {
|
|
263
|
+
const fieldValue = value[key];
|
|
264
|
+
if (fieldValue === undefined) {
|
|
265
|
+
if (!isOptional)
|
|
266
|
+
errors.push(ErrorHandler.createMissingFieldError([], key));
|
|
267
|
+
} else if (typeof fieldValue !== "boolean") {
|
|
268
|
+
errors.push(ErrorHandler.createTypeError([], "boolean", fieldValue));
|
|
269
|
+
} else {
|
|
270
|
+
data[key] = fieldValue;
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (fieldType.includes("|")) {
|
|
276
|
+
const allowedValues = new Set(fieldType.split("|").map((v) => v.trim()));
|
|
277
|
+
return (value: any, errors: ValidationError[], data: any) => {
|
|
278
|
+
const fieldValue = value[key];
|
|
279
|
+
if (fieldValue === undefined) {
|
|
280
|
+
if (!isOptional)
|
|
281
|
+
errors.push(ErrorHandler.createMissingFieldError([], key));
|
|
282
|
+
} else if (!allowedValues.has(String(fieldValue))) {
|
|
283
|
+
errors.push(
|
|
284
|
+
ErrorHandler.createUnionError(
|
|
285
|
+
[],
|
|
286
|
+
Array.from(allowedValues),
|
|
287
|
+
fieldValue
|
|
288
|
+
)
|
|
289
|
+
);
|
|
290
|
+
} else {
|
|
291
|
+
data[key] = fieldValue;
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// Array type
|
|
297
|
+
if (fieldType.endsWith("[]")) {
|
|
298
|
+
const itemType = fieldType.slice(0, -2);
|
|
299
|
+
return (value: any, errors: ValidationError[], data: any) => {
|
|
300
|
+
const fieldValue = value[key];
|
|
301
|
+
if (fieldValue === undefined) {
|
|
302
|
+
if (!isOptional)
|
|
303
|
+
errors.push(ErrorHandler.createMissingFieldError([], key));
|
|
304
|
+
} else if (!Array.isArray(fieldValue)) {
|
|
305
|
+
errors.push(ErrorHandler.createTypeError([], "array", fieldValue));
|
|
306
|
+
} else {
|
|
307
|
+
data[key] = fieldValue;
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// Default validator
|
|
313
|
+
return (value: any, errors: ValidationError[], data: any) => {
|
|
314
|
+
const fieldValue = value[key];
|
|
315
|
+
if (fieldValue === undefined && !isOptional) {
|
|
316
|
+
errors.push(ErrorHandler.createMissingFieldError([], key));
|
|
317
|
+
} else if (fieldValue !== undefined) {
|
|
318
|
+
data[key] = fieldValue;
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Compile structure validator
|
|
325
|
+
*/
|
|
326
|
+
private static compileStructureValidator(
|
|
327
|
+
schema: Record<string, any>
|
|
328
|
+
): (value: any) => SchemaValidationResult {
|
|
329
|
+
const schemaKeys = Object.keys(schema);
|
|
330
|
+
const requiredFields = schemaKeys.filter(
|
|
331
|
+
(key) => !this.isOptional(schema[key])
|
|
332
|
+
);
|
|
333
|
+
|
|
334
|
+
return (value: any): SchemaValidationResult => {
|
|
335
|
+
const errors: ValidationError[] = [];
|
|
336
|
+
const validatedData: any = {};
|
|
337
|
+
|
|
338
|
+
// Check required fields first
|
|
339
|
+
for (let i = 0; i < requiredFields.length; i++) {
|
|
340
|
+
const key = requiredFields[i];
|
|
341
|
+
if (value[key] === undefined) {
|
|
342
|
+
errors.push(ErrorHandler.createMissingFieldError([], key));
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// Process all fields
|
|
347
|
+
for (let i = 0; i < schemaKeys.length; i++) {
|
|
348
|
+
const key = schemaKeys[i];
|
|
349
|
+
const fieldValue = value[key];
|
|
350
|
+
|
|
351
|
+
if (fieldValue !== undefined) {
|
|
352
|
+
validatedData[key] = fieldValue;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
return {
|
|
357
|
+
success: errors.length === 0,
|
|
358
|
+
errors,
|
|
359
|
+
warnings: [],
|
|
360
|
+
data: validatedData,
|
|
361
|
+
};
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Check if field type is optional
|
|
367
|
+
*/
|
|
368
|
+
private static isOptional(fieldType: any): boolean {
|
|
369
|
+
return typeof fieldType === "string" && fieldType.endsWith("?");
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Mark path as hot path for optimization
|
|
374
|
+
*/
|
|
375
|
+
private static markAsHotPath(path: string[]): void {
|
|
376
|
+
const pathKey = path.join(".");
|
|
377
|
+
this.hotPaths.add(pathKey);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Update path statistics
|
|
382
|
+
*/
|
|
383
|
+
private static updatePathStatistics(
|
|
384
|
+
path: string[],
|
|
385
|
+
validationTime: number
|
|
386
|
+
): void {
|
|
387
|
+
const pathKey = path.join(".");
|
|
388
|
+
const existing = this.pathCache.get(pathKey);
|
|
389
|
+
|
|
390
|
+
if (existing) {
|
|
391
|
+
existing.avgValidationTime =
|
|
392
|
+
(existing.avgValidationTime + validationTime) / 2;
|
|
393
|
+
} else {
|
|
394
|
+
this.pathCache.set(pathKey, {
|
|
395
|
+
path,
|
|
396
|
+
validator: () => ({
|
|
397
|
+
success: true,
|
|
398
|
+
errors: [],
|
|
399
|
+
warnings: [],
|
|
400
|
+
data: null,
|
|
401
|
+
}),
|
|
402
|
+
isHotPath: false,
|
|
403
|
+
avgValidationTime: validationTime,
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Generate cache key for value and path
|
|
410
|
+
*/
|
|
411
|
+
private static generateCacheKey(value: any, path: string[]): string {
|
|
412
|
+
const valueHash = this.hashValue(value);
|
|
413
|
+
const pathHash = path.join(".");
|
|
414
|
+
return `${pathHash}:${valueHash}`;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Generate structure hash for value
|
|
419
|
+
*/
|
|
420
|
+
private static generateStructureHash(value: any): string {
|
|
421
|
+
return getObjectKeys(value);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Generate structure key for schema
|
|
426
|
+
*/
|
|
427
|
+
private static generateStructureKey(schema: Record<string, any>): string {
|
|
428
|
+
const keys = Object.keys(schema).sort();
|
|
429
|
+
const typeSignature = keys.map((k) => `${k}:${schema[k]}`).join(";");
|
|
430
|
+
return djb2Hash(typeSignature);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Fast hash function for values
|
|
435
|
+
*/
|
|
436
|
+
private static hashValue(value: any): string {
|
|
437
|
+
if (typeof value !== "object" || value === null) {
|
|
438
|
+
return String(value);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// Fast hash for objects
|
|
442
|
+
const str = JSON.stringify(value);
|
|
443
|
+
return djb2Hash(
|
|
444
|
+
str.length > 100 ? str.substring(0, 100 + (str.length % 50)) : str
|
|
445
|
+
);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* Check if cache entry is still valid
|
|
450
|
+
*/
|
|
451
|
+
private static isCacheValid(cached: CachedValidation): boolean {
|
|
452
|
+
return Date.now() - cached.lastAccessed < this.CACHE_TTL;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* Cleanup old cache entries using LRU strategy
|
|
457
|
+
*/
|
|
458
|
+
private static cleanupCache(): void {
|
|
459
|
+
if (this.cache.size <= this.MAX_CACHE_SIZE) return;
|
|
460
|
+
|
|
461
|
+
const now = Date.now();
|
|
462
|
+
const entries: [string, CachedValidation][] = [];
|
|
463
|
+
|
|
464
|
+
// Collect entries with scores
|
|
465
|
+
for (const [key, cached] of this.cache) {
|
|
466
|
+
const age = now - cached.lastAccessed;
|
|
467
|
+
const score = cached.accessCount / (age + 1); // Higher score = more valuable
|
|
468
|
+
entries.push([key, cached]);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
// Sort by value (lower score = less valuable)
|
|
472
|
+
entries.sort((a, b) => {
|
|
473
|
+
const ageA = now - a[1].lastAccessed;
|
|
474
|
+
const ageB = now - b[1].lastAccessed;
|
|
475
|
+
const scoreA = a[1].accessCount / (ageA + 1);
|
|
476
|
+
const scoreB = b[1].accessCount / (ageB + 1);
|
|
477
|
+
return scoreA - scoreB;
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
// Remove least valuable entries
|
|
481
|
+
const toRemove =
|
|
482
|
+
this.cache.size -
|
|
483
|
+
this.MAX_CACHE_SIZE +
|
|
484
|
+
Math.floor(this.MAX_CACHE_SIZE * 0.1);
|
|
485
|
+
for (let i = 0; i < toRemove && i < entries.length; i++) {
|
|
486
|
+
this.cache.delete(entries[i][0]);
|
|
487
|
+
this.stats.evictions++;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* Get cache statistics
|
|
493
|
+
*/
|
|
494
|
+
static getStats() {
|
|
495
|
+
const total = this.stats.hits + this.stats.misses;
|
|
496
|
+
const hitRate = total > 0 ? this.stats.hits / total : 0;
|
|
497
|
+
|
|
498
|
+
return {
|
|
499
|
+
...this.stats,
|
|
500
|
+
hitRate,
|
|
501
|
+
cacheSize: this.cache.size,
|
|
502
|
+
pathCacheSize: this.pathCache.size,
|
|
503
|
+
structureCacheSize: this.structureCache.size,
|
|
504
|
+
hotPathCount: this.hotPaths.size,
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Clear all caches
|
|
510
|
+
*/
|
|
511
|
+
static clearCache(): void {
|
|
512
|
+
this.cache.clear();
|
|
513
|
+
this.pathCache.clear();
|
|
514
|
+
this.structureCache.clear();
|
|
515
|
+
this.hotPaths.clear();
|
|
516
|
+
this.stats = {
|
|
517
|
+
hits: 0,
|
|
518
|
+
misses: 0,
|
|
519
|
+
hotPathHits: 0,
|
|
520
|
+
structureHits: 0,
|
|
521
|
+
evictions: 0,
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* Warm up cache with common validation patterns
|
|
527
|
+
*/
|
|
528
|
+
static warmup(commonSchemas: Record<string, any>[], sampleData: any[]): void {
|
|
529
|
+
for (const schema of commonSchemas) {
|
|
530
|
+
for (const data of sampleData) {
|
|
531
|
+
this.validateNestedObject(data, schema);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* Get cache efficiency metrics
|
|
538
|
+
*/
|
|
539
|
+
static getEfficiencyMetrics() {
|
|
540
|
+
const stats = this.getStats();
|
|
541
|
+
return {
|
|
542
|
+
hitRate: stats.hitRate,
|
|
543
|
+
hotPathEfficiency: stats.hotPathHits / (stats.hits || 1),
|
|
544
|
+
memoryUtilization: stats.cacheSize / this.MAX_CACHE_SIZE,
|
|
545
|
+
avgValidationTime: this.calculateAvgValidationTime(),
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
private static calculateAvgValidationTime(): number {
|
|
550
|
+
let totalTime = 0;
|
|
551
|
+
let count = 0;
|
|
552
|
+
|
|
553
|
+
for (const cached of this.cache.values()) {
|
|
554
|
+
totalTime += cached.validationTime;
|
|
555
|
+
count++;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
return count > 0 ? totalTime / count : 0;
|
|
559
|
+
}
|
|
560
|
+
}
|