docs: update api doc

This commit is contained in:
chenos 2021-12-05 18:43:26 +08:00
parent c1b560e928
commit bac1912b66
3 changed files with 92 additions and 6 deletions

View File

@ -19,9 +19,7 @@ class Application {
##### Examples ##### Examples
```ts ```ts
app.db.on('xxx', () => { app.db.close();
});
``` ```
## app.resourcer ## app.resourcer
@ -92,13 +90,22 @@ app.i18n.t('Hello');
等同于 app.resourcer.registerActions() 等同于 app.resourcer.registerActions()
```ts
app.actions({
async test(ctx, next) {
ctx.body = 'hello world';
await next();
},
});
```
## app.resource() <Badge>待完善</Badge> ## app.resource() <Badge>待完善</Badge>
等同于 app.resourcer.define() 等同于 app.resourcer.define()
## app.parse() ## app.parse()
等同于 app.cli.parse() 等同于 app.cli.parseAsync()
## app.load() <Badge>待完善</Badge> ## app.load() <Badge>待完善</Badge>

View File

@ -26,6 +26,85 @@ async (ctx, next) {
## ctx.action <Badge>待完善</Badge> ## ctx.action <Badge>待完善</Badge>
### action.params
资源标识定位
- `associatedName`
- `associatedIndex`
- `resourceName`
- `resourceIndex`
request body
- `values` bodyparser 之后的 body
request query
- `filter`
- `fields`
- `pageSize`
- `page`
- `sort`
- 其他参数
### action.mergeParams();
```ts
interface mergeParams {
(params: ActionParams, strategies?: MergeStrategies): void;
}
type MergeStrategyType = 'merge' | 'deepMerge' | 'overwrite' | 'andMerge' | 'orMerge' | 'intersect' | 'union';
type MergeStrategyFunc = (x: any, y: any) => any;
type MergeStrategy = MergeStrategyType | MergeStrategyFunc;
interface MergeStrategies {
[key: string]: MergeStrategy;
}
```
合并策略
- `merge` 浅合并
- `deepMerge` 深层合并(默认)
- `andMerge` and 合并,用于 filter 参数
- `orMerge` or 合并,用于 filter 参数
- `overwrite` 覆盖
- `intersect` 交集,用于 array 类型,也支持逗号间隔的字符串数组
- `union` 并集,去重,用于 array 类型,也支持逗号间隔的字符串数组
特定参数的默认合并策略
```ts
{
filter: 'andMerge',
fields: 'intersect',
appends: 'union',
except: 'union',
whitelist: 'intersect',
blacklist: 'union',
sort: 'overwrite',
}
```
示例
```ts
ctx.action.mergeParams({
filter: { b: 'b1' },
fields: 'a1,b1,c1',
key1: 'abcdef',
}, {
// filter 参数采用 orMerge 策略
filter: 'orMerge',
// fields 参数采用 intersect 策略
fields: 'intersect',
// key1 自定义函数
key1: (x, y) => y.split(''),
});
```
## ctx.i18n ## ctx.i18n
app.i18n 的 cloneInstance。详情见 [I18next API](https://www.i18next.com/overview/api) app.i18n 的 cloneInstance。详情见 [I18next API](https://www.i18next.com/overview/api)

View File

@ -25,7 +25,7 @@ toc: menu
- empty - empty
- notEmpty - notEmpty
## select ## enum
- eq - eq
- ne - ne
@ -34,7 +34,7 @@ toc: menu
- empty - empty
- notEmpty - notEmpty
## multipleSelect ## array
- match - match
- notMatch - notMatch