@trpc/client 11.14.0 → 11.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/README.md +8 -0
  2. package/bin/intent.js +20 -0
  3. package/dist/{httpBatchLink.d-B6vCg-F-.d.mts → httpBatchLink.d-p8Y9QM8p.d.mts} +3 -3
  4. package/dist/{httpBatchLink.d-B6vCg-F-.d.mts.map → httpBatchLink.d-p8Y9QM8p.d.mts.map} +1 -1
  5. package/dist/{httpLink.d-CVOTlkUT.d.mts → httpLink.d-CjpPCq4q.d.mts} +3 -3
  6. package/dist/{httpLink.d-CVOTlkUT.d.mts.map → httpLink.d-CjpPCq4q.d.mts.map} +1 -1
  7. package/dist/{httpUtils.d-yYSKGhiS.d.mts → httpUtils.d-C5t5to0D.d.mts} +2 -2
  8. package/dist/{httpUtils.d-yYSKGhiS.d.mts.map → httpUtils.d-C5t5to0D.d.mts.map} +1 -1
  9. package/dist/index.d.mts +7 -7
  10. package/dist/links/httpBatchLink.d.mts +3 -3
  11. package/dist/links/httpLink.d.mts +3 -3
  12. package/dist/links/loggerLink.d.mts +2 -2
  13. package/dist/links/splitLink.d.mts +2 -2
  14. package/dist/links/wsLink/wsLink.d.mts +2 -2
  15. package/dist/{loggerLink.d-DBRq_5Gd.d.mts → loggerLink.d-0ABgt7oh.d.mts} +2 -2
  16. package/dist/{loggerLink.d-DBRq_5Gd.d.mts.map → loggerLink.d-0ABgt7oh.d.mts.map} +1 -1
  17. package/dist/{splitLink.d-BKr9eE0o.d.mts → splitLink.d-CkHNg1Se.d.mts} +2 -2
  18. package/dist/{splitLink.d-BKr9eE0o.d.mts.map → splitLink.d-CkHNg1Se.d.mts.map} +1 -1
  19. package/dist/{types.d-sRNtuQA-.d.mts → types.d-CAr6snH0.d.mts} +2 -2
  20. package/dist/{types.d-sRNtuQA-.d.mts.map → types.d-CAr6snH0.d.mts.map} +1 -1
  21. package/dist/{wsLink.d-DCqbZKOH.d.mts → wsLink.d-pFN64NkG.d.mts} +2 -2
  22. package/dist/{wsLink.d-DCqbZKOH.d.mts.map → wsLink.d-pFN64NkG.d.mts.map} +1 -1
  23. package/package.json +15 -5
  24. package/skills/client-setup/SKILL.md +317 -0
  25. package/skills/links/SKILL.md +300 -0
  26. package/skills/links/references/link-options.md +248 -0
  27. package/skills/superjson/SKILL.md +273 -0
