@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
@@ -1,37 +1,150 @@
1
1
  import { observable } from '@trpc/server/observable';
2
2
  import type { AnyRouter } from '@trpc/server/unstable-core-do-not-import';
3
3
  import { createChain } from './internals/createChain';
4
- import type { Operation, TRPCLink } from './types';
4
+ import type {
5
+ AugmentedOperationContext,
6
+ inferLinksDeclaredContext,
7
+ Operation,
8
+ OperationContext,
9
+ TRPCLink,
10
+ } from './types';
5
11
 
6
- function asArray<TType>(value: TType | TType[]) {
7
- return Array.isArray(value) ? value : [value];
12
+ function asArray<TType>(value: TType | readonly TType[]): readonly TType[] {
13
+ return Array.isArray(value) ? value : [value as TType];
8
14
  }
15
+
16
+ // a field the call leaves out, or sets to `undefined`, takes its default
17
+ function withDefaults(
18
+ defaults: Record<PropertyKey, unknown>,
19
+ context: OperationContext,
20
+ ): OperationContext {
21
+ // spreading copies symbol keys too
22
+ const merged: Record<PropertyKey, unknown> = { ...defaults, ...context };
23
+ for (const key of Reflect.ownKeys(defaults)) {
24
+ if (merged[key] === undefined) merged[key] = defaults[key];
25
+ }
26
+ return merged;
27
+ }
28
+
9
29
  /**
10
- * Sends each operation down one of two link chains, based on `condition`.
11
- *
12
- * @see https://trpc.io/docs/client/links/splitLink
30
+ * A `splitLink` branch: one link or a chain of them.
31
+ * @internal
13
32
  */
14
- export function splitLink<TRouter extends AnyRouter = AnyRouter>(opts: {
33
+ type SplitLinkBranch<TRouter extends AnyRouter> =
34
+ | TRPCLink<TRouter, any>
35
+ | readonly TRPCLink<TRouter, any>[];
36
+
37
+ // a tuple, so links whose declarations nest aren't merged into one
38
+ type asLinks<TBranch> = TBranch extends readonly unknown[]
39
+ ? TBranch
40
+ : [TBranch];
41
+
42
+ interface SplitLinkOptions<
43
+ TRouter extends AnyRouter,
44
+ TTrue extends SplitLinkBranch<TRouter>,
45
+ TFalse extends SplitLinkBranch<TRouter>,
46
+ TContext extends object,
47
+ > {
15
48
  /**
16
49
  * Picks the chain for an operation.
17
50
  */
18
- condition: (op: Operation) => boolean;
51
+ condition: (op: Operation<unknown, TContext>) => boolean;
19
52
  /**
20
53
  * The link to execute next if the test function returns `true`.
21
54
  */
22
- true: TRPCLink<TRouter> | TRPCLink<TRouter>[];
55
+ true: TTrue;
23
56
  /**
24
57
  * The link to execute next if the test function returns `false`.
25
58
  */
26
- false: TRPCLink<TRouter> | TRPCLink<TRouter>[];
27
- }): TRPCLink<TRouter> {
59
+ false: TFalse;
60
+ }
61
+
62
+ // the types the branches' links read the defaults' fields as, so a
63
+ // default that a branch would read as another type is an error
64
+ type fitBranchContext<TContext, TTrue, TFalse> =
65
+ inferLinksDeclaredContext<
66
+ [...asLinks<TTrue>, ...asLinks<TFalse>]
67
+ > extends infer $Branches
68
+ ? { [TKey in keyof TContext & keyof $Branches]: $Branches[TKey] }
69
+ : never;
70
+
71
+ type SplitLink<
72
+ TRouter extends AnyRouter,
73
+ TTrue extends SplitLinkBranch<TRouter>,
74
+ TFalse extends SplitLinkBranch<TRouter>,
75
+ TContext extends object,
76
+ > = TRPCLink<
77
+ TRouter,
78
+ {
79
+ context: TContext &
80
+ inferLinksDeclaredContext<[...asLinks<TTrue>, ...asLinks<TFalse>]>;
81
+ }
82
+ >;
83
+
84
+ /**
85
+ * Sends each operation down one of two link chains, based on `condition`.
86
+ *
87
+ * Calls take the `context` both chains read. Give `context` defaults to
88
+ * declare the fields `condition` reads; without them, `condition` reads
89
+ * the fields added to `OperationContext`.
90
+ * @example
91
+ * splitLink({
92
+ * context: { skipBatch: false },
93
+ * condition: (op) => op.context.skipBatch,
94
+ * true: httpLink({ url }),
95
+ * false: httpBatchLink({ url }),
96
+ * })
97
+ *
98
+ * @see https://trpc.io/docs/client/links/splitLink
99
+ */
100
+ export function splitLink<
101
+ TRouter extends AnyRouter = AnyRouter,
102
+ // with an explicit router type, a branch is still a link or an array
103
+ const TTrue extends SplitLinkBranch<TRouter> = SplitLinkBranch<TRouter>,
104
+ const TFalse extends SplitLinkBranch<TRouter> = SplitLinkBranch<TRouter>,
105
+ >(
106
+ opts: SplitLinkOptions<TRouter, TTrue, TFalse, OperationContext> & {
107
+ context?: never;
108
+ },
109
+ // `condition` may read the fields added to `OperationContext`
110
+ ): SplitLink<TRouter, TTrue, TFalse, AugmentedOperationContext>;
111
+ export function splitLink<
112
+ TRouter extends AnyRouter,
113
+ const TTrue extends SplitLinkBranch<TRouter>,
114
+ const TFalse extends SplitLinkBranch<TRouter>,
115
+ TContext extends object,
116
+ >(
117
+ opts: SplitLinkOptions<TRouter, TTrue, TFalse, TContext> & {
118
+ /**
119
+ * Values for the `context` fields `condition` reads, used when a call
120
+ * leaves one out. Their types are the fields calls can pass. A field a
121
+ * call passes replaces its default whole: nested objects aren't merged.
122
+ * A field the branches' links also read must fit their type.
123
+ */
124
+ context: TContext & fitBranchContext<TContext, TTrue, TFalse>;
125
+ },
126
+ ): SplitLink<TRouter, TTrue, TFalse, TContext>;
127
+ export function splitLink(
128
+ opts: SplitLinkOptions<
129
+ AnyRouter,
130
+ SplitLinkBranch<AnyRouter>,
131
+ SplitLinkBranch<AnyRouter>,
132
+ any
133
+ > & { context?: Record<PropertyKey, unknown> },
134
+ ): TRPCLink<AnyRouter> {
28
135
  return (runtime) => {
29
136
  const yes = asArray(opts.true).map((link) => link(runtime));
30
137
  const no = asArray(opts.false).map((link) => link(runtime));
31
138
  return (props) => {
32
139
  return observable((observer) => {
33
- const links = opts.condition(props.op) ? yes : no;
34
- return createChain({ op: props.op, links }).subscribe(observer);
140
+ const op = opts.context
141
+ ? {
142
+ ...props.op,
143
+ context: withDefaults(opts.context, props.op.context),
144
+ }
145
+ : props.op;
146
+ const links = opts.condition(op) ? yes : no;
147
+ return createChain({ op, links }).subscribe(observer);
35
148
  });
36
149
  };
37
150
  };
@@ -2,6 +2,7 @@ import type { Observable, Observer } from '@trpc/server/observable';
2
2
  import type {
3
3
  InferrableClientTypes,
4
4
  Maybe,
5
+ Simplify,
5
6
  TRPCResultMessage,
6
7
  TRPCSuccessResponse,
7
8
  } from '@trpc/server/unstable-core-do-not-import';
@@ -22,17 +23,33 @@ export {
22
23
  */
23
24
  export interface OperationContext extends Record<string, unknown> {}
24
25
 
26
+ /**
27
+ * The fields added to `OperationContext` with module augmentation, without
28
+ * its `[key: string]: unknown`. Links that hand the operation to your code
29
+ * declare these, so calls take only fields something declared.
30
+ * @see https://trpc.io/docs/client/links#managing-context
31
+ * @public
32
+ */
33
+ export type AugmentedOperationContext = {
34
+ [
35
+ TKey in keyof OperationContext as string extends TKey ? never : TKey
36
+ ]: OperationContext[TKey];
37
+ };
38
+
25
39
  /**
26
40
  * A procedure call as it goes through the links.
27
41
  * @internal
28
42
  */
29
- export type Operation<TInput = unknown> = {
43
+ export type Operation<
44
+ TInput = unknown,
45
+ TContext extends object = OperationContext,
46
+ > = {
30
47
  /** A number unique to the call within its client. */
31
48
  id: number;
32
49
  type: 'mutation' | 'query' | 'subscription';
33
50
  input: TInput;
34
51
  path: string;
35
- context: OperationContext;
52
+ context: TContext;
36
53
  signal: Maybe<AbortSignal>;
37
54
  };
38
55
 
@@ -115,12 +132,104 @@ export type OperationLink<
115
132
  ) => OperationResultObservable<TInferrable, TOutput>;
116
133
  }) => OperationResultObservable<TInferrable, TOutput>;
117
134
 
135
+ /**
136
+ * What a link declares about itself, for clients created with
137
+ * `createTRPCClient({ router: routerType<AppRouter>(), links })`.
138
+ * @see https://trpc.io/docs/client/links#typing-call-options
139
+ * @public
140
+ */
141
+ export interface LinkDecl {
142
+ /**
143
+ * The fields the link reads from `op.context`. Calls can pass them, typed,
144
+ * as `.query(input, { context })`. `{}` declares that the link reads none.
145
+ */
146
+ context?: object;
147
+ }
148
+
118
149
  /**
119
150
  * A link: a step every call goes through, such as logging or sending it
120
151
  * over HTTP. It's called once when the client is created.
152
+ *
153
+ * `TDecl` says what it reads from `op.context`. A link that doesn't
154
+ * declare it may read any context.
121
155
  * @see https://trpc.io/docs/client/links#creating-a-custom-link
122
156
  * @public
123
157
  */
124
- export type TRPCLink<TInferrable extends InferrableClientTypes> = (
125
- opts: TRPCClientRuntime,
126
- ) => OperationLink<TInferrable>;
158
+ export type TRPCLink<
159
+ TInferrable extends InferrableClientTypes,
160
+ TDecl extends LinkDecl = LinkDecl,
161
+ > = ((opts: TRPCClientRuntime) => OperationLink<TInferrable>) & {
162
+ /** Type-only: what the link declares. Never set. */
163
+ readonly '~decl'?: TDecl;
164
+ };
165
+
166
+ type UnionToIntersection<TUnion> = (
167
+ TUnion extends any ? (arg: TUnion) => void : never
168
+ ) extends (arg: infer TIntersection) => void
169
+ ? TIntersection
170
+ : never;
171
+
172
+ // A function with no `~decl`, such as an inline `() => ({ op, next }) =>
173
+ // next(op)`, declares nothing either.
174
+ type inferLinkDecl<TLink> = TLink extends unknown
175
+ ? '~decl' extends keyof TLink
176
+ ? NonNullable<TLink['~decl' & keyof TLink]>
177
+ : LinkDecl
178
+ : never;
179
+
180
+ type inferDeclContext<TDecl> = TDecl extends unknown
181
+ ? // a link that declares nothing may read any context
182
+ LinkDecl extends TDecl
183
+ ? OperationContext
184
+ : TDecl extends { context: infer $Context }
185
+ ? $Context
186
+ : {}
187
+ : never;
188
+
189
+ declare const noLinkReadsContext: unique symbol;
190
+
191
+ /**
192
+ * The call options' `context` when no link reads one: passing any field is
193
+ * an error.
194
+ * @public
195
+ */
196
+ // A type literal, not an interface: like `Record<string, unknown>`, it
197
+ // then fits where any context is taken, so procedures and handles from
198
+ // clients typed both ways stay compatible.
199
+ export type NoLinkReadsContext = {
200
+ readonly [noLinkReadsContext]?: never;
201
+ };
202
+
203
+ /**
204
+ * The fields the links in `TLinks` declare they read, merged, for a link
205
+ * that wraps other links to declare.
206
+ * @public
207
+ */
208
+ export type inferLinksDeclaredContext<TLinks extends readonly unknown[]> =
209
+ // boxed per link, so a link that declares a union of contexts keeps it
210
+ // instead of having its alternatives intersected
211
+ UnionToIntersection<
212
+ TLinks[number] extends infer $Link
213
+ ? $Link extends unknown
214
+ ? { context: inferDeclContext<inferLinkDecl<$Link>> }
215
+ : never
216
+ : never
217
+ > extends { context: infer $Context }
218
+ ? $Context
219
+ : {};
220
+
221
+ /**
222
+ * The `context` calls can pass: the fields every link in `TLinks` reads,
223
+ * merged.
224
+ * @public
225
+ */
226
+ export type inferLinksContext<TLinks extends readonly unknown[]> =
227
+ inferLinksDeclaredContext<TLinks> extends infer $Context
228
+ ? // per alternative, so a union with no common keys keeps them
229
+ $Context extends unknown
230
+ ? keyof $Context extends never
231
+ ? NoLinkReadsContext
232
+ : // optional: a call can leave out its options altogether
233
+ Simplify<Partial<$Context>>
234
+ : never
235
+ : never;
@@ -34,7 +34,7 @@ export type WebSocketLinkOptions<TRouter extends AnyRouter> = {
34
34
  */
35
35
  export function wsLink<TRouter extends AnyRouter>(
36
36
  opts: WebSocketLinkOptions<TRouter>,
37
- ): TRPCLink<TRouter> {
37
+ ): TRPCLink<TRouter, { context: {} }> {
38
38
  const { client } = opts;
39
39
  const transformer = getTransformer(opts.transformer);
40
40
  return () => {
@@ -0,0 +1,31 @@
1
+ import type { AnyRouter } from '@trpc/server/unstable-core-do-not-import';
2
+
3
+ declare const routerTypeBrand: unique symbol;
4
+
5
+ /**
6
+ * A value that carries a router's type and nothing else. Made by
7
+ * {@link routerType}.
8
+ * @public
9
+ */
10
+ export interface RouterType<TRouter extends AnyRouter> {
11
+ readonly [routerTypeBrand]: TRouter;
12
+ }
13
+
14
+ /**
15
+ * Passes a router's type to `createTRPCClient({ router })` as a normal
16
+ * option, instead of a type argument. Nothing about the router exists at
17
+ * runtime, so it's safe to import the router's type only.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * const client = createTRPCClient({
22
+ * router: routerType<AppRouter>(),
23
+ * links: [httpBatchLink({ url: 'http://localhost:3000/trpc' })],
24
+ * });
25
+ * ```
26
+ * @see https://trpc.io/docs/client/vanilla/setup#3-initialize-the-trpc-client
27
+ * @public
28
+ */
29
+ export function routerType<TRouter extends AnyRouter>(): RouterType<TRouter> {
30
+ return {} as RouterType<TRouter>;
31
+ }
@@ -1 +0,0 @@
1
- {"version":3,"file":"httpLink-BjZdBzr6.d.mts","names":[],"sources":["../src/links/httpLink.ts"],"mappings":";;;;;;;KA+BY,gBAAgB,cAAc,kBACxC,oBAAoB;;;;;;EAMlB,UACI,gBACE;IAAQ,IAAI;QAAgB,cAAc,QAAQ;;;;;;;iBA0C5C,SAAS,gBAAgB,YAAY,WACnD,MAAM,gBAAgB,wCACrB,SAAS"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"loggerLink-CBPx95zm.d.mts","names":[],"sources":["../src/links/loggerLink.ts"],"mappings":";;KAeK;EACH,SAAS;EACT,WAAW;;KAGR,gBAAgB,gBAAgB;EAE/B;EACA,QACI,iCAAiC,gBAAgB,YACjD,gBAAgB;KAErB;EACC;;KAED,UAAU,gBAAgB,cAC7B,MAAM,gBAAgB;KAGnB,oBAAoB,gBAAgB,aAAa;;;;EAM9C;EACA,QACI,iCAAiC,gBAAgB,YACjD,gBAAgB;EACpB;;;;;EAMA;;KAIH,aAAa,gBAAgB,cAChC,MAAM,oBAAoB;KAGvB;;;;;;UAOY,kBAAkB,gBAAgB;;;;;EAKjD,SAAS,aAAa;;;;;EAKtB,UAAU,UAAU;;;;EAIpB,UAAU;;;;;EAKV,YAAY;;;;EAKZ;;;;;;;;iBA4Ic,WAAW,gBAAgB,YAAY,WACrD,OAAM,kBAAkB,WACvB,SAAS"}
@@ -1,23 +0,0 @@
1
- import { n as Operation, u as TRPCLink } from "./types-BG-3kpeg.mjs";
2
- import { AnyRouter } from "@trpc/server/unstable-core-do-not-import";
3
- /**
4
- * Sends each operation down one of two link chains, based on `condition`.
5
- *
6
- * @see https://trpc.io/docs/client/links/splitLink
7
- */
8
- declare function splitLink<TRouter extends AnyRouter = AnyRouter>(opts: {
9
- /**
10
- * Picks the chain for an operation.
11
- */
12
- condition: (op: Operation) => boolean;
13
- /**
14
- * The link to execute next if the test function returns `true`.
15
- */
16
- true: TRPCLink<TRouter> | TRPCLink<TRouter>[];
17
- /**
18
- * The link to execute next if the test function returns `false`.
19
- */
20
- false: TRPCLink<TRouter> | TRPCLink<TRouter>[];
21
- }): TRPCLink<TRouter>;
22
- export { splitLink as t };
23
- //# sourceMappingURL=splitLink-BtPz7lCB.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"splitLink-BtPz7lCB.d.mts","names":[],"sources":["../src/links/splitLink.ts"],"mappings":";;;;;;;iBAagB,UAAU,gBAAgB,YAAY,WAAW;;;;EAI/D,YAAY,IAAI;;;;EAIhB,MAAM,SAAS,WAAW,SAAS;;;;EAInC,OAAO,SAAS,WAAW,SAAS;IAClC,SAAS"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"splitLink-PFsRy7Mf.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 { Operation, TRPCLink } from './types';\n\nfunction asArray<TType>(value: TType | TType[]) {\n return Array.isArray(value) ? value : [value];\n}\n/**\n * Sends each operation down one of two link chains, based on `condition`.\n *\n * @see https://trpc.io/docs/client/links/splitLink\n */\nexport function splitLink<TRouter extends AnyRouter = AnyRouter>(opts: {\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: TRPCLink<TRouter> | TRPCLink<TRouter>[];\n /**\n * The link to execute next if the test function returns `false`.\n */\n false: TRPCLink<TRouter> | TRPCLink<TRouter>[];\n}): TRPCLink<TRouter> {\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;;AClCA,SAAS,QAAe,OAAwB;CAC9C,OAAO,MAAM,QAAQ,KAAK,IAAI,QAAQ,CAAC,KAAK;AAC9C;;;;;;AAMA,SAAgB,UAAiD,MAa3C;CACpB,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 +0,0 @@
1
- {"version":3,"file":"types-BG-3kpeg.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;;;;;;;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AAS,oBAAoB,0BACvC,MAAM,sBACH,cAAc"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"types-BhHxuBsu.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;KAEzC,gBAAgB;;;;;;UAOJ;;;;;EAKf,UAAU;;;;;;EAMV,SAAS;;KCjGN,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,+BAC9C,iBACG,oBAAoB,gBAAgB;;WAKtB,OAAK;;WAEd,OAAO,MAAM,gBAAgB;;WAE7B,MAAM,MAAM,gBAAgB;;;;;;EAOrC,MAAI;EAEX,YACE,iBACA;IACE,SAAS,MAAM,kBAAkB,gBAAgB;IACjD,QAAQ;IACR,OAAO;;;;;;SAuBG,KAAK,2BAA2B,uBAC5C,QAAQ,QAAQ,iCAChB;IAAQ,OAAO;IAAyB,QAAQ;MAC/C,gBAAgB;;;iBCjHL,YACd,iBACC,SAAS,WAAW,eAAe;;iBAStB,WAAW,iBAAc,S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