import { ErrorFactory } from "./errors.mjs"; import { SchemaInput, SchemaOutput } from "./components/foundation/modules/command/command.mjs"; import { AnyCommandMiddleware, ApplicationCommand, AuditedOperation, CommandConstructor } from "./components/foundation/client.mjs"; import { GenericDataModel, GenericMutationCtx } from "convex/server"; import { z } from "zod"; import { Value } from "convex/values"; //#region src/crud.d.ts /** * The zodTable surface the factory consumes — structural, so any zodTable / * tenantTable return satisfies it. */ type CrudTable = { tableName: string; commandInput: z.ZodObject>>; storage: z.ZodObject>>; }; type CrudContext = { db: Pick['db'], 'insert' | 'patch'>; }; type MaybePromise = Value | Promise; export type CrudConfig = { /** The Foundation-bound Command class (destructured from the facade). */ Command: CommandConstructor; table: Table; /** Audit aggregate type; enforced by the aggregates allowlist. */ aggregateType: string; /** Observability/audit classification. Default 'business'. */ classification?: string; /** Derives the audited actor id from the ctx (usually ctx.actor.userId). */ actor: (context: Context) => string; /** * Stamps server-owned fields onto creates (tenant, denormalized ids...). * REQUIRED when the table is a tenantTable — forgetting it would insert * untenanted rows; the factory fails fast at construction instead. */ enrich?: (context: Context, command: SchemaOutput) => MaybePromise>>; /** Per-operation preconditions; run before the handlers. */ guards?: { create?: (context: Context, command: never) => MaybePromise; update?: (context: Context, command: never) => MaybePromise; archive?: (context: Context, command: never) => MaybePromise; }; /** Per-operation middleware applied to all three generated operations. */ middleware?: readonly AnyCommandMiddleware[]; errors?: ErrorFactory; }; /** * Generates the standard create/update/archive operations from one zodTable * declaration, fully inside the audited command pipeline: strict command * inputs from `commandFields`, mandatory audit with the declared aggregate * type, soft delete only (archive sets `archivedAt` — no hard-delete * operation is generated, per kit doctrine). * * convex-helpers ships a same-named `crud` helper; it was deliberately not * used — it bypasses the command pipeline (no audits, no guards, and hard * deletes). See docs/crud.md. */ export type CrudCommands = ReturnType>; export declare function createCrudCommands(config: CrudConfig): { commands: ApplicationCommand; }, z.core.$strict>; classification: string; aggregates: string[]; middleware: readonly AnyCommandMiddleware[] | undefined; guard: ((context: Context, command: never) => MaybePromise) | undefined; audit: (resolution: { result: z.output; }, z.core.$strict>>; }, context: Context) => { operation: `${string}.create`; actorId: string; aggregate: { type: string; id: string & { __tableName: string; }; }; }; }> & NamedOperation<`${string}.update`, { command: z.ZodObject<{ id: import("convex-helpers/server/zod4").Zid; data: z.ZodObject<{ [x: string]: z.ZodOptional>>; }, z.core.$strict>; }, z.core.$strict>; result: z.ZodObject<{ ok: z.ZodLiteral; }, z.core.$strict>; classification: string; aggregates: string[]; middleware: readonly AnyCommandMiddleware[] | undefined; guard: ((context: Context, command: never) => MaybePromise) | undefined; audit: (resolution: { command: z.output; data: z.ZodObject<{ [x: string]: z.ZodOptional>>; }, z.core.$strict>; }, z.core.$strict>>; }, context: Context) => { operation: `${string}.update`; actorId: string; aggregate: { type: string; id: string & { __tableName: string; }; }; }; }> & NamedOperation<`${string}.archive`, { command: z.ZodObject<{ id: import("convex-helpers/server/zod4").Zid; }, z.core.$strict>; result: z.ZodObject<{ ok: z.ZodLiteral; }, z.core.$strict>; classification: string; aggregates: string[]; middleware: readonly AnyCommandMiddleware[] | undefined; guard: ((context: Context, command: never) => MaybePromise) | undefined; audit: (resolution: { command: z.output; }, z.core.$strict>>; }, context: Context) => { operation: `${string}.archive`; actorId: string; aggregate: { type: string; id: string & { __tableName: string; }; }; }; }>>; operations: NamedOperation<`${string}.create`, { command: Table["commandInput"]; result: z.ZodObject<{ id: import("convex-helpers/server/zod4").Zid; }, z.core.$strict>; classification: string; aggregates: string[]; middleware: readonly AnyCommandMiddleware[] | undefined; guard: ((context: Context, command: never) => MaybePromise) | undefined; audit: (resolution: { result: z.output; }, z.core.$strict>>; }, context: Context) => { operation: `${string}.create`; actorId: string; aggregate: { type: string; id: string & { __tableName: string; }; }; }; }> & NamedOperation<`${string}.update`, { command: z.ZodObject<{ id: import("convex-helpers/server/zod4").Zid; data: z.ZodObject<{ [x: string]: z.ZodOptional>>; }, z.core.$strict>; }, z.core.$strict>; result: z.ZodObject<{ ok: z.ZodLiteral; }, z.core.$strict>; classification: string; aggregates: string[]; middleware: readonly AnyCommandMiddleware[] | undefined; guard: ((context: Context, command: never) => MaybePromise) | undefined; audit: (resolution: { command: z.output; data: z.ZodObject<{ [x: string]: z.ZodOptional>>; }, z.core.$strict>; }, z.core.$strict>>; }, context: Context) => { operation: `${string}.update`; actorId: string; aggregate: { type: string; id: string & { __tableName: string; }; }; }; }> & NamedOperation<`${string}.archive`, { command: z.ZodObject<{ id: import("convex-helpers/server/zod4").Zid; }, z.core.$strict>; result: z.ZodObject<{ ok: z.ZodLiteral; }, z.core.$strict>; classification: string; aggregates: string[]; middleware: readonly AnyCommandMiddleware[] | undefined; guard: ((context: Context, command: never) => MaybePromise) | undefined; audit: (resolution: { command: z.output; }, z.core.$strict>>; }, context: Context) => { operation: `${string}.archive`; actorId: string; aggregate: { type: string; id: string & { __tableName: string; }; }; }; }>; executeCreate: (context: Context, command: SchemaInput) => Promise<{ id: string & { __tableName: string; }; }>; executeUpdate: (context: Context, command: { id: string; data: { [x: string]: unknown; }; }) => Promise<{ ok: true; }>; executeArchive: (context: Context, command: { id: string; }) => Promise<{ ok: true; }>; }; type NamedOperation = { [Key in Name]: Definition; }; //#endregion //# sourceMappingURL=crud.d.mts.map