remix-conform-rpc
Version:
Supercharge your remix/react-router actions and loaders with typesafe param and query parsing using conform and zod
20 lines (19 loc) • 1.64 kB
TypeScript
import { z, ZodSchema } from "zod";
import type { SuccessfulSubmission } from "../utils/submission.js";
import type { WithParams } from "../utils/with-params.js";
import type { ActionFunctionArgs, AppLoadContext } from "react-router";
type ActionArguments<TSchema extends ZodSchema, TParamSchema extends ZodSchema | undefined, TQuerySchema extends ZodSchema | undefined> = WithParams<TParamSchema, TQuerySchema, {
submission: SuccessfulSubmission<z.infer<TSchema>>;
request: ActionFunctionArgs["request"];
context: AppLoadContext;
}>;
interface SetupActionsArgs<TSchema extends ZodSchema, TParamSchema extends ZodSchema | undefined, TQuerySchema extends ZodSchema | undefined, TResult, TMiddlewareResult> {
actionArgs: ActionFunctionArgs;
paramSchema?: TParamSchema;
querySchema?: TQuerySchema;
schema: TSchema;
mutation: (args: ActionArguments<TSchema, TParamSchema, TQuerySchema> & (TMiddlewareResult extends undefined ? {} : TMiddlewareResult)) => Promise<TResult>;
middleware?: (args: ActionArguments<TSchema, TParamSchema, TQuerySchema>) => Promise<TMiddlewareResult>;
}
declare function setupAction<TSchema extends ZodSchema, TParamSchema extends ZodSchema | undefined, TQuerySchema extends ZodSchema | undefined, TResult, TMiddlewareResult>({ actionArgs, schema, mutation, querySchema, paramSchema, middleware }: SetupActionsArgs<TSchema, TParamSchema, TQuerySchema, TResult, TMiddlewareResult>): Promise<import("../utils/error.js").InvalidSubmissionResponse<import("@conform-to/dom").SubmissionResult<string[]>> | import("../utils/error.js").ErrorResponse<null> | TResult>;
export { setupAction };