typia 5.3.12-dev.20240121 → 5.3.12
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/package.json +1 -1
- package/src/AssertionGuard.ts +1 -1
- package/src/CamelCase.ts +114 -114
- package/src/IRandomGenerator.ts +35 -35
- package/src/IValidation.ts +21 -21
- package/src/PascalCase.ts +114 -114
- package/src/Primitive.ts +135 -135
- package/src/Resolved.ts +116 -116
- package/src/SnakeCase.ts +156 -156
- package/src/TypeGuardError.ts +36 -36
- package/src/executable/TypiaGenerateWizard.ts +83 -83
- package/src/executable/TypiaPatchWizard.ts +42 -42
- package/src/executable/TypiaSetupWizard.ts +151 -151
- package/src/executable/setup/ArgumentParser.ts +43 -43
- package/src/executable/setup/CommandExecutor.ts +8 -8
- package/src/executable/setup/FileRetriever.ts +22 -22
- package/src/executable/setup/PackageManager.ts +71 -71
- 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 +150 -150
- package/src/factories/IdentifierFactory.ts +70 -70
- package/src/factories/JsonMetadataFactory.ts +53 -53
- package/src/factories/LiteralFactory.ts +47 -47
- package/src/factories/MetadataCollection.ts +260 -260
- package/src/factories/MetadataCommentTagFactory.ts +601 -601
- package/src/factories/MetadataFactory.ts +267 -267
- package/src/factories/MetadataTypeTagFactory.ts +313 -313
- package/src/factories/NumericRangeFactory.ts +72 -72
- package/src/factories/ProtobufFactory.ts +259 -259
- package/src/factories/StatementFactory.ts +72 -72
- package/src/factories/TemplateFactory.ts +56 -56
- package/src/factories/TypeFactory.ts +118 -118
- package/src/factories/ValueFactory.ts +12 -12
- package/src/factories/internal/metadata/MetadataHelper.ts +15 -15
- package/src/factories/internal/metadata/emend_metadata_atomics.ts +37 -37
- package/src/factories/internal/metadata/emplace_metadata_alias.ts +41 -41
- package/src/factories/internal/metadata/emplace_metadata_array_type.ts +38 -38
- package/src/factories/internal/metadata/emplace_metadata_object.ts +175 -175
- package/src/factories/internal/metadata/emplace_metadata_tuple.ts +57 -57
- package/src/factories/internal/metadata/explore_metadata.ts +28 -28
- package/src/factories/internal/metadata/iterate_metadata.ts +94 -94
- package/src/factories/internal/metadata/iterate_metadata_alias.ts +34 -34
- package/src/factories/internal/metadata/iterate_metadata_array.ts +37 -37
- package/src/factories/internal/metadata/iterate_metadata_atomic.ts +62 -62
- package/src/factories/internal/metadata/iterate_metadata_coalesce.ts +33 -33
- package/src/factories/internal/metadata/iterate_metadata_collection.ts +131 -131
- package/src/factories/internal/metadata/iterate_metadata_comment_tags.ts +26 -26
- package/src/factories/internal/metadata/iterate_metadata_constant.ts +48 -48
- package/src/factories/internal/metadata/iterate_metadata_intersection.ts +230 -230
- package/src/factories/internal/metadata/iterate_metadata_map.ts +50 -50
- package/src/factories/internal/metadata/iterate_metadata_native.ts +208 -208
- package/src/factories/internal/metadata/iterate_metadata_object.ts +43 -43
- package/src/factories/internal/metadata/iterate_metadata_resolve.ts +52 -52
- package/src/factories/internal/metadata/iterate_metadata_set.ts +41 -41
- package/src/factories/internal/metadata/iterate_metadata_sort.ts +61 -61
- package/src/factories/internal/metadata/iterate_metadata_template.ts +44 -44
- package/src/factories/internal/metadata/iterate_metadata_tuple.ts +37 -37
- package/src/factories/internal/metadata/iterate_metadata_union.ts +27 -27
- package/src/functional/$HeadersReader/$HeadersReader.ts +26 -26
- package/src/functional/$HeadersReader/index.ts +1 -1
- package/src/functional/$ParameterReader/$ParameterReader.ts +29 -29
- package/src/functional/$ParameterReader/index.ts +1 -1
- package/src/functional/$ProtobufReader.ts +195 -195
- package/src/functional/$ProtobufSizer.ts +147 -147
- package/src/functional/$ProtobufWriter.ts +150 -150
- package/src/functional/$QueryReader/$QueryReader.ts +46 -46
- package/src/functional/$QueryReader/index.ts +1 -1
- package/src/functional/$any.ts +4 -4
- package/src/functional/$clone.ts +4 -4
- package/src/functional/$convention.ts +37 -37
- package/src/functional/$dictionary.ts +22 -22
- package/src/functional/$every.ts +11 -11
- package/src/functional/$guard.ts +35 -35
- package/src/functional/$is_between.ts +2 -2
- package/src/functional/$join.ts +46 -46
- package/src/functional/$number.ts +12 -12
- package/src/functional/$report.ts +13 -13
- package/src/functional/$rest.ts +3 -3
- package/src/functional/$stoll.ts +8 -8
- package/src/functional/$string.ts +50 -50
- package/src/functional/$strlen.ts +7 -7
- package/src/functional/$tail.ts +5 -5
- package/src/functional/$throws.ts +10 -10
- package/src/functional/$varint.ts +130 -130
- package/src/functional/$zigzag.ts +39 -39
- package/src/functional/IProtobufWriter.ts +18 -18
- package/src/functional/Namespace/http.ts +7 -7
- package/src/functional/Namespace/index.ts +75 -75
- package/src/functional/Namespace/json.ts +15 -15
- package/src/functional/Namespace/misc.ts +14 -14
- package/src/functional/Namespace/notations.ts +23 -23
- package/src/functional/Namespace/protobuf.ts +20 -20
- package/src/functional/is.ts +10 -10
- package/src/http.ts +1267 -1267
- package/src/index.ts +4 -4
- package/src/notations.ts +977 -977
- package/src/programmers/AssertProgrammer.ts +293 -293
- package/src/programmers/CheckerProgrammer.ts +1025 -1025
- package/src/programmers/FeatureProgrammer.ts +460 -460
- package/src/programmers/IsProgrammer.ts +232 -232
- package/src/programmers/RandomProgrammer.ts +825 -825
- package/src/programmers/TypiaProgrammer.ts +167 -167
- package/src/programmers/ValidateProgrammer.ts +307 -307
- package/src/programmers/helpers/AtomicPredicator.ts +25 -25
- package/src/programmers/helpers/CloneJoiner.ts +130 -130
- package/src/programmers/helpers/FunctionImporeter.ts +87 -87
- 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 +132 -132
- package/src/programmers/helpers/OptionPredicator.ts +15 -15
- package/src/programmers/helpers/ProtobufUtil.ts +125 -125
- package/src/programmers/helpers/ProtobufWire.ts +34 -34
- package/src/programmers/helpers/PruneJoiner.ts +141 -141
- package/src/programmers/helpers/RandomJoiner.ts +140 -140
- package/src/programmers/helpers/RandomRanger.ts +171 -171
- package/src/programmers/helpers/StringifyJoinder.ts +105 -105
- package/src/programmers/helpers/StringifyPredicator.ts +12 -12
- package/src/programmers/helpers/UnionExplorer.ts +269 -269
- package/src/programmers/helpers/UnionPredicator.ts +77 -77
- package/src/programmers/helpers/disable_function_importer_declare.ts +32 -32
- package/src/programmers/http/HttpAssertHeadersProgrammer.ts +77 -77
- package/src/programmers/http/HttpAssertQueryProgrammer.ts +75 -75
- package/src/programmers/http/HttpHeadersProgrammer.ts +314 -314
- package/src/programmers/http/HttpIsHeadersProgrammer.ts +84 -84
- package/src/programmers/http/HttpIsQueryProgrammer.ts +82 -82
- package/src/programmers/http/HttpParameterProgrammer.ts +97 -97
- package/src/programmers/http/HttpQueryProgrammer.ts +252 -252
- package/src/programmers/http/HttpValidateHeadersProgrammer.ts +77 -77
- package/src/programmers/http/HttpValidateQueryProgrammer.ts +75 -75
- package/src/programmers/internal/JSON_SCHEMA_PREFIX.ts +1 -1
- package/src/programmers/internal/application_alias.ts +74 -74
- package/src/programmers/internal/application_array.ts +59 -59
- package/src/programmers/internal/application_boolean.ts +35 -35
- package/src/programmers/internal/application_constant.ts +25 -25
- package/src/programmers/internal/application_default.ts +17 -17
- package/src/programmers/internal/application_default_string.ts +33 -33
- package/src/programmers/internal/application_escaped.ts +52 -52
- package/src/programmers/internal/application_native.ts +34 -34
- package/src/programmers/internal/application_number.ts +97 -97
- package/src/programmers/internal/application_object.ts +183 -183
- package/src/programmers/internal/application_schema.ts +165 -165
- package/src/programmers/internal/application_string.ts +61 -61
- package/src/programmers/internal/application_templates.ts +24 -24
- package/src/programmers/internal/application_tuple.ts +54 -54
- package/src/programmers/internal/check_array_length.ts +45 -45
- package/src/programmers/internal/check_bigint.ts +49 -49
- package/src/programmers/internal/check_dynamic_key.ts +175 -175
- package/src/programmers/internal/check_dynamic_properties.ts +198 -198
- package/src/programmers/internal/check_everything.ts +23 -23
- package/src/programmers/internal/check_native.ts +21 -21
- package/src/programmers/internal/check_number.ts +106 -106
- package/src/programmers/internal/check_object.ts +60 -60
- package/src/programmers/internal/check_string.ts +48 -48
- package/src/programmers/internal/check_template.ts +61 -61
- package/src/programmers/internal/check_union_array_like.ts +307 -307
- package/src/programmers/internal/decode_union_object.ts +78 -78
- package/src/programmers/internal/feature_object_entries.ts +58 -58
- package/src/programmers/internal/metadata_to_pattern.ts +33 -33
- package/src/programmers/internal/prune_object_properties.ts +60 -60
- package/src/programmers/internal/random_custom.ts +37 -37
- package/src/programmers/internal/stringify_dynamic_properties.ts +157 -157
- 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 +15 -15
- package/src/programmers/internal/wrap_metadata_rest_tuple.ts +20 -20
- package/src/programmers/json/JsonApplicationProgrammer.ts +49 -49
- package/src/programmers/json/JsonAssertParseProgrammer.ts +67 -67
- package/src/programmers/json/JsonAssertStringifyProgrammer.ts +61 -61
- package/src/programmers/json/JsonIsParseProgrammer.ts +73 -73
- package/src/programmers/json/JsonIsStringifyProgrammer.ts +75 -75
- package/src/programmers/json/JsonStringifyProgrammer.ts +893 -893
- package/src/programmers/json/JsonValidateParseProgrammer.ts +64 -64
- package/src/programmers/json/JsonValidateStringifyProgrammer.ts +83 -83
- package/src/programmers/misc/MiscAssertCloneProgrammer.ts +63 -63
- package/src/programmers/misc/MiscAssertPruneProgrammer.ts +60 -60
- package/src/programmers/misc/MiscCloneProgrammer.ts +713 -713
- package/src/programmers/misc/MiscIsCloneProgrammer.ts +70 -70
- package/src/programmers/misc/MiscIsPruneProgrammer.ts +66 -66
- package/src/programmers/misc/MiscLiteralsProgrammer.ts +72 -72
- package/src/programmers/misc/MiscPruneProgrammer.ts +523 -523
- package/src/programmers/misc/MiscValidateCloneProgrammer.ts +80 -80
- package/src/programmers/misc/MiscValidatePruneProgrammer.ts +73 -73
- package/src/programmers/notations/NotationAssertGeneralProgrammer.ts +64 -64
- package/src/programmers/notations/NotationGeneralProgrammer.ts +647 -647
- package/src/programmers/notations/NotationIsGeneralProgrammer.ts +71 -71
- package/src/programmers/notations/NotationValidateGeneralProgrammer.ts +81 -81
- package/src/programmers/protobuf/ProtobufAssertDecodeProgrammer.ts +75 -75
- package/src/programmers/protobuf/ProtobufAssertEncodeProgrammer.ts +61 -61
- package/src/programmers/protobuf/ProtobufDecodeProgrammer.ts +607 -607
- package/src/programmers/protobuf/ProtobufEncodeProgrammer.ts +819 -819
- package/src/programmers/protobuf/ProtobufIsDecodeProgrammer.ts +82 -82
- package/src/programmers/protobuf/ProtobufIsEncodeProgrammer.ts +75 -75
- package/src/programmers/protobuf/ProtobufMessageProgrammer.ts +160 -160
- package/src/programmers/protobuf/ProtobufValidateDecodeProgrammer.ts +75 -75
- package/src/programmers/protobuf/ProtobufValidateEncodeProgrammer.ts +83 -83
- package/src/protobuf.ts +970 -970
- package/src/reflect.ts +57 -57
- package/src/schemas/json/IJsonApplication.ts +9 -9
- package/src/schemas/json/IJsonComponents.ts +19 -19
- package/src/schemas/json/IJsonSchema.ts +122 -122
- package/src/schemas/metadata/IJsDocTagInfo.ts +10 -10
- package/src/schemas/metadata/IMetadata.ts +34 -34
- package/src/schemas/metadata/IMetadataAlias.ts +12 -12
- package/src/schemas/metadata/IMetadataApplication.ts +7 -7
- package/src/schemas/metadata/IMetadataArray.ts +7 -7
- 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 +23 -23
- package/src/schemas/metadata/IMetadataDictionary.ts +11 -11
- package/src/schemas/metadata/IMetadataEntry.ts +6 -6
- package/src/schemas/metadata/IMetadataEscaped.ts +6 -6
- package/src/schemas/metadata/IMetadataObject.ts +13 -13
- package/src/schemas/metadata/IMetadataProperty.ts +9 -9
- package/src/schemas/metadata/IMetadataTuple.ts +7 -7
- package/src/schemas/metadata/IMetadataTupleType.ts +10 -10
- package/src/schemas/metadata/IMetadataTypeTag.ts +15 -15
- package/src/schemas/metadata/Metadata.ts +612 -612
- package/src/schemas/metadata/MetadataAlias.ts +61 -61
- 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 +84 -84
- package/src/schemas/metadata/MetadataComponents.ts +98 -98
- package/src/schemas/metadata/MetadataConstant.ts +46 -46
- package/src/schemas/metadata/MetadataEscaped.ts +51 -51
- package/src/schemas/metadata/MetadataObject.ts +154 -154
- package/src/schemas/metadata/MetadataProperty.ts +56 -56
- package/src/schemas/metadata/MetadataTuple.ts +32 -32
- package/src/schemas/metadata/MetadataTupleType.ts +67 -67
- package/src/tags/Default.ts +15 -15
- package/src/tags/ExclusiveMaximum.ts +13 -13
- package/src/tags/ExclusiveMinimum.ts +13 -13
- package/src/tags/Format.ts +30 -30
- package/src/tags/MaxItems.ts +9 -9
- package/src/tags/MaxLength.ts +9 -9
- package/src/tags/Maximum.ts +13 -13
- package/src/tags/MinItems.ts +9 -9
- package/src/tags/MinLength.ts +9 -9
- package/src/tags/Minimum.ts +13 -13
- package/src/tags/MultipleOf.ts +15 -15
- package/src/tags/Pattern.ts +9 -9
- package/src/tags/TagBase.ts +68 -68
- package/src/tags/Type.ts +27 -27
- package/src/tags/index.ts +14 -14
- package/src/transform.ts +35 -35
- package/src/transformers/CallExpressionTransformer.ts +351 -351
- package/src/transformers/FileTransformer.ts +91 -91
- package/src/transformers/IProject.ts +15 -15
- package/src/transformers/ITransformOptions.ts +62 -62
- package/src/transformers/ImportTransformer.ts +66 -66
- package/src/transformers/NodeTransformer.ts +13 -13
- package/src/transformers/TransformerError.ts +55 -55
- package/src/transformers/features/AssertTransformer.ts +16 -16
- package/src/transformers/features/CreateAssertTransformer.ts +16 -16
- package/src/transformers/features/CreateIsTransformer.ts +10 -10
- package/src/transformers/features/CreateRandomTransformer.ts +40 -40
- package/src/transformers/features/CreateValidateTransformer.ts +13 -13
- package/src/transformers/features/IsTransformer.ts +10 -10
- package/src/transformers/features/RandomTransformer.ts +44 -44
- package/src/transformers/features/ValidateTransformer.ts +11 -11
- package/src/transformers/features/http/CreateHttpAssertHeadersTransformer.ts +11 -11
- package/src/transformers/features/http/CreateHttpAssertQueryTransformer.ts +9 -9
- package/src/transformers/features/http/CreateHttpHeadersTransformer.ts +9 -9
- package/src/transformers/features/http/CreateHttpIsHeadersTransformer.ts +9 -9
- package/src/transformers/features/http/CreateHttpIsQueryTransformer.ts +9 -9
- package/src/transformers/features/http/CreateHttpParameterTransformer.ts +9 -9
- package/src/transformers/features/http/CreateHttpQueryTransformer.ts +9 -9
- package/src/transformers/features/http/CreateHttpValidateHeadersTransformer.ts +12 -12
- package/src/transformers/features/http/CreateHttpValidateQueryTransformer.ts +11 -11
- package/src/transformers/features/http/HttpAssertHeadersTransformer.ts +9 -9
- package/src/transformers/features/http/HttpAssertQueryTransformer.ts +9 -9
- package/src/transformers/features/http/HttpHeadersTransformer.ts +9 -9
- package/src/transformers/features/http/HttpIsHeadersTransformer.ts +9 -9
- package/src/transformers/features/http/HttpIsQueryTransformer.ts +9 -9
- package/src/transformers/features/http/HttpParameterTransformer.ts +9 -9
- package/src/transformers/features/http/HttpQueryTransformer.ts +9 -9
- package/src/transformers/features/http/HttpValidateHeadersTransformer.ts +10 -10
- package/src/transformers/features/http/HttpValidateQueryTransformer.ts +9 -9
- package/src/transformers/features/json/JsonApplicationTransformer.ts +134 -134
- package/src/transformers/features/json/JsonAssertParseTransformer.ts +9 -9
- package/src/transformers/features/json/JsonAssertStringifyTransformer.ts +10 -10
- package/src/transformers/features/json/JsonCreateAssertParseTransformer.ts +9 -9
- package/src/transformers/features/json/JsonCreateAssertStringifyTransformer.ts +12 -12
- package/src/transformers/features/json/JsonCreateIsParseTransformer.ts +9 -9
- package/src/transformers/features/json/JsonCreateIsStringifyTransformer.ts +9 -9
- package/src/transformers/features/json/JsonCreateStringifyTransformer.ts +9 -9
- package/src/transformers/features/json/JsonCreateValidateParseTransformer.ts +11 -11
- package/src/transformers/features/json/JsonCreateValidateStringifyProgrammer.ts +12 -12
- package/src/transformers/features/json/JsonIsParseTransformer.ts +9 -9
- package/src/transformers/features/json/JsonIsStringifyTransformer.ts +9 -9
- package/src/transformers/features/json/JsonStringifyTransformer.ts +9 -9
- package/src/transformers/features/json/JsonValidateParseTransformer.ts +9 -9
- package/src/transformers/features/json/JsonValidateStringifyTransformer.ts +10 -10
- package/src/transformers/features/misc/MiscAssertCloneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscAssertPruneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscCloneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscCreateAssertCloneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscCreateAssertPruneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscCreateCloneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscCreateIsCloneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscCreateIsPruneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscCreatePruneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscCreateValidateCloneTransformer.ts +11 -11
- package/src/transformers/features/misc/MiscCreateValidatePruneTransformer.ts +11 -11
- package/src/transformers/features/misc/MiscIsCloneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscIsPruneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscLiteralsTransformer.ts +32 -32
- package/src/transformers/features/misc/MiscPruneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscValidateCloneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscValidatePruneTransformer.ts +9 -9
- package/src/transformers/features/notations/NotationAssertGeneralTransformer.ts +15 -15
- package/src/transformers/features/notations/NotationCreateAssertGeneralTransformer.ts +15 -15
- package/src/transformers/features/notations/NotationCreateGeneralTransformer.ts +15 -15
- package/src/transformers/features/notations/NotationCreateIsGeneralTransformer.ts +15 -15
- package/src/transformers/features/notations/NotationCreateValidateGeneralTransformer.ts +15 -15
- package/src/transformers/features/notations/NotationGeneralTransformer.ts +11 -11
- package/src/transformers/features/notations/NotationIsGeneralTransformer.ts +15 -15
- package/src/transformers/features/notations/NotationValidateGeneralTransformer.ts +15 -15
- package/src/transformers/features/protobuf/ProtobufAssertDecodeTransformer.ts +10 -10
- package/src/transformers/features/protobuf/ProtobufAssertEncodeTransformer.ts +10 -10
- package/src/transformers/features/protobuf/ProtobufCreateAssertDecodeTransformer.ts +12 -12
- package/src/transformers/features/protobuf/ProtobufCreateAssertEncodeTransformer.ts +12 -12
- package/src/transformers/features/protobuf/ProtobufCreateDecodeTransformer.ts +9 -9
- package/src/transformers/features/protobuf/ProtobufCreateEncodeTransformer.ts +9 -9
- package/src/transformers/features/protobuf/ProtobufCreateIsDecodeTransformer.ts +9 -9
- package/src/transformers/features/protobuf/ProtobufCreateIsEncodeTransformer.ts +9 -9
- package/src/transformers/features/protobuf/ProtobufCreateValidateDecodeTransformer.ts +12 -12
- package/src/transformers/features/protobuf/ProtobufCreateValidateEncodeTransformer.ts +12 -12
- package/src/transformers/features/protobuf/ProtobufDecodeTransformer.ts +9 -9
- package/src/transformers/features/protobuf/ProtobufEncodeTransformer.ts +9 -9
- package/src/transformers/features/protobuf/ProtobufIsDecodeTransformer.ts +9 -9
- package/src/transformers/features/protobuf/ProtobufIsEncodeTransformer.ts +9 -9
- package/src/transformers/features/protobuf/ProtobufMessageTransformer.ts +33 -33
- package/src/transformers/features/protobuf/ProtobufValidateDecodeTransformer.ts +10 -10
- package/src/transformers/features/protobuf/ProtobufValidateEncodeTransformer.ts +10 -10
- package/src/transformers/features/reflect/ReflectMetadataTransformer.ts +63 -63
- package/src/transformers/internal/GenericTransformer.ts +96 -96
- package/src/typings/Atomic.ts +13 -13
- package/src/typings/ClassProperties.ts +5 -5
- package/src/typings/Customizable.ts +5 -5
- 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/Writable.ts +11 -11
- package/src/utils/ArrayUtil.ts +43 -43
- package/src/utils/Escaper.ts +46 -46
- package/src/utils/MapUtil.ts +12 -12
- package/src/utils/NameEncoder.ts +32 -32
- package/src/utils/NamingConvention/NamingConvention.ts +77 -77
- package/src/utils/NamingConvention/index.ts +1 -1
- package/src/utils/PatternUtil.ts +29 -29
- package/src/utils/RandomGenerator/RandomGenerator.ts +74 -74
- package/src/utils/RandomGenerator/index.ts +1 -1
- package/src/utils/Singleton.ts +16 -16
- package/src/utils/StringUtil/StringUtil.ts +2 -2
- package/src/utils/StringUtil/index.ts +1 -1
|
@@ -1,825 +1,825 @@
|
|
|
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 { TemplateFactory } from "../factories/TemplateFactory";
|
|
9
|
-
import { TypeFactory } from "../factories/TypeFactory";
|
|
10
|
-
|
|
11
|
-
import { Metadata } from "../schemas/metadata/Metadata";
|
|
12
|
-
import { MetadataArray } from "../schemas/metadata/MetadataArray";
|
|
13
|
-
import { MetadataArrayType } from "../schemas/metadata/MetadataArrayType";
|
|
14
|
-
import { MetadataAtomic } from "../schemas/metadata/MetadataAtomic";
|
|
15
|
-
import { MetadataObject } from "../schemas/metadata/MetadataObject";
|
|
16
|
-
import { MetadataTuple } from "../schemas/metadata/MetadataTuple";
|
|
17
|
-
import { MetadataTupleType } from "../schemas/metadata/MetadataTupleType";
|
|
18
|
-
|
|
19
|
-
import { IProject } from "../transformers/IProject";
|
|
20
|
-
import { TransformerError } from "../transformers/TransformerError";
|
|
21
|
-
|
|
22
|
-
import { Escaper } from "../utils/Escaper";
|
|
23
|
-
|
|
24
|
-
import { FunctionImporter } from "./helpers/FunctionImporeter";
|
|
25
|
-
import { RandomJoiner } from "./helpers/RandomJoiner";
|
|
26
|
-
import { RandomRanger } from "./helpers/RandomRanger";
|
|
27
|
-
import { random_custom } from "./internal/random_custom";
|
|
28
|
-
|
|
29
|
-
export namespace RandomProgrammer {
|
|
30
|
-
export const write =
|
|
31
|
-
(project: IProject) =>
|
|
32
|
-
(modulo: ts.LeftHandSideExpression) =>
|
|
33
|
-
(init?: ts.Expression) => {
|
|
34
|
-
const importer: FunctionImporter = new FunctionImporter(modulo.getText());
|
|
35
|
-
return (type: ts.Type, name?: string) => {
|
|
36
|
-
// INITIALIZE METADATA
|
|
37
|
-
const collection: MetadataCollection = new MetadataCollection();
|
|
38
|
-
const result = MetadataFactory.analyze(
|
|
39
|
-
project.checker,
|
|
40
|
-
project.context,
|
|
41
|
-
)({
|
|
42
|
-
escape: false,
|
|
43
|
-
constant: true,
|
|
44
|
-
absorb: true,
|
|
45
|
-
validate: (meta) => {
|
|
46
|
-
const output: string[] = [];
|
|
47
|
-
if (meta.natives.some((n) => n === "WeakSet"))
|
|
48
|
-
output.push(`WeakSet is not supported.`);
|
|
49
|
-
else if (meta.natives.some((n) => n === "WeakMap"))
|
|
50
|
-
output.push(`WeakMap is not supported.`);
|
|
51
|
-
return output;
|
|
52
|
-
},
|
|
53
|
-
})(collection)(type);
|
|
54
|
-
if (result.success === false)
|
|
55
|
-
throw TransformerError.from(`typia.${importer.method}`)(
|
|
56
|
-
result.errors,
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
// GENERATE FUNCTION
|
|
60
|
-
const functions = {
|
|
61
|
-
objects: write_object_functions(importer)(collection),
|
|
62
|
-
arrays: write_array_functions(importer)(collection),
|
|
63
|
-
tuples: write_tuple_functions(importer)(collection),
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const output: ts.Expression = decode(importer)({
|
|
67
|
-
function: false,
|
|
68
|
-
recursive: false,
|
|
69
|
-
})(result.data);
|
|
70
|
-
|
|
71
|
-
return ts.factory.createArrowFunction(
|
|
72
|
-
undefined,
|
|
73
|
-
undefined,
|
|
74
|
-
[
|
|
75
|
-
IdentifierFactory.parameter(
|
|
76
|
-
"generator",
|
|
77
|
-
ts.factory.createTypeReferenceNode(
|
|
78
|
-
"Partial<typia.IRandomGenerator>",
|
|
79
|
-
),
|
|
80
|
-
init ?? ts.factory.createToken(ts.SyntaxKind.QuestionToken),
|
|
81
|
-
),
|
|
82
|
-
],
|
|
83
|
-
ts.factory.createTypeReferenceNode(
|
|
84
|
-
`typia.Resolved<${
|
|
85
|
-
name ?? TypeFactory.getFullName(project.checker)(type)
|
|
86
|
-
}>`,
|
|
87
|
-
),
|
|
88
|
-
undefined,
|
|
89
|
-
ts.factory.createBlock(
|
|
90
|
-
[
|
|
91
|
-
...importer.declare(modulo),
|
|
92
|
-
...functions.objects,
|
|
93
|
-
...functions.arrays,
|
|
94
|
-
...functions.tuples,
|
|
95
|
-
ts.factory.createReturnStatement(output),
|
|
96
|
-
],
|
|
97
|
-
true,
|
|
98
|
-
),
|
|
99
|
-
);
|
|
100
|
-
};
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
const write_object_functions =
|
|
104
|
-
(importer: FunctionImporter) =>
|
|
105
|
-
(collection: MetadataCollection): ts.VariableStatement[] =>
|
|
106
|
-
collection.objects().map((obj, i) =>
|
|
107
|
-
StatementFactory.constant(
|
|
108
|
-
PREFIX.object(i),
|
|
109
|
-
ts.factory.createArrowFunction(
|
|
110
|
-
undefined,
|
|
111
|
-
undefined,
|
|
112
|
-
[
|
|
113
|
-
IdentifierFactory.parameter(
|
|
114
|
-
"_recursive",
|
|
115
|
-
TypeFactory.keyword("boolean"),
|
|
116
|
-
ts.factory.createIdentifier(String(obj.recursive)),
|
|
117
|
-
),
|
|
118
|
-
IdentifierFactory.parameter(
|
|
119
|
-
"_depth",
|
|
120
|
-
TypeFactory.keyword("number"),
|
|
121
|
-
ExpressionFactory.number(0),
|
|
122
|
-
),
|
|
123
|
-
],
|
|
124
|
-
TypeFactory.keyword("any"),
|
|
125
|
-
undefined,
|
|
126
|
-
RandomJoiner.object(COALESCE(importer))(
|
|
127
|
-
decode(importer)({
|
|
128
|
-
recursive: obj.recursive,
|
|
129
|
-
function: true,
|
|
130
|
-
}),
|
|
131
|
-
)(obj),
|
|
132
|
-
),
|
|
133
|
-
),
|
|
134
|
-
);
|
|
135
|
-
|
|
136
|
-
const write_array_functions =
|
|
137
|
-
(importer: FunctionImporter) =>
|
|
138
|
-
(collection: MetadataCollection): ts.VariableStatement[] =>
|
|
139
|
-
collection
|
|
140
|
-
.arrays()
|
|
141
|
-
.filter((a) => a.recursive)
|
|
142
|
-
.map((array, i) =>
|
|
143
|
-
StatementFactory.constant(
|
|
144
|
-
PREFIX.array(i),
|
|
145
|
-
ts.factory.createArrowFunction(
|
|
146
|
-
undefined,
|
|
147
|
-
undefined,
|
|
148
|
-
[
|
|
149
|
-
IdentifierFactory.parameter(
|
|
150
|
-
"length",
|
|
151
|
-
TypeFactory.keyword("number"),
|
|
152
|
-
),
|
|
153
|
-
IdentifierFactory.parameter(
|
|
154
|
-
"_recursive",
|
|
155
|
-
TypeFactory.keyword("boolean"),
|
|
156
|
-
ts.factory.createTrue(),
|
|
157
|
-
),
|
|
158
|
-
IdentifierFactory.parameter(
|
|
159
|
-
"_depth",
|
|
160
|
-
TypeFactory.keyword("number"),
|
|
161
|
-
ExpressionFactory.number(0),
|
|
162
|
-
),
|
|
163
|
-
],
|
|
164
|
-
TypeFactory.keyword("any"),
|
|
165
|
-
undefined,
|
|
166
|
-
RandomJoiner.array(COALESCE(importer))(
|
|
167
|
-
decode(importer)({
|
|
168
|
-
recursive: true,
|
|
169
|
-
function: true,
|
|
170
|
-
}),
|
|
171
|
-
)({
|
|
172
|
-
recursive: true,
|
|
173
|
-
function: true,
|
|
174
|
-
})(ts.factory.createIdentifier("length"))(array.value),
|
|
175
|
-
),
|
|
176
|
-
),
|
|
177
|
-
);
|
|
178
|
-
|
|
179
|
-
const write_tuple_functions =
|
|
180
|
-
(importer: FunctionImporter) =>
|
|
181
|
-
(collection: MetadataCollection): ts.VariableStatement[] =>
|
|
182
|
-
collection
|
|
183
|
-
.tuples()
|
|
184
|
-
.filter((a) => a.recursive)
|
|
185
|
-
.map((tuple, i) =>
|
|
186
|
-
StatementFactory.constant(
|
|
187
|
-
PREFIX.tuple(i),
|
|
188
|
-
ts.factory.createArrowFunction(
|
|
189
|
-
undefined,
|
|
190
|
-
undefined,
|
|
191
|
-
[
|
|
192
|
-
IdentifierFactory.parameter(
|
|
193
|
-
"_recursive",
|
|
194
|
-
TypeFactory.keyword("boolean"),
|
|
195
|
-
ts.factory.createTrue(),
|
|
196
|
-
),
|
|
197
|
-
IdentifierFactory.parameter(
|
|
198
|
-
"_depth",
|
|
199
|
-
TypeFactory.keyword("number"),
|
|
200
|
-
ExpressionFactory.number(0),
|
|
201
|
-
),
|
|
202
|
-
],
|
|
203
|
-
TypeFactory.keyword("any"),
|
|
204
|
-
undefined,
|
|
205
|
-
RandomJoiner.tuple(
|
|
206
|
-
decode(importer)({
|
|
207
|
-
function: true,
|
|
208
|
-
recursive: true,
|
|
209
|
-
}),
|
|
210
|
-
)(tuple.elements),
|
|
211
|
-
),
|
|
212
|
-
),
|
|
213
|
-
);
|
|
214
|
-
|
|
215
|
-
/* -----------------------------------------------------------
|
|
216
|
-
DECODERS
|
|
217
|
-
----------------------------------------------------------- */
|
|
218
|
-
const decode =
|
|
219
|
-
(importer: FunctionImporter) =>
|
|
220
|
-
(explore: IExplore) =>
|
|
221
|
-
(meta: Metadata): ts.Expression => {
|
|
222
|
-
const expressions: ts.Expression[] = [];
|
|
223
|
-
if (meta.any)
|
|
224
|
-
expressions.push(ts.factory.createStringLiteral("any type used..."));
|
|
225
|
-
|
|
226
|
-
// NULL COALESCING
|
|
227
|
-
if (meta.isRequired() === false || meta.functional === true)
|
|
228
|
-
expressions.push(ts.factory.createIdentifier("undefined"));
|
|
229
|
-
if (meta.nullable === true) expressions.push(ts.factory.createNull());
|
|
230
|
-
|
|
231
|
-
// CONSTANT TYPES
|
|
232
|
-
for (const constant of meta.constants)
|
|
233
|
-
for (const value of constant.values)
|
|
234
|
-
expressions.push(decode_atomic(value));
|
|
235
|
-
|
|
236
|
-
// ATOMIC VARIABLES
|
|
237
|
-
for (const template of meta.templates)
|
|
238
|
-
expressions.push(decode_template(importer)(explore)(template));
|
|
239
|
-
for (const atomic of meta.atomics)
|
|
240
|
-
if (atomic.type === "boolean")
|
|
241
|
-
expressions.push(decode_boolean(importer));
|
|
242
|
-
else if (atomic.type === "number")
|
|
243
|
-
expressions.push(...decode_number(importer)(atomic));
|
|
244
|
-
else if (atomic.type === "string")
|
|
245
|
-
expressions.push(...decode_string(importer)(atomic));
|
|
246
|
-
else if (atomic.type === "bigint")
|
|
247
|
-
expressions.push(...decode_bigint(importer)(atomic));
|
|
248
|
-
|
|
249
|
-
// INSTANCE TYPES
|
|
250
|
-
if (meta.escaped)
|
|
251
|
-
expressions.push(decode(importer)(explore)(meta.escaped.returns));
|
|
252
|
-
for (const array of meta.arrays)
|
|
253
|
-
expressions.push(...decode_array(importer)(explore)(array));
|
|
254
|
-
for (const tuple of meta.tuples)
|
|
255
|
-
expressions.push(decode_tuple(importer)(explore)(tuple));
|
|
256
|
-
for (const o of meta.objects)
|
|
257
|
-
expressions.push(decode_object(importer)(explore)(o));
|
|
258
|
-
for (const native of meta.natives)
|
|
259
|
-
expressions.push(decode_native(importer)(native));
|
|
260
|
-
for (const set of meta.sets)
|
|
261
|
-
expressions.push(decode_set(importer)(explore)(set));
|
|
262
|
-
for (const map of meta.maps)
|
|
263
|
-
expressions.push(decode_map(importer)(explore)(map));
|
|
264
|
-
|
|
265
|
-
// PICK UP A TYPE
|
|
266
|
-
if (expressions.length === 1) return expressions[0]!;
|
|
267
|
-
return ts.factory.createCallExpression(
|
|
268
|
-
ts.factory.createCallExpression(importer.use("pick"), undefined, [
|
|
269
|
-
ts.factory.createArrayLiteralExpression(
|
|
270
|
-
expressions.map((expr) =>
|
|
271
|
-
ts.factory.createArrowFunction(
|
|
272
|
-
undefined,
|
|
273
|
-
undefined,
|
|
274
|
-
[],
|
|
275
|
-
undefined,
|
|
276
|
-
undefined,
|
|
277
|
-
expr,
|
|
278
|
-
),
|
|
279
|
-
),
|
|
280
|
-
true,
|
|
281
|
-
),
|
|
282
|
-
]),
|
|
283
|
-
undefined,
|
|
284
|
-
undefined,
|
|
285
|
-
);
|
|
286
|
-
};
|
|
287
|
-
|
|
288
|
-
const decode_boolean = (importer: FunctionImporter) =>
|
|
289
|
-
ts.factory.createCallExpression(
|
|
290
|
-
COALESCE(importer)("boolean"),
|
|
291
|
-
undefined,
|
|
292
|
-
undefined,
|
|
293
|
-
);
|
|
294
|
-
|
|
295
|
-
const decode_atomic = (value: Atomic) =>
|
|
296
|
-
typeof value === "boolean"
|
|
297
|
-
? ts.factory.createIdentifier(value.toString())
|
|
298
|
-
: typeof value === "number"
|
|
299
|
-
? ExpressionFactory.number(value)
|
|
300
|
-
: typeof value === "string"
|
|
301
|
-
? ts.factory.createStringLiteral(value)
|
|
302
|
-
: ExpressionFactory.bigint(Number(value));
|
|
303
|
-
|
|
304
|
-
const decode_template =
|
|
305
|
-
(importer: FunctionImporter) =>
|
|
306
|
-
(explore: IExplore) =>
|
|
307
|
-
(template: Metadata[]) =>
|
|
308
|
-
TemplateFactory.generate(
|
|
309
|
-
template.map((meta) => decode(importer)(explore)(meta)),
|
|
310
|
-
);
|
|
311
|
-
|
|
312
|
-
const decode_number =
|
|
313
|
-
(importer: FunctionImporter) =>
|
|
314
|
-
(atomic: MetadataAtomic): ts.Expression[] =>
|
|
315
|
-
(atomic.tags.length ? atomic.tags : [[]]).map((tags) => {
|
|
316
|
-
const type = tags.find(
|
|
317
|
-
(t) =>
|
|
318
|
-
t.kind === "type" && (t.value === "int32" || t.value === "int64"),
|
|
319
|
-
)
|
|
320
|
-
? "int"
|
|
321
|
-
: tags.find(
|
|
322
|
-
(t) =>
|
|
323
|
-
t.kind === "type" &&
|
|
324
|
-
(t.value === "uint32" || t.value === "uint64"),
|
|
325
|
-
)
|
|
326
|
-
? "uint"
|
|
327
|
-
: "double";
|
|
328
|
-
const multiply = tags.find((t) => t.kind === "multipleOf");
|
|
329
|
-
return random_custom(COALESCE(importer))("number")(tags)(
|
|
330
|
-
RandomRanger.number({
|
|
331
|
-
type,
|
|
332
|
-
transform: (value) => ExpressionFactory.number(value),
|
|
333
|
-
setter: (args) =>
|
|
334
|
-
ts.factory.createCallExpression(
|
|
335
|
-
type !== "double" || multiply !== undefined
|
|
336
|
-
? COALESCE(importer)("integer")
|
|
337
|
-
: COALESCE(importer)("number"),
|
|
338
|
-
undefined,
|
|
339
|
-
args.map((val) => ExpressionFactory.number(val)),
|
|
340
|
-
),
|
|
341
|
-
})({
|
|
342
|
-
minimum: 0,
|
|
343
|
-
maximum: 100,
|
|
344
|
-
gap: 10,
|
|
345
|
-
})(tags),
|
|
346
|
-
);
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
const decode_bigint =
|
|
350
|
-
(importer: FunctionImporter) =>
|
|
351
|
-
(atomic: MetadataAtomic): ts.Expression[] =>
|
|
352
|
-
(atomic.tags.length ? atomic.tags : [[]]).map((tags) =>
|
|
353
|
-
random_custom(COALESCE(importer))("bigint")(tags)(
|
|
354
|
-
RandomRanger.number({
|
|
355
|
-
type: tags.find(
|
|
356
|
-
(t) =>
|
|
357
|
-
t.kind === "type" &&
|
|
358
|
-
(t.value === "uint" || t.value === "uint64"),
|
|
359
|
-
)
|
|
360
|
-
? "uint"
|
|
361
|
-
: "int",
|
|
362
|
-
transform: (value) => ExpressionFactory.bigint(value),
|
|
363
|
-
setter: (args) =>
|
|
364
|
-
ts.factory.createCallExpression(
|
|
365
|
-
COALESCE(importer)("bigint"),
|
|
366
|
-
undefined,
|
|
367
|
-
args.map((value) => ExpressionFactory.bigint(value)),
|
|
368
|
-
),
|
|
369
|
-
})({
|
|
370
|
-
minimum: 0,
|
|
371
|
-
maximum: 100,
|
|
372
|
-
gap: 10,
|
|
373
|
-
})(tags),
|
|
374
|
-
),
|
|
375
|
-
);
|
|
376
|
-
|
|
377
|
-
const decode_string =
|
|
378
|
-
(importer: FunctionImporter) =>
|
|
379
|
-
(atomic: MetadataAtomic): ts.Expression[] =>
|
|
380
|
-
(atomic.tags.length ? atomic.tags : [[]]).map((tags) =>
|
|
381
|
-
random_custom(COALESCE(importer))("string")(tags)(
|
|
382
|
-
(() => {
|
|
383
|
-
for (const t of tags)
|
|
384
|
-
if (t.kind === "format")
|
|
385
|
-
return ts.factory.createCallExpression(
|
|
386
|
-
COALESCE(importer)(
|
|
387
|
-
t.value === "date-time" ? "datetime" : t.value,
|
|
388
|
-
),
|
|
389
|
-
undefined,
|
|
390
|
-
undefined,
|
|
391
|
-
);
|
|
392
|
-
else if (t.kind === "pattern")
|
|
393
|
-
return ts.factory.createCallExpression(
|
|
394
|
-
COALESCE(importer)("pattern"),
|
|
395
|
-
undefined,
|
|
396
|
-
[ts.factory.createIdentifier(`/${t.value}/`)],
|
|
397
|
-
);
|
|
398
|
-
|
|
399
|
-
const tail = RandomRanger.length(COALESCE(importer))({
|
|
400
|
-
minimum: 5,
|
|
401
|
-
maximum: 25,
|
|
402
|
-
gap: 5,
|
|
403
|
-
})({
|
|
404
|
-
minimum: "minLength",
|
|
405
|
-
maximum: "maxLength",
|
|
406
|
-
})(tags);
|
|
407
|
-
return ts.factory.createCallExpression(
|
|
408
|
-
COALESCE(importer)("string"),
|
|
409
|
-
undefined,
|
|
410
|
-
tail ? [tail] : undefined,
|
|
411
|
-
);
|
|
412
|
-
})(),
|
|
413
|
-
),
|
|
414
|
-
);
|
|
415
|
-
|
|
416
|
-
const decode_array =
|
|
417
|
-
(importer: FunctionImporter) =>
|
|
418
|
-
(explore: IExplore) =>
|
|
419
|
-
(array: MetadataArray): ts.Expression[] => {
|
|
420
|
-
const lengths: Array<ts.Expression | undefined> = (
|
|
421
|
-
array.tags.length ? array.tags : [[]]
|
|
422
|
-
).map((tags) =>
|
|
423
|
-
RandomRanger.length(COALESCE(importer))({
|
|
424
|
-
minimum: 0,
|
|
425
|
-
maximum: 3,
|
|
426
|
-
gap: 3,
|
|
427
|
-
})({
|
|
428
|
-
minimum: "minItems",
|
|
429
|
-
maximum: "maxItems",
|
|
430
|
-
})(tags),
|
|
431
|
-
);
|
|
432
|
-
if (array.type.recursive)
|
|
433
|
-
return lengths.map((len) =>
|
|
434
|
-
ts.factory.createCallExpression(
|
|
435
|
-
ts.factory.createIdentifier(
|
|
436
|
-
importer.useLocal(PREFIX.array(array.type.index!)),
|
|
437
|
-
),
|
|
438
|
-
undefined,
|
|
439
|
-
[
|
|
440
|
-
len ?? COALESCE(importer)("length"),
|
|
441
|
-
ts.factory.createTrue(),
|
|
442
|
-
explore.recursive
|
|
443
|
-
? ts.factory.createAdd(
|
|
444
|
-
ExpressionFactory.number(1),
|
|
445
|
-
ts.factory.createIdentifier("_depth"),
|
|
446
|
-
)
|
|
447
|
-
: ExpressionFactory.number(0),
|
|
448
|
-
],
|
|
449
|
-
),
|
|
450
|
-
);
|
|
451
|
-
return lengths.map((len) => {
|
|
452
|
-
const expr: ts.Expression = RandomJoiner.array(COALESCE(importer))(
|
|
453
|
-
decode(importer)(explore),
|
|
454
|
-
)(explore)(len)(array.type.value);
|
|
455
|
-
return explore.recursive
|
|
456
|
-
? ts.factory.createConditionalExpression(
|
|
457
|
-
ts.factory.createLogicalAnd(
|
|
458
|
-
ts.factory.createIdentifier("_recursive"),
|
|
459
|
-
ts.factory.createLessThan(
|
|
460
|
-
ExpressionFactory.number(5),
|
|
461
|
-
ts.factory.createIdentifier("_depth"),
|
|
462
|
-
),
|
|
463
|
-
),
|
|
464
|
-
undefined,
|
|
465
|
-
ts.factory.createIdentifier("[]"),
|
|
466
|
-
undefined,
|
|
467
|
-
expr,
|
|
468
|
-
)
|
|
469
|
-
: expr;
|
|
470
|
-
});
|
|
471
|
-
};
|
|
472
|
-
|
|
473
|
-
const decode_tuple =
|
|
474
|
-
(importer: FunctionImporter) =>
|
|
475
|
-
(explore: IExplore) =>
|
|
476
|
-
(tuple: MetadataTuple): ts.Expression =>
|
|
477
|
-
tuple.type.recursive
|
|
478
|
-
? ts.factory.createCallExpression(
|
|
479
|
-
ts.factory.createIdentifier(
|
|
480
|
-
importer.useLocal(PREFIX.tuple(tuple.type.index!)),
|
|
481
|
-
),
|
|
482
|
-
undefined,
|
|
483
|
-
[
|
|
484
|
-
ts.factory.createTrue(),
|
|
485
|
-
explore.recursive
|
|
486
|
-
? ts.factory.createAdd(
|
|
487
|
-
ExpressionFactory.number(1),
|
|
488
|
-
ts.factory.createIdentifier("_depth"),
|
|
489
|
-
)
|
|
490
|
-
: ExpressionFactory.number(0),
|
|
491
|
-
],
|
|
492
|
-
)
|
|
493
|
-
: RandomJoiner.tuple(decode(importer)(explore))(tuple.type.elements);
|
|
494
|
-
|
|
495
|
-
const decode_object =
|
|
496
|
-
(importer: FunctionImporter) =>
|
|
497
|
-
(explore: IExplore) =>
|
|
498
|
-
(object: MetadataObject) =>
|
|
499
|
-
ts.factory.createCallExpression(
|
|
500
|
-
ts.factory.createIdentifier(
|
|
501
|
-
importer.useLocal(PREFIX.object(object.index)),
|
|
502
|
-
),
|
|
503
|
-
undefined,
|
|
504
|
-
explore.function
|
|
505
|
-
? [
|
|
506
|
-
explore.recursive
|
|
507
|
-
? ts.factory.createTrue()
|
|
508
|
-
: ts.factory.createIdentifier("_recursive"),
|
|
509
|
-
ts.factory.createConditionalExpression(
|
|
510
|
-
ts.factory.createIdentifier("_recursive"),
|
|
511
|
-
undefined,
|
|
512
|
-
ts.factory.createAdd(
|
|
513
|
-
ExpressionFactory.number(1),
|
|
514
|
-
ts.factory.createIdentifier("_depth"),
|
|
515
|
-
),
|
|
516
|
-
undefined,
|
|
517
|
-
ts.factory.createIdentifier("_depth"),
|
|
518
|
-
),
|
|
519
|
-
]
|
|
520
|
-
: undefined,
|
|
521
|
-
);
|
|
522
|
-
|
|
523
|
-
/* -----------------------------------------------------------
|
|
524
|
-
NATIVE CLASSES
|
|
525
|
-
----------------------------------------------------------- */
|
|
526
|
-
const decode_set =
|
|
527
|
-
(importer: FunctionImporter) => (explore: IExplore) => (meta: Metadata) =>
|
|
528
|
-
ts.factory.createNewExpression(
|
|
529
|
-
ts.factory.createIdentifier("Set"),
|
|
530
|
-
undefined,
|
|
531
|
-
[
|
|
532
|
-
decode_array(importer)(explore)(
|
|
533
|
-
MetadataArray.create({
|
|
534
|
-
tags: [],
|
|
535
|
-
type: MetadataArrayType.create({
|
|
536
|
-
value: meta,
|
|
537
|
-
recursive: false,
|
|
538
|
-
index: null,
|
|
539
|
-
nullables: [],
|
|
540
|
-
name: `Set<${meta.getName()}>`,
|
|
541
|
-
}),
|
|
542
|
-
}),
|
|
543
|
-
)[0]!,
|
|
544
|
-
],
|
|
545
|
-
);
|
|
546
|
-
|
|
547
|
-
const decode_map =
|
|
548
|
-
(importer: FunctionImporter) =>
|
|
549
|
-
(explore: IExplore) =>
|
|
550
|
-
(map: Metadata.Entry) =>
|
|
551
|
-
ts.factory.createNewExpression(
|
|
552
|
-
ts.factory.createIdentifier("Map"),
|
|
553
|
-
undefined,
|
|
554
|
-
[
|
|
555
|
-
decode_array(importer)(explore)(
|
|
556
|
-
MetadataArray.create({
|
|
557
|
-
tags: [],
|
|
558
|
-
type: MetadataArrayType.create({
|
|
559
|
-
name: `Map<${map.key.getName()}, ${map.value.getName()}>`,
|
|
560
|
-
index: null,
|
|
561
|
-
recursive: false,
|
|
562
|
-
nullables: [],
|
|
563
|
-
value: Metadata.create({
|
|
564
|
-
...Metadata.initialize(),
|
|
565
|
-
tuples: [
|
|
566
|
-
(() => {
|
|
567
|
-
const type = MetadataTupleType.create({
|
|
568
|
-
name: `[${map.key.getName()}, ${map.value.getName()}]`,
|
|
569
|
-
index: null,
|
|
570
|
-
recursive: false,
|
|
571
|
-
nullables: [],
|
|
572
|
-
elements: [map.key, map.value],
|
|
573
|
-
});
|
|
574
|
-
type.of_map = true;
|
|
575
|
-
return MetadataTuple.create({
|
|
576
|
-
type,
|
|
577
|
-
tags: [],
|
|
578
|
-
});
|
|
579
|
-
})(),
|
|
580
|
-
],
|
|
581
|
-
}),
|
|
582
|
-
}),
|
|
583
|
-
}),
|
|
584
|
-
)[0]!,
|
|
585
|
-
],
|
|
586
|
-
);
|
|
587
|
-
|
|
588
|
-
const decode_native =
|
|
589
|
-
(importer: FunctionImporter) =>
|
|
590
|
-
(type: string): ts.Expression => {
|
|
591
|
-
if (type === "Boolean") return decode_boolean(importer);
|
|
592
|
-
else if (type === "Number")
|
|
593
|
-
return decode_number(importer)(
|
|
594
|
-
MetadataAtomic.create({
|
|
595
|
-
type: "number",
|
|
596
|
-
tags: [],
|
|
597
|
-
}),
|
|
598
|
-
)[0]!;
|
|
599
|
-
else if (type === "String")
|
|
600
|
-
return decode_string(importer)(
|
|
601
|
-
MetadataAtomic.create({
|
|
602
|
-
type: "string",
|
|
603
|
-
tags: [],
|
|
604
|
-
}),
|
|
605
|
-
)[0]!;
|
|
606
|
-
else if (type === "Date") return decode_native_date(importer);
|
|
607
|
-
else if (
|
|
608
|
-
type === "Uint8Array" ||
|
|
609
|
-
type === "Uint8ClampedArray" ||
|
|
610
|
-
type === "Uint16Array" ||
|
|
611
|
-
type === "Uint32Array" ||
|
|
612
|
-
type === "BigUint64Array" ||
|
|
613
|
-
type === "Int8Array" ||
|
|
614
|
-
type === "Int16Array" ||
|
|
615
|
-
type === "Int32Array" ||
|
|
616
|
-
type === "BigInt64Array" ||
|
|
617
|
-
type === "Float32Array" ||
|
|
618
|
-
type === "Float64Array"
|
|
619
|
-
)
|
|
620
|
-
return decode_native_byte_array(importer)(type);
|
|
621
|
-
else if (type === "ArrayBuffer" || type === "SharedArrayBuffer")
|
|
622
|
-
return decode_native_array_buffer(importer)(type);
|
|
623
|
-
else if (type === "DataView") return decode_native_data_view(importer);
|
|
624
|
-
else
|
|
625
|
-
return ts.factory.createNewExpression(
|
|
626
|
-
ts.factory.createIdentifier(type),
|
|
627
|
-
undefined,
|
|
628
|
-
[],
|
|
629
|
-
);
|
|
630
|
-
};
|
|
631
|
-
|
|
632
|
-
const decode_native_date = (importer: FunctionImporter) =>
|
|
633
|
-
ts.factory.createNewExpression(
|
|
634
|
-
ts.factory.createIdentifier("Date"),
|
|
635
|
-
undefined,
|
|
636
|
-
[
|
|
637
|
-
ts.factory.createCallExpression(
|
|
638
|
-
COALESCE(importer)("datetime"),
|
|
639
|
-
undefined,
|
|
640
|
-
[],
|
|
641
|
-
),
|
|
642
|
-
],
|
|
643
|
-
);
|
|
644
|
-
|
|
645
|
-
const decode_native_byte_array =
|
|
646
|
-
(importer: FunctionImporter) =>
|
|
647
|
-
(
|
|
648
|
-
type:
|
|
649
|
-
| "Uint8Array"
|
|
650
|
-
| "Uint8ClampedArray"
|
|
651
|
-
| "Uint16Array"
|
|
652
|
-
| "Uint32Array"
|
|
653
|
-
| "BigUint64Array"
|
|
654
|
-
| "Int8Array"
|
|
655
|
-
| "Int16Array"
|
|
656
|
-
| "Int32Array"
|
|
657
|
-
| "BigInt64Array"
|
|
658
|
-
| "Float32Array"
|
|
659
|
-
| "Float64Array",
|
|
660
|
-
): ts.Expression => {
|
|
661
|
-
new BigInt64Array();
|
|
662
|
-
const [minimum, maximum]: [number, number] = (() => {
|
|
663
|
-
if (type === "Uint8Array" || type === "Uint8ClampedArray")
|
|
664
|
-
return [0, 255];
|
|
665
|
-
else if (type === "Uint16Array") return [0, 65535];
|
|
666
|
-
else if (type === "Uint32Array") return [0, 4294967295];
|
|
667
|
-
else if (type === "BigUint64Array") return [0, 18446744073709551615];
|
|
668
|
-
else if (type === "Int8Array") return [-128, 127];
|
|
669
|
-
else if (type === "Int16Array") return [-32768, 32767];
|
|
670
|
-
else if (type === "Int32Array") return [-2147483648, 2147483647];
|
|
671
|
-
else if (type === "BigInt64Array")
|
|
672
|
-
return [-9223372036854775808, 9223372036854775807];
|
|
673
|
-
else if (type === "Float32Array")
|
|
674
|
-
return [-1.175494351e38, 3.4028235e38];
|
|
675
|
-
return [Number.MIN_VALUE, Number.MAX_VALUE];
|
|
676
|
-
})();
|
|
677
|
-
const literal =
|
|
678
|
-
type === "BigInt64Array" || type === "BigUint64Array"
|
|
679
|
-
? ExpressionFactory.bigint
|
|
680
|
-
: ExpressionFactory.number;
|
|
681
|
-
return ts.factory.createNewExpression(
|
|
682
|
-
ts.factory.createIdentifier(type),
|
|
683
|
-
[],
|
|
684
|
-
[
|
|
685
|
-
ts.factory.createCallExpression(
|
|
686
|
-
COALESCE(importer)("array"),
|
|
687
|
-
undefined,
|
|
688
|
-
[
|
|
689
|
-
ts.factory.createArrowFunction(
|
|
690
|
-
undefined,
|
|
691
|
-
undefined,
|
|
692
|
-
[],
|
|
693
|
-
TypeFactory.keyword("any"),
|
|
694
|
-
undefined,
|
|
695
|
-
ts.factory.createCallExpression(
|
|
696
|
-
COALESCE(importer)(
|
|
697
|
-
type === "Float32Array" || type === "Float64Array"
|
|
698
|
-
? "number"
|
|
699
|
-
: type === "BigInt64Array" || type === "BigUint64Array"
|
|
700
|
-
? "bigint"
|
|
701
|
-
: "integer",
|
|
702
|
-
),
|
|
703
|
-
undefined,
|
|
704
|
-
[literal(minimum), literal(maximum)],
|
|
705
|
-
),
|
|
706
|
-
),
|
|
707
|
-
],
|
|
708
|
-
),
|
|
709
|
-
],
|
|
710
|
-
);
|
|
711
|
-
};
|
|
712
|
-
|
|
713
|
-
const decode_native_array_buffer =
|
|
714
|
-
(importer: FunctionImporter) =>
|
|
715
|
-
(type: "ArrayBuffer" | "SharedArrayBuffer"): ts.Expression =>
|
|
716
|
-
type === "ArrayBuffer"
|
|
717
|
-
? IdentifierFactory.access(
|
|
718
|
-
decode_native_byte_array(importer)("Uint8Array"),
|
|
719
|
-
)("buffer")
|
|
720
|
-
: ExpressionFactory.selfCall(
|
|
721
|
-
ts.factory.createBlock(
|
|
722
|
-
[
|
|
723
|
-
StatementFactory.constant(
|
|
724
|
-
"length",
|
|
725
|
-
ts.factory.createCallExpression(
|
|
726
|
-
COALESCE(importer)("integer"),
|
|
727
|
-
undefined,
|
|
728
|
-
[],
|
|
729
|
-
),
|
|
730
|
-
),
|
|
731
|
-
StatementFactory.constant(
|
|
732
|
-
"buffer",
|
|
733
|
-
ts.factory.createNewExpression(
|
|
734
|
-
ts.factory.createIdentifier("SharedArrayBuffer"),
|
|
735
|
-
[],
|
|
736
|
-
[ts.factory.createIdentifier("length")],
|
|
737
|
-
),
|
|
738
|
-
),
|
|
739
|
-
StatementFactory.constant(
|
|
740
|
-
"bytes",
|
|
741
|
-
ts.factory.createNewExpression(
|
|
742
|
-
ts.factory.createIdentifier("Uint8Array"),
|
|
743
|
-
[],
|
|
744
|
-
[ts.factory.createIdentifier("buffer")],
|
|
745
|
-
),
|
|
746
|
-
),
|
|
747
|
-
ts.factory.createExpressionStatement(
|
|
748
|
-
ts.factory.createCallExpression(
|
|
749
|
-
IdentifierFactory.access(
|
|
750
|
-
ts.factory.createIdentifier("bytes"),
|
|
751
|
-
)("set"),
|
|
752
|
-
undefined,
|
|
753
|
-
[
|
|
754
|
-
ts.factory.createCallExpression(
|
|
755
|
-
COALESCE(importer)("array"),
|
|
756
|
-
undefined,
|
|
757
|
-
[
|
|
758
|
-
ts.factory.createArrowFunction(
|
|
759
|
-
undefined,
|
|
760
|
-
undefined,
|
|
761
|
-
[],
|
|
762
|
-
TypeFactory.keyword("any"),
|
|
763
|
-
undefined,
|
|
764
|
-
ts.factory.createCallExpression(
|
|
765
|
-
COALESCE(importer)("integer"),
|
|
766
|
-
undefined,
|
|
767
|
-
[
|
|
768
|
-
ExpressionFactory.number(0),
|
|
769
|
-
ExpressionFactory.number(255),
|
|
770
|
-
],
|
|
771
|
-
),
|
|
772
|
-
),
|
|
773
|
-
ts.factory.createIdentifier("length"),
|
|
774
|
-
],
|
|
775
|
-
),
|
|
776
|
-
ExpressionFactory.number(0),
|
|
777
|
-
],
|
|
778
|
-
),
|
|
779
|
-
),
|
|
780
|
-
ts.factory.createReturnStatement(
|
|
781
|
-
ts.factory.createIdentifier("buffer"),
|
|
782
|
-
),
|
|
783
|
-
],
|
|
784
|
-
true,
|
|
785
|
-
),
|
|
786
|
-
);
|
|
787
|
-
|
|
788
|
-
const decode_native_data_view = (importer: FunctionImporter) =>
|
|
789
|
-
ts.factory.createNewExpression(
|
|
790
|
-
ts.factory.createIdentifier("DataView"),
|
|
791
|
-
[],
|
|
792
|
-
[
|
|
793
|
-
IdentifierFactory.access(
|
|
794
|
-
decode_native_byte_array(importer)("Uint8Array"),
|
|
795
|
-
)("buffer"),
|
|
796
|
-
],
|
|
797
|
-
);
|
|
798
|
-
}
|
|
799
|
-
|
|
800
|
-
type Atomic = boolean | number | string | bigint;
|
|
801
|
-
interface IExplore {
|
|
802
|
-
function: boolean;
|
|
803
|
-
recursive: boolean;
|
|
804
|
-
}
|
|
805
|
-
|
|
806
|
-
const PREFIX = {
|
|
807
|
-
object: (i: number) => `$ro${i}`,
|
|
808
|
-
array: (i: number) => `$ra${i}`,
|
|
809
|
-
tuple: (i: number) => `$rt${i}`,
|
|
810
|
-
};
|
|
811
|
-
|
|
812
|
-
const COALESCE = (importer: FunctionImporter) => (name: string) =>
|
|
813
|
-
ExpressionFactory.coalesce(
|
|
814
|
-
Escaper.variable(name)
|
|
815
|
-
? ts.factory.createPropertyAccessChain(
|
|
816
|
-
ts.factory.createIdentifier("generator"),
|
|
817
|
-
ts.factory.createToken(ts.SyntaxKind.QuestionDotToken),
|
|
818
|
-
ts.factory.createIdentifier(name),
|
|
819
|
-
)
|
|
820
|
-
: ts.factory.createElementAccessChain(
|
|
821
|
-
ts.factory.createIdentifier("generator"),
|
|
822
|
-
ts.factory.createToken(ts.SyntaxKind.QuestionDotToken),
|
|
823
|
-
ts.factory.createStringLiteral(name),
|
|
824
|
-
),
|
|
825
|
-
)(IdentifierFactory.access(importer.use("generator"))(name));
|
|
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 { TemplateFactory } from "../factories/TemplateFactory";
|
|
9
|
+
import { TypeFactory } from "../factories/TypeFactory";
|
|
10
|
+
|
|
11
|
+
import { Metadata } from "../schemas/metadata/Metadata";
|
|
12
|
+
import { MetadataArray } from "../schemas/metadata/MetadataArray";
|
|
13
|
+
import { MetadataArrayType } from "../schemas/metadata/MetadataArrayType";
|
|
14
|
+
import { MetadataAtomic } from "../schemas/metadata/MetadataAtomic";
|
|
15
|
+
import { MetadataObject } from "../schemas/metadata/MetadataObject";
|
|
16
|
+
import { MetadataTuple } from "../schemas/metadata/MetadataTuple";
|
|
17
|
+
import { MetadataTupleType } from "../schemas/metadata/MetadataTupleType";
|
|
18
|
+
|
|
19
|
+
import { IProject } from "../transformers/IProject";
|
|
20
|
+
import { TransformerError } from "../transformers/TransformerError";
|
|
21
|
+
|
|
22
|
+
import { Escaper } from "../utils/Escaper";
|
|
23
|
+
|
|
24
|
+
import { FunctionImporter } from "./helpers/FunctionImporeter";
|
|
25
|
+
import { RandomJoiner } from "./helpers/RandomJoiner";
|
|
26
|
+
import { RandomRanger } from "./helpers/RandomRanger";
|
|
27
|
+
import { random_custom } from "./internal/random_custom";
|
|
28
|
+
|
|
29
|
+
export namespace RandomProgrammer {
|
|
30
|
+
export const write =
|
|
31
|
+
(project: IProject) =>
|
|
32
|
+
(modulo: ts.LeftHandSideExpression) =>
|
|
33
|
+
(init?: ts.Expression) => {
|
|
34
|
+
const importer: FunctionImporter = new FunctionImporter(modulo.getText());
|
|
35
|
+
return (type: ts.Type, name?: string) => {
|
|
36
|
+
// INITIALIZE METADATA
|
|
37
|
+
const collection: MetadataCollection = new MetadataCollection();
|
|
38
|
+
const result = MetadataFactory.analyze(
|
|
39
|
+
project.checker,
|
|
40
|
+
project.context,
|
|
41
|
+
)({
|
|
42
|
+
escape: false,
|
|
43
|
+
constant: true,
|
|
44
|
+
absorb: true,
|
|
45
|
+
validate: (meta) => {
|
|
46
|
+
const output: string[] = [];
|
|
47
|
+
if (meta.natives.some((n) => n === "WeakSet"))
|
|
48
|
+
output.push(`WeakSet is not supported.`);
|
|
49
|
+
else if (meta.natives.some((n) => n === "WeakMap"))
|
|
50
|
+
output.push(`WeakMap is not supported.`);
|
|
51
|
+
return output;
|
|
52
|
+
},
|
|
53
|
+
})(collection)(type);
|
|
54
|
+
if (result.success === false)
|
|
55
|
+
throw TransformerError.from(`typia.${importer.method}`)(
|
|
56
|
+
result.errors,
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
// GENERATE FUNCTION
|
|
60
|
+
const functions = {
|
|
61
|
+
objects: write_object_functions(importer)(collection),
|
|
62
|
+
arrays: write_array_functions(importer)(collection),
|
|
63
|
+
tuples: write_tuple_functions(importer)(collection),
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const output: ts.Expression = decode(importer)({
|
|
67
|
+
function: false,
|
|
68
|
+
recursive: false,
|
|
69
|
+
})(result.data);
|
|
70
|
+
|
|
71
|
+
return ts.factory.createArrowFunction(
|
|
72
|
+
undefined,
|
|
73
|
+
undefined,
|
|
74
|
+
[
|
|
75
|
+
IdentifierFactory.parameter(
|
|
76
|
+
"generator",
|
|
77
|
+
ts.factory.createTypeReferenceNode(
|
|
78
|
+
"Partial<typia.IRandomGenerator>",
|
|
79
|
+
),
|
|
80
|
+
init ?? ts.factory.createToken(ts.SyntaxKind.QuestionToken),
|
|
81
|
+
),
|
|
82
|
+
],
|
|
83
|
+
ts.factory.createTypeReferenceNode(
|
|
84
|
+
`typia.Resolved<${
|
|
85
|
+
name ?? TypeFactory.getFullName(project.checker)(type)
|
|
86
|
+
}>`,
|
|
87
|
+
),
|
|
88
|
+
undefined,
|
|
89
|
+
ts.factory.createBlock(
|
|
90
|
+
[
|
|
91
|
+
...importer.declare(modulo),
|
|
92
|
+
...functions.objects,
|
|
93
|
+
...functions.arrays,
|
|
94
|
+
...functions.tuples,
|
|
95
|
+
ts.factory.createReturnStatement(output),
|
|
96
|
+
],
|
|
97
|
+
true,
|
|
98
|
+
),
|
|
99
|
+
);
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const write_object_functions =
|
|
104
|
+
(importer: FunctionImporter) =>
|
|
105
|
+
(collection: MetadataCollection): ts.VariableStatement[] =>
|
|
106
|
+
collection.objects().map((obj, i) =>
|
|
107
|
+
StatementFactory.constant(
|
|
108
|
+
PREFIX.object(i),
|
|
109
|
+
ts.factory.createArrowFunction(
|
|
110
|
+
undefined,
|
|
111
|
+
undefined,
|
|
112
|
+
[
|
|
113
|
+
IdentifierFactory.parameter(
|
|
114
|
+
"_recursive",
|
|
115
|
+
TypeFactory.keyword("boolean"),
|
|
116
|
+
ts.factory.createIdentifier(String(obj.recursive)),
|
|
117
|
+
),
|
|
118
|
+
IdentifierFactory.parameter(
|
|
119
|
+
"_depth",
|
|
120
|
+
TypeFactory.keyword("number"),
|
|
121
|
+
ExpressionFactory.number(0),
|
|
122
|
+
),
|
|
123
|
+
],
|
|
124
|
+
TypeFactory.keyword("any"),
|
|
125
|
+
undefined,
|
|
126
|
+
RandomJoiner.object(COALESCE(importer))(
|
|
127
|
+
decode(importer)({
|
|
128
|
+
recursive: obj.recursive,
|
|
129
|
+
function: true,
|
|
130
|
+
}),
|
|
131
|
+
)(obj),
|
|
132
|
+
),
|
|
133
|
+
),
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
const write_array_functions =
|
|
137
|
+
(importer: FunctionImporter) =>
|
|
138
|
+
(collection: MetadataCollection): ts.VariableStatement[] =>
|
|
139
|
+
collection
|
|
140
|
+
.arrays()
|
|
141
|
+
.filter((a) => a.recursive)
|
|
142
|
+
.map((array, i) =>
|
|
143
|
+
StatementFactory.constant(
|
|
144
|
+
PREFIX.array(i),
|
|
145
|
+
ts.factory.createArrowFunction(
|
|
146
|
+
undefined,
|
|
147
|
+
undefined,
|
|
148
|
+
[
|
|
149
|
+
IdentifierFactory.parameter(
|
|
150
|
+
"length",
|
|
151
|
+
TypeFactory.keyword("number"),
|
|
152
|
+
),
|
|
153
|
+
IdentifierFactory.parameter(
|
|
154
|
+
"_recursive",
|
|
155
|
+
TypeFactory.keyword("boolean"),
|
|
156
|
+
ts.factory.createTrue(),
|
|
157
|
+
),
|
|
158
|
+
IdentifierFactory.parameter(
|
|
159
|
+
"_depth",
|
|
160
|
+
TypeFactory.keyword("number"),
|
|
161
|
+
ExpressionFactory.number(0),
|
|
162
|
+
),
|
|
163
|
+
],
|
|
164
|
+
TypeFactory.keyword("any"),
|
|
165
|
+
undefined,
|
|
166
|
+
RandomJoiner.array(COALESCE(importer))(
|
|
167
|
+
decode(importer)({
|
|
168
|
+
recursive: true,
|
|
169
|
+
function: true,
|
|
170
|
+
}),
|
|
171
|
+
)({
|
|
172
|
+
recursive: true,
|
|
173
|
+
function: true,
|
|
174
|
+
})(ts.factory.createIdentifier("length"))(array.value),
|
|
175
|
+
),
|
|
176
|
+
),
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
const write_tuple_functions =
|
|
180
|
+
(importer: FunctionImporter) =>
|
|
181
|
+
(collection: MetadataCollection): ts.VariableStatement[] =>
|
|
182
|
+
collection
|
|
183
|
+
.tuples()
|
|
184
|
+
.filter((a) => a.recursive)
|
|
185
|
+
.map((tuple, i) =>
|
|
186
|
+
StatementFactory.constant(
|
|
187
|
+
PREFIX.tuple(i),
|
|
188
|
+
ts.factory.createArrowFunction(
|
|
189
|
+
undefined,
|
|
190
|
+
undefined,
|
|
191
|
+
[
|
|
192
|
+
IdentifierFactory.parameter(
|
|
193
|
+
"_recursive",
|
|
194
|
+
TypeFactory.keyword("boolean"),
|
|
195
|
+
ts.factory.createTrue(),
|
|
196
|
+
),
|
|
197
|
+
IdentifierFactory.parameter(
|
|
198
|
+
"_depth",
|
|
199
|
+
TypeFactory.keyword("number"),
|
|
200
|
+
ExpressionFactory.number(0),
|
|
201
|
+
),
|
|
202
|
+
],
|
|
203
|
+
TypeFactory.keyword("any"),
|
|
204
|
+
undefined,
|
|
205
|
+
RandomJoiner.tuple(
|
|
206
|
+
decode(importer)({
|
|
207
|
+
function: true,
|
|
208
|
+
recursive: true,
|
|
209
|
+
}),
|
|
210
|
+
)(tuple.elements),
|
|
211
|
+
),
|
|
212
|
+
),
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
/* -----------------------------------------------------------
|
|
216
|
+
DECODERS
|
|
217
|
+
----------------------------------------------------------- */
|
|
218
|
+
const decode =
|
|
219
|
+
(importer: FunctionImporter) =>
|
|
220
|
+
(explore: IExplore) =>
|
|
221
|
+
(meta: Metadata): ts.Expression => {
|
|
222
|
+
const expressions: ts.Expression[] = [];
|
|
223
|
+
if (meta.any)
|
|
224
|
+
expressions.push(ts.factory.createStringLiteral("any type used..."));
|
|
225
|
+
|
|
226
|
+
// NULL COALESCING
|
|
227
|
+
if (meta.isRequired() === false || meta.functional === true)
|
|
228
|
+
expressions.push(ts.factory.createIdentifier("undefined"));
|
|
229
|
+
if (meta.nullable === true) expressions.push(ts.factory.createNull());
|
|
230
|
+
|
|
231
|
+
// CONSTANT TYPES
|
|
232
|
+
for (const constant of meta.constants)
|
|
233
|
+
for (const value of constant.values)
|
|
234
|
+
expressions.push(decode_atomic(value));
|
|
235
|
+
|
|
236
|
+
// ATOMIC VARIABLES
|
|
237
|
+
for (const template of meta.templates)
|
|
238
|
+
expressions.push(decode_template(importer)(explore)(template));
|
|
239
|
+
for (const atomic of meta.atomics)
|
|
240
|
+
if (atomic.type === "boolean")
|
|
241
|
+
expressions.push(decode_boolean(importer));
|
|
242
|
+
else if (atomic.type === "number")
|
|
243
|
+
expressions.push(...decode_number(importer)(atomic));
|
|
244
|
+
else if (atomic.type === "string")
|
|
245
|
+
expressions.push(...decode_string(importer)(atomic));
|
|
246
|
+
else if (atomic.type === "bigint")
|
|
247
|
+
expressions.push(...decode_bigint(importer)(atomic));
|
|
248
|
+
|
|
249
|
+
// INSTANCE TYPES
|
|
250
|
+
if (meta.escaped)
|
|
251
|
+
expressions.push(decode(importer)(explore)(meta.escaped.returns));
|
|
252
|
+
for (const array of meta.arrays)
|
|
253
|
+
expressions.push(...decode_array(importer)(explore)(array));
|
|
254
|
+
for (const tuple of meta.tuples)
|
|
255
|
+
expressions.push(decode_tuple(importer)(explore)(tuple));
|
|
256
|
+
for (const o of meta.objects)
|
|
257
|
+
expressions.push(decode_object(importer)(explore)(o));
|
|
258
|
+
for (const native of meta.natives)
|
|
259
|
+
expressions.push(decode_native(importer)(native));
|
|
260
|
+
for (const set of meta.sets)
|
|
261
|
+
expressions.push(decode_set(importer)(explore)(set));
|
|
262
|
+
for (const map of meta.maps)
|
|
263
|
+
expressions.push(decode_map(importer)(explore)(map));
|
|
264
|
+
|
|
265
|
+
// PICK UP A TYPE
|
|
266
|
+
if (expressions.length === 1) return expressions[0]!;
|
|
267
|
+
return ts.factory.createCallExpression(
|
|
268
|
+
ts.factory.createCallExpression(importer.use("pick"), undefined, [
|
|
269
|
+
ts.factory.createArrayLiteralExpression(
|
|
270
|
+
expressions.map((expr) =>
|
|
271
|
+
ts.factory.createArrowFunction(
|
|
272
|
+
undefined,
|
|
273
|
+
undefined,
|
|
274
|
+
[],
|
|
275
|
+
undefined,
|
|
276
|
+
undefined,
|
|
277
|
+
expr,
|
|
278
|
+
),
|
|
279
|
+
),
|
|
280
|
+
true,
|
|
281
|
+
),
|
|
282
|
+
]),
|
|
283
|
+
undefined,
|
|
284
|
+
undefined,
|
|
285
|
+
);
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
const decode_boolean = (importer: FunctionImporter) =>
|
|
289
|
+
ts.factory.createCallExpression(
|
|
290
|
+
COALESCE(importer)("boolean"),
|
|
291
|
+
undefined,
|
|
292
|
+
undefined,
|
|
293
|
+
);
|
|
294
|
+
|
|
295
|
+
const decode_atomic = (value: Atomic) =>
|
|
296
|
+
typeof value === "boolean"
|
|
297
|
+
? ts.factory.createIdentifier(value.toString())
|
|
298
|
+
: typeof value === "number"
|
|
299
|
+
? ExpressionFactory.number(value)
|
|
300
|
+
: typeof value === "string"
|
|
301
|
+
? ts.factory.createStringLiteral(value)
|
|
302
|
+
: ExpressionFactory.bigint(Number(value));
|
|
303
|
+
|
|
304
|
+
const decode_template =
|
|
305
|
+
(importer: FunctionImporter) =>
|
|
306
|
+
(explore: IExplore) =>
|
|
307
|
+
(template: Metadata[]) =>
|
|
308
|
+
TemplateFactory.generate(
|
|
309
|
+
template.map((meta) => decode(importer)(explore)(meta)),
|
|
310
|
+
);
|
|
311
|
+
|
|
312
|
+
const decode_number =
|
|
313
|
+
(importer: FunctionImporter) =>
|
|
314
|
+
(atomic: MetadataAtomic): ts.Expression[] =>
|
|
315
|
+
(atomic.tags.length ? atomic.tags : [[]]).map((tags) => {
|
|
316
|
+
const type = tags.find(
|
|
317
|
+
(t) =>
|
|
318
|
+
t.kind === "type" && (t.value === "int32" || t.value === "int64"),
|
|
319
|
+
)
|
|
320
|
+
? "int"
|
|
321
|
+
: tags.find(
|
|
322
|
+
(t) =>
|
|
323
|
+
t.kind === "type" &&
|
|
324
|
+
(t.value === "uint32" || t.value === "uint64"),
|
|
325
|
+
)
|
|
326
|
+
? "uint"
|
|
327
|
+
: "double";
|
|
328
|
+
const multiply = tags.find((t) => t.kind === "multipleOf");
|
|
329
|
+
return random_custom(COALESCE(importer))("number")(tags)(
|
|
330
|
+
RandomRanger.number({
|
|
331
|
+
type,
|
|
332
|
+
transform: (value) => ExpressionFactory.number(value),
|
|
333
|
+
setter: (args) =>
|
|
334
|
+
ts.factory.createCallExpression(
|
|
335
|
+
type !== "double" || multiply !== undefined
|
|
336
|
+
? COALESCE(importer)("integer")
|
|
337
|
+
: COALESCE(importer)("number"),
|
|
338
|
+
undefined,
|
|
339
|
+
args.map((val) => ExpressionFactory.number(val)),
|
|
340
|
+
),
|
|
341
|
+
})({
|
|
342
|
+
minimum: 0,
|
|
343
|
+
maximum: 100,
|
|
344
|
+
gap: 10,
|
|
345
|
+
})(tags),
|
|
346
|
+
);
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
const decode_bigint =
|
|
350
|
+
(importer: FunctionImporter) =>
|
|
351
|
+
(atomic: MetadataAtomic): ts.Expression[] =>
|
|
352
|
+
(atomic.tags.length ? atomic.tags : [[]]).map((tags) =>
|
|
353
|
+
random_custom(COALESCE(importer))("bigint")(tags)(
|
|
354
|
+
RandomRanger.number({
|
|
355
|
+
type: tags.find(
|
|
356
|
+
(t) =>
|
|
357
|
+
t.kind === "type" &&
|
|
358
|
+
(t.value === "uint" || t.value === "uint64"),
|
|
359
|
+
)
|
|
360
|
+
? "uint"
|
|
361
|
+
: "int",
|
|
362
|
+
transform: (value) => ExpressionFactory.bigint(value),
|
|
363
|
+
setter: (args) =>
|
|
364
|
+
ts.factory.createCallExpression(
|
|
365
|
+
COALESCE(importer)("bigint"),
|
|
366
|
+
undefined,
|
|
367
|
+
args.map((value) => ExpressionFactory.bigint(value)),
|
|
368
|
+
),
|
|
369
|
+
})({
|
|
370
|
+
minimum: 0,
|
|
371
|
+
maximum: 100,
|
|
372
|
+
gap: 10,
|
|
373
|
+
})(tags),
|
|
374
|
+
),
|
|
375
|
+
);
|
|
376
|
+
|
|
377
|
+
const decode_string =
|
|
378
|
+
(importer: FunctionImporter) =>
|
|
379
|
+
(atomic: MetadataAtomic): ts.Expression[] =>
|
|
380
|
+
(atomic.tags.length ? atomic.tags : [[]]).map((tags) =>
|
|
381
|
+
random_custom(COALESCE(importer))("string")(tags)(
|
|
382
|
+
(() => {
|
|
383
|
+
for (const t of tags)
|
|
384
|
+
if (t.kind === "format")
|
|
385
|
+
return ts.factory.createCallExpression(
|
|
386
|
+
COALESCE(importer)(
|
|
387
|
+
t.value === "date-time" ? "datetime" : t.value,
|
|
388
|
+
),
|
|
389
|
+
undefined,
|
|
390
|
+
undefined,
|
|
391
|
+
);
|
|
392
|
+
else if (t.kind === "pattern")
|
|
393
|
+
return ts.factory.createCallExpression(
|
|
394
|
+
COALESCE(importer)("pattern"),
|
|
395
|
+
undefined,
|
|
396
|
+
[ts.factory.createIdentifier(`/${t.value}/`)],
|
|
397
|
+
);
|
|
398
|
+
|
|
399
|
+
const tail = RandomRanger.length(COALESCE(importer))({
|
|
400
|
+
minimum: 5,
|
|
401
|
+
maximum: 25,
|
|
402
|
+
gap: 5,
|
|
403
|
+
})({
|
|
404
|
+
minimum: "minLength",
|
|
405
|
+
maximum: "maxLength",
|
|
406
|
+
})(tags);
|
|
407
|
+
return ts.factory.createCallExpression(
|
|
408
|
+
COALESCE(importer)("string"),
|
|
409
|
+
undefined,
|
|
410
|
+
tail ? [tail] : undefined,
|
|
411
|
+
);
|
|
412
|
+
})(),
|
|
413
|
+
),
|
|
414
|
+
);
|
|
415
|
+
|
|
416
|
+
const decode_array =
|
|
417
|
+
(importer: FunctionImporter) =>
|
|
418
|
+
(explore: IExplore) =>
|
|
419
|
+
(array: MetadataArray): ts.Expression[] => {
|
|
420
|
+
const lengths: Array<ts.Expression | undefined> = (
|
|
421
|
+
array.tags.length ? array.tags : [[]]
|
|
422
|
+
).map((tags) =>
|
|
423
|
+
RandomRanger.length(COALESCE(importer))({
|
|
424
|
+
minimum: 0,
|
|
425
|
+
maximum: 3,
|
|
426
|
+
gap: 3,
|
|
427
|
+
})({
|
|
428
|
+
minimum: "minItems",
|
|
429
|
+
maximum: "maxItems",
|
|
430
|
+
})(tags),
|
|
431
|
+
);
|
|
432
|
+
if (array.type.recursive)
|
|
433
|
+
return lengths.map((len) =>
|
|
434
|
+
ts.factory.createCallExpression(
|
|
435
|
+
ts.factory.createIdentifier(
|
|
436
|
+
importer.useLocal(PREFIX.array(array.type.index!)),
|
|
437
|
+
),
|
|
438
|
+
undefined,
|
|
439
|
+
[
|
|
440
|
+
len ?? COALESCE(importer)("length"),
|
|
441
|
+
ts.factory.createTrue(),
|
|
442
|
+
explore.recursive
|
|
443
|
+
? ts.factory.createAdd(
|
|
444
|
+
ExpressionFactory.number(1),
|
|
445
|
+
ts.factory.createIdentifier("_depth"),
|
|
446
|
+
)
|
|
447
|
+
: ExpressionFactory.number(0),
|
|
448
|
+
],
|
|
449
|
+
),
|
|
450
|
+
);
|
|
451
|
+
return lengths.map((len) => {
|
|
452
|
+
const expr: ts.Expression = RandomJoiner.array(COALESCE(importer))(
|
|
453
|
+
decode(importer)(explore),
|
|
454
|
+
)(explore)(len)(array.type.value);
|
|
455
|
+
return explore.recursive
|
|
456
|
+
? ts.factory.createConditionalExpression(
|
|
457
|
+
ts.factory.createLogicalAnd(
|
|
458
|
+
ts.factory.createIdentifier("_recursive"),
|
|
459
|
+
ts.factory.createLessThan(
|
|
460
|
+
ExpressionFactory.number(5),
|
|
461
|
+
ts.factory.createIdentifier("_depth"),
|
|
462
|
+
),
|
|
463
|
+
),
|
|
464
|
+
undefined,
|
|
465
|
+
ts.factory.createIdentifier("[]"),
|
|
466
|
+
undefined,
|
|
467
|
+
expr,
|
|
468
|
+
)
|
|
469
|
+
: expr;
|
|
470
|
+
});
|
|
471
|
+
};
|
|
472
|
+
|
|
473
|
+
const decode_tuple =
|
|
474
|
+
(importer: FunctionImporter) =>
|
|
475
|
+
(explore: IExplore) =>
|
|
476
|
+
(tuple: MetadataTuple): ts.Expression =>
|
|
477
|
+
tuple.type.recursive
|
|
478
|
+
? ts.factory.createCallExpression(
|
|
479
|
+
ts.factory.createIdentifier(
|
|
480
|
+
importer.useLocal(PREFIX.tuple(tuple.type.index!)),
|
|
481
|
+
),
|
|
482
|
+
undefined,
|
|
483
|
+
[
|
|
484
|
+
ts.factory.createTrue(),
|
|
485
|
+
explore.recursive
|
|
486
|
+
? ts.factory.createAdd(
|
|
487
|
+
ExpressionFactory.number(1),
|
|
488
|
+
ts.factory.createIdentifier("_depth"),
|
|
489
|
+
)
|
|
490
|
+
: ExpressionFactory.number(0),
|
|
491
|
+
],
|
|
492
|
+
)
|
|
493
|
+
: RandomJoiner.tuple(decode(importer)(explore))(tuple.type.elements);
|
|
494
|
+
|
|
495
|
+
const decode_object =
|
|
496
|
+
(importer: FunctionImporter) =>
|
|
497
|
+
(explore: IExplore) =>
|
|
498
|
+
(object: MetadataObject) =>
|
|
499
|
+
ts.factory.createCallExpression(
|
|
500
|
+
ts.factory.createIdentifier(
|
|
501
|
+
importer.useLocal(PREFIX.object(object.index)),
|
|
502
|
+
),
|
|
503
|
+
undefined,
|
|
504
|
+
explore.function
|
|
505
|
+
? [
|
|
506
|
+
explore.recursive
|
|
507
|
+
? ts.factory.createTrue()
|
|
508
|
+
: ts.factory.createIdentifier("_recursive"),
|
|
509
|
+
ts.factory.createConditionalExpression(
|
|
510
|
+
ts.factory.createIdentifier("_recursive"),
|
|
511
|
+
undefined,
|
|
512
|
+
ts.factory.createAdd(
|
|
513
|
+
ExpressionFactory.number(1),
|
|
514
|
+
ts.factory.createIdentifier("_depth"),
|
|
515
|
+
),
|
|
516
|
+
undefined,
|
|
517
|
+
ts.factory.createIdentifier("_depth"),
|
|
518
|
+
),
|
|
519
|
+
]
|
|
520
|
+
: undefined,
|
|
521
|
+
);
|
|
522
|
+
|
|
523
|
+
/* -----------------------------------------------------------
|
|
524
|
+
NATIVE CLASSES
|
|
525
|
+
----------------------------------------------------------- */
|
|
526
|
+
const decode_set =
|
|
527
|
+
(importer: FunctionImporter) => (explore: IExplore) => (meta: Metadata) =>
|
|
528
|
+
ts.factory.createNewExpression(
|
|
529
|
+
ts.factory.createIdentifier("Set"),
|
|
530
|
+
undefined,
|
|
531
|
+
[
|
|
532
|
+
decode_array(importer)(explore)(
|
|
533
|
+
MetadataArray.create({
|
|
534
|
+
tags: [],
|
|
535
|
+
type: MetadataArrayType.create({
|
|
536
|
+
value: meta,
|
|
537
|
+
recursive: false,
|
|
538
|
+
index: null,
|
|
539
|
+
nullables: [],
|
|
540
|
+
name: `Set<${meta.getName()}>`,
|
|
541
|
+
}),
|
|
542
|
+
}),
|
|
543
|
+
)[0]!,
|
|
544
|
+
],
|
|
545
|
+
);
|
|
546
|
+
|
|
547
|
+
const decode_map =
|
|
548
|
+
(importer: FunctionImporter) =>
|
|
549
|
+
(explore: IExplore) =>
|
|
550
|
+
(map: Metadata.Entry) =>
|
|
551
|
+
ts.factory.createNewExpression(
|
|
552
|
+
ts.factory.createIdentifier("Map"),
|
|
553
|
+
undefined,
|
|
554
|
+
[
|
|
555
|
+
decode_array(importer)(explore)(
|
|
556
|
+
MetadataArray.create({
|
|
557
|
+
tags: [],
|
|
558
|
+
type: MetadataArrayType.create({
|
|
559
|
+
name: `Map<${map.key.getName()}, ${map.value.getName()}>`,
|
|
560
|
+
index: null,
|
|
561
|
+
recursive: false,
|
|
562
|
+
nullables: [],
|
|
563
|
+
value: Metadata.create({
|
|
564
|
+
...Metadata.initialize(),
|
|
565
|
+
tuples: [
|
|
566
|
+
(() => {
|
|
567
|
+
const type = MetadataTupleType.create({
|
|
568
|
+
name: `[${map.key.getName()}, ${map.value.getName()}]`,
|
|
569
|
+
index: null,
|
|
570
|
+
recursive: false,
|
|
571
|
+
nullables: [],
|
|
572
|
+
elements: [map.key, map.value],
|
|
573
|
+
});
|
|
574
|
+
type.of_map = true;
|
|
575
|
+
return MetadataTuple.create({
|
|
576
|
+
type,
|
|
577
|
+
tags: [],
|
|
578
|
+
});
|
|
579
|
+
})(),
|
|
580
|
+
],
|
|
581
|
+
}),
|
|
582
|
+
}),
|
|
583
|
+
}),
|
|
584
|
+
)[0]!,
|
|
585
|
+
],
|
|
586
|
+
);
|
|
587
|
+
|
|
588
|
+
const decode_native =
|
|
589
|
+
(importer: FunctionImporter) =>
|
|
590
|
+
(type: string): ts.Expression => {
|
|
591
|
+
if (type === "Boolean") return decode_boolean(importer);
|
|
592
|
+
else if (type === "Number")
|
|
593
|
+
return decode_number(importer)(
|
|
594
|
+
MetadataAtomic.create({
|
|
595
|
+
type: "number",
|
|
596
|
+
tags: [],
|
|
597
|
+
}),
|
|
598
|
+
)[0]!;
|
|
599
|
+
else if (type === "String")
|
|
600
|
+
return decode_string(importer)(
|
|
601
|
+
MetadataAtomic.create({
|
|
602
|
+
type: "string",
|
|
603
|
+
tags: [],
|
|
604
|
+
}),
|
|
605
|
+
)[0]!;
|
|
606
|
+
else if (type === "Date") return decode_native_date(importer);
|
|
607
|
+
else if (
|
|
608
|
+
type === "Uint8Array" ||
|
|
609
|
+
type === "Uint8ClampedArray" ||
|
|
610
|
+
type === "Uint16Array" ||
|
|
611
|
+
type === "Uint32Array" ||
|
|
612
|
+
type === "BigUint64Array" ||
|
|
613
|
+
type === "Int8Array" ||
|
|
614
|
+
type === "Int16Array" ||
|
|
615
|
+
type === "Int32Array" ||
|
|
616
|
+
type === "BigInt64Array" ||
|
|
617
|
+
type === "Float32Array" ||
|
|
618
|
+
type === "Float64Array"
|
|
619
|
+
)
|
|
620
|
+
return decode_native_byte_array(importer)(type);
|
|
621
|
+
else if (type === "ArrayBuffer" || type === "SharedArrayBuffer")
|
|
622
|
+
return decode_native_array_buffer(importer)(type);
|
|
623
|
+
else if (type === "DataView") return decode_native_data_view(importer);
|
|
624
|
+
else
|
|
625
|
+
return ts.factory.createNewExpression(
|
|
626
|
+
ts.factory.createIdentifier(type),
|
|
627
|
+
undefined,
|
|
628
|
+
[],
|
|
629
|
+
);
|
|
630
|
+
};
|
|
631
|
+
|
|
632
|
+
const decode_native_date = (importer: FunctionImporter) =>
|
|
633
|
+
ts.factory.createNewExpression(
|
|
634
|
+
ts.factory.createIdentifier("Date"),
|
|
635
|
+
undefined,
|
|
636
|
+
[
|
|
637
|
+
ts.factory.createCallExpression(
|
|
638
|
+
COALESCE(importer)("datetime"),
|
|
639
|
+
undefined,
|
|
640
|
+
[],
|
|
641
|
+
),
|
|
642
|
+
],
|
|
643
|
+
);
|
|
644
|
+
|
|
645
|
+
const decode_native_byte_array =
|
|
646
|
+
(importer: FunctionImporter) =>
|
|
647
|
+
(
|
|
648
|
+
type:
|
|
649
|
+
| "Uint8Array"
|
|
650
|
+
| "Uint8ClampedArray"
|
|
651
|
+
| "Uint16Array"
|
|
652
|
+
| "Uint32Array"
|
|
653
|
+
| "BigUint64Array"
|
|
654
|
+
| "Int8Array"
|
|
655
|
+
| "Int16Array"
|
|
656
|
+
| "Int32Array"
|
|
657
|
+
| "BigInt64Array"
|
|
658
|
+
| "Float32Array"
|
|
659
|
+
| "Float64Array",
|
|
660
|
+
): ts.Expression => {
|
|
661
|
+
new BigInt64Array();
|
|
662
|
+
const [minimum, maximum]: [number, number] = (() => {
|
|
663
|
+
if (type === "Uint8Array" || type === "Uint8ClampedArray")
|
|
664
|
+
return [0, 255];
|
|
665
|
+
else if (type === "Uint16Array") return [0, 65535];
|
|
666
|
+
else if (type === "Uint32Array") return [0, 4294967295];
|
|
667
|
+
else if (type === "BigUint64Array") return [0, 18446744073709551615];
|
|
668
|
+
else if (type === "Int8Array") return [-128, 127];
|
|
669
|
+
else if (type === "Int16Array") return [-32768, 32767];
|
|
670
|
+
else if (type === "Int32Array") return [-2147483648, 2147483647];
|
|
671
|
+
else if (type === "BigInt64Array")
|
|
672
|
+
return [-9223372036854775808, 9223372036854775807];
|
|
673
|
+
else if (type === "Float32Array")
|
|
674
|
+
return [-1.175494351e38, 3.4028235e38];
|
|
675
|
+
return [Number.MIN_VALUE, Number.MAX_VALUE];
|
|
676
|
+
})();
|
|
677
|
+
const literal =
|
|
678
|
+
type === "BigInt64Array" || type === "BigUint64Array"
|
|
679
|
+
? ExpressionFactory.bigint
|
|
680
|
+
: ExpressionFactory.number;
|
|
681
|
+
return ts.factory.createNewExpression(
|
|
682
|
+
ts.factory.createIdentifier(type),
|
|
683
|
+
[],
|
|
684
|
+
[
|
|
685
|
+
ts.factory.createCallExpression(
|
|
686
|
+
COALESCE(importer)("array"),
|
|
687
|
+
undefined,
|
|
688
|
+
[
|
|
689
|
+
ts.factory.createArrowFunction(
|
|
690
|
+
undefined,
|
|
691
|
+
undefined,
|
|
692
|
+
[],
|
|
693
|
+
TypeFactory.keyword("any"),
|
|
694
|
+
undefined,
|
|
695
|
+
ts.factory.createCallExpression(
|
|
696
|
+
COALESCE(importer)(
|
|
697
|
+
type === "Float32Array" || type === "Float64Array"
|
|
698
|
+
? "number"
|
|
699
|
+
: type === "BigInt64Array" || type === "BigUint64Array"
|
|
700
|
+
? "bigint"
|
|
701
|
+
: "integer",
|
|
702
|
+
),
|
|
703
|
+
undefined,
|
|
704
|
+
[literal(minimum), literal(maximum)],
|
|
705
|
+
),
|
|
706
|
+
),
|
|
707
|
+
],
|
|
708
|
+
),
|
|
709
|
+
],
|
|
710
|
+
);
|
|
711
|
+
};
|
|
712
|
+
|
|
713
|
+
const decode_native_array_buffer =
|
|
714
|
+
(importer: FunctionImporter) =>
|
|
715
|
+
(type: "ArrayBuffer" | "SharedArrayBuffer"): ts.Expression =>
|
|
716
|
+
type === "ArrayBuffer"
|
|
717
|
+
? IdentifierFactory.access(
|
|
718
|
+
decode_native_byte_array(importer)("Uint8Array"),
|
|
719
|
+
)("buffer")
|
|
720
|
+
: ExpressionFactory.selfCall(
|
|
721
|
+
ts.factory.createBlock(
|
|
722
|
+
[
|
|
723
|
+
StatementFactory.constant(
|
|
724
|
+
"length",
|
|
725
|
+
ts.factory.createCallExpression(
|
|
726
|
+
COALESCE(importer)("integer"),
|
|
727
|
+
undefined,
|
|
728
|
+
[],
|
|
729
|
+
),
|
|
730
|
+
),
|
|
731
|
+
StatementFactory.constant(
|
|
732
|
+
"buffer",
|
|
733
|
+
ts.factory.createNewExpression(
|
|
734
|
+
ts.factory.createIdentifier("SharedArrayBuffer"),
|
|
735
|
+
[],
|
|
736
|
+
[ts.factory.createIdentifier("length")],
|
|
737
|
+
),
|
|
738
|
+
),
|
|
739
|
+
StatementFactory.constant(
|
|
740
|
+
"bytes",
|
|
741
|
+
ts.factory.createNewExpression(
|
|
742
|
+
ts.factory.createIdentifier("Uint8Array"),
|
|
743
|
+
[],
|
|
744
|
+
[ts.factory.createIdentifier("buffer")],
|
|
745
|
+
),
|
|
746
|
+
),
|
|
747
|
+
ts.factory.createExpressionStatement(
|
|
748
|
+
ts.factory.createCallExpression(
|
|
749
|
+
IdentifierFactory.access(
|
|
750
|
+
ts.factory.createIdentifier("bytes"),
|
|
751
|
+
)("set"),
|
|
752
|
+
undefined,
|
|
753
|
+
[
|
|
754
|
+
ts.factory.createCallExpression(
|
|
755
|
+
COALESCE(importer)("array"),
|
|
756
|
+
undefined,
|
|
757
|
+
[
|
|
758
|
+
ts.factory.createArrowFunction(
|
|
759
|
+
undefined,
|
|
760
|
+
undefined,
|
|
761
|
+
[],
|
|
762
|
+
TypeFactory.keyword("any"),
|
|
763
|
+
undefined,
|
|
764
|
+
ts.factory.createCallExpression(
|
|
765
|
+
COALESCE(importer)("integer"),
|
|
766
|
+
undefined,
|
|
767
|
+
[
|
|
768
|
+
ExpressionFactory.number(0),
|
|
769
|
+
ExpressionFactory.number(255),
|
|
770
|
+
],
|
|
771
|
+
),
|
|
772
|
+
),
|
|
773
|
+
ts.factory.createIdentifier("length"),
|
|
774
|
+
],
|
|
775
|
+
),
|
|
776
|
+
ExpressionFactory.number(0),
|
|
777
|
+
],
|
|
778
|
+
),
|
|
779
|
+
),
|
|
780
|
+
ts.factory.createReturnStatement(
|
|
781
|
+
ts.factory.createIdentifier("buffer"),
|
|
782
|
+
),
|
|
783
|
+
],
|
|
784
|
+
true,
|
|
785
|
+
),
|
|
786
|
+
);
|
|
787
|
+
|
|
788
|
+
const decode_native_data_view = (importer: FunctionImporter) =>
|
|
789
|
+
ts.factory.createNewExpression(
|
|
790
|
+
ts.factory.createIdentifier("DataView"),
|
|
791
|
+
[],
|
|
792
|
+
[
|
|
793
|
+
IdentifierFactory.access(
|
|
794
|
+
decode_native_byte_array(importer)("Uint8Array"),
|
|
795
|
+
)("buffer"),
|
|
796
|
+
],
|
|
797
|
+
);
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
type Atomic = boolean | number | string | bigint;
|
|
801
|
+
interface IExplore {
|
|
802
|
+
function: boolean;
|
|
803
|
+
recursive: boolean;
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
const PREFIX = {
|
|
807
|
+
object: (i: number) => `$ro${i}`,
|
|
808
|
+
array: (i: number) => `$ra${i}`,
|
|
809
|
+
tuple: (i: number) => `$rt${i}`,
|
|
810
|
+
};
|
|
811
|
+
|
|
812
|
+
const COALESCE = (importer: FunctionImporter) => (name: string) =>
|
|
813
|
+
ExpressionFactory.coalesce(
|
|
814
|
+
Escaper.variable(name)
|
|
815
|
+
? ts.factory.createPropertyAccessChain(
|
|
816
|
+
ts.factory.createIdentifier("generator"),
|
|
817
|
+
ts.factory.createToken(ts.SyntaxKind.QuestionDotToken),
|
|
818
|
+
ts.factory.createIdentifier(name),
|
|
819
|
+
)
|
|
820
|
+
: ts.factory.createElementAccessChain(
|
|
821
|
+
ts.factory.createIdentifier("generator"),
|
|
822
|
+
ts.factory.createToken(ts.SyntaxKind.QuestionDotToken),
|
|
823
|
+
ts.factory.createStringLiteral(name),
|
|
824
|
+
),
|
|
825
|
+
)(IdentifierFactory.access(importer.use("generator"))(name));
|