Skip to content

Commit 72c0312

Browse files
authored
refactor(query): move shared key logic to @orpc/tanstack-query (#543)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced a new shared package for TanStack Query integration, consolidating key generation logic for all supported frameworks. - Updated package dependencies to utilize the new shared logic across React, Solid, Svelte, and Vue integrations. - **Refactor** - Standardized key generation utilities and types by sourcing them from the new shared package, replacing previous local implementations in each framework package. - Adjusted type definitions and exports to align with the new shared logic. - **Documentation** - Added comprehensive documentation and metadata for the new shared package. - **Chores** - Updated TypeScript configurations and project references to include the new shared package. - Improved .gitignore coverage for generated and temporary files. - **Tests** - Removed redundant local tests for key generation, as this functionality is now centralized. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent b9c1832 commit 72c0312

Some content is hidden

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

41 files changed

+250
-158
lines changed

packages/react-query/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
"react": ">=18.3.0"
4343
},
4444
"dependencies": {
45-
"@orpc/shared": "workspace:*"
45+
"@orpc/shared": "workspace:*",
46+
"@orpc/tanstack-query": "workspace:*"
4647
},
4748
"devDependencies": {
4849
"@tanstack/react-query": "^5.72.3",

packages/react-query/src/general-utils.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import * as TanstackQueryModule from '@orpc/tanstack-query'
12
import { createGeneralUtils } from './general-utils'
2-
import * as keyModule from './key'
33

4-
const buildKeySpy = vi.spyOn(keyModule, 'buildKey')
4+
const buildKeySpy = vi.spyOn(TanstackQueryModule, 'buildKey')
55

66
beforeEach(() => {
77
vi.clearAllMocks()

packages/react-query/src/general-utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import type { BuildKeyOptions, OperationType } from '@orpc/tanstack-query'
12
import type { QueryKey } from '@tanstack/react-query'
2-
import type { BuildKeyOptions, KeyType } from './key'
3-
import { buildKey } from './key'
3+
import { buildKey } from '@orpc/tanstack-query'
44

55
/**
66
* Utils at any level (procedure or router)
@@ -11,7 +11,7 @@ export interface GeneralUtils<TInput> {
1111
*
1212
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#query-mutation-key Tanstack Query/Mutation Key Docs}
1313
*/
14-
key<UType extends KeyType = undefined>(options?: BuildKeyOptions<UType, TInput>): QueryKey
14+
key<UType extends OperationType>(options?: BuildKeyOptions<UType, TInput>): QueryKey
1515
}
1616

1717
export function createGeneralUtils<TInput>(

packages/react-query/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { createRouterUtils } from './router-utils'
22

33
export * from './general-utils'
4-
export * from './key'
54
export * from './procedure-utils'
65
export * from './router-utils'
76
export * from './types'
87

98
export {
109
createRouterUtils as createORPCReactQueryUtils,
1110
}
11+
12+
export type { BuildKeyOptions, OperationType as KeyType } from '@orpc/tanstack-query'
13+
export { buildKey } from '@orpc/tanstack-query'

packages/react-query/src/procedure-utils.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import * as TanstackQueryModule from '@orpc/tanstack-query'
12
import { skipToken, experimental_streamedQuery as streamedQuery } from '@tanstack/react-query'
23
import { queryClient } from '../tests/shared'
3-
import * as Key from './key'
44
import { createProcedureUtils } from './procedure-utils'
55

66
vi.mock('@tanstack/react-query', async (origin) => {
@@ -12,7 +12,7 @@ vi.mock('@tanstack/react-query', async (origin) => {
1212
}
1313
})
1414

15-
const buildKeySpy = vi.spyOn(Key, 'buildKey')
15+
const buildKeySpy = vi.spyOn(TanstackQueryModule, 'buildKey')
1616

1717
beforeEach(() => {
1818
queryClient.clear()

packages/react-query/src/procedure-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import type {
1313
experimental_StreamedOptionsIn as StreamedOptionsIn,
1414
} from './types'
1515
import { isAsyncIteratorObject } from '@orpc/shared'
16+
import { buildKey } from '@orpc/tanstack-query'
1617
import { skipToken, experimental_streamedQuery as streamedQuery } from '@tanstack/react-query'
17-
import { buildKey } from './key'
1818

1919
export interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError> {
2020
/**

packages/react-query/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"extends": "../../tsconfig.lib.json",
33
"references": [
44
{ "path": "../client" },
5+
{ "path": "../tanstack-query" },
56
{ "path": "../shared" }
67
],
78
"include": ["src"],

packages/solid-query/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
"solid-js": ">=1.9.0"
4343
},
4444
"dependencies": {
45-
"@orpc/shared": "workspace:*"
45+
"@orpc/shared": "workspace:*",
46+
"@orpc/tanstack-query": "workspace:*"
4647
},
4748
"devDependencies": {
4849
"@tanstack/solid-query": "^5.72.3",

packages/solid-query/src/general-utils.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import * as keyModule from '@orpc/tanstack-query'
12
import { createGeneralUtils } from './general-utils'
2-
import * as keyModule from './key'
33

44
const buildKeySpy = vi.spyOn(keyModule, 'buildKey')
55

packages/solid-query/src/general-utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import type { BuildKeyOptions, OperationType } from '@orpc/tanstack-query'
12
import type { QueryKey } from '@tanstack/solid-query'
2-
import type { BuildKeyOptions, KeyType } from './key'
3-
import { buildKey } from './key'
3+
import { buildKey } from '@orpc/tanstack-query'
44

55
/**
66
* Utils at any level (procedure or router)
@@ -11,7 +11,7 @@ export interface GeneralUtils<TInput> {
1111
*
1212
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#query-mutation-key Tanstack Query/Mutation Key Docs}
1313
*/
14-
key<UType extends KeyType = undefined>(options?: BuildKeyOptions<UType, TInput>): QueryKey
14+
key<UType extends OperationType>(options?: BuildKeyOptions<UType, TInput>): QueryKey
1515
}
1616

1717
export function createGeneralUtils<TInput>(

packages/solid-query/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { createRouterUtils } from './router-utils'
22

33
export * from './general-utils'
4-
export * from './key'
54
export * from './procedure-utils'
65
export * from './router-utils'
76
export * from './types'
87

98
export {
109
createRouterUtils as createORPCSolidQueryUtils,
1110
}
11+
12+
export type { BuildKeyOptions, OperationType as KeyType } from '@orpc/tanstack-query'
13+
export { buildKey } from '@orpc/tanstack-query'

packages/solid-query/src/key.test.ts

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

packages/solid-query/src/key.ts

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

packages/solid-query/src/procedure-utils.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import * as Key from '@orpc/tanstack-query'
12
import { experimental_streamedQuery, skipToken } from '@tanstack/solid-query'
23
import { queryClient } from '../tests/shared'
3-
import * as Key from './key'
44
import { createProcedureUtils } from './procedure-utils'
55

66
vi.mock('@tanstack/solid-query', async (origin) => {

packages/solid-query/src/procedure-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import type { MaybeOptionalOptions } from '@orpc/shared'
33
import type { InfiniteData } from '@tanstack/solid-query'
44
import type { experimental_InferStreamedOutput, experimental_StreamedOptionsBase, experimental_StreamedOptionsIn, InfiniteOptionsBase, InfiniteOptionsIn, MutationOptions, MutationOptionsIn, QueryOptionsBase, QueryOptionsIn } from './types'
55
import { isAsyncIteratorObject } from '@orpc/shared'
6+
import { buildKey } from '@orpc/tanstack-query'
67
import { experimental_streamedQuery, skipToken } from '@tanstack/solid-query'
7-
import { buildKey } from './key'
88

99
export interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError> {
1010
/**

packages/solid-query/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"extends": "../../tsconfig.lib.json",
33
"references": [
44
{ "path": "../client" },
5+
{ "path": "../tanstack-query" },
56
{ "path": "../shared" }
67
],
78
"include": ["src"],

packages/svelte-query/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
"svelte": ">=4.2.0"
4343
},
4444
"dependencies": {
45-
"@orpc/shared": "workspace:*"
45+
"@orpc/shared": "workspace:*",
46+
"@orpc/tanstack-query": "workspace:*"
4647
},
4748
"devDependencies": {
4849
"@tanstack/svelte-query": "^5.72.3",

packages/svelte-query/src/general-utils.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import * as keyModule from '@orpc/tanstack-query'
12
import { createGeneralUtils } from './general-utils'
2-
import * as keyModule from './key'
33

44
const buildKeySpy = vi.spyOn(keyModule, 'buildKey')
55

packages/svelte-query/src/general-utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import type { BuildKeyOptions, OperationType } from '@orpc/tanstack-query'
12
import type { QueryKey } from '@tanstack/svelte-query'
2-
import type { BuildKeyOptions, KeyType } from './key'
3-
import { buildKey } from './key'
3+
import { buildKey } from '@orpc/tanstack-query'
44

55
/**
66
* Utils at any level (procedure or router)
@@ -11,7 +11,7 @@ export interface GeneralUtils<TInput> {
1111
*
1212
* @see {@link https://orpc.unnoq.com/docs/tanstack-query/basic#query-mutation-key Tanstack Query/Mutation Key Docs}
1313
*/
14-
key<UType extends KeyType = undefined>(options?: BuildKeyOptions<UType, TInput>): QueryKey
14+
key<UType extends OperationType>(options?: BuildKeyOptions<UType, TInput>): QueryKey
1515
}
1616

1717
export function createGeneralUtils<TInput>(

packages/svelte-query/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { createRouterUtils } from './router-utils'
22

33
export * from './general-utils'
4-
export * from './key'
54
export * from './procedure-utils'
65
export * from './router-utils'
76
export * from './types'
87

98
export {
109
createRouterUtils as createORPCSvelteQueryUtils,
1110
}
11+
12+
export type { BuildKeyOptions, OperationType as KeyType } from '@orpc/tanstack-query'
13+
export { buildKey } from '@orpc/tanstack-query'

packages/svelte-query/src/key.test.ts

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

packages/svelte-query/src/key.ts

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

packages/svelte-query/src/procedure-utils.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import * as Key from '@orpc/tanstack-query'
12
import { experimental_streamedQuery, skipToken } from '@tanstack/svelte-query'
23
import { queryClient } from '../tests/shared'
3-
import * as Key from './key'
44
import { createProcedureUtils } from './procedure-utils'
55

66
vi.mock('@tanstack/svelte-query', async (origin) => {

packages/svelte-query/src/procedure-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import type { MaybeOptionalOptions } from '@orpc/shared'
33
import type { InfiniteData } from '@tanstack/svelte-query'
44
import type { experimental_InferStreamedOutput, experimental_StreamedOptionsBase, experimental_StreamedOptionsIn, InfiniteOptionsBase, InfiniteOptionsIn, MutationOptions, MutationOptionsIn, QueryOptionsBase, QueryOptionsIn } from './types'
55
import { isAsyncIteratorObject } from '@orpc/shared'
6+
import { buildKey } from '@orpc/tanstack-query'
67
import { experimental_streamedQuery, skipToken } from '@tanstack/svelte-query'
7-
import { buildKey } from './key'
88

99
export interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError> {
1010
/**

packages/tanstack-query/.gitignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Hidden folders and files
2+
.*
3+
!.gitignore
4+
!.*.example
5+
6+
# Common generated folders
7+
logs/
8+
node_modules/
9+
out/
10+
dist/
11+
dist-ssr/
12+
build/
13+
coverage/
14+
temp/
15+
16+
# Common generated files
17+
*.log
18+
*.log.*
19+
*.tsbuildinfo
20+
*.vitest-temp.json
21+
vite.config.ts.timestamp-*
22+
vitest.config.ts.timestamp-*
23+
24+
# Common manual ignore files
25+
*.local
26+
*.pem

0 commit comments

Comments
 (0)