@qualisero/openapi-endpoint 0.6.0 → 0.6.2
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 +2 -2
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/types.d.ts +165 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
# Vue OpenAPI Query
|
|
2
2
|
|
|
3
|
-
[](https://badge.fury.io/js/@qualisero%2Fopenapi-endpoint)
|
|
3
|
+
[](https://badge.fury.io/js/@qualisero%2Fopenapi-endpoint)
|
|
4
4
|
[](https://github.com/qualisero/openapi-endpoint/actions/workflows/ci.yml)
|
|
5
5
|
[](https://opensource.org/licenses/MIT)
|
|
6
6
|
[](https://bundlephobia.com/package/@qualisero/openapi-endpoint)
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
Turns your `openapi.json` into typesafe API composables using Vue Query (TanStack Query): guaranteeing that your frontend and backend share the same contract.
|
|
9
9
|
|
|
10
10
|
## Overview
|
|
11
11
|
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,9 @@ import { EndpointQueryReturn } from './openapi-query';
|
|
|
4
4
|
import { EndpointMutationReturn } from './openapi-mutation';
|
|
5
5
|
import { Operations, GetPathParameters, OpenApiConfig, QQueryOptions, QMutationOptions, IsQueryOperation } from './types';
|
|
6
6
|
export type { OpenApiConfig, OpenApiInstance } from './types';
|
|
7
|
+
/** @internal */
|
|
7
8
|
export { type EndpointQueryReturn, useEndpointQuery } from './openapi-query';
|
|
9
|
+
/** @internal */
|
|
8
10
|
export { type EndpointMutationReturn, useEndpointMutation } from './openapi-mutation';
|
|
9
11
|
/**
|
|
10
12
|
* Default QueryClient instance with pre-configured options.
|
|
@@ -21,11 +23,12 @@ export declare const queryClient: QueryClient;
|
|
|
21
23
|
*
|
|
22
24
|
* @template Ops - The operations type, typically generated from your OpenAPI spec
|
|
23
25
|
* @param config - Configuration object containing operations metadata and axios instance
|
|
24
|
-
* @returns API instance with useQuery, useMutation, useEndpoint, and debug methods
|
|
26
|
+
* @returns {OpenApiInstance<Ops>} API instance with useQuery, useMutation, useEndpoint, and debug methods
|
|
25
27
|
*
|
|
26
28
|
* @example
|
|
27
29
|
* ```typescript
|
|
28
30
|
* import { useOpenApi } from '@qualisero/openapi-endpoint'
|
|
31
|
+
* // See documentation on how to generate types and operations automatically:
|
|
29
32
|
* import { openApiOperations, type OpenApiOperations } from './generated/api-operations'
|
|
30
33
|
* import axios from 'axios'
|
|
31
34
|
*
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,KAAK,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAGjD,OAAO,EAAE,mBAAmB,EAAoB,MAAM,iBAAiB,CAAA;AACvE,OAAO,EAAE,sBAAsB,EAAuB,MAAM,oBAAoB,CAAA;AAChF,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,SAAS,CAAA;AAEhB,YAAY,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAC7D,OAAO,EAAE,KAAK,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAC5E,OAAO,EAAE,KAAK,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAErF;;;;;GAKG;AACH,eAAO,MAAM,WAAW,aAItB,CAAA;AAEF
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MA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AC,CAAC,kBACrF,gBAAgB,CAAC,GAAG,EAAE,EAAE,CAAC,SAAS,IAAI,GAAG,aAAa,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,gBAAgB,CAAC,GAAG,EAAE,EAAE,CAAC,KAC1G,gBAAgB,CAAC,GAAG,EAAE,EAAE,CAAC,SAAS,IAAI,GAAG,mBAAmB,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,sBAAsB,CAAC,GAAG,EAAE,EAAE,CAAC;EAM7G"}
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,9 @@ import { useEndpoint } from './openapi-endpoint';
|
|
|
3
3
|
import { useEndpointQuery } from './openapi-query';
|
|
4
4
|
import { useEndpointMutation } from './openapi-mutation';
|
|
5
5
|
import { getHelpers } from './openapi-helpers';
|
|
6
|
+
/** @internal */
|
|
6
7
|
export { useEndpointQuery } from './openapi-query';
|
|
8
|
+
/** @internal */
|
|
7
9
|
export { useEndpointMutation } from './openapi-mutation';
|
|
8
10
|
/**
|
|
9
11
|
* Default QueryClient instance with pre-configured options.
|
|
@@ -24,11 +26,12 @@ export const queryClient = new QueryClient({
|
|
|
24
26
|
*
|
|
25
27
|
* @template Ops - The operations type, typically generated from your OpenAPI spec
|
|
26
28
|
* @param config - Configuration object containing operations metadata and axios instance
|
|
27
|
-
* @returns API instance with useQuery, useMutation, useEndpoint, and debug methods
|
|
29
|
+
* @returns {OpenApiInstance<Ops>} API instance with useQuery, useMutation, useEndpoint, and debug methods
|
|
28
30
|
*
|
|
29
31
|
* @example
|
|
30
32
|
* ```typescript
|
|
31
33
|
* import { useOpenApi } from '@qualisero/openapi-endpoint'
|
|
34
|
+
* // See documentation on how to generate types and operations automatically:
|
|
32
35
|
* import { openApiOperations, type OpenApiOperations } from './generated/api-operations'
|
|
33
36
|
* import axios from 'axios'
|
|
34
37
|
*
|
package/dist/types.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { UseMutationOptions, type UseQueryOptions, QueryClient } from '@tanstack
|
|
|
3
3
|
import type { MaybeRef, MaybeRefOrGetter } from 'vue';
|
|
4
4
|
import type { EndpointQueryReturn } from './openapi-query';
|
|
5
5
|
import type { EndpointMutationReturn } from './openapi-mutation';
|
|
6
|
+
/** @internal */
|
|
6
7
|
export type { EndpointQueryReturn, EndpointMutationReturn };
|
|
7
8
|
export type OperationId = string;
|
|
8
9
|
export type Operations<Ops> = object & {
|
|
@@ -10,9 +11,46 @@ export type Operations<Ops> = object & {
|
|
|
10
11
|
method: HttpMethod;
|
|
11
12
|
};
|
|
12
13
|
};
|
|
14
|
+
/**
|
|
15
|
+
* Configuration object for initializing the OpenAPI client.
|
|
16
|
+
*
|
|
17
|
+
* This interface defines the required configuration to set up a type-safe OpenAPI client
|
|
18
|
+
* with Vue Query integration. It requires both the operations metadata (typically generated
|
|
19
|
+
* from your OpenAPI specification) and an Axios instance for making HTTP requests.
|
|
20
|
+
*
|
|
21
|
+
* @template Ops - The operations type, typically generated from your OpenAPI specification
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* import { OpenApiConfig } from '@qualisero/openapi-endpoint'
|
|
26
|
+
* import { openApiOperations, type OpenApiOperations } from './generated/api-operations'
|
|
27
|
+
* import axios from 'axios'
|
|
28
|
+
*
|
|
29
|
+
* const config: OpenApiConfig<OpenApiOperations> = {
|
|
30
|
+
* operations: openApiOperations,
|
|
31
|
+
* axios: axios.create({
|
|
32
|
+
* baseURL: 'https://api.example.com',
|
|
33
|
+
* headers: { 'Authorization': 'Bearer token' }
|
|
34
|
+
* }),
|
|
35
|
+
* queryClient: customQueryClient // optional
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
13
39
|
export interface OpenApiConfig<Ops extends Operations<Ops>> {
|
|
40
|
+
/**
|
|
41
|
+
* The operations metadata object, typically generated from your OpenAPI specification.
|
|
42
|
+
* This contains type information and HTTP method details for each API endpoint.
|
|
43
|
+
*/
|
|
14
44
|
operations: Ops;
|
|
45
|
+
/**
|
|
46
|
+
* Axios instance for making HTTP requests.
|
|
47
|
+
* Configure this with your base URL, authentication, and any global request/response interceptors.
|
|
48
|
+
*/
|
|
15
49
|
axios: AxiosInstance;
|
|
50
|
+
/**
|
|
51
|
+
* Optional TanStack Query client instance.
|
|
52
|
+
* If not provided, a default QueryClient with sensible defaults will be used.
|
|
53
|
+
*/
|
|
16
54
|
queryClient?: QueryClient;
|
|
17
55
|
}
|
|
18
56
|
export declare enum HttpMethod {
|
|
@@ -25,6 +63,7 @@ export declare enum HttpMethod {
|
|
|
25
63
|
OPTIONS = "OPTIONS",
|
|
26
64
|
TRACE = "TRACE"
|
|
27
65
|
}
|
|
66
|
+
/** @internal */
|
|
28
67
|
export interface OperationInfo {
|
|
29
68
|
path: string;
|
|
30
69
|
method: HttpMethod;
|
|
@@ -40,6 +79,7 @@ export type GetResponseData<Ops extends Operations<Ops>, Op extends keyof Ops> =
|
|
|
40
79
|
};
|
|
41
80
|
} ? RequireReadonly<Data> : unknown;
|
|
42
81
|
type OmitMaybeRef<T, K extends PropertyKey> = T extends MaybeRef<infer U> ? MaybeRef<Omit<U, K> & Partial<Pick<U, K & keyof U>>> : Omit<T, K> & Partial<Pick<T, K & keyof T>>;
|
|
82
|
+
/** @internal */
|
|
43
83
|
export type QQueryOptions<Ops extends Operations<Ops>, Op extends keyof Ops> = OmitMaybeRef<UseQueryOptions<GetResponseData<Ops, Op>, Error, GetResponseData<Ops, Op>, GetResponseData<Ops, Op>>, 'queryKey' | 'queryFn' | 'enabled'> & {
|
|
44
84
|
enabled?: MaybeRefOrGetter<boolean>;
|
|
45
85
|
onLoad?: (data: GetResponseData<Ops, Op>) => void;
|
|
@@ -54,10 +94,12 @@ type MutationOnSuccessOptions<Ops extends Operations<Ops>> = {
|
|
|
54
94
|
}>;
|
|
55
95
|
refetchEndpoints?: EndpointQueryReturn<Ops, keyof Ops>[];
|
|
56
96
|
};
|
|
97
|
+
/** @internal */
|
|
57
98
|
export type QMutationVars<Ops extends Operations<Ops>, Op extends keyof Ops> = MutationOnSuccessOptions<Ops> & {
|
|
58
99
|
data?: GetRequestBody<Ops, Op>;
|
|
59
100
|
pathParams?: GetPathParameters<Ops, Op>;
|
|
60
101
|
};
|
|
102
|
+
/** @internal */
|
|
61
103
|
export type QMutationOptions<Ops extends Operations<Ops>, Op extends keyof Ops> = OmitMaybeRef<UseMutationOptions<GetResponseData<Ops, Op>, Error, GetRequestBody<Ops, Op> extends never ? QMutationVars<Ops, Op> | void : QMutationVars<Ops, Op>>, 'mutationFn' | 'mutationKey'> & MutationOnSuccessOptions<Ops> & {
|
|
62
104
|
axiosOptions?: AxiosRequestConfig;
|
|
63
105
|
errorHandler?: (error: AxiosError) => GetResponseData<Ops, Op> | void | Promise<GetResponseData<Ops, Op> | void>;
|
|
@@ -91,10 +133,133 @@ type RequireReadonly<T> = {
|
|
|
91
133
|
export type IsQueryOperation<Ops extends Operations<Ops>, Op extends keyof Ops> = Ops[Op] extends {
|
|
92
134
|
method: HttpMethod.GET | HttpMethod.HEAD | HttpMethod.OPTIONS;
|
|
93
135
|
} ? true : false;
|
|
136
|
+
/**
|
|
137
|
+
* Type representing an instance of the OpenAPI client returned by useOpenApi.
|
|
138
|
+
*
|
|
139
|
+
* This interface defines all the methods available on the API client instance,
|
|
140
|
+
* providing type-safe access to queries, mutations, and generic endpoints based
|
|
141
|
+
* on your OpenAPI specification.
|
|
142
|
+
*
|
|
143
|
+
* @template Ops - The operations type from your OpenAPI specification
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```typescript
|
|
147
|
+
* import { OpenApiInstance } from '@qualisero/openapi-endpoint'
|
|
148
|
+
* import { type OpenApiOperations } from './generated/api-operations'
|
|
149
|
+
*
|
|
150
|
+
* // Type your API instance for better IntelliSense
|
|
151
|
+
* const api: OpenApiInstance<OpenApiOperations> = useOpenApi(config)
|
|
152
|
+
*
|
|
153
|
+
* // All methods are now fully typed
|
|
154
|
+
* const query = api.useQuery('getPet', { petId: '123' })
|
|
155
|
+
* const mutation = api.useMutation('createPet')
|
|
156
|
+
* const endpoint = api.useEndpoint('listPets')
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
94
159
|
export type OpenApiInstance<Ops extends Operations<Ops>> = {
|
|
160
|
+
/**
|
|
161
|
+
* Debug utility to inspect operation metadata at runtime.
|
|
162
|
+
*
|
|
163
|
+
* This method helps during development to understand how operations are classified
|
|
164
|
+
* and can be useful for debugging type inference issues.
|
|
165
|
+
*
|
|
166
|
+
* @param operationId - The operation ID to inspect
|
|
167
|
+
* @returns Boolean indicating whether the operation is a query (GET/HEAD/OPTIONS)
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```typescript
|
|
171
|
+
* // Check if an operation is a query or mutation
|
|
172
|
+
* const isQuery = api._debugIsQueryOperation('getPet') // true for GET
|
|
173
|
+
* const isMutation = api._debugIsQueryOperation('createPet') // false for POST
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
95
176
|
_debugIsQueryOperation: <Op extends keyof Ops>(operationId: Op) => IsQueryOperation<Ops, Op>;
|
|
177
|
+
/**
|
|
178
|
+
* Creates a reactive query for GET/HEAD/OPTIONS operations.
|
|
179
|
+
*
|
|
180
|
+
* This method creates a TanStack Query with automatic type inference, caching,
|
|
181
|
+
* and reactive updates. Only accepts operation IDs that correspond to query operations.
|
|
182
|
+
*
|
|
183
|
+
* @template Op - The operation key from your operations type
|
|
184
|
+
* @param operationId - Operation ID (must be a GET/HEAD/OPTIONS operation)
|
|
185
|
+
* @param pathParamsOrOptions - Path parameters (for parameterized routes) or query options
|
|
186
|
+
* @param optionsOrNull - Additional query options when path parameters are provided separately
|
|
187
|
+
* @returns Reactive query result with data, loading state, error handling, etc.
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```typescript
|
|
191
|
+
* // Simple query without parameters
|
|
192
|
+
* const { data: pets, isLoading } = api.useQuery('listPets')
|
|
193
|
+
*
|
|
194
|
+
* // Query with path parameters
|
|
195
|
+
* const { data: pet } = api.useQuery('getPet', { petId: '123' })
|
|
196
|
+
*
|
|
197
|
+
* // Query with options
|
|
198
|
+
* const { data: pets } = api.useQuery('listPets', {
|
|
199
|
+
* enabled: computed(() => shouldLoad.value),
|
|
200
|
+
* onLoad: (data) => console.log('Loaded:', data)
|
|
201
|
+
* })
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
96
204
|
useQuery: <Op extends keyof Ops>(operationId: IsQueryOperation<Ops, Op> extends true ? Op : never, pathParamsOrOptions?: GetPathParameters<Ops, Op> extends Record<string, never> ? QQueryOptions<Ops, Op> : MaybeRefOrGetter<GetPathParameters<Ops, Op> | null | undefined> | QQueryOptions<Ops, Op>, optionsOrNull?: QQueryOptions<Ops, Op>) => EndpointQueryReturn<Ops, Op>;
|
|
205
|
+
/**
|
|
206
|
+
* Creates a reactive mutation for POST/PUT/PATCH/DELETE operations.
|
|
207
|
+
*
|
|
208
|
+
* This method creates a TanStack Query mutation with automatic cache invalidation,
|
|
209
|
+
* optimistic updates, and type-safe request/response handling. Only accepts operation IDs
|
|
210
|
+
* that correspond to mutation operations.
|
|
211
|
+
*
|
|
212
|
+
* @template Op - The operation key from your operations type
|
|
213
|
+
* @param operationId - Operation ID (must be a POST/PUT/PATCH/DELETE operation)
|
|
214
|
+
* @param pathParamsOrOptions - Path parameters (for parameterized routes) or mutation options
|
|
215
|
+
* @param optionsOrNull - Additional mutation options when path parameters are provided separately
|
|
216
|
+
* @returns Reactive mutation result with mutate, mutateAsync, status, etc.
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```typescript
|
|
220
|
+
* // Simple mutation without path parameters
|
|
221
|
+
* const createPet = api.useMutation('createPet', {
|
|
222
|
+
* onSuccess: (data) => console.log('Created:', data),
|
|
223
|
+
* onError: (error) => console.error('Failed:', error)
|
|
224
|
+
* })
|
|
225
|
+
*
|
|
226
|
+
* // Mutation with path parameters
|
|
227
|
+
* const updatePet = api.useMutation('updatePet', { petId: '123' })
|
|
228
|
+
*
|
|
229
|
+
* // Execute mutations
|
|
230
|
+
* await createPet.mutateAsync({ data: { name: 'Fluffy', species: 'cat' } })
|
|
231
|
+
* await updatePet.mutateAsync({ data: { name: 'Updated Name' } })
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
97
234
|
useMutation: <Op extends keyof Ops>(operationId: IsQueryOperation<Ops, Op> extends false ? Op : never, pathParamsOrOptions?: GetPathParameters<Ops, Op> extends Record<string, never> ? QMutationOptions<Ops, Op> : MaybeRefOrGetter<GetPathParameters<Ops, Op> | null | undefined> | QMutationOptions<Ops, Op>, optionsOrNull?: QMutationOptions<Ops, Op>) => EndpointMutationReturn<Ops, Op>;
|
|
235
|
+
/**
|
|
236
|
+
* Generic endpoint composable that automatically detects operation type.
|
|
237
|
+
*
|
|
238
|
+
* This is a universal method that returns either a query or mutation based on the
|
|
239
|
+
* operation's HTTP method. It provides the same functionality as useQuery/useMutation
|
|
240
|
+
* but with automatic type detection, making it useful for generic or dynamic scenarios.
|
|
241
|
+
*
|
|
242
|
+
* @template Op - The operation key from your operations type
|
|
243
|
+
* @param operationId - Any valid operation ID from your API specification
|
|
244
|
+
* @param pathParamsOrOptions - Path parameters (for parameterized routes) or operation-specific options
|
|
245
|
+
* @param optionsOrNull - Additional options when path parameters are provided separately
|
|
246
|
+
* @returns Query result for GET/HEAD/OPTIONS operations, mutation result for others
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* ```typescript
|
|
250
|
+
* // Automatically becomes a query for GET operations
|
|
251
|
+
* const listEndpoint = api.useEndpoint('listPets')
|
|
252
|
+
* // TypeScript infers this has query properties: .data, .isLoading, .refetch(), etc.
|
|
253
|
+
*
|
|
254
|
+
* // Automatically becomes a mutation for POST operations
|
|
255
|
+
* const createEndpoint = api.useEndpoint('createPet')
|
|
256
|
+
* // TypeScript infers this has mutation properties: .mutate(), .mutateAsync(), etc.
|
|
257
|
+
*
|
|
258
|
+
* // Use based on the detected type
|
|
259
|
+
* const petData = listEndpoint.data // Query data
|
|
260
|
+
* await createEndpoint.mutateAsync({ data: { name: 'Fluffy' } }) // Mutation execution
|
|
261
|
+
* ```
|
|
262
|
+
*/
|
|
98
263
|
useEndpoint: <Op extends keyof Ops>(operationId: Op, pathParamsOrOptions?: GetPathParameters<Ops, Op> extends Record<string, never> ? IsQueryOperation<Ops, Op> extends true ? QQueryOptions<Ops, Op> : QMutationOptions<Ops, Op> : MaybeRefOrGetter<GetPathParameters<Ops, Op> | null | undefined> | (IsQueryOperation<Ops, Op> extends true ? QQueryOptions<Ops, Op> : QMutationOptions<Ops, Op>), optionsOrNull?: IsQueryOperation<Ops, Op> extends true ? QQueryOptions<Ops, Op> : QMutationOptions<Ops, Op>) => IsQueryOperation<Ops, Op> extends true ? EndpointQueryReturn<Ops, Op> : EndpointMutationReturn<Ops, Op>;
|
|
99
264
|
};
|
|
100
265
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,UAAU,EAAE,KAAK,kBAAkB,EAAE,MAAM,OAAO,CAAA;AACpF,OAAO,EAAE,kBAAkB,EAAE,KAAK,eAAe,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAC3F,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,KAAK,CAAA;AACrD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAC1D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAA;AAEhE,YAAY,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,CAAA;AAE3D,MAAM,MAAM,WAAW,GAAG,MAAM,CAAA;AAEhC,MAAM,MAAM,UAAU,CAAC,GAAG,IAAI,MAAM,GAAG;KAAG,CAAC,IA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
|
|
1
1
|
{
|
|
2
2
|
"name": "@qualisero/openapi-endpoint",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/qualisero/openapi-endpoint.git"
|
|
@@ -55,9 +55,9 @@
|
|
|
55
55
|
"provenance": true
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
|
-
"@tanstack/vue-query": "
|
|
59
|
-
"axios": "
|
|
60
|
-
"vue": "
|
|
58
|
+
"@tanstack/vue-query": ">=5.90",
|
|
59
|
+
"axios": ">=1.12",
|
|
60
|
+
"vue": ">=3.3"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@eslint/js": "^9.37.0",
|