@trpc/client 11.32.2 → 11.34.0

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 (78) hide show
  1. package/dist/{httpBatchLink-DbD4ZGAM.d.cts → httpBatchLink-50xXDyIp.d.cts} +6 -4
  2. package/dist/{httpBatchLink-DbD4ZGAM.d.cts.map → httpBatchLink-50xXDyIp.d.cts.map} +1 -1
  3. package/dist/{httpBatchLink-Dk3_n5pP.d.mts → httpBatchLink-D4shlyQy.d.mts} +6 -4
  4. package/dist/{httpBatchLink-Dk3_n5pP.d.mts.map → httpBatchLink-D4shlyQy.d.mts.map} +1 -1
  5. package/dist/httpBatchLink-DRitkRBC.mjs.map +1 -1
  6. package/dist/{httpLink-BjZdBzr6.d.mts → httpLink-Bb6hOyBN.d.mts} +6 -4
  7. package/dist/httpLink-Bb6hOyBN.d.mts.map +1 -0
  8. package/dist/httpLink-Cmg_mV7L.mjs.map +1 -1
  9. package/dist/{httpUtils-gZ7bAQ6T.d.mts → httpUtils-BbinScxw.d.mts} +2 -2
  10. package/dist/{httpUtils-CxgZ3W-1.d.cts.map → httpUtils-BbinScxw.d.mts.map} +1 -1
  11. package/dist/{httpUtils-CxgZ3W-1.d.cts → httpUtils-dB1XeokQ.d.cts} +2 -2
  12. package/dist/{httpUtils-gZ7bAQ6T.d.mts.map → httpUtils-dB1XeokQ.d.cts.map} +1 -1
  13. package/dist/index.cjs +25 -16
  14. package/dist/index.d.cts +120 -25
  15. package/dist/index.d.cts.map +1 -1
  16. package/dist/index.d.mts +123 -28
  17. package/dist/index.d.mts.map +1 -1
  18. package/dist/index.mjs +25 -17
  19. package/dist/index.mjs.map +1 -1
  20. package/dist/links/httpBatchLink.d.cts +1 -1
  21. package/dist/links/httpBatchLink.d.mts +1 -1
  22. package/dist/links/httpLink.d.cts +5 -3
  23. package/dist/links/httpLink.d.cts.map +1 -1
  24. package/dist/links/httpLink.d.mts +1 -1
  25. package/dist/links/loggerLink.d.cts +4 -2
  26. package/dist/links/loggerLink.d.cts.map +1 -1
  27. package/dist/links/loggerLink.d.mts +1 -1
  28. package/dist/links/loggerLink.mjs.map +1 -1
  29. package/dist/links/splitLink.cjs +1 -1
  30. package/dist/links/splitLink.d.cts +43 -9
  31. package/dist/links/splitLink.d.cts.map +1 -1
  32. package/dist/links/splitLink.d.mts +1 -1
  33. package/dist/links/splitLink.mjs +1 -1
  34. package/dist/links/wsLink/wsLink.d.cts +1 -1
  35. package/dist/links/wsLink/wsLink.d.mts +1 -1
  36. package/dist/{loggerLink-CBPx95zm.d.mts → loggerLink-y1x7WTWX.d.mts} +5 -3
  37. package/dist/loggerLink-y1x7WTWX.d.mts.map +1 -0
  38. package/dist/splitLink-BGLTgm1a.d.mts +56 -0
  39. package/dist/splitLink-BGLTgm1a.d.mts.map +1 -0
  40. package/dist/{splitLink-PFsRy7Mf.mjs → splitLink-C8U8vvLl.mjs} +10 -9
  41. package/dist/splitLink-C8U8vvLl.mjs.map +1 -0
  42. package/dist/{splitLink-BBLj14Dv.cjs → splitLink-NqS85b92.cjs} +9 -8
  43. package/dist/{types-BG-3kpeg.d.mts → types-BZH1P86I.d.mts} +67 -10
  44. package/dist/types-BZH1P86I.d.mts.map +1 -0
  45. package/dist/{types-BhHxuBsu.d.cts → types-CGS36fjk.d.cts} +67 -10
  46. package/dist/types-CGS36fjk.d.cts.map +1 -0
  47. package/dist/{wsLink-DU5wj6kH.d.mts → wsLink-CFh-pvQG.d.mts} +5 -3
  48. package/dist/{wsLink-BlAMQb0i.d.cts.map → wsLink-CFh-pvQG.d.mts.map} +1 -1
  49. package/dist/{wsLink-BlAMQb0i.d.cts → wsLink-CJT5pqFt.d.cts} +5 -3
  50. package/dist/{wsLink-DU5wj6kH.d.mts.map → wsLink-CJT5pqFt.d.cts.map} +1 -1
  51. package/dist/wsLink-C_Zg2yXV.mjs.map +1 -1
  52. package/package.json +3 -3
  53. package/skills/client-setup/SKILL.md +1 -1
  54. package/skills/links/SKILL.md +59 -2
  55. package/skills/links/references/client-links-retryLink.md +28 -0
  56. package/skills/links/references/client-links-splitLink.md +22 -6
  57. package/skills/superjson/SKILL.md +1 -1
  58. package/src/createTRPCClient.ts +91 -21
  59. package/src/index.ts +1 -0
  60. package/src/internals/types.ts +8 -5
  61. package/src/links/httpBatchLink.ts +6 -2
  62. package/src/links/httpBatchStreamLink.ts +6 -2
  63. package/src/links/httpLink.ts +6 -1
  64. package/src/links/httpSubscriptionLink.ts +6 -2
  65. package/src/links/localLink.ts +1 -1
  66. package/src/links/loggerLink.ts +11 -2
  67. package/src/links/retryLink.ts +42 -7
  68. package/src/links/splitLink.ts +126 -13
  69. package/src/links/types.ts +114 -5
  70. package/src/links/wsLink/wsLink.ts +1 -1
  71. package/src/routerType.ts +31 -0
  72. package/dist/httpLink-BjZdBzr6.d.mts.map +0 -1
  73. package/dist/loggerLink-CBPx95zm.d.mts.map +0 -1
  74. package/dist/splitLink-BtPz7lCB.d.mts +0 -23
  75. package/dist/splitLink-BtPz7lCB.d.mts.map +0 -1
  76. package/dist/splitLink-PFsRy7Mf.mjs.map +0 -1
  77. package/dist/types-BG-3kpeg.d.mts.map +0 -1
  78. package/dist/types-BhHxuBsu.d.cts.map +0 -1
