@trpc/react-query 11.23.1-canary.3.ae3beada3 → 11.23.1-canary.30.70e1d688c
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-B3wY6Hsc.d.mts} +278 -23
- package/dist/getQueryKey-B3wY6Hsc.d.mts.map +1 -0
- package/dist/{getQueryKey-D3tJ34z0.mjs → getQueryKey-CWSorJjT.mjs} +25 -9
- package/dist/getQueryKey-CWSorJjT.mjs.map +1 -0
- package/dist/{getQueryKey-CMt5tN9-.d.mts → getQueryKey-CkLbRjaS.d.cts} +278 -23
- package/dist/getQueryKey-CkLbRjaS.d.cts.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 +11 -3
- package/dist/rsc.d.cts +11 -3
- package/dist/rsc.d.cts.map +1 -1
- package/dist/rsc.d.mts +11 -3
- package/dist/rsc.d.mts.map +1 -1
- package/dist/rsc.mjs +11 -3
- 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/internals/useQueries.ts +77 -29
- package/src/rsc.tsx +10 -2
- package/src/server/ssgProxy.ts +41 -5
- package/src/shared/hooks/createHooksInternal.tsx +28 -2
- 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
|
@@ -106,11 +106,22 @@ function getMutationKeyInternal(path) {
|
|
|
106
106
|
return getQueryKeyInternal(path, void 0, "any");
|
|
107
107
|
}
|
|
108
108
|
/**
|
|
109
|
-
*
|
|
110
|
-
* @param procedureOrRouter - procedure or
|
|
111
|
-
* @param input - input to
|
|
112
|
-
*
|
|
113
|
-
* @
|
|
109
|
+
* Returns the TanStack Query key for a procedure or router.
|
|
110
|
+
* @param procedureOrRouter - a procedure or router from `createTRPCReact`
|
|
111
|
+
* @param input - the procedure input. Leave it out to match every input in
|
|
112
|
+
* fuzzy operations like `invalidateQueries`.
|
|
113
|
+
* @param type - `'query'`, `'infinite'` or `'any'` (default). `'any'` leaves
|
|
114
|
+
* the type out of the key, so exact reads like `getQueryData` need the same
|
|
115
|
+
* input the query used and the matching type. Infinite query keys leave out
|
|
116
|
+
* `cursor` and `direction`.
|
|
117
|
+
*
|
|
118
|
+
* @deprecated `@trpc/react-query` only gets bug fixes and will be removed in
|
|
119
|
+
* the next major version. Use `@trpc/tanstack-react-query` instead, where
|
|
120
|
+
* each query procedure has a `queryKey()` method and each router has a
|
|
121
|
+
* `pathKey()` method.
|
|
122
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/migrating
|
|
123
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/usage#queryKey
|
|
124
|
+
* @see https://trpc.io/docs/client/react/getQueryKey
|
|
114
125
|
*/
|
|
115
126
|
function getQueryKey(procedureOrRouter, ..._params) {
|
|
116
127
|
const [input, type] = _params;
|
|
@@ -118,9 +129,14 @@ function getQueryKey(procedureOrRouter, ..._params) {
|
|
|
118
129
|
return getQueryKeyInternal(path, input, type !== null && type !== void 0 ? type : "any");
|
|
119
130
|
}
|
|
120
131
|
/**
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
* @
|
|
132
|
+
* Returns the TanStack Query mutation key for a procedure.
|
|
133
|
+
*
|
|
134
|
+
* @deprecated `@trpc/react-query` only gets bug fixes and will be removed in
|
|
135
|
+
* the next major version. Use `@trpc/tanstack-react-query` instead, where
|
|
136
|
+
* each mutation has a `mutationKey()` method.
|
|
137
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/migrating
|
|
138
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/usage#mutationKey
|
|
139
|
+
* @see https://trpc.io/docs/client/react/getQueryKey#mutations
|
|
124
140
|
*/
|
|
125
141
|
function getMutationKey(procedure) {
|
|
126
142
|
const path = procedure._def().path;
|
|
@@ -129,4 +145,4 @@ function getMutationKey(procedure) {
|
|
|
129
145
|
//#endregion
|
|
130
146
|
export { _objectSpread2 as a, getQueryKeyInternal as i, getMutationKeyInternal as n, _objectWithoutProperties as o, getQueryKey as r, getMutationKey as t };
|
|
131
147
|
|
|
132
|
-
//# sourceMappingURL=getQueryKey-
|
|
148
|
+
//# sourceMappingURL=getQueryKey-CWSorJjT.mjs.map
|
|
@@ -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"}
|