typia 9.2.0 → 9.3.0-dev.20250511
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 +149 -149
- package/lib/executable/setup/PluginConfigurator.js +3 -3
- package/lib/executable/setup/PluginConfigurator.mjs +3 -3
- package/lib/executable/typia.js +15 -15
- package/lib/executable/typia.mjs +15 -15
- package/lib/factories/ExpressionFactory.d.mts +1 -1
- package/lib/factories/ExpressionFactory.d.ts +1 -1
- package/lib/factories/ExpressionFactory.js +2 -2
- package/lib/factories/ExpressionFactory.js.map +1 -1
- package/lib/factories/ExpressionFactory.mjs +2 -2
- package/lib/llm.d.mts +6 -4
- package/lib/llm.d.ts +6 -4
- package/lib/llm.js +7 -0
- package/lib/llm.js.map +1 -1
- package/lib/llm.mjs +7 -1
- package/lib/transformers/CallExpressionTransformer.js +2 -0
- package/lib/transformers/CallExpressionTransformer.js.map +1 -1
- package/lib/transformers/CallExpressionTransformer.mjs +2 -0
- package/lib/transformers/features/llm/LlmApplicationTransformer.js +46 -35
- package/lib/transformers/features/llm/LlmApplicationTransformer.js.map +1 -1
- package/lib/transformers/features/llm/LlmApplicationTransformer.mjs +44 -34
- package/lib/transformers/features/llm/LlmControllerTransformer.d.mts +5 -0
- package/lib/transformers/features/llm/LlmControllerTransformer.d.ts +5 -0
- package/lib/transformers/features/llm/LlmControllerTransformer.js +67 -0
- package/lib/transformers/features/llm/LlmControllerTransformer.js.map +1 -0
- package/lib/transformers/features/llm/LlmControllerTransformer.mjs +63 -0
- package/lib/transformers/features/llm/LlmControllerTransformer.mjs.map +1 -0
- package/package.json +2 -2
- package/src/AssertionGuard.ts +1 -1
- package/src/CamelCase.ts +75 -75
- package/src/IRandomGenerator.ts +49 -49
- package/src/IReadableURLSearchParams.ts +9 -9
- package/src/IValidation.ts +1 -1
- package/src/PascalCase.ts +71 -71
- package/src/Primitive.ts +92 -92
- package/src/Resolved.ts +74 -74
- package/src/SnakeCase.ts +126 -126
- package/src/TypeGuardError.ts +37 -37
- package/src/executable/TypiaGenerateWizard.ts +83 -83
- package/src/executable/TypiaPatchWizard.ts +45 -45
- package/src/executable/TypiaSetupWizard.ts +171 -171
- package/src/executable/setup/ArgumentParser.ts +42 -42
- package/src/executable/setup/CommandExecutor.ts +8 -8
- package/src/executable/setup/FileRetriever.ts +19 -19
- package/src/executable/setup/PackageManager.ts +87 -87
- package/src/executable/setup/PluginConfigurator.ts +69 -69
- package/src/executable/typia.ts +55 -55
- package/src/factories/CommentFactory.ts +79 -79
- package/src/factories/ExpressionFactory.ts +219 -216
- package/src/factories/IdentifierFactory.ts +89 -89
- package/src/factories/JsonMetadataFactory.ts +83 -83
- package/src/factories/LiteralFactory.ts +52 -52
- package/src/factories/MetadataCollection.ts +278 -278
- package/src/factories/MetadataCommentTagFactory.ts +648 -648
- package/src/factories/MetadataFactory.ts +404 -404
- package/src/factories/MetadataTypeTagFactory.ts +413 -413
- 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/ValueFactory.ts +12 -12
- package/src/factories/internal/metadata/IMetadataIteratorProps.ts +17 -17
- package/src/factories/internal/metadata/MetadataHelper.ts +21 -21
- package/src/factories/internal/metadata/emend_metadata_atomics.ts +45 -45
- 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 +212 -212
- 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 +212 -212
- package/src/factories/internal/metadata/iterate_metadata_map.ts +57 -57
- package/src/factories/internal/metadata/iterate_metadata_native.ts +264 -264
- 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 +740 -740
- package/src/http.ts +1040 -1040
- package/src/index.ts +4 -4
- 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/_createStandardSchema.ts +134 -134
- 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 +53 -53
- package/src/internal/_randomNumber.ts +80 -80
- 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 +696 -696
- package/src/llm.ts +358 -335
- package/src/misc.ts +651 -651
- package/src/module.ts +936 -936
- package/src/notations.ts +820 -820
- package/src/programmers/AssertProgrammer.ts +454 -454
- package/src/programmers/CheckerProgrammer.ts +1617 -1617
- package/src/programmers/FeatureProgrammer.ts +627 -627
- 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 +175 -175
- package/src/programmers/ValidateProgrammer.ts +448 -448
- 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/ICheckEntry.ts +13 -13
- package/src/programmers/helpers/IExpressionEntry.ts +12 -12
- 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/ProtobufWire.ts +34 -34
- 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 +185 -185
- 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_native.ts +7 -7
- 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 +266 -266
- 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/JsonSchemaProgrammer.ts +26 -26
- 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/LlmApplicationProgrammer.ts +401 -401
- package/src/programmers/llm/LlmModelPredicator.ts +127 -127
- package/src/programmers/llm/LlmParametersProgrammer.ts +93 -93
- package/src/programmers/llm/LlmSchemaProgrammer.ts +192 -192
- 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 +861 -861
- package/src/reflect.ts +50 -50
- package/src/schemas/json/IJsonApplication.ts +73 -73
- package/src/schemas/json/IJsonSchemaCollection.ts +29 -29
- package/src/schemas/json/IJsonSchemaUnit.ts +32 -32
- package/src/schemas/json/__IJsonApplication.ts +63 -63
- package/src/schemas/metadata/IJsDocTagInfo.ts +10 -10
- 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/IMetadataArrayType.ts +10 -10
- package/src/schemas/metadata/IMetadataAtomic.ts +6 -6
- package/src/schemas/metadata/IMetadataComponents.ts +11 -11
- package/src/schemas/metadata/IMetadataConstant.ts +18 -18
- package/src/schemas/metadata/IMetadataConstantValue.ts +11 -11
- package/src/schemas/metadata/IMetadataDictionary.ts +11 -11
- package/src/schemas/metadata/IMetadataEscaped.ts +6 -6
- package/src/schemas/metadata/IMetadataFunction.ts +8 -8
- 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/IMetadataParameter.ts +9 -9
- package/src/schemas/metadata/IMetadataProperty.ts +9 -9
- 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/IMetadataTupleType.ts +10 -10
- package/src/schemas/metadata/IMetadataTypeTag.ts +16 -16
- package/src/schemas/metadata/Metadata.ts +687 -687
- 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/MetadataArrayType.ts +57 -57
- package/src/schemas/metadata/MetadataAtomic.ts +87 -87
- package/src/schemas/metadata/MetadataComponents.ts +98 -98
- package/src/schemas/metadata/MetadataConstant.ts +34 -34
- package/src/schemas/metadata/MetadataConstantValue.ts +62 -62
- package/src/schemas/metadata/MetadataEscaped.ts +51 -51
- package/src/schemas/metadata/MetadataFunction.ts +49 -49
- 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/metadata/MetadataTupleType.ts +67 -67
- 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/Constant.ts +15 -15
- package/src/tags/ContentMediaType.ts +10 -10
- package/src/tags/Default.ts +22 -22
- package/src/tags/Example.ts +24 -24
- package/src/tags/Examples.ts +16 -16
- package/src/tags/ExclusiveMaximum.ts +23 -23
- package/src/tags/ExclusiveMinimum.ts +23 -23
- package/src/tags/Format.ts +50 -50
- package/src/tags/JsonSchemaPlugin.ts +8 -8
- package/src/tags/MaxItems.ts +12 -12
- package/src/tags/MaxLength.ts +12 -12
- package/src/tags/Maximum.ts +19 -19
- package/src/tags/MinItems.ts +12 -12
- package/src/tags/MinLength.ts +12 -12
- package/src/tags/Minimum.ts +19 -19
- package/src/tags/MultipleOf.ts +21 -21
- package/src/tags/Pattern.ts +31 -31
- package/src/tags/Sequence.ts +10 -10
- package/src/tags/TagBase.ts +82 -82
- package/src/tags/Type.ts +37 -37
- package/src/tags/UniqueItems.ts +14 -14
- package/src/tags/index.ts +21 -21
- package/src/tags/internal/FormatCheatSheet.ts +73 -73
- package/src/transform.ts +35 -35
- package/src/transformers/CallExpressionTransformer.ts +554 -552
- 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/NoTransformConfigurationError.ts +18 -18
- 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/JsonSchemaTransformer.ts +135 -135
- package/src/transformers/features/json/JsonSchemasTransformer.ts +145 -145
- 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/LlmApplicationTransformer.ts +145 -128
- package/src/transformers/features/llm/LlmControllerTransformer.ts +93 -0
- package/src/transformers/features/llm/LlmParametersTransformer.ts +102 -102
- package/src/transformers/features/llm/LlmSchemaTransformer.ts +170 -170
- 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/typings/Atomic.ts +13 -13
- package/src/typings/ClassProperties.ts +5 -5
- package/src/typings/Customizable.ts +5 -5
- package/src/typings/Equal.ts +18 -18
- package/src/typings/IsTuple.ts +9 -9
- package/src/typings/NativeClass.ts +23 -23
- package/src/typings/OmitNever.ts +3 -3
- package/src/typings/ProtobufAtomic.ts +19 -19
- package/src/typings/SpecialFields.ts +3 -3
- package/src/typings/ValidationPipe.ts +9 -9
- package/src/typings/ValueOf.ts +20 -20
- package/src/typings/Writable.ts +11 -11
- package/src/utils/ArrayUtil.ts +41 -41
- package/src/utils/Escaper.ts +50 -50
- package/src/utils/MapUtil.ts +14 -14
- package/src/utils/NamingConvention.ts +94 -94
- package/src/utils/PatternUtil.ts +29 -29
- package/src/utils/ProtobufNameEncoder.ts +32 -32
- package/src/utils/Singleton.ts +16 -16
- package/src/utils/StringUtil.ts +16 -16
|
@@ -1,1032 +1,1032 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { ExpressionFactory } from "../../factories/ExpressionFactory";
|
|
4
|
-
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
5
|
-
import { MetadataCollection } from "../../factories/MetadataCollection";
|
|
6
|
-
import { MetadataFactory } from "../../factories/MetadataFactory";
|
|
7
|
-
import { StatementFactory } from "../../factories/StatementFactory";
|
|
8
|
-
import { TypeFactory } from "../../factories/TypeFactory";
|
|
9
|
-
|
|
10
|
-
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
11
|
-
import { MetadataArray } from "../../schemas/metadata/MetadataArray";
|
|
12
|
-
import { MetadataMap } from "../../schemas/metadata/MetadataMap";
|
|
13
|
-
import { MetadataObjectType } from "../../schemas/metadata/MetadataObjectType";
|
|
14
|
-
import { MetadataSet } from "../../schemas/metadata/MetadataSet";
|
|
15
|
-
import { MetadataTuple } from "../../schemas/metadata/MetadataTuple";
|
|
16
|
-
import { MetadataTupleType } from "../../schemas/metadata/MetadataTupleType";
|
|
17
|
-
|
|
18
|
-
import { IProgrammerProps } from "../../transformers/IProgrammerProps";
|
|
19
|
-
import { ITypiaContext } from "../../transformers/ITypiaContext";
|
|
20
|
-
import { TransformerError } from "../../transformers/TransformerError";
|
|
21
|
-
|
|
22
|
-
import { FeatureProgrammer } from "../FeatureProgrammer";
|
|
23
|
-
import { IsProgrammer } from "../IsProgrammer";
|
|
24
|
-
import { CloneJoiner } from "../helpers/CloneJoiner";
|
|
25
|
-
import { FunctionProgrammer } from "../helpers/FunctionProgrammer";
|
|
26
|
-
import { UnionExplorer } from "../helpers/UnionExplorer";
|
|
27
|
-
import { decode_union_object } from "../internal/decode_union_object";
|
|
28
|
-
import { postfix_of_tuple } from "../internal/postfix_of_tuple";
|
|
29
|
-
import { wrap_metadata_rest_tuple } from "../internal/wrap_metadata_rest_tuple";
|
|
30
|
-
|
|
31
|
-
export namespace MiscCloneProgrammer {
|
|
32
|
-
export const decompose = (props: {
|
|
33
|
-
validated: boolean;
|
|
34
|
-
context: ITypiaContext;
|
|
35
|
-
functor: FunctionProgrammer;
|
|
36
|
-
type: ts.Type;
|
|
37
|
-
name: string | undefined;
|
|
38
|
-
}): FeatureProgrammer.IDecomposed => {
|
|
39
|
-
const config: FeatureProgrammer.IConfig = configure(props);
|
|
40
|
-
if (props.validated === false)
|
|
41
|
-
config.addition = (collection) =>
|
|
42
|
-
IsProgrammer.write_function_statements({
|
|
43
|
-
context: props.context,
|
|
44
|
-
functor: props.functor,
|
|
45
|
-
collection,
|
|
46
|
-
});
|
|
47
|
-
const composed: FeatureProgrammer.IComposed = FeatureProgrammer.compose({
|
|
48
|
-
...props,
|
|
49
|
-
config,
|
|
50
|
-
});
|
|
51
|
-
return {
|
|
52
|
-
functions: composed.functions,
|
|
53
|
-
statements: composed.statements,
|
|
54
|
-
arrow: ts.factory.createArrowFunction(
|
|
55
|
-
undefined,
|
|
56
|
-
undefined,
|
|
57
|
-
composed.parameters,
|
|
58
|
-
composed.response,
|
|
59
|
-
undefined,
|
|
60
|
-
composed.body,
|
|
61
|
-
),
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
export const write = (props: IProgrammerProps): ts.CallExpression => {
|
|
66
|
-
const functor: FunctionProgrammer = new FunctionProgrammer(
|
|
67
|
-
props.modulo.getText(),
|
|
68
|
-
);
|
|
69
|
-
const result: FeatureProgrammer.IDecomposed = decompose({
|
|
70
|
-
...props,
|
|
71
|
-
validated: false,
|
|
72
|
-
functor,
|
|
73
|
-
});
|
|
74
|
-
return FeatureProgrammer.writeDecomposed({
|
|
75
|
-
modulo: props.modulo,
|
|
76
|
-
functor,
|
|
77
|
-
result,
|
|
78
|
-
});
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
const write_array_functions = (props: {
|
|
82
|
-
config: FeatureProgrammer.IConfig;
|
|
83
|
-
functor: FunctionProgrammer;
|
|
84
|
-
collection: MetadataCollection;
|
|
85
|
-
}): ts.VariableStatement[] =>
|
|
86
|
-
props.collection
|
|
87
|
-
.arrays()
|
|
88
|
-
.filter((a) => a.recursive)
|
|
89
|
-
.map((type, i) =>
|
|
90
|
-
StatementFactory.constant({
|
|
91
|
-
name: `${props.config.prefix}a${i}`,
|
|
92
|
-
value: ts.factory.createArrowFunction(
|
|
93
|
-
undefined,
|
|
94
|
-
undefined,
|
|
95
|
-
FeatureProgrammer.parameterDeclarations({
|
|
96
|
-
config: props.config,
|
|
97
|
-
type: TypeFactory.keyword("any"),
|
|
98
|
-
input: ts.factory.createIdentifier("input"),
|
|
99
|
-
}),
|
|
100
|
-
TypeFactory.keyword("any"),
|
|
101
|
-
undefined,
|
|
102
|
-
decode_array_inline({
|
|
103
|
-
config: props.config,
|
|
104
|
-
functor: props.functor,
|
|
105
|
-
input: ts.factory.createIdentifier("input"),
|
|
106
|
-
array: MetadataArray.create({
|
|
107
|
-
type,
|
|
108
|
-
tags: [],
|
|
109
|
-
}),
|
|
110
|
-
explore: {
|
|
111
|
-
tracable: props.config.trace,
|
|
112
|
-
source: "function",
|
|
113
|
-
from: "array",
|
|
114
|
-
postfix: "",
|
|
115
|
-
},
|
|
116
|
-
}),
|
|
117
|
-
),
|
|
118
|
-
}),
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
const write_tuple_functions = (props: {
|
|
122
|
-
context: ITypiaContext;
|
|
123
|
-
config: FeatureProgrammer.IConfig;
|
|
124
|
-
functor: FunctionProgrammer;
|
|
125
|
-
collection: MetadataCollection;
|
|
126
|
-
}): ts.VariableStatement[] =>
|
|
127
|
-
props.collection
|
|
128
|
-
.tuples()
|
|
129
|
-
.filter((t) => t.recursive)
|
|
130
|
-
.map((tuple, i) =>
|
|
131
|
-
StatementFactory.constant({
|
|
132
|
-
name: `${props.config.prefix}t${i}`,
|
|
133
|
-
value: ts.factory.createArrowFunction(
|
|
134
|
-
undefined,
|
|
135
|
-
undefined,
|
|
136
|
-
FeatureProgrammer.parameterDeclarations({
|
|
137
|
-
config: props.config,
|
|
138
|
-
type: TypeFactory.keyword("any"),
|
|
139
|
-
input: ts.factory.createIdentifier("input"),
|
|
140
|
-
}),
|
|
141
|
-
TypeFactory.keyword("any"),
|
|
142
|
-
undefined,
|
|
143
|
-
decode_tuple_inline({
|
|
144
|
-
config: props.config,
|
|
145
|
-
context: props.context,
|
|
146
|
-
functor: props.functor,
|
|
147
|
-
input: ts.factory.createIdentifier("input"),
|
|
148
|
-
tuple,
|
|
149
|
-
explore: {
|
|
150
|
-
tracable: props.config.trace,
|
|
151
|
-
source: "function",
|
|
152
|
-
from: "array",
|
|
153
|
-
postfix: "",
|
|
154
|
-
},
|
|
155
|
-
}),
|
|
156
|
-
),
|
|
157
|
-
}),
|
|
158
|
-
);
|
|
159
|
-
|
|
160
|
-
/* -----------------------------------------------------------
|
|
161
|
-
DECODERS
|
|
162
|
-
----------------------------------------------------------- */
|
|
163
|
-
const decode = (props: {
|
|
164
|
-
context: ITypiaContext;
|
|
165
|
-
config: FeatureProgrammer.IConfig;
|
|
166
|
-
functor: FunctionProgrammer;
|
|
167
|
-
input: ts.Expression;
|
|
168
|
-
metadata: Metadata;
|
|
169
|
-
explore: FeatureProgrammer.IExplore;
|
|
170
|
-
}): ts.Expression => {
|
|
171
|
-
// ANY TYPE
|
|
172
|
-
if (
|
|
173
|
-
props.metadata.any ||
|
|
174
|
-
props.metadata.arrays.some((a) => a.type.value.any) ||
|
|
175
|
-
props.metadata.tuples.some(
|
|
176
|
-
(t) => !!t.type.elements.length && t.type.elements.every((e) => e.any),
|
|
177
|
-
)
|
|
178
|
-
)
|
|
179
|
-
return ts.factory.createCallExpression(
|
|
180
|
-
props.context.importer.internal("miscCloneAny"),
|
|
181
|
-
undefined,
|
|
182
|
-
[props.input],
|
|
183
|
-
);
|
|
184
|
-
|
|
185
|
-
interface IUnion {
|
|
186
|
-
type: string;
|
|
187
|
-
is: () => ts.Expression;
|
|
188
|
-
value: () => ts.Expression;
|
|
189
|
-
}
|
|
190
|
-
const unions: IUnion[] = [];
|
|
191
|
-
|
|
192
|
-
//----
|
|
193
|
-
// LIST UP UNION TYPES
|
|
194
|
-
//----
|
|
195
|
-
// FUNCTIONAL
|
|
196
|
-
if (props.metadata.functions.length)
|
|
197
|
-
unions.push({
|
|
198
|
-
type: "functional",
|
|
199
|
-
is: () =>
|
|
200
|
-
ts.factory.createStrictEquality(
|
|
201
|
-
ts.factory.createStringLiteral("function"),
|
|
202
|
-
ts.factory.createTypeOfExpression(props.input),
|
|
203
|
-
),
|
|
204
|
-
value: () => ts.factory.createIdentifier("undefined"),
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
// TUPLES
|
|
208
|
-
for (const tuple of props.metadata.tuples)
|
|
209
|
-
unions.push({
|
|
210
|
-
type: "tuple",
|
|
211
|
-
is: () =>
|
|
212
|
-
IsProgrammer.decode({
|
|
213
|
-
...props,
|
|
214
|
-
metadata: (() => {
|
|
215
|
-
const partial = Metadata.initialize();
|
|
216
|
-
partial.tuples.push(tuple);
|
|
217
|
-
return partial;
|
|
218
|
-
})(),
|
|
219
|
-
}),
|
|
220
|
-
value: () =>
|
|
221
|
-
decode_tuple({
|
|
222
|
-
...props,
|
|
223
|
-
tuple,
|
|
224
|
-
}),
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
// ARRAYS
|
|
228
|
-
if (props.metadata.arrays.length)
|
|
229
|
-
unions.push({
|
|
230
|
-
type: "array",
|
|
231
|
-
is: () => ExpressionFactory.isArray(props.input),
|
|
232
|
-
value: () =>
|
|
233
|
-
explore_arrays({
|
|
234
|
-
...props,
|
|
235
|
-
arrays: props.metadata.arrays,
|
|
236
|
-
explore: {
|
|
237
|
-
...props.explore,
|
|
238
|
-
from: "array",
|
|
239
|
-
},
|
|
240
|
-
}),
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
// NATIVE TYPES
|
|
244
|
-
if (props.metadata.sets.length)
|
|
245
|
-
unions.push({
|
|
246
|
-
type: "set",
|
|
247
|
-
is: () => ExpressionFactory.isInstanceOf("Set", props.input),
|
|
248
|
-
value: () =>
|
|
249
|
-
explore_sets({
|
|
250
|
-
...props,
|
|
251
|
-
sets: props.metadata.sets,
|
|
252
|
-
explore: {
|
|
253
|
-
...props.explore,
|
|
254
|
-
from: "array",
|
|
255
|
-
},
|
|
256
|
-
}),
|
|
257
|
-
});
|
|
258
|
-
if (props.metadata.maps.length)
|
|
259
|
-
unions.push({
|
|
260
|
-
type: "map",
|
|
261
|
-
is: () => ExpressionFactory.isInstanceOf("Map", props.input),
|
|
262
|
-
value: () =>
|
|
263
|
-
explore_maps({
|
|
264
|
-
...props,
|
|
265
|
-
maps: props.metadata.maps,
|
|
266
|
-
explore: {
|
|
267
|
-
...props.explore,
|
|
268
|
-
from: "array",
|
|
269
|
-
},
|
|
270
|
-
}),
|
|
271
|
-
});
|
|
272
|
-
for (const native of props.metadata.natives)
|
|
273
|
-
unions.push({
|
|
274
|
-
type: "native",
|
|
275
|
-
is: () => ExpressionFactory.isInstanceOf(native.name, props.input),
|
|
276
|
-
value: () =>
|
|
277
|
-
native.name === "Boolean" ||
|
|
278
|
-
native.name === "Number" ||
|
|
279
|
-
native.name === "String"
|
|
280
|
-
? ts.factory.createCallExpression(
|
|
281
|
-
IdentifierFactory.access(props.input, "valueOf"),
|
|
282
|
-
undefined,
|
|
283
|
-
undefined,
|
|
284
|
-
)
|
|
285
|
-
: decode_native({
|
|
286
|
-
type: native.name,
|
|
287
|
-
input: props.input,
|
|
288
|
-
}),
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
// OBJECTS
|
|
292
|
-
if (props.metadata.objects.length)
|
|
293
|
-
unions.push({
|
|
294
|
-
type: "object",
|
|
295
|
-
is: () =>
|
|
296
|
-
ExpressionFactory.isObject({
|
|
297
|
-
checkNull: true,
|
|
298
|
-
checkArray: false,
|
|
299
|
-
input: props.input,
|
|
300
|
-
}),
|
|
301
|
-
value: () =>
|
|
302
|
-
explore_objects({
|
|
303
|
-
...props,
|
|
304
|
-
explore: {
|
|
305
|
-
...props.explore,
|
|
306
|
-
from: "object",
|
|
307
|
-
},
|
|
308
|
-
}),
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
// COMPOSITION
|
|
312
|
-
if (unions.length === 0) return props.input;
|
|
313
|
-
else if (unions.length === 1 && props.metadata.size() === 1) {
|
|
314
|
-
const value: ts.Expression =
|
|
315
|
-
(props.metadata.nullable || props.metadata.isRequired() === false) &&
|
|
316
|
-
is_instance(props.metadata)
|
|
317
|
-
? ts.factory.createConditionalExpression(
|
|
318
|
-
props.input,
|
|
319
|
-
undefined,
|
|
320
|
-
unions[0]!.value(),
|
|
321
|
-
undefined,
|
|
322
|
-
props.input,
|
|
323
|
-
)
|
|
324
|
-
: unions[0]!.value();
|
|
325
|
-
return ts.factory.createAsExpression(value, TypeFactory.keyword("any"));
|
|
326
|
-
} else {
|
|
327
|
-
let last: ts.Expression = props.input;
|
|
328
|
-
for (const u of unions.reverse())
|
|
329
|
-
last = ts.factory.createConditionalExpression(
|
|
330
|
-
u.is(),
|
|
331
|
-
undefined,
|
|
332
|
-
u.value(),
|
|
333
|
-
undefined,
|
|
334
|
-
last,
|
|
335
|
-
);
|
|
336
|
-
return ts.factory.createAsExpression(last, TypeFactory.keyword("any"));
|
|
337
|
-
}
|
|
338
|
-
};
|
|
339
|
-
|
|
340
|
-
const decode_object = (props: {
|
|
341
|
-
functor: FunctionProgrammer;
|
|
342
|
-
input: ts.Expression;
|
|
343
|
-
object: MetadataObjectType;
|
|
344
|
-
explore: FeatureProgrammer.IExplore;
|
|
345
|
-
}) =>
|
|
346
|
-
FeatureProgrammer.decode_object({
|
|
347
|
-
config: {
|
|
348
|
-
trace: false,
|
|
349
|
-
path: false,
|
|
350
|
-
prefix: PREFIX,
|
|
351
|
-
},
|
|
352
|
-
functor: props.functor,
|
|
353
|
-
input: props.input,
|
|
354
|
-
object: props.object,
|
|
355
|
-
explore: props.explore,
|
|
356
|
-
});
|
|
357
|
-
|
|
358
|
-
const decode_array = (props: {
|
|
359
|
-
config: FeatureProgrammer.IConfig;
|
|
360
|
-
functor: FunctionProgrammer;
|
|
361
|
-
input: ts.Expression;
|
|
362
|
-
array: MetadataArray;
|
|
363
|
-
explore: FeatureProgrammer.IExplore;
|
|
364
|
-
}) =>
|
|
365
|
-
props.array.type.recursive
|
|
366
|
-
? ts.factory.createCallExpression(
|
|
367
|
-
ts.factory.createIdentifier(
|
|
368
|
-
props.functor.useLocal(
|
|
369
|
-
`${props.config.prefix}a${props.array.type.index}`,
|
|
370
|
-
),
|
|
371
|
-
),
|
|
372
|
-
undefined,
|
|
373
|
-
FeatureProgrammer.argumentsArray({
|
|
374
|
-
config: props.config,
|
|
375
|
-
explore: {
|
|
376
|
-
...props.explore,
|
|
377
|
-
source: "function",
|
|
378
|
-
from: "array",
|
|
379
|
-
},
|
|
380
|
-
input: props.input,
|
|
381
|
-
}),
|
|
382
|
-
)
|
|
383
|
-
: decode_array_inline(props);
|
|
384
|
-
|
|
385
|
-
const decode_array_inline = (props: {
|
|
386
|
-
config: FeatureProgrammer.IConfig;
|
|
387
|
-
functor: FunctionProgrammer;
|
|
388
|
-
input: ts.Expression;
|
|
389
|
-
array: MetadataArray;
|
|
390
|
-
explore: FeatureProgrammer.IExplore;
|
|
391
|
-
}) =>
|
|
392
|
-
FeatureProgrammer.decode_array({
|
|
393
|
-
config: props.config,
|
|
394
|
-
functor: props.functor,
|
|
395
|
-
combiner: CloneJoiner.array,
|
|
396
|
-
array: props.array,
|
|
397
|
-
input: props.input,
|
|
398
|
-
explore: props.explore,
|
|
399
|
-
});
|
|
400
|
-
|
|
401
|
-
const decode_tuple = (props: {
|
|
402
|
-
context: ITypiaContext;
|
|
403
|
-
config: FeatureProgrammer.IConfig;
|
|
404
|
-
functor: FunctionProgrammer;
|
|
405
|
-
input: ts.Expression;
|
|
406
|
-
tuple: MetadataTuple;
|
|
407
|
-
explore: FeatureProgrammer.IExplore;
|
|
408
|
-
}): ts.Expression =>
|
|
409
|
-
props.tuple.type.recursive
|
|
410
|
-
? ts.factory.createCallExpression(
|
|
411
|
-
ts.factory.createIdentifier(
|
|
412
|
-
props.functor.useLocal(
|
|
413
|
-
`${props.config.prefix}t${props.tuple.type.index}`,
|
|
414
|
-
),
|
|
415
|
-
),
|
|
416
|
-
undefined,
|
|
417
|
-
FeatureProgrammer.argumentsArray({
|
|
418
|
-
config: props.config,
|
|
419
|
-
explore: {
|
|
420
|
-
...props.explore,
|
|
421
|
-
source: "function",
|
|
422
|
-
},
|
|
423
|
-
input: props.input,
|
|
424
|
-
}),
|
|
425
|
-
)
|
|
426
|
-
: decode_tuple_inline({
|
|
427
|
-
...props,
|
|
428
|
-
tuple: props.tuple.type,
|
|
429
|
-
});
|
|
430
|
-
|
|
431
|
-
const decode_tuple_inline = (props: {
|
|
432
|
-
context: ITypiaContext;
|
|
433
|
-
config: FeatureProgrammer.IConfig;
|
|
434
|
-
functor: FunctionProgrammer;
|
|
435
|
-
input: ts.Expression;
|
|
436
|
-
tuple: MetadataTupleType;
|
|
437
|
-
explore: FeatureProgrammer.IExplore;
|
|
438
|
-
}): ts.Expression => {
|
|
439
|
-
const elements: ts.Expression[] = props.tuple.elements
|
|
440
|
-
.filter((m) => m.rest === null)
|
|
441
|
-
.map((elem, index) =>
|
|
442
|
-
decode({
|
|
443
|
-
context: props.context,
|
|
444
|
-
config: props.config,
|
|
445
|
-
functor: props.functor,
|
|
446
|
-
input: ts.factory.createElementAccessExpression(props.input, index),
|
|
447
|
-
metadata: elem,
|
|
448
|
-
explore: {
|
|
449
|
-
...props.explore,
|
|
450
|
-
from: "array",
|
|
451
|
-
postfix: props.explore.postfix.length
|
|
452
|
-
? `${postfix_of_tuple(props.explore.postfix)}[${index}]"`
|
|
453
|
-
: `"[${index}]"`,
|
|
454
|
-
},
|
|
455
|
-
}),
|
|
456
|
-
);
|
|
457
|
-
const rest = (() => {
|
|
458
|
-
if (props.tuple.elements.length === 0) return null;
|
|
459
|
-
|
|
460
|
-
const last: Metadata = props.tuple.elements.at(-1)!;
|
|
461
|
-
const rest: Metadata | null = last.rest;
|
|
462
|
-
if (rest === null) return null;
|
|
463
|
-
|
|
464
|
-
return decode({
|
|
465
|
-
context: props.context,
|
|
466
|
-
config: props.config,
|
|
467
|
-
functor: props.functor,
|
|
468
|
-
input: ts.factory.createCallExpression(
|
|
469
|
-
IdentifierFactory.access(props.input, "slice"),
|
|
470
|
-
undefined,
|
|
471
|
-
[ExpressionFactory.number(props.tuple.elements.length - 1)],
|
|
472
|
-
),
|
|
473
|
-
metadata: wrap_metadata_rest_tuple(props.tuple.elements.at(-1)!.rest!),
|
|
474
|
-
explore: {
|
|
475
|
-
...props.explore,
|
|
476
|
-
start: props.tuple.elements.length - 1,
|
|
477
|
-
},
|
|
478
|
-
});
|
|
479
|
-
})();
|
|
480
|
-
return CloneJoiner.tuple({
|
|
481
|
-
elements,
|
|
482
|
-
rest,
|
|
483
|
-
});
|
|
484
|
-
};
|
|
485
|
-
|
|
486
|
-
/* -----------------------------------------------------------
|
|
487
|
-
NATIVE CLASSES
|
|
488
|
-
----------------------------------------------------------- */
|
|
489
|
-
const decode_native = (props: { type: string; input: ts.Expression }) =>
|
|
490
|
-
props.type === "Date" ||
|
|
491
|
-
props.type === "Uint8Array" ||
|
|
492
|
-
props.type === "Uint8ClampedArray" ||
|
|
493
|
-
props.type === "Uint16Array" ||
|
|
494
|
-
props.type === "Uint32Array" ||
|
|
495
|
-
props.type === "BigUint64Array" ||
|
|
496
|
-
props.type === "Int8Array" ||
|
|
497
|
-
props.type === "Int16Array" ||
|
|
498
|
-
props.type === "Int32Array" ||
|
|
499
|
-
props.type === "BigInt64Array" ||
|
|
500
|
-
props.type === "Float32Array" ||
|
|
501
|
-
props.type === "Float64Array" ||
|
|
502
|
-
props.type === "RegExp"
|
|
503
|
-
? decode_native_copyable(props)
|
|
504
|
-
: props.type === "ArrayBuffer" || props.type === "SharedArrayBuffer"
|
|
505
|
-
? decode_native_buffer({
|
|
506
|
-
type: props.type,
|
|
507
|
-
input: props.input,
|
|
508
|
-
})
|
|
509
|
-
: props.type === "DataView"
|
|
510
|
-
? decode_native_data_view(props.input)
|
|
511
|
-
: ts.factory.createCallExpression(
|
|
512
|
-
ts.factory.createIdentifier(props.type),
|
|
513
|
-
undefined,
|
|
514
|
-
[],
|
|
515
|
-
);
|
|
516
|
-
|
|
517
|
-
const decode_native_copyable = (props: {
|
|
518
|
-
type: string;
|
|
519
|
-
input: ts.Expression;
|
|
520
|
-
}) =>
|
|
521
|
-
ts.factory.createNewExpression(
|
|
522
|
-
ts.factory.createIdentifier(props.type),
|
|
523
|
-
undefined,
|
|
524
|
-
[props.input],
|
|
525
|
-
);
|
|
526
|
-
|
|
527
|
-
const decode_native_buffer = (props: {
|
|
528
|
-
type: "ArrayBuffer" | "SharedArrayBuffer";
|
|
529
|
-
input: ts.Expression;
|
|
530
|
-
}) =>
|
|
531
|
-
ExpressionFactory.selfCall(
|
|
532
|
-
ts.factory.createBlock(
|
|
533
|
-
[
|
|
534
|
-
StatementFactory.constant({
|
|
535
|
-
name: "buffer",
|
|
536
|
-
value: ts.factory.createNewExpression(
|
|
537
|
-
ts.factory.createIdentifier(props.type),
|
|
538
|
-
undefined,
|
|
539
|
-
[IdentifierFactory.access(props.input, "byteLength")],
|
|
540
|
-
),
|
|
541
|
-
}),
|
|
542
|
-
ts.factory.createExpressionStatement(
|
|
543
|
-
ts.factory.createCallExpression(
|
|
544
|
-
IdentifierFactory.access(
|
|
545
|
-
ts.factory.createNewExpression(
|
|
546
|
-
ts.factory.createIdentifier("Uint8Array"),
|
|
547
|
-
undefined,
|
|
548
|
-
[ts.factory.createIdentifier("buffer")],
|
|
549
|
-
),
|
|
550
|
-
"set",
|
|
551
|
-
),
|
|
552
|
-
undefined,
|
|
553
|
-
[
|
|
554
|
-
ts.factory.createNewExpression(
|
|
555
|
-
ts.factory.createIdentifier("Uint8Array"),
|
|
556
|
-
undefined,
|
|
557
|
-
[props.input],
|
|
558
|
-
),
|
|
559
|
-
],
|
|
560
|
-
),
|
|
561
|
-
),
|
|
562
|
-
ts.factory.createReturnStatement(
|
|
563
|
-
ts.factory.createIdentifier("buffer"),
|
|
564
|
-
),
|
|
565
|
-
],
|
|
566
|
-
true,
|
|
567
|
-
),
|
|
568
|
-
);
|
|
569
|
-
|
|
570
|
-
const decode_native_data_view = (input: ts.Expression) =>
|
|
571
|
-
ts.factory.createNewExpression(
|
|
572
|
-
ts.factory.createIdentifier("DataView"),
|
|
573
|
-
undefined,
|
|
574
|
-
[IdentifierFactory.access(input, "buffer")],
|
|
575
|
-
);
|
|
576
|
-
|
|
577
|
-
/* -----------------------------------------------------------
|
|
578
|
-
EXPLORERS FOR UNION TYPES
|
|
579
|
-
----------------------------------------------------------- */
|
|
580
|
-
const explore_sets = (props: {
|
|
581
|
-
context: ITypiaContext;
|
|
582
|
-
config: FeatureProgrammer.IConfig;
|
|
583
|
-
functor: FunctionProgrammer;
|
|
584
|
-
input: ts.Expression;
|
|
585
|
-
sets: MetadataSet[];
|
|
586
|
-
explore: FeatureProgrammer.IExplore;
|
|
587
|
-
}): ts.Expression =>
|
|
588
|
-
ts.factory.createCallExpression(
|
|
589
|
-
UnionExplorer.set({
|
|
590
|
-
config: {
|
|
591
|
-
checker: (v) =>
|
|
592
|
-
IsProgrammer.decode({
|
|
593
|
-
context: props.context,
|
|
594
|
-
functor: props.functor,
|
|
595
|
-
input: v.input,
|
|
596
|
-
metadata: v.definition,
|
|
597
|
-
explore: v.explore,
|
|
598
|
-
}),
|
|
599
|
-
decoder: (v) =>
|
|
600
|
-
ts.factory.createNewExpression(
|
|
601
|
-
ts.factory.createIdentifier("Set"),
|
|
602
|
-
[TypeFactory.keyword("any")],
|
|
603
|
-
[
|
|
604
|
-
decode_array({
|
|
605
|
-
config: props.config,
|
|
606
|
-
functor: props.functor,
|
|
607
|
-
input: v.input,
|
|
608
|
-
array: v.definition,
|
|
609
|
-
explore: v.explore,
|
|
610
|
-
}),
|
|
611
|
-
],
|
|
612
|
-
),
|
|
613
|
-
empty: ts.factory.createNewExpression(
|
|
614
|
-
ts.factory.createIdentifier("Set"),
|
|
615
|
-
[TypeFactory.keyword("any")],
|
|
616
|
-
[],
|
|
617
|
-
),
|
|
618
|
-
success: ts.factory.createTrue(),
|
|
619
|
-
failure: (v) =>
|
|
620
|
-
create_throw_error({
|
|
621
|
-
context: props.context,
|
|
622
|
-
functor: props.functor,
|
|
623
|
-
expected: v.expected,
|
|
624
|
-
input: v.input,
|
|
625
|
-
}),
|
|
626
|
-
},
|
|
627
|
-
parameters: [],
|
|
628
|
-
input: props.input,
|
|
629
|
-
sets: props.sets,
|
|
630
|
-
explore: props.explore,
|
|
631
|
-
}),
|
|
632
|
-
undefined,
|
|
633
|
-
undefined,
|
|
634
|
-
);
|
|
635
|
-
|
|
636
|
-
const explore_maps = (props: {
|
|
637
|
-
context: ITypiaContext;
|
|
638
|
-
config: FeatureProgrammer.IConfig;
|
|
639
|
-
functor: FunctionProgrammer;
|
|
640
|
-
input: ts.Expression;
|
|
641
|
-
maps: MetadataMap[];
|
|
642
|
-
explore: FeatureProgrammer.IExplore;
|
|
643
|
-
}): ts.Expression =>
|
|
644
|
-
ts.factory.createCallExpression(
|
|
645
|
-
UnionExplorer.map({
|
|
646
|
-
config: {
|
|
647
|
-
checker: (v) =>
|
|
648
|
-
ts.factory.createLogicalAnd(
|
|
649
|
-
IsProgrammer.decode({
|
|
650
|
-
context: props.context,
|
|
651
|
-
functor: props.functor,
|
|
652
|
-
input: ts.factory.createElementAccessExpression(v.input, 0),
|
|
653
|
-
metadata: v.definition[0],
|
|
654
|
-
explore: {
|
|
655
|
-
...v.explore,
|
|
656
|
-
postfix: `${v.explore.postfix}[0]`,
|
|
657
|
-
},
|
|
658
|
-
}),
|
|
659
|
-
IsProgrammer.decode({
|
|
660
|
-
context: props.context,
|
|
661
|
-
functor: props.functor,
|
|
662
|
-
input: ts.factory.createElementAccessExpression(v.input, 1),
|
|
663
|
-
metadata: v.definition[1],
|
|
664
|
-
explore: {
|
|
665
|
-
...v.explore,
|
|
666
|
-
postfix: `${v.explore.postfix}[1]`,
|
|
667
|
-
},
|
|
668
|
-
}),
|
|
669
|
-
),
|
|
670
|
-
decoder: (v) =>
|
|
671
|
-
ts.factory.createNewExpression(
|
|
672
|
-
ts.factory.createIdentifier("Map"),
|
|
673
|
-
[TypeFactory.keyword("any"), TypeFactory.keyword("any")],
|
|
674
|
-
[
|
|
675
|
-
decode_array({
|
|
676
|
-
config: props.config,
|
|
677
|
-
functor: props.functor,
|
|
678
|
-
input: v.input,
|
|
679
|
-
array: v.definition,
|
|
680
|
-
explore: v.explore,
|
|
681
|
-
}),
|
|
682
|
-
],
|
|
683
|
-
),
|
|
684
|
-
empty: ts.factory.createNewExpression(
|
|
685
|
-
ts.factory.createIdentifier("Map"),
|
|
686
|
-
[TypeFactory.keyword("any"), TypeFactory.keyword("any")],
|
|
687
|
-
[],
|
|
688
|
-
),
|
|
689
|
-
success: ts.factory.createTrue(),
|
|
690
|
-
failure: (v) =>
|
|
691
|
-
create_throw_error({
|
|
692
|
-
context: props.context,
|
|
693
|
-
functor: props.functor,
|
|
694
|
-
expected: v.expected,
|
|
695
|
-
input: v.input,
|
|
696
|
-
}),
|
|
697
|
-
},
|
|
698
|
-
parameters: [],
|
|
699
|
-
input: props.input,
|
|
700
|
-
maps: props.maps,
|
|
701
|
-
explore: props.explore,
|
|
702
|
-
}),
|
|
703
|
-
// ([])(props.input, props.maps, props.explore),
|
|
704
|
-
undefined,
|
|
705
|
-
undefined,
|
|
706
|
-
);
|
|
707
|
-
|
|
708
|
-
const explore_objects = (props: {
|
|
709
|
-
config: FeatureProgrammer.IConfig;
|
|
710
|
-
functor: FunctionProgrammer;
|
|
711
|
-
input: ts.Expression;
|
|
712
|
-
metadata: Metadata;
|
|
713
|
-
explore: FeatureProgrammer.IExplore;
|
|
714
|
-
}) =>
|
|
715
|
-
props.metadata.objects.length === 1
|
|
716
|
-
? decode_object({
|
|
717
|
-
...props,
|
|
718
|
-
object: props.metadata.objects[0]!.type,
|
|
719
|
-
})
|
|
720
|
-
: ts.factory.createCallExpression(
|
|
721
|
-
ts.factory.createIdentifier(
|
|
722
|
-
props.functor.useLocal(`${PREFIX}u${props.metadata.union_index!}`),
|
|
723
|
-
),
|
|
724
|
-
undefined,
|
|
725
|
-
FeatureProgrammer.argumentsArray(props),
|
|
726
|
-
);
|
|
727
|
-
|
|
728
|
-
const explore_arrays = (props: {
|
|
729
|
-
context: ITypiaContext;
|
|
730
|
-
config: FeatureProgrammer.IConfig;
|
|
731
|
-
functor: FunctionProgrammer;
|
|
732
|
-
input: ts.Expression;
|
|
733
|
-
arrays: MetadataArray[];
|
|
734
|
-
explore: FeatureProgrammer.IExplore;
|
|
735
|
-
}): ts.Expression =>
|
|
736
|
-
explore_array_like_union_types({
|
|
737
|
-
...props,
|
|
738
|
-
definitions: props.arrays,
|
|
739
|
-
factory: (next) =>
|
|
740
|
-
UnionExplorer.array({
|
|
741
|
-
config: {
|
|
742
|
-
checker: (v) =>
|
|
743
|
-
IsProgrammer.decode({
|
|
744
|
-
context: props.context,
|
|
745
|
-
functor: props.functor,
|
|
746
|
-
input: v.input,
|
|
747
|
-
metadata: v.definition,
|
|
748
|
-
explore: v.explore,
|
|
749
|
-
}),
|
|
750
|
-
decoder: (v) =>
|
|
751
|
-
decode_array({
|
|
752
|
-
config: props.config,
|
|
753
|
-
functor: props.functor,
|
|
754
|
-
input: v.input,
|
|
755
|
-
array: v.definition,
|
|
756
|
-
explore: v.explore,
|
|
757
|
-
}),
|
|
758
|
-
empty: ts.factory.createIdentifier("[]"),
|
|
759
|
-
success: ts.factory.createTrue(),
|
|
760
|
-
failure: (v) =>
|
|
761
|
-
create_throw_error({
|
|
762
|
-
context: props.context,
|
|
763
|
-
functor: props.functor,
|
|
764
|
-
expected: v.expected,
|
|
765
|
-
input: v.input,
|
|
766
|
-
}),
|
|
767
|
-
},
|
|
768
|
-
parameters: next.parameters,
|
|
769
|
-
arrays: next.definitions,
|
|
770
|
-
input: next.input,
|
|
771
|
-
explore: next.explore,
|
|
772
|
-
}),
|
|
773
|
-
});
|
|
774
|
-
|
|
775
|
-
const explore_array_like_union_types = <
|
|
776
|
-
T extends MetadataArray | MetadataTuple,
|
|
777
|
-
>(props: {
|
|
778
|
-
config: FeatureProgrammer.IConfig;
|
|
779
|
-
functor: FunctionProgrammer;
|
|
780
|
-
factory: (next: {
|
|
781
|
-
parameters: ts.ParameterDeclaration[];
|
|
782
|
-
input: ts.Expression;
|
|
783
|
-
definitions: T[];
|
|
784
|
-
explore: FeatureProgrammer.IExplore;
|
|
785
|
-
}) => ts.ArrowFunction;
|
|
786
|
-
input: ts.Expression;
|
|
787
|
-
definitions: T[];
|
|
788
|
-
explore: FeatureProgrammer.IExplore;
|
|
789
|
-
}): ts.Expression => {
|
|
790
|
-
const arrow = (next: {
|
|
791
|
-
parameters: ts.ParameterDeclaration[];
|
|
792
|
-
explore: FeatureProgrammer.IExplore;
|
|
793
|
-
input: ts.Expression;
|
|
794
|
-
}): ts.ArrowFunction =>
|
|
795
|
-
props.factory({
|
|
796
|
-
definitions: props.definitions,
|
|
797
|
-
parameters: next.parameters,
|
|
798
|
-
input: next.input,
|
|
799
|
-
explore: next.explore,
|
|
800
|
-
});
|
|
801
|
-
if (props.definitions.every((e) => e.type.recursive === false))
|
|
802
|
-
ts.factory.createCallExpression(
|
|
803
|
-
arrow({
|
|
804
|
-
parameters: [],
|
|
805
|
-
explore: props.explore,
|
|
806
|
-
input: props.input,
|
|
807
|
-
}),
|
|
808
|
-
undefined,
|
|
809
|
-
[],
|
|
810
|
-
);
|
|
811
|
-
|
|
812
|
-
const arrayExplore: FeatureProgrammer.IExplore = {
|
|
813
|
-
...props.explore,
|
|
814
|
-
source: "function",
|
|
815
|
-
from: "array",
|
|
816
|
-
};
|
|
817
|
-
return ts.factory.createCallExpression(
|
|
818
|
-
ts.factory.createIdentifier(
|
|
819
|
-
props.functor.emplaceUnion(
|
|
820
|
-
props.config.prefix,
|
|
821
|
-
props.definitions.map((e) => e.type.name).join(" | "),
|
|
822
|
-
() =>
|
|
823
|
-
arrow({
|
|
824
|
-
parameters: FeatureProgrammer.parameterDeclarations({
|
|
825
|
-
config: props.config,
|
|
826
|
-
type: TypeFactory.keyword("any"),
|
|
827
|
-
input: ts.factory.createIdentifier("input"),
|
|
828
|
-
}),
|
|
829
|
-
explore: {
|
|
830
|
-
...arrayExplore,
|
|
831
|
-
postfix: "",
|
|
832
|
-
},
|
|
833
|
-
input: ts.factory.createIdentifier("input"),
|
|
834
|
-
}),
|
|
835
|
-
),
|
|
836
|
-
),
|
|
837
|
-
undefined,
|
|
838
|
-
FeatureProgrammer.argumentsArray({
|
|
839
|
-
config: props.config,
|
|
840
|
-
input: props.input,
|
|
841
|
-
explore: arrayExplore,
|
|
842
|
-
}),
|
|
843
|
-
);
|
|
844
|
-
};
|
|
845
|
-
|
|
846
|
-
/* -----------------------------------------------------------
|
|
847
|
-
CONFIGURATIONS
|
|
848
|
-
----------------------------------------------------------- */
|
|
849
|
-
const PREFIX = "_c";
|
|
850
|
-
|
|
851
|
-
const configure = (props: {
|
|
852
|
-
context: ITypiaContext;
|
|
853
|
-
functor: FunctionProgrammer;
|
|
854
|
-
}): FeatureProgrammer.IConfig => {
|
|
855
|
-
const config: FeatureProgrammer.IConfig = {
|
|
856
|
-
types: {
|
|
857
|
-
input: (type, name) =>
|
|
858
|
-
ts.factory.createTypeReferenceNode(
|
|
859
|
-
name ??
|
|
860
|
-
TypeFactory.getFullName({ checker: props.context.checker, type }),
|
|
861
|
-
),
|
|
862
|
-
output: (type, name) =>
|
|
863
|
-
props.context.importer.type({
|
|
864
|
-
file: "typia",
|
|
865
|
-
name: "Resolved",
|
|
866
|
-
arguments: [
|
|
867
|
-
ts.factory.createTypeReferenceNode(
|
|
868
|
-
name ??
|
|
869
|
-
TypeFactory.getFullName({
|
|
870
|
-
checker: props.context.checker,
|
|
871
|
-
type,
|
|
872
|
-
}),
|
|
873
|
-
),
|
|
874
|
-
],
|
|
875
|
-
}),
|
|
876
|
-
},
|
|
877
|
-
prefix: PREFIX,
|
|
878
|
-
trace: false,
|
|
879
|
-
path: false,
|
|
880
|
-
initializer,
|
|
881
|
-
decoder: (next) =>
|
|
882
|
-
decode({
|
|
883
|
-
context: props.context,
|
|
884
|
-
functor: props.functor,
|
|
885
|
-
config,
|
|
886
|
-
input: next.input,
|
|
887
|
-
metadata: next.metadata,
|
|
888
|
-
explore: next.explore,
|
|
889
|
-
}),
|
|
890
|
-
objector: {
|
|
891
|
-
checker: (next) =>
|
|
892
|
-
IsProgrammer.decode({
|
|
893
|
-
context: props.context,
|
|
894
|
-
functor: props.functor,
|
|
895
|
-
input: next.input,
|
|
896
|
-
metadata: next.metadata,
|
|
897
|
-
explore: next.explore,
|
|
898
|
-
}),
|
|
899
|
-
decoder: (next) =>
|
|
900
|
-
decode_object({
|
|
901
|
-
functor: props.functor,
|
|
902
|
-
input: next.input,
|
|
903
|
-
object: next.object,
|
|
904
|
-
explore: next.explore,
|
|
905
|
-
}),
|
|
906
|
-
joiner: CloneJoiner.object,
|
|
907
|
-
unionizer: (next) =>
|
|
908
|
-
decode_union_object({
|
|
909
|
-
checker: (v) =>
|
|
910
|
-
IsProgrammer.decode_object({
|
|
911
|
-
context: props.context,
|
|
912
|
-
functor: props.functor,
|
|
913
|
-
input: v.input,
|
|
914
|
-
object: v.object,
|
|
915
|
-
explore: v.explore,
|
|
916
|
-
}),
|
|
917
|
-
decoder: (v) =>
|
|
918
|
-
decode_object({
|
|
919
|
-
functor: props.functor,
|
|
920
|
-
input: v.input,
|
|
921
|
-
object: v.object,
|
|
922
|
-
explore: v.explore,
|
|
923
|
-
}),
|
|
924
|
-
success: (exp) => exp,
|
|
925
|
-
escaper: (v) =>
|
|
926
|
-
create_throw_error({
|
|
927
|
-
context: props.context,
|
|
928
|
-
functor: props.functor,
|
|
929
|
-
expected: v.expected,
|
|
930
|
-
input: v.input,
|
|
931
|
-
}),
|
|
932
|
-
input: next.input,
|
|
933
|
-
objects: next.objects,
|
|
934
|
-
explore: next.explore,
|
|
935
|
-
}),
|
|
936
|
-
failure: (next) =>
|
|
937
|
-
create_throw_error({
|
|
938
|
-
context: props.context,
|
|
939
|
-
functor: props.functor,
|
|
940
|
-
expected: next.expected,
|
|
941
|
-
input: next.input,
|
|
942
|
-
}),
|
|
943
|
-
},
|
|
944
|
-
generator: {
|
|
945
|
-
arrays: (collection) =>
|
|
946
|
-
write_array_functions({
|
|
947
|
-
functor: props.functor,
|
|
948
|
-
config,
|
|
949
|
-
collection,
|
|
950
|
-
}),
|
|
951
|
-
tuples: (collection) =>
|
|
952
|
-
write_tuple_functions({
|
|
953
|
-
context: props.context,
|
|
954
|
-
functor: props.functor,
|
|
955
|
-
config,
|
|
956
|
-
collection,
|
|
957
|
-
}),
|
|
958
|
-
},
|
|
959
|
-
};
|
|
960
|
-
return config;
|
|
961
|
-
};
|
|
962
|
-
|
|
963
|
-
const initializer: FeatureProgrammer.IConfig["initializer"] = (props) => {
|
|
964
|
-
const collection = new MetadataCollection();
|
|
965
|
-
const result = MetadataFactory.analyze({
|
|
966
|
-
checker: props.context.checker,
|
|
967
|
-
transformer: props.context.transformer,
|
|
968
|
-
options: {
|
|
969
|
-
escape: false,
|
|
970
|
-
constant: true,
|
|
971
|
-
absorb: true,
|
|
972
|
-
validate: (metadata) => {
|
|
973
|
-
const output: string[] = [];
|
|
974
|
-
if (metadata.natives.some((native) => native.name === "WeakSet"))
|
|
975
|
-
output.push("unable to clone WeakSet");
|
|
976
|
-
else if (metadata.natives.some((native) => native.name === "WeakMap"))
|
|
977
|
-
output.push("unable to clone WeakMap");
|
|
978
|
-
return output;
|
|
979
|
-
},
|
|
980
|
-
},
|
|
981
|
-
collection,
|
|
982
|
-
type: props.type,
|
|
983
|
-
});
|
|
984
|
-
if (result.success === false)
|
|
985
|
-
throw TransformerError.from({
|
|
986
|
-
code: props.functor.method,
|
|
987
|
-
errors: result.errors,
|
|
988
|
-
});
|
|
989
|
-
return {
|
|
990
|
-
collection,
|
|
991
|
-
metadata: result.data,
|
|
992
|
-
};
|
|
993
|
-
};
|
|
994
|
-
|
|
995
|
-
const create_throw_error = (props: {
|
|
996
|
-
context: ITypiaContext;
|
|
997
|
-
functor: FunctionProgrammer;
|
|
998
|
-
expected: string;
|
|
999
|
-
input: ts.Expression;
|
|
1000
|
-
}) =>
|
|
1001
|
-
ts.factory.createExpressionStatement(
|
|
1002
|
-
ts.factory.createCallExpression(
|
|
1003
|
-
props.context.importer.internal("throwTypeGuardError"),
|
|
1004
|
-
[],
|
|
1005
|
-
[
|
|
1006
|
-
ts.factory.createObjectLiteralExpression(
|
|
1007
|
-
[
|
|
1008
|
-
ts.factory.createPropertyAssignment(
|
|
1009
|
-
"method",
|
|
1010
|
-
ts.factory.createStringLiteral(props.functor.method),
|
|
1011
|
-
),
|
|
1012
|
-
ts.factory.createPropertyAssignment(
|
|
1013
|
-
"expected",
|
|
1014
|
-
ts.factory.createStringLiteral(props.expected),
|
|
1015
|
-
),
|
|
1016
|
-
ts.factory.createPropertyAssignment("value", props.input),
|
|
1017
|
-
],
|
|
1018
|
-
true,
|
|
1019
|
-
),
|
|
1020
|
-
],
|
|
1021
|
-
),
|
|
1022
|
-
);
|
|
1023
|
-
|
|
1024
|
-
const is_instance = (metadata: Metadata): boolean =>
|
|
1025
|
-
!!metadata.objects.length ||
|
|
1026
|
-
!!metadata.arrays.length ||
|
|
1027
|
-
!!metadata.tuples.length ||
|
|
1028
|
-
!!metadata.sets.length ||
|
|
1029
|
-
!!metadata.maps.length ||
|
|
1030
|
-
!!metadata.natives.length ||
|
|
1031
|
-
(metadata.rest !== null && is_instance(metadata.rest));
|
|
1032
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { ExpressionFactory } from "../../factories/ExpressionFactory";
|
|
4
|
+
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
5
|
+
import { MetadataCollection } from "../../factories/MetadataCollection";
|
|
6
|
+
import { MetadataFactory } from "../../factories/MetadataFactory";
|
|
7
|
+
import { StatementFactory } from "../../factories/StatementFactory";
|
|
8
|
+
import { TypeFactory } from "../../factories/TypeFactory";
|
|
9
|
+
|
|
10
|
+
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
11
|
+
import { MetadataArray } from "../../schemas/metadata/MetadataArray";
|
|
12
|
+
import { MetadataMap } from "../../schemas/metadata/MetadataMap";
|
|
13
|
+
import { MetadataObjectType } from "../../schemas/metadata/MetadataObjectType";
|
|
14
|
+
import { MetadataSet } from "../../schemas/metadata/MetadataSet";
|
|
15
|
+
import { MetadataTuple } from "../../schemas/metadata/MetadataTuple";
|
|
16
|
+
import { MetadataTupleType } from "../../schemas/metadata/MetadataTupleType";
|
|
17
|
+
|
|
18
|
+
import { IProgrammerProps } from "../../transformers/IProgrammerProps";
|
|
19
|
+
import { ITypiaContext } from "../../transformers/ITypiaContext";
|
|
20
|
+
import { TransformerError } from "../../transformers/TransformerError";
|
|
21
|
+
|
|
22
|
+
import { FeatureProgrammer } from "../FeatureProgrammer";
|
|
23
|
+
import { IsProgrammer } from "../IsProgrammer";
|
|
24
|
+
import { CloneJoiner } from "../helpers/CloneJoiner";
|
|
25
|
+
import { FunctionProgrammer } from "../helpers/FunctionProgrammer";
|
|
26
|
+
import { UnionExplorer } from "../helpers/UnionExplorer";
|
|
27
|
+
import { decode_union_object } from "../internal/decode_union_object";
|
|
28
|
+
import { postfix_of_tuple } from "../internal/postfix_of_tuple";
|
|
29
|
+
import { wrap_metadata_rest_tuple } from "../internal/wrap_metadata_rest_tuple";
|
|
30
|
+
|
|
31
|
+
export namespace MiscCloneProgrammer {
|
|
32
|
+
export const decompose = (props: {
|
|
33
|
+
validated: boolean;
|
|
34
|
+
context: ITypiaContext;
|
|
35
|
+
functor: FunctionProgrammer;
|
|
36
|
+
type: ts.Type;
|
|
37
|
+
name: string | undefined;
|
|
38
|
+
}): FeatureProgrammer.IDecomposed => {
|
|
39
|
+
const config: FeatureProgrammer.IConfig = configure(props);
|
|
40
|
+
if (props.validated === false)
|
|
41
|
+
config.addition = (collection) =>
|
|
42
|
+
IsProgrammer.write_function_statements({
|
|
43
|
+
context: props.context,
|
|
44
|
+
functor: props.functor,
|
|
45
|
+
collection,
|
|
46
|
+
});
|
|
47
|
+
const composed: FeatureProgrammer.IComposed = FeatureProgrammer.compose({
|
|
48
|
+
...props,
|
|
49
|
+
config,
|
|
50
|
+
});
|
|
51
|
+
return {
|
|
52
|
+
functions: composed.functions,
|
|
53
|
+
statements: composed.statements,
|
|
54
|
+
arrow: ts.factory.createArrowFunction(
|
|
55
|
+
undefined,
|
|
56
|
+
undefined,
|
|
57
|
+
composed.parameters,
|
|
58
|
+
composed.response,
|
|
59
|
+
undefined,
|
|
60
|
+
composed.body,
|
|
61
|
+
),
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export const write = (props: IProgrammerProps): ts.CallExpression => {
|
|
66
|
+
const functor: FunctionProgrammer = new FunctionProgrammer(
|
|
67
|
+
props.modulo.getText(),
|
|
68
|
+
);
|
|
69
|
+
const result: FeatureProgrammer.IDecomposed = decompose({
|
|
70
|
+
...props,
|
|
71
|
+
validated: false,
|
|
72
|
+
functor,
|
|
73
|
+
});
|
|
74
|
+
return FeatureProgrammer.writeDecomposed({
|
|
75
|
+
modulo: props.modulo,
|
|
76
|
+
functor,
|
|
77
|
+
result,
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const write_array_functions = (props: {
|
|
82
|
+
config: FeatureProgrammer.IConfig;
|
|
83
|
+
functor: FunctionProgrammer;
|
|
84
|
+
collection: MetadataCollection;
|
|
85
|
+
}): ts.VariableStatement[] =>
|
|
86
|
+
props.collection
|
|
87
|
+
.arrays()
|
|
88
|
+
.filter((a) => a.recursive)
|
|
89
|
+
.map((type, i) =>
|
|
90
|
+
StatementFactory.constant({
|
|
91
|
+
name: `${props.config.prefix}a${i}`,
|
|
92
|
+
value: ts.factory.createArrowFunction(
|
|
93
|
+
undefined,
|
|
94
|
+
undefined,
|
|
95
|
+
FeatureProgrammer.parameterDeclarations({
|
|
96
|
+
config: props.config,
|
|
97
|
+
type: TypeFactory.keyword("any"),
|
|
98
|
+
input: ts.factory.createIdentifier("input"),
|
|
99
|
+
}),
|
|
100
|
+
TypeFactory.keyword("any"),
|
|
101
|
+
undefined,
|
|
102
|
+
decode_array_inline({
|
|
103
|
+
config: props.config,
|
|
104
|
+
functor: props.functor,
|
|
105
|
+
input: ts.factory.createIdentifier("input"),
|
|
106
|
+
array: MetadataArray.create({
|
|
107
|
+
type,
|
|
108
|
+
tags: [],
|
|
109
|
+
}),
|
|
110
|
+
explore: {
|
|
111
|
+
tracable: props.config.trace,
|
|
112
|
+
source: "function",
|
|
113
|
+
from: "array",
|
|
114
|
+
postfix: "",
|
|
115
|
+
},
|
|
116
|
+
}),
|
|
117
|
+
),
|
|
118
|
+
}),
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
const write_tuple_functions = (props: {
|
|
122
|
+
context: ITypiaContext;
|
|
123
|
+
config: FeatureProgrammer.IConfig;
|
|
124
|
+
functor: FunctionProgrammer;
|
|
125
|
+
collection: MetadataCollection;
|
|
126
|
+
}): ts.VariableStatement[] =>
|
|
127
|
+
props.collection
|
|
128
|
+
.tuples()
|
|
129
|
+
.filter((t) => t.recursive)
|
|
130
|
+
.map((tuple, i) =>
|
|
131
|
+
StatementFactory.constant({
|
|
132
|
+
name: `${props.config.prefix}t${i}`,
|
|
133
|
+
value: ts.factory.createArrowFunction(
|
|
134
|
+
undefined,
|
|
135
|
+
undefined,
|
|
136
|
+
FeatureProgrammer.parameterDeclarations({
|
|
137
|
+
config: props.config,
|
|
138
|
+
type: TypeFactory.keyword("any"),
|
|
139
|
+
input: ts.factory.createIdentifier("input"),
|
|
140
|
+
}),
|
|
141
|
+
TypeFactory.keyword("any"),
|
|
142
|
+
undefined,
|
|
143
|
+
decode_tuple_inline({
|
|
144
|
+
config: props.config,
|
|
145
|
+
context: props.context,
|
|
146
|
+
functor: props.functor,
|
|
147
|
+
input: ts.factory.createIdentifier("input"),
|
|
148
|
+
tuple,
|
|
149
|
+
explore: {
|
|
150
|
+
tracable: props.config.trace,
|
|
151
|
+
source: "function",
|
|
152
|
+
from: "array",
|
|
153
|
+
postfix: "",
|
|
154
|
+
},
|
|
155
|
+
}),
|
|
156
|
+
),
|
|
157
|
+
}),
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
/* -----------------------------------------------------------
|
|
161
|
+
DECODERS
|
|
162
|
+
----------------------------------------------------------- */
|
|
163
|
+
const decode = (props: {
|
|
164
|
+
context: ITypiaContext;
|
|
165
|
+
config: FeatureProgrammer.IConfig;
|
|
166
|
+
functor: FunctionProgrammer;
|
|
167
|
+
input: ts.Expression;
|
|
168
|
+
metadata: Metadata;
|
|
169
|
+
explore: FeatureProgrammer.IExplore;
|
|
170
|
+
}): ts.Expression => {
|
|
171
|
+
// ANY TYPE
|
|
172
|
+
if (
|
|
173
|
+
props.metadata.any ||
|
|
174
|
+
props.metadata.arrays.some((a) => a.type.value.any) ||
|
|
175
|
+
props.metadata.tuples.some(
|
|
176
|
+
(t) => !!t.type.elements.length && t.type.elements.every((e) => e.any),
|
|
177
|
+
)
|
|
178
|
+
)
|
|
179
|
+
return ts.factory.createCallExpression(
|
|
180
|
+
props.context.importer.internal("miscCloneAny"),
|
|
181
|
+
undefined,
|
|
182
|
+
[props.input],
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
interface IUnion {
|
|
186
|
+
type: string;
|
|
187
|
+
is: () => ts.Expression;
|
|
188
|
+
value: () => ts.Expression;
|
|
189
|
+
}
|
|
190
|
+
const unions: IUnion[] = [];
|
|
191
|
+
|
|
192
|
+
//----
|
|
193
|
+
// LIST UP UNION TYPES
|
|
194
|
+
//----
|
|
195
|
+
// FUNCTIONAL
|
|
196
|
+
if (props.metadata.functions.length)
|
|
197
|
+
unions.push({
|
|
198
|
+
type: "functional",
|
|
199
|
+
is: () =>
|
|
200
|
+
ts.factory.createStrictEquality(
|
|
201
|
+
ts.factory.createStringLiteral("function"),
|
|
202
|
+
ts.factory.createTypeOfExpression(props.input),
|
|
203
|
+
),
|
|
204
|
+
value: () => ts.factory.createIdentifier("undefined"),
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
// TUPLES
|
|
208
|
+
for (const tuple of props.metadata.tuples)
|
|
209
|
+
unions.push({
|
|
210
|
+
type: "tuple",
|
|
211
|
+
is: () =>
|
|
212
|
+
IsProgrammer.decode({
|
|
213
|
+
...props,
|
|
214
|
+
metadata: (() => {
|
|
215
|
+
const partial = Metadata.initialize();
|
|
216
|
+
partial.tuples.push(tuple);
|
|
217
|
+
return partial;
|
|
218
|
+
})(),
|
|
219
|
+
}),
|
|
220
|
+
value: () =>
|
|
221
|
+
decode_tuple({
|
|
222
|
+
...props,
|
|
223
|
+
tuple,
|
|
224
|
+
}),
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
// ARRAYS
|
|
228
|
+
if (props.metadata.arrays.length)
|
|
229
|
+
unions.push({
|
|
230
|
+
type: "array",
|
|
231
|
+
is: () => ExpressionFactory.isArray(props.input),
|
|
232
|
+
value: () =>
|
|
233
|
+
explore_arrays({
|
|
234
|
+
...props,
|
|
235
|
+
arrays: props.metadata.arrays,
|
|
236
|
+
explore: {
|
|
237
|
+
...props.explore,
|
|
238
|
+
from: "array",
|
|
239
|
+
},
|
|
240
|
+
}),
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
// NATIVE TYPES
|
|
244
|
+
if (props.metadata.sets.length)
|
|
245
|
+
unions.push({
|
|
246
|
+
type: "set",
|
|
247
|
+
is: () => ExpressionFactory.isInstanceOf("Set", props.input),
|
|
248
|
+
value: () =>
|
|
249
|
+
explore_sets({
|
|
250
|
+
...props,
|
|
251
|
+
sets: props.metadata.sets,
|
|
252
|
+
explore: {
|
|
253
|
+
...props.explore,
|
|
254
|
+
from: "array",
|
|
255
|
+
},
|
|
256
|
+
}),
|
|
257
|
+
});
|
|
258
|
+
if (props.metadata.maps.length)
|
|
259
|
+
unions.push({
|
|
260
|
+
type: "map",
|
|
261
|
+
is: () => ExpressionFactory.isInstanceOf("Map", props.input),
|
|
262
|
+
value: () =>
|
|
263
|
+
explore_maps({
|
|
264
|
+
...props,
|
|
265
|
+
maps: props.metadata.maps,
|
|
266
|
+
explore: {
|
|
267
|
+
...props.explore,
|
|
268
|
+
from: "array",
|
|
269
|
+
},
|
|
270
|
+
}),
|
|
271
|
+
});
|
|
272
|
+
for (const native of props.metadata.natives)
|
|
273
|
+
unions.push({
|
|
274
|
+
type: "native",
|
|
275
|
+
is: () => ExpressionFactory.isInstanceOf(native.name, props.input),
|
|
276
|
+
value: () =>
|
|
277
|
+
native.name === "Boolean" ||
|
|
278
|
+
native.name === "Number" ||
|
|
279
|
+
native.name === "String"
|
|
280
|
+
? ts.factory.createCallExpression(
|
|
281
|
+
IdentifierFactory.access(props.input, "valueOf"),
|
|
282
|
+
undefined,
|
|
283
|
+
undefined,
|
|
284
|
+
)
|
|
285
|
+
: decode_native({
|
|
286
|
+
type: native.name,
|
|
287
|
+
input: props.input,
|
|
288
|
+
}),
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
// OBJECTS
|
|
292
|
+
if (props.metadata.objects.length)
|
|
293
|
+
unions.push({
|
|
294
|
+
type: "object",
|
|
295
|
+
is: () =>
|
|
296
|
+
ExpressionFactory.isObject({
|
|
297
|
+
checkNull: true,
|
|
298
|
+
checkArray: false,
|
|
299
|
+
input: props.input,
|
|
300
|
+
}),
|
|
301
|
+
value: () =>
|
|
302
|
+
explore_objects({
|
|
303
|
+
...props,
|
|
304
|
+
explore: {
|
|
305
|
+
...props.explore,
|
|
306
|
+
from: "object",
|
|
307
|
+
},
|
|
308
|
+
}),
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
// COMPOSITION
|
|
312
|
+
if (unions.length === 0) return props.input;
|
|
313
|
+
else if (unions.length === 1 && props.metadata.size() === 1) {
|
|
314
|
+
const value: ts.Expression =
|
|
315
|
+
(props.metadata.nullable || props.metadata.isRequired() === false) &&
|
|
316
|
+
is_instance(props.metadata)
|
|
317
|
+
? ts.factory.createConditionalExpression(
|
|
318
|
+
props.input,
|
|
319
|
+
undefined,
|
|
320
|
+
unions[0]!.value(),
|
|
321
|
+
undefined,
|
|
322
|
+
props.input,
|
|
323
|
+
)
|
|
324
|
+
: unions[0]!.value();
|
|
325
|
+
return ts.factory.createAsExpression(value, TypeFactory.keyword("any"));
|
|
326
|
+
} else {
|
|
327
|
+
let last: ts.Expression = props.input;
|
|
328
|
+
for (const u of unions.reverse())
|
|
329
|
+
last = ts.factory.createConditionalExpression(
|
|
330
|
+
u.is(),
|
|
331
|
+
undefined,
|
|
332
|
+
u.value(),
|
|
333
|
+
undefined,
|
|
334
|
+
last,
|
|
335
|
+
);
|
|
336
|
+
return ts.factory.createAsExpression(last, TypeFactory.keyword("any"));
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
const decode_object = (props: {
|
|
341
|
+
functor: FunctionProgrammer;
|
|
342
|
+
input: ts.Expression;
|
|
343
|
+
object: MetadataObjectType;
|
|
344
|
+
explore: FeatureProgrammer.IExplore;
|
|
345
|
+
}) =>
|
|
346
|
+
FeatureProgrammer.decode_object({
|
|
347
|
+
config: {
|
|
348
|
+
trace: false,
|
|
349
|
+
path: false,
|
|
350
|
+
prefix: PREFIX,
|
|
351
|
+
},
|
|
352
|
+
functor: props.functor,
|
|
353
|
+
input: props.input,
|
|
354
|
+
object: props.object,
|
|
355
|
+
explore: props.explore,
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
const decode_array = (props: {
|
|
359
|
+
config: FeatureProgrammer.IConfig;
|
|
360
|
+
functor: FunctionProgrammer;
|
|
361
|
+
input: ts.Expression;
|
|
362
|
+
array: MetadataArray;
|
|
363
|
+
explore: FeatureProgrammer.IExplore;
|
|
364
|
+
}) =>
|
|
365
|
+
props.array.type.recursive
|
|
366
|
+
? ts.factory.createCallExpression(
|
|
367
|
+
ts.factory.createIdentifier(
|
|
368
|
+
props.functor.useLocal(
|
|
369
|
+
`${props.config.prefix}a${props.array.type.index}`,
|
|
370
|
+
),
|
|
371
|
+
),
|
|
372
|
+
undefined,
|
|
373
|
+
FeatureProgrammer.argumentsArray({
|
|
374
|
+
config: props.config,
|
|
375
|
+
explore: {
|
|
376
|
+
...props.explore,
|
|
377
|
+
source: "function",
|
|
378
|
+
from: "array",
|
|
379
|
+
},
|
|
380
|
+
input: props.input,
|
|
381
|
+
}),
|
|
382
|
+
)
|
|
383
|
+
: decode_array_inline(props);
|
|
384
|
+
|
|
385
|
+
const decode_array_inline = (props: {
|
|
386
|
+
config: FeatureProgrammer.IConfig;
|
|
387
|
+
functor: FunctionProgrammer;
|
|
388
|
+
input: ts.Expression;
|
|
389
|
+
array: MetadataArray;
|
|
390
|
+
explore: FeatureProgrammer.IExplore;
|
|
391
|
+
}) =>
|
|
392
|
+
FeatureProgrammer.decode_array({
|
|
393
|
+
config: props.config,
|
|
394
|
+
functor: props.functor,
|
|
395
|
+
combiner: CloneJoiner.array,
|
|
396
|
+
array: props.array,
|
|
397
|
+
input: props.input,
|
|
398
|
+
explore: props.explore,
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
const decode_tuple = (props: {
|
|
402
|
+
context: ITypiaContext;
|
|
403
|
+
config: FeatureProgrammer.IConfig;
|
|
404
|
+
functor: FunctionProgrammer;
|
|
405
|
+
input: ts.Expression;
|
|
406
|
+
tuple: MetadataTuple;
|
|
407
|
+
explore: FeatureProgrammer.IExplore;
|
|
408
|
+
}): ts.Expression =>
|
|
409
|
+
props.tuple.type.recursive
|
|
410
|
+
? ts.factory.createCallExpression(
|
|
411
|
+
ts.factory.createIdentifier(
|
|
412
|
+
props.functor.useLocal(
|
|
413
|
+
`${props.config.prefix}t${props.tuple.type.index}`,
|
|
414
|
+
),
|
|
415
|
+
),
|
|
416
|
+
undefined,
|
|
417
|
+
FeatureProgrammer.argumentsArray({
|
|
418
|
+
config: props.config,
|
|
419
|
+
explore: {
|
|
420
|
+
...props.explore,
|
|
421
|
+
source: "function",
|
|
422
|
+
},
|
|
423
|
+
input: props.input,
|
|
424
|
+
}),
|
|
425
|
+
)
|
|
426
|
+
: decode_tuple_inline({
|
|
427
|
+
...props,
|
|
428
|
+
tuple: props.tuple.type,
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
const decode_tuple_inline = (props: {
|
|
432
|
+
context: ITypiaContext;
|
|
433
|
+
config: FeatureProgrammer.IConfig;
|
|
434
|
+
functor: FunctionProgrammer;
|
|
435
|
+
input: ts.Expression;
|
|
436
|
+
tuple: MetadataTupleType;
|
|
437
|
+
explore: FeatureProgrammer.IExplore;
|
|
438
|
+
}): ts.Expression => {
|
|
439
|
+
const elements: ts.Expression[] = props.tuple.elements
|
|
440
|
+
.filter((m) => m.rest === null)
|
|
441
|
+
.map((elem, index) =>
|
|
442
|
+
decode({
|
|
443
|
+
context: props.context,
|
|
444
|
+
config: props.config,
|
|
445
|
+
functor: props.functor,
|
|
446
|
+
input: ts.factory.createElementAccessExpression(props.input, index),
|
|
447
|
+
metadata: elem,
|
|
448
|
+
explore: {
|
|
449
|
+
...props.explore,
|
|
450
|
+
from: "array",
|
|
451
|
+
postfix: props.explore.postfix.length
|
|
452
|
+
? `${postfix_of_tuple(props.explore.postfix)}[${index}]"`
|
|
453
|
+
: `"[${index}]"`,
|
|
454
|
+
},
|
|
455
|
+
}),
|
|
456
|
+
);
|
|
457
|
+
const rest = (() => {
|
|
458
|
+
if (props.tuple.elements.length === 0) return null;
|
|
459
|
+
|
|
460
|
+
const last: Metadata = props.tuple.elements.at(-1)!;
|
|
461
|
+
const rest: Metadata | null = last.rest;
|
|
462
|
+
if (rest === null) return null;
|
|
463
|
+
|
|
464
|
+
return decode({
|
|
465
|
+
context: props.context,
|
|
466
|
+
config: props.config,
|
|
467
|
+
functor: props.functor,
|
|
468
|
+
input: ts.factory.createCallExpression(
|
|
469
|
+
IdentifierFactory.access(props.input, "slice"),
|
|
470
|
+
undefined,
|
|
471
|
+
[ExpressionFactory.number(props.tuple.elements.length - 1)],
|
|
472
|
+
),
|
|
473
|
+
metadata: wrap_metadata_rest_tuple(props.tuple.elements.at(-1)!.rest!),
|
|
474
|
+
explore: {
|
|
475
|
+
...props.explore,
|
|
476
|
+
start: props.tuple.elements.length - 1,
|
|
477
|
+
},
|
|
478
|
+
});
|
|
479
|
+
})();
|
|
480
|
+
return CloneJoiner.tuple({
|
|
481
|
+
elements,
|
|
482
|
+
rest,
|
|
483
|
+
});
|
|
484
|
+
};
|
|
485
|
+
|
|
486
|
+
/* -----------------------------------------------------------
|
|
487
|
+
NATIVE CLASSES
|
|
488
|
+
----------------------------------------------------------- */
|
|
489
|
+
const decode_native = (props: { type: string; input: ts.Expression }) =>
|
|
490
|
+
props.type === "Date" ||
|
|
491
|
+
props.type === "Uint8Array" ||
|
|
492
|
+
props.type === "Uint8ClampedArray" ||
|
|
493
|
+
props.type === "Uint16Array" ||
|
|
494
|
+
props.type === "Uint32Array" ||
|
|
495
|
+
props.type === "BigUint64Array" ||
|
|
496
|
+
props.type === "Int8Array" ||
|
|
497
|
+
props.type === "Int16Array" ||
|
|
498
|
+
props.type === "Int32Array" ||
|
|
499
|
+
props.type === "BigInt64Array" ||
|
|
500
|
+
props.type === "Float32Array" ||
|
|
501
|
+
props.type === "Float64Array" ||
|
|
502
|
+
props.type === "RegExp"
|
|
503
|
+
? decode_native_copyable(props)
|
|
504
|
+
: props.type === "ArrayBuffer" || props.type === "SharedArrayBuffer"
|
|
505
|
+
? decode_native_buffer({
|
|
506
|
+
type: props.type,
|
|
507
|
+
input: props.input,
|
|
508
|
+
})
|
|
509
|
+
: props.type === "DataView"
|
|
510
|
+
? decode_native_data_view(props.input)
|
|
511
|
+
: ts.factory.createCallExpression(
|
|
512
|
+
ts.factory.createIdentifier(props.type),
|
|
513
|
+
undefined,
|
|
514
|
+
[],
|
|
515
|
+
);
|
|
516
|
+
|
|
517
|
+
const decode_native_copyable = (props: {
|
|
518
|
+
type: string;
|
|
519
|
+
input: ts.Expression;
|
|
520
|
+
}) =>
|
|
521
|
+
ts.factory.createNewExpression(
|
|
522
|
+
ts.factory.createIdentifier(props.type),
|
|
523
|
+
undefined,
|
|
524
|
+
[props.input],
|
|
525
|
+
);
|
|
526
|
+
|
|
527
|
+
const decode_native_buffer = (props: {
|
|
528
|
+
type: "ArrayBuffer" | "SharedArrayBuffer";
|
|
529
|
+
input: ts.Expression;
|
|
530
|
+
}) =>
|
|
531
|
+
ExpressionFactory.selfCall(
|
|
532
|
+
ts.factory.createBlock(
|
|
533
|
+
[
|
|
534
|
+
StatementFactory.constant({
|
|
535
|
+
name: "buffer",
|
|
536
|
+
value: ts.factory.createNewExpression(
|
|
537
|
+
ts.factory.createIdentifier(props.type),
|
|
538
|
+
undefined,
|
|
539
|
+
[IdentifierFactory.access(props.input, "byteLength")],
|
|
540
|
+
),
|
|
541
|
+
}),
|
|
542
|
+
ts.factory.createExpressionStatement(
|
|
543
|
+
ts.factory.createCallExpression(
|
|
544
|
+
IdentifierFactory.access(
|
|
545
|
+
ts.factory.createNewExpression(
|
|
546
|
+
ts.factory.createIdentifier("Uint8Array"),
|
|
547
|
+
undefined,
|
|
548
|
+
[ts.factory.createIdentifier("buffer")],
|
|
549
|
+
),
|
|
550
|
+
"set",
|
|
551
|
+
),
|
|
552
|
+
undefined,
|
|
553
|
+
[
|
|
554
|
+
ts.factory.createNewExpression(
|
|
555
|
+
ts.factory.createIdentifier("Uint8Array"),
|
|
556
|
+
undefined,
|
|
557
|
+
[props.input],
|
|
558
|
+
),
|
|
559
|
+
],
|
|
560
|
+
),
|
|
561
|
+
),
|
|
562
|
+
ts.factory.createReturnStatement(
|
|
563
|
+
ts.factory.createIdentifier("buffer"),
|
|
564
|
+
),
|
|
565
|
+
],
|
|
566
|
+
true,
|
|
567
|
+
),
|
|
568
|
+
);
|
|
569
|
+
|
|
570
|
+
const decode_native_data_view = (input: ts.Expression) =>
|
|
571
|
+
ts.factory.createNewExpression(
|
|
572
|
+
ts.factory.createIdentifier("DataView"),
|
|
573
|
+
undefined,
|
|
574
|
+
[IdentifierFactory.access(input, "buffer")],
|
|
575
|
+
);
|
|
576
|
+
|
|
577
|
+
/* -----------------------------------------------------------
|
|
578
|
+
EXPLORERS FOR UNION TYPES
|
|
579
|
+
----------------------------------------------------------- */
|
|
580
|
+
const explore_sets = (props: {
|
|
581
|
+
context: ITypiaContext;
|
|
582
|
+
config: FeatureProgrammer.IConfig;
|
|
583
|
+
functor: FunctionProgrammer;
|
|
584
|
+
input: ts.Expression;
|
|
585
|
+
sets: MetadataSet[];
|
|
586
|
+
explore: FeatureProgrammer.IExplore;
|
|
587
|
+
}): ts.Expression =>
|
|
588
|
+
ts.factory.createCallExpression(
|
|
589
|
+
UnionExplorer.set({
|
|
590
|
+
config: {
|
|
591
|
+
checker: (v) =>
|
|
592
|
+
IsProgrammer.decode({
|
|
593
|
+
context: props.context,
|
|
594
|
+
functor: props.functor,
|
|
595
|
+
input: v.input,
|
|
596
|
+
metadata: v.definition,
|
|
597
|
+
explore: v.explore,
|
|
598
|
+
}),
|
|
599
|
+
decoder: (v) =>
|
|
600
|
+
ts.factory.createNewExpression(
|
|
601
|
+
ts.factory.createIdentifier("Set"),
|
|
602
|
+
[TypeFactory.keyword("any")],
|
|
603
|
+
[
|
|
604
|
+
decode_array({
|
|
605
|
+
config: props.config,
|
|
606
|
+
functor: props.functor,
|
|
607
|
+
input: v.input,
|
|
608
|
+
array: v.definition,
|
|
609
|
+
explore: v.explore,
|
|
610
|
+
}),
|
|
611
|
+
],
|
|
612
|
+
),
|
|
613
|
+
empty: ts.factory.createNewExpression(
|
|
614
|
+
ts.factory.createIdentifier("Set"),
|
|
615
|
+
[TypeFactory.keyword("any")],
|
|
616
|
+
[],
|
|
617
|
+
),
|
|
618
|
+
success: ts.factory.createTrue(),
|
|
619
|
+
failure: (v) =>
|
|
620
|
+
create_throw_error({
|
|
621
|
+
context: props.context,
|
|
622
|
+
functor: props.functor,
|
|
623
|
+
expected: v.expected,
|
|
624
|
+
input: v.input,
|
|
625
|
+
}),
|
|
626
|
+
},
|
|
627
|
+
parameters: [],
|
|
628
|
+
input: props.input,
|
|
629
|
+
sets: props.sets,
|
|
630
|
+
explore: props.explore,
|
|
631
|
+
}),
|
|
632
|
+
undefined,
|
|
633
|
+
undefined,
|
|
634
|
+
);
|
|
635
|
+
|
|
636
|
+
const explore_maps = (props: {
|
|
637
|
+
context: ITypiaContext;
|
|
638
|
+
config: FeatureProgrammer.IConfig;
|
|
639
|
+
functor: FunctionProgrammer;
|
|
640
|
+
input: ts.Expression;
|
|
641
|
+
maps: MetadataMap[];
|
|
642
|
+
explore: FeatureProgrammer.IExplore;
|
|
643
|
+
}): ts.Expression =>
|
|
644
|
+
ts.factory.createCallExpression(
|
|
645
|
+
UnionExplorer.map({
|
|
646
|
+
config: {
|
|
647
|
+
checker: (v) =>
|
|
648
|
+
ts.factory.createLogicalAnd(
|
|
649
|
+
IsProgrammer.decode({
|
|
650
|
+
context: props.context,
|
|
651
|
+
functor: props.functor,
|
|
652
|
+
input: ts.factory.createElementAccessExpression(v.input, 0),
|
|
653
|
+
metadata: v.definition[0],
|
|
654
|
+
explore: {
|
|
655
|
+
...v.explore,
|
|
656
|
+
postfix: `${v.explore.postfix}[0]`,
|
|
657
|
+
},
|
|
658
|
+
}),
|
|
659
|
+
IsProgrammer.decode({
|
|
660
|
+
context: props.context,
|
|
661
|
+
functor: props.functor,
|
|
662
|
+
input: ts.factory.createElementAccessExpression(v.input, 1),
|
|
663
|
+
metadata: v.definition[1],
|
|
664
|
+
explore: {
|
|
665
|
+
...v.explore,
|
|
666
|
+
postfix: `${v.explore.postfix}[1]`,
|
|
667
|
+
},
|
|
668
|
+
}),
|
|
669
|
+
),
|
|
670
|
+
decoder: (v) =>
|
|
671
|
+
ts.factory.createNewExpression(
|
|
672
|
+
ts.factory.createIdentifier("Map"),
|
|
673
|
+
[TypeFactory.keyword("any"), TypeFactory.keyword("any")],
|
|
674
|
+
[
|
|
675
|
+
decode_array({
|
|
676
|
+
config: props.config,
|
|
677
|
+
functor: props.functor,
|
|
678
|
+
input: v.input,
|
|
679
|
+
array: v.definition,
|
|
680
|
+
explore: v.explore,
|
|
681
|
+
}),
|
|
682
|
+
],
|
|
683
|
+
),
|
|
684
|
+
empty: ts.factory.createNewExpression(
|
|
685
|
+
ts.factory.createIdentifier("Map"),
|
|
686
|
+
[TypeFactory.keyword("any"), TypeFactory.keyword("any")],
|
|
687
|
+
[],
|
|
688
|
+
),
|
|
689
|
+
success: ts.factory.createTrue(),
|
|
690
|
+
failure: (v) =>
|
|
691
|
+
create_throw_error({
|
|
692
|
+
context: props.context,
|
|
693
|
+
functor: props.functor,
|
|
694
|
+
expected: v.expected,
|
|
695
|
+
input: v.input,
|
|
696
|
+
}),
|
|
697
|
+
},
|
|
698
|
+
parameters: [],
|
|
699
|
+
input: props.input,
|
|
700
|
+
maps: props.maps,
|
|
701
|
+
explore: props.explore,
|
|
702
|
+
}),
|
|
703
|
+
// ([])(props.input, props.maps, props.explore),
|
|
704
|
+
undefined,
|
|
705
|
+
undefined,
|
|
706
|
+
);
|
|
707
|
+
|
|
708
|
+
const explore_objects = (props: {
|
|
709
|
+
config: FeatureProgrammer.IConfig;
|
|
710
|
+
functor: FunctionProgrammer;
|
|
711
|
+
input: ts.Expression;
|
|
712
|
+
metadata: Metadata;
|
|
713
|
+
explore: FeatureProgrammer.IExplore;
|
|
714
|
+
}) =>
|
|
715
|
+
props.metadata.objects.length === 1
|
|
716
|
+
? decode_object({
|
|
717
|
+
...props,
|
|
718
|
+
object: props.metadata.objects[0]!.type,
|
|
719
|
+
})
|
|
720
|
+
: ts.factory.createCallExpression(
|
|
721
|
+
ts.factory.createIdentifier(
|
|
722
|
+
props.functor.useLocal(`${PREFIX}u${props.metadata.union_index!}`),
|
|
723
|
+
),
|
|
724
|
+
undefined,
|
|
725
|
+
FeatureProgrammer.argumentsArray(props),
|
|
726
|
+
);
|
|
727
|
+
|
|
728
|
+
const explore_arrays = (props: {
|
|
729
|
+
context: ITypiaContext;
|
|
730
|
+
config: FeatureProgrammer.IConfig;
|
|
731
|
+
functor: FunctionProgrammer;
|
|
732
|
+
input: ts.Expression;
|
|
733
|
+
arrays: MetadataArray[];
|
|
734
|
+
explore: FeatureProgrammer.IExplore;
|
|
735
|
+
}): ts.Expression =>
|
|
736
|
+
explore_array_like_union_types({
|
|
737
|
+
...props,
|
|
738
|
+
definitions: props.arrays,
|
|
739
|
+
factory: (next) =>
|
|
740
|
+
UnionExplorer.array({
|
|
741
|
+
config: {
|
|
742
|
+
checker: (v) =>
|
|
743
|
+
IsProgrammer.decode({
|
|
744
|
+
context: props.context,
|
|
745
|
+
functor: props.functor,
|
|
746
|
+
input: v.input,
|
|
747
|
+
metadata: v.definition,
|
|
748
|
+
explore: v.explore,
|
|
749
|
+
}),
|
|
750
|
+
decoder: (v) =>
|
|
751
|
+
decode_array({
|
|
752
|
+
config: props.config,
|
|
753
|
+
functor: props.functor,
|
|
754
|
+
input: v.input,
|
|
755
|
+
array: v.definition,
|
|
756
|
+
explore: v.explore,
|
|
757
|
+
}),
|
|
758
|
+
empty: ts.factory.createIdentifier("[]"),
|
|
759
|
+
success: ts.factory.createTrue(),
|
|
760
|
+
failure: (v) =>
|
|
761
|
+
create_throw_error({
|
|
762
|
+
context: props.context,
|
|
763
|
+
functor: props.functor,
|
|
764
|
+
expected: v.expected,
|
|
765
|
+
input: v.input,
|
|
766
|
+
}),
|
|
767
|
+
},
|
|
768
|
+
parameters: next.parameters,
|
|
769
|
+
arrays: next.definitions,
|
|
770
|
+
input: next.input,
|
|
771
|
+
explore: next.explore,
|
|
772
|
+
}),
|
|
773
|
+
});
|
|
774
|
+
|
|
775
|
+
const explore_array_like_union_types = <
|
|
776
|
+
T extends MetadataArray | MetadataTuple,
|
|
777
|
+
>(props: {
|
|
778
|
+
config: FeatureProgrammer.IConfig;
|
|
779
|
+
functor: FunctionProgrammer;
|
|
780
|
+
factory: (next: {
|
|
781
|
+
parameters: ts.ParameterDeclaration[];
|
|
782
|
+
input: ts.Expression;
|
|
783
|
+
definitions: T[];
|
|
784
|
+
explore: FeatureProgrammer.IExplore;
|
|
785
|
+
}) => ts.ArrowFunction;
|
|
786
|
+
input: ts.Expression;
|
|
787
|
+
definitions: T[];
|
|
788
|
+
explore: FeatureProgrammer.IExplore;
|
|
789
|
+
}): ts.Expression => {
|
|
790
|
+
const arrow = (next: {
|
|
791
|
+
parameters: ts.ParameterDeclaration[];
|
|
792
|
+
explore: FeatureProgrammer.IExplore;
|
|
793
|
+
input: ts.Expression;
|
|
794
|
+
}): ts.ArrowFunction =>
|
|
795
|
+
props.factory({
|
|
796
|
+
definitions: props.definitions,
|
|
797
|
+
parameters: next.parameters,
|
|
798
|
+
input: next.input,
|
|
799
|
+
explore: next.explore,
|
|
800
|
+
});
|
|
801
|
+
if (props.definitions.every((e) => e.type.recursive === false))
|
|
802
|
+
ts.factory.createCallExpression(
|
|
803
|
+
arrow({
|
|
804
|
+
parameters: [],
|
|
805
|
+
explore: props.explore,
|
|
806
|
+
input: props.input,
|
|
807
|
+
}),
|
|
808
|
+
undefined,
|
|
809
|
+
[],
|
|
810
|
+
);
|
|
811
|
+
|
|
812
|
+
const arrayExplore: FeatureProgrammer.IExplore = {
|
|
813
|
+
...props.explore,
|
|
814
|
+
source: "function",
|
|
815
|
+
from: "array",
|
|
816
|
+
};
|
|
817
|
+
return ts.factory.createCallExpression(
|
|
818
|
+
ts.factory.createIdentifier(
|
|
819
|
+
props.functor.emplaceUnion(
|
|
820
|
+
props.config.prefix,
|
|
821
|
+
props.definitions.map((e) => e.type.name).join(" | "),
|
|
822
|
+
() =>
|
|
823
|
+
arrow({
|
|
824
|
+
parameters: FeatureProgrammer.parameterDeclarations({
|
|
825
|
+
config: props.config,
|
|
826
|
+
type: TypeFactory.keyword("any"),
|
|
827
|
+
input: ts.factory.createIdentifier("input"),
|
|
828
|
+
}),
|
|
829
|
+
explore: {
|
|
830
|
+
...arrayExplore,
|
|
831
|
+
postfix: "",
|
|
832
|
+
},
|
|
833
|
+
input: ts.factory.createIdentifier("input"),
|
|
834
|
+
}),
|
|
835
|
+
),
|
|
836
|
+
),
|
|
837
|
+
undefined,
|
|
838
|
+
FeatureProgrammer.argumentsArray({
|
|
839
|
+
config: props.config,
|
|
840
|
+
input: props.input,
|
|
841
|
+
explore: arrayExplore,
|
|
842
|
+
}),
|
|
843
|
+
);
|
|
844
|
+
};
|
|
845
|
+
|
|
846
|
+
/* -----------------------------------------------------------
|
|
847
|
+
CONFIGURATIONS
|
|
848
|
+
----------------------------------------------------------- */
|
|
849
|
+
const PREFIX = "_c";
|
|
850
|
+
|
|
851
|
+
const configure = (props: {
|
|
852
|
+
context: ITypiaContext;
|
|
853
|
+
functor: FunctionProgrammer;
|
|
854
|
+
}): FeatureProgrammer.IConfig => {
|
|
855
|
+
const config: FeatureProgrammer.IConfig = {
|
|
856
|
+
types: {
|
|
857
|
+
input: (type, name) =>
|
|
858
|
+
ts.factory.createTypeReferenceNode(
|
|
859
|
+
name ??
|
|
860
|
+
TypeFactory.getFullName({ checker: props.context.checker, type }),
|
|
861
|
+
),
|
|
862
|
+
output: (type, name) =>
|
|
863
|
+
props.context.importer.type({
|
|
864
|
+
file: "typia",
|
|
865
|
+
name: "Resolved",
|
|
866
|
+
arguments: [
|
|
867
|
+
ts.factory.createTypeReferenceNode(
|
|
868
|
+
name ??
|
|
869
|
+
TypeFactory.getFullName({
|
|
870
|
+
checker: props.context.checker,
|
|
871
|
+
type,
|
|
872
|
+
}),
|
|
873
|
+
),
|
|
874
|
+
],
|
|
875
|
+
}),
|
|
876
|
+
},
|
|
877
|
+
prefix: PREFIX,
|
|
878
|
+
trace: false,
|
|
879
|
+
path: false,
|
|
880
|
+
initializer,
|
|
881
|
+
decoder: (next) =>
|
|
882
|
+
decode({
|
|
883
|
+
context: props.context,
|
|
884
|
+
functor: props.functor,
|
|
885
|
+
config,
|
|
886
|
+
input: next.input,
|
|
887
|
+
metadata: next.metadata,
|
|
888
|
+
explore: next.explore,
|
|
889
|
+
}),
|
|
890
|
+
objector: {
|
|
891
|
+
checker: (next) =>
|
|
892
|
+
IsProgrammer.decode({
|
|
893
|
+
context: props.context,
|
|
894
|
+
functor: props.functor,
|
|
895
|
+
input: next.input,
|
|
896
|
+
metadata: next.metadata,
|
|
897
|
+
explore: next.explore,
|
|
898
|
+
}),
|
|
899
|
+
decoder: (next) =>
|
|
900
|
+
decode_object({
|
|
901
|
+
functor: props.functor,
|
|
902
|
+
input: next.input,
|
|
903
|
+
object: next.object,
|
|
904
|
+
explore: next.explore,
|
|
905
|
+
}),
|
|
906
|
+
joiner: CloneJoiner.object,
|
|
907
|
+
unionizer: (next) =>
|
|
908
|
+
decode_union_object({
|
|
909
|
+
checker: (v) =>
|
|
910
|
+
IsProgrammer.decode_object({
|
|
911
|
+
context: props.context,
|
|
912
|
+
functor: props.functor,
|
|
913
|
+
input: v.input,
|
|
914
|
+
object: v.object,
|
|
915
|
+
explore: v.explore,
|
|
916
|
+
}),
|
|
917
|
+
decoder: (v) =>
|
|
918
|
+
decode_object({
|
|
919
|
+
functor: props.functor,
|
|
920
|
+
input: v.input,
|
|
921
|
+
object: v.object,
|
|
922
|
+
explore: v.explore,
|
|
923
|
+
}),
|
|
924
|
+
success: (exp) => exp,
|
|
925
|
+
escaper: (v) =>
|
|
926
|
+
create_throw_error({
|
|
927
|
+
context: props.context,
|
|
928
|
+
functor: props.functor,
|
|
929
|
+
expected: v.expected,
|
|
930
|
+
input: v.input,
|
|
931
|
+
}),
|
|
932
|
+
input: next.input,
|
|
933
|
+
objects: next.objects,
|
|
934
|
+
explore: next.explore,
|
|
935
|
+
}),
|
|
936
|
+
failure: (next) =>
|
|
937
|
+
create_throw_error({
|
|
938
|
+
context: props.context,
|
|
939
|
+
functor: props.functor,
|
|
940
|
+
expected: next.expected,
|
|
941
|
+
input: next.input,
|
|
942
|
+
}),
|
|
943
|
+
},
|
|
944
|
+
generator: {
|
|
945
|
+
arrays: (collection) =>
|
|
946
|
+
write_array_functions({
|
|
947
|
+
functor: props.functor,
|
|
948
|
+
config,
|
|
949
|
+
collection,
|
|
950
|
+
}),
|
|
951
|
+
tuples: (collection) =>
|
|
952
|
+
write_tuple_functions({
|
|
953
|
+
context: props.context,
|
|
954
|
+
functor: props.functor,
|
|
955
|
+
config,
|
|
956
|
+
collection,
|
|
957
|
+
}),
|
|
958
|
+
},
|
|
959
|
+
};
|
|
960
|
+
return config;
|
|
961
|
+
};
|
|
962
|
+
|
|
963
|
+
const initializer: FeatureProgrammer.IConfig["initializer"] = (props) => {
|
|
964
|
+
const collection = new MetadataCollection();
|
|
965
|
+
const result = MetadataFactory.analyze({
|
|
966
|
+
checker: props.context.checker,
|
|
967
|
+
transformer: props.context.transformer,
|
|
968
|
+
options: {
|
|
969
|
+
escape: false,
|
|
970
|
+
constant: true,
|
|
971
|
+
absorb: true,
|
|
972
|
+
validate: (metadata) => {
|
|
973
|
+
const output: string[] = [];
|
|
974
|
+
if (metadata.natives.some((native) => native.name === "WeakSet"))
|
|
975
|
+
output.push("unable to clone WeakSet");
|
|
976
|
+
else if (metadata.natives.some((native) => native.name === "WeakMap"))
|
|
977
|
+
output.push("unable to clone WeakMap");
|
|
978
|
+
return output;
|
|
979
|
+
},
|
|
980
|
+
},
|
|
981
|
+
collection,
|
|
982
|
+
type: props.type,
|
|
983
|
+
});
|
|
984
|
+
if (result.success === false)
|
|
985
|
+
throw TransformerError.from({
|
|
986
|
+
code: props.functor.method,
|
|
987
|
+
errors: result.errors,
|
|
988
|
+
});
|
|
989
|
+
return {
|
|
990
|
+
collection,
|
|
991
|
+
metadata: result.data,
|
|
992
|
+
};
|
|
993
|
+
};
|
|
994
|
+
|
|
995
|
+
const create_throw_error = (props: {
|
|
996
|
+
context: ITypiaContext;
|
|
997
|
+
functor: FunctionProgrammer;
|
|
998
|
+
expected: string;
|
|
999
|
+
input: ts.Expression;
|
|
1000
|
+
}) =>
|
|
1001
|
+
ts.factory.createExpressionStatement(
|
|
1002
|
+
ts.factory.createCallExpression(
|
|
1003
|
+
props.context.importer.internal("throwTypeGuardError"),
|
|
1004
|
+
[],
|
|
1005
|
+
[
|
|
1006
|
+
ts.factory.createObjectLiteralExpression(
|
|
1007
|
+
[
|
|
1008
|
+
ts.factory.createPropertyAssignment(
|
|
1009
|
+
"method",
|
|
1010
|
+
ts.factory.createStringLiteral(props.functor.method),
|
|
1011
|
+
),
|
|
1012
|
+
ts.factory.createPropertyAssignment(
|
|
1013
|
+
"expected",
|
|
1014
|
+
ts.factory.createStringLiteral(props.expected),
|
|
1015
|
+
),
|
|
1016
|
+
ts.factory.createPropertyAssignment("value", props.input),
|
|
1017
|
+
],
|
|
1018
|
+
true,
|
|
1019
|
+
),
|
|
1020
|
+
],
|
|
1021
|
+
),
|
|
1022
|
+
);
|
|
1023
|
+
|
|
1024
|
+
const is_instance = (metadata: Metadata): boolean =>
|
|
1025
|
+
!!metadata.objects.length ||
|
|
1026
|
+
!!metadata.arrays.length ||
|
|
1027
|
+
!!metadata.tuples.length ||
|
|
1028
|
+
!!metadata.sets.length ||
|
|
1029
|
+
!!metadata.maps.length ||
|
|
1030
|
+
!!metadata.natives.length ||
|
|
1031
|
+
(metadata.rest !== null && is_instance(metadata.rest));
|
|
1032
|
+
}
|