package/dist/index.d.mts CHANGED
@@ -1,12 +1,12 @@
1
1
  import { t as TRPCConnectionState } from "./subscriptions-CvJnusYO.mjs";
2
- import { a as OperationResultEnvelope, c as TRPCClientRuntime, d as TRPCClientError, f as TRPCClientErrorBase, g as NativeFetchEsque, h as FetchEsque, i as OperationLink, l as TRPCFetch, m as isTRPCClientError, n as Operation, o as OperationResultObservable, p as TRPCClientErrorLike, r as OperationContext, s as OperationResultObserver, t as HTTPHeaders, u as TRPCLink, v as TRPCProcedureOptions } from "./types-BG-3kpeg.mjs";
3
- import { n as HTTPBatchLinkOptions, t as httpBatchLink } from "./httpBatchLink-Dk3_n5pP.mjs";
4
- import { n as httpLink, t as HTTPLinkOptions } from "./httpLink-BjZdBzr6.mjs";
5
- import { n as loggerLink, t as LoggerLinkOptions } from "./loggerLink-CBPx95zm.mjs";
6
- import { t as splitLink } from "./splitLink-BtPz7lCB.mjs";
7
- import { a as WebSocketClientOptions, c as jsonEncoder, i as createWSClient, n as wsLink, o as UrlOptionsWithConnectionParams, r as TRPCWebSocketClient, s as Encoder, t as WebSocketLinkOptions } from "./wsLink-DU5wj6kH.mjs";
2
+ import { C as TRPCProcedureOptions, _ as TRPCClientErrorBase, a as Operation, b as FetchEsque, c as OperationResultEnvelope, d as TRPCClientRuntime, f as TRPCFetch, g as TRPCClientError, h as inferLinksDeclaredContext, i as NoLinkReadsContext, l as OperationResultObservable, m as inferLinksContext, n as HTTPHeaders, o as OperationContext, p as TRPCLink, r as LinkDecl, s as OperationLink, t as AugmentedOperationContext, u as OperationResultObserver, v as TRPCClientErrorLike, x as NativeFetchEsque, y as isTRPCClientError } from "./types-BZH1P86I.mjs";
3
+ import { n as HTTPBatchLinkOptions, t as httpBatchLink } from "./httpBatchLink-D4shlyQy.mjs";
4
+ import { n as httpLink, t as HTTPLinkOptions } from "./httpLink-Bb6hOyBN.mjs";
5
+ import { n as loggerLink, t as LoggerLinkOptions } from "./loggerLink-y1x7WTWX.mjs";
6
+ import { t as splitLink } from "./splitLink-BGLTgm1a.mjs";
7
+ import { a as WebSocketClientOptions, c as jsonEncoder, i as createWSClient, n as wsLink, o as UrlOptionsWithConnectionParams, r as TRPCWebSocketClient, s as Encoder, t as WebSocketLinkOptions } from "./wsLink-CFh-pvQG.mjs";
8
8
  import { n as TransformerOptions } from "./unstable-internals-CnrO49lh.mjs";
9
- import { t as HTTPLinkBaseOptions } from "./httpUtils-gZ7bAQ6T.mjs";
9
+ import { t as HTTPLinkBaseOptions } from "./httpUtils-BbinScxw.mjs";
10
10
  import { Unsubscribable } from "@trpc/server/observable";
11
11
  import { AnyClientTypes, AnyProcedure, AnyRouter, ErrorHandlerOptions, EventSourceLike, InferrableClientTypes, ProcedureType, RouterRecord, TypeError, inferAsyncIterableYield, inferClientTypes, inferProcedureErrorShape, inferProcedureInput, inferRouterContext, inferTransformedProcedureOutput } from "@trpc/server/unstable-core-do-not-import";
12
12
  import { AnyRouter as AnyRouter$1 } from "@trpc/server";
@@ -107,6 +107,31 @@ export declare class TRPCUntypedClient<TInferrable extends InferrableClientTypes
107
107
  * Meant for libraries built on tRPC; apps should use `createTRPCClient`.
