thrift-json

1.0.5 • Public • Published

thrift-json

parse thift idl info to json based on thriftpy

Installation

npm i thrift-json

Usage

var thriftToJSON = require('thrift-json');
thriftToJSON('/foo/bar.thrift').then(results => console.log(results));
// 或
thriftToJSON(['/foo/bar1.thrift', '/foo/bar2.thrift']).then(results => console.log(results));

Output

Example:

[
    {
        "source": "/foo/bar.thrift",
        "value": {
            "structs": {
                "CityInfo": "{id?:number,name?:string,pinyin?:string,acronym?:string,rank?:string,firstChar?:string}",
                "RecommendRequest": "{userId:number,cityId:number,lat:number,lng:number,uuid:string,poiId?:number}",
                "RecommendInfo": "{itemId?:number,title?:string,imgUrl?:string,score?:string,consumeNum?:number,areaName?:string,lowPrice?:string,saleNum?:number,commentNum?:number,detailUrl?:string,firstCate:Array<number>,avgPrice?:number}",
                "PcHomeCategory": "{id?:number,name?:string,url?:string,pinyin?:string}",
                "HomeCategoryResponse": "{leftPcHomeCategoryList:Array<PcHomeCategory>,rightPcHomeCategoryList:Array<Array<PcHomeCategory>>}",
                "GeneralCategory": "{pcHomeCategory:PcHomeCategory,subPcHomeCategory:Array<PcHomeCategory>}",
                "PoiListCategory": "{pcHomeCategory:PcHomeCategory,generalCategoryList:Array<GeneralCategory>}"
            },
            "services": {
                "WebApiService": {
                    "getNearCity": {
                        "args": "cityId:number",
                        "result": "Array<CityInfo>",
                        "empty": []
                    },
                    "getRecommendInfo": {
                        "args": "req:RecommendRequest",
                        "result": "Array<RecommendInfo>",
                        "empty": []
                    },
                    "getCategory": {
                        "args": "cityId:number",
                        "result": "Array<HomeCategoryResponse>",
                        "empty": []
                    }
                }
            },
            "includes": [
                "common"
            ]
        }
    }
]

the results include:

  1. Typescript definition for structs and methods.
  2. Empty output for methods.
  3. Name of thrift files included.

Readme

Keywords

none

Package Sidebar

Install

npm i thrift-json

Weekly Downloads

0

Version

1.0.5

License

MIT

Unpacked Size

420 kB

Total Files

29

Last publish

Collaborators

  • goumang2010