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
package/README.md
ADDED
|
@@ -0,0 +1,1305 @@
|
|
|
1
|
+
# ReliantType
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/js/reliant-type)
|
|
4
|
+
[](http://www.typescriptlang.org/)
|
|
5
|
+
[](https://github.com/nehonisteam/ReliantType/actions)
|
|
6
|
+
[](https://bundlephobia.com/package/reliant-type)
|
|
7
|
+
[](https://sdk.nehonix.space/pkgs/mods/vscode/latest/reliant-type.vsix)
|
|
8
|
+
|
|
9
|
+
<div align="center">
|
|
10
|
+
<img src="https://sdk.nehonix.space/sdks/assets/reliant-type.jpg" alt="ReliantType Logo" width="250" />
|
|
11
|
+
</div>
|
|
12
|
+
|
|
13
|
+
<div align="center">
|
|
14
|
+
<img src="https://sdk.nehonix.space/sdks/assets/vscode-extension-preview.gif" alt="VSCode extension preview" width="500" />
|
|
15
|
+
</div>
|
|
16
|
+
|
|
17
|
+
**TypeScript Schema Validation with Interface-Like Syntax**
|
|
18
|
+
|
|
19
|
+
A modern TypeScript validation library designed around familiar interface syntax and powerful conditional validation. Experience schema validation that feels natural to TypeScript developers while unlocking advanced runtime validation capabilities.
|
|
20
|
+
|
|
21
|
+
> **Formerly Fortify Schema** - Originally developed at [github.com/Nehonix-Team/fortify-schema](https://github.com/Nehonix-Team/fortify-schema)
|
|
22
|
+
|
|
23
|
+
⚠️ **Migration Notice**: The `fortify-schema` package will be deprecated in favor of `reliant-type`. While `fortify-schema` will continue to receive critical security updates, new features and improvements will only be available in `reliant-type`. We recommend migrating to `reliant-type` for the best experience and ongoing support.
|
|
24
|
+
|
|
25
|
+
## 🆕 What's New
|
|
26
|
+
|
|
27
|
+
- **Required Fields (`!`)**: Enforce non-empty strings and non-zero numbers with `"string!"` and `"number!"`
|
|
28
|
+
- **Object Types**: Validate generic object structures with `"object"` and `"object?"`
|
|
29
|
+
- **Enhanced Security**: All string operations now use secure regex patterns instead of potentially vulnerable methods
|
|
30
|
+
- **Improved Performance**: Optimized validation paths with better caching and precompilation
|
|
31
|
+
- **Better Error Messages**: More descriptive validation errors with clear property paths
|
|
32
|
+
|
|
33
|
+
## Quick Start
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm install reliant-type
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
import { Interface } from "reliant-type";
|
|
41
|
+
|
|
42
|
+
// Define schemas with familiar TypeScript-like syntax
|
|
43
|
+
const UserSchema = Interface({
|
|
44
|
+
id: "uuid",
|
|
45
|
+
email: "email!", // 🆕 Required (non-empty) email
|
|
46
|
+
name: "string(2,50)!", // 🆕 Required string with length constraints
|
|
47
|
+
age: "number(18,120)?",
|
|
48
|
+
role: "admin|user|guest",
|
|
49
|
+
|
|
50
|
+
// 🆕 Object and array types
|
|
51
|
+
profile: "object", // Any object structure
|
|
52
|
+
tags: "string[]", // Array of strings
|
|
53
|
+
metadata: "record<string, any>", // Dynamic key-value pairs
|
|
54
|
+
|
|
55
|
+
// Advanced conditional validation based on runtime properties
|
|
56
|
+
permissions: "when config.hasPermissions.$exists() *? string[] : =[]",
|
|
57
|
+
adminTools: "when role=admin *? boolean : =false",
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Validate with complete TypeScript inference
|
|
61
|
+
const result = UserSchema.safeParse(userData);
|
|
62
|
+
if (result.success) {
|
|
63
|
+
console.log("Valid user:", result.data); // Fully typed!
|
|
64
|
+
} else {
|
|
65
|
+
console.log("Validation errors:", result.errors);
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
_Note: For nested objects, we recommend limiting depth to 50-100 or no more than 300 levels for performance and safety. Default depth limit is 500._
|
|
70
|
+
|
|
71
|
+
Test by running:
|
|
72
|
+
|
|
73
|
+
- bun src\_\_tests\_\_\test_nested_obj.ts note: you may have bun installed if using this command. "npm i -g bun" (recommanded because it's faster than node)
|
|
74
|
+
|
|
75
|
+
- npm run benchmark:nestedObject
|
|
76
|
+
|
|
77
|
+
_Note: you may have tsx installed if using this command. "npm i -g tsx"._
|
|
78
|
+
|
|
79
|
+
## Table of Contents
|
|
80
|
+
|
|
81
|
+
- [Installation & Setup](#installation--setup)
|
|
82
|
+
- [Core Features](#core-features)
|
|
83
|
+
- [Utility Functions](#utility-functions)
|
|
84
|
+
- [Conditional Validation](#conditional-validation)
|
|
85
|
+
- [Live Utility - Real-time Validation](#live-utility---real-time-validation)
|
|
86
|
+
- [Real-World Applications](#real-world-applications)
|
|
87
|
+
- [Performance Excellence](#performance-excellence)
|
|
88
|
+
- [Advanced Capabilities](#advanced-capabilities)
|
|
89
|
+
- [Developer Experience](#developer-experience)
|
|
90
|
+
- [API Reference](#api-reference)
|
|
91
|
+
|
|
92
|
+
## Installation & Setup
|
|
93
|
+
|
|
94
|
+
### Requirements
|
|
95
|
+
|
|
96
|
+
- **TypeScript 4.5+**
|
|
97
|
+
- **Node.js 14+**
|
|
98
|
+
- **VS Code** (recommended for enhanced development experience)
|
|
99
|
+
|
|
100
|
+
### Installation
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
# NPM
|
|
104
|
+
npm install reliant-type
|
|
105
|
+
|
|
106
|
+
# Yarn
|
|
107
|
+
yarn add reliant-type
|
|
108
|
+
|
|
109
|
+
# PNPM
|
|
110
|
+
pnpm add reliant-type
|
|
111
|
+
|
|
112
|
+
# Bun
|
|
113
|
+
bun add reliant-type
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### VS Code Extension
|
|
117
|
+
|
|
118
|
+
Enhance your development workflow with our dedicated VS Code extension featuring comprehensive developer tools:
|
|
119
|
+
|
|
120
|
+
#### **🎨 Enhanced Features**
|
|
121
|
+
|
|
122
|
+
- **Syntax Highlighting**: Full syntax highlighting for all Reliant Type types and utilities
|
|
123
|
+
- **Hover Documentation**: Detailed type information, examples, and use cases on hover
|
|
124
|
+
- **Go-to-Definition**: Ctrl+Click on types to open comprehensive documentation
|
|
125
|
+
- **IntelliSense Support**: Smart autocomplete for schema definitions
|
|
126
|
+
- **Error Detection**: Real-time validation of schema syntax
|
|
127
|
+
- **Code Snippets**: Pre-built templates for common schema patterns
|
|
128
|
+
|
|
129
|
+
#### **📖 Interactive Documentation**
|
|
130
|
+
|
|
131
|
+
When you hover over any type in `Interface({...})` blocks, you'll see:
|
|
132
|
+
|
|
133
|
+
- **Type Description**: What the type validates
|
|
134
|
+
- **Usage Examples**: `"string"`, `"string?"`, `"string[]"`
|
|
135
|
+
- **Use Cases**: When and where to use each type
|
|
136
|
+
- **Code Examples**: Complete working examples
|
|
137
|
+
|
|
138
|
+
#### **🔧 Installation**
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
# Download and install
|
|
142
|
+
curl https://sdk.nehonix.space/pkgs/mods/vscode/latest/reliant-type.vsix -o reliant-type.vsix
|
|
143
|
+
code --install-extension reliant-type.vsix
|
|
144
|
+
|
|
145
|
+
# Or just search for "reliant-type" in the vscode marketplace
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Core Features
|
|
149
|
+
|
|
150
|
+
### Intuitive Schema Definition
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
import { Interface } from "reliant-type";
|
|
154
|
+
|
|
155
|
+
const ProductSchema = Interface({
|
|
156
|
+
id: "uuid",
|
|
157
|
+
name: "string(1,100)",
|
|
158
|
+
price: "number(0.01,99999.99)",
|
|
159
|
+
category: "electronics|books|clothing|home",
|
|
160
|
+
inStock: "boolean",
|
|
161
|
+
tags: "string[]?",
|
|
162
|
+
description: "string(,500)?",
|
|
163
|
+
createdAt: "date",
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
// Usage with full type safety
|
|
167
|
+
const product = {
|
|
168
|
+
id: "123e4567-e89b-12d3-a456-426614174000",
|
|
169
|
+
name: "Wireless Headphones",
|
|
170
|
+
price: 99.99,
|
|
171
|
+
category: "electronics",
|
|
172
|
+
inStock: true,
|
|
173
|
+
tags: ["wireless", "audio", "bluetooth"],
|
|
174
|
+
createdAt: new Date(),
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
const result = ProductSchema.safeParse(product);
|
|
178
|
+
console.log(result.success); // true
|
|
179
|
+
console.log(result.data); // Fully typed product data
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Comprehensive Type Support
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
const ComprehensiveSchema = Interface({
|
|
186
|
+
// Fundamental types
|
|
187
|
+
name: "string",
|
|
188
|
+
age: "number",
|
|
189
|
+
active: "boolean",
|
|
190
|
+
birthday: "date",
|
|
191
|
+
|
|
192
|
+
// Optional fields
|
|
193
|
+
nickname: "string?",
|
|
194
|
+
bio: "string?",
|
|
195
|
+
|
|
196
|
+
// 🆕 Required fields (cannot be empty/zero)
|
|
197
|
+
requiredName: "string!", // Non-empty string required
|
|
198
|
+
requiredCount: "number!", // Non-zero number required
|
|
199
|
+
|
|
200
|
+
// Constraint validation
|
|
201
|
+
username: "string(3,20)", // 3-20 characters
|
|
202
|
+
password: "string(8,)", // Minimum 8 characters
|
|
203
|
+
score: "number(0,100)", // Range 0-100
|
|
204
|
+
|
|
205
|
+
// Format validation
|
|
206
|
+
email: "email",
|
|
207
|
+
website: "url",
|
|
208
|
+
secureApi: "url.https", // HTTPS-only validation
|
|
209
|
+
devServer: "url.dev", // Development mode (allows localhost and security features disabled)
|
|
210
|
+
phone: "phone",
|
|
211
|
+
userId: "uuid",
|
|
212
|
+
|
|
213
|
+
// Array validation
|
|
214
|
+
tags: "string[]", // Required array
|
|
215
|
+
scores: "number[]?", // Optional array
|
|
216
|
+
limitedTags: "string[](1,5)", // 1-5 items
|
|
217
|
+
|
|
218
|
+
// Union types
|
|
219
|
+
status: "active|inactive|pending",
|
|
220
|
+
role: "user|admin|moderator",
|
|
221
|
+
|
|
222
|
+
// 🆕 Object types
|
|
223
|
+
profile: "object", // Any object
|
|
224
|
+
config: "object?", // Optional object
|
|
225
|
+
|
|
226
|
+
// Record types (dynamic key-value objects)
|
|
227
|
+
settings: "record<string, any>", // String keys, any values
|
|
228
|
+
counters: "record<string, number>", // String keys, number values
|
|
229
|
+
metadata: "record<string, string>", // String keys, string values
|
|
230
|
+
|
|
231
|
+
// Literal values
|
|
232
|
+
version: "=2.0",
|
|
233
|
+
type: "=user",
|
|
234
|
+
});
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### Deep Object Validation
|
|
238
|
+
|
|
239
|
+
```typescript
|
|
240
|
+
const UserProfileSchema = Interface({
|
|
241
|
+
user: {
|
|
242
|
+
id: "uuid",
|
|
243
|
+
email: "email",
|
|
244
|
+
profile: {
|
|
245
|
+
firstName: "string(1,50)",
|
|
246
|
+
lastName: "string(1,50)",
|
|
247
|
+
avatar: "url?",
|
|
248
|
+
preferences: {
|
|
249
|
+
theme: "light|dark|auto",
|
|
250
|
+
language: "string(/^[a-z]{2}$/)",
|
|
251
|
+
notifications: "boolean",
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
metadata: {
|
|
256
|
+
createdAt: "date",
|
|
257
|
+
lastLogin: "date?",
|
|
258
|
+
loginCount: "number(0,)",
|
|
259
|
+
},
|
|
260
|
+
});
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
### Utility Functions
|
|
264
|
+
|
|
265
|
+
Reliant Type provides powerful utility functions for advanced schema definition:
|
|
266
|
+
|
|
267
|
+
#### **Make.const() - Constant Values**
|
|
268
|
+
|
|
269
|
+
Create schemas that validate against exact constant values:
|
|
270
|
+
|
|
271
|
+
```typescript
|
|
272
|
+
import { Interface, Make } from "reliant-type";
|
|
273
|
+
|
|
274
|
+
const ConfigSchema = Interface({
|
|
275
|
+
// Exact string constants
|
|
276
|
+
apiVersion: Make.const("v2.1"),
|
|
277
|
+
environment: Make.const("production"),
|
|
278
|
+
|
|
279
|
+
// Numeric constants
|
|
280
|
+
maxRetries: Make.const(3),
|
|
281
|
+
timeout: Make.const(5000),
|
|
282
|
+
|
|
283
|
+
// Boolean constants
|
|
284
|
+
enableLogging: Make.const(true),
|
|
285
|
+
|
|
286
|
+
// Complex constants
|
|
287
|
+
defaultSettings: Make.const({
|
|
288
|
+
theme: "dark",
|
|
289
|
+
language: "en",
|
|
290
|
+
}),
|
|
291
|
+
|
|
292
|
+
// Array constants
|
|
293
|
+
supportedFormats: Make.const(["json", "xml", "csv"]),
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
// Usage
|
|
297
|
+
const config = {
|
|
298
|
+
apiVersion: "v2.1", // ✅ Valid
|
|
299
|
+
environment: "staging", // ❌ Invalid - must be exactly "production"
|
|
300
|
+
maxRetries: 3, // ✅ Valid
|
|
301
|
+
timeout: 3000, // ❌ Invalid - must be exactly 5000
|
|
302
|
+
};
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
#### **Record Types - Dynamic Objects**
|
|
306
|
+
|
|
307
|
+
Validate objects with dynamic keys but consistent value types:
|
|
308
|
+
|
|
309
|
+
```typescript
|
|
310
|
+
const DynamicSchema = Interface({
|
|
311
|
+
// String keys with any values
|
|
312
|
+
metadata: "record<string, any>",
|
|
313
|
+
|
|
314
|
+
// String keys with number values (counters, scores, etc.)
|
|
315
|
+
scores: "record<string, number>",
|
|
316
|
+
|
|
317
|
+
// String keys with string values (translations, labels, etc.)
|
|
318
|
+
translations: "record<string, string>",
|
|
319
|
+
|
|
320
|
+
// Optional record types
|
|
321
|
+
optionalSettings: "record<string, boolean>?",
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
// Usage
|
|
325
|
+
const data = {
|
|
326
|
+
metadata: {
|
|
327
|
+
userId: "123",
|
|
328
|
+
timestamp: new Date(),
|
|
329
|
+
flags: ["active", "verified"],
|
|
330
|
+
},
|
|
331
|
+
scores: {
|
|
332
|
+
math: 95,
|
|
333
|
+
science: 87,
|
|
334
|
+
english: 92,
|
|
335
|
+
},
|
|
336
|
+
translations: {
|
|
337
|
+
hello: "Hola",
|
|
338
|
+
goodbye: "Adiós",
|
|
339
|
+
welcome: "Bienvenido",
|
|
340
|
+
},
|
|
341
|
+
};
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
## Conditional Validation
|
|
345
|
+
|
|
346
|
+
Reliant Type's standout feature: advanced conditional validation based on runtime properties and business logic.
|
|
347
|
+
|
|
348
|
+
```typescript
|
|
349
|
+
const SmartUserSchema = Interface({
|
|
350
|
+
// Runtime context objects
|
|
351
|
+
config: "any?",
|
|
352
|
+
user: "any?",
|
|
353
|
+
features: "any?",
|
|
354
|
+
|
|
355
|
+
// Core user data
|
|
356
|
+
id: "uuid",
|
|
357
|
+
email: "email",
|
|
358
|
+
role: "admin|user|guest",
|
|
359
|
+
|
|
360
|
+
// Dynamic validation based on runtime state
|
|
361
|
+
hasPermissions: "when config.permissions.$exists() *? boolean : =false",
|
|
362
|
+
hasProfile: "when user.profile.$exists() *? boolean : =false",
|
|
363
|
+
isListEmpty: "when config.items.$empty() *? boolean : =true",
|
|
364
|
+
hasAdminRole: "when user.roles.$contains(admin) *? boolean : =false",
|
|
365
|
+
|
|
366
|
+
// Smart default values
|
|
367
|
+
defaultTags: 'when config.tags.$exists() *? string[] : =["default","user"]',
|
|
368
|
+
defaultSettings:
|
|
369
|
+
'when config.theme.$exists() *? any : ={"mode":"light","lang":"en"}',
|
|
370
|
+
|
|
371
|
+
// Deep property access
|
|
372
|
+
advancedFeature:
|
|
373
|
+
"when user.profile.settings.advanced.$exists() *? boolean : =false",
|
|
374
|
+
|
|
375
|
+
// Complex business rules
|
|
376
|
+
isValidUser:
|
|
377
|
+
"when user.email.$exists() && user.verified.$exists() *? boolean : =false",
|
|
378
|
+
});
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
### Runtime Validation Methods
|
|
382
|
+
|
|
383
|
+
```typescript
|
|
384
|
+
const RuntimeMethodsSchema = Interface({
|
|
385
|
+
data: "any?",
|
|
386
|
+
|
|
387
|
+
// Property existence checking
|
|
388
|
+
hasData: "when data.field.$exists() *? boolean : =false",
|
|
389
|
+
|
|
390
|
+
// Empty state validation
|
|
391
|
+
isEmpty: "when data.list.$empty() *? boolean : =true",
|
|
392
|
+
|
|
393
|
+
// Null checking
|
|
394
|
+
isNull: "when data.value.$null() *? boolean : =false",
|
|
395
|
+
|
|
396
|
+
// String pattern matching
|
|
397
|
+
containsText:
|
|
398
|
+
"when data.description.$contains(important) *? boolean : =false",
|
|
399
|
+
startsWithPrefix: "when data.code.$startsWith(PRE) *? boolean : =false",
|
|
400
|
+
endsWithSuffix: "when data.filename.$endsWith(.pdf) *? boolean : =false",
|
|
401
|
+
|
|
402
|
+
// Numeric range validation
|
|
403
|
+
inRange: "when data.score.$between(0,100) *? boolean : =false",
|
|
404
|
+
|
|
405
|
+
// Value inclusion testing
|
|
406
|
+
isValidStatus:
|
|
407
|
+
"when data.status.$in(active,pending,inactive) *? boolean : =false",
|
|
408
|
+
});
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
## Live Utility - Real-time Validation (still in progress so not recommended for production use yet)
|
|
412
|
+
|
|
413
|
+
The Live utility transforms Reliant Type into a powerful real-time validation system with EventEmitter-like interface, data transformation pipelines, and stream control methods. Perfect for modern applications requiring reactive validation.
|
|
414
|
+
|
|
415
|
+
### Key Features
|
|
416
|
+
|
|
417
|
+
- **Real-time Field Validation** - Validate form fields as users type
|
|
418
|
+
- **EventEmitter Interface** - Full `.on()`, `.emit()`, `.off()`, `.once()` support
|
|
419
|
+
- **Data Transformation Pipeline** - Chain `.transform()`, `.filter()`, `.map()` operations
|
|
420
|
+
- **Stream Control** - `.pause()`, `.resume()`, `.destroy()` for flow control
|
|
421
|
+
- **Stream Piping** - Connect validators with `.pipe()` for complex workflows
|
|
422
|
+
- **Performance Monitoring** - Built-in statistics and performance tracking
|
|
423
|
+
- **InterfaceSchema Sync** - Perfect synchronization with Interface validation
|
|
424
|
+
|
|
425
|
+
### Quick Example
|
|
426
|
+
|
|
427
|
+
```typescript
|
|
428
|
+
import { Live, Interface } from "reliant-type";
|
|
429
|
+
|
|
430
|
+
const UserSchema = Interface({
|
|
431
|
+
name: "string(2,50)",
|
|
432
|
+
email: "email",
|
|
433
|
+
age: "number(18,120)",
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
// Create stream validator with transformation pipeline
|
|
437
|
+
const validator = Live.stream(UserSchema)
|
|
438
|
+
.transform((data) => ({ ...data, timestamp: Date.now() }))
|
|
439
|
+
.filter((data) => data.age >= 21)
|
|
440
|
+
.map((data) => ({ ...data, name: data.name.toUpperCase() }));
|
|
441
|
+
|
|
442
|
+
// Listen for results
|
|
443
|
+
validator.on("valid", (data) => console.log("✅ Valid:", data));
|
|
444
|
+
validator.on("invalid", (data, errors) => console.log("❌ Invalid:", errors));
|
|
445
|
+
validator.on("filtered", (data) => console.log("🚫 Filtered:", data));
|
|
446
|
+
|
|
447
|
+
// Process data
|
|
448
|
+
validator.validate({ name: "john", email: "john@example.com", age: 25 });
|
|
449
|
+
// Output: ✅ Valid: { name: "JOHN", email: "john@example.com", age: 25, timestamp: 1703123456789 }
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
### Stream Control Example
|
|
453
|
+
|
|
454
|
+
```typescript
|
|
455
|
+
const streamValidator = Live.stream(UserSchema);
|
|
456
|
+
|
|
457
|
+
// Pause stream (queues data)
|
|
458
|
+
streamValidator.pause();
|
|
459
|
+
streamValidator.validate(userData1); // Queued
|
|
460
|
+
streamValidator.validate(userData2); // Queued
|
|
461
|
+
|
|
462
|
+
console.log("Queue length:", streamValidator.queueLength); // 2
|
|
463
|
+
|
|
464
|
+
// Resume and process queue
|
|
465
|
+
streamValidator.resume(); // Processes both queued items
|
|
466
|
+
|
|
467
|
+
// Stream piping
|
|
468
|
+
const sourceValidator = Live.stream(InputSchema);
|
|
469
|
+
const destinationValidator = Live.stream(OutputSchema);
|
|
470
|
+
|
|
471
|
+
sourceValidator.pipe(destinationValidator);
|
|
472
|
+
// Valid data flows: source → destination
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
### Form Integration Example
|
|
476
|
+
|
|
477
|
+
```typescript
|
|
478
|
+
const formValidator = Live.form(UserSchema);
|
|
479
|
+
|
|
480
|
+
// Bind form fields
|
|
481
|
+
formValidator.bindField("email", emailInput);
|
|
482
|
+
formValidator.bindField("name", nameInput);
|
|
483
|
+
|
|
484
|
+
// Enable real-time validation
|
|
485
|
+
formValidator.enableAutoValidation();
|
|
486
|
+
|
|
487
|
+
// Handle form submission
|
|
488
|
+
formValidator.onSubmit((isValid, data, errors) => {
|
|
489
|
+
if (isValid) {
|
|
490
|
+
submitToAPI(data);
|
|
491
|
+
} else {
|
|
492
|
+
displayErrors(errors);
|
|
493
|
+
}
|
|
494
|
+
});
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
The Live utility provides **100% coverage** of standard stream methods while maintaining **perfect synchronization** with InterfaceSchema validation logic.
|
|
498
|
+
|
|
499
|
+
## Real-World Applications
|
|
500
|
+
|
|
501
|
+
### E-Commerce Product Management
|
|
502
|
+
|
|
503
|
+
```typescript
|
|
504
|
+
const ECommerceProductSchema = Interface({
|
|
505
|
+
// Product identification
|
|
506
|
+
id: "uuid",
|
|
507
|
+
sku: "string(/^[A-Z0-9-]{8,20}$/)",
|
|
508
|
+
name: "string(1,200)",
|
|
509
|
+
slug: "string(/^[a-z0-9-]+$/)",
|
|
510
|
+
|
|
511
|
+
// Pricing structure
|
|
512
|
+
price: "number(0.01,999999.99)",
|
|
513
|
+
compareAtPrice: "number(0.01,999999.99)?",
|
|
514
|
+
cost: "number(0,999999.99)?",
|
|
515
|
+
|
|
516
|
+
// Inventory management
|
|
517
|
+
inventory: {
|
|
518
|
+
quantity: "number(0,)",
|
|
519
|
+
trackQuantity: "boolean",
|
|
520
|
+
allowBackorder: "boolean",
|
|
521
|
+
lowStockThreshold: "number(0,)?"
|
|
522
|
+
},
|
|
523
|
+
|
|
524
|
+
// Content management
|
|
525
|
+
description: "string(,5000)?",
|
|
526
|
+
shortDescription: "string(,500)?",
|
|
527
|
+
category: "electronics|clothing|books|home|sports|beauty",
|
|
528
|
+
tags: "string[](0,20)",
|
|
529
|
+
|
|
530
|
+
// Media assets
|
|
531
|
+
images: {
|
|
532
|
+
primary: "url",
|
|
533
|
+
gallery: "url[](0,10)",
|
|
534
|
+
alt: "string(,100)?"
|
|
535
|
+
}?,
|
|
536
|
+
|
|
537
|
+
// SEO optimization
|
|
538
|
+
seo: {
|
|
539
|
+
title: "string(,60)?",
|
|
540
|
+
description: "string(,160)?",
|
|
541
|
+
keywords: "string[](0,10)"
|
|
542
|
+
}?,
|
|
543
|
+
|
|
544
|
+
// Business logic with conditional validation
|
|
545
|
+
config: "any?",
|
|
546
|
+
|
|
547
|
+
// Product type-specific requirements
|
|
548
|
+
shipping: "when config.isDigital.$exists() *? any? : ={weight:0,dimensions:{}}",
|
|
549
|
+
subscription: "when config.isSubscription.$exists() *? any : =null",
|
|
550
|
+
variants: "when config.hasVariants.$exists() *? any[] : =[]",
|
|
551
|
+
|
|
552
|
+
// Publication workflow
|
|
553
|
+
status: "draft|active|archived",
|
|
554
|
+
publishedAt: "date?",
|
|
555
|
+
createdAt: "date",
|
|
556
|
+
updatedAt: "date"
|
|
557
|
+
});
|
|
558
|
+
```
|
|
559
|
+
|
|
560
|
+
## Performance Excellence
|
|
561
|
+
|
|
562
|
+
Reliant Type is engineered for high-performance validation with multiple optimization strategies:
|
|
563
|
+
|
|
564
|
+
### Performance Architecture
|
|
565
|
+
|
|
566
|
+
```typescript
|
|
567
|
+
// Built-in performance optimizations
|
|
568
|
+
const performanceFeatures = {
|
|
569
|
+
// Schema compilation
|
|
570
|
+
precompilation: "Schemas optimized at creation time",
|
|
571
|
+
caching: "Intelligent caching for union types and constraints",
|
|
572
|
+
|
|
573
|
+
// Memory management
|
|
574
|
+
memoryOptimized: "Minimal runtime overhead per validation",
|
|
575
|
+
zeroAllocation: "Hot paths avoid unnecessary object creation",
|
|
576
|
+
|
|
577
|
+
// Validation efficiency
|
|
578
|
+
earlyTermination: "Fast-fail validation on first error",
|
|
579
|
+
typeSpecialization: "Optimized validation paths per data type",
|
|
580
|
+
};
|
|
581
|
+
```
|
|
582
|
+
|
|
583
|
+
### Benchmark Highlights
|
|
584
|
+
|
|
585
|
+
Our continuous performance monitoring shows excellent results across all validation scenarios:
|
|
586
|
+
|
|
587
|
+
- **High Throughput**: Millions of operations per second for common validation patterns
|
|
588
|
+
- **Consistent Performance**: Low variation in execution times
|
|
589
|
+
- **Memory Efficient**: Minimal memory overhead per schema instance
|
|
590
|
+
- **Scalable**: Performance scales predictably with data complexity
|
|
591
|
+
|
|
592
|
+
### Performance Testing
|
|
593
|
+
|
|
594
|
+
Validate performance on your specific use cases:
|
|
595
|
+
|
|
596
|
+
```bash
|
|
597
|
+
# Run comprehensive benchmarks
|
|
598
|
+
bun run scripts/benchmark.js
|
|
599
|
+
|
|
600
|
+
```
|
|
601
|
+
|
|
602
|
+
View detailed [benchmark results](./src/bench/BENCHMARK-RESULTS.md) for comprehensive performance analysis.
|
|
603
|
+
|
|
604
|
+
## Advanced Capabilities
|
|
605
|
+
|
|
606
|
+
### Schema Transformation
|
|
607
|
+
|
|
608
|
+
```typescript
|
|
609
|
+
import { Mod } from "reliant-type";
|
|
610
|
+
|
|
611
|
+
const BaseUserSchema = Interface({
|
|
612
|
+
id: "uuid",
|
|
613
|
+
email: "email",
|
|
614
|
+
name: "string",
|
|
615
|
+
password: "string",
|
|
616
|
+
role: "user|admin",
|
|
617
|
+
createdAt: "date",
|
|
618
|
+
});
|
|
619
|
+
|
|
620
|
+
// Powerful schema transformations
|
|
621
|
+
const PublicUserSchema = Mod.omit(BaseUserSchema, ["password"]);
|
|
622
|
+
const PartialUserSchema = Mod.partial(BaseUserSchema);
|
|
623
|
+
const RequiredUserSchema = Mod.required(PartialUserSchema);
|
|
624
|
+
const ExtendedUserSchema = Mod.extend(BaseUserSchema, {
|
|
625
|
+
lastLogin: "date?",
|
|
626
|
+
preferences: {
|
|
627
|
+
theme: "light|dark",
|
|
628
|
+
notifications: "boolean",
|
|
629
|
+
},
|
|
630
|
+
});
|
|
631
|
+
```
|
|
632
|
+
|
|
633
|
+
### Comprehensive Error Handling
|
|
634
|
+
|
|
635
|
+
```typescript
|
|
636
|
+
const result = UserSchema.safeParse(invalidData);
|
|
637
|
+
|
|
638
|
+
if (!result.success) {
|
|
639
|
+
// Rich error information for debugging
|
|
640
|
+
result.errors.forEach((error) => {
|
|
641
|
+
console.log(`Field: ${error.path.join(".")}`);
|
|
642
|
+
console.log(`Message: ${error.message}`);
|
|
643
|
+
console.log(`Code: ${error.code}`);
|
|
644
|
+
console.log(`Expected: ${error.expected}`);
|
|
645
|
+
console.log(`Received: ${error.received}`);
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
// Exception-based validation
|
|
650
|
+
try {
|
|
651
|
+
const data = UserSchema.parse(userData);
|
|
652
|
+
// Process validated data
|
|
653
|
+
} catch (error) {
|
|
654
|
+
if (error instanceof ValidationError) {
|
|
655
|
+
console.log("Validation failed:", error.errors);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
```
|
|
659
|
+
|
|
660
|
+
## Developer Experience
|
|
661
|
+
|
|
662
|
+
### VS Code Extension Features
|
|
663
|
+
|
|
664
|
+
Our dedicated VS Code extension transforms your development experience:
|
|
665
|
+
|
|
666
|
+
- **Intelligent Syntax Highlighting** for schema definitions
|
|
667
|
+
- **Advanced IntelliSense** with type and method completion
|
|
668
|
+
- **Real-time Validation** with inline error detection
|
|
669
|
+
- **Rich Hover Documentation** for all types and methods
|
|
670
|
+
- **Multiple Theme Support** for different coding preferences
|
|
671
|
+
|
|
672
|
+
```typescript
|
|
673
|
+
const UserSchema = Interface({
|
|
674
|
+
// IntelliSense provides comprehensive type suggestions
|
|
675
|
+
email: "email", // Hover documentation explains validation rules
|
|
676
|
+
|
|
677
|
+
// Smart constraint completion
|
|
678
|
+
name: "string(2,50)", // Auto-suggests constraint syntax patterns
|
|
679
|
+
|
|
680
|
+
// Conditional method IntelliSense
|
|
681
|
+
hasProfile: "when user.profile.$exists() *? boolean : =false",
|
|
682
|
+
// ^ Shows all 8 available runtime methods
|
|
683
|
+
});
|
|
684
|
+
```
|
|
685
|
+
|
|
686
|
+
## What Sets Reliant Type Apart
|
|
687
|
+
|
|
688
|
+
### Design Philosophy
|
|
689
|
+
|
|
690
|
+
- **Developer-Centric**: Built around familiar TypeScript patterns and conventions
|
|
691
|
+
- **Interface Syntax**: Schema definitions that feel like native TypeScript interfaces
|
|
692
|
+
- **Conditional Intelligence**: Advanced runtime validation based on dynamic properties
|
|
693
|
+
- **Performance Focused**: Optimized for high-throughput production applications
|
|
694
|
+
- **Tooling Excellence**: Professional-grade development tools and IDE integration
|
|
695
|
+
- **Type Safety**: Complete TypeScript inference and compile-time validation
|
|
696
|
+
|
|
697
|
+
### Key Strengths
|
|
698
|
+
|
|
699
|
+
- **Familiar Syntax**: Write schemas using TypeScript-like interface definitions
|
|
700
|
+
- **Advanced Conditionals**: Unique runtime property validation and business logic
|
|
701
|
+
- **Rich Tooling**: Dedicated VS Code extension with comprehensive development support
|
|
702
|
+
- **Type Integration**: Seamless TypeScript integration with full type inference
|
|
703
|
+
- **Production Ready**: Battle-tested with comprehensive error handling and debugging
|
|
704
|
+
|
|
705
|
+
### Community and Growth
|
|
706
|
+
|
|
707
|
+
We're building Reliant Type with transparency and community feedback at its core. We welcome:
|
|
708
|
+
|
|
709
|
+
- **Real-world usage feedback** and performance insights
|
|
710
|
+
- **Issue reports** with detailed reproduction cases
|
|
711
|
+
- **Feature requests** based on practical development needs
|
|
712
|
+
- **Performance benchmarking** on diverse use cases
|
|
713
|
+
- **Constructive feedback** on API design and developer experience
|
|
714
|
+
|
|
715
|
+
## API Reference
|
|
716
|
+
|
|
717
|
+
### Core Validation Methods
|
|
718
|
+
|
|
719
|
+
#### `Interface(schema, options?)`
|
|
720
|
+
|
|
721
|
+
Creates a new schema instance with comprehensive validation rules.
|
|
722
|
+
|
|
723
|
+
```typescript
|
|
724
|
+
const UserSchema = Interface(
|
|
725
|
+
{
|
|
726
|
+
id: "uuid",
|
|
727
|
+
name: "string",
|
|
728
|
+
},
|
|
729
|
+
{
|
|
730
|
+
strict: true, // Reject extra properties
|
|
731
|
+
loose: false, // Disable automatic type coercion
|
|
732
|
+
allowUnknown: false, // Reject unknown properties
|
|
733
|
+
}
|
|
734
|
+
);
|
|
735
|
+
```
|
|
736
|
+
|
|
737
|
+
#### `schema.parse(data)`
|
|
738
|
+
|
|
739
|
+
Synchronous validation that returns validated data or throws detailed errors.
|
|
740
|
+
|
|
741
|
+
```typescript
|
|
742
|
+
try {
|
|
743
|
+
const user = UserSchema.parse(userData);
|
|
744
|
+
// user is fully typed and validated
|
|
745
|
+
} catch (error) {
|
|
746
|
+
console.error(error.errors);
|
|
747
|
+
}
|
|
748
|
+
```
|
|
749
|
+
|
|
750
|
+
#### `schema.safeParse(data)`
|
|
751
|
+
|
|
752
|
+
Safe validation that returns a result object without throwing exceptions.
|
|
753
|
+
|
|
754
|
+
```typescript
|
|
755
|
+
const result = UserSchema.safeParse(userData);
|
|
756
|
+
if (result.success) {
|
|
757
|
+
console.log(result.data); // Fully typed and validated
|
|
758
|
+
} else {
|
|
759
|
+
console.error(result.errors); // Detailed validation errors
|
|
760
|
+
}
|
|
761
|
+
```
|
|
762
|
+
|
|
763
|
+
#### `schema.safeParseUnknown(data)`
|
|
764
|
+
|
|
765
|
+
Safe validation for unknown data types, ideal for testing and debugging.
|
|
766
|
+
|
|
767
|
+
```typescript
|
|
768
|
+
const result = UserSchema.safeParseUnknown(unknownData);
|
|
769
|
+
// Same return type as safeParse() but accepts any input type
|
|
770
|
+
```
|
|
771
|
+
|
|
772
|
+
#### `schema.parseAsync(data)`
|
|
773
|
+
|
|
774
|
+
Asynchronous validation with promise-based error handling.
|
|
775
|
+
|
|
776
|
+
```typescript
|
|
777
|
+
try {
|
|
778
|
+
const user = await UserSchema.parseAsync(userData);
|
|
779
|
+
console.log("Valid user:", user);
|
|
780
|
+
} catch (error) {
|
|
781
|
+
console.error("Validation failed:", error.message);
|
|
782
|
+
}
|
|
783
|
+
```
|
|
784
|
+
|
|
785
|
+
#### `schema.safeParseAsync(data)`
|
|
786
|
+
|
|
787
|
+
Asynchronous safe validation that never throws exceptions.
|
|
788
|
+
|
|
789
|
+
```typescript
|
|
790
|
+
const result = await UserSchema.safeParseAsync(userData);
|
|
791
|
+
if (result.success) {
|
|
792
|
+
console.log("Valid user:", result.data);
|
|
793
|
+
} else {
|
|
794
|
+
console.error("Validation errors:", result.errors);
|
|
795
|
+
}
|
|
796
|
+
```
|
|
797
|
+
|
|
798
|
+
#### `schema.safeParseUnknownAsync(data)`
|
|
799
|
+
|
|
800
|
+
Asynchronous safe validation for unknown data types.
|
|
801
|
+
|
|
802
|
+
```typescript
|
|
803
|
+
const result = await UserSchema.safeParseUnknownAsync(unknownData);
|
|
804
|
+
if (result.success) {
|
|
805
|
+
console.log("Valid data:", result.data);
|
|
806
|
+
} else {
|
|
807
|
+
console.error("Validation errors:", result.errors);
|
|
808
|
+
}
|
|
809
|
+
```
|
|
810
|
+
|
|
811
|
+
### Schema Transformation Operations
|
|
812
|
+
|
|
813
|
+
#### `Mod.partial(schema)` - Optional Fields
|
|
814
|
+
|
|
815
|
+
```typescript
|
|
816
|
+
const PartialUserSchema = Mod.partial(UserSchema);
|
|
817
|
+
// Converts all fields to optional
|
|
818
|
+
```
|
|
819
|
+
|
|
820
|
+
#### `Mod.required(schema)` - Required Fields
|
|
821
|
+
|
|
822
|
+
```typescript
|
|
823
|
+
const RequiredUserSchema = Mod.required(PartialUserSchema);
|
|
824
|
+
// Makes all fields required
|
|
825
|
+
```
|
|
826
|
+
|
|
827
|
+
#### `Mod.pick(schema, keys)` - Field Selection
|
|
828
|
+
|
|
829
|
+
```typescript
|
|
830
|
+
const PublicUserSchema = Mod.pick(UserSchema, ["id", "name", "email"]);
|
|
831
|
+
// Creates schema with only specified fields
|
|
832
|
+
```
|
|
833
|
+
|
|
834
|
+
#### `Mod.omit(schema, keys)` - Field Exclusion
|
|
835
|
+
|
|
836
|
+
```typescript
|
|
837
|
+
const SafeUserSchema = Mod.omit(UserSchema, ["password", "internalId"]);
|
|
838
|
+
// Creates schema excluding specified fields
|
|
839
|
+
```
|
|
840
|
+
|
|
841
|
+
#### `Mod.extend(schema, extension)` - Schema Extension
|
|
842
|
+
|
|
843
|
+
```typescript
|
|
844
|
+
const ExtendedUserSchema = Mod.extend(UserSchema, {
|
|
845
|
+
lastLogin: "date?",
|
|
846
|
+
preferences: {
|
|
847
|
+
theme: "light|dark",
|
|
848
|
+
},
|
|
849
|
+
});
|
|
850
|
+
```
|
|
851
|
+
|
|
852
|
+
#### `Mod.merge(schema1, schema2)` - Schema Merging
|
|
853
|
+
|
|
854
|
+
```typescript
|
|
855
|
+
const CombinedSchema = Mod.merge(UserSchema, ProfileSchema);
|
|
856
|
+
// Combines two schemas into one
|
|
857
|
+
```
|
|
858
|
+
|
|
859
|
+
### Available Extensions
|
|
860
|
+
|
|
861
|
+
ReliantType provides powerful extensions for enhanced functionality:
|
|
862
|
+
|
|
863
|
+
```typescript
|
|
864
|
+
// Import extensions for advanced features
|
|
865
|
+
export {
|
|
866
|
+
Smart, // Smart schema inference from samples and TypeScript types
|
|
867
|
+
When, // Advanced conditional validation builder
|
|
868
|
+
Live, // Real-time validation for forms and streaming data
|
|
869
|
+
Docs, // Auto-documentation generation (OpenAPI, TypeScript, etc.)
|
|
870
|
+
Extensions, // Extension utilities and helpers
|
|
871
|
+
Quick, // Quick access utilities for common operations
|
|
872
|
+
TypeScriptGenerator, // TypeScript code generation from schemas
|
|
873
|
+
} from "reliant-type";
|
|
874
|
+
```
|
|
875
|
+
|
|
876
|
+
#### Smart Inference
|
|
877
|
+
|
|
878
|
+
```typescript
|
|
879
|
+
import { Smart } from "reliant-type";
|
|
880
|
+
|
|
881
|
+
// Infer schema from sample data
|
|
882
|
+
const sampleUser = {
|
|
883
|
+
id: 1,
|
|
884
|
+
email: "user@example.com",
|
|
885
|
+
name: "John Doe",
|
|
886
|
+
tags: ["developer", "typescript"],
|
|
887
|
+
};
|
|
888
|
+
|
|
889
|
+
const UserSchema = Smart.fromSample(sampleUser);
|
|
890
|
+
// Generates: { id: "positive", email: "email", name: "string", tags: "string[]" }
|
|
891
|
+
```
|
|
892
|
+
|
|
893
|
+
#### Conditional Builder
|
|
894
|
+
|
|
895
|
+
```typescript
|
|
896
|
+
import { When } from "reliant-type";
|
|
897
|
+
|
|
898
|
+
const OrderSchema = Interface({
|
|
899
|
+
orderType: "pickup|delivery",
|
|
900
|
+
address: "string?",
|
|
901
|
+
|
|
902
|
+
// Advanced conditional validation
|
|
903
|
+
deliveryFee: When.field("orderType")
|
|
904
|
+
.is("delivery")
|
|
905
|
+
.then("number(0,)")
|
|
906
|
+
.default("number?"),
|
|
907
|
+
});
|
|
908
|
+
```
|
|
909
|
+
|
|
910
|
+
#### Real-time Validation with Live Utility
|
|
911
|
+
|
|
912
|
+
The Live utility provides comprehensive real-time validation with full EventEmitter-like interface, data transformation pipelines, and stream control methods. Perfect for forms, streaming data, and reactive applications.
|
|
913
|
+
|
|
914
|
+
```typescript
|
|
915
|
+
import { Live } from "reliant-type";
|
|
916
|
+
|
|
917
|
+
const UserSchema = Interface({
|
|
918
|
+
id: "number",
|
|
919
|
+
name: "string(2,50)",
|
|
920
|
+
email: "email",
|
|
921
|
+
age: "number(18,120)",
|
|
922
|
+
});
|
|
923
|
+
```
|
|
924
|
+
|
|
925
|
+
##### Live Validator - Real-time Field Validation
|
|
926
|
+
|
|
927
|
+
```typescript
|
|
928
|
+
// Create live validator for real-time field validation
|
|
929
|
+
const liveValidator = Live.validator(UserSchema);
|
|
930
|
+
|
|
931
|
+
// Listen for validation changes
|
|
932
|
+
liveValidator.onValidation((result) => {
|
|
933
|
+
console.log("Validation result:", result.isValid);
|
|
934
|
+
console.log("Current errors:", result.errors);
|
|
935
|
+
updateUI(result);
|
|
936
|
+
});
|
|
937
|
+
|
|
938
|
+
// Validate fields in real-time
|
|
939
|
+
liveValidator.validateField("email", "user@example.com");
|
|
940
|
+
liveValidator.validateField("name", "John Doe");
|
|
941
|
+
|
|
942
|
+
// Get current validation state
|
|
943
|
+
console.log("Is valid:", liveValidator.isValid);
|
|
944
|
+
console.log("All errors:", liveValidator.errors);
|
|
945
|
+
|
|
946
|
+
// Validate entire object
|
|
947
|
+
const fullResult = liveValidator.validateAll(userData);
|
|
948
|
+
```
|
|
949
|
+
|
|
950
|
+
##### Stream Validator - Advanced Stream Processing
|
|
951
|
+
|
|
952
|
+
The StreamValidator provides a complete EventEmitter-like interface with all standard stream methods:
|
|
953
|
+
|
|
954
|
+
```typescript
|
|
955
|
+
// Create stream validator
|
|
956
|
+
const streamValidator = Live.stream(UserSchema);
|
|
957
|
+
|
|
958
|
+
// ===== EVENT EMITTER METHODS =====
|
|
959
|
+
|
|
960
|
+
// Generic event listeners (.on, .once, .off, .emit)
|
|
961
|
+
streamValidator.on("valid", (data) => {
|
|
962
|
+
console.log("Valid data received:", data);
|
|
963
|
+
});
|
|
964
|
+
|
|
965
|
+
streamValidator.once("invalid", (data, errors) => {
|
|
966
|
+
console.log("First invalid data:", errors);
|
|
967
|
+
});
|
|
968
|
+
|
|
969
|
+
streamValidator.on("error", (error) => {
|
|
970
|
+
console.error("Stream error:", error);
|
|
971
|
+
});
|
|
972
|
+
|
|
973
|
+
// Custom events
|
|
974
|
+
streamValidator.on("custom-event", (message) => {
|
|
975
|
+
console.log("Custom event:", message);
|
|
976
|
+
});
|
|
977
|
+
|
|
978
|
+
streamValidator.emit("custom-event", "Hello from stream!");
|
|
979
|
+
|
|
980
|
+
// Remove listeners
|
|
981
|
+
streamValidator.off("valid", specificListener);
|
|
982
|
+
streamValidator.off("invalid"); // Remove all listeners for event
|
|
983
|
+
```
|
|
984
|
+
|
|
985
|
+
##### Data Transformation Pipeline
|
|
986
|
+
|
|
987
|
+
```typescript
|
|
988
|
+
// Build comprehensive data transformation pipeline
|
|
989
|
+
const transformValidator = Live.stream(UserSchema)
|
|
990
|
+
.transform((data) => {
|
|
991
|
+
// Add metadata
|
|
992
|
+
return { ...data, timestamp: Date.now(), source: "api" };
|
|
993
|
+
})
|
|
994
|
+
.filter((data) => {
|
|
995
|
+
// Filter by business rules
|
|
996
|
+
return data.age >= 21; // Only adults
|
|
997
|
+
})
|
|
998
|
+
.map((data) => {
|
|
999
|
+
// Transform data format
|
|
1000
|
+
return {
|
|
1001
|
+
...data,
|
|
1002
|
+
name: data.name.toUpperCase(),
|
|
1003
|
+
email: data.email.toLowerCase(),
|
|
1004
|
+
};
|
|
1005
|
+
});
|
|
1006
|
+
|
|
1007
|
+
// Listen for pipeline results
|
|
1008
|
+
transformValidator.on("valid", (data) => {
|
|
1009
|
+
console.log("Processed data:", data); // Transformed and validated
|
|
1010
|
+
});
|
|
1011
|
+
|
|
1012
|
+
transformValidator.on("filtered", (data) => {
|
|
1013
|
+
console.log("Data filtered out:", data); // Failed filter conditions
|
|
1014
|
+
});
|
|
1015
|
+
|
|
1016
|
+
transformValidator.on("invalid", (data, errors) => {
|
|
1017
|
+
console.log("Validation failed after transformation:", errors);
|
|
1018
|
+
});
|
|
1019
|
+
|
|
1020
|
+
// Process data through pipeline
|
|
1021
|
+
transformValidator.validate(rawUserData);
|
|
1022
|
+
```
|
|
1023
|
+
|
|
1024
|
+
##### Stream Control Methods
|
|
1025
|
+
|
|
1026
|
+
```typescript
|
|
1027
|
+
// Stream control with pause/resume/destroy
|
|
1028
|
+
const controlValidator = Live.stream(UserSchema);
|
|
1029
|
+
|
|
1030
|
+
// Pause stream (queues incoming data)
|
|
1031
|
+
controlValidator.pause();
|
|
1032
|
+
console.log("Stream paused:", controlValidator.paused);
|
|
1033
|
+
|
|
1034
|
+
// Data sent while paused gets queued
|
|
1035
|
+
controlValidator.validate(userData1); // Queued
|
|
1036
|
+
controlValidator.validate(userData2); // Queued
|
|
1037
|
+
|
|
1038
|
+
console.log("Queue length:", controlValidator.queueLength);
|
|
1039
|
+
|
|
1040
|
+
// Resume stream (processes queued data)
|
|
1041
|
+
controlValidator.resume();
|
|
1042
|
+
console.log("Stream resumed, queue processed");
|
|
1043
|
+
|
|
1044
|
+
// Destroy stream (cleanup and prevent further use)
|
|
1045
|
+
controlValidator.on("destroy", () => {
|
|
1046
|
+
console.log("Stream destroyed and cleaned up");
|
|
1047
|
+
});
|
|
1048
|
+
|
|
1049
|
+
controlValidator.destroy();
|
|
1050
|
+
console.log("Stream destroyed:", controlValidator.destroyed);
|
|
1051
|
+
```
|
|
1052
|
+
|
|
1053
|
+
##### Stream Piping
|
|
1054
|
+
|
|
1055
|
+
```typescript
|
|
1056
|
+
// Pipe data between stream validators
|
|
1057
|
+
const sourceValidator = Live.stream(InputSchema);
|
|
1058
|
+
const destinationValidator = Live.stream(OutputSchema);
|
|
1059
|
+
|
|
1060
|
+
// Pipe valid data from source to destination
|
|
1061
|
+
sourceValidator.pipe(destinationValidator);
|
|
1062
|
+
|
|
1063
|
+
// Data flows: source → destination
|
|
1064
|
+
sourceValidator.validate(inputData);
|
|
1065
|
+
// If valid, automatically sent to destinationValidator
|
|
1066
|
+
|
|
1067
|
+
// Chain multiple streams
|
|
1068
|
+
const pipeline = sourceValidator
|
|
1069
|
+
.pipe(transformValidator)
|
|
1070
|
+
.pipe(destinationValidator);
|
|
1071
|
+
```
|
|
1072
|
+
|
|
1073
|
+
##### Form Validator - Advanced Form Integration
|
|
1074
|
+
|
|
1075
|
+
```typescript
|
|
1076
|
+
// Create form validator with field binding
|
|
1077
|
+
const formValidator = Live.form(UserSchema);
|
|
1078
|
+
|
|
1079
|
+
// Bind form fields to validator
|
|
1080
|
+
formValidator.bindField("email", emailInput);
|
|
1081
|
+
formValidator.bindField("name", nameInput);
|
|
1082
|
+
formValidator.bindField("age", ageInput);
|
|
1083
|
+
|
|
1084
|
+
// Enable automatic validation on input changes
|
|
1085
|
+
formValidator.enableAutoValidation();
|
|
1086
|
+
|
|
1087
|
+
// Handle form submission
|
|
1088
|
+
formValidator.onSubmit((isValid, data, errors) => {
|
|
1089
|
+
if (isValid) {
|
|
1090
|
+
console.log("Form is valid, submitting:", data);
|
|
1091
|
+
submitToAPI(data);
|
|
1092
|
+
} else {
|
|
1093
|
+
console.log("Form has errors:", errors);
|
|
1094
|
+
displayErrors(errors);
|
|
1095
|
+
}
|
|
1096
|
+
});
|
|
1097
|
+
|
|
1098
|
+
// Manual form validation
|
|
1099
|
+
const formResult = formValidator.validateForm();
|
|
1100
|
+
console.log("Form valid:", formResult.isValid);
|
|
1101
|
+
```
|
|
1102
|
+
|
|
1103
|
+
##### Advanced Event Handling
|
|
1104
|
+
|
|
1105
|
+
```typescript
|
|
1106
|
+
const streamValidator = Live.stream(UserSchema);
|
|
1107
|
+
|
|
1108
|
+
// Listen for all validation events
|
|
1109
|
+
streamValidator.on("data", (data) => {
|
|
1110
|
+
console.log("Data received for validation:", data);
|
|
1111
|
+
});
|
|
1112
|
+
|
|
1113
|
+
streamValidator.on("validated", (data, result) => {
|
|
1114
|
+
console.log("Validation completed:", result.isValid);
|
|
1115
|
+
});
|
|
1116
|
+
|
|
1117
|
+
streamValidator.on("queued", (data) => {
|
|
1118
|
+
console.log("Data queued (stream paused):", data);
|
|
1119
|
+
});
|
|
1120
|
+
|
|
1121
|
+
streamValidator.on("pause", () => {
|
|
1122
|
+
console.log("Stream paused");
|
|
1123
|
+
});
|
|
1124
|
+
|
|
1125
|
+
streamValidator.on("resume", () => {
|
|
1126
|
+
console.log("Stream resumed");
|
|
1127
|
+
});
|
|
1128
|
+
|
|
1129
|
+
// Error handling
|
|
1130
|
+
streamValidator.on("error", (error) => {
|
|
1131
|
+
console.error("Stream error:", error.message);
|
|
1132
|
+
// Handle gracefully without crashing
|
|
1133
|
+
});
|
|
1134
|
+
```
|
|
1135
|
+
|
|
1136
|
+
##### Performance and Statistics
|
|
1137
|
+
|
|
1138
|
+
```typescript
|
|
1139
|
+
// Monitor stream performance
|
|
1140
|
+
streamValidator.onStats((stats) => {
|
|
1141
|
+
console.log("Validation Statistics:");
|
|
1142
|
+
console.log(`- Total validated: ${stats.totalValidated}`);
|
|
1143
|
+
console.log(`- Valid count: ${stats.validCount}`);
|
|
1144
|
+
console.log(`- Invalid count: ${stats.invalidCount}`);
|
|
1145
|
+
console.log(`- Error rate: ${(stats.errorRate * 100).toFixed(2)}%`);
|
|
1146
|
+
console.log(`- Running since: ${stats.startTime}`);
|
|
1147
|
+
});
|
|
1148
|
+
|
|
1149
|
+
// Get current statistics
|
|
1150
|
+
const currentStats = streamValidator.getStats();
|
|
1151
|
+
console.log("Current performance:", currentStats);
|
|
1152
|
+
```
|
|
1153
|
+
|
|
1154
|
+
##### Integration with InterfaceSchema
|
|
1155
|
+
|
|
1156
|
+
The Live utility is fully synchronized with InterfaceSchema modules, ensuring consistent validation behavior:
|
|
1157
|
+
|
|
1158
|
+
```typescript
|
|
1159
|
+
const schema = Interface({
|
|
1160
|
+
email: "email",
|
|
1161
|
+
age: "number(18,120)",
|
|
1162
|
+
role: "admin|user|guest",
|
|
1163
|
+
});
|
|
1164
|
+
|
|
1165
|
+
// Both produce identical validation results
|
|
1166
|
+
const interfaceResult = schema.safeParse(userData);
|
|
1167
|
+
const liveResult = Live.stream(schema).validate(userData);
|
|
1168
|
+
|
|
1169
|
+
// Perfect synchronization guaranteed
|
|
1170
|
+
console.log("Results match:", interfaceResult.success === liveResult.isValid);
|
|
1171
|
+
```
|
|
1172
|
+
|
|
1173
|
+
#### Documentation Generation
|
|
1174
|
+
|
|
1175
|
+
```typescript
|
|
1176
|
+
import { Docs } from "reliant-type"; //in beta
|
|
1177
|
+
|
|
1178
|
+
// Generate OpenAPI specification
|
|
1179
|
+
const openApiSpec = Docs.openapi(UserSchema, {
|
|
1180
|
+
title: "User API",
|
|
1181
|
+
version: "1.0.0",
|
|
1182
|
+
servers: ["https://api.example.com"],
|
|
1183
|
+
});
|
|
1184
|
+
|
|
1185
|
+
// Generate TypeScript definitions
|
|
1186
|
+
const typeDefinitions = Docs.typescript(UserSchema, {
|
|
1187
|
+
exportName: "User",
|
|
1188
|
+
namespace: "API",
|
|
1189
|
+
});
|
|
1190
|
+
```
|
|
1191
|
+
|
|
1192
|
+
#### Quick Utilities
|
|
1193
|
+
|
|
1194
|
+
```typescript
|
|
1195
|
+
import { Quick } from "reliant-type";
|
|
1196
|
+
|
|
1197
|
+
// Quick schema inference
|
|
1198
|
+
const schema = Quick.fromSample(sampleData);
|
|
1199
|
+
|
|
1200
|
+
// Quick conditional validation
|
|
1201
|
+
const conditionalField = Quick.when("status").is("active").then("string");
|
|
1202
|
+
|
|
1203
|
+
// Quick documentation
|
|
1204
|
+
const docs = Quick.docs(schema);
|
|
1205
|
+
const typescript = Quick.typescript(schema);
|
|
1206
|
+
```
|
|
1207
|
+
|
|
1208
|
+
### Validation Configuration
|
|
1209
|
+
|
|
1210
|
+
#### Method Chaining
|
|
1211
|
+
|
|
1212
|
+
```typescript
|
|
1213
|
+
const FlexibleSchema = UserSchema.loose() // Enable automatic type coercion
|
|
1214
|
+
.allowUnknown() // Accept extra properties
|
|
1215
|
+
.min(1) // Set minimum constraints
|
|
1216
|
+
.max(100) // Set maximum constraints
|
|
1217
|
+
.unique() // Require unique array values
|
|
1218
|
+
.pattern(/^[A-Z]/) // Apply regex pattern validation
|
|
1219
|
+
.default("N/A"); // Set default value
|
|
1220
|
+
```
|
|
1221
|
+
|
|
1222
|
+
## Contributing
|
|
1223
|
+
|
|
1224
|
+
By contributing to ReliantType, you help reliant-type to:
|
|
1225
|
+
|
|
1226
|
+
- Improve the quality of TypeScript validation
|
|
1227
|
+
- Expand the reach of TypeScript in the JavaScript ecosystem
|
|
1228
|
+
- Provide a robust and reliable validation solution for developers
|
|
1229
|
+
- Foster a community of developers who care about code quality and security
|
|
1230
|
+
|
|
1231
|
+
### Development Environment
|
|
1232
|
+
|
|
1233
|
+
```bash
|
|
1234
|
+
# Repository setup
|
|
1235
|
+
git clone https://github.com/Nehonix-Team/reliant-type.git
|
|
1236
|
+
cd reliant-type
|
|
1237
|
+
|
|
1238
|
+
# Dependency installation
|
|
1239
|
+
npm install
|
|
1240
|
+
|
|
1241
|
+
# Test suite execution
|
|
1242
|
+
npm run test
|
|
1243
|
+
|
|
1244
|
+
# Performance benchmarking
|
|
1245
|
+
npm run benchmark
|
|
1246
|
+
|
|
1247
|
+
# Project build
|
|
1248
|
+
npm run build
|
|
1249
|
+
```
|
|
1250
|
+
|
|
1251
|
+
### Quality Standards
|
|
1252
|
+
|
|
1253
|
+
- **TypeScript**: Strict mode with comprehensive type checking
|
|
1254
|
+
- **Test Coverage**: 95%+ coverage requirement
|
|
1255
|
+
- **Performance**: All benchmarks must pass performance thresholds
|
|
1256
|
+
- **Documentation**: Complete JSDoc comments for all public APIs
|
|
1257
|
+
- **Code Quality**: ESLint and Prettier configuration compliance
|
|
1258
|
+
|
|
1259
|
+
### Contribution Process
|
|
1260
|
+
|
|
1261
|
+
1. **Fork** the repository on GitHub
|
|
1262
|
+
2. **Create** a feature branch: `git checkout -b feature/enhancement-name`
|
|
1263
|
+
3. **Implement** changes with comprehensive test coverage
|
|
1264
|
+
4. **Verify** all tests pass: `npm test`
|
|
1265
|
+
5. **Validate** performance: `npm run benchmark`
|
|
1266
|
+
6. **Commit** changes: `git commit -m 'Add enhancement: description'`
|
|
1267
|
+
7. **Push** to branch: `git push origin feature/enhancement-name`
|
|
1268
|
+
8. **Submit** a Pull Request with detailed description
|
|
1269
|
+
|
|
1270
|
+
### Issue Reporting
|
|
1271
|
+
|
|
1272
|
+
For effective issue resolution, please provide:
|
|
1273
|
+
|
|
1274
|
+
- **Environment Details**: Reliant Type, TypeScript, and Node.js versions
|
|
1275
|
+
- **Reproduction Case**: Minimal code example demonstrating the issue
|
|
1276
|
+
- **Expected Behavior**: Clear description of intended functionality
|
|
1277
|
+
- **Actual Behavior**: Detailed explanation of observed behavior
|
|
1278
|
+
- **Error Information**: Complete error messages and stack traces
|
|
1279
|
+
|
|
1280
|
+
## Release History
|
|
1281
|
+
|
|
1282
|
+
See [CHANGELOG.md](./CHANGELOG.md) for comprehensive release notes and migration guides.
|
|
1283
|
+
|
|
1284
|
+
## License
|
|
1285
|
+
|
|
1286
|
+
MIT License - see [LICENSE](./LICENSE) file for complete terms.
|
|
1287
|
+
|
|
1288
|
+
## Support Resources
|
|
1289
|
+
|
|
1290
|
+
- **Complete Documentation**: [Full documentation](./docs/)
|
|
1291
|
+
- **Issue Tracking**: [GitHub Issues](https://github.com/Nehonix-Team/reliant-type/issues)
|
|
1292
|
+
- **Community Discussions**: [GitHub Discussions](https://github.com/Nehonix-Team/reliant-type/discussions)
|
|
1293
|
+
|
|
1294
|
+
---
|
|
1295
|
+
|
|
1296
|
+
**Development Status**: Reliant Type is in active development with a focus on production readiness. We maintain transparency about capabilities and limitations while continuously improving based on community feedback and real-world usage patterns.
|
|
1297
|
+
|
|
1298
|
+
<div align="center">
|
|
1299
|
+
<p><strong>Built by Nehonix</strong></p>
|
|
1300
|
+
<p>
|
|
1301
|
+
<a href="https://nehonix.space">Website</a> •
|
|
1302
|
+
<a href="https://sdk.nehonix.space">SDK</a> •
|
|
1303
|
+
<a href="https://github.com/Nehonix-Team">GitHub</a>
|
|
1304
|
+
</p>
|
|
1305
|
+
</div>
|