@trpc/react-query 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/{getQueryKey-BqoKYDMR.d.cts → getQueryKey-BI6_waNM.d.mts} +256 -19
- package/dist/getQueryKey-BI6_waNM.d.mts.map +1 -0
- package/dist/{getQueryKey-CMt5tN9-.d.mts → getQueryKey-CSENlbGR.d.cts} +256 -19
- package/dist/getQueryKey-CSENlbGR.d.cts.map +1 -0
- package/dist/{getQueryKey-D3tJ34z0.mjs → getQueryKey-CWSorJjT.mjs} +25 -9
- package/dist/getQueryKey-CWSorJjT.mjs.map +1 -0
- package/dist/{getQueryKey-Db_3VDGo.cjs → getQueryKey-DASF3nl1.cjs} +24 -8
- package/dist/index.cjs +24 -2
- package/dist/index.d.cts +10 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +10 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +24 -2
- package/dist/index.mjs.map +1 -1
- package/dist/rsc.cjs +9 -1
- package/dist/rsc.d.cts +9 -1
- package/dist/rsc.d.cts.map +1 -1
- package/dist/rsc.d.mts +9 -1
- package/dist/rsc.d.mts.map +1 -1
- package/dist/rsc.mjs +9 -1
- package/dist/rsc.mjs.map +1 -1
- package/dist/server/index.cjs +30 -11
- package/dist/server/index.d.cts +17 -3
- package/dist/server/index.d.cts.map +1 -1
- package/dist/server/index.d.mts +17 -3
- package/dist/server/index.d.mts.map +1 -1
- package/dist/server/index.mjs +30 -11
- package/dist/server/index.mjs.map +1 -1
- package/dist/shared/index.cjs +1 -1
- package/dist/shared/index.d.cts +1 -1
- package/dist/shared/index.d.mts +1 -1
- package/dist/shared/index.mjs +1 -1
- package/dist/{shared-Bw5jcbcM.mjs → shared-DyU-Vz6d.mjs} +11 -2
- package/dist/shared-DyU-Vz6d.mjs.map +1 -0
- package/dist/{shared-ByAY3gMr.cjs → shared-v3jJm-s7.cjs} +10 -1
- package/package.json +6 -6
- package/src/createTRPCQueryUtils.tsx +9 -0
- package/src/createTRPCReact.tsx +40 -7
- package/src/internals/context.tsx +21 -0
- package/src/internals/getQueryKey.ts +24 -8
- package/src/rsc.tsx +8 -0
- package/src/server/ssgProxy.ts +41 -5
- package/src/shared/hooks/types.ts +93 -0
- package/src/shared/polymorphism/routerLike.ts +3 -0
- package/src/shared/proxy/utilsProxy.ts +15 -0
- package/src/shared/types.ts +50 -2
- package/src/utils/inferReactQueryProcedure.ts +8 -0
- package/dist/getQueryKey-BqoKYDMR.d.cts.map +0 -1
- package/dist/getQueryKey-CMt5tN9-.d.mts.map +0 -1
- package/dist/getQueryKey-D3tJ34z0.mjs.map +0 -1
- package/dist/shared-Bw5jcbcM.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getQueryKey-CWSorJjT.mjs","names":[],"sources":["../src/internals/getQueryKey.ts"],"sourcesContent":["import { skipToken } from '@tanstack/react-query';\nimport {\n isObject,\n type DeepPartial,\n} from '@trpc/server/unstable-core-do-not-import';\nimport type { DecoratedMutation, DecoratedQuery } from '../createTRPCReact';\nimport type { DecorateRouterRecord } from '../shared';\n\nexport type QueryType = 'any' | 'infinite' | 'query';\n\nexport type TRPCQueryKey = [\n readonly string[],\n { input?: unknown; type?: Exclude<QueryType, 'any'> }?,\n];\n\nexport type TRPCMutationKey = [readonly string[]]; // = [TRPCQueryKey[0]]\n\ntype ProcedureOrRouter =\n | DecoratedMutation<any>\n | DecoratedQuery<any>\n | DecorateRouterRecord<any, any>;\n\n/**\n * To allow easy interactions with groups of related queries, such as\n * invalidating all queries of a router, we use an array as the path when\n * storing in tanstack query.\n **/\nexport function getQueryKeyInternal(\n path: readonly string[],\n input: unknown,\n type: QueryType,\n): TRPCQueryKey {\n // Construct a query key that is easy to destructure and flexible for\n // partial selecting etc.\n // https://github.com/trpc/trpc/issues/3128\n\n // some parts of the path may be dot-separated, split them up\n const splitPath = path.flatMap((part) => part.split('.'));\n\n if (typeof input === 'undefined' && (!type || type === 'any')) {\n // this matches also all mutations (see `getMutationKeyInternal`)\n\n // for `utils.invalidate()` to match all queries (including vanilla react-query)\n // we don't want nested array if path is empty, i.e. `[]` instead of `[[]]`\n return splitPath.length ? [splitPath] : ([] as unknown as TRPCQueryKey);\n }\n\n if (\n type === 'infinite' &&\n isObject(input) &&\n ('direction' in input || 'cursor' in input)\n ) {\n const {\n cursor: _,\n direction: __,\n ...inputWithoutCursorAndDirection\n } = input;\n return [\n splitPath,\n {\n input: inputWithoutCursorAndDirection,\n type: 'infinite',\n },\n ];\n }\n return [\n splitPath,\n {\n ...(typeof input !== 'undefined' &&\n input !== skipToken && { input: input }),\n ...(type && type !== 'any' && { type: type }),\n },\n ];\n}\n\nexport function getMutationKeyInternal(path: readonly string[]) {\n return getQueryKeyInternal(path, undefined, 'any') as TRPCMutationKey;\n}\n\ntype GetInfiniteQueryInput<\n TProcedureInput,\n TInputWithoutCursorAndDirection = Omit<\n TProcedureInput,\n 'cursor' | 'direction'\n >,\n> = keyof TInputWithoutCursorAndDirection extends never\n ? undefined\n : DeepPartial<TInputWithoutCursorAndDirection> | undefined;\n\n/** @internal */\nexport type GetQueryProcedureInput<TProcedureInput> = TProcedureInput extends {\n cursor?: any;\n}\n ? GetInfiniteQueryInput<TProcedureInput>\n : DeepPartial<TProcedureInput> | undefined;\n\ntype GetParams<TProcedureOrRouter extends ProcedureOrRouter> =\n TProcedureOrRouter extends DecoratedQuery<infer $Def>\n ? [input?: GetQueryProcedureInput<$Def['input']>, type?: QueryType]\n : [];\n\n/**\n * Returns the TanStack Query key for a procedure or router.\n * @param procedureOrRouter - a procedure or router from `createTRPCReact`\n * @param input - the procedure input. Leave it out to match every input in\n * fuzzy operations like `invalidateQueries`.\n * @param type - `'query'`, `'infinite'` or `'any'` (default). `'any'` leaves\n * the type out of the key, so exact reads like `getQueryData` need the same\n * input the query used and the matching type. Infinite query keys leave out\n * `cursor` and `direction`.\n *\n * @deprecated `@trpc/react-query` only gets bug fixes and will be removed in\n * the next major version. Use `@trpc/tanstack-react-query` instead, where\n * each query procedure has a `queryKey()` method and each router has a\n * `pathKey()` method.\n * @see https://trpc.io/docs/client/tanstack-react-query/migrating\n * @see https://trpc.io/docs/client/tanstack-react-query/usage#queryKey\n * @see https://trpc.io/docs/client/react/getQueryKey\n */\nexport function getQueryKey<TProcedureOrRouter extends ProcedureOrRouter>(\n procedureOrRouter: TProcedureOrRouter,\n ..._params: GetParams<TProcedureOrRouter>\n) {\n const [input, type] = _params;\n\n // @ts-expect-error - we don't expose _def on the type layer\n const path = procedureOrRouter._def().path as string[];\n const queryKey = getQueryKeyInternal(path, input, type ?? 'any');\n return queryKey;\n}\n\n// TODO: look over if we can't use a single type\nexport type QueryKeyKnown<TInput, TType extends Exclude<QueryType, 'any'>> = [\n string[],\n { input?: GetQueryProcedureInput<TInput>; type: TType }?,\n];\n\n/**\n * Returns the TanStack Query mutation key for a procedure.\n *\n * @deprecated `@trpc/react-query` only gets bug fixes and will be removed in\n * the next major version. Use `@trpc/tanstack-react-query` instead, where\n * each mutation has a `mutationKey()` method.\n * @see https://trpc.io/docs/client/tanstack-react-query/migrating\n * @see https://trpc.io/docs/client/tanstack-react-query/usage#mutationKey\n * @see https://trpc.io/docs/client/react/getQueryKey#mutations\n */\nexport function getMutationKey<TProcedure extends DecoratedMutation<any>>(\n procedure: TProcedure,\n) {\n // @ts-expect-error - we don't expose _def on the type layer\n const path = procedure._def().path as string[];\n return getMutationKeyInternal(path);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqDM,MAAA,YAAA,CAAA,UACA,WAAA;;;;;;AA3BN,SAAgB,oBACd,MACA,OACA,MACc;CAMd,MAAM,YAAY,KAAK,SAAS,SAAS,KAAK,MAAM,GAAG,CAAC;CAExD,IAAI,OAAO,UAAU,gBAAgB,CAAC,QAAQ,SAAS,QAKrD,OAAO,UAAU,SAAS,CAAC,SAAS,IAAK,CAAC;CAG5C,IACE,SAAS,cACT,SAAS,KAAK,MACb,eAAe,SAAS,YAAY,QACrC;EACA,MAAM,EACJ,QAAQ,GACR,WAAW,OAAA;EAGb,OAAO,CACL,WACA;GACE,OAAA,yBAJA,OAAA,SAIoC;GACpC,MAAM;EACR,CACF;CACF;CACA,OAAO,CACL,WAAA,eAAA,eAAA,CAAA,GAEM,OAAO,UAAU,eACnB,UAAU,aAAa,EAAS,MAAM,CAAA,GACpC,QAAQ,SAAS,SAAS,EAAQ,KAAK,CAC7C,CACF;AACF;AAEA,SAAgB,uBAAuB,MAAyB;CAC9D,OAAO,oBAAoB,MAAM,KAAA,GAAW,KAAK;AACnD;;;;;;;;;;;;;;;;;;;AA0CA,SAAgB,YACd,mBACA,GAAG,SACH;CACA,MAAM,CAAC,OAAO,QAAQ;CAGtB,MAAM,OAAO,kBAAkB,KAAK,CAAC,CAAC;CAEtC,OADiB,oBAAoB,MAAM,OAAO,SAAA,QAAA,SAAA,KAAA,IAAA,OAAQ,KAC5C;AAChB;;;;;;;;;;;AAkBA,SAAgB,eACd,WACA;CAEA,MAAM,OAAO,UAAU,KAAK,CAAC,CAAC;CAC9B,OAAO,uBAAuB,IAAI;AACpC"}
|
|
@@ -128,11 +128,22 @@ function getMutationKeyInternal(path) {
|
|
|
128
128
|
return getQueryKeyInternal(path, void 0, "any");
|
|
129
129
|
}
|
|
130
130
|
/**
|
|
131
|
-
*
|
|
132
|
-
* @param procedureOrRouter - procedure or
|
|
133
|
-
* @param input - input to
|
|
134
|
-
*
|
|
135
|
-
* @
|
|
131
|
+
* Returns the TanStack Query key for a procedure or router.
|
|
132
|
+
* @param procedureOrRouter - a procedure or router from `createTRPCReact`
|
|
133
|
+
* @param input - the procedure input. Leave it out to match every input in
|
|
134
|
+
* fuzzy operations like `invalidateQueries`.
|
|
135
|
+
* @param type - `'query'`, `'infinite'` or `'any'` (default). `'any'` leaves
|
|
136
|
+
* the type out of the key, so exact reads like `getQueryData` need the same
|
|
137
|
+
* input the query used and the matching type. Infinite query keys leave out
|
|
138
|
+
* `cursor` and `direction`.
|
|
139
|
+
*
|
|
140
|
+
* @deprecated `@trpc/react-query` only gets bug fixes and will be removed in
|
|
141
|
+
* the next major version. Use `@trpc/tanstack-react-query` instead, where
|
|
142
|
+
* each query procedure has a `queryKey()` method and each router has a
|
|
143
|
+
* `pathKey()` method.
|
|
144
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/migrating
|
|
145
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/usage#queryKey
|
|
146
|
+
* @see https://trpc.io/docs/client/react/getQueryKey
|
|
136
147
|
*/
|
|
137
148
|
function getQueryKey(procedureOrRouter, ..._params) {
|
|
138
149
|
const [input, type] = _params;
|
|
@@ -140,9 +151,14 @@ function getQueryKey(procedureOrRouter, ..._params) {
|
|
|
140
151
|
return getQueryKeyInternal(path, input, type !== null && type !== void 0 ? type : "any");
|
|
141
152
|
}
|
|
142
153
|
/**
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
* @
|
|
154
|
+
* Returns the TanStack Query mutation key for a procedure.
|
|
155
|
+
*
|
|
156
|
+
* @deprecated `@trpc/react-query` only gets bug fixes and will be removed in
|
|
157
|
+
* the next major version. Use `@trpc/tanstack-react-query` instead, where
|
|
158
|
+
* each mutation has a `mutationKey()` method.
|
|
159
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/migrating
|
|
160
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/usage#mutationKey
|
|
161
|
+
* @see https://trpc.io/docs/client/react/getQueryKey#mutations
|
|
146
162
|
*/
|
|
147
163
|
function getMutationKey(procedure) {
|
|
148
164
|
const path = procedure._def().path;
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_getQueryKey = require("./getQueryKey-
|
|
3
|
-
const require_shared = require("./shared-
|
|
2
|
+
const require_getQueryKey = require("./getQueryKey-DASF3nl1.cjs");
|
|
3
|
+
const require_shared = require("./shared-v3jJm-s7.cjs");
|
|
4
4
|
let _trpc_server_unstable_core_do_not_import = require("@trpc/server/unstable-core-do-not-import");
|
|
5
5
|
let react = require("react");
|
|
6
6
|
react = require_getQueryKey.__toESM(react, 1);
|
|
@@ -21,11 +21,33 @@ function createHooksInternal(trpc) {
|
|
|
21
21
|
return proxy[key];
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Creates typed React hooks for your router, built on TanStack React Query.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* export const trpc = createTRPCReact<AppRouter>();
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @deprecated `@trpc/react-query` only gets bug fixes and will be removed in
|
|
33
|
+
* the next major version. Use `@trpc/tanstack-react-query` instead.
|
|
34
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/migrating
|
|
35
|
+
* @see https://trpc.io/docs/client/react/setup
|
|
36
|
+
*/
|
|
24
37
|
function createTRPCReact(opts) {
|
|
25
38
|
return createHooksInternal(require_shared.createRootHooks(opts));
|
|
26
39
|
}
|
|
27
40
|
//#endregion
|
|
28
41
|
//#region src/createTRPCQueryUtils.tsx
|
|
42
|
+
/**
|
|
43
|
+
* Creates the `useUtils` helpers outside of React, from a tRPC client and a
|
|
44
|
+
* `QueryClient`.
|
|
45
|
+
*
|
|
46
|
+
* @deprecated `@trpc/react-query` only gets bug fixes and will be removed in
|
|
47
|
+
* the next major version. Use `@trpc/tanstack-react-query` instead.
|
|
48
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/migrating
|
|
49
|
+
* @see https://trpc.io/docs/client/react/createTRPCQueryUtils
|
|
50
|
+
*/
|
|
29
51
|
function createTRPCQueryUtils(opts) {
|
|
30
52
|
const utils = require_shared.createUtilityFunctions(opts);
|
|
31
53
|
return require_shared.createQueryUtilsProxy(utils);
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { M as inferReactQueryProcedureOptions, T as CreateQueryUtils, i as CreateTRPCReactBase, n as getQueryKey, o as DecorateRouterRecord, r as CreateTRPCReact, s as createTRPCReact, t as getMutationKey } from "./getQueryKey-
|
|
1
|
+
import { M as inferReactQueryProcedureOptions, T as CreateQueryUtils, i as CreateTRPCReactBase, n as getQueryKey, o as DecorateRouterRecord, r as CreateTRPCReact, s as createTRPCReact, t as getMutationKey } from "./getQueryKey-CSENlbGR.cjs";
|
|
2
2
|
import { TRPCClient, TRPCUntypedClient } from "@trpc/client";
|
|
3
3
|
import { AnyRouter } from "@trpc/server/unstable-core-do-not-import";
|
|
4
4
|
import { QueryClient } from "@tanstack/react-query";
|
|
@@ -16,6 +16,15 @@ interface CreateQueryUtilsOptions<TRouter extends AnyRouter> {
|
|
|
16
16
|
}
|
|
17
17
|
//#endregion
|
|
18
18
|
//#region src/createTRPCQueryUtils.d.ts
|
|
19
|
+
/**
|
|
20
|
+
* Creates the `useUtils` helpers outside of React, from a tRPC client and a
|
|
21
|
+
* `QueryClient`.
|
|
22
|
+
*
|
|
23
|
+
* @deprecated `@trpc/react-query` only gets bug fixes and will be removed in
|
|
24
|
+
* the next major version. Use `@trpc/tanstack-react-query` instead.
|
|
25
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/migrating
|
|
26
|
+
* @see https://trpc.io/docs/client/react/createTRPCQueryUtils
|
|
27
|
+
*/
|
|
19
28
|
export declare function createTRPCQueryUtils<TRouter extends AnyRouter>(opts: CreateQueryUtilsOptions<TRouter>): CreateQueryUtils<TRouter>;
|
|
20
29
|
//#endregion
|
|
21
30
|
export { type CreateTRPCReact, type CreateTRPCReactBase, type DecorateRouterRecord, createTRPCReact, getMutationKey, getQueryKey, type inferReactQueryProcedureOptions };
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/utils/createUtilityFunctions.ts","../src/createTRPCQueryUtils.tsx"],"mappings":";;;;;;UAqBiB,wBAAwB,gBAAgB;;;;EAIvD,QAAQ,WAAW,WAAW,kBAAkB;;;;EAIhD,aAAa
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/utils/createUtilityFunctions.ts","../src/createTRPCQueryUtils.tsx"],"mappings":";;;;;;UAqBiB,wBAAwB,gBAAgB;;;;EAIvD,QAAQ,WAAW,WAAW,kBAAkB;;;;EAIhD,aAAa;;;;;;;;;;;;;wBCfC,qBAAqB,gBAAgB,WACnD,MAAM,wBAAwB,WAAQ,iBAAA"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { M as inferReactQueryProcedureOptions, T as CreateQueryUtils, i as CreateTRPCReactBase, n as getQueryKey, o as DecorateRouterRecord, r as CreateTRPCReact, s as createTRPCReact, t as getMutationKey } from "./getQueryKey-
|
|
1
|
+
import { M as inferReactQueryProcedureOptions, T as CreateQueryUtils, i as CreateTRPCReactBase, n as getQueryKey, o as DecorateRouterRecord, r as CreateTRPCReact, s as createTRPCReact, t as getMutationKey } from "./getQueryKey-BI6_waNM.mjs";
|
|
2
2
|
import { TRPCClient, TRPCUntypedClient } from "@trpc/client";
|
|
3
3
|
import { QueryClient } from "@tanstack/react-query";
|
|
4
4
|
import { AnyRouter } from "@trpc/server/unstable-core-do-not-import";
|
|
@@ -16,6 +16,15 @@ interface CreateQueryUtilsOptions<TRouter extends AnyRouter> {
|
|
|
16
16
|
}
|
|
17
17
|
//#endregion
|
|
18
18
|
//#region src/createTRPCQueryUtils.d.ts
|
|
19
|
+
/**
|
|
20
|
+
* Creates the `useUtils` helpers outside of React, from a tRPC client and a
|
|
21
|
+
* `QueryClient`.
|
|
22
|
+
*
|
|
23
|
+
* @deprecated `@trpc/react-query` only gets bug fixes and will be removed in
|
|
24
|
+
* the next major version. Use `@trpc/tanstack-react-query` instead.
|
|
25
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/migrating
|
|
26
|
+
* @see https://trpc.io/docs/client/react/createTRPCQueryUtils
|
|
27
|
+
*/
|
|
19
28
|
export declare function createTRPCQueryUtils<TRouter extends AnyRouter>(opts: CreateQueryUtilsOptions<TRouter>): CreateQueryUtils<TRouter>;
|
|
20
29
|
//#endregion
|
|
21
30
|
export { type CreateTRPCReact, type CreateTRPCReactBase, type DecorateRouterRecord, createTRPCReact, getMutationKey, getQueryKey, type inferReactQueryProcedureOptions };
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/utils/createUtilityFunctions.ts","../src/createTRPCQueryUtils.tsx"],"mappings":";;;;;;UAqBiB,wBAAwB,gBAAgB;;;;EAIvD,QAAQ,WAAW,WAAW,kBAAkB;;;;EAIhD,aAAa
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/utils/createUtilityFunctions.ts","../src/createTRPCQueryUtils.tsx"],"mappings":";;;;;;UAqBiB,wBAAwB,gBAAgB;;;;EAIvD,QAAQ,WAAW,WAAW,kBAAkB;;;;EAIhD,aAAa;;;;;;;;;;;;;wBCfC,qBAAqB,gBAAgB,WACnD,MAAM,wBAAwB,WAAQ,iBAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { r as getQueryKey, t as getMutationKey } from "./getQueryKey-
|
|
2
|
-
import { d as createReactDecoration, n as createRootHooks, o as createQueryUtilsProxy, r as createUtilityFunctions, s as createReactQueryUtils } from "./shared-
|
|
1
|
+
import { r as getQueryKey, t as getMutationKey } from "./getQueryKey-CWSorJjT.mjs";
|
|
2
|
+
import { d as createReactDecoration, n as createRootHooks, o as createQueryUtilsProxy, r as createUtilityFunctions, s as createReactQueryUtils } from "./shared-DyU-Vz6d.mjs";
|
|
3
3
|
import { createFlatProxy } from "@trpc/server/unstable-core-do-not-import";
|
|
4
4
|
import * as React from "react";
|
|
5
5
|
export * from "@trpc/client";
|
|
@@ -20,11 +20,33 @@ function createHooksInternal(trpc) {
|
|
|
20
20
|
return proxy[key];
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Creates typed React hooks for your router, built on TanStack React Query.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* export const trpc = createTRPCReact<AppRouter>();
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @deprecated `@trpc/react-query` only gets bug fixes and will be removed in
|
|
32
|
+
* the next major version. Use `@trpc/tanstack-react-query` instead.
|
|
33
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/migrating
|
|
34
|
+
* @see https://trpc.io/docs/client/react/setup
|
|
35
|
+
*/
|
|
23
36
|
function createTRPCReact(opts) {
|
|
24
37
|
return createHooksInternal(createRootHooks(opts));
|
|
25
38
|
}
|
|
26
39
|
//#endregion
|
|
27
40
|
//#region src/createTRPCQueryUtils.tsx
|
|
41
|
+
/**
|
|
42
|
+
* Creates the `useUtils` helpers outside of React, from a tRPC client and a
|
|
43
|
+
* `QueryClient`.
|
|
44
|
+
*
|
|
45
|
+
* @deprecated `@trpc/react-query` only gets bug fixes and will be removed in
|
|
46
|
+
* the next major version. Use `@trpc/tanstack-react-query` instead.
|
|
47
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/migrating
|
|
48
|
+
* @see https://trpc.io/docs/client/react/createTRPCQueryUtils
|
|
49
|
+
*/
|
|
28
50
|
function createTRPCQueryUtils(opts) {
|
|
29
51
|
const utils = createUtilityFunctions(opts);
|
|
30
52
|
return createQueryUtilsProxy(utils);
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/createTRPCReact.tsx","../src/createTRPCQueryUtils.tsx"],"sourcesContent":["import type {\n DefinedInitialDataInfiniteOptions,\n DefinedUseInfiniteQueryResult,\n InfiniteData,\n SkipToken,\n UndefinedInitialDataInfiniteOptions,\n UseInfiniteQueryOptions,\n UseInfiniteQueryResult,\n UseSuspenseInfiniteQueryOptions,\n UseSuspenseInfiniteQueryResult,\n UseSuspenseQueryResult,\n} from '@tanstack/react-query';\nimport type { createTRPCClient, TRPCClientErrorLike } from '@trpc/client';\nimport type {\n AnyProcedure,\n AnyRootTypes,\n AnyRouter,\n inferAsyncIterableYield,\n inferProcedureErrorShape,\n inferProcedureInput,\n inferTransformedProcedureOutput,\n ProcedureType,\n ProtectedIntersection,\n RouterRecord,\n Simplify,\n} from '@trpc/server/unstable-core-do-not-import';\nimport { createFlatProxy } from '@trpc/server/unstable-core-do-not-import';\nimport * as React from 'react';\nimport type {\n TRPCUseQueries,\n TRPCUseSuspenseQueries,\n} from './internals/useQueries';\nimport type {\n CreateReactUtils,\n TRPCFetchInfiniteQueryOptions,\n TRPCFetchQueryOptions,\n} from './shared';\nimport { createReactDecoration, createReactQueryUtils } from './shared';\nimport type { CreateReactQueryHooks } from './shared/hooks/createHooksInternal';\nimport { createRootHooks } from './shared/hooks/createHooksInternal';\nimport type {\n DefinedUseTRPCQueryOptions,\n DefinedUseTRPCQueryResult,\n TRPCHookResult,\n TRPCProvider,\n TRPCSubscriptionResult,\n TRPCUseQueryBaseOptions,\n UseTRPCMutationOptions,\n UseTRPCMutationResult,\n UseTRPCQueryOptions,\n UseTRPCQueryResult,\n UseTRPCSubscriptionOptions,\n UseTRPCSuspenseQueryOptions,\n} from './shared/hooks/types';\nimport type { CreateTRPCReactOptions } from './shared/types';\n\ntype ResolverDef = {\n input: any;\n output: any;\n transformer: boolean;\n errorShape: any;\n};\n/**\n * @internal\n */\nexport interface ProcedureUseQuery<TDef extends ResolverDef> {\n <TQueryFnData extends TDef['output'] = TDef['output'], TData = TQueryFnData>(\n input: TDef['input'] | SkipToken,\n opts: DefinedUseTRPCQueryOptions<\n TQueryFnData,\n TData,\n TRPCClientErrorLike<{\n errorShape: TDef['errorShape'];\n transformer: TDef['transformer'];\n }>,\n TDef['output']\n >,\n ): DefinedUseTRPCQueryResult<\n TData,\n TRPCClientErrorLike<{\n errorShape: TDef['errorShape'];\n transformer: TDef['transformer'];\n }>\n >;\n\n <TQueryFnData extends TDef['output'] = TDef['output'], TData = TQueryFnData>(\n input: TDef['input'] | SkipToken,\n opts?: UseTRPCQueryOptions<\n TQueryFnData,\n TData,\n TRPCClientErrorLike<TDef>,\n TDef['output']\n >,\n ): UseTRPCQueryResult<TData, TRPCClientErrorLike<TDef>>;\n}\n\n/**\n * @internal\n */\nexport type ProcedureUsePrefetchQuery<TDef extends ResolverDef> = (\n input: TDef['input'] | SkipToken,\n opts?: TRPCFetchQueryOptions<TDef['output'], TRPCClientErrorLike<TDef>>,\n) => void;\n\n/**\n * @remark `void` is here due to https://github.com/trpc/trpc/pull/4374\n */\ntype CursorInput = {\n cursor?: any;\n} | void;\n\ntype ReservedInfiniteQueryKeys = 'cursor' | 'direction';\ntype InfiniteInput<TInput> =\n | Omit<TInput, ReservedInfiniteQueryKeys>\n | SkipToken;\n\ntype inferCursorType<TInput> = TInput extends { cursor?: any }\n ? TInput['cursor']\n : unknown;\n\ntype makeInfiniteQueryOptions<TCursor, TOptions> = Omit<\n TOptions,\n 'queryKey' | 'initialPageParam' | 'queryFn' | 'queryHash' | 'queryHashFn'\n> &\n TRPCUseQueryBaseOptions & {\n initialCursor?: TCursor;\n };\n\ntype trpcInfiniteData<TDef extends ResolverDef> = Simplify<\n InfiniteData<TDef['output'], inferCursorType<TDef['input']>>\n>;\n// references from react-query\n// 1st\n// declare function useInfiniteQuery<\n// TQueryFnData,\n// TError = DefaultError,\n// TData = InfiniteData<TQueryFnData>,\n// TQueryKey extends QueryKey = QueryKey,\n// TPageParam = unknown,\n// >(\n// options: DefinedInitialDataInfiniteOptions<\n// TQueryFnData,\n// TError,\n// TData,\n// TQueryKey,\n// TPageParam\n// >,\n// queryClient?: QueryClient,\n// ): DefinedUseInfiniteQueryResult<TData, TError>;\n// 2nd\n// declare function useInfiniteQuery<\n// TQueryFnData,\n// TError = DefaultError,\n// TData = InfiniteData<TQueryFnData>,\n// TQueryKey extends QueryKey = QueryKey,\n// TPageParam = unknown,\n// >(\n// options: UndefinedInitialDataInfiniteOptions<\n// TQueryFnData,\n// TError,\n// TData,\n// TQueryKey,\n// TPageParam\n// >,\n// queryClient?: QueryClient,\n// ): UseInfiniteQueryResult<TData, TError>;\n// 3rd\n// declare function useInfiniteQuery<\n// TQueryFnData,\n// TError = DefaultError,\n// TData = InfiniteData<TQueryFnData>,\n// TQueryKey extends QueryKey = QueryKey,\n// TPageParam = unknown,\n// >(\n// options: UseInfiniteQueryOptions<\n// TQueryFnData,\n// TError,\n// TData,\n// TQueryFnData,\n// TQueryKey,\n// TPageParam\n// >,\n// queryClient?: QueryClient,\n// ): UseInfiniteQueryResult<TData, TError>;\n\nexport interface useTRPCInfiniteQuery<TDef extends ResolverDef> {\n // 1st\n <TData = trpcInfiniteData<TDef>>(\n input: InfiniteInput<TDef['input']>,\n opts: makeInfiniteQueryOptions<\n inferCursorType<TDef['input']>,\n DefinedInitialDataInfiniteOptions<\n // TQueryFnData,\n TDef['output'],\n // TError,\n TRPCClientErrorLike<TDef>,\n // TData,\n TData,\n // TQueryKey,\n any,\n // TPageParam\n inferCursorType<TDef['input']>\n >\n >,\n ): TRPCHookResult &\n DefinedUseInfiniteQueryResult<TData, TRPCClientErrorLike<TDef>>;\n\n // 2nd\n <TData = trpcInfiniteData<TDef>>(\n input: InfiniteInput<TDef['input']>,\n opts?: makeInfiniteQueryOptions<\n inferCursorType<TDef['input']>,\n UndefinedInitialDataInfiniteOptions<\n // TQueryFnData,\n TDef['output'],\n // TError,\n TRPCClientErrorLike<TDef>,\n // TData,\n TData,\n // TQueryKey,\n any,\n // TPageParam\n inferCursorType<TDef['input']>\n >\n >,\n ): TRPCHookResult & UseInfiniteQueryResult<TData, TRPCClientErrorLike<TDef>>;\n\n // 3rd:\n <TData = trpcInfiniteData<TDef>>(\n input: InfiniteInput<TDef['input']>,\n opts?: makeInfiniteQueryOptions<\n inferCursorType<TDef['input']>,\n UseInfiniteQueryOptions<\n // TQueryFnData,\n TDef['output'],\n // TError,\n TRPCClientErrorLike<TDef>,\n // TData,\n TData,\n // TQueryKey,\n any,\n // TPageParam\n inferCursorType<TDef['input']>\n >\n >,\n ): TRPCHookResult & UseInfiniteQueryResult<TData, TRPCClientErrorLike<TDef>>;\n}\n\n// references from react-query\n// declare function useSuspenseInfiniteQuery<\n// TQueryFnData,\n// TError = DefaultError,\n// TData = InfiniteData<TQueryFnData>,\n// TQueryKey extends QueryKey = QueryKey,\n// TPageParam = unknown,\n// >(\n// options: UseSuspenseInfiniteQueryOptions<\n// TQueryFnData,\n// TError,\n// TData,\n// TQueryFnData,\n// TQueryKey,\n// TPageParam\n// >,\n// queryClient?: QueryClient,\n// ): UseSuspenseInfiniteQueryResult<TData, TError>;\n\nexport type useTRPCSuspenseInfiniteQuery<TDef extends ResolverDef> = <\n TData = trpcInfiniteData<TDef>,\n>(\n input: InfiniteInput<TDef['input']>,\n opts: makeInfiniteQueryOptions<\n inferCursorType<TDef['input']>,\n UseSuspenseInfiniteQueryOptions<\n // TQueryFnData,\n TDef['output'],\n // TError,\n TRPCClientErrorLike<TDef>,\n // TData,\n TData,\n // TQueryKey,\n any,\n // TPageParam\n inferCursorType<TDef['input']>\n >\n >,\n) => [\n TData,\n TRPCHookResult &\n UseSuspenseInfiniteQueryResult<TData, TRPCClientErrorLike<TDef>>,\n];\n\n/**\n * @internal\n */\nexport type MaybeDecoratedInfiniteQuery<TDef extends ResolverDef> =\n TDef['input'] extends CursorInput\n ? {\n /**\n * @see https://trpc.io/docs/v11/client/react/useInfiniteQuery\n */\n useInfiniteQuery: useTRPCInfiniteQuery<TDef>;\n /**\n * @see https://trpc.io/docs/client/react/suspense#usesuspenseinfinitequery\n */\n useSuspenseInfiniteQuery: useTRPCSuspenseInfiniteQuery<TDef>;\n\n usePrefetchInfiniteQuery: (\n input: Omit<TDef['input'], ReservedInfiniteQueryKeys> | SkipToken,\n opts: TRPCFetchInfiniteQueryOptions<\n TDef['input'],\n TDef['output'],\n TRPCClientErrorLike<TDef>\n >,\n ) => void;\n }\n : object;\n\n/**\n * @internal\n */\nexport type DecoratedQueryMethods<TDef extends ResolverDef> = {\n /**\n * @see https://trpc.io/docs/v11/client/react/useQuery\n */\n useQuery: ProcedureUseQuery<TDef>;\n usePrefetchQuery: ProcedureUsePrefetchQuery<TDef>;\n /**\n * @see https://trpc.io/docs/v11/client/react/suspense#usesuspensequery\n */\n useSuspenseQuery: <\n TQueryFnData extends TDef['output'] = TDef['output'],\n TData = TQueryFnData,\n >(\n input: TDef['input'],\n opts?: UseTRPCSuspenseQueryOptions<\n TQueryFnData,\n TData,\n TRPCClientErrorLike<TDef>\n >,\n ) => [\n TData,\n UseSuspenseQueryResult<TData, TRPCClientErrorLike<TDef>> & TRPCHookResult,\n ];\n};\n\n/**\n * @internal\n */\nexport type DecoratedQuery<TDef extends ResolverDef> =\n MaybeDecoratedInfiniteQuery<TDef> & DecoratedQueryMethods<TDef>;\n\nexport type DecoratedMutation<TDef extends ResolverDef> = {\n /**\n * @see https://trpc.io/docs/v11/client/react/useMutation\n */\n useMutation: <TContext = unknown>(\n opts?: UseTRPCMutationOptions<\n TDef['input'],\n TRPCClientErrorLike<TDef>,\n TDef['output'],\n TContext\n >,\n ) => UseTRPCMutationResult<\n TDef['output'],\n TRPCClientErrorLike<TDef>,\n TDef['input'],\n TContext\n >;\n};\n\ninterface ProcedureUseSubscription<TDef extends ResolverDef> {\n // Without skip token\n (\n input: TDef['input'],\n opts?: UseTRPCSubscriptionOptions<\n inferAsyncIterableYield<TDef['output']>,\n TRPCClientErrorLike<TDef>\n >,\n ): TRPCSubscriptionResult<\n inferAsyncIterableYield<TDef['output']>,\n TRPCClientErrorLike<TDef>\n >;\n\n // With skip token\n (\n input: TDef['input'] | SkipToken,\n opts?: Omit<\n UseTRPCSubscriptionOptions<\n inferAsyncIterableYield<TDef['output']>,\n TRPCClientErrorLike<TDef>\n >,\n 'enabled'\n >,\n ): TRPCSubscriptionResult<\n inferAsyncIterableYield<TDef['output']>,\n TRPCClientErrorLike<TDef>\n >;\n}\n/**\n * @internal\n */\nexport type DecorateProcedure<\n TType extends ProcedureType,\n TDef extends ResolverDef,\n> = TType extends 'query'\n ? DecoratedQuery<TDef>\n : TType extends 'mutation'\n ? DecoratedMutation<TDef>\n : TType extends 'subscription'\n ? {\n /**\n * @see https://trpc.io/docs/v11/subscriptions\n */\n useSubscription: ProcedureUseSubscription<TDef>;\n }\n : never;\n\n/**\n * @internal\n */\nexport type DecorateRouterRecord<\n TRoot extends AnyRootTypes,\n TRecord extends RouterRecord,\n> = {\n [TKey in keyof TRecord]: TRecord[TKey] extends infer $Value\n ? $Value extends AnyProcedure\n ? DecorateProcedure<\n $Value['_def']['type'],\n {\n input: inferProcedureInput<$Value>;\n output: inferTransformedProcedureOutput<TRoot, $Value>;\n transformer: TRoot['transformer'];\n errorShape: inferProcedureErrorShape<TRoot, $Value>;\n }\n >\n : $Value extends RouterRecord\n ? DecorateRouterRecord<TRoot, $Value>\n : never\n : never;\n};\n\n/**\n * @internal\n */\nexport type CreateTRPCReactBase<TRouter extends AnyRouter, TSSRContext> = {\n /**\n * @deprecated renamed to `useUtils` and will be removed in a future tRPC version\n *\n * @see https://trpc.io/docs/v11/client/react/useUtils\n */\n useContext(): CreateReactUtils<TRouter, TSSRContext>;\n /**\n * @see https://trpc.io/docs/v11/client/react/useUtils\n */\n useUtils(): CreateReactUtils<TRouter, TSSRContext>;\n Provider: TRPCProvider<TRouter, TSSRContext>;\n createClient: typeof createTRPCClient<TRouter>;\n useQueries: TRPCUseQueries<TRouter>;\n useSuspenseQueries: TRPCUseSuspenseQueries<TRouter>;\n};\n\nexport type CreateTRPCReact<\n TRouter extends AnyRouter,\n TSSRContext,\n> = ProtectedIntersection<\n CreateTRPCReactBase<TRouter, TSSRContext>,\n DecorateRouterRecord<\n TRouter['_def']['_config']['$types'],\n TRouter['_def']['record']\n >\n>;\n\n/**\n * @internal\n */\nexport function createHooksInternal<\n TRouter extends AnyRouter,\n TSSRContext = unknown,\n>(trpc: CreateReactQueryHooks<TRouter, TSSRContext>) {\n type CreateHooksInternal = CreateTRPCReact<TRouter, TSSRContext>;\n\n const proxy = createReactDecoration<TRouter, TSSRContext>(\n trpc,\n ) as DecorateRouterRecord<\n TRouter['_def']['_config']['$types'],\n TRouter['_def']['record']\n >;\n return createFlatProxy<CreateHooksInternal>((key) => {\n if (key === 'useContext' || key === 'useUtils') {\n return () => {\n const context = trpc.useUtils();\n // create a stable reference of the utils context\n return React.useMemo(() => {\n return (createReactQueryUtils as any)(context);\n }, [context]);\n };\n }\n\n if (trpc.hasOwnProperty(key)) {\n return (trpc as any)[key];\n }\n\n return proxy[key];\n });\n}\n\nexport function createTRPCReact<\n TRouter extends AnyRouter,\n TSSRContext = unknown,\n>(\n opts?: CreateTRPCReactOptions<TRouter>,\n): CreateTRPCReact<TRouter, TSSRContext> {\n const hooks = createRootHooks<TRouter, TSSRContext>(opts);\n const proxy = createHooksInternal<TRouter, TSSRContext>(hooks);\n\n return proxy as any;\n}\n","import type { AnyRouter } from '@trpc/server/unstable-core-do-not-import';\nimport { createQueryUtilsProxy } from './shared';\nimport type { CreateQueryUtilsOptions } from './utils/createUtilityFunctions';\nimport { createUtilityFunctions } from './utils/createUtilityFunctions';\n\nexport function createTRPCQueryUtils<TRouter extends AnyRouter>(\n opts: CreateQueryUtilsOptions<TRouter>,\n) {\n const utils = createUtilityFunctions(opts);\n return createQueryUtilsProxy<TRouter>(utils);\n}\n"],"mappings":";;;;;;;;;AA4dA,SAAgB,oBAGd,MAAmD;CAGnD,MAAM,QAAQ,sBACZ,IACF;CAIA,OAAO,iBAAsC,QAAQ;EACnD,IAAI,QAAQ,gBAAgB,QAAQ,YAClC,aAAa;GACX,MAAM,UAAU,KAAK,SAAS;GAE9B,OAAO,MAAM,cAAc;IACzB,OAAQ,sBAA8B,OAAO;GAC/C,GAAG,CAAC,OAAO,CAAC;EACd;EAGF,IAAI,KAAK,eAAe,GAAG,GACzB,OAAQ,KAAa;EAGvB,OAAO,MAAM;CACf,CAAC;AACH;AAEA,SAAgB,gBAId,MACuC;CAIvC,OAFc,oBADA,gBAAsC,IACQ,CAEjD;AACb;;;AChgBA,SAAgB,qBACd,MACA;CACA,MAAM,QAAQ,uBAAuB,IAAI;CACzC,OAAO,sBAA+B,KAAK;AAC7C"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/createTRPCReact.tsx","../src/createTRPCQueryUtils.tsx"],"sourcesContent":["import type {\n DefinedInitialDataInfiniteOptions,\n DefinedUseInfiniteQueryResult,\n InfiniteData,\n SkipToken,\n UndefinedInitialDataInfiniteOptions,\n UseInfiniteQueryOptions,\n UseInfiniteQueryResult,\n UseSuspenseInfiniteQueryOptions,\n UseSuspenseInfiniteQueryResult,\n UseSuspenseQueryResult,\n} from '@tanstack/react-query';\nimport type { createTRPCClient, TRPCClientErrorLike } from '@trpc/client';\nimport type {\n AnyProcedure,\n AnyRootTypes,\n AnyRouter,\n inferAsyncIterableYield,\n inferProcedureErrorShape,\n inferProcedureInput,\n inferTransformedProcedureOutput,\n ProcedureType,\n ProtectedIntersection,\n RouterRecord,\n Simplify,\n} from '@trpc/server/unstable-core-do-not-import';\nimport { createFlatProxy } from '@trpc/server/unstable-core-do-not-import';\nimport * as React from 'react';\nimport type {\n TRPCUseQueries,\n TRPCUseSuspenseQueries,\n} from './internals/useQueries';\nimport type {\n CreateReactUtils,\n TRPCFetchInfiniteQueryOptions,\n TRPCFetchQueryOptions,\n} from './shared';\nimport { createReactDecoration, createReactQueryUtils } from './shared';\nimport type { CreateReactQueryHooks } from './shared/hooks/createHooksInternal';\nimport { createRootHooks } from './shared/hooks/createHooksInternal';\nimport type {\n DefinedUseTRPCQueryOptions,\n DefinedUseTRPCQueryResult,\n TRPCHookResult,\n TRPCProvider,\n TRPCSubscriptionResult,\n TRPCUseQueryBaseOptions,\n UseTRPCMutationOptions,\n UseTRPCMutationResult,\n UseTRPCQueryOptions,\n UseTRPCQueryResult,\n UseTRPCSubscriptionOptions,\n UseTRPCSuspenseQueryOptions,\n} from './shared/hooks/types';\nimport type { CreateTRPCReactOptions } from './shared/types';\n\ntype ResolverDef = {\n input: any;\n output: any;\n transformer: boolean;\n errorShape: any;\n};\n/**\n * @internal\n */\nexport interface ProcedureUseQuery<TDef extends ResolverDef> {\n <TQueryFnData extends TDef['output'] = TDef['output'], TData = TQueryFnData>(\n input: TDef['input'] | SkipToken,\n opts: DefinedUseTRPCQueryOptions<\n TQueryFnData,\n TData,\n TRPCClientErrorLike<{\n errorShape: TDef['errorShape'];\n transformer: TDef['transformer'];\n }>,\n TDef['output']\n >,\n ): DefinedUseTRPCQueryResult<\n TData,\n TRPCClientErrorLike<{\n errorShape: TDef['errorShape'];\n transformer: TDef['transformer'];\n }>\n >;\n\n <TQueryFnData extends TDef['output'] = TDef['output'], TData = TQueryFnData>(\n input: TDef['input'] | SkipToken,\n opts?: UseTRPCQueryOptions<\n TQueryFnData,\n TData,\n TRPCClientErrorLike<TDef>,\n TDef['output']\n >,\n ): UseTRPCQueryResult<TData, TRPCClientErrorLike<TDef>>;\n}\n\n/**\n * @internal\n */\nexport type ProcedureUsePrefetchQuery<TDef extends ResolverDef> = (\n input: TDef['input'] | SkipToken,\n opts?: TRPCFetchQueryOptions<TDef['output'], TRPCClientErrorLike<TDef>>,\n) => void;\n\n/**\n * @remark `void` is here due to https://github.com/trpc/trpc/pull/4374\n */\ntype CursorInput = {\n cursor?: any;\n} | void;\n\ntype ReservedInfiniteQueryKeys = 'cursor' | 'direction';\ntype InfiniteInput<TInput> =\n | Omit<TInput, ReservedInfiniteQueryKeys>\n | SkipToken;\n\ntype inferCursorType<TInput> = TInput extends { cursor?: any }\n ? TInput['cursor']\n : unknown;\n\ntype makeInfiniteQueryOptions<TCursor, TOptions> = Omit<\n TOptions,\n 'queryKey' | 'initialPageParam' | 'queryFn' | 'queryHash' | 'queryHashFn'\n> &\n TRPCUseQueryBaseOptions & {\n initialCursor?: TCursor;\n };\n\ntype trpcInfiniteData<TDef extends ResolverDef> = Simplify<\n InfiniteData<TDef['output'], inferCursorType<TDef['input']>>\n>;\n// references from react-query\n// 1st\n// declare function useInfiniteQuery<\n// TQueryFnData,\n// TError = DefaultError,\n// TData = InfiniteData<TQueryFnData>,\n// TQueryKey extends QueryKey = QueryKey,\n// TPageParam = unknown,\n// >(\n// options: DefinedInitialDataInfiniteOptions<\n// TQueryFnData,\n// TError,\n// TData,\n// TQueryKey,\n// TPageParam\n// >,\n// queryClient?: QueryClient,\n// ): DefinedUseInfiniteQueryResult<TData, TError>;\n// 2nd\n// declare function useInfiniteQuery<\n// TQueryFnData,\n// TError = DefaultError,\n// TData = InfiniteData<TQueryFnData>,\n// TQueryKey extends QueryKey = QueryKey,\n// TPageParam = unknown,\n// >(\n// options: UndefinedInitialDataInfiniteOptions<\n// TQueryFnData,\n// TError,\n// TData,\n// TQueryKey,\n// TPageParam\n// >,\n// queryClient?: QueryClient,\n// ): UseInfiniteQueryResult<TData, TError>;\n// 3rd\n// declare function useInfiniteQuery<\n// TQueryFnData,\n// TError = DefaultError,\n// TData = InfiniteData<TQueryFnData>,\n// TQueryKey extends QueryKey = QueryKey,\n// TPageParam = unknown,\n// >(\n// options: UseInfiniteQueryOptions<\n// TQueryFnData,\n// TError,\n// TData,\n// TQueryFnData,\n// TQueryKey,\n// TPageParam\n// >,\n// queryClient?: QueryClient,\n// ): UseInfiniteQueryResult<TData, TError>;\n\nexport interface useTRPCInfiniteQuery<TDef extends ResolverDef> {\n // 1st\n <TData = trpcInfiniteData<TDef>>(\n input: InfiniteInput<TDef['input']>,\n opts: makeInfiniteQueryOptions<\n inferCursorType<TDef['input']>,\n DefinedInitialDataInfiniteOptions<\n // TQueryFnData,\n TDef['output'],\n // TError,\n TRPCClientErrorLike<TDef>,\n // TData,\n TData,\n // TQueryKey,\n any,\n // TPageParam\n inferCursorType<TDef['input']>\n >\n >,\n ): TRPCHookResult &\n DefinedUseInfiniteQueryResult<TData, TRPCClientErrorLike<TDef>>;\n\n // 2nd\n <TData = trpcInfiniteData<TDef>>(\n input: InfiniteInput<TDef['input']>,\n opts?: makeInfiniteQueryOptions<\n inferCursorType<TDef['input']>,\n UndefinedInitialDataInfiniteOptions<\n // TQueryFnData,\n TDef['output'],\n // TError,\n TRPCClientErrorLike<TDef>,\n // TData,\n TData,\n // TQueryKey,\n any,\n // TPageParam\n inferCursorType<TDef['input']>\n >\n >,\n ): TRPCHookResult & UseInfiniteQueryResult<TData, TRPCClientErrorLike<TDef>>;\n\n // 3rd:\n <TData = trpcInfiniteData<TDef>>(\n input: InfiniteInput<TDef['input']>,\n opts?: makeInfiniteQueryOptions<\n inferCursorType<TDef['input']>,\n UseInfiniteQueryOptions<\n // TQueryFnData,\n TDef['output'],\n // TError,\n TRPCClientErrorLike<TDef>,\n // TData,\n TData,\n // TQueryKey,\n any,\n // TPageParam\n inferCursorType<TDef['input']>\n >\n >,\n ): TRPCHookResult & UseInfiniteQueryResult<TData, TRPCClientErrorLike<TDef>>;\n}\n\n// references from react-query\n// declare function useSuspenseInfiniteQuery<\n// TQueryFnData,\n// TError = DefaultError,\n// TData = InfiniteData<TQueryFnData>,\n// TQueryKey extends QueryKey = QueryKey,\n// TPageParam = unknown,\n// >(\n// options: UseSuspenseInfiniteQueryOptions<\n// TQueryFnData,\n// TError,\n// TData,\n// TQueryFnData,\n// TQueryKey,\n// TPageParam\n// >,\n// queryClient?: QueryClient,\n// ): UseSuspenseInfiniteQueryResult<TData, TError>;\n\nexport type useTRPCSuspenseInfiniteQuery<TDef extends ResolverDef> = <\n TData = trpcInfiniteData<TDef>,\n>(\n input: InfiniteInput<TDef['input']>,\n opts: makeInfiniteQueryOptions<\n inferCursorType<TDef['input']>,\n UseSuspenseInfiniteQueryOptions<\n // TQueryFnData,\n TDef['output'],\n // TError,\n TRPCClientErrorLike<TDef>,\n // TData,\n TData,\n // TQueryKey,\n any,\n // TPageParam\n inferCursorType<TDef['input']>\n >\n >,\n) => [\n TData,\n TRPCHookResult &\n UseSuspenseInfiniteQueryResult<TData, TRPCClientErrorLike<TDef>>,\n];\n\n/**\n * @internal\n */\nexport type MaybeDecoratedInfiniteQuery<TDef extends ResolverDef> =\n TDef['input'] extends CursorInput\n ? {\n /**\n * @see https://trpc.io/docs/client/react/useInfiniteQuery\n */\n useInfiniteQuery: useTRPCInfiniteQuery<TDef>;\n /**\n * @see https://trpc.io/docs/client/react/suspense#usesuspenseinfinitequery\n */\n useSuspenseInfiniteQuery: useTRPCSuspenseInfiniteQuery<TDef>;\n\n usePrefetchInfiniteQuery: (\n input: Omit<TDef['input'], ReservedInfiniteQueryKeys> | SkipToken,\n opts: TRPCFetchInfiniteQueryOptions<\n TDef['input'],\n TDef['output'],\n TRPCClientErrorLike<TDef>\n >,\n ) => void;\n }\n : object;\n\n/**\n * @internal\n */\nexport type DecoratedQueryMethods<TDef extends ResolverDef> = {\n /**\n * @see https://trpc.io/docs/client/react/useQuery\n */\n useQuery: ProcedureUseQuery<TDef>;\n usePrefetchQuery: ProcedureUsePrefetchQuery<TDef>;\n /**\n * @see https://trpc.io/docs/client/react/suspense#usesuspensequery\n */\n useSuspenseQuery: <\n TQueryFnData extends TDef['output'] = TDef['output'],\n TData = TQueryFnData,\n >(\n input: TDef['input'],\n opts?: UseTRPCSuspenseQueryOptions<\n TQueryFnData,\n TData,\n TRPCClientErrorLike<TDef>\n >,\n ) => [\n TData,\n UseSuspenseQueryResult<TData, TRPCClientErrorLike<TDef>> & TRPCHookResult,\n ];\n};\n\n/**\n * @internal\n */\nexport type DecoratedQuery<TDef extends ResolverDef> =\n MaybeDecoratedInfiniteQuery<TDef> & DecoratedQueryMethods<TDef>;\n\nexport type DecoratedMutation<TDef extends ResolverDef> = {\n /**\n * @see https://trpc.io/docs/client/react/useMutation\n */\n useMutation: <TContext = unknown>(\n opts?: UseTRPCMutationOptions<\n TDef['input'],\n TRPCClientErrorLike<TDef>,\n TDef['output'],\n TContext\n >,\n ) => UseTRPCMutationResult<\n TDef['output'],\n TRPCClientErrorLike<TDef>,\n TDef['input'],\n TContext\n >;\n};\n\ninterface ProcedureUseSubscription<TDef extends ResolverDef> {\n // Without skip token\n (\n input: TDef['input'],\n opts?: UseTRPCSubscriptionOptions<\n inferAsyncIterableYield<TDef['output']>,\n TRPCClientErrorLike<TDef>\n >,\n ): TRPCSubscriptionResult<\n inferAsyncIterableYield<TDef['output']>,\n TRPCClientErrorLike<TDef>\n >;\n\n // With skip token\n (\n input: TDef['input'] | SkipToken,\n opts?: Omit<\n UseTRPCSubscriptionOptions<\n inferAsyncIterableYield<TDef['output']>,\n TRPCClientErrorLike<TDef>\n >,\n 'enabled'\n >,\n ): TRPCSubscriptionResult<\n inferAsyncIterableYield<TDef['output']>,\n TRPCClientErrorLike<TDef>\n >;\n}\n/**\n * @internal\n */\nexport type DecorateProcedure<\n TType extends ProcedureType,\n TDef extends ResolverDef,\n> = TType extends 'query'\n ? DecoratedQuery<TDef>\n : TType extends 'mutation'\n ? DecoratedMutation<TDef>\n : TType extends 'subscription'\n ? {\n /**\n * @see https://trpc.io/docs/client/react/useSubscription\n */\n useSubscription: ProcedureUseSubscription<TDef>;\n }\n : never;\n\n/**\n * @internal\n */\nexport type DecorateRouterRecord<\n TRoot extends AnyRootTypes,\n TRecord extends RouterRecord,\n> = {\n [TKey in keyof TRecord]: TRecord[TKey] extends infer $Value\n ? $Value extends AnyProcedure\n ? DecorateProcedure<\n $Value['_def']['type'],\n {\n input: inferProcedureInput<$Value>;\n output: inferTransformedProcedureOutput<TRoot, $Value>;\n transformer: TRoot['transformer'];\n errorShape: inferProcedureErrorShape<TRoot, $Value>;\n }\n >\n : $Value extends RouterRecord\n ? DecorateRouterRecord<TRoot, $Value>\n : never\n : never;\n};\n\n/**\n * @internal\n */\nexport type CreateTRPCReactBase<TRouter extends AnyRouter, TSSRContext> = {\n /**\n * @deprecated renamed to `useUtils` and will be removed in a future tRPC version\n *\n * @see https://trpc.io/docs/client/react/useUtils\n */\n useContext(): CreateReactUtils<TRouter, TSSRContext>;\n /**\n * @see https://trpc.io/docs/client/react/useUtils\n */\n useUtils(): CreateReactUtils<TRouter, TSSRContext>;\n /**\n * Provides the tRPC client and `QueryClient` to the hooks.\n * @see https://trpc.io/docs/client/react/setup#4-add-trpc-providers\n */\n Provider: TRPCProvider<TRouter, TSSRContext>;\n /**\n * Same as `createTRPCClient`, typed for this router.\n */\n createClient: typeof createTRPCClient<TRouter>;\n /**\n * @see https://trpc.io/docs/client/react/useQueries\n */\n useQueries: TRPCUseQueries<TRouter>;\n /**\n * @see https://trpc.io/docs/client/react/suspense#usesuspensequeries\n */\n useSuspenseQueries: TRPCUseSuspenseQueries<TRouter>;\n};\n\n/**\n * The hooks object returned by {@link createTRPCReact}.\n *\n * @deprecated `@trpc/react-query` only gets bug fixes and will be removed in\n * the next major version. Use `@trpc/tanstack-react-query` instead.\n * @see https://trpc.io/docs/client/tanstack-react-query/migrating\n */\nexport type CreateTRPCReact<\n TRouter extends AnyRouter,\n TSSRContext,\n> = ProtectedIntersection<\n CreateTRPCReactBase<TRouter, TSSRContext>,\n DecorateRouterRecord<\n TRouter['_def']['_config']['$types'],\n TRouter['_def']['record']\n >\n>;\n\n/**\n * @internal\n */\nexport function createHooksInternal<\n TRouter extends AnyRouter,\n TSSRContext = unknown,\n>(trpc: CreateReactQueryHooks<TRouter, TSSRContext>) {\n type CreateHooksInternal = CreateTRPCReact<TRouter, TSSRContext>;\n\n const proxy = createReactDecoration<TRouter, TSSRContext>(\n trpc,\n ) as DecorateRouterRecord<\n TRouter['_def']['_config']['$types'],\n TRouter['_def']['record']\n >;\n return createFlatProxy<CreateHooksInternal>((key) => {\n if (key === 'useContext' || key === 'useUtils') {\n return () => {\n const context = trpc.useUtils();\n // create a stable reference of the utils context\n return React.useMemo(() => {\n return (createReactQueryUtils as any)(context);\n }, [context]);\n };\n }\n\n if (trpc.hasOwnProperty(key)) {\n return (trpc as any)[key];\n }\n\n return proxy[key];\n });\n}\n\n/**\n * Creates typed React hooks for your router, built on TanStack React Query.\n *\n * @example\n * ```ts\n * export const trpc = createTRPCReact<AppRouter>();\n * ```\n *\n * @deprecated `@trpc/react-query` only gets bug fixes and will be removed in\n * the next major version. Use `@trpc/tanstack-react-query` instead.\n * @see https://trpc.io/docs/client/tanstack-react-query/migrating\n * @see https://trpc.io/docs/client/react/setup\n */\nexport function createTRPCReact<\n TRouter extends AnyRouter,\n TSSRContext = unknown,\n>(\n opts?: CreateTRPCReactOptions<TRouter>,\n): CreateTRPCReact<TRouter, TSSRContext> {\n const hooks = createRootHooks<TRouter, TSSRContext>(opts);\n const proxy = createHooksInternal<TRouter, TSSRContext>(hooks);\n\n return proxy as any;\n}\n","import type { AnyRouter } from '@trpc/server/unstable-core-do-not-import';\nimport { createQueryUtilsProxy } from './shared';\nimport type { CreateQueryUtilsOptions } from './utils/createUtilityFunctions';\nimport { createUtilityFunctions } from './utils/createUtilityFunctions';\n\n/**\n * Creates the `useUtils` helpers outside of React, from a tRPC client and a\n * `QueryClient`.\n *\n * @deprecated `@trpc/react-query` only gets bug fixes and will be removed in\n * the next major version. Use `@trpc/tanstack-react-query` instead.\n * @see https://trpc.io/docs/client/tanstack-react-query/migrating\n * @see https://trpc.io/docs/client/react/createTRPCQueryUtils\n */\nexport function createTRPCQueryUtils<TRouter extends AnyRouter>(\n opts: CreateQueryUtilsOptions<TRouter>,\n) {\n const utils = createUtilityFunctions(opts);\n return createQueryUtilsProxy<TRouter>(utils);\n}\n"],"mappings":";;;;;;;;;AAgfA,SAAgB,oBAGd,MAAmD;CAGnD,MAAM,QAAQ,sBACZ,IACF;CAIA,OAAO,iBAAsC,QAAQ;EACnD,IAAI,QAAQ,gBAAgB,QAAQ,YAClC,aAAa;GACX,MAAM,UAAU,KAAK,SAAS;GAE9B,OAAO,MAAM,cAAc;IACzB,OAAQ,sBAA8B,OAAO;GAC/C,GAAG,CAAC,OAAO,CAAC;EACd;EAGF,IAAI,KAAK,eAAe,GAAG,GACzB,OAAQ,KAAa;EAGvB,OAAO,MAAM;CACf,CAAC;AACH;;;;;;;;;;;;;;AAeA,SAAgB,gBAId,MACuC;CAIvC,OAFc,oBADA,gBAAsC,IACQ,CAEjD;AACb;;;;;;;;;;;;ACxhBA,SAAgB,qBACd,MACA;CACA,MAAM,QAAQ,uBAAuB,IAAI;CACzC,OAAO,sBAA+B,KAAK;AAC7C"}
|
package/dist/rsc.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_getQueryKey = require("./getQueryKey-
|
|
2
|
+
const require_getQueryKey = require("./getQueryKey-DASF3nl1.cjs");
|
|
3
3
|
let _tanstack_react_query = require("@tanstack/react-query");
|
|
4
4
|
let _trpc_server_unstable_core_do_not_import = require("@trpc/server/unstable-core-do-not-import");
|
|
5
5
|
let react = require("react");
|
|
@@ -7,6 +7,9 @@ react = require_getQueryKey.__toESM(react, 1);
|
|
|
7
7
|
//#region src/rsc.tsx
|
|
8
8
|
const HELPERS = ["prefetch", "prefetchInfinite"];
|
|
9
9
|
/**
|
|
10
|
+
* Creates a server-side caller that can also prefetch queries, plus a
|
|
11
|
+
* `HydrateClient` component that sends the prefetched data to the client.
|
|
12
|
+
*
|
|
10
13
|
* @note This requires `@tanstack/react-query@^5.49.0`
|
|
11
14
|
* @note Make sure to have `dehydrate.serializeData` and `hydrate.deserializeData`
|
|
12
15
|
* set to your data transformer in your `QueryClient` factory.
|
|
@@ -24,6 +27,11 @@ const HELPERS = ["prefetch", "prefetchInfinite"];
|
|
|
24
27
|
* },
|
|
25
28
|
* });
|
|
26
29
|
* ```
|
|
30
|
+
*
|
|
31
|
+
* @deprecated `@trpc/react-query` only gets bug fixes and will be removed in
|
|
32
|
+
* the next major version. Use `@trpc/tanstack-react-query` instead.
|
|
33
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/migrating
|
|
34
|
+
* @see https://trpc.io/docs/client/react/server-components
|
|
27
35
|
*/
|
|
28
36
|
function createHydrationHelpers(caller, getQueryClient) {
|
|
29
37
|
const wrappedProxy = (0, _trpc_server_unstable_core_do_not_import.createRecursiveProxy)(async (opts) => {
|
package/dist/rsc.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Ft as TRPCFetchInfiniteQueryOptions, It as TRPCFetchQueryOptions } from "./getQueryKey-
|
|
1
|
+
import { Ft as TRPCFetchInfiniteQueryOptions, It as TRPCFetchQueryOptions } from "./getQueryKey-CSENlbGR.cjs";
|
|
2
2
|
import { TRPCClientError } from "@trpc/client";
|
|
3
3
|
import { AnyProcedure, AnyRootTypes, AnyRouter, RouterCaller, RouterRecord, TypeError, inferProcedureInput, inferProcedureOutput, inferRouterRootTypes } from "@trpc/server/unstable-core-do-not-import";
|
|
4
4
|
import { QueryClient } from "@tanstack/react-query";
|
|
@@ -13,6 +13,9 @@ type DecorateProcedure<TRoot extends AnyRootTypes, TProcedure extends AnyProcedu
|
|
|
13
13
|
type DecorateRouterRecord<TRoot extends AnyRootTypes, TRecord extends RouterRecord> = { [TKey in keyof TRecord]: TRecord[TKey] extends (infer $Value) ? $Value extends AnyProcedure ? DecorateProcedure<TRoot, $Value> : $Value extends RouterRecord ? DecorateRouterRecord<TRoot, $Value> : never : never; };
|
|
14
14
|
type Caller<TRouter extends AnyRouter> = ReturnType<RouterCaller<inferRouterRootTypes<TRouter>, TRouter['_def']['record']>>;
|
|
15
15
|
/**
|
|
16
|
+
* Creates a server-side caller that can also prefetch queries, plus a
|
|
17
|
+
* `HydrateClient` component that sends the prefetched data to the client.
|
|
18
|
+
*
|
|
16
19
|
* @note This requires `@tanstack/react-query@^5.49.0`
|
|
17
20
|
* @note Make sure to have `dehydrate.serializeData` and `hydrate.deserializeData`
|
|
18
21
|
* set to your data transformer in your `QueryClient` factory.
|
|
@@ -30,6 +33,11 @@ type Caller<TRouter extends AnyRouter> = ReturnType<RouterCaller<inferRouterRoot
|
|
|
30
33
|
* },
|
|
31
34
|
* });
|
|
32
35
|
* ```
|
|
36
|
+
*
|
|
37
|
+
* @deprecated `@trpc/react-query` only gets bug fixes and will be removed in
|
|
38
|
+
* the next major version. Use `@trpc/tanstack-react-query` instead.
|
|
39
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/migrating
|
|
40
|
+
* @see https://trpc.io/docs/client/react/server-components
|
|
33
41
|
*/
|
|
34
42
|
export declare function createHydrationHelpers<TRouter extends AnyRouter>(caller: AnyRouter extends TRouter ? TypeError<'Generic parameter missing in `createHydrationHelpers<HERE>`'> : Caller<TRouter>, getQueryClient: () => QueryClient): {
|
|
35
43
|
/***
|
package/dist/rsc.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rsc.d.cts","names":[],"sources":["../src/rsc.tsx"],"mappings":";;;;;;;KAiCK,kBACH,cAAc,cACd,mBAAmB;GAGjB,OAAO,oBAAoB,cAC1B,QAAQ,qBAAqB;EAChC,WACE,OAAO,oBAAoB,aAC3B,OAAO,sBACL,kCAAgC,OAAO,aACvC,gBAAgB,YAEf;EACL,mBACE,OAAO,oBAAoB,aAC3B,OAAO,8BACL,oBAAoB,aACpB,kCAAgC,OAAO,aACvC,gBAAgB,YAEf;;KAGF,qBACH,cAAc,cACd,gBAAgB,mBAEf,cAAc,UAAU,QAAQ,qBAAoB,UACjD,eAAe,eACb,kBAAkB,OAAO,UACzB,eAAe,eACb,qBAAqB,OAAO;KAKjC,OAAO,gBAAgB,aAAa,WACvC,aAAa,qBAAqB,UAAU
|
|
1
|
+
{"version":3,"file":"rsc.d.cts","names":[],"sources":["../src/rsc.tsx"],"mappings":";;;;;;;KAiCK,kBACH,cAAc,cACd,mBAAmB;GAGjB,OAAO,oBAAoB,cAC1B,QAAQ,qBAAqB;EAChC,WACE,OAAO,oBAAoB,aAC3B,OAAO,sBACL,kCAAgC,OAAO,aACvC,gBAAgB,YAEf;EACL,mBACE,OAAO,oBAAoB,aAC3B,OAAO,8BACL,oBAAoB,aACpB,kCAAgC,OAAO,aACvC,gBAAgB,YAEf;;KAGF,qBACH,cAAc,cACd,gBAAgB,mBAEf,cAAc,UAAU,QAAQ,qBAAoB,UACjD,eAAe,eACb,kBAAkB,OAAO,UACzB,eAAe,eACb,qBAAqB,OAAO;KAKjC,OAAO,gBAAgB,aAAa,WACvC,aAAa,qBAAqB,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA+B9B,uBAAuB,gBAAgB,WACrD,QAAQ,kBAAkB,UACtB,2EACA,OAAO,UACX,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+CQ,gBAAA;IAAE,UAAU,MAAM;QAAW,MAAA,IAAA"}
|
package/dist/rsc.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Ft as TRPCFetchInfiniteQueryOptions, It as TRPCFetchQueryOptions } from "./getQueryKey-
|
|
1
|
+
import { Ft as TRPCFetchInfiniteQueryOptions, It as TRPCFetchQueryOptions } from "./getQueryKey-BI6_waNM.mjs";
|
|
2
2
|
import { TRPCClientError } from "@trpc/client";
|
|
3
3
|
import { QueryClient } from "@tanstack/react-query";
|
|
4
4
|
import { AnyProcedure, AnyRootTypes, AnyRouter, RouterCaller, RouterRecord, TypeError, inferProcedureInput, inferProcedureOutput, inferRouterRootTypes } from "@trpc/server/unstable-core-do-not-import";
|
|
@@ -13,6 +13,9 @@ type DecorateProcedure<TRoot extends AnyRootTypes, TProcedure extends AnyProcedu
|
|
|
13
13
|
type DecorateRouterRecord<TRoot extends AnyRootTypes, TRecord extends RouterRecord> = { [TKey in keyof TRecord]: TRecord[TKey] extends (infer $Value) ? $Value extends AnyProcedure ? DecorateProcedure<TRoot, $Value> : $Value extends RouterRecord ? DecorateRouterRecord<TRoot, $Value> : never : never; };
|
|
14
14
|
type Caller<TRouter extends AnyRouter> = ReturnType<RouterCaller<inferRouterRootTypes<TRouter>, TRouter['_def']['record']>>;
|
|
15
15
|
/**
|
|
16
|
+
* Creates a server-side caller that can also prefetch queries, plus a
|
|
17
|
+
* `HydrateClient` component that sends the prefetched data to the client.
|
|
18
|
+
*
|
|
16
19
|
* @note This requires `@tanstack/react-query@^5.49.0`
|
|
17
20
|
* @note Make sure to have `dehydrate.serializeData` and `hydrate.deserializeData`
|
|
18
21
|
* set to your data transformer in your `QueryClient` factory.
|
|
@@ -30,6 +33,11 @@ type Caller<TRouter extends AnyRouter> = ReturnType<RouterCaller<inferRouterRoot
|
|
|
30
33
|
* },
|
|
31
34
|
* });
|
|
32
35
|
* ```
|
|
36
|
+
*
|
|
37
|
+
* @deprecated `@trpc/react-query` only gets bug fixes and will be removed in
|
|
38
|
+
* the next major version. Use `@trpc/tanstack-react-query` instead.
|
|
39
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/migrating
|
|
40
|
+
* @see https://trpc.io/docs/client/react/server-components
|
|
33
41
|
*/
|
|
34
42
|
export declare function createHydrationHelpers<TRouter extends AnyRouter>(caller: AnyRouter extends TRouter ? TypeError<'Generic parameter missing in `createHydrationHelpers<HERE>`'> : Caller<TRouter>, getQueryClient: () => QueryClient): {
|
|
35
43
|
/***
|
package/dist/rsc.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rsc.d.mts","names":[],"sources":["../src/rsc.tsx"],"mappings":";;;;;;;KAiCK,kBACH,cAAc,cACd,mBAAmB;GAGjB,OAAO,oBAAoB,cAC1B,QAAQ,qBAAqB;EAChC,WACE,OAAO,oBAAoB,aAC3B,OAAO,sBACL,kCAAgC,OAAO,aACvC,gBAAgB,YAEf;EACL,mBACE,OAAO,oBAAoB,aAC3B,OAAO,8BACL,oBAAoB,aACpB,kCAAgC,OAAO,aACvC,gBAAgB,YAEf;;KAGF,qBACH,cAAc,cACd,gBAAgB,mBAEf,cAAc,UAAU,QAAQ,qBAAoB,UACjD,eAAe,eACb,kBAAkB,OAAO,UACzB,eAAe,eACb,qBAAqB,OAAO;KAKjC,OAAO,gBAAgB,aAAa,WACvC,aAAa,qBAAqB,UAAU
|
|
1
|
+
{"version":3,"file":"rsc.d.mts","names":[],"sources":["../src/rsc.tsx"],"mappings":";;;;;;;KAiCK,kBACH,cAAc,cACd,mBAAmB;GAGjB,OAAO,oBAAoB,cAC1B,QAAQ,qBAAqB;EAChC,WACE,OAAO,oBAAoB,aAC3B,OAAO,sBACL,kCAAgC,OAAO,aACvC,gBAAgB,YAEf;EACL,mBACE,OAAO,oBAAoB,aAC3B,OAAO,8BACL,oBAAoB,aACpB,kCAAgC,OAAO,aACvC,gBAAgB,YAEf;;KAGF,qBACH,cAAc,cACd,gBAAgB,mBAEf,cAAc,UAAU,QAAQ,qBAAoB,UACjD,eAAe,eACb,kBAAkB,OAAO,UACzB,eAAe,eACb,qBAAqB,OAAO;KAKjC,OAAO,gBAAgB,aAAa,WACvC,aAAa,qBAAqB,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA+B9B,uBAAuB,gBAAgB,WACrD,QAAQ,kBAAkB,UACtB,2EACA,OAAO,UACX,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+CQ,gBAAA;IAAE,UAAU,MAAM;QAAW,MAAA,IAAA"}
|
package/dist/rsc.mjs
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { a as _objectSpread2, i as getQueryKeyInternal } from "./getQueryKey-
|
|
1
|
+
import { a as _objectSpread2, i as getQueryKeyInternal } from "./getQueryKey-CWSorJjT.mjs";
|
|
2
2
|
import { HydrationBoundary, dehydrate } from "@tanstack/react-query";
|
|
3
3
|
import { createRecursiveProxy } from "@trpc/server/unstable-core-do-not-import";
|
|
4
4
|
import * as React from "react";
|
|
5
5
|
//#region src/rsc.tsx
|
|
6
6
|
const HELPERS = ["prefetch", "prefetchInfinite"];
|
|
7
7
|
/**
|
|
8
|
+
* Creates a server-side caller that can also prefetch queries, plus a
|
|
9
|
+
* `HydrateClient` component that sends the prefetched data to the client.
|
|
10
|
+
*
|
|
8
11
|
* @note This requires `@tanstack/react-query@^5.49.0`
|
|
9
12
|
* @note Make sure to have `dehydrate.serializeData` and `hydrate.deserializeData`
|
|
10
13
|
* set to your data transformer in your `QueryClient` factory.
|
|
@@ -22,6 +25,11 @@ const HELPERS = ["prefetch", "prefetchInfinite"];
|
|
|
22
25
|
* },
|
|
23
26
|
* });
|
|
24
27
|
* ```
|
|
28
|
+
*
|
|
29
|
+
* @deprecated `@trpc/react-query` only gets bug fixes and will be removed in
|
|
30
|
+
* the next major version. Use `@trpc/tanstack-react-query` instead.
|
|
31
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/migrating
|
|
32
|
+
* @see https://trpc.io/docs/client/react/server-components
|
|
25
33
|
*/
|
|
26
34
|
function createHydrationHelpers(caller, getQueryClient) {
|
|
27
35
|
const wrappedProxy = createRecursiveProxy(async (opts) => {
|
package/dist/rsc.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rsc.mjs","names":[],"sources":["../src/rsc.tsx"],"sourcesContent":["/// <reference types=\"react/canary\" />\n\nimport {\n dehydrate,\n HydrationBoundary,\n type QueryClient,\n} from '@tanstack/react-query';\nimport type { TRPCClientError } from '@trpc/client';\nimport type { inferTransformedProcedureOutput } from '@trpc/server';\nimport {\n createRecursiveProxy,\n type AnyRouter,\n type inferProcedureInput,\n type RouterRecord,\n} from '@trpc/server/unstable-core-do-not-import';\nimport type {\n AnyProcedure,\n AnyRootTypes,\n inferProcedureOutput,\n inferRouterRootTypes,\n Maybe,\n RouterCaller,\n TypeError,\n} from '@trpc/server/unstable-core-do-not-import';\nimport * as React from 'react';\nimport { getQueryKeyInternal } from './internals/getQueryKey';\nimport type {\n TRPCFetchInfiniteQueryOptions,\n TRPCFetchQueryOptions,\n} from './shared';\n\nconst HELPERS = ['prefetch', 'prefetchInfinite'];\n\ntype DecorateProcedure<\n TRoot extends AnyRootTypes,\n TProcedure extends AnyProcedure,\n> = {\n (\n input: inferProcedureInput<TProcedure>,\n ): Promise<inferProcedureOutput<TProcedure>>;\n prefetch: (\n input: inferProcedureInput<TProcedure>,\n opts?: TRPCFetchQueryOptions<\n inferTransformedProcedureOutput<TRoot, TProcedure>,\n TRPCClientError<TRoot>\n >,\n ) => Promise<void>;\n prefetchInfinite: (\n input: inferProcedureInput<TProcedure>,\n opts?: TRPCFetchInfiniteQueryOptions<\n inferProcedureInput<TProcedure>,\n inferTransformedProcedureOutput<TRoot, TProcedure>,\n TRPCClientError<TRoot>\n >,\n ) => Promise<void>;\n};\n\ntype DecorateRouterRecord<\n TRoot extends AnyRootTypes,\n TRecord extends RouterRecord,\n> = {\n [TKey in keyof TRecord]: TRecord[TKey] extends infer $Value\n ? $Value extends AnyProcedure\n ? DecorateProcedure<TRoot, $Value>\n : $Value extends RouterRecord\n ? DecorateRouterRecord<TRoot, $Value>\n : never\n : never;\n};\n\ntype Caller<TRouter extends AnyRouter> = ReturnType<\n RouterCaller<inferRouterRootTypes<TRouter>, TRouter['_def']['record']>\n>;\n\n// ts-prune-ignore-next\n/**\n * @note This requires `@tanstack/react-query@^5.49.0`\n * @note Make sure to have `dehydrate.serializeData` and `hydrate.deserializeData`\n * set to your data transformer in your `QueryClient` factory.\n * @example\n * ```ts\n * export const createQueryClient = () =>\n * new QueryClient({\n * defaultOptions: {\n * dehydrate: {\n * serializeData: transformer.serialize,\n * },\n * hydrate: {\n * deserializeData: transformer.deserialize,\n * },\n * },\n * });\n * ```\n */\nexport function createHydrationHelpers<TRouter extends AnyRouter>(\n caller: AnyRouter extends TRouter\n ? TypeError<'Generic parameter missing in `createHydrationHelpers<HERE>`'>\n : Caller<TRouter>,\n getQueryClient: () => QueryClient,\n) {\n type RootTypes = inferRouterRootTypes<TRouter>;\n\n const wrappedProxy = createRecursiveProxy<\n DecorateRouterRecord<RootTypes, TRouter['_def']['record']>\n >(async (opts) => {\n const path = [...opts.path];\n const args = [...opts.args];\n const proc = path.reduce(\n (acc, key) =>\n // @ts-expect-error - ??\n HELPERS.includes(key) ? acc : acc[key],\n caller,\n ) as unknown as DecorateProcedure<RootTypes, AnyProcedure>;\n\n const input = args[0];\n const promise = proc(input);\n\n const helper = path.pop();\n if (helper === 'prefetch') {\n const args1 = args[1] as Maybe<\n TRPCFetchInfiniteQueryOptions<any, any, any>\n >;\n\n return getQueryClient().prefetchQuery({\n ...args1,\n queryKey: getQueryKeyInternal(path, input, 'query'),\n queryFn: () => promise,\n });\n }\n if (helper === 'prefetchInfinite') {\n const args1 = args[1] as Maybe<\n TRPCFetchInfiniteQueryOptions<any, any, any>\n >;\n\n return getQueryClient().prefetchInfiniteQuery({\n ...args1,\n queryKey: getQueryKeyInternal(path, input, 'infinite'),\n queryFn: () => promise,\n initialPageParam: args1?.initialCursor ?? null,\n });\n }\n\n return promise;\n });\n\n function HydrateClient(props: { children: React.ReactNode }) {\n const dehydratedState = dehydrate(getQueryClient());\n\n return (\n <HydrationBoundary state={dehydratedState}>\n {props.children}\n </HydrationBoundary>\n );\n }\n\n return {\n /***\n * Wrapped caller with prefetch helpers\n * Can be used as a regular [server-side caller](https://trpc.io/docs/server/server-side-calls)\n * or using prefetch helpers to put the promise into the QueryClient cache\n * @example\n * ```ts\n * const data = await trpc.post.get(\"postId\");\n *\n * // or\n * void trpc.post.get.prefetch(\"postId\");\n * ```\n */\n trpc: wrappedProxy,\n /**\n * HoC to hydrate the query client for a client component\n * to pick up the prefetched promise and skip an initial\n * client-side fetch.\n * @example\n * ```tsx\n * // MyRSC.tsx\n * const MyRSC = ({ params }) => {\n * void trpc.post.get.prefetch(params.postId);\n *\n * return (\n * <HydrateClient>\n * <MyCC postId={params.postId} />\n * </HydrateClient>\n * );\n * };\n *\n * // MyCC.tsx\n * \"use client\"\n * const MyCC = ({ postId }) => {\n * const { data: post } = trpc.post.get.useQuery(postId);\n * return <div>{post.title}</div>;\n * };\n * ```\n */\n HydrateClient,\n };\n}\n"],"mappings":";;;;;AA+BA,MAAM,UAAU,CAAC,YAAY,kBAAkB
|
|
1
|
+
{"version":3,"file":"rsc.mjs","names":[],"sources":["../src/rsc.tsx"],"sourcesContent":["/// <reference types=\"react/canary\" />\n\nimport {\n dehydrate,\n HydrationBoundary,\n type QueryClient,\n} from '@tanstack/react-query';\nimport type { TRPCClientError } from '@trpc/client';\nimport type { inferTransformedProcedureOutput } from '@trpc/server';\nimport {\n createRecursiveProxy,\n type AnyRouter,\n type inferProcedureInput,\n type RouterRecord,\n} from '@trpc/server/unstable-core-do-not-import';\nimport type {\n AnyProcedure,\n AnyRootTypes,\n inferProcedureOutput,\n inferRouterRootTypes,\n Maybe,\n RouterCaller,\n TypeError,\n} from '@trpc/server/unstable-core-do-not-import';\nimport * as React from 'react';\nimport { getQueryKeyInternal } from './internals/getQueryKey';\nimport type {\n TRPCFetchInfiniteQueryOptions,\n TRPCFetchQueryOptions,\n} from './shared';\n\nconst HELPERS = ['prefetch', 'prefetchInfinite'];\n\ntype DecorateProcedure<\n TRoot extends AnyRootTypes,\n TProcedure extends AnyProcedure,\n> = {\n (\n input: inferProcedureInput<TProcedure>,\n ): Promise<inferProcedureOutput<TProcedure>>;\n prefetch: (\n input: inferProcedureInput<TProcedure>,\n opts?: TRPCFetchQueryOptions<\n inferTransformedProcedureOutput<TRoot, TProcedure>,\n TRPCClientError<TRoot>\n >,\n ) => Promise<void>;\n prefetchInfinite: (\n input: inferProcedureInput<TProcedure>,\n opts?: TRPCFetchInfiniteQueryOptions<\n inferProcedureInput<TProcedure>,\n inferTransformedProcedureOutput<TRoot, TProcedure>,\n TRPCClientError<TRoot>\n >,\n ) => Promise<void>;\n};\n\ntype DecorateRouterRecord<\n TRoot extends AnyRootTypes,\n TRecord extends RouterRecord,\n> = {\n [TKey in keyof TRecord]: TRecord[TKey] extends infer $Value\n ? $Value extends AnyProcedure\n ? DecorateProcedure<TRoot, $Value>\n : $Value extends RouterRecord\n ? DecorateRouterRecord<TRoot, $Value>\n : never\n : never;\n};\n\ntype Caller<TRouter extends AnyRouter> = ReturnType<\n RouterCaller<inferRouterRootTypes<TRouter>, TRouter['_def']['record']>\n>;\n\n// ts-prune-ignore-next\n/**\n * Creates a server-side caller that can also prefetch queries, plus a\n * `HydrateClient` component that sends the prefetched data to the client.\n *\n * @note This requires `@tanstack/react-query@^5.49.0`\n * @note Make sure to have `dehydrate.serializeData` and `hydrate.deserializeData`\n * set to your data transformer in your `QueryClient` factory.\n * @example\n * ```ts\n * export const createQueryClient = () =>\n * new QueryClient({\n * defaultOptions: {\n * dehydrate: {\n * serializeData: transformer.serialize,\n * },\n * hydrate: {\n * deserializeData: transformer.deserialize,\n * },\n * },\n * });\n * ```\n *\n * @deprecated `@trpc/react-query` only gets bug fixes and will be removed in\n * the next major version. Use `@trpc/tanstack-react-query` instead.\n * @see https://trpc.io/docs/client/tanstack-react-query/migrating\n * @see https://trpc.io/docs/client/react/server-components\n */\nexport function createHydrationHelpers<TRouter extends AnyRouter>(\n caller: AnyRouter extends TRouter\n ? TypeError<'Generic parameter missing in `createHydrationHelpers<HERE>`'>\n : Caller<TRouter>,\n getQueryClient: () => QueryClient,\n) {\n type RootTypes = inferRouterRootTypes<TRouter>;\n\n const wrappedProxy = createRecursiveProxy<\n DecorateRouterRecord<RootTypes, TRouter['_def']['record']>\n >(async (opts) => {\n const path = [...opts.path];\n const args = [...opts.args];\n const proc = path.reduce(\n (acc, key) =>\n // @ts-expect-error - ??\n HELPERS.includes(key) ? acc : acc[key],\n caller,\n ) as unknown as DecorateProcedure<RootTypes, AnyProcedure>;\n\n const input = args[0];\n const promise = proc(input);\n\n const helper = path.pop();\n if (helper === 'prefetch') {\n const args1 = args[1] as Maybe<\n TRPCFetchInfiniteQueryOptions<any, any, any>\n >;\n\n return getQueryClient().prefetchQuery({\n ...args1,\n queryKey: getQueryKeyInternal(path, input, 'query'),\n queryFn: () => promise,\n });\n }\n if (helper === 'prefetchInfinite') {\n const args1 = args[1] as Maybe<\n TRPCFetchInfiniteQueryOptions<any, any, any>\n >;\n\n return getQueryClient().prefetchInfiniteQuery({\n ...args1,\n queryKey: getQueryKeyInternal(path, input, 'infinite'),\n queryFn: () => promise,\n initialPageParam: args1?.initialCursor ?? null,\n });\n }\n\n return promise;\n });\n\n function HydrateClient(props: { children: React.ReactNode }) {\n const dehydratedState = dehydrate(getQueryClient());\n\n return (\n <HydrationBoundary state={dehydratedState}>\n {props.children}\n </HydrationBoundary>\n );\n }\n\n return {\n /***\n * Wrapped caller with prefetch helpers\n * Can be used as a regular [server-side caller](https://trpc.io/docs/server/server-side-calls)\n * or using prefetch helpers to put the promise into the QueryClient cache\n * @example\n * ```ts\n * const data = await trpc.post.get(\"postId\");\n *\n * // or\n * void trpc.post.get.prefetch(\"postId\");\n * ```\n */\n trpc: wrappedProxy,\n /**\n * HoC to hydrate the query client for a client component\n * to pick up the prefetched promise and skip an initial\n * client-side fetch.\n * @example\n * ```tsx\n * // MyRSC.tsx\n * const MyRSC = ({ params }) => {\n * void trpc.post.get.prefetch(params.postId);\n *\n * return (\n * <HydrateClient>\n * <MyCC postId={params.postId} />\n * </HydrateClient>\n * );\n * };\n *\n * // MyCC.tsx\n * \"use client\"\n * const MyCC = ({ postId }) => {\n * const { data: post } = trpc.post.get.useQuery(postId);\n * return <div>{post.title}</div>;\n * };\n * ```\n */\n HydrateClient,\n };\n}\n"],"mappings":";;;;;AA+BA,MAAM,UAAU,CAAC,YAAY,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuE/C,SAAgB,uBACd,QAGA,gBACA;CAGA,MAAM,eAAe,qBAEnB,OAAO,SAAS;EAChB,MAAM,OAAO,CAAC,GAAG,KAAK,IAAI;EAC1B,MAAM,OAAO,CAAC,GAAG,KAAK,IAAI;EAC1B,MAAM,OAAO,KAAK,QACf,KAAK,QAEJ,QAAQ,SAAS,GAAG,IAAI,MAAM,IAAI,MACpC,MACF;EAEA,MAAM,QAAQ,KAAK;EACnB,MAAM,UAAU,KAAK,KAAK;EAE1B,MAAM,SAAS,KAAK,IAAI;EACxB,IAAI,WAAW,YAAY;GACzB,MAAM,QAAQ,KAAK;GAInB,OAAO,eAAe,CAAC,CAAC,cAAA,eAAA,eAAA,CAAA,GACnB,KAAA,GAAA,CAAA,GAAA;IACH,UAAU,oBAAoB,MAAM,OAAO,OAAO;IAClD,eAAe;GACjB,CAAA,CAAC;EACH;EACA,IAAI,WAAW,oBAAoB;;GACjC,MAAM,QAAQ,KAAK;GAInB,OAAO,eAAe,CAAC,CAAC,sBAAA,eAAA,eAAA,CAAA,GACnB,KAAA,GAAA,CAAA,GAAA;IACH,UAAU,oBAAoB,MAAM,OAAO,UAAU;IACrD,eAAe;IACf,mBAAA,uBAAA,UAAA,QAAA,UAAA,KAAA,IAAA,KAAA,IAAkB,MAAO,mBAAA,QAAA,yBAAA,KAAA,IAAA,uBAAiB;GAC5C,CAAA,CAAC;EACH;EAEA,OAAO;CACT,CAAC;CAED,SAAS,cAAc,OAAsC;EAC3D,MAAM,kBAAkB,UAAU,eAAe,CAAC;EAElD,OACE,sBAAA,cAAC,mBAAD,EAAmB,OAAO,gBAEP,GADhB,MAAM,QACU;CAEvB;CAEA,OAAO;;;;;;;;;;;;;EAaL,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;EA0BN;CACF;AACF"}
|
package/dist/server/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_getQueryKey = require("../getQueryKey-
|
|
3
|
-
const require_shared = require("../shared-
|
|
2
|
+
const require_getQueryKey = require("../getQueryKey-DASF3nl1.cjs");
|
|
3
|
+
const require_shared = require("../shared-v3jJm-s7.cjs");
|
|
4
4
|
let _trpc_client = require("@trpc/client");
|
|
5
5
|
let _tanstack_react_query = require("@tanstack/react-query");
|
|
6
6
|
let _trpc_server_unstable_core_do_not_import = require("@trpc/server/unstable-core-do-not-import");
|
|
@@ -8,8 +8,13 @@ let _trpc_client_unstable_internals = require("@trpc/client/unstable-internals")
|
|
|
8
8
|
//#region src/server/ssgProxy.ts
|
|
9
9
|
const _excluded = ["promise"];
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
11
|
+
* Creates helpers that fetch or prefetch queries on the server, for
|
|
12
|
+
* server-side rendering and static generation.
|
|
13
|
+
*
|
|
14
|
+
* @deprecated `@trpc/react-query` only gets bug fixes and will be removed in
|
|
15
|
+
* the next major version. Use `@trpc/tanstack-react-query` instead.
|
|
16
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/migrating
|
|
17
|
+
* @see https://trpc.io/docs/client/nextjs/pages-router/server-side-helpers
|
|
13
18
|
*/
|
|
14
19
|
function createServerSideHelpers(opts) {
|
|
15
20
|
const queryClient = require_shared.getQueryClient(opts);
|
|
@@ -64,6 +69,18 @@ function createServerSideHelpers(opts) {
|
|
|
64
69
|
path: arrayPath.join("."),
|
|
65
70
|
input
|
|
66
71
|
});
|
|
72
|
+
const infiniteQueryFn = ({ pageParam, direction }) => {
|
|
73
|
+
var _args$;
|
|
74
|
+
const initialCursor = (_args$ = args[1]) === null || _args$ === void 0 ? void 0 : _args$.initialCursor;
|
|
75
|
+
const [path, infiniteInput] = require_shared.getClientArgs([arrayPath, { input }], void 0, {
|
|
76
|
+
pageParam: pageParam !== null && pageParam !== void 0 ? pageParam : initialCursor,
|
|
77
|
+
direction
|
|
78
|
+
});
|
|
79
|
+
return resolvedOpts.query({
|
|
80
|
+
path,
|
|
81
|
+
input: infiniteInput
|
|
82
|
+
});
|
|
83
|
+
};
|
|
67
84
|
const queryKey = require_getQueryKey.getQueryKeyInternal(arrayPath, input, require_shared.getQueryType(utilName));
|
|
68
85
|
return {
|
|
69
86
|
queryOptions: () => {
|
|
@@ -74,10 +91,12 @@ function createServerSideHelpers(opts) {
|
|
|
74
91
|
});
|
|
75
92
|
},
|
|
76
93
|
infiniteQueryOptions: () => {
|
|
94
|
+
var _args1$initialCursor;
|
|
77
95
|
const args1 = args[1];
|
|
78
96
|
return require_getQueryKey._objectSpread2(require_getQueryKey._objectSpread2({}, args1), {}, {
|
|
79
97
|
queryKey,
|
|
80
|
-
queryFn
|
|
98
|
+
queryFn: infiniteQueryFn,
|
|
99
|
+
initialPageParam: (_args1$initialCursor = args1 === null || args1 === void 0 ? void 0 : args1.initialCursor) !== null && _args1$initialCursor !== void 0 ? _args1$initialCursor : null
|
|
81
100
|
});
|
|
82
101
|
},
|
|
83
102
|
fetch: () => {
|
|
@@ -88,12 +107,12 @@ function createServerSideHelpers(opts) {
|
|
|
88
107
|
}));
|
|
89
108
|
},
|
|
90
109
|
fetchInfinite: () => {
|
|
91
|
-
var _args1$
|
|
110
|
+
var _args1$initialCursor2;
|
|
92
111
|
const args1 = args[1];
|
|
93
112
|
return queryClient.fetchInfiniteQuery(require_getQueryKey._objectSpread2(require_getQueryKey._objectSpread2({}, args1), {}, {
|
|
94
113
|
queryKey,
|
|
95
|
-
queryFn,
|
|
96
|
-
initialPageParam: (_args1$
|
|
114
|
+
queryFn: infiniteQueryFn,
|
|
115
|
+
initialPageParam: (_args1$initialCursor2 = args1 === null || args1 === void 0 ? void 0 : args1.initialCursor) !== null && _args1$initialCursor2 !== void 0 ? _args1$initialCursor2 : null
|
|
97
116
|
}));
|
|
98
117
|
},
|
|
99
118
|
prefetch: () => {
|
|
@@ -104,12 +123,12 @@ function createServerSideHelpers(opts) {
|
|
|
104
123
|
}));
|
|
105
124
|
},
|
|
106
125
|
prefetchInfinite: () => {
|
|
107
|
-
var _args1$
|
|
126
|
+
var _args1$initialCursor3;
|
|
108
127
|
const args1 = args[1];
|
|
109
128
|
return queryClient.prefetchInfiniteQuery(require_getQueryKey._objectSpread2(require_getQueryKey._objectSpread2({}, args1), {}, {
|
|
110
129
|
queryKey,
|
|
111
|
-
queryFn,
|
|
112
|
-
initialPageParam: (_args1$
|
|
130
|
+
queryFn: infiniteQueryFn,
|
|
131
|
+
initialPageParam: (_args1$initialCursor3 = args1 === null || args1 === void 0 ? void 0 : args1.initialCursor) !== null && _args1$initialCursor3 !== void 0 ? _args1$initialCursor3 : null
|
|
113
132
|
}));
|
|
114
133
|
}
|
|
115
134
|
}[utilName]();
|
package/dist/server/index.d.cts
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
|
-
import { D as DecorateQueryProcedure, b as CreateTRPCReactQueryClientConfig } from "../getQueryKey-
|
|
1
|
+
import { D as DecorateQueryProcedure, b as CreateTRPCReactQueryClientConfig } from "../getQueryKey-CSENlbGR.cjs";
|
|
2
2
|
import { TRPCClient, TRPCUntypedClient } from "@trpc/client";
|
|
3
3
|
import { AnyQueryProcedure, AnyRootTypes, AnyRouter, ProtectedIntersection, RouterRecord, inferClientTypes, inferRouterContext } from "@trpc/server/unstable-core-do-not-import";
|
|
4
4
|
import { DehydrateOptions, DehydratedState, QueryClient } from "@tanstack/react-query";
|
|
5
5
|
import { TransformerOptions } from "@trpc/client/unstable-internals";
|
|
6
6
|
//#region src/server/ssgProxy.d.ts
|
|
7
7
|
type CreateSSGHelpersInternal<TRouter extends AnyRouter> = {
|
|
8
|
+
/**
|
|
9
|
+
* Call this router directly, without HTTP.
|
|
10
|
+
*/
|
|
8
11
|
router: TRouter;
|
|
12
|
+
/**
|
|
13
|
+
* The context to call procedures with.
|
|
14
|
+
*/
|
|
9
15
|
ctx: inferRouterContext<TRouter>;
|
|
10
16
|
} & TransformerOptions<inferClientTypes<TRouter>>;
|
|
11
17
|
interface CreateSSGHelpersExternal<TRouter extends AnyRouter> {
|
|
18
|
+
/**
|
|
19
|
+
* Call procedures through this tRPC client.
|
|
20
|
+
*/
|
|
12
21
|
client: TRPCClient<TRouter> | TRPCUntypedClient<TRouter>;
|
|
13
22
|
}
|
|
14
23
|
type CreateServerSideHelpersOptions<TRouter extends AnyRouter> = CreateTRPCReactQueryClientConfig & (CreateSSGHelpersExternal<TRouter> | CreateSSGHelpersInternal<TRouter>);
|
|
@@ -18,8 +27,13 @@ type SSGFns = 'queryOptions' | 'infiniteQueryOptions' | 'fetch' | 'fetchInfinite
|
|
|
18
27
|
*/
|
|
19
28
|
type DecoratedProcedureSSGRecord<TRoot extends AnyRootTypes, TRecord extends RouterRecord> = { [TKey in keyof TRecord]: TRecord[TKey] extends (infer $Value) ? $Value extends AnyQueryProcedure ? Pick<DecorateQueryProcedure<TRoot, $Value>, SSGFns> : $Value extends RouterRecord ? DecoratedProcedureSSGRecord<TRoot, $Value> : never : never; };
|
|
20
29
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
30
|
+
* Creates helpers that fetch or prefetch queries on the server, for
|
|
31
|
+
* server-side rendering and static generation.
|
|
32
|
+
*
|
|
33
|
+
* @deprecated `@trpc/react-query` only gets bug fixes and will be removed in
|
|
34
|
+
* the next major version. Use `@trpc/tanstack-react-query` instead.
|
|
35
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/migrating
|
|
36
|
+
* @see https://trpc.io/docs/client/nextjs/pages-router/server-side-helpers
|
|
23
37
|
*/
|
|
24
38
|
export declare function createServerSideHelpers<TRouter extends AnyRouter>(opts: CreateServerSideHelpersOptions<TRouter>): ProtectedIntersection<{
|
|
25
39
|
queryClient: QueryClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/server/ssgProxy.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/server/ssgProxy.ts"],"mappings":";;;;;;KAyCK,yBAAyB,gBAAgB;;;;EAI5C,QAAQ;;;;EAIR,KAAK,mBAAmB;IACtB,mBAAmB,iBAAiB;UAE9B,yBAAyB,gBAAgB;;;;EAIjD,QAAQ,WAAW,WAAW,kBAAkB;;KAG7C,+BAA+B,gBAAgB,aAClD,oCACG,yBAAyB,WAAW,yBAAyB;KAE7D;;;;KAWA,4BACH,cAAc,cACd,gBAAgB,mBAEf,cAAc,UAAU,QAAQ,qBAAoB,UACjD,eAAe,oBACb,KAAK,uBAAuB,OAAO,SAAS,UAC5C,eAAe,eACb,4BAA4B,OAAO;;;;;;;;;;wBAgB7B,wBAAwB,gBAAgB,WACtD,MAAM,+BAA+B,WAAQ;EAuE5B,aAAA;EACF,YAAC,OAAO,qBAAqB;GAyF7C,4BAAA,sCAAA"}
|