@aws/nx-plugin 0.14.2 → 0.15.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/package.json +2 -2
- package/src/open-api/ts-client/__snapshots__/generator.additional-properties.spec.ts.snap +2236 -0
- package/src/open-api/ts-client/__snapshots__/generator.complex-types.spec.ts.snap +2307 -0
- package/src/open-api/ts-client/__snapshots__/generator.composite-types.spec.ts.snap +1495 -0
- package/src/open-api/ts-client/__snapshots__/generator.primitive-types.spec.ts.snap +1470 -0
- package/src/open-api/ts-client/__snapshots__/generator.request.spec.ts.snap +1138 -0
- package/src/open-api/ts-client/__snapshots__/generator.response.spec.ts.snap +732 -0
- package/src/open-api/ts-client/__snapshots__/generator.tags.spec.ts.snap +743 -0
- package/src/open-api/ts-client/files/client.gen.ts.template +52 -15
- package/src/open-api/ts-client/files/types.gen.ts.template +5 -0
- package/src/open-api/ts-hooks/__snapshots__/generator.spec.tsx.snap +1092 -0
- package/src/open-api/ts-hooks/files/options-proxy.gen.ts.template +210 -0
- package/src/open-api/ts-hooks/generator.d.ts +5 -0
- package/src/open-api/ts-hooks/generator.js +15 -2
- package/src/open-api/ts-hooks/generator.js.map +1 -1
- package/src/open-api/ts-hooks/generator.spec.tsx +1787 -0
- package/src/open-api/utils/codegen-data/types.d.ts +25 -0
- package/src/open-api/utils/codegen-data/types.js +26 -1
- package/src/open-api/utils/codegen-data/types.js.map +1 -1
- package/src/open-api/utils/codegen-data.js +187 -79
- package/src/open-api/utils/codegen-data.js.map +1 -1
- package/src/open-api/utils/normalise.js +11 -1
- package/src/open-api/utils/normalise.js.map +1 -1
- package/src/py/fast-api/react/__snapshots__/generator.spec.ts.snap +120 -10
- package/src/py/fast-api/react/files/website/components/__apiNameClassName__Provider.tsx.template +40 -0
- package/src/py/fast-api/react/files/website/hooks/use__apiNameClassName__.tsx.template +13 -18
- package/src/py/fast-api/react/files/website/hooks/use__apiNameClassName__Client.tsx.template +13 -0
- package/src/py/fast-api/react/generator.js +35 -9
- package/src/py/fast-api/react/generator.js.map +1 -1
- package/src/py/project/generator.js +5 -0
- package/src/py/project/generator.js.map +1 -1
- package/src/trpc/backend/__snapshots__/generator.spec.ts.snap +7 -9
- package/src/utils/files/http-api/common/constructs/src/core/http-api.ts.template +7 -9
- package/src/open-api/ts-client/__snapshots__/generator.spec.ts.snap +0 -7880
|
@@ -0,0 +1,1092 @@
|
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
+
|
|
3
|
+
exports[`openApiTsHooksGenerator > should generate an options proxy for a mutation operation 1`] = `
|
|
4
|
+
"import type { UseMutationOptions } from '@tanstack/react-query';
|
|
5
|
+
import type {
|
|
6
|
+
CreateUserRequest,
|
|
7
|
+
CreateUserError,
|
|
8
|
+
CreateUser201Response,
|
|
9
|
+
} from './types.gen.js';
|
|
10
|
+
import { TestApi } from './client.gen.js';
|
|
11
|
+
|
|
12
|
+
export interface TestApiOptionsProxyConfig {
|
|
13
|
+
client: TestApi;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class TestApiOptionsProxy {
|
|
17
|
+
private $client: TestApi;
|
|
18
|
+
|
|
19
|
+
constructor({ client }: TestApiOptionsProxyConfig) {
|
|
20
|
+
this.$client = client;
|
|
21
|
+
|
|
22
|
+
this._createUserMutationKey = this._createUserMutationKey.bind(this);
|
|
23
|
+
this._createUserMutationOptions =
|
|
24
|
+
this._createUserMutationOptions.bind(this);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public queryKey = () => ['TestApi'];
|
|
28
|
+
|
|
29
|
+
private _createUserMutationKey() {
|
|
30
|
+
return [...this.queryKey(), 'createUser'];
|
|
31
|
+
}
|
|
32
|
+
private _createUserMutationOptions(
|
|
33
|
+
options?: UseMutationOptions<
|
|
34
|
+
CreateUser201Response,
|
|
35
|
+
CreateUserError,
|
|
36
|
+
CreateUserRequest
|
|
37
|
+
>,
|
|
38
|
+
): UseMutationOptions<
|
|
39
|
+
CreateUser201Response,
|
|
40
|
+
CreateUserError,
|
|
41
|
+
CreateUserRequest
|
|
42
|
+
> {
|
|
43
|
+
return {
|
|
44
|
+
mutationFn: (input) => this.$client.createUser(input),
|
|
45
|
+
mutationKey: this._createUserMutationKey(),
|
|
46
|
+
...options,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public createUser = {
|
|
51
|
+
mutationKey: this._createUserMutationKey.bind(this),
|
|
52
|
+
mutationOptions: this._createUserMutationOptions.bind(this),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
"
|
|
56
|
+
`;
|
|
57
|
+
|
|
58
|
+
exports[`openApiTsHooksGenerator > should generate an options proxy for a query operation 1`] = `
|
|
59
|
+
"import type { QueryFilters, UseQueryOptions } from '@tanstack/react-query';
|
|
60
|
+
import type { GetTestError, GetTest200Response } from './types.gen.js';
|
|
61
|
+
import { TestApi } from './client.gen.js';
|
|
62
|
+
|
|
63
|
+
export interface TestApiOptionsProxyConfig {
|
|
64
|
+
client: TestApi;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export class TestApiOptionsProxy {
|
|
68
|
+
private $client: TestApi;
|
|
69
|
+
|
|
70
|
+
constructor({ client }: TestApiOptionsProxyConfig) {
|
|
71
|
+
this.$client = client;
|
|
72
|
+
|
|
73
|
+
this._getTestQueryKey = this._getTestQueryKey.bind(this);
|
|
74
|
+
this._getTestQueryOptions = this._getTestQueryOptions.bind(this);
|
|
75
|
+
this._getTestQueryFilter = this._getTestQueryFilter.bind(this);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
public queryKey = () => ['TestApi'];
|
|
79
|
+
|
|
80
|
+
private _getTestQueryKey() {
|
|
81
|
+
return [...this.queryKey(), 'getTest'];
|
|
82
|
+
}
|
|
83
|
+
private _getTestQueryOptions(
|
|
84
|
+
options?: Omit<
|
|
85
|
+
UseQueryOptions<GetTest200Response, GetTestError>,
|
|
86
|
+
'queryFn' | 'queryKey'
|
|
87
|
+
> &
|
|
88
|
+
Partial<
|
|
89
|
+
Pick<
|
|
90
|
+
UseQueryOptions<GetTest200Response, GetTestError>,
|
|
91
|
+
'queryFn' | 'queryKey'
|
|
92
|
+
>
|
|
93
|
+
>,
|
|
94
|
+
): UseQueryOptions<GetTest200Response, GetTestError> {
|
|
95
|
+
return {
|
|
96
|
+
queryFn: () => this.$client.getTest(),
|
|
97
|
+
queryKey: this._getTestQueryKey(),
|
|
98
|
+
...options,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
private _getTestQueryFilter(
|
|
102
|
+
filter?: QueryFilters<GetTest200Response, GetTestError>,
|
|
103
|
+
): QueryFilters<GetTest200Response, GetTestError> {
|
|
104
|
+
return {
|
|
105
|
+
queryKey: this._getTestQueryKey(),
|
|
106
|
+
...filter,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
public getTest = {
|
|
111
|
+
queryKey: this._getTestQueryKey.bind(this),
|
|
112
|
+
queryOptions: this._getTestQueryOptions.bind(this),
|
|
113
|
+
queryFilter: this._getTestQueryFilter.bind(this),
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
"
|
|
117
|
+
`;
|
|
118
|
+
|
|
119
|
+
exports[`openApiTsHooksGenerator > should generate an options proxy for a successful infinite query operation 1`] = `
|
|
120
|
+
"import type {
|
|
121
|
+
QueryFilters,
|
|
122
|
+
UseQueryOptions,
|
|
123
|
+
UseInfiniteQueryOptions,
|
|
124
|
+
InfiniteData,
|
|
125
|
+
} from '@tanstack/react-query';
|
|
126
|
+
import type {
|
|
127
|
+
GetItemsRequest,
|
|
128
|
+
GetItemsError,
|
|
129
|
+
GetItems200Response,
|
|
130
|
+
} from './types.gen.js';
|
|
131
|
+
import { TestApi } from './client.gen.js';
|
|
132
|
+
|
|
133
|
+
export interface TestApiOptionsProxyConfig {
|
|
134
|
+
client: TestApi;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export class TestApiOptionsProxy {
|
|
138
|
+
private $client: TestApi;
|
|
139
|
+
|
|
140
|
+
constructor({ client }: TestApiOptionsProxyConfig) {
|
|
141
|
+
this.$client = client;
|
|
142
|
+
|
|
143
|
+
this._getItemsQueryKey = this._getItemsQueryKey.bind(this);
|
|
144
|
+
this._getItemsQueryOptions = this._getItemsQueryOptions.bind(this);
|
|
145
|
+
this._getItemsQueryFilter = this._getItemsQueryFilter.bind(this);
|
|
146
|
+
this._getItemsInfiniteQueryOptions =
|
|
147
|
+
this._getItemsInfiniteQueryOptions.bind(this);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
public queryKey = () => ['TestApi'];
|
|
151
|
+
|
|
152
|
+
private _getItemsQueryKey(input: GetItemsRequest) {
|
|
153
|
+
return [...this.queryKey(), 'getItems', input];
|
|
154
|
+
}
|
|
155
|
+
private _getItemsQueryOptions(
|
|
156
|
+
input: GetItemsRequest,
|
|
157
|
+
options?: Omit<
|
|
158
|
+
UseQueryOptions<GetItems200Response, GetItemsError>,
|
|
159
|
+
'queryFn' | 'queryKey'
|
|
160
|
+
> &
|
|
161
|
+
Partial<
|
|
162
|
+
Pick<
|
|
163
|
+
UseQueryOptions<GetItems200Response, GetItemsError>,
|
|
164
|
+
'queryFn' | 'queryKey'
|
|
165
|
+
>
|
|
166
|
+
>,
|
|
167
|
+
): UseQueryOptions<GetItems200Response, GetItemsError> {
|
|
168
|
+
return {
|
|
169
|
+
queryFn: () => this.$client.getItems(input),
|
|
170
|
+
queryKey: this._getItemsQueryKey(input),
|
|
171
|
+
...options,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
private _getItemsQueryFilter(
|
|
175
|
+
input: GetItemsRequest,
|
|
176
|
+
filter?: QueryFilters<GetItems200Response, GetItemsError>,
|
|
177
|
+
): QueryFilters<GetItems200Response, GetItemsError> {
|
|
178
|
+
return {
|
|
179
|
+
queryKey: this._getItemsQueryKey(input),
|
|
180
|
+
...filter,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
private _getItemsInfiniteQueryOptions(
|
|
184
|
+
input: GetItemsRequest,
|
|
185
|
+
options: Omit<
|
|
186
|
+
UseInfiniteQueryOptions<
|
|
187
|
+
GetItems200Response,
|
|
188
|
+
GetItemsError,
|
|
189
|
+
InfiniteData<GetItems200Response>,
|
|
190
|
+
GetItems200Response,
|
|
191
|
+
unknown[],
|
|
192
|
+
string | undefined | null
|
|
193
|
+
>,
|
|
194
|
+
'queryFn' | 'queryKey' | 'initialPageParam'
|
|
195
|
+
> &
|
|
196
|
+
Partial<
|
|
197
|
+
Pick<
|
|
198
|
+
UseInfiniteQueryOptions<
|
|
199
|
+
GetItems200Response,
|
|
200
|
+
GetItemsError,
|
|
201
|
+
InfiniteData<GetItems200Response>,
|
|
202
|
+
GetItems200Response,
|
|
203
|
+
unknown[],
|
|
204
|
+
string | undefined | null
|
|
205
|
+
>,
|
|
206
|
+
'queryFn' | 'queryKey' | 'initialPageParam'
|
|
207
|
+
>
|
|
208
|
+
>,
|
|
209
|
+
): UseInfiniteQueryOptions<
|
|
210
|
+
GetItems200Response,
|
|
211
|
+
GetItemsError,
|
|
212
|
+
InfiniteData<GetItems200Response>,
|
|
213
|
+
GetItems200Response,
|
|
214
|
+
unknown[],
|
|
215
|
+
string | undefined | null
|
|
216
|
+
> {
|
|
217
|
+
return {
|
|
218
|
+
queryKey: this._getItemsQueryKey(input),
|
|
219
|
+
queryFn: ({ pageParam }) =>
|
|
220
|
+
this.$client.getItems({ ...input, cursor: pageParam as any }),
|
|
221
|
+
initialPageParam: undefined,
|
|
222
|
+
...options,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
public getItems = {
|
|
227
|
+
queryKey: this._getItemsQueryKey.bind(this),
|
|
228
|
+
queryOptions: this._getItemsQueryOptions.bind(this),
|
|
229
|
+
queryFilter: this._getItemsQueryFilter.bind(this),
|
|
230
|
+
infiniteQueryOptions: this._getItemsInfiniteQueryOptions.bind(this),
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
"
|
|
234
|
+
`;
|
|
235
|
+
|
|
236
|
+
exports[`openApiTsHooksGenerator > should handle GET operation with x-mutation: true correctly 1`] = `
|
|
237
|
+
"import type { UseMutationOptions } from '@tanstack/react-query';
|
|
238
|
+
import type {
|
|
239
|
+
TriggerActionRequest,
|
|
240
|
+
TriggerActionError,
|
|
241
|
+
TriggerAction200Response,
|
|
242
|
+
} from './types.gen.js';
|
|
243
|
+
import { TestApi } from './client.gen.js';
|
|
244
|
+
|
|
245
|
+
export interface TestApiOptionsProxyConfig {
|
|
246
|
+
client: TestApi;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export class TestApiOptionsProxy {
|
|
250
|
+
private $client: TestApi;
|
|
251
|
+
|
|
252
|
+
constructor({ client }: TestApiOptionsProxyConfig) {
|
|
253
|
+
this.$client = client;
|
|
254
|
+
|
|
255
|
+
this._triggerActionMutationKey = this._triggerActionMutationKey.bind(this);
|
|
256
|
+
this._triggerActionMutationOptions =
|
|
257
|
+
this._triggerActionMutationOptions.bind(this);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
public queryKey = () => ['TestApi'];
|
|
261
|
+
|
|
262
|
+
private _triggerActionMutationKey() {
|
|
263
|
+
return [...this.queryKey(), 'triggerAction'];
|
|
264
|
+
}
|
|
265
|
+
private _triggerActionMutationOptions(
|
|
266
|
+
options?: UseMutationOptions<
|
|
267
|
+
TriggerAction200Response,
|
|
268
|
+
TriggerActionError,
|
|
269
|
+
TriggerActionRequest
|
|
270
|
+
>,
|
|
271
|
+
): UseMutationOptions<
|
|
272
|
+
TriggerAction200Response,
|
|
273
|
+
TriggerActionError,
|
|
274
|
+
TriggerActionRequest
|
|
275
|
+
> {
|
|
276
|
+
return {
|
|
277
|
+
mutationFn: (input) => this.$client.triggerAction(input),
|
|
278
|
+
mutationKey: this._triggerActionMutationKey(),
|
|
279
|
+
...options,
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
public triggerAction = {
|
|
284
|
+
mutationKey: this._triggerActionMutationKey.bind(this),
|
|
285
|
+
mutationOptions: this._triggerActionMutationOptions.bind(this),
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
"
|
|
289
|
+
`;
|
|
290
|
+
|
|
291
|
+
exports[`openApiTsHooksGenerator > should handle POST operation with x-query: true correctly 1`] = `
|
|
292
|
+
"import type { QueryFilters, UseQueryOptions } from '@tanstack/react-query';
|
|
293
|
+
import type {
|
|
294
|
+
SearchDataRequest,
|
|
295
|
+
SearchDataError,
|
|
296
|
+
SearchData200Response,
|
|
297
|
+
} from './types.gen.js';
|
|
298
|
+
import { TestApi } from './client.gen.js';
|
|
299
|
+
|
|
300
|
+
export interface TestApiOptionsProxyConfig {
|
|
301
|
+
client: TestApi;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export class TestApiOptionsProxy {
|
|
305
|
+
private $client: TestApi;
|
|
306
|
+
|
|
307
|
+
constructor({ client }: TestApiOptionsProxyConfig) {
|
|
308
|
+
this.$client = client;
|
|
309
|
+
|
|
310
|
+
this._searchDataQueryKey = this._searchDataQueryKey.bind(this);
|
|
311
|
+
this._searchDataQueryOptions = this._searchDataQueryOptions.bind(this);
|
|
312
|
+
this._searchDataQueryFilter = this._searchDataQueryFilter.bind(this);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
public queryKey = () => ['TestApi'];
|
|
316
|
+
|
|
317
|
+
private _searchDataQueryKey(input: SearchDataRequest) {
|
|
318
|
+
return [...this.queryKey(), 'searchData', input];
|
|
319
|
+
}
|
|
320
|
+
private _searchDataQueryOptions(
|
|
321
|
+
input: SearchDataRequest,
|
|
322
|
+
options?: Omit<
|
|
323
|
+
UseQueryOptions<SearchData200Response, SearchDataError>,
|
|
324
|
+
'queryFn' | 'queryKey'
|
|
325
|
+
> &
|
|
326
|
+
Partial<
|
|
327
|
+
Pick<
|
|
328
|
+
UseQueryOptions<SearchData200Response, SearchDataError>,
|
|
329
|
+
'queryFn' | 'queryKey'
|
|
330
|
+
>
|
|
331
|
+
>,
|
|
332
|
+
): UseQueryOptions<SearchData200Response, SearchDataError> {
|
|
333
|
+
return {
|
|
334
|
+
queryFn: () => this.$client.searchData(input),
|
|
335
|
+
queryKey: this._searchDataQueryKey(input),
|
|
336
|
+
...options,
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
private _searchDataQueryFilter(
|
|
340
|
+
input: SearchDataRequest,
|
|
341
|
+
filter?: QueryFilters<SearchData200Response, SearchDataError>,
|
|
342
|
+
): QueryFilters<SearchData200Response, SearchDataError> {
|
|
343
|
+
return {
|
|
344
|
+
queryKey: this._searchDataQueryKey(input),
|
|
345
|
+
...filter,
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
public searchData = {
|
|
350
|
+
queryKey: this._searchDataQueryKey.bind(this),
|
|
351
|
+
queryOptions: this._searchDataQueryOptions.bind(this),
|
|
352
|
+
queryFilter: this._searchDataQueryFilter.bind(this),
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
"
|
|
356
|
+
`;
|
|
357
|
+
|
|
358
|
+
exports[`openApiTsHooksGenerator > should handle infinite query errors correctly 1`] = `
|
|
359
|
+
"import type {
|
|
360
|
+
QueryFilters,
|
|
361
|
+
UseQueryOptions,
|
|
362
|
+
UseInfiniteQueryOptions,
|
|
363
|
+
InfiniteData,
|
|
364
|
+
} from '@tanstack/react-query';
|
|
365
|
+
import type {
|
|
366
|
+
GetItemsRequest,
|
|
367
|
+
GetItemsError,
|
|
368
|
+
GetItems200Response,
|
|
369
|
+
} from './types.gen.js';
|
|
370
|
+
import { TestApi } from './client.gen.js';
|
|
371
|
+
|
|
372
|
+
export interface TestApiOptionsProxyConfig {
|
|
373
|
+
client: TestApi;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
export class TestApiOptionsProxy {
|
|
377
|
+
private $client: TestApi;
|
|
378
|
+
|
|
379
|
+
constructor({ client }: TestApiOptionsProxyConfig) {
|
|
380
|
+
this.$client = client;
|
|
381
|
+
|
|
382
|
+
this._getItemsQueryKey = this._getItemsQueryKey.bind(this);
|
|
383
|
+
this._getItemsQueryOptions = this._getItemsQueryOptions.bind(this);
|
|
384
|
+
this._getItemsQueryFilter = this._getItemsQueryFilter.bind(this);
|
|
385
|
+
this._getItemsInfiniteQueryOptions =
|
|
386
|
+
this._getItemsInfiniteQueryOptions.bind(this);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
public queryKey = () => ['TestApi'];
|
|
390
|
+
|
|
391
|
+
private _getItemsQueryKey(input: GetItemsRequest) {
|
|
392
|
+
return [...this.queryKey(), 'getItems', input];
|
|
393
|
+
}
|
|
394
|
+
private _getItemsQueryOptions(
|
|
395
|
+
input: GetItemsRequest,
|
|
396
|
+
options?: Omit<
|
|
397
|
+
UseQueryOptions<GetItems200Response, GetItemsError>,
|
|
398
|
+
'queryFn' | 'queryKey'
|
|
399
|
+
> &
|
|
400
|
+
Partial<
|
|
401
|
+
Pick<
|
|
402
|
+
UseQueryOptions<GetItems200Response, GetItemsError>,
|
|
403
|
+
'queryFn' | 'queryKey'
|
|
404
|
+
>
|
|
405
|
+
>,
|
|
406
|
+
): UseQueryOptions<GetItems200Response, GetItemsError> {
|
|
407
|
+
return {
|
|
408
|
+
queryFn: () => this.$client.getItems(input),
|
|
409
|
+
queryKey: this._getItemsQueryKey(input),
|
|
410
|
+
...options,
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
private _getItemsQueryFilter(
|
|
414
|
+
input: GetItemsRequest,
|
|
415
|
+
filter?: QueryFilters<GetItems200Response, GetItemsError>,
|
|
416
|
+
): QueryFilters<GetItems200Response, GetItemsError> {
|
|
417
|
+
return {
|
|
418
|
+
queryKey: this._getItemsQueryKey(input),
|
|
419
|
+
...filter,
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
private _getItemsInfiniteQueryOptions(
|
|
423
|
+
input: GetItemsRequest,
|
|
424
|
+
options: Omit<
|
|
425
|
+
UseInfiniteQueryOptions<
|
|
426
|
+
GetItems200Response,
|
|
427
|
+
GetItemsError,
|
|
428
|
+
InfiniteData<GetItems200Response>,
|
|
429
|
+
GetItems200Response,
|
|
430
|
+
unknown[],
|
|
431
|
+
string | undefined | null
|
|
432
|
+
>,
|
|
433
|
+
'queryFn' | 'queryKey' | 'initialPageParam'
|
|
434
|
+
> &
|
|
435
|
+
Partial<
|
|
436
|
+
Pick<
|
|
437
|
+
UseInfiniteQueryOptions<
|
|
438
|
+
GetItems200Response,
|
|
439
|
+
GetItemsError,
|
|
440
|
+
InfiniteData<GetItems200Response>,
|
|
441
|
+
GetItems200Response,
|
|
442
|
+
unknown[],
|
|
443
|
+
string | undefined | null
|
|
444
|
+
>,
|
|
445
|
+
'queryFn' | 'queryKey' | 'initialPageParam'
|
|
446
|
+
>
|
|
447
|
+
>,
|
|
448
|
+
): UseInfiniteQueryOptions<
|
|
449
|
+
GetItems200Response,
|
|
450
|
+
GetItemsError,
|
|
451
|
+
InfiniteData<GetItems200Response>,
|
|
452
|
+
GetItems200Response,
|
|
453
|
+
unknown[],
|
|
454
|
+
string | undefined | null
|
|
455
|
+
> {
|
|
456
|
+
return {
|
|
457
|
+
queryKey: this._getItemsQueryKey(input),
|
|
458
|
+
queryFn: ({ pageParam }) =>
|
|
459
|
+
this.$client.getItems({ ...input, cursor: pageParam as any }),
|
|
460
|
+
initialPageParam: undefined,
|
|
461
|
+
...options,
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
public getItems = {
|
|
466
|
+
queryKey: this._getItemsQueryKey.bind(this),
|
|
467
|
+
queryOptions: this._getItemsQueryOptions.bind(this),
|
|
468
|
+
queryFilter: this._getItemsQueryFilter.bind(this),
|
|
469
|
+
infiniteQueryOptions: this._getItemsInfiniteQueryOptions.bind(this),
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
"
|
|
473
|
+
`;
|
|
474
|
+
|
|
475
|
+
exports[`openApiTsHooksGenerator > should handle infinite query with custom cursor parameter 1`] = `
|
|
476
|
+
"import type {
|
|
477
|
+
QueryFilters,
|
|
478
|
+
UseQueryOptions,
|
|
479
|
+
UseInfiniteQueryOptions,
|
|
480
|
+
InfiniteData,
|
|
481
|
+
} from '@tanstack/react-query';
|
|
482
|
+
import type {
|
|
483
|
+
ListRecordsRequest,
|
|
484
|
+
ListRecordsError,
|
|
485
|
+
ListRecords200Response,
|
|
486
|
+
} from './types.gen.js';
|
|
487
|
+
import { TestApi } from './client.gen.js';
|
|
488
|
+
|
|
489
|
+
export interface TestApiOptionsProxyConfig {
|
|
490
|
+
client: TestApi;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
export class TestApiOptionsProxy {
|
|
494
|
+
private $client: TestApi;
|
|
495
|
+
|
|
496
|
+
constructor({ client }: TestApiOptionsProxyConfig) {
|
|
497
|
+
this.$client = client;
|
|
498
|
+
|
|
499
|
+
this._listRecordsQueryKey = this._listRecordsQueryKey.bind(this);
|
|
500
|
+
this._listRecordsQueryOptions = this._listRecordsQueryOptions.bind(this);
|
|
501
|
+
this._listRecordsQueryFilter = this._listRecordsQueryFilter.bind(this);
|
|
502
|
+
this._listRecordsInfiniteQueryOptions =
|
|
503
|
+
this._listRecordsInfiniteQueryOptions.bind(this);
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
public queryKey = () => ['TestApi'];
|
|
507
|
+
|
|
508
|
+
private _listRecordsQueryKey(input: ListRecordsRequest) {
|
|
509
|
+
return [...this.queryKey(), 'listRecords', input];
|
|
510
|
+
}
|
|
511
|
+
private _listRecordsQueryOptions(
|
|
512
|
+
input: ListRecordsRequest,
|
|
513
|
+
options?: Omit<
|
|
514
|
+
UseQueryOptions<ListRecords200Response, ListRecordsError>,
|
|
515
|
+
'queryFn' | 'queryKey'
|
|
516
|
+
> &
|
|
517
|
+
Partial<
|
|
518
|
+
Pick<
|
|
519
|
+
UseQueryOptions<ListRecords200Response, ListRecordsError>,
|
|
520
|
+
'queryFn' | 'queryKey'
|
|
521
|
+
>
|
|
522
|
+
>,
|
|
523
|
+
): UseQueryOptions<ListRecords200Response, ListRecordsError> {
|
|
524
|
+
return {
|
|
525
|
+
queryFn: () => this.$client.listRecords(input),
|
|
526
|
+
queryKey: this._listRecordsQueryKey(input),
|
|
527
|
+
...options,
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
private _listRecordsQueryFilter(
|
|
531
|
+
input: ListRecordsRequest,
|
|
532
|
+
filter?: QueryFilters<ListRecords200Response, ListRecordsError>,
|
|
533
|
+
): QueryFilters<ListRecords200Response, ListRecordsError> {
|
|
534
|
+
return {
|
|
535
|
+
queryKey: this._listRecordsQueryKey(input),
|
|
536
|
+
...filter,
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
private _listRecordsInfiniteQueryOptions(
|
|
540
|
+
input: ListRecordsRequest,
|
|
541
|
+
options: Omit<
|
|
542
|
+
UseInfiniteQueryOptions<
|
|
543
|
+
ListRecords200Response,
|
|
544
|
+
ListRecordsError,
|
|
545
|
+
InfiniteData<ListRecords200Response>,
|
|
546
|
+
ListRecords200Response,
|
|
547
|
+
unknown[],
|
|
548
|
+
string | undefined | null
|
|
549
|
+
>,
|
|
550
|
+
'queryFn' | 'queryKey' | 'initialPageParam'
|
|
551
|
+
> &
|
|
552
|
+
Partial<
|
|
553
|
+
Pick<
|
|
554
|
+
UseInfiniteQueryOptions<
|
|
555
|
+
ListRecords200Response,
|
|
556
|
+
ListRecordsError,
|
|
557
|
+
InfiniteData<ListRecords200Response>,
|
|
558
|
+
ListRecords200Response,
|
|
559
|
+
unknown[],
|
|
560
|
+
string | undefined | null
|
|
561
|
+
>,
|
|
562
|
+
'queryFn' | 'queryKey' | 'initialPageParam'
|
|
563
|
+
>
|
|
564
|
+
>,
|
|
565
|
+
): UseInfiniteQueryOptions<
|
|
566
|
+
ListRecords200Response,
|
|
567
|
+
ListRecordsError,
|
|
568
|
+
InfiniteData<ListRecords200Response>,
|
|
569
|
+
ListRecords200Response,
|
|
570
|
+
unknown[],
|
|
571
|
+
string | undefined | null
|
|
572
|
+
> {
|
|
573
|
+
return {
|
|
574
|
+
queryKey: this._listRecordsQueryKey(input),
|
|
575
|
+
queryFn: ({ pageParam }) =>
|
|
576
|
+
this.$client.listRecords({ ...input, nextToken: pageParam as any }),
|
|
577
|
+
initialPageParam: undefined,
|
|
578
|
+
...options,
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
public listRecords = {
|
|
583
|
+
queryKey: this._listRecordsQueryKey.bind(this),
|
|
584
|
+
queryOptions: this._listRecordsQueryOptions.bind(this),
|
|
585
|
+
queryFilter: this._listRecordsQueryFilter.bind(this),
|
|
586
|
+
infiniteQueryOptions: this._listRecordsInfiniteQueryOptions.bind(this),
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
"
|
|
590
|
+
`;
|
|
591
|
+
|
|
592
|
+
exports[`openApiTsHooksGenerator > should handle mutation errors correctly 1`] = `
|
|
593
|
+
"import type { UseMutationOptions } from '@tanstack/react-query';
|
|
594
|
+
import type {
|
|
595
|
+
CreateUserRequest,
|
|
596
|
+
CreateUserError,
|
|
597
|
+
CreateUser201Response,
|
|
598
|
+
} from './types.gen.js';
|
|
599
|
+
import { TestApi } from './client.gen.js';
|
|
600
|
+
|
|
601
|
+
export interface TestApiOptionsProxyConfig {
|
|
602
|
+
client: TestApi;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
export class TestApiOptionsProxy {
|
|
606
|
+
private $client: TestApi;
|
|
607
|
+
|
|
608
|
+
constructor({ client }: TestApiOptionsProxyConfig) {
|
|
609
|
+
this.$client = client;
|
|
610
|
+
|
|
611
|
+
this._createUserMutationKey = this._createUserMutationKey.bind(this);
|
|
612
|
+
this._createUserMutationOptions =
|
|
613
|
+
this._createUserMutationOptions.bind(this);
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
public queryKey = () => ['TestApi'];
|
|
617
|
+
|
|
618
|
+
private _createUserMutationKey() {
|
|
619
|
+
return [...this.queryKey(), 'createUser'];
|
|
620
|
+
}
|
|
621
|
+
private _createUserMutationOptions(
|
|
622
|
+
options?: UseMutationOptions<
|
|
623
|
+
CreateUser201Response,
|
|
624
|
+
CreateUserError,
|
|
625
|
+
CreateUserRequest
|
|
626
|
+
>,
|
|
627
|
+
): UseMutationOptions<
|
|
628
|
+
CreateUser201Response,
|
|
629
|
+
CreateUserError,
|
|
630
|
+
CreateUserRequest
|
|
631
|
+
> {
|
|
632
|
+
return {
|
|
633
|
+
mutationFn: (input) => this.$client.createUser(input),
|
|
634
|
+
mutationKey: this._createUserMutationKey(),
|
|
635
|
+
...options,
|
|
636
|
+
};
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
public createUser = {
|
|
640
|
+
mutationKey: this._createUserMutationKey.bind(this),
|
|
641
|
+
mutationOptions: this._createUserMutationOptions.bind(this),
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
"
|
|
645
|
+
`;
|
|
646
|
+
|
|
647
|
+
exports[`openApiTsHooksGenerator > should handle query errors correctly 1`] = `
|
|
648
|
+
"import type { QueryFilters, UseQueryOptions } from '@tanstack/react-query';
|
|
649
|
+
import type { GetErrorError, GetError200Response } from './types.gen.js';
|
|
650
|
+
import { TestApi } from './client.gen.js';
|
|
651
|
+
|
|
652
|
+
export interface TestApiOptionsProxyConfig {
|
|
653
|
+
client: TestApi;
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
export class TestApiOptionsProxy {
|
|
657
|
+
private $client: TestApi;
|
|
658
|
+
|
|
659
|
+
constructor({ client }: TestApiOptionsProxyConfig) {
|
|
660
|
+
this.$client = client;
|
|
661
|
+
|
|
662
|
+
this._getErrorQueryKey = this._getErrorQueryKey.bind(this);
|
|
663
|
+
this._getErrorQueryOptions = this._getErrorQueryOptions.bind(this);
|
|
664
|
+
this._getErrorQueryFilter = this._getErrorQueryFilter.bind(this);
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
public queryKey = () => ['TestApi'];
|
|
668
|
+
|
|
669
|
+
private _getErrorQueryKey() {
|
|
670
|
+
return [...this.queryKey(), 'getError'];
|
|
671
|
+
}
|
|
672
|
+
private _getErrorQueryOptions(
|
|
673
|
+
options?: Omit<
|
|
674
|
+
UseQueryOptions<GetError200Response, GetErrorError>,
|
|
675
|
+
'queryFn' | 'queryKey'
|
|
676
|
+
> &
|
|
677
|
+
Partial<
|
|
678
|
+
Pick<
|
|
679
|
+
UseQueryOptions<GetError200Response, GetErrorError>,
|
|
680
|
+
'queryFn' | 'queryKey'
|
|
681
|
+
>
|
|
682
|
+
>,
|
|
683
|
+
): UseQueryOptions<GetError200Response, GetErrorError> {
|
|
684
|
+
return {
|
|
685
|
+
queryFn: () => this.$client.getError(),
|
|
686
|
+
queryKey: this._getErrorQueryKey(),
|
|
687
|
+
...options,
|
|
688
|
+
};
|
|
689
|
+
}
|
|
690
|
+
private _getErrorQueryFilter(
|
|
691
|
+
filter?: QueryFilters<GetError200Response, GetErrorError>,
|
|
692
|
+
): QueryFilters<GetError200Response, GetErrorError> {
|
|
693
|
+
return {
|
|
694
|
+
queryKey: this._getErrorQueryKey(),
|
|
695
|
+
...filter,
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
public getError = {
|
|
700
|
+
queryKey: this._getErrorQueryKey.bind(this),
|
|
701
|
+
queryOptions: this._getErrorQueryOptions.bind(this),
|
|
702
|
+
queryFilter: this._getErrorQueryFilter.bind(this),
|
|
703
|
+
};
|
|
704
|
+
}
|
|
705
|
+
"
|
|
706
|
+
`;
|
|
707
|
+
|
|
708
|
+
exports[`openApiTsHooksGenerator > should handle streaming infinite query operation correctly 1`] = `
|
|
709
|
+
"import type {
|
|
710
|
+
QueryFilters,
|
|
711
|
+
UseQueryOptions,
|
|
712
|
+
UseInfiniteQueryOptions,
|
|
713
|
+
InfiniteData,
|
|
714
|
+
QueryFunctionContext,
|
|
715
|
+
} from '@tanstack/react-query';
|
|
716
|
+
import type {
|
|
717
|
+
StreamLogsRequest,
|
|
718
|
+
StreamLogsError,
|
|
719
|
+
StreamLogs200Response,
|
|
720
|
+
} from './types.gen.js';
|
|
721
|
+
import { TestApi } from './client.gen.js';
|
|
722
|
+
|
|
723
|
+
export interface TestApiOptionsProxyConfig {
|
|
724
|
+
client: TestApi;
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
export class TestApiOptionsProxy {
|
|
728
|
+
private $client: TestApi;
|
|
729
|
+
|
|
730
|
+
constructor({ client }: TestApiOptionsProxyConfig) {
|
|
731
|
+
this.$client = client;
|
|
732
|
+
|
|
733
|
+
this._streamLogsQueryKey = this._streamLogsQueryKey.bind(this);
|
|
734
|
+
this._streamLogsQueryOptions = this._streamLogsQueryOptions.bind(this);
|
|
735
|
+
this._streamLogsQueryFilter = this._streamLogsQueryFilter.bind(this);
|
|
736
|
+
this._streamLogsInfiniteQueryOptions =
|
|
737
|
+
this._streamLogsInfiniteQueryOptions.bind(this);
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
protected async $queryStream<T>(
|
|
741
|
+
context: QueryFunctionContext<any>,
|
|
742
|
+
stream: AsyncIterable<T>,
|
|
743
|
+
): Promise<T[]> {
|
|
744
|
+
const query = context.client
|
|
745
|
+
.getQueryCache()
|
|
746
|
+
.find({ queryKey: context.queryKey, exact: true });
|
|
747
|
+
|
|
748
|
+
if (query && query.state.data !== undefined) {
|
|
749
|
+
query.setState({
|
|
750
|
+
status: 'pending',
|
|
751
|
+
data: undefined,
|
|
752
|
+
error: null,
|
|
753
|
+
fetchStatus: 'fetching',
|
|
754
|
+
});
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
const chunks: T[] = [];
|
|
758
|
+
for await (const chunk of stream) {
|
|
759
|
+
if (context.signal.aborted) {
|
|
760
|
+
break;
|
|
761
|
+
}
|
|
762
|
+
chunks.push(chunk);
|
|
763
|
+
query?.setState({
|
|
764
|
+
status: 'success',
|
|
765
|
+
fetchStatus: 'fetching',
|
|
766
|
+
});
|
|
767
|
+
context.client.setQueryData<T[]>(context.queryKey, (prev = []) =>
|
|
768
|
+
prev.concat(chunk),
|
|
769
|
+
);
|
|
770
|
+
}
|
|
771
|
+
query?.setState({
|
|
772
|
+
fetchStatus: 'idle',
|
|
773
|
+
});
|
|
774
|
+
return chunks;
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
protected async $waitForStream<T>(iterable: AsyncIterable<T>) {
|
|
778
|
+
const chunks: T[] = [];
|
|
779
|
+
for await (const chunk of iterable) {
|
|
780
|
+
chunks.push(chunk);
|
|
781
|
+
}
|
|
782
|
+
return chunks;
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
public queryKey = () => ['TestApi'];
|
|
786
|
+
|
|
787
|
+
private _streamLogsQueryKey(input: StreamLogsRequest) {
|
|
788
|
+
return [...this.queryKey(), 'streamLogs', input];
|
|
789
|
+
}
|
|
790
|
+
private _streamLogsQueryOptions(
|
|
791
|
+
input: StreamLogsRequest,
|
|
792
|
+
options?: Omit<
|
|
793
|
+
UseQueryOptions<StreamLogs200Response[], StreamLogsError>,
|
|
794
|
+
'queryFn' | 'queryKey'
|
|
795
|
+
> &
|
|
796
|
+
Partial<
|
|
797
|
+
Pick<
|
|
798
|
+
UseQueryOptions<StreamLogs200Response[], StreamLogsError>,
|
|
799
|
+
'queryFn' | 'queryKey'
|
|
800
|
+
>
|
|
801
|
+
>,
|
|
802
|
+
): UseQueryOptions<StreamLogs200Response[], StreamLogsError> {
|
|
803
|
+
return {
|
|
804
|
+
queryFn: (context) =>
|
|
805
|
+
this.$queryStream(context, this.$client.streamLogs(input)),
|
|
806
|
+
queryKey: this._streamLogsQueryKey(input),
|
|
807
|
+
...options,
|
|
808
|
+
};
|
|
809
|
+
}
|
|
810
|
+
private _streamLogsQueryFilter(
|
|
811
|
+
input: StreamLogsRequest,
|
|
812
|
+
filter?: QueryFilters<StreamLogs200Response[], StreamLogsError>,
|
|
813
|
+
): QueryFilters<StreamLogs200Response[], StreamLogsError> {
|
|
814
|
+
return {
|
|
815
|
+
queryKey: this._streamLogsQueryKey(input),
|
|
816
|
+
...filter,
|
|
817
|
+
};
|
|
818
|
+
}
|
|
819
|
+
private _streamLogsInfiniteQueryOptions(
|
|
820
|
+
input: StreamLogsRequest,
|
|
821
|
+
options: Omit<
|
|
822
|
+
UseInfiniteQueryOptions<
|
|
823
|
+
StreamLogs200Response[],
|
|
824
|
+
StreamLogsError,
|
|
825
|
+
InfiniteData<StreamLogs200Response[]>,
|
|
826
|
+
StreamLogs200Response[],
|
|
827
|
+
unknown[],
|
|
828
|
+
string | undefined | null
|
|
829
|
+
>,
|
|
830
|
+
'queryFn' | 'queryKey' | 'initialPageParam'
|
|
831
|
+
> &
|
|
832
|
+
Partial<
|
|
833
|
+
Pick<
|
|
834
|
+
UseInfiniteQueryOptions<
|
|
835
|
+
StreamLogs200Response[],
|
|
836
|
+
StreamLogsError,
|
|
837
|
+
InfiniteData<StreamLogs200Response[]>,
|
|
838
|
+
StreamLogs200Response[],
|
|
839
|
+
unknown[],
|
|
840
|
+
string | undefined | null
|
|
841
|
+
>,
|
|
842
|
+
'queryFn' | 'queryKey' | 'initialPageParam'
|
|
843
|
+
>
|
|
844
|
+
>,
|
|
845
|
+
): UseInfiniteQueryOptions<
|
|
846
|
+
StreamLogs200Response[],
|
|
847
|
+
StreamLogsError,
|
|
848
|
+
InfiniteData<StreamLogs200Response[]>,
|
|
849
|
+
StreamLogs200Response[],
|
|
850
|
+
unknown[],
|
|
851
|
+
string | undefined | null
|
|
852
|
+
> {
|
|
853
|
+
return {
|
|
854
|
+
queryKey: this._streamLogsQueryKey(input),
|
|
855
|
+
queryFn: ({ pageParam }) =>
|
|
856
|
+
this.$waitForStream(
|
|
857
|
+
this.$client.streamLogs({ ...input, cursor: pageParam as any }),
|
|
858
|
+
),
|
|
859
|
+
initialPageParam: undefined,
|
|
860
|
+
...options,
|
|
861
|
+
};
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
public streamLogs = {
|
|
865
|
+
queryKey: this._streamLogsQueryKey.bind(this),
|
|
866
|
+
queryOptions: this._streamLogsQueryOptions.bind(this),
|
|
867
|
+
queryFilter: this._streamLogsQueryFilter.bind(this),
|
|
868
|
+
infiniteQueryOptions: this._streamLogsInfiniteQueryOptions.bind(this),
|
|
869
|
+
};
|
|
870
|
+
}
|
|
871
|
+
"
|
|
872
|
+
`;
|
|
873
|
+
|
|
874
|
+
exports[`openApiTsHooksGenerator > should handle streaming mutation operation correctly 1`] = `
|
|
875
|
+
"import type {
|
|
876
|
+
UseMutationOptions,
|
|
877
|
+
QueryFunctionContext,
|
|
878
|
+
} from '@tanstack/react-query';
|
|
879
|
+
import type {
|
|
880
|
+
UploadStreamRequest,
|
|
881
|
+
UploadStreamError,
|
|
882
|
+
UploadStream200Response,
|
|
883
|
+
} from './types.gen.js';
|
|
884
|
+
import { TestApi } from './client.gen.js';
|
|
885
|
+
|
|
886
|
+
export interface TestApiOptionsProxyConfig {
|
|
887
|
+
client: TestApi;
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
export class TestApiOptionsProxy {
|
|
891
|
+
private $client: TestApi;
|
|
892
|
+
|
|
893
|
+
constructor({ client }: TestApiOptionsProxyConfig) {
|
|
894
|
+
this.$client = client;
|
|
895
|
+
|
|
896
|
+
this._uploadStreamMutationKey = this._uploadStreamMutationKey.bind(this);
|
|
897
|
+
this._uploadStreamMutationOptions =
|
|
898
|
+
this._uploadStreamMutationOptions.bind(this);
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
protected async $queryStream<T>(
|
|
902
|
+
context: QueryFunctionContext<any>,
|
|
903
|
+
stream: AsyncIterable<T>,
|
|
904
|
+
): Promise<T[]> {
|
|
905
|
+
const query = context.client
|
|
906
|
+
.getQueryCache()
|
|
907
|
+
.find({ queryKey: context.queryKey, exact: true });
|
|
908
|
+
|
|
909
|
+
if (query && query.state.data !== undefined) {
|
|
910
|
+
query.setState({
|
|
911
|
+
status: 'pending',
|
|
912
|
+
data: undefined,
|
|
913
|
+
error: null,
|
|
914
|
+
fetchStatus: 'fetching',
|
|
915
|
+
});
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
const chunks: T[] = [];
|
|
919
|
+
for await (const chunk of stream) {
|
|
920
|
+
if (context.signal.aborted) {
|
|
921
|
+
break;
|
|
922
|
+
}
|
|
923
|
+
chunks.push(chunk);
|
|
924
|
+
query?.setState({
|
|
925
|
+
status: 'success',
|
|
926
|
+
fetchStatus: 'fetching',
|
|
927
|
+
});
|
|
928
|
+
context.client.setQueryData<T[]>(context.queryKey, (prev = []) =>
|
|
929
|
+
prev.concat(chunk),
|
|
930
|
+
);
|
|
931
|
+
}
|
|
932
|
+
query?.setState({
|
|
933
|
+
fetchStatus: 'idle',
|
|
934
|
+
});
|
|
935
|
+
return chunks;
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
protected async $waitForStream<T>(iterable: AsyncIterable<T>) {
|
|
939
|
+
const chunks: T[] = [];
|
|
940
|
+
for await (const chunk of iterable) {
|
|
941
|
+
chunks.push(chunk);
|
|
942
|
+
}
|
|
943
|
+
return chunks;
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
public queryKey = () => ['TestApi'];
|
|
947
|
+
|
|
948
|
+
private _uploadStreamMutationKey() {
|
|
949
|
+
return [...this.queryKey(), 'uploadStream'];
|
|
950
|
+
}
|
|
951
|
+
private _uploadStreamMutationOptions(
|
|
952
|
+
options?: UseMutationOptions<
|
|
953
|
+
AsyncIterableIterator<UploadStream200Response>,
|
|
954
|
+
UploadStreamError,
|
|
955
|
+
UploadStreamRequest
|
|
956
|
+
>,
|
|
957
|
+
): UseMutationOptions<
|
|
958
|
+
AsyncIterableIterator<UploadStream200Response>,
|
|
959
|
+
UploadStreamError,
|
|
960
|
+
UploadStreamRequest
|
|
961
|
+
> {
|
|
962
|
+
return {
|
|
963
|
+
mutationFn: async (input) => this.$client.uploadStream(input),
|
|
964
|
+
mutationKey: this._uploadStreamMutationKey(),
|
|
965
|
+
...options,
|
|
966
|
+
};
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
public uploadStream = {
|
|
970
|
+
mutationKey: this._uploadStreamMutationKey.bind(this),
|
|
971
|
+
mutationOptions: this._uploadStreamMutationOptions.bind(this),
|
|
972
|
+
};
|
|
973
|
+
}
|
|
974
|
+
"
|
|
975
|
+
`;
|
|
976
|
+
|
|
977
|
+
exports[`openApiTsHooksGenerator > should handle streaming query operation correctly 1`] = `
|
|
978
|
+
"import type {
|
|
979
|
+
QueryFilters,
|
|
980
|
+
UseQueryOptions,
|
|
981
|
+
QueryFunctionContext,
|
|
982
|
+
} from '@tanstack/react-query';
|
|
983
|
+
import type {
|
|
984
|
+
StreamEventsRequest,
|
|
985
|
+
StreamEventsError,
|
|
986
|
+
StreamEvents200Response,
|
|
987
|
+
} from './types.gen.js';
|
|
988
|
+
import { TestApi } from './client.gen.js';
|
|
989
|
+
|
|
990
|
+
export interface TestApiOptionsProxyConfig {
|
|
991
|
+
client: TestApi;
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
export class TestApiOptionsProxy {
|
|
995
|
+
private $client: TestApi;
|
|
996
|
+
|
|
997
|
+
constructor({ client }: TestApiOptionsProxyConfig) {
|
|
998
|
+
this.$client = client;
|
|
999
|
+
|
|
1000
|
+
this._streamEventsQueryKey = this._streamEventsQueryKey.bind(this);
|
|
1001
|
+
this._streamEventsQueryOptions = this._streamEventsQueryOptions.bind(this);
|
|
1002
|
+
this._streamEventsQueryFilter = this._streamEventsQueryFilter.bind(this);
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
protected async $queryStream<T>(
|
|
1006
|
+
context: QueryFunctionContext<any>,
|
|
1007
|
+
stream: AsyncIterable<T>,
|
|
1008
|
+
): Promise<T[]> {
|
|
1009
|
+
const query = context.client
|
|
1010
|
+
.getQueryCache()
|
|
1011
|
+
.find({ queryKey: context.queryKey, exact: true });
|
|
1012
|
+
|
|
1013
|
+
if (query && query.state.data !== undefined) {
|
|
1014
|
+
query.setState({
|
|
1015
|
+
status: 'pending',
|
|
1016
|
+
data: undefined,
|
|
1017
|
+
error: null,
|
|
1018
|
+
fetchStatus: 'fetching',
|
|
1019
|
+
});
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
const chunks: T[] = [];
|
|
1023
|
+
for await (const chunk of stream) {
|
|
1024
|
+
if (context.signal.aborted) {
|
|
1025
|
+
break;
|
|
1026
|
+
}
|
|
1027
|
+
chunks.push(chunk);
|
|
1028
|
+
query?.setState({
|
|
1029
|
+
status: 'success',
|
|
1030
|
+
fetchStatus: 'fetching',
|
|
1031
|
+
});
|
|
1032
|
+
context.client.setQueryData<T[]>(context.queryKey, (prev = []) =>
|
|
1033
|
+
prev.concat(chunk),
|
|
1034
|
+
);
|
|
1035
|
+
}
|
|
1036
|
+
query?.setState({
|
|
1037
|
+
fetchStatus: 'idle',
|
|
1038
|
+
});
|
|
1039
|
+
return chunks;
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
protected async $waitForStream<T>(iterable: AsyncIterable<T>) {
|
|
1043
|
+
const chunks: T[] = [];
|
|
1044
|
+
for await (const chunk of iterable) {
|
|
1045
|
+
chunks.push(chunk);
|
|
1046
|
+
}
|
|
1047
|
+
return chunks;
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
public queryKey = () => ['TestApi'];
|
|
1051
|
+
|
|
1052
|
+
private _streamEventsQueryKey(input: StreamEventsRequest) {
|
|
1053
|
+
return [...this.queryKey(), 'streamEvents', input];
|
|
1054
|
+
}
|
|
1055
|
+
private _streamEventsQueryOptions(
|
|
1056
|
+
input: StreamEventsRequest,
|
|
1057
|
+
options?: Omit<
|
|
1058
|
+
UseQueryOptions<StreamEvents200Response[], StreamEventsError>,
|
|
1059
|
+
'queryFn' | 'queryKey'
|
|
1060
|
+
> &
|
|
1061
|
+
Partial<
|
|
1062
|
+
Pick<
|
|
1063
|
+
UseQueryOptions<StreamEvents200Response[], StreamEventsError>,
|
|
1064
|
+
'queryFn' | 'queryKey'
|
|
1065
|
+
>
|
|
1066
|
+
>,
|
|
1067
|
+
): UseQueryOptions<StreamEvents200Response[], StreamEventsError> {
|
|
1068
|
+
return {
|
|
1069
|
+
queryFn: (context) =>
|
|
1070
|
+
this.$queryStream(context, this.$client.streamEvents(input)),
|
|
1071
|
+
queryKey: this._streamEventsQueryKey(input),
|
|
1072
|
+
...options,
|
|
1073
|
+
};
|
|
1074
|
+
}
|
|
1075
|
+
private _streamEventsQueryFilter(
|
|
1076
|
+
input: StreamEventsRequest,
|
|
1077
|
+
filter?: QueryFilters<StreamEvents200Response[], StreamEventsError>,
|
|
1078
|
+
): QueryFilters<StreamEvents200Response[], StreamEventsError> {
|
|
1079
|
+
return {
|
|
1080
|
+
queryKey: this._streamEventsQueryKey(input),
|
|
1081
|
+
...filter,
|
|
1082
|
+
};
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
public streamEvents = {
|
|
1086
|
+
queryKey: this._streamEventsQueryKey.bind(this),
|
|
1087
|
+
queryOptions: this._streamEventsQueryOptions.bind(this),
|
|
1088
|
+
queryFilter: this._streamEventsQueryFilter.bind(this),
|
|
1089
|
+
};
|
|
1090
|
+
}
|
|
1091
|
+
"
|
|
1092
|
+
`;
|