Skip to content

Commit

Permalink
refa: migrate to cordis latest
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Feb 23, 2024
1 parent 7ae9ac8 commit 0b3f91b
Show file tree
Hide file tree
Showing 10 changed files with 11 additions and 15 deletions.
4 changes: 0 additions & 4 deletions packages/client/client/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ export function useRpc<T>(): Ref<T> {
export interface Internal {}

export class Context extends cordis.Context {
// workaround injection check
// eslint-disable-next-line @typescript-eslint/naming-convention
__v_isRef = undefined

app: App

constructor() {
Expand Down
2 changes: 1 addition & 1 deletion packages/client/client/plugins/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export default class LoaderService extends Service {

await Promise.all(Object.entries(rest).map(([key, { files, paths, data }]) => {
if (this.extensions[key]) return
const scope = this.ctx.isolate(['extension']).plugin(() => {})
const scope = this.ctx.isolate('extension').plugin(() => {})
scope.ctx.extension = this.extensions[key] = { done: ref(false), scope, paths, data: ref(data) }
const task = Promise.all(files.map((url) => {
for (const ext in loaders) {
Expand Down
3 changes: 1 addition & 2 deletions packages/client/client/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { markRaw } from 'vue'
import * as cordis from 'cordis'
import { Context } from './context'

export type Service = cordis.Service<Context>
export const Service = cordis.Service<Context>
export abstract class Service<T = unknown, C extends Context = Context> extends cordis.Service<T, C> {}

export interface Ordered {
order?: number
Expand Down
2 changes: 1 addition & 1 deletion packages/online/src/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ async function createVite() {
...require.resolve('@root/minato/package.json') ? {
'@minatojs/driver-sqlite': '@minatojs/driver-sqlite/src/index.ts',
'@minatojs/sql-utils': '@minatojs/sql-utils/src/index.ts',
'@minatojs/core': '@minatojs/core/src/index.ts',
'minato': 'minato/src/index.ts',
} : {},
'@koishijs/plugin-console': '@koishijs/plugin-console/src/browser/index.ts',
'chokidar': '@koishijs/fs/src/index.ts',
Expand Down
2 changes: 1 addition & 1 deletion plugins/analytics/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Analytics extends DataService<Analytics.Payload> {
private messages: Analytics.Message[] = []
private commands: Analytics.Command[] = []

constructor(ctx: Context, private config: Analytics.Config = {}) {
constructor(ctx: Context, public config: Analytics.Config = {}) {
super(ctx, 'analytics')

ctx.model.extend('analytics.message', {
Expand Down
4 changes: 2 additions & 2 deletions plugins/auth/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function toHash(password: string) {
class AuthService extends Service {
static inject = ['console', 'database']

constructor(ctx: Context, private config: AuthService.Config) {
constructor(ctx: Context, public config: AuthService.Config) {
super(ctx, 'auth')

ctx.model.extend('user', {
Expand Down Expand Up @@ -122,7 +122,7 @@ class AuthService extends Service {
async start() {
const { enabled, username, password } = this.config.admin
if (!enabled) return
this.logger.info('creating admin account')
this.ctx.logger.info('creating admin account')
await this.ctx.database.upsert('user', [{
id: 0,
name: username,
Expand Down
3 changes: 2 additions & 1 deletion plugins/console/src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class NodeConsole extends Console {
: fileURLToPath(new URL('../../dist', base))
}

// @ts-ignore FIXME
get config() {
return this._config
}
Expand Down Expand Up @@ -95,7 +96,7 @@ class NodeConsole extends Console {
if (this.config.open && !this.ctx.get('loader')?.envData.clientCount && !process.env.KOISHI_AGENT) {
open(target)
}
this.logger.info('webui is available at %c', target)
this.ctx.logger.info('webui is available at %c', target)
})
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/locales/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ declare module '@koishijs/console' {
const logger = new Logger('locales')

class LocaleProvider extends DataService<Dict<I18n.Store>> {
constructor(ctx: Context, private config: Config) {
constructor(ctx: Context, public config: Config) {
super(ctx, 'locales', { authority: 4 })

const update = ctx.debounce(() => this.refresh(), 0)
Expand Down
2 changes: 1 addition & 1 deletion plugins/market/src/node/market.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class MarketProvider extends BaseMarketProvider {
onFailure: (name, reason) => {
this.failed.push(name)
if (registry.config.endpoint.startsWith('https://registry.npmmirror.com')) {
if (Quester.isAxiosError(reason) && reason.response?.status === 404) {
if (Quester.Error.is(reason) && reason.response?.status === 404) {
// ignore 404 error for npmmirror
}
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/status/src/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function updateCpuUsage() {
class ProfileProvider extends DataService<ProfileProvider.Payload> {
cached: ProfileProvider.Payload

constructor(ctx: Context, private config: ProfileProvider.Config) {
constructor(ctx: Context, public config: ProfileProvider.Config) {
super(ctx, 'status')

ctx.i18n.define('zh-CN', zhCN)
Expand Down

0 comments on commit 0b3f91b

Please sign in to comment.