swagger-typescript-api 13.2.7 → 13.2.9
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 +54 -0
- package/dist/cli.cjs +1 -1
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.d.cts +2 -1
- package/dist/cli.d.ts +2 -1
- package/dist/cli.js +2 -1
- package/dist/cli.js.map +1 -1
- package/dist/lib.cjs +1 -1
- package/dist/lib.d.cts +205 -16
- package/dist/lib.d.ts +205 -16
- package/dist/lib.js +1 -1
- package/dist/{src-DYNtMxii.cjs → src-B-cU8h_Y.cjs} +41 -29
- package/dist/src-B-cU8h_Y.cjs.map +1 -0
- package/dist/{src-BgBqKQNC.js → src-BGOGeWR6.js} +105 -100
- package/dist/src-BGOGeWR6.js.map +1 -0
- package/package.json +13 -13
- package/templates/base/http-clients/fetch-http-client.ejs +9 -4
- package/templates/base/route-type.ejs +2 -1
- package/templates/default/procedure-call.ejs +3 -1
- package/templates/modular/procedure-call.ejs +4 -2
- package/dist/src-BgBqKQNC.js.map +0 -1
- package/dist/src-DYNtMxii.cjs.map +0 -1
|
@@ -1,20 +1,14 @@
|
|
|
1
1
|
import { __export } from "./chunk-Cl8Af3a2.js";
|
|
2
|
+
import * as module from "node:module";
|
|
2
3
|
import { consola } from "consola";
|
|
3
4
|
import lodash from "lodash";
|
|
4
|
-
import * as typescript$3 from "typescript";
|
|
5
|
-
import * as typescript$2 from "typescript";
|
|
6
|
-
import * as typescript$1 from "typescript";
|
|
7
5
|
import * as typescript from "typescript";
|
|
8
|
-
import * as path$3 from "node:path";
|
|
9
|
-
import * as path$2 from "node:path";
|
|
10
6
|
import * as path$1 from "node:path";
|
|
11
7
|
import path from "node:path";
|
|
12
8
|
import { Biome, Distribution } from "@biomejs/js-api";
|
|
13
|
-
import * as nanoid$1 from "nanoid";
|
|
14
9
|
import * as nanoid from "nanoid";
|
|
15
10
|
import * as yaml from "js-yaml";
|
|
16
11
|
import * as swagger2openapi from "swagger2openapi";
|
|
17
|
-
import * as url$2 from "node:url";
|
|
18
12
|
import * as url$1 from "node:url";
|
|
19
13
|
import url from "node:url";
|
|
20
14
|
import * as Eta from "eta";
|
|
@@ -29,11 +23,11 @@ var CodeFormatter = class {
|
|
|
29
23
|
removeUnusedImports = (content) => {
|
|
30
24
|
const tempFileName = "file.ts";
|
|
31
25
|
const host = new TsLanguageServiceHost(tempFileName, content);
|
|
32
|
-
const languageService = typescript
|
|
26
|
+
const languageService = typescript.createLanguageService(host);
|
|
33
27
|
const fileTextChanges = languageService.organizeImports({
|
|
34
28
|
type: "file",
|
|
35
29
|
fileName: tempFileName
|
|
36
|
-
}, { newLineCharacter: typescript
|
|
30
|
+
}, { newLineCharacter: typescript.sys.newLine }, void 0)[0];
|
|
37
31
|
if (fileTextChanges?.textChanges.length) return fileTextChanges.textChanges.reduceRight((content$1, { span, newText }) => `${content$1.slice(0, span.start)}${newText}${content$1.slice(span.start + span.length)}`, content);
|
|
38
32
|
return content;
|
|
39
33
|
};
|
|
@@ -44,8 +38,8 @@ var CodeFormatter = class {
|
|
|
44
38
|
files: { maxSize: Number.MAX_SAFE_INTEGER },
|
|
45
39
|
formatter: { indentStyle: "space" }
|
|
46
40
|
});
|
|
47
|
-
const formatted = biome.formatContent(biomeProject.projectKey, content, { filePath: path$
|
|
48
|
-
name: nanoid
|
|
41
|
+
const formatted = biome.formatContent(biomeProject.projectKey, content, { filePath: path$1.format({
|
|
42
|
+
name: nanoid.nanoid(),
|
|
49
43
|
ext: "ts"
|
|
50
44
|
}) });
|
|
51
45
|
return formatted.content;
|
|
@@ -63,11 +57,11 @@ var TsLanguageServiceHost = class {
|
|
|
63
57
|
constructor(fileName, content) {
|
|
64
58
|
this.fileName = fileName;
|
|
65
59
|
this.content = content;
|
|
66
|
-
const tsconfig = typescript
|
|
67
|
-
this.compilerOptions = tsconfig ? typescript
|
|
60
|
+
const tsconfig = typescript.findConfigFile(fileName, typescript.sys.fileExists);
|
|
61
|
+
this.compilerOptions = tsconfig ? typescript.convertCompilerOptionsFromJson(typescript.readConfigFile(tsconfig, typescript.sys.readFile).config.compilerOptions, "").options : typescript.getDefaultCompilerOptions();
|
|
68
62
|
}
|
|
69
63
|
getNewLine() {
|
|
70
|
-
return "newLine" in typescript
|
|
64
|
+
return "newLine" in typescript.sys ? typescript.sys.newLine : "\n";
|
|
71
65
|
}
|
|
72
66
|
getScriptFileNames() {
|
|
73
67
|
return [this.fileName];
|
|
@@ -76,23 +70,23 @@ var TsLanguageServiceHost = class {
|
|
|
76
70
|
return this.compilerOptions;
|
|
77
71
|
}
|
|
78
72
|
getDefaultLibFileName() {
|
|
79
|
-
return typescript
|
|
73
|
+
return typescript.getDefaultLibFileName(this.getCompilationSettings());
|
|
80
74
|
}
|
|
81
75
|
getCurrentDirectory() {
|
|
82
76
|
return process.cwd();
|
|
83
77
|
}
|
|
84
78
|
getScriptVersion() {
|
|
85
|
-
return typescript
|
|
79
|
+
return typescript.version;
|
|
86
80
|
}
|
|
87
81
|
getScriptSnapshot() {
|
|
88
|
-
return typescript
|
|
82
|
+
return typescript.ScriptSnapshot.fromString(this.content);
|
|
89
83
|
}
|
|
90
84
|
readFile(fileName, encoding) {
|
|
91
85
|
if (fileName === this.fileName) return this.content;
|
|
92
|
-
return typescript
|
|
86
|
+
return typescript.sys.readFile(fileName, encoding);
|
|
93
87
|
}
|
|
94
|
-
fileExists(path$
|
|
95
|
-
return typescript
|
|
88
|
+
fileExists(path$2) {
|
|
89
|
+
return typescript.sys.fileExists(path$2);
|
|
96
90
|
}
|
|
97
91
|
};
|
|
98
92
|
|
|
@@ -162,7 +156,7 @@ const getRandomInt = (min = 0, max = 1) => {
|
|
|
162
156
|
var ComponentTypeNameResolver = class extends NameResolver {
|
|
163
157
|
counter = 1;
|
|
164
158
|
fallbackNameCounter = 1;
|
|
165
|
-
countersByVariant = new Map();
|
|
159
|
+
countersByVariant = /* @__PURE__ */ new Map();
|
|
166
160
|
constructor(config, reservedNames) {
|
|
167
161
|
super(config, reservedNames, (variants) => {
|
|
168
162
|
const randomVariant = variants[getRandomInt(0, variants.length - 1)];
|
|
@@ -184,7 +178,7 @@ var ComponentTypeNameResolver = class extends NameResolver {
|
|
|
184
178
|
//#endregion
|
|
185
179
|
//#region package.json
|
|
186
180
|
var name = "swagger-typescript-api";
|
|
187
|
-
var version = "13.2.
|
|
181
|
+
var version = "13.2.9";
|
|
188
182
|
var description = "Generate the API client for Fetch or Axios from an OpenAPI Specification";
|
|
189
183
|
var homepage = "https://github.com/acacode/swagger-typescript-api";
|
|
190
184
|
var bugs = "https://github.com/acacode/swagger-typescript-api/issues";
|
|
@@ -204,7 +198,7 @@ var exports = { ".": {
|
|
|
204
198
|
}
|
|
205
199
|
} };
|
|
206
200
|
var main = "./dist/lib.cjs";
|
|
207
|
-
var module = "./dist/lib.js";
|
|
201
|
+
var module$1 = "./dist/lib.js";
|
|
208
202
|
var types = "./dist/lib.d.cts";
|
|
209
203
|
var bin = {
|
|
210
204
|
"sta": "./dist/cli.js",
|
|
@@ -224,10 +218,10 @@ var scripts = {
|
|
|
224
218
|
"typedoc": "typedoc"
|
|
225
219
|
};
|
|
226
220
|
var dependencies = {
|
|
227
|
-
"@biomejs/js-api": "
|
|
228
|
-
"@biomejs/wasm-nodejs": "2.
|
|
221
|
+
"@biomejs/js-api": "3.0.0",
|
|
222
|
+
"@biomejs/wasm-nodejs": "2.2.2",
|
|
229
223
|
"@types/swagger-schema-official": "^2.0.25",
|
|
230
|
-
"c12": "^3.0
|
|
224
|
+
"c12": "^3.2.0",
|
|
231
225
|
"citty": "^0.1.6",
|
|
232
226
|
"consola": "^3.4.2",
|
|
233
227
|
"eta": "^2.2.0",
|
|
@@ -236,25 +230,25 @@ var dependencies = {
|
|
|
236
230
|
"nanoid": "^5.1.5",
|
|
237
231
|
"swagger-schema-official": "2.0.0-bab6bed",
|
|
238
232
|
"swagger2openapi": "^7.0.8",
|
|
239
|
-
"typescript": "~5.
|
|
233
|
+
"typescript": "~5.9.2"
|
|
240
234
|
};
|
|
241
235
|
var devDependencies = {
|
|
242
|
-
"@biomejs/biome": "2.
|
|
236
|
+
"@biomejs/biome": "2.2.2",
|
|
243
237
|
"@changesets/changelog-github": "0.5.1",
|
|
244
|
-
"@changesets/cli": "2.29.
|
|
238
|
+
"@changesets/cli": "2.29.6",
|
|
245
239
|
"@tsconfig/node18": "18.2.4",
|
|
246
240
|
"@tsconfig/strictest": "2.0.5",
|
|
247
241
|
"@types/js-yaml": "4.0.9",
|
|
248
|
-
"@types/lodash": "4.17.
|
|
249
|
-
"@types/node": "24.0
|
|
242
|
+
"@types/lodash": "4.17.20",
|
|
243
|
+
"@types/node": "24.3.0",
|
|
250
244
|
"@types/swagger2openapi": "7.0.4",
|
|
251
|
-
"axios": "1.
|
|
245
|
+
"axios": "1.11.0",
|
|
252
246
|
"openapi-types": "12.1.3",
|
|
253
|
-
"tsdown": "0.
|
|
254
|
-
"typedoc": "0.28.
|
|
247
|
+
"tsdown": "0.14.2",
|
|
248
|
+
"typedoc": "0.28.11",
|
|
255
249
|
"vitest": "3.2.4"
|
|
256
250
|
};
|
|
257
|
-
var packageManager = "yarn@4.9.
|
|
251
|
+
var packageManager = "yarn@4.9.4";
|
|
258
252
|
var engines = { "node": ">=20" };
|
|
259
253
|
var publishConfig = {
|
|
260
254
|
"access": "public",
|
|
@@ -278,7 +272,7 @@ var package_default = {
|
|
|
278
272
|
type,
|
|
279
273
|
exports,
|
|
280
274
|
main,
|
|
281
|
-
module,
|
|
275
|
+
module: module$1,
|
|
282
276
|
types,
|
|
283
277
|
bin,
|
|
284
278
|
files,
|
|
@@ -433,7 +427,7 @@ var CodeGenConfig = class {
|
|
|
433
427
|
httpClient: "http-client",
|
|
434
428
|
outOfModuleApi: "Common"
|
|
435
429
|
};
|
|
436
|
-
routeNameDuplicatesMap = new Map();
|
|
430
|
+
routeNameDuplicatesMap = /* @__PURE__ */ new Map();
|
|
437
431
|
hooks = {
|
|
438
432
|
onPreBuildRoutePath: (_routePath) => void 0,
|
|
439
433
|
onBuildRoutePath: (_routeData) => void 0,
|
|
@@ -543,10 +537,10 @@ var CodeGenConfig = class {
|
|
|
543
537
|
]
|
|
544
538
|
};
|
|
545
539
|
compilerTsConfig = {
|
|
546
|
-
module: typescript
|
|
540
|
+
module: typescript.ModuleKind.ESNext,
|
|
547
541
|
noImplicitReturns: true,
|
|
548
542
|
alwaysStrict: true,
|
|
549
|
-
target: typescript
|
|
543
|
+
target: typescript.ScriptTarget.ESNext,
|
|
550
544
|
declaration: true,
|
|
551
545
|
noImplicitAny: false,
|
|
552
546
|
sourceMap: false,
|
|
@@ -700,6 +694,7 @@ var CodeGenConfig = class {
|
|
|
700
694
|
}
|
|
701
695
|
update = (update) => {
|
|
702
696
|
objectAssign(this, update);
|
|
697
|
+
if (this.enumNamesAsValues) this.extractEnums = true;
|
|
703
698
|
};
|
|
704
699
|
};
|
|
705
700
|
|
|
@@ -1156,9 +1151,19 @@ var EnumSchemaParser = class extends MonoSchemaParser {
|
|
|
1156
1151
|
let content = null;
|
|
1157
1152
|
const formatValue = (value) => {
|
|
1158
1153
|
if (value === null) return this.config.Ts.NullValue(value);
|
|
1159
|
-
if (keyType.includes(this.schemaUtils.getSchemaType({ type: "number" })))
|
|
1160
|
-
|
|
1161
|
-
|
|
1154
|
+
if (keyType.includes(this.schemaUtils.getSchemaType({ type: "number" }))) {
|
|
1155
|
+
const maybeNumber = typeof value === "number" ? value : Number(value);
|
|
1156
|
+
if (!Number.isNaN(maybeNumber)) return this.config.Ts.NumberValue(maybeNumber);
|
|
1157
|
+
}
|
|
1158
|
+
if (keyType.includes(this.schemaUtils.getSchemaType({ type: "boolean" }))) {
|
|
1159
|
+
if (typeof value === "boolean") return this.config.Ts.BooleanValue(value);
|
|
1160
|
+
if (value === "true" || value === "false") return this.config.Ts.BooleanValue(value === "true");
|
|
1161
|
+
}
|
|
1162
|
+
switch (typeof value) {
|
|
1163
|
+
case "number": return this.config.Ts.NumberValue(value);
|
|
1164
|
+
case "boolean": return this.config.Ts.BooleanValue(value);
|
|
1165
|
+
default: return this.config.Ts.StringValue(value);
|
|
1166
|
+
}
|
|
1162
1167
|
};
|
|
1163
1168
|
if (Array.isArray(enumNames) && lodash.size(enumNames)) content = enumNames.map((enumName, index) => {
|
|
1164
1169
|
const enumValue = lodash.get(this.schema.enum, index);
|
|
@@ -1630,7 +1635,7 @@ var SchemaUtils = class {
|
|
|
1630
1635
|
const refTypeInfo = this.getSchemaRefType(schema);
|
|
1631
1636
|
if (refTypeInfo) return this.checkAndAddRequiredKeys(schema, this.safeAddNullToType(schema, this.typeNameFormatter.format(refTypeInfo.typeName)));
|
|
1632
1637
|
let resultType;
|
|
1633
|
-
if (this.isConstantSchema(schema)) resultType = this.formatJsValue(schema.const);
|
|
1638
|
+
if (this.isConstantSchema(schema) && !schema.enum) resultType = this.formatJsValue(schema.const);
|
|
1634
1639
|
else {
|
|
1635
1640
|
const primitiveType = this.getSchemaPrimitiveType(schema);
|
|
1636
1641
|
if (primitiveType == null) return this.config.Ts.Keyword.Any;
|
|
@@ -1654,10 +1659,9 @@ var SchemaUtils = class {
|
|
|
1654
1659
|
case "string": return this.config.Ts.StringValue(value);
|
|
1655
1660
|
case "boolean": return this.config.Ts.BooleanValue(value);
|
|
1656
1661
|
case "number": return this.config.Ts.NumberValue(value);
|
|
1657
|
-
default:
|
|
1662
|
+
default:
|
|
1658
1663
|
if (value === null) return this.config.Ts.NullValue(value);
|
|
1659
1664
|
return this.config.Ts.Keyword.Any;
|
|
1660
|
-
}
|
|
1661
1665
|
}
|
|
1662
1666
|
};
|
|
1663
1667
|
};
|
|
@@ -2056,7 +2060,7 @@ var SchemaRoutes = class {
|
|
|
2056
2060
|
};
|
|
2057
2061
|
};
|
|
2058
2062
|
createRequestParamsSchema = ({ queryParams, queryObjectSchema, pathArgsSchemas, extractRequestParams, routeName }) => {
|
|
2059
|
-
if (!queryParams || !queryParams.length) return null;
|
|
2063
|
+
if ((!queryParams || !queryParams.length) && (!pathArgsSchemas || !pathArgsSchemas.length)) return null;
|
|
2060
2064
|
const pathParams = pathArgsSchemas.reduce((acc, pathArgSchema) => {
|
|
2061
2065
|
if (pathArgSchema.name) acc[pathArgSchema.name] = {
|
|
2062
2066
|
...pathArgSchema,
|
|
@@ -2349,8 +2353,8 @@ var SchemaRoutes = class {
|
|
|
2349
2353
|
var SchemaWalker = class {
|
|
2350
2354
|
config;
|
|
2351
2355
|
swaggerSchemaResolver;
|
|
2352
|
-
schemas = new Map();
|
|
2353
|
-
caches = new Map();
|
|
2356
|
+
schemas = /* @__PURE__ */ new Map();
|
|
2357
|
+
caches = /* @__PURE__ */ new Map();
|
|
2354
2358
|
constructor(config, swaggerSchemaResolver) {
|
|
2355
2359
|
this.config = config;
|
|
2356
2360
|
this.swaggerSchemaResolver = swaggerSchemaResolver;
|
|
@@ -2365,8 +2369,8 @@ var SchemaWalker = class {
|
|
|
2365
2369
|
return ref.startsWith("http://") || ref.startsWith("https://");
|
|
2366
2370
|
};
|
|
2367
2371
|
_getRefDataFromSchema = (schema, ref) => {
|
|
2368
|
-
const path$
|
|
2369
|
-
const refData = lodash.get(schema, path$
|
|
2372
|
+
const path$2 = ref.replace("#", "").split("/");
|
|
2373
|
+
const refData = lodash.get(schema, path$2);
|
|
2370
2374
|
if (refData) this.caches.set(ref, refData);
|
|
2371
2375
|
return refData;
|
|
2372
2376
|
};
|
|
@@ -2379,15 +2383,15 @@ var Request = class {
|
|
|
2379
2383
|
constructor(config) {
|
|
2380
2384
|
this.config = config;
|
|
2381
2385
|
}
|
|
2382
|
-
async download({ url: url$
|
|
2386
|
+
async download({ url: url$2, authToken,...options }) {
|
|
2383
2387
|
const requestOptions = {};
|
|
2384
2388
|
if (authToken) requestOptions.headers = { Authorization: authToken };
|
|
2385
2389
|
lodash.merge(requestOptions, options, this.config.requestOptions);
|
|
2386
2390
|
try {
|
|
2387
|
-
const response = await fetch(url$
|
|
2391
|
+
const response = await fetch(url$2, requestOptions);
|
|
2388
2392
|
return await response.text();
|
|
2389
2393
|
} catch (error) {
|
|
2390
|
-
const message = `error while fetching data from URL "${url$
|
|
2394
|
+
const message = `error while fetching data from URL "${url$2}"`;
|
|
2391
2395
|
consola.error(message, error);
|
|
2392
2396
|
return message;
|
|
2393
2397
|
}
|
|
@@ -2406,9 +2410,9 @@ var SwaggerSchemaResolver = class {
|
|
|
2406
2410
|
this.request = new Request(config);
|
|
2407
2411
|
}
|
|
2408
2412
|
async create() {
|
|
2409
|
-
const { spec, patch, input, url: url$
|
|
2413
|
+
const { spec, patch, input, url: url$2, authorizationToken } = this.config;
|
|
2410
2414
|
if (spec) return await this.convertSwaggerObject(spec, { patch });
|
|
2411
|
-
const swaggerSchemaFile = await this.fetchSwaggerSchemaFile(input, url$
|
|
2415
|
+
const swaggerSchemaFile = await this.fetchSwaggerSchemaFile(input, url$2, authorizationToken);
|
|
2412
2416
|
const swaggerSchemaObject = this.processSwaggerSchemaFile(swaggerSchemaFile);
|
|
2413
2417
|
return await this.convertSwaggerObject(swaggerSchemaObject, { patch });
|
|
2414
2418
|
}
|
|
@@ -2486,6 +2490,7 @@ var SwaggerSchemaResolver = class {
|
|
|
2486
2490
|
|
|
2487
2491
|
//#endregion
|
|
2488
2492
|
//#region src/templates-worker.ts
|
|
2493
|
+
const require = module.createRequire(import.meta.url);
|
|
2489
2494
|
var TemplatesWorker = class {
|
|
2490
2495
|
config;
|
|
2491
2496
|
fileSystem;
|
|
@@ -2498,12 +2503,12 @@ var TemplatesWorker = class {
|
|
|
2498
2503
|
if (this.config.silent) consola.level = 0;
|
|
2499
2504
|
}
|
|
2500
2505
|
getTemplatePaths = (config) => {
|
|
2501
|
-
const __dirname$1 = path$
|
|
2502
|
-
const baseTemplatesPath = path$
|
|
2503
|
-
const defaultTemplatesPath = path$
|
|
2504
|
-
const modularTemplatesPath = path$
|
|
2506
|
+
const __dirname$1 = path$1.dirname(url$1.fileURLToPath(import.meta.url));
|
|
2507
|
+
const baseTemplatesPath = path$1.resolve(__dirname$1, "../templates/base");
|
|
2508
|
+
const defaultTemplatesPath = path$1.resolve(__dirname$1, "../templates/default");
|
|
2509
|
+
const modularTemplatesPath = path$1.resolve(__dirname$1, "../templates/modular");
|
|
2505
2510
|
const originalTemplatesPath = config.modular ? modularTemplatesPath : defaultTemplatesPath;
|
|
2506
|
-
const customTemplatesPath = config.templates && path$
|
|
2511
|
+
const customTemplatesPath = config.templates && path$1.resolve(process.cwd(), config.templates);
|
|
2507
2512
|
return {
|
|
2508
2513
|
base: baseTemplatesPath,
|
|
2509
2514
|
default: defaultTemplatesPath,
|
|
@@ -2512,20 +2517,20 @@ var TemplatesWorker = class {
|
|
|
2512
2517
|
custom: customTemplatesPath
|
|
2513
2518
|
};
|
|
2514
2519
|
};
|
|
2515
|
-
cropExtension = (path$
|
|
2520
|
+
cropExtension = (path$2) => this.config.templateExtensions.reduce((path$3, ext) => path$3.endsWith(ext) ? path$3.replace(ext, "") : path$3, path$2);
|
|
2516
2521
|
getTemplateFullPath = (path_, fileName) => {
|
|
2517
|
-
const raw = path$
|
|
2522
|
+
const raw = path$1.resolve(path_, "./", this.cropExtension(fileName));
|
|
2518
2523
|
const pathVariants = this.config.templateExtensions.map((extension) => `${raw}${extension}`);
|
|
2519
2524
|
return pathVariants.find((variant) => !!this.fileSystem.pathIsExist(variant));
|
|
2520
2525
|
};
|
|
2521
|
-
requireFnFromTemplate =
|
|
2526
|
+
requireFnFromTemplate = (packageOrPath) => {
|
|
2522
2527
|
const isPath = packageOrPath.startsWith("./") || packageOrPath.startsWith("../");
|
|
2523
|
-
if (isPath) return
|
|
2524
|
-
return
|
|
2528
|
+
if (isPath) return require(path$1.resolve(this.config.templatePaths.custom || this.config.templatePaths.original, packageOrPath));
|
|
2529
|
+
return require(packageOrPath);
|
|
2525
2530
|
};
|
|
2526
|
-
getTemplate = (name$1, fileName, path$
|
|
2531
|
+
getTemplate = (name$1, fileName, path$2) => {
|
|
2527
2532
|
const { templatePaths } = this.config;
|
|
2528
|
-
if (path$
|
|
2533
|
+
if (path$2) return this.fileSystem.getFileContent(path$2);
|
|
2529
2534
|
if (!fileName) return "";
|
|
2530
2535
|
const customFullPath = templatePaths.custom && this.getTemplateFullPath(templatePaths.custom, fileName);
|
|
2531
2536
|
let fileContent = customFullPath && this.fileSystem.getFileContent(customFullPath);
|
|
@@ -2548,21 +2553,21 @@ var TemplatesWorker = class {
|
|
|
2548
2553
|
[name$1]: this.getTemplate(name$1, fileName)
|
|
2549
2554
|
}), {});
|
|
2550
2555
|
};
|
|
2551
|
-
findTemplateWithExt = (path$
|
|
2552
|
-
const raw = this.cropExtension(path$
|
|
2556
|
+
findTemplateWithExt = (path$2) => {
|
|
2557
|
+
const raw = this.cropExtension(path$2);
|
|
2553
2558
|
const pathVariants = this.config.templateExtensions.map((extension) => `${raw}${extension}`);
|
|
2554
2559
|
return pathVariants.find((variant) => this.fileSystem.pathIsExist(variant));
|
|
2555
2560
|
};
|
|
2556
2561
|
getTemplateContent = (path_) => {
|
|
2557
2562
|
const foundTemplatePathKey = lodash.keys(this.config.templatePaths).find((key) => path_.startsWith(`@${key}`));
|
|
2558
2563
|
if (foundTemplatePathKey) {
|
|
2559
|
-
const rawPath = path$
|
|
2564
|
+
const rawPath = path$1.resolve(path_.replace(`@${foundTemplatePathKey}`, lodash.get(this.config.templatePaths, foundTemplatePathKey)));
|
|
2560
2565
|
const fixedPath = this.findTemplateWithExt(rawPath);
|
|
2561
2566
|
if (fixedPath) return this.fileSystem.getFileContent(fixedPath);
|
|
2562
2567
|
}
|
|
2563
|
-
const customPath = this.config.templatePaths.custom && this.findTemplateWithExt(path$
|
|
2568
|
+
const customPath = this.config.templatePaths.custom && this.findTemplateWithExt(path$1.resolve(this.config.templatePaths.custom, path_));
|
|
2564
2569
|
if (customPath) return this.fileSystem.getFileContent(customPath);
|
|
2565
|
-
const originalPath = this.findTemplateWithExt(path$
|
|
2570
|
+
const originalPath = this.findTemplateWithExt(path$1.resolve(this.config.templatePaths.original, path_));
|
|
2566
2571
|
if (originalPath) return this.fileSystem.getFileContent(originalPath);
|
|
2567
2572
|
return "";
|
|
2568
2573
|
};
|
|
@@ -2574,8 +2579,8 @@ var TemplatesWorker = class {
|
|
|
2574
2579
|
}, {
|
|
2575
2580
|
async: false,
|
|
2576
2581
|
...options,
|
|
2577
|
-
includeFile: (path$
|
|
2578
|
-
return this.renderTemplate(this.getTemplateContent(path$
|
|
2582
|
+
includeFile: (path$2, configuration$1, options$1 = {}) => {
|
|
2583
|
+
return this.renderTemplate(this.getTemplateContent(path$2), configuration$1, options$1);
|
|
2579
2584
|
}
|
|
2580
2585
|
});
|
|
2581
2586
|
};
|
|
@@ -2601,23 +2606,23 @@ var JavascriptTranslator = class extends Translator {
|
|
|
2601
2606
|
compileTSCode = (input) => {
|
|
2602
2607
|
const fileNameFull = `${input.fileName}${input.fileExtension}`;
|
|
2603
2608
|
const output = {};
|
|
2604
|
-
const host = typescript
|
|
2609
|
+
const host = typescript.createCompilerHost(this.config.compilerTsConfig, true);
|
|
2605
2610
|
const fileNames = [fileNameFull];
|
|
2606
2611
|
const originalSourceFileGet = host.getSourceFile.bind(host);
|
|
2607
2612
|
host.getSourceFile = (sourceFileName, languageVersion, onError, shouldCreateNewSourceFile) => {
|
|
2608
2613
|
if (sourceFileName !== fileNameFull) return originalSourceFileGet(sourceFileName, languageVersion, onError, shouldCreateNewSourceFile);
|
|
2609
|
-
return typescript
|
|
2614
|
+
return typescript.createSourceFile(sourceFileName, input.fileContent, languageVersion, true, typescript.ScriptKind.TS);
|
|
2610
2615
|
};
|
|
2611
2616
|
host.writeFile = (fileName, contents) => {
|
|
2612
2617
|
output[fileName] = contents;
|
|
2613
2618
|
};
|
|
2614
|
-
typescript
|
|
2619
|
+
typescript.createProgram(fileNames, this.config.compilerTsConfig, host).emit();
|
|
2615
2620
|
return output;
|
|
2616
2621
|
};
|
|
2617
2622
|
translate = async (input) => {
|
|
2618
2623
|
const compiled = this.compileTSCode(input);
|
|
2619
|
-
const jsFileName = `${input.fileName}${typescript
|
|
2620
|
-
const dtsFileName = `${input.fileName}${typescript
|
|
2624
|
+
const jsFileName = `${input.fileName}${typescript.Extension.Js}`;
|
|
2625
|
+
const dtsFileName = `${input.fileName}${typescript.Extension.Dts}`;
|
|
2621
2626
|
const sourceContent = compiled[jsFileName];
|
|
2622
2627
|
const tsImportRows = input.fileContent.split("\n").filter((line) => line.startsWith("import "));
|
|
2623
2628
|
const declarationContent = compiled[dtsFileName].split("\n").map((line) => {
|
|
@@ -2626,11 +2631,11 @@ var JavascriptTranslator = class extends Translator {
|
|
|
2626
2631
|
}).join("\n");
|
|
2627
2632
|
return [{
|
|
2628
2633
|
fileName: input.fileName,
|
|
2629
|
-
fileExtension: typescript
|
|
2634
|
+
fileExtension: typescript.Extension.Js,
|
|
2630
2635
|
fileContent: await this.codeFormatter.formatCode(sourceContent)
|
|
2631
2636
|
}, {
|
|
2632
2637
|
fileName: input.fileName,
|
|
2633
|
-
fileExtension: typescript
|
|
2638
|
+
fileExtension: typescript.Extension.Dts,
|
|
2634
2639
|
fileContent: await this.codeFormatter.formatCode(declarationContent)
|
|
2635
2640
|
}];
|
|
2636
2641
|
};
|
|
@@ -2639,7 +2644,7 @@ var JavascriptTranslator = class extends Translator {
|
|
|
2639
2644
|
//#endregion
|
|
2640
2645
|
//#region src/type-name-formatter.ts
|
|
2641
2646
|
var TypeNameFormatter = class {
|
|
2642
|
-
formattedModelNamesMap = new Map();
|
|
2647
|
+
formattedModelNamesMap = /* @__PURE__ */ new Map();
|
|
2643
2648
|
config;
|
|
2644
2649
|
constructor(config) {
|
|
2645
2650
|
this.config = config;
|
|
@@ -2682,16 +2687,16 @@ var TypeNameFormatter = class {
|
|
|
2682
2687
|
//#endregion
|
|
2683
2688
|
//#region src/util/file-system.ts
|
|
2684
2689
|
var FileSystem = class {
|
|
2685
|
-
getFileContent = (path$
|
|
2686
|
-
return fs.readFileSync(path$
|
|
2690
|
+
getFileContent = (path$2) => {
|
|
2691
|
+
return fs.readFileSync(path$2, { encoding: "utf8" });
|
|
2687
2692
|
};
|
|
2688
|
-
readDir = (path$
|
|
2689
|
-
return fs.readdirSync(path$
|
|
2693
|
+
readDir = (path$2) => {
|
|
2694
|
+
return fs.readdirSync(path$2);
|
|
2690
2695
|
};
|
|
2691
|
-
pathIsDir = (path$
|
|
2692
|
-
if (!path$
|
|
2696
|
+
pathIsDir = (path$2) => {
|
|
2697
|
+
if (!path$2) return false;
|
|
2693
2698
|
try {
|
|
2694
|
-
const stat = fs.statSync(path$
|
|
2699
|
+
const stat = fs.statSync(path$2);
|
|
2695
2700
|
return stat.isDirectory();
|
|
2696
2701
|
} catch (e) {
|
|
2697
2702
|
return false;
|
|
@@ -2702,27 +2707,27 @@ var FileSystem = class {
|
|
|
2702
2707
|
if (fileNameParts.length > 1) fileNameParts.pop();
|
|
2703
2708
|
return fileNameParts.join(".");
|
|
2704
2709
|
};
|
|
2705
|
-
removeDir = (path$
|
|
2710
|
+
removeDir = (path$2) => {
|
|
2706
2711
|
try {
|
|
2707
|
-
if (typeof fs.rmSync === "function") fs.rmSync(path$
|
|
2708
|
-
else fs.rmdirSync(path$
|
|
2712
|
+
if (typeof fs.rmSync === "function") fs.rmSync(path$2, { recursive: true });
|
|
2713
|
+
else fs.rmdirSync(path$2, { recursive: true });
|
|
2709
2714
|
} catch (e) {
|
|
2710
2715
|
consola.debug("failed to remove dir", e);
|
|
2711
2716
|
}
|
|
2712
2717
|
};
|
|
2713
|
-
createDir = (path$
|
|
2718
|
+
createDir = (path$2) => {
|
|
2714
2719
|
try {
|
|
2715
|
-
fs.mkdirSync(path$
|
|
2720
|
+
fs.mkdirSync(path$2, { recursive: true });
|
|
2716
2721
|
} catch (e) {
|
|
2717
2722
|
consola.debug("failed to create dir", e);
|
|
2718
2723
|
}
|
|
2719
2724
|
};
|
|
2720
|
-
cleanDir = (path$
|
|
2721
|
-
this.removeDir(path$
|
|
2722
|
-
this.createDir(path$
|
|
2725
|
+
cleanDir = (path$2) => {
|
|
2726
|
+
this.removeDir(path$2);
|
|
2727
|
+
this.createDir(path$2);
|
|
2723
2728
|
};
|
|
2724
|
-
pathIsExist = (path$
|
|
2725
|
-
return !!path$
|
|
2729
|
+
pathIsExist = (path$2) => {
|
|
2730
|
+
return !!path$2 && fs.existsSync(path$2);
|
|
2726
2731
|
};
|
|
2727
2732
|
createFile = ({ path: path_, fileName, content, withPrefix }) => {
|
|
2728
2733
|
const __dirname$1 = path$1.dirname(url$1.fileURLToPath(import.meta.url));
|
|
@@ -3170,4 +3175,4 @@ async function generateApi(config) {
|
|
|
3170
3175
|
|
|
3171
3176
|
//#endregion
|
|
3172
3177
|
export { CodeGenConfig, HTTP_CLIENT, TemplatesGenConfig, constants_exports, generateApi, generateTemplates, package_default };
|
|
3173
|
-
//# sourceMappingURL=src-
|
|
3178
|
+
//# sourceMappingURL=src-BGOGeWR6.js.map
|