@kubb/core 3.0.0-alpha.6 → 3.0.0-alpha.8

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 (72) hide show
  1. package/dist/{FileManager-wyXRkgIk.d.cts → FileManager-B0GJlthB.d.cts} +30 -16
  2. package/dist/{FileManager-Ceski1W9.d.ts → FileManager-BFycBDqG.d.ts} +30 -16
  3. package/dist/chunk-27CPVXAT.js +945 -0
  4. package/dist/chunk-27CPVXAT.js.map +1 -0
  5. package/dist/{chunk-34BPAXR2.cjs → chunk-5E2I6KH4.cjs} +7 -7
  6. package/dist/{chunk-34BPAXR2.cjs.map → chunk-5E2I6KH4.cjs.map} +1 -1
  7. package/dist/chunk-5IGANEGE.cjs +1564 -0
  8. package/dist/chunk-5IGANEGE.cjs.map +1 -0
  9. package/dist/{chunk-67C6RBGQ.cjs → chunk-A6PCLWEY.cjs} +5 -5
  10. package/dist/{chunk-67C6RBGQ.cjs.map → chunk-A6PCLWEY.cjs.map} +1 -1
  11. package/dist/{chunk-5HN4LW3R.cjs → chunk-DID47EQD.cjs} +3 -3
  12. package/dist/{chunk-5HN4LW3R.cjs.map → chunk-DID47EQD.cjs.map} +1 -1
  13. package/dist/{chunk-25NKJ3DV.js → chunk-HBQM723K.js} +6 -6
  14. package/dist/{chunk-LOLEBOMW.cjs → chunk-IPZQXBA2.cjs} +16 -21
  15. package/dist/chunk-IPZQXBA2.cjs.map +1 -0
  16. package/dist/{chunk-76UEJFFE.js → chunk-SCR3LUXT.js} +9 -16
  17. package/dist/{chunk-76UEJFFE.js.map → chunk-SCR3LUXT.js.map} +1 -1
  18. package/dist/{chunk-XCPFG6DO.cjs → chunk-SEH6NUCX.cjs} +4 -28
  19. package/dist/chunk-SEH6NUCX.cjs.map +1 -0
  20. package/dist/index.cjs +380 -378
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.d.cts +2 -2
  23. package/dist/index.d.ts +2 -2
  24. package/dist/index.js +325 -319
  25. package/dist/index.js.map +1 -1
  26. package/dist/logger.cjs +4 -4
  27. package/dist/logger.js +2 -3
  28. package/dist/mocks.cjs +20 -15
  29. package/dist/mocks.cjs.map +1 -1
  30. package/dist/mocks.d.cts +6 -5
  31. package/dist/mocks.d.ts +6 -5
  32. package/dist/mocks.js +15 -11
  33. package/dist/mocks.js.map +1 -1
  34. package/dist/{prompt-6FWP747F.cjs → prompt-DVQN7JTN.cjs} +61 -61
  35. package/dist/{prompt-6FWP747F.cjs.map → prompt-DVQN7JTN.cjs.map} +1 -1
  36. package/dist/{prompt-HK3MWREM.js → prompt-WQQUN22Z.js} +5 -6
  37. package/dist/{prompt-HK3MWREM.js.map → prompt-WQQUN22Z.js.map} +1 -1
  38. package/dist/transformers.cjs +19 -19
  39. package/dist/transformers.js +0 -1
  40. package/dist/transformers.js.map +1 -1
  41. package/dist/utils.cjs +8 -4
  42. package/dist/utils.cjs.map +1 -1
  43. package/dist/utils.d.cts +25 -24
  44. package/dist/utils.d.ts +25 -24
  45. package/dist/utils.js +5 -2
  46. package/package.json +7 -7
  47. package/src/BarrelManager.ts +90 -40
  48. package/src/FileManager.ts +89 -109
  49. package/src/PluginManager.ts +2 -1
  50. package/src/__snapshots__/barrel.json +91 -0
  51. package/src/__snapshots__/grouped.json +114 -0
  52. package/src/__snapshots__/ordered.json +62 -0
  53. package/src/build.ts +60 -23
  54. package/src/plugin.ts +2 -2
  55. package/src/types.ts +22 -2
  56. package/src/utils/TreeNode.ts +43 -1
  57. package/src/utils/index.ts +1 -1
  58. package/src/utils/parser.ts +128 -67
  59. package/dist/chunk-AWAZR3D5.js +0 -360
  60. package/dist/chunk-AWAZR3D5.js.map +0 -1
  61. package/dist/chunk-DCZQYCCO.cjs +0 -1155
  62. package/dist/chunk-DCZQYCCO.cjs.map +0 -1
  63. package/dist/chunk-HMLY7DHA.js +0 -16
  64. package/dist/chunk-HMLY7DHA.js.map +0 -1
  65. package/dist/chunk-L3JJLZ5Q.cjs +0 -371
  66. package/dist/chunk-L3JJLZ5Q.cjs.map +0 -1
  67. package/dist/chunk-LOLEBOMW.cjs.map +0 -1
  68. package/dist/chunk-RIEGCND2.js +0 -525
  69. package/dist/chunk-RIEGCND2.js.map +0 -1
  70. package/dist/chunk-XCPFG6DO.cjs.map +0 -1
  71. package/schema.json +0 -86
  72. /package/dist/{chunk-25NKJ3DV.js.map → chunk-HBQM723K.js.map} +0 -0