@@ -0,0 +1,273 @@
1
+ ---
2
+ name: superjson
3
+ description: >
4
+ Configure SuperJSON transformer on both server initTRPC.create({ transformer:
5
+ superjson }) and every client terminating link (httpBatchLink, httpLink, wsLink,
6
+ httpSubscriptionLink) to support Date, Map, Set, BigInt over the wire. Transformer
7
+ must match on both sides. In v11, transformer goes on individual links, not the
8
+ client constructor.
9
+ type: composition
10
+ library: trpc
11
+ library_version: '11.14.0'
12
+ requires:
13
+ - server-setup
14
+ - client-setup
15
+ sources:
16
+ - www/docs/server/data-transformers.md
17
+ ---
18
+
19
+ # tRPC -- SuperJSON Transformer
20
+
21
+ ## Setup
22
+
23
+ ### 1. Install superjson
24
+
25
+ ```bash
26
+ npm install superjson
27
+ ```
28
+
29
+ ### 2. Add to initTRPC on the server
30
+
31
+ ```ts
32
+ // server/trpc.ts
33
+ import { initTRPC } from '@trpc/server';
34
+ import superjson from 'superjson';
35
+
36
+ const t = initTRPC.create({
37
+ transformer: superjson,
38
+ });
39
+
40
+ export const router = t.router;
41
+ export const publicProcedure = t.procedure;
42
+ ```
43
+
44
+ ### 3. Add to every terminating link on the client
45
+
46
+ ```ts
47
+ // client.ts
48
+ import { createTRPCClient, httpBatchLink } from '@trpc/client';
49
+ import superjson from 'superjson';
50
+ import type { AppRouter } from './server/trpc';
51
+
52
+ const client = createTRPCClient<AppRouter>({
53
+ links: [
54
+ httpBatchLink({
55
+ url: 'http://localhost:3000/trpc',
56
+ transformer: superjson,
57
+ }),
58
+ ],
59
+ });
60
+ ```
61
+
62
+ Now Date, Map, Set, BigInt, RegExp, undefined, and other non-JSON types survive the round trip.
63
+
64
+ ## Core Patterns
65
+
66
+ ### SuperJSON with splitLink and Subscriptions
67
+
68
+ ```ts
69
+ import {
70
+ createTRPCClient,
71
+ httpBatchLink,
72
+ httpSubscriptionLink,
73
+ splitLink,
74
+ } from '@trpc/client';
75
+ import superjson from 'superjson';
76
+ import type { AppRouter } from './server/trpc';
77
+
78
+ const client = createTRPCClient<AppRouter>({
79
+ links: [
80
+ splitLink({
81
+ condition: (op) => op.type === 'subscription',
82
+ true: httpSubscriptionLink({
83
+ url: 'http://localhost:3000/trpc',
84
+ transformer: superjson,
85
+ }),
86
+ false: httpBatchLink({
87
+ url: 'http://localhost:3000/trpc',
88
+ transformer: superjson,
89
+ }),
90
+ }),
91
+ ],
92
+ });
93
+ ```
94
+
95
+ Every terminating link in every branch must have `transformer: superjson`.
96
+
97
+ ### SuperJSON with wsLink
98
+
99
+ ```ts
100
+ import { createTRPCClient, createWSClient, wsLink } from '@trpc/client';
101
+ import superjson from 'superjson';
102
+ import type { AppRouter } from './server/trpc';
103
+
104
+ const wsClient = createWSClient({
105
+ url: 'ws://localhost:3000',
106
+ });
107
+
108
+ const client = createTRPCClient<AppRouter>({
109
+ links: [
110
+ wsLink<AppRouter>({
111
+ client: wsClient,
112
+ transformer: superjson,
113
+ }),
114
+ ],
115
+ });
116
+ ```
117
+
118
+ ### Returning Dates from Procedures
119
+
120
+ ```ts
121
+ // server
122
+ import { z } from 'zod';
123
+ import { publicProcedure, router } from './trpc';
124
+
125
+ const appRouter = router({
126
+ getEvent: publicProcedure
127
+ .input(z.object({ id: z.string() }))
128
+ .query(({ input }) => {
129
+ return {
130
+ id: input.id,
131
+ name: 'Launch Party',
132
+ date: new Date('2025-01-01T00:00:00Z'),
133
+ };
134
+ }),
135
+ });
136
+
137
+ export type AppRouter = typeof appRouter;
138
+ ```
139
+
140
+ ```ts
141
+ // client
142
+ const event = await client.getEvent.query({ id: '1' });
143
+ console.log(event.date instanceof Date); // true
144
+ console.log(event.date.getFullYear()); // 2025
145
+ ```
146
+
147
+ Without superjson, `event.date` would be a string like `"2025-01-01T00:00:00.000Z"`.
148
+
149
+ ## Common Mistakes
150
+
151
+ ### [CRITICAL] Transformer on server but missing from client link
152
+
153
+ Wrong:
154
+
155
+ ```ts
156
+ // Server
157
+ const t = initTRPC.create({ transformer: superjson });
158
+
159
+ // Client
160
+ const client = createTRPCClient<AppRouter>({
161
+ links: [httpBatchLink({ url: 'http://localhost:3000/trpc' })],
162
+ });
163
+ ```
164
+
165
+ Correct:
166
+
167
+ ```ts
168
+ // Server
169
+ const t = initTRPC.create({ transformer: superjson });
170
+
171
+ // Client
172
+ const client = createTRPCClient<AppRouter>({
173
+ links: [
174
+ httpBatchLink({
175
+ url: 'http://localhost:3000/trpc',
176
+ transformer: superjson,
177
+ }),
178
+ ],
179
+ });
180
+ ```
181
+
182
+ Server encodes with superjson but client tries to parse raw JSON, causing "Unable to transform response" or garbled data.
183
+
184
+ Source: www/docs/server/data-transformers.md
185
+
186
+ ### [CRITICAL] Transformer goes on individual links, not createTRPCClient
187
+
188
+ The `transformer` option is on individual terminating links:
189
+
190
+ ```ts
191
+ createTRPCClient<AppRouter>({
192
+ links: [
193
+ httpBatchLink({
194
+ url: 'http://localhost:3000/trpc',
195
+ transformer: superjson,
196
+ }),
197
+ ],
198
+ });
199
+ ```
200
+
201
+ In v11, `transformer` was moved from the client constructor to individual links. Passing it to `createTRPCClient` throws a TypeError.
202
+
203
+ Source: packages/client/src/internals/TRPCUntypedClient.ts
204
+
205
+ ### [CRITICAL] Transformer on only some terminating links in splitLink
206
+
207
+ Wrong:
208
+
209
+ ```ts
210
+ splitLink({
211
+ condition: (op) => op.type === 'subscription',
212
+ true: httpSubscriptionLink({
213
+ url: 'http://localhost:3000/trpc',
214
+ // missing transformer!
215
+ }),
216
+ false: httpBatchLink({
217
+ url: 'http://localhost:3000/trpc',
218
+ transformer: superjson,
219
+ }),
220
+ });
221
+ ```
222
+
223
+ Correct:
224
+
225
+ ```ts
226
+ splitLink({
227
+ condition: (op) => op.type === 'subscription',
228
+ true: httpSubscriptionLink({
229
+ url: 'http://localhost:3000/trpc',
230
+ transformer: superjson,
231
+ }),
232
+ false: httpBatchLink({
233
+ url: 'http://localhost:3000/trpc',
234
+ transformer: superjson,
235
+ }),
236
+ });
237
+ ```
238
+
239
+ Every terminating link must have the same transformer. A missing transformer on one branch causes deserialization failures only for operations routed through that branch.
240
+
241
+ Source: www/docs/server/data-transformers.md
242
+
243
+ ### [HIGH] Using transformer on client but not on server
244
+
245
+ Wrong:
246
+
247
+ ```ts
248
+ // Server -- no transformer
249
+ const t = initTRPC.create();
250
+
251
+ // Client
252
+ httpBatchLink({ url, transformer: superjson });
253
+ ```
254
+
255
+ Correct:
256
+
257
+ ```ts
258
+ // Server
259
+ const t = initTRPC.create({ transformer: superjson });
260
+
261
+ // Client
262
+ httpBatchLink({ url, transformer: superjson });
263
+ ```
264
+
265
+ The transformer must be configured on both `initTRPC.create()` and every client link. Client-only transformer corrupts the request encoding because the server expects plain JSON.
266
+
267
+ Source: www/docs/server/data-transformers.md
268
+
269
+ ## See Also
270
+
271
+ - `client-setup` -- create the tRPC client and configure links
272
+ - `links` -- detailed options for each link type including transformer
273
+ - `server-setup` -- initTRPC.create() where the server transformer is configured