@openapi-qraft/tanstack-query-react-plugin 2.0.0-next.9 → 2.0.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +124 -0
- package/dist/generateCode.d.ts +3 -3
- package/dist/generateCode.d.ts.map +1 -1
- package/dist/generateCode.js +3 -3
- package/dist/generateCode.js.map +1 -1
- package/dist/lib/createOperationCommonTSDoc.d.ts +1 -1
- package/dist/lib/createOperationCommonTSDoc.d.ts.map +1 -1
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +4 -1
- package/dist/plugin.js.map +1 -1
- package/dist/ts-factory/filterUnusedTypes.d.ts +9 -0
- package/dist/ts-factory/filterUnusedTypes.d.ts.map +1 -0
- package/dist/ts-factory/filterUnusedTypes.js +34 -0
- package/dist/ts-factory/filterUnusedTypes.js.map +1 -0
- package/dist/ts-factory/getClientFactory.d.ts +1 -1
- package/dist/ts-factory/getClientFactory.d.ts.map +1 -1
- package/dist/ts-factory/getClientFactory.js +1 -1
- package/dist/ts-factory/getClientFactory.js.map +1 -1
- package/dist/ts-factory/getIndexFactory.d.ts +1 -1
- package/dist/ts-factory/getIndexFactory.d.ts.map +1 -1
- package/dist/ts-factory/getIndexFactory.js +2 -2
- package/dist/ts-factory/getIndexFactory.js.map +1 -1
- package/dist/ts-factory/getServiceFactory.d.ts +1 -1
- package/dist/ts-factory/getServiceFactory.d.ts.map +1 -1
- package/dist/ts-factory/getServiceFactory.js +54 -42
- package/dist/ts-factory/getServiceFactory.js.map +1 -1
- package/dist/ts-factory/getServiceIndexFactory.d.ts +3 -3
- package/dist/ts-factory/getServiceIndexFactory.d.ts.map +1 -1
- package/dist/ts-factory/getServiceIndexFactory.js +1 -1
- package/dist/ts-factory/getServiceIndexFactory.js.map +1 -1
- package/dist/ts-factory/service-operation.generated/ServiceOperationFetchInfiniteQuery.d.ts.map +1 -1
- package/dist/ts-factory/service-operation.generated/ServiceOperationFetchInfiniteQuery.js +26 -67
- package/dist/ts-factory/service-operation.generated/ServiceOperationFetchInfiniteQuery.js.map +1 -1
- package/dist/ts-factory/service-operation.generated/ServiceOperationFetchQuery.d.ts.map +1 -1
- package/dist/ts-factory/service-operation.generated/ServiceOperationFetchQuery.js +16 -1
- package/dist/ts-factory/service-operation.generated/ServiceOperationFetchQuery.js.map +1 -1
- package/dist/ts-factory/service-operation.generated/ServiceOperationMutationFn.d.ts.map +1 -1
- package/dist/ts-factory/service-operation.generated/ServiceOperationMutationFn.js +7 -4
- package/dist/ts-factory/service-operation.generated/ServiceOperationMutationFn.js.map +1 -1
- package/dist/ts-factory/service-operation.generated/ServiceOperationSetQueryData.d.ts.map +1 -1
- package/dist/ts-factory/service-operation.generated/ServiceOperationSetQueryData.js +9 -3
- package/dist/ts-factory/service-operation.generated/ServiceOperationSetQueryData.js.map +1 -1
- package/dist/ts-factory/tsdoc/createOperationMethodTSDocExample.d.ts +1 -1
- package/dist/ts-factory/tsdoc/createOperationMethodTSDocExample.d.ts.map +1 -1
- package/dist/ts-factory/tsdoc/createOperationMethodTSDocExample.js +9 -0
- package/dist/ts-factory/tsdoc/createOperationMethodTSDocExample.js.map +1 -1
- package/dist/ts-factory/tsdoc/createUseInfiniteQueryOperationTSDocExample.d.ts +3 -1
- package/dist/ts-factory/tsdoc/createUseInfiniteQueryOperationTSDocExample.d.ts.map +1 -1
- package/dist/ts-factory/tsdoc/createUseInfiniteQueryOperationTSDocExample.js +19 -27
- package/dist/ts-factory/tsdoc/createUseInfiniteQueryOperationTSDocExample.js.map +1 -1
- package/dist/ts-factory/tsdoc/createUseIsFetchingOperationTSDocExample.d.ts +1 -1
- package/dist/ts-factory/tsdoc/createUseIsFetchingOperationTSDocExample.d.ts.map +1 -1
- package/dist/ts-factory/tsdoc/createUseIsFetchingOperationTSDocExample.js +3 -3
- package/dist/ts-factory/tsdoc/createUseIsFetchingOperationTSDocExample.js.map +1 -1
- package/dist/ts-factory/tsdoc/createUseIsMutatingOperationTSDocExample.d.ts +1 -1
- package/dist/ts-factory/tsdoc/createUseIsMutatingOperationTSDocExample.d.ts.map +1 -1
- package/dist/ts-factory/tsdoc/createUseIsMutatingOperationTSDocExample.js +3 -3
- package/dist/ts-factory/tsdoc/createUseIsMutatingOperationTSDocExample.js.map +1 -1
- package/dist/ts-factory/tsdoc/createUseMutationOperationTSDocExample.d.ts +1 -1
- package/dist/ts-factory/tsdoc/createUseMutationOperationTSDocExample.d.ts.map +1 -1
- package/dist/ts-factory/tsdoc/createUseMutationOperationTSDocExample.js +3 -3
- package/dist/ts-factory/tsdoc/createUseMutationOperationTSDocExample.js.map +1 -1
- package/dist/ts-factory/tsdoc/createUseMutationStateOperationTSDocExample.d.ts +3 -0
- package/dist/ts-factory/tsdoc/createUseMutationStateOperationTSDocExample.d.ts.map +1 -0
- package/dist/ts-factory/tsdoc/createUseMutationStateOperationTSDocExample.js +55 -0
- package/dist/ts-factory/tsdoc/createUseMutationStateOperationTSDocExample.js.map +1 -0
- package/dist/ts-factory/tsdoc/createUseQueriesOperationTSDocExample.d.ts +3 -0
- package/dist/ts-factory/tsdoc/createUseQueriesOperationTSDocExample.d.ts.map +1 -0
- package/dist/ts-factory/tsdoc/createUseQueriesOperationTSDocExample.js +88 -0
- package/dist/ts-factory/tsdoc/createUseQueriesOperationTSDocExample.js.map +1 -0
- package/dist/ts-factory/tsdoc/createUseQueryOperationTSDocExample.d.ts +1 -1
- package/dist/ts-factory/tsdoc/createUseQueryOperationTSDocExample.d.ts.map +1 -1
- package/dist/ts-factory/tsdoc/createUseQueryOperationTSDocExample.js +3 -3
- package/dist/ts-factory/tsdoc/createUseQueryOperationTSDocExample.js.map +1 -1
- package/dist/ts-factory/tsdoc/createUseSuspenseInfiniteQueryOperationTSDocExample.d.ts +3 -0
- package/dist/ts-factory/tsdoc/createUseSuspenseInfiniteQueryOperationTSDocExample.d.ts.map +1 -0
- package/dist/ts-factory/tsdoc/createUseSuspenseInfiniteQueryOperationTSDocExample.js +39 -0
- package/dist/ts-factory/tsdoc/createUseSuspenseInfiniteQueryOperationTSDocExample.js.map +1 -0
- package/dist/ts-factory/tsdoc/lib/createOperationMethodCallExpressionExampleNode.d.ts +7 -0
- package/dist/ts-factory/tsdoc/lib/createOperationMethodCallExpressionExampleNode.d.ts.map +1 -0
- package/dist/ts-factory/tsdoc/lib/createOperationMethodCallExpressionExampleNode.js +6 -0
- package/dist/ts-factory/tsdoc/lib/createOperationMethodCallExpressionExampleNode.js.map +1 -0
- package/dist/ts-factory/tsdoc/lib/createOperationMethodParametersExampleNodes.d.ts +1 -1
- package/dist/ts-factory/tsdoc/lib/createOperationMethodParametersExampleNodes.d.ts.map +1 -1
- package/dist/ts-factory/tsdoc/lib/createOperationMethodParametersExampleNodes.js +17 -1
- package/dist/ts-factory/tsdoc/lib/createOperationMethodParametersExampleNodes.js.map +1 -1
- package/package.json +12 -4
- package/src/generateCode.ts +8 -8
- package/src/lib/createOperationCommonTSDoc.ts +1 -1
- package/src/plugin.ts +8 -3
- package/src/ts-factory/filterUnusedTypes.ts +49 -0
- package/src/ts-factory/getClientFactory.ts +2 -2
- package/src/ts-factory/getIndexFactory.ts +13 -4
- package/src/ts-factory/getServiceFactory.ts +98 -69
- package/src/ts-factory/getServiceIndexFactory.ts +7 -7
- package/src/ts-factory/service-operation.generated/ServiceOperationFetchInfiniteQuery.ts +101 -190
- package/src/ts-factory/service-operation.generated/ServiceOperationFetchQuery.ts +80 -0
- package/src/ts-factory/service-operation.generated/ServiceOperationMutationFn.ts +23 -22
- package/src/ts-factory/service-operation.generated/ServiceOperationSetQueryData.ts +34 -10
- package/src/ts-factory/tsdoc/createOperationMethodTSDocExample.ts +19 -1
- package/src/ts-factory/tsdoc/createUseInfiniteQueryOperationTSDocExample.ts +84 -95
- package/src/ts-factory/tsdoc/createUseIsFetchingOperationTSDocExample.ts +4 -4
- package/src/ts-factory/tsdoc/createUseIsMutatingOperationTSDocExample.ts +4 -4
- package/src/ts-factory/tsdoc/createUseMutationOperationTSDocExample.ts +4 -4
- package/src/ts-factory/tsdoc/createUseMutationStateOperationTSDocExample.ts +154 -0
- package/src/ts-factory/tsdoc/createUseQueriesOperationTSDocExample.ts +292 -0
- package/src/ts-factory/tsdoc/createUseQueryOperationTSDocExample.ts +4 -4
- package/src/ts-factory/tsdoc/createUseSuspenseInfiniteQueryOperationTSDocExample.ts +63 -0
- package/src/ts-factory/tsdoc/lib/createOperationMethodCallExpressionExampleNode.ts +28 -0
- package/src/ts-factory/tsdoc/lib/createOperationMethodParametersExampleNodes.ts +19 -2
- package/dist/ts-factory/tsdoc/lib/createOperationMethodExampleNodes.d.ts +0 -7
- package/dist/ts-factory/tsdoc/lib/createOperationMethodExampleNodes.d.ts.map +0 -1
- package/dist/ts-factory/tsdoc/lib/createOperationMethodExampleNodes.js +0 -8
- package/dist/ts-factory/tsdoc/lib/createOperationMethodExampleNodes.js.map +0 -1
- package/src/ts-factory/tsdoc/lib/createOperationMethodExampleNodes.ts +0 -32
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,129 @@
|
|
|
1
1
|
# @openapi-qraft/tanstack-query-react-plugin
|
|
2
2
|
|
|
3
|
+
## 2.0.1-beta.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- def57df: Ensure external libraries are declared in `peerDependencies` to prevent conflicts and duplication.
|
|
8
|
+
- Updated dependencies [def57df]
|
|
9
|
+
- @openapi-qraft/plugin@2.0.1-beta.0
|
|
10
|
+
|
|
11
|
+
## 2.0.0
|
|
12
|
+
|
|
13
|
+
### Major Changes
|
|
14
|
+
|
|
15
|
+
- 5b64278: Refactored service method generation in **OpenAPI Qraft v2** with improved DX, including full TSDoc support and optimized autocomplete performance.
|
|
16
|
+
- 266611a: Enhance `createAPIClient` to accept `requestFn`, `baseUrl`, and optionally `queryClient`.
|
|
17
|
+
- 54fd011: Changed the exports from the schema file to include only the essential types: `$defs`, `paths`, `components`, `operations`, `webhooks`. This adjustment improves the development experience by preventing the export of all schema types, which could result in an excessive number of exported types, complicating development and reducing clarity.
|
|
18
|
+
|
|
19
|
+
### Minor Changes
|
|
20
|
+
|
|
21
|
+
- 56687f3: Added support for calling `qraftAPIClient(...)` with `{ queryClient }`, enabling non-fetching actions like `resetQueries()`.
|
|
22
|
+
- 8bbe14b: Added two new utility functions: `ensureQueryData` and `ensureInfiniteQueryData`. These methods improve data fetching workflows by allowing seamless retrieval of cached data or fetching it when unavailable. `ensureQueryData` supports standard queries, while `ensureInfiniteQueryData` is tailored for infinite queries, including paginated data handling.
|
|
23
|
+
- 2a53608: Updated TypeScript to version 5.5.4
|
|
24
|
+
- cd3fe16: Added a filtering mechanism to remove unused type imports from generated service files. This improves code readability by including only the necessary types and reduces clutter in the output.
|
|
25
|
+
- 0b3cda1: Updated the `qraftAPIClient(...)` to return only the set of services corresponding to the methods for which callbacks were passed.
|
|
26
|
+
- 76634bf: ### Changeset: `createPredefinedParametersRequestFn`
|
|
27
|
+
|
|
28
|
+
Introduced `createPredefinedParametersRequestFn`, generated by the `@openapi-qraft/cli` using
|
|
29
|
+
the `--operation-predefined-parameters` option.
|
|
30
|
+
This function allows for the automatic application of predefined
|
|
31
|
+
parameters to selected API operations by wrapping the base `requestFn`. It simplifies managing parameters, reducing
|
|
32
|
+
boilerplate code, and supports both static and dynamic values, enhancing flexibility in API request handling.
|
|
33
|
+
|
|
34
|
+
### Patch Changes
|
|
35
|
+
|
|
36
|
+
- 4ef9ce0: Clarified `FetchInfiniteQueryOptions` type to align with the latest TanStack Query version (5.56.2).
|
|
37
|
+
- 7ab718b: Enhanced the `--explicit-import-extensions` option to support `.ts` in addition to `.js`, making it easier for projects using TypeScript to explicitly specify import extensions.
|
|
38
|
+
- 78638a5: Extended TSDoc generation for existing `useQuery`, `useMutation`, `useInfiniteQuery`, `useIsFetching` and `useIsMutating` hooks, now including detailed usage examples.
|
|
39
|
+
- 7e51026: Added the ability to call `getQueryKey`, `getMutationKey`, and similar non-request operations without providing `requestFn` or `baseUrl`
|
|
40
|
+
- 3ed94dc: Implemented support for requests with multiple media types. Now, if an endpoint accepts more than one media type (e.g., JSON and form-data), types will be generated to account for all possible cases, ensuring compatibility with both JSON and form-data input formats.
|
|
41
|
+
- 62ff8e0: Refactor `Service` and `ServiceOperation` types.
|
|
42
|
+
- fc6b4e7: Use `import type` for types in generated `qraftPredefinedParametersRequestFn`.
|
|
43
|
+
- Updated dependencies [16b380f]
|
|
44
|
+
- Updated dependencies [8c77eb2]
|
|
45
|
+
- Updated dependencies [2a53608]
|
|
46
|
+
- Updated dependencies [76634bf]
|
|
47
|
+
- Updated dependencies [c111be6]
|
|
48
|
+
- Updated dependencies [62ff8e0]
|
|
49
|
+
- @openapi-qraft/plugin@2.0.0
|
|
50
|
+
|
|
51
|
+
## 2.0.0-next.19
|
|
52
|
+
|
|
53
|
+
### Patch Changes
|
|
54
|
+
|
|
55
|
+
- 62ff8e0: Refactor `Service` and `ServiceOperation` types.
|
|
56
|
+
- Updated dependencies [62ff8e0]
|
|
57
|
+
- @openapi-qraft/plugin@2.0.0-next.19
|
|
58
|
+
|
|
59
|
+
## 2.0.0-next.18
|
|
60
|
+
|
|
61
|
+
### Patch Changes
|
|
62
|
+
|
|
63
|
+
- @openapi-qraft/plugin@2.0.0-next.18
|
|
64
|
+
|
|
65
|
+
## 2.0.0-next.17
|
|
66
|
+
|
|
67
|
+
### Minor Changes
|
|
68
|
+
|
|
69
|
+
- 8bbe14b: Added two new utility functions: `ensureQueryData` and `ensureInfiniteQueryData`. These methods improve data fetching workflows by allowing seamless retrieval of cached data or fetching it when unavailable. `ensureQueryData` supports standard queries, while `ensureInfiniteQueryData` is tailored for infinite queries, including paginated data handling.
|
|
70
|
+
- cd3fe16: Added a filtering mechanism to remove unused type imports from generated service files. This improves code readability by including only the necessary types and reduces clutter in the output.
|
|
71
|
+
|
|
72
|
+
### Patch Changes
|
|
73
|
+
|
|
74
|
+
- Updated dependencies [16b380f]
|
|
75
|
+
- @openapi-qraft/plugin@2.0.0-next.17
|
|
76
|
+
|
|
77
|
+
## 2.0.0-next.16
|
|
78
|
+
|
|
79
|
+
### Patch Changes
|
|
80
|
+
|
|
81
|
+
- @openapi-qraft/plugin@2.0.0-next.16
|
|
82
|
+
|
|
83
|
+
## 2.0.0-next.15
|
|
84
|
+
|
|
85
|
+
### Patch Changes
|
|
86
|
+
|
|
87
|
+
- @openapi-qraft/plugin@2.0.0-next.15
|
|
88
|
+
|
|
89
|
+
## 2.0.0-next.14
|
|
90
|
+
|
|
91
|
+
### Major Changes
|
|
92
|
+
|
|
93
|
+
- 54fd011: Changed the exports from the schema file to include only the essential types: `$defs`, `paths`, `components`, `operations`, `webhooks`. This adjustment improves the development experience by preventing the export of all schema types, which could result in an excessive number of exported types, complicating development and reducing clarity.
|
|
94
|
+
|
|
95
|
+
### Patch Changes
|
|
96
|
+
|
|
97
|
+
- 7ab718b: Enhanced the `--explicit-import-extensions` option to support `.ts` in addition to `.js`, making it easier for projects using TypeScript to explicitly specify import extensions.
|
|
98
|
+
- @openapi-qraft/plugin@2.0.0-next.14
|
|
99
|
+
|
|
100
|
+
## 2.0.0-next.13
|
|
101
|
+
|
|
102
|
+
### Patch Changes
|
|
103
|
+
|
|
104
|
+
- Updated dependencies [c111be6]
|
|
105
|
+
- @openapi-qraft/plugin@2.0.0-next.13
|
|
106
|
+
|
|
107
|
+
## 2.0.0-next.12
|
|
108
|
+
|
|
109
|
+
### Patch Changes
|
|
110
|
+
|
|
111
|
+
- @openapi-qraft/plugin@2.0.0-next.12
|
|
112
|
+
|
|
113
|
+
## 2.0.0-next.11
|
|
114
|
+
|
|
115
|
+
### Patch Changes
|
|
116
|
+
|
|
117
|
+
- 3ed94dc: Implemented support for requests with multiple media types. Now, if an endpoint accepts more than one media type (e.g., JSON and form-data), types will be generated to account for all possible cases, ensuring compatibility with both JSON and form-data input formats.
|
|
118
|
+
- @openapi-qraft/plugin@2.0.0-next.11
|
|
119
|
+
|
|
120
|
+
## 2.0.0-next.10
|
|
121
|
+
|
|
122
|
+
### Patch Changes
|
|
123
|
+
|
|
124
|
+
- Updated dependencies [8c77eb2]
|
|
125
|
+
- @openapi-qraft/plugin@2.0.0-next.10
|
|
126
|
+
|
|
3
127
|
## 2.0.0-next.9
|
|
4
128
|
|
|
5
129
|
### Patch Changes
|
package/dist/generateCode.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GeneratorFile } from '@openapi-qraft/plugin/lib/GeneratorFile';
|
|
2
|
-
import {
|
|
2
|
+
import { OpenAPIService } from '@openapi-qraft/plugin/lib/open-api/OpenAPIService';
|
|
3
3
|
import { OutputOptions as OutputOptionsBase } from '@openapi-qraft/plugin/lib/OutputOptions';
|
|
4
4
|
import { PredefinedParametersGlob } from '@openapi-qraft/plugin/lib/predefineSchemaParameters';
|
|
5
5
|
import { Ora } from 'ora';
|
|
@@ -7,13 +7,13 @@ import { ServiceImportsFactoryOptions } from './ts-factory/getServiceFactory.js'
|
|
|
7
7
|
interface OutputOptions extends OutputOptionsBase {
|
|
8
8
|
fileHeader: string | undefined;
|
|
9
9
|
servicesDirName: string;
|
|
10
|
-
explicitImportExtensions:
|
|
10
|
+
explicitImportExtensions: '.js' | '.ts' | undefined;
|
|
11
11
|
exportSchemaTypes: boolean | undefined;
|
|
12
12
|
operationPredefinedParameters: Array<PredefinedParametersGlob> | undefined;
|
|
13
13
|
}
|
|
14
14
|
export declare const generateCode: ({ spinner, services, serviceImports, output, }: {
|
|
15
15
|
spinner: Ora;
|
|
16
|
-
services:
|
|
16
|
+
services: OpenAPIService[];
|
|
17
17
|
serviceImports: ServiceImportsFactoryOptions;
|
|
18
18
|
output: OutputOptions;
|
|
19
19
|
}) => Promise<GeneratorFile[]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateCode.d.ts","sourceRoot":"","sources":["../src/generateCode.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AACxE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"generateCode.d.ts","sourceRoot":"","sources":["../src/generateCode.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,mDAAmD,CAAC;AACnF,OAAO,EAAE,aAAa,IAAI,iBAAiB,EAAE,MAAM,yCAAyC,CAAC;AAC7F,OAAO,EAAE,wBAAwB,EAAE,MAAM,qDAAqD,CAAC;AAE/F,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAK1B,OAAO,EAEL,4BAA4B,EAC7B,MAAM,mCAAmC,CAAC;AAG3C,UAAU,aAAc,SAAQ,iBAAiB;IAC/C,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,eAAe,EAAE,MAAM,CAAC;IACxB,wBAAwB,EAAE,KAAK,GAAG,KAAK,GAAG,SAAS,CAAC;IACpD,iBAAiB,EAAE,OAAO,GAAG,SAAS,CAAC;IACvC,6BAA6B,EAAE,KAAK,CAAC,wBAAwB,CAAC,GAAG,SAAS,CAAC;CAC5E;AAED,eAAO,MAAM,YAAY,mDAKtB;IACD,OAAO,EAAE,GAAG,CAAC;IACb,QAAQ,EAAE,cAAc,EAAE,CAAC;IAC3B,cAAc,EAAE,4BAA4B,CAAC;IAC7C,MAAM,EAAE,aAAa,CAAC;CACvB,6BAcA,CAAC"}
|
package/dist/generateCode.js
CHANGED
|
@@ -61,7 +61,7 @@ const generateServiceIndex = async (spinner, services, output) => {
|
|
|
61
61
|
];
|
|
62
62
|
try {
|
|
63
63
|
const code = astToString(getServiceIndexFactory(services, {
|
|
64
|
-
explicitImportExtensions:
|
|
64
|
+
explicitImportExtensions: output.explicitImportExtensions,
|
|
65
65
|
}));
|
|
66
66
|
serviceIndexFiles.push({
|
|
67
67
|
file: new URL('index.ts', composeServicesDirPath(output)),
|
|
@@ -81,7 +81,7 @@ const generateClient = async (spinner, output) => {
|
|
|
81
81
|
try {
|
|
82
82
|
const code = astToString(getClientFactory({
|
|
83
83
|
servicesDirName: output.servicesDirName,
|
|
84
|
-
explicitImportExtensions:
|
|
84
|
+
explicitImportExtensions: output.explicitImportExtensions,
|
|
85
85
|
}));
|
|
86
86
|
clientFiles.push({
|
|
87
87
|
file: new URL('create-api-client.ts', output.dir),
|
|
@@ -122,7 +122,7 @@ const generateIndex = async (spinner, serviceImports, output) => {
|
|
|
122
122
|
try {
|
|
123
123
|
const code = astToString(getIndexFactory({
|
|
124
124
|
servicesDirName: output.servicesDirName,
|
|
125
|
-
explicitImportExtensions:
|
|
125
|
+
explicitImportExtensions: output.explicitImportExtensions,
|
|
126
126
|
openapiTypesImportPath: output.exportSchemaTypes
|
|
127
127
|
? serviceImports.openapiTypesImportPath
|
|
128
128
|
: undefined,
|
package/dist/generateCode.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateCode.js","sourceRoot":"","sources":["../src/generateCode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,4CAA4C,CAAC;AAK9E,OAAO,CAAC,MAAM,aAAa,CAAC;AAE5B,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,6CAA6C,EAAE,MAAM,+DAA+D,CAAC;AAC9H,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EACL,iBAAiB,GAElB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AAUhF,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAAE,EACjC,OAAO,EACP,QAAQ,EACR,cAAc,EACd,MAAM,GAMP,EAAE,EAAE;IACH,OAAO;QACL,GAAG,CAAC,MAAM,gBAAgB,CAAC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AEF,UAAU,CAAC,IAAI,CAAC;YACd,IAAI,EAAE,IAAI,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,GAAG,CAAC;YACrC,IAAI,EAAE,gBAAgB,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,IAAI;SACjD,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,wCAAwC,CAAC,CAAC,CAAC;QAEpE,MAAM,KAAK,CAAC;IACd,CAAC;IAED,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC,CAAC;IAErD,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { ServiceOperation } from '@openapi-qraft/plugin/lib/open-api/
|
|
1
|
+
import { ServiceOperation } from '@openapi-qraft/plugin/lib/open-api/OpenAPIService';
|
|
2
2
|
export declare const createOperationCommonTSDoc: (operation: ServiceOperation) => string[];
|
|
3
3
|
//# sourceMappingURL=createOperationCommonTSDoc.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createOperationCommonTSDoc.d.ts","sourceRoot":"","sources":["../../src/lib/createOperationCommonTSDoc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"createOperationCommonTSDoc.d.ts","sourceRoot":"","sources":["../../src/lib/createOperationCommonTSDoc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mDAAmD,CAAC;AAErF,eAAO,MAAM,0BAA0B,cAAe,gBAAgB,aAQrE,CAAC"}
|
package/dist/plugin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,kBAAkB,EAAE,MAAM,8CAA8C,CAAC;
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,kBAAkB,EAAE,MAAM,8CAA8C,CAAC;AAIlF,eAAO,MAAM,MAAM,EAAE,kBAgDpB,CAAC"}
|
package/dist/plugin.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { fileHeader } from '@openapi-qraft/plugin/lib/fileHeader';
|
|
2
2
|
import { createPredefinedParametersGlobs, parseOperationPredefinedParametersOption, } from '@openapi-qraft/plugin/lib/predefineSchemaParameters';
|
|
3
|
+
import { Option } from 'commander';
|
|
3
4
|
import { generateCode } from './generateCode.js';
|
|
4
5
|
export const plugin = {
|
|
5
6
|
setupCommand(command) {
|
|
6
7
|
command
|
|
7
8
|
.description('Generate TanStack Query React client from OpenAPI Schema')
|
|
8
9
|
.requiredOption('--openapi-types-import-path <path>', 'Path to schema types file (.d.ts), eg: "../schema.d.ts"')
|
|
9
|
-
.
|
|
10
|
+
.addOption(new Option('--explicit-import-extensions [extension]', 'All import statements will contain an explicit file extension. Ideal for projects using ECMAScript modules.')
|
|
11
|
+
.preset('.js')
|
|
12
|
+
.choices(['.js', '.ts']))
|
|
10
13
|
.option('--export-openapi-types [bool]', 'Export the OpenAPI schema types from the generated `./index.ts` file', (arg) => {
|
|
11
14
|
return arg?.toLowerCase() !== 'false';
|
|
12
15
|
})
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAC;AAClE,OAAO,EACL,+BAA+B,EAC/B,wCAAwC,GACzC,MAAM,qDAAqD,CAAC;AAG7D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,MAAM,CAAC,MAAM,MAAM,GAAu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IAAI,CAAC,wBAAwB;oBACvD,eAAe,EAAE,UAAU;oBAC3B,iBAAiB,EAAE,IAAI,CAAC,kBAAkB;oBAC1C,6BAA6B,EAAE,IAAI,CAAC,6BAA6B;wBAC/D,CAAC,CAAC,+BAA+B,CAC7B,MAAM,EACN,wCAAwC,CACtC,GAAG,IAAI,CAAC,6BAA6B,CACtC,CACF;wBACH,CAAC,CAAC,SAAS,EAAE,4DAA4D;iBAC5E;aACF,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;QACpB,CAAC,CAAC,CAAC;IACP,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
/**
|
|
3
|
+
* Checks if a type is used in the given nodes.
|
|
4
|
+
* @param typeImports Record<moduleName, typeName[]>
|
|
5
|
+
* @param nodes
|
|
6
|
+
* @returns Record<moduleName, typeName[]>
|
|
7
|
+
*/
|
|
8
|
+
export declare function filterUnusedTypes(typeImports: Record<string, string[]>, nodes: ts.Node[]): Record<string, string[]>;
|
|
9
|
+
//# sourceMappingURL=filterUnusedTypes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filterUnusedTypes.d.ts","sourceRoot":"","sources":["../../src/ts-factory/filterUnusedTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,EACrC,KAAK,EAAE,EAAE,CAAC,IAAI,EAAE,GACf,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAqC1B"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
/**
|
|
3
|
+
* Checks if a type is used in the given nodes.
|
|
4
|
+
* @param typeImports Record<moduleName, typeName[]>
|
|
5
|
+
* @param nodes
|
|
6
|
+
* @returns Record<moduleName, typeName[]>
|
|
7
|
+
*/
|
|
8
|
+
export function filterUnusedTypes(typeImports, nodes) {
|
|
9
|
+
const usedTypeImports = {};
|
|
10
|
+
const targetTypeNames = Object.entries(typeImports).reduce((acc, [moduleName, typeImports]) => typeImports.reduce((acc, typeName) => {
|
|
11
|
+
acc[typeName] = moduleName;
|
|
12
|
+
return acc;
|
|
13
|
+
}, acc), {});
|
|
14
|
+
const transformer = (context) => (rootNode) => {
|
|
15
|
+
function visit(node) {
|
|
16
|
+
if (ts.isTypeReferenceNode(node) && ts.isIdentifier(node.typeName)) {
|
|
17
|
+
const typeName = node.typeName.text;
|
|
18
|
+
const moduleName = targetTypeNames[typeName];
|
|
19
|
+
if (moduleName) {
|
|
20
|
+
usedTypeImports[moduleName] ??= [];
|
|
21
|
+
if (!usedTypeImports[moduleName].includes(typeName)) {
|
|
22
|
+
usedTypeImports[moduleName].push(typeName);
|
|
23
|
+
usedTypeImports[moduleName].sort();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return ts.visitEachChild(node, visit, context);
|
|
28
|
+
}
|
|
29
|
+
return ts.visitNode(rootNode, visit);
|
|
30
|
+
};
|
|
31
|
+
ts.transform(nodes, [transformer]).dispose();
|
|
32
|
+
return usedTypeImports;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=filterUnusedTypes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filterUnusedTypes.js","sourceRoot":"","sources":["../../src/ts-factory/filterUnusedTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAC/B,WAAqC,EACrC,KAAgB;IAEhB,MAAM,eAAe,GAA6B,EAAE,CAAC;IACrD,MAAM,eAAe,GAAG,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,MAAM,CAGxD,CAAC,GAAG,EAAE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7 +1,7 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
2
|
type Options = {
|
|
3
3
|
servicesDirName: string;
|
|
4
|
-
explicitImportExtensions:
|
|
4
|
+
explicitImportExtensions: '.js' | '.ts' | undefined;
|
|
5
5
|
};
|
|
6
6
|
export declare const getClientFactory: (options: Options) => (ts.ImportDeclaration | ts.FunctionDeclaration | ts.TypeAliasDeclaration)[];
|
|
7
7
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getClientFactory.d.ts","sourceRoot":"","sources":["../../src/ts-factory/getClientFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,KAAK,OAAO,GAAG;IACb,eAAe,EAAE,MAAM,CAAC;IACxB,wBAAwB,EAAE,
|
|
1
|
+
{"version":3,"file":"getClientFactory.d.ts","sourceRoot":"","sources":["../../src/ts-factory/getClientFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,KAAK,OAAO,GAAG;IACb,eAAe,EAAE,MAAM,CAAC;IACxB,wBAAwB,EAAE,KAAK,GAAG,KAAK,GAAG,SAAS,CAAC;CACrD,CAAC;AAEF,eAAO,MAAM,gBAAgB,YAAa,OAAO,gFAKhD,CAAC"}
|
|
@@ -24,7 +24,7 @@ const getClientImportsFactory = ({ servicesDirName, explicitImportExtensions, })
|
|
|
24
24
|
factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
|
|
25
25
|
factory.createImportSpecifier(false, undefined, factory.createIdentifier('services')),
|
|
26
26
|
factory.createImportSpecifier(true, undefined, factory.createIdentifier('Services')),
|
|
27
|
-
])), factory.createStringLiteral(`./${servicesDirName}/index${explicitImportExtensions
|
|
27
|
+
])), factory.createStringLiteral(`./${servicesDirName}/index${explicitImportExtensions ?? ''}`), undefined),
|
|
28
28
|
];
|
|
29
29
|
};
|
|
30
30
|
const getCreateClientFunctionFactory = () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getClientFactory.js","sourceRoot":"","sources":["../../src/ts-factory/getClientFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAO5B,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,OAAgB,EAAE,EAAE;IACnD,OAAO;QACL,GAAG,uBAAuB,CAAC,OAAO,CAAC;QACnC,GAAG,8BAA8B,EAAE;KACpC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,uBAAuB,GAAG,CAAC,EAC/B,eAAe,EACf,wBAAwB,GAChB,EAAE,EAAE;IACZ,MAAM,OAAO,GAAG,EAAE,CAAC,OAAO,CAAC;IAE3B,OAAO;QACL,OAAO,CAAC,uBAAuB,CAC7B,SAAS,EACT,OAAO,CAAC,kBAAkB,CACxB,KAAK,EACL,SAAS,EACT,OAAO,CAAC,kBAAkB,CAAC;YACzB,OAAO,CAAC,qBAAqB,CAC3B,KAAK,EACL,SAAS,EACT,OAAO,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,CAC3C;YACD,GAAG;gBACD,wBAAwB;gBACxB,6BAA6B;gBAC7B,0BAA0B;gBAC1B,kCAAkC;gBAClC,6BAA6B;gBAC7B,wBAAwB;gBACxB,6BAA6B;aAC9B,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACb,OAAO,CAAC,qBAAqB,CAC3B,IAAI,EACJ,SAAS,EACT,OAAO,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAC/B,CACF;SACF,CAAC,CACH,EACD,OAAO,CAAC,mBAAmB,CAAC,sBAAsB,CAAC,EACnD,SAAS,CACV;QACD,OAAO,CAAC,uBAAuB,CAC7B,SAAS,EACT,OAAO,CAAC,kBAAkB,CACxB,KAAK,EACL,SAAS,EACT,OAAO,CAAC,qBAAqB,CAAC,OAAO,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC,CACrE,EACD,OAAO,CAAC,mBAAmB,CAAC,sCAAsC,CAAC,EACnE,SAAS,CACV;QACD,OAAO,CAAC,uBAAuB,CAC7B,SAAS,EACT,OAAO,CAAC,kBAAkB,CACxB,KAAK,EACL,SAAS,EACT,OAAO,CAAC,kBAAkB,CAAC;YACzB,OAAO,CAAC,qBAAqB,CAC3B,KAAK,EACL,SAAS,EACT,OAAO,CAAC,gBAAgB,CAAC,UAAU,CAAC,CACrC;YACD,OAAO,CAAC,qBAAqB,CAC3B,IAAI,EACJ,SAAS,EACT,OAAO,CAAC,gBAAgB,CAAC,UAAU,CAAC,CACrC;SACF,CAAC,CACH,EACD,OAAO,CAAC,mBAAmB,CACzB,KAAK,eAAe,SAAS,wBAAwB,
|
|
1
|
+
{"version":3,"file":"getClientFactory.js","sourceRoot":"","sources":["../../src/ts-factory/getClientFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAO5B,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,OAAgB,EAAE,EAAE;IACnD,OAAO;QACL,GAAG,uBAAuB,CAAC,OAAO,CAAC;QACnC,GAAG,8BAA8B,EAAE;KACpC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,uBAAuB,GAAG,CAAC,EAC/B,eAAe,EACf,wBAAwB,GAChB,EAAE,EAAE;IACZ,MAAM,OAAO,GAAG,EAAE,CAAC,OAAO,CAAC;IAE3B,OAAO;QACL,OAAO,CAAC,uBAAuB,CAC7B,SAAS,EACT,OAAO,CAAC,kBAAkB,CACxB,KAAK,EACL,SAAS,EACT,OAAO,CAAC,kBAAkB,CAAC;YACzB,OAAO,CAAC,qBAAqB,CAC3B,KAAK,EACL,SAAS,EACT,OAAO,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,CAC3C;YACD,GAAG;gBACD,wBAAwB;gBACxB,6BAA6B;gBAC7B,0BAA0B;gBAC1B,kCAAkC;gBAClC,6BAA6B;gBAC7B,wBAAwB;gBACxB,6BAA6B;aAC9B,CAAC,GAAG,CAAC,CAAC,IAAI,E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ACF;SACF,EACD,IAAI,CACL,CACF;QACD,OAAO,CAAC,0BAA0B,CAChC,SAAS,EACT,OAAO,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,EAC1C,SAAS,EACT,OAAO,CAAC,mBAAmB,CACzB,OAAO,CAAC,gBAAgB,CAAC,WAAW,CAAC,EACrC,SAAS,CACV,CACF;KACF,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -2,6 +2,6 @@ import type { ServiceImportsFactoryOptions } from './getServiceFactory.js';
|
|
|
2
2
|
import ts from 'typescript';
|
|
3
3
|
export declare const getIndexFactory: ({ openapiTypesImportPath, servicesDirName, explicitImportExtensions, }: {
|
|
4
4
|
servicesDirName: string;
|
|
5
|
-
explicitImportExtensions:
|
|
5
|
+
explicitImportExtensions: ".js" | ".ts" | undefined;
|
|
6
6
|
} & Partial<Pick<ServiceImportsFactoryOptions, "openapiTypesImportPath">>) => ts.ExportDeclaration[];
|
|
7
7
|
//# sourceMappingURL=getIndexFactory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getIndexFactory.d.ts","sourceRoot":"","sources":["../../src/ts-factory/getIndexFactory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAC;AAC3E,OAAO,EAAE,MAAM,YAAY,CAAC;AAG5B,eAAO,MAAM,eAAe,2EAIzB;IACD,eAAe,EAAE,MAAM,CAAC;IACxB,wBAAwB,EAAE,
|
|
1
|
+
{"version":3,"file":"getIndexFactory.d.ts","sourceRoot":"","sources":["../../src/ts-factory/getIndexFactory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAC;AAC3E,OAAO,EAAE,MAAM,YAAY,CAAC;AAG5B,eAAO,MAAM,eAAe,2EAIzB;IACD,eAAe,EAAE,MAAM,CAAC;IACxB,wBAAwB,EAAE,KAAK,GAAG,KAAK,GAAG,SAAS,CAAC;CACrD,GAAG,OAAO,CAAC,IAAI,CAAC,4BAA4B,EAAE,wBAAwB,CAAC,CAAC,2BAuExE,CAAC"}
|
|
@@ -2,11 +2,11 @@ import ts from 'typescript';
|
|
|
2
2
|
import { maybeResolveImport } from '../lib/maybeResolveImport.js';
|
|
3
3
|
export const getIndexFactory = ({ openapiTypesImportPath, servicesDirName, explicitImportExtensions, }) => {
|
|
4
4
|
const factory = ts.factory;
|
|
5
|
-
const importExtension = explicitImportExtensions
|
|
5
|
+
const importExtension = explicitImportExtensions ?? '';
|
|
6
6
|
return [
|
|
7
7
|
...(openapiTypesImportPath
|
|
8
8
|
? [
|
|
9
|
-
factory.createExportDeclaration(undefined,
|
|
9
|
+
factory.createExportDeclaration(undefined, true, factory.createNamedExports(['$defs', 'paths', 'components', 'operations', 'webhooks'].map((name) => factory.createExportSpecifier(false, undefined, factory.createIdentifier(name)))), factory.createStringLiteral(maybeResolveImport({ openapiTypesImportPath, servicesDirName })), undefined),
|
|
10
10
|
]
|
|
11
11
|
: []),
|
|
12
12
|
factory.createExportDeclaration(undefined, false, factory.createNamedExports([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getIndexFactory.js","sourceRoot":"","sources":["../../src/ts-factory/getIndexFactory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAElE,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,EAC9B,sBAAsB,EACtB,eAAe,EACf,wBAAwB,GAI+C,EAAE,EAAE;IAC3E,MAAM,OAAO,GAAG,EAAE,CAAC,OAAO,CAAC;IAC3B,MAAM,eAAe,GAAG,wBAAwB,
|
|
1
|
+
{"version":3,"file":"getIndexFactory.js","sourceRoot":"","sources":["../../src/ts-factory/getIndexFactory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,8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,eAAe,EAAE,CAC/C,EACD,SAAS,CACV;QACD,OAAO,CAAC,uBAAuB,CAC7B,SAAS,EACT,KAAK,EACL,OAAO,CAAC,kBAAkB,CAAC;YACzB,OAAO,CAAC,qBAAqB,CAC3B,KAAK,EACL,SAAS,EACT,OAAO,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,CAC5C;SACF,CAAC,EACF,OAAO,CAAC,mBAAmB,CAAC,sBAAsB,eAAe,EAAE,CAAC,EACpE,SAAS,CACV;KACF,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ServiceOperation } from '@openapi-qraft/plugin/lib/open-api/
|
|
1
|
+
import { ServiceOperation } from '@openapi-qraft/plugin/lib/open-api/OpenAPIService';
|
|
2
2
|
import ts from 'typescript';
|
|
3
3
|
export type ServiceImportsFactoryOptions = {
|
|
4
4
|
openapiTypesImportPath: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getServiceFactory.d.ts","sourceRoot":"","sources":["../../src/ts-factory/getServiceFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"getServiceFactory.d.ts","sourceRoot":"","sources":["../../src/ts-factory/getServiceFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mDAAmD,CAAC;AAErF,OAAO,EAAE,MAAM,YAAY,CAAC;AAmC5B,MAAM,MAAM,4BAA4B,GAAG;IACzC,sBAAsB,EAAE,MAAM,CAAC;CAChC,CAAC;AAEF,KAAK,OAAO,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1D,eAAO,MAAM,iBAAiB,YACnB,OAAO,cACJ,gBAAgB,EAAE,8BACF,4BAA4B,wGAgBzD,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import camelCase from 'camelcase';
|
|
2
2
|
import ts from 'typescript';
|
|
3
3
|
import { createOperationCommonTSDoc } from '../lib/createOperationCommonTSDoc.js';
|
|
4
|
+
import { filterUnusedTypes } from './filterUnusedTypes.js';
|
|
4
5
|
import { createServiceOperationCancelQueriesNodes } from './service-operation.generated/ServiceOperationCancelQueries.js';
|
|
5
6
|
import { createServiceOperationFetchInfiniteQueryNodes } from './service-operation.generated/ServiceOperationFetchInfiniteQuery.js';
|
|
6
7
|
import { createServiceOperationFetchQueryNodes } from './service-operation.generated/ServiceOperationFetchQuery.js';
|
|
@@ -32,13 +33,16 @@ import { createServiceOperationUseSuspenseQueryNodes } from './service-operation
|
|
|
32
33
|
import { createOperationMethodTSDocExample } from './tsdoc/createOperationMethodTSDocExample.js';
|
|
33
34
|
const factory = ts.factory;
|
|
34
35
|
export const getServiceFactory = (service, operations, { openapiTypesImportPath }) => {
|
|
35
|
-
|
|
36
|
-
getOpenAPISchemaImportsFactory(openapiTypesImportPath),
|
|
37
|
-
...getServiceOperationImportsFactory(operations),
|
|
36
|
+
const mainNodes = [
|
|
38
37
|
getServiceInterfaceFactory(service, operations),
|
|
39
38
|
getServiceVariableFactory(service, operations),
|
|
40
39
|
...getOperationsTypes(operations),
|
|
41
40
|
];
|
|
41
|
+
const importNodes = [
|
|
42
|
+
getOpenAPISchemaImportsFactory(openapiTypesImportPath),
|
|
43
|
+
...getServiceOperationImportsFactory(filterUnusedTypes(getModuleTypeImports(operations), mainNodes)),
|
|
44
|
+
];
|
|
45
|
+
return [...importNodes, ...mainNodes];
|
|
42
46
|
};
|
|
43
47
|
const getOpenAPISchemaImportsFactory = (schemaTypesPath) => {
|
|
44
48
|
const factory = ts.factory;
|
|
@@ -46,16 +50,8 @@ const getOpenAPISchemaImportsFactory = (schemaTypesPath) => {
|
|
|
46
50
|
factory.createImportSpecifier(false, undefined, factory.createIdentifier('paths')),
|
|
47
51
|
])), factory.createStringLiteral(schemaTypesPath));
|
|
48
52
|
};
|
|
49
|
-
const getServiceOperationImportsFactory = (
|
|
53
|
+
const getServiceOperationImportsFactory = (moduleImports) => {
|
|
50
54
|
const factory = ts.factory;
|
|
51
|
-
const moduleImports = getModuleTypeImports([
|
|
52
|
-
...(operations.some((operation) => operation.method === 'get')
|
|
53
|
-
? createServicesQueryOperationNodes()
|
|
54
|
-
: []),
|
|
55
|
-
...(operations.some((operation) => operation.method !== 'get')
|
|
56
|
-
? createServicesMutationOperationNodes()
|
|
57
|
-
: []),
|
|
58
|
-
]);
|
|
59
55
|
return Object.entries(moduleImports).map(([moduleName, importSpecifierNames]) => {
|
|
60
56
|
return factory.createImportDeclaration(undefined, factory.createImportClause(true, undefined, factory.createNamedImports(importSpecifierNames.map((specifier) => factory.createImportSpecifier(false, undefined, factory.createIdentifier(specifier))))), factory.createStringLiteral(moduleName));
|
|
61
57
|
});
|
|
@@ -104,8 +100,8 @@ const getOperationSchemaFactory = (operation) => {
|
|
|
104
100
|
return factory.createTypeLiteralNode([
|
|
105
101
|
factory.createPropertySignature(undefined, factory.createIdentifier('method'), undefined, factory.createLiteralTypeNode(factory.createStringLiteral(operation.method))),
|
|
106
102
|
factory.createPropertySignature(undefined, factory.createIdentifier('url'), undefined, factory.createLiteralTypeNode(factory.createStringLiteral(operation.path))),
|
|
107
|
-
operation.
|
|
108
|
-
? factory.createPropertySignature(undefined, factory.createIdentifier('mediaType'), undefined, factory.createLiteralTypeNode(factory.createStringLiteral(
|
|
103
|
+
operation.requestBody
|
|
104
|
+
? factory.createPropertySignature(undefined, factory.createIdentifier('mediaType'), undefined, factory.createTupleTypeNode(Object.keys(operation.requestBody.content).map((mediaType) => factory.createLiteralTypeNode(factory.createStringLiteral(mediaType)))))
|
|
109
105
|
: null,
|
|
110
106
|
operation.security
|
|
111
107
|
? factory.createPropertySignature(undefined, factory.createIdentifier('security'), undefined, factory.createTupleTypeNode(getOperationSecuritySchemas(operation.security).map((securitySchemaName) => factory.createLiteralTypeNode(factory.createStringLiteral(securitySchemaName)))))
|
|
@@ -125,13 +121,19 @@ const getOperationResponseFactory = (operation, type) => {
|
|
|
125
121
|
}));
|
|
126
122
|
};
|
|
127
123
|
const getOperationBodyFactory = (operation) => {
|
|
128
|
-
if (!operation.
|
|
124
|
+
if (!operation.requestBody)
|
|
129
125
|
return factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword);
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
126
|
+
const mediaTypes = Object.keys(operation.requestBody.content);
|
|
127
|
+
return factory.createUnionTypeNode([
|
|
128
|
+
...mediaTypes.map((mediaType) => factory.createIndexedAccessTypeNode(factory.createIndexedAccessTypeNode(factory.createTypeReferenceNode(factory.createIdentifier('NonNullable'), [
|
|
129
|
+
factory.createIndexedAccessTypeNode(factory.createIndexedAccessTypeNode(factory.createIndexedAccessTypeNode(factory.createTypeReferenceNode(factory.createIdentifier('paths'), undefined), factory.createLiteralTypeNode(factory.createStringLiteral(operation.path))), factory.createLiteralTypeNode(factory.createStringLiteral(operation.method))), factory.createLiteralTypeNode(factory.createStringLiteral('requestBody'))),
|
|
130
|
+
]),
|
|
131
|
+
// todo::Add optional NonNullable inference, see `POST /entities/{entity_id}/documents`
|
|
132
|
+
factory.createLiteralTypeNode(factory.createStringLiteral('content'))), factory.createLiteralTypeNode(factory.createStringLiteral(mediaType)))),
|
|
133
|
+
...(mediaTypes.some((mediaType) => mediaType.includes('/form-data'))
|
|
134
|
+
? [factory.createTypeReferenceNode(factory.createIdentifier('FormData'))]
|
|
135
|
+
: []),
|
|
136
|
+
]);
|
|
135
137
|
};
|
|
136
138
|
const createOperationParametersFactory = (operation) => {
|
|
137
139
|
if (!operation.parameters?.length)
|
|
@@ -177,8 +179,8 @@ const getServiceVariablePropertyFactory = (operation) => {
|
|
|
177
179
|
factory.createPropertyAssignment(factory.createIdentifier('schema'), factory.createObjectLiteralExpression([
|
|
178
180
|
factory.createPropertyAssignment(factory.createIdentifier('method'), factory.createStringLiteral(operation.method)),
|
|
179
181
|
factory.createPropertyAssignment(factory.createIdentifier('url'), factory.createStringLiteral(operation.path)),
|
|
180
|
-
operation.
|
|
181
|
-
? factory.createPropertyAssignment(factory.createIdentifier('mediaType'), factory.
|
|
182
|
+
operation.requestBody
|
|
183
|
+
? factory.createPropertyAssignment(factory.createIdentifier('mediaType'), factory.createArrayLiteralExpression(Object.keys(operation.requestBody.content).map((mediaType) => factory.createStringLiteral(mediaType))))
|
|
182
184
|
: null,
|
|
183
185
|
operation.security
|
|
184
186
|
? factory.createPropertyAssignment(factory.createIdentifier('security'), factory.createArrayLiteralExpression(getOperationSecuritySchemas(operation.security).map((securitySchemaName) => factory.createStringLiteral(securitySchemaName))))
|
|
@@ -240,23 +242,33 @@ const getMethodSignatureNodes = (nodes) => {
|
|
|
240
242
|
? node.members.filter((node) => ts.isMethodSignature(node) || ts.isCallSignatureDeclaration(node))
|
|
241
243
|
: []);
|
|
242
244
|
};
|
|
243
|
-
|
|
245
|
+
/**
|
|
246
|
+
* Returns a list of all the modules that are imported by the operations.
|
|
247
|
+
* @param operations
|
|
248
|
+
* @returns Record<moduleName, importSpecifierNames[]>
|
|
249
|
+
*/
|
|
250
|
+
const getModuleTypeImports = (operations) => {
|
|
251
|
+
const nodes = [
|
|
252
|
+
...(operations.some((operation) => operation.method === 'get')
|
|
253
|
+
? createServicesQueryOperationNodes()
|
|
254
|
+
: []),
|
|
255
|
+
...(operations.some((operation) => operation.method !== 'get')
|
|
256
|
+
? createServicesMutationOperationNodes()
|
|
257
|
+
: []),
|
|
258
|
+
];
|
|
244
259
|
return nodes
|
|
245
|
-
.map((node) =>
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
: undefined;
|
|
258
|
-
return foo;
|
|
259
|
-
})
|
|
260
|
+
.map((node) => ts.isImportDeclaration(node) &&
|
|
261
|
+
ts.isStringLiteral(node.moduleSpecifier) &&
|
|
262
|
+
node.importClause?.isTypeOnly &&
|
|
263
|
+
node.importClause.namedBindings &&
|
|
264
|
+
ts.isNamedImports(node.importClause.namedBindings)
|
|
265
|
+
? {
|
|
266
|
+
module: node.moduleSpecifier.text,
|
|
267
|
+
imports: node.importClause.namedBindings.elements
|
|
268
|
+
.filter(ts.isImportSpecifier)
|
|
269
|
+
.map((specifier) => specifier.name.text),
|
|
270
|
+
}
|
|
271
|
+
: undefined)
|
|
260
272
|
.reduce((acc, item) => {
|
|
261
273
|
if (!item)
|
|
262
274
|
return acc;
|
|
@@ -264,6 +276,7 @@ const getModuleTypeImports = (nodes) => {
|
|
|
264
276
|
acc[item.module] = item.imports.filter(arrayFilterUniqueCallback);
|
|
265
277
|
else
|
|
266
278
|
acc[item.module] = [...acc[item.module], ...item.imports].filter(arrayFilterUniqueCallback);
|
|
279
|
+
acc[item.module].sort();
|
|
267
280
|
return acc;
|
|
268
281
|
}, {});
|
|
269
282
|
};
|
|
@@ -316,12 +329,11 @@ function reduceAreAllOptionalConditionalTParamsType(node, operation) {
|
|
|
316
329
|
ts.isIdentifier(node.typeName) &&
|
|
317
330
|
node.typeName.text === 'TParams');
|
|
318
331
|
})) {
|
|
319
|
-
if (
|
|
320
|
-
|
|
321
|
-
return node.trueType;
|
|
332
|
+
if (operation.parameters?.some((parameter) => parameter.required)) {
|
|
333
|
+
return node.falseType;
|
|
322
334
|
}
|
|
323
335
|
else {
|
|
324
|
-
return node.
|
|
336
|
+
return node.trueType;
|
|
325
337
|
}
|
|
326
338
|
}
|
|
327
339
|
return ts.visitEachChild(node, visit, context);
|