@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.
Files changed (53) hide show
  1. package/dist/{getQueryKey-BqoKYDMR.d.cts → getQueryKey-B3wY6Hsc.d.mts} +278 -23
  2. package/dist/getQueryKey-B3wY6Hsc.d.mts.map +1 -0
  3. package/dist/{getQueryKey-D3tJ34z0.mjs → getQueryKey-CWSorJjT.mjs} +25 -9
  4. package/dist/getQueryKey-CWSorJjT.mjs.map +1 -0
  5. package/dist/{getQueryKey-CMt5tN9-.d.mts → getQueryKey-CkLbRjaS.d.cts} +278 -23
  6. package/dist/getQueryKey-CkLbRjaS.d.cts.map +1 -0
  7. package/dist/{getQueryKey-Db_3VDGo.cjs → getQueryKey-DASF3nl1.cjs} +24 -8
  8. package/dist/index.cjs +24 -2
  9. package/dist/index.d.cts +10 -1
  10. package/dist/index.d.cts.map +1 -1
  11. package/dist/index.d.mts +10 -1
  12. package/dist/index.d.mts.map +1 -1
  13. package/dist/index.mjs +24 -2
  14. package/dist/index.mjs.map +1 -1
  15. package/dist/rsc.cjs +11 -3
  16. package/dist/rsc.d.cts +11 -3
  17. package/dist/rsc.d.cts.map +1 -1
  18. package/dist/rsc.d.mts +11 -3
  19. package/dist/rsc.d.mts.map +1 -1
  20. package/dist/rsc.mjs +11 -3
  21. package/dist/rsc.mjs.map +1 -1
  22. package/dist/server/index.cjs +30 -11
  23. package/dist/server/index.d.cts +17 -3
  24. package/dist/server/index.d.cts.map +1 -1
  25. package/dist/server/index.d.mts +17 -3
  26. package/dist/server/index.d.mts.map +1 -1
  27. package/dist/server/index.mjs +30 -11
  28. package/dist/server/index.mjs.map +1 -1
  29. package/dist/shared/index.cjs +1 -1
  30. package/dist/shared/index.d.cts +1 -1
  31. package/dist/shared/index.d.mts +1 -1
  32. package/dist/shared/index.mjs +1 -1
  33. package/dist/{shared-Bw5jcbcM.mjs → shared-DyU-Vz6d.mjs} +11 -2
  34. package/dist/shared-DyU-Vz6d.mjs.map +1 -0
  35. package/dist/{shared-ByAY3gMr.cjs → shared-v3jJm-s7.cjs} +10 -1
  36. package/package.json +6 -6
  37. package/src/createTRPCQueryUtils.tsx +9 -0
  38. package/src/createTRPCReact.tsx +40 -7
  39. package/src/internals/context.tsx +21 -0
  40. package/src/internals/getQueryKey.ts +24 -8
  41. package/src/internals/useQueries.ts +77 -29
  42. package/src/rsc.tsx +10 -2
  43. package/src/server/ssgProxy.ts +41 -5
  44. package/src/shared/hooks/createHooksInternal.tsx +28 -2
  45. package/src/shared/hooks/types.ts +93 -0
  46. package/src/shared/polymorphism/routerLike.ts +3 -0
  47. package/src/shared/proxy/utilsProxy.ts +15 -0
  48. package/src/shared/types.ts +50 -2
  49. package/src/utils/inferReactQueryProcedure.ts +8 -0
  50. package/dist/getQueryKey-BqoKYDMR.d.cts.map +0 -1
  51. package/dist/getQueryKey-CMt5tN9-.d.mts.map +0 -1
  52. package/dist/getQueryKey-D3tJ34z0.mjs.map +0 -1
  53. 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
- * Method to extract the query key for a procedure
110
- * @param procedureOrRouter - procedure or AnyRouter
111
- * @param input - input to procedureOrRouter
112
- * @param type - defaults to `any`
113
- * @see https://trpc.io/docs/v11/getQueryKey
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
- * Method to extract the mutation key for a procedure
122
- * @param procedure - procedure
123
- * @see https://trpc.io/docs/v11/getQueryKey#mutations
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-D3tJ34z0.mjs.map
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"}