Skip to content

Commit

Permalink
typings: adjust typings
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Aug 30, 2020
1 parent 3354b83 commit c991fd5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
4 changes: 2 additions & 2 deletions packages/koishi-core/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ export class App extends Context {
_commands: Command[]
_commandMap: Record<string, Command>
_hooks: Record<keyof any, [Context, (...args: any[]) => any][]>
_userCache: LruCache<number, Observed<Partial<User>>>
_groupCache: LruCache<number, Observed<Partial<Group>>>
_userCache: LruCache<number, Observed<Partial<User>, Promise<void>>>
_groupCache: LruCache<number, Observed<Partial<Group>, Promise<void>>>

private _nameRE: RegExp
private _prefixRE: RegExp
Expand Down
12 changes: 5 additions & 7 deletions packages/koishi-utils/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ const instances: Record<string, Logger> = {}

type LogFunction = (format: any, ...param: any[]) => void

type LogType = 'success' | 'error' | 'info' | 'warn' | 'debug'

export interface Logger extends Record<LogType, LogFunction> {}

export class Logger {
static readonly SUCCESS = 1
static readonly ERROR = 1
Expand Down Expand Up @@ -44,12 +48,6 @@ export class Logger {
private code: number
private displayName: string

public success: LogFunction
public error: LogFunction
public info: LogFunction
public warn: LogFunction
public debug: LogFunction

constructor(private name: string, private showDiff = false) {
if (name in instances) return instances[name]
let hash = 0
Expand All @@ -71,7 +69,7 @@ export class Logger {
return Logger.color(this.code, value, decoration)
}

private createMethod(name: string, prefix: string, minLevel: number) {
private createMethod(name: LogType, prefix: string, minLevel: number) {
this[name] = (...args: [any, ...any[]]) => {
if (this.level < minLevel) return
process.stderr.write(prefix + this.displayName + this.format(...args) + '\n')
Expand Down

0 comments on commit c991fd5

Please sign in to comment.