Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/wet-nails-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@orpc/server": minor
"@orpc/shared": minor
---

feat!: `.handler` become `.func`, caller accept FormData
2 changes: 1 addition & 1 deletion apps/content/content/docs/client/react.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const router = {
user: {
list: os
.input(z.object({ cursor: z.number(), limit: z.number() }))
.handler((input) => {
.func((input) => {
return {
nextCursor: input.cursor + input.limit,
users: []
Expand Down
6 changes: 3 additions & 3 deletions apps/content/content/docs/contract-first.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -95,23 +95,23 @@ export const authed /** require authed */ = os
.contract(contract)

export const router = pub.router({
getting: pub.getting.handler((input, context, meta) => {
getting: pub.getting.func((input, context, meta) => {
return {
message: `Hello, ${input.name}!`,
}
}),

post: {
find: pub.post.find
.handler((input, context, meta) => {
.func((input, context, meta) => {
return {
id: 'example',
title: 'example',
description: 'example',
}
}),

create: authed.post.create.handler((input, context, meta) => {
create: authed.post.create.func((input, context, meta) => {
return {
id: 'example',
title: input.title,
Expand Down
6 changes: 3 additions & 3 deletions apps/content/content/docs/contract/builder.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -88,23 +88,23 @@ export const authed /** require authed */ = base
.contract(contract)

export const router = pub.router({
getting: pub.getting.handler((input, context, meta) => {
getting: pub.getting.func((input, context, meta) => {
return {
message: `Hello, ${input.name}!`,
}
}),

post: {
find: pub.post.find
.handler((input, context, meta) => {
.func((input, context, meta) => {
return {
id: 'example',
title: 'example',
description: 'example',
}
}),

create: authed.post.create.handler((input, context, meta) => {
create: authed.post.create.func((input, context, meta) => {
return {
id: 'example',
title: input.title,
Expand Down
6 changes: 3 additions & 3 deletions apps/content/content/docs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const router = pub.router({
name: z.string(),
}),
)
.handler(async (input, context, meta) => {
.func(async (input, context, meta) => {
return {
message: `Hello, ${input.name}!`,
}
Expand Down Expand Up @@ -105,7 +105,7 @@ export const router = pub.router({

return result
})
.handler((input, context, meta) => {
.func((input, context, meta) => {
return {
id: 'example',
title: 'example',
Expand All @@ -121,7 +121,7 @@ export const router = pub.router({
thumb: oz.file().type('image/*'),
}),
)
.handler(async (input, context, meta) => {
.func(async (input, context, meta) => {
input.thumb // file upload out of the box

return {
Expand Down
6 changes: 3 additions & 3 deletions apps/content/content/docs/openapi/generator.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const router = pub.router({
name: z.string(),
}),
)
.handler(async (input, context, meta) => {
.func(async (input, context, meta) => {
return {
message: `Hello, ${input.name}!`,
}
Expand All @@ -53,7 +53,7 @@ export const router = pub.router({
description: z.string(),
}),
)
.handler((input, context, meta) => {
.func((input, context, meta) => {
return {
id: 'example',
title: 'example',
Expand All @@ -69,7 +69,7 @@ export const router = pub.router({
thumb: oz.file().type('image/*'),
}),
)
.handler(async (input, context, meta) => {
.func(async (input, context, meta) => {
input.thumb // file upload out of the box

return {
Expand Down
3 changes: 1 addition & 2 deletions apps/content/content/docs/server/advanced.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ description: Beyond the basics, oRPC offers more advanced features
import { os, createRouterCaller } from '@orpc/server'

const router = os.router({
ping: os.handler(() => 'pong')
ping: os.func(() => 'pong')
})

const caller = createRouterCaller({
router: router,
context: {},
validate: true // set false if you want bypass the validation input and output
})

const result = await caller.ping(undefined) // result is 'pong'
Expand Down
2 changes: 1 addition & 1 deletion apps/content/content/docs/server/error-handling.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const ping = os
// do something on finish
}
})
.handler((input, context, meta) => {
.func((input, context, meta) => {
throw new ORPCError({
code: 'NOT_FOUND',
message: 'Not found',
Expand Down
4 changes: 2 additions & 2 deletions apps/content/content/docs/server/file-upload.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { z } from 'zod'

export const uploadFile = os.input(
z.object({ file: z.instanceof(File) })
).handler(async (input) => {
).func(async (input) => {
const file: File = input.file
// Handle the file as needed, e.g., save to storage, process, etc.
})
Expand All @@ -45,7 +45,7 @@ import { z } from 'zod'

export const uploadFile = os.input(
z.object({ file: oz.file().type('image/*') })
).handler(async (input) => {
).func(async (input) => {
const image: File = input.file
// Process the image file as needed
})
Expand Down
2 changes: 1 addition & 1 deletion apps/content/content/docs/server/middleware.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export const authed = pub
}
})
})
.handler(async (input, context, meta) => {
.func(async (input, context, meta) => {

const _expect1: NonNullable<typeof context['user']> = context.user
const _expect2: string = context.say
Expand Down
2 changes: 1 addition & 1 deletion apps/content/content/docs/server/procedure.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const findUser = pub
})

// Define handler with business logic
.handler(async (input, context, meta) => {
.func(async (input, context, meta) => {
// Implement your business logic here

return {
Expand Down
2 changes: 1 addition & 1 deletion apps/content/content/docs/server/router.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ A router is a collection of procedures with utilities that help reduce code dupl
```ts twoslash
import { os } from '@orpc/server'

const findUser = os.route({path: '/'}).handler(() => {})
const findUser = os.route({path: '/'}).func(() => {})

export const appRouter = os.router({
user: {
Expand Down
19 changes: 14 additions & 5 deletions apps/content/content/docs/server/server-action.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,32 @@ Server actions are automatically enabled for procedures that have either:
```ts twoslash
"use server"

import { os } from '@orpc/server'
import { os, createProcedureCaller } from '@orpc/server'
import { z } from 'zod'

// This creates a server action since context is undefined
const actionProcedure = os
.input(z.object({ id: z.number() }))
.handler(() => 'result')
.func(() => 'result')

// This also creates a server action since context is optional
const optionalContextProcedure = os
.context<{ auth: boolean } | undefined>()
.handler(() => 'result')
.func(() => 'result')

// This won't be a server action since it requires context
const regularProcedure = os
.context<{ auth: boolean }>()
.handler(() => 'result')
.func(() => 'result')

// But this will be a server action since it already provided context
const regularProcedure2 = createProcedureCaller({
procedure: regularProcedure,
context: async () => {
// you can use headers, cookies, etc. here
return { auth: true }
},
})
```

## Usage Examples
Expand All @@ -59,7 +68,7 @@ export const createPost = os
}),
}),
)
.handler((input) => {
.func((input) => {
redirect('/posts/new')
})
```
Expand Down
6 changes: 3 additions & 3 deletions apps/content/examples/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const authed /** require authed */ = base
.contract(contract)

export const router = pub.router({
getting: pub.getting.handler((input, context, meta) => {
getting: pub.getting.func((input, context, meta) => {
return {
message: `Hello, ${input.name}!`,
}
Expand All @@ -105,15 +105,15 @@ export const router = pub.router({

return result
})
.handler((input, context, meta) => {
.func((input, context, meta) => {
return {
id: 'example',
title: 'example',
description: 'example',
}
}),

create: authed.post.create.handler((input, context, meta) => {
create: authed.post.create.func((input, context, meta) => {
return {
id: 'example',
title: input.title,
Expand Down
2 changes: 1 addition & 1 deletion apps/content/examples/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const editPost = authed
const _output = result.output
return result
})
.handler(() => 'Edited')
.func(() => 'Edited')

//
//
2 changes: 1 addition & 1 deletion apps/content/examples/server-action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const createPost = os
}),
}),
)
.handler((input) => {
.func((input) => {
redirect('/posts/new')
})

Expand Down
6 changes: 3 additions & 3 deletions apps/content/examples/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const router = pub.router({
name: z.string(),
}),
)
.handler(async (input, context, meta) => {
.func(async (input, context, meta) => {
return {
message: `Hello, ${input.name}!`,
}
Expand Down Expand Up @@ -66,7 +66,7 @@ export const router = pub.router({

return result
})
.handler((input, context, meta) => {
.func((input, context, meta) => {
return {
id: 'example',
title: 'example',
Expand All @@ -82,7 +82,7 @@ export const router = pub.router({
thumb: oz.file().type('image/*'),
}),
)
.handler(async (input, context, meta) => {
.func(async (input, context, meta) => {
const _thumb = input.thumb // file upload out of the box

return {
Expand Down
10 changes: 5 additions & 5 deletions packages/client/src/procedure.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('createProcedureClient', () => {
const schema = z.object({
value: z.string(),
})
const ping = os.input(schema).handler((_, __, { path }) => path)
const ping = os.input(schema).func((_, __, { path }) => path)
const router = os.router({
ping,
nested: {
Expand Down Expand Up @@ -111,7 +111,7 @@ describe('createProcedureClient', () => {
const router = os.router({
ping: os
.input(z.object({ value: z.date() }))
.handler(input => input.value),
.func(input => input.value),
})

const handler = createFetchHandler({
Expand All @@ -137,7 +137,7 @@ describe('createProcedureClient', () => {

it('error include data', async () => {
const router = os.router({
ping: os.handler((input) => {
ping: os.func((input) => {
throw new ORPCError({
code: 'BAD_GATEWAY',
data: {
Expand Down Expand Up @@ -180,14 +180,14 @@ describe('createProcedureClient', () => {

describe('upload file', () => {
const router = os.router({
signal: os.input(z.instanceof(Blob)).handler((input) => {
signal: os.input(z.instanceof(Blob)).func((input) => {
return input
}),
multiple: os
.input(
z.object({ first: z.instanceof(Blob), second: z.instanceof(Blob) }),
)
.handler((input) => {
.func((input) => {
return input
}),
})
Expand Down
8 changes: 4 additions & 4 deletions packages/client/src/procedure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import { ORPCDeserializer, ORPCSerializer } from '@orpc/transformer'
export interface ProcedureClient<
TInputSchema extends Schema,
TOutputSchema extends Schema,
THandlerOutput extends SchemaOutput<TOutputSchema>,
TFuncOutput extends SchemaOutput<TOutputSchema>,
> {
(
input: SchemaInput<TInputSchema>,
): Promise<SchemaOutput<TOutputSchema, THandlerOutput>>
): Promise<SchemaOutput<TOutputSchema, TFuncOutput>>
}

export interface CreateProcedureClientOptions {
Expand Down Expand Up @@ -50,10 +50,10 @@ export interface CreateProcedureClientOptions {
export function createProcedureClient<
TInputSchema extends Schema,
TOutputSchema extends Schema,
THandlerOutput extends SchemaOutput<TOutputSchema>,
TFuncOutput extends SchemaOutput<TOutputSchema>,
>(
options: CreateProcedureClientOptions,
): ProcedureClient<TInputSchema, TOutputSchema, THandlerOutput> {
): ProcedureClient<TInputSchema, TOutputSchema, TFuncOutput> {
const serializer = new ORPCSerializer()
const deserializer = new ORPCDeserializer()

Expand Down
Loading