108
108
  */
109
109
  export declare function createTRPCUntypedClient<TRouter extends AnyRouter>(opts: CreateTRPCClientOptions<TRouter>): TRPCUntypedClient<TRouter>;
110
+ declare const routerTypeBrand: unique symbol;
111
+ /**
112
+ * A value that carries a router's type and nothing else. Made by
113
+ * {@link routerType}.
114
+ * @public
115
+ */
116
+ export interface RouterType<TRouter extends AnyRouter> {
117
+ readonly [routerTypeBrand]: TRouter;
118
+ }
119
+ /**
120
+ * Passes a router's type to `createTRPCClient({ router })` as a normal
121
+ * option, instead of a type argument. Nothing about the router exists at
122
+ * runtime, so it's safe to import the router's type only.
123
+ *
124
+ * @example
125
+ * ```ts
126
+ * const client = createTRPCClient({
127
+ * router: routerType<AppRouter>(),
128
+ * links: [httpBatchLink({ url: 'http://localhost:3000/trpc' })],
129
+ * });
130
+ * ```
131
+ * @see https://trpc.io/docs/client/vanilla/setup#3-initialize-the-trpc-client
132
+ * @public
133
+ */
134
+ export declare function routerType<TRouter extends AnyRouter>(): RouterType<TRouter>;
110
135
  /**
111
136
  * @internal
112
137
  */
@@ -162,13 +187,16 @@ declare const untypedClientSymbol: unique symbol;
162
187
  /**
163
188
  * A typed client for a router, as `createTRPCClient` returns it. Each
164
189
  * procedure has `.query()`, `.mutate()` or `.subscribe()`.
190
+ *
191
+ * `TContext` is the `context` calls take; `createTRPCClient({ router,
192
+ * links })` infers it from the links.
165
193
  * @see https://trpc.io/docs/client/vanilla/infer-types
166
194
  * @public
167
195
  **/
