npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

thrift-mock

v0.0.19

Published

mock data by thrift idl

Readme

thrift-mock

Mock response data from thrift idl files.

Main Features

  • Customize module.exports template. (the mock data MUST using '@@dataPlaceholder' as its placeholder)
  • Method extends.

Config & Execute

const mock = require('thrift-mock');

const config = {
  service: [
    require.resolve('./idl/a.thrift'),
    require.resolve('./idl/b.thrift'),
    /* require.resolve('./idl/CommonService.thrift'),*/
    /* require.resolve('./idl/BaseService.thrift'),*/
    /* require.resolve('./idl/ExtendsService.thrift'),*/
    /* require.resolve('./idl/GrandExtendsService.thrift'),*/
    /* require.resolve('./idl/CustomizedTypeService.thrift'),*/
  ],
  output: {
    path: path.resolve(__dirname, 'mockapi'),
  },
  exportsTemplate: {
    statusCode: 200,
    body: {
      data: '@@dataPlaceholder',
    },
  },
};

mock(config);

Source

idl directory structure

idl
├── a
│   ├── accountVo.thrift
│   ├── pageVo.thrift
│   └── request.thrift
├── aService.thrift
├── b
│   ├── changeVo.thrift
│   ├── request.thrift
│   └── stepVo.thrift
├── bService.thrift
└── exception.thrift

aService's methods and modals

// aService.thrift
namespace java com.finance.account.service

include "./structDir/a/pageVo.thrift"
include "./structDir/a/request.thrift"
include "exception.thrift"

struct AStruct {
    1: required int id,
    2: required bool ishacker,
    # 3: required i16 name,
    4: required string name,
}

service AService {
       pageVo.PageVo search(1:request.Request SearchRequest 2: AStruct personel) throws (1:exception.Exception e) ;
}

// ./structDir/a/pageVo.thrift
include "accountVo.thrift"

struct PageVo{
     1:list<accountVo.AccountVo> tAccountVo;
     2:i32 total;
}

// ./structDir/a/accountVo.thrift
struct AccountVo {
      1:string accountId;
      2:string partnerName;
      3:i32 partnerId;
      4:string accountName;
      5:list<i32> forbiddenSources;
      6:double withdrawRemain;
}

// ./structDir/a/request.thrift
struct Request{
      1:i32 partnerId;
      2:string contractNum;
      3:i32 poiId;
      4:i32 offset;
      5:i32 limit;
}

// ./exception.thrift
exception Exception {
    1: i32 code; // 异常编码
    2: string message; // 异常原因
}

Output

It will output each thrift method with a mock file, which contains a mockjs template. You can then custom the properties as you need.

The mocked method's filepath as follows:

${config.output.path}/${serviceName}/${methodName}.js

Demo output tree structure:

mockapi
├── AService
│   └── search.js
└── BService
    ├── getStep.js
    └── submit.js

mockapi/Aservice/search.js 's content:

const { mock } = require('mockjs');

const body = mock({
  'tAccountVo|3-6': [
    {
      accountId: '@word(3, 5)',
      partnerName: '@word(3, 5)',
      partnerId: '@integer(0, 100)',
      accountName: '@word(3, 5)',
      'forbiddenSources|3-6': [
        '@integer(0, 100)',
      ],
      withdrawRemain: '@float(0, 100, 2, 2)',
    },
  ],
  total: '@integer(0, 100)',
});
module.exports = { statusCode: 200, body };

TODO

  • add unit test.
  • add args judgement(args' type & count) by api property: args.
  • mock data more real.