@kubb/core 3.16.2 → 3.16.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/dist/FileManager-Dk759iZ3.js +918 -0
  2. package/dist/FileManager-Dk759iZ3.js.map +1 -0
  3. package/dist/FileManager-DsRjYJa_.cjs +1031 -0
  4. package/dist/FileManager-DsRjYJa_.cjs.map +1 -0
  5. package/dist/PluginManager-1jPxuyQK.d.ts +511 -0
  6. package/dist/PluginManager-Cvj5AlsU.d.cts +511 -0
  7. package/dist/chunk-DWy1uDak.cjs +39 -0
  8. package/dist/chunk-DbvY3SJr.js +33 -0
  9. package/dist/fs-BacxV1CO.js +87 -0
  10. package/dist/fs-BacxV1CO.js.map +1 -0
  11. package/dist/fs-BazSaf2y.cjs +129 -0
  12. package/dist/fs-BazSaf2y.cjs.map +1 -0
  13. package/dist/fs.cjs +15 -39
  14. package/dist/fs.d.cts +2 -19
  15. package/dist/fs.d.ts +2 -19
  16. package/dist/fs.js +4 -3
  17. package/dist/index-BKHQGQVq.d.ts +140 -0
  18. package/dist/index-BfD6z1P5.d.cts +141 -0
  19. package/dist/index-Cb4pChs8.d.ts +180 -0
  20. package/dist/index-D2ptHzfn.d.cts +180 -0
  21. package/dist/index.cjs +997 -1077
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.d.cts +107 -89
  24. package/dist/index.d.ts +107 -89
  25. package/dist/index.js +1020 -864
  26. package/dist/index.js.map +1 -1
  27. package/dist/logger-BxvJpQMX.cjs +1115 -0
  28. package/dist/logger-BxvJpQMX.cjs.map +1 -0
  29. package/dist/logger-Cs45J4yy.js +1085 -0
  30. package/dist/logger-Cs45J4yy.js.map +1 -0
  31. package/dist/logger-OWS6fqk0.d.cts +69 -0
  32. package/dist/logger-xcdTETKy.d.ts +69 -0
  33. package/dist/logger.cjs +6 -24
  34. package/dist/logger.d.cts +2 -3
  35. package/dist/logger.d.ts +2 -3
  36. package/dist/logger.js +4 -4
  37. package/dist/mocks.cjs +49 -65
  38. package/dist/mocks.cjs.map +1 -1
  39. package/dist/mocks.d.cts +6 -6
  40. package/dist/mocks.d.ts +6 -6
  41. package/dist/mocks.js +48 -59
  42. package/dist/mocks.js.map +1 -1
  43. package/dist/prompt-DwEAzq0q.js +853 -0
  44. package/dist/prompt-DwEAzq0q.js.map +1 -0
  45. package/dist/prompt-qiwl6Be9.cjs +855 -0
  46. package/dist/prompt-qiwl6Be9.cjs.map +1 -0
  47. package/dist/transformers-B3CHtwuB.cjs +948 -0
  48. package/dist/transformers-B3CHtwuB.cjs.map +1 -0
  49. package/dist/transformers-CJqBQFIl.js +829 -0
  50. package/dist/transformers-CJqBQFIl.js.map +1 -0
  51. package/dist/transformers.cjs +33 -88
  52. package/dist/transformers.d.cts +75 -54
  53. package/dist/transformers.d.ts +75 -54
  54. package/dist/transformers.js +4 -3
  55. package/dist/utils.cjs +20 -73
  56. package/dist/utils.d.cts +5 -126
  57. package/dist/utils.d.ts +5 -126
  58. package/dist/utils.js +6 -5
  59. package/dist/write-CLTPlucv.js +42 -0
  60. package/dist/write-CLTPlucv.js.map +1 -0
  61. package/dist/write-l_NzIqyy.cjs +48 -0
  62. package/dist/write-l_NzIqyy.cjs.map +1 -0
  63. package/package.json +25 -32
  64. package/src/BarrelManager.ts +1 -0
  65. package/src/PromiseManager.ts +1 -7
  66. package/src/build.ts +9 -11
  67. package/src/index.ts +5 -5
  68. package/src/logger.ts +10 -10
  69. package/src/utils/FunctionParams.ts +3 -1
  70. package/src/utils/TreeNode.ts +3 -1
  71. package/dist/PluginManager-E3SghPP9.d.cts +0 -458
  72. package/dist/PluginManager-PDmRCu9k.d.ts +0 -458
  73. package/dist/chunk-4V7HK7PT.js +0 -1199
  74. package/dist/chunk-4V7HK7PT.js.map +0 -1
  75. package/dist/chunk-BHSTNFNQ.cjs +0 -701
  76. package/dist/chunk-BHSTNFNQ.cjs.map +0 -1
  77. package/dist/chunk-CAZ37TGB.js +0 -918
  78. package/dist/chunk-CAZ37TGB.js.map +0 -1
  79. package/dist/chunk-E4XLCCPK.cjs +0 -170
  80. package/dist/chunk-E4XLCCPK.cjs.map +0 -1
  81. package/dist/chunk-GBYHPDPK.js +0 -595
  82. package/dist/chunk-GBYHPDPK.js.map +0 -1
  83. package/dist/chunk-L3A3DTAX.cjs +0 -1074
  84. package/dist/chunk-L3A3DTAX.cjs.map +0 -1
  85. package/dist/chunk-MCNA6SYG.cjs +0 -1231
  86. package/dist/chunk-MCNA6SYG.cjs.map +0 -1
  87. package/dist/chunk-YRPOID7E.js +0 -157
  88. package/dist/chunk-YRPOID7E.js.map +0 -1
  89. package/dist/fs.cjs.map +0 -1
  90. package/dist/fs.js.map +0 -1
  91. package/dist/logger-BWq-oJU_.d.cts +0 -63
  92. package/dist/logger-BWq-oJU_.d.ts +0 -63
  93. package/dist/logger.cjs.map +0 -1
  94. package/dist/logger.js.map +0 -1
  95. package/dist/parser-C1vOjVEd.d.ts +0 -41
  96. package/dist/parser-D6vU1kA9.d.cts +0 -41
  97. package/dist/prompt-ELTHGQK6.js +0 -753
  98. package/dist/prompt-ELTHGQK6.js.map +0 -1
  99. package/dist/prompt-U7M5G25C.cjs +0 -761
  100. package/dist/prompt-U7M5G25C.cjs.map +0 -1
  101. package/dist/transformers.cjs.map +0 -1
  102. package/dist/transformers.js.map +0 -1
  103. package/dist/types-CA8nQKwM.d.cts +0 -132
  104. package/dist/types-CA8nQKwM.d.ts +0 -132
  105. package/dist/utils.cjs.map +0 -1
  106. package/dist/utils.js.map +0 -1
