Skip to content
Logic SDK
Esc
↑↓navigate↵open⌘Jpreview
On this page

Output

An output schema controls the value a caller receives.

An output schema checks a handler’s return value and controls which fields reach the caller.

handler
Returns the booking row
1
output
Keeps the selected fields
2
Caller
Receives the parsed result
The registry parses the handler's return value through output before it returns the result.
/** Get a booking. */
export const 
const get: Fn<"query", {
    bookingId: string;
}, {
    id: string;
}, true, {
    scope: {
        accountId: string;
    };
}, z.ZodObject<{
    bookingId: z.ZodUUID;
}, z.core.$strip>, undefined>
Get a booking.
get
=
const query: <z.ZodObject<{
    bookingId: z.ZodUUID;
}, z.core.$strip>, z.ZodObject<{
    id: z.ZodUUID;
}, z.core.$strip>, {
    id: string;
    accountId: string;
}, () => boolean, boolean, undefined>(def: Def<{
    scope: {
        accountId: string;
    };
}, "query", z.ZodObject<{
    bookingId: z.ZodUUID;
}, z.core.$strip>, z.ZodObject<{
    id: z.ZodUUID;
}, z.core.$strip>, {
    id: string;
    accountId: string;
}, () => boolean, boolean, undefined>) => Fn<"query", {
    bookingId: string;
}, {
    id: string;
}, true, {
    scope: {
        accountId: string;
    };
}, z.ZodObject<{
    bookingId: z.ZodUUID;
}, z.core.$strip>, undefined>
Reads data. Can run other queries. No writes, no events, no services.
query
({
input?: z.ZodObject<{
    bookingId: z.ZodUUID;
}, z.core.$strip> | undefined
What callers pass, validated on every call. Leave it out when the function takes nothing.
input
: import zz.
function object<{
    bookingId: z.ZodUUID;
}>(shape?: {
    bookingId: z.ZodUUID;
} | undefined, params?: string | {
    error?: string | z.core.$ZodErrorMap<NonNullable<z.core.$ZodIssueInvalidType<unknown> | z.core.$ZodIssueUnrecognizedKeys>> | undefined;
    message?: string | undefined | undefined;
} | undefined): z.ZodObject<{
    bookingId: z.ZodUUID;
}, z.core.$strip>
object
({ bookingId: z.ZodUUIDbookingId: import zz.function uuid(params?: string | z.core.$ZodUUIDParams): z.ZodUUIDuuid() }),
authorize?: ((() => boolean) & ((scope: {
    accountId: string;
}) => boolean)) | undefined
Who may call it, on every call. A type guard narrows `ctx.scope` in `handler`. Required to publish it through an adapter: callers outside your server are untrusted. Leave it out when only your own code runs it.
authorize
: const anyone: () => booleananyone,
output?: z.ZodObject<{
    id: z.ZodUUID;
}, z.core.$strip> | undefined
What callers get back, checked before it leaves: unknown fields are stripped, and a published function's client types come from it. Without it, the handler's return type, all of it.
output
: import zz.
function object<{
    id: z.ZodUUID;
}>(shape?: {
    id: z.ZodUUID;
} | 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.ZodUUID;
}, z.core.$strip>
object
({ id: z.ZodUUIDid: import zz.function uuid(params?: string | z.core.$ZodUUIDParams): z.ZodUUIDuuid() }),
async
handler: (ctx: QueryCtx<{
    scope: {
        accountId: string;
    };
}, {
    accountId: string;
}>, input: {
    bookingId: string;
}) => Promise<{
    id: string;
}>
handler
(
ctx: QueryCtx<{
    scope: {
        accountId: string;
    };
}, {
    accountId: string;
}>
ctx
, { bookingId: stringbookingId }) {
return
const findBooking: (ctx: {
    scope: {
        accountId: string;
    };
}, id: string) => Promise<{
    id: string;
    accountId: string;
}>
findBooking
(
ctx: QueryCtx<{
    scope: {
        accountId: string;
    };
}, {
    accountId: string;
}>
ctx
, bookingId: stringbookingId);
}, });
  • Return value (1). The handler returns the full row. The Zod object in this example strips unknown keys, including accountId.
  • Parsed result (2). Callers get the parsed value and type, or the handler’s full result if you omit output.
  • Public contract. Set an output schema that keeps only the fields you intend to publish. For a Drizzle table, you can derive it with createSelectSchema from drizzle-orm/zod.
  • Validation. Any Standard Schema works. Invalid output throws an unexpected error. In a mutation, that failure rolls back the transaction.

See also

Functions, Authorization, oRPC

Was this page helpful?