{"id":25658246,"url":"https://github.com/maloguertin/msw-trpc","last_synced_at":"2025-10-19T02:56:06.756Z","repository":{"id":65447847,"uuid":"592062598","full_name":"maloguertin/msw-trpc","owner":"maloguertin","description":"tPRC support for MSW","archived":false,"fork":false,"pushed_at":"2024-01-18T15:51:57.000Z","size":170,"stargazers_count":170,"open_issues_count":15,"forks_count":13,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-03-15T15:10:18.645Z","etag":null,"topics":["jest","msw","trpc"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maloguertin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-01-22T20:00:46.000Z","updated_at":"2024-04-22T15:28:53.053Z","dependencies_parsed_at":"2024-04-22T15:28:41.070Z","dependency_job_id":"d81adb5a-5189-475b-8b26-a294adb11d00","html_url":"https://github.com/maloguertin/msw-trpc","commit_stats":{"total_commits":18,"total_committers":2,"mean_commits":9.0,"dds":0.4444444444444444,"last_synced_commit":"6bcf88a80b8fb05743b711c52f30688a6c36c3c9"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maloguertin%2Fmsw-trpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maloguertin%2Fmsw-trpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maloguertin%2Fmsw-trpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maloguertin%2Fmsw-trpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maloguertin","download_url":"https://codeload.github.com/maloguertin/msw-trpc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247685628,"owners_count":20979085,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["jest","msw","trpc"],"created_at":"2025-02-24T00:01:59.693Z","updated_at":"2025-10-19T02:56:06.728Z","avatar_url":"https://github.com/maloguertin.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"assets/trpc-msw.png\" style=\"height: 100px;\"/\u003e\n  \u003ch1\u003emsw-trpc\u003c/h1\u003e\n  \u003ca href=\"https://www.npmjs.com/package/msw-trpc\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/msw-trpc.svg?style=flat\u0026color=brightgreen\" target=\"_blank\" /\u003e\u003c/a\u003e\n  \u003ca href=\"./LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/badge/license-MIT-black\" /\u003e\u003c/a\u003e\n  \u003cbr /\u003e\n  \u003chr /\u003e\n\u003c/div\u003e\n\n## **[tPRC](https://trpc.io/) support for [MSW](https://mswjs.io/)**\n\n- Create MSW handlers from your tRPC router.\n- Get your tRPC typing into your MSW handlers.\n- Augments MSW with utils for tRPC.\n- Use it like you would use the tRPC client.\n- Merged routers supported !\n- Use `msw` v2\n\n## Motivation\n\nAs someone who loves MSW and was already using it I wanted to keep using it instead of mocking tRPC. While it is possible to simply write the Rest handlers it felt like it would be great not to lose the full power of tRPC types in the tests.\n\n## Usage\n\n**1. Install `msw-trpc`.**\n\n```bash\nnpm i msw-trpc --save-dev\n```\n\n**2. build your trpcMsw with createTRPCMsw.**\n\n```typescript\nimport { createTRPCMsw } from 'msw-trpc'\nimport type { AppRouter } from 'path/to/your/router'\n\nexport const trpcMsw = createTRPCMsw\u003cAppRouter\u003e() /* 👈 */\n```\n\n**3. Start using it.**\n\n```typescript\nconst server = setupServer(\n  trpcMsw.userById.query(() =\u003e ({ id: '1', name: 'Uncle bob' })),\n  trpcMsw.createUser.mutation((name) =\u003e ({ id: '2', name }))\n)\n```\n\nYou can find examples of how to use it in the [test-react](./packages/test-react/package.json) package or in the [test-node](./packages/test-node/package.json) package.\n\n## How it works\n\n`createTRPCMsw` returns a Proxy that infers types from your AppRouter\n\n```typescript\n// all queries will expose a query function that accepts a MSW handler\ntrpcMsw.myQuery.query(() =\u003e {})\n\n// all mutations will expose a mutation function that accepts a MSW handler\ntrpcMsw.myMutation.mutation(() =\u003e {})\n```\n\n## Config\n\nYou need to pass a `httpLink` to the `createTRPCMsw` function like you would do with the tRPC client.\n\nYou can pass an optional transformer like `superjson` to the `createTRPCMsw` function.\n\n```typescript\ninterface TRPCMswConfig {\n  links: Link[]\n  transformer?: TRPCCombinedDataTransformer\n}\n```\n\n## Requirements\n\nPeer dependencies:\n\n- [`tRPC`](https://github.com/trpc/trpc) server v11 (`@trpc/server@next`) must be installed.\n- [`msw`](https://github.com/mswjs/msw) (`msw`) must be installed.\n\nPlease note:\n\n- Batch is not yet supported\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaloguertin%2Fmsw-trpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaloguertin%2Fmsw-trpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaloguertin%2Fmsw-trpc/lists"}