@@ -0,0 +1,1564 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;
2
+
3
+
4
+ var _chunkA6PCLWEYcjs = require('./chunk-A6PCLWEY.cjs');
5
+
6
+
7
+
8
+
9
+ var _chunkSEH6NUCXcjs = require('./chunk-SEH6NUCX.cjs');
10
+
11
+ // ../../node_modules/.pnpm/eventemitter3@5.0.1/node_modules/eventemitter3/index.js
12
+ var require_eventemitter3 = _chunkSEH6NUCXcjs.__commonJS.call(void 0, {
13
+ "../../node_modules/.pnpm/eventemitter3@5.0.1/node_modules/eventemitter3/index.js"(exports, module) {
14
+ "use strict";
15
+ _chunkSEH6NUCXcjs.init_cjs_shims.call(void 0, );
16
+ var has = Object.prototype.hasOwnProperty;
17
+ var prefix = "~";
18
+ function Events() {
19
+ }
20
+ if (Object.create) {
21
+ Events.prototype = /* @__PURE__ */ Object.create(null);
22
+ if (!new Events().__proto__) prefix = false;
23
+ }
24
+ function EE(fn, context, once) {
25
+ this.fn = fn;
26
+ this.context = context;
27
+ this.once = once || false;
28
+ }
29
+ function addListener(emitter, event, fn, context, once) {
30
+ if (typeof fn !== "function") {
31
+ throw new TypeError("The listener must be a function");
32
+ }
33
+ var listener = new EE(fn, context || emitter, once), evt = prefix ? prefix + event : event;
34
+ if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;
35
+ else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);
36
+ else emitter._events[evt] = [emitter._events[evt], listener];
37
+ return emitter;
38
+ }
39
+ function clearEvent(emitter, evt) {
40
+ if (--emitter._eventsCount === 0) emitter._events = new Events();
41
+ else delete emitter._events[evt];
42
+ }
43
+ function EventEmitter2() {
44
+ this._events = new Events();
45
+ this._eventsCount = 0;
46
+ }
47
+ EventEmitter2.prototype.eventNames = function eventNames() {
48
+ var names = [], events, name;
49
+ if (this._eventsCount === 0) return names;
50
+ for (name in events = this._events) {
51
+ if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
52
+ }
53
+ if (Object.getOwnPropertySymbols) {
54
+ return names.concat(Object.getOwnPropertySymbols(events));
55
+ }
56
+ return names;
57
+ };
58
+ EventEmitter2.prototype.listeners = function listeners(event) {
59
+ var evt = prefix ? prefix + event : event, handlers = this._events[evt];
60
+ if (!handlers) return [];
61
+ if (handlers.fn) return [handlers.fn];
62
+ for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
63
+ ee[i] = handlers[i].fn;
64
+ }
65
+ return ee;
66
+ };
67
+ EventEmitter2.prototype.listenerCount = function listenerCount(event) {
68
+ var evt = prefix ? prefix + event : event, listeners = this._events[evt];
69
+ if (!listeners) return 0;
70
+ if (listeners.fn) return 1;
71
+ return listeners.length;
72
+ };
73
+ EventEmitter2.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
74
+ var evt = prefix ? prefix + event : event;
75
+ if (!this._events[evt]) return false;
76
+ var listeners = this._events[evt], len = arguments.length, args, i;
77
+ if (listeners.fn) {
78
+ if (listeners.once) this.removeListener(event, listeners.fn, void 0, true);
79
+ switch (len) {
80
+ case 1:
81
+ return listeners.fn.call(listeners.context), true;
82
+ case 2:
83
+ return listeners.fn.call(listeners.context, a1), true;
84
+ case 3:
85
+ return listeners.fn.call(listeners.context, a1, a2), true;
86
+ case 4:
87
+ return listeners.fn.call(listeners.context, a1, a2, a3), true;
88
+ case 5:
89
+ return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
90
+ case 6:
91
+ return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
92
+ }
93
+ for (i = 1, args = new Array(len - 1); i < len; i++) {
94
+ args[i - 1] = arguments[i];
95
+ }
96
+ listeners.fn.apply(listeners.context, args);
97
+ } else {
98
+ var length = listeners.length, j;
99
+ for (i = 0; i < length; i++) {
100
+ if (listeners[i].once) this.removeListener(event, listeners[i].fn, void 0, true);
101
+ switch (len) {
102
+ case 1:
103
+ listeners[i].fn.call(listeners[i].context);
104
+ break;
105
+ case 2:
106
+ listeners[i].fn.call(listeners[i].context, a1);
107
+ break;
108
+ case 3:
109
+ listeners[i].fn.call(listeners[i].context, a1, a2);
110
+ break;
111
+ case 4:
112
+ listeners[i].fn.call(listeners[i].context, a1, a2, a3);
113
+ break;
114
+ default:
115
+ if (!args) for (j = 1, args = new Array(len - 1); j < len; j++) {
116
+ args[j - 1] = arguments[j];
117
+ }
118
+ listeners[i].fn.apply(listeners[i].context, args);
119
+ }
120
+ }
121
+ }
122
+ return true;
123
+ };
124
+ EventEmitter2.prototype.on = function on(event, fn, context) {
125
+ return addListener(this, event, fn, context, false);
126
+ };
127
+ EventEmitter2.prototype.once = function once(event, fn, context) {
128
+ return addListener(this, event, fn, context, true);
129
+ };
130
+ EventEmitter2.prototype.removeListener = function removeListener(event, fn, context, once) {
131
+ var evt = prefix ? prefix + event : event;
132
+ if (!this._events[evt]) return this;
133
+ if (!fn) {
134
+ clearEvent(this, evt);
135
+ return this;
136
+ }
137
+ var listeners = this._events[evt];
138
+ if (listeners.fn) {
139
+ if (listeners.fn === fn && (!once || listeners.once) && (!context || listeners.context === context)) {
140
+ clearEvent(this, evt);
141
+ }
142
+ } else {
143
+ for (var i = 0, events = [], length = listeners.length; i < length; i++) {
144
+ if (listeners[i].fn !== fn || once && !listeners[i].once || context && listeners[i].context !== context) {
145
+ events.push(listeners[i]);
146
+ }
147
+ }
148
+ if (events.length) this._events[evt] = events.length === 1 ? events[0] : events;
149
+ else clearEvent(this, evt);
150
+ }
151
+ return this;
152
+ };
153
+ EventEmitter2.prototype.removeAllListeners = function removeAllListeners(event) {
154
+ var evt;
155
+ if (event) {
156
+ evt = prefix ? prefix + event : event;
157
+ if (this._events[evt]) clearEvent(this, evt);
158
+ } else {
159
+ this._events = new Events();
160
+ this._eventsCount = 0;
161
+ }
162
+ return this;
163
+ };
164
+ EventEmitter2.prototype.off = EventEmitter2.prototype.removeListener;
165
+ EventEmitter2.prototype.addListener = EventEmitter2.prototype.on;
166
+ EventEmitter2.prefixed = prefix;
167
+ EventEmitter2.EventEmitter = EventEmitter2;
168
+ if ("undefined" !== typeof module) {
169
+ module.exports = EventEmitter2;
170
+ }
171
+ }
172
+ });
173
+
174
+ // src/utils/index.ts
175
+ _chunkSEH6NUCXcjs.init_cjs_shims.call(void 0, );
176
+
177
+ // src/utils/FunctionParams.ts
178
+ _chunkSEH6NUCXcjs.init_cjs_shims.call(void 0, );
179
+ var FunctionParams = class _FunctionParams {
180
+ #items = [];
181
+ constructor() {
182
+ return this;
183
+ }
184
+ get items() {
185
+ return this.#items.flat();
186
+ }
187
+ add(item) {
188
+ if (!item) {
189
+ return this;
190
+ }
191
+ if (Array.isArray(item)) {
192
+ item.filter(Boolean).forEach((it) => this.#items.push(it));
193
+ return this;
194
+ }
195
+ this.#items.push(item);
196
+ return this;
197
+ }
198
+ static #orderItems(items) {
199
+ return _chunkA6PCLWEYcjs.orderBy.call(void 0,
200
+ items.filter(Boolean),
201
+ [
202
+ (v) => {
203
+ if (Array.isArray(v)) {
204
+ return void 0;
205
+ }
206
+ return !v.default;
207
+ },
208
+ (v) => {
209
+ if (Array.isArray(v)) {
210
+ return void 0;
211
+ }
212
+ return _nullishCoalesce(v.required, () => ( true));
213
+ }
214
+ ],
215
+ ["desc", "desc"]
216
+ );
217
+ }
218
+ static #addParams(acc, item) {
219
+ const { enabled = true, name, type, required = true, ...rest } = item;
220
+ if (!enabled) {
221
+ return acc;
222
+ }
223
+ if (!name) {
224
+ acc.push(`${type}${rest.default ? ` = ${rest.default}` : ""}`);
225
+ return acc;
226
+ }
227
+ const parameterName = name.startsWith("{") ? name : _chunkA6PCLWEYcjs.camelCase.call(void 0, name);
228
+ if (type) {
229
+ if (required) {
230
+ acc.push(`${parameterName}: ${type}${rest.default ? ` = ${rest.default}` : ""}`);
231
+ } else {
232
+ acc.push(`${parameterName}?: ${type}`);
233
+ }
234
+ } else {
235
+ acc.push(`${parameterName}`);
236
+ }
237
+ return acc;
238
+ }
239
+ static toObject(items) {
240
+ let type = [];
241
+ let name = [];
242
+ const enabled = items.every((item) => item.enabled) ? _optionalChain([items, 'access', _ => _.at, 'call', _2 => _2(0), 'optionalAccess', _3 => _3.enabled]) : true;
243
+ const required = _nullishCoalesce(items.every((item) => item.required), () => ( true));
244
+ items.forEach((item) => {
245
+ name = _FunctionParams.#addParams(name, { ...item, type: void 0 });
246
+ if (items.some((item2) => item2.type)) {
247
+ type = _FunctionParams.#addParams(type, item);
248
+ }
249
+ });
250
+ return {
251
+ name: `{ ${name.join(", ")} }`,
252
+ type: type.length ? `{ ${type.join("; ")} }` : void 0,
253
+ enabled,
254
+ required
255
+ };
256
+ }
257
+ static toString(items) {
258
+ const sortedData = _FunctionParams.#orderItems(items);
259
+ return sortedData.reduce((acc, item) => {
260
+ if (Array.isArray(item)) {
261
+ if (item.length <= 0) {
262
+ return acc;
263
+ }
264
+ const subItems = _FunctionParams.#orderItems(item);
265
+ const objectItem = _FunctionParams.toObject(subItems);
266
+ return _FunctionParams.#addParams(acc, objectItem);
267
+ }
268
+ return _FunctionParams.#addParams(acc, item);
269
+ }, []).join(", ");
270
+ }
271
+ toObject() {
272
+ const items = _FunctionParams.#orderItems(this.#items).flat();
273
+ return _FunctionParams.toObject(items);
274
+ }
275
+ toString() {
276
+ const items = _FunctionParams.#orderItems(this.#items);
277
+ return _FunctionParams.toString(items);
278
+ }
279
+ };
280
+
281
+ // src/utils/promise.ts
282
+ _chunkSEH6NUCXcjs.init_cjs_shims.call(void 0, );
283
+ function isPromise(result) {
284
+ return !!result && typeof _optionalChain([result, 'optionalAccess', _4 => _4.then]) === "function";
285
+ }
286
+ function isPromiseFulfilledResult(result) {
287
+ return result.status === "fulfilled";
288
+ }
289
+ function isPromiseRejectedResult(result) {
290
+ return result.status === "rejected";
291
+ }
292
+
293
+ // src/utils/renderTemplate.ts
294
+ _chunkSEH6NUCXcjs.init_cjs_shims.call(void 0, );
295
+ function renderTemplate(template, data = void 0) {
296
+ if (!data || !Object.keys(data).length) {
297
+ return template.replace(/{{(.*?)}}/g, "");
298
+ }
299
+ const matches = template.match(/{{(.*?)}}/g);
300
+ return _optionalChain([matches, 'optionalAccess', _5 => _5.reduce, 'call', _6 => _6((prev, curr) => {
301
+ const index = _optionalChain([curr, 'access', _7 => _7.split, 'call', _8 => _8(/{{|}}/), 'access', _9 => _9.filter, 'call', _10 => _10(Boolean), 'access', _11 => _11[0], 'optionalAccess', _12 => _12.trim, 'call', _13 => _13()]);
302
+ if (index === void 0) {
303
+ return prev;
304
+ }
305
+ const value = data[index];
306
+ if (value === void 0) {
307
+ return prev;
308
+ }
309
+ return prev.replace(curr, () => {
310
+ if (typeof value === "boolean") {
311
+ return `${value.toString()}` || "false";
312
+ }
313
+ return value || "";
314
+ }).trim();
315
+ }, template)]) || "";
316
+ }
317
+
318
+ // src/utils/timeout.ts
319
+ _chunkSEH6NUCXcjs.init_cjs_shims.call(void 0, );
320
+ async function timeout(ms) {
321
+ return new Promise((resolve) => {
322
+ setTimeout(() => {
323
+ resolve(true);
324
+ }, ms);
325
+ });
326
+ }
327
+
328
+ // src/utils/uniqueName.ts
329
+ _chunkSEH6NUCXcjs.init_cjs_shims.call(void 0, );
330
+ function getUniqueName(originalName, data) {
331
+ let used = data[originalName] || 0;
332
+ if (used) {
333
+ data[originalName] = ++used;
334
+ originalName += used;
335
+ }
336
+ data[originalName] = 1;
337
+ return originalName;
338
+ }
339
+ function setUniqueName(originalName, data) {
340
+ let used = data[originalName] || 0;
341
+ if (used) {
342
+ data[originalName] = ++used;
343
+ return originalName;
344
+ }
345
+ data[originalName] = 1;
346
+ return originalName;
347
+ }
348
+
349
+ // src/utils/URLPath.ts
350
+ _chunkSEH6NUCXcjs.init_cjs_shims.call(void 0, );
351
+ var URLPath = class {
352
+
353
+ constructor(path) {
354
+ this.path = path;
355
+ return this;
356
+ }
357
+ /**
358
+ * Convert Swagger path to URLPath(syntax of Express)
359
+ * @example /pet/{petId} => /pet/:petId
360
+ */
361
+ get URL() {
362
+ return this.toURLPath();
363
+ }
364
+ get isURL() {
365
+ try {
366
+ const url = new URL(this.path);
367
+ if (_optionalChain([url, 'optionalAccess', _14 => _14.href])) {
368
+ return true;
369
+ }
370
+ } catch (error) {
371
+ return false;
372
+ }
373
+ return false;
374
+ }
375
+ /**
376
+ * Convert Swagger path to template literals/ template strings(camelcase)
377
+ * @example /pet/{petId} => `/pet/${petId}`
378
+ * @example /account/monetary-accountID => `/account/${monetaryAccountId}`
379
+ * @example /account/userID => `/account/${userId}`
380
+ */
381
+ get template() {
382
+ return this.toTemplateString();
383
+ }
384
+ get object() {
385
+ return this.toObject();
386
+ }
387
+ get params() {
388
+ return this.getParams();
389
+ }
390
+ toObject({ type = "path", replacer, stringify } = {}) {
391
+ const object = {
392
+ url: type === "path" ? this.toURLPath() : this.toTemplateString(replacer),
393
+ params: this.getParams()
394
+ };
395
+ if (stringify) {
396
+ if (type === "template") {
397
+ return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
398
+ }
399
+ if (object.params) {
400
+ return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
401
+ }
402
+ return `{ url: '${object.url}' }`;
403
+ }
404
+ return object;
405
+ }
406
+ /**
407
+ * Convert Swagger path to template literals/ template strings(camelcase)
408
+ * @example /pet/{petId} => `/pet/${petId}`
409
+ * @example /account/monetary-accountID => `/account/${monetaryAccountId}`
410
+ * @example /account/userID => `/account/${userId}`
411
+ */
412
+ toTemplateString(replacer) {
413
+ const regex = /{(\w|-)*}/g;
414
+ const found = this.path.match(regex);
415
+ let newPath = this.path.replaceAll("{", "${");
416
+ if (found) {
417
+ newPath = found.reduce((prev, curr) => {
418
+ const pathParam = replacer ? replacer(_chunkA6PCLWEYcjs.camelCase.call(void 0, curr)) : _chunkA6PCLWEYcjs.camelCase.call(void 0, curr);
419
+ const replacement = `\${${pathParam}}`;
420
+ return prev.replace(curr, replacement);
421
+ }, this.path);
422
+ }
423
+ return `\`${newPath}\``;
424
+ }
425
+ getParams(replacer) {
426
+ const regex = /{(\w|-)*}/g;
427
+ const found = this.path.match(regex);
428
+ if (!found) {
429
+ return void 0;
430
+ }
431
+ const params = {};
432
+ found.forEach((item) => {
433
+ item = item.replaceAll("{", "").replaceAll("}", "");
434
+ const pathParam = replacer ? replacer(_chunkA6PCLWEYcjs.camelCase.call(void 0, item)) : _chunkA6PCLWEYcjs.camelCase.call(void 0, item);
435
+ params[pathParam] = pathParam;
436
+ }, this.path);
437
+ return params;
438
+ }
439
+ /**
440
+ * Convert Swagger path to URLPath(syntax of Express)
441
+ * @example /pet/{petId} => /pet/:petId
442
+ */
443
+ toURLPath() {
444
+ return this.path.replaceAll("{", ":").replaceAll("}", "");
445
+ }
446
+ };
447
+
448
+ // src/utils/parser.ts
449
+ _chunkSEH6NUCXcjs.init_cjs_shims.call(void 0, );
450
+ var _path = require('path');
451
+ var _fs = require('@kubb/fs');
452
+ var _objecthash = require('object-hash'); var _objecthash2 = _interopRequireDefault(_objecthash);
453
+
454
+ // src/FileManager.ts
455
+ _chunkSEH6NUCXcjs.init_cjs_shims.call(void 0, );
456
+
457
+ var _remeda = require('remeda');
458
+
459
+
460
+ // src/BarrelManager.ts
461
+ _chunkSEH6NUCXcjs.init_cjs_shims.call(void 0, );
462
+
463
+
464
+ // src/utils/TreeNode.ts
465
+ _chunkSEH6NUCXcjs.init_cjs_shims.call(void 0, );
466
+ var TreeNode = (_class = class _TreeNode {
467
+
468
+
469
+ __init() {this.children = []}
470
+ constructor(data, parent) {;_class.prototype.__init.call(this);
471
+ this.data = data;
472
+ this.parent = parent;
473
+ return this;
474
+ }
475
+ addChild(data) {
476
+ const child = new _TreeNode(data, this);
477
+ if (!this.children) {
478
+ this.children = [];
479
+ }
480
+ this.children.push(child);
481
+ return child;
482
+ }
483
+ find(data) {
484
+ if (!data) {
485
+ return null;
486
+ }
487
+ if (data === this.data) {
488
+ return this;
489
+ }
490
+ if (_optionalChain([this, 'access', _15 => _15.children, 'optionalAccess', _16 => _16.length])) {
491
+ for (let i = 0, { length } = this.children, target = null; i < length; i++) {
492
+ target = this.children[i].find(data);
493
+ if (target) {
494
+ return target;
495
+ }
496
+ }
497
+ }
498
+ return null;
499
+ }
500
+ get leaves() {
501
+ if (!this.children || this.children.length === 0) {
502
+ return [this];
503
+ }
504
+ const leaves = [];
505
+ if (this.children) {
506
+ for (let i = 0, { length } = this.children; i < length; i++) {
507
+ leaves.push.apply(leaves, this.children[i].leaves);
508
+ }
509
+ }
510
+ return leaves;
511
+ }
512
+ get root() {
513
+ if (!this.parent) {
514
+ return this;
515
+ }
516
+ return this.parent.root;
517
+ }
518
+ forEach(callback) {
519
+ if (typeof callback !== "function") {
520
+ throw new TypeError("forEach() callback must be a function");
521
+ }
522
+ callback(this);
523
+ if (this.children) {
524
+ for (let i = 0, { length } = this.children; i < length; i++) {
525
+ _optionalChain([this, 'access', _17 => _17.children, 'access', _18 => _18[i], 'optionalAccess', _19 => _19.forEach, 'call', _20 => _20(callback)]);
526
+ }
527
+ }
528
+ return this;
529
+ }
530
+ filter(callback) {
531
+ let data = [];
532
+ if (typeof callback !== "function") {
533
+ throw new TypeError("forEach() callback must be a function");
534
+ }
535
+ if (callback(this)) {
536
+ data.push(this);
537
+ }
538
+ if (this.children) {
539
+ for (let i = 0, { length } = this.children; i < length; i++) {
540
+ const childData = _optionalChain([this, 'access', _21 => _21.children, 'access', _22 => _22[i], 'optionalAccess', _23 => _23.filter, 'call', _24 => _24(callback), 'access', _25 => _25.filter, 'call', _26 => _26(Boolean)]) || [];
541
+ data = [.../* @__PURE__ */ new Set([...data, ...childData])];
542
+ }
543
+ }
544
+ return data;
545
+ }
546
+ map(callback) {
547
+ let data = [];
548
+ if (typeof callback !== "function") {
549
+ throw new TypeError("forEach() callback must be a function");
550
+ }
551
+ data.push(callback(this));
552
+ if (this.children) {
553
+ for (let i = 0, { length } = this.children; i < length; i++) {
554
+ const childData = _optionalChain([this, 'access', _27 => _27.children, 'access', _28 => _28[i], 'optionalAccess', _29 => _29.map, 'call', _30 => _30(callback), 'access', _31 => _31.filter, 'call', _32 => _32(Boolean)]) || [];
555
+ data = [.../* @__PURE__ */ new Set([...data, ...childData])];
556
+ }
557
+ }
558
+ return data;
559
+ }
560
+ static build(files, root) {
561
+ try {
562
+ const filteredTree = buildDirectoryTree(files, root);
563
+ if (!filteredTree) {
564
+ return null;
565
+ }
566
+ const treeNode = new _TreeNode({
567
+ name: filteredTree.name,
568
+ path: filteredTree.path,
569
+ file: filteredTree.file,
570
+ type: FileManager.getMode(filteredTree.path)
571
+ });
572
+ const recurse = (node, item) => {
573
+ const subNode = node.addChild({
574
+ name: item.name,
575
+ path: item.path,
576
+ file: item.file,
577
+ type: FileManager.getMode(item.path)
578
+ });
579
+ if (_optionalChain([item, 'access', _33 => _33.children, 'optionalAccess', _34 => _34.length])) {
580
+ _optionalChain([item, 'access', _35 => _35.children, 'optionalAccess', _36 => _36.forEach, 'call', _37 => _37((child) => {
581
+ recurse(subNode, child);
582
+ })]);
583
+ }
584
+ };
585
+ _optionalChain([filteredTree, 'access', _38 => _38.children, 'optionalAccess', _39 => _39.forEach, 'call', _40 => _40((child) => recurse(treeNode, child))]);
586
+ return treeNode;
587
+ } catch (e) {
588
+ throw new Error("Something went wrong with creating barrel files with the TreeNode class", { cause: e });
589
+ }
590
+ }
591
+ }, _class);
592
+ function buildDirectoryTree(files, rootFolder = "") {
593
+ const rootPrefix = rootFolder.endsWith("/") ? rootFolder : `${rootFolder}/`;
594
+ const filteredFiles = files.filter((file) => rootFolder ? file.path.startsWith(rootPrefix) && !file.path.endsWith(".json") : !file.path.endsWith(".json"));
595
+ if (filteredFiles.length === 0) {
596
+ return null;
597
+ }
598
+ const root = {
599
+ name: rootFolder || "",
600
+ path: rootFolder || "",
601
+ children: []
602
+ };
603
+ filteredFiles.forEach((file) => {
604
+ const path = file.path.slice(rootFolder.length);
605
+ const parts = path.split("/");
606
+ let currentLevel = root.children;
607
+ let currentPath = rootFolder;
608
+ parts.forEach((part, index) => {
609
+ if (index !== 0) {
610
+ currentPath += `/${part}`;
611
+ } else {
612
+ currentPath += `${part}`;
613
+ }
614
+ let existingNode = currentLevel.find((node) => node.name === part);
615
+ if (!existingNode) {
616
+ if (index === parts.length - 1) {
617
+ existingNode = {
618
+ name: part,
619
+ file,
620
+ path: currentPath
621
+ };
622
+ } else {
623
+ existingNode = {
624
+ name: part,
625
+ path: currentPath,
626
+ children: []
627
+ };
628
+ }
629
+ currentLevel.push(existingNode);
630
+ }
631
+ if (!existingNode.file) {
632
+ currentLevel = existingNode.children;
633
+ }
634
+ });
635
+ });
636
+ return root;
637
+ }
638
+
639
+ // src/BarrelManager.ts
640
+
641
+ var BarrelManager = class {
642
+ #options;
643
+ constructor(options = {}) {
644
+ this.#options = options;
645
+ return this;
646
+ }
647
+ getFiles(generatedFiles, root) {
648
+ const { logger } = this.#options;
649
+ const files = /* @__PURE__ */ new Map();
650
+ _optionalChain([TreeNode, 'access', _41 => _41.build, 'call', _42 => _42(generatedFiles, root), 'optionalAccess', _43 => _43.forEach, 'call', _44 => _44((treeNode) => {
651
+ if (!treeNode || !treeNode.children || !_optionalChain([treeNode, 'access', _45 => _45.parent, 'optionalAccess', _46 => _46.data, 'access', _47 => _47.path])) {
652
+ return void 0;
653
+ }
654
+ const barrelPath = _path.join.call(void 0, _optionalChain([treeNode, 'access', _48 => _48.parent, 'optionalAccess', _49 => _49.data, 'access', _50 => _50.path]), "index.ts");
655
+ const leaves = treeNode.leaves;
656
+ const exports = leaves.map((item) => {
657
+ if (!item.data.name) {
658
+ return void 0;
659
+ }
660
+ const sources = _optionalChain([item, 'access', _51 => _51.data, 'access', _52 => _52.file, 'optionalAccess', _53 => _53.sources]) || [];
661
+ if (!sources.some((source) => source.isIndexable)) {
662
+ _optionalChain([logger, 'optionalAccess', _54 => _54.emit, 'call', _55 => _55(
663
+ "warning",
664
+ `No isIndexable source found(source should have a name and isIndexable):
665
+ File: ${JSON.stringify(item.data.file, void 0, 2)}`
666
+ )]);
667
+ }
668
+ return sources.map((source) => {
669
+ if (!_optionalChain([item, 'access', _56 => _56.data, 'access', _57 => _57.file, 'optionalAccess', _58 => _58.path]) || !source.isIndexable) {
670
+ return void 0;
671
+ }
672
+ const isSubExport = !!_optionalChain([treeNode, 'access', _59 => _59.parent, 'optionalAccess', _60 => _60.data, 'access', _61 => _61.path, 'optionalAccess', _62 => _62.split, 'optionalCall', _63 => _63("/"), 'optionalAccess', _64 => _64.length]);
673
+ if (isSubExport) {
674
+ return {
675
+ name: [source.name],
676
+ path: _fs.getRelativePath.call(void 0, _optionalChain([treeNode, 'access', _65 => _65.parent, 'optionalAccess', _66 => _66.data, 'access', _67 => _67.path]), item.data.path),
677
+ isTypeOnly: source.isTypeOnly
678
+ };
679
+ }
680
+ return {
681
+ name: [source.name],
682
+ path: `./${item.data.file.baseName}`,
683
+ isTypeOnly: source.isTypeOnly
684
+ };
685
+ });
686
+ }).flat().filter(Boolean);
687
+ const barrelFile = {
688
+ path: barrelPath,
689
+ baseName: "index.ts",
690
+ exports,
691
+ sources: exports.flatMap((item) => {
692
+ if (Array.isArray(item.name)) {
693
+ return item.name.map((name) => {
694
+ return {
695
+ name,
696
+ isTypeOnly: item.isTypeOnly,
697
+ //TODO use parser to generate import
698
+ value: "",
699
+ isExportable: false,
700
+ isIndexable: false
701
+ };
702
+ });
703
+ }
704
+ return [
705
+ {
706
+ name: item.name,
707
+ isTypeOnly: item.isTypeOnly,
708
+ //TODO use parser to generate import
709
+ value: "",
710
+ isExportable: false,
711
+ isIndexable: false
712
+ }
713
+ ];
714
+ })
715
+ };
716
+ const previousBarrelFile = files.get(barrelFile.path);
717
+ if (previousBarrelFile) {
718
+ files.set(barrelFile.path, {
719
+ ...previousBarrelFile,
720
+ ...barrelFile,
721
+ exports: combineExports([...previousBarrelFile.exports || [], ...barrelFile.exports || []]),
722
+ sources: combineSources([...previousBarrelFile.sources || [], ...barrelFile.sources || []])
723
+ });
724
+ } else {
725
+ files.set(barrelFile.path, barrelFile);
726
+ }
727
+ })]);
728
+ return [...files.values()];
729
+ }
730
+ };
731
+
732
+ // src/FileManager.ts
733
+
734
+
735
+ // ../../node_modules/.pnpm/p-queue@8.0.1/node_modules/p-queue/dist/index.js
736
+ _chunkSEH6NUCXcjs.init_cjs_shims.call(void 0, );
737
+
738
+ // ../../node_modules/.pnpm/eventemitter3@5.0.1/node_modules/eventemitter3/index.mjs
739
+ _chunkSEH6NUCXcjs.init_cjs_shims.call(void 0, );
740
+ var import_index = _chunkSEH6NUCXcjs.__toESM.call(void 0, require_eventemitter3(), 1);
741
+
742
+ // ../../node_modules/.pnpm/p-timeout@6.1.2/node_modules/p-timeout/index.js
743
+ _chunkSEH6NUCXcjs.init_cjs_shims.call(void 0, );
744
+ var TimeoutError = class extends Error {
745
+ constructor(message) {
746
+ super(message);
747
+ this.name = "TimeoutError";
748
+ }
749
+ };
750
+ var AbortError = class extends Error {
751
+ constructor(message) {
752
+ super();
753
+ this.name = "AbortError";
754
+ this.message = message;
755
+ }
756
+ };
757
+ var getDOMException = (errorMessage) => globalThis.DOMException === void 0 ? new AbortError(errorMessage) : new DOMException(errorMessage);
758
+ var getAbortedReason = (signal) => {
759
+ const reason = signal.reason === void 0 ? getDOMException("This operation was aborted.") : signal.reason;
760
+ return reason instanceof Error ? reason : getDOMException(reason);
761
+ };
762
+ function pTimeout(promise, options) {
763
+ const {
764
+ milliseconds,
765
+ fallback,
766
+ message,
767
+ customTimers = { setTimeout, clearTimeout }
768
+ } = options;
769
+ let timer;
770
+ const wrappedPromise = new Promise((resolve, reject) => {
771
+ if (typeof milliseconds !== "number" || Math.sign(milliseconds) !== 1) {
772
+ throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${milliseconds}\``);
773
+ }
774
+ if (options.signal) {
775
+ const { signal } = options;
776
+ if (signal.aborted) {
777
+ reject(getAbortedReason(signal));
778
+ }
779
+ signal.addEventListener("abort", () => {
780
+ reject(getAbortedReason(signal));
781
+ });
782
+ }
783
+ if (milliseconds === Number.POSITIVE_INFINITY) {
784
+ promise.then(resolve, reject);
785
+ return;
786
+ }
787
+ const timeoutError = new TimeoutError();
788
+ timer = customTimers.setTimeout.call(void 0, () => {
789
+ if (fallback) {
790
+ try {
791
+ resolve(fallback());
792
+ } catch (error) {
793
+ reject(error);
794
+ }
795
+ return;
796
+ }
797
+ if (typeof promise.cancel === "function") {
798
+ promise.cancel();
799
+ }
800
+ if (message === false) {
801
+ resolve();
802
+ } else if (message instanceof Error) {
803
+ reject(message);
804
+ } else {
805
+ timeoutError.message = _nullishCoalesce(message, () => ( `Promise timed out after ${milliseconds} milliseconds`));
806
+ reject(timeoutError);
807
+ }
808
+ }, milliseconds);
809
+ (async () => {
810
+ try {
811
+ resolve(await promise);
812
+ } catch (error) {
813
+ reject(error);
814
+ }
815
+ })();
816
+ });
817
+ const cancelablePromise = wrappedPromise.finally(() => {
818
+ cancelablePromise.clear();
819
+ });
820
+ cancelablePromise.clear = () => {
821
+ customTimers.clearTimeout.call(void 0, timer);
822
+ timer = void 0;
823
+ };
824
+ return cancelablePromise;
825
+ }
826
+
827
+ // ../../node_modules/.pnpm/p-queue@8.0.1/node_modules/p-queue/dist/priority-queue.js
828
+ _chunkSEH6NUCXcjs.init_cjs_shims.call(void 0, );
829
+
830
+ // ../../node_modules/.pnpm/p-queue@8.0.1/node_modules/p-queue/dist/lower-bound.js
831
+ _chunkSEH6NUCXcjs.init_cjs_shims.call(void 0, );
832
+ function lowerBound(array, value, comparator) {
833
+ let first = 0;
834
+ let count = array.length;
835
+ while (count > 0) {
836
+ const step = Math.trunc(count / 2);
837
+ let it = first + step;
838
+ if (comparator(array[it], value) <= 0) {
839
+ first = ++it;
840
+ count -= step + 1;
841
+ } else {
842
+ count = step;
843
+ }
844
+ }
845
+ return first;
846
+ }
847
+
848
+ // ../../node_modules/.pnpm/p-queue@8.0.1/node_modules/p-queue/dist/priority-queue.js
849
+ var PriorityQueue = class {
850
+ #queue = [];
851
+ enqueue(run, options) {
852
+ options = {
853
+ priority: 0,
854
+ ...options
855
+ };
856
+ const element = {
857
+ priority: options.priority,
858
+ run
859
+ };
860
+ if (this.size && this.#queue[this.size - 1].priority >= options.priority) {
861
+ this.#queue.push(element);
862
+ return;
863
+ }
864
+ const index = lowerBound(this.#queue, element, (a, b) => b.priority - a.priority);
865
+ this.#queue.splice(index, 0, element);
866
+ }
867
+ dequeue() {
868
+ const item = this.#queue.shift();
869
+ return _optionalChain([item, 'optionalAccess', _68 => _68.run]);
870
+ }
871
+ filter(options) {
872
+ return this.#queue.filter((element) => element.priority === options.priority).map((element) => element.run);
873
+ }
874
+ get size() {
875
+ return this.#queue.length;
876
+ }
877
+ };
878
+
879
+ // ../../node_modules/.pnpm/p-queue@8.0.1/node_modules/p-queue/dist/index.js
880
+ var PQueue = class extends import_index.default {
881
+ #carryoverConcurrencyCount;
882
+ #isIntervalIgnored;
883
+ #intervalCount = 0;
884
+ #intervalCap;
885
+ #interval;
886
+ #intervalEnd = 0;
887
+ #intervalId;
888
+ #timeoutId;
889
+ #queue;
890
+ #queueClass;
891
+ #pending = 0;
892
+ // The `!` is needed because of https://github.com/microsoft/TypeScript/issues/32194
893
+ #concurrency;
894
+ #isPaused;
895
+ #throwOnTimeout;
896
+ /**
897
+ Per-operation timeout in milliseconds. Operations fulfill once `timeout` elapses if they haven't already.
898
+
899
+ Applies to each future operation.
900
+ */
901
+
902
+ // TODO: The `throwOnTimeout` option should affect the return types of `add()` and `addAll()`
903
+ constructor(options) {
904
+ super();
905
+ options = {
906
+ carryoverConcurrencyCount: false,
907
+ intervalCap: Number.POSITIVE_INFINITY,
908
+ interval: 0,
909
+ concurrency: Number.POSITIVE_INFINITY,
910
+ autoStart: true,
911
+ queueClass: PriorityQueue,
912
+ ...options
913
+ };
914
+ if (!(typeof options.intervalCap === "number" && options.intervalCap >= 1)) {
915
+ throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${_nullishCoalesce(_optionalChain([options, 'access', _69 => _69.intervalCap, 'optionalAccess', _70 => _70.toString, 'call', _71 => _71()]), () => ( ""))}\` (${typeof options.intervalCap})`);
916
+ }
917
+ if (options.interval === void 0 || !(Number.isFinite(options.interval) && options.interval >= 0)) {
918
+ throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${_nullishCoalesce(_optionalChain([options, 'access', _72 => _72.interval, 'optionalAccess', _73 => _73.toString, 'call', _74 => _74()]), () => ( ""))}\` (${typeof options.interval})`);
919
+ }
920
+ this.#carryoverConcurrencyCount = options.carryoverConcurrencyCount;
921
+ this.#isIntervalIgnored = options.intervalCap === Number.POSITIVE_INFINITY || options.interval === 0;
922
+ this.#intervalCap = options.intervalCap;
923
+ this.#interval = options.interval;
924
+ this.#queue = new options.queueClass();
925
+ this.#queueClass = options.queueClass;
926
+ this.concurrency = options.concurrency;
927
+ this.timeout = options.timeout;
928
+ this.#throwOnTimeout = options.throwOnTimeout === true;
929
+ this.#isPaused = options.autoStart === false;
930
+ }
931
+ get #doesIntervalAllowAnother() {
932
+ return this.#isIntervalIgnored || this.#intervalCount < this.#intervalCap;
933
+ }
934
+ get #doesConcurrentAllowAnother() {
935
+ return this.#pending < this.#concurrency;
936
+ }
937
+ #next() {
938
+ this.#pending--;
939
+ this.#tryToStartAnother();
940
+ this.emit("next");
941
+ }
942
+ #onResumeInterval() {
943
+ this.#onInterval();
944
+ this.#initializeIntervalIfNeeded();
945
+ this.#timeoutId = void 0;
946
+ }
947
+ get #isIntervalPaused() {
948
+ const now = Date.now();
949
+ if (this.#intervalId === void 0) {
950
+ const delay = this.#intervalEnd - now;
951
+ if (delay < 0) {
952
+ this.#intervalCount = this.#carryoverConcurrencyCount ? this.#pending : 0;
953
+ } else {
954
+ if (this.#timeoutId === void 0) {
955
+ this.#timeoutId = setTimeout(() => {
956
+ this.#onResumeInterval();
957
+ }, delay);
958
+ }
959
+ return true;
960
+ }
961
+ }
962
+ return false;
963
+ }
964
+ #tryToStartAnother() {
965
+ if (this.#queue.size === 0) {
966
+ if (this.#intervalId) {
967
+ clearInterval(this.#intervalId);
968
+ }
969
+ this.#intervalId = void 0;
970
+ this.emit("empty");
971
+ if (this.#pending === 0) {
972
+ this.emit("idle");
973
+ }
974
+ return false;
975
+ }
976
+ if (!this.#isPaused) {
977
+ const canInitializeInterval = !this.#isIntervalPaused;
978
+ if (this.#doesIntervalAllowAnother && this.#doesConcurrentAllowAnother) {
979
+ const job = this.#queue.dequeue();
980
+ if (!job) {
981
+ return false;
982
+ }
983
+ this.emit("active");
984
+ job();
985
+ if (canInitializeInterval) {
986
+ this.#initializeIntervalIfNeeded();
987
+ }
988
+ return true;
989
+ }
990
+ }
991
+ return false;
992
+ }
993
+ #initializeIntervalIfNeeded() {
994
+ if (this.#isIntervalIgnored || this.#intervalId !== void 0) {
995
+ return;
996
+ }
997
+ this.#intervalId = setInterval(() => {
998
+ this.#onInterval();
999
+ }, this.#interval);
1000
+ this.#intervalEnd = Date.now() + this.#interval;
1001
+ }
1002
+ #onInterval() {
1003
+ if (this.#intervalCount === 0 && this.#pending === 0 && this.#intervalId) {
1004
+ clearInterval(this.#intervalId);
1005
+ this.#intervalId = void 0;
1006
+ }
1007
+ this.#intervalCount = this.#carryoverConcurrencyCount ? this.#pending : 0;
1008
+ this.#processQueue();
1009
+ }
1010
+ /**
1011
+ Executes all queued functions until it reaches the limit.
1012
+ */
1013
+ #processQueue() {
1014
+ while (this.#tryToStartAnother()) {
1015
+ }
1016
+ }
1017
+ get concurrency() {
1018
+ return this.#concurrency;
1019
+ }
1020
+ set concurrency(newConcurrency) {
1021
+ if (!(typeof newConcurrency === "number" && newConcurrency >= 1)) {
1022
+ throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${newConcurrency}\` (${typeof newConcurrency})`);
1023
+ }
1024
+ this.#concurrency = newConcurrency;
1025
+ this.#processQueue();
1026
+ }
1027
+ async #throwOnAbort(signal) {
1028
+ return new Promise((_resolve, reject) => {
1029
+ signal.addEventListener("abort", () => {
1030
+ reject(signal.reason);
1031
+ }, { once: true });
1032
+ });
1033
+ }
1034
+ async add(function_, options = {}) {
1035
+ options = {
1036
+ timeout: this.timeout,
1037
+ throwOnTimeout: this.#throwOnTimeout,
1038
+ ...options
1039
+ };
1040
+ return new Promise((resolve, reject) => {
1041
+ this.#queue.enqueue(async () => {
1042
+ this.#pending++;
1043
+ this.#intervalCount++;
1044
+ try {
1045
+ _optionalChain([options, 'access', _75 => _75.signal, 'optionalAccess', _76 => _76.throwIfAborted, 'call', _77 => _77()]);
1046
+ let operation = function_({ signal: options.signal });
1047
+ if (options.timeout) {
1048
+ operation = pTimeout(Promise.resolve(operation), { milliseconds: options.timeout });
1049
+ }
1050
+ if (options.signal) {
1051
+ operation = Promise.race([operation, this.#throwOnAbort(options.signal)]);
1052
+ }
1053
+ const result = await operation;
1054
+ resolve(result);
1055
+ this.emit("completed", result);
1056
+ } catch (error) {
1057
+ if (error instanceof TimeoutError && !options.throwOnTimeout) {
1058
+ resolve();
1059
+ return;
1060
+ }
1061
+ reject(error);
1062
+ this.emit("error", error);
1063
+ } finally {
1064
+ this.#next();
1065
+ }
1066
+ }, options);
1067
+ this.emit("add");
1068
+ this.#tryToStartAnother();
1069
+ });
1070
+ }
1071
+ async addAll(functions, options) {
1072
+ return Promise.all(functions.map(async (function_) => this.add(function_, options)));
1073
+ }
1074
+ /**
1075
+ Start (or resume) executing enqueued tasks within concurrency limit. No need to call this if queue is not paused (via `options.autoStart = false` or by `.pause()` method.)
1076
+ */
1077
+ start() {
1078
+ if (!this.#isPaused) {
1079
+ return this;
1080
+ }
1081
+ this.#isPaused = false;
1082
+ this.#processQueue();
1083
+ return this;
1084
+ }
1085
+ /**
1086
+ Put queue execution on hold.
1087
+ */
1088
+ pause() {
1089
+ this.#isPaused = true;
1090
+ }
1091
+ /**
1092
+ Clear the queue.
1093
+ */
1094
+ clear() {
1095
+ this.#queue = new this.#queueClass();
1096
+ }
1097
+ /**
1098
+ Can be called multiple times. Useful if you for example add additional items at a later time.
1099
+
1100
+ @returns A promise that settles when the queue becomes empty.
1101
+ */
1102
+ async onEmpty() {
1103
+ if (this.#queue.size === 0) {
1104
+ return;
1105
+ }
1106
+ await this.#onEvent("empty");
1107
+ }
1108
+ /**
1109
+ @returns A promise that settles when the queue size is less than the given limit: `queue.size < limit`.
1110
+
1111
+ If you want to avoid having the queue grow beyond a certain size you can `await queue.onSizeLessThan()` before adding a new item.
1112
+
1113
+ Note that this only limits the number of items waiting to start. There could still be up to `concurrency` jobs already running that this call does not include in its calculation.
1114
+ */
1115
+ async onSizeLessThan(limit) {
1116
+ if (this.#queue.size < limit) {
1117
+ return;
1118
+ }
1119
+ await this.#onEvent("next", () => this.#queue.size < limit);
1120
+ }
1121
+ /**
1122
+ The difference with `.onEmpty` is that `.onIdle` guarantees that all work from the queue has finished. `.onEmpty` merely signals that the queue is empty, but it could mean that some promises haven't completed yet.
1123
+
1124
+ @returns A promise that settles when the queue becomes empty, and all promises have completed; `queue.size === 0 && queue.pending === 0`.
1125
+ */
1126
+ async onIdle() {
1127
+ if (this.#pending === 0 && this.#queue.size === 0) {
1128
+ return;
1129
+ }
1130
+ await this.#onEvent("idle");
1131
+ }
1132
+ async #onEvent(event, filter) {
1133
+ return new Promise((resolve) => {
1134
+ const listener = () => {
1135
+ if (filter && !filter()) {
1136
+ return;
1137
+ }
1138
+ this.off(event, listener);
1139
+ resolve();
1140
+ };
1141
+ this.on(event, listener);
1142
+ });
1143
+ }
1144
+ /**
1145
+ Size of the queue, the number of queued items waiting to run.
1146
+ */
1147
+ get size() {
1148
+ return this.#queue.size;
1149
+ }
1150
+ /**
1151
+ Size of the queue, filtered by the given options.
1152
+
1153
+ For example, this can be used to find the number of items remaining in the queue with a specific priority level.
1154
+ */
1155
+ sizeBy(options) {
1156
+ return this.#queue.filter(options).length;
1157
+ }
1158
+ /**
1159
+ Number of running items (no longer in the queue).
1160
+ */
1161
+ get pending() {
1162
+ return this.#pending;
1163
+ }
1164
+ /**
1165
+ Whether the queue is currently paused.
1166
+ */
1167
+ get isPaused() {
1168
+ return this.#isPaused;
1169
+ }
1170
+ };
1171
+
1172
+ // src/FileManager.ts
1173
+ var FileManager = class {
1174
+ #filesByPath = /* @__PURE__ */ new Map();
1175
+ #files = /* @__PURE__ */ new Set();
1176
+ constructor() {
1177
+ return this;
1178
+ }
1179
+ get files() {
1180
+ return Array.from(this.#files);
1181
+ }
1182
+ get orderedFiles() {
1183
+ return _chunkA6PCLWEYcjs.orderBy.call(void 0, Array.from(this.#files), [
1184
+ (v) => _optionalChain([v, 'optionalAccess', _78 => _78.meta]) && "pluginKey" in v.meta && !v.meta.pluginKey,
1185
+ (v) => v.path.length,
1186
+ (v) => _fs.trimExtName.call(void 0, v.path).endsWith("index"),
1187
+ (v) => _fs.trimExtName.call(void 0, v.baseName),
1188
+ (v) => v.path.split(".").pop()
1189
+ ]);
1190
+ }
1191
+ get groupedFiles() {
1192
+ return buildDirectoryTree(Array.from(this.#files));
1193
+ }
1194
+ get treeNode() {
1195
+ return TreeNode.build(Array.from(this.#files));
1196
+ }
1197
+ async add(...files) {
1198
+ const promises = files.map((file) => {
1199
+ if (file.override) {
1200
+ return this.#add(file);
1201
+ }
1202
+ return this.#addOrAppend(file);
1203
+ });
1204
+ const resolvedFiles = await Promise.all(promises);
1205
+ if (files.length > 1) {
1206
+ return resolvedFiles;
1207
+ }
1208
+ return resolvedFiles[0];
1209
+ }
1210
+ async #add(file) {
1211
+ const resolvedFile = createFile(file);
1212
+ this.#filesByPath.set(resolvedFile.path, resolvedFile);
1213
+ this.#files.add(resolvedFile);
1214
+ return resolvedFile;
1215
+ }
1216
+ clear() {
1217
+ this.#filesByPath.clear();
1218
+ this.#files.clear();
1219
+ }
1220
+ async #addOrAppend(file) {
1221
+ const previousFile = this.#filesByPath.get(file.path);
1222
+ if (previousFile) {
1223
+ this.#filesByPath.delete(previousFile.path);
1224
+ this.#files.delete(previousFile);
1225
+ return this.#add(mergeFile(previousFile, file));
1226
+ }
1227
+ return this.#add(file);
1228
+ }
1229
+ getCacheById(id) {
1230
+ let cache;
1231
+ this.#files.forEach((file) => {
1232
+ if (file.id === id) {
1233
+ cache = file;
1234
+ }
1235
+ });
1236
+ return cache;
1237
+ }
1238
+ getByPath(path) {
1239
+ return this.#filesByPath.get(path);
1240
+ }
1241
+ deleteByPath(path) {
1242
+ const cacheItem = this.getByPath(path);
1243
+ if (!cacheItem) {
1244
+ return;
1245
+ }
1246
+ this.#filesByPath.delete(path);
1247
+ this.#files.delete(cacheItem);
1248
+ }
1249
+ async getBarrelFiles({ files, meta, root, output, logger }) {
1250
+ const { exportType = "barrelNamed" } = output;
1251
+ const barrelManager = new BarrelManager({ logger });
1252
+ if (exportType === false) {
1253
+ return [];
1254
+ }
1255
+ const pathToBuildFrom = _path.join.call(void 0, root, output.path);
1256
+ if (_fs.trimExtName.call(void 0, pathToBuildFrom).endsWith("index")) {
1257
+ _optionalChain([logger, 'optionalAccess', _79 => _79.emit, 'call', _80 => _80("warning", "Output has the same fileName as the barrelFiles, please disable barrel generation")]);
1258
+ return [];
1259
+ }
1260
+ const barrelFiles = barrelManager.getFiles(files, pathToBuildFrom);
1261
+ if (exportType === "barrel") {
1262
+ return barrelFiles.map((file) => {
1263
+ return {
1264
+ ...file,
1265
+ exports: _optionalChain([file, 'access', _81 => _81.exports, 'optionalAccess', _82 => _82.map, 'call', _83 => _83((exportItem) => {
1266
+ return {
1267
+ ...exportItem,
1268
+ name: void 0
1269
+ };
1270
+ })])
1271
+ };
1272
+ });
1273
+ }
1274
+ return barrelFiles.map((indexFile) => {
1275
+ return {
1276
+ ...indexFile,
1277
+ meta
1278
+ };
1279
+ });
1280
+ }
1281
+ async write(...params) {
1282
+ return _fs.write.call(void 0, ...params);
1283
+ }
1284
+ async read(...params) {
1285
+ return _fs.read.call(void 0, ...params);
1286
+ }
1287
+ // statics
1288
+ static getMode(path) {
1289
+ if (!path) {
1290
+ return "split";
1291
+ }
1292
+ return _path.extname.call(void 0, path) ? "single" : "split";
1293
+ }
1294
+ };
1295
+ async function getSource(file, { logger } = {}) {
1296
+ const parser = await getFileParser(file.extName);
1297
+ return parser.print(file, { logger });
1298
+ }
1299
+ function mergeFile(a, b) {
1300
+ return {
1301
+ ...a,
1302
+ sources: [...a.sources || [], ...b.sources || []],
1303
+ imports: [...a.imports || [], ...b.imports || []],
1304
+ exports: [...a.exports || [], ...b.exports || []]
1305
+ };
1306
+ }
1307
+ function combineSources(sources) {
1308
+ return sources.reduce(
1309
+ (prev, curr) => {
1310
+ const prevByName = prev.findLast((imp) => imp.name === curr.name);
1311
+ const prevByPathAndIsExportable = prev.findLast((imp) => imp.name === curr.name && imp.isExportable);
1312
+ if (prevByPathAndIsExportable) {
1313
+ return [...prev, curr];
1314
+ }
1315
+ if (prevByName) {
1316
+ prevByName.value = curr.value;
1317
+ prevByName.isExportable = curr.isExportable;
1318
+ prevByName.isTypeOnly = curr.isTypeOnly;
1319
+ prevByName.isIndexable = curr.isIndexable;
1320
+ return prev;
1321
+ }
1322
+ return [...prev, curr];
1323
+ },
1324
+ []
1325
+ );
1326
+ }
1327
+ function combineExports(exports) {
1328
+ const combinedExports = exports.reduce(
1329
+ (prev, curr) => {
1330
+ const name = curr.name;
1331
+ const prevByPath = prev.findLast((imp) => imp.path === curr.path);
1332
+ const prevByPathAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && _remeda.isDeepEqual.call(void 0, imp.name, name) && imp.isTypeOnly);
1333
+ if (prevByPathAndIsTypeOnly) {
1334
+ return prev;
1335
+ }
1336
+ const uniquePrev = prev.findLast(
1337
+ (imp) => imp.path === curr.path && _remeda.isDeepEqual.call(void 0, imp.name, name) && imp.isTypeOnly === curr.isTypeOnly && imp.asAlias === curr.asAlias
1338
+ );
1339
+ if (uniquePrev || Array.isArray(name) && !name.length || _optionalChain([prevByPath, 'optionalAccess', _84 => _84.asAlias]) && !curr.asAlias) {
1340
+ return prev;
1341
+ }
1342
+ if (!prevByPath) {
1343
+ return [
1344
+ ...prev,
1345
+ {
1346
+ ...curr,
1347
+ name: Array.isArray(name) ? [...new Set(name)] : name
1348
+ }
1349
+ ];
1350
+ }
1351
+ if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(curr.name) && prevByPath.isTypeOnly === curr.isTypeOnly) {
1352
+ prevByPath.name = [.../* @__PURE__ */ new Set([...prevByPath.name, ...curr.name])];
1353
+ return prev;
1354
+ }
1355
+ return [...prev, curr];
1356
+ },
1357
+ []
1358
+ );
1359
+ return _chunkA6PCLWEYcjs.orderBy.call(void 0, combinedExports, [
1360
+ (v) => !!Array.isArray(v.name),
1361
+ (v) => !v.isTypeOnly,
1362
+ (v) => v.path,
1363
+ (v) => !!v.name,
1364
+ (v) => Array.isArray(v.name) ? _chunkA6PCLWEYcjs.orderBy.call(void 0, v.name) : v.name
1365
+ ]);
1366
+ }
1367
+ function combineImports(imports, exports, source) {
1368
+ const combinedImports = imports.reduce(
1369
+ (prev, curr) => {
1370
+ let name = Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name;
1371
+ const hasImportInSource = (importName) => {
1372
+ if (!source) {
1373
+ return true;
1374
+ }
1375
+ const checker = (name2) => name2 && !!source.includes(name2);
1376
+ return checker(importName) || exports.some(({ name: name2 }) => Array.isArray(name2) ? name2.some(checker) : checker(name2));
1377
+ };
1378
+ if (curr.path === curr.root) {
1379
+ return prev;
1380
+ }
1381
+ if (Array.isArray(name)) {
1382
+ name = name.filter((item) => typeof item === "string" ? hasImportInSource(item) : hasImportInSource(item.propertyName));
1383
+ }
1384
+ const prevByPath = prev.findLast((imp) => imp.path === curr.path && imp.isTypeOnly === curr.isTypeOnly);
1385
+ const uniquePrev = prev.findLast((imp) => imp.path === curr.path && _remeda.isDeepEqual.call(void 0, imp.name, name) && imp.isTypeOnly === curr.isTypeOnly);
1386
+ const prevByPathNameAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && _remeda.isDeepEqual.call(void 0, imp.name, name) && imp.isTypeOnly);
1387
+ if (prevByPathNameAndIsTypeOnly) {
1388
+ return prev;
1389
+ }
1390
+ if (uniquePrev || Array.isArray(name) && !name.length) {
1391
+ return prev;
1392
+ }
1393
+ if (!prevByPath) {
1394
+ return [
1395
+ ...prev,
1396
+ {
1397
+ ...curr,
1398
+ name
1399
+ }
1400
+ ];
1401
+ }
1402
+ if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(name) && prevByPath.isTypeOnly === curr.isTypeOnly) {
1403
+ prevByPath.name = [.../* @__PURE__ */ new Set([...prevByPath.name, ...name])];
1404
+ return prev;
1405
+ }
1406
+ if (!Array.isArray(name) && name && !hasImportInSource(name)) {
1407
+ return prev;
1408
+ }
1409
+ return [...prev, curr];
1410
+ },
1411
+ []
1412
+ );
1413
+ return _chunkA6PCLWEYcjs.orderBy.call(void 0, combinedImports, [
1414
+ (v) => !!Array.isArray(v.name),
1415
+ (v) => !v.isTypeOnly,
1416
+ (v) => v.path,
1417
+ (v) => !!v.name,
1418
+ (v) => Array.isArray(v.name) ? _chunkA6PCLWEYcjs.orderBy.call(void 0, v.name) : v.name
1419
+ ]);
1420
+ }
1421
+ var queue = new PQueue({ concurrency: 100 });
1422
+ async function processFiles({ dryRun, config, logger, files }) {
1423
+ const orderedFiles = _chunkA6PCLWEYcjs.orderBy.call(void 0, files, [
1424
+ (v) => _optionalChain([v, 'optionalAccess', _85 => _85.meta]) && "pluginKey" in v.meta && !v.meta.pluginKey,
1425
+ (v) => v.path.length,
1426
+ (v) => _fs.trimExtName.call(void 0, v.path).endsWith("index")
1427
+ ]);
1428
+ logger.emit("debug", {
1429
+ logs: [JSON.stringify({ files: orderedFiles }, null, 2)],
1430
+ fileName: "kubb-files.json",
1431
+ override: true
1432
+ });
1433
+ if (!dryRun) {
1434
+ const size = orderedFiles.length;
1435
+ logger.emit("progress_start", { id: "files", size });
1436
+ const promises = orderedFiles.map(async (file) => {
1437
+ await queue.add(async () => {
1438
+ const source = await getSource(file, { logger });
1439
+ await _fs.write.call(void 0, file.path, source, { sanity: false });
1440
+ logger.emit("progress", { id: "files", data: file ? _path.relative.call(void 0, config.root, file.path) : "" });
1441
+ });
1442
+ });
1443
+ await Promise.all(promises);
1444
+ logger.emit("progress_stop", { id: "files" });
1445
+ }
1446
+ return files;
1447
+ }
1448
+
1449
+ // src/utils/parser.ts
1450
+ function createFile(file) {
1451
+ const extName = _path.extname.call(void 0, file.baseName);
1452
+ if (!extName) {
1453
+ throw new Error(`No extName found for ${file.baseName}`);
1454
+ }
1455
+ const source = file.sources.map((item) => item.value).join("\n\n");
1456
+ const exports = file.exports ? combineExports(file.exports) : [];
1457
+ const imports = file.imports && source ? combineImports(file.imports, exports, source) : [];
1458
+ const sources = file.sources ? combineSources(file.sources) : [];
1459
+ return {
1460
+ ...file,
1461
+ id: _objecthash2.default.call(void 0, { path: file.path }),
1462
+ name: trimExtName2(file.baseName),
1463
+ extName,
1464
+ imports: imports.map((item) => createFileImport(item)),
1465
+ exports: exports.map((item) => createFileExport(item)),
1466
+ sources: sources.map((item) => createFileSource(item))
1467
+ };
1468
+ }
1469
+ function createFileSource(source) {
1470
+ return source;
1471
+ }
1472
+ function createFileImport(imp) {
1473
+ const extName = _path.extname.call(void 0, imp.path);
1474
+ return {
1475
+ ...imp,
1476
+ extName: imp.extName ? imp.extName : extName
1477
+ };
1478
+ }
1479
+ function createFileExport(exp) {
1480
+ const extName = _path.extname.call(void 0, exp.path);
1481
+ return {
1482
+ ...exp,
1483
+ extName: exp.extName ? exp.extName : extName
1484
+ };
1485
+ }
1486
+ function createFileParser(parser) {
1487
+ return parser;
1488
+ }
1489
+ var typeScriptParser = createFileParser({
1490
+ render() {
1491
+ return void 0;
1492
+ },
1493
+ async print(file) {
1494
+ const module = await Promise.resolve().then(() => _interopRequireWildcard(require("@kubb/parser-ts")));
1495
+ const importNodes = file.imports.map((item) => {
1496
+ const path = item.root ? _fs.getRelativePath.call(void 0, item.root, item.path) : item.path;
1497
+ return module.factory.createImportDeclaration({
1498
+ name: item.name,
1499
+ path,
1500
+ isTypeOnly: item.isTypeOnly
1501
+ });
1502
+ }).filter(Boolean);
1503
+ const exportNodes = file.exports.map((item) => {
1504
+ return module.factory.createExportDeclaration({
1505
+ name: item.name,
1506
+ path: item.path,
1507
+ isTypeOnly: item.isTypeOnly,
1508
+ asAlias: item.asAlias
1509
+ });
1510
+ }).filter(Boolean);
1511
+ const source = [module.print([...importNodes, ...exportNodes]), file.sources.map((item) => item.value).join("\n\n")].join("\n");
1512
+ return module.print([], { source, noEmitHelpers: false });
1513
+ }
1514
+ });
1515
+ var defaultParser = createFileParser({
1516
+ render() {
1517
+ return void 0;
1518
+ },
1519
+ async print(file, { logger }) {
1520
+ return file.sources.map((item) => item.value).join("\n\n");
1521
+ }
1522
+ });
1523
+ var parsers = {
1524
+ ".ts": typeScriptParser,
1525
+ ".js": typeScriptParser,
1526
+ ".jsx": typeScriptParser,
1527
+ ".tsx": typeScriptParser,
1528
+ ".json": defaultParser
1529
+ };
1530
+ async function getFileParser(extName) {
1531
+ if (!extName) {
1532
+ return defaultParser;
1533
+ }
1534
+ const parser = parsers[extName];
1535
+ if (!parser) {
1536
+ console.warn(`[parser] No parser found for ${extName}, default parser will be used`);
1537
+ }
1538
+ return parser || defaultParser;
1539
+ }
1540
+ function trimExtName2(text) {
1541
+ const extName = text.split(".").pop();
1542
+ return text.replace(`.${extName}`, "");
1543
+ }
1544
+
1545
+
1546
+
1547
+
1548
+
1549
+
1550
+
1551
+
1552
+
1553
+
1554
+
1555
+
1556
+
1557
+
1558
+
1559
+
1560
+
1561
+
1562
+
1563
+ exports.FunctionParams = FunctionParams; exports.isPromise = isPromise; exports.isPromiseFulfilledResult = isPromiseFulfilledResult; exports.isPromiseRejectedResult = isPromiseRejectedResult; exports.renderTemplate = renderTemplate; exports.timeout = timeout; exports.getUniqueName = getUniqueName; exports.setUniqueName = setUniqueName; exports.URLPath = URLPath; exports.createFile = createFile; exports.createFileImport = createFileImport; exports.createFileExport = createFileExport; exports.createFileParser = createFileParser; exports.getFileParser = getFileParser; exports.FileManager = FileManager; exports.getSource = getSource; exports.processFiles = processFiles;
1564
+ //# sourceMappingURL=chunk-5IGANEGE.cjs.map