@kubb/core 3.16.2 → 3.16.3

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