Metadata
oRPC procedures support metadata, simple key-value pairs that provide extra information to customize behavior.
Basic Example
ts
interface ORPCMetadata {
cache?: boolean
}
const base = os
.$meta<ORPCMetadata>({}) // require define initial context
.use(async ({ procedure, next, path }, input, output) => {
if (!procedure['~orpc'].meta.cache) {
return await next()
}
const cacheKey = path.join('/') + JSON.stringify(input)
if (db.has(cacheKey)) {
return output(db.get(cacheKey))
}
const result = await next()
db.set(cacheKey, result.output)
return result
})
const example = base
.meta({ cache: true })
.handler(() => {
// Implement your procedure logic here
})
INFO
The .meta
can be called multiple times; each call spread merges the new metadata with the existing metadata or the initial metadata.