@trpc/client 11.32.1 → 11.33.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 (76) hide show
  1. package/dist/httpBatchLink-DRitkRBC.mjs.map +1 -1
  2. package/dist/{httpBatchLink-DbD4ZGAM.d.cts → httpBatchLink-DaVHWlLU.d.mts} +6 -4
  3. package/dist/{httpBatchLink-DbD4ZGAM.d.cts.map → httpBatchLink-DaVHWlLU.d.mts.map} +1 -1
  4. package/dist/{httpBatchLink-Dk3_n5pP.d.mts → httpBatchLink-_bkMj4mk.d.cts} +6 -4
  5. package/dist/{httpBatchLink-Dk3_n5pP.d.mts.map → httpBatchLink-_bkMj4mk.d.cts.map} +1 -1
  6. package/dist/httpLink-Cmg_mV7L.mjs.map +1 -1
  7. package/dist/{httpLink-BjZdBzr6.d.mts → httpLink-DN_Ana7a.d.mts} +6 -4
  8. package/dist/httpLink-DN_Ana7a.d.mts.map +1 -0
  9. package/dist/{httpUtils-CxgZ3W-1.d.cts → httpUtils-1z6dzl3V.d.cts} +2 -2
  10. package/dist/{httpUtils-CxgZ3W-1.d.cts.map → httpUtils-1z6dzl3V.d.cts.map} +1 -1
  11. package/dist/{httpUtils-gZ7bAQ6T.d.mts → httpUtils-BAs5frdP.d.mts} +2 -2
  12. package/dist/{httpUtils-gZ7bAQ6T.d.mts.map → httpUtils-BAs5frdP.d.mts.map} +1 -1
  13. package/dist/index.cjs +22 -14
  14. package/dist/index.d.cts +93 -21
  15. package/dist/index.d.cts.map +1 -1
  16. package/dist/index.d.mts +96 -24
  17. package/dist/index.d.mts.map +1 -1
  18. package/dist/index.mjs +22 -15
  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 +21 -8
  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-CiVinJOG.d.mts} +5 -3
  37. package/dist/loggerLink-CiVinJOG.d.mts.map +1 -0
  38. package/dist/{splitLink-BBLj14Dv.cjs → splitLink-BQoYcpdp.cjs} +3 -0
  39. package/dist/splitLink-ClFN_nbg.d.mts +35 -0
  40. package/dist/splitLink-ClFN_nbg.d.mts.map +1 -0
  41. package/dist/{splitLink-PFsRy7Mf.mjs → splitLink-IUbsOwO6.mjs} +4 -1
  42. package/dist/splitLink-IUbsOwO6.mjs.map +1 -0
  43. package/dist/{types-BhHxuBsu.d.cts → types-DMe6B4SV.d.cts} +65 -8
  44. package/dist/types-DMe6B4SV.d.cts.map +1 -0
  45. package/dist/{types-BG-3kpeg.d.mts → types-DW0iJUBU.d.mts} +65 -8
  46. package/dist/types-DW0iJUBU.d.mts.map +1 -0
  47. package/dist/wsLink-C_Zg2yXV.mjs.map +1 -1
  48. package/dist/{wsLink-DU5wj6kH.d.mts → wsLink-DX5fv7-H.d.mts} +5 -3
  49. package/dist/{wsLink-BlAMQb0i.d.cts.map → wsLink-DX5fv7-H.d.mts.map} +1 -1
  50. package/dist/{wsLink-BlAMQb0i.d.cts → wsLink-DuyXOEPt.d.cts} +5 -3
  51. package/dist/{wsLink-DU5wj6kH.d.mts.map → wsLink-DuyXOEPt.d.cts.map} +1 -1
  52. package/package.json +3 -3
  53. package/skills/client-setup/SKILL.md +1 -1
  54. package/skills/links/SKILL.md +58 -1
  55. package/skills/superjson/SKILL.md +1 -1
  56. package/src/createTRPCClient.ts +88 -21
  57. package/src/index.ts +1 -0
  58. package/src/internals/types.ts +8 -5
  59. package/src/links/httpBatchLink.ts +6 -2
  60. package/src/links/httpBatchStreamLink.ts +6 -2
  61. package/src/links/httpLink.ts +6 -1
  62. package/src/links/httpSubscriptionLink.ts +6 -2
  63. package/src/links/localLink.ts +1 -1
  64. package/src/links/loggerLink.ts +11 -2
  65. package/src/links/retryLink.ts +6 -2
  66. package/src/links/splitLink.ts +52 -10
  67. package/src/links/types.ts +109 -3
  68. package/src/links/wsLink/wsLink.ts +1 -1
  69. package/src/routerType.ts +31 -0
  70. package/dist/httpLink-BjZdBzr6.d.mts.map +0 -1
  71. package/dist/loggerLink-CBPx95zm.d.mts.map +0 -1
  72. package/dist/splitLink-BtPz7lCB.d.mts +0 -23
  73. package/dist/splitLink-BtPz7lCB.d.mts.map +0 -1
  74. package/dist/splitLink-PFsRy7Mf.mjs.map +0 -1
  75. package/dist/types-BG-3kpeg.d.mts.map +0 -1
  76. package/dist/types-BhHxuBsu.d.cts.map +0 -1
