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,771 @@
|
|
|
1
|
+
import { UnionCache } from '../mode/interfaces/validators/UnionCache.js';
|
|
2
|
+
import { ObjectValidationCache } from './ObjectValidationCache.js';
|
|
3
|
+
import { SchemaCompiler } from './SchemaCompiler.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Smart Performance Monitor & Auto-Optimizer
|
|
7
|
+
*
|
|
8
|
+
* Monitors validation performance in real-time and automatically
|
|
9
|
+
* applies optimizations based on usage patterns and bottlenecks.
|
|
10
|
+
*/
|
|
11
|
+
class PerformanceMonitor {
|
|
12
|
+
/**
|
|
13
|
+
* Start performance monitoring
|
|
14
|
+
*/
|
|
15
|
+
static startMonitoring(customThresholds) {
|
|
16
|
+
if (this.isMonitoring)
|
|
17
|
+
return;
|
|
18
|
+
if (customThresholds) {
|
|
19
|
+
Object.assign(this.thresholds, customThresholds);
|
|
20
|
+
}
|
|
21
|
+
this.isMonitoring = true;
|
|
22
|
+
// Start periodic analysis
|
|
23
|
+
this.analysisTimer = setInterval(() => {
|
|
24
|
+
this.performAnalysis();
|
|
25
|
+
}, this.ANALYSIS_INTERVAL);
|
|
26
|
+
// Start cleanup routine
|
|
27
|
+
this.cleanupTimer = setInterval(() => {
|
|
28
|
+
this.cleanupOldMetrics();
|
|
29
|
+
}, this.CLEANUP_INTERVAL);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Stop performance monitoring
|
|
33
|
+
*/
|
|
34
|
+
static stopMonitoring() {
|
|
35
|
+
this.isMonitoring = false;
|
|
36
|
+
if (this.analysisTimer) {
|
|
37
|
+
clearInterval(this.analysisTimer);
|
|
38
|
+
this.analysisTimer = undefined;
|
|
39
|
+
}
|
|
40
|
+
if (this.cleanupTimer) {
|
|
41
|
+
clearInterval(this.cleanupTimer);
|
|
42
|
+
this.cleanupTimer = undefined;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Register optimization callback
|
|
47
|
+
*/
|
|
48
|
+
static registerOptimization(type, callback) {
|
|
49
|
+
this.optimizationCallbacks.set(type, callback);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Record a validation operation
|
|
53
|
+
*/
|
|
54
|
+
static recordOperation(operationId, duration, schemaComplexity, cacheHit = false, optimizationApplied) {
|
|
55
|
+
if (!this.isMonitoring)
|
|
56
|
+
return;
|
|
57
|
+
const memoryUsage = this.getMemoryUsage();
|
|
58
|
+
const metric = {
|
|
59
|
+
operationId,
|
|
60
|
+
duration,
|
|
61
|
+
timestamp: Date.now(),
|
|
62
|
+
schemaComplexity,
|
|
63
|
+
cacheHit,
|
|
64
|
+
optimizationApplied,
|
|
65
|
+
memoryUsage
|
|
66
|
+
};
|
|
67
|
+
this.metrics.push(metric);
|
|
68
|
+
// Immediate cleanup if we exceed limits
|
|
69
|
+
if (this.metrics.length > this.MAX_METRICS * 1.2) {
|
|
70
|
+
this.cleanupOldMetrics();
|
|
71
|
+
}
|
|
72
|
+
// Real-time optimization for performance issues
|
|
73
|
+
this.handleOperationResult(metric);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Analyze performance and generate recommendations
|
|
77
|
+
*/
|
|
78
|
+
static analyzePerformance() {
|
|
79
|
+
if (this.metrics.length === 0) {
|
|
80
|
+
return this.getEmptyProfile();
|
|
81
|
+
}
|
|
82
|
+
const recentMetrics = this.getRecentMetrics(300000); // Last 5 minutes
|
|
83
|
+
return this.calculatePerformanceProfile(recentMetrics);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Get performance report
|
|
87
|
+
*/
|
|
88
|
+
static getPerformanceReport() {
|
|
89
|
+
const profile = this.analyzePerformance();
|
|
90
|
+
return {
|
|
91
|
+
profile,
|
|
92
|
+
optimizationHistory: this.optimizationHistory.slice(-20), // Last 20 optimizations
|
|
93
|
+
totalMetrics: this.metrics.length,
|
|
94
|
+
monitoringStatus: this.isMonitoring,
|
|
95
|
+
thresholds: { ...this.thresholds }
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Clear performance data
|
|
100
|
+
*/
|
|
101
|
+
static clearData() {
|
|
102
|
+
this.metrics = [];
|
|
103
|
+
this.optimizationHistory = [];
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Private methods
|
|
107
|
+
*/
|
|
108
|
+
static async performAnalysis() {
|
|
109
|
+
try {
|
|
110
|
+
const profile = this.analyzePerformance();
|
|
111
|
+
// Generate and apply optimizations
|
|
112
|
+
const recommendations = this.generateRecommendations(this.getRecentMetrics(300000));
|
|
113
|
+
await this.autoApplyOptimizations(recommendations);
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
// console.error('Performance analysis failed:', error);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
static calculatePerformanceProfile(metrics) {
|
|
120
|
+
if (metrics.length === 0)
|
|
121
|
+
return this.getEmptyProfile();
|
|
122
|
+
const durations = metrics.map(m => m.duration).sort((a, b) => a - b);
|
|
123
|
+
const cacheHits = metrics.filter(m => m.cacheHit).length;
|
|
124
|
+
const memoryUsages = metrics.map(m => m.memoryUsage || 0);
|
|
125
|
+
const averageDuration = durations.reduce((sum, d) => sum + d, 0) / durations.length;
|
|
126
|
+
const p95Index = Math.max(0, Math.floor(durations.length * 0.95) - 1);
|
|
127
|
+
const p99Index = Math.max(0, Math.floor(durations.length * 0.99) - 1);
|
|
128
|
+
const timeSpan = Math.max(1, (metrics[metrics.length - 1].timestamp - metrics[0].timestamp) / 1000);
|
|
129
|
+
const throughput = metrics.length / timeSpan;
|
|
130
|
+
const avgMemoryUsage = memoryUsages.reduce((sum, m) => sum + m, 0) / memoryUsages.length;
|
|
131
|
+
const profile = {
|
|
132
|
+
averageDuration,
|
|
133
|
+
p95Duration: durations[p95Index] || 0,
|
|
134
|
+
p99Duration: durations[p99Index] || 0,
|
|
135
|
+
throughput,
|
|
136
|
+
cacheHitRate: metrics.length > 0 ? cacheHits / metrics.length : 0,
|
|
137
|
+
memoryUsage: avgMemoryUsage,
|
|
138
|
+
bottlenecks: this.identifyBottlenecks(metrics),
|
|
139
|
+
recommendations: []
|
|
140
|
+
};
|
|
141
|
+
profile.recommendations = this.generateRecommendations(metrics);
|
|
142
|
+
return profile;
|
|
143
|
+
}
|
|
144
|
+
static identifyBottlenecks(metrics) {
|
|
145
|
+
const bottlenecks = [];
|
|
146
|
+
// Group by operation
|
|
147
|
+
const operationGroups = this.groupBy(metrics, 'operationId');
|
|
148
|
+
for (const [operationId, operationMetrics] of Object.entries(operationGroups)) {
|
|
149
|
+
const avgDuration = operationMetrics.reduce((sum, m) => sum + m.duration, 0) / operationMetrics.length;
|
|
150
|
+
if (avgDuration > this.thresholds.slowOperationMs) {
|
|
151
|
+
bottlenecks.push(`Slow operation: ${operationId} (${avgDuration.toFixed(2)}ms avg)`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
// Cache performance
|
|
155
|
+
const cacheHitRate = metrics.filter(m => m.cacheHit).length / metrics.length;
|
|
156
|
+
if (cacheHitRate < this.thresholds.minCacheHitRate) {
|
|
157
|
+
bottlenecks.push(`Low cache hit rate: ${(cacheHitRate * 100).toFixed(1)}%`);
|
|
158
|
+
}
|
|
159
|
+
// Memory usage
|
|
160
|
+
const avgMemory = metrics.reduce((sum, m) => sum + (m.memoryUsage || 0), 0) / metrics.length;
|
|
161
|
+
if (avgMemory > this.thresholds.maxMemoryMB) {
|
|
162
|
+
bottlenecks.push(`High memory usage: ${avgMemory.toFixed(1)}MB avg`);
|
|
163
|
+
}
|
|
164
|
+
// Complexity correlation
|
|
165
|
+
const complexMetrics = metrics.filter(m => m.schemaComplexity > 15);
|
|
166
|
+
if (complexMetrics.length > 0) {
|
|
167
|
+
const avgComplexDuration = complexMetrics.reduce((sum, m) => sum + m.duration, 0) / complexMetrics.length;
|
|
168
|
+
if (avgComplexDuration > this.thresholds.slowOperationMs * 1.5) {
|
|
169
|
+
bottlenecks.push(`Complex schemas are slow: ${avgComplexDuration.toFixed(2)}ms avg`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return bottlenecks;
|
|
173
|
+
}
|
|
174
|
+
static generateRecommendations(metrics) {
|
|
175
|
+
const recommendations = [];
|
|
176
|
+
// Cache optimization
|
|
177
|
+
const cacheHitRate = metrics.filter(m => m.cacheHit).length / metrics.length;
|
|
178
|
+
if (cacheHitRate < this.thresholds.minCacheHitRate) {
|
|
179
|
+
recommendations.push({
|
|
180
|
+
type: 'cache',
|
|
181
|
+
priority: 'high',
|
|
182
|
+
description: `Improve cache hit rate from ${(cacheHitRate * 100).toFixed(1)}% to 90%+`,
|
|
183
|
+
estimatedImprovement: Math.min(50, (0.9 - cacheHitRate) * 100),
|
|
184
|
+
implementation: async () => this.executeOptimization('cache')
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
// Memory optimization
|
|
188
|
+
const avgMemory = metrics.reduce((sum, m) => sum + (m.memoryUsage || 0), 0) / metrics.length;
|
|
189
|
+
if (avgMemory > this.thresholds.maxMemoryMB) {
|
|
190
|
+
recommendations.push({
|
|
191
|
+
type: 'memory',
|
|
192
|
+
priority: 'critical',
|
|
193
|
+
description: `Reduce memory usage from ${avgMemory.toFixed(1)}MB`,
|
|
194
|
+
estimatedImprovement: 30,
|
|
195
|
+
implementation: async () => this.executeOptimization('memory')
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
// Precompilation
|
|
199
|
+
const operationCounts = this.countOperations(metrics);
|
|
200
|
+
const frequentOperations = Object.entries(operationCounts)
|
|
201
|
+
.filter(([_, count]) => count > 50)
|
|
202
|
+
.map(([op, _]) => op);
|
|
203
|
+
if (frequentOperations.length > 0) {
|
|
204
|
+
recommendations.push({
|
|
205
|
+
type: 'precompile',
|
|
206
|
+
priority: 'medium',
|
|
207
|
+
description: `Precompile ${frequentOperations.length} frequently used schemas`,
|
|
208
|
+
estimatedImprovement: Math.min(40, frequentOperations.length * 5),
|
|
209
|
+
implementation: async () => this.executeOptimization('precompile', frequentOperations)
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
// Hot path optimization
|
|
213
|
+
const slowOperations = metrics
|
|
214
|
+
.filter(m => m.duration > this.thresholds.slowOperationMs)
|
|
215
|
+
.map(m => m.operationId);
|
|
216
|
+
const uniqueSlowOps = [...new Set(slowOperations)];
|
|
217
|
+
if (uniqueSlowOps.length > 0) {
|
|
218
|
+
recommendations.push({
|
|
219
|
+
type: 'hotpath',
|
|
220
|
+
priority: 'critical',
|
|
221
|
+
description: `Optimize ${uniqueSlowOps.length} slow validation paths`,
|
|
222
|
+
estimatedImprovement: Math.min(60, uniqueSlowOps.length * 10),
|
|
223
|
+
implementation: async () => this.executeOptimization('hotpath', uniqueSlowOps)
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
return recommendations.sort((a, b) => {
|
|
227
|
+
const priorityOrder = { critical: 4, high: 3, medium: 2, low: 1 };
|
|
228
|
+
return priorityOrder[b.priority] - priorityOrder[a.priority];
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
static async autoApplyOptimizations(recommendations) {
|
|
232
|
+
for (const rec of recommendations) {
|
|
233
|
+
if (rec.priority === 'critical' && rec.estimatedImprovement > this.thresholds.autoOptimizeThreshold * 100) {
|
|
234
|
+
await this.applyOptimization(rec);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
static async applyOptimization(recommendation) {
|
|
239
|
+
const startTime = Date.now();
|
|
240
|
+
let success = false;
|
|
241
|
+
try {
|
|
242
|
+
await recommendation.implementation();
|
|
243
|
+
success = true;
|
|
244
|
+
}
|
|
245
|
+
catch (error) {
|
|
246
|
+
// console.error(`Failed to apply ${recommendation.type} optimization:`, error);
|
|
247
|
+
}
|
|
248
|
+
this.optimizationHistory.push({
|
|
249
|
+
timestamp: startTime,
|
|
250
|
+
type: recommendation.type,
|
|
251
|
+
improvement: success ? recommendation.estimatedImprovement : 0,
|
|
252
|
+
success
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
static async executeOptimization(type, data) {
|
|
256
|
+
const callback = this.optimizationCallbacks.get(type);
|
|
257
|
+
if (callback) {
|
|
258
|
+
await callback();
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
// Default optimization behavior
|
|
262
|
+
switch (type) {
|
|
263
|
+
case 'cache':
|
|
264
|
+
this.optimizeCache();
|
|
265
|
+
break;
|
|
266
|
+
case 'memory':
|
|
267
|
+
this.optimizeMemory();
|
|
268
|
+
break;
|
|
269
|
+
case 'precompile':
|
|
270
|
+
this.precompileSchemas(data || []);
|
|
271
|
+
break;
|
|
272
|
+
case 'hotpath':
|
|
273
|
+
this.optimizeHotPaths(data || []);
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
static handleOperationResult(metric) {
|
|
279
|
+
if (metric.duration > this.thresholds.criticalOperationMs) {
|
|
280
|
+
// Handle critical performance issue
|
|
281
|
+
this.handleCriticalPerformance(metric);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
static async handleCriticalPerformance(metric) {
|
|
285
|
+
// Apply immediate optimization for critical issues
|
|
286
|
+
const emergencyOptimization = {
|
|
287
|
+
type: 'hotpath',
|
|
288
|
+
priority: 'critical',
|
|
289
|
+
description: `Emergency optimization for ${metric.operationId}`,
|
|
290
|
+
estimatedImprovement: 50,
|
|
291
|
+
implementation: async () => this.executeOptimization('hotpath', [metric.operationId])
|
|
292
|
+
};
|
|
293
|
+
await this.applyOptimization(emergencyOptimization);
|
|
294
|
+
}
|
|
295
|
+
static optimizeCache() {
|
|
296
|
+
try {
|
|
297
|
+
// Get current cache statistics
|
|
298
|
+
const cacheStats = ObjectValidationCache.getStats();
|
|
299
|
+
const unionStats = UnionCache.getCacheStats();
|
|
300
|
+
// console.log(`📊 Union cache: ${unionStats.size} entries`);
|
|
301
|
+
// console.log(`🔧 Cache optimization: Hit rate ${(cacheStats.hitRate * 100).toFixed(1)}%`);
|
|
302
|
+
// Optimize based on hit rates
|
|
303
|
+
if (cacheStats.hitRate < 0.7) {
|
|
304
|
+
// Pre-warm cache with common validation patterns
|
|
305
|
+
const commonPatterns = [
|
|
306
|
+
'string', 'number', 'boolean', 'email', 'url',
|
|
307
|
+
'string?', 'number?', 'boolean?',
|
|
308
|
+
'active|inactive', 'pending|approved|rejected',
|
|
309
|
+
'low|medium|high', 'user|admin|moderator'
|
|
310
|
+
];
|
|
311
|
+
UnionCache.preWarmCache(commonPatterns);
|
|
312
|
+
// console.log('✅ Cache pre-warmed with common patterns');
|
|
313
|
+
}
|
|
314
|
+
// Clean up old cache entries if memory usage is high
|
|
315
|
+
if (cacheStats.cacheSize > 3000) {
|
|
316
|
+
ObjectValidationCache.clearCache();
|
|
317
|
+
// console.log('🧹 Cache cleared due to high memory usage');
|
|
318
|
+
}
|
|
319
|
+
// console.log('✅ Cache optimization completed');
|
|
320
|
+
}
|
|
321
|
+
catch (error) {
|
|
322
|
+
// console.error('❌ Cache optimization failed:', error);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
static optimizeMemory() {
|
|
326
|
+
try {
|
|
327
|
+
// Clean up old metrics more aggressively
|
|
328
|
+
this.cleanupOldMetrics(0.5);
|
|
329
|
+
// Clear caches if memory usage is high
|
|
330
|
+
const memoryUsage = this.getMemoryUsage();
|
|
331
|
+
if (memoryUsage > 100) { // > 100MB
|
|
332
|
+
ObjectValidationCache.clearCache();
|
|
333
|
+
UnionCache.clearCache();
|
|
334
|
+
// console.log(`🧹 Memory optimization: Cleared caches (was ${memoryUsage.toFixed(1)}MB)`);
|
|
335
|
+
}
|
|
336
|
+
// Force garbage collection if available
|
|
337
|
+
if (global.gc) {
|
|
338
|
+
global.gc();
|
|
339
|
+
// console.log('🗑️ Garbage collection triggered');
|
|
340
|
+
}
|
|
341
|
+
// console.log('✅ Memory optimization completed');
|
|
342
|
+
}
|
|
343
|
+
catch (error) {
|
|
344
|
+
// console.error('❌ Memory optimization failed:', error);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Get current memory usage in MB
|
|
349
|
+
*/
|
|
350
|
+
static getMemoryUsage() {
|
|
351
|
+
if (typeof process !== 'undefined' && process.memoryUsage) {
|
|
352
|
+
return process.memoryUsage().heapUsed / 1024 / 1024;
|
|
353
|
+
}
|
|
354
|
+
return 0;
|
|
355
|
+
}
|
|
356
|
+
static precompileSchemas(operations) {
|
|
357
|
+
try {
|
|
358
|
+
// console.log(`🔧 Precompiling ${operations.length} frequently used schemas`);
|
|
359
|
+
// Get schema definitions for frequent operations
|
|
360
|
+
const schemasToCompile = this.getSchemaDefinitionsForOperations(operations);
|
|
361
|
+
let compiledCount = 0;
|
|
362
|
+
for (const [operationId, schemaDefinition] of schemasToCompile) {
|
|
363
|
+
try {
|
|
364
|
+
SchemaCompiler.compileSchema(schemaDefinition, { enableOptimizations: true });
|
|
365
|
+
compiledCount++;
|
|
366
|
+
}
|
|
367
|
+
catch (error) {
|
|
368
|
+
// console.warn(`⚠️ Failed to precompile schema for ${operationId}:`, error);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
catch (error) {
|
|
373
|
+
// // console.error('❌ Schema precompilation failed:', error);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
static optimizeHotPaths(operations) {
|
|
377
|
+
try {
|
|
378
|
+
// Mark operations as hot paths for caching priority
|
|
379
|
+
for (const operationId of operations) {
|
|
380
|
+
// Create optimized validators for hot paths
|
|
381
|
+
this.createHotPathValidator(operationId);
|
|
382
|
+
}
|
|
383
|
+
// Pre-warm cache for hot paths
|
|
384
|
+
const hotPathData = this.generateHotPathTestData(operations);
|
|
385
|
+
for (const [operationId, testData] of hotPathData) {
|
|
386
|
+
try {
|
|
387
|
+
// Trigger validation to warm up cache
|
|
388
|
+
ObjectValidationCache.getCachedValidation(testData, (value) => ({ success: true, errors: [], warnings: [], data: value }), [operationId]);
|
|
389
|
+
}
|
|
390
|
+
catch (error) {
|
|
391
|
+
// // console.warn(`⚠️ Failed to warm cache for ${operationId}:`, error);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
// console.log('✅ Hot path optimization completed');
|
|
395
|
+
}
|
|
396
|
+
catch (error) {
|
|
397
|
+
// console.error('❌ Hot path optimization failed:', error);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Get schema definitions for operations from integrated schema registry
|
|
402
|
+
*/
|
|
403
|
+
static getSchemaDefinitionsForOperations(operations) {
|
|
404
|
+
const schemas = new Map();
|
|
405
|
+
// Try to get schemas from the global schema registry first
|
|
406
|
+
const schemaRegistry = this.getSchemaRegistry();
|
|
407
|
+
for (const operationId of operations) {
|
|
408
|
+
let schema = null;
|
|
409
|
+
// 1. Try to get from registered schemas
|
|
410
|
+
if (schemaRegistry.has(operationId)) {
|
|
411
|
+
schema = schemaRegistry.get(operationId);
|
|
412
|
+
}
|
|
413
|
+
// 2. Try to infer from operation metrics
|
|
414
|
+
else if (!schema) {
|
|
415
|
+
schema = this.inferSchemaFromMetrics(operationId);
|
|
416
|
+
}
|
|
417
|
+
// 3. Fallback to pattern-based schema generation
|
|
418
|
+
if (!schema) {
|
|
419
|
+
schema = this.generateSchemaFromPattern(operationId);
|
|
420
|
+
}
|
|
421
|
+
if (schema) {
|
|
422
|
+
schemas.set(operationId, schema);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
return schemas;
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Get the global schema registry (integrates with existing Interface schemas)
|
|
429
|
+
*/
|
|
430
|
+
static getSchemaRegistry() {
|
|
431
|
+
// Use a module-level registry to avoid globalThis type issues
|
|
432
|
+
if (!this.schemaRegistry) {
|
|
433
|
+
this.schemaRegistry = new Map();
|
|
434
|
+
}
|
|
435
|
+
return this.schemaRegistry;
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* Infer schema structure from historical validation metrics
|
|
439
|
+
*/
|
|
440
|
+
static inferSchemaFromMetrics(operationId) {
|
|
441
|
+
// Analyze historical metrics to infer schema structure
|
|
442
|
+
const relatedMetrics = this.metrics.filter(m => m.operationId === operationId);
|
|
443
|
+
if (relatedMetrics.length === 0) {
|
|
444
|
+
return null;
|
|
445
|
+
}
|
|
446
|
+
// Analyze complexity patterns to infer schema structure
|
|
447
|
+
const avgComplexity = relatedMetrics.reduce((sum, m) => sum + m.schemaComplexity, 0) / relatedMetrics.length;
|
|
448
|
+
const avgDuration = relatedMetrics.reduce((sum, m) => sum + m.duration, 0) / relatedMetrics.length;
|
|
449
|
+
// Infer schema based on performance characteristics
|
|
450
|
+
if (avgComplexity < 5 && avgDuration < 2) {
|
|
451
|
+
// Simple schema
|
|
452
|
+
return {
|
|
453
|
+
id: 'number',
|
|
454
|
+
name: 'string',
|
|
455
|
+
active: 'boolean'
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
else if (avgComplexity < 15 && avgDuration < 10) {
|
|
459
|
+
// Medium complexity schema
|
|
460
|
+
return {
|
|
461
|
+
id: 'number',
|
|
462
|
+
data: {
|
|
463
|
+
name: 'string',
|
|
464
|
+
email: 'email',
|
|
465
|
+
status: 'active|inactive|pending'
|
|
466
|
+
},
|
|
467
|
+
metadata: {
|
|
468
|
+
created: 'date',
|
|
469
|
+
updated: 'date?'
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
else {
|
|
474
|
+
// Complex schema
|
|
475
|
+
return {
|
|
476
|
+
id: 'number',
|
|
477
|
+
user: {
|
|
478
|
+
profile: {
|
|
479
|
+
name: 'string(2,50)',
|
|
480
|
+
email: 'email',
|
|
481
|
+
address: {
|
|
482
|
+
street: 'string',
|
|
483
|
+
city: 'string',
|
|
484
|
+
country: 'string(2,3)'
|
|
485
|
+
}
|
|
486
|
+
},
|
|
487
|
+
preferences: {
|
|
488
|
+
theme: 'light|dark|auto',
|
|
489
|
+
notifications: 'boolean'
|
|
490
|
+
}
|
|
491
|
+
},
|
|
492
|
+
metadata: {
|
|
493
|
+
created: 'date',
|
|
494
|
+
updated: 'date?',
|
|
495
|
+
tags: 'string[]?'
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* Generate schema based on operation ID patterns
|
|
502
|
+
*/
|
|
503
|
+
static generateSchemaFromPattern(operationId) {
|
|
504
|
+
const lowerOp = operationId.toLowerCase();
|
|
505
|
+
// User-related operations
|
|
506
|
+
if (lowerOp.includes('user') || lowerOp.includes('profile') || lowerOp.includes('account')) {
|
|
507
|
+
return {
|
|
508
|
+
id: 'positive',
|
|
509
|
+
email: 'email',
|
|
510
|
+
name: 'string(2,100)',
|
|
511
|
+
status: 'active|inactive|pending|suspended',
|
|
512
|
+
role: 'user|admin|moderator|guest',
|
|
513
|
+
profile: {
|
|
514
|
+
firstName: 'string(1,50)',
|
|
515
|
+
lastName: 'string(1,50)',
|
|
516
|
+
avatar: 'url?',
|
|
517
|
+
bio: 'string(0,500)?'
|
|
518
|
+
},
|
|
519
|
+
preferences: {
|
|
520
|
+
theme: 'light|dark|auto',
|
|
521
|
+
language: 'string(2,5)',
|
|
522
|
+
notifications: 'boolean'
|
|
523
|
+
},
|
|
524
|
+
metadata: {
|
|
525
|
+
created: 'date',
|
|
526
|
+
updated: 'date?',
|
|
527
|
+
lastLogin: 'date?'
|
|
528
|
+
}
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
// Order/transaction operations
|
|
532
|
+
if (lowerOp.includes('order') || lowerOp.includes('transaction') || lowerOp.includes('payment')) {
|
|
533
|
+
return {
|
|
534
|
+
id: 'positive',
|
|
535
|
+
userId: 'positive',
|
|
536
|
+
total: 'number(0,999999.99)',
|
|
537
|
+
currency: 'string(3,3)',
|
|
538
|
+
status: 'pending|processing|completed|cancelled|refunded',
|
|
539
|
+
items: [{
|
|
540
|
+
id: 'positive',
|
|
541
|
+
name: 'string(1,200)',
|
|
542
|
+
quantity: 'positive',
|
|
543
|
+
price: 'number(0,99999.99)'
|
|
544
|
+
}],
|
|
545
|
+
billing: {
|
|
546
|
+
address: 'string',
|
|
547
|
+
city: 'string',
|
|
548
|
+
country: 'string(2,3)',
|
|
549
|
+
postalCode: 'string'
|
|
550
|
+
},
|
|
551
|
+
metadata: {
|
|
552
|
+
created: 'date',
|
|
553
|
+
updated: 'date?',
|
|
554
|
+
notes: 'string?'
|
|
555
|
+
}
|
|
556
|
+
};
|
|
557
|
+
}
|
|
558
|
+
// Product/catalog operations
|
|
559
|
+
if (lowerOp.includes('product') || lowerOp.includes('item') || lowerOp.includes('catalog')) {
|
|
560
|
+
return {
|
|
561
|
+
id: 'positive',
|
|
562
|
+
name: 'string(1,200)',
|
|
563
|
+
description: 'string(0,2000)?',
|
|
564
|
+
price: 'number(0,99999.99)',
|
|
565
|
+
category: 'string',
|
|
566
|
+
status: 'active|inactive|discontinued',
|
|
567
|
+
inventory: {
|
|
568
|
+
quantity: 'number(0,999999)',
|
|
569
|
+
reserved: 'number(0,999999)',
|
|
570
|
+
available: 'number(0,999999)'
|
|
571
|
+
},
|
|
572
|
+
attributes: {
|
|
573
|
+
weight: 'number?',
|
|
574
|
+
dimensions: {
|
|
575
|
+
length: 'number?',
|
|
576
|
+
width: 'number?',
|
|
577
|
+
height: 'number?'
|
|
578
|
+
}
|
|
579
|
+
},
|
|
580
|
+
metadata: {
|
|
581
|
+
created: 'date',
|
|
582
|
+
updated: 'date?',
|
|
583
|
+
tags: 'string[]?'
|
|
584
|
+
}
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
// API/request operations
|
|
588
|
+
if (lowerOp.includes('api') || lowerOp.includes('request') || lowerOp.includes('response')) {
|
|
589
|
+
return {
|
|
590
|
+
method: 'GET|POST|PUT|DELETE|PATCH',
|
|
591
|
+
path: 'string',
|
|
592
|
+
headers: 'any?',
|
|
593
|
+
body: 'any?',
|
|
594
|
+
query: 'any?',
|
|
595
|
+
params: 'any?',
|
|
596
|
+
metadata: {
|
|
597
|
+
timestamp: 'date',
|
|
598
|
+
userAgent: 'string?',
|
|
599
|
+
ip: 'string?'
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
// Generic fallback schema
|
|
604
|
+
return {
|
|
605
|
+
id: 'number',
|
|
606
|
+
type: 'string',
|
|
607
|
+
data: 'any',
|
|
608
|
+
status: 'active|inactive',
|
|
609
|
+
metadata: {
|
|
610
|
+
created: 'date',
|
|
611
|
+
updated: 'date?'
|
|
612
|
+
}
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
/**
|
|
616
|
+
* Create optimized validator for hot path with real implementation
|
|
617
|
+
*/
|
|
618
|
+
static createHotPathValidator(operationId) {
|
|
619
|
+
try {
|
|
620
|
+
// Get schema for this operation
|
|
621
|
+
const schemaDefinition = this.getSchemaDefinitionsForOperations([operationId]).get(operationId);
|
|
622
|
+
if (!schemaDefinition) {
|
|
623
|
+
// console.warn(`⚠️ No schema found for hot path: ${operationId}`);
|
|
624
|
+
return;
|
|
625
|
+
}
|
|
626
|
+
// Pre-compile the schema for maximum performance
|
|
627
|
+
const compiledValidator = SchemaCompiler.compileSchema(schemaDefinition, {
|
|
628
|
+
enableOptimizations: true,
|
|
629
|
+
cacheValidation: true,
|
|
630
|
+
hotPath: true
|
|
631
|
+
});
|
|
632
|
+
// Store the compiled validator in the hot path cache
|
|
633
|
+
this.hotPathValidators.set(operationId, compiledValidator);
|
|
634
|
+
// Mark this path for priority caching
|
|
635
|
+
ObjectValidationCache.getCachedValidation(this.generateSampleData(schemaDefinition), compiledValidator.validate.bind(compiledValidator), [operationId, 'hotpath']);
|
|
636
|
+
}
|
|
637
|
+
catch (error) {
|
|
638
|
+
// console.error(`❌ Failed to create hot path validator for ${operationId}:`, error);
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
/**
|
|
642
|
+
* Generate sample data for schema pre-warming
|
|
643
|
+
*/
|
|
644
|
+
static generateSampleData(schemaDefinition) {
|
|
645
|
+
const sampleData = {};
|
|
646
|
+
for (const [key, fieldType] of Object.entries(schemaDefinition)) {
|
|
647
|
+
if (typeof fieldType === 'string') {
|
|
648
|
+
sampleData[key] = this.generateSampleValue(fieldType);
|
|
649
|
+
}
|
|
650
|
+
else if (typeof fieldType === 'object' && fieldType !== null && !Array.isArray(fieldType)) {
|
|
651
|
+
sampleData[key] = this.generateSampleData(fieldType);
|
|
652
|
+
}
|
|
653
|
+
else if (Array.isArray(fieldType) && fieldType.length === 1) {
|
|
654
|
+
if (typeof fieldType[0] === 'object') {
|
|
655
|
+
sampleData[key] = [this.generateSampleData(fieldType[0])];
|
|
656
|
+
}
|
|
657
|
+
else {
|
|
658
|
+
sampleData[key] = [this.generateSampleValue(fieldType[0])];
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
return sampleData;
|
|
663
|
+
}
|
|
664
|
+
/**
|
|
665
|
+
* Generate sample value for a field type
|
|
666
|
+
*/
|
|
667
|
+
static generateSampleValue(fieldType) {
|
|
668
|
+
const cleanType = fieldType.replace('?', '').split('(')[0];
|
|
669
|
+
switch (cleanType) {
|
|
670
|
+
case 'string': return 'sample_string';
|
|
671
|
+
case 'number': return 42;
|
|
672
|
+
case 'positive': return 1;
|
|
673
|
+
case 'boolean': return true;
|
|
674
|
+
case 'date': return new Date();
|
|
675
|
+
case 'email': return 'test@example.com';
|
|
676
|
+
case 'url': return 'https://example.com';
|
|
677
|
+
case 'any': return 'sample_data';
|
|
678
|
+
default:
|
|
679
|
+
if (fieldType.includes('|')) {
|
|
680
|
+
const options = fieldType.split('|');
|
|
681
|
+
return options[0].trim();
|
|
682
|
+
}
|
|
683
|
+
return 'sample_value';
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
/**
|
|
687
|
+
* Generate test data for hot path warming
|
|
688
|
+
*/
|
|
689
|
+
static generateHotPathTestData(operations) {
|
|
690
|
+
const testData = new Map();
|
|
691
|
+
for (const operationId of operations) {
|
|
692
|
+
if (operationId.includes('user')) {
|
|
693
|
+
testData.set(operationId, {
|
|
694
|
+
id: 1,
|
|
695
|
+
email: 'test@example.com',
|
|
696
|
+
name: 'Test User',
|
|
697
|
+
status: 'active'
|
|
698
|
+
});
|
|
699
|
+
}
|
|
700
|
+
else if (operationId.includes('order')) {
|
|
701
|
+
testData.set(operationId, {
|
|
702
|
+
id: 1,
|
|
703
|
+
total: 99.99,
|
|
704
|
+
status: 'pending'
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
else {
|
|
708
|
+
testData.set(operationId, {
|
|
709
|
+
id: 1,
|
|
710
|
+
data: 'test'
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
return testData;
|
|
715
|
+
}
|
|
716
|
+
static cleanupOldMetrics(ratio = 0.8) {
|
|
717
|
+
if (this.metrics.length > this.MAX_METRICS) {
|
|
718
|
+
const keepCount = Math.floor(this.MAX_METRICS * ratio);
|
|
719
|
+
this.metrics = this.metrics.slice(-keepCount);
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
static getRecentMetrics(timeWindow) {
|
|
723
|
+
const cutoff = Date.now() - timeWindow;
|
|
724
|
+
return this.metrics.filter(m => m.timestamp > cutoff);
|
|
725
|
+
}
|
|
726
|
+
static groupBy(array, key) {
|
|
727
|
+
return array.reduce((groups, item) => {
|
|
728
|
+
const groupKey = String(item[key]);
|
|
729
|
+
if (!groups[groupKey])
|
|
730
|
+
groups[groupKey] = [];
|
|
731
|
+
groups[groupKey].push(item);
|
|
732
|
+
return groups;
|
|
733
|
+
}, {});
|
|
734
|
+
}
|
|
735
|
+
static countOperations(metrics) {
|
|
736
|
+
return metrics.reduce((counts, metric) => {
|
|
737
|
+
counts[metric.operationId] = (counts[metric.operationId] || 0) + 1;
|
|
738
|
+
return counts;
|
|
739
|
+
}, {});
|
|
740
|
+
}
|
|
741
|
+
static getEmptyProfile() {
|
|
742
|
+
return {
|
|
743
|
+
averageDuration: 0,
|
|
744
|
+
p95Duration: 0,
|
|
745
|
+
p99Duration: 0,
|
|
746
|
+
throughput: 0,
|
|
747
|
+
cacheHitRate: 0,
|
|
748
|
+
memoryUsage: 0,
|
|
749
|
+
bottlenecks: [],
|
|
750
|
+
recommendations: []
|
|
751
|
+
};
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
PerformanceMonitor.metrics = [];
|
|
755
|
+
PerformanceMonitor.MAX_METRICS = 5000; // Reduced for better memory usage
|
|
756
|
+
PerformanceMonitor.ANALYSIS_INTERVAL = 60000; // 1 minute
|
|
757
|
+
PerformanceMonitor.CLEANUP_INTERVAL = 300000; // 5 minutes
|
|
758
|
+
PerformanceMonitor.thresholds = {
|
|
759
|
+
slowOperationMs: 5,
|
|
760
|
+
criticalOperationMs: 20,
|
|
761
|
+
minCacheHitRate: 0.8,
|
|
762
|
+
maxMemoryMB: 100,
|
|
763
|
+
autoOptimizeThreshold: 0.15 // 15% improvement threshold
|
|
764
|
+
};
|
|
765
|
+
PerformanceMonitor.isMonitoring = false;
|
|
766
|
+
PerformanceMonitor.optimizationHistory = [];
|
|
767
|
+
PerformanceMonitor.optimizationCallbacks = new Map();
|
|
768
|
+
PerformanceMonitor.hotPathValidators = new Map();
|
|
769
|
+
|
|
770
|
+
export { PerformanceMonitor };
|
|
771
|
+
//# sourceMappingURL=PerformanceMonitor.js.map
|