@openapi-qraft/tanstack-query-react-plugin 2.0.0-next.9 → 2.0.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.
Files changed (115) hide show
  1. package/CHANGELOG.md +116 -0
  2. package/dist/generateCode.d.ts +3 -3
  3. package/dist/generateCode.d.ts.map +1 -1
  4. package/dist/generateCode.js +3 -3
  5. package/dist/generateCode.js.map +1 -1
  6. package/dist/lib/createOperationCommonTSDoc.d.ts +1 -1
  7. package/dist/lib/createOperationCommonTSDoc.d.ts.map +1 -1
  8. package/dist/plugin.d.ts.map +1 -1
  9. package/dist/plugin.js +4 -1
  10. package/dist/plugin.js.map +1 -1
  11. package/dist/ts-factory/filterUnusedTypes.d.ts +9 -0
  12. package/dist/ts-factory/filterUnusedTypes.d.ts.map +1 -0
  13. package/dist/ts-factory/filterUnusedTypes.js +34 -0
  14. package/dist/ts-factory/filterUnusedTypes.js.map +1 -0
  15. package/dist/ts-factory/getClientFactory.d.ts +1 -1
  16. package/dist/ts-factory/getClientFactory.d.ts.map +1 -1
  17. package/dist/ts-factory/getClientFactory.js +1 -1
  18. package/dist/ts-factory/getClientFactory.js.map +1 -1
  19. package/dist/ts-factory/getIndexFactory.d.ts +1 -1
  20. package/dist/ts-factory/getIndexFactory.d.ts.map +1 -1
  21. package/dist/ts-factory/getIndexFactory.js +2 -2
  22. package/dist/ts-factory/getIndexFactory.js.map +1 -1
  23. package/dist/ts-factory/getServiceFactory.d.ts +1 -1
  24. package/dist/ts-factory/getServiceFactory.d.ts.map +1 -1
  25. package/dist/ts-factory/getServiceFactory.js +54 -42
  26. package/dist/ts-factory/getServiceFactory.js.map +1 -1
  27. package/dist/ts-factory/getServiceIndexFactory.d.ts +3 -3
  28. package/dist/ts-factory/getServiceIndexFactory.d.ts.map +1 -1
  29. package/dist/ts-factory/getServiceIndexFactory.js +1 -1
  30. package/dist/ts-factory/getServiceIndexFactory.js.map +1 -1
  31. package/dist/ts-factory/service-operation.generated/ServiceOperationFetchInfiniteQuery.d.ts.map +1 -1
  32. package/dist/ts-factory/service-operation.generated/ServiceOperationFetchInfiniteQuery.js +26 -67
  33. package/dist/ts-factory/service-operation.generated/ServiceOperationFetchInfiniteQuery.js.map +1 -1
  34. package/dist/ts-factory/service-operation.generated/ServiceOperationFetchQuery.d.ts.map +1 -1
  35. package/dist/ts-factory/service-operation.generated/ServiceOperationFetchQuery.js +16 -1
  36. package/dist/ts-factory/service-operation.generated/ServiceOperationFetchQuery.js.map +1 -1
  37. package/dist/ts-factory/service-operation.generated/ServiceOperationMutationFn.d.ts.map +1 -1
  38. package/dist/ts-factory/service-operation.generated/ServiceOperationMutationFn.js +7 -4
  39. package/dist/ts-factory/service-operation.generated/ServiceOperationMutationFn.js.map +1 -1
  40. package/dist/ts-factory/service-operation.generated/ServiceOperationSetQueryData.d.ts.map +1 -1
  41. package/dist/ts-factory/service-operation.generated/ServiceOperationSetQueryData.js +9 -3
  42. package/dist/ts-factory/service-operation.generated/ServiceOperationSetQueryData.js.map +1 -1
  43. package/dist/ts-factory/tsdoc/createOperationMethodTSDocExample.d.ts +1 -1
  44. package/dist/ts-factory/tsdoc/createOperationMethodTSDocExample.d.ts.map +1 -1
  45. package/dist/ts-factory/tsdoc/createOperationMethodTSDocExample.js +9 -0
  46. package/dist/ts-factory/tsdoc/createOperationMethodTSDocExample.js.map +1 -1
  47. package/dist/ts-factory/tsdoc/createUseInfiniteQueryOperationTSDocExample.d.ts +3 -1
  48. package/dist/ts-factory/tsdoc/createUseInfiniteQueryOperationTSDocExample.d.ts.map +1 -1
  49. package/dist/ts-factory/tsdoc/createUseInfiniteQueryOperationTSDocExample.js +19 -27
  50. package/dist/ts-factory/tsdoc/createUseInfiniteQueryOperationTSDocExample.js.map +1 -1
  51. package/dist/ts-factory/tsdoc/createUseIsFetchingOperationTSDocExample.d.ts +1 -1
  52. package/dist/ts-factory/tsdoc/createUseIsFetchingOperationTSDocExample.d.ts.map +1 -1
  53. package/dist/ts-factory/tsdoc/createUseIsFetchingOperationTSDocExample.js +3 -3
  54. package/dist/ts-factory/tsdoc/createUseIsFetchingOperationTSDocExample.js.map +1 -1
  55. package/dist/ts-factory/tsdoc/createUseIsMutatingOperationTSDocExample.d.ts +1 -1
  56. package/dist/ts-factory/tsdoc/createUseIsMutatingOperationTSDocExample.d.ts.map +1 -1
  57. package/dist/ts-factory/tsdoc/createUseIsMutatingOperationTSDocExample.js +3 -3
  58. package/dist/ts-factory/tsdoc/createUseIsMutatingOperationTSDocExample.js.map +1 -1
  59. package/dist/ts-factory/tsdoc/createUseMutationOperationTSDocExample.d.ts +1 -1
  60. package/dist/ts-factory/tsdoc/createUseMutationOperationTSDocExample.d.ts.map +1 -1
  61. package/dist/ts-factory/tsdoc/createUseMutationOperationTSDocExample.js +3 -3
  62. package/dist/ts-factory/tsdoc/createUseMutationOperationTSDocExample.js.map +1 -1
  63. package/dist/ts-factory/tsdoc/createUseMutationStateOperationTSDocExample.d.ts +3 -0
  64. package/dist/ts-factory/tsdoc/createUseMutationStateOperationTSDocExample.d.ts.map +1 -0
  65. package/dist/ts-factory/tsdoc/createUseMutationStateOperationTSDocExample.js +55 -0
  66. package/dist/ts-factory/tsdoc/createUseMutationStateOperationTSDocExample.js.map +1 -0
  67. package/dist/ts-factory/tsdoc/createUseQueriesOperationTSDocExample.d.ts +3 -0
  68. package/dist/ts-factory/tsdoc/createUseQueriesOperationTSDocExample.d.ts.map +1 -0
  69. package/dist/ts-factory/tsdoc/createUseQueriesOperationTSDocExample.js +88 -0
  70. package/dist/ts-factory/tsdoc/createUseQueriesOperationTSDocExample.js.map +1 -0
  71. package/dist/ts-factory/tsdoc/createUseQueryOperationTSDocExample.d.ts +1 -1
  72. package/dist/ts-factory/tsdoc/createUseQueryOperationTSDocExample.d.ts.map +1 -1
  73. package/dist/ts-factory/tsdoc/createUseQueryOperationTSDocExample.js +3 -3
  74. package/dist/ts-factory/tsdoc/createUseQueryOperationTSDocExample.js.map +1 -1
  75. package/dist/ts-factory/tsdoc/createUseSuspenseInfiniteQueryOperationTSDocExample.d.ts +3 -0
  76. package/dist/ts-factory/tsdoc/createUseSuspenseInfiniteQueryOperationTSDocExample.d.ts.map +1 -0
  77. package/dist/ts-factory/tsdoc/createUseSuspenseInfiniteQueryOperationTSDocExample.js +39 -0
  78. package/dist/ts-factory/tsdoc/createUseSuspenseInfiniteQueryOperationTSDocExample.js.map +1 -0
  79. package/dist/ts-factory/tsdoc/lib/createOperationMethodCallExpressionExampleNode.d.ts +7 -0
  80. package/dist/ts-factory/tsdoc/lib/createOperationMethodCallExpressionExampleNode.d.ts.map +1 -0
  81. package/dist/ts-factory/tsdoc/lib/createOperationMethodCallExpressionExampleNode.js +6 -0
  82. package/dist/ts-factory/tsdoc/lib/createOperationMethodCallExpressionExampleNode.js.map +1 -0
  83. package/dist/ts-factory/tsdoc/lib/createOperationMethodParametersExampleNodes.d.ts +1 -1
  84. package/dist/ts-factory/tsdoc/lib/createOperationMethodParametersExampleNodes.d.ts.map +1 -1
  85. package/dist/ts-factory/tsdoc/lib/createOperationMethodParametersExampleNodes.js +17 -1
  86. package/dist/ts-factory/tsdoc/lib/createOperationMethodParametersExampleNodes.js.map +1 -1
  87. package/package.json +4 -4
  88. package/src/generateCode.ts +8 -8
  89. package/src/lib/createOperationCommonTSDoc.ts +1 -1
  90. package/src/plugin.ts +8 -3
  91. package/src/ts-factory/filterUnusedTypes.ts +49 -0
  92. package/src/ts-factory/getClientFactory.ts +2 -2
  93. package/src/ts-factory/getIndexFactory.ts +13 -4
  94. package/src/ts-factory/getServiceFactory.ts +98 -69
  95. package/src/ts-factory/getServiceIndexFactory.ts +7 -7
  96. package/src/ts-factory/service-operation.generated/ServiceOperationFetchInfiniteQuery.ts +101 -190
  97. package/src/ts-factory/service-operation.generated/ServiceOperationFetchQuery.ts +80 -0
  98. package/src/ts-factory/service-operation.generated/ServiceOperationMutationFn.ts +23 -22
  99. package/src/ts-factory/service-operation.generated/ServiceOperationSetQueryData.ts +34 -10
  100. package/src/ts-factory/tsdoc/createOperationMethodTSDocExample.ts +19 -1
  101. package/src/ts-factory/tsdoc/createUseInfiniteQueryOperationTSDocExample.ts +84 -95
  102. package/src/ts-factory/tsdoc/createUseIsFetchingOperationTSDocExample.ts +4 -4
  103. package/src/ts-factory/tsdoc/createUseIsMutatingOperationTSDocExample.ts +4 -4
  104. package/src/ts-factory/tsdoc/createUseMutationOperationTSDocExample.ts +4 -4
  105. package/src/ts-factory/tsdoc/createUseMutationStateOperationTSDocExample.ts +154 -0
  106. package/src/ts-factory/tsdoc/createUseQueriesOperationTSDocExample.ts +292 -0
  107. package/src/ts-factory/tsdoc/createUseQueryOperationTSDocExample.ts +4 -4
  108. package/src/ts-factory/tsdoc/createUseSuspenseInfiniteQueryOperationTSDocExample.ts +63 -0
  109. package/src/ts-factory/tsdoc/lib/createOperationMethodCallExpressionExampleNode.ts +28 -0
  110. package/src/ts-factory/tsdoc/lib/createOperationMethodParametersExampleNodes.ts +19 -2
  111. package/dist/ts-factory/tsdoc/lib/createOperationMethodExampleNodes.d.ts +0 -7
  112. package/dist/ts-factory/tsdoc/lib/createOperationMethodExampleNodes.d.ts.map +0 -1
  113. package/dist/ts-factory/tsdoc/lib/createOperationMethodExampleNodes.js +0 -8
  114. package/dist/ts-factory/tsdoc/lib/createOperationMethodExampleNodes.js.map +0 -1
  115. package/src/ts-factory/tsdoc/lib/createOperationMethodExampleNodes.ts +0 -32
