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