import { CommandArgument, CommandExecution, CommandHandlerResult, CommandInput, CommandRegistry, CommandResult, CommandSchema, Parseable, SchemaInput, SchemaOutput } from "./modules/command/command.mjs"; import { CommandObservation, Observability, ObservabilityOptions } from "./modules/observability/observability.mjs"; import { AnyQueryMiddleware, Query, QueryExecution, QueryMiddleware } from "./modules/query/query.mjs"; import { Result, ResultBoundary, TransactionMetricsContext, executeResultBoundary, projectResult } from "./result.mjs"; import { emitSemanticEvent } from "./telemetry.mjs"; import { CommandPreparation, OperationExtension, OperationHostContext, TypedOperation, operationFactory } from "./operation.mjs"; import "./client.mjs"; import { Value } from "convex/values"; declare namespace client_d_exports { export { AnyCommandMiddleware, AnyQueryMiddleware, ApplicationCommand, AuditEntryInput, AuditWriter, AuditedOperation, AuditedRegistry, CommandArgument, CommandConstructor, CommandDefaults, CommandExecution, CommandHandlerResult, CommandInput, CommandMiddleware, CommandObservation, CommandPreparation, CommandRegistry, CommandResult, Foundation, FoundationOptions, ObservabilityOptions, Parseable, PermissionChecker, QueryExecution, QueryMiddleware, Result, ResultBoundary, SchemaOutput, TransactionMetricsContext, TypedOperation }; } /** Shape handed to the injected audit writer; classification comes from the operation. */ export type AuditEntryInput = { operation: string; actorId: string; aggregate: { type: string; id: string; }; metadata?: Record; classification: string; }; export type AuditWriter = (context: never, entry: AuditEntryInput) => MaybePromise; type MaybePromise = Value | Promise; type OperationKey = Extract; export type AuditedOperation = Readonly<{ command: CommandSchema; result: CommandSchema; classification: string; /** * Permission slug required to execute this operation. Checked through the * Foundation's injected checkPermission BEFORE guards and the handler; * declaring a permission without injecting a checker fails closed. */ permission?: string; prepare?: (context: never, command: never) => MaybePromise>; replayResult?: CommandSchema; /** * Per-operation precondition, after the permission check and the registry * default guard, before the handler. Throw to deny — nothing has run yet. */ guard?: (context: never, command: never) => MaybePromise; /** * Allowlist of aggregate types this operation's audit may reference. When * declared, an audit entry whose aggregate.type is not listed throws — * the audit vocabulary is enforced, not advisory. */ aggregates?: readonly string[]; /** Per-operation middleware, inside the registry-wide chain. */ middleware?: readonly AnyCommandMiddleware[]; audit: (resolution: Readonly<{ command: never; result: never; }>, context: never) => MaybePromise | null>; }>; /** * Composable, next()-based middleware wrapping [guards → handler]. Runs * INSIDE the pipeline's invariants: after the permission check, before the * result-schema parse, aggregate allowlist, and audit — so middleware can * time, trace, enrich context (`next({ context })`), short-circuit, or * transform results, but can never skip authorization, return an invalid * result, or desynchronize audit from effects. */ export type CommandMiddleware = (input: { operation: string; command: Input; context: Context; next: (options?: { /** Merged into the context handed to inner middleware, guards, handler. */ context?: Extension; }) => Promise; }) => Promise; /** Any-context middleware — what registries and operations accept. */ export type AnyCommandMiddleware = (input: { operation: string; definition?: AuditedOperation; command: Input; context: never; next: (options?: { context?: object; }) => Promise; }) => Promise; /** Registry-wide defaults applied to every operation of one Command. */ export type CommandDefaults = Readonly<{ /** Runs before every operation's own guard. Throw to deny. */ guard?: (context: never) => MaybePromise; /** Outermost middleware, in array order, around every operation. */ middleware?: readonly AnyCommandMiddleware[]; }>; /** Injected permission policy: throw to deny. Host semantics, kit ordering. */ export type PermissionChecker = (context: never, input: Readonly<{ permission: string; operation: string; }>) => MaybePromise; export type AuditedRegistry = Readonly>; export type FoundationOptions = Readonly<{ observability: ObservabilityOptions & Readonly<{ /** * In-transaction audit writer used by Command. Operations that * return an audit record get it written here automatically. */ writeAudit?: AuditWriter; }>; /** * Permission policy for operations that declare a `permission`. Runs * before guards and the handler; throw to deny. An operation with a * permission but no injected checker fails closed. */ checkPermission?: PermissionChecker; }>; type FoundationComponentApi = Readonly<{ functions: Readonly<{ status: unknown; }>; }>; /** * Application command protocol bound to a Foundation instance: * validate, observe, execute, and audit. `classification` and `audit()` * are mandatory per operation — auditing is type-enforced, not opt-in. * Obtain it by destructuring the Foundation: `const { Command } = new Foundation(...)`. */ declare class BoundCommand { #private; static withContext: typeof operationFactory; /** Declared aggregate types per operation — introspectable for tests. */ readonly aggregates: Readonly<{ [Key in OperationKey]: Operations[Key]['aggregates']; }>; static operation(definition: Definition): Definition; /** * Identity helper that types a middleware against its context and the * context extension it passes downstream via next({ context }). */ static middleware(middleware: CommandMiddleware): CommandMiddleware; constructor(operations: Operations, deps: { observability: Observability; writeAudit: AuditWriter; checkPermission?: PermissionChecker; defaults?: CommandDefaults; }); /** * @deprecated Declare handlers inside command({...}) using createEffectFoundation * from cvx-kit/effect, then call exec(operation, input, host). */ exec>(executor: { operation: Key; handler: (context: Context & OperationExtension, command: CommandInput) => MaybePromise>; }): (context: Context, command: SchemaInput) => Promise>; } /** @deprecated Use the registry returned by createEffectFoundation(...).Command from cvx-kit/effect. */ export type ApplicationCommand = BoundCommand; /** * The constructor shape a Foundation instance exposes as `Command`. * Exported as a TYPE ONLY so factories (e.g. cvx-kit/crud) can accept the * destructured facade class as input without importing any runtime kernel. * @deprecated Use createEffectFoundation from cvx-kit/effect and declare handlers inside command({...}). */ export type CommandConstructor = { /** @deprecated Use createEffectFoundation(...).Command({ context, operations }) from cvx-kit/effect. */ new (operations: Operations & { readonly [Key in keyof Operations]: OperationHostContext; }, defaults?: CommandDefaults): BoundCommand; operation: (typeof BoundCommand)['operation']; withContext: (typeof BoundCommand)['withContext']; middleware: (typeof BoundCommand)['middleware']; }; /** * Host facade for a component that owns no application execution capability. * Declared once; the sole source of the command protocol, query kernel, and * observability: `const { Command, Query, observability } = new Foundation(...)`. */ export declare class Foundation { readonly status: Component['functions']['status']; /** @deprecated Use createEffectFoundation(...).Command from cvx-kit/effect. */ readonly Command: CommandConstructor; readonly Query: typeof Query; readonly observability: Observability; /** Typed-failure boundary — see result.ts. Facade-bound like the kernels. */ readonly executeResultBoundary: typeof executeResultBoundary; readonly projectResult: typeof projectResult; readonly emitSemanticEvent: typeof emitSemanticEvent; constructor(component: Component, options: FoundationOptions); } //#endregion export { type AnyQueryMiddleware, type CommandArgument, type CommandExecution, type CommandHandlerResult, type CommandInput, type CommandObservation, type CommandPreparation, type CommandRegistry, type CommandResult, type ObservabilityOptions, type Parseable, type QueryExecution, type QueryMiddleware, type Result, type ResultBoundary, type SchemaOutput, type TransactionMetricsContext, type TypedOperation, client_d_exports }; //# sourceMappingURL=client.d.mts.map