@nestia/sdk 14.0.0 → 14.0.2
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/README.md +1 -1
- package/assets/bundle/distribute/build-sdk.cjs +28 -0
- package/assets/bundle/distribute/package.json +7 -3
- package/assets/bundle/distribute/tsconfig.json +15 -105
- package/lib/INestiaConfig.d.ts +74 -34
- package/lib/NestiaSdkApplication.d.ts +60 -0
- package/lib/NestiaSdkApplication.js +121 -32
- package/lib/NestiaSdkApplication.js.map +1 -1
- package/lib/NestiaSwaggerComposer.d.ts +21 -0
- package/lib/NestiaSwaggerComposer.js +32 -13
- package/lib/NestiaSwaggerComposer.js.map +1 -1
- package/lib/analyses/AccessorAnalyzer.d.ts +26 -0
- package/lib/analyses/AccessorAnalyzer.js +26 -0
- package/lib/analyses/AccessorAnalyzer.js.map +1 -1
- package/lib/analyses/ConfigAnalyzer.d.ts +41 -0
- package/lib/analyses/ConfigAnalyzer.js +52 -77
- package/lib/analyses/ConfigAnalyzer.js.map +1 -1
- package/lib/analyses/ImportAnalyzer.d.ts +25 -0
- package/lib/analyses/ImportAnalyzer.js +25 -0
- package/lib/analyses/ImportAnalyzer.js.map +1 -1
- package/lib/analyses/ParameterNameAnalyzer.d.ts +44 -0
- package/lib/analyses/ParameterNameAnalyzer.js +63 -0
- package/lib/analyses/ParameterNameAnalyzer.js.map +1 -0
- package/lib/analyses/PathAnalyzer.d.ts +93 -1
- package/lib/analyses/PathAnalyzer.js +160 -23
- package/lib/analyses/PathAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectControllerAnalyzer.d.ts +32 -0
- package/lib/analyses/ReflectControllerAnalyzer.js +24 -1
- package/lib/analyses/ReflectControllerAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectHttpOperationAnalyzer.d.ts +29 -0
- package/lib/analyses/ReflectHttpOperationAnalyzer.js +35 -24
- package/lib/analyses/ReflectHttpOperationAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectHttpOperationExceptionAnalyzer.d.ts +31 -0
- package/lib/analyses/ReflectHttpOperationExceptionAnalyzer.js +21 -0
- package/lib/analyses/ReflectHttpOperationExceptionAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectHttpOperationParameterAnalyzer.d.ts +31 -0
- package/lib/analyses/ReflectHttpOperationParameterAnalyzer.js +143 -23
- package/lib/analyses/ReflectHttpOperationParameterAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectHttpOperationResponseAnalyzer.d.ts +32 -0
- package/lib/analyses/ReflectHttpOperationResponseAnalyzer.js +27 -2
- package/lib/analyses/ReflectHttpOperationResponseAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectMcpOperationAnalyzer.d.ts +29 -0
- package/lib/analyses/ReflectMcpOperationAnalyzer.js +35 -11
- package/lib/analyses/ReflectMcpOperationAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectMetadataAnalyzer.d.ts +47 -0
- package/lib/analyses/ReflectMetadataAnalyzer.js +47 -0
- package/lib/analyses/ReflectMetadataAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectWebSocketOperationAnalyzer.d.ts +29 -0
- package/lib/analyses/ReflectWebSocketOperationAnalyzer.js +27 -5
- package/lib/analyses/ReflectWebSocketOperationAnalyzer.js.map +1 -1
- package/lib/analyses/SecurityAnalyzer.d.ts +25 -0
- package/lib/analyses/SecurityAnalyzer.js +39 -19
- package/lib/analyses/SecurityAnalyzer.js.map +1 -1
- package/lib/analyses/SwaggerExampleAnalyzer.d.ts +31 -0
- package/lib/analyses/SwaggerExampleAnalyzer.js +36 -0
- package/lib/analyses/SwaggerExampleAnalyzer.js.map +1 -0
- package/lib/analyses/TypedHttpRouteAnalyzer.d.ts +41 -3
- package/lib/analyses/TypedHttpRouteAnalyzer.js +196 -172
- package/lib/analyses/TypedHttpRouteAnalyzer.js.map +1 -1
- package/lib/analyses/TypedMcpRouteAnalyzer.d.ts +29 -0
- package/lib/analyses/TypedMcpRouteAnalyzer.js +152 -20
- package/lib/analyses/TypedMcpRouteAnalyzer.js.map +1 -1
- package/lib/analyses/TypedWebSocketRouteAnalyzer.d.ts +19 -0
- package/lib/analyses/TypedWebSocketRouteAnalyzer.js +20 -1
- package/lib/analyses/TypedWebSocketRouteAnalyzer.js.map +1 -1
- package/lib/decorators/OperationMetadata.d.ts +6 -0
- package/lib/decorators/OperationMetadata.js +6 -0
- package/lib/decorators/OperationMetadata.js.map +1 -1
- package/lib/executable/internal/CommandParser.d.ts +19 -0
- package/lib/executable/internal/CommandParser.js +19 -0
- package/lib/executable/internal/CommandParser.js.map +1 -1
- package/lib/executable/internal/NestiaConfigLoader.d.ts +56 -0
- package/lib/executable/internal/NestiaConfigLoader.js +48 -42
- package/lib/executable/internal/NestiaConfigLoader.js.map +1 -1
- package/lib/executable/internal/NestiaSdkCommand.d.ts +60 -0
- package/lib/executable/internal/NestiaSdkCommand.js +95 -3
- package/lib/executable/internal/NestiaSdkCommand.js.map +1 -1
- package/lib/executable/internal/NestiaSdkWatcher.d.ts +81 -0
- package/lib/executable/internal/NestiaSdkWatcher.js +125 -41
- package/lib/executable/internal/NestiaSdkWatcher.js.map +1 -1
- package/lib/executable/internal/NestiaSwaggerWatch.d.ts +80 -0
- package/lib/executable/internal/NestiaSwaggerWatch.js +308 -0
- package/lib/executable/internal/NestiaSwaggerWatch.js.map +1 -0
- package/lib/executable/sdk.js +16 -1
- package/lib/executable/sdk.js.map +1 -1
- package/lib/factories/ExpressionFactory.d.ts +18 -0
- package/lib/factories/ExpressionFactory.js +21 -2
- package/lib/factories/ExpressionFactory.js.map +1 -1
- package/lib/factories/IdentifierFactory.d.ts +24 -0
- package/lib/factories/IdentifierFactory.js +24 -0
- package/lib/factories/IdentifierFactory.js.map +1 -1
- package/lib/factories/LiteralFactory.d.ts +22 -4
- package/lib/factories/LiteralFactory.js +33 -11
- package/lib/factories/LiteralFactory.js.map +1 -1
- package/lib/factories/StatementFactory.d.ts +28 -1
- package/lib/factories/StatementFactory.js +28 -1
- package/lib/factories/StatementFactory.js.map +1 -1
- package/lib/factories/TypeFactory.d.ts +24 -0
- package/lib/factories/TypeFactory.js +15 -0
- package/lib/factories/TypeFactory.js.map +1 -1
- package/lib/generates/CloneGenerator.d.ts +22 -0
- package/lib/generates/CloneGenerator.js +26 -5
- package/lib/generates/CloneGenerator.js.map +1 -1
- package/lib/generates/E2eGenerator.d.ts +19 -0
- package/lib/generates/E2eGenerator.js +19 -0
- package/lib/generates/E2eGenerator.js.map +1 -1
- package/lib/generates/SdkGenerator.d.ts +38 -0
- package/lib/generates/SdkGenerator.js +43 -5
- package/lib/generates/SdkGenerator.js.map +1 -1
- package/lib/generates/SwaggerGenerator.d.ts +36 -6
- package/lib/generates/SwaggerGenerator.js +190 -40
- package/lib/generates/SwaggerGenerator.js.map +1 -1
- package/lib/generates/internal/E2eFileProgrammer.d.ts +19 -0
- package/lib/generates/internal/E2eFileProgrammer.js +20 -1
- package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
- package/lib/generates/internal/FilePrinter.d.ts +57 -0
- package/lib/generates/internal/FilePrinter.js +74 -0
- package/lib/generates/internal/FilePrinter.js.map +1 -1
- package/lib/generates/internal/ImportDictionary.d.ts +93 -1
- package/lib/generates/internal/ImportDictionary.js +103 -2
- package/lib/generates/internal/ImportDictionary.js.map +1 -1
- package/lib/generates/internal/SdkAliasCollection.d.ts +121 -1
- package/lib/generates/internal/SdkAliasCollection.js +132 -11
- package/lib/generates/internal/SdkAliasCollection.js.map +1 -1
- package/lib/generates/internal/SdkDistributionComposer.d.ts +19 -0
- package/lib/generates/internal/SdkDistributionComposer.js +149 -52
- package/lib/generates/internal/SdkDistributionComposer.js.map +1 -1
- package/lib/generates/internal/SdkFileProgrammer.d.ts +18 -0
- package/lib/generates/internal/SdkFileProgrammer.js +101 -12
- package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpCloneProgrammer.d.ts +29 -0
- package/lib/generates/internal/SdkHttpCloneProgrammer.js +33 -0
- package/lib/generates/internal/SdkHttpCloneProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpCloneReferencer.d.ts +19 -0
- package/lib/generates/internal/SdkHttpCloneReferencer.js +78 -25
- package/lib/generates/internal/SdkHttpCloneReferencer.js.map +1 -1
- package/lib/generates/internal/SdkHttpFunctionProgrammer.d.ts +19 -0
- package/lib/generates/internal/SdkHttpFunctionProgrammer.js +40 -23
- package/lib/generates/internal/SdkHttpFunctionProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpNamespaceProgrammer.d.ts +19 -0
- package/lib/generates/internal/SdkHttpNamespaceProgrammer.js +46 -34
- package/lib/generates/internal/SdkHttpNamespaceProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpParameterProgrammer.d.ts +142 -1
- package/lib/generates/internal/SdkHttpParameterProgrammer.js +175 -6
- package/lib/generates/internal/SdkHttpParameterProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpRouteProgrammer.d.ts +20 -0
- package/lib/generates/internal/SdkHttpRouteProgrammer.js +36 -32
- package/lib/generates/internal/SdkHttpRouteProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpSimulationProgrammer.d.ts +38 -0
- package/lib/generates/internal/SdkHttpSimulationProgrammer.js +66 -18
- package/lib/generates/internal/SdkHttpSimulationProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkImportWizard.d.ts +63 -0
- package/lib/generates/internal/SdkImportWizard.js +63 -0
- package/lib/generates/internal/SdkImportWizard.js.map +1 -1
- package/lib/generates/internal/SdkMcpRouteProgrammer.d.ts +17 -2
- package/lib/generates/internal/SdkMcpRouteProgrammer.js +72 -24
- package/lib/generates/internal/SdkMcpRouteProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkPathTemplate.d.ts +36 -0
- package/lib/generates/internal/SdkPathTemplate.js +65 -0
- package/lib/generates/internal/SdkPathTemplate.js.map +1 -0
- package/lib/generates/internal/SdkRouteDirectory.d.ts +10 -0
- package/lib/generates/internal/SdkRouteDirectory.js +10 -0
- package/lib/generates/internal/SdkRouteDirectory.js.map +1 -1
- package/lib/generates/internal/SdkTypeProgrammer.d.ts +54 -1
- package/lib/generates/internal/SdkTypeProgrammer.js +111 -27
- package/lib/generates/internal/SdkTypeProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkTypeTagProgrammer.d.ts +53 -1
- package/lib/generates/internal/SdkTypeTagProgrammer.js +407 -67
- package/lib/generates/internal/SdkTypeTagProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkWebSocketCloneProgrammer.d.ts +40 -0
- package/lib/generates/internal/SdkWebSocketCloneProgrammer.js +149 -142
- package/lib/generates/internal/SdkWebSocketCloneProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.d.ts +19 -0
- package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js +46 -36
- package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkWebSocketParameterProgrammer.d.ts +114 -1
- package/lib/generates/internal/SdkWebSocketParameterProgrammer.js +120 -5
- package/lib/generates/internal/SdkWebSocketParameterProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkWebSocketRouteProgrammer.d.ts +18 -0
- package/lib/generates/internal/SdkWebSocketRouteProgrammer.js +75 -33
- package/lib/generates/internal/SdkWebSocketRouteProgrammer.js.map +1 -1
- package/lib/generates/internal/SwaggerDescriptionComposer.d.ts +42 -0
- package/lib/generates/internal/SwaggerDescriptionComposer.js +44 -1
- package/lib/generates/internal/SwaggerDescriptionComposer.js.map +1 -1
- package/lib/generates/internal/SwaggerOperationComposer.d.ts +18 -0
- package/lib/generates/internal/SwaggerOperationComposer.js +37 -8
- package/lib/generates/internal/SwaggerOperationComposer.js.map +1 -1
- package/lib/generates/internal/SwaggerOperationParameterComposer.d.ts +40 -1
- package/lib/generates/internal/SwaggerOperationParameterComposer.js +230 -25
- package/lib/generates/internal/SwaggerOperationParameterComposer.js.map +1 -1
- package/lib/generates/internal/SwaggerOperationResponseComposer.d.ts +21 -0
- package/lib/generates/internal/SwaggerOperationResponseComposer.js +58 -7
- package/lib/generates/internal/SwaggerOperationResponseComposer.js.map +1 -1
- package/lib/internal/legacy.d.ts +342 -31
- package/lib/internal/legacy.js +207 -31
- package/lib/internal/legacy.js.map +1 -1
- package/lib/structures/INestiaProject.d.ts +10 -0
- package/lib/structures/INestiaSdkInput.d.ts +30 -0
- package/lib/structures/IOperationMetadata.d.ts +77 -0
- package/lib/structures/IReflectController.d.ts +10 -0
- package/lib/structures/IReflectHttpOperation.d.ts +10 -0
- package/lib/structures/IReflectHttpOperationException.d.ts +13 -2
- package/lib/structures/IReflectHttpOperationParameter.d.ts +55 -3
- package/lib/structures/IReflectHttpOperationSuccess.d.ts +15 -3
- package/lib/structures/IReflectImport.d.ts +10 -0
- package/lib/structures/IReflectMcpOperation.d.ts +19 -0
- package/lib/structures/IReflectMcpOperationParameter.d.ts +9 -0
- package/lib/structures/IReflectOperationError.d.ts +28 -0
- package/lib/structures/IReflectOperationError.js +22 -2
- package/lib/structures/IReflectOperationError.js.map +1 -1
- package/lib/structures/IReflectType.d.ts +9 -0
- package/lib/structures/IReflectWebSocketOperation.d.ts +10 -0
- package/lib/structures/IReflectWebSocketOperationParameter.d.ts +55 -0
- package/lib/structures/ITypedApplication.d.ts +10 -0
- package/lib/structures/ITypedHttpRoute.d.ts +18 -0
- package/lib/structures/ITypedHttpRouteException.d.ts +13 -1
- package/lib/structures/ITypedHttpRouteParameter.d.ts +48 -1
- package/lib/structures/ITypedHttpRouteSuccess.d.ts +13 -1
- package/lib/structures/ITypedMcpRoute.d.ts +11 -0
- package/lib/structures/ITypedWebSocketRoute.d.ts +18 -0
- package/lib/transform.d.ts +6 -0
- package/lib/transform.js +6 -0
- package/lib/transform.js.map +1 -1
- package/lib/utils/ArrayUtil.d.ts +31 -1
- package/lib/utils/ArrayUtil.js +32 -11
- package/lib/utils/ArrayUtil.js.map +1 -1
- package/lib/utils/EmittedJavaScriptPatcher.d.ts +20 -0
- package/lib/utils/EmittedJavaScriptPatcher.js +65 -46
- package/lib/utils/EmittedJavaScriptPatcher.js.map +1 -1
- package/lib/utils/FileRetriever.d.ts +29 -0
- package/lib/utils/FileRetriever.js +29 -0
- package/lib/utils/FileRetriever.js.map +1 -1
- package/lib/utils/HttpResponseContentTypeUtil.d.ts +41 -0
- package/lib/utils/HttpResponseContentTypeUtil.js +31 -0
- package/lib/utils/HttpResponseContentTypeUtil.js.map +1 -1
- package/lib/utils/MapUtil.d.ts +64 -1
- package/lib/utils/MapUtil.js +24 -3
- package/lib/utils/MapUtil.js.map +1 -1
- package/lib/utils/PathUtil.d.ts +31 -0
- package/lib/utils/PathUtil.js +38 -0
- package/lib/utils/PathUtil.js.map +1 -1
- package/lib/utils/SdkBundlePath.d.ts +2 -0
- package/lib/utils/SdkBundlePath.js +10 -0
- package/lib/utils/SdkBundlePath.js.map +1 -0
- package/lib/utils/SdkInputFilter.d.ts +31 -0
- package/lib/utils/SdkInputFilter.js +115 -0
- package/lib/utils/SdkInputFilter.js.map +1 -0
- package/lib/utils/SourceFinder.d.ts +45 -0
- package/lib/utils/SourceFinder.js +74 -16
- package/lib/utils/SourceFinder.js.map +1 -1
- package/lib/utils/StringUtil.d.ts +77 -2
- package/lib/utils/StringUtil.js +166 -4
- package/lib/utils/StringUtil.js.map +1 -1
- package/lib/utils/TemporaryDirectory.d.ts +60 -0
- package/lib/utils/TemporaryDirectory.js +112 -0
- package/lib/utils/TemporaryDirectory.js.map +1 -0
- package/lib/utils/TsConfigReader.d.ts +42 -0
- package/lib/utils/TsConfigReader.js +98 -14
- package/lib/utils/TsConfigReader.js.map +1 -1
- package/lib/utils/TtscExecutor.d.ts +23 -1
- package/lib/utils/TtscExecutor.js +22 -0
- package/lib/utils/TtscExecutor.js.map +1 -1
- package/lib/utils/VersioningStrategy.d.ts +39 -2
- package/lib/utils/VersioningStrategy.js +46 -13
- package/lib/utils/VersioningStrategy.js.map +1 -1
- package/lib/validators/TextPlainValidator.d.ts +19 -0
- package/lib/validators/TextPlainValidator.js +19 -0
- package/lib/validators/TextPlainValidator.js.map +1 -1
- package/native/go.mod +1 -1
- package/native/go.sum +2 -2
- package/native/sdk/register.go +12 -2
- package/native/sdk/sdk_http_rules.go +210 -0
- package/native/sdk/sdk_metadata_json.go +79 -4
- package/native/sdk/sdk_transform.go +1157 -414
- package/package.json +8 -6
- package/src/INestiaConfig.ts +74 -34
- package/src/NestiaSdkApplication.ts +129 -41
- package/src/NestiaSwaggerComposer.ts +32 -14
- package/src/analyses/AccessorAnalyzer.ts +26 -0
- package/src/analyses/ConfigAnalyzer.ts +52 -90
- package/src/analyses/ImportAnalyzer.ts +25 -0
- package/src/analyses/ParameterNameAnalyzer.ts +75 -0
- package/src/analyses/PathAnalyzer.ts +167 -23
- package/src/analyses/ReflectControllerAnalyzer.ts +34 -1
- package/src/analyses/ReflectHttpOperationAnalyzer.ts +36 -14
- package/src/analyses/ReflectHttpOperationExceptionAnalyzer.ts +31 -0
- package/src/analyses/ReflectHttpOperationParameterAnalyzer.ts +153 -39
- package/src/analyses/ReflectHttpOperationResponseAnalyzer.ts +38 -7
- package/src/analyses/ReflectMcpOperationAnalyzer.ts +38 -3
- package/src/analyses/ReflectMetadataAnalyzer.ts +47 -0
- package/src/analyses/ReflectWebSocketOperationAnalyzer.ts +40 -7
- package/src/analyses/SecurityAnalyzer.ts +45 -20
- package/src/analyses/SwaggerExampleAnalyzer.ts +39 -0
- package/src/analyses/TypedHttpRouteAnalyzer.ts +263 -198
- package/src/analyses/TypedMcpRouteAnalyzer.ts +180 -20
- package/src/analyses/TypedWebSocketRouteAnalyzer.ts +20 -0
- package/src/decorators/OperationMetadata.ts +6 -0
- package/src/executable/internal/CommandParser.ts +19 -0
- package/src/executable/internal/NestiaConfigLoader.ts +66 -50
- package/src/executable/internal/NestiaSdkCommand.ts +96 -3
- package/src/executable/internal/NestiaSdkWatcher.ts +172 -44
- package/src/executable/internal/NestiaSwaggerWatch.ts +359 -0
- package/src/executable/sdk.ts +24 -1
- package/src/factories/ExpressionFactory.ts +23 -2
- package/src/factories/IdentifierFactory.ts +24 -0
- package/src/factories/LiteralFactory.ts +51 -13
- package/src/factories/StatementFactory.ts +28 -1
- package/src/factories/TypeFactory.ts +24 -0
- package/src/generates/CloneGenerator.ts +26 -5
- package/src/generates/E2eGenerator.ts +19 -0
- package/src/generates/SdkGenerator.ts +43 -12
- package/src/generates/SwaggerGenerator.ts +229 -46
- package/src/generates/internal/E2eFileProgrammer.ts +20 -0
- package/src/generates/internal/FilePrinter.ts +71 -0
- package/src/generates/internal/ImportDictionary.ts +120 -2
- package/src/generates/internal/SdkAliasCollection.ts +144 -15
- package/src/generates/internal/SdkDistributionComposer.ts +181 -56
- package/src/generates/internal/SdkFileProgrammer.ts +126 -16
- package/src/generates/internal/SdkHttpCloneProgrammer.ts +55 -0
- package/src/generates/internal/SdkHttpCloneReferencer.ts +97 -23
- package/src/generates/internal/SdkHttpFunctionProgrammer.ts +47 -30
- package/src/generates/internal/SdkHttpNamespaceProgrammer.ts +53 -64
- package/src/generates/internal/SdkHttpParameterProgrammer.ts +295 -13
- package/src/generates/internal/SdkHttpRouteProgrammer.ts +37 -31
- package/src/generates/internal/SdkHttpSimulationProgrammer.ts +122 -18
- package/src/generates/internal/SdkImportWizard.ts +63 -0
- package/src/generates/internal/SdkMcpRouteProgrammer.ts +150 -33
- package/src/generates/internal/SdkPathTemplate.ts +88 -0
- package/src/generates/internal/SdkRouteDirectory.ts +10 -0
- package/src/generates/internal/SdkTypeProgrammer.ts +137 -36
- package/src/generates/internal/SdkTypeTagProgrammer.ts +536 -78
- package/src/generates/internal/SdkWebSocketCloneProgrammer.ts +185 -142
- package/src/generates/internal/SdkWebSocketNamespaceProgrammer.ts +62 -68
- package/src/generates/internal/SdkWebSocketParameterProgrammer.ts +205 -5
- package/src/generates/internal/SdkWebSocketRouteProgrammer.ts +89 -48
- package/src/generates/internal/SwaggerDescriptionComposer.ts +47 -1
- package/src/generates/internal/SwaggerOperationComposer.ts +38 -6
- package/src/generates/internal/SwaggerOperationParameterComposer.ts +318 -36
- package/src/generates/internal/SwaggerOperationResponseComposer.ts +74 -11
- package/src/internal/legacy-augmentation.d.ts +16 -0
- package/src/internal/legacy.ts +407 -49
- package/src/structures/INestiaProject.ts +10 -0
- package/src/structures/INestiaSdkInput.ts +30 -0
- package/src/structures/IOperationMetadata.ts +83 -0
- package/src/structures/IReflectController.ts +10 -0
- package/src/structures/IReflectHttpOperation.ts +10 -0
- package/src/structures/IReflectHttpOperationException.ts +17 -2
- package/src/structures/IReflectHttpOperationParameter.ts +56 -2
- package/src/structures/IReflectHttpOperationSuccess.ts +19 -3
- package/src/structures/IReflectImport.ts +10 -0
- package/src/structures/IReflectMcpOperation.ts +19 -0
- package/src/structures/IReflectMcpOperationParameter.ts +9 -0
- package/src/structures/IReflectOperationError.ts +31 -2
- package/src/structures/IReflectType.ts +9 -0
- package/src/structures/IReflectWebSocketOperation.ts +10 -0
- package/src/structures/IReflectWebSocketOperationParameter.ts +55 -0
- package/src/structures/ITypedApplication.ts +10 -0
- package/src/structures/ITypedHttpRoute.ts +18 -0
- package/src/structures/ITypedHttpRouteException.ts +14 -1
- package/src/structures/ITypedHttpRouteParameter.ts +48 -1
- package/src/structures/ITypedHttpRouteSuccess.ts +14 -1
- package/src/structures/ITypedMcpRoute.ts +12 -0
- package/src/structures/ITypedWebSocketRoute.ts +18 -0
- package/src/transform.ts +6 -0
- package/src/utils/ArrayUtil.ts +32 -13
- package/src/utils/EmittedJavaScriptPatcher.ts +70 -47
- package/src/utils/FileRetriever.ts +29 -0
- package/src/utils/HttpResponseContentTypeUtil.ts +41 -0
- package/src/utils/MapUtil.ts +68 -3
- package/src/utils/PathUtil.ts +38 -0
- package/src/utils/SdkBundlePath.ts +11 -0
- package/src/utils/SdkInputFilter.ts +108 -0
- package/src/utils/SourceFinder.ts +76 -18
- package/src/utils/StringUtil.ts +182 -5
- package/src/utils/TemporaryDirectory.ts +108 -0
- package/src/utils/TsConfigReader.ts +124 -26
- package/src/utils/TtscExecutor.ts +23 -1
- package/src/utils/VersioningStrategy.ts +51 -16
- package/src/validators/TextPlainValidator.ts +19 -0
- package/lib/generates/internal/SwaggerReadonlyArrayEmender.d.ts +0 -9
- package/lib/generates/internal/SwaggerReadonlyArrayEmender.js +0 -178
- package/lib/generates/internal/SwaggerReadonlyArrayEmender.js.map +0 -1
- package/lib/validators/HttpHeadersValidator.d.ts +0 -11
- package/lib/validators/HttpHeadersValidator.js +0 -15
- package/lib/validators/HttpHeadersValidator.js.map +0 -1
- package/lib/validators/HttpQueryValidator.d.ts +0 -10
- package/lib/validators/HttpQueryValidator.js +0 -14
- package/lib/validators/HttpQueryValidator.js.map +0 -1
- package/src/generates/internal/SwaggerReadonlyArrayEmender.ts +0 -264
- package/src/validators/HttpHeadersValidator.ts +0 -12
- package/src/validators/HttpQueryValidator.ts +0 -11
|
@@ -2,40 +2,72 @@ import { type TypeNode, factory } from "@ttsc/factory";
|
|
|
2
2
|
import { IMetadataTypeTag } from "@typia/interface";
|
|
3
3
|
|
|
4
4
|
import { LiteralFactory } from "../../factories/LiteralFactory";
|
|
5
|
+
import { decodeTagValue } from "../../internal/legacy";
|
|
5
6
|
import { ImportDictionary } from "./ImportDictionary";
|
|
6
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Writes the type tags of a cloned DTO.
|
|
10
|
+
*
|
|
11
|
+
* @evidence contracts/common.md#principled-implementation Supported predefined tags require matching arguments and encoded validation, exclusivity and schema expansions; other tags are emitted from the metadata fields as tags.TagBase.
|
|
12
|
+
* @evidence contracts/common.md#clear-and-simple-design Two public functions over a table of predefined tags.
|
|
13
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts The choice is decided by the expansion.
|
|
14
|
+
* @evidence contracts/common.md#meaningful-documentation The comment states what the declaration produces and its result.
|
|
15
|
+
* @evidenceExclude contracts/portability.md#os-neutral-implementation SdkTypeTagProgrammer composes SDK syntax, identifiers or import bindings; it does not resolve native file identity or launch a process. Source resolution and file emission belong to their filesystem owners.
|
|
16
|
+
*/
|
|
7
17
|
export namespace SdkTypeTagProgrammer {
|
|
18
|
+
/**
|
|
19
|
+
* The kinds of type a tag can be attached to.
|
|
20
|
+
*
|
|
21
|
+
* @evidence contracts/common.md#principled-implementation The six kinds are those the tags declare.
|
|
22
|
+
* @evidence contracts/common.md#clear-and-simple-design One union.
|
|
23
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts It is a type and adds no runtime behavior.
|
|
24
|
+
* @evidence contracts/common.md#meaningful-documentation The comment states what the declaration produces and its result.
|
|
25
|
+
* @evidenceExclude contracts/portability.md#os-neutral-implementation SdkTypeTagProgrammer.Target composes SDK syntax, identifiers or import bindings; it does not resolve native file identity or launch a process. Source resolution and file emission belong to their filesystem owners.
|
|
26
|
+
*/
|
|
27
|
+
export type Target =
|
|
28
|
+
| "object"
|
|
29
|
+
| "array"
|
|
30
|
+
| "boolean"
|
|
31
|
+
| "number"
|
|
32
|
+
| "bigint"
|
|
33
|
+
| "string";
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Writes a type tag of a cloned DTO.
|
|
37
|
+
*
|
|
38
|
+
* A tag prints as the predefined typia tag it matches, `tags.Minimum<3>`,
|
|
39
|
+
* only when that tag accepts the argument and, given it, expands to exactly
|
|
40
|
+
* the tag the metadata carries; then the two are the same type. Anything else
|
|
41
|
+
* prints in the generic `tags.TagBase<{ ... }>` form using the native
|
|
42
|
+
* metadata's reported fields. This cannot recover source details absent from
|
|
43
|
+
* that metadata or composite values changed by JSON encoding.
|
|
44
|
+
*
|
|
45
|
+
* The tag's name cannot decide it. The SDK names a tag after its object type
|
|
46
|
+
* with the brackets and quotes a component name drops, `Minimum3` or
|
|
47
|
+
* `Formatuuid`, so a name no longer tells `tags.Minimum<3>` from a user's own
|
|
48
|
+
* tag named alike (#1662). The expansion can: it is typia's declaration of
|
|
49
|
+
* each predefined tag, and should typia change one, the tag only falls back
|
|
50
|
+
* to the `TagBase` form.
|
|
51
|
+
*
|
|
52
|
+
* @evidence contracts/common.md#principled-implementation A tag prints as the predefined tag it matches only when that tag expands to exactly the tag the metadata carries.
|
|
53
|
+
* @evidence contracts/common.md#clear-and-simple-design One function.
|
|
54
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts Generic tags retain the reported value, validation, exclusivity and schema fields; NaN has no literal type and is represented as null. Source details absent from native metadata are not claimed to be reconstructed.
|
|
55
|
+
* @evidence contracts/common.md#meaningful-documentation The comment states what the declaration produces and its result.
|
|
56
|
+
* @evidenceExclude contracts/portability.md#os-neutral-implementation SdkTypeTagProgrammer.write composes SDK syntax, identifiers or import bindings; it does not resolve native file identity or launch a process. Source resolution and file emission belong to their filesystem owners.
|
|
57
|
+
*/
|
|
8
58
|
export const write = (
|
|
9
59
|
importer: ImportDictionary,
|
|
10
|
-
from:
|
|
60
|
+
from: Target,
|
|
11
61
|
tag: IMetadataTypeTag,
|
|
12
62
|
): TypeNode => {
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
importer.external({
|
|
19
|
-
declaration: true,
|
|
20
|
-
file: `typia`,
|
|
21
|
-
type: "element",
|
|
22
|
-
name: "tags",
|
|
23
|
-
}),
|
|
24
|
-
),
|
|
25
|
-
factory.createIdentifier(name),
|
|
26
|
-
),
|
|
27
|
-
[factory.createLiteralTypeNode(LiteralFactory.write(tag.value) as any)],
|
|
28
|
-
);
|
|
63
|
+
const predefined: IPredefined | null =
|
|
64
|
+
comment(from, tag) ?? recognize(from, tag);
|
|
65
|
+
if (predefined !== null)
|
|
66
|
+
return writePredefined(importer, predefined.name, predefined.argument);
|
|
67
|
+
const value: unknown = decodeTagValue(tag);
|
|
29
68
|
return factory.createTypeReferenceNode(
|
|
30
69
|
factory.createQualifiedName(
|
|
31
|
-
factory.createIdentifier(
|
|
32
|
-
importer.external({
|
|
33
|
-
declaration: true,
|
|
34
|
-
file: `typia`,
|
|
35
|
-
type: "element",
|
|
36
|
-
name: "tags",
|
|
37
|
-
}),
|
|
38
|
-
),
|
|
70
|
+
factory.createIdentifier(tagsOf(importer)),
|
|
39
71
|
factory.createIdentifier("TagBase"),
|
|
40
72
|
),
|
|
41
73
|
[
|
|
@@ -43,7 +75,7 @@ export namespace SdkTypeTagProgrammer {
|
|
|
43
75
|
LiteralFactory.write({
|
|
44
76
|
target: from,
|
|
45
77
|
kind: tag.kind,
|
|
46
|
-
value:
|
|
78
|
+
value: Number.isNaN(value) ? null : value,
|
|
47
79
|
validate: tag.validate,
|
|
48
80
|
exclusive: tag.exclusive,
|
|
49
81
|
schema: tag.schema,
|
|
@@ -52,59 +84,485 @@ export namespace SdkTypeTagProgrammer {
|
|
|
52
84
|
],
|
|
53
85
|
);
|
|
54
86
|
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Writes the predefined typia tag `tags.<name><argument>`.
|
|
90
|
+
*
|
|
91
|
+
* @evidence contracts/common.md#principled-implementation The name and argument were decided by the matching.
|
|
92
|
+
* @evidence contracts/common.md#clear-and-simple-design One node.
|
|
93
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts The argument is written as a literal.
|
|
94
|
+
* @evidence contracts/common.md#meaningful-documentation The comment states what the declaration produces and its result.
|
|
95
|
+
* @evidenceExclude contracts/portability.md#os-neutral-implementation SdkTypeTagProgrammer.writePredefined composes SDK syntax, identifiers or import bindings; it does not resolve native file identity or launch a process. Source resolution and file emission belong to their filesystem owners.
|
|
96
|
+
*/
|
|
97
|
+
export const writePredefined = (
|
|
98
|
+
importer: ImportDictionary,
|
|
99
|
+
name: string,
|
|
100
|
+
argument: unknown,
|
|
101
|
+
): TypeNode =>
|
|
102
|
+
factory.createTypeReferenceNode(
|
|
103
|
+
factory.createQualifiedName(
|
|
104
|
+
factory.createIdentifier(tagsOf(importer)),
|
|
105
|
+
factory.createIdentifier(name),
|
|
106
|
+
),
|
|
107
|
+
[factory.createLiteralTypeNode(LiteralFactory.write(argument) as any)],
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
const tagsOf = (importer: ImportDictionary): string =>
|
|
111
|
+
importer.external({
|
|
112
|
+
declaration: true,
|
|
113
|
+
file: `typia`,
|
|
114
|
+
type: "element",
|
|
115
|
+
name: "tags",
|
|
116
|
+
});
|
|
55
117
|
}
|
|
56
118
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
119
|
+
interface IPredefined {
|
|
120
|
+
name: string;
|
|
121
|
+
argument: unknown;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* The predefined tag a JSDoc comment tag stands for.
|
|
126
|
+
*
|
|
127
|
+
* Typia names a comment tag, `@format uri`, after that tag with its brackets,
|
|
128
|
+
* `Format<"uri">`, while a type tag's name has none, as the SDK's component
|
|
129
|
+
* names drop them. The source has no type tag to equal, and a comment tag may
|
|
130
|
+
* validate its own way, such as a format's inlined expression, so it prints as
|
|
131
|
+
* the tag the comment names whenever the argument suits the tagged type.
|
|
132
|
+
*/
|
|
133
|
+
const comment = (
|
|
134
|
+
from: SdkTypeTagProgrammer.Target,
|
|
135
|
+
tag: IMetadataTypeTag,
|
|
136
|
+
): IPredefined | null => {
|
|
137
|
+
if (tag.name.includes("<") === false) return null;
|
|
138
|
+
const definition: IDefinition | undefined = DEFINITIONS[tag.kind];
|
|
139
|
+
if (definition === undefined || tag.name.split("<")[0] !== definition.name)
|
|
140
|
+
return null;
|
|
141
|
+
const argument: unknown = argumentOf(definition, tag);
|
|
142
|
+
return argument !== undefined && definition.expand(from, argument) !== null
|
|
143
|
+
? { name: definition.name, argument }
|
|
144
|
+
: null;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* The typia tag the metadata's type tag is, with the argument that makes it, or
|
|
149
|
+
* `null` when no predefined tag expands to it exactly.
|
|
150
|
+
*/
|
|
151
|
+
const recognize = (
|
|
152
|
+
from: SdkTypeTagProgrammer.Target,
|
|
153
|
+
tag: IMetadataTypeTag,
|
|
154
|
+
): IPredefined | null => {
|
|
155
|
+
const definition: IDefinition | undefined = DEFINITIONS[tag.kind];
|
|
156
|
+
if (definition === undefined) return null;
|
|
157
|
+
const argument: unknown = argumentOf(definition, tag);
|
|
158
|
+
if (argument === undefined) return null;
|
|
159
|
+
const expected: IExpansion | null = definition.expand(from, argument);
|
|
160
|
+
if (expected === null) return null;
|
|
161
|
+
// the metadata holds the schema as JSON holds it
|
|
162
|
+
return equals(expected.validate, tag.validate) &&
|
|
163
|
+
equals(expected.exclusive, tag.exclusive) &&
|
|
164
|
+
equals(json(expected.schema), tag.schema)
|
|
165
|
+
? { name: definition.name, argument }
|
|
166
|
+
: null;
|
|
88
167
|
};
|
|
89
168
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
169
|
+
/**
|
|
170
|
+
* The type argument a tag was written with: its value, or, for a tag whose
|
|
171
|
+
* value is no literal, the schema member holding it. NaN has no literal type to
|
|
172
|
+
* write, so it gives none.
|
|
173
|
+
*/
|
|
174
|
+
const argumentOf = (
|
|
175
|
+
definition: IDefinition,
|
|
176
|
+
tag: IMetadataTypeTag,
|
|
177
|
+
): unknown => {
|
|
178
|
+
const value: unknown = decodeTagValue(tag);
|
|
179
|
+
const argument: unknown =
|
|
180
|
+
value === null || value === undefined
|
|
181
|
+
? definition.fallback?.(tag.schema as Record<string, unknown>)
|
|
182
|
+
: value;
|
|
183
|
+
return Number.isNaN(argument) ? undefined : argument;
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* What a predefined tag, given its argument, bakes into the metadata. A tag
|
|
188
|
+
* whose type parameter constraint rejects the argument expands to nothing.
|
|
189
|
+
*/
|
|
190
|
+
interface IExpansion {
|
|
191
|
+
validate: string | undefined;
|
|
192
|
+
exclusive: boolean | string[];
|
|
193
|
+
schema: object;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
interface IDefinition {
|
|
197
|
+
name: string;
|
|
198
|
+
expand: (
|
|
199
|
+
from: SdkTypeTagProgrammer.Target,
|
|
200
|
+
argument: unknown,
|
|
201
|
+
) => IExpansion | null;
|
|
202
|
+
fallback?: (schema: Record<string, unknown> | undefined) => unknown;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** `${Value}` of a numeric type argument, as a TypeScript template prints it. */
|
|
206
|
+
const numeral = (value: number | bigint): string =>
|
|
207
|
+
typeof value === "bigint" ? `BigInt(${value})` : String(value);
|
|
208
|
+
|
|
209
|
+
const isNumeric = (value: unknown): value is number | bigint =>
|
|
210
|
+
typeof value === "number" || typeof value === "bigint";
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* A value as JSON holds it: a bigint as its number, as typia's `Numeric<Value>`
|
|
214
|
+
* does, and a non-finite number as null, as `JSON.stringify` writes it.
|
|
215
|
+
*/
|
|
216
|
+
const json = (value: unknown): unknown =>
|
|
217
|
+
typeof value === "bigint"
|
|
218
|
+
? Number(value)
|
|
219
|
+
: typeof value === "number" && Number.isFinite(value) === false
|
|
220
|
+
? null
|
|
221
|
+
: Array.isArray(value)
|
|
222
|
+
? value.map(json)
|
|
223
|
+
: typeof value === "object" && value !== null
|
|
224
|
+
? Object.fromEntries(
|
|
225
|
+
Object.entries(value).map(([key, v]) => [key, json(v)]),
|
|
226
|
+
)
|
|
227
|
+
: value;
|
|
228
|
+
|
|
229
|
+
const bound =
|
|
230
|
+
(
|
|
231
|
+
kind: string,
|
|
232
|
+
exclusive: string[],
|
|
233
|
+
validate: (value: string) => string,
|
|
234
|
+
): IDefinition["expand"] =>
|
|
235
|
+
(from, argument) =>
|
|
236
|
+
isNumeric(argument) &&
|
|
237
|
+
from === (typeof argument === "bigint" ? "bigint" : "number")
|
|
238
|
+
? {
|
|
239
|
+
validate: validate(numeral(argument)),
|
|
240
|
+
exclusive,
|
|
241
|
+
schema: { [kind]: json(argument) },
|
|
242
|
+
}
|
|
243
|
+
: null;
|
|
244
|
+
|
|
245
|
+
const TYPE_VALIDATE: Record<string, string | Record<string, string>> = {
|
|
246
|
+
int8: `$importInternal("isTypeInt8")($input)`,
|
|
247
|
+
uint8: `$importInternal("isTypeUint8")($input)`,
|
|
248
|
+
int16: `$importInternal("isTypeInt16")($input)`,
|
|
249
|
+
uint16: `$importInternal("isTypeUint16")($input)`,
|
|
250
|
+
int32: `$importInternal("isTypeInt32")($input)`,
|
|
251
|
+
uint32: `$importInternal("isTypeUint32")($input)`,
|
|
252
|
+
int64: {
|
|
253
|
+
number: `$importInternal("isTypeInt64")($input)`,
|
|
254
|
+
bigint: `$importInternal("isTypeInt64Bigint")($input)`,
|
|
255
|
+
},
|
|
256
|
+
uint64: {
|
|
257
|
+
number: `$importInternal("isTypeUint64")($input)`,
|
|
258
|
+
bigint: `$importInternal("isTypeUint64Bigint")($input)`,
|
|
259
|
+
},
|
|
260
|
+
float: `$importInternal("isTypeFloat")($input)`,
|
|
261
|
+
double: `true`,
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
/** `Format.Value` of typia's `Format` tag. */
|
|
265
|
+
const FORMATS: Set<string> = new Set([
|
|
266
|
+
"byte",
|
|
267
|
+
"password",
|
|
268
|
+
"regex",
|
|
269
|
+
"uuid",
|
|
270
|
+
"email",
|
|
271
|
+
"hostname",
|
|
272
|
+
"idn-email",
|
|
273
|
+
"idn-hostname",
|
|
274
|
+
"iri",
|
|
275
|
+
"iri-reference",
|
|
276
|
+
"ipv4",
|
|
277
|
+
"ipv6",
|
|
278
|
+
"uri",
|
|
279
|
+
"uri-reference",
|
|
280
|
+
"uri-template",
|
|
281
|
+
"url",
|
|
282
|
+
"date-time",
|
|
283
|
+
"date",
|
|
284
|
+
"time",
|
|
285
|
+
"duration",
|
|
286
|
+
"json-pointer",
|
|
287
|
+
"relative-json-pointer",
|
|
288
|
+
]);
|
|
289
|
+
|
|
290
|
+
/** `DefaultAtomic` of typia's `Default` tag. */
|
|
291
|
+
const isDefaultAtomic = (value: unknown): boolean =>
|
|
292
|
+
typeof value === "boolean" ||
|
|
293
|
+
typeof value === "bigint" ||
|
|
294
|
+
typeof value === "number" ||
|
|
295
|
+
typeof value === "string";
|
|
296
|
+
|
|
297
|
+
/** `PascalizeString` of typia's `Format` tag: `date-time` as `DateTime`. */
|
|
298
|
+
const pascalize = (value: string): string =>
|
|
299
|
+
value.includes("-")
|
|
300
|
+
? value
|
|
301
|
+
.split("-")
|
|
302
|
+
.filter((word) => word.length !== 0)
|
|
303
|
+
.map(
|
|
304
|
+
(word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase(),
|
|
305
|
+
)
|
|
306
|
+
.join("")
|
|
307
|
+
: value.charAt(0).toUpperCase() + value.slice(1);
|
|
308
|
+
|
|
309
|
+
/** `Serialize` of typia's `Pattern` tag, escaping as a string literal. */
|
|
310
|
+
const serialize = (value: string): string =>
|
|
311
|
+
value.replace(
|
|
312
|
+
/["\\\b\f\n\r\t]/g,
|
|
313
|
+
(char) =>
|
|
314
|
+
({
|
|
315
|
+
'"': '\\"',
|
|
316
|
+
"\\": "\\\\",
|
|
317
|
+
"\b": "\\b",
|
|
318
|
+
"\f": "\\f",
|
|
319
|
+
"\n": "\\n",
|
|
320
|
+
"\r": "\\r",
|
|
321
|
+
"\t": "\\t",
|
|
322
|
+
})[char]!,
|
|
323
|
+
);
|
|
324
|
+
|
|
325
|
+
/** Supported predefined typia tag expansions, keyed by their metadata kind. */
|
|
326
|
+
const DEFINITIONS: Record<string, IDefinition> = {
|
|
327
|
+
minimum: {
|
|
328
|
+
name: "Minimum",
|
|
329
|
+
expand: bound(
|
|
330
|
+
"minimum",
|
|
331
|
+
["minimum", "exclusiveMinimum"],
|
|
332
|
+
(v) => `${v} <= $input`,
|
|
333
|
+
),
|
|
334
|
+
},
|
|
335
|
+
maximum: {
|
|
336
|
+
name: "Maximum",
|
|
337
|
+
expand: bound(
|
|
338
|
+
"maximum",
|
|
339
|
+
["maximum", "exclusiveMaximum"],
|
|
340
|
+
(v) => `$input <= ${v}`,
|
|
341
|
+
),
|
|
342
|
+
},
|
|
343
|
+
exclusiveMinimum: {
|
|
344
|
+
name: "ExclusiveMinimum",
|
|
345
|
+
expand: bound(
|
|
346
|
+
"exclusiveMinimum",
|
|
347
|
+
["exclusiveMinimum", "minimum"],
|
|
348
|
+
(v) => `${v} < $input`,
|
|
349
|
+
),
|
|
350
|
+
},
|
|
351
|
+
exclusiveMaximum: {
|
|
352
|
+
name: "ExclusiveMaximum",
|
|
353
|
+
expand: bound(
|
|
354
|
+
"exclusiveMaximum",
|
|
355
|
+
["exclusiveMaximum", "maximum"],
|
|
356
|
+
(v) => `$input < ${v}`,
|
|
357
|
+
),
|
|
358
|
+
},
|
|
359
|
+
multipleOf: {
|
|
360
|
+
name: "MultipleOf",
|
|
361
|
+
expand: (from, argument) =>
|
|
362
|
+
isNumeric(argument) &&
|
|
363
|
+
from === (typeof argument === "bigint" ? "bigint" : "number")
|
|
364
|
+
? {
|
|
365
|
+
validate:
|
|
366
|
+
typeof argument === "bigint"
|
|
367
|
+
? `$input % ${numeral(argument)} === ${numeral(BigInt(0))}`
|
|
368
|
+
: `$importInternal("_isMultipleOf")($input, ${argument})`,
|
|
369
|
+
exclusive: true,
|
|
370
|
+
schema: { multipleOf: json(argument) },
|
|
371
|
+
}
|
|
372
|
+
: null,
|
|
373
|
+
},
|
|
374
|
+
type: {
|
|
375
|
+
name: "Type",
|
|
376
|
+
expand: (from, argument) => {
|
|
377
|
+
if (typeof argument !== "string") return null;
|
|
378
|
+
const validate = TYPE_VALIDATE[argument];
|
|
379
|
+
if (validate === undefined) return null;
|
|
380
|
+
const wide: boolean = argument === "int64" || argument === "uint64";
|
|
381
|
+
if (from !== "number" && (wide === false || from !== "bigint"))
|
|
382
|
+
return null;
|
|
383
|
+
return {
|
|
384
|
+
validate: typeof validate === "string" ? validate : validate[from],
|
|
385
|
+
exclusive: true,
|
|
386
|
+
schema: argument.startsWith("uint")
|
|
387
|
+
? { type: "integer", minimum: 0 }
|
|
388
|
+
: { type: argument.startsWith("int") ? "integer" : "number" },
|
|
389
|
+
};
|
|
390
|
+
},
|
|
391
|
+
},
|
|
392
|
+
format: {
|
|
393
|
+
name: "Format",
|
|
394
|
+
expand: (from, argument) =>
|
|
395
|
+
from === "string" && typeof argument === "string" && FORMATS.has(argument)
|
|
396
|
+
? {
|
|
397
|
+
validate: `$importInternal("isFormat${pascalize(argument)}")($input)`,
|
|
398
|
+
exclusive: ["format", "pattern"],
|
|
399
|
+
schema: { format: argument },
|
|
400
|
+
}
|
|
401
|
+
: null,
|
|
402
|
+
},
|
|
403
|
+
pattern: {
|
|
404
|
+
name: "Pattern",
|
|
405
|
+
expand: (from, argument) =>
|
|
406
|
+
from === "string" && typeof argument === "string"
|
|
407
|
+
? {
|
|
408
|
+
validate: `RegExp("${serialize(argument)}").test($input)`,
|
|
409
|
+
exclusive: ["format", "pattern"],
|
|
410
|
+
schema: { pattern: argument },
|
|
411
|
+
}
|
|
412
|
+
: null,
|
|
413
|
+
},
|
|
414
|
+
minLength: {
|
|
415
|
+
name: "MinLength",
|
|
416
|
+
expand: (from, argument) =>
|
|
417
|
+
from === "string" && typeof argument === "number"
|
|
418
|
+
? {
|
|
419
|
+
validate: `$importInternal("_stringLengthGte")($input, ${argument})`,
|
|
420
|
+
exclusive: true,
|
|
421
|
+
schema: { minLength: argument },
|
|
422
|
+
}
|
|
423
|
+
: null,
|
|
424
|
+
},
|
|
425
|
+
maxLength: {
|
|
426
|
+
name: "MaxLength",
|
|
427
|
+
expand: (from, argument) =>
|
|
428
|
+
from === "string" && typeof argument === "number"
|
|
429
|
+
? {
|
|
430
|
+
validate: `$importInternal("_stringLengthLte")($input, ${argument})`,
|
|
431
|
+
exclusive: true,
|
|
432
|
+
schema: { maxLength: argument },
|
|
433
|
+
}
|
|
434
|
+
: null,
|
|
435
|
+
},
|
|
436
|
+
minItems: {
|
|
437
|
+
name: "MinItems",
|
|
438
|
+
expand: (from, argument) =>
|
|
439
|
+
from === "array" && typeof argument === "number"
|
|
440
|
+
? {
|
|
441
|
+
validate: `${argument} <= $input.length`,
|
|
442
|
+
exclusive: true,
|
|
443
|
+
schema: { minItems: argument },
|
|
444
|
+
}
|
|
445
|
+
: null,
|
|
446
|
+
},
|
|
447
|
+
maxItems: {
|
|
448
|
+
name: "MaxItems",
|
|
449
|
+
expand: (from, argument) =>
|
|
450
|
+
from === "array" && typeof argument === "number"
|
|
451
|
+
? {
|
|
452
|
+
validate: `$input.length <= ${argument}`,
|
|
453
|
+
exclusive: true,
|
|
454
|
+
schema: { maxItems: argument },
|
|
455
|
+
}
|
|
456
|
+
: null,
|
|
457
|
+
},
|
|
458
|
+
uniqueItems: {
|
|
459
|
+
name: "UniqueItems",
|
|
460
|
+
expand: (from, argument) =>
|
|
461
|
+
from === "array" && typeof argument === "boolean"
|
|
462
|
+
? {
|
|
463
|
+
validate: argument
|
|
464
|
+
? `$importInternal("isUniqueItems")($input)`
|
|
465
|
+
: undefined,
|
|
466
|
+
exclusive: true,
|
|
467
|
+
schema: { uniqueItems: true },
|
|
468
|
+
}
|
|
469
|
+
: null,
|
|
470
|
+
},
|
|
471
|
+
contentMediaType: {
|
|
472
|
+
name: "ContentMediaType",
|
|
473
|
+
expand: (from, argument) =>
|
|
474
|
+
from === "string" && typeof argument === "string"
|
|
475
|
+
? {
|
|
476
|
+
validate: undefined,
|
|
477
|
+
exclusive: false,
|
|
478
|
+
schema: { contentMediaType: argument },
|
|
479
|
+
}
|
|
480
|
+
: null,
|
|
481
|
+
fallback: (schema) => schema?.contentMediaType,
|
|
482
|
+
},
|
|
483
|
+
default: {
|
|
484
|
+
name: "Default",
|
|
485
|
+
expand: (from, argument) =>
|
|
486
|
+
from ===
|
|
487
|
+
(Array.isArray(argument)
|
|
488
|
+
? argument.every(isDefaultAtomic)
|
|
489
|
+
? "array"
|
|
490
|
+
: null
|
|
491
|
+
: typeof argument === "boolean"
|
|
492
|
+
? "boolean"
|
|
493
|
+
: typeof argument === "bigint"
|
|
494
|
+
? "bigint"
|
|
495
|
+
: typeof argument === "number"
|
|
496
|
+
? "number"
|
|
497
|
+
: typeof argument === "string"
|
|
498
|
+
? "string"
|
|
499
|
+
: null)
|
|
500
|
+
? {
|
|
501
|
+
validate: undefined,
|
|
502
|
+
exclusive: true,
|
|
503
|
+
schema: { default: json(argument) },
|
|
504
|
+
}
|
|
505
|
+
: null,
|
|
506
|
+
fallback: (schema) => schema?.default,
|
|
507
|
+
},
|
|
508
|
+
example: {
|
|
509
|
+
name: "Example",
|
|
510
|
+
expand: (_from, argument) => ({
|
|
511
|
+
validate: undefined,
|
|
512
|
+
exclusive: true,
|
|
513
|
+
schema: {
|
|
514
|
+
example: typeof argument === "bigint" ? Number(argument) : argument,
|
|
515
|
+
},
|
|
516
|
+
}),
|
|
517
|
+
fallback: (schema) => schema?.example,
|
|
518
|
+
},
|
|
519
|
+
examples: {
|
|
520
|
+
name: "Examples",
|
|
521
|
+
expand: (_from, argument) =>
|
|
522
|
+
typeof argument === "object" &&
|
|
523
|
+
argument !== null &&
|
|
524
|
+
Array.isArray(argument) === false &&
|
|
525
|
+
Object.values(argument).every((value) => value !== undefined)
|
|
526
|
+
? {
|
|
527
|
+
validate: undefined,
|
|
528
|
+
exclusive: true,
|
|
529
|
+
schema: { examples: argument },
|
|
530
|
+
}
|
|
531
|
+
: null,
|
|
532
|
+
fallback: (schema) => schema?.examples,
|
|
533
|
+
},
|
|
534
|
+
sequence: {
|
|
535
|
+
name: "Sequence",
|
|
536
|
+
expand: (_from, argument) =>
|
|
537
|
+
typeof argument === "number"
|
|
538
|
+
? {
|
|
539
|
+
validate: undefined,
|
|
540
|
+
exclusive: false,
|
|
541
|
+
schema: { "x-protobuf-sequence": argument },
|
|
542
|
+
}
|
|
543
|
+
: null,
|
|
544
|
+
},
|
|
545
|
+
};
|
|
546
|
+
|
|
547
|
+
/** Structural equality of metadata values, which hold bigints. */
|
|
548
|
+
const equals = (x: unknown, y: unknown): boolean => {
|
|
549
|
+
if (x === y) return true;
|
|
550
|
+
if (typeof x !== "object" || typeof y !== "object") return false;
|
|
551
|
+
if (x === null || y === null) return false;
|
|
552
|
+
if (Array.isArray(x) !== Array.isArray(y)) return false;
|
|
553
|
+
const xKeys: string[] = Object.keys(x).filter(
|
|
554
|
+
(key) => (x as Record<string, unknown>)[key] !== undefined,
|
|
555
|
+
);
|
|
556
|
+
const yKeys: string[] = Object.keys(y).filter(
|
|
557
|
+
(key) => (y as Record<string, unknown>)[key] !== undefined,
|
|
558
|
+
);
|
|
559
|
+
return (
|
|
560
|
+
xKeys.length === yKeys.length &&
|
|
561
|
+
xKeys.every((key) =>
|
|
562
|
+
equals(
|
|
563
|
+
(x as Record<string, unknown>)[key],
|
|
564
|
+
(y as Record<string, unknown>)[key],
|
|
565
|
+
),
|
|
566
|
+
)
|
|
567
|
+
);
|
|
568
|
+
};
|