@trpc/client 11.33.0 → 11.35.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.
- package/dist/{httpBatchLink-_bkMj4mk.d.cts → httpBatchLink-50xXDyIp.d.cts} +3 -3
- package/dist/{httpBatchLink-DaVHWlLU.d.mts.map → httpBatchLink-50xXDyIp.d.cts.map} +1 -1
- package/dist/{httpBatchLink-DaVHWlLU.d.mts → httpBatchLink-D4shlyQy.d.mts} +3 -3
- package/dist/{httpBatchLink-_bkMj4mk.d.cts.map → httpBatchLink-D4shlyQy.d.mts.map} +1 -1
- package/dist/{httpLink-DN_Ana7a.d.mts → httpLink-Bb6hOyBN.d.mts} +3 -3
- package/dist/{httpLink-DN_Ana7a.d.mts.map → httpLink-Bb6hOyBN.d.mts.map} +1 -1
- package/dist/{httpUtils-BAs5frdP.d.mts → httpUtils-BbinScxw.d.mts} +2 -2
- package/dist/{httpUtils-1z6dzl3V.d.cts.map → httpUtils-BbinScxw.d.mts.map} +1 -1
- package/dist/{httpUtils-1z6dzl3V.d.cts → httpUtils-dB1XeokQ.d.cts} +2 -2
- package/dist/{httpUtils-BAs5frdP.d.mts.map → httpUtils-dB1XeokQ.d.cts.map} +1 -1
- package/dist/index.cjs +4 -3
- package/dist/index.d.cts +37 -11
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +40 -14
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +4 -3
- package/dist/index.mjs.map +1 -1
- package/dist/links/httpBatchLink.d.cts +1 -1
- package/dist/links/httpBatchLink.d.mts +1 -1
- package/dist/links/httpLink.d.cts +2 -2
- package/dist/links/httpLink.d.mts +1 -1
- package/dist/links/loggerLink.d.cts +1 -1
- package/dist/links/loggerLink.d.mts +1 -1
- package/dist/links/splitLink.cjs +1 -1
- package/dist/links/splitLink.d.cts +29 -8
- package/dist/links/splitLink.d.cts.map +1 -1
- package/dist/links/splitLink.d.mts +1 -1
- package/dist/links/splitLink.mjs +1 -1
- package/dist/links/wsLink/wsLink.d.cts +1 -1
- package/dist/links/wsLink/wsLink.d.mts +1 -1
- package/dist/{loggerLink-CiVinJOG.d.mts → loggerLink-y1x7WTWX.d.mts} +2 -2
- package/dist/{loggerLink-CiVinJOG.d.mts.map → loggerLink-y1x7WTWX.d.mts.map} +1 -1
- package/dist/splitLink-BGLTgm1a.d.mts +56 -0
- package/dist/splitLink-BGLTgm1a.d.mts.map +1 -0
- package/dist/{splitLink-IUbsOwO6.mjs → splitLink-C8U8vvLl.mjs} +10 -12
- package/dist/splitLink-C8U8vvLl.mjs.map +1 -0
- package/dist/{splitLink-BQoYcpdp.cjs → splitLink-NqS85b92.cjs} +9 -11
- package/dist/{types-DW0iJUBU.d.mts → types-BZH1P86I.d.mts} +3 -3
- package/dist/types-BZH1P86I.d.mts.map +1 -0
- package/dist/{types-DMe6B4SV.d.cts → types-CGS36fjk.d.cts} +3 -3
- package/dist/{types-DMe6B4SV.d.cts.map → types-CGS36fjk.d.cts.map} +1 -1
- package/dist/{wsLink-DX5fv7-H.d.mts → wsLink-CFh-pvQG.d.mts} +2 -2
- package/dist/{wsLink-DX5fv7-H.d.mts.map → wsLink-CFh-pvQG.d.mts.map} +1 -1
- package/dist/{wsLink-DuyXOEPt.d.cts → wsLink-CJT5pqFt.d.cts} +2 -2
- package/dist/{wsLink-DuyXOEPt.d.cts.map → wsLink-CJT5pqFt.d.cts.map} +1 -1
- package/package.json +3 -3
- package/skills/client-setup/SKILL.md +15 -10
- package/skills/links/SKILL.md +9 -7
- package/skills/links/references/client-links-httpBatchLink.md +12 -8
- package/skills/links/references/client-links-httpBatchStreamLink.md +9 -6
- package/skills/links/references/client-links-httpLink.md +3 -2
- package/skills/links/references/client-links-httpSubscriptionLink.md +12 -4
- package/skills/links/references/client-links-localLink.md +3 -2
- package/skills/links/references/client-links-loggerLink.md +3 -2
- package/skills/links/references/client-links-retryLink.md +31 -2
- package/skills/links/references/client-links-splitLink.md +22 -6
- package/skills/links/references/client-links-wsLink.md +3 -2
- package/skills/superjson/SKILL.md +10 -6
- package/src/createTRPCClient.ts +8 -2
- package/src/links/retryLink.ts +41 -10
- package/src/links/splitLink.ts +85 -14
- package/src/links/types.ts +5 -2
- package/dist/splitLink-ClFN_nbg.d.mts +0 -35
- package/dist/splitLink-ClFN_nbg.d.mts.map +0 -1
- package/dist/splitLink-IUbsOwO6.mjs.map +0 -1
- package/dist/types-DW0iJUBU.d.mts.map +0 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { t as _objectSpread2 } from "./objectSpread2-pyA4QVO4.mjs";
|
|
1
2
|
import { observable } from "@trpc/server/observable";
|
|
2
3
|
// src/links/internals/createChain.ts
|
|
3
4
|
/** @internal */
|
|
@@ -20,24 +21,21 @@ function createChain(opts) {
|
|
|
20
21
|
function asArray(value) {
|
|
21
22
|
return Array.isArray(value) ? value : [value];
|
|
22
23
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
*
|
|
29
|
-
* @see https://trpc.io/docs/client/links/splitLink
|
|
30
|
-
*/
|
|
24
|
+
function withDefaults(defaults, context) {
|
|
25
|
+
const merged = _objectSpread2(_objectSpread2({}, defaults), context);
|
|
26
|
+
for (const key of Reflect.ownKeys(defaults)) if (merged[key] === void 0) merged[key] = defaults[key];
|
|
27
|
+
return merged;
|
|
28
|
+
}
|
|
31
29
|
function splitLink(opts) {
|
|
32
30
|
return (runtime) => {
|
|
33
31
|
const yes = asArray(opts.true).map((link) => link(runtime));
|
|
34
32
|
const no = asArray(opts.false).map((link) => link(runtime));
|
|
35
33
|
return (props) => {
|
|
36
34
|
return observable((observer) => {
|
|
37
|
-
const
|
|
35
|
+
const op = opts.context ? _objectSpread2(_objectSpread2({}, props.op), {}, { context: withDefaults(opts.context, props.op.context) }) : props.op;
|
|
38
36
|
return createChain({
|
|
39
|
-
op
|
|
40
|
-
links
|
|
37
|
+
op,
|
|
38
|
+
links: opts.condition(op) ? yes : no
|
|
41
39
|
}).subscribe(observer);
|
|
42
40
|
});
|
|
43
41
|
};
|
|
@@ -45,4 +43,4 @@ function splitLink(opts) {
|
|
|
45
43
|
}
|
|
46
44
|
export { createChain as n, splitLink as t };
|
|
47
45
|
|
|
48
|
-
//# sourceMappingURL=splitLink-
|
|
46
|
+
//# sourceMappingURL=splitLink-C8U8vvLl.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"splitLink-C8U8vvLl.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 OperationContext,\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// a field the call leaves out, or sets to `undefined`, takes its default\nfunction withDefaults(\n defaults: Record<PropertyKey, unknown>,\n context: OperationContext,\n): OperationContext {\n // spreading copies symbol keys too\n const merged: Record<PropertyKey, unknown> = { ...defaults, ...context };\n for (const key of Reflect.ownKeys(defaults)) {\n if (merged[key] === undefined) merged[key] = defaults[key];\n }\n return merged;\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 TContext extends object,\n> {\n /**\n * Picks the chain for an operation.\n */\n condition: (op: Operation<unknown, TContext>) => 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// the types the branches' links read the defaults' fields as, so a\n// default that a branch would read as another type is an error\ntype fitBranchContext<TContext, TTrue, TFalse> =\n inferLinksDeclaredContext<\n [...asLinks<TTrue>, ...asLinks<TFalse>]\n > extends infer $Branches\n ? { [TKey in keyof TContext & keyof $Branches]: $Branches[TKey] }\n : never;\n\ntype SplitLink<\n TRouter extends AnyRouter,\n TTrue extends SplitLinkBranch<TRouter>,\n TFalse extends SplitLinkBranch<TRouter>,\n TContext extends object,\n> = TRPCLink<\n TRouter,\n {\n context: TContext &\n inferLinksDeclaredContext<[...asLinks<TTrue>, ...asLinks<TFalse>]>;\n }\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. Give `context` defaults to\n * declare the fields `condition` reads; without them, `condition` reads\n * the fields added to `OperationContext`.\n * @example\n * splitLink({\n * context: { skipBatch: false },\n * condition: (op) => op.context.skipBatch,\n * true: httpLink({ url }),\n * false: httpBatchLink({ url }),\n * })\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, OperationContext> & {\n context?: never;\n },\n // `condition` may read the fields added to `OperationContext`\n): SplitLink<TRouter, TTrue, TFalse, AugmentedOperationContext>;\nexport function splitLink<\n TRouter extends AnyRouter,\n const TTrue extends SplitLinkBranch<TRouter>,\n const TFalse extends SplitLinkBranch<TRouter>,\n TContext extends object,\n>(\n opts: SplitLinkOptions<TRouter, TTrue, TFalse, TContext> & {\n /**\n * Values for the `context` fields `condition` reads, used when a call\n * leaves one out. Their types are the fields calls can pass. A field a\n * call passes replaces its default whole: nested objects aren't merged.\n * A field the branches' links also read must fit their type.\n */\n context: TContext & fitBranchContext<TContext, TTrue, TFalse>;\n },\n): SplitLink<TRouter, TTrue, TFalse, TContext>;\nexport function splitLink(\n opts: SplitLinkOptions<\n AnyRouter,\n SplitLinkBranch<AnyRouter>,\n SplitLinkBranch<AnyRouter>,\n any\n > & { context?: Record<PropertyKey, unknown> },\n): TRPCLink<AnyRouter> {\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 op = opts.context\n ? {\n ...props.op,\n context: withDefaults(opts.context, props.op.context),\n }\n : props.op;\n const links = opts.condition(op) ? yes : no;\n return createChain({ 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;;AC5BA,SAAS,QAAe,OAAmD;CACzE,OAAO,MAAM,QAAQ,KAAK,IAAI,QAAQ,CAAC,KAAc;AACvD;AAGA,SAAS,aACP,UACA,SACkB;CAElB,MAAM,SAAA,eAAA,eAAA,CAAA,GAA4C,QAAA,GAAa,OAAQ;CACvE,KAAK,MAAM,OAAO,QAAQ,QAAQ,QAAQ,GACxC,IAAI,OAAO,SAAS,KAAA,GAAW,OAAO,OAAO,SAAS;CAExD,OAAO;AACT;AAoGA,SAAgB,UACd,MAMqB;CACrB,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,KAAK,KAAK,UAAA,eAAA,eAAA,CAAA,GAEP,MAAM,EAAA,GAAA,CAAA,GAAA,EACT,SAAS,aAAa,KAAK,SAAS,MAAM,GAAG,OAAO,EAAA,CACtD,IACA,MAAM;IAEV,OAAO,YAAY;KAAE;KAAI,OADX,KAAK,UAAU,EAAE,IAAI,MAAM;IACV,CAAC,CAAC,CAAC,UAAU,QAAQ;GACtD,CAAC;EACH;CACF;AACF"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const require_objectSpread2 = require("./objectSpread2-Xm0br5eL.cjs");
|
|
1
2
|
let _trpc_server_observable = require("@trpc/server/observable");
|
|
2
3
|
// src/links/internals/createChain.ts
|
|
3
4
|
/** @internal */
|
|
@@ -20,24 +21,21 @@ function createChain(opts) {
|
|
|
20
21
|
function asArray(value) {
|
|
21
22
|
return Array.isArray(value) ? value : [value];
|
|
22
23
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
*
|
|
29
|
-
* @see https://trpc.io/docs/client/links/splitLink
|
|
30
|
-
*/
|
|
24
|
+
function withDefaults(defaults, context) {
|
|
25
|
+
const merged = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, defaults), context);
|
|
26
|
+
for (const key of Reflect.ownKeys(defaults)) if (merged[key] === void 0) merged[key] = defaults[key];
|
|
27
|
+
return merged;
|
|
28
|
+
}
|
|
31
29
|
function splitLink(opts) {
|
|
32
30
|
return (runtime) => {
|
|
33
31
|
const yes = asArray(opts.true).map((link) => link(runtime));
|
|
34
32
|
const no = asArray(opts.false).map((link) => link(runtime));
|
|
35
33
|
return (props) => {
|
|
36
34
|
return (0, _trpc_server_observable.observable)((observer) => {
|
|
37
|
-
const
|
|
35
|
+
const op = opts.context ? require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, props.op), {}, { context: withDefaults(opts.context, props.op.context) }) : props.op;
|
|
38
36
|
return createChain({
|
|
39
|
-
op
|
|
40
|
-
links
|
|
37
|
+
op,
|
|
38
|
+
links: opts.condition(op) ? yes : no
|
|
41
39
|
}).subscribe(observer);
|
|
42
40
|
});
|
|
43
41
|
};
|
|
@@ -160,13 +160,13 @@ type AugmentedOperationContext = { [TKey in keyof OperationContext as string ext
|
|
|
160
160
|
* A procedure call as it goes through the links.
|
|
161
161
|
* @internal
|
|
162
162
|
*/
|
|
163
|
-
type Operation<TInput = unknown> = {
|
|
163
|
+
type Operation<TInput = unknown, TContext extends object = OperationContext> = {
|
|
164
164
|
/** A number unique to the call within its client. */
|
|
165
165
|
id: number;
|
|
166
166
|
type: 'mutation' | 'query' | 'subscription';
|
|
167
167
|
input: TInput;
|
|
168
168
|
path: string;
|
|
169
|
-
context:
|
|
169
|
+
context: TContext;
|
|
170
170
|
signal: Maybe<AbortSignal>;
|
|
171
171
|
};
|
|
172
172
|
interface HeadersInitEsque {
|
|
@@ -269,4 +269,4 @@ type inferLinksDeclaredContext<TLinks extends readonly unknown[]> = UnionToInter
|
|
|
269
269
|
*/
|
|
270
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
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-
|
|
272
|
+
//# sourceMappingURL=types-BZH1P86I.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-BZH1P86I.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,oBAAo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AErC,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"}
|
|
@@ -170,13 +170,13 @@ type AugmentedOperationContext = { [TKey in keyof OperationContext as string ext
|
|
|
170
170
|
* A procedure call as it goes through the links.
|
|
171
171
|
* @internal
|
|
172
172
|
*/
|
|
173
|
-
type Operation<TInput = unknown> = {
|
|
173
|
+
type Operation<TInput = unknown, TContext extends object = OperationContext> = {
|
|
174
174
|
/** A number unique to the call within its client. */
|
|
175
175
|
id: number;
|
|
176
176
|
type: 'mutation' | 'query' | 'subscription';
|
|
177
177
|
input: TInput;
|
|
178
178
|
path: string;
|
|
179
|
-
context:
|
|
179
|
+
context: TContext;
|
|
180
180
|
signal: Maybe<AbortSignal>;
|
|
181
181
|
};
|
|
182
182
|
interface HeadersInitEsque {
|
|
@@ -279,4 +279,4 @@ type inferLinksDeclaredContext<TLinks extends readonly unknown[]> = UnionToInter
|
|
|
279
279
|
*/
|
|
280
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
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-
|
|
282
|
+
//# sourceMappingURL=types-CGS36fjk.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types-
|
|
1
|
+
{"version":3,"file":"types-CGS36fjk.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,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,gBA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AAe;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,5 +1,5 @@
|
|
|
1
1
|
import { n as TransformerOptions } from "./unstable-internals-CnrO49lh.mjs";
|
|
2
|
-
import { a as Operation, c as OperationResultEnvelope, g as TRPCClientError, p as TRPCLink } from "./types-
|
|
2
|
+
import { a as Operation, c as OperationResultEnvelope, g as TRPCClientError, p as TRPCLink } from "./types-BZH1P86I.mjs";
|
|
3
3
|
import { t as TRPCConnectionState } from "./subscriptions-CvJnusYO.mjs";
|
|
4
4
|
import { BehaviorSubject } from "@trpc/server/observable";
|
|
5
5
|
import { AnyRouter, CombinedDataTransformer, Encoder, inferClientTypes } from "@trpc/server/unstable-core-do-not-import";
|
|
@@ -309,4 +309,4 @@ declare function wsLink<TRouter extends AnyRouter>(opts: WebSocketLinkOptions<TR
|
|
|
309
309
|
context: {};
|
|
310
310
|
}>;
|
|
311
311
|
export { WebSocketClientOptions as a, jsonEncoder as c, createWSClient as i, wsLink as n, UrlOptionsWithConnectionParams as o, TRPCWebSocketClient as r, Encoder as s, WebSocketLinkOptions as t };
|
|
312
|
-
//# sourceMappingURL=wsLink-
|
|
312
|
+
//# sourceMappingURL=wsLink-CFh-pvQG.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wsLink-
|
|
1
|
+
{"version":3,"file":"wsLink-CFh-pvQG.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"],"mappings":";;;;;;;;;;cAOa,aAA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, y as TRPCClientError } from "./types-
|
|
2
|
+
import { a as Operation, c as OperationResultEnvelope, p as TRPCLink, y as TRPCClientError } from "./types-CGS36fjk.cjs";
|
|
3
3
|
import { t as TRPCConnectionState } from "./subscriptions-CvJnusYO.cjs";
|
|
4
4
|
import { AnyRouter, CombinedDataTransformer, Encoder, inferClientTypes } from "@trpc/server/unstable-core-do-not-import";
|
|
5
5
|
import { BehaviorSubject } from "@trpc/server/observable";
|
|
@@ -309,4 +309,4 @@ declare function wsLink<TRouter extends AnyRouter>(opts: WebSocketLinkOptions<TR
|
|
|
309
309
|
context: {};
|
|
310
310
|
}>;
|
|
311
311
|
export { WebSocketClientOptions as a, jsonEncoder as c, createWSClient as i, wsLink as n, UrlOptionsWithConnectionParams as o, TRPCWebSocketClient as r, Encoder as s, WebSocketLinkOptions as t };
|
|
312
|
-
//# sourceMappingURL=wsLink-
|
|
312
|
+
//# sourceMappingURL=wsLink-CJT5pqFt.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wsLink-
|
|
1
|
+
{"version":3,"file":"wsLink-CJT5pqFt.d.cts","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"],"mappings":";;;;;;;;;;cAOa,aAAa;;;;KCWd,gBAAgB,KAAK,WAAW,IAAI,QAAQ;UAEvC;;;;EAIf,KAAK;;;;;;;EAQL,mBAAmB,gBAAgB;;;;;;;UCxBpB,+BAA+B;;;;EAI9C,mBAAmB;;;;;EAKnB,gBAAgB;;;;EAIhB;;;;EAIA,WAAW,MAAM;;;;EAIjB,WAAW;IAAU;;;;;EAIrB;;;;;IAKE;;;;;IAKA;;;;;EAKF;;;;IAIE;;;;;IAKA;;;;;IAKA;;;;;;EAMF,uBAAuB;;;;;;cCWZ;;;;WAIK,iBAAiB,gBAC/B,oBAAoB,gBAAgB;UAG9B;UACA;;;;;;;UASA;mBACS;;;;;;UAMT;mBACS;UACT;;;;;UAKA;mBACS;mBAIA;mBACA;mBACA;EAEjB,YAAY,MAAM;;;;;;UA4DV;UAUA;;;;;UAeM;;;;;EAmDD,SAAK;;;;;;;;;;;EAqDX,UACL,MAAM,MAAM,MAAM,OAAO,UACzB,aACA;IAEA,IAAI,KAAK;IACT,aAAa;IACb;wCACD,WAAA,iCAAA,gBAAA,iBAAA,gBAAA;;;;MAwEU;;;;;;;;;;;;;;;;;;UAaH;;;;UAIA;;;;;UAKA;;;;;;UAMA;;;;UAIA;;;;;;;;;;;UAWA;;mBAES;;;;;;;;;UAUT;;;;;;;;UA2FA;;;;;;;UA8CA;UAiBA;UASA;;;;UAaA;;;;;;UAWA;;;;;UAaA;UA0BA;UAqNA;UA+DA;;;;UASA;;;;;;UAqBA;;;;;UAWA;;;;;;;;iBCh9BM,eAAe,MAAM,yBAAsB;;;;KAO/C,sBAAsB,kBAAkB;;;;;;KCIxC,qBAAqB,gBAAgB;;;;EAI/C,QAAQ;IACN,mBAAmB,iBAAiB;;;;;;iBAOxB,OAAO,gBAAgB,WACrC,MAAM,qBAAqB,WAC1B,SAAS;EAAW"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@trpc/client",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
"version": "11.
|
|
5
|
+
"version": "11.35.0",
|
|
6
6
|
"description": "The tRPC client library",
|
|
7
7
|
"author": "KATT",
|
|
8
8
|
"license": "MIT",
|
|
@@ -100,12 +100,12 @@
|
|
|
100
100
|
"skills"
|
|
101
101
|
],
|
|
102
102
|
"peerDependencies": {
|
|
103
|
-
"@trpc/server": "11.
|
|
103
|
+
"@trpc/server": "11.35.0",
|
|
104
104
|
"typescript": ">=5.7.2"
|
|
105
105
|
},
|
|
106
106
|
"devDependencies": {
|
|
107
107
|
"@tanstack/intent": "0.5.6",
|
|
108
|
-
"@trpc/server": "11.
|
|
108
|
+
"@trpc/server": "11.35.0",
|
|
109
109
|
"@types/isomorphic-fetch": "^0.0.39",
|
|
110
110
|
"@types/node": "^24.19.2",
|
|
111
111
|
"dataloader": "^2.2.3",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: client-setup
|
|
3
|
-
description: Create a vanilla tRPC client with createTRPCClient<AppRouter>() and a terminating link such as httpBatchLink, import AppRouter with `import type`, set dynamic auth headers, and put the transformer on links (not the client constructor). Infer types with inferRouterInputs and inferRouterOutputs, handle TRPCClientError with try/catch or safe(), and abort calls with an AbortSignal.
|
|
3
|
+
description: Create a vanilla tRPC client with createTRPCClient, passing the router type as router routerType<AppRouter>() and a terminating link such as httpBatchLink, import AppRouter with `import type`, set dynamic auth headers, and put the transformer on links (not the client constructor). Infer types with inferRouterInputs and inferRouterOutputs, handle TRPCClientError with try/catch or safe(), and abort calls with an AbortSignal.
|
|
4
4
|
requires:
|
|
5
5
|
- server-setup
|
|
6
6
|
sources:
|
|
@@ -12,7 +12,7 @@ sources:
|
|
|
12
12
|
metadata:
|
|
13
13
|
type: core
|
|
14
14
|
library: trpc
|
|
15
|
-
library_version: 11.
|
|
15
|
+
library_version: 11.35.0
|
|
16
16
|
---
|
|
17
17
|
|
|
18
18
|
<!-- Generated from www/v11/docs/client/vanilla/setup.md by www/build/skills.ts. Edit the docs instead. -->
|
|
@@ -43,13 +43,16 @@ import type { AppRouter } from '../server/router';
|
|
|
43
43
|
|
|
44
44
|
### 3. Initialize the tRPC client
|
|
45
45
|
|
|
46
|
-
Create a tRPC client with the `createTRPCClient` method
|
|
46
|
+
Create a tRPC client with the `createTRPCClient` method. Pass your router's type as `router: routerType<AppRouter>()`, and add a `links` array with a [terminating link](https://trpc.io/docs/client/links#the-terminating-link) pointing at your API. `routerType` does nothing at runtime, so no server code reaches the client. To learn more about tRPC links, [click here](https://trpc.io/docs/client/links).
|
|
47
|
+
|
|
48
|
+
With `router:`, the client also types each call's `context` from what its links read. See [Typing call options](https://trpc.io/docs/client/links#typing-call-options).
|
|
47
49
|
|
|
48
50
|
```ts no-check title="client.ts"
|
|
49
|
-
import { createTRPCClient, httpBatchLink } from '@trpc/client';
|
|
51
|
+
import { createTRPCClient, httpBatchLink, routerType } from '@trpc/client';
|
|
50
52
|
import type { AppRouter } from './server';
|
|
51
53
|
|
|
52
|
-
const client = createTRPCClient
|
|
54
|
+
const client = createTRPCClient({
|
|
55
|
+
router: routerType<AppRouter>(),
|
|
53
56
|
links: [
|
|
54
57
|
httpBatchLink({
|
|
55
58
|
url: 'http://localhost:3000/trpc',
|
|
@@ -115,7 +118,7 @@ You're all set!
|
|
|
115
118
|
|
|
116
119
|
## Common mistakes
|
|
117
120
|
|
|
118
|
-
- **Leaving out
|
|
121
|
+
- **Leaving out `router`.** `createTRPCClient({ links })` without `router: routerType<AppRouter>()` compiles, but none of your procedures are typed. If the `AppRouter` import doesn't resolve (often a monorepo path or `tsconfig` issue), fix the import rather than reaching for `routerType<any>()`.
|
|
119
122
|
- **Importing the router value instead of its type.** `import { appRouter } from '../server/router'` pulls your server code into the client bundle. Export `type AppRouter = typeof appRouter` from the server and import it with `import type`.
|
|
120
123
|
- **Passing `transformer` to `createTRPCClient`.** The transformer belongs on each terminating link (`httpBatchLink`, `httpLink`, `wsLink`, ...), and TypeScript rejects it on the client itself. See [Data Transformers](https://trpc.io/docs/server/data-transformers).
|
|
121
124
|
- **Using `createTRPCProxyClient`.** It's the v10 name, kept as a deprecated alias of `createTRPCClient`.
|
|
@@ -309,10 +312,11 @@ From https://trpc.io/docs/client/vanilla/aborting-procedure-calls
|
|
|
309
312
|
tRPC supports the standard `AbortController`/`AbortSignal` API for aborting procedures. All you have to do is pass an `AbortSignal` to the query or mutation options, and call the `AbortController` instance's `abort` method if you need to cancel the request.
|
|
310
313
|
|
|
311
314
|
```ts no-check title="utils.ts"
|
|
312
|
-
import { createTRPCClient, httpBatchLink } from '@trpc/client';
|
|
315
|
+
import { createTRPCClient, httpBatchLink, routerType } from '@trpc/client';
|
|
313
316
|
import type { AppRouter } from './server';
|
|
314
317
|
|
|
315
|
-
const client = createTRPCClient
|
|
318
|
+
const client = createTRPCClient({
|
|
319
|
+
router: routerType<AppRouter>(),
|
|
316
320
|
links: [
|
|
317
321
|
httpBatchLink({
|
|
318
322
|
url: 'http://localhost:3000/trpc',
|
|
@@ -339,7 +343,7 @@ The headers option may be used with any of our HTTP links: [`httpBatchLink`](htt
|
|
|
339
343
|
`headers` can be both an object or a function. If it's a function it will get called dynamically for every HTTP request.
|
|
340
344
|
|
|
341
345
|
```ts no-check title="utils/trpc.ts"
|
|
342
|
-
import { createTRPCClient, httpBatchLink } from '@trpc/client';
|
|
346
|
+
import { createTRPCClient, httpBatchLink, routerType } from '@trpc/client';
|
|
343
347
|
import type { AppRouter } from './server';
|
|
344
348
|
|
|
345
349
|
let token: string;
|
|
@@ -352,7 +356,8 @@ export function setToken(newToken: string) {
|
|
|
352
356
|
token = newToken;
|
|
353
357
|
}
|
|
354
358
|
|
|
355
|
-
export const trpc = createTRPCClient
|
|
359
|
+
export const trpc = createTRPCClient({
|
|
360
|
+
router: routerType<AppRouter>(),
|
|
356
361
|
links: [
|
|
357
362
|
httpBatchLink({
|
|
358
363
|
url: 'http://localhost:3000',
|
package/skills/links/SKILL.md
CHANGED
|
@@ -17,7 +17,7 @@ sources:
|
|
|
17
17
|
metadata:
|
|
18
18
|
type: core
|
|
19
19
|
library: trpc
|
|
20
|
-
library_version: 11.
|
|
20
|
+
library_version: 11.35.0
|
|
21
21
|
---
|
|
22
22
|
|
|
23
23
|
<!-- Generated from www/v11/docs/client/links.md by www/build/skills.ts. Edit the docs instead. -->
|
|
@@ -36,10 +36,11 @@ You can compose links together into an array that you can provide to the tRPC cl
|
|
|
36
36
|
</div>
|
|
37
37
|
|
|
38
38
|
```ts no-check title="utils/trpc.ts"
|
|
39
|
-
import { createTRPCClient, httpBatchLink, loggerLink } from '@trpc/client';
|
|
39
|
+
import { createTRPCClient, httpBatchLink, loggerLink, routerType } from '@trpc/client';
|
|
40
40
|
import type { AppRouter } from './server';
|
|
41
41
|
|
|
42
|
-
export const trpc = createTRPCClient
|
|
42
|
+
export const trpc = createTRPCClient({
|
|
43
|
+
router: routerType<AppRouter>(),
|
|
43
44
|
links: [
|
|
44
45
|
loggerLink(),
|
|
45
46
|
httpBatchLink({
|
|
@@ -108,7 +109,7 @@ The `links` array that you add to the tRPC client config should have at least on
|
|
|
108
109
|
| Link | Use it for |
|
|
109
110
|
| --- | --- |
|
|
110
111
|
| [`httpBatchLink`](https://trpc.io/docs/client/links/httpBatchLink) | Queries and mutations. Calls made together, for example in a `Promise.all`, are sent as one HTTP request. |
|
|
111
|
-
| [`httpLink`](https://trpc.io/docs/client/links/httpLink) | One HTTP request per call, for example to [skip batching](https://trpc.io/docs/client/links/splitLink#
|
|
112
|
+
| [`httpLink`](https://trpc.io/docs/client/links/httpLink) | One HTTP request per call, for example to [skip batching](https://trpc.io/docs/client/links/splitLink#typed-context) or to send [`FormData` and binary inputs](https://trpc.io/docs/server/non-json-content-types). |
|
|
112
113
|
| [`httpBatchStreamLink`](https://trpc.io/docs/client/links/httpBatchStreamLink) | Batching, but each response is streamed as soon as it's ready. Required for procedures that return async generators or promises nested in the output. |
|
|
113
114
|
| [`httpSubscriptionLink`](https://trpc.io/docs/client/links/httpSubscriptionLink) | Subscriptions over Server-sent Events. |
|
|
114
115
|
| [`wsLink`](https://trpc.io/docs/client/links/wsLink) | Any operation over a WebSocket. |
|
|
@@ -123,10 +124,12 @@ import {
|
|
|
123
124
|
httpSubscriptionLink,
|
|
124
125
|
loggerLink,
|
|
125
126
|
splitLink,
|
|
127
|
+
routerType,
|
|
126
128
|
} from '@trpc/client';
|
|
127
129
|
import type { AppRouter } from './server';
|
|
128
130
|
|
|
129
|
-
export const trpc = createTRPCClient
|
|
131
|
+
export const trpc = createTRPCClient({
|
|
132
|
+
router: routerType<AppRouter>(),
|
|
130
133
|
links: [
|
|
131
134
|
loggerLink(),
|
|
132
135
|
splitLink({
|
|
@@ -150,7 +153,7 @@ For an example use case, see [Disable batching for certain requests](https://trp
|
|
|
150
153
|
|
|
151
154
|
### Typing call options
|
|
152
155
|
|
|
153
|
-
Create the client with `router: routerType<AppRouter>()` and the `context` each call takes is typed from the links. A link declares what it reads with the second type argument of `TRPCLink`.
|
|
156
|
+
Create the client with `router: routerType<AppRouter>()` and the `context` each call takes is typed from the links. A link declares what it reads with the second type argument of `TRPCLink`. Built-in links declare theirs: [`retryLink`](https://trpc.io/docs/client/links/retryLink#changing-retries-for-one-call) reads `retry`.
|
|
154
157
|
|
|
155
158
|
```ts no-check
|
|
156
159
|
import type { TRPCLink } from '@trpc/client';
|
|
@@ -176,7 +179,6 @@ await client.greeting.query(undefined, { context: { traceId: 123 } });
|
|
|
176
179
|
- Declared fields are type-checked, and always optional.
|
|
177
180
|
- A link that declares nothing, such as `TRPCLink<AppRouter>`, may read any field, so calls can pass any `context`. Declare `{ context: {} }` for a link that reads none. When every link reads none, passing a field is an error.
|
|
178
181
|
- Links that hand the operation to your code, such as the HTTP links' `headers` or `retryLink`'s `retry`, declare only the fields added to `OperationContext`.
|
|
179
|
-
- With `createTRPCClient<AppRouter>()`, calls take any `context`, as before.
|
|
180
182
|
|
|
181
183
|
To pass a field that such a callback reads, add it to `OperationContext`:
|
|
182
184
|
|
|
@@ -11,10 +11,11 @@ From https://trpc.io/docs/client/links/httpBatchLink
|
|
|
11
11
|
You can import and add the `httpBatchLink` to the `links` array as such:
|
|
12
12
|
|
|
13
13
|
```ts no-check title="client/index.ts"
|
|
14
|
-
import { createTRPCClient, httpBatchLink } from '@trpc/client';
|
|
14
|
+
import { createTRPCClient, httpBatchLink, routerType } from '@trpc/client';
|
|
15
15
|
import type { AppRouter } from './server';
|
|
16
16
|
|
|
17
|
-
const client = createTRPCClient
|
|
17
|
+
const client = createTRPCClient({
|
|
18
|
+
router: routerType<AppRouter>(),
|
|
18
19
|
links: [
|
|
19
20
|
httpBatchLink({
|
|
20
21
|
url: 'http://localhost:3000',
|
|
@@ -93,10 +94,11 @@ export interface HTTPLinkOptions {
|
|
|
93
94
|
When sending batch requests, sometimes the URL can become too large causing HTTP errors like [`413 Payload Too Large`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/413), [`414 URI Too Long`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/414), and [`404 Not Found`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/404). The `maxURLLength` option will limit the number of requests that can be sent together in a batch.
|
|
94
95
|
|
|
95
96
|
```ts no-check title="client/index.ts"
|
|
96
|
-
import { createTRPCClient, httpBatchLink } from '@trpc/client';
|
|
97
|
+
import { createTRPCClient, httpBatchLink, routerType } from '@trpc/client';
|
|
97
98
|
import type { AppRouter } from './server';
|
|
98
99
|
|
|
99
|
-
const client = createTRPCClient
|
|
100
|
+
const client = createTRPCClient({
|
|
101
|
+
router: routerType<AppRouter>(),
|
|
100
102
|
links: [
|
|
101
103
|
httpBatchLink({
|
|
102
104
|
url: 'http://localhost:3000',
|
|
@@ -141,10 +143,11 @@ export default createNextApiHandler({
|
|
|
141
143
|
Use the `maxItems` option on your batch link to ensure the client doesn't exceed the server's limit. This splits large batches into multiple HTTP requests automatically
|
|
142
144
|
|
|
143
145
|
```ts title="client/index.ts"
|
|
144
|
-
import { createTRPCClient, httpBatchLink } from '@trpc/client';
|
|
146
|
+
import { createTRPCClient, httpBatchLink, routerType } from '@trpc/client';
|
|
145
147
|
import type { AppRouter } from '../server';
|
|
146
148
|
|
|
147
|
-
const client = createTRPCClient
|
|
149
|
+
const client = createTRPCClient({
|
|
150
|
+
router: routerType<AppRouter>(),
|
|
148
151
|
links: [
|
|
149
152
|
httpBatchLink({
|
|
150
153
|
url: 'http://localhost:3000',
|
|
@@ -186,10 +189,11 @@ export default createNextApiHandler({
|
|
|
186
189
|
### 2. Replace `httpBatchLink` with [`httpLink`](https://trpc.io/docs/client/links/httpLink) in your tRPC Client
|
|
187
190
|
|
|
188
191
|
```ts no-check title="client/index.ts"
|
|
189
|
-
import { createTRPCClient, httpLink } from '@trpc/client';
|
|
192
|
+
import { createTRPCClient, httpLink, routerType } from '@trpc/client';
|
|
190
193
|
import type { AppRouter } from './server';
|
|
191
194
|
|
|
192
|
-
const client = createTRPCClient
|
|
195
|
+
const client = createTRPCClient({
|
|
196
|
+
router: routerType<AppRouter>(),
|
|
193
197
|
links: [
|
|
194
198
|
httpLink({
|
|
195
199
|
url: 'http://localhost:3000',
|
|
@@ -25,10 +25,11 @@ Options are identical to [`httpBatchLink options`](https://trpc.io/docs/client/l
|
|
|
25
25
|
You can import and add the `httpBatchStreamLink` to the `links` array as such:
|
|
26
26
|
|
|
27
27
|
```ts no-check title="client/index.ts"
|
|
28
|
-
import { createTRPCClient, httpBatchStreamLink } from '@trpc/client';
|
|
28
|
+
import { createTRPCClient, httpBatchStreamLink, routerType } from '@trpc/client';
|
|
29
29
|
import type { AppRouter } from './server';
|
|
30
30
|
|
|
31
|
-
const client = createTRPCClient
|
|
31
|
+
const client = createTRPCClient({
|
|
32
|
+
router: routerType<AppRouter>(),
|
|
32
33
|
links: [
|
|
33
34
|
httpBatchStreamLink({
|
|
34
35
|
url: 'http://localhost:3000',
|
|
@@ -54,10 +55,11 @@ Each procedure still runs its own resolver, so whether this makes one database q
|
|
|
54
55
|
When batching requests together, the behavior of a regular `httpBatchLink` is to wait for all requests to finish before sending the response. If you want to send responses as soon as they are ready, you can use `httpBatchStreamLink` instead. This is useful for long-running requests.
|
|
55
56
|
|
|
56
57
|
```ts no-check title="client/index.ts"
|
|
57
|
-
import { createTRPCClient, httpBatchStreamLink } from '@trpc/client';
|
|
58
|
+
import { createTRPCClient, httpBatchStreamLink, routerType } from '@trpc/client';
|
|
58
59
|
import type { AppRouter } from './server';
|
|
59
60
|
|
|
60
|
-
const client = createTRPCClient
|
|
61
|
+
const client = createTRPCClient({
|
|
62
|
+
router: routerType<AppRouter>(),
|
|
61
63
|
links: [
|
|
62
64
|
httpBatchStreamLink({
|
|
63
65
|
url: 'http://localhost:3000',
|
|
@@ -77,10 +79,11 @@ Compared to a regular `httpBatchLink`, a `httpBatchStreamLink` will:
|
|
|
77
79
|
You can try this out on the homepage of tRPC.io: [https://trpc.io/?try=minimal#try-it-out](https://trpc.io/?try=minimal#try-it-out)
|
|
78
80
|
|
|
79
81
|
```ts no-check
|
|
80
|
-
import { createTRPCClient, httpBatchStreamLink } from '@trpc/client';
|
|
82
|
+
import { createTRPCClient, httpBatchStreamLink, routerType } from '@trpc/client';
|
|
81
83
|
import type { AppRouter } from './server';
|
|
82
84
|
|
|
83
|
-
const trpc = createTRPCClient
|
|
85
|
+
const trpc = createTRPCClient({
|
|
86
|
+
router: routerType<AppRouter>(),
|
|
84
87
|
links: [
|
|
85
88
|
httpBatchStreamLink({
|
|
86
89
|
url: 'http://localhost:3000',
|
|
@@ -13,10 +13,11 @@ From https://trpc.io/docs/client/links/httpLink
|
|
|
13
13
|
You can import and add the `httpLink` to the `links` array as such:
|
|
14
14
|
|
|
15
15
|
```ts no-check title="client/index.ts"
|
|
16
|
-
import { createTRPCClient, httpLink } from '@trpc/client';
|
|
16
|
+
import { createTRPCClient, httpLink, routerType } from '@trpc/client';
|
|
17
17
|
import type { AppRouter } from './server';
|
|
18
18
|
|
|
19
|
-
const client = createTRPCClient
|
|
19
|
+
const client = createTRPCClient({
|
|
20
|
+
router: routerType<AppRouter>(),
|
|
20
21
|
links: [
|
|
21
22
|
httpLink({
|
|
22
23
|
url: 'http://localhost:3000',
|
|
@@ -23,10 +23,12 @@ import {
|
|
|
23
23
|
httpSubscriptionLink,
|
|
24
24
|
loggerLink,
|
|
25
25
|
splitLink,
|
|
26
|
+
routerType,
|
|
26
27
|
} from '@trpc/client';
|
|
27
28
|
import type { AppRouter } from './server';
|
|
28
29
|
|
|
29
|
-
const trpcClient = createTRPCClient
|
|
30
|
+
const trpcClient = createTRPCClient({
|
|
31
|
+
router: routerType<AppRouter>(),
|
|
30
32
|
/**
|
|
31
33
|
* @see https://trpc.io/docs/v11/client/links
|
|
32
34
|
*/
|
|
@@ -89,12 +91,14 @@ import {
|
|
|
89
91
|
httpBatchLink,
|
|
90
92
|
httpSubscriptionLink,
|
|
91
93
|
splitLink,
|
|
94
|
+
routerType,
|
|
92
95
|
} from '@trpc/client';
|
|
93
96
|
import { EventSourcePolyfill } from 'event-source-polyfill';
|
|
94
97
|
import type { AppRouter } from './server';
|
|
95
98
|
|
|
96
99
|
// Initialize the tRPC client
|
|
97
|
-
const trpc = createTRPCClient
|
|
100
|
+
const trpc = createTRPCClient({
|
|
101
|
+
router: routerType<AppRouter>(),
|
|
98
102
|
links: [
|
|
99
103
|
splitLink({
|
|
100
104
|
condition: (op) => op.type === 'subscription',
|
|
@@ -140,6 +144,7 @@ import {
|
|
|
140
144
|
httpSubscriptionLink,
|
|
141
145
|
retryLink,
|
|
142
146
|
splitLink,
|
|
147
|
+
routerType,
|
|
143
148
|
} from '@trpc/client';
|
|
144
149
|
import {
|
|
145
150
|
EventSourcePolyfill,
|
|
@@ -148,7 +153,8 @@ import {
|
|
|
148
153
|
import type { AppRouter } from './server';
|
|
149
154
|
|
|
150
155
|
// Initialize the tRPC client
|
|
151
|
-
const trpc = createTRPCClient
|
|
156
|
+
const trpc = createTRPCClient({
|
|
157
|
+
router: routerType<AppRouter>(),
|
|
152
158
|
links: [
|
|
153
159
|
splitLink({
|
|
154
160
|
condition: (op) => op.type === 'subscription',
|
|
@@ -220,11 +226,13 @@ import {
|
|
|
220
226
|
httpBatchLink,
|
|
221
227
|
httpSubscriptionLink,
|
|
222
228
|
splitLink,
|
|
229
|
+
routerType,
|
|
223
230
|
} from '@trpc/client';
|
|
224
231
|
import type { AppRouter } from './server';
|
|
225
232
|
|
|
226
233
|
// Initialize the tRPC client
|
|
227
|
-
const trpc = createTRPCClient
|
|
234
|
+
const trpc = createTRPCClient({
|
|
235
|
+
router: routerType<AppRouter>(),
|
|
228
236
|
links: [
|
|
229
237
|
splitLink({
|
|
230
238
|
condition: (op) => op.type === 'subscription',
|
|
@@ -13,11 +13,12 @@ From https://trpc.io/docs/client/links/localLink
|
|
|
13
13
|
## Usage
|
|
14
14
|
|
|
15
15
|
```tsx no-check
|
|
16
|
-
import { createTRPCClient, localLink } from '@trpc/client';
|
|
16
|
+
import { createTRPCClient, localLink, routerType } from '@trpc/client';
|
|
17
17
|
import type { AppRouter } from './server';
|
|
18
18
|
import { appRouter } from './server';
|
|
19
19
|
|
|
20
|
-
const client = createTRPCClient
|
|
20
|
+
const client = createTRPCClient({
|
|
21
|
+
router: routerType<AppRouter>(),
|
|
21
22
|
links: [
|
|
22
23
|
localLink({
|
|
23
24
|
router: appRouter,
|
|
@@ -11,10 +11,11 @@ From https://trpc.io/docs/client/links/loggerLink
|
|
|
11
11
|
You can import and add the `loggerLink` to the `links` array as such:
|
|
12
12
|
|
|
13
13
|
```ts no-check title="client/index.ts"
|
|
14
|
-
import { createTRPCClient, httpBatchLink, loggerLink } from '@trpc/client';
|
|
14
|
+
import { createTRPCClient, httpBatchLink, loggerLink, routerType } from '@trpc/client';
|
|
15
15
|
import type { AppRouter } from './server';
|
|
16
16
|
|
|
17
|
-
const client = createTRPCClient
|
|
17
|
+
const client = createTRPCClient({
|
|
18
|
+
router: routerType<AppRouter>(),
|
|
18
19
|
links: [
|
|
19
20
|
/**
|
|
20
21
|
* The function passed to enabled is an example in case you want to the link to
|