@srpc.org/react-query 0.20.3 → 0.20.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # @srpc/react-query
1
+ # @srpc.org/react-query
2
2
 
3
3
  React Query integration for SRPC - Type-safe RPC with automatic React Query hooks and query/mutation options generation.
4
4
 
@@ -6,11 +6,11 @@ React Query integration for SRPC - Type-safe RPC with automatic React Query hook
6
6
 
7
7
  ```bash
8
8
  # Using JSR (recommended)
9
- deno add @srpc/react-query
10
- npx jsr add @srpc/react-query
11
- yarn dlx jsr add @srpc/react-query
12
- pnpm dlx jsr add @srpc/react-query
13
- bunx jsr add @srpc/react-query
9
+ deno add @srpc.org/react-query
10
+ npx jsr add @srpc.org/react-query
11
+ yarn dlx jsr add @srpc.org/react-query
12
+ pnpm dlx jsr add @srpc.org/react-query
13
+ bunx jsr add @srpc.org/react-query
14
14
  ```
15
15
 
16
16
  ## Features
@@ -25,7 +25,7 @@ bunx jsr add @srpc/react-query
25
25
  ## Prerequisites
26
26
 
27
27
  This package requires:
28
- - `@srpc/core` - The core SRPC framework
28
+ - `@srpc.org/core` - The core SRPC framework
29
29
  - `@tanstack/react-query` v5.90 or higher
30
30
  - `react` v19 or higher
31
31
 
@@ -35,7 +35,7 @@ This package requires:
35
35
 
36
36
  ```typescript
37
37
  // server/router.ts
38
- import { initSRPC } from "@srpc/core/server";
38
+ import { initSRPC } from "@srpc.org/core/server";
39
39
 
40
40
  const s = initSRPC();
41
41
 
@@ -60,7 +60,7 @@ export type AppRouter = typeof appRouter;
60
60
 
61
61
  ```typescript
62
62
  // lib/rpc.ts
63
- import { createSRPCClient } from "@srpc/core/client";
63
+ import { createSRPCClient } from "@srpc.org/core/client";
64
64
  import { createSRPCContext } from "@srpc.org/react-query";
65
65
  import type { AppRouter } from "../server/router";
66
66
 
@@ -229,7 +229,7 @@ const postQuery = useQuery(srpc.posts.drafts.list.queryOptions());
229
229
  If you prefer not to use React Context:
230
230
 
231
231
  ```typescript
232
- import { createSRPCClient } from "@srpc/core/client";
232
+ import { createSRPCClient } from "@srpc.org/core/client";
233
233
  import { createSRPCQueryOptions } from "@srpc.org/react-query";
234
234
  import { useQuery } from "@tanstack/react-query";
235
235
  import type { AppRouter } from "./server/router";
@@ -254,7 +254,7 @@ function MyComponent() {
254
254
  ### Custom Serialization
255
255
 
256
256
  ```typescript
257
- import { createSRPCClient } from "@srpc/core/client";
257
+ import { createSRPCClient } from "@srpc.org/core/client";
258
258
  import { createSRPCContext } from "@srpc.org/react-query";
259
259
  import superjson from "superjson";
260
260
 
package/dist/context.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { SRPC, AnySRPC } from '@srpc/core/server';
2
- import { AnyRoutes, AnyProcedure, ClientProcedure, DecoratedProcedureRecord } from '@srpc/core/shared';
1
+ import { SRPC, AnySRPC } from '@srpc.org/core/server';
2
+ import { AnyRoutes, AnyProcedure, ClientProcedure, DecoratedProcedureRecord } from '@srpc.org/core/shared';
3
3
  import React, { PropsWithChildren } from 'react';
4
4
  import { UseQueryOptions, UseMutationOptions } from '@tanstack/react-query';
5
5
 
@@ -14,7 +14,7 @@ import { UseQueryOptions, UseMutationOptions } from '@tanstack/react-query';
14
14
  *
15
15
  * @example Basic usage
