@scayle/storefront-nuxt
Version:
Nuxt integration for the SCAYLE Commerce Engine and Storefront API
12 lines (11 loc) • 970 B
TypeScript
import type { RpcMethods, RpcMethodName, RpcHandler } from '@scayle/storefront-core';
/**
* Normalizes a rpc handler function that is not defined with `defineRpcHandler`.
* Sets the `rpcType` property to `WithParam` or `NoParam` based on the number of parameters
* the handler function takes, and defaults `httpMethod` to `'POST'` when it is missing.
* Handlers that already have both properties set are returned without modification.
*
* @param handler - The handler function to normalize.
* @returns The normalized handler function with `rpcType` and `httpMethod` properties.
*/
export declare const normalizeRpcHandler: <T extends RpcMethods[RpcMethodName], NormalizedHandler = T extends RpcHandler<infer R> ? RpcHandler<R> & Required<Pick<RpcHandler<R>, "rpcType" | "httpMethod">> : T extends RpcHandler<infer _P, infer R> ? RpcHandler<unknown, R> & Required<Pick<RpcHandler<unknown, R>, "rpcType" | "httpMethod">> : never>(handler: T) => NormalizedHandler;