Parse Thrift (IDL) to TypeScript, which could be used as typed interface docs for FrontEnd.
Also as an option, Thrift service clients could be generated. With these clients, a complete RPC call with Thrift data transport and protocol could be done.
* add sequence support for RPC client so that it can reuse the Websocket connection without incorrect response callback order * moduled script file, easy to import and package, rather than many global variables in official generated client for browser * all generated TypeScript files introduce types support and result in more convenient development of your app
npm install thrift2ts -g
yarn global add thrift2ts
t2t -i [thrift file path] -o [typescript file output folder] -r [request method import path] -c
t2t -i ./common.thrift -o ./services -r ./request -c
var thrift2ts = require('thrift2ts').default;var thriftCode = 'XXX';var tsCode = thrift2ts(thriftCode, './request')
Convert to TypeScript
Why import Request
Thrift service will exploded into functions which are used for RPC-liked call or webApi request, a common request instance is required, and accept method string, POST data as parameters. We donnot concern about which request approach(AJAX, Fetch) or libraries(axios, jQuery, fetch-io) you'd like to use, but you must provide the request implementation file path for importing.
Please find the examples in sample folder.
Using normal text transport without thrift rpc server
Using thrift data transport protocol with thrift rpc server
You need import Browser Thrift package when trying to communicate with a Thrift RPC server, which defines the thrift data transport protocol.
Also you could find a demo in this package's introduction.