├── .circleci └── config.yml ├── .editorconfig ├── .gitignore ├── .prettierignore ├── .prettierrc ├── .vscode └── settings.json ├── CHANGELOG.md ├── LICENSE ├── README.md ├── mocha.cover.opts ├── mocha.integration.opts ├── mocha.opts ├── package-lock.json ├── package.json ├── src ├── main │ ├── bin │ │ ├── index.ts │ │ └── resolveOptions.ts │ ├── debugger │ │ └── index.ts │ ├── defaults.ts │ ├── errors.ts │ ├── generator │ │ ├── index.ts │ │ └── iterator.ts │ ├── index.ts │ ├── options.ts │ ├── parser │ │ └── index.ts │ ├── printer.ts │ ├── reader │ │ └── index.ts │ ├── render │ │ ├── apache │ │ │ ├── const.ts │ │ │ ├── enum.ts │ │ │ ├── exception.ts │ │ │ ├── identifiers.ts │ │ │ ├── includes.ts │ │ │ ├── index.ts │ │ │ ├── interface.ts │ │ │ ├── service │ │ │ │ ├── client.ts │ │ │ │ ├── index.ts │ │ │ │ ├── processor.ts │ │ │ │ ├── types.ts │ │ │ │ └── utils.ts │ │ │ ├── struct │ │ │ │ ├── create.ts │ │ │ │ ├── index.ts │ │ │ │ ├── methods.ts │ │ │ │ ├── read.ts │ │ │ │ └── write.ts │ │ │ ├── typedef.ts │ │ │ ├── types.ts │ │ │ ├── union.ts │ │ │ ├── utils.ts │ │ │ └── values.ts │ │ ├── index.ts │ │ ├── shared │ │ │ ├── identifiers.ts │ │ │ ├── includes.ts │ │ │ ├── index.ts │ │ │ ├── service │ │ │ │ └── index.ts │ │ │ ├── types.ts │ │ │ └── utils.ts │ │ └── thrift-server │ │ │ ├── annotations.ts │ │ │ ├── const.ts │ │ │ ├── enum.ts │ │ │ ├── exception │ │ │ └── index.ts │ │ │ ├── identifiers.ts │ │ │ ├── index.ts │ │ │ ├── initializers.ts │ │ │ ├── service │ │ │ ├── client.ts │ │ │ ├── index.ts │ │ │ ├── processor.ts │ │ │ ├── types.ts │ │ │ └── utils.ts │ │ │ ├── struct │ │ │ ├── class.ts │ │ │ ├── decode.ts │ │ │ ├── encode.ts │ │ │ ├── index.ts │ │ │ ├── interface.ts │ │ │ ├── methods.ts │ │ │ ├── reader.ts │ │ │ ├── toolkit.ts │ │ │ └── utils.ts │ │ │ ├── typedef.ts │ │ │ ├── types.ts │ │ │ ├── union │ │ │ ├── class.ts │ │ │ ├── create.ts │ │ │ ├── decode.ts │ │ │ ├── encode.ts │ │ │ ├── index.ts │ │ │ ├── toolkit.ts │ │ │ ├── union-fields.ts │ │ │ └── utils.ts │ │ │ └── utils.ts │ ├── resolver │ │ ├── exportsForFile.ts │ │ ├── identifiersForStatements.ts │ │ ├── includesForFile.ts │ │ ├── index.ts │ │ ├── namespaceForFile.ts │ │ ├── namespaceForInclude.ts │ │ ├── organizeByNamespace.ts │ │ ├── resolveConstValue.ts │ │ ├── resolveIdentifierDefinition.ts │ │ ├── resolveIdentifierName.ts │ │ └── resolveNamespace.ts │ ├── sys.ts │ ├── types.ts │ ├── utils.ts │ └── validator │ │ ├── index.ts │ │ └── utils.ts └── tests │ ├── integration │ ├── apache │ │ ├── add-service.ts │ │ ├── calculator-service.ts │ │ ├── config.ts │ │ └── index.spec.ts │ └── thrift │ │ ├── add-service.thrift │ │ ├── calculator.thrift │ │ ├── common │ │ └── common.thrift │ │ ├── exceptions.thrift │ │ ├── operation.thrift │ │ ├── shared.thrift │ │ └── user.thrift │ └── unit │ ├── fixtures │ ├── apache │ │ ├── basic_const.solution.ts │ │ ├── basic_enum.solution.ts │ │ ├── basic_exception.solution.ts │ │ ├── basic_service.solution.ts │ │ ├── basic_typedef.solution.ts │ │ ├── basic_union.solution.ts │ │ ├── complex_typedef.solution.ts │ │ ├── container_id_struct.solution.ts │ │ ├── enum_typedef.solution.ts │ │ ├── field_initialized_enum.solution.ts │ │ ├── generated │ │ │ ├── Code.ts │ │ │ ├── SharedEnum.ts │ │ │ ├── SharedService.ts │ │ │ ├── SharedServiceBase.ts │ │ │ ├── SharedStruct.ts │ │ │ ├── SharedUnion.ts │ │ │ ├── com │ │ │ │ └── test │ │ │ │ │ ├── calculator │ │ │ │ │ ├── Calculator.ts │ │ │ │ │ ├── Choice.ts │ │ │ │ │ ├── CommonStruct.ts │ │ │ │ │ ├── FirstName.ts │ │ │ │ │ ├── LastName.ts │ │ │ │ │ ├── MyInteger.ts │ │ │ │ │ ├── NotAGoodIdea.ts │ │ │ │ │ ├── Operation.ts │ │ │ │ │ ├── TypedMap.ts │ │ │ │ │ ├── Work.ts │ │ │ │ │ ├── constants.ts │ │ │ │ │ └── index.ts │ │ │ │ │ ├── common │ │ │ │ │ ├── AuthException.ts │ │ │ │ │ ├── COMMON_INT.ts │ │ │ │ │ ├── CommonEnum.ts │ │ │ │ │ ├── CommonStruct.ts │ │ │ │ │ ├── CommonUnion.ts │ │ │ │ │ ├── MoreOptions.ts │ │ │ │ │ ├── NotAllowed.ts │ │ │ │ │ ├── OtherCommonUnion.ts │ │ │ │ │ └── index.ts │ │ │ │ │ ├── exceptions │ │ │ │ │ ├── InvalidOperation.ts │ │ │ │ │ ├── InvalidResult.ts │ │ │ │ │ └── index.ts │ │ │ │ │ └── operation │ │ │ │ │ ├── JankyOperation.ts │ │ │ │ │ ├── JankyResult.ts │ │ │ │ │ ├── Operation.ts │ │ │ │ │ ├── SomethingToDo.ts │ │ │ │ │ └── index.ts │ │ │ ├── constants.ts │ │ │ └── index.ts │ │ ├── i64_service.solution.ts │ │ ├── implicit_optional_struct.solution.ts │ │ ├── list_struct.solution.ts │ │ ├── map_struct.solution.ts │ │ ├── multi_field_struct.solution.ts │ │ ├── nested_list_struct.solution.ts │ │ ├── nested_list_union.solution.ts │ │ ├── nested_map_struct.solution.ts │ │ ├── nested_set_struct.solution.ts │ │ ├── return_id_struct.solution.ts │ │ ├── return_service.solution.ts │ │ ├── set_struct.solution.ts │ │ ├── throws_multi_service.solution.ts │ │ └── throws_service.solution.ts │ ├── thrift-server │ │ ├── annotations_exception.solution.ts │ │ ├── annotations_service.solution.ts │ │ ├── annotations_struct.solution.ts │ │ ├── annotations_union.solution.ts │ │ ├── basic_exception.solution.ts │ │ ├── basic_service.solution.ts │ │ ├── basic_service.strict_union.solution.ts │ │ ├── basic_struct.no_name.solution.ts │ │ ├── basic_struct.solution.ts │ │ ├── basic_typedef.solution.ts │ │ ├── basic_union.no_name.solution.ts │ │ ├── basic_union.solution.ts │ │ ├── basic_union.strict_union.solution.ts │ │ ├── complex_const.solution.ts │ │ ├── complex_nested_struct.solution.ts │ │ ├── complex_typedef.solution.ts │ │ ├── complex_typedef.strict_union.solution.ts │ │ ├── empty_struct.solution.ts │ │ ├── empty_union.solution.ts │ │ ├── generated-strict │ │ │ ├── Code.ts │ │ │ ├── SharedEnum.ts │ │ │ ├── SharedService.ts │ │ │ ├── SharedServiceBase.ts │ │ │ ├── SharedStruct.ts │ │ │ ├── SharedUnion.ts │ │ │ ├── com │ │ │ │ └── test │ │ │ │ │ ├── calculator │ │ │ │ │ ├── Calculator.ts │ │ │ │ │ ├── Choice.ts │ │ │ │ │ ├── CommonStruct.ts │ │ │ │ │ ├── FirstName.ts │ │ │ │ │ ├── LastName.ts │ │ │ │ │ ├── MyInteger.ts │ │ │ │ │ ├── NotAGoodIdea.ts │ │ │ │ │ ├── Operation.ts │ │ │ │ │ ├── TypedMap.ts │ │ │ │ │ ├── Work.ts │ │ │ │ │ ├── constants.ts │ │ │ │ │ └── index.ts │ │ │ │ │ ├── common │ │ │ │ │ ├── AuthException.ts │ │ │ │ │ ├── COMMON_INT.ts │ │ │ │ │ ├── CommonEnum.ts │ │ │ │ │ ├── CommonStruct.ts │ │ │ │ │ ├── CommonUnion.ts │ │ │ │ │ ├── MoreOptions.ts │ │ │ │ │ ├── NotAllowed.ts │ │ │ │ │ ├── OtherCommonUnion.ts │ │ │ │ │ └── index.ts │ │ │ │ │ ├── exceptions │ │ │ │ │ ├── InvalidOperation.ts │ │ │ │ │ ├── InvalidResult.ts │ │ │ │ │ └── index.ts │ │ │ │ │ └── operation │ │ │ │ │ ├── JankyOperation.ts │ │ │ │ │ ├── JankyResult.ts │ │ │ │ │ ├── Operation.ts │ │ │ │ │ ├── SomethingToDo.ts │ │ │ │ │ └── index.ts │ │ │ ├── constants.ts │ │ │ └── index.ts │ │ ├── generated │ │ │ ├── Code.ts │ │ │ ├── SharedEnum.ts │ │ │ ├── SharedService.ts │ │ │ ├── SharedServiceBase.ts │ │ │ ├── SharedStruct.ts │ │ │ ├── SharedUnion.ts │ │ │ ├── com │ │ │ │ └── test │ │ │ │ │ ├── calculator │ │ │ │ │ ├── Calculator.ts │ │ │ │ │ ├── Choice.ts │ │ │ │ │ ├── CommonStruct.ts │ │ │ │ │ ├── FirstName.ts │ │ │ │ │ ├── LastName.ts │ │ │ │ │ ├── MyInteger.ts │ │ │ │ │ ├── NotAGoodIdea.ts │ │ │ │ │ ├── Operation.ts │ │ │ │ │ ├── TypedMap.ts │ │ │ │ │ ├── Work.ts │ │ │ │ │ ├── constants.ts │ │ │ │ │ └── index.ts │ │ │ │ │ ├── common │ │ │ │ │ ├── AuthException.ts │ │ │ │ │ ├── COMMON_INT.ts │ │ │ │ │ ├── CommonEnum.ts │ │ │ │ │ ├── CommonStruct.ts │ │ │ │ │ ├── CommonUnion.ts │ │ │ │ │ ├── MoreOptions.ts │ │ │ │ │ ├── NotAllowed.ts │ │ │ │ │ ├── OtherCommonUnion.ts │ │ │ │ │ └── index.ts │ │ │ │ │ ├── exceptions │ │ │ │ │ ├── InvalidOperation.ts │ │ │ │ │ ├── InvalidResult.ts │ │ │ │ │ └── index.ts │ │ │ │ │ └── operation │ │ │ │ │ ├── JankyOperation.ts │ │ │ │ │ ├── JankyResult.ts │ │ │ │ │ ├── Operation.ts │ │ │ │ │ ├── SomethingToDo.ts │ │ │ │ │ └── index.ts │ │ │ ├── constants.ts │ │ │ └── index.ts │ │ ├── i64_service.solution.ts │ │ ├── initialized_union.solution.ts │ │ ├── initialized_union.strict_union.solution.ts │ │ ├── multi_field_struct.solution.ts │ │ ├── nested_exception.solution.ts │ │ ├── nested_struct.solution.ts │ │ ├── nested_union.solution.ts │ │ ├── nested_union.strict_union.solution.ts │ │ ├── required_field_exception.solution.ts │ │ ├── resolved_field_service.solution.ts │ │ ├── throws_multi_service.solution.ts │ │ └── throws_service.solution.ts │ └── thrift │ │ ├── calculator.thrift │ │ ├── common.thrift │ │ ├── exceptions.thrift │ │ ├── operation.thrift │ │ └── shared.thrift │ ├── index.spec.ts │ └── utils.spec.ts ├── tsconfig.json ├── tsconfig.test.json └── tslint.json /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | defaults: &defaults 2 | working_directory: ~/tmp 3 | docker: 4 | - image: circleci/node:8.9.4 5 | 6 | version: 2 7 | jobs: 8 | test_node_8: 9 | <<: *defaults 10 | steps: 11 | - checkout 12 | - run: 13 | name: Install NPM Dependencies 14 | command: npm install 15 | - run: 16 | name: Run Test Suite 17 | command: npm test 18 | - save_cache: 19 | key: dependency-cache-{{ checksum "package.json" }} 20 | paths: 21 | - ./node_modules 22 | 23 | test_node_10: 24 | <<: *defaults 25 | docker: 26 | - image: circleci/node:10.14.0 27 | steps: 28 | - checkout 29 | - run: 30 | name: Install NPM Dependencies 31 | command: npm install 32 | - run: 33 | name: Run Test Suite 34 | command: npm test 35 | - save_cache: 36 | key: dependency-cache-{{ checksum "package.json" }} 37 | paths: 38 | - ./node_modules 39 | 40 | publish: 41 | <<: *defaults 42 | steps: 43 | - checkout 44 | - run: 45 | name: Generate .npmrc File 46 | command: 'echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc' 47 | - run: 48 | name: Install NPM Dependencies 49 | command: npm install 50 | - run: 51 | name: Build Publish Assets 52 | command: npm run build 53 | - run: 54 | name: Publish to NPM 55 | command: npm publish --access public 56 | 57 | publish_next: 58 | <<: *defaults 59 | steps: 60 | - checkout 61 | - run: 62 | name: Generate .npmrc File 63 | command: 'echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc' 64 | - run: 65 | name: Install NPM Dependencies 66 | command: npm install 67 | - run: 68 | name: Build Publish Assets 69 | command: npm run build 70 | - run: 71 | name: Publish to NPM 72 | command: npm publish --tag next --access public 73 | 74 | workflows: 75 | version: 2 76 | build_publish: 77 | jobs: 78 | - test_node_8: 79 | filters: 80 | tags: 81 | only: /.*/ 82 | 83 | - test_node_10: 84 | filters: 85 | tags: 86 | only: /.*/ 87 | 88 | - publish: 89 | requires: 90 | - test_node_8 91 | - test_node_10 92 | filters: 93 | tags: 94 | only: /^(v){1}[0-9]+(\.[0-9]+){2}$/ 95 | branches: 96 | ignore: /.*/ 97 | 98 | - publish_next: 99 | requires: 100 | - test_node_8 101 | - test_node_10 102 | filters: 103 | tags: 104 | only: /^(v){1}[0-9]+(\.[0-9]+){2}(-)[0-9]+$/ 105 | branches: 106 | ignore: /.*/ 107 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | indent_size = 4 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Dependency directory 7 | node_modules 8 | 9 | # Optional npm cache directory 10 | .npm 11 | 12 | # Typescript artifacts 13 | dist 14 | 15 | # nyc artifacts 16 | coverage/ 17 | .nyc_output/ 18 | 19 | # Thrift test artifacts 20 | src/tests/integration/apache/codegen 21 | src/tests/integration/thrift-server/codegen 22 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | src/tests/unit/fixtures/**/*.ts 2 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "all", 3 | "tabWidth": 4, 4 | "semi": false, 5 | "singleQuote": true, 6 | "arrowParens": "always" 7 | } 8 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | // Place your settings in this file to overwrite default and user settings. 2 | { 3 | "editor.tabSize": 4, 4 | "editor.rulers": [110], 5 | "files.trimTrailingWhitespace": true, 6 | "files.insertFinalNewline": true, 7 | "editor.wordWrapColumn": 110, 8 | "editor.formatOnSave": false, 9 | "prettier.singleQuote": true, 10 | "prettier.printWidth": 110, 11 | "prettier.tabWidth": 4, 12 | "prettier.semi": false, 13 | "files.exclude": { 14 | "**/.DS_Store": true, 15 | "coverage": true, 16 | "coverage.lcov": true 17 | }, 18 | "typescript.tsdk": "node_modules/typescript/lib" 19 | -------------------------------------------------------------------------------- /mocha.cover.opts: -------------------------------------------------------------------------------- 1 | --require source-map-support/register 2 | --full-trace 3 | dist/tests/unit/**/*.spec.js 4 | -------------------------------------------------------------------------------- /mocha.integration.opts: -------------------------------------------------------------------------------- 1 | --full-trace 2 | --timeout 10000 3 | dist/tests/integration/**/*.spec.js 4 | -------------------------------------------------------------------------------- /mocha.opts: -------------------------------------------------------------------------------- 1 | --reporter spec 2 | --full-trace 3 | dist/tests/unit/**/*.spec.js 4 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@creditkarma/thrift-typescript", 3 | "version": "3.7.6", 4 | "description": "Generate TypeScript from Thrift IDL files", 5 | "main": "./dist/main/index.js", 6 | "types": "./dist/main/index.d.ts", 7 | "bin": { 8 | "thrift-typescript": "./dist/main/bin/index.js" 9 | }, 10 | "files": [ 11 | "dist/main" 12 | ], 13 | "scripts": { 14 | "clean": "rimraf ./dist ./**/codegen", 15 | "clean:all": "npm run clean && rimraf ./node_modules package-lock.json", 16 | "codegen": "node ./dist/main/bin/index.js --target apache --sourceDir ./src/tests/integration/thrift --outDir ./src/tests/integration/apache/codegen", 17 | "prebuild": "npm run clean && npm run lint && npm run format", 18 | "build": "npm run build:only", 19 | "build:only": "tsc", 20 | "prebuild:test": "npm run build && npm run codegen", 21 | "build:test": "npm run build:test:only", 22 | "build:test:only": "tsc -p tsconfig.test.json", 23 | "build:watch": "tsc --watch", 24 | "lint": "tslint --fix 'src/**/*.ts'", 25 | "format": "prettier --write 'src/**/*.ts'", 26 | "move:fixtures": "rimraf dist/tests/unit/fixtures && cp -r src/tests/unit/fixtures dist/tests/unit/fixtures", 27 | "pretest": "npm run build:test && npm run move:fixtures", 28 | "test": "npm run test:unit && npm run test:integration", 29 | "test:unit": "NODE_ENV=test mocha --opts mocha.opts", 30 | "test:integration": "NODE_ENV=test mocha --opts mocha.integration.opts" 31 | }, 32 | "keywords": [ 33 | "thrift", 34 | "typescript", 35 | "code generator", 36 | "rpc" 37 | ], 38 | "author": "Credit Karma", 39 | "license": "Apache-2.0", 40 | "repository": { 41 | "type": "git", 42 | "url": "https://github.com/creditkarma/thrift-typescript" 43 | }, 44 | "dependencies": { 45 | "@creditkarma/thrift-parser": "^1.2.0", 46 | "@types/fs-extra": "^7.0.0", 47 | "fs-extra": "^8.0.1", 48 | "glob": "^7.1.2", 49 | "typescript": "3.5.x" 50 | }, 51 | "devDependencies": { 52 | "@types/chai": "^4.1.5", 53 | "@types/glob": "^7.1.0", 54 | "@types/mocha": "^5.2.5", 55 | "@types/node": "^8.0.32", 56 | "@types/rimraf": "^2.0.2", 57 | "@types/thrift": "^0.10.7", 58 | "chai": "^4.2.0", 59 | "mocha": "^5.2.0", 60 | "prettier": "^1.17.0", 61 | "rimraf": "^2.6.2", 62 | "source-map-support": "^0.5.9", 63 | "thrift": "^0.11.0", 64 | "tslint": "^5.11.0", 65 | "tslint-config-prettier": "^1.17.0", 66 | "tslint-plugin-prettier": "^2.0.0" 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/bin/index.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | import { generate } from '../index' 3 | import { IMakeOptions } from '../types' 4 | import { resolveOptions } from './resolveOptions' 5 | 6 | const cliArgs: Array = process.argv.slice(2) 7 | const options: IMakeOptions = resolveOptions(cliArgs) 8 | 9 | generate(options) 10 | -------------------------------------------------------------------------------- /src/main/bin/resolveOptions.ts: -------------------------------------------------------------------------------- 1 | import { lstatSync } from 'fs' 2 | 3 | import { DEFAULT_OPTIONS, defaultLibrary } from '../defaults' 4 | import { IMakeOptions } from '../types' 5 | import { deepCopy, deepMerge } from '../utils' 6 | 7 | /** 8 | * Options: 9 | * 10 | * --rootDir 11 | * --outDir 12 | * --removeComments 13 | * --strictUnions 14 | * --fallbackNamespace 15 | * --library 16 | */ 17 | export function resolveOptions(args: Array): IMakeOptions { 18 | const len: number = args.length 19 | let index: number = 0 20 | const options: IMakeOptions = deepCopy(DEFAULT_OPTIONS) 21 | 22 | while (index < len) { 23 | const next: string = args[index] 24 | 25 | switch (next) { 26 | case '--rootDir': 27 | options.rootDir = args[index + 1] 28 | try { 29 | if (lstatSync(options.rootDir).isDirectory()) { 30 | index += 2 31 | break 32 | } else { 33 | throw new Error( 34 | `Provided root directory "${options.rootDir}" isn't a directory`, 35 | ) 36 | } 37 | } catch (e) { 38 | throw new Error( 39 | `Provided root directory "${options.rootDir}" doesn't exist`, 40 | ) 41 | } 42 | 43 | case '--sourceDir': 44 | options.sourceDir = args[index + 1] 45 | index += 2 46 | break 47 | 48 | case '--outDir': 49 | options.outDir = args[index + 1] 50 | index += 2 51 | break 52 | 53 | case '--target': 54 | const option = args[index + 1] 55 | if (option === 'apache' || option === 'thrift-server') { 56 | options.target = option 57 | } else { 58 | throw new Error(`Unsupported target: ${option}`) 59 | } 60 | index += 2 61 | break 62 | 63 | case '--library': 64 | options.library = args[index + 1] 65 | index += 2 66 | 67 | case '--fallbackNamespace': 68 | options.fallbackNamespace = args[index + 1] 69 | index += 2 70 | break 71 | 72 | case '--strictUnions': 73 | options.strictUnions = true 74 | index += 1 75 | break 76 | 77 | case '--strictUnionsComplexNames': 78 | options.strictUnionsComplexNames = true 79 | index += 1 80 | break 81 | 82 | case '--withNameField': 83 | options.withNameField = true 84 | index += 1 85 | break 86 | 87 | default: 88 | if (next.startsWith('--')) { 89 | throw new Error( 90 | `Unknown option provided to generator "${next}"`, 91 | ) 92 | } else { 93 | // Assume option is a file to render 94 | options.files.push(next) 95 | index += 1 96 | } 97 | } 98 | } 99 | 100 | return deepMerge(options, { 101 | library: defaultLibrary(options), 102 | }) 103 | } 104 | -------------------------------------------------------------------------------- /src/main/debugger/index.ts: -------------------------------------------------------------------------------- 1 | import { TextLocation } from '@creditkarma/thrift-parser' 2 | import * as os from 'os' 3 | 4 | import { ErrorType, IThriftError } from '../errors' 5 | import { INamespace, ISourceFile } from '../types' 6 | 7 | interface IErrorFile { 8 | sourceFile: ISourceFile 9 | errors: Array 10 | } 11 | 12 | interface IFormattedError { 13 | sourceLine: string 14 | locIndicator: string 15 | line: number 16 | column: number 17 | message: string 18 | type: ErrorType 19 | } 20 | 21 | function padLeft(num: number, str: string): string { 22 | while (str.length < num) { 23 | str = ' ' + str 24 | } 25 | return str 26 | } 27 | 28 | function indicatorForLocaction(loc: TextLocation): string { 29 | const indicator: string = padLeft(loc.start.column, '^') 30 | return indicator 31 | } 32 | 33 | function padStart(length: number, str: string): string { 34 | let paddedStr: string = str 35 | while (length--) { 36 | paddedStr = ' ' + paddedStr 37 | } 38 | 39 | return paddedStr 40 | } 41 | 42 | function errorType(type: ErrorType): string { 43 | switch (type) { 44 | case ErrorType.ValidationError: 45 | return 'Validation Error:' 46 | 47 | case ErrorType.ResolutionError: 48 | return 'Identifier Resolution Error:' 49 | 50 | case ErrorType.GenerationError: 51 | return 'Code Generation Error:' 52 | } 53 | } 54 | 55 | function printErrorForFile(file: T): void { 56 | const sourceLines: Array = file.sourceFile.source.split(os.EOL) 57 | const formattedErrors: Array = file.errors.map( 58 | (next: IThriftError): IFormattedError => { 59 | return formatError(next) 60 | }, 61 | ) 62 | 63 | function getSourceLine(lineNumber: number): string { 64 | return sourceLines[lineNumber - 1] 65 | } 66 | 67 | function formatError(err: IThriftError): IFormattedError { 68 | return { 69 | sourceLine: getSourceLine(err.loc.start.line), 70 | locIndicator: indicatorForLocaction(err.loc), 71 | line: err.loc.start.line, 72 | column: err.loc.start.column, 73 | message: err.message, 74 | type: err.type, 75 | } 76 | } 77 | 78 | console.log( 79 | `Error generating file '${file.sourceFile.path}/${file.sourceFile.name}.thrift': ${file.errors.length} errors found:`, 80 | ) 81 | formattedErrors.forEach((err: IFormattedError): void => { 82 | const prefix: string = `${err.line} | ` 83 | 84 | console.log() 85 | console.log(`${errorType(err.type)}\n`) 86 | console.log(`Message: ${err.message}`) 87 | console.log() 88 | console.log(`${prefix}${err.sourceLine}`) 89 | console.log(padStart(prefix.length, err.locIndicator)) 90 | console.log() 91 | }) 92 | } 93 | 94 | export function printErrorsForFiles( 95 | files: Array, 96 | ): void { 97 | files.forEach((next: T): void => { 98 | printErrorForFile(next) 99 | }) 100 | } 101 | 102 | export function printErrors(files: Array): void { 103 | files.forEach((next: INamespace) => { 104 | console.log( 105 | `Errors encountered while generating namesapce: ${next.namespace.name}`, 106 | ) 107 | console.log() 108 | next.errors.forEach((err: IThriftError) => { 109 | console.log(`Error: ${err.message}`) 110 | console.log() 111 | }) 112 | }) 113 | } 114 | 115 | export function collectInvalidFiles }>( 116 | resolvedFiles: Array, 117 | errors: Array = [], 118 | ): Array { 119 | for (const file of resolvedFiles) { 120 | if (file.errors.length > 0) { 121 | errors.push(file) 122 | } 123 | } 124 | 125 | return errors 126 | } 127 | -------------------------------------------------------------------------------- /src/main/defaults.ts: -------------------------------------------------------------------------------- 1 | import { IMakeOptions } from './types' 2 | import { deepMerge } from './utils' 3 | 4 | export const DEFAULT_APACHE_LIB = 'thrift' 5 | 6 | export const DEFAULT_THRIFT_SERVER_LIB = '@creditkarma/thrift-server-core' 7 | 8 | export const DEFAULT_OPTIONS: IMakeOptions = { 9 | rootDir: '.', 10 | outDir: './codegen', 11 | sourceDir: './thrift', 12 | target: 'apache', 13 | library: DEFAULT_APACHE_LIB, 14 | files: [], 15 | strictUnions: false, 16 | strictUnionsComplexNames: false, 17 | fallbackNamespace: 'java', 18 | withNameField: false, 19 | } 20 | 21 | export function defaultLibrary(options: Partial): string { 22 | if ( 23 | options.target === 'thrift-server' && 24 | (!options.library || options.library === DEFAULT_APACHE_LIB) 25 | ) { 26 | return DEFAULT_THRIFT_SERVER_LIB 27 | } else if (options.library) { 28 | return options.library 29 | } else { 30 | return DEFAULT_APACHE_LIB 31 | } 32 | } 33 | 34 | export function mergeWithDefaults( 35 | options: Partial, 36 | ): IMakeOptions { 37 | options.library = defaultLibrary(options) 38 | return deepMerge(DEFAULT_OPTIONS, options) 39 | } 40 | -------------------------------------------------------------------------------- /src/main/errors.ts: -------------------------------------------------------------------------------- 1 | import { TextLocation } from '@creditkarma/thrift-parser' 2 | import { emptyLocation } from './utils' 3 | 4 | export const enum ErrorType { 5 | ValidationError = 'ValidationError', 6 | ResolutionError = 'ResolutionError', 7 | GenerationError = 'GenerationError', 8 | } 9 | 10 | export interface IThriftError { 11 | type: ErrorType 12 | message: string 13 | loc: TextLocation 14 | } 15 | 16 | export class ValidationError extends Error { 17 | public message: string 18 | public loc: TextLocation 19 | constructor(msg: string, loc: TextLocation) { 20 | super(msg) 21 | this.message = msg 22 | this.loc = loc 23 | } 24 | } 25 | 26 | export function createValidationError( 27 | message: string, 28 | loc: TextLocation = emptyLocation(), 29 | ): IThriftError { 30 | return { 31 | type: ErrorType.ValidationError, 32 | message, 33 | loc, 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/generator/iterator.ts: -------------------------------------------------------------------------------- 1 | import * as ts from 'typescript' 2 | 3 | import { SyntaxType, ThriftStatement } from '@creditkarma/thrift-parser' 4 | 5 | import { IRenderer, IRenderState } from '../types' 6 | 7 | /** 8 | * Given a Thrift declaration return the corresponding TypeScript statement 9 | * 10 | * @param statement 11 | */ 12 | export function renderStatement( 13 | statement: ThriftStatement, 14 | state: IRenderState, 15 | renderer: IRenderer, 16 | ): Array { 17 | switch (statement.type) { 18 | case SyntaxType.ConstDefinition: 19 | return renderer.renderConst(statement, state) 20 | 21 | case SyntaxType.EnumDefinition: 22 | return renderer.renderEnum(statement, state) 23 | 24 | case SyntaxType.TypedefDefinition: 25 | return renderer.renderTypeDef(statement, state) 26 | 27 | case SyntaxType.StructDefinition: 28 | return renderer.renderStruct(statement, state) 29 | 30 | case SyntaxType.UnionDefinition: 31 | return renderer.renderUnion(statement, state) 32 | 33 | case SyntaxType.ExceptionDefinition: 34 | return renderer.renderException(statement, state) 35 | 36 | case SyntaxType.ServiceDefinition: 37 | return renderer.renderService(statement, state) 38 | 39 | case SyntaxType.NamespaceDefinition: 40 | case SyntaxType.CppIncludeDefinition: 41 | case SyntaxType.IncludeDefinition: 42 | return [] 43 | 44 | default: 45 | const msg: never = statement 46 | throw new Error(`Non-exhaustive match for statement: ${msg}`) 47 | } 48 | } 49 | 50 | /** 51 | * Our main iteration logic that visits each Thrift statement and calls a function to generate the 52 | * TypeScript statements for that Thrift statement. Usually this is a one to many mapping. 53 | * 54 | * @param ast 55 | */ 56 | export function processStatements( 57 | statements: Array, 58 | state: IRenderState, 59 | renderer: IRenderer, 60 | ): Array { 61 | return statements.reduce( 62 | (acc: Array, next: ThriftStatement) => { 63 | return [...acc, ...renderStatement(next, state, renderer)] 64 | }, 65 | [], 66 | ) 67 | } 68 | -------------------------------------------------------------------------------- /src/main/options.ts: -------------------------------------------------------------------------------- 1 | import { IMakeOptions } from './types' 2 | 3 | export const DEFAULT_OPTIONS: IMakeOptions = Object.freeze({ 4 | rootDir: '.', 5 | outDir: './codegen', 6 | sourceDir: './thrift', 7 | target: 'apache', 8 | files: (Object.freeze([]) as unknown) as Array, 9 | fallbackNamespace: 'java', 10 | library: '', 11 | } as IMakeOptions) 12 | -------------------------------------------------------------------------------- /src/main/parser/index.ts: -------------------------------------------------------------------------------- 1 | import { 2 | parse, 3 | SyntaxType, 4 | ThriftDocument, 5 | ThriftErrors, 6 | } from '@creditkarma/thrift-parser' 7 | 8 | import { 9 | IFileExports, 10 | IFileIncludes, 11 | INamespacePath, 12 | IParsedFile, 13 | ISourceFile, 14 | } from '../types' 15 | 16 | import { Resolver } from '../resolver' 17 | 18 | function parseThriftString(source: string): ThriftDocument { 19 | const thrift: ThriftDocument | ThriftErrors = parse(source) 20 | switch (thrift.type) { 21 | case SyntaxType.ThriftDocument: 22 | return thrift 23 | 24 | default: 25 | throw new Error('Unable to parse source: ') 26 | } 27 | } 28 | 29 | function parseFromSource( 30 | source: string, 31 | fallbackNamespace: string, 32 | ): IParsedFile { 33 | const sourceFile: ISourceFile = { 34 | type: 'SourceFile', 35 | name: '', 36 | path: '', 37 | fullPath: '', 38 | source, 39 | } 40 | 41 | return parseThriftFile(sourceFile, fallbackNamespace) 42 | } 43 | 44 | function parseThriftFile( 45 | file: ISourceFile, 46 | fallbackNamespace: string, 47 | ): IParsedFile { 48 | const thriftDoc: ThriftDocument = parseThriftString(file.source) 49 | 50 | const exports: IFileExports = Resolver.exportsForFile(thriftDoc.body) 51 | 52 | const namespace: INamespacePath = Resolver.namespaceForFile( 53 | thriftDoc.body, 54 | fallbackNamespace, 55 | ) 56 | 57 | const includes: IFileIncludes = Resolver.includesForFile( 58 | thriftDoc.body, 59 | file, 60 | ) 61 | 62 | return { 63 | type: 'ParsedFile', 64 | sourceFile: file, 65 | namespace, 66 | includes, 67 | exports, 68 | body: thriftDoc.body, 69 | errors: [], 70 | } 71 | } 72 | 73 | export const Parser = { 74 | parseFromSource, 75 | parseThriftString, 76 | parseThriftFile, 77 | } 78 | -------------------------------------------------------------------------------- /src/main/printer.ts: -------------------------------------------------------------------------------- 1 | import * as ts from 'typescript' 2 | const pkg = require('../../package.json') 3 | 4 | const tslintDisable: string = ' tslint:disable ' 5 | 6 | const eslintDisable: string = ' eslint-disable ' 7 | 8 | const prefaceComment: string = ` 9 | * Autogenerated by @creditkarma/thrift-typescript v${pkg.version} 10 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 11 | ` 12 | 13 | function generatePreface(req: ts.Statement): void { 14 | ts.addSyntheticLeadingComment( 15 | req, 16 | ts.SyntaxKind.MultiLineCommentTrivia, 17 | tslintDisable, 18 | true, 19 | ) 20 | 21 | ts.addSyntheticLeadingComment( 22 | req, 23 | ts.SyntaxKind.MultiLineCommentTrivia, 24 | eslintDisable, 25 | true, 26 | ) 27 | 28 | ts.addSyntheticLeadingComment( 29 | req, 30 | ts.SyntaxKind.MultiLineCommentTrivia, 31 | prefaceComment, 32 | true, 33 | ) 34 | } 35 | 36 | export function print( 37 | statements: Array, 38 | includePreface: boolean = false, 39 | ): string { 40 | const printer: ts.Printer = ts.createPrinter() 41 | const rawSourceFile: ts.SourceFile = ts.createSourceFile( 42 | 'thrift.ts', 43 | '', 44 | ts.ScriptTarget.ES2015, 45 | false, 46 | ts.ScriptKind.TS, 47 | ) 48 | 49 | const bodyFile: ts.SourceFile = ts.updateSourceFileNode( 50 | rawSourceFile, 51 | statements, 52 | ) 53 | 54 | if (includePreface && statements.length > 0) { 55 | generatePreface(statements[0]) 56 | } else { 57 | console.warn(`Printing empty file`) 58 | } 59 | 60 | return printer.printBundle(ts.createBundle([bodyFile])) 61 | } 62 | -------------------------------------------------------------------------------- /src/main/reader/index.ts: -------------------------------------------------------------------------------- 1 | import * as fs from 'fs' 2 | import * as path from 'path' 3 | import { ISourceFile } from '../types' 4 | 5 | export function readThriftFile( 6 | file: string, 7 | searchPaths: Array, 8 | ): ISourceFile { 9 | for (const sourcePath of searchPaths) { 10 | const filePath: string = path.resolve(sourcePath, file) 11 | if (fs.existsSync(filePath)) { 12 | return { 13 | type: 'SourceFile', 14 | name: path.basename(filePath, '.thrift'), 15 | path: path.dirname(filePath), 16 | fullPath: filePath, 17 | source: fs.readFileSync(filePath, 'utf-8'), 18 | } 19 | } 20 | } 21 | 22 | throw new Error(`Unable to find file ${file}`) 23 | } 24 | -------------------------------------------------------------------------------- /src/main/render/apache/const.ts: -------------------------------------------------------------------------------- 1 | import * as ts from 'typescript' 2 | 3 | import { ConstDefinition } from '@creditkarma/thrift-parser' 4 | 5 | import { TypeMapping } from './types' 6 | 7 | import { renderValue } from './values' 8 | 9 | import { IRenderState } from '../../types' 10 | import { createConst } from './utils' 11 | 12 | /** 13 | * EXAMPLE 14 | * 15 | * // thrift 16 | * const i32 myConst = 45 17 | * 18 | * // typescript 19 | * const myConst: number = 45 20 | */ 21 | export function renderConst( 22 | node: ConstDefinition, 23 | typeMapping: TypeMapping, 24 | state: IRenderState, 25 | ): ts.Statement { 26 | return ts.createVariableStatement( 27 | [ts.createToken(ts.SyntaxKind.ExportKeyword)], 28 | createConst( 29 | node.name.value, 30 | typeMapping(node.fieldType, state), 31 | renderValue(node.fieldType, node.initializer, state), 32 | ), 33 | ) 34 | } 35 | -------------------------------------------------------------------------------- /src/main/render/apache/enum.ts: -------------------------------------------------------------------------------- 1 | import * as ts from 'typescript' 2 | 3 | import { EnumDefinition, EnumMember } from '@creditkarma/thrift-parser' 4 | 5 | import { renderIntConstant } from './values' 6 | 7 | /** 8 | * EXAMPE 9 | * 10 | * // thrift 11 | * enum MyEnum { 12 | * ONE, 13 | * TWO 14 | * } 15 | * 16 | * // typescript 17 | * export enum MyEnum { 18 | * ONE, 19 | * TWO 20 | * } 21 | */ 22 | export function renderEnum(node: EnumDefinition): ts.Statement { 23 | return ts.createEnumDeclaration( 24 | undefined, // decorators 25 | [ts.createToken(ts.SyntaxKind.ExportKeyword)], // modifiers 26 | node.name.value, // enum name 27 | node.members.map((field: EnumMember) => { 28 | return ts.createEnumMember( 29 | field.name.value, 30 | field.initializer !== null 31 | ? renderIntConstant(field.initializer) 32 | : undefined, 33 | ) 34 | }), // enum members 35 | ) 36 | } 37 | -------------------------------------------------------------------------------- /src/main/render/apache/exception.ts: -------------------------------------------------------------------------------- 1 | import * as ts from 'typescript' 2 | 3 | import { ExceptionDefinition } from '@creditkarma/thrift-parser' 4 | 5 | import { IRenderState } from '../../types' 6 | import { renderStruct } from './struct' 7 | 8 | export function renderException( 9 | node: ExceptionDefinition, 10 | state: IRenderState, 11 | ): ts.ClassDeclaration { 12 | return renderStruct(node, state) 13 | } 14 | -------------------------------------------------------------------------------- /src/main/render/apache/includes.ts: -------------------------------------------------------------------------------- 1 | import * as ts from 'typescript' 2 | 3 | import { COMMON_IDENTIFIERS } from '../shared/identifiers' 4 | 5 | /** 6 | * import Int64 = require('node-int64'); 7 | * 8 | * Creates an import for Int64 type if it is being used by the file we're 9 | * generating. We'll need to keep track of what each files uses. 10 | */ 11 | export function renderInt64Import(): ts.ImportEqualsDeclaration { 12 | return ts.createImportEqualsDeclaration( 13 | undefined, 14 | undefined, 15 | COMMON_IDENTIFIERS.Node_Int64, 16 | ts.createExternalModuleReference(ts.createLiteral('node-int64')), 17 | ) 18 | } 19 | -------------------------------------------------------------------------------- /src/main/render/apache/index.ts: -------------------------------------------------------------------------------- 1 | import * as ts from 'typescript' 2 | 3 | import { 4 | ConstDefinition, 5 | EnumDefinition, 6 | ExceptionDefinition, 7 | ServiceDefinition, 8 | StructDefinition, 9 | ThriftStatement, 10 | TypedefDefinition, 11 | UnionDefinition, 12 | } from '@creditkarma/thrift-parser' 13 | 14 | import { renderException as _renderException } from './exception' 15 | 16 | import { renderInterface } from './interface' 17 | 18 | import { 19 | renderArgsStruct, 20 | renderClient, 21 | renderHandlerInterface, 22 | renderProcessor, 23 | renderResultStruct, 24 | } from './service' 25 | 26 | import { 27 | renderIncludes as _renderIncludes, 28 | renderThriftImports, 29 | statementsUseInt64, 30 | statementsUseThrift, 31 | } from '../shared/includes' 32 | import { renderConst as _renderConst } from './const' 33 | import { renderEnum as _renderEnum } from './enum' 34 | import { renderInt64Import } from './includes' 35 | import { renderStruct as _renderStruct } from './struct' 36 | import { renderTypeDef as _renderTypeDef } from './typedef' 37 | import { renderUnion as _renderUnion } from './union' 38 | 39 | import { IRenderer, IRenderState } from '../../types' 40 | import { renderIndex } from '../shared' 41 | import { typeNodeForFieldType } from './types' 42 | 43 | export function renderImports( 44 | statements: Array, 45 | state: IRenderState, 46 | ): Array { 47 | const includes: Array = [ 48 | ..._renderIncludes(statements, state), 49 | ] 50 | 51 | if (statementsUseThrift(statements)) { 52 | includes.unshift(renderThriftImports(state.options.library)) 53 | } 54 | 55 | if (statementsUseInt64(statements)) { 56 | includes.unshift(renderInt64Import()) 57 | } 58 | 59 | return includes 60 | } 61 | 62 | export function renderConst( 63 | statement: ConstDefinition, 64 | state: IRenderState, 65 | ): Array { 66 | return [_renderConst(statement, typeNodeForFieldType, state)] 67 | } 68 | 69 | export function renderTypeDef( 70 | statement: TypedefDefinition, 71 | state: IRenderState, 72 | ): Array { 73 | return _renderTypeDef(statement, typeNodeForFieldType, state) 74 | } 75 | 76 | export function renderEnum( 77 | statement: EnumDefinition, 78 | state: IRenderState, 79 | ): Array { 80 | return [_renderEnum(statement)] 81 | } 82 | 83 | export function renderStruct( 84 | statement: StructDefinition, 85 | state: IRenderState, 86 | ): Array { 87 | return [renderInterface(statement, state), _renderStruct(statement, state)] 88 | } 89 | 90 | export function renderException( 91 | statement: ExceptionDefinition, 92 | state: IRenderState, 93 | ): Array { 94 | return [ 95 | renderInterface(statement, state), 96 | _renderException(statement, state), 97 | ] 98 | } 99 | 100 | export function renderUnion( 101 | statement: UnionDefinition, 102 | state: IRenderState, 103 | ): Array { 104 | return [renderInterface(statement, state), _renderUnion(statement, state)] 105 | } 106 | 107 | export function renderService( 108 | statement: ServiceDefinition, 109 | state: IRenderState, 110 | ): Array { 111 | return [ 112 | ...renderArgsStruct(statement, state), 113 | ...renderResultStruct(statement, state), 114 | renderClient(statement, state), 115 | ...renderHandlerInterface(statement, state), 116 | renderProcessor(statement, state), 117 | ] 118 | } 119 | 120 | export const renderer: IRenderer = { 121 | renderImports, 122 | renderConst, 123 | renderTypeDef, 124 | renderEnum, 125 | renderStruct, 126 | renderException, 127 | renderUnion, 128 | renderService, 129 | renderIndex, 130 | } 131 | -------------------------------------------------------------------------------- /src/main/render/apache/interface.ts: -------------------------------------------------------------------------------- 1 | import * as ts from 'typescript' 2 | 3 | import { 4 | FieldDefinition, 5 | InterfaceWithFields, 6 | } from '@creditkarma/thrift-parser' 7 | 8 | import { typeNodeForFieldType } from './types' 9 | 10 | import { IRenderState } from '../../types' 11 | import { renderOptional } from './utils' 12 | 13 | /** 14 | * Returns the name of the interface for the args arguments for a given struct-like object 15 | */ 16 | export function interfaceNameForClass(statement: InterfaceWithFields): string { 17 | return `I${statement.name.value}Args` 18 | } 19 | 20 | /** 21 | * This generates an interface for the argument to the constructor of any struct-like object 22 | * These include struct, union and exception 23 | * 24 | * EXAMPLE: 25 | * 26 | * // thrift 27 | * stuct MyStruct { 28 | * 1: required i32 id, 29 | * 2: optional bool field1, 30 | * } 31 | * 32 | * // typescript 33 | * export interface IMyStructArgs { 34 | * id: number; 35 | * field1?: boolean 36 | * } 37 | */ 38 | export function renderInterface( 39 | statement: InterfaceWithFields, 40 | state: IRenderState, 41 | ): ts.InterfaceDeclaration { 42 | const signatures = statement.fields.map((field: FieldDefinition) => { 43 | return ts.createPropertySignature( 44 | undefined, 45 | field.name.value, 46 | renderOptional(field.requiredness), 47 | typeNodeForFieldType(field.fieldType, state, true), 48 | undefined, 49 | ) 50 | }) 51 | 52 | return ts.createInterfaceDeclaration( 53 | undefined, 54 | [ts.createToken(ts.SyntaxKind.ExportKeyword)], 55 | interfaceNameForClass(statement), 56 | [], 57 | [], 58 | signatures, 59 | ) 60 | } 61 | -------------------------------------------------------------------------------- /src/main/render/apache/service/types.ts: -------------------------------------------------------------------------------- 1 | import * as ts from 'typescript' 2 | 3 | import { createNumberType, createVoidType } from '../types' 4 | 5 | import { createFunctionParameter } from '../utils' 6 | 7 | import { createErrorType, createUndefinedType } from '../../shared/types' 8 | import { THRIFT_IDENTIFIERS } from '../identifiers' 9 | 10 | export const TProtocolType: ts.TypeNode = ts.createTypeReferenceNode( 11 | THRIFT_IDENTIFIERS.TProtocol, 12 | undefined, 13 | ) 14 | 15 | export function createProtocolType(): ts.ConstructorTypeNode { 16 | return ts.createConstructorTypeNode( 17 | [], 18 | [ 19 | createFunctionParameter( 20 | 'trans', 21 | ts.createTypeReferenceNode( 22 | THRIFT_IDENTIFIERS.TTransport, 23 | undefined, 24 | ), 25 | ), 26 | ], 27 | TProtocolType, 28 | ) 29 | } 30 | 31 | // { [key: string]: (e?: Error|object, r?: any) => void } 32 | export function createReqType(): ts.TypeLiteralNode { 33 | return ts.createTypeLiteralNode([ 34 | ts.createIndexSignature( 35 | undefined, 36 | undefined, 37 | [ 38 | ts.createParameter( 39 | undefined, 40 | undefined, 41 | undefined, 42 | 'name', 43 | undefined, 44 | createNumberType(), 45 | ), 46 | ], 47 | ts.createFunctionTypeNode( 48 | undefined, 49 | [ 50 | createFunctionParameter( 51 | 'err', 52 | ts.createUnionTypeNode([ 53 | createErrorType(), 54 | ts.createTypeReferenceNode('object', undefined), 55 | createUndefinedType(), 56 | ]), 57 | ), 58 | createFunctionParameter( 59 | 'val', 60 | ts.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword), 61 | undefined, 62 | true, 63 | ), 64 | ], 65 | createVoidType(), 66 | ), 67 | ), 68 | ]) 69 | } 70 | -------------------------------------------------------------------------------- /src/main/render/apache/service/utils.ts: -------------------------------------------------------------------------------- 1 | import { FieldDefinition, FunctionDefinition } from '@creditkarma/thrift-parser' 2 | 3 | export function capitalize(str: string): string { 4 | return str.charAt(0).toUpperCase() + str.slice(1) 5 | } 6 | 7 | export function createStructArgsName( 8 | def: FunctionDefinition | FieldDefinition, 9 | ): string { 10 | return `${capitalize(def.name.value)}Args` 11 | } 12 | 13 | export function createStructResultName( 14 | def: FunctionDefinition | FieldDefinition, 15 | ): string { 16 | return `${capitalize(def.name.value)}Result` 17 | } 18 | -------------------------------------------------------------------------------- /src/main/render/apache/struct/index.ts: -------------------------------------------------------------------------------- 1 | export * from './read' 2 | export * from './write' 3 | export * from './create' 4 | -------------------------------------------------------------------------------- /src/main/render/apache/struct/methods.ts: -------------------------------------------------------------------------------- 1 | import { SyntaxType } from '@creditkarma/thrift-parser' 2 | 3 | export type ReadMethodName = 4 | | 'readString' 5 | | 'readBinary' 6 | | 'readDouble' 7 | | 'readI16' 8 | | 'readI32' 9 | | 'readI64' 10 | | 'readByte' 11 | | 'readBool' 12 | 13 | export interface IReadMap { 14 | [name: string]: ReadMethodName 15 | } 16 | 17 | export const READ_METHODS: IReadMap = { 18 | [SyntaxType.BoolKeyword]: 'readBool', 19 | [SyntaxType.BinaryKeyword]: 'readBinary', 20 | [SyntaxType.StringKeyword]: 'readString', 21 | [SyntaxType.DoubleKeyword]: 'readDouble', 22 | [SyntaxType.I8Keyword]: 'readByte', 23 | [SyntaxType.ByteKeyword]: 'readByte', 24 | [SyntaxType.I16Keyword]: 'readI16', 25 | [SyntaxType.I32Keyword]: 'readI32', 26 | [SyntaxType.I64Keyword]: 'readI64', 27 | } 28 | 29 | export type WriteMethodName = 30 | | 'writeString' 31 | | 'writeBinary' 32 | | 'writeDouble' 33 | | 'writeI16' 34 | | 'writeI32' 35 | | 'writeI64' 36 | | 'writeByte' 37 | | 'writeBool' 38 | 39 | export interface IWriteMap { 40 | [name: string]: WriteMethodName 41 | } 42 | 43 | export const WRITE_METHODS: IWriteMap = { 44 | [SyntaxType.BoolKeyword]: 'writeBool', 45 | [SyntaxType.BinaryKeyword]: 'writeBinary', 46 | [SyntaxType.StringKeyword]: 'writeString', 47 | [SyntaxType.DoubleKeyword]: 'writeDouble', 48 | [SyntaxType.I8Keyword]: 'writeByte', 49 | [SyntaxType.ByteKeyword]: 'writeByte', 50 | [SyntaxType.I16Keyword]: 'writeI16', 51 | [SyntaxType.I32Keyword]: 'writeI32', 52 | [SyntaxType.I64Keyword]: 'writeI64', 53 | } 54 | -------------------------------------------------------------------------------- /src/main/render/apache/typedef.ts: -------------------------------------------------------------------------------- 1 | import * as ts from 'typescript' 2 | 3 | import { SyntaxType, TypedefDefinition } from '@creditkarma/thrift-parser' 4 | 5 | import { TypeMapping } from './types' 6 | 7 | import { Resolver } from '../../resolver' 8 | import { IRenderState, IResolvedIdentifier } from '../../types' 9 | 10 | function renderTypeDefForIdentifier( 11 | id: IResolvedIdentifier, 12 | node: TypedefDefinition, 13 | ): Array { 14 | return [ 15 | ts.createImportEqualsDeclaration( 16 | undefined, 17 | [ts.createToken(ts.SyntaxKind.ExportKeyword)], 18 | ts.createIdentifier(node.name.value), 19 | ts.createIdentifier(id.fullName), 20 | ), 21 | ] 22 | } 23 | 24 | export function renderTypeDef( 25 | node: TypedefDefinition, 26 | typeMapping: TypeMapping, 27 | state: IRenderState, 28 | ): Array { 29 | switch (node.definitionType.type) { 30 | case SyntaxType.Identifier: 31 | return renderTypeDefForIdentifier( 32 | Resolver.resolveIdentifierName(node.definitionType.value, { 33 | currentNamespace: state.currentNamespace, 34 | currentDefinitions: state.currentDefinitions, 35 | namespaceMap: state.project.namespaces, 36 | }), 37 | node, 38 | ) 39 | 40 | default: 41 | return [ 42 | ts.createTypeAliasDeclaration( 43 | undefined, 44 | [ts.createToken(ts.SyntaxKind.ExportKeyword)], 45 | node.name.value, 46 | undefined, 47 | typeMapping(node.definitionType, state), 48 | ), 49 | ] 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/render/apache/utils.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * UTILS 3 | * 4 | * This module contains abstractions around the TypeScript factory functions to make them more 5 | * concise. 6 | */ 7 | import * as ts from 'typescript' 8 | 9 | import { TApplicationException, TProtocolException } from './types' 10 | 11 | import { 12 | APPLICATION_EXCEPTION, 13 | PROTOCOL_EXCEPTION, 14 | THRIFT_IDENTIFIERS, 15 | } from './identifiers' 16 | 17 | export * from '../shared/utils' 18 | 19 | export function createProtocolException( 20 | type: TProtocolException, 21 | message: string, 22 | ): ts.NewExpression { 23 | const errCtor = THRIFT_IDENTIFIERS.TProtocolException 24 | const errType = PROTOCOL_EXCEPTION[type] 25 | const errArgs = [errType, ts.createLiteral(message)] 26 | return ts.createNew(errCtor, undefined, errArgs) 27 | } 28 | 29 | export function throwProtocolException( 30 | type: TProtocolException, 31 | message: string, 32 | ): ts.ThrowStatement { 33 | return ts.createThrow(createProtocolException(type, message)) 34 | } 35 | 36 | export function createApplicationException( 37 | type: TApplicationException, 38 | message: string | ts.Expression, 39 | ): ts.NewExpression { 40 | const errCtor = THRIFT_IDENTIFIERS.TApplicationException 41 | const errType = APPLICATION_EXCEPTION[type] 42 | const errArgs = [ 43 | errType, 44 | typeof message === 'string' ? ts.createLiteral(message) : message, 45 | ] 46 | return ts.createNew(errCtor, undefined, errArgs) 47 | } 48 | 49 | export function throwApplicationException( 50 | type: TApplicationException, 51 | message: string, 52 | ): ts.ThrowStatement { 53 | return ts.createThrow(createApplicationException(type, message)) 54 | } 55 | -------------------------------------------------------------------------------- /src/main/render/index.ts: -------------------------------------------------------------------------------- 1 | import { renderer as ApacheRenderer } from './apache' 2 | 3 | import { renderer as ThriftRenderer } from './thrift-server' 4 | 5 | import { CompileTarget, IRenderer } from '../types' 6 | 7 | export function rendererForTarget(target: CompileTarget = 'apache'): IRenderer { 8 | switch (target) { 9 | case 'thrift-server': 10 | return ThriftRenderer 11 | 12 | case 'apache': 13 | return ApacheRenderer 14 | 15 | default: 16 | const msg: never = target 17 | throw new Error(`Non-exhaustive match for ${msg}`) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/render/shared/index.ts: -------------------------------------------------------------------------------- 1 | import * as ts from 'typescript' 2 | 3 | import { ServiceDefinition } from '@creditkarma/thrift-parser' 4 | 5 | import { DefinitionType, INamespace, IRenderState } from '../../types' 6 | 7 | export function renderIndex(state: IRenderState): Array { 8 | const currentNamespace: INamespace = state.currentNamespace 9 | const results: Array = [] 10 | if (currentNamespace.constants.length > 0) { 11 | results.push( 12 | ts.createExportDeclaration( 13 | undefined, 14 | undefined, 15 | undefined, 16 | ts.createLiteral(`./constants`), 17 | ), 18 | ) 19 | } 20 | 21 | ;[ 22 | ...currentNamespace.enums, 23 | ...currentNamespace.typedefs, 24 | ...currentNamespace.structs, 25 | ...currentNamespace.unions, 26 | ...currentNamespace.exceptions, 27 | ].forEach((next: DefinitionType) => { 28 | results.push( 29 | ts.createExportDeclaration( 30 | undefined, 31 | undefined, 32 | undefined, 33 | ts.createLiteral(`./${next.name.value}`), 34 | ), 35 | ) 36 | }) 37 | 38 | currentNamespace.services.forEach((next: ServiceDefinition) => { 39 | results.push( 40 | ts.createImportDeclaration( 41 | undefined, 42 | undefined, 43 | ts.createImportClause( 44 | undefined, 45 | ts.createNamespaceImport( 46 | ts.createIdentifier(next.name.value), 47 | ), 48 | ), 49 | ts.createLiteral(`./${next.name.value}`), 50 | ), 51 | ) 52 | 53 | results.push( 54 | ts.createExportDeclaration( 55 | undefined, 56 | undefined, 57 | ts.createNamedExports([ 58 | ts.createExportSpecifier(next.name.value, next.name.value), 59 | ]), 60 | ), 61 | ) 62 | }) 63 | 64 | return results 65 | } 66 | -------------------------------------------------------------------------------- /src/main/render/thrift-server/const.ts: -------------------------------------------------------------------------------- 1 | import * as ts from 'typescript' 2 | 3 | import { ConstDefinition } from '@creditkarma/thrift-parser' 4 | 5 | import { TypeMapping } from './types' 6 | 7 | import { renderValue } from './initializers' 8 | 9 | import { IRenderState } from '../../types' 10 | import { createConst } from './utils' 11 | 12 | /** 13 | * EXAMPLE 14 | * 15 | * // thrift 16 | * const i32 myConst = 45 17 | * 18 | * // typescript 19 | * const myConst: number = 45 20 | */ 21 | export function renderConst( 22 | node: ConstDefinition, 23 | typeMapping: TypeMapping, 24 | state: IRenderState, 25 | ): ts.Statement { 26 | return ts.createVariableStatement( 27 | [ts.createToken(ts.SyntaxKind.ExportKeyword)], 28 | createConst( 29 | node.name.value, 30 | typeMapping(node.fieldType, state), 31 | renderValue(node.fieldType, node.initializer, state), 32 | ), 33 | ) 34 | } 35 | -------------------------------------------------------------------------------- /src/main/render/thrift-server/enum.ts: -------------------------------------------------------------------------------- 1 | import * as ts from 'typescript' 2 | 3 | import { EnumDefinition, EnumMember } from '@creditkarma/thrift-parser' 4 | 5 | import { renderIntConstant } from './initializers' 6 | 7 | /** 8 | * EXAMPE 9 | * 10 | * // thrift 11 | * enum MyEnum { 12 | * ONE, 13 | * TWO 14 | * } 15 | * 16 | * // typescript 17 | * export enum MyEnum { 18 | * ONE, 19 | * TWO 20 | * } 21 | */ 22 | export function renderEnum(node: EnumDefinition): ts.Statement { 23 | return ts.createEnumDeclaration( 24 | undefined, // decorators 25 | [ts.createToken(ts.SyntaxKind.ExportKeyword)], // modifiers 26 | node.name.value, // enum name 27 | node.members.map((field: EnumMember) => { 28 | return ts.createEnumMember( 29 | field.name.value, 30 | field.initializer !== null 31 | ? renderIntConstant(field.initializer) 32 | : undefined, 33 | ) 34 | }), // enum members 35 | ) 36 | } 37 | -------------------------------------------------------------------------------- /src/main/render/thrift-server/exception/index.ts: -------------------------------------------------------------------------------- 1 | import * as ts from 'typescript' 2 | 3 | import { ExceptionDefinition } from '@creditkarma/thrift-parser' 4 | 5 | import { IRenderState } from '../../../types' 6 | 7 | import { renderStruct } from '../struct' 8 | 9 | export function renderException( 10 | node: ExceptionDefinition, 11 | state: IRenderState, 12 | ): Array { 13 | return renderStruct(node, state) 14 | } 15 | -------------------------------------------------------------------------------- /src/main/render/thrift-server/index.ts: -------------------------------------------------------------------------------- 1 | import * as ts from 'typescript' 2 | 3 | import { 4 | ConstDefinition, 5 | EnumDefinition, 6 | ExceptionDefinition, 7 | ServiceDefinition, 8 | StructDefinition, 9 | ThriftStatement, 10 | TypedefDefinition, 11 | UnionDefinition, 12 | } from '@creditkarma/thrift-parser' 13 | 14 | import { renderIndex } from '../shared' 15 | import { 16 | renderIncludes as _renderIncludes, 17 | renderThriftImports, 18 | statementsUseThrift, 19 | } from '../shared/includes' 20 | import { renderConst as _renderConst } from './const' 21 | import { renderEnum as _renderEnum } from './enum' 22 | import { renderException as _renderException } from './exception' 23 | import { renderService as _renderService } from './service' 24 | import { renderStruct as _renderStruct } from './struct' 25 | import { renderTypeDef as _renderTypeDef } from './typedef' 26 | import { renderStrictUnion, renderUnion as _renderUnion } from './union' 27 | 28 | import { IRenderer, IRenderState } from '../../types' 29 | 30 | import { typeNodeForFieldType } from './types' 31 | 32 | export function renderImports( 33 | statements: Array, 34 | state: IRenderState, 35 | ): Array { 36 | if (statementsUseThrift(statements)) { 37 | return [ 38 | renderThriftImports(state.options.library), 39 | ..._renderIncludes(statements, state), 40 | ] 41 | } else { 42 | return _renderIncludes(statements, state) 43 | } 44 | } 45 | 46 | export function renderConst( 47 | statement: ConstDefinition, 48 | state: IRenderState, 49 | ): Array { 50 | return [_renderConst(statement, typeNodeForFieldType, state)] 51 | } 52 | 53 | export function renderTypeDef( 54 | statement: TypedefDefinition, 55 | state: IRenderState, 56 | ): Array { 57 | return _renderTypeDef(statement, typeNodeForFieldType, state) 58 | } 59 | 60 | export function renderEnum( 61 | statement: EnumDefinition, 62 | state: IRenderState, 63 | ): Array { 64 | return [_renderEnum(statement)] 65 | } 66 | 67 | export function renderStruct( 68 | statement: StructDefinition, 69 | state: IRenderState, 70 | ): Array { 71 | return _renderStruct(statement, state) 72 | } 73 | 74 | export function renderException( 75 | statement: ExceptionDefinition, 76 | state: IRenderState, 77 | ): Array { 78 | return _renderException(statement, state) 79 | } 80 | 81 | export function renderUnion( 82 | statement: UnionDefinition, 83 | state: IRenderState, 84 | ): Array { 85 | if (state.options.strictUnions) { 86 | return renderStrictUnion(statement, state) 87 | } else { 88 | return _renderUnion(statement, state) 89 | } 90 | } 91 | 92 | export function renderService( 93 | statement: ServiceDefinition, 94 | state: IRenderState, 95 | ): Array { 96 | return _renderService(statement, state) 97 | } 98 | 99 | export const renderer: IRenderer = { 100 | renderIndex, 101 | renderImports, 102 | renderConst, 103 | renderTypeDef, 104 | renderEnum, 105 | renderStruct, 106 | renderException, 107 | renderUnion, 108 | renderService, 109 | } 110 | -------------------------------------------------------------------------------- /src/main/render/thrift-server/service/types.ts: -------------------------------------------------------------------------------- 1 | import * as ts from 'typescript' 2 | 3 | import { COMMON_IDENTIFIERS, THRIFT_IDENTIFIERS } from '../identifiers' 4 | 5 | export const TProtocolType: ts.TypeNode = ts.createTypeReferenceNode( 6 | THRIFT_IDENTIFIERS.TProtocol, 7 | undefined, 8 | ) 9 | 10 | export const ContextType: ts.TypeNode = ts.createTypeReferenceNode( 11 | COMMON_IDENTIFIERS.Context, 12 | undefined, 13 | ) 14 | 15 | export function createConnectionType(): ts.TypeNode { 16 | return ts.createTypeReferenceNode(THRIFT_IDENTIFIERS.IThriftConnection, [ 17 | ts.createTypeReferenceNode(COMMON_IDENTIFIERS.Context, undefined), 18 | ]) 19 | } 20 | -------------------------------------------------------------------------------- /src/main/render/thrift-server/struct/index.ts: -------------------------------------------------------------------------------- 1 | import * as ts from 'typescript' 2 | 3 | import { InterfaceWithFields } from '@creditkarma/thrift-parser' 4 | 5 | import { IRenderState } from '../../../types' 6 | 7 | import { renderInterface } from './interface' 8 | 9 | import { renderToolkit } from './toolkit' 10 | 11 | import { renderClass } from './class' 12 | 13 | export function renderStruct( 14 | node: InterfaceWithFields, 15 | state: IRenderState, 16 | ): Array { 17 | return [ 18 | ...renderInterface(node, state, true), 19 | renderToolkit(node, state, true), 20 | renderClass(node, state, true), 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /src/main/render/thrift-server/struct/interface.ts: -------------------------------------------------------------------------------- 1 | import * as ts from 'typescript' 2 | 3 | import { 4 | FieldDefinition, 5 | InterfaceWithFields, 6 | } from '@creditkarma/thrift-parser' 7 | 8 | import { typeNodeForFieldType } from '../types' 9 | 10 | import { IRenderState } from '../../../types' 11 | 12 | import { COMMON_IDENTIFIERS } from '../../shared/identifiers' 13 | import { 14 | looseNameForStruct, 15 | renderOptional, 16 | strictNameForStruct, 17 | tokens, 18 | } from './utils' 19 | 20 | function strictInterface( 21 | node: InterfaceWithFields, 22 | state: IRenderState, 23 | isExported: boolean, 24 | ): ts.InterfaceDeclaration { 25 | const signatures = state.options.withNameField 26 | ? [ 27 | ts.createPropertySignature( 28 | undefined, 29 | COMMON_IDENTIFIERS.__name, 30 | undefined, 31 | ts.createLiteralTypeNode(ts.createLiteral(node.name.value)), 32 | undefined, 33 | ), 34 | ...node.fields.map((field: FieldDefinition) => { 35 | return ts.createPropertySignature( 36 | undefined, 37 | field.name.value, 38 | renderOptional(field), 39 | typeNodeForFieldType(field.fieldType, state), 40 | undefined, 41 | ) 42 | }), 43 | ] 44 | : [ 45 | ...node.fields.map((field: FieldDefinition) => { 46 | return ts.createPropertySignature( 47 | undefined, 48 | field.name.value, 49 | renderOptional(field), 50 | typeNodeForFieldType(field.fieldType, state), 51 | undefined, 52 | ) 53 | }), 54 | ] 55 | 56 | return ts.createInterfaceDeclaration( 57 | undefined, 58 | tokens(isExported), 59 | strictNameForStruct(node, state), 60 | [], 61 | [], 62 | signatures, 63 | ) 64 | } 65 | 66 | function looseInterface( 67 | node: InterfaceWithFields, 68 | state: IRenderState, 69 | isExported: boolean, 70 | ): ts.InterfaceDeclaration { 71 | const signatures = node.fields.map((field: FieldDefinition) => { 72 | return ts.createPropertySignature( 73 | undefined, 74 | field.name.value, 75 | renderOptional(field, true), 76 | typeNodeForFieldType(field.fieldType, state, true), 77 | undefined, 78 | ) 79 | }) 80 | 81 | return ts.createInterfaceDeclaration( 82 | undefined, 83 | tokens(isExported), 84 | looseNameForStruct(node, state), 85 | [], 86 | [], 87 | signatures, 88 | ) 89 | } 90 | 91 | /** 92 | * This generates an interface for the argument to the constructor of any struct-like object 93 | * These include struct, union and exception 94 | * 95 | * EXAMPLE: 96 | * 97 | * // thrift 98 | * stuct MyStruct { 99 | * 1: required i32 id, 100 | * 2: optional i64 field1, 101 | * } 102 | * 103 | * // typescript 104 | * export interface MyStruct { 105 | * id: number; 106 | * field1?: thrift.Int64 107 | * } 108 | * export interface MyStruct_Loose { 109 | * id: number; 110 | * field1?: number | thrift.Int64 111 | * } 112 | */ 113 | export function renderInterface( 114 | node: InterfaceWithFields, 115 | state: IRenderState, 116 | isExported: boolean, 117 | ): Array { 118 | return [ 119 | strictInterface(node, state, isExported), 120 | looseInterface(node, state, isExported), 121 | ] 122 | } 123 | -------------------------------------------------------------------------------- /src/main/render/thrift-server/struct/methods.ts: -------------------------------------------------------------------------------- 1 | import { SyntaxType } from '@creditkarma/thrift-parser' 2 | 3 | export type ReadMethodName = 4 | | 'readString' 5 | | 'readBinary' 6 | | 'readDouble' 7 | | 'readI16' 8 | | 'readI32' 9 | | 'readI64' 10 | | 'readByte' 11 | | 'readBool' 12 | 13 | export interface IReadMap { 14 | [name: string]: ReadMethodName 15 | } 16 | 17 | export const READ_METHODS: IReadMap = { 18 | [SyntaxType.BoolKeyword]: 'readBool', 19 | [SyntaxType.BinaryKeyword]: 'readBinary', 20 | [SyntaxType.StringKeyword]: 'readString', 21 | [SyntaxType.DoubleKeyword]: 'readDouble', 22 | [SyntaxType.I8Keyword]: 'readByte', 23 | [SyntaxType.ByteKeyword]: 'readByte', 24 | [SyntaxType.I16Keyword]: 'readI16', 25 | [SyntaxType.I32Keyword]: 'readI32', 26 | [SyntaxType.I64Keyword]: 'readI64', 27 | } 28 | 29 | export type WriteMethodName = 30 | | 'writeString' 31 | | 'writeBinary' 32 | | 'writeDouble' 33 | | 'writeI16' 34 | | 'writeI32' 35 | | 'writeI64' 36 | | 'writeByte' 37 | | 'writeBool' 38 | 39 | export interface IWriteMap { 40 | [name: string]: WriteMethodName 41 | } 42 | 43 | export const WRITE_METHODS: IWriteMap = { 44 | [SyntaxType.BoolKeyword]: 'writeBool', 45 | [SyntaxType.BinaryKeyword]: 'writeBinary', 46 | [SyntaxType.StringKeyword]: 'writeString', 47 | [SyntaxType.DoubleKeyword]: 'writeDouble', 48 | [SyntaxType.I8Keyword]: 'writeByte', 49 | [SyntaxType.ByteKeyword]: 'writeByte', 50 | [SyntaxType.I16Keyword]: 'writeI16', 51 | [SyntaxType.I32Keyword]: 'writeI32', 52 | [SyntaxType.I64Keyword]: 'writeI64', 53 | } 54 | -------------------------------------------------------------------------------- /src/main/render/thrift-server/struct/toolkit.ts: -------------------------------------------------------------------------------- 1 | import * as ts from 'typescript' 2 | 3 | import { InterfaceWithFields } from '@creditkarma/thrift-parser' 4 | 5 | import { createConst } from '../utils' 6 | 7 | import { THRIFT_IDENTIFIERS } from '../identifiers' 8 | 9 | import { createEncodeMethod } from './encode' 10 | 11 | import { createDecodeMethod } from './decode' 12 | 13 | import { IRenderState } from '../../../types' 14 | import { 15 | looseNameForStruct, 16 | strictNameForStruct, 17 | tokens, 18 | toolkitNameForStruct, 19 | } from './utils' 20 | 21 | export function renderToolkit( 22 | node: InterfaceWithFields, 23 | state: IRenderState, 24 | isExported: boolean, 25 | ): ts.Statement { 26 | return ts.createVariableStatement( 27 | tokens(isExported), 28 | createConst( 29 | toolkitNameForStruct(node, state), 30 | ts.createTypeReferenceNode(THRIFT_IDENTIFIERS.IStructCodec, [ 31 | ts.createTypeReferenceNode( 32 | looseNameForStruct(node, state), 33 | undefined, 34 | ), 35 | ts.createTypeReferenceNode( 36 | strictNameForStruct(node, state), 37 | undefined, 38 | ), 39 | ]), 40 | ts.createObjectLiteral( 41 | [ 42 | createEncodeMethod(node, state), 43 | createDecodeMethod(node, state), 44 | ], 45 | true, 46 | ), 47 | ), 48 | ) 49 | } 50 | -------------------------------------------------------------------------------- /src/main/render/thrift-server/union/index.ts: -------------------------------------------------------------------------------- 1 | import * as ts from 'typescript' 2 | 3 | import { UnionDefinition } from '@creditkarma/thrift-parser' 4 | 5 | import { IRenderState } from '../../../types' 6 | 7 | import { renderInterface } from '../struct/interface' 8 | 9 | import { renderToolkit } from './toolkit' 10 | 11 | import { renderClass } from './class' 12 | 13 | import { renderUnionsForFields, renderUnionTypes } from './union-fields' 14 | 15 | export function renderUnion( 16 | node: UnionDefinition, 17 | state: IRenderState, 18 | isExported: boolean = true, 19 | ): Array { 20 | return [ 21 | ...renderInterface(node, state, isExported), 22 | renderToolkit(node, state, isExported), 23 | renderClass(node, state, isExported), 24 | ] 25 | } 26 | 27 | export function renderStrictUnion( 28 | node: UnionDefinition, 29 | state: IRenderState, 30 | isExported: boolean = true, 31 | ): Array { 32 | return [ 33 | renderUnionTypes(node, state, isExported), 34 | ...renderUnionsForFields(node, state, isExported, true), 35 | ...renderUnionsForFields(node, state, isExported, false), 36 | renderToolkit(node, state, isExported), 37 | ] 38 | } 39 | -------------------------------------------------------------------------------- /src/main/render/thrift-server/union/toolkit.ts: -------------------------------------------------------------------------------- 1 | import * as ts from 'typescript' 2 | 3 | import { UnionDefinition } from '@creditkarma/thrift-parser' 4 | 5 | import { createConst } from '../utils' 6 | 7 | import { THRIFT_IDENTIFIERS } from '../identifiers' 8 | 9 | import { createEncodeMethod } from './encode' 10 | 11 | import { createDecodeMethod } from './decode' 12 | 13 | import { createCreateMethod } from './create' 14 | 15 | import { IRenderState } from '../../../types' 16 | import { 17 | looseNameForStruct, 18 | strictNameForStruct, 19 | tokens, 20 | toolkitNameForStruct, 21 | } from '../struct/utils' 22 | 23 | function renderMethodsForCodec( 24 | node: UnionDefinition, 25 | state: IRenderState, 26 | ): Array { 27 | if (state.options.strictUnions) { 28 | return [ 29 | createCreateMethod(node, state), 30 | createEncodeMethod(node, state), 31 | createDecodeMethod(node, state), 32 | ] 33 | } else { 34 | return [ 35 | createEncodeMethod(node, state), 36 | createDecodeMethod(node, state), 37 | ] 38 | } 39 | } 40 | 41 | function toolkitBaseClass(state: IRenderState): ts.Identifier { 42 | if (state.options.strictUnions) { 43 | return THRIFT_IDENTIFIERS.IStructToolkit 44 | } else { 45 | return THRIFT_IDENTIFIERS.IStructCodec 46 | } 47 | } 48 | 49 | function renderToolkitTypeNode( 50 | node: UnionDefinition, 51 | state: IRenderState, 52 | ): ts.TypeNode { 53 | return ts.createTypeReferenceNode(toolkitBaseClass(state), [ 54 | ts.createTypeReferenceNode( 55 | ts.createIdentifier(looseNameForStruct(node, state)), 56 | undefined, 57 | ), 58 | ts.createTypeReferenceNode( 59 | ts.createIdentifier(strictNameForStruct(node, state)), 60 | undefined, 61 | ), 62 | ]) 63 | } 64 | 65 | export function renderToolkit( 66 | node: UnionDefinition, 67 | state: IRenderState, 68 | isExported: boolean, 69 | ): ts.Statement { 70 | return ts.createVariableStatement( 71 | tokens(isExported), 72 | createConst( 73 | ts.createIdentifier(toolkitNameForStruct(node, state)), 74 | renderToolkitTypeNode(node, state), 75 | ts.createObjectLiteral(renderMethodsForCodec(node, state), true), 76 | ), 77 | ) 78 | } 79 | -------------------------------------------------------------------------------- /src/main/resolver/exportsForFile.ts: -------------------------------------------------------------------------------- 1 | import { SyntaxType, ThriftStatement } from '@creditkarma/thrift-parser' 2 | 3 | import { IFileExports } from '../types' 4 | 5 | // Give some thrift statements this generates a map of the name of those statements to the 6 | // definition of that statement 7 | export function exportsForFile(fileBody: Array): IFileExports { 8 | return fileBody.reduce((acc: IFileExports, next: ThriftStatement) => { 9 | switch (next.type) { 10 | case SyntaxType.TypedefDefinition: 11 | case SyntaxType.ConstDefinition: 12 | case SyntaxType.EnumDefinition: 13 | case SyntaxType.UnionDefinition: 14 | case SyntaxType.ExceptionDefinition: 15 | case SyntaxType.StructDefinition: 16 | case SyntaxType.ServiceDefinition: 17 | acc[next.name.value] = next 18 | break 19 | 20 | default: 21 | // Ignore 22 | break 23 | } 24 | 25 | return acc 26 | }, {}) 27 | } 28 | -------------------------------------------------------------------------------- /src/main/resolver/includesForFile.ts: -------------------------------------------------------------------------------- 1 | import { SyntaxType, ThriftStatement } from '@creditkarma/thrift-parser' 2 | import { IFileIncludes, ISourceFile } from '../types' 3 | 4 | function nameForInclude(fullInclude: string): string { 5 | const body = fullInclude.replace('.thrift', '') 6 | const parts = body.split('/') 7 | 8 | return parts[parts.length - 1] 9 | } 10 | 11 | export function includesForFile( 12 | fileBody: Array, 13 | sourceFile: ISourceFile, 14 | ): IFileIncludes { 15 | return fileBody.reduce((acc: IFileIncludes, next: ThriftStatement) => { 16 | if (next.type === SyntaxType.IncludeDefinition) { 17 | const includeName = nameForInclude(next.path.value) 18 | 19 | acc[includeName] = { 20 | type: 'IncludePath', 21 | path: next.path.value, 22 | importedFrom: sourceFile.path, 23 | } 24 | } 25 | 26 | return acc 27 | }, {}) 28 | } 29 | -------------------------------------------------------------------------------- /src/main/resolver/index.ts: -------------------------------------------------------------------------------- 1 | import { exportsForFile } from './exportsForFile' 2 | import { identifiersForStatements } from './identifiersForStatements' 3 | import { includesForFile } from './includesForFile' 4 | import { namespaceForFile } from './namespaceForFile' 5 | import { namespaceForInclude } from './namespaceForInclude' 6 | import { organizeByNamespace } from './organizeByNamespace' 7 | import { resolveConstValue } from './resolveConstValue' 8 | import { resolveIdentifierDefinition } from './resolveIdentifierDefinition' 9 | import { resolveIdentifierName } from './resolveIdentifierName' 10 | import { resolveNamespace } from './resolveNamespace' 11 | 12 | export const Resolver = { 13 | exportsForFile, 14 | identifiersForStatements, 15 | includesForFile, 16 | namespaceForFile, 17 | namespaceForInclude, 18 | organizeByNamespace, 19 | resolveConstValue, 20 | resolveIdentifierName, 21 | resolveIdentifierDefinition, 22 | resolveNamespace, 23 | } 24 | -------------------------------------------------------------------------------- /src/main/resolver/namespaceForFile.ts: -------------------------------------------------------------------------------- 1 | import { 2 | NamespaceDefinition, 3 | SyntaxType, 4 | ThriftStatement, 5 | } from '@creditkarma/thrift-parser' 6 | import { INamespacePath, INamespacePathMap } from '../types' 7 | 8 | function emptyNamespace(): INamespacePath { 9 | return { 10 | type: 'NamespacePath', 11 | scope: '', 12 | name: '__ROOT_NAMESPACE__', 13 | path: createPathForNamespace(''), 14 | accessor: '__ROOT_NAMESPACE__', 15 | } 16 | } 17 | 18 | function createPathForNamespace(ns: string): string { 19 | return ns.split('.').join('/') 20 | } 21 | 22 | function resolveNamespaceAccessor(namespaceName: string): string { 23 | return namespaceName 24 | .split('') 25 | .map((next: string) => { 26 | if (next === '.') { 27 | return '_' 28 | } else { 29 | return next 30 | } 31 | }) 32 | .join('') 33 | } 34 | 35 | function collectNamespaces( 36 | fileBody: Array, 37 | ): INamespacePathMap { 38 | return fileBody 39 | .filter((next: ThriftStatement): next is NamespaceDefinition => { 40 | return next.type === SyntaxType.NamespaceDefinition 41 | }) 42 | .reduce((acc: INamespacePathMap, def: NamespaceDefinition) => { 43 | const includeAccessor: string = resolveNamespaceAccessor( 44 | def.name.value, 45 | ) 46 | 47 | acc[def.scope.value] = { 48 | type: 'NamespacePath', 49 | scope: def.scope.value, 50 | name: def.name.value, 51 | path: createPathForNamespace(def.name.value), 52 | accessor: includeAccessor, 53 | } 54 | 55 | return acc 56 | }, {}) 57 | } 58 | 59 | export function namespaceForFile( 60 | fileBody: Array, 61 | fallbackNamespace: string, 62 | ): INamespacePath { 63 | const namespaceMap = collectNamespaces(fileBody) 64 | 65 | if (namespaceMap.js) { 66 | return namespaceMap.js 67 | } else if ( 68 | fallbackNamespace !== 'none' && 69 | namespaceMap[fallbackNamespace] 70 | ) { 71 | return namespaceMap[fallbackNamespace] 72 | } else { 73 | return emptyNamespace() 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/resolver/namespaceForInclude.ts: -------------------------------------------------------------------------------- 1 | import * as path from 'path' 2 | 3 | import { 4 | IIncludePath, 5 | INamespacePath, 6 | IParsedFile, 7 | IParsedFileMap, 8 | } from '../types' 9 | import { namespaceForFile } from './namespaceForFile' 10 | 11 | function fileForInclude( 12 | includePath: IIncludePath, 13 | fileMap: IParsedFileMap, 14 | sourceDir: string, 15 | ): IParsedFile { 16 | // Relative to the file requesting the include 17 | const relativeToFile: string = path.resolve( 18 | includePath.importedFrom, 19 | includePath.path, 20 | ) 21 | 22 | // Relative to the source directory 23 | const relativeToRoot: string = path.resolve(sourceDir, includePath.path) 24 | 25 | if (fileMap[relativeToFile]) { 26 | return fileMap[relativeToFile] 27 | } else if (fileMap[relativeToRoot]) { 28 | return fileMap[relativeToRoot] 29 | } else { 30 | throw new Error(`No file for include: ${includePath.path}`) 31 | } 32 | } 33 | 34 | export function namespaceForInclude( 35 | includePath: IIncludePath, 36 | fileMap: IParsedFileMap, 37 | sourceDir: string, 38 | fallbackNamespace: string, 39 | ): INamespacePath { 40 | const file: IParsedFile = fileForInclude(includePath, fileMap, sourceDir) 41 | const namespace: INamespacePath = namespaceForFile( 42 | file.body, 43 | fallbackNamespace, 44 | ) 45 | 46 | return namespace 47 | } 48 | -------------------------------------------------------------------------------- /src/main/resolver/resolveIdentifierDefinition.ts: -------------------------------------------------------------------------------- 1 | import { Identifier, SyntaxType } from '@creditkarma/thrift-parser' 2 | 3 | import { ValidationError } from '../errors' 4 | 5 | import { 6 | DefinitionType, 7 | INamespace, 8 | INamespacePath, 9 | IResolveContext, 10 | IResolveResult, 11 | } from '../types' 12 | 13 | import { stubIdentifier } from '../utils' 14 | 15 | export function resolveIdentifierDefinition( 16 | id: Identifier, 17 | context: IResolveContext, 18 | ): IResolveResult { 19 | if (context.currentNamespace.exports[id.value]) { 20 | const definition: DefinitionType = 21 | context.currentNamespace.exports[id.value] 22 | 23 | if (definition.type === SyntaxType.TypedefDefinition) { 24 | if (definition.definitionType.type === SyntaxType.Identifier) { 25 | return resolveIdentifierDefinition( 26 | definition.definitionType, 27 | context, 28 | ) 29 | } else { 30 | return { 31 | definition, 32 | namespace: context.currentNamespace, 33 | } 34 | } 35 | } else { 36 | return { 37 | definition, 38 | namespace: context.currentNamespace, 39 | } 40 | } 41 | } else { 42 | const [head, ...tail] = id.value.split('.') 43 | const namespace: INamespacePath = 44 | context.currentNamespace.includedNamespaces[head] 45 | 46 | if (context.currentNamespace.includedNamespaces[head]) { 47 | const nextNamespace: INamespace = 48 | context.namespaceMap[namespace.accessor] 49 | 50 | return resolveIdentifierDefinition(stubIdentifier(tail.join('.')), { 51 | currentNamespace: nextNamespace, 52 | namespaceMap: context.namespaceMap, 53 | }) 54 | } else if (context.currentNamespace.namespaceIncludes[head]) { 55 | const accessor: string = 56 | context.currentNamespace.namespaceIncludes[head] 57 | 58 | const nextNamespace: INamespace = context.namespaceMap[accessor] 59 | 60 | return resolveIdentifierDefinition(stubIdentifier(tail.join('.')), { 61 | currentNamespace: nextNamespace, 62 | namespaceMap: context.namespaceMap, 63 | }) 64 | } else { 65 | throw new ValidationError( 66 | `Unable to resolve identifier[${id.value}] in namespace[${context.currentNamespace.namespace.path}]`, 67 | id.loc, 68 | ) 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/resolver/resolveIdentifierName.ts: -------------------------------------------------------------------------------- 1 | import { SyntaxType } from '@creditkarma/thrift-parser' 2 | import { 3 | INamespace, 4 | INamespacePath, 5 | IResolveContext, 6 | IResolvedIdentifier, 7 | } from '../types' 8 | 9 | // Given the name of an identifier and the state in which that file is being rendered return the name that 10 | // should be used for the identifier in the given context. 11 | export function resolveIdentifierName( 12 | name: string, 13 | context: IResolveContext, 14 | ): IResolvedIdentifier { 15 | const currentNamespace: INamespace = context.currentNamespace 16 | const [pathName, base, ...tail] = name.split('.') 17 | let baseName: string = pathName 18 | 19 | if (base !== undefined) { 20 | baseName = [base, ...tail].join('.') 21 | } 22 | 23 | // Handle identifier exists in the current namespace 24 | if (currentNamespace.exports[pathName]) { 25 | if ( 26 | context.currentDefinitions && 27 | context.currentDefinitions[pathName] 28 | ) { 29 | return { 30 | rawName: name, 31 | name: pathName, 32 | baseName, 33 | pathName: undefined, 34 | fullName: name, 35 | } 36 | } else { 37 | const def = currentNamespace.exports[pathName] 38 | let rootName: string = pathName 39 | 40 | if (def.type === SyntaxType.ConstDefinition) { 41 | rootName = '__CONSTANTS__' 42 | } 43 | 44 | /** 45 | * Services do not export an object with the thrift-defined name. 46 | */ 47 | if (def.type === SyntaxType.ServiceDefinition) { 48 | return { 49 | rawName: name, 50 | name: pathName, 51 | baseName, 52 | pathName: rootName, 53 | fullName: `${rootName}`, 54 | } 55 | } 56 | 57 | return { 58 | rawName: name, 59 | name: pathName, 60 | baseName, 61 | pathName: rootName, 62 | fullName: `${rootName}.${name}`, 63 | } 64 | } 65 | } 66 | 67 | // Handle if identifier exists in another namespace 68 | const namespace: INamespacePath = 69 | currentNamespace.includedNamespaces[pathName] 70 | 71 | if (namespace !== undefined) { 72 | return { 73 | rawName: name, 74 | name: base, 75 | baseName, 76 | pathName, 77 | fullName: name, 78 | } 79 | } 80 | 81 | if (base === undefined) { 82 | return { 83 | rawName: name, 84 | name: pathName, 85 | baseName, 86 | pathName: undefined, 87 | fullName: name, 88 | } 89 | } 90 | 91 | throw new Error(`Unable to resolve identifier[${name}]`) 92 | } 93 | -------------------------------------------------------------------------------- /src/main/sys.ts: -------------------------------------------------------------------------------- 1 | import * as fs from 'fs-extra' 2 | import * as path from 'path' 3 | 4 | import { print } from './printer' 5 | import { IGeneratedFile } from './types' 6 | 7 | export function saveFiles(files: Array, outDir: string): void { 8 | files.forEach((next: IGeneratedFile) => { 9 | const outPath: string = path.resolve( 10 | outDir, 11 | next.path, 12 | `${next.name}.${next.ext}`, 13 | ) 14 | 15 | try { 16 | fs.outputFileSync(outPath, print(next.body, true)) 17 | } catch (err) { 18 | throw new Error(`Unable to save generated files to: ${outPath}`) 19 | } 20 | }) 21 | } 22 | -------------------------------------------------------------------------------- /src/main/utils.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Identifier, 3 | SyntaxType, 4 | TextLocation, 5 | } from '@creditkarma/thrift-parser' 6 | 7 | import * as glob from 'glob' 8 | 9 | export function valuesForObject(obj: { [key: string]: T }): Array { 10 | return Object.keys(obj).map((next: string) => { 11 | return obj[next] 12 | }) 13 | } 14 | 15 | export function deepCopy(obj: T): T { 16 | const newObj: any = Array.isArray(obj) ? [] : {} 17 | 18 | for (const key in obj) { 19 | if (obj.hasOwnProperty(key)) { 20 | const value: any = obj[key] 21 | if (typeof value === 'object') { 22 | if (value === null) { 23 | newObj[key] = null 24 | } else { 25 | newObj[key] = deepCopy(value) 26 | } 27 | } else { 28 | newObj[key] = value 29 | } 30 | } 31 | } 32 | 33 | return newObj 34 | } 35 | 36 | function isObject(obj: any): boolean { 37 | return obj !== null && typeof obj === 'object' 38 | } 39 | 40 | export function deepMerge( 41 | base: Base, 42 | update: Update, 43 | ): Base & Update { 44 | const newObj: any = Array.isArray(base) ? [] : {} 45 | const baseKeys: Array = Object.keys(base) 46 | const updateKeys: Array = Object.keys(update) 47 | 48 | for (const key of updateKeys) { 49 | if (baseKeys.indexOf(key) === -1) { 50 | baseKeys.push(key) 51 | } 52 | } 53 | 54 | for (const key of baseKeys) { 55 | if (base.hasOwnProperty(key) || update.hasOwnProperty(key)) { 56 | const baseValue: any = (base as any)[key] 57 | const updateValue: any = (update as any)[key] 58 | 59 | if (isObject(baseValue) && isObject(updateValue)) { 60 | newObj[key] = deepMerge(baseValue, updateValue) 61 | } else if (updateValue !== undefined) { 62 | newObj[key] = updateValue 63 | } else { 64 | newObj[key] = baseValue 65 | } 66 | } 67 | } 68 | 69 | return newObj as Base & Update 70 | } 71 | 72 | export function collectSourceFiles( 73 | sourceDir: string, 74 | files?: Array, 75 | ): Array { 76 | if (files && files.length > 0) { 77 | return files 78 | } else { 79 | return glob.sync(`${sourceDir}/**/*.thrift`) 80 | } 81 | } 82 | 83 | export function stubIdentifier(value: string): Identifier { 84 | return { 85 | type: SyntaxType.Identifier, 86 | value, 87 | annotations: undefined, 88 | loc: emptyLocation(), 89 | } 90 | } 91 | 92 | export function emptyLocation(): TextLocation { 93 | return { 94 | start: { line: 0, column: 0, index: 0 }, 95 | end: { line: 0, column: 0, index: 0 }, 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/main/validator/utils.ts: -------------------------------------------------------------------------------- 1 | import { 2 | ConstValue, 3 | FunctionType, 4 | SyntaxType, 5 | } from '@creditkarma/thrift-parser' 6 | 7 | /** 8 | * Takes a ConstValue type from our Thrift AST and generated a string representation of the TypeScript 9 | * type. This is just for making our error messages more readable to users. 10 | * 11 | * @param constValue 12 | */ 13 | export function constToTypeString(constValue: ConstValue): string { 14 | switch (constValue.type) { 15 | case SyntaxType.Identifier: 16 | return constValue.value 17 | 18 | case SyntaxType.StringLiteral: 19 | return 'string' 20 | 21 | case SyntaxType.IntConstant: 22 | case SyntaxType.DoubleConstant: 23 | return 'number' 24 | 25 | case SyntaxType.BooleanLiteral: 26 | return 'boolean' 27 | 28 | case SyntaxType.ConstList: 29 | return `Array<${constToTypeString(constValue.elements[0])}>` 30 | 31 | case SyntaxType.ConstMap: 32 | return `Map<${constToTypeString( 33 | constValue.properties[0].name, 34 | )},${constToTypeString(constValue.properties[0].initializer)}>` 35 | 36 | default: 37 | const msg: never = constValue 38 | throw new Error(`Non-exhaustive match for ${msg}`) 39 | } 40 | } 41 | 42 | /** 43 | * Takes a FunctionType type from our Thrift AST and generated a string representation of the TypeScript 44 | * type. This is just for making our error messages more readable to users. 45 | * 46 | * @param fieldType 47 | */ 48 | export function fieldTypeToString(fieldType: FunctionType): string { 49 | switch (fieldType.type) { 50 | case SyntaxType.Identifier: 51 | return fieldType.value 52 | 53 | case SyntaxType.SetType: 54 | return `Set<${fieldTypeToString(fieldType.valueType)}>` 55 | 56 | case SyntaxType.MapType: 57 | return `Map<${fieldTypeToString( 58 | fieldType.keyType, 59 | )},${fieldTypeToString(fieldType.valueType)}>` 60 | 61 | case SyntaxType.ListType: 62 | return `Array<${fieldTypeToString(fieldType.valueType)}>` 63 | 64 | case SyntaxType.StringKeyword: 65 | case SyntaxType.BinaryKeyword: 66 | return 'string' 67 | 68 | case SyntaxType.BoolKeyword: 69 | return 'boolean' 70 | 71 | case SyntaxType.I64Keyword: 72 | return 'Int64' 73 | 74 | case SyntaxType.DoubleKeyword: 75 | case SyntaxType.I8Keyword: 76 | case SyntaxType.I16Keyword: 77 | case SyntaxType.I32Keyword: 78 | case SyntaxType.ByteKeyword: 79 | return 'number' 80 | 81 | case SyntaxType.VoidKeyword: 82 | return 'void' 83 | 84 | default: 85 | const msg: never = fieldType 86 | throw new Error(`Non-exhaustive match for: ${msg}`) 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/tests/integration/apache/add-service.ts: -------------------------------------------------------------------------------- 1 | import { 2 | createWebServer, 3 | Int64, 4 | TBinaryProtocol, 5 | TBufferedTransport, 6 | } from 'thrift' 7 | 8 | import { AddService } from './codegen/com/test/add-service' 9 | 10 | import { Server } from 'net' 11 | 12 | export function createAddServer(): Server { 13 | // Handler: Implement the hello service 14 | const myServiceHandler: AddService.IHandler = { 15 | ping(): void { 16 | return 17 | }, 18 | add(a: number, b: number): number { 19 | return a + b 20 | }, 21 | addInt64(a: Int64, b: Int64): Int64 { 22 | return new Int64(a.toNumber() + b.toNumber()) 23 | }, 24 | } 25 | 26 | // ServiceOptions: The I/O stack for the service 27 | const myServiceOpts = { 28 | handler: myServiceHandler, 29 | processor: AddService, 30 | protocol: TBinaryProtocol, 31 | transport: TBufferedTransport, 32 | } 33 | 34 | // ServerOptions: Define server features 35 | const serverOpt = { 36 | services: { 37 | '/': myServiceOpts, 38 | }, 39 | } 40 | 41 | // Create and start the web server 42 | return createWebServer(serverOpt) 43 | } 44 | -------------------------------------------------------------------------------- /src/tests/integration/apache/config.ts: -------------------------------------------------------------------------------- 1 | export const CLIENT_CONFIG = { 2 | hostName: 'localhost', 3 | port: 8044, 4 | } 5 | 6 | export const CALC_SERVER_CONFIG = { 7 | hostName: 'localhost', 8 | port: 8054, 9 | } 10 | 11 | export const ADD_SERVER_CONFIG = { 12 | hostName: 'localhost', 13 | port: 8064, 14 | } 15 | -------------------------------------------------------------------------------- /src/tests/integration/thrift/add-service.thrift: -------------------------------------------------------------------------------- 1 | namespace java com.test.add-service 2 | namespace js com.test.add-service 3 | 4 | service AddService { 5 | 6 | void ping(), 7 | 8 | i32 add(1: i32 num1, 2: i32 num2), 9 | 10 | i64 addInt64(1: i64 num1, 2: i64 num2), 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/tests/integration/thrift/calculator.thrift: -------------------------------------------------------------------------------- 1 | include "shared.thrift" 2 | include "common/common.thrift" 3 | include "operation.thrift" 4 | 5 | namespace java com.test.calculator 6 | namespace js com.test.calculator 7 | 8 | typedef i32 MyInteger 9 | typedef operation.Operation Operation 10 | typedef common.CommonStruct CommonStruct 11 | 12 | const i32 INT32CONSTANT = 9853 13 | const map MAPCONSTANT = {'hello':'world', 'goodnight':'moon'} 14 | 15 | struct Work { 16 | 1: required i32 num1 = 0, 17 | 2: required i32 num2, 18 | 3: Operation op = Operation.ADD, 19 | 4: optional string comment, 20 | } 21 | 22 | struct FirstName { 23 | 1: string name 24 | } 25 | 26 | struct LastName { 27 | 1: string name 28 | } 29 | 30 | union Choice { 31 | 1: FirstName firstName 32 | 2: LastName lastName 33 | } 34 | 35 | exception ExceptionOne { 36 | 1: string message 37 | } 38 | 39 | exception ExceptionTwo { 40 | 1: string whatHappened 41 | } 42 | 43 | service Calculator extends shared.SharedService { 44 | 45 | void ping(), 46 | 47 | i32 add(1: i32 num1, 2: i32 num2) throws (1: operation.JankyResult exp), 48 | 49 | i64 addInt64(1: i64 num1, 2: i64 num2), 50 | 51 | i32 calculate(1:i32 logid, 2:Work work) throws (1: operation.JankyOperation ouch), 52 | 53 | string echoBinary(1: binary word) 54 | 55 | string echoString(1: string word) 56 | 57 | string checkName(1: Choice choice), 58 | 59 | string checkOptional(1: optional string type), 60 | 61 | list mapOneList(1: list arg) 62 | 63 | list mapValues(1: map arg) 64 | 65 | map listToMap(1: list> arg) 66 | 67 | common.CommonStruct fetchThing() 68 | 69 | void throw(1: i32 num) throws (1: ExceptionOne exp1, 2: ExceptionTwo exp2) 70 | 71 | oneway void zip() 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/tests/integration/thrift/common/common.thrift: -------------------------------------------------------------------------------- 1 | namespace java com.core.common 2 | namespace js com.core.common 3 | 4 | include "shared.thrift" 5 | 6 | typedef shared.SharedStruct CommonStruct 7 | typedef shared.SharedUnion CommonUnion 8 | typedef shared.SHARED_INT COMMON_INT 9 | 10 | exception AuthException { 11 | 1: i32 code 12 | 2: string message 13 | } 14 | 15 | union OtherCommonUnion { 16 | 1: string option1 17 | 2: i32 option2 18 | } 19 | 20 | typedef AuthException NotAllowed 21 | typedef OtherCommonUnion MoreOptions 22 | -------------------------------------------------------------------------------- /src/tests/integration/thrift/exceptions.thrift: -------------------------------------------------------------------------------- 1 | namespace java com.test.exceptions 2 | namespace js com.test.exceptions 3 | 4 | include "shared.thrift" 5 | 6 | exception InvalidOperation { 7 | 1: i32 whatOp, 8 | 2: string why 9 | } 10 | 11 | exception InvalidResult { 12 | 1: string message 13 | 2: shared.Code code 14 | } 15 | -------------------------------------------------------------------------------- /src/tests/integration/thrift/operation.thrift: -------------------------------------------------------------------------------- 1 | namespace java com.test.operation 2 | namespace js com.test.operation 3 | 4 | include "exceptions.thrift" 5 | 6 | typedef exceptions.InvalidOperation JankyOperation 7 | typedef exceptions.InvalidResult JankyResult 8 | 9 | enum Operation { 10 | ADD = 1, 11 | SUBTRACT = 2, 12 | MULTIPLY = 3, 13 | DIVIDE = 4 14 | } 15 | -------------------------------------------------------------------------------- /src/tests/integration/thrift/shared.thrift: -------------------------------------------------------------------------------- 1 | const i32 SHARED_INT = 45 2 | 3 | struct Code { 4 | 1: i64 status 5 | } 6 | 7 | struct SharedStruct { 8 | 1: required Code code 9 | 2: required string value 10 | } 11 | 12 | union SharedUnion { 13 | 1: string option1 14 | 2: string option2 15 | } 16 | 17 | enum SharedEnum { 18 | value1 19 | value2 20 | } 21 | 22 | service SharedServiceBase { 23 | SharedStruct getStruct(1: i32 key) 24 | } 25 | 26 | service SharedService extends SharedServiceBase { 27 | SharedUnion getUnion(1: i32 index) 28 | SharedEnum getEnum() 29 | } 30 | -------------------------------------------------------------------------------- /src/tests/integration/thrift/user.thrift: -------------------------------------------------------------------------------- 1 | namespace java com.test.user 2 | namespace js com.test.user 3 | 4 | struct User { 5 | 1: string name 6 | } 7 | 8 | service UserService { 9 | User getUser(1: i64 id) 10 | } 11 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/basic_const.solution.ts: -------------------------------------------------------------------------------- 1 | export const FALSE_CONST: boolean = false; 2 | export const INT_64: Int64 = new Int64(64); 3 | export const SET_CONST: Set = new Set(["hello", "world", "foo", "bar"]); 4 | export const MAP_CONST: Map = new Map([["hello", "world"], ["foo", "bar"]]); 5 | export const LIST_CONST: Array = ["hello", "world", "foo", "bar"]; 6 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/basic_enum.solution.ts: -------------------------------------------------------------------------------- 1 | export enum MyEnum { 2 | ONE = 0, 3 | TWO = 1, 4 | THREE = 2 5 | } 6 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/basic_exception.solution.ts: -------------------------------------------------------------------------------- 1 | export interface IMyExceptionArgs { 2 | message: string; 3 | } 4 | export class MyException { 5 | public message: string; 6 | constructor(args: IMyExceptionArgs) { 7 | if (args != null && args.message != null) { 8 | this.message = args.message; 9 | } 10 | else { 11 | throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Required field[message] is unset!"); 12 | } 13 | } 14 | public write(output: thrift.TProtocol): void { 15 | output.writeStructBegin("MyException"); 16 | if (this.message != null) { 17 | output.writeFieldBegin("message", thrift.Thrift.Type.STRING, 1); 18 | output.writeString(this.message); 19 | output.writeFieldEnd(); 20 | } 21 | output.writeFieldStop(); 22 | output.writeStructEnd(); 23 | return; 24 | } 25 | public static read(input: thrift.TProtocol): MyException { 26 | input.readStructBegin(); 27 | let _args: any = {}; 28 | while (true) { 29 | const ret: thrift.TField = input.readFieldBegin(); 30 | const fieldType: thrift.Thrift.Type = ret.ftype; 31 | const fieldId: number = ret.fid; 32 | if (fieldType === thrift.Thrift.Type.STOP) { 33 | break; 34 | } 35 | switch (fieldId) { 36 | case 1: 37 | if (fieldType === thrift.Thrift.Type.STRING) { 38 | const value_1: string = input.readString(); 39 | _args.message = value_1; 40 | } 41 | else { 42 | input.skip(fieldType); 43 | } 44 | break; 45 | default: { 46 | input.skip(fieldType); 47 | } 48 | } 49 | input.readFieldEnd(); 50 | } 51 | input.readStructEnd(); 52 | if (_args.message !== undefined) { 53 | return new MyException(_args); 54 | } 55 | else { 56 | throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Unable to read MyException from input"); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/basic_typedef.solution.ts: -------------------------------------------------------------------------------- 1 | export type name = string; 2 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/complex_typedef.solution.ts: -------------------------------------------------------------------------------- 1 | export enum MyEnum { 2 | ONE = 0, 3 | TWO = 1 4 | } 5 | export type MyInt = number; 6 | export import AnotherName = MyEnum; 7 | export const INT_32: number = 32; 8 | export const WHAT: AnotherName = AnotherName.ONE; 9 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/enum_typedef.solution.ts: -------------------------------------------------------------------------------- 1 | export enum MyEnum { 2 | ONE = 0, 3 | TWO = 1 4 | } 5 | export import AnotherName = MyEnum; 6 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/field_initialized_enum.solution.ts: -------------------------------------------------------------------------------- 1 | export enum MyEnum { 2 | ONE = 5, 3 | TWO = 3, 4 | THREE = 6 5 | } 6 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/generated/Code.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import Int64 = require("node-int64"); 8 | import * as thrift from "test-lib"; 9 | export interface ICodeArgs { 10 | status?: number | Int64; 11 | } 12 | export class Code { 13 | public status?: Int64; 14 | constructor(args?: ICodeArgs) { 15 | if (args != null && args.status != null) { 16 | if (typeof args.status === "number") { 17 | this.status = new Int64(args.status); 18 | } 19 | else { 20 | this.status = args.status; 21 | } 22 | } 23 | } 24 | public write(output: thrift.TProtocol): void { 25 | output.writeStructBegin("Code"); 26 | if (this.status != null) { 27 | output.writeFieldBegin("status", thrift.Thrift.Type.I64, 1); 28 | output.writeI64(this.status); 29 | output.writeFieldEnd(); 30 | } 31 | output.writeFieldStop(); 32 | output.writeStructEnd(); 33 | return; 34 | } 35 | public static read(input: thrift.TProtocol): Code { 36 | input.readStructBegin(); 37 | let _args: any = {}; 38 | while (true) { 39 | const ret: thrift.TField = input.readFieldBegin(); 40 | const fieldType: thrift.Thrift.Type = ret.ftype; 41 | const fieldId: number = ret.fid; 42 | if (fieldType === thrift.Thrift.Type.STOP) { 43 | break; 44 | } 45 | switch (fieldId) { 46 | case 1: 47 | if (fieldType === thrift.Thrift.Type.I64) { 48 | const value_1: Int64 = input.readI64(); 49 | _args.status = value_1; 50 | } 51 | else { 52 | input.skip(fieldType); 53 | } 54 | break; 55 | default: { 56 | input.skip(fieldType); 57 | } 58 | } 59 | input.readFieldEnd(); 60 | } 61 | input.readStructEnd(); 62 | return new Code(_args); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/generated/SharedEnum.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | export enum SharedEnum { 8 | value1 = 0, 9 | value2 = 1 10 | } 11 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/generated/SharedStruct.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as thrift from "test-lib"; 8 | import * as Code from "./Code"; 9 | export interface ISharedStructArgs { 10 | code: Code.Code; 11 | value: string; 12 | } 13 | export class SharedStruct { 14 | public code: Code.Code; 15 | public value: string; 16 | constructor(args: ISharedStructArgs) { 17 | if (args != null && args.code != null) { 18 | this.code = args.code; 19 | } 20 | else { 21 | throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Required field[code] is unset!"); 22 | } 23 | if (args != null && args.value != null) { 24 | this.value = args.value; 25 | } 26 | else { 27 | throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Required field[value] is unset!"); 28 | } 29 | } 30 | public write(output: thrift.TProtocol): void { 31 | output.writeStructBegin("SharedStruct"); 32 | if (this.code != null) { 33 | output.writeFieldBegin("code", thrift.Thrift.Type.STRUCT, 1); 34 | this.code.write(output); 35 | output.writeFieldEnd(); 36 | } 37 | if (this.value != null) { 38 | output.writeFieldBegin("value", thrift.Thrift.Type.STRING, 2); 39 | output.writeString(this.value); 40 | output.writeFieldEnd(); 41 | } 42 | output.writeFieldStop(); 43 | output.writeStructEnd(); 44 | return; 45 | } 46 | public static read(input: thrift.TProtocol): SharedStruct { 47 | input.readStructBegin(); 48 | let _args: any = {}; 49 | while (true) { 50 | const ret: thrift.TField = input.readFieldBegin(); 51 | const fieldType: thrift.Thrift.Type = ret.ftype; 52 | const fieldId: number = ret.fid; 53 | if (fieldType === thrift.Thrift.Type.STOP) { 54 | break; 55 | } 56 | switch (fieldId) { 57 | case 1: 58 | if (fieldType === thrift.Thrift.Type.STRUCT) { 59 | const value_1: Code.Code = Code.Code.read(input); 60 | _args.code = value_1; 61 | } 62 | else { 63 | input.skip(fieldType); 64 | } 65 | break; 66 | case 2: 67 | if (fieldType === thrift.Thrift.Type.STRING) { 68 | const value_2: string = input.readString(); 69 | _args.value = value_2; 70 | } 71 | else { 72 | input.skip(fieldType); 73 | } 74 | break; 75 | default: { 76 | input.skip(fieldType); 77 | } 78 | } 79 | input.readFieldEnd(); 80 | } 81 | input.readStructEnd(); 82 | if (_args.code !== undefined && _args.value !== undefined) { 83 | return new SharedStruct(_args); 84 | } 85 | else { 86 | throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Unable to read SharedStruct from input"); 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/generated/com/test/calculator/CommonStruct.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as com_test_common from "./../common"; 8 | export import CommonStruct = com_test_common.CommonStruct; 9 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/generated/com/test/calculator/FirstName.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as thrift from "test-lib"; 8 | export interface IFirstNameArgs { 9 | name?: string; 10 | } 11 | export class FirstName { 12 | public name?: string; 13 | constructor(args?: IFirstNameArgs) { 14 | if (args != null && args.name != null) { 15 | this.name = args.name; 16 | } 17 | } 18 | public write(output: thrift.TProtocol): void { 19 | output.writeStructBegin("FirstName"); 20 | if (this.name != null) { 21 | output.writeFieldBegin("name", thrift.Thrift.Type.STRING, 1); 22 | output.writeString(this.name); 23 | output.writeFieldEnd(); 24 | } 25 | output.writeFieldStop(); 26 | output.writeStructEnd(); 27 | return; 28 | } 29 | public static read(input: thrift.TProtocol): FirstName { 30 | input.readStructBegin(); 31 | let _args: any = {}; 32 | while (true) { 33 | const ret: thrift.TField = input.readFieldBegin(); 34 | const fieldType: thrift.Thrift.Type = ret.ftype; 35 | const fieldId: number = ret.fid; 36 | if (fieldType === thrift.Thrift.Type.STOP) { 37 | break; 38 | } 39 | switch (fieldId) { 40 | case 1: 41 | if (fieldType === thrift.Thrift.Type.STRING) { 42 | const value_1: string = input.readString(); 43 | _args.name = value_1; 44 | } 45 | else { 46 | input.skip(fieldType); 47 | } 48 | break; 49 | default: { 50 | input.skip(fieldType); 51 | } 52 | } 53 | input.readFieldEnd(); 54 | } 55 | input.readStructEnd(); 56 | return new FirstName(_args); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/generated/com/test/calculator/LastName.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as thrift from "test-lib"; 8 | export interface ILastNameArgs { 9 | name?: string; 10 | } 11 | export class LastName { 12 | public name?: string; 13 | constructor(args?: ILastNameArgs) { 14 | if (args != null && args.name != null) { 15 | this.name = args.name; 16 | } 17 | } 18 | public write(output: thrift.TProtocol): void { 19 | output.writeStructBegin("LastName"); 20 | if (this.name != null) { 21 | output.writeFieldBegin("name", thrift.Thrift.Type.STRING, 1); 22 | output.writeString(this.name); 23 | output.writeFieldEnd(); 24 | } 25 | output.writeFieldStop(); 26 | output.writeStructEnd(); 27 | return; 28 | } 29 | public static read(input: thrift.TProtocol): LastName { 30 | input.readStructBegin(); 31 | let _args: any = {}; 32 | while (true) { 33 | const ret: thrift.TField = input.readFieldBegin(); 34 | const fieldType: thrift.Thrift.Type = ret.ftype; 35 | const fieldId: number = ret.fid; 36 | if (fieldType === thrift.Thrift.Type.STOP) { 37 | break; 38 | } 39 | switch (fieldId) { 40 | case 1: 41 | if (fieldType === thrift.Thrift.Type.STRING) { 42 | const value_1: string = input.readString(); 43 | _args.name = value_1; 44 | } 45 | else { 46 | input.skip(fieldType); 47 | } 48 | break; 49 | default: { 50 | input.skip(fieldType); 51 | } 52 | } 53 | input.readFieldEnd(); 54 | } 55 | input.readStructEnd(); 56 | return new LastName(_args); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/generated/com/test/calculator/MyInteger.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | export type MyInteger = number; 8 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/generated/com/test/calculator/NotAGoodIdea.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as thrift from "test-lib"; 8 | import * as CommonStruct from "./CommonStruct"; 9 | import * as TypedMap from "./TypedMap"; 10 | export interface INotAGoodIdeaArgs { 11 | message?: string; 12 | data?: TypedMap.TypedMap; 13 | } 14 | export class NotAGoodIdea { 15 | public message?: string; 16 | public data?: TypedMap.TypedMap; 17 | constructor(args?: INotAGoodIdeaArgs) { 18 | if (args != null && args.message != null) { 19 | this.message = args.message; 20 | } 21 | if (args != null && args.data != null) { 22 | this.data = args.data; 23 | } 24 | } 25 | public write(output: thrift.TProtocol): void { 26 | output.writeStructBegin("NotAGoodIdea"); 27 | if (this.message != null) { 28 | output.writeFieldBegin("message", thrift.Thrift.Type.STRING, 1); 29 | output.writeString(this.message); 30 | output.writeFieldEnd(); 31 | } 32 | if (this.data != null) { 33 | output.writeFieldBegin("data", thrift.Thrift.Type.MAP, 2); 34 | output.writeMapBegin(thrift.Thrift.Type.STRING, thrift.Thrift.Type.STRUCT, this.data.size); 35 | this.data.forEach((value_1: CommonStruct.CommonStruct, key_1: string): void => { 36 | output.writeString(key_1); 37 | value_1.write(output); 38 | }); 39 | output.writeMapEnd(); 40 | output.writeFieldEnd(); 41 | } 42 | output.writeFieldStop(); 43 | output.writeStructEnd(); 44 | return; 45 | } 46 | public static read(input: thrift.TProtocol): NotAGoodIdea { 47 | input.readStructBegin(); 48 | let _args: any = {}; 49 | while (true) { 50 | const ret: thrift.TField = input.readFieldBegin(); 51 | const fieldType: thrift.Thrift.Type = ret.ftype; 52 | const fieldId: number = ret.fid; 53 | if (fieldType === thrift.Thrift.Type.STOP) { 54 | break; 55 | } 56 | switch (fieldId) { 57 | case 1: 58 | if (fieldType === thrift.Thrift.Type.STRING) { 59 | const value_2: string = input.readString(); 60 | _args.message = value_2; 61 | } 62 | else { 63 | input.skip(fieldType); 64 | } 65 | break; 66 | case 2: 67 | if (fieldType === thrift.Thrift.Type.MAP) { 68 | const value_3: Map = new Map(); 69 | const metadata_1: thrift.TMap = input.readMapBegin(); 70 | const size_1: number = metadata_1.size; 71 | for (let i_1: number = 0; i_1 < size_1; i_1++) { 72 | const key_2: string = input.readString(); 73 | const value_4: CommonStruct.CommonStruct = CommonStruct.CommonStruct.read(input); 74 | value_3.set(key_2, value_4); 75 | } 76 | input.readMapEnd(); 77 | _args.data = value_3; 78 | } 79 | else { 80 | input.skip(fieldType); 81 | } 82 | break; 83 | default: { 84 | input.skip(fieldType); 85 | } 86 | } 87 | input.readFieldEnd(); 88 | } 89 | input.readStructEnd(); 90 | return new NotAGoodIdea(_args); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/generated/com/test/calculator/Operation.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as com_test_operation from "./../operation"; 8 | export import Operation = com_test_operation.Operation; 9 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/generated/com/test/calculator/TypedMap.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as CommonStruct from "./CommonStruct"; 8 | export type TypedMap = Map; 9 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/generated/com/test/calculator/constants.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | export const INT32CONSTANT: number = 9853; 8 | export const MAPCONSTANT: Map = new Map([["hello", "world"], ["goodnight", "moon"]]); 9 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/generated/com/test/calculator/index.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | export * from "./constants"; 8 | export * from "./MyInteger"; 9 | export * from "./Operation"; 10 | export * from "./CommonStruct"; 11 | export * from "./TypedMap"; 12 | export * from "./Work"; 13 | export * from "./FirstName"; 14 | export * from "./LastName"; 15 | export * from "./Choice"; 16 | export * from "./NotAGoodIdea"; 17 | import * as Calculator from "./Calculator"; 18 | export { Calculator as Calculator }; 19 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/generated/com/test/common/AuthException.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as thrift from "test-lib"; 8 | export interface IAuthExceptionArgs { 9 | code?: number; 10 | message?: string; 11 | } 12 | export class AuthException { 13 | public code?: number; 14 | public message?: string; 15 | constructor(args?: IAuthExceptionArgs) { 16 | if (args != null && args.code != null) { 17 | this.code = args.code; 18 | } 19 | if (args != null && args.message != null) { 20 | this.message = args.message; 21 | } 22 | } 23 | public write(output: thrift.TProtocol): void { 24 | output.writeStructBegin("AuthException"); 25 | if (this.code != null) { 26 | output.writeFieldBegin("code", thrift.Thrift.Type.I32, 1); 27 | output.writeI32(this.code); 28 | output.writeFieldEnd(); 29 | } 30 | if (this.message != null) { 31 | output.writeFieldBegin("message", thrift.Thrift.Type.STRING, 2); 32 | output.writeString(this.message); 33 | output.writeFieldEnd(); 34 | } 35 | output.writeFieldStop(); 36 | output.writeStructEnd(); 37 | return; 38 | } 39 | public static read(input: thrift.TProtocol): AuthException { 40 | input.readStructBegin(); 41 | let _args: any = {}; 42 | while (true) { 43 | const ret: thrift.TField = input.readFieldBegin(); 44 | const fieldType: thrift.Thrift.Type = ret.ftype; 45 | const fieldId: number = ret.fid; 46 | if (fieldType === thrift.Thrift.Type.STOP) { 47 | break; 48 | } 49 | switch (fieldId) { 50 | case 1: 51 | if (fieldType === thrift.Thrift.Type.I32) { 52 | const value_1: number = input.readI32(); 53 | _args.code = value_1; 54 | } 55 | else { 56 | input.skip(fieldType); 57 | } 58 | break; 59 | case 2: 60 | if (fieldType === thrift.Thrift.Type.STRING) { 61 | const value_2: string = input.readString(); 62 | _args.message = value_2; 63 | } 64 | else { 65 | input.skip(fieldType); 66 | } 67 | break; 68 | default: { 69 | input.skip(fieldType); 70 | } 71 | } 72 | input.readFieldEnd(); 73 | } 74 | input.readStructEnd(); 75 | return new AuthException(_args); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/generated/com/test/common/COMMON_INT.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as __ROOT_NAMESPACE__ from "./../../.."; 8 | export import COMMON_INT = __ROOT_NAMESPACE__.SHARED_INT; 9 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/generated/com/test/common/CommonEnum.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as __ROOT_NAMESPACE__ from "./../../.."; 8 | export import CommonEnum = __ROOT_NAMESPACE__.SharedEnum; 9 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/generated/com/test/common/CommonStruct.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as __ROOT_NAMESPACE__ from "./../../.."; 8 | export import CommonStruct = __ROOT_NAMESPACE__.SharedStruct; 9 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/generated/com/test/common/CommonUnion.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as __ROOT_NAMESPACE__ from "./../../.."; 8 | export import CommonUnion = __ROOT_NAMESPACE__.SharedUnion; 9 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/generated/com/test/common/MoreOptions.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as OtherCommonUnion from "./OtherCommonUnion"; 8 | export import MoreOptions = OtherCommonUnion.OtherCommonUnion; 9 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/generated/com/test/common/NotAllowed.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as AuthException from "./AuthException"; 8 | export import NotAllowed = AuthException.AuthException; 9 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/generated/com/test/common/index.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | export * from "./CommonStruct"; 8 | export * from "./CommonUnion"; 9 | export * from "./CommonEnum"; 10 | export * from "./COMMON_INT"; 11 | export * from "./NotAllowed"; 12 | export * from "./MoreOptions"; 13 | export * from "./OtherCommonUnion"; 14 | export * from "./AuthException"; 15 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/generated/com/test/exceptions/InvalidOperation.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as thrift from "test-lib"; 8 | export interface IInvalidOperationArgs { 9 | whatOp?: number; 10 | why?: string; 11 | } 12 | export class InvalidOperation { 13 | public whatOp?: number; 14 | public why?: string; 15 | constructor(args?: IInvalidOperationArgs) { 16 | if (args != null && args.whatOp != null) { 17 | this.whatOp = args.whatOp; 18 | } 19 | if (args != null && args.why != null) { 20 | this.why = args.why; 21 | } 22 | } 23 | public write(output: thrift.TProtocol): void { 24 | output.writeStructBegin("InvalidOperation"); 25 | if (this.whatOp != null) { 26 | output.writeFieldBegin("whatOp", thrift.Thrift.Type.I32, 1); 27 | output.writeI32(this.whatOp); 28 | output.writeFieldEnd(); 29 | } 30 | if (this.why != null) { 31 | output.writeFieldBegin("why", thrift.Thrift.Type.STRING, 2); 32 | output.writeString(this.why); 33 | output.writeFieldEnd(); 34 | } 35 | output.writeFieldStop(); 36 | output.writeStructEnd(); 37 | return; 38 | } 39 | public static read(input: thrift.TProtocol): InvalidOperation { 40 | input.readStructBegin(); 41 | let _args: any = {}; 42 | while (true) { 43 | const ret: thrift.TField = input.readFieldBegin(); 44 | const fieldType: thrift.Thrift.Type = ret.ftype; 45 | const fieldId: number = ret.fid; 46 | if (fieldType === thrift.Thrift.Type.STOP) { 47 | break; 48 | } 49 | switch (fieldId) { 50 | case 1: 51 | if (fieldType === thrift.Thrift.Type.I32) { 52 | const value_1: number = input.readI32(); 53 | _args.whatOp = value_1; 54 | } 55 | else { 56 | input.skip(fieldType); 57 | } 58 | break; 59 | case 2: 60 | if (fieldType === thrift.Thrift.Type.STRING) { 61 | const value_2: string = input.readString(); 62 | _args.why = value_2; 63 | } 64 | else { 65 | input.skip(fieldType); 66 | } 67 | break; 68 | default: { 69 | input.skip(fieldType); 70 | } 71 | } 72 | input.readFieldEnd(); 73 | } 74 | input.readStructEnd(); 75 | return new InvalidOperation(_args); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/generated/com/test/exceptions/InvalidResult.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as thrift from "test-lib"; 8 | import * as __ROOT_NAMESPACE__ from "./../../.."; 9 | export interface IInvalidResultArgs { 10 | message?: string; 11 | code?: __ROOT_NAMESPACE__.Code; 12 | } 13 | export class InvalidResult { 14 | public message?: string; 15 | public code?: __ROOT_NAMESPACE__.Code; 16 | constructor(args?: IInvalidResultArgs) { 17 | if (args != null && args.message != null) { 18 | this.message = args.message; 19 | } 20 | if (args != null && args.code != null) { 21 | this.code = args.code; 22 | } 23 | } 24 | public write(output: thrift.TProtocol): void { 25 | output.writeStructBegin("InvalidResult"); 26 | if (this.message != null) { 27 | output.writeFieldBegin("message", thrift.Thrift.Type.STRING, 1); 28 | output.writeString(this.message); 29 | output.writeFieldEnd(); 30 | } 31 | if (this.code != null) { 32 | output.writeFieldBegin("code", thrift.Thrift.Type.STRUCT, 2); 33 | this.code.write(output); 34 | output.writeFieldEnd(); 35 | } 36 | output.writeFieldStop(); 37 | output.writeStructEnd(); 38 | return; 39 | } 40 | public static read(input: thrift.TProtocol): InvalidResult { 41 | input.readStructBegin(); 42 | let _args: any = {}; 43 | while (true) { 44 | const ret: thrift.TField = input.readFieldBegin(); 45 | const fieldType: thrift.Thrift.Type = ret.ftype; 46 | const fieldId: number = ret.fid; 47 | if (fieldType === thrift.Thrift.Type.STOP) { 48 | break; 49 | } 50 | switch (fieldId) { 51 | case 1: 52 | if (fieldType === thrift.Thrift.Type.STRING) { 53 | const value_1: string = input.readString(); 54 | _args.message = value_1; 55 | } 56 | else { 57 | input.skip(fieldType); 58 | } 59 | break; 60 | case 2: 61 | if (fieldType === thrift.Thrift.Type.STRUCT) { 62 | const value_2: __ROOT_NAMESPACE__.Code = __ROOT_NAMESPACE__.Code.read(input); 63 | _args.code = value_2; 64 | } 65 | else { 66 | input.skip(fieldType); 67 | } 68 | break; 69 | default: { 70 | input.skip(fieldType); 71 | } 72 | } 73 | input.readFieldEnd(); 74 | } 75 | input.readStructEnd(); 76 | return new InvalidResult(_args); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/generated/com/test/exceptions/index.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | export * from "./InvalidOperation"; 8 | export * from "./InvalidResult"; 9 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/generated/com/test/operation/JankyOperation.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as com_test_exceptions from "./../exceptions"; 8 | export import JankyOperation = com_test_exceptions.InvalidOperation; 9 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/generated/com/test/operation/JankyResult.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as com_test_exceptions from "./../exceptions"; 8 | export import JankyResult = com_test_exceptions.InvalidResult; 9 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/generated/com/test/operation/Operation.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | export enum Operation { 8 | ADD = 1, 9 | SUBTRACT = 2, 10 | MULTIPLY = 3, 11 | DIVIDE = 4 12 | } 13 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/generated/com/test/operation/SomethingToDo.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as Operation from "./Operation"; 8 | export import SomethingToDo = Operation.Operation; 9 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/generated/com/test/operation/index.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | export * from "./Operation"; 8 | export * from "./JankyOperation"; 9 | export * from "./JankyResult"; 10 | export * from "./SomethingToDo"; 11 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/generated/constants.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | export const SHARED_INT: number = 45; 8 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/generated/index.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | export * from "./constants"; 8 | export * from "./SharedEnum"; 9 | export * from "./Code"; 10 | export * from "./SharedStruct"; 11 | export * from "./SharedUnion"; 12 | import * as SharedServiceBase from "./SharedServiceBase"; 13 | export { SharedServiceBase as SharedServiceBase }; 14 | import * as SharedService from "./SharedService"; 15 | export { SharedService as SharedService }; 16 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/implicit_optional_struct.solution.ts: -------------------------------------------------------------------------------- 1 | export interface IMyStructArgs { 2 | id?: number; 3 | name?: string; 4 | } 5 | export class MyStruct { 6 | public id?: number; 7 | public name?: string; 8 | constructor(args?: IMyStructArgs) { 9 | if (args != null && args.id != null) { 10 | this.id = args.id; 11 | } 12 | if (args != null && args.name != null) { 13 | this.name = args.name; 14 | } 15 | } 16 | public write(output: thrift.TProtocol): void { 17 | output.writeStructBegin("MyStruct"); 18 | if (this.id != null) { 19 | output.writeFieldBegin("id", thrift.Thrift.Type.I32, 1); 20 | output.writeI32(this.id); 21 | output.writeFieldEnd(); 22 | } 23 | if (this.name != null) { 24 | output.writeFieldBegin("name", thrift.Thrift.Type.STRING, 2); 25 | output.writeString(this.name); 26 | output.writeFieldEnd(); 27 | } 28 | output.writeFieldStop(); 29 | output.writeStructEnd(); 30 | return; 31 | } 32 | public static read(input: thrift.TProtocol): MyStruct { 33 | input.readStructBegin(); 34 | let _args: any = {}; 35 | while (true) { 36 | const ret: thrift.TField = input.readFieldBegin(); 37 | const fieldType: thrift.Thrift.Type = ret.ftype; 38 | const fieldId: number = ret.fid; 39 | if (fieldType === thrift.Thrift.Type.STOP) { 40 | break; 41 | } 42 | switch (fieldId) { 43 | case 1: 44 | if (fieldType === thrift.Thrift.Type.I32) { 45 | const value_1: number = input.readI32(); 46 | _args.id = value_1; 47 | } 48 | else { 49 | input.skip(fieldType); 50 | } 51 | break; 52 | case 2: 53 | if (fieldType === thrift.Thrift.Type.STRING) { 54 | const value_2: string = input.readString(); 55 | _args.name = value_2; 56 | } 57 | else { 58 | input.skip(fieldType); 59 | } 60 | break; 61 | default: { 62 | input.skip(fieldType); 63 | } 64 | } 65 | input.readFieldEnd(); 66 | } 67 | input.readStructEnd(); 68 | return new MyStruct(_args); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/list_struct.solution.ts: -------------------------------------------------------------------------------- 1 | export interface IMyStructArgs { 2 | field1: Array; 3 | } 4 | export class MyStruct { 5 | public field1: Array; 6 | constructor(args: IMyStructArgs) { 7 | if (args != null && args.field1 != null) { 8 | this.field1 = args.field1; 9 | } 10 | else { 11 | throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Required field[field1] is unset!"); 12 | } 13 | } 14 | public write(output: thrift.TProtocol): void { 15 | output.writeStructBegin("MyStruct"); 16 | if (this.field1 != null) { 17 | output.writeFieldBegin("field1", thrift.Thrift.Type.LIST, 1); 18 | output.writeListBegin(thrift.Thrift.Type.STRING, this.field1.length); 19 | this.field1.forEach((value_1: string): void => { 20 | output.writeString(value_1); 21 | }); 22 | output.writeListEnd(); 23 | output.writeFieldEnd(); 24 | } 25 | output.writeFieldStop(); 26 | output.writeStructEnd(); 27 | return; 28 | } 29 | public static read(input: thrift.TProtocol): MyStruct { 30 | input.readStructBegin(); 31 | let _args: any = {}; 32 | while (true) { 33 | const ret: thrift.TField = input.readFieldBegin(); 34 | const fieldType: thrift.Thrift.Type = ret.ftype; 35 | const fieldId: number = ret.fid; 36 | if (fieldType === thrift.Thrift.Type.STOP) { 37 | break; 38 | } 39 | switch (fieldId) { 40 | case 1: 41 | if (fieldType === thrift.Thrift.Type.LIST) { 42 | const value_2: Array = new Array(); 43 | const metadata_1: thrift.TList = input.readListBegin(); 44 | const size_1: number = metadata_1.size; 45 | for (let i_1: number = 0; i_1 < size_1; i_1++) { 46 | const value_3: string = input.readString(); 47 | value_2.push(value_3); 48 | } 49 | input.readListEnd(); 50 | _args.field1 = value_2; 51 | } 52 | else { 53 | input.skip(fieldType); 54 | } 55 | break; 56 | default: { 57 | input.skip(fieldType); 58 | } 59 | } 60 | input.readFieldEnd(); 61 | } 62 | input.readStructEnd(); 63 | if (_args.field1 !== undefined) { 64 | return new MyStruct(_args); 65 | } 66 | else { 67 | throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Unable to read MyStruct from input"); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/map_struct.solution.ts: -------------------------------------------------------------------------------- 1 | export interface IMyStructArgs { 2 | field1: Map; 3 | } 4 | export class MyStruct { 5 | public field1: Map; 6 | constructor(args: IMyStructArgs) { 7 | if (args != null && args.field1 != null) { 8 | this.field1 = args.field1; 9 | } 10 | else { 11 | throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Required field[field1] is unset!"); 12 | } 13 | } 14 | public write(output: thrift.TProtocol): void { 15 | output.writeStructBegin("MyStruct"); 16 | if (this.field1 != null) { 17 | output.writeFieldBegin("field1", thrift.Thrift.Type.MAP, 1); 18 | output.writeMapBegin(thrift.Thrift.Type.STRING, thrift.Thrift.Type.STRING, this.field1.size); 19 | this.field1.forEach((value_1: string, key_1: string): void => { 20 | output.writeString(key_1); 21 | output.writeString(value_1); 22 | }); 23 | output.writeMapEnd(); 24 | output.writeFieldEnd(); 25 | } 26 | output.writeFieldStop(); 27 | output.writeStructEnd(); 28 | return; 29 | } 30 | public static read(input: thrift.TProtocol): MyStruct { 31 | input.readStructBegin(); 32 | let _args: any = {}; 33 | while (true) { 34 | const ret: thrift.TField = input.readFieldBegin(); 35 | const fieldType: thrift.Thrift.Type = ret.ftype; 36 | const fieldId: number = ret.fid; 37 | if (fieldType === thrift.Thrift.Type.STOP) { 38 | break; 39 | } 40 | switch (fieldId) { 41 | case 1: 42 | if (fieldType === thrift.Thrift.Type.MAP) { 43 | const value_2: Map = new Map(); 44 | const metadata_1: thrift.TMap = input.readMapBegin(); 45 | const size_1: number = metadata_1.size; 46 | for (let i_1: number = 0; i_1 < size_1; i_1++) { 47 | const key_2: string = input.readString(); 48 | const value_3: string = input.readString(); 49 | value_2.set(key_2, value_3); 50 | } 51 | input.readMapEnd(); 52 | _args.field1 = value_2; 53 | } 54 | else { 55 | input.skip(fieldType); 56 | } 57 | break; 58 | default: { 59 | input.skip(fieldType); 60 | } 61 | } 62 | input.readFieldEnd(); 63 | } 64 | input.readStructEnd(); 65 | if (_args.field1 !== undefined) { 66 | return new MyStruct(_args); 67 | } 68 | else { 69 | throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Unable to read MyStruct from input"); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/nested_list_struct.solution.ts: -------------------------------------------------------------------------------- 1 | export interface IMyStructArgs { 2 | field1: Array>; 3 | } 4 | export class MyStruct { 5 | public field1: Array>; 6 | constructor(args: IMyStructArgs) { 7 | if (args != null && args.field1 != null) { 8 | this.field1 = args.field1; 9 | } 10 | else { 11 | throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Required field[field1] is unset!"); 12 | } 13 | } 14 | public write(output: thrift.TProtocol): void { 15 | output.writeStructBegin("MyStruct"); 16 | if (this.field1 != null) { 17 | output.writeFieldBegin("field1", thrift.Thrift.Type.LIST, 1); 18 | output.writeListBegin(thrift.Thrift.Type.LIST, this.field1.length); 19 | this.field1.forEach((value_1: Array): void => { 20 | output.writeListBegin(thrift.Thrift.Type.STRING, value_1.length); 21 | value_1.forEach((value_2: string): void => { 22 | output.writeString(value_2); 23 | }); 24 | output.writeListEnd(); 25 | }); 26 | output.writeListEnd(); 27 | output.writeFieldEnd(); 28 | } 29 | output.writeFieldStop(); 30 | output.writeStructEnd(); 31 | return; 32 | } 33 | public static read(input: thrift.TProtocol): MyStruct { 34 | input.readStructBegin(); 35 | let _args: any = {}; 36 | while (true) { 37 | const ret: thrift.TField = input.readFieldBegin(); 38 | const fieldType: thrift.Thrift.Type = ret.ftype; 39 | const fieldId: number = ret.fid; 40 | if (fieldType === thrift.Thrift.Type.STOP) { 41 | break; 42 | } 43 | switch (fieldId) { 44 | case 1: 45 | if (fieldType === thrift.Thrift.Type.LIST) { 46 | const value_3: Array> = new Array>(); 47 | const metadata_1: thrift.TList = input.readListBegin(); 48 | const size_1: number = metadata_1.size; 49 | for (let i_1: number = 0; i_1 < size_1; i_1++) { 50 | const value_4: Array = new Array(); 51 | const metadata_2: thrift.TList = input.readListBegin(); 52 | const size_2: number = metadata_2.size; 53 | for (let i_2: number = 0; i_2 < size_2; i_2++) { 54 | const value_5: string = input.readString(); 55 | value_4.push(value_5); 56 | } 57 | input.readListEnd(); 58 | value_3.push(value_4); 59 | } 60 | input.readListEnd(); 61 | _args.field1 = value_3; 62 | } 63 | else { 64 | input.skip(fieldType); 65 | } 66 | break; 67 | default: { 68 | input.skip(fieldType); 69 | } 70 | } 71 | input.readFieldEnd(); 72 | } 73 | input.readStructEnd(); 74 | if (_args.field1 !== undefined) { 75 | return new MyStruct(_args); 76 | } 77 | else { 78 | throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Unable to read MyStruct from input"); 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/nested_map_struct.solution.ts: -------------------------------------------------------------------------------- 1 | export interface IMyStructArgs { 2 | field1: Map>; 3 | } 4 | export class MyStruct { 5 | public field1: Map>; 6 | constructor(args: IMyStructArgs) { 7 | if (args != null && args.field1 != null) { 8 | this.field1 = args.field1; 9 | } 10 | else { 11 | throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Required field[field1] is unset!"); 12 | } 13 | } 14 | public write(output: thrift.TProtocol): void { 15 | output.writeStructBegin("MyStruct"); 16 | if (this.field1 != null) { 17 | output.writeFieldBegin("field1", thrift.Thrift.Type.MAP, 1); 18 | output.writeMapBegin(thrift.Thrift.Type.STRING, thrift.Thrift.Type.MAP, this.field1.size); 19 | this.field1.forEach((value_1: Map, key_1: string): void => { 20 | output.writeString(key_1); 21 | output.writeMapBegin(thrift.Thrift.Type.STRING, thrift.Thrift.Type.I32, value_1.size); 22 | value_1.forEach((value_2: number, key_2: string): void => { 23 | output.writeString(key_2); 24 | output.writeI32(value_2); 25 | }); 26 | output.writeMapEnd(); 27 | }); 28 | output.writeMapEnd(); 29 | output.writeFieldEnd(); 30 | } 31 | output.writeFieldStop(); 32 | output.writeStructEnd(); 33 | return; 34 | } 35 | public static read(input: thrift.TProtocol): MyStruct { 36 | input.readStructBegin(); 37 | let _args: any = {}; 38 | while (true) { 39 | const ret: thrift.TField = input.readFieldBegin(); 40 | const fieldType: thrift.Thrift.Type = ret.ftype; 41 | const fieldId: number = ret.fid; 42 | if (fieldType === thrift.Thrift.Type.STOP) { 43 | break; 44 | } 45 | switch (fieldId) { 46 | case 1: 47 | if (fieldType === thrift.Thrift.Type.MAP) { 48 | const value_3: Map> = new Map>(); 49 | const metadata_1: thrift.TMap = input.readMapBegin(); 50 | const size_1: number = metadata_1.size; 51 | for (let i_1: number = 0; i_1 < size_1; i_1++) { 52 | const key_3: string = input.readString(); 53 | const value_4: Map = new Map(); 54 | const metadata_2: thrift.TMap = input.readMapBegin(); 55 | const size_2: number = metadata_2.size; 56 | for (let i_2: number = 0; i_2 < size_2; i_2++) { 57 | const key_4: string = input.readString(); 58 | const value_5: number = input.readI32(); 59 | value_4.set(key_4, value_5); 60 | } 61 | input.readMapEnd(); 62 | value_3.set(key_3, value_4); 63 | } 64 | input.readMapEnd(); 65 | _args.field1 = value_3; 66 | } 67 | else { 68 | input.skip(fieldType); 69 | } 70 | break; 71 | default: { 72 | input.skip(fieldType); 73 | } 74 | } 75 | input.readFieldEnd(); 76 | } 77 | input.readStructEnd(); 78 | if (_args.field1 !== undefined) { 79 | return new MyStruct(_args); 80 | } 81 | else { 82 | throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Unable to read MyStruct from input"); 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/nested_set_struct.solution.ts: -------------------------------------------------------------------------------- 1 | export interface IMyStructArgs { 2 | field1: Set>; 3 | } 4 | export class MyStruct { 5 | public field1: Set>; 6 | constructor(args: IMyStructArgs) { 7 | if (args != null && args.field1 != null) { 8 | this.field1 = args.field1; 9 | } 10 | else { 11 | throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Required field[field1] is unset!"); 12 | } 13 | } 14 | public write(output: thrift.TProtocol): void { 15 | output.writeStructBegin("MyStruct"); 16 | if (this.field1 != null) { 17 | output.writeFieldBegin("field1", thrift.Thrift.Type.SET, 1); 18 | output.writeSetBegin(thrift.Thrift.Type.SET, this.field1.size); 19 | this.field1.forEach((value_1: Set): void => { 20 | output.writeSetBegin(thrift.Thrift.Type.STRING, value_1.size); 21 | value_1.forEach((value_2: string): void => { 22 | output.writeString(value_2); 23 | }); 24 | output.writeSetEnd(); 25 | }); 26 | output.writeSetEnd(); 27 | output.writeFieldEnd(); 28 | } 29 | output.writeFieldStop(); 30 | output.writeStructEnd(); 31 | return; 32 | } 33 | public static read(input: thrift.TProtocol): MyStruct { 34 | input.readStructBegin(); 35 | let _args: any = {}; 36 | while (true) { 37 | const ret: thrift.TField = input.readFieldBegin(); 38 | const fieldType: thrift.Thrift.Type = ret.ftype; 39 | const fieldId: number = ret.fid; 40 | if (fieldType === thrift.Thrift.Type.STOP) { 41 | break; 42 | } 43 | switch (fieldId) { 44 | case 1: 45 | if (fieldType === thrift.Thrift.Type.SET) { 46 | const value_3: Set> = new Set>(); 47 | const metadata_1: thrift.TSet = input.readSetBegin(); 48 | const size_1: number = metadata_1.size; 49 | for (let i_1: number = 0; i_1 < size_1; i_1++) { 50 | const value_4: Set = new Set(); 51 | const metadata_2: thrift.TSet = input.readSetBegin(); 52 | const size_2: number = metadata_2.size; 53 | for (let i_2: number = 0; i_2 < size_2; i_2++) { 54 | const value_5: string = input.readString(); 55 | value_4.add(value_5); 56 | } 57 | input.readSetEnd(); 58 | value_3.add(value_4); 59 | } 60 | input.readSetEnd(); 61 | _args.field1 = value_3; 62 | } 63 | else { 64 | input.skip(fieldType); 65 | } 66 | break; 67 | default: { 68 | input.skip(fieldType); 69 | } 70 | } 71 | input.readFieldEnd(); 72 | } 73 | input.readStructEnd(); 74 | if (_args.field1 !== undefined) { 75 | return new MyStruct(_args); 76 | } 77 | else { 78 | throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Unable to read MyStruct from input"); 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/apache/set_struct.solution.ts: -------------------------------------------------------------------------------- 1 | export interface IMyStructArgs { 2 | field1: Set; 3 | } 4 | export class MyStruct { 5 | public field1: Set; 6 | constructor(args: IMyStructArgs) { 7 | if (args != null && args.field1 != null) { 8 | this.field1 = args.field1; 9 | } 10 | else { 11 | throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Required field[field1] is unset!"); 12 | } 13 | } 14 | public write(output: thrift.TProtocol): void { 15 | output.writeStructBegin("MyStruct"); 16 | if (this.field1 != null) { 17 | output.writeFieldBegin("field1", thrift.Thrift.Type.SET, 1); 18 | output.writeSetBegin(thrift.Thrift.Type.STRING, this.field1.size); 19 | this.field1.forEach((value_1: string): void => { 20 | output.writeString(value_1); 21 | }); 22 | output.writeSetEnd(); 23 | output.writeFieldEnd(); 24 | } 25 | output.writeFieldStop(); 26 | output.writeStructEnd(); 27 | return; 28 | } 29 | public static read(input: thrift.TProtocol): MyStruct { 30 | input.readStructBegin(); 31 | let _args: any = {}; 32 | while (true) { 33 | const ret: thrift.TField = input.readFieldBegin(); 34 | const fieldType: thrift.Thrift.Type = ret.ftype; 35 | const fieldId: number = ret.fid; 36 | if (fieldType === thrift.Thrift.Type.STOP) { 37 | break; 38 | } 39 | switch (fieldId) { 40 | case 1: 41 | if (fieldType === thrift.Thrift.Type.SET) { 42 | const value_2: Set = new Set(); 43 | const metadata_1: thrift.TSet = input.readSetBegin(); 44 | const size_1: number = metadata_1.size; 45 | for (let i_1: number = 0; i_1 < size_1; i_1++) { 46 | const value_3: string = input.readString(); 47 | value_2.add(value_3); 48 | } 49 | input.readSetEnd(); 50 | _args.field1 = value_2; 51 | } 52 | else { 53 | input.skip(fieldType); 54 | } 55 | break; 56 | default: { 57 | input.skip(fieldType); 58 | } 59 | } 60 | input.readFieldEnd(); 61 | } 62 | input.readStructEnd(); 63 | if (_args.field1 !== undefined) { 64 | return new MyStruct(_args); 65 | } 66 | else { 67 | throw new thrift.Thrift.TProtocolException(thrift.Thrift.TProtocolExceptionType.UNKNOWN, "Unable to read MyStruct from input"); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/basic_exception.solution.ts: -------------------------------------------------------------------------------- 1 | export interface IMyException { 2 | __name: "MyException"; 3 | message?: string; 4 | code?: number; 5 | } 6 | export interface IMyExceptionArgs { 7 | message?: string; 8 | code?: number; 9 | } 10 | export const MyExceptionCodec: thrift.IStructCodec = { 11 | encode(args: IMyExceptionArgs, output: thrift.TProtocol): void { 12 | const obj: any = { 13 | message: args.message, 14 | code: (args.code != null ? args.code : 200) 15 | }; 16 | output.writeStructBegin("MyException"); 17 | if (obj.message != null) { 18 | output.writeFieldBegin("message", thrift.TType.STRING, 1); 19 | output.writeString(obj.message); 20 | output.writeFieldEnd(); 21 | } 22 | if (obj.code != null) { 23 | output.writeFieldBegin("code", thrift.TType.I32, 2); 24 | output.writeI32(obj.code); 25 | output.writeFieldEnd(); 26 | } 27 | output.writeFieldStop(); 28 | output.writeStructEnd(); 29 | return; 30 | }, 31 | decode(input: thrift.TProtocol): IMyException { 32 | let _args: any = {}; 33 | input.readStructBegin(); 34 | while (true) { 35 | const ret: thrift.IThriftField = input.readFieldBegin(); 36 | const fieldType: thrift.TType = ret.fieldType; 37 | const fieldId: number = ret.fieldId; 38 | if (fieldType === thrift.TType.STOP) { 39 | break; 40 | } 41 | switch (fieldId) { 42 | case 1: 43 | if (fieldType === thrift.TType.STRING) { 44 | const value_1: string = input.readString(); 45 | _args.message = value_1; 46 | } 47 | else { 48 | input.skip(fieldType); 49 | } 50 | break; 51 | case 2: 52 | if (fieldType === thrift.TType.I32) { 53 | const value_2: number = input.readI32(); 54 | _args.code = value_2; 55 | } 56 | else { 57 | input.skip(fieldType); 58 | } 59 | break; 60 | default: { 61 | input.skip(fieldType); 62 | } 63 | } 64 | input.readFieldEnd(); 65 | } 66 | input.readStructEnd(); 67 | return { 68 | __name: "MyException", 69 | message: _args.message, 70 | code: (_args.code != null ? _args.code : 200) 71 | }; 72 | } 73 | }; 74 | export class MyException extends thrift.StructLike implements IMyException { 75 | public message?: string; 76 | public code?: number = 200; 77 | public readonly __name = "MyException"; 78 | public readonly _annotations: thrift.IThriftAnnotations = {}; 79 | public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; 80 | constructor(args: IMyExceptionArgs = {}) { 81 | super(); 82 | if (args.message != null) { 83 | const value_3: string = args.message; 84 | this.message = value_3; 85 | } 86 | if (args.code != null) { 87 | const value_4: number = args.code; 88 | this.code = value_4; 89 | } 90 | } 91 | public static read(input: thrift.TProtocol): MyException { 92 | return new MyException(MyExceptionCodec.decode(input)); 93 | } 94 | public static write(args: IMyExceptionArgs, output: thrift.TProtocol): void { 95 | return MyExceptionCodec.encode(args, output); 96 | } 97 | public write(output: thrift.TProtocol): void { 98 | return MyExceptionCodec.encode(this, output); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/basic_struct.no_name.solution.ts: -------------------------------------------------------------------------------- 1 | export interface IMyStruct { 2 | id: number; 3 | } 4 | export interface IMyStructArgs { 5 | id: number; 6 | } 7 | export const MyStructCodec: thrift.IStructCodec = { 8 | encode(args: IMyStructArgs, output: thrift.TProtocol): void { 9 | const obj: any = { 10 | id: args.id 11 | }; 12 | output.writeStructBegin("MyStruct"); 13 | if (obj.id != null) { 14 | output.writeFieldBegin("id", thrift.TType.I32, 1); 15 | output.writeI32(obj.id); 16 | output.writeFieldEnd(); 17 | } 18 | else { 19 | throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[id] is unset!"); 20 | } 21 | output.writeFieldStop(); 22 | output.writeStructEnd(); 23 | return; 24 | }, 25 | decode(input: thrift.TProtocol): IMyStruct { 26 | let _args: any = {}; 27 | input.readStructBegin(); 28 | while (true) { 29 | const ret: thrift.IThriftField = input.readFieldBegin(); 30 | const fieldType: thrift.TType = ret.fieldType; 31 | const fieldId: number = ret.fieldId; 32 | if (fieldType === thrift.TType.STOP) { 33 | break; 34 | } 35 | switch (fieldId) { 36 | case 1: 37 | if (fieldType === thrift.TType.I32) { 38 | const value_1: number = input.readI32(); 39 | _args.id = value_1; 40 | } 41 | else { 42 | input.skip(fieldType); 43 | } 44 | break; 45 | default: { 46 | input.skip(fieldType); 47 | } 48 | } 49 | input.readFieldEnd(); 50 | } 51 | input.readStructEnd(); 52 | if (_args.id !== undefined) { 53 | return { 54 | id: _args.id 55 | }; 56 | } 57 | else { 58 | throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read MyStruct from input"); 59 | } 60 | } 61 | }; 62 | export class MyStruct extends thrift.StructLike implements IMyStruct { 63 | public id: number; 64 | public readonly _annotations: thrift.IThriftAnnotations = {}; 65 | public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; 66 | constructor(args: IMyStructArgs) { 67 | super(); 68 | if (args.id != null) { 69 | const value_2: number = args.id; 70 | this.id = value_2; 71 | } 72 | else { 73 | throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Required field[id] is unset!"); 74 | } 75 | } 76 | public static read(input: thrift.TProtocol): MyStruct { 77 | return new MyStruct(MyStructCodec.decode(input)); 78 | } 79 | public static write(args: IMyStructArgs, output: thrift.TProtocol): void { 80 | return MyStructCodec.encode(args, output); 81 | } 82 | public write(output: thrift.TProtocol): void { 83 | return MyStructCodec.encode(this, output); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/basic_typedef.solution.ts: -------------------------------------------------------------------------------- 1 | export type NUM_TYPE = number; 2 | export type name = NUM_TYPE; 3 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/complex_const.solution.ts: -------------------------------------------------------------------------------- 1 | export const WHAT: number = 32; 2 | export const VALUE: number = 32; 3 | export const VALUE_LIST: Array = [32]; 4 | export const FALSE_CONST: boolean = false; 5 | export const INT_64: thrift.Int64 = thrift.Int64.fromDecimalString("64"); 6 | export const SET_CONST: Set = new Set(["hello", "world", "foo", "bar"]); 7 | export const MAP_CONST: Map = new Map([["hello", "world"], ["foo", "bar"]]); 8 | export const VALUE_MAP: Map = new Map([[32, "world"], [5, "bar"]]); 9 | export const LIST_CONST: Array = ["hello", "world", "foo", "bar"]; 10 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/complex_typedef.solution.ts: -------------------------------------------------------------------------------- 1 | export enum MyEnum { 2 | ONE = 0, 3 | TWO = 1 4 | } 5 | export type MyInt = number; 6 | export const AnotherName = MyEnum; 7 | export type AnotherName = MyEnum; 8 | export const INT_32: number = 32; 9 | export const WHAT: AnotherName = AnotherName.ONE; 10 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/empty_struct.solution.ts: -------------------------------------------------------------------------------- 1 | export interface IMyStruct { 2 | __name: "MyStruct"; 3 | } 4 | export interface IMyStructArgs { 5 | } 6 | export const MyStructCodec: thrift.IStructCodec = { 7 | encode(args: IMyStructArgs, output: thrift.TProtocol): void { 8 | output.writeStructBegin("MyStruct"); 9 | output.writeFieldStop(); 10 | output.writeStructEnd(); 11 | return; 12 | }, 13 | decode(input: thrift.TProtocol): IMyStruct { 14 | input.readStructBegin(); 15 | while (true) { 16 | const ret: thrift.IThriftField = input.readFieldBegin(); 17 | const fieldType: thrift.TType = ret.fieldType; 18 | const fieldId: number = ret.fieldId; 19 | if (fieldType === thrift.TType.STOP) { 20 | break; 21 | } 22 | switch (fieldId) { 23 | default: { 24 | input.skip(fieldType); 25 | } 26 | } 27 | input.readFieldEnd(); 28 | } 29 | input.readStructEnd(); 30 | return { 31 | __name: "MyStruct" 32 | }; 33 | } 34 | }; 35 | export class MyStruct extends thrift.StructLike implements IMyStruct { 36 | public readonly __name = "MyStruct"; 37 | public readonly _annotations: thrift.IThriftAnnotations = {}; 38 | public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; 39 | constructor(args: IMyStructArgs = {}) { 40 | super(); 41 | } 42 | public static read(input: thrift.TProtocol): MyStruct { 43 | return new MyStruct(MyStructCodec.decode(input)); 44 | } 45 | public static write(args: IMyStructArgs, output: thrift.TProtocol): void { 46 | return MyStructCodec.encode(args, output); 47 | } 48 | public write(output: thrift.TProtocol): void { 49 | return MyStructCodec.encode(this, output); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/empty_union.solution.ts: -------------------------------------------------------------------------------- 1 | export interface IMyUnion { 2 | __name: "MyUnion"; 3 | } 4 | export interface IMyUnionArgs { 5 | } 6 | export const MyUnionCodec: thrift.IStructCodec = { 7 | encode(args: IMyUnionArgs, output: thrift.TProtocol): void { 8 | let _fieldsSet: number = 0; 9 | output.writeStructBegin("MyUnion"); 10 | output.writeFieldStop(); 11 | output.writeStructEnd(); 12 | if (_fieldsSet > 1) { 13 | throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion cannot have more than one value"); 14 | } 15 | else if (_fieldsSet < 1) { 16 | throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion must have one value set"); 17 | } 18 | return; 19 | }, 20 | decode(input: thrift.TProtocol): IMyUnion { 21 | let _fieldsSet: number = 0; 22 | let _returnValue: any = null; 23 | input.readStructBegin(); 24 | while (true) { 25 | const ret: thrift.IThriftField = input.readFieldBegin(); 26 | const fieldType: thrift.TType = ret.fieldType; 27 | const fieldId: number = ret.fieldId; 28 | if (fieldType === thrift.TType.STOP) { 29 | break; 30 | } 31 | switch (fieldId) { 32 | default: { 33 | input.skip(fieldType); 34 | } 35 | } 36 | input.readFieldEnd(); 37 | } 38 | input.readStructEnd(); 39 | if (_fieldsSet > 1) { 40 | throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion cannot have more than one value"); 41 | } 42 | else if (_fieldsSet < 1) { 43 | throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion must have one value set"); 44 | } 45 | throw new thrift.TProtocolException(thrift.TProtocolExceptionType.UNKNOWN, "Unable to read data for TUnion"); 46 | } 47 | }; 48 | export class MyUnion extends thrift.StructLike implements IMyUnion { 49 | public readonly __name = "MyUnion"; 50 | public readonly _annotations: thrift.IThriftAnnotations = {}; 51 | public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; 52 | constructor(args: IMyUnionArgs = {}) { 53 | super(); 54 | let _fieldsSet: number = 0; 55 | if (_fieldsSet > 1) { 56 | throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion cannot have more than one value"); 57 | } 58 | else if (_fieldsSet < 1) { 59 | throw new thrift.TProtocolException(thrift.TProtocolExceptionType.INVALID_DATA, "TUnion must have one value set"); 60 | } 61 | } 62 | public static read(input: thrift.TProtocol): MyUnion { 63 | return new MyUnion(MyUnionCodec.decode(input)); 64 | } 65 | public static write(args: IMyUnionArgs, output: thrift.TProtocol): void { 66 | return MyUnionCodec.encode(args, output); 67 | } 68 | public write(output: thrift.TProtocol): void { 69 | return MyUnionCodec.encode(this, output); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated-strict/Code.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as thrift from "test-lib"; 8 | export interface ICode { 9 | __name: "Code"; 10 | status?: thrift.Int64; 11 | } 12 | export interface ICodeArgs { 13 | status?: number | string | thrift.Int64; 14 | } 15 | export const CodeCodec: thrift.IStructCodec = { 16 | encode(args: ICodeArgs, output: thrift.TProtocol): void { 17 | const obj: any = { 18 | status: (typeof args.status === "number" ? new thrift.Int64(args.status) : typeof args.status === "string" ? thrift.Int64.fromDecimalString(args.status) : args.status) 19 | }; 20 | output.writeStructBegin("Code"); 21 | if (obj.status != null) { 22 | output.writeFieldBegin("status", thrift.TType.I64, 1); 23 | output.writeI64((typeof obj.status === "number" ? new thrift.Int64(obj.status) : typeof obj.status === "string" ? thrift.Int64.fromDecimalString(obj.status) : obj.status)); 24 | output.writeFieldEnd(); 25 | } 26 | output.writeFieldStop(); 27 | output.writeStructEnd(); 28 | return; 29 | }, 30 | decode(input: thrift.TProtocol): ICode { 31 | let _args: any = {}; 32 | input.readStructBegin(); 33 | while (true) { 34 | const ret: thrift.IThriftField = input.readFieldBegin(); 35 | const fieldType: thrift.TType = ret.fieldType; 36 | const fieldId: number = ret.fieldId; 37 | if (fieldType === thrift.TType.STOP) { 38 | break; 39 | } 40 | switch (fieldId) { 41 | case 1: 42 | if (fieldType === thrift.TType.I64) { 43 | const value_1: thrift.Int64 = input.readI64(); 44 | _args.status = value_1; 45 | } 46 | else { 47 | input.skip(fieldType); 48 | } 49 | break; 50 | default: { 51 | input.skip(fieldType); 52 | } 53 | } 54 | input.readFieldEnd(); 55 | } 56 | input.readStructEnd(); 57 | return { 58 | __name: "Code", 59 | status: _args.status 60 | }; 61 | } 62 | }; 63 | export class Code extends thrift.StructLike implements ICode { 64 | public status?: thrift.Int64; 65 | public readonly __name = "Code"; 66 | public readonly _annotations: thrift.IThriftAnnotations = {}; 67 | public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; 68 | constructor(args: ICodeArgs = {}) { 69 | super(); 70 | if (args.status != null) { 71 | 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); 72 | this.status = value_2; 73 | } 74 | } 75 | public static read(input: thrift.TProtocol): Code { 76 | return new Code(CodeCodec.decode(input)); 77 | } 78 | public static write(args: ICodeArgs, output: thrift.TProtocol): void { 79 | return CodeCodec.encode(args, output); 80 | } 81 | public write(output: thrift.TProtocol): void { 82 | return CodeCodec.encode(this, output); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated-strict/SharedEnum.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | export enum SharedEnum { 8 | value1 = 0, 9 | value2 = 1 10 | } 11 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/CommonStruct.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as com_test_common from "./../common"; 8 | export type ICommonStruct = com_test_common.ICommonStruct; 9 | export type ICommonStructArgs = com_test_common.ICommonStructArgs; 10 | export const CommonStruct = com_test_common.CommonStruct; 11 | export const CommonStructCodec = com_test_common.CommonStructCodec; 12 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/FirstName.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as thrift from "test-lib"; 8 | export interface IFirstName { 9 | __name: "FirstName"; 10 | name?: string; 11 | } 12 | export interface IFirstNameArgs { 13 | name?: string; 14 | } 15 | export const FirstNameCodec: thrift.IStructCodec = { 16 | encode(args: IFirstNameArgs, output: thrift.TProtocol): void { 17 | const obj: any = { 18 | name: args.name 19 | }; 20 | output.writeStructBegin("FirstName"); 21 | if (obj.name != null) { 22 | output.writeFieldBegin("name", thrift.TType.STRING, 1); 23 | output.writeString(obj.name); 24 | output.writeFieldEnd(); 25 | } 26 | output.writeFieldStop(); 27 | output.writeStructEnd(); 28 | return; 29 | }, 30 | decode(input: thrift.TProtocol): IFirstName { 31 | let _args: any = {}; 32 | input.readStructBegin(); 33 | while (true) { 34 | const ret: thrift.IThriftField = input.readFieldBegin(); 35 | const fieldType: thrift.TType = ret.fieldType; 36 | const fieldId: number = ret.fieldId; 37 | if (fieldType === thrift.TType.STOP) { 38 | break; 39 | } 40 | switch (fieldId) { 41 | case 1: 42 | if (fieldType === thrift.TType.STRING) { 43 | const value_1: string = input.readString(); 44 | _args.name = value_1; 45 | } 46 | else { 47 | input.skip(fieldType); 48 | } 49 | break; 50 | default: { 51 | input.skip(fieldType); 52 | } 53 | } 54 | input.readFieldEnd(); 55 | } 56 | input.readStructEnd(); 57 | return { 58 | __name: "FirstName", 59 | name: _args.name 60 | }; 61 | } 62 | }; 63 | export class FirstName extends thrift.StructLike implements IFirstName { 64 | public name?: string; 65 | public readonly __name = "FirstName"; 66 | public readonly _annotations: thrift.IThriftAnnotations = {}; 67 | public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; 68 | constructor(args: IFirstNameArgs = {}) { 69 | super(); 70 | if (args.name != null) { 71 | const value_2: string = args.name; 72 | this.name = value_2; 73 | } 74 | } 75 | public static read(input: thrift.TProtocol): FirstName { 76 | return new FirstName(FirstNameCodec.decode(input)); 77 | } 78 | public static write(args: IFirstNameArgs, output: thrift.TProtocol): void { 79 | return FirstNameCodec.encode(args, output); 80 | } 81 | public write(output: thrift.TProtocol): void { 82 | return FirstNameCodec.encode(this, output); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/LastName.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as thrift from "test-lib"; 8 | export interface ILastName { 9 | __name: "LastName"; 10 | name?: string; 11 | } 12 | export interface ILastNameArgs { 13 | name?: string; 14 | } 15 | export const LastNameCodec: thrift.IStructCodec = { 16 | encode(args: ILastNameArgs, output: thrift.TProtocol): void { 17 | const obj: any = { 18 | name: args.name 19 | }; 20 | output.writeStructBegin("LastName"); 21 | if (obj.name != null) { 22 | output.writeFieldBegin("name", thrift.TType.STRING, 1); 23 | output.writeString(obj.name); 24 | output.writeFieldEnd(); 25 | } 26 | output.writeFieldStop(); 27 | output.writeStructEnd(); 28 | return; 29 | }, 30 | decode(input: thrift.TProtocol): ILastName { 31 | let _args: any = {}; 32 | input.readStructBegin(); 33 | while (true) { 34 | const ret: thrift.IThriftField = input.readFieldBegin(); 35 | const fieldType: thrift.TType = ret.fieldType; 36 | const fieldId: number = ret.fieldId; 37 | if (fieldType === thrift.TType.STOP) { 38 | break; 39 | } 40 | switch (fieldId) { 41 | case 1: 42 | if (fieldType === thrift.TType.STRING) { 43 | const value_1: string = input.readString(); 44 | _args.name = value_1; 45 | } 46 | else { 47 | input.skip(fieldType); 48 | } 49 | break; 50 | default: { 51 | input.skip(fieldType); 52 | } 53 | } 54 | input.readFieldEnd(); 55 | } 56 | input.readStructEnd(); 57 | return { 58 | __name: "LastName", 59 | name: _args.name 60 | }; 61 | } 62 | }; 63 | export class LastName extends thrift.StructLike implements ILastName { 64 | public name?: string; 65 | public readonly __name = "LastName"; 66 | public readonly _annotations: thrift.IThriftAnnotations = {}; 67 | public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; 68 | constructor(args: ILastNameArgs = {}) { 69 | super(); 70 | if (args.name != null) { 71 | const value_2: string = args.name; 72 | this.name = value_2; 73 | } 74 | } 75 | public static read(input: thrift.TProtocol): LastName { 76 | return new LastName(LastNameCodec.decode(input)); 77 | } 78 | public static write(args: ILastNameArgs, output: thrift.TProtocol): void { 79 | return LastNameCodec.encode(args, output); 80 | } 81 | public write(output: thrift.TProtocol): void { 82 | return LastNameCodec.encode(this, output); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/MyInteger.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | export type MyInteger = number; 8 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/Operation.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as com_test_operation from "./../operation"; 8 | export const Operation = com_test_operation.Operation; 9 | export type Operation = com_test_operation.Operation; 10 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/TypedMap.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as CommonStruct from "./CommonStruct"; 8 | export type TypedMap = Map; 9 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/constants.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | export const INT32CONSTANT: number = 9853; 8 | export const MAPCONSTANT: Map = new Map([["hello", "world"], ["goodnight", "moon"]]); 9 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated-strict/com/test/calculator/index.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | export * from "./constants"; 8 | export * from "./MyInteger"; 9 | export * from "./Operation"; 10 | export * from "./CommonStruct"; 11 | export * from "./TypedMap"; 12 | export * from "./Work"; 13 | export * from "./FirstName"; 14 | export * from "./LastName"; 15 | export * from "./Choice"; 16 | export * from "./NotAGoodIdea"; 17 | import * as Calculator from "./Calculator"; 18 | export { Calculator as Calculator }; 19 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated-strict/com/test/common/COMMON_INT.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as __ROOT_NAMESPACE__ from "./../../.."; 8 | export const COMMON_INT = __ROOT_NAMESPACE__.SHARED_INT; 9 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated-strict/com/test/common/CommonEnum.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as __ROOT_NAMESPACE__ from "./../../.."; 8 | export const CommonEnum = __ROOT_NAMESPACE__.SharedEnum; 9 | export type CommonEnum = __ROOT_NAMESPACE__.SharedEnum; 10 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated-strict/com/test/common/CommonStruct.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as __ROOT_NAMESPACE__ from "./../../.."; 8 | export type ICommonStruct = __ROOT_NAMESPACE__.ISharedStruct; 9 | export type ICommonStructArgs = __ROOT_NAMESPACE__.ISharedStructArgs; 10 | export const CommonStruct = __ROOT_NAMESPACE__.SharedStruct; 11 | export const CommonStructCodec = __ROOT_NAMESPACE__.SharedStructCodec; 12 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated-strict/com/test/common/CommonUnion.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as __ROOT_NAMESPACE__ from "./../../.."; 8 | export type CommonUnionType = __ROOT_NAMESPACE__.SharedUnionType; 9 | export type CommonUnion = __ROOT_NAMESPACE__.SharedUnion; 10 | export type ICommonUnionWithOption1 = __ROOT_NAMESPACE__.ISharedUnionWithOption1; 11 | export type ICommonUnionWithOption2 = __ROOT_NAMESPACE__.ISharedUnionWithOption2; 12 | export type CommonUnionArgs = __ROOT_NAMESPACE__.SharedUnionArgs; 13 | export type ICommonUnionWithOption1Args = __ROOT_NAMESPACE__.ISharedUnionWithOption1Args; 14 | export type ICommonUnionWithOption2Args = __ROOT_NAMESPACE__.ISharedUnionWithOption2Args; 15 | export const CommonUnionCodec = __ROOT_NAMESPACE__.SharedUnionCodec; 16 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated-strict/com/test/common/MoreOptions.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as OtherCommonUnion from "./OtherCommonUnion"; 8 | export type MoreOptionsType = OtherCommonUnion.OtherCommonUnionType; 9 | export type MoreOptions = OtherCommonUnion.OtherCommonUnion; 10 | export type IMoreOptionsWithOption1 = OtherCommonUnion.IOtherCommonUnionWithOption1; 11 | export type IMoreOptionsWithOption2 = OtherCommonUnion.IOtherCommonUnionWithOption2; 12 | export type MoreOptionsArgs = OtherCommonUnion.OtherCommonUnionArgs; 13 | export type IMoreOptionsWithOption1Args = OtherCommonUnion.IOtherCommonUnionWithOption1Args; 14 | export type IMoreOptionsWithOption2Args = OtherCommonUnion.IOtherCommonUnionWithOption2Args; 15 | export const MoreOptionsCodec = OtherCommonUnion.OtherCommonUnionCodec; 16 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated-strict/com/test/common/NotAllowed.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as AuthException from "./AuthException"; 8 | export type INotAllowed = AuthException.IAuthException; 9 | export type INotAllowedArgs = AuthException.IAuthExceptionArgs; 10 | export const NotAllowed = AuthException.AuthException; 11 | export const NotAllowedCodec = AuthException.AuthExceptionCodec; 12 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated-strict/com/test/common/index.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | export * from "./CommonStruct"; 8 | export * from "./CommonUnion"; 9 | export * from "./CommonEnum"; 10 | export * from "./COMMON_INT"; 11 | export * from "./NotAllowed"; 12 | export * from "./MoreOptions"; 13 | export * from "./OtherCommonUnion"; 14 | export * from "./AuthException"; 15 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated-strict/com/test/exceptions/index.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | export * from "./InvalidOperation"; 8 | export * from "./InvalidResult"; 9 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated-strict/com/test/operation/JankyOperation.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as com_test_exceptions from "./../exceptions"; 8 | export type IJankyOperation = com_test_exceptions.IInvalidOperation; 9 | export type IJankyOperationArgs = com_test_exceptions.IInvalidOperationArgs; 10 | export const JankyOperation = com_test_exceptions.InvalidOperation; 11 | export const JankyOperationCodec = com_test_exceptions.InvalidOperationCodec; 12 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated-strict/com/test/operation/JankyResult.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as com_test_exceptions from "./../exceptions"; 8 | export type IJankyResult = com_test_exceptions.IInvalidResult; 9 | export type IJankyResultArgs = com_test_exceptions.IInvalidResultArgs; 10 | export const JankyResult = com_test_exceptions.InvalidResult; 11 | export const JankyResultCodec = com_test_exceptions.InvalidResultCodec; 12 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated-strict/com/test/operation/Operation.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | export enum Operation { 8 | ADD = 1, 9 | SUBTRACT = 2, 10 | MULTIPLY = 3, 11 | DIVIDE = 4 12 | } 13 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated-strict/com/test/operation/SomethingToDo.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as Operation from "./Operation"; 8 | export const SomethingToDo = Operation.Operation; 9 | export type SomethingToDo = Operation.Operation; 10 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated-strict/com/test/operation/index.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | export * from "./Operation"; 8 | export * from "./JankyOperation"; 9 | export * from "./JankyResult"; 10 | export * from "./SomethingToDo"; 11 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated-strict/constants.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | export const SHARED_INT: number = 45; 8 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated-strict/index.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | export * from "./constants"; 8 | export * from "./SharedEnum"; 9 | export * from "./Code"; 10 | export * from "./SharedStruct"; 11 | export * from "./SharedUnion"; 12 | import * as SharedServiceBase from "./SharedServiceBase"; 13 | export { SharedServiceBase as SharedServiceBase }; 14 | import * as SharedService from "./SharedService"; 15 | export { SharedService as SharedService }; 16 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated/Code.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as thrift from "test-lib"; 8 | export interface ICode { 9 | __name: "Code"; 10 | status?: thrift.Int64; 11 | } 12 | export interface ICodeArgs { 13 | status?: number | string | thrift.Int64; 14 | } 15 | export const CodeCodec: thrift.IStructCodec = { 16 | encode(args: ICodeArgs, output: thrift.TProtocol): void { 17 | const obj: any = { 18 | status: (typeof args.status === "number" ? new thrift.Int64(args.status) : typeof args.status === "string" ? thrift.Int64.fromDecimalString(args.status) : args.status) 19 | }; 20 | output.writeStructBegin("Code"); 21 | if (obj.status != null) { 22 | output.writeFieldBegin("status", thrift.TType.I64, 1); 23 | output.writeI64((typeof obj.status === "number" ? new thrift.Int64(obj.status) : typeof obj.status === "string" ? thrift.Int64.fromDecimalString(obj.status) : obj.status)); 24 | output.writeFieldEnd(); 25 | } 26 | output.writeFieldStop(); 27 | output.writeStructEnd(); 28 | return; 29 | }, 30 | decode(input: thrift.TProtocol): ICode { 31 | let _args: any = {}; 32 | input.readStructBegin(); 33 | while (true) { 34 | const ret: thrift.IThriftField = input.readFieldBegin(); 35 | const fieldType: thrift.TType = ret.fieldType; 36 | const fieldId: number = ret.fieldId; 37 | if (fieldType === thrift.TType.STOP) { 38 | break; 39 | } 40 | switch (fieldId) { 41 | case 1: 42 | if (fieldType === thrift.TType.I64) { 43 | const value_1: thrift.Int64 = input.readI64(); 44 | _args.status = value_1; 45 | } 46 | else { 47 | input.skip(fieldType); 48 | } 49 | break; 50 | default: { 51 | input.skip(fieldType); 52 | } 53 | } 54 | input.readFieldEnd(); 55 | } 56 | input.readStructEnd(); 57 | return { 58 | __name: "Code", 59 | status: _args.status 60 | }; 61 | } 62 | }; 63 | export class Code extends thrift.StructLike implements ICode { 64 | public status?: thrift.Int64; 65 | public readonly __name = "Code"; 66 | public readonly _annotations: thrift.IThriftAnnotations = {}; 67 | public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; 68 | constructor(args: ICodeArgs = {}) { 69 | super(); 70 | if (args.status != null) { 71 | 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); 72 | this.status = value_2; 73 | } 74 | } 75 | public static read(input: thrift.TProtocol): Code { 76 | return new Code(CodeCodec.decode(input)); 77 | } 78 | public static write(args: ICodeArgs, output: thrift.TProtocol): void { 79 | return CodeCodec.encode(args, output); 80 | } 81 | public write(output: thrift.TProtocol): void { 82 | return CodeCodec.encode(this, output); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated/SharedEnum.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | export enum SharedEnum { 8 | value1 = 0, 9 | value2 = 1 10 | } 11 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/CommonStruct.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as com_test_common from "./../common"; 8 | export type ICommonStruct = com_test_common.ICommonStruct; 9 | export type ICommonStructArgs = com_test_common.ICommonStructArgs; 10 | export const CommonStruct = com_test_common.CommonStruct; 11 | export const CommonStructCodec = com_test_common.CommonStructCodec; 12 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/FirstName.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as thrift from "test-lib"; 8 | export interface IFirstName { 9 | __name: "FirstName"; 10 | name?: string; 11 | } 12 | export interface IFirstNameArgs { 13 | name?: string; 14 | } 15 | export const FirstNameCodec: thrift.IStructCodec = { 16 | encode(args: IFirstNameArgs, output: thrift.TProtocol): void { 17 | const obj: any = { 18 | name: args.name 19 | }; 20 | output.writeStructBegin("FirstName"); 21 | if (obj.name != null) { 22 | output.writeFieldBegin("name", thrift.TType.STRING, 1); 23 | output.writeString(obj.name); 24 | output.writeFieldEnd(); 25 | } 26 | output.writeFieldStop(); 27 | output.writeStructEnd(); 28 | return; 29 | }, 30 | decode(input: thrift.TProtocol): IFirstName { 31 | let _args: any = {}; 32 | input.readStructBegin(); 33 | while (true) { 34 | const ret: thrift.IThriftField = input.readFieldBegin(); 35 | const fieldType: thrift.TType = ret.fieldType; 36 | const fieldId: number = ret.fieldId; 37 | if (fieldType === thrift.TType.STOP) { 38 | break; 39 | } 40 | switch (fieldId) { 41 | case 1: 42 | if (fieldType === thrift.TType.STRING) { 43 | const value_1: string = input.readString(); 44 | _args.name = value_1; 45 | } 46 | else { 47 | input.skip(fieldType); 48 | } 49 | break; 50 | default: { 51 | input.skip(fieldType); 52 | } 53 | } 54 | input.readFieldEnd(); 55 | } 56 | input.readStructEnd(); 57 | return { 58 | __name: "FirstName", 59 | name: _args.name 60 | }; 61 | } 62 | }; 63 | export class FirstName extends thrift.StructLike implements IFirstName { 64 | public name?: string; 65 | public readonly __name = "FirstName"; 66 | public readonly _annotations: thrift.IThriftAnnotations = {}; 67 | public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; 68 | constructor(args: IFirstNameArgs = {}) { 69 | super(); 70 | if (args.name != null) { 71 | const value_2: string = args.name; 72 | this.name = value_2; 73 | } 74 | } 75 | public static read(input: thrift.TProtocol): FirstName { 76 | return new FirstName(FirstNameCodec.decode(input)); 77 | } 78 | public static write(args: IFirstNameArgs, output: thrift.TProtocol): void { 79 | return FirstNameCodec.encode(args, output); 80 | } 81 | public write(output: thrift.TProtocol): void { 82 | return FirstNameCodec.encode(this, output); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/LastName.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as thrift from "test-lib"; 8 | export interface ILastName { 9 | __name: "LastName"; 10 | name?: string; 11 | } 12 | export interface ILastNameArgs { 13 | name?: string; 14 | } 15 | export const LastNameCodec: thrift.IStructCodec = { 16 | encode(args: ILastNameArgs, output: thrift.TProtocol): void { 17 | const obj: any = { 18 | name: args.name 19 | }; 20 | output.writeStructBegin("LastName"); 21 | if (obj.name != null) { 22 | output.writeFieldBegin("name", thrift.TType.STRING, 1); 23 | output.writeString(obj.name); 24 | output.writeFieldEnd(); 25 | } 26 | output.writeFieldStop(); 27 | output.writeStructEnd(); 28 | return; 29 | }, 30 | decode(input: thrift.TProtocol): ILastName { 31 | let _args: any = {}; 32 | input.readStructBegin(); 33 | while (true) { 34 | const ret: thrift.IThriftField = input.readFieldBegin(); 35 | const fieldType: thrift.TType = ret.fieldType; 36 | const fieldId: number = ret.fieldId; 37 | if (fieldType === thrift.TType.STOP) { 38 | break; 39 | } 40 | switch (fieldId) { 41 | case 1: 42 | if (fieldType === thrift.TType.STRING) { 43 | const value_1: string = input.readString(); 44 | _args.name = value_1; 45 | } 46 | else { 47 | input.skip(fieldType); 48 | } 49 | break; 50 | default: { 51 | input.skip(fieldType); 52 | } 53 | } 54 | input.readFieldEnd(); 55 | } 56 | input.readStructEnd(); 57 | return { 58 | __name: "LastName", 59 | name: _args.name 60 | }; 61 | } 62 | }; 63 | export class LastName extends thrift.StructLike implements ILastName { 64 | public name?: string; 65 | public readonly __name = "LastName"; 66 | public readonly _annotations: thrift.IThriftAnnotations = {}; 67 | public readonly _fieldAnnotations: thrift.IFieldAnnotations = {}; 68 | constructor(args: ILastNameArgs = {}) { 69 | super(); 70 | if (args.name != null) { 71 | const value_2: string = args.name; 72 | this.name = value_2; 73 | } 74 | } 75 | public static read(input: thrift.TProtocol): LastName { 76 | return new LastName(LastNameCodec.decode(input)); 77 | } 78 | public static write(args: ILastNameArgs, output: thrift.TProtocol): void { 79 | return LastNameCodec.encode(args, output); 80 | } 81 | public write(output: thrift.TProtocol): void { 82 | return LastNameCodec.encode(this, output); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/MyInteger.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | export type MyInteger = number; 8 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/Operation.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as com_test_operation from "./../operation"; 8 | export const Operation = com_test_operation.Operation; 9 | export type Operation = com_test_operation.Operation; 10 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/TypedMap.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as CommonStruct from "./CommonStruct"; 8 | export type TypedMap = Map; 9 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/constants.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | export const INT32CONSTANT: number = 9853; 8 | export const MAPCONSTANT: Map = new Map([["hello", "world"], ["goodnight", "moon"]]); 9 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated/com/test/calculator/index.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | export * from "./constants"; 8 | export * from "./MyInteger"; 9 | export * from "./Operation"; 10 | export * from "./CommonStruct"; 11 | export * from "./TypedMap"; 12 | export * from "./Work"; 13 | export * from "./FirstName"; 14 | export * from "./LastName"; 15 | export * from "./Choice"; 16 | export * from "./NotAGoodIdea"; 17 | import * as Calculator from "./Calculator"; 18 | export { Calculator as Calculator }; 19 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated/com/test/common/COMMON_INT.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as __ROOT_NAMESPACE__ from "./../../.."; 8 | export const COMMON_INT = __ROOT_NAMESPACE__.SHARED_INT; 9 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated/com/test/common/CommonEnum.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as __ROOT_NAMESPACE__ from "./../../.."; 8 | export const CommonEnum = __ROOT_NAMESPACE__.SharedEnum; 9 | export type CommonEnum = __ROOT_NAMESPACE__.SharedEnum; 10 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated/com/test/common/CommonStruct.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as __ROOT_NAMESPACE__ from "./../../.."; 8 | export type ICommonStruct = __ROOT_NAMESPACE__.ISharedStruct; 9 | export type ICommonStructArgs = __ROOT_NAMESPACE__.ISharedStructArgs; 10 | export const CommonStruct = __ROOT_NAMESPACE__.SharedStruct; 11 | export const CommonStructCodec = __ROOT_NAMESPACE__.SharedStructCodec; 12 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated/com/test/common/CommonUnion.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as __ROOT_NAMESPACE__ from "./../../.."; 8 | export type ICommonUnion = __ROOT_NAMESPACE__.ISharedUnion; 9 | export type ICommonUnionArgs = __ROOT_NAMESPACE__.ISharedUnionArgs; 10 | export const CommonUnion = __ROOT_NAMESPACE__.SharedUnion; 11 | export const CommonUnionCodec = __ROOT_NAMESPACE__.SharedUnionCodec; 12 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated/com/test/common/MoreOptions.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as OtherCommonUnion from "./OtherCommonUnion"; 8 | export type IMoreOptions = OtherCommonUnion.IOtherCommonUnion; 9 | export type IMoreOptionsArgs = OtherCommonUnion.IOtherCommonUnionArgs; 10 | export const MoreOptions = OtherCommonUnion.OtherCommonUnion; 11 | export const MoreOptionsCodec = OtherCommonUnion.OtherCommonUnionCodec; 12 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated/com/test/common/NotAllowed.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as AuthException from "./AuthException"; 8 | export type INotAllowed = AuthException.IAuthException; 9 | export type INotAllowedArgs = AuthException.IAuthExceptionArgs; 10 | export const NotAllowed = AuthException.AuthException; 11 | export const NotAllowedCodec = AuthException.AuthExceptionCodec; 12 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated/com/test/common/index.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | export * from "./CommonStruct"; 8 | export * from "./CommonUnion"; 9 | export * from "./CommonEnum"; 10 | export * from "./COMMON_INT"; 11 | export * from "./NotAllowed"; 12 | export * from "./MoreOptions"; 13 | export * from "./OtherCommonUnion"; 14 | export * from "./AuthException"; 15 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated/com/test/exceptions/index.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | export * from "./InvalidOperation"; 8 | export * from "./InvalidResult"; 9 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated/com/test/operation/JankyOperation.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as com_test_exceptions from "./../exceptions"; 8 | export type IJankyOperation = com_test_exceptions.IInvalidOperation; 9 | export type IJankyOperationArgs = com_test_exceptions.IInvalidOperationArgs; 10 | export const JankyOperation = com_test_exceptions.InvalidOperation; 11 | export const JankyOperationCodec = com_test_exceptions.InvalidOperationCodec; 12 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated/com/test/operation/JankyResult.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as com_test_exceptions from "./../exceptions"; 8 | export type IJankyResult = com_test_exceptions.IInvalidResult; 9 | export type IJankyResultArgs = com_test_exceptions.IInvalidResultArgs; 10 | export const JankyResult = com_test_exceptions.InvalidResult; 11 | export const JankyResultCodec = com_test_exceptions.InvalidResultCodec; 12 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated/com/test/operation/Operation.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | export enum Operation { 8 | ADD = 1, 9 | SUBTRACT = 2, 10 | MULTIPLY = 3, 11 | DIVIDE = 4 12 | } 13 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated/com/test/operation/SomethingToDo.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | import * as Operation from "./Operation"; 8 | export const SomethingToDo = Operation.Operation; 9 | export type SomethingToDo = Operation.Operation; 10 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated/com/test/operation/index.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | export * from "./Operation"; 8 | export * from "./JankyOperation"; 9 | export * from "./JankyResult"; 10 | export * from "./SomethingToDo"; 11 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated/constants.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | export const SHARED_INT: number = 45; 8 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift-server/generated/index.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | /* 4 | * Autogenerated by @creditkarma/thrift-typescript v{{VERSION}} 5 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 6 | */ 7 | export * from "./constants"; 8 | export * from "./SharedEnum"; 9 | export * from "./Code"; 10 | export * from "./SharedStruct"; 11 | export * from "./SharedUnion"; 12 | import * as SharedServiceBase from "./SharedServiceBase"; 13 | export { SharedServiceBase as SharedServiceBase }; 14 | import * as SharedService from "./SharedService"; 15 | export { SharedService as SharedService }; 16 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift/calculator.thrift: -------------------------------------------------------------------------------- 1 | namespace cpp com.test.calculator 2 | namespace d com.test.calculator 3 | namespace dart com.test.calculator 4 | namespace java com.test.calculator 5 | namespace php com.test.calculator 6 | namespace perl com.test.calculator 7 | namespace haxe com.test.calculator 8 | namespace netcore com.test.calculator 9 | 10 | include "shared.thrift" 11 | include "common.thrift" 12 | include "operation.thrift" 13 | 14 | typedef i32 MyInteger 15 | typedef operation.Operation Operation 16 | typedef common.CommonStruct CommonStruct 17 | typedef map TypedMap 18 | 19 | const i32 INT32CONSTANT = 9853 20 | const map MAPCONSTANT = {'hello':'world', 'goodnight':'moon'} 21 | 22 | struct Work { 23 | 1: required i32 num1 = 0, 24 | 2: required i32 num2, 25 | 3: optional Operation op = Operation.ADD, 26 | 4: optional string comment, 27 | } 28 | 29 | struct FirstName { 30 | 1: string name 31 | } 32 | 33 | struct LastName { 34 | 1: string name 35 | } 36 | 37 | union Choice { 38 | 1: FirstName firstName 39 | 2: LastName lastName 40 | } 41 | 42 | exception NotAGoodIdea { 43 | 1: string message 44 | 2: TypedMap data 45 | } 46 | 47 | service Calculator extends shared.SharedService { 48 | 49 | void ping(), 50 | 51 | i32 add(1: i32 num1, 2: i32 num2) throws (1: operation.JankyResult exp), 52 | 53 | i64 addInt64(1: i64 num1, 2: i64 num2) throws (1: NotAGoodIdea exp), 54 | 55 | i32 addWithContext(1: i32 num1, 2: i32 num2), 56 | 57 | i32 calculate(1:i32 logid, 2:Work work) throws (1: operation.JankyOperation ouch), 58 | 59 | string echoBinary(1: binary word) 60 | 61 | string echoString(1: string word) 62 | 63 | string checkName(1: Choice choice), 64 | 65 | string checkOptional(1: optional string type), 66 | 67 | list mapOneList(1: list arg) 68 | 69 | list mapValues(1: map arg) 70 | 71 | map listToMap(1: list> arg) 72 | 73 | common.CommonStruct fetchThing() 74 | 75 | TypedMap fetchMap() 76 | 77 | /** 78 | * This method has a oneway modifier. That means the client only makes 79 | * a request and does not listen for any response at all. Oneway methods 80 | * must be void. 81 | */ 82 | oneway void zip() 83 | 84 | } 85 | 86 | /** 87 | * That just about covers the basics. Take a look in the test/ folder for more 88 | * detailed examples. After you run this file, your generated code shows up 89 | * in folders with names gen-. The generated code isn't too scary 90 | * to look at. It even has pretty indentation. 91 | */ 92 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift/common.thrift: -------------------------------------------------------------------------------- 1 | /** 2 | * Thrift files can namespace, package, or prefix their output in various 3 | * target languages. 4 | */ 5 | namespace cpp com.test.common 6 | namespace d com.test.common 7 | namespace dart com.test.common 8 | namespace java com.test.common 9 | namespace php com.test.common 10 | namespace perl com.test.common 11 | namespace haxe com.test.common 12 | namespace netcore com.test.common 13 | 14 | include "shared.thrift" 15 | 16 | typedef shared.SharedStruct CommonStruct 17 | typedef shared.SharedUnion CommonUnion 18 | typedef shared.SharedEnum CommonEnum 19 | typedef shared.SHARED_INT COMMON_INT 20 | 21 | exception AuthException { 22 | 1: i32 code 23 | 2: string message 24 | } 25 | 26 | union OtherCommonUnion { 27 | 1: string option1 28 | 2: i32 option2 29 | } 30 | 31 | typedef AuthException NotAllowed 32 | typedef OtherCommonUnion MoreOptions 33 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift/exceptions.thrift: -------------------------------------------------------------------------------- 1 | namespace cpp com.test.exceptions 2 | namespace d com.test.exceptions 3 | namespace dart com.test.exceptions 4 | namespace java com.test.exceptions 5 | namespace perl com.test.exceptions 6 | namespace php com.test.exceptions 7 | namespace haxe com.test.exceptions 8 | namespace netcore com.test.exceptions 9 | 10 | include "shared.thrift" 11 | 12 | exception InvalidOperation { 13 | 1: i32 whatOp, 14 | 2: string why 15 | } 16 | 17 | exception InvalidResult { 18 | 1: string message 19 | 2: shared.Code code 20 | } 21 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift/operation.thrift: -------------------------------------------------------------------------------- 1 | namespace java com.test.operation 2 | namespace js com.test.operation 3 | 4 | include "exceptions.thrift" 5 | 6 | typedef exceptions.InvalidOperation JankyOperation 7 | typedef exceptions.InvalidResult JankyResult 8 | 9 | /** 10 | * You can define enums, which are just 32 bit integers. Values are optional 11 | * and start at 1 if not supplied, C style again. 12 | */ 13 | enum Operation { 14 | ADD = 1, 15 | SUBTRACT = 2, 16 | MULTIPLY = 3, 17 | DIVIDE = 4 18 | } 19 | 20 | typedef Operation SomethingToDo 21 | -------------------------------------------------------------------------------- /src/tests/unit/fixtures/thrift/shared.thrift: -------------------------------------------------------------------------------- 1 | const i32 SHARED_INT = 45 2 | 3 | struct Code { 4 | 1: i64 status 5 | } 6 | 7 | struct SharedStruct { 8 | 1: required Code code 9 | 2: required string value 10 | } 11 | 12 | union SharedUnion { 13 | 1: string option1 14 | 2: string option2 15 | } 16 | 17 | enum SharedEnum { 18 | value1 19 | value2 20 | } 21 | 22 | service SharedServiceBase { 23 | SharedStruct getStruct(1: i32 key) 24 | } 25 | 26 | service SharedService extends SharedServiceBase { 27 | SharedUnion getUnion(1: i32 index) 28 | SharedEnum getEnum() 29 | } 30 | -------------------------------------------------------------------------------- /src/tests/unit/utils.spec.ts: -------------------------------------------------------------------------------- 1 | // import { assert } from 'chai' 2 | 3 | // import * as Utils from '../../main/utils' 4 | // import { ISourceFile } from '../../main/types' 5 | 6 | // describe('Utils', () => { 7 | // describe('pathForFile', () => { 8 | // it('should return empty string for empty path', async () => { 9 | // const mockFile: ISourceFile = { 10 | // name: '', 11 | // path: '', 12 | // fullPath: '', 13 | // source: '', 14 | // } 15 | 16 | // assert.equal(Utils.pathForFile(mockFile), '') 17 | // }) 18 | // }) 19 | // }) 20 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2017", 4 | "module": "commonjs", 5 | "moduleResolution": "node", 6 | "sourceMap": true, 7 | "declaration": true, 8 | "rootDir": "./src", 9 | "outDir": "./dist", 10 | "noEmitOnError": true, 11 | "strict": true, 12 | "noUnusedLocals": true, 13 | "pretty": true, 14 | "removeComments": true 15 | }, 16 | "exclude": [ 17 | "node_modules", 18 | "src/tests/", 19 | "dist" 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /tsconfig.test.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2017", 4 | "module": "commonjs", 5 | "moduleResolution": "node", 6 | "sourceMap": true, 7 | "declaration": true, 8 | "rootDir": "./src", 9 | "outDir": "./dist", 10 | "noEmitOnError": true, 11 | "strict": true, 12 | "noUnusedLocals": true, 13 | "pretty": true, 14 | "removeComments": true 15 | }, 16 | "exclude": [ 17 | "node_modules", 18 | "src/tests/unit/fixtures", 19 | "dist" 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "tslint:recommended", 4 | "tslint-config-prettier", 5 | "tslint-plugin-prettier" 6 | ], 7 | "linterOptions": { 8 | "exclude": ["src/tests/unit/fixtures/**/*.ts"] 9 | }, 10 | "rules": { 11 | "max-classes-per-file": false, 12 | "prettier": true, 13 | "no-string-literal": false, 14 | "variable-name": false, 15 | "max-line-length": false, 16 | "jsdoc-format": false, 17 | "object-literal-sort-keys": false, 18 | "no-console": false, 19 | "no-var-requires": false, 20 | "array-type": [ 21 | true, 22 | "generic" 23 | ], 24 | "semicolon": false, 25 | "quotemark": false 26 | } 27 | } 28 | --------------------------------------------------------------------------------