16
16
  * ```typescript
17
- * import { createSRPCClient } from "@srpc/core/client";
17
+ * import { createSRPCClient } from "@srpc.org/core/client";
18
18
  * import { createSRPCQueryOptions } from "@srpc.org/react-query";
19
19
  * import { useQuery } from "@tanstack/react-query";
20
20
  * import type { AppRouter } from "./server";
@@ -85,6 +85,8 @@ import { UseQueryOptions, UseMutationOptions } from '@tanstack/react-query';
85
85
  type OptionsFactory<Procedure extends ClientProcedure<any>, TInput = Parameters<Procedure>, TOutput = ReturnType<Procedure>> = {
86
86
  queryOptions: (...args: Parameters<Procedure>) => UseQueryOptions<TOutput>;
87
87
  mutationOptions: () => UseMutationOptions<TOutput, Error, TInput>;
88
+ queryKey: (...args: Parameters<Procedure>) => string[];
89
+ mutationKey: () => string[];
88
90
  };
89
91
  /**
90
92
  * Type that recursively transforms an SRPC router into a structure with React Query options.
@@ -135,8 +137,8 @@ type DecoratedQueryProcedureRecord<TRouter extends AnyRoutes> = {
135
137
  *
136
138
  * @example Complete setup
137
139
  * ```typescript
138
- * import { createSRPCClient } from "@srpc/core/client";
139
- * import { createSRPCContext } from "@srpc/react-query/context";
140
+ * import { createSRPCClient } from "@srpc.org/core/client";
141
+ * import { createSRPCContext } from "@srpc.org/react-query/context";
140
142
  * import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
141
143
  * import type { AppRouter } from "./server";
142
144
  *
