mobx-tanstack-query-api 0.12.0 → 0.13.1
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/README.md +4 -4
- package/codegen/index.d.ts +56 -34
- package/codegen/index.d.ts.map +1 -1
- package/codegen/index.js +4 -24
- package/codegen/templates/all-endpoints-per-file.tmpl.d.ts.map +1 -1
- package/codegen/templates/all-endpoints-per-file.tmpl.js +29 -26
- package/codegen/templates/endpoint-per-file.tmpl.d.ts.map +1 -1
- package/codegen/templates/endpoint-per-file.tmpl.js +7 -3
- package/codegen/utils/remove-unused-types.d.ts +2 -1
- package/codegen/utils/remove-unused-types.d.ts.map +1 -1
- package/codegen/utils/remove-unused-types.js +3 -15
- package/codegen/utils/unpack-filter-option.d.ts +4 -0
- package/codegen/utils/unpack-filter-option.d.ts.map +1 -0
- package/codegen/utils/unpack-filter-option.js +16 -0
- package/package.json +7 -2
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
<img src="assets/logo.png" align="right" width="156" alt="logo" />
|
|
2
|
+
|
|
1
3
|
# mobx-tanstack-query-api
|
|
2
4
|
|
|
3
5
|
[![NPM version][npm-image]][npm-url] [![build status][github-build-actions-image]][github-actions-url] [![npm download][download-image]][download-url] [![bundle size][bundlephobia-image]][bundlephobia-url]
|
|
@@ -12,8 +14,6 @@
|
|
|
12
14
|
[bundlephobia-url]: https://bundlephobia.com/result?p=mobx-tanstack-query-api
|
|
13
15
|
[bundlephobia-image]: https://badgen.net/bundlephobia/minzip/mobx-tanstack-query-api
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
API codegen from swagger
|
|
17
|
+
API codegen from swagger for `mobx-tanstack-query`
|
|
18
18
|
|
|
19
|
-
# [Documentation](https://js2me.github.io/mobx-tanstack-query/
|
|
19
|
+
# [Documentation](https://js2me.github.io/mobx-tanstack-query-api/)
|
package/codegen/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { LoDashStatic } from 'lodash';
|
|
2
|
-
import { type ParsedRoute } from 'swagger-typescript-api';
|
|
2
|
+
import { type ParsedRoute, type RawRouteInfo } from 'swagger-typescript-api';
|
|
3
3
|
import type { RequestInit } from 'undici-types';
|
|
4
4
|
import type { AnyObject, KeyOfByValue, Maybe } from 'yummies/utils/types';
|
|
5
5
|
import { type RemoveUnusedTypesParams } from './utils/remove-unused-types.js';
|
|
@@ -9,7 +9,9 @@ export type CodegenDataUtils = {
|
|
|
9
9
|
formatModelName: (modelName: string) => string;
|
|
10
10
|
};
|
|
11
11
|
export type EndpointData = ParsedRoute;
|
|
12
|
-
type
|
|
12
|
+
export type FilterOption<T extends (...args: any[]) => boolean> = T | string | RegExp | (RegExp | string)[];
|
|
13
|
+
type FilterEndpointsOption = FilterOption<(endpoint: EndpointData) => boolean>;
|
|
14
|
+
type FilterGroupsOption = FilterOption<(groupName: string) => boolean>;
|
|
13
15
|
export type CodegenProcess = AnyObject;
|
|
14
16
|
export interface ImportFileParams {
|
|
15
17
|
path: string;
|
|
@@ -21,22 +23,41 @@ export interface MetaInfo {
|
|
|
21
23
|
tags?: string[];
|
|
22
24
|
}
|
|
23
25
|
export interface GenerateQueryApiParams {
|
|
26
|
+
/**
|
|
27
|
+
* [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/config/#output)
|
|
28
|
+
*/
|
|
24
29
|
output: string;
|
|
30
|
+
/**
|
|
31
|
+
* [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/config/#input)
|
|
32
|
+
*/
|
|
25
33
|
input: string | AnyObject;
|
|
34
|
+
/**
|
|
35
|
+
* [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/config/#requestpathprefix)
|
|
36
|
+
*/
|
|
26
37
|
requestPathPrefix?: string;
|
|
38
|
+
/**
|
|
39
|
+
* [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/config/#requestpathsuffix)
|
|
40
|
+
*/
|
|
27
41
|
requestPathSuffix?: string;
|
|
28
|
-
|
|
42
|
+
/**
|
|
43
|
+
* [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/config/#removeunusedtypes)
|
|
44
|
+
*/
|
|
29
45
|
removeUnusedTypes?: true | {
|
|
30
46
|
keepTypes?: RemoveUnusedTypesParams['keepTypes'];
|
|
31
47
|
};
|
|
32
48
|
/**
|
|
33
|
-
*
|
|
49
|
+
* [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/config/#formatendpointname)
|
|
50
|
+
*/
|
|
51
|
+
formatEndpointName?: (endpointName: string, endpointData: RawRouteInfo) => Maybe<string>;
|
|
52
|
+
/**
|
|
53
|
+
* [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/config/#formatexportgroupname)
|
|
34
54
|
*/
|
|
35
|
-
formatEndpointName?: (endpointName: string, endpointData: AnyObject) => Maybe<string>;
|
|
36
55
|
formatExportGroupName?: (groupName: string, utils: CodegenDataUtils) => string;
|
|
37
56
|
/**
|
|
38
57
|
* Various generation output types
|
|
39
58
|
*
|
|
59
|
+
* [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/config/#outputtype)
|
|
60
|
+
*
|
|
40
61
|
* `one-endpoint-per-file`
|
|
41
62
|
* @example
|
|
42
63
|
* ```
|
|
@@ -76,60 +97,61 @@ export interface GenerateQueryApiParams {
|
|
|
76
97
|
outputType?: 'one-endpoint-per-file' | 'endpoints-per-file';
|
|
77
98
|
/**
|
|
78
99
|
* Group endpoints and collect it into object
|
|
100
|
+
*
|
|
101
|
+
* [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/config/#groupby)
|
|
79
102
|
*/
|
|
80
103
|
groupBy?: ((endpoint: EndpointData) => string) | `path-segment` | `path-segment-${number}` | `tag` | `tag-${number}`;
|
|
81
104
|
/**
|
|
82
105
|
* Collect all exports into single namespace
|
|
83
106
|
*
|
|
84
|
-
*
|
|
85
|
-
* without namespace:
|
|
86
|
-
*
|
|
87
|
-
* export * from "./endpoints";
|
|
88
|
-
* export * from "./data-contracts";
|
|
89
|
-
*
|
|
90
|
-
* with namespace:
|
|
91
|
-
*
|
|
92
|
-
* export * as namespaceName from "./__exports"; // exports like above
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
* namespaceName.login.toMutation()
|
|
107
|
+
* [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/config/#namespace)
|
|
96
108
|
*/
|
|
97
109
|
namespace?: string | ((utils: AnyObject) => string);
|
|
98
110
|
/**
|
|
99
|
-
*
|
|
100
|
-
* operationId: 'getById'
|
|
101
|
-
* /api/v1/users/{userId} => /api/v1/users/1
|
|
102
|
-
*
|
|
103
|
-
* addPathSegmentToRouteName: 2 (users), 0 - api
|
|
104
|
-
*
|
|
105
|
-
* output endpoint instance name: `usersGetById` (pathSegments[2] + operationId)
|
|
111
|
+
* [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/config/#addpathsegmenttoroutename)
|
|
106
112
|
*/
|
|
107
113
|
addPathSegmentToRouteName?: boolean | number;
|
|
114
|
+
/**
|
|
115
|
+
* [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/config/#queryclient)
|
|
116
|
+
*/
|
|
108
117
|
queryClient?: 'builtin' | ImportFileParams;
|
|
118
|
+
/**
|
|
119
|
+
* [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/config/#endpoint)
|
|
120
|
+
*/
|
|
109
121
|
endpoint?: 'builtin' | ImportFileParams;
|
|
122
|
+
/**
|
|
123
|
+
* [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/config/#httpclient)
|
|
124
|
+
*/
|
|
110
125
|
httpClient?: 'builtin' | ImportFileParams;
|
|
126
|
+
/**
|
|
127
|
+
* [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/config/#getendpointmeta)
|
|
128
|
+
*/
|
|
111
129
|
getEndpointMeta?: (route: AnyObject, utils: AnyObject) => {
|
|
112
|
-
typeName
|
|
113
|
-
|
|
130
|
+
typeName?: string;
|
|
131
|
+
typeNameImportPath?: string;
|
|
114
132
|
tmplData: string;
|
|
115
133
|
};
|
|
134
|
+
/**
|
|
135
|
+
* [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/config/#getrequestmeta)
|
|
136
|
+
*/
|
|
116
137
|
getRequestMeta?: (route: AnyObject, utils: AnyObject) => {
|
|
117
138
|
tmplData: string;
|
|
118
139
|
};
|
|
119
140
|
/**
|
|
120
141
|
* Additional parameters used to fetch your OpenAPI schema
|
|
121
142
|
*
|
|
122
|
-
*
|
|
123
|
-
* fetchSchemaRequestOptions: {
|
|
124
|
-
* headers: {
|
|
125
|
-
* 'PRIVATE-TOKEN': '12345'
|
|
126
|
-
* }
|
|
127
|
-
* }
|
|
143
|
+
* [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/config/#fetchschemarequestoptions)
|
|
128
144
|
*/
|
|
129
145
|
fetchSchemaRequestOptions?: RequestInit;
|
|
130
146
|
otherCodegenParams?: AnyObject;
|
|
131
|
-
|
|
132
|
-
|
|
147
|
+
/**
|
|
148
|
+
* [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/config/#filterendpoints)
|
|
149
|
+
*/
|
|
150
|
+
filterEndpoints?: FilterEndpointsOption;
|
|
151
|
+
/**
|
|
152
|
+
* [**Documentation**](https://js2me.github.io/mobx-tanstack-query-api/config/#filtergroups)
|
|
153
|
+
*/
|
|
154
|
+
filterGroups?: FilterGroupsOption;
|
|
133
155
|
libImports?: {
|
|
134
156
|
'mobx-tanstack-query-api'?: string;
|
|
135
157
|
};
|
package/codegen/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/codegen/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,EAEL,KAAK,WAAW,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/codegen/index.ts"],"names":[],"mappings":"AAEA,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pl } from './templates/index-ts-for-endpoint-per-file.tmpl.js';
|
|
10
10
|
import { metaInfoTmpl } from './templates/meta-info.tmpl.js';
|
|
11
11
|
import { removeUnusedTypes, } from './utils/remove-unused-types.js';
|
|
12
|
+
import { unpackFilterOption } from './utils/unpack-filter-option.js';
|
|
12
13
|
const __filename = fileURLToPath(import.meta.url);
|
|
13
14
|
const __dirname = path.dirname(__filename);
|
|
14
15
|
const __execdirname = process.cwd();
|
|
@@ -151,29 +152,7 @@ export const generateApi = async (params) => {
|
|
|
151
152
|
const allRoutes = Object.values(generated.configuration.routes)
|
|
152
153
|
.flat()
|
|
153
154
|
.flatMap((routeGroup) => 'routes' in routeGroup ? routeGroup.routes : routeGroup);
|
|
154
|
-
|
|
155
|
-
if (params.filterEndpoints) {
|
|
156
|
-
if (typeof params.filterEndpoints === 'function') {
|
|
157
|
-
filterEndpoint = params.filterEndpoints;
|
|
158
|
-
}
|
|
159
|
-
else {
|
|
160
|
-
const regexps = Array.isArray(params.filterEndpoints)
|
|
161
|
-
? params.filterEndpoints
|
|
162
|
-
: [params.filterEndpoints];
|
|
163
|
-
filterEndpoint = (route) => regexps.some((regexpOrString) => {
|
|
164
|
-
if (!route.raw) {
|
|
165
|
-
return false;
|
|
166
|
-
}
|
|
167
|
-
if (typeof regexpOrString === 'string') {
|
|
168
|
-
return regexpOrString === route.raw.operationId;
|
|
169
|
-
}
|
|
170
|
-
return regexpOrString.test(route.raw.operationId);
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
else {
|
|
175
|
-
filterEndpoint = () => true;
|
|
176
|
-
}
|
|
155
|
+
const filterEndpoint = unpackFilterOption(params.filterEndpoints, (route) => route.raw?.operationId || '');
|
|
177
156
|
const reservedDataContractNamesMap = new Map();
|
|
178
157
|
const collectedExportFilesFromIndexFile = [];
|
|
179
158
|
const groupsMap = new Map();
|
|
@@ -300,8 +279,9 @@ export const generateApi = async (params) => {
|
|
|
300
279
|
groupsMap.get(group)?.push(route);
|
|
301
280
|
});
|
|
302
281
|
// #endregion
|
|
282
|
+
const filterGroups = unpackFilterOption(params.filterGroups, (groupName) => groupName);
|
|
303
283
|
for await (const [groupName, routes] of groupsMap) {
|
|
304
|
-
if (
|
|
284
|
+
if (!filterGroups(groupName)) {
|
|
305
285
|
continue;
|
|
306
286
|
}
|
|
307
287
|
const fileNamesWithRequestInfo = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"all-endpoints-per-file.tmpl.d.ts","sourceRoot":"","sources":["../../../src/codegen/templates/all-endpoints-per-file.tmpl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5D,OAAO,KAAK,EACV,mBAAmB,EACnB,gBAAgB,EAChB,cAAc,EACd,sBAAsB,EACtB,QAAQ,EACT,MAAM,aAAa,CAAC;AAOrB,MAAM,WAAW,4BAA6B,SAAQ,SAAS;IAC7D,MAAM,EAAE,SAAS,EAAE,CAAC;IACpB,aAAa,EAAE,SAAS,CAAC;IACzB,SAAS,EAAE,sBAAsB,CAAC;IAClC,cAAc,EAAE,cAAc,CAAC;IAC/B,gBAAgB,EAAE,mBAAmB,CAAC;IACtC,KAAK,EAAE,gBAAgB,CAAC;IACxB,yBAAyB,EAAE,MAAM,CAAC;IAClC,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACzB,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;CAC3B;AAED,eAAO,MAAM,sBAAsB,GAAU,iIAU1C,4BAA4B;;;
|
|
1
|
+
{"version":3,"file":"all-endpoints-per-file.tmpl.d.ts","sourceRoot":"","sources":["../../../src/codegen/templates/all-endpoints-per-file.tmpl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5D,OAAO,KAAK,EACV,mBAAmB,EACnB,gBAAgB,EAChB,cAAc,EACd,sBAAsB,EACtB,QAAQ,EACT,MAAM,aAAa,CAAC;AAOrB,MAAM,WAAW,4BAA6B,SAAQ,SAAS;IAC7D,MAAM,EAAE,SAAS,EAAE,CAAC;IACpB,aAAa,EAAE,SAAS,CAAC;IACzB,SAAS,EAAE,sBAAsB,CAAC;IAClC,cAAc,EAAE,cAAc,CAAC;IAC/B,gBAAgB,EAAE,mBAAmB,CAAC;IACtC,KAAK,EAAE,gBAAgB,CAAC;IACxB,yBAAyB,EAAE,MAAM,CAAC;IAClC,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACzB,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;CAC3B;AAED,eAAO,MAAM,sBAAsB,GAAU,iIAU1C,4BAA4B;;;EAuI9B,CAAC"}
|
|
@@ -24,9 +24,34 @@ export const allEndpointPerFileTmpl = async ({ routes, configuration, apiParams,
|
|
|
24
24
|
});
|
|
25
25
|
return { ...newEndpointTemplateData, route };
|
|
26
26
|
});
|
|
27
|
-
|
|
27
|
+
const extraImportLines = [];
|
|
28
|
+
const endpointTemplates = await Promise.all(newEndpointTemplates.map(async ({ content: requestInfoInstanceContent, localModelTypes, route, }) => {
|
|
29
|
+
const requestInfoMeta = apiParams.getEndpointMeta?.(route, utils);
|
|
30
|
+
if (requestInfoMeta?.typeNameImportPath && requestInfoMeta.typeName) {
|
|
31
|
+
extraImportLines.push(`import { ${requestInfoMeta.typeName} } from "${requestInfoMeta.typeNameImportPath}";`);
|
|
32
|
+
}
|
|
33
|
+
return `
|
|
34
|
+
${(await Promise.all(localModelTypes.map(async (modelType) => {
|
|
35
|
+
const contractType = await dataContractTmpl({
|
|
36
|
+
configuration,
|
|
37
|
+
contract: modelType,
|
|
38
|
+
addExportKeyword: true,
|
|
39
|
+
});
|
|
40
|
+
return contractType;
|
|
41
|
+
})))
|
|
42
|
+
.filter(Boolean)
|
|
43
|
+
.join('\n\n')}
|
|
44
|
+
|
|
45
|
+
${endpointJSDocTmpl({
|
|
46
|
+
route,
|
|
47
|
+
configuration,
|
|
48
|
+
apiParams,
|
|
49
|
+
})}
|
|
50
|
+
export const ${_.camelCase(route.routeName.usage)} = ${requestInfoInstanceContent}
|
|
51
|
+
`;
|
|
52
|
+
}));
|
|
28
53
|
if (metaInfo) {
|
|
29
|
-
|
|
54
|
+
extraImportLines.push(`import { ${[groupName && 'Group', metaInfo?.namespace && 'namespace', 'Tag'].filter(Boolean).join(',')} } from "${groupName ? '../' : './'}meta-info";`);
|
|
30
55
|
}
|
|
31
56
|
return {
|
|
32
57
|
reservedDataContractNames: dataContractNamesInThisFile,
|
|
@@ -39,7 +64,7 @@ export const allEndpointPerFileTmpl = async ({ routes, configuration, apiParams,
|
|
|
39
64
|
import { ${importFileParams.endpoint.exportName} } from "${importFileParams.endpoint.path}";
|
|
40
65
|
import { ${importFileParams.httpClient.exportName} } from "${importFileParams.httpClient.path}";
|
|
41
66
|
import { ${importFileParams.queryClient.exportName} } from "${importFileParams.queryClient.path}";
|
|
42
|
-
${
|
|
67
|
+
${extraImportLines.join('\n')}
|
|
43
68
|
|
|
44
69
|
${configuration.modelTypes.length > 0
|
|
45
70
|
? `
|
|
@@ -64,29 +89,7 @@ export const allEndpointPerFileTmpl = async ({ routes, configuration, apiParams,
|
|
|
64
89
|
.filter(Boolean)
|
|
65
90
|
.join('\n\n')}
|
|
66
91
|
|
|
67
|
-
${
|
|
68
|
-
return `
|
|
69
|
-
${(await Promise.all(localModelTypes.map(async (modelType) => {
|
|
70
|
-
const contractType = await dataContractTmpl({
|
|
71
|
-
configuration,
|
|
72
|
-
contract: modelType,
|
|
73
|
-
addExportKeyword: true,
|
|
74
|
-
});
|
|
75
|
-
return contractType;
|
|
76
|
-
})))
|
|
77
|
-
.filter(Boolean)
|
|
78
|
-
.join('\n\n')}
|
|
79
|
-
|
|
80
|
-
${endpointJSDocTmpl({
|
|
81
|
-
route,
|
|
82
|
-
configuration,
|
|
83
|
-
apiParams,
|
|
84
|
-
})}
|
|
85
|
-
export const ${_.camelCase(route.routeName.usage)} = ${requestInfoInstanceContent}
|
|
86
|
-
`;
|
|
87
|
-
})))
|
|
88
|
-
.filter(Boolean)
|
|
89
|
-
.join('\n\n')}
|
|
92
|
+
${endpointTemplates.filter(Boolean).join('\n\n')}
|
|
90
93
|
`),
|
|
91
94
|
};
|
|
92
95
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"endpoint-per-file.tmpl.d.ts","sourceRoot":"","sources":["../../../src/codegen/templates/endpoint-per-file.tmpl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5D,OAAO,KAAK,EACV,mBAAmB,EACnB,gBAAgB,EAChB,cAAc,EACd,sBAAsB,EACtB,QAAQ,EACT,MAAM,aAAa,CAAC;AAOrB,MAAM,WAAW,yBAA0B,SAAQ,SAAS;IAC1D,KAAK,EAAE,SAAS,CAAC;IACjB,aAAa,EAAE,SAAS,CAAC;IACzB,SAAS,EAAE,sBAAsB,CAAC;IAClC,cAAc,EAAE,cAAc,CAAC;IAC/B,gBAAgB,EAAE,mBAAmB,CAAC;IACtC,KAAK,EAAE,gBAAgB,CAAC;IACxB,yBAAyB,EAAE,MAAM,CAAC;IAClC,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACzB,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;CAC3B;AAED,eAAO,MAAM,mBAAmB,GAAU,gIAUvC,yBAAyB;;;
|
|
1
|
+
{"version":3,"file":"endpoint-per-file.tmpl.d.ts","sourceRoot":"","sources":["../../../src/codegen/templates/endpoint-per-file.tmpl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5D,OAAO,KAAK,EACV,mBAAmB,EACnB,gBAAgB,EAChB,cAAc,EACd,sBAAsB,EACtB,QAAQ,EACT,MAAM,aAAa,CAAC;AAOrB,MAAM,WAAW,yBAA0B,SAAQ,SAAS;IAC1D,KAAK,EAAE,SAAS,CAAC;IACjB,aAAa,EAAE,SAAS,CAAC;IACzB,SAAS,EAAE,sBAAsB,CAAC;IAClC,cAAc,EAAE,cAAc,CAAC;IAC/B,gBAAgB,EAAE,mBAAmB,CAAC;IACtC,KAAK,EAAE,gBAAgB,CAAC;IACxB,yBAAyB,EAAE,MAAM,CAAC;IAClC,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACzB,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;CAC3B;AAED,eAAO,MAAM,mBAAmB,GAAU,gIAUvC,yBAAyB;;;EAwH3B,CAAC"}
|
|
@@ -20,9 +20,13 @@ export const endpointPerFileTmpl = async ({ route, configuration, apiParams, for
|
|
|
20
20
|
dataContractNamesInThisFile.push(reservedDataContractName);
|
|
21
21
|
}
|
|
22
22
|
});
|
|
23
|
-
|
|
23
|
+
const extraImportLines = [];
|
|
24
24
|
if (metaInfo) {
|
|
25
|
-
|
|
25
|
+
extraImportLines.push(`import { ${[groupName && 'Group', metaInfo?.namespace && 'namespace', 'Tag'].filter(Boolean).join(',')} } from "../${groupName ? '../' : ''}meta-info";`);
|
|
26
|
+
}
|
|
27
|
+
const requestInfoMeta = apiParams.getEndpointMeta?.(route, utils);
|
|
28
|
+
if (requestInfoMeta?.typeNameImportPath && requestInfoMeta.typeName) {
|
|
29
|
+
extraImportLines.push(`import { ${requestInfoMeta.typeName} } from "${requestInfoMeta.typeNameImportPath}";`);
|
|
26
30
|
}
|
|
27
31
|
return {
|
|
28
32
|
reservedDataContractNames: dataContractNamesInThisFile,
|
|
@@ -35,7 +39,7 @@ export const endpointPerFileTmpl = async ({ route, configuration, apiParams, for
|
|
|
35
39
|
import { ${importFileParams.endpoint.exportName} } from "${importFileParams.endpoint.path}";
|
|
36
40
|
import { ${importFileParams.httpClient.exportName} } from "${importFileParams.httpClient.path}";
|
|
37
41
|
import { ${importFileParams.queryClient.exportName} } from "${importFileParams.queryClient.path}";
|
|
38
|
-
${
|
|
42
|
+
${extraImportLines.join('\n')}
|
|
39
43
|
|
|
40
44
|
${configuration.modelTypes.length > 0
|
|
41
45
|
? `
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type { FilterOption } from '../index.js';
|
|
1
2
|
export interface RemoveUnusedTypesParams {
|
|
2
3
|
directory: string;
|
|
3
|
-
keepTypes?:
|
|
4
|
+
keepTypes?: FilterOption<(typeName: string) => boolean>;
|
|
4
5
|
}
|
|
5
6
|
export declare const removeUnusedTypes: (params: RemoveUnusedTypesParams) => Promise<void>;
|
|
6
7
|
//# sourceMappingURL=remove-unused-types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remove-unused-types.d.ts","sourceRoot":"","sources":["../../../src/codegen/utils/remove-unused-types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"remove-unused-types.d.ts","sourceRoot":"","sources":["../../../src/codegen/utils/remove-unused-types.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGhD,MAAM,WAAW,uBAAuB;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,YAAY,CAAC,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC;CACzD;AA4ID,eAAO,MAAM,iBAAiB,GAAU,QAAQ,uBAAuB,kBAKtE,CAAC"}
|
|
@@ -1,19 +1,6 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { Node, Project, SyntaxKind } from 'ts-morph';
|
|
3
|
-
|
|
4
|
-
if (!keepTypes) {
|
|
5
|
-
return true;
|
|
6
|
-
}
|
|
7
|
-
const keepTypesArr = Array.isArray(keepTypes) ? keepTypes : [keepTypes];
|
|
8
|
-
return keepTypesArr.every((keepTypeCheck) => {
|
|
9
|
-
if (typeof keepTypeCheck === 'string') {
|
|
10
|
-
return typeName !== keepTypeCheck;
|
|
11
|
-
}
|
|
12
|
-
else {
|
|
13
|
-
return !keepTypeCheck.test(typeName);
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
};
|
|
3
|
+
import { unpackFilterOption } from './unpack-filter-option.js';
|
|
17
4
|
const removeUnusedTypesItteration = async ({ directory, keepTypes,
|
|
18
5
|
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: <explanation>
|
|
19
6
|
}) => {
|
|
@@ -98,11 +85,12 @@ const removeUnusedTypesItteration = async ({ directory, keepTypes,
|
|
|
98
85
|
}
|
|
99
86
|
}
|
|
100
87
|
let removedCount = 0;
|
|
88
|
+
const isNeedToRemoveType = unpackFilterOption(keepTypes, (name) => name, false);
|
|
101
89
|
for (const [name, declarations] of candidateTypes) {
|
|
102
90
|
if (usedTypes.has(name))
|
|
103
91
|
continue;
|
|
104
92
|
for (const decl of declarations) {
|
|
105
|
-
if ('remove' in decl &&
|
|
93
|
+
if ('remove' in decl && isNeedToRemoveType(name)) {
|
|
106
94
|
decl.remove();
|
|
107
95
|
removedCount++;
|
|
108
96
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Maybe } from 'yummies/utils/types';
|
|
2
|
+
import type { FilterOption } from '../index.js';
|
|
3
|
+
export declare const unpackFilterOption: <TArgs extends any[]>(option: Maybe<FilterOption<(...args: TArgs) => boolean>>, argsToString: (...args: TArgs) => string, defaultReturnValue?: boolean) => ((...args: TArgs) => boolean);
|
|
4
|
+
//# sourceMappingURL=unpack-filter-option.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unpack-filter-option.d.ts","sourceRoot":"","sources":["../../../src/codegen/utils/unpack-filter-option.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,eAAO,MAAM,kBAAkB,GAAI,KAAK,SAAS,GAAG,EAAE,EACpD,QAAQ,KAAK,CAAC,YAAY,CAAC,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,CAAC,CAAC,EACxD,cAAc,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,MAAM,EACxC,qBAAoB,OAAc,KACjC,CAAC,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,CAqB9B,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const unpackFilterOption = (option, argsToString, defaultReturnValue = true) => {
|
|
2
|
+
if (typeof option === 'function') {
|
|
3
|
+
return option;
|
|
4
|
+
}
|
|
5
|
+
if (option == null) {
|
|
6
|
+
return () => defaultReturnValue;
|
|
7
|
+
}
|
|
8
|
+
const inputs = Array.isArray(option) ? option : [option];
|
|
9
|
+
return (...args) => inputs.some((input) => {
|
|
10
|
+
const str = argsToString(...args);
|
|
11
|
+
if (typeof input === 'string') {
|
|
12
|
+
return input === str;
|
|
13
|
+
}
|
|
14
|
+
return input.test(str);
|
|
15
|
+
});
|
|
16
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mobx-tanstack-query-api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.1",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"mobx",
|
|
6
6
|
"react-query",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"@types/lodash-es": "^4.17.12",
|
|
32
32
|
"http-status-code-types": "^0.0.2",
|
|
33
33
|
"jiti": "^2.5.1",
|
|
34
|
+
"cac": "^6.7.14",
|
|
34
35
|
"mobx-tanstack-query": "^6.4.0",
|
|
35
36
|
"swagger-typescript-api": "13.2.10",
|
|
36
37
|
"ts-morph": "^26.0.0",
|
|
@@ -45,7 +46,6 @@
|
|
|
45
46
|
"@types/node": "^20.17.11",
|
|
46
47
|
"@vitejs/plugin-react-swc": "^3.7.2",
|
|
47
48
|
"@vitest/coverage-istanbul": "^3.2.4",
|
|
48
|
-
"cac": "^6.7.14",
|
|
49
49
|
"commitfmt": "^1.0.0",
|
|
50
50
|
"js2me-biome-config": "^1.0.5",
|
|
51
51
|
"js2me-exports-post-build-script": "^5.0.1",
|
|
@@ -148,6 +148,11 @@
|
|
|
148
148
|
"default": "./codegen/utils/remove-unused-types.js",
|
|
149
149
|
"types": "./codegen/utils/remove-unused-types.d.ts"
|
|
150
150
|
},
|
|
151
|
+
"./codegen/utils/unpack-filter-option": {
|
|
152
|
+
"import": "./codegen/utils/unpack-filter-option.js",
|
|
153
|
+
"default": "./codegen/utils/unpack-filter-option.js",
|
|
154
|
+
"types": "./codegen/utils/unpack-filter-option.d.ts"
|
|
155
|
+
},
|
|
151
156
|
".": {
|
|
152
157
|
"import": "./index.js",
|
|
153
158
|
"default": "./index.js",
|