@@ -0,0 +1,292 @@
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 { createOperationMethodCallExpressionExampleNode } from './lib/createOperationMethodCallExpressionExampleNode.js';
7
+ import { createOperationMethodParametersExampleNodes } from './lib/createOperationMethodParametersExampleNodes.js';
8
+
9
+ export const createUseQueriesOperationTSDocExample = (
10
+ operation: ServiceOperation,
11
+ serviceVariableName: string
12
+ ) => {
13
+ const factory = ts.factory;
14
+
15
+ const example: string[] = [
16
+ 'Allows you to execute multiple asynchronous data fetching operations concurrently. This is especially useful for managing complex data dependencies in parallel.',
17
+ '',
18
+ ...createOperationCommonTSDoc(operation),
19
+ '@see {@link https://openapi-qraft.github.io/openapi-qraft/docs/hooks/useQueries|`useQueries(...)` documentation}',
20
+
21
+ '@example Multiple queries. Returns `data`, `error`, `isSuccess` and other properties.',
22
+ '```ts',
23
+ ...astToString([
24
+ factory.createVariableStatement(
25
+ undefined,
26
+ factory.createVariableDeclarationList(
27
+ [
28
+ factory.createVariableDeclaration(
29
+ factory.createIdentifier(camelcase(operation.name + '-results')),
30
+ undefined,
31
+ undefined,
32
+ createOperationMethodCallExpressionExampleNode(
33
+ operation,
34
+ {
35
+ serviceVariableName,
36
+ operationMethodName: 'useQueries',
37
+ },
38
+ [
39
+ factory.createObjectLiteralExpression(
40
+ [
41
+ factory.createPropertyAssignment(
42
+ factory.createIdentifier('queries'),
43
+ factory.createArrayLiteralExpression(
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
+ )
62
+ ),
63
+ ],
64
+ true
65
+ ),
66
+ ]
67
+ )
68
+ ),
69
+ ],
70
+ ts.NodeFlags.Const
71
+ )
72
+ ),
73
+ factory.createExpressionStatement(
74
+ factory.createCallExpression(
75
+ factory.createPropertyAccessExpression(
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
+ )
135
+ ),
136
+ ])
137
+ .trim()
138
+ .split('\n'),
139
+ '```',
140
+
141
+ '@example Combined results. Only the data will be returned.',
142
+ '```ts',
143
+ ...astToString([
144
+ factory.createVariableStatement(
145
+ undefined,
146
+ factory.createVariableDeclarationList(
147
+ [
148
+ factory.createVariableDeclaration(
149
+ factory.createIdentifier(
150
+ camelcase(operation.name + '-combined-results')
151
+ ),
152
+ undefined,
153
+ undefined,
154
+ createOperationMethodCallExpressionExampleNode(
155
+ operation,
156
+ {
157
+ serviceVariableName,
158
+ operationMethodName: 'useQueries',
159
+ },
160
+ [
161
+ factory.createObjectLiteralExpression(
162
+ [
163
+ factory.createPropertyAssignment(
164
+ factory.createIdentifier('combine'),
165
+ factory.createArrowFunction(
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
+ )
208
+ ),
209
+ factory.createPropertyAssignment(
210
+ factory.createIdentifier('queries'),
211
+ factory.createArrayLiteralExpression(
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
+ )
230
+ ),
231
+ ],
232
+ true
233
+ ),
234
+ ]
235
+ )
236
+ ),
237
+ ],
238
+ ts.NodeFlags.Const
239
+ )
240
+ ),
241
+ factory.createExpressionStatement(
242
+ factory.createCallExpression(
243
+ factory.createPropertyAccessExpression(
244
+ factory.createIdentifier(
245
+ camelcase(operation.name + '-combined-results')
246
+ ),
247
+ factory.createIdentifier('forEach')
248
+ ),
249
+ undefined,
250
+ [
251
+ factory.createArrowFunction(
252
+ undefined,
253
+ undefined,
254
+ [
255
+ factory.createParameterDeclaration(
256
+ undefined,
257
+ undefined,
258
+ factory.createIdentifier('data')
259
+ ),
260
+ ],
261
+ undefined,
262
+ factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken),
263
+ factory.createCallExpression(
264
+ factory.createPropertyAccessExpression(
265
+ factory.createIdentifier('console'),
266
+ factory.createIdentifier('log')
267
+ ),
268
+ undefined,
269
+ [
270
+ factory.createObjectLiteralExpression(
271
+ [
272
+ factory.createShorthandPropertyAssignment(
273
+ factory.createIdentifier('data'),
274
+ undefined
275
+ ),
276
+ ],
277
+ false
278
+ ),
279
+ ]
280
+ )
281
+ ),
282
+ ]
283
+ )
284
+ ),
285
+ ])
286
+ .trim()
287
+ .split('\n'),
288
+ '```',
289
+ ];
290
+
291
+ return example;
292
+ };
@@ -1,8 +1,8 @@
1
- import { ServiceOperation } from '@openapi-qraft/plugin/lib/open-api/getServices';
1
+ import { ServiceOperation } from '@openapi-qraft/plugin/lib/open-api/OpenAPIService';
2
2
  import ts from 'typescript';
