Convert thrift IDL file to .d.ts 😃
Go to file
2022-07-13 14:13:55 +03:00
.github/workflows TD-237: Add i64 to number flag & compile services (#4) 2022-03-24 11:14:54 +03:00
bin IMP-23: Codegen several dirs (#3) 2022-03-04 14:49:07 +03:00
src Remove ts nocheck (#8) 2022-07-13 14:13:55 +03:00
test refactor thrift-parser wrapper 2018-09-26 23:22:52 +03:00
.gitignore bad fix tests 2018-09-26 16:59:58 +03:00
.npmignore fix npmignore 2018-09-26 17:13:50 +03:00
.prettierignore refactor thrift-parser wrapper 2018-09-26 23:22:52 +03:00
.travis.yml refactor thrift-parser wrapper 2018-09-26 23:22:52 +03:00
package-lock.json IMP-23: Codegen several dirs (#3) 2022-03-04 14:49:07 +03:00
package.json Remove ts nocheck (#8) 2022-07-13 14:13:55 +03:00
prettier.config.js prettify 2018-09-26 22:36:56 +03:00
README.md add ci icon to README 2018-07-27 01:37:17 +08:00
tsconfig.json IMP-23: Codegen several dirs (#3) 2022-03-04 14:49:07 +03:00
tslint.json TD-237: Add i64 to number flag & compile services (#4) 2022-03-24 11:14:54 +03:00

Build Status

thrift-ts

thrift-ts is a typescript compiler that compile *.thrift files to *.d.ts files. It should works with thrift --gen js:node commands.

Installation

$ npm install -g thrift-ts

How to use

CLI

// just compile one file
thrift-ts Model.thrift

// compile all IDL files in the folder and output in other folder
thrift-ts ./src -o ./dist

// learn more
thrift-ts -h

Node

import thriftTs from 'thriftTs';
import fs = require('fs');

const filename = './Model.thrift';
const files = thriftTs({
  filename,
  content: fs.readFileSync(filename),
})

console.log(files);
// [{ filename: 'Model_types.d.ts', content: '...'}]

Example

thrift file:

namespace java com.my.test

struct Result {
 1: i32 id;
 2: string name;
}

enum Status {
  Success = 1;
  Error = 2;
}

struct Response {
  1:required Status status;
  2:optional list<Result> result;
}

struct Request {
  1: required string query;
  2: optional number page;
}

service MyTestService {
    Response search(1:Request request);
}

.d.ts file:

type Callback<T, E> = (err: E, resp: T) => void;

interface Int64 {
    constructor(o?: number | string): this;
    toString(): string;
    toJson(): string;
}

export enum Status {
    Success = 1,
    Error = 2,
}

export class Result {
    id: number;
    name: string;

    constructor(arg?: {
        id: number;
        name: string;
    })
}

export class Response {
    status: Status;
    result?: Result[];

    constructor(arg?: {
        status: Status;
        result?: Result[];
    })
}

export class Request {
    query: string;
    page?: number;

    constructor(arg?: {
        query: string;
        page?: number;
    })
}

export class Client {
    search(request: Request, callback: Callback<Response, Error>): void;
    search(request: Request): Promise<Response>;
}