Skip to content
oRPC
Esc
navigateopen⌘Jpreview
On this page

Metadata

Attach metadata to oRPC procedures with defineMeta or a custom MetaPlugin so middleware, plugins, and tooling can read it to control behavior.

Quickly Define Meta

In most cases, use defineMeta to create a metadata plugin. It takes a unique name and a merge function that defines how metadata is combined across repeated calls, then returns a tuple of [metaPlugin, getMeta]:

import { 
function defineMeta<TName extends string, TData>(name: TName, merge: (incoming: TData, current: TData | undefined) => TData): [metaPlugin: (meta: TData) => AnyMetaPlugin & {
    name: TName;
}, getMeta: (procedureOrLazy: {
    "~orpc": {
        meta: Meta;
    };
}) => TData | undefined]
Quickly defines a meta plugin factory and reader.
@exampleMark a procedure as requiring authentication and read it in middleware. ```ts interface AuthMeta { required?: boolean scope?: 'user' | 'admin' } const [authMeta, getAuthMeta] = defineMeta( 'auth', (incoming: AuthMeta, current) => ({ ...current, ...incoming }), ) const deletePostContract = oc .meta(authMeta({ required: true, scope: 'admin' })) .input(z.object({ postId: z.string() })) .output(z.object({ success: z.boolean() })) const authMiddleware = os.middleware(async ({ context, procedure, next }) => { const auth = getAuthMeta(procedure) if (auth?.required && !context.user) { throw new ORPCError('UNAUTHORIZED') } if (auth?.scope === 'admin' && !context.user?.isAdmin) { throw new ORPCError('FORBIDDEN') } return next() }) ```@paramname - Unique key for storing this meta entry.@parammerge - Merges the existing value (or `undefined`) with the incoming value when applied multiple times.@returnsA `[metaPlugin, getMeta]` tuple: - `metaPlugin(metadata)` - Attaches metadata to a procedure under `name`. - `getMeta(procedureOrLazy)` - Retrieves the metadata, or `undefined` if not set.@see{@link https://orpc.dev/docs/metadata Metadata}
defineMeta
} from '@orpc/server'
type type CacheMeta = booleanCacheMeta = boolean const [
const cacheMeta: (meta: boolean) => AnyMetaPlugin & {
    name: "cache";
}
cacheMeta
,
const getCacheMeta: (procedureOrLazy: {
    "~orpc": {
        meta: Meta;
    };
}) => boolean | undefined
getCacheMeta
] =
defineMeta<"cache", boolean>(name: "cache", merge: (incoming: boolean, current: boolean | undefined) => boolean): [metaPlugin: (meta: boolean) => AnyMetaPlugin & {
    name: "cache";
}, getMeta: (procedureOrLazy: {
    "~orpc": {
        meta: Meta;
    };
}) => boolean | undefined]
Quickly defines a meta plugin factory and reader.
@exampleMark a procedure as requiring authentication and read it in middleware. ```ts interface AuthMeta { required?: boolean scope?: 'user' | 'admin' } const [authMeta, getAuthMeta] = defineMeta( 'auth', (incoming: AuthMeta, current) => ({ ...current, ...incoming }), ) const deletePostContract = oc .meta(authMeta({ required: true, scope: 'admin' })) .input(z.object({ postId: z.string() })) .output(z.object({ success: z.boolean() })) const authMiddleware = os.middleware(async ({ context, procedure, next }) => { const auth = getAuthMeta(procedure) if (auth?.required && !context.user) { throw new ORPCError('UNAUTHORIZED') } if (auth?.scope === 'admin' && !context.user?.isAdmin) { throw new ORPCError('FORBIDDEN') } return next() }) ```@paramname - Unique key for storing this meta entry.@parammerge - Merges the existing value (or `undefined`) with the incoming value when applied multiple times.@returnsA `[metaPlugin, getMeta]` tuple: - `metaPlugin(metadata)` - Attaches metadata to a procedure under `name`. - `getMeta(procedureOrLazy)` - Retrieves the metadata, or `undefined` if not set.@see{@link https://orpc.dev/docs/metadata Metadata}
defineMeta
(
'cache', (incoming: booleanincoming: type CacheMeta = booleanCacheMeta, current: boolean | undefinedcurrent) => incoming: booleanincoming, ) const const base: BuilderWithMiddlewares<DefaultInitialContext & object, object, Record<never, never>>base = const os: Builder<DefaultInitialContext & object, Record<never, never>>
The oRPC procedure builder. Chain methods like `.input`, `.use`, and `.handler` to define procedures, then compose them into routers.
@see{@link https://orpc.dev/docs/procedure Procedure}
os
.Builder<DefaultInitialContext & object, Record<never, never>>.use<object, DefaultInitialContext & object, Record<never, never>>(middleware: Middleware<DefaultInitialContext & object, object, unknown, unknown, Record<never, never>>): BuilderWithMiddlewares<DefaultInitialContext & object, object, Record<never, never>>
Applies a middleware that runs before the handler of every procedure built from this builder.
@see{@link https://orpc.dev/docs/middleware Middleware}
use
(async ({ procedure: AnyProcedureprocedure, next: MiddlewareNext<unknown>
Invoke to continue the middleware chain.
next
, path: string[]path }, input: unknowninput, done: MiddlewareDone<unknown>done) => {
if (
const getCacheMeta: (procedureOrLazy: {
    "~orpc": {
        meta: Meta;
    };
}) => boolean | undefined
getCacheMeta
(procedure: AnyProcedureprocedure) !== true) {
return
next: MiddlewareNext
<object>(options?: {
    context?: object | undefined;
} | undefined) => MiddlewareResult<object, unknown>
Invoke to continue the middleware chain.
next
()
} const const key: stringkey = path: string[]path.Array<string>.join(separator?: string): string
Adds all the elements of an array into a string, separated by the specified separator string.
@paramseparator A string used to separate one element of the array from the next in the resulting string. If omitted, the array elements are separated with a comma.
join
('/') + var JSON: JSON
An intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format.
JSON
.JSON.stringify(value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string (+1 overload)
Converts a JavaScript value to a JavaScript Object Notation (JSON) string.
@paramvalue A JavaScript value, usually an object or array, to be converted.@paramreplacer A function that transforms the results.@paramspace Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.@throws{TypeError} If a circular reference or a BigInt value is found.
stringify
(input: unknowninput)
if (const store: Map<string, unknown>store.Map<string, unknown>.has(key: string): boolean
@returnsboolean indicating whether an element with the specified key exists or not.
has
(const key: stringkey)) {
return
done: MiddlewareDone
<object>(options: MiddlewareDoneOptions<object, unknown>) => MiddlewareResult<object, unknown>
Create a successful result and terminate the middleware chain early.
done
({ output: unknownoutput: const store: Map<string, unknown>store.Map<string, unknown>.get(key: string): unknown
Returns a specified element from the Map object. If the value that is associated to the provided key is an object, then you will get a reference to that object and any change made to that object will effectively modify it inside the Map.
@returnsReturns the element associated with the specified key. If no element is associated with the specified key, undefined is returned.
get
(const key: stringkey)! })
} const
const result: {
    output: unknown;
    context: object;
}
result
= await
next: MiddlewareNext
<object>(options?: {
    context?: object | undefined;
} | undefined) => MiddlewareResult<object, unknown>
Invoke to continue the middleware chain.
next
()
const store: Map<string, unknown>store.Map<string, unknown>.set(key: string, value: unknown): Map<string, unknown>
Adds a new element with a specified key and value to the Map. If an element with the same key already exists, the element will be updated.
set
(const key: stringkey,
const result: {
    output: unknown;
    context: object;
}
result
.output: unknownoutput)
return
const result: {
    output: unknown;
    context: object;
}
result
}) const const cachedProcedure: DecoratedProcedure<DefaultInitialContext & object, object, InitialInputSchema, Schema<string>, Record<never, never>, never>cachedProcedure = const base: BuilderWithMiddlewares<DefaultInitialContext & object, object, Record<never, never>>base .BuilderWithMiddlewares<DefaultInitialContext & object, object, Record<never, never>>['meta'](...plugins: MetaPlugin<InitialInputSchema, InitialOutputSchema, Record<never, never>>[]): BuilderWithMiddlewares<DefaultInitialContext & object, object, Record<never, never>>
Applies metadata plugins to procedures built from this builder.
@see{@link https://orpc.dev/docs/metadata Metadata}
meta
(
const cacheMeta: (meta: boolean) => AnyMetaPlugin & {
    name: "cache";
}
cacheMeta
(true))
.BuilderWithMiddlewares<DefaultInitialContext & object, object, Record<never, never>>['handler']<string>(handler: ProcedureHandler<DefaultInitialContext & object, unknown, string, ORPCErrorConstructorMap<Record<never, never>>>): DecoratedProcedure<DefaultInitialContext & object, object, InitialInputSchema, Schema<string>, Record<never, never>, never>
Defines the function that implements the procedure and completes the chain, returning a callable procedure.
@see{@link https://orpc.dev/docs/procedure Procedure}
handler
(async () => {
return 'Earth' })

Manually Define Meta

If defineMeta is not flexible enough, define a plugin directly with MetaPlugin<TInputSchema, TOutputSchema, TErrorMap>. This gives you full control and lets the plugin infer or restrict procedure types.

import type {
  type AnySchema = StandardSchemaV1<any, any>
Any Standard Schema compatible schema, regardless of its input and output types.
@see{@link https://orpc.dev/docs/integrations/standard-schema Standard Schema Integration}
AnySchema
,
type ErrorMap = {
    [x: string & {}]: ErrorMapItem | undefined;
    BAD_REQUEST?: ErrorMapItem | undefined;
    UNAUTHORIZED?: ErrorMapItem | undefined;
    PAYMENT_REQUIRED?: ErrorMapItem | undefined;
    FORBIDDEN?: ErrorMapItem | undefined;
    NOT_FOUND?: ErrorMapItem | undefined;
    METHOD_NOT_SUPPORTED?: ErrorMapItem | undefined;
    NOT_ACCEPTABLE?: ErrorMapItem | undefined;
    TIMEOUT?: ErrorMapItem | undefined;
    CONFLICT?: ErrorMapItem | undefined;
    ... 12 more ...;
    GATEWAY_TIMEOUT?: ErrorMapItem | undefined;
}
Map of error codes to their definitions, as passed to `.errors(...)`. Errors defined here remain properly typed on the client.
@see{@link https://orpc.dev/docs/metadata Metadata}
ErrorMap
,
type InferSchemaInput<T extends AnySchema> = T extends StandardSchemaV1<infer UInput, any> ? UInput : never
Infers the input type of a schema.
@see{@link https://orpc.dev/docs/metadata Metadata}
InferSchemaInput
,
type InferSchemaOutput<T extends AnySchema> = T extends StandardSchemaV1<any, infer UOutput> ? UOutput : never
Infers the output type of a schema.
@see{@link https://orpc.dev/docs/metadata Metadata}
InferSchemaOutput
,
Meta, interface MetaPlugin<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>
A metadata plugin passed to `.meta(...)`. Defines how metadata is initialized and merged, and can infer or restrict procedure types.
@see{@link https://orpc.dev/docs/metadata Metadata}
MetaPlugin
,
} from '@orpc/server' interface interface ExampleMeta<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>ExampleMeta< function (type parameter) TInputSchema in ExampleMeta<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>TInputSchema extends type AnySchema = StandardSchemaV1<any, any>
Any Standard Schema compatible schema, regardless of its input and output types.
@see{@link https://orpc.dev/docs/integrations/standard-schema Standard Schema Integration}
AnySchema
,
function (type parameter) TOutputSchema in ExampleMeta<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>TOutputSchema extends type AnySchema = StandardSchemaV1<any, any>
Any Standard Schema compatible schema, regardless of its input and output types.
@see{@link https://orpc.dev/docs/integrations/standard-schema Standard Schema Integration}
AnySchema
,
function (type parameter) TErrorMap in ExampleMeta<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>TErrorMap extends
type ErrorMap = {
    [x: string & {}]: ErrorMapItem | undefined;
    BAD_REQUEST?: ErrorMapItem | undefined;
    UNAUTHORIZED?: ErrorMapItem | undefined;
    PAYMENT_REQUIRED?: ErrorMapItem | undefined;
    FORBIDDEN?: ErrorMapItem | undefined;
    NOT_FOUND?: ErrorMapItem | undefined;
    METHOD_NOT_SUPPORTED?: ErrorMapItem | undefined;
    NOT_ACCEPTABLE?: ErrorMapItem | undefined;
    TIMEOUT?: ErrorMapItem | undefined;
    CONFLICT?: ErrorMapItem | undefined;
    ... 12 more ...;
    GATEWAY_TIMEOUT?: ErrorMapItem | undefined;
}
Map of error codes to their definitions, as passed to `.errors(...)`. Errors defined here remain properly typed on the client.
@see{@link https://orpc.dev/docs/metadata Metadata}
ErrorMap
> { ExampleMeta<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>.inputExamples?: InferSchemaInput<TInputSchema>[] | undefinedinputExamples?: type InferSchemaInput<T extends AnySchema> = T extends StandardSchemaV1<infer UInput, any> ? UInput : never
Infers the input type of a schema.
@see{@link https://orpc.dev/docs/metadata Metadata}
InferSchemaInput
<function (type parameter) TInputSchema in ExampleMeta<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>TInputSchema>[]
ExampleMeta<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>.outputExamples?: InferSchemaOutput<TOutputSchema>[] | undefinedoutputExamples?: type InferSchemaOutput<T extends AnySchema> = T extends StandardSchemaV1<any, infer UOutput> ? UOutput : never
Infers the output type of a schema.
@see{@link https://orpc.dev/docs/metadata Metadata}
InferSchemaOutput
<function (type parameter) TOutputSchema in ExampleMeta<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>TOutputSchema>[]
} interface interface ExampleMetaPlugin<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>ExampleMetaPlugin< function (type parameter) TInputSchema in ExampleMetaPlugin<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>TInputSchema extends type AnySchema = StandardSchemaV1<any, any>
Any Standard Schema compatible schema, regardless of its input and output types.
@see{@link https://orpc.dev/docs/integrations/standard-schema Standard Schema Integration}
AnySchema
,
function (type parameter) TOutputSchema in ExampleMetaPlugin<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>TOutputSchema extends type AnySchema = StandardSchemaV1<any, any>
Any Standard Schema compatible schema, regardless of its input and output types.
@see{@link https://orpc.dev/docs/integrations/standard-schema Standard Schema Integration}
AnySchema
,
function (type parameter) TErrorMap in ExampleMetaPlugin<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>TErrorMap extends
type ErrorMap = {
    [x: string & {}]: ErrorMapItem | undefined;
    BAD_REQUEST?: ErrorMapItem | undefined;
    UNAUTHORIZED?: ErrorMapItem | undefined;
    PAYMENT_REQUIRED?: ErrorMapItem | undefined;
    FORBIDDEN?: ErrorMapItem | undefined;
    NOT_FOUND?: ErrorMapItem | undefined;
    METHOD_NOT_SUPPORTED?: ErrorMapItem | undefined;
    NOT_ACCEPTABLE?: ErrorMapItem | undefined;
    TIMEOUT?: ErrorMapItem | undefined;
    CONFLICT?: ErrorMapItem | undefined;
    ... 12 more ...;
    GATEWAY_TIMEOUT?: ErrorMapItem | undefined;
}
Map of error codes to their definitions, as passed to `.errors(...)`. Errors defined here remain properly typed on the client.
@see{@link https://orpc.dev/docs/metadata Metadata}
ErrorMap
> extends interface MetaPlugin<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>
A metadata plugin passed to `.meta(...)`. Defines how metadata is initialized and merged, and can infer or restrict procedure types.
@see{@link https://orpc.dev/docs/metadata Metadata}
MetaPlugin
<function (type parameter) TInputSchema in ExampleMetaPlugin<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>TInputSchema, function (type parameter) TOutputSchema in ExampleMetaPlugin<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>TOutputSchema, function (type parameter) TErrorMap in ExampleMetaPlugin<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>TErrorMap> {
ExampleMetaPlugin<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>.name: "example"
Unique name of the plugin, used for identification.
name
: 'example'
} function function exampleMeta<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>(incoming: ExampleMeta<TInputSchema, TOutputSchema, TErrorMap>): ExampleMetaPlugin<TInputSchema, TOutputSchema, TErrorMap>exampleMeta< function (type parameter) TInputSchema in exampleMeta<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>(incoming: ExampleMeta<TInputSchema, TOutputSchema, TErrorMap>): ExampleMetaPlugin<TInputSchema, TOutputSchema, TErrorMap>TInputSchema extends type AnySchema = StandardSchemaV1<any, any>
Any Standard Schema compatible schema, regardless of its input and output types.
@see{@link https://orpc.dev/docs/integrations/standard-schema Standard Schema Integration}
AnySchema
,
function (type parameter) TOutputSchema in exampleMeta<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>(incoming: ExampleMeta<TInputSchema, TOutputSchema, TErrorMap>): ExampleMetaPlugin<TInputSchema, TOutputSchema, TErrorMap>TOutputSchema extends type AnySchema = StandardSchemaV1<any, any>
Any Standard Schema compatible schema, regardless of its input and output types.
@see{@link https://orpc.dev/docs/integrations/standard-schema Standard Schema Integration}
AnySchema
,
function (type parameter) TErrorMap in exampleMeta<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>(incoming: ExampleMeta<TInputSchema, TOutputSchema, TErrorMap>): ExampleMetaPlugin<TInputSchema, TOutputSchema, TErrorMap>TErrorMap extends
type ErrorMap = {
    [x: string & {}]: ErrorMapItem | undefined;
    BAD_REQUEST?: ErrorMapItem | undefined;
    UNAUTHORIZED?: ErrorMapItem | undefined;
    PAYMENT_REQUIRED?: ErrorMapItem | undefined;
    FORBIDDEN?: ErrorMapItem | undefined;
    NOT_FOUND?: ErrorMapItem | undefined;
    METHOD_NOT_SUPPORTED?: ErrorMapItem | undefined;
    NOT_ACCEPTABLE?: ErrorMapItem | undefined;
    TIMEOUT?: ErrorMapItem | undefined;
    CONFLICT?: ErrorMapItem | undefined;
    ... 12 more ...;
    GATEWAY_TIMEOUT?: ErrorMapItem | undefined;
}
Map of error codes to their definitions, as passed to `.errors(...)`. Errors defined here remain properly typed on the client.
@see{@link https://orpc.dev/docs/metadata Metadata}
ErrorMap
,
>( incoming: ExampleMeta<TInputSchema, TOutputSchema, TErrorMap>incoming: interface ExampleMeta<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>ExampleMeta<function (type parameter) TInputSchema in exampleMeta<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>(incoming: ExampleMeta<TInputSchema, TOutputSchema, TErrorMap>): ExampleMetaPlugin<TInputSchema, TOutputSchema, TErrorMap>TInputSchema, function (type parameter) TOutputSchema in exampleMeta<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>(incoming: ExampleMeta<TInputSchema, TOutputSchema, TErrorMap>): ExampleMetaPlugin<TInputSchema, TOutputSchema, TErrorMap>TOutputSchema, function (type parameter) TErrorMap in exampleMeta<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>(incoming: ExampleMeta<TInputSchema, TOutputSchema, TErrorMap>): ExampleMetaPlugin<TInputSchema, TOutputSchema, TErrorMap>TErrorMap> ): interface ExampleMetaPlugin<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>ExampleMetaPlugin<function (type parameter) TInputSchema in exampleMeta<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>(incoming: ExampleMeta<TInputSchema, TOutputSchema, TErrorMap>): ExampleMetaPlugin<TInputSchema, TOutputSchema, TErrorMap>TInputSchema, function (type parameter) TOutputSchema in exampleMeta<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>(incoming: ExampleMeta<TInputSchema, TOutputSchema, TErrorMap>): ExampleMetaPlugin<TInputSchema, TOutputSchema, TErrorMap>TOutputSchema, function (type parameter) TErrorMap in exampleMeta<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>(incoming: ExampleMeta<TInputSchema, TOutputSchema, TErrorMap>): ExampleMetaPlugin<TInputSchema, TOutputSchema, TErrorMap>TErrorMap> { return { ExampleMetaPlugin<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>.name: "example"
Unique name of the plugin, used for identification.
name
: 'example',
MetaPlugin<TInputSchema, TOutputSchema, TErrorMap>['apply']?: ((meta: Meta) => Meta) | undefined
Runs every time metadata is updated. This is called for all plugins in the chain whenever a new plugin is added.
apply
(meta: Metameta) {
const const current: ExampleMeta<TInputSchema, TOutputSchema, TErrorMap> | undefinedcurrent = meta: Metameta.Meta[string | number | symbol]: unknownexample as interface ExampleMeta<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>ExampleMeta<function (type parameter) TInputSchema in exampleMeta<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>(incoming: ExampleMeta<TInputSchema, TOutputSchema, TErrorMap>): ExampleMetaPlugin<TInputSchema, TOutputSchema, TErrorMap>TInputSchema, function (type parameter) TOutputSchema in exampleMeta<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>(incoming: ExampleMeta<TInputSchema, TOutputSchema, TErrorMap>): ExampleMetaPlugin<TInputSchema, TOutputSchema, TErrorMap>TOutputSchema, function (type parameter) TErrorMap in exampleMeta<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>(incoming: ExampleMeta<TInputSchema, TOutputSchema, TErrorMap>): ExampleMetaPlugin<TInputSchema, TOutputSchema, TErrorMap>TErrorMap> | undefined return { ...meta: Metameta,
example: {
    inputExamples?: InferSchemaInput<TInputSchema>[] | undefined;
    outputExamples?: InferSchemaOutput<TOutputSchema>[] | undefined;
}
example
: {
...const current: ExampleMeta<TInputSchema, TOutputSchema, TErrorMap> | undefinedcurrent, ...incoming: ExampleMeta<TInputSchema, TOutputSchema, TErrorMap>incoming, } } }, } } function
function getExampleMeta(procedureOrLazy: {
    "~orpc": {
        meta: Meta;
    };
}): ExampleMeta<any, any, any> | undefined
getExampleMeta
(
procedureOrLazy: {
    '~orpc': {
        meta: Meta;
    };
}
procedureOrLazy
: { '~orpc': { meta: Metameta: Meta } }
): interface ExampleMeta<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>ExampleMeta<any, any, any> | undefined { return
procedureOrLazy: {
    '~orpc': {
        meta: Meta;
    };
}
procedureOrLazy
['~orpc'].meta: Metameta.Meta[string | number | symbol]: unknownexample as interface ExampleMeta<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>ExampleMeta<any, any, any> | undefined
} const
const procedure: DecoratedProcedure<DefaultInitialContext & object, object, z.ZodObject<{
    name: z.ZodString;
}, z.core.$strip>, z.ZodObject<{
    id: z.ZodString;
    name: z.ZodString;
}, z.core.$strip>, Record<never, never>, never>
procedure
= const os: Builder<DefaultInitialContext & object, Record<never, never>>
The oRPC procedure builder. Chain methods like `.input`, `.use`, and `.handler` to define procedures, then compose them into routers.
@see{@link https://orpc.dev/docs/procedure Procedure}
os
.
Builder<DefaultInitialContext & object, Record<never, never>>.input<z.ZodObject<{
    name: z.ZodString;
}, z.core.$strip>>(schema: z.ZodObject<{
    name: z.ZodString;
}, z.core.$strip>): BuilderWithInput<DefaultInitialContext & object, object, z.ZodObject<{
    name: z.ZodString;
}, z.core.$strip>, Record<never, never>>
Defines the input schema used to validate and type the procedure input.
@see{@link https://orpc.dev/docs/procedure#inputoutput-validation Procedure - Input/Output Validation}
input
(import zz.
function object<{
    name: z.ZodString;
}>(shape?: {
    name: z.ZodString;
} | undefined, params?: string | {
    error?: string | z.core.$ZodErrorMap<NonNullable<z.core.$ZodIssueInvalidType<unknown> | z.core.$ZodIssueUnrecognizedKeys>> | undefined;
    message?: string | undefined | undefined;
} | undefined): z.ZodObject<{
    name: z.ZodString;
}, z.core.$strip>
object
({ name: z.ZodStringname: import zz.function string(params?: string | z.core.$ZodStringParams): z.ZodString (+1 overload)string() }))
.
BuilderWithInput<DefaultInitialContext & object, object, ZodObject<{ name: ZodString; }, $strip>, Record<never, never>>['output']<z.ZodObject<{
    id: z.ZodString;
    name: z.ZodString;
}, z.core.$strip>>(schema: z.ZodObject<{
    id: z.ZodString;
    name: z.ZodString;
}, z.core.$strip>): BuilderWithInputOutput<DefaultInitialContext & object, object, z.ZodObject<{
    name: z.ZodString;
}, z.core.$strip>, z.ZodObject<{
    id: z.ZodString;
    name: z.ZodString;
}, z.core.$strip>, Record<never, never>>
Defines the output schema used to validate and type the procedure output.
@see{@link https://orpc.dev/docs/procedure#inputoutput-validation Procedure - Input/Output Validation}
output
(import zz.
function object<{
    id: z.ZodString;
    name: z.ZodString;
}>(shape?: {
    id: z.ZodString;
    name: z.ZodString;
} | undefined, params?: string | {
    error?: string | z.core.$ZodErrorMap<NonNullable<z.core.$ZodIssueInvalidType<unknown> | z.core.$ZodIssueUnrecognizedKeys>> | undefined;
    message?: string | undefined | undefined;
} | undefined): z.ZodObject<{
    id: z.ZodString;
    name: z.ZodString;
}, z.core.$strip>
object
({ id: z.ZodStringid: import zz.function string(params?: string | z.core.$ZodStringParams): z.ZodString (+1 overload)string(), name: z.ZodStringname: import zz.function string(params?: string | z.core.$ZodStringParams): z.ZodString (+1 overload)string() }))
.
BuilderWithInputOutput<DefaultInitialContext & object, object, ZodObject<{ name: ZodString; }, $strip>, ZodObject<{ id: ZodString; name: ZodString; }, $strip>, Record<...>>['meta'](...plugins: MetaPlugin<z.ZodObject<{
    name: z.ZodString;
}, z.core.$strip>, z.ZodObject<{
    id: z.ZodString;
    name: z.ZodString;
}, z.core.$strip>, Record<never, never>>[]): BuilderWithInputOutput<DefaultInitialContext & object, object, z.ZodObject<{
    name: z.ZodString;
}, z.core.$strip>, z.ZodObject<{
    id: z.ZodString;
    name: z.ZodString;
}, z.core.$strip>, Record<never, never>>
Applies metadata plugins to procedures built from this builder.
@see{@link https://orpc.dev/docs/metadata Metadata}
meta
(
function exampleMeta<z.ZodObject<{
    name: z.ZodString;
}, z.core.$strip>, z.ZodObject<{
    id: z.ZodString;
    name: z.ZodString;
}, z.core.$strip>, Record<never, never>>(incoming: ExampleMeta<z.ZodObject<{
    name: z.ZodString;
}, z.core.$strip>, z.ZodObject<{
    id: z.ZodString;
    name: z.ZodString;
}, z.core.$strip>, Record<never, never>>): ExampleMetaPlugin<z.ZodObject<{
    name: z.ZodString;
}, z.core.$strip>, z.ZodObject<{
    id: z.ZodString;
    name: z.ZodString;
}, z.core.$strip>, Record<never, never>>
exampleMeta
({
ExampleMeta<ZodObject<{ name: ZodString; }, $strip>, ZodObject<{ id: ZodString; name: ZodString; }, $strip>, Record<...>>.inputExamples?: {
    name: string;
}[] | undefined
inputExamples
: [{ name: stringname: 'Alice' }], // <- typesafe
ExampleMeta<ZodObject<{ name: ZodString; }, $strip>, ZodObject<{ id: ZodString; name: ZodString; }, $strip>, Record<...>>.outputExamples?: {
    id: string;
    name: string;
}[] | undefined
outputExamples
: [{ id: stringid: '1', name: stringname: 'Alice' }], // <- typesafe
})) .
BuilderWithInputOutput<DefaultInitialContext & object, object, ZodObject<{ name: ZodString; }, $strip>, ZodObject<{ id: ZodString; name: ZodString; }, $strip>, Record<...>>['handler']<{
    id: string;
    name: "Alice";
}>(handler: ProcedureHandler<DefaultInitialContext & object, {
    name: string;
}, {
    id: string;
    name: "Alice";
}, ORPCErrorConstructorMap<Record<never, never>>>): DecoratedProcedure<DefaultInitialContext & object, object, z.ZodObject<{
    name: z.ZodString;
}, z.core.$strip>, z.ZodObject<{
    id: z.ZodString;
    name: z.ZodString;
}, z.core.$strip>, Record<never, never>, never>
Defines the function that implements the procedure and completes the chain, returning a callable procedure.
@see{@link https://orpc.dev/docs/procedure Procedure}
handler
(async ({
input: {
    name: string;
}
input
}) => {
return { id: stringid: '1', name: "Alice"name: 'Alice' } })

Last updated on August 8, 2026

Was this page helpful?