1.7.1 • Published 2 years ago

@tbmini/api-transform v1.7.1

Weekly downloads
-
License
ISC
Repository
gitlab
Last release
2 years ago

id: api-transform

S端可视化配置转化为通用api-tree,为转译代码做准备。

Install

npm i -s @tbmini/api-transform
// or
yarn add @tbmini/api-transform

Usage

import { IApiConfig, Transpiler } from '@tbmini/api-transform'

const transpiler = new Transpiler({ controllerConfig, projectConfig, beforeAnalysis })

// 根据配置获取api-tree
const apiConfigs = transpiler.getApiConfigs()

// 判 断某模块是否有user定义
const isHasUser = transpiler.isModuleIncludeUser('task')

Options

NameTypeDefaultDescription
projectConfigIProjectConfig-S端可视化运营配置
controllerConfigIAllControllerConfig-S端可视化玩法配置
beforeAnalysisIBeforeAnalysis-S端模板beforeModules静态解析结果(code-parse获取)

Methods

NameTypeDescription
getApiConfigs()=>IApiConfig[]获取api-tree
isModuleIncludeUser(moduleName:string)=> Boolean判断模块是否包含user定义

api-tree结构示例

  login: {
        path: 'login',
        module: {
          type: 'decorator',
          name: 'user',
          decoratorType: 'class',
          deps: ['user', 'awards', 'task']
        },
        validate: {
          key: 'Params',
          params: [
            {
              key: 'activityId',
              type: 'string',
              validators: [
                {
                  key: 'IsString',
                  message: '$必须是字符串'
                },
                {
                  key: 'IsNotEmpty',
                  message: '$必填'
                }
              ]
            },
            {
              key: 'isFollow',
              type: 'boolean',
              validators: [
                {
                  key: 'IsBoolean'
                }
              ]
            }
          ]
        },

        decorators: [
          {
            type: 'decorator',
            decoratorType: 'method',
            key: 'Validate',
            params: [
              {
                type: 'identifier',
                value: 'Params'
              }
            ]
          },
          {
            type: 'decorator',
            decoratorType: 'method',
            key: 'Inject',
            params: [
              {
                type: 'object',
                value: [
                  {
                    key: 'noCheckUser',
                    value: 'true',
                    type: 'boolean'
                  },
                  {
                    key: 'middlewares',
                    value: [
                      {
                        type: 'string',
                        value: 'vipInfo'
                      }
                    ],
                    type: 'array'
                  }
                ]
              }
            ]
            middlewares: {
              type: 'builtIn', // common custom
              key: 'vipInfo'
            }
          },
          {
            key: 'Init',
            type: 'decorator',
            decoratorType: 'method',
            params: []
          },
          {
            key: 'Before',
            type: 'decorator',
            decoratorType: 'method',
            lifecyle: true,
            params: [
              {
                key: 'updateOrderTask',
                type: 'callExpression',
                hasParams: true,
                params: [
                  {
                    type: 'string',
                    value: 'orderGoods'
                  }
                ]
              }
            ]
          }
        ],
        main: [
          {
            type: 'varStatement',
            nodeFlag: 'const',
            left: 'task',
            right: ['this', 'sss', 'eee']
          },
          {
            type: 'method',
            isAsync: true,
            module: 'user',
            name: 'addUserRecord',
            desc: '',
            scope: 'public',
            inputParams: [{ value: 'ctx', type: 'identifier' }],
            outputParams: {
              key: 'addUserResult',
              type: 'Promise<{ openId, newUser, firstLoginToday }>',
              struct: {
                openId: 'string',
                newUser: 'boolean',
                firstLoginToday: 'boolean'
              }
            }
          },
          {
            type: 'rewardCenter',
            params: [],
            method: {
              name: 'send',
              params: []
            },
            returnKey: 'rewardResult'
          },
          {
            type: 'custom',
            key: 'createStatData'
          },
          {
            type: 'resultModel',
            resultType: 'success',
            params: [
              {
                values: [
                  {
                    value: 'addUserRecordResult',
                    type: 'identifier',
                    isSpread: true
                  }
                ],
                type: 'object'
              },
              {
                type: 'number',
                value: '1'
              },
              {
                type: 'string',
                value: '3'
              },
              {
                type: 'boolean',
                value: 'true'
              },
              {
                value: 'addd',
                type: 'identifier',
                isSpread: true
              },
              {
                type: 'callExpression',
                value: 'updateOrder',
                params: []
              },
              {
                type: 'array',
                values: []
              }
            ]
          }
          {
            type: 'method',
            isAsync: true,
            module: 'user',
            name: 'addUserRecord',
            desc: '',
            tbDeps: ['vipInfo'],
            scope: 'public',
            inputParams: [
              {
                key: 'ctx',
                type: 'IContext<Login.Params>',
                struct: {
                  env: 'string',
                  data: {
                    activityId: 'string',
                    userNick: 'string',
                    avatar: 'string',
                    isFollow: 'boolean',
                    'inviteId?': 'string'
                  }
                }
              }
            ],
            outputParams: {
              key: 'addResult',
              type: 'Promise<{ openId, newUser, firstLoginToday }>',
              struct: {
                openId: 'string',
                newUser: 'boolean',
                firstLoginToday: 'boolean'
              }
            }
          }
        ]
      }
1.7.1

2 years ago

1.7.0

2 years ago

1.6.6

2 years ago

1.6.2

2 years ago

1.6.0

3 years ago

1.5.5

3 years ago

1.5.3

3 years ago

1.5.2

3 years ago

1.5.1

3 years ago

1.5.0

3 years ago

1.4.1

3 years ago

1.4.0

3 years ago

1.2.8

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.9

3 years ago

1.2.10

3 years ago

1.2.7

3 years ago

1.2.6

3 years ago

1.2.5

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.0

3 years ago

1.2.1

3 years ago

1.1.0

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago