@kubb/core 2.17.0 → 2.18.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 (79) hide show
  1. package/dist/{chunk-C6JPLJPT.cjs → chunk-2H4XNW5D.cjs} +351 -267
  2. package/dist/chunk-2H4XNW5D.cjs.map +1 -0
  3. package/dist/chunk-2OWVHAMB.cjs +2584 -0
  4. package/dist/chunk-2OWVHAMB.cjs.map +1 -0
  5. package/dist/chunk-3PQTRXZD.js +1597 -0
  6. package/dist/chunk-3PQTRXZD.js.map +1 -0
  7. package/dist/{chunk-PVJACA4A.js → chunk-4X5FFJPJ.js} +35 -2
  8. package/dist/chunk-4X5FFJPJ.js.map +1 -0
  9. package/dist/{chunk-6V72PGTE.cjs → chunk-5T2QA53B.cjs} +139 -3
  10. package/dist/chunk-5T2QA53B.cjs.map +1 -0
  11. package/dist/{chunk-CWXJJLZF.cjs → chunk-7HFYOZ7F.cjs} +12 -4
  12. package/dist/chunk-7HFYOZ7F.cjs.map +1 -0
  13. package/dist/chunk-FRT5NM5I.js +311 -0
  14. package/dist/chunk-FRT5NM5I.js.map +1 -0
  15. package/dist/chunk-I64YA7CN.cjs +322 -0
  16. package/dist/chunk-I64YA7CN.cjs.map +1 -0
  17. package/dist/{chunk-NLZ2T737.js → chunk-MDO6MCFJ.js} +9 -2
  18. package/dist/chunk-MDO6MCFJ.js.map +1 -0
  19. package/dist/{chunk-JFESCSNU.cjs → chunk-OCUNVJPQ.cjs} +6 -8
  20. package/dist/chunk-OCUNVJPQ.cjs.map +1 -0
  21. package/dist/{chunk-PQ7P6QX5.cjs → chunk-SU2W2A6V.cjs} +3 -3
  22. package/dist/{chunk-YQ5ZU5PV.js → chunk-UCKFXEKM.js} +3 -5
  23. package/dist/{chunk-YQ5ZU5PV.js.map → chunk-UCKFXEKM.js.map} +1 -1
  24. package/dist/fs.cjs +3 -6
  25. package/dist/fs.cjs.map +1 -1
  26. package/dist/fs.js +5 -7
  27. package/dist/index.cjs +10 -2553
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.d.cts +6 -6
  30. package/dist/index.d.ts +6 -6
  31. package/dist/index.js +21 -1576
  32. package/dist/index.js.map +1 -1
  33. package/dist/logger.cjs +3 -4
  34. package/dist/mocks.cjs +19 -6
  35. package/dist/mocks.cjs.map +1 -1
  36. package/dist/mocks.d.cts +3 -2
  37. package/dist/mocks.d.ts +3 -2
  38. package/dist/mocks.js +16 -2
  39. package/dist/mocks.js.map +1 -1
  40. package/dist/transformers.cjs +3 -5
  41. package/dist/transformers.js +3 -5
  42. package/dist/utils.cjs +26 -194
  43. package/dist/utils.cjs.map +1 -1
  44. package/dist/utils.d.cts +4 -1
  45. package/dist/utils.d.ts +4 -1
  46. package/dist/utils.js +12 -172
  47. package/dist/utils.js.map +1 -1
  48. package/globals.d.ts +9 -12
  49. package/package.json +6 -6
  50. package/src/BarrelManager.ts +1 -1
  51. package/src/FileManager.ts +9 -9
  52. package/src/PluginManager.ts +6 -6
  53. package/src/build.ts +22 -10
  54. package/src/index.ts +1 -1
  55. package/src/plugin.ts +5 -9
  56. package/src/types.ts +4 -2
  57. package/src/utils/getParser.ts +17 -0
  58. package/src/utils/index.ts +1 -0
  59. package/dist/chunk-4ARKZPSY.js +0 -36
  60. package/dist/chunk-4ARKZPSY.js.map +0 -1
  61. package/dist/chunk-5PLDNXZK.js +0 -10
  62. package/dist/chunk-5PLDNXZK.js.map +0 -1
  63. package/dist/chunk-6V72PGTE.cjs.map +0 -1
  64. package/dist/chunk-C6JPLJPT.cjs.map +0 -1
  65. package/dist/chunk-CFHVVM3A.cjs +0 -132
  66. package/dist/chunk-CFHVVM3A.cjs.map +0 -1
  67. package/dist/chunk-CWXJJLZF.cjs.map +0 -1
  68. package/dist/chunk-FU3AZXHF.cjs +0 -19
  69. package/dist/chunk-FU3AZXHF.cjs.map +0 -1
  70. package/dist/chunk-GBVPADCA.js +0 -127
  71. package/dist/chunk-GBVPADCA.js.map +0 -1
  72. package/dist/chunk-JFESCSNU.cjs.map +0 -1
  73. package/dist/chunk-LEPKPXA4.cjs +0 -143
  74. package/dist/chunk-LEPKPXA4.cjs.map +0 -1
  75. package/dist/chunk-NLZ2T737.js.map +0 -1
  76. package/dist/chunk-PVJACA4A.js.map +0 -1
  77. package/dist/chunk-T7WVNL7N.cjs +0 -94
  78. package/dist/chunk-T7WVNL7N.cjs.map +0 -1
  79. /package/dist/{chunk-PQ7P6QX5.cjs.map → chunk-SU2W2A6V.cjs.map} +0 -0
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkC6JPLJPTcjs = require('./chunk-C6JPLJPT.cjs');
3
+ var _chunk2H4XNW5Dcjs = require('./chunk-2H4XNW5D.cjs');
4
4
 
