@koishijs/core
Advanced tools
Comparing version 4.16.8 to 4.17.0-alpha.0
@@ -5,4 +5,4 @@ import * as utils from '@koishijs/utils'; | ||
import { Dict, Awaitable, Promisify } from 'cosmokit'; | ||
import { Database, Driver, Update, Eval } from '@minatojs/core'; | ||
import { Fragment, Schema, h, Universal, Bot, Quester } from '@satorijs/core'; | ||
import { Database, Driver, Update, Eval } from 'minato'; | ||
import { Fragment, h, Schema, Universal, Bot, Quester } from '@satorijs/core'; | ||
import { LocaleTree } from '@koishijs/i18n-utils'; | ||
@@ -67,5 +67,4 @@ import { Disposable, GetEvents, Parameters, ReturnType, ThisType } from 'cordis'; | ||
} | ||
export class DatabaseService extends Database<Tables> { | ||
protected app: Context; | ||
constructor(app: Context); | ||
export class DatabaseService extends Database<Tables, Context> { | ||
constructor(ctx: Context); | ||
getUser<K extends User.Field>(platform: string, pid: string, modifier?: Driver.Cursor<K>): Promise<Pick<User, K>>; | ||
@@ -82,3 +81,2 @@ setUser(platform: string, pid: string, data: Update<User>): Promise<Driver.WriteResult>; | ||
} | ||
export const defineDriver: <T>(constructor: Driver.Constructor<T>, schema?: Schema, prepare?: Plugin.Function<Context, T>) => Plugin.Object<Context, T>; | ||
export interface Context { | ||
@@ -558,3 +556,3 @@ $processor: Processor; | ||
send(fragment: Fragment, options?: Universal.SendOptions): Promise<string[]>; | ||
cancelQueued(delay?: number): void; | ||
cancelQueued(delay?: any): void; | ||
_next(): void; | ||
@@ -661,6 +659,2 @@ sendQueued(content: Fragment, delay?: number): Promise<string[]>; | ||
export type MainScope = cordis.MainScope<Context>; | ||
export interface Service extends Context.Associate<'service'> { | ||
} | ||
export class Service<C extends Context = Context> extends satori.Service<C> { | ||
} | ||
export { Adapter, Bot, Element, h, Logger, MessageEncoder, Messenger, Quester, Satori, Schema, segment, Universal, z } from '@satorijs/core'; | ||
@@ -687,3 +681,2 @@ export type { Component, Fragment, Render } from '@satorijs/core'; | ||
export interface Context { | ||
[Context.config]: Context.Config; | ||
[Context.events]: Events<this>; | ||
@@ -696,5 +689,5 @@ [Context.session]: Session<never, never, this>; | ||
/** @deprecated use `ctx.root` instead */ | ||
get app(): cordis.Context.Parameterized<this, this[typeof cordis.Context.config]>; | ||
get app(): this; | ||
/** @deprecated use `root.config` instead */ | ||
get options(): this[typeof cordis.Context.config]; | ||
get options(): any; | ||
waterfall<K extends keyof GetEvents<this>>(name: K, ...args: Parameters<GetEvents<this>[K]>): Promisify<ReturnType<GetEvents<this>[K]>>; | ||
@@ -739,2 +732,5 @@ waterfall<K extends keyof GetEvents<this>>(thisArg: ThisType<GetEvents<this>[K]>, name: K, ...args: Parameters<GetEvents<this>[K]>): Promisify<ReturnType<GetEvents<this>[K]>>; | ||
} | ||
export class Service<C extends Context = Context> extends satori.Service<C> { | ||
static Context: typeof Context; | ||
} | ||
export { Context as App }; | ||
@@ -750,3 +746,3 @@ export function defineConfig(config: Context.Config): Context.Config; | ||
export * from '@koishijs/utils'; | ||
export * from '@minatojs/core'; | ||
export * from 'minato'; | ||
export { version }; |
{ | ||
"name": "@koishijs/core", | ||
"description": "Core Features for Koishi", | ||
"version": "4.16.8", | ||
"version": "4.17.0-alpha.0", | ||
"main": "lib/index.cjs", | ||
@@ -36,8 +36,8 @@ "module": "lib/index.mjs", | ||
"@koishijs/utils": "^7.1.2", | ||
"@minatojs/core": "^2.9.0", | ||
"@satorijs/core": "^3.5.0", | ||
"cordis": "^3.7.1", | ||
"@satorijs/core": "^3.5.3", | ||
"cordis": "^3.9.1", | ||
"cosmokit": "^1.5.2", | ||
"fastest-levenshtein": "^1.0.16" | ||
"fastest-levenshtein": "^1.0.16", | ||
"minato": "^3.0.0-alpha.0" | ||
} | ||
} |
@@ -19,5 +19,2 @@ import { defineProperty, Promisify, Time } from 'cosmokit' | ||
export interface Service extends Context.Associate<'service'> {} | ||
export class Service<C extends Context = Context> extends satori.Service<C> {} | ||
export { Adapter, Bot, Element, h, Logger, MessageEncoder, Messenger, Quester, Satori, Schema, segment, Universal, z } from '@satorijs/core' | ||
@@ -47,3 +44,2 @@ export type { Component, Fragment, Render } from '@satorijs/core' | ||
export interface Context { | ||
[Context.config]: Context.Config | ||
[Context.events]: Events<this> | ||
@@ -71,4 +67,5 @@ [Context.session]: Session<never, never, this> | ||
this.provide('database', undefined, true) | ||
this.provide('model', new DatabaseService(this), true) | ||
this.provide('model', undefined, true) | ||
this.provide('$commander', new Commander(this, this.config), true) | ||
this.plugin(DatabaseService) | ||
} | ||
@@ -199,2 +196,6 @@ | ||
export class Service<C extends Context = Context> extends satori.Service<C> { | ||
static Context = Context | ||
} | ||
// for backward compatibility | ||
@@ -201,0 +202,0 @@ export { Context as App } |
import * as utils from '@koishijs/utils' | ||
import { defineProperty, Dict, MaybeArray } from 'cosmokit' | ||
import { Database, Driver, Update } from '@minatojs/core' | ||
import { Fragment, Schema, Universal } from '@satorijs/core' | ||
import { Context, Plugin } from './context' | ||
import { Dict, MaybeArray } from 'cosmokit' | ||
import { Database, Driver, Update } from 'minato' | ||
import { Fragment, Universal } from '@satorijs/core' | ||
import { Context } from './context' | ||
@@ -75,6 +75,5 @@ declare module './context' { | ||
export class DatabaseService extends Database<Tables> { | ||
constructor(protected app: Context) { | ||
super() | ||
defineProperty(this, Context.current, app) | ||
export class DatabaseService extends Database<Tables, Context> { | ||
constructor(ctx: Context) { | ||
super(ctx) | ||
@@ -115,3 +114,3 @@ this.extend('user', { | ||
app.on('login-added', ({ platform }) => { | ||
ctx.on('login-added', ({ platform }) => { | ||
if (platform in this.tables.user.fields) return | ||
@@ -160,3 +159,3 @@ this.migrate('user', { [platform]: 'string(255)' }, async (db) => { | ||
const selfIdMap: Dict<string[]> = Object.create(null) | ||
for (const bot of this.app.bots) { | ||
for (const bot of this.ctx.bots) { | ||
if (platforms && !platforms.includes(bot.platform)) continue | ||
@@ -210,3 +209,3 @@ (selfIdMap[bot.platform] ||= []).push(bot.selfId) | ||
return (await Promise.all(this.app.bots.map((bot) => { | ||
return (await Promise.all(this.ctx.bots.map((bot) => { | ||
const targets = assignMap[bot.platform]?.[bot.selfId] | ||
@@ -227,38 +226,1 @@ if (!targets) return Promise.resolve([]) | ||
} | ||
// workaround typings | ||
DatabaseService.prototype.extend = function extend(this: DatabaseService, name, fields, config) { | ||
Database.prototype.extend.call(this, name, fields, { | ||
...config, | ||
// driver: this[Context.current].mapping.database, | ||
}) | ||
this.app.emit('model', name) | ||
} | ||
// https://github.com/microsoft/TypeScript/issues/15713#issuecomment-499474386 | ||
export const defineDriver = <T, >(constructor: Driver.Constructor<T>, schema?: Schema, prepare?: Plugin.Function<Context, T>): Plugin.Object<Context, T> => ({ | ||
name: constructor.name, | ||
reusable: true, | ||
Config: schema, | ||
filter: false, | ||
async apply(ctx, config) { | ||
config = { ...config } | ||
await prepare?.(ctx, config) | ||
const driver = new constructor(ctx.model, config) | ||
const key = 'default' | ||
ctx.on('ready', async () => { | ||
await driver.start() | ||
ctx.model.drivers[key] = driver | ||
ctx.model.refresh() | ||
const database = Object.create(ctx.model) | ||
ctx.database = database | ||
}) | ||
ctx.on('dispose', async () => { | ||
ctx.database = null | ||
delete ctx.model.drivers[key] | ||
await driver.stop() | ||
}) | ||
}, | ||
}) |
import { defineProperty } from 'cosmokit' | ||
import { Eval } from '@minatojs/core' | ||
import { Eval } from 'minato' | ||
import { Channel, User } from './database' | ||
@@ -4,0 +4,0 @@ import { Context } from './context' |
@@ -5,3 +5,3 @@ // @ts-ignore | ||
export * from '@koishijs/utils' | ||
export * from '@minatojs/core' | ||
export * from 'minato' | ||
export * from './bot' | ||
@@ -8,0 +8,0 @@ export * from './context' |
import { observe } from '@koishijs/utils' | ||
import { Awaitable, isNullable, makeArray } from 'cosmokit' | ||
import { Fragment, h, Logger, Universal } from '@satorijs/core' | ||
import { Eval, executeEval, isEvalExpr } from '@minatojs/core' | ||
import { Eval, executeEval, isEvalExpr } from 'minato' | ||
import * as satori from '@satorijs/core' | ||
@@ -342,3 +342,3 @@ import { Argv } from './command' | ||
if (!this.app.$commander.resolveCommand(argv)) return | ||
this.app.emit(argv.session, `command/before-attach-${key}` as any, argv, fields) | ||
;(this.app as Context).emit(argv.session, `command/before-attach-${key}` as any, argv, fields) | ||
collectFields(argv, argv.command[`_${key}Fields` as any], fields) | ||
@@ -345,0 +345,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
467472
8751
1
+ Addedminato@^3.0.0-alpha.0
+ Addedminato@3.6.1(transitive)
- Removed@minatojs/core@^2.9.0
- Removed@minatojs/core@2.9.0(transitive)
Updated@satorijs/core@^3.5.3
Updatedcordis@^3.9.1