UNPKG

@scayle/storefront-core

Version:

Collection of essential utilities to work with the Storefront API

45 lines (44 loc) 1.99 kB
import type { RpcMethods, RpcMethodName } from '..'; import type { RpcContext, RpcHandler, RpcHttpMethod, RpcType } from '../types'; /** * Options accepted by {@link defineRpcHandler}. */ export interface DefineRpcHandlerOptions { /** * HTTP method the RPC endpoint will be exposed under. * Defaults to `'POST'`. Use `'GET'` for read-only, cacheable endpoints; * `'PUT'` / `'DELETE'` for RESTful update/delete semantics. */ method?: RpcHttpMethod; } /** * Default HTTP method for RPC handlers when not explicitly specified. */ export declare const DEFAULT_RPC_HTTP_METHOD: RpcHttpMethod; /** * Defines an RPC method handler. * * @param handler - The RPC handler function. * @param options - Optional handler options (e.g. HTTP method). * @returns The handler itself, with correct types enforced and internal properties set. */ export declare function defineRpcHandler<Params extends Record<string, any> | undefined, Result>(handler: (params: Params, context: RpcContext) => Result | Response | Promise<Result | Response>, options?: DefineRpcHandlerOptions): RpcHandler<Params, Result>; /** * Defines an RPC method handler. * * @param handler - The RPC handler function. * @param options - Optional handler options (e.g. HTTP method). * @returns The handler itself, with correct types enforced and internal properties set. */ export declare function defineRpcHandler<Result>(handler: (context: RpcContext) => Result | Response | Promise<Result | Response>, options?: DefineRpcHandlerOptions): RpcHandler<Result>; /** * Defines an RPC method handler. * * @param handler The RPC handler function. * @param options Optional handler options (e.g. HTTP method). * @returns The handler itself, with correct types enforced and internal properties set. */ export declare function defineRpcHandler<T extends RpcMethods[RpcMethodName]>(handler: T, options?: DefineRpcHandlerOptions): T & { rpcType: RpcType; httpMethod: RpcHttpMethod; };