@@ -237,7 +239,7 @@ type SRPCContextFactory<TRouter extends AnySRPC> = {
237
239
  *
238
240
  * @example Basic setup
239
241
  * ```typescript
240
- * import { createSRPCClient } from "@srpc/core/client";
242
+ * import { createSRPCClient } from "@srpc.org/core/client";
241
243
  * import { createSRPCContext } from "@srpc.org/react-query";
242
244
  * import type { AppRouter } from "./server";
243
245
  *
package/dist/context.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
  import { jsx } from 'react/jsx-runtime';
3
3
  import { createContext, useContext, useMemo } from 'react';
4
- import { createRecursiveProxy } from '@srpc/core/shared';
4
+ import { createRecursiveProxy } from '@srpc.org/core/shared';
5
5
  import { queryOptions, mutationOptions } from '@tanstack/react-query';
6
6
 
7
7
  /**
@@ -26,7 +26,7 @@ import { queryOptions, mutationOptions } from '@tanstack/react-query';
26
26
  *
27
27
  * @example Basic usage
28
28
  * ```typescript
29
- * import { createSRPCClient } from "@srpc/core/client";
29
+ * import { createSRPCClient } from "@srpc.org/core/client";
30
30
  * import { createSRPCQueryOptions } from "@srpc.org/react-query";
31
31
  * import { useQuery, useMutation } from "@tanstack/react-query";
32
32
  * import type { AppRouter } from "./server";
@@ -81,6 +81,12 @@ import { queryOptions, mutationOptions } from '@tanstack/react-query';
81
81
  return createRecursiveProxy(({ path, args })=>{
82
82
  const lastPath = path[path.length - 1];
83
83
  const pathWithoutTarget = path.slice(0, -1);
84
+ if (lastPath === "queryKey" || lastPath === "mutationKey") {
85
+ return [
86
+ ...pathWithoutTarget,
87
+ args
88
+ ];
89
+ }
84
90
  const procedure = pathWithoutTarget.reduce((acc, key)=>acc[key], client);
85
91
  if (typeof procedure !== "function") {
86
92
  throw new Error(`Procedure at path ${pathWithoutTarget.join(".")} is not a function`);
@@ -118,8 +124,8 @@ import { queryOptions, mutationOptions } from '@tanstack/react-query';
118
124
  *
119
125
  * @example Complete setup
120
126
  * ```typescript
121
- * import { createSRPCClient } from "@srpc/core/client";
122
- * import { createSRPCContext } from "@srpc/react-query/context";
127
+ * import { createSRPCClient } from "@srpc.org/core/client";
128
+ * import { createSRPCContext } from "@srpc.org/react-query/context";
123
129
  * import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
124
130
  * import type { AppRouter } from "./server";
125
131
  *
@@ -168,7 +174,7 @@ import { queryOptions, mutationOptions } from '@tanstack/react-query';
168
174
  *
169
175
  * @example Basic setup
170
176
  * ```typescript
171
- * import { createSRPCClient } from "@srpc/core/client";
177
+ * import { createSRPCClient } from "@srpc.org/core/client";
172
178
  * import { createSRPCContext } from "@srpc.org/react-query";
173
179
  * import type { AppRouter } from "./server";
174
180
  *
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { SRPC, AnySRPC } from '@srpc/core/server';
2
- import { ClientProcedure, AnyRoutes, AnyProcedure, DecoratedProcedureRecord } from '@srpc/core/shared';
1
+ import { SRPC, AnySRPC } from '@srpc.org/core/server';
2
+ import { ClientProcedure, AnyRoutes, AnyProcedure, DecoratedProcedureRecord } from '@srpc.org/core/shared';
3
3
  import { UseQueryOptions, UseMutationOptions } from '@tanstack/react-query';
4
4
  export { SRPCContextFactory, SRPCContextValue, createSRPCContext } from './context.js';
5
5
 
@@ -14,7 +14,7 @@ export { SRPCContextFactory, SRPCContextValue, createSRPCContext } from './conte
14
14
  *
15
15
  * @example Basic usage
16
16
  * ```typescript
17
- * import { createSRPCClient } from "@srpc/core/client";
17
+ * import { createSRPCClient } from "@srpc.org/core/client";
18
18
  * import { createSRPCQueryOptions } from "@srpc.org/react-query";
19
19
  * import { useQuery } from "@tanstack/react-query";
20
20
  * import type { AppRouter } from "./server";
@@ -85,6 +85,8 @@ export { SRPCContextFactory, SRPCContextValue, createSRPCContext } from './conte
85
85
  type OptionsFactory<Procedure extends ClientProcedure<any>, TInput = Parameters<Procedure>, TOutput = ReturnType<Procedure>> = {
86
86
  queryOptions: (...args: Parameters<Procedure>) => UseQueryOptions<TOutput>;
87
87
  mutationOptions: () => UseMutationOptions<TOutput, Error, TInput>;
88
+ queryKey: (...args: Parameters<Procedure>) => string[];
89
+ mutationKey: () => string[];
88
90
  };
89
91
  /**
90
92
  * Type that recursively transforms an SRPC router into a structure with React Query options.
@@ -145,7 +147,7 @@ type DecoratedQueryProcedureRecord<TRouter extends AnyRoutes> = {
145
147
  *
146
148
  * @example Basic usage
147
149
  * ```typescript
148
- * import { createSRPCClient } from "@srpc/core/client";
150
+ * import { createSRPCClient } from "@srpc.org/core/client";
149
151
  * import { createSRPCQueryOptions } from "@srpc.org/react-query";
150
152
  * import { useQuery, useMutation } from "@tanstack/react-query";
151
153
  * import type { AppRouter } from "./server";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createRecursiveProxy } from '@srpc/core/shared';
1
+ import { createRecursiveProxy } from '@srpc.org/core/shared';
2
2
  import { queryOptions, mutationOptions } from '@tanstack/react-query';
3
3
  export { createSRPCContext } from './context.js';
4
4
 
@@ -24,7 +24,7 @@ export { createSRPCContext } from './context.js';
24
24
  *
25
25
  * @example Basic usage
26
26
  * ```typescript
27
- * import { createSRPCClient } from "@srpc/core/client";
27
+ * import { createSRPCClient } from "@srpc.org/core/client";
28
28
  * import { createSRPCQueryOptions } from "@srpc.org/react-query";
29
29
  * import { useQuery, useMutation } from "@tanstack/react-query";
30
30
  * import type { AppRouter } from "./server";
@@ -79,6 +79,12 @@ export { createSRPCContext } from './context.js';
79
79
  return createRecursiveProxy(({ path, args })=>{
80
80
  const lastPath = path[path.length - 1];
81
81
  const pathWithoutTarget = path.slice(0, -1);
82
+ if (lastPath === "queryKey" || lastPath === "mutationKey") {
83
+ return [
84
+ ...pathWithoutTarget,
85
+ args
86
+ ];
87
+ }
82
88
  const procedure = pathWithoutTarget.reduce((acc, key)=>acc[key], client);
83
89
  if (typeof procedure !== "function") {
84
90
  throw new Error(`Procedure at path ${pathWithoutTarget.join(".")} is not a function`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@srpc.org/react-query",
3
- "version": "0.20.3",
3
+ "version": "0.20.5",
4
4
  "description": "React Query integration for SRPC - Type-safe RPC with automatic React Query hooks",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -35,12 +35,12 @@
35
35
  "get-port-please": "^3.1.2",
36
36
  "react": "^19.2.0",
37
37
  "vitest": "^4.0.10",
38
- "@srpc.org/core": "0.20.3"
38
+ "@srpc.org/core": "0.20.5"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "@tanstack/react-query": ">=5.90",
42
42
  "react": ">=19",
43
- "@srpc.org/core": "0.20.3"
43
+ "@srpc.org/core": "0.20.5"
44
44
  },
45
45
  "scripts": {
46
46
  "build": "bunchee",