@kellanjs/actioncraft
Version:
Fluent, type-safe builder for Next.js server actions.
30 lines (29 loc) • 1.67 kB
TypeScript
import { Crafter } from "./classes/crafter.js";
import type { CraftedAction } from "./types/actions.js";
import type { CrafterConfig, CrafterSchemas, CrafterErrors, CrafterCallbacks } from "./types/crafter.js";
/**
* Represents the function that the user passes to `craft()` in order to build an action.
*/
type CraftFn<TConfig extends CrafterConfig, TSchemas extends CrafterSchemas, TErrors extends CrafterErrors, TCallbacks extends CrafterCallbacks<TConfig, TSchemas, TErrors, TData>, TData> = (crafter: Crafter<CrafterConfig, Record<string, never>, Record<string, never>, Record<string, never>, unknown>) => Crafter<TConfig, TSchemas, TErrors, TCallbacks, TData> | Promise<Crafter<TConfig, TSchemas, TErrors, TCallbacks, TData>>;
/**
* One of two entry points to the Actioncraft system.
* It provides you with an empty Crafter instance on which you can call any of the fluent
* Crafter methods to configure and define your action.
*
* Example Usage:
* ```ts
* const myAction = craft(async (action) => {
* return action
* .config(...)
* .schemas(...)
* .errors(...)
* .handler(...)
* .callbacks(...)
* });
* ```
*
* @param craftFn - The function that the user passes to `craft()` in order to build an action.
* @returns The fully-typed server action function that can be used in your app.
*/
export declare function craft<TConfig extends CrafterConfig, TSchemas extends CrafterSchemas, TErrors extends CrafterErrors, TCallbacks extends CrafterCallbacks<TConfig, TSchemas, TErrors, TData>, TData>(craftFn: CraftFn<TConfig, TSchemas, TErrors, TCallbacks, TData>): CraftedAction<TConfig, TSchemas, TErrors, TData>;
export {};