@tbmini/api-transform
v1.7.1
Published
配置树转换
Downloads
2
Keywords
Readme
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
|Name|Type|Default|Description|
|:--:|:--:|:-----:|:----------|
|projectConfig
|IProjectConfig
|-
| S端可视化运营配置
|controllerConfig
|IAllControllerConfig
|-
|S端可视化玩法配置
|beforeAnalysis
|IBeforeAnalysis
|-
| S端模板beforeModules静态解析结果(code-parse获取)
Methods
|Name|Type|Description|
|:--:|:--:|:----------|
|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'
}
}
}
]
}