5
5
 
6
6
 
@@ -8,7 +8,7 @@ var _chunkOOZTXU7Fcjs = require('./chunk-OOZTXU7F.cjs');
8
8
 
9
9
  // src/fs/read.ts
10
10
  _chunkOOZTXU7Fcjs.init_cjs_shims.call(void 0, );
11
- var import_fs_extra = _chunkOOZTXU7Fcjs.__toESM.call(void 0, _chunkC6JPLJPTcjs.require_lib.call(void 0, ), 1);
11
+ var import_fs_extra = _chunkOOZTXU7Fcjs.__toESM.call(void 0, _chunk2H4XNW5Dcjs.require_lib.call(void 0, ), 1);
12
12
  var _path = require('path');
13
13
  var _jsruntime = require('js-runtime');
14
14
  function slash(path, platform = "linux") {
@@ -59,9 +59,17 @@ function readSync(path) {
59
59
  return syncReader(path);
60
60
  }
61
61
 
62
+ // src/fs/clean.ts
63
+ _chunkOOZTXU7Fcjs.init_cjs_shims.call(void 0, );
64
+ var import_fs_extra2 = _chunkOOZTXU7Fcjs.__toESM.call(void 0, _chunk2H4XNW5Dcjs.require_lib.call(void 0, ), 1);
65
+ async function clean(path) {
66
+ return import_fs_extra2.default.remove(path);
67
+ }
68
+
69
+
62
70
 
63
71
 
64
72
 
65
73
 
66
- exports.getRelativePath = getRelativePath; exports.read = read; exports.readSync = readSync;
67
- //# sourceMappingURL=chunk-CWXJJLZF.cjs.map
74
+ exports.getRelativePath = getRelativePath; exports.read = read; exports.readSync = readSync; exports.clean = clean;
75
+ //# sourceMappingURL=chunk-7HFYOZ7F.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/fs/read.ts","../src/fs/clean.ts"],"names":["fs","import_fs_extra"],"mappings":";;;;;;;;;AAAA;AAEA,sBAAe;AAFf,SAAS,UAAU,SAAS,gBAAgB;AAG5C,SAAS,gBAAgB;AAEzB,SAAS,MAAM,MAAc,WAAwC,SAAS;AAC5E,QAAM,gBAAgB,YAAY,KAAK,IAAI;AAE3C,MAAI,CAAC,SAAS,KAAK,EAAE,SAAS,QAAQ,KAAK,CAAC,eAAe;AAEzD,WAAO,KAAK,WAAW,OAAO,GAAG,EAAE,QAAQ,OAAO,EAAE,EAAE,QAAQ;AAAA,EAChE;AAGA,SAAO,KAAK,WAAW,OAAO,GAAG,EAAE,QAAQ,OAAO,EAAE,EAAE,QAAQ;AAChE;AAEO,SAAS,gBAAgB,SAAyB,UAA0B,WAAwC,SAAiB;AAC1I,MAAI,CAAC,WAAW,CAAC,UAAU;AACzB,UAAM,IAAI,MAAM,uEAAuE,WAAW,EAAE,IAAI,YAAY,EAAE,EAAE;AAAA,EAC1H;AAEA,QAAM,eAAe,SAAS,SAAS,QAAQ;AAI/C,QAAM,cAAc,MAAM,cAAc,QAAQ;AAEhD,MAAI,YAAY,WAAW,KAAK,GAAG;AACjC,WAAO,YAAY,QAAQ,SAAS,WAAW,GAAG,SAAS,aAAa,QAAQ,QAAQ,CAAC,CAAC;AAAA,EAC5F;AAEA,SAAO,KAAK,YAAY,QAAQ,SAAS,WAAW,GAAG,SAAS,aAAa,QAAQ,QAAQ,CAAC,CAAC,CAAC;AAClG;AAEA,IAAM,SAAS;AAAA,EACb;AAAA,IACE,MAAM,OAAO,SAAiB;AAC5B,aAAO,gBAAAA,QAAG,SAAS,MAAM,EAAE,UAAU,OAAO,CAAC;AAAA,IAC/C;AAAA,IACA,KAAK,OAAO,SAAiB;AAC3B,YAAM,OAAO,IAAI,KAAK,IAAI;AAE1B,aAAO,KAAK,KAAK;AAAA,IACnB;AAAA,EACF;AAAA,EACA;AACF;AAEA,IAAM,aAAa;AAAA,EACjB;AAAA,IACE,MAAM,CAAC,SAAiB;AACtB,aAAO,gBAAAA,QAAG,aAAa,MAAM,EAAE,UAAU,OAAO,CAAC;AAAA,IACnD;AAAA,IACA,KAAK,MAAM;AACT,YAAM,IAAI,MAAM,sBAAsB;AAAA,IACxC;AAAA,EACF;AAAA,EACA;AACF;AAEA,eAAsB,KAAK,MAA+B;AACxD,SAAO,OAAO,IAAI;AACpB;AAEO,SAAS,SAAS,MAAsB;AAC7C,SAAO,WAAW,IAAI;AACxB;;;ACnEA;AAAA,IAAAC,mBAAe;AAEf,eAAsB,MAAM,MAA6B;AACvD,SAAO,iBAAAD,QAAG,OAAO,IAAI;AACvB","sourcesContent":["import { basename, extname, relative } from 'node:path'\n\nimport fs from 'fs-extra'\nimport { switcher } from 'js-runtime'\n\nfunction slash(path: string, platform: 'windows' | 'mac' | 'linux' = 'linux') {\n const isWindowsPath = /^\\\\\\\\\\?\\\\/.test(path)\n\n if (['linux', 'mac'].includes(platform) && !isWindowsPath) {\n // linux and mac\n return path.replaceAll(/\\\\/g, '/').replace('../', '').trimEnd()\n }\n\n // windows\n return path.replaceAll(/\\\\/g, '/').replace('../', '').trimEnd()\n}\n\nexport function getRelativePath(rootDir?: string | null, filePath?: string | null, platform: 'windows' | 'mac' | 'linux' = 'linux'): string {\n if (!rootDir || !filePath) {\n throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir || ''} ${filePath || ''}`)\n }\n\n const relativePath = relative(rootDir, filePath)\n\n // On Windows, paths are separated with a \"\\\"\n // However, web browsers use \"/\" no matter the platform\n const slashedPath = slash(relativePath, platform)\n\n if (slashedPath.startsWith('../')) {\n return slashedPath.replace(basename(slashedPath), basename(slashedPath, extname(filePath)))\n }\n\n return `./${slashedPath.replace(basename(slashedPath), basename(slashedPath, extname(filePath)))}`\n}\n\nconst reader = switcher(\n {\n node: async (path: string) => {\n return fs.readFile(path, { encoding: 'utf8' })\n },\n bun: async (path: string) => {\n const file = Bun.file(path)\n\n return file.text()\n },\n },\n 'node',\n)\n\nconst syncReader = switcher(\n {\n node: (path: string) => {\n return fs.readFileSync(path, { encoding: 'utf8' })\n },\n bun: () => {\n throw new Error('Bun cannot read sync')\n },\n },\n 'node',\n)\n\nexport async function read(path: string): Promise<string> {\n return reader(path)\n}\n\nexport function readSync(path: string): string {\n return syncReader(path)\n}\n","import fs from 'fs-extra'\n\nexport async function clean(path: string): Promise<void> {\n return fs.remove(path)\n}\n"]}
@@ -0,0 +1,311 @@
1
+ import {
2
+ camelCase,
3
+ orderBy
4
+ } from "./chunk-4X5FFJPJ.js";
5
+ import {
6
+ __privateAdd,
7
+ __privateGet,
8
+ __privateMethod
9
+ } from "./chunk-Z4BLTVTB.js";
10
+
11
+ // src/utils/FunctionParams.ts
12
+ var _items, _orderItems, orderItems_fn, _addParams, addParams_fn;
13
+ var _FunctionParams = class _FunctionParams {
14
+ constructor() {
15
+ __privateAdd(this, _items, []);
16
+ return this;
17
+ }
18
+ get items() {
19
+ return __privateGet(this, _items).flat();
20
+ }
21
+ add(item) {
22
+ if (!item) {
23
+ return this;
24
+ }
25
+ if (Array.isArray(item)) {
26
+ item.filter(Boolean).forEach((it) => __privateGet(this, _items).push(it));
27
+ return this;
28
+ }
29
+ __privateGet(this, _items).push(item);
30
+ return this;
31
+ }
32
+ static toObject(items) {
33
+ let type = [];
34
+ let name = [];
35
+ const enabled = items.every((item) => item.enabled) ? items.at(0)?.enabled : true;
36
+ const required = items.every((item) => item.required) ?? true;
37
+ items.forEach((item) => {
38
+ var _a, _b;
39
+ name = __privateMethod(_a = _FunctionParams, _addParams, addParams_fn).call(_a, name, { ...item, type: void 0 });
40
+ if (items.some((item2) => item2.type)) {
41
+ type = __privateMethod(_b = _FunctionParams, _addParams, addParams_fn).call(_b, type, item);
42
+ }
43
+ });
44
+ return {
45
+ name: `{ ${name.join(", ")} }`,
46
+ type: type.length ? `{ ${type.join("; ")} }` : void 0,
47
+ enabled,
48
+ required
49
+ };
50
+ }
51
+ static toString(items) {
52
+ var _a;
53
+ const sortedData = __privateMethod(_a = _FunctionParams, _orderItems, orderItems_fn).call(_a, items);
54
+ return sortedData.reduce((acc, item) => {
55
+ var _a2, _b, _c;
56
+ if (Array.isArray(item)) {
57
+ if (item.length <= 0) {
58
+ return acc;
59
+ }
60
+ const subItems = __privateMethod(_a2 = _FunctionParams, _orderItems, orderItems_fn).call(_a2, item);
61
+ const objectItem = _FunctionParams.toObject(subItems);
62
+ return __privateMethod(_b = _FunctionParams, _addParams, addParams_fn).call(_b, acc, objectItem);
63
+ }
64
+ return __privateMethod(_c = _FunctionParams, _addParams, addParams_fn).call(_c, acc, item);
65
+ }, []).join(", ");
66
+ }
67
+ toObject() {
68
+ var _a;
69
+ const items = __privateMethod(_a = _FunctionParams, _orderItems, orderItems_fn).call(_a, __privateGet(this, _items)).flat();
70
+ return _FunctionParams.toObject(items);
71
+ }
72
+ toString() {
73
+ var _a;
74
+ const items = __privateMethod(_a = _FunctionParams, _orderItems, orderItems_fn).call(_a, __privateGet(this, _items));
75
+ return _FunctionParams.toString(items);
76
+ }
77
+ };
78
+ _items = new WeakMap();
79
+ _orderItems = new WeakSet();
80
+ orderItems_fn = function(items) {
81
+ return orderBy(
82
+ items.filter(Boolean),
83
+ [
84
+ (v) => {
85
+ if (Array.isArray(v)) {
86
+ return void 0;
87
+ }
88
+ return !v.default;
89
+ },
90
+ (v) => {
91
+ if (Array.isArray(v)) {
92
+ return void 0;
93
+ }
94
+ return v.required ?? true;
95
+ }
96
+ ],
97
+ ["desc", "desc"]
98
+ );
99
+ };
100
+ _addParams = new WeakSet();
101
+ addParams_fn = function(acc, item) {
102
+ const { enabled = true, name, type, required = true, ...rest } = item;
103
+ if (!enabled) {
104
+ return acc;
105
+ }
106
+ if (!name) {
107
+ acc.push(`${type}${rest.default ? ` = ${rest.default}` : ""}`);
108
+ return acc;
109
+ }
110
+ const parameterName = name.startsWith("{") ? name : camelCase(name);
111
+ if (type) {
112
+ if (required) {
113
+ acc.push(`${parameterName}: ${type}${rest.default ? ` = ${rest.default}` : ""}`);
114
+ } else {
115
+ acc.push(`${parameterName}?: ${type}`);
116
+ }
117
+ } else {
118
+ acc.push(`${parameterName}`);
119
+ }
120
+ return acc;
121
+ };
122
+ __privateAdd(_FunctionParams, _orderItems);
123
+ __privateAdd(_FunctionParams, _addParams);
124
+ var FunctionParams = _FunctionParams;
125
+
126
+ // src/utils/promise.ts
127
+ function isPromise(result) {
128
+ return !!result && typeof result?.then === "function";
129
+ }
130
+ function isPromiseFulfilledResult(result) {
131
+ return result.status === "fulfilled";
132
+ }
133
+ function isPromiseRejectedResult(result) {
134
+ return result.status === "rejected";
135
+ }
136
+
137
+ // src/utils/renderTemplate.ts
138
+ function renderTemplate(template, data = void 0) {
139
+ if (!data || !Object.keys(data).length) {
140
+ return template.replace(/{{(.*?)}}/g, "");
141
+ }
142
+ const matches = template.match(/{{(.*?)}}/g);
143
+ return matches?.reduce((prev, curr) => {
144
+ const index = curr.split(/{{|}}/).filter(Boolean)[0]?.trim();
145
+ if (index === void 0) {
146
+ return prev;
147
+ }
148
+ const value = data[index];
149
+ if (value === void 0) {
150
+ return prev;
151
+ }
152
+ return prev.replace(curr, () => {
153
+ if (typeof value === "boolean") {
154
+ return `${value.toString()}` || "false";
155
+ }
156
+ return value || "";
157
+ }).trim();
158
+ }, template) || "";
159
+ }
160
+
161
+ // src/utils/timeout.ts
162
+ async function timeout(ms) {
163
+ return new Promise((resolve) => {
164
+ setTimeout(() => {
165
+ resolve(true);
166
+ }, ms);
167
+ });
168
+ }
169
+
170
+ // src/utils/uniqueName.ts
171
+ function getUniqueName(originalName, data) {
172
+ let used = data[originalName] || 0;
173
+ if (used) {
174
+ data[originalName] = ++used;
175
+ originalName += used;
176
+ }
177
+ data[originalName] = 1;
178
+ return originalName;
179
+ }
180
+ function setUniqueName(originalName, data) {
181
+ let used = data[originalName] || 0;
182
+ if (used) {
183
+ data[originalName] = ++used;
184
+ return originalName;
185
+ }
186
+ data[originalName] = 1;
187
+ return originalName;
188
+ }
189
+
190
+ // src/utils/URLPath.ts
191
+ var URLPath = class {
192
+ constructor(path) {
193
+ this.path = path;
194
+ return this;
195
+ }
196
+ /**
197
+ * Convert Swagger path to URLPath(syntax of Express)
198
+ * @example /pet/{petId} => /pet/:petId
199
+ */
200
+ get URL() {
201
+ return this.toURLPath();
202
+ }
203
+ get isURL() {
204
+ try {
205
+ const url = new URL(this.path);
206
+ if (url?.href) {
207
+ return true;
208
+ }
209
+ } catch (error) {
210
+ return false;
211
+ }
212
+ return false;
213
+ }
214
+ /**
215
+ * Convert Swagger path to template literals/ template strings(camelcase)
216
+ * @example /pet/{petId} => `/pet/${petId}`
217
+ * @example /account/monetary-accountID => `/account/${monetaryAccountId}`
218
+ * @example /account/userID => `/account/${userId}`
219
+ */
220
+ get template() {
221
+ return this.toTemplateString();
222
+ }
223
+ get object() {
224
+ return this.toObject();
225
+ }
226
+ get params() {
227
+ return this.getParams();
228
+ }
229
+ toObject({ type = "path", replacer, stringify } = {}) {
230
+ const object = {
231
+ url: type === "path" ? this.toURLPath() : this.toTemplateString(replacer),
232
+ params: this.getParams()
233
+ };
234
+ if (stringify) {
235
+ if (type === "template") {
236
+ return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
237
+ }
238
+ if (object.params) {
239
+ return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
240
+ }
241
+ return `{ url: '${object.url}' }`;
242
+ }
243
+ return object;
244
+ }
245
+ /**
246
+ * Convert Swagger path to template literals/ template strings(camelcase)
247
+ * @example /pet/{petId} => `/pet/${petId}`
248
+ * @example /account/monetary-accountID => `/account/${monetaryAccountId}`
249
+ * @example /account/userID => `/account/${userId}`
250
+ */
251
+ toTemplateString(replacer) {
252
+ const regex = /{(\w|-)*}/g;
253
+ const found = this.path.match(regex);
254
+ let newPath = this.path.replaceAll("{", "${");
255
+ if (found) {
256
+ newPath = found.reduce((prev, curr) => {
257
+ const pathParam = replacer ? replacer(camelCase(curr)) : camelCase(curr);
258
+ const replacement = `\${${pathParam}}`;
259
+ return prev.replace(curr, replacement);
260
+ }, this.path);
261
+ }
262
+ return `\`${newPath}\``;
263
+ }
264
+ getParams(replacer) {
265
+ const regex = /{(\w|-)*}/g;
266
+ const found = this.path.match(regex);
267
+ if (!found) {
268
+ return void 0;
269
+ }
270
+ const params = {};
271
+ found.forEach((item) => {
272
+ item = item.replaceAll("{", "").replaceAll("}", "");
273
+ const pathParam = replacer ? replacer(camelCase(item)) : camelCase(item);
274
+ params[pathParam] = pathParam;
275
+ }, this.path);
276
+ return params;
277
+ }
278
+ /**
279
+ * Convert Swagger path to URLPath(syntax of Express)
280
+ * @example /pet/{petId} => /pet/:petId
281
+ */
282
+ toURLPath() {
283
+ return this.path.replaceAll("{", ":").replaceAll("}", "");
284
+ }
285
+ };
286
+
287
+ // src/utils/getParser.ts
288
+ async function getParser(language) {
289
+ let modulePromise;
290
+ switch (language) {
291
+ default:
292
+ modulePromise = import("@kubb/parser-ts");
293
+ break;
294
+ }
295
+ const module = await modulePromise;
296
+ return module;
297
+ }
298
+
299
+ export {
300
+ FunctionParams,
301
+ isPromise,
302
+ isPromiseFulfilledResult,
303
+ isPromiseRejectedResult,
304
+ renderTemplate,
305
+ timeout,
306
+ getUniqueName,
307
+ setUniqueName,
308
+ URLPath,
309
+ getParser
310
+ };
311
+ //# sourceMappingURL=chunk-FRT5NM5I.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/FunctionParams.ts","../src/utils/promise.ts","../src/utils/renderTemplate.ts","../src/utils/timeout.ts","../src/utils/uniqueName.ts","../src/utils/URLPath.ts","../src/utils/getParser.ts"],"sourcesContent":["import { orderBy } from 'natural-orderby'\n\nimport { camelCase } from '../transformers/casing.ts'\n\ntype FunctionParamsASTWithoutType = {\n name?: string\n type?: string\n /**\n * @default true\n */\n required?: boolean\n /**\n * @default true\n */\n enabled?: boolean\n default?: string\n}\n\ntype FunctionParamsASTWithType = {\n name?: never\n type: string\n /**\n * @default true\n */\n required?: boolean\n /**\n * @default true\n */\n enabled?: boolean\n default?: string\n}\n/**\n * @deprecated\n */\nexport type FunctionParamsAST = FunctionParamsASTWithoutType | FunctionParamsASTWithType\n\n/**\n * @deprecated\n */\nexport class FunctionParams {\n #items: Array<FunctionParamsAST | FunctionParamsAST[]> = []\n constructor() {\n return this\n }\n\n get items(): FunctionParamsAST[] {\n return this.#items.flat()\n }\n\n add(item: FunctionParamsAST | Array<FunctionParamsAST | FunctionParamsAST[] | undefined> | undefined): FunctionParams {\n if (!item) {\n return this\n }\n\n if (Array.isArray(item)) {\n item.filter(Boolean).forEach((it) => this.#items.push(it))\n return this\n }\n this.#items.push(item)\n\n return this\n }\n static #orderItems(items: Array<FunctionParamsAST | FunctionParamsAST[]>) {\n return orderBy(\n items.filter(Boolean),\n [\n (v) => {\n if (Array.isArray(v)) {\n return undefined\n }\n return !v.default\n },\n (v) => {\n if (Array.isArray(v)) {\n return undefined\n }\n return v.required ?? true\n },\n ],\n ['desc', 'desc'],\n )\n }\n\n static #addParams(acc: string[], item: FunctionParamsAST) {\n const { enabled = true, name, type, required = true, ...rest } = item\n\n if (!enabled) {\n return acc\n }\n\n if (!name) {\n // when name is not se we will use TypeScript generics\n acc.push(`${type}${rest.default ? ` = ${rest.default}` : ''}`)\n\n return acc\n }\n // TODO check whey we still need the camelcase here\n const parameterName = name.startsWith('{') ? name : camelCase(name)\n\n if (type) {\n if (required) {\n acc.push(`${parameterName}: ${type}${rest.default ? ` = ${rest.default}` : ''}`)\n } else {\n acc.push(`${parameterName}?: ${type}`)\n }\n } else {\n acc.push(`${parameterName}`)\n }\n\n return acc\n }\n\n static toObject(items: FunctionParamsAST[]): FunctionParamsAST {\n let type: string[] = []\n let name: string[] = []\n\n const enabled = items.every((item) => item.enabled) ? items.at(0)?.enabled : true\n const required = items.every((item) => item.required) ?? true\n\n items.forEach((item) => {\n name = FunctionParams.#addParams(name, { ...item, type: undefined })\n if (items.some((item) => item.type)) {\n type = FunctionParams.#addParams(type, item)\n }\n })\n\n return {\n name: `{ ${name.join(', ')} }`,\n type: type.length ? `{ ${type.join('; ')} }` : undefined,\n enabled,\n required,\n }\n }\n\n static toString(items: (FunctionParamsAST | FunctionParamsAST[])[]): string {\n const sortedData = FunctionParams.#orderItems(items)\n\n return sortedData\n .reduce((acc, item) => {\n if (Array.isArray(item)) {\n if (item.length <= 0) {\n return acc\n }\n const subItems = FunctionParams.#orderItems(item) as FunctionParamsAST[]\n const objectItem = FunctionParams.toObject(subItems)\n\n return FunctionParams.#addParams(acc, objectItem)\n }\n\n return FunctionParams.#addParams(acc, item)\n }, [] as string[])\n .join(', ')\n }\n\n toObject(): FunctionParamsAST {\n const items = FunctionParams.#orderItems(this.#items).flat()\n\n return FunctionParams.toObject(items)\n }\n\n toString(): string {\n const items = FunctionParams.#orderItems(this.#items)\n\n return FunctionParams.toString(items)\n }\n}\n","import type { PossiblePromise } from '@kubb/types'\n\nexport function isPromise<T>(result: PossiblePromise<T>): result is Promise<T> {\n return !!result && typeof (result as Promise<unknown>)?.then === 'function'\n}\n\nexport function isPromiseFulfilledResult<T = unknown>(result: PromiseSettledResult<unknown>): result is PromiseFulfilledResult<T> {\n return result.status === 'fulfilled'\n}\n\nexport function isPromiseRejectedResult<T>(result: PromiseSettledResult<unknown>): result is Omit<PromiseRejectedResult, 'reason'> & { reason: T } {\n return result.status === 'rejected'\n}\n","export function renderTemplate<TData extends Record<string, unknown> = Record<string, unknown>>(template: string, data: TData | undefined = undefined): string {\n if (!data || !Object.keys(data).length) {\n return template.replace(/{{(.*?)}}/g, '')\n }\n\n const matches = template.match(/{{(.*?)}}/g)\n\n return (\n matches?.reduce((prev, curr) => {\n const index = curr.split(/{{|}}/).filter(Boolean)[0]?.trim()\n if (index === undefined) {\n return prev\n }\n const value = data[index]\n\n if (value === undefined) {\n return prev\n }\n\n return prev\n .replace(curr, () => {\n if (typeof value === 'boolean') {\n return `${value.toString()}` || 'false'\n }\n\n return (value as string) || ''\n })\n .trim()\n }, template) || ''\n )\n}\n","export async function timeout(ms: number): Promise<unknown> {\n return new Promise((resolve) => {\n setTimeout(() => {\n resolve(true)\n }, ms)\n })\n}\n","export function getUniqueName(originalName: string, data: Record<string, number>): string {\n let used = data[originalName] || 0\n if (used) {\n data[originalName] = ++used\n originalName += used\n }\n data[originalName] = 1\n return originalName\n}\n\nexport function setUniqueName(originalName: string, data: Record<string, number>): string {\n let used = data[originalName] || 0\n if (used) {\n data[originalName] = ++used\n\n return originalName\n }\n data[originalName] = 1\n return originalName\n}\n","import { camelCase } from '../transformers/casing.ts'\n\nexport type URLObject = {\n url: string\n params?: Record<string, string>\n}\n\ntype ObjectOptions = {\n type?: 'path' | 'template'\n replacer?: (pathParam: string) => string\n stringify?: boolean\n}\n\nexport class URLPath {\n path: string\n\n constructor(path: string) {\n this.path = path\n\n return this\n }\n\n /**\n * Convert Swagger path to URLPath(syntax of Express)\n * @example /pet/{petId} => /pet/:petId\n */\n get URL(): string {\n return this.toURLPath()\n }\n get isURL(): boolean {\n try {\n const url = new URL(this.path)\n if (url?.href) {\n return true\n }\n } catch (error) {\n return false\n }\n return false\n }\n\n /**\n * Convert Swagger path to template literals/ template strings(camelcase)\n * @example /pet/{petId} => `/pet/${petId}`\n * @example /account/monetary-accountID => `/account/${monetaryAccountId}`\n * @example /account/userID => `/account/${userId}`\n */\n get template(): string {\n return this.toTemplateString()\n }\n get object(): URLObject | string {\n return this.toObject()\n }\n get params(): Record<string, string> | undefined {\n return this.getParams()\n }\n\n toObject({ type = 'path', replacer, stringify }: ObjectOptions = {}): URLObject | string {\n const object = {\n url: type === 'path' ? this.toURLPath() : this.toTemplateString(replacer),\n params: this.getParams(),\n }\n\n if (stringify) {\n if (type === 'template') {\n return JSON.stringify(object).replaceAll(\"'\", '').replaceAll(`\"`, '')\n }\n\n if (object.params) {\n return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll(\"'\", '').replaceAll(`\"`, '')} }`\n }\n\n return `{ url: '${object.url}' }`\n }\n\n return object\n }\n\n /**\n * Convert Swagger path to template literals/ template strings(camelcase)\n * @example /pet/{petId} => `/pet/${petId}`\n * @example /account/monetary-accountID => `/account/${monetaryAccountId}`\n * @example /account/userID => `/account/${userId}`\n */\n toTemplateString(replacer?: (pathParam: string) => string): string {\n const regex = /{(\\w|-)*}/g\n const found = this.path.match(regex)\n let newPath = this.path.replaceAll('{', '${')\n\n if (found) {\n newPath = found.reduce((prev, curr) => {\n const pathParam = replacer ? replacer(camelCase(curr)) : camelCase(curr)\n const replacement = `\\${${pathParam}}`\n\n return prev.replace(curr, replacement)\n }, this.path)\n }\n\n return `\\`${newPath}\\``\n }\n\n getParams(replacer?: (pathParam: string) => string): Record<string, string> | undefined {\n const regex = /{(\\w|-)*}/g\n const found = this.path.match(regex)\n\n if (!found) {\n return undefined\n }\n\n const params: Record<string, string> = {}\n found.forEach((item) => {\n item = item.replaceAll('{', '').replaceAll('}', '')\n\n const pathParam = replacer ? replacer(camelCase(item)) : camelCase(item)\n\n params[pathParam] = pathParam\n }, this.path)\n\n return params\n }\n\n /**\n * Convert Swagger path to URLPath(syntax of Express)\n * @example /pet/{petId} => /pet/:petId\n */\n toURLPath(): string {\n return this.path.replaceAll('{', ':').replaceAll('}', '')\n }\n}\n","type ParserModuleTs = typeof import('@kubb/parser-ts')\n\nexport type ParserModule = ParserModuleTs\n\nexport async function getParser(language: string | undefined) {\n let modulePromise: Promise<ParserModule>\n\n switch (language) {\n default:\n modulePromise = import('@kubb/parser-ts')\n break\n }\n\n const module = await modulePromise\n\n return module\n}\n"],"mappings":";;;;;;;;;;;AAAA;AAuCO,IAAM,kBAAN,MAAM,gBAAe;A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