docs: update api doc

This commit is contained in:
chenos 2021-11-29 10:00:42 +08:00
parent 34cec6480f
commit a5e2d57894

View File

@ -194,6 +194,8 @@ interface ImportOptions {
// @default ['js', 'ts', 'json']
extensions?: string[];
}
// 为了配合 db.import(),提供了一个 extend 方法,用于扩展已有 collection 配置
function extend(collectionOptions: CollectionOptions, mergeOptions?: MergeOptions) {}
```
##### Examples
@ -244,6 +246,51 @@ extend({
});
```
extend 可以自定义 merge 规则([deepmerge](https://www.npmjs.com/package/deepmerge#options)),如:
```ts
extend({
name: 'demos',
actions: [
{
name: 'list',
},
],
}, {
arrayMerge: (t, s) => t.concat(s),
})
```
备注extend 的 fields、hooks 等 array 参数,默认都是 concat 规则string 参数是覆盖,如:
```ts
{
name: 'tests',
repository: 'TestRepository1',
fields: [
{ type: 'string', name: 'name1' },
],
}
extend({
name: 'tests',
repository: 'TestRepository2',
fields: [
{ type: 'string', name: 'name2' },
],
});
// 等同于
{
name: 'tests',
repository: 'TestRepository2',
fields: [
{ type: 'string', name: 'name1' },
{ type: 'string', name: 'name2' },
],
}
```
## `db.on()`
##### Definition