@qualisero/openapi-endpoint 0.12.3 → 0.14.0
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 +135 -252
- package/dist/cli.js +1318 -58
- package/dist/index.d.ts +9 -213
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -143
- package/dist/openapi-helpers.d.ts +4 -17
- package/dist/openapi-helpers.d.ts.map +1 -1
- package/dist/openapi-helpers.js +3 -93
- package/dist/openapi-mutation.d.ts +48 -111
- package/dist/openapi-mutation.d.ts.map +1 -1
- package/dist/openapi-mutation.js +75 -104
- package/dist/openapi-query.d.ts +46 -209
- package/dist/openapi-query.d.ts.map +1 -1
- package/dist/openapi-query.js +50 -88
- package/dist/openapi-utils.d.ts +31 -4
- package/dist/openapi-utils.d.ts.map +1 -1
- package/dist/openapi-utils.js +45 -56
- package/dist/types.d.ts +250 -280
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +11 -0
- package/package.json +3 -2
- package/dist/openapi-endpoint.d.ts +0 -18
- package/dist/openapi-endpoint.d.ts.map +0 -1
- package/dist/openapi-endpoint.js +0 -24
- package/dist/types-documentation.d.ts +0 -158
- package/dist/types-documentation.d.ts.map +0 -1
- package/dist/types-documentation.js +0 -9
package/dist/openapi-query.d.ts
CHANGED
|
@@ -1,214 +1,51 @@
|
|
|
1
|
-
import { type ComputedRef, type
|
|
2
|
-
import
|
|
3
|
-
import { type
|
|
4
|
-
export type EndpointQueryReturn<Ops extends Operations<Ops>, Op extends keyof Ops> = ReturnType<typeof useEndpointQuery<Ops, Op>> & {
|
|
5
|
-
onLoad: (callback: (data: GetResponseData<Ops, Op>) => void) => void;
|
|
6
|
-
};
|
|
1
|
+
import { type ComputedRef, type Ref } from 'vue';
|
|
2
|
+
import type { MaybeRefOrGetter } from '@vue/reactivity';
|
|
3
|
+
import { type EndpointConfig, type QueryOptions } from './types';
|
|
7
4
|
/**
|
|
8
|
-
*
|
|
9
|
-
* Ensures the operation is a query (GET/HEAD/OPTIONS) at runtime.
|
|
10
|
-
* Returns a reactive query object, including helpers for query key, enabled state, and an `onLoad` callback.
|
|
5
|
+
* Return type of `useEndpointQuery` (the `useQuery` composable on a generated namespace).
|
|
11
6
|
*
|
|
12
|
-
* @template
|
|
13
|
-
* @
|
|
14
|
-
*
|
|
15
|
-
* @
|
|
16
|
-
* - All properties from {@link UseQueryOptions} (from @tanstack/vue-query)
|
|
17
|
-
* - `enabled`: Whether the query should automatically run (boolean or reactive).
|
|
18
|
-
* - `onLoad`: Callback invoked once when data is loaded (immediately or after fetch).
|
|
19
|
-
* - `axiosOptions`: Custom axios request options (e.g., headers, params).
|
|
20
|
-
* @throws Error if the operation is not a query operation.
|
|
21
|
-
* @returns Query object with strict typing and helpers:
|
|
22
|
-
* - `data`: ComputedRef of response data.
|
|
23
|
-
* - `isEnabled`: ComputedRef indicating if query is enabled.
|
|
24
|
-
* - `queryKey`: ComputedRef of the query key.
|
|
25
|
-
* - `onLoad`: Method to register a callback for when data is loaded.
|
|
7
|
+
* @template TResponse Response data type
|
|
8
|
+
* @template TPathParams Path parameters type (concrete, no undefined)
|
|
9
|
+
*
|
|
10
|
+
* @group Types
|
|
26
11
|
*/
|
|
27
|
-
export
|
|
28
|
-
data
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
errorUpdatedAt: import("vue").Ref<number, number>;
|
|
44
|
-
failureCount: import("vue").Ref<number, number>;
|
|
45
|
-
failureReason: import("vue").Ref<Error | null, Error | null>;
|
|
46
|
-
errorUpdateCount: import("vue").Ref<number, number>;
|
|
47
|
-
isFetched: import("vue").Ref<boolean, boolean>;
|
|
48
|
-
isFetchedAfterMount: import("vue").Ref<boolean, boolean>;
|
|
49
|
-
isFetching: import("vue").Ref<boolean, boolean>;
|
|
50
|
-
isInitialLoading: import("vue").Ref<boolean, boolean>;
|
|
51
|
-
isPaused: import("vue").Ref<boolean, boolean>;
|
|
52
|
-
isRefetching: import("vue").Ref<boolean, boolean>;
|
|
53
|
-
isStale: import("vue").Ref<boolean, boolean>;
|
|
54
|
-
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<GetResponseData<Ops, Op>, Error>>;
|
|
55
|
-
fetchStatus: import("vue").Ref<import("@tanstack/query-core").FetchStatus, import("@tanstack/query-core").FetchStatus>;
|
|
56
|
-
promise: import("vue").Ref<Promise<GetResponseData<Ops, Op>>, Promise<GetResponseData<Ops, Op>>>;
|
|
57
|
-
suspense: () => Promise<import("@tanstack/query-core").QueryObserverResult<GetResponseData<Ops, Op>, Error>>;
|
|
58
|
-
} | {
|
|
59
|
-
data: ComputedRef<GetResponseData<Ops, Op> | undefined>;
|
|
60
|
-
isEnabled: ComputedRef<boolean>;
|
|
61
|
-
queryKey: ComputedRef<(string | import("./types").GetQueryParameters<Ops, Op>)[]>;
|
|
62
|
-
onLoad: (callback: (data: GetResponseData<Ops, Op>) => void) => void;
|
|
63
|
-
pathParams: ComputedRef<GetPathParameters<Ops, Op> | null | undefined>;
|
|
64
|
-
error: import("vue").Ref<null, null>;
|
|
65
|
-
isError: import("vue").Ref<false, false>;
|
|
66
|
-
isPending: import("vue").Ref<false, false>;
|
|
67
|
-
isLoading: import("vue").Ref<false, false>;
|
|
68
|
-
isLoadingError: import("vue").Ref<false, false>;
|
|
69
|
-
isRefetchError: import("vue").Ref<false, false>;
|
|
70
|
-
isSuccess: import("vue").Ref<true, true>;
|
|
71
|
-
isPlaceholderData: import("vue").Ref<false, false>;
|
|
72
|
-
status: import("vue").Ref<"success", "success">;
|
|
73
|
-
dataUpdatedAt: import("vue").Ref<number, number>;
|
|
74
|
-
errorUpdatedAt: import("vue").Ref<number, number>;
|
|
75
|
-
failureCount: import("vue").Ref<number, number>;
|
|
76
|
-
failureReason: import("vue").Ref<Error | null, Error | null>;
|
|
77
|
-
errorUpdateCount: import("vue").Ref<number, number>;
|
|
78
|
-
isFetched: import("vue").Ref<boolean, boolean>;
|
|
79
|
-
isFetchedAfterMount: import("vue").Ref<boolean, boolean>;
|
|
80
|
-
isFetching: import("vue").Ref<boolean, boolean>;
|
|
81
|
-
isInitialLoading: import("vue").Ref<boolean, boolean>;
|
|
82
|
-
isPaused: import("vue").Ref<boolean, boolean>;
|
|
83
|
-
isRefetching: import("vue").Ref<boolean, boolean>;
|
|
84
|
-
isStale: import("vue").Ref<boolean, boolean>;
|
|
85
|
-
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<GetResponseData<Ops, Op>, Error>>;
|
|
86
|
-
fetchStatus: import("vue").Ref<import("@tanstack/query-core").FetchStatus, import("@tanstack/query-core").FetchStatus>;
|
|
87
|
-
promise: import("vue").Ref<Promise<GetResponseData<Ops, Op>>, Promise<GetResponseData<Ops, Op>>>;
|
|
88
|
-
suspense: () => Promise<import("@tanstack/query-core").QueryObserverResult<GetResponseData<Ops, Op>, Error>>;
|
|
89
|
-
} | {
|
|
90
|
-
data: ComputedRef<GetResponseData<Ops, Op> | undefined>;
|
|
91
|
-
isEnabled: ComputedRef<boolean>;
|
|
92
|
-
queryKey: ComputedRef<(string | import("./types").GetQueryParameters<Ops, Op>)[]>;
|
|
93
|
-
onLoad: (callback: (data: GetResponseData<Ops, Op>) => void) => void;
|
|
94
|
-
pathParams: ComputedRef<GetPathParameters<Ops, Op> | null | undefined>;
|
|
95
|
-
error: import("vue").Ref<Error, Error>;
|
|
96
|
-
isError: import("vue").Ref<true, true>;
|
|
97
|
-
isPending: import("vue").Ref<false, false>;
|
|
98
|
-
isLoading: import("vue").Ref<false, false>;
|
|
99
|
-
isLoadingError: import("vue").Ref<true, true>;
|
|
100
|
-
isRefetchError: import("vue").Ref<false, false>;
|
|
101
|
-
isSuccess: import("vue").Ref<false, false>;
|
|
102
|
-
isPlaceholderData: import("vue").Ref<false, false>;
|
|
103
|
-
status: import("vue").Ref<"error", "error">;
|
|
104
|
-
dataUpdatedAt: import("vue").Ref<number, number>;
|
|
105
|
-
errorUpdatedAt: import("vue").Ref<number, number>;
|
|
106
|
-
failureCount: import("vue").Ref<number, number>;
|
|
107
|
-
failureReason: import("vue").Ref<Error | null, Error | null>;
|
|
108
|
-
errorUpdateCount: import("vue").Ref<number, number>;
|
|
109
|
-
isFetched: import("vue").Ref<boolean, boolean>;
|
|
110
|
-
isFetchedAfterMount: import("vue").Ref<boolean, boolean>;
|
|
111
|
-
isFetching: import("vue").Ref<boolean, boolean>;
|
|
112
|
-
isInitialLoading: import("vue").Ref<boolean, boolean>;
|
|
113
|
-
isPaused: import("vue").Ref<boolean, boolean>;
|
|
114
|
-
isRefetching: import("vue").Ref<boolean, boolean>;
|
|
115
|
-
isStale: import("vue").Ref<boolean, boolean>;
|
|
116
|
-
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<GetResponseData<Ops, Op>, Error>>;
|
|
117
|
-
fetchStatus: import("vue").Ref<import("@tanstack/query-core").FetchStatus, import("@tanstack/query-core").FetchStatus>;
|
|
118
|
-
promise: import("vue").Ref<Promise<GetResponseData<Ops, Op>>, Promise<GetResponseData<Ops, Op>>>;
|
|
119
|
-
suspense: () => Promise<import("@tanstack/query-core").QueryObserverResult<GetResponseData<Ops, Op>, Error>>;
|
|
120
|
-
} | {
|
|
121
|
-
data: ComputedRef<GetResponseData<Ops, Op> | undefined>;
|
|
122
|
-
isEnabled: ComputedRef<boolean>;
|
|
123
|
-
queryKey: ComputedRef<(string | import("./types").GetQueryParameters<Ops, Op>)[]>;
|
|
124
|
-
onLoad: (callback: (data: GetResponseData<Ops, Op>) => void) => void;
|
|
125
|
-
pathParams: ComputedRef<GetPathParameters<Ops, Op> | null | undefined>;
|
|
126
|
-
error: import("vue").Ref<null, null>;
|
|
127
|
-
isError: import("vue").Ref<false, false>;
|
|
128
|
-
isPending: import("vue").Ref<true, true>;
|
|
129
|
-
isLoading: import("vue").Ref<true, true>;
|
|
130
|
-
isLoadingError: import("vue").Ref<false, false>;
|
|
131
|
-
isRefetchError: import("vue").Ref<false, false>;
|
|
132
|
-
isSuccess: import("vue").Ref<false, false>;
|
|
133
|
-
isPlaceholderData: import("vue").Ref<false, false>;
|
|
134
|
-
status: import("vue").Ref<"pending", "pending">;
|
|
135
|
-
dataUpdatedAt: import("vue").Ref<number, number>;
|
|
136
|
-
errorUpdatedAt: import("vue").Ref<number, number>;
|
|
137
|
-
failureCount: import("vue").Ref<number, number>;
|
|
138
|
-
failureReason: import("vue").Ref<Error | null, Error | null>;
|
|
139
|
-
errorUpdateCount: import("vue").Ref<number, number>;
|
|
140
|
-
isFetched: import("vue").Ref<boolean, boolean>;
|
|
141
|
-
isFetchedAfterMount: import("vue").Ref<boolean, boolean>;
|
|
142
|
-
isFetching: import("vue").Ref<boolean, boolean>;
|
|
143
|
-
isInitialLoading: import("vue").Ref<boolean, boolean>;
|
|
144
|
-
isPaused: import("vue").Ref<boolean, boolean>;
|
|
145
|
-
isRefetching: import("vue").Ref<boolean, boolean>;
|
|
146
|
-
isStale: import("vue").Ref<boolean, boolean>;
|
|
147
|
-
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<GetResponseData<Ops, Op>, Error>>;
|
|
148
|
-
fetchStatus: import("vue").Ref<import("@tanstack/query-core").FetchStatus, import("@tanstack/query-core").FetchStatus>;
|
|
149
|
-
promise: import("vue").Ref<Promise<GetResponseData<Ops, Op>>, Promise<GetResponseData<Ops, Op>>>;
|
|
150
|
-
suspense: () => Promise<import("@tanstack/query-core").QueryObserverResult<GetResponseData<Ops, Op>, Error>>;
|
|
151
|
-
} | {
|
|
152
|
-
data: ComputedRef<GetResponseData<Ops, Op> | undefined>;
|
|
153
|
-
isEnabled: ComputedRef<boolean>;
|
|
154
|
-
queryKey: ComputedRef<(string | import("./types").GetQueryParameters<Ops, Op>)[]>;
|
|
155
|
-
onLoad: (callback: (data: GetResponseData<Ops, Op>) => void) => void;
|
|
156
|
-
pathParams: ComputedRef<GetPathParameters<Ops, Op> | null | undefined>;
|
|
157
|
-
error: import("vue").Ref<null, null>;
|
|
158
|
-
isError: import("vue").Ref<false, false>;
|
|
159
|
-
isPending: import("vue").Ref<true, true>;
|
|
160
|
-
isLoadingError: import("vue").Ref<false, false>;
|
|
161
|
-
isRefetchError: import("vue").Ref<false, false>;
|
|
162
|
-
isSuccess: import("vue").Ref<false, false>;
|
|
163
|
-
isPlaceholderData: import("vue").Ref<false, false>;
|
|
164
|
-
status: import("vue").Ref<"pending", "pending">;
|
|
165
|
-
dataUpdatedAt: import("vue").Ref<number, number>;
|
|
166
|
-
errorUpdatedAt: import("vue").Ref<number, number>;
|
|
167
|
-
failureCount: import("vue").Ref<number, number>;
|
|
168
|
-
failureReason: import("vue").Ref<Error | null, Error | null>;
|
|
169
|
-
errorUpdateCount: import("vue").Ref<number, number>;
|
|
170
|
-
isFetched: import("vue").Ref<boolean, boolean>;
|
|
171
|
-
isFetchedAfterMount: import("vue").Ref<boolean, boolean>;
|
|
172
|
-
isFetching: import("vue").Ref<boolean, boolean>;
|
|
173
|
-
isLoading: import("vue").Ref<boolean, boolean>;
|
|
174
|
-
isInitialLoading: import("vue").Ref<boolean, boolean>;
|
|
175
|
-
isPaused: import("vue").Ref<boolean, boolean>;
|
|
176
|
-
isRefetching: import("vue").Ref<boolean, boolean>;
|
|
177
|
-
isStale: import("vue").Ref<boolean, boolean>;
|
|
178
|
-
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<GetResponseData<Ops, Op>, Error>>;
|
|
179
|
-
fetchStatus: import("vue").Ref<import("@tanstack/query-core").FetchStatus, import("@tanstack/query-core").FetchStatus>;
|
|
180
|
-
promise: import("vue").Ref<Promise<GetResponseData<Ops, Op>>, Promise<GetResponseData<Ops, Op>>>;
|
|
181
|
-
suspense: () => Promise<import("@tanstack/query-core").QueryObserverResult<GetResponseData<Ops, Op>, Error>>;
|
|
182
|
-
} | {
|
|
183
|
-
data: ComputedRef<GetResponseData<Ops, Op> | undefined>;
|
|
12
|
+
export interface QueryReturn<TResponse, TPathParams extends Record<string, unknown> = Record<string, never>> {
|
|
13
|
+
/** The response data (undefined until loaded). */
|
|
14
|
+
data: ComputedRef<TResponse | undefined>;
|
|
15
|
+
/** The error if the query failed. */
|
|
16
|
+
error: Ref<Error | null>;
|
|
17
|
+
/** True while the query is loading. */
|
|
18
|
+
isPending: Ref<boolean>;
|
|
19
|
+
/** True while loading (alias for isPending). */
|
|
20
|
+
isLoading: Ref<boolean>;
|
|
21
|
+
/** True when the query succeeded. */
|
|
22
|
+
isSuccess: Ref<boolean>;
|
|
23
|
+
/** True when the query failed. */
|
|
24
|
+
isError: Ref<boolean>;
|
|
25
|
+
/** Manually trigger a refetch. */
|
|
26
|
+
refetch: () => Promise<void>;
|
|
27
|
+
/** Whether the query is currently enabled. */
|
|
184
28
|
isEnabled: ComputedRef<boolean>;
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
isRefetching: import("vue").Ref<boolean, boolean>;
|
|
208
|
-
isStale: import("vue").Ref<boolean, boolean>;
|
|
209
|
-
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<GetResponseData<Ops, Op>, Error>>;
|
|
210
|
-
fetchStatus: import("vue").Ref<import("@tanstack/query-core").FetchStatus, import("@tanstack/query-core").FetchStatus>;
|
|
211
|
-
promise: import("vue").Ref<Promise<GetResponseData<Ops, Op>>, Promise<GetResponseData<Ops, Op>>>;
|
|
212
|
-
suspense: () => Promise<import("@tanstack/query-core").QueryObserverResult<GetResponseData<Ops, Op>, Error>>;
|
|
213
|
-
};
|
|
29
|
+
/** The resolved query key. */
|
|
30
|
+
queryKey: ComputedRef<string[] | (string | unknown)[]>;
|
|
31
|
+
/** The resolved path parameters. */
|
|
32
|
+
pathParams: ComputedRef<TPathParams>;
|
|
33
|
+
/** Register a callback for when data loads successfully for the first time. */
|
|
34
|
+
onLoad: (callback: (data: TResponse) => void) => void;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Execute a type-safe query (GET/HEAD/OPTIONS) with automatic caching.
|
|
38
|
+
*
|
|
39
|
+
* This is a low-level primitive — in normal usage it is called by the generated
|
|
40
|
+
* per-operation `useQuery` wrappers in `api-client.ts`, not directly.
|
|
41
|
+
*
|
|
42
|
+
* @template TResponse The response data type
|
|
43
|
+
* @template TPathParams The path parameters type (concrete, required values)
|
|
44
|
+
* @template TQueryParams The query parameters type
|
|
45
|
+
*
|
|
46
|
+
* @param config Endpoint config: axios instance, queryClient, path, method, listPath
|
|
47
|
+
* @param pathParams Path parameters (reactive). Pass `undefined` for operations without path params.
|
|
48
|
+
* @param options Query options (enabled, staleTime, queryParams, onLoad, etc.)
|
|
49
|
+
*/
|
|
50
|
+
export declare function useEndpointQuery<TResponse, TPathParams extends Record<string, unknown> = Record<string, never>, TQueryParams extends Record<string, unknown> = Record<string, never>>(config: EndpointConfig, pathParams?: MaybeRefOrGetter<Record<string, string | number | undefined> | null | undefined>, options?: QueryOptions<TResponse, TQueryParams>): QueryReturn<TResponse, TPathParams>;
|
|
214
51
|
//# sourceMappingURL=openapi-query.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openapi-query.d.ts","sourceRoot":"","sources":["../src/openapi-query.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,KAAK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AAI,EAAE,SAAS,KAAK,IAAI,KAAK,IAAI,CAAA;CACtD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EACT,WAAW,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EACnE,YAAY,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAEpE,MAAM,EAAE,cAAc,EACtB,UAAU,CAAC,EAAE,gBAAgB,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC,EAC7F,OAAO,CAAC,EAAE,YAAY,CAAC,SAAS,EAAE,YAAY,CAAC,GAC9C,WAAW,CAAC,SAAS,EAAE,WAAW,CAAC,CAuGrC"}
|
package/dist/openapi-query.js
CHANGED
|
@@ -1,73 +1,45 @@
|
|
|
1
1
|
import { computed, watch, toValue } from 'vue';
|
|
2
2
|
import { useQuery } from '@tanstack/vue-query';
|
|
3
|
-
import { resolvePath, generateQueryKey, isPathResolved, getParamsOptionsFrom } from './openapi-utils.js';
|
|
4
3
|
import { isAxiosError } from 'axios';
|
|
4
|
+
import { isQueryMethod } from './types.js';
|
|
5
|
+
import { normalizeParamsOptions, useResolvedOperation } from './openapi-utils.js';
|
|
5
6
|
/**
|
|
6
|
-
*
|
|
7
|
-
* Ensures the operation is a query (GET/HEAD/OPTIONS) at runtime.
|
|
8
|
-
* Returns a reactive query object, including helpers for query key, enabled state, and an `onLoad` callback.
|
|
7
|
+
* Execute a type-safe query (GET/HEAD/OPTIONS) with automatic caching.
|
|
9
8
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* @
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* @
|
|
19
|
-
* @
|
|
20
|
-
* - `data`: ComputedRef of response data.
|
|
21
|
-
* - `isEnabled`: ComputedRef indicating if query is enabled.
|
|
22
|
-
* - `queryKey`: ComputedRef of the query key.
|
|
23
|
-
* - `onLoad`: Method to register a callback for when data is loaded.
|
|
9
|
+
* This is a low-level primitive — in normal usage it is called by the generated
|
|
10
|
+
* per-operation `useQuery` wrappers in `api-client.ts`, not directly.
|
|
11
|
+
*
|
|
12
|
+
* @template TResponse The response data type
|
|
13
|
+
* @template TPathParams The path parameters type (concrete, required values)
|
|
14
|
+
* @template TQueryParams The query parameters type
|
|
15
|
+
*
|
|
16
|
+
* @param config Endpoint config: axios instance, queryClient, path, method, listPath
|
|
17
|
+
* @param pathParams Path parameters (reactive). Pass `undefined` for operations without path params.
|
|
18
|
+
* @param options Query options (enabled, staleTime, queryParams, onLoad, etc.)
|
|
24
19
|
*/
|
|
25
|
-
export function useEndpointQuery(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
export function useEndpointQuery(config, pathParams, options) {
|
|
21
|
+
if (!isQueryMethod(config.method)) {
|
|
22
|
+
throw new Error(`Operation at '${config.path}' uses method ${config.method} and cannot be used with useQuery(). ` +
|
|
23
|
+
`Use useMutation() for POST/PUT/PATCH/DELETE operations.`);
|
|
29
24
|
}
|
|
30
|
-
const {
|
|
31
|
-
const {
|
|
32
|
-
const {
|
|
33
|
-
// Make path parameters reactive by ensuring toValue is called inside computed
|
|
34
|
-
// This ensures that when pathParams is a function, it gets called within the computed
|
|
35
|
-
// so Vue can track dependencies of variables referenced inside the function
|
|
36
|
-
const allPathParams = computed(() => {
|
|
37
|
-
const result = toValue(pathParams);
|
|
38
|
-
return result;
|
|
39
|
-
});
|
|
40
|
-
const resolvedPath = computed(() => resolvePath(path, allPathParams.value));
|
|
41
|
-
// Make query parameters reactive
|
|
42
|
-
const allQueryParams = computed(() => {
|
|
43
|
-
const result = toValue(queryParams);
|
|
44
|
-
return result;
|
|
45
|
-
});
|
|
46
|
-
// Include query params in the query key so changes trigger refetch
|
|
47
|
-
const queryKey = computed(() => {
|
|
48
|
-
const baseKey = generateQueryKey(resolvedPath.value);
|
|
49
|
-
const qParams = allQueryParams.value;
|
|
50
|
-
if (qParams && Object.keys(qParams).length > 0) {
|
|
51
|
-
return [...baseKey, qParams];
|
|
52
|
-
}
|
|
53
|
-
return baseKey;
|
|
54
|
-
});
|
|
55
|
-
// Check if path is fully resolved for enabling the query
|
|
25
|
+
const { pathParams: resolvedPathParamsInput, options: resolvedOptions } = normalizeParamsOptions(pathParams, options);
|
|
26
|
+
const { enabled: enabledInit, onLoad: onLoadInit, axiosOptions, errorHandler, queryParams, ...useQueryOptions } = resolvedOptions;
|
|
27
|
+
const { resolvedPath, queryKey, isResolved, queryParams: resolvedQueryParams, pathParams: resolvedPathParams, } = useResolvedOperation(config.path, resolvedPathParamsInput, queryParams);
|
|
56
28
|
const isEnabled = computed(() => {
|
|
57
29
|
const baseEnabled = enabledInit !== undefined ? toValue(enabledInit) : true;
|
|
58
|
-
return baseEnabled &&
|
|
30
|
+
return baseEnabled && isResolved.value;
|
|
59
31
|
});
|
|
60
|
-
const
|
|
61
|
-
queryKey,
|
|
32
|
+
const queryOptions = {
|
|
33
|
+
queryKey: queryKey,
|
|
62
34
|
queryFn: async () => {
|
|
63
35
|
try {
|
|
64
|
-
const response = await
|
|
65
|
-
method: method.toLowerCase(),
|
|
36
|
+
const response = await config.axios({
|
|
37
|
+
method: config.method.toLowerCase(),
|
|
66
38
|
url: resolvedPath.value,
|
|
67
39
|
...axiosOptions,
|
|
68
40
|
params: {
|
|
69
41
|
...(axiosOptions?.params || {}),
|
|
70
|
-
...(
|
|
42
|
+
...(resolvedQueryParams.value || {}),
|
|
71
43
|
},
|
|
72
44
|
});
|
|
73
45
|
return response.data;
|
|
@@ -75,64 +47,54 @@ export function useEndpointQuery(operationId, h, pathParamsOrOptions, optionsOrN
|
|
|
75
47
|
catch (error) {
|
|
76
48
|
if (errorHandler && isAxiosError(error)) {
|
|
77
49
|
const result = await errorHandler(error);
|
|
78
|
-
if (result !== undefined)
|
|
50
|
+
if (result !== undefined)
|
|
79
51
|
return result;
|
|
80
|
-
}
|
|
81
|
-
// If errorHandler returns undefined and doesn't throw,
|
|
82
|
-
// we consider this a "recovered" state and return undefined
|
|
83
|
-
// TanStack Query will handle this as a successful query with no data
|
|
84
52
|
return undefined;
|
|
85
53
|
}
|
|
86
|
-
|
|
87
|
-
throw error;
|
|
88
|
-
}
|
|
54
|
+
throw error;
|
|
89
55
|
}
|
|
90
56
|
},
|
|
91
57
|
enabled: isEnabled,
|
|
92
58
|
staleTime: 1000 * 60,
|
|
93
59
|
retry: (_failureCount, error) => {
|
|
94
|
-
// Don't retry 4xx errors if error is AxiosError
|
|
95
60
|
if (isAxiosError(error) && error.response && error.response.status >= 400 && error.response.status < 500) {
|
|
96
61
|
return false;
|
|
97
62
|
}
|
|
98
|
-
// Retry up to 3 times for other errors
|
|
99
63
|
return _failureCount < 3;
|
|
100
64
|
},
|
|
101
65
|
...useQueryOptions,
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
66
|
+
};
|
|
67
|
+
const query = useQuery(queryOptions, config.queryClient);
|
|
68
|
+
const onLoadCallbacks = new Set();
|
|
69
|
+
if (onLoadInit)
|
|
70
|
+
onLoadCallbacks.add(onLoadInit);
|
|
71
|
+
if (query.data.value !== undefined) {
|
|
72
|
+
onLoadCallbacks.forEach((cb) => cb(query.data.value));
|
|
73
|
+
onLoadCallbacks.clear();
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
const stopWatch = watch(query.data, (newData) => {
|
|
77
|
+
if (newData !== undefined && onLoadCallbacks.size > 0) {
|
|
78
|
+
onLoadCallbacks.forEach((cb) => cb(newData));
|
|
79
|
+
onLoadCallbacks.clear();
|
|
80
|
+
stopWatch();
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
const onLoad = (callback) => {
|
|
107
85
|
if (query.data.value !== undefined) {
|
|
108
86
|
callback(query.data.value);
|
|
109
87
|
}
|
|
110
88
|
else {
|
|
111
|
-
|
|
112
|
-
let hasLoaded = false;
|
|
113
|
-
const stopWatch = watch(query.data, (newData) => {
|
|
114
|
-
if (newData !== undefined && !hasLoaded) {
|
|
115
|
-
hasLoaded = true;
|
|
116
|
-
callback(newData);
|
|
117
|
-
stopWatch(); // Stop watching after first load
|
|
118
|
-
}
|
|
119
|
-
});
|
|
89
|
+
onLoadCallbacks.add(callback);
|
|
120
90
|
}
|
|
121
91
|
};
|
|
122
|
-
// Handle onLoad callback from options
|
|
123
|
-
if (onLoadInit) {
|
|
124
|
-
setupOnLoadHandler(onLoadInit);
|
|
125
|
-
}
|
|
126
|
-
// Create onLoad method
|
|
127
|
-
const onLoad = (callback) => {
|
|
128
|
-
setupOnLoadHandler(callback);
|
|
129
|
-
};
|
|
130
92
|
return {
|
|
131
93
|
...query,
|
|
132
|
-
data: query.data,
|
|
94
|
+
data: computed(() => query.data.value),
|
|
133
95
|
isEnabled,
|
|
134
96
|
queryKey,
|
|
135
97
|
onLoad,
|
|
136
|
-
pathParams:
|
|
98
|
+
pathParams: resolvedPathParams,
|
|
137
99
|
};
|
|
138
100
|
}
|
package/dist/openapi-utils.d.ts
CHANGED
|
@@ -1,10 +1,37 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import
|
|
1
|
+
import { type ComputedRef } from 'vue';
|
|
2
|
+
import type { MaybeRefOrGetter } from '@vue/reactivity';
|
|
3
3
|
export declare function resolvePath(path: string, pathParams?: MaybeRefOrGetter<Record<string, string | number | undefined> | null | undefined>): string;
|
|
4
4
|
export declare function isPathResolved(path: string): boolean;
|
|
5
5
|
export declare function generateQueryKey(resolvedPath: string): string[];
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Return type for useResolvedOperation composable
|
|
8
|
+
*/
|
|
9
|
+
export interface ResolvedOperation<PathParams, QueryParams> {
|
|
10
|
+
/** Computed path parameters (resolved from reactive source) */
|
|
11
|
+
pathParams: ComputedRef<PathParams>;
|
|
12
|
+
/** Computed resolved path with parameters substituted */
|
|
13
|
+
resolvedPath: ComputedRef<string>;
|
|
14
|
+
/** Computed query parameters (resolved from reactive source) */
|
|
15
|
+
queryParams: ComputedRef<QueryParams>;
|
|
16
|
+
/** Computed query key for TanStack Query */
|
|
17
|
+
queryKey: ComputedRef<string[] | (string | QueryParams)[]>;
|
|
18
|
+
/** Whether the path is fully resolved (all params provided) */
|
|
19
|
+
isResolved: ComputedRef<boolean>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Composable for resolving operation paths and parameters.
|
|
23
|
+
* Consolidates the common pattern of computing resolved paths, query keys, and parameters.
|
|
24
|
+
*
|
|
25
|
+
* @param path - The OpenAPI path template (e.g., '/pets/{petId}')
|
|
26
|
+
* @param pathParams - Reactive path parameters
|
|
27
|
+
* @param queryParams - Optional reactive query parameters
|
|
28
|
+
* @param extraPathParams - Optional ref for additional path params (used by mutations)
|
|
29
|
+
*/
|
|
30
|
+
export declare function useResolvedOperation<PathParams extends Record<string, string | number | undefined> = Record<string, never>, QueryParams extends Record<string, unknown> = Record<string, never>>(path: string, pathParams: MaybeRefOrGetter<PathParams | null | undefined>, queryParams?: MaybeRefOrGetter<QueryParams | null | undefined>, extraPathParams?: {
|
|
31
|
+
value: Partial<PathParams>;
|
|
32
|
+
}): ResolvedOperation<PathParams, QueryParams>;
|
|
33
|
+
export declare function normalizeParamsOptions<PathParams extends Record<string, unknown>, Options>(pathParams?: MaybeRefOrGetter<PathParams | null | undefined>, options?: Options): {
|
|
34
|
+
pathParams: MaybeRefOrGetter<PathParams | null | undefined>;
|
|
8
35
|
options: Options;
|
|
9
36
|
};
|
|
10
37
|
//# sourceMappingURL=openapi-utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openapi-utils.d.ts","sourceRoot":"","sources":["../src/openapi-utils.ts"],"names":[],"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