Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Aug 10, 2021
2 parents f78c66a + c7d409e commit d41c9b7
Show file tree
Hide file tree
Showing 60 changed files with 663 additions and 440 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
atri
temp
dist
lib
*.js
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ jobs:
file: ./coverage/coverage-final.json
name: codecov
- name: Publish
run: npx ts-node build/publish
run: yarn pub
3 changes: 2 additions & 1 deletion build/dep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ interface Dependency {
for (const type of ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies'] as const) {
for (const dep in meta[type] || {}) {
// skip workspaces and symlinks
if (workspaces[dep] || meta[type][dep].includes(':')) continue
const version = meta[type][dep]
if (workspaces[dep] || version === '*' || version.includes(':')) continue
if (!dependencies[dep]) dependencies[dep] = { dependents: [] }
dependencies[dep].dependents.push({ name, type })
}
Expand Down
2 changes: 1 addition & 1 deletion build/dtsc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ async function bundle(path: string) {
return line
.replace(internalImport, '')
.replace(/import\("index"\)/g, 'import(".")')
.replace(/^((module|class|namespace) .+ \{)$/, (_) => `declare ${_}`)
.replace(/^(module|class|namespace|const) /, (_) => `declare ${_}`)
} else {
return ''
}
Expand Down
10 changes: 7 additions & 3 deletions docs/.vuepress/components/ChatMessage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,9 @@ $msgbox-left: 4.2rem;
margin-left: $msgbox-left;
width: fit-content;
border-radius: 0.5rem;
background-color: white;
background-color: var(--c-bg);
word-break: break-all;
transition: background-color ease 0.3s;
.chat-message:not(.no-padding) &{
padding: 0.5rem 0.7rem;
Expand Down Expand Up @@ -165,7 +166,8 @@ $msgbox-left: 4.2rem;
border-bottom-width: 8px;
border-bottom-color: currentColor;
border-radius: 0 0 0 32px;
color: white;
color: var(--c-bg);
transition: color ease 0.3s;
}
p {
Expand All @@ -179,7 +181,9 @@ $msgbox-left: 4.2rem;
border: none;
border-radius: 0.5rem;
padding: 0.2rem 0.6rem;
color: grayscale(10%);
background-color: var(--c-bg-light);
color: var(--c-text-lighter);
transition: background-color ease 0.3s, color ease 0.3s;
}
}
Expand Down
3 changes: 2 additions & 1 deletion docs/.vuepress/components/PanelView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ $textShadow: 1px 1px 1px rgba(23, 31, 35, 0.5);
border-radius: 6px;
margin: 1rem 0;
overflow-x: auto;
background-color: #f3f6f9;
background-color: var(--c-bg-light);
transition: background-color ease 0.3s;
&.manager {
background-color: #032f62;
Expand Down
47 changes: 31 additions & 16 deletions docs/api/database.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sidebarDepth: 2

# 数据库 (Database)

## 数据类型
## 内置表

### User

Expand Down Expand Up @@ -49,11 +49,13 @@ sidebarDepth: 2
### Tables.extend(name, config?)

- **name:** `string` 数据表名
- **config:** `TableMeta` 表的基本配置
- **config:** `Table.Meta` 表的基本配置
- **config.primary:** `string` 主键名,默认为 `'id'`
- **config.unique:** `string[]` 值唯一的键名列表
- **config.type:** `string` 主键产生的方式,目前支持:
- `incremental`: 检测目前最大的主键值,并增加 1 作为新的主键值
- `incremental`: 检测目前最大的主键值,并增加 1 作为新的主键值,适用于数值类型的主键
- `random`: 产生一个随机字符串作为新的主键值,适用于字符串类型的主键
- 注意:如果你的主键值是用户指定的,那么你将不需要此项配置

扩展一个新的数据表。

Expand All @@ -67,15 +69,15 @@ sidebarDepth: 2

扩展数据库的功能。

## 数据库对象
## ORM API

一个 Database 对象代理了 Koishi 上下文绑定的应用实例有关的所有数据库访问。同时它具有注入特性,任何插件都可以自己定义数据库上的方法。本章主要介绍数据库的官方接口。注意:**它们并不由 Koishi 自身实现,而是由每个数据库分别实现的**。Koishi 只是提供了一套标准。

### db.get(table, query, fields?)
### db.get(table, query, modifier?)

- **table:** `keyof Tables` 注册在 ORM 中的表名
- **query:** `QueryExpr<Tables[T]> | QueryShorthand` 搜索表达式
- **fields:** `Tables.Field<T>[]` 请求的字段,默认为全部字段
- **modifier:** `QueryModifier<keyof Tables[T]>` 请求修饰符
- 返回值: `Promise<Tables[T][]>` 用户数据

参数 query 支持正则以及表达式,你可以使用复杂的嵌套更细致化的去完成你对数据库的查找服务。实现上与 mongo 近似,如果你有使用过 mongodb 经验,那么使用 Koishi ORM 对你来说便不是一件难事。
Expand All @@ -92,16 +94,26 @@ interface FieldQueryExpr<T> {
$lt?: T
$lte?: T
}

interface LogicalQueryExpr<T> {
$or?: QueryExpr<T>[]
$and?: QueryExpr<T>[]
$not?: QueryExpr<T>
}
type QueryShorthand<T = IndexType> = T[] | RegExp

type QueryShorthand<T> = T[] | RegExp
type FieldQuery<T> = FieldQueryExpr<T> | QueryShorthand<T>
type QueryExpr<T = any> = LogicalQueryExpr<T> & {
type QueryExpr<T> = LogicalQueryExpr<T> & {
[K in keyof T]?: FieldQuery<T[K]>
}

interface QueryOptions<T extends string> {
limit?: number
offset?: number
fields?: T[]
}

type QueryModifier<T extends string> = T[] | QueryOptions<T>
```
下面是一些简单的示例
Expand All @@ -124,6 +136,9 @@ const rows = await ctx.database.get('schedule', {
id: { $gt: 2, $lte: 5 },
$or: [{ $id: { $gt: 100 } }],
})

// 只获取 id 和 command 字段(默认情况下将获取全部字段)
const rows = await ctx.database.get('schedule', 1, ['id', 'command'])
```

### db.remove(table, query)
Expand All @@ -132,11 +147,13 @@ const rows = await ctx.database.get('schedule', {

### db.update(table, data, key?)

### db.getUser(type, id, fields?)
## 数据库方法

### db.getUser(type, id, modifier?)

- **type:** `string` 平台名
- **id:** `string | string[]` 用户标识符
- **fields:** `User.Field[]` 请求的字段,默认为全部字段
- **modifier:** `QueryModifier<User.Field>` 请求修饰符
- 返回值: `Promise<User | User[]>` 用户数据

向数据库请求用户数据。如果传入的 id 是一个列表,则返回值也应当是一个列表。
Expand All @@ -146,25 +163,24 @@ const rows = await ctx.database.get('schedule', {
:::

### db.setUser(type, id, data)
### db.createUser(type, id, data)

- **type:** `string` 平台名
- **id:** `string` 用户标识符
- **data:** `User` 要修改 / 添加的数据
- 返回值: `Promise<void>`

向数据库修改 / 添加用户数据
向数据库修改或添加用户数据

### db.getChannel(type, id, fields?)

- **type:** `string` 平台名
- **id:** `string | string[]` 频道标识符
- **fields:** `ChannelField[]` 请求的字段,默认为全部字段
- **fields:** `QueryModifier<User.Field>` 请求修饰符
- 返回值: `Promise<Channel | Channel[]>` 频道数据

向数据库请求频道数据。如果传入的 id 是一个列表,则返回值也应当是一个列表。

### db.getChannelList(fields?, type?, assignees?)
### db.getAssignedChannels(fields?, type?, assignees?)

- **fields:** `ChannelField[]` 请求的字段,默认为全部字段
- **type:** `string` 平台名,默认为全平台
Expand All @@ -174,11 +190,10 @@ const rows = await ctx.database.get('schedule', {
向数据库请求被特定机器人管理的所有频道数据。这里的两个参数可以写任意一个,都可以识别。

### db.setChannel(type, id, data)
### db.createChannel(type, id, data)

- **type:** `string` 平台名
- **id:** `number` 频道标识符
- **data:** `Channel` 要修改 / 添加的数据
- 返回值: `Promise<void>`

向数据库修改 / 添加频道数据
向数据库修改或添加频道数据
12 changes: 6 additions & 6 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
"build": "vuepress build ."
},
"devDependencies": {
"@vuepress/plugin-docsearch": "^2.0.0-beta.12",
"@vuepress/plugin-pwa": "^2.0.0-beta.12",
"@vuepress/plugin-register-components": "^2.0.0-beta.12",
"@vuepress/plugin-docsearch": "^2.0.0-beta.23",
"@vuepress/plugin-pwa": "^2.0.0-beta.23",
"@vuepress/plugin-register-components": "^2.0.0-beta.23",
"diacritics": "^1.3.0",
"shiki": "^0.9.3",
"typescript": "^4.2.4",
"shiki": "^0.9.6",
"typescript": "^4.3.5",
"vuepress-plugin-medium-zoom": "^1.1.9",
"vuepress-vite": "^2.0.0-beta.12"
"vuepress-vite": "^2.0.0-beta.23"
}
}
47 changes: 23 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,61 +28,60 @@
"test:html": "rimraf coverage && c8 -r html yarn test",
"test:text": "c8 -r text yarn test",
"lint": "eslint packages/*/src/**/*.ts --fix --cache",
"pub": "yarn build && yarn build:web && node -r ./build/register build/publish",
"pub": "node -r ./build/register build/publish",
"webui": "yarn workspace koishi-plugin-webui",
"shiki": "yarn workspace bot-shiki",
"utsuho": "yarn workspace bot-utsuho"
},
"version": "1.0.0",
"license": "MIT",
"devDependencies": {
"@octokit/rest": "^18.5.3",
"@octokit/rest": "^18.9.0",
"@sinonjs/fake-timers": "^6.0.1",
"@types/chai": "^4.2.17",
"@types/chai-as-promised": "^7.1.3",
"@types/chai": "^4.2.21",
"@types/chai-as-promised": "^7.1.4",
"@types/cross-spawn": "^6.0.2",
"@types/estree": "^0.0.47",
"@types/fs-extra": "^9.0.11",
"@types/mocha": "^8.2.2",
"@types/node": "^15.0.2",
"@types/rimraf": "^3.0.0",
"@types/semver": "^7.3.5",
"@types/sinonjs__fake-timers": "^6.0.2",
"@types/source-map-support": "^0.5.3",
"@types/fs-extra": "^9.0.12",
"@types/mocha": "^9.0.0",
"@types/node": "^16.4.13",
"@types/rimraf": "^3.0.1",
"@types/semver": "^7.3.8",
"@types/sinonjs__fake-timers": "^6.0.3",
"@types/source-map-support": "^0.5.4",
"@typescript-eslint/eslint-plugin": "^3.10.1",
"@typescript-eslint/parser": "^3.10.1",
"c8": "^7.7.2",
"c8": "^7.8.0",
"cac": "^6.7.3",
"chai": "^4.3.4",
"chai-as-promised": "^7.1.1",
"cross-env": "^7.0.3",
"cross-spawn": "^7.0.3",
"del": "^6.0.0",
"esbuild": "^0.11.18",
"eslint": "^7.25.0",
"eslint-config-standard": "^16.0.2",
"esbuild": "^0.12.19",
"eslint": "^7.32.0",
"eslint-config-standard": "^16.0.3",
"eslint-import-resolver-typescript": "^2.4.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-import": "^2.24.0",
"eslint-plugin-mocha": "^8.1.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.3.1",
"eslint-plugin-standard": "^4.1.0",
"fs-extra": "^9.1.0",
"globby": "^11.0.3",
"jest-mock": "^26.6.2",
"jest-mock": "^27.0.6",
"json5": "^2.2.0",
"kleur": "^4.1.4",
"latest-version": "^5.1.0",
"mocha": "^8.3.2",
"nock": "^13.0.11",
"open": "^8.0.7",
"ora": "^5.4.0",
"mocha": "^9.0.3",
"nock": "^13.1.1",
"open": "^8.2.1",
"ora": "^5.4.1",
"p-map": "^4.0.0",
"prompts": "^2.4.1",
"rimraf": "^3.0.2",
"semver": "^7.3.5",
"source-map-support": "^0.5.19",
"tsconfig-paths": "^3.9.0",
"typescript": "^4.2.4"
"tsconfig-paths": "^3.10.1",
"typescript": "^4.3.5"
}
}
10 changes: 5 additions & 5 deletions packages/adapter-discord/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@
"koishi"
],
"peerDependencies": {
"koishi-core": "^3.13.0"
"koishi-core": "^3.13.1"
},
"devDependencies": {
"@types/es-aggregate-error": "^1.0.2",
"@types/ws": "^7.4.2",
"koishi-test-utils": "^6.1.0"
"@types/ws": "^7.4.7",
"koishi-test-utils": "^6.2.0"
},
"dependencies": {
"axios": "^0.21.1",
"es-aggregate-error": "^1.0.5",
"file-type": "^16.3.0",
"file-type": "^16.5.3",
"form-data": "^4.0.0",
"ws": "^7.4.5"
"ws": "^8.0.0"
}
}
6 changes: 3 additions & 3 deletions packages/adapter-kaiheila/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
"koishi"
],
"peerDependencies": {
"koishi-core": "^3.13.0"
"koishi-core": "^3.13.1"
},
"devDependencies": {
"koishi-test-utils": "^6.1.0"
"koishi-test-utils": "^6.2.0"
},
"dependencies": {
"axios": "^0.21.1",
"form-data": "^4.0.0",
"ws": "^7.4.5"
"ws": "^8.0.0"
}
}
12 changes: 6 additions & 6 deletions packages/adapter-onebot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@
"koishi"
],
"peerDependencies": {
"koishi-core": "^3.13.0"
"koishi-core": "^3.13.1"
},
"devDependencies": {
"@types/ws": "^7.4.2",
"@types/ws": "^7.4.7",
"get-port": "^5.1.1",
"koishi-test-utils": "^6.1.0"
"koishi-test-utils": "^6.2.0"
},
"dependencies": {
"axios": "^0.21.1",
"koishi-utils": "^4.2.3",
"qface": "1.1.0",
"ws": "^7.4.5"
"koishi-utils": "^4.2.4",
"qface": "^1.2.0",
"ws": "^8.0.0"
}
}
Loading

0 comments on commit d41c9b7

Please sign in to comment.