typia 7.2.1 → 7.3.0-dev.20241213
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 -21
- package/README.md +148 -148
- package/lib/executable/typia.js +0 -0
- package/lib/programmers/llm/LlmApplicationProgrammer.js +0 -1
- package/lib/programmers/llm/LlmApplicationProgrammer.js.map +1 -1
- package/package.json +3 -3
- package/src/IRandomGenerator.ts +49 -49
- package/src/IReadableURLSearchParams.ts +9 -9
- package/src/IValidation.ts +21 -21
- package/src/executable/TypiaGenerateWizard.ts +83 -83
- package/src/executable/TypiaPatchWizard.ts +45 -45
- package/src/executable/TypiaSetupWizard.ts +179 -179
- package/src/executable/setup/ArgumentParser.ts +42 -42
- package/src/executable/setup/FileRetriever.ts +19 -19
- package/src/executable/setup/PackageManager.ts +87 -87
- package/src/factories/ExpressionFactory.ts +216 -216
- package/src/factories/IdentifierFactory.ts +89 -89
- package/src/factories/JsonMetadataFactory.ts +76 -76
- package/src/factories/LiteralFactory.ts +52 -52
- package/src/factories/MetadataCollection.ts +278 -278
- package/src/factories/MetadataCommentTagFactory.ts +650 -650
- package/src/factories/MetadataFactory.ts +404 -404
- package/src/factories/MetadataTypeTagFactory.ts +411 -411
- package/src/factories/MetadataTypeTagSchemaFactory.ts +82 -82
- package/src/factories/NumericRangeFactory.ts +72 -72
- package/src/factories/ProtobufFactory.ts +875 -875
- package/src/factories/StatementFactory.ts +90 -90
- package/src/factories/TemplateFactory.ts +64 -64
- package/src/factories/TypeFactory.ts +140 -140
- package/src/factories/internal/metadata/IMetadataIteratorProps.ts +17 -17
- package/src/factories/internal/metadata/MetadataHelper.ts +21 -21
- package/src/factories/internal/metadata/emplace_metadata_alias.ts +33 -33
- package/src/factories/internal/metadata/emplace_metadata_array_type.ts +39 -39
- package/src/factories/internal/metadata/emplace_metadata_object.ts +208 -208
- package/src/factories/internal/metadata/emplace_metadata_tuple.ts +57 -57
- package/src/factories/internal/metadata/explore_metadata.ts +31 -31
- package/src/factories/internal/metadata/iterate_metadata.ts +54 -54
- package/src/factories/internal/metadata/iterate_metadata_alias.ts +33 -33
- package/src/factories/internal/metadata/iterate_metadata_array.ts +63 -63
- package/src/factories/internal/metadata/iterate_metadata_atomic.ts +62 -62
- package/src/factories/internal/metadata/iterate_metadata_coalesce.ts +28 -28
- package/src/factories/internal/metadata/iterate_metadata_collection.ts +146 -146
- package/src/factories/internal/metadata/iterate_metadata_comment_tags.ts +32 -32
- package/src/factories/internal/metadata/iterate_metadata_constant.ts +76 -76
- package/src/factories/internal/metadata/iterate_metadata_escape.ts +49 -49
- package/src/factories/internal/metadata/iterate_metadata_function.ts +91 -91
- package/src/factories/internal/metadata/iterate_metadata_intersection.ts +213 -213
- package/src/factories/internal/metadata/iterate_metadata_map.ts +57 -57
- package/src/factories/internal/metadata/iterate_metadata_native.ts +255 -255
- package/src/factories/internal/metadata/iterate_metadata_object.ts +35 -35
- package/src/factories/internal/metadata/iterate_metadata_set.ts +57 -57
- package/src/factories/internal/metadata/iterate_metadata_sort.ts +87 -87
- package/src/factories/internal/metadata/iterate_metadata_template.ts +41 -41
- package/src/factories/internal/metadata/iterate_metadata_tuple.ts +26 -26
- package/src/factories/internal/metadata/iterate_metadata_union.ts +19 -19
- package/src/functional.ts +750 -750
- package/src/http.ts +1047 -1047
- package/src/internal/_IProtobufWriter.ts +18 -18
- package/src/internal/_ProtobufReader.ts +194 -194
- package/src/internal/_ProtobufSizer.ts +145 -145
- package/src/internal/_ProtobufWriter.ts +145 -145
- package/src/internal/_accessExpressionAsString.ts +46 -46
- package/src/internal/_assertGuard.ts +13 -13
- package/src/internal/_functionalTypeGuardErrorFactory.ts +4 -4
- package/src/internal/_httpFormDataReadArray.ts +4 -4
- package/src/internal/_httpFormDataReadBigint.ts +18 -18
- package/src/internal/_httpFormDataReadBlob.ts +10 -10
- package/src/internal/_httpFormDataReadBoolean.ts +16 -16
- package/src/internal/_httpFormDataReadFile.ts +10 -10
- package/src/internal/_httpFormDataReadNumber.ts +15 -15
- package/src/internal/_httpFormDataReadString.ts +10 -10
- package/src/internal/_httpHeaderReadBigint.ts +10 -10
- package/src/internal/_httpHeaderReadBoolean.ts +8 -8
- package/src/internal/_httpHeaderReadNumber.ts +7 -7
- package/src/internal/_httpParameterReadBigint.ts +10 -10
- package/src/internal/_httpParameterReadBoolean.ts +8 -8
- package/src/internal/_httpParameterReadNumber.ts +7 -7
- package/src/internal/_httpParameterReadString.ts +2 -2
- package/src/internal/_httpQueryParseURLSearchParams.ts +12 -12
- package/src/internal/_httpQueryReadArray.ts +4 -4
- package/src/internal/_httpQueryReadBigint.ts +12 -12
- package/src/internal/_httpQueryReadBoolean.ts +14 -14
- package/src/internal/_httpQueryReadNumber.ts +9 -9
- package/src/internal/_httpQueryReadString.ts +4 -4
- package/src/internal/_isBetween.ts +2 -2
- package/src/internal/_isBigintString.ts +8 -8
- package/src/internal/_isFormatByte.ts +7 -7
- package/src/internal/_isFormatDate.ts +3 -3
- package/src/internal/_isFormatDateTime.ts +4 -4
- package/src/internal/_isFormatDuration.ts +4 -4
- package/src/internal/_isFormatEmail.ts +4 -4
- package/src/internal/_isFormatHostname.ts +4 -4
- package/src/internal/_isFormatIdnEmail.ts +4 -4
- package/src/internal/_isFormatIdnHostname.ts +4 -4
- package/src/internal/_isFormatIpv4.ts +4 -4
- package/src/internal/_isFormatIpv6.ts +4 -4
- package/src/internal/_isFormatIri.ts +3 -3
- package/src/internal/_isFormatIriReference.ts +4 -4
- package/src/internal/_isFormatJsonPointer.ts +3 -3
- package/src/internal/_isFormatPassword.ts +1 -1
- package/src/internal/_isFormatRegex.ts +8 -8
- package/src/internal/_isFormatRelativeJsonPointer.ts +4 -4
- package/src/internal/_isFormatTime.ts +4 -4
- package/src/internal/_isFormatUri.ts +6 -6
- package/src/internal/_isFormatUriReference.ts +5 -5
- package/src/internal/_isFormatUriTemplate.ts +4 -4
- package/src/internal/_isFormatUrl.ts +4 -4
- package/src/internal/_isFormatUuid.ts +3 -3
- package/src/internal/_isTypeFloat.ts +5 -5
- package/src/internal/_isTypeInt32.ts +5 -5
- package/src/internal/_isTypeInt64.ts +5 -5
- package/src/internal/_isTypeUint32.ts +5 -5
- package/src/internal/_isTypeUint64.ts +5 -5
- package/src/internal/_isUniqueItems.ts +159 -159
- package/src/internal/_jsonStringifyNumber.ts +12 -12
- package/src/internal/_jsonStringifyRest.ts +3 -3
- package/src/internal/_jsonStringifyString.ts +42 -42
- package/src/internal/_jsonStringifyTail.ts +2 -2
- package/src/internal/_llmApplicationFinalize.ts +20 -20
- package/src/internal/_miscCloneAny.ts +46 -46
- package/src/internal/_notationAny.ts +37 -37
- package/src/internal/_notationCamel.ts +13 -13
- package/src/internal/_notationPascal.ts +8 -8
- package/src/internal/_notationSnake.ts +43 -43
- package/src/internal/_randomArray.ts +21 -21
- package/src/internal/_randomBigint.ts +6 -6
- package/src/internal/_randomBoolean.ts +1 -1
- package/src/internal/_randomFormatByte.ts +3 -3
- package/src/internal/_randomFormatDate.ts +18 -18
- package/src/internal/_randomFormatDatetime.ts +16 -16
- package/src/internal/_randomFormatDuration.ts +27 -27
- package/src/internal/_randomFormatEmail.ts +11 -11
- package/src/internal/_randomFormatHostname.ts +6 -6
- package/src/internal/_randomFormatIdnEmail.ts +3 -3
- package/src/internal/_randomFormatIdnHostname.ts +3 -3
- package/src/internal/_randomFormatIpv4.ts +11 -11
- package/src/internal/_randomFormatIpv6.ts +11 -11
- package/src/internal/_randomFormatIri.ts +3 -3
- package/src/internal/_randomFormatIriReference.ts +3 -3
- package/src/internal/_randomFormatJsonPointer.ts +7 -7
- package/src/internal/_randomFormatPassword.ts +8 -8
- package/src/internal/_randomFormatRegex.ts +4 -4
- package/src/internal/_randomFormatRelativeJsonPointer.ts +8 -8
- package/src/internal/_randomFormatTime.ts +14 -14
- package/src/internal/_randomFormatUri.ts +3 -3
- package/src/internal/_randomFormatUriReference.ts +3 -3
- package/src/internal/_randomFormatUriTemplate.ts +3 -3
- package/src/internal/_randomFormatUrl.ts +11 -11
- package/src/internal/_randomFormatUuid.ts +6 -6
- package/src/internal/_randomInteger.ts +47 -47
- package/src/internal/_randomNumber.ts +74 -74
- package/src/internal/_randomPattern.ts +10 -10
- package/src/internal/_randomPick.ts +9 -9
- package/src/internal/_randomString.ts +24 -24
- package/src/internal/_throwTypeGuardError.ts +5 -5
- package/src/internal/_validateReport.ts +13 -13
- package/src/internal/private/__notationCapitalize.ts +2 -2
- package/src/internal/private/__notationUnsnake.ts +24 -24
- package/src/json.ts +752 -752
- package/src/llm.ts +481 -481
- package/src/misc.ts +658 -658
- package/src/module.ts +937 -937
- package/src/notations.ts +827 -827
- package/src/programmers/AssertProgrammer.ts +454 -454
- package/src/programmers/CheckerProgrammer.ts +1617 -1617
- package/src/programmers/FeatureProgrammer.ts +622 -622
- package/src/programmers/ImportProgrammer.ts +185 -185
- package/src/programmers/IsProgrammer.ts +273 -273
- package/src/programmers/RandomProgrammer.ts +1190 -1190
- package/src/programmers/TypiaProgrammer.ts +174 -174
- package/src/programmers/ValidateProgrammer.ts +439 -439
- package/src/programmers/functional/FunctionalAssertFunctionProgrammer.ts +153 -153
- package/src/programmers/functional/FunctionalAssertParametersProgrammer.ts +125 -125
- package/src/programmers/functional/FunctionalAssertReturnProgrammer.ts +115 -115
- package/src/programmers/functional/FunctionalIsFunctionProgrammer.ts +72 -72
- package/src/programmers/functional/FunctionalIsParametersProgrammer.ts +113 -113
- package/src/programmers/functional/FunctionalIsReturnProgrammer.ts +116 -116
- package/src/programmers/functional/FunctionalValidateFunctionProgrammer.ts +119 -119
- package/src/programmers/functional/FunctionalValidateParametersProgrammer.ts +274 -274
- package/src/programmers/functional/FunctionalValidateReturnProgrammer.ts +135 -135
- package/src/programmers/functional/internal/FunctionalGeneralProgrammer.ts +34 -34
- package/src/programmers/helpers/AtomicPredicator.ts +35 -35
- package/src/programmers/helpers/CloneJoiner.ts +143 -143
- package/src/programmers/helpers/FunctionProgrammer.ts +67 -67
- package/src/programmers/helpers/HttpMetadataUtil.ts +21 -21
- package/src/programmers/helpers/NotationJoiner.ts +144 -144
- package/src/programmers/helpers/OptionPredicator.ts +15 -15
- package/src/programmers/helpers/ProtobufUtil.ts +228 -228
- package/src/programmers/helpers/PruneJoiner.ts +148 -148
- package/src/programmers/helpers/RandomJoiner.ts +168 -168
- package/src/programmers/helpers/StringifyJoinder.ts +115 -115
- package/src/programmers/helpers/StringifyPredicator.ts +13 -13
- package/src/programmers/helpers/UnionExplorer.ts +372 -372
- package/src/programmers/helpers/UnionPredicator.ts +79 -79
- package/src/programmers/helpers/disable_function_programmer_declare.ts +32 -32
- package/src/programmers/http/HttpAssertFormDataProgrammer.ts +99 -99
- package/src/programmers/http/HttpAssertHeadersProgrammer.ts +99 -99
- package/src/programmers/http/HttpAssertQueryProgrammer.ts +105 -105
- package/src/programmers/http/HttpFormDataProgrammer.ts +308 -308
- package/src/programmers/http/HttpHeadersProgrammer.ts +400 -400
- package/src/programmers/http/HttpIsFormDataProgrammer.ts +108 -108
- package/src/programmers/http/HttpIsHeadersProgrammer.ts +108 -108
- package/src/programmers/http/HttpIsQueryProgrammer.ts +114 -114
- package/src/programmers/http/HttpParameterProgrammer.ts +115 -115
- package/src/programmers/http/HttpQueryProgrammer.ts +336 -336
- package/src/programmers/http/HttpValidateFormDataProgrammer.ts +92 -92
- package/src/programmers/http/HttpValidateHeadersProgrammer.ts +92 -92
- package/src/programmers/http/HttpValidateQueryProgrammer.ts +98 -98
- package/src/programmers/internal/check_array_length.ts +47 -47
- package/src/programmers/internal/check_bigint.ts +50 -50
- package/src/programmers/internal/check_dynamic_key.ts +201 -201
- package/src/programmers/internal/check_dynamic_properties.ts +208 -208
- package/src/programmers/internal/check_everything.ts +23 -23
- package/src/programmers/internal/check_native.ts +27 -27
- package/src/programmers/internal/check_number.ts +112 -112
- package/src/programmers/internal/check_object.ts +75 -75
- package/src/programmers/internal/check_string.ts +50 -50
- package/src/programmers/internal/check_template.ts +48 -48
- package/src/programmers/internal/check_union_array_like.ts +335 -335
- package/src/programmers/internal/decode_union_object.ts +116 -116
- package/src/programmers/internal/feature_object_entries.ts +61 -61
- package/src/programmers/internal/json_schema_alias.ts +47 -47
- package/src/programmers/internal/json_schema_array.ts +45 -45
- package/src/programmers/internal/json_schema_bigint.ts +15 -15
- package/src/programmers/internal/json_schema_boolean.ts +15 -15
- package/src/programmers/internal/json_schema_constant.ts +26 -26
- package/src/programmers/internal/json_schema_description.ts +12 -12
- package/src/programmers/internal/json_schema_discriminator.ts +35 -35
- package/src/programmers/internal/json_schema_escaped.ts +82 -82
- package/src/programmers/internal/json_schema_native.ts +33 -33
- package/src/programmers/internal/json_schema_number.ts +15 -15
- package/src/programmers/internal/json_schema_object.ts +158 -158
- package/src/programmers/internal/json_schema_plugin.ts +18 -18
- package/src/programmers/internal/json_schema_station.ts +182 -182
- package/src/programmers/internal/json_schema_string.ts +15 -15
- package/src/programmers/internal/json_schema_template.ts +55 -55
- package/src/programmers/internal/json_schema_title.ts +20 -20
- package/src/programmers/internal/json_schema_tuple.ts +35 -35
- package/src/programmers/internal/metadata_to_pattern.ts +42 -42
- package/src/programmers/internal/postfix_of_tuple.ts +5 -5
- package/src/programmers/internal/prune_object_properties.ts +71 -71
- package/src/programmers/internal/stringify_dynamic_properties.ts +162 -162
- package/src/programmers/internal/stringify_regular_properties.ts +81 -81
- package/src/programmers/internal/template_to_pattern.ts +23 -23
- package/src/programmers/internal/wrap_metadata_rest_tuple.ts +23 -23
- package/src/programmers/json/JsonApplicationProgrammer.ts +279 -279
- package/src/programmers/json/JsonAssertParseProgrammer.ts +113 -113
- package/src/programmers/json/JsonAssertStringifyProgrammer.ts +115 -115
- package/src/programmers/json/JsonIsParseProgrammer.ts +114 -114
- package/src/programmers/json/JsonIsStringifyProgrammer.ts +108 -108
- package/src/programmers/json/JsonSchemasProgrammer.ts +91 -91
- package/src/programmers/json/JsonStringifyProgrammer.ts +1124 -1124
- package/src/programmers/json/JsonValidateParseProgrammer.ts +105 -105
- package/src/programmers/json/JsonValidateStringifyProgrammer.ts +124 -124
- package/src/programmers/llm/LlmApplicationOfValidateProgrammer.ts +81 -81
- package/src/programmers/llm/LlmApplicationProgrammer.ts +277 -278
- package/src/programmers/llm/LlmModelPredicator.ts +127 -127
- package/src/programmers/llm/LlmParametersProgrammer.ts +90 -90
- package/src/programmers/llm/LlmSchemaProgrammer.ts +143 -143
- package/src/programmers/misc/MiscAssertCloneProgrammer.ts +95 -95
- package/src/programmers/misc/MiscAssertPruneProgrammer.ts +116 -116
- package/src/programmers/misc/MiscCloneProgrammer.ts +1032 -1032
- package/src/programmers/misc/MiscIsCloneProgrammer.ts +99 -99
- package/src/programmers/misc/MiscIsPruneProgrammer.ts +97 -97
- package/src/programmers/misc/MiscLiteralsProgrammer.ts +80 -80
- package/src/programmers/misc/MiscPruneProgrammer.ts +728 -728
- package/src/programmers/misc/MiscValidateCloneProgrammer.ts +111 -111
- package/src/programmers/misc/MiscValidatePruneProgrammer.ts +113 -113
- package/src/programmers/notations/NotationAssertGeneralProgrammer.ts +101 -101
- package/src/programmers/notations/NotationGeneralProgrammer.ts +984 -984
- package/src/programmers/notations/NotationIsGeneralProgrammer.ts +105 -105
- package/src/programmers/notations/NotationValidateGeneralProgrammer.ts +119 -119
- package/src/programmers/protobuf/ProtobufAssertDecodeProgrammer.ts +98 -98
- package/src/programmers/protobuf/ProtobufAssertEncodeProgrammer.ts +102 -102
- package/src/programmers/protobuf/ProtobufDecodeProgrammer.ts +654 -654
- package/src/programmers/protobuf/ProtobufEncodeProgrammer.ts +945 -945
- package/src/programmers/protobuf/ProtobufIsDecodeProgrammer.ts +109 -109
- package/src/programmers/protobuf/ProtobufIsEncodeProgrammer.ts +98 -98
- package/src/programmers/protobuf/ProtobufMessageProgrammer.ts +179 -179
- package/src/programmers/protobuf/ProtobufValidateDecodeProgrammer.ts +92 -92
- package/src/programmers/protobuf/ProtobufValidateEncodeProgrammer.ts +119 -119
- package/src/protobuf.ts +868 -868
- package/src/reflect.ts +57 -57
- package/src/schemas/json/IJsonApplication.ts +73 -73
- package/src/schemas/json/IJsonSchemaCollection.ts +29 -29
- package/src/schemas/json/__IJsonApplication.ts +63 -63
- package/src/schemas/llm/ILlmApplicationOfValidate.ts +55 -55
- package/src/schemas/llm/ILlmFunctionOfValidate.ts +39 -39
- package/src/schemas/metadata/IMetadata.ts +35 -35
- package/src/schemas/metadata/IMetadataAlias.ts +6 -6
- package/src/schemas/metadata/IMetadataAliasType.ts +12 -12
- package/src/schemas/metadata/IMetadataApplication.ts +7 -7
- package/src/schemas/metadata/IMetadataArray.ts +6 -6
- package/src/schemas/metadata/IMetadataComponents.ts +11 -11
- package/src/schemas/metadata/IMetadataConstantValue.ts +11 -11
- package/src/schemas/metadata/IMetadataDictionary.ts +11 -11
- package/src/schemas/metadata/IMetadataMap.ts +8 -8
- package/src/schemas/metadata/IMetadataNative.ts +6 -6
- package/src/schemas/metadata/IMetadataObject.ts +6 -6
- package/src/schemas/metadata/IMetadataObjectType.ts +13 -13
- package/src/schemas/metadata/IMetadataSet.ts +7 -7
- package/src/schemas/metadata/IMetadataTemplate.ts +7 -7
- package/src/schemas/metadata/IMetadataTuple.ts +6 -6
- package/src/schemas/metadata/IMetadataTypeTag.ts +16 -16
- package/src/schemas/metadata/Metadata.ts +669 -669
- package/src/schemas/metadata/MetadataAlias.ts +46 -46
- package/src/schemas/metadata/MetadataAliasType.ts +63 -63
- package/src/schemas/metadata/MetadataApplication.ts +44 -44
- package/src/schemas/metadata/MetadataArray.ts +49 -49
- package/src/schemas/metadata/MetadataAtomic.ts +87 -87
- package/src/schemas/metadata/MetadataComponents.ts +98 -98
- package/src/schemas/metadata/MetadataConstantValue.ts +62 -62
- package/src/schemas/metadata/MetadataMap.ts +48 -48
- package/src/schemas/metadata/MetadataNative.ts +44 -44
- package/src/schemas/metadata/MetadataObject.ts +48 -48
- package/src/schemas/metadata/MetadataObjectType.ts +149 -149
- package/src/schemas/metadata/MetadataParameter.ts +54 -54
- package/src/schemas/metadata/MetadataProperty.ts +59 -59
- package/src/schemas/metadata/MetadataSet.ts +45 -45
- package/src/schemas/metadata/MetadataTemplate.ts +80 -80
- package/src/schemas/metadata/MetadataTuple.ts +32 -32
- package/src/schemas/protobuf/IProtobufProperty.ts +6 -6
- package/src/schemas/protobuf/IProtobufPropertyType.ts +37 -37
- package/src/schemas/protobuf/IProtobufSchema.ts +50 -50
- package/src/tags/Example.ts +24 -24
- package/src/tags/Examples.ts +16 -16
- package/src/tags/Format.ts +50 -50
- package/src/tags/JsonSchemaPlugin.ts +8 -8
- package/src/tags/Sequence.ts +10 -10
- package/src/tags/TagBase.ts +82 -82
- package/src/tags/Type.ts +32 -32
- package/src/tags/UniqueItems.ts +14 -14
- package/src/tags/index.ts +21 -21
- package/src/transform.ts +35 -35
- package/src/transformers/CallExpressionTransformer.ts +547 -547
- package/src/transformers/FileTransformer.ts +136 -136
- package/src/transformers/IProgrammerProps.ts +11 -11
- package/src/transformers/ITransformOptions.ts +62 -62
- package/src/transformers/ITransformProps.ts +9 -9
- package/src/transformers/ITypiaContext.ts +18 -18
- package/src/transformers/ImportTransformer.ts +81 -81
- package/src/transformers/NodeTransformer.ts +17 -17
- package/src/transformers/TransformerError.ts +60 -60
- package/src/transformers/features/AssertTransformer.ts +24 -24
- package/src/transformers/features/CreateAssertTransformer.ts +24 -24
- package/src/transformers/features/CreateIsTransformer.ts +18 -18
- package/src/transformers/features/CreateRandomTransformer.ts +43 -43
- package/src/transformers/features/CreateValidateTransformer.ts +18 -18
- package/src/transformers/features/IsTransformer.ts +18 -18
- package/src/transformers/features/RandomTransformer.ts +41 -41
- package/src/transformers/features/ValidateTransformer.ts +18 -18
- package/src/transformers/features/functional/FunctionalGenericTransformer.ts +57 -57
- package/src/transformers/features/http/CreateHttpAssertFormDataTransformer.ts +13 -13
- package/src/transformers/features/http/CreateHttpAssertHeadersTransformer.ts +13 -13
- package/src/transformers/features/http/CreateHttpAssertQueryTransformer.ts +13 -13
- package/src/transformers/features/http/CreateHttpFormDataTransformer.ts +13 -13
- package/src/transformers/features/http/CreateHttpHeadersTransformer.ts +13 -13
- package/src/transformers/features/http/CreateHttpIsFormDataTransformer.ts +13 -13
- package/src/transformers/features/http/CreateHttpIsHeadersTransformer.ts +13 -13
- package/src/transformers/features/http/CreateHttpIsQueryTransformer.ts +13 -13
- package/src/transformers/features/http/CreateHttpParameterTransformer.ts +13 -13
- package/src/transformers/features/http/CreateHttpQueryTransformer.ts +13 -13
- package/src/transformers/features/http/CreateHttpValidateFormDataTransformer.ts +13 -13
- package/src/transformers/features/http/CreateHttpValidateHeadersTransformer.ts +13 -13
- package/src/transformers/features/http/CreateHttpValidateQueryTransformer.ts +13 -13
- package/src/transformers/features/http/HttpAssertFormDataTransformer.ts +13 -13
- package/src/transformers/features/http/HttpAssertHeadersTransformer.ts +13 -13
- package/src/transformers/features/http/HttpAssertQueryTransformer.ts +13 -13
- package/src/transformers/features/http/HttpFormDataTransformer.ts +13 -13
- package/src/transformers/features/http/HttpHeadersTransformer.ts +13 -13
- package/src/transformers/features/http/HttpIsFormDataTransformer.ts +13 -13
- package/src/transformers/features/http/HttpIsHeadersTransformer.ts +13 -13
- package/src/transformers/features/http/HttpIsQueryTransformer.ts +13 -13
- package/src/transformers/features/http/HttpParameterTransformer.ts +13 -13
- package/src/transformers/features/http/HttpQueryTransformer.ts +13 -13
- package/src/transformers/features/http/HttpValidateFormDataTransformer.ts +13 -13
- package/src/transformers/features/http/HttpValidateHeadersTransformer.ts +13 -13
- package/src/transformers/features/http/HttpValidateQueryTransformer.ts +13 -13
- package/src/transformers/features/json/JsonApplicationTransformer.ts +105 -105
- package/src/transformers/features/json/JsonAssertParseTransformer.ts +13 -13
- package/src/transformers/features/json/JsonAssertStringifyTransformer.ts +13 -13
- package/src/transformers/features/json/JsonCreateAssertParseTransformer.ts +13 -13
- package/src/transformers/features/json/JsonCreateAssertStringifyTransformer.ts +13 -13
- package/src/transformers/features/json/JsonCreateIsParseTransformer.ts +13 -13
- package/src/transformers/features/json/JsonCreateIsStringifyTransformer.ts +13 -13
- package/src/transformers/features/json/JsonCreateStringifyTransformer.ts +13 -13
- package/src/transformers/features/json/JsonCreateValidateParseTransformer.ts +13 -13
- package/src/transformers/features/json/JsonCreateValidateStringifyProgrammer.ts +13 -13
- package/src/transformers/features/json/JsonIsParseTransformer.ts +13 -13
- package/src/transformers/features/json/JsonIsStringifyTransformer.ts +13 -13
- package/src/transformers/features/json/JsonSchemasTransformer.ts +143 -143
- package/src/transformers/features/json/JsonStringifyTransformer.ts +13 -13
- package/src/transformers/features/json/JsonValidateParseTransformer.ts +13 -13
- package/src/transformers/features/json/JsonValidateStringifyTransformer.ts +13 -13
- package/src/transformers/features/llm/LlmApplicationOfValidateTransformer.ts +115 -115
- package/src/transformers/features/llm/LlmApplicationTransformer.ts +113 -113
- package/src/transformers/features/llm/LlmParametersTransformer.ts +89 -89
- package/src/transformers/features/llm/LlmSchemaTransformer.ts +130 -130
- package/src/transformers/features/misc/MiscAssertCloneTransformer.ts +13 -13
- package/src/transformers/features/misc/MiscAssertPruneTransformer.ts +13 -13
- package/src/transformers/features/misc/MiscCloneTransformer.ts +13 -13
- package/src/transformers/features/misc/MiscCreateAssertCloneTransformer.ts +13 -13
- package/src/transformers/features/misc/MiscCreateAssertPruneTransformer.ts +13 -13
- package/src/transformers/features/misc/MiscCreateCloneTransformer.ts +13 -13
- package/src/transformers/features/misc/MiscCreateIsCloneTransformer.ts +13 -13
- package/src/transformers/features/misc/MiscCreateIsPruneTransformer.ts +13 -13
- package/src/transformers/features/misc/MiscCreatePruneTransformer.ts +13 -13
- package/src/transformers/features/misc/MiscCreateValidateCloneTransformer.ts +13 -13
- package/src/transformers/features/misc/MiscCreateValidatePruneTransformer.ts +13 -13
- package/src/transformers/features/misc/MiscIsCloneTransformer.ts +13 -13
- package/src/transformers/features/misc/MiscIsPruneTransformer.ts +13 -13
- package/src/transformers/features/misc/MiscLiteralsTransformer.ts +35 -35
- package/src/transformers/features/misc/MiscPruneTransformer.ts +13 -13
- package/src/transformers/features/misc/MiscValidateCloneTransformer.ts +13 -13
- package/src/transformers/features/misc/MiscValidatePruneTransformer.ts +13 -13
- package/src/transformers/features/notations/NotationAssertGeneralTransformer.ts +20 -20
- package/src/transformers/features/notations/NotationCreateAssertGeneralTransformer.ts +20 -20
- package/src/transformers/features/notations/NotationCreateGeneralTransformer.ts +20 -20
- package/src/transformers/features/notations/NotationCreateIsGeneralTransformer.ts +20 -20
- package/src/transformers/features/notations/NotationCreateValidateGeneralTransformer.ts +20 -20
- package/src/transformers/features/notations/NotationGeneralTransformer.ts +18 -18
- package/src/transformers/features/notations/NotationIsGeneralTransformer.ts +20 -20
- package/src/transformers/features/notations/NotationValidateGeneralTransformer.ts +20 -20
- package/src/transformers/features/protobuf/ProtobufAssertDecodeTransformer.ts +13 -13
- package/src/transformers/features/protobuf/ProtobufAssertEncodeTransformer.ts +13 -13
- package/src/transformers/features/protobuf/ProtobufCreateAssertDecodeTransformer.ts +13 -13
- package/src/transformers/features/protobuf/ProtobufCreateAssertEncodeTransformer.ts +13 -13
- package/src/transformers/features/protobuf/ProtobufCreateDecodeTransformer.ts +13 -13
- package/src/transformers/features/protobuf/ProtobufCreateEncodeTransformer.ts +13 -13
- package/src/transformers/features/protobuf/ProtobufCreateIsDecodeTransformer.ts +13 -13
- package/src/transformers/features/protobuf/ProtobufCreateIsEncodeTransformer.ts +13 -13
- package/src/transformers/features/protobuf/ProtobufCreateValidateDecodeTransformer.ts +13 -13
- package/src/transformers/features/protobuf/ProtobufCreateValidateEncodeTransformer.ts +13 -13
- package/src/transformers/features/protobuf/ProtobufDecodeTransformer.ts +13 -13
- package/src/transformers/features/protobuf/ProtobufEncodeTransformer.ts +13 -13
- package/src/transformers/features/protobuf/ProtobufIsDecodeTransformer.ts +13 -13
- package/src/transformers/features/protobuf/ProtobufIsEncodeTransformer.ts +13 -13
- package/src/transformers/features/protobuf/ProtobufMessageTransformer.ts +35 -35
- package/src/transformers/features/protobuf/ProtobufValidateDecodeTransformer.ts +13 -13
- package/src/transformers/features/protobuf/ProtobufValidateEncodeTransformer.ts +13 -13
- package/src/transformers/features/reflect/ReflectMetadataTransformer.ts +69 -69
- package/src/transformers/features/reflect/ReflectNameTransformer.ts +82 -82
- package/src/transformers/internal/GenericTransformer.ts +101 -101
- package/src/utils/MapUtil.ts +14 -14
- package/src/utils/NamingConvention.ts +94 -94
- package/src/utils/ProtobufNameEncoder.ts +32 -32
- package/src/utils/StringUtil.ts +16 -16
|
@@ -1,1190 +1,1190 @@
|
|
|
1
|
-
import { OpenApi } from "@samchon/openapi";
|
|
2
|
-
import ts from "typescript";
|
|
3
|
-
|
|
4
|
-
import { ExpressionFactory } from "../factories/ExpressionFactory";
|
|
5
|
-
import { IdentifierFactory } from "../factories/IdentifierFactory";
|
|
6
|
-
import { LiteralFactory } from "../factories/LiteralFactory";
|
|
7
|
-
import { MetadataCollection } from "../factories/MetadataCollection";
|
|
8
|
-
import { MetadataCommentTagFactory } from "../factories/MetadataCommentTagFactory";
|
|
9
|
-
import { MetadataFactory } from "../factories/MetadataFactory";
|
|
10
|
-
import { StatementFactory } from "../factories/StatementFactory";
|
|
11
|
-
import { TemplateFactory } from "../factories/TemplateFactory";
|
|
12
|
-
import { TypeFactory } from "../factories/TypeFactory";
|
|
13
|
-
|
|
14
|
-
import { Metadata } from "../schemas/metadata/Metadata";
|
|
15
|
-
import { MetadataArray } from "../schemas/metadata/MetadataArray";
|
|
16
|
-
import { MetadataArrayType } from "../schemas/metadata/MetadataArrayType";
|
|
17
|
-
import { MetadataAtomic } from "../schemas/metadata/MetadataAtomic";
|
|
18
|
-
import { MetadataMap } from "../schemas/metadata/MetadataMap";
|
|
19
|
-
import { MetadataObjectType } from "../schemas/metadata/MetadataObjectType";
|
|
20
|
-
import { MetadataSet } from "../schemas/metadata/MetadataSet";
|
|
21
|
-
import { MetadataTemplate } from "../schemas/metadata/MetadataTemplate";
|
|
22
|
-
import { MetadataTuple } from "../schemas/metadata/MetadataTuple";
|
|
23
|
-
import { MetadataTupleType } from "../schemas/metadata/MetadataTupleType";
|
|
24
|
-
|
|
25
|
-
import { ITypiaContext } from "../transformers/ITypiaContext";
|
|
26
|
-
import { TransformerError } from "../transformers/TransformerError";
|
|
27
|
-
|
|
28
|
-
import { StringUtil } from "../utils/StringUtil";
|
|
29
|
-
|
|
30
|
-
import { FeatureProgrammer } from "./FeatureProgrammer";
|
|
31
|
-
import { FunctionProgrammer } from "./helpers/FunctionProgrammer";
|
|
32
|
-
import { RandomJoiner } from "./helpers/RandomJoiner";
|
|
33
|
-
import { json_schema_array } from "./internal/json_schema_array";
|
|
34
|
-
import { json_schema_bigint } from "./internal/json_schema_bigint";
|
|
35
|
-
import { json_schema_boolean } from "./internal/json_schema_boolean";
|
|
36
|
-
import { json_schema_number } from "./internal/json_schema_number";
|
|
37
|
-
import { json_schema_string } from "./internal/json_schema_string";
|
|
38
|
-
|
|
39
|
-
export namespace RandomProgrammer {
|
|
40
|
-
export interface IProps {
|
|
41
|
-
context: ITypiaContext;
|
|
42
|
-
modulo: ts.LeftHandSideExpression;
|
|
43
|
-
type: ts.Type;
|
|
44
|
-
name: string | undefined;
|
|
45
|
-
init: ts.Expression | undefined;
|
|
46
|
-
}
|
|
47
|
-
export interface IDecomposeProps {
|
|
48
|
-
context: ITypiaContext;
|
|
49
|
-
functor: FunctionProgrammer;
|
|
50
|
-
type: ts.Type;
|
|
51
|
-
name: string | undefined;
|
|
52
|
-
init: ts.Expression | undefined;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export const decompose = (
|
|
56
|
-
props: IDecomposeProps,
|
|
57
|
-
): FeatureProgrammer.IDecomposed => {
|
|
58
|
-
const collection: MetadataCollection = new MetadataCollection();
|
|
59
|
-
const result = MetadataFactory.analyze({
|
|
60
|
-
checker: props.context.checker,
|
|
61
|
-
transformer: props.context.transformer,
|
|
62
|
-
options: {
|
|
63
|
-
escape: false,
|
|
64
|
-
constant: true,
|
|
65
|
-
absorb: true,
|
|
66
|
-
validate: (meta) => {
|
|
67
|
-
const output: string[] = [];
|
|
68
|
-
if (meta.natives.some((native) => native.name === "WeakSet"))
|
|
69
|
-
output.push(`WeakSet is not supported.`);
|
|
70
|
-
else if (meta.natives.some((native) => native.name === "WeakMap"))
|
|
71
|
-
output.push(`WeakMap is not supported.`);
|
|
72
|
-
return output;
|
|
73
|
-
},
|
|
74
|
-
},
|
|
75
|
-
collection,
|
|
76
|
-
type: props.type,
|
|
77
|
-
});
|
|
78
|
-
if (result.success === false)
|
|
79
|
-
throw TransformerError.from({
|
|
80
|
-
code: props.functor.method,
|
|
81
|
-
errors: result.errors,
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
// GENERATE FUNCTION
|
|
85
|
-
const functions: Record<string, ts.VariableStatement> = Object.fromEntries([
|
|
86
|
-
...write_object_functions({
|
|
87
|
-
context: props.context,
|
|
88
|
-
functor: props.functor,
|
|
89
|
-
collection,
|
|
90
|
-
}).map((v, i) => [Prefix.object(i), v]),
|
|
91
|
-
...write_array_functions({
|
|
92
|
-
context: props.context,
|
|
93
|
-
functor: props.functor,
|
|
94
|
-
collection,
|
|
95
|
-
}).map((v, i) => [Prefix.array(i), v]),
|
|
96
|
-
...write_tuple_functions({
|
|
97
|
-
context: props.context,
|
|
98
|
-
functor: props.functor,
|
|
99
|
-
collection,
|
|
100
|
-
}).map((v, i) => [Prefix.tuple(i), v]),
|
|
101
|
-
]);
|
|
102
|
-
const arrow: ts.ArrowFunction = ts.factory.createArrowFunction(
|
|
103
|
-
undefined,
|
|
104
|
-
undefined,
|
|
105
|
-
[
|
|
106
|
-
IdentifierFactory.parameter(
|
|
107
|
-
"generator",
|
|
108
|
-
ts.factory.createTypeReferenceNode("Partial", [
|
|
109
|
-
props.context.importer.type({
|
|
110
|
-
file: "typia",
|
|
111
|
-
name: "IRandomGenerator",
|
|
112
|
-
}),
|
|
113
|
-
]),
|
|
114
|
-
props.init ?? ts.factory.createToken(ts.SyntaxKind.QuestionToken),
|
|
115
|
-
),
|
|
116
|
-
],
|
|
117
|
-
props.context.importer.type({
|
|
118
|
-
file: "typia",
|
|
119
|
-
name: "Resolved",
|
|
120
|
-
arguments: [
|
|
121
|
-
ts.factory.createTypeReferenceNode(
|
|
122
|
-
props.name ??
|
|
123
|
-
TypeFactory.getFullName({
|
|
124
|
-
checker: props.context.checker,
|
|
125
|
-
type: props.type,
|
|
126
|
-
}),
|
|
127
|
-
),
|
|
128
|
-
],
|
|
129
|
-
}),
|
|
130
|
-
undefined,
|
|
131
|
-
ts.factory.createBlock(
|
|
132
|
-
[
|
|
133
|
-
ts.factory.createExpressionStatement(
|
|
134
|
-
ts.factory.createBinaryExpression(
|
|
135
|
-
ts.factory.createIdentifier("_generator"),
|
|
136
|
-
ts.SyntaxKind.EqualsToken,
|
|
137
|
-
ts.factory.createIdentifier("generator"),
|
|
138
|
-
),
|
|
139
|
-
),
|
|
140
|
-
ts.factory.createReturnStatement(
|
|
141
|
-
decode({
|
|
142
|
-
context: props.context,
|
|
143
|
-
functor: props.functor,
|
|
144
|
-
explore: {
|
|
145
|
-
function: false,
|
|
146
|
-
recursive: false,
|
|
147
|
-
},
|
|
148
|
-
metadata: result.data,
|
|
149
|
-
}),
|
|
150
|
-
),
|
|
151
|
-
],
|
|
152
|
-
true,
|
|
153
|
-
),
|
|
154
|
-
);
|
|
155
|
-
return {
|
|
156
|
-
functions,
|
|
157
|
-
statements: [
|
|
158
|
-
StatementFactory.mut({
|
|
159
|
-
name: "_generator",
|
|
160
|
-
type: ts.factory.createUnionTypeNode([
|
|
161
|
-
ts.factory.createTypeReferenceNode("Partial", [
|
|
162
|
-
props.context.importer.type({
|
|
163
|
-
file: "typia",
|
|
164
|
-
name: "IRandomGenerator",
|
|
165
|
-
}),
|
|
166
|
-
]),
|
|
167
|
-
ts.factory.createTypeReferenceNode("undefined"),
|
|
168
|
-
]),
|
|
169
|
-
}),
|
|
170
|
-
],
|
|
171
|
-
arrow,
|
|
172
|
-
};
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
export const write = (props: IProps) => {
|
|
176
|
-
const functor: FunctionProgrammer = new FunctionProgrammer(
|
|
177
|
-
props.modulo.getText(),
|
|
178
|
-
);
|
|
179
|
-
const result: FeatureProgrammer.IDecomposed = decompose({
|
|
180
|
-
...props,
|
|
181
|
-
functor,
|
|
182
|
-
});
|
|
183
|
-
return FeatureProgrammer.writeDecomposed({
|
|
184
|
-
modulo: props.modulo,
|
|
185
|
-
functor,
|
|
186
|
-
result,
|
|
187
|
-
});
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
const write_object_functions = (props: {
|
|
191
|
-
context: ITypiaContext;
|
|
192
|
-
functor: FunctionProgrammer;
|
|
193
|
-
collection: MetadataCollection;
|
|
194
|
-
}): ts.VariableStatement[] =>
|
|
195
|
-
props.collection.objects().map((obj, i) =>
|
|
196
|
-
StatementFactory.constant({
|
|
197
|
-
name: Prefix.object(i),
|
|
198
|
-
value: ts.factory.createArrowFunction(
|
|
199
|
-
undefined,
|
|
200
|
-
undefined,
|
|
201
|
-
[
|
|
202
|
-
IdentifierFactory.parameter(
|
|
203
|
-
"_recursive",
|
|
204
|
-
TypeFactory.keyword("boolean"),
|
|
205
|
-
ts.factory.createIdentifier(String(obj.recursive)),
|
|
206
|
-
),
|
|
207
|
-
IdentifierFactory.parameter(
|
|
208
|
-
"_depth",
|
|
209
|
-
TypeFactory.keyword("number"),
|
|
210
|
-
ExpressionFactory.number(0),
|
|
211
|
-
),
|
|
212
|
-
],
|
|
213
|
-
TypeFactory.keyword("any"),
|
|
214
|
-
undefined,
|
|
215
|
-
RandomJoiner.object({
|
|
216
|
-
decode: (metadata) =>
|
|
217
|
-
decode({
|
|
218
|
-
context: props.context,
|
|
219
|
-
functor: props.functor,
|
|
220
|
-
explore: {
|
|
221
|
-
recursive: obj.recursive,
|
|
222
|
-
function: true,
|
|
223
|
-
},
|
|
224
|
-
metadata,
|
|
225
|
-
}),
|
|
226
|
-
object: obj,
|
|
227
|
-
}),
|
|
228
|
-
),
|
|
229
|
-
}),
|
|
230
|
-
);
|
|
231
|
-
|
|
232
|
-
const write_array_functions = (props: {
|
|
233
|
-
context: ITypiaContext;
|
|
234
|
-
functor: FunctionProgrammer;
|
|
235
|
-
collection: MetadataCollection;
|
|
236
|
-
}): ts.VariableStatement[] =>
|
|
237
|
-
props.collection
|
|
238
|
-
.arrays()
|
|
239
|
-
.filter((a) => a.recursive)
|
|
240
|
-
.map((array, i) =>
|
|
241
|
-
StatementFactory.constant({
|
|
242
|
-
name: Prefix.array(i),
|
|
243
|
-
value: ts.factory.createArrowFunction(
|
|
244
|
-
undefined,
|
|
245
|
-
undefined,
|
|
246
|
-
[
|
|
247
|
-
IdentifierFactory.parameter(
|
|
248
|
-
"_schema",
|
|
249
|
-
TypeFactory.keyword("boolean"),
|
|
250
|
-
),
|
|
251
|
-
IdentifierFactory.parameter(
|
|
252
|
-
"_recursive",
|
|
253
|
-
TypeFactory.keyword("boolean"),
|
|
254
|
-
ts.factory.createTrue(),
|
|
255
|
-
),
|
|
256
|
-
IdentifierFactory.parameter(
|
|
257
|
-
"_depth",
|
|
258
|
-
TypeFactory.keyword("number"),
|
|
259
|
-
ExpressionFactory.number(0),
|
|
260
|
-
),
|
|
261
|
-
],
|
|
262
|
-
TypeFactory.keyword("any"),
|
|
263
|
-
undefined,
|
|
264
|
-
RandomJoiner.array({
|
|
265
|
-
decode: (metadata) =>
|
|
266
|
-
decode({
|
|
267
|
-
context: props.context,
|
|
268
|
-
functor: props.functor,
|
|
269
|
-
explore: {
|
|
270
|
-
recursive: true,
|
|
271
|
-
function: true,
|
|
272
|
-
},
|
|
273
|
-
metadata,
|
|
274
|
-
}),
|
|
275
|
-
recursive: true,
|
|
276
|
-
expression: coalesce({
|
|
277
|
-
context: props.context,
|
|
278
|
-
method: "array",
|
|
279
|
-
internal: "randomArray",
|
|
280
|
-
}),
|
|
281
|
-
array,
|
|
282
|
-
schema: undefined,
|
|
283
|
-
}),
|
|
284
|
-
),
|
|
285
|
-
}),
|
|
286
|
-
);
|
|
287
|
-
|
|
288
|
-
const write_tuple_functions = (props: {
|
|
289
|
-
context: ITypiaContext;
|
|
290
|
-
functor: FunctionProgrammer;
|
|
291
|
-
collection: MetadataCollection;
|
|
292
|
-
}): ts.VariableStatement[] =>
|
|
293
|
-
props.collection
|
|
294
|
-
.tuples()
|
|
295
|
-
.filter((a) => a.recursive)
|
|
296
|
-
.map((tuple, i) =>
|
|
297
|
-
StatementFactory.constant({
|
|
298
|
-
name: Prefix.tuple(i),
|
|
299
|
-
value: ts.factory.createArrowFunction(
|
|
300
|
-
undefined,
|
|
301
|
-
undefined,
|
|
302
|
-
[
|
|
303
|
-
IdentifierFactory.parameter(
|
|
304
|
-
"_recursive",
|
|
305
|
-
TypeFactory.keyword("boolean"),
|
|
306
|
-
ts.factory.createTrue(),
|
|
307
|
-
),
|
|
308
|
-
IdentifierFactory.parameter(
|
|
309
|
-
"_depth",
|
|
310
|
-
TypeFactory.keyword("number"),
|
|
311
|
-
ExpressionFactory.number(0),
|
|
312
|
-
),
|
|
313
|
-
],
|
|
314
|
-
TypeFactory.keyword("any"),
|
|
315
|
-
undefined,
|
|
316
|
-
RandomJoiner.tuple({
|
|
317
|
-
decode: (metadata) =>
|
|
318
|
-
decode({
|
|
319
|
-
context: props.context,
|
|
320
|
-
functor: props.functor,
|
|
321
|
-
explore: {
|
|
322
|
-
function: true,
|
|
323
|
-
recursive: true,
|
|
324
|
-
},
|
|
325
|
-
metadata,
|
|
326
|
-
}),
|
|
327
|
-
elements: tuple.elements,
|
|
328
|
-
}),
|
|
329
|
-
),
|
|
330
|
-
}),
|
|
331
|
-
);
|
|
332
|
-
|
|
333
|
-
/* -----------------------------------------------------------
|
|
334
|
-
DECODERS
|
|
335
|
-
----------------------------------------------------------- */
|
|
336
|
-
const decode = (props: {
|
|
337
|
-
context: ITypiaContext;
|
|
338
|
-
functor: FunctionProgrammer;
|
|
339
|
-
explore: IExplore;
|
|
340
|
-
metadata: Metadata;
|
|
341
|
-
}): ts.Expression => {
|
|
342
|
-
const expressions: ts.Expression[] = [];
|
|
343
|
-
if (props.metadata.any === true)
|
|
344
|
-
expressions.push(ts.factory.createStringLiteral("any type used..."));
|
|
345
|
-
|
|
346
|
-
// NULL COALESCING
|
|
347
|
-
if (
|
|
348
|
-
props.metadata.isRequired() === false ||
|
|
349
|
-
props.metadata.functions.length !== 0
|
|
350
|
-
)
|
|
351
|
-
expressions.push(ts.factory.createIdentifier("undefined"));
|
|
352
|
-
if (props.metadata.nullable === true)
|
|
353
|
-
expressions.push(ts.factory.createNull());
|
|
354
|
-
|
|
355
|
-
// CONSTANT TYPES
|
|
356
|
-
for (const constant of props.metadata.constants)
|
|
357
|
-
for (const { value } of constant.values)
|
|
358
|
-
expressions.push(
|
|
359
|
-
constant.type === "boolean"
|
|
360
|
-
? value === true
|
|
361
|
-
? ts.factory.createTrue()
|
|
362
|
-
: ts.factory.createFalse()
|
|
363
|
-
: constant.type === "bigint"
|
|
364
|
-
? ExpressionFactory.bigint(value as bigint)
|
|
365
|
-
: constant.type === "number"
|
|
366
|
-
? ExpressionFactory.number(value as number)
|
|
367
|
-
: ts.factory.createStringLiteral(value as string),
|
|
368
|
-
);
|
|
369
|
-
|
|
370
|
-
// ATOMIC VARIABLES
|
|
371
|
-
for (const template of props.metadata.templates)
|
|
372
|
-
expressions.push(
|
|
373
|
-
decode_template({
|
|
374
|
-
...props,
|
|
375
|
-
template,
|
|
376
|
-
}),
|
|
377
|
-
);
|
|
378
|
-
for (const atomic of props.metadata.atomics)
|
|
379
|
-
expressions.push(
|
|
380
|
-
...decode_atomic({
|
|
381
|
-
context: props.context,
|
|
382
|
-
atomic,
|
|
383
|
-
}),
|
|
384
|
-
);
|
|
385
|
-
|
|
386
|
-
// INSTANCE TYPES
|
|
387
|
-
if (props.metadata.escaped)
|
|
388
|
-
expressions.push(
|
|
389
|
-
decode({
|
|
390
|
-
...props,
|
|
391
|
-
metadata: props.metadata.escaped.returns,
|
|
392
|
-
}),
|
|
393
|
-
);
|
|
394
|
-
for (const array of props.metadata.arrays)
|
|
395
|
-
expressions.push(
|
|
396
|
-
...decode_array({
|
|
397
|
-
...props,
|
|
398
|
-
array,
|
|
399
|
-
}),
|
|
400
|
-
);
|
|
401
|
-
for (const tuple of props.metadata.tuples)
|
|
402
|
-
expressions.push(
|
|
403
|
-
decode_tuple({
|
|
404
|
-
...props,
|
|
405
|
-
tuple,
|
|
406
|
-
}),
|
|
407
|
-
);
|
|
408
|
-
for (const object of props.metadata.objects)
|
|
409
|
-
expressions.push(
|
|
410
|
-
decode_object({
|
|
411
|
-
...props,
|
|
412
|
-
object: object.type,
|
|
413
|
-
}),
|
|
414
|
-
);
|
|
415
|
-
for (const native of props.metadata.natives)
|
|
416
|
-
expressions.push(
|
|
417
|
-
decode_native({
|
|
418
|
-
context: props.context,
|
|
419
|
-
functor: props.functor,
|
|
420
|
-
explore: props.explore,
|
|
421
|
-
name: native.name,
|
|
422
|
-
}),
|
|
423
|
-
);
|
|
424
|
-
for (const set of props.metadata.sets)
|
|
425
|
-
expressions.push(
|
|
426
|
-
decode_set({
|
|
427
|
-
...props,
|
|
428
|
-
set,
|
|
429
|
-
}),
|
|
430
|
-
);
|
|
431
|
-
for (const entry of props.metadata.maps)
|
|
432
|
-
expressions.push(
|
|
433
|
-
decode_map({
|
|
434
|
-
...props,
|
|
435
|
-
map: entry,
|
|
436
|
-
}),
|
|
437
|
-
);
|
|
438
|
-
|
|
439
|
-
// PICK UP A TYPE
|
|
440
|
-
if (expressions.length === 1) return expressions[0]!;
|
|
441
|
-
return ts.factory.createCallExpression(
|
|
442
|
-
ts.factory.createCallExpression(
|
|
443
|
-
props.context.importer.internal("randomPick"),
|
|
444
|
-
undefined,
|
|
445
|
-
[
|
|
446
|
-
ts.factory.createArrayLiteralExpression(
|
|
447
|
-
expressions.map((expr) =>
|
|
448
|
-
ts.factory.createArrowFunction(
|
|
449
|
-
undefined,
|
|
450
|
-
undefined,
|
|
451
|
-
[],
|
|
452
|
-
undefined,
|
|
453
|
-
undefined,
|
|
454
|
-
expr,
|
|
455
|
-
),
|
|
456
|
-
),
|
|
457
|
-
true,
|
|
458
|
-
),
|
|
459
|
-
],
|
|
460
|
-
),
|
|
461
|
-
undefined,
|
|
462
|
-
undefined,
|
|
463
|
-
);
|
|
464
|
-
};
|
|
465
|
-
|
|
466
|
-
const decode_atomic = (props: {
|
|
467
|
-
context: ITypiaContext;
|
|
468
|
-
atomic: MetadataAtomic;
|
|
469
|
-
}) => {
|
|
470
|
-
const schemaList: OpenApi.IJsonSchema[] =
|
|
471
|
-
props.atomic.type === "boolean"
|
|
472
|
-
? json_schema_boolean(props.atomic)
|
|
473
|
-
: props.atomic.type === "string"
|
|
474
|
-
? json_schema_string(props.atomic)
|
|
475
|
-
: props.atomic.type === "bigint"
|
|
476
|
-
? json_schema_bigint(props.atomic)
|
|
477
|
-
: json_schema_number(props.atomic);
|
|
478
|
-
return schemaList.map((schema) => {
|
|
479
|
-
interface IComposed {
|
|
480
|
-
method: string;
|
|
481
|
-
internal: string;
|
|
482
|
-
arguments: ts.Expression[];
|
|
483
|
-
}
|
|
484
|
-
const composed = ((): IComposed => {
|
|
485
|
-
if (props.atomic.type === "string") {
|
|
486
|
-
const string: OpenApi.IJsonSchema.IString =
|
|
487
|
-
schema as OpenApi.IJsonSchema.IString;
|
|
488
|
-
if (string.format !== undefined) {
|
|
489
|
-
const format: string = string.format!;
|
|
490
|
-
if (format === "date-time")
|
|
491
|
-
return {
|
|
492
|
-
method: "datetime",
|
|
493
|
-
internal: "randomFormatDatetime",
|
|
494
|
-
arguments: [],
|
|
495
|
-
};
|
|
496
|
-
return {
|
|
497
|
-
method: format
|
|
498
|
-
.split("-")
|
|
499
|
-
.map((s, i) => (i === 0 ? s : StringUtil.capitalize(s)))
|
|
500
|
-
.join(""),
|
|
501
|
-
internal: `randomFormat${format
|
|
502
|
-
.split("-")
|
|
503
|
-
.map(StringUtil.capitalize)
|
|
504
|
-
.join("")}`,
|
|
505
|
-
arguments: [],
|
|
506
|
-
};
|
|
507
|
-
} else if (string.pattern !== undefined)
|
|
508
|
-
return {
|
|
509
|
-
method: "pattern",
|
|
510
|
-
internal: "randomPattern",
|
|
511
|
-
arguments: [
|
|
512
|
-
ts.factory.createNewExpression(
|
|
513
|
-
ts.factory.createIdentifier("RegExp"),
|
|
514
|
-
undefined,
|
|
515
|
-
[
|
|
516
|
-
ts.factory.createStringLiteral(
|
|
517
|
-
(schema as OpenApi.IJsonSchema.IString).pattern!,
|
|
518
|
-
),
|
|
519
|
-
],
|
|
520
|
-
),
|
|
521
|
-
],
|
|
522
|
-
};
|
|
523
|
-
} else if (props.atomic.type === "number") {
|
|
524
|
-
const number:
|
|
525
|
-
| OpenApi.IJsonSchema.INumber
|
|
526
|
-
| OpenApi.IJsonSchema.IInteger = schema as
|
|
527
|
-
| OpenApi.IJsonSchema.INumber
|
|
528
|
-
| OpenApi.IJsonSchema.IInteger;
|
|
529
|
-
if (number.type === "integer")
|
|
530
|
-
return {
|
|
531
|
-
method: "integer",
|
|
532
|
-
internal: "randomInteger",
|
|
533
|
-
arguments: [LiteralFactory.write(schema)],
|
|
534
|
-
};
|
|
535
|
-
}
|
|
536
|
-
return {
|
|
537
|
-
method: props.atomic.type,
|
|
538
|
-
internal: `random${StringUtil.capitalize(props.atomic.type)}`,
|
|
539
|
-
arguments: [LiteralFactory.write(schema)],
|
|
540
|
-
};
|
|
541
|
-
})();
|
|
542
|
-
return ts.factory.createCallExpression(
|
|
543
|
-
ExpressionFactory.coalesce(
|
|
544
|
-
ts.factory.createPropertyAccessChain(
|
|
545
|
-
ts.factory.createIdentifier("_generator"),
|
|
546
|
-
ts.factory.createToken(ts.SyntaxKind.QuestionDotToken),
|
|
547
|
-
ts.factory.createIdentifier(composed.method),
|
|
548
|
-
),
|
|
549
|
-
props.context.importer.internal(composed.internal),
|
|
550
|
-
),
|
|
551
|
-
undefined,
|
|
552
|
-
composed.arguments,
|
|
553
|
-
);
|
|
554
|
-
});
|
|
555
|
-
};
|
|
556
|
-
|
|
557
|
-
const decode_template = (props: {
|
|
558
|
-
context: ITypiaContext;
|
|
559
|
-
functor: FunctionProgrammer;
|
|
560
|
-
explore: IExplore;
|
|
561
|
-
template: MetadataTemplate;
|
|
562
|
-
}) =>
|
|
563
|
-
TemplateFactory.generate(
|
|
564
|
-
props.template.row.map((metadata) =>
|
|
565
|
-
decode({
|
|
566
|
-
...props,
|
|
567
|
-
metadata,
|
|
568
|
-
}),
|
|
569
|
-
),
|
|
570
|
-
);
|
|
571
|
-
|
|
572
|
-
const decode_array = (props: {
|
|
573
|
-
context: ITypiaContext;
|
|
574
|
-
functor: FunctionProgrammer;
|
|
575
|
-
explore: IExplore;
|
|
576
|
-
array: MetadataArray;
|
|
577
|
-
}): ts.Expression[] => {
|
|
578
|
-
const components: OpenApi.IComponents = {};
|
|
579
|
-
const schemaList: OpenApi.IJsonSchema.IArray[] = json_schema_array({
|
|
580
|
-
components,
|
|
581
|
-
array: props.array,
|
|
582
|
-
}) as OpenApi.IJsonSchema.IArray[];
|
|
583
|
-
if (props.array.type.recursive)
|
|
584
|
-
return schemaList.map((schema) =>
|
|
585
|
-
ts.factory.createCallExpression(
|
|
586
|
-
ts.factory.createIdentifier(
|
|
587
|
-
props.functor.useLocal(Prefix.array(props.array.type.index!)),
|
|
588
|
-
),
|
|
589
|
-
undefined,
|
|
590
|
-
[
|
|
591
|
-
ts.factory.createObjectLiteralExpression(
|
|
592
|
-
Object.entries(schema)
|
|
593
|
-
.filter(([key]) => key !== "items")
|
|
594
|
-
.map(([key, value]) =>
|
|
595
|
-
ts.factory.createPropertyAssignment(
|
|
596
|
-
key,
|
|
597
|
-
LiteralFactory.write(value),
|
|
598
|
-
),
|
|
599
|
-
),
|
|
600
|
-
true,
|
|
601
|
-
),
|
|
602
|
-
],
|
|
603
|
-
),
|
|
604
|
-
);
|
|
605
|
-
return schemaList.map((schema) =>
|
|
606
|
-
RandomJoiner.array({
|
|
607
|
-
decode: (metadata) =>
|
|
608
|
-
decode({
|
|
609
|
-
...props,
|
|
610
|
-
metadata,
|
|
611
|
-
}),
|
|
612
|
-
expression: coalesce({
|
|
613
|
-
context: props.context,
|
|
614
|
-
method: "array",
|
|
615
|
-
internal: "randomArray",
|
|
616
|
-
}),
|
|
617
|
-
array: props.array.type,
|
|
618
|
-
recursive: props.explore.recursive,
|
|
619
|
-
schema,
|
|
620
|
-
}),
|
|
621
|
-
);
|
|
622
|
-
};
|
|
623
|
-
|
|
624
|
-
const decode_tuple = (props: {
|
|
625
|
-
context: ITypiaContext;
|
|
626
|
-
functor: FunctionProgrammer;
|
|
627
|
-
explore: IExplore;
|
|
628
|
-
tuple: MetadataTuple;
|
|
629
|
-
}): ts.Expression =>
|
|
630
|
-
props.tuple.type.recursive
|
|
631
|
-
? ts.factory.createCallExpression(
|
|
632
|
-
ts.factory.createIdentifier(
|
|
633
|
-
props.functor.useLocal(Prefix.tuple(props.tuple.type.index!)),
|
|
634
|
-
),
|
|
635
|
-
undefined,
|
|
636
|
-
[
|
|
637
|
-
ts.factory.createTrue(),
|
|
638
|
-
props.explore.recursive
|
|
639
|
-
? ts.factory.createAdd(
|
|
640
|
-
ExpressionFactory.number(1),
|
|
641
|
-
ts.factory.createIdentifier("_depth"),
|
|
642
|
-
)
|
|
643
|
-
: ExpressionFactory.number(0),
|
|
644
|
-
],
|
|
645
|
-
)
|
|
646
|
-
: RandomJoiner.tuple({
|
|
647
|
-
decode: (metadata) =>
|
|
648
|
-
decode({
|
|
649
|
-
...props,
|
|
650
|
-
metadata,
|
|
651
|
-
}),
|
|
652
|
-
elements: props.tuple.type.elements,
|
|
653
|
-
});
|
|
654
|
-
|
|
655
|
-
const decode_object = (props: {
|
|
656
|
-
functor: FunctionProgrammer;
|
|
657
|
-
explore: IExplore;
|
|
658
|
-
object: MetadataObjectType;
|
|
659
|
-
}) =>
|
|
660
|
-
ts.factory.createCallExpression(
|
|
661
|
-
ts.factory.createIdentifier(
|
|
662
|
-
props.functor.useLocal(Prefix.object(props.object.index)),
|
|
663
|
-
),
|
|
664
|
-
undefined,
|
|
665
|
-
props.explore.function
|
|
666
|
-
? [
|
|
667
|
-
props.explore.recursive
|
|
668
|
-
? ts.factory.createTrue()
|
|
669
|
-
: ts.factory.createIdentifier("_recursive"),
|
|
670
|
-
ts.factory.createConditionalExpression(
|
|
671
|
-
ts.factory.createIdentifier("_recursive"),
|
|
672
|
-
undefined,
|
|
673
|
-
ts.factory.createAdd(
|
|
674
|
-
ExpressionFactory.number(1),
|
|
675
|
-
ts.factory.createIdentifier("_depth"),
|
|
676
|
-
),
|
|
677
|
-
undefined,
|
|
678
|
-
ts.factory.createIdentifier("_depth"),
|
|
679
|
-
),
|
|
680
|
-
]
|
|
681
|
-
: undefined,
|
|
682
|
-
);
|
|
683
|
-
|
|
684
|
-
/* -----------------------------------------------------------
|
|
685
|
-
NATIVE CLASSES
|
|
686
|
-
----------------------------------------------------------- */
|
|
687
|
-
const decode_set = (props: {
|
|
688
|
-
context: ITypiaContext;
|
|
689
|
-
functor: FunctionProgrammer;
|
|
690
|
-
explore: IExplore;
|
|
691
|
-
set: MetadataSet;
|
|
692
|
-
}) =>
|
|
693
|
-
ts.factory.createNewExpression(
|
|
694
|
-
ts.factory.createIdentifier("Set"),
|
|
695
|
-
undefined,
|
|
696
|
-
[
|
|
697
|
-
decode_array({
|
|
698
|
-
...props,
|
|
699
|
-
array: MetadataArray.create({
|
|
700
|
-
tags: [],
|
|
701
|
-
type: MetadataArrayType.create({
|
|
702
|
-
value: props.set.value,
|
|
703
|
-
recursive: false,
|
|
704
|
-
index: null,
|
|
705
|
-
nullables: [],
|
|
706
|
-
name: props.set.getName(),
|
|
707
|
-
}),
|
|
708
|
-
}),
|
|
709
|
-
})[0]!,
|
|
710
|
-
],
|
|
711
|
-
);
|
|
712
|
-
|
|
713
|
-
const decode_map = (props: {
|
|
714
|
-
context: ITypiaContext;
|
|
715
|
-
functor: FunctionProgrammer;
|
|
716
|
-
explore: IExplore;
|
|
717
|
-
map: MetadataMap;
|
|
718
|
-
}) =>
|
|
719
|
-
ts.factory.createNewExpression(
|
|
720
|
-
ts.factory.createIdentifier("Map"),
|
|
721
|
-
undefined,
|
|
722
|
-
[
|
|
723
|
-
decode_array({
|
|
724
|
-
...props,
|
|
725
|
-
array: MetadataArray.create({
|
|
726
|
-
tags: [],
|
|
727
|
-
type: MetadataArrayType.create({
|
|
728
|
-
name: props.map.getName(),
|
|
729
|
-
index: null,
|
|
730
|
-
recursive: false,
|
|
731
|
-
nullables: [],
|
|
732
|
-
value: Metadata.create({
|
|
733
|
-
...Metadata.initialize(),
|
|
734
|
-
tuples: [
|
|
735
|
-
(() => {
|
|
736
|
-
const type = MetadataTupleType.create({
|
|
737
|
-
name: `[${props.map.key.getName()}, ${props.map.value.getName()}]`,
|
|
738
|
-
index: null,
|
|
739
|
-
recursive: false,
|
|
740
|
-
nullables: [],
|
|
741
|
-
elements: [props.map.key, props.map.value],
|
|
742
|
-
});
|
|
743
|
-
type.of_map = true;
|
|
744
|
-
return MetadataTuple.create({
|
|
745
|
-
type,
|
|
746
|
-
tags: [],
|
|
747
|
-
});
|
|
748
|
-
})(),
|
|
749
|
-
],
|
|
750
|
-
}),
|
|
751
|
-
}),
|
|
752
|
-
}),
|
|
753
|
-
})[0]!,
|
|
754
|
-
],
|
|
755
|
-
);
|
|
756
|
-
|
|
757
|
-
const decode_native = (props: {
|
|
758
|
-
context: ITypiaContext;
|
|
759
|
-
functor: FunctionProgrammer;
|
|
760
|
-
explore: IExplore;
|
|
761
|
-
name: string;
|
|
762
|
-
}): ts.Expression => {
|
|
763
|
-
if (
|
|
764
|
-
props.name === "Boolean" ||
|
|
765
|
-
props.name === "Number" ||
|
|
766
|
-
props.name === "BigInt" ||
|
|
767
|
-
props.name === "String"
|
|
768
|
-
)
|
|
769
|
-
return decode_atomic({
|
|
770
|
-
context: props.context,
|
|
771
|
-
atomic: MetadataAtomic.create({
|
|
772
|
-
type: props.name.toLowerCase() as "string",
|
|
773
|
-
tags: [],
|
|
774
|
-
}),
|
|
775
|
-
})[0]!;
|
|
776
|
-
else if (props.name === "Date") return decode_native_date(props.context);
|
|
777
|
-
else if (
|
|
778
|
-
props.name === "Uint8Array" ||
|
|
779
|
-
props.name === "Uint8ClampedArray" ||
|
|
780
|
-
props.name === "Uint16Array" ||
|
|
781
|
-
props.name === "Uint32Array" ||
|
|
782
|
-
props.name === "BigUint64Array" ||
|
|
783
|
-
props.name === "Int8Array" ||
|
|
784
|
-
props.name === "Int16Array" ||
|
|
785
|
-
props.name === "Int32Array" ||
|
|
786
|
-
props.name === "BigInt64Array" ||
|
|
787
|
-
props.name === "Float32Array" ||
|
|
788
|
-
props.name === "Float64Array"
|
|
789
|
-
)
|
|
790
|
-
return decode_native_byte_array({
|
|
791
|
-
...props,
|
|
792
|
-
name: props.name,
|
|
793
|
-
});
|
|
794
|
-
else if (props.name === "ArrayBuffer" || props.name === "SharedArrayBuffer")
|
|
795
|
-
return decode_native_array_buffer({
|
|
796
|
-
...props,
|
|
797
|
-
name: props.name,
|
|
798
|
-
});
|
|
799
|
-
else if (props.name === "DataView") return decode_native_data_view(props);
|
|
800
|
-
else if (props.name === "Blob") return decode_native_blob(props);
|
|
801
|
-
else if (props.name === "File") return decode_native_file(props);
|
|
802
|
-
else if (props.name === "RegExp") return decode_regexp(props.context);
|
|
803
|
-
else
|
|
804
|
-
return ts.factory.createNewExpression(
|
|
805
|
-
ts.factory.createIdentifier(props.name),
|
|
806
|
-
undefined,
|
|
807
|
-
[],
|
|
808
|
-
);
|
|
809
|
-
};
|
|
810
|
-
|
|
811
|
-
const decode_native_date = (context: ITypiaContext) =>
|
|
812
|
-
ts.factory.createNewExpression(
|
|
813
|
-
ts.factory.createIdentifier("Date"),
|
|
814
|
-
undefined,
|
|
815
|
-
[
|
|
816
|
-
ts.factory.createCallExpression(
|
|
817
|
-
coalesce({
|
|
818
|
-
context,
|
|
819
|
-
method: "datetime",
|
|
820
|
-
internal: "randomFormatDatetime",
|
|
821
|
-
}),
|
|
822
|
-
undefined,
|
|
823
|
-
[],
|
|
824
|
-
),
|
|
825
|
-
],
|
|
826
|
-
);
|
|
827
|
-
|
|
828
|
-
const decode_native_byte_array = (props: {
|
|
829
|
-
context: ITypiaContext;
|
|
830
|
-
functor: FunctionProgrammer;
|
|
831
|
-
explore: IExplore;
|
|
832
|
-
name:
|
|
833
|
-
| "Uint8Array"
|
|
834
|
-
| "Uint8ClampedArray"
|
|
835
|
-
| "Uint16Array"
|
|
836
|
-
| "Uint32Array"
|
|
837
|
-
| "BigUint64Array"
|
|
838
|
-
| "Int8Array"
|
|
839
|
-
| "Int16Array"
|
|
840
|
-
| "Int32Array"
|
|
841
|
-
| "BigInt64Array"
|
|
842
|
-
| "Float32Array"
|
|
843
|
-
| "Float64Array";
|
|
844
|
-
}): ts.Expression => {
|
|
845
|
-
new BigInt64Array();
|
|
846
|
-
const [type, minimum, maximum]: [string, number, number] = (() => {
|
|
847
|
-
if (props.name === "Uint8Array" || props.name === "Uint8ClampedArray")
|
|
848
|
-
return ["uint32", 0, 255];
|
|
849
|
-
else if (props.name === "Uint16Array") return ["uint32", 0, 65535];
|
|
850
|
-
else if (props.name === "Uint32Array") return ["uint32", 0, 4294967295];
|
|
851
|
-
else if (props.name === "BigUint64Array")
|
|
852
|
-
return ["uint64", 0, 18446744073709551615];
|
|
853
|
-
else if (props.name === "Int8Array") return ["int32", -128, 127];
|
|
854
|
-
else if (props.name === "Int16Array") return ["int32", -32768, 32767];
|
|
855
|
-
else if (props.name === "Int32Array")
|
|
856
|
-
return ["int32", -2147483648, 2147483647];
|
|
857
|
-
else if (props.name === "BigInt64Array")
|
|
858
|
-
return ["uint64", -9223372036854775808, 9223372036854775807];
|
|
859
|
-
else if (props.name === "Float32Array")
|
|
860
|
-
return ["float", -1.175494351e38, 3.4028235e38];
|
|
861
|
-
return ["double", Number.MIN_VALUE, Number.MAX_VALUE];
|
|
862
|
-
})();
|
|
863
|
-
const atomic: "bigint" | "number" =
|
|
864
|
-
props.name === "BigInt64Array" || props.name === "BigUint64Array"
|
|
865
|
-
? "bigint"
|
|
866
|
-
: "number";
|
|
867
|
-
const value: Metadata = Metadata.create({
|
|
868
|
-
...Metadata.initialize(),
|
|
869
|
-
atomics: [
|
|
870
|
-
MetadataAtomic.create({
|
|
871
|
-
type: atomic,
|
|
872
|
-
tags: [
|
|
873
|
-
[
|
|
874
|
-
...MetadataCommentTagFactory.get({
|
|
875
|
-
kind: "type",
|
|
876
|
-
type: atomic,
|
|
877
|
-
value: type,
|
|
878
|
-
}),
|
|
879
|
-
...MetadataCommentTagFactory.get({
|
|
880
|
-
kind: "minimum",
|
|
881
|
-
type: "number",
|
|
882
|
-
value: minimum.toString(),
|
|
883
|
-
}),
|
|
884
|
-
...MetadataCommentTagFactory.get({
|
|
885
|
-
kind: "maximum",
|
|
886
|
-
type: "number",
|
|
887
|
-
value: maximum.toString(),
|
|
888
|
-
}),
|
|
889
|
-
],
|
|
890
|
-
],
|
|
891
|
-
}),
|
|
892
|
-
],
|
|
893
|
-
});
|
|
894
|
-
return ts.factory.createNewExpression(
|
|
895
|
-
ts.factory.createIdentifier(props.name),
|
|
896
|
-
[],
|
|
897
|
-
decode_array({
|
|
898
|
-
context: props.context,
|
|
899
|
-
functor: props.functor,
|
|
900
|
-
explore: props.explore,
|
|
901
|
-
array: MetadataArray.create({
|
|
902
|
-
tags: [],
|
|
903
|
-
type: MetadataArrayType.create({
|
|
904
|
-
name: `${props.name}<${atomic}>`,
|
|
905
|
-
value,
|
|
906
|
-
recursive: false,
|
|
907
|
-
index: null,
|
|
908
|
-
nullables: [],
|
|
909
|
-
}),
|
|
910
|
-
}),
|
|
911
|
-
}),
|
|
912
|
-
);
|
|
913
|
-
};
|
|
914
|
-
|
|
915
|
-
const decode_native_blob = (props: {
|
|
916
|
-
context: ITypiaContext;
|
|
917
|
-
functor: FunctionProgrammer;
|
|
918
|
-
explore: IExplore;
|
|
919
|
-
}) =>
|
|
920
|
-
ts.factory.createNewExpression(
|
|
921
|
-
ts.factory.createIdentifier("Blob"),
|
|
922
|
-
undefined,
|
|
923
|
-
[
|
|
924
|
-
ts.factory.createArrayLiteralExpression(
|
|
925
|
-
[
|
|
926
|
-
decode_native_byte_array({
|
|
927
|
-
context: props.context,
|
|
928
|
-
functor: props.functor,
|
|
929
|
-
explore: props.explore,
|
|
930
|
-
name: "Uint8Array",
|
|
931
|
-
}),
|
|
932
|
-
],
|
|
933
|
-
true,
|
|
934
|
-
),
|
|
935
|
-
],
|
|
936
|
-
);
|
|
937
|
-
|
|
938
|
-
const decode_native_file = (props: {
|
|
939
|
-
context: ITypiaContext;
|
|
940
|
-
functor: FunctionProgrammer;
|
|
941
|
-
explore: IExplore;
|
|
942
|
-
}) =>
|
|
943
|
-
ts.factory.createNewExpression(
|
|
944
|
-
ts.factory.createIdentifier("File"),
|
|
945
|
-
undefined,
|
|
946
|
-
[
|
|
947
|
-
ts.factory.createArrayLiteralExpression(
|
|
948
|
-
[
|
|
949
|
-
decode_native_byte_array({
|
|
950
|
-
context: props.context,
|
|
951
|
-
functor: props.functor,
|
|
952
|
-
explore: props.explore,
|
|
953
|
-
name: "Uint8Array",
|
|
954
|
-
}),
|
|
955
|
-
],
|
|
956
|
-
true,
|
|
957
|
-
),
|
|
958
|
-
ts.factory.createTemplateExpression(ts.factory.createTemplateHead(""), [
|
|
959
|
-
ts.factory.createTemplateSpan(
|
|
960
|
-
writeRangedString({
|
|
961
|
-
context: props.context,
|
|
962
|
-
minLength: 1,
|
|
963
|
-
maxLength: 8,
|
|
964
|
-
}),
|
|
965
|
-
ts.factory.createTemplateMiddle("."),
|
|
966
|
-
),
|
|
967
|
-
ts.factory.createTemplateSpan(
|
|
968
|
-
writeRangedString({
|
|
969
|
-
context: props.context,
|
|
970
|
-
minLength: 3,
|
|
971
|
-
maxLength: 3,
|
|
972
|
-
}),
|
|
973
|
-
ts.factory.createTemplateTail(""),
|
|
974
|
-
),
|
|
975
|
-
]),
|
|
976
|
-
],
|
|
977
|
-
);
|
|
978
|
-
|
|
979
|
-
const decode_native_array_buffer = (props: {
|
|
980
|
-
context: ITypiaContext;
|
|
981
|
-
functor: FunctionProgrammer;
|
|
982
|
-
explore: IExplore;
|
|
983
|
-
name: "ArrayBuffer" | "SharedArrayBuffer";
|
|
984
|
-
}): ts.Expression =>
|
|
985
|
-
props.name === "ArrayBuffer"
|
|
986
|
-
? IdentifierFactory.access(
|
|
987
|
-
decode_native_byte_array({
|
|
988
|
-
context: props.context,
|
|
989
|
-
functor: props.functor,
|
|
990
|
-
explore: props.explore,
|
|
991
|
-
name: "Uint8Array",
|
|
992
|
-
}),
|
|
993
|
-
"buffer",
|
|
994
|
-
)
|
|
995
|
-
: ExpressionFactory.selfCall(
|
|
996
|
-
ts.factory.createBlock(
|
|
997
|
-
[
|
|
998
|
-
StatementFactory.constant({
|
|
999
|
-
name: "length",
|
|
1000
|
-
value: decode_atomic({
|
|
1001
|
-
context: props.context,
|
|
1002
|
-
atomic: MetadataAtomic.create({
|
|
1003
|
-
type: "number",
|
|
1004
|
-
tags: [
|
|
1005
|
-
MetadataCommentTagFactory.get({
|
|
1006
|
-
type: "number",
|
|
1007
|
-
kind: "type",
|
|
1008
|
-
value: "uint32",
|
|
1009
|
-
}),
|
|
1010
|
-
],
|
|
1011
|
-
}),
|
|
1012
|
-
})[0]!,
|
|
1013
|
-
}),
|
|
1014
|
-
StatementFactory.constant({
|
|
1015
|
-
name: "buffer",
|
|
1016
|
-
value: ts.factory.createNewExpression(
|
|
1017
|
-
ts.factory.createIdentifier("SharedArrayBuffer"),
|
|
1018
|
-
[],
|
|
1019
|
-
[ts.factory.createIdentifier("length")],
|
|
1020
|
-
),
|
|
1021
|
-
}),
|
|
1022
|
-
StatementFactory.constant({
|
|
1023
|
-
name: "bytes",
|
|
1024
|
-
value: ts.factory.createNewExpression(
|
|
1025
|
-
ts.factory.createIdentifier("Uint8Array"),
|
|
1026
|
-
[],
|
|
1027
|
-
[ts.factory.createIdentifier("buffer")],
|
|
1028
|
-
),
|
|
1029
|
-
}),
|
|
1030
|
-
ts.factory.createExpressionStatement(
|
|
1031
|
-
ts.factory.createCallExpression(
|
|
1032
|
-
IdentifierFactory.access(
|
|
1033
|
-
ts.factory.createIdentifier("bytes"),
|
|
1034
|
-
"set",
|
|
1035
|
-
),
|
|
1036
|
-
undefined,
|
|
1037
|
-
[
|
|
1038
|
-
ts.factory.createCallExpression(
|
|
1039
|
-
ts.factory.createPropertyAccessExpression(
|
|
1040
|
-
ts.factory.createCallExpression(
|
|
1041
|
-
ts.factory.createPropertyAccessExpression(
|
|
1042
|
-
ts.factory.createNewExpression(
|
|
1043
|
-
ts.factory.createIdentifier("Array"),
|
|
1044
|
-
undefined,
|
|
1045
|
-
[ts.factory.createIdentifier("length")],
|
|
1046
|
-
),
|
|
1047
|
-
ts.factory.createIdentifier("fill"),
|
|
1048
|
-
),
|
|
1049
|
-
undefined,
|
|
1050
|
-
[ts.factory.createNumericLiteral("0")],
|
|
1051
|
-
),
|
|
1052
|
-
ts.factory.createIdentifier("map"),
|
|
1053
|
-
),
|
|
1054
|
-
undefined,
|
|
1055
|
-
[
|
|
1056
|
-
ts.factory.createArrowFunction(
|
|
1057
|
-
undefined,
|
|
1058
|
-
undefined,
|
|
1059
|
-
[],
|
|
1060
|
-
undefined,
|
|
1061
|
-
undefined,
|
|
1062
|
-
decode_atomic({
|
|
1063
|
-
context: props.context,
|
|
1064
|
-
atomic: MetadataAtomic.create({
|
|
1065
|
-
type: "number",
|
|
1066
|
-
tags: [
|
|
1067
|
-
[
|
|
1068
|
-
...MetadataCommentTagFactory.get({
|
|
1069
|
-
kind: "type",
|
|
1070
|
-
type: "number",
|
|
1071
|
-
value: "uint32",
|
|
1072
|
-
}),
|
|
1073
|
-
...MetadataCommentTagFactory.get({
|
|
1074
|
-
kind: "minimum",
|
|
1075
|
-
type: "number",
|
|
1076
|
-
value: "0",
|
|
1077
|
-
}),
|
|
1078
|
-
...MetadataCommentTagFactory.get({
|
|
1079
|
-
kind: "maximum",
|
|
1080
|
-
type: "number",
|
|
1081
|
-
value: "255",
|
|
1082
|
-
}),
|
|
1083
|
-
],
|
|
1084
|
-
],
|
|
1085
|
-
}),
|
|
1086
|
-
})[0]!,
|
|
1087
|
-
),
|
|
1088
|
-
],
|
|
1089
|
-
),
|
|
1090
|
-
ExpressionFactory.number(0),
|
|
1091
|
-
],
|
|
1092
|
-
),
|
|
1093
|
-
),
|
|
1094
|
-
ts.factory.createReturnStatement(
|
|
1095
|
-
ts.factory.createIdentifier("buffer"),
|
|
1096
|
-
),
|
|
1097
|
-
],
|
|
1098
|
-
true,
|
|
1099
|
-
),
|
|
1100
|
-
);
|
|
1101
|
-
|
|
1102
|
-
const decode_native_data_view = (props: {
|
|
1103
|
-
context: ITypiaContext;
|
|
1104
|
-
functor: FunctionProgrammer;
|
|
1105
|
-
explore: IExplore;
|
|
1106
|
-
}) =>
|
|
1107
|
-
ts.factory.createNewExpression(
|
|
1108
|
-
ts.factory.createIdentifier("DataView"),
|
|
1109
|
-
[],
|
|
1110
|
-
[
|
|
1111
|
-
IdentifierFactory.access(
|
|
1112
|
-
decode_native_byte_array({
|
|
1113
|
-
context: props.context,
|
|
1114
|
-
functor: props.functor,
|
|
1115
|
-
explore: props.explore,
|
|
1116
|
-
name: "Uint8Array",
|
|
1117
|
-
}),
|
|
1118
|
-
"buffer",
|
|
1119
|
-
),
|
|
1120
|
-
],
|
|
1121
|
-
);
|
|
1122
|
-
|
|
1123
|
-
const decode_regexp = (context: ITypiaContext) =>
|
|
1124
|
-
ts.factory.createNewExpression(
|
|
1125
|
-
ts.factory.createIdentifier("RegExp"),
|
|
1126
|
-
[],
|
|
1127
|
-
[
|
|
1128
|
-
ts.factory.createCallExpression(
|
|
1129
|
-
coalesce({
|
|
1130
|
-
context,
|
|
1131
|
-
method: "regex",
|
|
1132
|
-
internal: "randomFormatRegex",
|
|
1133
|
-
}),
|
|
1134
|
-
undefined,
|
|
1135
|
-
undefined,
|
|
1136
|
-
),
|
|
1137
|
-
],
|
|
1138
|
-
);
|
|
1139
|
-
|
|
1140
|
-
const writeRangedString = (props: {
|
|
1141
|
-
context: ITypiaContext;
|
|
1142
|
-
minLength: number;
|
|
1143
|
-
maxLength: number;
|
|
1144
|
-
}): ts.CallExpression =>
|
|
1145
|
-
decode_atomic({
|
|
1146
|
-
context: props.context,
|
|
1147
|
-
atomic: MetadataAtomic.create({
|
|
1148
|
-
type: "string",
|
|
1149
|
-
tags: [
|
|
1150
|
-
[
|
|
1151
|
-
...MetadataCommentTagFactory.get({
|
|
1152
|
-
kind: "minLength",
|
|
1153
|
-
type: "string",
|
|
1154
|
-
value: props.minLength.toString(),
|
|
1155
|
-
}),
|
|
1156
|
-
...MetadataCommentTagFactory.get({
|
|
1157
|
-
kind: "maxLength",
|
|
1158
|
-
type: "string",
|
|
1159
|
-
value: props.maxLength.toString(),
|
|
1160
|
-
}),
|
|
1161
|
-
],
|
|
1162
|
-
],
|
|
1163
|
-
}),
|
|
1164
|
-
})[0]!;
|
|
1165
|
-
}
|
|
1166
|
-
|
|
1167
|
-
const coalesce = (props: {
|
|
1168
|
-
context: ITypiaContext;
|
|
1169
|
-
method: string;
|
|
1170
|
-
internal: string;
|
|
1171
|
-
}): ts.Expression =>
|
|
1172
|
-
ExpressionFactory.coalesce(
|
|
1173
|
-
ts.factory.createPropertyAccessChain(
|
|
1174
|
-
ts.factory.createIdentifier("_generator"),
|
|
1175
|
-
ts.factory.createToken(ts.SyntaxKind.QuestionDotToken),
|
|
1176
|
-
ts.factory.createIdentifier(props.method),
|
|
1177
|
-
),
|
|
1178
|
-
props.context.importer.internal(props.internal),
|
|
1179
|
-
);
|
|
1180
|
-
|
|
1181
|
-
interface IExplore {
|
|
1182
|
-
function: boolean;
|
|
1183
|
-
recursive: boolean;
|
|
1184
|
-
}
|
|
1185
|
-
|
|
1186
|
-
const Prefix = {
|
|
1187
|
-
object: (i: number) => `_ro${i}`,
|
|
1188
|
-
array: (i: number) => `_ra${i}`,
|
|
1189
|
-
tuple: (i: number) => `_rt${i}`,
|
|
1190
|
-
};
|
|
1
|
+
import { OpenApi } from "@samchon/openapi";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
|
|
4
|
+
import { ExpressionFactory } from "../factories/ExpressionFactory";
|
|
5
|
+
import { IdentifierFactory } from "../factories/IdentifierFactory";
|
|
6
|
+
import { LiteralFactory } from "../factories/LiteralFactory";
|
|
7
|
+
import { MetadataCollection } from "../factories/MetadataCollection";
|
|
8
|
+
import { MetadataCommentTagFactory } from "../factories/MetadataCommentTagFactory";
|
|
9
|
+
import { MetadataFactory } from "../factories/MetadataFactory";
|
|
10
|
+
import { StatementFactory } from "../factories/StatementFactory";
|
|
11
|
+
import { TemplateFactory } from "../factories/TemplateFactory";
|
|
12
|
+
import { TypeFactory } from "../factories/TypeFactory";
|
|
13
|
+
|
|
14
|
+
import { Metadata } from "../schemas/metadata/Metadata";
|
|
15
|
+
import { MetadataArray } from "../schemas/metadata/MetadataArray";
|
|
16
|
+
import { MetadataArrayType } from "../schemas/metadata/MetadataArrayType";
|
|
17
|
+
import { MetadataAtomic } from "../schemas/metadata/MetadataAtomic";
|
|
18
|
+
import { MetadataMap } from "../schemas/metadata/MetadataMap";
|
|
19
|
+
import { MetadataObjectType } from "../schemas/metadata/MetadataObjectType";
|
|
20
|
+
import { MetadataSet } from "../schemas/metadata/MetadataSet";
|
|
21
|
+
import { MetadataTemplate } from "../schemas/metadata/MetadataTemplate";
|
|
22
|
+
import { MetadataTuple } from "../schemas/metadata/MetadataTuple";
|
|
23
|
+
import { MetadataTupleType } from "../schemas/metadata/MetadataTupleType";
|
|
24
|
+
|
|
25
|
+
import { ITypiaContext } from "../transformers/ITypiaContext";
|
|
26
|
+
import { TransformerError } from "../transformers/TransformerError";
|
|
27
|
+
|
|
28
|
+
import { StringUtil } from "../utils/StringUtil";
|
|
29
|
+
|
|
30
|
+
import { FeatureProgrammer } from "./FeatureProgrammer";
|
|
31
|
+
import { FunctionProgrammer } from "./helpers/FunctionProgrammer";
|
|
32
|
+
import { RandomJoiner } from "./helpers/RandomJoiner";
|
|
33
|
+
import { json_schema_array } from "./internal/json_schema_array";
|
|
34
|
+
import { json_schema_bigint } from "./internal/json_schema_bigint";
|
|
35
|
+
import { json_schema_boolean } from "./internal/json_schema_boolean";
|
|
36
|
+
import { json_schema_number } from "./internal/json_schema_number";
|
|
37
|
+
import { json_schema_string } from "./internal/json_schema_string";
|
|
38
|
+
|
|
39
|
+
export namespace RandomProgrammer {
|
|
40
|
+
export interface IProps {
|
|
41
|
+
context: ITypiaContext;
|
|
42
|
+
modulo: ts.LeftHandSideExpression;
|
|
43
|
+
type: ts.Type;
|
|
44
|
+
name: string | undefined;
|
|
45
|
+
init: ts.Expression | undefined;
|
|
46
|
+
}
|
|
47
|
+
export interface IDecomposeProps {
|
|
48
|
+
context: ITypiaContext;
|
|
49
|
+
functor: FunctionProgrammer;
|
|
50
|
+
type: ts.Type;
|
|
51
|
+
name: string | undefined;
|
|
52
|
+
init: ts.Expression | undefined;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const decompose = (
|
|
56
|
+
props: IDecomposeProps,
|
|
57
|
+
): FeatureProgrammer.IDecomposed => {
|
|
58
|
+
const collection: MetadataCollection = new MetadataCollection();
|
|
59
|
+
const result = MetadataFactory.analyze({
|
|
60
|
+
checker: props.context.checker,
|
|
61
|
+
transformer: props.context.transformer,
|
|
62
|
+
options: {
|
|
63
|
+
escape: false,
|
|
64
|
+
constant: true,
|
|
65
|
+
absorb: true,
|
|
66
|
+
validate: (meta) => {
|
|
67
|
+
const output: string[] = [];
|
|
68
|
+
if (meta.natives.some((native) => native.name === "WeakSet"))
|
|
69
|
+
output.push(`WeakSet is not supported.`);
|
|
70
|
+
else if (meta.natives.some((native) => native.name === "WeakMap"))
|
|
71
|
+
output.push(`WeakMap is not supported.`);
|
|
72
|
+
return output;
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
collection,
|
|
76
|
+
type: props.type,
|
|
77
|
+
});
|
|
78
|
+
if (result.success === false)
|
|
79
|
+
throw TransformerError.from({
|
|
80
|
+
code: props.functor.method,
|
|
81
|
+
errors: result.errors,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// GENERATE FUNCTION
|
|
85
|
+
const functions: Record<string, ts.VariableStatement> = Object.fromEntries([
|
|
86
|
+
...write_object_functions({
|
|
87
|
+
context: props.context,
|
|
88
|
+
functor: props.functor,
|
|
89
|
+
collection,
|
|
90
|
+
}).map((v, i) => [Prefix.object(i), v]),
|
|
91
|
+
...write_array_functions({
|
|
92
|
+
context: props.context,
|
|
93
|
+
functor: props.functor,
|
|
94
|
+
collection,
|
|
95
|
+
}).map((v, i) => [Prefix.array(i), v]),
|
|
96
|
+
...write_tuple_functions({
|
|
97
|
+
context: props.context,
|
|
98
|
+
functor: props.functor,
|
|
99
|
+
collection,
|
|
100
|
+
}).map((v, i) => [Prefix.tuple(i), v]),
|
|
101
|
+
]);
|
|
102
|
+
const arrow: ts.ArrowFunction = ts.factory.createArrowFunction(
|
|
103
|
+
undefined,
|
|
104
|
+
undefined,
|
|
105
|
+
[
|
|
106
|
+
IdentifierFactory.parameter(
|
|
107
|
+
"generator",
|
|
108
|
+
ts.factory.createTypeReferenceNode("Partial", [
|
|
109
|
+
props.context.importer.type({
|
|
110
|
+
file: "typia",
|
|
111
|
+
name: "IRandomGenerator",
|
|
112
|
+
}),
|
|
113
|
+
]),
|
|
114
|
+
props.init ?? ts.factory.createToken(ts.SyntaxKind.QuestionToken),
|
|
115
|
+
),
|
|
116
|
+
],
|
|
117
|
+
props.context.importer.type({
|
|
118
|
+
file: "typia",
|
|
119
|
+
name: "Resolved",
|
|
120
|
+
arguments: [
|
|
121
|
+
ts.factory.createTypeReferenceNode(
|
|
122
|
+
props.name ??
|
|
123
|
+
TypeFactory.getFullName({
|
|
124
|
+
checker: props.context.checker,
|
|
125
|
+
type: props.type,
|
|
126
|
+
}),
|
|
127
|
+
),
|
|
128
|
+
],
|
|
129
|
+
}),
|
|
130
|
+
undefined,
|
|
131
|
+
ts.factory.createBlock(
|
|
132
|
+
[
|
|
133
|
+
ts.factory.createExpressionStatement(
|
|
134
|
+
ts.factory.createBinaryExpression(
|
|
135
|
+
ts.factory.createIdentifier("_generator"),
|
|
136
|
+
ts.SyntaxKind.EqualsToken,
|
|
137
|
+
ts.factory.createIdentifier("generator"),
|
|
138
|
+
),
|
|
139
|
+
),
|
|
140
|
+
ts.factory.createReturnStatement(
|
|
141
|
+
decode({
|
|
142
|
+
context: props.context,
|
|
143
|
+
functor: props.functor,
|
|
144
|
+
explore: {
|
|
145
|
+
function: false,
|
|
146
|
+
recursive: false,
|
|
147
|
+
},
|
|
148
|
+
metadata: result.data,
|
|
149
|
+
}),
|
|
150
|
+
),
|
|
151
|
+
],
|
|
152
|
+
true,
|
|
153
|
+
),
|
|
154
|
+
);
|
|
155
|
+
return {
|
|
156
|
+
functions,
|
|
157
|
+
statements: [
|
|
158
|
+
StatementFactory.mut({
|
|
159
|
+
name: "_generator",
|
|
160
|
+
type: ts.factory.createUnionTypeNode([
|
|
161
|
+
ts.factory.createTypeReferenceNode("Partial", [
|
|
162
|
+
props.context.importer.type({
|
|
163
|
+
file: "typia",
|
|
164
|
+
name: "IRandomGenerator",
|
|
165
|
+
}),
|
|
166
|
+
]),
|
|
167
|
+
ts.factory.createTypeReferenceNode("undefined"),
|
|
168
|
+
]),
|
|
169
|
+
}),
|
|
170
|
+
],
|
|
171
|
+
arrow,
|
|
172
|
+
};
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
export const write = (props: IProps) => {
|
|
176
|
+
const functor: FunctionProgrammer = new FunctionProgrammer(
|
|
177
|
+
props.modulo.getText(),
|
|
178
|
+
);
|
|
179
|
+
const result: FeatureProgrammer.IDecomposed = decompose({
|
|
180
|
+
...props,
|
|
181
|
+
functor,
|
|
182
|
+
});
|
|
183
|
+
return FeatureProgrammer.writeDecomposed({
|
|
184
|
+
modulo: props.modulo,
|
|
185
|
+
functor,
|
|
186
|
+
result,
|
|
187
|
+
});
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
const write_object_functions = (props: {
|
|
191
|
+
context: ITypiaContext;
|
|
192
|
+
functor: FunctionProgrammer;
|
|
193
|
+
collection: MetadataCollection;
|
|
194
|
+
}): ts.VariableStatement[] =>
|
|
195
|
+
props.collection.objects().map((obj, i) =>
|
|
196
|
+
StatementFactory.constant({
|
|
197
|
+
name: Prefix.object(i),
|
|
198
|
+
value: ts.factory.createArrowFunction(
|
|
199
|
+
undefined,
|
|
200
|
+
undefined,
|
|
201
|
+
[
|
|
202
|
+
IdentifierFactory.parameter(
|
|
203
|
+
"_recursive",
|
|
204
|
+
TypeFactory.keyword("boolean"),
|
|
205
|
+
ts.factory.createIdentifier(String(obj.recursive)),
|
|
206
|
+
),
|
|
207
|
+
IdentifierFactory.parameter(
|
|
208
|
+
"_depth",
|
|
209
|
+
TypeFactory.keyword("number"),
|
|
210
|
+
ExpressionFactory.number(0),
|
|
211
|
+
),
|
|
212
|
+
],
|
|
213
|
+
TypeFactory.keyword("any"),
|
|
214
|
+
undefined,
|
|
215
|
+
RandomJoiner.object({
|
|
216
|
+
decode: (metadata) =>
|
|
217
|
+
decode({
|
|
218
|
+
context: props.context,
|
|
219
|
+
functor: props.functor,
|
|
220
|
+
explore: {
|
|
221
|
+
recursive: obj.recursive,
|
|
222
|
+
function: true,
|
|
223
|
+
},
|
|
224
|
+
metadata,
|
|
225
|
+
}),
|
|
226
|
+
object: obj,
|
|
227
|
+
}),
|
|
228
|
+
),
|
|
229
|
+
}),
|
|
230
|
+
);
|
|
231
|
+
|
|
232
|
+
const write_array_functions = (props: {
|
|
233
|
+
context: ITypiaContext;
|
|
234
|
+
functor: FunctionProgrammer;
|
|
235
|
+
collection: MetadataCollection;
|
|
236
|
+
}): ts.VariableStatement[] =>
|
|
237
|
+
props.collection
|
|
238
|
+
.arrays()
|
|
239
|
+
.filter((a) => a.recursive)
|
|
240
|
+
.map((array, i) =>
|
|
241
|
+
StatementFactory.constant({
|
|
242
|
+
name: Prefix.array(i),
|
|
243
|
+
value: ts.factory.createArrowFunction(
|
|
244
|
+
undefined,
|
|
245
|
+
undefined,
|
|
246
|
+
[
|
|
247
|
+
IdentifierFactory.parameter(
|
|
248
|
+
"_schema",
|
|
249
|
+
TypeFactory.keyword("boolean"),
|
|
250
|
+
),
|
|
251
|
+
IdentifierFactory.parameter(
|
|
252
|
+
"_recursive",
|
|
253
|
+
TypeFactory.keyword("boolean"),
|
|
254
|
+
ts.factory.createTrue(),
|
|
255
|
+
),
|
|
256
|
+
IdentifierFactory.parameter(
|
|
257
|
+
"_depth",
|
|
258
|
+
TypeFactory.keyword("number"),
|
|
259
|
+
ExpressionFactory.number(0),
|
|
260
|
+
),
|
|
261
|
+
],
|
|
262
|
+
TypeFactory.keyword("any"),
|
|
263
|
+
undefined,
|
|
264
|
+
RandomJoiner.array({
|
|
265
|
+
decode: (metadata) =>
|
|
266
|
+
decode({
|
|
267
|
+
context: props.context,
|
|
268
|
+
functor: props.functor,
|
|
269
|
+
explore: {
|
|
270
|
+
recursive: true,
|
|
271
|
+
function: true,
|
|
272
|
+
},
|
|
273
|
+
metadata,
|
|
274
|
+
}),
|
|
275
|
+
recursive: true,
|
|
276
|
+
expression: coalesce({
|
|
277
|
+
context: props.context,
|
|
278
|
+
method: "array",
|
|
279
|
+
internal: "randomArray",
|
|
280
|
+
}),
|
|
281
|
+
array,
|
|
282
|
+
schema: undefined,
|
|
283
|
+
}),
|
|
284
|
+
),
|
|
285
|
+
}),
|
|
286
|
+
);
|
|
287
|
+
|
|
288
|
+
const write_tuple_functions = (props: {
|
|
289
|
+
context: ITypiaContext;
|
|
290
|
+
functor: FunctionProgrammer;
|
|
291
|
+
collection: MetadataCollection;
|
|
292
|
+
}): ts.VariableStatement[] =>
|
|
293
|
+
props.collection
|
|
294
|
+
.tuples()
|
|
295
|
+
.filter((a) => a.recursive)
|
|
296
|
+
.map((tuple, i) =>
|
|
297
|
+
StatementFactory.constant({
|
|
298
|
+
name: Prefix.tuple(i),
|
|
299
|
+
value: ts.factory.createArrowFunction(
|
|
300
|
+
undefined,
|
|
301
|
+
undefined,
|
|
302
|
+
[
|
|
303
|
+
IdentifierFactory.parameter(
|
|
304
|
+
"_recursive",
|
|
305
|
+
TypeFactory.keyword("boolean"),
|
|
306
|
+
ts.factory.createTrue(),
|
|
307
|
+
),
|
|
308
|
+
IdentifierFactory.parameter(
|
|
309
|
+
"_depth",
|
|
310
|
+
TypeFactory.keyword("number"),
|
|
311
|
+
ExpressionFactory.number(0),
|
|
312
|
+
),
|
|
313
|
+
],
|
|
314
|
+
TypeFactory.keyword("any"),
|
|
315
|
+
undefined,
|
|
316
|
+
RandomJoiner.tuple({
|
|
317
|
+
decode: (metadata) =>
|
|
318
|
+
decode({
|
|
319
|
+
context: props.context,
|
|
320
|
+
functor: props.functor,
|
|
321
|
+
explore: {
|
|
322
|
+
function: true,
|
|
323
|
+
recursive: true,
|
|
324
|
+
},
|
|
325
|
+
metadata,
|
|
326
|
+
}),
|
|
327
|
+
elements: tuple.elements,
|
|
328
|
+
}),
|
|
329
|
+
),
|
|
330
|
+
}),
|
|
331
|
+
);
|
|
332
|
+
|
|
333
|
+
/* -----------------------------------------------------------
|
|
334
|
+
DECODERS
|
|
335
|
+
----------------------------------------------------------- */
|
|
336
|
+
const decode = (props: {
|
|
337
|
+
context: ITypiaContext;
|
|
338
|
+
functor: FunctionProgrammer;
|
|
339
|
+
explore: IExplore;
|
|
340
|
+
metadata: Metadata;
|
|
341
|
+
}): ts.Expression => {
|
|
342
|
+
const expressions: ts.Expression[] = [];
|
|
343
|
+
if (props.metadata.any === true)
|
|
344
|
+
expressions.push(ts.factory.createStringLiteral("any type used..."));
|
|
345
|
+
|
|
346
|
+
// NULL COALESCING
|
|
347
|
+
if (
|
|
348
|
+
props.metadata.isRequired() === false ||
|
|
349
|
+
props.metadata.functions.length !== 0
|
|
350
|
+
)
|
|
351
|
+
expressions.push(ts.factory.createIdentifier("undefined"));
|
|
352
|
+
if (props.metadata.nullable === true)
|
|
353
|
+
expressions.push(ts.factory.createNull());
|
|
354
|
+
|
|
355
|
+
// CONSTANT TYPES
|
|
356
|
+
for (const constant of props.metadata.constants)
|
|
357
|
+
for (const { value } of constant.values)
|
|
358
|
+
expressions.push(
|
|
359
|
+
constant.type === "boolean"
|
|
360
|
+
? value === true
|
|
361
|
+
? ts.factory.createTrue()
|
|
362
|
+
: ts.factory.createFalse()
|
|
363
|
+
: constant.type === "bigint"
|
|
364
|
+
? ExpressionFactory.bigint(value as bigint)
|
|
365
|
+
: constant.type === "number"
|
|
366
|
+
? ExpressionFactory.number(value as number)
|
|
367
|
+
: ts.factory.createStringLiteral(value as string),
|
|
368
|
+
);
|
|
369
|
+
|
|
370
|
+
// ATOMIC VARIABLES
|
|
371
|
+
for (const template of props.metadata.templates)
|
|
372
|
+
expressions.push(
|
|
373
|
+
decode_template({
|
|
374
|
+
...props,
|
|
375
|
+
template,
|
|
376
|
+
}),
|
|
377
|
+
);
|
|
378
|
+
for (const atomic of props.metadata.atomics)
|
|
379
|
+
expressions.push(
|
|
380
|
+
...decode_atomic({
|
|
381
|
+
context: props.context,
|
|
382
|
+
atomic,
|
|
383
|
+
}),
|
|
384
|
+
);
|
|
385
|
+
|
|
386
|
+
// INSTANCE TYPES
|
|
387
|
+
if (props.metadata.escaped)
|
|
388
|
+
expressions.push(
|
|
389
|
+
decode({
|
|
390
|
+
...props,
|
|
391
|
+
metadata: props.metadata.escaped.returns,
|
|
392
|
+
}),
|
|
393
|
+
);
|
|
394
|
+
for (const array of props.metadata.arrays)
|
|
395
|
+
expressions.push(
|
|
396
|
+
...decode_array({
|
|
397
|
+
...props,
|
|
398
|
+
array,
|
|
399
|
+
}),
|
|
400
|
+
);
|
|
401
|
+
for (const tuple of props.metadata.tuples)
|
|
402
|
+
expressions.push(
|
|
403
|
+
decode_tuple({
|
|
404
|
+
...props,
|
|
405
|
+
tuple,
|
|
406
|
+
}),
|
|
407
|
+
);
|
|
408
|
+
for (const object of props.metadata.objects)
|
|
409
|
+
expressions.push(
|
|
410
|
+
decode_object({
|
|
411
|
+
...props,
|
|
412
|
+
object: object.type,
|
|
413
|
+
}),
|
|
414
|
+
);
|
|
415
|
+
for (const native of props.metadata.natives)
|
|
416
|
+
expressions.push(
|
|
417
|
+
decode_native({
|
|
418
|
+
context: props.context,
|
|
419
|
+
functor: props.functor,
|
|
420
|
+
explore: props.explore,
|
|
421
|
+
name: native.name,
|
|
422
|
+
}),
|
|
423
|
+
);
|
|
424
|
+
for (const set of props.metadata.sets)
|
|
425
|
+
expressions.push(
|
|
426
|
+
decode_set({
|
|
427
|
+
...props,
|
|
428
|
+
set,
|
|
429
|
+
}),
|
|
430
|
+
);
|
|
431
|
+
for (const entry of props.metadata.maps)
|
|
432
|
+
expressions.push(
|
|
433
|
+
decode_map({
|
|
434
|
+
...props,
|
|
435
|
+
map: entry,
|
|
436
|
+
}),
|
|
437
|
+
);
|
|
438
|
+
|
|
439
|
+
// PICK UP A TYPE
|
|
440
|
+
if (expressions.length === 1) return expressions[0]!;
|
|
441
|
+
return ts.factory.createCallExpression(
|
|
442
|
+
ts.factory.createCallExpression(
|
|
443
|
+
props.context.importer.internal("randomPick"),
|
|
444
|
+
undefined,
|
|
445
|
+
[
|
|
446
|
+
ts.factory.createArrayLiteralExpression(
|
|
447
|
+
expressions.map((expr) =>
|
|
448
|
+
ts.factory.createArrowFunction(
|
|
449
|
+
undefined,
|
|
450
|
+
undefined,
|
|
451
|
+
[],
|
|
452
|
+
undefined,
|
|
453
|
+
undefined,
|
|
454
|
+
expr,
|
|
455
|
+
),
|
|
456
|
+
),
|
|
457
|
+
true,
|
|
458
|
+
),
|
|
459
|
+
],
|
|
460
|
+
),
|
|
461
|
+
undefined,
|
|
462
|
+
undefined,
|
|
463
|
+
);
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
const decode_atomic = (props: {
|
|
467
|
+
context: ITypiaContext;
|
|
468
|
+
atomic: MetadataAtomic;
|
|
469
|
+
}) => {
|
|
470
|
+
const schemaList: OpenApi.IJsonSchema[] =
|
|
471
|
+
props.atomic.type === "boolean"
|
|
472
|
+
? json_schema_boolean(props.atomic)
|
|
473
|
+
: props.atomic.type === "string"
|
|
474
|
+
? json_schema_string(props.atomic)
|
|
475
|
+
: props.atomic.type === "bigint"
|
|
476
|
+
? json_schema_bigint(props.atomic)
|
|
477
|
+
: json_schema_number(props.atomic);
|
|
478
|
+
return schemaList.map((schema) => {
|
|
479
|
+
interface IComposed {
|
|
480
|
+
method: string;
|
|
481
|
+
internal: string;
|
|
482
|
+
arguments: ts.Expression[];
|
|
483
|
+
}
|
|
484
|
+
const composed = ((): IComposed => {
|
|
485
|
+
if (props.atomic.type === "string") {
|
|
486
|
+
const string: OpenApi.IJsonSchema.IString =
|
|
487
|
+
schema as OpenApi.IJsonSchema.IString;
|
|
488
|
+
if (string.format !== undefined) {
|
|
489
|
+
const format: string = string.format!;
|
|
490
|
+
if (format === "date-time")
|
|
491
|
+
return {
|
|
492
|
+
method: "datetime",
|
|
493
|
+
internal: "randomFormatDatetime",
|
|
494
|
+
arguments: [],
|
|
495
|
+
};
|
|
496
|
+
return {
|
|
497
|
+
method: format
|
|
498
|
+
.split("-")
|
|
499
|
+
.map((s, i) => (i === 0 ? s : StringUtil.capitalize(s)))
|
|
500
|
+
.join(""),
|
|
501
|
+
internal: `randomFormat${format
|
|
502
|
+
.split("-")
|
|
503
|
+
.map(StringUtil.capitalize)
|
|
504
|
+
.join("")}`,
|
|
505
|
+
arguments: [],
|
|
506
|
+
};
|
|
507
|
+
} else if (string.pattern !== undefined)
|
|
508
|
+
return {
|
|
509
|
+
method: "pattern",
|
|
510
|
+
internal: "randomPattern",
|
|
511
|
+
arguments: [
|
|
512
|
+
ts.factory.createNewExpression(
|
|
513
|
+
ts.factory.createIdentifier("RegExp"),
|
|
514
|
+
undefined,
|
|
515
|
+
[
|
|
516
|
+
ts.factory.createStringLiteral(
|
|
517
|
+
(schema as OpenApi.IJsonSchema.IString).pattern!,
|
|
518
|
+
),
|
|
519
|
+
],
|
|
520
|
+
),
|
|
521
|
+
],
|
|
522
|
+
};
|
|
523
|
+
} else if (props.atomic.type === "number") {
|
|
524
|
+
const number:
|
|
525
|
+
| OpenApi.IJsonSchema.INumber
|
|
526
|
+
| OpenApi.IJsonSchema.IInteger = schema as
|
|
527
|
+
| OpenApi.IJsonSchema.INumber
|
|
528
|
+
| OpenApi.IJsonSchema.IInteger;
|
|
529
|
+
if (number.type === "integer")
|
|
530
|
+
return {
|
|
531
|
+
method: "integer",
|
|
532
|
+
internal: "randomInteger",
|
|
533
|
+
arguments: [LiteralFactory.write(schema)],
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
return {
|
|
537
|
+
method: props.atomic.type,
|
|
538
|
+
internal: `random${StringUtil.capitalize(props.atomic.type)}`,
|
|
539
|
+
arguments: [LiteralFactory.write(schema)],
|
|
540
|
+
};
|
|
541
|
+
})();
|
|
542
|
+
return ts.factory.createCallExpression(
|
|
543
|
+
ExpressionFactory.coalesce(
|
|
544
|
+
ts.factory.createPropertyAccessChain(
|
|
545
|
+
ts.factory.createIdentifier("_generator"),
|
|
546
|
+
ts.factory.createToken(ts.SyntaxKind.QuestionDotToken),
|
|
547
|
+
ts.factory.createIdentifier(composed.method),
|
|
548
|
+
),
|
|
549
|
+
props.context.importer.internal(composed.internal),
|
|
550
|
+
),
|
|
551
|
+
undefined,
|
|
552
|
+
composed.arguments,
|
|
553
|
+
);
|
|
554
|
+
});
|
|
555
|
+
};
|
|
556
|
+
|
|
557
|
+
const decode_template = (props: {
|
|
558
|
+
context: ITypiaContext;
|
|
559
|
+
functor: FunctionProgrammer;
|
|
560
|
+
explore: IExplore;
|
|
561
|
+
template: MetadataTemplate;
|
|
562
|
+
}) =>
|
|
563
|
+
TemplateFactory.generate(
|
|
564
|
+
props.template.row.map((metadata) =>
|
|
565
|
+
decode({
|
|
566
|
+
...props,
|
|
567
|
+
metadata,
|
|
568
|
+
}),
|
|
569
|
+
),
|
|
570
|
+
);
|
|
571
|
+
|
|
572
|
+
const decode_array = (props: {
|
|
573
|
+
context: ITypiaContext;
|
|
574
|
+
functor: FunctionProgrammer;
|
|
575
|
+
explore: IExplore;
|
|
576
|
+
array: MetadataArray;
|
|
577
|
+
}): ts.Expression[] => {
|
|
578
|
+
const components: OpenApi.IComponents = {};
|
|
579
|
+
const schemaList: OpenApi.IJsonSchema.IArray[] = json_schema_array({
|
|
580
|
+
components,
|
|
581
|
+
array: props.array,
|
|
582
|
+
}) as OpenApi.IJsonSchema.IArray[];
|
|
583
|
+
if (props.array.type.recursive)
|
|
584
|
+
return schemaList.map((schema) =>
|
|
585
|
+
ts.factory.createCallExpression(
|
|
586
|
+
ts.factory.createIdentifier(
|
|
587
|
+
props.functor.useLocal(Prefix.array(props.array.type.index!)),
|
|
588
|
+
),
|
|
589
|
+
undefined,
|
|
590
|
+
[
|
|
591
|
+
ts.factory.createObjectLiteralExpression(
|
|
592
|
+
Object.entries(schema)
|
|
593
|
+
.filter(([key]) => key !== "items")
|
|
594
|
+
.map(([key, value]) =>
|
|
595
|
+
ts.factory.createPropertyAssignment(
|
|
596
|
+
key,
|
|
597
|
+
LiteralFactory.write(value),
|
|
598
|
+
),
|
|
599
|
+
),
|
|
600
|
+
true,
|
|
601
|
+
),
|
|
602
|
+
],
|
|
603
|
+
),
|
|
604
|
+
);
|
|
605
|
+
return schemaList.map((schema) =>
|
|
606
|
+
RandomJoiner.array({
|
|
607
|
+
decode: (metadata) =>
|
|
608
|
+
decode({
|
|
609
|
+
...props,
|
|
610
|
+
metadata,
|
|
611
|
+
}),
|
|
612
|
+
expression: coalesce({
|
|
613
|
+
context: props.context,
|
|
614
|
+
method: "array",
|
|
615
|
+
internal: "randomArray",
|
|
616
|
+
}),
|
|
617
|
+
array: props.array.type,
|
|
618
|
+
recursive: props.explore.recursive,
|
|
619
|
+
schema,
|
|
620
|
+
}),
|
|
621
|
+
);
|
|
622
|
+
};
|
|
623
|
+
|
|
624
|
+
const decode_tuple = (props: {
|
|
625
|
+
context: ITypiaContext;
|
|
626
|
+
functor: FunctionProgrammer;
|
|
627
|
+
explore: IExplore;
|
|
628
|
+
tuple: MetadataTuple;
|
|
629
|
+
}): ts.Expression =>
|
|
630
|
+
props.tuple.type.recursive
|
|
631
|
+
? ts.factory.createCallExpression(
|
|
632
|
+
ts.factory.createIdentifier(
|
|
633
|
+
props.functor.useLocal(Prefix.tuple(props.tuple.type.index!)),
|
|
634
|
+
),
|
|
635
|
+
undefined,
|
|
636
|
+
[
|
|
637
|
+
ts.factory.createTrue(),
|
|
638
|
+
props.explore.recursive
|
|
639
|
+
? ts.factory.createAdd(
|
|
640
|
+
ExpressionFactory.number(1),
|
|
641
|
+
ts.factory.createIdentifier("_depth"),
|
|
642
|
+
)
|
|
643
|
+
: ExpressionFactory.number(0),
|
|
644
|
+
],
|
|
645
|
+
)
|
|
646
|
+
: RandomJoiner.tuple({
|
|
647
|
+
decode: (metadata) =>
|
|
648
|
+
decode({
|
|
649
|
+
...props,
|
|
650
|
+
metadata,
|
|
651
|
+
}),
|
|
652
|
+
elements: props.tuple.type.elements,
|
|
653
|
+
});
|
|
654
|
+
|
|
655
|
+
const decode_object = (props: {
|
|
656
|
+
functor: FunctionProgrammer;
|
|
657
|
+
explore: IExplore;
|
|
658
|
+
object: MetadataObjectType;
|
|
659
|
+
}) =>
|
|
660
|
+
ts.factory.createCallExpression(
|
|
661
|
+
ts.factory.createIdentifier(
|
|
662
|
+
props.functor.useLocal(Prefix.object(props.object.index)),
|
|
663
|
+
),
|
|
664
|
+
undefined,
|
|
665
|
+
props.explore.function
|
|
666
|
+
? [
|
|
667
|
+
props.explore.recursive
|
|
668
|
+
? ts.factory.createTrue()
|
|
669
|
+
: ts.factory.createIdentifier("_recursive"),
|
|
670
|
+
ts.factory.createConditionalExpression(
|
|
671
|
+
ts.factory.createIdentifier("_recursive"),
|
|
672
|
+
undefined,
|
|
673
|
+
ts.factory.createAdd(
|
|
674
|
+
ExpressionFactory.number(1),
|
|
675
|
+
ts.factory.createIdentifier("_depth"),
|
|
676
|
+
),
|
|
677
|
+
undefined,
|
|
678
|
+
ts.factory.createIdentifier("_depth"),
|
|
679
|
+
),
|
|
680
|
+
]
|
|
681
|
+
: undefined,
|
|
682
|
+
);
|
|
683
|
+
|
|
684
|
+
/* -----------------------------------------------------------
|
|
685
|
+
NATIVE CLASSES
|
|
686
|
+
----------------------------------------------------------- */
|
|
687
|
+
const decode_set = (props: {
|
|
688
|
+
context: ITypiaContext;
|
|
689
|
+
functor: FunctionProgrammer;
|
|
690
|
+
explore: IExplore;
|
|
691
|
+
set: MetadataSet;
|
|
692
|
+
}) =>
|
|
693
|
+
ts.factory.createNewExpression(
|
|
694
|
+
ts.factory.createIdentifier("Set"),
|
|
695
|
+
undefined,
|
|
696
|
+
[
|
|
697
|
+
decode_array({
|
|
698
|
+
...props,
|
|
699
|
+
array: MetadataArray.create({
|
|
700
|
+
tags: [],
|
|
701
|
+
type: MetadataArrayType.create({
|
|
702
|
+
value: props.set.value,
|
|
703
|
+
recursive: false,
|
|
704
|
+
index: null,
|
|
705
|
+
nullables: [],
|
|
706
|
+
name: props.set.getName(),
|
|
707
|
+
}),
|
|
708
|
+
}),
|
|
709
|
+
})[0]!,
|
|
710
|
+
],
|
|
711
|
+
);
|
|
712
|
+
|
|
713
|
+
const decode_map = (props: {
|
|
714
|
+
context: ITypiaContext;
|
|
715
|
+
functor: FunctionProgrammer;
|
|
716
|
+
explore: IExplore;
|
|
717
|
+
map: MetadataMap;
|
|
718
|
+
}) =>
|
|
719
|
+
ts.factory.createNewExpression(
|
|
720
|
+
ts.factory.createIdentifier("Map"),
|
|
721
|
+
undefined,
|
|
722
|
+
[
|
|
723
|
+
decode_array({
|
|
724
|
+
...props,
|
|
725
|
+
array: MetadataArray.create({
|
|
726
|
+
tags: [],
|
|
727
|
+
type: MetadataArrayType.create({
|
|
728
|
+
name: props.map.getName(),
|
|
729
|
+
index: null,
|
|
730
|
+
recursive: false,
|
|
731
|
+
nullables: [],
|
|
732
|
+
value: Metadata.create({
|
|
733
|
+
...Metadata.initialize(),
|
|
734
|
+
tuples: [
|
|
735
|
+
(() => {
|
|
736
|
+
const type = MetadataTupleType.create({
|
|
737
|
+
name: `[${props.map.key.getName()}, ${props.map.value.getName()}]`,
|
|
738
|
+
index: null,
|
|
739
|
+
recursive: false,
|
|
740
|
+
nullables: [],
|
|
741
|
+
elements: [props.map.key, props.map.value],
|
|
742
|
+
});
|
|
743
|
+
type.of_map = true;
|
|
744
|
+
return MetadataTuple.create({
|
|
745
|
+
type,
|
|
746
|
+
tags: [],
|
|
747
|
+
});
|
|
748
|
+
})(),
|
|
749
|
+
],
|
|
750
|
+
}),
|
|
751
|
+
}),
|
|
752
|
+
}),
|
|
753
|
+
})[0]!,
|
|
754
|
+
],
|
|
755
|
+
);
|
|
756
|
+
|
|
757
|
+
const decode_native = (props: {
|
|
758
|
+
context: ITypiaContext;
|
|
759
|
+
functor: FunctionProgrammer;
|
|
760
|
+
explore: IExplore;
|
|
761
|
+
name: string;
|
|
762
|
+
}): ts.Expression => {
|
|
763
|
+
if (
|
|
764
|
+
props.name === "Boolean" ||
|
|
765
|
+
props.name === "Number" ||
|
|
766
|
+
props.name === "BigInt" ||
|
|
767
|
+
props.name === "String"
|
|
768
|
+
)
|
|
769
|
+
return decode_atomic({
|
|
770
|
+
context: props.context,
|
|
771
|
+
atomic: MetadataAtomic.create({
|
|
772
|
+
type: props.name.toLowerCase() as "string",
|
|
773
|
+
tags: [],
|
|
774
|
+
}),
|
|
775
|
+
})[0]!;
|
|
776
|
+
else if (props.name === "Date") return decode_native_date(props.context);
|
|
777
|
+
else if (
|
|
778
|
+
props.name === "Uint8Array" ||
|
|
779
|
+
props.name === "Uint8ClampedArray" ||
|
|
780
|
+
props.name === "Uint16Array" ||
|
|
781
|
+
props.name === "Uint32Array" ||
|
|
782
|
+
props.name === "BigUint64Array" ||
|
|
783
|
+
props.name === "Int8Array" ||
|
|
784
|
+
props.name === "Int16Array" ||
|
|
785
|
+
props.name === "Int32Array" ||
|
|
786
|
+
props.name === "BigInt64Array" ||
|
|
787
|
+
props.name === "Float32Array" ||
|
|
788
|
+
props.name === "Float64Array"
|
|
789
|
+
)
|
|
790
|
+
return decode_native_byte_array({
|
|
791
|
+
...props,
|
|
792
|
+
name: props.name,
|
|
793
|
+
});
|
|
794
|
+
else if (props.name === "ArrayBuffer" || props.name === "SharedArrayBuffer")
|
|
795
|
+
return decode_native_array_buffer({
|
|
796
|
+
...props,
|
|
797
|
+
name: props.name,
|
|
798
|
+
});
|
|
799
|
+
else if (props.name === "DataView") return decode_native_data_view(props);
|
|
800
|
+
else if (props.name === "Blob") return decode_native_blob(props);
|
|
801
|
+
else if (props.name === "File") return decode_native_file(props);
|
|
802
|
+
else if (props.name === "RegExp") return decode_regexp(props.context);
|
|
803
|
+
else
|
|
804
|
+
return ts.factory.createNewExpression(
|
|
805
|
+
ts.factory.createIdentifier(props.name),
|
|
806
|
+
undefined,
|
|
807
|
+
[],
|
|
808
|
+
);
|
|
809
|
+
};
|
|
810
|
+
|
|
811
|
+
const decode_native_date = (context: ITypiaContext) =>
|
|
812
|
+
ts.factory.createNewExpression(
|
|
813
|
+
ts.factory.createIdentifier("Date"),
|
|
814
|
+
undefined,
|
|
815
|
+
[
|
|
816
|
+
ts.factory.createCallExpression(
|
|
817
|
+
coalesce({
|
|
818
|
+
context,
|
|
819
|
+
method: "datetime",
|
|
820
|
+
internal: "randomFormatDatetime",
|
|
821
|
+
}),
|
|
822
|
+
undefined,
|
|
823
|
+
[],
|
|
824
|
+
),
|
|
825
|
+
],
|
|
826
|
+
);
|
|
827
|
+
|
|
828
|
+
const decode_native_byte_array = (props: {
|
|
829
|
+
context: ITypiaContext;
|
|
830
|
+
functor: FunctionProgrammer;
|
|
831
|
+
explore: IExplore;
|
|
832
|
+
name:
|
|
833
|
+
| "Uint8Array"
|
|
834
|
+
| "Uint8ClampedArray"
|
|
835
|
+
| "Uint16Array"
|
|
836
|
+
| "Uint32Array"
|
|
837
|
+
| "BigUint64Array"
|
|
838
|
+
| "Int8Array"
|
|
839
|
+
| "Int16Array"
|
|
840
|
+
| "Int32Array"
|
|
841
|
+
| "BigInt64Array"
|
|
842
|
+
| "Float32Array"
|
|
843
|
+
| "Float64Array";
|
|
844
|
+
}): ts.Expression => {
|
|
845
|
+
new BigInt64Array();
|
|
846
|
+
const [type, minimum, maximum]: [string, number, number] = (() => {
|
|
847
|
+
if (props.name === "Uint8Array" || props.name === "Uint8ClampedArray")
|
|
848
|
+
return ["uint32", 0, 255];
|
|
849
|
+
else if (props.name === "Uint16Array") return ["uint32", 0, 65535];
|
|
850
|
+
else if (props.name === "Uint32Array") return ["uint32", 0, 4294967295];
|
|
851
|
+
else if (props.name === "BigUint64Array")
|
|
852
|
+
return ["uint64", 0, 18446744073709551615];
|
|
853
|
+
else if (props.name === "Int8Array") return ["int32", -128, 127];
|
|
854
|
+
else if (props.name === "Int16Array") return ["int32", -32768, 32767];
|
|
855
|
+
else if (props.name === "Int32Array")
|
|
856
|
+
return ["int32", -2147483648, 2147483647];
|
|
857
|
+
else if (props.name === "BigInt64Array")
|
|
858
|
+
return ["uint64", -9223372036854775808, 9223372036854775807];
|
|
859
|
+
else if (props.name === "Float32Array")
|
|
860
|
+
return ["float", -1.175494351e38, 3.4028235e38];
|
|
861
|
+
return ["double", Number.MIN_VALUE, Number.MAX_VALUE];
|
|
862
|
+
})();
|
|
863
|
+
const atomic: "bigint" | "number" =
|
|
864
|
+
props.name === "BigInt64Array" || props.name === "BigUint64Array"
|
|
865
|
+
? "bigint"
|
|
866
|
+
: "number";
|
|
867
|
+
const value: Metadata = Metadata.create({
|
|
868
|
+
...Metadata.initialize(),
|
|
869
|
+
atomics: [
|
|
870
|
+
MetadataAtomic.create({
|
|
871
|
+
type: atomic,
|
|
872
|
+
tags: [
|
|
873
|
+
[
|
|
874
|
+
...MetadataCommentTagFactory.get({
|
|
875
|
+
kind: "type",
|
|
876
|
+
type: atomic,
|
|
877
|
+
value: type,
|
|
878
|
+
}),
|
|
879
|
+
...MetadataCommentTagFactory.get({
|
|
880
|
+
kind: "minimum",
|
|
881
|
+
type: "number",
|
|
882
|
+
value: minimum.toString(),
|
|
883
|
+
}),
|
|
884
|
+
...MetadataCommentTagFactory.get({
|
|
885
|
+
kind: "maximum",
|
|
886
|
+
type: "number",
|
|
887
|
+
value: maximum.toString(),
|
|
888
|
+
}),
|
|
889
|
+
],
|
|
890
|
+
],
|
|
891
|
+
}),
|
|
892
|
+
],
|
|
893
|
+
});
|
|
894
|
+
return ts.factory.createNewExpression(
|
|
895
|
+
ts.factory.createIdentifier(props.name),
|
|
896
|
+
[],
|
|
897
|
+
decode_array({
|
|
898
|
+
context: props.context,
|
|
899
|
+
functor: props.functor,
|
|
900
|
+
explore: props.explore,
|
|
901
|
+
array: MetadataArray.create({
|
|
902
|
+
tags: [],
|
|
903
|
+
type: MetadataArrayType.create({
|
|
904
|
+
name: `${props.name}<${atomic}>`,
|
|
905
|
+
value,
|
|
906
|
+
recursive: false,
|
|
907
|
+
index: null,
|
|
908
|
+
nullables: [],
|
|
909
|
+
}),
|
|
910
|
+
}),
|
|
911
|
+
}),
|
|
912
|
+
);
|
|
913
|
+
};
|
|
914
|
+
|
|
915
|
+
const decode_native_blob = (props: {
|
|
916
|
+
context: ITypiaContext;
|
|
917
|
+
functor: FunctionProgrammer;
|
|
918
|
+
explore: IExplore;
|
|
919
|
+
}) =>
|
|
920
|
+
ts.factory.createNewExpression(
|
|
921
|
+
ts.factory.createIdentifier("Blob"),
|
|
922
|
+
undefined,
|
|
923
|
+
[
|
|
924
|
+
ts.factory.createArrayLiteralExpression(
|
|
925
|
+
[
|
|
926
|
+
decode_native_byte_array({
|
|
927
|
+
context: props.context,
|
|
928
|
+
functor: props.functor,
|
|
929
|
+
explore: props.explore,
|
|
930
|
+
name: "Uint8Array",
|
|
931
|
+
}),
|
|
932
|
+
],
|
|
933
|
+
true,
|
|
934
|
+
),
|
|
935
|
+
],
|
|
936
|
+
);
|
|
937
|
+
|
|
938
|
+
const decode_native_file = (props: {
|
|
939
|
+
context: ITypiaContext;
|
|
940
|
+
functor: FunctionProgrammer;
|
|
941
|
+
explore: IExplore;
|
|
942
|
+
}) =>
|
|
943
|
+
ts.factory.createNewExpression(
|
|
944
|
+
ts.factory.createIdentifier("File"),
|
|
945
|
+
undefined,
|
|
946
|
+
[
|
|
947
|
+
ts.factory.createArrayLiteralExpression(
|
|
948
|
+
[
|
|
949
|
+
decode_native_byte_array({
|
|
950
|
+
context: props.context,
|
|
951
|
+
functor: props.functor,
|
|
952
|
+
explore: props.explore,
|
|
953
|
+
name: "Uint8Array",
|
|
954
|
+
}),
|
|
955
|
+
],
|
|
956
|
+
true,
|
|
957
|
+
),
|
|
958
|
+
ts.factory.createTemplateExpression(ts.factory.createTemplateHead(""), [
|
|
959
|
+
ts.factory.createTemplateSpan(
|
|
960
|
+
writeRangedString({
|
|
961
|
+
context: props.context,
|
|
962
|
+
minLength: 1,
|
|
963
|
+
maxLength: 8,
|
|
964
|
+
}),
|
|
965
|
+
ts.factory.createTemplateMiddle("."),
|
|
966
|
+
),
|
|
967
|
+
ts.factory.createTemplateSpan(
|
|
968
|
+
writeRangedString({
|
|
969
|
+
context: props.context,
|
|
970
|
+
minLength: 3,
|
|
971
|
+
maxLength: 3,
|
|
972
|
+
}),
|
|
973
|
+
ts.factory.createTemplateTail(""),
|
|
974
|
+
),
|
|
975
|
+
]),
|
|
976
|
+
],
|
|
977
|
+
);
|
|
978
|
+
|
|
979
|
+
const decode_native_array_buffer = (props: {
|
|
980
|
+
context: ITypiaContext;
|
|
981
|
+
functor: FunctionProgrammer;
|
|
982
|
+
explore: IExplore;
|
|
983
|
+
name: "ArrayBuffer" | "SharedArrayBuffer";
|
|
984
|
+
}): ts.Expression =>
|
|
985
|
+
props.name === "ArrayBuffer"
|
|
986
|
+
? IdentifierFactory.access(
|
|
987
|
+
decode_native_byte_array({
|
|
988
|
+
context: props.context,
|
|
989
|
+
functor: props.functor,
|
|
990
|
+
explore: props.explore,
|
|
991
|
+
name: "Uint8Array",
|
|
992
|
+
}),
|
|
993
|
+
"buffer",
|
|
994
|
+
)
|
|
995
|
+
: ExpressionFactory.selfCall(
|
|
996
|
+
ts.factory.createBlock(
|
|
997
|
+
[
|
|
998
|
+
StatementFactory.constant({
|
|
999
|
+
name: "length",
|
|
1000
|
+
value: decode_atomic({
|
|
1001
|
+
context: props.context,
|
|
1002
|
+
atomic: MetadataAtomic.create({
|
|
1003
|
+
type: "number",
|
|
1004
|
+
tags: [
|
|
1005
|
+
MetadataCommentTagFactory.get({
|
|
1006
|
+
type: "number",
|
|
1007
|
+
kind: "type",
|
|
1008
|
+
value: "uint32",
|
|
1009
|
+
}),
|
|
1010
|
+
],
|
|
1011
|
+
}),
|
|
1012
|
+
})[0]!,
|
|
1013
|
+
}),
|
|
1014
|
+
StatementFactory.constant({
|
|
1015
|
+
name: "buffer",
|
|
1016
|
+
value: ts.factory.createNewExpression(
|
|
1017
|
+
ts.factory.createIdentifier("SharedArrayBuffer"),
|
|
1018
|
+
[],
|
|
1019
|
+
[ts.factory.createIdentifier("length")],
|
|
1020
|
+
),
|
|
1021
|
+
}),
|
|
1022
|
+
StatementFactory.constant({
|
|
1023
|
+
name: "bytes",
|
|
1024
|
+
value: ts.factory.createNewExpression(
|
|
1025
|
+
ts.factory.createIdentifier("Uint8Array"),
|
|
1026
|
+
[],
|
|
1027
|
+
[ts.factory.createIdentifier("buffer")],
|
|
1028
|
+
),
|
|
1029
|
+
}),
|
|
1030
|
+
ts.factory.createExpressionStatement(
|
|
1031
|
+
ts.factory.createCallExpression(
|
|
1032
|
+
IdentifierFactory.access(
|
|
1033
|
+
ts.factory.createIdentifier("bytes"),
|
|
1034
|
+
"set",
|
|
1035
|
+
),
|
|
1036
|
+
undefined,
|
|
1037
|
+
[
|
|
1038
|
+
ts.factory.createCallExpression(
|
|
1039
|
+
ts.factory.createPropertyAccessExpression(
|
|
1040
|
+
ts.factory.createCallExpression(
|
|
1041
|
+
ts.factory.createPropertyAccessExpression(
|
|
1042
|
+
ts.factory.createNewExpression(
|
|
1043
|
+
ts.factory.createIdentifier("Array"),
|
|
1044
|
+
undefined,
|
|
1045
|
+
[ts.factory.createIdentifier("length")],
|
|
1046
|
+
),
|
|
1047
|
+
ts.factory.createIdentifier("fill"),
|
|
1048
|
+
),
|
|
1049
|
+
undefined,
|
|
1050
|
+
[ts.factory.createNumericLiteral("0")],
|
|
1051
|
+
),
|
|
1052
|
+
ts.factory.createIdentifier("map"),
|
|
1053
|
+
),
|
|
1054
|
+
undefined,
|
|
1055
|
+
[
|
|
1056
|
+
ts.factory.createArrowFunction(
|
|
1057
|
+
undefined,
|
|
1058
|
+
undefined,
|
|
1059
|
+
[],
|
|
1060
|
+
undefined,
|
|
1061
|
+
undefined,
|
|
1062
|
+
decode_atomic({
|
|
1063
|
+
context: props.context,
|
|
1064
|
+
atomic: MetadataAtomic.create({
|
|
1065
|
+
type: "number",
|
|
1066
|
+
tags: [
|
|
1067
|
+
[
|
|
1068
|
+
...MetadataCommentTagFactory.get({
|
|
1069
|
+
kind: "type",
|
|
1070
|
+
type: "number",
|
|
1071
|
+
value: "uint32",
|
|
1072
|
+
}),
|
|
1073
|
+
...MetadataCommentTagFactory.get({
|
|
1074
|
+
kind: "minimum",
|
|
1075
|
+
type: "number",
|
|
1076
|
+
value: "0",
|
|
1077
|
+
}),
|
|
1078
|
+
...MetadataCommentTagFactory.get({
|
|
1079
|
+
kind: "maximum",
|
|
1080
|
+
type: "number",
|
|
1081
|
+
value: "255",
|
|
1082
|
+
}),
|
|
1083
|
+
],
|
|
1084
|
+
],
|
|
1085
|
+
}),
|
|
1086
|
+
})[0]!,
|
|
1087
|
+
),
|
|
1088
|
+
],
|
|
1089
|
+
),
|
|
1090
|
+
ExpressionFactory.number(0),
|
|
1091
|
+
],
|
|
1092
|
+
),
|
|
1093
|
+
),
|
|
1094
|
+
ts.factory.createReturnStatement(
|
|
1095
|
+
ts.factory.createIdentifier("buffer"),
|
|
1096
|
+
),
|
|
1097
|
+
],
|
|
1098
|
+
true,
|
|
1099
|
+
),
|
|
1100
|
+
);
|
|
1101
|
+
|
|
1102
|
+
const decode_native_data_view = (props: {
|
|
1103
|
+
context: ITypiaContext;
|
|
1104
|
+
functor: FunctionProgrammer;
|
|
1105
|
+
explore: IExplore;
|
|
1106
|
+
}) =>
|
|
1107
|
+
ts.factory.createNewExpression(
|
|
1108
|
+
ts.factory.createIdentifier("DataView"),
|
|
1109
|
+
[],
|
|
1110
|
+
[
|
|
1111
|
+
IdentifierFactory.access(
|
|
1112
|
+
decode_native_byte_array({
|
|
1113
|
+
context: props.context,
|
|
1114
|
+
functor: props.functor,
|
|
1115
|
+
explore: props.explore,
|
|
1116
|
+
name: "Uint8Array",
|
|
1117
|
+
}),
|
|
1118
|
+
"buffer",
|
|
1119
|
+
),
|
|
1120
|
+
],
|
|
1121
|
+
);
|
|
1122
|
+
|
|
1123
|
+
const decode_regexp = (context: ITypiaContext) =>
|
|
1124
|
+
ts.factory.createNewExpression(
|
|
1125
|
+
ts.factory.createIdentifier("RegExp"),
|
|
1126
|
+
[],
|
|
1127
|
+
[
|
|
1128
|
+
ts.factory.createCallExpression(
|
|
1129
|
+
coalesce({
|
|
1130
|
+
context,
|
|
1131
|
+
method: "regex",
|
|
1132
|
+
internal: "randomFormatRegex",
|
|
1133
|
+
}),
|
|
1134
|
+
undefined,
|
|
1135
|
+
undefined,
|
|
1136
|
+
),
|
|
1137
|
+
],
|
|
1138
|
+
);
|
|
1139
|
+
|
|
1140
|
+
const writeRangedString = (props: {
|
|
1141
|
+
context: ITypiaContext;
|
|
1142
|
+
minLength: number;
|
|
1143
|
+
maxLength: number;
|
|
1144
|
+
}): ts.CallExpression =>
|
|
1145
|
+
decode_atomic({
|
|
1146
|
+
context: props.context,
|
|
1147
|
+
atomic: MetadataAtomic.create({
|
|
1148
|
+
type: "string",
|
|
1149
|
+
tags: [
|
|
1150
|
+
[
|
|
1151
|
+
...MetadataCommentTagFactory.get({
|
|
1152
|
+
kind: "minLength",
|
|
1153
|
+
type: "string",
|
|
1154
|
+
value: props.minLength.toString(),
|
|
1155
|
+
}),
|
|
1156
|
+
...MetadataCommentTagFactory.get({
|
|
1157
|
+
kind: "maxLength",
|
|
1158
|
+
type: "string",
|
|
1159
|
+
value: props.maxLength.toString(),
|
|
1160
|
+
}),
|
|
1161
|
+
],
|
|
1162
|
+
],
|
|
1163
|
+
}),
|
|
1164
|
+
})[0]!;
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
const coalesce = (props: {
|
|
1168
|
+
context: ITypiaContext;
|
|
1169
|
+
method: string;
|
|
1170
|
+
internal: string;
|
|
1171
|
+
}): ts.Expression =>
|
|
1172
|
+
ExpressionFactory.coalesce(
|
|
1173
|
+
ts.factory.createPropertyAccessChain(
|
|
1174
|
+
ts.factory.createIdentifier("_generator"),
|
|
1175
|
+
ts.factory.createToken(ts.SyntaxKind.QuestionDotToken),
|
|
1176
|
+
ts.factory.createIdentifier(props.method),
|
|
1177
|
+
),
|
|
1178
|
+
props.context.importer.internal(props.internal),
|
|
1179
|
+
);
|
|
1180
|
+
|
|
1181
|
+
interface IExplore {
|
|
1182
|
+
function: boolean;
|
|
1183
|
+
recursive: boolean;
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
const Prefix = {
|
|
1187
|
+
object: (i: number) => `_ro${i}`,
|
|
1188
|
+
array: (i: number) => `_ra${i}`,
|
|
1189
|
+
tuple: (i: number) => `_rt${i}`,
|
|
1190
|
+
};
|