@openapi-qraft/tanstack-query-react-plugin 2.0.0-next.8 → 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 (132) hide show
  1. package/CHANGELOG.md +124 -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 +3 -0
  7. package/dist/lib/createOperationCommonTSDoc.d.ts.map +1 -0
  8. package/dist/lib/createOperationCommonTSDoc.js +8 -0
  9. package/dist/lib/createOperationCommonTSDoc.js.map +1 -0
  10. package/dist/plugin.d.ts.map +1 -1
  11. package/dist/plugin.js +4 -1
  12. package/dist/plugin.js.map +1 -1
  13. package/dist/ts-factory/filterUnusedTypes.d.ts +9 -0
  14. package/dist/ts-factory/filterUnusedTypes.d.ts.map +1 -0
  15. package/dist/ts-factory/filterUnusedTypes.js +34 -0
  16. package/dist/ts-factory/filterUnusedTypes.js.map +1 -0
  17. package/dist/ts-factory/getClientFactory.d.ts +1 -1
  18. package/dist/ts-factory/getClientFactory.d.ts.map +1 -1
  19. package/dist/ts-factory/getClientFactory.js +1 -1
  20. package/dist/ts-factory/getClientFactory.js.map +1 -1
  21. package/dist/ts-factory/getIndexFactory.d.ts +1 -1
  22. package/dist/ts-factory/getIndexFactory.d.ts.map +1 -1
  23. package/dist/ts-factory/getIndexFactory.js +2 -2
  24. package/dist/ts-factory/getIndexFactory.js.map +1 -1
  25. package/dist/ts-factory/getServiceFactory.d.ts +5 -3
  26. package/dist/ts-factory/getServiceFactory.d.ts.map +1 -1
  27. package/dist/ts-factory/getServiceFactory.js +124 -72
  28. package/dist/ts-factory/getServiceFactory.js.map +1 -1
  29. package/dist/ts-factory/getServiceIndexFactory.d.ts +3 -3
  30. package/dist/ts-factory/getServiceIndexFactory.d.ts.map +1 -1
  31. package/dist/ts-factory/getServiceIndexFactory.js +1 -1
  32. package/dist/ts-factory/getServiceIndexFactory.js.map +1 -1
  33. package/dist/ts-factory/service-operation.generated/ServiceOperationFetchInfiniteQuery.d.ts.map +1 -1
  34. package/dist/ts-factory/service-operation.generated/ServiceOperationFetchInfiniteQuery.js +26 -67
  35. package/dist/ts-factory/service-operation.generated/ServiceOperationFetchInfiniteQuery.js.map +1 -1
  36. package/dist/ts-factory/service-operation.generated/ServiceOperationFetchQuery.d.ts.map +1 -1
  37. package/dist/ts-factory/service-operation.generated/ServiceOperationFetchQuery.js +16 -1
  38. package/dist/ts-factory/service-operation.generated/ServiceOperationFetchQuery.js.map +1 -1
  39. package/dist/ts-factory/service-operation.generated/ServiceOperationGetInfiniteQueryData.d.ts.map +1 -1
  40. package/dist/ts-factory/service-operation.generated/ServiceOperationGetInfiniteQueryData.js +6 -10
  41. package/dist/ts-factory/service-operation.generated/ServiceOperationGetInfiniteQueryData.js.map +1 -1
  42. package/dist/ts-factory/service-operation.generated/ServiceOperationGetQueryData.d.ts.map +1 -1
  43. package/dist/ts-factory/service-operation.generated/ServiceOperationGetQueryData.js +6 -10
  44. package/dist/ts-factory/service-operation.generated/ServiceOperationGetQueryData.js.map +1 -1
  45. package/dist/ts-factory/service-operation.generated/ServiceOperationGetQueryState.d.ts.map +1 -1
  46. package/dist/ts-factory/service-operation.generated/ServiceOperationGetQueryState.js +6 -10
  47. package/dist/ts-factory/service-operation.generated/ServiceOperationGetQueryState.js.map +1 -1
  48. package/dist/ts-factory/service-operation.generated/ServiceOperationMutationFn.d.ts.map +1 -1
  49. package/dist/ts-factory/service-operation.generated/ServiceOperationMutationFn.js +7 -4
  50. package/dist/ts-factory/service-operation.generated/ServiceOperationMutationFn.js.map +1 -1
  51. package/dist/ts-factory/service-operation.generated/ServiceOperationQueryFn.d.ts.map +1 -1
  52. package/dist/ts-factory/service-operation.generated/ServiceOperationQueryFn.js +11 -17
  53. package/dist/ts-factory/service-operation.generated/ServiceOperationQueryFn.js.map +1 -1
  54. package/dist/ts-factory/service-operation.generated/ServiceOperationSetQueryData.d.ts.map +1 -1
  55. package/dist/ts-factory/service-operation.generated/ServiceOperationSetQueryData.js +9 -3
  56. package/dist/ts-factory/service-operation.generated/ServiceOperationSetQueryData.js.map +1 -1
  57. package/dist/ts-factory/service-operation.generated/ServiceOperationUseMutation.d.ts.map +1 -1
  58. package/dist/ts-factory/service-operation.generated/ServiceOperationUseMutation.js +12 -15
  59. package/dist/ts-factory/service-operation.generated/ServiceOperationUseMutation.js.map +1 -1
  60. package/dist/ts-factory/tsdoc/createOperationMethodTSDocExample.d.ts +6 -0
  61. package/dist/ts-factory/tsdoc/createOperationMethodTSDocExample.d.ts.map +1 -0
  62. package/dist/ts-factory/tsdoc/createOperationMethodTSDocExample.js +31 -0
  63. package/dist/ts-factory/tsdoc/createOperationMethodTSDocExample.js.map +1 -0
  64. package/dist/ts-factory/tsdoc/createUseInfiniteQueryOperationTSDocExample.d.ts +5 -0
  65. package/dist/ts-factory/tsdoc/createUseInfiniteQueryOperationTSDocExample.d.ts.map +1 -0
  66. package/dist/ts-factory/tsdoc/createUseInfiniteQueryOperationTSDocExample.js +53 -0
  67. package/dist/ts-factory/tsdoc/createUseInfiniteQueryOperationTSDocExample.js.map +1 -0
  68. package/dist/ts-factory/tsdoc/createUseIsFetchingOperationTSDocExample.d.ts +3 -0
  69. package/dist/ts-factory/tsdoc/createUseIsFetchingOperationTSDocExample.d.ts.map +1 -0
  70. package/dist/ts-factory/tsdoc/createUseIsFetchingOperationTSDocExample.js +41 -0
  71. package/dist/ts-factory/tsdoc/createUseIsFetchingOperationTSDocExample.js.map +1 -0
  72. package/dist/ts-factory/tsdoc/createUseIsMutatingOperationTSDocExample.d.ts +3 -0
  73. package/dist/ts-factory/tsdoc/createUseIsMutatingOperationTSDocExample.d.ts.map +1 -0
  74. package/dist/ts-factory/tsdoc/createUseIsMutatingOperationTSDocExample.js +41 -0
  75. package/dist/ts-factory/tsdoc/createUseIsMutatingOperationTSDocExample.js.map +1 -0
  76. package/dist/ts-factory/tsdoc/createUseMutationOperationTSDocExample.d.ts +3 -0
  77. package/dist/ts-factory/tsdoc/createUseMutationOperationTSDocExample.d.ts.map +1 -0
  78. package/dist/ts-factory/tsdoc/createUseMutationOperationTSDocExample.js +44 -0
  79. package/dist/ts-factory/tsdoc/createUseMutationOperationTSDocExample.js.map +1 -0
  80. package/dist/ts-factory/tsdoc/createUseMutationStateOperationTSDocExample.d.ts +3 -0
  81. package/dist/ts-factory/tsdoc/createUseMutationStateOperationTSDocExample.d.ts.map +1 -0
  82. package/dist/ts-factory/tsdoc/createUseMutationStateOperationTSDocExample.js +55 -0
  83. package/dist/ts-factory/tsdoc/createUseMutationStateOperationTSDocExample.js.map +1 -0
  84. package/dist/ts-factory/tsdoc/createUseQueriesOperationTSDocExample.d.ts +3 -0
  85. package/dist/ts-factory/tsdoc/createUseQueriesOperationTSDocExample.d.ts.map +1 -0
  86. package/dist/ts-factory/tsdoc/createUseQueriesOperationTSDocExample.js +88 -0
  87. package/dist/ts-factory/tsdoc/createUseQueriesOperationTSDocExample.js.map +1 -0
  88. package/dist/ts-factory/tsdoc/createUseQueryOperationTSDocExample.d.ts +3 -0
  89. package/dist/ts-factory/tsdoc/createUseQueryOperationTSDocExample.d.ts.map +1 -0
  90. package/dist/ts-factory/tsdoc/createUseQueryOperationTSDocExample.js +37 -0
  91. package/dist/ts-factory/tsdoc/createUseQueryOperationTSDocExample.js.map +1 -0
  92. package/dist/ts-factory/tsdoc/createUseSuspenseInfiniteQueryOperationTSDocExample.d.ts +3 -0
  93. package/dist/ts-factory/tsdoc/createUseSuspenseInfiniteQueryOperationTSDocExample.d.ts.map +1 -0
  94. package/dist/ts-factory/tsdoc/createUseSuspenseInfiniteQueryOperationTSDocExample.js +39 -0
  95. package/dist/ts-factory/tsdoc/createUseSuspenseInfiniteQueryOperationTSDocExample.js.map +1 -0
  96. package/dist/ts-factory/tsdoc/lib/createOperationMethodCallExpressionExampleNode.d.ts +7 -0
  97. package/dist/ts-factory/tsdoc/lib/createOperationMethodCallExpressionExampleNode.d.ts.map +1 -0
  98. package/dist/ts-factory/tsdoc/lib/createOperationMethodCallExpressionExampleNode.js +6 -0
  99. package/dist/ts-factory/tsdoc/lib/createOperationMethodCallExpressionExampleNode.js.map +1 -0
  100. package/dist/ts-factory/tsdoc/lib/createOperationMethodParametersExampleNodes.d.ts +4 -0
  101. package/dist/ts-factory/tsdoc/lib/createOperationMethodParametersExampleNodes.d.ts.map +1 -0
  102. package/dist/ts-factory/tsdoc/lib/createOperationMethodParametersExampleNodes.js +47 -0
  103. package/dist/ts-factory/tsdoc/lib/createOperationMethodParametersExampleNodes.js.map +1 -0
  104. package/package.json +6 -6
  105. package/src/generateCode.ts +8 -8
  106. package/src/lib/createOperationCommonTSDoc.ts +11 -0
  107. package/src/plugin.ts +8 -3
  108. package/src/ts-factory/filterUnusedTypes.ts +49 -0
  109. package/src/ts-factory/getClientFactory.ts +2 -2
  110. package/src/ts-factory/getIndexFactory.ts +13 -4
  111. package/src/ts-factory/getServiceFactory.ts +213 -139
  112. package/src/ts-factory/getServiceIndexFactory.ts +7 -7
  113. package/src/ts-factory/service-operation.generated/ServiceOperationFetchInfiniteQuery.ts +101 -190
  114. package/src/ts-factory/service-operation.generated/ServiceOperationFetchQuery.ts +80 -0
  115. package/src/ts-factory/service-operation.generated/ServiceOperationGetInfiniteQueryData.ts +28 -41
  116. package/src/ts-factory/service-operation.generated/ServiceOperationGetQueryData.ts +28 -41
  117. package/src/ts-factory/service-operation.generated/ServiceOperationGetQueryState.ts +28 -41
  118. package/src/ts-factory/service-operation.generated/ServiceOperationMutationFn.ts +23 -22
  119. package/src/ts-factory/service-operation.generated/ServiceOperationQueryFn.ts +49 -70
  120. package/src/ts-factory/service-operation.generated/ServiceOperationSetQueryData.ts +34 -10
  121. package/src/ts-factory/service-operation.generated/ServiceOperationUseMutation.ts +42 -59
  122. package/src/ts-factory/tsdoc/createOperationMethodTSDocExample.ts +65 -0
  123. package/src/ts-factory/tsdoc/createUseInfiniteQueryOperationTSDocExample.ts +135 -0
  124. package/src/ts-factory/tsdoc/createUseIsFetchingOperationTSDocExample.ts +81 -0
  125. package/src/ts-factory/tsdoc/createUseIsMutatingOperationTSDocExample.ts +74 -0
  126. package/src/ts-factory/tsdoc/createUseMutationOperationTSDocExample.ts +88 -0
  127. package/src/ts-factory/tsdoc/createUseMutationStateOperationTSDocExample.ts +154 -0
  128. package/src/ts-factory/tsdoc/createUseQueriesOperationTSDocExample.ts +292 -0
  129. package/src/ts-factory/tsdoc/createUseQueryOperationTSDocExample.ts +76 -0
  130. package/src/ts-factory/tsdoc/createUseSuspenseInfiniteQueryOperationTSDocExample.ts +63 -0
  131. package/src/ts-factory/tsdoc/lib/createOperationMethodCallExpressionExampleNode.ts +28 -0
  132. package/src/ts-factory/tsdoc/lib/createOperationMethodParametersExampleNodes.ts +83 -0
