@openapi-qraft/tanstack-query-react-plugin 2.0.0-next.8 → 2.0.0-next.9
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 +8 -0
- package/dist/lib/createOperationCommonTSDoc.d.ts +3 -0
- package/dist/lib/createOperationCommonTSDoc.d.ts.map +1 -0
- package/dist/lib/createOperationCommonTSDoc.js +8 -0
- package/dist/lib/createOperationCommonTSDoc.js.map +1 -0
- package/dist/ts-factory/getServiceFactory.d.ts +4 -2
- package/dist/ts-factory/getServiceFactory.d.ts.map +1 -1
- package/dist/ts-factory/getServiceFactory.js +74 -34
- package/dist/ts-factory/getServiceFactory.js.map +1 -1
- package/dist/ts-factory/service-operation.generated/ServiceOperationGetInfiniteQueryData.d.ts.map +1 -1
- package/dist/ts-factory/service-operation.generated/ServiceOperationGetInfiniteQueryData.js +6 -10
- package/dist/ts-factory/service-operation.generated/ServiceOperationGetInfiniteQueryData.js.map +1 -1
- package/dist/ts-factory/service-operation.generated/ServiceOperationGetQueryData.d.ts.map +1 -1
- package/dist/ts-factory/service-operation.generated/ServiceOperationGetQueryData.js +6 -10
- package/dist/ts-factory/service-operation.generated/ServiceOperationGetQueryData.js.map +1 -1
- package/dist/ts-factory/service-operation.generated/ServiceOperationGetQueryState.d.ts.map +1 -1
- package/dist/ts-factory/service-operation.generated/ServiceOperationGetQueryState.js +6 -10
- package/dist/ts-factory/service-operation.generated/ServiceOperationGetQueryState.js.map +1 -1
- package/dist/ts-factory/service-operation.generated/ServiceOperationQueryFn.d.ts.map +1 -1
- package/dist/ts-factory/service-operation.generated/ServiceOperationQueryFn.js +11 -17
- package/dist/ts-factory/service-operation.generated/ServiceOperationQueryFn.js.map +1 -1
- package/dist/ts-factory/service-operation.generated/ServiceOperationUseMutation.d.ts.map +1 -1
- package/dist/ts-factory/service-operation.generated/ServiceOperationUseMutation.js +12 -15
- package/dist/ts-factory/service-operation.generated/ServiceOperationUseMutation.js.map +1 -1
- package/dist/ts-factory/tsdoc/createOperationMethodTSDocExample.d.ts +6 -0
- package/dist/ts-factory/tsdoc/createOperationMethodTSDocExample.d.ts.map +1 -0
- package/dist/ts-factory/tsdoc/createOperationMethodTSDocExample.js +22 -0
- package/dist/ts-factory/tsdoc/createOperationMethodTSDocExample.js.map +1 -0
- package/dist/ts-factory/tsdoc/createUseInfiniteQueryOperationTSDocExample.d.ts +3 -0
- package/dist/ts-factory/tsdoc/createUseInfiniteQueryOperationTSDocExample.d.ts.map +1 -0
- package/dist/ts-factory/tsdoc/createUseInfiniteQueryOperationTSDocExample.js +61 -0
- package/dist/ts-factory/tsdoc/createUseInfiniteQueryOperationTSDocExample.js.map +1 -0
- package/dist/ts-factory/tsdoc/createUseIsFetchingOperationTSDocExample.d.ts +3 -0
- package/dist/ts-factory/tsdoc/createUseIsFetchingOperationTSDocExample.d.ts.map +1 -0
- package/dist/ts-factory/tsdoc/createUseIsFetchingOperationTSDocExample.js +41 -0
- package/dist/ts-factory/tsdoc/createUseIsFetchingOperationTSDocExample.js.map +1 -0
- package/dist/ts-factory/tsdoc/createUseIsMutatingOperationTSDocExample.d.ts +3 -0
- package/dist/ts-factory/tsdoc/createUseIsMutatingOperationTSDocExample.d.ts.map +1 -0
- package/dist/ts-factory/tsdoc/createUseIsMutatingOperationTSDocExample.js +41 -0
- package/dist/ts-factory/tsdoc/createUseIsMutatingOperationTSDocExample.js.map +1 -0
- package/dist/ts-factory/tsdoc/createUseMutationOperationTSDocExample.d.ts +3 -0
- package/dist/ts-factory/tsdoc/createUseMutationOperationTSDocExample.d.ts.map +1 -0
- package/dist/ts-factory/tsdoc/createUseMutationOperationTSDocExample.js +44 -0
- package/dist/ts-factory/tsdoc/createUseMutationOperationTSDocExample.js.map +1 -0
- package/dist/ts-factory/tsdoc/createUseQueryOperationTSDocExample.d.ts +3 -0
- package/dist/ts-factory/tsdoc/createUseQueryOperationTSDocExample.d.ts.map +1 -0
- package/dist/ts-factory/tsdoc/createUseQueryOperationTSDocExample.js +37 -0
- package/dist/ts-factory/tsdoc/createUseQueryOperationTSDocExample.js.map +1 -0
- package/dist/ts-factory/tsdoc/lib/createOperationMethodExampleNodes.d.ts +7 -0
- package/dist/ts-factory/tsdoc/lib/createOperationMethodExampleNodes.d.ts.map +1 -0
- package/dist/ts-factory/tsdoc/lib/createOperationMethodExampleNodes.js +8 -0
- package/dist/ts-factory/tsdoc/lib/createOperationMethodExampleNodes.js.map +1 -0
- package/dist/ts-factory/tsdoc/lib/createOperationMethodParametersExampleNodes.d.ts +4 -0
- package/dist/ts-factory/tsdoc/lib/createOperationMethodParametersExampleNodes.d.ts.map +1 -0
- package/dist/ts-factory/tsdoc/lib/createOperationMethodParametersExampleNodes.js +31 -0
- package/dist/ts-factory/tsdoc/lib/createOperationMethodParametersExampleNodes.js.map +1 -0
- package/package.json +6 -6
- package/src/lib/createOperationCommonTSDoc.ts +11 -0
- package/src/ts-factory/getServiceFactory.ts +121 -76
- package/src/ts-factory/service-operation.generated/ServiceOperationGetInfiniteQueryData.ts +28 -41
- package/src/ts-factory/service-operation.generated/ServiceOperationGetQueryData.ts +28 -41
- package/src/ts-factory/service-operation.generated/ServiceOperationGetQueryState.ts +28 -41
- package/src/ts-factory/service-operation.generated/ServiceOperationQueryFn.ts +49 -70
- package/src/ts-factory/service-operation.generated/ServiceOperationUseMutation.ts +42 -59
- package/src/ts-factory/tsdoc/createOperationMethodTSDocExample.ts +47 -0
- package/src/ts-factory/tsdoc/createUseInfiniteQueryOperationTSDocExample.ts +146 -0
- package/src/ts-factory/tsdoc/createUseIsFetchingOperationTSDocExample.ts +81 -0
- package/src/ts-factory/tsdoc/createUseIsMutatingOperationTSDocExample.ts +74 -0
- package/src/ts-factory/tsdoc/createUseMutationOperationTSDocExample.ts +88 -0
- package/src/ts-factory/tsdoc/createUseQueryOperationTSDocExample.ts +76 -0
- package/src/ts-factory/tsdoc/lib/createOperationMethodExampleNodes.ts +32 -0
- package/src/ts-factory/tsdoc/lib/createOperationMethodParametersExampleNodes.ts +66 -0
|
@@ -109,57 +109,57 @@ export const createServiceOperationQueryFnNodes = () => [
|
|
|
109
109
|
undefined,
|
|
110
110
|
factory.createIdentifier("options"),
|
|
111
111
|
undefined,
|
|
112
|
-
factory.
|
|
112
|
+
factory.createUnionTypeNode([
|
|
113
113
|
factory.createTypeReferenceNode(
|
|
114
|
-
factory.createIdentifier("
|
|
115
|
-
[
|
|
116
|
-
factory.
|
|
117
|
-
|
|
118
|
-
|
|
114
|
+
factory.createIdentifier("QueryFnOptionsByQueryKey"),
|
|
115
|
+
[
|
|
116
|
+
factory.createTypeReferenceNode(
|
|
117
|
+
factory.createIdentifier("TSchema"),
|
|
118
|
+
undefined
|
|
119
|
+
),
|
|
120
|
+
factory.createTypeReferenceNode(
|
|
121
|
+
factory.createIdentifier("TParams"),
|
|
122
|
+
undefined
|
|
123
|
+
),
|
|
124
|
+
factory.createTypeReferenceNode(
|
|
125
|
+
factory.createIdentifier("TMeta"),
|
|
126
|
+
undefined
|
|
127
|
+
),
|
|
128
|
+
factory.createTypeReferenceNode(
|
|
129
|
+
factory.createIdentifier("TSignal"),
|
|
130
|
+
undefined
|
|
131
|
+
)
|
|
132
|
+
]
|
|
119
133
|
),
|
|
120
|
-
factory.
|
|
121
|
-
factory.createUnionTypeNode([
|
|
122
|
-
factory.createKeywordTypeNode(ts.SyntaxKind.VoidKeyword),
|
|
134
|
+
factory.createParenthesizedType(factory.createConditionalTypeNode(
|
|
123
135
|
factory.createTypeReferenceNode(
|
|
124
|
-
factory.createIdentifier("
|
|
125
|
-
[
|
|
126
|
-
factory.
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
),
|
|
130
|
-
factory.createTypeReferenceNode(
|
|
131
|
-
factory.createIdentifier("TMeta"),
|
|
132
|
-
undefined
|
|
133
|
-
),
|
|
134
|
-
factory.createTypeReferenceNode(
|
|
135
|
-
factory.createIdentifier("TSignal"),
|
|
136
|
-
undefined
|
|
137
|
-
)
|
|
138
|
-
]
|
|
136
|
+
factory.createIdentifier("AreAllOptional"),
|
|
137
|
+
[factory.createTypeReferenceNode(
|
|
138
|
+
factory.createIdentifier("TParams"),
|
|
139
|
+
undefined
|
|
140
|
+
)]
|
|
139
141
|
),
|
|
140
|
-
factory.
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
factory.
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
)
|
|
161
|
-
]),
|
|
162
|
-
factory.createUnionTypeNode([
|
|
142
|
+
factory.createLiteralTypeNode(factory.createTrue()),
|
|
143
|
+
factory.createUnionTypeNode([
|
|
144
|
+
factory.createTypeReferenceNode(
|
|
145
|
+
factory.createIdentifier("QueryFnOptionsByParameters"),
|
|
146
|
+
[
|
|
147
|
+
factory.createTypeReferenceNode(
|
|
148
|
+
factory.createIdentifier("TParams"),
|
|
149
|
+
undefined
|
|
150
|
+
),
|
|
151
|
+
factory.createTypeReferenceNode(
|
|
152
|
+
factory.createIdentifier("TMeta"),
|
|
153
|
+
undefined
|
|
154
|
+
),
|
|
155
|
+
factory.createTypeReferenceNode(
|
|
156
|
+
factory.createIdentifier("TSignal"),
|
|
157
|
+
undefined
|
|
158
|
+
)
|
|
159
|
+
]
|
|
160
|
+
),
|
|
161
|
+
factory.createKeywordTypeNode(ts.SyntaxKind.VoidKeyword)
|
|
162
|
+
]),
|
|
163
163
|
factory.createTypeReferenceNode(
|
|
164
164
|
factory.createIdentifier("QueryFnOptionsByParameters"),
|
|
165
165
|
[
|
|
@@ -176,30 +176,9 @@ export const createServiceOperationQueryFnNodes = () => [
|
|
|
176
176
|
undefined
|
|
177
177
|
)
|
|
178
178
|
]
|
|
179
|
-
),
|
|
180
|
-
factory.createTypeReferenceNode(
|
|
181
|
-
factory.createIdentifier("QueryFnOptionsByQueryKey"),
|
|
182
|
-
[
|
|
183
|
-
factory.createTypeReferenceNode(
|
|
184
|
-
factory.createIdentifier("TSchema"),
|
|
185
|
-
undefined
|
|
186
|
-
),
|
|
187
|
-
factory.createTypeReferenceNode(
|
|
188
|
-
factory.createIdentifier("TParams"),
|
|
189
|
-
undefined
|
|
190
|
-
),
|
|
191
|
-
factory.createTypeReferenceNode(
|
|
192
|
-
factory.createIdentifier("TMeta"),
|
|
193
|
-
undefined
|
|
194
|
-
),
|
|
195
|
-
factory.createTypeReferenceNode(
|
|
196
|
-
factory.createIdentifier("TSignal"),
|
|
197
|
-
undefined
|
|
198
|
-
)
|
|
199
|
-
]
|
|
200
179
|
)
|
|
201
|
-
|
|
202
|
-
),
|
|
180
|
+
))
|
|
181
|
+
]),
|
|
203
182
|
undefined
|
|
204
183
|
),
|
|
205
184
|
factory.createParameterDeclaration(
|
|
@@ -139,17 +139,8 @@ export const createServiceOperationUseMutationNodes = () => [
|
|
|
139
139
|
undefined,
|
|
140
140
|
factory.createIdentifier("TVariables"),
|
|
141
141
|
factory.createTypeReferenceNode(
|
|
142
|
-
factory.createIdentifier("
|
|
143
|
-
|
|
144
|
-
factory.createTypeReferenceNode(
|
|
145
|
-
factory.createIdentifier("TBody"),
|
|
146
|
-
undefined
|
|
147
|
-
),
|
|
148
|
-
factory.createTypeReferenceNode(
|
|
149
|
-
factory.createIdentifier("TParams"),
|
|
150
|
-
undefined
|
|
151
|
-
)
|
|
152
|
-
]
|
|
142
|
+
factory.createIdentifier("TBody"),
|
|
143
|
+
undefined
|
|
153
144
|
),
|
|
154
145
|
undefined
|
|
155
146
|
),
|
|
@@ -165,8 +156,11 @@ export const createServiceOperationUseMutationNodes = () => [
|
|
|
165
156
|
undefined,
|
|
166
157
|
undefined,
|
|
167
158
|
factory.createIdentifier("parameters"),
|
|
168
|
-
|
|
169
|
-
factory.
|
|
159
|
+
undefined,
|
|
160
|
+
factory.createTypeReferenceNode(
|
|
161
|
+
factory.createIdentifier("TParams"),
|
|
162
|
+
undefined
|
|
163
|
+
),
|
|
170
164
|
undefined
|
|
171
165
|
),
|
|
172
166
|
factory.createParameterDeclaration(
|
|
@@ -223,9 +217,26 @@ export const createServiceOperationUseMutationNodes = () => [
|
|
|
223
217
|
undefined
|
|
224
218
|
)
|
|
225
219
|
]),
|
|
226
|
-
factory.
|
|
227
|
-
factory.
|
|
228
|
-
|
|
220
|
+
factory.createConditionalTypeNode(
|
|
221
|
+
factory.createTypeReferenceNode(
|
|
222
|
+
factory.createIdentifier("AreAllOptional"),
|
|
223
|
+
[factory.createTypeReferenceNode(
|
|
224
|
+
factory.createIdentifier("TVariables"),
|
|
225
|
+
undefined
|
|
226
|
+
)]
|
|
227
|
+
),
|
|
228
|
+
factory.createLiteralTypeNode(factory.createTrue()),
|
|
229
|
+
factory.createUnionTypeNode([
|
|
230
|
+
factory.createTypeReferenceNode(
|
|
231
|
+
factory.createIdentifier("TVariables"),
|
|
232
|
+
undefined
|
|
233
|
+
),
|
|
234
|
+
factory.createKeywordTypeNode(ts.SyntaxKind.VoidKeyword)
|
|
235
|
+
]),
|
|
236
|
+
factory.createTypeReferenceNode(
|
|
237
|
+
factory.createIdentifier("TVariables"),
|
|
238
|
+
undefined
|
|
239
|
+
)
|
|
229
240
|
),
|
|
230
241
|
factory.createTypeReferenceNode(
|
|
231
242
|
factory.createIdentifier("TContext"),
|
|
@@ -243,8 +254,17 @@ export const createServiceOperationUseMutationNodes = () => [
|
|
|
243
254
|
undefined,
|
|
244
255
|
factory.createIdentifier("TVariables"),
|
|
245
256
|
factory.createTypeReferenceNode(
|
|
246
|
-
factory.createIdentifier("
|
|
247
|
-
|
|
257
|
+
factory.createIdentifier("MutationVariables"),
|
|
258
|
+
[
|
|
259
|
+
factory.createTypeReferenceNode(
|
|
260
|
+
factory.createIdentifier("TBody"),
|
|
261
|
+
undefined
|
|
262
|
+
),
|
|
263
|
+
factory.createTypeReferenceNode(
|
|
264
|
+
factory.createIdentifier("TParams"),
|
|
265
|
+
undefined
|
|
266
|
+
)
|
|
267
|
+
]
|
|
248
268
|
),
|
|
249
269
|
undefined
|
|
250
270
|
),
|
|
@@ -261,27 +281,7 @@ export const createServiceOperationUseMutationNodes = () => [
|
|
|
261
281
|
undefined,
|
|
262
282
|
factory.createIdentifier("parameters"),
|
|
263
283
|
undefined,
|
|
264
|
-
factory.
|
|
265
|
-
factory.createTypeReferenceNode(
|
|
266
|
-
factory.createIdentifier("AreAllOptional"),
|
|
267
|
-
[factory.createTypeReferenceNode(
|
|
268
|
-
factory.createIdentifier("TParams"),
|
|
269
|
-
undefined
|
|
270
|
-
)]
|
|
271
|
-
),
|
|
272
|
-
factory.createLiteralTypeNode(factory.createTrue()),
|
|
273
|
-
factory.createUnionTypeNode([
|
|
274
|
-
factory.createTypeReferenceNode(
|
|
275
|
-
factory.createIdentifier("TParams"),
|
|
276
|
-
undefined
|
|
277
|
-
),
|
|
278
|
-
factory.createKeywordTypeNode(ts.SyntaxKind.VoidKeyword)
|
|
279
|
-
]),
|
|
280
|
-
factory.createTypeReferenceNode(
|
|
281
|
-
factory.createIdentifier("TParams"),
|
|
282
|
-
undefined
|
|
283
|
-
)
|
|
284
|
-
),
|
|
284
|
+
factory.createKeywordTypeNode(ts.SyntaxKind.VoidKeyword),
|
|
285
285
|
undefined
|
|
286
286
|
),
|
|
287
287
|
factory.createParameterDeclaration(
|
|
@@ -338,26 +338,9 @@ export const createServiceOperationUseMutationNodes = () => [
|
|
|
338
338
|
undefined
|
|
339
339
|
)
|
|
340
340
|
]),
|
|
341
|
-
factory.
|
|
342
|
-
factory.
|
|
343
|
-
|
|
344
|
-
[factory.createTypeReferenceNode(
|
|
345
|
-
factory.createIdentifier("TVariables"),
|
|
346
|
-
undefined
|
|
347
|
-
)]
|
|
348
|
-
),
|
|
349
|
-
factory.createLiteralTypeNode(factory.createTrue()),
|
|
350
|
-
factory.createUnionTypeNode([
|
|
351
|
-
factory.createTypeReferenceNode(
|
|
352
|
-
factory.createIdentifier("TVariables"),
|
|
353
|
-
undefined
|
|
354
|
-
),
|
|
355
|
-
factory.createKeywordTypeNode(ts.SyntaxKind.VoidKeyword)
|
|
356
|
-
]),
|
|
357
|
-
factory.createTypeReferenceNode(
|
|
358
|
-
factory.createIdentifier("TVariables"),
|
|
359
|
-
undefined
|
|
360
|
-
)
|
|
341
|
+
factory.createTypeReferenceNode(
|
|
342
|
+
factory.createIdentifier("TVariables"),
|
|
343
|
+
undefined
|
|
361
344
|
),
|
|
362
345
|
factory.createTypeReferenceNode(
|
|
363
346
|
factory.createIdentifier("TContext"),
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ServiceOperation } from '@openapi-qraft/plugin/lib/open-api/getServices';
|
|
2
|
+
import { createUseInfiniteQueryOperationTSDocExample } from './createUseInfiniteQueryOperationTSDocExample.js';
|
|
3
|
+
import { createUseIsFetchingOperationTSDocExample } from './createUseIsFetchingOperationTSDocExample.js';
|
|
4
|
+
import { createUseIsMutatingOperationTSDocExample } from './createUseIsMutatingOperationTSDocExample.js';
|
|
5
|
+
import { createUseMutationOperationTSDocExample } from './createUseMutationOperationTSDocExample.js';
|
|
6
|
+
import { createUseQueryOperationTSDocExample } from './createUseQueryOperationTSDocExample.js';
|
|
7
|
+
|
|
8
|
+
export const createOperationMethodTSDocExample = (
|
|
9
|
+
operation: ServiceOperation,
|
|
10
|
+
{
|
|
11
|
+
serviceVariableName,
|
|
12
|
+
operationMethodName,
|
|
13
|
+
}: {
|
|
14
|
+
serviceVariableName: string;
|
|
15
|
+
operationMethodName: string;
|
|
16
|
+
}
|
|
17
|
+
) => {
|
|
18
|
+
switch (operationMethodName) {
|
|
19
|
+
case 'useQuery':
|
|
20
|
+
return createUseQueryOperationTSDocExample(
|
|
21
|
+
operation,
|
|
22
|
+
serviceVariableName
|
|
23
|
+
);
|
|
24
|
+
case 'useMutation':
|
|
25
|
+
return createUseMutationOperationTSDocExample(
|
|
26
|
+
operation,
|
|
27
|
+
serviceVariableName
|
|
28
|
+
);
|
|
29
|
+
case 'useInfiniteQuery':
|
|
30
|
+
return createUseInfiniteQueryOperationTSDocExample(
|
|
31
|
+
operation,
|
|
32
|
+
serviceVariableName
|
|
33
|
+
);
|
|
34
|
+
case 'useIsFetching':
|
|
35
|
+
return createUseIsFetchingOperationTSDocExample(
|
|
36
|
+
operation,
|
|
37
|
+
serviceVariableName
|
|
38
|
+
);
|
|
39
|
+
case 'useIsMutating':
|
|
40
|
+
return createUseIsMutatingOperationTSDocExample(
|
|
41
|
+
operation,
|
|
42
|
+
serviceVariableName
|
|
43
|
+
);
|
|
44
|
+
default:
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { ServiceOperation } from '@openapi-qraft/plugin/lib/open-api/getServices';
|
|
2
|
+
import camelcase from 'camelcase';
|
|
3
|
+
import ts from 'typescript';
|
|
4
|
+
import { astToString } from '../astToString.js';
|
|
5
|
+
import { createOperationMethodExampleNodes } from './lib/createOperationMethodExampleNodes.js';
|
|
6
|
+
import { createOperationMethodParametersExampleNodes } from './lib/createOperationMethodParametersExampleNodes.js';
|
|
7
|
+
|
|
8
|
+
export const createUseInfiniteQueryOperationTSDocExample = (
|
|
9
|
+
operation: ServiceOperation,
|
|
10
|
+
serviceVariableName: string
|
|
11
|
+
): string[] => {
|
|
12
|
+
const factory = ts.factory;
|
|
13
|
+
|
|
14
|
+
const commonTSDoc = [
|
|
15
|
+
'Performs asynchronous data fetching with support for infinite scrolling scenarios.',
|
|
16
|
+
'Manages paginated data and provides utilities for fetching additional pages.',
|
|
17
|
+
'',
|
|
18
|
+
'@see {@link https://openapi-qraft.github.io/openapi-qraft/docs/hooks/useInfiniteQuery|`useInfiniteQuery(...)` documentation}',
|
|
19
|
+
'',
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
if (!operation.parameters?.length) {
|
|
23
|
+
return [
|
|
24
|
+
...commonTSDoc,
|
|
25
|
+
'@example Infinite Query without parameters',
|
|
26
|
+
'```ts',
|
|
27
|
+
...(
|
|
28
|
+
'const { data, isLoading } = ' +
|
|
29
|
+
astToString(
|
|
30
|
+
createOperationMethodExampleNodes(
|
|
31
|
+
operation,
|
|
32
|
+
{
|
|
33
|
+
serviceVariableName,
|
|
34
|
+
operationMethodName: 'useInfiniteQuery',
|
|
35
|
+
},
|
|
36
|
+
undefined
|
|
37
|
+
)
|
|
38
|
+
)
|
|
39
|
+
)
|
|
40
|
+
.trim()
|
|
41
|
+
.split('\n'),
|
|
42
|
+
'```',
|
|
43
|
+
];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return [
|
|
47
|
+
...commonTSDoc,
|
|
48
|
+
'@example Infinite Query with parameters',
|
|
49
|
+
'```ts',
|
|
50
|
+
...(
|
|
51
|
+
'const { data, isLoading } = ' +
|
|
52
|
+
astToString(
|
|
53
|
+
createOperationMethodExampleNodes(
|
|
54
|
+
operation,
|
|
55
|
+
{
|
|
56
|
+
serviceVariableName,
|
|
57
|
+
operationMethodName: 'useInfiniteQuery',
|
|
58
|
+
},
|
|
59
|
+
[
|
|
60
|
+
factory.createObjectLiteralExpression(
|
|
61
|
+
createOperationMethodParametersExampleNodes(operation),
|
|
62
|
+
true
|
|
63
|
+
),
|
|
64
|
+
createInfiniteQueryOptionsArgumentExampleNodes(operation),
|
|
65
|
+
]
|
|
66
|
+
)
|
|
67
|
+
)
|
|
68
|
+
)
|
|
69
|
+
.trim()
|
|
70
|
+
.split('\n'),
|
|
71
|
+
'```',
|
|
72
|
+
];
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
function createInfiniteQueryOptionsArgumentExampleNodes(
|
|
76
|
+
operation: ServiceOperation
|
|
77
|
+
): ts.ObjectLiteralExpression {
|
|
78
|
+
const factory = ts.factory;
|
|
79
|
+
|
|
80
|
+
return factory.createObjectLiteralExpression(
|
|
81
|
+
[
|
|
82
|
+
factory.createPropertyAssignment(
|
|
83
|
+
factory.createIdentifier('getNextPageParam'),
|
|
84
|
+
factory.createArrowFunction(
|
|
85
|
+
undefined,
|
|
86
|
+
undefined,
|
|
87
|
+
[
|
|
88
|
+
factory.createParameterDeclaration(
|
|
89
|
+
undefined,
|
|
90
|
+
undefined,
|
|
91
|
+
factory.createIdentifier('lastPage'),
|
|
92
|
+
undefined,
|
|
93
|
+
undefined,
|
|
94
|
+
undefined
|
|
95
|
+
),
|
|
96
|
+
factory.createParameterDeclaration(
|
|
97
|
+
undefined,
|
|
98
|
+
undefined,
|
|
99
|
+
factory.createIdentifier('allPages'),
|
|
100
|
+
undefined,
|
|
101
|
+
undefined,
|
|
102
|
+
undefined
|
|
103
|
+
),
|
|
104
|
+
factory.createParameterDeclaration(
|
|
105
|
+
undefined,
|
|
106
|
+
undefined,
|
|
107
|
+
factory.createIdentifier('lastPageParam'),
|
|
108
|
+
undefined,
|
|
109
|
+
undefined,
|
|
110
|
+
undefined
|
|
111
|
+
),
|
|
112
|
+
factory.createParameterDeclaration(
|
|
113
|
+
undefined,
|
|
114
|
+
undefined,
|
|
115
|
+
factory.createIdentifier('allPageParams'),
|
|
116
|
+
undefined,
|
|
117
|
+
undefined,
|
|
118
|
+
undefined
|
|
119
|
+
),
|
|
120
|
+
],
|
|
121
|
+
undefined,
|
|
122
|
+
factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken),
|
|
123
|
+
factory.createCallExpression(
|
|
124
|
+
factory.createIdentifier('getNextPageParams'),
|
|
125
|
+
undefined,
|
|
126
|
+
[factory.createIdentifier('lastPage')]
|
|
127
|
+
)
|
|
128
|
+
)
|
|
129
|
+
),
|
|
130
|
+
factory.createPropertyAssignment(
|
|
131
|
+
factory.createIdentifier('initialPageParam'),
|
|
132
|
+
factory.createObjectLiteralExpression(
|
|
133
|
+
createOperationMethodParametersExampleNodes(
|
|
134
|
+
operation,
|
|
135
|
+
(operationParameter) =>
|
|
136
|
+
operationParameter.in === 'query'
|
|
137
|
+
? camelcase(`initial-${operationParameter.name}`)
|
|
138
|
+
: camelcase(operationParameter.name)
|
|
139
|
+
),
|
|
140
|
+
true
|
|
141
|
+
)
|
|
142
|
+
),
|
|
143
|
+
],
|
|
144
|
+
true
|
|
145
|
+
);
|
|
146
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { ServiceOperation } from '@openapi-qraft/plugin/lib/open-api/getServices';
|
|
2
|
+
import camelcase from 'camelcase';
|
|
3
|
+
import ts from 'typescript';
|
|
4
|
+
import { astToString } from '../astToString.js';
|
|
5
|
+
import { createOperationMethodExampleNodes } from './lib/createOperationMethodExampleNodes.js';
|
|
6
|
+
import { createOperationMethodParametersExampleNodes } from './lib/createOperationMethodParametersExampleNodes.js';
|
|
7
|
+
|
|
8
|
+
export const createUseIsFetchingOperationTSDocExample = (
|
|
9
|
+
operation: ServiceOperation,
|
|
10
|
+
serviceVariableName: string
|
|
11
|
+
) => {
|
|
12
|
+
const example: string[] = [
|
|
13
|
+
'Monitors the number of queries currently fetching, matching the provided filters.',
|
|
14
|
+
'Useful for creating loading indicators or performing actions based on active requests.',
|
|
15
|
+
'',
|
|
16
|
+
'@see {@link https://openapi-qraft.github.io/openapi-qraft/docs/hooks/useIsFetching|`useIsFetching(...)` documentation}',
|
|
17
|
+
'@example Checks the total number of queries fetching from the specified service method,',
|
|
18
|
+
'both normal and infinite. If no parameters are provided, no filtering is applied.',
|
|
19
|
+
'```ts',
|
|
20
|
+
...(
|
|
21
|
+
`const ${camelcase(operation.name + '-total')} = ` +
|
|
22
|
+
astToString(
|
|
23
|
+
createOperationMethodExampleNodes(
|
|
24
|
+
operation,
|
|
25
|
+
{
|
|
26
|
+
serviceVariableName,
|
|
27
|
+
operationMethodName: 'useIsFetching',
|
|
28
|
+
},
|
|
29
|
+
undefined
|
|
30
|
+
)
|
|
31
|
+
)
|
|
32
|
+
)
|
|
33
|
+
.trim()
|
|
34
|
+
.split('\n'),
|
|
35
|
+
'```',
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
if (operation.parameters?.length) {
|
|
39
|
+
const factory = ts.factory;
|
|
40
|
+
|
|
41
|
+
example.push(
|
|
42
|
+
'@example Checks the number of normal queries fetching with the specified parameters.',
|
|
43
|
+
'```ts',
|
|
44
|
+
...(
|
|
45
|
+
`const ${camelcase(operation.name + '-by-parameters-total')} = ` +
|
|
46
|
+
astToString(
|
|
47
|
+
createOperationMethodExampleNodes(
|
|
48
|
+
operation,
|
|
49
|
+
{
|
|
50
|
+
serviceVariableName,
|
|
51
|
+
operationMethodName: 'useIsFetching',
|
|
52
|
+
},
|
|
53
|
+
[
|
|
54
|
+
factory.createObjectLiteralExpression(
|
|
55
|
+
[
|
|
56
|
+
factory.createPropertyAssignment(
|
|
57
|
+
factory.createIdentifier('infinite'),
|
|
58
|
+
factory.createFalse()
|
|
59
|
+
),
|
|
60
|
+
factory.createPropertyAssignment(
|
|
61
|
+
factory.createIdentifier('parameters'),
|
|
62
|
+
factory.createObjectLiteralExpression(
|
|
63
|
+
createOperationMethodParametersExampleNodes(operation),
|
|
64
|
+
true
|
|
65
|
+
)
|
|
66
|
+
),
|
|
67
|
+
],
|
|
68
|
+
true
|
|
69
|
+
),
|
|
70
|
+
]
|
|
71
|
+
)
|
|
72
|
+
)
|
|
73
|
+
)
|
|
74
|
+
.trim()
|
|
75
|
+
.split('\n'),
|
|
76
|
+
'```'
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return example;
|
|
81
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { ServiceOperation } from '@openapi-qraft/plugin/lib/open-api/getServices';
|
|
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 { createOperationMethodExampleNodes } from './lib/createOperationMethodExampleNodes.js';
|
|
7
|
+
import { createOperationMethodParametersExampleNodes } from './lib/createOperationMethodParametersExampleNodes.js';
|
|
8
|
+
|
|
9
|
+
export const createUseIsMutatingOperationTSDocExample = (
|
|
10
|
+
operation: ServiceOperation,
|
|
11
|
+
serviceVariableName: string
|
|
12
|
+
) => {
|
|
13
|
+
const factory = ts.factory;
|
|
14
|
+
|
|
15
|
+
const example: string[] = [
|
|
16
|
+
'Returns the count of currently in-progress mutations.',
|
|
17
|
+
'',
|
|
18
|
+
...createOperationCommonTSDoc(operation),
|
|
19
|
+
'@see {@link https://openapi-qraft.github.io/openapi-qraft/docs/hooks/useIsMutating|`useIsMutating(...)` documentation}',
|
|
20
|
+
|
|
21
|
+
'@example Check how many mutations are currently in progress for the specified service method.',
|
|
22
|
+
'```ts',
|
|
23
|
+
...(
|
|
24
|
+
`const ${camelcase(operation.name + '-total')} = ` +
|
|
25
|
+
astToString(
|
|
26
|
+
createOperationMethodExampleNodes(
|
|
27
|
+
operation,
|
|
28
|
+
{
|
|
29
|
+
serviceVariableName,
|
|
30
|
+
operationMethodName: 'useIsMutating',
|
|
31
|
+
},
|
|
32
|
+
undefined
|
|
33
|
+
)
|
|
34
|
+
)
|
|
35
|
+
)
|
|
36
|
+
.trim()
|
|
37
|
+
.split('\n'),
|
|
38
|
+
'```',
|
|
39
|
+
|
|
40
|
+
'@example Check how many mutations are currently in progress with the specified parameters.',
|
|
41
|
+
'```ts',
|
|
42
|
+
...(
|
|
43
|
+
`const ${camelcase(operation.name + '-total')} = ` +
|
|
44
|
+
astToString(
|
|
45
|
+
createOperationMethodExampleNodes(
|
|
46
|
+
operation,
|
|
47
|
+
{
|
|
48
|
+
serviceVariableName,
|
|
49
|
+
operationMethodName: 'useIsMutating',
|
|
50
|
+
},
|
|
51
|
+
[
|
|
52
|
+
factory.createObjectLiteralExpression(
|
|
53
|
+
[
|
|
54
|
+
factory.createPropertyAssignment(
|
|
55
|
+
factory.createIdentifier('parameters'),
|
|
56
|
+
factory.createObjectLiteralExpression(
|
|
57
|
+
createOperationMethodParametersExampleNodes(operation),
|
|
58
|
+
true
|
|
59
|
+
)
|
|
60
|
+
),
|
|
61
|
+
],
|
|
62
|
+
true
|
|
63
|
+
),
|
|
64
|
+
]
|
|
65
|
+
)
|
|
66
|
+
)
|
|
67
|
+
)
|
|
68
|
+
.trim()
|
|
69
|
+
.split('\n'),
|
|
70
|
+
'```',
|
|
71
|
+
];
|
|
72
|
+
|
|
73
|
+
return example;
|
|
74
|
+
};
|