@openapi-qraft/tanstack-query-react-plugin 2.2.0 → 2.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/ts-factory/getServiceIndexFactory.js +10 -4
- package/dist/ts-factory/getServiceIndexFactory.js.map +1 -1
- package/dist/ts-factory/tsdoc/createOperationMethodTSDocExample.d.ts.map +1 -1
- package/dist/ts-factory/tsdoc/createOperationMethodTSDocExample.js +8 -2
- package/dist/ts-factory/tsdoc/createOperationMethodTSDocExample.js.map +1 -1
- package/dist/ts-factory/tsdoc/createUseQueriesOperationTSDocExample.d.ts +5 -0
- package/dist/ts-factory/tsdoc/createUseQueriesOperationTSDocExample.d.ts.map +1 -1
- package/dist/ts-factory/tsdoc/createUseQueriesOperationTSDocExample.js +48 -39
- package/dist/ts-factory/tsdoc/createUseQueriesOperationTSDocExample.js.map +1 -1
- package/dist/ts-factory/tsdoc/createUseSuspenseQueriesOperationTSDocExample.d.ts +3 -0
- package/dist/ts-factory/tsdoc/createUseSuspenseQueriesOperationTSDocExample.d.ts.map +1 -0
- package/dist/ts-factory/tsdoc/createUseSuspenseQueriesOperationTSDocExample.js +55 -0
- package/dist/ts-factory/tsdoc/createUseSuspenseQueriesOperationTSDocExample.js.map +1 -0
- package/dist/ts-factory/tsdoc/createUseSuspenseQueryOperationTSDocExample.d.ts +3 -0
- package/dist/ts-factory/tsdoc/createUseSuspenseQueryOperationTSDocExample.d.ts.map +1 -0
- package/dist/ts-factory/tsdoc/createUseSuspenseQueryOperationTSDocExample.js +38 -0
- package/dist/ts-factory/tsdoc/createUseSuspenseQueryOperationTSDocExample.js.map +1 -0
- package/package.json +2 -2
- package/src/ts-factory/getServiceIndexFactory.ts +36 -22
- package/src/ts-factory/tsdoc/createOperationMethodTSDocExample.ts +14 -2
- package/src/ts-factory/tsdoc/createUseQueriesOperationTSDocExample.ts +187 -181
- package/src/ts-factory/tsdoc/createUseSuspenseQueriesOperationTSDocExample.ts +121 -0
- package/src/ts-factory/tsdoc/createUseSuspenseQueryOperationTSDocExample.ts +77 -0
- package/src/ts-factory/service-operation.generated/.gitkeep +0 -0
- package/src/ts-factory/service-operation.generated/ServiceOperationCancelQueries.ts +0 -171
- package/src/ts-factory/service-operation.generated/ServiceOperationFetchInfiniteQuery.ts +0 -251
- package/src/ts-factory/service-operation.generated/ServiceOperationFetchQuery.ts +0 -299
- package/src/ts-factory/service-operation.generated/ServiceOperationGetInfiniteQueryData.ts +0 -134
- package/src/ts-factory/service-operation.generated/ServiceOperationGetQueriesData.ts +0 -258
- package/src/ts-factory/service-operation.generated/ServiceOperationGetQueryData.ts +0 -120
- package/src/ts-factory/service-operation.generated/ServiceOperationGetQueryState.ts +0 -248
- package/src/ts-factory/service-operation.generated/ServiceOperationInvalidateQueries.ts +0 -137
- package/src/ts-factory/service-operation.generated/ServiceOperationIsFetchingQueries.ts +0 -141
- package/src/ts-factory/service-operation.generated/ServiceOperationIsMutatingQueries.ts +0 -163
- package/src/ts-factory/service-operation.generated/ServiceOperationMutationFn.ts +0 -176
- package/src/ts-factory/service-operation.generated/ServiceOperationQueryFn.ts +0 -278
- package/src/ts-factory/service-operation.generated/ServiceOperationRefetchQueries.ts +0 -171
- package/src/ts-factory/service-operation.generated/ServiceOperationRemoveQueries.ts +0 -141
- package/src/ts-factory/service-operation.generated/ServiceOperationResetQueries.ts +0 -171
- package/src/ts-factory/service-operation.generated/ServiceOperationSetInfiniteQueryData.ts +0 -201
- package/src/ts-factory/service-operation.generated/ServiceOperationSetQueriesData.ts +0 -221
- package/src/ts-factory/service-operation.generated/ServiceOperationSetQueryData.ts +0 -191
- package/src/ts-factory/service-operation.generated/ServiceOperationUseInfiniteQuery.ts +0 -534
- package/src/ts-factory/service-operation.generated/ServiceOperationUseIsFetchingQueries.ts +0 -141
- package/src/ts-factory/service-operation.generated/ServiceOperationUseIsMutating.ts +0 -163
- package/src/ts-factory/service-operation.generated/ServiceOperationUseMutation.ts +0 -366
- package/src/ts-factory/service-operation.generated/ServiceOperationUseMutationState.ts +0 -300
- package/src/ts-factory/service-operation.generated/ServiceOperationUseQueries.ts +0 -191
- package/src/ts-factory/service-operation.generated/ServiceOperationUseQuery.ts +0 -392
- package/src/ts-factory/service-operation.generated/ServiceOperationUseSuspenseInfiniteQuery.ts +0 -299
- package/src/ts-factory/service-operation.generated/ServiceOperationUseSuspenseQueries.ts +0 -204
- package/src/ts-factory/service-operation.generated/ServiceOperationUseSuspenseQuery.ts +0 -212
|
@@ -40,25 +40,7 @@ export const createUseQueriesOperationTSDocExample = (
|
|
|
40
40
|
[
|
|
41
41
|
factory.createPropertyAssignment(
|
|
42
42
|
factory.createIdentifier('queries'),
|
|
43
|
-
factory
|
|
44
|
-
[
|
|
45
|
-
factory.createObjectLiteralExpression(
|
|
46
|
-
createOperationMethodParametersExampleNodes(
|
|
47
|
-
operation,
|
|
48
|
-
(parameter) => camelcase(`${parameter.name}-1`)
|
|
49
|
-
),
|
|
50
|
-
true
|
|
51
|
-
),
|
|
52
|
-
factory.createObjectLiteralExpression(
|
|
53
|
-
createOperationMethodParametersExampleNodes(
|
|
54
|
-
operation,
|
|
55
|
-
(parameter) => camelcase(`${parameter.name}-2`)
|
|
56
|
-
),
|
|
57
|
-
true
|
|
58
|
-
),
|
|
59
|
-
],
|
|
60
|
-
true
|
|
61
|
-
)
|
|
43
|
+
createQueriesArrayExpression(operation, factory)
|
|
62
44
|
),
|
|
63
45
|
],
|
|
64
46
|
true
|
|
@@ -70,68 +52,9 @@ export const createUseQueriesOperationTSDocExample = (
|
|
|
70
52
|
ts.NodeFlags.Const
|
|
71
53
|
)
|
|
72
54
|
),
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
factory.createIdentifier(camelcase(operation.name + '-results')),
|
|
77
|
-
factory.createIdentifier('forEach')
|
|
78
|
-
),
|
|
79
|
-
undefined,
|
|
80
|
-
[
|
|
81
|
-
factory.createArrowFunction(
|
|
82
|
-
undefined,
|
|
83
|
-
undefined,
|
|
84
|
-
[
|
|
85
|
-
factory.createParameterDeclaration(
|
|
86
|
-
undefined,
|
|
87
|
-
undefined,
|
|
88
|
-
factory.createObjectBindingPattern([
|
|
89
|
-
factory.createBindingElement(
|
|
90
|
-
undefined,
|
|
91
|
-
undefined,
|
|
92
|
-
factory.createIdentifier('isSuccess')
|
|
93
|
-
),
|
|
94
|
-
factory.createBindingElement(
|
|
95
|
-
undefined,
|
|
96
|
-
undefined,
|
|
97
|
-
factory.createIdentifier('data')
|
|
98
|
-
),
|
|
99
|
-
factory.createBindingElement(
|
|
100
|
-
undefined,
|
|
101
|
-
undefined,
|
|
102
|
-
factory.createIdentifier('error')
|
|
103
|
-
),
|
|
104
|
-
])
|
|
105
|
-
),
|
|
106
|
-
],
|
|
107
|
-
undefined,
|
|
108
|
-
factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken),
|
|
109
|
-
factory.createCallExpression(
|
|
110
|
-
factory.createPropertyAccessExpression(
|
|
111
|
-
factory.createIdentifier('console'),
|
|
112
|
-
factory.createIdentifier('log')
|
|
113
|
-
),
|
|
114
|
-
undefined,
|
|
115
|
-
[
|
|
116
|
-
factory.createObjectLiteralExpression(
|
|
117
|
-
[
|
|
118
|
-
factory.createShorthandPropertyAssignment(
|
|
119
|
-
factory.createIdentifier('isSuccess')
|
|
120
|
-
),
|
|
121
|
-
factory.createShorthandPropertyAssignment(
|
|
122
|
-
factory.createIdentifier('data')
|
|
123
|
-
),
|
|
124
|
-
factory.createShorthandPropertyAssignment(
|
|
125
|
-
factory.createIdentifier('error')
|
|
126
|
-
),
|
|
127
|
-
],
|
|
128
|
-
false
|
|
129
|
-
),
|
|
130
|
-
]
|
|
131
|
-
)
|
|
132
|
-
),
|
|
133
|
-
]
|
|
134
|
-
)
|
|
55
|
+
createResultsForEachExpression(
|
|
56
|
+
camelcase(operation.name + '-results'),
|
|
57
|
+
factory
|
|
135
58
|
),
|
|
136
59
|
])
|
|
137
60
|
.trim()
|
|
@@ -162,71 +85,11 @@ export const createUseQueriesOperationTSDocExample = (
|
|
|
162
85
|
[
|
|
163
86
|
factory.createPropertyAssignment(
|
|
164
87
|
factory.createIdentifier('combine'),
|
|
165
|
-
factory
|
|
166
|
-
undefined,
|
|
167
|
-
undefined,
|
|
168
|
-
[
|
|
169
|
-
factory.createParameterDeclaration(
|
|
170
|
-
undefined,
|
|
171
|
-
undefined,
|
|
172
|
-
factory.createIdentifier('results')
|
|
173
|
-
),
|
|
174
|
-
],
|
|
175
|
-
undefined,
|
|
176
|
-
factory.createToken(
|
|
177
|
-
ts.SyntaxKind.EqualsGreaterThanToken
|
|
178
|
-
),
|
|
179
|
-
factory.createCallExpression(
|
|
180
|
-
factory.createPropertyAccessExpression(
|
|
181
|
-
factory.createIdentifier('results'),
|
|
182
|
-
factory.createIdentifier('map')
|
|
183
|
-
),
|
|
184
|
-
undefined,
|
|
185
|
-
[
|
|
186
|
-
factory.createArrowFunction(
|
|
187
|
-
undefined,
|
|
188
|
-
undefined,
|
|
189
|
-
[
|
|
190
|
-
factory.createParameterDeclaration(
|
|
191
|
-
undefined,
|
|
192
|
-
undefined,
|
|
193
|
-
factory.createIdentifier('result')
|
|
194
|
-
),
|
|
195
|
-
],
|
|
196
|
-
undefined,
|
|
197
|
-
factory.createToken(
|
|
198
|
-
ts.SyntaxKind.EqualsGreaterThanToken
|
|
199
|
-
),
|
|
200
|
-
factory.createPropertyAccessExpression(
|
|
201
|
-
factory.createIdentifier('result'),
|
|
202
|
-
factory.createIdentifier('data')
|
|
203
|
-
)
|
|
204
|
-
),
|
|
205
|
-
]
|
|
206
|
-
)
|
|
207
|
-
)
|
|
88
|
+
createCombineFunction(factory)
|
|
208
89
|
),
|
|
209
90
|
factory.createPropertyAssignment(
|
|
210
91
|
factory.createIdentifier('queries'),
|
|
211
|
-
factory
|
|
212
|
-
[
|
|
213
|
-
factory.createObjectLiteralExpression(
|
|
214
|
-
createOperationMethodParametersExampleNodes(
|
|
215
|
-
operation,
|
|
216
|
-
(parameter) => camelcase(`${parameter.name}-1`)
|
|
217
|
-
),
|
|
218
|
-
true
|
|
219
|
-
),
|
|
220
|
-
factory.createObjectLiteralExpression(
|
|
221
|
-
createOperationMethodParametersExampleNodes(
|
|
222
|
-
operation,
|
|
223
|
-
(parameter) => camelcase(`${parameter.name}-2`)
|
|
224
|
-
),
|
|
225
|
-
true
|
|
226
|
-
),
|
|
227
|
-
],
|
|
228
|
-
true
|
|
229
|
-
)
|
|
92
|
+
createQueriesArrayExpression(operation, factory)
|
|
230
93
|
),
|
|
231
94
|
],
|
|
232
95
|
true
|
|
@@ -238,55 +101,198 @@ export const createUseQueriesOperationTSDocExample = (
|
|
|
238
101
|
ts.NodeFlags.Const
|
|
239
102
|
)
|
|
240
103
|
),
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
104
|
+
createCombinedResultsForEachExpression(
|
|
105
|
+
camelcase(operation.name + '-combined-results'),
|
|
106
|
+
factory
|
|
107
|
+
),
|
|
108
|
+
])
|
|
109
|
+
.trim()
|
|
110
|
+
.split('\n'),
|
|
111
|
+
'```',
|
|
112
|
+
];
|
|
113
|
+
|
|
114
|
+
return example;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export const createQueriesArrayExpression = (
|
|
118
|
+
operation: ServiceOperation,
|
|
119
|
+
factory: ts.NodeFactory
|
|
120
|
+
): ts.ArrayLiteralExpression => {
|
|
121
|
+
return factory.createArrayLiteralExpression(
|
|
122
|
+
[
|
|
123
|
+
factory.createObjectLiteralExpression(
|
|
124
|
+
createOperationMethodParametersExampleNodes(operation, (parameter) =>
|
|
125
|
+
camelcase(`${parameter.name}-1`)
|
|
126
|
+
),
|
|
127
|
+
true
|
|
128
|
+
),
|
|
129
|
+
factory.createObjectLiteralExpression(
|
|
130
|
+
createOperationMethodParametersExampleNodes(operation, (parameter) =>
|
|
131
|
+
camelcase(`${parameter.name}-2`)
|
|
132
|
+
),
|
|
133
|
+
true
|
|
134
|
+
),
|
|
135
|
+
],
|
|
136
|
+
true
|
|
137
|
+
);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
export const createCombineFunction = (
|
|
141
|
+
factory: ts.NodeFactory
|
|
142
|
+
): ts.ArrowFunction => {
|
|
143
|
+
return factory.createArrowFunction(
|
|
144
|
+
undefined,
|
|
145
|
+
undefined,
|
|
146
|
+
[
|
|
147
|
+
factory.createParameterDeclaration(
|
|
148
|
+
undefined,
|
|
149
|
+
undefined,
|
|
150
|
+
factory.createIdentifier('results')
|
|
151
|
+
),
|
|
152
|
+
],
|
|
153
|
+
undefined,
|
|
154
|
+
factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken),
|
|
155
|
+
factory.createCallExpression(
|
|
156
|
+
factory.createPropertyAccessExpression(
|
|
157
|
+
factory.createIdentifier('results'),
|
|
158
|
+
factory.createIdentifier('map')
|
|
159
|
+
),
|
|
160
|
+
undefined,
|
|
161
|
+
[
|
|
162
|
+
factory.createArrowFunction(
|
|
163
|
+
undefined,
|
|
164
|
+
undefined,
|
|
165
|
+
[
|
|
166
|
+
factory.createParameterDeclaration(
|
|
167
|
+
undefined,
|
|
168
|
+
undefined,
|
|
169
|
+
factory.createIdentifier('result')
|
|
246
170
|
),
|
|
247
|
-
|
|
248
|
-
|
|
171
|
+
],
|
|
172
|
+
undefined,
|
|
173
|
+
factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken),
|
|
174
|
+
factory.createPropertyAccessExpression(
|
|
175
|
+
factory.createIdentifier('result'),
|
|
176
|
+
factory.createIdentifier('data')
|
|
177
|
+
)
|
|
178
|
+
),
|
|
179
|
+
]
|
|
180
|
+
)
|
|
181
|
+
);
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
export const createResultsForEachExpression = (
|
|
185
|
+
variableName: string,
|
|
186
|
+
factory: ts.NodeFactory
|
|
187
|
+
): ts.ExpressionStatement => {
|
|
188
|
+
return factory.createExpressionStatement(
|
|
189
|
+
factory.createCallExpression(
|
|
190
|
+
factory.createPropertyAccessExpression(
|
|
191
|
+
factory.createIdentifier(variableName),
|
|
192
|
+
factory.createIdentifier('forEach')
|
|
193
|
+
),
|
|
194
|
+
undefined,
|
|
195
|
+
[
|
|
196
|
+
factory.createArrowFunction(
|
|
197
|
+
undefined,
|
|
249
198
|
undefined,
|
|
250
199
|
[
|
|
251
|
-
factory.
|
|
200
|
+
factory.createParameterDeclaration(
|
|
252
201
|
undefined,
|
|
253
202
|
undefined,
|
|
254
|
-
[
|
|
255
|
-
factory.
|
|
203
|
+
factory.createObjectBindingPattern([
|
|
204
|
+
factory.createBindingElement(
|
|
205
|
+
undefined,
|
|
206
|
+
undefined,
|
|
207
|
+
factory.createIdentifier('isSuccess')
|
|
208
|
+
),
|
|
209
|
+
factory.createBindingElement(
|
|
256
210
|
undefined,
|
|
257
211
|
undefined,
|
|
258
212
|
factory.createIdentifier('data')
|
|
259
213
|
),
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
factory.createPropertyAccessExpression(
|
|
265
|
-
factory.createIdentifier('console'),
|
|
266
|
-
factory.createIdentifier('log')
|
|
214
|
+
factory.createBindingElement(
|
|
215
|
+
undefined,
|
|
216
|
+
undefined,
|
|
217
|
+
factory.createIdentifier('error')
|
|
267
218
|
),
|
|
268
|
-
|
|
219
|
+
])
|
|
220
|
+
),
|
|
221
|
+
],
|
|
222
|
+
undefined,
|
|
223
|
+
factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken),
|
|
224
|
+
factory.createCallExpression(
|
|
225
|
+
factory.createPropertyAccessExpression(
|
|
226
|
+
factory.createIdentifier('console'),
|
|
227
|
+
factory.createIdentifier('log')
|
|
228
|
+
),
|
|
229
|
+
undefined,
|
|
230
|
+
[
|
|
231
|
+
factory.createObjectLiteralExpression(
|
|
269
232
|
[
|
|
270
|
-
factory.
|
|
271
|
-
|
|
272
|
-
factory.createShorthandPropertyAssignment(
|
|
273
|
-
factory.createIdentifier('data'),
|
|
274
|
-
undefined
|
|
275
|
-
),
|
|
276
|
-
],
|
|
277
|
-
false
|
|
233
|
+
factory.createShorthandPropertyAssignment(
|
|
234
|
+
factory.createIdentifier('isSuccess')
|
|
278
235
|
),
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
236
|
+
factory.createShorthandPropertyAssignment(
|
|
237
|
+
factory.createIdentifier('data')
|
|
238
|
+
),
|
|
239
|
+
factory.createShorthandPropertyAssignment(
|
|
240
|
+
factory.createIdentifier('error')
|
|
241
|
+
),
|
|
242
|
+
],
|
|
243
|
+
false
|
|
244
|
+
),
|
|
245
|
+
]
|
|
246
|
+
)
|
|
247
|
+
),
|
|
248
|
+
]
|
|
249
|
+
)
|
|
250
|
+
);
|
|
251
|
+
};
|
|
290
252
|
|
|
291
|
-
|
|
253
|
+
export const createCombinedResultsForEachExpression = (
|
|
254
|
+
variableName: string,
|
|
255
|
+
factory: ts.NodeFactory
|
|
256
|
+
): ts.ExpressionStatement => {
|
|
257
|
+
return factory.createExpressionStatement(
|
|
258
|
+
factory.createCallExpression(
|
|
259
|
+
factory.createPropertyAccessExpression(
|
|
260
|
+
factory.createIdentifier(variableName),
|
|
261
|
+
factory.createIdentifier('forEach')
|
|
262
|
+
),
|
|
263
|
+
undefined,
|
|
264
|
+
[
|
|
265
|
+
factory.createArrowFunction(
|
|
266
|
+
undefined,
|
|
267
|
+
undefined,
|
|
268
|
+
[
|
|
269
|
+
factory.createParameterDeclaration(
|
|
270
|
+
undefined,
|
|
271
|
+
undefined,
|
|
272
|
+
factory.createIdentifier('data')
|
|
273
|
+
),
|
|
274
|
+
],
|
|
275
|
+
undefined,
|
|
276
|
+
factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken),
|
|
277
|
+
factory.createCallExpression(
|
|
278
|
+
factory.createPropertyAccessExpression(
|
|
279
|
+
factory.createIdentifier('console'),
|
|
280
|
+
factory.createIdentifier('log')
|
|
281
|
+
),
|
|
282
|
+
undefined,
|
|
283
|
+
[
|
|
284
|
+
factory.createObjectLiteralExpression(
|
|
285
|
+
[
|
|
286
|
+
factory.createShorthandPropertyAssignment(
|
|
287
|
+
factory.createIdentifier('data')
|
|
288
|
+
),
|
|
289
|
+
],
|
|
290
|
+
false
|
|
291
|
+
),
|
|
292
|
+
]
|
|
293
|
+
)
|
|
294
|
+
),
|
|
295
|
+
]
|
|
296
|
+
)
|
|
297
|
+
);
|
|
292
298
|
};
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type { ServiceOperation } from '@openapi-qraft/plugin/lib/open-api/OpenAPIService';
|
|
2
|
+
import camelcase from 'camelcase';
|
|
3
|
+
import ts from 'typescript';
|
|
4
|
+
import { createOperationCommonTSDoc } from '../../lib/createOperationCommonTSDoc.js';
|
|
5
|
+
import { astToString } from '../astToString.js';
|
|
6
|
+
import {
|
|
7
|
+
createCombinedResultsForEachExpression,
|
|
8
|
+
createCombineFunction,
|
|
9
|
+
createQueriesArrayExpression,
|
|
10
|
+
createResultsForEachExpression,
|
|
11
|
+
} from './createUseQueriesOperationTSDocExample.js';
|
|
12
|
+
import { createOperationMethodCallExpressionExampleNode } from './lib/createOperationMethodCallExpressionExampleNode.js';
|
|
13
|
+
|
|
14
|
+
export const createUseSuspenseQueriesOperationTSDocExample = (
|
|
15
|
+
operation: ServiceOperation,
|
|
16
|
+
serviceVariableName: string
|
|
17
|
+
) => {
|
|
18
|
+
const factory = ts.factory;
|
|
19
|
+
|
|
20
|
+
const example: string[] = [
|
|
21
|
+
'Allows you to execute multiple asynchronous data fetching operations concurrently with Suspense support.',
|
|
22
|
+
'Similar to useQueries but integrates with React Suspense for loading states.',
|
|
23
|
+
'',
|
|
24
|
+
...createOperationCommonTSDoc(operation),
|
|
25
|
+
'@see {@link https://openapi-qraft.github.io/openapi-qraft/docs/hooks/useSuspenseQueries|`useSuspenseQueries(...)` documentation}',
|
|
26
|
+
|
|
27
|
+
'@example Basic usage with Suspense',
|
|
28
|
+
'```ts',
|
|
29
|
+
...astToString([
|
|
30
|
+
factory.createVariableStatement(
|
|
31
|
+
undefined,
|
|
32
|
+
factory.createVariableDeclarationList(
|
|
33
|
+
[
|
|
34
|
+
factory.createVariableDeclaration(
|
|
35
|
+
factory.createIdentifier(camelcase(operation.name + '-data')),
|
|
36
|
+
undefined,
|
|
37
|
+
undefined,
|
|
38
|
+
createOperationMethodCallExpressionExampleNode(
|
|
39
|
+
operation,
|
|
40
|
+
{
|
|
41
|
+
serviceVariableName,
|
|
42
|
+
operationMethodName: 'useSuspenseQueries',
|
|
43
|
+
},
|
|
44
|
+
[
|
|
45
|
+
factory.createObjectLiteralExpression(
|
|
46
|
+
[
|
|
47
|
+
factory.createPropertyAssignment(
|
|
48
|
+
factory.createIdentifier('queries'),
|
|
49
|
+
createQueriesArrayExpression(operation, factory)
|
|
50
|
+
),
|
|
51
|
+
],
|
|
52
|
+
true
|
|
53
|
+
),
|
|
54
|
+
]
|
|
55
|
+
)
|
|
56
|
+
),
|
|
57
|
+
],
|
|
58
|
+
ts.NodeFlags.Const
|
|
59
|
+
)
|
|
60
|
+
),
|
|
61
|
+
createResultsForEachExpression(
|
|
62
|
+
camelcase(operation.name + '-results'),
|
|
63
|
+
factory
|
|
64
|
+
),
|
|
65
|
+
])
|
|
66
|
+
.trim()
|
|
67
|
+
.split('\n'),
|
|
68
|
+
'```',
|
|
69
|
+
|
|
70
|
+
'@example With data transformation using combine',
|
|
71
|
+
'```ts',
|
|
72
|
+
...astToString([
|
|
73
|
+
factory.createVariableStatement(
|
|
74
|
+
undefined,
|
|
75
|
+
factory.createVariableDeclarationList(
|
|
76
|
+
[
|
|
77
|
+
factory.createVariableDeclaration(
|
|
78
|
+
factory.createIdentifier(
|
|
79
|
+
camelcase(operation.name + '-combined-data')
|
|
80
|
+
),
|
|
81
|
+
undefined,
|
|
82
|
+
undefined,
|
|
83
|
+
createOperationMethodCallExpressionExampleNode(
|
|
84
|
+
operation,
|
|
85
|
+
{
|
|
86
|
+
serviceVariableName,
|
|
87
|
+
operationMethodName: 'useSuspenseQueries',
|
|
88
|
+
},
|
|
89
|
+
[
|
|
90
|
+
factory.createObjectLiteralExpression(
|
|
91
|
+
[
|
|
92
|
+
factory.createPropertyAssignment(
|
|
93
|
+
factory.createIdentifier('combine'),
|
|
94
|
+
createCombineFunction(factory)
|
|
95
|
+
),
|
|
96
|
+
factory.createPropertyAssignment(
|
|
97
|
+
factory.createIdentifier('queries'),
|
|
98
|
+
createQueriesArrayExpression(operation, factory)
|
|
99
|
+
),
|
|
100
|
+
],
|
|
101
|
+
true
|
|
102
|
+
),
|
|
103
|
+
]
|
|
104
|
+
)
|
|
105
|
+
),
|
|
106
|
+
],
|
|
107
|
+
ts.NodeFlags.Const
|
|
108
|
+
)
|
|
109
|
+
),
|
|
110
|
+
createCombinedResultsForEachExpression(
|
|
111
|
+
camelcase(operation.name + '-combined-data'),
|
|
112
|
+
factory
|
|
113
|
+
),
|
|
114
|
+
])
|
|
115
|
+
.trim()
|
|
116
|
+
.split('\n'),
|
|
117
|
+
'```',
|
|
118
|
+
];
|
|
119
|
+
|
|
120
|
+
return example;
|
|
121
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { ServiceOperation } from '@openapi-qraft/plugin/lib/open-api/OpenAPIService';
|
|
2
|
+
import ts from 'typescript';
|
|
3
|
+
import { createOperationCommonTSDoc } from '../../lib/createOperationCommonTSDoc.js';
|
|
4
|
+
import { astToString } from '../astToString.js';
|
|
5
|
+
import { createOperationMethodCallExpressionExampleNode } from './lib/createOperationMethodCallExpressionExampleNode.js';
|
|
6
|
+
import { createOperationMethodParametersExampleNodes } from './lib/createOperationMethodParametersExampleNodes.js';
|
|
7
|
+
|
|
8
|
+
export const createUseSuspenseQueryOperationTSDocExample = (
|
|
9
|
+
operation: ServiceOperation,
|
|
10
|
+
serviceVariableName: string
|
|
11
|
+
) => {
|
|
12
|
+
const example: string[] = [
|
|
13
|
+
'Performs asynchronous data fetching with Suspense support.',
|
|
14
|
+
'Similar to useQuery but integrates with React Suspense for loading states.',
|
|
15
|
+
'',
|
|
16
|
+
...createOperationCommonTSDoc(operation),
|
|
17
|
+
'@see {@link https://openapi-qraft.github.io/openapi-qraft/docs/hooks/useSuspenseQuery|`useSuspenseQuery(...)` documentation}',
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
if (
|
|
21
|
+
!operation.parameters?.length ||
|
|
22
|
+
operation.parameters.every((parameter) => !parameter.required)
|
|
23
|
+
) {
|
|
24
|
+
example.push(
|
|
25
|
+
'@example Suspense Query without parameters',
|
|
26
|
+
'```ts',
|
|
27
|
+
...(
|
|
28
|
+
'const data = ' +
|
|
29
|
+
astToString(
|
|
30
|
+
createOperationMethodCallExpressionExampleNode(
|
|
31
|
+
operation,
|
|
32
|
+
{
|
|
33
|
+
serviceVariableName,
|
|
34
|
+
operationMethodName: 'useSuspenseQuery',
|
|
35
|
+
},
|
|
36
|
+
undefined
|
|
37
|
+
)
|
|
38
|
+
)
|
|
39
|
+
)
|
|
40
|
+
.trim()
|
|
41
|
+
.split('\n'),
|
|
42
|
+
'```'
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (operation.parameters?.length) {
|
|
47
|
+
const factory = ts.factory;
|
|
48
|
+
|
|
49
|
+
example.push(
|
|
50
|
+
'@example Suspense Query with parameters',
|
|
51
|
+
'```ts',
|
|
52
|
+
...(
|
|
53
|
+
'const data = ' +
|
|
54
|
+
astToString(
|
|
55
|
+
createOperationMethodCallExpressionExampleNode(
|
|
56
|
+
operation,
|
|
57
|
+
{
|
|
58
|
+
serviceVariableName,
|
|
59
|
+
operationMethodName: 'useSuspenseQuery',
|
|
60
|
+
},
|
|
61
|
+
[
|
|
62
|
+
factory.createObjectLiteralExpression(
|
|
63
|
+
createOperationMethodParametersExampleNodes(operation),
|
|
64
|
+
true
|
|
65
|
+
),
|
|
66
|
+
]
|
|
67
|
+
)
|
|
68
|
+
)
|
|
69
|
+
)
|
|
70
|
+
.trim()
|
|
71
|
+
.split('\n'),
|
|
72
|
+
'```'
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return example;
|
|
77
|
+
};
|
|
File without changes
|