@@ -0,0 +1,81 @@
1
+ import { ServiceOperation } from '@openapi-qraft/plugin/lib/open-api/OpenAPIService';
2
+ import camelcase from 'camelcase';
3
+ import ts from 'typescript';
4
+ import { astToString } from '../astToString.js';
5
+ import { createOperationMethodCallExpressionExampleNode } from './lib/createOperationMethodCallExpressionExampleNode.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
+ createOperationMethodCallExpressionExampleNode(
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
+ createOperationMethodCallExpressionExampleNode(
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/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 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
+ createOperationMethodCallExpressionExampleNode(
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
+ createOperationMethodCallExpressionExampleNode(
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
+ };
@@ -0,0 +1,88 @@
1
+ import type { ServiceOperation } from '@openapi-qraft/plugin/lib/open-api/OpenAPIService';
2
+ import ts from 'typescript';
3
+ import { astToString } from '../astToString.js';
4
+ import { createOperationMethodCallExpressionExampleNode } from './lib/createOperationMethodCallExpressionExampleNode.js';
5
+ import { createOperationMethodParametersExampleNodes } from './lib/createOperationMethodParametersExampleNodes.js';
6
+
7
+ export const createUseMutationOperationTSDocExample = (
8
+ operation: ServiceOperation,
9
+ serviceVariableName: string
10
+ ) => {
11
+ const factory = ts.factory;
12
+
13
+ const example: string[] = [
14
+ 'Enables performing asynchronous data mutation operations such as POST, PUT, PATCH, or DELETE requests.',
15
+ 'Handles loading state, optimistic updates, and error handling.',
16
+ '',
17
+ '@see {@link https://openapi-qraft.github.io/openapi-qraft/docs/hooks/useMutation|`useMutation(...)` documentation}',
18
+ '@example Mutation with predefined parameters, e.g., for updating',
19
+ '```ts',
20
+ ...(
21
+ 'const { mutate, isPending } = ' +
22
+ astToString(
23
+ createOperationMethodCallExpressionExampleNode(
24
+ operation,
25
+ {
26
+ serviceVariableName,
27
+ operationMethodName: 'useMutation',
28
+ },
29
+ [
30
+ factory.createObjectLiteralExpression(
31
+ createOperationMethodParametersExampleNodes(operation),
32
+ true
33
+ ),
34
+ ]
35
+ )
36
+ )
37
+ )
38
+ .trim()
39
+ .split('\n'),
40
+ 'mutate(body);',
41
+ '```',
42
+ ];
43
+
44
+ example.push(
45
+ '@example Mutation without predefined parameters, e.g., for creating',
46
+ '```ts',
47
+ ...(
48
+ 'const { mutate, isPending } = ' +
49
+ astToString(
50
+ createOperationMethodCallExpressionExampleNode(
51
+ operation,
52
+ {
53
+ serviceVariableName,
54
+ operationMethodName: 'useMutation',
55
+ },
56
+ undefined
57
+ )
58
+ )
59
+ )
60
+ .trim()
61
+ .split('\n'),
62
+ ...astToString([
63
+ factory.createExpressionStatement(
64
+ factory.createCallExpression(
65
+ factory.createIdentifier('mutate'),
66
+ undefined,
67
+ [
68
+ factory.createObjectLiteralExpression(
69
+ [
70
+ factory.createPropertyAssignment(
71
+ factory.createIdentifier('body'),
72
+ factory.createIdentifier('bodyPayload')
73
+ ),
74
+ ...createOperationMethodParametersExampleNodes(operation),
75
+ ],
76
+ true
77
+ ),
78
+ ]
79
+ )
80
+ ),
81
+ ])
82
+ .trim()
83
+ .split('\n'),
84
+ '```'
85
+ );
86
+
87
+ return example;
88
+ };
@@ -0,0 +1,154 @@
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 createUseMutationStateOperationTSDocExample = (
10
+ operation: ServiceOperation,
11
+ serviceVariableName: string
12
+ ) => {
13
+ const factory = ts.factory;
14
+
15
+ const example: string[] = [
16
+ 'Provides access to the current state of a mutation, including its status, any resulting data, and associated errors.',
17
+ '',
18
+ ...createOperationCommonTSDoc(operation),
19
+ '@see {@link https://openapi-qraft.github.io/openapi-qraft/docs/hooks/useMutationState|`useMutationState(...)` documentation}',
20
+
21
+ '@example Get all variables of all running mutations.',
22
+ '```ts',
23
+ ...(
24
+ `const ${camelcase(operation.name + '-pending-mutation-variables')} = ` +
25
+ astToString(
26
+ createOperationMethodCallExpressionExampleNode(
27
+ operation,
28
+ {
29
+ serviceVariableName,
30
+ operationMethodName: 'useMutationState',
31
+ },
32
+ [
33
+ factory.createObjectLiteralExpression(
34
+ [
35
+ factory.createPropertyAssignment(
36
+ factory.createIdentifier('filters'),
37
+ factory.createObjectLiteralExpression(
38
+ [
39
+ factory.createPropertyAssignment(
40
+ factory.createIdentifier('status'),
41
+ factory.createStringLiteral('pending')
42
+ ),
43
+ ],
44
+ true
45
+ )
46
+ ),
47
+ factory.createPropertyAssignment(
48
+ factory.createIdentifier('select'),
49
+ factory.createArrowFunction(
50
+ undefined,
51
+ undefined,
52
+ [
53
+ factory.createParameterDeclaration(
54
+ undefined,
55
+ undefined,
56
+ factory.createIdentifier('mutation'),
57
+ undefined,
58
+ undefined,
59
+ undefined
60
+ ),
61
+ ],
62
+ undefined,
63
+ factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken),
64
+ factory.createPropertyAccessExpression(
65
+ factory.createPropertyAccessExpression(
66
+ factory.createIdentifier('mutation'),
67
+ factory.createIdentifier('state')
68
+ ),
69
+ factory.createIdentifier('variables')
70
+ )
71
+ )
72
+ ),
73
+ ],
74
+ true
75
+ ),
76
+ ]
77
+ )
78
+ )
79
+ )
80
+ .trim()
81
+ .split('\n'),
82
+ '```',
83
+
84
+ '@example Get all data for specific mutations via the `parameters`.',
85
+ '```ts',
86
+ ...(
87
+ `const ${camelcase(operation.name + '-mutation-data')} = ` +
88
+ astToString(
89
+ createOperationMethodCallExpressionExampleNode(
90
+ operation,
91
+ {
92
+ serviceVariableName,
93
+ operationMethodName: 'useMutationState',
94
+ },
95
+ [
96
+ factory.createObjectLiteralExpression(
97
+ [
98
+ factory.createPropertyAssignment(
99
+ factory.createIdentifier('filters'),
100
+ factory.createObjectLiteralExpression(
101
+ [
102
+ factory.createPropertyAssignment(
103
+ factory.createIdentifier('parameters'),
104
+ factory.createObjectLiteralExpression(
105
+ createOperationMethodParametersExampleNodes(
106
+ operation
107
+ ),
108
+ true
109
+ )
110
+ ),
111
+ ],
112
+ true
113
+ )
114
+ ),
115
+ factory.createPropertyAssignment(
116
+ factory.createIdentifier('select'),
117
+ factory.createArrowFunction(
118
+ undefined,
119
+ undefined,
120
+ [
121
+ factory.createParameterDeclaration(
122
+ undefined,
123
+ undefined,
124
+ factory.createIdentifier('mutation'),
125
+ undefined,
126
+ undefined,
127
+ undefined
128
+ ),
129
+ ],
130
+ undefined,
131
+ factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken),
132
+ factory.createPropertyAccessExpression(
133
+ factory.createPropertyAccessExpression(
134
+ factory.createIdentifier('mutation'),
135
+ factory.createIdentifier('state')
136
+ ),
137
+ factory.createIdentifier('data')
138
+ )
139
+ )
140
+ ),
141
+ ],
142
+ true
143
+ ),
144
+ ]
145
+ )
146
+ )
147
+ )
148
+ .trim()
149
+ .split('\n'),
150
+ '```',
151
+ ];
152
+
153
+ return example;
154
+ };
@@ -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
+ };