@@ -0,0 +1,1031 @@
1
+ const require_chunk = require('./chunk-DWy1uDak.cjs');
2
+ const require_fs = require('./fs-BazSaf2y.cjs');
3
+ const require_write = require('./write-l_NzIqyy.cjs');
4
+ const require_transformers = require('./transformers-B3CHtwuB.cjs');
5
+ const node_path = require_chunk.__toESM(require("node:path"));
6
+ const remeda = require_chunk.__toESM(require("remeda"));
7
+ const object_hash = require_chunk.__toESM(require("object-hash"));
8
+
9
+ //#region ../../node_modules/.pnpm/yocto-queue@1.2.1/node_modules/yocto-queue/index.js
10
+ var Node = class {
11
+ value;
12
+ next;
13
+ constructor(value) {
14
+ this.value = value;
15
+ }
16
+ };
17
+ var Queue = class {
18
+ #head;
19
+ #tail;
20
+ #size;
21
+ constructor() {
22
+ this.clear();
23
+ }
24
+ enqueue(value) {
25
+ const node = new Node(value);
26
+ if (this.#head) {
27
+ this.#tail.next = node;
28
+ this.#tail = node;
29
+ } else {
30
+ this.#head = node;
31
+ this.#tail = node;
32
+ }
33
+ this.#size++;
34
+ }
35
+ dequeue() {
36
+ const current = this.#head;
37
+ if (!current) return;
38
+ this.#head = this.#head.next;
39
+ this.#size--;
40
+ return current.value;
41
+ }
42
+ peek() {
43
+ if (!this.#head) return;
44
+ return this.#head.value;
45
+ }
46
+ clear() {
47
+ this.#head = void 0;
48
+ this.#tail = void 0;
49
+ this.#size = 0;
50
+ }
51
+ get size() {
52
+ return this.#size;
53
+ }
54
+ *[Symbol.iterator]() {
55
+ let current = this.#head;
56
+ while (current) {
57
+ yield current.value;
58
+ current = current.next;
59
+ }
60
+ }
61
+ *drain() {
62
+ while (this.#head) yield this.dequeue();
63
+ }
64
+ };
65
+
66
+ //#endregion
67
+ //#region ../../node_modules/.pnpm/p-limit@7.0.0/node_modules/p-limit/index.js
68
+ function pLimit(concurrency) {
69
+ validateConcurrency(concurrency);
70
+ const queue = new Queue();
71
+ let activeCount = 0;
72
+ const resumeNext = () => {
73
+ if (activeCount < concurrency && queue.size > 0) {
74
+ activeCount++;
75
+ queue.dequeue()();
76
+ }
77
+ };
78
+ const next = () => {
79
+ activeCount--;
80
+ resumeNext();
81
+ };
82
+ const run = async (function_, resolve, arguments_) => {
83
+ const result = (async () => function_(...arguments_))();
84
+ resolve(result);
85
+ try {
86
+ await result;
87
+ } catch {}
88
+ next();
89
+ };
90
+ const enqueue = (function_, resolve, arguments_) => {
91
+ new Promise((internalResolve) => {
92
+ queue.enqueue(internalResolve);
93
+ }).then(run.bind(void 0, function_, resolve, arguments_));
94
+ if (activeCount < concurrency) resumeNext();
95
+ };
96
+ const generator = (function_, ...arguments_) => new Promise((resolve) => {
97
+ enqueue(function_, resolve, arguments_);
98
+ });
99
+ Object.defineProperties(generator, {
100
+ activeCount: { get: () => activeCount },
101
+ pendingCount: { get: () => queue.size },
102
+ clearQueue: { value() {
103
+ queue.clear();
104
+ } },
105
+ concurrency: {
106
+ get: () => concurrency,
107
+ set(newConcurrency) {
108
+ validateConcurrency(newConcurrency);
109
+ concurrency = newConcurrency;
110
+ queueMicrotask(() => {
111
+ while (activeCount < concurrency && queue.size > 0) resumeNext();
112
+ });
113
+ }
114
+ },
115
+ map: { async value(array, function_) {
116
+ const promises = array.map((value) => this(function_, value));
117
+ return Promise.all(promises);
118
+ } }
119
+ });
120
+ return generator;
121
+ }
122
+ function validateConcurrency(concurrency) {
123
+ if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) throw new TypeError("Expected `concurrency` to be a number from 1 and up");
124
+ }
125
+
126
+ //#endregion
127
+ //#region src/utils/TreeNode.ts
128
+ var TreeNode = class TreeNode {
129
+ data;
130
+ parent;
131
+ children = [];
132
+ #cachedLeaves = void 0;
133
+ constructor(data, parent) {
134
+ this.data = data;
135
+ this.parent = parent;
136
+ return this;
137
+ }
138
+ addChild(data) {
139
+ const child = new TreeNode(data, this);
140
+ if (!this.children) this.children = [];
141
+ this.children.push(child);
142
+ return child;
143
+ }
144
+ get root() {
145
+ if (!this.parent) return this;
146
+ return this.parent.root;
147
+ }
148
+ get leaves() {
149
+ if (!this.children || this.children.length === 0) return [this];
150
+ if (this.#cachedLeaves) return this.#cachedLeaves;
151
+ const leaves = [];
152
+ if (this.children) for (let i = 0, { length } = this.children; i < length; i++) leaves.push.apply(leaves, this.children[i].leaves);
153
+ this.#cachedLeaves = leaves;
154
+ return leaves;
155
+ }
156
+ forEach(callback) {
157
+ if (typeof callback !== "function") throw new TypeError("forEach() callback must be a function");
158
+ callback(this);
159
+ if (this.children) for (let i = 0, { length } = this.children; i < length; i++) this.children[i]?.forEach(callback);
160
+ return this;
161
+ }
162
+ findDeep(predicate) {
163
+ if (typeof predicate !== "function") throw new TypeError("find() predicate must be a function");
164
+ return this.leaves.find(predicate);
165
+ }
166
+ forEachDeep(callback) {
167
+ if (typeof callback !== "function") throw new TypeError("forEach() callback must be a function");
168
+ this.leaves.forEach(callback);
169
+ }
170
+ filterDeep(callback) {
171
+ if (typeof callback !== "function") throw new TypeError("filter() callback must be a function");
172
+ return this.leaves.filter(callback);
173
+ }
174
+ mapDeep(callback) {
175
+ if (typeof callback !== "function") throw new TypeError("map() callback must be a function");
176
+ return this.leaves.map(callback);
177
+ }
178
+ static build(files, root) {
179
+ try {
180
+ const filteredTree = buildDirectoryTree(files, root);
181
+ if (!filteredTree) return null;
182
+ const treeNode = new TreeNode({
183
+ name: filteredTree.name,
184
+ path: filteredTree.path,
185
+ file: filteredTree.file,
186
+ type: FileManager.getMode(filteredTree.path)
187
+ });
188
+ const recurse = (node, item) => {
189
+ const subNode = node.addChild({
190
+ name: item.name,
191
+ path: item.path,
192
+ file: item.file,
193
+ type: FileManager.getMode(item.path)
194
+ });
195
+ if (item.children?.length) item.children?.forEach((child) => {
196
+ recurse(subNode, child);
197
+ });
198
+ };
199
+ filteredTree.children?.forEach((child) => {
200
+ recurse(treeNode, child);
201
+ });
202
+ return treeNode;
203
+ } catch (e) {
204
+ throw new Error("Something went wrong with creating barrel files with the TreeNode class", { cause: e });
205
+ }
206
+ }
207
+ };
208
+ const normalizePath = (p) => p.replace(/\\/g, "/");
209
+ function buildDirectoryTree(files, rootFolder = "") {
210
+ const normalizedRootFolder = normalizePath(rootFolder);
211
+ const rootPrefix = normalizedRootFolder.endsWith("/") ? normalizedRootFolder : `${normalizedRootFolder}/`;
212
+ const filteredFiles = files.filter((file) => {
213
+ const normalizedFilePath = normalizePath(file.path);
214
+ return rootFolder ? normalizedFilePath.startsWith(rootPrefix) && !normalizedFilePath.endsWith(".json") : !normalizedFilePath.endsWith(".json");
215
+ });
216
+ if (filteredFiles.length === 0) return null;
217
+ const root = {
218
+ name: rootFolder || "",
219
+ path: rootFolder || "",
220
+ children: []
221
+ };
222
+ filteredFiles.forEach((file) => {
223
+ const path$1 = file.path.slice(rootFolder.length);
224
+ const parts = path$1.split("/");
225
+ let currentLevel = root.children;
226
+ let currentPath = rootFolder;
227
+ parts.forEach((part, index) => {
228
+ if (index !== 0) currentPath += `/${part}`;
229
+ else currentPath += `${part}`;
230
+ let existingNode = currentLevel.find((node) => node.name === part);
231
+ if (!existingNode) {
232
+ if (index === parts.length - 1) existingNode = {
233
+ name: part,
234
+ file,
235
+ path: currentPath
236
+ };
237
+ else existingNode = {
238
+ name: part,
239
+ path: currentPath,
240
+ children: []
241
+ };
242
+ currentLevel.push(existingNode);
243
+ }
244
+ if (!existingNode.file) currentLevel = existingNode.children;
245
+ });
246
+ });
247
+ return root;
248
+ }
249
+
250
+ //#endregion
251
+ //#region src/BarrelManager.ts
252
+ var BarrelManager = class {
253
+ #options;
254
+ constructor(options = {}) {
255
+ this.#options = options;
256
+ return this;
257
+ }
258
+ getFiles({ files: generatedFiles, root }) {
259
+ const { logger } = this.#options;
260
+ const cachedFiles = /* @__PURE__ */ new Map();
261
+ TreeNode.build(generatedFiles, root)?.forEach((treeNode) => {
262
+ if (!treeNode || !treeNode.children || !treeNode.parent?.data.path) return void 0;
263
+ const barrelFile = {
264
+ path: (0, node_path.join)(treeNode.parent?.data.path, "index.ts"),
265
+ baseName: "index.ts",
266
+ exports: [],
267
+ sources: []
268
+ };
269
+ const previousBarrelFile = cachedFiles.get(barrelFile.path);
270
+ const leaves = treeNode.leaves;
271
+ leaves.forEach((item) => {
272
+ if (!item.data.name) return void 0;
273
+ const sources = item.data.file?.sources || [];
274
+ if (!sources.some((source) => source.isIndexable)) logger?.emit("warning", `No isIndexable source found(source should have a name and isIndexable):\nFile: ${JSON.stringify(item.data.file, void 0, 2)}`);
275
+ sources.forEach((source) => {
276
+ if (!item.data.file?.path || !source.isIndexable || !source.name) return void 0;
277
+ const alreadyContainInPreviousBarrelFile = previousBarrelFile?.sources.some((item$1) => item$1.name === source.name && item$1.isTypeOnly === source.isTypeOnly);
278
+ if (alreadyContainInPreviousBarrelFile) return void 0;
279
+ if (!barrelFile.exports) barrelFile.exports = [];
280
+ const isSubExport = !!treeNode.parent?.data.path?.split?.("/")?.length;
281
+ if (isSubExport) barrelFile.exports.push({
282
+ name: [source.name],
283
+ path: require_fs.getRelativePath(treeNode.parent?.data.path, item.data.path),
284
+ isTypeOnly: source.isTypeOnly
285
+ });
286
+ else barrelFile.exports.push({
287
+ name: [source.name],
288
+ path: `./${item.data.file.baseName}`,
289
+ isTypeOnly: source.isTypeOnly
290
+ });
291
+ barrelFile.sources.push({
292
+ name: source.name,
293
+ isTypeOnly: source.isTypeOnly,
294
+ value: "",
295
+ isExportable: false,
296
+ isIndexable: false
297
+ });
298
+ });
299
+ });
300
+ if (previousBarrelFile) {
301
+ previousBarrelFile.sources.push(...barrelFile.sources);
302
+ previousBarrelFile.exports?.push(...barrelFile.exports || []);
303
+ } else cachedFiles.set(barrelFile.path, barrelFile);
304
+ });
305
+ return [...cachedFiles.values()];
306
+ }
307
+ };
308
+
309
+ //#endregion
310
+ //#region src/utils/FunctionParams.ts
311
+ var import_main$1 = /* @__PURE__ */ require_chunk.__toESM(require_transformers.require_main(), 1);
312
+ /**
313
+ * @deprecated
314
+ */
315
+ var FunctionParams = class FunctionParams {
316
+ #items = [];
317
+ constructor() {
318
+ return this;
319
+ }
320
+ get items() {
321
+ return this.#items.flat();
322
+ }
323
+ add(item) {
324
+ if (!item) return this;
325
+ if (Array.isArray(item)) {
326
+ item.filter(Boolean).forEach((it) => {
327
+ this.#items.push(it);
328
+ });
329
+ return this;
330
+ }
331
+ this.#items.push(item);
332
+ return this;
333
+ }
334
+ static #orderItems(items) {
335
+ return (0, import_main$1.orderBy)(items.filter(Boolean), [(v) => {
336
+ if (Array.isArray(v)) return void 0;
337
+ return !v.default;
338
+ }, (v) => {
339
+ if (Array.isArray(v)) return void 0;
340
+ return v.required ?? true;
341
+ }], ["desc", "desc"]);
342
+ }
343
+ static #addParams(acc, item) {
344
+ const { enabled = true, name, type, required = true,...rest } = item;
345
+ if (!enabled) return acc;
346
+ if (!name) {
347
+ acc.push(`${type}${rest.default ? ` = ${rest.default}` : ""}`);
348
+ return acc;
349
+ }
350
+ const parameterName = name.startsWith("{") ? name : require_transformers.camelCase(name);
351
+ if (type) if (required) acc.push(`${parameterName}: ${type}${rest.default ? ` = ${rest.default}` : ""}`);
352
+ else acc.push(`${parameterName}?: ${type}`);
353
+ else acc.push(`${parameterName}`);
354
+ return acc;
355
+ }
356
+ static toObject(items) {
357
+ let type = [];
358
+ let name = [];
359
+ const enabled = items.every((item) => item.enabled) ? items.at(0)?.enabled : true;
360
+ const required = items.every((item) => item.required) ?? true;
361
+ items.forEach((item) => {
362
+ name = FunctionParams.#addParams(name, {
363
+ ...item,
364
+ type: void 0
365
+ });
366
+ if (items.some((item$1) => item$1.type)) type = FunctionParams.#addParams(type, item);
367
+ });
368
+ return {
369
+ name: `{ ${name.join(", ")} }`,
370
+ type: type.length ? `{ ${type.join("; ")} }` : void 0,
371
+ enabled,
372
+ required
373
+ };
374
+ }
375
+ static toString(items) {
376
+ const sortedData = FunctionParams.#orderItems(items);
377
+ return sortedData.reduce((acc, item) => {
378
+ if (Array.isArray(item)) {
379
+ if (item.length <= 0) return acc;
380
+ const subItems = FunctionParams.#orderItems(item);
381
+ const objectItem = FunctionParams.toObject(subItems);
382
+ return FunctionParams.#addParams(acc, objectItem);
383
+ }
384
+ return FunctionParams.#addParams(acc, item);
385
+ }, []).join(", ");
386
+ }
387
+ toObject() {
388
+ const items = FunctionParams.#orderItems(this.#items).flat();
389
+ return FunctionParams.toObject(items);
390
+ }
391
+ toString() {
392
+ const items = FunctionParams.#orderItems(this.#items);
393
+ return FunctionParams.toString(items);
394
+ }
395
+ };
396
+
397
+ //#endregion
398
+ //#region src/utils/promise.ts
399
+ function isPromise(result) {
400
+ return !!result && typeof result?.then === "function";
401
+ }
402
+ function isPromiseFulfilledResult(result) {
403
+ return result.status === "fulfilled";
404
+ }
405
+ function isPromiseRejectedResult(result) {
406
+ return result.status === "rejected";
407
+ }
408
+
409
+ //#endregion
410
+ //#region src/utils/renderTemplate.ts
411
+ function renderTemplate(template, data = void 0) {
412
+ if (!data || !Object.keys(data).length) return template.replace(/{{(.*?)}}/g, "");
413
+ const matches = template.match(/{{(.*?)}}/g);
414
+ return matches?.reduce((prev, curr) => {
415
+ const index = curr.split(/{{|}}/).filter(Boolean)[0]?.trim();
416
+ if (index === void 0) return prev;
417
+ const value = data[index];
418
+ if (value === void 0) return prev;
419
+ return prev.replace(curr, () => {
420
+ if (typeof value === "boolean") return `${value.toString()}` || "false";
421
+ return value || "";
422
+ }).trim();
423
+ }, template) || "";
424
+ }
425
+
426
+ //#endregion
427
+ //#region src/utils/timeout.ts
428
+ async function timeout(ms) {
429
+ return new Promise((resolve) => {
430
+ setTimeout(() => {
431
+ resolve(true);
432
+ }, ms);
433
+ });
434
+ }
435
+
436
+ //#endregion
437
+ //#region src/utils/uniqueName.ts
438
+ function getUniqueName(originalName, data) {
439
+ let used = data[originalName] || 0;
440
+ if (used) {
441
+ data[originalName] = ++used;
442
+ originalName += used;
443
+ }
444
+ data[originalName] = 1;
445
+ return originalName;
446
+ }
447
+ function setUniqueName(originalName, data) {
448
+ let used = data[originalName] || 0;
449
+ if (used) {
450
+ data[originalName] = ++used;
451
+ return originalName;
452
+ }
453
+ data[originalName] = 1;
454
+ return originalName;
455
+ }
456
+
457
+ //#endregion
458
+ //#region src/utils/URLPath.ts
459
+ var URLPath = class {
460
+ path;
461
+ #options;
462
+ constructor(path$1, options = {}) {
463
+ this.path = path$1;
464
+ this.#options = options;
465
+ return this;
466
+ }
467
+ /**
468
+ * Convert Swagger path to URLPath(syntax of Express)
469
+ * @example /pet/{petId} => /pet/:petId
470
+ */
471
+ get URL() {
472
+ return this.toURLPath();
473
+ }
474
+ get isURL() {
475
+ try {
476
+ const url = new URL(this.path);
477
+ if (url?.href) return true;
478
+ } catch (_error) {
479
+ return false;
480
+ }
481
+ return false;
482
+ }
483
+ /**
484
+ * Convert Swagger path to template literals/ template strings(camelcase)
485
+ * @example /pet/{petId} => `/pet/${petId}`
486
+ * @example /account/monetary-accountID => `/account/${monetaryAccountId}`
487
+ * @example /account/userID => `/account/${userId}`
488
+ */
489
+ get template() {
490
+ return this.toTemplateString();
491
+ }
492
+ get object() {
493
+ return this.toObject();
494
+ }
495
+ get params() {
496
+ return this.getParams();
497
+ }
498
+ toObject({ type = "path", replacer, stringify } = {}) {
499
+ const object = {
500
+ url: type === "path" ? this.toURLPath() : this.toTemplateString({ replacer }),
501
+ params: this.getParams()
502
+ };
503
+ if (stringify) {
504
+ if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
505
+ if (object.params) return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
506
+ return `{ url: '${object.url}' }`;
507
+ }
508
+ return object;
509
+ }
510
+ /**
511
+ * Convert Swagger path to template literals/ template strings(camelcase)
512
+ * @example /pet/{petId} => `/pet/${petId}`
513
+ * @example /account/monetary-accountID => `/account/${monetaryAccountId}`
514
+ * @example /account/userID => `/account/${userId}`
515
+ */
516
+ toTemplateString({ prefix = "", replacer } = {}) {
517
+ const regex = /{(\w|-)*}/g;
518
+ const found = this.path.match(regex);
519
+ let newPath = this.path.replaceAll("{", "${");
520
+ if (found) newPath = found.reduce((prev, path$1) => {
521
+ const pathWithoutBrackets = path$1.replaceAll("{", "").replaceAll("}", "");
522
+ let param = require_transformers.isValidVarName(pathWithoutBrackets) ? pathWithoutBrackets : require_transformers.camelCase(pathWithoutBrackets);
523
+ if (this.#options.casing === "camelcase") param = require_transformers.camelCase(param);
524
+ return prev.replace(path$1, `\${${replacer ? replacer(param) : param}}`);
525
+ }, this.path);
526
+ return `\`${prefix}${newPath}\``;
527
+ }
528
+ getParams(replacer) {
529
+ const regex = /{(\w|-)*}/g;
530
+ const found = this.path.match(regex);
531
+ if (!found) return void 0;
532
+ const params = {};
533
+ found.forEach((item) => {
534
+ item = item.replaceAll("{", "").replaceAll("}", "");
535
+ let param = require_transformers.isValidVarName(item) ? item : require_transformers.camelCase(item);
536
+ if (this.#options.casing === "camelcase") param = require_transformers.camelCase(param);
537
+ const key = replacer ? replacer(param) : param;
538
+ params[key] = key;
539
+ }, this.path);
540
+ return params;
541
+ }
542
+ /**
543
+ * Convert Swagger path to URLPath(syntax of Express)
544
+ * @example /pet/{petId} => /pet/:petId
545
+ */
546
+ toURLPath() {
547
+ return this.path.replaceAll("{", ":").replaceAll("}", "");
548
+ }
549
+ };
550
+
551
+ //#endregion
552
+ //#region src/utils/parser.ts
553
+ /**
554
+ * Generate a default banner for files created by Kubb
555
+ * @returns A string with the default banner
556
+ */
557
+ function getDefaultBanner({ title, description, version, config }) {
558
+ try {
559
+ let source = "";
560
+ if ("path" in config.input) source = node_path.default.basename(config.input.path);
561
+ else if ("data" in config.input) source = "text content";
562
+ let banner = "/**\n* Generated by Kubb (https://kubb.dev/).\n* Do not edit manually.\n";
563
+ if (config.output.defaultBanner === "simple") {
564
+ banner += "*/\n";
565
+ return banner;
566
+ }
567
+ if (source) banner += `* Source: ${source}\n`;
568
+ if (title) banner += `* Title: ${title}\n`;
569
+ if (description) {
570
+ const formattedDescription = description.replace(/\n/gm, "\n* ");
571
+ banner += `* Description: ${formattedDescription}\n`;
572
+ }
573
+ if (version) banner += `* OpenAPI spec version: ${version}\n`;
574
+ banner += "*/\n";
575
+ return banner;
576
+ } catch (_error) {
577
+ return "/**\n* Generated by Kubb (https://kubb.dev/).\n* Do not edit manually.\n*/";
578
+ }
579
+ }
580
+ /**
581
+ * Helper to create a file with name and id set
582
+ */
583
+ function createFile(file) {
584
+ const extname$1 = node_path.default.extname(file.baseName);
585
+ if (!extname$1) throw new Error(`No extname found for ${file.baseName}`);
586
+ const source = file.sources.map((item) => item.value).join("\n\n");
587
+ const exports$1 = file.exports?.length ? combineExports(file.exports) : [];
588
+ const imports = file.imports?.length && source ? combineImports(file.imports, exports$1, source) : [];
589
+ const sources = file.sources?.length ? combineSources(file.sources) : [];
590
+ return {
591
+ ...file,
592
+ id: (0, object_hash.default)({ path: file.path }),
593
+ name: trimExtName$1(file.baseName),
594
+ extname: extname$1,
595
+ imports: imports.map(createFileImport),
596
+ exports: exports$1.map(createFileExport),
597
+ sources: sources.map(createFileSource),
598
+ meta: file.meta || {}
599
+ };
600
+ }
601
+ /**
602
+ * Helper to create a fileImport with extname set
603
+ */
604
+ function createFileSource(source) {
605
+ return source;
606
+ }
607
+ /**
608
+ * Helper to create a fileImport with extname set
609
+ */
610
+ function createFileImport(imp) {
611
+ return { ...imp };
612
+ }
613
+ /**
614
+ * Helper to create a fileExport with extname set
615
+ */
616
+ function createFileExport(exp) {
617
+ return { ...exp };
618
+ }
619
+ function createFileParser(parser) {
620
+ return parser;
621
+ }
622
+ const typeScriptParser = createFileParser({
623
+ async format(source) {
624
+ const module$1 = await import("@kubb/parser-ts");
625
+ return module$1.format(source);
626
+ },
627
+ async print(file, options = { extname: ".ts" }) {
628
+ const module$1 = await import("@kubb/parser-ts");
629
+ const source = file.sources.map((item) => item.value).join("\n\n");
630
+ const importNodes = file.imports.map((item) => {
631
+ const importPath = item.root ? require_fs.getRelativePath(item.root, item.path) : item.path;
632
+ const hasExtname = !!node_path.default.extname(importPath);
633
+ return module$1.factory.createImportDeclaration({
634
+ name: item.name,
635
+ path: options.extname && hasExtname ? `${trimExtName$1(importPath)}${options.extname}` : item.root ? trimExtName$1(importPath) : importPath,
636
+ isTypeOnly: item.isTypeOnly
637
+ });
638
+ }).filter(Boolean);
639
+ const exportNodes = file.exports.map((item) => {
640
+ const exportPath = item.path;
641
+ const hasExtname = !!node_path.default.extname(exportPath);
642
+ return module$1.factory.createExportDeclaration({
643
+ name: item.name,
644
+ path: options.extname && hasExtname ? `${trimExtName$1(item.path)}${options.extname}` : trimExtName$1(item.path),
645
+ isTypeOnly: item.isTypeOnly,
646
+ asAlias: item.asAlias
647
+ });
648
+ }).filter(Boolean);
649
+ return [
650
+ file.banner,
651
+ module$1.print([...importNodes, ...exportNodes]),
652
+ source,
653
+ file.footer
654
+ ].join("\n");
655
+ }
656
+ });
657
+ const tsxParser = createFileParser({
658
+ async format(source) {
659
+ const module$1 = await import("@kubb/parser-ts");
660
+ return module$1.format(source);
661
+ },
662
+ async print(file, options = { extname: ".tsx" }) {
663
+ return typeScriptParser.print(file, options);
664
+ }
665
+ });
666
+ const defaultParser = createFileParser({
667
+ async format(source) {
668
+ return source;
669
+ },
670
+ async print(file) {
671
+ return file.sources.map((item) => item.value).join("\n\n");
672
+ }
673
+ });
674
+ const parsers = {
675
+ ".ts": typeScriptParser,
676
+ ".js": typeScriptParser,
677
+ ".jsx": tsxParser,
678
+ ".tsx": tsxParser,
679
+ ".json": defaultParser
680
+ };
681
+ async function getFileParser(extname$1) {
682
+ if (!extname$1) return defaultParser;
683
+ const parser = parsers[extname$1];
684
+ if (!parser) console.warn(`[parser] No parser found for ${extname$1}, default parser will be used`);
685
+ return parser || defaultParser;
686
+ }
687
+ function trimExtName$1(text) {
688
+ const extname$1 = text.split(".").pop();
689
+ return text.replace(`.${extname$1}`, "");
690
+ }
691
+
692
+ //#endregion
693
+ //#region src/utils/Cache.ts
694
+ var Cache = class {
695
+ #buffer = /* @__PURE__ */ new Map();
696
+ async get(key) {
697
+ return this.#buffer.get(key) ?? null;
698
+ }
699
+ async set(key, value) {
700
+ this.#buffer.set(key, value);
701
+ }
702
+ async delete(key) {
703
+ this.#buffer.delete(key);
704
+ }
705
+ async clear() {
706
+ this.#buffer.clear();
707
+ }
708
+ async keys() {
709
+ return [...this.#buffer.keys()];
710
+ }
711
+ async values() {
712
+ return [...this.#buffer.values()];
713
+ }
714
+ async flush() {}
715
+ };
716
+
717
+ //#endregion
718
+ //#region src/FileManager.ts
719
+ var import_main = /* @__PURE__ */ require_chunk.__toESM(require_transformers.require_main(), 1);
720
+ var FileManager = class {
721
+ #cache = new Cache();
722
+ #limit = pLimit(100);
723
+ constructor() {
724
+ return this;
725
+ }
726
+ async add(...files) {
727
+ const resolvedFiles = [];
728
+ const mergedFiles = /* @__PURE__ */ new Map();
729
+ files.forEach((file) => {
730
+ const existing = mergedFiles.get(file.path);
731
+ if (existing) mergedFiles.set(file.path, mergeFile(existing, file));
732
+ else mergedFiles.set(file.path, file);
733
+ });
734
+ for (const file of mergedFiles.values()) {
735
+ const existing = await this.#cache.get(file.path);
736
+ const merged = existing ? mergeFile(existing, file) : file;
737
+ const resolvedFile = createFile(merged);
738
+ await this.#cache.set(resolvedFile.path, resolvedFile);
739
+ await this.#cache.flush();
740
+ resolvedFiles.push(resolvedFile);
741
+ }
742
+ if (files.length > 1) return resolvedFiles;
743
+ return resolvedFiles[0];
744
+ }
745
+ async getByPath(path$1) {
746
+ return this.#cache.get(path$1);
747
+ }
748
+ async deleteByPath(path$1) {
749
+ await this.#cache.delete(path$1);
750
+ }
751
+ async clear() {
752
+ await this.#cache.clear();
753
+ }
754
+ async getFiles() {
755
+ const cachedKeys = await this.#cache.keys();
756
+ const keys = (0, import_main.orderBy)(cachedKeys, [(v) => v.length, (v) => require_fs.trimExtName(v).endsWith("index")]);
757
+ const filesTasks = keys.map((key) => this.#limit(async () => {
758
+ const file = await this.#cache.get(key);
759
+ return file;
760
+ }));
761
+ const files = await Promise.all(filesTasks);
762
+ return files.filter(Boolean);
763
+ }
764
+ async processFiles({ dryRun, root, extension, logger }) {
765
+ const files = await this.getFiles();
766
+ logger?.emit("progress_start", {
767
+ id: "files",
768
+ size: files.length,
769
+ message: "Writing files ..."
770
+ });
771
+ const promises = files.map((file) => {
772
+ return this.#limit(async () => {
773
+ const message = file ? `Writing ${(0, node_path.relative)(root, file.path)}` : "";
774
+ const extname$1 = extension?.[file.extname] || void 0;
775
+ if (!dryRun) {
776
+ const source = await getSource(file, {
777
+ logger,
778
+ extname: extname$1
779
+ });
780
+ await require_write.write(file.path, source, { sanity: false });
781
+ }
782
+ logger?.emit("progressed", {
783
+ id: "files",
784
+ message
785
+ });
786
+ });
787
+ });
788
+ await Promise.all(promises);
789
+ logger?.emit("progress_stop", { id: "files" });
790
+ return files;
791
+ }
792
+ async getBarrelFiles({ type, meta = {}, root, output, logger }) {
793
+ if (!type || type === "propagate") return [];
794
+ const barrelManager = new BarrelManager({ logger });
795
+ const files = await this.getFiles();
796
+ const pathToBuildFrom = (0, node_path.join)(root, output.path);
797
+ if (require_fs.trimExtName(pathToBuildFrom).endsWith("index")) {
798
+ logger?.emit("warning", "Output has the same fileName as the barrelFiles, please disable barrel generation");
799
+ return [];
800
+ }
801
+ const barrelFiles = barrelManager.getFiles({
802
+ files,
803
+ root: pathToBuildFrom,
804
+ meta
805
+ });
806
+ if (type === "all") return barrelFiles.map((file) => {
807
+ return {
808
+ ...file,
809
+ exports: file.exports?.map((exportItem) => {
810
+ return {
811
+ ...exportItem,
812
+ name: void 0
813
+ };
814
+ })
815
+ };
816
+ });
817
+ return barrelFiles.map((indexFile) => {
818
+ return {
819
+ ...indexFile,
820
+ meta
821
+ };
822
+ });
823
+ }
824
+ static getMode(path$1) {
825
+ if (!path$1) return "split";
826
+ return (0, node_path.extname)(path$1) ? "single" : "split";
827
+ }
828
+ };
829
+ async function getSource(file, { logger, extname: extname$1 } = {}) {
830
+ const parser = await getFileParser(file.extname);
831
+ const source = await parser.print(file, {
832
+ logger,
833
+ extname: extname$1
834
+ });
835
+ return parser.format(source).catch((err) => {
836
+ console.warn(err);
837
+ return source;
838
+ });
839
+ }
840
+ function mergeFile(a, b) {
841
+ return {
842
+ ...a,
843
+ sources: [...a.sources || [], ...b.sources || []],
844
+ imports: [...a.imports || [], ...b.imports || []],
845
+ exports: [...a.exports || [], ...b.exports || []]
846
+ };
847
+ }
848
+ function combineSources(sources) {
849
+ return (0, remeda.uniqueBy)(sources, (obj) => [
850
+ obj.name,
851
+ obj.isExportable,
852
+ obj.isTypeOnly
853
+ ]);
854
+ }
855
+ function combineExports(exports$1) {
856
+ return (0, import_main.orderBy)(exports$1, [
857
+ (v) => !!Array.isArray(v.name),
858
+ (v) => !v.isTypeOnly,
859
+ (v) => v.path,
860
+ (v) => !!v.name,
861
+ (v) => Array.isArray(v.name) ? (0, import_main.orderBy)(v.name) : v.name
862
+ ]).reduce((prev, curr) => {
863
+ const name = curr.name;
864
+ const prevByPath = prev.findLast((imp) => imp.path === curr.path);
865
+ const prevByPathAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && (0, remeda.isDeepEqual)(imp.name, name) && imp.isTypeOnly);
866
+ if (prevByPathAndIsTypeOnly) return prev;
867
+ const uniquePrev = prev.findLast((imp) => imp.path === curr.path && (0, remeda.isDeepEqual)(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly && imp.asAlias === curr.asAlias);
868
+ if (uniquePrev || Array.isArray(name) && !name.length || prevByPath?.asAlias && !curr.asAlias) return prev;
869
+ if (!prevByPath) return [...prev, {
870
+ ...curr,
871
+ name: Array.isArray(name) ? [...new Set(name)] : name
872
+ }];
873
+ if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(curr.name) && prevByPath.isTypeOnly === curr.isTypeOnly) {
874
+ prevByPath.name = [...new Set([...prevByPath.name, ...curr.name])];
875
+ return prev;
876
+ }
877
+ return [...prev, curr];
878
+ }, []);
879
+ }
880
+ function combineImports(imports, exports$1, source) {
881
+ return (0, import_main.orderBy)(imports, [
882
+ (v) => !!Array.isArray(v.name),
883
+ (v) => !v.isTypeOnly,
884
+ (v) => v.path,
885
+ (v) => !!v.name,
886
+ (v) => Array.isArray(v.name) ? (0, import_main.orderBy)(v.name) : v.name
887
+ ]).reduce((prev, curr) => {
888
+ let name = Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name;
889
+ const hasImportInSource = (importName) => {
890
+ if (!source) return true;
891
+ const checker = (name$1) => {
892
+ return name$1 && source.includes(name$1);
893
+ };
894
+ return checker(importName) || exports$1.some(({ name: name$1 }) => Array.isArray(name$1) ? name$1.some(checker) : checker(name$1));
895
+ };
896
+ if (curr.path === curr.root) return prev;
897
+ if (Array.isArray(name)) name = name.filter((item) => typeof item === "string" ? hasImportInSource(item) : hasImportInSource(item.propertyName));
898
+ const prevByPath = prev.findLast((imp) => imp.path === curr.path && imp.isTypeOnly === curr.isTypeOnly);
899
+ const uniquePrev = prev.findLast((imp) => imp.path === curr.path && (0, remeda.isDeepEqual)(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly);
900
+ const prevByPathNameAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && (0, remeda.isDeepEqual)(imp.name, name) && imp.isTypeOnly);
901
+ if (prevByPathNameAndIsTypeOnly) return prev;
902
+ if (uniquePrev || Array.isArray(name) && !name.length) return prev;
903
+ if (!prevByPath) return [...prev, {
904
+ ...curr,
905
+ name
906
+ }];
907
+ if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(name) && prevByPath.isTypeOnly === curr.isTypeOnly) {
908
+ prevByPath.name = [...new Set([...prevByPath.name, ...name])];
909
+ return prev;
910
+ }
911
+ if (!Array.isArray(name) && name && !hasImportInSource(name)) return prev;
912
+ return [...prev, curr];
913
+ }, []);
914
+ }
915
+
916
+ //#endregion
917
+ Object.defineProperty(exports, 'Cache', {
918
+ enumerable: true,
919
+ get: function () {
920
+ return Cache;
921
+ }
922
+ });
923
+ Object.defineProperty(exports, 'FileManager', {
924
+ enumerable: true,
925
+ get: function () {
926
+ return FileManager;
927
+ }
928
+ });
929
+ Object.defineProperty(exports, 'FunctionParams', {
930
+ enumerable: true,
931
+ get: function () {
932
+ return FunctionParams;
933
+ }
934
+ });
935
+ Object.defineProperty(exports, 'URLPath', {
936
+ enumerable: true,
937
+ get: function () {
938
+ return URLPath;
939
+ }
940
+ });
941
+ Object.defineProperty(exports, 'createFile', {
942
+ enumerable: true,
943
+ get: function () {
944
+ return createFile;
945
+ }
946
+ });
947
+ Object.defineProperty(exports, 'createFileExport', {
948
+ enumerable: true,
949
+ get: function () {
950
+ return createFileExport;
951
+ }
952
+ });
953
+ Object.defineProperty(exports, 'createFileImport', {
954
+ enumerable: true,
955
+ get: function () {
956
+ return createFileImport;
957
+ }
958
+ });
959
+ Object.defineProperty(exports, 'createFileParser', {
960
+ enumerable: true,
961
+ get: function () {
962
+ return createFileParser;
963
+ }
964
+ });
965
+ Object.defineProperty(exports, 'getDefaultBanner', {
966
+ enumerable: true,
967
+ get: function () {
968
+ return getDefaultBanner;
969
+ }
970
+ });
971
+ Object.defineProperty(exports, 'getFileParser', {
972
+ enumerable: true,
973
+ get: function () {
974
+ return getFileParser;
975
+ }
976
+ });
977
+ Object.defineProperty(exports, 'getSource', {
978
+ enumerable: true,
979
+ get: function () {
980
+ return getSource;
981
+ }
982
+ });
983
+ Object.defineProperty(exports, 'getUniqueName', {
984
+ enumerable: true,
985
+ get: function () {
986
+ return getUniqueName;
987
+ }
988
+ });
989
+ Object.defineProperty(exports, 'isPromise', {
990
+ enumerable: true,
991
+ get: function () {
992
+ return isPromise;
993
+ }
994
+ });
995
+ Object.defineProperty(exports, 'isPromiseFulfilledResult', {
996
+ enumerable: true,
997
+ get: function () {
998
+ return isPromiseFulfilledResult;
999
+ }
1000
+ });
1001
+ Object.defineProperty(exports, 'isPromiseRejectedResult', {
1002
+ enumerable: true,
1003
+ get: function () {
1004
+ return isPromiseRejectedResult;
1005
+ }
1006
+ });
1007
+ Object.defineProperty(exports, 'pLimit', {
1008
+ enumerable: true,
1009
+ get: function () {
1010
+ return pLimit;
1011
+ }
1012
+ });
1013
+ Object.defineProperty(exports, 'renderTemplate', {
1014
+ enumerable: true,
1015
+ get: function () {
1016
+ return renderTemplate;
1017
+ }
1018
+ });
1019
+ Object.defineProperty(exports, 'setUniqueName', {
1020
+ enumerable: true,
1021
+ get: function () {
1022
+ return setUniqueName;
1023
+ }
1024
+ });
1025
+ Object.defineProperty(exports, 'timeout', {
1026
+ enumerable: true,
1027
+ get: function () {
1028
+ return timeout;
1029
+ }
1030
+ });
1031
+ //# sourceMappingURL=FileManager-DsRjYJa_.cjs.map