tangled
alpha
login
or
join now
mokkenstorm.dev
/
openapi-ts
0
fork
atom
fork of hey-api/openapi-ts because I need some additional things
0
fork
atom
overview
issues
pulls
pipelines
chore(pinia-colada): simplify example
Dmitriy Brolnickij
6 months ago
33516370
7eabf670
+22
-49
3 changed files
expand all
collapse all
unified
split
examples
openapi-ts-pinia-colada
openapi-ts.config.ts
src
client
@pinia
colada.gen.ts
views
PiniaColadaExample.vue
+2
-1
examples/openapi-ts-pinia-colada/openapi-ts.config.ts
···
18
},
19
{
20
exportFromIndex: true,
21
-
name: '@pinia/colada'
0
22
}
23
]
24
})
···
18
},
19
{
20
exportFromIndex: true,
21
+
name: '@pinia/colada',
22
+
queryKeys: false
23
}
24
]
25
})
+8
-32
examples/openapi-ts-pinia-colada/src/client/@pinia/colada.gen.ts
···
118
return [params]
119
}
120
121
-
export const findPetsByStatusQueryKey = (options: Options<FindPetsByStatusData>) =>
122
-
createQueryKey('findPetsByStatus', options)
123
-
124
/**
125
* Finds Pets by status.
126
* Multiple status values can be provided with comma separated strings.
127
*/
128
export const findPetsByStatusQuery = defineQueryOptions(
129
(options: Options<FindPetsByStatusData>) => ({
130
-
key: findPetsByStatusQueryKey(options),
131
query: async (context) => {
132
const { data } = await findPetsByStatus({
133
...options,
···
139
})
140
)
141
142
-
export const findPetsByTagsQueryKey = (options: Options<FindPetsByTagsData>) =>
143
-
createQueryKey('findPetsByTags', options)
144
-
145
/**
146
* Finds Pets by tags.
147
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
148
*/
149
export const findPetsByTagsQuery = defineQueryOptions((options: Options<FindPetsByTagsData>) => ({
150
-
key: findPetsByTagsQueryKey(options),
151
query: async (context) => {
152
const { data } = await findPetsByTags({
153
...options,
···
175
}
176
})
177
178
-
export const getPetByIdQueryKey = (options: Options<GetPetByIdData>) =>
179
-
createQueryKey('getPetById', options)
180
-
181
/**
182
* Find pet by ID.
183
* Returns a single pet.
184
*/
185
export const getPetByIdQuery = defineQueryOptions((options: Options<GetPetByIdData>) => ({
186
-
key: getPetByIdQueryKey(options),
187
query: async (context) => {
188
const { data } = await getPetById({
189
...options,
···
228
}
229
})
230
231
-
export const getInventoryQueryKey = (options?: Options<GetInventoryData>) =>
232
-
createQueryKey('getInventory', options)
233
-
234
/**
235
* Returns pet inventories by status.
236
* Returns a map of status codes to quantities.
237
*/
238
export const getInventoryQuery = defineQueryOptions((options?: Options<GetInventoryData>) => ({
239
-
key: getInventoryQueryKey(options),
240
query: async (context) => {
241
const { data } = await getInventory({
242
...options,
···
281
}
282
})
283
284
-
export const getOrderByIdQueryKey = (options: Options<GetOrderByIdData>) =>
285
-
createQueryKey('getOrderById', options)
286
-
287
/**
288
* Find purchase order by ID.
289
* For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions.
290
*/
291
export const getOrderByIdQuery = defineQueryOptions((options: Options<GetOrderByIdData>) => ({
292
-
key: getOrderByIdQueryKey(options),
293
query: async (context) => {
294
const { data } = await getOrderById({
295
...options,
···
338
}
339
})
340
341
-
export const loginUserQueryKey = (options?: Options<LoginUserData>) =>
342
-
createQueryKey('loginUser', options)
343
-
344
/**
345
* Logs user into the system.
346
* Log into the system.
347
*/
348
export const loginUserQuery = defineQueryOptions((options?: Options<LoginUserData>) => ({
349
-
key: loginUserQueryKey(options),
350
query: async (context) => {
351
const { data } = await loginUser({
352
...options,
···
357
}
358
}))
359
360
-
export const logoutUserQueryKey = (options?: Options<LogoutUserData>) =>
361
-
createQueryKey('logoutUser', options)
362
-
363
/**
364
* Logs out current logged in user session.
365
* Log user out of the system.
366
*/
367
export const logoutUserQuery = defineQueryOptions((options?: Options<LogoutUserData>) => ({
368
-
key: logoutUserQueryKey(options),
369
query: async (context) => {
370
const { data } = await logoutUser({
371
...options,
···
393
}
394
})
395
396
-
export const getUserByNameQueryKey = (options: Options<GetUserByNameData>) =>
397
-
createQueryKey('getUserByName', options)
398
-
399
/**
400
* Get user by user name.
401
* Get user detail based on username.
402
*/
403
export const getUserByNameQuery = defineQueryOptions((options: Options<GetUserByNameData>) => ({
404
-
key: getUserByNameQueryKey(options),
405
query: async (context) => {
406
const { data } = await getUserByName({
407
...options,
···
118
return [params]
119
}
120
0
0
0
121
/**
122
* Finds Pets by status.
123
* Multiple status values can be provided with comma separated strings.
124
*/
125
export const findPetsByStatusQuery = defineQueryOptions(
126
(options: Options<FindPetsByStatusData>) => ({
127
+
key: createQueryKey('findPetsByStatus', options),
128
query: async (context) => {
129
const { data } = await findPetsByStatus({
130
...options,
···
136
})
137
)
138
0
0
0
139
/**
140
* Finds Pets by tags.
141
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
142
*/
143
export const findPetsByTagsQuery = defineQueryOptions((options: Options<FindPetsByTagsData>) => ({
144
+
key: createQueryKey('findPetsByTags', options),
145
query: async (context) => {
146
const { data } = await findPetsByTags({
147
...options,
···
169
}
170
})
171
0
0
0
172
/**
173
* Find pet by ID.
174
* Returns a single pet.
175
*/
176
export const getPetByIdQuery = defineQueryOptions((options: Options<GetPetByIdData>) => ({
177
+
key: createQueryKey('getPetById', options),
178
query: async (context) => {
179
const { data } = await getPetById({
180
...options,
···
219
}
220
})
221
0
0
0
222
/**
223
* Returns pet inventories by status.
224
* Returns a map of status codes to quantities.
225
*/
226
export const getInventoryQuery = defineQueryOptions((options?: Options<GetInventoryData>) => ({
227
+
key: createQueryKey('getInventory', options),
228
query: async (context) => {
229
const { data } = await getInventory({
230
...options,
···
269
}
270
})
271
0
0
0
272
/**
273
* Find purchase order by ID.
274
* For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions.
275
*/
276
export const getOrderByIdQuery = defineQueryOptions((options: Options<GetOrderByIdData>) => ({
277
+
key: createQueryKey('getOrderById', options),
278
query: async (context) => {
279
const { data } = await getOrderById({
280
...options,
···
323
}
324
})
325
0
0
0
326
/**
327
* Logs user into the system.
328
* Log into the system.
329
*/
330
export const loginUserQuery = defineQueryOptions((options?: Options<LoginUserData>) => ({
331
+
key: createQueryKey('loginUser', options),
332
query: async (context) => {
333
const { data } = await loginUser({
334
...options,
···
339
}
340
}))
341
0
0
0
342
/**
343
* Logs out current logged in user session.
344
* Log user out of the system.
345
*/
346
export const logoutUserQuery = defineQueryOptions((options?: Options<LogoutUserData>) => ({
347
+
key: createQueryKey('logoutUser', options),
348
query: async (context) => {
349
const { data } = await logoutUser({
350
...options,
···
372
}
373
})
374
0
0
0
375
/**
376
* Get user by user name.
377
* Get user detail based on username.
378
*/
379
export const getUserByNameQuery = defineQueryOptions((options: Options<GetUserByNameData>) => ({
380
+
key: createQueryKey('getUserByName', options),
381
query: async (context) => {
382
const { data } = await getUserByName({
383
...options,
+12
-16
examples/openapi-ts-pinia-colada/src/views/PiniaColadaExample.vue
···
4
import { PiniaColadaDevtools } from '@pinia/colada-devtools'
5
import { createClient } from '@/client/client'
6
import { PetSchema } from '@/client/schemas.gen'
7
-
import {
8
-
addPetMutation,
9
-
getPetByIdQuery,
10
-
getPetByIdQueryKey,
11
-
updatePetMutation
12
-
} from '@/client/@pinia/colada.gen'
13
import { useQuery, useMutation, useQueryCache } from '@pinia/colada'
14
import { ref, watch } from 'vue'
15
···
42
const petInput = ref({ name: '', category: '' })
43
44
const { data: pet, error } = useQuery(() => ({
45
-
...getPetByIdQuery(petQueryOptions()),
0
0
0
0
46
enabled: petId.value !== undefined
47
}))
48
const { mutateAsync: createPet } = useMutation(addPetMutation())
···
50
51
const queryCache = useQueryCache()
52
async function invalidateCurrentPet() {
53
-
const key = getPetByIdQueryKey(petQueryOptions())
0
0
0
0
54
await queryCache.invalidateQueries({ key, exact: true })
55
}
56
···
87
await updatePetIdAndInvalidate(result.id)
88
}
89
90
-
function petQueryOptions() {
91
-
return {
92
-
client: localClient,
93
-
path: { petId: petId.value as number }
94
-
}
95
-
}
96
-
97
function randomInt(min: number, max: number) {
98
return Math.floor(Math.random() * (max - min + 1) + min)
99
}
···
122
}
123
124
watch(error, (error) => {
125
-
console.log(error)
126
})
127
</script>
128
···
4
import { PiniaColadaDevtools } from '@pinia/colada-devtools'
5
import { createClient } from '@/client/client'
6
import { PetSchema } from '@/client/schemas.gen'
7
+
import { addPetMutation, getPetByIdQuery, updatePetMutation } from '@/client/@pinia/colada.gen'
0
0
0
0
0
8
import { useQuery, useMutation, useQueryCache } from '@pinia/colada'
9
import { ref, watch } from 'vue'
10
···
37
const petInput = ref({ name: '', category: '' })
38
39
const { data: pet, error } = useQuery(() => ({
40
+
...getPetByIdQuery({
41
+
path: {
42
+
petId: petId.value as number
43
+
}
44
+
}),
45
enabled: petId.value !== undefined
46
}))
47
const { mutateAsync: createPet } = useMutation(addPetMutation())
···
49
50
const queryCache = useQueryCache()
51
async function invalidateCurrentPet() {
52
+
const { key } = getPetByIdQuery({
53
+
path: {
54
+
petId: petId.value as number
55
+
}
56
+
})
57
await queryCache.invalidateQueries({ key, exact: true })
58
}
59
···
90
await updatePetIdAndInvalidate(result.id)
91
}
92
0
0
0
0
0
0
0
93
function randomInt(min: number, max: number) {
94
return Math.floor(Math.random() * (max - min + 1) + min)
95
}
···
118
}
119
120
watch(error, (error) => {
121
+
console.error(error)
122
})
123
</script>
124