Skip to content

Commit

Permalink
refa: update cordis version
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Jun 16, 2022
1 parent 78058a4 commit ee831e0
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 32 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"cross-env": "^7.0.3",
"cross-spawn": "^7.0.3",
"del": "^6.1.1",
"dtsc": "^1.1.0",
"dtsc": "^1.1.1",
"esbuild": "^0.12.29",
"eslint": "^7.32.0",
"eslint-config-standard": "^16.0.3",
Expand All @@ -85,7 +85,7 @@
"semver": "^7.3.7",
"source-map-support": "^0.5.21",
"typescript": "^4.7.2",
"yakumo": "^0.2.6",
"yakumo": "^0.2.7",
"yakumo-mocha": "^0.2.4",
"yakumo-publish": "^0.2.4",
"yakumo-upgrade": "^0.2.3",
Expand Down
18 changes: 8 additions & 10 deletions packages/cli/src/worker/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@ declare module 'koishi' {
}
}

namespace Plugin {
interface Runtime {
[Loader.kWarning]?: boolean
}
interface Runtime {
[Loader.kWarning]?: boolean
}

// Theoretically, these properties will only appear on `Plugin.Fork`.
// We define them directly on `Plugin.State` for typing convenience.
interface State {
[Loader.kRecord]?: Dict<Plugin.Fork>
alias?: string
}
// Theoretically, these properties will only appear on `Fork`.
// We define them directly on `State` for typing convenience.
interface State {
[Loader.kRecord]?: Dict<Fork>
alias?: string
}
}

Expand Down
8 changes: 4 additions & 4 deletions packages/cli/src/worker/watcher.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { App, coerce, Context, Dict, Logger, makeArray, Plugin, Schema } from 'koishi'
import { App, coerce, Context, Dict, Logger, makeArray, Runtime, Schema } from 'koishi'
import { FSWatcher, watch, WatchOptions } from 'chokidar'
import { relative, resolve } from 'path'
import { debounce } from 'throttle-debounce'
Expand Down Expand Up @@ -227,10 +227,10 @@ class Watcher {
this.analyzeChanges()

/** plugins pending classification */
const pending = new Map<string, Plugin.Runtime>()
const pending = new Map<string, Runtime>()

/** plugins that should be reloaded */
const reloads = new Map<Plugin.Runtime, string>()
const reloads = new Map<Runtime, string>()

// we assume that plugin entry files are "atomic"
// that is, reloading them will not cause any other reloads
Expand All @@ -256,7 +256,7 @@ class Watcher {

// prepare for reload
let isMarked = false
const visited = new Set<Plugin.Runtime>()
const visited = new Set<Runtime>()
const queued = [runtime]
while (queued.length) {
const runtime = queued.shift()
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
},
"dependencies": {
"@koishijs/utils": "^5.4.5",
"cordis": "^1.4.1",
"cordis": "^1.4.3",
"fastest-levenshtein": "^1.0.12",
"minato": "^1.1.0"
}
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/protocol/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Argv, Command } from '../command'
import { Awaitable } from 'cosmokit'
import { defineProperty, isNullable, Logger, makeArray, observe, Promisify, Random, segment } from '@koishijs/utils'
import { Middleware, Next } from '.'
import { App } from 'cordis'
import { App, Context } from 'cordis'
import { Bot } from './bot'

type Genres = 'friend' | 'channel' | 'guild' | 'guild-member' | 'guild-role' | 'guild-file' | 'guild-emoji'
Expand Down Expand Up @@ -127,6 +127,10 @@ export class Session<U extends User.Field = never, G extends Channel.Field = nev
defineProperty(this, '_queuedTimeout', null)
}

[Context.filter](ctx: Context) {
return ctx.filter(this)
}

get uid() {
return `${this.platform}:${this.userId}`
}
Expand Down
10 changes: 2 additions & 8 deletions packages/core/src/selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,8 @@ function property<K extends keyof Session>(ctx: Context, key: K, ...values: Sess

export class SelectorService {
constructor(private ctx: Context) {
ctx.on('logger/error', (name, ...args) => {
this.logger(name).error(...args)
})
ctx.on('logger/warn', (name, ...args) => {
this.logger(name).warn(...args)
})
ctx.on('logger/debug', (name, ...args) => {
this.logger(name).debug(...args)
ctx.on('internal/warn', (format, ...args) => {
this.logger('app').warn(format, ...args)
})
}

Expand Down
2 changes: 1 addition & 1 deletion packages/koishi/src/patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ declare module '@koishijs/core' {

namespace Registry {
interface Delegates {
plugin(path: string, config?: any): Plugin.Fork
plugin(path: string, config?: any): Fork
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions plugins/frontend/insight/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { camelize, capitalize, Context, Dict, Plugin, Schema } from 'koishi'
import { camelize, capitalize, Context, Dict, Fork, Plugin, Schema, State } from 'koishi'
import { debounce } from 'throttle-debounce'
import { DataService } from '@koishijs/plugin-console'
import { resolve } from 'path'
Expand All @@ -22,7 +22,7 @@ function getName(plugin: Plugin) {
return format(plugin.name)
}

function getSourceId(child: Plugin.Fork) {
function getSourceId(child: Fork) {
const { state } = child.parent
if (state.runtime.isForkable) {
return state.uid
Expand Down Expand Up @@ -97,7 +97,7 @@ class Insight extends DataService<Insight.Payload> {
// M: target main state
// Service dependencies will be connected from the last node of each path

function addNode(state: Plugin.State) {
function addNode(state: State) {
const { uid, alias, disposables } = state
const weight = disposables.length
const node = { uid, rid, name, weight }
Expand Down
4 changes: 2 additions & 2 deletions plugins/frontend/manager/src/writer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DataService } from '@koishijs/plugin-console'
import { Adapter, App, Bot, Context, Plugin, remove } from 'koishi'
import { Adapter, App, Bot, Context, Fork, remove } from 'koishi'
import { Loader } from '@koishijs/cli'

declare module '@koishijs/plugin-console' {
Expand Down Expand Up @@ -181,7 +181,7 @@ class ConfigWriter extends DataService<App.Config> {
this.loader.writeConfig()
}

private locate(name: string, parent: Plugin.State): Plugin.Fork {
private locate(name: string, parent: Fork): Fork {
for (const key in parent.config) {
const value = parent.config[key]
const fork = parent[Loader.kRecord][key]
Expand Down

0 comments on commit ee831e0

Please sign in to comment.