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 🙏

© 2024 – Pkg Stats / Ryan Hefner

n-thrift

v0.4.2

Published

Apache Thrift implementation with node js

Downloads

1

Readme

N-Thrift

English document is being prepared

简介

n-thrift 是 Apache Thrift 的一个 nodejs 的实现,包含了 thrift compiler 和运行类库,相较于官方维护的 thrift, n-thrift 具有以下特点:

  1. 支持出参和入参自动实例化
  2. 支持es2016+,支持map、set等数据结构,支持服务端客户端都使用Promise
  3. 支持namespace,生成文件添加index.js文件,可以极为方便的发布到私有库
  4. 灵活配置,支持i64默认转换为string
  5. 支持esm,支持生成.mjs文件
  6. 支持struct field编码风格,如thrift定义风格为snakeCase,可以选择编译为camelCase,node端返回的都是camelCase的数据

安装

npm i n-thrift -S

全局安装

npm i n-thrift -g

使用

定义thrift文件 tutorial.thrift

namespace js test

struct Result {
  1:string name;
}

struct Request {
  1:string some;
}

service MyService {
  Result hello(1:Request request)
}

编译

n-thrift <thriftFileDir> [options]
//项目内安装用npx
npx n-thrift <thriftFileDir> [options]

node-thrift ./thrift -o lib -e mjs -m esm

options

| 配置项 | 简写 | 默认 | 描述 | | ----------- | ---- | --------- | ------------------------------------------- | | --out | -o | '.' | 输出文件路径 | | --module | -m | 'cjs' | js模块方式,支持cjsesm | | --extname | -e | 'js' | 生成文件后缀 | | --fieldcase | -fc | 'default' | field代码风格,支持camelCasesnakeCase |

服务端

const nThrift = require('n-thrift');
const thriftType = require('./lib');

const { MyServiceServer } = thriftType.test.tutorial

class MyService extends MyServiceServer {
  async hello(request){
    //do something
    return { name: request.some };
  }
}

const server = nThrift.createServer(MyService);
server.listen(9090);

客户端

const nThrift = require('n-thrift');
const thriftType = require('./lib');

const { MyServiceClient } = thriftType.test.tutorial
const connection = nThrift.createConnection('localhost', 9090)
const myService = nThrift.createClient(MyServiceClient, connection);

myService.hello({some:'hello'}).then(result => {
  console.log(result.name) // 'hello'
})

//可以在异步方法中使用
async function someFunc(){
  const result = await myService.hello({some:'world'});
  console.log(result.name) // 'world'
}