New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@tbmini/api-transform

Package Overview
Dependencies
Maintainers
7
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tbmini/api-transform

配置树转换

latest
npmnpm
Version
1.7.1
Version published
Maintainers
7
Created
Source

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'
              }
            }
          }
        ]
      }

FAQs

Package last updated on 27 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts