Skip to content
Classplugin-kyselyv0.9.0

Kysely

Connects a bot to any database that Kysely has a dialect for.

Opens the connection, runs your migrations, and loads your service classes.

class Kysely extends Plugin<{
    transport: "any";
    runtime: "server";
}>

Member visibility

Filter class members by access level.

connection

The Kysely instance that the plugin built from your dialect.

public get connection(): Kysely<KyselySchema>

Throws:

A SeedcordError if accessed before the plugin connects.

core

The host, typed to the transport whose Plugin base this class extends.

protected core: TCore

Inherited from:Plugin

dispatchMembers

Adds values that every handler can read. Each key becomes a member, like this.tag, and its function returns the value. Gates and Notice.render read the same values on ctx.

Seedcord calls each function once per interaction, and once per event that has a handler.

attach() throws if seedcord already uses one of these keys, like reply, if another plugin on the bot uses it, or if the bot attaches this plugin twice.

readonly dispatchMembers?: DispatchMemberFunctions
public override readonly dispatchMembers = {
    tag: (origin: DispatchOrigin) => `${origin.guildId}:${origin.userId}`
};

Inherited from:Plugin

id

public static readonly id

kv

This plugin's records in the bot's config.kv, stored under its attach key. Two attachments of one plugin class each get their own records. Renaming the attach key leaves the records under the old key behind.

protected kv: Kv
// works in a field initializer, the constructor, and every method
private readonly jobs = this.kv.collection<Job>('job');

Inherited from:Plugin

Throws:

  • A SeedcordTypeError when something built the plugin with new outside attach().

logger

Logs under the plugin's class name, on the channel its attach key sets.

protected readonly logger: Logger

Inherited from:Plugin

services

Your services, keyed by the name you pass to @RegisterKyselyService.

public get services(): KyselyServices

Throws:

A SeedcordError if accessed before the plugin finishes initializing.

dispose()

public override async dispose(): Promise<void>

fetch()

Answers a web request sent to the bot. seedcord calls this on each plugin in attach order and answers with the first Response. On an http bot, seedcord calls it for interactions too. Return undefined to pass the request on. If this method throws, seedcord logs the error on this plugin's logger and answers the request with a 500.

On an http bot, check the path before you await anything because every interaction waits for this method. On a server, requests reach it once the Ready phase begins. It can run before ready() finishes, and before an init() that you moved to Ready.

fetch?(
    request: Request
): Promisable<Response | undefined>

Throws:

seedcord throws a SeedcordError when this method reads or locks the body without answering the request.

public fetch(request: Request): Response | undefined {
    if (new URL(request.url).pathname !== '/status') return undefined;
    return Response.json({ ok: true });
}

Inherited from:Plugin

init()

Connects through your dialect, runs any startup migrations, and loads decorated services.

public async init(): Promise<void>

listMigrations()

Lists every migration and whether it has run.

public async listMigrations(): Promise<readonly MigrationInfo[]>

Throws:

A SeedcordError if called before the plugin connects.

listPendingMigrations()

Lists unapplied migrations.

public async listPendingMigrations(): Promise<MigrationInfo[]>

Throws:

A SeedcordError if called before the plugin connects.

migrate()

Runs migrations using the supplied options.

public async migrate(
    options?: MigrationOptions
): Promise<void>
Parameter: options

Target migration or direction overrides

Throws:

A SeedcordError if called before the plugin connects.

migrateDown()

Reverts the last migration, or the last steps of them.

public async migrateDown(
    options?: StepMigrationOptions
): Promise<void>

Throws:

A SeedcordError if called before the plugin connects.

migrateUp()

Runs the next pending migration, or steps of them.

public async migrateUp(
    options?: StepMigrationOptions
): Promise<void>

Throws:

A SeedcordError if called before the plugin connects.

prepareCommands()

Changes commands before seedcord sends them to Discord. Write your changes onto these objects, like setting name_localizations. Each command appears once, even when it deploys to several guilds.

If it throws, the deploy stops, and so do seedcord codegen, a Workers build, seedcord commands deploy, and seedcord commands list.

The CLI calls this without running init(). Read only what the constructor stored and the bot's files.

prepareCommands?(
    commands: readonly RESTPostAPIApplicationCommandsJSONBody[]
): Promisable<void>

Inherited from:Plugin

ready()

Runs in the Ready phase after every attached plugin's init() has resolved. The other Ready tasks run alongside it, including the http server binding its port.

Override it when your work needs a logged-in client or a resolved application id.

ready?(): Promisable<void>

Inherited from:Plugin

registerCommandFiles()

Tells seedcord dev which files your prepareCommands reads. Saving one of them in seedcord dev shows the command refresh prompt.

protected registerCommandFiles(patterns: string[]): void
Parameter: patterns

Glob patterns. A relative one resolves against root from seedcord.config.ts. A pattern that starts with ! excludes the files it matches.

Inherited from:Plugin

registerCriticalFiles()

Registers critical file patterns that should trigger a full restart when changed in Dev HMR.

protected registerCriticalFiles(
    patterns: string[]
): void
Parameter: patterns

Glob patterns. A relative one resolves against root from seedcord.config.ts. A pattern that starts with ! excludes the files it matches from the other patterns in this call.

Inherited from:Plugin

rejectOptions()

Rejects the options this plugin got.

protected rejectOptions(reason: string): never
Parameter: reason

Why the options are invalid.

Throws:

A SeedcordTypeError every time, with the plugin class name and reason in its message.

Inherited from:Plugin