hm-pinus-parse-interface
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

parse TS interface to TS pinus-protobuf

解析ts的 interface 到ts格式的 pinus-protobuf 。

pinus: https://github.com/node-pinus/pinus

changelog

v1.0.0:
将pinus-parse-interface模块私有化

v1.0.1:
定制项目框架解析需求

v1.0.2:
支持单文件多个路由接口解析

v1.0.3:
修复在handler会生成push路由的问题
add(parse):分为handler和push解析
1、parseHandlerToPinusProtobuf
2、parsePushToPinusProtobuf
3、parseHandlerFile
4、parsePushFile

v1.0.4:
更新README.md

v1.0.5:
add(parse): 修改类型解析机制
1、去掉additionalProperties属性 用format替换
2、新增数组和基础属性统一优先用format表示type
3、number默认 int32
4、需要double的地方需要显示增加注释`/** @format double */`替换

install

npm install hm-pinus-parse-interface

or

yarn add hm-pinus-parse-interface

usage

const main = require('hm-pinus-parse-interface');

const test = main.parseToPinusProtobuf('path_to_you_interface_dir');
console.log('result',JSON.stringify(test,null,4));

interface 结构约定

  1. 俩层目录结构。
  2. 第一层服务器名为目录名。
  3. 第二层Handler或者Push名为目录名。
  4. 请求和响应文件.req.res结尾。
  5. 推送文件.push结尾。
  6. 客户端请求消息接口命名Req结尾。
  7. 服务器响应消息接口命名Res结尾,其余命名部分要和客户端一致。
  8. 服务器推送消息接口命名On开头。

例如:百人牛牛

百人牛牛请求和响应文件名: brnn.req.res.ts

brnn.req.res.ts文件内容:

export interface DoBetReq {
    area: number; // 区域类型
    index: number; // 筹码索引
    /** @format double */
    value?: number; // 筹码值
}

export interface DoBetRes extends BaseRes {
    data?: DoBetData;
}

百人牛牛推送文件名: brnn.push.ts

brnn.push.ts文件内容:

/**
 * 推送玩家下注消息
 */
export interface OnBet {
    userId: string;
    index: number; // 筹码索引
    /** @format double */
    value: number; // 筹码值
    area: number; // 区域类型
    /** @format double */
    areaTotalValue: number; // 当前区域总值
    /** @format double */
    totalValue: number; // 所有区域总值
}

auto generate

serverProtos.ts,clientProtos.ts,dictionary.ts,routes.ts

说明:需要自定义生成脚本逻辑,只供内部使用

Package Sidebar

Install

npm i hm-pinus-parse-interface

Weekly Downloads

1

Version

1.0.5

License

none

Unpacked Size

47.8 kB

Total Files

25

Last publish

Collaborators

  • wjt382063576