3
3
  import { createOperationCommonTSDoc } from '../../lib/createOperationCommonTSDoc.js';
4
4
  import { astToString } from '../astToString.js';
5
- import { createOperationMethodExampleNodes } from './lib/createOperationMethodExampleNodes.js';
5
+ import { createOperationMethodCallExpressionExampleNode } from './lib/createOperationMethodCallExpressionExampleNode.js';
6
6
  import { createOperationMethodParametersExampleNodes } from './lib/createOperationMethodParametersExampleNodes.js';
7
7
 
8
8
  export const createUseQueryOperationTSDocExample = (
@@ -26,7 +26,7 @@ export const createUseQueryOperationTSDocExample = (
26
26
  ...(
27
27
  'const { data, isLoading } = ' +
28
28
  astToString(
29
- createOperationMethodExampleNodes(
29
+ createOperationMethodCallExpressionExampleNode(
30
30
  operation,
31
31
  {
32
32
  serviceVariableName,
@@ -51,7 +51,7 @@ export const createUseQueryOperationTSDocExample = (
51
51
  ...(
52
52
  'const { data, isLoading } = ' +
53
53
  astToString(
54
- createOperationMethodExampleNodes(
54
+ createOperationMethodCallExpressionExampleNode(
55
55
  operation,
56
56
  {
57
57
  serviceVariableName,
@@ -0,0 +1,63 @@
1
+ import { ServiceOperation } from '@openapi-qraft/plugin/lib/open-api/OpenAPIService';
2
+ import ts from 'typescript';
3
+ import { astToString } from '../astToString.js';
4
+ import { createInfiniteQueryOptionsArgumentExamplePropertyAssignmentNodes } from './createUseInfiniteQueryOperationTSDocExample.js';
5
+ import { createOperationMethodCallExpressionExampleNode } from './lib/createOperationMethodCallExpressionExampleNode.js';
6
+ import { createOperationMethodParametersExampleNodes } from './lib/createOperationMethodParametersExampleNodes.js';
7
+
8
+ export const createUseSuspenseInfiniteQueryOperationTSDocExample = (
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
+ 'It functions similarly to `useInfiniteQuery`, but with added support for React Suspense.',
18
+ '',
19
+ '@see {@link https://openapi-qraft.github.io/openapi-qraft/docs/hooks/useSuspenseInfiniteQuery|`useSuspenseInfiniteQuery(...)` documentation}',
20
+ '',
21
+ ];
22
+
23
+ return [
24
+ ...commonTSDoc,
25
+ '@example Suspense Infinite Query',
26
+ '```ts',
27
+ ...(
28
+ 'const { data, isLoading, fetchNextPage } = ' +
29
+ astToString(
30
+ createOperationMethodCallExpressionExampleNode(
31
+ operation,
32
+ {
33
+ serviceVariableName,
34
+ operationMethodName: 'useSuspenseInfiniteQuery',
35
+ },
36
+ [
37
+ factory.createObjectLiteralExpression(
38
+ createOperationMethodParametersExampleNodes({
39
+ ...operation,
40
+ parameters: operation.parameters?.filter((parameter) =>
41
+ parameter.in === 'query' ? parameter.required : true
42
+ ),
43
+ }),
44
+ true
45
+ ),
46
+ factory.createObjectLiteralExpression(
47
+ createInfiniteQueryOptionsArgumentExamplePropertyAssignmentNodes(
48
+ operation
49
+ ),
50
+ true
51
+ ),
52
+ ]
53
+ )
54
+ )
55
+ )
56
+ .trim()
57
+ .split('\n'),
58
+ '',
59
+ 'console.log(data);',
60
+ 'fetchNextPage(); // Fetch the next page',
61
+ '```',
62
+ ];
63
+ };
@@ -0,0 +1,28 @@
1
+ import { ServiceOperation } from '@openapi-qraft/plugin/lib/open-api/OpenAPIService';
2
+ import ts from 'typescript';
3
+
4
+ export const createOperationMethodCallExpressionExampleNode = (
5
+ operation: ServiceOperation,
6
+ {
7
+ serviceVariableName,
8
+ operationMethodName,
9
+ }: { serviceVariableName: string; operationMethodName: string },
10
+ nodes: ts.Expression[] | undefined
11
+ ) => {
12
+ const factory = ts.factory;
13
+
14
+ return factory.createCallExpression(
15
+ factory.createPropertyAccessExpression(
16
+ factory.createPropertyAccessExpression(
17
+ factory.createPropertyAccessExpression(
18
+ factory.createIdentifier('qraft'),
19
+ factory.createIdentifier(serviceVariableName)
20
+ ),
21
+ factory.createIdentifier(operation.name)
22
+ ),
23
+ factory.createIdentifier(operationMethodName)
24
+ ),
25
+ undefined,
26
+ nodes
27
+ );
28
+ };
@@ -1,4 +1,4 @@
1
- import { ServiceOperation } from '@openapi-qraft/plugin/lib/open-api/getServices';
1
+ import { ServiceOperation } from '@openapi-qraft/plugin/lib/open-api/OpenAPIService';
2
2
  import camelcase from 'camelcase';
3
3
  import ts from 'typescript';
4
4
 
@@ -46,7 +46,9 @@ export const createOperationMethodParametersExampleNodes = (
46
46
  factory.createObjectLiteralExpression(
47
47
  operationParameters.map((parameter) =>
48
48
  factory.createPropertyAssignment(
49
- factory.createStringLiteral(parameter.name),
49
+ isIdentifierCompatibleVariableName(parameter.name)
50
+ ? factory.createIdentifier(parameter.name)
51
+ : factory.createStringLiteral(parameter.name),
50
52
  parameter.example // todo:: add example type inferring
51
53
  ? factory.createStringLiteral(parameter.example)
52
54
  : factory.createIdentifier(
@@ -64,3 +66,18 @@ export const createOperationMethodParametersExampleNodes = (
64
66
  []
65
67
  );
66
68
  };
69
+
70
+ /**
71
+ * Checks if the given name is a valid identifier name.
72
+ *
73
+ * @example
74
+ * ```ts
75
+ * isIdentifierCompatibleVariableName('foo'); // true
76
+ * isIdentifierCompatibleVariableName('foo-bar'); // false
77
+ * isIdentifierCompatibleVariableName('foo_bar'); // true
78
+ * isIdentifierCompatibleVariableName('foo.bar'); // false
79
+ * ```
80
+ */
81
+ function isIdentifierCompatibleVariableName(name: string) {
82
+ return !/[^a-zA-Z0-9_$]/.test(name);
83
+ }
@@ -1,7 +0,0 @@
1
- import { ServiceOperation } from '@openapi-qraft/plugin/lib/open-api/getServices';
2
- import ts from 'typescript';
3
- export declare const createOperationMethodExampleNodes: (operation: ServiceOperation, { serviceVariableName, operationMethodName, }: {
4
- serviceVariableName: string;
5
- operationMethodName: string;
6
- }, nodes: ts.Expression[] | undefined) => ts.ExpressionStatement[];
7
- //# sourceMappingURL=createOperationMethodExampleNodes.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createOperationMethodExampleNodes.d.ts","sourceRoot":"","sources":["../../../../src/ts-factory/tsdoc/lib/createOperationMethodExampleNodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gDAAgD,CAAC;AAClF,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,eAAO,MAAM,iCAAiC,cACjC,gBAAgB,iDAIxB;IAAE,mBAAmB,EAAE,MAAM,CAAC;IAAC,mBAAmB,EAAE,MAAM,CAAA;CAAE,SACxD,EAAE,CAAC,UAAU,EAAE,GAAG,SAAS,6BAsBnC,CAAC"}
@@ -1,8 +0,0 @@
1
- import ts from 'typescript';
2
- export const createOperationMethodExampleNodes = (operation, { serviceVariableName, operationMethodName, }, nodes) => {
3
- const factory = ts.factory;
4
- return [
5
- factory.createExpressionStatement(factory.createCallExpression(factory.createPropertyAccessExpression(factory.createPropertyAccessExpression(factory.createPropertyAccessExpression(factory.createIdentifier('qraft'), factory.createIdentifier(serviceVariableName)), factory.createIdentifier(operation.name)), factory.createIdentifier(operationMethodName)), undefined, nodes)),
6
- ];
7
- };
8
- //# sourceMappingURL=createOperationMethodExampleNodes.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createOperationMethodExampleNodes.js","sourceRoot":"","sources":["../../../../src/ts-factory/tsdoc/lib/createOperationMethodExampleNodes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAC/C,SAA2B,EAC3B,EACE,mBAAmB,EACnB,mBAAmB,GAC0C,EAC/D,KAAkC,EAClC,EAAE;IACF,MAAM,OAAO,GAAG,EAAE,CAAC,OAAO,CAAC;IAE3B,OAAO;QACL,OAAO,CAAC,yBAAyB,CAC/B,OAAO,CAAC,oBAAoB,CAC1B,OAAO,CAAC,8BAA8B,CACpC,OAAO,CAAC,8BAA8B,CACpC,OAAO,CAAC,8BAA8B,CACpC,OAAO,CAAC,gBAAgB,CAAC,OAAO,CAAC,EACjC,OAAO,CAAC,gBAAgB,CAAC,mBAAmB,CAAC,CAC9C,EACD,OAAO,CAAC,gBAAgB,CAAC,SAAS,CAAC,IAAI,CAAC,CACzC,EACD,OAAO,CAAC,gBAAgB,CAAC,mBAAmB,CAAC,CAC9C,EACD,SAAS,EACT,KAAK,CACN,CACF;KACF,CAAC;AACJ,CAAC,CAAC"}
@@ -1,32 +0,0 @@
1
- import { ServiceOperation } from '@openapi-qraft/plugin/lib/open-api/getServices';
2
- import ts from 'typescript';
3
-
4
- export const createOperationMethodExampleNodes = (
5
- operation: ServiceOperation,
6
- {
7
- serviceVariableName,
8
- operationMethodName,
9
- }: { serviceVariableName: string; operationMethodName: string },
10
- nodes: ts.Expression[] | undefined
11
- ) => {
12
- const factory = ts.factory;
13
-
14
- return [
15
- factory.createExpressionStatement(
16
- factory.createCallExpression(
17
- factory.createPropertyAccessExpression(
18
- factory.createPropertyAccessExpression(
19
- factory.createPropertyAccessExpression(
20
- factory.createIdentifier('qraft'),
21
- factory.createIdentifier(serviceVariableName)
22
- ),
23
- factory.createIdentifier(operation.name)
24
- ),
25
- factory.createIdentifier(operationMethodName)
26
- ),
27
- undefined,
28
- nodes
29
- )
30
- ),
31
- ];
32
- };