@openapi-qraft/react 2.15.0-beta.4 → 2.15.0-beta.6
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 +16 -0
- package/dist/cjs/callbacks/useInfiniteQuery.cjs +4 -2
- package/dist/cjs/callbacks/useInfiniteQuery.cjs.map +1 -1
- package/dist/cjs/callbacks/useMutation.cjs +34 -16
- package/dist/cjs/callbacks/useMutation.cjs.map +1 -1
- package/dist/cjs/callbacks/useQuery.cjs +4 -2
- package/dist/cjs/callbacks/useQuery.cjs.map +1 -1
- package/dist/cjs/callbacks/useSuspenseInfiniteQuery.cjs +4 -2
- package/dist/cjs/callbacks/useSuspenseInfiniteQuery.cjs.map +1 -1
- package/dist/cjs/callbacks/useSuspenseQuery.cjs +4 -2
- package/dist/cjs/callbacks/useSuspenseQuery.cjs.map +1 -1
- package/dist/cjs/index.cjs +2 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/lib/useComposeUseQueryOptions.cjs +21 -11
- package/dist/cjs/lib/useComposeUseQueryOptions.cjs.map +1 -1
- package/dist/cjs/qraftAPIClient.cjs.map +1 -1
- package/dist/cjs/qraftReactAPIClient.cjs +36 -0
- package/dist/cjs/qraftReactAPIClient.cjs.map +1 -0
- package/dist/esm/callbacks/useInfiniteQuery.js +4 -2
- package/dist/esm/callbacks/useInfiniteQuery.js.map +1 -1
- package/dist/esm/callbacks/useMutation.js +34 -16
- package/dist/esm/callbacks/useMutation.js.map +1 -1
- package/dist/esm/callbacks/useQuery.js +4 -2
- package/dist/esm/callbacks/useQuery.js.map +1 -1
- package/dist/esm/callbacks/useSuspenseInfiniteQuery.js +4 -2
- package/dist/esm/callbacks/useSuspenseInfiniteQuery.js.map +1 -1
- package/dist/esm/callbacks/useSuspenseQuery.js +4 -2
- package/dist/esm/callbacks/useSuspenseQuery.js.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/useComposeUseQueryOptions.js +21 -11
- package/dist/esm/lib/useComposeUseQueryOptions.js.map +1 -1
- package/dist/esm/qraftAPIClient.js.map +1 -1
- package/dist/esm/qraftReactAPIClient.js +34 -0
- package/dist/esm/qraftReactAPIClient.js.map +1 -0
- package/dist/types/callbacks/useInfiniteQuery.d.ts.map +1 -1
- package/dist/types/callbacks/useMutation.d.ts +5 -2
- package/dist/types/callbacks/useMutation.d.ts.map +1 -1
- package/dist/types/callbacks/useQuery.d.ts.map +1 -1
- package/dist/types/callbacks/useSuspenseInfiniteQuery.d.ts.map +1 -1
- package/dist/types/callbacks/useSuspenseQuery.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/lib/useComposeUseQueryOptions.d.ts.map +1 -1
- package/dist/types/qraftAPIClient.d.ts +4 -22
- package/dist/types/qraftAPIClient.d.ts.map +1 -1
- package/dist/types/qraftReactAPIClient.d.ts +132 -0
- package/dist/types/qraftReactAPIClient.d.ts.map +1 -0
- package/package.json +6 -6
- package/src/callbacks/useInfiniteQuery.ts +9 -3
- package/src/callbacks/useMutation.ts +69 -45
- package/src/callbacks/useQuery.ts +8 -3
- package/src/callbacks/useSuspenseInfiniteQuery.ts +8 -3
- package/src/callbacks/useSuspenseQuery.ts +8 -3
- package/src/index.ts +4 -0
- package/src/lib/useComposeUseQueryOptions.ts +54 -27
- package/src/qraftAPIClient.ts +4 -30
- package/src/qraftReactAPIClient.ts +273 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useComposeUseQueryOptions.d.ts","sourceRoot":"","sources":["../../../src/lib/useComposeUseQueryOptions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useComposeUseQueryOptions.d.ts","sourceRoot":"","sources":["../../../src/lib/useComposeUseQueryOptions.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,WAAW,EAEX,eAAe,EAChB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAQtD;;;GAGG;AACH,wBAAgB,yBAAyB,CACvC,YAAY,EAAE,2BAA2B,EACzC,MAAM,EAAE,eAAe,EACvB,IAAI,EAAE,mBAAmB,EACzB,QAAQ,EAAE,OAAO,GAChB,KAAK,CAqBP;AA8BD,KAAK,mBAAmB,GAAG;IACzB,UAAU,EAAE,OAAO;IACnB,OAAO,CAAC,EAAE,eAAe;IACzB,WAAW,CAAC,EAAE,WAAW;CAC1B,CAAC"}
|
|
@@ -17,24 +17,6 @@ export interface CreateAPIQueryClientOptions extends CreateAPIBasicClientOptions
|
|
|
17
17
|
*/
|
|
18
18
|
export type QraftClientOptions = CreateAPIBasicClientOptions | CreateAPIQueryClientOptions;
|
|
19
19
|
export type CreateAPIClientOptions = CreateAPIBasicClientOptions | CreateAPIBasicQueryClientOptions | CreateAPIQueryClientOptions;
|
|
20
|
-
/**
|
|
21
|
-
* Creates a QueryClient compatible API Client which contains all operations
|
|
22
|
-
* such as `useQuery`, `useMutation`.
|
|
23
|
-
*
|
|
24
|
-
* @example Fetching data with QueryClient
|
|
25
|
-
* ```ts
|
|
26
|
-
* const api = qraftAPIClient(services, callbacks, {
|
|
27
|
-
* requestFn: requestFn,
|
|
28
|
-
* baseUrl: 'https://api.example.com',
|
|
29
|
-
* queryClient: new QueryClient(),
|
|
30
|
-
* });
|
|
31
|
-
*
|
|
32
|
-
* api.service.operation({
|
|
33
|
-
* parameters: { path: { id: 1 } },
|
|
34
|
-
* });
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
export declare function qraftAPIClient<Services extends UnionServiceOperationsDeclaration<Services>, Callbacks extends ServiceMethods>(services: Services, callbacks: Callbacks, options: CreateAPIQueryClientOptions): APIDefaultQueryClientServices<Services>;
|
|
38
20
|
/**
|
|
39
21
|
* Creates a QueryClient compatible API Client which contains all operations
|
|
40
22
|
* such as `useQuery`, `useMutation`.
|
|
@@ -142,15 +124,15 @@ type ServicesDeclaration<Services> = {
|
|
|
142
124
|
[service in keyof Services]: OperationsDeclaration<Services[service]>;
|
|
143
125
|
};
|
|
144
126
|
export type UnionServiceOperationsDeclaration<Services> = ServicesDeclaration<Services> | OperationsDeclaration<Services> | OperationDeclaration;
|
|
145
|
-
type QueryOperationHookCallbacks = Extract<keyof ServiceMethods, 'useInfiniteQuery' | 'useQueries' | 'useQuery' | 'useSuspenseInfiniteQuery' | 'useSuspenseQueries' | 'useSuspenseQuery'>;
|
|
127
|
+
export type QueryOperationHookCallbacks = Extract<keyof ServiceMethods, 'useInfiniteQuery' | 'useQueries' | 'useQuery' | 'useSuspenseInfiniteQuery' | 'useSuspenseQueries' | 'useSuspenseQuery'>;
|
|
146
128
|
type QueryOperationCallbacks = Extract<keyof ServiceMethods, 'fetchInfiniteQuery' | 'fetchQuery' | 'prefetchInfiniteQuery' | 'prefetchQuery' | 'refetchQueries' | 'ensureQueryData' | 'ensureInfiniteQueryData'> | QueryOperationHookCallbacks;
|
|
147
129
|
type QueryOperationStateHookCallbacks = Extract<keyof ServiceMethods, 'useIsFetching'>;
|
|
148
130
|
type QueryOperationStateCallbacks = Extract<keyof ServiceMethods, 'cancelQueries' | 'getInfiniteQueryData' | 'getInfiniteQueryState' | 'getQueriesData' | 'getQueryData' | 'getQueryState' | 'invalidateQueries' | 'isFetching' | 'removeQueries' | 'resetQueries' | 'setInfiniteQueryData' | 'setQueriesData' | 'setQueryData'> | QueryOperationStateHookCallbacks;
|
|
149
|
-
type MutationOperationHookCallbacks = Extract<keyof ServiceMethods, 'useMutation'>;
|
|
131
|
+
export type MutationOperationHookCallbacks = Extract<keyof ServiceMethods, 'useMutation'>;
|
|
150
132
|
type MutationOperationStateHookCallbacks = Extract<keyof ServiceMethods, 'useIsMutating' | 'useMutationState'>;
|
|
151
133
|
type MutationOperationStateCallbacks = Extract<keyof ServiceMethods, 'getMutationCache' | 'isMutating'> | MutationOperationStateHookCallbacks;
|
|
152
134
|
type InvokeOperationCallback = Extract<keyof typeof operationInvokeModule, 'operationInvokeFn'>;
|
|
153
|
-
type UtilityOperationCallbacks = Extract<keyof ServiceMethods, 'getQueryKey' | 'getInfiniteQueryKey' | 'getMutationKey' | QueryOperationStateHookCallbacks | MutationOperationStateHookCallbacks>;
|
|
135
|
+
export type UtilityOperationCallbacks = Extract<keyof ServiceMethods, 'getQueryKey' | 'getInfiniteQueryKey' | 'getMutationKey' | QueryOperationStateHookCallbacks | MutationOperationStateHookCallbacks>;
|
|
154
136
|
type OperationCallbackList = QueryOperationCallbacks | QueryOperationStateCallbacks | MutationOperationHookCallbacks | MutationOperationStateCallbacks | InvokeOperationCallback | UtilityOperationCallbacks;
|
|
155
137
|
export type APIQueryClientServices<Services extends UnionServiceOperationsDeclaration<Services>, Callbacks extends PartialServiceMethods> = ServicesFilteredByCallbacks<Services, Extract<keyof Callbacks, OperationCallbackList>>;
|
|
156
138
|
export type APIDefaultQueryClientServices<Services extends UnionServiceOperationsDeclaration<Services>> = Services extends OperationDeclaration ? Services[QraftServiceOperationsToken] : Services extends OperationsDeclaration<Services> ? {
|
|
@@ -163,7 +145,7 @@ export type APIDefaultQueryClientServices<Services extends UnionServiceOperation
|
|
|
163
145
|
export type APIBasicQueryClientServices<Services extends UnionServiceOperationsDeclaration<Services>, Callbacks extends PartialServiceMethods> = ServicesFilteredByCallbacks<Services, Extract<keyof Callbacks, QueryOperationStateCallbacks | MutationOperationStateCallbacks | UtilityOperationCallbacks>>;
|
|
164
146
|
export type APIBasicClientServices<Services extends UnionServiceOperationsDeclaration<Services>, Callbacks extends PartialServiceMethods> = ServicesFilteredByCallbacks<Services, Extract<keyof Callbacks, InvokeOperationCallback | UtilityOperationCallbacks | QueryOperationHookCallbacks | QueryOperationStateHookCallbacks | MutationOperationStateHookCallbacks | MutationOperationHookCallbacks>>;
|
|
165
147
|
export type APIUtilityClientServices<Services extends UnionServiceOperationsDeclaration<Services>, Callbacks extends Pick<PartialServiceMethods, UtilityOperationCallbacks>> = ServicesFilteredByUtilityCallbacks<Services, Extract<keyof Callbacks, UtilityOperationCallbacks>>;
|
|
166
|
-
type ServicesFilteredByCallbacks<Services extends UnionServiceOperationsDeclaration<Services>, CallbackList extends OperationCallbackList> = Services extends OperationDeclaration ? Pick<Services[QraftServiceOperationsToken], Extract<keyof Services[QraftServiceOperationsToken], CallbackList | 'schema' | 'types'>> & OperationInvokeFn<Services[QraftServiceOperationsToken], CallbackList> : Services extends OperationsDeclaration<Services> ? {
|
|
148
|
+
export type ServicesFilteredByCallbacks<Services extends UnionServiceOperationsDeclaration<Services>, CallbackList extends OperationCallbackList> = Services extends OperationDeclaration ? Pick<Services[QraftServiceOperationsToken], Extract<keyof Services[QraftServiceOperationsToken], CallbackList | 'schema' | 'types'>> & OperationInvokeFn<Services[QraftServiceOperationsToken], CallbackList> : Services extends OperationsDeclaration<Services> ? {
|
|
167
149
|
[operation in keyof Services]: Pick<Services[operation][QraftServiceOperationsToken], Extract<keyof Services[operation][QraftServiceOperationsToken], CallbackList | 'schema' | 'types'>> & OperationInvokeFn<Services[operation][QraftServiceOperationsToken], CallbackList>;
|
|
168
150
|
} : Services extends ServicesDeclaration<Services> ? {
|
|
169
151
|
[serviceName in keyof Services]: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"qraftAPIClient.d.ts","sourceRoot":"","sources":["../../src/qraftAPIClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,2CAA2C,CAAC;AAC7F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,KAAK,SAAS,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,KAAK,qBAAqB,MAAM,kCAAkC,CAAC;AAC/E,OAAO,KAAK,EACV,eAAe,EACf,aAAa,EACb,iBAAiB,EAClB,MAAM,oBAAoB,CAAC;AAG5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ACpD;IAAE,CAAC,GAAG,IAAI,EAAE,IAAI,GAAG,MAAM,CAAA;CAAE,GAC3B,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GACvB,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAE1B,KAAK,kCAAkC,CACrC,QAAQ,SAAS,iCAAiC,CAAC,QAAQ,CAAC,EAC5D,YAAY,SAAS,yBAAyB,IAC5C,QAAQ,SAAS,oBAAoB,GACrC,IAAI,CACF,QAAQ,CAAC,2BAA2B,CAAC,EACrC,OAAO,CACL,MAAM,QAAQ,CAAC,2BAA2B,CAAC,EAC3C,YAAY,GAAG,QAAQ,GAAG,OAAO,CAClC,CACF,GACD,QAAQ,SAAS,qBAAqB,CAAC,QAAQ,CAAC,GAC9C;KACG,SAAS,IAAI,MAAM,QAAQ,GAAG,IAAI,CACjC,QAAQ,CAAC,SAAS,CAAC,CAAC,2BAA2B,CAAC,EAChD,OAAO,CACL,MAAM,QAAQ,CAAC,SAAS,CAAC,CAAC,2BAA2B,CAAC,EACtD,YAAY,GAAG,QAAQ,GAAG,OAAO,CAClC,CACF;CACF,GACD,QAAQ,SAAS,mBAAmB,CAAC,QAAQ,CAAC,GAC5C;KACG,WAAW,IAAI,MAAM,QAAQ,GAAG;SAC9B,SAAS,IAAI,MAAM,QAAQ,CAAC,WAAW,CAAC,GAAG,IAAI,CAC9C,QAAQ,CAAC,WAAW,CAAC,CAAC,SAAS,CAAC,CAAC,2BAA2B,CAAC,EAC7D,OAAO,CACL,MAAM,QAAQ,CAAC,WAAW,CAAC,CAAC,SAAS,CAAC,CAAC,2BAA2B,CAAC,EACnE,YAAY,GAAG,QAAQ,GAAG,OAAO,CAClC,CACF;KACF;CACF,GACD,KAAK,CAAC"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { Context } from 'react';
|
|
2
|
+
import type * as callbacks from './callbacks/index.js';
|
|
3
|
+
import type { APIBasicClientServices, APIBasicQueryClientServices, APIDefaultQueryClientServices, APIQueryClientServices, APIUtilityClientServices, CreateAPIBasicClientOptions, CreateAPIBasicQueryClientOptions, CreateAPIQueryClientOptions, MutationOperationHookCallbacks, QueryOperationHookCallbacks, ServicesFilteredByCallbacks, UnionServiceOperationsDeclaration, UtilityOperationCallbacks } from './qraftAPIClient.js';
|
|
4
|
+
type ServiceMethods = typeof callbacks;
|
|
5
|
+
type PartialServiceMethods = Partial<ServiceMethods>;
|
|
6
|
+
/**
|
|
7
|
+
* Creates a QueryClient compatible API Client which contains all operations
|
|
8
|
+
* such as `useQuery`, `useMutation` with React Context support.
|
|
9
|
+
*
|
|
10
|
+
* @example Fetching data with QueryClient
|
|
11
|
+
* ```ts
|
|
12
|
+
* const api = qraftReactAPIClient(services, callbacks, {
|
|
13
|
+
* requestFn: requestFn,
|
|
14
|
+
* baseUrl: 'https://api.example.com',
|
|
15
|
+
* queryClient: new QueryClient(),
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* api.service.operation({
|
|
19
|
+
* parameters: { path: { id: 1 } },
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function qraftReactAPIClient<Services extends UnionServiceOperationsDeclaration<Services>, Callbacks extends ServiceMethods>(services: Services, callbacks: Callbacks, options: CreateAPIQueryClientOptions | Context<CreateAPIQueryClientOptions | undefined>): APIDefaultQueryClientServices<Services>;
|
|
24
|
+
/**
|
|
25
|
+
* It creates a QueryClient-compatible API client that contains all the hooks
|
|
26
|
+
* (useQuery, useMutation) and utilities for non-context operations,
|
|
27
|
+
* such as `getQueryKey`.
|
|
28
|
+
*
|
|
29
|
+
* @example Fetching data with QueryClient from React Context
|
|
30
|
+
* ```ts
|
|
31
|
+
* const api = qraftReactAPIClient(services, callbacks, context);
|
|
32
|
+
*
|
|
33
|
+
* api.service.operation.useQuery({
|
|
34
|
+
* parameters: { path: { id: 1 } },
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function qraftReactAPIClient<Services extends UnionServiceOperationsDeclaration<Services>, Callbacks extends PartialServiceMethods>(services: Services, callbacks: Callbacks, options: Context<CreateAPIQueryClientOptions | undefined>): APIContextQueryClientServices<Services, Callbacks>;
|
|
39
|
+
/**
|
|
40
|
+
* Creates a QueryClient compatible API Client which contains all operations
|
|
41
|
+
* such as `useQuery`, `useMutation`.
|
|
42
|
+
*
|
|
43
|
+
* @example Fetching data with QueryClient
|
|
44
|
+
* ```ts
|
|
45
|
+
* const api = qraftReactAPIClient(services, callbacks, {
|
|
46
|
+
* requestFn: requestFn,
|
|
47
|
+
* baseUrl: 'https://api.example.com',
|
|
48
|
+
* queryClient: new QueryClient(),
|
|
49
|
+
* });
|
|
50
|
+
*
|
|
51
|
+
* api.service.operation({
|
|
52
|
+
* parameters: { path: { id: 1 } },
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export declare function qraftReactAPIClient<Services extends UnionServiceOperationsDeclaration<Services>, Callbacks extends PartialServiceMethods>(services: Services, callbacks: Callbacks, options: CreateAPIQueryClientOptions): APIQueryClientServices<Services, Callbacks>;
|
|
57
|
+
/**
|
|
58
|
+
* Creates a QueryClient compatible API Client which contains
|
|
59
|
+
* only state management manipulations such as `useIsMutating`,
|
|
60
|
+
* `setQueryData`, `getQueryData` and `invalidateQueries`.
|
|
61
|
+
*
|
|
62
|
+
* @example Invalidating queries with QueryClient
|
|
63
|
+
* ```ts
|
|
64
|
+
* const api = qraftReactAPIClient(services, callbacks, {
|
|
65
|
+
* // an instance of QueryClient shared between all clients
|
|
66
|
+
* queryClient: sharedQueryClient
|
|
67
|
+
* });
|
|
68
|
+
*
|
|
69
|
+
* api.service.operation.invalidateQueries({
|
|
70
|
+
* parameters: { path: { id: 1 } },
|
|
71
|
+
* });
|
|
72
|
+
*/
|
|
73
|
+
export declare function qraftReactAPIClient<Services extends UnionServiceOperationsDeclaration<Services>, Callbacks extends PartialServiceMethods>(services: Services, callbacks: Callbacks, options: CreateAPIBasicQueryClientOptions): APIBasicQueryClientServices<Services, Callbacks>;
|
|
74
|
+
/**
|
|
75
|
+
* Creates a basic API Client which contains all hooks and methods
|
|
76
|
+
* that don't require an explicitly provided QueryClient.
|
|
77
|
+
* Hooks like `useQuery` and `useMutation` will automatically retrieve
|
|
78
|
+
* the QueryClient from the `<QueryClientProvider />` context.
|
|
79
|
+
*
|
|
80
|
+
* @example Fetching data with QueryClient from context
|
|
81
|
+
* ```ts
|
|
82
|
+
* const api = qraftReactAPIClient(services, callbacks, {
|
|
83
|
+
* requestFn: requestFn,
|
|
84
|
+
* baseUrl: 'https://api.example.com',
|
|
85
|
+
* });
|
|
86
|
+
*
|
|
87
|
+
* // QueryClient will be retrieved from React context
|
|
88
|
+
* api.service.operation.useQuery({
|
|
89
|
+
* parameters: { path: { id: 1 } },
|
|
90
|
+
* });
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* @example Fetching data without QueryClient
|
|
94
|
+
* ```ts
|
|
95
|
+
* const api = qraftReactAPIClient(services, callbacks, {
|
|
96
|
+
* requestFn: requestFn,
|
|
97
|
+
* baseUrl: 'https://api.example.com',
|
|
98
|
+
* });
|
|
99
|
+
*
|
|
100
|
+
* api.service.operation({
|
|
101
|
+
* parameters: { path: { id: 1 } },
|
|
102
|
+
* });
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export declare function qraftReactAPIClient<Services extends UnionServiceOperationsDeclaration<Services>, Callbacks extends PartialServiceMethods>(services: Services, callbacks: Callbacks, options: CreateAPIBasicClientOptions): APIBasicClientServices<Services, Callbacks>;
|
|
106
|
+
/**
|
|
107
|
+
* Creates a utility API Client which contains utility operations
|
|
108
|
+
* such as `getQueryKey`, `getInfiniteQueryKey`, `getMutationKey` and state hooks
|
|
109
|
+
* like `useIsFetching` and `useMutationData`.
|
|
110
|
+
*
|
|
111
|
+
* @example Using state hooks
|
|
112
|
+
* ```ts
|
|
113
|
+
* const api = qraftReactAPIClient(services, callbacks);
|
|
114
|
+
*
|
|
115
|
+
* // Check if any query is currently fetching
|
|
116
|
+
* const isFetching = api.service.operation.useIsFetching();
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
119
|
+
* @example Getting query keys with utility client
|
|
120
|
+
* ```ts
|
|
121
|
+
* const api = qraftReactAPIClient(services, callbacks);
|
|
122
|
+
*
|
|
123
|
+
* api.service.operation.getQueryKey({
|
|
124
|
+
* parameters: { path: { id: 1 } },
|
|
125
|
+
* });
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
export declare function qraftReactAPIClient<Services extends UnionServiceOperationsDeclaration<Services>, Callbacks extends Pick<PartialServiceMethods, UtilityOperationCallbacks>>(services: Services, callbacks: Callbacks): APIUtilityClientServices<Services, Callbacks>;
|
|
129
|
+
export type APIContextQueryClientServices<Services extends UnionServiceOperationsDeclaration<Services>, Callbacks extends PartialServiceMethods> = ServicesFilteredByCallbacks<Services, Extract<keyof Callbacks, HookOperationCallbackList>>;
|
|
130
|
+
type HookOperationCallbackList = UtilityOperationCallbacks | QueryOperationHookCallbacks | MutationOperationHookCallbacks;
|
|
131
|
+
export {};
|
|
132
|
+
//# sourceMappingURL=qraftReactAPIClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"qraftReactAPIClient.d.ts","sourceRoot":"","sources":["../../src/qraftReactAPIClient.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AACrC,OAAO,KAAK,KAAK,SAAS,MAAM,sBAAsB,CAAC;AAEvD,OAAO,KAAK,EACV,sBAAsB,EACtB,2BAA2B,EAC3B,6BAA6B,EAC7B,sBAAsB,EACtB,wBAAwB,EACxB,2BAA2B,EAC3B,gCAAgC,EAEhC,2BAA2B,EAC3B,8BAA8B,EAC9B,2BAA2B,EAC3B,2BAA2B,EAC3B,iCAAiC,EACjC,yBAAyB,EAC1B,MAAM,qBAAqB,CAAC;AAI7B,K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,wBAAgB,mBAAmB,CACjC,QAAQ,SAAS,iCAAiC,CAAC,QAAQ,CAAC,EAC5D,SAAS,SAAS,qBAAqB,EAEvC,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,2BAA2B,GACnC,sBAAsB,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;AAE/C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,SAAS,iCAAiC,CAAC,QAAQ,CAAC,EAC5D,SAAS,SAAS,IAAI,CAAC,qBAAqB,EAAE,yBAAyB,CAAC,EAExE,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,SAAS,GACnB,wBAAwB,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;AA+DjD,MAAM,MAAM,6BAA6B,CACvC,QAAQ,SAAS,iCAAiC,CAAC,QAAQ,CAAC,EAC5D,SAAS,SAAS,qBAAqB,IACrC,2BAA2B,CAC7B,QAAQ,EACR,OAAO,CAAC,MAAM,SAAS,EAAE,yBAAyB,CAAC,CACpD,CAAC;AAEF,KAAK,yBAAyB,GAC1B,yBAAyB,GACzB,2BAA2B,GAC3B,8BAA8B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openapi-qraft/react",
|
|
3
|
-
"version": "2.15.0-beta.
|
|
3
|
+
"version": "2.15.0-beta.6",
|
|
4
4
|
"description": "OpenAPI client for React, providing type-safe requests and dynamic TanStack Query React Hooks via a modular, Proxy-based architecture.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "NODE_ENV=production rollup --config rollup.config.mjs && tsc --project tsconfig.build.json --emitDeclarationOnly",
|
|
@@ -15,19 +15,19 @@
|
|
|
15
15
|
},
|
|
16
16
|
"sideEffects": false,
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@openapi-qraft/tanstack-query-react-types": "2.15.0-beta.
|
|
18
|
+
"@openapi-qraft/tanstack-query-react-types": "2.15.0-beta.6"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
21
|
"@tanstack/react-query": "^5.80.0",
|
|
22
22
|
"react": "^18 || ^19"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@openapi-qraft/cli": "2.15.0-beta.
|
|
25
|
+
"@openapi-qraft/cli": "2.15.0-beta.6",
|
|
26
26
|
"@openapi-qraft/eslint-config": "1.0.1",
|
|
27
|
-
"@openapi-qraft/eslint-plugin-query": "2.15.0-beta.
|
|
28
|
-
"@openapi-qraft/openapi-typescript-plugin": "^2.15.0-beta.
|
|
27
|
+
"@openapi-qraft/eslint-plugin-query": "2.15.0-beta.6",
|
|
28
|
+
"@openapi-qraft/openapi-typescript-plugin": "^2.15.0-beta.6",
|
|
29
29
|
"@openapi-qraft/rollup-config": "1.1.1",
|
|
30
|
-
"@openapi-qraft/tanstack-query-react-plugin": "2.15.0-beta.
|
|
30
|
+
"@openapi-qraft/tanstack-query-react-plugin": "2.15.0-beta.6",
|
|
31
31
|
"@openapi-qraft/test-fixtures": "1.2.0-beta.1",
|
|
32
32
|
"@tanstack/react-query": "^5.80.6",
|
|
33
33
|
"@testing-library/dom": "^10.4.0",
|
|
@@ -29,8 +29,14 @@ export const useInfiniteQuery: <
|
|
|
29
29
|
>['useInfiniteQuery']
|
|
30
30
|
>
|
|
31
31
|
) => UseInfiniteQueryResult<TData, TError> = (qraftOptions, schema, args) => {
|
|
32
|
-
|
|
32
|
+
// @ts-expect-error - Too complex to type...
|
|
33
|
+
const [queryOptions, queryClient] = useComposeUseQueryOptions(
|
|
34
|
+
qraftOptions,
|
|
35
|
+
schema,
|
|
33
36
|
// @ts-expect-error - Too complex to type...
|
|
34
|
-
|
|
35
|
-
|
|
37
|
+
args,
|
|
38
|
+
true
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
return useInfiniteQueryBase(queryOptions, queryClient) as never;
|
|
36
42
|
};
|
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
import type {
|
|
4
4
|
OperationSchema,
|
|
5
5
|
ServiceOperationMutationKey,
|
|
6
|
-
|
|
6
|
+
ServiceOperationUseMutationOptions,
|
|
7
7
|
} from '@openapi-qraft/tanstack-query-react-types';
|
|
8
8
|
import type { DefaultError, UseMutationResult } from '@tanstack/react-query';
|
|
9
9
|
import type { CreateAPIQueryClientOptions } from '../qraftAPIClient.js';
|
|
10
10
|
import { useMutation as useMutationBase } from '@tanstack/react-query';
|
|
11
|
+
import { useMemo } from 'react';
|
|
11
12
|
import { composeMutationKey } from '../lib/composeMutationKey.js';
|
|
12
13
|
import { requestFnResponseRejecter } from '../lib/requestFnResponseRejecter.js';
|
|
13
14
|
import { requestFnResponseResolver } from '../lib/requestFnResponseResolver.js';
|
|
@@ -20,15 +21,10 @@ export const useMutation: <
|
|
|
20
21
|
>(
|
|
21
22
|
qraftOptions: CreateAPIQueryClientOptions,
|
|
22
23
|
schema: OperationSchema,
|
|
23
|
-
args:
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
TVariables,
|
|
28
|
-
TData,
|
|
29
|
-
DefaultError
|
|
30
|
-
>['useMutation']
|
|
31
|
-
>
|
|
24
|
+
args: [
|
|
25
|
+
parameters?: unknown,
|
|
26
|
+
options?: ServiceOperationUseMutationOptions<any, any, any, any, any>,
|
|
27
|
+
]
|
|
32
28
|
) => UseMutationResult<TData, TError, TVariables, TContext> = (
|
|
33
29
|
qraftOptions,
|
|
34
30
|
schema,
|
|
@@ -36,52 +32,80 @@ export const useMutation: <
|
|
|
36
32
|
) => {
|
|
37
33
|
const [parameters, options] = args;
|
|
38
34
|
|
|
39
|
-
|
|
40
|
-
parameters &&
|
|
41
|
-
typeof parameters === 'object' &&
|
|
42
|
-
options &&
|
|
43
|
-
'mutationKey' in options
|
|
44
|
-
)
|
|
45
|
-
throw new Error(
|
|
46
|
-
`'useMutation': parameters and 'options.mutationKey' cannot be used together`
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
const mutationKey =
|
|
35
|
+
const optionsMutationKey =
|
|
50
36
|
options && 'mutationKey' in options
|
|
51
37
|
? (options.mutationKey as ServiceOperationMutationKey<
|
|
52
38
|
typeof schema,
|
|
53
39
|
unknown
|
|
54
40
|
>)
|
|
55
|
-
:
|
|
41
|
+
: undefined;
|
|
42
|
+
|
|
43
|
+
if (parameters && typeof parameters === 'object' && optionsMutationKey)
|
|
44
|
+
throw new Error(
|
|
45
|
+
`'useMutation': parameters and 'options.mutationKey' cannot be used together`
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
const mutationKey = useMemo(
|
|
49
|
+
() => optionsMutationKey ?? composeMutationKey(schema, parameters),
|
|
50
|
+
[optionsMutationKey, schema, parameters]
|
|
51
|
+
);
|
|
56
52
|
|
|
57
53
|
return useMutationBase(
|
|
58
54
|
{
|
|
59
55
|
...options,
|
|
60
56
|
mutationKey,
|
|
61
|
-
mutationFn:
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
baseUrl: qraftOptions.baseUrl,
|
|
80
|
-
body,
|
|
81
|
-
} as never)
|
|
82
|
-
.then(requestFnResponseResolver, requestFnResponseRejecter);
|
|
83
|
-
}),
|
|
57
|
+
mutationFn: useMemo(
|
|
58
|
+
() =>
|
|
59
|
+
options?.mutationFn ??
|
|
60
|
+
qraftMutationFn.bind(
|
|
61
|
+
null,
|
|
62
|
+
qraftOptions.requestFn,
|
|
63
|
+
qraftOptions.baseUrl,
|
|
64
|
+
schema,
|
|
65
|
+
parameters
|
|
66
|
+
),
|
|
67
|
+
[
|
|
68
|
+
options?.mutationFn,
|
|
69
|
+
qraftOptions.requestFn,
|
|
70
|
+
qraftOptions.baseUrl,
|
|
71
|
+
schema,
|
|
72
|
+
parameters,
|
|
73
|
+
]
|
|
74
|
+
),
|
|
84
75
|
},
|
|
85
76
|
qraftOptions.queryClient
|
|
86
77
|
) as never;
|
|
87
78
|
};
|
|
79
|
+
|
|
80
|
+
function qraftMutationFn(
|
|
81
|
+
requestFn: CreateAPIQueryClientOptions['requestFn'],
|
|
82
|
+
baseUrl: CreateAPIQueryClientOptions['baseUrl'],
|
|
83
|
+
schema: OperationSchema,
|
|
84
|
+
parameters: unknown,
|
|
85
|
+
mutationVariables:
|
|
86
|
+
| {
|
|
87
|
+
body: unknown;
|
|
88
|
+
}
|
|
89
|
+
| undefined
|
|
90
|
+
) {
|
|
91
|
+
if (parameters) {
|
|
92
|
+
return requestFn(schema, {
|
|
93
|
+
parameters,
|
|
94
|
+
baseUrl,
|
|
95
|
+
body: mutationVariables as never,
|
|
96
|
+
}).then(requestFnResponseResolver, requestFnResponseRejecter);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const mutationParameters =
|
|
100
|
+
typeof mutationVariables === 'object' && mutationVariables !== null
|
|
101
|
+
? { ...mutationVariables }
|
|
102
|
+
: undefined;
|
|
103
|
+
const body = mutationParameters?.body;
|
|
104
|
+
delete mutationParameters?.body;
|
|
105
|
+
|
|
106
|
+
return requestFn(schema, {
|
|
107
|
+
parameters: mutationParameters,
|
|
108
|
+
baseUrl,
|
|
109
|
+
body,
|
|
110
|
+
} as never).then(requestFnResponseResolver, requestFnResponseRejecter);
|
|
111
|
+
}
|
|
@@ -21,8 +21,13 @@ export const useQuery: <TData = unknown, TError = DefaultError>(
|
|
|
21
21
|
>['useQuery']
|
|
22
22
|
>
|
|
23
23
|
) => UseQueryResult<TData, TError> = (qraftOptions, schema, args) => {
|
|
24
|
-
|
|
24
|
+
// @ts-expect-error - Too complex to type
|
|
25
|
+
const [queryOptions, queryClient] = useComposeUseQueryOptions(
|
|
26
|
+
qraftOptions,
|
|
27
|
+
schema,
|
|
25
28
|
// @ts-expect-error - Too complex to type
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
args,
|
|
30
|
+
false
|
|
31
|
+
);
|
|
32
|
+
return useQueryTanstack(queryOptions, queryClient) as never;
|
|
28
33
|
};
|
|
@@ -33,8 +33,13 @@ export const useSuspenseInfiniteQuery: <
|
|
|
33
33
|
schema,
|
|
34
34
|
args
|
|
35
35
|
) => {
|
|
36
|
-
|
|
36
|
+
// @ts-expect-error - Too complex to type
|
|
37
|
+
const [queryOptions, queryClient] = useComposeUseQueryOptions(
|
|
38
|
+
qraftOptions,
|
|
39
|
+
schema,
|
|
37
40
|
// @ts-expect-error - Too complex to type
|
|
38
|
-
|
|
39
|
-
|
|
41
|
+
args,
|
|
42
|
+
true
|
|
43
|
+
);
|
|
44
|
+
return useSuspenseInfiniteQueryTanstack(queryOptions, queryClient) as never;
|
|
40
45
|
};
|
|
@@ -25,8 +25,13 @@ export const useSuspenseQuery: <
|
|
|
25
25
|
>['useSuspenseQuery']
|
|
26
26
|
>
|
|
27
27
|
) => UseQueryResult<TData, TError> = (qraftOptions, schema, args) => {
|
|
28
|
-
|
|
28
|
+
// @ts-expect-error - Too complex to type
|
|
29
|
+
const [queryOptions, queryClient] = useComposeUseQueryOptions(
|
|
30
|
+
qraftOptions,
|
|
31
|
+
schema,
|
|
29
32
|
// @ts-expect-error - Too complex to type
|
|
30
|
-
|
|
31
|
-
|
|
33
|
+
args,
|
|
34
|
+
false
|
|
35
|
+
);
|
|
36
|
+
return useSuspenseQueryTanstack(queryOptions, queryClient) as never;
|
|
32
37
|
};
|
package/src/index.ts
CHANGED
|
@@ -12,6 +12,10 @@ export {
|
|
|
12
12
|
type UnionServiceOperationsDeclaration,
|
|
13
13
|
type QraftClientOptions,
|
|
14
14
|
} from './qraftAPIClient.js';
|
|
15
|
+
export {
|
|
16
|
+
qraftReactAPIClient,
|
|
17
|
+
type APIContextQueryClientServices,
|
|
18
|
+
} from './qraftReactAPIClient.js';
|
|
15
19
|
export {
|
|
16
20
|
requestFn,
|
|
17
21
|
baseRequestFn,
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import type {
|
|
4
|
-
|
|
3
|
+
import type {
|
|
4
|
+
ServiceOperationInfiniteQueryKey,
|
|
5
|
+
ServiceOperationQueryKey,
|
|
6
|
+
} from '@openapi-qraft/tanstack-query-react-types';
|
|
7
|
+
import type {
|
|
8
|
+
QueryClient,
|
|
9
|
+
QueryFunctionContext,
|
|
10
|
+
UseQueryOptions,
|
|
11
|
+
} from '@tanstack/react-query';
|
|
5
12
|
import type { CreateAPIQueryClientOptions } from '../qraftAPIClient.js';
|
|
6
13
|
import type { OperationSchema } from './requestFn.js';
|
|
14
|
+
import { useMemo } from 'react';
|
|
7
15
|
import { composeInfiniteQueryKey } from './composeInfiniteQueryKey.js';
|
|
8
16
|
import { composeQueryKey } from './composeQueryKey.js';
|
|
9
17
|
import { prepareRequestFnParameters } from './prepareRequestFnParameters.js';
|
|
@@ -22,35 +30,54 @@ export function useComposeUseQueryOptions(
|
|
|
22
30
|
): never {
|
|
23
31
|
const [parameters, options] = args;
|
|
24
32
|
|
|
25
|
-
const queryFn =
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
})
|
|
42
|
-
.then(requestFnResponseResolver, requestFnResponseRejecter);
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const queryKey = Array.isArray(parameters)
|
|
46
|
-
? (parameters as ServiceOperationQueryKey<OperationSchema, unknown>)
|
|
47
|
-
: infinite
|
|
48
|
-
? composeInfiniteQueryKey(schema, parameters)
|
|
49
|
-
: composeQueryKey(schema, parameters);
|
|
33
|
+
const queryFn = useMemo(
|
|
34
|
+
() =>
|
|
35
|
+
options?.queryFn ??
|
|
36
|
+
qraftQueryFn.bind(null, qraftOptions.requestFn, qraftOptions.baseUrl),
|
|
37
|
+
[qraftOptions.requestFn, qraftOptions.baseUrl, options?.queryFn]
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
const queryKey = useMemo(
|
|
41
|
+
() =>
|
|
42
|
+
Array.isArray(parameters)
|
|
43
|
+
? (parameters as ServiceOperationQueryKey<OperationSchema, unknown>)
|
|
44
|
+
: infinite
|
|
45
|
+
? composeInfiniteQueryKey(schema, parameters)
|
|
46
|
+
: composeQueryKey(schema, parameters),
|
|
47
|
+
[schema, parameters, infinite]
|
|
48
|
+
);
|
|
50
49
|
|
|
51
50
|
return [{ ...options, queryFn, queryKey }, qraftOptions.queryClient] as never;
|
|
52
51
|
}
|
|
53
52
|
|
|
53
|
+
function qraftQueryFn(
|
|
54
|
+
requestFn: CreateAPIQueryClientOptions['requestFn'],
|
|
55
|
+
baseUrl: CreateAPIQueryClientOptions['baseUrl'],
|
|
56
|
+
{
|
|
57
|
+
queryKey: [schema, queryParams],
|
|
58
|
+
signal,
|
|
59
|
+
meta,
|
|
60
|
+
pageParam,
|
|
61
|
+
}: QueryFunctionContext<
|
|
62
|
+
| ServiceOperationQueryKey<OperationSchema, unknown>
|
|
63
|
+
| ServiceOperationInfiniteQueryKey<OperationSchema, unknown>
|
|
64
|
+
>
|
|
65
|
+
) {
|
|
66
|
+
const { parameters, body } = prepareRequestFnParameters(
|
|
67
|
+
queryParams,
|
|
68
|
+
pageParam,
|
|
69
|
+
Boolean('infinite' in schema && schema.infinite)
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
return requestFn(schema, {
|
|
73
|
+
parameters: parameters as never,
|
|
74
|
+
baseUrl,
|
|
75
|
+
body,
|
|
76
|
+
signal,
|
|
77
|
+
meta,
|
|
78
|
+
}).then(requestFnResponseResolver, requestFnResponseRejecter);
|
|
79
|
+
}
|
|
80
|
+
|
|
54
81
|
type UseQueryOptionsArgs = [
|
|
55
82
|
parameters: unknown,
|
|
56
83
|
options?: UseQueryOptions,
|