@@ -0,0 +1,35 @@
1
+ import { a as Operation, h as inferLinksDeclaredContext, p as TRPCLink, t as AugmentedOperationContext } from "./types-DW0iJUBU.mjs";
2
+ import { AnyRouter } from "@trpc/server/unstable-core-do-not-import";
3
+ /**
4
+ * A `splitLink` branch: one link or a chain of them.
5
+ * @internal
6
+ */
7
+ type SplitLinkBranch<TRouter extends AnyRouter> = TRPCLink<TRouter, any> | readonly TRPCLink<TRouter, any>[];
8
+ type asLinks<TBranch> = TBranch extends readonly unknown[] ? TBranch : [TBranch];
9
+ interface SplitLinkOptions<TRouter extends AnyRouter, TTrue extends SplitLinkBranch<TRouter>, TFalse extends SplitLinkBranch<TRouter>> {
10
+ /**
11
+ * Picks the chain for an operation.
12
+ */
13
+ condition: (op: Operation) => boolean;
14
+ /**
15
+ * The link to execute next if the test function returns `true`.
16
+ */
17
+ true: TTrue;
18
+ /**
19
+ * The link to execute next if the test function returns `false`.
20
+ */
21
+ false: TFalse;
22
+ }
23
+ /**
24
+ * Sends each operation down one of two link chains, based on `condition`.
25
+ *
26
+ * Calls take the `context` both chains read. `condition` may read the
27
+ * fields added to `OperationContext`.
28
+ *
29
+ * @see https://trpc.io/docs/client/links/splitLink
30
+ */
31
+ declare function splitLink<TRouter extends AnyRouter = AnyRouter, const TTrue extends SplitLinkBranch<TRouter> = SplitLinkBranch<TRouter>, const TFalse extends SplitLinkBranch<TRouter> = SplitLinkBranch<TRouter>>(opts: SplitLinkOptions<TRouter, TTrue, TFalse>): TRPCLink<TRouter, {
32
+ context: AugmentedOperationContext & inferLinksDeclaredContext<[...asLinks<TTrue>, ...asLinks<TFalse>]>;
33
+ }>;
34
+ export { splitLink as t };
35
+ //# sourceMappingURL=splitLink-ClFN_nbg.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"splitLink-ClFN_nbg.d.mts","names":[],"sources":["../src/links/splitLink.ts"],"mappings":";;;;;;KAkBK,gBAAgB,gBAAgB,aACjC,SAAS,yBACA,SAAS;KAGjB,QAAQ,WAAW,qCACpB,WACC;UAEK,iBACR,gBAAgB,WAChB,cAAc,gBAAgB,UAC9B,eAAe,gBAAgB;;;;EAK/B,YAAY,IAAI;;;;EAIhB,MAAM;;;;EAIN,OAAO;;;;;;;;;;iBAWO,UACd,gBAAgB,YAAY,iBAEtB,cAAc,gBAAgB,WAAW,gBAAgB,gBACzD,eAAe,gBAAgB,WAAW,gBAAgB,UAEhE,MAAM,iBAAiB,SAAS,OAAO,UACtC,SACD;EAGE,SAAS,4BACP,8BAA8B,QAAQ,WAAW,QAAQ"}
@@ -23,6 +23,9 @@ function asArray(value) {
23
23
  /**
24
24
  * Sends each operation down one of two link chains, based on `condition`.
25
25
  *
26
+ * Calls take the `context` both chains read. `condition` may read the
27
+ * fields added to `OperationContext`.
28
+ *
26
29
  * @see https://trpc.io/docs/client/links/splitLink
27
30
  */
28
31
  function splitLink(opts) {
@@ -42,4 +45,4 @@ function splitLink(opts) {
42
45
  }
43
46
  export { createChain as n, splitLink as t };
44
47
 
45
- //# sourceMappingURL=splitLink-PFsRy7Mf.mjs.map
48
+ //# sourceMappingURL=splitLink-IUbsOwO6.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"splitLink-IUbsOwO6.mjs","names":[],"sources":["../src/links/internals/createChain.ts","../src/links/splitLink.ts"],"sourcesContent":["import { observable } from '@trpc/server/observable';\nimport type { AnyRouter } from '@trpc/server/unstable-core-do-not-import';\nimport type {\n Operation,\n OperationLink,\n OperationResultObservable,\n} from '../types';\n\n/** @internal */\nexport function createChain<\n TRouter extends AnyRouter,\n TInput = unknown,\n TOutput = unknown,\n>(opts: {\n links: OperationLink<TRouter, TInput, TOutput>[];\n op: Operation<TInput>;\n}): OperationResultObservable<TRouter, TOutput> {\n return observable((observer) => {\n function execute(index = 0, op = opts.op) {\n const next = opts.links[index];\n if (!next) {\n throw new Error(\n 'No more links to execute - did you forget to add an ending link?',\n );\n }\n const subscription = next({\n op,\n next(nextOp) {\n const nextObserver = execute(index + 1, nextOp);\n\n return nextObserver;\n },\n });\n return subscription;\n }\n\n const obs$ = execute();\n return obs$.subscribe(observer);\n });\n}\n","import { observable } from '@trpc/server/observable';\nimport type { AnyRouter } from '@trpc/server/unstable-core-do-not-import';\nimport { createChain } from './internals/createChain';\nimport type {\n AugmentedOperationContext,\n inferLinksDeclaredContext,\n Operation,\n TRPCLink,\n} from './types';\n\nfunction asArray<TType>(value: TType | readonly TType[]): readonly TType[] {\n return Array.isArray(value) ? value : [value as TType];\n}\n\n/**\n * A `splitLink` branch: one link or a chain of them.\n * @internal\n */\ntype SplitLinkBranch<TRouter extends AnyRouter> =\n | TRPCLink<TRouter, any>\n | readonly TRPCLink<TRouter, any>[];\n\n// a tuple, so links whose declarations nest aren't merged into one\ntype asLinks<TBranch> = TBranch extends readonly unknown[]\n ? TBranch\n : [TBranch];\n\ninterface SplitLinkOptions<\n TRouter extends AnyRouter,\n TTrue extends SplitLinkBranch<TRouter>,\n TFalse extends SplitLinkBranch<TRouter>,\n> {\n /**\n * Picks the chain for an operation.\n */\n condition: (op: Operation) => boolean;\n /**\n * The link to execute next if the test function returns `true`.\n */\n true: TTrue;\n /**\n * The link to execute next if the test function returns `false`.\n */\n false: TFalse;\n}\n\n/**\n * Sends each operation down one of two link chains, based on `condition`.\n *\n * Calls take the `context` both chains read. `condition` may read the\n * fields added to `OperationContext`.\n *\n * @see https://trpc.io/docs/client/links/splitLink\n */\nexport function splitLink<\n TRouter extends AnyRouter = AnyRouter,\n // with an explicit router type, a branch is still a link or an array\n const TTrue extends SplitLinkBranch<TRouter> = SplitLinkBranch<TRouter>,\n const TFalse extends SplitLinkBranch<TRouter> = SplitLinkBranch<TRouter>,\n>(\n opts: SplitLinkOptions<TRouter, TTrue, TFalse>,\n): TRPCLink<\n TRouter,\n {\n // `condition` may read the fields added to `OperationContext`\n context: AugmentedOperationContext &\n inferLinksDeclaredContext<[...asLinks<TTrue>, ...asLinks<TFalse>]>;\n }\n> {\n return (runtime) => {\n const yes = asArray(opts.true).map((link) => link(runtime));\n const no = asArray(opts.false).map((link) => link(runtime));\n return (props) => {\n return observable((observer) => {\n const links = opts.condition(props.op) ? yes : no;\n return createChain({ op: props.op, links }).subscribe(observer);\n });\n };\n };\n}\n"],"mappings":";;;AASA,SAAgB,YAId,MAG8C;CAC9C,OAAO,YAAY,aAAa;EAC9B,SAAS,QAAQ,QAAQ,GAAG,KAAK,KAAK,IAAI;GACxC,MAAM,OAAO,KAAK,MAAM;GACxB,IAAI,CAAC,MACH,MAAM,IAAI,MACR,kEACF;GAUF,OARqB,KAAK;IACxB;IACA,KAAK,QAAQ;KAGX,OAFqB,QAAQ,QAAQ,GAAG,MAEtB;IACpB;GACF,CACkB;EACpB;EAGA,OADa,QACH,CAAC,CAAC,UAAU,QAAQ;CAChC,CAAC;AACH;;AC7BA,SAAS,QAAe,OAAmD;CACzE,OAAO,MAAM,QAAQ,KAAK,IAAI,QAAQ,CAAC,KAAc;AACvD;;;;;;;;;AA0CA,SAAgB,UAMd,MAQA;CACA,QAAQ,YAAY;EAClB,MAAM,MAAM,QAAQ,KAAK,IAAI,CAAC,CAAC,KAAK,SAAS,KAAK,OAAO,CAAC;EAC1D,MAAM,KAAK,QAAQ,KAAK,KAAK,CAAC,CAAC,KAAK,SAAS,KAAK,OAAO,CAAC;EAC1D,QAAQ,UAAU;GAChB,OAAO,YAAY,aAAa;IAC9B,MAAM,QAAQ,KAAK,UAAU,MAAM,EAAE,IAAI,MAAM;IAC/C,OAAO,YAAY;KAAE,IAAI,MAAM;KAAI;IAAM,CAAC,CAAC,CAAC,UAAU,QAAQ;GAChE,CAAC;EACH;CACF;AACF"}
@@ -1,5 +1,5 @@
1
1
  import { t as TRPCConnectionState } from "./subscriptions-CvJnusYO.cjs";
2
- import { DefaultErrorShape, InferrableClientTypes, Maybe, TRPCErrorResponse, TRPCResultMessage, TRPCSuccessResponse, inferClientTypes } from "@trpc/server/unstable-core-do-not-import";
2
+ import { DefaultErrorShape, InferrableClientTypes, Maybe, Simplify, TRPCErrorResponse, TRPCResultMessage, TRPCSuccessResponse, inferClientTypes } from "@trpc/server/unstable-core-do-not-import";
3
3
  import { Observable, Observer } from "@trpc/server/observable";
4
4
  /**
5
5
  * A subset of the standard fetch function type needed by tRPC internally.
@@ -71,18 +71,18 @@ interface ResponseEsque {
71
71
  * @internal
72
72
  */
73
73
  type NonEmptyArray<TItem> = [TItem, ...TItem[]];
74
- type ClientContext = Record<string, unknown>;
75
74
  /**
76
75
  * The options of a call made with the client, such as
77
- * `client.post.byId.query(input, opts)`.
76
+ * `client.post.byId.query(input, opts)`. `TContext` is what the client's
77
+ * links read, when it was created with `router: routerType<AppRouter>()`.
78
78
  * @public
79
79
  */
80
- interface TRPCProcedureOptions {
80
+ interface TRPCProcedureOptions<TContext extends object = Record<string, unknown>> {
81
81
  /**
82
82
  * Context for the links, such as a flag a `splitLink` reads.
83
83
  * @see https://trpc.io/docs/client/links#managing-context
84
84
  */
85
- context?: ClientContext;
85
+ context?: TContext;
86
86
  /**
87
87
  * Aborts the call. With `httpBatchLink`, the request is only aborted once
88
88
  * every call in its batch is, so an aborted call can still get a result.
@@ -158,6 +158,14 @@ declare function isNonJsonSerializable(input: unknown): input is Blob | FormData
158
158
  * @internal
159
159
  */
160
160
  interface OperationContext extends Record<string, unknown> {}
161
+ /**
162
+ * The fields added to `OperationContext` with module augmentation, without
163
+ * its `[key: string]: unknown`. Links that hand the operation to your code
164
+ * declare these, so calls take only fields something declared.
165
+ * @see https://trpc.io/docs/client/links#managing-context
166
+ * @public
167
+ */
168
+ type AugmentedOperationContext = { [TKey in keyof OperationContext as string extends TKey ? never : TKey]: OperationContext[TKey]; };
161
169
  /**
162
170
  * A procedure call as it goes through the links.
163
171
  * @internal
@@ -214,12 +222,61 @@ type OperationLink<TInferrable extends InferrableClientTypes, TInput = unknown,
214
222
  op: Operation<TInput>;
215
223
  next: (op: Operation<TInput>) => OperationResultObservable<TInferrable, TOutput>;
216
224
  }) => OperationResultObservable<TInferrable, TOutput>;
225
+ /**
226
+ * What a link declares about itself, for clients created with
227
+ * `createTRPCClient({ router: routerType<AppRouter>(), links })`.
228
+ * @see https://trpc.io/docs/client/links#typing-call-options
229
+ * @public
230
+ */
231
+ interface LinkDecl {
232
+ /**
233
+ * The fields the link reads from `op.context`. Calls can pass them, typed,
234
+ * as `.query(input, { context })`. `{}` declares that the link reads none.
235
+ */
236
+ context?: object;
237
+ }
217
238
  /**
218
239
  * A link: a step every call goes through, such as logging or sending it
219
240
  * over HTTP. It's called once when the client is created.
241
+ *
242
+ * `TDecl` says what it reads from `op.context`. A link that doesn't
243
+ * declare it may read any context.
220
244
  * @see https://trpc.io/docs/client/links#creating-a-custom-link
221
245
  * @public
222
246
  */
223
- type TRPCLink<TInferrable extends InferrableClientTypes> = (opts: TRPCClientRuntime) => OperationLink<TInferrable>;
224
- export { isTRPCClientError as _, OperationResultEnvelope as a, NonEmptyArray as b, TRPCClientRuntime as c, isFormData as d, isNonJsonSerializable as f, TRPCClientErrorLike as g, TRPCClientErrorBase as h, OperationLink as i, TRPCFetch as l, TRPCClientError as m, Operation as n, OperationResultObservable as o, isOctetType as p, OperationContext as r, OperationResultObserver as s, HTTPHeaders as t, TRPCLink as u, FetchEsque as v, TRPCProcedureOptions as x, NativeFetchEsque as y };
225
- //# sourceMappingURL=types-BhHxuBsu.d.cts.map
247
+ type TRPCLink<TInferrable extends InferrableClientTypes, TDecl extends LinkDecl = LinkDecl> = ((opts: TRPCClientRuntime) => OperationLink<TInferrable>) & {
248
+ /** Type-only: what the link declares. Never set. */
249
+ readonly '~decl'?: TDecl;
250
+ };
251
+ type UnionToIntersection<TUnion> = (TUnion extends any ? (arg: TUnion) => void : never) extends ((arg: infer TIntersection) => void) ? TIntersection : never;
252
+ type inferLinkDecl<TLink> = TLink extends unknown ? '~decl' extends keyof TLink ? NonNullable<TLink['~decl' & keyof TLink]> : LinkDecl : never;
253
+ type inferDeclContext<TDecl> = TDecl extends unknown ? LinkDecl extends TDecl ? OperationContext : TDecl extends {
254
+ context: infer $Context;
255
+ } ? $Context : {} : never;
256
+ declare const noLinkReadsContext: unique symbol;
257
+ /**
258
+ * The call options' `context` when no link reads one: passing any field is
259
+ * an error.
260
+ * @public
261
+ */
262
+ type NoLinkReadsContext = {
263
+ readonly [noLinkReadsContext]?: never;
264
+ };
265
+ /**
266
+ * The fields the links in `TLinks` declare they read, merged, for a link
267
+ * that wraps other links to declare.
268
+ * @public
269
+ */
270
+ type inferLinksDeclaredContext<TLinks extends readonly unknown[]> = UnionToIntersection<TLinks[number] extends (infer $Link) ? $Link extends unknown ? {
271
+ context: inferDeclContext<inferLinkDecl<$Link>>;
272
+ } : never : never> extends {
273
+ context: infer $Context;
274
+ } ? $Context : {};
275
+ /**
276
+ * The `context` calls can pass: the fields every link in `TLinks` reads,
277
+ * merged.
278
+ * @public
279
+ */
280
+ type inferLinksContext<TLinks extends readonly unknown[]> = inferLinksDeclaredContext<TLinks> extends (infer $Context) ? $Context extends unknown ? keyof $Context extends never ? NoLinkReadsContext : Simplify<Partial<$Context>> : never : never;
281
+ export { FetchEsque as C, TRPCProcedureOptions as E, isTRPCClientError as S, NonEmptyArray as T, isNonJsonSerializable as _, Operation as a, TRPCClientErrorBase as b, OperationResultEnvelope as c, TRPCClientRuntime as d, TRPCFetch as f, isFormData as g, inferLinksDeclaredContext as h, NoLinkReadsContext as i, OperationResultObservable as l, inferLinksContext as m, HTTPHeaders as n, OperationContext as o, TRPCLink as p, LinkDecl as r, OperationLink as s, AugmentedOperationContext as t, OperationResultObserver as u, isOctetType as v, NativeFetchEsque as w, TRPCClientErrorLike as x, TRPCClientError as y };
282
+ //# sourceMappingURL=types-DMe6B4SV.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-DMe6B4SV.d.cts","names":[],"sources":["../src/internals/types.ts","../src/TRPCClientError.ts","../src/links/internals/contentTypes.ts","../src/links/types.ts"],"mappings":";;;;;;;;;;KAOY,cACV,OAAO,cAAc,cACrB,OAAO,cAAc,qBAClB,QAAQ;;;;;KAMD,oBACV,KAAK,cACL,OAAO,8BACJ,QAAQ;UAEI;EACf;;;;;;;;;UAUe;;;;EAIf,OAAO,2BAA2B,WAAW,eAAe,OAAO;;;;EAKnE,+BAA+B;;;;EAK/B;;;;EAKA,SAAS;;;;;;KAOC;EACV,iBAAiB,4BAA4B;;KAGnC;EACV,GACE,4BACA,cAAc,uBACb;;;;;;UAOY;WACN;WACA,OAAO,4BAA4B;;;;;;;EAO5C,QAAQ;;;;;KAME,cAAc,UAAU,UAAU;;;;;;;UAU7B,qBACf,0BAA0B;;;;;EAM1B,UAAU;;;;;;EAMV,SAAS;;KCpGN,gBAAgB,oBAAoB,yBACvC,iBAAiB;;UAEF,oBAAoB,eAAe;WACzC;;WAEA,OAAO,MAAM;;WAEb,MAAM,MAAM;;;;;;;KAOX,oBAAoB,oBAAoB,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AAM,sBAAsB,cAAc;;WAErC,UAAU;;KAGhB,oBAAoB,WACvB,sBAAsB,KAAK,mCAClB,WAAW,0BAClB;KAKC,cAAc,SAAS,8CACF,QACpB,YAAY,sBAAsB,UAClC;KAGD,iBAAiB,SAAS,wBAE3B,iBAAiB,QACf,mBACA;EAAgB,eAAe;IAC7B;cAIM;;;;;;KAUF;YACA;;;;;;;KAQA,0BAA0B,qCAGpC,oBACE,8BAA6B,SACzB;EACI,SAAS,iBAAiB,cAAc;;EAGtC,eAAe;IACvB;;;;;;KAQM,kBAAkB,qCAC5B,0BAA0B,uBAAsB,YAE5C,iCACQ,yBACJ,qBAEA,SAAS,QAAQ"}
@@ -1,6 +1,6 @@
1
1
  import { t as TRPCConnectionState } from "./subscriptions-CvJnusYO.mjs";
2
2
  import { Observable, Observer } from "@trpc/server/observable";
3
- import { DefaultErrorShape, InferrableClientTypes, Maybe, TRPCErrorResponse, TRPCResultMessage, TRPCSuccessResponse, inferClientTypes } from "@trpc/server/unstable-core-do-not-import";
3
+ import { DefaultErrorShape, InferrableClientTypes, Maybe, Simplify, TRPCErrorResponse, TRPCResultMessage, TRPCSuccessResponse, inferClientTypes } from "@trpc/server/unstable-core-do-not-import";
4
4
  /**
5
5
  * A subset of the standard fetch function type needed by tRPC internally.
6
6
  * @see fetch from lib.dom.d.ts
@@ -71,18 +71,18 @@ interface ResponseEsque {
71
71
  * @internal
72
72
  */
73
73
  type NonEmptyArray<TItem> = [TItem, ...TItem[]];
74
- type ClientContext = Record<string, unknown>;
75
74
  /**
76
75
  * The options of a call made with the client, such as
77
- * `client.post.byId.query(input, opts)`.
76
+ * `client.post.byId.query(input, opts)`. `TContext` is what the client's
77
+ * links read, when it was created with `router: routerType<AppRouter>()`.
78
78
  * @public
79
79
  */
80
- interface TRPCProcedureOptions {
80
+ interface TRPCProcedureOptions<TContext extends object = Record<string, unknown>> {
81
81
  /**
82
82
  * Context for the links, such as a flag a `splitLink` reads.
83
83
  * @see https://trpc.io/docs/client/links#managing-context
84
84
  */
85
- context?: ClientContext;
85
+ context?: TContext;
86
86
  /**
87
87
  * Aborts the call. With `httpBatchLink`, the request is only aborted once
88
88
  * every call in its batch is, so an aborted call can still get a result.
@@ -148,6 +148,14 @@ declare class TRPCClientError<TRouterOrProcedure extends InferrableClientTypes>
148
148
  * @internal
149
149
  */
150
150
  interface OperationContext extends Record<string, unknown> {}
151
+ /**
152
+ * The fields added to `OperationContext` with module augmentation, without
153
+ * its `[key: string]: unknown`. Links that hand the operation to your code
154
+ * declare these, so calls take only fields something declared.
155
+ * @see https://trpc.io/docs/client/links#managing-context
156
+ * @public
157
+ */
158
+ type AugmentedOperationContext = { [TKey in keyof OperationContext as string extends TKey ? never : TKey]: OperationContext[TKey]; };
151
159
  /**
152
160
  * A procedure call as it goes through the links.
153
161
  * @internal
@@ -204,12 +212,61 @@ type OperationLink<TInferrable extends InferrableClientTypes, TInput = unknown,
204
212
  op: Operation<TInput>;
205
213
  next: (op: Operation<TInput>) => OperationResultObservable<TInferrable, TOutput>;
206
214
  }) => OperationResultObservable<TInferrable, TOutput>;
215
+ /**
216
+ * What a link declares about itself, for clients created with
217
+ * `createTRPCClient({ router: routerType<AppRouter>(), links })`.
218
+ * @see https://trpc.io/docs/client/links#typing-call-options
219
+ * @public
220
+ */
221
+ interface LinkDecl {
222
+ /**
223
+ * The fields the link reads from `op.context`. Calls can pass them, typed,
224
+ * as `.query(input, { context })`. `{}` declares that the link reads none.
225
+ */
226
+ context?: object;
227
+ }
207
228
  /**
208
229
  * A link: a step every call goes through, such as logging or sending it
209
230
  * over HTTP. It's called once when the client is created.
231
+ *
232
+ * `TDecl` says what it reads from `op.context`. A link that doesn't
233
+ * declare it may read any context.
210
234
  * @see https://trpc.io/docs/client/links#creating-a-custom-link
211
235
  * @public
212
236
  */
213
- type TRPCLink<TInferrable extends InferrableClientTypes> = (opts: TRPCClientRuntime) => OperationLink<TInferrable>;
214
- export { NonEmptyArray as _, OperationResultEnvelope as a, TRPCClientRuntime as c, TRPCClientError as d, TRPCClientErrorBase as f, NativeFetchEsque as g, FetchEsque as h, OperationLink as i, TRPCFetch as l, isTRPCClientError as m, Operation as n, OperationResultObservable as o, TRPCClientErrorLike as p, OperationContext as r, OperationResultObserver as s, HTTPHeaders as t, TRPCLink as u, TRPCProcedureOptions as v };
215
- //# sourceMappingURL=types-BG-3kpeg.d.mts.map
237
+ type TRPCLink<TInferrable extends InferrableClientTypes, TDecl extends LinkDecl = LinkDecl> = ((opts: TRPCClientRuntime) => OperationLink<TInferrable>) & {
238
+ /** Type-only: what the link declares. Never set. */
239
+ readonly '~decl'?: TDecl;
240
+ };
241
+ type UnionToIntersection<TUnion> = (TUnion extends any ? (arg: TUnion) => void : never) extends ((arg: infer TIntersection) => void) ? TIntersection : never;
242
+ type inferLinkDecl<TLink> = TLink extends unknown ? '~decl' extends keyof TLink ? NonNullable<TLink['~decl' & keyof TLink]> : LinkDecl : never;
243
+ type inferDeclContext<TDecl> = TDecl extends unknown ? LinkDecl extends TDecl ? OperationContext : TDecl extends {
244
+ context: infer $Context;
245
+ } ? $Context : {} : never;
246
+ declare const noLinkReadsContext: unique symbol;
247
+ /**
248
+ * The call options' `context` when no link reads one: passing any field is
249
+ * an error.
250
+ * @public
251
+ */
252
+ type NoLinkReadsContext = {
253
+ readonly [noLinkReadsContext]?: never;
254
+ };
255
+ /**
256
+ * The fields the links in `TLinks` declare they read, merged, for a link
257
+ * that wraps other links to declare.
258
+ * @public
259
+ */
260
+ type inferLinksDeclaredContext<TLinks extends readonly unknown[]> = UnionToIntersection<TLinks[number] extends (infer $Link) ? $Link extends unknown ? {
261
+ context: inferDeclContext<inferLinkDecl<$Link>>;
262
+ } : never : never> extends {
263
+ context: infer $Context;
264
+ } ? $Context : {};
265
+ /**
266
+ * The `context` calls can pass: the fields every link in `TLinks` reads,
267
+ * merged.
268
+ * @public
269
+ */
270
+ type inferLinksContext<TLinks extends readonly unknown[]> = inferLinksDeclaredContext<TLinks> extends (infer $Context) ? $Context extends unknown ? keyof $Context extends never ? NoLinkReadsContext : Simplify<Partial<$Context>> : never : never;
271
+ export { TRPCProcedureOptions as C, NonEmptyArray as S, TRPCClientErrorBase as _, Operation as a, FetchEsque as b, OperationResultEnvelope as c, TRPCClientRuntime as d, TRPCFetch as f, TRPCClientError as g, inferLinksDeclaredContext as h, NoLinkReadsContext as i, OperationResultObservable as l, inferLinksContext as m, HTTPHeaders as n, OperationContext as o, TRPCLink as p, LinkDecl as r, OperationLink as s, AugmentedOperationContext as t, OperationResultObserver as u, TRPCClientErrorLike as v, NativeFetchEsque as x, isTRPCClientError as y };
272
+ //# sourceMappingURL=types-DW0iJUBU.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-DW0iJUBU.d.mts","names":[],"sources":["../src/internals/types.ts","../src/TRPCClientError.ts","../src/links/types.ts"],"mappings":";;;;;;;;;;KAOY,cACV,OAAO,cAAc,cACrB,OAAO,cAAc,qBAClB,QAAQ;;;;;KAMD,oBACV,KAAK,cACL,OAAO,8BACJ,QAAQ;UAEI;EACf;;;;;;;;;UAUe;;;;EAIf,OAAO,2BAA2B,WAAW,eAAe,OAAO;;;;EAKnE,+BAA+B;;;;EAK/B;;;;EAKA,SAAS;;;;;;KAOC;EACV,iBAAiB,4BAA4B;;KAGnC;EACV,GACE,4BACA,cAAc,uBACb;;;;;;UAOY;WACN;WACA,OAAO,4BAA4B;;;;;;;EAO5C,QAAQ;;;;;KAME,cAAc,UAAU,UAAU;;;;;;;UAU7B,qBACf,0BAA0B;;;;;EAM1B,UAAU;;;;;;EAMV,SAAS;;KCpGN,gBAAgB,oBAAoB,yBACvC,iBAAiB;;UAEF,oBAAoB,eAAe;WACzC;;WAEA,OAAO,MAAM;;WAEb,MAAM,MAAM;;;;;;;KAOX,oBAAoB,oBAAoB,yBAClD,oBAAoB,gBAAgB;;;;;iBAMtB,kBAAkB,oBAAoB,uBACpD,iBACC,SAAS,gBAAgB;;;;;;cA4Bf,gBAAgB,2BAA2B,+BAC9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