mobx-tanstack-query-api 0.0.32 → 0.0.34

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.
@@ -1,4 +1,4 @@
1
1
  import { Maybe } from 'yummies/utils/types';
2
- import { GenerateApiParams } from '../codegen/index.js';
3
- export declare const defineConfig: (...configs: Maybe<GenerateApiParams | GenerateApiParams[]>[]) => GenerateApiParams[];
2
+ import { GenerateQueryApiParams } from '../codegen/index.js';
3
+ export declare const defineConfig: (...configs: Maybe<GenerateQueryApiParams | GenerateQueryApiParams[]>[]) => GenerateQueryApiParams[];
4
4
  //# sourceMappingURL=define-config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"define-config.d.ts","sourceRoot":"","sources":["../../src/cli/define-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,eAAO,MAAM,YAAY,eACX,KAAK,CAAC,iBAAiB,GAAG,iBAAiB,EAAE,CAAC,EAAE,KAC3D,iBAAiB,EAInB,CAAC"}
1
+ {"version":3,"file":"define-config.d.ts","sourceRoot":"","sources":["../../src/cli/define-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5C,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,eAAO,MAAM,YAAY,eACX,KAAK,CAAC,sBAAsB,GAAG,sBAAsB,EAAE,CAAC,EAAE,KACrE,sBAAsB,EAIxB,CAAC"}
@@ -8,15 +8,47 @@ export interface ImportFileParams {
8
8
  path: string;
9
9
  exportName: string;
10
10
  }
11
- export interface QueryApiParams {
11
+ export interface GenerateQueryApiParams {
12
+ output: string;
13
+ input: string | AnyObject;
12
14
  requestPathPrefix?: string;
13
15
  requestPathSuffix?: string;
14
16
  requestInfoPrefix?: string;
15
- outputType: 'request-info-per-file';
17
+ formatExportGroupName?: (groupName: string, utils: CodegenDataUtils) => string;
18
+ /**
19
+ * Group endpoints and collect it into object
20
+ */
21
+ groupBy?: ((route: ParsedRoute) => string) | `path-segment` | `path-segment-${number}` | `tag` | `tag-${number}`;
22
+ /**
23
+ * Collect all exports into single namespace
24
+ *
25
+ * Example:
26
+ * without namespace:
27
+ *
28
+ * export * from "./endpoints";
29
+ * export * from "./data-contracts";
30
+ *
31
+ * with namespace:
32
+ *
33
+ * export * as namespaceName from "./__exports"; // exports like above
34
+ *
35
+ *
36
+ * namespaceName.login.toMutation()
37
+ */
38
+ namespace?: string | ((utils: CodegenDataUtils) => string);
39
+ /**
40
+ * Example:
41
+ * operationId: 'getById'
42
+ * /api/v1/users/{userId} => /api/v1/users/1
43
+ *
44
+ * addPathSegmentToRouteName: 2 (users), 0 - api
45
+ *
46
+ * output endpoint instance name: `usersGetById` (pathSegments[2] + operationId)
47
+ */
16
48
  addPathSegmentToRouteName?: boolean | number;
17
- queryClient: 'builtin' | ImportFileParams;
18
- endpoint: 'builtin' | ImportFileParams;
19
- httpClient: 'builtin' | ImportFileParams;
49
+ queryClient?: 'builtin' | ImportFileParams;
50
+ endpoint?: 'builtin' | ImportFileParams;
51
+ httpClient?: 'builtin' | ImportFileParams;
20
52
  getEndpointMeta?: (route: ParsedRoute, utils: CodegenDataUtils) => {
21
53
  typeName: string;
22
54
  importTypePath: string;
@@ -25,11 +57,9 @@ export interface QueryApiParams {
25
57
  getRequestMeta?: (route: ParsedRoute, utils: CodegenDataUtils) => {
26
58
  tmplData: string;
27
59
  };
60
+ requestOptions?: GenerateApiParamsFromSwagger['requestOptions'];
61
+ otherCodegenParams?: Omit<GenerateApiParamsFromSwagger, 'requestOptions' | 'output' | 'moduleNameFirstTag' | 'moduleNameIndex' | 'url' | 'input' | 'spec'>;
28
62
  }
29
- export type AllImportFileParams = Record<KeyOfByValue<Required<QueryApiParams>, 'builtin' | ImportFileParams>, ImportFileParams>;
30
- export type GenerateApiParams = Omit<GenerateApiParamsFromSwagger, 'output' | 'moduleNameFirstTag' | 'moduleNameIndex' | 'url' | 'input' | 'spec'> & {
31
- output: string;
32
- input: string | AnyObject;
33
- } & QueryApiParams;
34
- export declare const generateApi: (inputParams: GenerateApiParams) => Promise<void>;
63
+ export type AllImportFileParams = Record<KeyOfByValue<Required<GenerateQueryApiParams>, 'builtin' | ImportFileParams>, ImportFileParams>;
64
+ export declare const generateApi: (params: GenerateQueryApiParams | GenerateQueryApiParams[]) => Promise<void>;
35
65
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/codegen/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,IAAI,4BAA4B,EACjD,WAAW,EAEZ,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAa9D,MAAM,MAAM,cAAc,GAAG,UAAU,CACrC,OAAO,CACL,QAAQ,CAAC,OAAO,CAAC,4BAA4B,EAAE;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC,OAAO,CAAC,CAAC,EAC3E,SAAS,CACV,CAAC,QAAQ,CAAC,CACZ,CAAC,CAAC,CAAC,CAAC;AAEL,MAAM,MAAM,gBAAgB,GAAG,UAAU,CACvC,cAAc,CAAC,uBAAuB,CAAC,CACxC,CAAC,OAAO,CAAC,CAAC;AAEX,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,UAAU,EAAE,uBAAuB,CAAC;IACpC,yBAAyB,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAE7C,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AAE,MAAM,CAAC;QACvB,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;IACF,cAAc,CAAC,EAAE,CACf,KAAK,EAAE,WAAW,EAClB,KAAK,EAAE,gBAAgB,KACpB;QACH,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;IAEF,cAAc,CAAC,EAAE,4BAA4B,CAAC,gBAAgB,CAAC,CAAC;IAEhE,kBAAkB,CAAC,EAAE,IAAI,CACvB,4BAA4B,EAC1B,gBAAgB,GAChB,QAAQ,GACR,oBAAoB,GACpB,iBAAiB,GACjB,KAAK,GACL,OAAO,GACP,MAAM,CACT,CAAC;CACH;AAED,MAAM,MAAM,mBAAmB,GAAG,MAAM,CACtC,YAAY,CAAC,QAAQ,CAAC,sBAAsB,CAAC,EAAE,SAAS,GAAG,gBAAgB,CAAC,EAC5E,gBAAgB,CACjB,CAAC;AAEF,eAAO,MAAM,WAAW,WACd,sBAAsB,GAAG,sBAAsB,EAAE,KACxD,OAAO,CAAC,IAAI,CAgXd,CAAC"}
package/codegen/index.js CHANGED
@@ -1,40 +1,43 @@
1
1
  import { generateApi as generateApiFromSwagger, } from 'swagger-typescript-api';
2
2
  import path from 'node:path';
3
3
  import { fileURLToPath } from 'node:url';
4
- import { dataContractsTmpl } from './templates/data-contracts.tmpl.js';
4
+ import { LINTERS_IGNORE } from './templates/constants.js';
5
+ import { dataContractsFileTmpl } from './templates/data-contracts-file.tmpl.js';
5
6
  import { indexTsForRequestPerFileTmpl } from './templates/index-ts-for-request-per-file.tmpl.js';
6
7
  import { requestInfoPerFileTmpl } from './templates/request-info-per-file.tmpl.js';
7
8
  const __filename = fileURLToPath(import.meta.url);
8
9
  const __dirname = path.dirname(__filename);
9
- export const generateApi = async (inputParams) => {
10
- const { output, input, ...params } = inputParams;
10
+ export const generateApi = async (params) => {
11
+ if (Array.isArray(params)) {
12
+ await Promise.all(params.map((param) => generateApi(param)));
13
+ return;
14
+ }
11
15
  const importFileParams = {
12
- queryClient: typeof inputParams.queryClient === 'string'
16
+ queryClient: !params.queryClient || typeof params.queryClient === 'string'
13
17
  ? {
14
18
  exportName: 'queryClient',
15
19
  path: 'mobx-tanstack-query-api/builtin',
16
20
  }
17
- : inputParams.queryClient,
18
- endpoint: typeof inputParams.endpoint === 'string'
21
+ : params.queryClient,
22
+ endpoint: !params.endpoint || typeof params.endpoint === 'string'
19
23
  ? {
20
24
  exportName: 'Endpoint',
21
25
  path: 'mobx-tanstack-query-api',
22
26
  }
23
- : inputParams.endpoint,
24
- httpClient: typeof inputParams.httpClient === 'string'
27
+ : params.endpoint,
28
+ httpClient: !params.httpClient || typeof params.httpClient === 'string'
25
29
  ? {
26
30
  exportName: 'http',
27
31
  path: 'mobx-tanstack-query-api/builtin',
28
32
  }
29
- : inputParams.httpClient,
33
+ : params.httpClient,
30
34
  };
31
35
  const paths = {
32
36
  templates: path.resolve(__dirname, 'templates'),
33
37
  requestInfoClass: path.resolve(__dirname, 'templates/request-info-class.ejs'),
34
38
  httpClient: path.resolve(__dirname, 'templates/http-client.ejs'),
35
39
  createRequestInfoInstance: path.resolve(__dirname, 'templates/create-request-info-instance.ejs'),
36
- outputDir: output,
37
- outputEndpoints: path.resolve(output, 'endpoints'),
40
+ outputDir: path.resolve(process.cwd(), params.output),
38
41
  };
39
42
  const codegenParams = {
40
43
  httpClientType: 'fetch',
@@ -59,19 +62,20 @@ export const generateApi = async (inputParams) => {
59
62
  ...constructs,
60
63
  object: () => `Record<string, any>`,
61
64
  float: () => `number`,
62
- ...params?.primitiveTypeConstructs?.(constructs),
65
+ ...params.otherCodegenParams?.primitiveTypeConstructs?.(constructs),
63
66
  };
64
67
  },
65
- ...params,
68
+ requestOptions: params.requestOptions,
69
+ ...params.otherCodegenParams,
66
70
  };
67
71
  let codegenProcess;
68
72
  const inputData = {};
69
- if (typeof input === 'string') {
70
- inputData.input = input;
71
- inputData.url = input;
73
+ if (typeof params.input === 'string') {
74
+ inputData.input = params.input;
75
+ inputData.url = params.input;
72
76
  }
73
77
  else {
74
- inputData.spec = input;
78
+ inputData.spec = params.input;
75
79
  }
76
80
  const generated = await generateApiFromSwagger({
77
81
  ...codegenParams,
@@ -89,10 +93,10 @@ export const generateApi = async (inputParams) => {
89
93
  },
90
94
  onFormatRouteName: (routeInfo, usageRouteName) => {
91
95
  let formattedRouteName = usageRouteName;
92
- if (inputParams.addPathSegmentToRouteName === true ||
93
- typeof inputParams.addPathSegmentToRouteName === 'number') {
94
- const pathSegmentForSuffix = typeof inputParams.addPathSegmentToRouteName === 'number'
95
- ? inputParams.addPathSegmentToRouteName
96
+ if (params.addPathSegmentToRouteName === true ||
97
+ typeof params.addPathSegmentToRouteName === 'number') {
98
+ const pathSegmentForSuffix = typeof params.addPathSegmentToRouteName === 'number'
99
+ ? params.addPathSegmentToRouteName
96
100
  : 0;
97
101
  const pathSegments = routeInfo.route.split('/').filter(Boolean);
98
102
  const { _ } = codegenProcess.getRenderTemplateData().utils;
@@ -105,41 +109,138 @@ export const generateApi = async (inputParams) => {
105
109
  const utils = codegenProcess.getRenderTemplateData().utils;
106
110
  const { _ } = utils;
107
111
  const codegenFs = codegenProcess.fileSystem;
108
- codegenFs.cleanDir(output);
109
- codegenFs.createDir(output);
110
- codegenFs.createDir(paths.outputEndpoints);
112
+ codegenFs.cleanDir(params.output);
113
+ codegenFs.createDir(params.output);
111
114
  const allRoutes = Object.values(generated.configuration.routes)
112
115
  .flat()
113
116
  .flatMap((routeGroup) => 'routes' in routeGroup ? routeGroup.routes : routeGroup);
114
117
  const reservedDataContractNamesMap = new Map();
115
- const fileNamesWithRequestInfo = [];
116
- for await (const route of allRoutes) {
117
- const { content: requestInfoPerFileContent, reservedDataContractNames } = await requestInfoPerFileTmpl({
118
- ...generated,
119
- route,
120
- apiParams: inputParams,
121
- codegenProcess,
122
- importFileParams,
123
- utils,
124
- });
125
- reservedDataContractNames.forEach((name) => {
126
- reservedDataContractNamesMap.set(name, (reservedDataContractNamesMap.get(name) ?? 0) + 1);
127
- });
128
- const fileName = `${_.kebabCase(route.routeName.usage)}.ts`;
129
- fileNamesWithRequestInfo.push(fileName);
118
+ const collectedExportFiles = [];
119
+ if (params.groupBy == null) {
120
+ collectedExportFiles.push('endpoints');
121
+ // #region кодогенерация 1 эндпоинт - 1 файл без группировки
122
+ codegenFs.createDir(path.resolve(params.output, 'endpoints'));
123
+ const fileNamesWithRequestInfo = [];
124
+ for await (const route of allRoutes) {
125
+ const { content: requestInfoPerFileContent, reservedDataContractNames } = await requestInfoPerFileTmpl({
126
+ ...generated,
127
+ route,
128
+ apiParams: params,
129
+ codegenProcess,
130
+ importFileParams,
131
+ utils,
132
+ relativePathDataContracts: '../data-contracts',
133
+ });
134
+ reservedDataContractNames.forEach((name) => {
135
+ reservedDataContractNamesMap.set(name, (reservedDataContractNamesMap.get(name) ?? 0) + 1);
136
+ });
137
+ const fileName = `${_.kebabCase(route.routeName.usage)}.ts`;
138
+ fileNamesWithRequestInfo.push(fileName);
139
+ codegenFs.createFile({
140
+ path: path.resolve(params.output, 'endpoints'),
141
+ fileName,
142
+ withPrefix: false,
143
+ content: requestInfoPerFileContent,
144
+ });
145
+ }
130
146
  codegenFs.createFile({
131
- path: paths.outputEndpoints,
132
- fileName,
147
+ path: path.resolve(params.output, 'endpoints'),
148
+ fileName: 'index.ts',
133
149
  withPrefix: false,
134
- content: requestInfoPerFileContent,
150
+ content: await indexTsForRequestPerFileTmpl({
151
+ ...generated,
152
+ apiParams: params,
153
+ codegenProcess,
154
+ generatedRequestFileNames: fileNamesWithRequestInfo,
155
+ }),
135
156
  });
157
+ // #endregion
158
+ }
159
+ else {
160
+ // #region кодогенерация с группировкой
161
+ // #region разбиение роутов по группам
162
+ const groupsMap = new Map();
163
+ allRoutes.forEach((route) => {
164
+ let group;
165
+ if (typeof params.groupBy === 'function') {
166
+ group = params.groupBy(route);
167
+ }
168
+ else if (params.groupBy?.includes('path-segment')) {
169
+ const segmentIndex = +params.groupBy.replaceAll(/path-segment-?/g, '') || 0;
170
+ group =
171
+ route.request.path?.split('/')?.filter(Boolean)?.[segmentIndex] || undefined;
172
+ }
173
+ else if (params.groupBy?.includes('tag')) {
174
+ const tagIndex = +params.groupBy.replaceAll(/tag-?/g, '') || 0;
175
+ group = route.raw?.tags?.[tagIndex] ?? undefined;
176
+ }
177
+ if (group == null) {
178
+ group = 'other';
179
+ }
180
+ if (!groupsMap.has(group)) {
181
+ groupsMap.set(group, []);
182
+ }
183
+ groupsMap.get(group)?.push(route);
184
+ });
185
+ // #endregion
186
+ for await (const [groupName, routes] of groupsMap) {
187
+ const fileNamesWithRequestInfo = [];
188
+ codegenFs.createDir(path.resolve(params.output, _.kebabCase(groupName)));
189
+ codegenFs.createDir(path.resolve(params.output, _.kebabCase(groupName), 'endpoints'));
190
+ for await (const route of routes) {
191
+ const { content: requestInfoPerFileContent, reservedDataContractNames, } = await requestInfoPerFileTmpl({
192
+ ...generated,
193
+ route,
194
+ apiParams: params,
195
+ codegenProcess,
196
+ importFileParams,
197
+ utils,
198
+ relativePathDataContracts: '../../data-contracts',
199
+ });
200
+ reservedDataContractNames.forEach((name) => {
201
+ reservedDataContractNamesMap.set(name, (reservedDataContractNamesMap.get(name) ?? 0) + 1);
202
+ });
203
+ const fileName = `${_.kebabCase(route.routeName.usage)}.ts`;
204
+ fileNamesWithRequestInfo.push(fileName);
205
+ codegenFs.createFile({
206
+ path: path.resolve(params.output, _.kebabCase(groupName), 'endpoints'),
207
+ fileName,
208
+ withPrefix: false,
209
+ content: requestInfoPerFileContent,
210
+ });
211
+ }
212
+ const exportGroupName = params.formatExportGroupName
213
+ ? params.formatExportGroupName(_.camelCase(groupName), utils)
214
+ : _.camelCase(groupName);
215
+ codegenFs.createFile({
216
+ path: path.resolve(params.output, _.kebabCase(groupName)),
217
+ fileName: 'index.ts',
218
+ withPrefix: false,
219
+ content: `${LINTERS_IGNORE}
220
+ export * as ${exportGroupName} from './endpoints';
221
+ `,
222
+ });
223
+ codegenFs.createFile({
224
+ path: path.resolve(params.output, _.kebabCase(groupName), 'endpoints'),
225
+ fileName: 'index.ts',
226
+ withPrefix: false,
227
+ content: await indexTsForRequestPerFileTmpl({
228
+ ...generated,
229
+ apiParams: params,
230
+ codegenProcess,
231
+ generatedRequestFileNames: fileNamesWithRequestInfo,
232
+ }),
233
+ });
234
+ collectedExportFiles.push(_.kebabCase(groupName));
235
+ }
236
+ // #endregion
136
237
  }
137
238
  const excludedDataContractNames = Array.from(reservedDataContractNamesMap.entries())
138
239
  .filter(([_, count]) => count === 1)
139
240
  .map(([name]) => name);
140
- const dataContractsContent = await dataContractsTmpl({
241
+ const dataContractsContent = await dataContractsFileTmpl({
141
242
  ...generated,
142
- apiParams: inputParams,
243
+ apiParams: params,
143
244
  codegenProcess,
144
245
  excludedDataContractNames,
145
246
  });
@@ -149,26 +250,37 @@ export const generateApi = async (inputParams) => {
149
250
  withPrefix: false,
150
251
  content: dataContractsContent,
151
252
  });
152
- codegenFs.createFile({
153
- path: paths.outputEndpoints,
154
- fileName: 'index.ts',
155
- withPrefix: false,
156
- content: await indexTsForRequestPerFileTmpl({
157
- ...generated,
158
- apiParams: inputParams,
159
- codegenProcess,
160
- generatedRequestFileNames: fileNamesWithRequestInfo,
161
- }),
162
- });
163
- codegenFs.createFile({
164
- path: paths.outputDir,
165
- fileName: 'index.ts',
166
- withPrefix: false,
167
- content: `
168
- /* eslint-disable */
169
- /* tslint:disable */
253
+ if (params.namespace) {
254
+ const namespace = typeof params.namespace === 'function'
255
+ ? params.namespace(utils)
256
+ : params.namespace;
257
+ codegenFs.createFile({
258
+ path: paths.outputDir,
259
+ fileName: '__exports.ts',
260
+ withPrefix: false,
261
+ content: `${LINTERS_IGNORE}
170
262
  export * from './data-contracts';
171
- export * from './endpoints';
263
+ ${collectedExportFiles.map((fileName) => `export * from './${fileName}';`).join('\n')}
264
+ `,
265
+ });
266
+ codegenFs.createFile({
267
+ path: paths.outputDir,
268
+ fileName: 'index.ts',
269
+ withPrefix: false,
270
+ content: `${LINTERS_IGNORE}
271
+ export * as ${namespace} from './__exports';
172
272
  `,
173
- });
273
+ });
274
+ }
275
+ else {
276
+ codegenFs.createFile({
277
+ path: paths.outputDir,
278
+ fileName: 'index.ts',
279
+ withPrefix: false,
280
+ content: `${LINTERS_IGNORE}
281
+ export * from './data-contracts';
282
+ ${collectedExportFiles.map((fileName) => `export * from './${fileName}';`).join('\n')}
283
+ `,
284
+ });
285
+ }
174
286
  };
@@ -0,0 +1,2 @@
1
+ export declare const LINTERS_IGNORE = "/* eslint-disable */\n/* tslint:disable */";
2
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/codegen/templates/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,+CACN,CAAC"}
@@ -0,0 +1,2 @@
1
+ export const LINTERS_IGNORE = `/* eslint-disable */
2
+ /* tslint:disable */`;
@@ -0,0 +1,10 @@
1
+ import { GenerateApiConfiguration, GenerateApiOutput } from 'swagger-typescript-api';
2
+ import type { CodegenProcess, GenerateQueryApiParams } from '../index.js';
3
+ export interface DataContractsTmplParams extends GenerateApiOutput {
4
+ configuration: GenerateApiConfiguration;
5
+ apiParams: GenerateQueryApiParams;
6
+ codegenProcess: CodegenProcess;
7
+ excludedDataContractNames?: string[];
8
+ }
9
+ export declare const dataContractsFileTmpl: ({ configuration, formatTSContent, excludedDataContractNames, }: DataContractsTmplParams) => Promise<string>;
10
+ //# sourceMappingURL=data-contracts-file.tmpl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-contracts-file.tmpl.d.ts","sourceRoot":"","sources":["../../../src/codegen/templates/data-contracts-file.tmpl.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,iBAAiB,EAClB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAK1E,MAAM,WAAW,uBAAwB,SAAQ,iBAAiB;IAChE,aAAa,EAAE,wBAAwB,CAAC;IACxC,SAAS,EAAE,sBAAsB,CAAC;IAClC,cAAc,EAAE,cAAc,CAAC;IAC/B,yBAAyB,CAAC,EAAE,MAAM,EAAE,CAAC;CACtC;AAED,eAAO,MAAM,qBAAqB,mEAI/B,uBAAuB,oBA6BzB,CAAC"}
@@ -1,5 +1,6 @@
1
+ import { LINTERS_IGNORE } from './constants.js';
1
2
  import { dataContractTmpl } from './data-contract.tmpl.js';
2
- export const dataContractsTmpl = async ({ configuration, formatTSContent, excludedDataContractNames, }) => {
3
+ export const dataContractsFileTmpl = async ({ configuration, formatTSContent, excludedDataContractNames, }) => {
3
4
  const { config, modelTypes } = configuration;
4
5
  const contractDefinitions = [];
5
6
  if (config.internalTemplateOptions?.addUtilRequiredKeysType) {
@@ -15,8 +16,7 @@ export const dataContractsTmpl = async ({ configuration, formatTSContent, exclud
15
16
  addExportKeyword: true,
16
17
  }));
17
18
  }
18
- return await formatTSContent(`/* eslint-disable */
19
- /* tslint:disable */
19
+ return await formatTSContent(`${LINTERS_IGNORE}
20
20
 
21
21
  ${contractDefinitions.join('\n\n')}
22
22
  `);
@@ -1,8 +1,8 @@
1
1
  import { GenerateApiConfiguration, GenerateApiOutput } from 'swagger-typescript-api';
2
- import { CodegenProcess, QueryApiParams } from '../index.js';
2
+ import { CodegenProcess, GenerateQueryApiParams } from '../index.js';
3
3
  export interface IndexTsForRequestPerFileTmplParams extends GenerateApiOutput {
4
4
  configuration: GenerateApiConfiguration;
5
- apiParams: QueryApiParams;
5
+ apiParams: GenerateQueryApiParams;
6
6
  codegenProcess: CodegenProcess;
7
7
  generatedRequestFileNames: string[];
8
8
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index-ts-for-request-per-file.tmpl.d.ts","sourceRoot":"","sources":["../../../src/codegen/templates/index-ts-for-request-per-file.tmpl.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,iBAAiB,EAClB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7D,MAAM,WAAW,kCAAmC,SAAQ,iBAAiB;IAC3E,aAAa,EAAE,wBAAwB,CAAC;IACxC,SAAS,EAAE,cAAc,CAAC;IAC1B,cAAc,EAAE,cAAc,CAAC;IAC/B,yBAAyB,EAAE,MAAM,EAAE,CAAC;CACrC;AAED,eAAO,MAAM,4BAA4B,mCAEtC,kCAAkC,oBAKpC,CAAC"}
1
+ {"version":3,"file":"index-ts-for-request-per-file.tmpl.d.ts","sourceRoot":"","sources":["../../../src/codegen/templates/index-ts-for-request-per-file.tmpl.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,iBAAiB,EAClB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAIrE,MAAM,WAAW,kCAAmC,SAAQ,iBAAiB;IAC3E,aAAa,EAAE,wBAAwB,CAAC;IACxC,SAAS,EAAE,sBAAsB,CAAC;IAClC,cAAc,EAAE,cAAc,CAAC;IAC/B,yBAAyB,EAAE,MAAM,EAAE,CAAC;CACrC;AAED,eAAO,MAAM,4BAA4B,mCAEtC,kCAAkC,oBAIpC,CAAC"}
@@ -1,6 +1,6 @@
1
+ import { LINTERS_IGNORE } from './constants.js';
1
2
  export const indexTsForRequestPerFileTmpl = async ({ generatedRequestFileNames, }) => {
2
- return `/* eslint-disable */
3
- /* tslint:disable */
3
+ return `${LINTERS_IGNORE}
4
4
  ${generatedRequestFileNames.map((fileName) => `export * from './${fileName.replace('.ts', '')}';`).join('\n')}
5
5
  `;
6
6
  };
@@ -1,9 +1,9 @@
1
1
  import { GenerateApiConfiguration, ParsedRoute } from 'swagger-typescript-api';
2
- import type { AllImportFileParams, CodegenDataUtils, QueryApiParams } from '../index.js';
2
+ import type { AllImportFileParams, CodegenDataUtils, GenerateQueryApiParams } from '../index.js';
3
3
  export interface NewRequestInfoTmplParams {
4
4
  route: ParsedRoute;
5
5
  configuration: GenerateApiConfiguration;
6
- apiParams: QueryApiParams;
6
+ apiParams: GenerateQueryApiParams;
7
7
  importFileParams: AllImportFileParams;
8
8
  utils: CodegenDataUtils;
9
9
  }
@@ -1 +1 @@
1
- {"version":3,"file":"new-request-info.tmpl.d.ts","sourceRoot":"","sources":["../../../src/codegen/templates/new-request-info.tmpl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAG/E,OAAO,KAAK,EACV,mBAAmB,EACnB,gBAAgB,EAChB,cAAc,EACf,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,wBAAwB;IACvC,KAAK,EAAE,WAAW,CAAC;IACnB,aAAa,EAAE,wBAAwB,CAAC;IACxC,SAAS,EAAE,cAAc,CAAC;IAC1B,gBAAgB,EAAE,mBAAmB,CAAC;IACtC,KAAK,EAAE,gBAAgB,CAAC;CACzB;AAiBD,eAAO,MAAM,kBAAkB,mDAK5B,wBAAwB;;;CAqO1B,CAAC"}
1
+ {"version":3,"file":"new-request-info.tmpl.d.ts","sourceRoot":"","sources":["../../../src/codegen/templates/new-request-info.tmpl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAG/E,OAAO,KAAK,EACV,mBAAmB,EACnB,gBAAgB,EAChB,sBAAsB,EACvB,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,wBAAwB;IACvC,KAAK,EAAE,WAAW,CAAC;IACnB,aAAa,EAAE,wBAAwB,CAAC;IACxC,SAAS,EAAE,sBAAsB,CAAC;IAClC,gBAAgB,EAAE,mBAAmB,CAAC;IACtC,KAAK,EAAE,gBAAgB,CAAC;CACzB;AAiBD,eAAO,MAAM,kBAAkB,mDAK5B,wBAAwB;;;CAqO1B,CAAC"}
@@ -1,9 +1,9 @@
1
1
  import { ParsedRoute, GenerateApiConfiguration } from 'swagger-typescript-api';
2
- import { QueryApiParams } from '../index.js';
2
+ import { GenerateQueryApiParams } from '../index.js';
3
3
  export interface RequestInfoJSDocTmplParams {
4
4
  route: ParsedRoute;
5
5
  configuration: GenerateApiConfiguration;
6
- apiParams: QueryApiParams;
6
+ apiParams: GenerateQueryApiParams;
7
7
  offset?: number;
8
8
  }
9
9
  export declare const requestInfoJSDocTmpl: ({ route, configuration, offset, }: RequestInfoJSDocTmplParams) => string;
@@ -1 +1 @@
1
- {"version":3,"file":"request-info-jsdoc.tmpl.d.ts","sourceRoot":"","sources":["../../../src/codegen/templates/request-info-jsdoc.tmpl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAG/E,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,MAAM,WAAW,0BAA0B;IACzC,KAAK,EAAE,WAAW,CAAC;IACnB,aAAa,EAAE,wBAAwB,CAAC;IACxC,SAAS,EAAE,cAAc,CAAC;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,eAAO,MAAM,oBAAoB,sCAI9B,0BAA0B,WAkH5B,CAAC"}
1
+ {"version":3,"file":"request-info-jsdoc.tmpl.d.ts","sourceRoot":"","sources":["../../../src/codegen/templates/request-info-jsdoc.tmpl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAG/E,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAErD,MAAM,WAAW,0BAA0B;IACzC,KAAK,EAAE,WAAW,CAAC;IACnB,aAAa,EAAE,wBAAwB,CAAC;IACxC,SAAS,EAAE,sBAAsB,CAAC;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,eAAO,MAAM,oBAAoB,sCAI9B,0BAA0B,WAkH5B,CAAC"}
@@ -1,14 +1,15 @@
1
1
  import { ParsedRoute, GenerateApiConfiguration, GenerateApiOutput } from 'swagger-typescript-api';
2
- import type { AllImportFileParams, CodegenDataUtils, CodegenProcess, QueryApiParams } from '../index.js';
2
+ import type { AllImportFileParams, CodegenDataUtils, CodegenProcess, GenerateQueryApiParams } from '../index.js';
3
3
  export interface RequestInfoPerFileTmplParams extends GenerateApiOutput {
4
4
  route: ParsedRoute;
5
5
  configuration: GenerateApiConfiguration;
6
- apiParams: QueryApiParams;
6
+ apiParams: GenerateQueryApiParams;
7
7
  codegenProcess: CodegenProcess;
8
8
  importFileParams: AllImportFileParams;
9
9
  utils: CodegenDataUtils;
10
+ relativePathDataContracts: string;
10
11
  }
11
- export declare const requestInfoPerFileTmpl: ({ route, configuration, apiParams, formatTSContent, importFileParams, utils, }: RequestInfoPerFileTmplParams) => Promise<{
12
+ export declare const requestInfoPerFileTmpl: ({ route, configuration, apiParams, formatTSContent, importFileParams, utils, relativePathDataContracts, }: RequestInfoPerFileTmplParams) => Promise<{
12
13
  reservedDataContractNames: string[];
13
14
  content: string;
14
15
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"request-info-per-file.tmpl.d.ts","sourceRoot":"","sources":["../../../src/codegen/templates/request-info-per-file.tmpl.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EACX,wBAAwB,EACxB,iBAAiB,EAClB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EACV,mBAAmB,EACnB,gBAAgB,EAChB,cAAc,EACd,cAAc,EACf,MAAM,aAAa,CAAC;AAMrB,MAAM,WAAW,4BAA6B,SAAQ,iBAAiB;IACrE,KAAK,EAAE,WAAW,CAAC;IACnB,aAAa,EAAE,wBAAwB,CAAC;IACxC,SAAS,EAAE,cAAc,CAAC;IAC1B,cAAc,EAAE,cAAc,CAAC;IAC/B,gBAAgB,EAAE,mBAAmB,CAAC;IACtC,KAAK,EAAE,gBAAgB,CAAC;CACzB;AAED,eAAO,MAAM,sBAAsB,mFAOhC,4BAA4B;;;EA8E9B,CAAC"}
1
+ {"version":3,"file":"request-info-per-file.tmpl.d.ts","sourceRoot":"","sources":["../../../src/codegen/templates/request-info-per-file.tmpl.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EACX,wBAAwB,EACxB,iBAAiB,EAClB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EACV,mBAAmB,EACnB,gBAAgB,EAChB,cAAc,EACd,sBAAsB,EACvB,MAAM,aAAa,CAAC;AAOrB,MAAM,WAAW,4BAA6B,SAAQ,iBAAiB;IACrE,KAAK,EAAE,WAAW,CAAC;IACnB,aAAa,EAAE,wBAAwB,CAAC;IACxC,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;CACnC;AAED,eAAO,MAAM,sBAAsB,8GAQhC,4BAA4B;;;EA6E9B,CAAC"}
@@ -1,7 +1,8 @@
1
+ import { LINTERS_IGNORE } from './constants.js';
1
2
  import { dataContractTmpl } from './data-contract.tmpl.js';
2
3
  import { newRequestInfoTmpl } from './new-request-info.tmpl.js';
3
4
  import { requestInfoJSDocTmpl } from './request-info-jsdoc.tmpl.js';
4
- export const requestInfoPerFileTmpl = async ({ route, configuration, apiParams, formatTSContent, importFileParams, utils, }) => {
5
+ export const requestInfoPerFileTmpl = async ({ route, configuration, apiParams, formatTSContent, importFileParams, utils, relativePathDataContracts, }) => {
5
6
  const { _ } = utils;
6
7
  const { content: requestInfoInstanceContent, reservedDataContractNames } = newRequestInfoTmpl({
7
8
  route,
@@ -19,8 +20,7 @@ export const requestInfoPerFileTmpl = async ({ route, configuration, apiParams,
19
20
  });
20
21
  return {
21
22
  reservedDataContractNames: dataContractNamesInThisFile,
22
- content: await formatTSContent(`/* eslint-disable */
23
- /* tslint:disable */
23
+ content: await formatTSContent(`${LINTERS_IGNORE}
24
24
  import { RequestParams } from "mobx-tanstack-query-api";
25
25
  import { ${importFileParams.endpoint.exportName} } from "${importFileParams.endpoint.path}";
26
26
  import { ${importFileParams.httpClient.exportName} } from "${importFileParams.httpClient.path}";
@@ -30,7 +30,7 @@ export const requestInfoPerFileTmpl = async ({ route, configuration, apiParams,
30
30
  import { ${configuration.modelTypes
31
31
  .map((it) => it.name)
32
32
  .filter((it) => !dataContractNamesInThisFile.includes(it))
33
- .join(', ')} } from "../data-contracts";
33
+ .join(', ')} } from "${relativePathDataContracts}";
34
34
  `
35
35
  : ''}
36
36
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mobx-tanstack-query-api",
3
- "version": "0.0.32",
3
+ "version": "0.0.34",
4
4
  "keywords": [],
5
5
  "author": "js2me",
6
6
  "license": "MIT",
@@ -22,7 +22,7 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "swagger-typescript-api": "13.0.23",
25
- "yummies": "^3.0.36"
25
+ "yummies": "^3.0.37"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@types/node": "^20.17.11",
@@ -62,15 +62,20 @@
62
62
  "default": "./codegen/index.js",
63
63
  "types": "./codegen/index.d.ts"
64
64
  },
65
+ "./codegen/templates/constants": {
66
+ "import": "./codegen/templates/constants.js",
67
+ "default": "./codegen/templates/constants.js",
68
+ "types": "./codegen/templates/constants.d.ts"
69
+ },
65
70
  "./codegen/templates/data-contract.tmpl": {
66
71
  "import": "./codegen/templates/data-contract.tmpl.js",
67
72
  "default": "./codegen/templates/data-contract.tmpl.js",
68
73
  "types": "./codegen/templates/data-contract.tmpl.d.ts"
69
74
  },
70
- "./codegen/templates/data-contracts.tmpl": {
71
- "import": "./codegen/templates/data-contracts.tmpl.js",
72
- "default": "./codegen/templates/data-contracts.tmpl.js",
73
- "types": "./codegen/templates/data-contracts.tmpl.d.ts"
75
+ "./codegen/templates/data-contracts-file.tmpl": {
76
+ "import": "./codegen/templates/data-contracts-file.tmpl.js",
77
+ "default": "./codegen/templates/data-contracts-file.tmpl.js",
78
+ "types": "./codegen/templates/data-contracts-file.tmpl.d.ts"
74
79
  },
75
80
  "./codegen/templates/index-ts-for-request-per-file.tmpl": {
76
81
  "import": "./codegen/templates/index-ts-for-request-per-file.tmpl.js",
@@ -1,10 +0,0 @@
1
- import { GenerateApiConfiguration, GenerateApiOutput } from 'swagger-typescript-api';
2
- import type { CodegenProcess, QueryApiParams } from '../index.js';
3
- export interface DataContractsTmplParams extends GenerateApiOutput {
4
- configuration: GenerateApiConfiguration;
5
- apiParams: QueryApiParams;
6
- codegenProcess: CodegenProcess;
7
- excludedDataContractNames?: string[];
8
- }
9
- export declare const dataContractsTmpl: ({ configuration, formatTSContent, excludedDataContractNames, }: DataContractsTmplParams) => Promise<string>;
10
- //# sourceMappingURL=data-contracts.tmpl.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"data-contracts.tmpl.d.ts","sourceRoot":"","sources":["../../../src/codegen/templates/data-contracts.tmpl.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,iBAAiB,EAClB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAIlE,MAAM,WAAW,uBAAwB,SAAQ,iBAAiB;IAChE,aAAa,EAAE,wBAAwB,CAAC;IACxC,SAAS,EAAE,cAAc,CAAC;IAC1B,cAAc,EAAE,cAAc,CAAC;IAC/B,yBAAyB,CAAC,EAAE,MAAM,EAAE,CAAC;CACtC;AAED,eAAO,MAAM,iBAAiB,mEAI3B,uBAAuB,oBA8BzB,CAAC"}