168
- export type TRPCClient<TRouter extends AnyRouter> = DecoratedProcedureRecord<{
196
+ export type TRPCClient<TRouter extends AnyRouter, TContext extends object = Record<string, unknown>> = DecoratedProcedureRecord<{
169
197
  transformer: TRouter['_def']['_config']['$types']['transformer'];
170
198
  errorShape: TRouter['_def']['_config']['$types']['errorShape'];
171
- }, TRouter['_def']['record']> & {
199
+ }, TRouter['_def']['record'], TContext> & {
172
200
  [untypedClientSymbol]: TRPCUntypedClient<TRouter>;
173
201
  };
174
202
  /**
@@ -186,31 +214,31 @@ type coerceAsyncGeneratorToIterable<T> = T extends AsyncGenerator<infer $T, infe
186
214
  * The `.query()` or `.mutate()` of a procedure on the client.
187
215
  * @internal
188
216
  */
189
- export type Resolver<TDef extends TRPCResolverDef> = (input: TDef['input'], opts?: TRPCProcedureOptions) => TRPCTaggedPromise<coerceAsyncGeneratorToIterable<TDef['output']>, TDef['errorShape']>;
217
+ export type Resolver<TDef extends TRPCResolverDef, TContext extends object = Record<string, unknown>> = (input: TDef['input'], opts?: TRPCProcedureOptions<TContext>) => TRPCTaggedPromise<coerceAsyncGeneratorToIterable<TDef['output']>, TDef['errorShape']>;
190
218
  /**
191
219
  * The `.subscribe()` of a subscription procedure on the client.
192
220
  * @internal
193
221
  */
194
- export type SubscriptionResolver<TDef extends TRPCResolverDef> = {
195
- (input: TDef['input'], opts: TRPCSubscriptionCallbacks<TDef['output'], TRPCClientError<TDef>> & TRPCProcedureOptions): Unsubscribable;
196
- <TOpts extends TRPCProcedureOptions & Partial<TRPCSubscriptionObserver<TDef['output'], TRPCClientError<TDef>>> = TRPCProcedureOptions>(input: TDef['input'], opts?: TRPCSubscriptionWithoutCallbacks<TOpts>): AsyncIterableIterator<inferAsyncIterableYield<TDef['output']>>;
222
+ export type SubscriptionResolver<TDef extends TRPCResolverDef, TContext extends object = Record<string, unknown>> = {
223
+ (input: TDef['input'], opts: TRPCSubscriptionCallbacks<TDef['output'], TRPCClientError<TDef>> & TRPCProcedureOptions<TContext>): Unsubscribable;
224
+ <TOpts extends TRPCProcedureOptions<TContext> & Partial<TRPCSubscriptionObserver<TDef['output'], TRPCClientError<TDef>>> = TRPCProcedureOptions<TContext>>(input: TDef['input'], opts?: TRPCSubscriptionWithoutCallbacks<TOpts>): AsyncIterableIterator<inferAsyncIterableYield<TDef['output']>>;
197
225
  };
198
- type DecorateProcedure<TType extends ProcedureType, TDef extends TRPCResolverDef> = TType extends 'query' ? {
199
- query: Resolver<TDef>;
226
+ type DecorateProcedure<TType extends ProcedureType, TDef extends TRPCResolverDef, TContext extends object> = TType extends 'query' ? {
227
+ query: Resolver<TDef, TContext>;
200
228
  } : TType extends 'mutation' ? {
201
- mutate: Resolver<TDef>;
229
+ mutate: Resolver<TDef, TContext>;
202
230
  } : TType extends 'subscription' ? {
203
- subscribe: SubscriptionResolver<TDef>;
231
+ subscribe: SubscriptionResolver<TDef, TContext>;
204
232
  } : never;
205
233
  /**
206
234
  * @internal
207
235
  */
208
- type DecoratedProcedureRecord<TRoot extends InferrableClientTypes, TRecord extends RouterRecord> = { [TKey in keyof TRecord]: TRecord[TKey] extends (infer $Value) ? $Value extends AnyProcedure ? DecorateProcedure<$Value['_def']['type'], {
236
+ type DecoratedProcedureRecord<TRoot extends InferrableClientTypes, TRecord extends RouterRecord, TContext extends object> = { [TKey in keyof TRecord]: TRecord[TKey] extends (infer $Value) ? $Value extends AnyProcedure ? DecorateProcedure<$Value['_def']['type'], {
209
237
  input: inferProcedureInput<$Value>;
210
238
  output: inferTransformedProcedureOutput<inferClientTypes<TRoot>, $Value>;
211
239
  errorShape: inferProcedureErrorShape<TRoot, $Value>;
212
240
  transformer: inferClientTypes<TRoot>['transformer'];
213
- }> : $Value extends RouterRecord ? DecoratedProcedureRecord<TRoot, $Value> : never : never; };
241
+ }, TContext> : $Value extends RouterRecord ? DecoratedProcedureRecord<TRoot, $Value, TContext> : never : never; };
214
242
  /**
215
243
  * The procedure type of a client method: `query`, `mutate` or `subscribe`.
216
244
  * @internal
@@ -221,6 +249,45 @@ export declare const clientCallTypeToProcedureType: (clientCallType: string) =>
221
249
  * @internal
222
250
  */
223
251
  export declare function createTRPCClientProxy<TRouter extends AnyRouter>(client: TRPCUntypedClient<TRouter>): TRPCClient<TRouter>;
252
+ /**
253
+ * The options of `createTRPCClient` with the router's type passed as
254
+ * `router: routerType<AppRouter>()`.
255
+ * @public
256
+ */
257
+ export type CreateTRPCClientWithRouterOptions<TRouter extends AnyRouter, TLinks extends readonly TRPCLink<TRouter, any>[] = TRPCLink<TRouter>[]> = Omit<CreateTRPCClientOptions<TRouter>, 'links'> & {
258
+ /**
259
+ * The router's type, from `routerType<AppRouter>()`. It's a type only:
260
+ * nothing about the router is sent or bundled.
261
+ */
262
+ router: RouterType<TRouter>;
263
+ /**
264
+ * The links each call goes through, in order. The last one must send
265
+ * the call, such as `httpBatchLink`. What they declare types each call's
266
+ * `context`, and which methods the client has. Pass them inline or
267
+ * `as const`: in an array declared without it, TypeScript can merge the
268
+ * links' types and drop what one declares.
269
+ * @see https://trpc.io/docs/client/links
270
+ */
271
+ links: TLinks;
272
+ };
273
+ /**
274
+ * Creates a typed client for a router. Pass the router's type with
275
+ * `routerType`, and the links that send its calls. What the links declare
276
+ * types each call's `context`.
277
+ * @example
278
+ * ```ts
279
+ * const client = createTRPCClient({
280
+ * router: routerType<AppRouter>(),
281
+ * links: [retryLink({ retry: () => false }), httpBatchLink({ url })],
282
+ * });
283
+ * const post = await client.post.byId.query(
284
+ * { id: '1' },
285
+ * { context: { retry: (opts) => opts.attempts <= 3 } },
286
+ * );
287
+ * ```
288
+ * @see https://trpc.io/docs/client/vanilla/setup#3-initialize-the-trpc-client
289
+ */
290
+ export declare function createTRPCClient<TRouter extends AnyRouter, const TLinks extends readonly TRPCLink<TRouter, any>[] = TRPCLink<TRouter>[]>(opts: CreateTRPCClientWithRouterOptions<TRouter, TLinks>): TRPCClient<TRouter, inferLinksContext<TLinks>>;
224
291
  /**
225
292
  * Creates a typed client for a router. Pass the router's type, and the
226
293
  * links that send its calls.
@@ -266,7 +333,9 @@ export type HTTPBatchStreamLinkOptions<TRoot extends AnyClientTypes> = HTTPBatch
266
333
  *
267
334
  * @see https://trpc.io/docs/client/links/httpBatchStreamLink
268
335
  */
269
- export declare function httpBatchStreamLink<TRouter extends AnyRouter$1>(opts: HTTPBatchStreamLinkOptions<TRouter['_def']['_config']['$types']>): TRPCLink<TRouter>;
336
+ export declare function httpBatchStreamLink<TRouter extends AnyRouter$1>(opts: HTTPBatchStreamLinkOptions<TRouter['_def']['_config']['$types']>): TRPCLink<TRouter, {
337
+ context: AugmentedOperationContext;
338
+ }>;
270
339
  /**
271
340
  * @deprecated Use {@link httpBatchStreamLink} instead.
272
341
  */
@@ -293,22 +362,44 @@ type HTTPSubscriptionLinkOptions<TRoot extends AnyClientTypes, TEventSource exte
293
362
  *
294
363
  * @see https://trpc.io/docs/client/links/httpSubscriptionLink
295
364
  */
296
- export declare function httpSubscriptionLink<TInferrable extends InferrableClientTypes, TEventSource extends EventSourceLike.AnyConstructor>(opts: HTTPSubscriptionLinkOptions<inferClientTypes<TInferrable>, TEventSource>): TRPCLink<TInferrable>;
365
+ export declare function httpSubscriptionLink<TInferrable extends InferrableClientTypes, TEventSource extends EventSourceLike.AnyConstructor>(opts: HTTPSubscriptionLinkOptions<inferClientTypes<TInferrable>, TEventSource>): TRPCLink<TInferrable, {
366
+ context: AugmentedOperationContext;
367
+ }>;
297
368
  /**
298
369
  * @deprecated Use {@link httpSubscriptionLink} instead.
299
370
  */
300
371
  export declare const unstable_httpSubscriptionLink: typeof httpSubscriptionLink;
372
+ type RetryFn<TInferrable extends InferrableClientTypes> = (opts: RetryFnOptions<TInferrable>) => boolean;
373
+ /**
374
+ * The `context` calls can pass through `retryLink`: the fields added to
375
+ * `OperationContext` (`TAugmented`), which its callbacks may read, and
376
+ * `retry`.
377
+ * @public
378
+ */
379
+ export type RetryLinkContext<TInferrable extends InferrableClientTypes, TAugmented extends object = AugmentedOperationContext> = Omit<TAugmented, 'retry'> & {
380
+ /**
381
+ * Decides whether to retry this call, in place of the link's `retry`.
382
+ * Anything else, such as a flag added to `OperationContext` that the
383
+ * link's `retry` reads, is left to the link.
384
+ * @example client.post.byId.query(input, { context: { retry: (opts) => opts.attempts <= 3 } })
385
+ */
386
+ retry?: RetryFn<TInferrable> | ('retry' extends keyof TAugmented ? TAugmented['retry'] : never);
387
+ };
301
388
  interface RetryLinkOptions<TInferrable extends InferrableClientTypes> {
302
389
  /**
303
- * The retry function
390
+ * The retry function. A call's `context.retry` replaces it for that call.
304
391
  */
305
- retry: (opts: RetryFnOptions<TInferrable>) => boolean;
392
+ retry: RetryFn<TInferrable>;
306
393
  /**
307
394
  * The delay between retries in ms (defaults to 0)
308
395
  */
309
396
  retryDelayMs?: (attempt: number) => number;
310
397
  }
311
- interface RetryFnOptions<TInferrable extends InferrableClientTypes> {
398
+ /**
399
+ * What a `retry` function is given.
400
+ * @public
401
+ */
402
+ export interface RetryFnOptions<TInferrable extends InferrableClientTypes> {
312
403
  /**
313
404
  * The operation that failed
314
405
  */
@@ -324,11 +415,13 @@ interface RetryFnOptions<TInferrable extends InferrableClientTypes> {
324
415
  }
325
416
  /**
326
417
  * Retries failed operations. Subscriptions resume from the last tracked event
327
- * id.
418
+ * id. A call can pass its own `retry` in `context`.
328
419
  *
329
420
  * @see https://trpc.io/docs/client/links/retryLink
330
421
  */
331
- export declare function retryLink<TInferrable extends InferrableClientTypes>(opts: RetryLinkOptions<TInferrable>): TRPCLink<TInferrable>;
422
+ export declare function retryLink<TInferrable extends InferrableClientTypes>(opts: RetryLinkOptions<TInferrable>): TRPCLink<TInferrable, {
423
+ context: RetryLinkContext<TInferrable>;
424
+ }>;
332
425
  /**
333
426
  * Passed to {@link LocalLinkOptions.createContext}.
334
427
  */
@@ -374,7 +467,9 @@ export type LocalLinkOptions<TRouter extends AnyRouter> = {
374
467
  *
375
468
  * @see https://trpc.io/docs/client/links/localLink
376
469
  */
377
- export declare function localLink<TRouter extends AnyRouter>(opts: LocalLinkOptions<TRouter>): TRPCLink<TRouter>;
470
+ export declare function localLink<TRouter extends AnyRouter>(opts: LocalLinkOptions<TRouter>): TRPCLink<TRouter, {
471
+ context: {};
472
+ }>;
378
473
  /**
379
474
  * @deprecated Use {@link localLink} instead.
380
475
  * @function
@@ -385,5 +480,5 @@ export declare const unstable_localLink: typeof localLink;
385
480
  * future major release.
386
481
  */
387
482
  export declare const experimental_localLink: typeof localLink;
388
- export { type CreateTRPCClientOptions, type Encoder, HTTPBatchLinkOptions, HTTPHeaders, HTTPLinkOptions, LoggerLinkOptions, Operation, OperationContext, OperationLink, OperationResultEnvelope, OperationResultObservable, OperationResultObserver, type SafeResult, TRPCClientError, TRPCClientErrorBase, TRPCClientErrorLike, TRPCClientRuntime, TRPCFetch, TRPCLink, type TRPCProcedureOptions, type TRPCTaggedPromise as TRPCPromise, type TRPCRequestOptions, type TRPCWebSocketClient, type WebSocketClientOptions, WebSocketLinkOptions, createTRPCClient as createTRPCProxyClient, createWSClient, httpBatchLink, httpLink, type inferRouterClient as inferRouterProxyClient, isTRPCClientError, jsonEncoder, loggerLink, splitLink, wsLink };
483
+ export { AugmentedOperationContext, type CreateTRPCClientOptions, type Encoder, HTTPBatchLinkOptions, HTTPHeaders, HTTPLinkOptions, LinkDecl, LoggerLinkOptions, NoLinkReadsContext, Operation, OperationContext, OperationLink, OperationResultEnvelope, OperationResultObservable, OperationResultObserver, type SafeResult, TRPCClientError, TRPCClientErrorBase, TRPCClientErrorLike, TRPCClientRuntime, TRPCFetch, TRPCLink, type TRPCProcedureOptions, type TRPCTaggedPromise as TRPCPromise, type TRPCRequestOptions, type TRPCWebSocketClient, type WebSocketClientOptions, WebSocketLinkOptions, createTRPCClient as createTRPCProxyClient, createWSClient, httpBatchLink, httpLink, inferLinksContext, inferLinksDeclaredContext, type inferRouterClient as inferRouterProxyClient, isTRPCClientError, jsonEncoder, loggerLink, splitLink, wsLink };
389
484
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":["AnyRouter"],"sources":["../src/links/internals/contentTypes.ts","../src/internals/TRPCUntypedClient.ts","../src/createTRPCUntypedClient.ts","../src/safe.ts","../src/createTRPCClient.ts","../src/getFetch.ts","../src/links/httpBatchStreamLink.ts","../src/links/httpSubscriptionLink.ts","../src/links/retryLink.ts","../src/links/localLink.ts"],"mappings":";;;;;;;;;;;;;wBACgB,YACd,iBACC,SAAS,WAAW,eAAe;;wBAStB,WAAW,iBAAc,SAAA;;;;;;wBASzB,sBAAsB,iBAAc,SAAA,OAAA,WAAA,WAAA;;UCQnC;;;;;EAKf,UAAU;;;;;EAKV,SAAS;;;UAIM,yBAAyB,QAAQ;;EAEhD,YAAY;IAAQ,SAAS;;;EAE7B,SAAS,OAAO,wBAAwB;;EAExC,UAAU,KAAK;;;;;EAKf;;EAEA;;EAEA,0BAA0B,OAAO,oBAAoB;;KAGlD,oBAAoB;;;;;;KAOb,iCAAiC,SAAS,WAEnD,QAAQ,6BAER,cAAc,QAAQ;;;;;KAOb,0BAA0B,QAAQ,UAAU,QACtD,yBAAyB,QAAQ,cAG9B,QAAQ,cAAc,KAAK,yBAAyB,QAAQ,SAAS,SACtE;;;;;KAeQ,wBAAwB,gBAAgB;;;;;;EAMlD,OAAO,SAAS;EAChB,cAAc;;;;;;qBAOH,kBAAkB,oBAAoB;mBAChC;WACD,SAAS;UACjB;EAER,YAAY,MAAM,wBAAwB;UASlC;UAkBM;;EAmBP,MAAM,cAAc,iBAAiB,OAAO,qBAAkB;;EAU9D,SAAS,cAAc,iBAAiB,OAAO,qBAAkB;;;;;;;EAejE,aACL,cACA,gBACA,MAAM,mCAAmC,gBAAgB,cACvD,qBACD;EACI,aACL,cAAc,qBACZ,QAAQ,kCAAkC,gBAAgB,eAC1D,oBAEF,cACA,gBACA,OAAO,iCAAiC,SACvC;;;;;;wBCnMW,wBAAwB,gBAAgB,WACtD,MAAM,wBAAwB,WAC7B,kBAAkB;;;;cCLA;;;;;KAMT,kBAAkB,OAAO,eAAe,QAAQ;YAChD,gBAAgB;;;;;KAMhB,eAAe,eAAe;EACxC,YAAY;EACZ;;;;;;KAOU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wBAWE,iBAAiB,gBAAgB,WAC/C,QAAQ,WAAW,WAClB,kBAAkB;;;;;wBCpNL,SACd,kBAAkB,aAAa,mBAC9B;;;;;;;YCkBS,2BAA2B,cAAc,kBACnD,qBAAqB;;;;;;;EAOnB;;;;;;;;wBAeY,oBAAoB,gBAAgBA,aAClD,MAAM,2BAA2B,wCAChC,SAAS;;;;qBA0NC,qCAA4B;;;;KCrOpC,4BACH,cAAc,gBACd,qBAAqB,gBAAgB,wBAAwB;;;;;EAM7D,cAAc;;;;;EAKd,qBACI,gBAAgB,WAAW,kBACzB;IACA,IAAI;QAEF,gBAAgB,WAAW,gBAC3B,QAAQ,gBAAgB,WAAW;IACzC,KAAK,oBAAoB,2BAC3B,mBAAmB,SACnB;;;;;;wBAOc,qBACd,oBAAoB,uBACpB,qBAAqB,gBAAgB,gBAErC,MAAM,4BACJ,iBAAiB,cACjB,gBAED,SAAS;;;;qBA4KC,sCAA6B;UCpPhC,iBAAiB,oBAAoB;;;;EAI7C,QAAQ,MAAM,eAAe;;;;EAI7B,gBAAgB;;UAGR,eAAe,oBAAoB;;;;EAI3C,IAAI;;;;EAIJ,OAAO,gBAAgB;;;;EAIvB;;;;;;;;wBASc,UAAU,oBAAoB,uBAC5C,MAAM,iBAAiB,eACtB,SAAS;;;;YCHA;;;;;EAKV;;;;;IAKE,QAAQ;;;;;;;;YASA,iBAAiB,gBAAgB;;;;;EAK3C,QAAQ;;;;;;EAMR,gBACE,MAAM,kCACH,QAAQ,mBAAmB;;;;;EAKhC,WAAW,MAAM,oBAAoB,mBAAmB;IACtD,mBAAmB,iBAAiB;;;;;;;wBAQxB,UAAU,gBAAgB,WACxC,MAAM,iBAAiB,WACtB,SAAS;;;;;qBAqQC,2BAAkB;;;;;qBAMlB,+BAAsB"}
1
+ {"version":3,"file":"index.d.mts","names":["AnyRouter"],"sources":["../src/links/internals/contentTypes.ts","../src/internals/TRPCUntypedClient.ts","../src/createTRPCUntypedClient.ts","../src/routerType.ts","../src/safe.ts","../src/createTRPCClient.ts","../src/getFetch.ts","../src/links/httpBatchStreamLink.ts","../src/links/httpSubscriptionLink.ts","../src/links/retryLink.ts","../src/links/localLink.ts"],"mappings":";;;;;;;;;;;;;wBACgB,YACd,iBACC,SAAS,WAAW,eAAe;;wBAStB,WAAW,iBAAc,SAAA;;;;;;wBASzB,sBAAsB,iBAAc,SAAA,OAAA,WAAA,WAAA;;UCQnC;;;;;EAKf,UAAU;;;;;EAKV,SAAS;;;UAIM,yBAAyB,QAAQ;;EAEhD,YAAY;IAAQ,SAAS;;;EAE7B,SAAS,OAAO,wBAAwB;;EAExC,UAAU,KAAK;;;;;EAKf;;EAEA;;EAEA,0BAA0B,OAAO,oBAAoB;;KAGlD,oBAAoB;;;;;;KAOb,iCAAiC,SAAS,WAEnD,QAAQ,6BAER,cAAc,QAAQ;;;;;KAOb,0BAA0B,QAAQ,UAAU,QACtD,yBAAyB,QAAQ,cAG9B,QAAQ,cAAc,KAAK,yBAAyB,QAAQ,SAAS,SACtE;;;;;KAeQ,wBAAwB,gBAAgB;;;;;;EAMlD,OAAO,SAAS;EAChB,cAAc;;;;;;qBAOH,kBAAkB,oBAAoB;mBAChC;WACD,SAAS;UACjB;EAER,YAAY,MAAM,wBAAwB;UASlC;UAkBM;;EAmBP,MAAM,cAAc,iBAAiB,OAAO,qBAAkB;;EAU9D,SAAS,cAAc,iBAAiB,OAAO,qBAAkB;;;;;;;EAejE,aACL,cACA,gBACA,MAAM,mCAAmC,gBAAgB,cACvD,qBACD;EACI,aACL,cAAc,qBACZ,QAAQ,kCAAkC,gBAAgB,eAC1D,oBAEF,cACA,gBACA,OAAO,iCAAiC,SACvC;;;;;;wBCnMW,wBAAwB,gBAAgB,WACtD,MAAM,wBAAwB,WAC7B,kBAAkB;cCRP;;;;;;iBAOG,WAAW,gBAAgB;YAChC,kBAAkB;;;;;;;;;;;;;;;;;wBAkBd,WAAW,gBAAgB,cAAc,WAAW;;;;cCvB/C;;;;;KAMT,kBAAkB,OAAO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oB;;;;EAI7C,OAAO,QAAQ;;;;EAIf,gBAAgB;;;;;;iBAOD,eAAe,oBAAoB;;;;EAIlD,IAAI;;;;EAIJ,OAAO,gBAAgB;;;;EAIvB;;;;;;;;wBASc,UAAU,oBAAoB,uBAC5C,MAAM,iBAAiB,eACtB,SAAS;EAAe,SAAS,iBAAiB;;;;;YChCzC;;;;;EAKV;;;;;IAKE,QAAQ;;;;;;;;YASA,iBAAiB,gBAAgB;;;;;EAK3C,QAAQ;;;;;;EAMR,gBACE,MAAM,kCACH,QAAQ,mBAAmB;;;;;EAKhC,WAAW,MAAM,oBAAoB,mBAAmB;IACtD,mBAAmB,iBAAiB;;;;;;;wBAQxB,UAAU,gBAAgB,WACxC,MAAM,iBAAiB,WACtB,SAAS;EAAW;;;;;;qBAqQV,2BAAkB;;;;;qBAMlB,+BAAsB"}
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { n as createChain, t as splitLink } from "./splitLink-PFsRy7Mf.mjs";
1
+ import { n as createChain, t as splitLink } from "./splitLink-C8U8vvLl.mjs";
2
2
  import { n as isTRPCClientError, t as TRPCClientError } from "./TRPCClientError-DE6-fd1n.mjs";
3
3
  import { n as _defineProperty, t as _objectSpread2 } from "./objectSpread2-pyA4QVO4.mjs";
4
4
  import { c as allAbortSignals, d as throwIfAborted, f as getFetch, l as raceAbortSignals, n as getBody, o as resolveHTTPLinkOptions, r as getUrl, s as abortSignalToPromise, t as fetchHTTPResponse, u as raceAbortSignalsWithCleanup } from "./httpUtils-HxB0aY5z.mjs";
@@ -168,20 +168,8 @@ function createTRPCClientProxy(client) {
168
168
  return proxy[key];
169
169
  });
170
170
  }
171
- /**
172
- * Creates a typed client for a router. Pass the router's type, and the
173
- * links that send its calls.
174
- * @example
175
- * ```ts
176
- * const client = createTRPCClient<AppRouter>({
177
- * links: [httpBatchLink({ url: 'http://localhost:3000/trpc' })],
178
- * });
179
- * const post = await client.post.byId.query({ id: '1' });
180
- * ```
181
- * @see https://trpc.io/docs/client/vanilla/setup#3-initialize-the-trpc-client
182
- */
183
171
  function createTRPCClient(opts) {
184
- return createTRPCClientProxy(new TRPCUntypedClient(opts));
172
+ return createTRPCClientProxy(new TRPCUntypedClient({ links: [...opts.links] }));
185
173
  }
186
174
  /**
187
175
  * The untyped client behind a typed client, which calls procedures by
@@ -191,6 +179,25 @@ function createTRPCClient(opts) {
191
179
  function getUntypedClient(client) {
192
180
  return client[untypedClientSymbol];
193
181
  }
182
+ // src/routerType.ts
183
+ /**
184
+ * Passes a router's type to `createTRPCClient({ router })` as a normal
185
+ * option, instead of a type argument. Nothing about the router exists at
186
+ * runtime, so it's safe to import the router's type only.
187
+ *
188
+ * @example
189
+ * ```ts
190
+ * const client = createTRPCClient({
191
+ * router: routerType<AppRouter>(),
192
+ * links: [httpBatchLink({ url: 'http://localhost:3000/trpc' })],
193
+ * });
194
+ * ```
195
+ * @see https://trpc.io/docs/client/vanilla/setup#3-initialize-the-trpc-client
196
+ * @public
197
+ */
198
+ function routerType() {
199
+ return {};
200
+ }
194
201
  // src/links/httpBatchStreamLink.ts
195
202
  /**
196
203
  * A terminating link that batches calls like `httpBatchLink`, but streams each
@@ -534,7 +541,7 @@ const unstable_httpSubscriptionLink = httpSubscriptionLink;
534
541
  /* istanbul ignore file -- @preserve */
535
542
  /**
536
543
  * Retries failed operations. Subscriptions resume from the last tracked event
537
- * id.
544
+ * id. A call can pass its own `retry` in `context`.
538
545
  *
539
546
  * @see https://trpc.io/docs/client/links/retryLink
540
547
  */
@@ -560,7 +567,8 @@ function retryLink(opts) {
560
567
  const subscription = callOpts.next(op).subscribe({
561
568
  error(error) {
562
569
  var _opts$retryDelayMs, _opts$retryDelayMs2;
563
- const shouldRetry = opts.retry({
570
+ const callRetry = op.context["retry"];
571
+ const shouldRetry = (typeof callRetry === "function" ? callRetry : opts.retry)({
564
572
  op,
565
573
  attempts,
566
574
  error
@@ -928,6 +936,6 @@ async function safe(promise) {
928
936
  return [void 0, cause];
929
937
  }
930
938
  }
931
- export { TRPCClientError, TRPCUntypedClient, clientCallTypeToProcedureType, createTRPCClient, createTRPCClient as createTRPCProxyClient, createTRPCClientProxy, createTRPCUntypedClient, createWSClient, experimental_localLink, getFetch, getUntypedClient, httpBatchLink, httpBatchStreamLink, httpLink, httpSubscriptionLink, isFormData, isNonJsonSerializable, isOctetType, isTRPCClientError, jsonEncoder, localLink, loggerLink, retryLink, safe, splitLink, unstable_httpBatchStreamLink, unstable_httpSubscriptionLink, unstable_localLink, wsLink };
939
+ export { TRPCClientError, TRPCUntypedClient, clientCallTypeToProcedureType, createTRPCClient, createTRPCClient as createTRPCProxyClient, createTRPCClientProxy, createTRPCUntypedClient, createWSClient, experimental_localLink, getFetch, getUntypedClient, httpBatchLink, httpBatchStreamLink, httpLink, httpSubscriptionLink, isFormData, isNonJsonSerializable, isOctetType, isTRPCClientError, jsonEncoder, localLink, loggerLink, retryLink, routerType, safe, splitLink, unstable_httpBatchStreamLink, unstable_httpSubscriptionLink, unstable_localLink, wsLink };
932
940
 
933
941
  //# sourceMappingURL=index.mjs.map