Skip to content

Commit e7ee5a9

Browse files
authored
docs: metadata (#197)
* docs: metadata * improve
1 parent 45097bd commit e7ee5a9

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

apps/content/.vitepress/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export default defineConfig({
7070
{ text: 'File Upload/Download', link: '/docs/file-upload-download' },
7171
{ text: 'Event Iterator (SSE)', link: '/docs/event-iterator' },
7272
{ text: 'Server Action', link: '/docs/server-action' },
73+
{ text: 'Metadata', link: '/docs/metadata' },
7374
{ text: 'RPC Handler', link: '/docs/rpc-handler' },
7475
{ text: 'Lifecycle', link: '/docs/lifecycle' },
7576
{

apps/content/docs/metadata.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
Title: Metadata
3+
Description: Enhance your procedures with metadata.
4+
---
5+
6+
# Metadata
7+
8+
oRPC procedures support metadata, simple key-value pairs that provide extra information to customize behavior.
9+
10+
## Basic Example
11+
12+
```ts twoslash
13+
import { os } from '@orpc/server'
14+
// ---cut---
15+
interface ORPCMetadata {
16+
cache?: boolean
17+
}
18+
19+
const base = os
20+
.$meta<ORPCMetadata>({}) // require define initial context [!code highlight]
21+
.use(async ({ procedure, next }) => {
22+
const result = await next()
23+
24+
if (!procedure['~orpc'].meta.cache) {
25+
return result
26+
}
27+
28+
// Process the result when caching is enabled
29+
30+
return result
31+
})
32+
33+
const example = base
34+
.meta({ cache: true }) // [!code highlight]
35+
.handler(() => {
36+
// Implement your procedure logic here
37+
})
38+
```
39+
40+
:::info
41+
The `.meta` can be called multiple times; each call [spread merges](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax) the new metadata with the existing metadata or the initial metadata.
42+
:::

apps/content/docs/openapi/routing.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ os.route({ method: 'GET', path: '/example', successStatus: 200 })
2020
os.route({ method: 'POST', path: '/example', successStatus: 201 })
2121
```
2222

23+
:::info
24+
The `.route` can be called multiple times; each call [spread merges](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax) the new route with the existing route.
25+
:::
26+
2327
## Path Parameters
2428

2529
By default, path parameters merge with query/body into a single input object. You can modify this behavior as described in the [Input/Output structure docs](/docs/openapi/input-output-structure).

0 commit comments

Comments
 (0)