@kubb/core 4.2.0 → 4.2.1

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 (130) hide show
  1. package/dist/URLPath-8WVzHBnA.cjs +134 -0
  2. package/dist/URLPath-8WVzHBnA.cjs.map +1 -0
  3. package/dist/URLPath-BYceu_vY.js +117 -0
  4. package/dist/URLPath-BYceu_vY.js.map +1 -0
  5. package/dist/{acorn-DExO7r0H.cjs → acorn-BAVXZMtK.cjs} +1 -1
  6. package/dist/{acorn-DExO7r0H.cjs.map → acorn-BAVXZMtK.cjs.map} +1 -1
  7. package/dist/{acorn-B0JdnMwY.js → acorn-D-VhIOLw.js} +1 -1
  8. package/dist/{acorn-B0JdnMwY.js.map → acorn-D-VhIOLw.js.map} +1 -1
  9. package/dist/{angular-C2M8l5eL.cjs → angular-Bp0XO9db.cjs} +1 -1
  10. package/dist/{angular-C2M8l5eL.cjs.map → angular-Bp0XO9db.cjs.map} +1 -1
  11. package/dist/{angular-CmU_K35W.js → angular-Czhp4eq5.js} +1 -1
  12. package/dist/{angular-CmU_K35W.js.map → angular-Czhp4eq5.js.map} +1 -1
  13. package/dist/{babel-CfF0c5A9.js → babel-DCR_B4Qn.js} +1 -1
  14. package/dist/{babel-CfF0c5A9.js.map → babel-DCR_B4Qn.js.map} +1 -1
  15. package/dist/{babel-BKn0s9Rj.cjs → babel-NI0v59ga.cjs} +1 -1
  16. package/dist/{babel-BKn0s9Rj.cjs.map → babel-NI0v59ga.cjs.map} +1 -1
  17. package/dist/casing-BSeq_teY.js +100 -0
  18. package/dist/casing-BSeq_teY.js.map +1 -0
  19. package/dist/casing-CP-9GGdK.cjs +112 -0
  20. package/dist/casing-CP-9GGdK.cjs.map +1 -0
  21. package/dist/{estree-Br3l79C5.cjs → estree-C3BZPlpU.cjs} +1 -1
  22. package/dist/{estree-Br3l79C5.cjs.map → estree-C3BZPlpU.cjs.map} +1 -1
  23. package/dist/{estree-B_YMDsR7.js → estree-DU2NummP.js} +1 -1
  24. package/dist/{estree-B_YMDsR7.js.map → estree-DU2NummP.js.map} +1 -1
  25. package/dist/{flow-B_3vaVXc.cjs → flow-CWUBUkoi.cjs} +1 -1
  26. package/dist/{flow-B_3vaVXc.cjs.map → flow-CWUBUkoi.cjs.map} +1 -1
  27. package/dist/{flow-Dc3wao4M.js → flow-JiEbweKj.js} +1 -1
  28. package/dist/{flow-Dc3wao4M.js.map → flow-JiEbweKj.js.map} +1 -1
  29. package/dist/fs.d.cts +1 -1
  30. package/dist/fs.d.ts +1 -1
  31. package/dist/{glimmer-BF35HI3l.cjs → glimmer-CX9OqG1j.cjs} +1 -1
  32. package/dist/{glimmer-BF35HI3l.cjs.map → glimmer-CX9OqG1j.cjs.map} +1 -1
  33. package/dist/{glimmer-CwM1XZA1.js → glimmer-t9nWn9aE.js} +1 -1
  34. package/dist/{glimmer-CwM1XZA1.js.map → glimmer-t9nWn9aE.js.map} +1 -1
  35. package/dist/{graphql-KQQTidk7.js → graphql-DjErlIi5.js} +1 -1
  36. package/dist/{graphql-KQQTidk7.js.map → graphql-DjErlIi5.js.map} +1 -1
  37. package/dist/{graphql-DhaHiYrP.cjs → graphql-GOxQAKxM.cjs} +1 -1
  38. package/dist/{graphql-DhaHiYrP.cjs.map → graphql-GOxQAKxM.cjs.map} +1 -1
  39. package/dist/hooks.d.cts +3 -2
  40. package/dist/hooks.d.ts +4 -3
  41. package/dist/{html-B2QWX43c.cjs → html-CWrdYAhQ.cjs} +1 -1
  42. package/dist/{html-B2QWX43c.cjs.map → html-CWrdYAhQ.cjs.map} +1 -1
  43. package/dist/{html-DQoJX7Yj.js → html-_apcbx34.js} +1 -1
  44. package/dist/{html-DQoJX7Yj.js.map → html-_apcbx34.js.map} +1 -1
  45. package/dist/{index-BY_kka8d.d.ts → index-BTe91LHd.d.ts} +2 -2
  46. package/dist/{index-Iq8NJRgc.d.cts → index-BmQIxvw0.d.cts} +2 -2
  47. package/dist/index.cjs +378 -22
  48. package/dist/index.cjs.map +1 -1
  49. package/dist/index.d.cts +37 -4
  50. package/dist/index.d.ts +38 -5
  51. package/dist/index.js +371 -15
  52. package/dist/index.js.map +1 -1
  53. package/dist/{logger-BkGPbocD.d.ts → logger-BA-za85-.d.ts} +1 -1
  54. package/dist/{logger-S_t55o9n.cjs → logger-BXL0YCrv.cjs} +2 -2
  55. package/dist/{logger-S_t55o9n.cjs.map → logger-BXL0YCrv.cjs.map} +1 -1
  56. package/dist/{logger-CsQ2EGpR.js → logger-CDxSrFkR.js} +2 -2
  57. package/dist/{logger-CsQ2EGpR.js.map → logger-CDxSrFkR.js.map} +1 -1
  58. package/dist/logger.cjs +1 -1
  59. package/dist/logger.d.ts +1 -1
  60. package/dist/logger.js +1 -1
  61. package/dist/{markdown-CDf4HsAQ.js → markdown-ckUc3Q6q.js} +1 -1
  62. package/dist/{markdown-CDf4HsAQ.js.map → markdown-ckUc3Q6q.js.map} +1 -1
  63. package/dist/{markdown-HXmAlxeH.cjs → markdown-pzqiRmft.cjs} +1 -1
  64. package/dist/{markdown-HXmAlxeH.cjs.map → markdown-pzqiRmft.cjs.map} +1 -1
  65. package/dist/{meriyah-D8fyVkyI.js → meriyah-BjnGqpUs.js} +1 -1
  66. package/dist/{meriyah-D8fyVkyI.js.map → meriyah-BjnGqpUs.js.map} +1 -1
  67. package/dist/{meriyah-CWoiYjq_.cjs → meriyah-D_x7itbT.cjs} +1 -1
  68. package/dist/{meriyah-CWoiYjq_.cjs.map → meriyah-D_x7itbT.cjs.map} +1 -1
  69. package/dist/mocks.cjs +24 -24
  70. package/dist/mocks.cjs.map +1 -1
  71. package/dist/mocks.d.cts +3 -2
  72. package/dist/mocks.d.ts +4 -3
  73. package/dist/mocks.js +19 -20
  74. package/dist/mocks.js.map +1 -1
  75. package/dist/{postcss-bESf1Yzf.cjs → postcss-B_c2wbFu.cjs} +1 -1
  76. package/dist/{postcss-bESf1Yzf.cjs.map → postcss-B_c2wbFu.cjs.map} +1 -1
  77. package/dist/{postcss-Dqh1XvaI.js → postcss-v7BP6SZ-.js} +1 -1
  78. package/dist/{postcss-Dqh1XvaI.js.map → postcss-v7BP6SZ-.js.map} +1 -1
  79. package/dist/{prompt-C5GR2LPU.js → prompt-DBVnG4Me.js} +1 -1
  80. package/dist/{prompt-C5GR2LPU.js.map → prompt-DBVnG4Me.js.map} +1 -1
  81. package/dist/{prompt-ZBXNC-aV.cjs → prompt-DgONOpPH.cjs} +1 -1
  82. package/dist/{prompt-ZBXNC-aV.cjs.map → prompt-DgONOpPH.cjs.map} +1 -1
  83. package/dist/{transformers-BIx7CVmw.cjs → transformers-BH0KLJJP.cjs} +119 -228
  84. package/dist/transformers-BH0KLJJP.cjs.map +1 -0
  85. package/dist/{transformers-5BubQvcu.js → transformers-DzHGqYO2.js} +118 -215
  86. package/dist/transformers-DzHGqYO2.js.map +1 -0
  87. package/dist/transformers.cjs +4 -3
  88. package/dist/transformers.js +2 -1
  89. package/dist/types-BzI9JlV8.d.ts +5 -0
  90. package/dist/types-C3ea5qNG.d.cts +5 -0
  91. package/dist/{types-IOE1JAFC.d.cts → types-DNxlynJr.d.cts} +11 -70
  92. package/dist/{types-DtokChaW.d.ts → types-DPeNK0FO.d.ts} +12 -71
  93. package/dist/{typescript-BYxryL2A.cjs → typescript-6kMN6Wqz.cjs} +1 -1
  94. package/dist/{typescript-BYxryL2A.cjs.map → typescript-6kMN6Wqz.cjs.map} +1 -1
  95. package/dist/{typescript-B7n7vRma.js → typescript-B_IBfKSe.js} +1 -1
  96. package/dist/{typescript-B7n7vRma.js.map → typescript-B_IBfKSe.js.map} +1 -1
  97. package/dist/typescript-C5hce4HG.cjs +4 -0
  98. package/dist/typescript-Cas1XcNz.js +3 -0
  99. package/dist/utils.cjs +165 -20
  100. package/dist/utils.cjs.map +1 -0
  101. package/dist/utils.d.cts +136 -5
  102. package/dist/utils.d.ts +136 -5
  103. package/dist/utils.js +156 -5
  104. package/dist/utils.js.map +1 -0
  105. package/dist/{yaml-BMiF8MYP.js → yaml-BfWM_B73.js} +1 -1
  106. package/dist/{yaml-BMiF8MYP.js.map → yaml-BfWM_B73.js.map} +1 -1
  107. package/dist/{yaml-DQCs4b_O.cjs → yaml-DZs6MhV1.cjs} +1 -1
  108. package/dist/{yaml-DQCs4b_O.cjs.map → yaml-DZs6MhV1.cjs.map} +1 -1
  109. package/package.json +3 -3
  110. package/src/FileManager.ts +34 -302
  111. package/src/PluginManager.ts +9 -8
  112. package/src/__snapshots__/barrel.json +5 -5
  113. package/src/build.ts +19 -5
  114. package/src/index.ts +1 -2
  115. package/src/mocks/index.ts +4 -3
  116. package/src/plugin.ts +1 -1
  117. package/src/types.ts +4 -1
  118. package/src/utils/TreeNode.ts +3 -3
  119. package/src/utils/index.ts +2 -4
  120. package/dist/FileManager-DlkY9W5A.cjs +0 -1001
  121. package/dist/FileManager-DlkY9W5A.cjs.map +0 -1
  122. package/dist/FileManager-zlhCXf6A.js +0 -879
  123. package/dist/FileManager-zlhCXf6A.js.map +0 -1
  124. package/dist/index-CYcjcRdj.d.ts +0 -179
  125. package/dist/index-DaYv9bst.d.cts +0 -179
  126. package/dist/transformers-5BubQvcu.js.map +0 -1
  127. package/dist/transformers-BIx7CVmw.cjs.map +0 -1
  128. package/dist/typescript-CIdP4XPm.js +0 -3
  129. package/dist/typescript-CbuCkdxv.cjs +0 -4
  130. package/src/utils/parser.ts +0 -199
