orpc-context
Type-safe dependency injection pattern in oRPC.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Type-safe dependency injection pattern in oRPC.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
Quick reference for Better Notify configuration, patterns, and common gotchas
Interactive setup wizard for adding Better Notify to a TypeScript/JavaScript project
Context and API guidance for Better Notify — end-to-end typed notification infrastructure for Node.js
Seamlessly use AI SDK inside your oRPC projects without any extra overhead.
Use oRPC inside an Astro project.
Functions to encode and decode base64url strings (URL-safe variant of base64).
| name | oRPC Context |
| description | Type-safe dependency injection pattern in oRPC. |
| license | MIT |
| metadata | {"author":"Ali Torki","homepage":"https://github.com/ali-master","version":"1.0.0"} |
oRPC's context mechanism provides a type-safe dependency injection pattern. Two types:
const base = os.$context<{ headers: Headers, env: { DB_URL: string } }>()
const getting = base.handler(async ({ context }) => {
console.log(context.env)
})
export const router = { getting }
Pass initial context explicitly:
import { RPCHandler } from '@orpc/server/fetch'
const handler = new RPCHandler(router)
export default function fetch(request: Request) {
handler.handle(request, {
context: {
headers: request.headers,
env: { DB_URL: '***' }
}
})
}
Provided dynamically through middleware:
import { cookies, headers } from 'next/headers'
const base = os.use(async ({ next }) => next({
context: {
headers: await headers(),
cookies: await cookies(),
},
}))
const getting = base.handler(async ({ context }) => {
context.cookies.set('key', 'value')
})
const base = os.$context<{ headers: Headers, env: { DB_URL: string } }>()
const requireAuth = base.middleware(async ({ context, next }) => {
const user = parseJWT(context.headers.get('authorization')?.split(' ')[1])
if (user) return next({ context: { user } })
throw new ORPCError('UNAUTHORIZED')
})
const dbProvider = base.middleware(async ({ context, next }) => {
const client = new Client(context.env.DB_URL)
try {
await client.connect()
return next({ context: { db: client } })
} finally {
await client.disconnect()
}
})
const getting = base
.use(dbProvider)
.use(requireAuth)
.handler(async ({ context }) => {
console.log(context.db)
console.log(context.user)
})
When you pass additional context to
next, it merges with the existing context.