@trpc/client 11.14.0 → 11.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -0
- package/bin/intent.js +20 -0
- package/dist/{httpBatchLink.d-B6vCg-F-.d.mts → httpBatchLink.d-p8Y9QM8p.d.mts} +3 -3
- package/dist/{httpBatchLink.d-B6vCg-F-.d.mts.map → httpBatchLink.d-p8Y9QM8p.d.mts.map} +1 -1
- package/dist/{httpLink.d-CVOTlkUT.d.mts → httpLink.d-CjpPCq4q.d.mts} +3 -3
- package/dist/{httpLink.d-CVOTlkUT.d.mts.map → httpLink.d-CjpPCq4q.d.mts.map} +1 -1
- package/dist/{httpUtils.d-yYSKGhiS.d.mts → httpUtils.d-C5t5to0D.d.mts} +2 -2
- package/dist/{httpUtils.d-yYSKGhiS.d.mts.map → httpUtils.d-C5t5to0D.d.mts.map} +1 -1
- package/dist/index.d.mts +7 -7
- package/dist/links/httpBatchLink.d.mts +3 -3
- package/dist/links/httpLink.d.mts +3 -3
- package/dist/links/loggerLink.d.mts +2 -2
- package/dist/links/splitLink.d.mts +2 -2
- package/dist/links/wsLink/wsLink.d.mts +2 -2
- package/dist/{loggerLink.d-DBRq_5Gd.d.mts → loggerLink.d-0ABgt7oh.d.mts} +2 -2
- package/dist/{loggerLink.d-DBRq_5Gd.d.mts.map → loggerLink.d-0ABgt7oh.d.mts.map} +1 -1
- package/dist/{splitLink.d-BKr9eE0o.d.mts → splitLink.d-CkHNg1Se.d.mts} +2 -2
- package/dist/{splitLink.d-BKr9eE0o.d.mts.map → splitLink.d-CkHNg1Se.d.mts.map} +1 -1
- package/dist/{types.d-sRNtuQA-.d.mts → types.d-CAr6snH0.d.mts} +2 -2
- package/dist/{types.d-sRNtuQA-.d.mts.map → types.d-CAr6snH0.d.mts.map} +1 -1
- package/dist/{wsLink.d-DCqbZKOH.d.mts → wsLink.d-pFN64NkG.d.mts} +2 -2
- package/dist/{wsLink.d-DCqbZKOH.d.mts.map → wsLink.d-pFN64NkG.d.mts.map} +1 -1
- package/package.json +15 -5
- package/skills/client-setup/SKILL.md +317 -0
- package/skills/links/SKILL.md +300 -0
- package/skills/links/references/link-options.md +248 -0
- package/skills/superjson/SKILL.md +273 -0
package/README.md
CHANGED
|
@@ -36,6 +36,14 @@ pnpm add @trpc/client
|
|
|
36
36
|
bun add @trpc/client
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
+
## AI Agents
|
|
40
|
+
|
|
41
|
+
If you use an AI coding agent, install tRPC skills for better code generation:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
npx @tanstack/intent@latest install
|
|
45
|
+
```
|
|
46
|
+
|
|
39
47
|
## Basic Example
|
|
40
48
|
|
|
41
49
|
```ts
|
package/bin/intent.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Auto-generated by @tanstack/intent setup
|
|
3
|
+
// Exposes the intent end-user CLI for consumers of this library.
|
|
4
|
+
// Commit this file, then add to your package.json:
|
|
5
|
+
// "bin": { "intent": "./bin/intent.js" }
|
|
6
|
+
try {
|
|
7
|
+
await import('@tanstack/intent/intent-library');
|
|
8
|
+
} catch (e) {
|
|
9
|
+
if (e?.code === 'ERR_MODULE_NOT_FOUND' || e?.code === 'MODULE_NOT_FOUND') {
|
|
10
|
+
console.error('@tanstack/intent is not installed.');
|
|
11
|
+
console.error('');
|
|
12
|
+
console.error('Install it as a dev dependency:');
|
|
13
|
+
console.error(' npm add -D @tanstack/intent');
|
|
14
|
+
console.error('');
|
|
15
|
+
console.error('Or run directly:');
|
|
16
|
+
console.error(' npx @tanstack/intent@latest list');
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
throw e;
|
|
20
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { HTTPHeaders, NonEmptyArray, Operation, TRPCLink } from "./types.d-
|
|
2
|
-
import { HTTPLinkBaseOptions } from "./httpUtils.d-
|
|
1
|
+
import { HTTPHeaders, NonEmptyArray, Operation, TRPCLink } from "./types.d-CAr6snH0.mjs";
|
|
2
|
+
import { HTTPLinkBaseOptions } from "./httpUtils.d-C5t5to0D.mjs";
|
|
3
3
|
import { AnyClientTypes } from "@trpc/server/unstable-core-do-not-import";
|
|
4
4
|
import { AnyRouter as AnyRouter$1 } from "@trpc/server";
|
|
5
5
|
|
|
@@ -30,4 +30,4 @@ declare function httpBatchLink<TRouter extends AnyRouter$1>(opts: HTTPBatchLinkO
|
|
|
30
30
|
|
|
31
31
|
//#endregion
|
|
32
32
|
export { HTTPBatchLinkOptions, httpBatchLink };
|
|
33
|
-
//# sourceMappingURL=httpBatchLink.d-
|
|
33
|
+
//# sourceMappingURL=httpBatchLink.d-p8Y9QM8p.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"httpBatchLink.d-
|
|
1
|
+
{"version":3,"file":"httpBatchLink.d-p8Y9QM8p.d.mts","names":[],"sources":["../src/links/HTTPBatchLinkOptions.ts","../src/links/httpBatchLink.ts"],"sourcesContent":[],"mappings":";;;;;;KAKY,mCAAmC,kBAC7C,oBAAoB;;EADV;;;;EACe,OAAzB,CAAA,EAOM,WAPN,GAAA,CAAA,CAAA,IAAA,EAAA;IAOM,MAAA,EAEU,aAFV,CAEwB,SAFxB,CAAA;EAAW,CAAA,EAEa,GAClB,WADkB,GACJ,OADI,CACI,WADJ,CAAA,CAAA;EAAS;;;;EACN,QAAA,CAAA,EAAA,MAAA;;;;;;;;AAXvB,iBCeI,aDfgB,CAAA,gBCec,WDfd,CAAA,CAAA,IAAA,ECgBxB,oBDhBwB,CCgBH,ODhBG,CAAA,MAAA,CAAA,CAAA,SAAA,CAAA,CAAA,QAAA,CAAA,CAAA,CAAA,ECiB7B,QDjB6B,CCiBpB,ODjBoB,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { HTTPHeaders, Operation, TRPCLink } from "./types.d-
|
|
2
|
-
import { HTTPLinkBaseOptions } from "./httpUtils.d-
|
|
1
|
+
import { HTTPHeaders, Operation, TRPCLink } from "./types.d-CAr6snH0.mjs";
|
|
2
|
+
import { HTTPLinkBaseOptions } from "./httpUtils.d-C5t5to0D.mjs";
|
|
3
3
|
import { AnyClientTypes, AnyRouter } from "@trpc/server/unstable-core-do-not-import";
|
|
4
4
|
|
|
5
5
|
//#region src/links/httpLink.d.ts
|
|
@@ -20,4 +20,4 @@ declare function httpLink<TRouter extends AnyRouter = AnyRouter>(opts: HTTPLinkO
|
|
|
20
20
|
|
|
21
21
|
//#endregion
|
|
22
22
|
export { HTTPLinkOptions, httpLink };
|
|
23
|
-
//# sourceMappingURL=httpLink.d-
|
|
23
|
+
//# sourceMappingURL=httpLink.d-CjpPCq4q.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"httpLink.d-
|
|
1
|
+
{"version":3,"file":"httpLink.d-CjpPCq4q.d.mts","names":[],"sources":["../src/links/httpLink.ts"],"sourcesContent":[],"mappings":";;;;;KA0BY,8BAA8B,kBACxC,oBAAoB;;AADtB;;;EAAwD,OAClC,CAAA,EAMd,WANc,GAAA,CAAA,CAAA,IAAA,EAAA;IAApB,EAAA,EAOoB,SAPpB;EAAmB,CAAA,EAMb,GAC8B,WAD9B,GAC4C,OAD5C,CACoD,WADpD,CAAA,CAAA;CAAW;;;;AACwC,iBAwC3C,QAxC2C,CAAA,gBAwClB,SAxCkB,GAwCN,SAxCM,CAAA,CAAA,IAAA,EAyCnD,eAzCmD,CAyCnC,OAzCmC,CAAA,MAAA,CAAA,CAAA,SAAA,CAAA,CAAA,QAAA,CAAA,CAAA,CAAA,EA0CxD,QA1CwD,CA0C/C,OA1C+C,CAAA;AAwC3D"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FetchEsque } from "./types.d-
|
|
1
|
+
import { FetchEsque } from "./types.d-CAr6snH0.mjs";
|
|
2
2
|
import { TransformerOptions } from "./unstable-internals.d-BOmV7EK1.mjs";
|
|
3
3
|
import { AnyClientTypes, CombinedDataTransformer, Maybe, ProcedureType } from "@trpc/server/unstable-core-do-not-import";
|
|
4
4
|
|
|
@@ -22,4 +22,4 @@ type HTTPLinkBaseOptions<TRoot extends Pick<AnyClientTypes, 'transformer'>> = {
|
|
|
22
22
|
} & TransformerOptions<TRoot>;
|
|
23
23
|
//#endregion
|
|
24
24
|
export { HTTPLinkBaseOptions };
|
|
25
|
-
//# sourceMappingURL=httpUtils.d-
|
|
25
|
+
//# sourceMappingURL=httpUtils.d-C5t5to0D.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"httpUtils.d-
|
|
1
|
+
{"version":3,"file":"httpUtils.d-C5t5to0D.d.mts","names":[],"sources":["../src/links/internals/httpUtils.ts"],"sourcesContent":[],"mappings":";;;;;;;AAqBA;;AACqB,KADT,mBACS,CAAA,cAAL,IAAK,CAAA,cAAA,EAAA,aAAA,CAAA,CAAA,GAAA;EAAc,GAAnB,EAAA,MAAA,GAEA,GAFA;EAAI;;;EAaQ,KAAxB,CAAA,EAPM,UAON;EAAkB;;;;;;IAAlB,mBAAmB"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { TRPCConnectionState } from "./subscriptions.d-Dlr1nWGD.mjs";
|
|
2
|
-
import { FetchEsque, HTTPHeaders, NativeFetchEsque, Operation, OperationContext, OperationLink, OperationResultEnvelope, OperationResultObservable, OperationResultObserver, TRPCClientError, TRPCClientErrorBase, TRPCClientErrorLike, TRPCClientRuntime, TRPCFetch, TRPCLink, TRPCProcedureOptions, isFormData, isNonJsonSerializable, isOctetType, isTRPCClientError } from "./types.d-
|
|
2
|
+
import { FetchEsque, HTTPHeaders, NativeFetchEsque, Operation, OperationContext, OperationLink, OperationResultEnvelope, OperationResultObservable, OperationResultObserver, TRPCClientError, TRPCClientErrorBase, TRPCClientErrorLike, TRPCClientRuntime, TRPCFetch, TRPCLink, TRPCProcedureOptions, isFormData, isNonJsonSerializable, isOctetType, isTRPCClientError } from "./types.d-CAr6snH0.mjs";
|
|
3
3
|
import { TransformerOptions } from "./unstable-internals.d-BOmV7EK1.mjs";
|
|
4
|
-
import "./httpUtils.d-
|
|
5
|
-
import { HTTPBatchLinkOptions, httpBatchLink } from "./httpBatchLink.d-
|
|
6
|
-
import { HTTPLinkOptions, httpLink } from "./httpLink.d-
|
|
7
|
-
import { LoggerLinkOptions, loggerLink } from "./loggerLink.d-
|
|
8
|
-
import { splitLink } from "./splitLink.d-
|
|
9
|
-
import { Encoder, TRPCWebSocketClient, UrlOptionsWithConnectionParams, WebSocketClientOptions, WebSocketLinkOptions, createWSClient, jsonEncoder, wsLink } from "./wsLink.d-
|
|
4
|
+
import "./httpUtils.d-C5t5to0D.mjs";
|
|
5
|
+
import { HTTPBatchLinkOptions, httpBatchLink } from "./httpBatchLink.d-p8Y9QM8p.mjs";
|
|
6
|
+
import { HTTPLinkOptions, httpLink } from "./httpLink.d-CjpPCq4q.mjs";
|
|
7
|
+
import { LoggerLinkOptions, loggerLink } from "./loggerLink.d-0ABgt7oh.mjs";
|
|
8
|
+
import { splitLink } from "./splitLink.d-CkHNg1Se.mjs";
|
|
9
|
+
import { Encoder, TRPCWebSocketClient, UrlOptionsWithConnectionParams, WebSocketClientOptions, WebSocketLinkOptions, createWSClient, jsonEncoder, wsLink } from "./wsLink.d-pFN64NkG.mjs";
|
|
10
10
|
import { Unsubscribable } from "@trpc/server/observable";
|
|
11
11
|
import { AnyClientTypes, AnyProcedure, AnyRouter, ErrorHandlerOptions, EventSourceLike, InferrableClientTypes, ProcedureType, RouterRecord, TypeError, inferAsyncIterableYield, inferClientTypes, inferProcedureInput, inferRouterContext, inferTransformedProcedureOutput } from "@trpc/server/unstable-core-do-not-import";
|
|
12
12
|
import { AnyRouter as AnyRouter$1 } from "@trpc/server";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "../subscriptions.d-Dlr1nWGD.mjs";
|
|
2
|
-
import "../types.d-
|
|
2
|
+
import "../types.d-CAr6snH0.mjs";
|
|
3
3
|
import "../unstable-internals.d-BOmV7EK1.mjs";
|
|
4
|
-
import "../httpUtils.d-
|
|
5
|
-
import { httpBatchLink } from "../httpBatchLink.d-
|
|
4
|
+
import "../httpUtils.d-C5t5to0D.mjs";
|
|
5
|
+
import { httpBatchLink } from "../httpBatchLink.d-p8Y9QM8p.mjs";
|
|
6
6
|
export { httpBatchLink };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "../subscriptions.d-Dlr1nWGD.mjs";
|
|
2
|
-
import "../types.d-
|
|
2
|
+
import "../types.d-CAr6snH0.mjs";
|
|
3
3
|
import "../unstable-internals.d-BOmV7EK1.mjs";
|
|
4
|
-
import "../httpUtils.d-
|
|
5
|
-
import { HTTPLinkOptions, httpLink } from "../httpLink.d-
|
|
4
|
+
import "../httpUtils.d-C5t5to0D.mjs";
|
|
5
|
+
import { HTTPLinkOptions, httpLink } from "../httpLink.d-CjpPCq4q.mjs";
|
|
6
6
|
export { HTTPLinkOptions, httpLink };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import "../subscriptions.d-Dlr1nWGD.mjs";
|
|
2
|
-
import "../types.d-
|
|
3
|
-
import { LoggerLinkOptions, loggerLink } from "../loggerLink.d-
|
|
2
|
+
import "../types.d-CAr6snH0.mjs";
|
|
3
|
+
import { LoggerLinkOptions, loggerLink } from "../loggerLink.d-0ABgt7oh.mjs";
|
|
4
4
|
export { LoggerLinkOptions, loggerLink };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "../../subscriptions.d-Dlr1nWGD.mjs";
|
|
2
|
-
import "../../types.d-
|
|
2
|
+
import "../../types.d-CAr6snH0.mjs";
|
|
3
3
|
import "../../unstable-internals.d-BOmV7EK1.mjs";
|
|
4
|
-
import { Encoder, TRPCWebSocketClient, WebSocketClientOptions, WebSocketLinkOptions, createWSClient, jsonEncoder, wsLink } from "../../wsLink.d-
|
|
4
|
+
import { Encoder, TRPCWebSocketClient, WebSocketClientOptions, WebSocketLinkOptions, createWSClient, jsonEncoder, wsLink } from "../../wsLink.d-pFN64NkG.mjs";
|
|
5
5
|
export { Encoder, TRPCWebSocketClient, WebSocketClientOptions, WebSocketLinkOptions, createWSClient, jsonEncoder, wsLink };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Operation, OperationResultEnvelope, TRPCClientError, TRPCLink } from "./types.d-
|
|
1
|
+
import { Operation, OperationResultEnvelope, TRPCClientError, TRPCLink } from "./types.d-CAr6snH0.mjs";
|
|
2
2
|
import { AnyRouter, InferrableClientTypes } from "@trpc/server/unstable-core-do-not-import";
|
|
3
3
|
|
|
4
4
|
//#region src/links/loggerLink.d.ts
|
|
@@ -51,4 +51,4 @@ interface LoggerLinkOptions<TRouter extends AnyRouter> {
|
|
|
51
51
|
declare function loggerLink<TRouter extends AnyRouter = AnyRouter>(opts?: LoggerLinkOptions<TRouter>): TRPCLink<TRouter>;
|
|
52
52
|
//#endregion
|
|
53
53
|
export { LoggerLinkOptions, loggerLink };
|
|
54
|
-
//# sourceMappingURL=loggerLink.d-
|
|
54
|
+
//# sourceMappingURL=loggerLink.d-0ABgt7oh.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loggerLink.d-
|
|
1
|
+
{"version":3,"file":"loggerLink.d-0ABgt7oh.d.mts","names":[],"sources":["../src/links/loggerLink.ts"],"sourcesContent":[],"mappings":";;;;KAeK,YAAA;EAAA,GAAA,EAAA,CAAA,GAAA,IAAA,EAAY,GAAA,EAAA,EAAA,GAAA,IAAA;EAKZ,KAAA,EAAA,CAAA,GAAA,IAAA,EAAA,GAAe,EAAA,EAAA,GAAA,IAAA;CAAA;KAAf,eAAgC,CAAA,gBAAA,qBAAA,CAAA,GAAA;EAAqB,SAIC,EAAA,MAAA;EAAO,MAAvB,EAAjC,uBAAiC,CAAA,OAAA,EAAA,eAAA,CAAgB,OAAhB,CAAA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ation, TRPCLink } from "./types.d-CAr6snH0.mjs";
|
|
2
2
|
import { AnyRouter } from "@trpc/server/unstable-core-do-not-import";
|
|
3
3
|
|
|
4
4
|
//#region src/links/splitLink.d.ts
|
|
@@ -17,4 +17,4 @@ declare function splitLink<TRouter extends AnyRouter = AnyRouter>(opts: {
|
|
|
17
17
|
|
|
18
18
|
//#endregion
|
|
19
19
|
export { splitLink };
|
|
20
|
-
//# sourceMappingURL=splitLink.d-
|
|
20
|
+
//# sourceMappingURL=splitLink.d-CkHNg1Se.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"splitLink.d-
|
|
1
|
+
{"version":3,"file":"splitLink.d-CkHNg1Se.d.mts","names":[],"sources":["../src/links/splitLink.ts"],"sourcesContent":[],"mappings":";;;;iBAQgB,0BAA0B,YAAY;kBACpC;EADF;;;EAAmC,IAAG,EAK9C,QAL8C,CAKrC,OALqC,CAAA,GAK1B,QAL0B,CAKjB,OALiB,CAAA,EAAA;EAAS;;;EAK/C,KAAqB,EAI5B,QAJ4B,CAInB,OAJmB,CAAA,GAIR,QAJQ,CAIC,OAJD,CAAA,EAAA;CAAO,CAAA,EAKxC,QALwB,CAKf,OALe,CAAA"}
|
|
@@ -118,7 +118,7 @@ declare class TRPCClientError<TRouterOrProcedure extends InferrableClientTypes>
|
|
|
118
118
|
//#region src/links/internals/contentTypes.d.ts
|
|
119
119
|
declare function isOctetType(input: unknown): input is Uint8Array<ArrayBuffer> | Blob;
|
|
120
120
|
declare function isFormData(input: unknown): input is FormData;
|
|
121
|
-
declare function isNonJsonSerializable(input: unknown): input is
|
|
121
|
+
declare function isNonJsonSerializable(input: unknown): input is FormData | Uint8Array<ArrayBuffer> | Blob;
|
|
122
122
|
//# sourceMappingURL=contentTypes.d.ts.map
|
|
123
123
|
|
|
124
124
|
//#endregion
|
|
@@ -181,4 +181,4 @@ type TRPCLink<TInferrable extends InferrableClientTypes> = (opts: TRPCClientRunt
|
|
|
181
181
|
|
|
182
182
|
//#endregion
|
|
183
183
|
export { FetchEsque, HTTPHeaders, NativeFetchEsque, NonEmptyArray, Operation, OperationContext, OperationLink, OperationResultEnvelope, OperationResultObservable, OperationResultObserver, TRPCClientError, TRPCClientErrorBase, TRPCClientErrorLike, TRPCClientRuntime, TRPCFetch, TRPCLink, TRPCProcedureOptions, isFormData, isNonJsonSerializable, isOctetType, isTRPCClientError };
|
|
184
|
-
//# sourceMappingURL=types.d-
|
|
184
|
+
//# sourceMappingURL=types.d-CAr6snH0.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d-
|
|
1
|
+
{"version":3,"file":"types.d-CAr6snH0.d.mts","names":[],"sources":["../src/internals/types.ts","../src/TRPCClientError.ts","../src/links/internals/contentTypes.ts","../src/links/types.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;AAOA;;AACS,KADG,UAAA,GACH,CAAA,KAAA,EAAA,WAAA,GAAc,GAAd,GAAA,MAAA,EAAA,IAAA,CAAA,EACA,WADA,GACc,gBADd,EAAA,GAEJ,OAFI,CAEI,aAFJ,CAAA;;;;;AAEJ,KAMO,gBAAA,GANP,CAAA,GAAA,EAOE,GAPF,GAAA,MAAA,EAAA,IAAA,CAAA,EAQI,yBARJ,EAAA,GASA,OATA,CASQ,aATR,CAAA;AAAO,UAWK,yBAAA,CAXL;EAMA,IAAA,CAAA,EAAA,MAAA;;;;;;AAGA;AAEZ;AAWA;AAAiC,UAAhB,gBAAA,CAAgB;EAAA;;;EAIa,IAAgB,CAAA,EAArD,QAAqD,GAAA,MAAA,GAAA,IAAA,GAA1B,UAA0B,CAAf,WAAe,CAAA,GAAA,IAAA,GAAO,IAAP;EAAI;;;EAe5C,OAAA,CAAA,EAAA,CAAA,MAAA,EAAA,MAAA,CAAA,EAAA,GAVW,MAUX,CAAA,MAAA,EAAA,MAAA,CAAA;EAOV;;;EAC6C,MAAtC,CAAA,EAAA,MAAA;EAA2B;AAG9C;AAWA;EAA8B,MAAA,CAAA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OAAA,CAAA,GAAA,CAAA,IAAA,EAAA;MGDhB,UAAU;aAER,UAAU,YACX,0BAA0B,aAAa;MACxC,0BAA0B,aAAa;AF9FK;;;AAG/B,KEgGP,QFhGO,CAAA,oBEgGsB,qBFhGtB,CAAA,GAAA,CAAA,IAAA,EEiGX,iBFjGW,EAAA,GEkGd,aFlGc,CEkGA,WFlGA,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TRPCConnectionState } from "./subscriptions.d-Dlr1nWGD.mjs";
|
|
2
|
-
import { Operation, OperationResultEnvelope, TRPCClientError, TRPCLink } from "./types.d-
|
|
2
|
+
import { Operation, OperationResultEnvelope, TRPCClientError, TRPCLink } from "./types.d-CAr6snH0.mjs";
|
|
3
3
|
import { TransformerOptions } from "./unstable-internals.d-BOmV7EK1.mjs";
|
|
4
4
|
import * as _trpc_server_observable0 from "@trpc/server/observable";
|
|
5
5
|
import { BehaviorSubject } from "@trpc/server/observable";
|
|
@@ -203,4 +203,4 @@ type WebSocketLinkOptions<TRouter extends AnyRouter> = {
|
|
|
203
203
|
declare function wsLink<TRouter extends AnyRouter>(opts: WebSocketLinkOptions<TRouter>): TRPCLink<TRouter>;
|
|
204
204
|
//#endregion
|
|
205
205
|
export { Encoder, TRPCWebSocketClient, UrlOptionsWithConnectionParams, WebSocketClientOptions, WebSocketLinkOptions, createWSClient, jsonEncoder, wsLink };
|
|
206
|
-
//# sourceMappingURL=wsLink.d-
|
|
206
|
+
//# sourceMappingURL=wsLink.d-pFN64NkG.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wsLink.d-
|
|
1
|
+
{"version":3,"file":"wsLink.d-pFN64NkG.d.mts","names":[],"sources":["../src/links/wsLink/wsClient/encoder.ts","../src/links/internals/urlWithConnectionParams.ts","../src/links/wsLink/wsClient/options.ts","../src/links/wsLink/wsClient/wsClient.ts","../src/links/wsLink/createWsClient.ts","../src/links/wsLink/wsLink.ts"],"sourcesContent":[],"m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3
3
|
"type": "module",
|
|
4
|
-
"version": "11.14.
|
|
4
|
+
"version": "11.14.1",
|
|
5
5
|
"description": "The tRPC client library",
|
|
6
6
|
"author": "KATT",
|
|
7
7
|
"license": "MIT",
|
|
@@ -109,14 +109,18 @@
|
|
|
109
109
|
"links",
|
|
110
110
|
"unstable-internals",
|
|
111
111
|
"!**/*.test.*",
|
|
112
|
-
"!**/__tests__"
|
|
112
|
+
"!**/__tests__",
|
|
113
|
+
"skills",
|
|
114
|
+
"!skills/_artifacts",
|
|
115
|
+
"bin"
|
|
113
116
|
],
|
|
114
117
|
"peerDependencies": {
|
|
115
|
-
"@trpc/server": "11.14.
|
|
118
|
+
"@trpc/server": "11.14.1",
|
|
116
119
|
"typescript": ">=5.7.2"
|
|
117
120
|
},
|
|
118
121
|
"devDependencies": {
|
|
119
|
-
"@
|
|
122
|
+
"@tanstack/intent": "^0.0.20",
|
|
123
|
+
"@trpc/server": "11.14.1",
|
|
120
124
|
"@types/isomorphic-fetch": "^0.0.39",
|
|
121
125
|
"@types/node": "^22.13.5",
|
|
122
126
|
"dataloader": "^2.2.2",
|
|
@@ -135,5 +139,11 @@
|
|
|
135
139
|
"funding": [
|
|
136
140
|
"https://trpc.io/sponsor"
|
|
137
141
|
],
|
|
138
|
-
"
|
|
142
|
+
"keywords": [
|
|
143
|
+
"tanstack-intent"
|
|
144
|
+
],
|
|
145
|
+
"bin": {
|
|
146
|
+
"intent": "./bin/intent.js"
|
|
147
|
+
},
|
|
148
|
+
"gitHead": "e896259af491fc4b1c9e8fc320817e2222bae869"
|
|
139
149
|
}
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: client-setup
|
|
3
|
+
description: >
|
|
4
|
+
Create a vanilla tRPC client with createTRPCClient<AppRouter>(), configure
|
|
5
|
+
link chain with httpBatchLink/httpLink, dynamic headers for auth, transformer
|
|
6
|
+
on links (not client constructor). Infer types with inferRouterInputs and
|
|
7
|
+
inferRouterOutputs. AbortController signal support. TRPCClientError typing.
|
|
8
|
+
type: core
|
|
9
|
+
library: trpc
|
|
10
|
+
library_version: '11.14.0'
|
|
11
|
+
requires:
|
|
12
|
+
- server-setup
|
|
13
|
+
sources:
|
|
14
|
+
- www/docs/client/overview.md
|
|
15
|
+
- www/docs/client/vanilla/overview.md
|
|
16
|
+
- www/docs/client/vanilla/setup.mdx
|
|
17
|
+
- www/docs/client/vanilla/infer-types.md
|
|
18
|
+
- www/docs/client/headers.md
|
|
19
|
+
- packages/client/src/internals/TRPCUntypedClient.ts
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
# tRPC -- Client Setup
|
|
23
|
+
|
|
24
|
+
## Setup
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
// server.ts
|
|
28
|
+
import { initTRPC } from '@trpc/server';
|
|
29
|
+
import { z } from 'zod';
|
|
30
|
+
|
|
31
|
+
const t = initTRPC.create();
|
|
32
|
+
|
|
33
|
+
const appRouter = t.router({
|
|
34
|
+
user: t.router({
|
|
35
|
+
byId: t.procedure
|
|
36
|
+
.input(z.object({ id: z.string() }))
|
|
37
|
+
.query(({ input }) => ({ id: input.id, name: 'Bilbo' })),
|
|
38
|
+
create: t.procedure
|
|
39
|
+
.input(z.object({ name: z.string() }))
|
|
40
|
+
.mutation(({ input }) => ({ id: '1', ...input })),
|
|
41
|
+
}),
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
export type AppRouter = typeof appRouter;
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
// client.ts
|
|
49
|
+
import { createTRPCClient, httpBatchLink } from '@trpc/client';
|
|
50
|
+
import type { AppRouter } from './server';
|
|
51
|
+
|
|
52
|
+
const client = createTRPCClient<AppRouter>({
|
|
53
|
+
links: [
|
|
54
|
+
httpBatchLink({
|
|
55
|
+
url: 'http://localhost:3000/trpc',
|
|
56
|
+
}),
|
|
57
|
+
],
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const user = await client.user.byId.query({ id: '1' });
|
|
61
|
+
const created = await client.user.create.mutate({ name: 'Frodo' });
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Core Patterns
|
|
65
|
+
|
|
66
|
+
### Dynamic Auth Headers
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
import { createTRPCClient, httpBatchLink } from '@trpc/client';
|
|
70
|
+
import type { AppRouter } from './server';
|
|
71
|
+
|
|
72
|
+
let token = '';
|
|
73
|
+
|
|
74
|
+
export function setToken(newToken: string) {
|
|
75
|
+
token = newToken;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export const client = createTRPCClient<AppRouter>({
|
|
79
|
+
links: [
|
|
80
|
+
httpBatchLink({
|
|
81
|
+
url: 'http://localhost:3000/trpc',
|
|
82
|
+
headers() {
|
|
83
|
+
return {
|
|
84
|
+
Authorization: token ? `Bearer ${token}` : '',
|
|
85
|
+
};
|
|
86
|
+
},
|
|
87
|
+
}),
|
|
88
|
+
],
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
The `headers` callback is invoked on every HTTP request, so token changes take effect immediately.
|
|
93
|
+
|
|
94
|
+
### Inferring Procedure Input and Output Types
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
import type { inferRouterInputs, inferRouterOutputs } from '@trpc/server';
|
|
98
|
+
import type { AppRouter } from './server';
|
|
99
|
+
|
|
100
|
+
type RouterInput = inferRouterInputs<AppRouter>;
|
|
101
|
+
type RouterOutput = inferRouterOutputs<AppRouter>;
|
|
102
|
+
|
|
103
|
+
type UserCreateInput = RouterInput['user']['create'];
|
|
104
|
+
type UserByIdOutput = RouterOutput['user']['byId'];
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Aborting Requests with AbortController
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
import { createTRPCClient, httpBatchLink } from '@trpc/client';
|
|
111
|
+
import type { AppRouter } from './server';
|
|
112
|
+
|
|
113
|
+
const client = createTRPCClient<AppRouter>({
|
|
114
|
+
links: [httpBatchLink({ url: 'http://localhost:3000/trpc' })],
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
const ac = new AbortController();
|
|
118
|
+
const query = client.user.byId.query({ id: '1' }, { signal: ac.signal });
|
|
119
|
+
ac.abort();
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Typed Error Handling
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
import { TRPCClientError } from '@trpc/client';
|
|
126
|
+
import type { AppRouter } from './server';
|
|
127
|
+
|
|
128
|
+
function isTRPCClientError(
|
|
129
|
+
cause: unknown,
|
|
130
|
+
): cause is TRPCClientError<AppRouter> {
|
|
131
|
+
return cause instanceof TRPCClientError;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
try {
|
|
135
|
+
await client.user.byId.query({ id: '1' });
|
|
136
|
+
} catch (cause) {
|
|
137
|
+
if (isTRPCClientError(cause)) {
|
|
138
|
+
console.log('tRPC error code:', cause.data?.code);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Common Mistakes
|
|
144
|
+
|
|
145
|
+
### [CRITICAL] Missing AppRouter type parameter on createTRPCClient
|
|
146
|
+
|
|
147
|
+
Wrong:
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
const client = createTRPCClient({ links: [httpBatchLink({ url })] });
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Correct:
|
|
154
|
+
|
|
155
|
+
```ts
|
|
156
|
+
import type { AppRouter } from './server';
|
|
157
|
+
|
|
158
|
+
const client = createTRPCClient<AppRouter>({ links: [httpBatchLink({ url })] });
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Without the type parameter, all procedure calls return `any` and type safety is completely lost.
|
|
162
|
+
|
|
163
|
+
Source: www/docs/client/vanilla/setup.mdx
|
|
164
|
+
|
|
165
|
+
### [CRITICAL] Transformer goes on individual links, not createTRPCClient
|
|
166
|
+
|
|
167
|
+
In v11, the `transformer` option is on individual terminating links, not the client constructor:
|
|
168
|
+
|
|
169
|
+
```ts
|
|
170
|
+
import superjson from 'superjson';
|
|
171
|
+
|
|
172
|
+
createTRPCClient<AppRouter>({
|
|
173
|
+
links: [
|
|
174
|
+
httpBatchLink({
|
|
175
|
+
url: 'http://localhost:3000',
|
|
176
|
+
transformer: superjson,
|
|
177
|
+
}),
|
|
178
|
+
],
|
|
179
|
+
});
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
In v11, the `transformer` option was moved from the client constructor to individual terminating links. Passing it to `createTRPCClient` throws a TypeError.
|
|
183
|
+
|
|
184
|
+
Source: packages/client/src/internals/TRPCUntypedClient.ts
|
|
185
|
+
|
|
186
|
+
### [CRITICAL] Transformer on server but not on client links
|
|
187
|
+
|
|
188
|
+
Wrong:
|
|
189
|
+
|
|
190
|
+
```ts
|
|
191
|
+
// Server: initTRPC.create({ transformer: superjson })
|
|
192
|
+
// Client:
|
|
193
|
+
httpBatchLink({ url: 'http://localhost:3000' });
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Correct:
|
|
197
|
+
|
|
198
|
+
```ts
|
|
199
|
+
// Server: initTRPC.create({ transformer: superjson })
|
|
200
|
+
// Client:
|
|
201
|
+
httpBatchLink({ url: 'http://localhost:3000', transformer: superjson });
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
If the server uses a transformer, every terminating link on the client must also specify that transformer. Mismatch causes "Unable to transform response" errors.
|
|
205
|
+
|
|
206
|
+
Source: https://github.com/trpc/trpc/issues/7083
|
|
207
|
+
|
|
208
|
+
### [CRITICAL] Using import instead of import type for AppRouter
|
|
209
|
+
|
|
210
|
+
Wrong:
|
|
211
|
+
|
|
212
|
+
```ts
|
|
213
|
+
import { AppRouter } from '../server/router';
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
Correct:
|
|
217
|
+
|
|
218
|
+
```ts
|
|
219
|
+
import type { AppRouter } from '../server/router';
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
A non-type import pulls the entire server bundle into the client. Use `import type` so it is erased at build time.
|
|
223
|
+
|
|
224
|
+
Source: www/docs/client/vanilla/setup.mdx
|
|
225
|
+
|
|
226
|
+
### [CRITICAL] Importing appRouter value to derive type in client
|
|
227
|
+
|
|
228
|
+
Wrong:
|
|
229
|
+
|
|
230
|
+
```ts
|
|
231
|
+
import { appRouter } from '../server/router';
|
|
232
|
+
|
|
233
|
+
type AppRouter = typeof appRouter;
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
Correct:
|
|
237
|
+
|
|
238
|
+
```ts
|
|
239
|
+
// In server: export type AppRouter = typeof appRouter;
|
|
240
|
+
// In client:
|
|
241
|
+
import type { AppRouter } from '../server/router';
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
Importing the `appRouter` value (not just the type) bundles the entire server into the client, shipping server code to the browser.
|
|
245
|
+
|
|
246
|
+
Source: www/docs/server/routers.md
|
|
247
|
+
|
|
248
|
+
### [CRITICAL] Using type assertions to bypass AppRouter import errors
|
|
249
|
+
|
|
250
|
+
Wrong:
|
|
251
|
+
|
|
252
|
+
```ts
|
|
253
|
+
const client = createTRPCClient<any>({ links: [httpBatchLink({ url })] });
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
Correct:
|
|
257
|
+
|
|
258
|
+
```ts
|
|
259
|
+
// Fix the import path or monorepo configuration
|
|
260
|
+
import type { AppRouter } from '@myorg/api-types';
|
|
261
|
+
|
|
262
|
+
const client = createTRPCClient<AppRouter>({ links: [httpBatchLink({ url })] });
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
Casting to `any` or manually recreating the router type destroys end-to-end type safety. Fix the import path or monorepo config instead.
|
|
266
|
+
|
|
267
|
+
Source: www/docs/client/vanilla/setup.mdx
|
|
268
|
+
|
|
269
|
+
### [CRITICAL] Using createTRPCProxyClient (renamed in v11)
|
|
270
|
+
|
|
271
|
+
Wrong:
|
|
272
|
+
|
|
273
|
+
```ts
|
|
274
|
+
import { createTRPCProxyClient } from '@trpc/client';
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
Correct:
|
|
278
|
+
|
|
279
|
+
```ts
|
|
280
|
+
import { createTRPCClient } from '@trpc/client';
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
`createTRPCProxyClient` was renamed to `createTRPCClient` in v11.
|
|
284
|
+
|
|
285
|
+
Source: www/docs/client/vanilla/setup.mdx
|
|
286
|
+
|
|
287
|
+
### [CRITICAL] Treating tRPC as a REST API
|
|
288
|
+
|
|
289
|
+
Wrong:
|
|
290
|
+
|
|
291
|
+
```ts
|
|
292
|
+
fetch('/api/trpc/users/123', { method: 'GET' });
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
Correct:
|
|
296
|
+
|
|
297
|
+
```ts
|
|
298
|
+
const user = await client.user.byId.query({ id: '123' });
|
|
299
|
+
// Raw equivalent: GET /api/trpc/user.byId?input={"id":"123"}
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
tRPC uses JSON-RPC over HTTP. Procedures are called by dot-separated name with JSON input, not by REST resource paths.
|
|
303
|
+
|
|
304
|
+
Source: www/docs/client/overview.md
|
|
305
|
+
|
|
306
|
+
### [HIGH] HTML error page instead of JSON response
|
|
307
|
+
|
|
308
|
+
If you see `couldn't parse JSON, invalid character '<'`, the tRPC endpoint returned an HTML page (404/503) instead of JSON. This means the `url` in your link config is wrong or infrastructure routing is misconfigured -- it is not a tRPC bug. Verify the URL matches your adapter's mount point.
|
|
309
|
+
|
|
310
|
+
Source: www/docs/client/vanilla/setup.mdx
|
|
311
|
+
|
|
312
|
+
## See Also
|
|
313
|
+
|
|
314
|
+
- `links` -- configure httpBatchLink, httpLink, splitLink, and other link types
|
|
315
|
+
- `superjson` -- set up SuperJSON transformer on server and client
|
|
316
|
+
- `server-setup` -- define routers, procedures, context, and export AppRouter type
|
|
317
|
+
- `react-query-setup` -- use tRPC with TanStack React Query for React applications
|