import { TailorEnv, TailorPrincipal } from "../runtime/types.mjs"; //#region src/plugin/with-context.d.ts /** * Plugin executor factory function type. * Takes context and returns an executor configuration. * Returns unknown since the exact return type depends on createExecutor's generic params. */ export type PluginExecutorFactory = (ctx: Ctx) => unknown; /** * Base args for plugin executor function operations. * Provides typed access to runtime context without requiring specific record types. */ export interface PluginFunctionArgs { /** Workspace ID where the executor runs */ workspaceId: string; /** Application namespace */ appNamespace: string; /** Environment variables */ env: TailorEnv; /** Principal that triggered the event, null for system events */ actor: TailorPrincipal | null; /** Name of the TailorDB table */ typeName: string; /** TailorDB connections by namespace */ tailordb: Record; } /** * Args for plugin executors triggered on record creation. */ export interface PluginRecordCreatedArgs extends PluginFunctionArgs { /** The newly created record */ newRecord: Record; } /** * Args for plugin executors triggered on record update. */ export interface PluginRecordUpdatedArgs extends PluginFunctionArgs { /** The record after update */ newRecord: Record; /** The record before update */ oldRecord: Record; } /** * Args for plugin executors triggered on record deletion. */ export interface PluginRecordDeletedArgs extends PluginFunctionArgs { /** The deleted record */ oldRecord: Record; } /** * Database schema type for plugins. * Since plugins work with dynamic types, the schema uses Record types. */ export type PluginDBSchema = Record>; /** * Base record type for TailorDB records. * All records have an id field. */ export type PluginRecord = { id: string; } & Record; /** * Define a plugin executor that receives context at runtime. * This allows executor definitions to be in separate files while * still receiving dynamic values like typeName, generated types, and namespace. * @param factory - Function that takes context and returns executor configuration * @returns The same factory function (for type inference) * @example * ```typescript * // executors/on-create.ts * import { withPluginContext } from "@tailor-platform/sdk/plugin"; * import { createExecutor, recordCreatedTrigger } from "@tailor-platform/sdk"; * import { getDB } from "@tailor-platform/function-kysely-tailordb"; * * interface MyContext { * sourceTable: TailorAnyDBType; * historyType: TailorAnyDBType; * namespace: string; * } * * export default withPluginContext((ctx) => * createExecutor({ * name: `${ctx.sourceTable.name.toLowerCase()}-on-create`, * trigger: recordCreatedTrigger({ type: ctx.sourceTable }), * operation: { * kind: "function", * body: async (args) => { * const db = getDB(ctx.namespace); * await db.insertInto(ctx.historyType.name).values({ * recordId: args.newRecord.id, * // ... * }).execute(); * }, * }, * }) * ); * ``` */ export declare function withPluginContext(factory: PluginExecutorFactory): PluginExecutorFactory; //#endregion