@trpc/client 11.23.0 → 11.23.1-canary.14.507382d73
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.
- package/dist/{TRPCClientError-CxFRO7Js.mjs → TRPCClientError-Byo7P4QG.mjs} +14 -1
- package/dist/TRPCClientError-Byo7P4QG.mjs.map +1 -0
- package/dist/{TRPCClientError-CmHlBkPF.cjs → TRPCClientError-CPEwAI4E.cjs} +13 -0
- package/dist/{httpBatchLink-DPypDRI1.mjs → httpBatchLink-B-gQhW2d.mjs} +6 -3
- package/dist/httpBatchLink-B-gQhW2d.mjs.map +1 -0
- package/dist/httpBatchLink-CRRfyw0c.d.cts +46 -0
- package/dist/httpBatchLink-CRRfyw0c.d.cts.map +1 -0
- package/dist/httpBatchLink-DFDg8cHu.d.mts +46 -0
- package/dist/httpBatchLink-DFDg8cHu.d.mts.map +1 -0
- package/dist/{httpBatchLink-Cmao5uUF.cjs → httpBatchLink-DfpTwHVx.cjs} +5 -2
- package/dist/{httpLink-eSAq8J9S.d.mts → httpLink-Bc4oLWCJ.d.cts} +12 -5
- package/dist/httpLink-Bc4oLWCJ.d.cts.map +1 -0
- package/dist/{httpLink-B6E1HSLY.cjs → httpLink-CTrye8t0.cjs} +11 -2
- package/dist/{httpLink--yqaZ9lA.mjs → httpLink-D1jF9wdN.mjs} +12 -3
- package/dist/httpLink-D1jF9wdN.mjs.map +1 -0
- package/dist/{httpLink-D5FQijY2.d.cts → httpLink-yX9QPwni.d.mts} +12 -5
- package/dist/httpLink-yX9QPwni.d.mts.map +1 -0
- package/dist/httpUtils-j-oJ4G4z.d.cts +25 -0
- package/dist/httpUtils-j-oJ4G4z.d.cts.map +1 -0
- package/dist/{httpUtils-CrSF2CZF.cjs → httpUtils-os0q2Zvy.cjs} +4 -0
- package/dist/{httpUtils-CAZsqwOQ.mjs → httpUtils-ttfajAo5.mjs} +5 -1
- package/dist/httpUtils-ttfajAo5.mjs.map +1 -0
- package/dist/httpUtils-v7O5xeam.d.mts +25 -0
- package/dist/httpUtils-v7O5xeam.d.mts.map +1 -0
- package/dist/index.cjs +55 -16
- package/dist/index.d.cts +150 -26
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +150 -26
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +55 -16
- package/dist/index.mjs.map +1 -1
- package/dist/links/httpBatchLink.cjs +1 -1
- package/dist/links/httpBatchLink.d.cts +1 -1
- package/dist/links/httpBatchLink.d.mts +1 -1
- package/dist/links/httpBatchLink.mjs +1 -1
- package/dist/links/httpLink.cjs +1 -1
- package/dist/links/httpLink.d.cts +1 -1
- package/dist/links/httpLink.d.mts +1 -1
- package/dist/links/httpLink.mjs +1 -1
- package/dist/links/loggerLink.cjs +4 -1
- package/dist/links/loggerLink.d.cts +1 -1
- package/dist/links/loggerLink.d.mts +1 -1
- package/dist/links/loggerLink.mjs +4 -1
- package/dist/links/loggerLink.mjs.map +1 -1
- package/dist/links/splitLink.cjs +1 -1
- package/dist/links/splitLink.d.cts +1 -1
- package/dist/links/splitLink.d.mts +1 -1
- package/dist/links/splitLink.mjs +1 -1
- package/dist/links/wsLink/wsLink.cjs +1 -1
- package/dist/links/wsLink/wsLink.d.cts +1 -1
- package/dist/links/wsLink/wsLink.d.mts +1 -1
- package/dist/links/wsLink/wsLink.mjs +1 -1
- package/dist/{loggerLink-CFercTVc.d.mts → loggerLink-BEMtA7V5.d.cts} +20 -4
- package/dist/loggerLink-BEMtA7V5.d.cts.map +1 -0
- package/dist/{loggerLink-2o-uZ3r1.d.cts → loggerLink-Daki_B65.d.mts} +20 -4
- package/dist/loggerLink-Daki_B65.d.mts.map +1 -0
- package/dist/{splitLink-MXnaFlEb.cjs → splitLink-CL8W2Mit.cjs} +5 -0
- package/dist/{splitLink-BZPioDdG.mjs → splitLink-DcpFI5s5.mjs} +6 -1
- package/dist/splitLink-DcpFI5s5.mjs.map +1 -0
- package/dist/{splitLink-CJdcmEmS.d.cts → splitLink-i7EskO_m.d.cts} +10 -2
- package/dist/splitLink-i7EskO_m.d.cts.map +1 -0
- package/dist/{splitLink-CixmF14P.d.mts → splitLink-zyV5y7N1.d.mts} +10 -2
- package/dist/splitLink-zyV5y7N1.d.mts.map +1 -0
- package/dist/{types-BxbMkv6C.d.cts → types-BrCJd1zp.d.cts} +54 -6
- package/dist/types-BrCJd1zp.d.cts.map +1 -0
- package/dist/{types-CAPs7vhA.d.mts → types-DO-GCB2q.d.mts} +54 -6
- package/dist/types-DO-GCB2q.d.mts.map +1 -0
- package/dist/{unstable-internals-CE8gFBQ9.d.cts → unstable-internals-CNoyg7Yf.d.cts} +4 -4
- package/dist/{unstable-internals-CE8gFBQ9.d.cts.map → unstable-internals-CNoyg7Yf.d.cts.map} +1 -1
- package/dist/{unstable-internals-CE8gFBQ9.d.mts → unstable-internals-CNoyg7Yf.d.mts} +4 -4
- package/dist/{unstable-internals-CE8gFBQ9.d.mts.map → unstable-internals-CNoyg7Yf.d.mts.map} +1 -1
- package/dist/unstable-internals.d.cts +1 -1
- package/dist/unstable-internals.d.mts +1 -1
- package/dist/unstable-internals.mjs.map +1 -1
- package/dist/{wsLink-CQGBu_VZ.cjs → wsLink-Bl27m-y2.cjs} +18 -1
- package/dist/{wsLink--7trqYPG.mjs → wsLink-CDaUjHvu.mjs} +19 -2
- package/dist/wsLink-CDaUjHvu.mjs.map +1 -0
- package/dist/{wsLink-DnvK9sTv.d.mts → wsLink-CEgNu9Gj.d.mts} +39 -5
- package/dist/wsLink-CEgNu9Gj.d.mts.map +1 -0
- package/dist/{wsLink-C3hsDLsL.d.cts → wsLink-DZr_cFFg.d.cts} +39 -5
- package/dist/wsLink-DZr_cFFg.d.cts.map +1 -0
- package/package.json +4 -4
- package/skills/client-setup/SKILL.md +1 -1
- package/skills/links/SKILL.md +1 -1
- package/skills/superjson/SKILL.md +1 -1
- package/src/TRPCClientError.ts +27 -2
- package/src/createTRPCClient.ts +38 -7
- package/src/createTRPCUntypedClient.ts +4 -0
- package/src/getFetch.ts +4 -0
- package/src/internals/TRPCUntypedClient.ts +33 -2
- package/src/internals/transformer.ts +3 -3
- package/src/internals/types.ts +9 -1
- package/src/links/HTTPBatchLinkOptions.ts +17 -3
- package/src/links/httpBatchLink.ts +3 -0
- package/src/links/httpBatchStreamLink.ts +10 -1
- package/src/links/httpLink.ts +9 -2
- package/src/links/httpSubscriptionLink.ts +10 -3
- package/src/links/internals/contentTypes.ts +7 -0
- package/src/links/internals/httpUtils.ts +6 -4
- package/src/links/internals/urlWithConnectionParams.ts +1 -0
- package/src/links/localLink.ts +22 -3
- package/src/links/loggerLink.ts +18 -2
- package/src/links/retryLink.ts +4 -1
- package/src/links/splitLink.ts +8 -0
- package/src/links/types.ts +17 -2
- package/src/links/wsLink/createWsClient.ts +9 -0
- package/src/links/wsLink/wsClient/encoder.ts +3 -0
- package/src/links/wsLink/wsClient/options.ts +7 -2
- package/src/links/wsLink/wsClient/wsClient.ts +3 -0
- package/src/links/wsLink/wsLink.ts +13 -0
- package/src/safe.ts +11 -2
- package/dist/TRPCClientError-CxFRO7Js.mjs.map +0 -1
- package/dist/httpBatchLink-Br-pzPXf.d.cts +0 -29
- package/dist/httpBatchLink-Br-pzPXf.d.cts.map +0 -1
- package/dist/httpBatchLink-DPypDRI1.mjs.map +0 -1
- package/dist/httpBatchLink-nvc48L_N.d.mts +0 -29
- package/dist/httpBatchLink-nvc48L_N.d.mts.map +0 -1
- package/dist/httpLink--yqaZ9lA.mjs.map +0 -1
- package/dist/httpLink-D5FQijY2.d.cts.map +0 -1
- package/dist/httpLink-eSAq8J9S.d.mts.map +0 -1
- package/dist/httpUtils-C37jRVnj.d.mts +0 -23
- package/dist/httpUtils-C37jRVnj.d.mts.map +0 -1
- package/dist/httpUtils-CAZsqwOQ.mjs.map +0 -1
- package/dist/httpUtils-CUqAubVD.d.cts +0 -23
- package/dist/httpUtils-CUqAubVD.d.cts.map +0 -1
- package/dist/loggerLink-2o-uZ3r1.d.cts.map +0 -1
- package/dist/loggerLink-CFercTVc.d.mts.map +0 -1
- package/dist/splitLink-BZPioDdG.mjs.map +0 -1
- package/dist/splitLink-CJdcmEmS.d.cts.map +0 -1
- package/dist/splitLink-CixmF14P.d.mts.map +0 -1
- package/dist/types-BxbMkv6C.d.cts.map +0 -1
- package/dist/types-CAPs7vhA.d.mts.map +0 -1
- package/dist/wsLink--7trqYPG.mjs.map +0 -1
- package/dist/wsLink-C3hsDLsL.d.cts.map +0 -1
- package/dist/wsLink-DnvK9sTv.d.mts.map +0 -1
|
@@ -21,29 +21,57 @@ import type {
|
|
|
21
21
|
import { TRPCClientError } from '../TRPCClientError';
|
|
22
22
|
|
|
23
23
|
type TRPCType = 'mutation' | 'query' | 'subscription';
|
|
24
|
+
/** The options of a call made with the untyped client. */
|
|
24
25
|
export interface TRPCRequestOptions {
|
|
25
26
|
/**
|
|
26
|
-
*
|
|
27
|
+
* Context for the links, such as a flag a `splitLink` reads.
|
|
28
|
+
* @see https://trpc.io/docs/client/links#managing-context
|
|
27
29
|
*/
|
|
28
30
|
context?: OperationContext;
|
|
31
|
+
/**
|
|
32
|
+
* Aborts the call. With `httpBatchLink`, the request is only aborted once
|
|
33
|
+
* every call in its batch is, so an aborted call can still get a result.
|
|
34
|
+
*/
|
|
29
35
|
signal?: AbortSignal;
|
|
30
36
|
}
|
|
31
37
|
|
|
38
|
+
/** The callbacks a subscription takes on the client. */
|
|
32
39
|
export interface TRPCSubscriptionObserver<TValue, TError> {
|
|
40
|
+
/** Called when the link sends a `started` result. */
|
|
33
41
|
onStarted: (opts: { context: OperationContext | undefined }) => void;
|
|
42
|
+
/** Called with each event. */
|
|
34
43
|
onData: (value: inferAsyncIterableYield<TValue>) => void;
|
|
44
|
+
/** Called when the subscription ends with an error. */
|
|
35
45
|
onError: (err: TError) => void;
|
|
46
|
+
/**
|
|
47
|
+
* Called when the link sends a `stopped` result. Not every link sends
|
|
48
|
+
* one; `localLink` doesn't.
|
|
49
|
+
*/
|
|
36
50
|
onStopped: () => void;
|
|
51
|
+
/** Called when the subscription's observable completes, for any reason. */
|
|
37
52
|
onComplete: () => void;
|
|
53
|
+
/** Called when the connection connects, drops or reconnects. */
|
|
38
54
|
onConnectionStateChange: (state: TRPCConnectionState<TError>) => void;
|
|
39
55
|
}
|
|
40
56
|
|
|
41
|
-
/**
|
|
57
|
+
/**
|
|
58
|
+
* The options of `createTRPCClient`.
|
|
59
|
+
* @internal
|
|
60
|
+
*/
|
|
42
61
|
export type CreateTRPCClientOptions<TRouter extends InferrableClientTypes> = {
|
|
62
|
+
/**
|
|
63
|
+
* The links each call goes through, in order. The last one must send
|
|
64
|
+
* the call, such as `httpBatchLink`.
|
|
65
|
+
* @see https://trpc.io/docs/client/links
|
|
66
|
+
*/
|
|
43
67
|
links: TRPCLink<TRouter>[];
|
|
44
68
|
transformer?: TypeError<'The transformer property has moved to httpLink/httpBatchLink/wsLink'>;
|
|
45
69
|
};
|
|
46
70
|
|
|
71
|
+
/**
|
|
72
|
+
* A client that calls procedures by path string, without types.
|
|
73
|
+
* `createTRPCClient` wraps one.
|
|
74
|
+
*/
|
|
47
75
|
export class TRPCUntypedClient<TInferrable extends InferrableClientTypes> {
|
|
48
76
|
private readonly links: OperationLink<TInferrable>[];
|
|
49
77
|
public readonly runtime: TRPCClientRuntime;
|
|
@@ -94,6 +122,7 @@ export class TRPCUntypedClient<TInferrable extends InferrableClientTypes> {
|
|
|
94
122
|
throw TRPCClientError.from(err as Error);
|
|
95
123
|
}
|
|
96
124
|
}
|
|
125
|
+
/** Calls a query. */
|
|
97
126
|
public query(path: string, input?: unknown, opts?: TRPCRequestOptions) {
|
|
98
127
|
return this.requestAsPromise<unknown, unknown>({
|
|
99
128
|
type: 'query',
|
|
@@ -103,6 +132,7 @@ export class TRPCUntypedClient<TInferrable extends InferrableClientTypes> {
|
|
|
103
132
|
signal: opts?.signal,
|
|
104
133
|
});
|
|
105
134
|
}
|
|
135
|
+
/** Calls a mutation. */
|
|
106
136
|
public mutation(path: string, input?: unknown, opts?: TRPCRequestOptions) {
|
|
107
137
|
return this.requestAsPromise<unknown, unknown>({
|
|
108
138
|
type: 'mutation',
|
|
@@ -112,6 +142,7 @@ export class TRPCUntypedClient<TInferrable extends InferrableClientTypes> {
|
|
|
112
142
|
signal: opts?.signal,
|
|
113
143
|
});
|
|
114
144
|
}
|
|
145
|
+
/** Starts a subscription. Returns what stops it. */
|
|
115
146
|
public subscription(
|
|
116
147
|
path: string,
|
|
117
148
|
input: unknown,
|
|
@@ -17,7 +17,7 @@ type TransformerOptionYes = {
|
|
|
17
17
|
* Data transformer
|
|
18
18
|
*
|
|
19
19
|
* You must use the same transformer on the backend and frontend
|
|
20
|
-
* @see https://trpc.io/docs/
|
|
20
|
+
* @see https://trpc.io/docs/server/data-transformers
|
|
21
21
|
**/
|
|
22
22
|
transformer: DataTransformerOptions;
|
|
23
23
|
};
|
|
@@ -26,9 +26,9 @@ type TransformerOptionNo = {
|
|
|
26
26
|
* Data transformer
|
|
27
27
|
*
|
|
28
28
|
* You must use the same transformer on the backend and frontend
|
|
29
|
-
* @see https://trpc.io/docs/
|
|
29
|
+
* @see https://trpc.io/docs/server/data-transformers
|
|
30
30
|
**/
|
|
31
|
-
transformer?: TypeError<'You must define a transformer on your
|
|
31
|
+
transformer?: TypeError<'You must define a transformer on your `initTRPC`-object first'>;
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
/**
|
package/src/internals/types.ts
CHANGED
|
@@ -91,12 +91,20 @@ export type NonEmptyArray<TItem> = [TItem, ...TItem[]];
|
|
|
91
91
|
type ClientContext = Record<string, unknown>;
|
|
92
92
|
|
|
93
93
|
/**
|
|
94
|
+
* The options of a call made with the client, such as
|
|
95
|
+
* `client.post.byId.query(input, opts)`.
|
|
94
96
|
* @public
|
|
95
97
|
*/
|
|
96
98
|
export interface TRPCProcedureOptions {
|
|
97
99
|
/**
|
|
98
|
-
*
|
|
100
|
+
* Context for the links, such as a flag a `splitLink` reads.
|
|
101
|
+
* @see https://trpc.io/docs/client/links#managing-context
|
|
99
102
|
*/
|
|
100
103
|
context?: ClientContext;
|
|
104
|
+
/**
|
|
105
|
+
* Aborts the call. With `httpBatchLink`, the request is only aborted once
|
|
106
|
+
* every call in its batch is, so an aborted call can still get a result.
|
|
107
|
+
* @see https://trpc.io/docs/client/vanilla/aborting-procedure-calls
|
|
108
|
+
*/
|
|
101
109
|
signal?: AbortSignal;
|
|
102
110
|
}
|
|
@@ -3,12 +3,24 @@ import type { NonEmptyArray } from '../internals/types';
|
|
|
3
3
|
import type { HTTPLinkBaseOptions } from './internals/httpUtils';
|
|
4
4
|
import type { HTTPHeaders, Operation } from './types';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* The options of `httpBatchLink`.
|
|
8
|
+
* @see https://trpc.io/docs/client/links/httpBatchLink#options
|
|
9
|
+
*/
|
|
6
10
|
export type HTTPBatchLinkOptions<TRoot extends AnyClientTypes> =
|
|
7
11
|
HTTPLinkBaseOptions<TRoot> & {
|
|
12
|
+
/**
|
|
13
|
+
* The longest URL a batched GET request can have. Calls that would
|
|
14
|
+
* make it longer go in another batch. A call too long on its own
|
|
15
|
+
* fails.
|
|
16
|
+
* @see https://trpc.io/docs/client/links/httpBatchLink#setting-a-maximum-url-length
|
|
17
|
+
* @default Infinity
|
|
18
|
+
*/
|
|
8
19
|
maxURLLength?: number;
|
|
9
20
|
/**
|
|
10
|
-
* Headers
|
|
11
|
-
*
|
|
21
|
+
* Headers for each request: an object, or a function of the batch's
|
|
22
|
+
* operations that returns them.
|
|
23
|
+
* @see https://trpc.io/docs/client/headers
|
|
12
24
|
*/
|
|
13
25
|
headers?:
|
|
14
26
|
| HTTPHeaders
|
|
@@ -17,7 +29,9 @@ export type HTTPBatchLinkOptions<TRoot extends AnyClientTypes> =
|
|
|
17
29
|
}) => HTTPHeaders | Promise<HTTPHeaders>);
|
|
18
30
|
|
|
19
31
|
/**
|
|
20
|
-
*
|
|
32
|
+
* The most calls one batch can have. Set it to the server's
|
|
33
|
+
* `maxBatchSize` or lower.
|
|
34
|
+
* @see https://trpc.io/docs/client/links/httpBatchLink#limiting-batch-size
|
|
21
35
|
* @default Infinity
|
|
22
36
|
*/
|
|
23
37
|
maxItems?: number;
|
|
@@ -16,6 +16,9 @@ import {
|
|
|
16
16
|
import type { Operation, TRPCLink } from './types';
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
+
* A terminating link that batches calls made in the same tick into one HTTP
|
|
20
|
+
* request.
|
|
21
|
+
*
|
|
19
22
|
* @see https://trpc.io/docs/client/links/httpBatchLink
|
|
20
23
|
*/
|
|
21
24
|
export function httpBatchLink<TRouter extends AnyRouter>(
|
|
@@ -18,6 +18,12 @@ import {
|
|
|
18
18
|
} from './internals/httpUtils';
|
|
19
19
|
import type { Operation, TRPCLink } from './types';
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Options for {@link httpBatchStreamLink}. Takes the same options as
|
|
23
|
+
* `httpBatchLink`, plus `streamHeader`.
|
|
24
|
+
*
|
|
25
|
+
* @see https://trpc.io/docs/client/links/httpBatchStreamLink#options
|
|
26
|
+
*/
|
|
21
27
|
export type HTTPBatchStreamLinkOptions<TRoot extends AnyClientTypes> =
|
|
22
28
|
HTTPBatchLinkOptions<TRoot> & {
|
|
23
29
|
/**
|
|
@@ -30,6 +36,9 @@ export type HTTPBatchStreamLinkOptions<TRoot extends AnyClientTypes> =
|
|
|
30
36
|
};
|
|
31
37
|
|
|
32
38
|
/**
|
|
39
|
+
* A terminating link that batches calls like `httpBatchLink`, but streams each
|
|
40
|
+
* response back as soon as it is ready.
|
|
41
|
+
*
|
|
33
42
|
* @see https://trpc.io/docs/client/links/httpBatchStreamLink
|
|
34
43
|
*/
|
|
35
44
|
export function httpBatchStreamLink<TRouter extends AnyRouter>(
|
|
@@ -230,6 +239,6 @@ export function httpBatchStreamLink<TRouter extends AnyRouter>(
|
|
|
230
239
|
}
|
|
231
240
|
|
|
232
241
|
/**
|
|
233
|
-
* @deprecated
|
|
242
|
+
* @deprecated Use {@link httpBatchStreamLink} instead.
|
|
234
243
|
*/
|
|
235
244
|
export const unstable_httpBatchStreamLink = httpBatchStreamLink;
|
package/src/links/httpLink.ts
CHANGED
|
@@ -25,11 +25,16 @@ import {
|
|
|
25
25
|
type TRPCLink,
|
|
26
26
|
} from './types';
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* The options of `httpLink`.
|
|
30
|
+
* @see https://trpc.io/docs/client/links/httpLink#httplink-options
|
|
31
|
+
*/
|
|
28
32
|
export type HTTPLinkOptions<TRoot extends AnyClientTypes> =
|
|
29
33
|
HTTPLinkBaseOptions<TRoot> & {
|
|
30
34
|
/**
|
|
31
|
-
* Headers
|
|
32
|
-
*
|
|
35
|
+
* Headers for each request: an object, or a function of the operation
|
|
36
|
+
* that returns them.
|
|
37
|
+
* @see https://trpc.io/docs/client/headers
|
|
33
38
|
*/
|
|
34
39
|
headers?:
|
|
35
40
|
| HTTPHeaders
|
|
@@ -71,6 +76,8 @@ const universalRequester: Requester = (opts) => {
|
|
|
71
76
|
};
|
|
72
77
|
|
|
73
78
|
/**
|
|
79
|
+
* A terminating link that sends each call in its own HTTP request. It can
|
|
80
|
+
* send `FormData` and binary inputs.
|
|
74
81
|
* @see https://trpc.io/docs/client/links/httpLink
|
|
75
82
|
*/
|
|
76
83
|
export function httpLink<TRouter extends AnyRouter = AnyRouter>(
|
|
@@ -38,16 +38,21 @@ async function urlWithConnectionParams(
|
|
|
38
38
|
return url;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
/**
|
|
42
|
+
* @see https://trpc.io/docs/client/links/httpSubscriptionLink#httpsubscriptionlink-options
|
|
43
|
+
*/
|
|
41
44
|
type HTTPSubscriptionLinkOptions<
|
|
42
45
|
TRoot extends AnyClientTypes,
|
|
43
46
|
TEventSource extends EventSourceLike.AnyConstructor = typeof EventSource,
|
|
44
47
|
> = {
|
|
45
48
|
/**
|
|
46
|
-
* EventSource
|
|
49
|
+
* The `EventSource` class to use, for runtimes that don't have one.
|
|
50
|
+
* @see https://trpc.io/docs/client/links/httpSubscriptionLink#custom-headers-through-ponyfill
|
|
47
51
|
*/
|
|
48
52
|
EventSource?: TEventSource;
|
|
49
53
|
/**
|
|
50
|
-
* EventSource
|
|
54
|
+
* Options passed to the `EventSource`, or a function that returns them for
|
|
55
|
+
* each subscription.
|
|
51
56
|
*/
|
|
52
57
|
eventSourceOptions?:
|
|
53
58
|
| EventSourceLike.InitDictOf<TEventSource>
|
|
@@ -60,6 +65,8 @@ type HTTPSubscriptionLinkOptions<
|
|
|
60
65
|
UrlOptionsWithConnectionParams;
|
|
61
66
|
|
|
62
67
|
/**
|
|
68
|
+
* A terminating link that runs subscriptions over Server-Sent Events.
|
|
69
|
+
*
|
|
63
70
|
* @see https://trpc.io/docs/client/links/httpSubscriptionLink
|
|
64
71
|
*/
|
|
65
72
|
export function httpSubscriptionLink<
|
|
@@ -238,6 +245,6 @@ export function httpSubscriptionLink<
|
|
|
238
245
|
}
|
|
239
246
|
|
|
240
247
|
/**
|
|
241
|
-
* @deprecated
|
|
248
|
+
* @deprecated Use {@link httpSubscriptionLink} instead.
|
|
242
249
|
*/
|
|
243
250
|
export const unstable_httpSubscriptionLink = httpSubscriptionLink;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** Whether an input is binary: a `Uint8Array`, `Blob` or `File`. */
|
|
1
2
|
export function isOctetType(
|
|
2
3
|
input: unknown,
|
|
3
4
|
): input is Uint8Array<ArrayBuffer> | Blob {
|
|
@@ -8,10 +9,16 @@ export function isOctetType(
|
|
|
8
9
|
);
|
|
9
10
|
}
|
|
10
11
|
|
|
12
|
+
/** Whether an input is `FormData`. */
|
|
11
13
|
export function isFormData(input: unknown) {
|
|
12
14
|
return input instanceof FormData;
|
|
13
15
|
}
|
|
14
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Whether an input can't be sent as JSON: binary data or `FormData`. Use
|
|
19
|
+
* it in a `splitLink` to send such inputs with `httpLink`.
|
|
20
|
+
* @see https://trpc.io/docs/server/non-json-content-types#client-setup
|
|
21
|
+
*/
|
|
15
22
|
export function isNonJsonSerializable(input: unknown) {
|
|
16
23
|
return isOctetType(input) || isFormData(input);
|
|
17
24
|
}
|
|
@@ -17,20 +17,22 @@ import { getTransformer } from '../../unstable-internals';
|
|
|
17
17
|
import type { HTTPHeaders } from '../types';
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
|
+
* The options every HTTP link takes.
|
|
20
21
|
* @internal
|
|
21
22
|
*/
|
|
22
23
|
export type HTTPLinkBaseOptions<
|
|
23
24
|
TRoot extends Pick<AnyClientTypes, 'transformer'>,
|
|
24
25
|
> = {
|
|
26
|
+
/** The URL of your tRPC endpoint, such as `http://localhost:3000/trpc`. */
|
|
25
27
|
url: string | URL;
|
|
26
28
|
/**
|
|
27
|
-
*
|
|
29
|
+
* The `fetch` to use, if not the global one.
|
|
28
30
|
*/
|
|
29
31
|
fetch?: FetchEsque;
|
|
30
32
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* @see https://trpc.io/docs/rpc
|
|
33
|
+
* Sends every call as a POST, whatever its type. The server must set
|
|
34
|
+
* `allowMethodOverride: true`.
|
|
35
|
+
* @see https://trpc.io/docs/rpc#overriding-the-default-http-method
|
|
34
36
|
*/
|
|
35
37
|
methodOverride?: 'POST';
|
|
36
38
|
} & TransformerOptions<TRoot>;
|
|
@@ -28,6 +28,7 @@ export interface UrlOptionsWithConnectionParams {
|
|
|
28
28
|
* Connection params that are available in `createContext()`
|
|
29
29
|
* - For `wsLink`/`wsClient`, these are sent as the first message
|
|
30
30
|
* - For `httpSubscriptionLink`, these are serialized as part of the URL under the `connectionParams` query
|
|
31
|
+
* @see https://trpc.io/docs/server/websockets#connectionParams
|
|
31
32
|
*/
|
|
32
33
|
connectionParams?: CallbackOrValue<TRPCRequestInfo['connectionParams']>;
|
|
33
34
|
}
|
package/src/links/localLink.ts
CHANGED
|
@@ -26,14 +26,32 @@ import { isTRPCClientError, TRPCClientError } from '../TRPCClientError';
|
|
|
26
26
|
import type { TRPCConnectionState } from './internals/subscriptions';
|
|
27
27
|
import type { TRPCLink } from './types';
|
|
28
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Options for {@link localLink}.
|
|
31
|
+
*
|
|
32
|
+
* @see https://trpc.io/docs/client/links/localLink#options
|
|
33
|
+
*/
|
|
29
34
|
export type LocalLinkOptions<TRouter extends AnyRouter> = {
|
|
35
|
+
/**
|
|
36
|
+
* The router to call.
|
|
37
|
+
* @see https://trpc.io/docs/client/links/localLink#router
|
|
38
|
+
*/
|
|
30
39
|
router: TRouter;
|
|
40
|
+
/**
|
|
41
|
+
* Creates the context for each call.
|
|
42
|
+
* @see https://trpc.io/docs/client/links/localLink#createcontext
|
|
43
|
+
*/
|
|
31
44
|
createContext: () => Promise<inferRouterContext<TRouter>>;
|
|
45
|
+
/**
|
|
46
|
+
* Called when a procedure throws.
|
|
47
|
+
* @see https://trpc.io/docs/client/links/localLink#onerror
|
|
48
|
+
*/
|
|
32
49
|
onError?: (opts: ErrorHandlerOptions<inferRouterContext<TRouter>>) => void;
|
|
33
50
|
} & TransformerOptions<inferClientTypes<TRouter>>;
|
|
34
51
|
|
|
35
52
|
/**
|
|
36
|
-
*
|
|
53
|
+
* A terminating link that calls procedures on a router in the same process,
|
|
54
|
+
* without HTTP.
|
|
37
55
|
*
|
|
38
56
|
* @see https://trpc.io/docs/client/links/localLink
|
|
39
57
|
*/
|
|
@@ -288,12 +306,13 @@ export function localLink<TRouter extends AnyRouter>(
|
|
|
288
306
|
}
|
|
289
307
|
|
|
290
308
|
/**
|
|
291
|
-
* @deprecated
|
|
309
|
+
* @deprecated Use {@link localLink} instead.
|
|
292
310
|
* @function
|
|
293
311
|
*/
|
|
294
312
|
export const unstable_localLink = localLink;
|
|
295
313
|
|
|
296
314
|
/**
|
|
297
|
-
* @deprecated
|
|
315
|
+
* @deprecated Use {@link localLink} instead. This alias will be removed in a
|
|
316
|
+
* future major release.
|
|
298
317
|
*/
|
|
299
318
|
export const experimental_localLink = localLink;
|
package/src/links/loggerLink.ts
CHANGED
|
@@ -58,11 +58,24 @@ type LoggerLinkFn<TRouter extends AnyRouter> = (
|
|
|
58
58
|
|
|
59
59
|
type ColorMode = 'ansi' | 'css' | 'none';
|
|
60
60
|
|
|
61
|
+
/**
|
|
62
|
+
* Options for {@link loggerLink}.
|
|
63
|
+
*
|
|
64
|
+
* @see https://trpc.io/docs/client/links/loggerLink#loggerlink-options
|
|
65
|
+
*/
|
|
61
66
|
export interface LoggerLinkOptions<TRouter extends AnyRouter> {
|
|
67
|
+
/**
|
|
68
|
+
* Replaces the built-in logger. Called when a call starts and for each
|
|
69
|
+
* result or error, so a subscription calls it for every event.
|
|
70
|
+
*/
|
|
62
71
|
logger?: LoggerLinkFn<TRouter>;
|
|
72
|
+
/**
|
|
73
|
+
* Decides whether to log a call.
|
|
74
|
+
* @default () => true
|
|
75
|
+
*/
|
|
63
76
|
enabled?: EnabledFn<TRouter>;
|
|
64
77
|
/**
|
|
65
|
-
*
|
|
78
|
+
* The console the built-in logger writes to.
|
|
66
79
|
*/
|
|
67
80
|
console?: ConsoleEsque;
|
|
68
81
|
/**
|
|
@@ -209,7 +222,10 @@ const defaultLogger =
|
|
|
209
222
|
};
|
|
210
223
|
|
|
211
224
|
/**
|
|
212
|
-
*
|
|
225
|
+
* Logs each call when it starts, and each result or error it gets with the
|
|
226
|
+
* time since the start.
|
|
227
|
+
*
|
|
228
|
+
* @see https://trpc.io/docs/client/links/loggerLink
|
|
213
229
|
*/
|
|
214
230
|
export function loggerLink<TRouter extends AnyRouter = AnyRouter>(
|
|
215
231
|
opts: LoggerLinkOptions<TRouter> = {},
|
package/src/links/retryLink.ts
CHANGED
|
@@ -34,7 +34,10 @@ interface RetryFnOptions<TInferrable extends InferrableClientTypes> {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
|
-
*
|
|
37
|
+
* Retries failed operations. Subscriptions resume from the last tracked event
|
|
38
|
+
* id.
|
|
39
|
+
*
|
|
40
|
+
* @see https://trpc.io/docs/client/links/retryLink
|
|
38
41
|
*/
|
|
39
42
|
export function retryLink<TInferrable extends InferrableClientTypes>(
|
|
40
43
|
opts: RetryLinkOptions<TInferrable>,
|
package/src/links/splitLink.ts
CHANGED
|
@@ -6,7 +6,15 @@ import type { Operation, TRPCLink } from './types';
|
|
|
6
6
|
function asArray<TType>(value: TType | TType[]) {
|
|
7
7
|
return Array.isArray(value) ? value : [value];
|
|
8
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Sends each operation down one of two link chains, based on `condition`.
|
|
11
|
+
*
|
|
12
|
+
* @see https://trpc.io/docs/client/links/splitLink
|
|
13
|
+
*/
|
|
9
14
|
export function splitLink<TRouter extends AnyRouter = AnyRouter>(opts: {
|
|
15
|
+
/**
|
|
16
|
+
* Picks the chain for an operation.
|
|
17
|
+
*/
|
|
10
18
|
condition: (op: Operation) => boolean;
|
|
11
19
|
/**
|
|
12
20
|
* The link to execute next if the test function returns `true`.
|
package/src/links/types.ts
CHANGED
|
@@ -16,14 +16,18 @@ export {
|
|
|
16
16
|
} from './internals/contentTypes';
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
+
* Context an operation carries through the links, set per call.
|
|
20
|
+
* @see https://trpc.io/docs/client/links#managing-context
|
|
19
21
|
* @internal
|
|
20
22
|
*/
|
|
21
23
|
export interface OperationContext extends Record<string, unknown> {}
|
|
22
24
|
|
|
23
25
|
/**
|
|
26
|
+
* A procedure call as it goes through the links.
|
|
24
27
|
* @internal
|
|
25
28
|
*/
|
|
26
29
|
export type Operation<TInput = unknown> = {
|
|
30
|
+
/** A number unique to the call within its client. */
|
|
27
31
|
id: number;
|
|
28
32
|
type: 'mutation' | 'query' | 'subscription';
|
|
29
33
|
input: TInput;
|
|
@@ -37,6 +41,7 @@ interface HeadersInitEsque {
|
|
|
37
41
|
}
|
|
38
42
|
|
|
39
43
|
/**
|
|
44
|
+
* Request headers: a `Headers`-like iterable, or an object.
|
|
40
45
|
* @internal
|
|
41
46
|
*/
|
|
42
47
|
export type HTTPHeaders =
|
|
@@ -44,19 +49,21 @@ export type HTTPHeaders =
|
|
|
44
49
|
| Record<string, string[] | string | undefined>;
|
|
45
50
|
|
|
46
51
|
/**
|
|
47
|
-
* The
|
|
48
|
-
* only uses the overload taking a string and options object.
|
|
52
|
+
* The `fetch` the HTTP links call: only its `(url, options)` form.
|
|
49
53
|
*/
|
|
50
54
|
export type TRPCFetch = (
|
|
51
55
|
url: string,
|
|
52
56
|
options?: RequestInit,
|
|
53
57
|
) => Promise<ResponseEsque>;
|
|
54
58
|
|
|
59
|
+
/** What a link gets when the client is created. Empty for now. */
|
|
55
60
|
export interface TRPCClientRuntime {
|
|
56
61
|
// nothing here anymore
|
|
57
62
|
}
|
|
58
63
|
|
|
59
64
|
/**
|
|
65
|
+
* A result a link passes back: data, a subscription's `started` or
|
|
66
|
+
* `stopped` event, or a change of connection state.
|
|
60
67
|
* @internal
|
|
61
68
|
*/
|
|
62
69
|
export interface OperationResultEnvelope<TOutput, TError> {
|
|
@@ -68,6 +75,7 @@ export interface OperationResultEnvelope<TOutput, TError> {
|
|
|
68
75
|
}
|
|
69
76
|
|
|
70
77
|
/**
|
|
78
|
+
* The observable of results a link returns for an operation.
|
|
71
79
|
* @internal
|
|
72
80
|
*/
|
|
73
81
|
export type OperationResultObservable<
|
|
@@ -79,6 +87,7 @@ export type OperationResultObservable<
|
|
|
79
87
|
>;
|
|
80
88
|
|
|
81
89
|
/**
|
|
90
|
+
* An observer of a link's results.
|
|
82
91
|
* @internal
|
|
83
92
|
*/
|
|
84
93
|
export type OperationResultObserver<
|
|
@@ -90,6 +99,9 @@ export type OperationResultObserver<
|
|
|
90
99
|
>;
|
|
91
100
|
|
|
92
101
|
/**
|
|
102
|
+
* Handles one operation: pass it on with `next(op)`, or send it and
|
|
103
|
+
* return the results.
|
|
104
|
+
* @see https://trpc.io/docs/client/links#creating-a-custom-link
|
|
93
105
|
* @internal
|
|
94
106
|
*/
|
|
95
107
|
export type OperationLink<
|
|
@@ -104,6 +116,9 @@ export type OperationLink<
|
|
|
104
116
|
}) => OperationResultObservable<TInferrable, TOutput>;
|
|
105
117
|
|
|
106
118
|
/**
|
|
119
|
+
* A link: a step every call goes through, such as logging or sending it
|
|
120
|
+
* over HTTP. It's called once when the client is created.
|
|
121
|
+
* @see https://trpc.io/docs/client/links#creating-a-custom-link
|
|
107
122
|
* @public
|
|
108
123
|
*/
|
|
109
124
|
export type TRPCLink<TInferrable extends InferrableClientTypes> = (
|
|
@@ -3,10 +3,19 @@ import { jsonEncoder } from './wsClient/encoder';
|
|
|
3
3
|
import type { WebSocketClientOptions } from './wsClient/options';
|
|
4
4
|
import { WsClient } from './wsClient/wsClient';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Opens and manages a WebSocket connection to a tRPC server. Pass it to
|
|
8
|
+
* `wsLink`.
|
|
9
|
+
*
|
|
10
|
+
* @see https://trpc.io/docs/client/links/wsLink#wslink--createwsclient-options
|
|
11
|
+
*/
|
|
6
12
|
export function createWSClient(opts: WebSocketClientOptions) {
|
|
7
13
|
return new WsClient(opts);
|
|
8
14
|
}
|
|
9
15
|
|
|
16
|
+
/**
|
|
17
|
+
* The client returned by {@link createWSClient}.
|
|
18
|
+
*/
|
|
10
19
|
export type TRPCWebSocketClient = ReturnType<typeof createWSClient>;
|
|
11
20
|
|
|
12
21
|
export { jsonEncoder, type Encoder, type WebSocketClientOptions };
|
|
@@ -2,6 +2,9 @@ import type { Encoder } from '@trpc/server/unstable-core-do-not-import';
|
|
|
2
2
|
|
|
3
3
|
export type { Encoder };
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* The default WebSocket encoder. Sends messages as JSON text frames.
|
|
7
|
+
*/
|
|
5
8
|
export const jsonEncoder: Encoder = {
|
|
6
9
|
encode: (data) => JSON.stringify(data),
|
|
7
10
|
decode: (data) => {
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import type { UrlOptionsWithConnectionParams } from '../../internals/urlWithConnectionParams';
|
|
2
2
|
import type { Encoder } from './encoder';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Options for `createWSClient`.
|
|
6
|
+
*
|
|
7
|
+
* @see https://trpc.io/docs/client/links/wsLink#wslink--createwsclient-options
|
|
8
|
+
*/
|
|
4
9
|
export interface WebSocketClientOptions extends UrlOptionsWithConnectionParams {
|
|
5
10
|
/**
|
|
6
|
-
*
|
|
11
|
+
* The `WebSocket` class to use, for runtimes that don't have one.
|
|
7
12
|
*/
|
|
8
13
|
WebSocket?: typeof WebSocket;
|
|
9
14
|
/**
|
|
@@ -58,7 +63,7 @@ export interface WebSocketClientOptions extends UrlOptionsWithConnectionParams {
|
|
|
58
63
|
pongTimeoutMs?: number;
|
|
59
64
|
};
|
|
60
65
|
/**
|
|
61
|
-
*
|
|
66
|
+
* Encodes and decodes messages on the wire, for example as a binary format.
|
|
62
67
|
* @default jsonEncoder
|
|
63
68
|
*/
|
|
64
69
|
experimental_encoder?: Encoder;
|
|
@@ -13,10 +13,23 @@ import type {
|
|
|
13
13
|
} from './createWsClient';
|
|
14
14
|
import { createWSClient, jsonEncoder } from './createWsClient';
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Options for {@link wsLink}.
|
|
18
|
+
*
|
|
19
|
+
* @see https://trpc.io/docs/client/links/wsLink#wslink--createwsclient-options
|
|
20
|
+
*/
|
|
16
21
|
export type WebSocketLinkOptions<TRouter extends AnyRouter> = {
|
|
22
|
+
/**
|
|
23
|
+
* The client made with `createWSClient`.
|
|
24
|
+
*/
|
|
17
25
|
client: TRPCWebSocketClient;
|
|
18
26
|
} & TransformerOptions<inferClientTypes<TRouter>>;
|
|
19
27
|
|
|
28
|
+
/**
|
|
29
|
+
* A terminating link that sends calls over a WebSocket.
|
|
30
|
+
*
|
|
31
|
+
* @see https://trpc.io/docs/client/links/wsLink
|
|
32
|
+
*/
|
|
20
33
|
export function wsLink<TRouter extends AnyRouter>(
|
|
21
34
|
opts: WebSocketLinkOptions<TRouter>,
|
|
22
35
|
): TRPCLink<TRouter> {
|