trpc
БесплатноБез исполняемых скриптовНе проверенConventions for writing tRPC routers and procedures.
от PrairieLearn★ 539 звёзд на GitHubОб этом скилле
Quick reference
- Adding a procedure to an existing feature? The subrouter file in the appropriate scope directory is the primary location. Depending on the procedure, also update focused tests, SQL or model functions, safe-output schemas, and the subrouter's typed-error interface.
- Adding a new subrouter to an existing scope? Create a new file in the scope directory, export a router, register it in that scope's
trpc.ts. - Adding a new scope? Copy an existing scope directory (e.g.
trpc/assessment/), adjust theResLocalsForPagetype, context fields, URL helper inlib/client/url.ts, and mount path inserver.ts. - Wiring up client-side React? Follow the pattern in any page that already uses tRPC (e.g.
pages/instructorInstanceAdminSettings/). Key pieces:generatePrefixCsrfTokenfrom@prairielearn/signed-tokenserver-side, the scope'sclient.tsandcontext.ts, andQueryClientProviderDebugfrom@prairielearn/trpc/reactclient-side. - Returning typed errors? See Typed errors.
Authorization scopes
tRPC routers are mounted per authorization scope, not per page. Each scope has its own directory under apps/prairielearn/src/trpc/ and is mounted behind the corresponding Express authorization middleware chain.
| Scope | Directory | Mount path | ResLocalsForPage type |
|---|---|---|---|
| administrator | trpc/administrator/ |
/pl/administrator/trpc |
'plain' |
| course | (create when needed) | /pl/course/:course_id/trpc |
'course' |
| course instance | trpc/courseInstance/ |
/pl/course_instance/:id/instructor/trpc |
'course-instance' |
| assessment | trpc/assessment/ |
.../assessment/:assessment_id/trpc |
'assessment' |
| assessment question | trpc/assessmentQuestion/ |
.../assessment/:aid/assessment_question/:aqid/trpc |
'instructor-assessment-question' |
| assessment instance | (create when needed) | .../assessment_instance/:ai_id/trpc |
'assessment-instance' |
| instance question | (create when needed) | .../instance_question/:iq_id/trpc |
'instance-question' |
Do not create per-page tRPC routers.
File structure
Every scope directory contains: init.ts, trpc.ts, client.ts, context.ts, plus one *.ts file per subrouter and optional *.sql files for scope-specific queries. All routers use superjson as the transformer in both init.ts and client.ts.
See any existing scope (e.g. trpc/assessment/) for the exact boilerplate. The files follow a mechanical pattern — init.ts creates the tRPC instance and authorization middleware, trpc.ts composes subrouters and exports Express middleware via createExpressMiddleware, client.ts creates the HTTP client with CSRF headers, context.ts exports TRPCProvider/useTRPC via createTRPCContext.
Shared infrastructure comes from explicit @prairielearn/trpc subpaths:
@prairielearn/trpc/serverforappErrorFormatterandthrowAppError.@prairielearn/trpc/clientforAppError,getAppError, andrenderAppError.@prairielearn/trpc/reactforAppErrorAlertandQueryClientProviderDebug.@prairielearn/trpc/expressfor tRPC request detection, multipart detection, and pre-adapter error responses.
Do not create a global tRPC initialization factory. Each scope initializes its context-bound t in its own init.ts with the shared appErrorFormatter.
Conventions
Naming
- Procedure names describe the action:
list,upsert,destroy— notlistWidgetsordeleteMutation. - Variable names may use a
Mutation/Proceduresuffix (e.g.const setModeMutation = t.procedure...), but the router key must not:setMode: setModeMutation. - Subrouter exports:
{feature}Router(e.g.widgetsRouter). Router keys: camelCase (widgets).
Authorization
- Permission middleware (
requireCourseInstancePermissionView, etc.) is defined ininit.tsand chained with.use(). - Feature flag middleware (checking
features.enabled(...)) goes in the subrouter file, notinit.ts. Seetrpc/assessment/access-control.tsfor an example. - Each scope's
createContextincludes the fulllocalsobject alongside extracted fields as an escape hatch.
Returning data
- Use role-scoped schemas from
lib/client/safe-db-types.ts(e.g.StaffStudentLabelSchema). Always.parse()records through the schema before returning. - Use existing model functions from
models/instead of one-off SQL.
Client-side queries and mutations
- Use
Установить trpc в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл trpc?
Conventions for writing tRPC routers and procedures.
Как установить скилл trpc?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл trpc запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic