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