Skip to content

Commit

Permalink
refa: migrte logger, schema, timer to upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Feb 8, 2024
1 parent 979f2da commit 3ff856a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 28 deletions.
5 changes: 1 addition & 4 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,11 @@
"@types/ws": "^8.5.10"
},
"dependencies": {
"@cordisjs/logger": "^0.1.4",
"@cordisjs/timer": "^0.2.3",
"@satorijs/element": "^3.1.4",
"@satorijs/protocol": "^1.2.1",
"cordis": "^3.7.1",
"cordis": "^3.9.0",
"cordis-axios": "^4.1.0",
"cosmokit": "^1.5.2",
"schemastery": "^3.14.3",
"ws": "^8.14.2"
}
}
3 changes: 1 addition & 2 deletions packages/core/src/adapter.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Awaitable, remove, Time } from 'cosmokit'
import { Status, WebSocket } from '@satorijs/protocol'
import { Context } from '.'
import { Context, Schema } from '.'
import { Bot } from './bot'
import Schema from 'schemastery'

export abstract class Adapter<C extends Context = Context, B extends Bot<C> = Bot<C>> {
static schema = false as const
Expand Down
32 changes: 10 additions & 22 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@ import * as cordis from 'cordis'
import { Awaitable, defineProperty, Dict } from 'cosmokit'
import { Bot } from './bot'
import { Session } from './session'
import Schema from 'schemastery'
import { Schema } from 'cordis'
import { Quester } from 'cordis-axios'
import * as logger from '@cordisjs/logger'
import { TimerService } from '@cordisjs/timer'
import { Event, SendOptions } from '@satorijs/protocol'
import h from '@satorijs/element'

h.warn = new logger.Logger('element').warn
h.warn = new cordis.Logger('element').warn

// do not remove the `type` modifier
// because `esModuleInterop` is not respected by esbuild
export type { Fragment, Render } from '@satorijs/element'

export { Logger } from '@cordisjs/logger'
export { Logger, Schema, Schema as z } from 'cordis'

export { h, h as Element, h as segment }
export { Schema, Schema as z, Quester }
export { Quester }

export * as Satori from '@satorijs/protocol'
export * as Universal from '@satorijs/protocol'
Expand Down Expand Up @@ -100,24 +98,18 @@ export interface Events<C extends Context = Context> extends cordis.Events<C> {
'bot-disconnect'(client: Bot<C>): Awaitable<void>
}

export interface Service extends Context.Associate<'service'> {}
export type EffectScope<C extends Context = Context> = cordis.EffectScope<C>
export type ForkScope<C extends Context = Context> = cordis.ForkScope<C>
export type MainScope<C extends Context = Context> = cordis.MainScope<C>

export class Service<C extends Context = Context> extends cordis.Service<C> {
public logger: logger.Logger
export interface Events<C extends Context = Context> extends cordis.Events<C> {}

constructor(ctx: C, name: string, immediate?: boolean) {
super(ctx, name, immediate)
this.logger = ctx.logger(name)
}
}
export class Service<C extends Context = Context> extends cordis.Service<C> {}

export interface Context {
[Context.config]: Context.Config
[Context.events]: Events<this>
[Context.session]: Session<this>
baseDir: string
http: Quester
timer: TimerService
}

export class Context extends cordis.Context {
Expand Down Expand Up @@ -145,11 +137,7 @@ export class Context extends cordis.Context {

constructor(config: Context.Config = {}) {
super(config)
this.provide('logger', undefined, true)
this.provide('timer', undefined, true)
this.provide('http', undefined, true)
this.plugin(logger)
this.plugin(TimerService)
this.http = new Quester(config.request)
}

Expand All @@ -171,7 +159,7 @@ export class Context extends cordis.Context {
}

export namespace Context {
export interface Config extends cordis.Context.Config {
export interface Config {
request?: Quester.Config
}

Expand Down

0 comments on commit 3ff856a

Please sign in to comment.