Skip to content

Commit 172fe95

Browse files
authored
feat(query)!: redesign pageParam input to use a function and refine internal types (#126)
* react query - wip * wip * wip * improve * wip * wip * rename * rename * improve react query * improve tests * vue query - procedure utils tests * vue query - general utils tests * vue query - router utils * e2e tests improve * vue colada * vue colada - rename files * vue colada -unit tests * vue colada - improve * improve types * improve types * vue colada - e2e tests * is object utils * improve vue utils * fix types * update docs * update pnpm lock * fix tests * improve tests * improve tests
1 parent bc9d3dd commit 172fe95

File tree

102 files changed

+2842
-3844
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+2842
-3844
lines changed

apps/content/content/docs/client/react-query.mdx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ queryClient.invalidateQueries({ queryKey: orpc.posts.getPost.key({ input: { id:
132132

133133
## Infinite Queries
134134

135-
Infinite queries require a `cursor` in the input field for pagination.
135+
Infinite queries require you define input as a function with `pageParam` as the first argument.
136136

137137
```tsx twoslash
138138
import { os, createRouterClient } from '@orpc/server';
@@ -158,15 +158,7 @@ const orpc = createORPCReactQueryUtils(client);
158158
export function MyComponent() {
159159
const query = useInfiniteQuery(
160160
orpc.user.list.infiniteOptions({
161-
input: { limit: 10 },
162-
getNextPageParam: (lastPage) => lastPage.nextCursor,
163-
initialPageParam: 0,
164-
})
165-
);
166-
167-
const query2 = useSuspenseInfiniteQuery(
168-
orpc.user.list.infiniteOptions({
169-
input: { limit: 10 },
161+
input: (pageParam) => ({ limit: 10, cursor: pageParam }),
170162
getNextPageParam: (lastPage) => lastPage.nextCursor,
171163
initialPageParam: 0,
172164
})

apps/content/content/docs/client/vue-query.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ queryClient.invalidateQueries({ queryKey: orpc.posts.getPost.key({ input: { id:
7373

7474
## Infinite Queries
7575

76-
Infinite queries require a `cursor` in the input field for pagination.
76+
Infinite queries require you define input as a function with `pageParam` as the first argument.
7777

7878
```ts twoslash
7979
import { os, createRouterClient } from '@orpc/server';
@@ -97,7 +97,7 @@ const orpc = createORPCVueQueryUtils(client);
9797

9898
const query = useInfiniteQuery(
9999
orpc.user.list.infiniteOptions({
100-
input: { limit: 10 },
100+
input: (pageParam) => ({ limit: 10, cursor: pageParam }),
101101
getNextPageParam: (lastPage) => lastPage.nextCursor,
102102
initialPageParam: 0,
103103
})

eslint.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default antfu({
99
'react-refresh/only-export-components': 'off',
1010
'react/prefer-destructuring-assignment': 'off',
1111
'react/no-context-provider': 'off',
12-
'ts/method-signature-style': ['error', 'method'],
12+
'ts/method-signature-style': ['off'],
1313
},
1414
}, {
1515
files: ['**/*.test.ts', '**/*.test.tsx', '**/*.test-d.ts', '**/*.test-d.tsx', 'apps/content/examples/**', 'playgrounds/**'],

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"@testing-library/react": "^16.0.1",
3333
"@types/node": "^22.10.0",
3434
"@vitest/coverage-v8": "^3.0.4",
35+
"@vue/test-utils": "^2.4.6",
3536
"eslint": "^9.15.0",
3637
"eslint-plugin-format": "^0.1.2",
3738
"eslint-plugin-react-hooks": "^5.0.0",

packages/client/tests/shared.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { RPCHandler } from '@orpc/server/fetch'
2+
import { router } from '../../server/tests/shared'
3+
import { createORPCClient } from '../src'
4+
import { RPCLink } from '../src/adapters/fetch'
5+
6+
const rpcHandler = new RPCHandler(router)
7+
8+
export type ClientContext = { cache?: string } | undefined
9+
10+
const rpcLink = new RPCLink<ClientContext>({
11+
url: 'http://localhost:3000',
12+
fetch: async (url, init, context) => {
13+
if (context?.cache) {
14+
throw new Error(`cache=${context.cache} is not supported`)
15+
}
16+
17+
const request = new Request(url, init)
18+
19+
const { matched, response } = await rpcHandler.handle(request, {
20+
context: { db: 'postgres' },
21+
})
22+
23+
if (!matched) {
24+
throw new Error('No procedure matched')
25+
}
26+
27+
return response
28+
},
29+
})
30+
31+
export const orpc = createORPCClient<typeof router, ClientContext>(rpcLink)

packages/contract/src/client.test-d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { Client } from './client'
2-
import type { AbortSignal } from './types'
32

43
describe('client', () => {
54
const fn: Client<unknown, string, number, Error> = async (...[input, options]) => {

packages/contract/src/client.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import type { AbortSignal } from './types'
2-
31
export type ClientOptions<TClientContext> =
42
& { signal?: AbortSignal }
53
& (undefined extends TClientContext ? { context?: TClientContext } : { context: TClientContext })

packages/contract/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,3 @@ export * from './route'
1616
export * from './router'
1717
export * from './router-client'
1818
export * from './schema'
19-
export * from './types'

packages/contract/src/types.test-d.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

packages/contract/src/types.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)