@qualisero/openapi-endpoint 0.3.5 → 0.4.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 +10 -18
- package/dist/cli.js +25 -15
- package/dist/index.d.ts +141 -20
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +126 -0
- package/dist/openapi-endpoint.d.ts +2 -2
- package/dist/openapi-endpoint.d.ts.map +1 -1
- package/dist/openapi-endpoint.js +0 -15
- package/dist/openapi-mutation.d.ts +17 -17
- package/dist/openapi-mutation.d.ts.map +1 -1
- package/dist/openapi-mutation.js +2 -2
- package/dist/openapi-query.d.ts +22 -23
- package/dist/openapi-query.d.ts.map +1 -1
- package/dist/openapi-query.js +5 -5
- package/dist/openapi-utils.d.ts +2 -2
- package/dist/openapi-utils.d.ts.map +1 -1
- package/dist/openapi-utils.js +51 -6
- package/dist/types.d.ts +9 -7
- package/dist/types.d.ts.map +1 -1
- package/package.json +7 -3
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@ npx @qualisero/openapi-endpoint https://api.example.com/openapi.json ./src/api
|
|
|
28
28
|
This will generate two files in your specified output directory:
|
|
29
29
|
|
|
30
30
|
- `openapi-types.ts` - TypeScript type definitions for your API
|
|
31
|
-
- `api-operations.ts` -
|
|
31
|
+
- `api-operations.ts` - Streamlined operation definitions combining metadata and types
|
|
32
32
|
|
|
33
33
|
## Usage
|
|
34
34
|
|
|
@@ -37,46 +37,38 @@ This will generate two files in your specified output directory:
|
|
|
37
37
|
```typescript
|
|
38
38
|
// api/init.ts
|
|
39
39
|
import { useOpenApi } from '@qualisero/openapi-endpoint'
|
|
40
|
-
import { QueryClient } from '@tanstack/vue-query'
|
|
41
40
|
import axios from 'axios'
|
|
42
41
|
|
|
43
|
-
// Import your generated
|
|
44
|
-
import type
|
|
45
|
-
import { OperationId, OPERATION_INFO } from './generated/api-operations'
|
|
42
|
+
// Import your generated operations (includes both metadata and types)
|
|
43
|
+
import { OperationId, openApiOperations, type OpenApiOperations } from './generated/api-operations'
|
|
46
44
|
|
|
47
45
|
// Create axios instance
|
|
48
46
|
const axiosInstance = axios.create({
|
|
49
47
|
baseURL: 'https://api.example.com',
|
|
50
48
|
})
|
|
51
49
|
|
|
52
|
-
//
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
// Initialize the package
|
|
57
|
-
const api = useOpenApi({
|
|
58
|
-
operations: operationInfoDict as OperationsWithInfo,
|
|
50
|
+
// Initialize the package with the streamlined operations
|
|
51
|
+
const api = useOpenApi<OpenApiOperations>({
|
|
52
|
+
operations: openApiOperations,
|
|
59
53
|
axios: axiosInstance,
|
|
60
54
|
})
|
|
61
55
|
|
|
62
56
|
// Export for use in other parts of your application
|
|
63
|
-
export { api }
|
|
57
|
+
export { api, OperationId }
|
|
64
58
|
```
|
|
65
59
|
|
|
66
60
|
### 2. Use the API in your components
|
|
67
61
|
|
|
68
62
|
```typescript
|
|
69
63
|
// In your Vue components
|
|
70
|
-
import { api } from './api/init'
|
|
71
|
-
import { OperationId } from './generated/api-operations'
|
|
64
|
+
import { api, OperationId } from './api/init'
|
|
72
65
|
|
|
73
66
|
// Use queries for GET operations
|
|
74
|
-
const { data: pets, isLoading } = api.useQuery(OperationId.listPets
|
|
67
|
+
const { data: pets, isLoading } = api.useQuery(OperationId.listPets)
|
|
75
68
|
const { data: pet } = api.useQuery(OperationId.getPet, { petId: '123' })
|
|
76
69
|
|
|
77
70
|
// Use mutations for POST/PUT/PATCH/DELETE operations
|
|
78
|
-
const createPetMutation = api.useMutation(OperationId.createPet
|
|
79
|
-
const updatePetMutation = api.useMutation(OperationId.updatePet, { petId: '123' })
|
|
71
|
+
const createPetMutation = api.useMutation(OperationId.createPet)
|
|
80
72
|
|
|
81
73
|
// Execute mutations
|
|
82
74
|
await createPetMutation.mutateAsync({
|
package/dist/cli.js
CHANGED
|
@@ -78,23 +78,24 @@ function parseOperationsFromSpec(openapiContent) {
|
|
|
78
78
|
}
|
|
79
79
|
});
|
|
80
80
|
});
|
|
81
|
-
// Sort operationIds for consistent output
|
|
82
81
|
operationIds.sort();
|
|
83
82
|
return { operationIds, operationInfoMap };
|
|
84
83
|
}
|
|
85
84
|
function generateApiOperationsContent(operationIds, operationInfoMap) {
|
|
86
|
-
// Generate
|
|
87
|
-
const
|
|
88
|
-
// Generate dictionary
|
|
89
|
-
const dictionaryContent = operationIds
|
|
85
|
+
// Generate operationsBase dictionary
|
|
86
|
+
const operationsBaseContent = operationIds
|
|
90
87
|
.map((id) => {
|
|
91
88
|
const info = operationInfoMap[id];
|
|
92
89
|
return ` ${id}: {\n path: '${info.path}',\n method: HttpMethod.${info.method},\n },`;
|
|
93
90
|
})
|
|
94
91
|
.join('\n');
|
|
92
|
+
// Generate OperationId enum content
|
|
93
|
+
const operationIdContent = operationIds.map((id) => ` ${id}: '${id}' as const,`).join('\n');
|
|
95
94
|
return `// Auto-generated from OpenAPI specification
|
|
96
95
|
// Do not edit this file manually
|
|
97
96
|
|
|
97
|
+
import type { operations } from './openapi-types'
|
|
98
|
+
|
|
98
99
|
export enum HttpMethod {
|
|
99
100
|
GET = 'GET',
|
|
100
101
|
POST = 'POST',
|
|
@@ -106,26 +107,35 @@ export enum HttpMethod {
|
|
|
106
107
|
TRACE = 'TRACE',
|
|
107
108
|
}
|
|
108
109
|
|
|
109
|
-
|
|
110
|
-
|
|
110
|
+
// Create the typed structure that combines operations with operation metadata
|
|
111
|
+
// This ensures the debug method returns correct values and all operations are properly typed
|
|
112
|
+
const operationsBase = {
|
|
113
|
+
${operationsBaseContent}
|
|
111
114
|
} as const
|
|
112
115
|
|
|
113
|
-
|
|
116
|
+
// Merge with operations type to maintain OpenAPI type information
|
|
117
|
+
export const openApiOperations = operationsBase as typeof operationsBase & operations
|
|
114
118
|
|
|
115
|
-
export
|
|
116
|
-
|
|
117
|
-
|
|
119
|
+
export type OpenApiOperations = typeof openApiOperations
|
|
120
|
+
|
|
121
|
+
// Dynamically generate OperationId enum from the operations keys
|
|
122
|
+
export const OperationId = {
|
|
123
|
+
${operationIdContent}
|
|
124
|
+
} satisfies Record<keyof typeof operationsBase, keyof typeof operationsBase>
|
|
125
|
+
|
|
126
|
+
// Export the type for TypeScript inference
|
|
127
|
+
export type OperationId = keyof OpenApiOperations
|
|
118
128
|
`;
|
|
119
129
|
}
|
|
120
130
|
async function generateApiOperations(openapiContent, outputDir) {
|
|
121
|
-
console.log('🔨 Generating
|
|
131
|
+
console.log('🔨 Generating openapi-typed-operations.ts file...');
|
|
122
132
|
const { operationIds, operationInfoMap } = parseOperationsFromSpec(openapiContent);
|
|
123
133
|
// Generate TypeScript content
|
|
124
134
|
const tsContent = generateApiOperationsContent(operationIds, operationInfoMap);
|
|
125
135
|
// Write to output file
|
|
126
|
-
const outputPath = path.join(outputDir, '
|
|
136
|
+
const outputPath = path.join(outputDir, 'openapi-typed-operations.ts');
|
|
127
137
|
fs.writeFileSync(outputPath, tsContent);
|
|
128
|
-
console.log(`✅ Generated
|
|
138
|
+
console.log(`✅ Generated openapi-typed-operations file: ${outputPath}`);
|
|
129
139
|
console.log(`📊 Found ${operationIds.length} operations`);
|
|
130
140
|
}
|
|
131
141
|
function printUsage() {
|
|
@@ -142,7 +152,7 @@ Examples:
|
|
|
142
152
|
|
|
143
153
|
This command will generate:
|
|
144
154
|
- openapi-types.ts (TypeScript types from OpenAPI spec)
|
|
145
|
-
-
|
|
155
|
+
- openapi-typed-operations.ts (Operation IDs and info for use with this library)
|
|
146
156
|
`);
|
|
147
157
|
}
|
|
148
158
|
async function main() {
|
package/dist/index.d.ts
CHANGED
|
@@ -2,17 +2,114 @@ import type { MaybeRefOrGetter } from 'vue';
|
|
|
2
2
|
import { QueryClient } from '@tanstack/vue-query';
|
|
3
3
|
import { EndpointQueryReturn } from './openapi-query';
|
|
4
4
|
import { EndpointMutationReturn } from './openapi-mutation';
|
|
5
|
-
import { Operations, GetPathParameters, OpenApiConfig,
|
|
6
|
-
export type { OperationInfo,
|
|
5
|
+
import { Operations, GetPathParameters, OpenApiConfig, QQueryOptions, QMutationOptions, IsQueryOperation } from './types';
|
|
6
|
+
export type { OperationInfo, QQueryOptions, OpenApiConfig, OpenApiInstance } from './types';
|
|
7
7
|
export { type EndpointQueryReturn, useEndpointQuery } from './openapi-query';
|
|
8
8
|
export { type EndpointMutationReturn, useEndpointMutation } from './openapi-mutation';
|
|
9
|
+
/**
|
|
10
|
+
* Default QueryClient instance with pre-configured options.
|
|
11
|
+
*
|
|
12
|
+
* This client is used by default when no custom QueryClient is provided to useOpenApi.
|
|
13
|
+
* It includes sensible defaults like 5-minute stale time for queries.
|
|
14
|
+
*/
|
|
9
15
|
export declare const queryClient: QueryClient;
|
|
16
|
+
/**
|
|
17
|
+
* Creates a type-safe OpenAPI client for Vue applications.
|
|
18
|
+
*
|
|
19
|
+
* This is the main entry point for the library. It provides reactive composables
|
|
20
|
+
* for API operations with full TypeScript type safety based on your OpenAPI specification.
|
|
21
|
+
*
|
|
22
|
+
* @template Ops - The operations type, typically generated from your OpenAPI spec
|
|
23
|
+
* @param config - Configuration object containing operations metadata and axios instance
|
|
24
|
+
* @returns API instance with useQuery, useMutation, useEndpoint, and debug methods
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* import { useOpenApi } from '@qualisero/openapi-endpoint'
|
|
29
|
+
* import { openApiOperations, type OpenApiOperations } from './generated/api-operations'
|
|
30
|
+
* import axios from 'axios'
|
|
31
|
+
*
|
|
32
|
+
* const api = useOpenApi<OpenApiOperations>({
|
|
33
|
+
* operations: openApiOperations,
|
|
34
|
+
* axios: axios.create({ baseURL: 'https://api.example.com' })
|
|
35
|
+
* })
|
|
36
|
+
*
|
|
37
|
+
* // Use in components
|
|
38
|
+
* const { data, isLoading } = api.useQuery('listPets', {})
|
|
39
|
+
* const createPet = api.useMutation('createPet', {})
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
10
42
|
export declare function useOpenApi<Ops extends Operations<Ops>>(config: OpenApiConfig<Ops>): {
|
|
11
|
-
|
|
12
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Debug utility to inspect operation metadata.
|
|
45
|
+
*
|
|
46
|
+
* @param operationId - The operation ID to debug
|
|
47
|
+
* @returns Information about whether the operation is a query operation
|
|
48
|
+
*/
|
|
49
|
+
_debugIsQueryOperation: <Op extends keyof Ops>(operationId: Op) => IsQueryOperation<Ops, Op>;
|
|
50
|
+
/**
|
|
51
|
+
* Creates a reactive query for GET operations.
|
|
52
|
+
*
|
|
53
|
+
* This composable wraps TanStack Query for read-only operations with automatic
|
|
54
|
+
* type inference, caching, and reactive updates.
|
|
55
|
+
*
|
|
56
|
+
* @template Op - The operation key from your operations type
|
|
57
|
+
* @param operationId - Operation ID (must be a GET operation)
|
|
58
|
+
* @param pathParamsOrOptions - Path parameters or query options
|
|
59
|
+
* @param optionsOrNull - Additional query options when path params are provided
|
|
60
|
+
* @returns Reactive query result with data, loading state, error handling, etc.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* // Query without path parameters
|
|
65
|
+
* const { data: pets, isLoading } = api.useQuery(OperationId.listPets, {
|
|
66
|
+
* enabled: true,
|
|
67
|
+
* onLoad: (data) => console.log('Loaded:', data)
|
|
68
|
+
* })
|
|
69
|
+
*
|
|
70
|
+
* // Query with path parameters
|
|
71
|
+
* const { data: pet } = api.useQuery(OperationId.getPet, { petId: '123' }, {
|
|
72
|
+
* enabled: computed(() => Boolean(petId.value))
|
|
73
|
+
* })
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
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>;
|
|
77
|
+
/**
|
|
78
|
+
* Creates a reactive mutation for POST/PUT/PATCH/DELETE operations.
|
|
79
|
+
*
|
|
80
|
+
* This composable wraps TanStack Query's useMutation for data-modifying operations
|
|
81
|
+
* with automatic cache invalidation and optimistic updates.
|
|
82
|
+
*
|
|
83
|
+
* @template Op - The operation key from your operations type
|
|
84
|
+
* @param operationId - Operation ID (must be a mutation operation)
|
|
85
|
+
* @param pathParamsOrOptions - Path parameters or mutation options
|
|
86
|
+
* @param optionsOrNull - Additional mutation options when path params are provided
|
|
87
|
+
* @returns Reactive mutation result with mutate, mutateAsync, status, etc.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* // Mutation without path parameters
|
|
92
|
+
* const createPet = api.useMutation(OperationId.createPet, {
|
|
93
|
+
* onSuccess: (data) => console.log('Created:', data),
|
|
94
|
+
* onError: (error) => console.error('Failed:', error)
|
|
95
|
+
* })
|
|
96
|
+
*
|
|
97
|
+
* // Mutation with path parameters
|
|
98
|
+
* const updatePet = api.useMutation(OperationId.updatePet, { petId: '123' }, {
|
|
99
|
+
* onSuccess: async () => {
|
|
100
|
+
* // Automatically invalidates related queries
|
|
101
|
+
* }
|
|
102
|
+
* })
|
|
103
|
+
*
|
|
104
|
+
* // Execute the mutation
|
|
105
|
+
* await createPet.mutateAsync({ data: { name: 'Fluffy' } })
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
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>) => {
|
|
13
109
|
data: import("vue").ComputedRef<import("./types").GetResponseData<Ops, Op> | undefined>;
|
|
14
110
|
isEnabled: import("vue").ComputedRef<boolean>;
|
|
15
111
|
extraPathParams: import("vue").Ref<GetPathParameters<Ops, Op>, GetPathParameters<Ops, Op>>;
|
|
112
|
+
context: import("vue").Ref<unknown, unknown>;
|
|
16
113
|
error: import("vue").Ref<null, null>;
|
|
17
114
|
isError: import("vue").Ref<false, false>;
|
|
18
115
|
isPending: import("vue").Ref<false, false>;
|
|
@@ -23,15 +120,15 @@ export declare function useOpenApi<Ops extends Operations<Ops>>(config: OpenApiC
|
|
|
23
120
|
isPaused: import("vue").Ref<boolean, boolean>;
|
|
24
121
|
variables: import("vue").Ref<undefined, undefined>;
|
|
25
122
|
isIdle: import("vue").Ref<true, true>;
|
|
26
|
-
context: import("vue").Ref<unknown, unknown>;
|
|
27
123
|
submittedAt: import("vue").Ref<number, number>;
|
|
28
|
-
mutate: (variables: import("./types").
|
|
29
|
-
mutateAsync: import("@tanstack/query-core").MutateFunction<import("./types").GetResponseData<Ops, Op>, Error, import("./types").
|
|
124
|
+
mutate: (variables: import("./types").QMutationVars<Ops, Op>, options?: import("@tanstack/query-core").MutateOptions<import("./types").GetResponseData<Ops, Op>, Error, import("./types").QMutationVars<Ops, Op>, unknown> | undefined) => void;
|
|
125
|
+
mutateAsync: import("@tanstack/query-core").MutateFunction<import("./types").GetResponseData<Ops, Op>, Error, import("./types").QMutationVars<Ops, Op>, unknown>;
|
|
30
126
|
reset: import("@tanstack/query-core").MutationObserverResult<TData, TError, TVariables, TOnMutateResult>["reset"];
|
|
31
127
|
} | {
|
|
32
128
|
data: import("vue").ComputedRef<import("./types").GetResponseData<Ops, Op> | undefined>;
|
|
33
129
|
isEnabled: import("vue").ComputedRef<boolean>;
|
|
34
130
|
extraPathParams: import("vue").Ref<GetPathParameters<Ops, Op>, GetPathParameters<Ops, Op>>;
|
|
131
|
+
context: import("vue").Ref<unknown, unknown>;
|
|
35
132
|
error: import("vue").Ref<null, null>;
|
|
36
133
|
isError: import("vue").Ref<false, false>;
|
|
37
134
|
isPending: import("vue").Ref<true, true>;
|
|
@@ -40,17 +137,17 @@ export declare function useOpenApi<Ops extends Operations<Ops>>(config: OpenApiC
|
|
|
40
137
|
failureCount: import("vue").Ref<number, number>;
|
|
41
138
|
failureReason: import("vue").Ref<Error | null, Error | null>;
|
|
42
139
|
isPaused: import("vue").Ref<boolean, boolean>;
|
|
43
|
-
variables: import("vue").Ref<import("./types").
|
|
140
|
+
variables: import("vue").Ref<import("./types").QMutationVars<Ops, Op>, import("./types").QMutationVars<Ops, Op>>;
|
|
44
141
|
isIdle: import("vue").Ref<false, false>;
|
|
45
|
-
context: import("vue").Ref<unknown, unknown>;
|
|
46
142
|
submittedAt: import("vue").Ref<number, number>;
|
|
47
|
-
mutate: (variables: import("./types").
|
|
48
|
-
mutateAsync: import("@tanstack/query-core").MutateFunction<import("./types").GetResponseData<Ops, Op>, Error, import("./types").
|
|
143
|
+
mutate: (variables: import("./types").QMutationVars<Ops, Op>, options?: import("@tanstack/query-core").MutateOptions<import("./types").GetResponseData<Ops, Op>, Error, import("./types").QMutationVars<Ops, Op>, unknown> | undefined) => void;
|
|
144
|
+
mutateAsync: import("@tanstack/query-core").MutateFunction<import("./types").GetResponseData<Ops, Op>, Error, import("./types").QMutationVars<Ops, Op>, unknown>;
|
|
49
145
|
reset: import("@tanstack/query-core").MutationObserverResult<TData, TError, TVariables, TOnMutateResult>["reset"];
|
|
50
146
|
} | {
|
|
51
147
|
data: import("vue").ComputedRef<import("./types").GetResponseData<Ops, Op> | undefined>;
|
|
52
148
|
isEnabled: import("vue").ComputedRef<boolean>;
|
|
53
149
|
extraPathParams: import("vue").Ref<GetPathParameters<Ops, Op>, GetPathParameters<Ops, Op>>;
|
|
150
|
+
context: import("vue").Ref<unknown, unknown>;
|
|
54
151
|
error: import("vue").Ref<Error, Error>;
|
|
55
152
|
isError: import("vue").Ref<true, true>;
|
|
56
153
|
isPending: import("vue").Ref<false, false>;
|
|
@@ -59,17 +156,17 @@ export declare function useOpenApi<Ops extends Operations<Ops>>(config: OpenApiC
|
|
|
59
156
|
failureCount: import("vue").Ref<number, number>;
|
|
60
157
|
failureReason: import("vue").Ref<Error | null, Error | null>;
|
|
61
158
|
isPaused: import("vue").Ref<boolean, boolean>;
|
|
62
|
-
variables: import("vue").Ref<import("./types").
|
|
159
|
+
variables: import("vue").Ref<import("./types").QMutationVars<Ops, Op>, import("./types").QMutationVars<Ops, Op>>;
|
|
63
160
|
isIdle: import("vue").Ref<false, false>;
|
|
64
|
-
context: import("vue").Ref<unknown, unknown>;
|
|
65
161
|
submittedAt: import("vue").Ref<number, number>;
|
|
66
|
-
mutate: (variables: import("./types").
|
|
67
|
-
mutateAsync: import("@tanstack/query-core").MutateFunction<import("./types").GetResponseData<Ops, Op>, Error, import("./types").
|
|
162
|
+
mutate: (variables: import("./types").QMutationVars<Ops, Op>, options?: import("@tanstack/query-core").MutateOptions<import("./types").GetResponseData<Ops, Op>, Error, import("./types").QMutationVars<Ops, Op>, unknown> | undefined) => void;
|
|
163
|
+
mutateAsync: import("@tanstack/query-core").MutateFunction<import("./types").GetResponseData<Ops, Op>, Error, import("./types").QMutationVars<Ops, Op>, unknown>;
|
|
68
164
|
reset: import("@tanstack/query-core").MutationObserverResult<TData, TError, TVariables, TOnMutateResult>["reset"];
|
|
69
165
|
} | {
|
|
70
166
|
data: import("vue").ComputedRef<import("./types").GetResponseData<Ops, Op> | undefined>;
|
|
71
167
|
isEnabled: import("vue").ComputedRef<boolean>;
|
|
72
168
|
extraPathParams: import("vue").Ref<GetPathParameters<Ops, Op>, GetPathParameters<Ops, Op>>;
|
|
169
|
+
context: import("vue").Ref<unknown, unknown>;
|
|
73
170
|
error: import("vue").Ref<null, null>;
|
|
74
171
|
isError: import("vue").Ref<false, false>;
|
|
75
172
|
isPending: import("vue").Ref<false, false>;
|
|
@@ -78,14 +175,38 @@ export declare function useOpenApi<Ops extends Operations<Ops>>(config: OpenApiC
|
|
|
78
175
|
failureCount: import("vue").Ref<number, number>;
|
|
79
176
|
failureReason: import("vue").Ref<Error | null, Error | null>;
|
|
80
177
|
isPaused: import("vue").Ref<boolean, boolean>;
|
|
81
|
-
variables: import("vue").Ref<import("./types").
|
|
178
|
+
variables: import("vue").Ref<import("./types").QMutationVars<Ops, Op>, import("./types").QMutationVars<Ops, Op>>;
|
|
82
179
|
isIdle: import("vue").Ref<false, false>;
|
|
83
|
-
context: import("vue").Ref<unknown, unknown>;
|
|
84
180
|
submittedAt: import("vue").Ref<number, number>;
|
|
85
|
-
mutate: (variables: import("./types").
|
|
86
|
-
mutateAsync: import("@tanstack/query-core").MutateFunction<import("./types").GetResponseData<Ops, Op>, Error, import("./types").
|
|
181
|
+
mutate: (variables: import("./types").QMutationVars<Ops, Op>, options?: import("@tanstack/query-core").MutateOptions<import("./types").GetResponseData<Ops, Op>, Error, import("./types").QMutationVars<Ops, Op>, unknown> | undefined) => void;
|
|
182
|
+
mutateAsync: import("@tanstack/query-core").MutateFunction<import("./types").GetResponseData<Ops, Op>, Error, import("./types").QMutationVars<Ops, Op>, unknown>;
|
|
87
183
|
reset: import("@tanstack/query-core").MutationObserverResult<TData, TError, TVariables, TOnMutateResult>["reset"];
|
|
88
184
|
};
|
|
89
|
-
|
|
185
|
+
/**
|
|
186
|
+
* Generic endpoint composable that automatically detects operation type.
|
|
187
|
+
*
|
|
188
|
+
* This is a universal composable that returns either a query or mutation based
|
|
189
|
+
* on the operation's HTTP method. Use this when you want unified handling.
|
|
190
|
+
*
|
|
191
|
+
* @template Op - The operation key from your operations type
|
|
192
|
+
* @param operationId - Any operation ID
|
|
193
|
+
* @param pathParamsOrOptions - Path parameters or operation options
|
|
194
|
+
* @param optionsOrNull - Additional options when path params are provided
|
|
195
|
+
* @returns Query result for GET operations, mutation result for others
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```typescript
|
|
199
|
+
* // Automatically becomes a query for GET operations
|
|
200
|
+
* const listEndpoint = api.useEndpoint(OperationId.listPets)
|
|
201
|
+
*
|
|
202
|
+
* // Automatically becomes a mutation for POST operations
|
|
203
|
+
* const createEndpoint = api.useEndpoint(OperationId.createPet)
|
|
204
|
+
*
|
|
205
|
+
* // TypeScript knows the correct return type based on the operation
|
|
206
|
+
* const data = listEndpoint.data // Query data
|
|
207
|
+
* await createEndpoint.mutateAsync({ data: petData }) // Mutation execution
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
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>;
|
|
90
211
|
};
|
|
91
212
|
//# sourceMappingURL=index.d.ts.map
|
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,
|
|
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,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,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
|
@@ -5,21 +5,147 @@ import { useEndpointMutation } from './openapi-mutation';
|
|
|
5
5
|
import { getHelpers } from './openapi-helpers';
|
|
6
6
|
export { useEndpointQuery } from './openapi-query';
|
|
7
7
|
export { useEndpointMutation } from './openapi-mutation';
|
|
8
|
+
/**
|
|
9
|
+
* Default QueryClient instance with pre-configured options.
|
|
10
|
+
*
|
|
11
|
+
* This client is used by default when no custom QueryClient is provided to useOpenApi.
|
|
12
|
+
* It includes sensible defaults like 5-minute stale time for queries.
|
|
13
|
+
*/
|
|
8
14
|
export const queryClient = new QueryClient({
|
|
9
15
|
defaultOptions: {
|
|
10
16
|
queries: { staleTime: 1000 * 60 * 5 },
|
|
11
17
|
},
|
|
12
18
|
});
|
|
19
|
+
/**
|
|
20
|
+
* Creates a type-safe OpenAPI client for Vue applications.
|
|
21
|
+
*
|
|
22
|
+
* This is the main entry point for the library. It provides reactive composables
|
|
23
|
+
* for API operations with full TypeScript type safety based on your OpenAPI specification.
|
|
24
|
+
*
|
|
25
|
+
* @template Ops - The operations type, typically generated from your OpenAPI spec
|
|
26
|
+
* @param config - Configuration object containing operations metadata and axios instance
|
|
27
|
+
* @returns API instance with useQuery, useMutation, useEndpoint, and debug methods
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* import { useOpenApi } from '@qualisero/openapi-endpoint'
|
|
32
|
+
* import { openApiOperations, type OpenApiOperations } from './generated/api-operations'
|
|
33
|
+
* import axios from 'axios'
|
|
34
|
+
*
|
|
35
|
+
* const api = useOpenApi<OpenApiOperations>({
|
|
36
|
+
* operations: openApiOperations,
|
|
37
|
+
* axios: axios.create({ baseURL: 'https://api.example.com' })
|
|
38
|
+
* })
|
|
39
|
+
*
|
|
40
|
+
* // Use in components
|
|
41
|
+
* const { data, isLoading } = api.useQuery('listPets', {})
|
|
42
|
+
* const createPet = api.useMutation('createPet', {})
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
13
45
|
export function useOpenApi(config) {
|
|
14
46
|
return {
|
|
47
|
+
/**
|
|
48
|
+
* Debug utility to inspect operation metadata.
|
|
49
|
+
*
|
|
50
|
+
* @param operationId - The operation ID to debug
|
|
51
|
+
* @returns Information about whether the operation is a query operation
|
|
52
|
+
*/
|
|
53
|
+
_debugIsQueryOperation: function (operationId) {
|
|
54
|
+
const helpers = getHelpers(config);
|
|
55
|
+
const info = helpers.getOperationInfo(operationId);
|
|
56
|
+
console.log('Operation Info:', info);
|
|
57
|
+
return {};
|
|
58
|
+
},
|
|
59
|
+
/**
|
|
60
|
+
* Creates a reactive query for GET operations.
|
|
61
|
+
*
|
|
62
|
+
* This composable wraps TanStack Query for read-only operations with automatic
|
|
63
|
+
* type inference, caching, and reactive updates.
|
|
64
|
+
*
|
|
65
|
+
* @template Op - The operation key from your operations type
|
|
66
|
+
* @param operationId - Operation ID (must be a GET operation)
|
|
67
|
+
* @param pathParamsOrOptions - Path parameters or query options
|
|
68
|
+
* @param optionsOrNull - Additional query options when path params are provided
|
|
69
|
+
* @returns Reactive query result with data, loading state, error handling, etc.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* // Query without path parameters
|
|
74
|
+
* const { data: pets, isLoading } = api.useQuery(OperationId.listPets, {
|
|
75
|
+
* enabled: true,
|
|
76
|
+
* onLoad: (data) => console.log('Loaded:', data)
|
|
77
|
+
* })
|
|
78
|
+
*
|
|
79
|
+
* // Query with path parameters
|
|
80
|
+
* const { data: pet } = api.useQuery(OperationId.getPet, { petId: '123' }, {
|
|
81
|
+
* enabled: computed(() => Boolean(petId.value))
|
|
82
|
+
* })
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
15
85
|
useQuery: function (operationId, pathParamsOrOptions, optionsOrNull) {
|
|
16
86
|
const helpers = getHelpers(config);
|
|
17
87
|
return useEndpointQuery(operationId, helpers, pathParamsOrOptions, optionsOrNull);
|
|
18
88
|
},
|
|
89
|
+
/**
|
|
90
|
+
* Creates a reactive mutation for POST/PUT/PATCH/DELETE operations.
|
|
91
|
+
*
|
|
92
|
+
* This composable wraps TanStack Query's useMutation for data-modifying operations
|
|
93
|
+
* with automatic cache invalidation and optimistic updates.
|
|
94
|
+
*
|
|
95
|
+
* @template Op - The operation key from your operations type
|
|
96
|
+
* @param operationId - Operation ID (must be a mutation operation)
|
|
97
|
+
* @param pathParamsOrOptions - Path parameters or mutation options
|
|
98
|
+
* @param optionsOrNull - Additional mutation options when path params are provided
|
|
99
|
+
* @returns Reactive mutation result with mutate, mutateAsync, status, etc.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* // Mutation without path parameters
|
|
104
|
+
* const createPet = api.useMutation(OperationId.createPet, {
|
|
105
|
+
* onSuccess: (data) => console.log('Created:', data),
|
|
106
|
+
* onError: (error) => console.error('Failed:', error)
|
|
107
|
+
* })
|
|
108
|
+
*
|
|
109
|
+
* // Mutation with path parameters
|
|
110
|
+
* const updatePet = api.useMutation(OperationId.updatePet, { petId: '123' }, {
|
|
111
|
+
* onSuccess: async () => {
|
|
112
|
+
* // Automatically invalidates related queries
|
|
113
|
+
* }
|
|
114
|
+
* })
|
|
115
|
+
*
|
|
116
|
+
* // Execute the mutation
|
|
117
|
+
* await createPet.mutateAsync({ data: { name: 'Fluffy' } })
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
19
120
|
useMutation: function (operationId, pathParamsOrOptions, optionsOrNull) {
|
|
20
121
|
const helpers = getHelpers(config);
|
|
21
122
|
return useEndpointMutation(operationId, helpers, pathParamsOrOptions, optionsOrNull);
|
|
22
123
|
},
|
|
124
|
+
/**
|
|
125
|
+
* Generic endpoint composable that automatically detects operation type.
|
|
126
|
+
*
|
|
127
|
+
* This is a universal composable that returns either a query or mutation based
|
|
128
|
+
* on the operation's HTTP method. Use this when you want unified handling.
|
|
129
|
+
*
|
|
130
|
+
* @template Op - The operation key from your operations type
|
|
131
|
+
* @param operationId - Any operation ID
|
|
132
|
+
* @param pathParamsOrOptions - Path parameters or operation options
|
|
133
|
+
* @param optionsOrNull - Additional options when path params are provided
|
|
134
|
+
* @returns Query result for GET operations, mutation result for others
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* // Automatically becomes a query for GET operations
|
|
139
|
+
* const listEndpoint = api.useEndpoint(OperationId.listPets)
|
|
140
|
+
*
|
|
141
|
+
* // Automatically becomes a mutation for POST operations
|
|
142
|
+
* const createEndpoint = api.useEndpoint(OperationId.createPet)
|
|
143
|
+
*
|
|
144
|
+
* // TypeScript knows the correct return type based on the operation
|
|
145
|
+
* const data = listEndpoint.data // Query data
|
|
146
|
+
* await createEndpoint.mutateAsync({ data: petData }) // Mutation execution
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
23
149
|
useEndpoint: function (operationId, pathParamsOrOptions, optionsOrNull) {
|
|
24
150
|
const helpers = getHelpers(config);
|
|
25
151
|
return useEndpoint(operationId, helpers, pathParamsOrOptions, optionsOrNull);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type MaybeRefOrGetter } from 'vue';
|
|
2
2
|
import { EndpointQueryReturn } from './openapi-query';
|
|
3
3
|
import { EndpointMutationReturn } from './openapi-mutation';
|
|
4
|
-
import type { GetPathParameters,
|
|
4
|
+
import type { GetPathParameters, QQueryOptions, QMutationOptions, Operations, IsQueryOperation } from './types';
|
|
5
5
|
import { getHelpers } from './openapi-helpers';
|
|
6
6
|
/**
|
|
7
7
|
* Composable for performing a strictly typed OpenAPI operation (query or mutation) using Vue Query.
|
|
@@ -14,5 +14,5 @@ import { getHelpers } from './openapi-helpers';
|
|
|
14
14
|
* @param optionsOrNull Optional query or mutation options, including Vue Query options.
|
|
15
15
|
* @returns Query or mutation object with strict typing and helpers.
|
|
16
16
|
*/
|
|
17
|
-
export declare function useEndpoint<Ops extends Operations<Ops>, Op extends keyof Ops>(operationId: Op, helpers: ReturnType<typeof getHelpers<Ops, Op>>, pathParamsOrOptions?: MaybeRefOrGetter<GetPathParameters<Ops, Op> | null | undefined> | (IsQueryOperation<Ops, Op> extends true ?
|
|
17
|
+
export declare function useEndpoint<Ops extends Operations<Ops>, Op extends keyof Ops>(operationId: Op, helpers: ReturnType<typeof getHelpers<Ops, Op>>, pathParamsOrOptions?: 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>;
|
|
18
18
|
//# sourceMappingURL=openapi-endpoint.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openapi-endpoint.d.ts","sourceRoot":"","sources":["../src/openapi-endpoint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,KAAK,CAAA;AAC3C,OAAO,EAAE,mBAAmB,EAAoB,MAAM,iBAAiB,CAAA;AACvE,OAAO,EAAE,sBAAsB,EAAuB,MAAM,oBAAoB,CAAA;AAChF,OAAO,KAAK,EAEV,iBAAiB,EACjB,
|
|
1
|
+
{"version":3,"file":"openapi-endpoint.d.ts","sourceRoot":"","sources":["../src/openapi-endpoint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,KAAK,CAAA;AAC3C,OAAO,EAAE,mBAAmB,EAAoB,MAAM,iBAAiB,CAAA;AACvE,OAAO,EAAE,sBAAsB,EAAuB,MAAM,oBAAoB,CAAA;AAChF,OAAO,KAAK,EAEV,iBAAiB,EACjB,aAAa,EACb,gBAAgB,EAChB,UAAU,EACV,gBAAgB,EACjB,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAE9C;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,GAAG,SAAS,UAAU,CAAC,GAAG,CAAC,EAAE,EAAE,SAAS,MAAM,GAAG,EAC3E,WAAW,EAAE,EAAE,EACf,OAAO,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,EAC/C,mBAAmB,CAAC,EAChB,gBAAgB,CAAC,iBAAiB,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC,GAC/D,CAAC,gBAAgB,CAAC,GAAG,EAAE,EAAE,CAAC,SAAS,IAAI,GAAG,aAAa,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,gBAAgB,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,EACjG,aAAa,CAAC,EAAE,gBAAgB,CAAC,GAAG,EAAE,EAAE,CAAC,SAAS,IAAI,GAAG,aAAa,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,gBAAgB,CAAC,GAAG,EAAE,EAAE,CAAC,GAC1G,gBAAgB,CAAC,GAAG,EAAE,EAAE,CAAC,SAAS,IAAI,GAAG,mBAAmB,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,sBAAsB,CAAC,GAAG,EAAE,EAAE,CAAC,CAoBzG"}
|
package/dist/openapi-endpoint.js
CHANGED
|
@@ -1,20 +1,5 @@
|
|
|
1
1
|
import { useEndpointQuery } from './openapi-query';
|
|
2
2
|
import { useEndpointMutation } from './openapi-mutation';
|
|
3
|
-
// NOTE: rather than using conditional overloads, we are adjusting the signature in the calling code based on IsQueryOperation
|
|
4
|
-
// Conditional overload: if operation is a query, use QueryOptions and return QueryReturn
|
|
5
|
-
// export function useEndpoint<Ops extends Operations<Ops>, Op extends keyof Ops>(
|
|
6
|
-
// config: OpenApiConfig<Ops>,
|
|
7
|
-
// operationId: IsQueryOperation<Ops, Op> extends true ? Op : never,
|
|
8
|
-
// pathParamsOrOptions?: MaybeRefOrGetter<GetPathParameters<Ops, Op> | null | undefined> | QueryOptions<Ops, Op>,
|
|
9
|
-
// optionsOrNull?: QueryOptions<Ops, Op>
|
|
10
|
-
// ): EndpointQueryReturn<Ops, Op>
|
|
11
|
-
// // Conditional overload: if operation is a mutation, use MutationOptions and return MutationReturn
|
|
12
|
-
// export function useEndpoint<Ops extends Operations<Ops>, Op extends keyof Ops>(
|
|
13
|
-
// config: OpenApiConfig<Ops>,
|
|
14
|
-
// operationId: IsQueryOperation<Ops, Op> extends false ? Op : never,
|
|
15
|
-
// pathParamsOrOptions?: MaybeRefOrGetter<GetPathParameters<Ops, Op> | null | undefined> | MutationOptions<Ops, Op>,
|
|
16
|
-
// optionsOrNull?: MutationOptions<Ops, Op>
|
|
17
|
-
// ): EndpointMutationReturn<Ops, Op>
|
|
18
3
|
/**
|
|
19
4
|
* Composable for performing a strictly typed OpenAPI operation (query or mutation) using Vue Query.
|
|
20
5
|
* Automatically detects whether the operation is a query or mutation and delegates to the appropriate composable.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ComputedRef, type Ref, type MaybeRefOrGetter } from 'vue';
|
|
2
|
-
import { type GetPathParameters, type
|
|
2
|
+
import { type GetPathParameters, type QMutationVars, type GetResponseData, type QMutationOptions, Operations } from './types';
|
|
3
3
|
import { getHelpers } from './openapi-helpers';
|
|
4
4
|
export type EndpointMutationReturn<Ops extends Operations<Ops>, Op extends keyof Ops> = ReturnType<typeof useEndpointMutation<Ops, Op>>;
|
|
5
5
|
/**
|
|
@@ -32,10 +32,11 @@ export type EndpointMutationReturn<Ops extends Operations<Ops>, Op extends keyof
|
|
|
32
32
|
* - All other properties and methods from the underlying Vue Query mutation object.
|
|
33
33
|
*/
|
|
34
34
|
export declare function useEndpointMutation<Ops extends Operations<Ops>, Op extends keyof Ops>(operationId: Op, h: ReturnType<typeof getHelpers<Ops, Op>>, // helpers
|
|
35
|
-
pathParamsOrOptions?: MaybeRefOrGetter<GetPathParameters<Ops, Op> | null | undefined> |
|
|
35
|
+
pathParamsOrOptions?: MaybeRefOrGetter<GetPathParameters<Ops, Op> | null | undefined> | QMutationOptions<Ops, Op>, optionsOrNull?: QMutationOptions<Ops, Op>): {
|
|
36
36
|
data: ComputedRef<GetResponseData<Ops, Op> | undefined>;
|
|
37
37
|
isEnabled: ComputedRef<boolean>;
|
|
38
38
|
extraPathParams: Ref<GetPathParameters<Ops, Op>, GetPathParameters<Ops, Op>>;
|
|
39
|
+
context: Ref<unknown, unknown>;
|
|
39
40
|
error: Ref<null, null>;
|
|
40
41
|
isError: Ref<false, false>;
|
|
41
42
|
isPending: Ref<false, false>;
|
|
@@ -46,15 +47,15 @@ pathParamsOrOptions?: MaybeRefOrGetter<GetPathParameters<Ops, Op> | null | undef
|
|
|
46
47
|
isPaused: Ref<boolean, boolean>;
|
|
47
48
|
variables: Ref<undefined, undefined>;
|
|
48
49
|
isIdle: Ref<true, true>;
|
|
49
|
-
context: Ref<unknown, unknown>;
|
|
50
50
|
submittedAt: Ref<number, number>;
|
|
51
|
-
mutate: (variables:
|
|
52
|
-
mutateAsync: import("@tanstack/query-core").MutateFunction<GetResponseData<Ops, Op>, Error,
|
|
51
|
+
mutate: (variables: QMutationVars<Ops, Op>, options?: import("@tanstack/query-core").MutateOptions<GetResponseData<Ops, Op>, Error, QMutationVars<Ops, Op>, unknown> | undefined) => void;
|
|
52
|
+
mutateAsync: import("@tanstack/query-core").MutateFunction<GetResponseData<Ops, Op>, Error, QMutationVars<Ops, Op>, unknown>;
|
|
53
53
|
reset: import("@tanstack/query-core").MutationObserverResult<TData, TError, TVariables, TOnMutateResult>["reset"];
|
|
54
54
|
} | {
|
|
55
55
|
data: ComputedRef<GetResponseData<Ops, Op> | undefined>;
|
|
56
56
|
isEnabled: ComputedRef<boolean>;
|
|
57
57
|
extraPathParams: Ref<GetPathParameters<Ops, Op>, GetPathParameters<Ops, Op>>;
|
|
58
|
+
context: Ref<unknown, unknown>;
|
|
58
59
|
error: Ref<null, null>;
|
|
59
60
|
isError: Ref<false, false>;
|
|
60
61
|
isPending: Ref<true, true>;
|
|
@@ -63,17 +64,17 @@ pathParamsOrOptions?: MaybeRefOrGetter<GetPathParameters<Ops, Op> | null | undef
|
|
|
63
64
|
failureCount: Ref<number, number>;
|
|
64
65
|
failureReason: Ref<Error | null, Error | null>;
|
|
65
66
|
isPaused: Ref<boolean, boolean>;
|
|
66
|
-
variables: Ref<
|
|
67
|
+
variables: Ref<QMutationVars<Ops, Op>, QMutationVars<Ops, Op>>;
|
|
67
68
|
isIdle: Ref<false, false>;
|
|
68
|
-
context: Ref<unknown, unknown>;
|
|
69
69
|
submittedAt: Ref<number, number>;
|
|
70
|
-
mutate: (variables:
|
|
71
|
-
mutateAsync: import("@tanstack/query-core").MutateFunction<GetResponseData<Ops, Op>, Error,
|
|
70
|
+
mutate: (variables: QMutationVars<Ops, Op>, options?: import("@tanstack/query-core").MutateOptions<GetResponseData<Ops, Op>, Error, QMutationVars<Ops, Op>, unknown> | undefined) => void;
|
|
71
|
+
mutateAsync: import("@tanstack/query-core").MutateFunction<GetResponseData<Ops, Op>, Error, QMutationVars<Ops, Op>, unknown>;
|
|
72
72
|
reset: import("@tanstack/query-core").MutationObserverResult<TData, TError, TVariables, TOnMutateResult>["reset"];
|
|
73
73
|
} | {
|
|
74
74
|
data: ComputedRef<GetResponseData<Ops, Op> | undefined>;
|
|
75
75
|
isEnabled: ComputedRef<boolean>;
|
|
76
76
|
extraPathParams: Ref<GetPathParameters<Ops, Op>, GetPathParameters<Ops, Op>>;
|
|
77
|
+
context: Ref<unknown, unknown>;
|
|
77
78
|
error: Ref<Error, Error>;
|
|
78
79
|
isError: Ref<true, true>;
|
|
79
80
|
isPending: Ref<false, false>;
|
|
@@ -82,17 +83,17 @@ pathParamsOrOptions?: MaybeRefOrGetter<GetPathParameters<Ops, Op> | null | undef
|
|
|
82
83
|
failureCount: Ref<number, number>;
|
|
83
84
|
failureReason: Ref<Error | null, Error | null>;
|
|
84
85
|
isPaused: Ref<boolean, boolean>;
|
|
85
|
-
variables: Ref<
|
|
86
|
+
variables: Ref<QMutationVars<Ops, Op>, QMutationVars<Ops, Op>>;
|
|
86
87
|
isIdle: Ref<false, false>;
|
|
87
|
-
context: Ref<unknown, unknown>;
|
|
88
88
|
submittedAt: Ref<number, number>;
|
|
89
|
-
mutate: (variables:
|
|
90
|
-
mutateAsync: import("@tanstack/query-core").MutateFunction<GetResponseData<Ops, Op>, Error,
|
|
89
|
+
mutate: (variables: QMutationVars<Ops, Op>, options?: import("@tanstack/query-core").MutateOptions<GetResponseData<Ops, Op>, Error, QMutationVars<Ops, Op>, unknown> | undefined) => void;
|
|
90
|
+
mutateAsync: import("@tanstack/query-core").MutateFunction<GetResponseData<Ops, Op>, Error, QMutationVars<Ops, Op>, unknown>;
|
|
91
91
|
reset: import("@tanstack/query-core").MutationObserverResult<TData, TError, TVariables, TOnMutateResult>["reset"];
|
|
92
92
|
} | {
|
|
93
93
|
data: ComputedRef<GetResponseData<Ops, Op> | undefined>;
|
|
94
94
|
isEnabled: ComputedRef<boolean>;
|
|
95
95
|
extraPathParams: Ref<GetPathParameters<Ops, Op>, GetPathParameters<Ops, Op>>;
|
|
96
|
+
context: Ref<unknown, unknown>;
|
|
96
97
|
error: Ref<null, null>;
|
|
97
98
|
isError: Ref<false, false>;
|
|
98
99
|
isPending: Ref<false, false>;
|
|
@@ -101,12 +102,11 @@ pathParamsOrOptions?: MaybeRefOrGetter<GetPathParameters<Ops, Op> | null | undef
|
|
|
101
102
|
failureCount: Ref<number, number>;
|
|
102
103
|
failureReason: Ref<Error | null, Error | null>;
|
|
103
104
|
isPaused: Ref<boolean, boolean>;
|
|
104
|
-
variables: Ref<
|
|
105
|
+
variables: Ref<QMutationVars<Ops, Op>, QMutationVars<Ops, Op>>;
|
|
105
106
|
isIdle: Ref<false, false>;
|
|
106
|
-
context: Ref<unknown, unknown>;
|
|
107
107
|
submittedAt: Ref<number, number>;
|
|
108
|
-
mutate: (variables:
|
|
109
|
-
mutateAsync: import("@tanstack/query-core").MutateFunction<GetResponseData<Ops, Op>, Error,
|
|
108
|
+
mutate: (variables: QMutationVars<Ops, Op>, options?: import("@tanstack/query-core").MutateOptions<GetResponseData<Ops, Op>, Error, QMutationVars<Ops, Op>, unknown> | undefined) => void;
|
|
109
|
+
mutateAsync: import("@tanstack/query-core").MutateFunction<GetResponseData<Ops, Op>, Error, QMutationVars<Ops, Op>, unknown>;
|
|
110
110
|
reset: import("@tanstack/query-core").MutationObserverResult<TData, TError, TVariables, TOnMutateResult>["reset"];
|
|
111
111
|
};
|
|
112
112
|
//# sourceMappingURL=openapi-mutation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openapi-mutation.d.ts","sourceRoot":"","sources":["../src/openapi-mutation.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,WAAW,EAAE,KAAK,GAAG,EAAE,KAAK,gBAAgB,EAAE,MAAM,KAAK,CAAA;AAG/F,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,
|
|
1
|
+
{"version":3,"file":"openapi-mutation.d.ts","sourceRoot":"","sources":["../src/openapi-mutation.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,WAAW,EAAE,KAAK,GAAG,EAAE,KAAK,gBAAgB,EAAE,MAAM,KAAK,CAAA;AAG/F,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EAErB,UAAU,EACX,MAAM,SAAS,CAAA;AAEhB,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAG9C,MAAM,MAAM,sBAAsB,CAAC,GAAG,SAAS,UAAU,CAAC,GAAG,CAAC,EAAE,EAAE,SAAS,MAAM,GAAG,IAAI,UAAU,CAChG,OAAO,mBAAmB,CAAC,GAAG,EAAE,EAAE,CAAC,CACpC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,SAAS,UAAU,CAAC,GAAG,CAAC,EAAE,EAAE,SAAS,MAAM,GAAG,EACnF,WAAW,EAAE,EAAE,EACf,CAAC,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,UAAU;AACrD,mBAAmB,CAAC,EAAE,gBAAgB,CAAC,iBAAiB,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC,GAAG,gBAAgB,CAAC,GAAG,EAAE,EAAE,CAAC,EACjH,aAAa,CAAC,EAAE,gBAAgB,CAAC,GAAG,EAAE,EAAE,CAAC;UAuJhB,WAAW,CAAC,eAAe,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,SAAS,CAAC;;;;;;;;;;;;;;;;;;;UAAjD,WAAW,CAAC,eAAe,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,SAAS,CAAC;;;;;;;;;;;;;;;;;;;UAAjD,WAAW,CAAC,eAAe,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,SAAS,CAAC;;;;;;;;;;;;;;;;;;;UAAjD,WAAW,CAAC,eAAe,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,SAAS,CAAC;;;;;;;;;;;;;;;;;;EAI3E"}
|
package/dist/openapi-mutation.js
CHANGED
|
@@ -39,7 +39,7 @@ pathParamsOrOptions, optionsOrNull) {
|
|
|
39
39
|
throw new Error(`Operation ${String(operationId)} is not a mutation operation (POST/PUT/PATCH/DELETE)`);
|
|
40
40
|
}
|
|
41
41
|
const { path, method } = h.getOperationInfo(operationId);
|
|
42
|
-
const { pathParams, options } = getParamsOptionsFrom(pathParamsOrOptions, optionsOrNull);
|
|
42
|
+
const { pathParams, options } = getParamsOptionsFrom(path, pathParamsOrOptions, optionsOrNull);
|
|
43
43
|
const { axiosOptions, dontInvalidate, dontUpdateCache, invalidateOperations, refetchEndpoints, errorHandler, ...useMutationOptions } = options;
|
|
44
44
|
const extraPathParams = ref({});
|
|
45
45
|
// Compute the resolved path
|
|
@@ -142,7 +142,7 @@ pathParamsOrOptions, optionsOrNull) {
|
|
|
142
142
|
extraPathParams.value = {};
|
|
143
143
|
},
|
|
144
144
|
...useMutationOptions,
|
|
145
|
-
});
|
|
145
|
+
}, h.queryClient);
|
|
146
146
|
return {
|
|
147
147
|
...mutation,
|
|
148
148
|
data: mutation.data,
|
package/dist/openapi-query.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { type ComputedRef, type MaybeRefOrGetter } from 'vue';
|
|
2
|
-
import { Operations, type GetPathParameters, type GetResponseData, type
|
|
3
|
-
import type { AxiosError } from 'axios';
|
|
2
|
+
import { Operations, type GetPathParameters, type GetResponseData, type QQueryOptions } from './types';
|
|
4
3
|
import { getHelpers } from './openapi-helpers';
|
|
5
4
|
export type EndpointQueryReturn<Ops extends Operations<Ops>, Op extends keyof Ops> = ReturnType<typeof useEndpointQuery<Ops, Op>> & {
|
|
6
5
|
onLoad: (callback: (data: GetResponseData<Ops, Op>) => void) => void;
|
|
@@ -25,12 +24,12 @@ export type EndpointQueryReturn<Ops extends Operations<Ops>, Op extends keyof Op
|
|
|
25
24
|
* - `queryKey`: ComputedRef of the query key.
|
|
26
25
|
* - `onLoad`: Method to register a callback for when data is loaded.
|
|
27
26
|
*/
|
|
28
|
-
export declare function useEndpointQuery<Ops extends Operations<Ops>, Op extends keyof Ops>(operationId: Op, h: ReturnType<typeof getHelpers<Ops, Op>>, pathParamsOrOptions?: MaybeRefOrGetter<GetPathParameters<Ops, Op> | null | undefined> |
|
|
27
|
+
export declare function useEndpointQuery<Ops extends Operations<Ops>, Op extends keyof Ops>(operationId: Op, h: ReturnType<typeof getHelpers<Ops, Op>>, pathParamsOrOptions?: MaybeRefOrGetter<GetPathParameters<Ops, Op> | null | undefined> | QQueryOptions<Ops, Op>, optionsOrNull?: QQueryOptions<Ops, Op>): {
|
|
29
28
|
data: ComputedRef<GetResponseData<Ops, Op> | undefined>;
|
|
30
29
|
isEnabled: ComputedRef<boolean>;
|
|
31
30
|
queryKey: ComputedRef<string[]>;
|
|
32
31
|
onLoad: (callback: (data: GetResponseData<Ops, Op>) => void) => void;
|
|
33
|
-
error: import("vue").Ref<
|
|
32
|
+
error: import("vue").Ref<Error, Error>;
|
|
34
33
|
isError: import("vue").Ref<true, true>;
|
|
35
34
|
isPending: import("vue").Ref<false, false>;
|
|
36
35
|
isLoading: import("vue").Ref<false, false>;
|
|
@@ -42,7 +41,7 @@ export declare function useEndpointQuery<Ops extends Operations<Ops>, Op extends
|
|
|
42
41
|
dataUpdatedAt: import("vue").Ref<number, number>;
|
|
43
42
|
errorUpdatedAt: import("vue").Ref<number, number>;
|
|
44
43
|
failureCount: import("vue").Ref<number, number>;
|
|
45
|
-
failureReason: import("vue").Ref<
|
|
44
|
+
failureReason: import("vue").Ref<Error | null, Error | null>;
|
|
46
45
|
errorUpdateCount: import("vue").Ref<number, number>;
|
|
47
46
|
isFetched: import("vue").Ref<boolean, boolean>;
|
|
48
47
|
isFetchedAfterMount: import("vue").Ref<boolean, boolean>;
|
|
@@ -51,10 +50,10 @@ export declare function useEndpointQuery<Ops extends Operations<Ops>, Op extends
|
|
|
51
50
|
isPaused: import("vue").Ref<boolean, boolean>;
|
|
52
51
|
isRefetching: import("vue").Ref<boolean, boolean>;
|
|
53
52
|
isStale: import("vue").Ref<boolean, boolean>;
|
|
54
|
-
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<GetResponseData<Ops, Op>,
|
|
53
|
+
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<GetResponseData<Ops, Op>, Error>>;
|
|
55
54
|
fetchStatus: import("vue").Ref<import("@tanstack/query-core").FetchStatus, import("@tanstack/query-core").FetchStatus>;
|
|
56
55
|
promise: import("vue").Ref<Promise<GetResponseData<Ops, Op>>, Promise<GetResponseData<Ops, Op>>>;
|
|
57
|
-
suspense: () => Promise<import("@tanstack/query-core").QueryObserverResult<GetResponseData<Ops, Op>,
|
|
56
|
+
suspense: () => Promise<import("@tanstack/query-core").QueryObserverResult<GetResponseData<Ops, Op>, Error>>;
|
|
58
57
|
} | {
|
|
59
58
|
data: ComputedRef<GetResponseData<Ops, Op> | undefined>;
|
|
60
59
|
isEnabled: ComputedRef<boolean>;
|
|
@@ -72,7 +71,7 @@ export declare function useEndpointQuery<Ops extends Operations<Ops>, Op extends
|
|
|
72
71
|
dataUpdatedAt: import("vue").Ref<number, number>;
|
|
73
72
|
errorUpdatedAt: import("vue").Ref<number, number>;
|
|
74
73
|
failureCount: import("vue").Ref<number, number>;
|
|
75
|
-
failureReason: import("vue").Ref<
|
|
74
|
+
failureReason: import("vue").Ref<Error | null, Error | null>;
|
|
76
75
|
errorUpdateCount: import("vue").Ref<number, number>;
|
|
77
76
|
isFetched: import("vue").Ref<boolean, boolean>;
|
|
78
77
|
isFetchedAfterMount: import("vue").Ref<boolean, boolean>;
|
|
@@ -81,16 +80,16 @@ export declare function useEndpointQuery<Ops extends Operations<Ops>, Op extends
|
|
|
81
80
|
isPaused: import("vue").Ref<boolean, boolean>;
|
|
82
81
|
isRefetching: import("vue").Ref<boolean, boolean>;
|
|
83
82
|
isStale: import("vue").Ref<boolean, boolean>;
|
|
84
|
-
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<GetResponseData<Ops, Op>,
|
|
83
|
+
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<GetResponseData<Ops, Op>, Error>>;
|
|
85
84
|
fetchStatus: import("vue").Ref<import("@tanstack/query-core").FetchStatus, import("@tanstack/query-core").FetchStatus>;
|
|
86
85
|
promise: import("vue").Ref<Promise<GetResponseData<Ops, Op>>, Promise<GetResponseData<Ops, Op>>>;
|
|
87
|
-
suspense: () => Promise<import("@tanstack/query-core").QueryObserverResult<GetResponseData<Ops, Op>,
|
|
86
|
+
suspense: () => Promise<import("@tanstack/query-core").QueryObserverResult<GetResponseData<Ops, Op>, Error>>;
|
|
88
87
|
} | {
|
|
89
88
|
data: ComputedRef<GetResponseData<Ops, Op> | undefined>;
|
|
90
89
|
isEnabled: ComputedRef<boolean>;
|
|
91
90
|
queryKey: ComputedRef<string[]>;
|
|
92
91
|
onLoad: (callback: (data: GetResponseData<Ops, Op>) => void) => void;
|
|
93
|
-
error: import("vue").Ref<
|
|
92
|
+
error: import("vue").Ref<Error, Error>;
|
|
94
93
|
isError: import("vue").Ref<true, true>;
|
|
95
94
|
isPending: import("vue").Ref<false, false>;
|
|
96
95
|
isLoading: import("vue").Ref<false, false>;
|
|
@@ -102,7 +101,7 @@ export declare function useEndpointQuery<Ops extends Operations<Ops>, Op extends
|
|
|
102
101
|
dataUpdatedAt: import("vue").Ref<number, number>;
|
|
103
102
|
errorUpdatedAt: import("vue").Ref<number, number>;
|
|
104
103
|
failureCount: import("vue").Ref<number, number>;
|
|
105
|
-
failureReason: import("vue").Ref<
|
|
104
|
+
failureReason: import("vue").Ref<Error | null, Error | null>;
|
|
106
105
|
errorUpdateCount: import("vue").Ref<number, number>;
|
|
107
106
|
isFetched: import("vue").Ref<boolean, boolean>;
|
|
108
107
|
isFetchedAfterMount: import("vue").Ref<boolean, boolean>;
|
|
@@ -111,10 +110,10 @@ export declare function useEndpointQuery<Ops extends Operations<Ops>, Op extends
|
|
|
111
110
|
isPaused: import("vue").Ref<boolean, boolean>;
|
|
112
111
|
isRefetching: import("vue").Ref<boolean, boolean>;
|
|
113
112
|
isStale: import("vue").Ref<boolean, boolean>;
|
|
114
|
-
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<GetResponseData<Ops, Op>,
|
|
113
|
+
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<GetResponseData<Ops, Op>, Error>>;
|
|
115
114
|
fetchStatus: import("vue").Ref<import("@tanstack/query-core").FetchStatus, import("@tanstack/query-core").FetchStatus>;
|
|
116
115
|
promise: import("vue").Ref<Promise<GetResponseData<Ops, Op>>, Promise<GetResponseData<Ops, Op>>>;
|
|
117
|
-
suspense: () => Promise<import("@tanstack/query-core").QueryObserverResult<GetResponseData<Ops, Op>,
|
|
116
|
+
suspense: () => Promise<import("@tanstack/query-core").QueryObserverResult<GetResponseData<Ops, Op>, Error>>;
|
|
118
117
|
} | {
|
|
119
118
|
data: ComputedRef<GetResponseData<Ops, Op> | undefined>;
|
|
120
119
|
isEnabled: ComputedRef<boolean>;
|
|
@@ -132,7 +131,7 @@ export declare function useEndpointQuery<Ops extends Operations<Ops>, Op extends
|
|
|
132
131
|
dataUpdatedAt: import("vue").Ref<number, number>;
|
|
133
132
|
errorUpdatedAt: import("vue").Ref<number, number>;
|
|
134
133
|
failureCount: import("vue").Ref<number, number>;
|
|
135
|
-
failureReason: import("vue").Ref<
|
|
134
|
+
failureReason: import("vue").Ref<Error | null, Error | null>;
|
|
136
135
|
errorUpdateCount: import("vue").Ref<number, number>;
|
|
137
136
|
isFetched: import("vue").Ref<boolean, boolean>;
|
|
138
137
|
isFetchedAfterMount: import("vue").Ref<boolean, boolean>;
|
|
@@ -141,10 +140,10 @@ export declare function useEndpointQuery<Ops extends Operations<Ops>, Op extends
|
|
|
141
140
|
isPaused: import("vue").Ref<boolean, boolean>;
|
|
142
141
|
isRefetching: import("vue").Ref<boolean, boolean>;
|
|
143
142
|
isStale: import("vue").Ref<boolean, boolean>;
|
|
144
|
-
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<GetResponseData<Ops, Op>,
|
|
143
|
+
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<GetResponseData<Ops, Op>, Error>>;
|
|
145
144
|
fetchStatus: import("vue").Ref<import("@tanstack/query-core").FetchStatus, import("@tanstack/query-core").FetchStatus>;
|
|
146
145
|
promise: import("vue").Ref<Promise<GetResponseData<Ops, Op>>, Promise<GetResponseData<Ops, Op>>>;
|
|
147
|
-
suspense: () => Promise<import("@tanstack/query-core").QueryObserverResult<GetResponseData<Ops, Op>,
|
|
146
|
+
suspense: () => Promise<import("@tanstack/query-core").QueryObserverResult<GetResponseData<Ops, Op>, Error>>;
|
|
148
147
|
} | {
|
|
149
148
|
data: ComputedRef<GetResponseData<Ops, Op> | undefined>;
|
|
150
149
|
isEnabled: ComputedRef<boolean>;
|
|
@@ -161,7 +160,7 @@ export declare function useEndpointQuery<Ops extends Operations<Ops>, Op extends
|
|
|
161
160
|
dataUpdatedAt: import("vue").Ref<number, number>;
|
|
162
161
|
errorUpdatedAt: import("vue").Ref<number, number>;
|
|
163
162
|
failureCount: import("vue").Ref<number, number>;
|
|
164
|
-
failureReason: import("vue").Ref<
|
|
163
|
+
failureReason: import("vue").Ref<Error | null, Error | null>;
|
|
165
164
|
errorUpdateCount: import("vue").Ref<number, number>;
|
|
166
165
|
isFetched: import("vue").Ref<boolean, boolean>;
|
|
167
166
|
isFetchedAfterMount: import("vue").Ref<boolean, boolean>;
|
|
@@ -171,10 +170,10 @@ export declare function useEndpointQuery<Ops extends Operations<Ops>, Op extends
|
|
|
171
170
|
isPaused: import("vue").Ref<boolean, boolean>;
|
|
172
171
|
isRefetching: import("vue").Ref<boolean, boolean>;
|
|
173
172
|
isStale: import("vue").Ref<boolean, boolean>;
|
|
174
|
-
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<GetResponseData<Ops, Op>,
|
|
173
|
+
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<GetResponseData<Ops, Op>, Error>>;
|
|
175
174
|
fetchStatus: import("vue").Ref<import("@tanstack/query-core").FetchStatus, import("@tanstack/query-core").FetchStatus>;
|
|
176
175
|
promise: import("vue").Ref<Promise<GetResponseData<Ops, Op>>, Promise<GetResponseData<Ops, Op>>>;
|
|
177
|
-
suspense: () => Promise<import("@tanstack/query-core").QueryObserverResult<GetResponseData<Ops, Op>,
|
|
176
|
+
suspense: () => Promise<import("@tanstack/query-core").QueryObserverResult<GetResponseData<Ops, Op>, Error>>;
|
|
178
177
|
} | {
|
|
179
178
|
data: ComputedRef<GetResponseData<Ops, Op> | undefined>;
|
|
180
179
|
isEnabled: ComputedRef<boolean>;
|
|
@@ -192,7 +191,7 @@ export declare function useEndpointQuery<Ops extends Operations<Ops>, Op extends
|
|
|
192
191
|
dataUpdatedAt: import("vue").Ref<number, number>;
|
|
193
192
|
errorUpdatedAt: import("vue").Ref<number, number>;
|
|
194
193
|
failureCount: import("vue").Ref<number, number>;
|
|
195
|
-
failureReason: import("vue").Ref<
|
|
194
|
+
failureReason: import("vue").Ref<Error | null, Error | null>;
|
|
196
195
|
errorUpdateCount: import("vue").Ref<number, number>;
|
|
197
196
|
isFetched: import("vue").Ref<boolean, boolean>;
|
|
198
197
|
isFetchedAfterMount: import("vue").Ref<boolean, boolean>;
|
|
@@ -201,9 +200,9 @@ export declare function useEndpointQuery<Ops extends Operations<Ops>, Op extends
|
|
|
201
200
|
isPaused: import("vue").Ref<boolean, boolean>;
|
|
202
201
|
isRefetching: import("vue").Ref<boolean, boolean>;
|
|
203
202
|
isStale: import("vue").Ref<boolean, boolean>;
|
|
204
|
-
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<GetResponseData<Ops, Op>,
|
|
203
|
+
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<GetResponseData<Ops, Op>, Error>>;
|
|
205
204
|
fetchStatus: import("vue").Ref<import("@tanstack/query-core").FetchStatus, import("@tanstack/query-core").FetchStatus>;
|
|
206
205
|
promise: import("vue").Ref<Promise<GetResponseData<Ops, Op>>, Promise<GetResponseData<Ops, Op>>>;
|
|
207
|
-
suspense: () => Promise<import("@tanstack/query-core").QueryObserverResult<GetResponseData<Ops, Op>,
|
|
206
|
+
suspense: () => Promise<import("@tanstack/query-core").QueryObserverResult<GetResponseData<Ops, Op>, Error>>;
|
|
208
207
|
};
|
|
209
208
|
//# 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,WAAW,EAAE,KAAK,gBAAgB,EAAE,MAAM,KAAK,CAAA;AAEvF,OAAO,
|
|
1
|
+
{"version":3,"file":"openapi-query.d.ts","sourceRoot":"","sources":["../src/openapi-query.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,KAAK,WAAW,EAAE,KAAK,gBAAgB,EAAE,MAAM,KAAK,CAAA;AAEvF,OAAO,EAAE,UAAU,EAAE,KAAK,iBAAiB,EAAE,KAAK,eAAe,EAAE,KAAK,aAAa,EAAE,MAAM,SAAS,CAAA;AAGtG,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAE9C,MAAM,MAAM,mBAAmB,CAAC,GAAG,SAAS,UAAU,CAAC,GAAG,CAAC,EAAE,EAAE,SAAS,MAAM,GAAG,IAAI,UAAU,CAC7F,OAAO,gBAAgB,CAAC,GAAG,EAAE,EAAE,CAAC,CACjC,GAAG;IACF,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,eAAe,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK,IAAI,KAAK,IAAI,CAAA;CACrE,CAAA;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,SAAS,UAAU,CAAC,GA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;;;;;;;;;;;;;;;;;;;;;;;;;;UAM5C,WAAW,CAAC,eAAe,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,SAAS,CAAC;;;uBAN7C,CAAC,IAAI,EAAE,eAAe,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;EAWnE"}
|
package/dist/openapi-query.js
CHANGED
|
@@ -28,7 +28,7 @@ export function useEndpointQuery(operationId, h, pathParamsOrOptions, optionsOrN
|
|
|
28
28
|
throw new Error(`Operation ${String(operationId)} is not a query operation (GET/HEAD/OPTIONS)`);
|
|
29
29
|
}
|
|
30
30
|
const { path, method } = h.getOperationInfo(operationId);
|
|
31
|
-
const { pathParams, options } = getParamsOptionsFrom(pathParamsOrOptions, optionsOrNull);
|
|
31
|
+
const { pathParams, options } = getParamsOptionsFrom(path, pathParamsOrOptions, optionsOrNull);
|
|
32
32
|
const { enabled: enabledInit, onLoad: onLoadInit, axiosOptions, errorHandler, ...useQueryOptions } = options;
|
|
33
33
|
const resolvedPath = computed(() => resolvePath(path, pathParams));
|
|
34
34
|
const queryKey = computed(() => generateQueryKey(resolvedPath.value));
|
|
@@ -67,13 +67,13 @@ export function useEndpointQuery(operationId, h, pathParamsOrOptions, optionsOrN
|
|
|
67
67
|
},
|
|
68
68
|
enabled: isEnabled,
|
|
69
69
|
staleTime: 1000 * 60,
|
|
70
|
-
retry: (
|
|
71
|
-
// Don't retry 4xx errors
|
|
72
|
-
if (error.response && error.response.status >= 400 && error.response.status < 500) {
|
|
70
|
+
retry: (_failureCount, error) => {
|
|
71
|
+
// Don't retry 4xx errors if error is AxiosError
|
|
72
|
+
if (isAxiosError(error) && error.response && error.response.status >= 400 && error.response.status < 500) {
|
|
73
73
|
return false;
|
|
74
74
|
}
|
|
75
75
|
// Retry up to 3 times for other errors
|
|
76
|
-
return
|
|
76
|
+
return _failureCount < 3;
|
|
77
77
|
},
|
|
78
78
|
...useQueryOptions,
|
|
79
79
|
}, h.queryClient);
|
package/dist/openapi-utils.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type MaybeRefOrGetter } from 'vue';
|
|
2
|
-
import { type GetPathParameters, type
|
|
2
|
+
import { type GetPathParameters, type QMutationOptions, type QQueryOptions, Operations } from './types';
|
|
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
|
-
export declare function getParamsOptionsFrom<Ops extends Operations<Ops>, Op extends keyof Ops, Options extends
|
|
6
|
+
export declare function getParamsOptionsFrom<Ops extends Operations<Ops>, Op extends keyof Ops, Options extends QMutationOptions<Ops, Op> | QQueryOptions<Ops, Op>>(path: string, pathParamsOrOptions?: MaybeRefOrGetter<GetPathParameters<Ops, Op> | null | undefined> | Options, optionsOrNull?: Options): {
|
|
7
7
|
pathParams: MaybeRefOrGetter<GetPathParameters<Ops, Op> | null | undefined>;
|
|
8
8
|
options: Options;
|
|
9
9
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openapi-utils.d.ts","sourceRoot":"","sources":["../src/openapi-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,gBAAgB,EAAE,MAAM,KAAK,CAAA;AACpD,OAAO,EAAE,KAAK,iBAAiB,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"openapi-utils.d.ts","sourceRoot":"","sources":["../src/openapi-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,gBAAgB,EAAE,MAAM,KAAK,CAAA;AACpD,OAAO,EAAE,KAAK,iBAAiB,EAAE,KAAK,gBAAgB,EAAE,KAAK,aAAa,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAGvG,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,EACZ,UAAU,CAAC,EAAE,gBAAgB,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC,GAC5F,MAAM,CAaR;AAqCD,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEpD;AAGD,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,EAAE,CAE/D;AAED,wBAAgB,oBAAoB,CAClC,GAAG,SAAS,UAAU,CAAC,GAAG,CAAC,EAC3B,EAAE,SAAS,MAAM,GAAG,EACpB,OAAO,SAAS,gBAAgB,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,aAAa,CAAC,GAAG,EAAE,EAAE,CAAC,EAElE,IAAI,EAAE,MAAM,EACZ,mBAAmB,CAAC,EAAE,gBAAgB,CAAC,iBAAiB,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC,GAAG,OAAO,EAC/F,aAAa,CAAC,EAAE,OAAO,GACtB;IACD,UAAU,EAAE,gBAAgB,CAAC,iBAAiB,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC,CAAA;IAC3E,OAAO,EAAE,OAAO,CAAA;CACjB,CA8BA"}
|
package/dist/openapi-utils.js
CHANGED
|
@@ -14,6 +14,40 @@ export function resolvePath(path, pathParams) {
|
|
|
14
14
|
});
|
|
15
15
|
return resolvedPath;
|
|
16
16
|
}
|
|
17
|
+
function isPathParams(path, pathParams) {
|
|
18
|
+
if (!pathParams)
|
|
19
|
+
return false;
|
|
20
|
+
const paramNames = Object.keys(pathParams);
|
|
21
|
+
// List of known option-like properties to exclude
|
|
22
|
+
const optionProps = [
|
|
23
|
+
'enabled',
|
|
24
|
+
'onSuccess',
|
|
25
|
+
'onError',
|
|
26
|
+
'onSettled',
|
|
27
|
+
'select',
|
|
28
|
+
'retry',
|
|
29
|
+
'staleTime',
|
|
30
|
+
'cacheTime',
|
|
31
|
+
'refetchOnWindowFocus',
|
|
32
|
+
'refetchOnReconnect',
|
|
33
|
+
'refetchOnMount',
|
|
34
|
+
'suspense',
|
|
35
|
+
'useErrorBoundary',
|
|
36
|
+
'meta',
|
|
37
|
+
'mutationKey',
|
|
38
|
+
'mutationFn',
|
|
39
|
+
'queryKey',
|
|
40
|
+
'queryFn',
|
|
41
|
+
'initialData',
|
|
42
|
+
'context',
|
|
43
|
+
// Add more as needed
|
|
44
|
+
];
|
|
45
|
+
// If any option-like property is present, it's not path params
|
|
46
|
+
if (paramNames.some((name) => optionProps.includes(name))) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
return paramNames.every((paramName) => path.includes(`{${paramName}}`));
|
|
50
|
+
}
|
|
17
51
|
// Helper to check if all required path parameters are provided
|
|
18
52
|
export function isPathResolved(path) {
|
|
19
53
|
return !/{[^}]+}/.test(path);
|
|
@@ -22,14 +56,25 @@ export function isPathResolved(path) {
|
|
|
22
56
|
export function generateQueryKey(resolvedPath) {
|
|
23
57
|
return resolvedPath.split('/').filter((segment) => segment.length > 0);
|
|
24
58
|
}
|
|
25
|
-
export function getParamsOptionsFrom(pathParamsOrOptions, optionsOrNull) {
|
|
59
|
+
export function getParamsOptionsFrom(path, pathParamsOrOptions, optionsOrNull) {
|
|
26
60
|
// Check if pathParamsOrOptions is MutationOptions or QueryOptions by checking if options is undefined
|
|
27
61
|
// and pathParamsOrOptions has MutationOptions properties
|
|
28
|
-
let pathParams;
|
|
29
|
-
let options;
|
|
30
|
-
if (optionsOrNull === undefined
|
|
31
|
-
|
|
32
|
-
|
|
62
|
+
let pathParams = undefined;
|
|
63
|
+
let options = undefined;
|
|
64
|
+
if (optionsOrNull === undefined) {
|
|
65
|
+
const pathParamsOrOptionsValue = toValue(pathParamsOrOptions);
|
|
66
|
+
if (typeof pathParamsOrOptions === 'object' &&
|
|
67
|
+
pathParamsOrOptions !== null &&
|
|
68
|
+
pathParamsOrOptionsValue &&
|
|
69
|
+
typeof pathParamsOrOptionsValue === 'object' &&
|
|
70
|
+
isPathParams(path, pathParamsOrOptionsValue)) {
|
|
71
|
+
// Called as: useEndpointQuery(operationId, pathParams)
|
|
72
|
+
pathParams = pathParamsOrOptions;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
// Called as: useEndpointQuery(operationId, [options])
|
|
76
|
+
options = pathParamsOrOptions;
|
|
77
|
+
}
|
|
33
78
|
}
|
|
34
79
|
else {
|
|
35
80
|
// Called as: useEndpointQuery(operationId, pathParams, options)
|
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type AxiosInstance, type AxiosError } from 'axios';
|
|
2
2
|
import { UseMutationOptions, type UseQueryOptions, QueryClient } from '@tanstack/vue-query';
|
|
3
|
-
import type { MaybeRefOrGetter } from 'vue';
|
|
3
|
+
import type { MaybeRef, MaybeRefOrGetter } from 'vue';
|
|
4
4
|
import { type AxiosRequestConfig } from 'axios';
|
|
5
5
|
import type { EndpointQueryReturn } from './openapi-query';
|
|
6
6
|
import type { EndpointMutationReturn } from './openapi-mutation';
|
|
@@ -41,7 +41,8 @@ export type GetResponseData<Ops extends Operations<Ops>, Op extends keyof Ops> =
|
|
|
41
41
|
};
|
|
42
42
|
};
|
|
43
43
|
} ? RequireReadonly<Data> : unknown;
|
|
44
|
-
|
|
44
|
+
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>>;
|
|
45
|
+
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'> & {
|
|
45
46
|
enabled?: MaybeRefOrGetter<boolean>;
|
|
46
47
|
onLoad?: (data: GetResponseData<Ops, Op>) => void;
|
|
47
48
|
axiosOptions?: AxiosRequestConfig;
|
|
@@ -55,11 +56,11 @@ type MutationOnSuccessOptions<Ops extends Operations<Ops>> = {
|
|
|
55
56
|
}>;
|
|
56
57
|
refetchEndpoints?: EndpointQueryReturn<Ops, keyof Ops>[];
|
|
57
58
|
};
|
|
58
|
-
export type
|
|
59
|
+
export type QMutationVars<Ops extends Operations<Ops>, Op extends keyof Ops> = MutationOnSuccessOptions<Ops> & {
|
|
59
60
|
data: GetRequestBody<Ops, Op>;
|
|
60
61
|
pathParams?: GetPathParameters<Ops, Op>;
|
|
61
62
|
};
|
|
62
|
-
export type
|
|
63
|
+
export type QMutationOptions<Ops extends Operations<Ops>, Op extends keyof Ops> = OmitMaybeRef<UseMutationOptions<GetResponseData<Ops, Op>, Error, QMutationVars<Ops, Op>>, 'mutationFn' | 'mutationKey'> & MutationOnSuccessOptions<Ops> & {
|
|
63
64
|
axiosOptions?: AxiosRequestConfig;
|
|
64
65
|
errorHandler?: (error: AxiosError) => GetResponseData<Ops, Op> | void | Promise<GetResponseData<Ops, Op> | void>;
|
|
65
66
|
};
|
|
@@ -93,8 +94,9 @@ export type IsQueryOperation<Ops extends Operations<Ops>, Op extends keyof Ops>
|
|
|
93
94
|
method: HttpMethod.GET | HttpMethod.HEAD | HttpMethod.OPTIONS;
|
|
94
95
|
} ? true : false;
|
|
95
96
|
export type OpenApiInstance<Ops extends Operations<Ops>> = {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
_debugIsQueryOperation: <Op extends keyof Ops>(operationId: Op) => IsQueryOperation<Ops, Op>;
|
|
98
|
+
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>;
|
|
99
|
+
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>;
|
|
100
|
+
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
101
|
};
|
|
100
102
|
//# 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,MAAM,OAAO,CAAA;AAC3D,OAAO,EAAE,kBAAkB,EAAE,KAAK,eAAe,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAE3F,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,KAAK,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,UAAU,EAAE,MAAM,OAAO,CAAA;AAC3D,OAAO,EAAE,kBAAkB,EAAE,KAAK,eAAe,EAAE,WAAW,EAA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EAAE,EAAE,CAAC,SAAS,IAAI,GAAG,aAAa,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,gBAAgB,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,EACrG,aAAa,CAAC,EAAE,gBAAgB,CAAC,GAAG,EAAE,EAAE,CAAC,SAAS,IAAI,GAAG,aAAa,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,gBAAgB,CAAC,GAAG,EAAE,EAAE,CAAC,KACxG,gBAAgB,CAAC,GAAG,EAAE,EAAE,CAAC,SAAS,IAAI,GAAG,mBAAmB,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,sBAAsB,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;CAC7G,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qualisero/openapi-endpoint",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/qualisero/openapi-endpoint.git"
|
|
@@ -24,16 +24,20 @@
|
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
26
|
"build": "tsc -p tsconfig.json",
|
|
27
|
-
"
|
|
27
|
+
"dev": "vitest",
|
|
28
28
|
"test": "vitest",
|
|
29
29
|
"test:run": "vitest run",
|
|
30
30
|
"test:ui": "vitest --ui",
|
|
31
31
|
"test:coverage": "vitest run --coverage",
|
|
32
|
+
"check": "npm run types && npm run types:test && npm run lint && npm run format:check",
|
|
33
|
+
"fix": "npm run lint:fix && npm run format",
|
|
34
|
+
"types": "tsc --noEmit",
|
|
35
|
+
"types:test": "npx tsc --noEmit --project tests/tsconfig.json",
|
|
32
36
|
"lint": "eslint .",
|
|
33
37
|
"lint:fix": "eslint . --fix",
|
|
34
38
|
"format": "prettier --write .",
|
|
35
39
|
"format:check": "prettier --check .",
|
|
36
|
-
"prepublishOnly": "npm run build && npm run
|
|
40
|
+
"prepublishOnly": "npm run build && npm run check"
|
|
37
41
|
},
|
|
38
42
|
"keywords": [
|
|
39
43
|
"vue",
|