@@ -1,879 +0,0 @@
1
- import { r as __toESM } from "./chunk-1SJ2vVWa.js";
2
- import { r as getRelativePath, t as trimExtName } from "./fs-BIPMUfpW.js";
3
- import { t as write } from "./write-CxO1CDML.js";
4
- import { b as require_main, i as isValidVarName, v as camelCase } from "./transformers-5BubQvcu.js";
5
- import path, { extname, join, relative } from "node:path";
6
- import { isDeepEqual, uniqueBy } from "remeda";
7
- import hash from "object-hash";
8
-
9
- //#region ../../node_modules/.pnpm/yocto-queue@1.2.1/node_modules/yocto-queue/index.js
10
- var Node = class {
11
- value;
12
- next;
13
- constructor(value) {
14
- this.value = value;
15
- }
16
- };
17
- var Queue = class {
18
- #head;
19
- #tail;
20
- #size;
21
- constructor() {
22
- this.clear();
23
- }
24
- enqueue(value) {
25
- const node = new Node(value);
26
- if (this.#head) {
27
- this.#tail.next = node;
28
- this.#tail = node;
29
- } else {
30
- this.#head = node;
31
- this.#tail = node;
32
- }
33
- this.#size++;
34
- }
35
- dequeue() {
36
- const current = this.#head;
37
- if (!current) return;
38
- this.#head = this.#head.next;
39
- this.#size--;
40
- return current.value;
41
- }
42
- peek() {
43
- if (!this.#head) return;
44
- return this.#head.value;
45
- }
46
- clear() {
47
- this.#head = void 0;
48
- this.#tail = void 0;
49
- this.#size = 0;
50
- }
51
- get size() {
52
- return this.#size;
53
- }
54
- *[Symbol.iterator]() {
55
- let current = this.#head;
56
- while (current) {
57
- yield current.value;
58
- current = current.next;
59
- }
60
- }
61
- *drain() {
62
- while (this.#head) yield this.dequeue();
63
- }
64
- };
65
-
66
- //#endregion
67
- //#region ../../node_modules/.pnpm/p-limit@7.2.0/node_modules/p-limit/index.js
68
- function pLimit(concurrency) {
69
- validateConcurrency(concurrency);
70
- const queue = new Queue();
71
- let activeCount = 0;
72
- const resumeNext = () => {
73
- if (activeCount < concurrency && queue.size > 0) {
74
- activeCount++;
75
- queue.dequeue()();
76
- }
77
- };
78
- const next = () => {
79
- activeCount--;
80
- resumeNext();
81
- };
82
- const run = async (function_, resolve$1, arguments_) => {
83
- const result = (async () => function_(...arguments_))();
84
- resolve$1(result);
85
- try {
86
- await result;
87
- } catch {}
88
- next();
89
- };
90
- const enqueue = (function_, resolve$1, arguments_) => {
91
- new Promise((internalResolve) => {
92
- queue.enqueue(internalResolve);
93
- }).then(run.bind(void 0, function_, resolve$1, arguments_));
94
- if (activeCount < concurrency) resumeNext();
95
- };
96
- const generator = (function_, ...arguments_) => new Promise((resolve$1) => {
97
- enqueue(function_, resolve$1, arguments_);
98
- });
99
- Object.defineProperties(generator, {
100
- activeCount: { get: () => activeCount },
101
- pendingCount: { get: () => queue.size },
102
- clearQueue: { value() {
103
- queue.clear();
104
- } },
105
- concurrency: {
106
- get: () => concurrency,
107
- set(newConcurrency) {
108
- validateConcurrency(newConcurrency);
109
- concurrency = newConcurrency;
110
- queueMicrotask(() => {
111
- while (activeCount < concurrency && queue.size > 0) resumeNext();
112
- });
113
- }
114
- },
115
- map: { async value(iterable, function_) {
116
- const promises = Array.from(iterable, (value, index) => this(function_, value, index));
117
- return Promise.all(promises);
118
- } }
119
- });
120
- return generator;
121
- }
122
- function validateConcurrency(concurrency) {
123
- if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) throw new TypeError("Expected `concurrency` to be a number from 1 and up");
124
- }
125
-
126
- //#endregion
127
- //#region src/utils/TreeNode.ts
128
- var TreeNode = class TreeNode {
129
- data;
130
- parent;
131
- children = [];
132
- #cachedLeaves = void 0;
133
- constructor(data, parent) {
134
- this.data = data;
135
- this.parent = parent;
136
- return this;
137
- }
138
- addChild(data) {
139
- const child = new TreeNode(data, this);
140
- if (!this.children) this.children = [];
141
- this.children.push(child);
142
- return child;
143
- }
144
- get root() {
145
- if (!this.parent) return this;
146
- return this.parent.root;
147
- }
148
- get leaves() {
149
- if (!this.children || this.children.length === 0) return [this];
150
- if (this.#cachedLeaves) return this.#cachedLeaves;
151
- const leaves = [];
152
- if (this.children) for (let i = 0, { length } = this.children; i < length; i++) leaves.push.apply(leaves, this.children[i].leaves);
153
- this.#cachedLeaves = leaves;
154
- return leaves;
155
- }
156
- forEach(callback) {
157
- if (typeof callback !== "function") throw new TypeError("forEach() callback must be a function");
158
- callback(this);
159
- if (this.children) for (let i = 0, { length } = this.children; i < length; i++) this.children[i]?.forEach(callback);
160
- return this;
161
- }
162
- findDeep(predicate) {
163
- if (typeof predicate !== "function") throw new TypeError("find() predicate must be a function");
164
- return this.leaves.find(predicate);
165
- }
166
- forEachDeep(callback) {
167
- if (typeof callback !== "function") throw new TypeError("forEach() callback must be a function");
168
- this.leaves.forEach(callback);
169
- }
170
- filterDeep(callback) {
171
- if (typeof callback !== "function") throw new TypeError("filter() callback must be a function");
172
- return this.leaves.filter(callback);
173
- }
174
- mapDeep(callback) {
175
- if (typeof callback !== "function") throw new TypeError("map() callback must be a function");
176
- return this.leaves.map(callback);
177
- }
178
- static build(files, root) {
179
- try {
180
- const filteredTree = buildDirectoryTree(files, root);
181
- if (!filteredTree) return null;
182
- const treeNode = new TreeNode({
183
- name: filteredTree.name,
184
- path: filteredTree.path,
185
- file: filteredTree.file,
186
- type: FileManager.getMode(filteredTree.path)
187
- });
188
- const recurse = (node, item) => {
189
- const subNode = node.addChild({
190
- name: item.name,
191
- path: item.path,
192
- file: item.file,
193
- type: FileManager.getMode(item.path)
194
- });
195
- if (item.children?.length) item.children?.forEach((child) => {
196
- recurse(subNode, child);
197
- });
198
- };
199
- filteredTree.children?.forEach((child) => {
200
- recurse(treeNode, child);
201
- });
202
- return treeNode;
203
- } catch (e) {
204
- throw new Error("Something went wrong with creating barrel files with the TreeNode class", { cause: e });
205
- }
206
- }
207
- };
208
- const normalizePath = (p) => p.replace(/\\/g, "/");
209
- function buildDirectoryTree(files, rootFolder = "") {
210
- const normalizedRootFolder = normalizePath(rootFolder);
211
- const rootPrefix = normalizedRootFolder.endsWith("/") ? normalizedRootFolder : `${normalizedRootFolder}/`;
212
- const filteredFiles = files.filter((file) => {
213
- const normalizedFilePath = normalizePath(file.path);
214
- return rootFolder ? normalizedFilePath.startsWith(rootPrefix) && !normalizedFilePath.endsWith(".json") : !normalizedFilePath.endsWith(".json");
215
- });
216
- if (filteredFiles.length === 0) return null;
217
- const root = {
218
- name: rootFolder || "",
219
- path: rootFolder || "",
220
- children: []
221
- };
222
- filteredFiles.forEach((file) => {
223
- const parts = file.path.slice(rootFolder.length).split("/");
224
- let currentLevel = root.children;
225
- let currentPath = rootFolder;
226
- parts.forEach((part, index) => {
227
- if (index !== 0) currentPath += `/${part}`;
228
- else currentPath += `${part}`;
229
- let existingNode = currentLevel.find((node) => node.name === part);
230
- if (!existingNode) {
231
- if (index === parts.length - 1) existingNode = {
232
- name: part,
233
- file,
234
- path: currentPath
235
- };
236
- else existingNode = {
237
- name: part,
238
- path: currentPath,
239
- children: []
240
- };
241
- currentLevel.push(existingNode);
242
- }
243
- if (!existingNode.file) currentLevel = existingNode.children;
244
- });
245
- });
246
- return root;
247
- }
248
-
249
- //#endregion
250
- //#region src/BarrelManager.ts
251
- var BarrelManager = class {
252
- #options;
253
- constructor(options = {}) {
254
- this.#options = options;
255
- return this;
256
- }
257
- getFiles({ files: generatedFiles, root }) {
258
- const { logger } = this.#options;
259
- const cachedFiles = /* @__PURE__ */ new Map();
260
- TreeNode.build(generatedFiles, root)?.forEach((treeNode) => {
261
- if (!treeNode || !treeNode.children || !treeNode.parent?.data.path) return;
262
- const barrelFile = {
263
- path: join(treeNode.parent?.data.path, "index.ts"),
264
- baseName: "index.ts",
265
- exports: [],
266
- sources: []
267
- };
268
- const previousBarrelFile = cachedFiles.get(barrelFile.path);
269
- treeNode.leaves.forEach((item) => {
270
- if (!item.data.name) return;
271
- const sources = item.data.file?.sources || [];
272
- if (!sources.some((source) => source.isIndexable)) logger?.emit("warning", `No isIndexable source found(source should have a name and isIndexable):\nFile: ${JSON.stringify(item.data.file, void 0, 2)}`);
273
- sources.forEach((source) => {
274
- if (!item.data.file?.path || !source.isIndexable || !source.name) return;
275
- if (previousBarrelFile?.sources.some((item$1) => item$1.name === source.name && item$1.isTypeOnly === source.isTypeOnly)) return;
276
- if (!barrelFile.exports) barrelFile.exports = [];
277
- if (!!treeNode.parent?.data.path?.split?.("/")?.length) barrelFile.exports.push({
278
- name: [source.name],
279
- path: getRelativePath(treeNode.parent?.data.path, item.data.path),
280
- isTypeOnly: source.isTypeOnly
281
- });
282
- else barrelFile.exports.push({
283
- name: [source.name],
284
- path: `./${item.data.file.baseName}`,
285
- isTypeOnly: source.isTypeOnly
286
- });
287
- barrelFile.sources.push({
288
- name: source.name,
289
- isTypeOnly: source.isTypeOnly,
290
- value: "",
291
- isExportable: false,
292
- isIndexable: false
293
- });
294
- });
295
- });
296
- if (previousBarrelFile) {
297
- previousBarrelFile.sources.push(...barrelFile.sources);
298
- previousBarrelFile.exports?.push(...barrelFile.exports || []);
299
- } else cachedFiles.set(barrelFile.path, barrelFile);
300
- });
301
- return [...cachedFiles.values()];
302
- }
303
- };
304
-
305
- //#endregion
306
- //#region src/utils/FunctionParams.ts
307
- var import_main$1 = /* @__PURE__ */ __toESM(require_main(), 1);
308
- /**
309
- * @deprecated
310
- */
311
- var FunctionParams = class FunctionParams {
312
- #items = [];
313
- constructor() {
314
- return this;
315
- }
316
- get items() {
317
- return this.#items.flat();
318
- }
319
- add(item) {
320
- if (!item) return this;
321
- if (Array.isArray(item)) {
322
- item.filter(Boolean).forEach((it) => {
323
- this.#items.push(it);
324
- });
325
- return this;
326
- }
327
- this.#items.push(item);
328
- return this;
329
- }
330
- static #orderItems(items) {
331
- return (0, import_main$1.orderBy)(items.filter(Boolean), [(v) => {
332
- if (Array.isArray(v)) return;
333
- return !v.default;
334
- }, (v) => {
335
- if (Array.isArray(v)) return;
336
- return v.required ?? true;
337
- }], ["desc", "desc"]);
338
- }
339
- static #addParams(acc, item) {
340
- const { enabled = true, name, type, required = true,...rest } = item;
341
- if (!enabled) return acc;
342
- if (!name) {
343
- acc.push(`${type}${rest.default ? ` = ${rest.default}` : ""}`);
344
- return acc;
345
- }
346
- const parameterName = name.startsWith("{") ? name : camelCase(name);
347
- if (type) if (required) acc.push(`${parameterName}: ${type}${rest.default ? ` = ${rest.default}` : ""}`);
348
- else acc.push(`${parameterName}?: ${type}`);
349
- else acc.push(`${parameterName}`);
350
- return acc;
351
- }
352
- static toObject(items) {
353
- let type = [];
354
- let name = [];
355
- const enabled = items.every((item) => item.enabled) ? items.at(0)?.enabled : true;
356
- const required = items.every((item) => item.required) ?? true;
357
- items.forEach((item) => {
358
- name = FunctionParams.#addParams(name, {
359
- ...item,
360
- type: void 0
361
- });
362
- if (items.some((item$1) => item$1.type)) type = FunctionParams.#addParams(type, item);
363
- });
364
- return {
365
- name: `{ ${name.join(", ")} }`,
366
- type: type.length ? `{ ${type.join("; ")} }` : void 0,
367
- enabled,
368
- required
369
- };
370
- }
371
- static toString(items) {
372
- return FunctionParams.#orderItems(items).reduce((acc, item) => {
373
- if (Array.isArray(item)) {
374
- if (item.length <= 0) return acc;
375
- const subItems = FunctionParams.#orderItems(item);
376
- const objectItem = FunctionParams.toObject(subItems);
377
- return FunctionParams.#addParams(acc, objectItem);
378
- }
379
- return FunctionParams.#addParams(acc, item);
380
- }, []).join(", ");
381
- }
382
- toObject() {
383
- const items = FunctionParams.#orderItems(this.#items).flat();
384
- return FunctionParams.toObject(items);
385
- }
386
- toString() {
387
- const items = FunctionParams.#orderItems(this.#items);
388
- return FunctionParams.toString(items);
389
- }
390
- };
391
-
392
- //#endregion
393
- //#region src/utils/promise.ts
394
- function isPromise(result) {
395
- return !!result && typeof result?.then === "function";
396
- }
397
- function isPromiseFulfilledResult(result) {
398
- return result.status === "fulfilled";
399
- }
400
- function isPromiseRejectedResult(result) {
401
- return result.status === "rejected";
402
- }
403
-
404
- //#endregion
405
- //#region src/utils/renderTemplate.ts
406
- function renderTemplate(template, data = void 0) {
407
- if (!data || !Object.keys(data).length) return template.replace(/{{(.*?)}}/g, "");
408
- return template.match(/{{(.*?)}}/g)?.reduce((prev, curr) => {
409
- const index = curr.split(/{{|}}/).filter(Boolean)[0]?.trim();
410
- if (index === void 0) return prev;
411
- const value = data[index];
412
- if (value === void 0) return prev;
413
- return prev.replace(curr, () => {
414
- if (typeof value === "boolean") return `${value.toString()}` || "false";
415
- return value || "";
416
- }).trim();
417
- }, template) || "";
418
- }
419
-
420
- //#endregion
421
- //#region src/utils/timeout.ts
422
- async function timeout(ms) {
423
- return new Promise((resolve$1) => {
424
- setTimeout(() => {
425
- resolve$1(true);
426
- }, ms);
427
- });
428
- }
429
-
430
- //#endregion
431
- //#region src/utils/uniqueName.ts
432
- function getUniqueName(originalName, data) {
433
- let used = data[originalName] || 0;
434
- if (used) {
435
- data[originalName] = ++used;
436
- originalName += used;
437
- }
438
- data[originalName] = 1;
439
- return originalName;
440
- }
441
- function setUniqueName(originalName, data) {
442
- let used = data[originalName] || 0;
443
- if (used) {
444
- data[originalName] = ++used;
445
- return originalName;
446
- }
447
- data[originalName] = 1;
448
- return originalName;
449
- }
450
-
451
- //#endregion
452
- //#region src/utils/URLPath.ts
453
- var URLPath = class {
454
- path;
455
- #options;
456
- constructor(path$1, options = {}) {
457
- this.path = path$1;
458
- this.#options = options;
459
- return this;
460
- }
461
- /**
462
- * Convert Swagger path to URLPath(syntax of Express)
463
- * @example /pet/{petId} => /pet/:petId
464
- */
465
- get URL() {
466
- return this.toURLPath();
467
- }
468
- get isURL() {
469
- try {
470
- if (new URL(this.path)?.href) return true;
471
- } catch (_error) {
472
- return false;
473
- }
474
- return false;
475
- }
476
- /**
477
- * Convert Swagger path to template literals/ template strings(camelcase)
478
- * @example /pet/{petId} => `/pet/${petId}`
479
- * @example /account/monetary-accountID => `/account/${monetaryAccountId}`
480
- * @example /account/userID => `/account/${userId}`
481
- */
482
- get template() {
483
- return this.toTemplateString();
484
- }
485
- get object() {
486
- return this.toObject();
487
- }
488
- get params() {
489
- return this.getParams();
490
- }
491
- toObject({ type = "path", replacer, stringify } = {}) {
492
- const object = {
493
- url: type === "path" ? this.toURLPath() : this.toTemplateString({ replacer }),
494
- params: this.getParams()
495
- };
496
- if (stringify) {
497
- if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
498
- if (object.params) return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
499
- return `{ url: '${object.url}' }`;
500
- }
501
- return object;
502
- }
503
- /**
504
- * Convert Swagger path to template literals/ template strings(camelcase)
505
- * @example /pet/{petId} => `/pet/${petId}`
506
- * @example /account/monetary-accountID => `/account/${monetaryAccountId}`
507
- * @example /account/userID => `/account/${userId}`
508
- */
509
- toTemplateString({ prefix = "", replacer } = {}) {
510
- const found = this.path.match(/{(\w|-)*}/g);
511
- let newPath = this.path.replaceAll("{", "${");
512
- if (found) newPath = found.reduce((prev, path$1) => {
513
- const pathWithoutBrackets = path$1.replaceAll("{", "").replaceAll("}", "");
514
- let param = isValidVarName(pathWithoutBrackets) ? pathWithoutBrackets : camelCase(pathWithoutBrackets);
515
- if (this.#options.casing === "camelcase") param = camelCase(param);
516
- return prev.replace(path$1, `\${${replacer ? replacer(param) : param}}`);
517
- }, this.path);
518
- return `\`${prefix}${newPath}\``;
519
- }
520
- getParams(replacer) {
521
- const found = this.path.match(/{(\w|-)*}/g);
522
- if (!found) return;
523
- const params = {};
524
- found.forEach((item) => {
525
- item = item.replaceAll("{", "").replaceAll("}", "");
526
- let param = isValidVarName(item) ? item : camelCase(item);
527
- if (this.#options.casing === "camelcase") param = camelCase(param);
528
- const key = replacer ? replacer(param) : param;
529
- params[key] = key;
530
- }, this.path);
531
- return params;
532
- }
533
- /**
534
- * Convert Swagger path to URLPath(syntax of Express)
535
- * @example /pet/{petId} => /pet/:petId
536
- */
537
- toURLPath() {
538
- return this.path.replaceAll("{", ":").replaceAll("}", "");
539
- }
540
- };
541
-
542
- //#endregion
543
- //#region src/utils/parser.ts
544
- /**
545
- * Generate a default banner for files created by Kubb
546
- * @returns A string with the default banner
547
- */
548
- function getDefaultBanner({ title, description, version, config }) {
549
- try {
550
- let source = "";
551
- if ("path" in config.input) source = path.basename(config.input.path);
552
- else if ("data" in config.input) source = "text content";
553
- let banner = "/**\n* Generated by Kubb (https://kubb.dev/).\n* Do not edit manually.\n";
554
- if (config.output.defaultBanner === "simple") {
555
- banner += "*/\n";
556
- return banner;
557
- }
558
- if (source) banner += `* Source: ${source}\n`;
559
- if (title) banner += `* Title: ${title}\n`;
560
- if (description) {
561
- const formattedDescription = description.replace(/\n/gm, "\n* ");
562
- banner += `* Description: ${formattedDescription}\n`;
563
- }
564
- if (version) banner += `* OpenAPI spec version: ${version}\n`;
565
- banner += "*/\n";
566
- return banner;
567
- } catch (_error) {
568
- return "/**\n* Generated by Kubb (https://kubb.dev/).\n* Do not edit manually.\n*/";
569
- }
570
- }
571
- /**
572
- * Helper to create a file with name and id set
573
- */
574
- function createFile(file) {
575
- const extname$1 = path.extname(file.baseName);
576
- if (!extname$1) throw new Error(`No extname found for ${file.baseName}`);
577
- const source = file.sources.map((item) => item.value).join("\n\n");
578
- const exports = file.exports?.length ? combineExports(file.exports) : [];
579
- const imports = file.imports?.length && source ? combineImports(file.imports, exports, source) : [];
580
- const sources = file.sources?.length ? combineSources(file.sources) : [];
581
- return {
582
- ...file,
583
- id: hash({ path: file.path }),
584
- name: trimExtName$1(file.baseName),
585
- extname: extname$1,
586
- imports: imports.map(createFileImport),
587
- exports: exports.map(createFileExport),
588
- sources: sources.map(createFileSource),
589
- meta: file.meta || {}
590
- };
591
- }
592
- /**
593
- * Helper to create a fileImport with extname set
594
- */
595
- function createFileSource(source) {
596
- return source;
597
- }
598
- /**
599
- * Helper to create a fileImport with extname set
600
- */
601
- function createFileImport(imp) {
602
- return { ...imp };
603
- }
604
- /**
605
- * Helper to create a fileExport with extname set
606
- */
607
- function createFileExport(exp) {
608
- return { ...exp };
609
- }
610
- function createFileParser(parser) {
611
- return parser;
612
- }
613
- const typeScriptParser = createFileParser({ async print(file, options = { extname: ".ts" }) {
614
- const module = await import("@kubb/parser-ts");
615
- const source = file.sources.map((item) => item.value).join("\n\n");
616
- const importNodes = file.imports.map((item) => {
617
- const importPath = item.root ? getRelativePath(item.root, item.path) : item.path;
618
- const hasExtname = !!path.extname(importPath);
619
- return module.factory.createImportDeclaration({
620
- name: item.name,
621
- path: options.extname && hasExtname ? `${trimExtName$1(importPath)}${options.extname}` : item.root ? trimExtName$1(importPath) : importPath,
622
- isTypeOnly: item.isTypeOnly
623
- });
624
- }).filter(Boolean);
625
- const exportNodes = file.exports.map((item) => {
626
- const exportPath = item.path;
627
- const hasExtname = !!path.extname(exportPath);
628
- return module.factory.createExportDeclaration({
629
- name: item.name,
630
- path: options.extname && hasExtname ? `${trimExtName$1(item.path)}${options.extname}` : trimExtName$1(item.path),
631
- isTypeOnly: item.isTypeOnly,
632
- asAlias: item.asAlias
633
- });
634
- }).filter(Boolean);
635
- return [
636
- file.banner,
637
- module.print([...importNodes, ...exportNodes]),
638
- source,
639
- file.footer
640
- ].join("\n");
641
- } });
642
- const tsxParser = createFileParser({ async print(file, options = { extname: ".tsx" }) {
643
- return typeScriptParser.print(file, options);
644
- } });
645
- const defaultParser = createFileParser({ async print(file) {
646
- return file.sources.map((item) => item.value).join("\n\n");
647
- } });
648
- const parsers = {
649
- ".ts": typeScriptParser,
650
- ".js": typeScriptParser,
651
- ".jsx": tsxParser,
652
- ".tsx": tsxParser,
653
- ".json": defaultParser
654
- };
655
- async function getFileParser(extname$1) {
656
- if (!extname$1) return defaultParser;
657
- const parser = parsers[extname$1];
658
- if (!parser) console.warn(`[parser] No parser found for ${extname$1}, default parser will be used`);
659
- return parser || defaultParser;
660
- }
661
- function trimExtName$1(text) {
662
- const extname$1 = text.split(".").pop();
663
- return text.replace(`.${extname$1}`, "");
664
- }
665
-
666
- //#endregion
667
- //#region src/utils/Cache.ts
668
- var Cache = class {
669
- #buffer = /* @__PURE__ */ new Map();
670
- async get(key) {
671
- return this.#buffer.get(key) ?? null;
672
- }
673
- async set(key, value) {
674
- this.#buffer.set(key, value);
675
- }
676
- async delete(key) {
677
- this.#buffer.delete(key);
678
- }
679
- async clear() {
680
- this.#buffer.clear();
681
- }
682
- async keys() {
683
- return [...this.#buffer.keys()];
684
- }
685
- async values() {
686
- return [...this.#buffer.values()];
687
- }
688
- async flush() {}
689
- };
690
-
691
- //#endregion
692
- //#region src/FileManager.ts
693
- var import_main = /* @__PURE__ */ __toESM(require_main(), 1);
694
- var FileManager = class {
695
- #cache = new Cache();
696
- #limit = pLimit(100);
697
- constructor() {
698
- return this;
699
- }
700
- async add(...files) {
701
- const resolvedFiles = [];
702
- const mergedFiles = /* @__PURE__ */ new Map();
703
- files.forEach((file) => {
704
- const existing = mergedFiles.get(file.path);
705
- if (existing) mergedFiles.set(file.path, mergeFile(existing, file));
706
- else mergedFiles.set(file.path, file);
707
- });
708
- for (const file of mergedFiles.values()) {
709
- const existing = await this.#cache.get(file.path);
710
- const resolvedFile = createFile(existing ? mergeFile(existing, file) : file);
711
- await this.#cache.set(resolvedFile.path, resolvedFile);
712
- await this.#cache.flush();
713
- resolvedFiles.push(resolvedFile);
714
- }
715
- if (files.length > 1) return resolvedFiles;
716
- return resolvedFiles[0];
717
- }
718
- async getByPath(path$1) {
719
- return this.#cache.get(path$1);
720
- }
721
- async deleteByPath(path$1) {
722
- await this.#cache.delete(path$1);
723
- }
724
- async clear() {
725
- await this.#cache.clear();
726
- }
727
- async getFiles() {
728
- const filesTasks = (0, import_main.orderBy)(await this.#cache.keys(), [(v) => v.length, (v) => trimExtName(v).endsWith("index")]).map((key) => this.#limit(async () => {
729
- return await this.#cache.get(key);
730
- }));
731
- return (await Promise.all(filesTasks)).filter(Boolean);
732
- }
733
- async processFiles({ dryRun, root, extension, logger }) {
734
- const files = await this.getFiles();
735
- logger?.emit("progress_start", {
736
- id: "files",
737
- size: files.length,
738
- message: "Writing files ..."
739
- });
740
- const promises = files.map((file) => {
741
- return this.#limit(async () => {
742
- const message = file ? `Writing ${relative(root, file.path)}` : "";
743
- const extname$1 = extension?.[file.extname] || void 0;
744
- if (!dryRun) {
745
- const source = await getSource(file, {
746
- logger,
747
- extname: extname$1
748
- });
749
- await write(file.path, source, { sanity: false });
750
- }
751
- logger?.emit("progressed", {
752
- id: "files",
753
- message
754
- });
755
- });
756
- });
757
- await Promise.all(promises);
758
- logger?.emit("progress_stop", { id: "files" });
759
- return files;
760
- }
761
- async getBarrelFiles({ type, meta = {}, root, output, logger }) {
762
- if (!type || type === "propagate") return [];
763
- const barrelManager = new BarrelManager({ logger });
764
- const files = await this.getFiles();
765
- const pathToBuildFrom = join(root, output.path);
766
- if (trimExtName(pathToBuildFrom).endsWith("index")) {
767
- logger?.emit("warning", "Output has the same fileName as the barrelFiles, please disable barrel generation");
768
- return [];
769
- }
770
- const barrelFiles = barrelManager.getFiles({
771
- files,
772
- root: pathToBuildFrom,
773
- meta
774
- });
775
- if (type === "all") return barrelFiles.map((file) => {
776
- return {
777
- ...file,
778
- exports: file.exports?.map((exportItem) => {
779
- return {
780
- ...exportItem,
781
- name: void 0
782
- };
783
- })
784
- };
785
- });
786
- return barrelFiles.map((indexFile) => {
787
- return {
788
- ...indexFile,
789
- meta
790
- };
791
- });
792
- }
793
- static getMode(path$1) {
794
- if (!path$1) return "split";
795
- return extname(path$1) ? "single" : "split";
796
- }
797
- };
798
- async function getSource(file, { logger, extname: extname$1 } = {}) {
799
- return (await getFileParser(file.extname)).print(file, {
800
- logger,
801
- extname: extname$1
802
- });
803
- }
804
- function mergeFile(a, b) {
805
- return {
806
- ...a,
807
- sources: [...a.sources || [], ...b.sources || []],
808
- imports: [...a.imports || [], ...b.imports || []],
809
- exports: [...a.exports || [], ...b.exports || []]
810
- };
811
- }
812
- function combineSources(sources) {
813
- return uniqueBy(sources, (obj) => [
814
- obj.name,
815
- obj.isExportable,
816
- obj.isTypeOnly
817
- ]);
818
- }
819
- function combineExports(exports) {
820
- return (0, import_main.orderBy)(exports, [
821
- (v) => !!Array.isArray(v.name),
822
- (v) => !v.isTypeOnly,
823
- (v) => v.path,
824
- (v) => !!v.name,
825
- (v) => Array.isArray(v.name) ? (0, import_main.orderBy)(v.name) : v.name
826
- ]).reduce((prev, curr) => {
827
- const name = curr.name;
828
- const prevByPath = prev.findLast((imp) => imp.path === curr.path);
829
- if (prev.findLast((imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly)) return prev;
830
- if (prev.findLast((imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly && imp.asAlias === curr.asAlias) || Array.isArray(name) && !name.length || prevByPath?.asAlias && !curr.asAlias) return prev;
831
- if (!prevByPath) return [...prev, {
832
- ...curr,
833
- name: Array.isArray(name) ? [...new Set(name)] : name
834
- }];
835
- if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(curr.name) && prevByPath.isTypeOnly === curr.isTypeOnly) {
836
- prevByPath.name = [...new Set([...prevByPath.name, ...curr.name])];
837
- return prev;
838
- }
839
- return [...prev, curr];
840
- }, []);
841
- }
842
- function combineImports(imports, exports, source) {
843
- return (0, import_main.orderBy)(imports, [
844
- (v) => !!Array.isArray(v.name),
845
- (v) => !v.isTypeOnly,
846
- (v) => v.path,
847
- (v) => !!v.name,
848
- (v) => Array.isArray(v.name) ? (0, import_main.orderBy)(v.name) : v.name
849
- ]).reduce((prev, curr) => {
850
- let name = Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name;
851
- const hasImportInSource = (importName) => {
852
- if (!source) return true;
853
- const checker = (name$1) => {
854
- return name$1 && source.includes(name$1);
855
- };
856
- return checker(importName) || exports.some(({ name: name$1 }) => Array.isArray(name$1) ? name$1.some(checker) : checker(name$1));
857
- };
858
- if (curr.path === curr.root) return prev;
859
- if (Array.isArray(name)) name = name.filter((item) => typeof item === "string" ? hasImportInSource(item) : hasImportInSource(item.propertyName));
860
- const prevByPath = prev.findLast((imp) => imp.path === curr.path && imp.isTypeOnly === curr.isTypeOnly);
861
- const uniquePrev = prev.findLast((imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly);
862
- if (prev.findLast((imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly)) return prev;
863
- if (uniquePrev || Array.isArray(name) && !name.length) return prev;
864
- if (!prevByPath) return [...prev, {
865
- ...curr,
866
- name
867
- }];
868
- if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(name) && prevByPath.isTypeOnly === curr.isTypeOnly) {
869
- prevByPath.name = [...new Set([...prevByPath.name, ...name])];
870
- return prev;
871
- }
872
- if (!Array.isArray(name) && name && !hasImportInSource(name)) return prev;
873
- return [...prev, curr];
874
- }, []);
875
- }
876
-
877
- //#endregion
878
- export { isPromiseRejectedResult as _, createFileExport as a, Queue as b, getDefaultBanner as c, getUniqueName as d, setUniqueName as f, isPromiseFulfilledResult as g, isPromise as h, createFile as i, getFileParser as l, renderTemplate as m, getSource as n, createFileImport as o, timeout as p, Cache as r, createFileParser as s, FileManager as t, URLPath as u, FunctionParams as v, pLimit as y };
879
- //# sourceMappingURL=FileManager-zlhCXf6A.js.map