@openapi-qraft/tanstack-query-react-types 2.0.0-next.8
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/CHANGELOG.md +3 -0
- package/dist/cjs/index.cjs +3 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/service-operation/ServiceOperation.d.ts +98 -0
- package/dist/types/service-operation/ServiceOperation.d.ts.map +1 -0
- package/dist/types/service-operation/ServiceOperationCancelQueries.d.ts +9 -0
- package/dist/types/service-operation/ServiceOperationCancelQueries.d.ts.map +1 -0
- package/dist/types/service-operation/ServiceOperationFetchInfiniteQuery.d.ts +9 -0
- package/dist/types/service-operation/ServiceOperationFetchInfiniteQuery.d.ts.map +1 -0
- package/dist/types/service-operation/ServiceOperationFetchQuery.d.ts +9 -0
- package/dist/types/service-operation/ServiceOperationFetchQuery.d.ts.map +1 -0
- package/dist/types/service-operation/ServiceOperationGetInfiniteQueryData.d.ts +8 -0
- package/dist/types/service-operation/ServiceOperationGetInfiniteQueryData.d.ts.map +1 -0
- package/dist/types/service-operation/ServiceOperationGetQueriesData.d.ts +15 -0
- package/dist/types/service-operation/ServiceOperationGetQueriesData.d.ts.map +1 -0
- package/dist/types/service-operation/ServiceOperationGetQueryData.d.ts +8 -0
- package/dist/types/service-operation/ServiceOperationGetQueryData.d.ts.map +1 -0
- package/dist/types/service-operation/ServiceOperationGetQueryState.d.ts +10 -0
- package/dist/types/service-operation/ServiceOperationGetQueryState.d.ts.map +1 -0
- package/dist/types/service-operation/ServiceOperationInvalidateQueries.d.ts +9 -0
- package/dist/types/service-operation/ServiceOperationInvalidateQueries.d.ts.map +1 -0
- package/dist/types/service-operation/ServiceOperationIsFetchingQueries.d.ts +8 -0
- package/dist/types/service-operation/ServiceOperationIsFetchingQueries.d.ts.map +1 -0
- package/dist/types/service-operation/ServiceOperationIsMutatingQueries.d.ts +8 -0
- package/dist/types/service-operation/ServiceOperationIsMutatingQueries.d.ts.map +1 -0
- package/dist/types/service-operation/ServiceOperationMutationFn.d.ts +8 -0
- package/dist/types/service-operation/ServiceOperationMutationFn.d.ts.map +1 -0
- package/dist/types/service-operation/ServiceOperationQueryFn.d.ts +12 -0
- package/dist/types/service-operation/ServiceOperationQueryFn.d.ts.map +1 -0
- package/dist/types/service-operation/ServiceOperationRefetchQueries.d.ts +9 -0
- package/dist/types/service-operation/ServiceOperationRefetchQueries.d.ts.map +1 -0
- package/dist/types/service-operation/ServiceOperationRemoveQueries.d.ts +8 -0
- package/dist/types/service-operation/ServiceOperationRemoveQueries.d.ts.map +1 -0
- package/dist/types/service-operation/ServiceOperationResetQueries.d.ts +9 -0
- package/dist/types/service-operation/ServiceOperationResetQueries.d.ts.map +1 -0
- package/dist/types/service-operation/ServiceOperationSetInfiniteQueryData.d.ts +9 -0
- package/dist/types/service-operation/ServiceOperationSetInfiniteQueryData.d.ts.map +1 -0
- package/dist/types/service-operation/ServiceOperationSetQueriesData.d.ts +9 -0
- package/dist/types/service-operation/ServiceOperationSetQueriesData.d.ts.map +1 -0
- package/dist/types/service-operation/ServiceOperationSetQueryData.d.ts +9 -0
- package/dist/types/service-operation/ServiceOperationSetQueryData.d.ts.map +1 -0
- package/dist/types/service-operation/ServiceOperationUseInfiniteQuery.d.ts +12 -0
- package/dist/types/service-operation/ServiceOperationUseInfiniteQuery.d.ts.map +1 -0
- package/dist/types/service-operation/ServiceOperationUseIsFetchingQueries.d.ts +8 -0
- package/dist/types/service-operation/ServiceOperationUseIsFetchingQueries.d.ts.map +1 -0
- package/dist/types/service-operation/ServiceOperationUseIsMutating.d.ts +8 -0
- package/dist/types/service-operation/ServiceOperationUseIsMutating.d.ts.map +1 -0
- package/dist/types/service-operation/ServiceOperationUseMutation.d.ts +11 -0
- package/dist/types/service-operation/ServiceOperationUseMutation.d.ts.map +1 -0
- package/dist/types/service-operation/ServiceOperationUseMutationState.d.ts +12 -0
- package/dist/types/service-operation/ServiceOperationUseMutationState.d.ts.map +1 -0
- package/dist/types/service-operation/ServiceOperationUseQueries.d.ts +12 -0
- package/dist/types/service-operation/ServiceOperationUseQueries.d.ts.map +1 -0
- package/dist/types/service-operation/ServiceOperationUseQuery.d.ts +11 -0
- package/dist/types/service-operation/ServiceOperationUseQuery.d.ts.map +1 -0
- package/dist/types/service-operation/ServiceOperationUseSuspenseInfiniteQuery.d.ts +10 -0
- package/dist/types/service-operation/ServiceOperationUseSuspenseInfiniteQuery.d.ts.map +1 -0
- package/dist/types/service-operation/ServiceOperationUseSuspenseQueries.d.ts +12 -0
- package/dist/types/service-operation/ServiceOperationUseSuspenseQueries.d.ts.map +1 -0
- package/dist/types/service-operation/ServiceOperationUseSuspenseQuery.d.ts +9 -0
- package/dist/types/service-operation/ServiceOperationUseSuspenseQuery.d.ts.map +1 -0
- package/dist/types/service-operation/index.d.ts +30 -0
- package/dist/types/service-operation/index.d.ts.map +1 -0
- package/dist/types/shared/AreAllOptional.d.ts +4 -0
- package/dist/types/shared/AreAllOptional.d.ts.map +1 -0
- package/dist/types/shared/FetchInfiniteQueryOptions.d.ts +54 -0
- package/dist/types/shared/FetchInfiniteQueryOptions.d.ts.map +1 -0
- package/dist/types/shared/InvalidateQueryFilters.d.ts +9 -0
- package/dist/types/shared/InvalidateQueryFilters.d.ts.map +1 -0
- package/dist/types/shared/MutationFilters.d.ts +52 -0
- package/dist/types/shared/MutationFilters.d.ts.map +1 -0
- package/dist/types/shared/OperationInfiniteData.d.ts +4 -0
- package/dist/types/shared/OperationInfiniteData.d.ts.map +1 -0
- package/dist/types/shared/PartialParameters.d.ts +13 -0
- package/dist/types/shared/PartialParameters.d.ts.map +1 -0
- package/dist/types/shared/QueryFilters.d.ts +123 -0
- package/dist/types/shared/QueryFilters.d.ts.map +1 -0
- package/dist/types/shared/RequestFn.d.ts +80 -0
- package/dist/types/shared/RequestFn.d.ts.map +1 -0
- package/dist/types/shared/ServiceOperationFetchQueryOptions.d.ts +50 -0
- package/dist/types/shared/ServiceOperationFetchQueryOptions.d.ts.map +1 -0
- package/dist/types/shared/ServiceOperationKey.d.ts +16 -0
- package/dist/types/shared/ServiceOperationKey.d.ts.map +1 -0
- package/dist/types/shared/ServiceOperationMutation.d.ts +23 -0
- package/dist/types/shared/ServiceOperationMutation.d.ts.map +1 -0
- package/dist/types/shared/ServiceOperationQuery.d.ts +25 -0
- package/dist/types/shared/ServiceOperationQuery.d.ts.map +1 -0
- package/dist/types/shared/UseQueryOptionsForUseQueries.d.ts +16 -0
- package/dist/types/shared/UseQueryOptionsForUseQueries.d.ts.map +1 -0
- package/dist/types/shared/UseQueryOptionsForUseSuspenseQuery.d.ts +13 -0
- package/dist/types/shared/UseQueryOptionsForUseSuspenseQuery.d.ts.map +1 -0
- package/dist/types/shared/WithOptional.d.ts +2 -0
- package/dist/types/shared/WithOptional.d.ts.map +1 -0
- package/dist/types/shared/index.d.ts +16 -0
- package/dist/types/shared/index.d.ts.map +1 -0
- package/package.json +48 -0
- package/src/index.ts +2 -0
- package/src/service-operation/ServiceOperation.ts +170 -0
- package/src/service-operation/ServiceOperationCancelQueries.ts +31 -0
- package/src/service-operation/ServiceOperationFetchInfiniteQuery.ts +73 -0
- package/src/service-operation/ServiceOperationFetchQuery.ts +43 -0
- package/src/service-operation/ServiceOperationGetInfiniteQueryData.ts +17 -0
- package/src/service-operation/ServiceOperationGetQueriesData.ts +47 -0
- package/src/service-operation/ServiceOperationGetQueryData.ts +16 -0
- package/src/service-operation/ServiceOperationGetQueryState.ts +28 -0
- package/src/service-operation/ServiceOperationInvalidateQueries.ts +20 -0
- package/src/service-operation/ServiceOperationIsFetchingQueries.ts +29 -0
- package/src/service-operation/ServiceOperationIsMutatingQueries.ts +31 -0
- package/src/service-operation/ServiceOperationMutationFn.ts +20 -0
- package/src/service-operation/ServiceOperationQueryFn.ts +35 -0
- package/src/service-operation/ServiceOperationRefetchQueries.ts +31 -0
- package/src/service-operation/ServiceOperationRemoveQueries.ts +29 -0
- package/src/service-operation/ServiceOperationResetQueries.ts +31 -0
- package/src/service-operation/ServiceOperationSetInfiniteQueryData.ts +20 -0
- package/src/service-operation/ServiceOperationSetQueriesData.ts +35 -0
- package/src/service-operation/ServiceOperationSetQueryData.ts +17 -0
- package/src/service-operation/ServiceOperationUseInfiniteQuery.ts +76 -0
- package/src/service-operation/ServiceOperationUseIsFetchingQueries.ts +29 -0
- package/src/service-operation/ServiceOperationUseIsMutating.ts +31 -0
- package/src/service-operation/ServiceOperationUseMutation.ts +51 -0
- package/src/service-operation/ServiceOperationUseMutationState.ts +49 -0
- package/src/service-operation/ServiceOperationUseQueries.ts +21 -0
- package/src/service-operation/ServiceOperationUseQuery.ts +51 -0
- package/src/service-operation/ServiceOperationUseSuspenseInfiniteQuery.ts +45 -0
- package/src/service-operation/ServiceOperationUseSuspenseQueries.ts +26 -0
- package/src/service-operation/ServiceOperationUseSuspenseQuery.ts +30 -0
- package/src/service-operation/index.ts +29 -0
- package/src/shared/AreAllOptional.ts +8 -0
- package/src/shared/FetchInfiniteQueryOptions.ts +109 -0
- package/src/shared/InvalidateQueryFilters.ts +19 -0
- package/src/shared/MutationFilters.ts +93 -0
- package/src/shared/OperationInfiniteData.ts +7 -0
- package/src/shared/PartialParameters.ts +12 -0
- package/src/shared/QueryFilters.ts +226 -0
- package/src/shared/RequestFn.ts +121 -0
- package/src/shared/ServiceOperationFetchQueryOptions.ts +84 -0
- package/src/shared/ServiceOperationKey.ts +20 -0
- package/src/shared/ServiceOperationMutation.ts +32 -0
- package/src/shared/ServiceOperationQuery.ts +40 -0
- package/src/shared/UseQueryOptionsForUseQueries.ts +35 -0
- package/src/shared/UseQueryOptionsForUseSuspenseQuery.ts +28 -0
- package/src/shared/WithOptional.ts +2 -0
- package/src/shared/index.ts +15 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
DefaultError,
|
|
3
|
+
FetchQueryOptions,
|
|
4
|
+
GetNextPageParamFunction,
|
|
5
|
+
InitialPageParam,
|
|
6
|
+
QueryFunction,
|
|
7
|
+
} from '@tanstack/query-core';
|
|
8
|
+
import type { OperationInfiniteData } from './OperationInfiniteData.js';
|
|
9
|
+
import type { PartialParameters } from './PartialParameters.js';
|
|
10
|
+
import type {
|
|
11
|
+
ServiceOperationInfiniteQueryKey,
|
|
12
|
+
ServiceOperationQueryKey,
|
|
13
|
+
} from './ServiceOperationKey.js';
|
|
14
|
+
import { RequestFn } from './RequestFn.js';
|
|
15
|
+
|
|
16
|
+
type FetchInfiniteQueryPages<TQueryFnData = unknown, TPageParam = unknown> =
|
|
17
|
+
| {
|
|
18
|
+
pages?: never;
|
|
19
|
+
}
|
|
20
|
+
| {
|
|
21
|
+
pages: number;
|
|
22
|
+
getNextPageParam: GetNextPageParamFunction<
|
|
23
|
+
PartialParameters<TPageParam>,
|
|
24
|
+
TQueryFnData
|
|
25
|
+
>;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
type FetchInfiniteQueryOptionsBase<
|
|
29
|
+
TSchema extends { url: string; method: string },
|
|
30
|
+
TQueryFnData,
|
|
31
|
+
TParams = {},
|
|
32
|
+
TPageParam = unknown,
|
|
33
|
+
TError = DefaultError,
|
|
34
|
+
> = Omit<
|
|
35
|
+
FetchQueryOptions<
|
|
36
|
+
TQueryFnData,
|
|
37
|
+
TError,
|
|
38
|
+
OperationInfiniteData<TQueryFnData, TParams>,
|
|
39
|
+
ServiceOperationQueryKey<TSchema, TParams>,
|
|
40
|
+
TPageParam
|
|
41
|
+
>,
|
|
42
|
+
'queryKey'
|
|
43
|
+
> &
|
|
44
|
+
InitialPageParam<PartialParameters<TPageParam>> &
|
|
45
|
+
FetchInfiniteQueryPages<TQueryFnData, TPageParam>;
|
|
46
|
+
|
|
47
|
+
export type FetchInfiniteQueryOptionsByQueryKey<
|
|
48
|
+
TSchema extends { url: string; method: string },
|
|
49
|
+
TQueryFnData,
|
|
50
|
+
TParams = {},
|
|
51
|
+
TPageParam = {},
|
|
52
|
+
TError = DefaultError,
|
|
53
|
+
> = FetchInfiniteQueryOptionsBase<
|
|
54
|
+
TSchema,
|
|
55
|
+
TQueryFnData,
|
|
56
|
+
TParams,
|
|
57
|
+
TPageParam,
|
|
58
|
+
TError
|
|
59
|
+
> & {
|
|
60
|
+
/**
|
|
61
|
+
* Fetch Queries by query key
|
|
62
|
+
*/
|
|
63
|
+
queryKey?: ServiceOperationInfiniteQueryKey<TSchema, TParams>;
|
|
64
|
+
parameters?: never;
|
|
65
|
+
};
|
|
66
|
+
export type FetchInfiniteQueryOptionsByParameters<
|
|
67
|
+
TSchema extends { url: string; method: string },
|
|
68
|
+
TQueryFnData,
|
|
69
|
+
TParams = {},
|
|
70
|
+
TPageParam = {},
|
|
71
|
+
TError = DefaultError,
|
|
72
|
+
> = FetchInfiniteQueryOptionsBase<
|
|
73
|
+
TSchema,
|
|
74
|
+
TQueryFnData,
|
|
75
|
+
TParams,
|
|
76
|
+
TPageParam,
|
|
77
|
+
TError
|
|
78
|
+
> & {
|
|
79
|
+
/**
|
|
80
|
+
* Fetch Queries by parameters
|
|
81
|
+
*/
|
|
82
|
+
parameters?: TParams;
|
|
83
|
+
queryKey?: never;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export type FetchInfiniteQueryOptionsQueryFn<
|
|
87
|
+
TSchema extends { url: string; method: string },
|
|
88
|
+
TQueryFnData,
|
|
89
|
+
TParams,
|
|
90
|
+
TError,
|
|
91
|
+
> =
|
|
92
|
+
| {
|
|
93
|
+
queryFn: QueryFunction<
|
|
94
|
+
TQueryFnData,
|
|
95
|
+
ServiceOperationInfiniteQueryKey<TSchema, TParams>
|
|
96
|
+
>;
|
|
97
|
+
}
|
|
98
|
+
| {
|
|
99
|
+
/**
|
|
100
|
+
* Custom request function to use for the query
|
|
101
|
+
*/
|
|
102
|
+
requestFn?: RequestFn<TQueryFnData, TError>;
|
|
103
|
+
/**
|
|
104
|
+
* Base URL to use for the request (used in the `queryFn`)
|
|
105
|
+
* @example 'https://api.example.com'
|
|
106
|
+
*/
|
|
107
|
+
baseUrl?: string | undefined;
|
|
108
|
+
queryFn?: never; // Workaround to fix union type error
|
|
109
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { DefaultError } from '@tanstack/query-core';
|
|
2
|
+
import type {
|
|
3
|
+
QueryFiltersByParameters,
|
|
4
|
+
QueryFiltersByQueryKey,
|
|
5
|
+
QueryTypeFilter,
|
|
6
|
+
} from './QueryFilters.js';
|
|
7
|
+
|
|
8
|
+
export type InvalidateQueryFilters<
|
|
9
|
+
TSchema extends { url: string; method: string },
|
|
10
|
+
TQueryFnData,
|
|
11
|
+
TInfinite extends boolean,
|
|
12
|
+
TParams = {},
|
|
13
|
+
TError = DefaultError,
|
|
14
|
+
> = (
|
|
15
|
+
| QueryFiltersByParameters<TSchema, TQueryFnData, TInfinite, TParams, TError>
|
|
16
|
+
| QueryFiltersByQueryKey<TSchema, TQueryFnData, TInfinite, TParams, TError>
|
|
17
|
+
) & {
|
|
18
|
+
refetchType?: QueryTypeFilter | 'none';
|
|
19
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
DefaultError,
|
|
3
|
+
Mutation,
|
|
4
|
+
MutationStatus,
|
|
5
|
+
} from '@tanstack/query-core';
|
|
6
|
+
import type { UseMutationOptions } from '@tanstack/react-query';
|
|
7
|
+
import type { AreAllOptional } from './AreAllOptional.js';
|
|
8
|
+
import type { PartialParameters } from './PartialParameters.js';
|
|
9
|
+
import type { ServiceOperationMutationKey } from './ServiceOperationKey.js';
|
|
10
|
+
|
|
11
|
+
interface UseMutationStateFiltersBase<
|
|
12
|
+
TBody,
|
|
13
|
+
TData,
|
|
14
|
+
TParams,
|
|
15
|
+
TError = DefaultError,
|
|
16
|
+
TContext = unknown,
|
|
17
|
+
> {
|
|
18
|
+
/**
|
|
19
|
+
* Match mutation key exactly
|
|
20
|
+
*/
|
|
21
|
+
exact?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Include mutations matching this predicate function
|
|
24
|
+
*/
|
|
25
|
+
predicate?: (
|
|
26
|
+
mutation: Mutation<
|
|
27
|
+
TData,
|
|
28
|
+
TError,
|
|
29
|
+
MutationVariables<TBody, TParams>,
|
|
30
|
+
TContext
|
|
31
|
+
>
|
|
32
|
+
) => boolean;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Filter by mutation status
|
|
36
|
+
*/
|
|
37
|
+
status?: MutationStatus;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface MutationFiltersByParameters<
|
|
41
|
+
TBody,
|
|
42
|
+
TData,
|
|
43
|
+
TParams,
|
|
44
|
+
TError = DefaultError,
|
|
45
|
+
TContext = unknown,
|
|
46
|
+
> extends UseMutationStateFiltersBase<TBody, TData, TParams, TError, TContext> {
|
|
47
|
+
/**
|
|
48
|
+
* Include mutations matching these parameters
|
|
49
|
+
*/
|
|
50
|
+
parameters?: PartialParameters<TParams>;
|
|
51
|
+
mutationKey?: never;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface MutationFiltersByMutationKey<
|
|
55
|
+
TSchema extends { url: string; method: string },
|
|
56
|
+
TBody,
|
|
57
|
+
TData,
|
|
58
|
+
TParams,
|
|
59
|
+
TError = DefaultError,
|
|
60
|
+
TContext = unknown,
|
|
61
|
+
> extends UseMutationStateFiltersBase<TBody, TData, TParams, TError, TContext> {
|
|
62
|
+
/**
|
|
63
|
+
* Include mutations matching this mutation key
|
|
64
|
+
*/
|
|
65
|
+
mutationKey?: ServiceOperationMutationKey<
|
|
66
|
+
TSchema,
|
|
67
|
+
PartialParameters<TParams>
|
|
68
|
+
>;
|
|
69
|
+
parameters?: never;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export type MutationVariables<TBody, TParams> =
|
|
73
|
+
AreAllOptional<TBody> extends true
|
|
74
|
+
? AreAllOptional<TParams> extends true
|
|
75
|
+
? ({ body?: TBody } & NonNullableObject<TParams>) | void
|
|
76
|
+
: { body?: TBody } & TParams
|
|
77
|
+
: { body: TBody } & NonNullableObject<TParams>;
|
|
78
|
+
|
|
79
|
+
type NonNullableObject<T> = NonNullable<T> extends never ? {} : T;
|
|
80
|
+
|
|
81
|
+
export type ServiceOperationUseMutationOptions<
|
|
82
|
+
TSchema extends { url: string; method: string },
|
|
83
|
+
TData,
|
|
84
|
+
TParams,
|
|
85
|
+
TVariables,
|
|
86
|
+
TError,
|
|
87
|
+
TContext = unknown,
|
|
88
|
+
> = Omit<
|
|
89
|
+
UseMutationOptions<TData, TError, TVariables, TContext>,
|
|
90
|
+
'mutationKey'
|
|
91
|
+
> & {
|
|
92
|
+
mutationKey?: ServiceOperationMutationKey<TSchema, TParams>;
|
|
93
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shallow partial 'parameters'.
|
|
3
|
+
* @example
|
|
4
|
+
* ```ts
|
|
5
|
+
* {query?: {page: number, nested: {still: 'not_partial'}}}
|
|
6
|
+
* // =>
|
|
7
|
+
* {query?: {page?: number, nested?: {still: 'not_partial'}}}
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
10
|
+
export type PartialParameters<T> = T extends object
|
|
11
|
+
? { [K in keyof T]?: T[K] extends object ? Partial<T[K]> : T[K] }
|
|
12
|
+
: T;
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import type { DefaultError, FetchStatus, Query } from '@tanstack/query-core';
|
|
2
|
+
import type { OperationInfiniteData } from './OperationInfiniteData.js';
|
|
3
|
+
import type { PartialParameters } from './PartialParameters.js';
|
|
4
|
+
import type {
|
|
5
|
+
ServiceOperationBaseQueryKey,
|
|
6
|
+
ServiceOperationInfiniteQueryKey,
|
|
7
|
+
ServiceOperationQueryKey,
|
|
8
|
+
} from './ServiceOperationKey.js';
|
|
9
|
+
|
|
10
|
+
export type QueryTypeFilter = 'all' | 'active' | 'inactive';
|
|
11
|
+
|
|
12
|
+
interface QueryFiltersBase<
|
|
13
|
+
TSchema extends { url: string; method: string },
|
|
14
|
+
TData,
|
|
15
|
+
TInfinite extends boolean,
|
|
16
|
+
TParams = {},
|
|
17
|
+
TError = DefaultError,
|
|
18
|
+
> {
|
|
19
|
+
/**
|
|
20
|
+
* Include queries matching this predicate function
|
|
21
|
+
*/
|
|
22
|
+
predicate?: TInfinite extends true
|
|
23
|
+
? QueryFilterInfinitePredicate<TSchema, TData, TParams, TError>
|
|
24
|
+
: TInfinite extends false
|
|
25
|
+
? QueryFilterRegularPredicate<TSchema, TData, TParams, TError>
|
|
26
|
+
: (query: string) => boolean;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Filter to active queries, inactive queries or all queries
|
|
30
|
+
*/
|
|
31
|
+
type?: QueryTypeFilter;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Include or exclude stale queries
|
|
35
|
+
*/
|
|
36
|
+
stale?: boolean;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Include queries matching their fetchStatus
|
|
40
|
+
*/
|
|
41
|
+
fetchStatus?: FetchStatus;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
interface QueryFiltersByQueryKeyBase<
|
|
45
|
+
TSchema extends { url: string; method: string },
|
|
46
|
+
TData,
|
|
47
|
+
TInfinite extends boolean,
|
|
48
|
+
TParams = {},
|
|
49
|
+
TError = DefaultError,
|
|
50
|
+
> extends QueryFiltersBase<TSchema, TData, TInfinite, TParams, TError> {
|
|
51
|
+
infinite?: never;
|
|
52
|
+
parameters?: never;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
interface QueryFiltersByExactQueryKey<
|
|
56
|
+
TSchema extends { url: string; method: string },
|
|
57
|
+
TData,
|
|
58
|
+
TInfinite extends boolean,
|
|
59
|
+
TParams = {},
|
|
60
|
+
TError = DefaultError,
|
|
61
|
+
> extends QueryFiltersByQueryKeyBase<
|
|
62
|
+
TSchema,
|
|
63
|
+
TData,
|
|
64
|
+
TInfinite,
|
|
65
|
+
TParams,
|
|
66
|
+
TError
|
|
67
|
+
> {
|
|
68
|
+
/**
|
|
69
|
+
* Include queries matching this query key
|
|
70
|
+
*/
|
|
71
|
+
queryKey: ServiceOperationBaseQueryKey<TSchema, TInfinite, TParams>;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Match query key exactly
|
|
75
|
+
*/
|
|
76
|
+
exact: true;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
interface QueryFiltersWeakExactQueryKey<
|
|
80
|
+
TSchema extends { url: string; method: string },
|
|
81
|
+
TData,
|
|
82
|
+
TInfinite extends boolean,
|
|
83
|
+
TParams = {},
|
|
84
|
+
TError = DefaultError,
|
|
85
|
+
> extends QueryFiltersByQueryKeyBase<
|
|
86
|
+
TSchema,
|
|
87
|
+
TData,
|
|
88
|
+
TInfinite,
|
|
89
|
+
TParams,
|
|
90
|
+
TError
|
|
91
|
+
> {
|
|
92
|
+
/**
|
|
93
|
+
* Include queries matching this query key
|
|
94
|
+
*/
|
|
95
|
+
queryKey?: ServiceOperationBaseQueryKey<
|
|
96
|
+
TSchema,
|
|
97
|
+
TInfinite,
|
|
98
|
+
PartialParameters<TParams>
|
|
99
|
+
>;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Match query key exactly
|
|
103
|
+
*/
|
|
104
|
+
exact?: false;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export type QueryFiltersByQueryKey<
|
|
108
|
+
TSchema extends { url: string; method: string },
|
|
109
|
+
TData,
|
|
110
|
+
TInfinite extends boolean,
|
|
111
|
+
TParams = {},
|
|
112
|
+
TError = DefaultError,
|
|
113
|
+
> =
|
|
114
|
+
| QueryFiltersByExactQueryKey<TSchema, TData, TInfinite, TParams, TError>
|
|
115
|
+
| QueryFiltersWeakExactQueryKey<TSchema, TData, TInfinite, TParams, TError>;
|
|
116
|
+
|
|
117
|
+
interface QueryFiltersByParametersBase<
|
|
118
|
+
TSchema extends { url: string; method: string },
|
|
119
|
+
TData,
|
|
120
|
+
TInfinite extends boolean,
|
|
121
|
+
TParams = {},
|
|
122
|
+
TError = DefaultError,
|
|
123
|
+
> extends QueryFiltersBase<TSchema, TData, TInfinite, TParams, TError> {
|
|
124
|
+
/**
|
|
125
|
+
* Is the query infinite
|
|
126
|
+
*/
|
|
127
|
+
infinite?: TInfinite;
|
|
128
|
+
|
|
129
|
+
queryKey?: never;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
interface QueryFiltersByExactParameters<
|
|
133
|
+
TSchema extends { url: string; method: string },
|
|
134
|
+
TData,
|
|
135
|
+
TInfinite extends boolean,
|
|
136
|
+
TParams = {},
|
|
137
|
+
TError = DefaultError,
|
|
138
|
+
> extends QueryFiltersByParametersBase<
|
|
139
|
+
TSchema,
|
|
140
|
+
TData,
|
|
141
|
+
TInfinite,
|
|
142
|
+
TParams,
|
|
143
|
+
TError
|
|
144
|
+
> {
|
|
145
|
+
/**
|
|
146
|
+
* Match query key exactly
|
|
147
|
+
*/
|
|
148
|
+
exact: true;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Include queries matching parameters
|
|
152
|
+
*/
|
|
153
|
+
parameters: TParams;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
interface QueryFiltersByWeakParameters<
|
|
157
|
+
TSchema extends { url: string; method: string },
|
|
158
|
+
TData,
|
|
159
|
+
TInfinite extends boolean,
|
|
160
|
+
TParams = {},
|
|
161
|
+
TError = DefaultError,
|
|
162
|
+
> extends QueryFiltersByParametersBase<
|
|
163
|
+
TSchema,
|
|
164
|
+
TData,
|
|
165
|
+
TInfinite,
|
|
166
|
+
TParams,
|
|
167
|
+
TError
|
|
168
|
+
> {
|
|
169
|
+
/**
|
|
170
|
+
* Match query key exactly
|
|
171
|
+
*/
|
|
172
|
+
exact?: false;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Include queries matching parameters
|
|
176
|
+
*/
|
|
177
|
+
parameters?: PartialParameters<TParams>;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export type QueryFiltersByParameters<
|
|
181
|
+
TSchema extends { url: string; method: string },
|
|
182
|
+
TData,
|
|
183
|
+
TInfinite extends boolean,
|
|
184
|
+
TParams = {},
|
|
185
|
+
TError = DefaultError,
|
|
186
|
+
> =
|
|
187
|
+
| QueryFiltersByExactParameters<TSchema, TData, TInfinite, TParams, TError>
|
|
188
|
+
| QueryFiltersByWeakParameters<TSchema, TData, TInfinite, TParams, TError>;
|
|
189
|
+
|
|
190
|
+
interface QueryFilterInfinitePredicate<
|
|
191
|
+
TSchema extends { url: string; method: string },
|
|
192
|
+
TData,
|
|
193
|
+
TParams = {},
|
|
194
|
+
TError = DefaultError,
|
|
195
|
+
> {
|
|
196
|
+
/**
|
|
197
|
+
* Include queries matching this predicate function
|
|
198
|
+
*/
|
|
199
|
+
(
|
|
200
|
+
query: Query<
|
|
201
|
+
OperationInfiniteData<TData, TParams>,
|
|
202
|
+
TError,
|
|
203
|
+
OperationInfiniteData<TData, TParams>,
|
|
204
|
+
ServiceOperationInfiniteQueryKey<TSchema, TParams>
|
|
205
|
+
>
|
|
206
|
+
): boolean;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
interface QueryFilterRegularPredicate<
|
|
210
|
+
TSchema extends { url: string; method: string },
|
|
211
|
+
TData,
|
|
212
|
+
TParams = {},
|
|
213
|
+
TError = DefaultError,
|
|
214
|
+
> {
|
|
215
|
+
/**
|
|
216
|
+
* Include queries matching this predicate function
|
|
217
|
+
*/
|
|
218
|
+
(
|
|
219
|
+
query: Query<
|
|
220
|
+
TData,
|
|
221
|
+
TError,
|
|
222
|
+
TData,
|
|
223
|
+
ServiceOperationQueryKey<TSchema, TParams>
|
|
224
|
+
>
|
|
225
|
+
): boolean;
|
|
226
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
export interface RequestFn<TData, TError> {
|
|
2
|
+
(
|
|
3
|
+
schema: OperationSchema,
|
|
4
|
+
requestInfo: RequestFnInfo,
|
|
5
|
+
options?: RequestFnOptions
|
|
6
|
+
): Promise<RequestFnResponse<TData, TError>>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface OperationSchema {
|
|
10
|
+
/**
|
|
11
|
+
* Operation path
|
|
12
|
+
* @example /user/{id}
|
|
13
|
+
*/
|
|
14
|
+
readonly url: string; //todo::rename to `path`
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Operation method
|
|
18
|
+
*/
|
|
19
|
+
readonly method:
|
|
20
|
+
| 'get'
|
|
21
|
+
| 'put'
|
|
22
|
+
| 'post'
|
|
23
|
+
| 'patch'
|
|
24
|
+
| 'delete'
|
|
25
|
+
| 'options'
|
|
26
|
+
| 'head'
|
|
27
|
+
| 'trace';
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Media type of the request body
|
|
31
|
+
* @example application/json
|
|
32
|
+
*/
|
|
33
|
+
readonly mediaType?: string;
|
|
34
|
+
|
|
35
|
+
readonly security?: string[];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface RequestFnInfo
|
|
39
|
+
extends RequestFnPayload,
|
|
40
|
+
Omit<RequestInit, 'headers' | 'method' | 'body' | 'signal'> {
|
|
41
|
+
/**
|
|
42
|
+
* Request headers
|
|
43
|
+
* @example { 'X-Auth': '123' }
|
|
44
|
+
*/
|
|
45
|
+
readonly headers?: HeadersOptions;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface RequestFnPayload {
|
|
49
|
+
/**
|
|
50
|
+
* Base URL to use for the request
|
|
51
|
+
* @example 'https://api.example.com'
|
|
52
|
+
*/
|
|
53
|
+
baseUrl?: string;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* OpenAPI parameters
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* { path: {id: 1}, query: {search: 'hello'} }
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
readonly parameters?: {
|
|
63
|
+
readonly path?: Record<string, any>;
|
|
64
|
+
readonly header?: Record<string, any>;
|
|
65
|
+
readonly query?: Record<string, any>;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Request body
|
|
70
|
+
* @example { name: 'John' }
|
|
71
|
+
*/
|
|
72
|
+
readonly body?: BodyInit | Record<string, unknown> | null;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Tanstack Query Meta
|
|
76
|
+
*/
|
|
77
|
+
meta?: Record<string, unknown>;
|
|
78
|
+
|
|
79
|
+
/** An AbortSignal to set request's signal. */
|
|
80
|
+
signal?: AbortSignal | null;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export type RequestFnResponse<TData, TError> =
|
|
84
|
+
| {
|
|
85
|
+
data: TData;
|
|
86
|
+
response: Response;
|
|
87
|
+
error?: undefined;
|
|
88
|
+
}
|
|
89
|
+
| {
|
|
90
|
+
// server error
|
|
91
|
+
data?: undefined;
|
|
92
|
+
response: Response;
|
|
93
|
+
error: TError | Error;
|
|
94
|
+
}
|
|
95
|
+
| {
|
|
96
|
+
// network error
|
|
97
|
+
data?: undefined;
|
|
98
|
+
response?: undefined;
|
|
99
|
+
error: Error;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export interface RequestFnOptions {
|
|
103
|
+
urlSerializer?: UrlSerializer;
|
|
104
|
+
bodySerializer?: BodySerializer;
|
|
105
|
+
fetch?: typeof fetch;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
type BodySerializer = (
|
|
109
|
+
schema: OperationSchema,
|
|
110
|
+
info: RequestFnPayload
|
|
111
|
+
) => string | FormData | Blob | undefined;
|
|
112
|
+
|
|
113
|
+
type UrlSerializer = (
|
|
114
|
+
schema: OperationSchema,
|
|
115
|
+
info: RequestFnPayload
|
|
116
|
+
) => string;
|
|
117
|
+
|
|
118
|
+
// To have definitely typed headers without a conversion to stings
|
|
119
|
+
export type HeadersOptions =
|
|
120
|
+
| HeadersInit
|
|
121
|
+
| Record<string, string | number | boolean | null | undefined>;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { RequestFn } from '@openapi-qraft/tanstack-query-react-types';
|
|
2
|
+
import type {
|
|
3
|
+
DefaultError,
|
|
4
|
+
FetchQueryOptions,
|
|
5
|
+
QueryFunction,
|
|
6
|
+
} from '@tanstack/query-core';
|
|
7
|
+
import type { ServiceOperationQueryKey } from './ServiceOperationKey.js';
|
|
8
|
+
|
|
9
|
+
export type ServiceOperationFetchQueryOptions<
|
|
10
|
+
TSchema extends { url: string; method: string },
|
|
11
|
+
TQueryFnData,
|
|
12
|
+
TParams,
|
|
13
|
+
TError,
|
|
14
|
+
> =
|
|
15
|
+
| (FetchQueryOptionsByQueryKey<TSchema, TQueryFnData, TParams, TError> &
|
|
16
|
+
FetchQueryOptionsQueryFn<TSchema, TQueryFnData, TParams, TError>)
|
|
17
|
+
| (FetchQueryOptionsByParameters<TSchema, TQueryFnData, TParams, TError> &
|
|
18
|
+
FetchQueryOptionsQueryFn<TSchema, TQueryFnData, TParams, TError>);
|
|
19
|
+
|
|
20
|
+
type FetchQueryOptionsBase<
|
|
21
|
+
TSchema extends { url: string; method: string },
|
|
22
|
+
TQueryFnData,
|
|
23
|
+
TParams = {},
|
|
24
|
+
TError = DefaultError,
|
|
25
|
+
> = Omit<
|
|
26
|
+
FetchQueryOptions<
|
|
27
|
+
TQueryFnData,
|
|
28
|
+
TError,
|
|
29
|
+
TQueryFnData,
|
|
30
|
+
ServiceOperationQueryKey<TSchema, TParams>
|
|
31
|
+
>,
|
|
32
|
+
'queryKey' | 'queryFn'
|
|
33
|
+
>;
|
|
34
|
+
|
|
35
|
+
interface FetchQueryOptionsByQueryKey<
|
|
36
|
+
TSchema extends { url: string; method: string },
|
|
37
|
+
TQueryFnData,
|
|
38
|
+
TParams = {},
|
|
39
|
+
TError = DefaultError,
|
|
40
|
+
> extends FetchQueryOptionsBase<TSchema, TQueryFnData, TParams, TError> {
|
|
41
|
+
/**
|
|
42
|
+
* Fetch Queries by query key
|
|
43
|
+
*/
|
|
44
|
+
queryKey: ServiceOperationQueryKey<TSchema, TParams>;
|
|
45
|
+
parameters?: never;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
interface FetchQueryOptionsByParameters<
|
|
49
|
+
TSchema extends { url: string; method: string },
|
|
50
|
+
TQueryFnData,
|
|
51
|
+
TParams = {},
|
|
52
|
+
TError = DefaultError,
|
|
53
|
+
> extends FetchQueryOptionsBase<TSchema, TQueryFnData, TParams, TError> {
|
|
54
|
+
/**
|
|
55
|
+
* Fetch Queries by parameters
|
|
56
|
+
*/
|
|
57
|
+
parameters: TParams;
|
|
58
|
+
queryKey?: never;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
type FetchQueryOptionsQueryFn<
|
|
62
|
+
TSchema extends { url: string; method: string },
|
|
63
|
+
TQueryFnData,
|
|
64
|
+
TParams,
|
|
65
|
+
TError,
|
|
66
|
+
> =
|
|
67
|
+
| {
|
|
68
|
+
queryFn: QueryFunction<
|
|
69
|
+
TQueryFnData,
|
|
70
|
+
ServiceOperationQueryKey<TSchema, TParams>
|
|
71
|
+
>;
|
|
72
|
+
}
|
|
73
|
+
| {
|
|
74
|
+
/**
|
|
75
|
+
* Custom request function to use for the query
|
|
76
|
+
*/
|
|
77
|
+
requestFn?: RequestFn<TQueryFnData, TError>;
|
|
78
|
+
/**
|
|
79
|
+
* Base URL to use for the request (used in the `queryFn`)
|
|
80
|
+
* @example 'https://api.example.com'
|
|
81
|
+
*/
|
|
82
|
+
baseUrl?: string | undefined;
|
|
83
|
+
queryFn?: never; // Workaround to fix union type error
|
|
84
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type ServiceOperationBaseQueryKey<
|
|
2
|
+
S extends { url: string; method: string },
|
|
3
|
+
Infinite extends boolean,
|
|
4
|
+
T,
|
|
5
|
+
> = [S & { infinite: Infinite }, T];
|
|
6
|
+
|
|
7
|
+
export type ServiceOperationQueryKey<
|
|
8
|
+
S extends { url: string; method: string },
|
|
9
|
+
T,
|
|
10
|
+
> = ServiceOperationBaseQueryKey<S, false, T>;
|
|
11
|
+
|
|
12
|
+
export type ServiceOperationInfiniteQueryKey<
|
|
13
|
+
S extends { url: string; method: string },
|
|
14
|
+
T,
|
|
15
|
+
> = ServiceOperationBaseQueryKey<S, true, T>;
|
|
16
|
+
|
|
17
|
+
export type ServiceOperationMutationKey<
|
|
18
|
+
S extends Record<'url' | 'method', string>,
|
|
19
|
+
T,
|
|
20
|
+
> = NonNullable<T> extends never ? [S] : [S, T];
|