From c15a838569a691cef180cc2883206bf040884e5c Mon Sep 17 00:00:00 2001 From: Kevin Greene Date: Wed, 10 Apr 2019 16:22:48 -0700 Subject: [PATCH] feat: Split files by type --- README.md | 10 +- package-lock.json | 509 +-- package.json | 2 +- src/main/{debugger.ts => debugger/index.ts} | 17 +- src/main/errors.ts | 35 + src/main/generator/index.ts | 192 +- src/main/generator/utils.ts | 80 - src/main/index.ts | 217 +- src/main/parser/index.ts | 62 + src/main/printer.ts | 5 +- src/main/reader/index.ts | 23 + src/main/render/apache/const.ts | 6 +- src/main/render/apache/exception.ts | 7 +- src/main/render/apache/includes.ts | 74 - src/main/render/apache/index.ts | 76 +- src/main/render/apache/interface.ts | 4 +- src/main/render/apache/service/client.ts | 33 +- src/main/render/apache/service/index.ts | 14 +- src/main/render/apache/service/processor.ts | 92 +- src/main/render/apache/struct/create.ts | 27 +- src/main/render/apache/struct/read.ts | 109 +- src/main/render/apache/struct/write.ts | 96 +- src/main/render/{shared => apache}/typedef.ts | 11 +- src/main/render/apache/types.ts | 48 +- src/main/render/apache/union.ts | 38 +- src/main/render/apache/values.ts | 34 +- src/main/render/index.ts | 6 +- src/main/render/shared/identifiers.ts | 2 + src/main/render/shared/includes.ts | 113 +- src/main/render/shared/index.ts | 77 + src/main/render/shared/service/index.ts | 11 +- src/main/render/shared/types.ts | 19 +- src/main/render/thrift-server/const.ts | 6 +- src/main/render/thrift-server/includes.ts | 93 - src/main/render/thrift-server/index.ts | 58 +- src/main/render/thrift-server/initializers.ts | 34 +- .../render/thrift-server/service/client.ts | 8 +- .../render/thrift-server/service/index.ts | 40 +- .../render/thrift-server/service/processor.ts | 41 +- .../render/thrift-server/service/utils.ts | 40 +- src/main/render/thrift-server/struct/class.ts | 24 +- .../render/thrift-server/struct/decode.ts | 49 +- .../render/thrift-server/struct/encode.ts | 72 +- .../render/thrift-server/struct/interface.ts | 4 +- .../render/thrift-server/struct/reader.ts | 36 +- .../render/thrift-server/struct/toolkit.ts | 6 +- src/main/render/thrift-server/struct/utils.ts | 53 +- src/main/render/thrift-server/typedef.ts | 366 +- src/main/render/thrift-server/types.ts | 60 +- src/main/render/thrift-server/union/class.ts | 6 +- src/main/render/thrift-server/union/create.ts | 21 +- src/main/render/thrift-server/union/decode.ts | 9 +- src/main/render/thrift-server/union/encode.ts | 4 +- .../render/thrift-server/union/toolkit.ts | 2 +- .../thrift-server/union/union-fields.ts | 20 +- src/main/render/thrift-server/utils.ts | 4 +- src/main/resolver/index.ts | 786 ++-- src/main/resolver/utils.ts | 483 +- src/main/types.ts | 354 +- src/main/utils.ts | 493 ++- src/main/validator/index.ts | 747 +--- .../integration/thrift/calculator.thrift | 2 +- src/tests/unit/bin.spec.ts | 45 - .../fixtures/apache/basic_enum.solution.ts | 6 +- .../fixtures/apache/basic_service.solution.ts | 328 +- .../apache/complex_typedef.solution.ts | 4 +- .../fixtures/apache/enum_typedef.solution.ts | 4 +- .../apache/extend_service.solution.ts | 471 -- .../com/test/calculator/Calculator.ts | 2826 ++++++++++++ .../generated/com/test/calculator/Choice.ts | 108 + .../com/test/calculator/FirstName.ts | 57 + .../generated/com/test/calculator/LastName.ts | 57 + .../com/test/calculator/NotAGoodIdea.ts | 57 + .../generated/com/test/calculator/Work.ts | 126 + .../com/test/calculator/constants.ts | 7 + .../generated/com/test/calculator/index.ts | 14 + .../generated/com/test/calculator/typedefs.ts | 10 + .../com/test/common/AuthException.ts | 76 + .../com/test/common/OtherCommonUnion.ts | 107 + .../apache/generated/com/test/common/index.ts | 8 + .../generated/com/test/common/typedefs.ts | 12 + .../com/test/exceptions/InvalidOperation.ts | 76 + .../com/test/exceptions/InvalidResult.ts | 77 + .../generated/com/test/exceptions/index.ts | 7 + .../generated/com/test/operation/constants.ts | 11 + .../generated/com/test/operation/index.ts | 7 + .../generated/com/test/operation/typedefs.ts | 10 + .../apache/generated/com/test/shared/Code.ts | 63 + .../com/test/shared/SharedService.ts | 421 ++ .../generated/com/test/shared/SharedStruct.ts | 88 + .../generated/com/test/shared/SharedUnion.ts | 107 + .../generated/com/test/shared/constants.ts | 6 + .../apache/generated/com/test/shared/index.ts | 11 + .../fixtures/apache/i64_service.solution.ts | 452 +- .../apache/return_service.solution.ts | 452 +- .../apache/throws_multi_service.solution.ts | 572 ++- .../apache/throws_service.solution.ts | 386 +- .../fixtures/generated/calculator/index.ts | 3890 ---------------- .../fixtures/generated/exceptions/index.ts | 201 - .../fixtures/generated/operation/index.ts | 21 - .../unit/fixtures/generated/shared/index.ts | 836 ---- .../strict-unions/calculator/index.ts | 3919 ----------------- .../strict-unions/operation/index.ts | 21 - .../generated/strict-unions/shared/index.ts | 865 ---- .../import-identifiers-types.solution.json | 787 ---- .../import-identifiers-values.solution.json | 715 --- .../resolver/imported-id-types.solution.json | 791 ---- .../resolver/imported-id-values.solution.json | 719 --- .../annotations_extend_service.solution.ts | 821 ---- .../annotations_service.solution.ts | 1212 +++-- .../thrift-server/basic_service.solution.ts | 1202 +++-- .../basic_service.strict_union.solution.ts | 818 ++-- .../thrift-server/basic_struct.solution.ts | 177 + .../thrift-server/basic_typedef.solution.ts | 2 + .../thrift-server/basic_union.solution.ts | 48 +- .../basic_union.strict_union.solution.ts | 8 +- .../thrift-server/complex_typedef.solution.ts | 260 ++ .../complex_typedef.strict_union.solution.ts | 163 + .../thrift-server/extend_service.solution.ts | 803 ---- .../com/test/calculator/Calculator.ts | 3482 +++++++++++++++ .../com/test/calculator/Choice.ts | 162 + .../com/test/calculator/FirstName.ts | 80 + .../com/test/calculator/LastName.ts | 80 + .../com/test/calculator/NotAGoodIdea.ts | 80 + .../com/test/calculator/Work.ts | 161 + .../com/test/calculator/constants.ts | 7 + .../com/test/calculator/index.ts | 14 + .../com/test/calculator/typedefs.ts | 13 + .../com/test/common/AuthException.ts} | 16 +- .../com/test/common/OtherCommonUnion.ts | 161 + .../generated-strict/com/test/common/index.ts | 8 + .../com/test/common/typedefs.ts | 32 + .../com/test/exceptions/InvalidOperation.ts | 103 + .../com/test/exceptions/InvalidResult.ts | 104 + .../com/test/exceptions/index.ts | 7 + .../com/test/operation/constants.ts | 11 + .../com/test/operation/index.ts | 7 + .../com/test/operation/typedefs.ts | 16 + .../generated-strict/com/test/shared/Code.ts | 80 + .../com/test/shared/SharedService.ts | 520 +++ .../com/test/shared/SharedStruct.ts | 121 + .../com/test/shared/SharedUnion.ts | 161 + .../com/test/shared/constants.ts | 6 + .../generated-strict/com/test/shared/index.ts | 11 + .../com/test/calculator/Calculator.ts | 3482 +++++++++++++++ .../generated/com/test/calculator/Choice.ts | 133 + .../com/test/calculator/FirstName.ts | 80 + .../generated/com/test/calculator/LastName.ts | 80 + .../com/test/calculator/NotAGoodIdea.ts | 80 + .../generated/com/test/calculator/Work.ts | 161 + .../com/test/calculator/constants.ts | 7 + .../generated/com/test/calculator/index.ts | 14 + .../generated/com/test/calculator/typedefs.ts | 13 + .../com/test/common/AuthException.ts} | 10 - .../com/test/common/OtherCommonUnion.ts | 132 + .../generated/com/test/common/index.ts | 8 + .../generated/com/test/common/typedefs.ts | 24 + .../com/test/exceptions/InvalidOperation.ts} | 98 - .../com/test/exceptions/InvalidResult.ts | 104 + .../generated/com/test/exceptions/index.ts | 7 + .../generated/com/test/operation/constants.ts | 11 + .../generated/com/test/operation/index.ts | 7 + .../generated/com/test/operation/typedefs.ts | 16 + .../generated/com/test/shared/Code.ts | 80 + .../com/test/shared/SharedService.ts | 520 +++ .../generated/com/test/shared/SharedStruct.ts | 121 + .../generated/com/test/shared/SharedUnion.ts | 132 + .../generated/com/test/shared/constants.ts | 6 + .../generated/com/test/shared/index.ts | 11 + .../thrift-server/i64_service.solution.ts | 884 ++-- .../nested_union.strict_union.solution.ts | 16 +- .../resolved_field_service.solution.ts | 270 ++ .../throws_multi_service.solution.ts | 684 ++- .../thrift-server/throws_service.solution.ts | 936 ++-- .../unit/fixtures/thrift/calculator.thrift | 24 +- src/tests/unit/fixtures/thrift/common.thrift | 24 +- .../unit/fixtures/thrift/exceptions.thrift | 16 +- .../unit/fixtures/thrift/operation.thrift | 4 +- src/tests/unit/fixtures/thrift/shared.thrift | 16 +- .../validator/include-types.solution.json | 719 --- .../validator/missing-field-ids.solution.json | 318 -- .../validator/missing-ids.solution.json | 319 -- src/tests/unit/index.spec.ts | 484 +- src/tests/unit/resolver.spec.ts | 107 - src/tests/unit/utils.spec.ts | 19 + src/tests/unit/validator.spec.ts | 811 ---- 186 files changed, 23381 insertions(+), 24368 deletions(-) rename src/main/{debugger.ts => debugger/index.ts} (81%) create mode 100644 src/main/errors.ts delete mode 100644 src/main/generator/utils.ts create mode 100644 src/main/parser/index.ts create mode 100644 src/main/reader/index.ts rename src/main/render/{shared => apache}/typedef.ts (75%) create mode 100644 src/main/render/shared/index.ts delete mode 100644 src/main/render/thrift-server/includes.ts delete mode 100644 src/tests/unit/bin.spec.ts delete mode 100644 src/tests/unit/fixtures/apache/extend_service.solution.ts create mode 100644 src/tests/unit/fixtures/apache/generated/com/test/calculator/Calculator.ts create mode 100644 src/tests/unit/fixtures/apache/generated/com/test/calculator/Choice.ts create mode 100644 src/tests/unit/fixtures/apache/generated/com/test/calculator/FirstName.ts create mode 100644 src/tests/unit/fixtures/apache/generated/com/test/calculator/LastName.ts create mode 100644 src/tests/unit/fixtures/apache/generated/com/test/calculator/NotAGoodIdea.ts create mode 100644 src/tests/unit/fixtures/apache/generated/com/test/calculator/Work.ts create mode 100644 src/tests/unit/fixtures/apache/generated/com/test/calculator/constants.ts create mode 100644 src/tests/unit/fixtures/apache/generated/com/test/calculator/index.ts create mode 100644 src/tests/unit/fixtures/apache/generated/com/test/calculator/typedefs.ts create mode 100644 src/tests/unit/fixtures/apache/generated/com/test/common/AuthException.ts create mode 100644 src/tests/unit/fixtures/apache/generated/com/test/common/OtherCommonUnion.ts create mode 100644 src/tests/unit/fixtures/apache/generated/com/test/common/index.ts create mode 100644 src/tests/unit/fixtures/apache/generated/com/test/common/typedefs.ts create mode 100644 src/tests/unit/fixtures/apache/generated/com/test/exceptions/InvalidOperation.ts create mode 100644 src/tests/unit/fixtures/apache/generated/com/test/exceptions/InvalidResult.ts create mode 100644 src/tests/unit/fixtures/apache/generated/com/test/exceptions/index.ts create mode 100644 src/tests/unit/fixtures/apache/generated/com/test/operation/constants.ts create mode 100644 src/tests/unit/fixtures/apache/generated/com/test/operation/index.ts create mode 100644 src/tests/unit/fixtures/apache/generated/com/test/operation/typedefs.ts create mode 100644 src/tests/unit/fixtures/apache/generated/com/test/shared/Code.ts create mode 100644 src/tests/unit/fixtures/apache/generated/com/test/shared/SharedService.ts create mode 100644 src/tests/unit/fixtures/apache/generated/com/test/shared/SharedStruct.ts create mode 100644 src/tests/unit/fixtures/apache/generated/com/test/shared/SharedUnion.ts create mode 100644 src/tests/unit/fixtures/apache/generated/com/test/shared/constants.ts create mode 100644 src/tests/unit/fixtures/apache/generated/com/test/shared/index.ts delete mode 100644 src/tests/unit/fixtures/generated/calculator/index.ts delete mode 100644 src/tests/unit/fixtures/generated/exceptions/index.ts delete mode 100644 src/tests/unit/fixtures/generated/operation/index.ts delete mode 100644 src/tests/unit/fixtures/generated/shared/index.ts delete mode 100644 src/tests/unit/fixtures/generated/strict-unions/calculator/index.ts delete mode 100644 src/tests/unit/fixtures/generated/strict-unions/operation/index.ts delete mode 100644 src/tests/unit/fixtures/generated/strict-unions/shared/index.ts delete mode 100644 src/tests/unit/fixtures/resolver/import-identifiers-types.solution.json delete mode 100644 src/tests/unit/fixtures/resolver/import-identifiers-values.solution.json delete mode 100644 src/tests/unit/fixtures/resolver/imported-id-types.solution.json delete mode 100644 src/tests/unit/fixtures/resolver/imported-id-values.solution.json delete mode 100644 src/tests/unit/fixtures/thrift-server/annotations_extend_service.solution.ts create mode 100644 src/tests/unit/fixtures/thrift-server/basic_struct.solution.ts create mode 100644 src/tests/unit/fixtures/thrift-server/basic_typedef.solution.ts create mode 100644 src/tests/unit/fixtures/thrift-server/complex_typedef.solution.ts create mode 100644 src/tests/unit/fixtures/thrift-server/complex_typedef.strict_union.solution.ts delete mode 100644 src/tests/unit/fixtures/thrift-server/extend_service.solution.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/Calculator.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/Choice.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/FirstName.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/LastName.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/NotAGoodIdea.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/Work.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/constants.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/index.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/typedefs.ts rename src/tests/unit/fixtures/{generated/strict-unions/common/index.ts => thrift-server/generated-strict/com/test/common/AuthException.ts} (79%) create mode 100644 src/tests/unit/fixtures/thrift-server/generated-strict/com/test/common/OtherCommonUnion.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated-strict/com/test/common/index.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated-strict/com/test/common/typedefs.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated-strict/com/test/exceptions/InvalidOperation.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated-strict/com/test/exceptions/InvalidResult.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated-strict/com/test/exceptions/index.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated-strict/com/test/operation/constants.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated-strict/com/test/operation/index.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated-strict/com/test/operation/typedefs.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated-strict/com/test/shared/Code.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated-strict/com/test/shared/SharedService.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated-strict/com/test/shared/SharedStruct.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated-strict/com/test/shared/SharedUnion.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated-strict/com/test/shared/constants.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated-strict/com/test/shared/index.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/Calculator.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/Choice.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/FirstName.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/LastName.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/NotAGoodIdea.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/Work.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/constants.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/index.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/typedefs.ts rename src/tests/unit/fixtures/{generated/common/index.ts => thrift-server/generated/com/test/common/AuthException.ts} (87%) create mode 100644 src/tests/unit/fixtures/thrift-server/generated/com/test/common/OtherCommonUnion.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated/com/test/common/index.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated/com/test/common/typedefs.ts rename src/tests/unit/fixtures/{generated/strict-unions/exceptions/index.ts => thrift-server/generated/com/test/exceptions/InvalidOperation.ts} (50%) create mode 100644 src/tests/unit/fixtures/thrift-server/generated/com/test/exceptions/InvalidResult.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated/com/test/exceptions/index.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated/com/test/operation/constants.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated/com/test/operation/index.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated/com/test/operation/typedefs.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated/com/test/shared/Code.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated/com/test/shared/SharedService.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated/com/test/shared/SharedStruct.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated/com/test/shared/SharedUnion.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated/com/test/shared/constants.ts create mode 100644 src/tests/unit/fixtures/thrift-server/generated/com/test/shared/index.ts create mode 100644 src/tests/unit/fixtures/thrift-server/resolved_field_service.solution.ts delete mode 100644 src/tests/unit/fixtures/validator/include-types.solution.json delete mode 100644 src/tests/unit/fixtures/validator/missing-field-ids.solution.json delete mode 100644 src/tests/unit/fixtures/validator/missing-ids.solution.json delete mode 100644 src/tests/unit/resolver.spec.ts create mode 100644 src/tests/unit/utils.spec.ts delete mode 100644 src/tests/unit/validator.spec.ts diff --git a/README.md b/README.md index b8c99dc9..32b52cf7 100644 --- a/README.md +++ b/README.md @@ -486,20 +486,20 @@ type MyUnion = IMyUnionWithOption1 | IMyUnionWithOption2 interface IMyUnionWithOption1 { __type: MyUnionType.MyUnionWithOption1 option1: string - option2?: void + option2?: undefined } interface IMyUnionWithOption2 { __type: MyUnionType.MyUnionWithOption2 - option1?: void + option1?: undefined option2: number } type MyUnionArgs = IMyUnionWithOption1Args | IMyUnionWithOption2Args interface IMyUnionWithOption1Args { option1: string - option2?: void + option2?: undefined } interface IMyUnionWithOption2Args { - option1?: void + option1?: undefined option2: number } ``` @@ -524,7 +524,7 @@ function processUnion(union: MyUnion) { } ``` -The fact that each interface we generate defines one required field and some n number of optional `void` fields we can do things like check `union.option2 !== undefined` without a compiler error, but we will get a compiler error if you try to use a value that shouldn't exist on a given union. This expands the ways you can operate on unions to be more general. +The fact that each interface we generate defines one required field and some n number of optional `undefined` fields we can do things like check `union.option2 !== undefined` without a compiler error, but we will get a compiler error if you try to use a value that shouldn't exist on a given union. This expands the ways you can operate on unions to be more general. Using this form will require that you prove to the compiler that one (and only one) field is set for your unions. diff --git a/package-lock.json b/package-lock.json index 68523802..2100bb26 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,12 +14,12 @@ } }, "@babel/generator": { - "version": "7.3.4", - "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.3.4.tgz", - "integrity": "sha512-8EXhHRFqlVVWXPezBW5keTiQi/rJMQTg/Y9uVCEZ0CAF3PKtCCaVRnp64Ii1ujhkoDhhF1fVsImoN4yJ2uz4Wg==", + "version": "7.4.0", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.4.0.tgz", + "integrity": "sha512-/v5I+a1jhGSKLgZDcmAUZ4K/VePi43eRkUs3yePW1HB1iANOD5tqJXwGSG4BZhSksP8J9ejSlwGeTiiOFZOrXQ==", "dev": true, "requires": { - "@babel/types": "^7.3.4", + "@babel/types": "^7.4.0", "jsesc": "^2.5.1", "lodash": "^4.17.11", "source-map": "^0.5.0", @@ -47,12 +47,12 @@ } }, "@babel/helper-split-export-declaration": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.0.0.tgz", - "integrity": "sha512-MXkOJqva62dfC0w85mEf/LucPPS/1+04nmmRMPEBUB++hiiThQ2zPtX/mEWQ3mtzCEjIJvPY8nuwxXtQeQwUag==", + "version": "7.4.0", + "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.4.0.tgz", + "integrity": "sha512-7Cuc6JZiYShaZnybDmfwhY4UYHzI6rlqhWjaIqbsJGsIqPimEYy5uh3akSRLMg65LSdSEnJ8a8/bWQN6u2oMGw==", "dev": true, "requires": { - "@babel/types": "^7.0.0" + "@babel/types": "^7.4.0" } }, "@babel/highlight": { @@ -67,34 +67,34 @@ } }, "@babel/parser": { - "version": "7.3.4", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.3.4.tgz", - "integrity": "sha512-tXZCqWtlOOP4wgCp6RjRvLmfuhnqTLy9VHwRochJBCP2nDm27JnnuFEnXFASVyQNHk36jD1tAammsCEEqgscIQ==", + "version": "7.4.3", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.4.3.tgz", + "integrity": "sha512-gxpEUhTS1sGA63EGQGuA+WESPR/6tz6ng7tSHFCmaTJK/cGK8y37cBTspX+U2xCAue2IQVvF6Z0oigmjwD8YGQ==", "dev": true }, "@babel/template": { - "version": "7.2.2", - "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.2.2.tgz", - "integrity": "sha512-zRL0IMM02AUDwghf5LMSSDEz7sBCO2YnNmpg3uWTZj/v1rcG2BmQUvaGU8GhU8BvfMh1k2KIAYZ7Ji9KXPUg7g==", + "version": "7.4.0", + "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.4.0.tgz", + "integrity": "sha512-SOWwxxClTTh5NdbbYZ0BmaBVzxzTh2tO/TeLTbF6MO6EzVhHTnff8CdBXx3mEtazFBoysmEM6GU/wF+SuSx4Fw==", "dev": true, "requires": { "@babel/code-frame": "^7.0.0", - "@babel/parser": "^7.2.2", - "@babel/types": "^7.2.2" + "@babel/parser": "^7.4.0", + "@babel/types": "^7.4.0" } }, "@babel/traverse": { - "version": "7.3.4", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.3.4.tgz", - "integrity": "sha512-TvTHKp6471OYEcE/91uWmhR6PrrYywQntCHSaZ8CM8Vmp+pjAusal4nGB2WCCQd0rvI7nOMKn9GnbcvTUz3/ZQ==", + "version": "7.4.3", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.4.3.tgz", + "integrity": "sha512-HmA01qrtaCwwJWpSKpA948cBvU5BrmviAief/b3AVw936DtcdsTexlbyzNuDnthwhOQ37xshn7hvQaEQk7ISYQ==", "dev": true, "requires": { "@babel/code-frame": "^7.0.0", - "@babel/generator": "^7.3.4", + "@babel/generator": "^7.4.0", "@babel/helper-function-name": "^7.1.0", - "@babel/helper-split-export-declaration": "^7.0.0", - "@babel/parser": "^7.3.4", - "@babel/types": "^7.3.4", + "@babel/helper-split-export-declaration": "^7.4.0", + "@babel/parser": "^7.4.3", + "@babel/types": "^7.4.0", "debug": "^4.1.0", "globals": "^11.1.0", "lodash": "^4.17.11" @@ -118,9 +118,9 @@ } }, "@babel/types": { - "version": "7.3.4", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.3.4.tgz", - "integrity": "sha512-WEkp8MsLftM7O/ty580wAmZzN1nDmCACc5+jFzUt+GUFNNIi3LdRlueYz0YIlmJhlZx1QYDMZL5vdWCL0fNjFQ==", + "version": "7.4.0", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.4.0.tgz", + "integrity": "sha512-aPvkXyU2SPOnztlgo8n9cEiXW755mgyvueUPcpStqdzoSPm0fjO0vQBjLkt3JKJW7ufikfcnMTTPsN1xaTsBPA==", "dev": true, "requires": { "esutils": "^2.0.2", @@ -169,9 +169,9 @@ "dev": true }, "@types/node": { - "version": "8.10.42", - "resolved": "https://registry.npmjs.org/@types/node/-/node-8.10.42.tgz", - "integrity": "sha512-8LCqostMfYwQs9by1k21/P4KZp9uFQk3Q528y3qtPKQnCJmKz0Em3YzgeNjTNV1FVrG/7n/6j12d4UKg9zSgDw==", + "version": "8.10.45", + "resolved": "https://registry.npmjs.org/@types/node/-/node-8.10.45.tgz", + "integrity": "sha512-tGVTbA+i3qfXsLbq9rEq/hezaHY55QxQLeXQL2ejNgFAxxrgu8eMmYIOsRcl7hN1uTLVsKOOYacV/rcJM3sfgQ==", "dev": true }, "@types/node-int64": { @@ -184,9 +184,9 @@ } }, "@types/q": { - "version": "1.5.1", - "resolved": "https://registry.npmjs.org/@types/q/-/q-1.5.1.tgz", - "integrity": "sha512-eqz8c/0kwNi/OEHQfvIuJVLTst3in0e7uTKeuY+WL/zfKn0xVujOTp42bS/vUUokhK5P2BppLd9JXMOMHcgbjA==", + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/@types/q/-/q-1.5.2.tgz", + "integrity": "sha512-ce5d3q03Ex0sy4R14722Rmt6MT07Ua+k4FwDfdcToYJcMKNtRVQvJ6JCAPdAmAnbRb6CsX6aYb9m96NGod9uTw==", "dev": true }, "@types/rimraf": { @@ -542,9 +542,9 @@ "dev": true }, "js-yaml": { - "version": "3.12.2", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.12.2.tgz", - "integrity": "sha512-QHn/Lh/7HhZ/Twc7vJYQTkjuCa0kaCcDcjK5Zlk2rvnUpy7DxMJ23+Jc2dcyvltwQVg1nygAVlB2oRDFHoRS5Q==", + "version": "3.13.1", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz", + "integrity": "sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==", "dev": true, "requires": { "argparse": "^1.0.7", @@ -673,14 +673,12 @@ "dependencies": { "ansi-regex": { "version": "3.0.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", - "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=", + "bundled": true, "dev": true }, "append-transform": { "version": "1.0.0", - "resolved": "https://registry.npmjs.org/append-transform/-/append-transform-1.0.0.tgz", - "integrity": "sha512-P009oYkeHyU742iSZJzZZywj4QRJdnTWffaKuJQLablCZ1uz6/cW4yaRgcDaoQ+uwOxxnt0gRUcwfsNP2ri0gw==", + "bundled": true, "dev": true, "requires": { "default-require-extensions": "^2.0.0" @@ -688,20 +686,17 @@ }, "archy": { "version": "1.0.0", - "resolved": "https://registry.npmjs.org/archy/-/archy-1.0.0.tgz", - "integrity": "sha1-+cjBN1fMHde8N5rHeyxipcKGjEA=", + "bundled": true, "dev": true }, "arrify": { "version": "1.0.1", - "resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz", - "integrity": "sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=", + "bundled": true, "dev": true }, "async": { "version": "2.6.2", - "resolved": "https://registry.npmjs.org/async/-/async-2.6.2.tgz", - "integrity": "sha512-H1qVYh1MYhEEFLsP97cVKqCGo7KfCyTt6uEWqsTBr9SO84oK9Uwbyd/yCW+6rKJLHksBNUVWZDAjfS+Ccx0Bbg==", + "bundled": true, "dev": true, "requires": { "lodash": "^4.17.11" @@ -709,14 +704,12 @@ }, "balanced-match": { "version": "1.0.0", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", + "bundled": true, "dev": true }, "brace-expansion": { "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "bundled": true, "dev": true, "requires": { "balanced-match": "^1.0.0", @@ -725,8 +718,7 @@ }, "caching-transform": { "version": "3.0.1", - "resolved": "https://registry.npmjs.org/caching-transform/-/caching-transform-3.0.1.tgz", - "integrity": "sha512-Y1KTLNwSPd4ljsDrFOtyXVmm7Gnk42yQitNq43AhE+cwUR/e4T+rmOHs1IPtzBg8066GBJfTOj1rQYFSWSsH2g==", + "bundled": true, "dev": true, "requires": { "hasha": "^3.0.0", @@ -737,14 +729,12 @@ }, "camelcase": { "version": "5.0.0", - "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.0.0.tgz", - "integrity": "sha512-faqwZqnWxbxn+F1d399ygeamQNy3lPp/H9H6rNrqYh4FSVCtcY+3cub1MxA8o9mDd55mM8Aghuu/kuyYA6VTsA==", + "bundled": true, "dev": true }, "cliui": { "version": "4.1.0", - "resolved": "https://registry.npmjs.org/cliui/-/cliui-4.1.0.tgz", - "integrity": "sha512-4FG+RSG9DL7uEwRUZXZn3SS34DiDPfzP0VOiEwtUWlE+AR2EIg+hSyvrIgUUfhdgR/UkAeW2QHgeP+hWrXs7jQ==", + "bundled": true, "dev": true, "requires": { "string-width": "^2.1.1", @@ -754,33 +744,28 @@ }, "code-point-at": { "version": "1.1.0", - "resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz", - "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=", + "bundled": true, "dev": true }, "commander": { "version": "2.17.1", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.17.1.tgz", - "integrity": "sha512-wPMUt6FnH2yzG95SA6mzjQOEKUU3aLaDEmzs1ti+1E9h+CsrZghRlqEM/EJ4KscsQVG8uNN4uVreUeT8+drlgg==", + "bundled": true, "dev": true, "optional": true }, "commondir": { "version": "1.0.1", - "resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz", - "integrity": "sha1-3dgA2gxmEnOTzKWVDqloo6rxJTs=", + "bundled": true, "dev": true }, "concat-map": { "version": "0.0.1", - "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", + "bundled": true, "dev": true }, "convert-source-map": { "version": "1.6.0", - "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.6.0.tgz", - "integrity": "sha512-eFu7XigvxdZ1ETfbgPBohgyQ/Z++C0eEhTor0qRwBw9unw+L0/6V8wkSuGgzdThkiS5lSpdptOQPD8Ak40a+7A==", + "bundled": true, "dev": true, "requires": { "safe-buffer": "~5.1.1" @@ -788,8 +773,7 @@ }, "cross-spawn": { "version": "4.0.2", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-4.0.2.tgz", - "integrity": "sha1-e5JHYhwjrf3ThWAEqCPL45dCTUE=", + "bundled": true, "dev": true, "requires": { "lru-cache": "^4.0.1", @@ -798,8 +782,7 @@ }, "debug": { "version": "4.1.1", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", - "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", + "bundled": true, "dev": true, "requires": { "ms": "^2.1.1" @@ -807,14 +790,12 @@ }, "decamelize": { "version": "1.2.0", - "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", - "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=", + "bundled": true, "dev": true }, "default-require-extensions": { "version": "2.0.0", - "resolved": "https://registry.npmjs.org/default-require-extensions/-/default-require-extensions-2.0.0.tgz", - "integrity": "sha1-9fj7sYp9bVCyH2QfZJ67Uiz+JPc=", + "bundled": true, "dev": true, "requires": { "strip-bom": "^3.0.0" @@ -822,8 +803,7 @@ }, "end-of-stream": { "version": "1.4.1", - "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.1.tgz", - "integrity": "sha512-1MkrZNvWTKCaigbn+W15elq2BB/L22nqrSY5DKlo3X6+vclJm8Bb5djXJBmEX6fS3+zCh/F4VBK5Z2KxJt4s2Q==", + "bundled": true, "dev": true, "requires": { "once": "^1.4.0" @@ -831,8 +811,7 @@ }, "error-ex": { "version": "1.3.2", - "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz", - "integrity": "sha512-7dFHNmqeFSEt2ZBsCriorKnn3Z2pj+fd9kmI6QoWw4//DL+icEBfc0U7qJCisqrTsKTjw4fNFy2pW9OqStD84g==", + "bundled": true, "dev": true, "requires": { "is-arrayish": "^0.2.1" @@ -840,14 +819,12 @@ }, "es6-error": { "version": "4.1.1", - "resolved": "https://registry.npmjs.org/es6-error/-/es6-error-4.1.1.tgz", - "integrity": "sha512-Um/+FxMr9CISWh0bi5Zv0iOD+4cFh5qLeks1qhAopKVAJw3drgKbKySikp7wGhDL0HPeaja0P5ULZrxLkniUVg==", + "bundled": true, "dev": true }, "execa": { "version": "1.0.0", - "resolved": "https://registry.npmjs.org/execa/-/execa-1.0.0.tgz", - "integrity": "sha512-adbxcyWV46qiHyvSp50TKt05tB4tK3HcmF7/nxfAdhnox83seTDbwnaqKO4sXRy7roHAIFqJP/Rw/AuEbX61LA==", + "bundled": true, "dev": true, "requires": { "cross-spawn": "^6.0.0", @@ -861,8 +838,7 @@ "dependencies": { "cross-spawn": { "version": "6.0.5", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", - "integrity": "sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==", + "bundled": true, "dev": true, "requires": { "nice-try": "^1.0.4", @@ -876,8 +852,7 @@ }, "find-cache-dir": { "version": "2.0.0", - "resolved": "https://registry.npmjs.org/find-cache-dir/-/find-cache-dir-2.0.0.tgz", - "integrity": "sha512-LDUY6V1Xs5eFskUVYtIwatojt6+9xC9Chnlk/jYOOvn3FAFfSaWddxahDGyNHh0b2dMXa6YW2m0tk8TdVaXHlA==", + "bundled": true, "dev": true, "requires": { "commondir": "^1.0.1", @@ -887,8 +862,7 @@ }, "find-up": { "version": "3.0.0", - "resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz", - "integrity": "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==", + "bundled": true, "dev": true, "requires": { "locate-path": "^3.0.0" @@ -896,8 +870,7 @@ }, "foreground-child": { "version": "1.5.6", - "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-1.5.6.tgz", - "integrity": "sha1-T9ca0t/elnibmApcCilZN8svXOk=", + "bundled": true, "dev": true, "requires": { "cross-spawn": "^4", @@ -906,20 +879,17 @@ }, "fs.realpath": { "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", + "bundled": true, "dev": true }, "get-caller-file": { "version": "1.0.3", - "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-1.0.3.tgz", - "integrity": "sha512-3t6rVToeoZfYSGd8YoLFR2DJkiQrIiUrGcjvFX2mDw3bn6k2OtwHN0TNCLbBO+w8qTvimhDkv+LSscbJY1vE6w==", + "bundled": true, "dev": true }, "get-stream": { "version": "4.1.0", - "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-4.1.0.tgz", - "integrity": "sha512-GMat4EJ5161kIy2HevLlr4luNjBgvmj413KaQA7jt4V8B4RDsfpHk7WQ9GVqfYyyx8OS/L66Kox+rJRNklLK7w==", + "bundled": true, "dev": true, "requires": { "pump": "^3.0.0" @@ -927,8 +897,7 @@ }, "glob": { "version": "7.1.3", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz", - "integrity": "sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==", + "bundled": true, "dev": true, "requires": { "fs.realpath": "^1.0.0", @@ -941,14 +910,12 @@ }, "graceful-fs": { "version": "4.1.15", - "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.15.tgz", - "integrity": "sha512-6uHUhOPEBgQ24HM+r6b/QwWfZq+yiFcipKFrOFiBEnWdy5sdzYoi+pJeQaPI5qOLRFqWmAXUPQNsielzdLoecA==", + "bundled": true, "dev": true }, "handlebars": { "version": "4.1.0", - "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.1.0.tgz", - "integrity": "sha512-l2jRuU1NAWK6AW5qqcTATWQJvNPEwkM7NEKSiv/gqOsoSQbVoWyqVEY5GS+XPQ88zLNmqASRpzfdm8d79hJS+w==", + "bundled": true, "dev": true, "requires": { "async": "^2.5.0", @@ -959,22 +926,19 @@ "dependencies": { "source-map": { "version": "0.6.1", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", - "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "bundled": true, "dev": true } } }, "has-flag": { "version": "3.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", - "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", + "bundled": true, "dev": true }, "hasha": { "version": "3.0.0", - "resolved": "https://registry.npmjs.org/hasha/-/hasha-3.0.0.tgz", - "integrity": "sha1-UqMvq4Vp1BymmmH/GiFPjrfIvTk=", + "bundled": true, "dev": true, "requires": { "is-stream": "^1.0.1" @@ -982,20 +946,17 @@ }, "hosted-git-info": { "version": "2.7.1", - "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.7.1.tgz", - "integrity": "sha512-7T/BxH19zbcCTa8XkMlbK5lTo1WtgkFi3GvdWEyNuc4Vex7/9Dqbnpsf4JMydcfj9HCg4zUWFTL3Za6lapg5/w==", + "bundled": true, "dev": true }, "imurmurhash": { "version": "0.1.4", - "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", - "integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o=", + "bundled": true, "dev": true }, "inflight": { "version": "1.0.6", - "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", - "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "bundled": true, "dev": true, "requires": { "once": "^1.3.0", @@ -1004,50 +965,42 @@ }, "inherits": { "version": "2.0.3", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", - "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", + "bundled": true, "dev": true }, "invert-kv": { "version": "2.0.0", - "resolved": "https://registry.npmjs.org/invert-kv/-/invert-kv-2.0.0.tgz", - "integrity": "sha512-wPVv/y/QQ/Uiirj/vh3oP+1Ww+AWehmi1g5fFWGPF6IpCBCDVrhgHRMvrLfdYcwDh3QJbGXDW4JAuzxElLSqKA==", + "bundled": true, "dev": true }, "is-arrayish": { "version": "0.2.1", - "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz", - "integrity": "sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0=", + "bundled": true, "dev": true }, "is-fullwidth-code-point": { "version": "2.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", - "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", + "bundled": true, "dev": true }, "is-stream": { "version": "1.1.0", - "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", - "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=", + "bundled": true, "dev": true }, "isexe": { "version": "2.0.0", - "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", - "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=", + "bundled": true, "dev": true }, "istanbul-lib-coverage": { "version": "2.0.3", - "resolved": "https://registry.npmjs.org/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.3.tgz", - "integrity": "sha512-dKWuzRGCs4G+67VfW9pBFFz2Jpi4vSp/k7zBcJ888ofV5Mi1g5CUML5GvMvV6u9Cjybftu+E8Cgp+k0dI1E5lw==", + "bundled": true, "dev": true }, "istanbul-lib-hook": { "version": "2.0.3", - "resolved": "https://registry.npmjs.org/istanbul-lib-hook/-/istanbul-lib-hook-2.0.3.tgz", - "integrity": "sha512-CLmEqwEhuCYtGcpNVJjLV1DQyVnIqavMLFHV/DP+np/g3qvdxu3gsPqYoJMXm15sN84xOlckFB3VNvRbf5yEgA==", + "bundled": true, "dev": true, "requires": { "append-transform": "^1.0.0" @@ -1055,8 +1008,7 @@ }, "istanbul-lib-report": { "version": "2.0.4", - "resolved": "https://registry.npmjs.org/istanbul-lib-report/-/istanbul-lib-report-2.0.4.tgz", - "integrity": "sha512-sOiLZLAWpA0+3b5w5/dq0cjm2rrNdAfHWaGhmn7XEFW6X++IV9Ohn+pnELAl9K3rfpaeBfbmH9JU5sejacdLeA==", + "bundled": true, "dev": true, "requires": { "istanbul-lib-coverage": "^2.0.3", @@ -1066,8 +1018,7 @@ "dependencies": { "supports-color": { "version": "6.1.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-6.1.0.tgz", - "integrity": "sha512-qe1jfm1Mg7Nq/NSh6XE24gPXROEVsWHxC1LIx//XNlD9iw7YZQGjZNjYN7xGaEG6iKdA8EtNFW6R0gjnVXp+wQ==", + "bundled": true, "dev": true, "requires": { "has-flag": "^3.0.0" @@ -1077,8 +1028,7 @@ }, "istanbul-lib-source-maps": { "version": "3.0.2", - "resolved": "https://registry.npmjs.org/istanbul-lib-source-maps/-/istanbul-lib-source-maps-3.0.2.tgz", - "integrity": "sha512-JX4v0CiKTGp9fZPmoxpu9YEkPbEqCqBbO3403VabKjH+NRXo72HafD5UgnjTEqHL2SAjaZK1XDuDOkn6I5QVfQ==", + "bundled": true, "dev": true, "requires": { "debug": "^4.1.1", @@ -1090,16 +1040,14 @@ "dependencies": { "source-map": { "version": "0.6.1", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", - "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "bundled": true, "dev": true } } }, "istanbul-reports": { "version": "2.1.1", - "resolved": "https://registry.npmjs.org/istanbul-reports/-/istanbul-reports-2.1.1.tgz", - "integrity": "sha512-FzNahnidyEPBCI0HcufJoSEoKykesRlFcSzQqjH9x0+LC8tnnE/p/90PBLu8iZTxr8yYZNyTtiAujUqyN+CIxw==", + "bundled": true, "dev": true, "requires": { "handlebars": "^4.1.0" @@ -1107,14 +1055,12 @@ }, "json-parse-better-errors": { "version": "1.0.2", - "resolved": "https://registry.npmjs.org/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz", - "integrity": "sha512-mrqyZKfX5EhL7hvqcV6WG1yYjnjeuYDzDhhcAAUrq8Po85NBQBJP+ZDUT75qZQ98IkUoBqdkExkukOU7Ts2wrw==", + "bundled": true, "dev": true }, "lcid": { "version": "2.0.0", - "resolved": "https://registry.npmjs.org/lcid/-/lcid-2.0.0.tgz", - "integrity": "sha512-avPEb8P8EGnwXKClwsNUgryVjllcRqtMYa49NTsbQagYuT1DcXnl1915oxWjoyGrXR6zH/Y0Zc96xWsPcoDKeA==", + "bundled": true, "dev": true, "requires": { "invert-kv": "^2.0.0" @@ -1122,8 +1068,7 @@ }, "load-json-file": { "version": "4.0.0", - "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-4.0.0.tgz", - "integrity": "sha1-L19Fq5HjMhYjT9U62rZo607AmTs=", + "bundled": true, "dev": true, "requires": { "graceful-fs": "^4.1.2", @@ -1134,8 +1079,7 @@ }, "locate-path": { "version": "3.0.0", - "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-3.0.0.tgz", - "integrity": "sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==", + "bundled": true, "dev": true, "requires": { "p-locate": "^3.0.0", @@ -1144,20 +1088,17 @@ }, "lodash": { "version": "4.17.11", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", - "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==", + "bundled": true, "dev": true }, "lodash.flattendeep": { "version": "4.4.0", - "resolved": "https://registry.npmjs.org/lodash.flattendeep/-/lodash.flattendeep-4.4.0.tgz", - "integrity": "sha1-+wMJF/hqMTTlvJvsDWngAT3f7bI=", + "bundled": true, "dev": true }, "lru-cache": { "version": "4.1.5", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.5.tgz", - "integrity": "sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g==", + "bundled": true, "dev": true, "requires": { "pseudomap": "^1.0.2", @@ -1166,8 +1107,7 @@ }, "make-dir": { "version": "1.3.0", - "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-1.3.0.tgz", - "integrity": "sha512-2w31R7SJtieJJnQtGc7RVL2StM2vGYVfqUOvUDxH6bC6aJTxPxTF0GnIgCyu7tjockiUWAYQRbxa7vKn34s5sQ==", + "bundled": true, "dev": true, "requires": { "pify": "^3.0.0" @@ -1175,8 +1115,7 @@ }, "map-age-cleaner": { "version": "0.1.3", - "resolved": "https://registry.npmjs.org/map-age-cleaner/-/map-age-cleaner-0.1.3.tgz", - "integrity": "sha512-bJzx6nMoP6PDLPBFmg7+xRKeFZvFboMrGlxmNj9ClvX53KrmvM5bXFXEWjbz4cz1AFn+jWJ9z/DJSz7hrs0w3w==", + "bundled": true, "dev": true, "requires": { "p-defer": "^1.0.0" @@ -1184,8 +1123,7 @@ }, "mem": { "version": "4.1.0", - "resolved": "https://registry.npmjs.org/mem/-/mem-4.1.0.tgz", - "integrity": "sha512-I5u6Q1x7wxO0kdOpYBB28xueHADYps5uty/zg936CiG8NTe5sJL8EjrCuLneuDW3PlMdZBGDIn8BirEVdovZvg==", + "bundled": true, "dev": true, "requires": { "map-age-cleaner": "^0.1.1", @@ -1195,8 +1133,7 @@ }, "merge-source-map": { "version": "1.1.0", - "resolved": "https://registry.npmjs.org/merge-source-map/-/merge-source-map-1.1.0.tgz", - "integrity": "sha512-Qkcp7P2ygktpMPh2mCQZaf3jhN6D3Z/qVZHSdWvQ+2Ef5HgRAPBO57A77+ENm0CPx2+1Ce/MYKi3ymqdfuqibw==", + "bundled": true, "dev": true, "requires": { "source-map": "^0.6.1" @@ -1204,22 +1141,19 @@ "dependencies": { "source-map": { "version": "0.6.1", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", - "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "bundled": true, "dev": true } } }, "mimic-fn": { "version": "1.2.0", - "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-1.2.0.tgz", - "integrity": "sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ==", + "bundled": true, "dev": true }, "minimatch": { "version": "3.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "bundled": true, "dev": true, "requires": { "brace-expansion": "^1.1.7" @@ -1227,14 +1161,12 @@ }, "minimist": { "version": "0.0.10", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz", - "integrity": "sha1-3j+YVD2/lggr5IrRoMfNqDYwHc8=", + "bundled": true, "dev": true }, "mkdirp": { "version": "0.5.1", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", - "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "bundled": true, "dev": true, "requires": { "minimist": "0.0.8" @@ -1242,28 +1174,24 @@ "dependencies": { "minimist": { "version": "0.0.8", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", - "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", + "bundled": true, "dev": true } } }, "ms": { "version": "2.1.1", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", - "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==", + "bundled": true, "dev": true }, "nice-try": { "version": "1.0.5", - "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", - "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==", + "bundled": true, "dev": true }, "normalize-package-data": { "version": "2.5.0", - "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.5.0.tgz", - "integrity": "sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA==", + "bundled": true, "dev": true, "requires": { "hosted-git-info": "^2.1.4", @@ -1274,8 +1202,7 @@ }, "npm-run-path": { "version": "2.0.2", - "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-2.0.2.tgz", - "integrity": "sha1-NakjLfo11wZ7TLLd8jV7GHFTbF8=", + "bundled": true, "dev": true, "requires": { "path-key": "^2.0.0" @@ -1283,14 +1210,12 @@ }, "number-is-nan": { "version": "1.0.1", - "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", - "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=", + "bundled": true, "dev": true }, "once": { "version": "1.4.0", - "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", - "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "bundled": true, "dev": true, "requires": { "wrappy": "1" @@ -1298,8 +1223,7 @@ }, "optimist": { "version": "0.6.1", - "resolved": "https://registry.npmjs.org/optimist/-/optimist-0.6.1.tgz", - "integrity": "sha1-2j6nRob6IaGaERwybpDrFaAZZoY=", + "bundled": true, "dev": true, "requires": { "minimist": "~0.0.1", @@ -1308,14 +1232,12 @@ }, "os-homedir": { "version": "1.0.2", - "resolved": "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz", - "integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=", + "bundled": true, "dev": true }, "os-locale": { "version": "3.1.0", - "resolved": "https://registry.npmjs.org/os-locale/-/os-locale-3.1.0.tgz", - "integrity": "sha512-Z8l3R4wYWM40/52Z+S265okfFj8Kt2cC2MKY+xNi3kFs+XGI7WXu/I309QQQYbRW4ijiZ+yxs9pqEhJh0DqW3Q==", + "bundled": true, "dev": true, "requires": { "execa": "^1.0.0", @@ -1325,26 +1247,22 @@ }, "p-defer": { "version": "1.0.0", - "resolved": "https://registry.npmjs.org/p-defer/-/p-defer-1.0.0.tgz", - "integrity": "sha1-n26xgvbJqozXQwBKfU+WsZaw+ww=", + "bundled": true, "dev": true }, "p-finally": { "version": "1.0.0", - "resolved": "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz", - "integrity": "sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4=", + "bundled": true, "dev": true }, "p-is-promise": { "version": "2.0.0", - "resolved": "https://registry.npmjs.org/p-is-promise/-/p-is-promise-2.0.0.tgz", - "integrity": "sha512-pzQPhYMCAgLAKPWD2jC3Se9fEfrD9npNos0y150EeqZll7akhEgGhTW/slB6lHku8AvYGiJ+YJ5hfHKePPgFWg==", + "bundled": true, "dev": true }, "p-limit": { "version": "2.1.0", - "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.1.0.tgz", - "integrity": "sha512-NhURkNcrVB+8hNfLuysU8enY5xn2KXphsHBaC2YmRNTZRc7RWusw6apSpdEj3jo4CMb6W9nrF6tTnsJsJeyu6g==", + "bundled": true, "dev": true, "requires": { "p-try": "^2.0.0" @@ -1352,8 +1270,7 @@ }, "p-locate": { "version": "3.0.0", - "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-3.0.0.tgz", - "integrity": "sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==", + "bundled": true, "dev": true, "requires": { "p-limit": "^2.0.0" @@ -1361,14 +1278,12 @@ }, "p-try": { "version": "2.0.0", - "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.0.0.tgz", - "integrity": "sha512-hMp0onDKIajHfIkdRk3P4CdCmErkYAxxDtP3Wx/4nZ3aGlau2VKh3mZpcuFkH27WQkL/3WBCPOktzA9ZOAnMQQ==", + "bundled": true, "dev": true }, "package-hash": { "version": "3.0.0", - "resolved": "https://registry.npmjs.org/package-hash/-/package-hash-3.0.0.tgz", - "integrity": "sha512-lOtmukMDVvtkL84rJHI7dpTYq+0rli8N2wlnqUcBuDWCfVhRUfOmnR9SsoHFMLpACvEV60dX7rd0rFaYDZI+FA==", + "bundled": true, "dev": true, "requires": { "graceful-fs": "^4.1.15", @@ -1379,8 +1294,7 @@ }, "parse-json": { "version": "4.0.0", - "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-4.0.0.tgz", - "integrity": "sha1-vjX1Qlvh9/bHRxhPmKeIy5lHfuA=", + "bundled": true, "dev": true, "requires": { "error-ex": "^1.3.1", @@ -1389,32 +1303,27 @@ }, "path-exists": { "version": "3.0.0", - "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", - "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=", + "bundled": true, "dev": true }, "path-is-absolute": { "version": "1.0.1", - "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", + "bundled": true, "dev": true }, "path-key": { "version": "2.0.1", - "resolved": "https://registry.npmjs.org/path-key/-/path-key-2.0.1.tgz", - "integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=", + "bundled": true, "dev": true }, "path-parse": { "version": "1.0.6", - "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz", - "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==", + "bundled": true, "dev": true }, "path-type": { "version": "3.0.0", - "resolved": "https://registry.npmjs.org/path-type/-/path-type-3.0.0.tgz", - "integrity": "sha512-T2ZUsdZFHgA3u4e5PfPbjd7HDDpxPnQb5jN0SrDsjNSuVXHJqtwTnWqG0B1jZrgmJ/7lj1EmVIByWt1gxGkWvg==", + "bundled": true, "dev": true, "requires": { "pify": "^3.0.0" @@ -1422,14 +1331,12 @@ }, "pify": { "version": "3.0.0", - "resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz", - "integrity": "sha1-5aSs0sEB/fPZpNB/DbxNtJ3SgXY=", + "bundled": true, "dev": true }, "pkg-dir": { "version": "3.0.0", - "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-3.0.0.tgz", - "integrity": "sha512-/E57AYkoeQ25qkxMj5PBOVgF8Kiu/h7cYS30Z5+R7WaiCCBfLq58ZI/dSeaEKb9WVJV5n/03QwrN3IeWIFllvw==", + "bundled": true, "dev": true, "requires": { "find-up": "^3.0.0" @@ -1437,14 +1344,12 @@ }, "pseudomap": { "version": "1.0.2", - "resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz", - "integrity": "sha1-8FKijacOYYkX7wqKw0wa5aaChrM=", + "bundled": true, "dev": true }, "pump": { "version": "3.0.0", - "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", - "integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==", + "bundled": true, "dev": true, "requires": { "end-of-stream": "^1.1.0", @@ -1453,8 +1358,7 @@ }, "read-pkg": { "version": "3.0.0", - "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-3.0.0.tgz", - "integrity": "sha1-nLxoaXj+5l0WwA4rGcI3/Pbjg4k=", + "bundled": true, "dev": true, "requires": { "load-json-file": "^4.0.0", @@ -1464,8 +1368,7 @@ }, "read-pkg-up": { "version": "4.0.0", - "resolved": "https://registry.npmjs.org/read-pkg-up/-/read-pkg-up-4.0.0.tgz", - "integrity": "sha512-6etQSH7nJGsK0RbG/2TeDzZFa8shjQ1um+SwQQ5cwKy0dhSXdOncEhb1CPpvQG4h7FyOV6EB6YlV0yJvZQNAkA==", + "bundled": true, "dev": true, "requires": { "find-up": "^3.0.0", @@ -1474,8 +1377,7 @@ }, "release-zalgo": { "version": "1.0.0", - "resolved": "https://registry.npmjs.org/release-zalgo/-/release-zalgo-1.0.0.tgz", - "integrity": "sha1-CXALflB0Mpc5Mw5TXFqQ+2eFFzA=", + "bundled": true, "dev": true, "requires": { "es6-error": "^4.0.1" @@ -1483,20 +1385,17 @@ }, "require-directory": { "version": "2.1.1", - "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", - "integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I=", + "bundled": true, "dev": true }, "require-main-filename": { "version": "1.0.1", - "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-1.0.1.tgz", - "integrity": "sha1-l/cXtp1IeE9fUmpsWqj/3aBVpNE=", + "bundled": true, "dev": true }, "resolve": { "version": "1.10.0", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.10.0.tgz", - "integrity": "sha512-3sUr9aq5OfSg2S9pNtPA9hL1FVEAjvfOC4leW0SNf/mpnaakz2a9femSd6LqAww2RaFctwyf1lCqnTHuF1rxDg==", + "bundled": true, "dev": true, "requires": { "path-parse": "^1.0.6" @@ -1504,14 +1403,12 @@ }, "resolve-from": { "version": "4.0.0", - "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", - "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", + "bundled": true, "dev": true }, "rimraf": { "version": "2.6.3", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz", - "integrity": "sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==", + "bundled": true, "dev": true, "requires": { "glob": "^7.1.3" @@ -1519,26 +1416,22 @@ }, "safe-buffer": { "version": "5.1.2", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", - "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", + "bundled": true, "dev": true }, "semver": { "version": "5.6.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.6.0.tgz", - "integrity": "sha512-RS9R6R35NYgQn++fkDWaOmqGoj4Ek9gGs+DPxNUZKuwE183xjJroKvyo1IzVFeXvUrvmALy6FWD5xrdJT25gMg==", + "bundled": true, "dev": true }, "set-blocking": { "version": "2.0.0", - "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", - "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=", + "bundled": true, "dev": true }, "shebang-command": { "version": "1.2.0", - "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz", - "integrity": "sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=", + "bundled": true, "dev": true, "requires": { "shebang-regex": "^1.0.0" @@ -1546,20 +1439,17 @@ }, "shebang-regex": { "version": "1.0.0", - "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-1.0.0.tgz", - "integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=", + "bundled": true, "dev": true }, "signal-exit": { "version": "3.0.2", - "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", - "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=", + "bundled": true, "dev": true }, "spawn-wrap": { "version": "1.4.2", - "resolved": "https://registry.npmjs.org/spawn-wrap/-/spawn-wrap-1.4.2.tgz", - "integrity": "sha512-vMwR3OmmDhnxCVxM8M+xO/FtIp6Ju/mNaDfCMMW7FDcLRTPFWUswec4LXJHTJE2hwTI9O0YBfygu4DalFl7Ylg==", + "bundled": true, "dev": true, "requires": { "foreground-child": "^1.5.6", @@ -1572,8 +1462,7 @@ }, "spdx-correct": { "version": "3.1.0", - "resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-3.1.0.tgz", - "integrity": "sha512-lr2EZCctC2BNR7j7WzJ2FpDznxky1sjfxvvYEyzxNyb6lZXHODmEoJeFu4JupYlkfha1KZpJyoqiJ7pgA1qq8Q==", + "bundled": true, "dev": true, "requires": { "spdx-expression-parse": "^3.0.0", @@ -1582,14 +1471,12 @@ }, "spdx-exceptions": { "version": "2.2.0", - "resolved": "https://registry.npmjs.org/spdx-exceptions/-/spdx-exceptions-2.2.0.tgz", - "integrity": "sha512-2XQACfElKi9SlVb1CYadKDXvoajPgBVPn/gOQLrTvHdElaVhr7ZEbqJaRnJLVNeaI4cMEAgVCeBMKF6MWRDCRA==", + "bundled": true, "dev": true }, "spdx-expression-parse": { "version": "3.0.0", - "resolved": "https://registry.npmjs.org/spdx-expression-parse/-/spdx-expression-parse-3.0.0.tgz", - "integrity": "sha512-Yg6D3XpRD4kkOmTpdgbUiEJFKghJH03fiC1OPll5h/0sO6neh2jqRDVHOQ4o/LMea0tgCkbMgea5ip/e+MkWyg==", + "bundled": true, "dev": true, "requires": { "spdx-exceptions": "^2.1.0", @@ -1598,14 +1485,12 @@ }, "spdx-license-ids": { "version": "3.0.3", - "resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.3.tgz", - "integrity": "sha512-uBIcIl3Ih6Phe3XHK1NqboJLdGfwr1UN3k6wSD1dZpmPsIkb8AGNbZYJ1fOBk834+Gxy8rpfDxrS6XLEMZMY2g==", + "bundled": true, "dev": true }, "string-width": { "version": "2.1.1", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", - "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", + "bundled": true, "dev": true, "requires": { "is-fullwidth-code-point": "^2.0.0", @@ -1614,8 +1499,7 @@ }, "strip-ansi": { "version": "4.0.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", - "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", + "bundled": true, "dev": true, "requires": { "ansi-regex": "^3.0.0" @@ -1623,20 +1507,17 @@ }, "strip-bom": { "version": "3.0.0", - "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", - "integrity": "sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM=", + "bundled": true, "dev": true }, "strip-eof": { "version": "1.0.0", - "resolved": "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz", - "integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=", + "bundled": true, "dev": true }, "test-exclude": { "version": "5.1.0", - "resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-5.1.0.tgz", - "integrity": "sha512-gwf0S2fFsANC55fSeSqpb8BYk6w3FDvwZxfNjeF6FRgvFa43r+7wRiA/Q0IxoRU37wB/LE8IQ4221BsNucTaCA==", + "bundled": true, "dev": true, "requires": { "arrify": "^1.0.1", @@ -1647,8 +1528,7 @@ }, "uglify-js": { "version": "3.4.9", - "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.4.9.tgz", - "integrity": "sha512-8CJsbKOtEbnJsTyv6LE6m6ZKniqMiFWmm9sRbopbkGs3gMPPfd3Fh8iIA4Ykv5MgaTbqHr4BaoGLJLZNhsrW1Q==", + "bundled": true, "dev": true, "optional": true, "requires": { @@ -1658,8 +1538,7 @@ "dependencies": { "source-map": { "version": "0.6.1", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", - "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "bundled": true, "dev": true, "optional": true } @@ -1667,14 +1546,12 @@ }, "uuid": { "version": "3.3.2", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.2.tgz", - "integrity": "sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA==", + "bundled": true, "dev": true }, "validate-npm-package-license": { "version": "3.0.4", - "resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz", - "integrity": "sha512-DpKm2Ui/xN7/HQKCtpZxoRWBhZ9Z0kqtygG8XCgNQ8ZlDnxuQmWhj566j8fN4Cu3/JmbhsDo7fcAJq4s9h27Ew==", + "bundled": true, "dev": true, "requires": { "spdx-correct": "^3.0.0", @@ -1683,8 +1560,7 @@ }, "which": { "version": "1.3.1", - "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", - "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", + "bundled": true, "dev": true, "requires": { "isexe": "^2.0.0" @@ -1692,20 +1568,17 @@ }, "which-module": { "version": "2.0.0", - "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz", - "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=", + "bundled": true, "dev": true }, "wordwrap": { "version": "0.0.3", - "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.3.tgz", - "integrity": "sha1-o9XabNXAvAAI03I0u68b7WMFkQc=", + "bundled": true, "dev": true }, "wrap-ansi": { "version": "2.1.0", - "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.1.0.tgz", - "integrity": "sha1-2Pw9KE3QV5T+hJc8rs3Rz4JP3YU=", + "bundled": true, "dev": true, "requires": { "string-width": "^1.0.1", @@ -1714,14 +1587,12 @@ "dependencies": { "ansi-regex": { "version": "2.1.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", - "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", + "bundled": true, "dev": true }, "is-fullwidth-code-point": { "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", - "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", + "bundled": true, "dev": true, "requires": { "number-is-nan": "^1.0.0" @@ -1729,8 +1600,7 @@ }, "string-width": { "version": "1.0.2", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", - "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", + "bundled": true, "dev": true, "requires": { "code-point-at": "^1.0.0", @@ -1740,8 +1610,7 @@ }, "strip-ansi": { "version": "3.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", - "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "bundled": true, "dev": true, "requires": { "ansi-regex": "^2.0.0" @@ -1751,14 +1620,12 @@ }, "wrappy": { "version": "1.0.2", - "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", + "bundled": true, "dev": true }, "write-file-atomic": { "version": "2.4.2", - "resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-2.4.2.tgz", - "integrity": "sha512-s0b6vB3xIVRLWywa6X9TOMA7k9zio0TMOsl9ZnDkliA/cfJlpHXAscj0gbHVJiTdIuAYpIyqS5GW91fqm6gG5g==", + "bundled": true, "dev": true, "requires": { "graceful-fs": "^4.1.11", @@ -1768,20 +1635,17 @@ }, "y18n": { "version": "4.0.0", - "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz", - "integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==", + "bundled": true, "dev": true }, "yallist": { "version": "2.1.2", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz", - "integrity": "sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI=", + "bundled": true, "dev": true }, "yargs": { "version": "12.0.5", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-12.0.5.tgz", - "integrity": "sha512-Lhz8TLaYnxq/2ObqHDql8dX8CJi97oHxrjUcYtzKbbykPtVW9WB+poxI+NM2UIzsMgNCZTIf0AQwsjK5yMAqZw==", + "bundled": true, "dev": true, "requires": { "cliui": "^4.0.0", @@ -1800,8 +1664,7 @@ }, "yargs-parser": { "version": "11.1.1", - "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-11.1.1.tgz", - "integrity": "sha512-C6kB/WJDiaxONLJQnF8ccx9SEeoTTLek8RVbaOIsrAUS8VrBEXfmeSnCZxygc+XC2sNMBIwOOnfcxiynjHsVSQ==", + "bundled": true, "dev": true, "requires": { "camelcase": "^5.0.0", @@ -1866,9 +1729,9 @@ } }, "semver": { - "version": "5.6.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.6.0.tgz", - "integrity": "sha512-RS9R6R35NYgQn++fkDWaOmqGoj4Ek9gGs+DPxNUZKuwE183xjJroKvyo1IzVFeXvUrvmALy6FWD5xrdJT25gMg==", + "version": "5.7.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.0.tgz", + "integrity": "sha512-Ya52jSX2u7QKghxeoFGpLwCtGlt7j0oY9DYb5apt9nPlJ42ID+ulTXESnt/qAQcoSERyZ5sl3LDIOw0nAn/5DA==", "dev": true }, "source-map": { @@ -1878,9 +1741,9 @@ "dev": true }, "source-map-support": { - "version": "0.5.10", - "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.10.tgz", - "integrity": "sha512-YfQ3tQFTK/yzlGJuX8pTwa4tifQj4QS2Mj7UegOu8jAz59MqIiMGPXxQhVQiIMNzayuUSF/jEuVnfFF5JqybmQ==", + "version": "0.5.11", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.11.tgz", + "integrity": "sha512-//sajEx/fGL3iw6fltKMdPvy8kL3kJ2O3iuYlRoT3k9Kb4BjOoZ+BZzaNHeuaruSt+Kf3Zk9tnfAQg9/AJqUVQ==", "dev": true, "requires": { "buffer-from": "^1.0.0", @@ -1949,9 +1812,9 @@ "dev": true }, "tslint": { - "version": "5.13.1", - "resolved": "https://registry.npmjs.org/tslint/-/tslint-5.13.1.tgz", - "integrity": "sha512-fplQqb2miLbcPhyHoMV4FU9PtNRbgmm/zI5d3SZwwmJQM6V0eodju+hplpyfhLWpmwrDNfNYU57uYRb8s0zZoQ==", + "version": "5.15.0", + "resolved": "https://registry.npmjs.org/tslint/-/tslint-5.15.0.tgz", + "integrity": "sha512-6bIEujKR21/3nyeoX2uBnE8s+tMXCQXhqMmaIPJpHmXJoBJPTLcI7/VHRtUwMhnLVdwLqqY3zmd8Dxqa5CVdJA==", "dev": true, "requires": { "babel-code-frame": "^6.22.0", @@ -1960,13 +1823,13 @@ "commander": "^2.12.1", "diff": "^3.2.0", "glob": "^7.1.1", - "js-yaml": "^3.7.0", + "js-yaml": "^3.13.0", "minimatch": "^3.0.4", "mkdirp": "^0.5.1", "resolve": "^1.3.2", "semver": "^5.3.0", "tslib": "^1.8.0", - "tsutils": "^2.27.2" + "tsutils": "^2.29.0" } }, "tslint-config-prettier": { @@ -2012,9 +1875,9 @@ "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" }, "ws": { - "version": "6.1.4", - "resolved": "https://registry.npmjs.org/ws/-/ws-6.1.4.tgz", - "integrity": "sha512-eqZfL+NE/YQc1/ZynhojeV8q+H050oR8AZ2uIev7RU10svA9ZnJUddHcOUZTJLinZ9yEfdA2kSATS2qZK5fhJA==", + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/ws/-/ws-6.2.1.tgz", + "integrity": "sha512-GIyAXC2cB7LjvpgMt9EKS2ldqr0MTrORaleiOno6TweZ6r3TKtoFQWay/2PceJ3RuBasOHzXNn5Lrw1X0bEjqA==", "dev": true, "requires": { "async-limiter": "~1.0.0" diff --git a/package.json b/package.json index 3c3ab33e..1545053f 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ ], "scripts": { "clean": "rimraf ./coverage ./dist ./**/codegen", - "clean-all": "npm run clean && rimraf ./node_modules package-lock.json", + "clean:all": "npm run clean && rimraf ./node_modules package-lock.json", "codegen": "node ./dist/main/bin/index.js --sourceDir ./src/tests/integration/thrift --outDir ./src/tests/integration/apache/codegen", "prebuild": "npm run clean && npm run lint && npm run format", "build": "npm run build:only", diff --git a/src/main/debugger.ts b/src/main/debugger/index.ts similarity index 81% rename from src/main/debugger.ts rename to src/main/debugger/index.ts index 46746e4a..6dcf845c 100644 --- a/src/main/debugger.ts +++ b/src/main/debugger/index.ts @@ -1,7 +1,8 @@ import { TextLocation } from '@creditkarma/thrift-parser' import * as os from 'os' -import { ErrorType, IResolvedFile, IThriftError } from './types' +import { ErrorType, IThriftError } from '../errors' +import { IProcessedFile } from '../types' interface IFormattedError { sourceLine: string @@ -46,8 +47,8 @@ function errorType(type: ErrorType): string { } } -function printErrorForFile(file: IResolvedFile): void { - const sourceLines: Array = file.source.split(os.EOL) +function printErrorForFile(file: T): void { + const sourceLines: Array = file.sourceFile.source.split(os.EOL) const formattedErrors: Array = file.errors.map( (next: IThriftError): IFormattedError => { return formatError(next) @@ -70,9 +71,9 @@ function printErrorForFile(file: IResolvedFile): void { } console.log( - `Error generating file '${file.path}/${file.name}.thrift': ${ - file.errors.length - } errors found:`, + `Error generating file '${file.sourceFile.path}/${ + file.sourceFile.name + }.thrift': ${file.errors.length} errors found:`, ) formattedErrors.forEach( (err: IFormattedError): void => { @@ -89,9 +90,9 @@ function printErrorForFile(file: IResolvedFile): void { ) } -export function printErrors(files: Array): void { +export function printErrors(files: Array): void { files.forEach( - (next: IResolvedFile): void => { + (next: T): void => { printErrorForFile(next) }, ) diff --git a/src/main/errors.ts b/src/main/errors.ts new file mode 100644 index 00000000..7e78ef8a --- /dev/null +++ b/src/main/errors.ts @@ -0,0 +1,35 @@ +import { TextLocation } from '@creditkarma/thrift-parser' +import { emptyLocation } from './utils' + +export const enum ErrorType { + ValidationError = 'ValidationError', + ResolutionError = 'ResolutionError', + GenerationError = 'GenerationError', +} + +export interface IThriftError { + type: ErrorType + message: string + loc: TextLocation +} + +export class ValidationError extends Error { + public message: string + public loc: TextLocation + constructor(msg: string, loc: TextLocation) { + super(msg) + this.message = msg + this.loc = loc + } +} + +export function createValidationError( + message: string, + loc: TextLocation = emptyLocation(), +): IThriftError { + return { + type: ErrorType.ValidationError, + message, + loc, + } +} diff --git a/src/main/generator/index.ts b/src/main/generator/index.ts index bb7b69a9..f82aaf75 100644 --- a/src/main/generator/index.ts +++ b/src/main/generator/index.ts @@ -1,17 +1,25 @@ import * as ts from 'typescript' import { - IIdentifierMap, - IMakeOptions, - INamespaceFile, - IRenderedCache, - IRenderedFile, + ExceptionDefinition, + ServiceDefinition, + StructDefinition, + ThriftStatement, + UnionDefinition, +} from '@creditkarma/thrift-parser' + +import { rendererForTarget } from '../render' +import { processStatements, renderStatement } from './iterator' + +import { exportsForFile } from '../resolver/utils' +import { + IGeneratedFile, + INamespace, IRenderer, IRenderState, + IThriftProject, } from '../types' -import { processStatements } from './iterator' - /** * Export this directly is useful for generating code without generating files */ @@ -30,31 +38,155 @@ export { processStatements } from './iterator' */ export function generateFile( renderer: IRenderer, - resolvedFile: INamespaceFile, - options: IMakeOptions, - cache: IRenderedCache = {}, -): IRenderedFile { - const cacheKey: string = resolvedFile.namespace.path - - if (cacheKey === '/' || cache[cacheKey] === undefined) { - const identifiers: IIdentifierMap = resolvedFile.identifiers - const state: IRenderState = { options, identifiers } - const statements: Array = [ - ...renderer.renderIncludes( - resolvedFile.namespace.path, - resolvedFile, - options, - ), - ...processStatements(resolvedFile.body, state, renderer), - ] + statements: Array, + state: IRenderState, +): Array { + return processStatements(statements, state, renderer) +} + +function generateFileFromStatements( + statements: Array< + | ServiceDefinition + | ExceptionDefinition + | UnionDefinition + | StructDefinition + >, + namespace: INamespace, + thriftProject: IThriftProject, + renderer: IRenderer, +): Array { + const result: Array = [] + + statements.forEach( + ( + statement: + | ServiceDefinition + | ExceptionDefinition + | UnionDefinition + | StructDefinition, + ) => { + const state: IRenderState = { + options: thriftProject.options, + currentNamespace: namespace, + currentDefinitions: exportsForFile([statement]), + project: thriftProject, + } + + const structFile: IGeneratedFile = { + type: 'GeneratedFile', + name: statement.name.value, + path: namespace.namespace.path, + body: renderStatement(statement, state, renderer), + } + + structFile.body = [ + ...renderer.renderImports([statement], state), + ...structFile.body, + ] + + result.push(structFile) + }, + ) + + return result +} + +function generateFilesFromKey( + key: 'constants' | 'typedefs', + namespace: INamespace, + thriftProject: IThriftProject, + renderer: IRenderer, +): Array { + const result: Array = [] + const statements: Array = namespace[key] - cache[cacheKey] = { - outPath: resolvedFile.namespace.path, - namespace: resolvedFile.namespace, - statements, - identifiers, + if (statements.length > 0) { + const constantsFile: IGeneratedFile = { + type: 'GeneratedFile', + name: key, + path: namespace.namespace.path, + body: [], } + + const state: IRenderState = { + options: thriftProject.options, + currentNamespace: namespace, + currentDefinitions: exportsForFile(statements), + project: thriftProject, + } + + statements.forEach((statement: ThriftStatement) => { + constantsFile.body = [ + ...constantsFile.body, + ...renderStatement(statement, state, renderer), + ] + }) + + constantsFile.body = [ + ...renderer.renderImports(statements, state), + ...constantsFile.body, + ] + + result.push(constantsFile) } - return cache[cacheKey] + return result +} + +export function generateProject( + thriftProject: IThriftProject, +): Array { + let result: Array = [] + const renderer: IRenderer = rendererForTarget(thriftProject.options.target) + + Object.keys(thriftProject.namespaces).forEach((namespaceName: string) => { + const namespace: INamespace = thriftProject.namespaces[namespaceName] + + // Generate content for this namespace + result = result.concat( + generateFilesFromKey( + 'constants', + namespace, + thriftProject, + renderer, + ), + generateFilesFromKey( + 'typedefs', + namespace, + thriftProject, + renderer, + ), + generateFileFromStatements( + [ + ...namespace.structs, + ...namespace.unions, + ...namespace.exceptions, + ], + namespace, + thriftProject, + renderer, + ), + generateFileFromStatements( + namespace.services, + namespace, + thriftProject, + renderer, + ), + ) + + // Index file for this namespace + result.push({ + type: 'GeneratedFile', + name: 'index', + path: namespace.namespace.path, + body: renderer.renderIndex({ + options: thriftProject.options, + currentNamespace: namespace, + currentDefinitions: {}, + project: thriftProject, + }), + }) + }) + + return result } diff --git a/src/main/generator/utils.ts b/src/main/generator/utils.ts deleted file mode 100644 index b77a6e08..00000000 --- a/src/main/generator/utils.ts +++ /dev/null @@ -1,80 +0,0 @@ -import * as path from 'path' -import * as ts from 'typescript' - -import { - IRenderedFile, - IRenderedFileMap, - IResolvedIdentifier, - IResolvedIncludeMap, -} from '../types' - -/** - * import { Thrift, TProtocol, TTransport, Int64 } from 'thrift'; - * - * I would really like this to only import what is being used by the file we're - * generating. We'll need to keep track of what each files uses. - */ -export function createThriftImports(): ts.ImportDeclaration { - return ts.createImportDeclaration( - undefined, - undefined, - ts.createImportClause( - undefined, - ts.createNamespaceImport(ts.createIdentifier('thrift')), - ), - ts.createLiteral('thrift'), - ) -} - -/** - * Given a hash of included files this will return a list of import statements. - * - * @param currentPath The path of the file performing imports. Import paths are - * resolved relative to this. - * @param includes A hash of all included files - * @param resolved A hash of include name to a list of ids used from this include - */ -export function createImportsForIncludes( - currentPath: string, - includes: IRenderedFileMap, - resolved: IResolvedIncludeMap, -): Array { - const imports: Array = [] - for (const name of Object.keys(resolved)) { - const resolvedIncludes: Array = - resolved[name].identifiers - const includeFile: IRenderedFile = includes[name] - - if (resolvedIncludes != null && includeFile != null) { - imports.push( - ts.createImportDeclaration( - undefined, - undefined, - ts.createImportClause( - undefined, - ts.createNamedImports( - resolvedIncludes.map( - (next: IResolvedIdentifier) => { - return ts.createImportSpecifier( - ts.createIdentifier(next.name), - ts.createIdentifier(next.resolvedName), - ) - }, - ), - ), - ), - ts.createLiteral( - `./${path.join( - path.relative( - path.dirname(currentPath), - path.dirname(includeFile.outPath), - ), - path.basename(includeFile.outPath, '.ts'), - )}`, - ), - ), - ) - } - } - return imports -} diff --git a/src/main/index.ts b/src/main/index.ts index b4090cac..df62a34b 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -1,48 +1,39 @@ -export * from './types' - import * as path from 'path' +import { parseFromSource, parseThriftFile } from './parser' + import { CompileTarget, - IIncludeCache, + IFileExports, + IGeneratedFile, IMakeOptions, - INamespaceFile, + INamespaceMap, IParsedFile, - IRenderedCache, - IRenderedFile, IRenderState, - IResolvedCache, IResolvedFile, - IThriftFile, + ISourceFile, + IThriftProject, + ParsedFileMap, + ResolvedFileMap, } from './types' -import { print } from './printer' - -import { resolveFile } from './resolver' - -import { validateFile } from './validator' - -import { generateFile, processStatements } from './generator' - -import { rendererForTarget } from './render' - -import { printErrors } from './debugger' - import { mergeWithDefaults } from './defaults' - import { collectInvalidFiles, collectSourceFiles, - dedupResolvedFiles, - flattenResolvedFile, + emptyNamespace, organizeByNamespace, - parseFile, - parseSource, - readThriftFile, saveFiles, } from './utils' -import { DEFAULT_OPTIONS } from './options' +import { printErrors } from './debugger' +import { generateProject, processStatements } from './generator' +import { print } from './printer' +import { readThriftFile } from './reader' +import { rendererForTarget } from './render' +import { resolveFile } from './resolver' +import { exportsForFile } from './resolver/utils' +import { validateFile } from './validator' /** * This function is mostly for testing purposes. It does not support includes. @@ -61,93 +52,137 @@ export function make( target, strictUnions, }) - const parsedFile: IParsedFile = parseSource(source) - const resolvedAST: IResolvedFile = resolveFile( - '', - parsedFile, - DEFAULT_OPTIONS, - ) - const validAST: IResolvedFile = validateFile(resolvedAST) + const parsedFile: IParsedFile = parseFromSource(source, options) + const resolvedFile: IResolvedFile = resolveFile(parsedFile, {}, '', options) + const validatedFile: IResolvedFile = validateFile(resolvedFile, {}, '') + + if (validatedFile.errors.length > 0) { + throw new Error(`Shit broke`) + } + + const fileExports: IFileExports = exportsForFile(resolvedFile.body) const state: IRenderState = { options, - identifiers: validAST.identifiers, + currentNamespace: { + type: 'Namespace', + namespace: emptyNamespace(), + files: { + [resolvedFile.sourceFile.fullPath]: resolvedFile, + }, + exports: fileExports, + includedNamespaces: {}, + constants: [], + typedefs: [], + structs: [], + unions: [], + exceptions: [], + services: [], + }, + currentDefinitions: fileExports, + project: { + type: 'ThriftProject', + rootDir: '', + sourceDir: '', + outDir: '', + namespaces: {}, + options, + }, } + return print( - processStatements(validAST.body, state, rendererForTarget(target)), + processStatements(resolvedFile.body, state, rendererForTarget(target)), ) } -/** - * Generate TypeScript files from Thrift IDL files. The generated TS files will be saved - * based on the options passed in. - * - * rootDir: All file operations are relative to this - * sourceDir: Where to look for Thrift IDL source files - * outDir: Where to save generated TS files - * files: Array of Thrift IDL files to generate from - * - * @param options - */ -export function generate(options: Partial): void { +export async function generate(options: Partial): Promise { const mergedOptions: IMakeOptions = mergeWithDefaults(options) + + // Root at which we operate relative to const rootDir: string = path.resolve(process.cwd(), mergedOptions.rootDir) + + // Where do we save generated files const outDir: string = path.resolve(rootDir, mergedOptions.outDir) - const sourceDir: string = path.resolve(rootDir, mergedOptions.sourceDir) - const includeCache: IIncludeCache = {} - const resolvedCache: IResolvedCache = {} - const renderedCache: IRenderedCache = {} - if (mergedOptions.strictUnions && mergedOptions.strictUnionsComplexNames) { - console.log( - `The behavior of 'strictUnionsComplexNames' is experimental an may change.`, - ) - } + // Where do we read source files + const sourceDir: string = path.resolve(rootDir, mergedOptions.sourceDir) - const validatedFiles: Array = collectSourceFiles( + const fileNames: Array = collectSourceFiles( sourceDir, mergedOptions, - ).reduce((acc: Array, next: string): Array< - IResolvedFile - > => { - const thriftFile: IThriftFile = readThriftFile(next, [sourceDir]) - const parsedFile: IParsedFile = parseFile( - sourceDir, - thriftFile, - includeCache, - ) - const resolvedFile: IResolvedFile = resolveFile( - outDir, - parsedFile, - mergedOptions, - resolvedCache, - ) - return acc.concat(flattenResolvedFile(resolvedFile).map(validateFile)) - }, []) + ) + + const thriftFiles: Array = await Promise.all( + fileNames.map((next: string) => { + return readThriftFile(next, [sourceDir]) + }), + ) + + const parsedFiles: Array = thriftFiles.map( + (next: ISourceFile) => { + const parsed = parseThriftFile(next, mergedOptions) + return parsed + }, + ) - const dedupedFiles: Array = dedupResolvedFiles( - validatedFiles, + const parsedFileMap: ParsedFileMap = parsedFiles.reduce( + (acc: ParsedFileMap, next: IParsedFile) => { + acc[next.sourceFile.fullPath] = next + return acc + }, + {}, ) - const invalidFiles: Array = collectInvalidFiles(dedupedFiles) + const resolvedFiles: Array = parsedFiles.map( + (next: IParsedFile) => { + return resolveFile(next, parsedFileMap, sourceDir, mergedOptions) + }, + ) + + const resolvedInvalidFiles: Array = collectInvalidFiles( + resolvedFiles, + ) - if (invalidFiles.length > 0) { - printErrors(invalidFiles) + if (resolvedInvalidFiles.length > 0) { + printErrors(resolvedInvalidFiles) process.exitCode = 1 } else { - const namespaces: Array = organizeByNamespace( - dedupedFiles, + const resolvedFileMap: ResolvedFileMap = resolvedFiles.reduce( + (acc: ResolvedFileMap, next: IResolvedFile) => { + acc[next.sourceFile.fullPath] = next + return acc + }, + {}, ) - const renderedFiles: Array = namespaces.map( - (next: INamespaceFile): IRenderedFile => { - return generateFile( - rendererForTarget(mergedOptions.target), - next, - mergedOptions, - renderedCache, - ) + const validatedFiles: Array = resolvedFiles.map( + (next: IResolvedFile) => { + return validateFile(next, resolvedFileMap, sourceDir) }, ) - saveFiles(rootDir, outDir, renderedFiles) + const validatedInvalidFiles: Array = collectInvalidFiles( + validatedFiles, + ) + + if (validatedInvalidFiles.length > 0) { + printErrors(validatedInvalidFiles) + process.exitCode = 1 + } else { + const namespaces: INamespaceMap = organizeByNamespace(resolvedFiles) + + const thriftProject: IThriftProject = { + type: 'ThriftProject', + rootDir, + outDir, + sourceDir, + namespaces, + options: mergedOptions, + } + + const generatedFiles: Array = generateProject( + thriftProject, + ) + + saveFiles(generatedFiles, outDir) + } } } diff --git a/src/main/parser/index.ts b/src/main/parser/index.ts new file mode 100644 index 00000000..50180a0f --- /dev/null +++ b/src/main/parser/index.ts @@ -0,0 +1,62 @@ +import { + parse, + SyntaxType, + ThriftDocument, + ThriftErrors, +} from '@creditkarma/thrift-parser' +import { exportsForFile } from '../resolver/utils' +import { + IFileExports, + IFileIncludes, + IMakeOptions, + INamespacePath, + IParsedFile, + ISourceFile, +} from '../types' +import { includesForFile, namespaceForFile } from '../utils' + +export function parseThriftString(source: string): ThriftDocument { + const thrift: ThriftDocument | ThriftErrors = parse(source) + switch (thrift.type) { + case SyntaxType.ThriftDocument: + return thrift + + default: + throw new Error('Unable to parse source: ') + } +} + +export function parseFromSource( + source: string, + options: IMakeOptions, +): IParsedFile { + const sourceFile: ISourceFile = { + type: 'SourceFile', + name: '', + path: '', + fullPath: '', + source, + } + + return parseThriftFile(sourceFile, options) +} + +export function parseThriftFile( + file: ISourceFile, + options: IMakeOptions, +): IParsedFile { + const thriftDoc: ThriftDocument = parseThriftString(file.source) + const exports: IFileExports = exportsForFile(thriftDoc.body) + const namespace: INamespacePath = namespaceForFile(thriftDoc.body, options) + const includes: IFileIncludes = includesForFile(thriftDoc.body, file) + + return { + type: 'ParsedFile', + sourceFile: file, + namespace, + includes, + exports, + body: thriftDoc.body, + errors: [], + } +} diff --git a/src/main/printer.ts b/src/main/printer.ts index 17b22d26..77f6cf44 100644 --- a/src/main/printer.ts +++ b/src/main/printer.ts @@ -36,13 +36,16 @@ export function print( false, ts.ScriptKind.TS, ) + const bodyFile: ts.SourceFile = ts.updateSourceFileNode( rawSourceFile, statements, ) - if (includePreface) { + if (includePreface && statements.length > 0) { generatePreface(statements[0]) + } else { + console.warn(`Printing empty file`) } return printer.printBundle(ts.createBundle([bodyFile])) diff --git a/src/main/reader/index.ts b/src/main/reader/index.ts new file mode 100644 index 00000000..95b6750d --- /dev/null +++ b/src/main/reader/index.ts @@ -0,0 +1,23 @@ +import * as fs from 'fs' +import * as path from 'path' +import { ISourceFile } from '../types' + +export function readThriftFile( + file: string, + searchPaths: Array, +): ISourceFile { + for (const sourcePath of searchPaths) { + const filePath: string = path.resolve(sourcePath, file) + if (fs.existsSync(filePath)) { + return { + type: 'SourceFile', + name: path.basename(filePath, '.thrift'), + path: path.dirname(filePath), + fullPath: filePath, + source: fs.readFileSync(filePath, 'utf-8'), + } + } + } + + throw new Error(`Unable to find file ${file}`) +} diff --git a/src/main/render/apache/const.ts b/src/main/render/apache/const.ts index 6788ed5a..8b56935e 100644 --- a/src/main/render/apache/const.ts +++ b/src/main/render/apache/const.ts @@ -6,6 +6,7 @@ import { TypeMapping } from './types' import { renderValue } from './values' +import { IRenderState } from '../../types' import { createConst } from './utils' /** @@ -20,13 +21,14 @@ import { createConst } from './utils' export function renderConst( node: ConstDefinition, typeMapping: TypeMapping, + state: IRenderState, ): ts.Statement { return ts.createVariableStatement( [ts.createToken(ts.SyntaxKind.ExportKeyword)], createConst( node.name.value, - typeMapping(node.fieldType), - renderValue(node.fieldType, node.initializer), + typeMapping(node.fieldType, state), + renderValue(node.fieldType, node.initializer, state), ), ) } diff --git a/src/main/render/apache/exception.ts b/src/main/render/apache/exception.ts index e5ff0f47..62bb1252 100644 --- a/src/main/render/apache/exception.ts +++ b/src/main/render/apache/exception.ts @@ -2,13 +2,12 @@ import * as ts from 'typescript' import { ExceptionDefinition } from '@creditkarma/thrift-parser' -import { IIdentifierMap } from '../../types' - +import { IRenderState } from '../../types' import { renderStruct } from './struct' export function renderException( node: ExceptionDefinition, - identifiers: IIdentifierMap, + state: IRenderState, ): ts.ClassDeclaration { - return renderStruct(node, identifiers) + return renderStruct(node, state) } diff --git a/src/main/render/apache/includes.ts b/src/main/render/apache/includes.ts index 8a0fcf50..5855012b 100644 --- a/src/main/render/apache/includes.ts +++ b/src/main/render/apache/includes.ts @@ -1,81 +1,7 @@ -import * as path from 'path' import * as ts from 'typescript' -import { - IResolvedFile, - IResolvedIdentifier, - IResolvedIncludeMap, -} from '../../types' - import { COMMON_IDENTIFIERS } from '../shared/identifiers' -const DEFAULT_THRIFT_LIB: string = 'thrift' - -/** - * import { Thrift, TProtocol, TTransport, Int64 } from 'thrift'; - * - * I would really like this to only import what is being used by the file we're - * generating. We'll need to keep track of what each files uses. - */ -export function renderThriftImports( - thriftLib: string = DEFAULT_THRIFT_LIB, -): ts.ImportDeclaration { - return ts.createImportDeclaration( - undefined, - undefined, - ts.createImportClause( - undefined, - ts.createNamespaceImport(COMMON_IDENTIFIERS.thrift), - ), - ts.createLiteral(thriftLib), - ) -} - -/** - * Given a hash of included files this will return a list of import statements. - * - * @param currentPath The path of the file performing imports. Import paths are - * resolved relative to this. - * @param includes A hash of all included files - * @param resolved A hash of include name to a list of ids used from this include - */ -export function renderIncludes( - currentPath: string, - resolved: IResolvedIncludeMap, -): Array { - const imports: Array = [] - - for (const name of Object.keys(resolved)) { - const resolvedIncludes: Array = - resolved[name].identifiers - const includeFile: IResolvedFile = resolved[name].file - - if (resolvedIncludes != null && includeFile != null) { - const includePath: string = includeFile.namespace.path - imports.push( - ts.createImportDeclaration( - undefined, - undefined, - ts.createImportClause( - undefined, - ts.createNamespaceImport(ts.createIdentifier(name)), - ), - ts.createLiteral( - `./${path.join( - path.relative( - path.dirname(currentPath), - path.dirname(includePath), - ), - )}`, - ), - ), - ) - } - } - - return imports -} - /** * import Int64 = require('node-int64'); * diff --git a/src/main/render/apache/index.ts b/src/main/render/apache/index.ts index 88c44033..69c09e1f 100644 --- a/src/main/render/apache/index.ts +++ b/src/main/render/apache/index.ts @@ -6,6 +6,7 @@ import { ExceptionDefinition, ServiceDefinition, StructDefinition, + ThriftStatement, TypedefDefinition, UnionDefinition, } from '@creditkarma/thrift-parser' @@ -22,40 +23,36 @@ import { renderResultStruct, } from './service' -import { fileUsesInt64, fileUsesThrift } from '../shared/includes' -import { renderTypeDef as _renderTypeDef } from '../shared/typedef' -import { renderConst as _renderConst } from './const' -import { renderEnum as _renderEnum } from './enum' import { renderIncludes as _renderIncludes, - renderInt64Import, renderThriftImports, -} from './includes' + statementsUseInt64, + statementsUseThrift, +} from '../shared/includes' +import { renderConst as _renderConst } from './const' +import { renderEnum as _renderEnum } from './enum' +import { renderInt64Import } from './includes' import { renderStruct as _renderStruct } from './struct' +import { renderTypeDef as _renderTypeDef } from './typedef' import { renderUnion as _renderUnion } from './union' -import { - IMakeOptions, - INamespaceFile, - IRenderer, - IRenderState, -} from '../../types' +import { IRenderer, IRenderState } from '../../types' +import { renderIndex } from '../shared' import { typeNodeForFieldType } from './types' -export function renderIncludes( - currentPath: string, - resolvedFile: INamespaceFile, - options: IMakeOptions, +export function renderImports( + statements: Array, + state: IRenderState, ): Array { const includes: Array = [ - ..._renderIncludes(currentPath, resolvedFile.includes), + ..._renderIncludes(statements, state), ] - if (fileUsesThrift(resolvedFile)) { - includes.unshift(renderThriftImports(options.library)) + if (statementsUseThrift(statements)) { + includes.unshift(renderThriftImports(state.options.library)) } - if (fileUsesInt64(resolvedFile)) { + if (statementsUseInt64(statements)) { includes.unshift(renderInt64Import()) } @@ -66,14 +63,14 @@ export function renderConst( statement: ConstDefinition, state: IRenderState, ): Array { - return [_renderConst(statement, typeNodeForFieldType)] + return [_renderConst(statement, typeNodeForFieldType, state)] } export function renderTypeDef( statement: TypedefDefinition, state: IRenderState, ): Array { - return _renderTypeDef(statement, typeNodeForFieldType, state.identifiers) + return _renderTypeDef(statement, typeNodeForFieldType, state) } export function renderEnum( @@ -87,10 +84,7 @@ export function renderStruct( statement: StructDefinition, state: IRenderState, ): Array { - return [ - renderInterface(statement), - _renderStruct(statement, state.identifiers), - ] + return [renderInterface(statement, state), _renderStruct(statement, state)] } export function renderException( @@ -98,8 +92,8 @@ export function renderException( state: IRenderState, ): Array { return [ - renderInterface(statement), - _renderException(statement, state.identifiers), + renderInterface(statement, state), + _renderException(statement, state), ] } @@ -107,10 +101,7 @@ export function renderUnion( statement: UnionDefinition, state: IRenderState, ): Array { - return [ - renderInterface(statement), - _renderUnion(statement, state.identifiers), - ] + return [renderInterface(statement, state), _renderUnion(statement, state)] } export function renderService( @@ -118,24 +109,16 @@ export function renderService( state: IRenderState, ): Array { return [ - ts.createModuleDeclaration( - undefined, - [ts.createToken(ts.SyntaxKind.ExportKeyword)], - ts.createIdentifier(statement.name.value), - ts.createModuleBlock([ - ...renderArgsStruct(statement, state.identifiers), - ...renderResultStruct(statement, state.identifiers), - renderClient(statement), - ...renderHandlerInterface(statement), - renderProcessor(statement, state.identifiers), - ]), - ts.NodeFlags.Namespace, - ), + ...renderArgsStruct(statement, state), + ...renderResultStruct(statement, state), + renderClient(statement, state), + ...renderHandlerInterface(statement, state), + renderProcessor(statement, state), ] } export const renderer: IRenderer = { - renderIncludes, + renderImports, renderConst, renderTypeDef, renderEnum, @@ -143,4 +126,5 @@ export const renderer: IRenderer = { renderException, renderUnion, renderService, + renderIndex, } diff --git a/src/main/render/apache/interface.ts b/src/main/render/apache/interface.ts index b266c58e..9492be97 100644 --- a/src/main/render/apache/interface.ts +++ b/src/main/render/apache/interface.ts @@ -7,6 +7,7 @@ import { import { typeNodeForFieldType } from './types' +import { IRenderState } from '../../types' import { renderOptional } from './utils' /** @@ -36,13 +37,14 @@ export function interfaceNameForClass(statement: InterfaceWithFields): string { */ export function renderInterface( statement: InterfaceWithFields, + state: IRenderState, ): ts.InterfaceDeclaration { const signatures = statement.fields.map((field: FieldDefinition) => { return ts.createPropertySignature( undefined, field.name.value, renderOptional(field.requiredness), - typeNodeForFieldType(field.fieldType, true), + typeNodeForFieldType(field.fieldType, state, true), undefined, ) }) diff --git a/src/main/render/apache/service/client.ts b/src/main/render/apache/service/client.ts index b5ad9517..4eb776e0 100644 --- a/src/main/render/apache/service/client.ts +++ b/src/main/render/apache/service/client.ts @@ -40,7 +40,12 @@ import { typeNodeForFieldType, } from '../types' -export function renderClient(node: ServiceDefinition): ts.ClassDeclaration { +import { IRenderState } from '../../../types' + +export function renderClient( + node: ServiceDefinition, + state: IRenderState, +): ts.ClassDeclaration { // public _seqid: number; const seqid: ts.PropertyDeclaration = createPublicProperty( '_seqid', @@ -127,11 +132,13 @@ export function renderClient(node: ServiceDefinition): ts.ClassDeclaration { ) const baseMethods: Array = node.functions.map( - createBaseMethodForDefinition, + (next: FunctionDefinition) => { + return createBaseMethodForDefinition(next, state) + }, ) const sendMethods: Array = node.functions.map( (next) => { - return createSendMethodForDefinition(node, next) + return createSendMethodForDefinition(next, state) }, ) const recvMethods: Array = node.functions.map( @@ -207,6 +214,7 @@ function createSuperCall(node: ServiceDefinition): Array { // } function createBaseMethodForDefinition( def: FunctionDefinition, + state: IRenderState, ): ts.MethodDeclaration { return ts.createMethod( undefined, // decorators @@ -215,9 +223,11 @@ function createBaseMethodForDefinition( def.name.value, // name undefined, // question token undefined, // type parameters - def.fields.map(createParametersForField), // parameters + def.fields.map((field: FieldDefinition) => { + return createParametersForField(field, state) + }), // parameters ts.createTypeReferenceNode('Promise', [ - typeNodeForFieldType(def.returnType), + typeNodeForFieldType(def.returnType, state), ]), // return type ts.createBlock( [ @@ -234,7 +244,7 @@ function createBaseMethodForDefinition( // return new Promise((resolve, reject) => { ... }) ts.createReturn( createPromise( - typeNodeForFieldType(def.returnType), + typeNodeForFieldType(def.returnType, state), createVoidType(), [ // this._reqs[this.seqid()] = (error, result) => @@ -345,8 +355,8 @@ function createBaseMethodForDefinition( // return this.output.flush() // } function createSendMethodForDefinition( - service: ServiceDefinition, def: FunctionDefinition, + state: IRenderState, ): ts.MethodDeclaration { return ts.createMethod( undefined, // decorators @@ -360,13 +370,13 @@ function createSendMethodForDefinition( const returnType: ts.TypeNode = field.requiredness === 'optional' ? ts.createUnionTypeNode([ - typeNodeForFieldType(field.fieldType), + typeNodeForFieldType(field.fieldType, state), ts.createTypeReferenceNode( ts.createIdentifier('undefined'), undefined, ), ]) - : typeNodeForFieldType(field.fieldType) + : typeNodeForFieldType(field.fieldType, state) return createFunctionParameter( ts.createIdentifier(field.name.value), @@ -701,15 +711,16 @@ function createResultHandler(def: FunctionDefinition): ts.Statement { function createParametersForField( field: FieldDefinition, + state: IRenderState, ): ts.ParameterDeclaration { const defaultValue = field.defaultValue !== null - ? renderValue(field.fieldType, field.defaultValue) + ? renderValue(field.fieldType, field.defaultValue, state) : undefined return createFunctionParameter( field.name.value, - typeNodeForFieldType(field.fieldType), + typeNodeForFieldType(field.fieldType, state), defaultValue, field.requiredness === 'optional', ) diff --git a/src/main/render/apache/service/index.ts b/src/main/render/apache/service/index.ts index 178cd9d0..09ccf479 100644 --- a/src/main/render/apache/service/index.ts +++ b/src/main/render/apache/service/index.ts @@ -18,7 +18,7 @@ import { renderStruct } from '../struct' import { renderInterface } from '../interface' -import { IIdentifierMap } from '../../../types' +import { IRenderState } from '../../../types' function emptyLocation(): TextLocation { return { @@ -29,7 +29,7 @@ function emptyLocation(): TextLocation { export function renderArgsStruct( service: ServiceDefinition, - identifiers: IIdentifierMap, + state: IRenderState, ): Array { return service.functions.reduce( ( @@ -56,8 +56,8 @@ export function renderArgsStruct( return [ ...acc, - renderInterface(argsStruct), - renderStruct(argsStruct, identifiers), + renderInterface(argsStruct, state), + renderStruct(argsStruct, state), ] }, [], @@ -66,7 +66,7 @@ export function renderArgsStruct( export function renderResultStruct( service: ServiceDefinition, - identifiers: IIdentifierMap, + state: IRenderState, ): Array { return service.functions.reduce( ( @@ -125,8 +125,8 @@ export function renderResultStruct( return [ ...acc, - renderInterface(resultStruct), - renderStruct(resultStruct, identifiers), + renderInterface(resultStruct, state), + renderStruct(resultStruct, state), ] }, [], diff --git a/src/main/render/apache/service/processor.ts b/src/main/render/apache/service/processor.ts index 7f44aced..f5429d3c 100644 --- a/src/main/render/apache/service/processor.ts +++ b/src/main/render/apache/service/processor.ts @@ -25,7 +25,11 @@ import { createPublicMethod, } from '../utils' -import { IIdentifierMap } from '../../../types' +import { + resolveIdentifierDefinition, + resolveIdentifierName, +} from '../../../resolver/utils' +import { IRenderState } from '../../../types' import { constructorNameForFieldType, @@ -45,6 +49,7 @@ import { function funcToMethodReducer( acc: Array, func: FunctionDefinition, + state: IRenderState, ): Array { return acc.concat([ ts.createMethodSignature( @@ -53,16 +58,16 @@ function funcToMethodReducer( ...func.fields.map((field: FieldDefinition) => { return createFunctionParameter( field.name.value, - typeNodeForFieldType(field.fieldType), + typeNodeForFieldType(field.fieldType, state), undefined, field.requiredness === 'optional', ) }), ], ts.createUnionTypeNode([ - typeNodeForFieldType(func.returnType), + typeNodeForFieldType(func.returnType, state), ts.createTypeReferenceNode(COMMON_IDENTIFIERS.Promise, [ - typeNodeForFieldType(func.returnType), + typeNodeForFieldType(func.returnType, state), ]), ]), func.name.value, @@ -84,9 +89,12 @@ function funcToMethodReducer( */ export function renderHandlerInterface( service: ServiceDefinition, + state: IRenderState, ): Array { const signatures: Array = service.functions.reduce( - funcToMethodReducer, + (acc: Array, next: FunctionDefinition) => { + return funcToMethodReducer(acc, next, state) + }, [], ) @@ -164,10 +172,10 @@ function handlerType(node: ServiceDefinition): ts.TypeNode { } function createSuperCall( - node: ServiceDefinition, - identifiers: IIdentifierMap, + service: ServiceDefinition, + state: IRenderState, ): Array { - if (node.extends !== null) { + if (service.extends !== null) { return [ ts.createStatement( ts.createCall( @@ -175,7 +183,12 @@ function createSuperCall( [], [ objectLiteralForServiceFunctions( - identifiers[node.extends.value].definition, + resolveIdentifierDefinition( + service.extends, + state.currentNamespace, + state.project.namespaces, + state.project.sourceDir, + ), ), ], ), @@ -188,7 +201,7 @@ function createSuperCall( export function renderProcessor( node: ServiceDefinition, - identifiers: IIdentifierMap, + state: IRenderState, ): ts.ClassDeclaration { // private _handler const handler: ts.PropertyDeclaration = ts.createProperty( @@ -208,7 +221,7 @@ export function renderProcessor( ), ], [ - ...createSuperCall(node, identifiers), + ...createSuperCall(node, state), createAssignmentStatement( ts.createIdentifier('this._handler'), COMMON_IDENTIFIERS.handler, @@ -216,13 +229,10 @@ export function renderProcessor( ], ) - const processMethod: ts.MethodDeclaration = createProcessMethod( - node, - identifiers, - ) + const processMethod: ts.MethodDeclaration = createProcessMethod(node, state) const processFunctions: Array = node.functions.map( (next: FunctionDefinition) => { - return createProcessFunctionMethod(node, next) + return createProcessFunctionMethod(next, state) }, ) @@ -290,8 +300,8 @@ export function renderProcessor( // }) // } function createProcessFunctionMethod( - service: ServiceDefinition, funcDef: FunctionDefinition, + state: IRenderState, ): ts.MethodDeclaration { return createPublicMethod( ts.createIdentifier(`process_${funcDef.name.value}`), @@ -307,7 +317,7 @@ function createProcessFunctionMethod( createMethodCall( createMethodCall( createPromise( - typeNodeForFieldType(funcDef.returnType), + typeNodeForFieldType(funcDef.returnType, state), createVoidType(), [ // try { @@ -382,6 +392,7 @@ function createProcessFunctionMethod( COMMON_IDENTIFIERS.data, typeNodeForFieldType( funcDef.returnType, + state, ), ), ], @@ -478,7 +489,7 @@ function createProcessFunctionMethod( ts.createBlock( [ // if (def.throws.length > 0) - ...createExceptionHandlers(funcDef), + ...createExceptionHandlers(funcDef, state), ], true, ), @@ -515,9 +526,9 @@ function createArgsVariable(funcDef: FunctionDefinition): Array { } function createElseForExceptions( - exp: FieldDefinition, remaining: Array, funcDef: FunctionDefinition, + state: IRenderState, ): ts.Statement { if (remaining.length > 0) { const [next, ...tail] = remaining @@ -525,10 +536,16 @@ function createElseForExceptions( ts.createBinary( COMMON_IDENTIFIERS.err, ts.SyntaxKind.InstanceOfKeyword, - constructorNameForFieldType(next.fieldType), + constructorNameForFieldType( + next.fieldType, + (name: string) => { + return resolveIdentifierName(name, state).fullName + }, + state, + ), ), createThenForException(next, funcDef), - createElseForExceptions(next, tail, funcDef), + createElseForExceptions(tail, funcDef, state), ) } else { return ts.createBlock( @@ -639,6 +656,7 @@ function createThenForException( function createIfForExceptions( exps: Array, funcDef: FunctionDefinition, + state: IRenderState, ): ts.Statement { const [throwDef, ...tail] = exps @@ -646,19 +664,26 @@ function createIfForExceptions( ts.createBinary( COMMON_IDENTIFIERS.err, ts.SyntaxKind.InstanceOfKeyword, - constructorNameForFieldType(throwDef.fieldType), + constructorNameForFieldType( + throwDef.fieldType, + (name: string) => { + return resolveIdentifierName(name, state).fullName + }, + state, + ), ), createThenForException(throwDef, funcDef), - createElseForExceptions(throwDef, tail, funcDef), + createElseForExceptions(tail, funcDef, state), ) } function createExceptionHandlers( funcDef: FunctionDefinition, + state: IRenderState, ): Array { if (funcDef.throws.length > 0) { // if (err instanceof {{throwType}}) { - return [createIfForExceptions(funcDef.throws, funcDef)] + return [createIfForExceptions(funcDef.throws, funcDef, state)] } else { return [ // const result: Thrift.TApplicationException = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN, err.message) @@ -719,7 +744,7 @@ function createExceptionHandlers( // } function createProcessMethod( service: ServiceDefinition, - identifiers: IIdentifierMap, + state: IRenderState, ): ts.MethodDeclaration { return createPublicMethod( COMMON_IDENTIFIERS.process, @@ -760,7 +785,7 @@ function createProcessMethod( COMMON_IDENTIFIERS.fname, ), ), - createMethodCallForFname(service, identifiers), + createMethodCallForFname(service, state), ], // body ) } @@ -804,11 +829,16 @@ function functionsForService(node: ThriftStatement): Array { function collectAllMethods( service: ServiceDefinition, - identifiers: IIdentifierMap, + state: IRenderState, ): Array { if (service.extends !== null) { const inheritedMethods: Array = functionsForService( - identifiers[service.extends.value].definition, + resolveIdentifierDefinition( + service.extends, + state.currentNamespace, + state.project.namespaces, + state.project.sourceDir, + ), ) return [...inheritedMethods, ...service.functions] } else { @@ -842,12 +872,12 @@ function collectAllMethods( */ function createMethodCallForFname( service: ServiceDefinition, - identifiers: IIdentifierMap, + state: IRenderState, ): ts.SwitchStatement { return ts.createSwitch( ts.createIdentifier('methodName'), ts.createCaseBlock([ - ...collectAllMethods(service, identifiers).map( + ...collectAllMethods(service, state).map( createMethodCallForFunction, ), ts.createDefaultClause([ diff --git a/src/main/render/apache/struct/create.ts b/src/main/render/apache/struct/create.ts index e6677daf..f2a16706 100644 --- a/src/main/render/apache/struct/create.ts +++ b/src/main/render/apache/struct/create.ts @@ -6,8 +6,6 @@ import { SyntaxType, } from '@creditkarma/thrift-parser' -import { IIdentifierMap } from '../../../types' - import { createAssignmentStatement, createClassConstructor, @@ -27,14 +25,18 @@ import { typeNodeForFieldType } from '../types' import { interfaceNameForClass } from '../interface' +import { IRenderState } from '../../../types' import { createReadMethod } from './read' import { createWriteMethod } from './write' export function renderStruct( node: InterfaceWithFields, - identifiers: IIdentifierMap, + state: IRenderState, ): ts.ClassDeclaration { - const fields: Array = createFieldsForStruct(node) + const fields: Array = createFieldsForStruct( + node, + state, + ) /** * After creating the properties on our class for the struct fields we must create @@ -64,13 +66,10 @@ export function renderStruct( ) // Build the `read` method - const readMethod: ts.MethodDeclaration = createReadMethod(node, identifiers) + const readMethod: ts.MethodDeclaration = createReadMethod(node, state) // Build the `write` method - const writeMethod: ts.MethodDeclaration = createWriteMethod( - node, - identifiers, - ) + const writeMethod: ts.MethodDeclaration = createWriteMethod(node, state) // export class { ... } return ts.createClassDeclaration( @@ -85,8 +84,11 @@ export function renderStruct( export function createFieldsForStruct( node: InterfaceWithFields, + state: IRenderState, ): Array { - return node.fields.map(renderFieldDeclarations) + return node.fields.map((next: FieldDefinition) => { + return renderFieldDeclarations(next, state) + }) } export function createArgsTypeForStruct( @@ -224,10 +226,11 @@ export function createFieldAssignment(field: FieldDefinition): ts.IfStatement { */ export function renderFieldDeclarations( field: FieldDefinition, + state: IRenderState, ): ts.PropertyDeclaration { const defaultValue = field.defaultValue !== null - ? renderValue(field.fieldType, field.defaultValue) + ? renderValue(field.fieldType, field.defaultValue, state) : undefined return ts.createProperty( @@ -235,7 +238,7 @@ export function renderFieldDeclarations( [ts.createToken(ts.SyntaxKind.PublicKeyword)], ts.createIdentifier(field.name.value), renderOptional(field.requiredness), - typeNodeForFieldType(field.fieldType), + typeNodeForFieldType(field.fieldType, state), defaultValue, ) } diff --git a/src/main/render/apache/struct/read.ts b/src/main/render/apache/struct/read.ts index b6940e6f..854b958e 100644 --- a/src/main/render/apache/struct/read.ts +++ b/src/main/render/apache/struct/read.ts @@ -8,7 +8,7 @@ import { SyntaxType, } from '@creditkarma/thrift-parser' -import { IIdentifierMap, IResolvedIdentifier } from '../../../types' +import { DefinitionType, IRenderState } from '../../../types' import { thriftTypeForFieldType, typeNodeForFieldType } from '../types' @@ -33,6 +33,10 @@ import { createAnyType, createNumberType } from '../types' import { THRIFT_IDENTIFIERS, THRIFT_TYPES } from '../identifiers' +import { + resolveIdentifierDefinition, + resolveIdentifierName, +} from '../../../resolver/utils' import { READ_METHODS } from './methods' /** @@ -70,7 +74,7 @@ import { READ_METHODS } from './methods' */ export function createReadMethod( struct: InterfaceWithFields, - identifiers: IIdentifierMap, + state: IRenderState, ): ts.MethodDeclaration { const inputParameter: ts.ParameterDeclaration = createInputParameter() const tempVariable: Array = createTempVariable(struct) @@ -120,7 +124,7 @@ export function createReadMethod( COMMON_IDENTIFIERS.fieldId, // what to switch on ts.createCaseBlock([ ...struct.fields.map((next: FieldDefinition) => { - return createCaseForField(next, identifiers) + return createCaseForField(next, state) }), ts.createDefaultClause([createSkipBlock()]), ]), @@ -260,21 +264,17 @@ export function createInputParameter(): ts.ParameterDeclaration { */ export function createCaseForField( field: FieldDefinition, - identifiers: IIdentifierMap, + state: IRenderState, ): ts.CaseClause { const fieldAlias: ts.Identifier = ts.createUniqueName('value') const checkType: ts.IfStatement = ts.createIf( createEqualsCheck( COMMON_IDENTIFIERS.fieldType, - thriftTypeForFieldType(field.fieldType, identifiers), + thriftTypeForFieldType(field.fieldType, state), ), ts.createBlock( [ - ...readValueForFieldType( - field.fieldType, - fieldAlias, - identifiers, - ), + ...readValueForFieldType(field.fieldType, fieldAlias, state), ...endReadForField(fieldAlias, field), ], true, @@ -375,7 +375,7 @@ function readEndForFieldType(fieldType: ContainerType): ts.CallExpression { function loopBody( fieldType: ContainerType, fieldName: ts.Identifier, - identifiers: IIdentifierMap, + state: IRenderState, ): Array { const value: ts.Identifier = ts.createUniqueName('value') @@ -383,32 +383,20 @@ function loopBody( case SyntaxType.MapType: const key: ts.Identifier = ts.createUniqueName('key') return [ - ...readValueForFieldType(fieldType.keyType, key, identifiers), - ...readValueForFieldType( - fieldType.valueType, - value, - identifiers, - ), + ...readValueForFieldType(fieldType.keyType, key, state), + ...readValueForFieldType(fieldType.valueType, value, state), createMethodCallStatement(fieldName, 'set', [key, value]), ] case SyntaxType.ListType: return [ - ...readValueForFieldType( - fieldType.valueType, - value, - identifiers, - ), + ...readValueForFieldType(fieldType.valueType, value, state), createMethodCallStatement(fieldName, 'push', [value]), ] case SyntaxType.SetType: return [ - ...readValueForFieldType( - fieldType.valueType, - value, - identifiers, - ), + ...readValueForFieldType(fieldType.valueType, value, state), createMethodCallStatement(fieldName, 'add', [value]), ] } @@ -436,7 +424,7 @@ function loopBody( function loopOverContainer( fieldType: ContainerType, fieldName: ts.Identifier, - identifiers: IIdentifierMap, + state: IRenderState, ): Array { const incrementer: ts.Identifier = ts.createUniqueName('i') const metadata: ts.Identifier = ts.createUniqueName('metadata') @@ -460,30 +448,27 @@ function loopOverContainer( createLet(incrementer, createNumberType(), ts.createLiteral(0)), ts.createLessThan(incrementer, size), ts.createPostfixIncrement(incrementer), - ts.createBlock(loopBody(fieldType, fieldName, identifiers), true), + ts.createBlock(loopBody(fieldType, fieldName, state), true), ), ts.createStatement(readEndForFieldType(fieldType)), ] } export function readValueForIdentifier( - id: IResolvedIdentifier, + baseName: string, + definition: DefinitionType, fieldType: FunctionType, fieldName: ts.Identifier, - identifiers: IIdentifierMap, + state: IRenderState, ): Array { - switch (id.definition.type) { + switch (definition.type) { case SyntaxType.ConstDefinition: throw new TypeError( - `Identifier ${ - id.definition.name.value - } is a value being used as a type`, + `Identifier ${baseName} is a value being used as a type`, ) case SyntaxType.ServiceDefinition: - throw new TypeError( - `Service ${id.definition.name.value} is being used as a type`, - ) + throw new TypeError(`Service ${baseName} is being used as a type`) case SyntaxType.StructDefinition: case SyntaxType.UnionDefinition: @@ -491,10 +476,12 @@ export function readValueForIdentifier( return [ createConstStatement( fieldName, - typeNodeForFieldType(fieldType), + typeNodeForFieldType(fieldType, state), ts.createCall( ts.createPropertyAccess( - ts.createIdentifier(id.resolvedName), + ts.createIdentifier( + resolveIdentifierName(baseName, state).fullName, + ), COMMON_IDENTIFIERS.read, ), undefined, @@ -507,7 +494,7 @@ export function readValueForIdentifier( return [ createConstStatement( fieldName, - typeNodeForFieldType(fieldType), + typeNodeForFieldType(fieldType, state), createMethodCall( 'input', READ_METHODS[SyntaxType.I32Keyword], @@ -517,13 +504,13 @@ export function readValueForIdentifier( case SyntaxType.TypedefDefinition: return readValueForFieldType( - id.definition.definitionType, + definition.definitionType, fieldName, - identifiers, + state, ) default: - const msg: never = id.definition + const msg: never = definition throw new Error(`Non-exhaustive match for: ${msg}`) } } @@ -531,15 +518,21 @@ export function readValueForIdentifier( export function readValueForFieldType( fieldType: FunctionType, fieldName: ts.Identifier, - identifiers: IIdentifierMap, + state: IRenderState, ): Array { switch (fieldType.type) { case SyntaxType.Identifier: return readValueForIdentifier( - identifiers[fieldType.value], + fieldType.value, + resolveIdentifierDefinition( + fieldType, + state.currentNamespace, + state.project.namespaces, + state.project.sourceDir, + ), fieldType, fieldName, - identifiers, + state, ) /** @@ -562,7 +555,7 @@ export function readValueForFieldType( return [ createConstStatement( fieldName, - typeNodeForFieldType(fieldType), + typeNodeForFieldType(fieldType, state), createMethodCall('input', READ_METHODS[fieldType.type]), ), ] @@ -576,45 +569,45 @@ export function readValueForFieldType( return [ createConstStatement( fieldName, - typeNodeForFieldType(fieldType), + typeNodeForFieldType(fieldType, state), ts.createNew( COMMON_IDENTIFIERS.Map, // class name [ - typeNodeForFieldType(fieldType.keyType), - typeNodeForFieldType(fieldType.valueType), + typeNodeForFieldType(fieldType.keyType, state), + typeNodeForFieldType(fieldType.valueType, state), ], [], ), ), - ...loopOverContainer(fieldType, fieldName, identifiers), + ...loopOverContainer(fieldType, fieldName, state), ] case SyntaxType.ListType: return [ createConstStatement( fieldName, - typeNodeForFieldType(fieldType), + typeNodeForFieldType(fieldType, state), ts.createNew( COMMON_IDENTIFIERS.Array, // class name - [typeNodeForFieldType(fieldType.valueType)], + [typeNodeForFieldType(fieldType.valueType, state)], [], ), ), - ...loopOverContainer(fieldType, fieldName, identifiers), + ...loopOverContainer(fieldType, fieldName, state), ] case SyntaxType.SetType: return [ createConstStatement( fieldName, - typeNodeForFieldType(fieldType), + typeNodeForFieldType(fieldType, state), ts.createNew( COMMON_IDENTIFIERS.Set, // class name - [typeNodeForFieldType(fieldType.valueType)], + [typeNodeForFieldType(fieldType.valueType, state)], [], ), ), - ...loopOverContainer(fieldType, fieldName, identifiers), + ...loopOverContainer(fieldType, fieldName, state), ] case SyntaxType.VoidKeyword: diff --git a/src/main/render/apache/struct/write.ts b/src/main/render/apache/struct/write.ts index a47d6d95..2d414836 100644 --- a/src/main/render/apache/struct/write.ts +++ b/src/main/render/apache/struct/write.ts @@ -11,7 +11,7 @@ import { SyntaxType, } from '@creditkarma/thrift-parser' -import { IIdentifierMap, IResolvedIdentifier } from '../../../types' +import { DefinitionType, IRenderState } from '../../../types' import { createFunctionParameter, @@ -30,6 +30,7 @@ import { import { COMMON_IDENTIFIERS, THRIFT_IDENTIFIERS } from '../identifiers' +import { resolveIdentifierDefinition } from '../../../resolver/utils' import { WRITE_METHODS, WriteMethodName } from './methods' function isNotVoid(field: FieldDefinition): boolean { @@ -51,12 +52,12 @@ function isNotVoid(field: FieldDefinition): boolean { */ export function createWriteMethod( struct: InterfaceWithFields, - identifiers: IIdentifierMap, + state: IRenderState, ): ts.MethodDeclaration { const fieldWrites: Array = struct.fields .filter(isNotVoid) .map((field) => { - return createWriteForField(struct, field, identifiers) + return createWriteForField(struct, field, state) }) const inputParameter: ts.ParameterDeclaration = createFunctionParameter( COMMON_IDENTIFIERS.output, @@ -100,7 +101,7 @@ export function createWriteMethod( export function createWriteForField( struct: InterfaceWithFields, field: FieldDefinition, - identifiers: IIdentifierMap, + state: IRenderState, ): ts.IfStatement { return ts.createIf( createNotNullCheck(`this.${field.name.value}`), // Condition @@ -108,7 +109,7 @@ export function createWriteForField( struct, field, ts.createIdentifier(`this.${field.name.value}`), - identifiers, + state, ), // Then block undefined, // Else block ) @@ -127,33 +128,32 @@ export function createWriteForFieldType( struct: InterfaceWithFields, field: FieldDefinition, fieldName: ts.Identifier, - identifiers: IIdentifierMap, + state: IRenderState, ): ts.Block { return ts.createBlock([ - writeFieldBegin(field, identifiers), - ...writeValueForField(struct, field.fieldType, fieldName, identifiers), + writeFieldBegin(field, state), + ...writeValueForField(struct, field.fieldType, fieldName, state), writeFieldEnd(), ]) } -function writeValueForIdentifier( - id: IResolvedIdentifier, - struct: InterfaceWithFields, - fieldType: FunctionType, +export function writeValueForIdentifier( + definition: DefinitionType, + node: InterfaceWithFields, fieldName: ts.Identifier, - identifiers: IIdentifierMap, + state: IRenderState, ): Array { - switch (id.definition.type) { + switch (definition.type) { case SyntaxType.ConstDefinition: throw new TypeError( `Identifier ${ - id.definition.name.value + definition.name.value } is a value being used as a type`, ) case SyntaxType.ServiceDefinition: throw new TypeError( - `Service ${id.definition.name.value} is being used as a type`, + `Service ${definition.name.value} is being used as a type`, ) case SyntaxType.StructDefinition: @@ -175,14 +175,14 @@ function writeValueForIdentifier( case SyntaxType.TypedefDefinition: return writeValueForType( - struct, - id.definition.definitionType, + node, + definition.definitionType, fieldName, - identifiers, + state, ) default: - const msg: never = id.definition + const msg: never = definition throw new Error(`Non-exhaustive match for: ${msg}`) } } @@ -191,16 +191,20 @@ export function writeValueForType( struct: InterfaceWithFields, fieldType: FunctionType, fieldName: ts.Identifier, - identifiers: IIdentifierMap, + state: IRenderState, ): Array { switch (fieldType.type) { case SyntaxType.Identifier: return writeValueForIdentifier( - identifiers[fieldType.value], + resolveIdentifierDefinition( + fieldType, + state.currentNamespace, + state.project.namespaces, + state.project.sourceDir, + ), struct, - fieldType, fieldName, - identifiers, + state, ) /** @@ -210,22 +214,22 @@ export function writeValueForType( */ case SyntaxType.SetType: return [ - writeSetBegin(fieldType, fieldName, identifiers), - forEach(struct, fieldType, fieldName, identifiers), + writeSetBegin(fieldType, fieldName, state), + forEach(struct, fieldType, fieldName, state), writeSetEnd(), ] case SyntaxType.MapType: return [ - writeMapBegin(fieldType, fieldName, identifiers), - forEach(struct, fieldType, fieldName, identifiers), + writeMapBegin(fieldType, fieldName, state), + forEach(struct, fieldType, fieldName, state), writeMapEnd(), ] case SyntaxType.ListType: return [ - writeListBegin(fieldType, fieldName, identifiers), - forEach(struct, fieldType, fieldName, identifiers), + writeListBegin(fieldType, fieldName, state), + forEach(struct, fieldType, fieldName, state), writeListEnd(), ] @@ -269,9 +273,9 @@ function writeValueForField( struct: InterfaceWithFields, fieldType: FunctionType, fieldName: ts.Identifier, - identifiers: IIdentifierMap, + state: IRenderState, ): Array { - return writeValueForType(struct, fieldType, fieldName, identifiers).map( + return writeValueForType(struct, fieldType, fieldName, state).map( ts.createStatement, ) } @@ -295,18 +299,18 @@ function forEach( struct: InterfaceWithFields, fieldType: ContainerType, fieldName: ts.Identifier, - identifiers: IIdentifierMap, + state: IRenderState, ): ts.CallExpression { const value: ts.Identifier = ts.createUniqueName('value') const forEachParameters: Array = [ createFunctionParameter( value, - typeNodeForFieldType(fieldType.valueType), + typeNodeForFieldType(fieldType.valueType, state), ), ] const forEachStatements: Array = [ - ...writeValueForField(struct, fieldType.valueType, value, identifiers), + ...writeValueForField(struct, fieldType.valueType, value, state), ] // If map we have to handle key type as well as value type @@ -315,12 +319,12 @@ function forEach( forEachParameters.push( createFunctionParameter( key, - typeNodeForFieldType(fieldType.keyType), + typeNodeForFieldType(fieldType.keyType, state), ), ) forEachStatements.unshift( - ...writeValueForField(struct, fieldType.keyType, key, identifiers), + ...writeValueForField(struct, fieldType.keyType, key, state), ) } @@ -352,11 +356,11 @@ function writeStructEnd(): ts.ExpressionStatement { function writeMapBegin( fieldType: MapType, fieldName: string | ts.Identifier, - identifiers: IIdentifierMap, + state: IRenderState, ): ts.CallExpression { return createMethodCall('output', 'writeMapBegin', [ - thriftTypeForFieldType(fieldType.keyType, identifiers), - thriftTypeForFieldType(fieldType.valueType, identifiers), + thriftTypeForFieldType(fieldType.keyType, state), + thriftTypeForFieldType(fieldType.valueType, state), propertyAccessForIdentifier(fieldName, 'size'), ]) } @@ -370,10 +374,10 @@ function writeMapEnd(): ts.CallExpression { function writeListBegin( fieldType: ListType, fieldName: string | ts.Identifier, - identifiers: IIdentifierMap, + state: IRenderState, ): ts.CallExpression { return createMethodCall('output', 'writeListBegin', [ - thriftTypeForFieldType(fieldType.valueType, identifiers), + thriftTypeForFieldType(fieldType.valueType, state), propertyAccessForIdentifier(fieldName, 'length'), ]) } @@ -387,10 +391,10 @@ function writeListEnd(): ts.CallExpression { function writeSetBegin( fieldType: SetType, fieldName: string | ts.Identifier, - identifiers: IIdentifierMap, + state: IRenderState, ): ts.CallExpression { return createMethodCall('output', 'writeSetBegin', [ - thriftTypeForFieldType(fieldType.valueType, identifiers), + thriftTypeForFieldType(fieldType.valueType, state), propertyAccessForIdentifier(fieldName, 'size'), ]) } @@ -403,12 +407,12 @@ function writeSetEnd(): ts.CallExpression { // output.writeFieldBegin(, , ) function writeFieldBegin( field: FieldDefinition, - identifiers: IIdentifierMap, + state: IRenderState, ): ts.ExpressionStatement { if (field.fieldID !== null) { return createMethodCallStatement('output', 'writeFieldBegin', [ ts.createLiteral(field.name.value), - thriftTypeForFieldType(field.fieldType, identifiers), + thriftTypeForFieldType(field.fieldType, state), ts.createLiteral(field.fieldID.value), ]) } else { diff --git a/src/main/render/shared/typedef.ts b/src/main/render/apache/typedef.ts similarity index 75% rename from src/main/render/shared/typedef.ts rename to src/main/render/apache/typedef.ts index 3ced962f..5b1a7799 100644 --- a/src/main/render/shared/typedef.ts +++ b/src/main/render/apache/typedef.ts @@ -4,7 +4,8 @@ import { SyntaxType, TypedefDefinition } from '@creditkarma/thrift-parser' import { TypeMapping } from './types' -import { IIdentifierMap, IResolvedIdentifier } from '../../types' +import { resolveIdentifierName } from '../../resolver/utils' +import { IRenderState, IResolvedIdentifier } from '../../types' function renderTypeDefForIdentifier( id: IResolvedIdentifier, @@ -15,7 +16,7 @@ function renderTypeDefForIdentifier( undefined, [ts.createToken(ts.SyntaxKind.ExportKeyword)], ts.createIdentifier(node.name.value), - ts.createIdentifier(id.resolvedName), + ts.createIdentifier(id.fullName), ), ] } @@ -23,12 +24,12 @@ function renderTypeDefForIdentifier( export function renderTypeDef( node: TypedefDefinition, typeMapping: TypeMapping, - identifiers: IIdentifierMap, + state: IRenderState, ): Array { switch (node.definitionType.type) { case SyntaxType.Identifier: return renderTypeDefForIdentifier( - identifiers[node.definitionType.value], + resolveIdentifierName(node.definitionType.value, state), node, ) @@ -39,7 +40,7 @@ export function renderTypeDef( [ts.createToken(ts.SyntaxKind.ExportKeyword)], node.name.value, undefined, - typeMapping(node.definitionType), + typeMapping(node.definitionType, state), ), ] } diff --git a/src/main/render/apache/types.ts b/src/main/render/apache/types.ts index 54b42e92..637c32ac 100644 --- a/src/main/render/apache/types.ts +++ b/src/main/render/apache/types.ts @@ -2,7 +2,7 @@ import * as ts from 'typescript' import { FunctionType, SyntaxType } from '@creditkarma/thrift-parser' -import { IIdentifierMap, IResolvedIdentifier } from '../../types' +import { DefinitionType, IRenderState } from '../../types' import { APPLICATION_EXCEPTION, @@ -11,6 +11,10 @@ import { THRIFT_TYPES, } from './identifiers' +import { + resolveIdentifierDefinition, + resolveIdentifierName, +} from '../../resolver/utils' import { createBooleanType, createNumberType, @@ -99,20 +103,20 @@ export function applicationException( } function thriftTypeForIdentifier( - id: IResolvedIdentifier, - identifiers: IIdentifierMap, + definition: DefinitionType, + state: IRenderState, ): ts.Identifier { - switch (id.definition.type) { + switch (definition.type) { case SyntaxType.ConstDefinition: throw new TypeError( `Identifier ${ - id.definition.name.value + definition.name.value } is a value being used as a type`, ) case SyntaxType.ServiceDefinition: throw new TypeError( - `Service ${id.definition.name.value} is being used as a type`, + `Service ${definition.name.value} is being used as a type`, ) case SyntaxType.StructDefinition: @@ -124,13 +128,10 @@ function thriftTypeForIdentifier( return THRIFT_TYPES.I32 case SyntaxType.TypedefDefinition: - return thriftTypeForFieldType( - id.definition.definitionType, - identifiers, - ) + return thriftTypeForFieldType(definition.definitionType, state) default: - const msg: never = id.definition + const msg: never = definition throw new Error(`Non-exhaustive match for: ${msg}`) } } @@ -147,13 +148,18 @@ function thriftTypeForIdentifier( */ export function thriftTypeForFieldType( fieldType: FunctionType, - identifiers: IIdentifierMap, + state: IRenderState, ): ts.Identifier { switch (fieldType.type) { case SyntaxType.Identifier: return thriftTypeForIdentifier( - identifiers[fieldType.value], - identifiers, + resolveIdentifierDefinition( + fieldType, + state.currentNamespace, + state.project.namespaces, + state.project.sourceDir, + ), + state, ) case SyntaxType.SetType: @@ -226,26 +232,30 @@ export function thriftTypeForFieldType( */ export function typeNodeForFieldType( fieldType: FunctionType, + state: IRenderState, loose: boolean = false, ): ts.TypeNode { switch (fieldType.type) { case SyntaxType.Identifier: - return ts.createTypeReferenceNode(fieldType.value, undefined) + return ts.createTypeReferenceNode( + resolveIdentifierName(fieldType.value, state).fullName, + undefined, + ) case SyntaxType.SetType: return ts.createTypeReferenceNode(COMMON_IDENTIFIERS.Set, [ - typeNodeForFieldType(fieldType.valueType), + typeNodeForFieldType(fieldType.valueType, state, loose), ]) case SyntaxType.MapType: return ts.createTypeReferenceNode(COMMON_IDENTIFIERS.Map, [ - typeNodeForFieldType(fieldType.keyType), - typeNodeForFieldType(fieldType.valueType), + typeNodeForFieldType(fieldType.keyType, state, loose), + typeNodeForFieldType(fieldType.valueType, state, loose), ]) case SyntaxType.ListType: return ts.createTypeReferenceNode(COMMON_IDENTIFIERS.Array, [ - typeNodeForFieldType(fieldType.valueType), + typeNodeForFieldType(fieldType.valueType, state, loose), ]) case SyntaxType.StringKeyword: diff --git a/src/main/render/apache/union.ts b/src/main/render/apache/union.ts index 73c25582..dc67deec 100644 --- a/src/main/render/apache/union.ts +++ b/src/main/render/apache/union.ts @@ -6,8 +6,6 @@ import { UnionDefinition, } from '@creditkarma/thrift-parser' -import { IIdentifierMap } from '../../types' - import { thriftTypeForFieldType, typeNodeForFieldType } from './types' import { @@ -44,6 +42,8 @@ import { THRIFT_TYPES, } from './identifiers' +import { IRenderState } from '../../types' + /** * There is a lot of duplication here of code with renderStruct. Need to revisit and clean this up. * Probably revisit how functions are defined in the struct rendering code so that it is easier @@ -51,9 +51,12 @@ import { */ export function renderUnion( node: UnionDefinition, - identifiers: IIdentifierMap, + state: IRenderState, ): ts.ClassDeclaration { - const fields: Array = createFieldsForStruct(node) + const fields: Array = createFieldsForStruct( + node, + state, + ) /** * After creating the properties on our class for the struct fields we must create @@ -105,17 +108,14 @@ export function renderUnion( const factories: Array = createUnionFactories( node, - identifiers, + state, ) // Build the `read` method - const readMethod: ts.MethodDeclaration = createReadMethod(node, identifiers) + const readMethod: ts.MethodDeclaration = createReadMethod(node, state) // Build the `write` method - const writeMethod: ts.MethodDeclaration = createWriteMethod( - node, - identifiers, - ) + const writeMethod: ts.MethodDeclaration = createWriteMethod(node, state) // export class { ... } return ts.createClassDeclaration( @@ -138,7 +138,7 @@ function createFactoryNameForField(field: FieldDefinition): string { function createUnionFactories( node: UnionDefinition, - identifiers: IIdentifierMap, + state: IRenderState, ): Array { return node.fields.map( (next: FieldDefinition): ts.MethodDeclaration => { @@ -155,7 +155,7 @@ function createUnionFactories( [ createFunctionParameter( ts.createIdentifier(next.name.value), - typeNodeForFieldType(next.fieldType), + typeNodeForFieldType(next.fieldType, state), ), ], ts.createTypeReferenceNode( @@ -215,7 +215,7 @@ function createFieldAssignment(field: FieldDefinition): ts.IfStatement { function createReadMethod( node: UnionDefinition, - identifiers: IIdentifierMap, + state: IRenderState, ): ts.MethodDeclaration { const inputParameter: ts.ParameterDeclaration = createInputParameter() const returnVariable: ts.VariableStatement = createLetStatement( @@ -266,7 +266,7 @@ function createReadMethod( const caseStatements: Array = node.fields.map( (field: FieldDefinition) => { - return createCaseForField(node, field, identifiers) + return createCaseForField(node, field, state) }, ) @@ -358,22 +358,18 @@ function createReadMethod( export function createCaseForField( node: UnionDefinition, field: FieldDefinition, - identifiers: IIdentifierMap, + state: IRenderState, ): ts.CaseClause { const fieldAlias: ts.Identifier = ts.createUniqueName('value') const checkType: ts.IfStatement = ts.createIf( createEqualsCheck( COMMON_IDENTIFIERS.fieldType, - thriftTypeForFieldType(field.fieldType, identifiers), + thriftTypeForFieldType(field.fieldType, state), ), ts.createBlock( [ incrementFieldsSet(), - ...readValueForFieldType( - field.fieldType, - fieldAlias, - identifiers, - ), + ...readValueForFieldType(field.fieldType, fieldAlias, state), ...endReadForField(node, fieldAlias, field), ], true, diff --git a/src/main/render/apache/values.ts b/src/main/render/apache/values.ts index 6968bb76..f7e353e9 100644 --- a/src/main/render/apache/values.ts +++ b/src/main/render/apache/values.ts @@ -16,15 +16,20 @@ import { import { COMMON_IDENTIFIERS } from './identifiers' +import { resolveIdentifierName } from '../../resolver/utils' +import { IRenderState } from '../../types' import { propertyAccessForIdentifier } from './utils' export function renderValue( fieldType: FunctionType, node: ConstValue, + state: IRenderState, ): ts.Expression { switch (node.type) { case SyntaxType.Identifier: - return ts.createIdentifier(node.value) + return ts.createIdentifier( + resolveIdentifierName(node.value, state).fullName, + ) case SyntaxType.IntConstant: return renderIntConstant(node, fieldType) @@ -44,16 +49,16 @@ export function renderValue( case SyntaxType.ConstList: if (fieldType.type === SyntaxType.ListType) { - return renderList(fieldType, node) + return renderList(fieldType, node, state) } else if (fieldType.type === SyntaxType.SetType) { - return renderSet(fieldType, node) + return renderSet(fieldType, node, state) } else { throw new TypeError(`Type list | set expected`) } case SyntaxType.ConstMap: if (fieldType.type === SyntaxType.MapType) { - return renderMap(fieldType, node) + return renderMap(fieldType, node, state) } else { throw new TypeError(`Type map expected`) } @@ -106,11 +111,15 @@ export function renderDoubleConstant(node: DoubleConstant): ts.Expression { } } -function renderMap(fieldType: MapType, node: ConstMap): ts.NewExpression { +function renderMap( + fieldType: MapType, + node: ConstMap, + state: IRenderState, +): ts.NewExpression { const values = node.properties.map(({ name, initializer }) => { return ts.createArrayLiteral([ - renderValue(fieldType.keyType, name), - renderValue(fieldType.valueType, initializer), + renderValue(fieldType.keyType, name, state), + renderValue(fieldType.valueType, initializer, state), ]) }) @@ -119,10 +128,14 @@ function renderMap(fieldType: MapType, node: ConstMap): ts.NewExpression { ]) } -function renderSet(fieldType: SetType, node: ConstList): ts.NewExpression { +function renderSet( + fieldType: SetType, + node: ConstList, + state: IRenderState, +): ts.NewExpression { const values: Array = node.elements.map( (val: ConstValue) => { - return renderValue(fieldType.valueType, val) + return renderValue(fieldType.valueType, val, state) }, ) @@ -134,10 +147,11 @@ function renderSet(fieldType: SetType, node: ConstList): ts.NewExpression { function renderList( fieldType: ListType, node: ConstList, + state: IRenderState, ): ts.ArrayLiteralExpression { const values: Array = node.elements.map( (val: ConstValue) => { - return renderValue(fieldType.valueType, val) + return renderValue(fieldType.valueType, val, state) }, ) diff --git a/src/main/render/index.ts b/src/main/render/index.ts index 4e46474b..41c517d1 100644 --- a/src/main/render/index.ts +++ b/src/main/render/index.ts @@ -6,12 +6,12 @@ import { CompileTarget, IRenderer } from '../types' export function rendererForTarget(target: CompileTarget = 'apache'): IRenderer { switch (target) { - case 'apache': - return ApacheRenderer - case 'thrift-server': return ThriftRenderer + case 'apache': + return ApacheRenderer + default: const msg: never = target throw new Error(`Non-exhaustive match for ${msg}`) diff --git a/src/main/render/shared/identifiers.ts b/src/main/render/shared/identifiers.ts index cbc4682a..e27d6c56 100644 --- a/src/main/render/shared/identifiers.ts +++ b/src/main/render/shared/identifiers.ts @@ -1,6 +1,8 @@ import * as ts from 'typescript' export const COMMON_IDENTIFIERS = { + __NAMESPACE__: ts.createIdentifier('__NAMESPACE__'), + methodName: ts.createIdentifier('methodName'), __type: ts.createIdentifier('__type'), _fieldsSet: ts.createIdentifier('_fieldsSet'), _returnValue: ts.createIdentifier('_returnValue'), diff --git a/src/main/render/shared/includes.ts b/src/main/render/shared/includes.ts index 003a6b39..cee09df4 100644 --- a/src/main/render/shared/includes.ts +++ b/src/main/render/shared/includes.ts @@ -1,3 +1,6 @@ +import * as path from 'path' +import * as ts from 'typescript' + import { ConstDefinition, FieldDefinition, @@ -7,7 +10,9 @@ import { TypedefDefinition, } from '@creditkarma/thrift-parser' -import { INamespaceFile } from '../../types' +import { INamespacePath, IRenderState } from '../../types' +import { identifiersForStatements } from '../../utils' +import { COMMON_IDENTIFIERS } from './identifiers' function constUsesThrift(statement: ConstDefinition): boolean { return statement.fieldType.type === SyntaxType.I64Keyword @@ -85,8 +90,10 @@ function statementUsesInt64(statement: ThriftStatement): boolean { } } -export function fileUsesThrift(resolvedFile: INamespaceFile): boolean { - for (const statement of resolvedFile.body) { +export function statementsUseThrift( + statements: Array, +): boolean { + for (const statement of statements) { if (statementUsesThrift(statement)) { return true } @@ -95,8 +102,10 @@ export function fileUsesThrift(resolvedFile: INamespaceFile): boolean { return false } -export function fileUsesInt64(resolvedFile: INamespaceFile): boolean { - for (const statement of resolvedFile.body) { +export function statementsUseInt64( + statements: Array, +): boolean { + for (const statement of statements) { if (statementUsesInt64(statement)) { return true } @@ -104,3 +113,97 @@ export function fileUsesInt64(resolvedFile: INamespaceFile): boolean { return false } + +/** + * import * as thrift from 'thrift'; + * + * I would really like this to only import what is being used by the file we're + * generating. We'll need to keep track of what each files uses. + */ +export function renderThriftImports(thriftLib: string): ts.ImportDeclaration { + return ts.createImportDeclaration( + undefined, + undefined, + ts.createImportClause( + undefined, + ts.createNamespaceImport(COMMON_IDENTIFIERS.thrift), + ), + ts.createLiteral(thriftLib), + ) +} + +/** + * Given a hash of included files this will return a list of import statements. + * + * @param currentPath The path of the file performing imports. Import paths are + * resolved relative to this. + * @param includes A hash of all included files + * @param resolved A hash of include name to a list of ids used from this include + */ +export function renderIncludes( + statements: Array, + state: IRenderState, +): Array { + const importedNamespaces: Set = new Set() + const imports: Array = [] + const identifiers: Array = identifiersForStatements(statements) + let importNamespace: boolean = false + + identifiers.forEach((next: string) => { + const [head] = next.split('.') + if ( + state.currentNamespace.exports[head] && + state.currentDefinitions[head] === undefined + ) { + importNamespace = true + } else if ( + state.currentNamespace.includedNamespaces[head] !== undefined + ) { + if (!importedNamespaces.has(head)) { + importedNamespaces.add(head) + + const includedNamespace: INamespacePath = + state.currentNamespace.includedNamespaces[head] + + imports.push( + ts.createImportDeclaration( + undefined, + undefined, + ts.createImportClause( + undefined, + ts.createNamespaceImport(ts.createIdentifier(head)), + ), + ts.createLiteral( + `./${path.relative( + path.resolve( + state.project.outDir, + state.currentNamespace.namespace.path, + ), + path.resolve( + state.project.outDir, + includedNamespace.path, + ), + )}`, + ), + ), + ) + } + } + }) + + if (importNamespace) { + imports.push( + ts.createImportDeclaration( + undefined, + undefined, + ts.createImportClause( + undefined, + ts.createNamespaceImport(COMMON_IDENTIFIERS.__NAMESPACE__), + ), + ts.createLiteral(`./.`), + ), + ) + } + + return imports +} diff --git a/src/main/render/shared/index.ts b/src/main/render/shared/index.ts new file mode 100644 index 00000000..7e36d095 --- /dev/null +++ b/src/main/render/shared/index.ts @@ -0,0 +1,77 @@ +import * as ts from 'typescript' + +import { + InterfaceWithFields, + ServiceDefinition, +} from '@creditkarma/thrift-parser' + +import { INamespace, IRenderState } from '../../types' + +export function renderIndex(state: IRenderState): Array { + const currentNamespace: INamespace = state.currentNamespace + const results: Array = [] + if (currentNamespace.constants.length > 0) { + results.push( + ts.createExportDeclaration( + undefined, + undefined, + undefined, + ts.createLiteral(`./constants`), + ), + ) + } + + if (currentNamespace.typedefs.length > 0) { + results.push( + ts.createExportDeclaration( + undefined, + undefined, + undefined, + ts.createLiteral(`./typedefs`), + ), + ) + } + + ;[ + ...currentNamespace.structs, + ...currentNamespace.unions, + ...currentNamespace.exceptions, + ].forEach((next: InterfaceWithFields) => { + results.push( + ts.createExportDeclaration( + undefined, + undefined, + undefined, + ts.createLiteral(`./${next.name.value}`), + ), + ) + }) + + currentNamespace.services.forEach((next: ServiceDefinition) => { + results.push( + ts.createImportDeclaration( + undefined, + undefined, + ts.createImportClause( + undefined, + ts.createNamespaceImport( + ts.createIdentifier(next.name.value), + ), + ), + ts.createLiteral(`./${next.name.value}`), + ), + ) + + results.push( + ts.createExportDeclaration( + undefined, + undefined, + ts.createNamedExports([ + ts.createExportSpecifier(next.name.value, next.name.value), + ]), + ), + ) + }) + + return results +} diff --git a/src/main/render/shared/service/index.ts b/src/main/render/shared/service/index.ts index d7cc2fcc..84db7579 100644 --- a/src/main/render/shared/service/index.ts +++ b/src/main/render/shared/service/index.ts @@ -10,12 +10,14 @@ import { COMMON_IDENTIFIERS } from '../identifiers' import { createAnyType, TypeMapping } from '../types' +import { IRenderState } from '../../../types' import { createFunctionParameter } from '../utils' function funcToMethodReducer( acc: Array, func: FunctionDefinition, typeMapping: TypeMapping, + state: IRenderState, ): Array { return acc.concat([ ts.createMethodSignature( @@ -24,7 +26,7 @@ function funcToMethodReducer( ...func.fields.map((field: FieldDefinition) => { return createFunctionParameter( field.name.value, - typeMapping(field.fieldType), + typeMapping(field.fieldType, state), undefined, field.requiredness === 'optional', ) @@ -37,9 +39,9 @@ function funcToMethodReducer( ), ], ts.createUnionTypeNode([ - typeMapping(func.returnType, true), + typeMapping(func.returnType, state, true), ts.createTypeReferenceNode(COMMON_IDENTIFIERS.Promise, [ - typeMapping(func.returnType, true), + typeMapping(func.returnType, state, true), ]), ]), func.name.value, @@ -63,10 +65,11 @@ function funcToMethodReducer( export function renderHandlerInterface( service: ServiceDefinition, typeMapping: TypeMapping, + state: IRenderState, ): Array { const signatures: Array = service.functions.reduce( (acc: Array, next: FunctionDefinition) => { - return funcToMethodReducer(acc, next, typeMapping) + return funcToMethodReducer(acc, next, typeMapping, state) }, [], ) diff --git a/src/main/render/shared/types.ts b/src/main/render/shared/types.ts index 867bed71..08c1433f 100644 --- a/src/main/render/shared/types.ts +++ b/src/main/render/shared/types.ts @@ -2,13 +2,19 @@ import * as ts from 'typescript' import { FunctionType, SyntaxType } from '@creditkarma/thrift-parser' +import { IRenderState } from '../../types' import { COMMON_IDENTIFIERS } from './identifiers' export type TypeMapping = ( fieldType: FunctionType, + state: IRenderState, loose?: boolean, ) => ts.TypeNode +export function createUndefinedType(): ts.TypeNode { + return ts.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword) +} + export function createVoidType(): ts.TypeNode { return ts.createKeywordTypeNode(ts.SyntaxKind.VoidKeyword) } @@ -42,12 +48,23 @@ export function createTypeProperty( ) } +export type ClassNameWithStateMapping = ( + name: string, + state: IRenderState, +) => string +export type ClassNameWithoutStateMapping = (name: string) => string +export type ClassNameMapping = + | ClassNameWithStateMapping + | ClassNameWithoutStateMapping + export function constructorNameForFieldType( fieldType: FunctionType, + className: ClassNameMapping, + state: IRenderState, ): ts.Identifier { switch (fieldType.type) { case SyntaxType.Identifier: - return ts.createIdentifier(fieldType.value) + return ts.createIdentifier(className(fieldType.value, state)) case SyntaxType.SetType: return COMMON_IDENTIFIERS.Set diff --git a/src/main/render/thrift-server/const.ts b/src/main/render/thrift-server/const.ts index e810adc9..61a4ae5b 100644 --- a/src/main/render/thrift-server/const.ts +++ b/src/main/render/thrift-server/const.ts @@ -6,6 +6,7 @@ import { TypeMapping } from './types' import { renderValue } from './initializers' +import { IRenderState } from '../../types' import { createConst } from './utils' /** @@ -20,13 +21,14 @@ import { createConst } from './utils' export function renderConst( node: ConstDefinition, typeMapping: TypeMapping, + state: IRenderState, ): ts.Statement { return ts.createVariableStatement( [ts.createToken(ts.SyntaxKind.ExportKeyword)], createConst( node.name.value, - typeMapping(node.fieldType), - renderValue(node.fieldType, node.initializer), + typeMapping(node.fieldType, state), + renderValue(node.fieldType, node.initializer, state), ), ) } diff --git a/src/main/render/thrift-server/includes.ts b/src/main/render/thrift-server/includes.ts deleted file mode 100644 index 5fc57369..00000000 --- a/src/main/render/thrift-server/includes.ts +++ /dev/null @@ -1,93 +0,0 @@ -import * as path from 'path' -import * as ts from 'typescript' - -import { - IIdentifierMap, - INamespaceFile, - IResolvedFile, - IResolvedIdentifier, -} from '../../types' -import { COMMON_IDENTIFIERS } from '../shared/identifiers' - -const DEFAULT_THRIFT_LIB: string = '@creditkarma/thrift-server-core' - -/** - * import * as thrift from 'thrift'; - * - * I would really like this to only import what is being used by the file we're - * generating. We'll need to keep track of what each files uses. - */ -export function renderThriftImports( - thriftLib: string = DEFAULT_THRIFT_LIB, -): ts.ImportDeclaration { - return ts.createImportDeclaration( - undefined, - undefined, - ts.createImportClause( - undefined, - ts.createNamespaceImport(COMMON_IDENTIFIERS.thrift), - ), - ts.createLiteral(thriftLib), - ) -} - -function existInIdentifiers( - name: string, - identifiers: IIdentifierMap, -): boolean { - for (const next in identifiers) { - if (identifiers.hasOwnProperty(next)) { - const identifier = identifiers[next] - if (identifier.pathName === name) { - return true - } - } - } - - return false -} - -/** - * Given a hash of included files this will return a list of import statements. - * - * @param currentPath The path of the file performing imports. Import paths are - * resolved relative to this. - * @param includes A hash of all included files - * @param resolved A hash of include name to a list of ids used from this include - */ -export function renderIncludes( - currentPath: string, - resolvedFile: INamespaceFile, -): Array { - const imports: Array = [] - for (const name of Object.keys(resolvedFile.includes)) { - if (existInIdentifiers(name, resolvedFile.identifiers)) { - const resolvedIncludes: Array = - resolvedFile.includes[name].identifiers - const includeFile: IResolvedFile = resolvedFile.includes[name].file - - if (resolvedIncludes != null && resolvedFile != null) { - const includePath: string = includeFile.namespace.path - imports.push( - ts.createImportDeclaration( - undefined, - undefined, - ts.createImportClause( - undefined, - ts.createNamespaceImport(ts.createIdentifier(name)), - ), - ts.createLiteral( - `./${path.join( - path.relative( - path.dirname(currentPath), - path.dirname(includePath), - ), - )}`, - ), - ), - ) - } - } - } - return imports -} diff --git a/src/main/render/thrift-server/index.ts b/src/main/render/thrift-server/index.ts index d7ecfdcb..50b9e823 100644 --- a/src/main/render/thrift-server/index.ts +++ b/src/main/render/thrift-server/index.ts @@ -4,48 +4,42 @@ import { ConstDefinition, EnumDefinition, ExceptionDefinition, - FunctionType, ServiceDefinition, StructDefinition, + ThriftStatement, TypedefDefinition, UnionDefinition, } from '@creditkarma/thrift-parser' -import { renderException as _renderException } from './exception' - -import { fileUsesThrift } from '../shared/includes' -import { renderConst as _renderConst } from './const' -import { renderEnum as _renderEnum } from './enum' +import { renderIndex } from '../shared' import { renderIncludes as _renderIncludes, renderThriftImports, -} from './includes' + statementsUseThrift, +} from '../shared/includes' +import { renderConst as _renderConst } from './const' +import { renderEnum as _renderEnum } from './enum' +import { renderException as _renderException } from './exception' import { renderService as _renderService } from './service' import { renderStruct as _renderStruct } from './struct' import { renderTypeDef as _renderTypeDef } from './typedef' import { renderStrictUnion, renderUnion as _renderUnion } from './union' -import { - IMakeOptions, - INamespaceFile, - IRenderer, - IRenderState, -} from '../../types' +import { IRenderer, IRenderState } from '../../types' import { typeNodeForFieldType } from './types' -export function renderIncludes( - currentPath: string, - resolvedFile: INamespaceFile, - options: IMakeOptions, +export function renderImports( + statements: Array, + state: IRenderState, ): Array { - if (fileUsesThrift(resolvedFile)) { + if (statementsUseThrift(statements)) { return [ - renderThriftImports(options.library), - ..._renderIncludes(currentPath, resolvedFile), + renderThriftImports(state.options.library), + ..._renderIncludes(statements, state), ] } else { - return _renderIncludes(currentPath, resolvedFile) + return _renderIncludes(statements, state) } } @@ -53,27 +47,14 @@ export function renderConst( statement: ConstDefinition, state: IRenderState, ): Array { - return [ - _renderConst( - statement, - (fieldType: FunctionType, loose?: boolean): ts.TypeNode => { - return typeNodeForFieldType(fieldType, state, loose) - }, - ), - ] + return [_renderConst(statement, typeNodeForFieldType, state)] } export function renderTypeDef( statement: TypedefDefinition, state: IRenderState, ): Array { - return _renderTypeDef( - statement, - (fieldType: FunctionType, loose?: boolean): ts.TypeNode => { - return typeNodeForFieldType(fieldType, state, loose) - }, - state, - ) + return _renderTypeDef(statement, typeNodeForFieldType, state) } export function renderEnum( @@ -112,11 +93,12 @@ export function renderService( statement: ServiceDefinition, state: IRenderState, ): Array { - return [_renderService(statement, state)] + return _renderService(statement, state) } export const renderer: IRenderer = { - renderIncludes, + renderIndex, + renderImports, renderConst, renderTypeDef, renderEnum, diff --git a/src/main/render/thrift-server/initializers.ts b/src/main/render/thrift-server/initializers.ts index f779149a..3ed38bfc 100644 --- a/src/main/render/thrift-server/initializers.ts +++ b/src/main/render/thrift-server/initializers.ts @@ -16,15 +16,20 @@ import { import { COMMON_IDENTIFIERS } from './identifiers' +import { resolveIdentifierName } from '../../resolver/utils' +import { IRenderState } from '../../types' import { propertyAccessForIdentifier } from './utils' export function renderValue( fieldType: FunctionType, node: ConstValue, + state: IRenderState, ): ts.Expression { switch (node.type) { case SyntaxType.Identifier: - return ts.createIdentifier(node.value) + return ts.createIdentifier( + resolveIdentifierName(node.value, state).fullName, + ) case SyntaxType.IntConstant: return renderIntConstant(node, fieldType) @@ -44,16 +49,16 @@ export function renderValue( case SyntaxType.ConstList: if (fieldType.type === SyntaxType.ListType) { - return renderList(fieldType, node) + return renderList(fieldType, node, state) } else if (fieldType.type === SyntaxType.SetType) { - return renderSet(fieldType, node) + return renderSet(fieldType, node, state) } else { throw new TypeError(`Type list | set expected`) } case SyntaxType.ConstMap: if (fieldType.type === SyntaxType.MapType) { - return renderMap(fieldType, node) + return renderMap(fieldType, node, state) } else { throw new TypeError(`Type map expected`) } @@ -111,11 +116,15 @@ export function renderDoubleConstant(node: DoubleConstant): ts.Expression { } } -function renderMap(fieldType: MapType, node: ConstMap): ts.NewExpression { +function renderMap( + fieldType: MapType, + node: ConstMap, + state: IRenderState, +): ts.NewExpression { const values = node.properties.map(({ name, initializer }) => { return ts.createArrayLiteral([ - renderValue(fieldType.keyType, name), - renderValue(fieldType.valueType, initializer), + renderValue(fieldType.keyType, name, state), + renderValue(fieldType.valueType, initializer, state), ]) }) @@ -124,10 +133,14 @@ function renderMap(fieldType: MapType, node: ConstMap): ts.NewExpression { ]) } -function renderSet(fieldType: SetType, node: ConstList): ts.NewExpression { +function renderSet( + fieldType: SetType, + node: ConstList, + state: IRenderState, +): ts.NewExpression { const values: Array = node.elements.map( (value: ConstValue) => { - return renderValue(fieldType.valueType, value) + return renderValue(fieldType.valueType, value, state) }, ) @@ -139,10 +152,11 @@ function renderSet(fieldType: SetType, node: ConstList): ts.NewExpression { function renderList( fieldType: ListType, node: ConstList, + state: IRenderState, ): ts.ArrayLiteralExpression { const values: Array = node.elements.map( (value: ConstValue) => { - return renderValue(fieldType.valueType, value) + return renderValue(fieldType.valueType, value, state) }, ) diff --git a/src/main/render/thrift-server/service/client.ts b/src/main/render/thrift-server/service/client.ts index feef9d4a..f3b22891 100644 --- a/src/main/render/thrift-server/service/client.ts +++ b/src/main/render/thrift-server/service/client.ts @@ -243,7 +243,9 @@ function createBaseMethodForDefinition( ), // args.write(output) createMethodCallStatement( - ts.createIdentifier(toolkitName(createStructArgsName(def))), + ts.createIdentifier( + toolkitName(createStructArgsName(def), state), + ), 'encode', [COMMON_IDENTIFIERS.args, COMMON_IDENTIFIERS.output], ), @@ -516,7 +518,7 @@ function createNewResultInstance( ts.createCall( ts.createPropertyAccess( ts.createIdentifier( - toolkitName(createStructResultName(def)), + toolkitName(createStructResultName(def), state), ), ts.createIdentifier('decode'), ), @@ -641,7 +643,7 @@ function createParametersForField( ): ts.ParameterDeclaration { const defaultValue = field.defaultValue !== null - ? renderValue(field.fieldType, field.defaultValue) + ? renderValue(field.fieldType, field.defaultValue, state) : undefined return createFunctionParameter( diff --git a/src/main/render/thrift-server/service/index.ts b/src/main/render/thrift-server/service/index.ts index 1ec90d43..ce5d817e 100644 --- a/src/main/render/thrift-server/service/index.ts +++ b/src/main/render/thrift-server/service/index.ts @@ -3,7 +3,6 @@ import * as ts from 'typescript' import { FieldDefinition, FunctionDefinition, - FunctionType, ServiceDefinition, StructDefinition, SyntaxType, @@ -46,33 +45,18 @@ function emptyLocation(): TextLocation { export function renderService( service: ServiceDefinition, state: IRenderState, -): ts.ModuleDeclaration { - return ts.createModuleDeclaration( - undefined, - [ts.createToken(ts.SyntaxKind.ExportKeyword)], - ts.createIdentifier(service.name.value), - ts.createModuleBlock([ - renderServiceName(service), - renderServiceAnnotations( - collectAllAnnotations(service, state.identifiers), - ), - renderMethodAnnotations( - collectAllMethods(service, state.identifiers), - ), - renderMethodNames(service, state.identifiers), - ...renderArgsStruct(service, state), - ...renderResultStruct(service, state), - renderClient(service, state), - ...renderHandlerInterface( - service, - (fieldType: FunctionType, loose?: boolean): ts.TypeNode => { - return typeNodeForFieldType(fieldType, state, loose) - }, - ), - renderProcessor(service, state), - ]), - ts.NodeFlags.Namespace, - ) +): Array { + return [ + renderServiceName(service), + renderServiceAnnotations(collectAllAnnotations(service, state)), + renderMethodAnnotations(collectAllMethods(service, state)), + renderMethodNames(service, state), + ...renderArgsStruct(service, state), + ...renderResultStruct(service, state), + renderClient(service, state), + ...renderHandlerInterface(service, typeNodeForFieldType, state), + renderProcessor(service, state), + ] } export function renderArgsStruct( diff --git a/src/main/render/thrift-server/service/processor.ts b/src/main/render/thrift-server/service/processor.ts index 20723509..1d59923e 100644 --- a/src/main/render/thrift-server/service/processor.ts +++ b/src/main/render/thrift-server/service/processor.ts @@ -22,7 +22,7 @@ import { renderServiceNameStaticProperty, } from './utils' -import { IIdentifierMap, IRenderState } from '../../../types' +import { IRenderState } from '../../../types' import { COMMON_IDENTIFIERS, @@ -60,7 +60,8 @@ import { renderServiceAnnotationsStaticProperty, } from '../annotations' -import { looseName, strictName, toolkitName } from '../struct/utils' +import { resolveIdentifierDefinition } from '../../../resolver/utils' +import { className, looseName, strictName, toolkitName } from '../struct/utils' function objectLiteralForServiceFunctions( node: ThriftStatement, @@ -153,7 +154,7 @@ export function renderProcessor( const processMethod: ts.MethodDeclaration = createProcessMethod( service, - state.identifiers, + state, ) const processFunctions: Array = service.functions.map( (next: FunctionDefinition) => { @@ -189,7 +190,7 @@ export function renderProcessor( annotations, methodAnnotations, methodNames, - createCtor(service, state.identifiers), + createCtor(service, state), processMethod, ...processFunctions, ], // body @@ -198,13 +199,13 @@ export function renderProcessor( function createCtor( service: ServiceDefinition, - identifiers: IIdentifierMap, + state: IRenderState, ): ts.ConstructorDeclaration { if (service.extends !== null) { return createClassConstructor( [createFunctionParameter('handler', createHandlerType(service))], [ - createSuperCall(service.extends, identifiers), + createSuperCall(service.extends, state), createAssignmentStatement( ts.createIdentifier('this._handler'), ts.createIdentifier('handler'), @@ -227,7 +228,7 @@ function createCtor( function createSuperCall( service: Identifier, - identifiers: IIdentifierMap, + state: IRenderState, ): ts.Statement { return ts.createStatement( ts.createCall( @@ -235,7 +236,12 @@ function createSuperCall( [], [ objectLiteralForServiceFunctions( - identifiers[service.value].definition, + resolveIdentifierDefinition( + service, + state.currentNamespace, + state.project.namespaces, + state.project.sourceDir, + ), ), ], ), @@ -405,6 +411,7 @@ function createProcessFunctionMethod( createStructResultName( funcDef, ), + state, ), ), 'encode', @@ -492,7 +499,7 @@ function createArgsVariable( ts.createCall( ts.createPropertyAccess( ts.createIdentifier( - toolkitName(createStructArgsName(funcDef)), + toolkitName(createStructArgsName(funcDef), state), ), ts.createIdentifier('decode'), ), @@ -518,7 +525,7 @@ function createElseForExceptions( ts.createBinary( COMMON_IDENTIFIERS.err, ts.SyntaxKind.InstanceOfKeyword, - constructorNameForFieldType(next.fieldType), + constructorNameForFieldType(next.fieldType, className, state), ), createThenForException(next, funcDef, state), createElseForExceptions(next, tail, funcDef, state), @@ -616,7 +623,7 @@ function createThenForException( // StructCodec.encode(result, output) createMethodCallStatement( ts.createIdentifier( - toolkitName(createStructResultName(funcDef)), + toolkitName(createStructResultName(funcDef), state), ), 'encode', [COMMON_IDENTIFIERS.result, COMMON_IDENTIFIERS.output], @@ -650,7 +657,7 @@ function createIfForExceptions( ts.createBinary( COMMON_IDENTIFIERS.err, ts.SyntaxKind.InstanceOfKeyword, - constructorNameForFieldType(throwDef.fieldType), + constructorNameForFieldType(throwDef.fieldType, className, state), ), createThenForException(throwDef, funcDef, state), createElseForExceptions(throwDef, tail, funcDef, state), @@ -726,7 +733,7 @@ function createExceptionHandlers( // } function createProcessMethod( service: ServiceDefinition, - identifiers: IIdentifierMap, + state: IRenderState, ): ts.MethodDeclaration { return createPublicMethod( COMMON_IDENTIFIERS.process, @@ -779,7 +786,7 @@ function createProcessMethod( COMMON_IDENTIFIERS.fieldName, ), ), - createMethodCallForFname(service, identifiers), + createMethodCallForFname(service, state), ], ), ), @@ -839,12 +846,12 @@ function createMethodCallForFunction(func: FunctionDefinition): ts.CaseClause { */ function createMethodCallForFname( service: ServiceDefinition, - identifiers: IIdentifierMap, + state: IRenderState, ): ts.SwitchStatement { return ts.createSwitch( - ts.createIdentifier('methodName'), + COMMON_IDENTIFIERS.methodName, ts.createCaseBlock([ - ...collectAllMethods(service, identifiers).map( + ...collectAllMethods(service, state).map( createMethodCallForFunction, ), ts.createDefaultClause([ diff --git a/src/main/render/thrift-server/service/utils.ts b/src/main/render/thrift-server/service/utils.ts index ef392ff9..691ba291 100644 --- a/src/main/render/thrift-server/service/utils.ts +++ b/src/main/render/thrift-server/service/utils.ts @@ -9,10 +9,11 @@ import { SyntaxType, } from '@creditkarma/thrift-parser' -import { DefinitionType, IIdentifierMap } from '../../../types' +import { DefinitionType, IRenderState } from '../../../types' import { COMMON_IDENTIFIERS } from '../identifiers' +import { resolveIdentifierDefinition } from '../../../resolver/utils' import { createStringType } from '../../shared/types' export function capitalize(str: string): string { @@ -80,19 +81,23 @@ export function renderServiceNameStaticProperty(): ts.PropertyDeclaration { export function collectAllMethods( service: ServiceDefinition, - identifiers: IIdentifierMap, + state: IRenderState, ): Array { if (service.extends === null) { return service.functions } else { - const parentService: DefinitionType = - identifiers[service.extends.value].definition + const parentService: DefinitionType = resolveIdentifierDefinition( + service.extends, + state.currentNamespace, + state.project.namespaces, + state.project.sourceDir, + ) switch (parentService.type) { case SyntaxType.ServiceDefinition: // This actually doesn't work for deeply extended services. This identifier map only // has the identifiers for the current namespace. return [ - ...collectAllMethods(parentService, identifiers), + ...collectAllMethods(parentService, state), ...service.functions, ] @@ -108,7 +113,7 @@ export function collectAllMethods( export function renderMethodNames( service: ServiceDefinition, - identifiers: IIdentifierMap, + state: IRenderState, ): ts.VariableStatement { return ts.createVariableStatement( [ts.createToken(ts.SyntaxKind.ExportKeyword)], @@ -118,7 +123,7 @@ export function renderMethodNames( COMMON_IDENTIFIERS.methodNames, ts.createTypeReferenceNode('Array', undefined), ts.createArrayLiteral([ - ...collectAllMethods(service, identifiers).map( + ...collectAllMethods(service, state).map( (next: FunctionDefinition) => { return ts.createLiteral(next.name.value) }, @@ -162,7 +167,7 @@ export function renderMethodNamesStaticProperty(): ts.PropertyDeclaration { function getRawAnnotations( service: ServiceDefinition, - identifiers: IIdentifierMap, + state: IRenderState, ): Array { if (service.extends === null) { if (service.annotations) { @@ -171,19 +176,23 @@ function getRawAnnotations( return [] } } else { - const parentService: DefinitionType = - identifiers[service.extends.value].definition + const parentService: DefinitionType = resolveIdentifierDefinition( + service.extends, + state.currentNamespace, + state.project.namespaces, + state.project.sourceDir, + ) switch (parentService.type) { case SyntaxType.ServiceDefinition: if (service.annotations) { // This actually doesn't work for deeply extended services. This identifier map only // has the identifiers for the current namespace. return [ - ...getRawAnnotations(parentService, identifiers), + ...getRawAnnotations(parentService, state), ...service.annotations.annotations, ] } else { - return getRawAnnotations(parentService, identifiers) + return getRawAnnotations(parentService, state) } default: @@ -198,13 +207,10 @@ function getRawAnnotations( export function collectAllAnnotations( service: ServiceDefinition, - identifiers: IIdentifierMap, + state: IRenderState, ): Annotations { const temp: Map = new Map() - const rawAnnotations: Array = getRawAnnotations( - service, - identifiers, - ) + const rawAnnotations: Array = getRawAnnotations(service, state) for (const annotation of rawAnnotations) { temp.set(annotation.name.value, annotation) diff --git a/src/main/render/thrift-server/struct/class.ts b/src/main/render/thrift-server/struct/class.ts index 150870ef..f0e9c6e7 100644 --- a/src/main/render/thrift-server/struct/class.ts +++ b/src/main/render/thrift-server/struct/class.ts @@ -86,7 +86,7 @@ export function renderClass( return ts.createClassDeclaration( undefined, tokens(isExported), - classNameForStruct(node), + classNameForStruct(node, state).replace('__NAMESPACE__', ''), [], [extendsAbstract(), implementsInterface(node, state)], // heritage [ @@ -94,15 +94,16 @@ export function renderClass( annotations, fieldAnnotations, ctor, - createStaticReadMethod(node), + createStaticReadMethod(node, state), createStaticWriteMethod(node, state), - createWriteMethod(node), + createWriteMethod(node, state), ], ) } export function createWriteMethod( node: InterfaceWithFields, + state: IRenderState, ): ts.MethodDeclaration { return ts.createMethod( undefined, @@ -118,7 +119,9 @@ export function createWriteMethod( ts.createReturn( ts.createCall( ts.createPropertyAccess( - ts.createIdentifier(toolkitNameForStruct(node)), + ts.createIdentifier( + toolkitNameForStruct(node, state), + ), COMMON_IDENTIFIERS.encode, ), undefined, @@ -161,7 +164,9 @@ export function createStaticWriteMethod( ts.createReturn( ts.createCall( ts.createPropertyAccess( - ts.createIdentifier(toolkitNameForStruct(node)), + ts.createIdentifier( + toolkitNameForStruct(node, state), + ), COMMON_IDENTIFIERS.encode, ), undefined, @@ -176,6 +181,7 @@ export function createStaticWriteMethod( export function createStaticReadMethod( node: InterfaceWithFields, + state: IRenderState, ): ts.MethodDeclaration { return ts.createMethod( undefined, @@ -189,20 +195,20 @@ export function createStaticReadMethod( undefined, [createInputParameter()], ts.createTypeReferenceNode( - ts.createIdentifier(classNameForStruct(node)), + ts.createIdentifier(classNameForStruct(node, state)), undefined, ), ts.createBlock( [ ts.createReturn( ts.createNew( - ts.createIdentifier(classNameForStruct(node)), + ts.createIdentifier(classNameForStruct(node, state)), undefined, [ ts.createCall( ts.createPropertyAccess( ts.createIdentifier( - toolkitNameForStruct(node), + toolkitNameForStruct(node, state), ), COMMON_IDENTIFIERS.decode, ), @@ -266,7 +272,7 @@ export function renderFieldDeclarations( ): ts.PropertyDeclaration { const defaultValue: ts.Expression | undefined = field.defaultValue !== null - ? renderValue(field.fieldType, field.defaultValue) + ? renderValue(field.fieldType, field.defaultValue, state) : undefined return ts.createProperty( diff --git a/src/main/render/thrift-server/struct/decode.ts b/src/main/render/thrift-server/struct/decode.ts index df85044a..0c7d91a7 100644 --- a/src/main/render/thrift-server/struct/decode.ts +++ b/src/main/render/thrift-server/struct/decode.ts @@ -36,10 +36,12 @@ import { throwProtocolException, } from '../utils' -import { IRenderState, IResolvedIdentifier } from '../../../types' +import { DefinitionType, IRenderState } from '../../../types' import { READ_METHODS } from './methods' +import { resolveIdentifierDefinition } from '../../../resolver/utils' + import { strictNameForStruct, toolkitName } from './utils' export function createTempVariables( @@ -139,7 +141,7 @@ export function createDecodeMethod( readStructBegin(), whileLoop, readStructEnd(), - createReturnForStruct(node), + createReturnForStruct(node, state), ], true, ), @@ -199,7 +201,7 @@ export function createCaseForField( const checkType: ts.IfStatement = ts.createIf( createEqualsCheck( COMMON_IDENTIFIERS.fieldType, - thriftTypeForFieldType(field.fieldType, state.identifiers), + thriftTypeForFieldType(field.fieldType, state), ), ts.createBlock( [ @@ -239,11 +241,14 @@ export function endReadForField( } } -export function createReturnForStruct(node: InterfaceWithFields): ts.Statement { +export function createReturnForStruct( + node: InterfaceWithFields, + state: IRenderState, +): ts.Statement { if (hasRequiredField(node)) { return ts.createIf( createCheckForFields(node.fields), - ts.createBlock([createReturnValue(node)], true), + ts.createBlock([createReturnValue(node, state)], true), ts.createBlock( [ throwProtocolException( @@ -255,18 +260,21 @@ export function createReturnForStruct(node: InterfaceWithFields): ts.Statement { ), ) } else { - return createReturnValue(node) + return createReturnValue(node, state) } } -function createReturnValue(node: InterfaceWithFields): ts.ReturnStatement { +function createReturnValue( + node: InterfaceWithFields, + state: IRenderState, +): ts.ReturnStatement { return ts.createReturn( ts.createObjectLiteral( node.fields.map( (next: FieldDefinition): ts.ObjectLiteralElementLike => { return ts.createPropertyAssignment( next.name.value, - getInitializerForField('_args', next), + getInitializerForField('_args', next, state), ) }, ), @@ -276,22 +284,23 @@ function createReturnValue(node: InterfaceWithFields): ts.ReturnStatement { } export function readValueForIdentifier( - id: IResolvedIdentifier, + id: string, + definition: DefinitionType, fieldType: FunctionType, fieldName: ts.Identifier, state: IRenderState, ): Array { - switch (id.definition.type) { + switch (definition.type) { case SyntaxType.ConstDefinition: throw new TypeError( `Identifier ${ - id.definition.name.value + definition.name.value } is a value being used as a type`, ) case SyntaxType.ServiceDefinition: throw new TypeError( - `Service ${id.definition.name.value} is being used as a type`, + `Service ${definition.name.value} is being used as a type`, ) case SyntaxType.StructDefinition: @@ -304,7 +313,7 @@ export function readValueForIdentifier( typeNodeForFieldType(fieldType, state), ts.createCall( ts.createPropertyAccess( - ts.createIdentifier(toolkitName(id.resolvedName)), + ts.createIdentifier(toolkitName(id, state)), COMMON_IDENTIFIERS.decode, ), undefined, @@ -327,13 +336,13 @@ export function readValueForIdentifier( case SyntaxType.TypedefDefinition: return readValueForFieldType( - id.definition.definitionType, + definition.definitionType, fieldName, state, ) default: - const msg: never = id.definition + const msg: never = definition throw new Error(`Non-exhaustive match for: ${msg}`) } } @@ -345,8 +354,16 @@ export function readValueForFieldType( ): Array { switch (fieldType.type) { case SyntaxType.Identifier: + const definition = resolveIdentifierDefinition( + fieldType, + state.currentNamespace, + state.project.namespaces, + state.project.sourceDir, + ) + return readValueForIdentifier( - state.identifiers[fieldType.value], + fieldType.value, + definition, fieldType, fieldName, state, diff --git a/src/main/render/thrift-server/struct/encode.ts b/src/main/render/thrift-server/struct/encode.ts index 286b0ad9..24296cd9 100644 --- a/src/main/render/thrift-server/struct/encode.ts +++ b/src/main/render/thrift-server/struct/encode.ts @@ -15,6 +15,8 @@ import { COMMON_IDENTIFIERS, THRIFT_IDENTIFIERS } from '../identifiers' import { WRITE_METHODS, WriteMethodName } from './methods' +import { resolveIdentifierDefinition } from '../../../resolver/utils' + import { coerceType, createConstStatement, @@ -33,17 +35,13 @@ import { typeNodeForFieldType, } from '../types' -import { - IIdentifierMap, - IRenderState, - IResolvedIdentifier, -} from '../../../types' +import { DefinitionType, IRenderState } from '../../../types' import { looseNameForStruct, throwForField, toolkitName } from './utils' export function createTempVariables( node: InterfaceWithFields, - identifiers: IIdentifierMap, + state: IRenderState, ): Array { const structFields: Array = node.fields.filter( (next: FieldDefinition): boolean => { @@ -63,7 +61,12 @@ export function createTempVariables( ): ts.ObjectLiteralElementLike => { return ts.createPropertyAssignment( next.name.value, - getInitializerForField('args', next, true), + getInitializerForField( + 'args', + next, + state, + true, + ), ) }, ), @@ -82,7 +85,7 @@ export function createEncodeMethod( ): ts.MethodDeclaration { const tempVariables: Array = createTempVariables( node, - state.identifiers, + state, ) return ts.createMethod( @@ -171,30 +174,30 @@ export function createWriteForFieldType( state: IRenderState, ): ts.Block { return ts.createBlock([ - writeFieldBegin(field, state.identifiers), + writeFieldBegin(field, state), ...writeValueForField(node, field.fieldType, fieldName, state), writeFieldEnd(), ]) } export function writeValueForIdentifier( - id: IResolvedIdentifier, + id: string, + definition: DefinitionType, node: InterfaceWithFields, - fieldType: FunctionType, fieldName: ts.Identifier, state: IRenderState, ): Array { - switch (id.definition.type) { + switch (definition.type) { case SyntaxType.ConstDefinition: throw new TypeError( `Identifier[${ - id.definition.name.value + definition.name.value }] is a value being used as a type`, ) case SyntaxType.ServiceDefinition: throw new TypeError( - `Service[${id.definition.name.value}] is being used as a type`, + `Service[${definition.name.value}] is being used as a type`, ) case SyntaxType.StructDefinition: @@ -202,7 +205,7 @@ export function writeValueForIdentifier( case SyntaxType.ExceptionDefinition: return [ createMethodCall( - ts.createIdentifier(toolkitName(id.resolvedName)), + ts.createIdentifier(toolkitName(id, state)), 'encode', [fieldName, COMMON_IDENTIFIERS.output], ), @@ -219,13 +222,13 @@ export function writeValueForIdentifier( case SyntaxType.TypedefDefinition: return writeValueForType( node, - id.definition.definitionType, + definition.definitionType, fieldName, state, ) default: - const msg: never = id.definition + const msg: never = definition throw new Error(`Non-exhaustive match for: ${msg}`) } } @@ -238,10 +241,17 @@ export function writeValueForType( ): Array { switch (fieldType.type) { case SyntaxType.Identifier: + const definition: DefinitionType = resolveIdentifierDefinition( + fieldType, + state.currentNamespace, + state.project.namespaces, + state.project.sourceDir, + ) + return writeValueForIdentifier( - state.identifiers[fieldType.value], + fieldType.value, + definition, node, - fieldType, fieldName, state, ) @@ -253,21 +263,21 @@ export function writeValueForType( */ case SyntaxType.SetType: return [ - writeSetBegin(fieldType, fieldName, state.identifiers), + writeSetBegin(fieldType, fieldName, state), forEach(node, fieldType, fieldName, state), writeSetEnd(), ] case SyntaxType.MapType: return [ - writeMapBegin(fieldType, fieldName, state.identifiers), + writeMapBegin(fieldType, fieldName, state), forEach(node, fieldType, fieldName, state), writeMapEnd(), ] case SyntaxType.ListType: return [ - writeListBegin(fieldType, fieldName, state.identifiers), + writeListBegin(fieldType, fieldName, state), forEach(node, fieldType, fieldName, state), writeListEnd(), ] @@ -402,11 +412,11 @@ export function writeStructEnd(): ts.ExpressionStatement { export function writeMapBegin( fieldType: MapType, fieldName: string | ts.Identifier, - identifiers: IIdentifierMap, + state: IRenderState, ): ts.CallExpression { return createMethodCall('output', 'writeMapBegin', [ - thriftTypeForFieldType(fieldType.keyType, identifiers), - thriftTypeForFieldType(fieldType.valueType, identifiers), + thriftTypeForFieldType(fieldType.keyType, state), + thriftTypeForFieldType(fieldType.valueType, state), propertyAccessForIdentifier(fieldName, 'size'), ]) } @@ -420,10 +430,10 @@ export function writeMapEnd(): ts.CallExpression { export function writeListBegin( fieldType: ListType, fieldName: string | ts.Identifier, - identifiers: IIdentifierMap, + state: IRenderState, ): ts.CallExpression { return createMethodCall('output', 'writeListBegin', [ - thriftTypeForFieldType(fieldType.valueType, identifiers), + thriftTypeForFieldType(fieldType.valueType, state), propertyAccessForIdentifier(fieldName, 'length'), ]) } @@ -437,10 +447,10 @@ export function writeListEnd(): ts.CallExpression { export function writeSetBegin( fieldType: SetType, fieldName: string | ts.Identifier, - identifiers: IIdentifierMap, + state: IRenderState, ): ts.CallExpression { return createMethodCall('output', 'writeSetBegin', [ - thriftTypeForFieldType(fieldType.valueType, identifiers), + thriftTypeForFieldType(fieldType.valueType, state), propertyAccessForIdentifier(fieldName, 'size'), ]) } @@ -453,12 +463,12 @@ export function writeSetEnd(): ts.CallExpression { // output.writeFieldBegin(, , ) export function writeFieldBegin( field: FieldDefinition, - identifiers: IIdentifierMap, + state: IRenderState, ): ts.ExpressionStatement { if (field.fieldID !== null) { return createMethodCallStatement('output', 'writeFieldBegin', [ ts.createLiteral(field.name.value), - thriftTypeForFieldType(field.fieldType, identifiers), + thriftTypeForFieldType(field.fieldType, state), ts.createLiteral(field.fieldID.value), ]) } else { diff --git a/src/main/render/thrift-server/struct/interface.ts b/src/main/render/thrift-server/struct/interface.ts index 6480ae2f..5aa9d733 100644 --- a/src/main/render/thrift-server/struct/interface.ts +++ b/src/main/render/thrift-server/struct/interface.ts @@ -34,7 +34,7 @@ function strictInterface( return ts.createInterfaceDeclaration( undefined, tokens(isExported), - ts.createIdentifier(strictNameForStruct(node, state)), + strictNameForStruct(node, state), [], [], signatures, @@ -59,7 +59,7 @@ function looseInterface( return ts.createInterfaceDeclaration( undefined, tokens(isExported), - ts.createIdentifier(looseNameForStruct(node, state)), + looseNameForStruct(node, state), [], [], signatures, diff --git a/src/main/render/thrift-server/struct/reader.ts b/src/main/render/thrift-server/struct/reader.ts index c18f0a36..dab4fc73 100644 --- a/src/main/render/thrift-server/struct/reader.ts +++ b/src/main/render/thrift-server/struct/reader.ts @@ -16,7 +16,8 @@ import { import { className, toolkitName } from './utils' -import { IRenderState, IResolvedIdentifier } from '../../../types' +import { resolveIdentifierDefinition } from '../../../resolver/utils' +import { DefinitionType, IRenderState } from '../../../types' import { createMethodCall } from '../../shared/utils' import { COMMON_IDENTIFIERS } from '../identifiers' import { createVoidType, typeNodeForFieldType } from '../types' @@ -71,24 +72,25 @@ export function defaultAssignment( } export function assignmentForIdentifier( + id: string, field: FieldDefinition, - id: IResolvedIdentifier, + definition: DefinitionType, fieldType: FieldType, saveName: ts.Identifier, readName: ts.Identifier, state: IRenderState, ): Array { - switch (id.definition.type) { + switch (definition.type) { case SyntaxType.ConstDefinition: throw new TypeError( `Identifier ${ - id.definition.name.value + definition.name.value } is a value being used as a type`, ) case SyntaxType.ServiceDefinition: throw new TypeError( - `Service ${id.definition.name.value} is being used as a type`, + `Service ${definition.name.value} is being used as a type`, ) // Handle creating value for args. @@ -98,11 +100,9 @@ export function assignmentForIdentifier( createConstStatement( saveName, typeNodeForFieldType(fieldType, state), - createMethodCall( - toolkitName(id.resolvedName), - 'create', - [readName], - ), + createMethodCall(toolkitName(id, state), 'create', [ + readName, + ]), ), ] } else { @@ -116,7 +116,7 @@ export function assignmentForIdentifier( saveName, typeNodeForFieldType(fieldType, state), ts.createNew( - ts.createIdentifier(className(id.resolvedName)), + ts.createIdentifier(className(id, state)), undefined, [readName], ), @@ -129,14 +129,14 @@ export function assignmentForIdentifier( case SyntaxType.TypedefDefinition: return assignmentForFieldType( field, - id.definition.definitionType, + definition.definitionType, saveName, readName, state, ) default: - const msg: never = id.definition + const msg: never = definition throw new Error(`Non-exhaustive match for: ${msg}`) } } @@ -150,9 +150,17 @@ export function assignmentForFieldType( ): Array { switch (fieldType.type) { case SyntaxType.Identifier: + const definition = resolveIdentifierDefinition( + fieldType, + state.currentNamespace, + state.project.namespaces, + state.project.sourceDir, + ) + return assignmentForIdentifier( + fieldType.value, field, - state.identifiers[fieldType.value], + definition, fieldType, saveName, readName, diff --git a/src/main/render/thrift-server/struct/toolkit.ts b/src/main/render/thrift-server/struct/toolkit.ts index 23746532..dfe46596 100644 --- a/src/main/render/thrift-server/struct/toolkit.ts +++ b/src/main/render/thrift-server/struct/toolkit.ts @@ -26,14 +26,14 @@ export function renderToolkit( return ts.createVariableStatement( tokens(isExported), createConst( - ts.createIdentifier(toolkitNameForStruct(node)), + toolkitNameForStruct(node, state), ts.createTypeReferenceNode(THRIFT_IDENTIFIERS.IStructCodec, [ ts.createTypeReferenceNode( - ts.createIdentifier(looseNameForStruct(node, state)), + looseNameForStruct(node, state), undefined, ), ts.createTypeReferenceNode( - ts.createIdentifier(strictNameForStruct(node, state)), + strictNameForStruct(node, state), undefined, ), ]), diff --git a/src/main/render/thrift-server/struct/utils.ts b/src/main/render/thrift-server/struct/utils.ts index e59db6c0..a72edf10 100644 --- a/src/main/render/thrift-server/struct/utils.ts +++ b/src/main/render/thrift-server/struct/utils.ts @@ -8,23 +8,20 @@ import { import { COMMON_IDENTIFIERS, THRIFT_IDENTIFIERS } from '../identifiers' -import { IRenderState } from '../../../types' +import { resolveIdentifierName } from '../../../resolver/utils' +import { IRenderState, IResolvedIdentifier } from '../../../types' import { throwProtocolException } from '../utils' type NameMapping = (name: string) => string -function splitPath(path: string): Array { - return path.split('.').filter( - (next: string): boolean => { - return next.trim() !== '' - }, - ) -} - -function makeNameForNode(name: string, mapping: NameMapping): string { - const parts: Array = splitPath(name) - if (parts.length > 1) { - return `${parts[0]}.${mapping(parts[1])}` +function makeNameForNode( + name: string, + state: IRenderState, + mapping: NameMapping, +): string { + const resolvedId: IResolvedIdentifier = resolveIdentifierName(name, state) + if (resolvedId.pathName) { + return `${resolvedId.pathName}.${mapping(resolvedId.baseName)}` } else { return mapping(name) } @@ -61,8 +58,11 @@ export function looseNameForStruct( return looseName(node.name.value, node.type, state) } -export function classNameForStruct(node: InterfaceWithFields): string { - return className(node.name.value) +export function classNameForStruct( + node: InterfaceWithFields, + state: IRenderState, +): string { + return className(node.name.value, state) } export function strictNameForStruct( @@ -72,12 +72,15 @@ export function strictNameForStruct( return strictName(node.name.value, node.type, state) } -export function toolkitNameForStruct(node: InterfaceWithFields): string { - return toolkitName(node.name.value) +export function toolkitNameForStruct( + node: InterfaceWithFields, + state: IRenderState, +): string { + return toolkitName(node.name.value, state) } -export function className(name: string): string { - return makeNameForNode(name, (part: string) => { +export function className(name: string, state: IRenderState): string { + return makeNameForNode(name, state, (part: string) => { return part }) } @@ -88,9 +91,9 @@ export function looseName( state: IRenderState, ): string { if (type === SyntaxType.UnionDefinition && state.options.strictUnions) { - return `${className(name)}Args` + return `${className(name, state)}Args` } else { - return makeNameForNode(name, (part: string) => { + return makeNameForNode(name, state, (part: string) => { return `I${part}Args` }) } @@ -102,17 +105,17 @@ export function strictName( state: IRenderState, ): string { if (type === SyntaxType.UnionDefinition && state.options.strictUnions) { - return className(name) + return className(name, state) } else { - return makeNameForNode(name, (part: string) => { + return makeNameForNode(name, state, (part: string) => { return `I${part}` }) } } // TODO: This will be renamed to Toolkit in a breaking release -export function toolkitName(name: string): string { - return makeNameForNode(name, (part: string) => { +export function toolkitName(name: string, state: IRenderState): string { + return makeNameForNode(name, state, (part: string) => { return `${part}Codec` }) } diff --git a/src/main/render/thrift-server/typedef.ts b/src/main/render/thrift-server/typedef.ts index c8e7fd6b..0ae7a09a 100644 --- a/src/main/render/thrift-server/typedef.ts +++ b/src/main/render/thrift-server/typedef.ts @@ -1,7 +1,9 @@ import * as ts from 'typescript' import { + ExceptionDefinition, FieldDefinition, + StructDefinition, SyntaxType, TypedefDefinition, UnionDefinition, @@ -9,153 +11,297 @@ import { import { TypeMapping } from './types' -import { IRenderState, IResolvedIdentifier } from '../../types' +import { DefinitionType, IRenderState, IResolvedIdentifier } from '../../types' import { className, looseName, strictName, toolkitName } from './struct/utils' + import { fieldInterfaceName, renderUnionTypeName, unionTypeName, } from './union/union-fields' +import { + resolveIdentifierDefinition, + resolveIdentifierName, +} from '../../resolver/utils' + function renderStrictInterfaceReexport( id: IResolvedIdentifier, + definition: DefinitionType, node: TypedefDefinition, state: IRenderState, -): ts.ImportEqualsDeclaration { - return ts.createImportEqualsDeclaration( - undefined, - [ts.createToken(ts.SyntaxKind.ExportKeyword)], - ts.createIdentifier( - strictName(node.name.value, id.definition.type, state), - ), - ts.createIdentifier( - `${id.pathName}.${strictName(id.name, id.definition.type, state)}`, - ), - ) +): ts.Statement { + if (id.pathName !== undefined) { + return ts.createImportEqualsDeclaration( + undefined, + [ts.createToken(ts.SyntaxKind.ExportKeyword)], + ts.createIdentifier( + strictName(node.name.value, definition.type, state), + ), + ts.createIdentifier( + `${strictName(id.rawName, definition.type, state)}`, + ), + ) + } else { + return ts.createExportDeclaration( + [], + [], + ts.createNamedExports([ + ts.createExportSpecifier( + ts.createIdentifier( + `${strictName(id.rawName, definition.type, state)}`, + ), + ts.createIdentifier( + strictName(node.name.value, definition.type, state), + ), + ), + ]), + undefined, + ) + } } function renderLooseInterfaceReexport( id: IResolvedIdentifier, + definition: DefinitionType, node: TypedefDefinition, state: IRenderState, -): ts.ImportEqualsDeclaration { - return ts.createImportEqualsDeclaration( - undefined, - [ts.createToken(ts.SyntaxKind.ExportKeyword)], - ts.createIdentifier( - looseName(node.name.value, id.definition.type, state), - ), - ts.createIdentifier( - `${id.pathName}.${looseName(id.name, id.definition.type, state)}`, - ), - ) +): ts.Statement { + if (id.pathName !== undefined) { + return ts.createImportEqualsDeclaration( + undefined, + [ts.createToken(ts.SyntaxKind.ExportKeyword)], + ts.createIdentifier( + looseName(node.name.value, definition.type, state), + ), + ts.createIdentifier( + `${looseName(id.rawName, definition.type, state)}`, + ), + ) + } else { + return ts.createExportDeclaration( + [], + [], + ts.createNamedExports([ + ts.createExportSpecifier( + ts.createIdentifier( + `${looseName(id.rawName, definition.type, state)}`, + ), + ts.createIdentifier( + looseName(node.name.value, definition.type, state), + ), + ), + ]), + undefined, + ) + } } function renderClassReexport( id: IResolvedIdentifier, node: TypedefDefinition, -): ts.ImportEqualsDeclaration { - return ts.createImportEqualsDeclaration( - undefined, - [ts.createToken(ts.SyntaxKind.ExportKeyword)], - ts.createIdentifier(className(node.name.value)), - ts.createIdentifier(`${id.pathName}.${className(id.name)}`), - ) + state: IRenderState, +): ts.Statement { + if (id.pathName !== undefined) { + return ts.createImportEqualsDeclaration( + undefined, + [ts.createToken(ts.SyntaxKind.ExportKeyword)], + ts.createIdentifier(className(node.name.value, state)), + ts.createIdentifier(`${className(id.rawName, state)}`), + ) + } else { + return ts.createExportDeclaration( + [], + [], + ts.createNamedExports([ + ts.createExportSpecifier( + ts.createIdentifier(`${className(id.rawName, state)}`), + ts.createIdentifier(className(node.name.value, state)), + ), + ]), + undefined, + ) + } } function renderToolkitReexport( id: IResolvedIdentifier, + definition: StructDefinition | UnionDefinition | ExceptionDefinition, node: TypedefDefinition, -): ts.ImportEqualsDeclaration { - return ts.createImportEqualsDeclaration( - undefined, - [ts.createToken(ts.SyntaxKind.ExportKeyword)], - ts.createIdentifier(toolkitName(node.name.value)), - ts.createIdentifier(toolkitName(id.resolvedName)), - ) + state: IRenderState, +): ts.Statement { + if (id.pathName !== undefined) { + return ts.createImportEqualsDeclaration( + undefined, + [ts.createToken(ts.SyntaxKind.ExportKeyword)], + ts.createIdentifier(toolkitName(node.name.value, state)), + ts.createIdentifier(`${toolkitName(id.rawName, state)}`), + ) + } else { + return ts.createExportDeclaration( + [], + [], + ts.createNamedExports([ + ts.createExportSpecifier( + ts.createIdentifier(`${toolkitName(id.rawName, state)}`), + ts.createIdentifier(toolkitName(node.name.value, state)), + ), + ]), + undefined, + ) + } } function renderUnionTypeReexport( id: IResolvedIdentifier, node: TypedefDefinition, state: IRenderState, -): ts.ImportEqualsDeclaration { - return ts.createImportEqualsDeclaration( - undefined, - [ts.createToken(ts.SyntaxKind.ExportKeyword)], - ts.createIdentifier(renderUnionTypeName(node.name.value, state)), - ts.createIdentifier( - `${id.pathName}.${renderUnionTypeName(id.name, state)}`, - ), - ) +): ts.Statement { + if (id.pathName !== undefined) { + return ts.createImportEqualsDeclaration( + undefined, + [ts.createToken(ts.SyntaxKind.ExportKeyword)], + ts.createIdentifier(renderUnionTypeName(node.name.value, state)), + ts.createIdentifier(`${renderUnionTypeName(id.rawName, state)}`), + ) + } else { + return ts.createExportDeclaration( + [], + [], + ts.createNamedExports([ + ts.createExportSpecifier( + ts.createIdentifier( + `${renderUnionTypeName(id.rawName, state)}`, + ), + ts.createIdentifier( + renderUnionTypeName(node.name.value, state), + ), + ), + ]), + undefined, + ) + } } function renderUnionInterfaceReexports( id: IResolvedIdentifier, union: UnionDefinition, node: TypedefDefinition, - state: IRenderState, strict: boolean, -): Array { - return union.fields.map((next: FieldDefinition) => { - return ts.createImportEqualsDeclaration( - undefined, - [ts.createToken(ts.SyntaxKind.ExportKeyword)], - ts.createIdentifier( - fieldInterfaceName(node.name.value, next.name.value, strict), - ), - ts.createIdentifier( - `${id.pathName}.${fieldInterfaceName( - union.name.value, - next.name.value, - strict, - )}`, - ), - ) - }) +): Array { + if (id.pathName !== undefined) { + return union.fields.map((next: FieldDefinition) => { + return ts.createImportEqualsDeclaration( + undefined, + [ts.createToken(ts.SyntaxKind.ExportKeyword)], + ts.createIdentifier( + fieldInterfaceName( + node.name.value, + next.name.value, + strict, + ), + ), + ts.createIdentifier( + `${id.pathName}.${fieldInterfaceName( + union.name.value, + next.name.value, + strict, + )}`, + ), + ) + }) + } else { + return union.fields.map((next: FieldDefinition) => { + return ts.createExportDeclaration( + [], + [], + ts.createNamedExports([ + ts.createExportSpecifier( + ts.createIdentifier( + `${fieldInterfaceName( + union.name.value, + next.name.value, + strict, + )}`, + ), + ts.createIdentifier( + fieldInterfaceName( + node.name.value, + next.name.value, + strict, + ), + ), + ), + ]), + ) + }) + } } function renderUnionArgsReexport( id: IResolvedIdentifier, node: TypedefDefinition, -): ts.ImportEqualsDeclaration { - return ts.createImportEqualsDeclaration( - undefined, - [ts.createToken(ts.SyntaxKind.ExportKeyword)], - ts.createIdentifier(unionTypeName(node.name.value, false)), - ts.createIdentifier(`${id.pathName}.${unionTypeName(id.name, false)}`), - ) + state: IRenderState, +): ts.Statement { + if (id.pathName !== undefined) { + return ts.createImportEqualsDeclaration( + undefined, + [ts.createToken(ts.SyntaxKind.ExportKeyword)], + ts.createIdentifier(unionTypeName(node.name.value, state, false)), + ts.createIdentifier(`${unionTypeName(id.rawName, state, false)}`), + ) + } else { + return ts.createExportDeclaration( + [], + [], + ts.createNamedExports([ + ts.createExportSpecifier( + ts.createIdentifier( + `${unionTypeName(id.rawName, state, false)}`, + ), + ts.createIdentifier( + unionTypeName(node.name.value, state, false), + ), + ), + ]), + undefined, + ) + } } function renderTypeDefForIdentifier( - id: IResolvedIdentifier, + resolvedIdentifier: IResolvedIdentifier, + definition: DefinitionType, node: TypedefDefinition, typeMapping: TypeMapping, state: IRenderState, ): Array { - switch (id.definition.type) { + switch (definition.type) { case SyntaxType.UnionDefinition: if (state.options.strictUnions) { return [ - renderUnionTypeReexport(id, node, state), - renderClassReexport(id, node), + renderUnionTypeReexport(resolvedIdentifier, node, state), + renderClassReexport(resolvedIdentifier, node, state), ...renderUnionInterfaceReexports( - id, - id.definition, + resolvedIdentifier, + definition, node, - state, true, ), - renderUnionArgsReexport(id, node), + renderUnionArgsReexport(resolvedIdentifier, node, state), ...renderUnionInterfaceReexports( - id, - id.definition, + resolvedIdentifier, + definition, node, - state, false, ), - renderToolkitReexport(id, node), + renderToolkitReexport( + resolvedIdentifier, + definition, + node, + state, + ), ] } else { // Fallthrough to reexport union as struct @@ -163,19 +309,46 @@ function renderTypeDefForIdentifier( case SyntaxType.ExceptionDefinition: case SyntaxType.StructDefinition: return [ - renderStrictInterfaceReexport(id, node, state), - renderLooseInterfaceReexport(id, node, state), - renderClassReexport(id, node), - renderToolkitReexport(id, node), + renderStrictInterfaceReexport( + resolvedIdentifier, + definition, + node, + state, + ), + renderLooseInterfaceReexport( + resolvedIdentifier, + definition, + node, + state, + ), + renderClassReexport(resolvedIdentifier, node, state), + renderToolkitReexport( + resolvedIdentifier, + definition, + node, + state, + ), ] - default: + case SyntaxType.ConstDefinition: + case SyntaxType.EnumDefinition: return [ ts.createImportEqualsDeclaration( undefined, [ts.createToken(ts.SyntaxKind.ExportKeyword)], ts.createIdentifier(node.name.value), - ts.createIdentifier(id.resolvedName), + ts.createIdentifier(resolvedIdentifier.fullName), + ), + ] + + default: + return [ + ts.createTypeAliasDeclaration( + undefined, + [ts.createToken(ts.SyntaxKind.ExportKeyword)], + node.name.value, + undefined, + typeMapping(node.definitionType, state), ), ] } @@ -188,8 +361,19 @@ export function renderTypeDef( ): Array { switch (node.definitionType.type) { case SyntaxType.Identifier: + const resolvedIdentifier = resolveIdentifierName( + node.definitionType.value, + state, + ) + return renderTypeDefForIdentifier( - state.identifiers[node.definitionType.value], + resolvedIdentifier, + resolveIdentifierDefinition( + node.definitionType, + state.currentNamespace, + state.project.namespaces, + state.project.sourceDir, + ), node, typeMapping, state, @@ -202,7 +386,7 @@ export function renderTypeDef( [ts.createToken(ts.SyntaxKind.ExportKeyword)], node.name.value, undefined, - typeMapping(node.definitionType), + typeMapping(node.definitionType, state), ), ] } diff --git a/src/main/render/thrift-server/types.ts b/src/main/render/thrift-server/types.ts index e5715c3d..ce77456a 100644 --- a/src/main/render/thrift-server/types.ts +++ b/src/main/render/thrift-server/types.ts @@ -2,7 +2,7 @@ import * as ts from 'typescript' import { FunctionType, SyntaxType } from '@creditkarma/thrift-parser' -import { IIdentifierMap, IRenderState, IResolvedIdentifier } from '../../types' +import { DefinitionType, IRenderState } from '../../types' import { APPLICATION_EXCEPTION, @@ -18,6 +18,10 @@ import { createVoidType, } from '../shared/types' +import { + resolveIdentifierDefinition, + resolveIdentifierName, +} from '../../resolver/utils' import { looseName, strictName } from './struct/utils' export * from '../shared/types' @@ -101,20 +105,20 @@ export function applicationException( } function thriftTypeForIdentifier( - id: IResolvedIdentifier, - identifiers: IIdentifierMap, + definition: DefinitionType, + state: IRenderState, ): ts.Identifier { - switch (id.definition.type) { + switch (definition.type) { case SyntaxType.ConstDefinition: throw new TypeError( `Identifier ${ - id.definition.name.value + definition.name.value } is a value being used as a type`, ) case SyntaxType.ServiceDefinition: throw new TypeError( - `Service ${id.definition.name.value} is being used as a type`, + `Service ${definition.name.value} is being used as a type`, ) case SyntaxType.StructDefinition: @@ -126,36 +130,31 @@ function thriftTypeForIdentifier( return THRIFT_TYPES.I32 case SyntaxType.TypedefDefinition: - return thriftTypeForFieldType( - id.definition.definitionType, - identifiers, - ) + return thriftTypeForFieldType(definition.definitionType, state) default: - const msg: never = id.definition + const msg: never = definition throw new Error(`Non-exhaustive match for: ${msg}`) } } /** * Gets the type access for the 'Thrift' object for a given FieldType. - * - * This could and should probably be a map of FieldType -> ThriftAccess. - * However, using a switch statement gives us the safety of exhaustive matching - * for FieldTypes. - * - * @todo Clean up so that we can use the strictNullChecks compiler flag which - * would allow us to use a map and get the same safety as the switch. */ export function thriftTypeForFieldType( fieldType: FunctionType, - identifiers: IIdentifierMap, + state: IRenderState, ): ts.Identifier { switch (fieldType.type) { case SyntaxType.Identifier: return thriftTypeForIdentifier( - identifiers[fieldType.value], - identifiers, + resolveIdentifierDefinition( + fieldType, + state.currentNamespace, + state.project.namespaces, + state.project.sourceDir, + ), + state, ) case SyntaxType.SetType: @@ -227,26 +226,26 @@ export function thriftTypeForFieldType( * SyntaxType.VoidKeyword */ function typeNodeForIdentifier( - id: IResolvedIdentifier, + definition: DefinitionType, name: string, state: IRenderState, loose: boolean = false, ): ts.TypeNode { - switch (id.definition.type) { + switch (definition.type) { case SyntaxType.StructDefinition: case SyntaxType.ExceptionDefinition: case SyntaxType.UnionDefinition: if (loose) { return ts.createTypeReferenceNode( ts.createIdentifier( - looseName(name, id.definition.type, state), + looseName(name, definition.type, state), ), undefined, ) } else { return ts.createTypeReferenceNode( ts.createIdentifier( - strictName(name, id.definition.type, state), + strictName(name, definition.type, state), ), undefined, ) @@ -254,7 +253,9 @@ function typeNodeForIdentifier( default: return ts.createTypeReferenceNode( - ts.createIdentifier(name), + ts.createIdentifier( + resolveIdentifierName(name, state).fullName, + ), undefined, ) } @@ -268,7 +269,12 @@ export function typeNodeForFieldType( switch (fieldType.type) { case SyntaxType.Identifier: return typeNodeForIdentifier( - state.identifiers[fieldType.value], + resolveIdentifierDefinition( + fieldType, + state.currentNamespace, + state.project.namespaces, + state.project.sourceDir, + ), fieldType.value, state, loose, diff --git a/src/main/render/thrift-server/union/class.ts b/src/main/render/thrift-server/union/class.ts index ba68b586..20c68b44 100644 --- a/src/main/render/thrift-server/union/class.ts +++ b/src/main/render/thrift-server/union/class.ts @@ -95,7 +95,7 @@ export function renderClass( return ts.createClassDeclaration( undefined, tokens(isExported), - classNameForStruct(node), + classNameForStruct(node, state), [], [extendsAbstract(), implementsInterface(node, state)], // heritage [ @@ -103,9 +103,9 @@ export function renderClass( annotations, fieldAnnotations, ctor, - createStaticReadMethod(node), + createStaticReadMethod(node, state), createStaticWriteMethod(node, state), - createWriteMethod(node), + createWriteMethod(node, state), ], ) } diff --git a/src/main/render/thrift-server/union/create.ts b/src/main/render/thrift-server/union/create.ts index 410ee13b..cd68e960 100644 --- a/src/main/render/thrift-server/union/create.ts +++ b/src/main/render/thrift-server/union/create.ts @@ -38,11 +38,14 @@ import { incrementFieldsSet, } from './utils' -function createArgsParameter(node: UnionDefinition): ts.ParameterDeclaration { +function createArgsParameter( + node: UnionDefinition, + state: IRenderState, +): ts.ParameterDeclaration { return createFunctionParameter( 'args', // param name ts.createTypeReferenceNode( - ts.createIdentifier(unionTypeName(node.name.value, false)), + ts.createIdentifier(unionTypeName(node.name.value, state, false)), undefined, ), ) @@ -52,7 +55,10 @@ export function createCreateMethod( node: UnionDefinition, state: IRenderState, ): ts.MethodDeclaration { - const inputParameter: ts.ParameterDeclaration = createArgsParameter(node) + const inputParameter: ts.ParameterDeclaration = createArgsParameter( + node, + state, + ) const returnVariable: ts.VariableStatement = createReturnVariable( node, state, @@ -189,7 +195,7 @@ export function createCaseForField( const checkType: ts.IfStatement = ts.createIf( createEqualsCheck( COMMON_IDENTIFIERS.fieldType, - thriftTypeForFieldType(field.fieldType, state.identifiers), + thriftTypeForFieldType(field.fieldType, state), ), ts.createBlock( [ @@ -239,6 +245,7 @@ export function endReadForField( export function createReturnForStruct( struct: InterfaceWithFields, + state: IRenderState, ): ts.Statement { if (hasRequiredField(struct)) { return ts.createIf( @@ -253,7 +260,11 @@ export function createReturnForStruct( ): ts.ObjectLiteralElementLike => { return ts.createPropertyAssignment( next.name.value, - getInitializerForField('_args', next), + getInitializerForField( + '_args', + next, + state, + ), ) }, ), diff --git a/src/main/render/thrift-server/union/decode.ts b/src/main/render/thrift-server/union/decode.ts index 5b528cdd..d6fc91bc 100644 --- a/src/main/render/thrift-server/union/decode.ts +++ b/src/main/render/thrift-server/union/decode.ts @@ -237,7 +237,7 @@ export function createCaseForField( const checkType: ts.IfStatement = ts.createIf( createEqualsCheck( COMMON_IDENTIFIERS.fieldType, - thriftTypeForFieldType(field.fieldType, state.identifiers), + thriftTypeForFieldType(field.fieldType, state), ), ts.createBlock( [ @@ -315,6 +315,7 @@ export function metadataTypeForFieldType( export function createReturnForStruct( struct: InterfaceWithFields, + state: IRenderState, ): ts.Statement { if (hasRequiredField(struct)) { return ts.createIf( @@ -329,7 +330,11 @@ export function createReturnForStruct( ): ts.ObjectLiteralElementLike => { return ts.createPropertyAssignment( next.name.value, - getInitializerForField('_args', next), + getInitializerForField( + '_args', + next, + state, + ), ) }, ), diff --git a/src/main/render/thrift-server/union/encode.ts b/src/main/render/thrift-server/union/encode.ts index 16bbb437..60ada19a 100644 --- a/src/main/render/thrift-server/union/encode.ts +++ b/src/main/render/thrift-server/union/encode.ts @@ -63,7 +63,7 @@ export function createEncodeMethod( ts.createBlock( [ createFieldIncrementer(), - ...createTempVariables(node, state.identifiers), + ...createTempVariables(node, state), writeStructBegin(node.name.value), ...node.fields.filter(isNotVoid).map((field) => { return createWriteForField(node, field, state) @@ -127,7 +127,7 @@ export function createWriteForFieldType( return ts.createBlock( [ incrementFieldsSet(), - writeFieldBegin(field, state.identifiers), + writeFieldBegin(field, state), ...writeValueForField(node, field.fieldType, fieldName, state), writeFieldEnd(), ], diff --git a/src/main/render/thrift-server/union/toolkit.ts b/src/main/render/thrift-server/union/toolkit.ts index 5e18f338..69b0e634 100644 --- a/src/main/render/thrift-server/union/toolkit.ts +++ b/src/main/render/thrift-server/union/toolkit.ts @@ -70,7 +70,7 @@ export function renderToolkit( return ts.createVariableStatement( tokens(isExported), createConst( - ts.createIdentifier(toolkitNameForStruct(node)), + ts.createIdentifier(toolkitNameForStruct(node, state)), renderToolkitTypeNode(node, state), ts.createObjectLiteral(renderMethodsForCodec(node, state), true), ), diff --git a/src/main/render/thrift-server/union/union-fields.ts b/src/main/render/thrift-server/union/union-fields.ts index ee7547ba..b9753764 100644 --- a/src/main/render/thrift-server/union/union-fields.ts +++ b/src/main/render/thrift-server/union/union-fields.ts @@ -4,7 +4,7 @@ import { FieldDefinition, UnionDefinition } from '@creditkarma/thrift-parser' import { IRenderState } from '../../../types' import { COMMON_IDENTIFIERS } from '../../shared/identifiers' -import { createVoidType } from '../../shared/types' +import { createUndefinedType } from '../../shared/types' import { className, tokens } from '../struct/utils' import { typeNodeForFieldType } from '../types' @@ -38,19 +38,23 @@ export function fieldTypeAccess( )}` } -export function unionTypeName(name: string, strict: boolean): string { +export function unionTypeName( + name: string, + state: IRenderState, + strict: boolean, +): string { if (strict) { - return className(name) + return className(name, state) } else { - return `${className(name)}Args` + return `${className(name, state)}Args` } } export function renderUnionTypeName(name: string, state: IRenderState): string { if (state.options.strictUnionsComplexNames) { - return `${unionTypeName(name, true)}__Type` + return `${unionTypeName(name, state, true)}__Type` } else { - return `${unionTypeName(name, true)}Type` + return `${unionTypeName(name, state, true)}Type` } } @@ -109,7 +113,7 @@ function renderInterfaceForField( undefined, next.name.value, ts.createToken(ts.SyntaxKind.QuestionToken), - createVoidType(), + createUndefinedType(), undefined, ) } @@ -152,7 +156,7 @@ export function renderUnionsForFields( ts.createTypeAliasDeclaration( undefined, tokens(isExported), - unionTypeName(node.name.value, strict), + unionTypeName(node.name.value, state, strict), undefined, ts.createUnionTypeNode([ ...node.fields.map((next: FieldDefinition) => { diff --git a/src/main/render/thrift-server/utils.ts b/src/main/render/thrift-server/utils.ts index b68cc61c..c81a9e36 100644 --- a/src/main/render/thrift-server/utils.ts +++ b/src/main/render/thrift-server/utils.ts @@ -18,6 +18,7 @@ import { renderValue } from './initializers' import { createNotNullCheck } from './utils' +import { IRenderState } from '../../types' import { APPLICATION_EXCEPTION, COMMON_IDENTIFIERS, @@ -87,6 +88,7 @@ export function coerceType( export function getInitializerForField( objName: string, field: FieldDefinition, + state: IRenderState, loose: boolean = false, ): ts.Expression { const valueName: ts.Identifier = ts.createIdentifier( @@ -100,7 +102,7 @@ export function getInitializerForField( loose === true ? coerceType(valueName, field.fieldType) : valueName, - renderValue(field.fieldType, field.defaultValue), + renderValue(field.fieldType, field.defaultValue, state), ), ) } else { diff --git a/src/main/resolver/index.ts b/src/main/resolver/index.ts index bb5425f8..775d66aa 100644 --- a/src/main/resolver/index.ts +++ b/src/main/resolver/index.ts @@ -1,474 +1,466 @@ -/** - * RESOLVER - * - * TODO: Some of the logic in this file may best fit with thrift-parser. Will need - * to revist this and decide what logic is generic enough to be in the parser. What - * could other code generators use? - */ import { ConstValue, + EnumMember, FieldDefinition, + FieldID, FieldType, FunctionDefinition, FunctionType, + Identifier, + IntConstant, SyntaxType, ThriftStatement, - TypedefDefinition, } from '@creditkarma/thrift-parser' import { - DefinitionType, - IIdentifierMap, + IFileExports, IMakeOptions, - INamespace, + INamespacePath, + INamespacePathMap, + INamespaceToIncludeMap, IParsedFile, - IResolvedCache, IResolvedFile, - IResolvedFileMap, - IResolvedIdentifier, - IResolvedIncludeMap, + ParsedFileMap, } from '../types' -import { resolveNamespace } from './utils' +import { createValidationError, IThriftError, ValidationError } from '../errors' + +import { emptyLocation, namespaceForInclude } from '../utils' + +import { + exportsForFile, + resolveConstValue, + resolveIdentifierDefinition, +} from './utils' /** - * The job of the resolver is to traverse the AST and find all of the Identifiers. In order to - * correctly generate code we need to know the types of all Identifiers. The type of an - * Identifier may be defined in this Thrift doc or a Thrift doc imported through an include. - * - * The resolve function will find the ultimate definition of an Identifier and save its type - * to a hash map of the form (name -> type) - * - * There are ultimately two places we need to look for Identifiers. Types or values defined by - * this file will be defined by a ThriftStatement. When looping through the Thrift statements - * we need to save all statements that can be exported and used as types by other files. These - * are Structs, Unions, Exceptions, Enums and TypeDefs - * - * The other thing we need to do is look at Identifiers used by this file. Identifiers can appear - * in three positions, FieldType, ReturnType or value (initializer or defaultValue). The usual case - * is for an Identifier to represent a type, but an Identifier can represent a value if the - * Identifier represents a const or an enum. When we find an Identifier we need to resolve what it - * actualy refers to. - * - * - * REDRAW THE AST - * - * The other thing this will do is redraw the AST so that imported Identifiers no longer use - * the dot syntax. The dot syntax is replaced with '$' - * - * For example + * What do you mean, resolve file? * - * // thrift - * const example.Type name = "value" + * There are a few things we need to do to resolve a file. * - * // typescript - * const name: example$Type = "value" + * 1. We need to resolve the value of all the identifiers in a given file. * - * Then, when we create our imports we do this: + * 2. We need to keep track of all the namespaces being used in this file. * - * import { Type as example$Type } from './example' + * 3. We need to rewrite the paths for imported identifiers. * + * For example, if a identifier is being imported from another file such as "operation.Operation", we + * need to rewrite this so that the file path is replaced with the namespace path such as + * "com_test_operation.Operation" * - * KEEP TRACK OF USED IMPORTS + * 4. We need to rewrite indetifiers that point to primitive constants with the primitive value. * - * When we ultimately generate TypeScript we will need to import types from the included files. The - * final thing the resolver does is keep a list of all Identifiers used from a specific import. This - * allows us to only import what we need from given files. + * 5. We need to make sure every field has an ID * + * 6. We need to rewrite all enum members with an initiaizer * - * IRESOLVEDFILE * - * Ultimately this returns an object of the type IResolvedFile which will contain the namespaces for - * this Thrift file, the resolved includes, the resolved Identifiers and a new doc body where Identifiers - * in statements are using the rewritten names. - * - * @param thrift - * @param includes + * @param parsedFile + * @param files + * @param sourceDir + * @param options */ export function resolveFile( - outPath: string, parsedFile: IParsedFile, + files: ParsedFileMap, + sourceDir: string, options: IMakeOptions, - cache: IResolvedCache = {}, ): IResolvedFile { - const cacheKey: string = `${parsedFile.path}/${parsedFile.name}` - - if (cacheKey === '/' || !cache[cacheKey]) { - const identifiers: IIdentifierMap = {} - const resolvedIncludes: IResolvedIncludeMap = {} - const namespace: INamespace = resolveNamespace( - outPath, - parsedFile.ast, - options, - ) - const includes: Array = parsedFile.includes.map( - (next: IParsedFile): IResolvedFile => { - return resolveFile(outPath, next, options, cache) - }, - ) - - const includeMap: IResolvedFileMap = includes.reduce( - (acc: IResolvedFileMap, next: IResolvedFile): IResolvedFileMap => { - acc[next.name] = next - return acc - }, - {}, - ) - - for (const include of includes) { - resolvedIncludes[include.name] = { - file: include, - identifiers: [], + const body: Array = parsedFile.body + const bodySize: number = body.length + let currentIndex: number = 0 + + const errors: Array = [] + const includedNamespaces: INamespacePathMap = {} + const namespaceToInclude: INamespaceToIncludeMap = {} + + function resolveStatements(): Array { + const newBody: Array = [] + while (!isAtEnd()) { + try { + const statement = resolveStatement(body[currentIndex]) + + if (statement !== null) { + newBody.push(statement) + } + } catch (e) { + errors.push(createValidationError(e.message, e.loc)) } + + currentIndex += 1 } - function resolveFunctionType(fieldType: FunctionType): FunctionType { - switch (fieldType.type) { - case SyntaxType.VoidKeyword: - return fieldType + return newBody + } - default: - return resolveFieldType(fieldType) - } - } + function isAtEnd(): boolean { + return currentIndex >= bodySize + } - function resolveFieldType(fieldType: FieldType): FieldType { - switch (fieldType.type) { - /** - * An Identifier can refer to either a container type or an alias to another - * type. Here we check for the typedef case and resolve to the base type in that - * case. - */ - case SyntaxType.Identifier: - const id: IResolvedIdentifier = identifiers[fieldType.value] - if ( - id !== undefined && - id.definition.type === SyntaxType.TypedefDefinition - ) { - return id.definition.definitionType - } else { - return { - type: SyntaxType.Identifier, - value: resolveName(fieldType.value), - loc: fieldType.loc, - } - } + function resolveStatement( + statement: ThriftStatement, + ): ThriftStatement | null { + switch (statement.type) { + case SyntaxType.NamespaceDefinition: + case SyntaxType.IncludeDefinition: + case SyntaxType.CppIncludeDefinition: + return null + + case SyntaxType.TypedefDefinition: + return { + type: SyntaxType.TypedefDefinition, + name: statement.name, + definitionType: resolveFieldType(statement.definitionType), + annotations: statement.annotations, + comments: statement.comments, + loc: statement.loc, + } - case SyntaxType.ListType: - return { - type: SyntaxType.ListType, - valueType: resolveFieldType(fieldType.valueType), - loc: fieldType.loc, - } + case SyntaxType.ConstDefinition: + return { + type: SyntaxType.ConstDefinition, + name: statement.name, + fieldType: resolveFieldType(statement.fieldType), + initializer: resolveValue( + statement.initializer, + statement.fieldType, + ), + comments: statement.comments, + annotations: statement.annotations, + loc: statement.loc, + } - case SyntaxType.SetType: - return { - type: SyntaxType.SetType, - valueType: resolveFieldType(fieldType.valueType), - loc: fieldType.loc, - } + case SyntaxType.EnumDefinition: + return { + type: SyntaxType.EnumDefinition, + name: statement.name, + members: resolveEnumMembers(statement.members), + comments: statement.comments, + annotations: statement.annotations, + loc: statement.loc, + } - case SyntaxType.MapType: - return { - type: SyntaxType.MapType, - valueType: resolveFieldType(fieldType.valueType), - keyType: resolveFieldType(fieldType.keyType), - loc: fieldType.loc, - } + case SyntaxType.StructDefinition: + return { + type: SyntaxType.StructDefinition, + name: statement.name, + fields: resolveFields(statement.fields), + comments: statement.comments, + annotations: statement.annotations, + loc: statement.loc, + } - default: - return fieldType - } - } + case SyntaxType.UnionDefinition: + return { + type: SyntaxType.UnionDefinition, + name: statement.name, + fields: resolveFields(statement.fields), + comments: statement.comments, + annotations: statement.annotations, + loc: statement.loc, + } - function resolveValue(constValue: ConstValue): ConstValue { - switch (constValue.type) { - case SyntaxType.Identifier: - return { - type: SyntaxType.Identifier, - value: resolveName(constValue.value), - loc: constValue.loc, - } + case SyntaxType.ExceptionDefinition: + return { + type: SyntaxType.ExceptionDefinition, + name: statement.name, + fields: resolveFields(statement.fields), + comments: statement.comments, + annotations: statement.annotations, + loc: statement.loc, + } - default: - return constValue - } - } + case SyntaxType.ServiceDefinition: + return { + type: SyntaxType.ServiceDefinition, + name: statement.name, + functions: resolveFunctions(statement.functions), + extends: + statement.extends === null + ? null + : resolveIdentifier(statement.extends), + comments: statement.comments, + annotations: statement.annotations, + loc: statement.loc, + } - function resolveFunction(func: FunctionDefinition): FunctionDefinition { - return { - type: SyntaxType.FunctionDefinition, - name: func.name, - returnType: resolveFunctionType(func.returnType), - fields: func.fields.map(resolveField), - throws: func.throws.map(resolveField), - comments: func.comments, - annotations: func.annotations, - oneway: func.oneway, - modifiers: func.modifiers, - loc: func.loc, - } + default: + const msg: never = statement + throw new Error(`Non-exhaustive match for ${msg}`) } + } - function resolveField(field: FieldDefinition): FieldDefinition { - return { - type: SyntaxType.FieldDefinition, - name: field.name, - fieldID: field.fieldID, - fieldType: resolveFunctionType(field.fieldType), - requiredness: field.requiredness, - defaultValue: - field.defaultValue !== null - ? resolveValue(field.defaultValue) - : null, - comments: field.comments, - annotations: field.annotations, - loc: field.loc, - } + function resolveIdentifier(id: Identifier): Identifier { + return { + type: SyntaxType.Identifier, + value: resolveName(id.value), + annotations: id.annotations, + loc: id.loc, } + } - function resolveStatement(statement: ThriftStatement): ThriftStatement { - switch (statement.type) { - case SyntaxType.ConstDefinition: - return { - type: SyntaxType.ConstDefinition, - name: statement.name, - fieldType: resolveFieldType(statement.fieldType), - initializer: resolveValue(statement.initializer), - comments: statement.comments, - annotations: statement.annotations, - loc: statement.loc, - } - - case SyntaxType.ServiceDefinition: - return { - type: SyntaxType.ServiceDefinition, - name: statement.name, - extends: - statement.extends !== null - ? { - type: SyntaxType.Identifier, - value: resolveName( - statement.extends.value, - ), - loc: statement.extends.loc, - } - : null, - functions: statement.functions.map( - (next: FunctionDefinition) => { - return resolveFunction(next) - }, - ), - comments: statement.comments, - annotations: statement.annotations, - loc: statement.loc, + function resolveName(name: string): string { + const [head, ...tail] = name.split('.') + if (parsedFile.exports[head] !== undefined) { + return name + } else if (parsedFile.includes[head] !== undefined) { + const namespace: INamespacePath = namespaceForInclude( + parsedFile.includes[head], + files, + sourceDir, + options, + ) + const includeAccessor: string = namespace.name + .split('') + .map((next: string) => { + if (next === '.') { + return '_' + } else { + return next } + }) + .join('') + includedNamespaces[includeAccessor] = namespace + namespaceToInclude[includeAccessor] = head + return [includeAccessor, ...tail].join('.') + } else { + return name + } + } - case SyntaxType.StructDefinition: - return { - type: SyntaxType.StructDefinition, - name: statement.name, - fields: statement.fields.map(resolveField), - comments: statement.comments, - annotations: statement.annotations, - loc: statement.loc, - } + function resolveFunctionType(fieldType: FunctionType): FunctionType { + switch (fieldType.type) { + case SyntaxType.VoidKeyword: + return fieldType - case SyntaxType.UnionDefinition: - return { - type: SyntaxType.UnionDefinition, - name: statement.name, - fields: statement.fields.map(resolveField), - comments: statement.comments, - annotations: statement.annotations, - loc: statement.loc, - } + default: + return resolveFieldType(fieldType) + } + } - case SyntaxType.ExceptionDefinition: - return { - type: SyntaxType.ExceptionDefinition, - name: statement.name, - fields: statement.fields.map(resolveField), - comments: statement.comments, - annotations: statement.annotations, - loc: statement.loc, - } + function isBaseType(fieldType: FieldType): boolean { + switch (fieldType.type) { + case SyntaxType.I8Keyword: + case SyntaxType.I16Keyword: + case SyntaxType.I32Keyword: + case SyntaxType.I64Keyword: + case SyntaxType.StringKeyword: + case SyntaxType.BinaryKeyword: + return true + default: + return false + } + } - case SyntaxType.TypedefDefinition: - return { - type: SyntaxType.TypedefDefinition, - name: statement.name, - definitionType: resolveFieldType( - statement.definitionType, - ), - comments: statement.comments, - annotations: statement.annotations, - loc: statement.loc, + function resolveFieldType(fieldType: FieldType): FieldType { + switch (fieldType.type) { + /** + * An Identifier can refer to either a container type or an alias to another + * type. Here we check for the typedef case and resolve to the base type in that + * case. + */ + case SyntaxType.Identifier: + const definition = resolveIdentifierDefinition( + fieldType, + parsedFile, + files, + sourceDir, + ) + if (definition.type === SyntaxType.TypedefDefinition) { + if (isBaseType(definition.definitionType)) { + return definition.definitionType + } else { + return resolveIdentifier(fieldType) } + } else { + return resolveIdentifier(fieldType) + } - default: - return statement - } - } + case SyntaxType.ListType: + return { + type: SyntaxType.ListType, + valueType: resolveFieldType(fieldType.valueType), + annotations: fieldType.annotations, + loc: fieldType.loc, + } - function containsIdentifier( - pathName: string, - resolvedName: string, - ): boolean { - for (const include of resolvedIncludes[pathName].identifiers) { - if (include.resolvedName === resolvedName) { - return true + case SyntaxType.SetType: + return { + type: SyntaxType.SetType, + valueType: resolveFieldType(fieldType.valueType), + annotations: fieldType.annotations, + loc: fieldType.loc, } - } - return false - } - function definitionForTypeDef( - statement: TypedefDefinition, - ): DefinitionType { - switch (statement.definitionType.type) { - case SyntaxType.Identifier: - return identifiers[statement.definitionType.value] - .definition + case SyntaxType.MapType: + return { + type: SyntaxType.MapType, + valueType: resolveFieldType(fieldType.valueType), + keyType: resolveFieldType(fieldType.keyType), + annotations: fieldType.annotations, + loc: fieldType.loc, + } - default: - return statement - } + default: + return fieldType } + } - // Add types defined in this file to our Identifier map - function addIdentiferForStatement(statement: ThriftStatement): void { - switch (statement.type) { - case SyntaxType.StructDefinition: - case SyntaxType.UnionDefinition: - case SyntaxType.ExceptionDefinition: - case SyntaxType.EnumDefinition: - case SyntaxType.ConstDefinition: - case SyntaxType.ServiceDefinition: - identifiers[statement.name.value] = { - name: statement.name.value, - pathName: '', - resolvedName: statement.name.value, - definition: statement, - } - return - - case SyntaxType.TypedefDefinition: - identifiers[statement.name.value] = { - name: statement.name.value, - pathName: '', - resolvedName: statement.name.value, - definition: definitionForTypeDef(statement), - } - return + function resolveEnumMembers( + enumMembers: Array, + ): Array { + let previousValue: number = -1 - default: - return - } - } + return enumMembers.map( + (next: EnumMember): EnumMember => { + let initializer: IntConstant - function resolveName(name: string): string { - const parts: Array = name.split('.') - - if (parts.length > 1) { - const [pathname, base, ...tail] = parts - - /** - * In this case we are dealing with an Identifier that is defined in - * another file. The first part (pathname) is a reference to the file - * containing the type definition - */ - if (resolvedIncludes[pathname] !== undefined) { - const resolvedName: string = `${pathname}.${base}` - const baseIdentifier: IResolvedIdentifier = - includeMap[pathname].identifiers[base] - - identifiers[resolvedName] = { - name: baseIdentifier.name, - pathName: pathname, - resolvedName, - definition: baseIdentifier.definition, + if (next.initializer !== null) { + previousValue = parseInt(next.initializer.value.value, 10) + initializer = next.initializer + } else { + initializer = { + type: SyntaxType.IntConstant, + value: { + type: SyntaxType.IntegerLiteral, + value: `${++previousValue}`, + loc: emptyLocation(), + }, + loc: emptyLocation(), } + } - if (!containsIdentifier(pathname, resolvedName)) { - const resolvedIdentifier: IResolvedIdentifier = { - name: base, - pathName: pathname, - resolvedName, - definition: baseIdentifier.definition, - } - - resolvedIncludes[pathname].identifiers.push( - resolvedIdentifier, - ) - } + return { + type: SyntaxType.EnumMember, + name: next.name, + initializer, + comments: next.comments, + annotations: next.annotations, + loc: next.loc, + } + }, + ) + } - if (tail.length > 0) { - return `${resolvedName}.${tail.join('.')}` - } else { - return resolvedName - } + function resolveValue( + value: ConstValue, + fieldType: FunctionType, + ): ConstValue { + const resolvedValue: ConstValue = resolveConstValue( + value, + fieldType, + parsedFile, + files, + sourceDir, + ) - /** - * This case handles assignment to values - * - * ``` - * enum MyEnum { - * ONE, - * TWO - * } - * - * typedef OtherName = MyEnum - * - * const OtherName TEST = OtherName.ONE - * ``` - * - * We need to resolve 'OtherName' in the value assignement - */ - } else { - const id: IResolvedIdentifier = identifiers[pathname] - - if (id !== undefined) { - if ( - id.definition.type === SyntaxType.TypedefDefinition - ) { - if ( - id.definition.definitionType.type === - SyntaxType.Identifier - ) { - return [ - id.definition.definitionType.value, - base, - ...tail, - ].join('.') - } - } - } + if (resolvedValue.type === SyntaxType.Identifier) { + return resolveIdentifier(resolvedValue) + } else { + return resolvedValue + } + } - return name + function resolveFields( + fields: Array, + ): Array { + let generatedFieldID: number = 0 + const usedFieldIDs: Array = [] + + function resolveFieldID(fieldID: FieldID | null): FieldID { + if (fieldID === null) { + return { + type: SyntaxType.FieldID, + value: --generatedFieldID, + loc: emptyLocation(), } + } else if (fieldID.value < 0) { + throw new ValidationError( + `Field IDs should be positive integers, found ${ + fieldID.value + }`, + fieldID.loc, + ) + } else if (usedFieldIDs.indexOf(fieldID.value) > -1) { + throw new ValidationError( + `Found duplicate usage of fieldID: ${fieldID.value}`, + fieldID.loc, + ) } else { - return name + usedFieldIDs.push(fieldID.value) + return fieldID } } - cache[cacheKey] = { - name: parsedFile.name, - path: parsedFile.path, - source: parsedFile.source, - namespace, - includes: resolvedIncludes, - identifiers, - body: parsedFile.ast.body.map((statement: ThriftStatement) => { - const resolvedStatement: ThriftStatement = resolveStatement( - statement, - ) - addIdentiferForStatement(resolvedStatement) - return resolvedStatement - }), - errors: [], - } + return fields.map( + (field: FieldDefinition): FieldDefinition => { + return { + type: SyntaxType.FieldDefinition, + name: field.name, + fieldID: resolveFieldID(field.fieldID), + fieldType: resolveFunctionType(field.fieldType), + requiredness: field.requiredness, + defaultValue: + field.defaultValue === null + ? null + : resolveValue(field.defaultValue, field.fieldType), + comments: field.comments, + annotations: field.annotations, + loc: field.loc, + } + }, + ) } - return cache[cacheKey] + function resolveFunctions( + funcs: Array, + ): Array { + return funcs.map( + (func: FunctionDefinition): FunctionDefinition => { + return { + type: SyntaxType.FunctionDefinition, + name: func.name, + oneway: func.oneway, + returnType: resolveFunctionType(func.returnType), + fields: resolveFields( + func.fields.map((next: FieldDefinition) => { + next.requiredness = + next.requiredness === 'optional' + ? 'optional' + : 'required' + return next + }), + ), + throws: resolveFields( + func.throws.map((next: FieldDefinition) => { + next.requiredness = + next.requiredness === 'optional' + ? 'optional' + : 'required' + return next + }), + ), + modifiers: func.modifiers, + comments: func.comments, + annotations: func.annotations, + loc: func.loc, + } + }, + ) + } + + const resolvedBody: Array = resolveStatements() + const resolvedExports: IFileExports = exportsForFile(resolvedBody) + + return { + type: 'ResolvedFile', + sourceFile: parsedFile.sourceFile, + namespace: parsedFile.namespace, + includedNamespaces, + namespaceToInclude, + includes: parsedFile.includes, + exports: resolvedExports, + body: resolvedBody, + errors, + } } diff --git a/src/main/resolver/utils.ts b/src/main/resolver/utils.ts index a820a15c..3247603a 100644 --- a/src/main/resolver/utils.ts +++ b/src/main/resolver/utils.ts @@ -1,78 +1,451 @@ import { - NamespaceDefinition, + ConstValue, + createBooleanLiteral, + FunctionType, + Identifier, + PropertyAssignment, SyntaxType, - ThriftDocument, ThriftStatement, } from '@creditkarma/thrift-parser' -import * as path from 'path' -import { IMakeOptions, INamespace, INamespaceMap } from '../types' +import { + DefinitionType, + IFileExports, + IIncludePath, + INamespace, + INamespaceMap, + INamespacePath, + IParsedFile, + IProcessedFile, + IProcessedFileMap, + IRenderState, + IResolvedFile, + IResolvedIdentifier, + ParsedFileMap, + ResolvedFileMap, +} from '../types' + +import { ValidationError } from '../errors' +import { emptyLocation, fileForInclude } from '../utils' + +// Give some thrift statements this generates a map of the name of those statements to the +// definition of that statement +export function exportsForFile(body: Array): IFileExports { + return body.reduce((acc: IFileExports, next: ThriftStatement) => { + switch (next.type) { + case SyntaxType.TypedefDefinition: + case SyntaxType.ConstDefinition: + case SyntaxType.EnumDefinition: + case SyntaxType.UnionDefinition: + case SyntaxType.ExceptionDefinition: + case SyntaxType.StructDefinition: + case SyntaxType.ServiceDefinition: + acc[next.name.value] = next + break + + default: + // Ignore + break + } -function createPathForNamespace(outPath: string, ns: string): string { - return path.resolve(outPath, ns.split('.').join('/'), 'index.ts') + return acc + }, {}) } -function emptyNamespace(outPath: string = ''): INamespace { +function stubIdentifier(value: string): Identifier { return { - scope: '', - name: '', - path: createPathForNamespace(outPath, ''), + type: SyntaxType.Identifier, + value, + annotations: undefined, + loc: emptyLocation(), } } -/** - * In Scrooge we are defaulting to use the Java namespace, so keeping that for now. - * Probably want to update at somepoint to not fall back to that, or have the fallback - * be configurable. - * - * @param namespaces - */ -function getNamespace( - outPath: string, +// Given an identifier and the parsed file where the identifier is being used find +// the definition of the identifier +function resolveIdentifierFromParsedFile( + id: Identifier, + currentFile: IParsedFile, + files: ParsedFileMap, + sourceDir: string, +): DefinitionType { + const [head, ...tail] = id.value.split('.') + if (currentFile.exports[head] !== undefined) { + const definition: DefinitionType = currentFile.exports[head] + if (definition.type === SyntaxType.TypedefDefinition) { + if (definition.definitionType.type === SyntaxType.Identifier) { + return resolveIdentifierFromParsedFile( + definition.definitionType, + currentFile, + files, + sourceDir, + ) + } else { + return definition + } + } else { + return definition + } + } else if (currentFile.includes[head] !== undefined) { + const include: IIncludePath | undefined = currentFile.includes[head] + if (include !== undefined) { + // The next file to look in for the definition of this constant + const nextFile: IParsedFile = fileForInclude( + include, + files, + sourceDir, + ) + + return resolveIdentifierFromParsedFile( + stubIdentifier(tail.join('.')), + nextFile, + files, + sourceDir, + ) + } + } + + throw new ValidationError( + `Unable to resolve identifier[${id.value}] in parsed file[${ + currentFile.sourceFile.fullPath + }]`, + id.loc, + ) +} + +// Given an identifier and the resolved file where the identifier is being used find +// the definition of the identifier +function resolveIdentifierFromResolvedFile( + id: Identifier, + currentFile: IResolvedFile, + files: ResolvedFileMap, + sourceDir: string, +): DefinitionType { + // The head of the identifier can be one of two things. It can be an identifier defined in this file, + // or it can be an include path. + const [head, ...tail] = id.value.split('.') + if (currentFile.exports[head] !== undefined) { + const definition: DefinitionType = currentFile.exports[head] + if (definition.type === SyntaxType.TypedefDefinition) { + if (definition.definitionType.type === SyntaxType.Identifier) { + return resolveIdentifierFromResolvedFile( + definition.definitionType, + currentFile, + files, + sourceDir, + ) + } else { + return definition + } + } else { + return definition + } + } else if (currentFile.namespaceToInclude[head] !== undefined) { + const includeName: string = currentFile.namespaceToInclude[head] + const include: IIncludePath | undefined = + currentFile.includes[includeName] + if (include !== undefined) { + // The next file to look in for the definition of this constant + const nextFile: IResolvedFile = fileForInclude( + include, + files, + sourceDir, + ) + + return resolveIdentifierFromResolvedFile( + stubIdentifier(tail.join('.')), + nextFile, + files, + sourceDir, + ) + } + } + + throw new ValidationError( + `Unable to resolve identifier[${id.value}] in resolved file[${ + currentFile.sourceFile.fullPath + }]`, + id.loc, + ) +} + +// Given an identifier and the namespace where the identifier is being used find +// the definition of the identifier +function resolveIdentifierFromNamespace( + id: Identifier, + currentNamespace: INamespace, namespaces: INamespaceMap, - options: IMakeOptions, -): INamespace { - if (namespaces.js) { - return namespaces.js - } else if ( - options.fallbackNamespace !== 'none' && - namespaces[options.fallbackNamespace] - ) { - return namespaces[options.fallbackNamespace] + sourceDir: string, +): DefinitionType { + if (currentNamespace.exports[id.value]) { + const definition: DefinitionType = currentNamespace.exports[id.value] + if (definition.type === SyntaxType.TypedefDefinition) { + if (definition.definitionType.type === SyntaxType.Identifier) { + return resolveIdentifierFromNamespace( + definition.definitionType, + currentNamespace, + namespaces, + sourceDir, + ) + } else { + return definition + } + } else { + return definition + } } else { - return emptyNamespace(outPath) + const [head, ...tail] = id.value.split('.') + const namespace: INamespacePath = + currentNamespace.includedNamespaces[head] + + if (namespace !== undefined) { + const nextNamespace: INamespace = namespaces[namespace.path] + + return resolveIdentifierFromNamespace( + stubIdentifier(tail.join('.')), + nextNamespace, + namespaces, + sourceDir, + ) + } + + throw new ValidationError( + `Unable to resolve identifier[${id.value}] in namespace[${ + currentNamespace.namespace.path + }]`, + id.loc, + ) } } +export function resolveIdentifierDefinition( + id: Identifier, + currentFile: IParsedFile, + files: ParsedFileMap, + sourceDir: string, +): DefinitionType +export function resolveIdentifierDefinition( + id: Identifier, + currentFile: IResolvedFile, + files: ResolvedFileMap, + sourceDir: string, +): DefinitionType +export function resolveIdentifierDefinition( + id: Identifier, + currentNamespace: INamespace, + namespaces: INamespaceMap, + sourceDir: string, +): DefinitionType +export function resolveIdentifierDefinition( + id: Identifier, + currentFile: any, + files: any, + sourceDir: string, +): DefinitionType { + if (currentFile.type === 'ParsedFile') { + return resolveIdentifierFromParsedFile( + id, + currentFile, + files, + sourceDir, + ) + } else if (currentFile.type === 'ResolvedFile') { + return resolveIdentifierFromResolvedFile( + id, + currentFile, + files, + sourceDir, + ) + } else { + return resolveIdentifierFromNamespace(id, currentFile, files, sourceDir) + } +} + +// Given the name of an identifier and the state in which that file is being rendered return the name that +// should be used for the identifier in the given context. +export function resolveIdentifierName( + name: string, + state: IRenderState, +): IResolvedIdentifier { + const currentNamespace: INamespace = state.currentNamespace + const [pathName, base, ...tail] = name.split('.') + let baseName: string = pathName + + if (base !== undefined) { + baseName = [base, ...tail].join('.') + } + + if (currentNamespace.exports[pathName]) { + if (state.currentDefinitions[pathName]) { + return { + rawName: name, + name: pathName, + baseName, + pathName: undefined, + fullName: name, + } + } else { + return { + rawName: name, + name: pathName, + baseName, + pathName: '__NAMESPACE__', + fullName: `__NAMESPACE__.${name}`, + } + } + } + + const namespace = currentNamespace.includedNamespaces[pathName] + + if (namespace !== undefined) { + return { + rawName: name, + name: base, + baseName, + pathName, + fullName: name, + } + } + + if (base === undefined) { + return { + rawName: name, + name: pathName, + baseName, + pathName: undefined, + fullName: name, + } + } + + throw new Error(`Unable to resolve identifier[${name}]`) +} + /** - * Find the namespace for use by this file. + * It makes things easier to rewrite all const values to their literal values. + * For example you can use the identifier of a constant as the initializer of another constant + * or the default value of a field in a struct. * - * @param thrift + * const i32 VALUE = 32 + * cosnt list LIST = [ VALUE ] + * + * This can be safely rewritten to: + * + * const i32 VALUE = 32 + * const list LIST = [ 32 ] + * + * This is blunt, but it makes type-checking later very easy. */ -export function resolveNamespace( - outPath: string, - thrift: ThriftDocument, - options: IMakeOptions, -): INamespace { - const statements: Array = thrift.body.filter( - (next: ThriftStatement): next is NamespaceDefinition => { - return next.type === SyntaxType.NamespaceDefinition - }, - ) +export function resolveConstValue( + value: ConstValue, + fieldType: FunctionType, + currentFile: T, + files: IProcessedFileMap, + sourceDir: string, +): ConstValue { + switch (value.type) { + case SyntaxType.IntConstant: + if (fieldType.type === SyntaxType.BoolKeyword) { + if (value.value.value === '1' || value.value.value === '0') { + return createBooleanLiteral( + value.value.value === '1', + value.loc, + ) + } else { + throw new ValidationError( + `Can only assign booleans to the int values '1' or '0'`, + value.loc, + ) + } + } else { + return value + } - return getNamespace( - outPath, - statements.reduce( - (acc: INamespaceMap, next: NamespaceDefinition) => { - acc[next.scope.value] = { - scope: next.scope.value, - name: next.name.value, - path: createPathForNamespace(outPath, next.name.value), + case SyntaxType.Identifier: + const [head, ...tail] = value.value.split('.') + if (currentFile.exports[head]) { + const statement: ThriftStatement = currentFile.exports[head] + if (statement.type === SyntaxType.ConstDefinition) { + return resolveConstValue( + statement.initializer, + fieldType, + currentFile, + files, + sourceDir, + ) + } else { + return value } - return acc - }, - {} as INamespaceMap, - ), - options, - ) + } else { + const include: IIncludePath | undefined = + currentFile.includes[head] + if (include !== undefined) { + // The next file to look in for the definition of this constant + const nextFile: T = fileForInclude( + include, + files, + sourceDir, + ) + + return resolveConstValue( + stubIdentifier(tail.join('.')), + fieldType, + nextFile, + files, + sourceDir, + ) + } + } + throw new ValidationError( + `Unable to resolve value of identifier[${value.value}]`, + value.loc, + ) + + case SyntaxType.ConstMap: + return { + type: SyntaxType.ConstMap, + properties: value.properties.map( + (next: PropertyAssignment): PropertyAssignment => { + return { + type: SyntaxType.PropertyAssignment, + name: resolveConstValue( + next.name, + fieldType, + currentFile, + files, + sourceDir, + ), + initializer: resolveConstValue( + next.initializer, + fieldType, + currentFile, + files, + sourceDir, + ), + loc: next.loc, + } + }, + ), + loc: value.loc, + } + + case SyntaxType.ConstList: + return { + type: SyntaxType.ConstList, + elements: value.elements.map( + (next: ConstValue): ConstValue => { + return resolveConstValue( + next, + fieldType, + currentFile, + files, + sourceDir, + ) + }, + ), + loc: value.loc, + } + + default: + return value + } } diff --git a/src/main/types.ts b/src/main/types.ts index fad9b2e3..bc3b865e 100644 --- a/src/main/types.ts +++ b/src/main/types.ts @@ -6,33 +6,109 @@ import { ExceptionDefinition, ServiceDefinition, StructDefinition, - TextLocation, - ThriftDocument, ThriftStatement, TypedefDefinition, UnionDefinition, } from '@creditkarma/thrift-parser' +import { IThriftError } from './errors' + +export interface IThriftProject { + type: 'ThriftProject' + + // Root directory for the project + rootDir: string + + // Output directory (relative to root) for generated code + outDir: string + + // Source directory (relative to root) for thrift files + sourceDir: string + + // Namespace declared in this project + namespaces: INamespaceMap + + // Options for rendering this project + options: IMakeOptions +} + +export interface INamespaceFiles { + [name: string]: Array +} + +// Map of resolved identifier name to the namespace it represents +export interface INamespacePathMap { + [resolvedName: string]: INamespacePath +} + +export interface INamespacePath { + type: 'NamespacePath' + + // Scope is the language this namespace belongs to 'js', 'java'... + scope: string + + // The name of the namespace com.company.package + name: string + + // The name translated to its result path com/company/package + path: string +} + +// Namespace path to namespace +export interface INamespaceMap { + [path: string]: INamespace +} + +export interface INamespace { + type: 'Namespace' + + namespace: INamespacePath + + // Files declared as part of this namespace + files: ResolvedFileMap + + // Identifiers defined in this namespace + exports: IFileExports + + // Map of namespaces used by this file + includedNamespaces: INamespacePathMap + + // Data/services defined in this namespace + constants: Array + typedefs: Array + structs: Array + unions: Array + exceptions: Array + services: Array +} + +export interface IRenderState { + // Options for this render + options: IMakeOptions + + // The current namespace being processed + currentNamespace: INamespace + + // Current statements being processed + currentDefinitions: IFileExports + + // The current Thrift project + project: IThriftProject +} + export type CompileTarget = 'apache' | 'thrift-server' -/** - * The compiler options for our codegen. These can be provided to the generator - * directly through the JS API, or via the command line. - * - * EXAMPLE - * - * $ thrift-parser --rootDir . --sourceDir thrift --outDir codegen example.thrift - */ export interface IMakeOptions { + // Root to resolve outDir and sourceDir from rootDir: string - // resolved relative to the root directory + // Where to put generated TypeScript outDir: string - // resolved relative to the root directory + // Where to find source thrift sourceDir: string - // list of files to generate code from + // Files to generate from files: Array // What core libs are you compiling for? @@ -53,145 +129,76 @@ export interface IMakeOptions { strictUnionsComplexNames: boolean } -export interface IRenderState { - identifiers: IIdentifierMap - options: IMakeOptions +export interface IThriftFiles { + [filePath: string]: ISourceFile } -export interface IRenderer { - renderIncludes( - currentPath: string, - resolvedFile: INamespaceFile, - options: IMakeOptions, - ): Array - - renderConst( - statement: ConstDefinition, - state: IRenderState, - ): Array - - renderTypeDef( - statement: TypedefDefinition, - state: IRenderState, - ): Array - - renderEnum( - statement: EnumDefinition, - state: IRenderState, - ): Array - - renderStruct( - statement: StructDefinition, - state: IRenderState, - ): Array - - renderException( - statement: ExceptionDefinition, - state: IRenderState, - ): Array +export interface ISourceFile { + type: 'SourceFile' - renderUnion( - statement: UnionDefinition, - state: IRenderState, - ): Array + // Name of the source file + name: string - renderService( - statement: ServiceDefinition, - state: IRenderState, - ): Array -} + // Absolute path to the directory containing source file + path: string -/** - * - * INamespace { - * namespace: string - * path: string - * } - * - * - */ + // Full path to this file + fullPath: string -export interface IThriftFile { - name: string - path: string + // The raw source content of this file source: string } -export interface IParsedFile { - name: string - path: string - source: string - includes: Array - ast: ThriftDocument +// Map of file path to the parsed file +export interface IProcessedFileMap { + [filePath: string]: FileType } -// Map from import identifier to namespace path -export interface IIncludeMap { - [name: string]: string -} +export type ParsedFileMap = IProcessedFileMap +export type ResolvedFileMap = IProcessedFileMap -export interface IResolvedFile { - name: string - path: string - source: string - namespace: INamespace - includes: IResolvedIncludeMap - identifiers: IIdentifierMap - body: Array - errors: Array -} +export interface IProcessedFile { + // Source file that parses to this AST + sourceFile: ISourceFile -export interface INamespaceFile { - namespace: INamespace - includes: IResolvedIncludeMap - identifiers: IIdentifierMap - body: Array -} + // Namespace for this file + namespace: INamespacePath -export interface IRenderedFile { - outPath: string - namespace: INamespace - // includes: IRenderedFileMap - identifiers: IIdentifierMap - statements: Array -} + // Map of include names to include path + includes: IFileIncludes -export interface IResolvedFileMap { - [name: string]: IResolvedFile -} + // Identifiers exported by this file + exports: IFileExports -export interface IRenderedFileMap { - [name: string]: IRenderedFile -} + // AST for source file content + body: Array -export interface INamespacedResolvedFiles { - [name: string]: Array + // Array of errors encountered processing this file + errors: Array } -export interface INamespace { - scope: string - name: string - path: string +export interface IParsedFile extends IProcessedFile { + type: 'ParsedFile' } -export interface INamespaceMap { - [name: string]: INamespace -} +export interface IResolvedFile extends IProcessedFile { + type: 'ResolvedFile' -export interface IResolvedInclude { - file: IResolvedFile + // Map of namespaces used by this file + includedNamespaces: INamespacePathMap - // Identifiers used from this include - identifiers: Array + // Map of namespace id to include path + namespaceToInclude: INamespaceToIncludeMap } -export interface IResolvedIncludeMap { - [name: string]: IResolvedInclude +// Map of resolved namespace identifier to include +export interface INamespaceToIncludeMap { + [name: string]: string } -export interface IIncludeData { - path: string - base: string +// Map of include name to include path +export interface IFileIncludes { + [name: string]: IIncludePath } export type DefinitionType = @@ -203,37 +210,92 @@ export type DefinitionType = | TypedefDefinition | ServiceDefinition -export interface IResolvedIdentifier { - name: string - pathName: string - resolvedName: string - definition: DefinitionType +// A map of identifier name to the Thrift definition of that identifier +export interface IFileExports { + [name: string]: DefinitionType } -export interface IIdentifierMap { - [name: string]: IResolvedIdentifier +export interface IIncludePath { + type: 'IncludePath' + + // Include path as it literally appears in the source code + path: string + + // Path to the file importing this include + importedFrom: string } -export const enum ErrorType { - ValidationError = 'ValidationError', - ResolutionError = 'ResolutionError', - GenerationError = 'GenerationError', +// The Thrift file path to the resolved namespace for that file's +// generated TypeScript. +export interface IFileToNamespaceMap { + [filePath: string]: INamespacePath } -export interface IThriftError { - type: ErrorType - message: string - loc: TextLocation +// Map of an include's name in a specific file to the namespace that +// include resolves to. +export interface IIncludeToNamespaceMap { + [includeName: string]: INamespacePath } -export interface IIncludeCache { - [path: string]: IParsedFile +// Interface for our render object +export interface IRenderer { + renderIndex(state: IRenderState): Array + + renderImports( + files: Array, + state: IRenderState, + ): Array + + renderConst( + statement: ConstDefinition, + state: IRenderState, + ): Array + + renderTypeDef( + statement: TypedefDefinition, + state: IRenderState, + ): Array + + renderEnum( + statement: EnumDefinition, + state: IRenderState, + ): Array + + renderStruct( + statement: StructDefinition, + state: IRenderState, + ): Array + + renderException( + statement: ExceptionDefinition, + state: IRenderState, + ): Array + + renderUnion( + statement: UnionDefinition, + state: IRenderState, + ): Array + + renderService( + statement: ServiceDefinition, + state: IRenderState, + ): Array } -export interface IResolvedCache { - [path: string]: IResolvedFile +export interface IResolvedIdentifier { + rawName: string + name: string + baseName: string + pathName?: string + fullName: string } -export interface IRenderedCache { - [path: string]: IRenderedFile +export interface IGeneratedFile { + type: 'GeneratedFile' + + name: string + + path: string + + body: Array } diff --git a/src/main/utils.ts b/src/main/utils.ts index ee2f0616..f974b1c3 100644 --- a/src/main/utils.ts +++ b/src/main/utils.ts @@ -1,38 +1,36 @@ -import * as fs from 'fs' -import * as glob from 'glob' -import * as path from 'path' - import { - IncludeDefinition, - parse, + ConstValue, + FieldDefinition, + FunctionDefinition, + FunctionType, + NamespaceDefinition, + PropertyAssignment, SyntaxType, - ThriftDocument, - ThriftErrors, + TextLocation, ThriftStatement, } from '@creditkarma/thrift-parser' +import * as fs from 'fs' +import * as glob from 'glob' +import * as path from 'path' + import { - IIncludeCache, - IIncludeData, + IFileIncludes, + IGeneratedFile, + IIncludePath, IMakeOptions, - INamespaceFile, - IParsedFile, - IRenderedFile, + INamespaceMap, + INamespacePath, + INamespacePathMap, + IProcessedFile, + IProcessedFileMap, IResolvedFile, - IResolvedIncludeMap, - IThriftFile, + ISourceFile, } from './types' import { print } from './printer' - import { mkdir } from './sys' -interface IFileCache { - [path: string]: IThriftFile -} - -const fileCache: IFileCache = {} - export function deepCopy(obj: T): T { const newObj: any = Array.isArray(obj) ? [] : {} for (const key in obj) { @@ -100,218 +98,321 @@ export function collectSourceFiles( } } -export function parseThriftString(source: string): ThriftDocument { - const thrift: ThriftDocument | ThriftErrors = parse(source) - switch (thrift.type) { - case SyntaxType.ThriftDocument: - return thrift +export function nameForInclude(fullInclude: string): string { + const body = fullInclude.replace('.thrift', '') + const parts = body.split('/') + return parts[parts.length - 1] +} - default: - throw new Error('Unable to parse source') - } +export function includesForFile( + body: Array, + sourceFile: ISourceFile, +): IFileIncludes { + return body.reduce((acc: IFileIncludes, next: ThriftStatement) => { + if (next.type === SyntaxType.IncludeDefinition) { + const includeName = nameForInclude(next.path.value) + + acc[includeName] = { + type: 'IncludePath', + path: next.path.value, + importedFrom: sourceFile.path, + } + } + + return acc + }, {}) } -export function dedupResolvedFiles( - files: Array, -): Array { - return Array.from( - files - .reduce((acc: Map, next: IResolvedFile) => { - acc.set(`${next.path}/${next.name}`, next) - return acc - }, new Map()) - .values(), - ) +export function namespaceForInclude( + include: IIncludePath, + files: IProcessedFileMap, + sourceDir: string, + options: IMakeOptions, +): INamespacePath { + const file: T = fileForInclude(include, files, sourceDir) + const namespace: INamespacePath = namespaceForFile(file.body, options) + return namespace } -function collectNamespaces( - files: Array, - cache: Map = new Map(), -): Map { - if (files.length > 0) { - const [head, ...tail] = files - const namespace = cache.get(head.namespace.path) - if (namespace !== undefined) { - namespace.body = namespace.body.concat(head.body) - for (const item in head.identifiers) { - if (head.identifiers.hasOwnProperty(item)) { - namespace.identifiers[item] = head.identifiers[item] - } - } - for (const item in head.includes) { - if (head.includes.hasOwnProperty(item)) { - namespace.includes[item] = head.includes[item] - } - } - } else { - cache.set(head.namespace.path, { - namespace: head.namespace, - includes: head.includes, - identifiers: head.identifiers, - body: head.body, - }) - } +export function fileForInclude( + include: IIncludePath, + files: IProcessedFileMap, + sourceDir: string, +): T { + // Relative to the file requesting the include + const optionOne: string = path.resolve(include.importedFrom, include.path) + + // Relative to the source directory + const optionTwo: string = path.resolve(sourceDir, include.path) - return collectNamespaces(tail, cache) + if (files[optionOne]) { + return files[optionOne] + } else if (files[optionTwo]) { + return files[optionTwo] } else { - return cache + throw new Error(`No file for include: ${include.path}`) } } -export function organizeByNamespace( - files: Array, -): Array { - return Array.from(collectNamespaces(files).values()) +function createPathForNamespace(ns: string): string { + return ns.split('.').join('/') } -/** - * Once identifiers have been resolved it's easier to deal with files in a flattened state - */ -export function flattenResolvedFile(file: IResolvedFile): Array { - let result: Array = [file] - for (const key in file.includes) { - if (file.includes.hasOwnProperty(key)) { - const include = file.includes[key].file - result = result.concat(flattenResolvedFile(include)) - } +export function emptyNamespace(): INamespacePath { + return { + type: 'NamespacePath', + scope: '', + name: '', + path: createPathForNamespace(''), } - return result } -export function saveFiles( - rootDir: string, - outDir: string, - files: Array, -): void { - files.forEach((next: IRenderedFile) => { - mkdir(path.dirname(next.outPath)) - try { - fs.writeFileSync(next.outPath, print(next.statements, true)) - } catch (err) { - throw new Error( - `Unable to save generated files to: ${next.outPath}`, - ) - } - }) +export function emptyLocation(): TextLocation { + return { + start: { line: 0, column: 0, index: 0 }, + end: { line: 0, column: 0, index: 0 }, + } } -export function readThriftFile( - file: string, - searchPaths: Array, -): IThriftFile { - for (const sourcePath of searchPaths) { - const filePath: string = path.resolve(sourcePath, file) - if (fileCache[filePath] !== undefined) { - return fileCache[filePath] - } +function collectNamespaces(body: Array): INamespacePathMap { + return body + .filter( + (next: ThriftStatement): next is NamespaceDefinition => { + return next.type === SyntaxType.NamespaceDefinition + }, + ) + .reduce((acc: INamespacePathMap, next: NamespaceDefinition) => { + acc[next.scope.value] = { + type: 'NamespacePath', + scope: next.scope.value, + name: next.name.value, + path: createPathForNamespace(next.name.value), + } + return acc + }, {}) +} + +export function namespaceForFile( + body: Array, + options: IMakeOptions, +): INamespacePath { + const namespaceMap = collectNamespaces(body) + if (namespaceMap.js) { + return namespaceMap.js + } else if ( + options.fallbackNamespace !== 'none' && + namespaceMap[options.fallbackNamespace] + ) { + return namespaceMap[options.fallbackNamespace] + } else { + return emptyNamespace() + } +} - if (fs.existsSync(filePath)) { - fileCache[filePath] = { - name: path.basename(filePath, '.thrift'), - path: path.dirname(filePath), - source: fs.readFileSync(filePath, 'utf-8'), +export function organizeByNamespace( + files: Array, +): INamespaceMap { + return files.reduce((acc: INamespaceMap, next: IResolvedFile) => { + const namespacePath: string = next.namespace.path + let namespace = acc[namespacePath] + if (namespace === undefined) { + namespace = { + type: 'Namespace', + namespace: next.namespace, + includedNamespaces: {}, + files: {}, + exports: {}, + constants: [], + typedefs: [], + structs: [], + unions: [], + exceptions: [], + services: [], } - return fileCache[filePath] + acc[namespacePath] = namespace } - } - throw new Error(`Unable to find file ${file}`) -} + namespace.files[next.sourceFile.fullPath] = next + namespace.includedNamespaces = { + ...namespace.includedNamespaces, + ...next.includedNamespaces, + } -function collectIncludes(thrift: ThriftDocument): Array { - const statements: Array = thrift.body.filter( - (next: ThriftStatement): next is IncludeDefinition => { - return next.type === SyntaxType.IncludeDefinition - }, - ) - - return statements.map( - (next: IncludeDefinition): IIncludeData => ({ - path: next.path.value, - base: path.basename(next.path.value).replace('.thrift', ''), - }), - ) + next.body.forEach((statement: ThriftStatement) => { + switch (statement.type) { + case SyntaxType.ConstDefinition: + case SyntaxType.EnumDefinition: + namespace.constants.push(statement) + namespace.exports[statement.name.value] = statement + break + + case SyntaxType.TypedefDefinition: + namespace.typedefs.push(statement) + namespace.exports[statement.name.value] = statement + break + + case SyntaxType.StructDefinition: + namespace.structs.push(statement) + namespace.exports[statement.name.value] = statement + break + + case SyntaxType.UnionDefinition: + namespace.unions.push(statement) + namespace.exports[statement.name.value] = statement + break + + case SyntaxType.ExceptionDefinition: + namespace.exceptions.push(statement) + namespace.exports[statement.name.value] = statement + break + + case SyntaxType.ServiceDefinition: + namespace.services.push(statement) + namespace.exports[statement.name.value] = statement + break + } + }) + + return acc + }, {}) } -function parseInclude( - currentPath: string, - sourceDir: string, - include: IIncludeData, - cache: IIncludeCache = {}, -): IParsedFile { - if (!cache[include.path]) { - cache[include.path] = parseFile( - sourceDir, - readThriftFile(include.path, [currentPath, sourceDir]), - ) +export function collectInvalidFiles( + resolvedFiles: Array, + errors: Array = [], +): Array { + for (const file of resolvedFiles) { + if (file.errors.length > 0) { + errors.push(file) + } } - return cache[include.path] + return errors } -/** - * interface IParsedFile { - * name: string - * path: string - * includes: Array - * ast: ThriftDocument - * } - * - * @param sourceDir - * @param file - */ -export function parseFile( - sourceDir: string, - file: IThriftFile, - cache: IIncludeCache = {}, -): IParsedFile { - const ast: ThriftDocument = parseThriftString(file.source) - const includes: Array = collectIncludes(ast).map( - (next: IIncludeData): IParsedFile => { - return parseInclude(file.path, sourceDir, next, cache) - }, - ) +export function saveFiles(files: Array, outDir: string): void { + files.forEach((next: IGeneratedFile) => { + const outPath: string = path.resolve( + outDir, + next.path, + `${next.name}.ts`, + ) - return { - name: file.name, - path: file.path, - source: file.source, - includes, - ast, - } + mkdir(path.dirname(outPath)) + + try { + fs.writeFileSync(outPath, print(next.body, true)) + } catch (err) { + throw new Error(`Unable to save generated files to: ${outPath}`) + } + }) } -export function parseSource(source: string): IParsedFile { - return { - name: '', - path: '', - source, - includes: [], - ast: parseThriftString(source), +function identifiersForFieldType( + fieldType: FunctionType, + results: Set, +): void { + switch (fieldType.type) { + case SyntaxType.Identifier: + results.add(fieldType.value) + break + + case SyntaxType.MapType: + identifiersForFieldType(fieldType.keyType, results) + identifiersForFieldType(fieldType.valueType, results) + break + + case SyntaxType.SetType: + case SyntaxType.ListType: + identifiersForFieldType(fieldType.valueType, results) + break } } -function includeListForMap( - includes: IResolvedIncludeMap, -): Array { - const includeList: Array = [] - for (const name of Object.keys(includes)) { - includeList.push(includes[name].file) +function identifiersForConstValue( + constValue: ConstValue | null, + results: Set, +): void { + if (constValue !== null) { + switch (constValue.type) { + case SyntaxType.Identifier: + results.add(constValue.value) + break + + case SyntaxType.ConstList: + constValue.elements.forEach((next: ConstValue) => { + identifiersForConstValue(next, results) + }) + break + + case SyntaxType.ConstMap: + constValue.properties.forEach((next: PropertyAssignment) => { + identifiersForConstValue(next.name, results) + identifiersForConstValue(next.initializer, results) + }) + } } - return includeList } -export function collectInvalidFiles( - resolvedFiles: Array, - errors: Array = [], -): Array { - for (const file of resolvedFiles) { - if (file.errors.length > 0) { - errors.push(file) - collectInvalidFiles(includeListForMap(file.includes), errors) +export function identifiersForStatements( + statements: Array, +): Array { + const results: Set = new Set() + + statements.forEach((next: ThriftStatement) => { + switch (next.type) { + case SyntaxType.IncludeDefinition: + case SyntaxType.CppIncludeDefinition: + case SyntaxType.NamespaceDefinition: + case SyntaxType.EnumDefinition: + // Ignore + break + + case SyntaxType.ConstDefinition: + identifiersForFieldType(next.fieldType, results) + identifiersForConstValue(next.initializer, results) + break + + case SyntaxType.TypedefDefinition: + identifiersForFieldType(next.definitionType, results) + break + + case SyntaxType.StructDefinition: + case SyntaxType.UnionDefinition: + case SyntaxType.ExceptionDefinition: + next.fields.forEach((field: FieldDefinition) => { + identifiersForFieldType(field.fieldType, results) + identifiersForConstValue(field.defaultValue, results) + }) + break + + case SyntaxType.ServiceDefinition: + if (next.extends) { + results.add(next.extends.value) + } + + next.functions.forEach((func: FunctionDefinition) => { + func.fields.forEach((field: FieldDefinition) => { + identifiersForFieldType(field.fieldType, results) + identifiersForConstValue(field.defaultValue, results) + }) + + func.throws.forEach((field: FieldDefinition) => { + identifiersForFieldType(field.fieldType, results) + identifiersForConstValue(field.defaultValue, results) + }) + + identifiersForFieldType(func.returnType, results) + }) + + break + + default: + const _exhaustiveCheck: never = next + throw new Error(`Non-exhaustive match for ${_exhaustiveCheck}`) } - } + }) - return errors + return Array.from(results) } diff --git a/src/main/validator/index.ts b/src/main/validator/index.ts index ae20628c..e04fd535 100644 --- a/src/main/validator/index.ts +++ b/src/main/validator/index.ts @@ -1,12 +1,7 @@ import { ConstValue, - createBooleanLiteral, EnumDefinition, - EnumMember, FieldDefinition, - FieldID, - FieldType, - FunctionDefinition, FunctionType, Identifier, PropertyAssignment, @@ -15,48 +10,14 @@ import { ThriftStatement, } from '@creditkarma/thrift-parser' +import { createValidationError, IThriftError, ValidationError } from '../errors' import { - ErrorType, - IResolvedFile, - IResolvedIdentifier, - IThriftError, -} from '../types' - + resolveConstValue, + resolveIdentifierDefinition, +} from '../resolver/utils' +import { DefinitionType, IResolvedFile, ResolvedFileMap } from '../types' import { constToTypeString, fieldTypeToString } from './utils' -/** - * Internal class that we will transform into an IThriftError object before passing to the reporter. - * We create this error class so that we can throw the error to unwind the call stack before - * handling the error gracefully. - */ -class ValidationError extends Error { - public message: string - public loc: TextLocation - constructor(msg: string, loc: TextLocation) { - super(msg) - this.message = msg - this.loc = loc - } -} - -function createValidationError( - message: string, - loc: TextLocation, -): IThriftError { - return { - type: ErrorType.ValidationError, - message, - loc, - } -} - -function emptyLocation(): TextLocation { - return { - start: { line: 0, column: 0, index: 0 }, - end: { line: 0, column: 0, index: 0 }, - } -} - function typeMismatch( expected: FunctionType, actual: ConstValue, @@ -71,208 +32,61 @@ function typeMismatch( } /** - * VALIDATOR - * - * The job of the validator is to perform checks against the AST that the parser may have allowed pass. Somethings, - * like type checking, are not part of the language spec, but are still things we can validate through static - * analysis before allowing the AST to move on to the code generation phase. - * - * During this process we are going to be doing three main things. - * - * 1. Validate types during field assignemnts. There is no need for us to move on to code generation if the Thrift - * file is doing things like this: - * - * ``` - * const i32 test = "not valid" - * - * // or... - * - * struct TestStruct { - * 1: required string field1 = [ 'one', 'two', 'three' ] - * } - * ``` - * - * 2. Validate field IDs. Check for duplicate IDs. Each structure containing field IDs should have unique IDs. - * We also generate field IDs for any fields with null IDs. - * - * This should fail: - * - * ``` - * struct TestStruct { - * 1: required string field1 - * 1: i32 field2 - * } - * ``` - * - * The AST for this should be rewritten to include field IDs - * - * ``` - * struct TestStruct { - * required string field1 - * i32 field2 - * } - * ``` - * - * 3. Validate that all identifiers are defined. - * - * If "location" is not being included this should fail: - * - * ``` - * struct TestStruct { - * 1: required location.Location loc - * } - * ``` + * The main purpose of the validator is to type-check our Thrift file to make sure it is valid. * * @param resolvedFile + * @param files + * @param sourceDir */ -export function validateFile(resolvedFile: IResolvedFile): IResolvedFile { - const bodySize: number = resolvedFile.body.length +export function validateFile( + resolvedFile: IResolvedFile, + files: ResolvedFileMap, + sourceDir: string, +): IResolvedFile { + const body = resolvedFile.body + const bodySize: number = body.length let currentIndex: number = 0 const errors: Array = [] - function validateStatements(): Array { - const newBody: Array = [] + function validateStatements(): void { while (!isAtEnd()) { try { - const statement = validateStatement( - resolvedFile.body[currentIndex], - ) - newBody.push(statement) + validateStatement(body[currentIndex]) } catch (e) { errors.push(createValidationError(e.message, e.loc)) } currentIndex += 1 } - - return newBody } function isAtEnd(): boolean { return currentIndex >= bodySize } - function resolveValue(value: ConstValue): ConstValue { - if ( - value.type === SyntaxType.Identifier && - resolvedFile.identifiers[value.value] - ) { - const resolvedIdentifier = resolvedFile.identifiers[value.value] - if ( - resolvedIdentifier.definition.type === - SyntaxType.ConstDefinition - ) { - if ( - resolvedIdentifier.definition.initializer.type === - SyntaxType.Identifier - ) { - return resolveValue( - resolvedIdentifier.definition.initializer, - ) - } else { - return resolvedIdentifier.definition.initializer - } - } else { - return value - } - } else { - return value - } - } - - function requireIdentifier( - loc: TextLocation, - ...names: Array - ): IResolvedIdentifier { - for (const name of names) { - if (resolvedFile.identifiers[name]) { - return resolvedFile.identifiers[name] - } - } - - throw new ValidationError( - `Unable to resolve type of Identifier ${names[0]}`, - loc, - ) - } - - /** - * The driver behind validating the AST is to loop through the statements of the body and find the pieces - * that need validation. - * - * These are: - * 1. fieldTypes - * 2. returnTypes - * 3. defaultValues - * 4. initializers - */ - function validateStatement(statement: ThriftStatement): ThriftStatement { + function validateStatement(statement: ThriftStatement): void { switch (statement.type) { case SyntaxType.NamespaceDefinition: case SyntaxType.IncludeDefinition: case SyntaxType.CppIncludeDefinition: case SyntaxType.EnumDefinition: case SyntaxType.TypedefDefinition: - return statement + break case SyntaxType.ConstDefinition: - return { - type: SyntaxType.ConstDefinition, - name: statement.name, - fieldType: statement.fieldType, - initializer: validateValue( - statement.fieldType, - statement.initializer, - ), - comments: statement.comments, - annotations: statement.annotations, - loc: statement.loc, - } + validateValue(statement.fieldType, statement.initializer) + break case SyntaxType.StructDefinition: - return { - type: SyntaxType.StructDefinition, - name: statement.name, - fields: validateFields(statement.fields), - comments: statement.comments, - annotations: statement.annotations, - loc: statement.loc, - } - case SyntaxType.UnionDefinition: - return { - type: SyntaxType.UnionDefinition, - name: statement.name, - fields: validateFields(statement.fields), - comments: statement.comments, - annotations: statement.annotations, - loc: statement.loc, - } - case SyntaxType.ExceptionDefinition: - return { - type: SyntaxType.ExceptionDefinition, - name: statement.name, - fields: validateFields(statement.fields), - comments: statement.comments, - annotations: statement.annotations, - loc: statement.loc, - } + validateFields(statement.fields) + break case SyntaxType.ServiceDefinition: - return { - type: SyntaxType.ServiceDefinition, - name: statement.name, - functions: validateFunctions(statement.functions), - extends: - statement.extends !== null - ? validateExtends(statement.extends) - : null, - comments: statement.comments, - annotations: statement.annotations, - loc: statement.loc, - } + validateExtends(statement.extends) + break default: const msg: never = statement @@ -280,158 +94,93 @@ export function validateFile(resolvedFile: IResolvedFile): IResolvedFile { } } - function validateExtends(id: Identifier): Identifier { - const resolvedID: IResolvedIdentifier = requireIdentifier( - id.loc, - id.value, - ) - if (resolvedID.definition.type === SyntaxType.ServiceDefinition) { - return id - } else { - throw new ValidationError( - `Service type expected but found type ${ - resolvedID.definition.type - }`, - id.loc, + function validateExtends(id: Identifier | null): void { + if (id !== null) { + const resolvedIdentifier: DefinitionType = resolveIdentifierDefinition( + id, + resolvedFile, + files, + sourceDir, ) + + if (resolvedIdentifier.type !== SyntaxType.ServiceDefinition) { + throw new ValidationError( + `Service type expected but found type ${ + resolvedIdentifier.type + }`, + id.loc, + ) + } } } - function valuesForEnum(enumDef: EnumDefinition): Array { - let previousValue: number = -1 - const values: Array = enumDef.members.reduce( - ( - acc: Array, - next: EnumMember, - ): Array => { - if (next.initializer !== null) { - return [...acc, parseInt(next.initializer.value.value, 10)] - } else { - return [...acc, null] - } - }, - [], - ) - - return values.map( - (next: number | null): number => { - if (next !== null) { - previousValue = next - return next - } else { - return ++previousValue + function validateFields(fields: Array): void { + fields.forEach( + (field: FieldDefinition): void => { + if (field.defaultValue !== null) { + validateValue(field.fieldType, field.defaultValue) } }, ) } - function enumMembers(enumDef: EnumDefinition): Array { - return enumDef.members.map( - (next: EnumMember): string => { - return next.name.value - }, - ) - } - function validateEnum( - enumName: string, enumDef: EnumDefinition, constValue: ConstValue, - ): ConstValue { - switch (constValue.type) { - /** - * If we're dealing with object access (Status.SUCCESS), we just want the base of the identifier (Status) - */ - case SyntaxType.Identifier: - const parts = constValue.value.split('.') - const baseName = - parts.length > 2 ? `${parts[0]}.${parts[1]}` : parts[0] - const accessName = parts[parts.length - 1] - const resolvedConst: IResolvedIdentifier = requireIdentifier( - constValue.loc, - baseName, - constValue.value, - ) - if (resolvedConst.resolvedName === enumName) { - if (enumMembers(enumDef).indexOf(accessName) > -1) { - return constValue - } else { - throw new ValidationError( - `The value ${accessName} is not a member of enum ${ - enumDef.name.value - }`, - constValue.loc, - ) - } - } else { - throw new ValidationError( - `The value ${ - resolvedConst.name - } is not assignable to type ${enumDef.name.value}`, - constValue.loc, - ) - } - - /** - * Thrift does allow us to assign an i32 to a field whose type is that of an enum. However, we need to - * validate that the assigned value is in the range of the enum. - */ - case SyntaxType.IntConstant: - const acceptedValues: Array = valuesForEnum(enumDef) - const intValue: number = parseInt(constValue.value.value, 10) - if (acceptedValues.indexOf(intValue) > -1) { - return constValue - } else { - throw new ValidationError( - `The value ${ - constValue.value.value - } is not assignable to type ${enumDef.name.value}`, - constValue.loc, - ) - } - - default: - throw new ValidationError( - `Value of type ${constToTypeString( - constValue, - )} cannot be assigned to type ${enumDef.name.value}`, - constValue.loc, - ) + ): void { + if ( + constValue.type !== SyntaxType.Identifier && + constValue.type !== SyntaxType.IntConstant + ) { + throw new ValidationError( + `Value of type ${constToTypeString( + constValue, + )} cannot be assigned to type ${enumDef.name.value}`, + constValue.loc, + ) } } function validateTypeForIdentifier( - id: IResolvedIdentifier, - value: ConstValue, - ): ConstValue { - switch (id.definition.type) { + id: Identifier, + resolvedValue: ConstValue, + rawValue: ConstValue, + ): void { + const definition: DefinitionType = resolveIdentifierDefinition( + id, + resolvedFile, + files, + sourceDir, + ) + switch (definition.type) { case SyntaxType.ServiceDefinition: throw new ValidationError( - `Service ${ - id.definition.name.value - } is being used as a value`, - value.loc, + `Service ${definition.name.value} is being used as a value`, + rawValue.loc, ) case SyntaxType.EnumDefinition: - return validateEnum(id.resolvedName, id.definition, value) + validateEnum(definition, resolvedValue) + break case SyntaxType.TypedefDefinition: - return validateValue(id.definition.definitionType, value) + validateValue(definition.definitionType, resolvedValue) + break case SyntaxType.ConstDefinition: - return validateValue(id.definition.fieldType, value) + validateValue(definition.fieldType, resolvedValue) + break case SyntaxType.StructDefinition: case SyntaxType.UnionDefinition: case SyntaxType.ExceptionDefinition: throw new ValidationError( - `Cannot assign value to type ${id.definition.name.value}`, - value.loc, + `Cannot assign value to type ${definition.name.value}`, + rawValue.loc, ) default: - const msg: never = id.definition + const msg: never = definition throw new Error(`Non-exhaustive match for ${msg}`) } } @@ -439,169 +188,109 @@ export function validateFile(resolvedFile: IResolvedFile): IResolvedFile { function validateValue( expectedType: FunctionType, value: ConstValue, - ): ConstValue { - const resolvedValue: ConstValue = resolveValue(value) + rawValue: ConstValue = value, + ): void { + const resolvedValue: ConstValue = resolveConstValue( + value, + expectedType, + resolvedFile, + files, + sourceDir, + ) + switch (expectedType.type) { case SyntaxType.VoidKeyword: throw new ValidationError( `Cannot assign value to type void`, - resolvedValue.loc, + rawValue.loc, ) case SyntaxType.Identifier: - return validateTypeForIdentifier( - requireIdentifier(expectedType.loc, expectedType.value), - resolvedValue, - ) + validateTypeForIdentifier(expectedType, resolvedValue, rawValue) + break case SyntaxType.StringKeyword: - if (resolvedValue.type === SyntaxType.StringLiteral) { - return value - } else { - throw typeMismatch( - expectedType, - resolvedValue, - resolvedValue.loc, - ) + if (resolvedValue.type !== SyntaxType.StringLiteral) { + throw typeMismatch(expectedType, rawValue, rawValue.loc) } + break case SyntaxType.BoolKeyword: - if (resolvedValue.type === SyntaxType.BooleanLiteral) { - return resolvedValue - - // Handle the case where the literal values 1 or 0 can be used to represent booleans - } else if ( - resolvedValue.type === SyntaxType.IntConstant && - (resolvedValue.value.value === '0' || - resolvedValue.value.value === '1') - ) { - return createBooleanLiteral( - resolvedValue.value.value === '1', - resolvedValue.loc, - ) - } else { - throw typeMismatch( - expectedType, - resolvedValue, - resolvedValue.loc, - ) + if (resolvedValue.type !== SyntaxType.BooleanLiteral) { + throw typeMismatch(expectedType, rawValue, rawValue.loc) } + break case SyntaxType.DoubleKeyword: if ( - resolvedValue.type === SyntaxType.DoubleConstant || - resolvedValue.type === SyntaxType.IntConstant + resolvedValue.type !== SyntaxType.DoubleConstant && + resolvedValue.type !== SyntaxType.IntConstant ) { - return resolvedValue - } else { - throw typeMismatch(expectedType, value, value.loc) + throw typeMismatch(expectedType, rawValue, rawValue.loc) } + break case SyntaxType.BinaryKeyword: - if (resolvedValue.type === SyntaxType.StringLiteral) { - return value - } else { - throw typeMismatch( - expectedType, - resolvedValue, - resolvedValue.loc, - ) + if (resolvedValue.type !== SyntaxType.StringLiteral) { + throw typeMismatch(expectedType, rawValue, rawValue.loc) } + break case SyntaxType.ByteKeyword: case SyntaxType.I8Keyword: case SyntaxType.I16Keyword: case SyntaxType.I32Keyword: - if (resolvedValue.type === SyntaxType.IntConstant) { - return resolvedValue - } else { - throw typeMismatch( - expectedType, - resolvedValue, - resolvedValue.loc, - ) + if (resolvedValue.type !== SyntaxType.IntConstant) { + throw typeMismatch(expectedType, rawValue, rawValue.loc) } + break case SyntaxType.I64Keyword: - if (resolvedValue.type === SyntaxType.IntConstant) { - return resolvedValue - } else { - throw typeMismatch( - expectedType, - resolvedValue, - resolvedValue.loc, - ) + if (resolvedValue.type !== SyntaxType.IntConstant) { + throw typeMismatch(expectedType, rawValue, rawValue.loc) } + break case SyntaxType.SetType: if (resolvedValue.type === SyntaxType.ConstList) { - return { - type: SyntaxType.ConstList, - elements: resolvedValue.elements.map( - (next: ConstValue): ConstValue => { - return validateValue( - expectedType.valueType, - next, - ) - }, - ), - loc: resolvedValue.loc, - } - } else { - throw typeMismatch( - expectedType, - resolvedValue, - resolvedValue.loc, + resolvedValue.elements.forEach( + (next: ConstValue): void => { + validateValue(expectedType.valueType, next) + }, ) + } else { + throw typeMismatch(expectedType, rawValue, rawValue.loc) } + break case SyntaxType.ListType: if (resolvedValue.type === SyntaxType.ConstList) { - return { - type: SyntaxType.ConstList, - elements: resolvedValue.elements.map( - (next: ConstValue): ConstValue => { - return validateValue( - expectedType.valueType, - next, - ) - }, - ), - loc: resolvedValue.loc, - } - } else { - throw typeMismatch( - expectedType, - resolvedValue, - resolvedValue.loc, + resolvedValue.elements.forEach( + (next: ConstValue): void => { + validateValue(expectedType.valueType, next) + }, ) + } else { + throw typeMismatch(expectedType, rawValue, rawValue.loc) } + break case SyntaxType.MapType: if (resolvedValue.type === SyntaxType.ConstMap) { - return { - type: SyntaxType.ConstMap, - properties: resolvedValue.properties.map( - (next: PropertyAssignment): PropertyAssignment => { - return { - type: SyntaxType.PropertyAssignment, - name: validateValue( - expectedType.keyType, - next.name, - ), - initializer: validateValue( - expectedType.valueType, - next.initializer, - ), - loc: next.loc, - } - }, - ), - loc: value.loc, - } + resolvedValue.properties.forEach( + (next: PropertyAssignment): void => { + validateValue(expectedType.keyType, next.name) + + validateValue( + expectedType.valueType, + next.initializer, + ) + }, + ) } else { - throw typeMismatch(expectedType, value, value.loc) + throw typeMismatch(expectedType, rawValue, rawValue.loc) } + break default: const msg: never = expectedType @@ -609,165 +298,17 @@ export function validateFile(resolvedFile: IResolvedFile): IResolvedFile { } } - function validateFunctionType(functionType: FunctionType): FunctionType { - switch (functionType.type) { - case SyntaxType.VoidKeyword: - return functionType - - default: - return validateFieldType(functionType) - } - } - - function validateFieldType(fieldType: FieldType): FieldType { - switch (fieldType.type) { - case SyntaxType.Identifier: - if (requireIdentifier(fieldType.loc, fieldType.value) != null) { - return fieldType - } else { - throw new ValidationError( - `Unable to resolve type of identifier ${ - fieldType.value - }`, - fieldType.loc, - ) - } - - case SyntaxType.MapType: - return { - type: SyntaxType.MapType, - keyType: validateFieldType(fieldType.keyType), - valueType: validateFieldType(fieldType.valueType), - loc: fieldType.loc, - } - - case SyntaxType.ListType: - return { - type: SyntaxType.ListType, - valueType: validateFieldType(fieldType.valueType), - loc: fieldType.loc, - } - - case SyntaxType.SetType: - return { - type: SyntaxType.SetType, - valueType: validateFieldType(fieldType.valueType), - loc: fieldType.loc, - } - - default: - return fieldType - } - } - - function validateFields( - fields: Array, - ): Array { - let generatedFieldID: number = 0 - const usedFieldIDs: Array = [] - - function validateFieldID(fieldID: FieldID | null): FieldID { - if (fieldID === null) { - return { - type: SyntaxType.FieldID, - value: --generatedFieldID, - loc: emptyLocation(), - } - } else if (fieldID.value < 0) { - throw new ValidationError( - `Field IDs should be positive integers, found ${ - fieldID.value - }`, - fieldID.loc, - ) - } else if (usedFieldIDs.indexOf(fieldID.value) > -1) { - throw new ValidationError( - `Found duplicate usage of fieldID: ${fieldID.value}`, - fieldID.loc, - ) - } else { - usedFieldIDs.push(fieldID.value) - return fieldID - } - } - - return fields.map( - (field: FieldDefinition): FieldDefinition => { - return { - type: SyntaxType.FieldDefinition, - name: field.name, - fieldID: validateFieldID(field.fieldID), - fieldType: validateFunctionType(field.fieldType), - requiredness: field.requiredness, - defaultValue: - field.defaultValue !== null - ? validateValue(field.fieldType, field.defaultValue) - : null, - comments: field.comments, - annotations: field.annotations, - loc: field.loc, - } - }, - ) - } - - function validateFunctions( - funcs: Array, - ): Array { - return funcs.map( - (func: FunctionDefinition): FunctionDefinition => { - if ( - func.oneway && - func.returnType.type !== SyntaxType.VoidKeyword - ) { - throw new ValidationError( - `Oneway function must have return type of void, instead found ${fieldTypeToString( - func.returnType, - )}`, - func.loc, - ) - } - - return { - type: SyntaxType.FunctionDefinition, - name: func.name, - oneway: func.oneway, - returnType: validateFunctionType(func.returnType), - fields: validateFields( - func.fields.map((next: FieldDefinition) => { - next.requiredness = - next.requiredness === 'optional' - ? 'optional' - : 'required' - return next - }), - ), - throws: validateFields( - func.throws.map((next: FieldDefinition) => { - next.requiredness = - next.requiredness === 'optional' - ? 'optional' - : 'required' - return next - }), - ), - modifiers: func.modifiers, - comments: func.comments, - annotations: func.annotations, - loc: func.loc, - } - }, - ) - } + validateStatements() return { - name: resolvedFile.name, - path: resolvedFile.path, - source: resolvedFile.source, + type: 'ResolvedFile', + sourceFile: resolvedFile.sourceFile, namespace: resolvedFile.namespace, + includedNamespaces: resolvedFile.includedNamespaces, + namespaceToInclude: resolvedFile.namespaceToInclude, includes: resolvedFile.includes, - identifiers: resolvedFile.identifiers, - body: validateStatements(), + exports: resolvedFile.exports, + body: resolvedFile.body, errors, } } diff --git a/src/tests/integration/thrift/calculator.thrift b/src/tests/integration/thrift/calculator.thrift index 8323b458..08cdc5d2 100644 --- a/src/tests/integration/thrift/calculator.thrift +++ b/src/tests/integration/thrift/calculator.thrift @@ -15,7 +15,7 @@ const map MAPCONSTANT = {'hello':'world', 'goodnight':'moon'} struct Work { 1: required i32 num1 = 0, 2: required i32 num2, - 3: required Operation op, + 3: Operation op = Operation.ADD, 4: optional string comment, } diff --git a/src/tests/unit/bin.spec.ts b/src/tests/unit/bin.spec.ts deleted file mode 100644 index 094bb2df..00000000 --- a/src/tests/unit/bin.spec.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { assert } from 'chai' -import { resolveOptions } from '../../main/bin/resolveOptions' -import { IMakeOptions } from '../../main/types' - -describe('resolveOptions', () => { - it('should return defaults with empty options', async () => { - const result: IMakeOptions = resolveOptions([]) - - assert.deepEqual(result, { - rootDir: '.', - outDir: './codegen', - sourceDir: './thrift', - target: 'apache', - files: [], - fallbackNamespace: 'java', - library: 'thrift', - strictUnions: false, - strictUnionsComplexNames: false, - }) - }) - - it('should correctly merge options with defaults', async () => { - const result: IMakeOptions = resolveOptions([ - '--rootDir', - 'src', - '--fallbackNamespace', - 'scala', - '--strictUnionsComplexNames', - 'test.thrift', - 'test-two.thrift', - ]) - - assert.deepEqual(result, { - rootDir: 'src', - outDir: './codegen', - sourceDir: './thrift', - target: 'apache', - files: ['test.thrift', 'test-two.thrift'], - fallbackNamespace: 'scala', - library: 'thrift', - strictUnions: false, - strictUnionsComplexNames: true, - }) - }) -}) diff --git a/src/tests/unit/fixtures/apache/basic_enum.solution.ts b/src/tests/unit/fixtures/apache/basic_enum.solution.ts index 0c6dc732..82276439 100644 --- a/src/tests/unit/fixtures/apache/basic_enum.solution.ts +++ b/src/tests/unit/fixtures/apache/basic_enum.solution.ts @@ -1,5 +1,5 @@ export enum MyEnum { - ONE, - TWO, - THREE + ONE = 0, + TWO = 1, + THREE = 2 } diff --git a/src/tests/unit/fixtures/apache/basic_service.solution.ts b/src/tests/unit/fixtures/apache/basic_service.solution.ts index 331fe367..49f86f25 100644 --- a/src/tests/unit/fixtures/apache/basic_service.solution.ts +++ b/src/tests/unit/fixtures/apache/basic_service.solution.ts @@ -1,190 +1,188 @@ -export namespace MyService { - export interface IPingArgsArgs { - } - export class PingArgs { - constructor() { - } - public write(output: thrift.TProtocol): void { - output.writeStructBegin("PingArgs"); - output.writeFieldStop(); - output.writeStructEnd(); - return; - } - public static read(input: thrift.TProtocol): PingArgs { - input.readStructBegin(); - while (true) { - const ret: thrift.TField = input.readFieldBegin(); - const fieldType: thrift.Thrift.Type = ret.ftype; - const fieldId: number = ret.fid; - if (fieldType === thrift.Thrift.Type.STOP) { - break; - } - switch (fieldId) { - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return new PingArgs(); - } +export interface IPingArgsArgs { +} +export class PingArgs { + constructor() { } - export interface IPingResultArgs { - success?: void; + public write(output: thrift.TProtocol): void { + output.writeStructBegin("PingArgs"); + output.writeFieldStop(); + output.writeStructEnd(); + return; } - export class PingResult { - public success?: void; - constructor(args?: IPingResultArgs) { - if (args != null && args.success != null) { - this.success = args.success; + public static read(input: thrift.TProtocol): PingArgs { + input.readStructBegin(); + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; } - } - public write(output: thrift.TProtocol): void { - output.writeStructBegin("PingResult"); - output.writeFieldStop(); - output.writeStructEnd(); - return; - } - public static read(input: thrift.TProtocol): PingResult { - input.readStructBegin(); - let _args: any = {}; - while (true) { - const ret: thrift.TField = input.readFieldBegin(); - const fieldType: thrift.Thrift.Type = ret.ftype; - const fieldId: number = ret.fid; - if (fieldType === thrift.Thrift.Type.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.Thrift.Type.VOID) { - input.skip(fieldType); - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } + switch (fieldId) { + default: { + input.skip(fieldType); } - input.readFieldEnd(); } - input.readStructEnd(); - return new PingResult(_args); + input.readFieldEnd(); } + input.readStructEnd(); + return new PingArgs(); } - export class Client { - public _seqid: number; - public _reqs: { - [name: number]: (err: Error | object | undefined, val?: any) => void; - }; - public output: thrift.TTransport; - public protocol: new (trans: thrift.TTransport) => thrift.TProtocol; - constructor(output: thrift.TTransport, protocol: new (trans: thrift.TTransport) => thrift.TProtocol) { - this._seqid = 0; - this._reqs = {}; - this.output = output; - this.protocol = protocol; - } - public incrementSeqId(): number { - return this._seqid += 1; +} +export interface IPingResultArgs { + success?: void; +} +export class PingResult { + public success?: void; + constructor(args?: IPingResultArgs) { + if (args != null && args.success != null) { + this.success = args.success; } - public ping(): Promise { - const requestId: number = this.incrementSeqId(); - return new Promise((resolve, reject): void => { - this._reqs[requestId] = (error, result) => { - delete this._reqs[requestId]; - if (error != null) { - reject(error); + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("PingResult"); + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): PingResult { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.Thrift.Type.VOID) { + input.skip(fieldType); } else { - resolve(result); + input.skip(fieldType); } - }; - this.send_ping(requestId); - }); - } - public send_ping(requestId: number): void { - const output: thrift.TProtocol = new this.protocol(this.output); - output.writeMessageBegin("ping", thrift.Thrift.MessageType.CALL, requestId); - const args: PingArgs = new PingArgs(); - args.write(output); - output.writeMessageEnd(); - this.output.flush(); - return; - } - public recv_ping(input: thrift.TProtocol, mtype: thrift.Thrift.MessageType, requestId: number): void { - const noop = (): any => null; - const callback = this._reqs[requestId] || noop; - if (mtype === thrift.Thrift.MessageType.EXCEPTION) { - const x: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(); - x.read(input); - input.readMessageEnd(); - return callback(x); - } - else { - input.readMessageEnd(); - return callback(undefined); + break; + default: { + input.skip(fieldType); + } } + input.readFieldEnd(); } + input.readStructEnd(); + return new PingResult(_args); + } +} +export class Client { + public _seqid: number; + public _reqs: { + [name: number]: (err: Error | object | undefined, val?: any) => void; + }; + public output: thrift.TTransport; + public protocol: new (trans: thrift.TTransport) => thrift.TProtocol; + constructor(output: thrift.TTransport, protocol: new (trans: thrift.TTransport) => thrift.TProtocol) { + this._seqid = 0; + this._reqs = {}; + this.output = output; + this.protocol = protocol; } - export interface IHandler { - ping(): void | Promise; + public incrementSeqId(): number { + return this._seqid += 1; } - export class Processor { - public _handler: IHandler; - constructor(handler: IHandler) { - this._handler = handler; - } - public process(input: thrift.TProtocol, output: thrift.TProtocol): void { - const metadata: thrift.TMessage = input.readMessageBegin(); - const fname: string = metadata.fname; - const requestId: number = metadata.rseqid; - const methodName: string = "process_" + fname; - switch (methodName) { - case "process_ping": { - this.process_ping(requestId, input, output); - return; + public ping(): Promise { + const requestId: number = this.incrementSeqId(); + return new Promise((resolve, reject): void => { + this._reqs[requestId] = (error, result) => { + delete this._reqs[requestId]; + if (error != null) { + reject(error); } - default: { - input.skip(thrift.Thrift.Type.STRUCT); - input.readMessageEnd(); - const errMessage = "Unknown function " + fname; - const err = new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN_METHOD, errMessage); - output.writeMessageBegin(fname, thrift.Thrift.MessageType.EXCEPTION, requestId); - err.write(output); - output.writeMessageEnd(); - output.flush(); - return; + else { + resolve(result); } - } + }; + this.send_ping(requestId); + }); + } + public send_ping(requestId: number): void { + const output: thrift.TProtocol = new this.protocol(this.output); + output.writeMessageBegin("ping", thrift.Thrift.MessageType.CALL, requestId); + const args: PingArgs = new PingArgs(); + args.write(output); + output.writeMessageEnd(); + this.output.flush(); + return; + } + public recv_ping(input: thrift.TProtocol, mtype: thrift.Thrift.MessageType, requestId: number): void { + const noop = (): any => null; + const callback = this._reqs[requestId] || noop; + if (mtype === thrift.Thrift.MessageType.EXCEPTION) { + const x: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(); + x.read(input); + input.readMessageEnd(); + return callback(x); } - public process_ping(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol): void { - new Promise((resolve, reject): void => { - try { - input.readMessageEnd(); - resolve(this._handler.ping()); - } - catch (err) { - reject(err); - } - }).then((data: void): void => { - const result: PingResult = new PingResult({ success: data }); - output.writeMessageBegin("ping", thrift.Thrift.MessageType.REPLY, requestId); - result.write(output); - output.writeMessageEnd(); - output.flush(); + else { + input.readMessageEnd(); + return callback(undefined); + } + } +} +export interface IHandler { + ping(): void | Promise; +} +export class Processor { + public _handler: IHandler; + constructor(handler: IHandler) { + this._handler = handler; + } + public process(input: thrift.TProtocol, output: thrift.TProtocol): void { + const metadata: thrift.TMessage = input.readMessageBegin(); + const fname: string = metadata.fname; + const requestId: number = metadata.rseqid; + const methodName: string = "process_" + fname; + switch (methodName) { + case "process_ping": { + this.process_ping(requestId, input, output); return; - }).catch((err: Error): void => { - const result: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("ping", thrift.Thrift.MessageType.EXCEPTION, requestId); - result.write(output); + } + default: { + input.skip(thrift.Thrift.Type.STRUCT); + input.readMessageEnd(); + const errMessage = "Unknown function " + fname; + const err = new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN_METHOD, errMessage); + output.writeMessageBegin(fname, thrift.Thrift.MessageType.EXCEPTION, requestId); + err.write(output); output.writeMessageEnd(); output.flush(); return; - }); + } } } + public process_ping(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol): void { + new Promise((resolve, reject): void => { + try { + input.readMessageEnd(); + resolve(this._handler.ping()); + } + catch (err) { + reject(err); + } + }).then((data: void): void => { + const result: PingResult = new PingResult({ success: data }); + output.writeMessageBegin("ping", thrift.Thrift.MessageType.REPLY, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + }).catch((err: Error): void => { + const result: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("ping", thrift.Thrift.MessageType.EXCEPTION, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + }); + } } diff --git a/src/tests/unit/fixtures/apache/complex_typedef.solution.ts b/src/tests/unit/fixtures/apache/complex_typedef.solution.ts index 1dc53670..bbc738f7 100644 --- a/src/tests/unit/fixtures/apache/complex_typedef.solution.ts +++ b/src/tests/unit/fixtures/apache/complex_typedef.solution.ts @@ -1,6 +1,6 @@ export enum MyEnum { - ONE, - TWO + ONE = 0, + TWO = 1 } export type MyInt = number; export import AnotherName = MyEnum; diff --git a/src/tests/unit/fixtures/apache/enum_typedef.solution.ts b/src/tests/unit/fixtures/apache/enum_typedef.solution.ts index 50b1179e..2c7b7749 100644 --- a/src/tests/unit/fixtures/apache/enum_typedef.solution.ts +++ b/src/tests/unit/fixtures/apache/enum_typedef.solution.ts @@ -1,5 +1,5 @@ export enum MyEnum { - ONE, - TWO + ONE = 0, + TWO = 1 } export import AnotherName = MyEnum; diff --git a/src/tests/unit/fixtures/apache/extend_service.solution.ts b/src/tests/unit/fixtures/apache/extend_service.solution.ts deleted file mode 100644 index 6f44aa8e..00000000 --- a/src/tests/unit/fixtures/apache/extend_service.solution.ts +++ /dev/null @@ -1,471 +0,0 @@ -export namespace ParentService { - export interface IPingArgsArgs { - status: number; - } - export class PingArgs { - public status: number; - constructor(args: IPingArgsArgs) { - if (args != null && args.status != null) { - this.status = args.status; - } - else { - throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Required field[status] is unset!"); - } - } - public write(output: thrift.TProtocol): void { - output.writeStructBegin("PingArgs"); - if (this.status != null) { - output.writeFieldBegin("status", thrift.Thrift.Type.I32, 1); - output.writeI32(this.status); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - } - public static read(input: thrift.TProtocol): PingArgs { - input.readStructBegin(); - let _args: any = {}; - while (true) { - const ret: thrift.TField = input.readFieldBegin(); - const fieldType: thrift.Thrift.Type = ret.ftype; - const fieldId: number = ret.fid; - if (fieldType === thrift.Thrift.Type.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.Thrift.Type.I32) { - const value_1: number = input.readI32(); - _args.status = value_1; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.status !== undefined) { - return new PingArgs(_args); - } - else { - throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Unable to read PingArgs from input"); - } - } - } - export interface IPingResultArgs { - success?: string; - } - export class PingResult { - public success?: string; - constructor(args?: IPingResultArgs) { - if (args != null && args.success != null) { - this.success = args.success; - } - } - public write(output: thrift.TProtocol): void { - output.writeStructBegin("PingResult"); - if (this.success != null) { - output.writeFieldBegin("success", thrift.Thrift.Type.STRING, 0); - output.writeString(this.success); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - } - public static read(input: thrift.TProtocol): PingResult { - input.readStructBegin(); - let _args: any = {}; - while (true) { - const ret: thrift.TField = input.readFieldBegin(); - const fieldType: thrift.Thrift.Type = ret.ftype; - const fieldId: number = ret.fid; - if (fieldType === thrift.Thrift.Type.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.Thrift.Type.STRING) { - const value_2: string = input.readString(); - _args.success = value_2; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return new PingResult(_args); - } - } - export class Client { - public _seqid: number; - public _reqs: { - [name: number]: (err: Error | object | undefined, val?: any) => void; - }; - public output: thrift.TTransport; - public protocol: new (trans: thrift.TTransport) => thrift.TProtocol; - constructor(output: thrift.TTransport, protocol: new (trans: thrift.TTransport) => thrift.TProtocol) { - this._seqid = 0; - this._reqs = {}; - this.output = output; - this.protocol = protocol; - } - public incrementSeqId(): number { - return this._seqid += 1; - } - public ping(status: number): Promise { - const requestId: number = this.incrementSeqId(); - return new Promise((resolve, reject): void => { - this._reqs[requestId] = (error, result) => { - delete this._reqs[requestId]; - if (error != null) { - reject(error); - } - else { - resolve(result); - } - }; - this.send_ping(status, requestId); - }); - } - public send_ping(status: number, requestId: number): void { - const output: thrift.TProtocol = new this.protocol(this.output); - output.writeMessageBegin("ping", thrift.Thrift.MessageType.CALL, requestId); - const args: PingArgs = new PingArgs({ status }); - args.write(output); - output.writeMessageEnd(); - this.output.flush(); - return; - } - public recv_ping(input: thrift.TProtocol, mtype: thrift.Thrift.MessageType, requestId: number): void { - const noop = (): any => null; - const callback = this._reqs[requestId] || noop; - if (mtype === thrift.Thrift.MessageType.EXCEPTION) { - const x: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(); - x.read(input); - input.readMessageEnd(); - return callback(x); - } - else { - const result: PingResult = PingResult.read(input); - input.readMessageEnd(); - if (result.success != null) { - return callback(undefined, result.success); - } - else { - return callback(new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, "ping failed: unknown result")); - } - } - } - } - export interface IHandler { - ping(status: number): string | Promise; - } - export class Processor { - public _handler: IHandler; - constructor(handler: IHandler) { - this._handler = handler; - } - public process(input: thrift.TProtocol, output: thrift.TProtocol): void { - const metadata: thrift.TMessage = input.readMessageBegin(); - const fname: string = metadata.fname; - const requestId: number = metadata.rseqid; - const methodName: string = "process_" + fname; - switch (methodName) { - case "process_ping": { - this.process_ping(requestId, input, output); - return; - } - default: { - input.skip(thrift.Thrift.Type.STRUCT); - input.readMessageEnd(); - const errMessage = "Unknown function " + fname; - const err = new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN_METHOD, errMessage); - output.writeMessageBegin(fname, thrift.Thrift.MessageType.EXCEPTION, requestId); - err.write(output); - output.writeMessageEnd(); - output.flush(); - return; - } - } - } - public process_ping(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol): void { - new Promise((resolve, reject): void => { - try { - const args: PingArgs = PingArgs.read(input); - input.readMessageEnd(); - resolve(this._handler.ping(args.status)); - } - catch (err) { - reject(err); - } - }).then((data: string): void => { - const result: PingResult = new PingResult({ success: data }); - output.writeMessageBegin("ping", thrift.Thrift.MessageType.REPLY, requestId); - result.write(output); - output.writeMessageEnd(); - output.flush(); - return; - }).catch((err: Error): void => { - const result: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("ping", thrift.Thrift.MessageType.EXCEPTION, requestId); - result.write(output); - output.writeMessageEnd(); - output.flush(); - return; - }); - } - } -} -export namespace ChildService { - export interface IPegArgsArgs { - name: string; - } - export class PegArgs { - public name: string; - constructor(args: IPegArgsArgs) { - if (args != null && args.name != null) { - this.name = args.name; - } - else { - throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Required field[name] is unset!"); - } - } - public write(output: thrift.TProtocol): void { - output.writeStructBegin("PegArgs"); - if (this.name != null) { - output.writeFieldBegin("name", thrift.Thrift.Type.STRING, 1); - output.writeString(this.name); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - } - public static read(input: thrift.TProtocol): PegArgs { - input.readStructBegin(); - let _args: any = {}; - while (true) { - const ret: thrift.TField = input.readFieldBegin(); - const fieldType: thrift.Thrift.Type = ret.ftype; - const fieldId: number = ret.fid; - if (fieldType === thrift.Thrift.Type.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.Thrift.Type.STRING) { - const value_3: string = input.readString(); - _args.name = value_3; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.name !== undefined) { - return new PegArgs(_args); - } - else { - throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Unable to read PegArgs from input"); - } - } - } - export interface IPegResultArgs { - success?: string; - } - export class PegResult { - public success?: string; - constructor(args?: IPegResultArgs) { - if (args != null && args.success != null) { - this.success = args.success; - } - } - public write(output: thrift.TProtocol): void { - output.writeStructBegin("PegResult"); - if (this.success != null) { - output.writeFieldBegin("success", thrift.Thrift.Type.STRING, 0); - output.writeString(this.success); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - } - public static read(input: thrift.TProtocol): PegResult { - input.readStructBegin(); - let _args: any = {}; - while (true) { - const ret: thrift.TField = input.readFieldBegin(); - const fieldType: thrift.Thrift.Type = ret.ftype; - const fieldId: number = ret.fid; - if (fieldType === thrift.Thrift.Type.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.Thrift.Type.STRING) { - const value_4: string = input.readString(); - _args.success = value_4; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return new PegResult(_args); - } - } - export class Client extends ParentService.Client { - public _seqid: number; - public _reqs: { - [name: number]: (err: Error | object | undefined, val?: any) => void; - }; - public output: thrift.TTransport; - public protocol: new (trans: thrift.TTransport) => thrift.TProtocol; - constructor(output: thrift.TTransport, protocol: new (trans: thrift.TTransport) => thrift.TProtocol) { - super(output, protocol); - this._seqid = 0; - this._reqs = {}; - this.output = output; - this.protocol = protocol; - } - public incrementSeqId(): number { - return this._seqid += 1; - } - public peg(name: string): Promise { - const requestId: number = this.incrementSeqId(); - return new Promise((resolve, reject): void => { - this._reqs[requestId] = (error, result) => { - delete this._reqs[requestId]; - if (error != null) { - reject(error); - } - else { - resolve(result); - } - }; - this.send_peg(name, requestId); - }); - } - public send_peg(name: string, requestId: number): void { - const output: thrift.TProtocol = new this.protocol(this.output); - output.writeMessageBegin("peg", thrift.Thrift.MessageType.CALL, requestId); - const args: PegArgs = new PegArgs({ name }); - args.write(output); - output.writeMessageEnd(); - this.output.flush(); - return; - } - public recv_peg(input: thrift.TProtocol, mtype: thrift.Thrift.MessageType, requestId: number): void { - const noop = (): any => null; - const callback = this._reqs[requestId] || noop; - if (mtype === thrift.Thrift.MessageType.EXCEPTION) { - const x: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(); - x.read(input); - input.readMessageEnd(); - return callback(x); - } - else { - const result: PegResult = PegResult.read(input); - input.readMessageEnd(); - if (result.success != null) { - return callback(undefined, result.success); - } - else { - return callback(new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, "peg failed: unknown result")); - } - } - } - } - export interface ILocalHandler { - peg(name: string): string | Promise; - } - export type IHandler = ILocalHandler & ParentService.IHandler; - export class Processor extends ParentService.Processor { - public _handler: IHandler; - constructor(handler: IHandler) { - super({ - ping: handler.ping - }); - this._handler = handler; - } - public process(input: thrift.TProtocol, output: thrift.TProtocol): void { - const metadata: thrift.TMessage = input.readMessageBegin(); - const fname: string = metadata.fname; - const requestId: number = metadata.rseqid; - const methodName: string = "process_" + fname; - switch (methodName) { - case "process_ping": { - this.process_ping(requestId, input, output); - return; - } - case "process_peg": { - this.process_peg(requestId, input, output); - return; - } - default: { - input.skip(thrift.Thrift.Type.STRUCT); - input.readMessageEnd(); - const errMessage = "Unknown function " + fname; - const err = new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN_METHOD, errMessage); - output.writeMessageBegin(fname, thrift.Thrift.MessageType.EXCEPTION, requestId); - err.write(output); - output.writeMessageEnd(); - output.flush(); - return; - } - } - } - public process_peg(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol): void { - new Promise((resolve, reject): void => { - try { - const args: PegArgs = PegArgs.read(input); - input.readMessageEnd(); - resolve(this._handler.peg(args.name)); - } - catch (err) { - reject(err); - } - }).then((data: string): void => { - const result: PegResult = new PegResult({ success: data }); - output.writeMessageBegin("peg", thrift.Thrift.MessageType.REPLY, requestId); - result.write(output); - output.writeMessageEnd(); - output.flush(); - return; - }).catch((err: Error): void => { - const result: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("peg", thrift.Thrift.MessageType.EXCEPTION, requestId); - result.write(output); - output.writeMessageEnd(); - output.flush(); - return; - }); - } - } -} diff --git a/src/tests/unit/fixtures/apache/generated/com/test/calculator/Calculator.ts b/src/tests/unit/fixtures/apache/generated/com/test/calculator/Calculator.ts new file mode 100644 index 00000000..f8fcecbe --- /dev/null +++ b/src/tests/unit/fixtures/apache/generated/com/test/calculator/Calculator.ts @@ -0,0 +1,2826 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import Int64 = require("node-int64"); +import * as thrift from "test-lib"; +import * as com_test_shared from "./../shared"; +import * as com_test_operation from "./../operation"; +import * as com_test_common from "./../common"; +import * as __NAMESPACE__ from "./."; +export interface IPingArgsArgs { +} +export class PingArgs { + constructor() { + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("PingArgs"); + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): PingArgs { + input.readStructBegin(); + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return new PingArgs(); + } +} +export interface IAddArgsArgs { + num1: number; + num2: number; +} +export class AddArgs { + public num1: number; + public num2: number; + constructor(args: IAddArgsArgs) { + if (args != null && args.num1 != null) { + this.num1 = args.num1; + } + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Required field[num1] is unset!"); + } + if (args != null && args.num2 != null) { + this.num2 = args.num2; + } + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Required field[num2] is unset!"); + } + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("AddArgs"); + if (this.num1 != null) { + output.writeFieldBegin("num1", thrift.Thrift.Type.I32, 1); + output.writeI32(this.num1); + output.writeFieldEnd(); + } + if (this.num2 != null) { + output.writeFieldBegin("num2", thrift.Thrift.Type.I32, 2); + output.writeI32(this.num2); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): AddArgs { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.Thrift.Type.I32) { + const value_1: number = input.readI32(); + _args.num1 = value_1; + } + else { + input.skip(fieldType); + } + break; + case 2: + if (fieldType === thrift.Thrift.Type.I32) { + const value_2: number = input.readI32(); + _args.num2 = value_2; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.num1 !== undefined && _args.num2 !== undefined) { + return new AddArgs(_args); + } + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Unable to read AddArgs from input"); + } + } +} +export interface IAddInt64ArgsArgs { + num1: number | Int64; + num2: number | Int64; +} +export class AddInt64Args { + public num1: Int64; + public num2: Int64; + constructor(args: IAddInt64ArgsArgs) { + if (args != null && args.num1 != null) { + if (typeof args.num1 === "number") { + this.num1 = new Int64(args.num1); + } + else { + this.num1 = args.num1; + } + } + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Required field[num1] is unset!"); + } + if (args != null && args.num2 != null) { + if (typeof args.num2 === "number") { + this.num2 = new Int64(args.num2); + } + else { + this.num2 = args.num2; + } + } + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Required field[num2] is unset!"); + } + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("AddInt64Args"); + if (this.num1 != null) { + output.writeFieldBegin("num1", thrift.Thrift.Type.I64, 1); + output.writeI64(this.num1); + output.writeFieldEnd(); + } + if (this.num2 != null) { + output.writeFieldBegin("num2", thrift.Thrift.Type.I64, 2); + output.writeI64(this.num2); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): AddInt64Args { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.Thrift.Type.I64) { + const value_3: Int64 = input.readI64(); + _args.num1 = value_3; + } + else { + input.skip(fieldType); + } + break; + case 2: + if (fieldType === thrift.Thrift.Type.I64) { + const value_4: Int64 = input.readI64(); + _args.num2 = value_4; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.num1 !== undefined && _args.num2 !== undefined) { + return new AddInt64Args(_args); + } + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Unable to read AddInt64Args from input"); + } + } +} +export interface IAddWithContextArgsArgs { + num1: number; + num2: number; +} +export class AddWithContextArgs { + public num1: number; + public num2: number; + constructor(args: IAddWithContextArgsArgs) { + if (args != null && args.num1 != null) { + this.num1 = args.num1; + } + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Required field[num1] is unset!"); + } + if (args != null && args.num2 != null) { + this.num2 = args.num2; + } + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Required field[num2] is unset!"); + } + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("AddWithContextArgs"); + if (this.num1 != null) { + output.writeFieldBegin("num1", thrift.Thrift.Type.I32, 1); + output.writeI32(this.num1); + output.writeFieldEnd(); + } + if (this.num2 != null) { + output.writeFieldBegin("num2", thrift.Thrift.Type.I32, 2); + output.writeI32(this.num2); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): AddWithContextArgs { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.Thrift.Type.I32) { + const value_5: number = input.readI32(); + _args.num1 = value_5; + } + else { + input.skip(fieldType); + } + break; + case 2: + if (fieldType === thrift.Thrift.Type.I32) { + const value_6: number = input.readI32(); + _args.num2 = value_6; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.num1 !== undefined && _args.num2 !== undefined) { + return new AddWithContextArgs(_args); + } + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Unable to read AddWithContextArgs from input"); + } + } +} +export interface ICalculateArgsArgs { + logid: number; + work: __NAMESPACE__.Work; +} +export class CalculateArgs { + public logid: number; + public work: __NAMESPACE__.Work; + constructor(args: ICalculateArgsArgs) { + if (args != null && args.logid != null) { + this.logid = args.logid; + } + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Required field[logid] is unset!"); + } + if (args != null && args.work != null) { + this.work = args.work; + } + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Required field[work] is unset!"); + } + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("CalculateArgs"); + if (this.logid != null) { + output.writeFieldBegin("logid", thrift.Thrift.Type.I32, 1); + output.writeI32(this.logid); + output.writeFieldEnd(); + } + if (this.work != null) { + output.writeFieldBegin("work", thrift.Thrift.Type.STRUCT, 2); + this.work.write(output); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): CalculateArgs { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.Thrift.Type.I32) { + const value_7: number = input.readI32(); + _args.logid = value_7; + } + else { + input.skip(fieldType); + } + break; + case 2: + if (fieldType === thrift.Thrift.Type.STRUCT) { + const value_8: __NAMESPACE__.Work = __NAMESPACE__.Work.read(input); + _args.work = value_8; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.logid !== undefined && _args.work !== undefined) { + return new CalculateArgs(_args); + } + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Unable to read CalculateArgs from input"); + } + } +} +export interface IEchoBinaryArgsArgs { + word: Buffer; +} +export class EchoBinaryArgs { + public word: Buffer; + constructor(args: IEchoBinaryArgsArgs) { + if (args != null && args.word != null) { + this.word = args.word; + } + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Required field[word] is unset!"); + } + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("EchoBinaryArgs"); + if (this.word != null) { + output.writeFieldBegin("word", thrift.Thrift.Type.STRING, 1); + output.writeBinary(this.word); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): EchoBinaryArgs { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.Thrift.Type.STRING) { + const value_9: Buffer = input.readBinary(); + _args.word = value_9; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.word !== undefined) { + return new EchoBinaryArgs(_args); + } + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Unable to read EchoBinaryArgs from input"); + } + } +} +export interface IEchoStringArgsArgs { + word: string; +} +export class EchoStringArgs { + public word: string; + constructor(args: IEchoStringArgsArgs) { + if (args != null && args.word != null) { + this.word = args.word; + } + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Required field[word] is unset!"); + } + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("EchoStringArgs"); + if (this.word != null) { + output.writeFieldBegin("word", thrift.Thrift.Type.STRING, 1); + output.writeString(this.word); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): EchoStringArgs { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.Thrift.Type.STRING) { + const value_10: string = input.readString(); + _args.word = value_10; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.word !== undefined) { + return new EchoStringArgs(_args); + } + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Unable to read EchoStringArgs from input"); + } + } +} +export interface ICheckNameArgsArgs { + choice: __NAMESPACE__.Choice; +} +export class CheckNameArgs { + public choice: __NAMESPACE__.Choice; + constructor(args: ICheckNameArgsArgs) { + if (args != null && args.choice != null) { + this.choice = args.choice; + } + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Required field[choice] is unset!"); + } + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("CheckNameArgs"); + if (this.choice != null) { + output.writeFieldBegin("choice", thrift.Thrift.Type.STRUCT, 1); + this.choice.write(output); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): CheckNameArgs { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.Thrift.Type.STRUCT) { + const value_11: __NAMESPACE__.Choice = __NAMESPACE__.Choice.read(input); + _args.choice = value_11; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.choice !== undefined) { + return new CheckNameArgs(_args); + } + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Unable to read CheckNameArgs from input"); + } + } +} +export interface ICheckOptionalArgsArgs { + type?: string; +} +export class CheckOptionalArgs { + public type?: string; + constructor(args?: ICheckOptionalArgsArgs) { + if (args != null && args.type != null) { + this.type = args.type; + } + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("CheckOptionalArgs"); + if (this.type != null) { + output.writeFieldBegin("type", thrift.Thrift.Type.STRING, 1); + output.writeString(this.type); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): CheckOptionalArgs { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.Thrift.Type.STRING) { + const value_12: string = input.readString(); + _args.type = value_12; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return new CheckOptionalArgs(_args); + } +} +export interface IMapOneListArgsArgs { + arg: Array; +} +export class MapOneListArgs { + public arg: Array; + constructor(args: IMapOneListArgsArgs) { + if (args != null && args.arg != null) { + this.arg = args.arg; + } + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Required field[arg] is unset!"); + } + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("MapOneListArgs"); + if (this.arg != null) { + output.writeFieldBegin("arg", thrift.Thrift.Type.LIST, 1); + output.writeListBegin(thrift.Thrift.Type.I32, this.arg.length); + this.arg.forEach((value_13: number): void => { + output.writeI32(value_13); + }); + output.writeListEnd(); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): MapOneListArgs { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.Thrift.Type.LIST) { + const value_14: Array = new Array(); + const metadata_1: thrift.TList = input.readListBegin(); + const size_1: number = metadata_1.size; + for (let i_1: number = 0; i_1 < size_1; i_1++) { + const value_15: number = input.readI32(); + value_14.push(value_15); + } + input.readListEnd(); + _args.arg = value_14; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.arg !== undefined) { + return new MapOneListArgs(_args); + } + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Unable to read MapOneListArgs from input"); + } + } +} +export interface IMapValuesArgsArgs { + arg: Map; +} +export class MapValuesArgs { + public arg: Map; + constructor(args: IMapValuesArgsArgs) { + if (args != null && args.arg != null) { + this.arg = args.arg; + } + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Required field[arg] is unset!"); + } + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("MapValuesArgs"); + if (this.arg != null) { + output.writeFieldBegin("arg", thrift.Thrift.Type.MAP, 1); + output.writeMapBegin(thrift.Thrift.Type.STRING, thrift.Thrift.Type.I32, this.arg.size); + this.arg.forEach((value_16: number, key_1: string): void => { + output.writeString(key_1); + output.writeI32(value_16); + }); + output.writeMapEnd(); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): MapValuesArgs { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.Thrift.Type.MAP) { + const value_17: Map = new Map(); + const metadata_2: thrift.TMap = input.readMapBegin(); + const size_2: number = metadata_2.size; + for (let i_2: number = 0; i_2 < size_2; i_2++) { + const key_2: string = input.readString(); + const value_18: number = input.readI32(); + value_17.set(key_2, value_18); + } + input.readMapEnd(); + _args.arg = value_17; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.arg !== undefined) { + return new MapValuesArgs(_args); + } + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Unable to read MapValuesArgs from input"); + } + } +} +export interface IListToMapArgsArgs { + arg: Array>; +} +export class ListToMapArgs { + public arg: Array>; + constructor(args: IListToMapArgsArgs) { + if (args != null && args.arg != null) { + this.arg = args.arg; + } + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Required field[arg] is unset!"); + } + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("ListToMapArgs"); + if (this.arg != null) { + output.writeFieldBegin("arg", thrift.Thrift.Type.LIST, 1); + output.writeListBegin(thrift.Thrift.Type.LIST, this.arg.length); + this.arg.forEach((value_19: Array): void => { + output.writeListBegin(thrift.Thrift.Type.STRING, value_19.length); + value_19.forEach((value_20: string): void => { + output.writeString(value_20); + }); + output.writeListEnd(); + }); + output.writeListEnd(); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): ListToMapArgs { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.Thrift.Type.LIST) { + const value_21: Array> = new Array>(); + const metadata_3: thrift.TList = input.readListBegin(); + const size_3: number = metadata_3.size; + for (let i_3: number = 0; i_3 < size_3; i_3++) { + const value_22: Array = new Array(); + const metadata_4: thrift.TList = input.readListBegin(); + const size_4: number = metadata_4.size; + for (let i_4: number = 0; i_4 < size_4; i_4++) { + const value_23: string = input.readString(); + value_22.push(value_23); + } + input.readListEnd(); + value_21.push(value_22); + } + input.readListEnd(); + _args.arg = value_21; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.arg !== undefined) { + return new ListToMapArgs(_args); + } + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Unable to read ListToMapArgs from input"); + } + } +} +export interface IFetchThingArgsArgs { +} +export class FetchThingArgs { + constructor() { + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("FetchThingArgs"); + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): FetchThingArgs { + input.readStructBegin(); + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return new FetchThingArgs(); + } +} +export interface IZipArgsArgs { +} +export class ZipArgs { + constructor() { + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("ZipArgs"); + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): ZipArgs { + input.readStructBegin(); + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return new ZipArgs(); + } +} +export interface IPingResultArgs { + success?: void; +} +export class PingResult { + public success?: void; + constructor(args?: IPingResultArgs) { + if (args != null && args.success != null) { + this.success = args.success; + } + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("PingResult"); + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): PingResult { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.Thrift.Type.VOID) { + input.skip(fieldType); + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return new PingResult(_args); + } +} +export interface IAddResultArgs { + success?: number; + exp?: com_test_operation.JankyResult; +} +export class AddResult { + public success?: number; + public exp?: com_test_operation.JankyResult; + constructor(args?: IAddResultArgs) { + if (args != null && args.success != null) { + this.success = args.success; + } + if (args != null && args.exp != null) { + this.exp = args.exp; + } + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("AddResult"); + if (this.success != null) { + output.writeFieldBegin("success", thrift.Thrift.Type.I32, 0); + output.writeI32(this.success); + output.writeFieldEnd(); + } + if (this.exp != null) { + output.writeFieldBegin("exp", thrift.Thrift.Type.STRUCT, 1); + this.exp.write(output); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): AddResult { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.Thrift.Type.I32) { + const value_24: number = input.readI32(); + _args.success = value_24; + } + else { + input.skip(fieldType); + } + break; + case 1: + if (fieldType === thrift.Thrift.Type.STRUCT) { + const value_25: com_test_operation.JankyResult = com_test_operation.JankyResult.read(input); + _args.exp = value_25; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return new AddResult(_args); + } +} +export interface IAddInt64ResultArgs { + success?: number | Int64; + exp?: __NAMESPACE__.NotAGoodIdea; +} +export class AddInt64Result { + public success?: Int64; + public exp?: __NAMESPACE__.NotAGoodIdea; + constructor(args?: IAddInt64ResultArgs) { + if (args != null && args.success != null) { + if (typeof args.success === "number") { + this.success = new Int64(args.success); + } + else { + this.success = args.success; + } + } + if (args != null && args.exp != null) { + this.exp = args.exp; + } + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("AddInt64Result"); + if (this.success != null) { + output.writeFieldBegin("success", thrift.Thrift.Type.I64, 0); + output.writeI64(this.success); + output.writeFieldEnd(); + } + if (this.exp != null) { + output.writeFieldBegin("exp", thrift.Thrift.Type.STRUCT, 1); + this.exp.write(output); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): AddInt64Result { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.Thrift.Type.I64) { + const value_26: Int64 = input.readI64(); + _args.success = value_26; + } + else { + input.skip(fieldType); + } + break; + case 1: + if (fieldType === thrift.Thrift.Type.STRUCT) { + const value_27: __NAMESPACE__.NotAGoodIdea = __NAMESPACE__.NotAGoodIdea.read(input); + _args.exp = value_27; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return new AddInt64Result(_args); + } +} +export interface IAddWithContextResultArgs { + success?: number; +} +export class AddWithContextResult { + public success?: number; + constructor(args?: IAddWithContextResultArgs) { + if (args != null && args.success != null) { + this.success = args.success; + } + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("AddWithContextResult"); + if (this.success != null) { + output.writeFieldBegin("success", thrift.Thrift.Type.I32, 0); + output.writeI32(this.success); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): AddWithContextResult { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.Thrift.Type.I32) { + const value_28: number = input.readI32(); + _args.success = value_28; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return new AddWithContextResult(_args); + } +} +export interface ICalculateResultArgs { + success?: number; + ouch?: com_test_operation.JankyOperation; +} +export class CalculateResult { + public success?: number; + public ouch?: com_test_operation.JankyOperation; + constructor(args?: ICalculateResultArgs) { + if (args != null && args.success != null) { + this.success = args.success; + } + if (args != null && args.ouch != null) { + this.ouch = args.ouch; + } + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("CalculateResult"); + if (this.success != null) { + output.writeFieldBegin("success", thrift.Thrift.Type.I32, 0); + output.writeI32(this.success); + output.writeFieldEnd(); + } + if (this.ouch != null) { + output.writeFieldBegin("ouch", thrift.Thrift.Type.STRUCT, 1); + this.ouch.write(output); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): CalculateResult { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.Thrift.Type.I32) { + const value_29: number = input.readI32(); + _args.success = value_29; + } + else { + input.skip(fieldType); + } + break; + case 1: + if (fieldType === thrift.Thrift.Type.STRUCT) { + const value_30: com_test_operation.JankyOperation = com_test_operation.JankyOperation.read(input); + _args.ouch = value_30; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return new CalculateResult(_args); + } +} +export interface IEchoBinaryResultArgs { + success?: string; +} +export class EchoBinaryResult { + public success?: string; + constructor(args?: IEchoBinaryResultArgs) { + if (args != null && args.success != null) { + this.success = args.success; + } + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("EchoBinaryResult"); + if (this.success != null) { + output.writeFieldBegin("success", thrift.Thrift.Type.STRING, 0); + output.writeString(this.success); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): EchoBinaryResult { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.Thrift.Type.STRING) { + const value_31: string = input.readString(); + _args.success = value_31; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return new EchoBinaryResult(_args); + } +} +export interface IEchoStringResultArgs { + success?: string; +} +export class EchoStringResult { + public success?: string; + constructor(args?: IEchoStringResultArgs) { + if (args != null && args.success != null) { + this.success = args.success; + } + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("EchoStringResult"); + if (this.success != null) { + output.writeFieldBegin("success", thrift.Thrift.Type.STRING, 0); + output.writeString(this.success); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): EchoStringResult { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.Thrift.Type.STRING) { + const value_32: string = input.readString(); + _args.success = value_32; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return new EchoStringResult(_args); + } +} +export interface ICheckNameResultArgs { + success?: string; +} +export class CheckNameResult { + public success?: string; + constructor(args?: ICheckNameResultArgs) { + if (args != null && args.success != null) { + this.success = args.success; + } + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("CheckNameResult"); + if (this.success != null) { + output.writeFieldBegin("success", thrift.Thrift.Type.STRING, 0); + output.writeString(this.success); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): CheckNameResult { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.Thrift.Type.STRING) { + const value_33: string = input.readString(); + _args.success = value_33; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return new CheckNameResult(_args); + } +} +export interface ICheckOptionalResultArgs { + success?: string; +} +export class CheckOptionalResult { + public success?: string; + constructor(args?: ICheckOptionalResultArgs) { + if (args != null && args.success != null) { + this.success = args.success; + } + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("CheckOptionalResult"); + if (this.success != null) { + output.writeFieldBegin("success", thrift.Thrift.Type.STRING, 0); + output.writeString(this.success); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): CheckOptionalResult { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.Thrift.Type.STRING) { + const value_34: string = input.readString(); + _args.success = value_34; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return new CheckOptionalResult(_args); + } +} +export interface IMapOneListResultArgs { + success?: Array; +} +export class MapOneListResult { + public success?: Array; + constructor(args?: IMapOneListResultArgs) { + if (args != null && args.success != null) { + this.success = args.success; + } + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("MapOneListResult"); + if (this.success != null) { + output.writeFieldBegin("success", thrift.Thrift.Type.LIST, 0); + output.writeListBegin(thrift.Thrift.Type.I32, this.success.length); + this.success.forEach((value_35: number): void => { + output.writeI32(value_35); + }); + output.writeListEnd(); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): MapOneListResult { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.Thrift.Type.LIST) { + const value_36: Array = new Array(); + const metadata_5: thrift.TList = input.readListBegin(); + const size_5: number = metadata_5.size; + for (let i_5: number = 0; i_5 < size_5; i_5++) { + const value_37: number = input.readI32(); + value_36.push(value_37); + } + input.readListEnd(); + _args.success = value_36; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return new MapOneListResult(_args); + } +} +export interface IMapValuesResultArgs { + success?: Array; +} +export class MapValuesResult { + public success?: Array; + constructor(args?: IMapValuesResultArgs) { + if (args != null && args.success != null) { + this.success = args.success; + } + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("MapValuesResult"); + if (this.success != null) { + output.writeFieldBegin("success", thrift.Thrift.Type.LIST, 0); + output.writeListBegin(thrift.Thrift.Type.I32, this.success.length); + this.success.forEach((value_38: number): void => { + output.writeI32(value_38); + }); + output.writeListEnd(); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): MapValuesResult { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.Thrift.Type.LIST) { + const value_39: Array = new Array(); + const metadata_6: thrift.TList = input.readListBegin(); + const size_6: number = metadata_6.size; + for (let i_6: number = 0; i_6 < size_6; i_6++) { + const value_40: number = input.readI32(); + value_39.push(value_40); + } + input.readListEnd(); + _args.success = value_39; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return new MapValuesResult(_args); + } +} +export interface IListToMapResultArgs { + success?: Map; +} +export class ListToMapResult { + public success?: Map; + constructor(args?: IListToMapResultArgs) { + if (args != null && args.success != null) { + this.success = args.success; + } + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("ListToMapResult"); + if (this.success != null) { + output.writeFieldBegin("success", thrift.Thrift.Type.MAP, 0); + output.writeMapBegin(thrift.Thrift.Type.STRING, thrift.Thrift.Type.STRING, this.success.size); + this.success.forEach((value_41: string, key_3: string): void => { + output.writeString(key_3); + output.writeString(value_41); + }); + output.writeMapEnd(); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): ListToMapResult { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.Thrift.Type.MAP) { + const value_42: Map = new Map(); + const metadata_7: thrift.TMap = input.readMapBegin(); + const size_7: number = metadata_7.size; + for (let i_7: number = 0; i_7 < size_7; i_7++) { + const key_4: string = input.readString(); + const value_43: string = input.readString(); + value_42.set(key_4, value_43); + } + input.readMapEnd(); + _args.success = value_42; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return new ListToMapResult(_args); + } +} +export interface IFetchThingResultArgs { + success?: com_test_common.CommonStruct; +} +export class FetchThingResult { + public success?: com_test_common.CommonStruct; + constructor(args?: IFetchThingResultArgs) { + if (args != null && args.success != null) { + this.success = args.success; + } + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("FetchThingResult"); + if (this.success != null) { + output.writeFieldBegin("success", thrift.Thrift.Type.STRUCT, 0); + this.success.write(output); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): FetchThingResult { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.Thrift.Type.STRUCT) { + const value_44: com_test_common.CommonStruct = com_test_common.CommonStruct.read(input); + _args.success = value_44; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return new FetchThingResult(_args); + } +} +export interface IZipResultArgs { + success?: void; +} +export class ZipResult { + public success?: void; + constructor(args?: IZipResultArgs) { + if (args != null && args.success != null) { + this.success = args.success; + } + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("ZipResult"); + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): ZipResult { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.Thrift.Type.VOID) { + input.skip(fieldType); + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return new ZipResult(_args); + } +} +export class Client extends com_test_shared.SharedService.Client { + public _seqid: number; + public _reqs: { + [name: number]: (err: Error | object | undefined, val?: any) => void; + }; + public output: thrift.TTransport; + public protocol: new (trans: thrift.TTransport) => thrift.TProtocol; + constructor(output: thrift.TTransport, protocol: new (trans: thrift.TTransport) => thrift.TProtocol) { + super(output, protocol); + this._seqid = 0; + this._reqs = {}; + this.output = output; + this.protocol = protocol; + } + public incrementSeqId(): number { + return this._seqid += 1; + } + public ping(): Promise { + const requestId: number = this.incrementSeqId(); + return new Promise((resolve, reject): void => { + this._reqs[requestId] = (error, result) => { + delete this._reqs[requestId]; + if (error != null) { + reject(error); + } + else { + resolve(result); + } + }; + this.send_ping(requestId); + }); + } + public add(num1: number, num2: number): Promise { + const requestId: number = this.incrementSeqId(); + return new Promise((resolve, reject): void => { + this._reqs[requestId] = (error, result) => { + delete this._reqs[requestId]; + if (error != null) { + reject(error); + } + else { + resolve(result); + } + }; + this.send_add(num1, num2, requestId); + }); + } + public addInt64(num1: Int64, num2: Int64): Promise { + const requestId: number = this.incrementSeqId(); + return new Promise((resolve, reject): void => { + this._reqs[requestId] = (error, result) => { + delete this._reqs[requestId]; + if (error != null) { + reject(error); + } + else { + resolve(result); + } + }; + this.send_addInt64(num1, num2, requestId); + }); + } + public addWithContext(num1: number, num2: number): Promise { + const requestId: number = this.incrementSeqId(); + return new Promise((resolve, reject): void => { + this._reqs[requestId] = (error, result) => { + delete this._reqs[requestId]; + if (error != null) { + reject(error); + } + else { + resolve(result); + } + }; + this.send_addWithContext(num1, num2, requestId); + }); + } + public calculate(logid: number, work: __NAMESPACE__.Work): Promise { + const requestId: number = this.incrementSeqId(); + return new Promise((resolve, reject): void => { + this._reqs[requestId] = (error, result) => { + delete this._reqs[requestId]; + if (error != null) { + reject(error); + } + else { + resolve(result); + } + }; + this.send_calculate(logid, work, requestId); + }); + } + public echoBinary(word: Buffer): Promise { + const requestId: number = this.incrementSeqId(); + return new Promise((resolve, reject): void => { + this._reqs[requestId] = (error, result) => { + delete this._reqs[requestId]; + if (error != null) { + reject(error); + } + else { + resolve(result); + } + }; + this.send_echoBinary(word, requestId); + }); + } + public echoString(word: string): Promise { + const requestId: number = this.incrementSeqId(); + return new Promise((resolve, reject): void => { + this._reqs[requestId] = (error, result) => { + delete this._reqs[requestId]; + if (error != null) { + reject(error); + } + else { + resolve(result); + } + }; + this.send_echoString(word, requestId); + }); + } + public checkName(choice: __NAMESPACE__.Choice): Promise { + const requestId: number = this.incrementSeqId(); + return new Promise((resolve, reject): void => { + this._reqs[requestId] = (error, result) => { + delete this._reqs[requestId]; + if (error != null) { + reject(error); + } + else { + resolve(result); + } + }; + this.send_checkName(choice, requestId); + }); + } + public checkOptional(type?: string): Promise { + const requestId: number = this.incrementSeqId(); + return new Promise((resolve, reject): void => { + this._reqs[requestId] = (error, result) => { + delete this._reqs[requestId]; + if (error != null) { + reject(error); + } + else { + resolve(result); + } + }; + this.send_checkOptional(type, requestId); + }); + } + public mapOneList(arg: Array): Promise> { + const requestId: number = this.incrementSeqId(); + return new Promise>((resolve, reject): void => { + this._reqs[requestId] = (error, result) => { + delete this._reqs[requestId]; + if (error != null) { + reject(error); + } + else { + resolve(result); + } + }; + this.send_mapOneList(arg, requestId); + }); + } + public mapValues(arg: Map): Promise> { + const requestId: number = this.incrementSeqId(); + return new Promise>((resolve, reject): void => { + this._reqs[requestId] = (error, result) => { + delete this._reqs[requestId]; + if (error != null) { + reject(error); + } + else { + resolve(result); + } + }; + this.send_mapValues(arg, requestId); + }); + } + public listToMap(arg: Array>): Promise> { + const requestId: number = this.incrementSeqId(); + return new Promise>((resolve, reject): void => { + this._reqs[requestId] = (error, result) => { + delete this._reqs[requestId]; + if (error != null) { + reject(error); + } + else { + resolve(result); + } + }; + this.send_listToMap(arg, requestId); + }); + } + public fetchThing(): Promise { + const requestId: number = this.incrementSeqId(); + return new Promise((resolve, reject): void => { + this._reqs[requestId] = (error, result) => { + delete this._reqs[requestId]; + if (error != null) { + reject(error); + } + else { + resolve(result); + } + }; + this.send_fetchThing(requestId); + }); + } + public zip(): Promise { + const requestId: number = this.incrementSeqId(); + return new Promise((resolve, reject): void => { + this._reqs[requestId] = (error, result) => { + delete this._reqs[requestId]; + if (error != null) { + reject(error); + } + else { + resolve(result); + } + }; + this.send_zip(requestId); + }); + } + public send_ping(requestId: number): void { + const output: thrift.TProtocol = new this.protocol(this.output); + output.writeMessageBegin("ping", thrift.Thrift.MessageType.CALL, requestId); + const args: PingArgs = new PingArgs(); + args.write(output); + output.writeMessageEnd(); + this.output.flush(); + return; + } + public send_add(num1: number, num2: number, requestId: number): void { + const output: thrift.TProtocol = new this.protocol(this.output); + output.writeMessageBegin("add", thrift.Thrift.MessageType.CALL, requestId); + const args: AddArgs = new AddArgs({ num1, num2 }); + args.write(output); + output.writeMessageEnd(); + this.output.flush(); + return; + } + public send_addInt64(num1: Int64, num2: Int64, requestId: number): void { + const output: thrift.TProtocol = new this.protocol(this.output); + output.writeMessageBegin("addInt64", thrift.Thrift.MessageType.CALL, requestId); + const args: AddInt64Args = new AddInt64Args({ num1, num2 }); + args.write(output); + output.writeMessageEnd(); + this.output.flush(); + return; + } + public send_addWithContext(num1: number, num2: number, requestId: number): void { + const output: thrift.TProtocol = new this.protocol(this.output); + output.writeMessageBegin("addWithContext", thrift.Thrift.MessageType.CALL, requestId); + const args: AddWithContextArgs = new AddWithContextArgs({ num1, num2 }); + args.write(output); + output.writeMessageEnd(); + this.output.flush(); + return; + } + public send_calculate(logid: number, work: __NAMESPACE__.Work, requestId: number): void { + const output: thrift.TProtocol = new this.protocol(this.output); + output.writeMessageBegin("calculate", thrift.Thrift.MessageType.CALL, requestId); + const args: CalculateArgs = new CalculateArgs({ logid, work }); + args.write(output); + output.writeMessageEnd(); + this.output.flush(); + return; + } + public send_echoBinary(word: Buffer, requestId: number): void { + const output: thrift.TProtocol = new this.protocol(this.output); + output.writeMessageBegin("echoBinary", thrift.Thrift.MessageType.CALL, requestId); + const args: EchoBinaryArgs = new EchoBinaryArgs({ word }); + args.write(output); + output.writeMessageEnd(); + this.output.flush(); + return; + } + public send_echoString(word: string, requestId: number): void { + const output: thrift.TProtocol = new this.protocol(this.output); + output.writeMessageBegin("echoString", thrift.Thrift.MessageType.CALL, requestId); + const args: EchoStringArgs = new EchoStringArgs({ word }); + args.write(output); + output.writeMessageEnd(); + this.output.flush(); + return; + } + public send_checkName(choice: __NAMESPACE__.Choice, requestId: number): void { + const output: thrift.TProtocol = new this.protocol(this.output); + output.writeMessageBegin("checkName", thrift.Thrift.MessageType.CALL, requestId); + const args: CheckNameArgs = new CheckNameArgs({ choice }); + args.write(output); + output.writeMessageEnd(); + this.output.flush(); + return; + } + public send_checkOptional(type: string | undefined, requestId: number): void { + const output: thrift.TProtocol = new this.protocol(this.output); + output.writeMessageBegin("checkOptional", thrift.Thrift.MessageType.CALL, requestId); + const args: CheckOptionalArgs = new CheckOptionalArgs({ type }); + args.write(output); + output.writeMessageEnd(); + this.output.flush(); + return; + } + public send_mapOneList(arg: Array, requestId: number): void { + const output: thrift.TProtocol = new this.protocol(this.output); + output.writeMessageBegin("mapOneList", thrift.Thrift.MessageType.CALL, requestId); + const args: MapOneListArgs = new MapOneListArgs({ arg }); + args.write(output); + output.writeMessageEnd(); + this.output.flush(); + return; + } + public send_mapValues(arg: Map, requestId: number): void { + const output: thrift.TProtocol = new this.protocol(this.output); + output.writeMessageBegin("mapValues", thrift.Thrift.MessageType.CALL, requestId); + const args: MapValuesArgs = new MapValuesArgs({ arg }); + args.write(output); + output.writeMessageEnd(); + this.output.flush(); + return; + } + public send_listToMap(arg: Array>, requestId: number): void { + const output: thrift.TProtocol = new this.protocol(this.output); + output.writeMessageBegin("listToMap", thrift.Thrift.MessageType.CALL, requestId); + const args: ListToMapArgs = new ListToMapArgs({ arg }); + args.write(output); + output.writeMessageEnd(); + this.output.flush(); + return; + } + public send_fetchThing(requestId: number): void { + const output: thrift.TProtocol = new this.protocol(this.output); + output.writeMessageBegin("fetchThing", thrift.Thrift.MessageType.CALL, requestId); + const args: FetchThingArgs = new FetchThingArgs(); + args.write(output); + output.writeMessageEnd(); + this.output.flush(); + return; + } + public send_zip(requestId: number): void { + const output: thrift.TProtocol = new this.protocol(this.output); + output.writeMessageBegin("zip", thrift.Thrift.MessageType.CALL, requestId); + const args: ZipArgs = new ZipArgs(); + args.write(output); + output.writeMessageEnd(); + this.output.flush(); + return; + } + public recv_ping(input: thrift.TProtocol, mtype: thrift.Thrift.MessageType, requestId: number): void { + const noop = (): any => null; + const callback = this._reqs[requestId] || noop; + if (mtype === thrift.Thrift.MessageType.EXCEPTION) { + const x: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(); + x.read(input); + input.readMessageEnd(); + return callback(x); + } + else { + input.readMessageEnd(); + return callback(undefined); + } + } + public recv_add(input: thrift.TProtocol, mtype: thrift.Thrift.MessageType, requestId: number): void { + const noop = (): any => null; + const callback = this._reqs[requestId] || noop; + if (mtype === thrift.Thrift.MessageType.EXCEPTION) { + const x: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(); + x.read(input); + input.readMessageEnd(); + return callback(x); + } + else { + const result: AddResult = AddResult.read(input); + input.readMessageEnd(); + if (result.exp != null) { + return callback(result.exp); + } + else { + if (result.success != null) { + return callback(undefined, result.success); + } + else { + return callback(new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, "add failed: unknown result")); + } + } + } + } + public recv_addInt64(input: thrift.TProtocol, mtype: thrift.Thrift.MessageType, requestId: number): void { + const noop = (): any => null; + const callback = this._reqs[requestId] || noop; + if (mtype === thrift.Thrift.MessageType.EXCEPTION) { + const x: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(); + x.read(input); + input.readMessageEnd(); + return callback(x); + } + else { + const result: AddInt64Result = AddInt64Result.read(input); + input.readMessageEnd(); + if (result.exp != null) { + return callback(result.exp); + } + else { + if (result.success != null) { + return callback(undefined, result.success); + } + else { + return callback(new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, "addInt64 failed: unknown result")); + } + } + } + } + public recv_addWithContext(input: thrift.TProtocol, mtype: thrift.Thrift.MessageType, requestId: number): void { + const noop = (): any => null; + const callback = this._reqs[requestId] || noop; + if (mtype === thrift.Thrift.MessageType.EXCEPTION) { + const x: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(); + x.read(input); + input.readMessageEnd(); + return callback(x); + } + else { + const result: AddWithContextResult = AddWithContextResult.read(input); + input.readMessageEnd(); + if (result.success != null) { + return callback(undefined, result.success); + } + else { + return callback(new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, "addWithContext failed: unknown result")); + } + } + } + public recv_calculate(input: thrift.TProtocol, mtype: thrift.Thrift.MessageType, requestId: number): void { + const noop = (): any => null; + const callback = this._reqs[requestId] || noop; + if (mtype === thrift.Thrift.MessageType.EXCEPTION) { + const x: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(); + x.read(input); + input.readMessageEnd(); + return callback(x); + } + else { + const result: CalculateResult = CalculateResult.read(input); + input.readMessageEnd(); + if (result.ouch != null) { + return callback(result.ouch); + } + else { + if (result.success != null) { + return callback(undefined, result.success); + } + else { + return callback(new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, "calculate failed: unknown result")); + } + } + } + } + public recv_echoBinary(input: thrift.TProtocol, mtype: thrift.Thrift.MessageType, requestId: number): void { + const noop = (): any => null; + const callback = this._reqs[requestId] || noop; + if (mtype === thrift.Thrift.MessageType.EXCEPTION) { + const x: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(); + x.read(input); + input.readMessageEnd(); + return callback(x); + } + else { + const result: EchoBinaryResult = EchoBinaryResult.read(input); + input.readMessageEnd(); + if (result.success != null) { + return callback(undefined, result.success); + } + else { + return callback(new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, "echoBinary failed: unknown result")); + } + } + } + public recv_echoString(input: thrift.TProtocol, mtype: thrift.Thrift.MessageType, requestId: number): void { + const noop = (): any => null; + const callback = this._reqs[requestId] || noop; + if (mtype === thrift.Thrift.MessageType.EXCEPTION) { + const x: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(); + x.read(input); + input.readMessageEnd(); + return callback(x); + } + else { + const result: EchoStringResult = EchoStringResult.read(input); + input.readMessageEnd(); + if (result.success != null) { + return callback(undefined, result.success); + } + else { + return callback(new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, "echoString failed: unknown result")); + } + } + } + public recv_checkName(input: thrift.TProtocol, mtype: thrift.Thrift.MessageType, requestId: number): void { + const noop = (): any => null; + const callback = this._reqs[requestId] || noop; + if (mtype === thrift.Thrift.MessageType.EXCEPTION) { + const x: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(); + x.read(input); + input.readMessageEnd(); + return callback(x); + } + else { + const result: CheckNameResult = CheckNameResult.read(input); + input.readMessageEnd(); + if (result.success != null) { + return callback(undefined, result.success); + } + else { + return callback(new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, "checkName failed: unknown result")); + } + } + } + public recv_checkOptional(input: thrift.TProtocol, mtype: thrift.Thrift.MessageType, requestId: number): void { + const noop = (): any => null; + const callback = this._reqs[requestId] || noop; + if (mtype === thrift.Thrift.MessageType.EXCEPTION) { + const x: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(); + x.read(input); + input.readMessageEnd(); + return callback(x); + } + else { + const result: CheckOptionalResult = CheckOptionalResult.read(input); + input.readMessageEnd(); + if (result.success != null) { + return callback(undefined, result.success); + } + else { + return callback(new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, "checkOptional failed: unknown result")); + } + } + } + public recv_mapOneList(input: thrift.TProtocol, mtype: thrift.Thrift.MessageType, requestId: number): void { + const noop = (): any => null; + const callback = this._reqs[requestId] || noop; + if (mtype === thrift.Thrift.MessageType.EXCEPTION) { + const x: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(); + x.read(input); + input.readMessageEnd(); + return callback(x); + } + else { + const result: MapOneListResult = MapOneListResult.read(input); + input.readMessageEnd(); + if (result.success != null) { + return callback(undefined, result.success); + } + else { + return callback(new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, "mapOneList failed: unknown result")); + } + } + } + public recv_mapValues(input: thrift.TProtocol, mtype: thrift.Thrift.MessageType, requestId: number): void { + const noop = (): any => null; + const callback = this._reqs[requestId] || noop; + if (mtype === thrift.Thrift.MessageType.EXCEPTION) { + const x: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(); + x.read(input); + input.readMessageEnd(); + return callback(x); + } + else { + const result: MapValuesResult = MapValuesResult.read(input); + input.readMessageEnd(); + if (result.success != null) { + return callback(undefined, result.success); + } + else { + return callback(new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, "mapValues failed: unknown result")); + } + } + } + public recv_listToMap(input: thrift.TProtocol, mtype: thrift.Thrift.MessageType, requestId: number): void { + const noop = (): any => null; + const callback = this._reqs[requestId] || noop; + if (mtype === thrift.Thrift.MessageType.EXCEPTION) { + const x: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(); + x.read(input); + input.readMessageEnd(); + return callback(x); + } + else { + const result: ListToMapResult = ListToMapResult.read(input); + input.readMessageEnd(); + if (result.success != null) { + return callback(undefined, result.success); + } + else { + return callback(new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, "listToMap failed: unknown result")); + } + } + } + public recv_fetchThing(input: thrift.TProtocol, mtype: thrift.Thrift.MessageType, requestId: number): void { + const noop = (): any => null; + const callback = this._reqs[requestId] || noop; + if (mtype === thrift.Thrift.MessageType.EXCEPTION) { + const x: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(); + x.read(input); + input.readMessageEnd(); + return callback(x); + } + else { + const result: FetchThingResult = FetchThingResult.read(input); + input.readMessageEnd(); + if (result.success != null) { + return callback(undefined, result.success); + } + else { + return callback(new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, "fetchThing failed: unknown result")); + } + } + } + public recv_zip(input: thrift.TProtocol, mtype: thrift.Thrift.MessageType, requestId: number): void { + const noop = (): any => null; + const callback = this._reqs[requestId] || noop; + if (mtype === thrift.Thrift.MessageType.EXCEPTION) { + const x: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(); + x.read(input); + input.readMessageEnd(); + return callback(x); + } + else { + input.readMessageEnd(); + return callback(undefined); + } + } +} +export interface ILocalHandler { + ping(): void | Promise; + add(num1: number, num2: number): number | Promise; + addInt64(num1: Int64, num2: Int64): Int64 | Promise; + addWithContext(num1: number, num2: number): number | Promise; + calculate(logid: number, work: __NAMESPACE__.Work): number | Promise; + echoBinary(word: Buffer): string | Promise; + echoString(word: string): string | Promise; + checkName(choice: __NAMESPACE__.Choice): string | Promise; + checkOptional(type?: string): string | Promise; + mapOneList(arg: Array): Array | Promise>; + mapValues(arg: Map): Array | Promise>; + listToMap(arg: Array>): Map | Promise>; + fetchThing(): com_test_common.CommonStruct | Promise; + zip(): void | Promise; +} +export type IHandler = ILocalHandler & com_test_shared.SharedService.IHandler; +export class Processor extends com_test_shared.SharedService.Processor { + public _handler: IHandler; + constructor(handler: IHandler) { + super({ + getStruct: handler.getStruct, + getUnion: handler.getUnion + }); + this._handler = handler; + } + public process(input: thrift.TProtocol, output: thrift.TProtocol): void { + const metadata: thrift.TMessage = input.readMessageBegin(); + const fname: string = metadata.fname; + const requestId: number = metadata.rseqid; + const methodName: string = "process_" + fname; + switch (methodName) { + case "process_getStruct": { + this.process_getStruct(requestId, input, output); + return; + } + case "process_getUnion": { + this.process_getUnion(requestId, input, output); + return; + } + case "process_ping": { + this.process_ping(requestId, input, output); + return; + } + case "process_add": { + this.process_add(requestId, input, output); + return; + } + case "process_addInt64": { + this.process_addInt64(requestId, input, output); + return; + } + case "process_addWithContext": { + this.process_addWithContext(requestId, input, output); + return; + } + case "process_calculate": { + this.process_calculate(requestId, input, output); + return; + } + case "process_echoBinary": { + this.process_echoBinary(requestId, input, output); + return; + } + case "process_echoString": { + this.process_echoString(requestId, input, output); + return; + } + case "process_checkName": { + this.process_checkName(requestId, input, output); + return; + } + case "process_checkOptional": { + this.process_checkOptional(requestId, input, output); + return; + } + case "process_mapOneList": { + this.process_mapOneList(requestId, input, output); + return; + } + case "process_mapValues": { + this.process_mapValues(requestId, input, output); + return; + } + case "process_listToMap": { + this.process_listToMap(requestId, input, output); + return; + } + case "process_fetchThing": { + this.process_fetchThing(requestId, input, output); + return; + } + case "process_zip": { + this.process_zip(requestId, input, output); + return; + } + default: { + input.skip(thrift.Thrift.Type.STRUCT); + input.readMessageEnd(); + const errMessage = "Unknown function " + fname; + const err = new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN_METHOD, errMessage); + output.writeMessageBegin(fname, thrift.Thrift.MessageType.EXCEPTION, requestId); + err.write(output); + output.writeMessageEnd(); + output.flush(); + return; + } + } + } + public process_ping(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol): void { + new Promise((resolve, reject): void => { + try { + input.readMessageEnd(); + resolve(this._handler.ping()); + } + catch (err) { + reject(err); + } + }).then((data: void): void => { + const result: PingResult = new PingResult({ success: data }); + output.writeMessageBegin("ping", thrift.Thrift.MessageType.REPLY, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + }).catch((err: Error): void => { + const result: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("ping", thrift.Thrift.MessageType.EXCEPTION, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + }); + } + public process_add(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol): void { + new Promise((resolve, reject): void => { + try { + const args: AddArgs = AddArgs.read(input); + input.readMessageEnd(); + resolve(this._handler.add(args.num1, args.num2)); + } + catch (err) { + reject(err); + } + }).then((data: number): void => { + const result: AddResult = new AddResult({ success: data }); + output.writeMessageBegin("add", thrift.Thrift.MessageType.REPLY, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + }).catch((err: Error): void => { + if (err instanceof com_test_operation.JankyResult) { + const result: AddResult = new AddResult({ exp: err }); + output.writeMessageBegin("add", thrift.Thrift.MessageType.REPLY, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + } + else { + const result: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("add", thrift.Thrift.MessageType.EXCEPTION, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + } + }); + } + public process_addInt64(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol): void { + new Promise((resolve, reject): void => { + try { + const args: AddInt64Args = AddInt64Args.read(input); + input.readMessageEnd(); + resolve(this._handler.addInt64(args.num1, args.num2)); + } + catch (err) { + reject(err); + } + }).then((data: Int64): void => { + const result: AddInt64Result = new AddInt64Result({ success: data }); + output.writeMessageBegin("addInt64", thrift.Thrift.MessageType.REPLY, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + }).catch((err: Error): void => { + if (err instanceof __NAMESPACE__.NotAGoodIdea) { + const result: AddInt64Result = new AddInt64Result({ exp: err }); + output.writeMessageBegin("addInt64", thrift.Thrift.MessageType.REPLY, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + } + else { + const result: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("addInt64", thrift.Thrift.MessageType.EXCEPTION, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + } + }); + } + public process_addWithContext(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol): void { + new Promise((resolve, reject): void => { + try { + const args: AddWithContextArgs = AddWithContextArgs.read(input); + input.readMessageEnd(); + resolve(this._handler.addWithContext(args.num1, args.num2)); + } + catch (err) { + reject(err); + } + }).then((data: number): void => { + const result: AddWithContextResult = new AddWithContextResult({ success: data }); + output.writeMessageBegin("addWithContext", thrift.Thrift.MessageType.REPLY, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + }).catch((err: Error): void => { + const result: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("addWithContext", thrift.Thrift.MessageType.EXCEPTION, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + }); + } + public process_calculate(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol): void { + new Promise((resolve, reject): void => { + try { + const args: CalculateArgs = CalculateArgs.read(input); + input.readMessageEnd(); + resolve(this._handler.calculate(args.logid, args.work)); + } + catch (err) { + reject(err); + } + }).then((data: number): void => { + const result: CalculateResult = new CalculateResult({ success: data }); + output.writeMessageBegin("calculate", thrift.Thrift.MessageType.REPLY, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + }).catch((err: Error): void => { + if (err instanceof com_test_operation.JankyOperation) { + const result: CalculateResult = new CalculateResult({ ouch: err }); + output.writeMessageBegin("calculate", thrift.Thrift.MessageType.REPLY, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + } + else { + const result: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("calculate", thrift.Thrift.MessageType.EXCEPTION, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + } + }); + } + public process_echoBinary(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol): void { + new Promise((resolve, reject): void => { + try { + const args: EchoBinaryArgs = EchoBinaryArgs.read(input); + input.readMessageEnd(); + resolve(this._handler.echoBinary(args.word)); + } + catch (err) { + reject(err); + } + }).then((data: string): void => { + const result: EchoBinaryResult = new EchoBinaryResult({ success: data }); + output.writeMessageBegin("echoBinary", thrift.Thrift.MessageType.REPLY, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + }).catch((err: Error): void => { + const result: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("echoBinary", thrift.Thrift.MessageType.EXCEPTION, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + }); + } + public process_echoString(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol): void { + new Promise((resolve, reject): void => { + try { + const args: EchoStringArgs = EchoStringArgs.read(input); + input.readMessageEnd(); + resolve(this._handler.echoString(args.word)); + } + catch (err) { + reject(err); + } + }).then((data: string): void => { + const result: EchoStringResult = new EchoStringResult({ success: data }); + output.writeMessageBegin("echoString", thrift.Thrift.MessageType.REPLY, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + }).catch((err: Error): void => { + const result: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("echoString", thrift.Thrift.MessageType.EXCEPTION, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + }); + } + public process_checkName(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol): void { + new Promise((resolve, reject): void => { + try { + const args: CheckNameArgs = CheckNameArgs.read(input); + input.readMessageEnd(); + resolve(this._handler.checkName(args.choice)); + } + catch (err) { + reject(err); + } + }).then((data: string): void => { + const result: CheckNameResult = new CheckNameResult({ success: data }); + output.writeMessageBegin("checkName", thrift.Thrift.MessageType.REPLY, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + }).catch((err: Error): void => { + const result: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("checkName", thrift.Thrift.MessageType.EXCEPTION, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + }); + } + public process_checkOptional(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol): void { + new Promise((resolve, reject): void => { + try { + const args: CheckOptionalArgs = CheckOptionalArgs.read(input); + input.readMessageEnd(); + resolve(this._handler.checkOptional(args.type)); + } + catch (err) { + reject(err); + } + }).then((data: string): void => { + const result: CheckOptionalResult = new CheckOptionalResult({ success: data }); + output.writeMessageBegin("checkOptional", thrift.Thrift.MessageType.REPLY, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + }).catch((err: Error): void => { + const result: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("checkOptional", thrift.Thrift.MessageType.EXCEPTION, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + }); + } + public process_mapOneList(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol): void { + new Promise>((resolve, reject): void => { + try { + const args: MapOneListArgs = MapOneListArgs.read(input); + input.readMessageEnd(); + resolve(this._handler.mapOneList(args.arg)); + } + catch (err) { + reject(err); + } + }).then((data: Array): void => { + const result: MapOneListResult = new MapOneListResult({ success: data }); + output.writeMessageBegin("mapOneList", thrift.Thrift.MessageType.REPLY, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + }).catch((err: Error): void => { + const result: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("mapOneList", thrift.Thrift.MessageType.EXCEPTION, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + }); + } + public process_mapValues(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol): void { + new Promise>((resolve, reject): void => { + try { + const args: MapValuesArgs = MapValuesArgs.read(input); + input.readMessageEnd(); + resolve(this._handler.mapValues(args.arg)); + } + catch (err) { + reject(err); + } + }).then((data: Array): void => { + const result: MapValuesResult = new MapValuesResult({ success: data }); + output.writeMessageBegin("mapValues", thrift.Thrift.MessageType.REPLY, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + }).catch((err: Error): void => { + const result: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("mapValues", thrift.Thrift.MessageType.EXCEPTION, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + }); + } + public process_listToMap(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol): void { + new Promise>((resolve, reject): void => { + try { + const args: ListToMapArgs = ListToMapArgs.read(input); + input.readMessageEnd(); + resolve(this._handler.listToMap(args.arg)); + } + catch (err) { + reject(err); + } + }).then((data: Map): void => { + const result: ListToMapResult = new ListToMapResult({ success: data }); + output.writeMessageBegin("listToMap", thrift.Thrift.MessageType.REPLY, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + }).catch((err: Error): void => { + const result: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("listToMap", thrift.Thrift.MessageType.EXCEPTION, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + }); + } + public process_fetchThing(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol): void { + new Promise((resolve, reject): void => { + try { + input.readMessageEnd(); + resolve(this._handler.fetchThing()); + } + catch (err) { + reject(err); + } + }).then((data: com_test_common.CommonStruct): void => { + const result: FetchThingResult = new FetchThingResult({ success: data }); + output.writeMessageBegin("fetchThing", thrift.Thrift.MessageType.REPLY, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + }).catch((err: Error): void => { + const result: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("fetchThing", thrift.Thrift.MessageType.EXCEPTION, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + }); + } + public process_zip(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol): void { + new Promise((resolve, reject): void => { + try { + input.readMessageEnd(); + resolve(this._handler.zip()); + } + catch (err) { + reject(err); + } + }).then((data: void): void => { + const result: ZipResult = new ZipResult({ success: data }); + output.writeMessageBegin("zip", thrift.Thrift.MessageType.REPLY, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + }).catch((err: Error): void => { + const result: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("zip", thrift.Thrift.MessageType.EXCEPTION, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + }); + } +} diff --git a/src/tests/unit/fixtures/apache/generated/com/test/calculator/Choice.ts b/src/tests/unit/fixtures/apache/generated/com/test/calculator/Choice.ts new file mode 100644 index 00000000..71d31209 --- /dev/null +++ b/src/tests/unit/fixtures/apache/generated/com/test/calculator/Choice.ts @@ -0,0 +1,108 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as thrift from "test-lib"; +import * as __NAMESPACE__ from "./."; +export interface IChoiceArgs { + firstName?: __NAMESPACE__.FirstName; + lastName?: __NAMESPACE__.LastName; +} +export class Choice { + public firstName?: __NAMESPACE__.FirstName; + public lastName?: __NAMESPACE__.LastName; + constructor(args?: IChoiceArgs) { + let _fieldsSet: number = 0; + if (args != null) { + if (args.firstName != null) { + _fieldsSet++; + this.firstName = args.firstName; + } + if (args.lastName != null) { + _fieldsSet++; + this.lastName = args.lastName; + } + if (_fieldsSet > 1) { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.INVALID_DATA, "Cannot read a TUnion with more than one set value!"); + } + else if (_fieldsSet < 1) { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.INVALID_DATA, "Cannot read a TUnion with no set value!"); + } + } + } + public static fromFirstName(firstName: __NAMESPACE__.FirstName): Choice { + return new Choice({ firstName }); + } + public static fromLastName(lastName: __NAMESPACE__.LastName): Choice { + return new Choice({ lastName }); + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("Choice"); + if (this.firstName != null) { + output.writeFieldBegin("firstName", thrift.Thrift.Type.STRUCT, 1); + this.firstName.write(output); + output.writeFieldEnd(); + } + if (this.lastName != null) { + output.writeFieldBegin("lastName", thrift.Thrift.Type.STRUCT, 2); + this.lastName.write(output); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): Choice { + let _fieldsSet: number = 0; + let _returnValue: Choice | null = null; + input.readStructBegin(); + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.Thrift.Type.STRUCT) { + _fieldsSet++; + const value_1: __NAMESPACE__.FirstName = __NAMESPACE__.FirstName.read(input); + _returnValue = Choice.fromFirstName(value_1); + } + else { + input.skip(fieldType); + } + break; + case 2: + if (fieldType === thrift.Thrift.Type.STRUCT) { + _fieldsSet++; + const value_2: __NAMESPACE__.LastName = __NAMESPACE__.LastName.read(input); + _returnValue = Choice.fromLastName(value_2); + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_fieldsSet > 1) { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.INVALID_DATA, "Cannot read a TUnion with more than one set value!"); + } + else if (_fieldsSet < 1) { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.INVALID_DATA, "Cannot read a TUnion with no set value!"); + } + if (_returnValue !== null) { + return _returnValue; + } + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Unable to read data for TUnion"); + } + } +} diff --git a/src/tests/unit/fixtures/apache/generated/com/test/calculator/FirstName.ts b/src/tests/unit/fixtures/apache/generated/com/test/calculator/FirstName.ts new file mode 100644 index 00000000..f8f032e0 --- /dev/null +++ b/src/tests/unit/fixtures/apache/generated/com/test/calculator/FirstName.ts @@ -0,0 +1,57 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as thrift from "test-lib"; +export interface IFirstNameArgs { + name?: string; +} +export class FirstName { + public name?: string; + constructor(args?: IFirstNameArgs) { + if (args != null && args.name != null) { + this.name = args.name; + } + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("FirstName"); + if (this.name != null) { + output.writeFieldBegin("name", thrift.Thrift.Type.STRING, 1); + output.writeString(this.name); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): FirstName { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.Thrift.Type.STRING) { + const value_1: string = input.readString(); + _args.name = value_1; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return new FirstName(_args); + } +} diff --git a/src/tests/unit/fixtures/apache/generated/com/test/calculator/LastName.ts b/src/tests/unit/fixtures/apache/generated/com/test/calculator/LastName.ts new file mode 100644 index 00000000..311ab8ea --- /dev/null +++ b/src/tests/unit/fixtures/apache/generated/com/test/calculator/LastName.ts @@ -0,0 +1,57 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as thrift from "test-lib"; +export interface ILastNameArgs { + name?: string; +} +export class LastName { + public name?: string; + constructor(args?: ILastNameArgs) { + if (args != null && args.name != null) { + this.name = args.name; + } + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("LastName"); + if (this.name != null) { + output.writeFieldBegin("name", thrift.Thrift.Type.STRING, 1); + output.writeString(this.name); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): LastName { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.Thrift.Type.STRING) { + const value_1: string = input.readString(); + _args.name = value_1; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return new LastName(_args); + } +} diff --git a/src/tests/unit/fixtures/apache/generated/com/test/calculator/NotAGoodIdea.ts b/src/tests/unit/fixtures/apache/generated/com/test/calculator/NotAGoodIdea.ts new file mode 100644 index 00000000..c0c6ceec --- /dev/null +++ b/src/tests/unit/fixtures/apache/generated/com/test/calculator/NotAGoodIdea.ts @@ -0,0 +1,57 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as thrift from "test-lib"; +export interface INotAGoodIdeaArgs { + message?: string; +} +export class NotAGoodIdea { + public message?: string; + constructor(args?: INotAGoodIdeaArgs) { + if (args != null && args.message != null) { + this.message = args.message; + } + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("NotAGoodIdea"); + if (this.message != null) { + output.writeFieldBegin("message", thrift.Thrift.Type.STRING, 1); + output.writeString(this.message); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): NotAGoodIdea { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.Thrift.Type.STRING) { + const value_1: string = input.readString(); + _args.message = value_1; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return new NotAGoodIdea(_args); + } +} diff --git a/src/tests/unit/fixtures/apache/generated/com/test/calculator/Work.ts b/src/tests/unit/fixtures/apache/generated/com/test/calculator/Work.ts new file mode 100644 index 00000000..ce8af774 --- /dev/null +++ b/src/tests/unit/fixtures/apache/generated/com/test/calculator/Work.ts @@ -0,0 +1,126 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as thrift from "test-lib"; +import * as __NAMESPACE__ from "./."; +export interface IWorkArgs { + num1: number; + num2: number; + op?: __NAMESPACE__.Operation; + comment?: string; +} +export class Work { + public num1: number = 0; + public num2: number; + public op?: __NAMESPACE__.Operation = __NAMESPACE__.Operation.ADD; + public comment?: string; + constructor(args: IWorkArgs) { + if (args != null && args.num1 != null) { + this.num1 = args.num1; + } + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Required field[num1] is unset!"); + } + if (args != null && args.num2 != null) { + this.num2 = args.num2; + } + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Required field[num2] is unset!"); + } + if (args != null && args.op != null) { + this.op = args.op; + } + if (args != null && args.comment != null) { + this.comment = args.comment; + } + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("Work"); + if (this.num1 != null) { + output.writeFieldBegin("num1", thrift.Thrift.Type.I32, 1); + output.writeI32(this.num1); + output.writeFieldEnd(); + } + if (this.num2 != null) { + output.writeFieldBegin("num2", thrift.Thrift.Type.I32, 2); + output.writeI32(this.num2); + output.writeFieldEnd(); + } + if (this.op != null) { + output.writeFieldBegin("op", thrift.Thrift.Type.I32, 3); + output.writeI32(this.op); + output.writeFieldEnd(); + } + if (this.comment != null) { + output.writeFieldBegin("comment", thrift.Thrift.Type.STRING, 4); + output.writeString(this.comment); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): Work { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.Thrift.Type.I32) { + const value_1: number = input.readI32(); + _args.num1 = value_1; + } + else { + input.skip(fieldType); + } + break; + case 2: + if (fieldType === thrift.Thrift.Type.I32) { + const value_2: number = input.readI32(); + _args.num2 = value_2; + } + else { + input.skip(fieldType); + } + break; + case 3: + if (fieldType === thrift.Thrift.Type.I32) { + const value_3: __NAMESPACE__.Operation = input.readI32(); + _args.op = value_3; + } + else { + input.skip(fieldType); + } + break; + case 4: + if (fieldType === thrift.Thrift.Type.STRING) { + const value_4: string = input.readString(); + _args.comment = value_4; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.num1 !== undefined && _args.num2 !== undefined) { + return new Work(_args); + } + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Unable to read Work from input"); + } + } +} diff --git a/src/tests/unit/fixtures/apache/generated/com/test/calculator/constants.ts b/src/tests/unit/fixtures/apache/generated/com/test/calculator/constants.ts new file mode 100644 index 00000000..e023784e --- /dev/null +++ b/src/tests/unit/fixtures/apache/generated/com/test/calculator/constants.ts @@ -0,0 +1,7 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +export const INT32CONSTANT: number = 9853; +export const MAPCONSTANT: Map = new Map([["hello", "world"], ["goodnight", "moon"]]); diff --git a/src/tests/unit/fixtures/apache/generated/com/test/calculator/index.ts b/src/tests/unit/fixtures/apache/generated/com/test/calculator/index.ts new file mode 100644 index 00000000..6c07a209 --- /dev/null +++ b/src/tests/unit/fixtures/apache/generated/com/test/calculator/index.ts @@ -0,0 +1,14 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +export * from "./constants"; +export * from "./typedefs"; +export * from "./Work"; +export * from "./FirstName"; +export * from "./LastName"; +export * from "./Choice"; +export * from "./NotAGoodIdea"; +import * as Calculator from "./Calculator"; +export { Calculator as Calculator }; diff --git a/src/tests/unit/fixtures/apache/generated/com/test/calculator/typedefs.ts b/src/tests/unit/fixtures/apache/generated/com/test/calculator/typedefs.ts new file mode 100644 index 00000000..308abf50 --- /dev/null +++ b/src/tests/unit/fixtures/apache/generated/com/test/calculator/typedefs.ts @@ -0,0 +1,10 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as com_test_operation from "./../operation"; +import * as com_test_common from "./../common"; +export type MyInteger = number; +export import Operation = com_test_operation.Operation; +export import CommonStruct = com_test_common.CommonStruct; diff --git a/src/tests/unit/fixtures/apache/generated/com/test/common/AuthException.ts b/src/tests/unit/fixtures/apache/generated/com/test/common/AuthException.ts new file mode 100644 index 00000000..4d04a7ba --- /dev/null +++ b/src/tests/unit/fixtures/apache/generated/com/test/common/AuthException.ts @@ -0,0 +1,76 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as thrift from "test-lib"; +export interface IAuthExceptionArgs { + code?: number; + message?: string; +} +export class AuthException { + public code?: number; + public message?: string; + constructor(args?: IAuthExceptionArgs) { + if (args != null && args.code != null) { + this.code = args.code; + } + if (args != null && args.message != null) { + this.message = args.message; + } + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("AuthException"); + if (this.code != null) { + output.writeFieldBegin("code", thrift.Thrift.Type.I32, 1); + output.writeI32(this.code); + output.writeFieldEnd(); + } + if (this.message != null) { + output.writeFieldBegin("message", thrift.Thrift.Type.STRING, 2); + output.writeString(this.message); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): AuthException { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.Thrift.Type.I32) { + const value_1: number = input.readI32(); + _args.code = value_1; + } + else { + input.skip(fieldType); + } + break; + case 2: + if (fieldType === thrift.Thrift.Type.STRING) { + const value_2: string = input.readString(); + _args.message = value_2; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return new AuthException(_args); + } +} diff --git a/src/tests/unit/fixtures/apache/generated/com/test/common/OtherCommonUnion.ts b/src/tests/unit/fixtures/apache/generated/com/test/common/OtherCommonUnion.ts new file mode 100644 index 00000000..deef7938 --- /dev/null +++ b/src/tests/unit/fixtures/apache/generated/com/test/common/OtherCommonUnion.ts @@ -0,0 +1,107 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v3.3.4 + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as thrift from "test-lib"; +export interface IOtherCommonUnionArgs { + option1?: string; + option2?: number; +} +export class OtherCommonUnion { + public option1?: string; + public option2?: number; + constructor(args?: IOtherCommonUnionArgs) { + let _fieldsSet: number = 0; + if (args != null) { + if (args.option1 != null) { + _fieldsSet++; + this.option1 = args.option1; + } + if (args.option2 != null) { + _fieldsSet++; + this.option2 = args.option2; + } + if (_fieldsSet > 1) { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.INVALID_DATA, "Cannot read a TUnion with more than one set value!"); + } + else if (_fieldsSet < 1) { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.INVALID_DATA, "Cannot read a TUnion with no set value!"); + } + } + } + public static fromOption1(option1: string): OtherCommonUnion { + return new OtherCommonUnion({ option1 }); + } + public static fromOption2(option2: number): OtherCommonUnion { + return new OtherCommonUnion({ option2 }); + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("OtherCommonUnion"); + if (this.option1 != null) { + output.writeFieldBegin("option1", thrift.Thrift.Type.STRING, 1); + output.writeString(this.option1); + output.writeFieldEnd(); + } + if (this.option2 != null) { + output.writeFieldBegin("option2", thrift.Thrift.Type.I32, 2); + output.writeI32(this.option2); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): OtherCommonUnion { + let _fieldsSet: number = 0; + let _returnValue: OtherCommonUnion | null = null; + input.readStructBegin(); + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.Thrift.Type.STRING) { + _fieldsSet++; + const value_1: string = input.readString(); + _returnValue = OtherCommonUnion.fromOption1(value_1); + } + else { + input.skip(fieldType); + } + break; + case 2: + if (fieldType === thrift.Thrift.Type.I32) { + _fieldsSet++; + const value_2: number = input.readI32(); + _returnValue = OtherCommonUnion.fromOption2(value_2); + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_fieldsSet > 1) { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.INVALID_DATA, "Cannot read a TUnion with more than one set value!"); + } + else if (_fieldsSet < 1) { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.INVALID_DATA, "Cannot read a TUnion with no set value!"); + } + if (_returnValue !== null) { + return _returnValue; + } + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Unable to read data for TUnion"); + } + } +} diff --git a/src/tests/unit/fixtures/apache/generated/com/test/common/index.ts b/src/tests/unit/fixtures/apache/generated/com/test/common/index.ts new file mode 100644 index 00000000..230e2538 --- /dev/null +++ b/src/tests/unit/fixtures/apache/generated/com/test/common/index.ts @@ -0,0 +1,8 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +export * from "./typedefs"; +export * from "./OtherCommonUnion"; +export * from "./AuthException"; diff --git a/src/tests/unit/fixtures/apache/generated/com/test/common/typedefs.ts b/src/tests/unit/fixtures/apache/generated/com/test/common/typedefs.ts new file mode 100644 index 00000000..5db587a5 --- /dev/null +++ b/src/tests/unit/fixtures/apache/generated/com/test/common/typedefs.ts @@ -0,0 +1,12 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as com_test_shared from "./../shared"; +import * as __NAMESPACE__ from "./."; +export import CommonStruct = com_test_shared.SharedStruct; +export import CommonUnion = com_test_shared.SharedUnion; +export import COMMON_INT = com_test_shared.SHARED_INT; +export import NotAllowed = __NAMESPACE__.AuthException; +export import MoreOptions = __NAMESPACE__.OtherCommonUnion; diff --git a/src/tests/unit/fixtures/apache/generated/com/test/exceptions/InvalidOperation.ts b/src/tests/unit/fixtures/apache/generated/com/test/exceptions/InvalidOperation.ts new file mode 100644 index 00000000..226a78c1 --- /dev/null +++ b/src/tests/unit/fixtures/apache/generated/com/test/exceptions/InvalidOperation.ts @@ -0,0 +1,76 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as thrift from "test-lib"; +export interface IInvalidOperationArgs { + whatOp?: number; + why?: string; +} +export class InvalidOperation { + public whatOp?: number; + public why?: string; + constructor(args?: IInvalidOperationArgs) { + if (args != null && args.whatOp != null) { + this.whatOp = args.whatOp; + } + if (args != null && args.why != null) { + this.why = args.why; + } + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("InvalidOperation"); + if (this.whatOp != null) { + output.writeFieldBegin("whatOp", thrift.Thrift.Type.I32, 1); + output.writeI32(this.whatOp); + output.writeFieldEnd(); + } + if (this.why != null) { + output.writeFieldBegin("why", thrift.Thrift.Type.STRING, 2); + output.writeString(this.why); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): InvalidOperation { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.Thrift.Type.I32) { + const value_1: number = input.readI32(); + _args.whatOp = value_1; + } + else { + input.skip(fieldType); + } + break; + case 2: + if (fieldType === thrift.Thrift.Type.STRING) { + const value_2: string = input.readString(); + _args.why = value_2; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return new InvalidOperation(_args); + } +} diff --git a/src/tests/unit/fixtures/apache/generated/com/test/exceptions/InvalidResult.ts b/src/tests/unit/fixtures/apache/generated/com/test/exceptions/InvalidResult.ts new file mode 100644 index 00000000..7c0d3ce1 --- /dev/null +++ b/src/tests/unit/fixtures/apache/generated/com/test/exceptions/InvalidResult.ts @@ -0,0 +1,77 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as thrift from "test-lib"; +import * as com_test_shared from "./../shared"; +export interface IInvalidResultArgs { + message?: string; + code?: com_test_shared.Code; +} +export class InvalidResult { + public message?: string; + public code?: com_test_shared.Code; + constructor(args?: IInvalidResultArgs) { + if (args != null && args.message != null) { + this.message = args.message; + } + if (args != null && args.code != null) { + this.code = args.code; + } + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("InvalidResult"); + if (this.message != null) { + output.writeFieldBegin("message", thrift.Thrift.Type.STRING, 1); + output.writeString(this.message); + output.writeFieldEnd(); + } + if (this.code != null) { + output.writeFieldBegin("code", thrift.Thrift.Type.STRUCT, 2); + this.code.write(output); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): InvalidResult { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.Thrift.Type.STRING) { + const value_1: string = input.readString(); + _args.message = value_1; + } + else { + input.skip(fieldType); + } + break; + case 2: + if (fieldType === thrift.Thrift.Type.STRUCT) { + const value_2: com_test_shared.Code = com_test_shared.Code.read(input); + _args.code = value_2; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return new InvalidResult(_args); + } +} diff --git a/src/tests/unit/fixtures/apache/generated/com/test/exceptions/index.ts b/src/tests/unit/fixtures/apache/generated/com/test/exceptions/index.ts new file mode 100644 index 00000000..c172cc5f --- /dev/null +++ b/src/tests/unit/fixtures/apache/generated/com/test/exceptions/index.ts @@ -0,0 +1,7 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +export * from "./InvalidOperation"; +export * from "./InvalidResult"; diff --git a/src/tests/unit/fixtures/apache/generated/com/test/operation/constants.ts b/src/tests/unit/fixtures/apache/generated/com/test/operation/constants.ts new file mode 100644 index 00000000..292a3004 --- /dev/null +++ b/src/tests/unit/fixtures/apache/generated/com/test/operation/constants.ts @@ -0,0 +1,11 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +export enum Operation { + ADD = 1, + SUBTRACT = 2, + MULTIPLY = 3, + DIVIDE = 4 +} diff --git a/src/tests/unit/fixtures/apache/generated/com/test/operation/index.ts b/src/tests/unit/fixtures/apache/generated/com/test/operation/index.ts new file mode 100644 index 00000000..1c98c541 --- /dev/null +++ b/src/tests/unit/fixtures/apache/generated/com/test/operation/index.ts @@ -0,0 +1,7 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +export * from "./constants"; +export * from "./typedefs"; diff --git a/src/tests/unit/fixtures/apache/generated/com/test/operation/typedefs.ts b/src/tests/unit/fixtures/apache/generated/com/test/operation/typedefs.ts new file mode 100644 index 00000000..d56f4eda --- /dev/null +++ b/src/tests/unit/fixtures/apache/generated/com/test/operation/typedefs.ts @@ -0,0 +1,10 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as com_test_exceptions from "./../exceptions"; +import * as __NAMESPACE__ from "./."; +export import JankyOperation = com_test_exceptions.InvalidOperation; +export import JankyResult = com_test_exceptions.InvalidResult; +export import SomethingToDo = __NAMESPACE__.Operation; diff --git a/src/tests/unit/fixtures/apache/generated/com/test/shared/Code.ts b/src/tests/unit/fixtures/apache/generated/com/test/shared/Code.ts new file mode 100644 index 00000000..23fea9b9 --- /dev/null +++ b/src/tests/unit/fixtures/apache/generated/com/test/shared/Code.ts @@ -0,0 +1,63 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import Int64 = require("node-int64"); +import * as thrift from "test-lib"; +export interface ICodeArgs { + status?: number | Int64; +} +export class Code { + public status?: Int64; + constructor(args?: ICodeArgs) { + if (args != null && args.status != null) { + if (typeof args.status === "number") { + this.status = new Int64(args.status); + } + else { + this.status = args.status; + } + } + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("Code"); + if (this.status != null) { + output.writeFieldBegin("status", thrift.Thrift.Type.I64, 1); + output.writeI64(this.status); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): Code { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.Thrift.Type.I64) { + const value_1: Int64 = input.readI64(); + _args.status = value_1; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return new Code(_args); + } +} diff --git a/src/tests/unit/fixtures/apache/generated/com/test/shared/SharedService.ts b/src/tests/unit/fixtures/apache/generated/com/test/shared/SharedService.ts new file mode 100644 index 00000000..9d998fe1 --- /dev/null +++ b/src/tests/unit/fixtures/apache/generated/com/test/shared/SharedService.ts @@ -0,0 +1,421 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as thrift from "test-lib"; +import * as __NAMESPACE__ from "./."; +export interface IGetStructArgsArgs { + key: number; +} +export class GetStructArgs { + public key: number; + constructor(args: IGetStructArgsArgs) { + if (args != null && args.key != null) { + this.key = args.key; + } + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Required field[key] is unset!"); + } + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("GetStructArgs"); + if (this.key != null) { + output.writeFieldBegin("key", thrift.Thrift.Type.I32, 1); + output.writeI32(this.key); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): GetStructArgs { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.Thrift.Type.I32) { + const value_1: number = input.readI32(); + _args.key = value_1; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.key !== undefined) { + return new GetStructArgs(_args); + } + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Unable to read GetStructArgs from input"); + } + } +} +export interface IGetUnionArgsArgs { + index: number; +} +export class GetUnionArgs { + public index: number; + constructor(args: IGetUnionArgsArgs) { + if (args != null && args.index != null) { + this.index = args.index; + } + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Required field[index] is unset!"); + } + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("GetUnionArgs"); + if (this.index != null) { + output.writeFieldBegin("index", thrift.Thrift.Type.I32, 1); + output.writeI32(this.index); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): GetUnionArgs { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.Thrift.Type.I32) { + const value_2: number = input.readI32(); + _args.index = value_2; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.index !== undefined) { + return new GetUnionArgs(_args); + } + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Unable to read GetUnionArgs from input"); + } + } +} +export interface IGetStructResultArgs { + success?: __NAMESPACE__.SharedStruct; +} +export class GetStructResult { + public success?: __NAMESPACE__.SharedStruct; + constructor(args?: IGetStructResultArgs) { + if (args != null && args.success != null) { + this.success = args.success; + } + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("GetStructResult"); + if (this.success != null) { + output.writeFieldBegin("success", thrift.Thrift.Type.STRUCT, 0); + this.success.write(output); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): GetStructResult { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.Thrift.Type.STRUCT) { + const value_3: __NAMESPACE__.SharedStruct = __NAMESPACE__.SharedStruct.read(input); + _args.success = value_3; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return new GetStructResult(_args); + } +} +export interface IGetUnionResultArgs { + success?: __NAMESPACE__.SharedUnion; +} +export class GetUnionResult { + public success?: __NAMESPACE__.SharedUnion; + constructor(args?: IGetUnionResultArgs) { + if (args != null && args.success != null) { + this.success = args.success; + } + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("GetUnionResult"); + if (this.success != null) { + output.writeFieldBegin("success", thrift.Thrift.Type.STRUCT, 0); + this.success.write(output); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): GetUnionResult { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.Thrift.Type.STRUCT) { + const value_4: __NAMESPACE__.SharedUnion = __NAMESPACE__.SharedUnion.read(input); + _args.success = value_4; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return new GetUnionResult(_args); + } +} +export class Client { + public _seqid: number; + public _reqs: { + [name: number]: (err: Error | object | undefined, val?: any) => void; + }; + public output: thrift.TTransport; + public protocol: new (trans: thrift.TTransport) => thrift.TProtocol; + constructor(output: thrift.TTransport, protocol: new (trans: thrift.TTransport) => thrift.TProtocol) { + this._seqid = 0; + this._reqs = {}; + this.output = output; + this.protocol = protocol; + } + public incrementSeqId(): number { + return this._seqid += 1; + } + public getStruct(key: number): Promise<__NAMESPACE__.SharedStruct> { + const requestId: number = this.incrementSeqId(); + return new Promise<__NAMESPACE__.SharedStruct>((resolve, reject): void => { + this._reqs[requestId] = (error, result) => { + delete this._reqs[requestId]; + if (error != null) { + reject(error); + } + else { + resolve(result); + } + }; + this.send_getStruct(key, requestId); + }); + } + public getUnion(index: number): Promise<__NAMESPACE__.SharedUnion> { + const requestId: number = this.incrementSeqId(); + return new Promise<__NAMESPACE__.SharedUnion>((resolve, reject): void => { + this._reqs[requestId] = (error, result) => { + delete this._reqs[requestId]; + if (error != null) { + reject(error); + } + else { + resolve(result); + } + }; + this.send_getUnion(index, requestId); + }); + } + public send_getStruct(key: number, requestId: number): void { + const output: thrift.TProtocol = new this.protocol(this.output); + output.writeMessageBegin("getStruct", thrift.Thrift.MessageType.CALL, requestId); + const args: GetStructArgs = new GetStructArgs({ key }); + args.write(output); + output.writeMessageEnd(); + this.output.flush(); + return; + } + public send_getUnion(index: number, requestId: number): void { + const output: thrift.TProtocol = new this.protocol(this.output); + output.writeMessageBegin("getUnion", thrift.Thrift.MessageType.CALL, requestId); + const args: GetUnionArgs = new GetUnionArgs({ index }); + args.write(output); + output.writeMessageEnd(); + this.output.flush(); + return; + } + public recv_getStruct(input: thrift.TProtocol, mtype: thrift.Thrift.MessageType, requestId: number): void { + const noop = (): any => null; + const callback = this._reqs[requestId] || noop; + if (mtype === thrift.Thrift.MessageType.EXCEPTION) { + const x: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(); + x.read(input); + input.readMessageEnd(); + return callback(x); + } + else { + const result: GetStructResult = GetStructResult.read(input); + input.readMessageEnd(); + if (result.success != null) { + return callback(undefined, result.success); + } + else { + return callback(new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, "getStruct failed: unknown result")); + } + } + } + public recv_getUnion(input: thrift.TProtocol, mtype: thrift.Thrift.MessageType, requestId: number): void { + const noop = (): any => null; + const callback = this._reqs[requestId] || noop; + if (mtype === thrift.Thrift.MessageType.EXCEPTION) { + const x: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(); + x.read(input); + input.readMessageEnd(); + return callback(x); + } + else { + const result: GetUnionResult = GetUnionResult.read(input); + input.readMessageEnd(); + if (result.success != null) { + return callback(undefined, result.success); + } + else { + return callback(new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, "getUnion failed: unknown result")); + } + } + } +} +export interface IHandler { + getStruct(key: number): __NAMESPACE__.SharedStruct | Promise<__NAMESPACE__.SharedStruct>; + getUnion(index: number): __NAMESPACE__.SharedUnion | Promise<__NAMESPACE__.SharedUnion>; +} +export class Processor { + public _handler: IHandler; + constructor(handler: IHandler) { + this._handler = handler; + } + public process(input: thrift.TProtocol, output: thrift.TProtocol): void { + const metadata: thrift.TMessage = input.readMessageBegin(); + const fname: string = metadata.fname; + const requestId: number = metadata.rseqid; + const methodName: string = "process_" + fname; + switch (methodName) { + case "process_getStruct": { + this.process_getStruct(requestId, input, output); + return; + } + case "process_getUnion": { + this.process_getUnion(requestId, input, output); + return; + } + default: { + input.skip(thrift.Thrift.Type.STRUCT); + input.readMessageEnd(); + const errMessage = "Unknown function " + fname; + const err = new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN_METHOD, errMessage); + output.writeMessageBegin(fname, thrift.Thrift.MessageType.EXCEPTION, requestId); + err.write(output); + output.writeMessageEnd(); + output.flush(); + return; + } + } + } + public process_getStruct(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol): void { + new Promise<__NAMESPACE__.SharedStruct>((resolve, reject): void => { + try { + const args: GetStructArgs = GetStructArgs.read(input); + input.readMessageEnd(); + resolve(this._handler.getStruct(args.key)); + } + catch (err) { + reject(err); + } + }).then((data: __NAMESPACE__.SharedStruct): void => { + const result: GetStructResult = new GetStructResult({ success: data }); + output.writeMessageBegin("getStruct", thrift.Thrift.MessageType.REPLY, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + }).catch((err: Error): void => { + const result: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("getStruct", thrift.Thrift.MessageType.EXCEPTION, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + }); + } + public process_getUnion(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol): void { + new Promise<__NAMESPACE__.SharedUnion>((resolve, reject): void => { + try { + const args: GetUnionArgs = GetUnionArgs.read(input); + input.readMessageEnd(); + resolve(this._handler.getUnion(args.index)); + } + catch (err) { + reject(err); + } + }).then((data: __NAMESPACE__.SharedUnion): void => { + const result: GetUnionResult = new GetUnionResult({ success: data }); + output.writeMessageBegin("getUnion", thrift.Thrift.MessageType.REPLY, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + }).catch((err: Error): void => { + const result: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("getUnion", thrift.Thrift.MessageType.EXCEPTION, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + }); + } +} diff --git a/src/tests/unit/fixtures/apache/generated/com/test/shared/SharedStruct.ts b/src/tests/unit/fixtures/apache/generated/com/test/shared/SharedStruct.ts new file mode 100644 index 00000000..e9bc9083 --- /dev/null +++ b/src/tests/unit/fixtures/apache/generated/com/test/shared/SharedStruct.ts @@ -0,0 +1,88 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as thrift from "test-lib"; +import * as __NAMESPACE__ from "./."; +export interface ISharedStructArgs { + code: __NAMESPACE__.Code; + value: string; +} +export class SharedStruct { + public code: __NAMESPACE__.Code; + public value: string; + constructor(args: ISharedStructArgs) { + if (args != null && args.code != null) { + this.code = args.code; + } + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Required field[code] is unset!"); + } + if (args != null && args.value != null) { + this.value = args.value; + } + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Required field[value] is unset!"); + } + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("SharedStruct"); + if (this.code != null) { + output.writeFieldBegin("code", thrift.Thrift.Type.STRUCT, 1); + this.code.write(output); + output.writeFieldEnd(); + } + if (this.value != null) { + output.writeFieldBegin("value", thrift.Thrift.Type.STRING, 2); + output.writeString(this.value); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): SharedStruct { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.Thrift.Type.STRUCT) { + const value_1: __NAMESPACE__.Code = __NAMESPACE__.Code.read(input); + _args.code = value_1; + } + else { + input.skip(fieldType); + } + break; + case 2: + if (fieldType === thrift.Thrift.Type.STRING) { + const value_2: string = input.readString(); + _args.value = value_2; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.code !== undefined && _args.value !== undefined) { + return new SharedStruct(_args); + } + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Unable to read SharedStruct from input"); + } + } +} diff --git a/src/tests/unit/fixtures/apache/generated/com/test/shared/SharedUnion.ts b/src/tests/unit/fixtures/apache/generated/com/test/shared/SharedUnion.ts new file mode 100644 index 00000000..2aa1f61f --- /dev/null +++ b/src/tests/unit/fixtures/apache/generated/com/test/shared/SharedUnion.ts @@ -0,0 +1,107 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as thrift from "test-lib"; +export interface ISharedUnionArgs { + option1?: string; + option2?: string; +} +export class SharedUnion { + public option1?: string; + public option2?: string; + constructor(args?: ISharedUnionArgs) { + let _fieldsSet: number = 0; + if (args != null) { + if (args.option1 != null) { + _fieldsSet++; + this.option1 = args.option1; + } + if (args.option2 != null) { + _fieldsSet++; + this.option2 = args.option2; + } + if (_fieldsSet > 1) { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.INVALID_DATA, "Cannot read a TUnion with more than one set value!"); + } + else if (_fieldsSet < 1) { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.INVALID_DATA, "Cannot read a TUnion with no set value!"); + } + } + } + public static fromOption1(option1: string): SharedUnion { + return new SharedUnion({ option1 }); + } + public static fromOption2(option2: string): SharedUnion { + return new SharedUnion({ option2 }); + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("SharedUnion"); + if (this.option1 != null) { + output.writeFieldBegin("option1", thrift.Thrift.Type.STRING, 1); + output.writeString(this.option1); + output.writeFieldEnd(); + } + if (this.option2 != null) { + output.writeFieldBegin("option2", thrift.Thrift.Type.STRING, 2); + output.writeString(this.option2); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): SharedUnion { + let _fieldsSet: number = 0; + let _returnValue: SharedUnion | null = null; + input.readStructBegin(); + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.Thrift.Type.STRING) { + _fieldsSet++; + const value_1: string = input.readString(); + _returnValue = SharedUnion.fromOption1(value_1); + } + else { + input.skip(fieldType); + } + break; + case 2: + if (fieldType === thrift.Thrift.Type.STRING) { + _fieldsSet++; + const value_2: string = input.readString(); + _returnValue = SharedUnion.fromOption2(value_2); + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_fieldsSet > 1) { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.INVALID_DATA, "Cannot read a TUnion with more than one set value!"); + } + else if (_fieldsSet < 1) { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.INVALID_DATA, "Cannot read a TUnion with no set value!"); + } + if (_returnValue !== null) { + return _returnValue; + } + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Unable to read data for TUnion"); + } + } +} diff --git a/src/tests/unit/fixtures/apache/generated/com/test/shared/constants.ts b/src/tests/unit/fixtures/apache/generated/com/test/shared/constants.ts new file mode 100644 index 00000000..9bdc1290 --- /dev/null +++ b/src/tests/unit/fixtures/apache/generated/com/test/shared/constants.ts @@ -0,0 +1,6 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +export const SHARED_INT: number = 45; diff --git a/src/tests/unit/fixtures/apache/generated/com/test/shared/index.ts b/src/tests/unit/fixtures/apache/generated/com/test/shared/index.ts new file mode 100644 index 00000000..c6209b6a --- /dev/null +++ b/src/tests/unit/fixtures/apache/generated/com/test/shared/index.ts @@ -0,0 +1,11 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +export * from "./constants"; +export * from "./Code"; +export * from "./SharedStruct"; +export * from "./SharedUnion"; +import * as SharedService from "./SharedService"; +export { SharedService as SharedService }; diff --git a/src/tests/unit/fixtures/apache/i64_service.solution.ts b/src/tests/unit/fixtures/apache/i64_service.solution.ts index da6632a6..fffb4d41 100644 --- a/src/tests/unit/fixtures/apache/i64_service.solution.ts +++ b/src/tests/unit/fixtures/apache/i64_service.solution.ts @@ -1,268 +1,266 @@ -export namespace MyService { - export interface IAddArgsArgs { - num1: number | Int64; - num2: number | Int64; - } - export class AddArgs { - public num1: Int64; - public num2: Int64; - constructor(args: IAddArgsArgs) { - if (args != null && args.num1 != null) { - if (typeof args.num1 === "number") { - this.num1 = new Int64(args.num1); - } - else { - this.num1 = args.num1; - } +export interface IAddArgsArgs { + num1: number | Int64; + num2: number | Int64; +} +export class AddArgs { + public num1: Int64; + public num2: Int64; + constructor(args: IAddArgsArgs) { + if (args != null && args.num1 != null) { + if (typeof args.num1 === "number") { + this.num1 = new Int64(args.num1); } else { - throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Required field[num1] is unset!"); + this.num1 = args.num1; } - if (args != null && args.num2 != null) { - if (typeof args.num2 === "number") { - this.num2 = new Int64(args.num2); - } - else { - this.num2 = args.num2; - } + } + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Required field[num1] is unset!"); + } + if (args != null && args.num2 != null) { + if (typeof args.num2 === "number") { + this.num2 = new Int64(args.num2); } else { - throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Required field[num2] is unset!"); + this.num2 = args.num2; } } - public write(output: thrift.TProtocol): void { - output.writeStructBegin("AddArgs"); - if (this.num1 != null) { - output.writeFieldBegin("num1", thrift.Thrift.Type.I64, 1); - output.writeI64(this.num1); - output.writeFieldEnd(); - } - if (this.num2 != null) { - output.writeFieldBegin("num2", thrift.Thrift.Type.I64, 2); - output.writeI64(this.num2); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Required field[num2] is unset!"); + } + } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("AddArgs"); + if (this.num1 != null) { + output.writeFieldBegin("num1", thrift.Thrift.Type.I64, 1); + output.writeI64(this.num1); + output.writeFieldEnd(); } - public static read(input: thrift.TProtocol): AddArgs { - input.readStructBegin(); - let _args: any = {}; - while (true) { - const ret: thrift.TField = input.readFieldBegin(); - const fieldType: thrift.Thrift.Type = ret.ftype; - const fieldId: number = ret.fid; - if (fieldType === thrift.Thrift.Type.STOP) { + if (this.num2 != null) { + output.writeFieldBegin("num2", thrift.Thrift.Type.I64, 2); + output.writeI64(this.num2); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): AddArgs { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.Thrift.Type.I64) { + const value_1: Int64 = input.readI64(); + _args.num1 = value_1; + } + else { + input.skip(fieldType); + } break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.Thrift.Type.I64) { - const value_1: Int64 = input.readI64(); - _args.num1 = value_1; - } - else { - input.skip(fieldType); - } - break; - case 2: - if (fieldType === thrift.Thrift.Type.I64) { - const value_2: Int64 = input.readI64(); - _args.num2 = value_2; - } - else { - input.skip(fieldType); - } - break; - default: { + case 2: + if (fieldType === thrift.Thrift.Type.I64) { + const value_2: Int64 = input.readI64(); + _args.num2 = value_2; + } + else { input.skip(fieldType); } + break; + default: { + input.skip(fieldType); } - input.readFieldEnd(); } - input.readStructEnd(); - if (_args.num1 !== undefined && _args.num2 !== undefined) { - return new AddArgs(_args); + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.num1 !== undefined && _args.num2 !== undefined) { + return new AddArgs(_args); + } + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Unable to read AddArgs from input"); + } + } +} +export interface IAddResultArgs { + success?: number | Int64; +} +export class AddResult { + public success?: Int64; + constructor(args?: IAddResultArgs) { + if (args != null && args.success != null) { + if (typeof args.success === "number") { + this.success = new Int64(args.success); } else { - throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Unable to read AddArgs from input"); + this.success = args.success; } } } - export interface IAddResultArgs { - success?: number | Int64; - } - export class AddResult { - public success?: Int64; - constructor(args?: IAddResultArgs) { - if (args != null && args.success != null) { - if (typeof args.success === "number") { - this.success = new Int64(args.success); - } - else { - this.success = args.success; - } - } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("AddResult"); + if (this.success != null) { + output.writeFieldBegin("success", thrift.Thrift.Type.I64, 0); + output.writeI64(this.success); + output.writeFieldEnd(); } - public write(output: thrift.TProtocol): void { - output.writeStructBegin("AddResult"); - if (this.success != null) { - output.writeFieldBegin("success", thrift.Thrift.Type.I64, 0); - output.writeI64(this.success); - output.writeFieldEnd(); + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): AddResult { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; } - output.writeFieldStop(); - output.writeStructEnd(); - return; - } - public static read(input: thrift.TProtocol): AddResult { - input.readStructBegin(); - let _args: any = {}; - while (true) { - const ret: thrift.TField = input.readFieldBegin(); - const fieldType: thrift.Thrift.Type = ret.ftype; - const fieldId: number = ret.fid; - if (fieldType === thrift.Thrift.Type.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.Thrift.Type.I64) { - const value_3: Int64 = input.readI64(); - _args.success = value_3; - } - else { - input.skip(fieldType); - } - break; - default: { + switch (fieldId) { + case 0: + if (fieldType === thrift.Thrift.Type.I64) { + const value_3: Int64 = input.readI64(); + _args.success = value_3; + } + else { input.skip(fieldType); } + break; + default: { + input.skip(fieldType); } - input.readFieldEnd(); } - input.readStructEnd(); - return new AddResult(_args); + input.readFieldEnd(); } + input.readStructEnd(); + return new AddResult(_args); } - export class Client { - public _seqid: number; - public _reqs: { - [name: number]: (err: Error | object | undefined, val?: any) => void; - }; - public output: thrift.TTransport; - public protocol: new (trans: thrift.TTransport) => thrift.TProtocol; - constructor(output: thrift.TTransport, protocol: new (trans: thrift.TTransport) => thrift.TProtocol) { - this._seqid = 0; - this._reqs = {}; - this.output = output; - this.protocol = protocol; - } - public incrementSeqId(): number { - return this._seqid += 1; - } - public add(num1: Int64, num2: Int64): Promise { - const requestId: number = this.incrementSeqId(); - return new Promise((resolve, reject): void => { - this._reqs[requestId] = (error, result) => { - delete this._reqs[requestId]; - if (error != null) { - reject(error); - } - else { - resolve(result); - } - }; - this.send_add(num1, num2, requestId); - }); - } - public send_add(num1: Int64, num2: Int64, requestId: number): void { - const output: thrift.TProtocol = new this.protocol(this.output); - output.writeMessageBegin("add", thrift.Thrift.MessageType.CALL, requestId); - const args: AddArgs = new AddArgs({ num1, num2 }); - args.write(output); - output.writeMessageEnd(); - this.output.flush(); - return; - } - public recv_add(input: thrift.TProtocol, mtype: thrift.Thrift.MessageType, requestId: number): void { - const noop = (): any => null; - const callback = this._reqs[requestId] || noop; - if (mtype === thrift.Thrift.MessageType.EXCEPTION) { - const x: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(); - x.read(input); - input.readMessageEnd(); - return callback(x); - } - else { - const result: AddResult = AddResult.read(input); - input.readMessageEnd(); - if (result.success != null) { - return callback(undefined, result.success); +} +export class Client { + public _seqid: number; + public _reqs: { + [name: number]: (err: Error | object | undefined, val?: any) => void; + }; + public output: thrift.TTransport; + public protocol: new (trans: thrift.TTransport) => thrift.TProtocol; + constructor(output: thrift.TTransport, protocol: new (trans: thrift.TTransport) => thrift.TProtocol) { + this._seqid = 0; + this._reqs = {}; + this.output = output; + this.protocol = protocol; + } + public incrementSeqId(): number { + return this._seqid += 1; + } + public add(num1: Int64, num2: Int64): Promise { + const requestId: number = this.incrementSeqId(); + return new Promise((resolve, reject): void => { + this._reqs[requestId] = (error, result) => { + delete this._reqs[requestId]; + if (error != null) { + reject(error); } else { - return callback(new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, "add failed: unknown result")); + resolve(result); } - } - } + }; + this.send_add(num1, num2, requestId); + }); } - export interface IHandler { - add(num1: Int64, num2: Int64): Int64 | Promise; + public send_add(num1: Int64, num2: Int64, requestId: number): void { + const output: thrift.TProtocol = new this.protocol(this.output); + output.writeMessageBegin("add", thrift.Thrift.MessageType.CALL, requestId); + const args: AddArgs = new AddArgs({ num1, num2 }); + args.write(output); + output.writeMessageEnd(); + this.output.flush(); + return; } - export class Processor { - public _handler: IHandler; - constructor(handler: IHandler) { - this._handler = handler; + public recv_add(input: thrift.TProtocol, mtype: thrift.Thrift.MessageType, requestId: number): void { + const noop = (): any => null; + const callback = this._reqs[requestId] || noop; + if (mtype === thrift.Thrift.MessageType.EXCEPTION) { + const x: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(); + x.read(input); + input.readMessageEnd(); + return callback(x); } - public process(input: thrift.TProtocol, output: thrift.TProtocol): void { - const metadata: thrift.TMessage = input.readMessageBegin(); - const fname: string = metadata.fname; - const requestId: number = metadata.rseqid; - const methodName: string = "process_" + fname; - switch (methodName) { - case "process_add": { - this.process_add(requestId, input, output); - return; - } - default: { - input.skip(thrift.Thrift.Type.STRUCT); - input.readMessageEnd(); - const errMessage = "Unknown function " + fname; - const err = new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN_METHOD, errMessage); - output.writeMessageBegin(fname, thrift.Thrift.MessageType.EXCEPTION, requestId); - err.write(output); - output.writeMessageEnd(); - output.flush(); - return; - } + else { + const result: AddResult = AddResult.read(input); + input.readMessageEnd(); + if (result.success != null) { + return callback(undefined, result.success); + } + else { + return callback(new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, "add failed: unknown result")); } } - public process_add(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol): void { - new Promise((resolve, reject): void => { - try { - const args: AddArgs = AddArgs.read(input); - input.readMessageEnd(); - resolve(this._handler.add(args.num1, args.num2)); - } - catch (err) { - reject(err); - } - }).then((data: Int64): void => { - const result: AddResult = new AddResult({ success: data }); - output.writeMessageBegin("add", thrift.Thrift.MessageType.REPLY, requestId); - result.write(output); - output.writeMessageEnd(); - output.flush(); + } +} +export interface IHandler { + add(num1: Int64, num2: Int64): Int64 | Promise; +} +export class Processor { + public _handler: IHandler; + constructor(handler: IHandler) { + this._handler = handler; + } + public process(input: thrift.TProtocol, output: thrift.TProtocol): void { + const metadata: thrift.TMessage = input.readMessageBegin(); + const fname: string = metadata.fname; + const requestId: number = metadata.rseqid; + const methodName: string = "process_" + fname; + switch (methodName) { + case "process_add": { + this.process_add(requestId, input, output); return; - }).catch((err: Error): void => { - const result: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("add", thrift.Thrift.MessageType.EXCEPTION, requestId); - result.write(output); + } + default: { + input.skip(thrift.Thrift.Type.STRUCT); + input.readMessageEnd(); + const errMessage = "Unknown function " + fname; + const err = new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN_METHOD, errMessage); + output.writeMessageBegin(fname, thrift.Thrift.MessageType.EXCEPTION, requestId); + err.write(output); output.writeMessageEnd(); output.flush(); return; - }); + } } } + public process_add(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol): void { + new Promise((resolve, reject): void => { + try { + const args: AddArgs = AddArgs.read(input); + input.readMessageEnd(); + resolve(this._handler.add(args.num1, args.num2)); + } + catch (err) { + reject(err); + } + }).then((data: Int64): void => { + const result: AddResult = new AddResult({ success: data }); + output.writeMessageBegin("add", thrift.Thrift.MessageType.REPLY, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + }).catch((err: Error): void => { + const result: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("add", thrift.Thrift.MessageType.EXCEPTION, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + }); + } } diff --git a/src/tests/unit/fixtures/apache/return_service.solution.ts b/src/tests/unit/fixtures/apache/return_service.solution.ts index 5eab3498..ad4588cf 100644 --- a/src/tests/unit/fixtures/apache/return_service.solution.ts +++ b/src/tests/unit/fixtures/apache/return_service.solution.ts @@ -49,268 +49,266 @@ export class MyException { return new MyException(_args); } } -export namespace MyService { - export interface IPingArgsArgs { - status: number; +export interface IPingArgsArgs { + status: number; +} +export class PingArgs { + public status: number; + constructor(args: IPingArgsArgs) { + if (args != null && args.status != null) { + this.status = args.status; + } + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Required field[status] is unset!"); + } } - export class PingArgs { - public status: number; - constructor(args: IPingArgsArgs) { - if (args != null && args.status != null) { - this.status = args.status; - } - else { - throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Required field[status] is unset!"); - } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("PingArgs"); + if (this.status != null) { + output.writeFieldBegin("status", thrift.Thrift.Type.I32, 1); + output.writeI32(this.status); + output.writeFieldEnd(); } - public write(output: thrift.TProtocol): void { - output.writeStructBegin("PingArgs"); - if (this.status != null) { - output.writeFieldBegin("status", thrift.Thrift.Type.I32, 1); - output.writeI32(this.status); - output.writeFieldEnd(); + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): PingArgs { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; } - output.writeFieldStop(); - output.writeStructEnd(); - return; - } - public static read(input: thrift.TProtocol): PingArgs { - input.readStructBegin(); - let _args: any = {}; - while (true) { - const ret: thrift.TField = input.readFieldBegin(); - const fieldType: thrift.Thrift.Type = ret.ftype; - const fieldId: number = ret.fid; - if (fieldType === thrift.Thrift.Type.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.Thrift.Type.I32) { - const value_2: number = input.readI32(); - _args.status = value_2; - } - else { - input.skip(fieldType); - } - break; - default: { + switch (fieldId) { + case 1: + if (fieldType === thrift.Thrift.Type.I32) { + const value_2: number = input.readI32(); + _args.status = value_2; + } + else { input.skip(fieldType); } + break; + default: { + input.skip(fieldType); } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.status !== undefined) { - return new PingArgs(_args); - } - else { - throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Unable to read PingArgs from input"); } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.status !== undefined) { + return new PingArgs(_args); + } + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Unable to read PingArgs from input"); } } - export interface IPingResultArgs { - success?: string; - exp?: MyException; +} +export interface IPingResultArgs { + success?: string; + exp?: MyException; +} +export class PingResult { + public success?: string; + public exp?: MyException; + constructor(args?: IPingResultArgs) { + if (args != null && args.success != null) { + this.success = args.success; + } + if (args != null && args.exp != null) { + this.exp = args.exp; + } } - export class PingResult { - public success?: string; - public exp?: MyException; - constructor(args?: IPingResultArgs) { - if (args != null && args.success != null) { - this.success = args.success; - } - if (args != null && args.exp != null) { - this.exp = args.exp; - } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("PingResult"); + if (this.success != null) { + output.writeFieldBegin("success", thrift.Thrift.Type.STRING, 0); + output.writeString(this.success); + output.writeFieldEnd(); } - public write(output: thrift.TProtocol): void { - output.writeStructBegin("PingResult"); - if (this.success != null) { - output.writeFieldBegin("success", thrift.Thrift.Type.STRING, 0); - output.writeString(this.success); - output.writeFieldEnd(); - } - if (this.exp != null) { - output.writeFieldBegin("exp", thrift.Thrift.Type.STRUCT, 1); - this.exp.write(output); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; + if (this.exp != null) { + output.writeFieldBegin("exp", thrift.Thrift.Type.STRUCT, 1); + this.exp.write(output); + output.writeFieldEnd(); } - public static read(input: thrift.TProtocol): PingResult { - input.readStructBegin(); - let _args: any = {}; - while (true) { - const ret: thrift.TField = input.readFieldBegin(); - const fieldType: thrift.Thrift.Type = ret.ftype; - const fieldId: number = ret.fid; - if (fieldType === thrift.Thrift.Type.STOP) { + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): PingResult { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.Thrift.Type.STRING) { + const value_3: string = input.readString(); + _args.success = value_3; + } + else { + input.skip(fieldType); + } break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.Thrift.Type.STRING) { - const value_3: string = input.readString(); - _args.success = value_3; - } - else { - input.skip(fieldType); - } - break; - case 1: - if (fieldType === thrift.Thrift.Type.STRUCT) { - const value_4: MyException = MyException.read(input); - _args.exp = value_4; - } - else { - input.skip(fieldType); - } - break; - default: { + case 1: + if (fieldType === thrift.Thrift.Type.STRUCT) { + const value_4: MyException = MyException.read(input); + _args.exp = value_4; + } + else { input.skip(fieldType); } + break; + default: { + input.skip(fieldType); } - input.readFieldEnd(); } - input.readStructEnd(); - return new PingResult(_args); + input.readFieldEnd(); } + input.readStructEnd(); + return new PingResult(_args); } - export class Client { - public _seqid: number; - public _reqs: { - [name: number]: (err: Error | object | undefined, val?: any) => void; - }; - public output: thrift.TTransport; - public protocol: new (trans: thrift.TTransport) => thrift.TProtocol; - constructor(output: thrift.TTransport, protocol: new (trans: thrift.TTransport) => thrift.TProtocol) { - this._seqid = 0; - this._reqs = {}; - this.output = output; - this.protocol = protocol; - } - public incrementSeqId(): number { - return this._seqid += 1; - } - public ping(status: number): Promise { - const requestId: number = this.incrementSeqId(); - return new Promise((resolve, reject): void => { - this._reqs[requestId] = (error, result) => { - delete this._reqs[requestId]; - if (error != null) { - reject(error); - } - else { - resolve(result); - } - }; - this.send_ping(status, requestId); - }); - } - public send_ping(status: number, requestId: number): void { - const output: thrift.TProtocol = new this.protocol(this.output); - output.writeMessageBegin("ping", thrift.Thrift.MessageType.CALL, requestId); - const args: PingArgs = new PingArgs({ status }); - args.write(output); - output.writeMessageEnd(); - this.output.flush(); - return; +} +export class Client { + public _seqid: number; + public _reqs: { + [name: number]: (err: Error | object | undefined, val?: any) => void; + }; + public output: thrift.TTransport; + public protocol: new (trans: thrift.TTransport) => thrift.TProtocol; + constructor(output: thrift.TTransport, protocol: new (trans: thrift.TTransport) => thrift.TProtocol) { + this._seqid = 0; + this._reqs = {}; + this.output = output; + this.protocol = protocol; + } + public incrementSeqId(): number { + return this._seqid += 1; + } + public ping(status: number): Promise { + const requestId: number = this.incrementSeqId(); + return new Promise((resolve, reject): void => { + this._reqs[requestId] = (error, result) => { + delete this._reqs[requestId]; + if (error != null) { + reject(error); + } + else { + resolve(result); + } + }; + this.send_ping(status, requestId); + }); + } + public send_ping(status: number, requestId: number): void { + const output: thrift.TProtocol = new this.protocol(this.output); + output.writeMessageBegin("ping", thrift.Thrift.MessageType.CALL, requestId); + const args: PingArgs = new PingArgs({ status }); + args.write(output); + output.writeMessageEnd(); + this.output.flush(); + return; + } + public recv_ping(input: thrift.TProtocol, mtype: thrift.Thrift.MessageType, requestId: number): void { + const noop = (): any => null; + const callback = this._reqs[requestId] || noop; + if (mtype === thrift.Thrift.MessageType.EXCEPTION) { + const x: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(); + x.read(input); + input.readMessageEnd(); + return callback(x); } - public recv_ping(input: thrift.TProtocol, mtype: thrift.Thrift.MessageType, requestId: number): void { - const noop = (): any => null; - const callback = this._reqs[requestId] || noop; - if (mtype === thrift.Thrift.MessageType.EXCEPTION) { - const x: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(); - x.read(input); - input.readMessageEnd(); - return callback(x); + else { + const result: PingResult = PingResult.read(input); + input.readMessageEnd(); + if (result.exp != null) { + return callback(result.exp); } else { - const result: PingResult = PingResult.read(input); - input.readMessageEnd(); - if (result.exp != null) { - return callback(result.exp); + if (result.success != null) { + return callback(undefined, result.success); } else { - if (result.success != null) { - return callback(undefined, result.success); - } - else { - return callback(new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, "ping failed: unknown result")); - } + return callback(new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, "ping failed: unknown result")); } } } } - export interface IHandler { - ping(status: number): string | Promise; +} +export interface IHandler { + ping(status: number): string | Promise; +} +export class Processor { + public _handler: IHandler; + constructor(handler: IHandler) { + this._handler = handler; } - export class Processor { - public _handler: IHandler; - constructor(handler: IHandler) { - this._handler = handler; - } - public process(input: thrift.TProtocol, output: thrift.TProtocol): void { - const metadata: thrift.TMessage = input.readMessageBegin(); - const fname: string = metadata.fname; - const requestId: number = metadata.rseqid; - const methodName: string = "process_" + fname; - switch (methodName) { - case "process_ping": { - this.process_ping(requestId, input, output); - return; - } - default: { - input.skip(thrift.Thrift.Type.STRUCT); - input.readMessageEnd(); - const errMessage = "Unknown function " + fname; - const err = new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN_METHOD, errMessage); - output.writeMessageBegin(fname, thrift.Thrift.MessageType.EXCEPTION, requestId); - err.write(output); - output.writeMessageEnd(); - output.flush(); - return; - } + public process(input: thrift.TProtocol, output: thrift.TProtocol): void { + const metadata: thrift.TMessage = input.readMessageBegin(); + const fname: string = metadata.fname; + const requestId: number = metadata.rseqid; + const methodName: string = "process_" + fname; + switch (methodName) { + case "process_ping": { + this.process_ping(requestId, input, output); + return; + } + default: { + input.skip(thrift.Thrift.Type.STRUCT); + input.readMessageEnd(); + const errMessage = "Unknown function " + fname; + const err = new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN_METHOD, errMessage); + output.writeMessageBegin(fname, thrift.Thrift.MessageType.EXCEPTION, requestId); + err.write(output); + output.writeMessageEnd(); + output.flush(); + return; } } - public process_ping(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol): void { - new Promise((resolve, reject): void => { - try { - const args: PingArgs = PingArgs.read(input); - input.readMessageEnd(); - resolve(this._handler.ping(args.status)); - } - catch (err) { - reject(err); - } - }).then((data: string): void => { - const result: PingResult = new PingResult({ success: data }); + } + public process_ping(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol): void { + new Promise((resolve, reject): void => { + try { + const args: PingArgs = PingArgs.read(input); + input.readMessageEnd(); + resolve(this._handler.ping(args.status)); + } + catch (err) { + reject(err); + } + }).then((data: string): void => { + const result: PingResult = new PingResult({ success: data }); + output.writeMessageBegin("ping", thrift.Thrift.MessageType.REPLY, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + }).catch((err: Error): void => { + if (err instanceof MyException) { + const result: PingResult = new PingResult({ exp: err }); output.writeMessageBegin("ping", thrift.Thrift.MessageType.REPLY, requestId); result.write(output); output.writeMessageEnd(); output.flush(); return; - }).catch((err: Error): void => { - if (err instanceof MyException) { - const result: PingResult = new PingResult({ exp: err }); - output.writeMessageBegin("ping", thrift.Thrift.MessageType.REPLY, requestId); - result.write(output); - output.writeMessageEnd(); - output.flush(); - return; - } - else { - const result: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("ping", thrift.Thrift.MessageType.EXCEPTION, requestId); - result.write(output); - output.writeMessageEnd(); - output.flush(); - return; - } - }); - } + } + else { + const result: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("ping", thrift.Thrift.MessageType.EXCEPTION, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + } + }); } } diff --git a/src/tests/unit/fixtures/apache/throws_multi_service.solution.ts b/src/tests/unit/fixtures/apache/throws_multi_service.solution.ts index a90964ce..50bd781c 100644 --- a/src/tests/unit/fixtures/apache/throws_multi_service.solution.ts +++ b/src/tests/unit/fixtures/apache/throws_multi_service.solution.ts @@ -170,328 +170,326 @@ export class UnknownException { return new UnknownException(_args); } } -export namespace MyService { - export interface IPegArgsArgs { - name: string; +export interface IPegArgsArgs { + name: string; +} +export class PegArgs { + public name: string; + constructor(args: IPegArgsArgs) { + if (args != null && args.name != null) { + this.name = args.name; + } + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Required field[name] is unset!"); + } } - export class PegArgs { - public name: string; - constructor(args: IPegArgsArgs) { - if (args != null && args.name != null) { - this.name = args.name; - } - else { - throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Required field[name] is unset!"); - } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("PegArgs"); + if (this.name != null) { + output.writeFieldBegin("name", thrift.Thrift.Type.STRING, 1); + output.writeString(this.name); + output.writeFieldEnd(); } - public write(output: thrift.TProtocol): void { - output.writeStructBegin("PegArgs"); - if (this.name != null) { - output.writeFieldBegin("name", thrift.Thrift.Type.STRING, 1); - output.writeString(this.name); - output.writeFieldEnd(); + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): PegArgs { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; } - output.writeFieldStop(); - output.writeStructEnd(); - return; - } - public static read(input: thrift.TProtocol): PegArgs { - input.readStructBegin(); - let _args: any = {}; - while (true) { - const ret: thrift.TField = input.readFieldBegin(); - const fieldType: thrift.Thrift.Type = ret.ftype; - const fieldId: number = ret.fid; - if (fieldType === thrift.Thrift.Type.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.Thrift.Type.STRING) { - const value_5: string = input.readString(); - _args.name = value_5; - } - else { - input.skip(fieldType); - } - break; - default: { + switch (fieldId) { + case 1: + if (fieldType === thrift.Thrift.Type.STRING) { + const value_5: string = input.readString(); + _args.name = value_5; + } + else { input.skip(fieldType); } + break; + default: { + input.skip(fieldType); } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.name !== undefined) { - return new PegArgs(_args); - } - else { - throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Unable to read PegArgs from input"); } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.name !== undefined) { + return new PegArgs(_args); + } + else { + throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Unable to read PegArgs from input"); } } - export interface IPegResultArgs { - success?: string; - exp?: ServiceException; - authExp?: AuthException; - unknownExp?: UnknownException; - } - export class PegResult { - public success?: string; - public exp?: ServiceException; - public authExp?: AuthException; - public unknownExp?: UnknownException; - constructor(args?: IPegResultArgs) { - if (args != null && args.success != null) { - this.success = args.success; - } - if (args != null && args.exp != null) { - this.exp = args.exp; - } - if (args != null && args.authExp != null) { - this.authExp = args.authExp; - } - if (args != null && args.unknownExp != null) { - this.unknownExp = args.unknownExp; - } +} +export interface IPegResultArgs { + success?: string; + exp?: ServiceException; + authExp?: AuthException; + unknownExp?: UnknownException; +} +export class PegResult { + public success?: string; + public exp?: ServiceException; + public authExp?: AuthException; + public unknownExp?: UnknownException; + constructor(args?: IPegResultArgs) { + if (args != null && args.success != null) { + this.success = args.success; } - public write(output: thrift.TProtocol): void { - output.writeStructBegin("PegResult"); - if (this.success != null) { - output.writeFieldBegin("success", thrift.Thrift.Type.STRING, 0); - output.writeString(this.success); - output.writeFieldEnd(); - } - if (this.exp != null) { - output.writeFieldBegin("exp", thrift.Thrift.Type.STRUCT, 1); - this.exp.write(output); - output.writeFieldEnd(); - } - if (this.authExp != null) { - output.writeFieldBegin("authExp", thrift.Thrift.Type.STRUCT, 2); - this.authExp.write(output); - output.writeFieldEnd(); - } - if (this.unknownExp != null) { - output.writeFieldBegin("unknownExp", thrift.Thrift.Type.STRUCT, 3); - this.unknownExp.write(output); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; + if (args != null && args.exp != null) { + this.exp = args.exp; } - public static read(input: thrift.TProtocol): PegResult { - input.readStructBegin(); - let _args: any = {}; - while (true) { - const ret: thrift.TField = input.readFieldBegin(); - const fieldType: thrift.Thrift.Type = ret.ftype; - const fieldId: number = ret.fid; - if (fieldType === thrift.Thrift.Type.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.Thrift.Type.STRING) { - const value_6: string = input.readString(); - _args.success = value_6; - } - else { - input.skip(fieldType); - } - break; - case 1: - if (fieldType === thrift.Thrift.Type.STRUCT) { - const value_7: ServiceException = ServiceException.read(input); - _args.exp = value_7; - } - else { - input.skip(fieldType); - } - break; - case 2: - if (fieldType === thrift.Thrift.Type.STRUCT) { - const value_8: AuthException = AuthException.read(input); - _args.authExp = value_8; - } - else { - input.skip(fieldType); - } - break; - case 3: - if (fieldType === thrift.Thrift.Type.STRUCT) { - const value_9: UnknownException = UnknownException.read(input); - _args.unknownExp = value_9; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return new PegResult(_args); + if (args != null && args.authExp != null) { + this.authExp = args.authExp; + } + if (args != null && args.unknownExp != null) { + this.unknownExp = args.unknownExp; } } - export class Client { - public _seqid: number; - public _reqs: { - [name: number]: (err: Error | object | undefined, val?: any) => void; - }; - public output: thrift.TTransport; - public protocol: new (trans: thrift.TTransport) => thrift.TProtocol; - constructor(output: thrift.TTransport, protocol: new (trans: thrift.TTransport) => thrift.TProtocol) { - this._seqid = 0; - this._reqs = {}; - this.output = output; - this.protocol = protocol; + public write(output: thrift.TProtocol): void { + output.writeStructBegin("PegResult"); + if (this.success != null) { + output.writeFieldBegin("success", thrift.Thrift.Type.STRING, 0); + output.writeString(this.success); + output.writeFieldEnd(); } - public incrementSeqId(): number { - return this._seqid += 1; + if (this.exp != null) { + output.writeFieldBegin("exp", thrift.Thrift.Type.STRUCT, 1); + this.exp.write(output); + output.writeFieldEnd(); } - public peg(name: string): Promise { - const requestId: number = this.incrementSeqId(); - return new Promise((resolve, reject): void => { - this._reqs[requestId] = (error, result) => { - delete this._reqs[requestId]; - if (error != null) { - reject(error); - } - else { - resolve(result); - } - }; - this.send_peg(name, requestId); - }); + if (this.authExp != null) { + output.writeFieldBegin("authExp", thrift.Thrift.Type.STRUCT, 2); + this.authExp.write(output); + output.writeFieldEnd(); } - public send_peg(name: string, requestId: number): void { - const output: thrift.TProtocol = new this.protocol(this.output); - output.writeMessageBegin("peg", thrift.Thrift.MessageType.CALL, requestId); - const args: PegArgs = new PegArgs({ name }); - args.write(output); - output.writeMessageEnd(); - this.output.flush(); - return; + if (this.unknownExp != null) { + output.writeFieldBegin("unknownExp", thrift.Thrift.Type.STRUCT, 3); + this.unknownExp.write(output); + output.writeFieldEnd(); } - public recv_peg(input: thrift.TProtocol, mtype: thrift.Thrift.MessageType, requestId: number): void { - const noop = (): any => null; - const callback = this._reqs[requestId] || noop; - if (mtype === thrift.Thrift.MessageType.EXCEPTION) { - const x: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(); - x.read(input); - input.readMessageEnd(); - return callback(x); + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): PegResult { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; } - else { - const result: PegResult = PegResult.read(input); - input.readMessageEnd(); - if (result.exp != null) { - return callback(result.exp); - } - else if (result.authExp != null) { - return callback(result.authExp); - } - else if (result.unknownExp != null) { - return callback(result.unknownExp); - } - else { - if (result.success != null) { - return callback(undefined, result.success); + switch (fieldId) { + case 0: + if (fieldType === thrift.Thrift.Type.STRING) { + const value_6: string = input.readString(); + _args.success = value_6; + } + else { + input.skip(fieldType); + } + break; + case 1: + if (fieldType === thrift.Thrift.Type.STRUCT) { + const value_7: ServiceException = ServiceException.read(input); + _args.exp = value_7; + } + else { + input.skip(fieldType); + } + break; + case 2: + if (fieldType === thrift.Thrift.Type.STRUCT) { + const value_8: AuthException = AuthException.read(input); + _args.authExp = value_8; } else { - return callback(new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, "peg failed: unknown result")); + input.skip(fieldType); } + break; + case 3: + if (fieldType === thrift.Thrift.Type.STRUCT) { + const value_9: UnknownException = UnknownException.read(input); + _args.unknownExp = value_9; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); } } + input.readFieldEnd(); } + input.readStructEnd(); + return new PegResult(_args); } - export interface IHandler { - peg(name: string): string | Promise; +} +export class Client { + public _seqid: number; + public _reqs: { + [name: number]: (err: Error | object | undefined, val?: any) => void; + }; + public output: thrift.TTransport; + public protocol: new (trans: thrift.TTransport) => thrift.TProtocol; + constructor(output: thrift.TTransport, protocol: new (trans: thrift.TTransport) => thrift.TProtocol) { + this._seqid = 0; + this._reqs = {}; + this.output = output; + this.protocol = protocol; } - export class Processor { - public _handler: IHandler; - constructor(handler: IHandler) { - this._handler = handler; - } - public process(input: thrift.TProtocol, output: thrift.TProtocol): void { - const metadata: thrift.TMessage = input.readMessageBegin(); - const fname: string = metadata.fname; - const requestId: number = metadata.rseqid; - const methodName: string = "process_" + fname; - switch (methodName) { - case "process_peg": { - this.process_peg(requestId, input, output); - return; + public incrementSeqId(): number { + return this._seqid += 1; + } + public peg(name: string): Promise { + const requestId: number = this.incrementSeqId(); + return new Promise((resolve, reject): void => { + this._reqs[requestId] = (error, result) => { + delete this._reqs[requestId]; + if (error != null) { + reject(error); } - default: { - input.skip(thrift.Thrift.Type.STRUCT); - input.readMessageEnd(); - const errMessage = "Unknown function " + fname; - const err = new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN_METHOD, errMessage); - output.writeMessageBegin(fname, thrift.Thrift.MessageType.EXCEPTION, requestId); - err.write(output); - output.writeMessageEnd(); - output.flush(); - return; + else { + resolve(result); } - } + }; + this.send_peg(name, requestId); + }); + } + public send_peg(name: string, requestId: number): void { + const output: thrift.TProtocol = new this.protocol(this.output); + output.writeMessageBegin("peg", thrift.Thrift.MessageType.CALL, requestId); + const args: PegArgs = new PegArgs({ name }); + args.write(output); + output.writeMessageEnd(); + this.output.flush(); + return; + } + public recv_peg(input: thrift.TProtocol, mtype: thrift.Thrift.MessageType, requestId: number): void { + const noop = (): any => null; + const callback = this._reqs[requestId] || noop; + if (mtype === thrift.Thrift.MessageType.EXCEPTION) { + const x: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(); + x.read(input); + input.readMessageEnd(); + return callback(x); } - public process_peg(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol): void { - new Promise((resolve, reject): void => { - try { - const args: PegArgs = PegArgs.read(input); - input.readMessageEnd(); - resolve(this._handler.peg(args.name)); + else { + const result: PegResult = PegResult.read(input); + input.readMessageEnd(); + if (result.exp != null) { + return callback(result.exp); + } + else if (result.authExp != null) { + return callback(result.authExp); + } + else if (result.unknownExp != null) { + return callback(result.unknownExp); + } + else { + if (result.success != null) { + return callback(undefined, result.success); } - catch (err) { - reject(err); + else { + return callback(new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, "peg failed: unknown result")); } - }).then((data: string): void => { - const result: PegResult = new PegResult({ success: data }); + } + } + } +} +export interface IHandler { + peg(name: string): string | Promise; +} +export class Processor { + public _handler: IHandler; + constructor(handler: IHandler) { + this._handler = handler; + } + public process(input: thrift.TProtocol, output: thrift.TProtocol): void { + const metadata: thrift.TMessage = input.readMessageBegin(); + const fname: string = metadata.fname; + const requestId: number = metadata.rseqid; + const methodName: string = "process_" + fname; + switch (methodName) { + case "process_peg": { + this.process_peg(requestId, input, output); + return; + } + default: { + input.skip(thrift.Thrift.Type.STRUCT); + input.readMessageEnd(); + const errMessage = "Unknown function " + fname; + const err = new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN_METHOD, errMessage); + output.writeMessageBegin(fname, thrift.Thrift.MessageType.EXCEPTION, requestId); + err.write(output); + output.writeMessageEnd(); + output.flush(); + return; + } + } + } + public process_peg(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol): void { + new Promise((resolve, reject): void => { + try { + const args: PegArgs = PegArgs.read(input); + input.readMessageEnd(); + resolve(this._handler.peg(args.name)); + } + catch (err) { + reject(err); + } + }).then((data: string): void => { + const result: PegResult = new PegResult({ success: data }); + output.writeMessageBegin("peg", thrift.Thrift.MessageType.REPLY, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + }).catch((err: Error): void => { + if (err instanceof ServiceException) { + const result: PegResult = new PegResult({ exp: err }); output.writeMessageBegin("peg", thrift.Thrift.MessageType.REPLY, requestId); result.write(output); output.writeMessageEnd(); output.flush(); return; - }).catch((err: Error): void => { - if (err instanceof ServiceException) { - const result: PegResult = new PegResult({ exp: err }); - output.writeMessageBegin("peg", thrift.Thrift.MessageType.REPLY, requestId); - result.write(output); - output.writeMessageEnd(); - output.flush(); - return; - } - else if (err instanceof AuthException) { - const result: PegResult = new PegResult({ authExp: err }); - output.writeMessageBegin("peg", thrift.Thrift.MessageType.REPLY, requestId); - result.write(output); - output.writeMessageEnd(); - output.flush(); - return; - } - else if (err instanceof UnknownException) { - const result: PegResult = new PegResult({ unknownExp: err }); - output.writeMessageBegin("peg", thrift.Thrift.MessageType.REPLY, requestId); - result.write(output); - output.writeMessageEnd(); - output.flush(); - return; - } - else { - const result: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("peg", thrift.Thrift.MessageType.EXCEPTION, requestId); - result.write(output); - output.writeMessageEnd(); - output.flush(); - return; - } - }); - } + } + else if (err instanceof AuthException) { + const result: PegResult = new PegResult({ authExp: err }); + output.writeMessageBegin("peg", thrift.Thrift.MessageType.REPLY, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + } + else if (err instanceof UnknownException) { + const result: PegResult = new PegResult({ unknownExp: err }); + output.writeMessageBegin("peg", thrift.Thrift.MessageType.REPLY, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + } + else { + const result: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("peg", thrift.Thrift.MessageType.EXCEPTION, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + } + }); } } diff --git a/src/tests/unit/fixtures/apache/throws_service.solution.ts b/src/tests/unit/fixtures/apache/throws_service.solution.ts index 63312413..961762df 100644 --- a/src/tests/unit/fixtures/apache/throws_service.solution.ts +++ b/src/tests/unit/fixtures/apache/throws_service.solution.ts @@ -49,228 +49,226 @@ export class MyException { return new MyException(_args); } } -export namespace MyService { - export interface IPingArgsArgs { +export interface IPingArgsArgs { +} +export class PingArgs { + constructor() { } - export class PingArgs { - constructor() { - } - public write(output: thrift.TProtocol): void { - output.writeStructBegin("PingArgs"); - output.writeFieldStop(); - output.writeStructEnd(); - return; - } - public static read(input: thrift.TProtocol): PingArgs { - input.readStructBegin(); - while (true) { - const ret: thrift.TField = input.readFieldBegin(); - const fieldType: thrift.Thrift.Type = ret.ftype; - const fieldId: number = ret.fid; - if (fieldType === thrift.Thrift.Type.STOP) { - break; - } - switch (fieldId) { - default: { - input.skip(fieldType); - } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("PingArgs"); + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): PingArgs { + input.readStructBegin(); + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; + } + switch (fieldId) { + default: { + input.skip(fieldType); } - input.readFieldEnd(); } - input.readStructEnd(); - return new PingArgs(); + input.readFieldEnd(); } + input.readStructEnd(); + return new PingArgs(); } - export interface IPingResultArgs { - success?: void; - exp?: MyException; +} +export interface IPingResultArgs { + success?: void; + exp?: MyException; +} +export class PingResult { + public success?: void; + public exp?: MyException; + constructor(args?: IPingResultArgs) { + if (args != null && args.success != null) { + this.success = args.success; + } + if (args != null && args.exp != null) { + this.exp = args.exp; + } } - export class PingResult { - public success?: void; - public exp?: MyException; - constructor(args?: IPingResultArgs) { - if (args != null && args.success != null) { - this.success = args.success; - } - if (args != null && args.exp != null) { - this.exp = args.exp; - } + public write(output: thrift.TProtocol): void { + output.writeStructBegin("PingResult"); + if (this.exp != null) { + output.writeFieldBegin("exp", thrift.Thrift.Type.STRUCT, 1); + this.exp.write(output); + output.writeFieldEnd(); } - public write(output: thrift.TProtocol): void { - output.writeStructBegin("PingResult"); - if (this.exp != null) { - output.writeFieldBegin("exp", thrift.Thrift.Type.STRUCT, 1); - this.exp.write(output); - output.writeFieldEnd(); + output.writeFieldStop(); + output.writeStructEnd(); + return; + } + public static read(input: thrift.TProtocol): PingResult { + input.readStructBegin(); + let _args: any = {}; + while (true) { + const ret: thrift.TField = input.readFieldBegin(); + const fieldType: thrift.Thrift.Type = ret.ftype; + const fieldId: number = ret.fid; + if (fieldType === thrift.Thrift.Type.STOP) { + break; } - output.writeFieldStop(); - output.writeStructEnd(); - return; - } - public static read(input: thrift.TProtocol): PingResult { - input.readStructBegin(); - let _args: any = {}; - while (true) { - const ret: thrift.TField = input.readFieldBegin(); - const fieldType: thrift.Thrift.Type = ret.ftype; - const fieldId: number = ret.fid; - if (fieldType === thrift.Thrift.Type.STOP) { + switch (fieldId) { + case 0: + if (fieldType === thrift.Thrift.Type.VOID) { + input.skip(fieldType); + } + else { + input.skip(fieldType); + } break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.Thrift.Type.VOID) { - input.skip(fieldType); - } - else { - input.skip(fieldType); - } - break; - case 1: - if (fieldType === thrift.Thrift.Type.STRUCT) { - const value_2: MyException = MyException.read(input); - _args.exp = value_2; - } - else { - input.skip(fieldType); - } - break; - default: { + case 1: + if (fieldType === thrift.Thrift.Type.STRUCT) { + const value_2: MyException = MyException.read(input); + _args.exp = value_2; + } + else { input.skip(fieldType); } + break; + default: { + input.skip(fieldType); } - input.readFieldEnd(); } - input.readStructEnd(); - return new PingResult(_args); + input.readFieldEnd(); } + input.readStructEnd(); + return new PingResult(_args); } - export class Client { - public _seqid: number; - public _reqs: { - [name: number]: (err: Error | object | undefined, val?: any) => void; - }; - public output: thrift.TTransport; - public protocol: new (trans: thrift.TTransport) => thrift.TProtocol; - constructor(output: thrift.TTransport, protocol: new (trans: thrift.TTransport) => thrift.TProtocol) { - this._seqid = 0; - this._reqs = {}; - this.output = output; - this.protocol = protocol; - } - public incrementSeqId(): number { - return this._seqid += 1; - } - public ping(): Promise { - const requestId: number = this.incrementSeqId(); - return new Promise((resolve, reject): void => { - this._reqs[requestId] = (error, result) => { - delete this._reqs[requestId]; - if (error != null) { - reject(error); - } - else { - resolve(result); - } - }; - this.send_ping(requestId); - }); - } - public send_ping(requestId: number): void { - const output: thrift.TProtocol = new this.protocol(this.output); - output.writeMessageBegin("ping", thrift.Thrift.MessageType.CALL, requestId); - const args: PingArgs = new PingArgs(); - args.write(output); - output.writeMessageEnd(); - this.output.flush(); - return; - } - public recv_ping(input: thrift.TProtocol, mtype: thrift.Thrift.MessageType, requestId: number): void { - const noop = (): any => null; - const callback = this._reqs[requestId] || noop; - if (mtype === thrift.Thrift.MessageType.EXCEPTION) { - const x: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(); - x.read(input); - input.readMessageEnd(); - return callback(x); - } - else { - const result: PingResult = PingResult.read(input); - input.readMessageEnd(); - if (result.exp != null) { - return callback(result.exp); +} +export class Client { + public _seqid: number; + public _reqs: { + [name: number]: (err: Error | object | undefined, val?: any) => void; + }; + public output: thrift.TTransport; + public protocol: new (trans: thrift.TTransport) => thrift.TProtocol; + constructor(output: thrift.TTransport, protocol: new (trans: thrift.TTransport) => thrift.TProtocol) { + this._seqid = 0; + this._reqs = {}; + this.output = output; + this.protocol = protocol; + } + public incrementSeqId(): number { + return this._seqid += 1; + } + public ping(): Promise { + const requestId: number = this.incrementSeqId(); + return new Promise((resolve, reject): void => { + this._reqs[requestId] = (error, result) => { + delete this._reqs[requestId]; + if (error != null) { + reject(error); } else { - return callback(undefined); + resolve(result); } + }; + this.send_ping(requestId); + }); + } + public send_ping(requestId: number): void { + const output: thrift.TProtocol = new this.protocol(this.output); + output.writeMessageBegin("ping", thrift.Thrift.MessageType.CALL, requestId); + const args: PingArgs = new PingArgs(); + args.write(output); + output.writeMessageEnd(); + this.output.flush(); + return; + } + public recv_ping(input: thrift.TProtocol, mtype: thrift.Thrift.MessageType, requestId: number): void { + const noop = (): any => null; + const callback = this._reqs[requestId] || noop; + if (mtype === thrift.Thrift.MessageType.EXCEPTION) { + const x: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(); + x.read(input); + input.readMessageEnd(); + return callback(x); + } + else { + const result: PingResult = PingResult.read(input); + input.readMessageEnd(); + if (result.exp != null) { + return callback(result.exp); + } + else { + return callback(undefined); } } } - export interface IHandler { - ping(): void | Promise; +} +export interface IHandler { + ping(): void | Promise; +} +export class Processor { + public _handler: IHandler; + constructor(handler: IHandler) { + this._handler = handler; } - export class Processor { - public _handler: IHandler; - constructor(handler: IHandler) { - this._handler = handler; - } - public process(input: thrift.TProtocol, output: thrift.TProtocol): void { - const metadata: thrift.TMessage = input.readMessageBegin(); - const fname: string = metadata.fname; - const requestId: number = metadata.rseqid; - const methodName: string = "process_" + fname; - switch (methodName) { - case "process_ping": { - this.process_ping(requestId, input, output); - return; - } - default: { - input.skip(thrift.Thrift.Type.STRUCT); - input.readMessageEnd(); - const errMessage = "Unknown function " + fname; - const err = new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN_METHOD, errMessage); - output.writeMessageBegin(fname, thrift.Thrift.MessageType.EXCEPTION, requestId); - err.write(output); - output.writeMessageEnd(); - output.flush(); - return; - } + public process(input: thrift.TProtocol, output: thrift.TProtocol): void { + const metadata: thrift.TMessage = input.readMessageBegin(); + const fname: string = metadata.fname; + const requestId: number = metadata.rseqid; + const methodName: string = "process_" + fname; + switch (methodName) { + case "process_ping": { + this.process_ping(requestId, input, output); + return; + } + default: { + input.skip(thrift.Thrift.Type.STRUCT); + input.readMessageEnd(); + const errMessage = "Unknown function " + fname; + const err = new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN_METHOD, errMessage); + output.writeMessageBegin(fname, thrift.Thrift.MessageType.EXCEPTION, requestId); + err.write(output); + output.writeMessageEnd(); + output.flush(); + return; } } - public process_ping(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol): void { - new Promise((resolve, reject): void => { - try { - input.readMessageEnd(); - resolve(this._handler.ping()); - } - catch (err) { - reject(err); - } - }).then((data: void): void => { - const result: PingResult = new PingResult({ success: data }); + } + public process_ping(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol): void { + new Promise((resolve, reject): void => { + try { + input.readMessageEnd(); + resolve(this._handler.ping()); + } + catch (err) { + reject(err); + } + }).then((data: void): void => { + const result: PingResult = new PingResult({ success: data }); + output.writeMessageBegin("ping", thrift.Thrift.MessageType.REPLY, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + }).catch((err: Error): void => { + if (err instanceof MyException) { + const result: PingResult = new PingResult({ exp: err }); output.writeMessageBegin("ping", thrift.Thrift.MessageType.REPLY, requestId); result.write(output); output.writeMessageEnd(); output.flush(); return; - }).catch((err: Error): void => { - if (err instanceof MyException) { - const result: PingResult = new PingResult({ exp: err }); - output.writeMessageBegin("ping", thrift.Thrift.MessageType.REPLY, requestId); - result.write(output); - output.writeMessageEnd(); - output.flush(); - return; - } - else { - const result: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("ping", thrift.Thrift.MessageType.EXCEPTION, requestId); - result.write(output); - output.writeMessageEnd(); - output.flush(); - return; - } - }); - } + } + else { + const result: thrift.Thrift.TApplicationException = new thrift.Thrift.TApplicationException(thrift.Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("ping", thrift.Thrift.MessageType.EXCEPTION, requestId); + result.write(output); + output.writeMessageEnd(); + output.flush(); + return; + } + }); } } diff --git a/src/tests/unit/fixtures/generated/calculator/index.ts b/src/tests/unit/fixtures/generated/calculator/index.ts deleted file mode 100644 index 89eac0ed..00000000 --- a/src/tests/unit/fixtures/generated/calculator/index.ts +++ /dev/null @@ -1,3890 +0,0 @@ -/* tslint:disable */ -/* - * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} - * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING -*/ -import * as thrift from "test-lib"; -import * as shared from "./../shared"; -import * as common from "./../common"; -import * as operation from "./../operation"; -export type MyInteger = number; -export import Operation = operation.Operation; -export import ICommonStruct = common.ICommonStruct; -export import ICommonStructArgs = common.ICommonStructArgs; -export import CommonStruct = common.CommonStruct; -export import CommonStructCodec = common.CommonStructCodec; -export const INT32CONSTANT: number = 9853; -export const MAPCONSTANT: Map = new Map([["hello", "world"], ["goodnight", "moon"]]); -export interface IWork { - num1: number; - num2: number; - op: Operation; - comment?: string; -} -export interface IWorkArgs { - num1?: number; - num2: number; - op: Operation; - comment?: string; -} -export const WorkCodec: thrift.IStructCodec = { - encode(args: IWorkArgs, output: thrift.TProtocol): void { - const obj = { - num1: (args.num1 != null ? args.num1 : 0), - num2: args.num2, - op: args.op, - comment: args.comment - }; - output.writeStructBegin("Work"); - if (obj.num1 != null) { - output.writeFieldBegin("num1", thrift.TType.I32, 1); - output.writeI32(obj.num1); - output.writeFieldEnd(); - } - if (obj.num2 != null) { - output.writeFieldBegin("num2", thrift.TType.I32, 2); - output.writeI32(obj.num2); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num2] is unset!"); - } - if (obj.op != null) { - output.writeFieldBegin("op", thrift.TType.I32, 3); - output.writeI32(obj.op); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[op] is unset!"); - } - if (obj.comment != null) { - output.writeFieldBegin("comment", thrift.TType.STRING, 4); - output.writeString(obj.comment); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IWork { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.I32) { - const value_1: number = input.readI32(); - _args.num1 = value_1; - } - else { - input.skip(fieldType); - } - break; - case 2: - if (fieldType === thrift.TType.I32) { - const value_2: number = input.readI32(); - _args.num2 = value_2; - } - else { - input.skip(fieldType); - } - break; - case 3: - if (fieldType === thrift.TType.I32) { - const value_3: Operation = input.readI32(); - _args.op = value_3; - } - else { - input.skip(fieldType); - } - break; - case 4: - if (fieldType === thrift.TType.STRING) { - const value_4: string = input.readString(); - _args.comment = value_4; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.num1 !== undefined && _args.num2 !== undefined && _args.op !== undefined) { - return { - num1: (_args.num1 != null ? _args.num1 : 0), - num2: _args.num2, - op: _args.op, - comment: _args.comment - }; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read Work from input"); - } - } -}; -export class Work extends thrift.StructLike implements IWork { - public num1: number = 0; - public num2: number; - public op: Operation; - public comment?: string; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IWorkArgs) { - super(); - if (args.num1 != null) { - const value_5: number = args.num1; - this.num1 = value_5; - } - if (args.num2 != null) { - const value_6: number = args.num2; - this.num2 = value_6; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num2] is unset!"); - } - if (args.op != null) { - const value_7: Operation = args.op; - this.op = value_7; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[op] is unset!"); - } - if (args.comment != null) { - const value_8: string = args.comment; - this.comment = value_8; - } - } - public static read(input: thrift.TProtocol): Work { - return new Work(WorkCodec.decode(input)); - } - public static write(args: IWorkArgs, output: thrift.TProtocol): void { - return WorkCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return WorkCodec.encode(this, output); - } -} -export interface IFirstName { - name?: string; -} -export interface IFirstNameArgs { - name?: string; -} -export const FirstNameCodec: thrift.IStructCodec = { - encode(args: IFirstNameArgs, output: thrift.TProtocol): void { - const obj = { - name: args.name - }; - output.writeStructBegin("FirstName"); - if (obj.name != null) { - output.writeFieldBegin("name", thrift.TType.STRING, 1); - output.writeString(obj.name); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IFirstName { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.STRING) { - const value_9: string = input.readString(); - _args.name = value_9; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - name: _args.name - }; - } -}; -export class FirstName extends thrift.StructLike implements IFirstName { - public name?: string; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IFirstNameArgs = {}) { - super(); - if (args.name != null) { - const value_10: string = args.name; - this.name = value_10; - } - } - public static read(input: thrift.TProtocol): FirstName { - return new FirstName(FirstNameCodec.decode(input)); - } - public static write(args: IFirstNameArgs, output: thrift.TProtocol): void { - return FirstNameCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return FirstNameCodec.encode(this, output); - } -} -export interface ILastName { - name?: string; -} -export interface ILastNameArgs { - name?: string; -} -export const LastNameCodec: thrift.IStructCodec = { - encode(args: ILastNameArgs, output: thrift.TProtocol): void { - const obj = { - name: args.name - }; - output.writeStructBegin("LastName"); - if (obj.name != null) { - output.writeFieldBegin("name", thrift.TType.STRING, 1); - output.writeString(obj.name); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): ILastName { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.STRING) { - const value_11: string = input.readString(); - _args.name = value_11; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - name: _args.name - }; - } -}; -export class LastName extends thrift.StructLike implements ILastName { - public name?: string; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: ILastNameArgs = {}) { - super(); - if (args.name != null) { - const value_12: string = args.name; - this.name = value_12; - } - } - public static read(input: thrift.TProtocol): LastName { - return new LastName(LastNameCodec.decode(input)); - } - public static write(args: ILastNameArgs, output: thrift.TProtocol): void { - return LastNameCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return LastNameCodec.encode(this, output); - } -} -export interface IChoice { - firstName?: IFirstName; - lastName?: ILastName; -} -export interface IChoiceArgs { - firstName?: IFirstNameArgs; - lastName?: ILastNameArgs; -} -export const ChoiceCodec: thrift.IStructCodec = { - encode(args: IChoiceArgs, output: thrift.TProtocol): void { - let _fieldsSet: number = 0; - const obj = { - firstName: args.firstName, - lastName: args.lastName - }; - output.writeStructBegin("Choice"); - if (obj.firstName != null) { - _fieldsSet++; - output.writeFieldBegin("firstName", thrift.TType.STRUCT, 1); - FirstNameCodec.encode(obj.firstName, output); - output.writeFieldEnd(); - } - if (obj.lastName != null) { - _fieldsSet++; - output.writeFieldBegin("lastName", thrift.TType.STRUCT, 2); - LastNameCodec.encode(obj.lastName, output); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - if (_fieldsSet > 1) { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion cannot have more than one value"); - } - else if (_fieldsSet < 1) { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion must have one value set"); - } - return; - }, - decode(input: thrift.TProtocol): IChoice { - let _fieldsSet: number = 0; - let _returnValue: IChoice | null = null; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.STRUCT) { - _fieldsSet++; - const value_13: IFirstName = FirstNameCodec.decode(input); - _returnValue = { firstName: value_13 }; - } - else { - input.skip(fieldType); - } - break; - case 2: - if (fieldType === thrift.TType.STRUCT) { - _fieldsSet++; - const value_14: ILastName = LastNameCodec.decode(input); - _returnValue = { lastName: value_14 }; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_fieldsSet > 1) { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion cannot have more than one value"); - } - else if (_fieldsSet < 1) { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion must have one value set"); - } - if (_returnValue !== null) { - return _returnValue; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read data for TUnion"); - } - } -}; -export class Choice extends thrift.StructLike implements IChoice { - public firstName?: IFirstName; - public lastName?: ILastName; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IChoiceArgs = {}) { - super(); - let _fieldsSet: number = 0; - if (args.firstName != null) { - _fieldsSet++; - const value_15: IFirstName = new FirstName(args.firstName); - this.firstName = value_15; - } - if (args.lastName != null) { - _fieldsSet++; - const value_16: ILastName = new LastName(args.lastName); - this.lastName = value_16; - } - if (_fieldsSet > 1) { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion cannot have more than one value"); - } - else if (_fieldsSet < 1) { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion must have one value set"); - } - } - public static read(input: thrift.TProtocol): Choice { - return new Choice(ChoiceCodec.decode(input)); - } - public static write(args: IChoiceArgs, output: thrift.TProtocol): void { - return ChoiceCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return ChoiceCodec.encode(this, output); - } -} -export namespace Calculator { - export const serviceName: string = "Calculator"; - export const annotations: thrift.IThriftAnnotations = {}; - export const methodAnnotations: thrift.IMethodAnnotations = { - getStruct: { - annotations: {}, - fieldAnnotations: {} - }, - getUnion: { - annotations: {}, - fieldAnnotations: {} - }, - ping: { - annotations: {}, - fieldAnnotations: {} - }, - add: { - annotations: {}, - fieldAnnotations: {} - }, - addInt64: { - annotations: {}, - fieldAnnotations: {} - }, - addWithContext: { - annotations: {}, - fieldAnnotations: {} - }, - calculate: { - annotations: {}, - fieldAnnotations: {} - }, - echoBinary: { - annotations: {}, - fieldAnnotations: {} - }, - echoString: { - annotations: {}, - fieldAnnotations: {} - }, - checkName: { - annotations: {}, - fieldAnnotations: {} - }, - checkOptional: { - annotations: {}, - fieldAnnotations: {} - }, - mapOneList: { - annotations: {}, - fieldAnnotations: {} - }, - mapValues: { - annotations: {}, - fieldAnnotations: {} - }, - listToMap: { - annotations: {}, - fieldAnnotations: {} - }, - fetchThing: { - annotations: {}, - fieldAnnotations: {} - }, - zip: { - annotations: {}, - fieldAnnotations: {} - } - }; - export const methodNames: Array = ["getStruct", "getUnion", "ping", "add", "addInt64", "addWithContext", "calculate", "echoBinary", "echoString", "checkName", "checkOptional", "mapOneList", "mapValues", "listToMap", "fetchThing", "zip"]; - export interface IPing__Args { - } - export interface IPing__ArgsArgs { - } - export const Ping__ArgsCodec: thrift.IStructCodec = { - encode(args: IPing__ArgsArgs, output: thrift.TProtocol): void { - output.writeStructBegin("Ping__Args"); - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IPing__Args { - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return {}; - } - }; - export class Ping__Args extends thrift.StructLike implements IPing__Args { - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IPing__ArgsArgs = {}) { - super(); - } - public static read(input: thrift.TProtocol): Ping__Args { - return new Ping__Args(Ping__ArgsCodec.decode(input)); - } - public static write(args: IPing__ArgsArgs, output: thrift.TProtocol): void { - return Ping__ArgsCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return Ping__ArgsCodec.encode(this, output); - } - } - export interface IAdd__Args { - num1: number; - num2: number; - } - export interface IAdd__ArgsArgs { - num1: number; - num2: number; - } - export const Add__ArgsCodec: thrift.IStructCodec = { - encode(args: IAdd__ArgsArgs, output: thrift.TProtocol): void { - const obj = { - num1: args.num1, - num2: args.num2 - }; - output.writeStructBegin("Add__Args"); - if (obj.num1 != null) { - output.writeFieldBegin("num1", thrift.TType.I32, 1); - output.writeI32(obj.num1); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num1] is unset!"); - } - if (obj.num2 != null) { - output.writeFieldBegin("num2", thrift.TType.I32, 2); - output.writeI32(obj.num2); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num2] is unset!"); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IAdd__Args { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.I32) { - const value_17: number = input.readI32(); - _args.num1 = value_17; - } - else { - input.skip(fieldType); - } - break; - case 2: - if (fieldType === thrift.TType.I32) { - const value_18: number = input.readI32(); - _args.num2 = value_18; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.num1 !== undefined && _args.num2 !== undefined) { - return { - num1: _args.num1, - num2: _args.num2 - }; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read Add__Args from input"); - } - } - }; - export class Add__Args extends thrift.StructLike implements IAdd__Args { - public num1: number; - public num2: number; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IAdd__ArgsArgs) { - super(); - if (args.num1 != null) { - const value_19: number = args.num1; - this.num1 = value_19; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num1] is unset!"); - } - if (args.num2 != null) { - const value_20: number = args.num2; - this.num2 = value_20; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num2] is unset!"); - } - } - public static read(input: thrift.TProtocol): Add__Args { - return new Add__Args(Add__ArgsCodec.decode(input)); - } - public static write(args: IAdd__ArgsArgs, output: thrift.TProtocol): void { - return Add__ArgsCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return Add__ArgsCodec.encode(this, output); - } - } - export interface IAddInt64__Args { - num1: thrift.Int64; - num2: thrift.Int64; - } - export interface IAddInt64__ArgsArgs { - num1: number | string | thrift.Int64; - num2: number | string | thrift.Int64; - } - export const AddInt64__ArgsCodec: thrift.IStructCodec = { - encode(args: IAddInt64__ArgsArgs, output: thrift.TProtocol): void { - const obj = { - num1: (typeof args.num1 === "number" ? new thrift.Int64(args.num1) : typeof args.num1 === "string" ? thrift.Int64.fromDecimalString(args.num1) : args.num1), - num2: (typeof args.num2 === "number" ? new thrift.Int64(args.num2) : typeof args.num2 === "string" ? thrift.Int64.fromDecimalString(args.num2) : args.num2) - }; - output.writeStructBegin("AddInt64__Args"); - if (obj.num1 != null) { - output.writeFieldBegin("num1", thrift.TType.I64, 1); - output.writeI64((typeof obj.num1 === "number" ? new thrift.Int64(obj.num1) : typeof obj.num1 === "string" ? thrift.Int64.fromDecimalString(obj.num1) : obj.num1)); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num1] is unset!"); - } - if (obj.num2 != null) { - output.writeFieldBegin("num2", thrift.TType.I64, 2); - output.writeI64((typeof obj.num2 === "number" ? new thrift.Int64(obj.num2) : typeof obj.num2 === "string" ? thrift.Int64.fromDecimalString(obj.num2) : obj.num2)); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num2] is unset!"); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IAddInt64__Args { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.I64) { - const value_21: thrift.Int64 = input.readI64(); - _args.num1 = value_21; - } - else { - input.skip(fieldType); - } - break; - case 2: - if (fieldType === thrift.TType.I64) { - const value_22: thrift.Int64 = input.readI64(); - _args.num2 = value_22; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.num1 !== undefined && _args.num2 !== undefined) { - return { - num1: _args.num1, - num2: _args.num2 - }; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read AddInt64__Args from input"); - } - } - }; - export class AddInt64__Args extends thrift.StructLike implements IAddInt64__Args { - public num1: thrift.Int64; - public num2: thrift.Int64; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IAddInt64__ArgsArgs) { - super(); - if (args.num1 != null) { - const value_23: thrift.Int64 = (typeof args.num1 === "number" ? new thrift.Int64(args.num1) : typeof args.num1 === "string" ? thrift.Int64.fromDecimalString(args.num1) : args.num1); - this.num1 = value_23; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num1] is unset!"); - } - if (args.num2 != null) { - const value_24: thrift.Int64 = (typeof args.num2 === "number" ? new thrift.Int64(args.num2) : typeof args.num2 === "string" ? thrift.Int64.fromDecimalString(args.num2) : args.num2); - this.num2 = value_24; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num2] is unset!"); - } - } - public static read(input: thrift.TProtocol): AddInt64__Args { - return new AddInt64__Args(AddInt64__ArgsCodec.decode(input)); - } - public static write(args: IAddInt64__ArgsArgs, output: thrift.TProtocol): void { - return AddInt64__ArgsCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return AddInt64__ArgsCodec.encode(this, output); - } - } - export interface IAddWithContext__Args { - num1: number; - num2: number; - } - export interface IAddWithContext__ArgsArgs { - num1: number; - num2: number; - } - export const AddWithContext__ArgsCodec: thrift.IStructCodec = { - encode(args: IAddWithContext__ArgsArgs, output: thrift.TProtocol): void { - const obj = { - num1: args.num1, - num2: args.num2 - }; - output.writeStructBegin("AddWithContext__Args"); - if (obj.num1 != null) { - output.writeFieldBegin("num1", thrift.TType.I32, 1); - output.writeI32(obj.num1); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num1] is unset!"); - } - if (obj.num2 != null) { - output.writeFieldBegin("num2", thrift.TType.I32, 2); - output.writeI32(obj.num2); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num2] is unset!"); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IAddWithContext__Args { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.I32) { - const value_25: number = input.readI32(); - _args.num1 = value_25; - } - else { - input.skip(fieldType); - } - break; - case 2: - if (fieldType === thrift.TType.I32) { - const value_26: number = input.readI32(); - _args.num2 = value_26; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.num1 !== undefined && _args.num2 !== undefined) { - return { - num1: _args.num1, - num2: _args.num2 - }; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read AddWithContext__Args from input"); - } - } - }; - export class AddWithContext__Args extends thrift.StructLike implements IAddWithContext__Args { - public num1: number; - public num2: number; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IAddWithContext__ArgsArgs) { - super(); - if (args.num1 != null) { - const value_27: number = args.num1; - this.num1 = value_27; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num1] is unset!"); - } - if (args.num2 != null) { - const value_28: number = args.num2; - this.num2 = value_28; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num2] is unset!"); - } - } - public static read(input: thrift.TProtocol): AddWithContext__Args { - return new AddWithContext__Args(AddWithContext__ArgsCodec.decode(input)); - } - public static write(args: IAddWithContext__ArgsArgs, output: thrift.TProtocol): void { - return AddWithContext__ArgsCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return AddWithContext__ArgsCodec.encode(this, output); - } - } - export interface ICalculate__Args { - logid: number; - work: IWork; - } - export interface ICalculate__ArgsArgs { - logid: number; - work: IWorkArgs; - } - export const Calculate__ArgsCodec: thrift.IStructCodec = { - encode(args: ICalculate__ArgsArgs, output: thrift.TProtocol): void { - const obj = { - logid: args.logid, - work: args.work - }; - output.writeStructBegin("Calculate__Args"); - if (obj.logid != null) { - output.writeFieldBegin("logid", thrift.TType.I32, 1); - output.writeI32(obj.logid); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[logid] is unset!"); - } - if (obj.work != null) { - output.writeFieldBegin("work", thrift.TType.STRUCT, 2); - WorkCodec.encode(obj.work, output); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[work] is unset!"); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): ICalculate__Args { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.I32) { - const value_29: number = input.readI32(); - _args.logid = value_29; - } - else { - input.skip(fieldType); - } - break; - case 2: - if (fieldType === thrift.TType.STRUCT) { - const value_30: IWork = WorkCodec.decode(input); - _args.work = value_30; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.logid !== undefined && _args.work !== undefined) { - return { - logid: _args.logid, - work: _args.work - }; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read Calculate__Args from input"); - } - } - }; - export class Calculate__Args extends thrift.StructLike implements ICalculate__Args { - public logid: number; - public work: IWork; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: ICalculate__ArgsArgs) { - super(); - if (args.logid != null) { - const value_31: number = args.logid; - this.logid = value_31; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[logid] is unset!"); - } - if (args.work != null) { - const value_32: IWork = new Work(args.work); - this.work = value_32; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[work] is unset!"); - } - } - public static read(input: thrift.TProtocol): Calculate__Args { - return new Calculate__Args(Calculate__ArgsCodec.decode(input)); - } - public static write(args: ICalculate__ArgsArgs, output: thrift.TProtocol): void { - return Calculate__ArgsCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return Calculate__ArgsCodec.encode(this, output); - } - } - export interface IEchoBinary__Args { - word: Buffer; - } - export interface IEchoBinary__ArgsArgs { - word: string | Buffer; - } - export const EchoBinary__ArgsCodec: thrift.IStructCodec = { - encode(args: IEchoBinary__ArgsArgs, output: thrift.TProtocol): void { - const obj = { - word: (typeof args.word === "string" ? Buffer.from(args.word) : args.word) - }; - output.writeStructBegin("EchoBinary__Args"); - if (obj.word != null) { - output.writeFieldBegin("word", thrift.TType.STRING, 1); - output.writeBinary(obj.word); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[word] is unset!"); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IEchoBinary__Args { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.STRING) { - const value_33: Buffer = input.readBinary(); - _args.word = value_33; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.word !== undefined) { - return { - word: _args.word - }; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read EchoBinary__Args from input"); - } - } - }; - export class EchoBinary__Args extends thrift.StructLike implements IEchoBinary__Args { - public word: Buffer; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IEchoBinary__ArgsArgs) { - super(); - if (args.word != null) { - const value_34: Buffer = (typeof args.word === "string" ? Buffer.from(args.word) : args.word); - this.word = value_34; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[word] is unset!"); - } - } - public static read(input: thrift.TProtocol): EchoBinary__Args { - return new EchoBinary__Args(EchoBinary__ArgsCodec.decode(input)); - } - public static write(args: IEchoBinary__ArgsArgs, output: thrift.TProtocol): void { - return EchoBinary__ArgsCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return EchoBinary__ArgsCodec.encode(this, output); - } - } - export interface IEchoString__Args { - word: string; - } - export interface IEchoString__ArgsArgs { - word: string; - } - export const EchoString__ArgsCodec: thrift.IStructCodec = { - encode(args: IEchoString__ArgsArgs, output: thrift.TProtocol): void { - const obj = { - word: args.word - }; - output.writeStructBegin("EchoString__Args"); - if (obj.word != null) { - output.writeFieldBegin("word", thrift.TType.STRING, 1); - output.writeString(obj.word); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[word] is unset!"); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IEchoString__Args { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.STRING) { - const value_35: string = input.readString(); - _args.word = value_35; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.word !== undefined) { - return { - word: _args.word - }; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read EchoString__Args from input"); - } - } - }; - export class EchoString__Args extends thrift.StructLike implements IEchoString__Args { - public word: string; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IEchoString__ArgsArgs) { - super(); - if (args.word != null) { - const value_36: string = args.word; - this.word = value_36; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[word] is unset!"); - } - } - public static read(input: thrift.TProtocol): EchoString__Args { - return new EchoString__Args(EchoString__ArgsCodec.decode(input)); - } - public static write(args: IEchoString__ArgsArgs, output: thrift.TProtocol): void { - return EchoString__ArgsCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return EchoString__ArgsCodec.encode(this, output); - } - } - export interface ICheckName__Args { - choice: IChoice; - } - export interface ICheckName__ArgsArgs { - choice: IChoiceArgs; - } - export const CheckName__ArgsCodec: thrift.IStructCodec = { - encode(args: ICheckName__ArgsArgs, output: thrift.TProtocol): void { - const obj = { - choice: args.choice - }; - output.writeStructBegin("CheckName__Args"); - if (obj.choice != null) { - output.writeFieldBegin("choice", thrift.TType.STRUCT, 1); - ChoiceCodec.encode(obj.choice, output); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[choice] is unset!"); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): ICheckName__Args { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.STRUCT) { - const value_37: IChoice = ChoiceCodec.decode(input); - _args.choice = value_37; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.choice !== undefined) { - return { - choice: _args.choice - }; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read CheckName__Args from input"); - } - } - }; - export class CheckName__Args extends thrift.StructLike implements ICheckName__Args { - public choice: IChoice; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: ICheckName__ArgsArgs) { - super(); - if (args.choice != null) { - const value_38: IChoice = new Choice(args.choice); - this.choice = value_38; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[choice] is unset!"); - } - } - public static read(input: thrift.TProtocol): CheckName__Args { - return new CheckName__Args(CheckName__ArgsCodec.decode(input)); - } - public static write(args: ICheckName__ArgsArgs, output: thrift.TProtocol): void { - return CheckName__ArgsCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return CheckName__ArgsCodec.encode(this, output); - } - } - export interface ICheckOptional__Args { - type?: string; - } - export interface ICheckOptional__ArgsArgs { - type?: string; - } - export const CheckOptional__ArgsCodec: thrift.IStructCodec = { - encode(args: ICheckOptional__ArgsArgs, output: thrift.TProtocol): void { - const obj = { - type: args.type - }; - output.writeStructBegin("CheckOptional__Args"); - if (obj.type != null) { - output.writeFieldBegin("type", thrift.TType.STRING, 1); - output.writeString(obj.type); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): ICheckOptional__Args { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.STRING) { - const value_39: string = input.readString(); - _args.type = value_39; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - type: _args.type - }; - } - }; - export class CheckOptional__Args extends thrift.StructLike implements ICheckOptional__Args { - public type?: string; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: ICheckOptional__ArgsArgs = {}) { - super(); - if (args.type != null) { - const value_40: string = args.type; - this.type = value_40; - } - } - public static read(input: thrift.TProtocol): CheckOptional__Args { - return new CheckOptional__Args(CheckOptional__ArgsCodec.decode(input)); - } - public static write(args: ICheckOptional__ArgsArgs, output: thrift.TProtocol): void { - return CheckOptional__ArgsCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return CheckOptional__ArgsCodec.encode(this, output); - } - } - export interface IMapOneList__Args { - arg: Array; - } - export interface IMapOneList__ArgsArgs { - arg: Array; - } - export const MapOneList__ArgsCodec: thrift.IStructCodec = { - encode(args: IMapOneList__ArgsArgs, output: thrift.TProtocol): void { - const obj = { - arg: args.arg - }; - output.writeStructBegin("MapOneList__Args"); - if (obj.arg != null) { - output.writeFieldBegin("arg", thrift.TType.LIST, 1); - output.writeListBegin(thrift.TType.I32, obj.arg.length); - obj.arg.forEach((value_41: number): void => { - output.writeI32(value_41); - }); - output.writeListEnd(); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[arg] is unset!"); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IMapOneList__Args { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.LIST) { - const value_42: Array = new Array(); - const metadata_1: thrift.IThriftList = input.readListBegin(); - const size_1: number = metadata_1.size; - for (let i_1: number = 0; i_1 < size_1; i_1++) { - const value_43: number = input.readI32(); - value_42.push(value_43); - } - input.readListEnd(); - _args.arg = value_42; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.arg !== undefined) { - return { - arg: _args.arg - }; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read MapOneList__Args from input"); - } - } - }; - export class MapOneList__Args extends thrift.StructLike implements IMapOneList__Args { - public arg: Array; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IMapOneList__ArgsArgs) { - super(); - if (args.arg != null) { - const value_44: Array = new Array(); - args.arg.forEach((value_45: number): void => { - const value_46: number = value_45; - value_44.push(value_46); - }); - this.arg = value_44; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[arg] is unset!"); - } - } - public static read(input: thrift.TProtocol): MapOneList__Args { - return new MapOneList__Args(MapOneList__ArgsCodec.decode(input)); - } - public static write(args: IMapOneList__ArgsArgs, output: thrift.TProtocol): void { - return MapOneList__ArgsCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return MapOneList__ArgsCodec.encode(this, output); - } - } - export interface IMapValues__Args { - arg: Map; - } - export interface IMapValues__ArgsArgs { - arg: Map; - } - export const MapValues__ArgsCodec: thrift.IStructCodec = { - encode(args: IMapValues__ArgsArgs, output: thrift.TProtocol): void { - const obj = { - arg: args.arg - }; - output.writeStructBegin("MapValues__Args"); - if (obj.arg != null) { - output.writeFieldBegin("arg", thrift.TType.MAP, 1); - output.writeMapBegin(thrift.TType.STRING, thrift.TType.I32, obj.arg.size); - obj.arg.forEach((value_47: number, key_1: string): void => { - output.writeString(key_1); - output.writeI32(value_47); - }); - output.writeMapEnd(); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[arg] is unset!"); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IMapValues__Args { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.MAP) { - const value_48: Map = new Map(); - const metadata_2: thrift.IThriftMap = input.readMapBegin(); - const size_2: number = metadata_2.size; - for (let i_2: number = 0; i_2 < size_2; i_2++) { - const key_2: string = input.readString(); - const value_49: number = input.readI32(); - value_48.set(key_2, value_49); - } - input.readMapEnd(); - _args.arg = value_48; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.arg !== undefined) { - return { - arg: _args.arg - }; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read MapValues__Args from input"); - } - } - }; - export class MapValues__Args extends thrift.StructLike implements IMapValues__Args { - public arg: Map; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IMapValues__ArgsArgs) { - super(); - if (args.arg != null) { - const value_50: Map = new Map(); - args.arg.forEach((value_51: number, key_3: string): void => { - const value_52: number = value_51; - const key_4: string = key_3; - value_50.set(key_4, value_52); - }); - this.arg = value_50; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[arg] is unset!"); - } - } - public static read(input: thrift.TProtocol): MapValues__Args { - return new MapValues__Args(MapValues__ArgsCodec.decode(input)); - } - public static write(args: IMapValues__ArgsArgs, output: thrift.TProtocol): void { - return MapValues__ArgsCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return MapValues__ArgsCodec.encode(this, output); - } - } - export interface IListToMap__Args { - arg: Array>; - } - export interface IListToMap__ArgsArgs { - arg: Array>; - } - export const ListToMap__ArgsCodec: thrift.IStructCodec = { - encode(args: IListToMap__ArgsArgs, output: thrift.TProtocol): void { - const obj = { - arg: args.arg - }; - output.writeStructBegin("ListToMap__Args"); - if (obj.arg != null) { - output.writeFieldBegin("arg", thrift.TType.LIST, 1); - output.writeListBegin(thrift.TType.LIST, obj.arg.length); - obj.arg.forEach((value_53: Array): void => { - output.writeListBegin(thrift.TType.STRING, value_53.length); - value_53.forEach((value_54: string): void => { - output.writeString(value_54); - }); - output.writeListEnd(); - }); - output.writeListEnd(); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[arg] is unset!"); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IListToMap__Args { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.LIST) { - const value_55: Array> = new Array>(); - const metadata_3: thrift.IThriftList = input.readListBegin(); - const size_3: number = metadata_3.size; - for (let i_3: number = 0; i_3 < size_3; i_3++) { - const value_56: Array = new Array(); - const metadata_4: thrift.IThriftList = input.readListBegin(); - const size_4: number = metadata_4.size; - for (let i_4: number = 0; i_4 < size_4; i_4++) { - const value_57: string = input.readString(); - value_56.push(value_57); - } - input.readListEnd(); - value_55.push(value_56); - } - input.readListEnd(); - _args.arg = value_55; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.arg !== undefined) { - return { - arg: _args.arg - }; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read ListToMap__Args from input"); - } - } - }; - export class ListToMap__Args extends thrift.StructLike implements IListToMap__Args { - public arg: Array>; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IListToMap__ArgsArgs) { - super(); - if (args.arg != null) { - const value_58: Array> = new Array>(); - args.arg.forEach((value_59: Array): void => { - const value_60: Array = new Array(); - value_59.forEach((value_61: string): void => { - const value_62: string = value_61; - value_60.push(value_62); - }); - value_58.push(value_60); - }); - this.arg = value_58; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[arg] is unset!"); - } - } - public static read(input: thrift.TProtocol): ListToMap__Args { - return new ListToMap__Args(ListToMap__ArgsCodec.decode(input)); - } - public static write(args: IListToMap__ArgsArgs, output: thrift.TProtocol): void { - return ListToMap__ArgsCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return ListToMap__ArgsCodec.encode(this, output); - } - } - export interface IFetchThing__Args { - } - export interface IFetchThing__ArgsArgs { - } - export const FetchThing__ArgsCodec: thrift.IStructCodec = { - encode(args: IFetchThing__ArgsArgs, output: thrift.TProtocol): void { - output.writeStructBegin("FetchThing__Args"); - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IFetchThing__Args { - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return {}; - } - }; - export class FetchThing__Args extends thrift.StructLike implements IFetchThing__Args { - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IFetchThing__ArgsArgs = {}) { - super(); - } - public static read(input: thrift.TProtocol): FetchThing__Args { - return new FetchThing__Args(FetchThing__ArgsCodec.decode(input)); - } - public static write(args: IFetchThing__ArgsArgs, output: thrift.TProtocol): void { - return FetchThing__ArgsCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return FetchThing__ArgsCodec.encode(this, output); - } - } - export interface IZip__Args { - } - export interface IZip__ArgsArgs { - } - export const Zip__ArgsCodec: thrift.IStructCodec = { - encode(args: IZip__ArgsArgs, output: thrift.TProtocol): void { - output.writeStructBegin("Zip__Args"); - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IZip__Args { - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return {}; - } - }; - export class Zip__Args extends thrift.StructLike implements IZip__Args { - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IZip__ArgsArgs = {}) { - super(); - } - public static read(input: thrift.TProtocol): Zip__Args { - return new Zip__Args(Zip__ArgsCodec.decode(input)); - } - public static write(args: IZip__ArgsArgs, output: thrift.TProtocol): void { - return Zip__ArgsCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return Zip__ArgsCodec.encode(this, output); - } - } - export interface IPing__Result { - success?: void; - } - export interface IPing__ResultArgs { - success?: void; - } - export const Ping__ResultCodec: thrift.IStructCodec = { - encode(args: IPing__ResultArgs, output: thrift.TProtocol): void { - output.writeStructBegin("Ping__Result"); - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IPing__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.VOID) { - input.skip(fieldType); - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - success: _args.success - }; - } - }; - export class Ping__Result extends thrift.StructLike implements IPing__Result { - public success?: void; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IPing__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_63: void = undefined; - this.success = value_63; - } - } - public static read(input: thrift.TProtocol): Ping__Result { - return new Ping__Result(Ping__ResultCodec.decode(input)); - } - public static write(args: IPing__ResultArgs, output: thrift.TProtocol): void { - return Ping__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return Ping__ResultCodec.encode(this, output); - } - } - export interface IAdd__Result { - success?: number; - exp?: operation.IJankyResult; - } - export interface IAdd__ResultArgs { - success?: number; - exp?: operation.IJankyResultArgs; - } - export const Add__ResultCodec: thrift.IStructCodec = { - encode(args: IAdd__ResultArgs, output: thrift.TProtocol): void { - const obj = { - success: args.success, - exp: args.exp - }; - output.writeStructBegin("Add__Result"); - if (obj.success != null) { - output.writeFieldBegin("success", thrift.TType.I32, 0); - output.writeI32(obj.success); - output.writeFieldEnd(); - } - if (obj.exp != null) { - output.writeFieldBegin("exp", thrift.TType.STRUCT, 1); - operation.JankyResultCodec.encode(obj.exp, output); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IAdd__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.I32) { - const value_64: number = input.readI32(); - _args.success = value_64; - } - else { - input.skip(fieldType); - } - break; - case 1: - if (fieldType === thrift.TType.STRUCT) { - const value_65: operation.IJankyResult = operation.JankyResultCodec.decode(input); - _args.exp = value_65; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - success: _args.success, - exp: _args.exp - }; - } - }; - export class Add__Result extends thrift.StructLike implements IAdd__Result { - public success?: number; - public exp?: operation.IJankyResult; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IAdd__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_66: number = args.success; - this.success = value_66; - } - if (args.exp != null) { - const value_67: operation.IJankyResult = new operation.JankyResult(args.exp); - this.exp = value_67; - } - } - public static read(input: thrift.TProtocol): Add__Result { - return new Add__Result(Add__ResultCodec.decode(input)); - } - public static write(args: IAdd__ResultArgs, output: thrift.TProtocol): void { - return Add__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return Add__ResultCodec.encode(this, output); - } - } - export interface IAddInt64__Result { - success?: thrift.Int64; - } - export interface IAddInt64__ResultArgs { - success?: number | string | thrift.Int64; - } - export const AddInt64__ResultCodec: thrift.IStructCodec = { - encode(args: IAddInt64__ResultArgs, output: thrift.TProtocol): void { - const obj = { - success: (typeof args.success === "number" ? new thrift.Int64(args.success) : typeof args.success === "string" ? thrift.Int64.fromDecimalString(args.success) : args.success) - }; - output.writeStructBegin("AddInt64__Result"); - if (obj.success != null) { - output.writeFieldBegin("success", thrift.TType.I64, 0); - output.writeI64((typeof obj.success === "number" ? new thrift.Int64(obj.success) : typeof obj.success === "string" ? thrift.Int64.fromDecimalString(obj.success) : obj.success)); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IAddInt64__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.I64) { - const value_68: thrift.Int64 = input.readI64(); - _args.success = value_68; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - success: _args.success - }; - } - }; - export class AddInt64__Result extends thrift.StructLike implements IAddInt64__Result { - public success?: thrift.Int64; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IAddInt64__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_69: thrift.Int64 = (typeof args.success === "number" ? new thrift.Int64(args.success) : typeof args.success === "string" ? thrift.Int64.fromDecimalString(args.success) : args.success); - this.success = value_69; - } - } - public static read(input: thrift.TProtocol): AddInt64__Result { - return new AddInt64__Result(AddInt64__ResultCodec.decode(input)); - } - public static write(args: IAddInt64__ResultArgs, output: thrift.TProtocol): void { - return AddInt64__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return AddInt64__ResultCodec.encode(this, output); - } - } - export interface IAddWithContext__Result { - success?: number; - } - export interface IAddWithContext__ResultArgs { - success?: number; - } - export const AddWithContext__ResultCodec: thrift.IStructCodec = { - encode(args: IAddWithContext__ResultArgs, output: thrift.TProtocol): void { - const obj = { - success: args.success - }; - output.writeStructBegin("AddWithContext__Result"); - if (obj.success != null) { - output.writeFieldBegin("success", thrift.TType.I32, 0); - output.writeI32(obj.success); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IAddWithContext__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.I32) { - const value_70: number = input.readI32(); - _args.success = value_70; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - success: _args.success - }; - } - }; - export class AddWithContext__Result extends thrift.StructLike implements IAddWithContext__Result { - public success?: number; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IAddWithContext__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_71: number = args.success; - this.success = value_71; - } - } - public static read(input: thrift.TProtocol): AddWithContext__Result { - return new AddWithContext__Result(AddWithContext__ResultCodec.decode(input)); - } - public static write(args: IAddWithContext__ResultArgs, output: thrift.TProtocol): void { - return AddWithContext__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return AddWithContext__ResultCodec.encode(this, output); - } - } - export interface ICalculate__Result { - success?: number; - ouch?: operation.IJankyOperation; - } - export interface ICalculate__ResultArgs { - success?: number; - ouch?: operation.IJankyOperationArgs; - } - export const Calculate__ResultCodec: thrift.IStructCodec = { - encode(args: ICalculate__ResultArgs, output: thrift.TProtocol): void { - const obj = { - success: args.success, - ouch: args.ouch - }; - output.writeStructBegin("Calculate__Result"); - if (obj.success != null) { - output.writeFieldBegin("success", thrift.TType.I32, 0); - output.writeI32(obj.success); - output.writeFieldEnd(); - } - if (obj.ouch != null) { - output.writeFieldBegin("ouch", thrift.TType.STRUCT, 1); - operation.JankyOperationCodec.encode(obj.ouch, output); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): ICalculate__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.I32) { - const value_72: number = input.readI32(); - _args.success = value_72; - } - else { - input.skip(fieldType); - } - break; - case 1: - if (fieldType === thrift.TType.STRUCT) { - const value_73: operation.IJankyOperation = operation.JankyOperationCodec.decode(input); - _args.ouch = value_73; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - success: _args.success, - ouch: _args.ouch - }; - } - }; - export class Calculate__Result extends thrift.StructLike implements ICalculate__Result { - public success?: number; - public ouch?: operation.IJankyOperation; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: ICalculate__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_74: number = args.success; - this.success = value_74; - } - if (args.ouch != null) { - const value_75: operation.IJankyOperation = new operation.JankyOperation(args.ouch); - this.ouch = value_75; - } - } - public static read(input: thrift.TProtocol): Calculate__Result { - return new Calculate__Result(Calculate__ResultCodec.decode(input)); - } - public static write(args: ICalculate__ResultArgs, output: thrift.TProtocol): void { - return Calculate__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return Calculate__ResultCodec.encode(this, output); - } - } - export interface IEchoBinary__Result { - success?: string; - } - export interface IEchoBinary__ResultArgs { - success?: string; - } - export const EchoBinary__ResultCodec: thrift.IStructCodec = { - encode(args: IEchoBinary__ResultArgs, output: thrift.TProtocol): void { - const obj = { - success: args.success - }; - output.writeStructBegin("EchoBinary__Result"); - if (obj.success != null) { - output.writeFieldBegin("success", thrift.TType.STRING, 0); - output.writeString(obj.success); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IEchoBinary__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.STRING) { - const value_76: string = input.readString(); - _args.success = value_76; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - success: _args.success - }; - } - }; - export class EchoBinary__Result extends thrift.StructLike implements IEchoBinary__Result { - public success?: string; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IEchoBinary__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_77: string = args.success; - this.success = value_77; - } - } - public static read(input: thrift.TProtocol): EchoBinary__Result { - return new EchoBinary__Result(EchoBinary__ResultCodec.decode(input)); - } - public static write(args: IEchoBinary__ResultArgs, output: thrift.TProtocol): void { - return EchoBinary__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return EchoBinary__ResultCodec.encode(this, output); - } - } - export interface IEchoString__Result { - success?: string; - } - export interface IEchoString__ResultArgs { - success?: string; - } - export const EchoString__ResultCodec: thrift.IStructCodec = { - encode(args: IEchoString__ResultArgs, output: thrift.TProtocol): void { - const obj = { - success: args.success - }; - output.writeStructBegin("EchoString__Result"); - if (obj.success != null) { - output.writeFieldBegin("success", thrift.TType.STRING, 0); - output.writeString(obj.success); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IEchoString__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.STRING) { - const value_78: string = input.readString(); - _args.success = value_78; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - success: _args.success - }; - } - }; - export class EchoString__Result extends thrift.StructLike implements IEchoString__Result { - public success?: string; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IEchoString__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_79: string = args.success; - this.success = value_79; - } - } - public static read(input: thrift.TProtocol): EchoString__Result { - return new EchoString__Result(EchoString__ResultCodec.decode(input)); - } - public static write(args: IEchoString__ResultArgs, output: thrift.TProtocol): void { - return EchoString__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return EchoString__ResultCodec.encode(this, output); - } - } - export interface ICheckName__Result { - success?: string; - } - export interface ICheckName__ResultArgs { - success?: string; - } - export const CheckName__ResultCodec: thrift.IStructCodec = { - encode(args: ICheckName__ResultArgs, output: thrift.TProtocol): void { - const obj = { - success: args.success - }; - output.writeStructBegin("CheckName__Result"); - if (obj.success != null) { - output.writeFieldBegin("success", thrift.TType.STRING, 0); - output.writeString(obj.success); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): ICheckName__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.STRING) { - const value_80: string = input.readString(); - _args.success = value_80; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - success: _args.success - }; - } - }; - export class CheckName__Result extends thrift.StructLike implements ICheckName__Result { - public success?: string; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: ICheckName__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_81: string = args.success; - this.success = value_81; - } - } - public static read(input: thrift.TProtocol): CheckName__Result { - return new CheckName__Result(CheckName__ResultCodec.decode(input)); - } - public static write(args: ICheckName__ResultArgs, output: thrift.TProtocol): void { - return CheckName__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return CheckName__ResultCodec.encode(this, output); - } - } - export interface ICheckOptional__Result { - success?: string; - } - export interface ICheckOptional__ResultArgs { - success?: string; - } - export const CheckOptional__ResultCodec: thrift.IStructCodec = { - encode(args: ICheckOptional__ResultArgs, output: thrift.TProtocol): void { - const obj = { - success: args.success - }; - output.writeStructBegin("CheckOptional__Result"); - if (obj.success != null) { - output.writeFieldBegin("success", thrift.TType.STRING, 0); - output.writeString(obj.success); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): ICheckOptional__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.STRING) { - const value_82: string = input.readString(); - _args.success = value_82; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - success: _args.success - }; - } - }; - export class CheckOptional__Result extends thrift.StructLike implements ICheckOptional__Result { - public success?: string; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: ICheckOptional__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_83: string = args.success; - this.success = value_83; - } - } - public static read(input: thrift.TProtocol): CheckOptional__Result { - return new CheckOptional__Result(CheckOptional__ResultCodec.decode(input)); - } - public static write(args: ICheckOptional__ResultArgs, output: thrift.TProtocol): void { - return CheckOptional__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return CheckOptional__ResultCodec.encode(this, output); - } - } - export interface IMapOneList__Result { - success?: Array; - } - export interface IMapOneList__ResultArgs { - success?: Array; - } - export const MapOneList__ResultCodec: thrift.IStructCodec = { - encode(args: IMapOneList__ResultArgs, output: thrift.TProtocol): void { - const obj = { - success: args.success - }; - output.writeStructBegin("MapOneList__Result"); - if (obj.success != null) { - output.writeFieldBegin("success", thrift.TType.LIST, 0); - output.writeListBegin(thrift.TType.I32, obj.success.length); - obj.success.forEach((value_84: number): void => { - output.writeI32(value_84); - }); - output.writeListEnd(); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IMapOneList__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.LIST) { - const value_85: Array = new Array(); - const metadata_5: thrift.IThriftList = input.readListBegin(); - const size_5: number = metadata_5.size; - for (let i_5: number = 0; i_5 < size_5; i_5++) { - const value_86: number = input.readI32(); - value_85.push(value_86); - } - input.readListEnd(); - _args.success = value_85; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - success: _args.success - }; - } - }; - export class MapOneList__Result extends thrift.StructLike implements IMapOneList__Result { - public success?: Array; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IMapOneList__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_87: Array = new Array(); - args.success.forEach((value_88: number): void => { - const value_89: number = value_88; - value_87.push(value_89); - }); - this.success = value_87; - } - } - public static read(input: thrift.TProtocol): MapOneList__Result { - return new MapOneList__Result(MapOneList__ResultCodec.decode(input)); - } - public static write(args: IMapOneList__ResultArgs, output: thrift.TProtocol): void { - return MapOneList__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return MapOneList__ResultCodec.encode(this, output); - } - } - export interface IMapValues__Result { - success?: Array; - } - export interface IMapValues__ResultArgs { - success?: Array; - } - export const MapValues__ResultCodec: thrift.IStructCodec = { - encode(args: IMapValues__ResultArgs, output: thrift.TProtocol): void { - const obj = { - success: args.success - }; - output.writeStructBegin("MapValues__Result"); - if (obj.success != null) { - output.writeFieldBegin("success", thrift.TType.LIST, 0); - output.writeListBegin(thrift.TType.I32, obj.success.length); - obj.success.forEach((value_90: number): void => { - output.writeI32(value_90); - }); - output.writeListEnd(); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IMapValues__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.LIST) { - const value_91: Array = new Array(); - const metadata_6: thrift.IThriftList = input.readListBegin(); - const size_6: number = metadata_6.size; - for (let i_6: number = 0; i_6 < size_6; i_6++) { - const value_92: number = input.readI32(); - value_91.push(value_92); - } - input.readListEnd(); - _args.success = value_91; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - success: _args.success - }; - } - }; - export class MapValues__Result extends thrift.StructLike implements IMapValues__Result { - public success?: Array; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IMapValues__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_93: Array = new Array(); - args.success.forEach((value_94: number): void => { - const value_95: number = value_94; - value_93.push(value_95); - }); - this.success = value_93; - } - } - public static read(input: thrift.TProtocol): MapValues__Result { - return new MapValues__Result(MapValues__ResultCodec.decode(input)); - } - public static write(args: IMapValues__ResultArgs, output: thrift.TProtocol): void { - return MapValues__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return MapValues__ResultCodec.encode(this, output); - } - } - export interface IListToMap__Result { - success?: Map; - } - export interface IListToMap__ResultArgs { - success?: Map; - } - export const ListToMap__ResultCodec: thrift.IStructCodec = { - encode(args: IListToMap__ResultArgs, output: thrift.TProtocol): void { - const obj = { - success: args.success - }; - output.writeStructBegin("ListToMap__Result"); - if (obj.success != null) { - output.writeFieldBegin("success", thrift.TType.MAP, 0); - output.writeMapBegin(thrift.TType.STRING, thrift.TType.STRING, obj.success.size); - obj.success.forEach((value_96: string, key_5: string): void => { - output.writeString(key_5); - output.writeString(value_96); - }); - output.writeMapEnd(); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IListToMap__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.MAP) { - const value_97: Map = new Map(); - const metadata_7: thrift.IThriftMap = input.readMapBegin(); - const size_7: number = metadata_7.size; - for (let i_7: number = 0; i_7 < size_7; i_7++) { - const key_6: string = input.readString(); - const value_98: string = input.readString(); - value_97.set(key_6, value_98); - } - input.readMapEnd(); - _args.success = value_97; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - success: _args.success - }; - } - }; - export class ListToMap__Result extends thrift.StructLike implements IListToMap__Result { - public success?: Map; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IListToMap__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_99: Map = new Map(); - args.success.forEach((value_100: string, key_7: string): void => { - const value_101: string = value_100; - const key_8: string = key_7; - value_99.set(key_8, value_101); - }); - this.success = value_99; - } - } - public static read(input: thrift.TProtocol): ListToMap__Result { - return new ListToMap__Result(ListToMap__ResultCodec.decode(input)); - } - public static write(args: IListToMap__ResultArgs, output: thrift.TProtocol): void { - return ListToMap__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return ListToMap__ResultCodec.encode(this, output); - } - } - export interface IFetchThing__Result { - success?: common.ICommonStruct; - } - export interface IFetchThing__ResultArgs { - success?: common.ICommonStructArgs; - } - export const FetchThing__ResultCodec: thrift.IStructCodec = { - encode(args: IFetchThing__ResultArgs, output: thrift.TProtocol): void { - const obj = { - success: args.success - }; - output.writeStructBegin("FetchThing__Result"); - if (obj.success != null) { - output.writeFieldBegin("success", thrift.TType.STRUCT, 0); - common.CommonStructCodec.encode(obj.success, output); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IFetchThing__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.STRUCT) { - const value_102: common.ICommonStruct = common.CommonStructCodec.decode(input); - _args.success = value_102; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - success: _args.success - }; - } - }; - export class FetchThing__Result extends thrift.StructLike implements IFetchThing__Result { - public success?: common.ICommonStruct; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IFetchThing__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_103: common.ICommonStruct = new common.CommonStruct(args.success); - this.success = value_103; - } - } - public static read(input: thrift.TProtocol): FetchThing__Result { - return new FetchThing__Result(FetchThing__ResultCodec.decode(input)); - } - public static write(args: IFetchThing__ResultArgs, output: thrift.TProtocol): void { - return FetchThing__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return FetchThing__ResultCodec.encode(this, output); - } - } - export interface IZip__Result { - success?: void; - } - export interface IZip__ResultArgs { - success?: void; - } - export const Zip__ResultCodec: thrift.IStructCodec = { - encode(args: IZip__ResultArgs, output: thrift.TProtocol): void { - output.writeStructBegin("Zip__Result"); - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IZip__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.VOID) { - input.skip(fieldType); - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - success: _args.success - }; - } - }; - export class Zip__Result extends thrift.StructLike implements IZip__Result { - public success?: void; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IZip__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_104: void = undefined; - this.success = value_104; - } - } - public static read(input: thrift.TProtocol): Zip__Result { - return new Zip__Result(Zip__ResultCodec.decode(input)); - } - public static write(args: IZip__ResultArgs, output: thrift.TProtocol): void { - return Zip__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return Zip__ResultCodec.encode(this, output); - } - } - export class Client extends shared.SharedService.Client { - public static readonly serviceName: string = serviceName; - public static readonly annotations: thrift.IThriftAnnotations = annotations; - public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public static readonly methodNames: Array = methodNames; - public readonly _serviceName: string = serviceName; - public readonly _annotations: thrift.IThriftAnnotations = annotations; - public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public readonly _methodNames: Array = methodNames; - constructor(connection: thrift.IThriftConnection) { - super(connection); - } - public ping(context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("ping", thrift.MessageType.CALL, this.incrementRequestId()); - const args: IPing__ArgsArgs = {}; - Ping__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "ping") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: IPing__Result = Ping__ResultCodec.decode(input); - input.readMessageEnd(); - return Promise.resolve(result.success); - } - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } - } - catch (err) { - return Promise.reject(err); - } - }); - } - public add(num1: number, num2: number, context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("add", thrift.MessageType.CALL, this.incrementRequestId()); - const args: IAdd__ArgsArgs = { num1, num2 }; - Add__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "add") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: IAdd__Result = Add__ResultCodec.decode(input); - input.readMessageEnd(); - if (result.exp != null) { - return Promise.reject(result.exp); - } - else if (result.success != null) { - return Promise.resolve(result.success); - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "add failed: unknown result")); - } - } - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } - } - catch (err) { - return Promise.reject(err); - } - }); - } - public addInt64(num1: number | string | thrift.Int64, num2: number | string | thrift.Int64, context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("addInt64", thrift.MessageType.CALL, this.incrementRequestId()); - const args: IAddInt64__ArgsArgs = { num1, num2 }; - AddInt64__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "addInt64") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: IAddInt64__Result = AddInt64__ResultCodec.decode(input); - input.readMessageEnd(); - if (result.success != null) { - return Promise.resolve(result.success); - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "addInt64 failed: unknown result")); - } - } - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } - } - catch (err) { - return Promise.reject(err); - } - }); - } - public addWithContext(num1: number, num2: number, context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("addWithContext", thrift.MessageType.CALL, this.incrementRequestId()); - const args: IAddWithContext__ArgsArgs = { num1, num2 }; - AddWithContext__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "addWithContext") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: IAddWithContext__Result = AddWithContext__ResultCodec.decode(input); - input.readMessageEnd(); - if (result.success != null) { - return Promise.resolve(result.success); - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "addWithContext failed: unknown result")); - } - } - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } - } - catch (err) { - return Promise.reject(err); - } - }); - } - public calculate(logid: number, work: IWorkArgs, context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("calculate", thrift.MessageType.CALL, this.incrementRequestId()); - const args: ICalculate__ArgsArgs = { logid, work }; - Calculate__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "calculate") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: ICalculate__Result = Calculate__ResultCodec.decode(input); - input.readMessageEnd(); - if (result.ouch != null) { - return Promise.reject(result.ouch); - } - else if (result.success != null) { - return Promise.resolve(result.success); - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "calculate failed: unknown result")); - } - } - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } - } - catch (err) { - return Promise.reject(err); - } - }); - } - public echoBinary(word: string | Buffer, context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("echoBinary", thrift.MessageType.CALL, this.incrementRequestId()); - const args: IEchoBinary__ArgsArgs = { word }; - EchoBinary__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "echoBinary") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: IEchoBinary__Result = EchoBinary__ResultCodec.decode(input); - input.readMessageEnd(); - if (result.success != null) { - return Promise.resolve(result.success); - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "echoBinary failed: unknown result")); - } - } - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } - } - catch (err) { - return Promise.reject(err); - } - }); - } - public echoString(word: string, context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("echoString", thrift.MessageType.CALL, this.incrementRequestId()); - const args: IEchoString__ArgsArgs = { word }; - EchoString__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "echoString") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: IEchoString__Result = EchoString__ResultCodec.decode(input); - input.readMessageEnd(); - if (result.success != null) { - return Promise.resolve(result.success); - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "echoString failed: unknown result")); - } - } - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } - } - catch (err) { - return Promise.reject(err); - } - }); - } - public checkName(choice: IChoiceArgs, context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("checkName", thrift.MessageType.CALL, this.incrementRequestId()); - const args: ICheckName__ArgsArgs = { choice }; - CheckName__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "checkName") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: ICheckName__Result = CheckName__ResultCodec.decode(input); - input.readMessageEnd(); - if (result.success != null) { - return Promise.resolve(result.success); - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "checkName failed: unknown result")); - } - } - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } - } - catch (err) { - return Promise.reject(err); - } - }); - } - public checkOptional(type?: string, context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("checkOptional", thrift.MessageType.CALL, this.incrementRequestId()); - const args: ICheckOptional__ArgsArgs = { type }; - CheckOptional__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "checkOptional") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: ICheckOptional__Result = CheckOptional__ResultCodec.decode(input); - input.readMessageEnd(); - if (result.success != null) { - return Promise.resolve(result.success); - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "checkOptional failed: unknown result")); - } - } - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } - } - catch (err) { - return Promise.reject(err); - } - }); - } - public mapOneList(arg: Array, context?: Context): Promise> { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("mapOneList", thrift.MessageType.CALL, this.incrementRequestId()); - const args: IMapOneList__ArgsArgs = { arg }; - MapOneList__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "mapOneList") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: IMapOneList__Result = MapOneList__ResultCodec.decode(input); - input.readMessageEnd(); - if (result.success != null) { - return Promise.resolve(result.success); - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "mapOneList failed: unknown result")); - } - } - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } - } - catch (err) { - return Promise.reject(err); - } - }); - } - public mapValues(arg: Map, context?: Context): Promise> { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("mapValues", thrift.MessageType.CALL, this.incrementRequestId()); - const args: IMapValues__ArgsArgs = { arg }; - MapValues__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "mapValues") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: IMapValues__Result = MapValues__ResultCodec.decode(input); - input.readMessageEnd(); - if (result.success != null) { - return Promise.resolve(result.success); - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "mapValues failed: unknown result")); - } - } - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } - } - catch (err) { - return Promise.reject(err); - } - }); - } - public listToMap(arg: Array>, context?: Context): Promise> { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("listToMap", thrift.MessageType.CALL, this.incrementRequestId()); - const args: IListToMap__ArgsArgs = { arg }; - ListToMap__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "listToMap") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: IListToMap__Result = ListToMap__ResultCodec.decode(input); - input.readMessageEnd(); - if (result.success != null) { - return Promise.resolve(result.success); - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "listToMap failed: unknown result")); - } - } - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } - } - catch (err) { - return Promise.reject(err); - } - }); - } - public fetchThing(context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("fetchThing", thrift.MessageType.CALL, this.incrementRequestId()); - const args: IFetchThing__ArgsArgs = {}; - FetchThing__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "fetchThing") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: IFetchThing__Result = FetchThing__ResultCodec.decode(input); - input.readMessageEnd(); - if (result.success != null) { - return Promise.resolve(result.success); - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "fetchThing failed: unknown result")); - } - } - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } - } - catch (err) { - return Promise.reject(err); - } - }); - } - public zip(context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("zip", thrift.MessageType.CALL, this.incrementRequestId()); - const args: IZip__ArgsArgs = {}; - Zip__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "zip") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: IZip__Result = Zip__ResultCodec.decode(input); - input.readMessageEnd(); - return Promise.resolve(result.success); - } - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } - } - catch (err) { - return Promise.reject(err); - } - }); - } - } - export interface ILocalHandler { - ping(context?: Context): void | Promise; - add(num1: number, num2: number, context?: Context): number | Promise; - addInt64(num1: thrift.Int64, num2: thrift.Int64, context?: Context): (number | string | thrift.Int64) | Promise; - addWithContext(num1: number, num2: number, context?: Context): number | Promise; - calculate(logid: number, work: IWork, context?: Context): number | Promise; - echoBinary(word: Buffer, context?: Context): string | Promise; - echoString(word: string, context?: Context): string | Promise; - checkName(choice: IChoice, context?: Context): string | Promise; - checkOptional(type?: string, context?: Context): string | Promise; - mapOneList(arg: Array, context?: Context): Array | Promise>; - mapValues(arg: Map, context?: Context): Array | Promise>; - listToMap(arg: Array>, context?: Context): Map | Promise>; - fetchThing(context?: Context): common.ICommonStructArgs | Promise; - zip(context?: Context): void | Promise; - } - export type IHandler = ILocalHandler & shared.SharedService.IHandler; - export class Processor extends shared.SharedService.Processor { - protected readonly _handler: IHandler; - public static readonly serviceName: string = serviceName; - public static readonly annotations: thrift.IThriftAnnotations = annotations; - public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public static readonly methodNames: Array = methodNames; - public readonly _serviceName: string = serviceName; - public readonly _annotations: thrift.IThriftAnnotations = annotations; - public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public readonly _methodNames: Array = methodNames; - constructor(handler: IHandler) { - super({ - getStruct: handler.getStruct, - getUnion: handler.getUnion - }); - this._handler = handler; - } - public process(input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - const metadata: thrift.IThriftMessage = input.readMessageBegin(); - const fieldName: string = metadata.fieldName; - const requestId: number = metadata.requestId; - const methodName: string = "process_" + fieldName; - switch (methodName) { - case "process_getStruct": { - resolve(this.process_getStruct(requestId, input, output, context)); - break; - } - case "process_getUnion": { - resolve(this.process_getUnion(requestId, input, output, context)); - break; - } - case "process_ping": { - resolve(this.process_ping(requestId, input, output, context)); - break; - } - case "process_add": { - resolve(this.process_add(requestId, input, output, context)); - break; - } - case "process_addInt64": { - resolve(this.process_addInt64(requestId, input, output, context)); - break; - } - case "process_addWithContext": { - resolve(this.process_addWithContext(requestId, input, output, context)); - break; - } - case "process_calculate": { - resolve(this.process_calculate(requestId, input, output, context)); - break; - } - case "process_echoBinary": { - resolve(this.process_echoBinary(requestId, input, output, context)); - break; - } - case "process_echoString": { - resolve(this.process_echoString(requestId, input, output, context)); - break; - } - case "process_checkName": { - resolve(this.process_checkName(requestId, input, output, context)); - break; - } - case "process_checkOptional": { - resolve(this.process_checkOptional(requestId, input, output, context)); - break; - } - case "process_mapOneList": { - resolve(this.process_mapOneList(requestId, input, output, context)); - break; - } - case "process_mapValues": { - resolve(this.process_mapValues(requestId, input, output, context)); - break; - } - case "process_listToMap": { - resolve(this.process_listToMap(requestId, input, output, context)); - break; - } - case "process_fetchThing": { - resolve(this.process_fetchThing(requestId, input, output, context)); - break; - } - case "process_zip": { - resolve(this.process_zip(requestId, input, output, context)); - break; - } - default: { - input.skip(thrift.TType.STRUCT); - input.readMessageEnd(); - const errMessage = "Unknown function " + fieldName; - const err = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN_METHOD, errMessage); - output.writeMessageBegin(fieldName, thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(err, output); - output.writeMessageEnd(); - resolve(output.flush()); - break; - } - } - }); - } - public process_ping(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { - input.readMessageEnd(); - resolve(this._handler.ping(context)); - } - catch (err) { - reject(err); - } - }).then((data: void): Buffer => { - const result: IPing__ResultArgs = { success: data }; - output.writeMessageBegin("ping", thrift.MessageType.REPLY, requestId); - Ping__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("ping", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } - public process_add(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { - const args: IAdd__Args = Add__ArgsCodec.decode(input); - input.readMessageEnd(); - resolve(this._handler.add(args.num1, args.num2, context)); - } - catch (err) { - reject(err); - } - }).then((data: number): Buffer => { - const result: IAdd__ResultArgs = { success: data }; - output.writeMessageBegin("add", thrift.MessageType.REPLY, requestId); - Add__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - if (err instanceof operation.JankyResult) { - const result: IAdd__ResultArgs = { exp: err }; - output.writeMessageBegin("add", thrift.MessageType.REPLY, requestId); - Add__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - } - else { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("add", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - } - }); - } - public process_addInt64(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { - const args: IAddInt64__Args = AddInt64__ArgsCodec.decode(input); - input.readMessageEnd(); - resolve(this._handler.addInt64(args.num1, args.num2, context)); - } - catch (err) { - reject(err); - } - }).then((data: number | string | thrift.Int64): Buffer => { - const result: IAddInt64__ResultArgs = { success: data }; - output.writeMessageBegin("addInt64", thrift.MessageType.REPLY, requestId); - AddInt64__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("addInt64", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } - public process_addWithContext(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { - const args: IAddWithContext__Args = AddWithContext__ArgsCodec.decode(input); - input.readMessageEnd(); - resolve(this._handler.addWithContext(args.num1, args.num2, context)); - } - catch (err) { - reject(err); - } - }).then((data: number): Buffer => { - const result: IAddWithContext__ResultArgs = { success: data }; - output.writeMessageBegin("addWithContext", thrift.MessageType.REPLY, requestId); - AddWithContext__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("addWithContext", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } - public process_calculate(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { - const args: ICalculate__Args = Calculate__ArgsCodec.decode(input); - input.readMessageEnd(); - resolve(this._handler.calculate(args.logid, args.work, context)); - } - catch (err) { - reject(err); - } - }).then((data: number): Buffer => { - const result: ICalculate__ResultArgs = { success: data }; - output.writeMessageBegin("calculate", thrift.MessageType.REPLY, requestId); - Calculate__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - if (err instanceof operation.JankyOperation) { - const result: ICalculate__ResultArgs = { ouch: err }; - output.writeMessageBegin("calculate", thrift.MessageType.REPLY, requestId); - Calculate__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - } - else { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("calculate", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - } - }); - } - public process_echoBinary(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { - const args: IEchoBinary__Args = EchoBinary__ArgsCodec.decode(input); - input.readMessageEnd(); - resolve(this._handler.echoBinary(args.word, context)); - } - catch (err) { - reject(err); - } - }).then((data: string): Buffer => { - const result: IEchoBinary__ResultArgs = { success: data }; - output.writeMessageBegin("echoBinary", thrift.MessageType.REPLY, requestId); - EchoBinary__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("echoBinary", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } - public process_echoString(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { - const args: IEchoString__Args = EchoString__ArgsCodec.decode(input); - input.readMessageEnd(); - resolve(this._handler.echoString(args.word, context)); - } - catch (err) { - reject(err); - } - }).then((data: string): Buffer => { - const result: IEchoString__ResultArgs = { success: data }; - output.writeMessageBegin("echoString", thrift.MessageType.REPLY, requestId); - EchoString__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("echoString", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } - public process_checkName(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { - const args: ICheckName__Args = CheckName__ArgsCodec.decode(input); - input.readMessageEnd(); - resolve(this._handler.checkName(args.choice, context)); - } - catch (err) { - reject(err); - } - }).then((data: string): Buffer => { - const result: ICheckName__ResultArgs = { success: data }; - output.writeMessageBegin("checkName", thrift.MessageType.REPLY, requestId); - CheckName__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("checkName", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } - public process_checkOptional(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { - const args: ICheckOptional__Args = CheckOptional__ArgsCodec.decode(input); - input.readMessageEnd(); - resolve(this._handler.checkOptional(args.type, context)); - } - catch (err) { - reject(err); - } - }).then((data: string): Buffer => { - const result: ICheckOptional__ResultArgs = { success: data }; - output.writeMessageBegin("checkOptional", thrift.MessageType.REPLY, requestId); - CheckOptional__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("checkOptional", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } - public process_mapOneList(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise>((resolve, reject): void => { - try { - const args: IMapOneList__Args = MapOneList__ArgsCodec.decode(input); - input.readMessageEnd(); - resolve(this._handler.mapOneList(args.arg, context)); - } - catch (err) { - reject(err); - } - }).then((data: Array): Buffer => { - const result: IMapOneList__ResultArgs = { success: data }; - output.writeMessageBegin("mapOneList", thrift.MessageType.REPLY, requestId); - MapOneList__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("mapOneList", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } - public process_mapValues(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise>((resolve, reject): void => { - try { - const args: IMapValues__Args = MapValues__ArgsCodec.decode(input); - input.readMessageEnd(); - resolve(this._handler.mapValues(args.arg, context)); - } - catch (err) { - reject(err); - } - }).then((data: Array): Buffer => { - const result: IMapValues__ResultArgs = { success: data }; - output.writeMessageBegin("mapValues", thrift.MessageType.REPLY, requestId); - MapValues__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("mapValues", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } - public process_listToMap(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise>((resolve, reject): void => { - try { - const args: IListToMap__Args = ListToMap__ArgsCodec.decode(input); - input.readMessageEnd(); - resolve(this._handler.listToMap(args.arg, context)); - } - catch (err) { - reject(err); - } - }).then((data: Map): Buffer => { - const result: IListToMap__ResultArgs = { success: data }; - output.writeMessageBegin("listToMap", thrift.MessageType.REPLY, requestId); - ListToMap__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("listToMap", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } - public process_fetchThing(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { - input.readMessageEnd(); - resolve(this._handler.fetchThing(context)); - } - catch (err) { - reject(err); - } - }).then((data: common.ICommonStructArgs): Buffer => { - const result: IFetchThing__ResultArgs = { success: data }; - output.writeMessageBegin("fetchThing", thrift.MessageType.REPLY, requestId); - FetchThing__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("fetchThing", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } - public process_zip(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { - input.readMessageEnd(); - resolve(this._handler.zip(context)); - } - catch (err) { - reject(err); - } - }).then((data: void): Buffer => { - const result: IZip__ResultArgs = { success: data }; - output.writeMessageBegin("zip", thrift.MessageType.REPLY, requestId); - Zip__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("zip", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } - } -} diff --git a/src/tests/unit/fixtures/generated/exceptions/index.ts b/src/tests/unit/fixtures/generated/exceptions/index.ts deleted file mode 100644 index bf14ed8c..00000000 --- a/src/tests/unit/fixtures/generated/exceptions/index.ts +++ /dev/null @@ -1,201 +0,0 @@ -/* tslint:disable */ -/* - * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} - * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING -*/ -import * as thrift from "test-lib"; -import * as shared from "./../shared"; -export interface IInvalidOperation { - whatOp?: number; - why?: string; -} -export interface IInvalidOperationArgs { - whatOp?: number; - why?: string; -} -export const InvalidOperationCodec: thrift.IStructCodec = { - encode(args: IInvalidOperationArgs, output: thrift.TProtocol): void { - const obj = { - whatOp: args.whatOp, - why: args.why - }; - output.writeStructBegin("InvalidOperation"); - if (obj.whatOp != null) { - output.writeFieldBegin("whatOp", thrift.TType.I32, 1); - output.writeI32(obj.whatOp); - output.writeFieldEnd(); - } - if (obj.why != null) { - output.writeFieldBegin("why", thrift.TType.STRING, 2); - output.writeString(obj.why); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IInvalidOperation { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.I32) { - const value_1: number = input.readI32(); - _args.whatOp = value_1; - } - else { - input.skip(fieldType); - } - break; - case 2: - if (fieldType === thrift.TType.STRING) { - const value_2: string = input.readString(); - _args.why = value_2; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - whatOp: _args.whatOp, - why: _args.why - }; - } -}; -export class InvalidOperation extends thrift.StructLike implements IInvalidOperation { - public whatOp?: number; - public why?: string; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IInvalidOperationArgs = {}) { - super(); - if (args.whatOp != null) { - const value_3: number = args.whatOp; - this.whatOp = value_3; - } - if (args.why != null) { - const value_4: string = args.why; - this.why = value_4; - } - } - public static read(input: thrift.TProtocol): InvalidOperation { - return new InvalidOperation(InvalidOperationCodec.decode(input)); - } - public static write(args: IInvalidOperationArgs, output: thrift.TProtocol): void { - return InvalidOperationCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return InvalidOperationCodec.encode(this, output); - } -} -export interface IInvalidResult { - message?: string; - code?: shared.ICode; -} -export interface IInvalidResultArgs { - message?: string; - code?: shared.ICodeArgs; -} -export const InvalidResultCodec: thrift.IStructCodec = { - encode(args: IInvalidResultArgs, output: thrift.TProtocol): void { - const obj = { - message: args.message, - code: args.code - }; - output.writeStructBegin("InvalidResult"); - if (obj.message != null) { - output.writeFieldBegin("message", thrift.TType.STRING, 1); - output.writeString(obj.message); - output.writeFieldEnd(); - } - if (obj.code != null) { - output.writeFieldBegin("code", thrift.TType.STRUCT, 2); - shared.CodeCodec.encode(obj.code, output); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IInvalidResult { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.STRING) { - const value_5: string = input.readString(); - _args.message = value_5; - } - else { - input.skip(fieldType); - } - break; - case 2: - if (fieldType === thrift.TType.STRUCT) { - const value_6: shared.ICode = shared.CodeCodec.decode(input); - _args.code = value_6; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - message: _args.message, - code: _args.code - }; - } -}; -export class InvalidResult extends thrift.StructLike implements IInvalidResult { - public message?: string; - public code?: shared.ICode; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IInvalidResultArgs = {}) { - super(); - if (args.message != null) { - const value_7: string = args.message; - this.message = value_7; - } - if (args.code != null) { - const value_8: shared.ICode = new shared.Code(args.code); - this.code = value_8; - } - } - public static read(input: thrift.TProtocol): InvalidResult { - return new InvalidResult(InvalidResultCodec.decode(input)); - } - public static write(args: IInvalidResultArgs, output: thrift.TProtocol): void { - return InvalidResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return InvalidResultCodec.encode(this, output); - } -} diff --git a/src/tests/unit/fixtures/generated/operation/index.ts b/src/tests/unit/fixtures/generated/operation/index.ts deleted file mode 100644 index c25135b5..00000000 --- a/src/tests/unit/fixtures/generated/operation/index.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* tslint:disable */ -/* - * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} - * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING -*/ -import * as exceptions from "./../exceptions"; -export enum Operation { - ADD = 1, - SUBTRACT = 2, - MULTIPLY = 3, - DIVIDE = 4 -} -export import IJankyOperation = exceptions.IInvalidOperation; -export import IJankyOperationArgs = exceptions.IInvalidOperationArgs; -export import JankyOperation = exceptions.InvalidOperation; -export import JankyOperationCodec = exceptions.InvalidOperationCodec; -export import IJankyResult = exceptions.IInvalidResult; -export import IJankyResultArgs = exceptions.IInvalidResultArgs; -export import JankyResult = exceptions.InvalidResult; -export import JankyResultCodec = exceptions.InvalidResultCodec; -export import SomethingToDo = Operation; diff --git a/src/tests/unit/fixtures/generated/shared/index.ts b/src/tests/unit/fixtures/generated/shared/index.ts deleted file mode 100644 index 7d35f450..00000000 --- a/src/tests/unit/fixtures/generated/shared/index.ts +++ /dev/null @@ -1,836 +0,0 @@ -/* tslint:disable */ -/* - * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} - * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING -*/ -import * as thrift from "test-lib"; -export const SHARED_INT: number = 45; -export interface ICode { - status?: thrift.Int64; -} -export interface ICodeArgs { - status?: number | string | thrift.Int64; -} -export const CodeCodec: thrift.IStructCodec = { - encode(args: ICodeArgs, output: thrift.TProtocol): void { - const obj = { - status: (typeof args.status === "number" ? new thrift.Int64(args.status) : typeof args.status === "string" ? thrift.Int64.fromDecimalString(args.status) : args.status) - }; - output.writeStructBegin("Code"); - if (obj.status != null) { - output.writeFieldBegin("status", thrift.TType.I64, 1); - output.writeI64((typeof obj.status === "number" ? new thrift.Int64(obj.status) : typeof obj.status === "string" ? thrift.Int64.fromDecimalString(obj.status) : obj.status)); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): ICode { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.I64) { - const value_1: thrift.Int64 = input.readI64(); - _args.status = value_1; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - status: _args.status - }; - } -}; -export class Code extends thrift.StructLike implements ICode { - public status?: thrift.Int64; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: ICodeArgs = {}) { - super(); - if (args.status != null) { - const value_2: thrift.Int64 = (typeof args.status === "number" ? new thrift.Int64(args.status) : typeof args.status === "string" ? thrift.Int64.fromDecimalString(args.status) : args.status); - this.status = value_2; - } - } - public static read(input: thrift.TProtocol): Code { - return new Code(CodeCodec.decode(input)); - } - public static write(args: ICodeArgs, output: thrift.TProtocol): void { - return CodeCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return CodeCodec.encode(this, output); - } -} -export interface ISharedStruct { - code: ICode; - value: string; -} -export interface ISharedStructArgs { - code: ICodeArgs; - value: string; -} -export const SharedStructCodec: thrift.IStructCodec = { - encode(args: ISharedStructArgs, output: thrift.TProtocol): void { - const obj = { - code: args.code, - value: args.value - }; - output.writeStructBegin("SharedStruct"); - if (obj.code != null) { - output.writeFieldBegin("code", thrift.TType.STRUCT, 1); - CodeCodec.encode(obj.code, output); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[code] is unset!"); - } - if (obj.value != null) { - output.writeFieldBegin("value", thrift.TType.STRING, 2); - output.writeString(obj.value); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[value] is unset!"); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): ISharedStruct { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.STRUCT) { - const value_3: ICode = CodeCodec.decode(input); - _args.code = value_3; - } - else { - input.skip(fieldType); - } - break; - case 2: - if (fieldType === thrift.TType.STRING) { - const value_4: string = input.readString(); - _args.value = value_4; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.code !== undefined && _args.value !== undefined) { - return { - code: _args.code, - value: _args.value - }; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read SharedStruct from input"); - } - } -}; -export class SharedStruct extends thrift.StructLike implements ISharedStruct { - public code: ICode; - public value: string; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: ISharedStructArgs) { - super(); - if (args.code != null) { - const value_5: ICode = new Code(args.code); - this.code = value_5; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[code] is unset!"); - } - if (args.value != null) { - const value_6: string = args.value; - this.value = value_6; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[value] is unset!"); - } - } - public static read(input: thrift.TProtocol): SharedStruct { - return new SharedStruct(SharedStructCodec.decode(input)); - } - public static write(args: ISharedStructArgs, output: thrift.TProtocol): void { - return SharedStructCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return SharedStructCodec.encode(this, output); - } -} -export interface ISharedUnion { - option1?: string; - option2?: string; -} -export interface ISharedUnionArgs { - option1?: string; - option2?: string; -} -export const SharedUnionCodec: thrift.IStructCodec = { - encode(args: ISharedUnionArgs, output: thrift.TProtocol): void { - let _fieldsSet: number = 0; - const obj = { - option1: args.option1, - option2: args.option2 - }; - output.writeStructBegin("SharedUnion"); - if (obj.option1 != null) { - _fieldsSet++; - output.writeFieldBegin("option1", thrift.TType.STRING, 1); - output.writeString(obj.option1); - output.writeFieldEnd(); - } - if (obj.option2 != null) { - _fieldsSet++; - output.writeFieldBegin("option2", thrift.TType.STRING, 2); - output.writeString(obj.option2); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - if (_fieldsSet > 1) { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion cannot have more than one value"); - } - else if (_fieldsSet < 1) { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion must have one value set"); - } - return; - }, - decode(input: thrift.TProtocol): ISharedUnion { - let _fieldsSet: number = 0; - let _returnValue: ISharedUnion | null = null; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.STRING) { - _fieldsSet++; - const value_7: string = input.readString(); - _returnValue = { option1: value_7 }; - } - else { - input.skip(fieldType); - } - break; - case 2: - if (fieldType === thrift.TType.STRING) { - _fieldsSet++; - const value_8: string = input.readString(); - _returnValue = { option2: value_8 }; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_fieldsSet > 1) { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion cannot have more than one value"); - } - else if (_fieldsSet < 1) { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion must have one value set"); - } - if (_returnValue !== null) { - return _returnValue; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read data for TUnion"); - } - } -}; -export class SharedUnion extends thrift.StructLike implements ISharedUnion { - public option1?: string; - public option2?: string; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: ISharedUnionArgs = {}) { - super(); - let _fieldsSet: number = 0; - if (args.option1 != null) { - _fieldsSet++; - const value_9: string = args.option1; - this.option1 = value_9; - } - if (args.option2 != null) { - _fieldsSet++; - const value_10: string = args.option2; - this.option2 = value_10; - } - if (_fieldsSet > 1) { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion cannot have more than one value"); - } - else if (_fieldsSet < 1) { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion must have one value set"); - } - } - public static read(input: thrift.TProtocol): SharedUnion { - return new SharedUnion(SharedUnionCodec.decode(input)); - } - public static write(args: ISharedUnionArgs, output: thrift.TProtocol): void { - return SharedUnionCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return SharedUnionCodec.encode(this, output); - } -} -export namespace SharedService { - export const serviceName: string = "SharedService"; - export const annotations: thrift.IThriftAnnotations = {}; - export const methodAnnotations: thrift.IMethodAnnotations = { - getStruct: { - annotations: {}, - fieldAnnotations: {} - }, - getUnion: { - annotations: {}, - fieldAnnotations: {} - } - }; - export const methodNames: Array = ["getStruct", "getUnion"]; - export interface IGetStruct__Args { - key: number; - } - export interface IGetStruct__ArgsArgs { - key: number; - } - export const GetStruct__ArgsCodec: thrift.IStructCodec = { - encode(args: IGetStruct__ArgsArgs, output: thrift.TProtocol): void { - const obj = { - key: args.key - }; - output.writeStructBegin("GetStruct__Args"); - if (obj.key != null) { - output.writeFieldBegin("key", thrift.TType.I32, 1); - output.writeI32(obj.key); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[key] is unset!"); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IGetStruct__Args { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.I32) { - const value_11: number = input.readI32(); - _args.key = value_11; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.key !== undefined) { - return { - key: _args.key - }; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read GetStruct__Args from input"); - } - } - }; - export class GetStruct__Args extends thrift.StructLike implements IGetStruct__Args { - public key: number; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IGetStruct__ArgsArgs) { - super(); - if (args.key != null) { - const value_12: number = args.key; - this.key = value_12; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[key] is unset!"); - } - } - public static read(input: thrift.TProtocol): GetStruct__Args { - return new GetStruct__Args(GetStruct__ArgsCodec.decode(input)); - } - public static write(args: IGetStruct__ArgsArgs, output: thrift.TProtocol): void { - return GetStruct__ArgsCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return GetStruct__ArgsCodec.encode(this, output); - } - } - export interface IGetUnion__Args { - index: number; - } - export interface IGetUnion__ArgsArgs { - index: number; - } - export const GetUnion__ArgsCodec: thrift.IStructCodec = { - encode(args: IGetUnion__ArgsArgs, output: thrift.TProtocol): void { - const obj = { - index: args.index - }; - output.writeStructBegin("GetUnion__Args"); - if (obj.index != null) { - output.writeFieldBegin("index", thrift.TType.I32, 1); - output.writeI32(obj.index); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[index] is unset!"); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IGetUnion__Args { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.I32) { - const value_13: number = input.readI32(); - _args.index = value_13; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.index !== undefined) { - return { - index: _args.index - }; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read GetUnion__Args from input"); - } - } - }; - export class GetUnion__Args extends thrift.StructLike implements IGetUnion__Args { - public index: number; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IGetUnion__ArgsArgs) { - super(); - if (args.index != null) { - const value_14: number = args.index; - this.index = value_14; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[index] is unset!"); - } - } - public static read(input: thrift.TProtocol): GetUnion__Args { - return new GetUnion__Args(GetUnion__ArgsCodec.decode(input)); - } - public static write(args: IGetUnion__ArgsArgs, output: thrift.TProtocol): void { - return GetUnion__ArgsCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return GetUnion__ArgsCodec.encode(this, output); - } - } - export interface IGetStruct__Result { - success?: ISharedStruct; - } - export interface IGetStruct__ResultArgs { - success?: ISharedStructArgs; - } - export const GetStruct__ResultCodec: thrift.IStructCodec = { - encode(args: IGetStruct__ResultArgs, output: thrift.TProtocol): void { - const obj = { - success: args.success - }; - output.writeStructBegin("GetStruct__Result"); - if (obj.success != null) { - output.writeFieldBegin("success", thrift.TType.STRUCT, 0); - SharedStructCodec.encode(obj.success, output); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IGetStruct__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.STRUCT) { - const value_15: ISharedStruct = SharedStructCodec.decode(input); - _args.success = value_15; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - success: _args.success - }; - } - }; - export class GetStruct__Result extends thrift.StructLike implements IGetStruct__Result { - public success?: ISharedStruct; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IGetStruct__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_16: ISharedStruct = new SharedStruct(args.success); - this.success = value_16; - } - } - public static read(input: thrift.TProtocol): GetStruct__Result { - return new GetStruct__Result(GetStruct__ResultCodec.decode(input)); - } - public static write(args: IGetStruct__ResultArgs, output: thrift.TProtocol): void { - return GetStruct__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return GetStruct__ResultCodec.encode(this, output); - } - } - export interface IGetUnion__Result { - success?: ISharedUnion; - } - export interface IGetUnion__ResultArgs { - success?: ISharedUnionArgs; - } - export const GetUnion__ResultCodec: thrift.IStructCodec = { - encode(args: IGetUnion__ResultArgs, output: thrift.TProtocol): void { - const obj = { - success: args.success - }; - output.writeStructBegin("GetUnion__Result"); - if (obj.success != null) { - output.writeFieldBegin("success", thrift.TType.STRUCT, 0); - SharedUnionCodec.encode(obj.success, output); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IGetUnion__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.STRUCT) { - const value_17: ISharedUnion = SharedUnionCodec.decode(input); - _args.success = value_17; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - success: _args.success - }; - } - }; - export class GetUnion__Result extends thrift.StructLike implements IGetUnion__Result { - public success?: ISharedUnion; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IGetUnion__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_18: ISharedUnion = new SharedUnion(args.success); - this.success = value_18; - } - } - public static read(input: thrift.TProtocol): GetUnion__Result { - return new GetUnion__Result(GetUnion__ResultCodec.decode(input)); - } - public static write(args: IGetUnion__ResultArgs, output: thrift.TProtocol): void { - return GetUnion__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return GetUnion__ResultCodec.encode(this, output); - } - } - export class Client extends thrift.ThriftClient { - public static readonly serviceName: string = serviceName; - public static readonly annotations: thrift.IThriftAnnotations = annotations; - public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public static readonly methodNames: Array = methodNames; - public readonly _serviceName: string = serviceName; - public readonly _annotations: thrift.IThriftAnnotations = annotations; - public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public readonly _methodNames: Array = methodNames; - public getStruct(key: number, context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("getStruct", thrift.MessageType.CALL, this.incrementRequestId()); - const args: IGetStruct__ArgsArgs = { key }; - GetStruct__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "getStruct") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: IGetStruct__Result = GetStruct__ResultCodec.decode(input); - input.readMessageEnd(); - if (result.success != null) { - return Promise.resolve(result.success); - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "getStruct failed: unknown result")); - } - } - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } - } - catch (err) { - return Promise.reject(err); - } - }); - } - public getUnion(index: number, context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("getUnion", thrift.MessageType.CALL, this.incrementRequestId()); - const args: IGetUnion__ArgsArgs = { index }; - GetUnion__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "getUnion") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: IGetUnion__Result = GetUnion__ResultCodec.decode(input); - input.readMessageEnd(); - if (result.success != null) { - return Promise.resolve(result.success); - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "getUnion failed: unknown result")); - } - } - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } - } - catch (err) { - return Promise.reject(err); - } - }); - } - } - export interface IHandler { - getStruct(key: number, context?: Context): ISharedStructArgs | Promise; - getUnion(index: number, context?: Context): ISharedUnionArgs | Promise; - } - export class Processor extends thrift.ThriftProcessor> { - protected readonly _handler: IHandler; - public static readonly serviceName: string = serviceName; - public static readonly annotations: thrift.IThriftAnnotations = annotations; - public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public static readonly methodNames: Array = methodNames; - public readonly _serviceName: string = serviceName; - public readonly _annotations: thrift.IThriftAnnotations = annotations; - public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public readonly _methodNames: Array = methodNames; - constructor(handler: IHandler) { - super(); - this._handler = handler; - } - public process(input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - const metadata: thrift.IThriftMessage = input.readMessageBegin(); - const fieldName: string = metadata.fieldName; - const requestId: number = metadata.requestId; - const methodName: string = "process_" + fieldName; - switch (methodName) { - case "process_getStruct": { - resolve(this.process_getStruct(requestId, input, output, context)); - break; - } - case "process_getUnion": { - resolve(this.process_getUnion(requestId, input, output, context)); - break; - } - default: { - input.skip(thrift.TType.STRUCT); - input.readMessageEnd(); - const errMessage = "Unknown function " + fieldName; - const err = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN_METHOD, errMessage); - output.writeMessageBegin(fieldName, thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(err, output); - output.writeMessageEnd(); - resolve(output.flush()); - break; - } - } - }); - } - public process_getStruct(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { - const args: IGetStruct__Args = GetStruct__ArgsCodec.decode(input); - input.readMessageEnd(); - resolve(this._handler.getStruct(args.key, context)); - } - catch (err) { - reject(err); - } - }).then((data: ISharedStructArgs): Buffer => { - const result: IGetStruct__ResultArgs = { success: data }; - output.writeMessageBegin("getStruct", thrift.MessageType.REPLY, requestId); - GetStruct__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("getStruct", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } - public process_getUnion(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { - const args: IGetUnion__Args = GetUnion__ArgsCodec.decode(input); - input.readMessageEnd(); - resolve(this._handler.getUnion(args.index, context)); - } - catch (err) { - reject(err); - } - }).then((data: ISharedUnionArgs): Buffer => { - const result: IGetUnion__ResultArgs = { success: data }; - output.writeMessageBegin("getUnion", thrift.MessageType.REPLY, requestId); - GetUnion__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("getUnion", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } - } -} diff --git a/src/tests/unit/fixtures/generated/strict-unions/calculator/index.ts b/src/tests/unit/fixtures/generated/strict-unions/calculator/index.ts deleted file mode 100644 index 38914ab9..00000000 --- a/src/tests/unit/fixtures/generated/strict-unions/calculator/index.ts +++ /dev/null @@ -1,3919 +0,0 @@ -/* tslint:disable */ -/* - * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} - * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING -*/ -import * as thrift from "test-lib"; -import * as shared from "./../shared"; -import * as common from "./../common"; -import * as operation from "./../operation"; -export type MyInteger = number; -export import Operation = operation.Operation; -export import ICommonStruct = common.ICommonStruct; -export import ICommonStructArgs = common.ICommonStructArgs; -export import CommonStruct = common.CommonStruct; -export import CommonStructCodec = common.CommonStructCodec; -export const INT32CONSTANT: number = 9853; -export const MAPCONSTANT: Map = new Map([["hello", "world"], ["goodnight", "moon"]]); -export interface IWork { - num1: number; - num2: number; - op: Operation; - comment?: string; -} -export interface IWorkArgs { - num1?: number; - num2: number; - op: Operation; - comment?: string; -} -export const WorkCodec: thrift.IStructCodec = { - encode(args: IWorkArgs, output: thrift.TProtocol): void { - const obj = { - num1: (args.num1 != null ? args.num1 : 0), - num2: args.num2, - op: args.op, - comment: args.comment - }; - output.writeStructBegin("Work"); - if (obj.num1 != null) { - output.writeFieldBegin("num1", thrift.TType.I32, 1); - output.writeI32(obj.num1); - output.writeFieldEnd(); - } - if (obj.num2 != null) { - output.writeFieldBegin("num2", thrift.TType.I32, 2); - output.writeI32(obj.num2); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num2] is unset!"); - } - if (obj.op != null) { - output.writeFieldBegin("op", thrift.TType.I32, 3); - output.writeI32(obj.op); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[op] is unset!"); - } - if (obj.comment != null) { - output.writeFieldBegin("comment", thrift.TType.STRING, 4); - output.writeString(obj.comment); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IWork { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.I32) { - const value_1: number = input.readI32(); - _args.num1 = value_1; - } - else { - input.skip(fieldType); - } - break; - case 2: - if (fieldType === thrift.TType.I32) { - const value_2: number = input.readI32(); - _args.num2 = value_2; - } - else { - input.skip(fieldType); - } - break; - case 3: - if (fieldType === thrift.TType.I32) { - const value_3: Operation = input.readI32(); - _args.op = value_3; - } - else { - input.skip(fieldType); - } - break; - case 4: - if (fieldType === thrift.TType.STRING) { - const value_4: string = input.readString(); - _args.comment = value_4; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.num1 !== undefined && _args.num2 !== undefined && _args.op !== undefined) { - return { - num1: (_args.num1 != null ? _args.num1 : 0), - num2: _args.num2, - op: _args.op, - comment: _args.comment - }; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read Work from input"); - } - } -}; -export class Work extends thrift.StructLike implements IWork { - public num1: number = 0; - public num2: number; - public op: Operation; - public comment?: string; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IWorkArgs) { - super(); - if (args.num1 != null) { - const value_5: number = args.num1; - this.num1 = value_5; - } - if (args.num2 != null) { - const value_6: number = args.num2; - this.num2 = value_6; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num2] is unset!"); - } - if (args.op != null) { - const value_7: Operation = args.op; - this.op = value_7; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[op] is unset!"); - } - if (args.comment != null) { - const value_8: string = args.comment; - this.comment = value_8; - } - } - public static read(input: thrift.TProtocol): Work { - return new Work(WorkCodec.decode(input)); - } - public static write(args: IWorkArgs, output: thrift.TProtocol): void { - return WorkCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return WorkCodec.encode(this, output); - } -} -export interface IFirstName { - name?: string; -} -export interface IFirstNameArgs { - name?: string; -} -export const FirstNameCodec: thrift.IStructCodec = { - encode(args: IFirstNameArgs, output: thrift.TProtocol): void { - const obj = { - name: args.name - }; - output.writeStructBegin("FirstName"); - if (obj.name != null) { - output.writeFieldBegin("name", thrift.TType.STRING, 1); - output.writeString(obj.name); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IFirstName { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.STRING) { - const value_9: string = input.readString(); - _args.name = value_9; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - name: _args.name - }; - } -}; -export class FirstName extends thrift.StructLike implements IFirstName { - public name?: string; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IFirstNameArgs = {}) { - super(); - if (args.name != null) { - const value_10: string = args.name; - this.name = value_10; - } - } - public static read(input: thrift.TProtocol): FirstName { - return new FirstName(FirstNameCodec.decode(input)); - } - public static write(args: IFirstNameArgs, output: thrift.TProtocol): void { - return FirstNameCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return FirstNameCodec.encode(this, output); - } -} -export interface ILastName { - name?: string; -} -export interface ILastNameArgs { - name?: string; -} -export const LastNameCodec: thrift.IStructCodec = { - encode(args: ILastNameArgs, output: thrift.TProtocol): void { - const obj = { - name: args.name - }; - output.writeStructBegin("LastName"); - if (obj.name != null) { - output.writeFieldBegin("name", thrift.TType.STRING, 1); - output.writeString(obj.name); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): ILastName { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.STRING) { - const value_11: string = input.readString(); - _args.name = value_11; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - name: _args.name - }; - } -}; -export class LastName extends thrift.StructLike implements ILastName { - public name?: string; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: ILastNameArgs = {}) { - super(); - if (args.name != null) { - const value_12: string = args.name; - this.name = value_12; - } - } - public static read(input: thrift.TProtocol): LastName { - return new LastName(LastNameCodec.decode(input)); - } - public static write(args: ILastNameArgs, output: thrift.TProtocol): void { - return LastNameCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return LastNameCodec.encode(this, output); - } -} -export enum Choice__Type { - ChoiceWithFirstName = "firstName", - ChoiceWithLastName = "lastName" -} -export type Choice = IChoiceWithFirstName | IChoiceWithLastName; -export interface IChoiceWithFirstName { - __type: Choice__Type.ChoiceWithFirstName; - firstName: IFirstName; - lastName?: void; -} -export interface IChoiceWithLastName { - __type: Choice__Type.ChoiceWithLastName; - firstName?: void; - lastName: ILastName; -} -export type ChoiceArgs = IChoiceWithFirstNameArgs | IChoiceWithLastNameArgs; -export interface IChoiceWithFirstNameArgs { - firstName: IFirstNameArgs; - lastName?: void; -} -export interface IChoiceWithLastNameArgs { - firstName?: void; - lastName: ILastNameArgs; -} -export const ChoiceCodec: thrift.IStructToolkit = { - create(args: ChoiceArgs): Choice { - let _fieldsSet: number = 0; - let _returnValue: any = null; - if (args.firstName != null) { - _fieldsSet++; - const value_13: IFirstName = new FirstName(args.firstName); - _returnValue = { firstName: value_13 }; - } - if (args.lastName != null) { - _fieldsSet++; - const value_14: ILastName = new LastName(args.lastName); - _returnValue = { lastName: value_14 }; - } - if (_fieldsSet > 1) { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion cannot have more than one value"); - } - else if (_fieldsSet < 1) { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion must have one value set"); - } - if (_returnValue !== null) { - if (_returnValue.firstName) { - return { - __type: Choice__Type.ChoiceWithFirstName, - firstName: _returnValue.firstName - }; - } - else { - return { - __type: Choice__Type.ChoiceWithLastName, - lastName: _returnValue.lastName - }; - } - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read data for TUnion"); - } - }, - encode(args: ChoiceArgs, output: thrift.TProtocol): void { - let _fieldsSet: number = 0; - const obj = { - firstName: args.firstName, - lastName: args.lastName - }; - output.writeStructBegin("Choice"); - if (obj.firstName != null) { - _fieldsSet++; - output.writeFieldBegin("firstName", thrift.TType.STRUCT, 1); - FirstNameCodec.encode(obj.firstName, output); - output.writeFieldEnd(); - } - if (obj.lastName != null) { - _fieldsSet++; - output.writeFieldBegin("lastName", thrift.TType.STRUCT, 2); - LastNameCodec.encode(obj.lastName, output); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - if (_fieldsSet > 1) { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion cannot have more than one value"); - } - else if (_fieldsSet < 1) { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion must have one value set"); - } - return; - }, - decode(input: thrift.TProtocol): Choice { - let _fieldsSet: number = 0; - let _returnValue: any = null; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.STRUCT) { - _fieldsSet++; - const value_15: IFirstName = FirstNameCodec.decode(input); - _returnValue = { firstName: value_15 }; - } - else { - input.skip(fieldType); - } - break; - case 2: - if (fieldType === thrift.TType.STRUCT) { - _fieldsSet++; - const value_16: ILastName = LastNameCodec.decode(input); - _returnValue = { lastName: value_16 }; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_fieldsSet > 1) { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion cannot have more than one value"); - } - else if (_fieldsSet < 1) { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion must have one value set"); - } - if (_returnValue !== null) { - if (_returnValue.firstName) { - return { - __type: Choice__Type.ChoiceWithFirstName, - firstName: _returnValue.firstName - }; - } - else { - return { - __type: Choice__Type.ChoiceWithLastName, - lastName: _returnValue.lastName - }; - } - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read data for TUnion"); - } - } -}; -export namespace Calculator { - export const serviceName: string = "Calculator"; - export const annotations: thrift.IThriftAnnotations = {}; - export const methodAnnotations: thrift.IMethodAnnotations = { - getStruct: { - annotations: {}, - fieldAnnotations: {} - }, - getUnion: { - annotations: {}, - fieldAnnotations: {} - }, - ping: { - annotations: {}, - fieldAnnotations: {} - }, - add: { - annotations: {}, - fieldAnnotations: {} - }, - addInt64: { - annotations: {}, - fieldAnnotations: {} - }, - addWithContext: { - annotations: {}, - fieldAnnotations: {} - }, - calculate: { - annotations: {}, - fieldAnnotations: {} - }, - echoBinary: { - annotations: {}, - fieldAnnotations: {} - }, - echoString: { - annotations: {}, - fieldAnnotations: {} - }, - checkName: { - annotations: {}, - fieldAnnotations: {} - }, - checkOptional: { - annotations: {}, - fieldAnnotations: {} - }, - mapOneList: { - annotations: {}, - fieldAnnotations: {} - }, - mapValues: { - annotations: {}, - fieldAnnotations: {} - }, - listToMap: { - annotations: {}, - fieldAnnotations: {} - }, - fetchThing: { - annotations: {}, - fieldAnnotations: {} - }, - zip: { - annotations: {}, - fieldAnnotations: {} - } - }; - export const methodNames: Array = ["getStruct", "getUnion", "ping", "add", "addInt64", "addWithContext", "calculate", "echoBinary", "echoString", "checkName", "checkOptional", "mapOneList", "mapValues", "listToMap", "fetchThing", "zip"]; - export interface IPing__Args { - } - export interface IPing__ArgsArgs { - } - export const Ping__ArgsCodec: thrift.IStructCodec = { - encode(args: IPing__ArgsArgs, output: thrift.TProtocol): void { - output.writeStructBegin("Ping__Args"); - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IPing__Args { - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return {}; - } - }; - export class Ping__Args extends thrift.StructLike implements IPing__Args { - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IPing__ArgsArgs = {}) { - super(); - } - public static read(input: thrift.TProtocol): Ping__Args { - return new Ping__Args(Ping__ArgsCodec.decode(input)); - } - public static write(args: IPing__ArgsArgs, output: thrift.TProtocol): void { - return Ping__ArgsCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return Ping__ArgsCodec.encode(this, output); - } - } - export interface IAdd__Args { - num1: number; - num2: number; - } - export interface IAdd__ArgsArgs { - num1: number; - num2: number; - } - export const Add__ArgsCodec: thrift.IStructCodec = { - encode(args: IAdd__ArgsArgs, output: thrift.TProtocol): void { - const obj = { - num1: args.num1, - num2: args.num2 - }; - output.writeStructBegin("Add__Args"); - if (obj.num1 != null) { - output.writeFieldBegin("num1", thrift.TType.I32, 1); - output.writeI32(obj.num1); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num1] is unset!"); - } - if (obj.num2 != null) { - output.writeFieldBegin("num2", thrift.TType.I32, 2); - output.writeI32(obj.num2); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num2] is unset!"); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IAdd__Args { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.I32) { - const value_17: number = input.readI32(); - _args.num1 = value_17; - } - else { - input.skip(fieldType); - } - break; - case 2: - if (fieldType === thrift.TType.I32) { - const value_18: number = input.readI32(); - _args.num2 = value_18; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.num1 !== undefined && _args.num2 !== undefined) { - return { - num1: _args.num1, - num2: _args.num2 - }; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read Add__Args from input"); - } - } - }; - export class Add__Args extends thrift.StructLike implements IAdd__Args { - public num1: number; - public num2: number; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IAdd__ArgsArgs) { - super(); - if (args.num1 != null) { - const value_19: number = args.num1; - this.num1 = value_19; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num1] is unset!"); - } - if (args.num2 != null) { - const value_20: number = args.num2; - this.num2 = value_20; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num2] is unset!"); - } - } - public static read(input: thrift.TProtocol): Add__Args { - return new Add__Args(Add__ArgsCodec.decode(input)); - } - public static write(args: IAdd__ArgsArgs, output: thrift.TProtocol): void { - return Add__ArgsCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return Add__ArgsCodec.encode(this, output); - } - } - export interface IAddInt64__Args { - num1: thrift.Int64; - num2: thrift.Int64; - } - export interface IAddInt64__ArgsArgs { - num1: number | string | thrift.Int64; - num2: number | string | thrift.Int64; - } - export const AddInt64__ArgsCodec: thrift.IStructCodec = { - encode(args: IAddInt64__ArgsArgs, output: thrift.TProtocol): void { - const obj = { - num1: (typeof args.num1 === "number" ? new thrift.Int64(args.num1) : typeof args.num1 === "string" ? thrift.Int64.fromDecimalString(args.num1) : args.num1), - num2: (typeof args.num2 === "number" ? new thrift.Int64(args.num2) : typeof args.num2 === "string" ? thrift.Int64.fromDecimalString(args.num2) : args.num2) - }; - output.writeStructBegin("AddInt64__Args"); - if (obj.num1 != null) { - output.writeFieldBegin("num1", thrift.TType.I64, 1); - output.writeI64((typeof obj.num1 === "number" ? new thrift.Int64(obj.num1) : typeof obj.num1 === "string" ? thrift.Int64.fromDecimalString(obj.num1) : obj.num1)); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num1] is unset!"); - } - if (obj.num2 != null) { - output.writeFieldBegin("num2", thrift.TType.I64, 2); - output.writeI64((typeof obj.num2 === "number" ? new thrift.Int64(obj.num2) : typeof obj.num2 === "string" ? thrift.Int64.fromDecimalString(obj.num2) : obj.num2)); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num2] is unset!"); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IAddInt64__Args { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.I64) { - const value_21: thrift.Int64 = input.readI64(); - _args.num1 = value_21; - } - else { - input.skip(fieldType); - } - break; - case 2: - if (fieldType === thrift.TType.I64) { - const value_22: thrift.Int64 = input.readI64(); - _args.num2 = value_22; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.num1 !== undefined && _args.num2 !== undefined) { - return { - num1: _args.num1, - num2: _args.num2 - }; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read AddInt64__Args from input"); - } - } - }; - export class AddInt64__Args extends thrift.StructLike implements IAddInt64__Args { - public num1: thrift.Int64; - public num2: thrift.Int64; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IAddInt64__ArgsArgs) { - super(); - if (args.num1 != null) { - const value_23: thrift.Int64 = (typeof args.num1 === "number" ? new thrift.Int64(args.num1) : typeof args.num1 === "string" ? thrift.Int64.fromDecimalString(args.num1) : args.num1); - this.num1 = value_23; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num1] is unset!"); - } - if (args.num2 != null) { - const value_24: thrift.Int64 = (typeof args.num2 === "number" ? new thrift.Int64(args.num2) : typeof args.num2 === "string" ? thrift.Int64.fromDecimalString(args.num2) : args.num2); - this.num2 = value_24; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num2] is unset!"); - } - } - public static read(input: thrift.TProtocol): AddInt64__Args { - return new AddInt64__Args(AddInt64__ArgsCodec.decode(input)); - } - public static write(args: IAddInt64__ArgsArgs, output: thrift.TProtocol): void { - return AddInt64__ArgsCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return AddInt64__ArgsCodec.encode(this, output); - } - } - export interface IAddWithContext__Args { - num1: number; - num2: number; - } - export interface IAddWithContext__ArgsArgs { - num1: number; - num2: number; - } - export const AddWithContext__ArgsCodec: thrift.IStructCodec = { - encode(args: IAddWithContext__ArgsArgs, output: thrift.TProtocol): void { - const obj = { - num1: args.num1, - num2: args.num2 - }; - output.writeStructBegin("AddWithContext__Args"); - if (obj.num1 != null) { - output.writeFieldBegin("num1", thrift.TType.I32, 1); - output.writeI32(obj.num1); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num1] is unset!"); - } - if (obj.num2 != null) { - output.writeFieldBegin("num2", thrift.TType.I32, 2); - output.writeI32(obj.num2); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num2] is unset!"); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IAddWithContext__Args { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.I32) { - const value_25: number = input.readI32(); - _args.num1 = value_25; - } - else { - input.skip(fieldType); - } - break; - case 2: - if (fieldType === thrift.TType.I32) { - const value_26: number = input.readI32(); - _args.num2 = value_26; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.num1 !== undefined && _args.num2 !== undefined) { - return { - num1: _args.num1, - num2: _args.num2 - }; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read AddWithContext__Args from input"); - } - } - }; - export class AddWithContext__Args extends thrift.StructLike implements IAddWithContext__Args { - public num1: number; - public num2: number; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IAddWithContext__ArgsArgs) { - super(); - if (args.num1 != null) { - const value_27: number = args.num1; - this.num1 = value_27; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num1] is unset!"); - } - if (args.num2 != null) { - const value_28: number = args.num2; - this.num2 = value_28; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num2] is unset!"); - } - } - public static read(input: thrift.TProtocol): AddWithContext__Args { - return new AddWithContext__Args(AddWithContext__ArgsCodec.decode(input)); - } - public static write(args: IAddWithContext__ArgsArgs, output: thrift.TProtocol): void { - return AddWithContext__ArgsCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return AddWithContext__ArgsCodec.encode(this, output); - } - } - export interface ICalculate__Args { - logid: number; - work: IWork; - } - export interface ICalculate__ArgsArgs { - logid: number; - work: IWorkArgs; - } - export const Calculate__ArgsCodec: thrift.IStructCodec = { - encode(args: ICalculate__ArgsArgs, output: thrift.TProtocol): void { - const obj = { - logid: args.logid, - work: args.work - }; - output.writeStructBegin("Calculate__Args"); - if (obj.logid != null) { - output.writeFieldBegin("logid", thrift.TType.I32, 1); - output.writeI32(obj.logid); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[logid] is unset!"); - } - if (obj.work != null) { - output.writeFieldBegin("work", thrift.TType.STRUCT, 2); - WorkCodec.encode(obj.work, output); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[work] is unset!"); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): ICalculate__Args { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.I32) { - const value_29: number = input.readI32(); - _args.logid = value_29; - } - else { - input.skip(fieldType); - } - break; - case 2: - if (fieldType === thrift.TType.STRUCT) { - const value_30: IWork = WorkCodec.decode(input); - _args.work = value_30; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.logid !== undefined && _args.work !== undefined) { - return { - logid: _args.logid, - work: _args.work - }; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read Calculate__Args from input"); - } - } - }; - export class Calculate__Args extends thrift.StructLike implements ICalculate__Args { - public logid: number; - public work: IWork; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: ICalculate__ArgsArgs) { - super(); - if (args.logid != null) { - const value_31: number = args.logid; - this.logid = value_31; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[logid] is unset!"); - } - if (args.work != null) { - const value_32: IWork = new Work(args.work); - this.work = value_32; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[work] is unset!"); - } - } - public static read(input: thrift.TProtocol): Calculate__Args { - return new Calculate__Args(Calculate__ArgsCodec.decode(input)); - } - public static write(args: ICalculate__ArgsArgs, output: thrift.TProtocol): void { - return Calculate__ArgsCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return Calculate__ArgsCodec.encode(this, output); - } - } - export interface IEchoBinary__Args { - word: Buffer; - } - export interface IEchoBinary__ArgsArgs { - word: string | Buffer; - } - export const EchoBinary__ArgsCodec: thrift.IStructCodec = { - encode(args: IEchoBinary__ArgsArgs, output: thrift.TProtocol): void { - const obj = { - word: (typeof args.word === "string" ? Buffer.from(args.word) : args.word) - }; - output.writeStructBegin("EchoBinary__Args"); - if (obj.word != null) { - output.writeFieldBegin("word", thrift.TType.STRING, 1); - output.writeBinary(obj.word); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[word] is unset!"); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IEchoBinary__Args { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.STRING) { - const value_33: Buffer = input.readBinary(); - _args.word = value_33; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.word !== undefined) { - return { - word: _args.word - }; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read EchoBinary__Args from input"); - } - } - }; - export class EchoBinary__Args extends thrift.StructLike implements IEchoBinary__Args { - public word: Buffer; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IEchoBinary__ArgsArgs) { - super(); - if (args.word != null) { - const value_34: Buffer = (typeof args.word === "string" ? Buffer.from(args.word) : args.word); - this.word = value_34; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[word] is unset!"); - } - } - public static read(input: thrift.TProtocol): EchoBinary__Args { - return new EchoBinary__Args(EchoBinary__ArgsCodec.decode(input)); - } - public static write(args: IEchoBinary__ArgsArgs, output: thrift.TProtocol): void { - return EchoBinary__ArgsCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return EchoBinary__ArgsCodec.encode(this, output); - } - } - export interface IEchoString__Args { - word: string; - } - export interface IEchoString__ArgsArgs { - word: string; - } - export const EchoString__ArgsCodec: thrift.IStructCodec = { - encode(args: IEchoString__ArgsArgs, output: thrift.TProtocol): void { - const obj = { - word: args.word - }; - output.writeStructBegin("EchoString__Args"); - if (obj.word != null) { - output.writeFieldBegin("word", thrift.TType.STRING, 1); - output.writeString(obj.word); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[word] is unset!"); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IEchoString__Args { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.STRING) { - const value_35: string = input.readString(); - _args.word = value_35; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.word !== undefined) { - return { - word: _args.word - }; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read EchoString__Args from input"); - } - } - }; - export class EchoString__Args extends thrift.StructLike implements IEchoString__Args { - public word: string; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IEchoString__ArgsArgs) { - super(); - if (args.word != null) { - const value_36: string = args.word; - this.word = value_36; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[word] is unset!"); - } - } - public static read(input: thrift.TProtocol): EchoString__Args { - return new EchoString__Args(EchoString__ArgsCodec.decode(input)); - } - public static write(args: IEchoString__ArgsArgs, output: thrift.TProtocol): void { - return EchoString__ArgsCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return EchoString__ArgsCodec.encode(this, output); - } - } - export interface ICheckName__Args { - choice: Choice; - } - export interface ICheckName__ArgsArgs { - choice: ChoiceArgs; - } - export const CheckName__ArgsCodec: thrift.IStructCodec = { - encode(args: ICheckName__ArgsArgs, output: thrift.TProtocol): void { - const obj = { - choice: args.choice - }; - output.writeStructBegin("CheckName__Args"); - if (obj.choice != null) { - output.writeFieldBegin("choice", thrift.TType.STRUCT, 1); - ChoiceCodec.encode(obj.choice, output); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[choice] is unset!"); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): ICheckName__Args { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.STRUCT) { - const value_37: Choice = ChoiceCodec.decode(input); - _args.choice = value_37; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.choice !== undefined) { - return { - choice: _args.choice - }; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read CheckName__Args from input"); - } - } - }; - export class CheckName__Args extends thrift.StructLike implements ICheckName__Args { - public choice: Choice; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: ICheckName__ArgsArgs) { - super(); - if (args.choice != null) { - const value_38: Choice = ChoiceCodec.create(args.choice); - this.choice = value_38; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[choice] is unset!"); - } - } - public static read(input: thrift.TProtocol): CheckName__Args { - return new CheckName__Args(CheckName__ArgsCodec.decode(input)); - } - public static write(args: ICheckName__ArgsArgs, output: thrift.TProtocol): void { - return CheckName__ArgsCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return CheckName__ArgsCodec.encode(this, output); - } - } - export interface ICheckOptional__Args { - type?: string; - } - export interface ICheckOptional__ArgsArgs { - type?: string; - } - export const CheckOptional__ArgsCodec: thrift.IStructCodec = { - encode(args: ICheckOptional__ArgsArgs, output: thrift.TProtocol): void { - const obj = { - type: args.type - }; - output.writeStructBegin("CheckOptional__Args"); - if (obj.type != null) { - output.writeFieldBegin("type", thrift.TType.STRING, 1); - output.writeString(obj.type); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): ICheckOptional__Args { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.STRING) { - const value_39: string = input.readString(); - _args.type = value_39; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - type: _args.type - }; - } - }; - export class CheckOptional__Args extends thrift.StructLike implements ICheckOptional__Args { - public type?: string; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: ICheckOptional__ArgsArgs = {}) { - super(); - if (args.type != null) { - const value_40: string = args.type; - this.type = value_40; - } - } - public static read(input: thrift.TProtocol): CheckOptional__Args { - return new CheckOptional__Args(CheckOptional__ArgsCodec.decode(input)); - } - public static write(args: ICheckOptional__ArgsArgs, output: thrift.TProtocol): void { - return CheckOptional__ArgsCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return CheckOptional__ArgsCodec.encode(this, output); - } - } - export interface IMapOneList__Args { - arg: Array; - } - export interface IMapOneList__ArgsArgs { - arg: Array; - } - export const MapOneList__ArgsCodec: thrift.IStructCodec = { - encode(args: IMapOneList__ArgsArgs, output: thrift.TProtocol): void { - const obj = { - arg: args.arg - }; - output.writeStructBegin("MapOneList__Args"); - if (obj.arg != null) { - output.writeFieldBegin("arg", thrift.TType.LIST, 1); - output.writeListBegin(thrift.TType.I32, obj.arg.length); - obj.arg.forEach((value_41: number): void => { - output.writeI32(value_41); - }); - output.writeListEnd(); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[arg] is unset!"); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IMapOneList__Args { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.LIST) { - const value_42: Array = new Array(); - const metadata_1: thrift.IThriftList = input.readListBegin(); - const size_1: number = metadata_1.size; - for (let i_1: number = 0; i_1 < size_1; i_1++) { - const value_43: number = input.readI32(); - value_42.push(value_43); - } - input.readListEnd(); - _args.arg = value_42; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.arg !== undefined) { - return { - arg: _args.arg - }; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read MapOneList__Args from input"); - } - } - }; - export class MapOneList__Args extends thrift.StructLike implements IMapOneList__Args { - public arg: Array; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IMapOneList__ArgsArgs) { - super(); - if (args.arg != null) { - const value_44: Array = new Array(); - args.arg.forEach((value_45: number): void => { - const value_46: number = value_45; - value_44.push(value_46); - }); - this.arg = value_44; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[arg] is unset!"); - } - } - public static read(input: thrift.TProtocol): MapOneList__Args { - return new MapOneList__Args(MapOneList__ArgsCodec.decode(input)); - } - public static write(args: IMapOneList__ArgsArgs, output: thrift.TProtocol): void { - return MapOneList__ArgsCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return MapOneList__ArgsCodec.encode(this, output); - } - } - export interface IMapValues__Args { - arg: Map; - } - export interface IMapValues__ArgsArgs { - arg: Map; - } - export const MapValues__ArgsCodec: thrift.IStructCodec = { - encode(args: IMapValues__ArgsArgs, output: thrift.TProtocol): void { - const obj = { - arg: args.arg - }; - output.writeStructBegin("MapValues__Args"); - if (obj.arg != null) { - output.writeFieldBegin("arg", thrift.TType.MAP, 1); - output.writeMapBegin(thrift.TType.STRING, thrift.TType.I32, obj.arg.size); - obj.arg.forEach((value_47: number, key_1: string): void => { - output.writeString(key_1); - output.writeI32(value_47); - }); - output.writeMapEnd(); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[arg] is unset!"); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IMapValues__Args { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.MAP) { - const value_48: Map = new Map(); - const metadata_2: thrift.IThriftMap = input.readMapBegin(); - const size_2: number = metadata_2.size; - for (let i_2: number = 0; i_2 < size_2; i_2++) { - const key_2: string = input.readString(); - const value_49: number = input.readI32(); - value_48.set(key_2, value_49); - } - input.readMapEnd(); - _args.arg = value_48; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.arg !== undefined) { - return { - arg: _args.arg - }; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read MapValues__Args from input"); - } - } - }; - export class MapValues__Args extends thrift.StructLike implements IMapValues__Args { - public arg: Map; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IMapValues__ArgsArgs) { - super(); - if (args.arg != null) { - const value_50: Map = new Map(); - args.arg.forEach((value_51: number, key_3: string): void => { - const value_52: number = value_51; - const key_4: string = key_3; - value_50.set(key_4, value_52); - }); - this.arg = value_50; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[arg] is unset!"); - } - } - public static read(input: thrift.TProtocol): MapValues__Args { - return new MapValues__Args(MapValues__ArgsCodec.decode(input)); - } - public static write(args: IMapValues__ArgsArgs, output: thrift.TProtocol): void { - return MapValues__ArgsCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return MapValues__ArgsCodec.encode(this, output); - } - } - export interface IListToMap__Args { - arg: Array>; - } - export interface IListToMap__ArgsArgs { - arg: Array>; - } - export const ListToMap__ArgsCodec: thrift.IStructCodec = { - encode(args: IListToMap__ArgsArgs, output: thrift.TProtocol): void { - const obj = { - arg: args.arg - }; - output.writeStructBegin("ListToMap__Args"); - if (obj.arg != null) { - output.writeFieldBegin("arg", thrift.TType.LIST, 1); - output.writeListBegin(thrift.TType.LIST, obj.arg.length); - obj.arg.forEach((value_53: Array): void => { - output.writeListBegin(thrift.TType.STRING, value_53.length); - value_53.forEach((value_54: string): void => { - output.writeString(value_54); - }); - output.writeListEnd(); - }); - output.writeListEnd(); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[arg] is unset!"); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IListToMap__Args { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.LIST) { - const value_55: Array> = new Array>(); - const metadata_3: thrift.IThriftList = input.readListBegin(); - const size_3: number = metadata_3.size; - for (let i_3: number = 0; i_3 < size_3; i_3++) { - const value_56: Array = new Array(); - const metadata_4: thrift.IThriftList = input.readListBegin(); - const size_4: number = metadata_4.size; - for (let i_4: number = 0; i_4 < size_4; i_4++) { - const value_57: string = input.readString(); - value_56.push(value_57); - } - input.readListEnd(); - value_55.push(value_56); - } - input.readListEnd(); - _args.arg = value_55; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.arg !== undefined) { - return { - arg: _args.arg - }; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read ListToMap__Args from input"); - } - } - }; - export class ListToMap__Args extends thrift.StructLike implements IListToMap__Args { - public arg: Array>; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IListToMap__ArgsArgs) { - super(); - if (args.arg != null) { - const value_58: Array> = new Array>(); - args.arg.forEach((value_59: Array): void => { - const value_60: Array = new Array(); - value_59.forEach((value_61: string): void => { - const value_62: string = value_61; - value_60.push(value_62); - }); - value_58.push(value_60); - }); - this.arg = value_58; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[arg] is unset!"); - } - } - public static read(input: thrift.TProtocol): ListToMap__Args { - return new ListToMap__Args(ListToMap__ArgsCodec.decode(input)); - } - public static write(args: IListToMap__ArgsArgs, output: thrift.TProtocol): void { - return ListToMap__ArgsCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return ListToMap__ArgsCodec.encode(this, output); - } - } - export interface IFetchThing__Args { - } - export interface IFetchThing__ArgsArgs { - } - export const FetchThing__ArgsCodec: thrift.IStructCodec = { - encode(args: IFetchThing__ArgsArgs, output: thrift.TProtocol): void { - output.writeStructBegin("FetchThing__Args"); - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IFetchThing__Args { - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return {}; - } - }; - export class FetchThing__Args extends thrift.StructLike implements IFetchThing__Args { - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IFetchThing__ArgsArgs = {}) { - super(); - } - public static read(input: thrift.TProtocol): FetchThing__Args { - return new FetchThing__Args(FetchThing__ArgsCodec.decode(input)); - } - public static write(args: IFetchThing__ArgsArgs, output: thrift.TProtocol): void { - return FetchThing__ArgsCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return FetchThing__ArgsCodec.encode(this, output); - } - } - export interface IZip__Args { - } - export interface IZip__ArgsArgs { - } - export const Zip__ArgsCodec: thrift.IStructCodec = { - encode(args: IZip__ArgsArgs, output: thrift.TProtocol): void { - output.writeStructBegin("Zip__Args"); - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IZip__Args { - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return {}; - } - }; - export class Zip__Args extends thrift.StructLike implements IZip__Args { - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IZip__ArgsArgs = {}) { - super(); - } - public static read(input: thrift.TProtocol): Zip__Args { - return new Zip__Args(Zip__ArgsCodec.decode(input)); - } - public static write(args: IZip__ArgsArgs, output: thrift.TProtocol): void { - return Zip__ArgsCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return Zip__ArgsCodec.encode(this, output); - } - } - export interface IPing__Result { - success?: void; - } - export interface IPing__ResultArgs { - success?: void; - } - export const Ping__ResultCodec: thrift.IStructCodec = { - encode(args: IPing__ResultArgs, output: thrift.TProtocol): void { - output.writeStructBegin("Ping__Result"); - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IPing__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.VOID) { - input.skip(fieldType); - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - success: _args.success - }; - } - }; - export class Ping__Result extends thrift.StructLike implements IPing__Result { - public success?: void; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IPing__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_63: void = undefined; - this.success = value_63; - } - } - public static read(input: thrift.TProtocol): Ping__Result { - return new Ping__Result(Ping__ResultCodec.decode(input)); - } - public static write(args: IPing__ResultArgs, output: thrift.TProtocol): void { - return Ping__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return Ping__ResultCodec.encode(this, output); - } - } - export interface IAdd__Result { - success?: number; - exp?: operation.IJankyResult; - } - export interface IAdd__ResultArgs { - success?: number; - exp?: operation.IJankyResultArgs; - } - export const Add__ResultCodec: thrift.IStructCodec = { - encode(args: IAdd__ResultArgs, output: thrift.TProtocol): void { - const obj = { - success: args.success, - exp: args.exp - }; - output.writeStructBegin("Add__Result"); - if (obj.success != null) { - output.writeFieldBegin("success", thrift.TType.I32, 0); - output.writeI32(obj.success); - output.writeFieldEnd(); - } - if (obj.exp != null) { - output.writeFieldBegin("exp", thrift.TType.STRUCT, 1); - operation.JankyResultCodec.encode(obj.exp, output); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IAdd__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.I32) { - const value_64: number = input.readI32(); - _args.success = value_64; - } - else { - input.skip(fieldType); - } - break; - case 1: - if (fieldType === thrift.TType.STRUCT) { - const value_65: operation.IJankyResult = operation.JankyResultCodec.decode(input); - _args.exp = value_65; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - success: _args.success, - exp: _args.exp - }; - } - }; - export class Add__Result extends thrift.StructLike implements IAdd__Result { - public success?: number; - public exp?: operation.IJankyResult; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IAdd__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_66: number = args.success; - this.success = value_66; - } - if (args.exp != null) { - const value_67: operation.IJankyResult = new operation.JankyResult(args.exp); - this.exp = value_67; - } - } - public static read(input: thrift.TProtocol): Add__Result { - return new Add__Result(Add__ResultCodec.decode(input)); - } - public static write(args: IAdd__ResultArgs, output: thrift.TProtocol): void { - return Add__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return Add__ResultCodec.encode(this, output); - } - } - export interface IAddInt64__Result { - success?: thrift.Int64; - } - export interface IAddInt64__ResultArgs { - success?: number | string | thrift.Int64; - } - export const AddInt64__ResultCodec: thrift.IStructCodec = { - encode(args: IAddInt64__ResultArgs, output: thrift.TProtocol): void { - const obj = { - success: (typeof args.success === "number" ? new thrift.Int64(args.success) : typeof args.success === "string" ? thrift.Int64.fromDecimalString(args.success) : args.success) - }; - output.writeStructBegin("AddInt64__Result"); - if (obj.success != null) { - output.writeFieldBegin("success", thrift.TType.I64, 0); - output.writeI64((typeof obj.success === "number" ? new thrift.Int64(obj.success) : typeof obj.success === "string" ? thrift.Int64.fromDecimalString(obj.success) : obj.success)); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IAddInt64__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.I64) { - const value_68: thrift.Int64 = input.readI64(); - _args.success = value_68; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - success: _args.success - }; - } - }; - export class AddInt64__Result extends thrift.StructLike implements IAddInt64__Result { - public success?: thrift.Int64; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IAddInt64__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_69: thrift.Int64 = (typeof args.success === "number" ? new thrift.Int64(args.success) : typeof args.success === "string" ? thrift.Int64.fromDecimalString(args.success) : args.success); - this.success = value_69; - } - } - public static read(input: thrift.TProtocol): AddInt64__Result { - return new AddInt64__Result(AddInt64__ResultCodec.decode(input)); - } - public static write(args: IAddInt64__ResultArgs, output: thrift.TProtocol): void { - return AddInt64__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return AddInt64__ResultCodec.encode(this, output); - } - } - export interface IAddWithContext__Result { - success?: number; - } - export interface IAddWithContext__ResultArgs { - success?: number; - } - export const AddWithContext__ResultCodec: thrift.IStructCodec = { - encode(args: IAddWithContext__ResultArgs, output: thrift.TProtocol): void { - const obj = { - success: args.success - }; - output.writeStructBegin("AddWithContext__Result"); - if (obj.success != null) { - output.writeFieldBegin("success", thrift.TType.I32, 0); - output.writeI32(obj.success); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IAddWithContext__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.I32) { - const value_70: number = input.readI32(); - _args.success = value_70; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - success: _args.success - }; - } - }; - export class AddWithContext__Result extends thrift.StructLike implements IAddWithContext__Result { - public success?: number; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IAddWithContext__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_71: number = args.success; - this.success = value_71; - } - } - public static read(input: thrift.TProtocol): AddWithContext__Result { - return new AddWithContext__Result(AddWithContext__ResultCodec.decode(input)); - } - public static write(args: IAddWithContext__ResultArgs, output: thrift.TProtocol): void { - return AddWithContext__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return AddWithContext__ResultCodec.encode(this, output); - } - } - export interface ICalculate__Result { - success?: number; - ouch?: operation.IJankyOperation; - } - export interface ICalculate__ResultArgs { - success?: number; - ouch?: operation.IJankyOperationArgs; - } - export const Calculate__ResultCodec: thrift.IStructCodec = { - encode(args: ICalculate__ResultArgs, output: thrift.TProtocol): void { - const obj = { - success: args.success, - ouch: args.ouch - }; - output.writeStructBegin("Calculate__Result"); - if (obj.success != null) { - output.writeFieldBegin("success", thrift.TType.I32, 0); - output.writeI32(obj.success); - output.writeFieldEnd(); - } - if (obj.ouch != null) { - output.writeFieldBegin("ouch", thrift.TType.STRUCT, 1); - operation.JankyOperationCodec.encode(obj.ouch, output); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): ICalculate__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.I32) { - const value_72: number = input.readI32(); - _args.success = value_72; - } - else { - input.skip(fieldType); - } - break; - case 1: - if (fieldType === thrift.TType.STRUCT) { - const value_73: operation.IJankyOperation = operation.JankyOperationCodec.decode(input); - _args.ouch = value_73; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - success: _args.success, - ouch: _args.ouch - }; - } - }; - export class Calculate__Result extends thrift.StructLike implements ICalculate__Result { - public success?: number; - public ouch?: operation.IJankyOperation; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: ICalculate__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_74: number = args.success; - this.success = value_74; - } - if (args.ouch != null) { - const value_75: operation.IJankyOperation = new operation.JankyOperation(args.ouch); - this.ouch = value_75; - } - } - public static read(input: thrift.TProtocol): Calculate__Result { - return new Calculate__Result(Calculate__ResultCodec.decode(input)); - } - public static write(args: ICalculate__ResultArgs, output: thrift.TProtocol): void { - return Calculate__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return Calculate__ResultCodec.encode(this, output); - } - } - export interface IEchoBinary__Result { - success?: string; - } - export interface IEchoBinary__ResultArgs { - success?: string; - } - export const EchoBinary__ResultCodec: thrift.IStructCodec = { - encode(args: IEchoBinary__ResultArgs, output: thrift.TProtocol): void { - const obj = { - success: args.success - }; - output.writeStructBegin("EchoBinary__Result"); - if (obj.success != null) { - output.writeFieldBegin("success", thrift.TType.STRING, 0); - output.writeString(obj.success); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IEchoBinary__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.STRING) { - const value_76: string = input.readString(); - _args.success = value_76; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - success: _args.success - }; - } - }; - export class EchoBinary__Result extends thrift.StructLike implements IEchoBinary__Result { - public success?: string; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IEchoBinary__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_77: string = args.success; - this.success = value_77; - } - } - public static read(input: thrift.TProtocol): EchoBinary__Result { - return new EchoBinary__Result(EchoBinary__ResultCodec.decode(input)); - } - public static write(args: IEchoBinary__ResultArgs, output: thrift.TProtocol): void { - return EchoBinary__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return EchoBinary__ResultCodec.encode(this, output); - } - } - export interface IEchoString__Result { - success?: string; - } - export interface IEchoString__ResultArgs { - success?: string; - } - export const EchoString__ResultCodec: thrift.IStructCodec = { - encode(args: IEchoString__ResultArgs, output: thrift.TProtocol): void { - const obj = { - success: args.success - }; - output.writeStructBegin("EchoString__Result"); - if (obj.success != null) { - output.writeFieldBegin("success", thrift.TType.STRING, 0); - output.writeString(obj.success); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IEchoString__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.STRING) { - const value_78: string = input.readString(); - _args.success = value_78; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - success: _args.success - }; - } - }; - export class EchoString__Result extends thrift.StructLike implements IEchoString__Result { - public success?: string; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IEchoString__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_79: string = args.success; - this.success = value_79; - } - } - public static read(input: thrift.TProtocol): EchoString__Result { - return new EchoString__Result(EchoString__ResultCodec.decode(input)); - } - public static write(args: IEchoString__ResultArgs, output: thrift.TProtocol): void { - return EchoString__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return EchoString__ResultCodec.encode(this, output); - } - } - export interface ICheckName__Result { - success?: string; - } - export interface ICheckName__ResultArgs { - success?: string; - } - export const CheckName__ResultCodec: thrift.IStructCodec = { - encode(args: ICheckName__ResultArgs, output: thrift.TProtocol): void { - const obj = { - success: args.success - }; - output.writeStructBegin("CheckName__Result"); - if (obj.success != null) { - output.writeFieldBegin("success", thrift.TType.STRING, 0); - output.writeString(obj.success); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): ICheckName__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.STRING) { - const value_80: string = input.readString(); - _args.success = value_80; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - success: _args.success - }; - } - }; - export class CheckName__Result extends thrift.StructLike implements ICheckName__Result { - public success?: string; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: ICheckName__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_81: string = args.success; - this.success = value_81; - } - } - public static read(input: thrift.TProtocol): CheckName__Result { - return new CheckName__Result(CheckName__ResultCodec.decode(input)); - } - public static write(args: ICheckName__ResultArgs, output: thrift.TProtocol): void { - return CheckName__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return CheckName__ResultCodec.encode(this, output); - } - } - export interface ICheckOptional__Result { - success?: string; - } - export interface ICheckOptional__ResultArgs { - success?: string; - } - export const CheckOptional__ResultCodec: thrift.IStructCodec = { - encode(args: ICheckOptional__ResultArgs, output: thrift.TProtocol): void { - const obj = { - success: args.success - }; - output.writeStructBegin("CheckOptional__Result"); - if (obj.success != null) { - output.writeFieldBegin("success", thrift.TType.STRING, 0); - output.writeString(obj.success); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): ICheckOptional__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.STRING) { - const value_82: string = input.readString(); - _args.success = value_82; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - success: _args.success - }; - } - }; - export class CheckOptional__Result extends thrift.StructLike implements ICheckOptional__Result { - public success?: string; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: ICheckOptional__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_83: string = args.success; - this.success = value_83; - } - } - public static read(input: thrift.TProtocol): CheckOptional__Result { - return new CheckOptional__Result(CheckOptional__ResultCodec.decode(input)); - } - public static write(args: ICheckOptional__ResultArgs, output: thrift.TProtocol): void { - return CheckOptional__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return CheckOptional__ResultCodec.encode(this, output); - } - } - export interface IMapOneList__Result { - success?: Array; - } - export interface IMapOneList__ResultArgs { - success?: Array; - } - export const MapOneList__ResultCodec: thrift.IStructCodec = { - encode(args: IMapOneList__ResultArgs, output: thrift.TProtocol): void { - const obj = { - success: args.success - }; - output.writeStructBegin("MapOneList__Result"); - if (obj.success != null) { - output.writeFieldBegin("success", thrift.TType.LIST, 0); - output.writeListBegin(thrift.TType.I32, obj.success.length); - obj.success.forEach((value_84: number): void => { - output.writeI32(value_84); - }); - output.writeListEnd(); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IMapOneList__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.LIST) { - const value_85: Array = new Array(); - const metadata_5: thrift.IThriftList = input.readListBegin(); - const size_5: number = metadata_5.size; - for (let i_5: number = 0; i_5 < size_5; i_5++) { - const value_86: number = input.readI32(); - value_85.push(value_86); - } - input.readListEnd(); - _args.success = value_85; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - success: _args.success - }; - } - }; - export class MapOneList__Result extends thrift.StructLike implements IMapOneList__Result { - public success?: Array; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IMapOneList__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_87: Array = new Array(); - args.success.forEach((value_88: number): void => { - const value_89: number = value_88; - value_87.push(value_89); - }); - this.success = value_87; - } - } - public static read(input: thrift.TProtocol): MapOneList__Result { - return new MapOneList__Result(MapOneList__ResultCodec.decode(input)); - } - public static write(args: IMapOneList__ResultArgs, output: thrift.TProtocol): void { - return MapOneList__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return MapOneList__ResultCodec.encode(this, output); - } - } - export interface IMapValues__Result { - success?: Array; - } - export interface IMapValues__ResultArgs { - success?: Array; - } - export const MapValues__ResultCodec: thrift.IStructCodec = { - encode(args: IMapValues__ResultArgs, output: thrift.TProtocol): void { - const obj = { - success: args.success - }; - output.writeStructBegin("MapValues__Result"); - if (obj.success != null) { - output.writeFieldBegin("success", thrift.TType.LIST, 0); - output.writeListBegin(thrift.TType.I32, obj.success.length); - obj.success.forEach((value_90: number): void => { - output.writeI32(value_90); - }); - output.writeListEnd(); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IMapValues__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.LIST) { - const value_91: Array = new Array(); - const metadata_6: thrift.IThriftList = input.readListBegin(); - const size_6: number = metadata_6.size; - for (let i_6: number = 0; i_6 < size_6; i_6++) { - const value_92: number = input.readI32(); - value_91.push(value_92); - } - input.readListEnd(); - _args.success = value_91; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - success: _args.success - }; - } - }; - export class MapValues__Result extends thrift.StructLike implements IMapValues__Result { - public success?: Array; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IMapValues__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_93: Array = new Array(); - args.success.forEach((value_94: number): void => { - const value_95: number = value_94; - value_93.push(value_95); - }); - this.success = value_93; - } - } - public static read(input: thrift.TProtocol): MapValues__Result { - return new MapValues__Result(MapValues__ResultCodec.decode(input)); - } - public static write(args: IMapValues__ResultArgs, output: thrift.TProtocol): void { - return MapValues__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return MapValues__ResultCodec.encode(this, output); - } - } - export interface IListToMap__Result { - success?: Map; - } - export interface IListToMap__ResultArgs { - success?: Map; - } - export const ListToMap__ResultCodec: thrift.IStructCodec = { - encode(args: IListToMap__ResultArgs, output: thrift.TProtocol): void { - const obj = { - success: args.success - }; - output.writeStructBegin("ListToMap__Result"); - if (obj.success != null) { - output.writeFieldBegin("success", thrift.TType.MAP, 0); - output.writeMapBegin(thrift.TType.STRING, thrift.TType.STRING, obj.success.size); - obj.success.forEach((value_96: string, key_5: string): void => { - output.writeString(key_5); - output.writeString(value_96); - }); - output.writeMapEnd(); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IListToMap__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.MAP) { - const value_97: Map = new Map(); - const metadata_7: thrift.IThriftMap = input.readMapBegin(); - const size_7: number = metadata_7.size; - for (let i_7: number = 0; i_7 < size_7; i_7++) { - const key_6: string = input.readString(); - const value_98: string = input.readString(); - value_97.set(key_6, value_98); - } - input.readMapEnd(); - _args.success = value_97; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - success: _args.success - }; - } - }; - export class ListToMap__Result extends thrift.StructLike implements IListToMap__Result { - public success?: Map; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IListToMap__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_99: Map = new Map(); - args.success.forEach((value_100: string, key_7: string): void => { - const value_101: string = value_100; - const key_8: string = key_7; - value_99.set(key_8, value_101); - }); - this.success = value_99; - } - } - public static read(input: thrift.TProtocol): ListToMap__Result { - return new ListToMap__Result(ListToMap__ResultCodec.decode(input)); - } - public static write(args: IListToMap__ResultArgs, output: thrift.TProtocol): void { - return ListToMap__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return ListToMap__ResultCodec.encode(this, output); - } - } - export interface IFetchThing__Result { - success?: common.ICommonStruct; - } - export interface IFetchThing__ResultArgs { - success?: common.ICommonStructArgs; - } - export const FetchThing__ResultCodec: thrift.IStructCodec = { - encode(args: IFetchThing__ResultArgs, output: thrift.TProtocol): void { - const obj = { - success: args.success - }; - output.writeStructBegin("FetchThing__Result"); - if (obj.success != null) { - output.writeFieldBegin("success", thrift.TType.STRUCT, 0); - common.CommonStructCodec.encode(obj.success, output); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IFetchThing__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.STRUCT) { - const value_102: common.ICommonStruct = common.CommonStructCodec.decode(input); - _args.success = value_102; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - success: _args.success - }; - } - }; - export class FetchThing__Result extends thrift.StructLike implements IFetchThing__Result { - public success?: common.ICommonStruct; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IFetchThing__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_103: common.ICommonStruct = new common.CommonStruct(args.success); - this.success = value_103; - } - } - public static read(input: thrift.TProtocol): FetchThing__Result { - return new FetchThing__Result(FetchThing__ResultCodec.decode(input)); - } - public static write(args: IFetchThing__ResultArgs, output: thrift.TProtocol): void { - return FetchThing__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return FetchThing__ResultCodec.encode(this, output); - } - } - export interface IZip__Result { - success?: void; - } - export interface IZip__ResultArgs { - success?: void; - } - export const Zip__ResultCodec: thrift.IStructCodec = { - encode(args: IZip__ResultArgs, output: thrift.TProtocol): void { - output.writeStructBegin("Zip__Result"); - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IZip__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.VOID) { - input.skip(fieldType); - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - success: _args.success - }; - } - }; - export class Zip__Result extends thrift.StructLike implements IZip__Result { - public success?: void; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IZip__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_104: void = undefined; - this.success = value_104; - } - } - public static read(input: thrift.TProtocol): Zip__Result { - return new Zip__Result(Zip__ResultCodec.decode(input)); - } - public static write(args: IZip__ResultArgs, output: thrift.TProtocol): void { - return Zip__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return Zip__ResultCodec.encode(this, output); - } - } - export class Client extends shared.SharedService.Client { - public static readonly serviceName: string = serviceName; - public static readonly annotations: thrift.IThriftAnnotations = annotations; - public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public static readonly methodNames: Array = methodNames; - public readonly _serviceName: string = serviceName; - public readonly _annotations: thrift.IThriftAnnotations = annotations; - public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public readonly _methodNames: Array = methodNames; - constructor(connection: thrift.IThriftConnection) { - super(connection); - } - public ping(context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("ping", thrift.MessageType.CALL, this.incrementRequestId()); - const args: IPing__ArgsArgs = {}; - Ping__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "ping") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: IPing__Result = Ping__ResultCodec.decode(input); - input.readMessageEnd(); - return Promise.resolve(result.success); - } - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } - } - catch (err) { - return Promise.reject(err); - } - }); - } - public add(num1: number, num2: number, context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("add", thrift.MessageType.CALL, this.incrementRequestId()); - const args: IAdd__ArgsArgs = { num1, num2 }; - Add__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "add") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: IAdd__Result = Add__ResultCodec.decode(input); - input.readMessageEnd(); - if (result.exp != null) { - return Promise.reject(result.exp); - } - else if (result.success != null) { - return Promise.resolve(result.success); - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "add failed: unknown result")); - } - } - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } - } - catch (err) { - return Promise.reject(err); - } - }); - } - public addInt64(num1: number | string | thrift.Int64, num2: number | string | thrift.Int64, context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("addInt64", thrift.MessageType.CALL, this.incrementRequestId()); - const args: IAddInt64__ArgsArgs = { num1, num2 }; - AddInt64__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "addInt64") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: IAddInt64__Result = AddInt64__ResultCodec.decode(input); - input.readMessageEnd(); - if (result.success != null) { - return Promise.resolve(result.success); - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "addInt64 failed: unknown result")); - } - } - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } - } - catch (err) { - return Promise.reject(err); - } - }); - } - public addWithContext(num1: number, num2: number, context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("addWithContext", thrift.MessageType.CALL, this.incrementRequestId()); - const args: IAddWithContext__ArgsArgs = { num1, num2 }; - AddWithContext__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "addWithContext") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: IAddWithContext__Result = AddWithContext__ResultCodec.decode(input); - input.readMessageEnd(); - if (result.success != null) { - return Promise.resolve(result.success); - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "addWithContext failed: unknown result")); - } - } - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } - } - catch (err) { - return Promise.reject(err); - } - }); - } - public calculate(logid: number, work: IWorkArgs, context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("calculate", thrift.MessageType.CALL, this.incrementRequestId()); - const args: ICalculate__ArgsArgs = { logid, work }; - Calculate__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "calculate") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: ICalculate__Result = Calculate__ResultCodec.decode(input); - input.readMessageEnd(); - if (result.ouch != null) { - return Promise.reject(result.ouch); - } - else if (result.success != null) { - return Promise.resolve(result.success); - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "calculate failed: unknown result")); - } - } - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } - } - catch (err) { - return Promise.reject(err); - } - }); - } - public echoBinary(word: string | Buffer, context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("echoBinary", thrift.MessageType.CALL, this.incrementRequestId()); - const args: IEchoBinary__ArgsArgs = { word }; - EchoBinary__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "echoBinary") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: IEchoBinary__Result = EchoBinary__ResultCodec.decode(input); - input.readMessageEnd(); - if (result.success != null) { - return Promise.resolve(result.success); - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "echoBinary failed: unknown result")); - } - } - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } - } - catch (err) { - return Promise.reject(err); - } - }); - } - public echoString(word: string, context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("echoString", thrift.MessageType.CALL, this.incrementRequestId()); - const args: IEchoString__ArgsArgs = { word }; - EchoString__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "echoString") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: IEchoString__Result = EchoString__ResultCodec.decode(input); - input.readMessageEnd(); - if (result.success != null) { - return Promise.resolve(result.success); - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "echoString failed: unknown result")); - } - } - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } - } - catch (err) { - return Promise.reject(err); - } - }); - } - public checkName(choice: ChoiceArgs, context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("checkName", thrift.MessageType.CALL, this.incrementRequestId()); - const args: ICheckName__ArgsArgs = { choice }; - CheckName__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "checkName") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: ICheckName__Result = CheckName__ResultCodec.decode(input); - input.readMessageEnd(); - if (result.success != null) { - return Promise.resolve(result.success); - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "checkName failed: unknown result")); - } - } - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } - } - catch (err) { - return Promise.reject(err); - } - }); - } - public checkOptional(type?: string, context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("checkOptional", thrift.MessageType.CALL, this.incrementRequestId()); - const args: ICheckOptional__ArgsArgs = { type }; - CheckOptional__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "checkOptional") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: ICheckOptional__Result = CheckOptional__ResultCodec.decode(input); - input.readMessageEnd(); - if (result.success != null) { - return Promise.resolve(result.success); - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "checkOptional failed: unknown result")); - } - } - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } - } - catch (err) { - return Promise.reject(err); - } - }); - } - public mapOneList(arg: Array, context?: Context): Promise> { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("mapOneList", thrift.MessageType.CALL, this.incrementRequestId()); - const args: IMapOneList__ArgsArgs = { arg }; - MapOneList__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "mapOneList") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: IMapOneList__Result = MapOneList__ResultCodec.decode(input); - input.readMessageEnd(); - if (result.success != null) { - return Promise.resolve(result.success); - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "mapOneList failed: unknown result")); - } - } - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } - } - catch (err) { - return Promise.reject(err); - } - }); - } - public mapValues(arg: Map, context?: Context): Promise> { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("mapValues", thrift.MessageType.CALL, this.incrementRequestId()); - const args: IMapValues__ArgsArgs = { arg }; - MapValues__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "mapValues") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: IMapValues__Result = MapValues__ResultCodec.decode(input); - input.readMessageEnd(); - if (result.success != null) { - return Promise.resolve(result.success); - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "mapValues failed: unknown result")); - } - } - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } - } - catch (err) { - return Promise.reject(err); - } - }); - } - public listToMap(arg: Array>, context?: Context): Promise> { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("listToMap", thrift.MessageType.CALL, this.incrementRequestId()); - const args: IListToMap__ArgsArgs = { arg }; - ListToMap__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "listToMap") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: IListToMap__Result = ListToMap__ResultCodec.decode(input); - input.readMessageEnd(); - if (result.success != null) { - return Promise.resolve(result.success); - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "listToMap failed: unknown result")); - } - } - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } - } - catch (err) { - return Promise.reject(err); - } - }); - } - public fetchThing(context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("fetchThing", thrift.MessageType.CALL, this.incrementRequestId()); - const args: IFetchThing__ArgsArgs = {}; - FetchThing__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "fetchThing") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: IFetchThing__Result = FetchThing__ResultCodec.decode(input); - input.readMessageEnd(); - if (result.success != null) { - return Promise.resolve(result.success); - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "fetchThing failed: unknown result")); - } - } - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } - } - catch (err) { - return Promise.reject(err); - } - }); - } - public zip(context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("zip", thrift.MessageType.CALL, this.incrementRequestId()); - const args: IZip__ArgsArgs = {}; - Zip__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "zip") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: IZip__Result = Zip__ResultCodec.decode(input); - input.readMessageEnd(); - return Promise.resolve(result.success); - } - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } - } - catch (err) { - return Promise.reject(err); - } - }); - } - } - export interface ILocalHandler { - ping(context?: Context): void | Promise; - add(num1: number, num2: number, context?: Context): number | Promise; - addInt64(num1: thrift.Int64, num2: thrift.Int64, context?: Context): (number | string | thrift.Int64) | Promise; - addWithContext(num1: number, num2: number, context?: Context): number | Promise; - calculate(logid: number, work: IWork, context?: Context): number | Promise; - echoBinary(word: Buffer, context?: Context): string | Promise; - echoString(word: string, context?: Context): string | Promise; - checkName(choice: Choice, context?: Context): string | Promise; - checkOptional(type?: string, context?: Context): string | Promise; - mapOneList(arg: Array, context?: Context): Array | Promise>; - mapValues(arg: Map, context?: Context): Array | Promise>; - listToMap(arg: Array>, context?: Context): Map | Promise>; - fetchThing(context?: Context): common.ICommonStructArgs | Promise; - zip(context?: Context): void | Promise; - } - export type IHandler = ILocalHandler & shared.SharedService.IHandler; - export class Processor extends shared.SharedService.Processor { - protected readonly _handler: IHandler; - public static readonly serviceName: string = serviceName; - public static readonly annotations: thrift.IThriftAnnotations = annotations; - public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public static readonly methodNames: Array = methodNames; - public readonly _serviceName: string = serviceName; - public readonly _annotations: thrift.IThriftAnnotations = annotations; - public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public readonly _methodNames: Array = methodNames; - constructor(handler: IHandler) { - super({ - getStruct: handler.getStruct, - getUnion: handler.getUnion - }); - this._handler = handler; - } - public process(input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - const metadata: thrift.IThriftMessage = input.readMessageBegin(); - const fieldName: string = metadata.fieldName; - const requestId: number = metadata.requestId; - const methodName: string = "process_" + fieldName; - switch (methodName) { - case "process_getStruct": { - resolve(this.process_getStruct(requestId, input, output, context)); - break; - } - case "process_getUnion": { - resolve(this.process_getUnion(requestId, input, output, context)); - break; - } - case "process_ping": { - resolve(this.process_ping(requestId, input, output, context)); - break; - } - case "process_add": { - resolve(this.process_add(requestId, input, output, context)); - break; - } - case "process_addInt64": { - resolve(this.process_addInt64(requestId, input, output, context)); - break; - } - case "process_addWithContext": { - resolve(this.process_addWithContext(requestId, input, output, context)); - break; - } - case "process_calculate": { - resolve(this.process_calculate(requestId, input, output, context)); - break; - } - case "process_echoBinary": { - resolve(this.process_echoBinary(requestId, input, output, context)); - break; - } - case "process_echoString": { - resolve(this.process_echoString(requestId, input, output, context)); - break; - } - case "process_checkName": { - resolve(this.process_checkName(requestId, input, output, context)); - break; - } - case "process_checkOptional": { - resolve(this.process_checkOptional(requestId, input, output, context)); - break; - } - case "process_mapOneList": { - resolve(this.process_mapOneList(requestId, input, output, context)); - break; - } - case "process_mapValues": { - resolve(this.process_mapValues(requestId, input, output, context)); - break; - } - case "process_listToMap": { - resolve(this.process_listToMap(requestId, input, output, context)); - break; - } - case "process_fetchThing": { - resolve(this.process_fetchThing(requestId, input, output, context)); - break; - } - case "process_zip": { - resolve(this.process_zip(requestId, input, output, context)); - break; - } - default: { - input.skip(thrift.TType.STRUCT); - input.readMessageEnd(); - const errMessage = "Unknown function " + fieldName; - const err = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN_METHOD, errMessage); - output.writeMessageBegin(fieldName, thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(err, output); - output.writeMessageEnd(); - resolve(output.flush()); - break; - } - } - }); - } - public process_ping(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { - input.readMessageEnd(); - resolve(this._handler.ping(context)); - } - catch (err) { - reject(err); - } - }).then((data: void): Buffer => { - const result: IPing__ResultArgs = { success: data }; - output.writeMessageBegin("ping", thrift.MessageType.REPLY, requestId); - Ping__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("ping", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } - public process_add(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { - const args: IAdd__Args = Add__ArgsCodec.decode(input); - input.readMessageEnd(); - resolve(this._handler.add(args.num1, args.num2, context)); - } - catch (err) { - reject(err); - } - }).then((data: number): Buffer => { - const result: IAdd__ResultArgs = { success: data }; - output.writeMessageBegin("add", thrift.MessageType.REPLY, requestId); - Add__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - if (err instanceof operation.JankyResult) { - const result: IAdd__ResultArgs = { exp: err }; - output.writeMessageBegin("add", thrift.MessageType.REPLY, requestId); - Add__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - } - else { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("add", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - } - }); - } - public process_addInt64(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { - const args: IAddInt64__Args = AddInt64__ArgsCodec.decode(input); - input.readMessageEnd(); - resolve(this._handler.addInt64(args.num1, args.num2, context)); - } - catch (err) { - reject(err); - } - }).then((data: number | string | thrift.Int64): Buffer => { - const result: IAddInt64__ResultArgs = { success: data }; - output.writeMessageBegin("addInt64", thrift.MessageType.REPLY, requestId); - AddInt64__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("addInt64", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } - public process_addWithContext(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { - const args: IAddWithContext__Args = AddWithContext__ArgsCodec.decode(input); - input.readMessageEnd(); - resolve(this._handler.addWithContext(args.num1, args.num2, context)); - } - catch (err) { - reject(err); - } - }).then((data: number): Buffer => { - const result: IAddWithContext__ResultArgs = { success: data }; - output.writeMessageBegin("addWithContext", thrift.MessageType.REPLY, requestId); - AddWithContext__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("addWithContext", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } - public process_calculate(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { - const args: ICalculate__Args = Calculate__ArgsCodec.decode(input); - input.readMessageEnd(); - resolve(this._handler.calculate(args.logid, args.work, context)); - } - catch (err) { - reject(err); - } - }).then((data: number): Buffer => { - const result: ICalculate__ResultArgs = { success: data }; - output.writeMessageBegin("calculate", thrift.MessageType.REPLY, requestId); - Calculate__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - if (err instanceof operation.JankyOperation) { - const result: ICalculate__ResultArgs = { ouch: err }; - output.writeMessageBegin("calculate", thrift.MessageType.REPLY, requestId); - Calculate__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - } - else { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("calculate", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - } - }); - } - public process_echoBinary(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { - const args: IEchoBinary__Args = EchoBinary__ArgsCodec.decode(input); - input.readMessageEnd(); - resolve(this._handler.echoBinary(args.word, context)); - } - catch (err) { - reject(err); - } - }).then((data: string): Buffer => { - const result: IEchoBinary__ResultArgs = { success: data }; - output.writeMessageBegin("echoBinary", thrift.MessageType.REPLY, requestId); - EchoBinary__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("echoBinary", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } - public process_echoString(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { - const args: IEchoString__Args = EchoString__ArgsCodec.decode(input); - input.readMessageEnd(); - resolve(this._handler.echoString(args.word, context)); - } - catch (err) { - reject(err); - } - }).then((data: string): Buffer => { - const result: IEchoString__ResultArgs = { success: data }; - output.writeMessageBegin("echoString", thrift.MessageType.REPLY, requestId); - EchoString__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("echoString", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } - public process_checkName(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { - const args: ICheckName__Args = CheckName__ArgsCodec.decode(input); - input.readMessageEnd(); - resolve(this._handler.checkName(args.choice, context)); - } - catch (err) { - reject(err); - } - }).then((data: string): Buffer => { - const result: ICheckName__ResultArgs = { success: data }; - output.writeMessageBegin("checkName", thrift.MessageType.REPLY, requestId); - CheckName__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("checkName", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } - public process_checkOptional(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { - const args: ICheckOptional__Args = CheckOptional__ArgsCodec.decode(input); - input.readMessageEnd(); - resolve(this._handler.checkOptional(args.type, context)); - } - catch (err) { - reject(err); - } - }).then((data: string): Buffer => { - const result: ICheckOptional__ResultArgs = { success: data }; - output.writeMessageBegin("checkOptional", thrift.MessageType.REPLY, requestId); - CheckOptional__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("checkOptional", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } - public process_mapOneList(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise>((resolve, reject): void => { - try { - const args: IMapOneList__Args = MapOneList__ArgsCodec.decode(input); - input.readMessageEnd(); - resolve(this._handler.mapOneList(args.arg, context)); - } - catch (err) { - reject(err); - } - }).then((data: Array): Buffer => { - const result: IMapOneList__ResultArgs = { success: data }; - output.writeMessageBegin("mapOneList", thrift.MessageType.REPLY, requestId); - MapOneList__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("mapOneList", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } - public process_mapValues(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise>((resolve, reject): void => { - try { - const args: IMapValues__Args = MapValues__ArgsCodec.decode(input); - input.readMessageEnd(); - resolve(this._handler.mapValues(args.arg, context)); - } - catch (err) { - reject(err); - } - }).then((data: Array): Buffer => { - const result: IMapValues__ResultArgs = { success: data }; - output.writeMessageBegin("mapValues", thrift.MessageType.REPLY, requestId); - MapValues__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("mapValues", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } - public process_listToMap(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise>((resolve, reject): void => { - try { - const args: IListToMap__Args = ListToMap__ArgsCodec.decode(input); - input.readMessageEnd(); - resolve(this._handler.listToMap(args.arg, context)); - } - catch (err) { - reject(err); - } - }).then((data: Map): Buffer => { - const result: IListToMap__ResultArgs = { success: data }; - output.writeMessageBegin("listToMap", thrift.MessageType.REPLY, requestId); - ListToMap__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("listToMap", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } - public process_fetchThing(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { - input.readMessageEnd(); - resolve(this._handler.fetchThing(context)); - } - catch (err) { - reject(err); - } - }).then((data: common.ICommonStructArgs): Buffer => { - const result: IFetchThing__ResultArgs = { success: data }; - output.writeMessageBegin("fetchThing", thrift.MessageType.REPLY, requestId); - FetchThing__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("fetchThing", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } - public process_zip(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { - input.readMessageEnd(); - resolve(this._handler.zip(context)); - } - catch (err) { - reject(err); - } - }).then((data: void): Buffer => { - const result: IZip__ResultArgs = { success: data }; - output.writeMessageBegin("zip", thrift.MessageType.REPLY, requestId); - Zip__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("zip", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } - } -} diff --git a/src/tests/unit/fixtures/generated/strict-unions/operation/index.ts b/src/tests/unit/fixtures/generated/strict-unions/operation/index.ts deleted file mode 100644 index c25135b5..00000000 --- a/src/tests/unit/fixtures/generated/strict-unions/operation/index.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* tslint:disable */ -/* - * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} - * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING -*/ -import * as exceptions from "./../exceptions"; -export enum Operation { - ADD = 1, - SUBTRACT = 2, - MULTIPLY = 3, - DIVIDE = 4 -} -export import IJankyOperation = exceptions.IInvalidOperation; -export import IJankyOperationArgs = exceptions.IInvalidOperationArgs; -export import JankyOperation = exceptions.InvalidOperation; -export import JankyOperationCodec = exceptions.InvalidOperationCodec; -export import IJankyResult = exceptions.IInvalidResult; -export import IJankyResultArgs = exceptions.IInvalidResultArgs; -export import JankyResult = exceptions.InvalidResult; -export import JankyResultCodec = exceptions.InvalidResultCodec; -export import SomethingToDo = Operation; diff --git a/src/tests/unit/fixtures/generated/strict-unions/shared/index.ts b/src/tests/unit/fixtures/generated/strict-unions/shared/index.ts deleted file mode 100644 index 0d3d1d9f..00000000 --- a/src/tests/unit/fixtures/generated/strict-unions/shared/index.ts +++ /dev/null @@ -1,865 +0,0 @@ -/* tslint:disable */ -/* - * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} - * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING -*/ -import * as thrift from "test-lib"; -export const SHARED_INT: number = 45; -export interface ICode { - status?: thrift.Int64; -} -export interface ICodeArgs { - status?: number | string | thrift.Int64; -} -export const CodeCodec: thrift.IStructCodec = { - encode(args: ICodeArgs, output: thrift.TProtocol): void { - const obj = { - status: (typeof args.status === "number" ? new thrift.Int64(args.status) : typeof args.status === "string" ? thrift.Int64.fromDecimalString(args.status) : args.status) - }; - output.writeStructBegin("Code"); - if (obj.status != null) { - output.writeFieldBegin("status", thrift.TType.I64, 1); - output.writeI64((typeof obj.status === "number" ? new thrift.Int64(obj.status) : typeof obj.status === "string" ? thrift.Int64.fromDecimalString(obj.status) : obj.status)); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): ICode { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.I64) { - const value_1: thrift.Int64 = input.readI64(); - _args.status = value_1; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - status: _args.status - }; - } -}; -export class Code extends thrift.StructLike implements ICode { - public status?: thrift.Int64; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: ICodeArgs = {}) { - super(); - if (args.status != null) { - const value_2: thrift.Int64 = (typeof args.status === "number" ? new thrift.Int64(args.status) : typeof args.status === "string" ? thrift.Int64.fromDecimalString(args.status) : args.status); - this.status = value_2; - } - } - public static read(input: thrift.TProtocol): Code { - return new Code(CodeCodec.decode(input)); - } - public static write(args: ICodeArgs, output: thrift.TProtocol): void { - return CodeCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return CodeCodec.encode(this, output); - } -} -export interface ISharedStruct { - code: ICode; - value: string; -} -export interface ISharedStructArgs { - code: ICodeArgs; - value: string; -} -export const SharedStructCodec: thrift.IStructCodec = { - encode(args: ISharedStructArgs, output: thrift.TProtocol): void { - const obj = { - code: args.code, - value: args.value - }; - output.writeStructBegin("SharedStruct"); - if (obj.code != null) { - output.writeFieldBegin("code", thrift.TType.STRUCT, 1); - CodeCodec.encode(obj.code, output); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[code] is unset!"); - } - if (obj.value != null) { - output.writeFieldBegin("value", thrift.TType.STRING, 2); - output.writeString(obj.value); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[value] is unset!"); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): ISharedStruct { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.STRUCT) { - const value_3: ICode = CodeCodec.decode(input); - _args.code = value_3; - } - else { - input.skip(fieldType); - } - break; - case 2: - if (fieldType === thrift.TType.STRING) { - const value_4: string = input.readString(); - _args.value = value_4; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.code !== undefined && _args.value !== undefined) { - return { - code: _args.code, - value: _args.value - }; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read SharedStruct from input"); - } - } -}; -export class SharedStruct extends thrift.StructLike implements ISharedStruct { - public code: ICode; - public value: string; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: ISharedStructArgs) { - super(); - if (args.code != null) { - const value_5: ICode = new Code(args.code); - this.code = value_5; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[code] is unset!"); - } - if (args.value != null) { - const value_6: string = args.value; - this.value = value_6; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[value] is unset!"); - } - } - public static read(input: thrift.TProtocol): SharedStruct { - return new SharedStruct(SharedStructCodec.decode(input)); - } - public static write(args: ISharedStructArgs, output: thrift.TProtocol): void { - return SharedStructCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return SharedStructCodec.encode(this, output); - } -} -export enum SharedUnion__Type { - SharedUnionWithOption1 = "option1", - SharedUnionWithOption2 = "option2" -} -export type SharedUnion = ISharedUnionWithOption1 | ISharedUnionWithOption2; -export interface ISharedUnionWithOption1 { - __type: SharedUnion__Type.SharedUnionWithOption1; - option1: string; - option2?: void; -} -export interface ISharedUnionWithOption2 { - __type: SharedUnion__Type.SharedUnionWithOption2; - option1?: void; - option2: string; -} -export type SharedUnionArgs = ISharedUnionWithOption1Args | ISharedUnionWithOption2Args; -export interface ISharedUnionWithOption1Args { - option1: string; - option2?: void; -} -export interface ISharedUnionWithOption2Args { - option1?: void; - option2: string; -} -export const SharedUnionCodec: thrift.IStructToolkit = { - create(args: SharedUnionArgs): SharedUnion { - let _fieldsSet: number = 0; - let _returnValue: any = null; - if (args.option1 != null) { - _fieldsSet++; - const value_7: string = args.option1; - _returnValue = { option1: value_7 }; - } - if (args.option2 != null) { - _fieldsSet++; - const value_8: string = args.option2; - _returnValue = { option2: value_8 }; - } - if (_fieldsSet > 1) { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion cannot have more than one value"); - } - else if (_fieldsSet < 1) { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion must have one value set"); - } - if (_returnValue !== null) { - if (_returnValue.option1) { - return { - __type: SharedUnion__Type.SharedUnionWithOption1, - option1: _returnValue.option1 - }; - } - else { - return { - __type: SharedUnion__Type.SharedUnionWithOption2, - option2: _returnValue.option2 - }; - } - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read data for TUnion"); - } - }, - encode(args: SharedUnionArgs, output: thrift.TProtocol): void { - let _fieldsSet: number = 0; - const obj = { - option1: args.option1, - option2: args.option2 - }; - output.writeStructBegin("SharedUnion"); - if (obj.option1 != null) { - _fieldsSet++; - output.writeFieldBegin("option1", thrift.TType.STRING, 1); - output.writeString(obj.option1); - output.writeFieldEnd(); - } - if (obj.option2 != null) { - _fieldsSet++; - output.writeFieldBegin("option2", thrift.TType.STRING, 2); - output.writeString(obj.option2); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - if (_fieldsSet > 1) { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion cannot have more than one value"); - } - else if (_fieldsSet < 1) { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion must have one value set"); - } - return; - }, - decode(input: thrift.TProtocol): SharedUnion { - let _fieldsSet: number = 0; - let _returnValue: any = null; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.STRING) { - _fieldsSet++; - const value_9: string = input.readString(); - _returnValue = { option1: value_9 }; - } - else { - input.skip(fieldType); - } - break; - case 2: - if (fieldType === thrift.TType.STRING) { - _fieldsSet++; - const value_10: string = input.readString(); - _returnValue = { option2: value_10 }; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_fieldsSet > 1) { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion cannot have more than one value"); - } - else if (_fieldsSet < 1) { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion must have one value set"); - } - if (_returnValue !== null) { - if (_returnValue.option1) { - return { - __type: SharedUnion__Type.SharedUnionWithOption1, - option1: _returnValue.option1 - }; - } - else { - return { - __type: SharedUnion__Type.SharedUnionWithOption2, - option2: _returnValue.option2 - }; - } - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read data for TUnion"); - } - } -}; -export namespace SharedService { - export const serviceName: string = "SharedService"; - export const annotations: thrift.IThriftAnnotations = {}; - export const methodAnnotations: thrift.IMethodAnnotations = { - getStruct: { - annotations: {}, - fieldAnnotations: {} - }, - getUnion: { - annotations: {}, - fieldAnnotations: {} - } - }; - export const methodNames: Array = ["getStruct", "getUnion"]; - export interface IGetStruct__Args { - key: number; - } - export interface IGetStruct__ArgsArgs { - key: number; - } - export const GetStruct__ArgsCodec: thrift.IStructCodec = { - encode(args: IGetStruct__ArgsArgs, output: thrift.TProtocol): void { - const obj = { - key: args.key - }; - output.writeStructBegin("GetStruct__Args"); - if (obj.key != null) { - output.writeFieldBegin("key", thrift.TType.I32, 1); - output.writeI32(obj.key); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[key] is unset!"); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IGetStruct__Args { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.I32) { - const value_11: number = input.readI32(); - _args.key = value_11; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.key !== undefined) { - return { - key: _args.key - }; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read GetStruct__Args from input"); - } - } - }; - export class GetStruct__Args extends thrift.StructLike implements IGetStruct__Args { - public key: number; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IGetStruct__ArgsArgs) { - super(); - if (args.key != null) { - const value_12: number = args.key; - this.key = value_12; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[key] is unset!"); - } - } - public static read(input: thrift.TProtocol): GetStruct__Args { - return new GetStruct__Args(GetStruct__ArgsCodec.decode(input)); - } - public static write(args: IGetStruct__ArgsArgs, output: thrift.TProtocol): void { - return GetStruct__ArgsCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return GetStruct__ArgsCodec.encode(this, output); - } - } - export interface IGetUnion__Args { - index: number; - } - export interface IGetUnion__ArgsArgs { - index: number; - } - export const GetUnion__ArgsCodec: thrift.IStructCodec = { - encode(args: IGetUnion__ArgsArgs, output: thrift.TProtocol): void { - const obj = { - index: args.index - }; - output.writeStructBegin("GetUnion__Args"); - if (obj.index != null) { - output.writeFieldBegin("index", thrift.TType.I32, 1); - output.writeI32(obj.index); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[index] is unset!"); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IGetUnion__Args { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.I32) { - const value_13: number = input.readI32(); - _args.index = value_13; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.index !== undefined) { - return { - index: _args.index - }; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read GetUnion__Args from input"); - } - } - }; - export class GetUnion__Args extends thrift.StructLike implements IGetUnion__Args { - public index: number; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IGetUnion__ArgsArgs) { - super(); - if (args.index != null) { - const value_14: number = args.index; - this.index = value_14; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[index] is unset!"); - } - } - public static read(input: thrift.TProtocol): GetUnion__Args { - return new GetUnion__Args(GetUnion__ArgsCodec.decode(input)); - } - public static write(args: IGetUnion__ArgsArgs, output: thrift.TProtocol): void { - return GetUnion__ArgsCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return GetUnion__ArgsCodec.encode(this, output); - } - } - export interface IGetStruct__Result { - success?: ISharedStruct; - } - export interface IGetStruct__ResultArgs { - success?: ISharedStructArgs; - } - export const GetStruct__ResultCodec: thrift.IStructCodec = { - encode(args: IGetStruct__ResultArgs, output: thrift.TProtocol): void { - const obj = { - success: args.success - }; - output.writeStructBegin("GetStruct__Result"); - if (obj.success != null) { - output.writeFieldBegin("success", thrift.TType.STRUCT, 0); - SharedStructCodec.encode(obj.success, output); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IGetStruct__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.STRUCT) { - const value_15: ISharedStruct = SharedStructCodec.decode(input); - _args.success = value_15; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - success: _args.success - }; - } - }; - export class GetStruct__Result extends thrift.StructLike implements IGetStruct__Result { - public success?: ISharedStruct; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IGetStruct__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_16: ISharedStruct = new SharedStruct(args.success); - this.success = value_16; - } - } - public static read(input: thrift.TProtocol): GetStruct__Result { - return new GetStruct__Result(GetStruct__ResultCodec.decode(input)); - } - public static write(args: IGetStruct__ResultArgs, output: thrift.TProtocol): void { - return GetStruct__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return GetStruct__ResultCodec.encode(this, output); - } - } - export interface IGetUnion__Result { - success?: SharedUnion; - } - export interface IGetUnion__ResultArgs { - success?: SharedUnionArgs; - } - export const GetUnion__ResultCodec: thrift.IStructCodec = { - encode(args: IGetUnion__ResultArgs, output: thrift.TProtocol): void { - const obj = { - success: args.success - }; - output.writeStructBegin("GetUnion__Result"); - if (obj.success != null) { - output.writeFieldBegin("success", thrift.TType.STRUCT, 0); - SharedUnionCodec.encode(obj.success, output); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IGetUnion__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.STRUCT) { - const value_17: SharedUnion = SharedUnionCodec.decode(input); - _args.success = value_17; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - success: _args.success - }; - } - }; - export class GetUnion__Result extends thrift.StructLike implements IGetUnion__Result { - public success?: SharedUnion; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IGetUnion__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_18: SharedUnion = SharedUnionCodec.create(args.success); - this.success = value_18; - } - } - public static read(input: thrift.TProtocol): GetUnion__Result { - return new GetUnion__Result(GetUnion__ResultCodec.decode(input)); - } - public static write(args: IGetUnion__ResultArgs, output: thrift.TProtocol): void { - return GetUnion__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return GetUnion__ResultCodec.encode(this, output); - } - } - export class Client extends thrift.ThriftClient { - public static readonly serviceName: string = serviceName; - public static readonly annotations: thrift.IThriftAnnotations = annotations; - public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public static readonly methodNames: Array = methodNames; - public readonly _serviceName: string = serviceName; - public readonly _annotations: thrift.IThriftAnnotations = annotations; - public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public readonly _methodNames: Array = methodNames; - public getStruct(key: number, context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("getStruct", thrift.MessageType.CALL, this.incrementRequestId()); - const args: IGetStruct__ArgsArgs = { key }; - GetStruct__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "getStruct") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: IGetStruct__Result = GetStruct__ResultCodec.decode(input); - input.readMessageEnd(); - if (result.success != null) { - return Promise.resolve(result.success); - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "getStruct failed: unknown result")); - } - } - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } - } - catch (err) { - return Promise.reject(err); - } - }); - } - public getUnion(index: number, context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("getUnion", thrift.MessageType.CALL, this.incrementRequestId()); - const args: IGetUnion__ArgsArgs = { index }; - GetUnion__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "getUnion") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: IGetUnion__Result = GetUnion__ResultCodec.decode(input); - input.readMessageEnd(); - if (result.success != null) { - return Promise.resolve(result.success); - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "getUnion failed: unknown result")); - } - } - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } - } - catch (err) { - return Promise.reject(err); - } - }); - } - } - export interface IHandler { - getStruct(key: number, context?: Context): ISharedStructArgs | Promise; - getUnion(index: number, context?: Context): SharedUnionArgs | Promise; - } - export class Processor extends thrift.ThriftProcessor> { - protected readonly _handler: IHandler; - public static readonly serviceName: string = serviceName; - public static readonly annotations: thrift.IThriftAnnotations = annotations; - public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public static readonly methodNames: Array = methodNames; - public readonly _serviceName: string = serviceName; - public readonly _annotations: thrift.IThriftAnnotations = annotations; - public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public readonly _methodNames: Array = methodNames; - constructor(handler: IHandler) { - super(); - this._handler = handler; - } - public process(input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - const metadata: thrift.IThriftMessage = input.readMessageBegin(); - const fieldName: string = metadata.fieldName; - const requestId: number = metadata.requestId; - const methodName: string = "process_" + fieldName; - switch (methodName) { - case "process_getStruct": { - resolve(this.process_getStruct(requestId, input, output, context)); - break; - } - case "process_getUnion": { - resolve(this.process_getUnion(requestId, input, output, context)); - break; - } - default: { - input.skip(thrift.TType.STRUCT); - input.readMessageEnd(); - const errMessage = "Unknown function " + fieldName; - const err = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN_METHOD, errMessage); - output.writeMessageBegin(fieldName, thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(err, output); - output.writeMessageEnd(); - resolve(output.flush()); - break; - } - } - }); - } - public process_getStruct(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { - const args: IGetStruct__Args = GetStruct__ArgsCodec.decode(input); - input.readMessageEnd(); - resolve(this._handler.getStruct(args.key, context)); - } - catch (err) { - reject(err); - } - }).then((data: ISharedStructArgs): Buffer => { - const result: IGetStruct__ResultArgs = { success: data }; - output.writeMessageBegin("getStruct", thrift.MessageType.REPLY, requestId); - GetStruct__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("getStruct", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } - public process_getUnion(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { - const args: IGetUnion__Args = GetUnion__ArgsCodec.decode(input); - input.readMessageEnd(); - resolve(this._handler.getUnion(args.index, context)); - } - catch (err) { - reject(err); - } - }).then((data: SharedUnionArgs): Buffer => { - const result: IGetUnion__ResultArgs = { success: data }; - output.writeMessageBegin("getUnion", thrift.MessageType.REPLY, requestId); - GetUnion__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("getUnion", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } - } -} diff --git a/src/tests/unit/fixtures/resolver/import-identifiers-types.solution.json b/src/tests/unit/fixtures/resolver/import-identifiers-types.solution.json deleted file mode 100644 index c85e2648..00000000 --- a/src/tests/unit/fixtures/resolver/import-identifiers-types.solution.json +++ /dev/null @@ -1,787 +0,0 @@ -{ - "name": "test", - "path": "", - "source": "", - "namespace": { - "scope": "", - "name": "", - "path": "" - }, - "includes": { - "exception": { - "file": { - "name": "exception", - "path": "", - "source": "", - "namespace": { - "scope": "", - "name": "", - "path": "" - }, - "includes": {}, - "identifiers": { - "MyException": { - "name": "MyException", - "resolvedName": "MyException", - "definition": { - "type": "ExceptionDefinition", - "name": { - "type": "Identifier", - "value": "MyException", - "loc": { - "start": { - "line": 2, - "column": 17, - "index": 17 - }, - "end": { - "line": 2, - "column": 28, - "index": 28 - } - } - }, - "fields": [ - { - "type": "FieldDefinition", - "name": { - "type": "Identifier", - "value": "message", - "loc": { - "start": { - "line": 3, - "column": 28, - "index": 58 - }, - "end": { - "line": 3, - "column": 35, - "index": 65 - } - } - }, - "fieldID": { - "type": "FieldID", - "value": 1, - "loc": { - "start": { - "line": 3, - "column": 9, - "index": 39 - }, - "end": { - "line": 3, - "column": 11, - "index": 41 - } - } - }, - "fieldType": { - "type": "StringKeyword", - "loc": { - "start": { - "line": 3, - "column": 21, - "index": 51 - }, - "end": { - "line": 3, - "column": 27, - "index": 57 - } - } - }, - "requiredness": "required", - "defaultValue": null, - "comments": [], - "loc": { - "start": { - "line": 3, - "column": 9, - "index": 39 - }, - "end": { - "line": 3, - "column": 35, - "index": 65 - } - } - } - ], - "comments": [], - "loc": { - "start": { - "line": 2, - "column": 7, - "index": 7 - }, - "end": { - "line": 4, - "column": 8, - "index": 73 - } - } - } - } - }, - "body": [ - { - "type": "ExceptionDefinition", - "name": { - "type": "Identifier", - "value": "MyException", - "loc": { - "start": { - "line": 2, - "column": 17, - "index": 17 - }, - "end": { - "line": 2, - "column": 28, - "index": 28 - } - } - }, - "fields": [ - { - "type": "FieldDefinition", - "name": { - "type": "Identifier", - "value": "message", - "loc": { - "start": { - "line": 3, - "column": 28, - "index": 58 - }, - "end": { - "line": 3, - "column": 35, - "index": 65 - } - } - }, - "fieldID": { - "type": "FieldID", - "value": 1, - "loc": { - "start": { - "line": 3, - "column": 9, - "index": 39 - }, - "end": { - "line": 3, - "column": 11, - "index": 41 - } - } - }, - "fieldType": { - "type": "StringKeyword", - "loc": { - "start": { - "line": 3, - "column": 21, - "index": 51 - }, - "end": { - "line": 3, - "column": 27, - "index": 57 - } - } - }, - "requiredness": "required", - "defaultValue": null, - "comments": [], - "loc": { - "start": { - "line": 3, - "column": 9, - "index": 39 - }, - "end": { - "line": 3, - "column": 35, - "index": 65 - } - } - } - ], - "comments": [], - "loc": { - "start": { - "line": 2, - "column": 7, - "index": 7 - }, - "end": { - "line": 4, - "column": 8, - "index": 73 - } - } - } - ], - "errors": [] - }, - "identifiers": [ - { - "name": "MyException", - "resolvedName": "exception$MyException", - "definition": { - "type": "ExceptionDefinition", - "name": { - "type": "Identifier", - "value": "MyException", - "loc": { - "start": { - "line": 2, - "column": 17, - "index": 17 - }, - "end": { - "line": 2, - "column": 28, - "index": 28 - } - } - }, - "fields": [ - { - "type": "FieldDefinition", - "name": { - "type": "Identifier", - "value": "message", - "loc": { - "start": { - "line": 3, - "column": 28, - "index": 58 - }, - "end": { - "line": 3, - "column": 35, - "index": 65 - } - } - }, - "fieldID": { - "type": "FieldID", - "value": 1, - "loc": { - "start": { - "line": 3, - "column": 9, - "index": 39 - }, - "end": { - "line": 3, - "column": 11, - "index": 41 - } - } - }, - "fieldType": { - "type": "StringKeyword", - "loc": { - "start": { - "line": 3, - "column": 21, - "index": 51 - }, - "end": { - "line": 3, - "column": 27, - "index": 57 - } - } - }, - "requiredness": "required", - "defaultValue": null, - "comments": [], - "loc": { - "start": { - "line": 3, - "column": 9, - "index": 39 - }, - "end": { - "line": 3, - "column": 35, - "index": 65 - } - } - } - ], - "comments": [], - "loc": { - "start": { - "line": 2, - "column": 7, - "index": 7 - }, - "end": { - "line": 4, - "column": 8, - "index": 73 - } - } - } - } - ] - } - }, - "identifiers": { - "exception$MyException": { - "name": "MyException", - "resolvedName": "exception$MyException", - "definition": { - "type": "ExceptionDefinition", - "name": { - "type": "Identifier", - "value": "MyException", - "loc": { - "start": { - "line": 2, - "column": 17, - "index": 17 - }, - "end": { - "line": 2, - "column": 28, - "index": 28 - } - } - }, - "fields": [ - { - "type": "FieldDefinition", - "name": { - "type": "Identifier", - "value": "message", - "loc": { - "start": { - "line": 3, - "column": 28, - "index": 58 - }, - "end": { - "line": 3, - "column": 35, - "index": 65 - } - } - }, - "fieldID": { - "type": "FieldID", - "value": 1, - "loc": { - "start": { - "line": 3, - "column": 9, - "index": 39 - }, - "end": { - "line": 3, - "column": 11, - "index": 41 - } - } - }, - "fieldType": { - "type": "StringKeyword", - "loc": { - "start": { - "line": 3, - "column": 21, - "index": 51 - }, - "end": { - "line": 3, - "column": 27, - "index": 57 - } - } - }, - "requiredness": "required", - "defaultValue": null, - "comments": [], - "loc": { - "start": { - "line": 3, - "column": 9, - "index": 39 - }, - "end": { - "line": 3, - "column": 35, - "index": 65 - } - } - } - ], - "comments": [], - "loc": { - "start": { - "line": 2, - "column": 7, - "index": 7 - }, - "end": { - "line": 4, - "column": 8, - "index": 73 - } - } - } - }, - "MyService": { - "name": "MyService", - "resolvedName": "MyService", - "definition": { - "type": "ServiceDefinition", - "name": { - "type": "Identifier", - "value": "MyService", - "loc": { - "start": { - "line": 4, - "column": 15, - "index": 49 - }, - "end": { - "line": 4, - "column": 24, - "index": 58 - } - } - }, - "extends": null, - "functions": [ - { - "type": "FunctionDefinition", - "name": { - "type": "Identifier", - "value": "ping", - "loc": { - "start": { - "line": 5, - "column": 14, - "index": 74 - }, - "end": { - "line": 5, - "column": 18, - "index": 78 - } - } - }, - "returnType": { - "type": "VoidKeyword", - "loc": { - "start": { - "line": 5, - "column": 9, - "index": 69 - }, - "end": { - "line": 5, - "column": 13, - "index": 73 - } - } - }, - "fields": [], - "throws": [ - { - "type": "FieldDefinition", - "name": { - "type": "Identifier", - "value": "exp", - "loc": { - "start": { - "line": 5, - "column": 54, - "index": 114 - }, - "end": { - "line": 5, - "column": 57, - "index": 117 - } - } - }, - "fieldID": { - "type": "FieldID", - "value": 1, - "loc": { - "start": { - "line": 5, - "column": 29, - "index": 89 - }, - "end": { - "line": 5, - "column": 31, - "index": 91 - } - } - }, - "fieldType": { - "type": "Identifier", - "value": "exception$MyException", - "loc": { - "start": { - "line": 5, - "column": 32, - "index": 92 - }, - "end": { - "line": 5, - "column": 53, - "index": 113 - } - } - }, - "requiredness": null, - "defaultValue": null, - "comments": [], - "loc": { - "start": { - "line": 5, - "column": 29, - "index": 89 - }, - "end": { - "line": 5, - "column": 57, - "index": 117 - } - } - } - ], - "comments": [], - "oneway": false, - "modifiers": [], - "loc": { - "start": { - "line": 5, - "column": 9, - "index": 69 - }, - "end": { - "line": 5, - "column": 58, - "index": 118 - } - } - } - ], - "comments": [], - "loc": { - "start": { - "line": 4, - "column": 7, - "index": 41 - }, - "end": { - "line": 6, - "column": 8, - "index": 126 - } - } - } - } - }, - "body": [ - { - "type": "IncludeDefinition", - "path": { - "type": "StringLiteral", - "value": "exception.thrift", - "loc": { - "start": { - "line": 2, - "column": 15, - "index": 15 - }, - "end": { - "line": 2, - "column": 33, - "index": 33 - } - } - }, - "comments": [], - "loc": { - "start": { - "line": 2, - "column": 7, - "index": 7 - }, - "end": { - "line": 2, - "column": 33, - "index": 33 - } - } - }, - { - "type": "ServiceDefinition", - "name": { - "type": "Identifier", - "value": "MyService", - "loc": { - "start": { - "line": 4, - "column": 15, - "index": 49 - }, - "end": { - "line": 4, - "column": 24, - "index": 58 - } - } - }, - "extends": null, - "functions": [ - { - "type": "FunctionDefinition", - "name": { - "type": "Identifier", - "value": "ping", - "loc": { - "start": { - "line": 5, - "column": 14, - "index": 74 - }, - "end": { - "line": 5, - "column": 18, - "index": 78 - } - } - }, - "returnType": { - "type": "VoidKeyword", - "loc": { - "start": { - "line": 5, - "column": 9, - "index": 69 - }, - "end": { - "line": 5, - "column": 13, - "index": 73 - } - } - }, - "fields": [], - "throws": [ - { - "type": "FieldDefinition", - "name": { - "type": "Identifier", - "value": "exp", - "loc": { - "start": { - "line": 5, - "column": 54, - "index": 114 - }, - "end": { - "line": 5, - "column": 57, - "index": 117 - } - } - }, - "fieldID": { - "type": "FieldID", - "value": 1, - "loc": { - "start": { - "line": 5, - "column": 29, - "index": 89 - }, - "end": { - "line": 5, - "column": 31, - "index": 91 - } - } - }, - "fieldType": { - "type": "Identifier", - "value": "exception$MyException", - "loc": { - "start": { - "line": 5, - "column": 32, - "index": 92 - }, - "end": { - "line": 5, - "column": 53, - "index": 113 - } - } - }, - "requiredness": null, - "defaultValue": null, - "comments": [], - "loc": { - "start": { - "line": 5, - "column": 29, - "index": 89 - }, - "end": { - "line": 5, - "column": 57, - "index": 117 - } - } - } - ], - "comments": [], - "oneway": false, - "modifiers": [], - "loc": { - "start": { - "line": 5, - "column": 9, - "index": 69 - }, - "end": { - "line": 5, - "column": 58, - "index": 118 - } - } - } - ], - "comments": [], - "loc": { - "start": { - "line": 4, - "column": 7, - "index": 41 - }, - "end": { - "line": 6, - "column": 8, - "index": 126 - } - } - } - ], - "errors": [] -} diff --git a/src/tests/unit/fixtures/resolver/import-identifiers-values.solution.json b/src/tests/unit/fixtures/resolver/import-identifiers-values.solution.json deleted file mode 100644 index a726cd5e..00000000 --- a/src/tests/unit/fixtures/resolver/import-identifiers-values.solution.json +++ /dev/null @@ -1,715 +0,0 @@ -{ - "name": "test", - "path": "", - "source": "", - "namespace": { - "scope": "", - "name": "", - "path": "" - }, - "includes": { - "exception": { - "file": { - "name": "exception", - "path": "", - "source": "", - "namespace": { - "scope": "", - "name": "", - "path": "" - }, - "includes": {}, - "identifiers": { - "Status": { - "name": "Status", - "resolvedName": "Status", - "definition": { - "type": "EnumDefinition", - "name": { - "type": "Identifier", - "value": "Status", - "loc": { - "start": { - "line": 2, - "column": 12, - "index": 12 - }, - "end": { - "line": 2, - "column": 18, - "index": 18 - } - } - }, - "members": [ - { - "type": "EnumMember", - "name": { - "type": "Identifier", - "value": "SUCCESS", - "loc": { - "start": { - "line": 3, - "column": 9, - "index": 29 - }, - "end": { - "line": 3, - "column": 16, - "index": 36 - } - } - }, - "initializer": null, - "comments": [], - "loc": { - "start": { - "line": 3, - "column": 9, - "index": 29 - }, - "end": { - "line": 3, - "column": 16, - "index": 36 - } - } - }, - { - "type": "EnumMember", - "name": { - "type": "Identifier", - "value": "FAILURE", - "loc": { - "start": { - "line": 4, - "column": 9, - "index": 46 - }, - "end": { - "line": 4, - "column": 16, - "index": 53 - } - } - }, - "initializer": null, - "comments": [], - "loc": { - "start": { - "line": 4, - "column": 9, - "index": 46 - }, - "end": { - "line": 4, - "column": 16, - "index": 53 - } - } - } - ], - "comments": [], - "loc": { - "start": { - "line": 2, - "column": 7, - "index": 7 - }, - "end": { - "line": 5, - "column": 8, - "index": 61 - } - } - } - } - }, - "body": [ - { - "type": "EnumDefinition", - "name": { - "type": "Identifier", - "value": "Status", - "loc": { - "start": { - "line": 2, - "column": 12, - "index": 12 - }, - "end": { - "line": 2, - "column": 18, - "index": 18 - } - } - }, - "members": [ - { - "type": "EnumMember", - "name": { - "type": "Identifier", - "value": "SUCCESS", - "loc": { - "start": { - "line": 3, - "column": 9, - "index": 29 - }, - "end": { - "line": 3, - "column": 16, - "index": 36 - } - } - }, - "initializer": null, - "comments": [], - "loc": { - "start": { - "line": 3, - "column": 9, - "index": 29 - }, - "end": { - "line": 3, - "column": 16, - "index": 36 - } - } - }, - { - "type": "EnumMember", - "name": { - "type": "Identifier", - "value": "FAILURE", - "loc": { - "start": { - "line": 4, - "column": 9, - "index": 46 - }, - "end": { - "line": 4, - "column": 16, - "index": 53 - } - } - }, - "initializer": null, - "comments": [], - "loc": { - "start": { - "line": 4, - "column": 9, - "index": 46 - }, - "end": { - "line": 4, - "column": 16, - "index": 53 - } - } - } - ], - "comments": [], - "loc": { - "start": { - "line": 2, - "column": 7, - "index": 7 - }, - "end": { - "line": 5, - "column": 8, - "index": 61 - } - } - } - ], - "errors": [] - }, - "identifiers": [ - { - "name": "Status", - "resolvedName": "exception$Status", - "definition": { - "type": "EnumDefinition", - "name": { - "type": "Identifier", - "value": "Status", - "loc": { - "start": { - "line": 2, - "column": 12, - "index": 12 - }, - "end": { - "line": 2, - "column": 18, - "index": 18 - } - } - }, - "members": [ - { - "type": "EnumMember", - "name": { - "type": "Identifier", - "value": "SUCCESS", - "loc": { - "start": { - "line": 3, - "column": 9, - "index": 29 - }, - "end": { - "line": 3, - "column": 16, - "index": 36 - } - } - }, - "initializer": null, - "comments": [], - "loc": { - "start": { - "line": 3, - "column": 9, - "index": 29 - }, - "end": { - "line": 3, - "column": 16, - "index": 36 - } - } - }, - { - "type": "EnumMember", - "name": { - "type": "Identifier", - "value": "FAILURE", - "loc": { - "start": { - "line": 4, - "column": 9, - "index": 46 - }, - "end": { - "line": 4, - "column": 16, - "index": 53 - } - } - }, - "initializer": null, - "comments": [], - "loc": { - "start": { - "line": 4, - "column": 9, - "index": 46 - }, - "end": { - "line": 4, - "column": 16, - "index": 53 - } - } - } - ], - "comments": [], - "loc": { - "start": { - "line": 2, - "column": 7, - "index": 7 - }, - "end": { - "line": 5, - "column": 8, - "index": 61 - } - } - } - } - ] - } - }, - "identifiers": { - "exception$Status": { - "name": "Status", - "resolvedName": "exception$Status", - "definition": { - "type": "EnumDefinition", - "name": { - "type": "Identifier", - "value": "Status", - "loc": { - "start": { - "line": 2, - "column": 12, - "index": 12 - }, - "end": { - "line": 2, - "column": 18, - "index": 18 - } - } - }, - "members": [ - { - "type": "EnumMember", - "name": { - "type": "Identifier", - "value": "SUCCESS", - "loc": { - "start": { - "line": 3, - "column": 9, - "index": 29 - }, - "end": { - "line": 3, - "column": 16, - "index": 36 - } - } - }, - "initializer": null, - "comments": [], - "loc": { - "start": { - "line": 3, - "column": 9, - "index": 29 - }, - "end": { - "line": 3, - "column": 16, - "index": 36 - } - } - }, - { - "type": "EnumMember", - "name": { - "type": "Identifier", - "value": "FAILURE", - "loc": { - "start": { - "line": 4, - "column": 9, - "index": 46 - }, - "end": { - "line": 4, - "column": 16, - "index": 53 - } - } - }, - "initializer": null, - "comments": [], - "loc": { - "start": { - "line": 4, - "column": 9, - "index": 46 - }, - "end": { - "line": 4, - "column": 16, - "index": 53 - } - } - } - ], - "comments": [], - "loc": { - "start": { - "line": 2, - "column": 7, - "index": 7 - }, - "end": { - "line": 5, - "column": 8, - "index": 61 - } - } - } - }, - "MyStruct": { - "name": "MyStruct", - "resolvedName": "MyStruct", - "definition": { - "type": "StructDefinition", - "name": { - "type": "Identifier", - "value": "MyStruct", - "loc": { - "start": { - "line": 4, - "column": 14, - "index": 48 - }, - "end": { - "line": 4, - "column": 22, - "index": 56 - } - } - }, - "fields": [ - { - "type": "FieldDefinition", - "name": { - "type": "Identifier", - "value": "status", - "loc": { - "start": { - "line": 5, - "column": 29, - "index": 87 - }, - "end": { - "line": 5, - "column": 35, - "index": 93 - } - } - }, - "fieldID": { - "type": "FieldID", - "value": 1, - "loc": { - "start": { - "line": 5, - "column": 9, - "index": 67 - }, - "end": { - "line": 5, - "column": 11, - "index": 69 - } - } - }, - "fieldType": { - "type": "Identifier", - "value": "exception$Status", - "loc": { - "start": { - "line": 5, - "column": 12, - "index": 70 - }, - "end": { - "line": 5, - "column": 28, - "index": 86 - } - } - }, - "requiredness": null, - "defaultValue": { - "type": "Identifier", - "value": "exception$Status.SUCCESS", - "loc": { - "start": { - "line": 5, - "column": 38, - "index": 96 - }, - "end": { - "line": 5, - "column": 62, - "index": 120 - } - } - }, - "comments": [], - "loc": { - "start": { - "line": 5, - "column": 9, - "index": 67 - }, - "end": { - "line": 5, - "column": 62, - "index": 120 - } - } - } - ], - "comments": [], - "loc": { - "start": { - "line": 4, - "column": 7, - "index": 41 - }, - "end": { - "line": 6, - "column": 8, - "index": 128 - } - } - } - } - }, - "body": [ - { - "type": "IncludeDefinition", - "path": { - "type": "StringLiteral", - "value": "exception.thrift", - "loc": { - "start": { - "line": 2, - "column": 15, - "index": 15 - }, - "end": { - "line": 2, - "column": 33, - "index": 33 - } - } - }, - "comments": [], - "loc": { - "start": { - "line": 2, - "column": 7, - "index": 7 - }, - "end": { - "line": 2, - "column": 33, - "index": 33 - } - } - }, - { - "type": "StructDefinition", - "name": { - "type": "Identifier", - "value": "MyStruct", - "loc": { - "start": { - "line": 4, - "column": 14, - "index": 48 - }, - "end": { - "line": 4, - "column": 22, - "index": 56 - } - } - }, - "fields": [ - { - "type": "FieldDefinition", - "name": { - "type": "Identifier", - "value": "status", - "loc": { - "start": { - "line": 5, - "column": 29, - "index": 87 - }, - "end": { - "line": 5, - "column": 35, - "index": 93 - } - } - }, - "fieldID": { - "type": "FieldID", - "value": 1, - "loc": { - "start": { - "line": 5, - "column": 9, - "index": 67 - }, - "end": { - "line": 5, - "column": 11, - "index": 69 - } - } - }, - "fieldType": { - "type": "Identifier", - "value": "exception$Status", - "loc": { - "start": { - "line": 5, - "column": 12, - "index": 70 - }, - "end": { - "line": 5, - "column": 28, - "index": 86 - } - } - }, - "requiredness": null, - "defaultValue": { - "type": "Identifier", - "value": "exception$Status.SUCCESS", - "loc": { - "start": { - "line": 5, - "column": 38, - "index": 96 - }, - "end": { - "line": 5, - "column": 62, - "index": 120 - } - } - }, - "comments": [], - "loc": { - "start": { - "line": 5, - "column": 9, - "index": 67 - }, - "end": { - "line": 5, - "column": 62, - "index": 120 - } - } - } - ], - "comments": [], - "loc": { - "start": { - "line": 4, - "column": 7, - "index": 41 - }, - "end": { - "line": 6, - "column": 8, - "index": 128 - } - } - } - ], - "errors": [] -} diff --git a/src/tests/unit/fixtures/resolver/imported-id-types.solution.json b/src/tests/unit/fixtures/resolver/imported-id-types.solution.json deleted file mode 100644 index af4e2f0e..00000000 --- a/src/tests/unit/fixtures/resolver/imported-id-types.solution.json +++ /dev/null @@ -1,791 +0,0 @@ -{ - "name": "test", - "path": "", - "source": "", - "namespace": { - "scope": "", - "name": "", - "path": "" - }, - "includes": { - "exception": { - "file": { - "name": "exception", - "path": "", - "source": "", - "namespace": { - "scope": "", - "name": "", - "path": "" - }, - "includes": {}, - "identifiers": { - "MyException": { - "name": "MyException", - "pathName": "", - "resolvedName": "MyException", - "definition": { - "type": "ExceptionDefinition", - "name": { - "type": "Identifier", - "value": "MyException", - "loc": { - "start": { - "line": 2, - "column": 23, - "index": 23 - }, - "end": { - "line": 2, - "column": 34, - "index": 34 - } - } - }, - "fields": [ - { - "type": "FieldDefinition", - "name": { - "type": "Identifier", - "value": "message", - "loc": { - "start": { - "line": 3, - "column": 36, - "index": 72 - }, - "end": { - "line": 3, - "column": 43, - "index": 79 - } - } - }, - "fieldID": { - "type": "FieldID", - "value": 1, - "loc": { - "start": { - "line": 3, - "column": 17, - "index": 53 - }, - "end": { - "line": 3, - "column": 19, - "index": 55 - } - } - }, - "fieldType": { - "type": "StringKeyword", - "loc": { - "start": { - "line": 3, - "column": 29, - "index": 65 - }, - "end": { - "line": 3, - "column": 35, - "index": 71 - } - } - }, - "requiredness": "required", - "defaultValue": null, - "comments": [], - "loc": { - "start": { - "line": 3, - "column": 17, - "index": 53 - }, - "end": { - "line": 3, - "column": 43, - "index": 79 - } - } - } - ], - "comments": [], - "loc": { - "start": { - "line": 2, - "column": 13, - "index": 13 - }, - "end": { - "line": 4, - "column": 14, - "index": 93 - } - } - } - } - }, - "body": [ - { - "type": "ExceptionDefinition", - "name": { - "type": "Identifier", - "value": "MyException", - "loc": { - "start": { - "line": 2, - "column": 23, - "index": 23 - }, - "end": { - "line": 2, - "column": 34, - "index": 34 - } - } - }, - "fields": [ - { - "type": "FieldDefinition", - "name": { - "type": "Identifier", - "value": "message", - "loc": { - "start": { - "line": 3, - "column": 36, - "index": 72 - }, - "end": { - "line": 3, - "column": 43, - "index": 79 - } - } - }, - "fieldID": { - "type": "FieldID", - "value": 1, - "loc": { - "start": { - "line": 3, - "column": 17, - "index": 53 - }, - "end": { - "line": 3, - "column": 19, - "index": 55 - } - } - }, - "fieldType": { - "type": "StringKeyword", - "loc": { - "start": { - "line": 3, - "column": 29, - "index": 65 - }, - "end": { - "line": 3, - "column": 35, - "index": 71 - } - } - }, - "requiredness": "required", - "defaultValue": null, - "comments": [], - "loc": { - "start": { - "line": 3, - "column": 17, - "index": 53 - }, - "end": { - "line": 3, - "column": 43, - "index": 79 - } - } - } - ], - "comments": [], - "loc": { - "start": { - "line": 2, - "column": 13, - "index": 13 - }, - "end": { - "line": 4, - "column": 14, - "index": 93 - } - } - } - ], - "errors": [] - }, - "identifiers": [ - { - "name": "MyException", - "pathName": "exception", - "resolvedName": "exception.MyException", - "definition": { - "type": "ExceptionDefinition", - "name": { - "type": "Identifier", - "value": "MyException", - "loc": { - "start": { - "line": 2, - "column": 23, - "index": 23 - }, - "end": { - "line": 2, - "column": 34, - "index": 34 - } - } - }, - "fields": [ - { - "type": "FieldDefinition", - "name": { - "type": "Identifier", - "value": "message", - "loc": { - "start": { - "line": 3, - "column": 36, - "index": 72 - }, - "end": { - "line": 3, - "column": 43, - "index": 79 - } - } - }, - "fieldID": { - "type": "FieldID", - "value": 1, - "loc": { - "start": { - "line": 3, - "column": 17, - "index": 53 - }, - "end": { - "line": 3, - "column": 19, - "index": 55 - } - } - }, - "fieldType": { - "type": "StringKeyword", - "loc": { - "start": { - "line": 3, - "column": 29, - "index": 65 - }, - "end": { - "line": 3, - "column": 35, - "index": 71 - } - } - }, - "requiredness": "required", - "defaultValue": null, - "comments": [], - "loc": { - "start": { - "line": 3, - "column": 17, - "index": 53 - }, - "end": { - "line": 3, - "column": 43, - "index": 79 - } - } - } - ], - "comments": [], - "loc": { - "start": { - "line": 2, - "column": 13, - "index": 13 - }, - "end": { - "line": 4, - "column": 14, - "index": 93 - } - } - } - } - ] - } - }, - "identifiers": { - "exception.MyException": { - "name": "MyException", - "pathName": "exception", - "resolvedName": "exception.MyException", - "definition": { - "type": "ExceptionDefinition", - "name": { - "type": "Identifier", - "value": "MyException", - "loc": { - "start": { - "line": 2, - "column": 23, - "index": 23 - }, - "end": { - "line": 2, - "column": 34, - "index": 34 - } - } - }, - "fields": [ - { - "type": "FieldDefinition", - "name": { - "type": "Identifier", - "value": "message", - "loc": { - "start": { - "line": 3, - "column": 36, - "index": 72 - }, - "end": { - "line": 3, - "column": 43, - "index": 79 - } - } - }, - "fieldID": { - "type": "FieldID", - "value": 1, - "loc": { - "start": { - "line": 3, - "column": 17, - "index": 53 - }, - "end": { - "line": 3, - "column": 19, - "index": 55 - } - } - }, - "fieldType": { - "type": "StringKeyword", - "loc": { - "start": { - "line": 3, - "column": 29, - "index": 65 - }, - "end": { - "line": 3, - "column": 35, - "index": 71 - } - } - }, - "requiredness": "required", - "defaultValue": null, - "comments": [], - "loc": { - "start": { - "line": 3, - "column": 17, - "index": 53 - }, - "end": { - "line": 3, - "column": 43, - "index": 79 - } - } - } - ], - "comments": [], - "loc": { - "start": { - "line": 2, - "column": 13, - "index": 13 - }, - "end": { - "line": 4, - "column": 14, - "index": 93 - } - } - } - }, - "MyService": { - "name": "MyService", - "pathName": "", - "resolvedName": "MyService", - "definition": { - "type": "ServiceDefinition", - "name": { - "type": "Identifier", - "value": "MyService", - "loc": { - "start": { - "line": 4, - "column": 21, - "index": 61 - }, - "end": { - "line": 4, - "column": 30, - "index": 70 - } - } - }, - "extends": null, - "functions": [ - { - "type": "FunctionDefinition", - "name": { - "type": "Identifier", - "value": "ping", - "loc": { - "start": { - "line": 5, - "column": 22, - "index": 94 - }, - "end": { - "line": 5, - "column": 26, - "index": 98 - } - } - }, - "returnType": { - "type": "VoidKeyword", - "loc": { - "start": { - "line": 5, - "column": 17, - "index": 89 - }, - "end": { - "line": 5, - "column": 21, - "index": 93 - } - } - }, - "fields": [], - "throws": [ - { - "type": "FieldDefinition", - "name": { - "type": "Identifier", - "value": "exp", - "loc": { - "start": { - "line": 5, - "column": 62, - "index": 134 - }, - "end": { - "line": 5, - "column": 65, - "index": 137 - } - } - }, - "fieldID": { - "type": "FieldID", - "value": 1, - "loc": { - "start": { - "line": 5, - "column": 37, - "index": 109 - }, - "end": { - "line": 5, - "column": 39, - "index": 111 - } - } - }, - "fieldType": { - "type": "Identifier", - "value": "exception.MyException", - "loc": { - "start": { - "line": 5, - "column": 40, - "index": 112 - }, - "end": { - "line": 5, - "column": 61, - "index": 133 - } - } - }, - "requiredness": null, - "defaultValue": null, - "comments": [], - "loc": { - "start": { - "line": 5, - "column": 37, - "index": 109 - }, - "end": { - "line": 5, - "column": 65, - "index": 137 - } - } - } - ], - "comments": [], - "oneway": false, - "modifiers": [], - "loc": { - "start": { - "line": 5, - "column": 17, - "index": 89 - }, - "end": { - "line": 5, - "column": 66, - "index": 138 - } - } - } - ], - "comments": [], - "loc": { - "start": { - "line": 4, - "column": 13, - "index": 53 - }, - "end": { - "line": 6, - "column": 14, - "index": 152 - } - } - } - } - }, - "body": [ - { - "type": "IncludeDefinition", - "path": { - "type": "StringLiteral", - "value": "exception.thrift", - "loc": { - "start": { - "line": 2, - "column": 21, - "index": 21 - }, - "end": { - "line": 2, - "column": 39, - "index": 39 - } - } - }, - "comments": [], - "loc": { - "start": { - "line": 2, - "column": 13, - "index": 13 - }, - "end": { - "line": 2, - "column": 39, - "index": 39 - } - } - }, - { - "type": "ServiceDefinition", - "name": { - "type": "Identifier", - "value": "MyService", - "loc": { - "start": { - "line": 4, - "column": 21, - "index": 61 - }, - "end": { - "line": 4, - "column": 30, - "index": 70 - } - } - }, - "extends": null, - "functions": [ - { - "type": "FunctionDefinition", - "name": { - "type": "Identifier", - "value": "ping", - "loc": { - "start": { - "line": 5, - "column": 22, - "index": 94 - }, - "end": { - "line": 5, - "column": 26, - "index": 98 - } - } - }, - "returnType": { - "type": "VoidKeyword", - "loc": { - "start": { - "line": 5, - "column": 17, - "index": 89 - }, - "end": { - "line": 5, - "column": 21, - "index": 93 - } - } - }, - "fields": [], - "throws": [ - { - "type": "FieldDefinition", - "name": { - "type": "Identifier", - "value": "exp", - "loc": { - "start": { - "line": 5, - "column": 62, - "index": 134 - }, - "end": { - "line": 5, - "column": 65, - "index": 137 - } - } - }, - "fieldID": { - "type": "FieldID", - "value": 1, - "loc": { - "start": { - "line": 5, - "column": 37, - "index": 109 - }, - "end": { - "line": 5, - "column": 39, - "index": 111 - } - } - }, - "fieldType": { - "type": "Identifier", - "value": "exception.MyException", - "loc": { - "start": { - "line": 5, - "column": 40, - "index": 112 - }, - "end": { - "line": 5, - "column": 61, - "index": 133 - } - } - }, - "requiredness": null, - "defaultValue": null, - "comments": [], - "loc": { - "start": { - "line": 5, - "column": 37, - "index": 109 - }, - "end": { - "line": 5, - "column": 65, - "index": 137 - } - } - } - ], - "comments": [], - "oneway": false, - "modifiers": [], - "loc": { - "start": { - "line": 5, - "column": 17, - "index": 89 - }, - "end": { - "line": 5, - "column": 66, - "index": 138 - } - } - } - ], - "comments": [], - "loc": { - "start": { - "line": 4, - "column": 13, - "index": 53 - }, - "end": { - "line": 6, - "column": 14, - "index": 152 - } - } - } - ], - "errors": [] -} diff --git a/src/tests/unit/fixtures/resolver/imported-id-values.solution.json b/src/tests/unit/fixtures/resolver/imported-id-values.solution.json deleted file mode 100644 index d0ca6433..00000000 --- a/src/tests/unit/fixtures/resolver/imported-id-values.solution.json +++ /dev/null @@ -1,719 +0,0 @@ -{ - "name": "test", - "path": "", - "source": "", - "namespace": { - "scope": "", - "name": "", - "path": "" - }, - "includes": { - "exception": { - "file": { - "name": "exception", - "path": "", - "source": "", - "namespace": { - "scope": "", - "name": "", - "path": "" - }, - "includes": {}, - "identifiers": { - "Status": { - "name": "Status", - "pathName": "", - "resolvedName": "Status", - "definition": { - "type": "EnumDefinition", - "name": { - "type": "Identifier", - "value": "Status", - "loc": { - "start": { - "line": 2, - "column": 18, - "index": 18 - }, - "end": { - "line": 2, - "column": 24, - "index": 24 - } - } - }, - "members": [ - { - "type": "EnumMember", - "name": { - "type": "Identifier", - "value": "SUCCESS", - "loc": { - "start": { - "line": 3, - "column": 17, - "index": 43 - }, - "end": { - "line": 3, - "column": 24, - "index": 50 - } - } - }, - "initializer": null, - "comments": [], - "loc": { - "start": { - "line": 3, - "column": 17, - "index": 43 - }, - "end": { - "line": 3, - "column": 24, - "index": 50 - } - } - }, - { - "type": "EnumMember", - "name": { - "type": "Identifier", - "value": "FAILURE", - "loc": { - "start": { - "line": 4, - "column": 17, - "index": 68 - }, - "end": { - "line": 4, - "column": 24, - "index": 75 - } - } - }, - "initializer": null, - "comments": [], - "loc": { - "start": { - "line": 4, - "column": 17, - "index": 68 - }, - "end": { - "line": 4, - "column": 24, - "index": 75 - } - } - } - ], - "comments": [], - "loc": { - "start": { - "line": 2, - "column": 13, - "index": 13 - }, - "end": { - "line": 5, - "column": 14, - "index": 89 - } - } - } - } - }, - "body": [ - { - "type": "EnumDefinition", - "name": { - "type": "Identifier", - "value": "Status", - "loc": { - "start": { - "line": 2, - "column": 18, - "index": 18 - }, - "end": { - "line": 2, - "column": 24, - "index": 24 - } - } - }, - "members": [ - { - "type": "EnumMember", - "name": { - "type": "Identifier", - "value": "SUCCESS", - "loc": { - "start": { - "line": 3, - "column": 17, - "index": 43 - }, - "end": { - "line": 3, - "column": 24, - "index": 50 - } - } - }, - "initializer": null, - "comments": [], - "loc": { - "start": { - "line": 3, - "column": 17, - "index": 43 - }, - "end": { - "line": 3, - "column": 24, - "index": 50 - } - } - }, - { - "type": "EnumMember", - "name": { - "type": "Identifier", - "value": "FAILURE", - "loc": { - "start": { - "line": 4, - "column": 17, - "index": 68 - }, - "end": { - "line": 4, - "column": 24, - "index": 75 - } - } - }, - "initializer": null, - "comments": [], - "loc": { - "start": { - "line": 4, - "column": 17, - "index": 68 - }, - "end": { - "line": 4, - "column": 24, - "index": 75 - } - } - } - ], - "comments": [], - "loc": { - "start": { - "line": 2, - "column": 13, - "index": 13 - }, - "end": { - "line": 5, - "column": 14, - "index": 89 - } - } - } - ], - "errors": [] - }, - "identifiers": [ - { - "name": "Status", - "pathName": "exception", - "resolvedName": "exception.Status", - "definition": { - "type": "EnumDefinition", - "name": { - "type": "Identifier", - "value": "Status", - "loc": { - "start": { - "line": 2, - "column": 18, - "index": 18 - }, - "end": { - "line": 2, - "column": 24, - "index": 24 - } - } - }, - "members": [ - { - "type": "EnumMember", - "name": { - "type": "Identifier", - "value": "SUCCESS", - "loc": { - "start": { - "line": 3, - "column": 17, - "index": 43 - }, - "end": { - "line": 3, - "column": 24, - "index": 50 - } - } - }, - "initializer": null, - "comments": [], - "loc": { - "start": { - "line": 3, - "column": 17, - "index": 43 - }, - "end": { - "line": 3, - "column": 24, - "index": 50 - } - } - }, - { - "type": "EnumMember", - "name": { - "type": "Identifier", - "value": "FAILURE", - "loc": { - "start": { - "line": 4, - "column": 17, - "index": 68 - }, - "end": { - "line": 4, - "column": 24, - "index": 75 - } - } - }, - "initializer": null, - "comments": [], - "loc": { - "start": { - "line": 4, - "column": 17, - "index": 68 - }, - "end": { - "line": 4, - "column": 24, - "index": 75 - } - } - } - ], - "comments": [], - "loc": { - "start": { - "line": 2, - "column": 13, - "index": 13 - }, - "end": { - "line": 5, - "column": 14, - "index": 89 - } - } - } - } - ] - } - }, - "identifiers": { - "exception.Status": { - "name": "Status", - "pathName": "exception", - "resolvedName": "exception.Status", - "definition": { - "type": "EnumDefinition", - "name": { - "type": "Identifier", - "value": "Status", - "loc": { - "start": { - "line": 2, - "column": 18, - "index": 18 - }, - "end": { - "line": 2, - "column": 24, - "index": 24 - } - } - }, - "members": [ - { - "type": "EnumMember", - "name": { - "type": "Identifier", - "value": "SUCCESS", - "loc": { - "start": { - "line": 3, - "column": 17, - "index": 43 - }, - "end": { - "line": 3, - "column": 24, - "index": 50 - } - } - }, - "initializer": null, - "comments": [], - "loc": { - "start": { - "line": 3, - "column": 17, - "index": 43 - }, - "end": { - "line": 3, - "column": 24, - "index": 50 - } - } - }, - { - "type": "EnumMember", - "name": { - "type": "Identifier", - "value": "FAILURE", - "loc": { - "start": { - "line": 4, - "column": 17, - "index": 68 - }, - "end": { - "line": 4, - "column": 24, - "index": 75 - } - } - }, - "initializer": null, - "comments": [], - "loc": { - "start": { - "line": 4, - "column": 17, - "index": 68 - }, - "end": { - "line": 4, - "column": 24, - "index": 75 - } - } - } - ], - "comments": [], - "loc": { - "start": { - "line": 2, - "column": 13, - "index": 13 - }, - "end": { - "line": 5, - "column": 14, - "index": 89 - } - } - } - }, - "MyStruct": { - "name": "MyStruct", - "pathName": "", - "resolvedName": "MyStruct", - "definition": { - "type": "StructDefinition", - "name": { - "type": "Identifier", - "value": "MyStruct", - "loc": { - "start": { - "line": 4, - "column": 20, - "index": 60 - }, - "end": { - "line": 4, - "column": 28, - "index": 68 - } - } - }, - "fields": [ - { - "type": "FieldDefinition", - "name": { - "type": "Identifier", - "value": "status", - "loc": { - "start": { - "line": 5, - "column": 37, - "index": 107 - }, - "end": { - "line": 5, - "column": 43, - "index": 113 - } - } - }, - "fieldID": { - "type": "FieldID", - "value": 1, - "loc": { - "start": { - "line": 5, - "column": 17, - "index": 87 - }, - "end": { - "line": 5, - "column": 19, - "index": 89 - } - } - }, - "fieldType": { - "type": "Identifier", - "value": "exception.Status", - "loc": { - "start": { - "line": 5, - "column": 20, - "index": 90 - }, - "end": { - "line": 5, - "column": 36, - "index": 106 - } - } - }, - "requiredness": null, - "defaultValue": { - "type": "Identifier", - "value": "exception.Status.SUCCESS", - "loc": { - "start": { - "line": 5, - "column": 46, - "index": 116 - }, - "end": { - "line": 5, - "column": 70, - "index": 140 - } - } - }, - "comments": [], - "loc": { - "start": { - "line": 5, - "column": 17, - "index": 87 - }, - "end": { - "line": 5, - "column": 70, - "index": 140 - } - } - } - ], - "comments": [], - "loc": { - "start": { - "line": 4, - "column": 13, - "index": 53 - }, - "end": { - "line": 6, - "column": 14, - "index": 154 - } - } - } - } - }, - "body": [ - { - "type": "IncludeDefinition", - "path": { - "type": "StringLiteral", - "value": "exception.thrift", - "loc": { - "start": { - "line": 2, - "column": 21, - "index": 21 - }, - "end": { - "line": 2, - "column": 39, - "index": 39 - } - } - }, - "comments": [], - "loc": { - "start": { - "line": 2, - "column": 13, - "index": 13 - }, - "end": { - "line": 2, - "column": 39, - "index": 39 - } - } - }, - { - "type": "StructDefinition", - "name": { - "type": "Identifier", - "value": "MyStruct", - "loc": { - "start": { - "line": 4, - "column": 20, - "index": 60 - }, - "end": { - "line": 4, - "column": 28, - "index": 68 - } - } - }, - "fields": [ - { - "type": "FieldDefinition", - "name": { - "type": "Identifier", - "value": "status", - "loc": { - "start": { - "line": 5, - "column": 37, - "index": 107 - }, - "end": { - "line": 5, - "column": 43, - "index": 113 - } - } - }, - "fieldID": { - "type": "FieldID", - "value": 1, - "loc": { - "start": { - "line": 5, - "column": 17, - "index": 87 - }, - "end": { - "line": 5, - "column": 19, - "index": 89 - } - } - }, - "fieldType": { - "type": "Identifier", - "value": "exception.Status", - "loc": { - "start": { - "line": 5, - "column": 20, - "index": 90 - }, - "end": { - "line": 5, - "column": 36, - "index": 106 - } - } - }, - "requiredness": null, - "defaultValue": { - "type": "Identifier", - "value": "exception.Status.SUCCESS", - "loc": { - "start": { - "line": 5, - "column": 46, - "index": 116 - }, - "end": { - "line": 5, - "column": 70, - "index": 140 - } - } - }, - "comments": [], - "loc": { - "start": { - "line": 5, - "column": 17, - "index": 87 - }, - "end": { - "line": 5, - "column": 70, - "index": 140 - } - } - } - ], - "comments": [], - "loc": { - "start": { - "line": 4, - "column": 13, - "index": 53 - }, - "end": { - "line": 6, - "column": 14, - "index": 154 - } - } - } - ], - "errors": [] -} diff --git a/src/tests/unit/fixtures/thrift-server/annotations_extend_service.solution.ts b/src/tests/unit/fixtures/thrift-server/annotations_extend_service.solution.ts deleted file mode 100644 index fee2107b..00000000 --- a/src/tests/unit/fixtures/thrift-server/annotations_extend_service.solution.ts +++ /dev/null @@ -1,821 +0,0 @@ -export namespace ParentService { - export const serviceName: string = "ParentService"; - export const annotations: thrift.IThriftAnnotations = { - foo: "boo", - two: "three", - alone: "" - }; - export const methodAnnotations: thrift.IMethodAnnotations = { - ping: { - annotations: { - foo: "bar", - two: "three", - lonely: "" - }, - fieldAnnotations: {} - } - }; - export const methodNames: Array = ["ping"]; - export interface IPing__Args { - status: number; - } - export interface IPing__ArgsArgs { - status: number; - } - export const Ping__ArgsCodec: thrift.IStructCodec = { - encode(args: IPing__ArgsArgs, output: thrift.TProtocol): void { - const obj = { - status: args.status - }; - output.writeStructBegin("Ping__Args"); - if (obj.status != null) { - output.writeFieldBegin("status", thrift.TType.I32, 1); - output.writeI32(obj.status); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[status] is unset!"); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IPing__Args { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.I32) { - const value_1: number = input.readI32(); - _args.status = value_1; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.status !== undefined) { - return { - status: _args.status - }; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read Ping__Args from input"); - } - } - }; - export class Ping__Args extends thrift.StructLike implements IPing__Args { - public status: number; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IPing__ArgsArgs) { - super(); - if (args.status != null) { - const value_2: number = args.status; - this.status = value_2; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[status] is unset!"); - } - } - public static read(input: thrift.TProtocol): Ping__Args { - return new Ping__Args(Ping__ArgsCodec.decode(input)); - } - public static write(args: IPing__ArgsArgs, output: thrift.TProtocol): void { - return Ping__ArgsCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return Ping__ArgsCodec.encode(this, output); - } - } - export interface IPing__Result { - success?: string; - } - export interface IPing__ResultArgs { - success?: string; - } - export const Ping__ResultCodec: thrift.IStructCodec = { - encode(args: IPing__ResultArgs, output: thrift.TProtocol): void { - const obj = { - success: args.success - }; - output.writeStructBegin("Ping__Result"); - if (obj.success != null) { - output.writeFieldBegin("success", thrift.TType.STRING, 0); - output.writeString(obj.success); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IPing__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.STRING) { - const value_3: string = input.readString(); - _args.success = value_3; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - success: _args.success - }; - } - }; - export class Ping__Result extends thrift.StructLike implements IPing__Result { - public success?: string; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IPing__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_4: string = args.success; - this.success = value_4; - } - } - public static read(input: thrift.TProtocol): Ping__Result { - return new Ping__Result(Ping__ResultCodec.decode(input)); - } - public static write(args: IPing__ResultArgs, output: thrift.TProtocol): void { - return Ping__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return Ping__ResultCodec.encode(this, output); - } - } - export class Client extends thrift.ThriftClient { - public static readonly serviceName: string = serviceName; - public static readonly annotations: thrift.IThriftAnnotations = annotations; - public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public static readonly methodNames: Array = methodNames; - public readonly _serviceName: string = serviceName; - public readonly _annotations: thrift.IThriftAnnotations = annotations; - public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public readonly _methodNames: Array = methodNames; - public ping(status: number, context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("ping", thrift.MessageType.CALL, this.incrementRequestId()); - const args: IPing__ArgsArgs = { status }; - Ping__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "ping") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: IPing__Result = Ping__ResultCodec.decode(input); - input.readMessageEnd(); - if (result.success != null) { - return Promise.resolve(result.success); - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "ping failed: unknown result")); - } - } - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } - } - catch (err) { - return Promise.reject(err); - } - }); - } - } - export interface IHandler { - ping(status: number, context?: Context): string | Promise; - } - export class Processor extends thrift.ThriftProcessor> { - protected readonly _handler: IHandler; - public static readonly serviceName: string = serviceName; - public static readonly annotations: thrift.IThriftAnnotations = annotations; - public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public static readonly methodNames: Array = methodNames; - public readonly _serviceName: string = serviceName; - public readonly _annotations: thrift.IThriftAnnotations = annotations; - public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public readonly _methodNames: Array = methodNames; - constructor(handler: IHandler) { - super(); - this._handler = handler; - } - public process(input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - const metadata: thrift.IThriftMessage = input.readMessageBegin(); - const fieldName: string = metadata.fieldName; - const requestId: number = metadata.requestId; - const methodName: string = "process_" + fieldName; - switch (methodName) { - case "process_ping": { - resolve(this.process_ping(requestId, input, output, context)); - break; - } - default: { - input.skip(thrift.TType.STRUCT); - input.readMessageEnd(); - const errMessage = "Unknown function " + fieldName; - const err = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN_METHOD, errMessage); - output.writeMessageBegin(fieldName, thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(err, output); - output.writeMessageEnd(); - resolve(output.flush()); - break; - } - } - }); - } - public process_ping(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { - const args: IPing__Args = Ping__ArgsCodec.decode(input); - input.readMessageEnd(); - resolve(this._handler.ping(args.status, context)); - } - catch (err) { - reject(err); - } - }).then((data: string): Buffer => { - const result: IPing__ResultArgs = { success: data }; - output.writeMessageBegin("ping", thrift.MessageType.REPLY, requestId); - Ping__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("ping", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } - } -} -export namespace ChildService { - export const serviceName: string = "ChildService"; - export const annotations: thrift.IThriftAnnotations = { - foo: "bar", - two: "three", - alone: "", - four: "five", - secured: "" - }; - export const methodAnnotations: thrift.IMethodAnnotations = { - ping: { - annotations: { - foo: "bar", - two: "three", - lonely: "" - }, - fieldAnnotations: {} - }, - peg: { - annotations: {}, - fieldAnnotations: {} - }, - pong: { - annotations: {}, - fieldAnnotations: {} - } - }; - export const methodNames: Array = ["ping", "peg", "pong"]; - export interface IPeg__Args { - name: string; - } - export interface IPeg__ArgsArgs { - name: string; - } - export const Peg__ArgsCodec: thrift.IStructCodec = { - encode(args: IPeg__ArgsArgs, output: thrift.TProtocol): void { - const obj = { - name: args.name - }; - output.writeStructBegin("Peg__Args"); - if (obj.name != null) { - output.writeFieldBegin("name", thrift.TType.STRING, 1); - output.writeString(obj.name); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[name] is unset!"); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IPeg__Args { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.STRING) { - const value_5: string = input.readString(); - _args.name = value_5; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.name !== undefined) { - return { - name: _args.name - }; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read Peg__Args from input"); - } - } - }; - export class Peg__Args extends thrift.StructLike implements IPeg__Args { - public name: string; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IPeg__ArgsArgs) { - super(); - if (args.name != null) { - const value_6: string = args.name; - this.name = value_6; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[name] is unset!"); - } - } - public static read(input: thrift.TProtocol): Peg__Args { - return new Peg__Args(Peg__ArgsCodec.decode(input)); - } - public static write(args: IPeg__ArgsArgs, output: thrift.TProtocol): void { - return Peg__ArgsCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return Peg__ArgsCodec.encode(this, output); - } - } - export interface IPong__Args { - name?: string; - } - export interface IPong__ArgsArgs { - name?: string; - } - export const Pong__ArgsCodec: thrift.IStructCodec = { - encode(args: IPong__ArgsArgs, output: thrift.TProtocol): void { - const obj = { - name: args.name - }; - output.writeStructBegin("Pong__Args"); - if (obj.name != null) { - output.writeFieldBegin("name", thrift.TType.STRING, 1); - output.writeString(obj.name); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IPong__Args { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.STRING) { - const value_7: string = input.readString(); - _args.name = value_7; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - name: _args.name - }; - } - }; - export class Pong__Args extends thrift.StructLike implements IPong__Args { - public name?: string; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IPong__ArgsArgs = {}) { - super(); - if (args.name != null) { - const value_8: string = args.name; - this.name = value_8; - } - } - public static read(input: thrift.TProtocol): Pong__Args { - return new Pong__Args(Pong__ArgsCodec.decode(input)); - } - public static write(args: IPong__ArgsArgs, output: thrift.TProtocol): void { - return Pong__ArgsCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return Pong__ArgsCodec.encode(this, output); - } - } - export interface IPeg__Result { - success?: string; - } - export interface IPeg__ResultArgs { - success?: string; - } - export const Peg__ResultCodec: thrift.IStructCodec = { - encode(args: IPeg__ResultArgs, output: thrift.TProtocol): void { - const obj = { - success: args.success - }; - output.writeStructBegin("Peg__Result"); - if (obj.success != null) { - output.writeFieldBegin("success", thrift.TType.STRING, 0); - output.writeString(obj.success); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IPeg__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.STRING) { - const value_9: string = input.readString(); - _args.success = value_9; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - success: _args.success - }; - } - }; - export class Peg__Result extends thrift.StructLike implements IPeg__Result { - public success?: string; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IPeg__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_10: string = args.success; - this.success = value_10; - } - } - public static read(input: thrift.TProtocol): Peg__Result { - return new Peg__Result(Peg__ResultCodec.decode(input)); - } - public static write(args: IPeg__ResultArgs, output: thrift.TProtocol): void { - return Peg__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return Peg__ResultCodec.encode(this, output); - } - } - export interface IPong__Result { - success?: string; - } - export interface IPong__ResultArgs { - success?: string; - } - export const Pong__ResultCodec: thrift.IStructCodec = { - encode(args: IPong__ResultArgs, output: thrift.TProtocol): void { - const obj = { - success: args.success - }; - output.writeStructBegin("Pong__Result"); - if (obj.success != null) { - output.writeFieldBegin("success", thrift.TType.STRING, 0); - output.writeString(obj.success); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IPong__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.STRING) { - const value_11: string = input.readString(); - _args.success = value_11; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - success: _args.success - }; - } - }; - export class Pong__Result extends thrift.StructLike implements IPong__Result { - public success?: string; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IPong__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_12: string = args.success; - this.success = value_12; - } - } - public static read(input: thrift.TProtocol): Pong__Result { - return new Pong__Result(Pong__ResultCodec.decode(input)); - } - public static write(args: IPong__ResultArgs, output: thrift.TProtocol): void { - return Pong__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return Pong__ResultCodec.encode(this, output); - } - } - export class Client extends ParentService.Client { - public static readonly serviceName: string = serviceName; - public static readonly annotations: thrift.IThriftAnnotations = annotations; - public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public static readonly methodNames: Array = methodNames; - public readonly _serviceName: string = serviceName; - public readonly _annotations: thrift.IThriftAnnotations = annotations; - public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public readonly _methodNames: Array = methodNames; - constructor(connection: thrift.IThriftConnection) { - super(connection); - } - public peg(name: string, context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("peg", thrift.MessageType.CALL, this.incrementRequestId()); - const args: IPeg__ArgsArgs = { name }; - Peg__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "peg") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: IPeg__Result = Peg__ResultCodec.decode(input); - input.readMessageEnd(); - if (result.success != null) { - return Promise.resolve(result.success); - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "peg failed: unknown result")); - } - } - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } - } - catch (err) { - return Promise.reject(err); - } - }); - } - public pong(name?: string, context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("pong", thrift.MessageType.CALL, this.incrementRequestId()); - const args: IPong__ArgsArgs = { name }; - Pong__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "pong") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: IPong__Result = Pong__ResultCodec.decode(input); - input.readMessageEnd(); - if (result.success != null) { - return Promise.resolve(result.success); - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "pong failed: unknown result")); - } - } - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } - } - catch (err) { - return Promise.reject(err); - } - }); - } - } - export interface ILocalHandler { - peg(name: string, context?: Context): string | Promise; - pong(name?: string, context?: Context): string | Promise; - } - export type IHandler = ILocalHandler & ParentService.IHandler; - export class Processor extends ParentService.Processor { - protected readonly _handler: IHandler; - public static readonly serviceName: string = serviceName; - public static readonly annotations: thrift.IThriftAnnotations = annotations; - public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public static readonly methodNames: Array = methodNames; - public readonly _serviceName: string = serviceName; - public readonly _annotations: thrift.IThriftAnnotations = annotations; - public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public readonly _methodNames: Array = methodNames; - constructor(handler: IHandler) { - super({ - ping: handler.ping - }); - this._handler = handler; - } - public process(input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - const metadata: thrift.IThriftMessage = input.readMessageBegin(); - const fieldName: string = metadata.fieldName; - const requestId: number = metadata.requestId; - const methodName: string = "process_" + fieldName; - switch (methodName) { - case "process_ping": { - resolve(this.process_ping(requestId, input, output, context)); - break; - } - case "process_peg": { - resolve(this.process_peg(requestId, input, output, context)); - break; - } - case "process_pong": { - resolve(this.process_pong(requestId, input, output, context)); - break; - } - default: { - input.skip(thrift.TType.STRUCT); - input.readMessageEnd(); - const errMessage = "Unknown function " + fieldName; - const err = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN_METHOD, errMessage); - output.writeMessageBegin(fieldName, thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(err, output); - output.writeMessageEnd(); - resolve(output.flush()); - break; - } - } - }); - } - public process_peg(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { - const args: IPeg__Args = Peg__ArgsCodec.decode(input); - input.readMessageEnd(); - resolve(this._handler.peg(args.name, context)); - } - catch (err) { - reject(err); - } - }).then((data: string): Buffer => { - const result: IPeg__ResultArgs = { success: data }; - output.writeMessageBegin("peg", thrift.MessageType.REPLY, requestId); - Peg__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("peg", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } - public process_pong(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { - const args: IPong__Args = Pong__ArgsCodec.decode(input); - input.readMessageEnd(); - resolve(this._handler.pong(args.name, context)); - } - catch (err) { - reject(err); - } - }).then((data: string): Buffer => { - const result: IPong__ResultArgs = { success: data }; - output.writeMessageBegin("pong", thrift.MessageType.REPLY, requestId); - Pong__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("pong", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } - } -} diff --git a/src/tests/unit/fixtures/thrift-server/annotations_service.solution.ts b/src/tests/unit/fixtures/thrift-server/annotations_service.solution.ts index de07fbf2..507e7ab4 100644 --- a/src/tests/unit/fixtures/thrift-server/annotations_service.solution.ts +++ b/src/tests/unit/fixtures/thrift-server/annotations_service.solution.ts @@ -112,693 +112,691 @@ export class User extends thrift.StructLike implements IUser { return UserCodec.encode(this, output); } } -export namespace MyService { - export const serviceName: string = "MyService"; - export const annotations: thrift.IThriftAnnotations = { - foo: "bar", - two: "three", - alone: "", - 'dot.foo': "bar", - 'dot.lonely': "" - }; - export const methodAnnotations: thrift.IMethodAnnotations = { - getUser: { - annotations: { - foo: "bar", - two: "three", - lonely: "", - 'dot.foo': "bar", - 'dot.lonely': "" - }, - fieldAnnotations: {} - }, - saveUser: { - annotations: {}, - fieldAnnotations: {} +export const serviceName: string = "MyService"; +export const annotations: thrift.IThriftAnnotations = { + foo: "bar", + two: "three", + alone: "", + 'dot.foo': "bar", + 'dot.lonely': "" +}; +export const methodAnnotations: thrift.IMethodAnnotations = { + getUser: { + annotations: { + foo: "bar", + two: "three", + lonely: "", + 'dot.foo': "bar", + 'dot.lonely': "" }, - ping: { - annotations: {}, - fieldAnnotations: {} - } - }; - export const methodNames: Array = ["getUser", "saveUser", "ping"]; - export interface IGetUser__Args { - id: number; - } - export interface IGetUser__ArgsArgs { - id: number; - } - export const GetUser__ArgsCodec: thrift.IStructCodec = { - encode(args: IGetUser__ArgsArgs, output: thrift.TProtocol): void { - const obj = { - id: args.id - }; - output.writeStructBegin("GetUser__Args"); - if (obj.id != null) { - output.writeFieldBegin("id", thrift.TType.I32, 1); - output.writeI32(obj.id); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[id] is unset!"); + fieldAnnotations: {} + }, + saveUser: { + annotations: {}, + fieldAnnotations: {} + }, + ping: { + annotations: {}, + fieldAnnotations: {} + } +}; +export const methodNames: Array = ["getUser", "saveUser", "ping"]; +export interface IGetUser__Args { + id: number; +} +export interface IGetUser__ArgsArgs { + id: number; +} +export const GetUser__ArgsCodec: thrift.IStructCodec = { + encode(args: IGetUser__ArgsArgs, output: thrift.TProtocol): void { + const obj = { + id: args.id + }; + output.writeStructBegin("GetUser__Args"); + if (obj.id != null) { + output.writeFieldBegin("id", thrift.TType.I32, 1); + output.writeI32(obj.id); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[id] is unset!"); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IGetUser__Args { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IGetUser__Args { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.I32) { - const value_5: number = input.readI32(); - _args.id = value_5; - } - else { - input.skip(fieldType); - } - break; - default: { + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.I32) { + const value_5: number = input.readI32(); + _args.id = value_5; + } + else { input.skip(fieldType); } + break; + default: { + input.skip(fieldType); } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.id !== undefined) { - return { - id: _args.id - }; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read GetUser__Args from input"); } + input.readFieldEnd(); } - }; - export class GetUser__Args extends thrift.StructLike implements IGetUser__Args { - public id: number; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IGetUser__ArgsArgs) { - super(); - if (args.id != null) { - const value_6: number = args.id; - this.id = value_6; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[id] is unset!"); - } + input.readStructEnd(); + if (_args.id !== undefined) { + return { + id: _args.id + }; } - public static read(input: thrift.TProtocol): GetUser__Args { - return new GetUser__Args(GetUser__ArgsCodec.decode(input)); + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read GetUser__Args from input"); } - public static write(args: IGetUser__ArgsArgs, output: thrift.TProtocol): void { - return GetUser__ArgsCodec.encode(args, output); + } +}; +export class GetUser__Args extends thrift.StructLike implements IGetUser__Args { + public id: number; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IGetUser__ArgsArgs) { + super(); + if (args.id != null) { + const value_6: number = args.id; + this.id = value_6; } - public write(output: thrift.TProtocol): void { - return GetUser__ArgsCodec.encode(this, output); + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[id] is unset!"); } } - export interface ISaveUser__Args { - user: IUser; + public static read(input: thrift.TProtocol): GetUser__Args { + return new GetUser__Args(GetUser__ArgsCodec.decode(input)); } - export interface ISaveUser__ArgsArgs { - user: IUserArgs; + public static write(args: IGetUser__ArgsArgs, output: thrift.TProtocol): void { + return GetUser__ArgsCodec.encode(args, output); } - export const SaveUser__ArgsCodec: thrift.IStructCodec = { - encode(args: ISaveUser__ArgsArgs, output: thrift.TProtocol): void { - const obj = { - user: args.user - }; - output.writeStructBegin("SaveUser__Args"); - if (obj.user != null) { - output.writeFieldBegin("user", thrift.TType.STRUCT, 1); - UserCodec.encode(obj.user, output); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[user] is unset!"); + public write(output: thrift.TProtocol): void { + return GetUser__ArgsCodec.encode(this, output); + } +} +export interface ISaveUser__Args { + user: IUser; +} +export interface ISaveUser__ArgsArgs { + user: IUserArgs; +} +export const SaveUser__ArgsCodec: thrift.IStructCodec = { + encode(args: ISaveUser__ArgsArgs, output: thrift.TProtocol): void { + const obj = { + user: args.user + }; + output.writeStructBegin("SaveUser__Args"); + if (obj.user != null) { + output.writeFieldBegin("user", thrift.TType.STRUCT, 1); + UserCodec.encode(obj.user, output); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[user] is unset!"); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): ISaveUser__Args { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): ISaveUser__Args { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.STRUCT) { - const value_7: IUser = UserCodec.decode(input); - _args.user = value_7; - } - else { - input.skip(fieldType); - } - break; - default: { + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.STRUCT) { + const value_7: IUser = UserCodec.decode(input); + _args.user = value_7; + } + else { input.skip(fieldType); } + break; + default: { + input.skip(fieldType); } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.user !== undefined) { - return { - user: _args.user - }; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read SaveUser__Args from input"); } + input.readFieldEnd(); } - }; - export class SaveUser__Args extends thrift.StructLike implements ISaveUser__Args { - public user: IUser; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: ISaveUser__ArgsArgs) { - super(); - if (args.user != null) { - const value_8: IUser = new User(args.user); - this.user = value_8; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[user] is unset!"); - } + input.readStructEnd(); + if (_args.user !== undefined) { + return { + user: _args.user + }; } - public static read(input: thrift.TProtocol): SaveUser__Args { - return new SaveUser__Args(SaveUser__ArgsCodec.decode(input)); + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read SaveUser__Args from input"); } - public static write(args: ISaveUser__ArgsArgs, output: thrift.TProtocol): void { - return SaveUser__ArgsCodec.encode(args, output); + } +}; +export class SaveUser__Args extends thrift.StructLike implements ISaveUser__Args { + public user: IUser; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: ISaveUser__ArgsArgs) { + super(); + if (args.user != null) { + const value_8: IUser = new User(args.user); + this.user = value_8; } - public write(output: thrift.TProtocol): void { - return SaveUser__ArgsCodec.encode(this, output); + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[user] is unset!"); } } - export interface IPing__Args { + public static read(input: thrift.TProtocol): SaveUser__Args { + return new SaveUser__Args(SaveUser__ArgsCodec.decode(input)); } - export interface IPing__ArgsArgs { + public static write(args: ISaveUser__ArgsArgs, output: thrift.TProtocol): void { + return SaveUser__ArgsCodec.encode(args, output); } - export const Ping__ArgsCodec: thrift.IStructCodec = { - encode(args: IPing__ArgsArgs, output: thrift.TProtocol): void { - output.writeStructBegin("Ping__Args"); - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IPing__Args { - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - default: { - input.skip(fieldType); - } + public write(output: thrift.TProtocol): void { + return SaveUser__ArgsCodec.encode(this, output); + } +} +export interface IPing__Args { +} +export interface IPing__ArgsArgs { +} +export const Ping__ArgsCodec: thrift.IStructCodec = { + encode(args: IPing__ArgsArgs, output: thrift.TProtocol): void { + output.writeStructBegin("Ping__Args"); + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IPing__Args { + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + default: { + input.skip(fieldType); } - input.readFieldEnd(); } - input.readStructEnd(); - return {}; - } - }; - export class Ping__Args extends thrift.StructLike implements IPing__Args { - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IPing__ArgsArgs = {}) { - super(); - } - public static read(input: thrift.TProtocol): Ping__Args { - return new Ping__Args(Ping__ArgsCodec.decode(input)); - } - public static write(args: IPing__ArgsArgs, output: thrift.TProtocol): void { - return Ping__ArgsCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return Ping__ArgsCodec.encode(this, output); + input.readFieldEnd(); } + input.readStructEnd(); + return {}; } - export interface IGetUser__Result { - success?: IUser; +}; +export class Ping__Args extends thrift.StructLike implements IPing__Args { + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IPing__ArgsArgs = {}) { + super(); } - export interface IGetUser__ResultArgs { - success?: IUserArgs; + public static read(input: thrift.TProtocol): Ping__Args { + return new Ping__Args(Ping__ArgsCodec.decode(input)); } - export const GetUser__ResultCodec: thrift.IStructCodec = { - encode(args: IGetUser__ResultArgs, output: thrift.TProtocol): void { - const obj = { - success: args.success - }; - output.writeStructBegin("GetUser__Result"); - if (obj.success != null) { - output.writeFieldBegin("success", thrift.TType.STRUCT, 0); - UserCodec.encode(obj.success, output); - output.writeFieldEnd(); + public static write(args: IPing__ArgsArgs, output: thrift.TProtocol): void { + return Ping__ArgsCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return Ping__ArgsCodec.encode(this, output); + } +} +export interface IGetUser__Result { + success?: IUser; +} +export interface IGetUser__ResultArgs { + success?: IUserArgs; +} +export const GetUser__ResultCodec: thrift.IStructCodec = { + encode(args: IGetUser__ResultArgs, output: thrift.TProtocol): void { + const obj = { + success: args.success + }; + output.writeStructBegin("GetUser__Result"); + if (obj.success != null) { + output.writeFieldBegin("success", thrift.TType.STRUCT, 0); + UserCodec.encode(obj.success, output); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IGetUser__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IGetUser__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.STRUCT) { - const value_9: IUser = UserCodec.decode(input); - _args.success = value_9; - } - else { - input.skip(fieldType); - } - break; - default: { + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.STRUCT) { + const value_9: IUser = UserCodec.decode(input); + _args.success = value_9; + } + else { input.skip(fieldType); } + break; + default: { + input.skip(fieldType); } - input.readFieldEnd(); } - input.readStructEnd(); - return { - success: _args.success - }; - } - }; - export class GetUser__Result extends thrift.StructLike implements IGetUser__Result { - public success?: IUser; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IGetUser__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_10: IUser = new User(args.success); - this.success = value_10; - } - } - public static read(input: thrift.TProtocol): GetUser__Result { - return new GetUser__Result(GetUser__ResultCodec.decode(input)); - } - public static write(args: IGetUser__ResultArgs, output: thrift.TProtocol): void { - return GetUser__ResultCodec.encode(args, output); + input.readFieldEnd(); } - public write(output: thrift.TProtocol): void { - return GetUser__ResultCodec.encode(this, output); + input.readStructEnd(); + return { + success: _args.success + }; + } +}; +export class GetUser__Result extends thrift.StructLike implements IGetUser__Result { + public success?: IUser; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IGetUser__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_10: IUser = new User(args.success); + this.success = value_10; } } - export interface ISaveUser__Result { - success?: void; + public static read(input: thrift.TProtocol): GetUser__Result { + return new GetUser__Result(GetUser__ResultCodec.decode(input)); } - export interface ISaveUser__ResultArgs { - success?: void; + public static write(args: IGetUser__ResultArgs, output: thrift.TProtocol): void { + return GetUser__ResultCodec.encode(args, output); } - export const SaveUser__ResultCodec: thrift.IStructCodec = { - encode(args: ISaveUser__ResultArgs, output: thrift.TProtocol): void { - output.writeStructBegin("SaveUser__Result"); - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): ISaveUser__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.VOID) { - input.skip(fieldType); - } - else { - input.skip(fieldType); - } - break; - default: { + public write(output: thrift.TProtocol): void { + return GetUser__ResultCodec.encode(this, output); + } +} +export interface ISaveUser__Result { + success?: void; +} +export interface ISaveUser__ResultArgs { + success?: void; +} +export const SaveUser__ResultCodec: thrift.IStructCodec = { + encode(args: ISaveUser__ResultArgs, output: thrift.TProtocol): void { + output.writeStructBegin("SaveUser__Result"); + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): ISaveUser__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.VOID) { + input.skip(fieldType); + } + else { input.skip(fieldType); } + break; + default: { + input.skip(fieldType); } - input.readFieldEnd(); } - input.readStructEnd(); - return { - success: _args.success - }; - } - }; - export class SaveUser__Result extends thrift.StructLike implements ISaveUser__Result { - public success?: void; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: ISaveUser__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_11: void = undefined; - this.success = value_11; - } - } - public static read(input: thrift.TProtocol): SaveUser__Result { - return new SaveUser__Result(SaveUser__ResultCodec.decode(input)); - } - public static write(args: ISaveUser__ResultArgs, output: thrift.TProtocol): void { - return SaveUser__ResultCodec.encode(args, output); + input.readFieldEnd(); } - public write(output: thrift.TProtocol): void { - return SaveUser__ResultCodec.encode(this, output); + input.readStructEnd(); + return { + success: _args.success + }; + } +}; +export class SaveUser__Result extends thrift.StructLike implements ISaveUser__Result { + public success?: void; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: ISaveUser__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_11: void = undefined; + this.success = value_11; } } - export interface IPing__Result { - success?: void; + public static read(input: thrift.TProtocol): SaveUser__Result { + return new SaveUser__Result(SaveUser__ResultCodec.decode(input)); } - export interface IPing__ResultArgs { - success?: void; + public static write(args: ISaveUser__ResultArgs, output: thrift.TProtocol): void { + return SaveUser__ResultCodec.encode(args, output); } - export const Ping__ResultCodec: thrift.IStructCodec = { - encode(args: IPing__ResultArgs, output: thrift.TProtocol): void { - output.writeStructBegin("Ping__Result"); - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IPing__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.VOID) { - input.skip(fieldType); - } - else { - input.skip(fieldType); - } - break; - default: { + public write(output: thrift.TProtocol): void { + return SaveUser__ResultCodec.encode(this, output); + } +} +export interface IPing__Result { + success?: void; +} +export interface IPing__ResultArgs { + success?: void; +} +export const Ping__ResultCodec: thrift.IStructCodec = { + encode(args: IPing__ResultArgs, output: thrift.TProtocol): void { + output.writeStructBegin("Ping__Result"); + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IPing__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.VOID) { + input.skip(fieldType); + } + else { input.skip(fieldType); } + break; + default: { + input.skip(fieldType); } - input.readFieldEnd(); } - input.readStructEnd(); - return { - success: _args.success - }; + input.readFieldEnd(); } - }; - export class Ping__Result extends thrift.StructLike implements IPing__Result { - public success?: void; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IPing__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_12: void = undefined; - this.success = value_12; - } + input.readStructEnd(); + return { + success: _args.success + }; + } +}; +export class Ping__Result extends thrift.StructLike implements IPing__Result { + public success?: void; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IPing__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_12: void = undefined; + this.success = value_12; } - public static read(input: thrift.TProtocol): Ping__Result { - return new Ping__Result(Ping__ResultCodec.decode(input)); - } - public static write(args: IPing__ResultArgs, output: thrift.TProtocol): void { - return Ping__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return Ping__ResultCodec.encode(this, output); - } - } - export class Client extends thrift.ThriftClient { - public static readonly serviceName: string = serviceName; - public static readonly annotations: thrift.IThriftAnnotations = annotations; - public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public static readonly methodNames: Array = methodNames; - public readonly _serviceName: string = serviceName; - public readonly _annotations: thrift.IThriftAnnotations = annotations; - public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public readonly _methodNames: Array = methodNames; - public getUser(id: number, context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("getUser", thrift.MessageType.CALL, this.incrementRequestId()); - const args: IGetUser__ArgsArgs = { id }; - GetUser__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "getUser") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: IGetUser__Result = GetUser__ResultCodec.decode(input); - input.readMessageEnd(); - if (result.success != null) { - return Promise.resolve(result.success); - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "getUser failed: unknown result")); - } - } + } + public static read(input: thrift.TProtocol): Ping__Result { + return new Ping__Result(Ping__ResultCodec.decode(input)); + } + public static write(args: IPing__ResultArgs, output: thrift.TProtocol): void { + return Ping__ResultCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return Ping__ResultCodec.encode(this, output); + } +} +export class Client extends thrift.ThriftClient { + public static readonly serviceName: string = serviceName; + public static readonly annotations: thrift.IThriftAnnotations = annotations; + public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public static readonly methodNames: Array = methodNames; + public readonly _serviceName: string = serviceName; + public readonly _annotations: thrift.IThriftAnnotations = annotations; + public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public readonly _methodNames: Array = methodNames; + public getUser(id: number, context?: Context): Promise { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("getUser", thrift.MessageType.CALL, this.incrementRequestId()); + const args: IGetUser__ArgsArgs = { id }; + GetUser__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "getUser") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); } else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } - } - catch (err) { - return Promise.reject(err); - } - }); - } - public saveUser(user: IUserArgs, context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("saveUser", thrift.MessageType.CALL, this.incrementRequestId()); - const args: ISaveUser__ArgsArgs = { user }; - SaveUser__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "saveUser") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); + const result: IGetUser__Result = GetUser__ResultCodec.decode(input); + input.readMessageEnd(); + if (result.success != null) { + return Promise.resolve(result.success); } else { - const result: ISaveUser__Result = SaveUser__ResultCodec.decode(input); - input.readMessageEnd(); - return Promise.resolve(result.success); + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "getUser failed: unknown result")); } } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } } - catch (err) { - return Promise.reject(err); + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); } - }); - } - public ping(context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("ping", thrift.MessageType.CALL, this.incrementRequestId()); - const args: IPing__ArgsArgs = {}; - Ping__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "ping") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: IPing__Result = Ping__ResultCodec.decode(input); - input.readMessageEnd(); - return Promise.resolve(result.success); - } + } + catch (err) { + return Promise.reject(err); + } + }); + } + public saveUser(user: IUserArgs, context?: Context): Promise { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("saveUser", thrift.MessageType.CALL, this.incrementRequestId()); + const args: ISaveUser__ArgsArgs = { user }; + SaveUser__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "saveUser") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); } else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); + const result: ISaveUser__Result = SaveUser__ResultCodec.decode(input); + input.readMessageEnd(); + return Promise.resolve(result.success); } } - catch (err) { - return Promise.reject(err); + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); } - }); - } - } - export interface IHandler { - getUser(id: number, context?: Context): IUserArgs | Promise; - saveUser(user: IUser, context?: Context): void | Promise; - ping(context?: Context): void | Promise; - } - export class Processor extends thrift.ThriftProcessor> { - protected readonly _handler: IHandler; - public static readonly serviceName: string = serviceName; - public static readonly annotations: thrift.IThriftAnnotations = annotations; - public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public static readonly methodNames: Array = methodNames; - public readonly _serviceName: string = serviceName; - public readonly _annotations: thrift.IThriftAnnotations = annotations; - public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public readonly _methodNames: Array = methodNames; - constructor(handler: IHandler) { - super(); - this._handler = handler; - } - public process(input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - const metadata: thrift.IThriftMessage = input.readMessageBegin(); - const fieldName: string = metadata.fieldName; - const requestId: number = metadata.requestId; - const methodName: string = "process_" + fieldName; - switch (methodName) { - case "process_getUser": { - resolve(this.process_getUser(requestId, input, output, context)); - break; - } - case "process_saveUser": { - resolve(this.process_saveUser(requestId, input, output, context)); - break; - } - case "process_ping": { - resolve(this.process_ping(requestId, input, output, context)); - break; + } + catch (err) { + return Promise.reject(err); + } + }); + } + public ping(context?: Context): Promise { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("ping", thrift.MessageType.CALL, this.incrementRequestId()); + const args: IPing__ArgsArgs = {}; + Ping__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "ping") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); } - default: { - input.skip(thrift.TType.STRUCT); + else { + const result: IPing__Result = Ping__ResultCodec.decode(input); input.readMessageEnd(); - const errMessage = "Unknown function " + fieldName; - const err = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN_METHOD, errMessage); - output.writeMessageBegin(fieldName, thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(err, output); - output.writeMessageEnd(); - resolve(output.flush()); - break; + return Promise.resolve(result.success); } } - }); - } - public process_getUser(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { - const args: IGetUser__Args = GetUser__ArgsCodec.decode(input); - input.readMessageEnd(); - resolve(this._handler.getUser(args.id, context)); + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); } - catch (err) { - reject(err); + } + catch (err) { + return Promise.reject(err); + } + }); + } +} +export interface IHandler { + getUser(id: number, context?: Context): IUserArgs | Promise; + saveUser(user: IUser, context?: Context): void | Promise; + ping(context?: Context): void | Promise; +} +export class Processor extends thrift.ThriftProcessor> { + protected readonly _handler: IHandler; + public static readonly serviceName: string = serviceName; + public static readonly annotations: thrift.IThriftAnnotations = annotations; + public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public static readonly methodNames: Array = methodNames; + public readonly _serviceName: string = serviceName; + public readonly _annotations: thrift.IThriftAnnotations = annotations; + public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public readonly _methodNames: Array = methodNames; + constructor(handler: IHandler) { + super(); + this._handler = handler; + } + public process(input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + const metadata: thrift.IThriftMessage = input.readMessageBegin(); + const fieldName: string = metadata.fieldName; + const requestId: number = metadata.requestId; + const methodName: string = "process_" + fieldName; + switch (methodName) { + case "process_getUser": { + resolve(this.process_getUser(requestId, input, output, context)); + break; } - }).then((data: IUserArgs): Buffer => { - const result: IGetUser__ResultArgs = { success: data }; - output.writeMessageBegin("getUser", thrift.MessageType.REPLY, requestId); - GetUser__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("getUser", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } - public process_saveUser(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { - const args: ISaveUser__Args = SaveUser__ArgsCodec.decode(input); - input.readMessageEnd(); - resolve(this._handler.saveUser(args.user, context)); + case "process_saveUser": { + resolve(this.process_saveUser(requestId, input, output, context)); + break; } - catch (err) { - reject(err); + case "process_ping": { + resolve(this.process_ping(requestId, input, output, context)); + break; } - }).then((data: void): Buffer => { - const result: ISaveUser__ResultArgs = { success: data }; - output.writeMessageBegin("saveUser", thrift.MessageType.REPLY, requestId); - SaveUser__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("saveUser", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } - public process_ping(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { + default: { + input.skip(thrift.TType.STRUCT); input.readMessageEnd(); - resolve(this._handler.ping(context)); - } - catch (err) { - reject(err); + const errMessage = "Unknown function " + fieldName; + const err = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN_METHOD, errMessage); + output.writeMessageBegin(fieldName, thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(err, output); + output.writeMessageEnd(); + resolve(output.flush()); + break; } - }).then((data: void): Buffer => { - const result: IPing__ResultArgs = { success: data }; - output.writeMessageBegin("ping", thrift.MessageType.REPLY, requestId); - Ping__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("ping", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } + } + }); + } + public process_getUser(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + try { + const args: IGetUser__Args = GetUser__ArgsCodec.decode(input); + input.readMessageEnd(); + resolve(this._handler.getUser(args.id, context)); + } + catch (err) { + reject(err); + } + }).then((data: IUserArgs): Buffer => { + const result: IGetUser__ResultArgs = { success: data }; + output.writeMessageBegin("getUser", thrift.MessageType.REPLY, requestId); + GetUser__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("getUser", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }); + } + public process_saveUser(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + try { + const args: ISaveUser__Args = SaveUser__ArgsCodec.decode(input); + input.readMessageEnd(); + resolve(this._handler.saveUser(args.user, context)); + } + catch (err) { + reject(err); + } + }).then((data: void): Buffer => { + const result: ISaveUser__ResultArgs = { success: data }; + output.writeMessageBegin("saveUser", thrift.MessageType.REPLY, requestId); + SaveUser__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("saveUser", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }); + } + public process_ping(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + try { + input.readMessageEnd(); + resolve(this._handler.ping(context)); + } + catch (err) { + reject(err); + } + }).then((data: void): Buffer => { + const result: IPing__ResultArgs = { success: data }; + output.writeMessageBegin("ping", thrift.MessageType.REPLY, requestId); + Ping__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("ping", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }); } } diff --git a/src/tests/unit/fixtures/thrift-server/basic_service.solution.ts b/src/tests/unit/fixtures/thrift-server/basic_service.solution.ts index f42e86c0..e13e1878 100644 --- a/src/tests/unit/fixtures/thrift-server/basic_service.solution.ts +++ b/src/tests/unit/fixtures/thrift-server/basic_service.solution.ts @@ -112,681 +112,679 @@ export class User extends thrift.StructLike implements IUser { return UserCodec.encode(this, output); } } -export namespace MyService { - export const serviceName: string = "MyService"; - export const annotations: thrift.IThriftAnnotations = {}; - export const methodAnnotations: thrift.IMethodAnnotations = { - getUser: { - annotations: {}, - fieldAnnotations: {} - }, - saveUser: { - annotations: {}, - fieldAnnotations: {} - }, - ping: { - annotations: {}, - fieldAnnotations: {} - } - }; - export const methodNames: Array = ["getUser", "saveUser", "ping"]; - export interface IGetUser__Args { - id: number; - } - export interface IGetUser__ArgsArgs { - id: number; - } - export const GetUser__ArgsCodec: thrift.IStructCodec = { - encode(args: IGetUser__ArgsArgs, output: thrift.TProtocol): void { - const obj = { - id: args.id - }; - output.writeStructBegin("GetUser__Args"); - if (obj.id != null) { - output.writeFieldBegin("id", thrift.TType.I32, 1); - output.writeI32(obj.id); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[id] is unset!"); +export const serviceName: string = "MyService"; +export const annotations: thrift.IThriftAnnotations = {}; +export const methodAnnotations: thrift.IMethodAnnotations = { + getUser: { + annotations: {}, + fieldAnnotations: {} + }, + saveUser: { + annotations: {}, + fieldAnnotations: {} + }, + ping: { + annotations: {}, + fieldAnnotations: {} + } +}; +export const methodNames: Array = ["getUser", "saveUser", "ping"]; +export interface IGetUser__Args { + id: number; +} +export interface IGetUser__ArgsArgs { + id: number; +} +export const GetUser__ArgsCodec: thrift.IStructCodec = { + encode(args: IGetUser__ArgsArgs, output: thrift.TProtocol): void { + const obj = { + id: args.id + }; + output.writeStructBegin("GetUser__Args"); + if (obj.id != null) { + output.writeFieldBegin("id", thrift.TType.I32, 1); + output.writeI32(obj.id); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[id] is unset!"); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IGetUser__Args { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IGetUser__Args { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.I32) { - const value_5: number = input.readI32(); - _args.id = value_5; - } - else { - input.skip(fieldType); - } - break; - default: { + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.I32) { + const value_5: number = input.readI32(); + _args.id = value_5; + } + else { input.skip(fieldType); } + break; + default: { + input.skip(fieldType); } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.id !== undefined) { - return { - id: _args.id - }; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read GetUser__Args from input"); } + input.readFieldEnd(); } - }; - export class GetUser__Args extends thrift.StructLike implements IGetUser__Args { - public id: number; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IGetUser__ArgsArgs) { - super(); - if (args.id != null) { - const value_6: number = args.id; - this.id = value_6; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[id] is unset!"); - } + input.readStructEnd(); + if (_args.id !== undefined) { + return { + id: _args.id + }; } - public static read(input: thrift.TProtocol): GetUser__Args { - return new GetUser__Args(GetUser__ArgsCodec.decode(input)); + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read GetUser__Args from input"); } - public static write(args: IGetUser__ArgsArgs, output: thrift.TProtocol): void { - return GetUser__ArgsCodec.encode(args, output); + } +}; +export class GetUser__Args extends thrift.StructLike implements IGetUser__Args { + public id: number; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IGetUser__ArgsArgs) { + super(); + if (args.id != null) { + const value_6: number = args.id; + this.id = value_6; } - public write(output: thrift.TProtocol): void { - return GetUser__ArgsCodec.encode(this, output); + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[id] is unset!"); } } - export interface ISaveUser__Args { - user: IUser; + public static read(input: thrift.TProtocol): GetUser__Args { + return new GetUser__Args(GetUser__ArgsCodec.decode(input)); } - export interface ISaveUser__ArgsArgs { - user: IUserArgs; + public static write(args: IGetUser__ArgsArgs, output: thrift.TProtocol): void { + return GetUser__ArgsCodec.encode(args, output); } - export const SaveUser__ArgsCodec: thrift.IStructCodec = { - encode(args: ISaveUser__ArgsArgs, output: thrift.TProtocol): void { - const obj = { - user: args.user - }; - output.writeStructBegin("SaveUser__Args"); - if (obj.user != null) { - output.writeFieldBegin("user", thrift.TType.STRUCT, 1); - UserCodec.encode(obj.user, output); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[user] is unset!"); + public write(output: thrift.TProtocol): void { + return GetUser__ArgsCodec.encode(this, output); + } +} +export interface ISaveUser__Args { + user: IUser; +} +export interface ISaveUser__ArgsArgs { + user: IUserArgs; +} +export const SaveUser__ArgsCodec: thrift.IStructCodec = { + encode(args: ISaveUser__ArgsArgs, output: thrift.TProtocol): void { + const obj = { + user: args.user + }; + output.writeStructBegin("SaveUser__Args"); + if (obj.user != null) { + output.writeFieldBegin("user", thrift.TType.STRUCT, 1); + UserCodec.encode(obj.user, output); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[user] is unset!"); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): ISaveUser__Args { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): ISaveUser__Args { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.STRUCT) { - const value_7: IUser = UserCodec.decode(input); - _args.user = value_7; - } - else { - input.skip(fieldType); - } - break; - default: { + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.STRUCT) { + const value_7: IUser = UserCodec.decode(input); + _args.user = value_7; + } + else { input.skip(fieldType); } + break; + default: { + input.skip(fieldType); } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.user !== undefined) { - return { - user: _args.user - }; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read SaveUser__Args from input"); } + input.readFieldEnd(); } - }; - export class SaveUser__Args extends thrift.StructLike implements ISaveUser__Args { - public user: IUser; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: ISaveUser__ArgsArgs) { - super(); - if (args.user != null) { - const value_8: IUser = new User(args.user); - this.user = value_8; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[user] is unset!"); - } + input.readStructEnd(); + if (_args.user !== undefined) { + return { + user: _args.user + }; } - public static read(input: thrift.TProtocol): SaveUser__Args { - return new SaveUser__Args(SaveUser__ArgsCodec.decode(input)); + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read SaveUser__Args from input"); } - public static write(args: ISaveUser__ArgsArgs, output: thrift.TProtocol): void { - return SaveUser__ArgsCodec.encode(args, output); + } +}; +export class SaveUser__Args extends thrift.StructLike implements ISaveUser__Args { + public user: IUser; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: ISaveUser__ArgsArgs) { + super(); + if (args.user != null) { + const value_8: IUser = new User(args.user); + this.user = value_8; } - public write(output: thrift.TProtocol): void { - return SaveUser__ArgsCodec.encode(this, output); + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[user] is unset!"); } } - export interface IPing__Args { + public static read(input: thrift.TProtocol): SaveUser__Args { + return new SaveUser__Args(SaveUser__ArgsCodec.decode(input)); } - export interface IPing__ArgsArgs { + public static write(args: ISaveUser__ArgsArgs, output: thrift.TProtocol): void { + return SaveUser__ArgsCodec.encode(args, output); } - export const Ping__ArgsCodec: thrift.IStructCodec = { - encode(args: IPing__ArgsArgs, output: thrift.TProtocol): void { - output.writeStructBegin("Ping__Args"); - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IPing__Args { - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - default: { - input.skip(fieldType); - } + public write(output: thrift.TProtocol): void { + return SaveUser__ArgsCodec.encode(this, output); + } +} +export interface IPing__Args { +} +export interface IPing__ArgsArgs { +} +export const Ping__ArgsCodec: thrift.IStructCodec = { + encode(args: IPing__ArgsArgs, output: thrift.TProtocol): void { + output.writeStructBegin("Ping__Args"); + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IPing__Args { + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + default: { + input.skip(fieldType); } - input.readFieldEnd(); } - input.readStructEnd(); - return {}; - } - }; - export class Ping__Args extends thrift.StructLike implements IPing__Args { - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IPing__ArgsArgs = {}) { - super(); - } - public static read(input: thrift.TProtocol): Ping__Args { - return new Ping__Args(Ping__ArgsCodec.decode(input)); - } - public static write(args: IPing__ArgsArgs, output: thrift.TProtocol): void { - return Ping__ArgsCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return Ping__ArgsCodec.encode(this, output); + input.readFieldEnd(); } + input.readStructEnd(); + return {}; } - export interface IGetUser__Result { - success?: IUser; +}; +export class Ping__Args extends thrift.StructLike implements IPing__Args { + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IPing__ArgsArgs = {}) { + super(); } - export interface IGetUser__ResultArgs { - success?: IUserArgs; + public static read(input: thrift.TProtocol): Ping__Args { + return new Ping__Args(Ping__ArgsCodec.decode(input)); } - export const GetUser__ResultCodec: thrift.IStructCodec = { - encode(args: IGetUser__ResultArgs, output: thrift.TProtocol): void { - const obj = { - success: args.success - }; - output.writeStructBegin("GetUser__Result"); - if (obj.success != null) { - output.writeFieldBegin("success", thrift.TType.STRUCT, 0); - UserCodec.encode(obj.success, output); - output.writeFieldEnd(); + public static write(args: IPing__ArgsArgs, output: thrift.TProtocol): void { + return Ping__ArgsCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return Ping__ArgsCodec.encode(this, output); + } +} +export interface IGetUser__Result { + success?: IUser; +} +export interface IGetUser__ResultArgs { + success?: IUserArgs; +} +export const GetUser__ResultCodec: thrift.IStructCodec = { + encode(args: IGetUser__ResultArgs, output: thrift.TProtocol): void { + const obj = { + success: args.success + }; + output.writeStructBegin("GetUser__Result"); + if (obj.success != null) { + output.writeFieldBegin("success", thrift.TType.STRUCT, 0); + UserCodec.encode(obj.success, output); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IGetUser__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IGetUser__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.STRUCT) { - const value_9: IUser = UserCodec.decode(input); - _args.success = value_9; - } - else { - input.skip(fieldType); - } - break; - default: { + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.STRUCT) { + const value_9: IUser = UserCodec.decode(input); + _args.success = value_9; + } + else { input.skip(fieldType); } + break; + default: { + input.skip(fieldType); } - input.readFieldEnd(); } - input.readStructEnd(); - return { - success: _args.success - }; + input.readFieldEnd(); } - }; - export class GetUser__Result extends thrift.StructLike implements IGetUser__Result { - public success?: IUser; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IGetUser__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_10: IUser = new User(args.success); - this.success = value_10; - } + input.readStructEnd(); + return { + success: _args.success + }; + } +}; +export class GetUser__Result extends thrift.StructLike implements IGetUser__Result { + public success?: IUser; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IGetUser__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_10: IUser = new User(args.success); + this.success = value_10; } - public static read(input: thrift.TProtocol): GetUser__Result { - return new GetUser__Result(GetUser__ResultCodec.decode(input)); - } - public static write(args: IGetUser__ResultArgs, output: thrift.TProtocol): void { - return GetUser__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return GetUser__ResultCodec.encode(this, output); - } - } - export interface ISaveUser__Result { - success?: void; - } - export interface ISaveUser__ResultArgs { - success?: void; - } - export const SaveUser__ResultCodec: thrift.IStructCodec = { - encode(args: ISaveUser__ResultArgs, output: thrift.TProtocol): void { - output.writeStructBegin("SaveUser__Result"); - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): ISaveUser__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.VOID) { - input.skip(fieldType); - } - else { - input.skip(fieldType); - } - break; - default: { + } + public static read(input: thrift.TProtocol): GetUser__Result { + return new GetUser__Result(GetUser__ResultCodec.decode(input)); + } + public static write(args: IGetUser__ResultArgs, output: thrift.TProtocol): void { + return GetUser__ResultCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return GetUser__ResultCodec.encode(this, output); + } +} +export interface ISaveUser__Result { + success?: void; +} +export interface ISaveUser__ResultArgs { + success?: void; +} +export const SaveUser__ResultCodec: thrift.IStructCodec = { + encode(args: ISaveUser__ResultArgs, output: thrift.TProtocol): void { + output.writeStructBegin("SaveUser__Result"); + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): ISaveUser__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.VOID) { + input.skip(fieldType); + } + else { input.skip(fieldType); } + break; + default: { + input.skip(fieldType); } - input.readFieldEnd(); } - input.readStructEnd(); - return { - success: _args.success - }; + input.readFieldEnd(); } - }; - export class SaveUser__Result extends thrift.StructLike implements ISaveUser__Result { - public success?: void; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: ISaveUser__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_11: void = undefined; - this.success = value_11; - } + input.readStructEnd(); + return { + success: _args.success + }; + } +}; +export class SaveUser__Result extends thrift.StructLike implements ISaveUser__Result { + public success?: void; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: ISaveUser__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_11: void = undefined; + this.success = value_11; } - public static read(input: thrift.TProtocol): SaveUser__Result { - return new SaveUser__Result(SaveUser__ResultCodec.decode(input)); - } - public static write(args: ISaveUser__ResultArgs, output: thrift.TProtocol): void { - return SaveUser__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return SaveUser__ResultCodec.encode(this, output); - } - } - export interface IPing__Result { - success?: void; - } - export interface IPing__ResultArgs { - success?: void; - } - export const Ping__ResultCodec: thrift.IStructCodec = { - encode(args: IPing__ResultArgs, output: thrift.TProtocol): void { - output.writeStructBegin("Ping__Result"); - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IPing__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.VOID) { - input.skip(fieldType); - } - else { - input.skip(fieldType); - } - break; - default: { + } + public static read(input: thrift.TProtocol): SaveUser__Result { + return new SaveUser__Result(SaveUser__ResultCodec.decode(input)); + } + public static write(args: ISaveUser__ResultArgs, output: thrift.TProtocol): void { + return SaveUser__ResultCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return SaveUser__ResultCodec.encode(this, output); + } +} +export interface IPing__Result { + success?: void; +} +export interface IPing__ResultArgs { + success?: void; +} +export const Ping__ResultCodec: thrift.IStructCodec = { + encode(args: IPing__ResultArgs, output: thrift.TProtocol): void { + output.writeStructBegin("Ping__Result"); + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IPing__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.VOID) { + input.skip(fieldType); + } + else { input.skip(fieldType); } + break; + default: { + input.skip(fieldType); } - input.readFieldEnd(); } - input.readStructEnd(); - return { - success: _args.success - }; + input.readFieldEnd(); } - }; - export class Ping__Result extends thrift.StructLike implements IPing__Result { - public success?: void; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IPing__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_12: void = undefined; - this.success = value_12; - } + input.readStructEnd(); + return { + success: _args.success + }; + } +}; +export class Ping__Result extends thrift.StructLike implements IPing__Result { + public success?: void; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IPing__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_12: void = undefined; + this.success = value_12; } - public static read(input: thrift.TProtocol): Ping__Result { - return new Ping__Result(Ping__ResultCodec.decode(input)); - } - public static write(args: IPing__ResultArgs, output: thrift.TProtocol): void { - return Ping__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return Ping__ResultCodec.encode(this, output); - } - } - export class Client extends thrift.ThriftClient { - public static readonly serviceName: string = serviceName; - public static readonly annotations: thrift.IThriftAnnotations = annotations; - public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public static readonly methodNames: Array = methodNames; - public readonly _serviceName: string = serviceName; - public readonly _annotations: thrift.IThriftAnnotations = annotations; - public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public readonly _methodNames: Array = methodNames; - public getUser(id: number, context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("getUser", thrift.MessageType.CALL, this.incrementRequestId()); - const args: IGetUser__ArgsArgs = { id }; - GetUser__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "getUser") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: IGetUser__Result = GetUser__ResultCodec.decode(input); - input.readMessageEnd(); - if (result.success != null) { - return Promise.resolve(result.success); - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "getUser failed: unknown result")); - } - } + } + public static read(input: thrift.TProtocol): Ping__Result { + return new Ping__Result(Ping__ResultCodec.decode(input)); + } + public static write(args: IPing__ResultArgs, output: thrift.TProtocol): void { + return Ping__ResultCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return Ping__ResultCodec.encode(this, output); + } +} +export class Client extends thrift.ThriftClient { + public static readonly serviceName: string = serviceName; + public static readonly annotations: thrift.IThriftAnnotations = annotations; + public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public static readonly methodNames: Array = methodNames; + public readonly _serviceName: string = serviceName; + public readonly _annotations: thrift.IThriftAnnotations = annotations; + public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public readonly _methodNames: Array = methodNames; + public getUser(id: number, context?: Context): Promise { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("getUser", thrift.MessageType.CALL, this.incrementRequestId()); + const args: IGetUser__ArgsArgs = { id }; + GetUser__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "getUser") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); } else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } - } - catch (err) { - return Promise.reject(err); - } - }); - } - public saveUser(user: IUserArgs, context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("saveUser", thrift.MessageType.CALL, this.incrementRequestId()); - const args: ISaveUser__ArgsArgs = { user }; - SaveUser__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "saveUser") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); + const result: IGetUser__Result = GetUser__ResultCodec.decode(input); + input.readMessageEnd(); + if (result.success != null) { + return Promise.resolve(result.success); } else { - const result: ISaveUser__Result = SaveUser__ResultCodec.decode(input); - input.readMessageEnd(); - return Promise.resolve(result.success); + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "getUser failed: unknown result")); } } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } } - catch (err) { - return Promise.reject(err); + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); } - }); - } - public ping(context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("ping", thrift.MessageType.CALL, this.incrementRequestId()); - const args: IPing__ArgsArgs = {}; - Ping__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "ping") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: IPing__Result = Ping__ResultCodec.decode(input); - input.readMessageEnd(); - return Promise.resolve(result.success); - } + } + catch (err) { + return Promise.reject(err); + } + }); + } + public saveUser(user: IUserArgs, context?: Context): Promise { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("saveUser", thrift.MessageType.CALL, this.incrementRequestId()); + const args: ISaveUser__ArgsArgs = { user }; + SaveUser__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "saveUser") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); } else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); + const result: ISaveUser__Result = SaveUser__ResultCodec.decode(input); + input.readMessageEnd(); + return Promise.resolve(result.success); } } - catch (err) { - return Promise.reject(err); + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); } - }); - } - } - export interface IHandler { - getUser(id: number, context?: Context): IUserArgs | Promise; - saveUser(user: IUser, context?: Context): void | Promise; - ping(context?: Context): void | Promise; - } - export class Processor extends thrift.ThriftProcessor> { - protected readonly _handler: IHandler; - public static readonly serviceName: string = serviceName; - public static readonly annotations: thrift.IThriftAnnotations = annotations; - public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public static readonly methodNames: Array = methodNames; - public readonly _serviceName: string = serviceName; - public readonly _annotations: thrift.IThriftAnnotations = annotations; - public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public readonly _methodNames: Array = methodNames; - constructor(handler: IHandler) { - super(); - this._handler = handler; - } - public process(input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - const metadata: thrift.IThriftMessage = input.readMessageBegin(); - const fieldName: string = metadata.fieldName; - const requestId: number = metadata.requestId; - const methodName: string = "process_" + fieldName; - switch (methodName) { - case "process_getUser": { - resolve(this.process_getUser(requestId, input, output, context)); - break; - } - case "process_saveUser": { - resolve(this.process_saveUser(requestId, input, output, context)); - break; - } - case "process_ping": { - resolve(this.process_ping(requestId, input, output, context)); - break; + } + catch (err) { + return Promise.reject(err); + } + }); + } + public ping(context?: Context): Promise { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("ping", thrift.MessageType.CALL, this.incrementRequestId()); + const args: IPing__ArgsArgs = {}; + Ping__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "ping") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); } - default: { - input.skip(thrift.TType.STRUCT); + else { + const result: IPing__Result = Ping__ResultCodec.decode(input); input.readMessageEnd(); - const errMessage = "Unknown function " + fieldName; - const err = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN_METHOD, errMessage); - output.writeMessageBegin(fieldName, thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(err, output); - output.writeMessageEnd(); - resolve(output.flush()); - break; + return Promise.resolve(result.success); } } - }); - } - public process_getUser(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { - const args: IGetUser__Args = GetUser__ArgsCodec.decode(input); - input.readMessageEnd(); - resolve(this._handler.getUser(args.id, context)); + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); } - catch (err) { - reject(err); + } + catch (err) { + return Promise.reject(err); + } + }); + } +} +export interface IHandler { + getUser(id: number, context?: Context): IUserArgs | Promise; + saveUser(user: IUser, context?: Context): void | Promise; + ping(context?: Context): void | Promise; +} +export class Processor extends thrift.ThriftProcessor> { + protected readonly _handler: IHandler; + public static readonly serviceName: string = serviceName; + public static readonly annotations: thrift.IThriftAnnotations = annotations; + public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public static readonly methodNames: Array = methodNames; + public readonly _serviceName: string = serviceName; + public readonly _annotations: thrift.IThriftAnnotations = annotations; + public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public readonly _methodNames: Array = methodNames; + constructor(handler: IHandler) { + super(); + this._handler = handler; + } + public process(input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + const metadata: thrift.IThriftMessage = input.readMessageBegin(); + const fieldName: string = metadata.fieldName; + const requestId: number = metadata.requestId; + const methodName: string = "process_" + fieldName; + switch (methodName) { + case "process_getUser": { + resolve(this.process_getUser(requestId, input, output, context)); + break; } - }).then((data: IUserArgs): Buffer => { - const result: IGetUser__ResultArgs = { success: data }; - output.writeMessageBegin("getUser", thrift.MessageType.REPLY, requestId); - GetUser__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("getUser", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } - public process_saveUser(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { - const args: ISaveUser__Args = SaveUser__ArgsCodec.decode(input); - input.readMessageEnd(); - resolve(this._handler.saveUser(args.user, context)); + case "process_saveUser": { + resolve(this.process_saveUser(requestId, input, output, context)); + break; } - catch (err) { - reject(err); + case "process_ping": { + resolve(this.process_ping(requestId, input, output, context)); + break; } - }).then((data: void): Buffer => { - const result: ISaveUser__ResultArgs = { success: data }; - output.writeMessageBegin("saveUser", thrift.MessageType.REPLY, requestId); - SaveUser__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("saveUser", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } - public process_ping(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { + default: { + input.skip(thrift.TType.STRUCT); input.readMessageEnd(); - resolve(this._handler.ping(context)); - } - catch (err) { - reject(err); + const errMessage = "Unknown function " + fieldName; + const err = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN_METHOD, errMessage); + output.writeMessageBegin(fieldName, thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(err, output); + output.writeMessageEnd(); + resolve(output.flush()); + break; } - }).then((data: void): Buffer => { - const result: IPing__ResultArgs = { success: data }; - output.writeMessageBegin("ping", thrift.MessageType.REPLY, requestId); - Ping__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("ping", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } + } + }); + } + public process_getUser(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + try { + const args: IGetUser__Args = GetUser__ArgsCodec.decode(input); + input.readMessageEnd(); + resolve(this._handler.getUser(args.id, context)); + } + catch (err) { + reject(err); + } + }).then((data: IUserArgs): Buffer => { + const result: IGetUser__ResultArgs = { success: data }; + output.writeMessageBegin("getUser", thrift.MessageType.REPLY, requestId); + GetUser__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("getUser", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }); + } + public process_saveUser(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + try { + const args: ISaveUser__Args = SaveUser__ArgsCodec.decode(input); + input.readMessageEnd(); + resolve(this._handler.saveUser(args.user, context)); + } + catch (err) { + reject(err); + } + }).then((data: void): Buffer => { + const result: ISaveUser__ResultArgs = { success: data }; + output.writeMessageBegin("saveUser", thrift.MessageType.REPLY, requestId); + SaveUser__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("saveUser", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }); + } + public process_ping(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + try { + input.readMessageEnd(); + resolve(this._handler.ping(context)); + } + catch (err) { + reject(err); + } + }).then((data: void): Buffer => { + const result: IPing__ResultArgs = { success: data }; + output.writeMessageBegin("ping", thrift.MessageType.REPLY, requestId); + Ping__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("ping", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }); } } diff --git a/src/tests/unit/fixtures/thrift-server/basic_service.strict_union.solution.ts b/src/tests/unit/fixtures/thrift-server/basic_service.strict_union.solution.ts index 72061a35..e09ccc1e 100644 --- a/src/tests/unit/fixtures/thrift-server/basic_service.strict_union.solution.ts +++ b/src/tests/unit/fixtures/thrift-server/basic_service.strict_union.solution.ts @@ -6,20 +6,20 @@ export type MyUnion = IMyUnionWithField1 | IMyUnionWithField2; export interface IMyUnionWithField1 { __type: MyUnionType.MyUnionWithField1; field1: number; - field2?: void; + field2?: undefined; } export interface IMyUnionWithField2 { __type: MyUnionType.MyUnionWithField2; - field1?: void; + field1?: undefined; field2: thrift.Int64; } export type MyUnionArgs = IMyUnionWithField1Args | IMyUnionWithField2Args; export interface IMyUnionWithField1Args { field1: number; - field2?: void; + field2?: undefined; } export interface IMyUnionWithField2Args { - field1?: void; + field1?: undefined; field2: number | string | thrift.Int64; } export const MyUnionCodec: thrift.IStructToolkit = { @@ -153,465 +153,463 @@ export const MyUnionCodec: thrift.IStructToolkit = { } } }; -export namespace MyService { - export const serviceName: string = "MyService"; - export const annotations: thrift.IThriftAnnotations = {}; - export const methodAnnotations: thrift.IMethodAnnotations = { - getUser: { - annotations: {}, - fieldAnnotations: {} - }, - ping: { - annotations: {}, - fieldAnnotations: {} - } - }; - export const methodNames: Array = ["getUser", "ping"]; - export interface IGetUser__Args { - arg1: MyUnion; - } - export interface IGetUser__ArgsArgs { - arg1: MyUnionArgs; +export const serviceName: string = "MyService"; +export const annotations: thrift.IThriftAnnotations = {}; +export const methodAnnotations: thrift.IMethodAnnotations = { + getUser: { + annotations: {}, + fieldAnnotations: {} + }, + ping: { + annotations: {}, + fieldAnnotations: {} } - export const GetUser__ArgsCodec: thrift.IStructCodec = { - encode(args: IGetUser__ArgsArgs, output: thrift.TProtocol): void { - const obj = { - arg1: args.arg1 - }; - output.writeStructBegin("GetUser__Args"); - if (obj.arg1 != null) { - output.writeFieldBegin("arg1", thrift.TType.STRUCT, 1); - MyUnionCodec.encode(obj.arg1, output); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[arg1] is unset!"); +}; +export const methodNames: Array = ["getUser", "ping"]; +export interface IGetUser__Args { + arg1: MyUnion; +} +export interface IGetUser__ArgsArgs { + arg1: MyUnionArgs; +} +export const GetUser__ArgsCodec: thrift.IStructCodec = { + encode(args: IGetUser__ArgsArgs, output: thrift.TProtocol): void { + const obj = { + arg1: args.arg1 + }; + output.writeStructBegin("GetUser__Args"); + if (obj.arg1 != null) { + output.writeFieldBegin("arg1", thrift.TType.STRUCT, 1); + MyUnionCodec.encode(obj.arg1, output); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[arg1] is unset!"); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IGetUser__Args { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IGetUser__Args { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.STRUCT) { - const value_5: MyUnion = MyUnionCodec.decode(input); - _args.arg1 = value_5; - } - else { - input.skip(fieldType); - } - break; - default: { + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.STRUCT) { + const value_5: MyUnion = MyUnionCodec.decode(input); + _args.arg1 = value_5; + } + else { input.skip(fieldType); } + break; + default: { + input.skip(fieldType); } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.arg1 !== undefined) { - return { - arg1: _args.arg1 - }; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read GetUser__Args from input"); } + input.readFieldEnd(); } - }; - export class GetUser__Args extends thrift.StructLike implements IGetUser__Args { - public arg1: MyUnion; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IGetUser__ArgsArgs) { - super(); - if (args.arg1 != null) { - const value_6: MyUnion = MyUnionCodec.create(args.arg1); - this.arg1 = value_6; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[arg1] is unset!"); - } + input.readStructEnd(); + if (_args.arg1 !== undefined) { + return { + arg1: _args.arg1 + }; } - public static read(input: thrift.TProtocol): GetUser__Args { - return new GetUser__Args(GetUser__ArgsCodec.decode(input)); + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read GetUser__Args from input"); } - public static write(args: IGetUser__ArgsArgs, output: thrift.TProtocol): void { - return GetUser__ArgsCodec.encode(args, output); + } +}; +export class GetUser__Args extends thrift.StructLike implements IGetUser__Args { + public arg1: MyUnion; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IGetUser__ArgsArgs) { + super(); + if (args.arg1 != null) { + const value_6: MyUnion = MyUnionCodec.create(args.arg1); + this.arg1 = value_6; } - public write(output: thrift.TProtocol): void { - return GetUser__ArgsCodec.encode(this, output); + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[arg1] is unset!"); } } - export interface IPing__Args { + public static read(input: thrift.TProtocol): GetUser__Args { + return new GetUser__Args(GetUser__ArgsCodec.decode(input)); } - export interface IPing__ArgsArgs { + public static write(args: IGetUser__ArgsArgs, output: thrift.TProtocol): void { + return GetUser__ArgsCodec.encode(args, output); } - export const Ping__ArgsCodec: thrift.IStructCodec = { - encode(args: IPing__ArgsArgs, output: thrift.TProtocol): void { - output.writeStructBegin("Ping__Args"); - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IPing__Args { - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - default: { - input.skip(fieldType); - } + public write(output: thrift.TProtocol): void { + return GetUser__ArgsCodec.encode(this, output); + } +} +export interface IPing__Args { +} +export interface IPing__ArgsArgs { +} +export const Ping__ArgsCodec: thrift.IStructCodec = { + encode(args: IPing__ArgsArgs, output: thrift.TProtocol): void { + output.writeStructBegin("Ping__Args"); + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IPing__Args { + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + default: { + input.skip(fieldType); } - input.readFieldEnd(); } - input.readStructEnd(); - return {}; - } - }; - export class Ping__Args extends thrift.StructLike implements IPing__Args { - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IPing__ArgsArgs = {}) { - super(); - } - public static read(input: thrift.TProtocol): Ping__Args { - return new Ping__Args(Ping__ArgsCodec.decode(input)); - } - public static write(args: IPing__ArgsArgs, output: thrift.TProtocol): void { - return Ping__ArgsCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return Ping__ArgsCodec.encode(this, output); + input.readFieldEnd(); } + input.readStructEnd(); + return {}; } - export interface IGetUser__Result { - success?: string; +}; +export class Ping__Args extends thrift.StructLike implements IPing__Args { + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IPing__ArgsArgs = {}) { + super(); } - export interface IGetUser__ResultArgs { - success?: string; + public static read(input: thrift.TProtocol): Ping__Args { + return new Ping__Args(Ping__ArgsCodec.decode(input)); } - export const GetUser__ResultCodec: thrift.IStructCodec = { - encode(args: IGetUser__ResultArgs, output: thrift.TProtocol): void { - const obj = { - success: args.success - }; - output.writeStructBegin("GetUser__Result"); - if (obj.success != null) { - output.writeFieldBegin("success", thrift.TType.STRING, 0); - output.writeString(obj.success); - output.writeFieldEnd(); + public static write(args: IPing__ArgsArgs, output: thrift.TProtocol): void { + return Ping__ArgsCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return Ping__ArgsCodec.encode(this, output); + } +} +export interface IGetUser__Result { + success?: string; +} +export interface IGetUser__ResultArgs { + success?: string; +} +export const GetUser__ResultCodec: thrift.IStructCodec = { + encode(args: IGetUser__ResultArgs, output: thrift.TProtocol): void { + const obj = { + success: args.success + }; + output.writeStructBegin("GetUser__Result"); + if (obj.success != null) { + output.writeFieldBegin("success", thrift.TType.STRING, 0); + output.writeString(obj.success); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IGetUser__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IGetUser__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.STRING) { - const value_7: string = input.readString(); - _args.success = value_7; - } - else { - input.skip(fieldType); - } - break; - default: { + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.STRING) { + const value_7: string = input.readString(); + _args.success = value_7; + } + else { input.skip(fieldType); } + break; + default: { + input.skip(fieldType); } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - success: _args.success - }; - } - }; - export class GetUser__Result extends thrift.StructLike implements IGetUser__Result { - public success?: string; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IGetUser__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_8: string = args.success; - this.success = value_8; } + input.readFieldEnd(); } - public static read(input: thrift.TProtocol): GetUser__Result { - return new GetUser__Result(GetUser__ResultCodec.decode(input)); - } - public static write(args: IGetUser__ResultArgs, output: thrift.TProtocol): void { - return GetUser__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return GetUser__ResultCodec.encode(this, output); + input.readStructEnd(); + return { + success: _args.success + }; + } +}; +export class GetUser__Result extends thrift.StructLike implements IGetUser__Result { + public success?: string; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IGetUser__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_8: string = args.success; + this.success = value_8; } } - export interface IPing__Result { - success?: void; + public static read(input: thrift.TProtocol): GetUser__Result { + return new GetUser__Result(GetUser__ResultCodec.decode(input)); } - export interface IPing__ResultArgs { - success?: void; + public static write(args: IGetUser__ResultArgs, output: thrift.TProtocol): void { + return GetUser__ResultCodec.encode(args, output); } - export const Ping__ResultCodec: thrift.IStructCodec = { - encode(args: IPing__ResultArgs, output: thrift.TProtocol): void { - output.writeStructBegin("Ping__Result"); - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IPing__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.VOID) { - input.skip(fieldType); - } - else { - input.skip(fieldType); - } - break; - default: { + public write(output: thrift.TProtocol): void { + return GetUser__ResultCodec.encode(this, output); + } +} +export interface IPing__Result { + success?: void; +} +export interface IPing__ResultArgs { + success?: void; +} +export const Ping__ResultCodec: thrift.IStructCodec = { + encode(args: IPing__ResultArgs, output: thrift.TProtocol): void { + output.writeStructBegin("Ping__Result"); + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IPing__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.VOID) { + input.skip(fieldType); + } + else { input.skip(fieldType); } + break; + default: { + input.skip(fieldType); } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - success: _args.success - }; - } - }; - export class Ping__Result extends thrift.StructLike implements IPing__Result { - public success?: void; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IPing__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_9: void = undefined; - this.success = value_9; } + input.readFieldEnd(); } - public static read(input: thrift.TProtocol): Ping__Result { - return new Ping__Result(Ping__ResultCodec.decode(input)); - } - public static write(args: IPing__ResultArgs, output: thrift.TProtocol): void { - return Ping__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return Ping__ResultCodec.encode(this, output); + input.readStructEnd(); + return { + success: _args.success + }; + } +}; +export class Ping__Result extends thrift.StructLike implements IPing__Result { + public success?: void; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IPing__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_9: void = undefined; + this.success = value_9; } } - export class Client extends thrift.ThriftClient { - public static readonly serviceName: string = serviceName; - public static readonly annotations: thrift.IThriftAnnotations = annotations; - public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public static readonly methodNames: Array = methodNames; - public readonly _serviceName: string = serviceName; - public readonly _annotations: thrift.IThriftAnnotations = annotations; - public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public readonly _methodNames: Array = methodNames; - public getUser(arg1: MyUnionArgs, context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("getUser", thrift.MessageType.CALL, this.incrementRequestId()); - const args: IGetUser__ArgsArgs = { arg1 }; - GetUser__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "getUser") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: IGetUser__Result = GetUser__ResultCodec.decode(input); - input.readMessageEnd(); - if (result.success != null) { - return Promise.resolve(result.success); - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "getUser failed: unknown result")); - } - } + public static read(input: thrift.TProtocol): Ping__Result { + return new Ping__Result(Ping__ResultCodec.decode(input)); + } + public static write(args: IPing__ResultArgs, output: thrift.TProtocol): void { + return Ping__ResultCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return Ping__ResultCodec.encode(this, output); + } +} +export class Client extends thrift.ThriftClient { + public static readonly serviceName: string = serviceName; + public static readonly annotations: thrift.IThriftAnnotations = annotations; + public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public static readonly methodNames: Array = methodNames; + public readonly _serviceName: string = serviceName; + public readonly _annotations: thrift.IThriftAnnotations = annotations; + public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public readonly _methodNames: Array = methodNames; + public getUser(arg1: MyUnionArgs, context?: Context): Promise { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("getUser", thrift.MessageType.CALL, this.incrementRequestId()); + const args: IGetUser__ArgsArgs = { arg1 }; + GetUser__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "getUser") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); } else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } - } - catch (err) { - return Promise.reject(err); - } - }); - } - public ping(context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("ping", thrift.MessageType.CALL, this.incrementRequestId()); - const args: IPing__ArgsArgs = {}; - Ping__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "ping") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); + const result: IGetUser__Result = GetUser__ResultCodec.decode(input); + input.readMessageEnd(); + if (result.success != null) { + return Promise.resolve(result.success); } else { - const result: IPing__Result = Ping__ResultCodec.decode(input); - input.readMessageEnd(); - return Promise.resolve(result.success); + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "getUser failed: unknown result")); } } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } } - catch (err) { - return Promise.reject(err); + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); } - }); - } - } - export interface IHandler { - getUser(arg1: MyUnion, context?: Context): string | Promise; - ping(context?: Context): void | Promise; + } + catch (err) { + return Promise.reject(err); + } + }); } - export class Processor extends thrift.ThriftProcessor> { - protected readonly _handler: IHandler; - public static readonly serviceName: string = serviceName; - public static readonly annotations: thrift.IThriftAnnotations = annotations; - public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public static readonly methodNames: Array = methodNames; - public readonly _serviceName: string = serviceName; - public readonly _annotations: thrift.IThriftAnnotations = annotations; - public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public readonly _methodNames: Array = methodNames; - constructor(handler: IHandler) { - super(); - this._handler = handler; - } - public process(input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - const metadata: thrift.IThriftMessage = input.readMessageBegin(); - const fieldName: string = metadata.fieldName; - const requestId: number = metadata.requestId; - const methodName: string = "process_" + fieldName; - switch (methodName) { - case "process_getUser": { - resolve(this.process_getUser(requestId, input, output, context)); - break; - } - case "process_ping": { - resolve(this.process_ping(requestId, input, output, context)); - break; + public ping(context?: Context): Promise { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("ping", thrift.MessageType.CALL, this.incrementRequestId()); + const args: IPing__ArgsArgs = {}; + Ping__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "ping") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); } - default: { - input.skip(thrift.TType.STRUCT); + else { + const result: IPing__Result = Ping__ResultCodec.decode(input); input.readMessageEnd(); - const errMessage = "Unknown function " + fieldName; - const err = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN_METHOD, errMessage); - output.writeMessageBegin(fieldName, thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(err, output); - output.writeMessageEnd(); - resolve(output.flush()); - break; + return Promise.resolve(result.success); } } - }); - } - public process_getUser(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { - const args: IGetUser__Args = GetUser__ArgsCodec.decode(input); - input.readMessageEnd(); - resolve(this._handler.getUser(args.arg1, context)); + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); + } + } + catch (err) { + return Promise.reject(err); + } + }); + } +} +export interface IHandler { + getUser(arg1: MyUnion, context?: Context): string | Promise; + ping(context?: Context): void | Promise; +} +export class Processor extends thrift.ThriftProcessor> { + protected readonly _handler: IHandler; + public static readonly serviceName: string = serviceName; + public static readonly annotations: thrift.IThriftAnnotations = annotations; + public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public static readonly methodNames: Array = methodNames; + public readonly _serviceName: string = serviceName; + public readonly _annotations: thrift.IThriftAnnotations = annotations; + public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public readonly _methodNames: Array = methodNames; + constructor(handler: IHandler) { + super(); + this._handler = handler; + } + public process(input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + const metadata: thrift.IThriftMessage = input.readMessageBegin(); + const fieldName: string = metadata.fieldName; + const requestId: number = metadata.requestId; + const methodName: string = "process_" + fieldName; + switch (methodName) { + case "process_getUser": { + resolve(this.process_getUser(requestId, input, output, context)); + break; } - catch (err) { - reject(err); + case "process_ping": { + resolve(this.process_ping(requestId, input, output, context)); + break; } - }).then((data: string): Buffer => { - const result: IGetUser__ResultArgs = { success: data }; - output.writeMessageBegin("getUser", thrift.MessageType.REPLY, requestId); - GetUser__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("getUser", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } - public process_ping(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { + default: { + input.skip(thrift.TType.STRUCT); input.readMessageEnd(); - resolve(this._handler.ping(context)); - } - catch (err) { - reject(err); + const errMessage = "Unknown function " + fieldName; + const err = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN_METHOD, errMessage); + output.writeMessageBegin(fieldName, thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(err, output); + output.writeMessageEnd(); + resolve(output.flush()); + break; } - }).then((data: void): Buffer => { - const result: IPing__ResultArgs = { success: data }; - output.writeMessageBegin("ping", thrift.MessageType.REPLY, requestId); - Ping__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("ping", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } + } + }); + } + public process_getUser(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + try { + const args: IGetUser__Args = GetUser__ArgsCodec.decode(input); + input.readMessageEnd(); + resolve(this._handler.getUser(args.arg1, context)); + } + catch (err) { + reject(err); + } + }).then((data: string): Buffer => { + const result: IGetUser__ResultArgs = { success: data }; + output.writeMessageBegin("getUser", thrift.MessageType.REPLY, requestId); + GetUser__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("getUser", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }); + } + public process_ping(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + try { + input.readMessageEnd(); + resolve(this._handler.ping(context)); + } + catch (err) { + reject(err); + } + }).then((data: void): Buffer => { + const result: IPing__ResultArgs = { success: data }; + output.writeMessageBegin("ping", thrift.MessageType.REPLY, requestId); + Ping__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("ping", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }); } } diff --git a/src/tests/unit/fixtures/thrift-server/basic_struct.solution.ts b/src/tests/unit/fixtures/thrift-server/basic_struct.solution.ts new file mode 100644 index 00000000..6eb73b31 --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/basic_struct.solution.ts @@ -0,0 +1,177 @@ +export interface IMyStruct { + id: number; + bigID: thrift.Int64; + word: string; + field1?: number; + blob?: Buffer; +} +export interface IMyStructArgs { + id?: number; + bigID?: number | string | thrift.Int64; + word: string; + field1?: number; + blob?: string | Buffer; +} +export const MyStructCodec: thrift.IStructCodec = { + encode(args: IMyStructArgs, output: thrift.TProtocol): void { + const obj = { + id: (args.id != null ? args.id : 45), + bigID: (args.bigID != null ? (typeof args.bigID === "number" ? new thrift.Int64(args.bigID) : typeof args.bigID === "string" ? thrift.Int64.fromDecimalString(args.bigID) : args.bigID) : thrift.Int64.fromDecimalString("23948234")), + word: args.word, + field1: args.field1, + blob: (args.blob != null ? (typeof args.blob === "string" ? Buffer.from(args.blob) : args.blob) : Buffer.from("binary")) + }; + output.writeStructBegin("MyStruct"); + if (obj.id != null) { + output.writeFieldBegin("id", thrift.TType.I32, 1); + output.writeI32(obj.id); + output.writeFieldEnd(); + } + if (obj.bigID != null) { + output.writeFieldBegin("bigID", thrift.TType.I64, 2); + output.writeI64((typeof obj.bigID === "number" ? new thrift.Int64(obj.bigID) : typeof obj.bigID === "string" ? thrift.Int64.fromDecimalString(obj.bigID) : obj.bigID)); + output.writeFieldEnd(); + } + if (obj.word != null) { + output.writeFieldBegin("word", thrift.TType.STRING, 3); + output.writeString(obj.word); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[word] is unset!"); + } + if (obj.field1 != null) { + output.writeFieldBegin("field1", thrift.TType.DOUBLE, 4); + output.writeDouble(obj.field1); + output.writeFieldEnd(); + } + if (obj.blob != null) { + output.writeFieldBegin("blob", thrift.TType.STRING, 5); + output.writeBinary(obj.blob); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IMyStruct { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.I32) { + const value_1: number = input.readI32(); + _args.id = value_1; + } + else { + input.skip(fieldType); + } + break; + case 2: + if (fieldType === thrift.TType.I64) { + const value_2: thrift.Int64 = input.readI64(); + _args.bigID = value_2; + } + else { + input.skip(fieldType); + } + break; + case 3: + if (fieldType === thrift.TType.STRING) { + const value_3: string = input.readString(); + _args.word = value_3; + } + else { + input.skip(fieldType); + } + break; + case 4: + if (fieldType === thrift.TType.DOUBLE) { + const value_4: number = input.readDouble(); + _args.field1 = value_4; + } + else { + input.skip(fieldType); + } + break; + case 5: + if (fieldType === thrift.TType.STRING) { + const value_5: Buffer = input.readBinary(); + _args.blob = value_5; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.id !== undefined && _args.bigID !== undefined && _args.word !== undefined) { + return { + id: (_args.id != null ? _args.id : 45), + bigID: (_args.bigID != null ? _args.bigID : thrift.Int64.fromDecimalString("23948234")), + word: _args.word, + field1: _args.field1, + blob: (_args.blob != null ? _args.blob : Buffer.from("binary")) + }; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read MyStruct from input"); + } + } +}; +export class MyStruct extends thrift.StructLike implements IMyStruct { + public id: number = 45; + public bigID: thrift.Int64 = thrift.Int64.fromDecimalString("23948234"); + public word: string; + public field1?: number; + public blob?: Buffer = Buffer.from("binary"); + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IMyStructArgs) { + super(); + if (args.id != null) { + const value_6: number = args.id; + this.id = value_6; + } + if (args.bigID != null) { + const value_7: thrift.Int64 = (typeof args.bigID === "number" ? new thrift.Int64(args.bigID) : typeof args.bigID === "string" ? thrift.Int64.fromDecimalString(args.bigID) : args.bigID); + this.bigID = value_7; + } + if (args.word != null) { + const value_8: string = args.word; + this.word = value_8; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[word] is unset!"); + } + if (args.field1 != null) { + const value_9: number = args.field1; + this.field1 = value_9; + } + if (args.blob != null) { + const value_10: Buffer = (typeof args.blob === "string" ? Buffer.from(args.blob) : args.blob); + this.blob = value_10; + } + } + public static read(input: thrift.TProtocol): MyStruct { + return new MyStruct(MyStructCodec.decode(input)); + } + public static write(args: IMyStructArgs, output: thrift.TProtocol): void { + return MyStructCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return MyStructCodec.encode(this, output); + } +} diff --git a/src/tests/unit/fixtures/thrift-server/basic_typedef.solution.ts b/src/tests/unit/fixtures/thrift-server/basic_typedef.solution.ts new file mode 100644 index 00000000..6192c336 --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/basic_typedef.solution.ts @@ -0,0 +1,2 @@ +export type NUM_TYPE = number; +export type name = NUM_TYPE; diff --git a/src/tests/unit/fixtures/thrift-server/basic_union.solution.ts b/src/tests/unit/fixtures/thrift-server/basic_union.solution.ts index ebdc0b95..c1ebe9dd 100644 --- a/src/tests/unit/fixtures/thrift-server/basic_union.solution.ts +++ b/src/tests/unit/fixtures/thrift-server/basic_union.solution.ts @@ -1,29 +1,29 @@ export interface IMyUnion { - field1?: number; - field2?: thrift.Int64; + option1?: string; + option2?: thrift.Int64; } export interface IMyUnionArgs { - field1?: number; - field2?: number | string | thrift.Int64; + option1?: string; + option2?: number | string | thrift.Int64; } export const MyUnionCodec: thrift.IStructCodec = { encode(args: IMyUnionArgs, output: thrift.TProtocol): void { let _fieldsSet: number = 0; const obj = { - field1: args.field1, - field2: (typeof args.field2 === "number" ? new thrift.Int64(args.field2) : typeof args.field2 === "string" ? thrift.Int64.fromDecimalString(args.field2) : args.field2) + option1: args.option1, + option2: (typeof args.option2 === "number" ? new thrift.Int64(args.option2) : typeof args.option2 === "string" ? thrift.Int64.fromDecimalString(args.option2) : args.option2) }; output.writeStructBegin("MyUnion"); - if (obj.field1 != null) { + if (obj.option1 != null) { _fieldsSet++; - output.writeFieldBegin("field1", thrift.TType.I32, 1); - output.writeI32(obj.field1); + output.writeFieldBegin("option1", thrift.TType.STRING, 1); + output.writeString(obj.option1); output.writeFieldEnd(); } - if (obj.field2 != null) { + if (obj.option2 != null) { _fieldsSet++; - output.writeFieldBegin("field2", thrift.TType.I64, 2); - output.writeI64((typeof obj.field2 === "number" ? new thrift.Int64(obj.field2) : typeof obj.field2 === "string" ? thrift.Int64.fromDecimalString(obj.field2) : obj.field2)); + output.writeFieldBegin("option2", thrift.TType.I64, 2); + output.writeI64((typeof obj.option2 === "number" ? new thrift.Int64(obj.option2) : typeof obj.option2 === "string" ? thrift.Int64.fromDecimalString(obj.option2) : obj.option2)); output.writeFieldEnd(); } output.writeFieldStop(); @@ -49,10 +49,10 @@ export const MyUnionCodec: thrift.IStructCodec = { } switch (fieldId) { case 1: - if (fieldType === thrift.TType.I32) { + if (fieldType === thrift.TType.STRING) { _fieldsSet++; - const value_1: number = input.readI32(); - _returnValue = { field1: value_1 }; + const value_1: string = input.readString(); + _returnValue = { option1: value_1 }; } else { input.skip(fieldType); @@ -62,7 +62,7 @@ export const MyUnionCodec: thrift.IStructCodec = { if (fieldType === thrift.TType.I64) { _fieldsSet++; const value_2: thrift.Int64 = input.readI64(); - _returnValue = { field2: value_2 }; + _returnValue = { option2: value_2 }; } else { input.skip(fieldType); @@ -90,22 +90,22 @@ export const MyUnionCodec: thrift.IStructCodec = { } }; export class MyUnion extends thrift.StructLike implements IMyUnion { - public field1?: number; - public field2?: thrift.Int64; + public option1?: string; + public option2?: thrift.Int64; public readonly _annotations: thrift.IThriftAnnotations = {}; public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; constructor(args: IMyUnionArgs = {}) { super(); let _fieldsSet: number = 0; - if (args.field1 != null) { + if (args.option1 != null) { _fieldsSet++; - const value_3: number = args.field1; - this.field1 = value_3; + const value_3: string = args.option1; + this.option1 = value_3; } - if (args.field2 != null) { + if (args.option2 != null) { _fieldsSet++; - const value_4: thrift.Int64 = (typeof args.field2 === "number" ? new thrift.Int64(args.field2) : typeof args.field2 === "string" ? thrift.Int64.fromDecimalString(args.field2) : args.field2); - this.field2 = value_4; + const value_4: thrift.Int64 = (typeof args.option2 === "number" ? new thrift.Int64(args.option2) : typeof args.option2 === "string" ? thrift.Int64.fromDecimalString(args.option2) : args.option2); + this.option2 = value_4; } if (_fieldsSet > 1) { throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion cannot have more than one value"); diff --git a/src/tests/unit/fixtures/thrift-server/basic_union.strict_union.solution.ts b/src/tests/unit/fixtures/thrift-server/basic_union.strict_union.solution.ts index 2949cc3e..e8f5210d 100644 --- a/src/tests/unit/fixtures/thrift-server/basic_union.strict_union.solution.ts +++ b/src/tests/unit/fixtures/thrift-server/basic_union.strict_union.solution.ts @@ -6,20 +6,20 @@ export type MyUnion = IMyUnionWithField1 | IMyUnionWithField2; export interface IMyUnionWithField1 { __type: MyUnionType.MyUnionWithField1; field1: number; - field2?: void; + field2?: undefined; } export interface IMyUnionWithField2 { __type: MyUnionType.MyUnionWithField2; - field1?: void; + field1?: undefined; field2: thrift.Int64; } export type MyUnionArgs = IMyUnionWithField1Args | IMyUnionWithField2Args; export interface IMyUnionWithField1Args { field1: number; - field2?: void; + field2?: undefined; } export interface IMyUnionWithField2Args { - field1?: void; + field1?: undefined; field2: number | string | thrift.Int64; } export const MyUnionCodec: thrift.IStructToolkit = { diff --git a/src/tests/unit/fixtures/thrift-server/complex_typedef.solution.ts b/src/tests/unit/fixtures/thrift-server/complex_typedef.solution.ts new file mode 100644 index 00000000..28b3dce4 --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/complex_typedef.solution.ts @@ -0,0 +1,260 @@ +export { IMyUnion as IALIAS_UNION }; +export { IMyUnionArgs as IALIAS_UNIONArgs }; +export { MyUnion as ALIAS_UNION }; +export { MyUnionCodec as ALIAS_UNIONCodec }; +export { IMyStruct as IALIAS_STRUCT }; +export { IMyStructArgs as IALIAS_STRUCTArgs }; +export { MyStruct as ALIAS_STRUCT }; +export { MyStructCodec as ALIAS_STRUCTCodec }; +export interface IMyUnion { + option1?: number; + option2?: string; +} +export interface IMyUnionArgs { + option1?: number; + option2?: string; +} +export const MyUnionCodec: thrift.IStructCodec = { + encode(args: IMyUnionArgs, output: thrift.TProtocol): void { + let _fieldsSet: number = 0; + const obj = { + option1: args.option1, + option2: args.option2 + }; + output.writeStructBegin("MyUnion"); + if (obj.option1 != null) { + _fieldsSet++; + output.writeFieldBegin("option1", thrift.TType.I32, 1); + output.writeI32(obj.option1); + output.writeFieldEnd(); + } + if (obj.option2 != null) { + _fieldsSet++; + output.writeFieldBegin("option2", thrift.TType.STRING, 2); + output.writeString(obj.option2); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + if (_fieldsSet > 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion cannot have more than one value"); + } + else if (_fieldsSet < 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion must have one value set"); + } + return; + }, + decode(input: thrift.TProtocol): IMyUnion { + let _fieldsSet: number = 0; + let _returnValue: IMyUnion | null = null; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.I32) { + _fieldsSet++; + const value_1: number = input.readI32(); + _returnValue = { option1: value_1 }; + } + else { + input.skip(fieldType); + } + break; + case 2: + if (fieldType === thrift.TType.STRING) { + _fieldsSet++; + const value_2: string = input.readString(); + _returnValue = { option2: value_2 }; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_fieldsSet > 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion cannot have more than one value"); + } + else if (_fieldsSet < 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion must have one value set"); + } + if (_returnValue !== null) { + return _returnValue; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read data for TUnion"); + } + } +}; +export class MyUnion extends thrift.StructLike implements IMyUnion { + public option1?: number; + public option2?: string; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IMyUnionArgs = {}) { + super(); + let _fieldsSet: number = 0; + if (args.option1 != null) { + _fieldsSet++; + const value_3: number = args.option1; + this.option1 = value_3; + } + if (args.option2 != null) { + _fieldsSet++; + const value_4: string = args.option2; + this.option2 = value_4; + } + if (_fieldsSet > 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion cannot have more than one value"); + } + else if (_fieldsSet < 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion must have one value set"); + } + } + public static read(input: thrift.TProtocol): MyUnion { + return new MyUnion(MyUnionCodec.decode(input)); + } + public static write(args: IMyUnionArgs, output: thrift.TProtocol): void { + return MyUnionCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return MyUnionCodec.encode(this, output); + } +} +export interface IMyStruct { + option1?: number; + option2?: string; +} +export interface IMyStructArgs { + option1?: number; + option2?: string; +} +export const MyStructCodec: thrift.IStructCodec = { + encode(args: IMyStructArgs, output: thrift.TProtocol): void { + let _fieldsSet: number = 0; + const obj = { + option1: args.option1, + option2: args.option2 + }; + output.writeStructBegin("MyStruct"); + if (obj.option1 != null) { + _fieldsSet++; + output.writeFieldBegin("option1", thrift.TType.I32, 1); + output.writeI32(obj.option1); + output.writeFieldEnd(); + } + if (obj.option2 != null) { + _fieldsSet++; + output.writeFieldBegin("option2", thrift.TType.STRING, 2); + output.writeString(obj.option2); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + if (_fieldsSet > 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion cannot have more than one value"); + } + else if (_fieldsSet < 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion must have one value set"); + } + return; + }, + decode(input: thrift.TProtocol): IMyStruct { + let _fieldsSet: number = 0; + let _returnValue: IMyStruct | null = null; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.I32) { + _fieldsSet++; + const value_5: number = input.readI32(); + _returnValue = { option1: value_5 }; + } + else { + input.skip(fieldType); + } + break; + case 2: + if (fieldType === thrift.TType.STRING) { + _fieldsSet++; + const value_6: string = input.readString(); + _returnValue = { option2: value_6 }; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_fieldsSet > 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion cannot have more than one value"); + } + else if (_fieldsSet < 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion must have one value set"); + } + if (_returnValue !== null) { + return _returnValue; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read data for TUnion"); + } + } +}; +export class MyStruct extends thrift.StructLike implements IMyStruct { + public option1?: number; + public option2?: string; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IMyStructArgs = {}) { + super(); + let _fieldsSet: number = 0; + if (args.option1 != null) { + _fieldsSet++; + const value_7: number = args.option1; + this.option1 = value_7; + } + if (args.option2 != null) { + _fieldsSet++; + const value_8: string = args.option2; + this.option2 = value_8; + } + if (_fieldsSet > 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion cannot have more than one value"); + } + else if (_fieldsSet < 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion must have one value set"); + } + } + public static read(input: thrift.TProtocol): MyStruct { + return new MyStruct(MyStructCodec.decode(input)); + } + public static write(args: IMyStructArgs, output: thrift.TProtocol): void { + return MyStructCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return MyStructCodec.encode(this, output); + } +} diff --git a/src/tests/unit/fixtures/thrift-server/complex_typedef.strict_union.solution.ts b/src/tests/unit/fixtures/thrift-server/complex_typedef.strict_union.solution.ts new file mode 100644 index 00000000..c5542dd8 --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/complex_typedef.strict_union.solution.ts @@ -0,0 +1,163 @@ +export { MyUnionType as ALIAS_UNIONType }; +export { MyUnion as ALIAS_UNION }; +export { IMyUnionWithOption1 as IALIAS_UNIONWithOption1 }; +export { IMyUnionWithOption2 as IALIAS_UNIONWithOption2 }; +export { MyUnionArgs as ALIAS_UNIONArgs }; +export { IMyUnionWithOption1Args as IALIAS_UNIONWithOption1Args }; +export { IMyUnionWithOption2Args as IALIAS_UNIONWithOption2Args }; +export { MyUnionCodec as ALIAS_UNIONCodec }; +export enum MyUnionType { + MyUnionWithOption1 = "option1", + MyUnionWithOption2 = "option2" +} +export type MyUnion = IMyUnionWithOption1 | IMyUnionWithOption2; +export interface IMyUnionWithOption1 { + __type: MyUnionType.MyUnionWithOption1; + option1: number; + option2?: undefined; +} +export interface IMyUnionWithOption2 { + __type: MyUnionType.MyUnionWithOption2; + option1?: undefined; + option2: string; +} +export type MyUnionArgs = IMyUnionWithOption1Args | IMyUnionWithOption2Args; +export interface IMyUnionWithOption1Args { + option1: number; + option2?: undefined; +} +export interface IMyUnionWithOption2Args { + option1?: undefined; + option2: string; +} +export const MyUnionCodec: thrift.IStructToolkit = { + create(args: MyUnionArgs): MyUnion { + let _fieldsSet: number = 0; + let _returnValue: any = null; + if (args.option1 != null) { + _fieldsSet++; + const value_1: number = args.option1; + _returnValue = { option1: value_1 }; + } + if (args.option2 != null) { + _fieldsSet++; + const value_2: string = args.option2; + _returnValue = { option2: value_2 }; + } + if (_fieldsSet > 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion cannot have more than one value"); + } + else if (_fieldsSet < 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion must have one value set"); + } + if (_returnValue !== null) { + if (_returnValue.option1) { + return { + __type: MyUnionType.MyUnionWithOption1, + option1: _returnValue.option1 + }; + } + else { + return { + __type: MyUnionType.MyUnionWithOption2, + option2: _returnValue.option2 + }; + } + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read data for TUnion"); + } + }, + encode(args: MyUnionArgs, output: thrift.TProtocol): void { + let _fieldsSet: number = 0; + const obj = { + option1: args.option1, + option2: args.option2 + }; + output.writeStructBegin("MyUnion"); + if (obj.option1 != null) { + _fieldsSet++; + output.writeFieldBegin("option1", thrift.TType.I32, 1); + output.writeI32(obj.option1); + output.writeFieldEnd(); + } + if (obj.option2 != null) { + _fieldsSet++; + output.writeFieldBegin("option2", thrift.TType.STRING, 2); + output.writeString(obj.option2); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + if (_fieldsSet > 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion cannot have more than one value"); + } + else if (_fieldsSet < 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion must have one value set"); + } + return; + }, + decode(input: thrift.TProtocol): MyUnion { + let _fieldsSet: number = 0; + let _returnValue: any = null; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.I32) { + _fieldsSet++; + const value_3: number = input.readI32(); + _returnValue = { option1: value_3 }; + } + else { + input.skip(fieldType); + } + break; + case 2: + if (fieldType === thrift.TType.STRING) { + _fieldsSet++; + const value_4: string = input.readString(); + _returnValue = { option2: value_4 }; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_fieldsSet > 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion cannot have more than one value"); + } + else if (_fieldsSet < 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion must have one value set"); + } + if (_returnValue !== null) { + if (_returnValue.option1) { + return { + __type: MyUnionType.MyUnionWithOption1, + option1: _returnValue.option1 + }; + } + else { + return { + __type: MyUnionType.MyUnionWithOption2, + option2: _returnValue.option2 + }; + } + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read data for TUnion"); + } + } +}; diff --git a/src/tests/unit/fixtures/thrift-server/extend_service.solution.ts b/src/tests/unit/fixtures/thrift-server/extend_service.solution.ts deleted file mode 100644 index 77b107e6..00000000 --- a/src/tests/unit/fixtures/thrift-server/extend_service.solution.ts +++ /dev/null @@ -1,803 +0,0 @@ -export namespace ParentService { - export const serviceName: string = "ParentService"; - export const annotations: thrift.IThriftAnnotations = {}; - export const methodAnnotations: thrift.IMethodAnnotations = { - ping: { - annotations: {}, - fieldAnnotations: {} - } - }; - export const methodNames: Array = ["ping"]; - export interface IPing__Args { - status: number; - } - export interface IPing__ArgsArgs { - status: number; - } - export const Ping__ArgsCodec: thrift.IStructCodec = { - encode(args: IPing__ArgsArgs, output: thrift.TProtocol): void { - const obj = { - status: args.status - }; - output.writeStructBegin("Ping__Args"); - if (obj.status != null) { - output.writeFieldBegin("status", thrift.TType.I32, 1); - output.writeI32(obj.status); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[status] is unset!"); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IPing__Args { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.I32) { - const value_1: number = input.readI32(); - _args.status = value_1; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.status !== undefined) { - return { - status: _args.status - }; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read Ping__Args from input"); - } - } - }; - export class Ping__Args extends thrift.StructLike implements IPing__Args { - public status: number; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IPing__ArgsArgs) { - super(); - if (args.status != null) { - const value_2: number = args.status; - this.status = value_2; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[status] is unset!"); - } - } - public static read(input: thrift.TProtocol): Ping__Args { - return new Ping__Args(Ping__ArgsCodec.decode(input)); - } - public static write(args: IPing__ArgsArgs, output: thrift.TProtocol): void { - return Ping__ArgsCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return Ping__ArgsCodec.encode(this, output); - } - } - export interface IPing__Result { - success?: string; - } - export interface IPing__ResultArgs { - success?: string; - } - export const Ping__ResultCodec: thrift.IStructCodec = { - encode(args: IPing__ResultArgs, output: thrift.TProtocol): void { - const obj = { - success: args.success - }; - output.writeStructBegin("Ping__Result"); - if (obj.success != null) { - output.writeFieldBegin("success", thrift.TType.STRING, 0); - output.writeString(obj.success); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IPing__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.STRING) { - const value_3: string = input.readString(); - _args.success = value_3; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - success: _args.success - }; - } - }; - export class Ping__Result extends thrift.StructLike implements IPing__Result { - public success?: string; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IPing__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_4: string = args.success; - this.success = value_4; - } - } - public static read(input: thrift.TProtocol): Ping__Result { - return new Ping__Result(Ping__ResultCodec.decode(input)); - } - public static write(args: IPing__ResultArgs, output: thrift.TProtocol): void { - return Ping__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return Ping__ResultCodec.encode(this, output); - } - } - export class Client extends thrift.ThriftClient { - public static readonly serviceName: string = serviceName; - public static readonly annotations: thrift.IThriftAnnotations = annotations; - public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public static readonly methodNames: Array = methodNames; - public readonly _serviceName: string = serviceName; - public readonly _annotations: thrift.IThriftAnnotations = annotations; - public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public readonly _methodNames: Array = methodNames; - public ping(status: number, context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("ping", thrift.MessageType.CALL, this.incrementRequestId()); - const args: IPing__ArgsArgs = { status }; - Ping__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "ping") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: IPing__Result = Ping__ResultCodec.decode(input); - input.readMessageEnd(); - if (result.success != null) { - return Promise.resolve(result.success); - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "ping failed: unknown result")); - } - } - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } - } - catch (err) { - return Promise.reject(err); - } - }); - } - } - export interface IHandler { - ping(status: number, context?: Context): string | Promise; - } - export class Processor extends thrift.ThriftProcessor> { - protected readonly _handler: IHandler; - public static readonly serviceName: string = serviceName; - public static readonly annotations: thrift.IThriftAnnotations = annotations; - public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public static readonly methodNames: Array = methodNames; - public readonly _serviceName: string = serviceName; - public readonly _annotations: thrift.IThriftAnnotations = annotations; - public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public readonly _methodNames: Array = methodNames; - constructor(handler: IHandler) { - super(); - this._handler = handler; - } - public process(input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - const metadata: thrift.IThriftMessage = input.readMessageBegin(); - const fieldName: string = metadata.fieldName; - const requestId: number = metadata.requestId; - const methodName: string = "process_" + fieldName; - switch (methodName) { - case "process_ping": { - resolve(this.process_ping(requestId, input, output, context)); - break; - } - default: { - input.skip(thrift.TType.STRUCT); - input.readMessageEnd(); - const errMessage = "Unknown function " + fieldName; - const err = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN_METHOD, errMessage); - output.writeMessageBegin(fieldName, thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(err, output); - output.writeMessageEnd(); - resolve(output.flush()); - break; - } - } - }); - } - public process_ping(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { - const args: IPing__Args = Ping__ArgsCodec.decode(input); - input.readMessageEnd(); - resolve(this._handler.ping(args.status, context)); - } - catch (err) { - reject(err); - } - }).then((data: string): Buffer => { - const result: IPing__ResultArgs = { success: data }; - output.writeMessageBegin("ping", thrift.MessageType.REPLY, requestId); - Ping__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("ping", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } - } -} -export namespace ChildService { - export const serviceName: string = "ChildService"; - export const annotations: thrift.IThriftAnnotations = {}; - export const methodAnnotations: thrift.IMethodAnnotations = { - ping: { - annotations: {}, - fieldAnnotations: {} - }, - peg: { - annotations: {}, - fieldAnnotations: {} - }, - pong: { - annotations: {}, - fieldAnnotations: {} - } - }; - export const methodNames: Array = ["ping", "peg", "pong"]; - export interface IPeg__Args { - name: string; - } - export interface IPeg__ArgsArgs { - name: string; - } - export const Peg__ArgsCodec: thrift.IStructCodec = { - encode(args: IPeg__ArgsArgs, output: thrift.TProtocol): void { - const obj = { - name: args.name - }; - output.writeStructBegin("Peg__Args"); - if (obj.name != null) { - output.writeFieldBegin("name", thrift.TType.STRING, 1); - output.writeString(obj.name); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[name] is unset!"); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IPeg__Args { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.STRING) { - const value_5: string = input.readString(); - _args.name = value_5; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.name !== undefined) { - return { - name: _args.name - }; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read Peg__Args from input"); - } - } - }; - export class Peg__Args extends thrift.StructLike implements IPeg__Args { - public name: string; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IPeg__ArgsArgs) { - super(); - if (args.name != null) { - const value_6: string = args.name; - this.name = value_6; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[name] is unset!"); - } - } - public static read(input: thrift.TProtocol): Peg__Args { - return new Peg__Args(Peg__ArgsCodec.decode(input)); - } - public static write(args: IPeg__ArgsArgs, output: thrift.TProtocol): void { - return Peg__ArgsCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return Peg__ArgsCodec.encode(this, output); - } - } - export interface IPong__Args { - name?: string; - } - export interface IPong__ArgsArgs { - name?: string; - } - export const Pong__ArgsCodec: thrift.IStructCodec = { - encode(args: IPong__ArgsArgs, output: thrift.TProtocol): void { - const obj = { - name: args.name - }; - output.writeStructBegin("Pong__Args"); - if (obj.name != null) { - output.writeFieldBegin("name", thrift.TType.STRING, 1); - output.writeString(obj.name); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IPong__Args { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.STRING) { - const value_7: string = input.readString(); - _args.name = value_7; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - name: _args.name - }; - } - }; - export class Pong__Args extends thrift.StructLike implements IPong__Args { - public name?: string; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IPong__ArgsArgs = {}) { - super(); - if (args.name != null) { - const value_8: string = args.name; - this.name = value_8; - } - } - public static read(input: thrift.TProtocol): Pong__Args { - return new Pong__Args(Pong__ArgsCodec.decode(input)); - } - public static write(args: IPong__ArgsArgs, output: thrift.TProtocol): void { - return Pong__ArgsCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return Pong__ArgsCodec.encode(this, output); - } - } - export interface IPeg__Result { - success?: string; - } - export interface IPeg__ResultArgs { - success?: string; - } - export const Peg__ResultCodec: thrift.IStructCodec = { - encode(args: IPeg__ResultArgs, output: thrift.TProtocol): void { - const obj = { - success: args.success - }; - output.writeStructBegin("Peg__Result"); - if (obj.success != null) { - output.writeFieldBegin("success", thrift.TType.STRING, 0); - output.writeString(obj.success); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IPeg__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.STRING) { - const value_9: string = input.readString(); - _args.success = value_9; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - success: _args.success - }; - } - }; - export class Peg__Result extends thrift.StructLike implements IPeg__Result { - public success?: string; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IPeg__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_10: string = args.success; - this.success = value_10; - } - } - public static read(input: thrift.TProtocol): Peg__Result { - return new Peg__Result(Peg__ResultCodec.decode(input)); - } - public static write(args: IPeg__ResultArgs, output: thrift.TProtocol): void { - return Peg__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return Peg__ResultCodec.encode(this, output); - } - } - export interface IPong__Result { - success?: string; - } - export interface IPong__ResultArgs { - success?: string; - } - export const Pong__ResultCodec: thrift.IStructCodec = { - encode(args: IPong__ResultArgs, output: thrift.TProtocol): void { - const obj = { - success: args.success - }; - output.writeStructBegin("Pong__Result"); - if (obj.success != null) { - output.writeFieldBegin("success", thrift.TType.STRING, 0); - output.writeString(obj.success); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IPong__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.STRING) { - const value_11: string = input.readString(); - _args.success = value_11; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - success: _args.success - }; - } - }; - export class Pong__Result extends thrift.StructLike implements IPong__Result { - public success?: string; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IPong__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_12: string = args.success; - this.success = value_12; - } - } - public static read(input: thrift.TProtocol): Pong__Result { - return new Pong__Result(Pong__ResultCodec.decode(input)); - } - public static write(args: IPong__ResultArgs, output: thrift.TProtocol): void { - return Pong__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return Pong__ResultCodec.encode(this, output); - } - } - export class Client extends ParentService.Client { - public static readonly serviceName: string = serviceName; - public static readonly annotations: thrift.IThriftAnnotations = annotations; - public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public static readonly methodNames: Array = methodNames; - public readonly _serviceName: string = serviceName; - public readonly _annotations: thrift.IThriftAnnotations = annotations; - public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public readonly _methodNames: Array = methodNames; - constructor(connection: thrift.IThriftConnection) { - super(connection); - } - public peg(name: string, context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("peg", thrift.MessageType.CALL, this.incrementRequestId()); - const args: IPeg__ArgsArgs = { name }; - Peg__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "peg") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: IPeg__Result = Peg__ResultCodec.decode(input); - input.readMessageEnd(); - if (result.success != null) { - return Promise.resolve(result.success); - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "peg failed: unknown result")); - } - } - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } - } - catch (err) { - return Promise.reject(err); - } - }); - } - public pong(name?: string, context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("pong", thrift.MessageType.CALL, this.incrementRequestId()); - const args: IPong__ArgsArgs = { name }; - Pong__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "pong") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: IPong__Result = Pong__ResultCodec.decode(input); - input.readMessageEnd(); - if (result.success != null) { - return Promise.resolve(result.success); - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "pong failed: unknown result")); - } - } - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } - } - catch (err) { - return Promise.reject(err); - } - }); - } - } - export interface ILocalHandler { - peg(name: string, context?: Context): string | Promise; - pong(name?: string, context?: Context): string | Promise; - } - export type IHandler = ILocalHandler & ParentService.IHandler; - export class Processor extends ParentService.Processor { - protected readonly _handler: IHandler; - public static readonly serviceName: string = serviceName; - public static readonly annotations: thrift.IThriftAnnotations = annotations; - public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public static readonly methodNames: Array = methodNames; - public readonly _serviceName: string = serviceName; - public readonly _annotations: thrift.IThriftAnnotations = annotations; - public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public readonly _methodNames: Array = methodNames; - constructor(handler: IHandler) { - super({ - ping: handler.ping - }); - this._handler = handler; - } - public process(input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - const metadata: thrift.IThriftMessage = input.readMessageBegin(); - const fieldName: string = metadata.fieldName; - const requestId: number = metadata.requestId; - const methodName: string = "process_" + fieldName; - switch (methodName) { - case "process_ping": { - resolve(this.process_ping(requestId, input, output, context)); - break; - } - case "process_peg": { - resolve(this.process_peg(requestId, input, output, context)); - break; - } - case "process_pong": { - resolve(this.process_pong(requestId, input, output, context)); - break; - } - default: { - input.skip(thrift.TType.STRUCT); - input.readMessageEnd(); - const errMessage = "Unknown function " + fieldName; - const err = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN_METHOD, errMessage); - output.writeMessageBegin(fieldName, thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(err, output); - output.writeMessageEnd(); - resolve(output.flush()); - break; - } - } - }); - } - public process_peg(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { - const args: IPeg__Args = Peg__ArgsCodec.decode(input); - input.readMessageEnd(); - resolve(this._handler.peg(args.name, context)); - } - catch (err) { - reject(err); - } - }).then((data: string): Buffer => { - const result: IPeg__ResultArgs = { success: data }; - output.writeMessageBegin("peg", thrift.MessageType.REPLY, requestId); - Peg__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("peg", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } - public process_pong(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { - const args: IPong__Args = Pong__ArgsCodec.decode(input); - input.readMessageEnd(); - resolve(this._handler.pong(args.name, context)); - } - catch (err) { - reject(err); - } - }).then((data: string): Buffer => { - const result: IPong__ResultArgs = { success: data }; - output.writeMessageBegin("pong", thrift.MessageType.REPLY, requestId); - Pong__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("pong", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } - } -} diff --git a/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/Calculator.ts b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/Calculator.ts new file mode 100644 index 00000000..0522bd99 --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/Calculator.ts @@ -0,0 +1,3482 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v3.3.4 + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as thrift from "test-lib"; +import * as com_test_shared from "./../shared"; +import * as com_test_operation from "./../operation"; +import * as com_test_common from "./../common"; +import * as __NAMESPACE__ from "./."; +export const serviceName: string = "Calculator"; +export const annotations: thrift.IThriftAnnotations = {}; +export const methodAnnotations: thrift.IMethodAnnotations = { + getStruct: { + annotations: {}, + fieldAnnotations: {} + }, + getUnion: { + annotations: {}, + fieldAnnotations: {} + }, + ping: { + annotations: {}, + fieldAnnotations: {} + }, + add: { + annotations: {}, + fieldAnnotations: {} + }, + addInt64: { + annotations: {}, + fieldAnnotations: {} + }, + addWithContext: { + annotations: {}, + fieldAnnotations: {} + }, + calculate: { + annotations: {}, + fieldAnnotations: {} + }, + echoBinary: { + annotations: {}, + fieldAnnotations: {} + }, + echoString: { + annotations: {}, + fieldAnnotations: {} + }, + checkName: { + annotations: {}, + fieldAnnotations: {} + }, + checkOptional: { + annotations: {}, + fieldAnnotations: {} + }, + mapOneList: { + annotations: {}, + fieldAnnotations: {} + }, + mapValues: { + annotations: {}, + fieldAnnotations: {} + }, + listToMap: { + annotations: {}, + fieldAnnotations: {} + }, + fetchThing: { + annotations: {}, + fieldAnnotations: {} + }, + zip: { + annotations: {}, + fieldAnnotations: {} + } +}; +export const methodNames: Array = ["getStruct", "getUnion", "ping", "add", "addInt64", "addWithContext", "calculate", "echoBinary", "echoString", "checkName", "checkOptional", "mapOneList", "mapValues", "listToMap", "fetchThing", "zip"]; +export interface IPing__Args { +} +export interface IPing__ArgsArgs { +} +export const Ping__ArgsCodec: thrift.IStructCodec = { + encode(args: IPing__ArgsArgs, output: thrift.TProtocol): void { + output.writeStructBegin("Ping__Args"); + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IPing__Args { + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return {}; + } +}; +export class Ping__Args extends thrift.StructLike implements IPing__Args { + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IPing__ArgsArgs = {}) { + super(); + } + public static read(input: thrift.TProtocol): Ping__Args { + return new Ping__Args(Ping__ArgsCodec.decode(input)); + } + public static write(args: IPing__ArgsArgs, output: thrift.TProtocol): void { + return Ping__ArgsCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return Ping__ArgsCodec.encode(this, output); + } +} +export interface IAdd__Args { + num1: number; + num2: number; +} +export interface IAdd__ArgsArgs { + num1: number; + num2: number; +} +export const Add__ArgsCodec: thrift.IStructCodec = { + encode(args: IAdd__ArgsArgs, output: thrift.TProtocol): void { + const obj = { + num1: args.num1, + num2: args.num2 + }; + output.writeStructBegin("Add__Args"); + if (obj.num1 != null) { + output.writeFieldBegin("num1", thrift.TType.I32, 1); + output.writeI32(obj.num1); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num1] is unset!"); + } + if (obj.num2 != null) { + output.writeFieldBegin("num2", thrift.TType.I32, 2); + output.writeI32(obj.num2); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num2] is unset!"); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IAdd__Args { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.I32) { + const value_1: number = input.readI32(); + _args.num1 = value_1; + } + else { + input.skip(fieldType); + } + break; + case 2: + if (fieldType === thrift.TType.I32) { + const value_2: number = input.readI32(); + _args.num2 = value_2; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.num1 !== undefined && _args.num2 !== undefined) { + return { + num1: _args.num1, + num2: _args.num2 + }; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read Add__Args from input"); + } + } +}; +export class Add__Args extends thrift.StructLike implements IAdd__Args { + public num1: number; + public num2: number; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IAdd__ArgsArgs) { + super(); + if (args.num1 != null) { + const value_3: number = args.num1; + this.num1 = value_3; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num1] is unset!"); + } + if (args.num2 != null) { + const value_4: number = args.num2; + this.num2 = value_4; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num2] is unset!"); + } + } + public static read(input: thrift.TProtocol): Add__Args { + return new Add__Args(Add__ArgsCodec.decode(input)); + } + public static write(args: IAdd__ArgsArgs, output: thrift.TProtocol): void { + return Add__ArgsCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return Add__ArgsCodec.encode(this, output); + } +} +export interface IAddInt64__Args { + num1: thrift.Int64; + num2: thrift.Int64; +} +export interface IAddInt64__ArgsArgs { + num1: number | string | thrift.Int64; + num2: number | string | thrift.Int64; +} +export const AddInt64__ArgsCodec: thrift.IStructCodec = { + encode(args: IAddInt64__ArgsArgs, output: thrift.TProtocol): void { + const obj = { + num1: (typeof args.num1 === "number" ? new thrift.Int64(args.num1) : typeof args.num1 === "string" ? thrift.Int64.fromDecimalString(args.num1) : args.num1), + num2: (typeof args.num2 === "number" ? new thrift.Int64(args.num2) : typeof args.num2 === "string" ? thrift.Int64.fromDecimalString(args.num2) : args.num2) + }; + output.writeStructBegin("AddInt64__Args"); + if (obj.num1 != null) { + output.writeFieldBegin("num1", thrift.TType.I64, 1); + output.writeI64((typeof obj.num1 === "number" ? new thrift.Int64(obj.num1) : typeof obj.num1 === "string" ? thrift.Int64.fromDecimalString(obj.num1) : obj.num1)); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num1] is unset!"); + } + if (obj.num2 != null) { + output.writeFieldBegin("num2", thrift.TType.I64, 2); + output.writeI64((typeof obj.num2 === "number" ? new thrift.Int64(obj.num2) : typeof obj.num2 === "string" ? thrift.Int64.fromDecimalString(obj.num2) : obj.num2)); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num2] is unset!"); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IAddInt64__Args { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.I64) { + const value_5: thrift.Int64 = input.readI64(); + _args.num1 = value_5; + } + else { + input.skip(fieldType); + } + break; + case 2: + if (fieldType === thrift.TType.I64) { + const value_6: thrift.Int64 = input.readI64(); + _args.num2 = value_6; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.num1 !== undefined && _args.num2 !== undefined) { + return { + num1: _args.num1, + num2: _args.num2 + }; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read AddInt64__Args from input"); + } + } +}; +export class AddInt64__Args extends thrift.StructLike implements IAddInt64__Args { + public num1: thrift.Int64; + public num2: thrift.Int64; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IAddInt64__ArgsArgs) { + super(); + if (args.num1 != null) { + const value_7: thrift.Int64 = (typeof args.num1 === "number" ? new thrift.Int64(args.num1) : typeof args.num1 === "string" ? thrift.Int64.fromDecimalString(args.num1) : args.num1); + this.num1 = value_7; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num1] is unset!"); + } + if (args.num2 != null) { + const value_8: thrift.Int64 = (typeof args.num2 === "number" ? new thrift.Int64(args.num2) : typeof args.num2 === "string" ? thrift.Int64.fromDecimalString(args.num2) : args.num2); + this.num2 = value_8; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num2] is unset!"); + } + } + public static read(input: thrift.TProtocol): AddInt64__Args { + return new AddInt64__Args(AddInt64__ArgsCodec.decode(input)); + } + public static write(args: IAddInt64__ArgsArgs, output: thrift.TProtocol): void { + return AddInt64__ArgsCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return AddInt64__ArgsCodec.encode(this, output); + } +} +export interface IAddWithContext__Args { + num1: number; + num2: number; +} +export interface IAddWithContext__ArgsArgs { + num1: number; + num2: number; +} +export const AddWithContext__ArgsCodec: thrift.IStructCodec = { + encode(args: IAddWithContext__ArgsArgs, output: thrift.TProtocol): void { + const obj = { + num1: args.num1, + num2: args.num2 + }; + output.writeStructBegin("AddWithContext__Args"); + if (obj.num1 != null) { + output.writeFieldBegin("num1", thrift.TType.I32, 1); + output.writeI32(obj.num1); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num1] is unset!"); + } + if (obj.num2 != null) { + output.writeFieldBegin("num2", thrift.TType.I32, 2); + output.writeI32(obj.num2); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num2] is unset!"); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IAddWithContext__Args { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.I32) { + const value_9: number = input.readI32(); + _args.num1 = value_9; + } + else { + input.skip(fieldType); + } + break; + case 2: + if (fieldType === thrift.TType.I32) { + const value_10: number = input.readI32(); + _args.num2 = value_10; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.num1 !== undefined && _args.num2 !== undefined) { + return { + num1: _args.num1, + num2: _args.num2 + }; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read AddWithContext__Args from input"); + } + } +}; +export class AddWithContext__Args extends thrift.StructLike implements IAddWithContext__Args { + public num1: number; + public num2: number; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IAddWithContext__ArgsArgs) { + super(); + if (args.num1 != null) { + const value_11: number = args.num1; + this.num1 = value_11; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num1] is unset!"); + } + if (args.num2 != null) { + const value_12: number = args.num2; + this.num2 = value_12; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num2] is unset!"); + } + } + public static read(input: thrift.TProtocol): AddWithContext__Args { + return new AddWithContext__Args(AddWithContext__ArgsCodec.decode(input)); + } + public static write(args: IAddWithContext__ArgsArgs, output: thrift.TProtocol): void { + return AddWithContext__ArgsCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return AddWithContext__ArgsCodec.encode(this, output); + } +} +export interface ICalculate__Args { + logid: number; + work: __NAMESPACE__.IWork; +} +export interface ICalculate__ArgsArgs { + logid: number; + work: __NAMESPACE__.IWorkArgs; +} +export const Calculate__ArgsCodec: thrift.IStructCodec = { + encode(args: ICalculate__ArgsArgs, output: thrift.TProtocol): void { + const obj = { + logid: args.logid, + work: args.work + }; + output.writeStructBegin("Calculate__Args"); + if (obj.logid != null) { + output.writeFieldBegin("logid", thrift.TType.I32, 1); + output.writeI32(obj.logid); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[logid] is unset!"); + } + if (obj.work != null) { + output.writeFieldBegin("work", thrift.TType.STRUCT, 2); + __NAMESPACE__.WorkCodec.encode(obj.work, output); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[work] is unset!"); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): ICalculate__Args { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.I32) { + const value_13: number = input.readI32(); + _args.logid = value_13; + } + else { + input.skip(fieldType); + } + break; + case 2: + if (fieldType === thrift.TType.STRUCT) { + const value_14: __NAMESPACE__.IWork = __NAMESPACE__.WorkCodec.decode(input); + _args.work = value_14; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.logid !== undefined && _args.work !== undefined) { + return { + logid: _args.logid, + work: _args.work + }; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read Calculate__Args from input"); + } + } +}; +export class Calculate__Args extends thrift.StructLike implements ICalculate__Args { + public logid: number; + public work: __NAMESPACE__.IWork; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: ICalculate__ArgsArgs) { + super(); + if (args.logid != null) { + const value_15: number = args.logid; + this.logid = value_15; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[logid] is unset!"); + } + if (args.work != null) { + const value_16: __NAMESPACE__.IWork = new __NAMESPACE__.Work(args.work); + this.work = value_16; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[work] is unset!"); + } + } + public static read(input: thrift.TProtocol): Calculate__Args { + return new Calculate__Args(Calculate__ArgsCodec.decode(input)); + } + public static write(args: ICalculate__ArgsArgs, output: thrift.TProtocol): void { + return Calculate__ArgsCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return Calculate__ArgsCodec.encode(this, output); + } +} +export interface IEchoBinary__Args { + word: Buffer; +} +export interface IEchoBinary__ArgsArgs { + word: string | Buffer; +} +export const EchoBinary__ArgsCodec: thrift.IStructCodec = { + encode(args: IEchoBinary__ArgsArgs, output: thrift.TProtocol): void { + const obj = { + word: (typeof args.word === "string" ? Buffer.from(args.word) : args.word) + }; + output.writeStructBegin("EchoBinary__Args"); + if (obj.word != null) { + output.writeFieldBegin("word", thrift.TType.STRING, 1); + output.writeBinary(obj.word); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[word] is unset!"); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IEchoBinary__Args { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.STRING) { + const value_17: Buffer = input.readBinary(); + _args.word = value_17; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.word !== undefined) { + return { + word: _args.word + }; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read EchoBinary__Args from input"); + } + } +}; +export class EchoBinary__Args extends thrift.StructLike implements IEchoBinary__Args { + public word: Buffer; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IEchoBinary__ArgsArgs) { + super(); + if (args.word != null) { + const value_18: Buffer = (typeof args.word === "string" ? Buffer.from(args.word) : args.word); + this.word = value_18; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[word] is unset!"); + } + } + public static read(input: thrift.TProtocol): EchoBinary__Args { + return new EchoBinary__Args(EchoBinary__ArgsCodec.decode(input)); + } + public static write(args: IEchoBinary__ArgsArgs, output: thrift.TProtocol): void { + return EchoBinary__ArgsCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return EchoBinary__ArgsCodec.encode(this, output); + } +} +export interface IEchoString__Args { + word: string; +} +export interface IEchoString__ArgsArgs { + word: string; +} +export const EchoString__ArgsCodec: thrift.IStructCodec = { + encode(args: IEchoString__ArgsArgs, output: thrift.TProtocol): void { + const obj = { + word: args.word + }; + output.writeStructBegin("EchoString__Args"); + if (obj.word != null) { + output.writeFieldBegin("word", thrift.TType.STRING, 1); + output.writeString(obj.word); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[word] is unset!"); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IEchoString__Args { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.STRING) { + const value_19: string = input.readString(); + _args.word = value_19; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.word !== undefined) { + return { + word: _args.word + }; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read EchoString__Args from input"); + } + } +}; +export class EchoString__Args extends thrift.StructLike implements IEchoString__Args { + public word: string; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IEchoString__ArgsArgs) { + super(); + if (args.word != null) { + const value_20: string = args.word; + this.word = value_20; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[word] is unset!"); + } + } + public static read(input: thrift.TProtocol): EchoString__Args { + return new EchoString__Args(EchoString__ArgsCodec.decode(input)); + } + public static write(args: IEchoString__ArgsArgs, output: thrift.TProtocol): void { + return EchoString__ArgsCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return EchoString__ArgsCodec.encode(this, output); + } +} +export interface ICheckName__Args { + choice: __NAMESPACE__.Choice; +} +export interface ICheckName__ArgsArgs { + choice: __NAMESPACE__.ChoiceArgs; +} +export const CheckName__ArgsCodec: thrift.IStructCodec = { + encode(args: ICheckName__ArgsArgs, output: thrift.TProtocol): void { + const obj = { + choice: args.choice + }; + output.writeStructBegin("CheckName__Args"); + if (obj.choice != null) { + output.writeFieldBegin("choice", thrift.TType.STRUCT, 1); + __NAMESPACE__.ChoiceCodec.encode(obj.choice, output); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[choice] is unset!"); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): ICheckName__Args { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.STRUCT) { + const value_21: __NAMESPACE__.Choice = __NAMESPACE__.ChoiceCodec.decode(input); + _args.choice = value_21; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.choice !== undefined) { + return { + choice: _args.choice + }; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read CheckName__Args from input"); + } + } +}; +export class CheckName__Args extends thrift.StructLike implements ICheckName__Args { + public choice: __NAMESPACE__.Choice; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: ICheckName__ArgsArgs) { + super(); + if (args.choice != null) { + const value_22: __NAMESPACE__.Choice = __NAMESPACE__.ChoiceCodec.create(args.choice); + this.choice = value_22; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[choice] is unset!"); + } + } + public static read(input: thrift.TProtocol): CheckName__Args { + return new CheckName__Args(CheckName__ArgsCodec.decode(input)); + } + public static write(args: ICheckName__ArgsArgs, output: thrift.TProtocol): void { + return CheckName__ArgsCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return CheckName__ArgsCodec.encode(this, output); + } +} +export interface ICheckOptional__Args { + type?: string; +} +export interface ICheckOptional__ArgsArgs { + type?: string; +} +export const CheckOptional__ArgsCodec: thrift.IStructCodec = { + encode(args: ICheckOptional__ArgsArgs, output: thrift.TProtocol): void { + const obj = { + type: args.type + }; + output.writeStructBegin("CheckOptional__Args"); + if (obj.type != null) { + output.writeFieldBegin("type", thrift.TType.STRING, 1); + output.writeString(obj.type); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): ICheckOptional__Args { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.STRING) { + const value_23: string = input.readString(); + _args.type = value_23; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + type: _args.type + }; + } +}; +export class CheckOptional__Args extends thrift.StructLike implements ICheckOptional__Args { + public type?: string; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: ICheckOptional__ArgsArgs = {}) { + super(); + if (args.type != null) { + const value_24: string = args.type; + this.type = value_24; + } + } + public static read(input: thrift.TProtocol): CheckOptional__Args { + return new CheckOptional__Args(CheckOptional__ArgsCodec.decode(input)); + } + public static write(args: ICheckOptional__ArgsArgs, output: thrift.TProtocol): void { + return CheckOptional__ArgsCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return CheckOptional__ArgsCodec.encode(this, output); + } +} +export interface IMapOneList__Args { + arg: Array; +} +export interface IMapOneList__ArgsArgs { + arg: Array; +} +export const MapOneList__ArgsCodec: thrift.IStructCodec = { + encode(args: IMapOneList__ArgsArgs, output: thrift.TProtocol): void { + const obj = { + arg: args.arg + }; + output.writeStructBegin("MapOneList__Args"); + if (obj.arg != null) { + output.writeFieldBegin("arg", thrift.TType.LIST, 1); + output.writeListBegin(thrift.TType.I32, obj.arg.length); + obj.arg.forEach((value_25: number): void => { + output.writeI32(value_25); + }); + output.writeListEnd(); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[arg] is unset!"); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IMapOneList__Args { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.LIST) { + const value_26: Array = new Array(); + const metadata_1: thrift.IThriftList = input.readListBegin(); + const size_1: number = metadata_1.size; + for (let i_1: number = 0; i_1 < size_1; i_1++) { + const value_27: number = input.readI32(); + value_26.push(value_27); + } + input.readListEnd(); + _args.arg = value_26; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.arg !== undefined) { + return { + arg: _args.arg + }; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read MapOneList__Args from input"); + } + } +}; +export class MapOneList__Args extends thrift.StructLike implements IMapOneList__Args { + public arg: Array; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IMapOneList__ArgsArgs) { + super(); + if (args.arg != null) { + const value_28: Array = new Array(); + args.arg.forEach((value_29: number): void => { + const value_30: number = value_29; + value_28.push(value_30); + }); + this.arg = value_28; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[arg] is unset!"); + } + } + public static read(input: thrift.TProtocol): MapOneList__Args { + return new MapOneList__Args(MapOneList__ArgsCodec.decode(input)); + } + public static write(args: IMapOneList__ArgsArgs, output: thrift.TProtocol): void { + return MapOneList__ArgsCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return MapOneList__ArgsCodec.encode(this, output); + } +} +export interface IMapValues__Args { + arg: Map; +} +export interface IMapValues__ArgsArgs { + arg: Map; +} +export const MapValues__ArgsCodec: thrift.IStructCodec = { + encode(args: IMapValues__ArgsArgs, output: thrift.TProtocol): void { + const obj = { + arg: args.arg + }; + output.writeStructBegin("MapValues__Args"); + if (obj.arg != null) { + output.writeFieldBegin("arg", thrift.TType.MAP, 1); + output.writeMapBegin(thrift.TType.STRING, thrift.TType.I32, obj.arg.size); + obj.arg.forEach((value_31: number, key_1: string): void => { + output.writeString(key_1); + output.writeI32(value_31); + }); + output.writeMapEnd(); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[arg] is unset!"); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IMapValues__Args { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.MAP) { + const value_32: Map = new Map(); + const metadata_2: thrift.IThriftMap = input.readMapBegin(); + const size_2: number = metadata_2.size; + for (let i_2: number = 0; i_2 < size_2; i_2++) { + const key_2: string = input.readString(); + const value_33: number = input.readI32(); + value_32.set(key_2, value_33); + } + input.readMapEnd(); + _args.arg = value_32; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.arg !== undefined) { + return { + arg: _args.arg + }; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read MapValues__Args from input"); + } + } +}; +export class MapValues__Args extends thrift.StructLike implements IMapValues__Args { + public arg: Map; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IMapValues__ArgsArgs) { + super(); + if (args.arg != null) { + const value_34: Map = new Map(); + args.arg.forEach((value_35: number, key_3: string): void => { + const value_36: number = value_35; + const key_4: string = key_3; + value_34.set(key_4, value_36); + }); + this.arg = value_34; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[arg] is unset!"); + } + } + public static read(input: thrift.TProtocol): MapValues__Args { + return new MapValues__Args(MapValues__ArgsCodec.decode(input)); + } + public static write(args: IMapValues__ArgsArgs, output: thrift.TProtocol): void { + return MapValues__ArgsCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return MapValues__ArgsCodec.encode(this, output); + } +} +export interface IListToMap__Args { + arg: Array>; +} +export interface IListToMap__ArgsArgs { + arg: Array>; +} +export const ListToMap__ArgsCodec: thrift.IStructCodec = { + encode(args: IListToMap__ArgsArgs, output: thrift.TProtocol): void { + const obj = { + arg: args.arg + }; + output.writeStructBegin("ListToMap__Args"); + if (obj.arg != null) { + output.writeFieldBegin("arg", thrift.TType.LIST, 1); + output.writeListBegin(thrift.TType.LIST, obj.arg.length); + obj.arg.forEach((value_37: Array): void => { + output.writeListBegin(thrift.TType.STRING, value_37.length); + value_37.forEach((value_38: string): void => { + output.writeString(value_38); + }); + output.writeListEnd(); + }); + output.writeListEnd(); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[arg] is unset!"); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IListToMap__Args { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.LIST) { + const value_39: Array> = new Array>(); + const metadata_3: thrift.IThriftList = input.readListBegin(); + const size_3: number = metadata_3.size; + for (let i_3: number = 0; i_3 < size_3; i_3++) { + const value_40: Array = new Array(); + const metadata_4: thrift.IThriftList = input.readListBegin(); + const size_4: number = metadata_4.size; + for (let i_4: number = 0; i_4 < size_4; i_4++) { + const value_41: string = input.readString(); + value_40.push(value_41); + } + input.readListEnd(); + value_39.push(value_40); + } + input.readListEnd(); + _args.arg = value_39; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.arg !== undefined) { + return { + arg: _args.arg + }; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read ListToMap__Args from input"); + } + } +}; +export class ListToMap__Args extends thrift.StructLike implements IListToMap__Args { + public arg: Array>; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IListToMap__ArgsArgs) { + super(); + if (args.arg != null) { + const value_42: Array> = new Array>(); + args.arg.forEach((value_43: Array): void => { + const value_44: Array = new Array(); + value_43.forEach((value_45: string): void => { + const value_46: string = value_45; + value_44.push(value_46); + }); + value_42.push(value_44); + }); + this.arg = value_42; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[arg] is unset!"); + } + } + public static read(input: thrift.TProtocol): ListToMap__Args { + return new ListToMap__Args(ListToMap__ArgsCodec.decode(input)); + } + public static write(args: IListToMap__ArgsArgs, output: thrift.TProtocol): void { + return ListToMap__ArgsCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return ListToMap__ArgsCodec.encode(this, output); + } +} +export interface IFetchThing__Args { +} +export interface IFetchThing__ArgsArgs { +} +export const FetchThing__ArgsCodec: thrift.IStructCodec = { + encode(args: IFetchThing__ArgsArgs, output: thrift.TProtocol): void { + output.writeStructBegin("FetchThing__Args"); + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IFetchThing__Args { + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return {}; + } +}; +export class FetchThing__Args extends thrift.StructLike implements IFetchThing__Args { + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IFetchThing__ArgsArgs = {}) { + super(); + } + public static read(input: thrift.TProtocol): FetchThing__Args { + return new FetchThing__Args(FetchThing__ArgsCodec.decode(input)); + } + public static write(args: IFetchThing__ArgsArgs, output: thrift.TProtocol): void { + return FetchThing__ArgsCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return FetchThing__ArgsCodec.encode(this, output); + } +} +export interface IZip__Args { +} +export interface IZip__ArgsArgs { +} +export const Zip__ArgsCodec: thrift.IStructCodec = { + encode(args: IZip__ArgsArgs, output: thrift.TProtocol): void { + output.writeStructBegin("Zip__Args"); + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IZip__Args { + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return {}; + } +}; +export class Zip__Args extends thrift.StructLike implements IZip__Args { + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IZip__ArgsArgs = {}) { + super(); + } + public static read(input: thrift.TProtocol): Zip__Args { + return new Zip__Args(Zip__ArgsCodec.decode(input)); + } + public static write(args: IZip__ArgsArgs, output: thrift.TProtocol): void { + return Zip__ArgsCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return Zip__ArgsCodec.encode(this, output); + } +} +export interface IPing__Result { + success?: void; +} +export interface IPing__ResultArgs { + success?: void; +} +export const Ping__ResultCodec: thrift.IStructCodec = { + encode(args: IPing__ResultArgs, output: thrift.TProtocol): void { + output.writeStructBegin("Ping__Result"); + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IPing__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.VOID) { + input.skip(fieldType); + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + success: _args.success + }; + } +}; +export class Ping__Result extends thrift.StructLike implements IPing__Result { + public success?: void; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IPing__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_47: void = undefined; + this.success = value_47; + } + } + public static read(input: thrift.TProtocol): Ping__Result { + return new Ping__Result(Ping__ResultCodec.decode(input)); + } + public static write(args: IPing__ResultArgs, output: thrift.TProtocol): void { + return Ping__ResultCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return Ping__ResultCodec.encode(this, output); + } +} +export interface IAdd__Result { + success?: number; + exp?: com_test_operation.IJankyResult; +} +export interface IAdd__ResultArgs { + success?: number; + exp?: com_test_operation.IJankyResultArgs; +} +export const Add__ResultCodec: thrift.IStructCodec = { + encode(args: IAdd__ResultArgs, output: thrift.TProtocol): void { + const obj = { + success: args.success, + exp: args.exp + }; + output.writeStructBegin("Add__Result"); + if (obj.success != null) { + output.writeFieldBegin("success", thrift.TType.I32, 0); + output.writeI32(obj.success); + output.writeFieldEnd(); + } + if (obj.exp != null) { + output.writeFieldBegin("exp", thrift.TType.STRUCT, 1); + com_test_operation.JankyResultCodec.encode(obj.exp, output); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IAdd__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.I32) { + const value_48: number = input.readI32(); + _args.success = value_48; + } + else { + input.skip(fieldType); + } + break; + case 1: + if (fieldType === thrift.TType.STRUCT) { + const value_49: com_test_operation.IJankyResult = com_test_operation.JankyResultCodec.decode(input); + _args.exp = value_49; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + success: _args.success, + exp: _args.exp + }; + } +}; +export class Add__Result extends thrift.StructLike implements IAdd__Result { + public success?: number; + public exp?: com_test_operation.IJankyResult; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IAdd__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_50: number = args.success; + this.success = value_50; + } + if (args.exp != null) { + const value_51: com_test_operation.IJankyResult = new com_test_operation.JankyResult(args.exp); + this.exp = value_51; + } + } + public static read(input: thrift.TProtocol): Add__Result { + return new Add__Result(Add__ResultCodec.decode(input)); + } + public static write(args: IAdd__ResultArgs, output: thrift.TProtocol): void { + return Add__ResultCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return Add__ResultCodec.encode(this, output); + } +} +export interface IAddInt64__Result { + success?: thrift.Int64; + exp?: __NAMESPACE__.INotAGoodIdea; +} +export interface IAddInt64__ResultArgs { + success?: number | string | thrift.Int64; + exp?: __NAMESPACE__.INotAGoodIdeaArgs; +} +export const AddInt64__ResultCodec: thrift.IStructCodec = { + encode(args: IAddInt64__ResultArgs, output: thrift.TProtocol): void { + const obj = { + success: (typeof args.success === "number" ? new thrift.Int64(args.success) : typeof args.success === "string" ? thrift.Int64.fromDecimalString(args.success) : args.success), + exp: args.exp + }; + output.writeStructBegin("AddInt64__Result"); + if (obj.success != null) { + output.writeFieldBegin("success", thrift.TType.I64, 0); + output.writeI64((typeof obj.success === "number" ? new thrift.Int64(obj.success) : typeof obj.success === "string" ? thrift.Int64.fromDecimalString(obj.success) : obj.success)); + output.writeFieldEnd(); + } + if (obj.exp != null) { + output.writeFieldBegin("exp", thrift.TType.STRUCT, 1); + __NAMESPACE__.NotAGoodIdeaCodec.encode(obj.exp, output); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IAddInt64__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.I64) { + const value_52: thrift.Int64 = input.readI64(); + _args.success = value_52; + } + else { + input.skip(fieldType); + } + break; + case 1: + if (fieldType === thrift.TType.STRUCT) { + const value_53: __NAMESPACE__.INotAGoodIdea = __NAMESPACE__.NotAGoodIdeaCodec.decode(input); + _args.exp = value_53; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + success: _args.success, + exp: _args.exp + }; + } +}; +export class AddInt64__Result extends thrift.StructLike implements IAddInt64__Result { + public success?: thrift.Int64; + public exp?: __NAMESPACE__.INotAGoodIdea; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IAddInt64__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_54: thrift.Int64 = (typeof args.success === "number" ? new thrift.Int64(args.success) : typeof args.success === "string" ? thrift.Int64.fromDecimalString(args.success) : args.success); + this.success = value_54; + } + if (args.exp != null) { + const value_55: __NAMESPACE__.INotAGoodIdea = new __NAMESPACE__.NotAGoodIdea(args.exp); + this.exp = value_55; + } + } + public static read(input: thrift.TProtocol): AddInt64__Result { + return new AddInt64__Result(AddInt64__ResultCodec.decode(input)); + } + public static write(args: IAddInt64__ResultArgs, output: thrift.TProtocol): void { + return AddInt64__ResultCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return AddInt64__ResultCodec.encode(this, output); + } +} +export interface IAddWithContext__Result { + success?: number; +} +export interface IAddWithContext__ResultArgs { + success?: number; +} +export const AddWithContext__ResultCodec: thrift.IStructCodec = { + encode(args: IAddWithContext__ResultArgs, output: thrift.TProtocol): void { + const obj = { + success: args.success + }; + output.writeStructBegin("AddWithContext__Result"); + if (obj.success != null) { + output.writeFieldBegin("success", thrift.TType.I32, 0); + output.writeI32(obj.success); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IAddWithContext__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.I32) { + const value_56: number = input.readI32(); + _args.success = value_56; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + success: _args.success + }; + } +}; +export class AddWithContext__Result extends thrift.StructLike implements IAddWithContext__Result { + public success?: number; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IAddWithContext__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_57: number = args.success; + this.success = value_57; + } + } + public static read(input: thrift.TProtocol): AddWithContext__Result { + return new AddWithContext__Result(AddWithContext__ResultCodec.decode(input)); + } + public static write(args: IAddWithContext__ResultArgs, output: thrift.TProtocol): void { + return AddWithContext__ResultCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return AddWithContext__ResultCodec.encode(this, output); + } +} +export interface ICalculate__Result { + success?: number; + ouch?: com_test_operation.IJankyOperation; +} +export interface ICalculate__ResultArgs { + success?: number; + ouch?: com_test_operation.IJankyOperationArgs; +} +export const Calculate__ResultCodec: thrift.IStructCodec = { + encode(args: ICalculate__ResultArgs, output: thrift.TProtocol): void { + const obj = { + success: args.success, + ouch: args.ouch + }; + output.writeStructBegin("Calculate__Result"); + if (obj.success != null) { + output.writeFieldBegin("success", thrift.TType.I32, 0); + output.writeI32(obj.success); + output.writeFieldEnd(); + } + if (obj.ouch != null) { + output.writeFieldBegin("ouch", thrift.TType.STRUCT, 1); + com_test_operation.JankyOperationCodec.encode(obj.ouch, output); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): ICalculate__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.I32) { + const value_58: number = input.readI32(); + _args.success = value_58; + } + else { + input.skip(fieldType); + } + break; + case 1: + if (fieldType === thrift.TType.STRUCT) { + const value_59: com_test_operation.IJankyOperation = com_test_operation.JankyOperationCodec.decode(input); + _args.ouch = value_59; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + success: _args.success, + ouch: _args.ouch + }; + } +}; +export class Calculate__Result extends thrift.StructLike implements ICalculate__Result { + public success?: number; + public ouch?: com_test_operation.IJankyOperation; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: ICalculate__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_60: number = args.success; + this.success = value_60; + } + if (args.ouch != null) { + const value_61: com_test_operation.IJankyOperation = new com_test_operation.JankyOperation(args.ouch); + this.ouch = value_61; + } + } + public static read(input: thrift.TProtocol): Calculate__Result { + return new Calculate__Result(Calculate__ResultCodec.decode(input)); + } + public static write(args: ICalculate__ResultArgs, output: thrift.TProtocol): void { + return Calculate__ResultCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return Calculate__ResultCodec.encode(this, output); + } +} +export interface IEchoBinary__Result { + success?: string; +} +export interface IEchoBinary__ResultArgs { + success?: string; +} +export const EchoBinary__ResultCodec: thrift.IStructCodec = { + encode(args: IEchoBinary__ResultArgs, output: thrift.TProtocol): void { + const obj = { + success: args.success + }; + output.writeStructBegin("EchoBinary__Result"); + if (obj.success != null) { + output.writeFieldBegin("success", thrift.TType.STRING, 0); + output.writeString(obj.success); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IEchoBinary__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.STRING) { + const value_62: string = input.readString(); + _args.success = value_62; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + success: _args.success + }; + } +}; +export class EchoBinary__Result extends thrift.StructLike implements IEchoBinary__Result { + public success?: string; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IEchoBinary__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_63: string = args.success; + this.success = value_63; + } + } + public static read(input: thrift.TProtocol): EchoBinary__Result { + return new EchoBinary__Result(EchoBinary__ResultCodec.decode(input)); + } + public static write(args: IEchoBinary__ResultArgs, output: thrift.TProtocol): void { + return EchoBinary__ResultCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return EchoBinary__ResultCodec.encode(this, output); + } +} +export interface IEchoString__Result { + success?: string; +} +export interface IEchoString__ResultArgs { + success?: string; +} +export const EchoString__ResultCodec: thrift.IStructCodec = { + encode(args: IEchoString__ResultArgs, output: thrift.TProtocol): void { + const obj = { + success: args.success + }; + output.writeStructBegin("EchoString__Result"); + if (obj.success != null) { + output.writeFieldBegin("success", thrift.TType.STRING, 0); + output.writeString(obj.success); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IEchoString__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.STRING) { + const value_64: string = input.readString(); + _args.success = value_64; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + success: _args.success + }; + } +}; +export class EchoString__Result extends thrift.StructLike implements IEchoString__Result { + public success?: string; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IEchoString__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_65: string = args.success; + this.success = value_65; + } + } + public static read(input: thrift.TProtocol): EchoString__Result { + return new EchoString__Result(EchoString__ResultCodec.decode(input)); + } + public static write(args: IEchoString__ResultArgs, output: thrift.TProtocol): void { + return EchoString__ResultCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return EchoString__ResultCodec.encode(this, output); + } +} +export interface ICheckName__Result { + success?: string; +} +export interface ICheckName__ResultArgs { + success?: string; +} +export const CheckName__ResultCodec: thrift.IStructCodec = { + encode(args: ICheckName__ResultArgs, output: thrift.TProtocol): void { + const obj = { + success: args.success + }; + output.writeStructBegin("CheckName__Result"); + if (obj.success != null) { + output.writeFieldBegin("success", thrift.TType.STRING, 0); + output.writeString(obj.success); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): ICheckName__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.STRING) { + const value_66: string = input.readString(); + _args.success = value_66; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + success: _args.success + }; + } +}; +export class CheckName__Result extends thrift.StructLike implements ICheckName__Result { + public success?: string; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: ICheckName__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_67: string = args.success; + this.success = value_67; + } + } + public static read(input: thrift.TProtocol): CheckName__Result { + return new CheckName__Result(CheckName__ResultCodec.decode(input)); + } + public static write(args: ICheckName__ResultArgs, output: thrift.TProtocol): void { + return CheckName__ResultCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return CheckName__ResultCodec.encode(this, output); + } +} +export interface ICheckOptional__Result { + success?: string; +} +export interface ICheckOptional__ResultArgs { + success?: string; +} +export const CheckOptional__ResultCodec: thrift.IStructCodec = { + encode(args: ICheckOptional__ResultArgs, output: thrift.TProtocol): void { + const obj = { + success: args.success + }; + output.writeStructBegin("CheckOptional__Result"); + if (obj.success != null) { + output.writeFieldBegin("success", thrift.TType.STRING, 0); + output.writeString(obj.success); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): ICheckOptional__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.STRING) { + const value_68: string = input.readString(); + _args.success = value_68; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + success: _args.success + }; + } +}; +export class CheckOptional__Result extends thrift.StructLike implements ICheckOptional__Result { + public success?: string; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: ICheckOptional__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_69: string = args.success; + this.success = value_69; + } + } + public static read(input: thrift.TProtocol): CheckOptional__Result { + return new CheckOptional__Result(CheckOptional__ResultCodec.decode(input)); + } + public static write(args: ICheckOptional__ResultArgs, output: thrift.TProtocol): void { + return CheckOptional__ResultCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return CheckOptional__ResultCodec.encode(this, output); + } +} +export interface IMapOneList__Result { + success?: Array; +} +export interface IMapOneList__ResultArgs { + success?: Array; +} +export const MapOneList__ResultCodec: thrift.IStructCodec = { + encode(args: IMapOneList__ResultArgs, output: thrift.TProtocol): void { + const obj = { + success: args.success + }; + output.writeStructBegin("MapOneList__Result"); + if (obj.success != null) { + output.writeFieldBegin("success", thrift.TType.LIST, 0); + output.writeListBegin(thrift.TType.I32, obj.success.length); + obj.success.forEach((value_70: number): void => { + output.writeI32(value_70); + }); + output.writeListEnd(); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IMapOneList__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.LIST) { + const value_71: Array = new Array(); + const metadata_5: thrift.IThriftList = input.readListBegin(); + const size_5: number = metadata_5.size; + for (let i_5: number = 0; i_5 < size_5; i_5++) { + const value_72: number = input.readI32(); + value_71.push(value_72); + } + input.readListEnd(); + _args.success = value_71; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + success: _args.success + }; + } +}; +export class MapOneList__Result extends thrift.StructLike implements IMapOneList__Result { + public success?: Array; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IMapOneList__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_73: Array = new Array(); + args.success.forEach((value_74: number): void => { + const value_75: number = value_74; + value_73.push(value_75); + }); + this.success = value_73; + } + } + public static read(input: thrift.TProtocol): MapOneList__Result { + return new MapOneList__Result(MapOneList__ResultCodec.decode(input)); + } + public static write(args: IMapOneList__ResultArgs, output: thrift.TProtocol): void { + return MapOneList__ResultCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return MapOneList__ResultCodec.encode(this, output); + } +} +export interface IMapValues__Result { + success?: Array; +} +export interface IMapValues__ResultArgs { + success?: Array; +} +export const MapValues__ResultCodec: thrift.IStructCodec = { + encode(args: IMapValues__ResultArgs, output: thrift.TProtocol): void { + const obj = { + success: args.success + }; + output.writeStructBegin("MapValues__Result"); + if (obj.success != null) { + output.writeFieldBegin("success", thrift.TType.LIST, 0); + output.writeListBegin(thrift.TType.I32, obj.success.length); + obj.success.forEach((value_76: number): void => { + output.writeI32(value_76); + }); + output.writeListEnd(); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IMapValues__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.LIST) { + const value_77: Array = new Array(); + const metadata_6: thrift.IThriftList = input.readListBegin(); + const size_6: number = metadata_6.size; + for (let i_6: number = 0; i_6 < size_6; i_6++) { + const value_78: number = input.readI32(); + value_77.push(value_78); + } + input.readListEnd(); + _args.success = value_77; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + success: _args.success + }; + } +}; +export class MapValues__Result extends thrift.StructLike implements IMapValues__Result { + public success?: Array; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IMapValues__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_79: Array = new Array(); + args.success.forEach((value_80: number): void => { + const value_81: number = value_80; + value_79.push(value_81); + }); + this.success = value_79; + } + } + public static read(input: thrift.TProtocol): MapValues__Result { + return new MapValues__Result(MapValues__ResultCodec.decode(input)); + } + public static write(args: IMapValues__ResultArgs, output: thrift.TProtocol): void { + return MapValues__ResultCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return MapValues__ResultCodec.encode(this, output); + } +} +export interface IListToMap__Result { + success?: Map; +} +export interface IListToMap__ResultArgs { + success?: Map; +} +export const ListToMap__ResultCodec: thrift.IStructCodec = { + encode(args: IListToMap__ResultArgs, output: thrift.TProtocol): void { + const obj = { + success: args.success + }; + output.writeStructBegin("ListToMap__Result"); + if (obj.success != null) { + output.writeFieldBegin("success", thrift.TType.MAP, 0); + output.writeMapBegin(thrift.TType.STRING, thrift.TType.STRING, obj.success.size); + obj.success.forEach((value_82: string, key_5: string): void => { + output.writeString(key_5); + output.writeString(value_82); + }); + output.writeMapEnd(); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IListToMap__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.MAP) { + const value_83: Map = new Map(); + const metadata_7: thrift.IThriftMap = input.readMapBegin(); + const size_7: number = metadata_7.size; + for (let i_7: number = 0; i_7 < size_7; i_7++) { + const key_6: string = input.readString(); + const value_84: string = input.readString(); + value_83.set(key_6, value_84); + } + input.readMapEnd(); + _args.success = value_83; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + success: _args.success + }; + } +}; +export class ListToMap__Result extends thrift.StructLike implements IListToMap__Result { + public success?: Map; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IListToMap__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_85: Map = new Map(); + args.success.forEach((value_86: string, key_7: string): void => { + const value_87: string = value_86; + const key_8: string = key_7; + value_85.set(key_8, value_87); + }); + this.success = value_85; + } + } + public static read(input: thrift.TProtocol): ListToMap__Result { + return new ListToMap__Result(ListToMap__ResultCodec.decode(input)); + } + public static write(args: IListToMap__ResultArgs, output: thrift.TProtocol): void { + return ListToMap__ResultCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return ListToMap__ResultCodec.encode(this, output); + } +} +export interface IFetchThing__Result { + success?: com_test_common.ICommonStruct; +} +export interface IFetchThing__ResultArgs { + success?: com_test_common.ICommonStructArgs; +} +export const FetchThing__ResultCodec: thrift.IStructCodec = { + encode(args: IFetchThing__ResultArgs, output: thrift.TProtocol): void { + const obj = { + success: args.success + }; + output.writeStructBegin("FetchThing__Result"); + if (obj.success != null) { + output.writeFieldBegin("success", thrift.TType.STRUCT, 0); + com_test_common.CommonStructCodec.encode(obj.success, output); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IFetchThing__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.STRUCT) { + const value_88: com_test_common.ICommonStruct = com_test_common.CommonStructCodec.decode(input); + _args.success = value_88; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + success: _args.success + }; + } +}; +export class FetchThing__Result extends thrift.StructLike implements IFetchThing__Result { + public success?: com_test_common.ICommonStruct; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IFetchThing__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_89: com_test_common.ICommonStruct = new com_test_common.CommonStruct(args.success); + this.success = value_89; + } + } + public static read(input: thrift.TProtocol): FetchThing__Result { + return new FetchThing__Result(FetchThing__ResultCodec.decode(input)); + } + public static write(args: IFetchThing__ResultArgs, output: thrift.TProtocol): void { + return FetchThing__ResultCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return FetchThing__ResultCodec.encode(this, output); + } +} +export interface IZip__Result { + success?: void; +} +export interface IZip__ResultArgs { + success?: void; +} +export const Zip__ResultCodec: thrift.IStructCodec = { + encode(args: IZip__ResultArgs, output: thrift.TProtocol): void { + output.writeStructBegin("Zip__Result"); + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IZip__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.VOID) { + input.skip(fieldType); + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + success: _args.success + }; + } +}; +export class Zip__Result extends thrift.StructLike implements IZip__Result { + public success?: void; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IZip__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_90: void = undefined; + this.success = value_90; + } + } + public static read(input: thrift.TProtocol): Zip__Result { + return new Zip__Result(Zip__ResultCodec.decode(input)); + } + public static write(args: IZip__ResultArgs, output: thrift.TProtocol): void { + return Zip__ResultCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return Zip__ResultCodec.encode(this, output); + } +} +export class Client extends com_test_shared.SharedService.Client { + public static readonly serviceName: string = serviceName; + public static readonly annotations: thrift.IThriftAnnotations = annotations; + public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public static readonly methodNames: Array = methodNames; + public readonly _serviceName: string = serviceName; + public readonly _annotations: thrift.IThriftAnnotations = annotations; + public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public readonly _methodNames: Array = methodNames; + constructor(connection: thrift.IThriftConnection) { + super(connection); + } + public ping(context?: Context): Promise { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("ping", thrift.MessageType.CALL, this.incrementRequestId()); + const args: IPing__ArgsArgs = {}; + Ping__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "ping") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); + } + else { + const result: IPing__Result = Ping__ResultCodec.decode(input); + input.readMessageEnd(); + return Promise.resolve(result.success); + } + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); + } + } + catch (err) { + return Promise.reject(err); + } + }); + } + public add(num1: number, num2: number, context?: Context): Promise { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("add", thrift.MessageType.CALL, this.incrementRequestId()); + const args: IAdd__ArgsArgs = { num1, num2 }; + Add__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "add") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); + } + else { + const result: IAdd__Result = Add__ResultCodec.decode(input); + input.readMessageEnd(); + if (result.exp != null) { + return Promise.reject(result.exp); + } + else if (result.success != null) { + return Promise.resolve(result.success); + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "add failed: unknown result")); + } + } + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); + } + } + catch (err) { + return Promise.reject(err); + } + }); + } + public addInt64(num1: number | string | thrift.Int64, num2: number | string | thrift.Int64, context?: Context): Promise { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("addInt64", thrift.MessageType.CALL, this.incrementRequestId()); + const args: IAddInt64__ArgsArgs = { num1, num2 }; + AddInt64__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "addInt64") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); + } + else { + const result: IAddInt64__Result = AddInt64__ResultCodec.decode(input); + input.readMessageEnd(); + if (result.exp != null) { + return Promise.reject(result.exp); + } + else if (result.success != null) { + return Promise.resolve(result.success); + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "addInt64 failed: unknown result")); + } + } + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); + } + } + catch (err) { + return Promise.reject(err); + } + }); + } + public addWithContext(num1: number, num2: number, context?: Context): Promise { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("addWithContext", thrift.MessageType.CALL, this.incrementRequestId()); + const args: IAddWithContext__ArgsArgs = { num1, num2 }; + AddWithContext__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "addWithContext") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); + } + else { + const result: IAddWithContext__Result = AddWithContext__ResultCodec.decode(input); + input.readMessageEnd(); + if (result.success != null) { + return Promise.resolve(result.success); + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "addWithContext failed: unknown result")); + } + } + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); + } + } + catch (err) { + return Promise.reject(err); + } + }); + } + public calculate(logid: number, work: __NAMESPACE__.IWorkArgs, context?: Context): Promise { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("calculate", thrift.MessageType.CALL, this.incrementRequestId()); + const args: ICalculate__ArgsArgs = { logid, work }; + Calculate__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "calculate") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); + } + else { + const result: ICalculate__Result = Calculate__ResultCodec.decode(input); + input.readMessageEnd(); + if (result.ouch != null) { + return Promise.reject(result.ouch); + } + else if (result.success != null) { + return Promise.resolve(result.success); + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "calculate failed: unknown result")); + } + } + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); + } + } + catch (err) { + return Promise.reject(err); + } + }); + } + public echoBinary(word: string | Buffer, context?: Context): Promise { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("echoBinary", thrift.MessageType.CALL, this.incrementRequestId()); + const args: IEchoBinary__ArgsArgs = { word }; + EchoBinary__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "echoBinary") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); + } + else { + const result: IEchoBinary__Result = EchoBinary__ResultCodec.decode(input); + input.readMessageEnd(); + if (result.success != null) { + return Promise.resolve(result.success); + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "echoBinary failed: unknown result")); + } + } + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); + } + } + catch (err) { + return Promise.reject(err); + } + }); + } + public echoString(word: string, context?: Context): Promise { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("echoString", thrift.MessageType.CALL, this.incrementRequestId()); + const args: IEchoString__ArgsArgs = { word }; + EchoString__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "echoString") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); + } + else { + const result: IEchoString__Result = EchoString__ResultCodec.decode(input); + input.readMessageEnd(); + if (result.success != null) { + return Promise.resolve(result.success); + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "echoString failed: unknown result")); + } + } + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); + } + } + catch (err) { + return Promise.reject(err); + } + }); + } + public checkName(choice: __NAMESPACE__.ChoiceArgs, context?: Context): Promise { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("checkName", thrift.MessageType.CALL, this.incrementRequestId()); + const args: ICheckName__ArgsArgs = { choice }; + CheckName__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "checkName") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); + } + else { + const result: ICheckName__Result = CheckName__ResultCodec.decode(input); + input.readMessageEnd(); + if (result.success != null) { + return Promise.resolve(result.success); + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "checkName failed: unknown result")); + } + } + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); + } + } + catch (err) { + return Promise.reject(err); + } + }); + } + public checkOptional(type?: string, context?: Context): Promise { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("checkOptional", thrift.MessageType.CALL, this.incrementRequestId()); + const args: ICheckOptional__ArgsArgs = { type }; + CheckOptional__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "checkOptional") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); + } + else { + const result: ICheckOptional__Result = CheckOptional__ResultCodec.decode(input); + input.readMessageEnd(); + if (result.success != null) { + return Promise.resolve(result.success); + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "checkOptional failed: unknown result")); + } + } + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); + } + } + catch (err) { + return Promise.reject(err); + } + }); + } + public mapOneList(arg: Array, context?: Context): Promise> { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("mapOneList", thrift.MessageType.CALL, this.incrementRequestId()); + const args: IMapOneList__ArgsArgs = { arg }; + MapOneList__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "mapOneList") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); + } + else { + const result: IMapOneList__Result = MapOneList__ResultCodec.decode(input); + input.readMessageEnd(); + if (result.success != null) { + return Promise.resolve(result.success); + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "mapOneList failed: unknown result")); + } + } + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); + } + } + catch (err) { + return Promise.reject(err); + } + }); + } + public mapValues(arg: Map, context?: Context): Promise> { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("mapValues", thrift.MessageType.CALL, this.incrementRequestId()); + const args: IMapValues__ArgsArgs = { arg }; + MapValues__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "mapValues") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); + } + else { + const result: IMapValues__Result = MapValues__ResultCodec.decode(input); + input.readMessageEnd(); + if (result.success != null) { + return Promise.resolve(result.success); + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "mapValues failed: unknown result")); + } + } + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); + } + } + catch (err) { + return Promise.reject(err); + } + }); + } + public listToMap(arg: Array>, context?: Context): Promise> { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("listToMap", thrift.MessageType.CALL, this.incrementRequestId()); + const args: IListToMap__ArgsArgs = { arg }; + ListToMap__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "listToMap") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); + } + else { + const result: IListToMap__Result = ListToMap__ResultCodec.decode(input); + input.readMessageEnd(); + if (result.success != null) { + return Promise.resolve(result.success); + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "listToMap failed: unknown result")); + } + } + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); + } + } + catch (err) { + return Promise.reject(err); + } + }); + } + public fetchThing(context?: Context): Promise { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("fetchThing", thrift.MessageType.CALL, this.incrementRequestId()); + const args: IFetchThing__ArgsArgs = {}; + FetchThing__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "fetchThing") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); + } + else { + const result: IFetchThing__Result = FetchThing__ResultCodec.decode(input); + input.readMessageEnd(); + if (result.success != null) { + return Promise.resolve(result.success); + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "fetchThing failed: unknown result")); + } + } + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); + } + } + catch (err) { + return Promise.reject(err); + } + }); + } + public zip(context?: Context): Promise { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("zip", thrift.MessageType.CALL, this.incrementRequestId()); + const args: IZip__ArgsArgs = {}; + Zip__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "zip") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); + } + else { + const result: IZip__Result = Zip__ResultCodec.decode(input); + input.readMessageEnd(); + return Promise.resolve(result.success); + } + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); + } + } + catch (err) { + return Promise.reject(err); + } + }); + } +} +export interface ILocalHandler { + ping(context?: Context): void | Promise; + add(num1: number, num2: number, context?: Context): number | Promise; + addInt64(num1: thrift.Int64, num2: thrift.Int64, context?: Context): (number | string | thrift.Int64) | Promise; + addWithContext(num1: number, num2: number, context?: Context): number | Promise; + calculate(logid: number, work: __NAMESPACE__.IWork, context?: Context): number | Promise; + echoBinary(word: Buffer, context?: Context): string | Promise; + echoString(word: string, context?: Context): string | Promise; + checkName(choice: __NAMESPACE__.Choice, context?: Context): string | Promise; + checkOptional(type?: string, context?: Context): string | Promise; + mapOneList(arg: Array, context?: Context): Array | Promise>; + mapValues(arg: Map, context?: Context): Array | Promise>; + listToMap(arg: Array>, context?: Context): Map | Promise>; + fetchThing(context?: Context): com_test_common.ICommonStructArgs | Promise; + zip(context?: Context): void | Promise; +} +export type IHandler = ILocalHandler & com_test_shared.SharedService.IHandler; +export class Processor extends com_test_shared.SharedService.Processor { + protected readonly _handler: IHandler; + public static readonly serviceName: string = serviceName; + public static readonly annotations: thrift.IThriftAnnotations = annotations; + public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public static readonly methodNames: Array = methodNames; + public readonly _serviceName: string = serviceName; + public readonly _annotations: thrift.IThriftAnnotations = annotations; + public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public readonly _methodNames: Array = methodNames; + constructor(handler: IHandler) { + super({ + getStruct: handler.getStruct, + getUnion: handler.getUnion + }); + this._handler = handler; + } + public process(input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + const metadata: thrift.IThriftMessage = input.readMessageBegin(); + const fieldName: string = metadata.fieldName; + const requestId: number = metadata.requestId; + const methodName: string = "process_" + fieldName; + switch (methodName) { + case "process_getStruct": { + resolve(this.process_getStruct(requestId, input, output, context)); + break; + } + case "process_getUnion": { + resolve(this.process_getUnion(requestId, input, output, context)); + break; + } + case "process_ping": { + resolve(this.process_ping(requestId, input, output, context)); + break; + } + case "process_add": { + resolve(this.process_add(requestId, input, output, context)); + break; + } + case "process_addInt64": { + resolve(this.process_addInt64(requestId, input, output, context)); + break; + } + case "process_addWithContext": { + resolve(this.process_addWithContext(requestId, input, output, context)); + break; + } + case "process_calculate": { + resolve(this.process_calculate(requestId, input, output, context)); + break; + } + case "process_echoBinary": { + resolve(this.process_echoBinary(requestId, input, output, context)); + break; + } + case "process_echoString": { + resolve(this.process_echoString(requestId, input, output, context)); + break; + } + case "process_checkName": { + resolve(this.process_checkName(requestId, input, output, context)); + break; + } + case "process_checkOptional": { + resolve(this.process_checkOptional(requestId, input, output, context)); + break; + } + case "process_mapOneList": { + resolve(this.process_mapOneList(requestId, input, output, context)); + break; + } + case "process_mapValues": { + resolve(this.process_mapValues(requestId, input, output, context)); + break; + } + case "process_listToMap": { + resolve(this.process_listToMap(requestId, input, output, context)); + break; + } + case "process_fetchThing": { + resolve(this.process_fetchThing(requestId, input, output, context)); + break; + } + case "process_zip": { + resolve(this.process_zip(requestId, input, output, context)); + break; + } + default: { + input.skip(thrift.TType.STRUCT); + input.readMessageEnd(); + const errMessage = "Unknown function " + fieldName; + const err = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN_METHOD, errMessage); + output.writeMessageBegin(fieldName, thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(err, output); + output.writeMessageEnd(); + resolve(output.flush()); + break; + } + } + }); + } + public process_ping(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + try { + input.readMessageEnd(); + resolve(this._handler.ping(context)); + } + catch (err) { + reject(err); + } + }).then((data: void): Buffer => { + const result: IPing__ResultArgs = { success: data }; + output.writeMessageBegin("ping", thrift.MessageType.REPLY, requestId); + Ping__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("ping", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }); + } + public process_add(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + try { + const args: IAdd__Args = Add__ArgsCodec.decode(input); + input.readMessageEnd(); + resolve(this._handler.add(args.num1, args.num2, context)); + } + catch (err) { + reject(err); + } + }).then((data: number): Buffer => { + const result: IAdd__ResultArgs = { success: data }; + output.writeMessageBegin("add", thrift.MessageType.REPLY, requestId); + Add__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + if (err instanceof com_test_operation.JankyResult) { + const result: IAdd__ResultArgs = { exp: err }; + output.writeMessageBegin("add", thrift.MessageType.REPLY, requestId); + Add__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + } + else { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("add", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + } + }); + } + public process_addInt64(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + try { + const args: IAddInt64__Args = AddInt64__ArgsCodec.decode(input); + input.readMessageEnd(); + resolve(this._handler.addInt64(args.num1, args.num2, context)); + } + catch (err) { + reject(err); + } + }).then((data: number | string | thrift.Int64): Buffer => { + const result: IAddInt64__ResultArgs = { success: data }; + output.writeMessageBegin("addInt64", thrift.MessageType.REPLY, requestId); + AddInt64__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + if (err instanceof __NAMESPACE__.NotAGoodIdea) { + const result: IAddInt64__ResultArgs = { exp: err }; + output.writeMessageBegin("addInt64", thrift.MessageType.REPLY, requestId); + AddInt64__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + } + else { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("addInt64", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + } + }); + } + public process_addWithContext(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + try { + const args: IAddWithContext__Args = AddWithContext__ArgsCodec.decode(input); + input.readMessageEnd(); + resolve(this._handler.addWithContext(args.num1, args.num2, context)); + } + catch (err) { + reject(err); + } + }).then((data: number): Buffer => { + const result: IAddWithContext__ResultArgs = { success: data }; + output.writeMessageBegin("addWithContext", thrift.MessageType.REPLY, requestId); + AddWithContext__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("addWithContext", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }); + } + public process_calculate(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + try { + const args: ICalculate__Args = Calculate__ArgsCodec.decode(input); + input.readMessageEnd(); + resolve(this._handler.calculate(args.logid, args.work, context)); + } + catch (err) { + reject(err); + } + }).then((data: number): Buffer => { + const result: ICalculate__ResultArgs = { success: data }; + output.writeMessageBegin("calculate", thrift.MessageType.REPLY, requestId); + Calculate__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + if (err instanceof com_test_operation.JankyOperation) { + const result: ICalculate__ResultArgs = { ouch: err }; + output.writeMessageBegin("calculate", thrift.MessageType.REPLY, requestId); + Calculate__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + } + else { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("calculate", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + } + }); + } + public process_echoBinary(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + try { + const args: IEchoBinary__Args = EchoBinary__ArgsCodec.decode(input); + input.readMessageEnd(); + resolve(this._handler.echoBinary(args.word, context)); + } + catch (err) { + reject(err); + } + }).then((data: string): Buffer => { + const result: IEchoBinary__ResultArgs = { success: data }; + output.writeMessageBegin("echoBinary", thrift.MessageType.REPLY, requestId); + EchoBinary__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("echoBinary", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }); + } + public process_echoString(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + try { + const args: IEchoString__Args = EchoString__ArgsCodec.decode(input); + input.readMessageEnd(); + resolve(this._handler.echoString(args.word, context)); + } + catch (err) { + reject(err); + } + }).then((data: string): Buffer => { + const result: IEchoString__ResultArgs = { success: data }; + output.writeMessageBegin("echoString", thrift.MessageType.REPLY, requestId); + EchoString__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("echoString", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }); + } + public process_checkName(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + try { + const args: ICheckName__Args = CheckName__ArgsCodec.decode(input); + input.readMessageEnd(); + resolve(this._handler.checkName(args.choice, context)); + } + catch (err) { + reject(err); + } + }).then((data: string): Buffer => { + const result: ICheckName__ResultArgs = { success: data }; + output.writeMessageBegin("checkName", thrift.MessageType.REPLY, requestId); + CheckName__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("checkName", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }); + } + public process_checkOptional(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + try { + const args: ICheckOptional__Args = CheckOptional__ArgsCodec.decode(input); + input.readMessageEnd(); + resolve(this._handler.checkOptional(args.type, context)); + } + catch (err) { + reject(err); + } + }).then((data: string): Buffer => { + const result: ICheckOptional__ResultArgs = { success: data }; + output.writeMessageBegin("checkOptional", thrift.MessageType.REPLY, requestId); + CheckOptional__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("checkOptional", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }); + } + public process_mapOneList(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise>((resolve, reject): void => { + try { + const args: IMapOneList__Args = MapOneList__ArgsCodec.decode(input); + input.readMessageEnd(); + resolve(this._handler.mapOneList(args.arg, context)); + } + catch (err) { + reject(err); + } + }).then((data: Array): Buffer => { + const result: IMapOneList__ResultArgs = { success: data }; + output.writeMessageBegin("mapOneList", thrift.MessageType.REPLY, requestId); + MapOneList__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("mapOneList", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }); + } + public process_mapValues(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise>((resolve, reject): void => { + try { + const args: IMapValues__Args = MapValues__ArgsCodec.decode(input); + input.readMessageEnd(); + resolve(this._handler.mapValues(args.arg, context)); + } + catch (err) { + reject(err); + } + }).then((data: Array): Buffer => { + const result: IMapValues__ResultArgs = { success: data }; + output.writeMessageBegin("mapValues", thrift.MessageType.REPLY, requestId); + MapValues__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("mapValues", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }); + } + public process_listToMap(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise>((resolve, reject): void => { + try { + const args: IListToMap__Args = ListToMap__ArgsCodec.decode(input); + input.readMessageEnd(); + resolve(this._handler.listToMap(args.arg, context)); + } + catch (err) { + reject(err); + } + }).then((data: Map): Buffer => { + const result: IListToMap__ResultArgs = { success: data }; + output.writeMessageBegin("listToMap", thrift.MessageType.REPLY, requestId); + ListToMap__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("listToMap", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }); + } + public process_fetchThing(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + try { + input.readMessageEnd(); + resolve(this._handler.fetchThing(context)); + } + catch (err) { + reject(err); + } + }).then((data: com_test_common.ICommonStructArgs): Buffer => { + const result: IFetchThing__ResultArgs = { success: data }; + output.writeMessageBegin("fetchThing", thrift.MessageType.REPLY, requestId); + FetchThing__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("fetchThing", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }); + } + public process_zip(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + try { + input.readMessageEnd(); + resolve(this._handler.zip(context)); + } + catch (err) { + reject(err); + } + }).then((data: void): Buffer => { + const result: IZip__ResultArgs = { success: data }; + output.writeMessageBegin("zip", thrift.MessageType.REPLY, requestId); + Zip__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("zip", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }); + } +} diff --git a/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/Choice.ts b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/Choice.ts new file mode 100644 index 00000000..f0bf3ac9 --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/Choice.ts @@ -0,0 +1,162 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v3.3.4 + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as thrift from "test-lib"; +import * as __NAMESPACE__ from "./."; +export enum ChoiceType { + ChoiceWithFirstName = "firstName", + ChoiceWithLastName = "lastName" +} +export type Choice = IChoiceWithFirstName | IChoiceWithLastName; +export interface IChoiceWithFirstName { + __type: ChoiceType.ChoiceWithFirstName; + firstName: __NAMESPACE__.IFirstName; + lastName?: undefined; +} +export interface IChoiceWithLastName { + __type: ChoiceType.ChoiceWithLastName; + firstName?: undefined; + lastName: __NAMESPACE__.ILastName; +} +export type ChoiceArgs = IChoiceWithFirstNameArgs | IChoiceWithLastNameArgs; +export interface IChoiceWithFirstNameArgs { + firstName: __NAMESPACE__.IFirstNameArgs; + lastName?: undefined; +} +export interface IChoiceWithLastNameArgs { + firstName?: undefined; + lastName: __NAMESPACE__.ILastNameArgs; +} +export const ChoiceCodec: thrift.IStructToolkit = { + create(args: ChoiceArgs): Choice { + let _fieldsSet: number = 0; + let _returnValue: any = null; + if (args.firstName != null) { + _fieldsSet++; + const value_1: __NAMESPACE__.IFirstName = new __NAMESPACE__.FirstName(args.firstName); + _returnValue = { firstName: value_1 }; + } + if (args.lastName != null) { + _fieldsSet++; + const value_2: __NAMESPACE__.ILastName = new __NAMESPACE__.LastName(args.lastName); + _returnValue = { lastName: value_2 }; + } + if (_fieldsSet > 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion cannot have more than one value"); + } + else if (_fieldsSet < 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion must have one value set"); + } + if (_returnValue !== null) { + if (_returnValue.firstName) { + return { + __type: ChoiceType.ChoiceWithFirstName, + firstName: _returnValue.firstName + }; + } + else { + return { + __type: ChoiceType.ChoiceWithLastName, + lastName: _returnValue.lastName + }; + } + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read data for TUnion"); + } + }, + encode(args: ChoiceArgs, output: thrift.TProtocol): void { + let _fieldsSet: number = 0; + const obj = { + firstName: args.firstName, + lastName: args.lastName + }; + output.writeStructBegin("Choice"); + if (obj.firstName != null) { + _fieldsSet++; + output.writeFieldBegin("firstName", thrift.TType.STRUCT, 1); + __NAMESPACE__.FirstNameCodec.encode(obj.firstName, output); + output.writeFieldEnd(); + } + if (obj.lastName != null) { + _fieldsSet++; + output.writeFieldBegin("lastName", thrift.TType.STRUCT, 2); + __NAMESPACE__.LastNameCodec.encode(obj.lastName, output); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + if (_fieldsSet > 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion cannot have more than one value"); + } + else if (_fieldsSet < 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion must have one value set"); + } + return; + }, + decode(input: thrift.TProtocol): Choice { + let _fieldsSet: number = 0; + let _returnValue: any = null; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.STRUCT) { + _fieldsSet++; + const value_3: __NAMESPACE__.IFirstName = __NAMESPACE__.FirstNameCodec.decode(input); + _returnValue = { firstName: value_3 }; + } + else { + input.skip(fieldType); + } + break; + case 2: + if (fieldType === thrift.TType.STRUCT) { + _fieldsSet++; + const value_4: __NAMESPACE__.ILastName = __NAMESPACE__.LastNameCodec.decode(input); + _returnValue = { lastName: value_4 }; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_fieldsSet > 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion cannot have more than one value"); + } + else if (_fieldsSet < 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion must have one value set"); + } + if (_returnValue !== null) { + if (_returnValue.firstName) { + return { + __type: ChoiceType.ChoiceWithFirstName, + firstName: _returnValue.firstName + }; + } + else { + return { + __type: ChoiceType.ChoiceWithLastName, + lastName: _returnValue.lastName + }; + } + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read data for TUnion"); + } + } +}; diff --git a/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/FirstName.ts b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/FirstName.ts new file mode 100644 index 00000000..728eadcd --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/FirstName.ts @@ -0,0 +1,80 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v3.3.4 + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as thrift from "test-lib"; +export interface IFirstName { + name?: string; +} +export interface IFirstNameArgs { + name?: string; +} +export const FirstNameCodec: thrift.IStructCodec = { + encode(args: IFirstNameArgs, output: thrift.TProtocol): void { + const obj = { + name: args.name + }; + output.writeStructBegin("FirstName"); + if (obj.name != null) { + output.writeFieldBegin("name", thrift.TType.STRING, 1); + output.writeString(obj.name); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IFirstName { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.STRING) { + const value_1: string = input.readString(); + _args.name = value_1; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + name: _args.name + }; + } +}; +export class FirstName extends thrift.StructLike implements IFirstName { + public name?: string; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IFirstNameArgs = {}) { + super(); + if (args.name != null) { + const value_2: string = args.name; + this.name = value_2; + } + } + public static read(input: thrift.TProtocol): FirstName { + return new FirstName(FirstNameCodec.decode(input)); + } + public static write(args: IFirstNameArgs, output: thrift.TProtocol): void { + return FirstNameCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return FirstNameCodec.encode(this, output); + } +} diff --git a/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/LastName.ts b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/LastName.ts new file mode 100644 index 00000000..cde47823 --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/LastName.ts @@ -0,0 +1,80 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v3.3.4 + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as thrift from "test-lib"; +export interface ILastName { + name?: string; +} +export interface ILastNameArgs { + name?: string; +} +export const LastNameCodec: thrift.IStructCodec = { + encode(args: ILastNameArgs, output: thrift.TProtocol): void { + const obj = { + name: args.name + }; + output.writeStructBegin("LastName"); + if (obj.name != null) { + output.writeFieldBegin("name", thrift.TType.STRING, 1); + output.writeString(obj.name); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): ILastName { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.STRING) { + const value_1: string = input.readString(); + _args.name = value_1; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + name: _args.name + }; + } +}; +export class LastName extends thrift.StructLike implements ILastName { + public name?: string; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: ILastNameArgs = {}) { + super(); + if (args.name != null) { + const value_2: string = args.name; + this.name = value_2; + } + } + public static read(input: thrift.TProtocol): LastName { + return new LastName(LastNameCodec.decode(input)); + } + public static write(args: ILastNameArgs, output: thrift.TProtocol): void { + return LastNameCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return LastNameCodec.encode(this, output); + } +} diff --git a/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/NotAGoodIdea.ts b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/NotAGoodIdea.ts new file mode 100644 index 00000000..c5d75150 --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/NotAGoodIdea.ts @@ -0,0 +1,80 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v3.3.4 + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as thrift from "test-lib"; +export interface INotAGoodIdea { + message?: string; +} +export interface INotAGoodIdeaArgs { + message?: string; +} +export const NotAGoodIdeaCodec: thrift.IStructCodec = { + encode(args: INotAGoodIdeaArgs, output: thrift.TProtocol): void { + const obj = { + message: args.message + }; + output.writeStructBegin("NotAGoodIdea"); + if (obj.message != null) { + output.writeFieldBegin("message", thrift.TType.STRING, 1); + output.writeString(obj.message); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): INotAGoodIdea { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.STRING) { + const value_1: string = input.readString(); + _args.message = value_1; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + message: _args.message + }; + } +}; +export class NotAGoodIdea extends thrift.StructLike implements INotAGoodIdea { + public message?: string; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: INotAGoodIdeaArgs = {}) { + super(); + if (args.message != null) { + const value_2: string = args.message; + this.message = value_2; + } + } + public static read(input: thrift.TProtocol): NotAGoodIdea { + return new NotAGoodIdea(NotAGoodIdeaCodec.decode(input)); + } + public static write(args: INotAGoodIdeaArgs, output: thrift.TProtocol): void { + return NotAGoodIdeaCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return NotAGoodIdeaCodec.encode(this, output); + } +} diff --git a/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/Work.ts b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/Work.ts new file mode 100644 index 00000000..6fe13f6d --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/Work.ts @@ -0,0 +1,161 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as thrift from "test-lib"; +import * as __NAMESPACE__ from "./."; +export interface IWork { + num1: number; + num2: number; + op?: __NAMESPACE__.Operation; + comment?: string; +} +export interface IWorkArgs { + num1?: number; + num2: number; + op?: __NAMESPACE__.Operation; + comment?: string; +} +export const WorkCodec: thrift.IStructCodec = { + encode(args: IWorkArgs, output: thrift.TProtocol): void { + const obj = { + num1: (args.num1 != null ? args.num1 : 0), + num2: args.num2, + op: (args.op != null ? args.op : __NAMESPACE__.Operation.ADD), + comment: args.comment + }; + output.writeStructBegin("Work"); + if (obj.num1 != null) { + output.writeFieldBegin("num1", thrift.TType.I32, 1); + output.writeI32(obj.num1); + output.writeFieldEnd(); + } + if (obj.num2 != null) { + output.writeFieldBegin("num2", thrift.TType.I32, 2); + output.writeI32(obj.num2); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num2] is unset!"); + } + if (obj.op != null) { + output.writeFieldBegin("op", thrift.TType.I32, 3); + output.writeI32(obj.op); + output.writeFieldEnd(); + } + if (obj.comment != null) { + output.writeFieldBegin("comment", thrift.TType.STRING, 4); + output.writeString(obj.comment); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IWork { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.I32) { + const value_1: number = input.readI32(); + _args.num1 = value_1; + } + else { + input.skip(fieldType); + } + break; + case 2: + if (fieldType === thrift.TType.I32) { + const value_2: number = input.readI32(); + _args.num2 = value_2; + } + else { + input.skip(fieldType); + } + break; + case 3: + if (fieldType === thrift.TType.I32) { + const value_3: __NAMESPACE__.Operation = input.readI32(); + _args.op = value_3; + } + else { + input.skip(fieldType); + } + break; + case 4: + if (fieldType === thrift.TType.STRING) { + const value_4: string = input.readString(); + _args.comment = value_4; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.num1 !== undefined && _args.num2 !== undefined) { + return { + num1: (_args.num1 != null ? _args.num1 : 0), + num2: _args.num2, + op: (_args.op != null ? _args.op : __NAMESPACE__.Operation.ADD), + comment: _args.comment + }; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read Work from input"); + } + } +}; +export class Work extends thrift.StructLike implements IWork { + public num1: number = 0; + public num2: number; + public op?: __NAMESPACE__.Operation = __NAMESPACE__.Operation.ADD; + public comment?: string; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IWorkArgs) { + super(); + if (args.num1 != null) { + const value_5: number = args.num1; + this.num1 = value_5; + } + if (args.num2 != null) { + const value_6: number = args.num2; + this.num2 = value_6; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num2] is unset!"); + } + if (args.op != null) { + const value_7: __NAMESPACE__.Operation = args.op; + this.op = value_7; + } + if (args.comment != null) { + const value_8: string = args.comment; + this.comment = value_8; + } + } + public static read(input: thrift.TProtocol): Work { + return new Work(WorkCodec.decode(input)); + } + public static write(args: IWorkArgs, output: thrift.TProtocol): void { + return WorkCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return WorkCodec.encode(this, output); + } +} diff --git a/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/constants.ts b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/constants.ts new file mode 100644 index 00000000..25df30a5 --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/constants.ts @@ -0,0 +1,7 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v3.3.4 + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +export const INT32CONSTANT: number = 9853; +export const MAPCONSTANT: Map = new Map([["hello", "world"], ["goodnight", "moon"]]); diff --git a/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/index.ts b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/index.ts new file mode 100644 index 00000000..1a997082 --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/index.ts @@ -0,0 +1,14 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v3.3.4 + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +export * from "./constants"; +export * from "./typedefs"; +export * from "./Work"; +export * from "./FirstName"; +export * from "./LastName"; +export * from "./Choice"; +export * from "./NotAGoodIdea"; +import * as Calculator from "./Calculator"; +export { Calculator as Calculator }; diff --git a/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/typedefs.ts b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/typedefs.ts new file mode 100644 index 00000000..ba2b340d --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/typedefs.ts @@ -0,0 +1,13 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v3.3.4 + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as com_test_operation from "./../operation"; +import * as com_test_common from "./../common"; +export type MyInteger = number; +export import Operation = com_test_operation.Operation; +export import ICommonStruct = com_test_common.ICommonStruct; +export import ICommonStructArgs = com_test_common.ICommonStructArgs; +export import CommonStruct = com_test_common.CommonStruct; +export import CommonStructCodec = com_test_common.CommonStructCodec; diff --git a/src/tests/unit/fixtures/generated/strict-unions/common/index.ts b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/common/AuthException.ts similarity index 79% rename from src/tests/unit/fixtures/generated/strict-unions/common/index.ts rename to src/tests/unit/fixtures/thrift-server/generated-strict/com/test/common/AuthException.ts index 23d86821..f548ce47 100644 --- a/src/tests/unit/fixtures/generated/strict-unions/common/index.ts +++ b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/common/AuthException.ts @@ -1,23 +1,9 @@ /* tslint:disable */ /* - * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * Autogenerated by @creditkarma/thrift-typescript v3.3.4 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING */ import * as thrift from "test-lib"; -import * as shared from "./../shared"; -export import ICommonStruct = shared.ISharedStruct; -export import ICommonStructArgs = shared.ISharedStructArgs; -export import CommonStruct = shared.SharedStruct; -export import CommonStructCodec = shared.SharedStructCodec; -export import CommonUnion__Type = shared.SharedUnion__Type; -export import CommonUnion = shared.SharedUnion; -export import ICommonUnionWithOption1 = shared.ISharedUnionWithOption1; -export import ICommonUnionWithOption2 = shared.ISharedUnionWithOption2; -export import CommonUnionArgs = shared.SharedUnionArgs; -export import ICommonUnionWithOption1Args = shared.ISharedUnionWithOption1Args; -export import ICommonUnionWithOption2Args = shared.ISharedUnionWithOption2Args; -export import CommonUnionCodec = shared.SharedUnionCodec; -export import COMMON_INT = shared.SHARED_INT; export interface IAuthException { code?: number; message?: string; diff --git a/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/common/OtherCommonUnion.ts b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/common/OtherCommonUnion.ts new file mode 100644 index 00000000..b87cade6 --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/common/OtherCommonUnion.ts @@ -0,0 +1,161 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v3.3.4 + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as thrift from "test-lib"; +export enum OtherCommonUnionType { + OtherCommonUnionWithOption1 = "option1", + OtherCommonUnionWithOption2 = "option2" +} +export type OtherCommonUnion = IOtherCommonUnionWithOption1 | IOtherCommonUnionWithOption2; +export interface IOtherCommonUnionWithOption1 { + __type: OtherCommonUnionType.OtherCommonUnionWithOption1; + option1: string; + option2?: undefined; +} +export interface IOtherCommonUnionWithOption2 { + __type: OtherCommonUnionType.OtherCommonUnionWithOption2; + option1?: undefined; + option2: number; +} +export type OtherCommonUnionArgs = IOtherCommonUnionWithOption1Args | IOtherCommonUnionWithOption2Args; +export interface IOtherCommonUnionWithOption1Args { + option1: string; + option2?: undefined; +} +export interface IOtherCommonUnionWithOption2Args { + option1?: undefined; + option2: number; +} +export const OtherCommonUnionCodec: thrift.IStructToolkit = { + create(args: OtherCommonUnionArgs): OtherCommonUnion { + let _fieldsSet: number = 0; + let _returnValue: any = null; + if (args.option1 != null) { + _fieldsSet++; + const value_1: string = args.option1; + _returnValue = { option1: value_1 }; + } + if (args.option2 != null) { + _fieldsSet++; + const value_2: number = args.option2; + _returnValue = { option2: value_2 }; + } + if (_fieldsSet > 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion cannot have more than one value"); + } + else if (_fieldsSet < 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion must have one value set"); + } + if (_returnValue !== null) { + if (_returnValue.option1) { + return { + __type: OtherCommonUnionType.OtherCommonUnionWithOption1, + option1: _returnValue.option1 + }; + } + else { + return { + __type: OtherCommonUnionType.OtherCommonUnionWithOption2, + option2: _returnValue.option2 + }; + } + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read data for TUnion"); + } + }, + encode(args: OtherCommonUnionArgs, output: thrift.TProtocol): void { + let _fieldsSet: number = 0; + const obj = { + option1: args.option1, + option2: args.option2 + }; + output.writeStructBegin("OtherCommonUnion"); + if (obj.option1 != null) { + _fieldsSet++; + output.writeFieldBegin("option1", thrift.TType.STRING, 1); + output.writeString(obj.option1); + output.writeFieldEnd(); + } + if (obj.option2 != null) { + _fieldsSet++; + output.writeFieldBegin("option2", thrift.TType.I32, 2); + output.writeI32(obj.option2); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + if (_fieldsSet > 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion cannot have more than one value"); + } + else if (_fieldsSet < 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion must have one value set"); + } + return; + }, + decode(input: thrift.TProtocol): OtherCommonUnion { + let _fieldsSet: number = 0; + let _returnValue: any = null; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.STRING) { + _fieldsSet++; + const value_3: string = input.readString(); + _returnValue = { option1: value_3 }; + } + else { + input.skip(fieldType); + } + break; + case 2: + if (fieldType === thrift.TType.I32) { + _fieldsSet++; + const value_4: number = input.readI32(); + _returnValue = { option2: value_4 }; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_fieldsSet > 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion cannot have more than one value"); + } + else if (_fieldsSet < 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion must have one value set"); + } + if (_returnValue !== null) { + if (_returnValue.option1) { + return { + __type: OtherCommonUnionType.OtherCommonUnionWithOption1, + option1: _returnValue.option1 + }; + } + else { + return { + __type: OtherCommonUnionType.OtherCommonUnionWithOption2, + option2: _returnValue.option2 + }; + } + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read data for TUnion"); + } + } +}; diff --git a/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/common/index.ts b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/common/index.ts new file mode 100644 index 00000000..e58427d6 --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/common/index.ts @@ -0,0 +1,8 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v3.3.4 + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +export * from "./typedefs"; +export * from "./OtherCommonUnion"; +export * from "./AuthException"; diff --git a/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/common/typedefs.ts b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/common/typedefs.ts new file mode 100644 index 00000000..f04332ac --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/common/typedefs.ts @@ -0,0 +1,32 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v3.3.4 + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as com_test_shared from "./../shared"; +import * as __NAMESPACE__ from "./."; +export import ICommonStruct = com_test_shared.ISharedStruct; +export import ICommonStructArgs = com_test_shared.ISharedStructArgs; +export import CommonStruct = com_test_shared.SharedStruct; +export import CommonStructCodec = com_test_shared.SharedStructCodec; +export import CommonUnionType = com_test_shared.SharedUnionType; +export import CommonUnion = com_test_shared.SharedUnion; +export import ICommonUnionWithOption1 = com_test_shared.ISharedUnionWithOption1; +export import ICommonUnionWithOption2 = com_test_shared.ISharedUnionWithOption2; +export import CommonUnionArgs = com_test_shared.SharedUnionArgs; +export import ICommonUnionWithOption1Args = com_test_shared.ISharedUnionWithOption1Args; +export import ICommonUnionWithOption2Args = com_test_shared.ISharedUnionWithOption2Args; +export import CommonUnionCodec = com_test_shared.SharedUnionCodec; +export import COMMON_INT = com_test_shared.SHARED_INT; +export import INotAllowed = __NAMESPACE__.IAuthException; +export import INotAllowedArgs = __NAMESPACE__.IAuthExceptionArgs; +export import NotAllowed = __NAMESPACE__.AuthException; +export import NotAllowedCodec = __NAMESPACE__.AuthExceptionCodec; +export import MoreOptionsType = __NAMESPACE__.OtherCommonUnionType; +export import MoreOptions = __NAMESPACE__.OtherCommonUnion; +export import IMoreOptionsWithOption1 = __NAMESPACE__.IOtherCommonUnionWithOption1; +export import IMoreOptionsWithOption2 = __NAMESPACE__.IOtherCommonUnionWithOption2; +export import MoreOptionsArgs = __NAMESPACE__.OtherCommonUnionArgs; +export import IMoreOptionsWithOption1Args = __NAMESPACE__.IOtherCommonUnionWithOption1Args; +export import IMoreOptionsWithOption2Args = __NAMESPACE__.IOtherCommonUnionWithOption2Args; +export import MoreOptionsCodec = __NAMESPACE__.OtherCommonUnionCodec; diff --git a/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/exceptions/InvalidOperation.ts b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/exceptions/InvalidOperation.ts new file mode 100644 index 00000000..4bf5b462 --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/exceptions/InvalidOperation.ts @@ -0,0 +1,103 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v3.3.4 + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as thrift from "test-lib"; +export interface IInvalidOperation { + whatOp?: number; + why?: string; +} +export interface IInvalidOperationArgs { + whatOp?: number; + why?: string; +} +export const InvalidOperationCodec: thrift.IStructCodec = { + encode(args: IInvalidOperationArgs, output: thrift.TProtocol): void { + const obj = { + whatOp: args.whatOp, + why: args.why + }; + output.writeStructBegin("InvalidOperation"); + if (obj.whatOp != null) { + output.writeFieldBegin("whatOp", thrift.TType.I32, 1); + output.writeI32(obj.whatOp); + output.writeFieldEnd(); + } + if (obj.why != null) { + output.writeFieldBegin("why", thrift.TType.STRING, 2); + output.writeString(obj.why); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IInvalidOperation { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.I32) { + const value_1: number = input.readI32(); + _args.whatOp = value_1; + } + else { + input.skip(fieldType); + } + break; + case 2: + if (fieldType === thrift.TType.STRING) { + const value_2: string = input.readString(); + _args.why = value_2; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + whatOp: _args.whatOp, + why: _args.why + }; + } +}; +export class InvalidOperation extends thrift.StructLike implements IInvalidOperation { + public whatOp?: number; + public why?: string; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IInvalidOperationArgs = {}) { + super(); + if (args.whatOp != null) { + const value_3: number = args.whatOp; + this.whatOp = value_3; + } + if (args.why != null) { + const value_4: string = args.why; + this.why = value_4; + } + } + public static read(input: thrift.TProtocol): InvalidOperation { + return new InvalidOperation(InvalidOperationCodec.decode(input)); + } + public static write(args: IInvalidOperationArgs, output: thrift.TProtocol): void { + return InvalidOperationCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return InvalidOperationCodec.encode(this, output); + } +} diff --git a/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/exceptions/InvalidResult.ts b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/exceptions/InvalidResult.ts new file mode 100644 index 00000000..8dc81b3e --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/exceptions/InvalidResult.ts @@ -0,0 +1,104 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v3.3.4 + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as thrift from "test-lib"; +import * as com_test_shared from "./../shared"; +export interface IInvalidResult { + message?: string; + code?: com_test_shared.ICode; +} +export interface IInvalidResultArgs { + message?: string; + code?: com_test_shared.ICodeArgs; +} +export const InvalidResultCodec: thrift.IStructCodec = { + encode(args: IInvalidResultArgs, output: thrift.TProtocol): void { + const obj = { + message: args.message, + code: args.code + }; + output.writeStructBegin("InvalidResult"); + if (obj.message != null) { + output.writeFieldBegin("message", thrift.TType.STRING, 1); + output.writeString(obj.message); + output.writeFieldEnd(); + } + if (obj.code != null) { + output.writeFieldBegin("code", thrift.TType.STRUCT, 2); + com_test_shared.CodeCodec.encode(obj.code, output); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IInvalidResult { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.STRING) { + const value_1: string = input.readString(); + _args.message = value_1; + } + else { + input.skip(fieldType); + } + break; + case 2: + if (fieldType === thrift.TType.STRUCT) { + const value_2: com_test_shared.ICode = com_test_shared.CodeCodec.decode(input); + _args.code = value_2; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + message: _args.message, + code: _args.code + }; + } +}; +export class InvalidResult extends thrift.StructLike implements IInvalidResult { + public message?: string; + public code?: com_test_shared.ICode; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IInvalidResultArgs = {}) { + super(); + if (args.message != null) { + const value_3: string = args.message; + this.message = value_3; + } + if (args.code != null) { + const value_4: com_test_shared.ICode = new com_test_shared.Code(args.code); + this.code = value_4; + } + } + public static read(input: thrift.TProtocol): InvalidResult { + return new InvalidResult(InvalidResultCodec.decode(input)); + } + public static write(args: IInvalidResultArgs, output: thrift.TProtocol): void { + return InvalidResultCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return InvalidResultCodec.encode(this, output); + } +} diff --git a/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/exceptions/index.ts b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/exceptions/index.ts new file mode 100644 index 00000000..6605e142 --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/exceptions/index.ts @@ -0,0 +1,7 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v3.3.4 + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +export * from "./InvalidOperation"; +export * from "./InvalidResult"; diff --git a/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/operation/constants.ts b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/operation/constants.ts new file mode 100644 index 00000000..b3a47dce --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/operation/constants.ts @@ -0,0 +1,11 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v3.3.4 + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +export enum Operation { + ADD = 1, + SUBTRACT = 2, + MULTIPLY = 3, + DIVIDE = 4 +} diff --git a/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/operation/index.ts b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/operation/index.ts new file mode 100644 index 00000000..06848dab --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/operation/index.ts @@ -0,0 +1,7 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v3.3.4 + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +export * from "./constants"; +export * from "./typedefs"; diff --git a/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/operation/typedefs.ts b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/operation/typedefs.ts new file mode 100644 index 00000000..e8ea4462 --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/operation/typedefs.ts @@ -0,0 +1,16 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v3.3.4 + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as com_test_exceptions from "./../exceptions"; +import * as __NAMESPACE__ from "./."; +export import IJankyOperation = com_test_exceptions.IInvalidOperation; +export import IJankyOperationArgs = com_test_exceptions.IInvalidOperationArgs; +export import JankyOperation = com_test_exceptions.InvalidOperation; +export import JankyOperationCodec = com_test_exceptions.InvalidOperationCodec; +export import IJankyResult = com_test_exceptions.IInvalidResult; +export import IJankyResultArgs = com_test_exceptions.IInvalidResultArgs; +export import JankyResult = com_test_exceptions.InvalidResult; +export import JankyResultCodec = com_test_exceptions.InvalidResultCodec; +export import SomethingToDo = __NAMESPACE__.Operation; diff --git a/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/shared/Code.ts b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/shared/Code.ts new file mode 100644 index 00000000..555c31ef --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/shared/Code.ts @@ -0,0 +1,80 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v3.3.4 + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as thrift from "test-lib"; +export interface ICode { + status?: thrift.Int64; +} +export interface ICodeArgs { + status?: number | string | thrift.Int64; +} +export const CodeCodec: thrift.IStructCodec = { + encode(args: ICodeArgs, output: thrift.TProtocol): void { + const obj = { + status: (typeof args.status === "number" ? new thrift.Int64(args.status) : typeof args.status === "string" ? thrift.Int64.fromDecimalString(args.status) : args.status) + }; + output.writeStructBegin("Code"); + if (obj.status != null) { + output.writeFieldBegin("status", thrift.TType.I64, 1); + output.writeI64((typeof obj.status === "number" ? new thrift.Int64(obj.status) : typeof obj.status === "string" ? thrift.Int64.fromDecimalString(obj.status) : obj.status)); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): ICode { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.I64) { + const value_1: thrift.Int64 = input.readI64(); + _args.status = value_1; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + status: _args.status + }; + } +}; +export class Code extends thrift.StructLike implements ICode { + public status?: thrift.Int64; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: ICodeArgs = {}) { + super(); + if (args.status != null) { + const value_2: thrift.Int64 = (typeof args.status === "number" ? new thrift.Int64(args.status) : typeof args.status === "string" ? thrift.Int64.fromDecimalString(args.status) : args.status); + this.status = value_2; + } + } + public static read(input: thrift.TProtocol): Code { + return new Code(CodeCodec.decode(input)); + } + public static write(args: ICodeArgs, output: thrift.TProtocol): void { + return CodeCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return CodeCodec.encode(this, output); + } +} diff --git a/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/shared/SharedService.ts b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/shared/SharedService.ts new file mode 100644 index 00000000..3e690a4b --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/shared/SharedService.ts @@ -0,0 +1,520 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v3.3.4 + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as thrift from "test-lib"; +import * as __NAMESPACE__ from "./."; +export const serviceName: string = "SharedService"; +export const annotations: thrift.IThriftAnnotations = {}; +export const methodAnnotations: thrift.IMethodAnnotations = { + getStruct: { + annotations: {}, + fieldAnnotations: {} + }, + getUnion: { + annotations: {}, + fieldAnnotations: {} + } +}; +export const methodNames: Array = ["getStruct", "getUnion"]; +export interface IGetStruct__Args { + key: number; +} +export interface IGetStruct__ArgsArgs { + key: number; +} +export const GetStruct__ArgsCodec: thrift.IStructCodec = { + encode(args: IGetStruct__ArgsArgs, output: thrift.TProtocol): void { + const obj = { + key: args.key + }; + output.writeStructBegin("GetStruct__Args"); + if (obj.key != null) { + output.writeFieldBegin("key", thrift.TType.I32, 1); + output.writeI32(obj.key); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[key] is unset!"); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IGetStruct__Args { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.I32) { + const value_1: number = input.readI32(); + _args.key = value_1; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.key !== undefined) { + return { + key: _args.key + }; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read GetStruct__Args from input"); + } + } +}; +export class GetStruct__Args extends thrift.StructLike implements IGetStruct__Args { + public key: number; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IGetStruct__ArgsArgs) { + super(); + if (args.key != null) { + const value_2: number = args.key; + this.key = value_2; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[key] is unset!"); + } + } + public static read(input: thrift.TProtocol): GetStruct__Args { + return new GetStruct__Args(GetStruct__ArgsCodec.decode(input)); + } + public static write(args: IGetStruct__ArgsArgs, output: thrift.TProtocol): void { + return GetStruct__ArgsCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return GetStruct__ArgsCodec.encode(this, output); + } +} +export interface IGetUnion__Args { + index: number; +} +export interface IGetUnion__ArgsArgs { + index: number; +} +export const GetUnion__ArgsCodec: thrift.IStructCodec = { + encode(args: IGetUnion__ArgsArgs, output: thrift.TProtocol): void { + const obj = { + index: args.index + }; + output.writeStructBegin("GetUnion__Args"); + if (obj.index != null) { + output.writeFieldBegin("index", thrift.TType.I32, 1); + output.writeI32(obj.index); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[index] is unset!"); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IGetUnion__Args { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.I32) { + const value_3: number = input.readI32(); + _args.index = value_3; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.index !== undefined) { + return { + index: _args.index + }; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read GetUnion__Args from input"); + } + } +}; +export class GetUnion__Args extends thrift.StructLike implements IGetUnion__Args { + public index: number; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IGetUnion__ArgsArgs) { + super(); + if (args.index != null) { + const value_4: number = args.index; + this.index = value_4; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[index] is unset!"); + } + } + public static read(input: thrift.TProtocol): GetUnion__Args { + return new GetUnion__Args(GetUnion__ArgsCodec.decode(input)); + } + public static write(args: IGetUnion__ArgsArgs, output: thrift.TProtocol): void { + return GetUnion__ArgsCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return GetUnion__ArgsCodec.encode(this, output); + } +} +export interface IGetStruct__Result { + success?: __NAMESPACE__.ISharedStruct; +} +export interface IGetStruct__ResultArgs { + success?: __NAMESPACE__.ISharedStructArgs; +} +export const GetStruct__ResultCodec: thrift.IStructCodec = { + encode(args: IGetStruct__ResultArgs, output: thrift.TProtocol): void { + const obj = { + success: args.success + }; + output.writeStructBegin("GetStruct__Result"); + if (obj.success != null) { + output.writeFieldBegin("success", thrift.TType.STRUCT, 0); + __NAMESPACE__.SharedStructCodec.encode(obj.success, output); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IGetStruct__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.STRUCT) { + const value_5: __NAMESPACE__.ISharedStruct = __NAMESPACE__.SharedStructCodec.decode(input); + _args.success = value_5; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + success: _args.success + }; + } +}; +export class GetStruct__Result extends thrift.StructLike implements IGetStruct__Result { + public success?: __NAMESPACE__.ISharedStruct; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IGetStruct__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_6: __NAMESPACE__.ISharedStruct = new __NAMESPACE__.SharedStruct(args.success); + this.success = value_6; + } + } + public static read(input: thrift.TProtocol): GetStruct__Result { + return new GetStruct__Result(GetStruct__ResultCodec.decode(input)); + } + public static write(args: IGetStruct__ResultArgs, output: thrift.TProtocol): void { + return GetStruct__ResultCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return GetStruct__ResultCodec.encode(this, output); + } +} +export interface IGetUnion__Result { + success?: __NAMESPACE__.SharedUnion; +} +export interface IGetUnion__ResultArgs { + success?: __NAMESPACE__.SharedUnionArgs; +} +export const GetUnion__ResultCodec: thrift.IStructCodec = { + encode(args: IGetUnion__ResultArgs, output: thrift.TProtocol): void { + const obj = { + success: args.success + }; + output.writeStructBegin("GetUnion__Result"); + if (obj.success != null) { + output.writeFieldBegin("success", thrift.TType.STRUCT, 0); + __NAMESPACE__.SharedUnionCodec.encode(obj.success, output); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IGetUnion__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.STRUCT) { + const value_7: __NAMESPACE__.SharedUnion = __NAMESPACE__.SharedUnionCodec.decode(input); + _args.success = value_7; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + success: _args.success + }; + } +}; +export class GetUnion__Result extends thrift.StructLike implements IGetUnion__Result { + public success?: __NAMESPACE__.SharedUnion; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IGetUnion__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_8: __NAMESPACE__.SharedUnion = __NAMESPACE__.SharedUnionCodec.create(args.success); + this.success = value_8; + } + } + public static read(input: thrift.TProtocol): GetUnion__Result { + return new GetUnion__Result(GetUnion__ResultCodec.decode(input)); + } + public static write(args: IGetUnion__ResultArgs, output: thrift.TProtocol): void { + return GetUnion__ResultCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return GetUnion__ResultCodec.encode(this, output); + } +} +export class Client extends thrift.ThriftClient { + public static readonly serviceName: string = serviceName; + public static readonly annotations: thrift.IThriftAnnotations = annotations; + public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public static readonly methodNames: Array = methodNames; + public readonly _serviceName: string = serviceName; + public readonly _annotations: thrift.IThriftAnnotations = annotations; + public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public readonly _methodNames: Array = methodNames; + public getStruct(key: number, context?: Context): Promise<__NAMESPACE__.ISharedStruct> { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("getStruct", thrift.MessageType.CALL, this.incrementRequestId()); + const args: IGetStruct__ArgsArgs = { key }; + GetStruct__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "getStruct") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); + } + else { + const result: IGetStruct__Result = GetStruct__ResultCodec.decode(input); + input.readMessageEnd(); + if (result.success != null) { + return Promise.resolve(result.success); + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "getStruct failed: unknown result")); + } + } + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); + } + } + catch (err) { + return Promise.reject(err); + } + }); + } + public getUnion(index: number, context?: Context): Promise<__NAMESPACE__.SharedUnion> { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("getUnion", thrift.MessageType.CALL, this.incrementRequestId()); + const args: IGetUnion__ArgsArgs = { index }; + GetUnion__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "getUnion") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); + } + else { + const result: IGetUnion__Result = GetUnion__ResultCodec.decode(input); + input.readMessageEnd(); + if (result.success != null) { + return Promise.resolve(result.success); + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "getUnion failed: unknown result")); + } + } + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); + } + } + catch (err) { + return Promise.reject(err); + } + }); + } +} +export interface IHandler { + getStruct(key: number, context?: Context): __NAMESPACE__.ISharedStructArgs | Promise<__NAMESPACE__.ISharedStructArgs>; + getUnion(index: number, context?: Context): __NAMESPACE__.SharedUnionArgs | Promise<__NAMESPACE__.SharedUnionArgs>; +} +export class Processor extends thrift.ThriftProcessor> { + protected readonly _handler: IHandler; + public static readonly serviceName: string = serviceName; + public static readonly annotations: thrift.IThriftAnnotations = annotations; + public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public static readonly methodNames: Array = methodNames; + public readonly _serviceName: string = serviceName; + public readonly _annotations: thrift.IThriftAnnotations = annotations; + public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public readonly _methodNames: Array = methodNames; + constructor(handler: IHandler) { + super(); + this._handler = handler; + } + public process(input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + const metadata: thrift.IThriftMessage = input.readMessageBegin(); + const fieldName: string = metadata.fieldName; + const requestId: number = metadata.requestId; + const methodName: string = "process_" + fieldName; + switch (methodName) { + case "process_getStruct": { + resolve(this.process_getStruct(requestId, input, output, context)); + break; + } + case "process_getUnion": { + resolve(this.process_getUnion(requestId, input, output, context)); + break; + } + default: { + input.skip(thrift.TType.STRUCT); + input.readMessageEnd(); + const errMessage = "Unknown function " + fieldName; + const err = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN_METHOD, errMessage); + output.writeMessageBegin(fieldName, thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(err, output); + output.writeMessageEnd(); + resolve(output.flush()); + break; + } + } + }); + } + public process_getStruct(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise<__NAMESPACE__.ISharedStructArgs>((resolve, reject): void => { + try { + const args: IGetStruct__Args = GetStruct__ArgsCodec.decode(input); + input.readMessageEnd(); + resolve(this._handler.getStruct(args.key, context)); + } + catch (err) { + reject(err); + } + }).then((data: __NAMESPACE__.ISharedStructArgs): Buffer => { + const result: IGetStruct__ResultArgs = { success: data }; + output.writeMessageBegin("getStruct", thrift.MessageType.REPLY, requestId); + GetStruct__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("getStruct", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }); + } + public process_getUnion(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise<__NAMESPACE__.SharedUnionArgs>((resolve, reject): void => { + try { + const args: IGetUnion__Args = GetUnion__ArgsCodec.decode(input); + input.readMessageEnd(); + resolve(this._handler.getUnion(args.index, context)); + } + catch (err) { + reject(err); + } + }).then((data: __NAMESPACE__.SharedUnionArgs): Buffer => { + const result: IGetUnion__ResultArgs = { success: data }; + output.writeMessageBegin("getUnion", thrift.MessageType.REPLY, requestId); + GetUnion__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("getUnion", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }); + } +} diff --git a/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/shared/SharedStruct.ts b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/shared/SharedStruct.ts new file mode 100644 index 00000000..9c1bc3e6 --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/shared/SharedStruct.ts @@ -0,0 +1,121 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v3.3.4 + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as thrift from "test-lib"; +import * as __NAMESPACE__ from "./."; +export interface ISharedStruct { + code: __NAMESPACE__.ICode; + value: string; +} +export interface ISharedStructArgs { + code: __NAMESPACE__.ICodeArgs; + value: string; +} +export const SharedStructCodec: thrift.IStructCodec = { + encode(args: ISharedStructArgs, output: thrift.TProtocol): void { + const obj = { + code: args.code, + value: args.value + }; + output.writeStructBegin("SharedStruct"); + if (obj.code != null) { + output.writeFieldBegin("code", thrift.TType.STRUCT, 1); + __NAMESPACE__.CodeCodec.encode(obj.code, output); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[code] is unset!"); + } + if (obj.value != null) { + output.writeFieldBegin("value", thrift.TType.STRING, 2); + output.writeString(obj.value); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[value] is unset!"); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): ISharedStruct { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.STRUCT) { + const value_1: __NAMESPACE__.ICode = __NAMESPACE__.CodeCodec.decode(input); + _args.code = value_1; + } + else { + input.skip(fieldType); + } + break; + case 2: + if (fieldType === thrift.TType.STRING) { + const value_2: string = input.readString(); + _args.value = value_2; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.code !== undefined && _args.value !== undefined) { + return { + code: _args.code, + value: _args.value + }; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read SharedStruct from input"); + } + } +}; +export class SharedStruct extends thrift.StructLike implements ISharedStruct { + public code: __NAMESPACE__.ICode; + public value: string; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: ISharedStructArgs) { + super(); + if (args.code != null) { + const value_3: __NAMESPACE__.ICode = new __NAMESPACE__.Code(args.code); + this.code = value_3; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[code] is unset!"); + } + if (args.value != null) { + const value_4: string = args.value; + this.value = value_4; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[value] is unset!"); + } + } + public static read(input: thrift.TProtocol): SharedStruct { + return new SharedStruct(SharedStructCodec.decode(input)); + } + public static write(args: ISharedStructArgs, output: thrift.TProtocol): void { + return SharedStructCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return SharedStructCodec.encode(this, output); + } +} diff --git a/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/shared/SharedUnion.ts b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/shared/SharedUnion.ts new file mode 100644 index 00000000..cf32ecc6 --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/shared/SharedUnion.ts @@ -0,0 +1,161 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v3.3.4 + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as thrift from "test-lib"; +export enum SharedUnionType { + SharedUnionWithOption1 = "option1", + SharedUnionWithOption2 = "option2" +} +export type SharedUnion = ISharedUnionWithOption1 | ISharedUnionWithOption2; +export interface ISharedUnionWithOption1 { + __type: SharedUnionType.SharedUnionWithOption1; + option1: string; + option2?: undefined; +} +export interface ISharedUnionWithOption2 { + __type: SharedUnionType.SharedUnionWithOption2; + option1?: undefined; + option2: string; +} +export type SharedUnionArgs = ISharedUnionWithOption1Args | ISharedUnionWithOption2Args; +export interface ISharedUnionWithOption1Args { + option1: string; + option2?: undefined; +} +export interface ISharedUnionWithOption2Args { + option1?: undefined; + option2: string; +} +export const SharedUnionCodec: thrift.IStructToolkit = { + create(args: SharedUnionArgs): SharedUnion { + let _fieldsSet: number = 0; + let _returnValue: any = null; + if (args.option1 != null) { + _fieldsSet++; + const value_1: string = args.option1; + _returnValue = { option1: value_1 }; + } + if (args.option2 != null) { + _fieldsSet++; + const value_2: string = args.option2; + _returnValue = { option2: value_2 }; + } + if (_fieldsSet > 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion cannot have more than one value"); + } + else if (_fieldsSet < 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion must have one value set"); + } + if (_returnValue !== null) { + if (_returnValue.option1) { + return { + __type: SharedUnionType.SharedUnionWithOption1, + option1: _returnValue.option1 + }; + } + else { + return { + __type: SharedUnionType.SharedUnionWithOption2, + option2: _returnValue.option2 + }; + } + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read data for TUnion"); + } + }, + encode(args: SharedUnionArgs, output: thrift.TProtocol): void { + let _fieldsSet: number = 0; + const obj = { + option1: args.option1, + option2: args.option2 + }; + output.writeStructBegin("SharedUnion"); + if (obj.option1 != null) { + _fieldsSet++; + output.writeFieldBegin("option1", thrift.TType.STRING, 1); + output.writeString(obj.option1); + output.writeFieldEnd(); + } + if (obj.option2 != null) { + _fieldsSet++; + output.writeFieldBegin("option2", thrift.TType.STRING, 2); + output.writeString(obj.option2); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + if (_fieldsSet > 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion cannot have more than one value"); + } + else if (_fieldsSet < 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion must have one value set"); + } + return; + }, + decode(input: thrift.TProtocol): SharedUnion { + let _fieldsSet: number = 0; + let _returnValue: any = null; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.STRING) { + _fieldsSet++; + const value_3: string = input.readString(); + _returnValue = { option1: value_3 }; + } + else { + input.skip(fieldType); + } + break; + case 2: + if (fieldType === thrift.TType.STRING) { + _fieldsSet++; + const value_4: string = input.readString(); + _returnValue = { option2: value_4 }; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_fieldsSet > 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion cannot have more than one value"); + } + else if (_fieldsSet < 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion must have one value set"); + } + if (_returnValue !== null) { + if (_returnValue.option1) { + return { + __type: SharedUnionType.SharedUnionWithOption1, + option1: _returnValue.option1 + }; + } + else { + return { + __type: SharedUnionType.SharedUnionWithOption2, + option2: _returnValue.option2 + }; + } + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read data for TUnion"); + } + } +}; diff --git a/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/shared/constants.ts b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/shared/constants.ts new file mode 100644 index 00000000..caa150af --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/shared/constants.ts @@ -0,0 +1,6 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v3.3.4 + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +export const SHARED_INT: number = 45; diff --git a/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/shared/index.ts b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/shared/index.ts new file mode 100644 index 00000000..a3d2a633 --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated-strict/com/test/shared/index.ts @@ -0,0 +1,11 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v3.3.4 + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +export * from "./constants"; +export * from "./Code"; +export * from "./SharedStruct"; +export * from "./SharedUnion"; +import * as SharedService from "./SharedService"; +export { SharedService as SharedService }; diff --git a/src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/Calculator.ts b/src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/Calculator.ts new file mode 100644 index 00000000..143ee4b0 --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/Calculator.ts @@ -0,0 +1,3482 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as thrift from "test-lib"; +import * as com_test_shared from "./../shared"; +import * as com_test_operation from "./../operation"; +import * as com_test_common from "./../common"; +import * as __NAMESPACE__ from "./."; +export const serviceName: string = "Calculator"; +export const annotations: thrift.IThriftAnnotations = {}; +export const methodAnnotations: thrift.IMethodAnnotations = { + getStruct: { + annotations: {}, + fieldAnnotations: {} + }, + getUnion: { + annotations: {}, + fieldAnnotations: {} + }, + ping: { + annotations: {}, + fieldAnnotations: {} + }, + add: { + annotations: {}, + fieldAnnotations: {} + }, + addInt64: { + annotations: {}, + fieldAnnotations: {} + }, + addWithContext: { + annotations: {}, + fieldAnnotations: {} + }, + calculate: { + annotations: {}, + fieldAnnotations: {} + }, + echoBinary: { + annotations: {}, + fieldAnnotations: {} + }, + echoString: { + annotations: {}, + fieldAnnotations: {} + }, + checkName: { + annotations: {}, + fieldAnnotations: {} + }, + checkOptional: { + annotations: {}, + fieldAnnotations: {} + }, + mapOneList: { + annotations: {}, + fieldAnnotations: {} + }, + mapValues: { + annotations: {}, + fieldAnnotations: {} + }, + listToMap: { + annotations: {}, + fieldAnnotations: {} + }, + fetchThing: { + annotations: {}, + fieldAnnotations: {} + }, + zip: { + annotations: {}, + fieldAnnotations: {} + } +}; +export const methodNames: Array = ["getStruct", "getUnion", "ping", "add", "addInt64", "addWithContext", "calculate", "echoBinary", "echoString", "checkName", "checkOptional", "mapOneList", "mapValues", "listToMap", "fetchThing", "zip"]; +export interface IPing__Args { +} +export interface IPing__ArgsArgs { +} +export const Ping__ArgsCodec: thrift.IStructCodec = { + encode(args: IPing__ArgsArgs, output: thrift.TProtocol): void { + output.writeStructBegin("Ping__Args"); + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IPing__Args { + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return {}; + } +}; +export class Ping__Args extends thrift.StructLike implements IPing__Args { + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IPing__ArgsArgs = {}) { + super(); + } + public static read(input: thrift.TProtocol): Ping__Args { + return new Ping__Args(Ping__ArgsCodec.decode(input)); + } + public static write(args: IPing__ArgsArgs, output: thrift.TProtocol): void { + return Ping__ArgsCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return Ping__ArgsCodec.encode(this, output); + } +} +export interface IAdd__Args { + num1: number; + num2: number; +} +export interface IAdd__ArgsArgs { + num1: number; + num2: number; +} +export const Add__ArgsCodec: thrift.IStructCodec = { + encode(args: IAdd__ArgsArgs, output: thrift.TProtocol): void { + const obj = { + num1: args.num1, + num2: args.num2 + }; + output.writeStructBegin("Add__Args"); + if (obj.num1 != null) { + output.writeFieldBegin("num1", thrift.TType.I32, 1); + output.writeI32(obj.num1); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num1] is unset!"); + } + if (obj.num2 != null) { + output.writeFieldBegin("num2", thrift.TType.I32, 2); + output.writeI32(obj.num2); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num2] is unset!"); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IAdd__Args { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.I32) { + const value_1: number = input.readI32(); + _args.num1 = value_1; + } + else { + input.skip(fieldType); + } + break; + case 2: + if (fieldType === thrift.TType.I32) { + const value_2: number = input.readI32(); + _args.num2 = value_2; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.num1 !== undefined && _args.num2 !== undefined) { + return { + num1: _args.num1, + num2: _args.num2 + }; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read Add__Args from input"); + } + } +}; +export class Add__Args extends thrift.StructLike implements IAdd__Args { + public num1: number; + public num2: number; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IAdd__ArgsArgs) { + super(); + if (args.num1 != null) { + const value_3: number = args.num1; + this.num1 = value_3; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num1] is unset!"); + } + if (args.num2 != null) { + const value_4: number = args.num2; + this.num2 = value_4; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num2] is unset!"); + } + } + public static read(input: thrift.TProtocol): Add__Args { + return new Add__Args(Add__ArgsCodec.decode(input)); + } + public static write(args: IAdd__ArgsArgs, output: thrift.TProtocol): void { + return Add__ArgsCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return Add__ArgsCodec.encode(this, output); + } +} +export interface IAddInt64__Args { + num1: thrift.Int64; + num2: thrift.Int64; +} +export interface IAddInt64__ArgsArgs { + num1: number | string | thrift.Int64; + num2: number | string | thrift.Int64; +} +export const AddInt64__ArgsCodec: thrift.IStructCodec = { + encode(args: IAddInt64__ArgsArgs, output: thrift.TProtocol): void { + const obj = { + num1: (typeof args.num1 === "number" ? new thrift.Int64(args.num1) : typeof args.num1 === "string" ? thrift.Int64.fromDecimalString(args.num1) : args.num1), + num2: (typeof args.num2 === "number" ? new thrift.Int64(args.num2) : typeof args.num2 === "string" ? thrift.Int64.fromDecimalString(args.num2) : args.num2) + }; + output.writeStructBegin("AddInt64__Args"); + if (obj.num1 != null) { + output.writeFieldBegin("num1", thrift.TType.I64, 1); + output.writeI64((typeof obj.num1 === "number" ? new thrift.Int64(obj.num1) : typeof obj.num1 === "string" ? thrift.Int64.fromDecimalString(obj.num1) : obj.num1)); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num1] is unset!"); + } + if (obj.num2 != null) { + output.writeFieldBegin("num2", thrift.TType.I64, 2); + output.writeI64((typeof obj.num2 === "number" ? new thrift.Int64(obj.num2) : typeof obj.num2 === "string" ? thrift.Int64.fromDecimalString(obj.num2) : obj.num2)); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num2] is unset!"); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IAddInt64__Args { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.I64) { + const value_5: thrift.Int64 = input.readI64(); + _args.num1 = value_5; + } + else { + input.skip(fieldType); + } + break; + case 2: + if (fieldType === thrift.TType.I64) { + const value_6: thrift.Int64 = input.readI64(); + _args.num2 = value_6; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.num1 !== undefined && _args.num2 !== undefined) { + return { + num1: _args.num1, + num2: _args.num2 + }; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read AddInt64__Args from input"); + } + } +}; +export class AddInt64__Args extends thrift.StructLike implements IAddInt64__Args { + public num1: thrift.Int64; + public num2: thrift.Int64; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IAddInt64__ArgsArgs) { + super(); + if (args.num1 != null) { + const value_7: thrift.Int64 = (typeof args.num1 === "number" ? new thrift.Int64(args.num1) : typeof args.num1 === "string" ? thrift.Int64.fromDecimalString(args.num1) : args.num1); + this.num1 = value_7; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num1] is unset!"); + } + if (args.num2 != null) { + const value_8: thrift.Int64 = (typeof args.num2 === "number" ? new thrift.Int64(args.num2) : typeof args.num2 === "string" ? thrift.Int64.fromDecimalString(args.num2) : args.num2); + this.num2 = value_8; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num2] is unset!"); + } + } + public static read(input: thrift.TProtocol): AddInt64__Args { + return new AddInt64__Args(AddInt64__ArgsCodec.decode(input)); + } + public static write(args: IAddInt64__ArgsArgs, output: thrift.TProtocol): void { + return AddInt64__ArgsCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return AddInt64__ArgsCodec.encode(this, output); + } +} +export interface IAddWithContext__Args { + num1: number; + num2: number; +} +export interface IAddWithContext__ArgsArgs { + num1: number; + num2: number; +} +export const AddWithContext__ArgsCodec: thrift.IStructCodec = { + encode(args: IAddWithContext__ArgsArgs, output: thrift.TProtocol): void { + const obj = { + num1: args.num1, + num2: args.num2 + }; + output.writeStructBegin("AddWithContext__Args"); + if (obj.num1 != null) { + output.writeFieldBegin("num1", thrift.TType.I32, 1); + output.writeI32(obj.num1); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num1] is unset!"); + } + if (obj.num2 != null) { + output.writeFieldBegin("num2", thrift.TType.I32, 2); + output.writeI32(obj.num2); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num2] is unset!"); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IAddWithContext__Args { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.I32) { + const value_9: number = input.readI32(); + _args.num1 = value_9; + } + else { + input.skip(fieldType); + } + break; + case 2: + if (fieldType === thrift.TType.I32) { + const value_10: number = input.readI32(); + _args.num2 = value_10; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.num1 !== undefined && _args.num2 !== undefined) { + return { + num1: _args.num1, + num2: _args.num2 + }; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read AddWithContext__Args from input"); + } + } +}; +export class AddWithContext__Args extends thrift.StructLike implements IAddWithContext__Args { + public num1: number; + public num2: number; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IAddWithContext__ArgsArgs) { + super(); + if (args.num1 != null) { + const value_11: number = args.num1; + this.num1 = value_11; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num1] is unset!"); + } + if (args.num2 != null) { + const value_12: number = args.num2; + this.num2 = value_12; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num2] is unset!"); + } + } + public static read(input: thrift.TProtocol): AddWithContext__Args { + return new AddWithContext__Args(AddWithContext__ArgsCodec.decode(input)); + } + public static write(args: IAddWithContext__ArgsArgs, output: thrift.TProtocol): void { + return AddWithContext__ArgsCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return AddWithContext__ArgsCodec.encode(this, output); + } +} +export interface ICalculate__Args { + logid: number; + work: __NAMESPACE__.IWork; +} +export interface ICalculate__ArgsArgs { + logid: number; + work: __NAMESPACE__.IWorkArgs; +} +export const Calculate__ArgsCodec: thrift.IStructCodec = { + encode(args: ICalculate__ArgsArgs, output: thrift.TProtocol): void { + const obj = { + logid: args.logid, + work: args.work + }; + output.writeStructBegin("Calculate__Args"); + if (obj.logid != null) { + output.writeFieldBegin("logid", thrift.TType.I32, 1); + output.writeI32(obj.logid); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[logid] is unset!"); + } + if (obj.work != null) { + output.writeFieldBegin("work", thrift.TType.STRUCT, 2); + __NAMESPACE__.WorkCodec.encode(obj.work, output); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[work] is unset!"); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): ICalculate__Args { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.I32) { + const value_13: number = input.readI32(); + _args.logid = value_13; + } + else { + input.skip(fieldType); + } + break; + case 2: + if (fieldType === thrift.TType.STRUCT) { + const value_14: __NAMESPACE__.IWork = __NAMESPACE__.WorkCodec.decode(input); + _args.work = value_14; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.logid !== undefined && _args.work !== undefined) { + return { + logid: _args.logid, + work: _args.work + }; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read Calculate__Args from input"); + } + } +}; +export class Calculate__Args extends thrift.StructLike implements ICalculate__Args { + public logid: number; + public work: __NAMESPACE__.IWork; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: ICalculate__ArgsArgs) { + super(); + if (args.logid != null) { + const value_15: number = args.logid; + this.logid = value_15; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[logid] is unset!"); + } + if (args.work != null) { + const value_16: __NAMESPACE__.IWork = new __NAMESPACE__.Work(args.work); + this.work = value_16; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[work] is unset!"); + } + } + public static read(input: thrift.TProtocol): Calculate__Args { + return new Calculate__Args(Calculate__ArgsCodec.decode(input)); + } + public static write(args: ICalculate__ArgsArgs, output: thrift.TProtocol): void { + return Calculate__ArgsCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return Calculate__ArgsCodec.encode(this, output); + } +} +export interface IEchoBinary__Args { + word: Buffer; +} +export interface IEchoBinary__ArgsArgs { + word: string | Buffer; +} +export const EchoBinary__ArgsCodec: thrift.IStructCodec = { + encode(args: IEchoBinary__ArgsArgs, output: thrift.TProtocol): void { + const obj = { + word: (typeof args.word === "string" ? Buffer.from(args.word) : args.word) + }; + output.writeStructBegin("EchoBinary__Args"); + if (obj.word != null) { + output.writeFieldBegin("word", thrift.TType.STRING, 1); + output.writeBinary(obj.word); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[word] is unset!"); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IEchoBinary__Args { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.STRING) { + const value_17: Buffer = input.readBinary(); + _args.word = value_17; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.word !== undefined) { + return { + word: _args.word + }; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read EchoBinary__Args from input"); + } + } +}; +export class EchoBinary__Args extends thrift.StructLike implements IEchoBinary__Args { + public word: Buffer; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IEchoBinary__ArgsArgs) { + super(); + if (args.word != null) { + const value_18: Buffer = (typeof args.word === "string" ? Buffer.from(args.word) : args.word); + this.word = value_18; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[word] is unset!"); + } + } + public static read(input: thrift.TProtocol): EchoBinary__Args { + return new EchoBinary__Args(EchoBinary__ArgsCodec.decode(input)); + } + public static write(args: IEchoBinary__ArgsArgs, output: thrift.TProtocol): void { + return EchoBinary__ArgsCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return EchoBinary__ArgsCodec.encode(this, output); + } +} +export interface IEchoString__Args { + word: string; +} +export interface IEchoString__ArgsArgs { + word: string; +} +export const EchoString__ArgsCodec: thrift.IStructCodec = { + encode(args: IEchoString__ArgsArgs, output: thrift.TProtocol): void { + const obj = { + word: args.word + }; + output.writeStructBegin("EchoString__Args"); + if (obj.word != null) { + output.writeFieldBegin("word", thrift.TType.STRING, 1); + output.writeString(obj.word); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[word] is unset!"); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IEchoString__Args { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.STRING) { + const value_19: string = input.readString(); + _args.word = value_19; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.word !== undefined) { + return { + word: _args.word + }; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read EchoString__Args from input"); + } + } +}; +export class EchoString__Args extends thrift.StructLike implements IEchoString__Args { + public word: string; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IEchoString__ArgsArgs) { + super(); + if (args.word != null) { + const value_20: string = args.word; + this.word = value_20; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[word] is unset!"); + } + } + public static read(input: thrift.TProtocol): EchoString__Args { + return new EchoString__Args(EchoString__ArgsCodec.decode(input)); + } + public static write(args: IEchoString__ArgsArgs, output: thrift.TProtocol): void { + return EchoString__ArgsCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return EchoString__ArgsCodec.encode(this, output); + } +} +export interface ICheckName__Args { + choice: __NAMESPACE__.IChoice; +} +export interface ICheckName__ArgsArgs { + choice: __NAMESPACE__.IChoiceArgs; +} +export const CheckName__ArgsCodec: thrift.IStructCodec = { + encode(args: ICheckName__ArgsArgs, output: thrift.TProtocol): void { + const obj = { + choice: args.choice + }; + output.writeStructBegin("CheckName__Args"); + if (obj.choice != null) { + output.writeFieldBegin("choice", thrift.TType.STRUCT, 1); + __NAMESPACE__.ChoiceCodec.encode(obj.choice, output); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[choice] is unset!"); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): ICheckName__Args { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.STRUCT) { + const value_21: __NAMESPACE__.IChoice = __NAMESPACE__.ChoiceCodec.decode(input); + _args.choice = value_21; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.choice !== undefined) { + return { + choice: _args.choice + }; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read CheckName__Args from input"); + } + } +}; +export class CheckName__Args extends thrift.StructLike implements ICheckName__Args { + public choice: __NAMESPACE__.IChoice; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: ICheckName__ArgsArgs) { + super(); + if (args.choice != null) { + const value_22: __NAMESPACE__.IChoice = new __NAMESPACE__.Choice(args.choice); + this.choice = value_22; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[choice] is unset!"); + } + } + public static read(input: thrift.TProtocol): CheckName__Args { + return new CheckName__Args(CheckName__ArgsCodec.decode(input)); + } + public static write(args: ICheckName__ArgsArgs, output: thrift.TProtocol): void { + return CheckName__ArgsCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return CheckName__ArgsCodec.encode(this, output); + } +} +export interface ICheckOptional__Args { + type?: string; +} +export interface ICheckOptional__ArgsArgs { + type?: string; +} +export const CheckOptional__ArgsCodec: thrift.IStructCodec = { + encode(args: ICheckOptional__ArgsArgs, output: thrift.TProtocol): void { + const obj = { + type: args.type + }; + output.writeStructBegin("CheckOptional__Args"); + if (obj.type != null) { + output.writeFieldBegin("type", thrift.TType.STRING, 1); + output.writeString(obj.type); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): ICheckOptional__Args { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.STRING) { + const value_23: string = input.readString(); + _args.type = value_23; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + type: _args.type + }; + } +}; +export class CheckOptional__Args extends thrift.StructLike implements ICheckOptional__Args { + public type?: string; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: ICheckOptional__ArgsArgs = {}) { + super(); + if (args.type != null) { + const value_24: string = args.type; + this.type = value_24; + } + } + public static read(input: thrift.TProtocol): CheckOptional__Args { + return new CheckOptional__Args(CheckOptional__ArgsCodec.decode(input)); + } + public static write(args: ICheckOptional__ArgsArgs, output: thrift.TProtocol): void { + return CheckOptional__ArgsCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return CheckOptional__ArgsCodec.encode(this, output); + } +} +export interface IMapOneList__Args { + arg: Array; +} +export interface IMapOneList__ArgsArgs { + arg: Array; +} +export const MapOneList__ArgsCodec: thrift.IStructCodec = { + encode(args: IMapOneList__ArgsArgs, output: thrift.TProtocol): void { + const obj = { + arg: args.arg + }; + output.writeStructBegin("MapOneList__Args"); + if (obj.arg != null) { + output.writeFieldBegin("arg", thrift.TType.LIST, 1); + output.writeListBegin(thrift.TType.I32, obj.arg.length); + obj.arg.forEach((value_25: number): void => { + output.writeI32(value_25); + }); + output.writeListEnd(); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[arg] is unset!"); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IMapOneList__Args { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.LIST) { + const value_26: Array = new Array(); + const metadata_1: thrift.IThriftList = input.readListBegin(); + const size_1: number = metadata_1.size; + for (let i_1: number = 0; i_1 < size_1; i_1++) { + const value_27: number = input.readI32(); + value_26.push(value_27); + } + input.readListEnd(); + _args.arg = value_26; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.arg !== undefined) { + return { + arg: _args.arg + }; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read MapOneList__Args from input"); + } + } +}; +export class MapOneList__Args extends thrift.StructLike implements IMapOneList__Args { + public arg: Array; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IMapOneList__ArgsArgs) { + super(); + if (args.arg != null) { + const value_28: Array = new Array(); + args.arg.forEach((value_29: number): void => { + const value_30: number = value_29; + value_28.push(value_30); + }); + this.arg = value_28; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[arg] is unset!"); + } + } + public static read(input: thrift.TProtocol): MapOneList__Args { + return new MapOneList__Args(MapOneList__ArgsCodec.decode(input)); + } + public static write(args: IMapOneList__ArgsArgs, output: thrift.TProtocol): void { + return MapOneList__ArgsCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return MapOneList__ArgsCodec.encode(this, output); + } +} +export interface IMapValues__Args { + arg: Map; +} +export interface IMapValues__ArgsArgs { + arg: Map; +} +export const MapValues__ArgsCodec: thrift.IStructCodec = { + encode(args: IMapValues__ArgsArgs, output: thrift.TProtocol): void { + const obj = { + arg: args.arg + }; + output.writeStructBegin("MapValues__Args"); + if (obj.arg != null) { + output.writeFieldBegin("arg", thrift.TType.MAP, 1); + output.writeMapBegin(thrift.TType.STRING, thrift.TType.I32, obj.arg.size); + obj.arg.forEach((value_31: number, key_1: string): void => { + output.writeString(key_1); + output.writeI32(value_31); + }); + output.writeMapEnd(); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[arg] is unset!"); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IMapValues__Args { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.MAP) { + const value_32: Map = new Map(); + const metadata_2: thrift.IThriftMap = input.readMapBegin(); + const size_2: number = metadata_2.size; + for (let i_2: number = 0; i_2 < size_2; i_2++) { + const key_2: string = input.readString(); + const value_33: number = input.readI32(); + value_32.set(key_2, value_33); + } + input.readMapEnd(); + _args.arg = value_32; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.arg !== undefined) { + return { + arg: _args.arg + }; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read MapValues__Args from input"); + } + } +}; +export class MapValues__Args extends thrift.StructLike implements IMapValues__Args { + public arg: Map; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IMapValues__ArgsArgs) { + super(); + if (args.arg != null) { + const value_34: Map = new Map(); + args.arg.forEach((value_35: number, key_3: string): void => { + const value_36: number = value_35; + const key_4: string = key_3; + value_34.set(key_4, value_36); + }); + this.arg = value_34; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[arg] is unset!"); + } + } + public static read(input: thrift.TProtocol): MapValues__Args { + return new MapValues__Args(MapValues__ArgsCodec.decode(input)); + } + public static write(args: IMapValues__ArgsArgs, output: thrift.TProtocol): void { + return MapValues__ArgsCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return MapValues__ArgsCodec.encode(this, output); + } +} +export interface IListToMap__Args { + arg: Array>; +} +export interface IListToMap__ArgsArgs { + arg: Array>; +} +export const ListToMap__ArgsCodec: thrift.IStructCodec = { + encode(args: IListToMap__ArgsArgs, output: thrift.TProtocol): void { + const obj = { + arg: args.arg + }; + output.writeStructBegin("ListToMap__Args"); + if (obj.arg != null) { + output.writeFieldBegin("arg", thrift.TType.LIST, 1); + output.writeListBegin(thrift.TType.LIST, obj.arg.length); + obj.arg.forEach((value_37: Array): void => { + output.writeListBegin(thrift.TType.STRING, value_37.length); + value_37.forEach((value_38: string): void => { + output.writeString(value_38); + }); + output.writeListEnd(); + }); + output.writeListEnd(); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[arg] is unset!"); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IListToMap__Args { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.LIST) { + const value_39: Array> = new Array>(); + const metadata_3: thrift.IThriftList = input.readListBegin(); + const size_3: number = metadata_3.size; + for (let i_3: number = 0; i_3 < size_3; i_3++) { + const value_40: Array = new Array(); + const metadata_4: thrift.IThriftList = input.readListBegin(); + const size_4: number = metadata_4.size; + for (let i_4: number = 0; i_4 < size_4; i_4++) { + const value_41: string = input.readString(); + value_40.push(value_41); + } + input.readListEnd(); + value_39.push(value_40); + } + input.readListEnd(); + _args.arg = value_39; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.arg !== undefined) { + return { + arg: _args.arg + }; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read ListToMap__Args from input"); + } + } +}; +export class ListToMap__Args extends thrift.StructLike implements IListToMap__Args { + public arg: Array>; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IListToMap__ArgsArgs) { + super(); + if (args.arg != null) { + const value_42: Array> = new Array>(); + args.arg.forEach((value_43: Array): void => { + const value_44: Array = new Array(); + value_43.forEach((value_45: string): void => { + const value_46: string = value_45; + value_44.push(value_46); + }); + value_42.push(value_44); + }); + this.arg = value_42; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[arg] is unset!"); + } + } + public static read(input: thrift.TProtocol): ListToMap__Args { + return new ListToMap__Args(ListToMap__ArgsCodec.decode(input)); + } + public static write(args: IListToMap__ArgsArgs, output: thrift.TProtocol): void { + return ListToMap__ArgsCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return ListToMap__ArgsCodec.encode(this, output); + } +} +export interface IFetchThing__Args { +} +export interface IFetchThing__ArgsArgs { +} +export const FetchThing__ArgsCodec: thrift.IStructCodec = { + encode(args: IFetchThing__ArgsArgs, output: thrift.TProtocol): void { + output.writeStructBegin("FetchThing__Args"); + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IFetchThing__Args { + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return {}; + } +}; +export class FetchThing__Args extends thrift.StructLike implements IFetchThing__Args { + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IFetchThing__ArgsArgs = {}) { + super(); + } + public static read(input: thrift.TProtocol): FetchThing__Args { + return new FetchThing__Args(FetchThing__ArgsCodec.decode(input)); + } + public static write(args: IFetchThing__ArgsArgs, output: thrift.TProtocol): void { + return FetchThing__ArgsCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return FetchThing__ArgsCodec.encode(this, output); + } +} +export interface IZip__Args { +} +export interface IZip__ArgsArgs { +} +export const Zip__ArgsCodec: thrift.IStructCodec = { + encode(args: IZip__ArgsArgs, output: thrift.TProtocol): void { + output.writeStructBegin("Zip__Args"); + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IZip__Args { + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return {}; + } +}; +export class Zip__Args extends thrift.StructLike implements IZip__Args { + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IZip__ArgsArgs = {}) { + super(); + } + public static read(input: thrift.TProtocol): Zip__Args { + return new Zip__Args(Zip__ArgsCodec.decode(input)); + } + public static write(args: IZip__ArgsArgs, output: thrift.TProtocol): void { + return Zip__ArgsCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return Zip__ArgsCodec.encode(this, output); + } +} +export interface IPing__Result { + success?: void; +} +export interface IPing__ResultArgs { + success?: void; +} +export const Ping__ResultCodec: thrift.IStructCodec = { + encode(args: IPing__ResultArgs, output: thrift.TProtocol): void { + output.writeStructBegin("Ping__Result"); + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IPing__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.VOID) { + input.skip(fieldType); + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + success: _args.success + }; + } +}; +export class Ping__Result extends thrift.StructLike implements IPing__Result { + public success?: void; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IPing__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_47: void = undefined; + this.success = value_47; + } + } + public static read(input: thrift.TProtocol): Ping__Result { + return new Ping__Result(Ping__ResultCodec.decode(input)); + } + public static write(args: IPing__ResultArgs, output: thrift.TProtocol): void { + return Ping__ResultCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return Ping__ResultCodec.encode(this, output); + } +} +export interface IAdd__Result { + success?: number; + exp?: com_test_operation.IJankyResult; +} +export interface IAdd__ResultArgs { + success?: number; + exp?: com_test_operation.IJankyResultArgs; +} +export const Add__ResultCodec: thrift.IStructCodec = { + encode(args: IAdd__ResultArgs, output: thrift.TProtocol): void { + const obj = { + success: args.success, + exp: args.exp + }; + output.writeStructBegin("Add__Result"); + if (obj.success != null) { + output.writeFieldBegin("success", thrift.TType.I32, 0); + output.writeI32(obj.success); + output.writeFieldEnd(); + } + if (obj.exp != null) { + output.writeFieldBegin("exp", thrift.TType.STRUCT, 1); + com_test_operation.JankyResultCodec.encode(obj.exp, output); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IAdd__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.I32) { + const value_48: number = input.readI32(); + _args.success = value_48; + } + else { + input.skip(fieldType); + } + break; + case 1: + if (fieldType === thrift.TType.STRUCT) { + const value_49: com_test_operation.IJankyResult = com_test_operation.JankyResultCodec.decode(input); + _args.exp = value_49; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + success: _args.success, + exp: _args.exp + }; + } +}; +export class Add__Result extends thrift.StructLike implements IAdd__Result { + public success?: number; + public exp?: com_test_operation.IJankyResult; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IAdd__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_50: number = args.success; + this.success = value_50; + } + if (args.exp != null) { + const value_51: com_test_operation.IJankyResult = new com_test_operation.JankyResult(args.exp); + this.exp = value_51; + } + } + public static read(input: thrift.TProtocol): Add__Result { + return new Add__Result(Add__ResultCodec.decode(input)); + } + public static write(args: IAdd__ResultArgs, output: thrift.TProtocol): void { + return Add__ResultCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return Add__ResultCodec.encode(this, output); + } +} +export interface IAddInt64__Result { + success?: thrift.Int64; + exp?: __NAMESPACE__.INotAGoodIdea; +} +export interface IAddInt64__ResultArgs { + success?: number | string | thrift.Int64; + exp?: __NAMESPACE__.INotAGoodIdeaArgs; +} +export const AddInt64__ResultCodec: thrift.IStructCodec = { + encode(args: IAddInt64__ResultArgs, output: thrift.TProtocol): void { + const obj = { + success: (typeof args.success === "number" ? new thrift.Int64(args.success) : typeof args.success === "string" ? thrift.Int64.fromDecimalString(args.success) : args.success), + exp: args.exp + }; + output.writeStructBegin("AddInt64__Result"); + if (obj.success != null) { + output.writeFieldBegin("success", thrift.TType.I64, 0); + output.writeI64((typeof obj.success === "number" ? new thrift.Int64(obj.success) : typeof obj.success === "string" ? thrift.Int64.fromDecimalString(obj.success) : obj.success)); + output.writeFieldEnd(); + } + if (obj.exp != null) { + output.writeFieldBegin("exp", thrift.TType.STRUCT, 1); + __NAMESPACE__.NotAGoodIdeaCodec.encode(obj.exp, output); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IAddInt64__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.I64) { + const value_52: thrift.Int64 = input.readI64(); + _args.success = value_52; + } + else { + input.skip(fieldType); + } + break; + case 1: + if (fieldType === thrift.TType.STRUCT) { + const value_53: __NAMESPACE__.INotAGoodIdea = __NAMESPACE__.NotAGoodIdeaCodec.decode(input); + _args.exp = value_53; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + success: _args.success, + exp: _args.exp + }; + } +}; +export class AddInt64__Result extends thrift.StructLike implements IAddInt64__Result { + public success?: thrift.Int64; + public exp?: __NAMESPACE__.INotAGoodIdea; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IAddInt64__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_54: thrift.Int64 = (typeof args.success === "number" ? new thrift.Int64(args.success) : typeof args.success === "string" ? thrift.Int64.fromDecimalString(args.success) : args.success); + this.success = value_54; + } + if (args.exp != null) { + const value_55: __NAMESPACE__.INotAGoodIdea = new __NAMESPACE__.NotAGoodIdea(args.exp); + this.exp = value_55; + } + } + public static read(input: thrift.TProtocol): AddInt64__Result { + return new AddInt64__Result(AddInt64__ResultCodec.decode(input)); + } + public static write(args: IAddInt64__ResultArgs, output: thrift.TProtocol): void { + return AddInt64__ResultCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return AddInt64__ResultCodec.encode(this, output); + } +} +export interface IAddWithContext__Result { + success?: number; +} +export interface IAddWithContext__ResultArgs { + success?: number; +} +export const AddWithContext__ResultCodec: thrift.IStructCodec = { + encode(args: IAddWithContext__ResultArgs, output: thrift.TProtocol): void { + const obj = { + success: args.success + }; + output.writeStructBegin("AddWithContext__Result"); + if (obj.success != null) { + output.writeFieldBegin("success", thrift.TType.I32, 0); + output.writeI32(obj.success); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IAddWithContext__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.I32) { + const value_56: number = input.readI32(); + _args.success = value_56; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + success: _args.success + }; + } +}; +export class AddWithContext__Result extends thrift.StructLike implements IAddWithContext__Result { + public success?: number; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IAddWithContext__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_57: number = args.success; + this.success = value_57; + } + } + public static read(input: thrift.TProtocol): AddWithContext__Result { + return new AddWithContext__Result(AddWithContext__ResultCodec.decode(input)); + } + public static write(args: IAddWithContext__ResultArgs, output: thrift.TProtocol): void { + return AddWithContext__ResultCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return AddWithContext__ResultCodec.encode(this, output); + } +} +export interface ICalculate__Result { + success?: number; + ouch?: com_test_operation.IJankyOperation; +} +export interface ICalculate__ResultArgs { + success?: number; + ouch?: com_test_operation.IJankyOperationArgs; +} +export const Calculate__ResultCodec: thrift.IStructCodec = { + encode(args: ICalculate__ResultArgs, output: thrift.TProtocol): void { + const obj = { + success: args.success, + ouch: args.ouch + }; + output.writeStructBegin("Calculate__Result"); + if (obj.success != null) { + output.writeFieldBegin("success", thrift.TType.I32, 0); + output.writeI32(obj.success); + output.writeFieldEnd(); + } + if (obj.ouch != null) { + output.writeFieldBegin("ouch", thrift.TType.STRUCT, 1); + com_test_operation.JankyOperationCodec.encode(obj.ouch, output); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): ICalculate__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.I32) { + const value_58: number = input.readI32(); + _args.success = value_58; + } + else { + input.skip(fieldType); + } + break; + case 1: + if (fieldType === thrift.TType.STRUCT) { + const value_59: com_test_operation.IJankyOperation = com_test_operation.JankyOperationCodec.decode(input); + _args.ouch = value_59; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + success: _args.success, + ouch: _args.ouch + }; + } +}; +export class Calculate__Result extends thrift.StructLike implements ICalculate__Result { + public success?: number; + public ouch?: com_test_operation.IJankyOperation; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: ICalculate__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_60: number = args.success; + this.success = value_60; + } + if (args.ouch != null) { + const value_61: com_test_operation.IJankyOperation = new com_test_operation.JankyOperation(args.ouch); + this.ouch = value_61; + } + } + public static read(input: thrift.TProtocol): Calculate__Result { + return new Calculate__Result(Calculate__ResultCodec.decode(input)); + } + public static write(args: ICalculate__ResultArgs, output: thrift.TProtocol): void { + return Calculate__ResultCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return Calculate__ResultCodec.encode(this, output); + } +} +export interface IEchoBinary__Result { + success?: string; +} +export interface IEchoBinary__ResultArgs { + success?: string; +} +export const EchoBinary__ResultCodec: thrift.IStructCodec = { + encode(args: IEchoBinary__ResultArgs, output: thrift.TProtocol): void { + const obj = { + success: args.success + }; + output.writeStructBegin("EchoBinary__Result"); + if (obj.success != null) { + output.writeFieldBegin("success", thrift.TType.STRING, 0); + output.writeString(obj.success); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IEchoBinary__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.STRING) { + const value_62: string = input.readString(); + _args.success = value_62; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + success: _args.success + }; + } +}; +export class EchoBinary__Result extends thrift.StructLike implements IEchoBinary__Result { + public success?: string; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IEchoBinary__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_63: string = args.success; + this.success = value_63; + } + } + public static read(input: thrift.TProtocol): EchoBinary__Result { + return new EchoBinary__Result(EchoBinary__ResultCodec.decode(input)); + } + public static write(args: IEchoBinary__ResultArgs, output: thrift.TProtocol): void { + return EchoBinary__ResultCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return EchoBinary__ResultCodec.encode(this, output); + } +} +export interface IEchoString__Result { + success?: string; +} +export interface IEchoString__ResultArgs { + success?: string; +} +export const EchoString__ResultCodec: thrift.IStructCodec = { + encode(args: IEchoString__ResultArgs, output: thrift.TProtocol): void { + const obj = { + success: args.success + }; + output.writeStructBegin("EchoString__Result"); + if (obj.success != null) { + output.writeFieldBegin("success", thrift.TType.STRING, 0); + output.writeString(obj.success); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IEchoString__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.STRING) { + const value_64: string = input.readString(); + _args.success = value_64; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + success: _args.success + }; + } +}; +export class EchoString__Result extends thrift.StructLike implements IEchoString__Result { + public success?: string; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IEchoString__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_65: string = args.success; + this.success = value_65; + } + } + public static read(input: thrift.TProtocol): EchoString__Result { + return new EchoString__Result(EchoString__ResultCodec.decode(input)); + } + public static write(args: IEchoString__ResultArgs, output: thrift.TProtocol): void { + return EchoString__ResultCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return EchoString__ResultCodec.encode(this, output); + } +} +export interface ICheckName__Result { + success?: string; +} +export interface ICheckName__ResultArgs { + success?: string; +} +export const CheckName__ResultCodec: thrift.IStructCodec = { + encode(args: ICheckName__ResultArgs, output: thrift.TProtocol): void { + const obj = { + success: args.success + }; + output.writeStructBegin("CheckName__Result"); + if (obj.success != null) { + output.writeFieldBegin("success", thrift.TType.STRING, 0); + output.writeString(obj.success); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): ICheckName__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.STRING) { + const value_66: string = input.readString(); + _args.success = value_66; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + success: _args.success + }; + } +}; +export class CheckName__Result extends thrift.StructLike implements ICheckName__Result { + public success?: string; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: ICheckName__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_67: string = args.success; + this.success = value_67; + } + } + public static read(input: thrift.TProtocol): CheckName__Result { + return new CheckName__Result(CheckName__ResultCodec.decode(input)); + } + public static write(args: ICheckName__ResultArgs, output: thrift.TProtocol): void { + return CheckName__ResultCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return CheckName__ResultCodec.encode(this, output); + } +} +export interface ICheckOptional__Result { + success?: string; +} +export interface ICheckOptional__ResultArgs { + success?: string; +} +export const CheckOptional__ResultCodec: thrift.IStructCodec = { + encode(args: ICheckOptional__ResultArgs, output: thrift.TProtocol): void { + const obj = { + success: args.success + }; + output.writeStructBegin("CheckOptional__Result"); + if (obj.success != null) { + output.writeFieldBegin("success", thrift.TType.STRING, 0); + output.writeString(obj.success); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): ICheckOptional__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.STRING) { + const value_68: string = input.readString(); + _args.success = value_68; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + success: _args.success + }; + } +}; +export class CheckOptional__Result extends thrift.StructLike implements ICheckOptional__Result { + public success?: string; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: ICheckOptional__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_69: string = args.success; + this.success = value_69; + } + } + public static read(input: thrift.TProtocol): CheckOptional__Result { + return new CheckOptional__Result(CheckOptional__ResultCodec.decode(input)); + } + public static write(args: ICheckOptional__ResultArgs, output: thrift.TProtocol): void { + return CheckOptional__ResultCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return CheckOptional__ResultCodec.encode(this, output); + } +} +export interface IMapOneList__Result { + success?: Array; +} +export interface IMapOneList__ResultArgs { + success?: Array; +} +export const MapOneList__ResultCodec: thrift.IStructCodec = { + encode(args: IMapOneList__ResultArgs, output: thrift.TProtocol): void { + const obj = { + success: args.success + }; + output.writeStructBegin("MapOneList__Result"); + if (obj.success != null) { + output.writeFieldBegin("success", thrift.TType.LIST, 0); + output.writeListBegin(thrift.TType.I32, obj.success.length); + obj.success.forEach((value_70: number): void => { + output.writeI32(value_70); + }); + output.writeListEnd(); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IMapOneList__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.LIST) { + const value_71: Array = new Array(); + const metadata_5: thrift.IThriftList = input.readListBegin(); + const size_5: number = metadata_5.size; + for (let i_5: number = 0; i_5 < size_5; i_5++) { + const value_72: number = input.readI32(); + value_71.push(value_72); + } + input.readListEnd(); + _args.success = value_71; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + success: _args.success + }; + } +}; +export class MapOneList__Result extends thrift.StructLike implements IMapOneList__Result { + public success?: Array; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IMapOneList__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_73: Array = new Array(); + args.success.forEach((value_74: number): void => { + const value_75: number = value_74; + value_73.push(value_75); + }); + this.success = value_73; + } + } + public static read(input: thrift.TProtocol): MapOneList__Result { + return new MapOneList__Result(MapOneList__ResultCodec.decode(input)); + } + public static write(args: IMapOneList__ResultArgs, output: thrift.TProtocol): void { + return MapOneList__ResultCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return MapOneList__ResultCodec.encode(this, output); + } +} +export interface IMapValues__Result { + success?: Array; +} +export interface IMapValues__ResultArgs { + success?: Array; +} +export const MapValues__ResultCodec: thrift.IStructCodec = { + encode(args: IMapValues__ResultArgs, output: thrift.TProtocol): void { + const obj = { + success: args.success + }; + output.writeStructBegin("MapValues__Result"); + if (obj.success != null) { + output.writeFieldBegin("success", thrift.TType.LIST, 0); + output.writeListBegin(thrift.TType.I32, obj.success.length); + obj.success.forEach((value_76: number): void => { + output.writeI32(value_76); + }); + output.writeListEnd(); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IMapValues__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.LIST) { + const value_77: Array = new Array(); + const metadata_6: thrift.IThriftList = input.readListBegin(); + const size_6: number = metadata_6.size; + for (let i_6: number = 0; i_6 < size_6; i_6++) { + const value_78: number = input.readI32(); + value_77.push(value_78); + } + input.readListEnd(); + _args.success = value_77; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + success: _args.success + }; + } +}; +export class MapValues__Result extends thrift.StructLike implements IMapValues__Result { + public success?: Array; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IMapValues__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_79: Array = new Array(); + args.success.forEach((value_80: number): void => { + const value_81: number = value_80; + value_79.push(value_81); + }); + this.success = value_79; + } + } + public static read(input: thrift.TProtocol): MapValues__Result { + return new MapValues__Result(MapValues__ResultCodec.decode(input)); + } + public static write(args: IMapValues__ResultArgs, output: thrift.TProtocol): void { + return MapValues__ResultCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return MapValues__ResultCodec.encode(this, output); + } +} +export interface IListToMap__Result { + success?: Map; +} +export interface IListToMap__ResultArgs { + success?: Map; +} +export const ListToMap__ResultCodec: thrift.IStructCodec = { + encode(args: IListToMap__ResultArgs, output: thrift.TProtocol): void { + const obj = { + success: args.success + }; + output.writeStructBegin("ListToMap__Result"); + if (obj.success != null) { + output.writeFieldBegin("success", thrift.TType.MAP, 0); + output.writeMapBegin(thrift.TType.STRING, thrift.TType.STRING, obj.success.size); + obj.success.forEach((value_82: string, key_5: string): void => { + output.writeString(key_5); + output.writeString(value_82); + }); + output.writeMapEnd(); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IListToMap__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.MAP) { + const value_83: Map = new Map(); + const metadata_7: thrift.IThriftMap = input.readMapBegin(); + const size_7: number = metadata_7.size; + for (let i_7: number = 0; i_7 < size_7; i_7++) { + const key_6: string = input.readString(); + const value_84: string = input.readString(); + value_83.set(key_6, value_84); + } + input.readMapEnd(); + _args.success = value_83; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + success: _args.success + }; + } +}; +export class ListToMap__Result extends thrift.StructLike implements IListToMap__Result { + public success?: Map; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IListToMap__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_85: Map = new Map(); + args.success.forEach((value_86: string, key_7: string): void => { + const value_87: string = value_86; + const key_8: string = key_7; + value_85.set(key_8, value_87); + }); + this.success = value_85; + } + } + public static read(input: thrift.TProtocol): ListToMap__Result { + return new ListToMap__Result(ListToMap__ResultCodec.decode(input)); + } + public static write(args: IListToMap__ResultArgs, output: thrift.TProtocol): void { + return ListToMap__ResultCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return ListToMap__ResultCodec.encode(this, output); + } +} +export interface IFetchThing__Result { + success?: com_test_common.ICommonStruct; +} +export interface IFetchThing__ResultArgs { + success?: com_test_common.ICommonStructArgs; +} +export const FetchThing__ResultCodec: thrift.IStructCodec = { + encode(args: IFetchThing__ResultArgs, output: thrift.TProtocol): void { + const obj = { + success: args.success + }; + output.writeStructBegin("FetchThing__Result"); + if (obj.success != null) { + output.writeFieldBegin("success", thrift.TType.STRUCT, 0); + com_test_common.CommonStructCodec.encode(obj.success, output); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IFetchThing__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.STRUCT) { + const value_88: com_test_common.ICommonStruct = com_test_common.CommonStructCodec.decode(input); + _args.success = value_88; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + success: _args.success + }; + } +}; +export class FetchThing__Result extends thrift.StructLike implements IFetchThing__Result { + public success?: com_test_common.ICommonStruct; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IFetchThing__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_89: com_test_common.ICommonStruct = new com_test_common.CommonStruct(args.success); + this.success = value_89; + } + } + public static read(input: thrift.TProtocol): FetchThing__Result { + return new FetchThing__Result(FetchThing__ResultCodec.decode(input)); + } + public static write(args: IFetchThing__ResultArgs, output: thrift.TProtocol): void { + return FetchThing__ResultCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return FetchThing__ResultCodec.encode(this, output); + } +} +export interface IZip__Result { + success?: void; +} +export interface IZip__ResultArgs { + success?: void; +} +export const Zip__ResultCodec: thrift.IStructCodec = { + encode(args: IZip__ResultArgs, output: thrift.TProtocol): void { + output.writeStructBegin("Zip__Result"); + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IZip__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.VOID) { + input.skip(fieldType); + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + success: _args.success + }; + } +}; +export class Zip__Result extends thrift.StructLike implements IZip__Result { + public success?: void; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IZip__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_90: void = undefined; + this.success = value_90; + } + } + public static read(input: thrift.TProtocol): Zip__Result { + return new Zip__Result(Zip__ResultCodec.decode(input)); + } + public static write(args: IZip__ResultArgs, output: thrift.TProtocol): void { + return Zip__ResultCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return Zip__ResultCodec.encode(this, output); + } +} +export class Client extends com_test_shared.SharedService.Client { + public static readonly serviceName: string = serviceName; + public static readonly annotations: thrift.IThriftAnnotations = annotations; + public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public static readonly methodNames: Array = methodNames; + public readonly _serviceName: string = serviceName; + public readonly _annotations: thrift.IThriftAnnotations = annotations; + public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public readonly _methodNames: Array = methodNames; + constructor(connection: thrift.IThriftConnection) { + super(connection); + } + public ping(context?: Context): Promise { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("ping", thrift.MessageType.CALL, this.incrementRequestId()); + const args: IPing__ArgsArgs = {}; + Ping__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "ping") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); + } + else { + const result: IPing__Result = Ping__ResultCodec.decode(input); + input.readMessageEnd(); + return Promise.resolve(result.success); + } + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); + } + } + catch (err) { + return Promise.reject(err); + } + }); + } + public add(num1: number, num2: number, context?: Context): Promise { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("add", thrift.MessageType.CALL, this.incrementRequestId()); + const args: IAdd__ArgsArgs = { num1, num2 }; + Add__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "add") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); + } + else { + const result: IAdd__Result = Add__ResultCodec.decode(input); + input.readMessageEnd(); + if (result.exp != null) { + return Promise.reject(result.exp); + } + else if (result.success != null) { + return Promise.resolve(result.success); + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "add failed: unknown result")); + } + } + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); + } + } + catch (err) { + return Promise.reject(err); + } + }); + } + public addInt64(num1: number | string | thrift.Int64, num2: number | string | thrift.Int64, context?: Context): Promise { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("addInt64", thrift.MessageType.CALL, this.incrementRequestId()); + const args: IAddInt64__ArgsArgs = { num1, num2 }; + AddInt64__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "addInt64") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); + } + else { + const result: IAddInt64__Result = AddInt64__ResultCodec.decode(input); + input.readMessageEnd(); + if (result.exp != null) { + return Promise.reject(result.exp); + } + else if (result.success != null) { + return Promise.resolve(result.success); + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "addInt64 failed: unknown result")); + } + } + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); + } + } + catch (err) { + return Promise.reject(err); + } + }); + } + public addWithContext(num1: number, num2: number, context?: Context): Promise { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("addWithContext", thrift.MessageType.CALL, this.incrementRequestId()); + const args: IAddWithContext__ArgsArgs = { num1, num2 }; + AddWithContext__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "addWithContext") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); + } + else { + const result: IAddWithContext__Result = AddWithContext__ResultCodec.decode(input); + input.readMessageEnd(); + if (result.success != null) { + return Promise.resolve(result.success); + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "addWithContext failed: unknown result")); + } + } + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); + } + } + catch (err) { + return Promise.reject(err); + } + }); + } + public calculate(logid: number, work: __NAMESPACE__.IWorkArgs, context?: Context): Promise { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("calculate", thrift.MessageType.CALL, this.incrementRequestId()); + const args: ICalculate__ArgsArgs = { logid, work }; + Calculate__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "calculate") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); + } + else { + const result: ICalculate__Result = Calculate__ResultCodec.decode(input); + input.readMessageEnd(); + if (result.ouch != null) { + return Promise.reject(result.ouch); + } + else if (result.success != null) { + return Promise.resolve(result.success); + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "calculate failed: unknown result")); + } + } + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); + } + } + catch (err) { + return Promise.reject(err); + } + }); + } + public echoBinary(word: string | Buffer, context?: Context): Promise { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("echoBinary", thrift.MessageType.CALL, this.incrementRequestId()); + const args: IEchoBinary__ArgsArgs = { word }; + EchoBinary__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "echoBinary") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); + } + else { + const result: IEchoBinary__Result = EchoBinary__ResultCodec.decode(input); + input.readMessageEnd(); + if (result.success != null) { + return Promise.resolve(result.success); + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "echoBinary failed: unknown result")); + } + } + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); + } + } + catch (err) { + return Promise.reject(err); + } + }); + } + public echoString(word: string, context?: Context): Promise { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("echoString", thrift.MessageType.CALL, this.incrementRequestId()); + const args: IEchoString__ArgsArgs = { word }; + EchoString__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "echoString") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); + } + else { + const result: IEchoString__Result = EchoString__ResultCodec.decode(input); + input.readMessageEnd(); + if (result.success != null) { + return Promise.resolve(result.success); + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "echoString failed: unknown result")); + } + } + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); + } + } + catch (err) { + return Promise.reject(err); + } + }); + } + public checkName(choice: __NAMESPACE__.IChoiceArgs, context?: Context): Promise { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("checkName", thrift.MessageType.CALL, this.incrementRequestId()); + const args: ICheckName__ArgsArgs = { choice }; + CheckName__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "checkName") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); + } + else { + const result: ICheckName__Result = CheckName__ResultCodec.decode(input); + input.readMessageEnd(); + if (result.success != null) { + return Promise.resolve(result.success); + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "checkName failed: unknown result")); + } + } + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); + } + } + catch (err) { + return Promise.reject(err); + } + }); + } + public checkOptional(type?: string, context?: Context): Promise { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("checkOptional", thrift.MessageType.CALL, this.incrementRequestId()); + const args: ICheckOptional__ArgsArgs = { type }; + CheckOptional__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "checkOptional") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); + } + else { + const result: ICheckOptional__Result = CheckOptional__ResultCodec.decode(input); + input.readMessageEnd(); + if (result.success != null) { + return Promise.resolve(result.success); + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "checkOptional failed: unknown result")); + } + } + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); + } + } + catch (err) { + return Promise.reject(err); + } + }); + } + public mapOneList(arg: Array, context?: Context): Promise> { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("mapOneList", thrift.MessageType.CALL, this.incrementRequestId()); + const args: IMapOneList__ArgsArgs = { arg }; + MapOneList__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "mapOneList") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); + } + else { + const result: IMapOneList__Result = MapOneList__ResultCodec.decode(input); + input.readMessageEnd(); + if (result.success != null) { + return Promise.resolve(result.success); + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "mapOneList failed: unknown result")); + } + } + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); + } + } + catch (err) { + return Promise.reject(err); + } + }); + } + public mapValues(arg: Map, context?: Context): Promise> { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("mapValues", thrift.MessageType.CALL, this.incrementRequestId()); + const args: IMapValues__ArgsArgs = { arg }; + MapValues__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "mapValues") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); + } + else { + const result: IMapValues__Result = MapValues__ResultCodec.decode(input); + input.readMessageEnd(); + if (result.success != null) { + return Promise.resolve(result.success); + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "mapValues failed: unknown result")); + } + } + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); + } + } + catch (err) { + return Promise.reject(err); + } + }); + } + public listToMap(arg: Array>, context?: Context): Promise> { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("listToMap", thrift.MessageType.CALL, this.incrementRequestId()); + const args: IListToMap__ArgsArgs = { arg }; + ListToMap__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "listToMap") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); + } + else { + const result: IListToMap__Result = ListToMap__ResultCodec.decode(input); + input.readMessageEnd(); + if (result.success != null) { + return Promise.resolve(result.success); + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "listToMap failed: unknown result")); + } + } + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); + } + } + catch (err) { + return Promise.reject(err); + } + }); + } + public fetchThing(context?: Context): Promise { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("fetchThing", thrift.MessageType.CALL, this.incrementRequestId()); + const args: IFetchThing__ArgsArgs = {}; + FetchThing__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "fetchThing") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); + } + else { + const result: IFetchThing__Result = FetchThing__ResultCodec.decode(input); + input.readMessageEnd(); + if (result.success != null) { + return Promise.resolve(result.success); + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "fetchThing failed: unknown result")); + } + } + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); + } + } + catch (err) { + return Promise.reject(err); + } + }); + } + public zip(context?: Context): Promise { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("zip", thrift.MessageType.CALL, this.incrementRequestId()); + const args: IZip__ArgsArgs = {}; + Zip__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "zip") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); + } + else { + const result: IZip__Result = Zip__ResultCodec.decode(input); + input.readMessageEnd(); + return Promise.resolve(result.success); + } + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); + } + } + catch (err) { + return Promise.reject(err); + } + }); + } +} +export interface ILocalHandler { + ping(context?: Context): void | Promise; + add(num1: number, num2: number, context?: Context): number | Promise; + addInt64(num1: thrift.Int64, num2: thrift.Int64, context?: Context): (number | string | thrift.Int64) | Promise; + addWithContext(num1: number, num2: number, context?: Context): number | Promise; + calculate(logid: number, work: __NAMESPACE__.IWork, context?: Context): number | Promise; + echoBinary(word: Buffer, context?: Context): string | Promise; + echoString(word: string, context?: Context): string | Promise; + checkName(choice: __NAMESPACE__.IChoice, context?: Context): string | Promise; + checkOptional(type?: string, context?: Context): string | Promise; + mapOneList(arg: Array, context?: Context): Array | Promise>; + mapValues(arg: Map, context?: Context): Array | Promise>; + listToMap(arg: Array>, context?: Context): Map | Promise>; + fetchThing(context?: Context): com_test_common.ICommonStructArgs | Promise; + zip(context?: Context): void | Promise; +} +export type IHandler = ILocalHandler & com_test_shared.SharedService.IHandler; +export class Processor extends com_test_shared.SharedService.Processor { + protected readonly _handler: IHandler; + public static readonly serviceName: string = serviceName; + public static readonly annotations: thrift.IThriftAnnotations = annotations; + public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public static readonly methodNames: Array = methodNames; + public readonly _serviceName: string = serviceName; + public readonly _annotations: thrift.IThriftAnnotations = annotations; + public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public readonly _methodNames: Array = methodNames; + constructor(handler: IHandler) { + super({ + getStruct: handler.getStruct, + getUnion: handler.getUnion + }); + this._handler = handler; + } + public process(input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + const metadata: thrift.IThriftMessage = input.readMessageBegin(); + const fieldName: string = metadata.fieldName; + const requestId: number = metadata.requestId; + const methodName: string = "process_" + fieldName; + switch (methodName) { + case "process_getStruct": { + resolve(this.process_getStruct(requestId, input, output, context)); + break; + } + case "process_getUnion": { + resolve(this.process_getUnion(requestId, input, output, context)); + break; + } + case "process_ping": { + resolve(this.process_ping(requestId, input, output, context)); + break; + } + case "process_add": { + resolve(this.process_add(requestId, input, output, context)); + break; + } + case "process_addInt64": { + resolve(this.process_addInt64(requestId, input, output, context)); + break; + } + case "process_addWithContext": { + resolve(this.process_addWithContext(requestId, input, output, context)); + break; + } + case "process_calculate": { + resolve(this.process_calculate(requestId, input, output, context)); + break; + } + case "process_echoBinary": { + resolve(this.process_echoBinary(requestId, input, output, context)); + break; + } + case "process_echoString": { + resolve(this.process_echoString(requestId, input, output, context)); + break; + } + case "process_checkName": { + resolve(this.process_checkName(requestId, input, output, context)); + break; + } + case "process_checkOptional": { + resolve(this.process_checkOptional(requestId, input, output, context)); + break; + } + case "process_mapOneList": { + resolve(this.process_mapOneList(requestId, input, output, context)); + break; + } + case "process_mapValues": { + resolve(this.process_mapValues(requestId, input, output, context)); + break; + } + case "process_listToMap": { + resolve(this.process_listToMap(requestId, input, output, context)); + break; + } + case "process_fetchThing": { + resolve(this.process_fetchThing(requestId, input, output, context)); + break; + } + case "process_zip": { + resolve(this.process_zip(requestId, input, output, context)); + break; + } + default: { + input.skip(thrift.TType.STRUCT); + input.readMessageEnd(); + const errMessage = "Unknown function " + fieldName; + const err = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN_METHOD, errMessage); + output.writeMessageBegin(fieldName, thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(err, output); + output.writeMessageEnd(); + resolve(output.flush()); + break; + } + } + }); + } + public process_ping(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + try { + input.readMessageEnd(); + resolve(this._handler.ping(context)); + } + catch (err) { + reject(err); + } + }).then((data: void): Buffer => { + const result: IPing__ResultArgs = { success: data }; + output.writeMessageBegin("ping", thrift.MessageType.REPLY, requestId); + Ping__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("ping", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }); + } + public process_add(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + try { + const args: IAdd__Args = Add__ArgsCodec.decode(input); + input.readMessageEnd(); + resolve(this._handler.add(args.num1, args.num2, context)); + } + catch (err) { + reject(err); + } + }).then((data: number): Buffer => { + const result: IAdd__ResultArgs = { success: data }; + output.writeMessageBegin("add", thrift.MessageType.REPLY, requestId); + Add__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + if (err instanceof com_test_operation.JankyResult) { + const result: IAdd__ResultArgs = { exp: err }; + output.writeMessageBegin("add", thrift.MessageType.REPLY, requestId); + Add__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + } + else { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("add", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + } + }); + } + public process_addInt64(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + try { + const args: IAddInt64__Args = AddInt64__ArgsCodec.decode(input); + input.readMessageEnd(); + resolve(this._handler.addInt64(args.num1, args.num2, context)); + } + catch (err) { + reject(err); + } + }).then((data: number | string | thrift.Int64): Buffer => { + const result: IAddInt64__ResultArgs = { success: data }; + output.writeMessageBegin("addInt64", thrift.MessageType.REPLY, requestId); + AddInt64__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + if (err instanceof __NAMESPACE__.NotAGoodIdea) { + const result: IAddInt64__ResultArgs = { exp: err }; + output.writeMessageBegin("addInt64", thrift.MessageType.REPLY, requestId); + AddInt64__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + } + else { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("addInt64", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + } + }); + } + public process_addWithContext(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + try { + const args: IAddWithContext__Args = AddWithContext__ArgsCodec.decode(input); + input.readMessageEnd(); + resolve(this._handler.addWithContext(args.num1, args.num2, context)); + } + catch (err) { + reject(err); + } + }).then((data: number): Buffer => { + const result: IAddWithContext__ResultArgs = { success: data }; + output.writeMessageBegin("addWithContext", thrift.MessageType.REPLY, requestId); + AddWithContext__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("addWithContext", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }); + } + public process_calculate(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + try { + const args: ICalculate__Args = Calculate__ArgsCodec.decode(input); + input.readMessageEnd(); + resolve(this._handler.calculate(args.logid, args.work, context)); + } + catch (err) { + reject(err); + } + }).then((data: number): Buffer => { + const result: ICalculate__ResultArgs = { success: data }; + output.writeMessageBegin("calculate", thrift.MessageType.REPLY, requestId); + Calculate__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + if (err instanceof com_test_operation.JankyOperation) { + const result: ICalculate__ResultArgs = { ouch: err }; + output.writeMessageBegin("calculate", thrift.MessageType.REPLY, requestId); + Calculate__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + } + else { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("calculate", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + } + }); + } + public process_echoBinary(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + try { + const args: IEchoBinary__Args = EchoBinary__ArgsCodec.decode(input); + input.readMessageEnd(); + resolve(this._handler.echoBinary(args.word, context)); + } + catch (err) { + reject(err); + } + }).then((data: string): Buffer => { + const result: IEchoBinary__ResultArgs = { success: data }; + output.writeMessageBegin("echoBinary", thrift.MessageType.REPLY, requestId); + EchoBinary__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("echoBinary", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }); + } + public process_echoString(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + try { + const args: IEchoString__Args = EchoString__ArgsCodec.decode(input); + input.readMessageEnd(); + resolve(this._handler.echoString(args.word, context)); + } + catch (err) { + reject(err); + } + }).then((data: string): Buffer => { + const result: IEchoString__ResultArgs = { success: data }; + output.writeMessageBegin("echoString", thrift.MessageType.REPLY, requestId); + EchoString__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("echoString", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }); + } + public process_checkName(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + try { + const args: ICheckName__Args = CheckName__ArgsCodec.decode(input); + input.readMessageEnd(); + resolve(this._handler.checkName(args.choice, context)); + } + catch (err) { + reject(err); + } + }).then((data: string): Buffer => { + const result: ICheckName__ResultArgs = { success: data }; + output.writeMessageBegin("checkName", thrift.MessageType.REPLY, requestId); + CheckName__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("checkName", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }); + } + public process_checkOptional(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + try { + const args: ICheckOptional__Args = CheckOptional__ArgsCodec.decode(input); + input.readMessageEnd(); + resolve(this._handler.checkOptional(args.type, context)); + } + catch (err) { + reject(err); + } + }).then((data: string): Buffer => { + const result: ICheckOptional__ResultArgs = { success: data }; + output.writeMessageBegin("checkOptional", thrift.MessageType.REPLY, requestId); + CheckOptional__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("checkOptional", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }); + } + public process_mapOneList(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise>((resolve, reject): void => { + try { + const args: IMapOneList__Args = MapOneList__ArgsCodec.decode(input); + input.readMessageEnd(); + resolve(this._handler.mapOneList(args.arg, context)); + } + catch (err) { + reject(err); + } + }).then((data: Array): Buffer => { + const result: IMapOneList__ResultArgs = { success: data }; + output.writeMessageBegin("mapOneList", thrift.MessageType.REPLY, requestId); + MapOneList__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("mapOneList", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }); + } + public process_mapValues(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise>((resolve, reject): void => { + try { + const args: IMapValues__Args = MapValues__ArgsCodec.decode(input); + input.readMessageEnd(); + resolve(this._handler.mapValues(args.arg, context)); + } + catch (err) { + reject(err); + } + }).then((data: Array): Buffer => { + const result: IMapValues__ResultArgs = { success: data }; + output.writeMessageBegin("mapValues", thrift.MessageType.REPLY, requestId); + MapValues__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("mapValues", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }); + } + public process_listToMap(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise>((resolve, reject): void => { + try { + const args: IListToMap__Args = ListToMap__ArgsCodec.decode(input); + input.readMessageEnd(); + resolve(this._handler.listToMap(args.arg, context)); + } + catch (err) { + reject(err); + } + }).then((data: Map): Buffer => { + const result: IListToMap__ResultArgs = { success: data }; + output.writeMessageBegin("listToMap", thrift.MessageType.REPLY, requestId); + ListToMap__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("listToMap", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }); + } + public process_fetchThing(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + try { + input.readMessageEnd(); + resolve(this._handler.fetchThing(context)); + } + catch (err) { + reject(err); + } + }).then((data: com_test_common.ICommonStructArgs): Buffer => { + const result: IFetchThing__ResultArgs = { success: data }; + output.writeMessageBegin("fetchThing", thrift.MessageType.REPLY, requestId); + FetchThing__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("fetchThing", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }); + } + public process_zip(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + try { + input.readMessageEnd(); + resolve(this._handler.zip(context)); + } + catch (err) { + reject(err); + } + }).then((data: void): Buffer => { + const result: IZip__ResultArgs = { success: data }; + output.writeMessageBegin("zip", thrift.MessageType.REPLY, requestId); + Zip__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("zip", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }); + } +} diff --git a/src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/Choice.ts b/src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/Choice.ts new file mode 100644 index 00000000..0d754d1d --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/Choice.ts @@ -0,0 +1,133 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as thrift from "test-lib"; +import * as __NAMESPACE__ from "./."; +export interface IChoice { + firstName?: __NAMESPACE__.IFirstName; + lastName?: __NAMESPACE__.ILastName; +} +export interface IChoiceArgs { + firstName?: __NAMESPACE__.IFirstNameArgs; + lastName?: __NAMESPACE__.ILastNameArgs; +} +export const ChoiceCodec: thrift.IStructCodec = { + encode(args: IChoiceArgs, output: thrift.TProtocol): void { + let _fieldsSet: number = 0; + const obj = { + firstName: args.firstName, + lastName: args.lastName + }; + output.writeStructBegin("Choice"); + if (obj.firstName != null) { + _fieldsSet++; + output.writeFieldBegin("firstName", thrift.TType.STRUCT, 1); + __NAMESPACE__.FirstNameCodec.encode(obj.firstName, output); + output.writeFieldEnd(); + } + if (obj.lastName != null) { + _fieldsSet++; + output.writeFieldBegin("lastName", thrift.TType.STRUCT, 2); + __NAMESPACE__.LastNameCodec.encode(obj.lastName, output); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + if (_fieldsSet > 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion cannot have more than one value"); + } + else if (_fieldsSet < 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion must have one value set"); + } + return; + }, + decode(input: thrift.TProtocol): IChoice { + let _fieldsSet: number = 0; + let _returnValue: IChoice | null = null; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.STRUCT) { + _fieldsSet++; + const value_1: __NAMESPACE__.IFirstName = __NAMESPACE__.FirstNameCodec.decode(input); + _returnValue = { firstName: value_1 }; + } + else { + input.skip(fieldType); + } + break; + case 2: + if (fieldType === thrift.TType.STRUCT) { + _fieldsSet++; + const value_2: __NAMESPACE__.ILastName = __NAMESPACE__.LastNameCodec.decode(input); + _returnValue = { lastName: value_2 }; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_fieldsSet > 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion cannot have more than one value"); + } + else if (_fieldsSet < 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion must have one value set"); + } + if (_returnValue !== null) { + return _returnValue; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read data for TUnion"); + } + } +}; +export class Choice extends thrift.StructLike implements IChoice { + public firstName?: __NAMESPACE__.IFirstName; + public lastName?: __NAMESPACE__.ILastName; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IChoiceArgs = {}) { + super(); + let _fieldsSet: number = 0; + if (args.firstName != null) { + _fieldsSet++; + const value_3: __NAMESPACE__.IFirstName = new __NAMESPACE__.FirstName(args.firstName); + this.firstName = value_3; + } + if (args.lastName != null) { + _fieldsSet++; + const value_4: __NAMESPACE__.ILastName = new __NAMESPACE__.LastName(args.lastName); + this.lastName = value_4; + } + if (_fieldsSet > 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion cannot have more than one value"); + } + else if (_fieldsSet < 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion must have one value set"); + } + } + public static read(input: thrift.TProtocol): Choice { + return new Choice(ChoiceCodec.decode(input)); + } + public static write(args: IChoiceArgs, output: thrift.TProtocol): void { + return ChoiceCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return ChoiceCodec.encode(this, output); + } +} diff --git a/src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/FirstName.ts b/src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/FirstName.ts new file mode 100644 index 00000000..e7f41e65 --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/FirstName.ts @@ -0,0 +1,80 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as thrift from "test-lib"; +export interface IFirstName { + name?: string; +} +export interface IFirstNameArgs { + name?: string; +} +export const FirstNameCodec: thrift.IStructCodec = { + encode(args: IFirstNameArgs, output: thrift.TProtocol): void { + const obj = { + name: args.name + }; + output.writeStructBegin("FirstName"); + if (obj.name != null) { + output.writeFieldBegin("name", thrift.TType.STRING, 1); + output.writeString(obj.name); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IFirstName { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.STRING) { + const value_1: string = input.readString(); + _args.name = value_1; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + name: _args.name + }; + } +}; +export class FirstName extends thrift.StructLike implements IFirstName { + public name?: string; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IFirstNameArgs = {}) { + super(); + if (args.name != null) { + const value_2: string = args.name; + this.name = value_2; + } + } + public static read(input: thrift.TProtocol): FirstName { + return new FirstName(FirstNameCodec.decode(input)); + } + public static write(args: IFirstNameArgs, output: thrift.TProtocol): void { + return FirstNameCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return FirstNameCodec.encode(this, output); + } +} diff --git a/src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/LastName.ts b/src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/LastName.ts new file mode 100644 index 00000000..6d44e129 --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/LastName.ts @@ -0,0 +1,80 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as thrift from "test-lib"; +export interface ILastName { + name?: string; +} +export interface ILastNameArgs { + name?: string; +} +export const LastNameCodec: thrift.IStructCodec = { + encode(args: ILastNameArgs, output: thrift.TProtocol): void { + const obj = { + name: args.name + }; + output.writeStructBegin("LastName"); + if (obj.name != null) { + output.writeFieldBegin("name", thrift.TType.STRING, 1); + output.writeString(obj.name); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): ILastName { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.STRING) { + const value_1: string = input.readString(); + _args.name = value_1; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + name: _args.name + }; + } +}; +export class LastName extends thrift.StructLike implements ILastName { + public name?: string; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: ILastNameArgs = {}) { + super(); + if (args.name != null) { + const value_2: string = args.name; + this.name = value_2; + } + } + public static read(input: thrift.TProtocol): LastName { + return new LastName(LastNameCodec.decode(input)); + } + public static write(args: ILastNameArgs, output: thrift.TProtocol): void { + return LastNameCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return LastNameCodec.encode(this, output); + } +} diff --git a/src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/NotAGoodIdea.ts b/src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/NotAGoodIdea.ts new file mode 100644 index 00000000..e36e6345 --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/NotAGoodIdea.ts @@ -0,0 +1,80 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as thrift from "test-lib"; +export interface INotAGoodIdea { + message?: string; +} +export interface INotAGoodIdeaArgs { + message?: string; +} +export const NotAGoodIdeaCodec: thrift.IStructCodec = { + encode(args: INotAGoodIdeaArgs, output: thrift.TProtocol): void { + const obj = { + message: args.message + }; + output.writeStructBegin("NotAGoodIdea"); + if (obj.message != null) { + output.writeFieldBegin("message", thrift.TType.STRING, 1); + output.writeString(obj.message); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): INotAGoodIdea { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.STRING) { + const value_1: string = input.readString(); + _args.message = value_1; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + message: _args.message + }; + } +}; +export class NotAGoodIdea extends thrift.StructLike implements INotAGoodIdea { + public message?: string; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: INotAGoodIdeaArgs = {}) { + super(); + if (args.message != null) { + const value_2: string = args.message; + this.message = value_2; + } + } + public static read(input: thrift.TProtocol): NotAGoodIdea { + return new NotAGoodIdea(NotAGoodIdeaCodec.decode(input)); + } + public static write(args: INotAGoodIdeaArgs, output: thrift.TProtocol): void { + return NotAGoodIdeaCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return NotAGoodIdeaCodec.encode(this, output); + } +} diff --git a/src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/Work.ts b/src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/Work.ts new file mode 100644 index 00000000..6fe13f6d --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/Work.ts @@ -0,0 +1,161 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as thrift from "test-lib"; +import * as __NAMESPACE__ from "./."; +export interface IWork { + num1: number; + num2: number; + op?: __NAMESPACE__.Operation; + comment?: string; +} +export interface IWorkArgs { + num1?: number; + num2: number; + op?: __NAMESPACE__.Operation; + comment?: string; +} +export const WorkCodec: thrift.IStructCodec = { + encode(args: IWorkArgs, output: thrift.TProtocol): void { + const obj = { + num1: (args.num1 != null ? args.num1 : 0), + num2: args.num2, + op: (args.op != null ? args.op : __NAMESPACE__.Operation.ADD), + comment: args.comment + }; + output.writeStructBegin("Work"); + if (obj.num1 != null) { + output.writeFieldBegin("num1", thrift.TType.I32, 1); + output.writeI32(obj.num1); + output.writeFieldEnd(); + } + if (obj.num2 != null) { + output.writeFieldBegin("num2", thrift.TType.I32, 2); + output.writeI32(obj.num2); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num2] is unset!"); + } + if (obj.op != null) { + output.writeFieldBegin("op", thrift.TType.I32, 3); + output.writeI32(obj.op); + output.writeFieldEnd(); + } + if (obj.comment != null) { + output.writeFieldBegin("comment", thrift.TType.STRING, 4); + output.writeString(obj.comment); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IWork { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.I32) { + const value_1: number = input.readI32(); + _args.num1 = value_1; + } + else { + input.skip(fieldType); + } + break; + case 2: + if (fieldType === thrift.TType.I32) { + const value_2: number = input.readI32(); + _args.num2 = value_2; + } + else { + input.skip(fieldType); + } + break; + case 3: + if (fieldType === thrift.TType.I32) { + const value_3: __NAMESPACE__.Operation = input.readI32(); + _args.op = value_3; + } + else { + input.skip(fieldType); + } + break; + case 4: + if (fieldType === thrift.TType.STRING) { + const value_4: string = input.readString(); + _args.comment = value_4; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.num1 !== undefined && _args.num2 !== undefined) { + return { + num1: (_args.num1 != null ? _args.num1 : 0), + num2: _args.num2, + op: (_args.op != null ? _args.op : __NAMESPACE__.Operation.ADD), + comment: _args.comment + }; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read Work from input"); + } + } +}; +export class Work extends thrift.StructLike implements IWork { + public num1: number = 0; + public num2: number; + public op?: __NAMESPACE__.Operation = __NAMESPACE__.Operation.ADD; + public comment?: string; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IWorkArgs) { + super(); + if (args.num1 != null) { + const value_5: number = args.num1; + this.num1 = value_5; + } + if (args.num2 != null) { + const value_6: number = args.num2; + this.num2 = value_6; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[num2] is unset!"); + } + if (args.op != null) { + const value_7: __NAMESPACE__.Operation = args.op; + this.op = value_7; + } + if (args.comment != null) { + const value_8: string = args.comment; + this.comment = value_8; + } + } + public static read(input: thrift.TProtocol): Work { + return new Work(WorkCodec.decode(input)); + } + public static write(args: IWorkArgs, output: thrift.TProtocol): void { + return WorkCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return WorkCodec.encode(this, output); + } +} diff --git a/src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/constants.ts b/src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/constants.ts new file mode 100644 index 00000000..e023784e --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/constants.ts @@ -0,0 +1,7 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +export const INT32CONSTANT: number = 9853; +export const MAPCONSTANT: Map = new Map([["hello", "world"], ["goodnight", "moon"]]); diff --git a/src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/index.ts b/src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/index.ts new file mode 100644 index 00000000..6c07a209 --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/index.ts @@ -0,0 +1,14 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +export * from "./constants"; +export * from "./typedefs"; +export * from "./Work"; +export * from "./FirstName"; +export * from "./LastName"; +export * from "./Choice"; +export * from "./NotAGoodIdea"; +import * as Calculator from "./Calculator"; +export { Calculator as Calculator }; diff --git a/src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/typedefs.ts b/src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/typedefs.ts new file mode 100644 index 00000000..86551bad --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/typedefs.ts @@ -0,0 +1,13 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as com_test_operation from "./../operation"; +import * as com_test_common from "./../common"; +export type MyInteger = number; +export import Operation = com_test_operation.Operation; +export import ICommonStruct = com_test_common.ICommonStruct; +export import ICommonStructArgs = com_test_common.ICommonStructArgs; +export import CommonStruct = com_test_common.CommonStruct; +export import CommonStructCodec = com_test_common.CommonStructCodec; diff --git a/src/tests/unit/fixtures/generated/common/index.ts b/src/tests/unit/fixtures/thrift-server/generated/com/test/common/AuthException.ts similarity index 87% rename from src/tests/unit/fixtures/generated/common/index.ts rename to src/tests/unit/fixtures/thrift-server/generated/com/test/common/AuthException.ts index f3a91842..e717de0f 100644 --- a/src/tests/unit/fixtures/generated/common/index.ts +++ b/src/tests/unit/fixtures/thrift-server/generated/com/test/common/AuthException.ts @@ -4,16 +4,6 @@ * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING */ import * as thrift from "test-lib"; -import * as shared from "./../shared"; -export import ICommonStruct = shared.ISharedStruct; -export import ICommonStructArgs = shared.ISharedStructArgs; -export import CommonStruct = shared.SharedStruct; -export import CommonStructCodec = shared.SharedStructCodec; -export import ICommonUnion = shared.ISharedUnion; -export import ICommonUnionArgs = shared.ISharedUnionArgs; -export import CommonUnion = shared.SharedUnion; -export import CommonUnionCodec = shared.SharedUnionCodec; -export import COMMON_INT = shared.SHARED_INT; export interface IAuthException { code?: number; message?: string; diff --git a/src/tests/unit/fixtures/thrift-server/generated/com/test/common/OtherCommonUnion.ts b/src/tests/unit/fixtures/thrift-server/generated/com/test/common/OtherCommonUnion.ts new file mode 100644 index 00000000..551f4c16 --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated/com/test/common/OtherCommonUnion.ts @@ -0,0 +1,132 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v3.3.4 + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as thrift from "test-lib"; +export interface IOtherCommonUnion { + option1?: string; + option2?: number; +} +export interface IOtherCommonUnionArgs { + option1?: string; + option2?: number; +} +export const OtherCommonUnionCodec: thrift.IStructCodec = { + encode(args: IOtherCommonUnionArgs, output: thrift.TProtocol): void { + let _fieldsSet: number = 0; + const obj = { + option1: args.option1, + option2: args.option2 + }; + output.writeStructBegin("OtherCommonUnion"); + if (obj.option1 != null) { + _fieldsSet++; + output.writeFieldBegin("option1", thrift.TType.STRING, 1); + output.writeString(obj.option1); + output.writeFieldEnd(); + } + if (obj.option2 != null) { + _fieldsSet++; + output.writeFieldBegin("option2", thrift.TType.I32, 2); + output.writeI32(obj.option2); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + if (_fieldsSet > 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion cannot have more than one value"); + } + else if (_fieldsSet < 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion must have one value set"); + } + return; + }, + decode(input: thrift.TProtocol): IOtherCommonUnion { + let _fieldsSet: number = 0; + let _returnValue: IOtherCommonUnion | null = null; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.STRING) { + _fieldsSet++; + const value_1: string = input.readString(); + _returnValue = { option1: value_1 }; + } + else { + input.skip(fieldType); + } + break; + case 2: + if (fieldType === thrift.TType.I32) { + _fieldsSet++; + const value_2: number = input.readI32(); + _returnValue = { option2: value_2 }; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_fieldsSet > 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion cannot have more than one value"); + } + else if (_fieldsSet < 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion must have one value set"); + } + if (_returnValue !== null) { + return _returnValue; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read data for TUnion"); + } + } +}; +export class OtherCommonUnion extends thrift.StructLike implements IOtherCommonUnion { + public option1?: string; + public option2?: number; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IOtherCommonUnionArgs = {}) { + super(); + let _fieldsSet: number = 0; + if (args.option1 != null) { + _fieldsSet++; + const value_3: string = args.option1; + this.option1 = value_3; + } + if (args.option2 != null) { + _fieldsSet++; + const value_4: number = args.option2; + this.option2 = value_4; + } + if (_fieldsSet > 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion cannot have more than one value"); + } + else if (_fieldsSet < 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion must have one value set"); + } + } + public static read(input: thrift.TProtocol): OtherCommonUnion { + return new OtherCommonUnion(OtherCommonUnionCodec.decode(input)); + } + public static write(args: IOtherCommonUnionArgs, output: thrift.TProtocol): void { + return OtherCommonUnionCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return OtherCommonUnionCodec.encode(this, output); + } +} diff --git a/src/tests/unit/fixtures/thrift-server/generated/com/test/common/index.ts b/src/tests/unit/fixtures/thrift-server/generated/com/test/common/index.ts new file mode 100644 index 00000000..e58427d6 --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated/com/test/common/index.ts @@ -0,0 +1,8 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v3.3.4 + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +export * from "./typedefs"; +export * from "./OtherCommonUnion"; +export * from "./AuthException"; diff --git a/src/tests/unit/fixtures/thrift-server/generated/com/test/common/typedefs.ts b/src/tests/unit/fixtures/thrift-server/generated/com/test/common/typedefs.ts new file mode 100644 index 00000000..ac141300 --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated/com/test/common/typedefs.ts @@ -0,0 +1,24 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v3.3.4 + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as com_test_shared from "./../shared"; +import * as __NAMESPACE__ from "./."; +export import ICommonStruct = com_test_shared.ISharedStruct; +export import ICommonStructArgs = com_test_shared.ISharedStructArgs; +export import CommonStruct = com_test_shared.SharedStruct; +export import CommonStructCodec = com_test_shared.SharedStructCodec; +export import ICommonUnion = com_test_shared.ISharedUnion; +export import ICommonUnionArgs = com_test_shared.ISharedUnionArgs; +export import CommonUnion = com_test_shared.SharedUnion; +export import CommonUnionCodec = com_test_shared.SharedUnionCodec; +export import COMMON_INT = com_test_shared.SHARED_INT; +export import INotAllowed = __NAMESPACE__.IAuthException; +export import INotAllowedArgs = __NAMESPACE__.IAuthExceptionArgs; +export import NotAllowed = __NAMESPACE__.AuthException; +export import NotAllowedCodec = __NAMESPACE__.AuthExceptionCodec; +export import IMoreOptions = __NAMESPACE__.IOtherCommonUnion; +export import IMoreOptionsArgs = __NAMESPACE__.IOtherCommonUnionArgs; +export import MoreOptions = __NAMESPACE__.OtherCommonUnion; +export import MoreOptionsCodec = __NAMESPACE__.OtherCommonUnionCodec; diff --git a/src/tests/unit/fixtures/generated/strict-unions/exceptions/index.ts b/src/tests/unit/fixtures/thrift-server/generated/com/test/exceptions/InvalidOperation.ts similarity index 50% rename from src/tests/unit/fixtures/generated/strict-unions/exceptions/index.ts rename to src/tests/unit/fixtures/thrift-server/generated/com/test/exceptions/InvalidOperation.ts index bf14ed8c..25030ce4 100644 --- a/src/tests/unit/fixtures/generated/strict-unions/exceptions/index.ts +++ b/src/tests/unit/fixtures/thrift-server/generated/com/test/exceptions/InvalidOperation.ts @@ -4,7 +4,6 @@ * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING */ import * as thrift from "test-lib"; -import * as shared from "./../shared"; export interface IInvalidOperation { whatOp?: number; why?: string; @@ -102,100 +101,3 @@ export class InvalidOperation extends thrift.StructLike implements IInvalidOpera return InvalidOperationCodec.encode(this, output); } } -export interface IInvalidResult { - message?: string; - code?: shared.ICode; -} -export interface IInvalidResultArgs { - message?: string; - code?: shared.ICodeArgs; -} -export const InvalidResultCodec: thrift.IStructCodec = { - encode(args: IInvalidResultArgs, output: thrift.TProtocol): void { - const obj = { - message: args.message, - code: args.code - }; - output.writeStructBegin("InvalidResult"); - if (obj.message != null) { - output.writeFieldBegin("message", thrift.TType.STRING, 1); - output.writeString(obj.message); - output.writeFieldEnd(); - } - if (obj.code != null) { - output.writeFieldBegin("code", thrift.TType.STRUCT, 2); - shared.CodeCodec.encode(obj.code, output); - output.writeFieldEnd(); - } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IInvalidResult { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.STRING) { - const value_5: string = input.readString(); - _args.message = value_5; - } - else { - input.skip(fieldType); - } - break; - case 2: - if (fieldType === thrift.TType.STRUCT) { - const value_6: shared.ICode = shared.CodeCodec.decode(input); - _args.code = value_6; - } - else { - input.skip(fieldType); - } - break; - default: { - input.skip(fieldType); - } - } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - message: _args.message, - code: _args.code - }; - } -}; -export class InvalidResult extends thrift.StructLike implements IInvalidResult { - public message?: string; - public code?: shared.ICode; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IInvalidResultArgs = {}) { - super(); - if (args.message != null) { - const value_7: string = args.message; - this.message = value_7; - } - if (args.code != null) { - const value_8: shared.ICode = new shared.Code(args.code); - this.code = value_8; - } - } - public static read(input: thrift.TProtocol): InvalidResult { - return new InvalidResult(InvalidResultCodec.decode(input)); - } - public static write(args: IInvalidResultArgs, output: thrift.TProtocol): void { - return InvalidResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return InvalidResultCodec.encode(this, output); - } -} diff --git a/src/tests/unit/fixtures/thrift-server/generated/com/test/exceptions/InvalidResult.ts b/src/tests/unit/fixtures/thrift-server/generated/com/test/exceptions/InvalidResult.ts new file mode 100644 index 00000000..b89b71be --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated/com/test/exceptions/InvalidResult.ts @@ -0,0 +1,104 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as thrift from "test-lib"; +import * as com_test_shared from "./../shared"; +export interface IInvalidResult { + message?: string; + code?: com_test_shared.ICode; +} +export interface IInvalidResultArgs { + message?: string; + code?: com_test_shared.ICodeArgs; +} +export const InvalidResultCodec: thrift.IStructCodec = { + encode(args: IInvalidResultArgs, output: thrift.TProtocol): void { + const obj = { + message: args.message, + code: args.code + }; + output.writeStructBegin("InvalidResult"); + if (obj.message != null) { + output.writeFieldBegin("message", thrift.TType.STRING, 1); + output.writeString(obj.message); + output.writeFieldEnd(); + } + if (obj.code != null) { + output.writeFieldBegin("code", thrift.TType.STRUCT, 2); + com_test_shared.CodeCodec.encode(obj.code, output); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IInvalidResult { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.STRING) { + const value_1: string = input.readString(); + _args.message = value_1; + } + else { + input.skip(fieldType); + } + break; + case 2: + if (fieldType === thrift.TType.STRUCT) { + const value_2: com_test_shared.ICode = com_test_shared.CodeCodec.decode(input); + _args.code = value_2; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + message: _args.message, + code: _args.code + }; + } +}; +export class InvalidResult extends thrift.StructLike implements IInvalidResult { + public message?: string; + public code?: com_test_shared.ICode; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IInvalidResultArgs = {}) { + super(); + if (args.message != null) { + const value_3: string = args.message; + this.message = value_3; + } + if (args.code != null) { + const value_4: com_test_shared.ICode = new com_test_shared.Code(args.code); + this.code = value_4; + } + } + public static read(input: thrift.TProtocol): InvalidResult { + return new InvalidResult(InvalidResultCodec.decode(input)); + } + public static write(args: IInvalidResultArgs, output: thrift.TProtocol): void { + return InvalidResultCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return InvalidResultCodec.encode(this, output); + } +} diff --git a/src/tests/unit/fixtures/thrift-server/generated/com/test/exceptions/index.ts b/src/tests/unit/fixtures/thrift-server/generated/com/test/exceptions/index.ts new file mode 100644 index 00000000..c172cc5f --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated/com/test/exceptions/index.ts @@ -0,0 +1,7 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +export * from "./InvalidOperation"; +export * from "./InvalidResult"; diff --git a/src/tests/unit/fixtures/thrift-server/generated/com/test/operation/constants.ts b/src/tests/unit/fixtures/thrift-server/generated/com/test/operation/constants.ts new file mode 100644 index 00000000..292a3004 --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated/com/test/operation/constants.ts @@ -0,0 +1,11 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +export enum Operation { + ADD = 1, + SUBTRACT = 2, + MULTIPLY = 3, + DIVIDE = 4 +} diff --git a/src/tests/unit/fixtures/thrift-server/generated/com/test/operation/index.ts b/src/tests/unit/fixtures/thrift-server/generated/com/test/operation/index.ts new file mode 100644 index 00000000..1c98c541 --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated/com/test/operation/index.ts @@ -0,0 +1,7 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +export * from "./constants"; +export * from "./typedefs"; diff --git a/src/tests/unit/fixtures/thrift-server/generated/com/test/operation/typedefs.ts b/src/tests/unit/fixtures/thrift-server/generated/com/test/operation/typedefs.ts new file mode 100644 index 00000000..4769465b --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated/com/test/operation/typedefs.ts @@ -0,0 +1,16 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as com_test_exceptions from "./../exceptions"; +import * as __NAMESPACE__ from "./."; +export import IJankyOperation = com_test_exceptions.IInvalidOperation; +export import IJankyOperationArgs = com_test_exceptions.IInvalidOperationArgs; +export import JankyOperation = com_test_exceptions.InvalidOperation; +export import JankyOperationCodec = com_test_exceptions.InvalidOperationCodec; +export import IJankyResult = com_test_exceptions.IInvalidResult; +export import IJankyResultArgs = com_test_exceptions.IInvalidResultArgs; +export import JankyResult = com_test_exceptions.InvalidResult; +export import JankyResultCodec = com_test_exceptions.InvalidResultCodec; +export import SomethingToDo = __NAMESPACE__.Operation; diff --git a/src/tests/unit/fixtures/thrift-server/generated/com/test/shared/Code.ts b/src/tests/unit/fixtures/thrift-server/generated/com/test/shared/Code.ts new file mode 100644 index 00000000..fa81acbf --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated/com/test/shared/Code.ts @@ -0,0 +1,80 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as thrift from "test-lib"; +export interface ICode { + status?: thrift.Int64; +} +export interface ICodeArgs { + status?: number | string | thrift.Int64; +} +export const CodeCodec: thrift.IStructCodec = { + encode(args: ICodeArgs, output: thrift.TProtocol): void { + const obj = { + status: (typeof args.status === "number" ? new thrift.Int64(args.status) : typeof args.status === "string" ? thrift.Int64.fromDecimalString(args.status) : args.status) + }; + output.writeStructBegin("Code"); + if (obj.status != null) { + output.writeFieldBegin("status", thrift.TType.I64, 1); + output.writeI64((typeof obj.status === "number" ? new thrift.Int64(obj.status) : typeof obj.status === "string" ? thrift.Int64.fromDecimalString(obj.status) : obj.status)); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): ICode { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.I64) { + const value_1: thrift.Int64 = input.readI64(); + _args.status = value_1; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + status: _args.status + }; + } +}; +export class Code extends thrift.StructLike implements ICode { + public status?: thrift.Int64; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: ICodeArgs = {}) { + super(); + if (args.status != null) { + const value_2: thrift.Int64 = (typeof args.status === "number" ? new thrift.Int64(args.status) : typeof args.status === "string" ? thrift.Int64.fromDecimalString(args.status) : args.status); + this.status = value_2; + } + } + public static read(input: thrift.TProtocol): Code { + return new Code(CodeCodec.decode(input)); + } + public static write(args: ICodeArgs, output: thrift.TProtocol): void { + return CodeCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return CodeCodec.encode(this, output); + } +} diff --git a/src/tests/unit/fixtures/thrift-server/generated/com/test/shared/SharedService.ts b/src/tests/unit/fixtures/thrift-server/generated/com/test/shared/SharedService.ts new file mode 100644 index 00000000..0efffb53 --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated/com/test/shared/SharedService.ts @@ -0,0 +1,520 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as thrift from "test-lib"; +import * as __NAMESPACE__ from "./."; +export const serviceName: string = "SharedService"; +export const annotations: thrift.IThriftAnnotations = {}; +export const methodAnnotations: thrift.IMethodAnnotations = { + getStruct: { + annotations: {}, + fieldAnnotations: {} + }, + getUnion: { + annotations: {}, + fieldAnnotations: {} + } +}; +export const methodNames: Array = ["getStruct", "getUnion"]; +export interface IGetStruct__Args { + key: number; +} +export interface IGetStruct__ArgsArgs { + key: number; +} +export const GetStruct__ArgsCodec: thrift.IStructCodec = { + encode(args: IGetStruct__ArgsArgs, output: thrift.TProtocol): void { + const obj = { + key: args.key + }; + output.writeStructBegin("GetStruct__Args"); + if (obj.key != null) { + output.writeFieldBegin("key", thrift.TType.I32, 1); + output.writeI32(obj.key); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[key] is unset!"); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IGetStruct__Args { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.I32) { + const value_1: number = input.readI32(); + _args.key = value_1; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.key !== undefined) { + return { + key: _args.key + }; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read GetStruct__Args from input"); + } + } +}; +export class GetStruct__Args extends thrift.StructLike implements IGetStruct__Args { + public key: number; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IGetStruct__ArgsArgs) { + super(); + if (args.key != null) { + const value_2: number = args.key; + this.key = value_2; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[key] is unset!"); + } + } + public static read(input: thrift.TProtocol): GetStruct__Args { + return new GetStruct__Args(GetStruct__ArgsCodec.decode(input)); + } + public static write(args: IGetStruct__ArgsArgs, output: thrift.TProtocol): void { + return GetStruct__ArgsCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return GetStruct__ArgsCodec.encode(this, output); + } +} +export interface IGetUnion__Args { + index: number; +} +export interface IGetUnion__ArgsArgs { + index: number; +} +export const GetUnion__ArgsCodec: thrift.IStructCodec = { + encode(args: IGetUnion__ArgsArgs, output: thrift.TProtocol): void { + const obj = { + index: args.index + }; + output.writeStructBegin("GetUnion__Args"); + if (obj.index != null) { + output.writeFieldBegin("index", thrift.TType.I32, 1); + output.writeI32(obj.index); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[index] is unset!"); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IGetUnion__Args { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.I32) { + const value_3: number = input.readI32(); + _args.index = value_3; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.index !== undefined) { + return { + index: _args.index + }; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read GetUnion__Args from input"); + } + } +}; +export class GetUnion__Args extends thrift.StructLike implements IGetUnion__Args { + public index: number; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IGetUnion__ArgsArgs) { + super(); + if (args.index != null) { + const value_4: number = args.index; + this.index = value_4; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[index] is unset!"); + } + } + public static read(input: thrift.TProtocol): GetUnion__Args { + return new GetUnion__Args(GetUnion__ArgsCodec.decode(input)); + } + public static write(args: IGetUnion__ArgsArgs, output: thrift.TProtocol): void { + return GetUnion__ArgsCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return GetUnion__ArgsCodec.encode(this, output); + } +} +export interface IGetStruct__Result { + success?: __NAMESPACE__.ISharedStruct; +} +export interface IGetStruct__ResultArgs { + success?: __NAMESPACE__.ISharedStructArgs; +} +export const GetStruct__ResultCodec: thrift.IStructCodec = { + encode(args: IGetStruct__ResultArgs, output: thrift.TProtocol): void { + const obj = { + success: args.success + }; + output.writeStructBegin("GetStruct__Result"); + if (obj.success != null) { + output.writeFieldBegin("success", thrift.TType.STRUCT, 0); + __NAMESPACE__.SharedStructCodec.encode(obj.success, output); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IGetStruct__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.STRUCT) { + const value_5: __NAMESPACE__.ISharedStruct = __NAMESPACE__.SharedStructCodec.decode(input); + _args.success = value_5; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + success: _args.success + }; + } +}; +export class GetStruct__Result extends thrift.StructLike implements IGetStruct__Result { + public success?: __NAMESPACE__.ISharedStruct; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IGetStruct__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_6: __NAMESPACE__.ISharedStruct = new __NAMESPACE__.SharedStruct(args.success); + this.success = value_6; + } + } + public static read(input: thrift.TProtocol): GetStruct__Result { + return new GetStruct__Result(GetStruct__ResultCodec.decode(input)); + } + public static write(args: IGetStruct__ResultArgs, output: thrift.TProtocol): void { + return GetStruct__ResultCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return GetStruct__ResultCodec.encode(this, output); + } +} +export interface IGetUnion__Result { + success?: __NAMESPACE__.ISharedUnion; +} +export interface IGetUnion__ResultArgs { + success?: __NAMESPACE__.ISharedUnionArgs; +} +export const GetUnion__ResultCodec: thrift.IStructCodec = { + encode(args: IGetUnion__ResultArgs, output: thrift.TProtocol): void { + const obj = { + success: args.success + }; + output.writeStructBegin("GetUnion__Result"); + if (obj.success != null) { + output.writeFieldBegin("success", thrift.TType.STRUCT, 0); + __NAMESPACE__.SharedUnionCodec.encode(obj.success, output); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IGetUnion__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.STRUCT) { + const value_7: __NAMESPACE__.ISharedUnion = __NAMESPACE__.SharedUnionCodec.decode(input); + _args.success = value_7; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + success: _args.success + }; + } +}; +export class GetUnion__Result extends thrift.StructLike implements IGetUnion__Result { + public success?: __NAMESPACE__.ISharedUnion; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IGetUnion__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_8: __NAMESPACE__.ISharedUnion = new __NAMESPACE__.SharedUnion(args.success); + this.success = value_8; + } + } + public static read(input: thrift.TProtocol): GetUnion__Result { + return new GetUnion__Result(GetUnion__ResultCodec.decode(input)); + } + public static write(args: IGetUnion__ResultArgs, output: thrift.TProtocol): void { + return GetUnion__ResultCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return GetUnion__ResultCodec.encode(this, output); + } +} +export class Client extends thrift.ThriftClient { + public static readonly serviceName: string = serviceName; + public static readonly annotations: thrift.IThriftAnnotations = annotations; + public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public static readonly methodNames: Array = methodNames; + public readonly _serviceName: string = serviceName; + public readonly _annotations: thrift.IThriftAnnotations = annotations; + public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public readonly _methodNames: Array = methodNames; + public getStruct(key: number, context?: Context): Promise<__NAMESPACE__.ISharedStruct> { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("getStruct", thrift.MessageType.CALL, this.incrementRequestId()); + const args: IGetStruct__ArgsArgs = { key }; + GetStruct__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "getStruct") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); + } + else { + const result: IGetStruct__Result = GetStruct__ResultCodec.decode(input); + input.readMessageEnd(); + if (result.success != null) { + return Promise.resolve(result.success); + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "getStruct failed: unknown result")); + } + } + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); + } + } + catch (err) { + return Promise.reject(err); + } + }); + } + public getUnion(index: number, context?: Context): Promise<__NAMESPACE__.ISharedUnion> { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("getUnion", thrift.MessageType.CALL, this.incrementRequestId()); + const args: IGetUnion__ArgsArgs = { index }; + GetUnion__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "getUnion") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); + } + else { + const result: IGetUnion__Result = GetUnion__ResultCodec.decode(input); + input.readMessageEnd(); + if (result.success != null) { + return Promise.resolve(result.success); + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "getUnion failed: unknown result")); + } + } + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); + } + } + catch (err) { + return Promise.reject(err); + } + }); + } +} +export interface IHandler { + getStruct(key: number, context?: Context): __NAMESPACE__.ISharedStructArgs | Promise<__NAMESPACE__.ISharedStructArgs>; + getUnion(index: number, context?: Context): __NAMESPACE__.ISharedUnionArgs | Promise<__NAMESPACE__.ISharedUnionArgs>; +} +export class Processor extends thrift.ThriftProcessor> { + protected readonly _handler: IHandler; + public static readonly serviceName: string = serviceName; + public static readonly annotations: thrift.IThriftAnnotations = annotations; + public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public static readonly methodNames: Array = methodNames; + public readonly _serviceName: string = serviceName; + public readonly _annotations: thrift.IThriftAnnotations = annotations; + public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public readonly _methodNames: Array = methodNames; + constructor(handler: IHandler) { + super(); + this._handler = handler; + } + public process(input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + const metadata: thrift.IThriftMessage = input.readMessageBegin(); + const fieldName: string = metadata.fieldName; + const requestId: number = metadata.requestId; + const methodName: string = "process_" + fieldName; + switch (methodName) { + case "process_getStruct": { + resolve(this.process_getStruct(requestId, input, output, context)); + break; + } + case "process_getUnion": { + resolve(this.process_getUnion(requestId, input, output, context)); + break; + } + default: { + input.skip(thrift.TType.STRUCT); + input.readMessageEnd(); + const errMessage = "Unknown function " + fieldName; + const err = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN_METHOD, errMessage); + output.writeMessageBegin(fieldName, thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(err, output); + output.writeMessageEnd(); + resolve(output.flush()); + break; + } + } + }); + } + public process_getStruct(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise<__NAMESPACE__.ISharedStructArgs>((resolve, reject): void => { + try { + const args: IGetStruct__Args = GetStruct__ArgsCodec.decode(input); + input.readMessageEnd(); + resolve(this._handler.getStruct(args.key, context)); + } + catch (err) { + reject(err); + } + }).then((data: __NAMESPACE__.ISharedStructArgs): Buffer => { + const result: IGetStruct__ResultArgs = { success: data }; + output.writeMessageBegin("getStruct", thrift.MessageType.REPLY, requestId); + GetStruct__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("getStruct", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }); + } + public process_getUnion(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise<__NAMESPACE__.ISharedUnionArgs>((resolve, reject): void => { + try { + const args: IGetUnion__Args = GetUnion__ArgsCodec.decode(input); + input.readMessageEnd(); + resolve(this._handler.getUnion(args.index, context)); + } + catch (err) { + reject(err); + } + }).then((data: __NAMESPACE__.ISharedUnionArgs): Buffer => { + const result: IGetUnion__ResultArgs = { success: data }; + output.writeMessageBegin("getUnion", thrift.MessageType.REPLY, requestId); + GetUnion__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("getUnion", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }); + } +} diff --git a/src/tests/unit/fixtures/thrift-server/generated/com/test/shared/SharedStruct.ts b/src/tests/unit/fixtures/thrift-server/generated/com/test/shared/SharedStruct.ts new file mode 100644 index 00000000..181e9289 --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated/com/test/shared/SharedStruct.ts @@ -0,0 +1,121 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as thrift from "test-lib"; +import * as __NAMESPACE__ from "./."; +export interface ISharedStruct { + code: __NAMESPACE__.ICode; + value: string; +} +export interface ISharedStructArgs { + code: __NAMESPACE__.ICodeArgs; + value: string; +} +export const SharedStructCodec: thrift.IStructCodec = { + encode(args: ISharedStructArgs, output: thrift.TProtocol): void { + const obj = { + code: args.code, + value: args.value + }; + output.writeStructBegin("SharedStruct"); + if (obj.code != null) { + output.writeFieldBegin("code", thrift.TType.STRUCT, 1); + __NAMESPACE__.CodeCodec.encode(obj.code, output); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[code] is unset!"); + } + if (obj.value != null) { + output.writeFieldBegin("value", thrift.TType.STRING, 2); + output.writeString(obj.value); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[value] is unset!"); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): ISharedStruct { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.STRUCT) { + const value_1: __NAMESPACE__.ICode = __NAMESPACE__.CodeCodec.decode(input); + _args.code = value_1; + } + else { + input.skip(fieldType); + } + break; + case 2: + if (fieldType === thrift.TType.STRING) { + const value_2: string = input.readString(); + _args.value = value_2; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.code !== undefined && _args.value !== undefined) { + return { + code: _args.code, + value: _args.value + }; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read SharedStruct from input"); + } + } +}; +export class SharedStruct extends thrift.StructLike implements ISharedStruct { + public code: __NAMESPACE__.ICode; + public value: string; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: ISharedStructArgs) { + super(); + if (args.code != null) { + const value_3: __NAMESPACE__.ICode = new __NAMESPACE__.Code(args.code); + this.code = value_3; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[code] is unset!"); + } + if (args.value != null) { + const value_4: string = args.value; + this.value = value_4; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[value] is unset!"); + } + } + public static read(input: thrift.TProtocol): SharedStruct { + return new SharedStruct(SharedStructCodec.decode(input)); + } + public static write(args: ISharedStructArgs, output: thrift.TProtocol): void { + return SharedStructCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return SharedStructCodec.encode(this, output); + } +} diff --git a/src/tests/unit/fixtures/thrift-server/generated/com/test/shared/SharedUnion.ts b/src/tests/unit/fixtures/thrift-server/generated/com/test/shared/SharedUnion.ts new file mode 100644 index 00000000..78fa055f --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated/com/test/shared/SharedUnion.ts @@ -0,0 +1,132 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +import * as thrift from "test-lib"; +export interface ISharedUnion { + option1?: string; + option2?: string; +} +export interface ISharedUnionArgs { + option1?: string; + option2?: string; +} +export const SharedUnionCodec: thrift.IStructCodec = { + encode(args: ISharedUnionArgs, output: thrift.TProtocol): void { + let _fieldsSet: number = 0; + const obj = { + option1: args.option1, + option2: args.option2 + }; + output.writeStructBegin("SharedUnion"); + if (obj.option1 != null) { + _fieldsSet++; + output.writeFieldBegin("option1", thrift.TType.STRING, 1); + output.writeString(obj.option1); + output.writeFieldEnd(); + } + if (obj.option2 != null) { + _fieldsSet++; + output.writeFieldBegin("option2", thrift.TType.STRING, 2); + output.writeString(obj.option2); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + if (_fieldsSet > 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion cannot have more than one value"); + } + else if (_fieldsSet < 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion must have one value set"); + } + return; + }, + decode(input: thrift.TProtocol): ISharedUnion { + let _fieldsSet: number = 0; + let _returnValue: ISharedUnion | null = null; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.STRING) { + _fieldsSet++; + const value_1: string = input.readString(); + _returnValue = { option1: value_1 }; + } + else { + input.skip(fieldType); + } + break; + case 2: + if (fieldType === thrift.TType.STRING) { + _fieldsSet++; + const value_2: string = input.readString(); + _returnValue = { option2: value_2 }; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_fieldsSet > 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion cannot have more than one value"); + } + else if (_fieldsSet < 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion must have one value set"); + } + if (_returnValue !== null) { + return _returnValue; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read data for TUnion"); + } + } +}; +export class SharedUnion extends thrift.StructLike implements ISharedUnion { + public option1?: string; + public option2?: string; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: ISharedUnionArgs = {}) { + super(); + let _fieldsSet: number = 0; + if (args.option1 != null) { + _fieldsSet++; + const value_3: string = args.option1; + this.option1 = value_3; + } + if (args.option2 != null) { + _fieldsSet++; + const value_4: string = args.option2; + this.option2 = value_4; + } + if (_fieldsSet > 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion cannot have more than one value"); + } + else if (_fieldsSet < 1) { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion must have one value set"); + } + } + public static read(input: thrift.TProtocol): SharedUnion { + return new SharedUnion(SharedUnionCodec.decode(input)); + } + public static write(args: ISharedUnionArgs, output: thrift.TProtocol): void { + return SharedUnionCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return SharedUnionCodec.encode(this, output); + } +} diff --git a/src/tests/unit/fixtures/thrift-server/generated/com/test/shared/constants.ts b/src/tests/unit/fixtures/thrift-server/generated/com/test/shared/constants.ts new file mode 100644 index 00000000..9bdc1290 --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated/com/test/shared/constants.ts @@ -0,0 +1,6 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +export const SHARED_INT: number = 45; diff --git a/src/tests/unit/fixtures/thrift-server/generated/com/test/shared/index.ts b/src/tests/unit/fixtures/thrift-server/generated/com/test/shared/index.ts new file mode 100644 index 00000000..c6209b6a --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/generated/com/test/shared/index.ts @@ -0,0 +1,11 @@ +/* tslint:disable */ +/* + * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +*/ +export * from "./constants"; +export * from "./Code"; +export * from "./SharedStruct"; +export * from "./SharedUnion"; +import * as SharedService from "./SharedService"; +export { SharedService as SharedService }; diff --git a/src/tests/unit/fixtures/thrift-server/i64_service.solution.ts b/src/tests/unit/fixtures/thrift-server/i64_service.solution.ts index 0f1463e5..49475650 100644 --- a/src/tests/unit/fixtures/thrift-server/i64_service.solution.ts +++ b/src/tests/unit/fixtures/thrift-server/i64_service.solution.ts @@ -72,507 +72,505 @@ export class Code extends thrift.StructLike implements ICode { return CodeCodec.encode(this, output); } } -export namespace MyService { - export const serviceName: string = "MyService"; - export const annotations: thrift.IThriftAnnotations = {}; - export const methodAnnotations: thrift.IMethodAnnotations = { - peg: { - annotations: {}, - fieldAnnotations: {} - }, - pong: { - annotations: {}, - fieldAnnotations: {} +export const serviceName: string = "MyService"; +export const annotations: thrift.IThriftAnnotations = {}; +export const methodAnnotations: thrift.IMethodAnnotations = { + peg: { + annotations: {}, + fieldAnnotations: {} + }, + pong: { + annotations: {}, + fieldAnnotations: {} + } +}; +export const methodNames: Array = ["peg", "pong"]; +export interface IPeg__Args { + name: string; +} +export interface IPeg__ArgsArgs { + name: string; +} +export const Peg__ArgsCodec: thrift.IStructCodec = { + encode(args: IPeg__ArgsArgs, output: thrift.TProtocol): void { + const obj = { + name: args.name + }; + output.writeStructBegin("Peg__Args"); + if (obj.name != null) { + output.writeFieldBegin("name", thrift.TType.STRING, 1); + output.writeString(obj.name); + output.writeFieldEnd(); } - }; - export const methodNames: Array = ["peg", "pong"]; - export interface IPeg__Args { - name: string; - } - export interface IPeg__ArgsArgs { - name: string; - } - export const Peg__ArgsCodec: thrift.IStructCodec = { - encode(args: IPeg__ArgsArgs, output: thrift.TProtocol): void { - const obj = { - name: args.name - }; - output.writeStructBegin("Peg__Args"); - if (obj.name != null) { - output.writeFieldBegin("name", thrift.TType.STRING, 1); - output.writeString(obj.name); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[name] is unset!"); + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[name] is unset!"); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IPeg__Args { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IPeg__Args { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.STRING) { - const value_3: string = input.readString(); - _args.name = value_3; - } - else { - input.skip(fieldType); - } - break; - default: { + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.STRING) { + const value_3: string = input.readString(); + _args.name = value_3; + } + else { input.skip(fieldType); } + break; + default: { + input.skip(fieldType); } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.name !== undefined) { - return { - name: _args.name - }; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read Peg__Args from input"); } + input.readFieldEnd(); } - }; - export class Peg__Args extends thrift.StructLike implements IPeg__Args { - public name: string; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IPeg__ArgsArgs) { - super(); - if (args.name != null) { - const value_4: string = args.name; - this.name = value_4; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[name] is unset!"); - } + input.readStructEnd(); + if (_args.name !== undefined) { + return { + name: _args.name + }; } - public static read(input: thrift.TProtocol): Peg__Args { - return new Peg__Args(Peg__ArgsCodec.decode(input)); + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read Peg__Args from input"); } - public static write(args: IPeg__ArgsArgs, output: thrift.TProtocol): void { - return Peg__ArgsCodec.encode(args, output); + } +}; +export class Peg__Args extends thrift.StructLike implements IPeg__Args { + public name: string; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IPeg__ArgsArgs) { + super(); + if (args.name != null) { + const value_4: string = args.name; + this.name = value_4; } - public write(output: thrift.TProtocol): void { - return Peg__ArgsCodec.encode(this, output); + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[name] is unset!"); } } - export interface IPong__Args { - code?: ICode; + public static read(input: thrift.TProtocol): Peg__Args { + return new Peg__Args(Peg__ArgsCodec.decode(input)); } - export interface IPong__ArgsArgs { - code?: ICodeArgs; + public static write(args: IPeg__ArgsArgs, output: thrift.TProtocol): void { + return Peg__ArgsCodec.encode(args, output); } - export const Pong__ArgsCodec: thrift.IStructCodec = { - encode(args: IPong__ArgsArgs, output: thrift.TProtocol): void { - const obj = { - code: args.code - }; - output.writeStructBegin("Pong__Args"); - if (obj.code != null) { - output.writeFieldBegin("code", thrift.TType.STRUCT, 1); - CodeCodec.encode(obj.code, output); - output.writeFieldEnd(); + public write(output: thrift.TProtocol): void { + return Peg__ArgsCodec.encode(this, output); + } +} +export interface IPong__Args { + code?: ICode; +} +export interface IPong__ArgsArgs { + code?: ICodeArgs; +} +export const Pong__ArgsCodec: thrift.IStructCodec = { + encode(args: IPong__ArgsArgs, output: thrift.TProtocol): void { + const obj = { + code: args.code + }; + output.writeStructBegin("Pong__Args"); + if (obj.code != null) { + output.writeFieldBegin("code", thrift.TType.STRUCT, 1); + CodeCodec.encode(obj.code, output); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IPong__Args { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IPong__Args { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.STRUCT) { - const value_5: ICode = CodeCodec.decode(input); - _args.code = value_5; - } - else { - input.skip(fieldType); - } - break; - default: { + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.STRUCT) { + const value_5: ICode = CodeCodec.decode(input); + _args.code = value_5; + } + else { input.skip(fieldType); } + break; + default: { + input.skip(fieldType); } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - code: _args.code - }; - } - }; - export class Pong__Args extends thrift.StructLike implements IPong__Args { - public code?: ICode; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IPong__ArgsArgs = {}) { - super(); - if (args.code != null) { - const value_6: ICode = new Code(args.code); - this.code = value_6; } + input.readFieldEnd(); } - public static read(input: thrift.TProtocol): Pong__Args { - return new Pong__Args(Pong__ArgsCodec.decode(input)); - } - public static write(args: IPong__ArgsArgs, output: thrift.TProtocol): void { - return Pong__ArgsCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return Pong__ArgsCodec.encode(this, output); + input.readStructEnd(); + return { + code: _args.code + }; + } +}; +export class Pong__Args extends thrift.StructLike implements IPong__Args { + public code?: ICode; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IPong__ArgsArgs = {}) { + super(); + if (args.code != null) { + const value_6: ICode = new Code(args.code); + this.code = value_6; } } - export interface IPeg__Result { - success?: string; + public static read(input: thrift.TProtocol): Pong__Args { + return new Pong__Args(Pong__ArgsCodec.decode(input)); } - export interface IPeg__ResultArgs { - success?: string; + public static write(args: IPong__ArgsArgs, output: thrift.TProtocol): void { + return Pong__ArgsCodec.encode(args, output); } - export const Peg__ResultCodec: thrift.IStructCodec = { - encode(args: IPeg__ResultArgs, output: thrift.TProtocol): void { - const obj = { - success: args.success - }; - output.writeStructBegin("Peg__Result"); - if (obj.success != null) { - output.writeFieldBegin("success", thrift.TType.STRING, 0); - output.writeString(obj.success); - output.writeFieldEnd(); + public write(output: thrift.TProtocol): void { + return Pong__ArgsCodec.encode(this, output); + } +} +export interface IPeg__Result { + success?: string; +} +export interface IPeg__ResultArgs { + success?: string; +} +export const Peg__ResultCodec: thrift.IStructCodec = { + encode(args: IPeg__ResultArgs, output: thrift.TProtocol): void { + const obj = { + success: args.success + }; + output.writeStructBegin("Peg__Result"); + if (obj.success != null) { + output.writeFieldBegin("success", thrift.TType.STRING, 0); + output.writeString(obj.success); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IPeg__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IPeg__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.STRING) { - const value_7: string = input.readString(); - _args.success = value_7; - } - else { - input.skip(fieldType); - } - break; - default: { + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.STRING) { + const value_7: string = input.readString(); + _args.success = value_7; + } + else { input.skip(fieldType); } + break; + default: { + input.skip(fieldType); } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - success: _args.success - }; - } - }; - export class Peg__Result extends thrift.StructLike implements IPeg__Result { - public success?: string; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IPeg__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_8: string = args.success; - this.success = value_8; } + input.readFieldEnd(); } - public static read(input: thrift.TProtocol): Peg__Result { - return new Peg__Result(Peg__ResultCodec.decode(input)); - } - public static write(args: IPeg__ResultArgs, output: thrift.TProtocol): void { - return Peg__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return Peg__ResultCodec.encode(this, output); + input.readStructEnd(); + return { + success: _args.success + }; + } +}; +export class Peg__Result extends thrift.StructLike implements IPeg__Result { + public success?: string; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IPeg__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_8: string = args.success; + this.success = value_8; } } - export interface IPong__Result { - success?: thrift.Int64; + public static read(input: thrift.TProtocol): Peg__Result { + return new Peg__Result(Peg__ResultCodec.decode(input)); } - export interface IPong__ResultArgs { - success?: number | string | thrift.Int64; + public static write(args: IPeg__ResultArgs, output: thrift.TProtocol): void { + return Peg__ResultCodec.encode(args, output); } - export const Pong__ResultCodec: thrift.IStructCodec = { - encode(args: IPong__ResultArgs, output: thrift.TProtocol): void { - const obj = { - success: (typeof args.success === "number" ? new thrift.Int64(args.success) : typeof args.success === "string" ? thrift.Int64.fromDecimalString(args.success) : args.success) - }; - output.writeStructBegin("Pong__Result"); - if (obj.success != null) { - output.writeFieldBegin("success", thrift.TType.I64, 0); - output.writeI64((typeof obj.success === "number" ? new thrift.Int64(obj.success) : typeof obj.success === "string" ? thrift.Int64.fromDecimalString(obj.success) : obj.success)); - output.writeFieldEnd(); + public write(output: thrift.TProtocol): void { + return Peg__ResultCodec.encode(this, output); + } +} +export interface IPong__Result { + success?: thrift.Int64; +} +export interface IPong__ResultArgs { + success?: number | string | thrift.Int64; +} +export const Pong__ResultCodec: thrift.IStructCodec = { + encode(args: IPong__ResultArgs, output: thrift.TProtocol): void { + const obj = { + success: (typeof args.success === "number" ? new thrift.Int64(args.success) : typeof args.success === "string" ? thrift.Int64.fromDecimalString(args.success) : args.success) + }; + output.writeStructBegin("Pong__Result"); + if (obj.success != null) { + output.writeFieldBegin("success", thrift.TType.I64, 0); + output.writeI64((typeof obj.success === "number" ? new thrift.Int64(obj.success) : typeof obj.success === "string" ? thrift.Int64.fromDecimalString(obj.success) : obj.success)); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IPong__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IPong__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.I64) { - const value_9: thrift.Int64 = input.readI64(); - _args.success = value_9; - } - else { - input.skip(fieldType); - } - break; - default: { + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.I64) { + const value_9: thrift.Int64 = input.readI64(); + _args.success = value_9; + } + else { input.skip(fieldType); } + break; + default: { + input.skip(fieldType); } - input.readFieldEnd(); } - input.readStructEnd(); - return { - success: _args.success - }; - } - }; - export class Pong__Result extends thrift.StructLike implements IPong__Result { - public success?: thrift.Int64; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IPong__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_10: thrift.Int64 = (typeof args.success === "number" ? new thrift.Int64(args.success) : typeof args.success === "string" ? thrift.Int64.fromDecimalString(args.success) : args.success); - this.success = value_10; - } - } - public static read(input: thrift.TProtocol): Pong__Result { - return new Pong__Result(Pong__ResultCodec.decode(input)); - } - public static write(args: IPong__ResultArgs, output: thrift.TProtocol): void { - return Pong__ResultCodec.encode(args, output); + input.readFieldEnd(); } - public write(output: thrift.TProtocol): void { - return Pong__ResultCodec.encode(this, output); + input.readStructEnd(); + return { + success: _args.success + }; + } +}; +export class Pong__Result extends thrift.StructLike implements IPong__Result { + public success?: thrift.Int64; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IPong__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_10: thrift.Int64 = (typeof args.success === "number" ? new thrift.Int64(args.success) : typeof args.success === "string" ? thrift.Int64.fromDecimalString(args.success) : args.success); + this.success = value_10; } } - export class Client extends thrift.ThriftClient { - public static readonly serviceName: string = serviceName; - public static readonly annotations: thrift.IThriftAnnotations = annotations; - public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public static readonly methodNames: Array = methodNames; - public readonly _serviceName: string = serviceName; - public readonly _annotations: thrift.IThriftAnnotations = annotations; - public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public readonly _methodNames: Array = methodNames; - public peg(name: string, context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("peg", thrift.MessageType.CALL, this.incrementRequestId()); - const args: IPeg__ArgsArgs = { name }; - Peg__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "peg") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: IPeg__Result = Peg__ResultCodec.decode(input); - input.readMessageEnd(); - if (result.success != null) { - return Promise.resolve(result.success); - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "peg failed: unknown result")); - } - } + public static read(input: thrift.TProtocol): Pong__Result { + return new Pong__Result(Pong__ResultCodec.decode(input)); + } + public static write(args: IPong__ResultArgs, output: thrift.TProtocol): void { + return Pong__ResultCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return Pong__ResultCodec.encode(this, output); + } +} +export class Client extends thrift.ThriftClient { + public static readonly serviceName: string = serviceName; + public static readonly annotations: thrift.IThriftAnnotations = annotations; + public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public static readonly methodNames: Array = methodNames; + public readonly _serviceName: string = serviceName; + public readonly _annotations: thrift.IThriftAnnotations = annotations; + public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public readonly _methodNames: Array = methodNames; + public peg(name: string, context?: Context): Promise { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("peg", thrift.MessageType.CALL, this.incrementRequestId()); + const args: IPeg__ArgsArgs = { name }; + Peg__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "peg") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); } else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } - } - catch (err) { - return Promise.reject(err); - } - }); - } - public pong(code?: ICodeArgs, context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("pong", thrift.MessageType.CALL, this.incrementRequestId()); - const args: IPong__ArgsArgs = { code }; - Pong__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "pong") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); + const result: IPeg__Result = Peg__ResultCodec.decode(input); + input.readMessageEnd(); + if (result.success != null) { + return Promise.resolve(result.success); } else { - const result: IPong__Result = Pong__ResultCodec.decode(input); - input.readMessageEnd(); - if (result.success != null) { - return Promise.resolve(result.success); - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "pong failed: unknown result")); - } + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "peg failed: unknown result")); } } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } } - catch (err) { - return Promise.reject(err); + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); } - }); - } + } + catch (err) { + return Promise.reject(err); + } + }); } - export interface IHandler { - peg(name: string, context?: Context): string | Promise; - pong(code?: ICode, context?: Context): (number | string | thrift.Int64) | Promise; - } - export class Processor extends thrift.ThriftProcessor> { - protected readonly _handler: IHandler; - public static readonly serviceName: string = serviceName; - public static readonly annotations: thrift.IThriftAnnotations = annotations; - public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public static readonly methodNames: Array = methodNames; - public readonly _serviceName: string = serviceName; - public readonly _annotations: thrift.IThriftAnnotations = annotations; - public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public readonly _methodNames: Array = methodNames; - constructor(handler: IHandler) { - super(); - this._handler = handler; - } - public process(input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - const metadata: thrift.IThriftMessage = input.readMessageBegin(); - const fieldName: string = metadata.fieldName; - const requestId: number = metadata.requestId; - const methodName: string = "process_" + fieldName; - switch (methodName) { - case "process_peg": { - resolve(this.process_peg(requestId, input, output, context)); - break; - } - case "process_pong": { - resolve(this.process_pong(requestId, input, output, context)); - break; + public pong(code?: ICodeArgs, context?: Context): Promise { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("pong", thrift.MessageType.CALL, this.incrementRequestId()); + const args: IPong__ArgsArgs = { code }; + Pong__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "pong") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); } - default: { - input.skip(thrift.TType.STRUCT); + else { + const result: IPong__Result = Pong__ResultCodec.decode(input); input.readMessageEnd(); - const errMessage = "Unknown function " + fieldName; - const err = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN_METHOD, errMessage); - output.writeMessageBegin(fieldName, thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(err, output); - output.writeMessageEnd(); - resolve(output.flush()); - break; + if (result.success != null) { + return Promise.resolve(result.success); + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "pong failed: unknown result")); + } } } - }); - } - public process_peg(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { - const args: IPeg__Args = Peg__ArgsCodec.decode(input); - input.readMessageEnd(); - resolve(this._handler.peg(args.name, context)); + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); } - catch (err) { - reject(err); + } + catch (err) { + return Promise.reject(err); + } + }); + } +} +export interface IHandler { + peg(name: string, context?: Context): string | Promise; + pong(code?: ICode, context?: Context): (number | string | thrift.Int64) | Promise; +} +export class Processor extends thrift.ThriftProcessor> { + protected readonly _handler: IHandler; + public static readonly serviceName: string = serviceName; + public static readonly annotations: thrift.IThriftAnnotations = annotations; + public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public static readonly methodNames: Array = methodNames; + public readonly _serviceName: string = serviceName; + public readonly _annotations: thrift.IThriftAnnotations = annotations; + public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public readonly _methodNames: Array = methodNames; + constructor(handler: IHandler) { + super(); + this._handler = handler; + } + public process(input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + const metadata: thrift.IThriftMessage = input.readMessageBegin(); + const fieldName: string = metadata.fieldName; + const requestId: number = metadata.requestId; + const methodName: string = "process_" + fieldName; + switch (methodName) { + case "process_peg": { + resolve(this.process_peg(requestId, input, output, context)); + break; } - }).then((data: string): Buffer => { - const result: IPeg__ResultArgs = { success: data }; - output.writeMessageBegin("peg", thrift.MessageType.REPLY, requestId); - Peg__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("peg", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } - public process_pong(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { - const args: IPong__Args = Pong__ArgsCodec.decode(input); - input.readMessageEnd(); - resolve(this._handler.pong(args.code, context)); + case "process_pong": { + resolve(this.process_pong(requestId, input, output, context)); + break; } - catch (err) { - reject(err); + default: { + input.skip(thrift.TType.STRUCT); + input.readMessageEnd(); + const errMessage = "Unknown function " + fieldName; + const err = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN_METHOD, errMessage); + output.writeMessageBegin(fieldName, thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(err, output); + output.writeMessageEnd(); + resolve(output.flush()); + break; } - }).then((data: number | string | thrift.Int64): Buffer => { - const result: IPong__ResultArgs = { success: data }; - output.writeMessageBegin("pong", thrift.MessageType.REPLY, requestId); - Pong__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("pong", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }); - } + } + }); + } + public process_peg(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + try { + const args: IPeg__Args = Peg__ArgsCodec.decode(input); + input.readMessageEnd(); + resolve(this._handler.peg(args.name, context)); + } + catch (err) { + reject(err); + } + }).then((data: string): Buffer => { + const result: IPeg__ResultArgs = { success: data }; + output.writeMessageBegin("peg", thrift.MessageType.REPLY, requestId); + Peg__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("peg", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }); + } + public process_pong(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + try { + const args: IPong__Args = Pong__ArgsCodec.decode(input); + input.readMessageEnd(); + resolve(this._handler.pong(args.code, context)); + } + catch (err) { + reject(err); + } + }).then((data: number | string | thrift.Int64): Buffer => { + const result: IPong__ResultArgs = { success: data }; + output.writeMessageBegin("pong", thrift.MessageType.REPLY, requestId); + Pong__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("pong", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }); } } diff --git a/src/tests/unit/fixtures/thrift-server/nested_union.strict_union.solution.ts b/src/tests/unit/fixtures/thrift-server/nested_union.strict_union.solution.ts index 7c9aa525..65a7dc8a 100644 --- a/src/tests/unit/fixtures/thrift-server/nested_union.strict_union.solution.ts +++ b/src/tests/unit/fixtures/thrift-server/nested_union.strict_union.solution.ts @@ -6,20 +6,20 @@ export type InnerUnion = IInnerUnionWithName | IInnerUnionWithId; export interface IInnerUnionWithName { __type: InnerUnionType.InnerUnionWithName; name: string; - id?: void; + id?: undefined; } export interface IInnerUnionWithId { __type: InnerUnionType.InnerUnionWithId; - name?: void; + name?: undefined; id: number; } export type InnerUnionArgs = IInnerUnionWithNameArgs | IInnerUnionWithIdArgs; export interface IInnerUnionWithNameArgs { name: string; - id?: void; + id?: undefined; } export interface IInnerUnionWithIdArgs { - name?: void; + name?: undefined; id: number; } export const InnerUnionCodec: thrift.IStructToolkit = { @@ -161,20 +161,20 @@ export type MyUnion = IMyUnionWithUser | IMyUnionWithField2; export interface IMyUnionWithUser { __type: MyUnionType.MyUnionWithUser; user: InnerUnion; - field2?: void; + field2?: undefined; } export interface IMyUnionWithField2 { __type: MyUnionType.MyUnionWithField2; - user?: void; + user?: undefined; field2: string; } export type MyUnionArgs = IMyUnionWithUserArgs | IMyUnionWithField2Args; export interface IMyUnionWithUserArgs { user: InnerUnionArgs; - field2?: void; + field2?: undefined; } export interface IMyUnionWithField2Args { - user?: void; + user?: undefined; field2: string; } export const MyUnionCodec: thrift.IStructToolkit = { diff --git a/src/tests/unit/fixtures/thrift-server/resolved_field_service.solution.ts b/src/tests/unit/fixtures/thrift-server/resolved_field_service.solution.ts new file mode 100644 index 00000000..0cb1bbb4 --- /dev/null +++ b/src/tests/unit/fixtures/thrift-server/resolved_field_service.solution.ts @@ -0,0 +1,270 @@ +export type INT_64 = thrift.Int64; +export const serviceName: string = "MyService"; +export const annotations: thrift.IThriftAnnotations = {}; +export const methodAnnotations: thrift.IMethodAnnotations = { + ping: { + annotations: {}, + fieldAnnotations: {} + } +}; +export const methodNames: Array = ["ping"]; +export interface IPing__Args { + id: thrift.Int64; +} +export interface IPing__ArgsArgs { + id: number | string | thrift.Int64; +} +export const Ping__ArgsCodec: thrift.IStructCodec = { + encode(args: IPing__ArgsArgs, output: thrift.TProtocol): void { + const obj = { + id: (typeof args.id === "number" ? new thrift.Int64(args.id) : typeof args.id === "string" ? thrift.Int64.fromDecimalString(args.id) : args.id) + }; + output.writeStructBegin("Ping__Args"); + if (obj.id != null) { + output.writeFieldBegin("id", thrift.TType.I64, 1); + output.writeI64((typeof obj.id === "number" ? new thrift.Int64(obj.id) : typeof obj.id === "string" ? thrift.Int64.fromDecimalString(obj.id) : obj.id)); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[id] is unset!"); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IPing__Args { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.I64) { + const value_1: thrift.Int64 = input.readI64(); + _args.id = value_1; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + if (_args.id !== undefined) { + return { + id: _args.id + }; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read Ping__Args from input"); + } + } +}; +export class Ping__Args extends thrift.StructLike implements IPing__Args { + public id: thrift.Int64; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IPing__ArgsArgs) { + super(); + if (args.id != null) { + const value_2: thrift.Int64 = (typeof args.id === "number" ? new thrift.Int64(args.id) : typeof args.id === "string" ? thrift.Int64.fromDecimalString(args.id) : args.id); + this.id = value_2; + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[id] is unset!"); + } + } + public static read(input: thrift.TProtocol): Ping__Args { + return new Ping__Args(Ping__ArgsCodec.decode(input)); + } + public static write(args: IPing__ArgsArgs, output: thrift.TProtocol): void { + return Ping__ArgsCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return Ping__ArgsCodec.encode(this, output); + } +} +export interface IPing__Result { + success?: void; +} +export interface IPing__ResultArgs { + success?: void; +} +export const Ping__ResultCodec: thrift.IStructCodec = { + encode(args: IPing__ResultArgs, output: thrift.TProtocol): void { + output.writeStructBegin("Ping__Result"); + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IPing__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; + } + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.VOID) { + input.skip(fieldType); + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); + } + } + input.readFieldEnd(); + } + input.readStructEnd(); + return { + success: _args.success + }; + } +}; +export class Ping__Result extends thrift.StructLike implements IPing__Result { + public success?: void; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IPing__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_3: void = undefined; + this.success = value_3; + } + } + public static read(input: thrift.TProtocol): Ping__Result { + return new Ping__Result(Ping__ResultCodec.decode(input)); + } + public static write(args: IPing__ResultArgs, output: thrift.TProtocol): void { + return Ping__ResultCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return Ping__ResultCodec.encode(this, output); + } +} +export class Client extends thrift.ThriftClient { + public static readonly serviceName: string = serviceName; + public static readonly annotations: thrift.IThriftAnnotations = annotations; + public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public static readonly methodNames: Array = methodNames; + public readonly _serviceName: string = serviceName; + public readonly _annotations: thrift.IThriftAnnotations = annotations; + public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public readonly _methodNames: Array = methodNames; + public ping(id: number | string | thrift.Int64, context?: Context): Promise { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("ping", thrift.MessageType.CALL, this.incrementRequestId()); + const args: IPing__ArgsArgs = { id }; + Ping__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "ping") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); + } + else { + const result: IPing__Result = Ping__ResultCodec.decode(input); + input.readMessageEnd(); + return Promise.resolve(result.success); + } + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); + } + } + catch (err) { + return Promise.reject(err); + } + }); + } +} +export interface IHandler { + ping(id: thrift.Int64, context?: Context): void | Promise; +} +export class Processor extends thrift.ThriftProcessor> { + protected readonly _handler: IHandler; + public static readonly serviceName: string = serviceName; + public static readonly annotations: thrift.IThriftAnnotations = annotations; + public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public static readonly methodNames: Array = methodNames; + public readonly _serviceName: string = serviceName; + public readonly _annotations: thrift.IThriftAnnotations = annotations; + public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public readonly _methodNames: Array = methodNames; + constructor(handler: IHandler) { + super(); + this._handler = handler; + } + public process(input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + const metadata: thrift.IThriftMessage = input.readMessageBegin(); + const fieldName: string = metadata.fieldName; + const requestId: number = metadata.requestId; + const methodName: string = "process_" + fieldName; + switch (methodName) { + case "process_ping": { + resolve(this.process_ping(requestId, input, output, context)); + break; + } + default: { + input.skip(thrift.TType.STRUCT); + input.readMessageEnd(); + const errMessage = "Unknown function " + fieldName; + const err = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN_METHOD, errMessage); + output.writeMessageBegin(fieldName, thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(err, output); + output.writeMessageEnd(); + resolve(output.flush()); + break; + } + } + }); + } + public process_ping(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + try { + const args: IPing__Args = Ping__ArgsCodec.decode(input); + input.readMessageEnd(); + resolve(this._handler.ping(args.id, context)); + } + catch (err) { + reject(err); + } + }).then((data: void): Buffer => { + const result: IPing__ResultArgs = { success: data }; + output.writeMessageBegin("ping", thrift.MessageType.REPLY, requestId); + Ping__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("ping", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }); + } +} diff --git a/src/tests/unit/fixtures/thrift-server/throws_multi_service.solution.ts b/src/tests/unit/fixtures/thrift-server/throws_multi_service.solution.ts index cf21a52e..fc463ca2 100644 --- a/src/tests/unit/fixtures/thrift-server/throws_multi_service.solution.ts +++ b/src/tests/unit/fixtures/thrift-server/throws_multi_service.solution.ts @@ -243,389 +243,387 @@ export class UnknownException extends thrift.StructLike implements IUnknownExcep return UnknownExceptionCodec.encode(this, output); } } -export namespace MyService { - export const serviceName: string = "MyService"; - export const annotations: thrift.IThriftAnnotations = {}; - export const methodAnnotations: thrift.IMethodAnnotations = { - peg: { - annotations: {}, - fieldAnnotations: {} - } - }; - export const methodNames: Array = ["peg"]; - export interface IPeg__Args { - name: string; - } - export interface IPeg__ArgsArgs { - name: string; +export const serviceName: string = "MyService"; +export const annotations: thrift.IThriftAnnotations = {}; +export const methodAnnotations: thrift.IMethodAnnotations = { + peg: { + annotations: {}, + fieldAnnotations: {} } - export const Peg__ArgsCodec: thrift.IStructCodec = { - encode(args: IPeg__ArgsArgs, output: thrift.TProtocol): void { - const obj = { - name: args.name - }; - output.writeStructBegin("Peg__Args"); - if (obj.name != null) { - output.writeFieldBegin("name", thrift.TType.STRING, 1); - output.writeString(obj.name); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[name] is unset!"); +}; +export const methodNames: Array = ["peg"]; +export interface IPeg__Args { + name: string; +} +export interface IPeg__ArgsArgs { + name: string; +} +export const Peg__ArgsCodec: thrift.IStructCodec = { + encode(args: IPeg__ArgsArgs, output: thrift.TProtocol): void { + const obj = { + name: args.name + }; + output.writeStructBegin("Peg__Args"); + if (obj.name != null) { + output.writeFieldBegin("name", thrift.TType.STRING, 1); + output.writeString(obj.name); + output.writeFieldEnd(); + } + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[name] is unset!"); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IPeg__Args { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IPeg__Args { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.STRING) { - const value_9: string = input.readString(); - _args.name = value_9; - } - else { - input.skip(fieldType); - } - break; - default: { + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.STRING) { + const value_9: string = input.readString(); + _args.name = value_9; + } + else { input.skip(fieldType); } + break; + default: { + input.skip(fieldType); } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.name !== undefined) { - return { - name: _args.name - }; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read Peg__Args from input"); } + input.readFieldEnd(); } - }; - export class Peg__Args extends thrift.StructLike implements IPeg__Args { - public name: string; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IPeg__ArgsArgs) { - super(); - if (args.name != null) { - const value_10: string = args.name; - this.name = value_10; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[name] is unset!"); - } + input.readStructEnd(); + if (_args.name !== undefined) { + return { + name: _args.name + }; } - public static read(input: thrift.TProtocol): Peg__Args { - return new Peg__Args(Peg__ArgsCodec.decode(input)); + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read Peg__Args from input"); } - public static write(args: IPeg__ArgsArgs, output: thrift.TProtocol): void { - return Peg__ArgsCodec.encode(args, output); + } +}; +export class Peg__Args extends thrift.StructLike implements IPeg__Args { + public name: string; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IPeg__ArgsArgs) { + super(); + if (args.name != null) { + const value_10: string = args.name; + this.name = value_10; } - public write(output: thrift.TProtocol): void { - return Peg__ArgsCodec.encode(this, output); + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[name] is unset!"); } } - export interface IPeg__Result { - success?: string; - exp?: IServiceException; - authExp?: IAuthException; - unknownExp?: IUnknownException; + public static read(input: thrift.TProtocol): Peg__Args { + return new Peg__Args(Peg__ArgsCodec.decode(input)); } - export interface IPeg__ResultArgs { - success?: string; - exp?: IServiceExceptionArgs; - authExp?: IAuthExceptionArgs; - unknownExp?: IUnknownExceptionArgs; + public static write(args: IPeg__ArgsArgs, output: thrift.TProtocol): void { + return Peg__ArgsCodec.encode(args, output); } - export const Peg__ResultCodec: thrift.IStructCodec = { - encode(args: IPeg__ResultArgs, output: thrift.TProtocol): void { - const obj = { - success: args.success, - exp: args.exp, - authExp: args.authExp, - unknownExp: args.unknownExp - }; - output.writeStructBegin("Peg__Result"); - if (obj.success != null) { - output.writeFieldBegin("success", thrift.TType.STRING, 0); - output.writeString(obj.success); - output.writeFieldEnd(); - } - if (obj.exp != null) { - output.writeFieldBegin("exp", thrift.TType.STRUCT, 1); - ServiceExceptionCodec.encode(obj.exp, output); - output.writeFieldEnd(); - } - if (obj.authExp != null) { - output.writeFieldBegin("authExp", thrift.TType.STRUCT, 2); - AuthExceptionCodec.encode(obj.authExp, output); - output.writeFieldEnd(); - } - if (obj.unknownExp != null) { - output.writeFieldBegin("unknownExp", thrift.TType.STRUCT, 3); - UnknownExceptionCodec.encode(obj.unknownExp, output); - output.writeFieldEnd(); + public write(output: thrift.TProtocol): void { + return Peg__ArgsCodec.encode(this, output); + } +} +export interface IPeg__Result { + success?: string; + exp?: IServiceException; + authExp?: IAuthException; + unknownExp?: IUnknownException; +} +export interface IPeg__ResultArgs { + success?: string; + exp?: IServiceExceptionArgs; + authExp?: IAuthExceptionArgs; + unknownExp?: IUnknownExceptionArgs; +} +export const Peg__ResultCodec: thrift.IStructCodec = { + encode(args: IPeg__ResultArgs, output: thrift.TProtocol): void { + const obj = { + success: args.success, + exp: args.exp, + authExp: args.authExp, + unknownExp: args.unknownExp + }; + output.writeStructBegin("Peg__Result"); + if (obj.success != null) { + output.writeFieldBegin("success", thrift.TType.STRING, 0); + output.writeString(obj.success); + output.writeFieldEnd(); + } + if (obj.exp != null) { + output.writeFieldBegin("exp", thrift.TType.STRUCT, 1); + ServiceExceptionCodec.encode(obj.exp, output); + output.writeFieldEnd(); + } + if (obj.authExp != null) { + output.writeFieldBegin("authExp", thrift.TType.STRUCT, 2); + AuthExceptionCodec.encode(obj.authExp, output); + output.writeFieldEnd(); + } + if (obj.unknownExp != null) { + output.writeFieldBegin("unknownExp", thrift.TType.STRUCT, 3); + UnknownExceptionCodec.encode(obj.unknownExp, output); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IPeg__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IPeg__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.STRING) { + const value_11: string = input.readString(); + _args.success = value_11; + } + else { + input.skip(fieldType); + } break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.STRING) { - const value_11: string = input.readString(); - _args.success = value_11; - } - else { - input.skip(fieldType); - } - break; - case 1: - if (fieldType === thrift.TType.STRUCT) { - const value_12: IServiceException = ServiceExceptionCodec.decode(input); - _args.exp = value_12; - } - else { - input.skip(fieldType); - } - break; - case 2: - if (fieldType === thrift.TType.STRUCT) { - const value_13: IAuthException = AuthExceptionCodec.decode(input); - _args.authExp = value_13; - } - else { - input.skip(fieldType); - } - break; - case 3: - if (fieldType === thrift.TType.STRUCT) { - const value_14: IUnknownException = UnknownExceptionCodec.decode(input); - _args.unknownExp = value_14; - } - else { - input.skip(fieldType); - } - break; - default: { + case 1: + if (fieldType === thrift.TType.STRUCT) { + const value_12: IServiceException = ServiceExceptionCodec.decode(input); + _args.exp = value_12; + } + else { + input.skip(fieldType); + } + break; + case 2: + if (fieldType === thrift.TType.STRUCT) { + const value_13: IAuthException = AuthExceptionCodec.decode(input); + _args.authExp = value_13; + } + else { input.skip(fieldType); } + break; + case 3: + if (fieldType === thrift.TType.STRUCT) { + const value_14: IUnknownException = UnknownExceptionCodec.decode(input); + _args.unknownExp = value_14; + } + else { + input.skip(fieldType); + } + break; + default: { + input.skip(fieldType); } - input.readFieldEnd(); } - input.readStructEnd(); - return { - success: _args.success, - exp: _args.exp, - authExp: _args.authExp, - unknownExp: _args.unknownExp - }; + input.readFieldEnd(); } - }; - export class Peg__Result extends thrift.StructLike implements IPeg__Result { - public success?: string; - public exp?: IServiceException; - public authExp?: IAuthException; - public unknownExp?: IUnknownException; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IPeg__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_15: string = args.success; - this.success = value_15; - } - if (args.exp != null) { - const value_16: IServiceException = new ServiceException(args.exp); - this.exp = value_16; - } - if (args.authExp != null) { - const value_17: IAuthException = new AuthException(args.authExp); - this.authExp = value_17; - } - if (args.unknownExp != null) { - const value_18: IUnknownException = new UnknownException(args.unknownExp); - this.unknownExp = value_18; - } + input.readStructEnd(); + return { + success: _args.success, + exp: _args.exp, + authExp: _args.authExp, + unknownExp: _args.unknownExp + }; + } +}; +export class Peg__Result extends thrift.StructLike implements IPeg__Result { + public success?: string; + public exp?: IServiceException; + public authExp?: IAuthException; + public unknownExp?: IUnknownException; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IPeg__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_15: string = args.success; + this.success = value_15; } - public static read(input: thrift.TProtocol): Peg__Result { - return new Peg__Result(Peg__ResultCodec.decode(input)); + if (args.exp != null) { + const value_16: IServiceException = new ServiceException(args.exp); + this.exp = value_16; } - public static write(args: IPeg__ResultArgs, output: thrift.TProtocol): void { - return Peg__ResultCodec.encode(args, output); + if (args.authExp != null) { + const value_17: IAuthException = new AuthException(args.authExp); + this.authExp = value_17; } - public write(output: thrift.TProtocol): void { - return Peg__ResultCodec.encode(this, output); + if (args.unknownExp != null) { + const value_18: IUnknownException = new UnknownException(args.unknownExp); + this.unknownExp = value_18; } } - export class Client extends thrift.ThriftClient { - public static readonly serviceName: string = serviceName; - public static readonly annotations: thrift.IThriftAnnotations = annotations; - public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public static readonly methodNames: Array = methodNames; - public readonly _serviceName: string = serviceName; - public readonly _annotations: thrift.IThriftAnnotations = annotations; - public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public readonly _methodNames: Array = methodNames; - public peg(name: string, context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("peg", thrift.MessageType.CALL, this.incrementRequestId()); - const args: IPeg__ArgsArgs = { name }; - Peg__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "peg") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); + public static read(input: thrift.TProtocol): Peg__Result { + return new Peg__Result(Peg__ResultCodec.decode(input)); + } + public static write(args: IPeg__ResultArgs, output: thrift.TProtocol): void { + return Peg__ResultCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return Peg__ResultCodec.encode(this, output); + } +} +export class Client extends thrift.ThriftClient { + public static readonly serviceName: string = serviceName; + public static readonly annotations: thrift.IThriftAnnotations = annotations; + public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public static readonly methodNames: Array = methodNames; + public readonly _serviceName: string = serviceName; + public readonly _annotations: thrift.IThriftAnnotations = annotations; + public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public readonly _methodNames: Array = methodNames; + public peg(name: string, context?: Context): Promise { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("peg", thrift.MessageType.CALL, this.incrementRequestId()); + const args: IPeg__ArgsArgs = { name }; + Peg__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "peg") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); + } + else { + const result: IPeg__Result = Peg__ResultCodec.decode(input); + input.readMessageEnd(); + if (result.exp != null) { + return Promise.reject(result.exp); + } + else if (result.authExp != null) { + return Promise.reject(result.authExp); + } + else if (result.unknownExp != null) { + return Promise.reject(result.unknownExp); + } + else if (result.success != null) { + return Promise.resolve(result.success); } else { - const result: IPeg__Result = Peg__ResultCodec.decode(input); - input.readMessageEnd(); - if (result.exp != null) { - return Promise.reject(result.exp); - } - else if (result.authExp != null) { - return Promise.reject(result.authExp); - } - else if (result.unknownExp != null) { - return Promise.reject(result.unknownExp); - } - else if (result.success != null) { - return Promise.resolve(result.success); - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "peg failed: unknown result")); - } + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "peg failed: unknown result")); } } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } } - catch (err) { - return Promise.reject(err); + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); } - }); - } + } + catch (err) { + return Promise.reject(err); + } + }); } - export interface IHandler { - peg(name: string, context?: Context): string | Promise; +} +export interface IHandler { + peg(name: string, context?: Context): string | Promise; +} +export class Processor extends thrift.ThriftProcessor> { + protected readonly _handler: IHandler; + public static readonly serviceName: string = serviceName; + public static readonly annotations: thrift.IThriftAnnotations = annotations; + public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public static readonly methodNames: Array = methodNames; + public readonly _serviceName: string = serviceName; + public readonly _annotations: thrift.IThriftAnnotations = annotations; + public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public readonly _methodNames: Array = methodNames; + constructor(handler: IHandler) { + super(); + this._handler = handler; } - export class Processor extends thrift.ThriftProcessor> { - protected readonly _handler: IHandler; - public static readonly serviceName: string = serviceName; - public static readonly annotations: thrift.IThriftAnnotations = annotations; - public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public static readonly methodNames: Array = methodNames; - public readonly _serviceName: string = serviceName; - public readonly _annotations: thrift.IThriftAnnotations = annotations; - public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public readonly _methodNames: Array = methodNames; - constructor(handler: IHandler) { - super(); - this._handler = handler; - } - public process(input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - const metadata: thrift.IThriftMessage = input.readMessageBegin(); - const fieldName: string = metadata.fieldName; - const requestId: number = metadata.requestId; - const methodName: string = "process_" + fieldName; - switch (methodName) { - case "process_peg": { - resolve(this.process_peg(requestId, input, output, context)); - break; - } - default: { - input.skip(thrift.TType.STRUCT); - input.readMessageEnd(); - const errMessage = "Unknown function " + fieldName; - const err = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN_METHOD, errMessage); - output.writeMessageBegin(fieldName, thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(err, output); - output.writeMessageEnd(); - resolve(output.flush()); - break; - } + public process(input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + const metadata: thrift.IThriftMessage = input.readMessageBegin(); + const fieldName: string = metadata.fieldName; + const requestId: number = metadata.requestId; + const methodName: string = "process_" + fieldName; + switch (methodName) { + case "process_peg": { + resolve(this.process_peg(requestId, input, output, context)); + break; } - }); - } - public process_peg(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { - const args: IPeg__Args = Peg__ArgsCodec.decode(input); + default: { + input.skip(thrift.TType.STRUCT); input.readMessageEnd(); - resolve(this._handler.peg(args.name, context)); - } - catch (err) { - reject(err); + const errMessage = "Unknown function " + fieldName; + const err = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN_METHOD, errMessage); + output.writeMessageBegin(fieldName, thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(err, output); + output.writeMessageEnd(); + resolve(output.flush()); + break; } - }).then((data: string): Buffer => { - const result: IPeg__ResultArgs = { success: data }; + } + }); + } + public process_peg(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + try { + const args: IPeg__Args = Peg__ArgsCodec.decode(input); + input.readMessageEnd(); + resolve(this._handler.peg(args.name, context)); + } + catch (err) { + reject(err); + } + }).then((data: string): Buffer => { + const result: IPeg__ResultArgs = { success: data }; + output.writeMessageBegin("peg", thrift.MessageType.REPLY, requestId); + Peg__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + if (err instanceof ServiceException) { + const result: IPeg__ResultArgs = { exp: err }; output.writeMessageBegin("peg", thrift.MessageType.REPLY, requestId); Peg__ResultCodec.encode(result, output); output.writeMessageEnd(); return output.flush(); - }).catch((err: Error): Buffer => { - if (err instanceof ServiceException) { - const result: IPeg__ResultArgs = { exp: err }; - output.writeMessageBegin("peg", thrift.MessageType.REPLY, requestId); - Peg__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - } - else if (err instanceof AuthException) { - const result: IPeg__ResultArgs = { authExp: err }; - output.writeMessageBegin("peg", thrift.MessageType.REPLY, requestId); - Peg__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - } - else if (err instanceof UnknownException) { - const result: IPeg__ResultArgs = { unknownExp: err }; - output.writeMessageBegin("peg", thrift.MessageType.REPLY, requestId); - Peg__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - } - else { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("peg", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - } - }); - } + } + else if (err instanceof AuthException) { + const result: IPeg__ResultArgs = { authExp: err }; + output.writeMessageBegin("peg", thrift.MessageType.REPLY, requestId); + Peg__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + } + else if (err instanceof UnknownException) { + const result: IPeg__ResultArgs = { unknownExp: err }; + output.writeMessageBegin("peg", thrift.MessageType.REPLY, requestId); + Peg__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + } + else { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("peg", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + } + }); } } diff --git a/src/tests/unit/fixtures/thrift-server/throws_service.solution.ts b/src/tests/unit/fixtures/thrift-server/throws_service.solution.ts index f0cfeed8..d4730860 100644 --- a/src/tests/unit/fixtures/thrift-server/throws_service.solution.ts +++ b/src/tests/unit/fixtures/thrift-server/throws_service.solution.ts @@ -72,542 +72,540 @@ export class ServiceException extends thrift.StructLike implements IServiceExcep return ServiceExceptionCodec.encode(this, output); } } -export namespace MyService { - export const serviceName: string = "MyService"; - export const annotations: thrift.IThriftAnnotations = {}; - export const methodAnnotations: thrift.IMethodAnnotations = { - peg: { - annotations: {}, - fieldAnnotations: {} - }, - pong: { - annotations: {}, - fieldAnnotations: {} +export const serviceName: string = "MyService"; +export const annotations: thrift.IThriftAnnotations = {}; +export const methodAnnotations: thrift.IMethodAnnotations = { + peg: { + annotations: {}, + fieldAnnotations: {} + }, + pong: { + annotations: {}, + fieldAnnotations: {} + } +}; +export const methodNames: Array = ["peg", "pong"]; +export interface IPeg__Args { + name: string; +} +export interface IPeg__ArgsArgs { + name: string; +} +export const Peg__ArgsCodec: thrift.IStructCodec = { + encode(args: IPeg__ArgsArgs, output: thrift.TProtocol): void { + const obj = { + name: args.name + }; + output.writeStructBegin("Peg__Args"); + if (obj.name != null) { + output.writeFieldBegin("name", thrift.TType.STRING, 1); + output.writeString(obj.name); + output.writeFieldEnd(); } - }; - export const methodNames: Array = ["peg", "pong"]; - export interface IPeg__Args { - name: string; - } - export interface IPeg__ArgsArgs { - name: string; - } - export const Peg__ArgsCodec: thrift.IStructCodec = { - encode(args: IPeg__ArgsArgs, output: thrift.TProtocol): void { - const obj = { - name: args.name - }; - output.writeStructBegin("Peg__Args"); - if (obj.name != null) { - output.writeFieldBegin("name", thrift.TType.STRING, 1); - output.writeString(obj.name); - output.writeFieldEnd(); - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[name] is unset!"); + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[name] is unset!"); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IPeg__Args { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IPeg__Args { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.STRING) { - const value_3: string = input.readString(); - _args.name = value_3; - } - else { - input.skip(fieldType); - } - break; - default: { + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.STRING) { + const value_3: string = input.readString(); + _args.name = value_3; + } + else { input.skip(fieldType); } + break; + default: { + input.skip(fieldType); } - input.readFieldEnd(); - } - input.readStructEnd(); - if (_args.name !== undefined) { - return { - name: _args.name - }; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read Peg__Args from input"); } + input.readFieldEnd(); } - }; - export class Peg__Args extends thrift.StructLike implements IPeg__Args { - public name: string; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IPeg__ArgsArgs) { - super(); - if (args.name != null) { - const value_4: string = args.name; - this.name = value_4; - } - else { - throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[name] is unset!"); - } + input.readStructEnd(); + if (_args.name !== undefined) { + return { + name: _args.name + }; } - public static read(input: thrift.TProtocol): Peg__Args { - return new Peg__Args(Peg__ArgsCodec.decode(input)); + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read Peg__Args from input"); } - public static write(args: IPeg__ArgsArgs, output: thrift.TProtocol): void { - return Peg__ArgsCodec.encode(args, output); + } +}; +export class Peg__Args extends thrift.StructLike implements IPeg__Args { + public name: string; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IPeg__ArgsArgs) { + super(); + if (args.name != null) { + const value_4: string = args.name; + this.name = value_4; } - public write(output: thrift.TProtocol): void { - return Peg__ArgsCodec.encode(this, output); + else { + throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[name] is unset!"); } } - export interface IPong__Args { - name?: string; + public static read(input: thrift.TProtocol): Peg__Args { + return new Peg__Args(Peg__ArgsCodec.decode(input)); } - export interface IPong__ArgsArgs { - name?: string; + public static write(args: IPeg__ArgsArgs, output: thrift.TProtocol): void { + return Peg__ArgsCodec.encode(args, output); } - export const Pong__ArgsCodec: thrift.IStructCodec = { - encode(args: IPong__ArgsArgs, output: thrift.TProtocol): void { - const obj = { - name: args.name - }; - output.writeStructBegin("Pong__Args"); - if (obj.name != null) { - output.writeFieldBegin("name", thrift.TType.STRING, 1); - output.writeString(obj.name); - output.writeFieldEnd(); + public write(output: thrift.TProtocol): void { + return Peg__ArgsCodec.encode(this, output); + } +} +export interface IPong__Args { + name?: string; +} +export interface IPong__ArgsArgs { + name?: string; +} +export const Pong__ArgsCodec: thrift.IStructCodec = { + encode(args: IPong__ArgsArgs, output: thrift.TProtocol): void { + const obj = { + name: args.name + }; + output.writeStructBegin("Pong__Args"); + if (obj.name != null) { + output.writeFieldBegin("name", thrift.TType.STRING, 1); + output.writeString(obj.name); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IPong__Args { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IPong__Args { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 1: - if (fieldType === thrift.TType.STRING) { - const value_5: string = input.readString(); - _args.name = value_5; - } - else { - input.skip(fieldType); - } - break; - default: { + switch (fieldId) { + case 1: + if (fieldType === thrift.TType.STRING) { + const value_5: string = input.readString(); + _args.name = value_5; + } + else { input.skip(fieldType); } + break; + default: { + input.skip(fieldType); } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - name: _args.name - }; - } - }; - export class Pong__Args extends thrift.StructLike implements IPong__Args { - public name?: string; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IPong__ArgsArgs = {}) { - super(); - if (args.name != null) { - const value_6: string = args.name; - this.name = value_6; } + input.readFieldEnd(); } - public static read(input: thrift.TProtocol): Pong__Args { - return new Pong__Args(Pong__ArgsCodec.decode(input)); - } - public static write(args: IPong__ArgsArgs, output: thrift.TProtocol): void { - return Pong__ArgsCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return Pong__ArgsCodec.encode(this, output); + input.readStructEnd(); + return { + name: _args.name + }; + } +}; +export class Pong__Args extends thrift.StructLike implements IPong__Args { + public name?: string; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IPong__ArgsArgs = {}) { + super(); + if (args.name != null) { + const value_6: string = args.name; + this.name = value_6; } } - export interface IPeg__Result { - success?: string; - exp?: IServiceException; + public static read(input: thrift.TProtocol): Pong__Args { + return new Pong__Args(Pong__ArgsCodec.decode(input)); } - export interface IPeg__ResultArgs { - success?: string; - exp?: IServiceExceptionArgs; + public static write(args: IPong__ArgsArgs, output: thrift.TProtocol): void { + return Pong__ArgsCodec.encode(args, output); } - export const Peg__ResultCodec: thrift.IStructCodec = { - encode(args: IPeg__ResultArgs, output: thrift.TProtocol): void { - const obj = { - success: args.success, - exp: args.exp - }; - output.writeStructBegin("Peg__Result"); - if (obj.success != null) { - output.writeFieldBegin("success", thrift.TType.STRING, 0); - output.writeString(obj.success); - output.writeFieldEnd(); - } - if (obj.exp != null) { - output.writeFieldBegin("exp", thrift.TType.STRUCT, 1); - ServiceExceptionCodec.encode(obj.exp, output); - output.writeFieldEnd(); + public write(output: thrift.TProtocol): void { + return Pong__ArgsCodec.encode(this, output); + } +} +export interface IPeg__Result { + success?: string; + exp?: IServiceException; +} +export interface IPeg__ResultArgs { + success?: string; + exp?: IServiceExceptionArgs; +} +export const Peg__ResultCodec: thrift.IStructCodec = { + encode(args: IPeg__ResultArgs, output: thrift.TProtocol): void { + const obj = { + success: args.success, + exp: args.exp + }; + output.writeStructBegin("Peg__Result"); + if (obj.success != null) { + output.writeFieldBegin("success", thrift.TType.STRING, 0); + output.writeString(obj.success); + output.writeFieldEnd(); + } + if (obj.exp != null) { + output.writeFieldBegin("exp", thrift.TType.STRUCT, 1); + ServiceExceptionCodec.encode(obj.exp, output); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IPeg__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IPeg__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.STRING) { + const value_7: string = input.readString(); + _args.success = value_7; + } + else { + input.skip(fieldType); + } break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.STRING) { - const value_7: string = input.readString(); - _args.success = value_7; - } - else { - input.skip(fieldType); - } - break; - case 1: - if (fieldType === thrift.TType.STRUCT) { - const value_8: IServiceException = ServiceExceptionCodec.decode(input); - _args.exp = value_8; - } - else { - input.skip(fieldType); - } - break; - default: { + case 1: + if (fieldType === thrift.TType.STRUCT) { + const value_8: IServiceException = ServiceExceptionCodec.decode(input); + _args.exp = value_8; + } + else { input.skip(fieldType); } + break; + default: { + input.skip(fieldType); } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - success: _args.success, - exp: _args.exp - }; - } - }; - export class Peg__Result extends thrift.StructLike implements IPeg__Result { - public success?: string; - public exp?: IServiceException; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IPeg__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_9: string = args.success; - this.success = value_9; - } - if (args.exp != null) { - const value_10: IServiceException = new ServiceException(args.exp); - this.exp = value_10; } + input.readFieldEnd(); } - public static read(input: thrift.TProtocol): Peg__Result { - return new Peg__Result(Peg__ResultCodec.decode(input)); - } - public static write(args: IPeg__ResultArgs, output: thrift.TProtocol): void { - return Peg__ResultCodec.encode(args, output); + input.readStructEnd(); + return { + success: _args.success, + exp: _args.exp + }; + } +}; +export class Peg__Result extends thrift.StructLike implements IPeg__Result { + public success?: string; + public exp?: IServiceException; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IPeg__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_9: string = args.success; + this.success = value_9; } - public write(output: thrift.TProtocol): void { - return Peg__ResultCodec.encode(this, output); + if (args.exp != null) { + const value_10: IServiceException = new ServiceException(args.exp); + this.exp = value_10; } } - export interface IPong__Result { - success?: string; + public static read(input: thrift.TProtocol): Peg__Result { + return new Peg__Result(Peg__ResultCodec.decode(input)); } - export interface IPong__ResultArgs { - success?: string; + public static write(args: IPeg__ResultArgs, output: thrift.TProtocol): void { + return Peg__ResultCodec.encode(args, output); } - export const Pong__ResultCodec: thrift.IStructCodec = { - encode(args: IPong__ResultArgs, output: thrift.TProtocol): void { - const obj = { - success: args.success - }; - output.writeStructBegin("Pong__Result"); - if (obj.success != null) { - output.writeFieldBegin("success", thrift.TType.STRING, 0); - output.writeString(obj.success); - output.writeFieldEnd(); + public write(output: thrift.TProtocol): void { + return Peg__ResultCodec.encode(this, output); + } +} +export interface IPong__Result { + success?: string; +} +export interface IPong__ResultArgs { + success?: string; +} +export const Pong__ResultCodec: thrift.IStructCodec = { + encode(args: IPong__ResultArgs, output: thrift.TProtocol): void { + const obj = { + success: args.success + }; + output.writeStructBegin("Pong__Result"); + if (obj.success != null) { + output.writeFieldBegin("success", thrift.TType.STRING, 0); + output.writeString(obj.success); + output.writeFieldEnd(); + } + output.writeFieldStop(); + output.writeStructEnd(); + return; + }, + decode(input: thrift.TProtocol): IPong__Result { + let _args: any = {}; + input.readStructBegin(); + while (true) { + const ret: thrift.IThriftField = input.readFieldBegin(); + const fieldType: thrift.TType = ret.fieldType; + const fieldId: number = ret.fieldId; + if (fieldType === thrift.TType.STOP) { + break; } - output.writeFieldStop(); - output.writeStructEnd(); - return; - }, - decode(input: thrift.TProtocol): IPong__Result { - let _args: any = {}; - input.readStructBegin(); - while (true) { - const ret: thrift.IThriftField = input.readFieldBegin(); - const fieldType: thrift.TType = ret.fieldType; - const fieldId: number = ret.fieldId; - if (fieldType === thrift.TType.STOP) { - break; - } - switch (fieldId) { - case 0: - if (fieldType === thrift.TType.STRING) { - const value_11: string = input.readString(); - _args.success = value_11; - } - else { - input.skip(fieldType); - } - break; - default: { + switch (fieldId) { + case 0: + if (fieldType === thrift.TType.STRING) { + const value_11: string = input.readString(); + _args.success = value_11; + } + else { input.skip(fieldType); } + break; + default: { + input.skip(fieldType); } - input.readFieldEnd(); - } - input.readStructEnd(); - return { - success: _args.success - }; - } - }; - export class Pong__Result extends thrift.StructLike implements IPong__Result { - public success?: string; - public readonly _annotations: thrift.IThriftAnnotations = {}; - public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; - constructor(args: IPong__ResultArgs = {}) { - super(); - if (args.success != null) { - const value_12: string = args.success; - this.success = value_12; } + input.readFieldEnd(); } - public static read(input: thrift.TProtocol): Pong__Result { - return new Pong__Result(Pong__ResultCodec.decode(input)); - } - public static write(args: IPong__ResultArgs, output: thrift.TProtocol): void { - return Pong__ResultCodec.encode(args, output); - } - public write(output: thrift.TProtocol): void { - return Pong__ResultCodec.encode(this, output); + input.readStructEnd(); + return { + success: _args.success + }; + } +}; +export class Pong__Result extends thrift.StructLike implements IPong__Result { + public success?: string; + public readonly _annotations: thrift.IThriftAnnotations = {}; + public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; + constructor(args: IPong__ResultArgs = {}) { + super(); + if (args.success != null) { + const value_12: string = args.success; + this.success = value_12; } } - export class Client extends thrift.ThriftClient { - public static readonly serviceName: string = serviceName; - public static readonly annotations: thrift.IThriftAnnotations = annotations; - public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public static readonly methodNames: Array = methodNames; - public readonly _serviceName: string = serviceName; - public readonly _annotations: thrift.IThriftAnnotations = annotations; - public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public readonly _methodNames: Array = methodNames; - public peg(name: string, context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("peg", thrift.MessageType.CALL, this.incrementRequestId()); - const args: IPeg__ArgsArgs = { name }; - Peg__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "peg") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); - } - else { - const result: IPeg__Result = Peg__ResultCodec.decode(input); - input.readMessageEnd(); - if (result.exp != null) { - return Promise.reject(result.exp); - } - else if (result.success != null) { - return Promise.resolve(result.success); - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "peg failed: unknown result")); - } - } + public static read(input: thrift.TProtocol): Pong__Result { + return new Pong__Result(Pong__ResultCodec.decode(input)); + } + public static write(args: IPong__ResultArgs, output: thrift.TProtocol): void { + return Pong__ResultCodec.encode(args, output); + } + public write(output: thrift.TProtocol): void { + return Pong__ResultCodec.encode(this, output); + } +} +export class Client extends thrift.ThriftClient { + public static readonly serviceName: string = serviceName; + public static readonly annotations: thrift.IThriftAnnotations = annotations; + public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public static readonly methodNames: Array = methodNames; + public readonly _serviceName: string = serviceName; + public readonly _annotations: thrift.IThriftAnnotations = annotations; + public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public readonly _methodNames: Array = methodNames; + public peg(name: string, context?: Context): Promise { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("peg", thrift.MessageType.CALL, this.incrementRequestId()); + const args: IPeg__ArgsArgs = { name }; + Peg__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "peg") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); } else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } - } - catch (err) { - return Promise.reject(err); - } - }); - } - public pong(name?: string, context?: Context): Promise { - const writer: thrift.TTransport = new this.transport(); - const output: thrift.TProtocol = new this.protocol(writer); - output.writeMessageBegin("pong", thrift.MessageType.CALL, this.incrementRequestId()); - const args: IPong__ArgsArgs = { name }; - Pong__ArgsCodec.encode(args, output); - output.writeMessageEnd(); - return this.connection.send(writer.flush(), context).then((data: Buffer) => { - const reader: thrift.TTransport = this.transport.receiver(data); - const input: thrift.TProtocol = new this.protocol(reader); - try { - const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); - if (fieldName === "pong") { - if (messageType === thrift.MessageType.EXCEPTION) { - const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); - input.readMessageEnd(); - return Promise.reject(err); + const result: IPeg__Result = Peg__ResultCodec.decode(input); + input.readMessageEnd(); + if (result.exp != null) { + return Promise.reject(result.exp); + } + else if (result.success != null) { + return Promise.resolve(result.success); } else { - const result: IPong__Result = Pong__ResultCodec.decode(input); - input.readMessageEnd(); - if (result.success != null) { - return Promise.resolve(result.success); - } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "pong failed: unknown result")); - } + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "peg failed: unknown result")); } } - else { - return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); - } } - catch (err) { - return Promise.reject(err); + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); } - }); - } + } + catch (err) { + return Promise.reject(err); + } + }); } - export interface IHandler { - peg(name: string, context?: Context): string | Promise; - pong(name?: string, context?: Context): string | Promise; - } - export class Processor extends thrift.ThriftProcessor> { - protected readonly _handler: IHandler; - public static readonly serviceName: string = serviceName; - public static readonly annotations: thrift.IThriftAnnotations = annotations; - public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public static readonly methodNames: Array = methodNames; - public readonly _serviceName: string = serviceName; - public readonly _annotations: thrift.IThriftAnnotations = annotations; - public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; - public readonly _methodNames: Array = methodNames; - constructor(handler: IHandler) { - super(); - this._handler = handler; - } - public process(input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - const metadata: thrift.IThriftMessage = input.readMessageBegin(); - const fieldName: string = metadata.fieldName; - const requestId: number = metadata.requestId; - const methodName: string = "process_" + fieldName; - switch (methodName) { - case "process_peg": { - resolve(this.process_peg(requestId, input, output, context)); - break; - } - case "process_pong": { - resolve(this.process_pong(requestId, input, output, context)); - break; + public pong(name?: string, context?: Context): Promise { + const writer: thrift.TTransport = new this.transport(); + const output: thrift.TProtocol = new this.protocol(writer); + output.writeMessageBegin("pong", thrift.MessageType.CALL, this.incrementRequestId()); + const args: IPong__ArgsArgs = { name }; + Pong__ArgsCodec.encode(args, output); + output.writeMessageEnd(); + return this.connection.send(writer.flush(), context).then((data: Buffer) => { + const reader: thrift.TTransport = this.transport.receiver(data); + const input: thrift.TProtocol = new this.protocol(reader); + try { + const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin(); + if (fieldName === "pong") { + if (messageType === thrift.MessageType.EXCEPTION) { + const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input); + input.readMessageEnd(); + return Promise.reject(err); } - default: { - input.skip(thrift.TType.STRUCT); + else { + const result: IPong__Result = Pong__ResultCodec.decode(input); input.readMessageEnd(); - const errMessage = "Unknown function " + fieldName; - const err = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN_METHOD, errMessage); - output.writeMessageBegin(fieldName, thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(err, output); - output.writeMessageEnd(); - resolve(output.flush()); - break; + if (result.success != null) { + return Promise.resolve(result.success); + } + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "pong failed: unknown result")); + } } } - }); - } - public process_peg(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { - const args: IPeg__Args = Peg__ArgsCodec.decode(input); - input.readMessageEnd(); - resolve(this._handler.peg(args.name, context)); - } - catch (err) { - reject(err); + else { + return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName)); } - }).then((data: string): Buffer => { - const result: IPeg__ResultArgs = { success: data }; - output.writeMessageBegin("peg", thrift.MessageType.REPLY, requestId); - Peg__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); - }).catch((err: Error): Buffer => { - if (err instanceof ServiceException) { - const result: IPeg__ResultArgs = { exp: err }; - output.writeMessageBegin("peg", thrift.MessageType.REPLY, requestId); - Peg__ResultCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); + } + catch (err) { + return Promise.reject(err); + } + }); + } +} +export interface IHandler { + peg(name: string, context?: Context): string | Promise; + pong(name?: string, context?: Context): string | Promise; +} +export class Processor extends thrift.ThriftProcessor> { + protected readonly _handler: IHandler; + public static readonly serviceName: string = serviceName; + public static readonly annotations: thrift.IThriftAnnotations = annotations; + public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public static readonly methodNames: Array = methodNames; + public readonly _serviceName: string = serviceName; + public readonly _annotations: thrift.IThriftAnnotations = annotations; + public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations; + public readonly _methodNames: Array = methodNames; + constructor(handler: IHandler) { + super(); + this._handler = handler; + } + public process(input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + const metadata: thrift.IThriftMessage = input.readMessageBegin(); + const fieldName: string = metadata.fieldName; + const requestId: number = metadata.requestId; + const methodName: string = "process_" + fieldName; + switch (methodName) { + case "process_peg": { + resolve(this.process_peg(requestId, input, output, context)); + break; } - else { - const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("peg", thrift.MessageType.EXCEPTION, requestId); - thrift.TApplicationExceptionCodec.encode(result, output); - output.writeMessageEnd(); - return output.flush(); + case "process_pong": { + resolve(this.process_pong(requestId, input, output, context)); + break; } - }); - } - public process_pong(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { - return new Promise((resolve, reject): void => { - try { - const args: IPong__Args = Pong__ArgsCodec.decode(input); + default: { + input.skip(thrift.TType.STRUCT); input.readMessageEnd(); - resolve(this._handler.pong(args.name, context)); - } - catch (err) { - reject(err); + const errMessage = "Unknown function " + fieldName; + const err = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN_METHOD, errMessage); + output.writeMessageBegin(fieldName, thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(err, output); + output.writeMessageEnd(); + resolve(output.flush()); + break; } - }).then((data: string): Buffer => { - const result: IPong__ResultArgs = { success: data }; - output.writeMessageBegin("pong", thrift.MessageType.REPLY, requestId); - Pong__ResultCodec.encode(result, output); + } + }); + } + public process_peg(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + try { + const args: IPeg__Args = Peg__ArgsCodec.decode(input); + input.readMessageEnd(); + resolve(this._handler.peg(args.name, context)); + } + catch (err) { + reject(err); + } + }).then((data: string): Buffer => { + const result: IPeg__ResultArgs = { success: data }; + output.writeMessageBegin("peg", thrift.MessageType.REPLY, requestId); + Peg__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + if (err instanceof ServiceException) { + const result: IPeg__ResultArgs = { exp: err }; + output.writeMessageBegin("peg", thrift.MessageType.REPLY, requestId); + Peg__ResultCodec.encode(result, output); output.writeMessageEnd(); return output.flush(); - }).catch((err: Error): Buffer => { + } + else { const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); - output.writeMessageBegin("pong", thrift.MessageType.EXCEPTION, requestId); + output.writeMessageBegin("peg", thrift.MessageType.EXCEPTION, requestId); thrift.TApplicationExceptionCodec.encode(result, output); output.writeMessageEnd(); return output.flush(); - }); - } + } + }); + } + public process_pong(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise { + return new Promise((resolve, reject): void => { + try { + const args: IPong__Args = Pong__ArgsCodec.decode(input); + input.readMessageEnd(); + resolve(this._handler.pong(args.name, context)); + } + catch (err) { + reject(err); + } + }).then((data: string): Buffer => { + const result: IPong__ResultArgs = { success: data }; + output.writeMessageBegin("pong", thrift.MessageType.REPLY, requestId); + Pong__ResultCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }).catch((err: Error): Buffer => { + const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("pong", thrift.MessageType.EXCEPTION, requestId); + thrift.TApplicationExceptionCodec.encode(result, output); + output.writeMessageEnd(); + return output.flush(); + }); } } diff --git a/src/tests/unit/fixtures/thrift/calculator.thrift b/src/tests/unit/fixtures/thrift/calculator.thrift index 9491e558..1710ce44 100644 --- a/src/tests/unit/fixtures/thrift/calculator.thrift +++ b/src/tests/unit/fixtures/thrift/calculator.thrift @@ -1,11 +1,11 @@ -namespace cpp calculator -namespace d calculator -namespace dart calculator -namespace java calculator -namespace php calculator -namespace perl calculator -namespace haxe calculator -namespace netcore calculator +namespace cpp com.test.calculator +namespace d com.test.calculator +namespace dart com.test.calculator +namespace java com.test.calculator +namespace php com.test.calculator +namespace perl com.test.calculator +namespace haxe com.test.calculator +namespace netcore com.test.calculator include "shared.thrift" include "common.thrift" @@ -21,7 +21,7 @@ const map MAPCONSTANT = {'hello':'world', 'goodnight':'moon'} struct Work { 1: required i32 num1 = 0, 2: required i32 num2, - 3: required Operation op, + 3: optional Operation op = Operation.ADD, 4: optional string comment, } @@ -38,13 +38,17 @@ union Choice { 2: LastName lastName } +exception NotAGoodIdea { + 1: string message +} + service Calculator extends shared.SharedService { void ping(), i32 add(1: i32 num1, 2: i32 num2) throws (1: operation.JankyResult exp), - i64 addInt64(1: i64 num1, 2: i64 num2), + i64 addInt64(1: i64 num1, 2: i64 num2) throws (1: NotAGoodIdea exp), i32 addWithContext(1: i32 num1, 2: i32 num2), diff --git a/src/tests/unit/fixtures/thrift/common.thrift b/src/tests/unit/fixtures/thrift/common.thrift index feaf10a4..9102328b 100644 --- a/src/tests/unit/fixtures/thrift/common.thrift +++ b/src/tests/unit/fixtures/thrift/common.thrift @@ -2,14 +2,14 @@ * Thrift files can namespace, package, or prefix their output in various * target languages. */ -namespace cpp common -namespace d common -namespace dart common -namespace java common -namespace php common -namespace perl common -namespace haxe common -namespace netcore common +namespace cpp com.test.common +namespace d com.test.common +namespace dart com.test.common +namespace java com.test.common +namespace php com.test.common +namespace perl com.test.common +namespace haxe com.test.common +namespace netcore com.test.common include "shared.thrift" @@ -21,3 +21,11 @@ exception AuthException { 1: i32 code 2: string message } + +union OtherCommonUnion { + 1: string option1 + 2: i32 option2 +} + +typedef AuthException NotAllowed +typedef OtherCommonUnion MoreOptions diff --git a/src/tests/unit/fixtures/thrift/exceptions.thrift b/src/tests/unit/fixtures/thrift/exceptions.thrift index 880b6a3f..14f930ee 100644 --- a/src/tests/unit/fixtures/thrift/exceptions.thrift +++ b/src/tests/unit/fixtures/thrift/exceptions.thrift @@ -1,11 +1,11 @@ -namespace cpp exceptions -namespace d exceptions -namespace dart exceptions -namespace java exceptions -namespace perl exceptions -namespace php exceptions -namespace haxe exceptions -namespace netcore exceptions +namespace cpp com.test.exceptions +namespace d com.test.exceptions +namespace dart com.test.exceptions +namespace java com.test.exceptions +namespace perl com.test.exceptions +namespace php com.test.exceptions +namespace haxe com.test.exceptions +namespace netcore com.test.exceptions include "shared.thrift" diff --git a/src/tests/unit/fixtures/thrift/operation.thrift b/src/tests/unit/fixtures/thrift/operation.thrift index c8837939..28c961ad 100644 --- a/src/tests/unit/fixtures/thrift/operation.thrift +++ b/src/tests/unit/fixtures/thrift/operation.thrift @@ -1,5 +1,5 @@ -namespace java operation -namespace js operation +namespace java com.test.operation +namespace js com.test.operation include "exceptions.thrift" diff --git a/src/tests/unit/fixtures/thrift/shared.thrift b/src/tests/unit/fixtures/thrift/shared.thrift index 243a309e..9f76b21d 100644 --- a/src/tests/unit/fixtures/thrift/shared.thrift +++ b/src/tests/unit/fixtures/thrift/shared.thrift @@ -1,11 +1,11 @@ -namespace cpp shared -namespace d share // "shared" would collide with the eponymous D keyword. -namespace dart shared -namespace java shared -namespace perl shared -namespace php shared -namespace haxe shared -namespace netcore shared +namespace cpp com.test.shared +namespace d com.test.share // "shared" would collide with the eponymous D keyword. +namespace dart com.test.shared +namespace java com.test.shared +namespace perl com.test.shared +namespace php com.test.shared +namespace haxe com.test.shared +namespace netcore com.test.shared const i32 SHARED_INT = 45 diff --git a/src/tests/unit/fixtures/validator/include-types.solution.json b/src/tests/unit/fixtures/validator/include-types.solution.json deleted file mode 100644 index 485b6548..00000000 --- a/src/tests/unit/fixtures/validator/include-types.solution.json +++ /dev/null @@ -1,719 +0,0 @@ -{ - "name": "", - "path": "", - "source": "\n include 'exception.thrift'\n\n exception MyException {\n 1: exception.Status status = exception.Status.SUCCESS;\n }\n ", - "namespace": { - "scope": "", - "name": "", - "path": "" - }, - "includes": { - "exception": { - "file": { - "name": "exception", - "path": "", - "source": "", - "namespace": { - "scope": "", - "name": "", - "path": "" - }, - "includes": {}, - "identifiers": { - "Status": { - "name": "Status", - "pathName": "", - "resolvedName": "Status", - "definition": { - "type": "EnumDefinition", - "name": { - "type": "Identifier", - "value": "Status", - "loc": { - "start": { - "line": 2, - "column": 18, - "index": 18 - }, - "end": { - "line": 2, - "column": 24, - "index": 24 - } - } - }, - "members": [ - { - "type": "EnumMember", - "name": { - "type": "Identifier", - "value": "SUCCESS", - "loc": { - "start": { - "line": 3, - "column": 17, - "index": 43 - }, - "end": { - "line": 3, - "column": 24, - "index": 50 - } - } - }, - "initializer": null, - "comments": [], - "loc": { - "start": { - "line": 3, - "column": 17, - "index": 43 - }, - "end": { - "line": 3, - "column": 24, - "index": 50 - } - } - }, - { - "type": "EnumMember", - "name": { - "type": "Identifier", - "value": "FAILURE", - "loc": { - "start": { - "line": 4, - "column": 17, - "index": 68 - }, - "end": { - "line": 4, - "column": 24, - "index": 75 - } - } - }, - "initializer": null, - "comments": [], - "loc": { - "start": { - "line": 4, - "column": 17, - "index": 68 - }, - "end": { - "line": 4, - "column": 24, - "index": 75 - } - } - } - ], - "comments": [], - "loc": { - "start": { - "line": 2, - "column": 13, - "index": 13 - }, - "end": { - "line": 5, - "column": 14, - "index": 89 - } - } - } - } - }, - "body": [ - { - "type": "EnumDefinition", - "name": { - "type": "Identifier", - "value": "Status", - "loc": { - "start": { - "line": 2, - "column": 18, - "index": 18 - }, - "end": { - "line": 2, - "column": 24, - "index": 24 - } - } - }, - "members": [ - { - "type": "EnumMember", - "name": { - "type": "Identifier", - "value": "SUCCESS", - "loc": { - "start": { - "line": 3, - "column": 17, - "index": 43 - }, - "end": { - "line": 3, - "column": 24, - "index": 50 - } - } - }, - "initializer": null, - "comments": [], - "loc": { - "start": { - "line": 3, - "column": 17, - "index": 43 - }, - "end": { - "line": 3, - "column": 24, - "index": 50 - } - } - }, - { - "type": "EnumMember", - "name": { - "type": "Identifier", - "value": "FAILURE", - "loc": { - "start": { - "line": 4, - "column": 17, - "index": 68 - }, - "end": { - "line": 4, - "column": 24, - "index": 75 - } - } - }, - "initializer": null, - "comments": [], - "loc": { - "start": { - "line": 4, - "column": 17, - "index": 68 - }, - "end": { - "line": 4, - "column": 24, - "index": 75 - } - } - } - ], - "comments": [], - "loc": { - "start": { - "line": 2, - "column": 13, - "index": 13 - }, - "end": { - "line": 5, - "column": 14, - "index": 89 - } - } - } - ], - "errors": [] - }, - "identifiers": [ - { - "name": "Status", - "pathName": "exception", - "resolvedName": "exception.Status", - "definition": { - "type": "EnumDefinition", - "name": { - "type": "Identifier", - "value": "Status", - "loc": { - "start": { - "line": 2, - "column": 18, - "index": 18 - }, - "end": { - "line": 2, - "column": 24, - "index": 24 - } - } - }, - "members": [ - { - "type": "EnumMember", - "name": { - "type": "Identifier", - "value": "SUCCESS", - "loc": { - "start": { - "line": 3, - "column": 17, - "index": 43 - }, - "end": { - "line": 3, - "column": 24, - "index": 50 - } - } - }, - "initializer": null, - "comments": [], - "loc": { - "start": { - "line": 3, - "column": 17, - "index": 43 - }, - "end": { - "line": 3, - "column": 24, - "index": 50 - } - } - }, - { - "type": "EnumMember", - "name": { - "type": "Identifier", - "value": "FAILURE", - "loc": { - "start": { - "line": 4, - "column": 17, - "index": 68 - }, - "end": { - "line": 4, - "column": 24, - "index": 75 - } - } - }, - "initializer": null, - "comments": [], - "loc": { - "start": { - "line": 4, - "column": 17, - "index": 68 - }, - "end": { - "line": 4, - "column": 24, - "index": 75 - } - } - } - ], - "comments": [], - "loc": { - "start": { - "line": 2, - "column": 13, - "index": 13 - }, - "end": { - "line": 5, - "column": 14, - "index": 89 - } - } - } - } - ] - } - }, - "identifiers": { - "exception.Status": { - "name": "Status", - "pathName": "exception", - "resolvedName": "exception.Status", - "definition": { - "type": "EnumDefinition", - "name": { - "type": "Identifier", - "value": "Status", - "loc": { - "start": { - "line": 2, - "column": 18, - "index": 18 - }, - "end": { - "line": 2, - "column": 24, - "index": 24 - } - } - }, - "members": [ - { - "type": "EnumMember", - "name": { - "type": "Identifier", - "value": "SUCCESS", - "loc": { - "start": { - "line": 3, - "column": 17, - "index": 43 - }, - "end": { - "line": 3, - "column": 24, - "index": 50 - } - } - }, - "initializer": null, - "comments": [], - "loc": { - "start": { - "line": 3, - "column": 17, - "index": 43 - }, - "end": { - "line": 3, - "column": 24, - "index": 50 - } - } - }, - { - "type": "EnumMember", - "name": { - "type": "Identifier", - "value": "FAILURE", - "loc": { - "start": { - "line": 4, - "column": 17, - "index": 68 - }, - "end": { - "line": 4, - "column": 24, - "index": 75 - } - } - }, - "initializer": null, - "comments": [], - "loc": { - "start": { - "line": 4, - "column": 17, - "index": 68 - }, - "end": { - "line": 4, - "column": 24, - "index": 75 - } - } - } - ], - "comments": [], - "loc": { - "start": { - "line": 2, - "column": 13, - "index": 13 - }, - "end": { - "line": 5, - "column": 14, - "index": 89 - } - } - } - }, - "MyException": { - "name": "MyException", - "pathName": "", - "resolvedName": "MyException", - "definition": { - "type": "ExceptionDefinition", - "name": { - "type": "Identifier", - "value": "MyException", - "loc": { - "start": { - "line": 4, - "column": 23, - "index": 63 - }, - "end": { - "line": 4, - "column": 34, - "index": 74 - } - } - }, - "fields": [ - { - "type": "FieldDefinition", - "name": { - "type": "Identifier", - "value": "status", - "loc": { - "start": { - "line": 5, - "column": 37, - "index": 113 - }, - "end": { - "line": 5, - "column": 43, - "index": 119 - } - } - }, - "fieldID": { - "type": "FieldID", - "value": 1, - "loc": { - "start": { - "line": 5, - "column": 17, - "index": 93 - }, - "end": { - "line": 5, - "column": 19, - "index": 95 - } - } - }, - "fieldType": { - "type": "Identifier", - "value": "exception.Status", - "loc": { - "start": { - "line": 5, - "column": 20, - "index": 96 - }, - "end": { - "line": 5, - "column": 36, - "index": 112 - } - } - }, - "requiredness": null, - "defaultValue": { - "type": "Identifier", - "value": "exception.Status.SUCCESS", - "loc": { - "start": { - "line": 5, - "column": 46, - "index": 122 - }, - "end": { - "line": 5, - "column": 70, - "index": 146 - } - } - }, - "comments": [], - "loc": { - "start": { - "line": 5, - "column": 17, - "index": 93 - }, - "end": { - "line": 5, - "column": 71, - "index": 147 - } - } - } - ], - "comments": [], - "loc": { - "start": { - "line": 4, - "column": 13, - "index": 53 - }, - "end": { - "line": 6, - "column": 14, - "index": 161 - } - } - } - } - }, - "body": [ - { - "type": "IncludeDefinition", - "path": { - "type": "StringLiteral", - "value": "exception.thrift", - "loc": { - "start": { - "line": 2, - "column": 21, - "index": 21 - }, - "end": { - "line": 2, - "column": 39, - "index": 39 - } - } - }, - "comments": [], - "loc": { - "start": { - "line": 2, - "column": 13, - "index": 13 - }, - "end": { - "line": 2, - "column": 39, - "index": 39 - } - } - }, - { - "type": "ExceptionDefinition", - "name": { - "type": "Identifier", - "value": "MyException", - "loc": { - "start": { - "line": 4, - "column": 23, - "index": 63 - }, - "end": { - "line": 4, - "column": 34, - "index": 74 - } - } - }, - "fields": [ - { - "type": "FieldDefinition", - "name": { - "type": "Identifier", - "value": "status", - "loc": { - "start": { - "line": 5, - "column": 37, - "index": 113 - }, - "end": { - "line": 5, - "column": 43, - "index": 119 - } - } - }, - "fieldID": { - "type": "FieldID", - "value": 1, - "loc": { - "start": { - "line": 5, - "column": 17, - "index": 93 - }, - "end": { - "line": 5, - "column": 19, - "index": 95 - } - } - }, - "fieldType": { - "type": "Identifier", - "value": "exception.Status", - "loc": { - "start": { - "line": 5, - "column": 20, - "index": 96 - }, - "end": { - "line": 5, - "column": 36, - "index": 112 - } - } - }, - "requiredness": null, - "defaultValue": { - "type": "Identifier", - "value": "exception.Status.SUCCESS", - "loc": { - "start": { - "line": 5, - "column": 46, - "index": 122 - }, - "end": { - "line": 5, - "column": 70, - "index": 146 - } - } - }, - "comments": [], - "loc": { - "start": { - "line": 5, - "column": 17, - "index": 93 - }, - "end": { - "line": 5, - "column": 71, - "index": 147 - } - } - } - ], - "comments": [], - "loc": { - "start": { - "line": 4, - "column": 13, - "index": 53 - }, - "end": { - "line": 6, - "column": 14, - "index": 161 - } - } - } - ], - "errors": [] -} diff --git a/src/tests/unit/fixtures/validator/missing-field-ids.solution.json b/src/tests/unit/fixtures/validator/missing-field-ids.solution.json deleted file mode 100644 index 5452fdd9..00000000 --- a/src/tests/unit/fixtures/validator/missing-field-ids.solution.json +++ /dev/null @@ -1,318 +0,0 @@ -{ - "name": "", - "path": "", - "source": "\n struct TestStruct {\n i32 status\n required string message\n }\n ", - "namespace": { - "scope": "", - "name": "", - "path": "" - }, - "includes": {}, - "identifiers": { - "TestStruct": { - "name": "TestStruct", - "resolvedName": "TestStruct", - "definition": { - "type": "StructDefinition", - "name": { - "type": "Identifier", - "value": "TestStruct", - "loc": { - "start": { - "line": 2, - "column": 14, - "index": 14 - }, - "end": { - "line": 2, - "column": 24, - "index": 24 - } - } - }, - "fields": [ - { - "type": "FieldDefinition", - "name": { - "type": "Identifier", - "value": "status", - "loc": { - "start": { - "line": 3, - "column": 13, - "index": 39 - }, - "end": { - "line": 3, - "column": 19, - "index": 45 - } - } - }, - "fieldID": null, - "fieldType": { - "type": "I32Keyword", - "loc": { - "start": { - "line": 3, - "column": 9, - "index": 35 - }, - "end": { - "line": 3, - "column": 12, - "index": 38 - } - } - }, - "requiredness": null, - "defaultValue": null, - "comments": [], - "loc": { - "start": { - "line": 3, - "column": 9, - "index": 35 - }, - "end": { - "line": 3, - "column": 19, - "index": 45 - } - } - }, - { - "type": "FieldDefinition", - "name": { - "type": "Identifier", - "value": "message", - "loc": { - "start": { - "line": 4, - "column": 25, - "index": 70 - }, - "end": { - "line": 4, - "column": 32, - "index": 77 - } - } - }, - "fieldID": null, - "fieldType": { - "type": "StringKeyword", - "loc": { - "start": { - "line": 4, - "column": 18, - "index": 63 - }, - "end": { - "line": 4, - "column": 24, - "index": 69 - } - } - }, - "requiredness": "required", - "defaultValue": null, - "comments": [], - "loc": { - "start": { - "line": 4, - "column": 9, - "index": 54 - }, - "end": { - "line": 4, - "column": 32, - "index": 77 - } - } - } - ], - "comments": [], - "loc": { - "start": { - "line": 2, - "column": 7, - "index": 7 - }, - "end": { - "line": 5, - "column": 8, - "index": 85 - } - } - } - } - }, - "body": [ - { - "type": "StructDefinition", - "name": { - "type": "Identifier", - "value": "TestStruct", - "loc": { - "start": { - "line": 2, - "column": 14, - "index": 14 - }, - "end": { - "line": 2, - "column": 24, - "index": 24 - } - } - }, - "fields": [ - { - "type": "FieldDefinition", - "name": { - "type": "Identifier", - "value": "status", - "loc": { - "start": { - "line": 3, - "column": 13, - "index": 39 - }, - "end": { - "line": 3, - "column": 19, - "index": 45 - } - } - }, - "fieldID": { - "type": "FieldID", - "value": -1, - "loc": { - "start": { - "line": 0, - "column": 0, - "index": 0 - }, - "end": { - "line": 0, - "column": 0, - "index": 0 - } - } - }, - "fieldType": { - "type": "I32Keyword", - "loc": { - "start": { - "line": 3, - "column": 9, - "index": 35 - }, - "end": { - "line": 3, - "column": 12, - "index": 38 - } - } - }, - "requiredness": null, - "defaultValue": null, - "comments": [], - "loc": { - "start": { - "line": 3, - "column": 9, - "index": 35 - }, - "end": { - "line": 3, - "column": 19, - "index": 45 - } - } - }, - { - "type": "FieldDefinition", - "name": { - "type": "Identifier", - "value": "message", - "loc": { - "start": { - "line": 4, - "column": 25, - "index": 70 - }, - "end": { - "line": 4, - "column": 32, - "index": 77 - } - } - }, - "fieldID": { - "type": "FieldID", - "value": -2, - "loc": { - "start": { - "line": 0, - "column": 0, - "index": 0 - }, - "end": { - "line": 0, - "column": 0, - "index": 0 - } - } - }, - "fieldType": { - "type": "StringKeyword", - "loc": { - "start": { - "line": 4, - "column": 18, - "index": 63 - }, - "end": { - "line": 4, - "column": 24, - "index": 69 - } - } - }, - "requiredness": "required", - "defaultValue": null, - "comments": [], - "loc": { - "start": { - "line": 4, - "column": 9, - "index": 54 - }, - "end": { - "line": 4, - "column": 32, - "index": 77 - } - } - } - ], - "comments": [], - "loc": { - "start": { - "line": 2, - "column": 7, - "index": 7 - }, - "end": { - "line": 5, - "column": 8, - "index": 85 - } - } - } - ], - "errors": [] -} diff --git a/src/tests/unit/fixtures/validator/missing-ids.solution.json b/src/tests/unit/fixtures/validator/missing-ids.solution.json deleted file mode 100644 index 928782ea..00000000 --- a/src/tests/unit/fixtures/validator/missing-ids.solution.json +++ /dev/null @@ -1,319 +0,0 @@ -{ - "name": "", - "path": "", - "source": "\n struct TestStruct {\n i32 status\n required string message\n }\n ", - "namespace": { - "scope": "", - "name": "", - "path": "" - }, - "includes": {}, - "identifiers": { - "TestStruct": { - "name": "TestStruct", - "pathName": "", - "resolvedName": "TestStruct", - "definition": { - "type": "StructDefinition", - "name": { - "type": "Identifier", - "value": "TestStruct", - "loc": { - "start": { - "line": 2, - "column": 20, - "index": 20 - }, - "end": { - "line": 2, - "column": 30, - "index": 30 - } - } - }, - "fields": [ - { - "type": "FieldDefinition", - "name": { - "type": "Identifier", - "value": "status", - "loc": { - "start": { - "line": 3, - "column": 21, - "index": 53 - }, - "end": { - "line": 3, - "column": 27, - "index": 59 - } - } - }, - "fieldID": null, - "fieldType": { - "type": "I32Keyword", - "loc": { - "start": { - "line": 3, - "column": 17, - "index": 49 - }, - "end": { - "line": 3, - "column": 20, - "index": 52 - } - } - }, - "requiredness": null, - "defaultValue": null, - "comments": [], - "loc": { - "start": { - "line": 3, - "column": 17, - "index": 49 - }, - "end": { - "line": 3, - "column": 27, - "index": 59 - } - } - }, - { - "type": "FieldDefinition", - "name": { - "type": "Identifier", - "value": "message", - "loc": { - "start": { - "line": 4, - "column": 33, - "index": 92 - }, - "end": { - "line": 4, - "column": 40, - "index": 99 - } - } - }, - "fieldID": null, - "fieldType": { - "type": "StringKeyword", - "loc": { - "start": { - "line": 4, - "column": 26, - "index": 85 - }, - "end": { - "line": 4, - "column": 32, - "index": 91 - } - } - }, - "requiredness": "required", - "defaultValue": null, - "comments": [], - "loc": { - "start": { - "line": 4, - "column": 17, - "index": 76 - }, - "end": { - "line": 4, - "column": 40, - "index": 99 - } - } - } - ], - "comments": [], - "loc": { - "start": { - "line": 2, - "column": 13, - "index": 13 - }, - "end": { - "line": 5, - "column": 14, - "index": 113 - } - } - } - } - }, - "body": [ - { - "type": "StructDefinition", - "name": { - "type": "Identifier", - "value": "TestStruct", - "loc": { - "start": { - "line": 2, - "column": 20, - "index": 20 - }, - "end": { - "line": 2, - "column": 30, - "index": 30 - } - } - }, - "fields": [ - { - "type": "FieldDefinition", - "name": { - "type": "Identifier", - "value": "status", - "loc": { - "start": { - "line": 3, - "column": 21, - "index": 53 - }, - "end": { - "line": 3, - "column": 27, - "index": 59 - } - } - }, - "fieldID": { - "type": "FieldID", - "value": -1, - "loc": { - "start": { - "line": 0, - "column": 0, - "index": 0 - }, - "end": { - "line": 0, - "column": 0, - "index": 0 - } - } - }, - "fieldType": { - "type": "I32Keyword", - "loc": { - "start": { - "line": 3, - "column": 17, - "index": 49 - }, - "end": { - "line": 3, - "column": 20, - "index": 52 - } - } - }, - "requiredness": null, - "defaultValue": null, - "comments": [], - "loc": { - "start": { - "line": 3, - "column": 17, - "index": 49 - }, - "end": { - "line": 3, - "column": 27, - "index": 59 - } - } - }, - { - "type": "FieldDefinition", - "name": { - "type": "Identifier", - "value": "message", - "loc": { - "start": { - "line": 4, - "column": 33, - "index": 92 - }, - "end": { - "line": 4, - "column": 40, - "index": 99 - } - } - }, - "fieldID": { - "type": "FieldID", - "value": -2, - "loc": { - "start": { - "line": 0, - "column": 0, - "index": 0 - }, - "end": { - "line": 0, - "column": 0, - "index": 0 - } - } - }, - "fieldType": { - "type": "StringKeyword", - "loc": { - "start": { - "line": 4, - "column": 26, - "index": 85 - }, - "end": { - "line": 4, - "column": 32, - "index": 91 - } - } - }, - "requiredness": "required", - "defaultValue": null, - "comments": [], - "loc": { - "start": { - "line": 4, - "column": 17, - "index": 76 - }, - "end": { - "line": 4, - "column": 40, - "index": 99 - } - } - } - ], - "comments": [], - "loc": { - "start": { - "line": 2, - "column": 13, - "index": 13 - }, - "end": { - "line": 5, - "column": 14, - "index": 113 - } - } - } - ], - "errors": [] -} diff --git a/src/tests/unit/index.spec.ts b/src/tests/unit/index.spec.ts index 64af9526..4078cc17 100644 --- a/src/tests/unit/index.spec.ts +++ b/src/tests/unit/index.spec.ts @@ -2,41 +2,103 @@ import { assert } from 'chai' import * as fs from 'fs' import * as path from 'path' -import { generate, make } from '../../main/index' +import { + generate, + // make +} from '../../main/index' import { CompileTarget } from '../../main/types' -function readSolution(name: string, target: CompileTarget = 'apache'): string { - return fs.readFileSync( - path.join(__dirname, `./fixtures/${target}/${name}.solution.ts`), - 'utf-8', +interface IFileDetails { + name: string + content: string +} + +type FileList = Array + +type ZippedDetail = [IFileDetails, IFileDetails] + +type ZippedList = Array + +function readDir(dir: string): FileList { + return fs + .readdirSync(dir) + .filter((file) => file.endsWith('.ts')) + .map((name) => ({ + name, + content: fs.readFileSync(path.join(dir, name), 'utf-8'), + })) +} + +function zipResults(actual: FileList, expected: FileList): ZippedList { + return actual.reduce( + ( + acc: ZippedList, + next: IFileDetails, + currentIndex: number, + ): ZippedList => { + return [...acc, [next, expected[currentIndex]]] + }, + [], ) } -function readGenerated(name: string, location: string = 'generated'): string { - return fs.readFileSync( - path.join(__dirname, `./${location}/${name}/index.ts`), - 'utf-8', +// function readSolution( +// name: string, +// target: CompileTarget = 'thrift-server', +// ): string { +// return fs.readFileSync( +// path.join(__dirname, `./fixtures/${target}/${name}.solution.ts`), +// 'utf-8', +// ) +// } + +function readGenerated( + name: string, + target: CompileTarget = 'thrift-server', +): FileList { + return readDir( + path.join(__dirname, `./${target}/generated/com/test/${name}`), ) } function readGeneratedSolution( name: string, - location: string = 'generated', -): string { - const contents: string = fs.readFileSync( - path.join(__dirname, `./fixtures/${location}/${name}/index.ts`), - 'utf-8', + target: CompileTarget = 'thrift-server', + strictUnions: boolean = false, +): FileList { + const files: FileList = readDir( + path.join( + __dirname, + `./fixtures/${target}/${ + strictUnions ? 'generated-strict' : 'generated' + }/com/test/${name}`, + ), ) - return contents.replace('{{VERSION}}', process.env.npm_package_version!) + + return files.map(({ name: fileName, content }) => ({ + name: fileName, + content: content.replace( + '{{VERSION}}', + process.env.npm_package_version!, + ), + })) } describe('Thrift TypeScript Generator', () => { - describe('Thrift Server v2 Generated', () => { + const generatedTests: { [testName: string]: string } = { + operation: 'should correctly generate typedefs for includes', + common: 'should correctly generate a struct using includes', + exceptions: 'should correctly generate an exception using includes', + shared: 'should correctly generate a service', + calculator: 'should correctly generate a service using includes', + } + + describe('Thrift Server Generated', () => { before(() => { generate({ rootDir: __dirname, - outDir: 'generated', + outDir: 'thrift-server/generated', sourceDir: 'fixtures/thrift', target: 'thrift-server', files: [], @@ -44,108 +106,74 @@ describe('Thrift TypeScript Generator', () => { }) }) - it('should correctly generate typedefs for includes', () => { - const actual: string = readGenerated('operation') - const expected: string = readGeneratedSolution('operation') - assert.deepEqual(actual, expected) - }) - - it('should correctly generate a struct using includes', () => { - const actual: string = readGenerated('common') - const expected: string = readGeneratedSolution('common') - assert.deepEqual(actual, expected) - }) - - it('should correctly generate an exception using includes', () => { - const actual: string = readGenerated('exceptions') - const expected: string = readGeneratedSolution('exceptions') - assert.deepEqual(actual, expected) - }) + Object.keys(generatedTests).forEach((testName) => { + it(generatedTests[testName], () => { + const actual: FileList = readGenerated(testName) + const expected: FileList = readGeneratedSolution(testName) + const zipped: ZippedList = zipResults(actual, expected) - it('should correctly generate a service', () => { - const actual: string = readGenerated('shared') - const expected: string = readGeneratedSolution('shared') - assert.deepEqual(actual, expected) - }) - - it('should correctly generate a service using includes', () => { - const actual: string = readGenerated('calculator') - const expected: string = readGeneratedSolution('calculator') - assert.deepEqual(actual, expected) + zipped.forEach((next: ZippedDetail) => { + assert.deepEqual(next[0].content, next[1].content) + }) + }) }) }) - describe('Thrift Server v2 Generated w Strict Unions', () => { + describe('Thrift Server Generated w/ Strict Unions', () => { before(() => { generate({ rootDir: __dirname, - outDir: 'generated/strict-unions', + outDir: 'thrift-server/generated', sourceDir: 'fixtures/thrift', target: 'thrift-server', files: [], library: 'test-lib', strictUnions: true, - strictUnionsComplexNames: true, }) }) - it('should correctly generate typedefs for includes', () => { - const actual: string = readGenerated( - 'operation', - 'generated/strict-unions', - ) - const expected: string = readGeneratedSolution( - 'operation', - 'generated/strict-unions', - ) - assert.deepEqual(actual, expected) - }) - it('should correctly generate a struct using includes', () => { - const actual: string = readGenerated( - 'common', - 'generated/strict-unions', - ) - const expected: string = readGeneratedSolution( - 'common', - 'generated/strict-unions', - ) - assert.deepEqual(actual, expected) - }) + Object.keys(generatedTests).forEach((testName) => { + it(generatedTests[testName], () => { + const actual: FileList = readGenerated(testName) + const expected: FileList = readGeneratedSolution( + testName, + 'thrift-server', + true, + ) + const zipped: ZippedList = zipResults(actual, expected) - it('should correctly generate an exception using includes', () => { - const actual: string = readGenerated( - 'exceptions', - 'generated/strict-unions', - ) - const expected: string = readGeneratedSolution( - 'exceptions', - 'generated/strict-unions', - ) - assert.deepEqual(actual, expected) + zipped.forEach((next: ZippedDetail) => { + assert.deepEqual(next[0].content, next[1].content) + }) + }) }) + }) - it('should correctly generate a service', () => { - const actual: string = readGenerated( - 'shared', - 'generated/strict-unions', - ) - const expected: string = readGeneratedSolution( - 'shared', - 'generated/strict-unions', - ) - assert.deepEqual(actual, expected) + describe('Apache Generated', () => { + before(() => { + generate({ + rootDir: __dirname, + outDir: 'apache/generated', + sourceDir: 'fixtures/thrift', + target: 'apache', + files: [], + library: 'test-lib', + }) }) - it('should correctly generate a service using includes', () => { - const actual: string = readGenerated( - 'calculator', - 'generated/strict-unions', - ) - const expected: string = readGeneratedSolution( - 'calculator', - 'generated/strict-unions', - ) - assert.deepEqual(actual, expected) + Object.keys(generatedTests).forEach((testName) => { + it(generatedTests[testName], () => { + const actual: FileList = readGenerated(testName, 'apache') + const expected: FileList = readGeneratedSolution( + testName, + 'apache', + ) + const zipped: ZippedList = zipResults(actual, expected) + + zipped.forEach((next: ZippedDetail) => { + assert.deepEqual(next[0].content, next[1].content) + }) + }) }) }) @@ -222,10 +250,7 @@ describe('Thrift TypeScript Generator', () => { const map VALUE_MAP = { VALUE: 'world', 5: 'bar' } const list LIST_CONST = ['hello', 'world', 'foo', 'bar'] ` - const expected: string = readSolution( - 'complex_const', - 'thrift-server', - ) + const expected: string = readSolution('complex_const') const actual: string = make(content) assert.deepEqual(actual, expected) @@ -233,18 +258,15 @@ describe('Thrift TypeScript Generator', () => { it('should correctly generate a struct', () => { const content: string = ` - struct MyStruct { - 1: required i32 id = 45 - 2: required i64 bigID = 23948234 - 3: required string word - 4: optional double field1 - 5: optional binary blob = "binary" - } - ` - const expected: string = readSolution( - 'multi_field_struct', - 'thrift-server', - ) + struct MyStruct { + 1: required i32 id = 45 + 2: required i64 bigID = 23948234 + 3: required string word + 4: optional double field1 + 5: optional binary blob = "binary" + } + ` + const expected: string = readSolution('multi_field_struct') const actual: string = make(content) assert.deepEqual(actual, expected) @@ -254,10 +276,7 @@ describe('Thrift TypeScript Generator', () => { const content: string = ` struct MyStruct {} ` - const expected: string = readSolution( - 'empty_struct', - 'thrift-server', - ) + const expected: string = readSolution('empty_struct') const actual: string = make(content) assert.deepEqual(actual, expected) @@ -270,10 +289,7 @@ describe('Thrift TypeScript Generator', () => { 2: required i64 bigID = 23948234 } ( foo = "bar", two = "three", alone, dot.foo = "bar", dot.lonely ) ` - const expected: string = readSolution( - 'annotations_struct', - 'thrift-server', - ) + const expected: string = readSolution('annotations_struct') const actual: string = make(content) assert.deepEqual(actual, expected) @@ -291,10 +307,7 @@ describe('Thrift TypeScript Generator', () => { 2: required User user } ` - const expected: string = readSolution( - 'nested_struct', - 'thrift-server', - ) + const expected: string = readSolution('nested_struct') const actual: string = make(content) assert.deepEqual(actual, expected) @@ -318,10 +331,7 @@ describe('Thrift TypeScript Generator', () => { 8: required map i64KeyedMap } ` - const expected: string = readSolution( - 'complex_nested_struct', - 'thrift-server', - ) + const expected: string = readSolution('complex_nested_struct') const actual: string = make(content) assert.deepEqual(actual, expected) @@ -329,15 +339,12 @@ describe('Thrift TypeScript Generator', () => { it('should correctly generate a union', () => { const content: string = ` - union MyUnion { - 1: i32 field1 - 2: i64 field2 - } - ` - const expected: string = readSolution( - 'basic_union', - 'thrift-server', - ) + union MyUnion { + 1: string option1 + 2: i64 option2 + } + ` + const expected: string = readSolution('basic_union') const actual: string = make(content) assert.deepEqual(actual, expected) @@ -350,10 +357,7 @@ describe('Thrift TypeScript Generator', () => { 2: i64 field2 } ( foo = "bar", two = "three", alone, dot.foo = "bar", dot.lonely ) ` - const expected: string = readSolution( - 'annotations_union', - 'thrift-server', - ) + const expected: string = readSolution('annotations_union') const actual: string = make(content) assert.deepEqual(actual, expected) @@ -363,10 +367,7 @@ describe('Thrift TypeScript Generator', () => { const content: string = ` union MyUnion {} ` - const expected: string = readSolution( - 'empty_union', - 'thrift-server', - ) + const expected: string = readSolution('empty_union') const actual: string = make(content) assert.deepEqual(actual, expected) @@ -384,10 +385,7 @@ describe('Thrift TypeScript Generator', () => { 2: Option option } ` - const expected: string = readSolution( - 'nested_union', - 'thrift-server', - ) + const expected: string = readSolution('nested_union') const actual: string = make(content) assert.deepEqual(actual, expected) @@ -400,10 +398,7 @@ describe('Thrift TypeScript Generator', () => { 2: i32 code = 200 } ` - const expected: string = readSolution( - 'basic_exception', - 'thrift-server', - ) + const expected: string = readSolution('basic_exception') const actual: string = make(content) assert.deepEqual(actual, expected) @@ -416,10 +411,7 @@ describe('Thrift TypeScript Generator', () => { 2: i32 code = 200 } ( foo = "bar", two = "three", alone, dot.foo = "bar", dot.lonely ) ` - const expected: string = readSolution( - 'annotations_exception', - 'thrift-server', - ) + const expected: string = readSolution('annotations_exception') const actual: string = make(content) assert.deepEqual(actual, expected) @@ -432,10 +424,7 @@ describe('Thrift TypeScript Generator', () => { 2: i32 code } ` - const expected: string = readSolution( - 'required_field_exception', - 'thrift-server', - ) + const expected: string = readSolution('required_field_exception') const actual: string = make(content) assert.deepEqual(actual, expected) @@ -453,10 +442,7 @@ describe('Thrift TypeScript Generator', () => { 3: Code code } ` - const expected: string = readSolution( - 'nested_exception', - 'thrift-server', - ) + const expected: string = readSolution('nested_exception') const actual: string = make(content) assert.deepEqual(actual, expected) @@ -475,10 +461,7 @@ describe('Thrift TypeScript Generator', () => { void ping() } ` - const expected: string = readSolution( - 'basic_service', - 'thrift-server', - ) + const expected: string = readSolution('basic_service') const actual: string = make(content) assert.deepEqual(actual, expected) @@ -497,50 +480,7 @@ describe('Thrift TypeScript Generator', () => { void ping() } ( foo = "bar", two = "three", alone, dot.foo = "bar", dot.lonely ) ` - const expected: string = readSolution( - 'annotations_service', - 'thrift-server', - ) - const actual: string = make(content) - - assert.deepEqual(actual, expected) - }) - - it('should correctly generate a service that extends another service', () => { - const content: string = ` - service ParentService { - string ping(1: i32 status) - } - - service ChildService extends ParentService { - string peg(1: string name) - string pong(1: optional string name) - } - ` - const expected: string = readSolution( - 'extend_service', - 'thrift-server', - ) - const actual: string = make(content) - - assert.deepEqual(actual, expected) - }) - - it('should correctly generate a service that extends another service with annotations', () => { - const content: string = ` - service ParentService { - string ping(1: i32 status) ( foo = "bar", two = "three", lonely ) - } ( foo = "boo", two = "three", alone ) - - service ChildService extends ParentService { - string peg(1: string name) - string pong(1: optional string name) - } ( foo = "bar", four = "five", secured ) - ` - const expected: string = readSolution( - 'annotations_extend_service', - 'thrift-server', - ) + const expected: string = readSolution('annotations_service') const actual: string = make(content) assert.deepEqual(actual, expected) @@ -557,10 +497,7 @@ describe('Thrift TypeScript Generator', () => { i64 pong(1: optional Code code) } ` - const expected: string = readSolution( - 'i64_service', - 'thrift-server', - ) + const expected: string = readSolution('i64_service') const actual: string = make(content) assert.deepEqual(actual, expected) @@ -577,10 +514,7 @@ describe('Thrift TypeScript Generator', () => { string pong(1: optional string name) } ` - const expected: string = readSolution( - 'throws_service', - 'thrift-server', - ) + const expected: string = readSolution('throws_service') const actual: string = make(content) assert.deepEqual(actual, expected) @@ -605,10 +539,22 @@ describe('Thrift TypeScript Generator', () => { string peg(1: string name) throws (1: ServiceException exp, 2: AuthException authExp, 3: UnknownException unknownExp) } ` - const expected: string = readSolution( - 'throws_multi_service', - 'thrift-server', - ) + const expected: string = readSolution('throws_multi_service') + const actual: string = make(content) + + assert.deepEqual(actual, expected) + }) + + it('should resolve primitive typedefs', () => { + const content: string = ` + typedef i64 INT_64 + + service MyService { + void ping(1: INT_64 id) + } + ` + + const expected: string = readSolution('resolved_field_service') const actual: string = make(content) assert.deepEqual(actual, expected) @@ -624,8 +570,8 @@ describe('Thrift TypeScript Generator', () => { const map MAP_CONST = {'hello': 'world', 'foo': 'bar' } const list LIST_CONST = ['hello', 'world', 'foo', 'bar'] ` + const expected: string = readSolution('basic_const', 'apache') const actual: string = make(content, 'apache') - const expected: string = readSolution('basic_const') assert.deepEqual(actual, expected) }) @@ -634,7 +580,7 @@ describe('Thrift TypeScript Generator', () => { const content: string = ` typedef string name ` - const expected: string = readSolution('basic_typedef') + const expected: string = readSolution('basic_typedef', 'apache') const actual: string = make(content, 'apache') assert.deepEqual(actual, expected) @@ -649,7 +595,7 @@ describe('Thrift TypeScript Generator', () => { typedef MyEnum AnotherName ` - const expected: string = readSolution('enum_typedef') + const expected: string = readSolution('enum_typedef', 'apache') const actual: string = make(content, 'apache') assert.deepEqual(actual, expected) @@ -670,7 +616,7 @@ describe('Thrift TypeScript Generator', () => { const AnotherName WHAT = AnotherName.ONE ` - const expected: string = readSolution('complex_typedef') + const expected: string = readSolution('complex_typedef', 'apache') const actual: string = make(content, 'apache') assert.deepEqual(actual, expected) @@ -684,7 +630,7 @@ describe('Thrift TypeScript Generator', () => { THREE } ` - const expected: string = readSolution('basic_enum') + const expected: string = readSolution('basic_enum', 'apache') const actual: string = make(content, 'apache') assert.deepEqual(actual, expected) @@ -698,7 +644,10 @@ describe('Thrift TypeScript Generator', () => { THREE = 6 } ` - const expected: string = readSolution('field_initialized_enum') + const expected: string = readSolution( + 'field_initialized_enum', + 'apache', + ) const actual: string = make(content, 'apache') assert.deepEqual(actual, expected) @@ -714,7 +663,10 @@ describe('Thrift TypeScript Generator', () => { 5: optional binary blob = "binary" } ` - const expected: string = readSolution('multi_field_struct') + const expected: string = readSolution( + 'multi_field_struct', + 'apache', + ) const actual: string = make(content, 'apache') assert.deepEqual(actual, expected) @@ -727,7 +679,10 @@ describe('Thrift TypeScript Generator', () => { 2: string name } ` - const expected: string = readSolution('implicit_optional_struct') + const expected: string = readSolution( + 'implicit_optional_struct', + 'apache', + ) const actual: string = make(content, 'apache') assert.deepEqual(actual, expected) @@ -739,7 +694,7 @@ describe('Thrift TypeScript Generator', () => { 1: required map field1 } ` - const expected: string = readSolution('map_struct') + const expected: string = readSolution('map_struct', 'apache') const actual: string = make(content, 'apache') assert.deepEqual(actual, expected) @@ -751,7 +706,7 @@ describe('Thrift TypeScript Generator', () => { 1: required map> field1 } ` - const expected: string = readSolution('nested_map_struct') + const expected: string = readSolution('nested_map_struct', 'apache') const actual: string = make(content, 'apache') assert.deepEqual(actual, expected) @@ -763,7 +718,7 @@ describe('Thrift TypeScript Generator', () => { 1: required list field1 } ` - const expected: string = readSolution('list_struct') + const expected: string = readSolution('list_struct', 'apache') const actual: string = make(content, 'apache') assert.deepEqual(actual, expected) @@ -775,7 +730,10 @@ describe('Thrift TypeScript Generator', () => { 1: required list> field1 } ` - const expected: string = readSolution('nested_list_struct') + const expected: string = readSolution( + 'nested_list_struct', + 'apache', + ) const actual: string = make(content, 'apache') assert.deepEqual(actual, expected) @@ -787,7 +745,7 @@ describe('Thrift TypeScript Generator', () => { 1: required set field1 } ` - const expected: string = readSolution('set_struct') + const expected: string = readSolution('set_struct', 'apache') const actual: string = make(content, 'apache') assert.deepEqual(actual, expected) @@ -799,7 +757,7 @@ describe('Thrift TypeScript Generator', () => { 1: required set> field1 } ` - const expected: string = readSolution('nested_set_struct') + const expected: string = readSolution('nested_set_struct', 'apache') const actual: string = make(content, 'apache') assert.deepEqual(actual, expected) @@ -815,7 +773,7 @@ describe('Thrift TypeScript Generator', () => { 1: required OtherStruct field1 } ` - const expected: string = readSolution('return_id_struct') + const expected: string = readSolution('return_id_struct', 'apache') const actual: string = make(content, 'apache') assert.deepEqual(actual, expected) @@ -831,7 +789,10 @@ describe('Thrift TypeScript Generator', () => { 1: required set field1 } ` - const expected: string = readSolution('container_id_struct') + const expected: string = readSolution( + 'container_id_struct', + 'apache', + ) const actual: string = make(content, 'apache') assert.deepEqual(actual, expected) @@ -843,7 +804,7 @@ describe('Thrift TypeScript Generator', () => { 1: required string message } ` - const expected: string = readSolution('basic_exception') + const expected: string = readSolution('basic_exception', 'apache') const actual: string = make(content, 'apache') assert.deepEqual(actual, expected) @@ -856,7 +817,7 @@ describe('Thrift TypeScript Generator', () => { 2: string field2 } ` - const expected: string = readSolution('basic_union') + const expected: string = readSolution('basic_union', 'apache') const actual: string = make(content, 'apache') assert.deepEqual(actual, expected) @@ -869,7 +830,7 @@ describe('Thrift TypeScript Generator', () => { 2: list> field2 } ` - const expected: string = readSolution('nested_list_union') + const expected: string = readSolution('nested_list_union', 'apache') const actual: string = make(content, 'apache') assert.deepEqual(actual, expected) @@ -881,7 +842,7 @@ describe('Thrift TypeScript Generator', () => { void ping() } ` - const expected: string = readSolution('basic_service') + const expected: string = readSolution('basic_service', 'apache') const actual: string = make(content, 'apache') assert.deepEqual(actual, expected) @@ -893,7 +854,7 @@ describe('Thrift TypeScript Generator', () => { i64 add(1: i64 num1, 2: i64 num2) } ` - const expected: string = readSolution('i64_service') + const expected: string = readSolution('i64_service', 'apache') const actual: string = make(content, 'apache') assert.deepEqual(actual, expected) @@ -909,7 +870,7 @@ describe('Thrift TypeScript Generator', () => { void ping() throws (1: MyException exp) } ` - const expected: string = readSolution('throws_service') + const expected: string = readSolution('throws_service', 'apache') const actual: string = make(content, 'apache') assert.deepEqual(actual, expected) @@ -934,7 +895,10 @@ describe('Thrift TypeScript Generator', () => { string peg(1: string name) throws (1: ServiceException exp, 2: AuthException authExp, 3: UnknownException unknownExp) } ` - const expected: string = readSolution('throws_multi_service') + const expected: string = readSolution( + 'throws_multi_service', + 'apache', + ) const actual: string = make(content, 'apache') assert.deepEqual(actual, expected) @@ -950,23 +914,7 @@ describe('Thrift TypeScript Generator', () => { string ping(1: i32 status) throws (1: MyException exp) } ` - const expected: string = readSolution('return_service') - const actual: string = make(content, 'apache') - - assert.deepEqual(actual, expected) - }) - - it('should correctly generate a service that extends another service', () => { - const content: string = ` - service ParentService { - string ping(1: i32 status) - } - - service ChildService extends ParentService { - string peg(1: string name) - } - ` - const expected: string = readSolution('extend_service') + const expected: string = readSolution('return_service', 'apache') const actual: string = make(content, 'apache') assert.deepEqual(actual, expected) diff --git a/src/tests/unit/resolver.spec.ts b/src/tests/unit/resolver.spec.ts deleted file mode 100644 index fee0df83..00000000 --- a/src/tests/unit/resolver.spec.ts +++ /dev/null @@ -1,107 +0,0 @@ -import { assert } from 'chai' -import * as fs from 'fs' -import * as path from 'path' - -import { resolveFile } from '../../main/resolver' -import { parseThriftString } from '../../main/utils' - -import { DEFAULT_OPTIONS } from '../../main/options' -import { IParsedFile, IResolvedFile } from '../../main/types' - -function loadSolution(name: string): any { - return JSON.parse( - fs.readFileSync( - path.join(__dirname, `./fixtures/resolver/${name}.solution.json`), - 'utf-8', - ), - ) -} - -function objectify(thrift: any): any { - return JSON.parse(JSON.stringify(thrift)) -} - -describe('Thrift TypeScript Resolver', () => { - it('should find and resolve imported identifiers as types', () => { - const content: string = ` - include 'exception.thrift' - - service MyService { - void ping() throws (1: exception.MyException exp) - } - ` - const mockIncludeContent = ` - exception MyException { - 1: required string message - } - ` - const mockParsedFile: IParsedFile = { - name: 'test', - path: '', - source: '', - includes: [ - { - name: 'exception', - path: '', - source: '', - includes: [], - ast: parseThriftString(mockIncludeContent), - }, - ], - ast: parseThriftString(content), - } - const actual: IResolvedFile = resolveFile( - '', - mockParsedFile, - DEFAULT_OPTIONS, - ) - const expected: IResolvedFile = loadSolution('imported-id-types') - - assert.deepEqual( - objectify(actual.identifiers), - objectify(expected.identifiers), - ) - }) - - it('should find and resolve imported identifiers as values', () => { - const content: string = ` - include 'exception.thrift' - - struct MyStruct { - 1: exception.Status status = exception.Status.SUCCESS - } - ` - const mockIncludeContent: string = ` - enum Status { - SUCCESS, - FAILURE - } - ` - const mockParsedFile: IParsedFile = { - name: 'test', - path: '', - source: '', - includes: [ - { - name: 'exception', - path: '', - source: '', - includes: [], - ast: parseThriftString(mockIncludeContent), - }, - ], - ast: parseThriftString(content), - } - const actual: IResolvedFile = resolveFile( - '', - mockParsedFile, - DEFAULT_OPTIONS, - ) - const expected: IResolvedFile = loadSolution('imported-id-values') - - assert.deepEqual( - objectify(actual.identifiers), - objectify(expected.identifiers), - ) - }) -}) diff --git a/src/tests/unit/utils.spec.ts b/src/tests/unit/utils.spec.ts new file mode 100644 index 00000000..e039ad32 --- /dev/null +++ b/src/tests/unit/utils.spec.ts @@ -0,0 +1,19 @@ +// import { assert } from 'chai' + +// import * as Utils from '../../main/utils' +// import { ISourceFile } from '../../main/types' + +// describe('Utils', () => { +// describe('pathForFile', () => { +// it('should return empty string for empty path', async () => { +// const mockFile: ISourceFile = { +// name: '', +// path: '', +// fullPath: '', +// source: '', +// } + +// assert.equal(Utils.pathForFile(mockFile), '') +// }) +// }) +// }) diff --git a/src/tests/unit/validator.spec.ts b/src/tests/unit/validator.spec.ts deleted file mode 100644 index dcad1c4c..00000000 --- a/src/tests/unit/validator.spec.ts +++ /dev/null @@ -1,811 +0,0 @@ -import { assert } from 'chai' -import * as fs from 'fs' -import * as path from 'path' - -import { DEFAULT_OPTIONS } from '../../main/options' -import { resolveFile } from '../../main/resolver' -import { - ErrorType, - IParsedFile, - IResolvedFile, - IThriftError, -} from '../../main/types' -import { parseSource, parseThriftString } from '../../main/utils' -import { validateFile } from '../../main/validator' - -function loadSolution(name: string): any { - return JSON.parse( - fs.readFileSync( - path.join(__dirname, `./fixtures/validator/${name}.solution.json`), - 'utf-8', - ), - ) -} - -function objectify(thrift: any): any { - return JSON.parse(JSON.stringify(thrift)) -} - -describe('Thrift TypeScript Validator', () => { - it('should return error if oneway keyword is not followed by void type', () => { - const content: string = ` - service Test { - oneway string test() - } - ` - const parsedFile: IParsedFile = parseSource(content) - const resolvedFile: IResolvedFile = resolveFile( - '', - parsedFile, - DEFAULT_OPTIONS, - ) - const validatedFile: IResolvedFile = validateFile(resolvedFile) - const expected: Array = [ - { - type: ErrorType.ValidationError, - message: - 'Oneway function must have return type of void, instead found string', - loc: { - start: { - line: 3, - column: 24, - index: 51, - }, - end: { - line: 3, - column: 37, - index: 64, - }, - }, - }, - ] - - assert.deepEqual(validatedFile.errors, expected) - }) - - it('should not return error if oneway keyword is followed by void type', () => { - const content: string = ` - service Test { - oneway void test() - } - ` - const parsedFile: IParsedFile = parseSource(content) - const resolvedFile: IResolvedFile = resolveFile( - '', - parsedFile, - DEFAULT_OPTIONS, - ) - const validatedFile: IResolvedFile = validateFile(resolvedFile) - const expected: Array = [] - - assert.deepEqual(validatedFile.errors, expected) - }) - - it('should return an error if a service tries to extend a non-service', () => { - const content: string = ` - struct TestStruct { - 1: string field1; - } - - service ServiceOne extends TestStruct { - void ping() - } - ` - const parsedFile: IParsedFile = parseSource(content) - const resolvedFile: IResolvedFile = resolveFile( - '', - parsedFile, - DEFAULT_OPTIONS, - ) - const validatedFile: IResolvedFile = validateFile(resolvedFile) - const expected: Array = [ - { - type: ErrorType.ValidationError, - message: - 'Service type expected but found type StructDefinition', - loc: { - start: { - line: 6, - column: 32, - index: 113, - }, - end: { - line: 6, - column: 50, - index: 131, - }, - }, - }, - ] - - assert.deepEqual(validatedFile.errors, expected) - }) - - it('should not return an error if a service extends a service', () => { - const content: string = ` - service ServiceOne { - void sendMessage(1: string msg) - } - - service ServiceTwo extends ServiceOne { - void ping() - } - ` - const parsedFile: IParsedFile = parseSource(content) - const resolvedFile: IResolvedFile = resolveFile( - '', - parsedFile, - DEFAULT_OPTIONS, - ) - const validatedFile: IResolvedFile = validateFile(resolvedFile) - const expected: Array = [] - - assert.deepEqual(validatedFile.errors, expected) - }) - - it('should not return an error when using identifier as valid value', () => { - const content: string = ` - const i32 VALUE = 32 - const list TEST = [ VALUE ] - ` - const parsedFile: IParsedFile = parseSource(content) - const resolvedFile: IResolvedFile = resolveFile( - '', - parsedFile, - DEFAULT_OPTIONS, - ) - const validatedFile: IResolvedFile = validateFile(resolvedFile) - const expected: Array = [] - - assert.deepEqual(validatedFile.errors, expected) - }) - - it('should return an error if it finds incorrect list types', () => { - const content: string = ` - const list TEST = [ 32, 41, 65 ] - ` - const parsedFile: IParsedFile = parseSource(content) - const resolvedFile: IResolvedFile = resolveFile( - '', - parsedFile, - DEFAULT_OPTIONS, - ) - const validatedFile: IResolvedFile = validateFile(resolvedFile) - const expected: Array = [ - { - type: ErrorType.ValidationError, - message: 'Expected type string but found type number', - loc: { - start: { - line: 2, - column: 41, - index: 41, - }, - end: { - line: 2, - column: 43, - index: 43, - }, - }, - }, - ] - - assert.deepEqual(validatedFile.errors, expected) - }) - - it('should not return an error if it finds correct list types', () => { - const content: string = ` - const list TEST = [ 32, 41, 65 ] - ` - const parsedFile: IParsedFile = parseSource(content) - const resolvedFile: IResolvedFile = resolveFile( - '', - parsedFile, - DEFAULT_OPTIONS, - ) - const validatedFile: IResolvedFile = validateFile(resolvedFile) - const expected: Array = [] - - assert.deepEqual(validatedFile.errors, expected) - }) - - it('should return an error if it finds incorrect nested list types', () => { - const content: string = ` - const list> TEST = [ [ 32, 41, 65 ], [ 2, 3 ] ] - ` - const parsedFile: IParsedFile = parseSource(content) - const resolvedFile: IResolvedFile = resolveFile( - '', - parsedFile, - DEFAULT_OPTIONS, - ) - const validatedFile: IResolvedFile = validateFile(resolvedFile) - const expected: Array = [ - { - type: ErrorType.ValidationError, - message: 'Expected type string but found type number', - loc: { - start: { - line: 2, - column: 49, - index: 49, - }, - end: { - line: 2, - column: 51, - index: 51, - }, - }, - }, - ] - - assert.deepEqual(validatedFile.errors, expected) - }) - - it('should not return an error if it finds correct nested list types', () => { - const content: string = ` - const list> TEST = [ [ 32, 41, 65 ], [ 2, 3 ] ] - ` - const parsedFile: IParsedFile = parseSource(content) - const resolvedFile: IResolvedFile = resolveFile( - '', - parsedFile, - DEFAULT_OPTIONS, - ) - const validatedFile: IResolvedFile = validateFile(resolvedFile) - const expected: Array = [] - - assert.deepEqual(validatedFile.errors, expected) - }) - - it('should return an error if it finds incorrect set types', () => { - const content: string = ` - const set TEST = [ 32, 41, 65 ] - ` - const parsedFile: IParsedFile = parseSource(content) - const resolvedFile: IResolvedFile = resolveFile( - '', - parsedFile, - DEFAULT_OPTIONS, - ) - const validatedFile: IResolvedFile = validateFile(resolvedFile) - const expected: Array = [ - { - type: ErrorType.ValidationError, - message: 'Expected type string but found type number', - loc: { - start: { - line: 2, - column: 40, - index: 40, - }, - end: { - line: 2, - column: 42, - index: 42, - }, - }, - }, - ] - - assert.deepEqual(validatedFile.errors, expected) - }) - - it('should not return an error if it finds correct set types', () => { - const content: string = ` - const set TEST = [ 32, 41, 65 ] - ` - const parsedFile: IParsedFile = parseSource(content) - const resolvedFile: IResolvedFile = resolveFile( - '', - parsedFile, - DEFAULT_OPTIONS, - ) - const validatedFile: IResolvedFile = validateFile(resolvedFile) - const expected: Array = [] - - assert.deepEqual(validatedFile.errors, expected) - }) - - it('should return an error if it finds incorrect map types', () => { - const content: string = ` - const map TEST = { 'one': 1, 'two': 2 } - ` - const parsedFile: IParsedFile = parseSource(content) - const resolvedFile: IResolvedFile = resolveFile( - '', - parsedFile, - DEFAULT_OPTIONS, - ) - const validatedFile: IResolvedFile = validateFile(resolvedFile) - const expected: Array = [ - { - type: ErrorType.ValidationError, - message: 'Expected type string but found type number', - loc: { - start: { - line: 2, - column: 54, - index: 54, - }, - end: { - line: 2, - column: 55, - index: 55, - }, - }, - }, - ] - - assert.deepEqual(validatedFile.errors, expected) - }) - - it('should not return an error if it finds correct map types', () => { - const content: string = ` - const map TEST = { 'one': 'value one', 'two': 'value two' } - ` - const parsedFile: IParsedFile = parseSource(content) - const resolvedFile: IResolvedFile = resolveFile( - '', - parsedFile, - DEFAULT_OPTIONS, - ) - const validatedFile: IResolvedFile = validateFile(resolvedFile) - const expected: Array = [] - - assert.deepEqual(validatedFile.errors, expected) - }) - - it('should return an error if it finds incorrect nested map types', () => { - const content: string = ` - const map> TEST = { 'one': { 'a': 1 }, 'two': { 'b': 4 } } - ` - const parsedFile: IParsedFile = parseSource(content) - const resolvedFile: IResolvedFile = resolveFile( - '', - parsedFile, - DEFAULT_OPTIONS, - ) - const validatedFile: IResolvedFile = validateFile(resolvedFile) - const expected: Array = [ - { - type: ErrorType.ValidationError, - message: 'Expected type string but found type number', - loc: { - start: { - line: 2, - column: 73, - index: 73, - }, - end: { - line: 2, - column: 74, - index: 74, - }, - }, - }, - ] - - assert.deepEqual(validatedFile.errors, expected) - }) - - it('should not return an error if it finds correct nested map types', () => { - const content: string = ` - const map> TEST = { 'one': { 'a': 'blah' }, 'two': { 'b': 'blam' } } - ` - const parsedFile: IParsedFile = parseSource(content) - const resolvedFile: IResolvedFile = resolveFile( - '', - parsedFile, - DEFAULT_OPTIONS, - ) - const validatedFile: IResolvedFile = validateFile(resolvedFile) - const expected: Array = [] - - assert.deepEqual(validatedFile.errors, expected) - }) - - it('should return an error if it finds duplicate field IDs', () => { - const content: string = ` - struct TestStruct { - 1: i32 field1 - 1: string field2 - } - ` - const parsedFile: IParsedFile = parseSource(content) - const resolvedFile: IResolvedFile = resolveFile( - '', - parsedFile, - DEFAULT_OPTIONS, - ) - const validatedFile: IResolvedFile = validateFile(resolvedFile) - const expected: Array = [ - { - type: ErrorType.ValidationError, - message: 'Found duplicate usage of fieldID: 1', - loc: { - start: { - line: 4, - column: 17, - index: 79, - }, - end: { - line: 4, - column: 19, - index: 81, - }, - }, - }, - ] - - assert.deepEqual(validatedFile.errors, expected) - }) - - it('should return an error if unable to resolve type of identifier', () => { - const content: string = ` - struct TestStruct { - 1: i32 test = status.Status.SUCCESS - } - ` - const parsedFile: IParsedFile = parseSource(content) - const resolvedFile: IResolvedFile = resolveFile( - '', - parsedFile, - DEFAULT_OPTIONS, - ) - const validatedFile: IResolvedFile = validateFile(resolvedFile) - const expected: Array = [ - { - type: ErrorType.ValidationError, - message: - 'Expected type number but found type status.Status.SUCCESS', - loc: { - start: { - line: 3, - column: 31, - index: 63, - }, - end: { - line: 3, - column: 52, - index: 84, - }, - }, - }, - ] - - assert.deepEqual(validatedFile.errors, expected) - }) - - it('should not return an error if assigning an int to and int field', () => { - const content: string = ` - struct TestStruct { - 1: i32 test = 45 - } - ` - const parsedFile: IParsedFile = parseSource(content) - const resolvedFile: IResolvedFile = resolveFile( - '', - parsedFile, - DEFAULT_OPTIONS, - ) - const validatedFile: IResolvedFile = validateFile(resolvedFile) - const expected: Array = [] - - assert.deepEqual(validatedFile.errors, expected) - }) - - it('should return an error if assigning a string to an int field', () => { - const content: string = ` - struct TestStruct { - 1: i32 test = 'whoa' - } - ` - const parsedFile: IParsedFile = parseSource(content) - const resolvedFile: IResolvedFile = resolveFile( - '', - parsedFile, - DEFAULT_OPTIONS, - ) - const validatedFile: IResolvedFile = validateFile(resolvedFile) - const expected: Array = [ - { - type: ErrorType.ValidationError, - message: 'Expected type number but found type string', - loc: { - start: { - line: 3, - column: 31, - index: 63, - }, - end: { - line: 3, - column: 37, - index: 69, - }, - }, - }, - ] - - assert.deepEqual(validatedFile.errors, expected) - }) - - it('should return an error when assigning an enum member to i32 field', () => { - const content: string = ` - enum Status { - SUCCESS, - FAILURE - } - - struct TestStruct { - 1: i32 test = Status.SUCCESS - } - ` - const parsedFile: IParsedFile = parseSource(content) - const resolvedFile: IResolvedFile = resolveFile( - '', - parsedFile, - DEFAULT_OPTIONS, - ) - const validatedFile: IResolvedFile = validateFile(resolvedFile) - const expected: Array = [ - { - type: ErrorType.ValidationError, - message: 'Expected type number but found type Status.SUCCESS', - loc: { - start: { - line: 8, - column: 31, - index: 153, - }, - end: { - line: 8, - column: 45, - index: 167, - }, - }, - }, - ] - - assert.deepEqual(validatedFile.errors, expected) - }) - - it('should not return an error if assigning valid int to enum type', () => { - const content: string = ` - enum TestEnum { - ONE, - TWO, - THREE - } - - const TestEnum test = 1 - ` - const parsedFile: IParsedFile = parseSource(content) - const resolvedFile: IResolvedFile = resolveFile( - '', - parsedFile, - DEFAULT_OPTIONS, - ) - const validatedFile: IResolvedFile = validateFile(resolvedFile) - const expected: Array = [] - - assert.deepEqual(validatedFile.errors, expected) - }) - - it('should return an error if assigning to enum out of range', () => { - const content: string = ` - enum TestEnum { - ONE, - TWO, - THREE - } - - const TestEnum test = 6 - ` - const parsedFile: IParsedFile = parseSource(content) - const resolvedFile: IResolvedFile = resolveFile( - '', - parsedFile, - DEFAULT_OPTIONS, - ) - const validatedFile: IResolvedFile = validateFile(resolvedFile) - const expected: Array = [ - { - type: ErrorType.ValidationError, - message: 'The value 6 is not assignable to type TestEnum', - loc: { - start: { - line: 8, - column: 35, - index: 142, - }, - end: { - line: 8, - column: 36, - index: 143, - }, - }, - }, - ] - - assert.deepEqual(validatedFile.errors, expected) - }) - - it('should add missing field IDs', () => { - const content: string = ` - struct TestStruct { - i32 status - required string message - } - ` - const parsedFile: IParsedFile = parseSource(content) - const resolvedFile: IResolvedFile = resolveFile( - '', - parsedFile, - DEFAULT_OPTIONS, - ) - const validatedFile: IResolvedFile = validateFile(resolvedFile) - const expected: IResolvedFile = loadSolution('missing-ids') - - assert.deepEqual( - objectify(validatedFile.identifiers), - expected.identifiers, - ) - }) - - it('should validate types for includes', () => { - const content: string = ` - include 'exception.thrift' - - exception MyException { - 1: exception.Status status = exception.Status.SUCCESS; - } - ` - const mockIncludeContent: string = ` - enum Status { - SUCCESS, - FAILURE - } - ` - const parsedFile: IParsedFile = { - name: '', - path: '', - source: ` - include 'exception.thrift' - - exception MyException { - 1: exception.Status status = exception.Status.SUCCESS; - } - `, - includes: [ - { - name: 'exception', - path: '', - source: '', - includes: [], - ast: parseThriftString(mockIncludeContent), - }, - ], - ast: parseThriftString(content), - } - const resolvedFile: IResolvedFile = resolveFile( - '', - parsedFile, - DEFAULT_OPTIONS, - ) - const validatedFile: IResolvedFile = validateFile(resolvedFile) - const expected: IResolvedFile = loadSolution('include-types') - - assert.deepEqual( - objectify(validatedFile.identifiers), - expected.identifiers, - ) - }) - - it('should not return an error if assigning an int with value 0 or 1 to a bool field', () => { - const content: string = ` - struct TestStruct { - 1: bool testFalse = 0 - 2: bool testTrue = 1 - } - ` - const parsedFile: IParsedFile = parseSource(content) - const resolvedFile: IResolvedFile = resolveFile( - '', - parsedFile, - DEFAULT_OPTIONS, - ) - const validatedFile: IResolvedFile = validateFile(resolvedFile) - const expected: Array = [] - - assert.deepEqual(validatedFile.errors, expected) - }) - - it('should return an error if assigning an int with value not 0 or 1 to a bool field', () => { - const content: string = ` - struct TestStruct { - 1: bool test = 2 - } - ` - const parsedFile: IParsedFile = parseSource(content) - const resolvedFile: IResolvedFile = resolveFile( - '', - parsedFile, - DEFAULT_OPTIONS, - ) - const validatedFile: IResolvedFile = validateFile(resolvedFile) - const expected: Array = [ - { - type: ErrorType.ValidationError, - message: 'Expected type boolean but found type number', - loc: { - start: { - line: 3, - column: 32, - index: 64, - }, - end: { - line: 3, - column: 33, - index: 65, - }, - }, - }, - ] - - assert.deepEqual(validatedFile.errors, expected) - }) - - it('should not return an error if assigning a binary to a string', () => { - const content: string = ` - struct TestStruct { - 1: binary blob = "test" - } - ` - const parsedFile: IParsedFile = parseSource(content) - const resolvedFile: IResolvedFile = resolveFile( - '', - parsedFile, - DEFAULT_OPTIONS, - ) - const validatedFile: IResolvedFile = validateFile(resolvedFile) - const expected: Array = [] - - assert.deepEqual(validatedFile.errors, expected) - }) - - it('should return an error if assigning a binary to a number', () => { - const content: string = ` - struct TestStruct { - 1: binary blob = 1 - } - ` - const parsedFile: IParsedFile = parseSource(content) - const resolvedFile: IResolvedFile = resolveFile( - '', - parsedFile, - DEFAULT_OPTIONS, - ) - const validatedFile: IResolvedFile = validateFile(resolvedFile) - const expected: Array = [ - { - type: ErrorType.ValidationError, - message: 'Expected type string but found type number', - loc: { - start: { - line: 3, - column: 34, - index: 66, - }, - end: { - line: 3, - column: 35, - index: 67, - }, - }, - }, - ] - - assert.deepEqual(validatedFile.errors, expected) - }) -})