withMeta / getServerFunctionMetadata / isServerFunction
Attaches declaration metadata to a server-function reference and returns the reference.
Import
import { withMeta, getServerFunctionMetadata, isServerFunction,} from "@solidjs/web/server-functions";withMeta
Type signature
function withMeta<F extends (...args: any[]) => any>( fn: F, meta: ServerFunctionMetadata): F;Parameters
fn
- Type:
any
meta
- Type:
any
Examples
export const charge = withMeta( async (amount: number) => { "use server"; return payments.charge(amount); }, { requiresAuth: true });getServerFunctionMetadata
Returns the declaration metadata attached to a server-function reference.
Type signature
function getServerFunctionMetadata( fn: unknown): ServerFunctionMetadata | undefined;Parameters
fn
- Type:
any
isServerFunction
Returns whether a value is a server-function reference.
Type signature
function isServerFunction(fn: unknown): fn is ServerFunction;Parameters
fn
- Type:
any
Learn more
Related types
ServerFunction
The public contract of a server function reference — what a "use server" import is at runtime on either side: an async callable plus its
build-stable identity.
interface ServerFunction<A extends readonly any[] = any[], T = any> { (...args: A): Promise<T>; readonly id: string; readonly url: string;}id
- Type:
string
The build-stable function id (stable across the client and server builds).
url
- Type:
string
The plain-HTTP address of this function — what a <form action> posts
to without the runtime (the integration behind action={fn} reads it).
Not where the reference's own call goes: that is serverFunctionUrl(fn, ...args), for a GET() reference — the url to preload or fetch.
ServerFunctionMetadata
Declaration-static metadata attached to a server function reference
through declaration wrappers (GET, withMeta). Read it with
getServerFunctionMetadata; routers and integrations detect capability
from here instead of property sniffing, and prepareRequest receives it
as context.meta. Write through withMeta — later writes shallow-merge
over earlier ones.
interface ServerFunctionMetadata { readonly method?: "GET" | "POST"; readonly name?: string; readonly fetch?: ( address: string, init: RequestInit, next: (address: string, init: RequestInit) => Response | Promise<Response> ) => Response | Promise<Response>; readonly [key: string]: unknown;}method
- Type:
"GET" | "POST"
The declared HTTP method. Undeclared references call over POST.
name
- Type:
string
A human-readable label for the function, seeded by development builds
from the compiled function's source name (dev tooling — inspectors,
logs). Dev-only: production builds emit no name. Not unique and not an
identity key — use id for identity. Seeded as a default: an explicit
withMeta write wins.
fetch
- Type:
( address: string, init: RequestInit, next: (address: string, init: RequestInit) => Response | Promise<Response> ) => Response | Promise<Response>
This function's own send, client side: the transport calls it instead
of the configured fetch for every request the function makes, with
the configured send (the app's fetch, or the global) as next. For
an integration that answers a declared function's calls itself — a
prerendered build's static artifacts, a cache — while the app's
transport fetch stays the app's: pass on what you don't answer
through next. The contract is fetch's (see
ServerFunctionsClientConfig.fetch); hydration adopts a
server-rendered read only if the send reaches the global fetch in the
same tick.
withMeta(getPosts, { fetch: (address, init, next) => cached(address) ?? next(address, init),});